summaryrefslogtreecommitdiffstats
path: root/tests/check_klog.sh
blob: 489fa714bc6fc7e855e19460d06aac124969ab28 (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
#!/bin/bash

# set -x
set -e

# arguments: ipaddr proto port setname ...

expand_ipv6() {
	# incomplete, but for our addresses it's OK
	addr=
	n=0
	while read a; do
		n=$((n+1))
		if [ -z "$a" ]; then
			addr="$addr::"
		else
			case `echo $a | wc -c` in
			4) a="0$a";;
			3) a="00$a";;
			2) a="000$a";;
			esac
			addr="$addr$a:"
		fi
	done < <(echo $1 | tr : '\n')
	addr=`echo $addr | sed -e 's/:$//'`
	null=
	while [ $n -le 8 ]; do
		null="$null:0000"
		n=$((n+1))
	done
	addr=`echo $addr | sed -e "s/::/$null/"`
	echo $addr
}

ipaddr=`expand_ipv6 $1`; shift
proto=`echo $1 | tr a-z A-Z`; shift
port=$1; shift

for setname in $@; do
	match=`grep -e "in set $setname: .* SRC=$ipaddr .* PROTO=$proto SPT=$port .*" /var/log/kern.log`
	if [ -z "$match" ]; then
		echo "no match!"
		exit 1
	fi
done
exit 0