Blame SOURCES/0008-set_elem-Introduce-support-for-NFTNL_SET_ELEM_KEY_EN.patch

ecfd6a
From 0ac992b8118bce817e0f1da3e2581c4cde95ca80 Mon Sep 17 00:00:00 2001
ecfd6a
From: Phil Sutter <psutter@redhat.com>
ecfd6a
Date: Thu, 13 Feb 2020 17:47:45 +0100
ecfd6a
Subject: [PATCH] set_elem: Introduce support for NFTNL_SET_ELEM_KEY_END
ecfd6a
ecfd6a
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1795223
ecfd6a
Upstream Status: libnftnl commit 04cc28d8d6923
ecfd6a
ecfd6a
commit 04cc28d8d6923ea66b08ae9a74d81d8b6ac5b2d7
ecfd6a
Author: Stefano Brivio <sbrivio@redhat.com>
ecfd6a
Date:   Thu Jan 30 01:16:34 2020 +0100
ecfd6a
ecfd6a
    set_elem: Introduce support for NFTNL_SET_ELEM_KEY_END
ecfd6a
ecfd6a
    The new set element attribute maps to the netlink attribute
ecfd6a
    NFTA_SET_ELEM_KEY_END in the same way as NFTNL_SET_ELEM_KEY
ecfd6a
    maps to NFTA_SET_ELEM_KEY, and represents the key data used
ecfd6a
    to express the upper bound of a range, in concatenations.
ecfd6a
ecfd6a
    Suggested-by: Pablo Neira Ayuso <pablo@netfilter.org>
ecfd6a
    Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
ecfd6a
    Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
ecfd6a
---
ecfd6a
 include/libnftnl/set.h |  1 +
ecfd6a
 include/set_elem.h     |  1 +
ecfd6a
 src/set_elem.c         | 24 ++++++++++++++++++++++++
ecfd6a
 3 files changed, 26 insertions(+)
ecfd6a
ecfd6a
diff --git a/include/libnftnl/set.h b/include/libnftnl/set.h
ecfd6a
index bbbf58d..6843adf 100644
ecfd6a
--- a/include/libnftnl/set.h
ecfd6a
+++ b/include/libnftnl/set.h
ecfd6a
@@ -105,6 +105,7 @@ enum {
ecfd6a
 	NFTNL_SET_ELEM_USERDATA,
ecfd6a
 	NFTNL_SET_ELEM_EXPR,
ecfd6a
 	NFTNL_SET_ELEM_OBJREF,
ecfd6a
+	NFTNL_SET_ELEM_KEY_END,
ecfd6a
 	__NFTNL_SET_ELEM_MAX
ecfd6a
 };
ecfd6a
 #define NFTNL_SET_ELEM_MAX (__NFTNL_SET_ELEM_MAX - 1)
