From: Florian Westphal Date: Tue, 16 Sep 2025 16:52:53 +0000 (+0200) Subject: tests: shell: add regression tests for set flush+add bugs X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b134dc218066911a9ddab8fd82957b2e48da48f3;p=thirdparty%2Fnftables.git tests: shell: add regression tests for set flush+add bugs Create a helper file to: 1. create client <-> router <-> server topology 2. floodping from client to server 3. add a chain + set that contains both client and server addresses 4. a control counter that should never match 5. then, flush the set (not the ruleset) and re-add the addresses in one transaction Report failure when counter had a match. The test cases for the set types are done in separate files to take advantage of run-tests.sh parallelization. The expected behavior is that every ping packet is matched by the set. The packet path should either match the old state, right before flush, or the new state, after re-add. As the flushed addresses are re-added in the same transaction we must not observe in-limbo state where existing elements are deactivated but new elements are not found. Signed-off-by: Florian Westphal --- diff --git a/tests/shell/helpers/set_flush_add_atomic_helpers b/tests/shell/helpers/set_flush_add_atomic_helpers new file mode 100644 index 00000000..fe895e98 --- /dev/null +++ b/tests/shell/helpers/set_flush_add_atomic_helpers @@ -0,0 +1,223 @@ +# Test skeleton for kernel fixes: +# b2f742c846ca netfilter: nf_tables: restart set lookup on base_seq change +# a60f7bf4a152 netfilter: nft_set_rbtree: continue traversal if element is inactive +# .. and related patches. +# +# Generate traffic and then flush the set contents and replace +# them with the same matching entries. +# +# Fail when a packet gets through. + +# global variables: +# R, S, C (network namespaces). +# ip_s (server address) + +# helpers: +# set_flush_add_atomic_cleanup +# set_flush_add_create_topo +# set_flush_add_atomic_run_test + +[ -z "$TIMEOUT" ] && TIMEOUT=30 + +set_flush_add_atomic_cleanup() +{ + local tmp="$1" + local i + + rm -f "$tmp" + + ip netns exec $R $NFT --debug netlink list ruleset + + for i in $C $S $R;do + kill $(ip netns pid $i) 2>/dev/null + ip netns del $i + done +} + +check_counter() +{ + local tmp="$1" + local then="$2" + + if ip netns exec $R $NFT list chain ip filter block-spoofed | grep -q 'counter packets 0 bytes 0'; then + return 0 + fi + + local now=$(date +%s) + echo "$0 failed counter check after $((now-then))s" + + rm -f "$tmp" + kill $(ip netns pid $C) 2>/dev/null + return 1 +} + +load_ruleset() +{ + local type="$1" + local flags="$2" + local elements="$3" + local expr="$4" + +ip netns exec $R $NFT -f - <