Blame SOURCES/0020-src-Add-support-for-NFTNL_SET_DESC_CONCAT.patch

911625
From c8a5da2f527c85ab7c392cd293ff37d02a3f93a7 Mon Sep 17 00:00:00 2001
911625
From: Phil Sutter <psutter@redhat.com>
911625
Date: Thu, 13 Feb 2020 17:48:18 +0100
911625
Subject: [PATCH] src: Add support for NFTNL_SET_DESC_CONCAT
911625
911625
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1795224
911625
Upstream Status: nftables commit 6156ba34018dd
911625
Conflicts: Context change in src/mnl.c due to missing commit
911625
	   6e48df5329eab ("src: add "typeof" build/parse/print support")
911625
911625
commit 6156ba34018dddd59cb6737cfd5a69a0cbc5eaa4
911625
Author: Stefano Brivio <sbrivio@redhat.com>
911625
Date:   Thu Jan 30 01:16:56 2020 +0100
911625
911625
    src: Add support for NFTNL_SET_DESC_CONCAT
911625
911625
    To support arbitrary range concatenations, the kernel needs to know
911625
    how long each field in the concatenation is. The new libnftnl
911625
    NFTNL_SET_DESC_CONCAT set attribute describes this as an array of
911625
    lengths, in bytes, of concatenated fields.
911625
911625
    While evaluating concatenated expressions, export the datatype size
911625
    into the new field_len array, and hand the data over via libnftnl.
911625
911625
    Similarly, when data is passed back from libnftnl, parse it into
911625
    the set description.
911625
911625
    When set data is cloned, we now need to copy the additional fields
911625
    in set_clone(), too.
911625
911625
    This change depends on the libnftnl patch with title:
911625
      set: Add support for NFTA_SET_DESC_CONCAT attributes
911625
911625
    v4: No changes
911625
    v3: Rework to use set description data instead of a stand-alone
911625
        attribute
911625
    v2: No changes
911625
911625
    Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
911625
    Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
911625
---
911625
 include/expression.h |  2 ++
911625
 include/rule.h       |  6 +++++-
911625
 src/evaluate.c       | 14 +++++++++++---
911625
 src/mnl.c            |  7 +++++++
911625
 src/netlink.c        | 11 +++++++++++
911625
 src/rule.c           |  2 +-
911625
 6 files changed, 37 insertions(+), 5 deletions(-)
911625
911625
diff --git a/include/expression.h b/include/expression.h
911625
index 717b675..ee726aa 100644
911625
--- a/include/expression.h
911625
+++ b/include/expression.h
911625
@@ -256,6 +256,8 @@ struct expr {
911625
 			struct list_head	expressions;
911625
 			unsigned int		size;
911625
 			uint32_t		set_flags;
911625
+			uint8_t			field_len[NFT_REG32_COUNT];
911625
+			uint8_t			field_count;
911625
 		};
