summaryrefslogtreecommitdiffstats
path: root/tests/shell/testcases/maps
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2023-09-18 12:28:28 +0200
committerFlorian Westphal <fw@strlen.de>2023-09-18 13:09:03 +0200
commit78fa7db4885496fd906ccbfbe0a6a3deed81c8a8 (patch)
tree1071d3d16d640244609cabab9107882ca2b4b7b1 /tests/shell/testcases/maps
parentf30cb622d27e4b14454bccb4b9c0c990a68888df (diff)
tests/shell: check diff in "maps/typeof_maps_0" and "sets/typeof_sets_0" test
These tests run different variants based on NFT_TEST_HAVE_osf support. Consequently, we cannot check the pre-generated diff. Instead, construct what we expect dynamically in the script, and compare the ruleset against that. Signed-off-by: Thomas Haller <thaller@redhat.com> Signed-off-by: Florian Westphal <fw@strlen.de>
Diffstat (limited to 'tests/shell/testcases/maps')
-rwxr-xr-xtests/shell/testcases/maps/typeof_maps_075
1 files changed, 59 insertions, 16 deletions
diff --git a/tests/shell/testcases/maps/typeof_maps_0 b/tests/shell/testcases/maps/typeof_maps_0
index 263390d5..98517fd5 100755
--- a/tests/shell/testcases/maps/typeof_maps_0
+++ b/tests/shell/testcases/maps/typeof_maps_0
@@ -4,18 +4,24 @@
# without typeof, this is 'type string' and 'type integer',
# but neither could be used because it lacks size information.
-OSFMAP=""
-OSFRULE=""
-if [ "$NFT_TEST_HAVE_osf" != n ] ; then
- OSFMAP="map m1 {
- typeof osf name : ct mark
- elements = { "Linux" : 0x00000001 }
- }"
- OSFRULE="ct mark set osf name map @m1"
+set -e
+
+die() {
+ printf '%s\n' "$*"
+ exit 1
+}
+
+INPUT_OSF_CT="
+ ct mark set osf name map @m1"
+if [ "$NFT_TEST_HAVE_osf" = n ] ; then
+ INPUT_OSF_CT=
fi
-EXPECTED="table inet t {
- $OSFMAP
+INPUT="table inet t {
+ map m1 {
+ typeof osf name : ct mark
+ elements = { Linux : 0x00000001 }
+ }
map m2 {
typeof vlan id : mark
@@ -39,8 +45,7 @@ EXPECTED="table inet t {
elements = { 23 . eth0 : accept }
}
- chain c {
- $OSFRULE
+ chain c {$INPUT_OSF_CT
ether type vlan meta mark set vlan id map @m2
meta mark set ip saddr . ip daddr map @m3
iifname . ip protocol . th dport vmap @m4
@@ -49,10 +54,48 @@ EXPECTED="table inet t {
}
}"
-set -e
-$NFT -f - <<< $EXPECTED
+EXPECTED="table inet t {
+ map m1 {
+ typeof osf name : ct mark
+ elements = { \"Linux\" : 0x00000001 }
+ }
+
+ map m2 {
+ typeof vlan id : meta mark
+ elements = { 1 : 0x00000001, 4095 : 0x00004095 }
+ }
+
+ map m3 {
+ typeof ip saddr . ip daddr : meta mark
+ elements = { 1.2.3.4 . 5.6.7.8 : 0x00000001,
+ 2.3.4.5 . 6.7.8.9 : 0x00000002 }
+ }
+
+ map m4 {
+ typeof iifname . ip protocol . th dport : verdict
+ elements = { \"eth0\" . tcp . 22 : accept }
+ }
+
+ map m5 {
+ typeof ipsec in reqid . iifname : verdict
+ elements = { 23 . \"eth0\" : accept }
+ }
+
+ chain c {$INPUT_OSF_CT
+ meta mark set vlan id map @m2
+ meta mark set ip saddr . ip daddr map @m3
+ iifname . ip protocol . th dport vmap @m4
+ iifname . ip protocol . th dport vmap { \"eth0\" . tcp . 22 : accept, \"eth1\" . udp . 67 : drop }
+ ipsec in reqid . iifname vmap @m5
+ }
+}"
+
+$NFT -f - <<< "$INPUT" || die $'nft command failed to process input:\n'">$INPUT<"
+
+$DIFF -u <($NFT list ruleset) - <<<"$EXPECTED" || die $'diff failed between ruleset and expected data.\nExpected:\n'">$EXPECTED<"
+
if [ "$NFT_TEST_HAVE_osf" = n ] ; then
- echo "Partial test due to NFT_TEST_HAVE_osf=n. Skip"
- exit 77
+ echo "Partial test due to NFT_TEST_HAVE_osf=n. Skip"
+ exit 77
fi