summaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/net/forwarding/tc_flower_l2_miss.sh
blob: 20a7cb7222b8baa4062a769f2f0d27daf2b00cfd (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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0

# +-----------------------+                             +----------------------+
# | H1 (vrf)              |                             | H2 (vrf)             |
# |    + $h1              |                             |              $h2 +   |
# |    | 192.0.2.1/28     |                             |     192.0.2.2/28 |   |
# |    | 2001:db8:1::1/64 |                             | 2001:db8:1::2/64 |   |
# +----|------------------+                             +------------------|---+
#      |                                                                   |
# +----|-------------------------------------------------------------------|---+
# | SW |                                                                   |   |
# |  +-|-------------------------------------------------------------------|-+ |
# |  | + $swp1                       BR                              $swp2 + | |
# |  +-----------------------------------------------------------------------+ |
# +----------------------------------------------------------------------------+

ALL_TESTS="
	test_l2_miss_unicast
	test_l2_miss_multicast
	test_l2_miss_ll_multicast
	test_l2_miss_broadcast
"

NUM_NETIFS=4
source lib.sh
source tc_common.sh

h1_create()
{
	simple_if_init $h1 192.0.2.1/28 2001:db8:1::1/64
}

h1_destroy()
{
	simple_if_fini $h1 192.0.2.1/28 2001:db8:1::1/64
}

h2_create()
{
	simple_if_init $h2 192.0.2.2/28 2001:db8:1::2/64
}

h2_destroy()
{
	simple_if_fini $h2 192.0.2.2/28 2001:db8:1::2/64
}

switch_create()
{
	ip link add name br1 up type bridge
	ip link set dev $swp1 master br1
	ip link set dev $swp1 up
	ip link set dev $swp2 master br1
	ip link set dev $swp2 up

	tc qdisc add dev $swp2 clsact
}

switch_destroy()
{
	tc qdisc del dev $swp2 clsact

	ip link set dev $swp2 down
	ip link set dev $swp2 nomaster
	ip link set dev $swp1 down
	ip link set dev $swp1 nomaster
	ip link del dev br1
}

test_l2_miss_unicast()
{
	local dmac=00:01:02:03:04:05
	local dip=192.0.2.2
	local sip=192.0.2.1

	RET=0

	# Unknown unicast.
	tc filter add dev $swp2 egress protocol ipv4 handle 101 pref 1 \
	   flower indev $swp1 l2_miss 1 dst_mac $dmac src_ip $sip \
	   dst_ip $dip action pass
	# Known unicast.
	tc filter add dev $swp2 egress protocol ipv4 handle 102 pref 1 \
	   flower indev $swp1 l2_miss 0 dst_mac $dmac src_ip $sip \
	   dst_ip $dip action pass

	# Before adding FDB entry.
	$MZ $h1 -a own -b $dmac -t ip -A $sip -B $dip -c 1 -p 100 -q

	tc_check_packets "dev $swp2 egress" 101 1
	check_err $? "Unknown unicast filter was not hit before adding FDB entry"

	tc_check_packets "dev $swp2 egress" 102 0
	check_err $? "Known unicast filter was hit before adding FDB entry"

	# Adding FDB entry.
	bridge fdb replace $dmac dev $swp2 master static

	$MZ $h1 -a own -b $dmac -t ip -A $sip -B $dip -c 1 -p 100 -q

	tc_check_packets "dev $swp2 egress" 101 1
	check_err $? "Unknown unicast filter was hit after adding FDB entry"

	tc_check_packets "dev $swp2 egress" 102 1
	check_err $? "Known unicast filter was not hit after adding FDB entry"

	# Deleting FDB entry.
	bridge fdb del $dmac dev $swp2 master static

	$MZ $h1 -a own -b $dmac -t ip -A $sip -B $dip -c 1 -p 100 -q

	tc_check_packets "dev $swp2 egress" 101 2
	check_err $? "Unknown unicast filter was not hit after deleting FDB entry"

	tc_check_packets "dev $swp2 egress" 102 1
	check_err $? "Known unicast filter was hit after deleting FDB entry"

	tc filter del dev $swp2 egress protocol ipv4 pref 1 handle 102 flower
	tc filter del dev $swp2 egress protocol ipv4 pref 1 handle 101 flower

	log_test "L2 miss - Unicast"
}

test_l2_miss_multicast_common()
{
	local proto=$1; shift
	local sip=$1; shift
	local dip=$1; shift
	local dmac=$1; shift
	local mode=$1; shift
	local name=$1; shift

	RET=0

	# Unregistered multicast.
	tc filter add dev $swp2 egress protocol $proto handle 101 pref 1 \
	   flower indev $swp1 l2_miss 1 src_ip $sip dst_ip $dip \
	   action pass
	# Registered multicast.
	tc filter add dev $swp2 egress protocol $proto handle 102 pref 1 \
	   flower indev $swp1 l2_miss 0 src_ip $sip dst_ip $dip \
	   action pass

	# Before adding MDB entry.
	$MZ $mode $h1 -a own -b $dmac -t ip -A $sip -B $dip -c 1 -p 100 -q

	tc_check_packets "dev $swp2 egress" 101 1
	check_err $? "Unregistered multicast filter was not hit before adding MDB entry"

	tc_check_packets "dev $swp2 egress" 102 0
	check_err $? "Registered multicast filter was hit before adding MDB entry"

	# Adding MDB entry.
	bridge mdb replace dev br1 port $swp2 grp $dip permanent

	$MZ $mode $h1 -a own -b $dmac -t ip -A $sip -B $dip -c 1 -p 100 -q

	tc_check_packets "dev $swp2 egress" 101 1
	check_err $? "Unregistered multicast filter was hit after adding MDB entry"

	tc_check_packets "dev $swp2 egress" 102 1
	check_err $? "Registered multicast filter was not hit after adding MDB entry"

	# Deleting MDB entry.
	bridge mdb del dev br1 port $swp2 grp $dip

	$MZ $mode $h1 -a own -b $dmac -t ip -A $sip -B $dip -c 1 -p 100 -q

	tc_check_packets "dev $swp2 egress" 101 2
	check_err $? "Unregistered multicast filter was not hit after deleting MDB entry"

	tc_check_packets "dev $swp2 egress" 102 1
	check_err $? "Registered multicast filter was hit after deleting MDB entry"

	tc filter del dev $swp2 egress protocol $proto pref 1 handle 102 flower
	tc filter del dev $swp2 egress protocol $proto pref 1 handle 101 flower

	log_test "L2 miss - Multicast ($name)"
}

test_l2_miss_multicast_ipv4()
{
	local proto="ipv4"
	local sip=192.0.2.1
	local dip=239.1.1.1
	local dmac=01:00:5e:01:01:01
	local mode="-4"
	local name="IPv4"

	test_l2_miss_multicast_common $proto $sip $dip $dmac $mode $name
}

test_l2_miss_multicast_ipv6()
{
	local proto="ipv6"
	local sip=2001:db8:1::1
	local dip=ff0e::1
	local dmac=33:33:00:00:00:01
	local mode="-6"
	local name="IPv6"

	test_l2_miss_multicast_common $proto $sip $dip $dmac $mode $name
}

test_l2_miss_multicast()
{
	# Configure $swp2 as a multicast router port so that it will forward
	# both registered and unregistered multicast traffic.
	bridge link set dev $swp2 mcast_router 2

	# Forwarding according to MDB entries only takes place when the bridge
	# detects that there is a valid querier in the network. Set the bridge
	# as the querier and assign it a valid IPv6 link-local address to be
	# used as the source address for MLD queries.
	ip link set dev br1 type bridge mcast_querier 1
	ip -6 address add fe80::1/64 nodad dev br1
	# Wait the default Query Response Interval (10 seconds) for the bridge
	# to determine that there are no other queriers in the network.
	sleep 10

	test_l2_miss_multicast_ipv4
	test_l2_miss_multicast_ipv6

	ip -6 address del fe80::1/64 dev br1
	ip link set dev br1 type bridge mcast_querier 0
	bridge link set dev $swp2 mcast_router 1
}

test_l2_miss_multicast_common2()
{
	local name=$1; shift
	local dmac=$1; shift
	local dip=224.0.0.1
	local sip=192.0.2.1

}

test_l2_miss_ll_multicast_common()
{
	local proto=$1; shift
	local dmac=$1; shift
	local sip=$1; shift
	local dip=$1; shift
	local mode=$1; shift
	local name=$1; shift

	RET=0

	tc filter add dev $swp2 egress protocol $proto handle 101 pref 1 \
	   flower indev $swp1 l2_miss 1 dst_mac $dmac src_ip $sip \
	   dst_ip $dip action pass

	$MZ $mode $h1 -a own -b $dmac -t ip -A $sip -B $dip -c 1 -p 100 -q

	tc_check_packets "dev $swp2 egress" 101 1
	check_err $? "Filter was not hit"

	tc filter del dev $swp2 egress protocol $proto pref 1 handle 101 flower

	log_test "L2 miss - Link-local multicast ($name)"
}

test_l2_miss_ll_multicast_ipv4()
{
	local proto=ipv4
	local dmac=01:00:5e:00:00:01
	local sip=192.0.2.1
	local dip=224.0.0.1
	local mode="-4"
	local name="IPv4"

	test_l2_miss_ll_multicast_common $proto $dmac $sip $dip $mode $name
}

test_l2_miss_ll_multicast_ipv6()
{
	local proto=ipv6
	local dmac=33:33:00:00:00:01
	local sip=2001:db8:1::1
	local dip=ff02::1
	local mode="-6"
	local name="IPv6"

	test_l2_miss_ll_multicast_common $proto $dmac $sip $dip $mode $name
}

test_l2_miss_ll_multicast()
{
	test_l2_miss_ll_multicast_ipv4
	test_l2_miss_ll_multicast_ipv6
}

test_l2_miss_broadcast()
{
	local dmac=ff:ff:ff:ff:ff:ff
	local smac=00:01:02:03:04:05

	RET=0

	tc filter add dev $swp2 egress protocol all handle 101 pref 1 \
	   flower l2_miss 1 dst_mac $dmac src_mac $smac \
	   action pass
	tc filter add dev $swp2 egress protocol all handle 102 pref 1 \
	   flower l2_miss 0 dst_mac $dmac src_mac $smac \
	   action pass

	$MZ $h1 -a $smac -b $dmac -c 1 -p 100 -q

	tc_check_packets "dev $swp2 egress" 101 0
	check_err $? "L2 miss filter was hit when should not"

	tc_check_packets "dev $swp2 egress" 102 1
	check_err $? "L2 no miss filter was not hit when should"

	tc filter del dev $swp2 egress protocol all pref 1 handle 102 flower
	tc filter del dev $swp2 egress protocol all pref 1 handle 101 flower

	log_test "L2 miss - Broadcast"
}

setup_prepare()
{
	h1=${NETIFS[p1]}
	swp1=${NETIFS[p2]}

	swp2=${NETIFS[p3]}
	h2=${NETIFS[p4]}

	vrf_prepare
	h1_create
	h2_create
	switch_create
}

cleanup()
{
	pre_cleanup

	switch_destroy
	h2_destroy
	h1_destroy
	vrf_cleanup
}

trap cleanup EXIT

setup_prepare
setup_wait

tests_run

exit $EXIT_STATUS