evaluate: attempt to set_eval flag if dynamic updates requested
Florian Westphal
maintainerPATCH 1/1 evaluate: attempt to set_eval flag if dynamic updates requested
When passing no upper size limit, the dynset expression forces an internal 64k upperlimit.
In some cases, this can result in 'nft -f' to restore the ruleset. Avoid this by always setting the EVAL flag on a set definition when we encounter packet-path update attempt in the batch.
Reported-by Yi Chen <[email protected]>
Suggested-by Pablo Neira Ayuso <[email protected]>
Signed-off-by Florian Westphal <[email protected]>
--- src/evaluate.c | 10 ++++++ .../testcases/sets/dumps/dynset_missing.nft | 12 +++++++ tests/shell/testcases/sets/dynset_missing | 32 +++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 tests/shell/testcases/sets/dumps/dynset_missing.nft create mode 100755 tests/shell/testcases/sets/dynset_missing
src/evaluate.c +10 -0
@@ -3621,6 +3621,7 @@ static int stmt_evaluate_log(struct eval_ctx *ctx, struct stmt *stmt)static int stmt_evaluate_set (struct eval_ctx *ctx,struct stmt *stmt) { +struct set *this_set;struct stmt *this;expr_set_context (&ctx->ectx,NULL ,0 );
@@ -3650,6 +3651,15 @@ static int stmt_evaluate_set(struct eval_ctx *ctx, struct stmt *stmt) "statement must be stateful"); } + this_set = stmt->set.set->set; + +/* Make sure EVAL flag is set on set definition so that kernel +* picks a set that allows updates from the packet path. +* +* Alternatively we could error out in case 'flags dynamic' was +* not given, but we can repair this here. +*/ + this_set->flags |=NFT_SET_EVAL ;return 0 ; }
tests/shell/testcases/sets/dumps/dynset_missing.nft new file +12 -0
@@ -0,0 +1,12 @@ +table ip test { + set dlist { + type ipv4_addr + size 65535 + flags dynamic + } + + chain output { + type filter hook output priority filter; policy accept; + udp dport 1234 update @dlist { ip daddr } counter packets 0 bytes 0 + } +}
tests/shell/testcases/sets/dynset_missing new file +32 -0
@@ -0,0 +1,32 @@ +#!/bin/bash + +set -e + +$NFT -f /dev/stdin <<EOF +table ip test { + chain output { type filter hook output priority 0; + } +} +EOF + +# misses 'flags dynamic' +$NFT 'add set ip test dlist {type ipv4_addr; }' + +# picks rhash backend because 'size' was also missing. +$NFT 'add rule ip test output udp dport 1234 update @dlist { ip daddr } counter' + +tmpfile=$(mktemp) + +trap "rm -rf $tmpfile" EXIT + +# kernel has forced an 64k upper size, i.e. this restore file +# has 'size 65536' but no 'flags dynamic'. +$NFT list ruleset > $tmpfile + +# this restore works, because set is still the rhash backend. +$NFT -f $tmpfile # success +$NFT flush ruleset + +# fails without commit 'attempt to set_eval flag if dynamic updates requested', +# because set in $tmpfile has 'size x' but no 'flags dynamic'. +$NFT -f $tmpfile
Signature · 1 line
2.34.1
Pablo Neira Ayuso
maintainerQuoted 6 lines · Florian Westphal
When passing no upper size limit, the dynset expression forces an internal 64k upperlimit.
In some cases, this can result in 'nft -f' to restore the ruleset. Avoid this by always setting the EVAL flag on a set definition when we encounter packet-path update attempt in the batch.
LGTM.
Quoted 98 lines
Reported-by Yi Chen <[email protected]>Suggested-by Pablo Neira Ayuso <[email protected]>Signed-off-by Florian Westphal <[email protected]>--- src/evaluate.c | 10 ++++++ .../testcases/sets/dumps/dynset_missing.nft | 12 +++++++ tests/shell/testcases/sets/dynset_missing | 32 +++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 tests/shell/testcases/sets/dumps/dynset_missing.nft create mode 100755 tests/shell/testcases/sets/dynset_missingsrc/evaluate.c +10
-0@@ -3621,6 +3621,7 @@ static int stmt_evaluate_log(struct eval_ctx *ctx, struct stmt *stmt)static int stmt_evaluate_set (struct eval_ctx *ctx,struct stmt *stmt) { +struct set *this_set;struct stmt *this;expr_set_context (&ctx->ectx,NULL ,0 );@@ -3650,6 +3651,15 @@ static int stmt_evaluate_set(struct eval_ctx *ctx, struct stmt *stmt) "statement must be stateful"); } + this_set = stmt->set.set->set; + +/* Make sure EVAL flag is set on set definition so that kernel +* picks a set that allows updates from the packet path. +* +* Alternatively we could error out in case 'flags dynamic' was +* not given, but we can repair this here. +*/ + this_set->flags |=NFT_SET_EVAL ;return 0 ; }tests/shell/testcases/sets/dumps/dynset_missing.nft new file +12
-0@@ -0,0 +1,12 @@ +table ip test { + set dlist { + type ipv4_addr + size 65535 + flags dynamic + } + + chain output { + type filter hook output priority filter; policy accept; + udp dport 1234 update @dlist { ip daddr } counter packets 0 bytes 0 + } +}tests/shell/testcases/sets/dynset_missing new file +32
-0@@ -0,0 +1,32 @@ +#!/bin/bash + +set -e + +$NFT -f /dev/stdin <<EOF +table ip test { + chain output { type filter hook output priority 0; + } +} +EOF + +# misses 'flags dynamic' +$NFT 'add set ip test dlist {type ipv4_addr; }' + +# picks rhash backend because 'size' was also missing. +$NFT 'add rule ip test output udp dport 1234 update @dlist { ip daddr } counter' + +tmpfile=$(mktemp) + +trap "rm -rf $tmpfile" EXIT + +# kernel has forced an 64k upper size, i.e. this restore file +# has 'size 65536' but no 'flags dynamic'. +$NFT list ruleset > $tmpfile + +# this restore works, because set is still the rhash backend. +$NFT -f $tmpfile # success +$NFT flush ruleset + +# fails without commit 'attempt to set_eval flag if dynamic updates requested', +# because set in $tmpfile has 'size x' but no 'flags dynamic'. +$NFT -f $tmpfileSignature · 1 line
2.34.1