]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
tests: shell: Fix ifname_based_hooks feature check
authorPhil Sutter <phil@nwl.cc>
Wed, 25 Jun 2025 16:53:36 +0000 (18:53 +0200)
committerFlorian Westphal <fw@strlen.de>
Thu, 26 Jun 2025 12:06:51 +0000 (14:06 +0200)
The test was technically incorrect: Instead of detecting whether
interface hooks are name-based or not, it actually tested whether
netdev-family chains are removed along with their last hook.

Since the latter behaviour is established in kernel commit fc0133428e7a
("netfilter: nf_tables: Tolerate chains with no remaining hooks") and
thus independent from the name-based hooks change, treating both as the
same kernel feature is not acceptable.

Fix this by detecting whether a netdev-family chain may be added despite
specifying a non-existent interface to hook into. Keep the old check
around with a better name, although unused for now.

Reported-by: Florian Westphal <fw@strlen.de>
Fixes: f27e5abd81f29 ("tests: shell: Adjust to ifname-based hooks")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
tests/shell/features/empty_netdev_chains.sh [new file with mode: 0755]
tests/shell/features/ifname_based_hooks.sh

diff --git a/tests/shell/features/empty_netdev_chains.sh b/tests/shell/features/empty_netdev_chains.sh
new file mode 100755 (executable)
index 0000000..cada695
--- /dev/null
@@ -0,0 +1,12 @@
+#!/bin/bash
+
+# check if netdev chains survive without a single device
+
+unshare -n bash -c "ip link add d0 type dummy; \
+       $NFT \"table netdev t { \
+               chain c { \
+                       type filter hook ingress priority 0; devices = { d0 }; \
+               }; \
+       }\"; \
+       ip link del d0; \
+       $NFT list chain netdev t c"
index cada6956f165badd750a07e4b6a7b840c9b5b426..1f6af531c8c42eafc3190d3e93c82dbd0d744d9b 100755 (executable)
@@ -1,12 +1,12 @@
 #!/bin/bash
 
-# check if netdev chains survive without a single device
+# check if adding a netdev-family chain hooking into a non-existent device is
+# accepted or not
 
-unshare -n bash -c "ip link add d0 type dummy; \
-       $NFT \"table netdev t { \
-               chain c { \
-                       type filter hook ingress priority 0; devices = { d0 }; \
-               }; \
-       }\"; \
-       ip link del d0; \
-       $NFT list chain netdev t c"
+RULESET="table netdev t {
+       chain c {
+               type filter hook ingress priority 0
+               devices = { foobar123 }
+       }
+}"
+unshare -n $NFT -f - <<< "$RULESET"