summaryrefslogtreecommitdiffstats
path: root/iptables/tests/shell/testcases/iptables/0007-zero-counters_0
blob: 36da1907e3b226a6924d997c90c33abe3490e1c3 (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
#!/bin/bash

RC=0
COUNTR=$RANDOM$RANDOM

$XT_MULTI iptables-restore -c <<EOF
*filter
:INPUT ACCEPT [1:23]
:FOO - [0:0]
[12:345] -A INPUT -i lo -p icmp -m comment --comment "$COUNTR"
[22:123] -A FOO -m comment --comment one
[44:123] -A FOO -m comment --comment two
COMMIT
EOF
EXPECT="*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:FOO - [0:0]
[0:0] -A INPUT -i lo -p icmp -m comment --comment "$COUNTR"
[0:0] -A FOO -m comment --comment one
[0:0] -A FOO -m comment --comment two
COMMIT"

COUNTER=$($XT_MULTI iptables-save -c |grep "comment $COUNTR"| cut -f 1 -d " ")
if [ $COUNTER != "[12:345]" ]; then
	echo "Counter $COUNTER is wrong, expected 12:345"
	RC=1
fi

$XT_MULTI iptables -Z FOO
COUNTER=$($XT_MULTI iptables-save -c |grep "comment $COUNTR"| cut -f 1 -d " ")
if [ $COUNTER = "[0:0]" ]; then
	echo "Counter $COUNTER is wrong, should not have been zeroed"
	RC=1
fi

for c in one two; do
	COUNTER=$($XT_MULTI iptables-save -c |grep "comment $c"| cut -f 1 -d " ")
	if [ $COUNTER != "[0:0]" ]; then
		echo "Counter $COUNTER is wrong, should have been zeroed at rule $c"
		RC=1
	fi
done

$XT_MULTI iptables -Z
COUNTER=$($XT_MULTI iptables-save -c |grep "comment $COUNTR"| cut -f 1 -d " ")

if [ $COUNTER != "[0:0]" ]; then
	echo "Counter $COUNTER is wrong, expected 0:0 after -Z"
	RC=1
fi

diff -u -Z <(echo -e "$EXPECT") <($XT_MULTI iptables-save -c | grep -v '^#')
if [ $? -ne 0 ]; then
	echo "Diff error: counters were not zeroed"
	RC=1
fi

$XT_MULTI iptables -D INPUT -i lo -p icmp -m comment --comment "$COUNTR"
$XT_MULTI iptables -D FOO -m comment --comment one
$XT_MULTI iptables -D FOO -m comment --comment two
$XT_MULTI iptables -X FOO
exit $RC