aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristof Provost <kp@FreeBSD.org>2021-04-15 14:53:16 +0000
committerKristof Provost <kp@FreeBSD.org>2021-05-11 15:04:45 +0000
commit5c371d922aa859f7d674bea4ada22a15dee7bb0c (patch)
tree2b4af41fe9812a1e053ee9a057b3d769f629b9f2
parent898407819d8158154692a6cceb7757c9d7aa2d8b (diff)
downloadsrc-5c371d922aa859f7d674bea4ada22a15dee7bb0c.tar.gz
src-5c371d922aa859f7d674bea4ada22a15dee7bb0c.zip
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)
-rw-r--r--tests/sys/netpfil/pf/rules_counter.sh82
1 files changed, 82 insertions, 0 deletions
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"
}