The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=2c53e251601c1fcd558f42a16f6030ba75b7e8df
commit 2c53e251601c1fcd558f42a16f6030ba75b7e8df Author: Kristof Provost <k...@freebsd.org> AuthorDate: 2025-08-28 15:36:03 +0000 Commit: Kristof Provost <k...@freebsd.org> CommitDate: 2025-09-25 12:41:10 +0000 pf tests: test once rule inside an anchor Sponsored by: Rubicon Communications, LLC ("Netgate") --- tests/sys/netpfil/pf/once.sh | 49 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/tests/sys/netpfil/pf/once.sh b/tests/sys/netpfil/pf/once.sh index 50ccb17e16c6..54dbb030dbe6 100644 --- a/tests/sys/netpfil/pf/once.sh +++ b/tests/sys/netpfil/pf/once.sh @@ -77,7 +77,56 @@ basic_cleanup() pft_cleanup } +atf_test_case "anchor" "cleanup" +anchor_head() +{ + atf_set descr 'Test one shot rule in anchors' + atf_set require.user root +} + +anchor_body() +{ + pft_init + epair=$(vnet_mkepair) + + vnet_mkjail alcatraz ${epair}a + jexec alcatraz ifconfig ${epair}a 192.0.2.1/24 up + + ifconfig ${epair}b 192.0.2.2/24 up + + # Sanity checks + atf_check -s exit:0 -o ignore \ + ping -c 1 192.0.2.1 + + jexec alcatraz pfctl -e + pft_set_rules alcatraz \ + "block" \ + "anchor \"once\" {\n + pass in from 192.0.2.2 once\n + }" + + # First once succeeds + atf_check -s exit:0 -o ignore \ + ping -c 3 192.0.2.1 + + # Check for '# expired' + jexec alcatraz pfctl -sr -vv -a "*" + atf_check -s exit:0 -e ignore \ + -o match:'pass in inet from 192.0.2.2 to any flags S/SA keep state once # expired' \ + jexec alcatraz pfctl -sr -vv -a "*" + + # The second one does not + atf_check -s exit:2 -o ignore \ + ping -c 3 192.0.2.1 +} + +anchor_cleanup() +{ + pft_cleanup +} + atf_init_test_cases() { atf_add_test_case "basic" + atf_add_test_case "anchor" }