xref: /freebsd/tests/sys/common/vnet.subr (revision ec0ea6efa1ad229d75c394c1a9b9cac33af2b1d3)
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}b >> created_interfaces.lst
17	echo ${ifname%a}
18}
19
20vnet_mkbridge()
21{
22	ifname=$(ifconfig bridge create)
23	echo $ifname >> created_interfaces.lst
24	echo ${ifname}
25}
26
27vnet_mkvlan()
28{
29	ifname=$(ifconfig vlan create)
30	echo ${ifname} >> created_interfaces.lst
31	echo ${ifname}
32}
33
34vnet_mkloopback()
35{
36	ifname=$(ifconfig lo create)
37	echo $ifname >> created_interfaces.lst
38	echo ${ifname}
39}
40
41vnet_mkjail()
42{
43	jailname=$1
44	shift
45
46	vnet_interfaces=
47	for ifname in $@
48	do
49		vnet_interfaces="${vnet_interfaces} vnet.interface=${ifname}"
50	done
51	jail -c name=${jailname} persist vnet ${vnet_interfaces}
52
53	echo $jailname >> created_jails.lst
54}
55
56vnet_cleanup()
57{
58	if [ -f created_jails.lst ]; then
59		for jailname in `cat created_jails.lst`
60		do
61			jail -r ${jailname}
62		done
63		rm created_jails.lst
64	fi
65
66	if [ -f created_interfaces.lst ]; then
67		for ifname in `cat created_interfaces.lst`
68		do
69			ifconfig ${ifname} destroy
70		done
71		rm created_interfaces.lst
72	fi
73}
74