Skip to contentSkip to conversation

tests: shell: Fix ifname_based_hooks feature check

PATCH In review Phil Sutter 2 participants 3 messages Jun 25, 2025 – Jun 26, 2025 netfilter

lore
Share & tools
lore

Phil Sutter

author reviewer
#0 lore raw

PATCH 1/1 tests: shell: Fix ifname_based_hooks feature check

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.

Fixes f27e5abd81f29 ("tests: shell: Adjust to ifname-based hooks")
---
 tests/shell/features/empty_netdev_chains.sh | 12 ++++++++++++
 tests/shell/features/ifname_based_hooks.sh  | 18 +++++++++---------
 2 files changed, 21 insertions(+), 9 deletions(-)
 create mode 100755 tests/shell/features/empty_netdev_chains.sh
tests/shell/features/empty_netdev_chains.sh new file +12 -0
new file mode 100755
index 0000000000000..cada6956f165b
@@ -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"
tests/shell/features/ifname_based_hooks.sh +9 -9
index cada6956f165b..1f6af531c8c42 100755
@@ -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"
Signature · 1 line
2.49.0
maintainer
#1 lore raw
Quoted 3 lines · Phil Sutter

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.

Thanks, this makes shell tests pass on fedora 42 again, so I pushed it out.

author reviewer
#2 lore raw
Quoted 7 lines · Florian Westphal
Quoted 3 lines · Phil Sutter

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.

Thanks, this makes shell tests pass on fedora 42 again, so I pushed it out.

Perfect, thanks!