mirror of
https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git
synced 2024-12-29 15:10:57 +01:00
96b90524d1
Remove the created_jails.lst and created_interfaces.lst files in the cleanup code.
70 lines
1.1 KiB
Plaintext
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
|
|
}
|