From: Thomas Haller <thaller@redhat.com>
To: NetFilter <netfilter-devel@vger.kernel.org>
Cc: Florian Westphal <fw@strlen.de>, Thomas Haller <thaller@redhat.com>
Subject: [PATCH nft 12/14] tests/shell: skip reset tests if kernel lacks support
Date: Mon, 18 Sep 2023 12:28:26 +0200 [thread overview]
Message-ID: <20230918102947.2125883-13-thaller@redhat.com> (raw)
In-Reply-To: <20230918102947.2125883-1-thaller@redhat.com>
From: Florian Westphal <fw@strlen.de>
reset is implemented via flush + extra attribute, so older kernels
perform a flush. This means .nft doesn't work, we need to check
if the individual set contents/sets are still in place post-reset.
Make this generic and permit use of feat.sh in addition to the simpler
foo.nft feature files.
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Thomas Haller <thaller@redhat.com>
---
tests/shell/features/reset_rule.sh | 8 ++++++
tests/shell/features/reset_set.sh | 10 ++++++++
tests/shell/run-tests.sh | 25 ++++++++++++++++---
.../testcases/rule_management/0011reset_0 | 2 ++
tests/shell/testcases/sets/reset_command_0 | 2 ++
5 files changed, 43 insertions(+), 4 deletions(-)
create mode 100755 tests/shell/features/reset_rule.sh
create mode 100755 tests/shell/features/reset_set.sh
diff --git a/tests/shell/features/reset_rule.sh b/tests/shell/features/reset_rule.sh
new file mode 100755
index 000000000000..567ee2f1a4bd
--- /dev/null
+++ b/tests/shell/features/reset_rule.sh
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+# 8daa8fde3fc3 ("netfilter: nf_tables: Introduce NFT_MSG_GETRULE_RESET")
+# v6.2-rc1~99^2~210^2~2
+
+unshare -n bash -c "$NFT \"add table t; add chain t c ; add rule t c counter packets 1 bytes 42\"; \
+$NFT reset rules chain t c ; \
+$NFT reset rules chain t c |grep counter\ packets\ 0\ bytes\ 0"
diff --git a/tests/shell/features/reset_set.sh b/tests/shell/features/reset_set.sh
new file mode 100755
index 000000000000..3d034175d82a
--- /dev/null
+++ b/tests/shell/features/reset_set.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+# 079cd633219d ("netfilter: nf_tables: Introduce NFT_MSG_GETSETELEM_RESET")
+# v6.5-rc1~163^2~9^2~1
+
+unshare -n bash -c "$NFT add table t; \
+ $NFT add set t s { type ipv4_addr\; counter\; elements = { 127.0.0.1 counter packets 1 bytes 2 } } ; \
+ $NFT reset set t s ; \
+ $NFT reset set t s | grep counter\ packets\ 0\ bytes\ 0
+"
diff --git a/tests/shell/run-tests.sh b/tests/shell/run-tests.sh
index d11b4a63b6d1..9c7e280e31c7 100755
--- a/tests/shell/run-tests.sh
+++ b/tests/shell/run-tests.sh
@@ -224,13 +224,13 @@ export NFT_TEST_BASEDIR
_HAVE_OPTS=( json )
_HAVE_OPTS_NFT=()
shopt -s nullglob
-F=( "$NFT_TEST_BASEDIR/features/"*.nft )
+F=( "$NFT_TEST_BASEDIR/features/"*.nft "$NFT_TEST_BASEDIR/features/"*.sh )
shopt -u nullglob
for file in "${F[@]}"; do
feat="${file##*/}"
- feat="${feat%.nft}"
+ feat="${feat%.*}"
re="^[a-z_0-9]+$"
- if [[ "$feat" =~ $re ]] && ! array_contains "$feat" "${_HAVE_OPTS[@]}" ; then
+ if [[ "$feat" =~ $re ]] && ! array_contains "$feat" "${_HAVE_OPTS[@]}" "${_HAVE_OPTS_NFT[@]}" && [[ "$file" != *.sh || -x "$file" ]] ; then
_HAVE_OPTS_NFT+=( "$feat" )
else
msg_warn "Ignore feature file \"$file\""
@@ -494,11 +494,28 @@ else
fi
export NFT_TEST_HAVE_json
+feature_probe()
+{
+ local with_path="$NFT_TEST_BASEDIR/features/$1"
+
+ if [ -r "$with_path.nft" ] ; then
+ $NFT_TEST_UNSHARE_CMD "$NFT_REAL" --check -f "$with_path.nft" &>/dev/null
+ return $?
+ fi
+
+ if [ -x "$with_path.sh" ] ; then
+ NFT="$NFT_REAL" $NFT_TEST_UNSHARE_CMD "$with_path.sh" &>/dev/null
+ return $?
+ fi
+
+ return 1
+}
+
for feat in "${_HAVE_OPTS_NFT[@]}" ; do
var="NFT_TEST_HAVE_$feat"
if [ -z "${!var+x}" ] ; then
val='y'
- $NFT_TEST_UNSHARE_CMD "$NFT_REAL" --check -f "$NFT_TEST_BASEDIR/features/$feat.nft" &>/dev/null || val='n'
+ feature_probe "$feat" || val='n'
else
val="$(bool_n "${!var}")"
fi
diff --git a/tests/shell/testcases/rule_management/0011reset_0 b/tests/shell/testcases/rule_management/0011reset_0
index 8d2307964c37..33eadd9eb562 100755
--- a/tests/shell/testcases/rule_management/0011reset_0
+++ b/tests/shell/testcases/rule_management/0011reset_0
@@ -1,5 +1,7 @@
#!/bin/bash
+# NFT_TEST_REQUIRES(NFT_TEST_HAVE_reset_rule)
+
set -e
echo "loading ruleset"
diff --git a/tests/shell/testcases/sets/reset_command_0 b/tests/shell/testcases/sets/reset_command_0
index ad2e16a7d274..5e769fe66d68 100755
--- a/tests/shell/testcases/sets/reset_command_0
+++ b/tests/shell/testcases/sets/reset_command_0
@@ -1,5 +1,7 @@
#!/bin/bash
+# NFT_TEST_REQUIRES(NFT_TEST_HAVE_reset_set)
+
set -e
trap '[[ $? -eq 0 ]] || echo FAIL' EXIT
--
2.41.0
next prev parent reply other threads:[~2023-09-18 10:32 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-18 10:28 [PATCH nft 00/14] tests/shell: fix tests to skip on lacking feature support Thomas Haller
2023-09-18 10:28 ` [PATCH nft 01/14] tests/shell: add and use chain binding feature probe Thomas Haller
2023-09-18 10:28 ` [PATCH nft 02/14] tests/shell: skip netdev_chain_0 if kernel requires netdev device Thomas Haller
2023-09-18 10:28 ` [PATCH nft 03/14] tests/shell: skip map query if kernel lacks support Thomas Haller
2023-09-18 10:28 ` [PATCH nft 04/14] tests/shell: skip inner matching tests if unsupported Thomas Haller
2023-09-18 10:28 ` [PATCH nft 05/14] tests/shell: skip bitshift tests if kernel lacks support Thomas Haller
2023-09-18 10:28 ` [PATCH nft 06/14] tests/shell: skip some tests if kernel lacks netdev egress support Thomas Haller
2023-09-18 10:28 ` [PATCH nft 07/14] tests/shell: skip inet ingress tests if kernel lacks support Thomas Haller
2023-09-18 10:28 ` [PATCH nft 08/14] tests/shell: skip destroy " Thomas Haller
2023-09-18 10:28 ` [PATCH nft 09/14] tests/shell: skip catchall " Thomas Haller
2023-09-18 10:28 ` [PATCH nft 10/14] tests/shell: skip test cases involving osf match " Thomas Haller
2023-09-18 10:28 ` [PATCH nft 11/14] tests/shell: skip test cases if ct expectation and/or timeout " Thomas Haller
2023-09-18 10:28 ` Thomas Haller [this message]
2023-09-18 10:28 ` [PATCH nft 13/14] tests/shell: implement NFT_TEST_HAVE_json feature detection as script Thomas Haller
2023-09-18 10:28 ` [PATCH nft 14/14] tests/shell: check diff in "maps/typeof_maps_0" and "sets/typeof_sets_0" test Thomas Haller
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=20230918102947.2125883-13-thaller@redhat.com \
--to=thaller@redhat.com \
--cc=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).