summaryrefslogtreecommitdiff
path: root/regress/sbin/pfctl/pfr.exec
blob: 9264fdd6cb1ba65de0f14bd68deb38641a77353c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/ksh
D=`dirname $1`
for TABLE in `pfctl -sT | grep regress`; do 
	pfctl -t $TABLE -qTk 2>&1 || exit 1
done
pfctl -Fr -a regress:regress 2>/dev/null
pfctl -Fn -a regress:regress 2>/dev/null
KT_A=0`vmstat -m | awk '/pfrktable/{print $3}'`
KT_R=0`vmstat -m | awk '/pfrktable/{print $5}'`
KE_A=0`vmstat -m | awk '/pfrkentry/{print $3}'`
KE_R=0`vmstat -m | awk '/pfrkentry/{print $5}'`
echo "# create"
echo "table <regress> persist" | pfctl -Tl -f - 2>&1 || exit 1
for LINE in `sed -e "s/ /_/g" $1`; do 
	RESULT=`echo $LINE | awk '{split($1,a,"_");print a[1]}'`
	case $RESULT in
		pass|fail) ;;
		*) continue ;;
	esac
	CMD=`echo $LINE | awk '{split($1,a,"_");print a[2]}'` 
	ARGSX=`echo $LINE | awk '{split($1,a,"_");for(i=3;a[i];i++)print a[i]}'`
	ARGS=""
	for ARG in $ARGSX; do
		if [ "X$ARGS" = "X" ]; then
			ARGS="$ARG"
		else
			ARGS="$ARGS $ARG"
		fi
	done
	if [ "$RESULT" = "pass" ]; then case $CMD in
	add|delete|replace)
		echo "# pass $CMD -n $ARGS"
		pfctl -t regress -nT $CMD $ARGS 2>&1 | sort || exit 1
		echo "# pass $CMD -nf-"
		echo "# test\n" $ARGSX | pfctl -t regress -nT $CMD -f- \
			2>&1 | sort || exit 1
		echo "# pass $CMD -nqv $ARGS"
		pfctl -t regress -nqvT $CMD $ARGS 2>&1 | sort || exit 1
		echo "# pass $CMD -nqvv $ARGS"
		pfctl -t regress -nqvvT $CMD $ARGS 2>&1 | sort || exit 1
		;;
	esac fi
	echo "# $RESULT $CMD $ARGS"
	if [ "$RESULT" = "pass" ]; then
		case $CMD in
		list)
			(pfctl -sT | grep regress) 2>&1
			echo "# pass $CMD -v"
			(pfctl -gvsT | grep regress) 2>&1
			;;
		load)
			echo $ARGS | sed "s,DIR,$D,g" | pfctl -Tl -f- || exit 1
			;;
		rule)
			echo $ARGS | pfctl -a regress:regress -f- 2>&1 || exit 1
			;;
		*)
			pfctl -t regress -T $CMD $ARGS 2>&1 | sort || exit 1
			;;
		esac
	else
		case $CMD in
		load)
			echo ARGS | sed "s,DIR,$D,g" | pfctl -Tl -f- && exit 1
			;;
		rule)
			echo $ARGS | pfctl -a regress:regress -f- 2>&1 && exit 1			;;
		*)
			pfctl -t regress -T $CMD $ARGS 2>&1 && exit 1
			;;
		esac
	fi
done
echo "# kill"
for TABLE in `pfctl -sT | grep regress`; do
        pfctl -t $TABLE -Tk 2>&1 || exit 1
done
pfctl -Fr -a regress:regress 2>/dev/null
pfctl -Fn -a regress:regress 2>/dev/null
let KT_A=`vmstat -m | awk '/pfrktable/{print $3}'`-$KT_A
let KT_R=`vmstat -m | awk '/pfrktable/{print $5}'`-$KT_R
let KT_L=$KT_A-$KT_R
let KE_A=`vmstat -m | awk '/pfrkentry/{print $3}'`-$KE_A
let KE_R=`vmstat -m | awk '/pfrkentry/{print $5}'`-$KE_R
let KE_L=$KE_A-$KE_R
echo "ktable: $KT_A allocated, $KT_R released, $KT_L leaked."
echo "kentry: $KE_A allocated, $KE_R released, $KE_L leaked."
[ "$KT_L" = "0" -a "$KE_L" = "0" ] || exit 1