git: 32cac604487b - main - pf tests: test dummynet on nat64 rules

From: Kristof Provost <kp_at_FreeBSD.org>
Date: Tue, 17 Dec 2024 10:08:19 UTC
The branch main has been updated by kp:

URL: https://cgit.FreeBSD.org/src/commit/?id=32cac604487b4c6a8588c5df7641bdb5b452711f

commit 32cac604487b4c6a8588c5df7641bdb5b452711f
Author:     Kristof Provost <kp@FreeBSD.org>
AuthorDate: 2024-12-12 14:35:34 +0000
Commit:     Kristof Provost <kp@FreeBSD.org>
CommitDate: 2024-12-17 10:07:18 +0000

    pf tests: test dummynet on nat64 rules
    
    Sponsored by:   Rubicon Communications, LLC ("Netgate")
---
 tests/sys/netpfil/pf/nat64.sh | 55 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)

diff --git a/tests/sys/netpfil/pf/nat64.sh b/tests/sys/netpfil/pf/nat64.sh
index 318b6a61bcab..79fa0c99a311 100644
--- a/tests/sys/netpfil/pf/nat64.sh
+++ b/tests/sys/netpfil/pf/nat64.sh
@@ -555,6 +555,60 @@ table_round_robin_cleanup()
 	pft_cleanup
 }
 
+atf_test_case "dummynet" "cleanup"
+dummynet_head()
+{
+	atf_set descr 'Test dummynet on af-to rules'
+	atf_set require.user root
+}
+
+dummynet_body()
+{
+	pft_init
+	dummynet_init
+
+	epair_link=$(vnet_mkepair)
+	epair=$(vnet_mkepair)
+
+	ifconfig ${epair}a inet6 2001:db8::2/64 up no_dad
+	route -6 add default 2001:db8::1
+
+	vnet_mkjail rtr ${epair}b ${epair_link}a
+	jexec rtr ifconfig ${epair}b inet6 2001:db8::1/64 up no_dad
+	jexec rtr ifconfig ${epair_link}a 192.0.2.1/24 up
+
+	vnet_mkjail dst ${epair_link}b
+	jexec dst ifconfig ${epair_link}b 192.0.2.2/24 up
+	jexec dst route add default 192.0.2.1
+
+	# Sanity checks
+	atf_check -s exit:0 -o ignore \
+	    ping6 -c 1 2001:db8::1
+	atf_check -s exit:0 -o ignore \
+	    jexec dst ping -c 1 192.0.2.1
+
+	jexec rtr pfctl -e
+	jexec rtr dnctl pipe 1 config delay 600
+	pft_set_rules rtr \
+	    "set reassemble yes" \
+	    "set state-policy if-bound" \
+	    "pass in on ${epair}b inet6 from any to 64:ff9b::/96 dnpipe 1 af-to inet from (${epair_link}a)"
+
+	# The ping request will pass, but take 1.2 seconds (.6 in, .6 out)
+	# So this works:
+	atf_check -s exit:0 -o ignore \
+	    ping6 -c 1 -t 2 64:ff9b::192.0.2.2
+
+	# But this times out:
+	atf_check -s exit:2 -o ignore \
+	    ping6 -c 1 -t 1 64:ff9b::192.0.2.2
+}
+
+dummynet_cleanup()
+{
+	pft_cleanup
+}
+
 atf_init_test_cases()
 {
 	atf_add_test_case "icmp_echo"
@@ -569,4 +623,5 @@ atf_init_test_cases()
 	atf_add_test_case "table"
 	atf_add_test_case "table_range"
 	atf_add_test_case "table_round_robin"
+	atf_add_test_case "dummynet"
 }