]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
tests: add typeof test cases
authorFlorian Westphal <fw@strlen.de>
Fri, 16 Aug 2019 12:22:01 +0000 (14:22 +0200)
committerFlorian Westphal <fw@strlen.de>
Tue, 17 Dec 2019 22:10:46 +0000 (23:10 +0100)
Add sets using unspecific string/integer types, one with
osf name, other with vlan id.  Neither type can be used directly,
as they lack the type size information.

Signed-off-by: Florian Westphal <fw@strlen.de>
tests/shell/testcases/maps/dumps/typeof_maps_0.nft [new file with mode: 0644]
tests/shell/testcases/maps/typeof_maps_0 [new file with mode: 0755]
tests/shell/testcases/sets/dumps/typeof_sets_0.nft [new file with mode: 0644]
tests/shell/testcases/sets/typeof_sets_0 [new file with mode: 0755]

diff --git a/tests/shell/testcases/maps/dumps/typeof_maps_0.nft b/tests/shell/testcases/maps/dumps/typeof_maps_0.nft
new file mode 100644 (file)
index 0000000..4361ca3
--- /dev/null
@@ -0,0 +1,16 @@
+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 }
+       }
+
+       chain c {
+               ct mark set osf name map @m1
+               meta mark set vlan id map @m2
+       }
+}
diff --git a/tests/shell/testcases/maps/typeof_maps_0 b/tests/shell/testcases/maps/typeof_maps_0
new file mode 100755 (executable)
index 0000000..950bbf1
--- /dev/null
@@ -0,0 +1,27 @@
+#!/bin/bash
+
+# support for strings and integers in named maps.
+# without typeof, this is 'type string' and 'type integer',
+# but neither could be used because it lacks size information.
+
+EXPECTED="table inet t {
+       map m1 {
+               typeof osf name : ct mark
+               elements = { "Linux" : 0x00000001 }
+       }
+
+       map m2 {
+               typeof vlan id : mark
+               elements = { 1 : 0x1,
+                            4095 : 0x4095 }
+       }
+
+       chain c {
+               ct mark set osf name map @m1
+               ether type vlan meta mark set vlan id map @m2
+       }
+}"
+
+set -e
+$NFT -f - <<< $EXPECTED
+
diff --git a/tests/shell/testcases/sets/dumps/typeof_sets_0.nft b/tests/shell/testcases/sets/dumps/typeof_sets_0.nft
new file mode 100644 (file)
index 0000000..44e1120
--- /dev/null
@@ -0,0 +1,19 @@
+table inet t {
+       set s1 {
+               typeof osf name
+               elements = { "Linux" }
+       }
+
+       set s2 {
+               typeof vlan id
+               elements = { 2, 3, 103 }
+       }
+
+       chain c1 {
+               osf name @s1 accept
+       }
+
+       chain c2 {
+               vlan id @s2 accept
+       }
+}
diff --git a/tests/shell/testcases/sets/typeof_sets_0 b/tests/shell/testcases/sets/typeof_sets_0
new file mode 100755 (executable)
index 0000000..2a8b21c
--- /dev/null
@@ -0,0 +1,29 @@
+#!/bin/bash
+
+# support for strings/typeof in named sets.
+# s1 and s2 are identical, they just use different
+# ways for declaration.
+
+EXPECTED="table inet t {
+       set s1 {
+               typeof osf name
+               elements = { \"Linux\" }
+       }
+
+       set s2 {
+               typeof vlan id
+               elements = { 2, 3, 103 }
+       }
+
+       chain c1 {
+               osf name @s1 accept
+       }
+
+       chain c2 {
+               ether type vlan vlan id @s2 accept
+       }
+}"
+
+set -e
+$NFT -f - <<< $EXPECTED
+