tests/shell: fix tests to skip on lacking feature support
cover tests/shell: fix tests to skip on lacking feature support
Most of the patches are from Florian.
With this, a test-run on Fedora 38 and CentOS-Stream-9 should pass (some tests will be skipped).
Florian Westphal (12):
tests/shell: add and use chain binding feature probe tests/shell: skip netdev_chain_0 if kernel requires netdev device tests/shell: skip map query if kernel lacks support tests/shell: skip inner matching tests if unsupported tests/shell: skip bitshift tests if kernel lacks support tests/shell: skip some tests if kernel lacks netdev egress support tests/shell: skip inet ingress tests if kernel lacks support tests/shell: skip destroy tests if kernel lacks support tests/shell: skip catchall tests if kernel lacks support tests/shell: skip test cases involving osf match if kernel lacks
support
tests/shell: skip test cases if ct expectation and/or timeout lacks
support
tests/shell: skip reset tests if kernel lacks support
Thomas Haller (2):
tests/shell: implement NFT_TEST_HAVE_json feature detection as script tests/shell: check diff in "maps/typeof_maps_0" and
"sets/typeof_sets_0" test
tests/shell/features/bitshift.nft | 7 + tests/shell/features/catchall_element.nft | 8 ++ tests/shell/features/chain_binding.nft | 7 + tests/shell/features/ctexpect.nft | 10 ++ tests/shell/features/cttimeout.nft | 8 ++ tests/shell/features/destroy.nft | 3 + tests/shell/features/inet_ingress.nft | 7 + tests/shell/features/inner_matching.nft | 7 + tests/shell/features/json.sh | 6 + tests/shell/features/map_lookup.nft | 11 ++ .../features/netdev_chain_without_device.nft | 7 + tests/shell/features/netdev_egress.nft | 7 + tests/shell/features/osf.nft | 7 + tests/shell/features/reset_rule.sh | 8 ++ tests/shell/features/reset_set.sh | 10 ++ tests/shell/run-tests.sh | 39 +++--- .../shell/testcases/bitwise/0040mark_binop_0 | 2 + .../shell/testcases/bitwise/0040mark_binop_1 | 2 + .../shell/testcases/bitwise/0040mark_binop_2 | 2 + .../shell/testcases/bitwise/0040mark_binop_3 | 2 + .../shell/testcases/bitwise/0040mark_binop_4 | 2 + .../shell/testcases/bitwise/0040mark_binop_5 | 2 + .../shell/testcases/bitwise/0040mark_binop_6 | 2 + .../shell/testcases/bitwise/0040mark_binop_7 | 2 + .../shell/testcases/bitwise/0040mark_binop_8 | 2 + .../shell/testcases/bitwise/0040mark_binop_9 | 2 + .../testcases/cache/0010_implicit_chain_0 | 2 + tests/shell/testcases/chains/0021prio_0 | 7 +- .../testcases/chains/0041chain_binding_0 | 5 + .../testcases/chains/0042chain_variable_0 | 5 + .../testcases/chains/0043chain_ingress_0 | 9 +- .../testcases/chains/0044chain_destroy_0 | 2 + .../chains/dumps/netdev_chain_autoremove.nft | 0 tests/shell/testcases/chains/netdev_chain_0 | 2 + .../testcases/chains/netdev_chain_autoremove | 9 ++ tests/shell/testcases/flowtable/0015destroy_0 | 2 + tests/shell/testcases/listing/0013objects_0 | 50 ++----- .../testcases/listing/dumps/0013objects_0.nft | 2 - tests/shell/testcases/maps/0011vmap_0 | 10 +- tests/shell/testcases/maps/0014destroy_0 | 2 + .../shell/testcases/maps/0017_map_variable_0 | 13 +- .../maps/map_catchall_double_deactivate | 2 + tests/shell/testcases/maps/typeof_maps_0 | 66 ++++++++- .../testcases/maps/typeof_maps_add_delete | 35 +++-- .../testcases/nft-f/0017ct_timeout_obj_0 | 2 + .../testcases/rule_management/0011reset_0 | 2 + .../testcases/rule_management/0012destroy_0 | 2 + tests/shell/testcases/sets/0063set_catchall_0 | 2 + tests/shell/testcases/sets/0064map_catchall_0 | 2 + tests/shell/testcases/sets/0072destroy_0 | 2 + tests/shell/testcases/sets/inner_0 | 2 + tests/shell/testcases/sets/reset_command_0 | 2 + tests/shell/testcases/sets/typeof_sets_0 | 130 ++++++++++++++++-- tests/shell/testcases/transactions/30s-stress | 55 +++++++- 54 files changed, 502 insertions(+), 94 deletions(-) create mode 100644 tests/shell/features/bitshift.nft create mode 100644 tests/shell/features/catchall_element.nft create mode 100644 tests/shell/features/chain_binding.nft create mode 100644 tests/shell/features/ctexpect.nft create mode 100644 tests/shell/features/cttimeout.nft create mode 100644 tests/shell/features/destroy.nft create mode 100644 tests/shell/features/inet_ingress.nft create mode 100644 tests/shell/features/inner_matching.nft create mode 100755 tests/shell/features/json.sh create mode 100644 tests/shell/features/map_lookup.nft create mode 100644 tests/shell/features/netdev_chain_without_device.nft create mode 100644 tests/shell/features/netdev_egress.nft create mode 100644 tests/shell/features/osf.nft create mode 100755 tests/shell/features/reset_rule.sh create mode 100755 tests/shell/features/reset_set.sh create mode 100644 tests/shell/testcases/chains/dumps/netdev_chain_autoremove.nft create mode 100755 tests/shell/testcases/chains/netdev_chain_autoremove
Signature · 1 line
2.41.0
PATCH 1/14 tests/shell: add and use chain binding feature probe
From: Florian Westphal <[email protected]>
Alter 30s-stress to suppress anon chains when its unuspported.
Note that 30s-stress is optionally be run standalone, so also update the test script.
--- tests/shell/features/chain_binding.nft | 7 +++ .../testcases/cache/0010_implicit_chain_0 | 2 + .../testcases/chains/0041chain_binding_0 | 5 ++ tests/shell/testcases/transactions/30s-stress | 55 ++++++++++++++++--- 4 files changed, 62 insertions(+), 7 deletions(-) create mode 100644 tests/shell/features/chain_binding.nft
tests/shell/features/chain_binding.nft new file +7 -0
@@ -0,0 +1,7 @@ +# d0e2c7de92c7 ("netfilter: nf_tables: add NFT_CHAIN_BINDING") +# v5.9-rc1~133^2~302^2~1 +table ip t { + chain c { + jump { counter; } + } +}
tests/shell/testcases/cache/0010_implicit_chain_0 +2 -0
@@ -1,5 +1,7 @@ #!/bin/bash +# NFT_TEST_REQUIRES(NFT_TEST_HAVE_chain_binding) + set -e EXPECTED="table ip f {
tests/shell/testcases/chains/0041chain_binding_0 +5 -0
@@ -6,6 +6,11 @@ if [ $? -ne 1 ]; then exit 1 fi +if [ $NFT_TEST_HAVE_chain_binding = "n" ] ; then + echo "Test partially skipped due to NFT_TEST_HAVE_chain_binding=n" + exit 77 +fi + set -e EXPECTED="table inet x {
tests/shell/testcases/transactions/30s-stress +48 -7
108 lines not on this page · raw message
Signature · 1 line
2.41.0
PATCH 2/14 tests/shell: skip netdev_chain_0 if kernel requires netdev device
In reply to Thomas HallerFrom: Florian Westphal <[email protected]>
This test case only works on kernel 6.4+.
Add feature probe for this and tag the test accordingly using the scheme added by Thomas Haller in
"tests/shell: skip tests if nft does not support JSON mode"
so that run-test.sh skips it if kernel requires a device.
--- tests/shell/features/netdev_chain_without_device.nft | 7 +++++++ tests/shell/testcases/chains/netdev_chain_0 | 2 ++ 2 files changed, 9 insertions(+) create mode 100644 tests/shell/features/netdev_chain_without_device.nft
tests/shell/features/netdev_chain_without_device.nft new file +7 -0
@@ -0,0 +1,7 @@ +# 207296f1a03b ("netfilter: nf_tables: allow to create netdev chain without device") +# v6.4-rc1~132^2~14^2 +table netdev t { + chain c { + type filter hook ingress priority 0; policy accept; + } +}
tests/shell/testcases/chains/netdev_chain_0 +2 -0
@@ -1,5 +1,7 @@ #!/bin/bash +# NFT_TEST_REQUIRES(NFT_TEST_HAVE_netdev_chain_without_device) + set -e iface_cleanup() {
Signature · 1 line
2.41.0
PATCH 3/14 tests/shell: skip map query if kernel lacks support
In reply to Thomas HallerFrom: Florian Westphal <[email protected]>
On recent kernels one can perform a lookup in a map without a destination register (i.e., treat the map like a set -- pure existence check).
Add a feature probe and work around the missing feature intypeof_maps_add_delete: do the test with a simplified ruleset,
Indicate skipped even though a reduced test was run (earlier errors cause a failure) to not trigger dump validation error.
--- tests/shell/features/map_lookup.nft | 11 ++++++ .../testcases/maps/typeof_maps_add_delete | 35 ++++++++++++++----- 2 files changed, 38 insertions(+), 8 deletions(-) create mode 100644 tests/shell/features/map_lookup.nft
tests/shell/features/map_lookup.nft new file +11 -0
@@ -0,0 +1,11 @@ +# a4878eeae390 ("netfilter: nf_tables: relax set/map validation checks") +# v6.5-rc1~163^2~256^2~8 +table ip t { + map m { + typeof ip daddr : meta mark + } + + chain c { + ip saddr @m + } +}
tests/shell/testcases/maps/typeof_maps_add_delete +27 -8
@@ -1,6 +1,15 @@ #!/bin/bash -EXPECTED='table ip dynset { +CONDMATCH="ip saddr @dynmark" +NCONDMATCH="ip saddr != @dynmark" + +# use reduced feature set +if [ "$NFT_TEST_HAVE_map_lookup" = n ] ; then + CONDMATCH="" + NCONDMATCH="" +fi + +EXPECTED="table ip dynset { map dynmark { typeof ip daddr : meta mark counter
@@ -9,20 +18,20 @@ EXPECTED='table ip dynset { } chain test_ping { - ip saddr @dynmark counter comment "should not increment" - ip saddr != @dynmark add @dynmark { ip saddr : 0x1 } counter - ip saddr @dynmark counter comment "should increment" - ip saddr @dynmark delete @dynmark { ip saddr : 0x1 } - ip saddr @dynmark counter comment "delete should be instant but might fail under memory pressure" + $CONDMATCH counter comment \"should not increment\" + $NCONDMATCH add @dynmark { ip saddr : 0x1 } counter + $CONDMATCH counter comment \"should increment\" + $CONDMATCH delete @dynmark { ip saddr : 0x1 } + $CONDMATCH counter comment \"delete should be instant but might fail under memory pressure\" } chain input { type filter hook input priority 0; policy accept; - add @dynmark { 10.2.3.4 timeout 1s : 0x2 } comment "also check timeout-gc" + add @dynmark { 10.2.3.4 timeout 1s : 0x2 } comment \"also check timeout-gc\" meta l4proto icmp ip daddr 127.0.0.42 jump test_ping } -}' +}" set -e $NFT -f - <<< $EXPECTED
@@ -31,5 +40,15 @@ $NFT list ruleset ip link set lo up ping -c 1 127.0.0.42 +$NFT get element ip dynset dynmark { 10.2.3.4 } + # wait so that 10.2.3.4 times out. sleep 2 + +set +e +$NFT get element ip dynset dynmark { 10.2.3.4 } && exit 1 + +if [ "$NFT_TEST_HAVE_map_lookup" = n ] ; then + echo "Only tested a subset due to NFT_TEST_HAVE_map_lookup=n. Skipped." + exit 77 +fi
Signature · 1 line
2.41.0
PATCH 4/14 tests/shell: skip inner matching tests if unsupported
In reply to Thomas HallerFrom: Florian Westphal <[email protected]>
--- tests/shell/features/inner_matching.nft | 7 +++++++ tests/shell/testcases/sets/inner_0 | 2 ++ 2 files changed, 9 insertions(+) create mode 100644 tests/shell/features/inner_matching.nft
tests/shell/features/inner_matching.nft new file +7 -0
@@ -0,0 +1,7 @@ +# 3a07327d10a0 ("netfilter: nft_inner: support for inner tunnel header matching") +# v6.2-rc1~99^2~350^2~4 +table ip t { + chain c { + udp dport 4789 vxlan ip saddr 1.2.3.4 + } +}
tests/shell/testcases/sets/inner_0 +2 -0
@@ -1,5 +1,7 @@ #!/bin/bash +# NFT_TEST_REQUIRES(NFT_TEST_HAVE_inner_matching) + set -e RULESET="table netdev x {
Signature · 1 line
2.41.0
PATCH 5/14 tests/shell: skip bitshift tests if kernel lacks support
In reply to Thomas HallerFrom: Florian Westphal <[email protected]>
--- tests/shell/features/bitshift.nft | 7 +++++++ tests/shell/testcases/bitwise/0040mark_binop_0 | 2 ++ tests/shell/testcases/bitwise/0040mark_binop_1 | 2 ++ tests/shell/testcases/bitwise/0040mark_binop_2 | 2 ++ tests/shell/testcases/bitwise/0040mark_binop_3 | 2 ++ tests/shell/testcases/bitwise/0040mark_binop_4 | 2 ++ tests/shell/testcases/bitwise/0040mark_binop_5 | 2 ++ tests/shell/testcases/bitwise/0040mark_binop_6 | 2 ++ tests/shell/testcases/bitwise/0040mark_binop_7 | 2 ++ tests/shell/testcases/bitwise/0040mark_binop_8 | 2 ++ tests/shell/testcases/bitwise/0040mark_binop_9 | 2 ++ 11 files changed, 27 insertions(+) create mode 100644 tests/shell/features/bitshift.nft
tests/shell/features/bitshift.nft new file +7 -0
@@ -0,0 +1,7 @@ +# 567d746b55bc ("netfilter: bitwise: add support for shifts.") +# v5.6-rc1~151^2~73^2 +table ip t { + chain c { + meta mark set meta mark << 2 + } +}
tests/shell/testcases/bitwise/0040mark_binop_0 +2 -0
@@ -1,5 +1,7 @@ #!/bin/bash +# NFT_TEST_REQUIRES(NFT_TEST_HAVE_bitshift) + set -e RULESET="
tests/shell/testcases/bitwise/0040mark_binop_1 +2 -0
@@ -1,5 +1,7 @@ #!/bin/bash +# NFT_TEST_REQUIRES(NFT_TEST_HAVE_bitshift) + set -e RULESET="
tests/shell/testcases/bitwise/0040mark_binop_2 +2 -0
@@ -1,5 +1,7 @@ #!/bin/bash +# NFT_TEST_REQUIRES(NFT_TEST_HAVE_bitshift) + set -e RULESET="
tests/shell/testcases/bitwise/0040mark_binop_3 +2 -0
@@ -1,5 +1,7 @@ #!/bin/bash +# NFT_TEST_REQUIRES(NFT_TEST_HAVE_bitshift) + set -e RULESET="
tests/shell/testcases/bitwise/0040mark_binop_4 +2 -0
@@ -1,5 +1,7 @@ #!/bin/bash +# NFT_TEST_REQUIRES(NFT_TEST_HAVE_bitshift) + set -e RULESET="
tests/shell/testcases/bitwise/0040mark_binop_5 +2 -0
@@ -1,5 +1,7 @@ #!/bin/bash +# NFT_TEST_REQUIRES(NFT_TEST_HAVE_bitshift) + set -e RULESET="
tests/shell/testcases/bitwise/0040mark_binop_6 +2 -0
@@ -1,5 +1,7 @@ #!/bin/bash +# NFT_TEST_REQUIRES(NFT_TEST_HAVE_bitshift) + set -e RULESET="
tests/shell/testcases/bitwise/0040mark_binop_7 +2 -0
@@ -1,5 +1,7 @@ #!/bin/bash +# NFT_TEST_REQUIRES(NFT_TEST_HAVE_bitshift) + set -e RULESET="
tests/shell/testcases/bitwise/0040mark_binop_8 +2 -0
@@ -1,5 +1,7 @@ #!/bin/bash +# NFT_TEST_REQUIRES(NFT_TEST_HAVE_bitshift) + set -e RULESET="
tests/shell/testcases/bitwise/0040mark_binop_9 +2 -0
@@ -1,5 +1,7 @@ #!/bin/bash +# NFT_TEST_REQUIRES(NFT_TEST_HAVE_bitshift) + set -e RULESET="
Signature · 1 line
2.41.0
PATCH 6/14 tests/shell: skip some tests if kernel lacks netdev egress support
In reply to Thomas HallerFrom: Florian Westphal <[email protected]>
--- tests/shell/features/netdev_egress.nft | 7 +++++++ tests/shell/testcases/chains/0021prio_0 | 7 ++++++- tests/shell/testcases/chains/0042chain_variable_0 | 5 +++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 tests/shell/features/netdev_egress.nft
tests/shell/features/netdev_egress.nft new file +7 -0
@@ -0,0 +1,7 @@ +# 42df6e1d221d ("netfilter: Introduce egress hook") +# v5.16-rc1~159^2~167^2~10 +table netdev t { + chain c { + type filter hook egress devices = { lo } priority 0; policy accept; + } +}
tests/shell/testcases/chains/0021prio_0 +6 -1
@@ -69,7 +69,7 @@ done family=netdev echo "add table $family x" gen_chains $family ingress filter lo -gen_chains $family egress filter lo +[ "$NFT_TEST_HAVE_netdev_egress" != n ] && gen_chains $family egress filter lo family=bridge echo "add table $family x"
@@ -83,3 +83,8 @@ gen_chains $family postrouting srcnat ) >$tmpfile $NFT -f $tmpfile + +if [ "$NFT_TEST_HAVE_netdev_egress" = n ]; then + echo "Ran a modified version of the test due to NFT_TEST_HAVE_netdev_egress=n" + exit 77 +fi
tests/shell/testcases/chains/0042chain_variable_0 +5 -0
@@ -24,6 +24,11 @@ table netdev filter2 { $NFT -f - <<< $EXPECTED +if [ "$NFT_TEST_HAVE_netdev_egress" = n ] ; then + echo "Skip parts of the test due to NFT_TEST_HAVE_netdev_egress=n" + exit 77 +fi + EXPECTED="define if_main = { lo, dummy0 } define lan_interfaces = { lo }
Signature · 1 line
2.41.0
PATCH 7/14 tests/shell: skip inet ingress tests if kernel lacks support
In reply to Thomas HallerFrom: Florian Westphal <[email protected]>
Split the bridge autoremove test to a new file.
--- tests/shell/features/inet_ingress.nft | 7 +++++++ tests/shell/testcases/chains/0043chain_ingress_0 | 9 ++------- .../testcases/chains/dumps/netdev_chain_autoremove.nft | 0 tests/shell/testcases/chains/netdev_chain_autoremove | 9 +++++++++ 4 files changed, 18 insertions(+), 7 deletions(-) create mode 100644 tests/shell/features/inet_ingress.nft create mode 100644 tests/shell/testcases/chains/dumps/netdev_chain_autoremove.nft create mode 100755 tests/shell/testcases/chains/netdev_chain_autoremove
tests/shell/features/inet_ingress.nft new file +7 -0
@@ -0,0 +1,7 @@ +# d3519cb89f6d ("netfilter: nf_tables: add inet ingress support") +# v5.10-rc1~107^2~17^2~1 +table inet t { + chain c { + type filter hook ingress device "lo" priority filter; policy accept; + } +}
tests/shell/testcases/chains/0043chain_ingress_0 +2 -7
@@ -1,7 +1,8 @@ #!/bin/bash -set -e +# NFT_TEST_REQUIRES(NFT_TEST_HAVE_inet_ingress) +set -e RULESET="table inet filter { chain ingress { type filter hook ingress device \"lo\" priority filter; policy accept;
@@ -14,11 +15,5 @@ RULESET="table inet filter { } }" -# Test auto-removal of chain hook on netns removal -unshare -n bash -c "ip link add br0 type bridge; \ - $NFT add table netdev test; \ - $NFT add chain netdev test ingress { type filter hook ingress device \"br0\" priority 0\; policy drop\; } ; \ -" || exit 1 - $NFT -f - <<< "$RULESET" && exit 0 exit 1
tests/shell/testcases/chains/dumps/netdev_chain_autoremove.nft new file +0 -0
tests/shell/testcases/chains/netdev_chain_autoremove new file +9 -0
@@ -0,0 +1,9 @@ +#!/bin/bash + +set -e + +# Test auto-removal of chain hook on netns removal +unshare -n bash -e -c "ip link add br0 type bridge; \ + $NFT add table netdev test; \ + $NFT add chain netdev test ingress { type filter hook ingress device \"br0\" priority 0\; policy drop\; } ; \ +"
Signature · 1 line
2.41.0
PATCH 8/14 tests/shell: skip destroy tests if kernel lacks support
In reply to Thomas HallerFrom: Florian Westphal <[email protected]>
Destroy support was added for table/flowtable/chain etc. in a single commit, so no need to add capability tests for each destroy subtype.
--- tests/shell/features/destroy.nft | 3 +++ tests/shell/testcases/chains/0044chain_destroy_0 | 2 ++ tests/shell/testcases/flowtable/0015destroy_0 | 2 ++ tests/shell/testcases/maps/0014destroy_0 | 2 ++ tests/shell/testcases/rule_management/0012destroy_0 | 2 ++ tests/shell/testcases/sets/0072destroy_0 | 2 ++ 6 files changed, 13 insertions(+) create mode 100644 tests/shell/features/destroy.nft
tests/shell/features/destroy.nft new file +3 -0
@@ -0,0 +1,3 @@ +# f80a612dd77c ("netfilter: nf_tables: add support to destroy operation") +# v6.3-rc1~162^2~264^2 +destroy table t
tests/shell/testcases/chains/0044chain_destroy_0 +2 -0
@@ -1,5 +1,7 @@ #!/bin/sh -e +# NFT_TEST_REQUIRES(NFT_TEST_HAVE_destroy) + $NFT add table t # pass for non-existent chain
tests/shell/testcases/flowtable/0015destroy_0 +2 -0
@@ -1,5 +1,7 @@ #!/bin/sh -e +# NFT_TEST_REQUIRES(NFT_TEST_HAVE_destroy) + $NFT add table t # pass for non-existent flowtable
tests/shell/testcases/maps/0014destroy_0 +2 -0
@@ -1,5 +1,7 @@ #!/bin/sh -e +# NFT_TEST_REQUIRES(NFT_TEST_HAVE_destroy) + $NFT add table x # pass for non-existent map
tests/shell/testcases/rule_management/0012destroy_0 +2 -0
@@ -1,5 +1,7 @@ #!/bin/sh -e +# NFT_TEST_REQUIRES(NFT_TEST_HAVE_destroy) + $NFT add table t $NFT add chain t c
tests/shell/testcases/sets/0072destroy_0 +2 -0
@@ -1,5 +1,7 @@ #!/bin/sh -e +# NFT_TEST_REQUIRES(NFT_TEST_HAVE_destroy) + $NFT add table x # pass for non-existent set
Signature · 1 line
2.41.0
PATCH 9/14 tests/shell: skip catchall tests if kernel lacks support
In reply to Thomas HallerFrom: Florian Westphal <[email protected]>
--- tests/shell/features/catchall_element.nft | 8 ++++++++ tests/shell/testcases/maps/0011vmap_0 | 10 +++++++++- tests/shell/testcases/maps/0017_map_variable_0 | 13 ++++++++++++- .../testcases/maps/map_catchall_double_deactivate | 2 ++ tests/shell/testcases/sets/0063set_catchall_0 | 2 ++ tests/shell/testcases/sets/0064map_catchall_0 | 2 ++ 6 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 tests/shell/features/catchall_element.nft
tests/shell/features/catchall_element.nft new file +8 -0
@@ -0,0 +1,8 @@ +# aaa31047a6d2 ("netfilter: nftables: add catch-all set element support") +# v5.13-rc1~94^2~10^2~2 +table t { + map m { + type inet_service : inet_service + elements = { * : 42 } + } +}
tests/shell/testcases/maps/0011vmap_0 +9 -1
@@ -22,4 +22,12 @@ EXPECTED="table inet filter { }" $NFT -f - <<< "$EXPECTED" -$NFT 'add element inet filter portmap { 22 : jump ssh_input, * : drop }' + +if [ "$NFT_TEST_HAVE_catchall_element" != n ]; then + $NFT 'add element inet filter portmap { 22 : jump ssh_input, * : drop }' +fi + +if [ "$NFT_TEST_HAVE_catchall_element" = n ]; then + echo "Ran partial tests due to NFT_TEST_HAVE_catchall_element=n (skipped)" + exit 77 +fi
tests/shell/testcases/maps/0017_map_variable_0 +12 -1
@@ -2,9 +2,15 @@ set -e +if [ "$NFT_TEST_HAVE_catchall_element" != n ] ; then + CATCHALL="* : 3," +else + CATCHALL="," +fi + RULESET="define x = { 1.1.1.1 : 2, - * : 3, + $CATCHALL } table ip x {
@@ -19,3 +25,8 @@ table ip x { }" $NFT -f - <<< "$RULESET" + +if [ "$NFT_TEST_HAVE_catchall_element" = n ] ; then + echo "Ran modified version of test due to NFT_TEST_HAVE_catchall_element=n (skipped)" + exit 77 +fi
tests/shell/testcases/maps/map_catchall_double_deactivate +2 -0
@@ -1,5 +1,7 @@ #!/bin/bash +# NFT_TEST_REQUIRES(NFT_TEST_HAVE_catchall_element) + $NFT "add table ip test ; add map ip test testmap { type ipv4_addr : verdict; }; add chain ip test testchain;
tests/shell/testcases/sets/0063set_catchall_0 +2 -0
@@ -1,5 +1,7 @@ #!/bin/bash +# NFT_TEST_REQUIRES(NFT_TEST_HAVE_catchall_element) + set -e RULESET="table ip x {
tests/shell/testcases/sets/0064map_catchall_0 +2 -0
@@ -1,5 +1,7 @@ #!/bin/bash +# NFT_TEST_REQUIRES(NFT_TEST_HAVE_catchall_element) + set -e RULESET="table ip x {
Signature · 1 line
2.41.0
PATCH 10/14 tests/shell: skip test cases involving osf match if kernel lacks support
In reply to Thomas HallerFrom: Florian Westphal <[email protected]>
--- tests/shell/features/osf.nft | 7 +++++++ tests/shell/testcases/maps/typeof_maps_0 | 19 +++++++++++++++---- tests/shell/testcases/sets/typeof_sets_0 | 23 +++++++++++++++++------ 3 files changed, 39 insertions(+), 10 deletions(-) create mode 100644 tests/shell/features/osf.nft
tests/shell/features/osf.nft new file +7 -0
@@ -0,0 +1,7 @@ +# b96af92d6eaf ("netfilter: nf_tables: implement Passive OS fingerprint module in nft_osf") +# v4.19-rc1~140^2~135^2~15 +table t { + chain c { + osf name "Linux" + } +}
tests/shell/testcases/maps/typeof_maps_0 +15 -4
@@ -4,11 +4,18 @@ # without typeof, this is 'type string' and 'type integer', # but neither could be used because it lacks size information. -EXPECTED="table inet t { - map m1 { +OSFMAP="" +OSFRULE="" +if [ "$NFT_TEST_HAVE_osf" != n ] ; then + OSFMAP="map m1 { typeof osf name : ct mark elements = { "Linux" : 0x00000001 } - } + }" + OSFRULE="ct mark set osf name map @m1" +fi + +EXPECTED="table inet t { + $OSFMAP map m2 { typeof vlan id : mark
@@ -33,7 +40,7 @@ EXPECTED="table inet t { } chain c { - ct mark set osf name map @m1 + $OSFRULE ether type vlan meta mark set vlan id map @m2 meta mark set ip saddr . ip daddr map @m3 iifname . ip protocol . th dport vmap @m4
@@ -45,3 +52,7 @@ EXPECTED="table inet t { set -e $NFT -f - <<< $EXPECTED +if [ "$NFT_TEST_HAVE_osf" = n ] ; then + echo "Partial test due to NFT_TEST_HAVE_osf=n. Skip" + exit 77 +fi
tests/shell/testcases/sets/typeof_sets_0 +17 -6
@@ -4,11 +4,20 @@ # s1 and s2 are identical, they just use different # ways for declaration. -EXPECTED="table inet t { - set s1 { +OSFSET="" +OSFCHAIN="" +if [ "$NFT_TEST_HAVE_osf" != n ] ; then + OSFSET="set s1 { typeof osf name elements = { \"Linux\" } - } + }" + OSFCHAIN="chain c1 { + osf name @s1 accept + }" +fi + +EXPECTED="table inet t { + $OSFSET set s2 { typeof vlan id
@@ -60,9 +69,7 @@ EXPECTED="table inet t { elements = { 3567 . 1.2.3.4 } } - chain c1 { - osf name @s1 accept - } + $OSFCHAIN chain c2 { ether type vlan vlan id @s2 accept
@@ -104,3 +111,7 @@ EXPECTED="table inet t { set -e $NFT -f - <<< $EXPECTED +if [ "$NFT_TEST_HAVE_osf" = n ] ; then + echo "Partial test due to NFT_TEST_HAVE_osf=n. Skip" + exit 77 +fi
Signature · 1 line
2.41.0
PATCH 11/14 tests/shell: skip test cases if ct expectation and/or timeout lacks support
In reply to Thomas HallerFrom: Florian Westphal <[email protected]>
--- tests/shell/features/ctexpect.nft | 10 ++++ tests/shell/features/cttimeout.nft | 8 +++ tests/shell/testcases/listing/0013objects_0 | 50 +++++-------------- .../testcases/listing/dumps/0013objects_0.nft | 2 - .../testcases/nft-f/0017ct_timeout_obj_0 | 2 + 5 files changed, 33 insertions(+), 39 deletions(-) create mode 100644 tests/shell/features/ctexpect.nft create mode 100644 tests/shell/features/cttimeout.nft
tests/shell/features/ctexpect.nft new file +10 -0
@@ -0,0 +1,10 @@ +# 857b46027d6f ("netfilter: nft_ct: add ct expectations support") +# v5.3-rc1~140^2~153^2~19 +table t { + ct expectation ctexpect { + protocol tcp + dport 5432 + timeout 1h + size 12; + } +}
tests/shell/features/cttimeout.nft new file +8 -0
@@ -0,0 +1,8 @@ +# 7e0b2b57f01d ("netfilter: nft_ct: add ct timeout support") +# v4.19-rc1~140^2~64^2~3 +table t { + ct timeout cttime { + protocol tcp; + policy = {established: 120 } + } +}
tests/shell/testcases/listing/0013objects_0 +13 -37
60 lines not on this page · raw message
tests/shell/testcases/listing/dumps/0013objects_0.nft +0 -2
@@ -25,5 +25,3 @@ table ip test { chain input { } } -table ip test-ip { -}
tests/shell/testcases/nft-f/0017ct_timeout_obj_0 +2 -0
@@ -1,5 +1,7 @@ #!/bin/bash +# NFT_TEST_REQUIRES(NFT_TEST_HAVE_cttimeout) + EXPECTED='table ip filter { ct timeout cttime{ protocol tcp
Signature · 1 line
2.41.0
PATCH 12/14 tests/shell: skip reset tests if kernel lacks support
In reply to Thomas HallerFrom: Florian Westphal <[email protected]>
reset is implemented via flush + extra attribute, so older kernels perform a flush. This means .nft doesn't work, we need to check if the individual set contents/sets are still in place post-reset.
Make this generic and permit use of feat.sh in addition to the simpler foo.nft feature files.
--- tests/shell/features/reset_rule.sh | 8 ++++++ tests/shell/features/reset_set.sh | 10 ++++++++ tests/shell/run-tests.sh | 25 ++++++++++++++++--- .../testcases/rule_management/0011reset_0 | 2 ++ tests/shell/testcases/sets/reset_command_0 | 2 ++ 5 files changed, 43 insertions(+), 4 deletions(-) create mode 100755 tests/shell/features/reset_rule.sh create mode 100755 tests/shell/features/reset_set.sh
tests/shell/features/reset_rule.sh new file +8 -0
@@ -0,0 +1,8 @@ +#!/bin/bash + +# 8daa8fde3fc3 ("netfilter: nf_tables: Introduce NFT_MSG_GETRULE_RESET") +# v6.2-rc1~99^2~210^2~2 + +unshare -n bash -c "$NFT \"add table t; add chain t c ; add rule t c counter packets 1 bytes 42\"; \ +$NFT reset rules chain t c ; \ +$NFT reset rules chain t c |grep counter\ packets\ 0\ bytes\ 0"
tests/shell/features/reset_set.sh new file +10 -0
@@ -0,0 +1,10 @@ +#!/bin/bash + +# 079cd633219d ("netfilter: nf_tables: Introduce NFT_MSG_GETSETELEM_RESET") +# v6.5-rc1~163^2~9^2~1 + +unshare -n bash -c "$NFT add table t; \ + $NFT add set t s { type ipv4_addr\; counter\; elements = { 127.0.0.1 counter packets 1 bytes 2 } } ; \ + $NFT reset set t s ; \ + $NFT reset set t s | grep counter\ packets\ 0\ bytes\ 0 +"
tests/shell/run-tests.sh +21 -4
@@ -224,13 +224,13 @@ export NFT_TEST_BASEDIR _HAVE_OPTS=( json ) _HAVE_OPTS_NFT=() shopt -s nullglob -F=( "$NFT_TEST_BASEDIR/features/"*.nft ) +F=( "$NFT_TEST_BASEDIR/features/"*.nft "$NFT_TEST_BASEDIR/features/"*.sh ) shopt -u nullglob for file in "${F[@]}"; do feat="${file##*/}" - feat="${feat%.nft}" + feat="${feat%.*}" re="^[a-z_0-9]+$" - if [[ "$feat" =~ $re ]] && ! array_contains "$feat" "${_HAVE_OPTS[@]}" ; then + if [[ "$feat" =~ $re ]] && ! array_contains "$feat" "${_HAVE_OPTS[@]}" "${_HAVE_OPTS_NFT[@]}" && [[ "$file" != *.sh || -x "$file" ]] ; then _HAVE_OPTS_NFT+=( "$feat" ) else msg_warn "Ignore feature file \"$file\""
@@ -494,11 +494,28 @@ else fi export NFT_TEST_HAVE_json +feature_probe() +{ + local with_path="$NFT_TEST_BASEDIR/features/$1" + + if [ -r "$with_path.nft" ] ; then + $NFT_TEST_UNSHARE_CMD "$NFT_REAL" --check -f "$with_path.nft" &>/dev/null + return $? + fi + + if [ -x "$with_path.sh" ] ; then + NFT="$NFT_REAL" $NFT_TEST_UNSHARE_CMD "$with_path.sh" &>/dev/null + return $? + fi + + return 1 +} + for feat in "${_HAVE_OPTS_NFT[@]}" ; do var="NFT_TEST_HAVE_$feat" if [ -z "${!var+x}" ] ; then val='y' - $NFT_TEST_UNSHARE_CMD "$NFT_REAL" --check -f "$NFT_TEST_BASEDIR/features/$feat.nft" &>/dev/null || val='n' + feature_probe "$feat" || val='n' else val="$(bool_n "${!var}")" fi
tests/shell/testcases/rule_management/0011reset_0 +2 -0
@@ -1,5 +1,7 @@ #!/bin/bash +# NFT_TEST_REQUIRES(NFT_TEST_HAVE_reset_rule) + set -e echo "loading ruleset"
tests/shell/testcases/sets/reset_command_0 +2 -0
@@ -1,5 +1,7 @@ #!/bin/bash +# NFT_TEST_REQUIRES(NFT_TEST_HAVE_reset_set) + set -e trap '[[ $? -eq 0 ]] || echo FAIL' EXIT
Signature · 1 line
2.41.0
PATCH 13/14 tests/shell: implement NFT_TEST_HAVE_json feature detection as script
In reply to Thomas HallerNo more need to special case the "run a script" approach for detecting the json feature. Use the new mechanism instead.
--- tests/shell/features/json.sh | 6 ++++++ tests/shell/run-tests.sh | 18 ++++-------------- 2 files changed, 10 insertions(+), 14 deletions(-) create mode 100755 tests/shell/features/json.sh
tests/shell/features/json.sh new file +6 -0
@@ -0,0 +1,6 @@ +#!/bin/sh + +# Detect JSON support. Note that $NFT may not be the binary from our build +# tree, hence we detect it by running the binary (instead of asking the build +# configuration). +$NFT -j list ruleset
tests/shell/run-tests.sh +4 -14
@@ -221,8 +221,7 @@ NFT_TEST_BASEDIR="$(dirname "$0")" # Export the base directory. It may be used by tests. export NFT_TEST_BASEDIR -_HAVE_OPTS=( json ) -_HAVE_OPTS_NFT=() +_HAVE_OPTS=() shopt -s nullglob F=( "$NFT_TEST_BASEDIR/features/"*.nft "$NFT_TEST_BASEDIR/features/"*.sh ) shopt -u nullglob
@@ -230,13 +229,12 @@ for file in "${F[@]}"; do feat="${file##*/}" feat="${feat%.*}" re="^[a-z_0-9]+$" - if [[ "$feat" =~ $re ]] && ! array_contains "$feat" "${_HAVE_OPTS[@]}" "${_HAVE_OPTS_NFT[@]}" && [[ "$file" != *.sh || -x "$file" ]] ; then - _HAVE_OPTS_NFT+=( "$feat" ) + if [[ "$feat" =~ $re ]] && ! array_contains "$feat" "${_HAVE_OPTS[@]}" && [[ "$file" != *.sh || -x "$file" ]] ; then + _HAVE_OPTS+=( "$feat" ) else msg_warn "Ignore feature file \"$file\"" fi done -_HAVE_OPTS+=( "${_HAVE_OPTS_NFT[@]}" ) _HAVE_OPTS=( $(printf '%s\n' "${_HAVE_OPTS[@]}" | LANG=C sort) ) for KEY in $(compgen -v | grep '^NFT_TEST_HAVE_' | sort) ; do
@@ -486,14 +484,6 @@ fi NFT_REAL="${NFT_REAL-$NFT}" -if [ -z "${NFT_TEST_HAVE_json+x}" ] ; then - NFT_TEST_HAVE_json=y - $NFT_TEST_UNSHARE_CMD "$NFT_REAL" -j list ruleset &>/dev/null || NFT_TEST_HAVE_json=n -else - NFT_TEST_HAVE_json="$(bool_n "$NFT_TEST_HAVE_json")" -fi -export NFT_TEST_HAVE_json - feature_probe() { local with_path="$NFT_TEST_BASEDIR/features/$1"
@@ -511,7 +501,7 @@ feature_probe() return 1 } -for feat in "${_HAVE_OPTS_NFT[@]}" ; do +for feat in "${_HAVE_OPTS[@]}" ; do var="NFT_TEST_HAVE_$feat" if [ -z "${!var+x}" ] ; then val='y'
Signature · 1 line
2.41.0
PATCH 14/14 tests/shell: check diff in "maps/typeof_maps_0" and "sets/typeof_sets_0" test
In reply to Thomas HallerThese tests run different variants based on NFT_TEST_HAVE_osf support. Consequently, we cannot check the pre-generated diff.
Instead, construct what we expect dynamically in the script, and compare the ruleset against that.
--- tests/shell/testcases/maps/typeof_maps_0 | 75 ++++++++++--- tests/shell/testcases/sets/typeof_sets_0 | 133 ++++++++++++++++++++--- 2 files changed, 177 insertions(+), 31 deletions(-)
tests/shell/testcases/maps/typeof_maps_0 +59 -16
@@ -4,18 +4,24 @@ # without typeof, this is 'type string' and 'type integer', # but neither could be used because it lacks size information. -OSFMAP="" -OSFRULE="" -if [ "$NFT_TEST_HAVE_osf" != n ] ; then - OSFMAP="map m1 { - typeof osf name : ct mark - elements = { "Linux" : 0x00000001 } - }" - OSFRULE="ct mark set osf name map @m1" +set -e + +die() { + printf '%s\n' "$*" + exit 1 +} + +INPUT_OSF_CT=" + ct mark set osf name map @m1" +if [ "$NFT_TEST_HAVE_osf" = n ] ; then + INPUT_OSF_CT= fi -EXPECTED="table inet t { - $OSFMAP +INPUT="table inet t { + map m1 { + typeof osf name : ct mark + elements = { Linux : 0x00000001 } + } map m2 { typeof vlan id : mark
@@ -39,8 +45,7 @@ EXPECTED="table inet t { elements = { 23 . eth0 : accept } } - chain c { - $OSFRULE + chain c {$INPUT_OSF_CT ether type vlan meta mark set vlan id map @m2 meta mark set ip saddr . ip daddr map @m3 iifname . ip protocol . th dport vmap @m4
@@ -49,10 +54,48 @@ EXPECTED="table inet t { } }" -set -e -$NFT -f - <<< $EXPECTED +EXPECTED="table inet t { + map m1 { + typeof osf name : ct mark + elements = { \"Linux\" : 0x00000001 } + } + + map m2 { + typeof vlan id : meta mark + elements = { 1 : 0x00000001, 4095 : 0x00004095 } + } + + map m3 { + typeof ip saddr . ip daddr : meta mark + elements = { 1.2.3.4 . 5.6.7.8 : 0x00000001, + 2.3.4.5 . 6.7.8.9 : 0x00000002 } + } + + map m4 { + typeof iifname . ip protocol . th dport : verdict + elements = { \"eth0\" . tcp . 22 : accept } + } + + map m5 { + typeof ipsec in reqid . iifname : verdict + elements = { 23 . \"eth0\" : accept } + } + + chain c {$INPUT_OSF_CT + meta mark set vlan id map @m2 + meta mark set ip saddr . ip daddr map @m3 + iifname . ip protocol . th dport vmap @m4 + iifname . ip protocol . th dport vmap { \"eth0\" . tcp . 22 : accept, \"eth1\" . udp . 67 : drop } + ipsec in reqid . iifname vmap @m5 + } +}" + +$NFT -f - <<< "$INPUT" || die $'nft command failed to process input:\n'">$INPUT<" + +$DIFF -u <($NFT list ruleset) - <<<"$EXPECTED" || die $'diff failed between ruleset and expected data.\nExpected:\n'">$EXPECTED<" + if [ "$NFT_TEST_HAVE_osf" = n ] ; then - echo "Partial test due to NFT_TEST_HAVE_osf=n. Skip" - exit 77 + echo "Partial test due to NFT_TEST_HAVE_osf=n. Skip" + exit 77 fi
tests/shell/testcases/sets/typeof_sets_0 +118 -15
156 lines not on this page · raw message
Signature · 1 line
2.41.0