ecfd6a
diff --git a/include/set_elem.h b/include/set_elem.h
ecfd6a
index cc4d529..52f185a 100644
ecfd6a
--- a/include/set_elem.h
ecfd6a
+++ b/include/set_elem.h
ecfd6a
@@ -8,6 +8,7 @@ struct nftnl_set_elem {
ecfd6a
 	uint32_t		set_elem_flags;
ecfd6a
 	uint32_t		flags;
ecfd6a
 	union nftnl_data_reg	key;
ecfd6a
+	union nftnl_data_reg	key_end;
ecfd6a
 	union nftnl_data_reg	data;
ecfd6a
 	struct nftnl_expr	*expr;
ecfd6a
 	uint64_t		timeout;
ecfd6a
diff --git a/src/set_elem.c b/src/set_elem.c
ecfd6a
index d3ce807..2203193 100644
ecfd6a
--- a/src/set_elem.c
ecfd6a
+++ b/src/set_elem.c
ecfd6a
@@ -75,6 +75,7 @@ void nftnl_set_elem_unset(struct nftnl_set_elem *s, uint16_t attr)
ecfd6a
 		break;
ecfd6a
 	case NFTNL_SET_ELEM_FLAGS:
ecfd6a
 	case NFTNL_SET_ELEM_KEY:	/* NFTA_SET_ELEM_KEY */
ecfd6a
+	case NFTNL_SET_ELEM_KEY_END:	/* NFTA_SET_ELEM_KEY_END */
ecfd6a
 	case NFTNL_SET_ELEM_VERDICT:	/* NFTA_SET_ELEM_DATA */
ecfd6a
 	case NFTNL_SET_ELEM_DATA:	/* NFTA_SET_ELEM_DATA */
ecfd6a
 	case NFTNL_SET_ELEM_TIMEOUT:	/* NFTA_SET_ELEM_TIMEOUT */
ecfd6a
@@ -118,6 +119,10 @@ int nftnl_set_elem_set(struct nftnl_set_elem *s, uint16_t attr,
ecfd6a
 		memcpy(&s->key.val, data, data_len);
ecfd6a
 		s->key.len = data_len;
ecfd6a
 		break;
ecfd6a
+	case NFTNL_SET_ELEM_KEY_END:	/* NFTA_SET_ELEM_KEY_END */
ecfd6a
+		memcpy(&s->key_end.val, data, data_len);
ecfd6a
+		s->key_end.len = data_len;
ecfd6a
+		break;
ecfd6a
 	case NFTNL_SET_ELEM_VERDICT:	/* NFTA_SET_ELEM_DATA */
ecfd6a
 		memcpy(&s->data.verdict, data, sizeof(s->data.verdict));
ecfd6a
 		break;
ecfd6a
@@ -193,6 +198,9 @@ const void *nftnl_set_elem_get(struct nftnl_set_elem *s, uint16_t attr, uint32_t
ecfd6a
 	case NFTNL_SET_ELEM_KEY:	/* NFTA_SET_ELEM_KEY */
ecfd6a
 		*data_len = s->key.len;
ecfd6a
 		return &s->key.val;
ecfd6a
+	case NFTNL_SET_ELEM_KEY_END:	/* NFTA_SET_ELEM_KEY_END */
ecfd6a
+		*data_len = s->key_end.len;
ecfd6a
+		return &s->key_end.val;
ecfd6a
 	case NFTNL_SET_ELEM_VERDICT:	/* NFTA_SET_ELEM_DATA */
ecfd6a
 		*data_len = sizeof(s->data.verdict);
ecfd6a
 		return &s->data.verdict;
ecfd6a
@@ -287,6 +295,14 @@ void nftnl_set_elem_nlmsg_build_payload(struct nlmsghdr *nlh,
ecfd6a
 		mnl_attr_put(nlh, NFTA_DATA_VALUE, e->key.len, e->key.val);
ecfd6a
 		mnl_attr_nest_end(nlh, nest1);
ecfd6a
 	}
ecfd6a
+	if (e->flags & (1 << NFTNL_SET_ELEM_KEY_END)) {
ecfd6a
+		struct nlattr *nest1;
ecfd6a
+
ecfd6a
+		nest1 = mnl_attr_nest_start(nlh, NFTA_SET_ELEM_KEY_END);
ecfd6a
+		mnl_attr_put(nlh, NFTA_DATA_VALUE, e->key_end.len,
ecfd6a
+			     e->key_end.val);
ecfd6a
+		mnl_attr_nest_end(nlh, nest1);
ecfd6a
+	}
ecfd6a
 	if (e->flags & (1 << NFTNL_SET_ELEM_VERDICT)) {
ecfd6a
 		struct nlattr *nest1, *nest2;
ecfd6a
 
ecfd6a
@@ -373,6 +389,7 @@ static int nftnl_set_elem_parse_attr_cb(const struct nlattr *attr, void *data)
ecfd6a
 			abi_breakage();
ecfd6a
 		break;
ecfd6a
 	case NFTA_SET_ELEM_KEY:
ecfd6a
+	case NFTA_SET_ELEM_KEY_END:
ecfd6a
 	case NFTA_SET_ELEM_DATA:
ecfd6a
 	case NFTA_SET_ELEM_EXPR:
ecfd6a
 		if (mnl_attr_validate(attr, MNL_TYPE_NESTED) < 0)
ecfd6a
@@ -421,6 +438,13 @@ static int nftnl_set_elems_parse2(struct nftnl_set *s, const struct nlattr *nest
ecfd6a
 			goto out_set_elem;
ecfd6a
 		e->flags |= (1 << NFTNL_SET_ELEM_KEY);
ecfd6a
         }
ecfd6a
+	if (tb[NFTA_SET_ELEM_KEY_END]) {
ecfd6a
+		ret = nftnl_parse_data(&e->key_end, tb[NFTA_SET_ELEM_KEY_END],
ecfd6a
+				       &type);
ecfd6a
+		if (ret < 0)
ecfd6a
+			goto out_set_elem;
ecfd6a
+		e->flags |= (1 << NFTNL_SET_ELEM_KEY_END);
ecfd6a
+	}
ecfd6a
         if (tb[NFTA_SET_ELEM_DATA]) {
ecfd6a
 		ret = nftnl_parse_data(&e->data, tb[NFTA_SET_ELEM_DATA], &type);
ecfd6a
 		if (ret < 0)
ecfd6a
-- 
ecfd6a
1.8.3.1
ecfd6a