aboutsummaryrefslogtreecommitdiff
path: root/tests/sys/netpfil/pf/utils.subr
blob: 822dd741e204cd7217baffb6423bd1a8da935f6f (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
# $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
	ifname=$2
	jail -c name=${jailname} persist vnet vnet.interface=${ifname}

	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
}