]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
tests: shell: cover reset command with counter and quota
authorPablo Neira Ayuso <pablo@netfilter.org>
Sun, 25 Aug 2024 22:41:45 +0000 (00:41 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Mon, 26 Aug 2024 16:38:33 +0000 (18:38 +0200)
Tested-by: Eric Garver <eric@garver.life>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
tests/shell/testcases/listing/reset_objects [new file with mode: 0755]

diff --git a/tests/shell/testcases/listing/reset_objects b/tests/shell/testcases/listing/reset_objects
new file mode 100755 (executable)
index 0000000..0b6720b
--- /dev/null
@@ -0,0 +1,104 @@
+#!/bin/bash
+
+set -e
+
+load_ruleset()
+{
+       $NFT -f - <<EOF
+table ip test {
+       quota https-quota {
+               25 mbytes used 10 mbytes
+       }
+       counter https-counter {
+               packets 10 bytes 4096
+       }
+}
+EOF
+}
+
+check_list_quota()
+{
+       EXPECT="table ip test {
+       quota https-quota {
+               25 mbytes
+       }
+}"
+       $DIFF -u <(echo "$EXPECT") <($NFT list quotas)
+}
+
+check_list_counter()
+{
+       EXPECT="table ip test {
+       counter https-counter {
+               packets 0 bytes 0
+       }
+}"
+       $DIFF -u <(echo "$EXPECT") <($NFT list counters)
+}
+
+load_ruleset
+
+EXPECT="table ip test {
+       quota https-quota {
+               25 mbytes used 10 mbytes
+       }
+}"
+$DIFF -u <(echo "$EXPECT") <($NFT reset quotas)
+
+check_list_quota
+$NFT flush ruleset
+load_ruleset
+
+EXPECT="table ip test {
+       quota https-quota {
+               25 mbytes used 10 mbytes
+       }
+}"
+$DIFF -u <(echo "$EXPECT") <($NFT reset quotas ip)
+
+check_list_quota
+$NFT flush ruleset
+load_ruleset
+
+EXPECT="table ip test {
+       quota https-quota {
+               25 mbytes used 10 mbytes
+       }
+}"
+$DIFF -u <(echo "$EXPECT") <($NFT reset quota ip test https-quota)
+
+check_list_quota
+$NFT flush ruleset
+load_ruleset
+
+EXPECT="table ip test {
+       counter https-counter {
+               packets 10 bytes 4096
+       }
+}"
+$DIFF -u <(echo "$EXPECT") <($NFT reset counters)
+
+check_list_counter
+$NFT flush ruleset
+load_ruleset
+
+EXPECT="table ip test {
+       counter https-counter {
+               packets 10 bytes 4096
+       }
+}"
+$DIFF -u <(echo "$EXPECT") <($NFT reset counters ip)
+
+check_list_counter
+$NFT flush ruleset
+load_ruleset
+
+EXPECT="table ip test {
+       counter https-counter {
+               packets 10 bytes 4096
+       }
+}"
+$DIFF -u <(echo "$EXPECT") <($NFT reset counter ip test https-counter)
+
+check_list_counter
+$NFT flush ruleset