pf tests: test block/no-match limiters

Sponsored by:	Rubicon Communications, LLC ("Netgate")
This commit is contained in:
Kristof Provost
2026-01-13 09:54:28 +01:00
parent e28dfd6b55
commit 098febfcc1
+56
View File
@@ -130,6 +130,61 @@ state_rate_cleanup()
pft_cleanup
}
atf_test_case "state_block" "cleanup"
state_block_head()
{
atf_set descr 'Test block mode state limiter'
atf_set require.user root
}
state_block_body()
{
pft_init
epair=$(vnet_mkepair)
ifconfig ${epair}a 192.0.2.2/24 up
vnet_mkjail alcatraz ${epair}b
jexec alcatraz ifconfig ${epair}b 192.0.2.1/24 up
# Sanity check
atf_check -s exit:0 -o ignore \
ping -c 1 192.0.2.1
jexec alcatraz pfctl -e
# Allow one ICMP state per 5 seconds
pft_set_rules alcatraz \
"set timeout icmp.error 120" \
"state limiter \"server\" id 1 limit 1000 rate 1/5" \
"pass" \
"pass in proto icmp state limiter \"server\" (block)"
atf_check -s exit:0 -o ignore \
ping -c 2 192.0.2.1
# This should now fail
atf_check -s exit:2 -o ignore \
ping -c 2 192.0.2.1
# However, if we set no-match and exceed the limit we just pass
pft_set_rules alcatraz \
"set timeout icmp.error 120" \
"state limiter \"server\" id 1 limit 1000 rate 1/5" \
"pass" \
"pass in proto icmp state limiter \"server\" (no-match)"
atf_check -s exit:0 -o ignore \
ping -c 2 192.0.2.1
atf_check -s exit:0 -o ignore \
ping -c 2 192.0.2.1
}
state_block_cleanup()
{
pft_cleanup
}
atf_test_case "source_basic" "cleanup"
source_basic_head()
{
@@ -205,5 +260,6 @@ atf_init_test_cases()
{
atf_add_test_case "state_basic"
atf_add_test_case "state_rate"
atf_add_test_case "state_block"
atf_add_test_case "source_basic"
}