libpfctl: Fix displaying deeply nested anchors

Set the number of rulesets (i.e., anchors) directly attached to the
anchor and its path in pfctl_get_ruleset().

While here, add a test to document this behavior.

PR:		290478
Reviewed by:	kp
Fixes:		041ce1d690 ("pfctl: recursively flush rules and tables")
MFC after:	2 days
Differential Revision:	https://reviews.freebsd.org/D53358
This commit is contained in:
Jose Luis Duran committed 2025-10-28 11:29:19 +00:00
1 parent e5f545e0d8
commit a943a96a50
2 files changed
+49

No files matched your search

+3
View File
@@ -3202,6 +3202,9 @@ pfctl_get_ruleset(struct pfctl_handle *h, const char *path, uint32_t nr, struct
continue;
}
rs->nr = nr;
strlcpy(rs->path, path, sizeof(rs->path));
return (e.error);
}
+46
View File
@@ -123,6 +123,51 @@ nested_anchor_cleanup()
pft_cleanup
}
atf_test_case "deeply_nested" "cleanup"
deeply_nested_head()
{
atf_set descr 'Test setting and retrieving deeply nested anchors'
atf_set require.user root
}
deeply_nested_body()
{
pft_init
epair=$(vnet_mkepair)
vnet_mkjail alcatraz ${epair}a
pft_set_rules alcatraz \
"anchor \"foo\" { \n\
anchor \"bar\" { \n\
anchor \"foobar\" { \n\
pass on ${epair}a \n\
} \n\
anchor \"quux\" { \n\
pass on ${epair}a \n\
} \n\
} \n\
anchor \"baz\" { \n\
pass on ${epair}a \n\
} \n\
anchor \"qux\" { \n\
pass on ${epair}a \n\
} \n\
}"
atf_check -s exit:0 -o \
inline:" foo\n foo/bar\n foo/bar/foobar\n foo/bar/quux\n foo/baz\n foo/qux\n" \
-e ignore jexec alcatraz pfctl -sA
atf_check -s exit:0 -o inline:" foo/bar/foobar\n foo/bar/quux\n" \
-e ignore jexec alcatraz pfctl -a foo/bar -sA
}
deeply_nested_cleanup()
{
pft_cleanup
}
atf_test_case "wildcard" "cleanup"
wildcard_head()
{
@@ -498,6 +543,7 @@ atf_init_test_cases()
atf_add_test_case "pr183198"
atf_add_test_case "pr279225"
atf_add_test_case "nested_anchor"
atf_add_test_case "deeply_nested"
atf_add_test_case "wildcard"
atf_add_test_case "nested_label"
atf_add_test_case "quick"