1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3
4# +-----------------------+                          +------------------------+
5# | H1 (vrf)              |                          | H2 (vrf)               |
6# | + $h1.10              |                          | + $h2.10               |
7# | | 192.0.2.1/28        |                          | | 192.0.2.2/28         |
8# | | 2001:db8:1::1/64    |                          | | 2001:db8:1::2/64     |
9# | |                     |                          | |                      |
10# | |  + $h1.20           |                          | |  + $h2.20            |
11# | \  | 198.51.100.1/24  |                          | \  | 198.51.100.2/24   |
12# |  \ | 2001:db8:2::1/64 |                          |  \ | 2001:db8:2::2/64  |
13# |   \|                  |                          |   \|                   |
14# |    + $h1              |                          |    + $h2               |
15# +----|------------------+                          +----|-------------------+
16#      |                                                  |
17# +----|--------------------------------------------------|-------------------+
18# | SW |                                                  |                   |
19# | +--|--------------------------------------------------|-----------------+ |
20# | |  + $swp1                   BR0 (802.1q)             + $swp2           | |
21# | |     vid 10                                             vid 10         | |
22# | |     vid 20                                             vid 20         | |
23# | |                                                                       | |
24# | +-----------------------------------------------------------------------+ |
25# +---------------------------------------------------------------------------+
26
27ALL_TESTS="
28	cfg_test
29	fwd_test
30	ctrl_test
31"
32
33NUM_NETIFS=4
34source lib.sh
35source tc_common.sh
36
37h1_create()
38{
39	simple_if_init $h1
40	vlan_create $h1 10 v$h1 192.0.2.1/28 2001:db8:1::1/64
41	vlan_create $h1 20 v$h1 198.51.100.1/24 2001:db8:2::1/64
42}
43
44h1_destroy()
45{
46	vlan_destroy $h1 20
47	vlan_destroy $h1 10
48	simple_if_fini $h1
49}
50
51h2_create()
52{
53	simple_if_init $h2
54	vlan_create $h2 10 v$h2 192.0.2.2/28
55	vlan_create $h2 20 v$h2 198.51.100.2/24
56}
57
58h2_destroy()
59{
60	vlan_destroy $h2 20
61	vlan_destroy $h2 10
62	simple_if_fini $h2
63}
64
65switch_create()
66{
67	ip link add name br0 type bridge vlan_filtering 1 vlan_default_pvid 0 \
68		mcast_snooping 1 mcast_igmp_version 3 mcast_mld_version 2
69	bridge vlan add vid 10 dev br0 self
70	bridge vlan add vid 20 dev br0 self
71	ip link set dev br0 up
72
73	ip link set dev $swp1 master br0
74	ip link set dev $swp1 up
75	bridge vlan add vid 10 dev $swp1
76	bridge vlan add vid 20 dev $swp1
77
78	ip link set dev $swp2 master br0
79	ip link set dev $swp2 up
80	bridge vlan add vid 10 dev $swp2
81	bridge vlan add vid 20 dev $swp2
82
83	tc qdisc add dev br0 clsact
84	tc qdisc add dev $h2 clsact
85}
86
87switch_destroy()
88{
89	tc qdisc del dev $h2 clsact
90	tc qdisc del dev br0 clsact
91
92	bridge vlan del vid 20 dev $swp2
93	bridge vlan del vid 10 dev $swp2
94	ip link set dev $swp2 down
95	ip link set dev $swp2 nomaster
96
97	bridge vlan del vid 20 dev $swp1
98	bridge vlan del vid 10 dev $swp1
99	ip link set dev $swp1 down
100	ip link set dev $swp1 nomaster
101
102	ip link set dev br0 down
103	bridge vlan del vid 20 dev br0 self
104	bridge vlan del vid 10 dev br0 self
105	ip link del dev br0
106}
107
108setup_prepare()
109{
110	h1=${NETIFS[p1]}
111	swp1=${NETIFS[p2]}
112
113	swp2=${NETIFS[p3]}
114	h2=${NETIFS[p4]}
115
116	vrf_prepare
117	forwarding_enable
118
119	h1_create
120	h2_create
121	switch_create
122}
123
124cleanup()
125{
126	pre_cleanup
127
128	switch_destroy
129	h2_destroy
130	h1_destroy
131
132	forwarding_restore
133	vrf_cleanup
134}
135
136cfg_test_host_common()
137{
138	local name=$1; shift
139	local grp=$1; shift
140	local src=$1; shift
141	local state=$1; shift
142	local invalid_state=$1; shift
143
144	RET=0
145
146	# Check basic add, replace and delete behavior.
147	bridge mdb add dev br0 port br0 grp $grp $state vid 10
148	bridge mdb show dev br0 vid 10 | grep -q "$grp"
149	check_err $? "Failed to add $name host entry"
150
151	bridge mdb replace dev br0 port br0 grp $grp $state vid 10 &> /dev/null
152	check_fail $? "Managed to replace $name host entry"
153
154	bridge mdb del dev br0 port br0 grp $grp $state vid 10
155	bridge mdb show dev br0 vid 10 | grep -q "$grp"
156	check_fail $? "Failed to delete $name host entry"
157
158	# Check error cases.
159	bridge mdb add dev br0 port br0 grp $grp $invalid_state vid 10 \
160		&> /dev/null
161	check_fail $? "Managed to add $name host entry with a $invalid_state state"
162
163	bridge mdb add dev br0 port br0 grp $grp src $src $state vid 10 \
164		&> /dev/null
165	check_fail $? "Managed to add $name host entry with a source"
166
167	bridge mdb add dev br0 port br0 grp $grp $state vid 10 \
168		filter_mode exclude &> /dev/null
169	check_fail $? "Managed to add $name host entry with a filter mode"
170
171	bridge mdb add dev br0 port br0 grp $grp $state vid 10 \
172		source_list $src &> /dev/null
173	check_fail $? "Managed to add $name host entry with a source list"
174
175	bridge mdb add dev br0 port br0 grp $grp $state vid 10 \
176		proto 123 &> /dev/null
177	check_fail $? "Managed to add $name host entry with a protocol"
178
179	log_test "Common host entries configuration tests ($name)"
180}
181
182# Check configuration of host entries from all types.
183cfg_test_host()
184{
185	echo
186	log_info "# Host entries configuration tests"
187
188	cfg_test_host_common "IPv4" "239.1.1.1" "192.0.2.1" "temp" "permanent"
189	cfg_test_host_common "IPv6" "ff0e::1" "2001:db8:1::1" "temp" "permanent"
190	cfg_test_host_common "L2" "01:02:03:04:05:06" "00:00:00:00:00:01" \
191		"permanent" "temp"
192}
193
194cfg_test_port_common()
195{
196	local name=$1;shift
197	local grp_key=$1; shift
198
199	RET=0
200
201	# Check basic add, replace and delete behavior.
202	bridge mdb add dev br0 port $swp1 $grp_key permanent vid 10
203	bridge mdb show dev br0 vid 10 | grep -q "$grp_key"
204	check_err $? "Failed to add $name entry"
205
206	bridge mdb replace dev br0 port $swp1 $grp_key permanent vid 10 \
207		&> /dev/null
208	check_err $? "Failed to replace $name entry"
209
210	bridge mdb del dev br0 port $swp1 $grp_key permanent vid 10
211	bridge mdb show dev br0 vid 10 | grep -q "$grp_key"
212	check_fail $? "Failed to delete $name entry"
213
214	# Check default protocol and replacement.
215	bridge mdb add dev br0 port $swp1 $grp_key permanent vid 10
216	bridge -d mdb show dev br0 vid 10 | grep "$grp_key" | grep -q "static"
217	check_err $? "$name entry not added with default \"static\" protocol"
218
219	bridge mdb replace dev br0 port $swp1 $grp_key permanent vid 10 \
220		proto 123
221	bridge -d mdb show dev br0 vid 10 | grep "$grp_key" | grep -q "123"
222	check_err $? "Failed to replace protocol of $name entry"
223	bridge mdb del dev br0 port $swp1 $grp_key permanent vid 10
224
225	# Check behavior when VLAN is not specified.
226	bridge mdb add dev br0 port $swp1 $grp_key permanent
227	bridge mdb show dev br0 vid 10 | grep -q "$grp_key"
228	check_err $? "$name entry with VLAN 10 not added when VLAN was not specified"
229	bridge mdb show dev br0 vid 20 | grep -q "$grp_key"
230	check_err $? "$name entry with VLAN 20 not added when VLAN was not specified"
231
232	bridge mdb del dev br0 port $swp1 $grp_key permanent
233	bridge mdb show dev br0 vid 10 | grep -q "$grp_key"
234	check_fail $? "$name entry with VLAN 10 not deleted when VLAN was not specified"
235	bridge mdb show dev br0 vid 20 | grep -q "$grp_key"
236	check_fail $? "$name entry with VLAN 20 not deleted when VLAN was not specified"
237
238	# Check behavior when bridge port is down.
239	ip link set dev $swp1 down
240
241	bridge mdb add dev br0 port $swp1 $grp_key permanent vid 10
242	check_err $? "Failed to add $name permanent entry when bridge port is down"
243
244	bridge mdb del dev br0 port $swp1 $grp_key permanent vid 10
245
246	bridge mdb add dev br0 port $swp1 $grp_key temp vid 10 &> /dev/null
247	check_fail $? "Managed to add $name temporary entry when bridge port is down"
248
249	ip link set dev $swp1 up
250	setup_wait_dev $swp1
251
252	# Check error cases.
253	ip link set dev br0 down
254	bridge mdb add dev br0 port $swp1 $grp_key permanent vid 10 \
255		&> /dev/null
256	check_fail $? "Managed to add $name entry when bridge is down"
257	ip link set dev br0 up
258
259	ip link set dev br0 type bridge mcast_snooping 0
260	bridge mdb add dev br0 port $swp1 $grp_key permanent vid \
261		10 &> /dev/null
262	check_fail $? "Managed to add $name entry when multicast snooping is disabled"
263	ip link set dev br0 type bridge mcast_snooping 1
264
265	bridge mdb add dev br0 port $swp1 $grp_key permanent vid 5000 \
266		&> /dev/null
267	check_fail $? "Managed to add $name entry with an invalid VLAN"
268
269	log_test "Common port group entries configuration tests ($name)"
270}
271
272src_list_create()
273{
274	local src_prefix=$1; shift
275	local num_srcs=$1; shift
276	local src_list
277	local i
278
279	for i in $(seq 1 $num_srcs); do
280		src_list=${src_list},${src_prefix}${i}
281	done
282
283	echo $src_list | cut -c 2-
284}
285
286__cfg_test_port_ip_star_g()
287{
288	local name=$1; shift
289	local grp=$1; shift
290	local invalid_grp=$1; shift
291	local src_prefix=$1; shift
292	local src1=${src_prefix}1
293	local src2=${src_prefix}2
294	local src3=${src_prefix}3
295	local max_srcs=31
296	local num_srcs
297
298	RET=0
299
300	bridge mdb add dev br0 port $swp1 grp $grp vid 10
301	bridge -d mdb show dev br0 vid 10 | grep "$grp" | grep -q "exclude"
302	check_err $? "Default filter mode is not \"exclude\""
303	bridge mdb del dev br0 port $swp1 grp $grp vid 10
304
305	# Check basic add and delete behavior.
306	bridge mdb add dev br0 port $swp1 grp $grp vid 10 filter_mode exclude \
307		source_list $src1
308	bridge -d mdb show dev br0 vid 10 | grep "$grp" | grep -q -v "src"
309	check_err $? "(*, G) entry not created"
310	bridge -d mdb show dev br0 vid 10 | grep "$grp" | grep -q "src $src1"
311	check_err $? "(S, G) entry not created"
312	bridge mdb del dev br0 port $swp1 grp $grp vid 10
313	bridge -d mdb show dev br0 vid 10 | grep "$grp" | grep -q -v "src"
314	check_fail $? "(*, G) entry not deleted"
315	bridge -d mdb show dev br0 vid 10 | grep "$grp" | grep -q "src $src1"
316	check_fail $? "(S, G) entry not deleted"
317
318	## State (permanent / temp) tests.
319
320	# Check that group and source timer are not set for permanent entries.
321	bridge mdb add dev br0 port $swp1 grp $grp permanent vid 10 \
322		filter_mode exclude source_list $src1
323
324	bridge -d mdb show dev br0 vid 10 | grep "$grp" | grep -v "src" | \
325		grep -q "permanent"
326	check_err $? "(*, G) entry not added as \"permanent\" when should"
327	bridge -d mdb show dev br0 vid 10 | grep "$grp" | grep "src" | \
328		grep -q "permanent"
329	check_err $? "(S, G) entry not added as \"permanent\" when should"
330
331	bridge -d -s mdb show dev br0 vid 10 | grep "$grp" | grep -v "src" | \
332		grep -q " 0.00"
333	check_err $? "(*, G) \"permanent\" entry has a pending group timer"
334	bridge -d -s mdb show dev br0 vid 10 | grep "$grp" | grep -v "src" | \
335		grep -q "\/0.00"
336	check_err $? "\"permanent\" source entry has a pending source timer"
337
338	bridge mdb del dev br0 port $swp1 grp $grp vid 10
339
340	# Check that group timer is set for temporary (*, G) EXCLUDE, but not
341	# the source timer.
342	bridge mdb add dev br0 port $swp1 grp $grp temp vid 10 \
343		filter_mode exclude source_list $src1
344
345	bridge -d mdb show dev br0 vid 10 | grep "$grp" | grep -v "src" | \
346		grep -q "temp"
347	check_err $? "(*, G) EXCLUDE entry not added as \"temp\" when should"
348	bridge -d mdb show dev br0 vid 10 | grep "$grp" | grep "src" | \
349		grep -q "temp"
350	check_err $? "(S, G) \"blocked\" entry not added as \"temp\" when should"
351
352	bridge -d -s mdb show dev br0 vid 10 | grep "$grp" | grep -v "src" | \
353		grep -q " 0.00"
354	check_fail $? "(*, G) EXCLUDE entry does not have a pending group timer"
355	bridge -d -s mdb show dev br0 vid 10 | grep "$grp" | grep -v "src" | \
356		grep -q "\/0.00"
357	check_err $? "\"blocked\" source entry has a pending source timer"
358
359	bridge mdb del dev br0 port $swp1 grp $grp vid 10
360
361	# Check that group timer is not set for temporary (*, G) INCLUDE, but
362	# that the source timer is set.
363	bridge mdb add dev br0 port $swp1 grp $grp temp vid 10 \
364		filter_mode include source_list $src1
365
366	bridge -d mdb show dev br0 vid 10 | grep "$grp" | grep -v "src" | \
367		grep -q "temp"
368	check_err $? "(*, G) INCLUDE entry not added as \"temp\" when should"
369	bridge -d mdb show dev br0 vid 10 | grep "$grp" | grep "src" | \
370		grep -q "temp"
371	check_err $? "(S, G) entry not added as \"temp\" when should"
372
373	bridge -d -s mdb show dev br0 vid 10 | grep "$grp" | grep -v "src" | \
374		grep -q " 0.00"
375	check_err $? "(*, G) INCLUDE entry has a pending group timer"
376	bridge -d -s mdb show dev br0 vid 10 | grep "$grp" | grep -v "src" | \
377		grep -q "\/0.00"
378	check_fail $? "Source entry does not have a pending source timer"
379
380	bridge mdb del dev br0 port $swp1 grp $grp vid 10
381
382	# Check that group timer is never set for (S, G) entries.
383	bridge mdb add dev br0 port $swp1 grp $grp temp vid 10 \
384		filter_mode include source_list $src1
385
386	bridge -d -s mdb show dev br0 vid 10 | grep "$grp" | grep "src" | \
387		grep -q " 0.00"
388	check_err $? "(S, G) entry has a pending group timer"
389
390	bridge mdb del dev br0 port $swp1 grp $grp vid 10
391
392	## Filter mode (include / exclude) tests.
393
394	# Check that (*, G) INCLUDE entries are added with correct filter mode
395	# and that (S, G) entries are not marked as "blocked".
396	bridge mdb add dev br0 port $swp1 grp $grp vid 10 \
397		filter_mode include source_list $src1
398
399	bridge -d mdb show dev br0 vid 10 | grep "$grp" | grep -v "src" | \
400		grep -q "include"
401	check_err $? "(*, G) INCLUDE not added with \"include\" filter mode"
402	bridge -d mdb show dev br0 vid 10 | grep "$grp" | grep "src" | \
403		grep -q "blocked"
404	check_fail $? "(S, G) entry marked as \"blocked\" when should not"
405
406	bridge mdb del dev br0 port $swp1 grp $grp vid 10
407
408	# Check that (*, G) EXCLUDE entries are added with correct filter mode
409	# and that (S, G) entries are marked as "blocked".
410	bridge mdb add dev br0 port $swp1 grp $grp vid 10 \
411		filter_mode exclude source_list $src1
412
413	bridge -d mdb show dev br0 vid 10 | grep "$grp" | grep -v "src" | \
414		grep -q "exclude"
415	check_err $? "(*, G) EXCLUDE not added with \"exclude\" filter mode"
416	bridge -d mdb show dev br0 vid 10 | grep "$grp" | grep "src" | \
417		grep -q "blocked"
418	check_err $? "(S, G) entry not marked as \"blocked\" when should"
419
420	bridge mdb del dev br0 port $swp1 grp $grp vid 10
421
422	## Protocol tests.
423
424	# Check that (*, G) and (S, G) entries are added with the specified
425	# protocol.
426	bridge mdb add dev br0 port $swp1 grp $grp vid 10 \
427		filter_mode exclude source_list $src1 proto zebra
428
429	bridge -d mdb show dev br0 vid 10 | grep "$grp" | grep -v "src" | \
430		grep -q "zebra"
431	check_err $? "(*, G) entry not added with \"zebra\" protocol"
432	bridge -d mdb show dev br0 vid 10 | grep "$grp" | grep "src" | \
433		grep -q "zebra"
434	check_err $? "(S, G) entry not marked added with \"zebra\" protocol"
435
436	bridge mdb del dev br0 port $swp1 grp $grp vid 10
437
438	## Replace tests.
439
440	# Check that state can be modified.
441	bridge mdb add dev br0 port $swp1 grp $grp temp vid 10 \
442		filter_mode exclude source_list $src1
443
444	bridge mdb replace dev br0 port $swp1 grp $grp permanent vid 10 \
445		filter_mode exclude source_list $src1
446	bridge -d mdb show dev br0 vid 10 | grep "$grp" | grep -v "src" | \
447		grep -q "permanent"
448	check_err $? "(*, G) entry not marked as \"permanent\" after replace"
449	bridge -d mdb show dev br0 vid 10 | grep "$grp" | grep "src" | \
450		grep -q "permanent"
451	check_err $? "(S, G) entry not marked as \"permanent\" after replace"
452
453	bridge mdb replace dev br0 port $swp1 grp $grp temp vid 10 \
454		filter_mode exclude source_list $src1
455	bridge -d mdb show dev br0 vid 10 | grep "$grp" | grep -v "src" | \
456		grep -q "temp"
457	check_err $? "(*, G) entry not marked as \"temp\" after replace"
458	bridge -d mdb show dev br0 vid 10 | grep "$grp" | grep "src" | \
459		grep -q "temp"
460	check_err $? "(S, G) entry not marked as \"temp\" after replace"
461
462	bridge mdb del dev br0 port $swp1 grp $grp vid 10
463
464	# Check that filter mode can be modified.
465	bridge mdb add dev br0 port $swp1 grp $grp temp vid 10 \
466		filter_mode exclude source_list $src1
467
468	bridge mdb replace dev br0 port $swp1 grp $grp temp vid 10 \
469		filter_mode include source_list $src1
470	bridge -d mdb show dev br0 vid 10 | grep "$grp" | grep -v "src" | \
471		grep -q "include"
472	check_err $? "(*, G) not marked with \"include\" filter mode after replace"
473	bridge -d mdb show dev br0 vid 10 | grep "$grp" | grep "src" | \
474		grep -q "blocked"
475	check_fail $? "(S, G) marked as \"blocked\" after replace"
476
477	bridge mdb replace dev br0 port $swp1 grp $grp temp vid 10 \
478		filter_mode exclude source_list $src1
479	bridge -d mdb show dev br0 vid 10 | grep "$grp" | grep -v "src" | \
480		grep -q "exclude"
481	check_err $? "(*, G) not marked with \"exclude\" filter mode after replace"
482	bridge -d mdb show dev br0 vid 10 | grep "$grp" | grep "src" | \
483		grep -q "blocked"
484	check_err $? "(S, G) not marked as \"blocked\" after replace"
485
486	bridge mdb del dev br0 port $swp1 grp $grp vid 10
487
488	# Check that sources can be added to and removed from the source list.
489	bridge mdb add dev br0 port $swp1 grp $grp temp vid 10 \
490		filter_mode exclude source_list $src1
491
492	bridge mdb replace dev br0 port $swp1 grp $grp temp vid 10 \
493		filter_mode exclude source_list $src1,$src2,$src3
494	bridge -d mdb show dev br0 vid 10 | grep "$grp" | grep -q "src $src1"
495	check_err $? "(S, G) entry for source $src1 not created after replace"
496	bridge -d mdb show dev br0 vid 10 | grep "$grp" | grep -q "src $src2"
497	check_err $? "(S, G) entry for source $src2 not created after replace"
498	bridge -d mdb show dev br0 vid 10 | grep "$grp" | grep -q "src $src3"
499	check_err $? "(S, G) entry for source $src3 not created after replace"
500
501	bridge mdb replace dev br0 port $swp1 grp $grp temp vid 10 \
502		filter_mode exclude source_list $src1,$src3
503	bridge -d mdb show dev br0 vid 10 | grep "$grp" | grep -q "src $src1"
504	check_err $? "(S, G) entry for source $src1 not created after second replace"
505	bridge -d mdb show dev br0 vid 10 | grep "$grp" | grep -q "src $src2"
506	check_fail $? "(S, G) entry for source $src2 created after second replace"
507	bridge -d mdb show dev br0 vid 10 | grep "$grp" | grep -q "src $src3"
508	check_err $? "(S, G) entry for source $src3 not created after second replace"
509
510	bridge mdb del dev br0 port $swp1 grp $grp vid 10
511
512	# Check that protocol can be modified.
513	bridge mdb add dev br0 port $swp1 grp $grp temp vid 10 \
514		filter_mode exclude source_list $src1 proto zebra
515
516	bridge mdb replace dev br0 port $swp1 grp $grp temp vid 10 \
517		filter_mode exclude source_list $src1 proto bgp
518	bridge -d mdb show dev br0 vid 10 | grep "$grp" | grep -v "src" | \
519		grep -q "bgp"
520	check_err $? "(*, G) protocol not changed to \"bgp\" after replace"
521	bridge -d mdb show dev br0 vid 10 | grep "$grp" | grep "src" | \
522		grep -q "bgp"
523	check_err $? "(S, G) protocol not changed to \"bgp\" after replace"
524
525	bridge mdb del dev br0 port $swp1 grp $grp vid 10
526
527	## Star exclude tests.
528
529	# Check star exclude functionality. When adding a new EXCLUDE (*, G),
530	# it needs to be also added to all (S, G) entries for proper
531	# replication.
532	bridge mdb add dev br0 port $swp2 grp $grp vid 10 \
533		filter_mode include source_list $src1
534	bridge mdb add dev br0 port $swp1 grp $grp vid 10
535	bridge -d mdb show dev br0 vid 10 | grep "$swp1" | grep "$grp" | \
536		grep "$src1" | grep -q "added_by_star_ex"
537	check_err $? "\"added_by_star_ex\" entry not created after adding (*, G) entry"
538	bridge mdb del dev br0 port $swp1 grp $grp vid 10
539	bridge mdb del dev br0 port $swp2 grp $grp src $src1 vid 10
540
541	## Error cases tests.
542
543	bridge mdb add dev br0 port $swp1 grp $invalid_grp vid 10 &> /dev/null
544	check_fail $? "Managed to add an entry with an invalid group"
545
546	bridge mdb add dev br0 port $swp1 grp $grp vid 10 filter_mode include \
547		&> /dev/null
548	check_fail $? "Managed to add an INCLUDE entry with an empty source list"
549
550	bridge mdb add dev br0 port $swp1 grp $grp vid 10 filter_mode include \
551		source_list $grp &> /dev/null
552	check_fail $? "Managed to add an entry with an invalid source in source list"
553
554	bridge mdb add dev br0 port $swp1 grp $grp vid 10 \
555		source_list $src &> /dev/null
556	check_fail $? "Managed to add an entry with a source list and no filter mode"
557
558	bridge mdb add dev br0 port $swp1 grp $grp vid 10 filter_mode include \
559		source_list $src1
560	bridge mdb add dev br0 port $swp1 grp $grp vid 10 filter_mode exclude \
561		source_list $src1 &> /dev/null
562	check_fail $? "Managed to replace an entry without using replace"
563	bridge mdb del dev br0 port $swp1 grp $grp vid 10
564
565	bridge mdb add dev br0 port $swp1 grp $grp src $src2 vid 10
566	bridge mdb add dev br0 port $swp1 grp $grp vid 10 filter_mode include \
567		source_list $src1,$src2,$src3 &> /dev/null
568	check_fail $? "Managed to add a source that already has a forwarding entry"
569	bridge mdb del dev br0 port $swp1 grp $grp src $src2 vid 10
570
571	# Check maximum number of sources.
572	bridge mdb add dev br0 port $swp1 grp $grp vid 10 filter_mode exclude \
573		source_list $(src_list_create $src_prefix $max_srcs)
574	num_srcs=$(bridge -d mdb show dev br0 vid 10 | grep "$grp" | \
575		grep "src" | wc -l)
576	[[ $num_srcs -eq $max_srcs ]]
577	check_err $? "Failed to configure maximum number of sources ($max_srcs)"
578	bridge mdb del dev br0 port $swp1 grp $grp vid 10
579
580	bridge mdb add dev br0 port $swp1 grp $grp vid 10 filter_mode exclude \
581		source_list $(src_list_create $src_prefix $((max_srcs + 1))) \
582		&> /dev/null
583	check_fail $? "Managed to exceed maximum number of sources ($max_srcs)"
584
585	log_test "$name (*, G) port group entries configuration tests"
586}
587
588cfg_test_port_ip_star_g()
589{
590	echo
591	log_info "# Port group entries configuration tests - (*, G)"
592
593	cfg_test_port_common "IPv4 (*, G)" "grp 239.1.1.1"
594	cfg_test_port_common "IPv6 (*, G)" "grp ff0e::1"
595	__cfg_test_port_ip_star_g "IPv4" "239.1.1.1" "224.0.0.1" "192.0.2."
596	__cfg_test_port_ip_star_g "IPv6" "ff0e::1" "ff02::1" "2001:db8:1::"
597}
598
599__cfg_test_port_ip_sg()
600{
601	local name=$1; shift
602	local grp=$1; shift
603	local src=$1; shift
604	local grp_key="grp $grp src $src"
605
606	RET=0
607
608	bridge mdb add dev br0 port $swp1 $grp_key vid 10
609	bridge -d mdb show dev br0 vid 10 | grep "$grp_key" | grep -q "include"
610	check_err $? "Default filter mode is not \"include\""
611	bridge mdb del dev br0 port $swp1 $grp_key vid 10
612
613	# Check that entries can be added as both permanent and temp and that
614	# group timer is set correctly.
615	bridge mdb add dev br0 port $swp1 $grp_key permanent vid 10
616	bridge -d mdb show dev br0 vid 10 | grep "$grp_key" | \
617		grep -q "permanent"
618	check_err $? "Entry not added as \"permanent\" when should"
619	bridge -d -s mdb show dev br0 vid 10 | grep "$grp_key" | \
620		grep -q "0.00"
621	check_err $? "\"permanent\" entry has a pending group timer"
622	bridge mdb del dev br0 port $swp1 $grp_key vid 10
623
624	bridge mdb add dev br0 port $swp1 $grp_key temp vid 10
625	bridge -d mdb show dev br0 vid 10 | grep "$grp_key" | \
626		grep -q "temp"
627	check_err $? "Entry not added as \"temp\" when should"
628	bridge -d -s mdb show dev br0 vid 10 | grep "$grp_key" | \
629		grep -q "0.00"
630	check_fail $? "\"temp\" entry has an unpending group timer"
631	bridge mdb del dev br0 port $swp1 $grp_key vid 10
632
633	# Check error cases.
634	bridge mdb add dev br0 port $swp1 $grp_key vid 10 \
635		filter_mode include &> /dev/null
636	check_fail $? "Managed to add an entry with a filter mode"
637
638	bridge mdb add dev br0 port $swp1 $grp_key vid 10 \
639		filter_mode include source_list $src &> /dev/null
640	check_fail $? "Managed to add an entry with a source list"
641
642	bridge mdb add dev br0 port $swp1 grp $grp src $grp vid 10 &> /dev/null
643	check_fail $? "Managed to add an entry with an invalid source"
644
645	bridge mdb add dev br0 port $swp1 $grp_key vid 10 temp
646	bridge mdb add dev br0 port $swp1 $grp_key vid 10 permanent &> /dev/null
647	check_fail $? "Managed to replace an entry without using replace"
648	bridge mdb del dev br0 port $swp1 $grp_key vid 10
649
650	# Check that we can replace available attributes.
651	bridge mdb add dev br0 port $swp1 $grp_key vid 10 proto 123
652	bridge mdb replace dev br0 port $swp1 $grp_key vid 10 proto 111
653	bridge -d mdb show dev br0 vid 10 | grep "$grp_key" | \
654		grep -q "111"
655	check_err $? "Failed to replace protocol"
656
657	bridge mdb replace dev br0 port $swp1 $grp_key vid 10 permanent
658	bridge -d mdb show dev br0 vid 10 | grep "$grp_key" | \
659		grep -q "permanent"
660	check_err $? "Entry not marked as \"permanent\" after replace"
661	bridge -d -s mdb show dev br0 vid 10 | grep "$grp_key" | \
662		grep -q "0.00"
663	check_err $? "Entry has a pending group timer after replace"
664
665	bridge mdb replace dev br0 port $swp1 $grp_key vid 10 temp
666	bridge -d mdb show dev br0 vid 10 | grep "$grp_key" | \
667		grep -q "temp"
668	check_err $? "Entry not marked as \"temp\" after replace"
669	bridge -d -s mdb show dev br0 vid 10 | grep "$grp_key" | \
670		grep -q "0.00"
671	check_fail $? "Entry has an unpending group timer after replace"
672	bridge mdb del dev br0 port $swp1 $grp_key vid 10
673
674	# Check star exclude functionality. When adding a (S, G), all matching
675	# (*, G) ports need to be added to it.
676	bridge mdb add dev br0 port $swp2 grp $grp vid 10
677	bridge mdb add dev br0 port $swp1 $grp_key vid 10
678	bridge mdb show dev br0 vid 10 | grep "$grp_key" | grep $swp2 | \
679		grep -q "added_by_star_ex"
680	check_err $? "\"added_by_star_ex\" entry not created after adding (S, G) entry"
681	bridge mdb del dev br0 port $swp1 $grp_key vid 10
682	bridge mdb del dev br0 port $swp2 grp $grp vid 10
683
684	log_test "$name (S, G) port group entries configuration tests"
685}
686
687cfg_test_port_ip_sg()
688{
689	echo
690	log_info "# Port group entries configuration tests - (S, G)"
691
692	cfg_test_port_common "IPv4 (S, G)" "grp 239.1.1.1 src 192.0.2.1"
693	cfg_test_port_common "IPv6 (S, G)" "grp ff0e::1 src 2001:db8:1::1"
694	__cfg_test_port_ip_sg "IPv4" "239.1.1.1" "192.0.2.1"
695	__cfg_test_port_ip_sg "IPv6" "ff0e::1" "2001:db8:1::1"
696}
697
698cfg_test_port_ip()
699{
700	cfg_test_port_ip_star_g
701	cfg_test_port_ip_sg
702}
703
704__cfg_test_port_l2()
705{
706	local grp="01:02:03:04:05:06"
707
708	RET=0
709
710	bridge meb add dev br0 port $swp grp 00:01:02:03:04:05 \
711		permanent vid 10 &> /dev/null
712	check_fail $? "Managed to add an entry with unicast MAC"
713
714	bridge mdb add dev br0 port $swp grp $grp src 00:01:02:03:04:05 \
715		permanent vid 10 &> /dev/null
716	check_fail $? "Managed to add an entry with a source"
717
718	bridge mdb add dev br0 port $swp1 grp $grp permanent vid 10 \
719		filter_mode include &> /dev/null
720	check_fail $? "Managed to add an entry with a filter mode"
721
722	bridge mdb add dev br0 port $swp1 grp $grp permanent vid 10 \
723		source_list 00:01:02:03:04:05 &> /dev/null
724	check_fail $? "Managed to add an entry with a source list"
725
726	log_test "L2 (*, G) port group entries configuration tests"
727}
728
729cfg_test_port_l2()
730{
731	echo
732	log_info "# Port group entries configuration tests - L2"
733
734	cfg_test_port_common "L2 (*, G)" "grp 01:02:03:04:05:06"
735	__cfg_test_port_l2
736}
737
738# Check configuration of regular (port) entries of all types.
739cfg_test_port()
740{
741	cfg_test_port_ip
742	cfg_test_port_l2
743}
744
745ipv4_grps_get()
746{
747	local max_grps=$1; shift
748	local i
749
750	for i in $(seq 0 $((max_grps - 1))); do
751		echo "239.1.1.$i"
752	done
753}
754
755ipv6_grps_get()
756{
757	local max_grps=$1; shift
758	local i
759
760	for i in $(seq 0 $((max_grps - 1))); do
761		echo "ff0e::$(printf %x $i)"
762	done
763}
764
765l2_grps_get()
766{
767	local max_grps=$1; shift
768	local i
769
770	for i in $(seq 0 $((max_grps - 1))); do
771		echo "01:00:00:00:00:$(printf %02x $i)"
772	done
773}
774
775cfg_test_dump_common()
776{
777	local name=$1; shift
778	local fn=$1; shift
779	local max_bridges=2
780	local max_grps=256
781	local max_ports=32
782	local num_entries
783	local batch_file
784	local grp
785	local i j
786
787	RET=0
788
789	# Create net devices.
790	for i in $(seq 1 $max_bridges); do
791		ip link add name br-test${i} up type bridge vlan_filtering 1 \
792			mcast_snooping 1
793		for j in $(seq 1 $max_ports); do
794			ip link add name br-test${i}-du${j} up \
795				master br-test${i} type dummy
796		done
797	done
798
799	# Create batch file with MDB entries.
800	batch_file=$(mktemp)
801	for i in $(seq 1 $max_bridges); do
802		for j in $(seq 1 $max_ports); do
803			for grp in $($fn $max_grps); do
804				echo "mdb add dev br-test${i} \
805					port br-test${i}-du${j} grp $grp \
806					permanent vid 1" >> $batch_file
807			done
808		done
809	done
810
811	# Program the batch file and check for expected number of entries.
812	bridge -b $batch_file
813	for i in $(seq 1 $max_bridges); do
814		num_entries=$(bridge mdb show dev br-test${i} | \
815			grep "permanent" | wc -l)
816		[[ $num_entries -eq $((max_grps * max_ports)) ]]
817		check_err $? "Wrong number of entries in br-test${i}"
818	done
819
820	# Cleanup.
821	rm $batch_file
822	for i in $(seq 1 $max_bridges); do
823		ip link del dev br-test${i}
824		for j in $(seq $max_ports); do
825			ip link del dev br-test${i}-du${j}
826		done
827	done
828
829	log_test "$name large scale dump tests"
830}
831
832# Check large scale dump.
833cfg_test_dump()
834{
835	echo
836	log_info "# Large scale dump tests"
837
838	cfg_test_dump_common "IPv4" ipv4_grps_get
839	cfg_test_dump_common "IPv6" ipv6_grps_get
840	cfg_test_dump_common "L2" l2_grps_get
841}
842
843cfg_test()
844{
845	cfg_test_host
846	cfg_test_port
847	cfg_test_dump
848}
849
850__fwd_test_host_ip()
851{
852	local grp=$1; shift
853	local src=$1; shift
854	local mode=$1; shift
855	local name
856	local eth_type
857
858	RET=0
859
860	if [[ $mode == "-4" ]]; then
861		name="IPv4"
862		eth_type="ipv4"
863	else
864		name="IPv6"
865		eth_type="ipv6"
866	fi
867
868	tc filter add dev br0 ingress protocol 802.1q pref 1 handle 1 flower \
869		vlan_ethtype $eth_type vlan_id 10 dst_ip $grp src_ip $src \
870		action drop
871
872	# Packet should only be flooded to multicast router ports when there is
873	# no matching MDB entry. The bridge is not configured as a multicast
874	# router port.
875	$MZ $mode $h1.10 -c 1 -p 128 -A $src -B $grp -t udp -q
876	tc_check_packets "dev br0 ingress" 1 0
877	check_err $? "Packet locally received after flood"
878
879	# Install a regular port group entry and expect the packet to not be
880	# locally received.
881	bridge mdb add dev br0 port $swp2 grp $grp temp vid 10
882	$MZ $mode $h1.10 -c 1 -p 128 -A $src -B $grp -t udp -q
883	tc_check_packets "dev br0 ingress" 1 0
884	check_err $? "Packet locally received after installing a regular entry"
885
886	# Add a host entry and expect the packet to be locally received.
887	bridge mdb add dev br0 port br0 grp $grp temp vid 10
888	$MZ $mode $h1.10 -c 1 -p 128 -A $src -B $grp -t udp -q
889	tc_check_packets "dev br0 ingress" 1 1
890	check_err $? "Packet not locally received after adding a host entry"
891
892	# Remove the host entry and expect the packet to not be locally
893	# received.
894	bridge mdb del dev br0 port br0 grp $grp vid 10
895	$MZ $mode $h1.10 -c 1 -p 128 -A $src -B $grp -t udp -q
896	tc_check_packets "dev br0 ingress" 1 1
897	check_err $? "Packet locally received after removing a host entry"
898
899	bridge mdb del dev br0 port $swp2 grp $grp vid 10
900
901	tc filter del dev br0 ingress protocol 802.1q pref 1 handle 1 flower
902
903	log_test "$name host entries forwarding tests"
904}
905
906fwd_test_host_ip()
907{
908	__fwd_test_host_ip "239.1.1.1" "192.0.2.1" "-4"
909	__fwd_test_host_ip "ff0e::1" "2001:db8:1::1" "-6"
910}
911
912fwd_test_host_l2()
913{
914	local dmac=01:02:03:04:05:06
915
916	RET=0
917
918	tc filter add dev br0 ingress protocol all pref 1 handle 1 flower \
919		dst_mac $dmac action drop
920
921	# Packet should be flooded and locally received when there is no
922	# matching MDB entry.
923	$MZ $h1.10 -c 1 -p 128 -a own -b $dmac -q
924	tc_check_packets "dev br0 ingress" 1 1
925	check_err $? "Packet not locally received after flood"
926
927	# Install a regular port group entry and expect the packet to not be
928	# locally received.
929	bridge mdb add dev br0 port $swp2 grp $dmac permanent vid 10
930	$MZ $h1.10 -c 1 -p 128 -a own -b $dmac -q
931	tc_check_packets "dev br0 ingress" 1 1
932	check_err $? "Packet locally received after installing a regular entry"
933
934	# Add a host entry and expect the packet to be locally received.
935	bridge mdb add dev br0 port br0 grp $dmac permanent vid 10
936	$MZ $h1.10 -c 1 -p 128 -a own -b $dmac -q
937	tc_check_packets "dev br0 ingress" 1 2
938	check_err $? "Packet not locally received after adding a host entry"
939
940	# Remove the host entry and expect the packet to not be locally
941	# received.
942	bridge mdb del dev br0 port br0 grp $dmac permanent vid 10
943	$MZ $h1.10 -c 1 -p 128 -a own -b $dmac -q
944	tc_check_packets "dev br0 ingress" 1 2
945	check_err $? "Packet locally received after removing a host entry"
946
947	bridge mdb del dev br0 port $swp2 grp $dmac permanent vid 10
948
949	tc filter del dev br0 ingress protocol all pref 1 handle 1 flower
950
951	log_test "L2 host entries forwarding tests"
952}
953
954fwd_test_host()
955{
956	# Disable multicast router on the bridge to ensure that packets are
957	# only locally received when a matching host entry is present.
958	ip link set dev br0 type bridge mcast_router 0
959
960	fwd_test_host_ip
961	fwd_test_host_l2
962
963	ip link set dev br0 type bridge mcast_router 1
964}
965
966__fwd_test_port_ip()
967{
968	local grp=$1; shift
969	local valid_src=$1; shift
970	local invalid_src=$1; shift
971	local mode=$1; shift
972	local filter_mode=$1; shift
973	local name
974	local eth_type
975	local src_list
976
977	RET=0
978
979	if [[ $mode == "-4" ]]; then
980		name="IPv4"
981		eth_type="ipv4"
982	else
983		name="IPv6"
984		eth_type="ipv6"
985	fi
986
987	# The valid source is the one we expect to get packets from after
988	# adding the entry.
989	if [[ $filter_mode == "include" ]]; then
990		src_list=$valid_src
991	else
992		src_list=$invalid_src
993	fi
994
995	tc filter add dev $h2 ingress protocol 802.1q pref 1 handle 1 flower \
996		vlan_ethtype $eth_type vlan_id 10 dst_ip $grp \
997		src_ip $valid_src action drop
998	tc filter add dev $h2 ingress protocol 802.1q pref 1 handle 2 flower \
999		vlan_ethtype $eth_type vlan_id 10 dst_ip $grp \
1000		src_ip $invalid_src action drop
1001
1002	$MZ $mode $h1.10 -c 1 -p 128 -A $valid_src -B $grp -t udp -q
1003	tc_check_packets "dev $h2 ingress" 1 0
1004	check_err $? "Packet from valid source received on H2 before adding entry"
1005
1006	$MZ $mode $h1.10 -c 1 -p 128 -A $invalid_src -B $grp -t udp -q
1007	tc_check_packets "dev $h2 ingress" 2 0
1008	check_err $? "Packet from invalid source received on H2 before adding entry"
1009
1010	bridge mdb add dev br0 port $swp2 grp $grp vid 10 \
1011		filter_mode $filter_mode source_list $src_list
1012
1013	$MZ $mode $h1.10 -c 1 -p 128 -A $valid_src -B $grp -t udp -q
1014	tc_check_packets "dev $h2 ingress" 1 1
1015	check_err $? "Packet from valid source not received on H2 after adding entry"
1016
1017	$MZ $mode $h1.10 -c 1 -p 128 -A $invalid_src -B $grp -t udp -q
1018	tc_check_packets "dev $h2 ingress" 2 0
1019	check_err $? "Packet from invalid source received on H2 after adding entry"
1020
1021	bridge mdb replace dev br0 port $swp2 grp $grp vid 10 \
1022		filter_mode exclude
1023
1024	$MZ $mode $h1.10 -c 1 -p 128 -A $valid_src -B $grp -t udp -q
1025	tc_check_packets "dev $h2 ingress" 1 2
1026	check_err $? "Packet from valid source not received on H2 after allowing all sources"
1027
1028	$MZ $mode $h1.10 -c 1 -p 128 -A $invalid_src -B $grp -t udp -q
1029	tc_check_packets "dev $h2 ingress" 2 1
1030	check_err $? "Packet from invalid source not received on H2 after allowing all sources"
1031
1032	bridge mdb del dev br0 port $swp2 grp $grp vid 10
1033
1034	$MZ $mode $h1.10 -c 1 -p 128 -A $valid_src -B $grp -t udp -q
1035	tc_check_packets "dev $h2 ingress" 1 2
1036	check_err $? "Packet from valid source received on H2 after deleting entry"
1037
1038	$MZ $mode $h1.10 -c 1 -p 128 -A $invalid_src -B $grp -t udp -q
1039	tc_check_packets "dev $h2 ingress" 2 1
1040	check_err $? "Packet from invalid source received on H2 after deleting entry"
1041
1042	tc filter del dev $h2 ingress protocol 802.1q pref 1 handle 2 flower
1043	tc filter del dev $h2 ingress protocol 802.1q pref 1 handle 1 flower
1044
1045	log_test "$name port group \"$filter_mode\" entries forwarding tests"
1046}
1047
1048fwd_test_port_ip()
1049{
1050	__fwd_test_port_ip "239.1.1.1" "192.0.2.1" "192.0.2.2" "-4" "exclude"
1051	__fwd_test_port_ip "ff0e::1" "2001:db8:1::1" "2001:db8:1::2" "-6" \
1052		"exclude"
1053	__fwd_test_port_ip "239.1.1.1" "192.0.2.1" "192.0.2.2" "-4" "include"
1054	__fwd_test_port_ip "ff0e::1" "2001:db8:1::1" "2001:db8:1::2" "-6" \
1055		"include"
1056}
1057
1058fwd_test_port_l2()
1059{
1060	local dmac=01:02:03:04:05:06
1061
1062	RET=0
1063
1064	tc filter add dev $h2 ingress protocol all pref 1 handle 1 flower \
1065		dst_mac $dmac action drop
1066
1067	$MZ $h1.10 -c 1 -p 128 -a own -b $dmac -q
1068	tc_check_packets "dev $h2 ingress" 1 0
1069	check_err $? "Packet received on H2 before adding entry"
1070
1071	bridge mdb add dev br0 port $swp2 grp $dmac permanent vid 10
1072	$MZ $h1.10 -c 1 -p 128 -a own -b $dmac -q
1073	tc_check_packets "dev $h2 ingress" 1 1
1074	check_err $? "Packet not received on H2 after adding entry"
1075
1076	bridge mdb del dev br0 port $swp2 grp $dmac permanent vid 10
1077	$MZ $h1.10 -c 1 -p 128 -a own -b $dmac -q
1078	tc_check_packets "dev $h2 ingress" 1 1
1079	check_err $? "Packet received on H2 after deleting entry"
1080
1081	tc filter del dev $h2 ingress protocol all pref 1 handle 1 flower
1082
1083	log_test "L2 port entries forwarding tests"
1084}
1085
1086fwd_test_port()
1087{
1088	# Disable multicast flooding to ensure that packets are only forwarded
1089	# out of a port when a matching port group entry is present.
1090	bridge link set dev $swp2 mcast_flood off
1091
1092	fwd_test_port_ip
1093	fwd_test_port_l2
1094
1095	bridge link set dev $swp2 mcast_flood on
1096}
1097
1098fwd_test()
1099{
1100	echo
1101	log_info "# Forwarding tests"
1102
1103	# Forwarding according to MDB entries only takes place when the bridge
1104	# detects that there is a valid querier in the network. Set the bridge
1105	# as the querier and assign it a valid IPv6 link-local address to be
1106	# used as the source address for MLD queries.
1107	ip -6 address add fe80::1/64 nodad dev br0
1108	ip link set dev br0 type bridge mcast_querier 1
1109	# Wait the default Query Response Interval (10 seconds) for the bridge
1110	# to determine that there are no other queriers in the network.
1111	sleep 10
1112
1113	fwd_test_host
1114	fwd_test_port
1115
1116	ip link set dev br0 type bridge mcast_querier 0
1117	ip -6 address del fe80::1/64 dev br0
1118}
1119
1120ctrl_igmpv3_is_in_test()
1121{
1122	RET=0
1123
1124	# Add a permanent entry and check that it is not affected by the
1125	# received IGMP packet.
1126	bridge mdb add dev br0 port $swp1 grp 239.1.1.1 permanent vid 10 \
1127		filter_mode include source_list 192.0.2.1
1128
1129	# IS_IN ( 192.0.2.2 )
1130	$MZ $h1.10 -c 1 -A 192.0.2.1 -B 239.1.1.1 \
1131		-t ip proto=2,p=$(igmpv3_is_in_get 239.1.1.1 192.0.2.2) -q
1132
1133	bridge -d mdb show dev br0 vid 10 | grep 239.1.1.1 | grep -q 192.0.2.2
1134	check_fail $? "Permanent entry affected by IGMP packet"
1135
1136	# Replace the permanent entry with a temporary one and check that after
1137	# processing the IGMP packet, a new source is added to the list along
1138	# with a new forwarding entry.
1139	bridge mdb replace dev br0 port $swp1 grp 239.1.1.1 temp vid 10 \
1140		filter_mode include source_list 192.0.2.1
1141
1142	# IS_IN ( 192.0.2.2 )
1143	$MZ $h1.10 -c 1 -A 192.0.2.1 -B 239.1.1.1 \
1144		-t ip proto=2,p=$(igmpv3_is_in_get 239.1.1.1 192.0.2.2) -q
1145
1146	bridge -d mdb show dev br0 vid 10 | grep 239.1.1.1 | grep -v "src" | \
1147		grep -q 192.0.2.2
1148	check_err $? "Source not add to source list"
1149
1150	bridge -d mdb show dev br0 vid 10 | grep 239.1.1.1 | \
1151		grep -q "src 192.0.2.2"
1152	check_err $? "(S, G) entry not created for new source"
1153
1154	bridge mdb del dev br0 port $swp1 grp 239.1.1.1 vid 10
1155
1156	log_test "IGMPv3 MODE_IS_INCLUDE tests"
1157}
1158
1159ctrl_mldv2_is_in_test()
1160{
1161	RET=0
1162
1163	# Add a permanent entry and check that it is not affected by the
1164	# received MLD packet.
1165	bridge mdb add dev br0 port $swp1 grp ff0e::1 permanent vid 10 \
1166		filter_mode include source_list 2001:db8:1::1
1167
1168	# IS_IN ( 2001:db8:1::2 )
1169	local p=$(mldv2_is_in_get fe80::1 ff0e::1 2001:db8:1::2)
1170	$MZ -6 $h1.10 -c 1 -A fe80::1 -B ff0e::1 \
1171		-t ip hop=1,next=0,p="$p" -q
1172
1173	bridge -d mdb show dev br0 vid 10 | grep ff0e::1 | \
1174		grep -q 2001:db8:1::2
1175	check_fail $? "Permanent entry affected by MLD packet"
1176
1177	# Replace the permanent entry with a temporary one and check that after
1178	# processing the MLD packet, a new source is added to the list along
1179	# with a new forwarding entry.
1180	bridge mdb replace dev br0 port $swp1 grp ff0e::1 temp vid 10 \
1181		filter_mode include source_list 2001:db8:1::1
1182
1183	# IS_IN ( 2001:db8:1::2 )
1184	$MZ -6 $h1.10 -c 1 -A fe80::1 -B ff0e::1 \
1185		-t ip hop=1,next=0,p="$p" -q
1186
1187	bridge -d mdb show dev br0 vid 10 | grep ff0e::1 | grep -v "src" | \
1188		grep -q 2001:db8:1::2
1189	check_err $? "Source not add to source list"
1190
1191	bridge -d mdb show dev br0 vid 10 | grep ff0e::1 | \
1192		grep -q "src 2001:db8:1::2"
1193	check_err $? "(S, G) entry not created for new source"
1194
1195	bridge mdb del dev br0 port $swp1 grp ff0e::1 vid 10
1196
1197	log_test "MLDv2 MODE_IS_INCLUDE tests"
1198}
1199
1200ctrl_test()
1201{
1202	echo
1203	log_info "# Control packets tests"
1204
1205	ctrl_igmpv3_is_in_test
1206	ctrl_mldv2_is_in_test
1207}
1208
1209trap cleanup EXIT
1210
1211setup_prepare
1212setup_wait
1213tests_run
1214
1215exit $EXIT_STATUS
1216