xref: /freebsd/tests/sys/netpfil/pf/macro.sh (revision ebacd8013fe5f7fdf9f6a5b286f6680dd2891036)
1. $(atf_get_srcdir)/utils.subr
2
3atf_test_case "nr" "cleanup"
4nr_head()
5{
6	atf_set descr 'Test $nr expansion'
7	atf_set require.user root
8}
9
10nr_body()
11{
12	# Ensure that when the optimiser collapses rules the macro expansion
13	# has the correct rule number
14	pft_init
15
16	vnet_mkjail alcatraz
17	jexec alcatraz ifconfig lo0 inet 127.0.0.1/8
18	jexec alcatraz ifconfig lo0 inet 127.0.0.2/32 alias
19
20	pft_set_rules alcatraz \
21	    "pass quick on lo from lo:network to lo:network" \
22	    "block quick all label \"ruleNo:\$nr\""
23
24	no=$(jexec alcatraz pfctl -sr -vv | awk '/ruleNo/ { gsub("@", "", $1); print $1; }')
25	ruleno=$(jexec alcatraz pfctl -sr -vv | awk '/ruleNo/ { gsub(/"ruleNo:/, "", $7); gsub(/"/, "", $7); print $7; }')
26	if [ "${no}" -ne "${ruleno}" ];
27	then
28		atf_fail "Expected ruleNo $no != $ruleno"
29	fi
30}
31
32nr_cleanup()
33{
34	pft_cleanup
35}
36
37atf_init_test_cases()
38{
39	atf_add_test_case "nr"
40}
41