git: 10d71d02cfb2 - stable/13 - pf tests: Test retrieving nested nat-anchors

From: Kristof Provost <kp_at_FreeBSD.org>
Date: Thu, 24 Mar 2022 13:15:53 UTC
The branch stable/13 has been updated by kp:

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

commit 10d71d02cfb2203220b06abe224bb514aa3d754c
Author:     Kristof Provost <kp@FreeBSD.org>
AuthorDate: 2022-03-17 17:33:50 +0000
Commit:     Kristof Provost <kp@FreeBSD.org>
CommitDate: 2022-03-24 09:44:54 +0000

    pf tests: Test retrieving nested nat-anchors
    
    MFC after:      1 week
    Sponsored by:   Rubicon Communications, LLC ("Netgate")
    
    (cherry picked from commit 3c3a19d1f42af049e798b193d4fd2a872c7c8fec)
---
 tests/sys/netpfil/pf/nat.sh | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/tests/sys/netpfil/pf/nat.sh b/tests/sys/netpfil/pf/nat.sh
index 3fabb32db80f..a957dfd59c78 100644
--- a/tests/sys/netpfil/pf/nat.sh
+++ b/tests/sys/netpfil/pf/nat.sh
@@ -84,7 +84,43 @@ exhaust_cleanup()
 	pft_cleanup
 }
 
+atf_test_case "nested_anchor" "cleanup"
+nested_anchor_head()
+{
+	atf_set descr 'Test setting and retrieving nested nat anchors'
+	atf_set require.user root
+}
+
+nested_anchor_body()
+{
+	pft_init
+
+	epair=$(vnet_mkepair)
+
+	vnet_mkjail nat ${epair}a
+
+	pft_set_rules nat \
+		"nat-anchor \"foo\""
+
+	echo "nat-anchor \"bar\"" | jexec nat pfctl -g -a foo -f -
+	echo "nat on ${epair}a from any to any -> (${epair}a)" | jexec nat pfctl -g -a "foo/bar" -f -
+
+	atf_check -s exit:0 -o inline:"nat-anchor \"foo\" all {
+  nat-anchor \"bar\" all {
+    nat on ${epair}a all -> (${epair}a) round-robin
+  }
+}
+" jexec nat pfctl -sn -a "*"
+
+}
+
+nested_anchor_cleanup()
+{
+	pft_cleanup
+}
+
 atf_init_test_cases()
 {
 	atf_add_test_case "exhaust"
+	atf_add_test_case "nested_anchor"
 }