git: 6790b1257b63 - stable/12 - pf tests: Test set keepcounters
Kristof Provost
kp at FreeBSD.org
Tue May 11 15:06:47 UTC 2021
The branch stable/12 has been updated by kp:
URL: https://cgit.FreeBSD.org/src/commit/?id=6790b1257b634ba212142d3c8968e1f2fbe08fa5
commit 6790b1257b634ba212142d3c8968e1f2fbe08fa5
Author: Kristof Provost <kp at FreeBSD.org>
AuthorDate: 2021-04-15 14:53:16 +0000
Commit: Kristof Provost <kp at FreeBSD.org>
CommitDate: 2021-05-11 08:28:33 +0000
pf tests: Test set keepcounters
MFC after: 4 weeks
Sponsored by: Rubicon Communications, LLC ("Netgate")
Differential Revision: https://reviews.freebsd.org/D29781
(cherry picked from commit e14d56f370184fdf7ef33ec57883a45f4a220cff)
---
tests/sys/netpfil/pf/rules_counter.sh | 82 +++++++++++++++++++++++++++++++++++
1 file changed, 82 insertions(+)
diff --git a/tests/sys/netpfil/pf/rules_counter.sh b/tests/sys/netpfil/pf/rules_counter.sh
index 56dc159f49c8..567bf439b0ef 100644
--- a/tests/sys/netpfil/pf/rules_counter.sh
+++ b/tests/sys/netpfil/pf/rules_counter.sh
@@ -73,7 +73,89 @@ get_clear_cleanup()
pft_cleanup
}
+atf_test_case "keepcounters" "cleanup"
+keepcounters_head()
+{
+ atf_set descr 'Test keepcounter functionality'
+ atf_set require.user root
+}
+
+keepcounters_body()
+{
+ pft_init
+
+ epair_send=$(vnet_mkepair)
+ ifconfig ${epair_send}a 192.0.2.1/24 up
+
+ vnet_mkjail alcatraz ${epair_send}b
+ jexec alcatraz ifconfig ${epair_send}b 192.0.2.2/24 up
+ jexec alcatraz pfctl -e
+
+ pft_set_rules alcatraz \
+ "pass all"
+
+ # Expect zero counters
+ atf_check -s exit:0 -e ignore \
+ -o match:'Evaluations: 0[[:space:]]*Packets: 0*[[:space:]]*Bytes: 0*[[:space:]]*' \
+ jexec alcatraz pfctl -s r -v
+
+ # Ensure the rule matched packets, so we can verify non-zero counters
+ atf_check -s exit:0 -o ignore ping -c 3 192.0.2.2
+
+ # Expect non-zero counters
+ atf_check -s exit:0 -e ignore \
+ -o match:'Evaluations: [1-9][0-9]*[[:space:]]*Packets: [1-9][0-9]*[[:space:]]*Bytes: [1-9][0-9]*[[:space:]]*' \
+ jexec alcatraz pfctl -s r -v
+
+ # As we set the (same) rules again we'd expect the counters to return
+ # to zero
+ pft_set_rules noflush alcatraz \
+ "pass all"
+
+ atf_check -s exit:0 -e ignore \
+ -o match:'Evaluations: 0[[:space:]]*Packets: 0*[[:space:]]*Bytes: 0*[[:space:]]*' \
+ jexec alcatraz pfctl -s r -v
+
+ # Increment rule counters
+ atf_check -s exit:0 -o ignore ping -c 3 192.0.2.2
+
+ # Now set new rules with 'keepcounters' set, so we'd expect nonzero
+ # counters
+ pft_set_rules noflush alcatraz \
+ "set keepcounters" \
+ "pass all"
+
+ atf_check -s exit:0 -e ignore \
+ -o match:'Evaluations: [1-9][0-9]*[[:space:]]*Packets: [1-9][0-9]*[[:space:]]*Bytes: [1-9][0-9]*[[:space:]]*' \
+ jexec alcatraz pfctl -s r -v
+
+ # However, if we set a different rule it should return to zero
+ pft_set_rules noflush alcatraz \
+ "set keepcounters" \
+ "pass inet all"
+
+ atf_check -s exit:0 -e ignore \
+ -o match:'Evaluations: 0[[:space:]]*Packets: 0*[[:space:]]*Bytes: 0*[[:space:]]*' \
+ jexec alcatraz pfctl -s r -v
+
+ # If we generate traffic and don't set keepcounters we also see zero
+ # counts when setting new rules
+ atf_check -s exit:0 -o ignore ping -c 3 192.0.2.2
+ pft_set_rules noflush alcatraz \
+ "pass inet all"
+
+ atf_check -s exit:0 -e ignore \
+ -o match:'Evaluations: 0[[:space:]]*Packets: 0*[[:space:]]*Bytes: 0*[[:space:]]*' \
+ jexec alcatraz pfctl -s r -v
+}
+
+keepcounters_cleanup()
+{
+ pft_cleanup
+}
+
atf_init_test_cases()
{
atf_add_test_case "get_clear"
+ atf_add_test_case "keepcounters"
}
More information about the dev-commits-src-all
mailing list