summaryrefslogtreecommitdiff
path: root/regress/sbin/pfctl/if2ip
blob: 56324cc25c14a73b9736ca8605c20cab4f22cb1f (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
#!/bin/ksh
# simple script that compare and display interface to address translation
# done by the userland pfctl tool and by the kernel PF dynamic code.

if2ip_user() {
    echo "pass in from $1" | pfctl -nvf- 2>/dev/null \
	| awk '{print  "   "(($3=="on")?$7:$5)}' | sort -u
}

kernel_spec() {
    set -- `echo $1 | sed "s;/; ;"`
    if [ "X$2" == "X" ]; then
	echo "($1)"
    else
	echo "($1)/$2"
    fi
}

if2ip_kernel() {
    T=`echo "pass in on tun100 from $1" | pfctl -a _regress:if2ip -f- \
	-vf- | awk '{ print $6}' | tr -d "()"` 
    pfctl -a _pf:_if -t "$T" -Ts | sort
    pfctl -a _regress:if2ip -qFr
}

while [ "X$1" != "X" ]; do
    if [ "$1" == "-q" ]; then
	QUIET=1
	shift
    fi
    if [ "$1" == "-v" ]; then
	QUIET=0
	shift
    fi

    UIP=`if2ip_user $1`
    KIF=`kernel_spec $1`
    KIP=`if2ip_kernel $KIF`

    if [ "$QUIET" == "1" ]; then
	if [ "$UIP" == "$KIP" ]; then
	    echo "$1 and $KIF match."
	else
	    echo "$1 and $KIF mismatch."
	fi
    else
	echo "$1:"$UIP
	echo "$KIF:"$KIP
    fi

    if [ "$UIP" != "$KIP" ]; then
	exit 1
    fi
    shift
done