summaryrefslogtreecommitdiffstats
path: root/tests/shell
diff options
context:
space:
mode:
authorPhil Sutter <phil@nwl.cc>2018-09-28 18:17:31 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2018-10-03 12:19:35 +0200
commit2e0ea44c99e466ea0bcb6aca5de95e2c7284f09c (patch)
tree06ed992f7fe29512d3971ffa3ecc27336fdd4891 /tests/shell
parent3ef117927cf4cf4d6b18667b9e6105cdbf96fc99 (diff)
tests: shell: Test 'get element' command
This command is currently broken when used in sets with ranges. Test various variants against known data and check if output is as expected. Signed-off-by: Phil Sutter <phil@nwl.cc> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'tests/shell')
-rwxr-xr-xtests/shell/testcases/sets/0034get_element_037
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/shell/testcases/sets/0034get_element_0 b/tests/shell/testcases/sets/0034get_element_0
new file mode 100755
index 00000000..2bfb527b
--- /dev/null
+++ b/tests/shell/testcases/sets/0034get_element_0
@@ -0,0 +1,37 @@
+#!/bin/bash
+
+RC=0
+
+check() { # (elems, expected)
+ out=$($NFT get element ip t s "{ $1 }" 2>/dev/null)
+ out=$(grep "elements =" <<< "$out")
+ out="${out#* \{ }"
+ out="${out% \}}"
+ [[ "$out" == "$2" ]] && return
+ echo "ERROR: asked for '$1', expecting '$2' but got '$out'"
+ ((RC++))
+}
+
+RULESET="add table ip t
+add set ip t s { type inet_service; flags interval; }
+add element ip t s { 10, 20-30, 40, 50-60 }
+"
+
+$NFT -f - <<< "$RULESET"
+
+# simple cases, (non-)existing values and ranges
+check 10 10
+check 11 ""
+check 20-30 20-30
+check 15-18 ""
+
+# multiple single elements, ranges smaller than present
+check "10, 40" "10, 40"
+check 21-29 20-30
+
+# non-existing ranges matching elements
+check 10-40 ""
+check 10-25 ""
+check 25-55 ""
+
+exit $RC