xref: /freebsd/tests/sys/common/vnet.subr (revision f6a3b357e9be4c6423c85eff9a847163a0d307c8)
1# $FreeBSD$
2# VNAT/jail utility functions
3##
4
5vnet_init()
6{
7	if [ "`sysctl -i -n kern.features.vimage`" != 1 ]; then
8		atf_skip "This test requires VIMAGE"
9	fi
10}
11
12vnet_mkepair()
13{
14	ifname=$(ifconfig epair create)
15	echo $ifname >> created_interfaces.lst
16	echo ${ifname%a}
17}
18
19vnet_mkjail()
20{
21	jailname=$1
22	shift
23
24	vnet_interfaces=
25	for ifname in $@
26	do
27		vnet_interfaces="${vnet_interfaces} vnet.interface=${ifname}"
28	done
29	jail -c name=${jailname} persist vnet ${vnet_interfaces}
30
31	echo $jailname >> created_jails.lst
32}
33
34vnet_cleanup()
35{
36	if [ -f created_jails.lst ]; then
37		for jailname in `cat created_jails.lst`
38		do
39			jail -r ${jailname}
40		done
41		rm created_jails.lst
42	fi
43
44	if [ -f created_interfaces.lst ]; then
45		for ifname in `cat created_interfaces.lst`
46		do
47			ifconfig ${ifname} destroy
48		done
49		rm created_interfaces.lst
50	fi
51}
52