Skip to contentSkip to conversation

rule: adjust set expression size accordingly with intervals

PATCH New Pablo Neira Ayuso 1 participant 3 messages May 24, 2017 netfilter

lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/3 rule: adjust set expression size accordingly with intervals

For implicit sets, we have to call set_to_intervals() before we add the set so we have the net size in elements.

---
 src/rule.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)
src/rule.c +11 -6
index 5923bf64101e..0d9e393ab26f 100644
@@ -914,10 +914,6 @@ static int do_add_chain(struct netlink_ctx *ctx, const struct handle *h,
 static int __do_add_setelems(struct netlink_ctx *ctx, const struct handle *h,
 			     struct set *set, struct expr *expr, bool excl)
 {
-	if (set->flags & NFT_SET_INTERVAL &&
-	    set_to_intervals(ctx->msgs, set, expr, true) < 0)
-		return -1;
-
 	expr->set_flags |= set->flags;
 	if (netlink_add_setelems(ctx, h, expr, excl) < 0)
 		return -1;
@@ -934,18 +930,27 @@ static int do_add_setelems(struct netlink_ctx *ctx, const struct handle *h,
 	table = table_lookup(h);
 	set = set_lookup(table, h->set);
 
+	if (set->flags & NFT_SET_INTERVAL &&
+	    set_to_intervals(ctx->msgs, set, init, true) < 0)
+		return -1;
+
 	return __do_add_setelems(ctx, h, set, init, excl);
 }
 
 static int do_add_set(struct netlink_ctx *ctx, const struct handle *h,
 		      struct set *set, bool excl)
 {
+	if (set->init != NULL) {
+		if (set->flags & NFT_SET_INTERVAL &&
+		    set_to_intervals(ctx->msgs, set, set->init, true) < 0)
+			return -1;
+	}
 	if (netlink_add_set(ctx, h, set, excl) < 0)
 		return -1;
-	if (set->init != NULL)
+	if (set->init != NULL) {
 		return __do_add_setelems(ctx, &set->handle, set, set->init,
 					 false);
-
+	}
 	return 0;
 }
 
Signature · 1 line
2.1.4
author maintainer
#1 lore raw

PATCH 2/3 segtree: reset element size counter before adding intervals to set

Otherwise we get double the real size in terms of set elements during the interval expansion to individual elements.

---
 src/segtree.c | 2 ++
 1 file changed, 2 insertions(+)
src/segtree.c +2 -0
index 8df82a801ae4..15e8849cd684 100644
@@ -552,6 +552,7 @@ int set_to_intervals(struct list_head *errs, struct set *set,
 		return -1;
 	segtree_linearize(&list, set, init, &tree, add);
 
+	init->size = 0;
 	list_for_each_entry_safe(ei, next, &list, list) {
 		if (segtree_debug()) {
 			pr_gmp_debug("list: [%.*Zx %.*Zx]\n",
@@ -566,6 +567,7 @@ int set_to_intervals(struct list_head *errs, struct set *set,
 		expr_print(init);
 		pr_gmp_debug("\n");
 	}
+
 	return 0;
 }
 
Signature · 1 line
2.1.4
author maintainer
#2 lore raw

PATCH 3/3 netlink: add size description for constant sets

In reply to Pablo Neira Ayuso

The kernel side can make better decisions with this information when selecting the right backend, so add this information to the set netlink message.

---
 src/netlink.c | 2 ++
 1 file changed, 2 insertions(+)
src/netlink.c +2 -0
index 59e8918d2ba0..28821903f18c 100644
@@ -1293,6 +1293,8 @@ static int netlink_add_set_batch(struct netlink_ctx *ctx,
 		if (set->desc.size != 0)
 			nftnl_set_set_u32(nls, NFTNL_SET_DESC_SIZE,
 					  set->desc.size);
+	} else if (set->init) {
+		nftnl_set_set_u32(nls, NFTNL_SET_DESC_SIZE, set->init->size);
 	}
 
 	udbuf = nftnl_udata_buf_alloc(NFT_USERDATA_MAXLEN);
Signature · 1 line
2.1.4