1# $FreeBSD$ 2# Utility functions 3## 4 5pft_init() 6{ 7 if [ ! -c /dev/pf ]; then 8 atf_skip "This test requires pf" 9 fi 10 11 if [ "`sysctl -i -n kern.features.vimage`" != 1 ]; then 12 atf_skip "This test requires VIMAGE" 13 fi 14} 15 16pfsynct_init() 17{ 18 pft_init 19 20 if ! kldstat -q -m pfsync; then 21 atf_skip "This test requires pfsync" 22 fi 23} 24 25pft_mkepair() 26{ 27 ifname=$(ifconfig epair create) 28 echo $ifname >> created_interfaces.lst 29 echo ${ifname%a} 30} 31 32pft_mkjail() 33{ 34 jailname=$1 35 shift 36 37 vnet_interfaces= 38 for ifname in $@ 39 do 40 vnet_interfaces="${vnet_interfaces} vnet.interface=${ifname}" 41 done 42 jail -c name=${jailname} persist vnet ${vnet_interfaces} 43 44 echo $jailname >> created_jails.lst 45} 46 47pft_set_rules() 48{ 49 jname=$1 50 shift 51 52 if [ $jname == "noflush" ]; 53 then 54 jname=$1 55 shift 56 else 57 # Flush all states, rules, fragments, ... 58 jexec ${jname} pfctl -F all 59 fi 60 61 while [ $# -gt 0 ]; do 62 printf "$1\n" 63 shift 64 done | jexec ${jname} pfctl -f - 65} 66 67pft_cleanup() 68{ 69 if [ -f created_jails.lst ]; then 70 for jailname in `cat created_jails.lst` 71 do 72 jail -r ${jailname} 73 done 74 rm created_jails.lst 75 fi 76 77 if [ -f created_interfaces.lst ]; then 78 for ifname in `cat created_interfaces.lst` 79 do 80 ifconfig ${ifname} destroy 81 done 82 rm created_interfaces.lst 83 fi 84} 85 86pfsynct_cleanup() 87{ 88 pft_cleanup 89} 90