911625
 		struct {
911625
 			/* EXPR_SET_REF */
911625
diff --git a/include/rule.h b/include/rule.h
911625
index 47eb29f..c03b0b8 100644
911625
--- a/include/rule.h
911625
+++ b/include/rule.h
911625
@@ -290,7 +290,9 @@ extern struct rule *rule_lookup_by_index(const struct chain *chain,
911625
  * @rg_cache:	cached range element (left)
911625
  * @policy:	set mechanism policy
911625
  * @automerge:	merge adjacents and overlapping elements, if possible
911625
- * @desc:	set mechanism desc
911625
+ * @desc.size:		count of set elements
911625
+ * @desc.field_len:	length of single concatenated fields, bytes
911625
+ * @desc.field_count:	count of concatenated fields
911625
  */
911625
 struct set {
911625
 	struct list_head	list;
911625
@@ -310,6 +312,8 @@ struct set {
911625
 	bool			automerge;
911625
 	struct {
911625
 		uint32_t	size;
911625
+		uint8_t		field_len[NFT_REG32_COUNT];
911625
+		uint8_t		field_count;
911625
 	} desc;
911625
 };
911625
 
911625
diff --git a/src/evaluate.c b/src/evaluate.c
911625
index a865902..58f458d 100644
911625
--- a/src/evaluate.c
911625
+++ b/src/evaluate.c
911625
@@ -1216,6 +1216,8 @@ static int expr_evaluate_concat(struct eval_ctx *ctx, struct expr **expr,
911625
 	struct expr *i, *next;
911625
 
911625
 	list_for_each_entry_safe(i, next, &(*expr)->expressions, list) {
911625
+		unsigned dsize_bytes;
911625
+
911625
 		if (expr_is_constant(*expr) && dtype && off == 0)
911625
 			return expr_binary_error(ctx->msgs, i, *expr,
911625
 						 "unexpected concat component, "
911625
@@ -1240,6 +1242,9 @@ static int expr_evaluate_concat(struct eval_ctx *ctx, struct expr **expr,
911625
 						 i->dtype->name);
911625
 
911625
 		ntype = concat_subtype_add(ntype, i->dtype->type);
911625
+
911625
+		dsize_bytes = div_round_up(i->dtype->size, BITS_PER_BYTE);
911625
+		(*expr)->field_len[(*expr)->field_count++] = dsize_bytes;
911625
 	}
911625
 
911625
 	(*expr)->flags |= flags;
911625
@@ -3321,9 +3326,12 @@ static int set_evaluate(struct eval_ctx *ctx, struct set *set)
911625
 					 "specified in %s definition",
911625
 					 set->key->dtype->name, type);
911625
 	}
911625
-	if (set->flags & NFT_SET_INTERVAL &&
911625
-	    set->key->etype == EXPR_CONCAT)
911625
-		return set_error(ctx, set, "concatenated types not supported in interval sets");
911625
+
911625
+	if (set->flags & NFT_SET_INTERVAL && set->key->etype == EXPR_CONCAT) {
911625
+		memcpy(&set->desc.field_len, &set->key->field_len,
911625
+		       sizeof(set->desc.field_len));
911625
+		set->desc.field_count = set->key->field_count;
911625
+	}
911625
 
911625
 	if (set_is_datamap(set->flags)) {
911625
 		if (set->datatype == NULL)
911625
diff --git a/src/mnl.c b/src/mnl.c
911625
index aa5b0b4..221ee05 100644
911625
--- a/src/mnl.c
911625
+++ b/src/mnl.c
911625
@@ -881,6 +881,13 @@ int mnl_nft_set_add(struct netlink_ctx *ctx, const struct cmd *cmd,
911625
 				 set->automerge))
911625
 		memory_allocation_error();
911625
 
911625
+	if (set->desc.field_len[0]) {
911625
+		nftnl_set_set_data(nls, NFTNL_SET_DESC_CONCAT,
911625
+				   set->desc.field_len,
911625
+				   set->desc.field_count *
911625
+				   sizeof(set->desc.field_len[0]));
911625
+	}
911625
+
911625
 	nftnl_set_set_data(nls, NFTNL_SET_USERDATA, nftnl_udata_buf_data(udbuf),
911625
 			   nftnl_udata_buf_len(udbuf));
911625
 	nftnl_udata_buf_free(udbuf);
911625
diff --git a/src/netlink.c b/src/netlink.c
911625
index 486e124..83d863c 100644
911625
--- a/src/netlink.c
911625
+++ b/src/netlink.c
911625
@@ -672,6 +672,17 @@ struct set *netlink_delinearize_set(struct netlink_ctx *ctx,
911625
 	if (nftnl_set_is_set(nls, NFTNL_SET_DESC_SIZE))
911625
 		set->desc.size = nftnl_set_get_u32(nls, NFTNL_SET_DESC_SIZE);
911625
 
911625
+	if (nftnl_set_is_set(nls, NFTNL_SET_DESC_CONCAT)) {
911625
+		uint32_t len = NFT_REG32_COUNT;
911625
+		const uint8_t *data;
911625
+
911625
+		data = nftnl_set_get_data(nls, NFTNL_SET_DESC_CONCAT, &len;;
911625
+		if (data) {
911625
+			memcpy(set->desc.field_len, data, len);
911625
+			set->desc.field_count = len;
911625
+		}
911625
+	}
911625
+
911625
 	return set;
911625
 }
911625
 
911625
diff --git a/src/rule.c b/src/rule.c
911625
index 3ca1805..4669577 100644
911625
--- a/src/rule.c
911625
+++ b/src/rule.c
911625
@@ -337,7 +337,7 @@ struct set *set_clone(const struct set *set)
911625
 	new_set->objtype	= set->objtype;
911625
 	new_set->policy		= set->policy;
911625
 	new_set->automerge	= set->automerge;
911625
-	new_set->desc.size	= set->desc.size;
911625
+	new_set->desc		= set->desc;
911625
 
911625
 	return new_set;
911625
 }
911625
-- 
8ff5ad
2.31.1
911625