]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
tests: shell: Use --numeric-protocol for dumps
authorPhil Sutter <phil@nwl.cc>
Thu, 13 Aug 2026 11:35:24 +0000 (13:35 +0200)
committerPhil Sutter <phil@nwl.cc>
Thu, 13 Aug 2026 15:12:04 +0000 (17:12 +0200)
The py test suite does this as well. Protocol names depend on contents
of /etc/protocols which is not in control of nftables. Using numeric
protocol values for dumps therefore prevents the host system from
compromising test results.

Signed-off-by: Phil Sutter <phil@nwl.cc>
tests/shell/helpers/test-wrapper.sh

index 7a73e531f7e42a4c9c0428e7e1f5ac94f9e5a699..78a01d5666ec267c6d9af19c2949623dea94813a 100755 (executable)
@@ -152,21 +152,22 @@ fi
 
 rc_chkdump=0
 rc=0
-$NFT list ruleset > "$NFT_TEST_TESTTMPDIR/ruleset-after" 2> "$NFT_TEST_TESTTMPDIR/chkdump" || rc=$?
+chkdump_nft="$NFT --numeric-protocol"
+$chkdump_nft list ruleset > "$NFT_TEST_TESTTMPDIR/ruleset-after" 2> "$NFT_TEST_TESTTMPDIR/chkdump" || rc=$?
 if [ "$rc" -ne 0 -o -s "$NFT_TEST_TESTTMPDIR/chkdump" ] ; then
-       show_file "$NFT_TEST_TESTTMPDIR/chkdump" "Command \`$NFT list ruleset\` failed" >> "$NFT_TEST_TESTTMPDIR/rc-failed-chkdump"
+       show_file "$NFT_TEST_TESTTMPDIR/chkdump" "Command \`$chkdump_nft list ruleset\` failed" >> "$NFT_TEST_TESTTMPDIR/rc-failed-chkdump"
        rc_chkdump=1
 fi
 if [ "$NFT_TEST_HAVE_json" != n ] ; then
        rc=0
-       $NFT -j list ruleset > "$NFT_TEST_TESTTMPDIR/ruleset-after.json" 2> "$NFT_TEST_TESTTMPDIR/chkdump" || rc=$?
+       $chkdump_nft -j list ruleset > "$NFT_TEST_TESTTMPDIR/ruleset-after.json" 2> "$NFT_TEST_TESTTMPDIR/chkdump" || rc=$?
 
        # Workaround known bug in stmt_print_json(), due to
        # "chain_stmt_ops.json" being NULL. This spams stderr.
        sed -i '/^warning: stmt ops chain have no json callback$/d' "$NFT_TEST_TESTTMPDIR/chkdump"
 
        if [ "$rc" -ne 0 -o -s "$NFT_TEST_TESTTMPDIR/chkdump" ] ; then
-               show_file "$NFT_TEST_TESTTMPDIR/chkdump" "Command \`$NFT -j list ruleset\` failed" >> "$NFT_TEST_TESTTMPDIR/rc-failed-chkdump"
+               show_file "$NFT_TEST_TESTTMPDIR/chkdump" "Command \`$chkdump_nft -j list ruleset\` failed" >> "$NFT_TEST_TESTTMPDIR/rc-failed-chkdump"
                rc_chkdump=1
        fi
        # JSON output needs normalization/sanitization, otherwise it's not stable.