aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristof Provost <kp@FreeBSD.org>2022-12-31 18:23:15 +0000
committerKristof Provost <kp@FreeBSD.org>2023-01-28 01:34:38 +0000
commit2cfb60783900b625798c5ceb52b9aa93c5c412ae (patch)
treec16f24aa67df148a3c7b435956131a039b2a00a4
parent14f52003bd8ae8884fcf8223e2170a7d76a39006 (diff)
downloadsrc-2cfb60783900b625798c5ceb52b9aa93c5c412ae.tar.gz
src-2cfb60783900b625798c5ceb52b9aa93c5c412ae.zip
pf tests: test fast port re-use with syncookies
When a src/dst ip/port tuple is re-used before the pf state fully expires we clean up the state and create a new one, unless syncookies are enabled. Test this, by running two back-to-back nc sessions, with a fixed source port. Move the interface and IP to a different (vnet) jail, to trick the network stack into letting us do this. MFC after: 2 weeks Event: Aberdeen hackathon 2022 Differential Revision: https://reviews.freebsd.org/D36886 (cherry picked from commit dc698b2cd59ebc08b05a261dbba8ee5707450d28)
-rw-r--r--tests/sys/netpfil/pf/syncookie.sh57
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/sys/netpfil/pf/syncookie.sh b/tests/sys/netpfil/pf/syncookie.sh
index d85beac1a4d1..dbb6407e9c38 100644
--- a/tests/sys/netpfil/pf/syncookie.sh
+++ b/tests/sys/netpfil/pf/syncookie.sh
@@ -217,10 +217,67 @@ adaptive_cleanup()
pft_cleanup
}
+atf_test_case "port_reuse" "cleanup"
+port_reuse_head()
+{
+ atf_set descr 'Test rapid port re-use'
+ atf_set require.user root
+}
+
+port_reuse_body()
+{
+ pft_init
+
+ epair=$(vnet_mkepair)
+
+ vnet_mkjail alcatraz ${epair}b
+ vnet_mkjail singsing
+ jexec alcatraz ifconfig ${epair}b 192.0.2.1/24 up
+ jexec alcatraz /usr/sbin/inetd -p ${HOME}/inetd-alcatraz.pid \
+ $(atf_get_srcdir)/echo_inetd.conf
+
+ ifconfig ${epair}a 192.0.2.2/24 up
+
+ jexec alcatraz pfctl -e
+ jexec alcatraz pfctl -x loud
+ pft_set_rules alcatraz \
+ "set syncookies always" \
+ "pass in" \
+ "pass out"
+
+ # Sanity check
+ atf_check -s exit:0 -o ignore ping -c 1 192.0.2.1
+
+ reply=$(echo foo | nc -p 1234 -N -w 5 192.0.2.1 7)
+ if [ "${reply}" != "foo" ];
+ then
+ atf_fail "Failed to connect to syncookie protected echo daemon"
+ fi
+
+ # We can't re-use the source IP/port combo quickly enough, so we're
+ # going to play a really dirty trick, and move our interface to a new
+ # jail, and do it from there.
+ ifconfig ${epair}a vnet singsing
+ jexec singsing ifconfig ${epair}a 192.0.2.2/24 up
+ atf_check -s exit:0 -o ignore jexec singsing ping -c 1 192.0.2.1
+
+ reply=$(echo bar | jexec singsing nc -p 1234 -N -w 5 192.0.2.1 7)
+ if [ "${reply}" != "bar" ];
+ then
+ atf_fail "Failed to connect to syncookie protected echo daemon (2)"
+ fi
+}
+
+port_reuse_cleanup()
+{
+ pft_cleanup
+}
+
atf_init_test_cases()
{
atf_add_test_case "basic"
atf_add_test_case "forward"
atf_add_test_case "nostate"
atf_add_test_case "adaptive"
+ atf_add_test_case "port_reuse"
}