]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
segtree: Fix add and delete of element in same batch
authorPhil Sutter <phil@nwl.cc>
Thu, 21 Nov 2019 10:41:24 +0000 (11:41 +0100)
committerPablo Neira Ayuso <pablo@netfilter.org>
Mon, 2 Dec 2019 18:25:22 +0000 (19:25 +0100)
The commit this fixes accidentally broke a rather exotic use-case which
is but used in set-simple.t of tests/monitor:

| # nft 'add element t s { 22-25 }; delete element t s { 22-25 }'

Since ranges are now checked for existence in userspace before delete
command is submitted to kernel, the second command above was rejected
because the range in question wasn't present in cache yet. Fix this by
adding new interval set elements to cache after creating the batch job
for them.

Fixes: decc12ec2dc31 ("segtree: Check ranges when deleting elements")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/rule.c

index 4abc13c993b8925756d229e50e920263672df1f6..d985d3a2316e45a1c598795d5a2439ec54c637b0 100644 (file)
@@ -1511,6 +1511,14 @@ static int __do_add_setelems(struct netlink_ctx *ctx, struct set *set,
        if (mnl_nft_setelem_add(ctx, set, expr, flags) < 0)
                return -1;
 
+       if (set->init != NULL &&
+           set->flags & NFT_SET_INTERVAL) {
+               interval_map_decompose(expr);
+               list_splice_tail_init(&expr->expressions, &set->init->expressions);
+               set->init->size += expr->size;
+               expr->size = 0;
+       }
+
        return 0;
 }