From: Florian Westphal <fw@strlen.de>
To: <netfilter-devel@vger.kernel.org>
Cc: Florian Westphal <fw@strlen.de>
Subject: [PATCH nft 6/6] tests: add test case for removal of anon sets with only a single element
Date: Thu, 27 May 2021 17:43:23 +0200 [thread overview]
Message-ID: <20210527154323.4003-7-fw@strlen.de> (raw)
In-Reply-To: <20210527154323.4003-1-fw@strlen.de>
Signed-off-by: Florian Westphal <fw@strlen.de>
---
.../optimizations/dumps/single_anon_set.nft | 12 ++++++++
.../single_anon_set.replace-single-anon-sets | 12 ++++++++
.../testcases/optimizations/single_anon_set | 30 +++++++++++++++++++
3 files changed, 54 insertions(+)
create mode 100644 tests/shell/testcases/optimizations/dumps/single_anon_set.nft
create mode 100644 tests/shell/testcases/optimizations/dumps/single_anon_set.replace-single-anon-sets
create mode 100755 tests/shell/testcases/optimizations/single_anon_set
diff --git a/tests/shell/testcases/optimizations/dumps/single_anon_set.nft b/tests/shell/testcases/optimizations/dumps/single_anon_set.nft
new file mode 100644
index 000000000000..5320bcfc360a
--- /dev/null
+++ b/tests/shell/testcases/optimizations/dumps/single_anon_set.nft
@@ -0,0 +1,12 @@
+table ip test {
+ chain test {
+ ip saddr { 127.0.0.1 } accept
+ ip saddr { 127.0.0.0/8 } accept
+ ip saddr { 127.0.0.1-192.168.7.3 } accept
+ ip daddr { 192.168.7.1, 192.168.7.5 } accept
+ tcp dport { 80, 443 } accept
+ tcp dport != { 22 } drop
+ tcp sport { 1-1023 } drop
+ iif { "lo" } accept
+ }
+}
diff --git a/tests/shell/testcases/optimizations/dumps/single_anon_set.replace-single-anon-sets b/tests/shell/testcases/optimizations/dumps/single_anon_set.replace-single-anon-sets
new file mode 100644
index 000000000000..b9afa245fc16
--- /dev/null
+++ b/tests/shell/testcases/optimizations/dumps/single_anon_set.replace-single-anon-sets
@@ -0,0 +1,12 @@
+table ip test {
+ chain test {
+ ip saddr 127.0.0.1 accept
+ ip saddr 127.0.0.0/8 accept
+ ip saddr 127.0.0.1-192.168.7.3 accept
+ ip daddr { 192.168.7.1, 192.168.7.5 } accept
+ tcp dport { 80, 443 } accept
+ tcp dport != 22 drop
+ tcp sport 1-1023 drop
+ iif "lo" accept
+ }
+}
diff --git a/tests/shell/testcases/optimizations/single_anon_set b/tests/shell/testcases/optimizations/single_anon_set
new file mode 100755
index 000000000000..81c8533b2a57
--- /dev/null
+++ b/tests/shell/testcases/optimizations/single_anon_set
@@ -0,0 +1,30 @@
+#!/bin/bash
+
+set -e
+
+# Input file contains rules with anon sets that contain
+# one element, plus extra rule with two elements (that should be
+# left alone).
+
+# Second file contains a postprocessed version with rules
+# translated to simple equality test rather than set lookup.
+dumpfile=$(dirname $0)/dumps/$(basename $0).nft
+dumpfile_pp=$(dirname $0)/dumps/$(basename $0).replace-single-anon-sets
+
+$NFT -O replace-single-anon-sets -f "$dumpfile"
+A=$(mktemp)
+$NFT list ruleset > "$A"
+
+# This checks that -O no-remove... kept all auto-generated
+# dependencies, even though the imported file doesn't
+# mention them.
+
+diff -u "$A" "$dumpfile_pp"
+ret=$?
+
+rm -f "$A"
+
+$NFT delete table ip test
+$NFT -f "$dumpfile"
+
+exit $ret
--
2.26.3
prev parent reply other threads:[~2021-05-27 15:43 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-27 15:43 [PATCH nft 0/6] nftables: add --optimize support Florian Westphal
2021-05-27 15:43 ` [PATCH nft 1/6] src: add proto ctx options Florian Westphal
2021-05-27 15:43 ` [PATCH nft 2/6] src: allow to turn off dependency removal Florian Westphal
2021-05-27 15:43 ` [PATCH nft 3/6] main: add -O help to dump list of supported optimzation flags Florian Westphal
2021-05-27 15:43 ` [PATCH nft 4/6] evaluate: optionally kill anon sets with one element Florian Westphal
2021-05-27 15:43 ` [PATCH nft 5/6] tests: add test case for -O no-remove-dependencies Florian Westphal
2021-05-27 15:43 ` Florian Westphal [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=20210527154323.4003-7-fw@strlen.de \
--to=fw@strlen.de \
--cc=netfilter-devel@vger.kernel.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).