From: Phil Sutter <phil@nwl.cc>
To: netfilter-devel@vger.kernel.org
Cc: Florian Westphal <fw@strlen.de>,
Pablo Neira Ayuso <pablo@netfilter.org>, Eric Garver <e@erig.me>,
danw@redhat.com, aauren@gmail.com
Subject: [iptables PATCH 4/4] tests: Test compat mode
Date: Fri, 5 May 2023 20:34:46 +0200 [thread overview]
Message-ID: <20230505183446.28822-5-phil@nwl.cc> (raw)
In-Reply-To: <20230505183446.28822-1-phil@nwl.cc>
Extend iptables-test.py by a third mode, which is using
xtables-nft-multi and passing --compat to all calls creating rules.
Also add a shell testcase asserting the effectiveness of --compat by
comparing debug (-vv) output.
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
iptables-test.py | 19 ++++--
.../testcases/nft-only/0011-compat-mode_0 | 61 +++++++++++++++++++
2 files changed, 76 insertions(+), 4 deletions(-)
create mode 100755 iptables/tests/shell/testcases/nft-only/0011-compat-mode_0
diff --git a/iptables-test.py b/iptables-test.py
index ef0a35d3daa22..d41778ba4e653 100755
--- a/iptables-test.py
+++ b/iptables-test.py
@@ -28,6 +28,8 @@ EBTABLES_SAVE = "ebtables-save"
#IPTABLES_SAVE = ['xtables-save','-4']
#IP6TABLES_SAVE = ['xtables-save','-6']
+COMPAT_ARG = ""
+
EXTENSIONS_PATH = "extensions"
LOGFILE="/tmp/iptables-test.log"
log_file = None
@@ -83,7 +85,7 @@ STDERR_IS_TTY = sys.stderr.isatty()
'''
ret = 0
- cmd = iptables + " -A " + rule
+ cmd = iptables + COMPAT_ARG + " -A " + rule
ret = execute_cmd(cmd, filename, lineno, netns)
#
@@ -318,7 +320,7 @@ STDERR_IS_TTY = sys.stderr.isatty()
# load all rules via iptables_restore
- command = EXECUTABLE + " " + iptables + "-restore"
+ command = EXECUTABLE + " " + iptables + "-restore" + COMPAT_ARG
if netns:
command = "ip netns exec " + netns + " " + command
@@ -555,6 +557,8 @@ STDERR_IS_TTY = sys.stderr.isatty()
help='Check for missing tests')
parser.add_argument('-n', '--nftables', action='store_true',
help='Test iptables-over-nftables')
+ parser.add_argument('-c', '--nft-compat', action='store_true',
+ help='Test iptables-over-nftables in compat mode')
parser.add_argument('-N', '--netns', action='store_const',
const='____iptables-container-test',
help='Test netnamespace path')
@@ -574,8 +578,10 @@ STDERR_IS_TTY = sys.stderr.isatty()
variants.append("legacy")
if args.nftables:
variants.append("nft")
+ if args.nft_compat:
+ variants.append("nft_compat")
if len(variants) == 0:
- variants = [ "legacy", "nft" ]
+ variants = [ "legacy", "nft", "nft_compat" ]
if os.getuid() != 0:
print("You need to be root to run this, sorry", file=sys.stderr)
@@ -595,7 +601,12 @@ STDERR_IS_TTY = sys.stderr.isatty()
total_tests = 0
for variant in variants:
global EXECUTABLE
- EXECUTABLE = "xtables-" + variant + "-multi"
+ global COMPAT_ARG
+ if variant == "nft_compat":
+ EXECUTABLE = "xtables-nft-multi"
+ COMPAT_ARG = " --compat"
+ else:
+ EXECUTABLE = "xtables-" + variant + "-multi"
test_files = 0
tests = 0
diff --git a/iptables/tests/shell/testcases/nft-only/0011-compat-mode_0 b/iptables/tests/shell/testcases/nft-only/0011-compat-mode_0
new file mode 100755
index 0000000000000..b339dd9ec870b
--- /dev/null
+++ b/iptables/tests/shell/testcases/nft-only/0011-compat-mode_0
@@ -0,0 +1,61 @@
+#!/bin/bash
+
+[[ $XT_MULTI == *xtables-nft-multi ]] || { echo "skip $XT_MULTI"; exit 0; }
+
+set -e
+
+# reduce noise in debug output
+$XT_MULTI iptables -t raw -A OUTPUT
+$XT_MULTI iptables -t raw -F
+
+# add all the things which were "optimized" here
+RULE='-t raw -A OUTPUT'
+
+# prefix matches on class (actually: byte) boundaries no longer need a bitwise
+RULE+=' -s 10.0.0.0/8 -d 192.168.0.0/16'
+
+# these were turned into native matches meanwhile
+# (plus -m tcp, but it conflicts with -m udp)
+RULE+=' -m limit --limit 1/min'
+RULE+=' -p udp -m udp --sport 1024:65535'
+RULE+=' -m mark --mark 0xfeedcafe/0xfeedcafe'
+RULE+=' -j TRACE'
+
+EXPECT_COMMON='TRACE udp opt -- in * out * 10.0.0.0/8 -> 192.168.0.0/16 limit: avg 1/min burst 5 udp spts:1024:65535 mark match 0xfeedcafe/0xfeedcafe
+ip raw OUTPUT
+ [ meta load l4proto => reg 1 ]
+ [ cmp eq reg 1 0x00000011 ]'
+
+EXPECT="$EXPECT_COMMON
+ [ payload load 1b @ network header + 12 => reg 1 ]
+ [ cmp eq reg 1 0x0000000a ]
+ [ payload load 2b @ network header + 16 => reg 1 ]
+ [ cmp eq reg 1 0x0000a8c0 ]
+ [ limit rate 1/minute burst 5 type packets flags 0x0 ]
+ [ payload load 2b @ transport header + 0 => reg 1 ]
+ [ range eq reg 1 0x00000004 0x0000ffff ]
+ [ meta load mark => reg 1 ]
+ [ bitwise reg 1 = ( reg 1 & 0xfeedcafe ) ^ 0x00000000 ]
+ [ cmp eq reg 1 0xfeedcafe ]
+ [ counter pkts 0 bytes 0 ]
+ [ immediate reg 9 0x00000001 ]
+ [ meta set nftrace with reg 9 ]
+"
+
+diff -u -Z <(echo -e "$EXPECT") <($XT_MULTI iptables -vv $RULE)
+
+EXPECT="$EXPECT_COMMON
+ [ payload load 4b @ network header + 12 => reg 1 ]
+ [ bitwise reg 1 = ( reg 1 & 0x000000ff ) ^ 0x00000000 ]
+ [ cmp eq reg 1 0x0000000a ]
+ [ payload load 4b @ network header + 16 => reg 1 ]
+ [ bitwise reg 1 = ( reg 1 & 0x0000ffff ) ^ 0x00000000 ]
+ [ cmp eq reg 1 0x0000a8c0 ]
+ [ match name limit rev 0 ]
+ [ match name udp rev 0 ]
+ [ match name mark rev 1 ]
+ [ counter pkts 0 bytes 0 ]
+ [ target name TRACE rev 0 ]
+"
+
+diff -u -Z <(echo -e "$EXPECT") <($XT_MULTI iptables --compat -vv $RULE)
--
2.40.0
prev parent reply other threads:[~2023-05-05 18:35 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-05 18:34 [iptables PATCH 0/4] Implement a best-effort forward compat solution Phil Sutter
2023-05-05 18:34 ` [iptables PATCH 1/4] nft: Pass nft_handle to add_{target,action}() Phil Sutter
2023-05-05 18:34 ` [iptables PATCH 2/4] nft: Introduce and use bool nft_handle::compat Phil Sutter
2023-05-05 18:34 ` [iptables PATCH 3/4] Add --compat option to *tables-nft and *-nft-restore commands Phil Sutter
2023-05-31 0:16 ` Pablo Neira Ayuso
2023-05-31 9:02 ` Phil Sutter
2023-05-31 11:28 ` Florian Westphal
2023-05-31 12:10 ` Phil Sutter
2023-06-23 16:52 ` Phil Sutter
2023-05-05 18:34 ` Phil Sutter [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230505183446.28822-5-phil@nwl.cc \
--to=phil@nwl.cc \
--cc=aauren@gmail.com \
--cc=danw@redhat.com \
--cc=e@erig.me \
--cc=fw@strlen.de \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).