git: 3fccdfab6430 - main - pf tests: basic 'tagged' test for Ethernet rules

From: Kristof Provost <kp_at_FreeBSD.org>
Date: Mon, 20 Jun 2022 09:09:09 UTC
The branch main has been updated by kp:

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

commit 3fccdfab6430e8c415dfa6d0be04d5ebcd121429
Author:     Kristof Provost <kp@FreeBSD.org>
AuthorDate: 2022-05-31 12:55:15 +0000
Commit:     Kristof Provost <kp@FreeBSD.org>
CommitDate: 2022-06-20 08:16:20 +0000

    pf tests: basic 'tagged' test for Ethernet rules
    
    Sponsored by:   Rubicon Communications, LLC ("Netgate")
    Differential Revision: https://reviews.freebsd.org/D35364
---
 tests/sys/netpfil/pf/ether.sh | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/tests/sys/netpfil/pf/ether.sh b/tests/sys/netpfil/pf/ether.sh
index dc580b234c39..283267b98c54 100644
--- a/tests/sys/netpfil/pf/ether.sh
+++ b/tests/sys/netpfil/pf/ether.sh
@@ -553,6 +553,46 @@ ip_cleanup()
 	pft_cleanup
 }
 
+atf_test_case "tag" "cleanup"
+tag_head()
+{
+	atf_set descr 'Test setting tags'
+	atf_set require.user root
+}
+
+tag_body()
+{
+	pft_init
+
+	epair=$(vnet_mkepair)
+
+	vnet_mkjail alcatraz ${epair}b
+	ifconfig ${epair}a 192.0.2.1/24 up
+	jexec alcatraz ifconfig ${epair}b 192.0.2.2/24 up
+
+	# Sanity check
+	atf_check -s exit:0 -o ignore ping -c 1 192.0.2.2
+
+	jexec alcatraz pfctl -e
+	pft_set_rules alcatraz \
+		"ether pass in tag foo" \
+		"block in tagged foo"
+
+	atf_check -s exit:2 -o ignore ping -c 1 192.0.2.2
+
+	pft_set_rules alcatraz \
+		"ether pass in tag bar" \
+		"block in tagged foo"
+
+	# Still passes when tagged differently
+	atf_check -s exit:0 -o ignore ping -c 1 192.0.2.2
+}
+
+tag_cleanup()
+{
+	pft_cleanup
+}
+
 atf_test_case "match_tag" "cleanup"
 match_tag_head()
 {
@@ -604,5 +644,6 @@ atf_init_test_cases()
 	atf_add_test_case "dummynet"
 	atf_add_test_case "anchor"
 	atf_add_test_case "ip"
+	atf_add_test_case "tag"
 	atf_add_test_case "match_tag"
 }