aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristof Provost <kp@FreeBSD.org>2021-05-03 13:31:03 +0000
committerKristof Provost <kp@FreeBSD.org>2021-05-14 08:48:52 +0000
commit147c64747203053e55a28a4c5d7515f4d7cbce82 (patch)
treeee42ee204a89923ecac0903e31a350e04ca1dd2a
parent21449c5c1eee253dc5ce5a70632edba525f803e7 (diff)
downloadsrc-147c64747203053e55a28a4c5d7515f4d7cbce82.tar.gz
src-147c64747203053e55a28a4c5d7515f4d7cbce82.zip
pf tests: Test killing matching states
MFC after: 1 week Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D30093 (cherry picked from commit ac200a9c3847d3a92c347de60e32a7af430dede6)
-rw-r--r--tests/sys/netpfil/pf/killstate.sh71
1 files changed, 71 insertions, 0 deletions
diff --git a/tests/sys/netpfil/pf/killstate.sh b/tests/sys/netpfil/pf/killstate.sh
index ae0a4b88b228..131b6268daf7 100644
--- a/tests/sys/netpfil/pf/killstate.sh
+++ b/tests/sys/netpfil/pf/killstate.sh
@@ -305,10 +305,81 @@ gateway_cleanup()
pft_cleanup
}
+atf_test_case "match" "cleanup"
+match_head()
+{
+ atf_set descr 'Test killing matching states'
+ atf_set require.user root
+}
+
+match_body()
+{
+ pft_init
+
+ epair_one=$(vnet_mkepair)
+ ifconfig ${epair_one}a 192.0.2.1/24 up
+
+ epair_two=$(vnet_mkepair)
+
+ vnet_mkjail alcatraz ${epair_one}b ${epair_two}a
+ jexec alcatraz ifconfig ${epair_one}b 192.0.2.2/24 up
+ jexec alcatraz ifconfig ${epair_two}a 198.51.100.1/24 up
+ jexec alcatraz sysctl net.inet.ip.forwarding=1
+ jexec alcatraz pfctl -e
+
+ vnet_mkjail singsing ${epair_two}b
+ jexec singsing ifconfig ${epair_two}b 198.51.100.2/24 up
+ jexec singsing route add default 198.51.100.1
+ jexec singsing /usr/sbin/inetd -p inetd-echo.pid \
+ $(atf_get_srcdir)/echo_inetd.conf
+
+ route add 198.51.100.0/24 192.0.2.2
+
+ pft_set_rules alcatraz \
+ "nat on ${epair_two}a from 192.0.2.0/24 -> (${epair_two}a)" \
+ "pass all"
+
+ nc 198.51.100.2 7 &
+
+ # Expect two states
+ states=$(jexec alcatraz pfctl -s s | wc -l)
+ if [ $states -ne 2 ] ;
+ then
+ atf_fail "Expected two states, found $states"
+ fi
+
+ # If we don't kill the matching NAT state one should be left
+ jexec alcatraz pfctl -k 192.0.2.1
+ states=$(jexec alcatraz pfctl -s s | wc -l)
+ if [ $states -ne 1 ] ;
+ then
+ atf_fail "Expected one states, found $states"
+ fi
+
+ # Flush
+ jexec alcatraz pfctl -F states
+
+ nc 198.51.100.2 7 &
+
+ # Kill matching states, expect all of them to be gone
+ jexec alcatraz pfctl -M -k 192.0.2.1
+ states=$(jexec alcatraz pfctl -s s | wc -l)
+ if [ $states -ne 0 ] ;
+ then
+ atf_fail "Expected zero states, found $states"
+ fi
+}
+
+match_cleanup()
+{
+ pft_cleanup
+}
+
atf_init_test_cases()
{
atf_add_test_case "v4"
atf_add_test_case "label"
atf_add_test_case "multilabel"
atf_add_test_case "gateway"
+ atf_add_test_case "match"
}