xref: /freebsd/tests/sys/netpfil/pf/utils.subr (revision bda54b8f964b4035dcf5aba394d14ed24370a6f2)
1# $FreeBSD$
2# Utility functions
3##
4
5. $(atf_get_srcdir)/../../common/vnet.subr
6
7pft_init()
8{
9	vnet_init
10
11	if [ ! -c /dev/pf ]; then
12		atf_skip "This test requires pf"
13	fi
14}
15
16pfsynct_init()
17{
18	pft_init
19
20	if ! kldstat -q -m pfsync; then
21		atf_skip "This test requires pfsync"
22	fi
23}
24
25pft_set_rules()
26{
27	jname=$1
28	shift
29
30	if [ $jname == "noflush" ];
31	then
32		jname=$1
33		shift
34	else
35		# Flush all states, rules, fragments, ...
36		jexec ${jname} pfctl -F all
37	fi
38
39	while [ $# -gt 0 ]; do
40		printf "$1\n"
41		shift
42	done | jexec ${jname} pfctl -f -
43}
44
45pft_cleanup()
46{
47	vnet_cleanup
48}
49
50pfsynct_cleanup()
51{
52	pft_cleanup
53}
54