aboutsummaryrefslogtreecommitdiff
path: root/tests/sys/netpfil/pf/utils.subr
blob: 9d2f2bee95e4f5796769e75cdf70b6dcb717047d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# $FreeBSD$
# Utility functions
##

pft_init()
{
	if [ ! -c /dev/pf ]; then
		atf_skip "This test requires pf"
	fi

	if [ "`sysctl -i -n kern.features.vimage`" != 1 ]; then
		atf_skip "This test requires VIMAGE"
	fi
}

pft_mkepair()
{
	ifname=$(ifconfig epair create)
	echo $ifname >> created_interfaces.lst
	echo ${ifname%a}
}

pft_mkjail()
{
	jailname=$1
	shift

	vnet_interfaces=
	for ifname in $@
	do
		vnet_interfaces="${vnet_interfaces} vnet.interface=${ifname}"
	done
	jail -c name=${jailname} persist vnet ${vnet_interfaces}

	echo $jailname >> created_jails.lst
}

pft_cleanup()
{
	if [ -f created_interfaces.lst ]; then
		for ifname in `cat created_interfaces.lst`
		do
			ifconfig ${ifname} destroy
		done
	fi

	if [ -f created_jails.lst ]; then
		for jailname in `cat created_jails.lst`
		do
			jail -r ${jailname}
		done
	fi
}