]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
ebtables: Avoid dropping policy when flushing
authorPhil Sutter <phil@nwl.cc>
Wed, 15 Sep 2021 15:37:51 +0000 (17:37 +0200)
committerPhil Sutter <phil@nwl.cc>
Wed, 15 Sep 2021 16:12:58 +0000 (18:12 +0200)
Unlike nftables, ebtables' user-defined chains have policies -
ebtables-nft implements those internally as invisible last rule. In
order to recreate them after a flush command, a rule cache is needed.

https://bugzilla.netfilter.org/show_bug.cgi?id=1558

iptables/nft-cmd.c
iptables/tests/shell/testcases/ebtables/0007-chain-policies_0 [new file with mode: 0755]

index 35b392689c2f191867253218d68be1d52f72a0d0..2d874bd41e8f64aee388c7b1182f6c9b923e2cdc 100644 (file)
@@ -167,7 +167,9 @@ int nft_cmd_rule_flush(struct nft_handle *h, const char *chain,
        if (!cmd)
                return 0;
 
-       if (chain || verbose)
+       if (h->family == NFPROTO_BRIDGE)
+               nft_cache_level_set(h, NFT_CL_RULES, cmd);
+       else if (chain || verbose)
                nft_cache_level_set(h, NFT_CL_CHAINS, cmd);
        else
                nft_cache_level_set(h, NFT_CL_TABLES, cmd);
diff --git a/iptables/tests/shell/testcases/ebtables/0007-chain-policies_0 b/iptables/tests/shell/testcases/ebtables/0007-chain-policies_0
new file mode 100755 (executable)
index 0000000..faf37d0
--- /dev/null
@@ -0,0 +1,41 @@
+#!/bin/sh
+
+case "$XT_MULTI" in
+*xtables-nft-multi)
+       ;;
+*)
+       echo "skip $XT_MULTI"
+       exit 0
+       ;;
+esac
+
+set -e
+
+# ebtables supports policies in user-defined chains %)
+# and the default policy is ACCEPT ...
+$XT_MULTI ebtables -N FOO -P DROP
+$XT_MULTI ebtables -N BAR
+$XT_MULTI ebtables -P BAR RETURN
+$XT_MULTI ebtables -N BAZ
+
+EXPECT_BASE="*filter
+:INPUT ACCEPT
+:FORWARD ACCEPT
+:OUTPUT ACCEPT"
+
+EXPECT="$EXPECT_BASE
+:BAR RETURN
+:BAZ ACCEPT
+:FOO DROP"
+
+diff -u -Z <(echo -e "$EXPECT") <($XT_MULTI ebtables-save | grep -v '^#')
+
+# rule commands must not break the policies
+$XT_MULTI ebtables -A FOO -j ACCEPT
+$XT_MULTI ebtables -D FOO -j ACCEPT
+$XT_MULTI ebtables -F
+diff -u -Z <(echo -e "$EXPECT") <($XT_MULTI ebtables-save | grep -v '^#')
+
+# dropping the chains must implicitly remove the policy rule as well
+$XT_MULTI ebtables -X
+diff -u -Z <(echo -e "$EXPECT_BASE") <($XT_MULTI ebtables-save | grep -v '^#')