git: 661d0031bbc6 - main - pf tests: test the new received-on feature
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 16 Sep 2024 13:05:23 UTC
The branch main has been updated by kp:
URL: https://cgit.FreeBSD.org/src/commit/?id=661d0031bbc6b5623eb11234a9c4f20c6a1a5972
commit 661d0031bbc6b5623eb11234a9c4f20c6a1a5972
Author: Kristof Provost <kp@FreeBSD.org>
AuthorDate: 2024-09-06 13:06:35 +0000
Commit: Kristof Provost <kp@FreeBSD.org>
CommitDate: 2024-09-16 11:48:20 +0000
pf tests: test the new received-on feature
Reviewed by: zlei
Sponsored by: Rubicon Communications, LLC ("Netgate")
Differential Revision: https://reviews.freebsd.org/D46578
---
sbin/pfctl/tests/files/pf1022.in | 1 +
sbin/pfctl/tests/files/pf1022.ok | 1 +
sbin/pfctl/tests/pfctl_test_list.inc | 1 +
tests/sys/netpfil/pf/pass_block.sh | 82 ++++++++++++++++++++++++++++++++++++
4 files changed, 85 insertions(+)
diff --git a/sbin/pfctl/tests/files/pf1022.in b/sbin/pfctl/tests/files/pf1022.in
new file mode 100644
index 000000000000..640eb1334100
--- /dev/null
+++ b/sbin/pfctl/tests/files/pf1022.in
@@ -0,0 +1 @@
+pass out on em0 from 192.0.2.1 to 198.51.100.1 received-on fxp0
diff --git a/sbin/pfctl/tests/files/pf1022.ok b/sbin/pfctl/tests/files/pf1022.ok
new file mode 100644
index 000000000000..2f7b4a5bd616
--- /dev/null
+++ b/sbin/pfctl/tests/files/pf1022.ok
@@ -0,0 +1 @@
+pass out on em0 inet from 192.0.2.1 to 198.51.100.1 received-on fxp0 flags S/SA keep state
diff --git a/sbin/pfctl/tests/pfctl_test_list.inc b/sbin/pfctl/tests/pfctl_test_list.inc
index 1fd31de6ccc4..0ab336ec100d 100644
--- a/sbin/pfctl/tests/pfctl_test_list.inc
+++ b/sbin/pfctl/tests/pfctl_test_list.inc
@@ -130,3 +130,4 @@ PFCTL_TEST(1018, "Test dynamic address mask")
PFCTL_TEST(1019, "Test pflow option")
PFCTL_TEST(1020, "Test hashmark and semicolon comment")
PFCTL_TEST(1021, "Endpoint-independent")
+PFCTL_TEST(1022, "Test received-on")
diff --git a/tests/sys/netpfil/pf/pass_block.sh b/tests/sys/netpfil/pf/pass_block.sh
index faf5c2de4de2..36218d8e673f 100644
--- a/tests/sys/netpfil/pf/pass_block.sh
+++ b/tests/sys/netpfil/pf/pass_block.sh
@@ -292,6 +292,87 @@ urpf_cleanup()
pft_cleanup
}
+atf_test_case "received_on" "cleanup"
+received_on_head()
+{
+ atf_set descr 'Test received-on filtering'
+ atf_set require.user root
+}
+
+received_on_body()
+{
+ pft_init
+
+ epair_one=$(vnet_mkepair)
+ epair_two=$(vnet_mkepair)
+ epair_route=$(vnet_mkepair)
+
+ vnet_mkjail alcatraz ${epair_one}b ${epair_two}b ${epair_route}a
+ vnet_mkjail srv ${epair_route}b
+
+ ifconfig ${epair_one}a 192.0.2.2/24 up
+ ifconfig ${epair_two}a 198.51.100.2/24 up
+ route add 203.0.113.2 192.0.2.1
+ route add 203.0.113.3 198.51.100.1
+
+ jexec alcatraz ifconfig ${epair_one}b 192.0.2.1/24 up
+ jexec alcatraz ifconfig ${epair_two}b 198.51.100.1/24 up
+ jexec alcatraz ifconfig ${epair_route}a 203.0.113.1/24 up
+ jexec alcatraz sysctl net.inet.ip.forwarding=1
+
+ jexec srv ifconfig ${epair_route}b 203.0.113.2/24 up
+ jexec srv ifconfig ${epair_route}b inet alias 203.0.113.3/24 up
+ jexec srv route add default 203.0.113.1
+
+ # Sanity checks
+ atf_check -s exit:0 -o ignore \
+ ping -c 1 192.0.2.1
+ atf_check -s exit:0 -o ignore \
+ ping -c 1 198.51.100.1
+ atf_check -s exit:0 -o ignore \
+ ping -c 1 203.0.113.2
+ atf_check -s exit:0 -o ignore \
+ ping -c 1 203.0.113.3
+
+ jexec alcatraz pfctl -e
+ pft_set_rules alcatraz \
+ "block in" \
+ "pass received-on ${epair_one}b"
+
+ atf_check -s exit:0 -o ignore \
+ ping -c 1 192.0.2.1
+ atf_check -s exit:2 -o ignore \
+ ping -c 1 198.51.100.1
+
+ # And ensure we can check the received-on interface after routing
+ atf_check -s exit:0 -o ignore \
+ ping -c 1 203.0.113.2
+ atf_check -s exit:2 -o ignore \
+ ping -c 1 203.0.113.3
+
+ # Now try this with a group instead
+ jexec alcatraz ifconfig ${epair_one}b group test
+ pft_set_rules alcatraz \
+ "block in" \
+ "pass received-on test"
+
+ atf_check -s exit:0 -o ignore \
+ ping -c 1 192.0.2.1
+ atf_check -s exit:2 -o ignore \
+ ping -c 1 198.51.100.1
+
+ # And ensure we can check the received-on interface after routing
+ atf_check -s exit:0 -o ignore \
+ ping -c 1 203.0.113.2
+ atf_check -s exit:2 -o ignore \
+ ping -c 1 203.0.113.3
+}
+
+received_on_cleanup()
+{
+ pft_cleanup
+}
+
atf_init_test_cases()
{
atf_add_test_case "enable_disable"
@@ -300,4 +381,5 @@ atf_init_test_cases()
atf_add_test_case "noalias"
atf_add_test_case "nested_inline"
atf_add_test_case "urpf"
+ atf_add_test_case "received_on"
}