HardenedBSD/tests/sys/netpfil/pf/utils.subr
Kristof Provost 96b90524d1 pf tests: Remove temporary files
Remove the created_jails.lst and created_interfaces.lst files in the
cleanup code.
2017-10-26 20:55:33 +00:00

70 lines
1.1 KiB
Plaintext

# $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_set_rules()
{
jname=$1
shift
# Flush all states, rules, fragments, ...
jexec ${jname} pfctl -F all
while [ $# -gt 0 ]; do
printf "$1\n"
shift
done | jexec ${jname} pfctl -f -
}
pft_cleanup()
{
if [ -f created_jails.lst ]; then
for jailname in `cat created_jails.lst`
do
jail -r ${jailname}
done
rm created_jails.lst
fi
if [ -f created_interfaces.lst ]; then
for ifname in `cat created_interfaces.lst`
do
ifconfig ${ifname} destroy
done
rm created_interfaces.lst
fi
}