]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
tests: shell: validate set size
authorPablo Neira Ayuso <pablo@netfilter.org>
Tue, 24 Jan 2017 18:33:07 +0000 (19:33 +0100)
committerPablo Neira Ayuso <pablo@netfilter.org>
Tue, 24 Jan 2017 18:34:48 +0000 (19:34 +0100)
Add two tests to make sure that set size checks work fine:

1) Check if set size is indeed working, this is a simple one.
2) Check if set size is correct after ENFILE error, there is bug that
   adds a new spare slot everytime we hit this.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
tests/shell/testcases/sets/0018set_check_size_1 [new file with mode: 0755]
tests/shell/testcases/sets/0019set_check_size_0 [new file with mode: 0755]

diff --git a/tests/shell/testcases/sets/0018set_check_size_1 b/tests/shell/testcases/sets/0018set_check_size_1
new file mode 100755 (executable)
index 0000000..833b8e2
--- /dev/null
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+set -e
+$NFT add table x
+$NFT add set x s {type ipv4_addr\; size 2\;}
+$NFT add element x s {1.1.1.1}
+$NFT add element x s {1.1.1.2}
+$NFT add element x s {1.1.1.3}
diff --git a/tests/shell/testcases/sets/0019set_check_size_0 b/tests/shell/testcases/sets/0019set_check_size_0
new file mode 100755 (executable)
index 0000000..c209708
--- /dev/null
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+$NFT add table x
+$NFT add set x s {type ipv4_addr\; size 2\;}
+$NFT add element x s {1.1.1.1}
+$NFT add element x s {1.1.1.2}
+
+$NFT add element x s { 1.1.1.3 } 2>/dev/null
+if [ $? -eq 0 ]; then
+        echo "E: set is full, but element was added" >&2
+       exit 1
+fi
+#
+# Try again, this helps us catch incorrect set->nelems decrement from abort path
+#
+$NFT add element x s { 1.1.1.3 } 2>/dev/null
+if [ $? -eq 0 ]; then
+        echo "E: set is full, but element was added" >&2
+       exit 1
+fi