git: 7d3fc84b2d3e - main - pf tests: Test per-anchor tables

From: Kristof Provost <kp_at_FreeBSD.org>
Date: Thu, 17 Feb 2022 13:15:06 UTC
The branch main has been updated by kp:

URL: https://cgit.FreeBSD.org/src/commit/?id=7d3fc84b2d3eb18b675200dbf7732ef41eb79fe2

commit 7d3fc84b2d3eb18b675200dbf7732ef41eb79fe2
Author:     Kristof Provost <kp@FreeBSD.org>
AuthorDate: 2022-02-17 13:13:50 +0000
Commit:     Kristof Provost <kp@FreeBSD.org>
CommitDate: 2022-02-17 13:13:50 +0000

    pf tests: Test per-anchor tables
    
    MFC after:      1 week
    Sponsored by:   Rubicon Communications, LLC ("Netgate")
---
 tests/sys/netpfil/pf/table.sh | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/tests/sys/netpfil/pf/table.sh b/tests/sys/netpfil/pf/table.sh
index b224f3520bb9..ef23a71711f2 100644
--- a/tests/sys/netpfil/pf/table.sh
+++ b/tests/sys/netpfil/pf/table.sh
@@ -277,6 +277,48 @@ precreate_cleanup()
 	pft_cleanup
 }
 
+atf_test_case "anchor" "cleanup"
+anchor_head()
+{
+	atf_set descr 'Test tables in anchors'
+	atf_set require.user root
+}
+
+anchor_body()
+{
+	pft_init
+
+	epair=$(vnet_mkepair)
+	ifconfig ${epair}a 192.0.2.1/24 up
+
+	vnet_mkjail alcatraz ${epair}b
+	jexec alcatraz ifconfig ${epair}b 192.0.2.2/24 up
+	jexec alcatraz pfctl -e
+
+	(echo "table <testtable> persist"
+	 echo "block in quick from <testtable> to any"
+	) | jexec alcatraz pfctl -a anchorage -f -
+
+	pft_set_rules noflush alcatraz \
+		"pass" \
+		"anchor anchorage"
+
+	atf_check -s exit:0 -o ignore ping -c 1 192.0.2.2
+
+	# Tables belong to anchors, so this is a different table and won't affect anything
+	jexec alcatraz pfctl -t testtable -T add 192.0.2.1
+	atf_check -s exit:0 -o ignore ping -c 1 192.0.2.2
+
+	# But when we add the address to the table in the anchor it does block traffic
+	jexec alcatraz pfctl -a anchorage -t testtable -T add 192.0.2.1
+	atf_check -s exit:2 -o ignore ping -c 1 192.0.2.2
+}
+
+anchor_cleanup()
+{
+	pft_cleanup
+}
+
 atf_init_test_cases()
 {
 	atf_add_test_case "v4_counters"
@@ -286,4 +328,5 @@ atf_init_test_cases()
 	atf_add_test_case "network"
 	atf_add_test_case "pr259689"
 	atf_add_test_case "precreate"
+	atf_add_test_case "anchor"
 }