git: e41b30c849ed - stable/13 - pf tests: Test per-anchor tables

From: Kristof Provost <kp_at_FreeBSD.org>
Date: Mon, 28 Feb 2022 15:39:07 UTC
The branch stable/13 has been updated by kp:

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

commit e41b30c849ed9cb5b6c6a9afbd7c37c0d2dcb7bf
Author:     Kristof Provost <kp@FreeBSD.org>
AuthorDate: 2022-02-17 13:13:50 +0000
Commit:     Kristof Provost <kp@FreeBSD.org>
CommitDate: 2022-02-28 15:38:05 +0000

    pf tests: Test per-anchor tables
    
    MFC after:      1 week
    Sponsored by:   Rubicon Communications, LLC ("Netgate")
    
    (cherry picked from commit 7d3fc84b2d3eb18b675200dbf7732ef41eb79fe2)
---
 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 e363c86a4939..cc95daba048b 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 "automatic"
 	atf_add_test_case "pr259689"
 	atf_add_test_case "precreate"
+	atf_add_test_case "anchor"
 }