git: e0724177b584 - stable/12 - pf tests: check that we clean up unused kifs

From: Kristof Provost <kp_at_FreeBSD.org>
Date: Wed, 28 Dec 2022 09:03:15 UTC
The branch stable/12 has been updated by kp:

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

commit e0724177b5840c7f89efc00201fc5c4f4dc66fc5
Author:     Kristof Provost <kp@FreeBSD.org>
AuthorDate: 2022-11-30 14:20:41 +0000
Commit:     Kristof Provost <kp@FreeBSD.org>
CommitDate: 2022-12-28 05:06:13 +0000

    pf tests: check that we clean up unused kifs
    
    The previous commit fixed a memory leak, where we'd fail to clean up
    removed groups (and interfaces).
    Check that we now clean those up as expected.
    
    MFC after:      2 weeks
    Sponsored by:   Rubicon Communications, LLC ("Netgate")
    Differential Revision:  https://reviews.freebsd.org/D37570
    
    (cherry picked from commit 654e8d84ec8bcb3d94cd8de69edecbe1bbd73eb8)
---
 tests/sys/netpfil/pf/names.sh | 44 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/tests/sys/netpfil/pf/names.sh b/tests/sys/netpfil/pf/names.sh
index b2102d644312..e3fb3eb56103 100755
--- a/tests/sys/netpfil/pf/names.sh
+++ b/tests/sys/netpfil/pf/names.sh
@@ -53,7 +53,51 @@ names_cleanup()
 	pft_cleanup
 }
 
+atf_test_case "group" "cleanup"
+group_head()
+{
+	atf_set descr 'Test group cleanup, PR257218'
+	atf_set require.user root
+}
+
+group_body()
+{
+	pft_init
+
+	vnet_mkjail alcatraz
+
+	if [ -n "$(jexec alcatraz pfctl -sI | grep '^epair$')" ];
+	then
+		atf_fail "Unexpected epair group"
+	fi
+
+	epair=$(vnet_mkepair)
+	if [ -n "$(jexec alcatraz pfctl -sI | grep '^epair$')" ];
+	then
+		atf_fail "Unexpected epair group"
+	fi
+
+	ifconfig ${epair}b vnet alcatraz
+	if [ -z "$(jexec alcatraz pfctl -sI | grep '^epair$')" ];
+	then
+		atf_fail "Failed to find epair group"
+	fi
+
+	ifconfig ${epair}a destroy
+
+	if [ -n "$(jexec alcatraz pfctl -sI | grep '^epair$')" ];
+	then
+		atf_fail "Unexpected epair group"
+	fi
+}
+
+group_cleanup()
+{
+	pft_cleanup
+}
+
 atf_init_test_cases()
 {
 	atf_add_test_case "names"
+	atf_add_test_case "group"
 }