git: 920c3410872c - main - pf tests: test dummynet on route-to'd packets

From: Kristof Provost <kp_at_FreeBSD.org>
Date: Thu, 12 May 2022 19:58:16 UTC
The branch main has been updated by kp:

URL: https://cgit.FreeBSD.org/src/commit/?id=920c3410872c93f0ca97dcc4c96a134746eb9393

commit 920c3410872c93f0ca97dcc4c96a134746eb9393
Author:     Kristof Provost <kp@FreeBSD.org>
AuthorDate: 2022-05-09 10:36:53 +0000
Commit:     Kristof Provost <kp@FreeBSD.org>
CommitDate: 2022-05-12 19:50:10 +0000

    pf tests: test dummynet on route-to'd packets
    
    Sponsored by:   Rubicon Communications, LLC ("Netgate")
    Differential Revision:  https://reviews.freebsd.org/D35161
---
 tests/sys/netpfil/pf/route_to.sh | 57 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)

diff --git a/tests/sys/netpfil/pf/route_to.sh b/tests/sys/netpfil/pf/route_to.sh
index 570d1feb36ff..f77b9a35b8ad 100644
--- a/tests/sys/netpfil/pf/route_to.sh
+++ b/tests/sys/netpfil/pf/route_to.sh
@@ -309,6 +309,62 @@ icmp_nat_cleanup()
 	pft_cleanup
 }
 
+atf_test_case "dummynet" "cleanup"
+dummynet_head()
+{
+	atf_set descr 'Test that dummynet applies to route-to packets'
+	atf_set require.user root
+}
+
+dummynet_body()
+{
+	dummynet_init
+
+	epair_srv=$(vnet_mkepair)
+	epair_gw=$(vnet_mkepair)
+
+	vnet_mkjail srv ${epair_srv}a
+	jexec srv ifconfig ${epair_srv}a 192.0.2.1/24 up
+	jexec srv route add default 192.0.2.2
+
+	vnet_mkjail gw ${epair_srv}b ${epair_gw}a
+	jexec gw ifconfig ${epair_srv}b 192.0.2.2/24 up
+	jexec gw ifconfig ${epair_gw}a 198.51.100.1/24 up
+	jexec gw sysctl net.inet.ip.forwarding=1
+
+	ifconfig ${epair_gw}b 198.51.100.2/24 up
+	route add -net 192.0.2.0/24 198.51.100.1
+
+	# Sanity check
+	atf_check -s exit:0 -o ignore ping -c 1 -t 1 192.0.2.1
+
+	jexec gw dnctl pipe 1 config delay 1200
+	pft_set_rules gw \
+		"pass out route-to (${epair_srv}b 192.0.2.1) to 192.0.2.1 dnpipe 1"
+	jexec gw pfctl -e
+
+	# The ping request will pass, but take 1.2 seconds
+	# So this works:
+	atf_check -s exit:0 -o ignore ping -c 1 192.0.2.1
+	# But this times out:
+	atf_check -s exit:2 -o ignore ping -c 1 -t 1 192.0.2.1
+
+	# return path dummynet
+	pft_set_rules gw \
+		"pass out route-to (${epair_srv}b 192.0.2.1) to 192.0.2.1 dnpipe (0, 1)"
+
+	# The ping request will pass, but take 1.2 seconds
+	# So this works:
+	atf_check -s exit:0 -o ignore ping -c 1 192.0.2.1
+	# But this times out:
+	atf_check -s exit:2 -o ignore ping -c 1 -t 1 192.0.2.1
+}
+
+dummynet_cleanup()
+{
+	pft_cleanup
+}
+
 atf_init_test_cases()
 {
 	atf_add_test_case "v4"
@@ -316,4 +372,5 @@ atf_init_test_cases()
 	atf_add_test_case "multiwan"
 	atf_add_test_case "multiwanlocal"
 	atf_add_test_case "icmp_nat"
+	atf_add_test_case "dummynet"
 }