summaryrefslogtreecommitdiffstats
path: root/tests/shell/testcases/rule_management/0011reset_0
blob: 5e65ced946e52bbde4105c4c3d663d681294f714 (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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#!/bin/bash

# NFT_TEST_REQUIRES(NFT_TEST_HAVE_reset_rule)

set -e

if [ $NFT_TEST_HAVE_setcount = y ]; then
	size="size 65535	# count 1"
else
	size="size 65535"
fi

echo "loading ruleset with anonymous set"
$NFT -f - <<EOF
table t {
        chain dns-nat-pre {
                type nat hook prerouting priority filter; policy accept;
                meta l4proto { tcp, udp } th dport 53 ip saddr 10.24.0.0/24 ip daddr != 10.25.0.1 counter packets 1000 bytes 1000 dnat to 10.25.0.1
        }
}
EOF

echo "resetting ruleset with anonymous set"
$NFT reset rules
EXPECT='table ip t {
	chain dns-nat-pre {
		type nat hook prerouting priority filter; policy accept;
		meta l4proto { tcp, udp } th dport 53 ip saddr 10.24.0.0/24 ip daddr != 10.25.0.1 counter packets 0 bytes 0 dnat to 10.25.0.1
	}
}'
$DIFF -u <(echo "$EXPECT") <($NFT list ruleset)
$NFT flush ruleset

echo "loading ruleset"
$NFT -f - <<EOF
table ip t {
	set s {
		type ipv4_addr
		counter
		elements = { 1.1.1.1 counter packets 1 bytes 11 }
	}
	chain c {
		counter packets 1 bytes 11 update @s { ip saddr } accept
		counter packets 2 bytes 12 drop
	}

	chain c2 {
		counter packets 3 bytes 13 accept
		counter packets 4 bytes 14 drop
	}
}
table inet t {
	chain c {
		counter packets 5 bytes 15 accept
		counter packets 6 bytes 16 drop
	}
}
table ip t2 {
	chain c2 {
		counter packets 7 bytes 17 accept
		counter packets 8 bytes 18 drop
	}
}
EOF

echo "resetting specific rule"
handle=$($NFT -a list chain t c | sed -n 's/.*accept # handle \([0-9]*\)$/\1/p')
$NFT reset rule t c handle $handle
EXPECT="table ip t {
	set s {
		type ipv4_addr
		$size
		flags dynamic
		counter
		elements = { 1.1.1.1 counter packets 1 bytes 11 }
	}

	chain c {
		counter packets 0 bytes 0 update @s { ip saddr } accept
		counter packets 2 bytes 12 drop
	}

	chain c2 {
		counter packets 3 bytes 13 accept
		counter packets 4 bytes 14 drop
	}
}
table inet t {
	chain c {
		counter packets 5 bytes 15 accept
		counter packets 6 bytes 16 drop
	}
}
table ip t2 {
	chain c2 {
		counter packets 7 bytes 17 accept
		counter packets 8 bytes 18 drop
	}
}"
$DIFF -u <(echo "$EXPECT") <($NFT list ruleset)

echo "resetting specific chain"
EXPECT='table ip t {
	chain c2 {
		counter packets 3 bytes 13 accept
		counter packets 4 bytes 14 drop
	}
}'
$DIFF -u <(echo "$EXPECT") <($NFT reset rules chain t c2)

echo "resetting specific table"
EXPECT="table ip t {
	set s {
		type ipv4_addr
		$size
		flags dynamic
		counter
		elements = { 1.1.1.1 counter packets 1 bytes 11 }
	}

	chain c {
		counter packets 0 bytes 0 update @s { ip saddr } accept
		counter packets 2 bytes 12 drop
	}

	chain c2 {
		counter packets 0 bytes 0 accept
		counter packets 0 bytes 0 drop
	}
}"
$DIFF -u <(echo "$EXPECT") <($NFT reset rules table t)

echo "resetting specific family"
EXPECT="table ip t {
	set s {
		type ipv4_addr
		$size
		flags dynamic
		counter
		elements = { 1.1.1.1 counter packets 1 bytes 11 }
	}

	chain c {
		counter packets 0 bytes 0 update @s { ip saddr } accept
		counter packets 0 bytes 0 drop
	}

	chain c2 {
		counter packets 0 bytes 0 accept
		counter packets 0 bytes 0 drop
	}
}
table ip t2 {
	chain c2 {
		counter packets 7 bytes 17 accept
		counter packets 8 bytes 18 drop
	}
}"
$DIFF -u <(echo "$EXPECT") <($NFT reset rules ip)

echo "resetting whole ruleset"
EXPECT="table ip t {
	set s {
		type ipv4_addr
		$size
		flags dynamic
		counter
		elements = { 1.1.1.1 counter packets 1 bytes 11 }
	}

	chain c {
		counter packets 0 bytes 0 update @s { ip saddr } accept
		counter packets 0 bytes 0 drop
	}

	chain c2 {
		counter packets 0 bytes 0 accept
		counter packets 0 bytes 0 drop
	}
}
table inet t {
	chain c {
		counter packets 5 bytes 15 accept
		counter packets 6 bytes 16 drop
	}
}
table ip t2 {
	chain c2 {
		counter packets 0 bytes 0 accept
		counter packets 0 bytes 0 drop
	}
}"
$DIFF -u <(echo "$EXPECT") <($NFT reset rules)