WIP FPC-III support
[linux/fpc-iii.git] / tools / testing / selftests / net / forwarding / bridge_igmp.sh
blob675eff45b03717007a8437695b7b5945d1f1467f
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
4 ALL_TESTS="v2reportleave_test v3include_test v3inc_allow_test v3inc_is_include_test \
5 v3inc_is_exclude_test v3inc_to_exclude_test v3exc_allow_test v3exc_is_include_test \
6 v3exc_is_exclude_test v3exc_to_exclude_test v3inc_block_test v3exc_block_test \
7 v3exc_timeout_test v3star_ex_auto_add_test"
8 NUM_NETIFS=4
9 CHECK_TC="yes"
10 TEST_GROUP="239.10.10.10"
11 TEST_GROUP_MAC="01:00:5e:0a:0a:0a"
13 ALL_GROUP="224.0.0.1"
14 ALL_MAC="01:00:5e:00:00:01"
16 # IGMPv3 is_in report: grp 239.10.10.10 is_include 192.0.2.1,192.0.2.2,192.0.2.3
17 MZPKT_IS_INC="22:00:9d:de:00:00:00:01:01:00:00:03:ef:0a:0a:0a:c0:00:02:01:c0:00:02:02:c0:00:02:03"
18 # IGMPv3 is_in report: grp 239.10.10.10 is_include 192.0.2.10,192.0.2.11,192.0.2.12
19 MZPKT_IS_INC2="22:00:9d:c3:00:00:00:01:01:00:00:03:ef:0a:0a:0a:c0:00:02:0a:c0:00:02:0b:c0:00:02:0c"
20 # IGMPv3 is_in report: grp 239.10.10.10 is_include 192.0.2.20,192.0.2.30
21 MZPKT_IS_INC3="22:00:5f:b4:00:00:00:01:01:00:00:02:ef:0a:0a:0a:c0:00:02:14:c0:00:02:1e"
22 # IGMPv3 allow report: grp 239.10.10.10 allow 192.0.2.10,192.0.2.11,192.0.2.12
23 MZPKT_ALLOW="22:00:99:c3:00:00:00:01:05:00:00:03:ef:0a:0a:0a:c0:00:02:0a:c0:00:02:0b:c0:00:02:0c"
24 # IGMPv3 allow report: grp 239.10.10.10 allow 192.0.2.20,192.0.2.30
25 MZPKT_ALLOW2="22:00:5b:b4:00:00:00:01:05:00:00:02:ef:0a:0a:0a:c0:00:02:14:c0:00:02:1e"
26 # IGMPv3 is_ex report: grp 239.10.10.10 is_exclude 192.0.2.1,192.0.2.2,192.0.2.20,192.0.2.21
27 MZPKT_IS_EXC="22:00:da:b6:00:00:00:01:02:00:00:04:ef:0a:0a:0a:c0:00:02:01:c0:00:02:02:c0:00:02:14:c0:00:02:15"
28 # IGMPv3 is_ex report: grp 239.10.10.10 is_exclude 192.0.2.20,192.0.2.30
29 MZPKT_IS_EXC2="22:00:5e:b4:00:00:00:01:02:00:00:02:ef:0a:0a:0a:c0:00:02:14:c0:00:02:1e"
30 # IGMPv3 to_ex report: grp 239.10.10.10 to_exclude 192.0.2.1,192.0.2.20,192.0.2.30
31 MZPKT_TO_EXC="22:00:9a:b1:00:00:00:01:04:00:00:03:ef:0a:0a:0a:c0:00:02:01:c0:00:02:14:c0:00:02:1e"
32 # IGMPv3 block report: grp 239.10.10.10 block 192.0.2.1,192.0.2.20,192.0.2.30
33 MZPKT_BLOCK="22:00:98:b1:00:00:00:01:06:00:00:03:ef:0a:0a:0a:c0:00:02:01:c0:00:02:14:c0:00:02:1e"
35 source lib.sh
37 h1_create()
39 simple_if_init $h1 192.0.2.1/24 2001:db8:1::1/64
42 h1_destroy()
44 simple_if_fini $h1 192.0.2.1/24 2001:db8:1::1/64
47 h2_create()
49 simple_if_init $h2 192.0.2.2/24 2001:db8:1::2/64
52 h2_destroy()
54 simple_if_fini $h2 192.0.2.2/24 2001:db8:1::2/64
57 switch_create()
59 ip link add dev br0 type bridge mcast_snooping 1 mcast_querier 1
61 ip link set dev $swp1 master br0
62 ip link set dev $swp2 master br0
64 ip link set dev br0 up
65 ip link set dev $swp1 up
66 ip link set dev $swp2 up
69 switch_destroy()
71 ip link set dev $swp2 down
72 ip link set dev $swp1 down
74 ip link del dev br0
77 setup_prepare()
79 h1=${NETIFS[p1]}
80 swp1=${NETIFS[p2]}
82 swp2=${NETIFS[p3]}
83 h2=${NETIFS[p4]}
85 vrf_prepare
87 h1_create
88 h2_create
90 switch_create
93 cleanup()
95 pre_cleanup
97 switch_destroy
99 # Always cleanup the mcast group
100 ip address del dev $h2 $TEST_GROUP/32 2>&1 1>/dev/null
102 h2_destroy
103 h1_destroy
105 vrf_cleanup
108 v2reportleave_test()
110 RET=0
111 ip address add dev $h2 $TEST_GROUP/32 autojoin
112 check_err $? "Could not join $TEST_GROUP"
114 sleep 5
115 bridge mdb show dev br0 | grep $TEST_GROUP 1>/dev/null
116 check_err $? "IGMPv2 report didn't create mdb entry for $TEST_GROUP"
118 mcast_packet_test $TEST_GROUP_MAC 192.0.2.1 $TEST_GROUP $h1 $h2
119 check_fail $? "Traffic to $TEST_GROUP wasn't forwarded"
121 log_test "IGMPv2 report $TEST_GROUP"
123 RET=0
124 bridge mdb show dev br0 | grep $TEST_GROUP 1>/dev/null
125 check_err $? "mdb entry for $TEST_GROUP is missing"
127 ip address del dev $h2 $TEST_GROUP/32
128 check_err $? "Could not leave $TEST_GROUP"
130 sleep 5
131 bridge mdb show dev br0 | grep $TEST_GROUP 1>/dev/null
132 check_fail $? "Leave didn't delete mdb entry for $TEST_GROUP"
134 mcast_packet_test $TEST_GROUP_MAC 192.0.2.1 $TEST_GROUP $h1 $h2
135 check_err $? "Traffic to $TEST_GROUP was forwarded without mdb entry"
137 log_test "IGMPv2 leave $TEST_GROUP"
140 v3include_prepare()
142 local host1_if=$1
143 local mac=$2
144 local group=$3
145 local X=("192.0.2.1" "192.0.2.2" "192.0.2.3")
147 ip link set dev br0 type bridge mcast_igmp_version 3
148 check_err $? "Could not change bridge IGMP version to 3"
150 $MZ $host1_if -b $mac -c 1 -B $group -t ip "proto=2,p=$MZPKT_IS_INC" -q
151 sleep 1
152 bridge -j -d -s mdb show dev br0 \
153 | jq -e ".[].mdb[] | \
154 select(.grp == \"$TEST_GROUP\" and .source_list != null)" &>/dev/null
155 check_err $? "Missing *,G entry with source list"
156 bridge -j -d -s mdb show dev br0 \
157 | jq -e ".[].mdb[] | \
158 select(.grp == \"$TEST_GROUP\" and \
159 .source_list != null and .filter_mode == \"include\")" &>/dev/null
160 check_err $? "Wrong *,G entry filter mode"
161 brmcast_check_sg_entries "is_include" "${X[@]}"
164 v3exclude_prepare()
166 local host1_if=$1
167 local mac=$2
168 local group=$3
169 local pkt=$4
170 local X=("192.0.2.1" "192.0.2.2")
171 local Y=("192.0.2.20" "192.0.2.21")
173 v3include_prepare $host1_if $mac $group
175 $MZ $host1_if -c 1 -b $mac -B $group -t ip "proto=2,p=$MZPKT_IS_EXC" -q
176 sleep 1
177 bridge -j -d -s mdb show dev br0 \
178 | jq -e ".[].mdb[] | \
179 select(.grp == \"$TEST_GROUP\" and \
180 .source_list != null and .filter_mode == \"exclude\")" &>/dev/null
181 check_err $? "Wrong *,G entry filter mode"
183 brmcast_check_sg_entries "is_exclude" "${X[@]}" "${Y[@]}"
185 brmcast_check_sg_state 0 "${X[@]}"
186 brmcast_check_sg_state 1 "${Y[@]}"
188 bridge -j -d -s mdb show dev br0 \
189 | jq -e ".[].mdb[] | \
190 select(.grp == \"$TEST_GROUP\" and \
191 .source_list != null and
192 .source_list[].address == \"192.0.2.3\")" &>/dev/null
193 check_fail $? "Wrong *,G entry source list, 192.0.2.3 entry still exists"
196 v3cleanup()
198 local port=$1
199 local group=$2
201 bridge mdb del dev br0 port $port grp $group
202 ip link set dev br0 type bridge mcast_igmp_version 2
205 v3include_test()
207 RET=0
208 local X=("192.0.2.1" "192.0.2.2" "192.0.2.3")
210 v3include_prepare $h1 $ALL_MAC $ALL_GROUP
212 brmcast_check_sg_state 0 "${X[@]}"
214 brmcast_check_sg_fwding 1 "${X[@]}"
215 brmcast_check_sg_fwding 0 "192.0.2.100"
217 log_test "IGMPv3 report $TEST_GROUP is_include"
219 v3cleanup $swp1 $TEST_GROUP
222 v3inc_allow_test()
224 RET=0
225 local X=("192.0.2.10" "192.0.2.11" "192.0.2.12")
227 v3include_prepare $h1 $ALL_MAC $ALL_GROUP
229 $MZ $h1 -c 1 -b $ALL_MAC -B $ALL_GROUP -t ip "proto=2,p=$MZPKT_ALLOW" -q
230 sleep 1
231 brmcast_check_sg_entries "allow" "${X[@]}"
233 brmcast_check_sg_state 0 "${X[@]}"
235 brmcast_check_sg_fwding 1 "${X[@]}"
236 brmcast_check_sg_fwding 0 "192.0.2.100"
238 log_test "IGMPv3 report $TEST_GROUP include -> allow"
240 v3cleanup $swp1 $TEST_GROUP
243 v3inc_is_include_test()
245 RET=0
246 local X=("192.0.2.10" "192.0.2.11" "192.0.2.12")
248 v3include_prepare $h1 $ALL_MAC $ALL_GROUP
250 $MZ $h1 -c 1 -b $ALL_MAC -B $ALL_GROUP -t ip "proto=2,p=$MZPKT_IS_INC2" -q
251 sleep 1
252 brmcast_check_sg_entries "is_include" "${X[@]}"
254 brmcast_check_sg_state 0 "${X[@]}"
256 brmcast_check_sg_fwding 1 "${X[@]}"
257 brmcast_check_sg_fwding 0 "192.0.2.100"
259 log_test "IGMPv3 report $TEST_GROUP include -> is_include"
261 v3cleanup $swp1 $TEST_GROUP
264 v3inc_is_exclude_test()
266 RET=0
268 v3exclude_prepare $h1 $ALL_MAC $ALL_GROUP
270 brmcast_check_sg_fwding 1 "${X[@]}" 192.0.2.100
271 brmcast_check_sg_fwding 0 "${Y[@]}"
273 log_test "IGMPv3 report $TEST_GROUP include -> is_exclude"
275 v3cleanup $swp1 $TEST_GROUP
278 v3inc_to_exclude_test()
280 RET=0
281 local X=("192.0.2.1")
282 local Y=("192.0.2.20" "192.0.2.30")
284 v3include_prepare $h1 $ALL_MAC $ALL_GROUP
286 ip link set dev br0 type bridge mcast_last_member_interval 500
287 check_err $? "Could not change mcast_last_member_interval to 5s"
289 $MZ $h1 -c 1 -b $ALL_MAC -B $ALL_GROUP -t ip "proto=2,p=$MZPKT_TO_EXC" -q
290 sleep 1
291 bridge -j -d -s mdb show dev br0 \
292 | jq -e ".[].mdb[] | \
293 select(.grp == \"$TEST_GROUP\" and \
294 .source_list != null and .filter_mode == \"exclude\")" &>/dev/null
295 check_err $? "Wrong *,G entry filter mode"
297 brmcast_check_sg_entries "to_exclude" "${X[@]}" "${Y[@]}"
299 brmcast_check_sg_state 0 "${X[@]}"
300 brmcast_check_sg_state 1 "${Y[@]}"
302 bridge -j -d -s mdb show dev br0 \
303 | jq -e ".[].mdb[] | \
304 select(.grp == \"$TEST_GROUP\" and \
305 .source_list != null and
306 .source_list[].address == \"192.0.2.2\")" &>/dev/null
307 check_fail $? "Wrong *,G entry source list, 192.0.2.2 entry still exists"
308 bridge -j -d -s mdb show dev br0 \
309 | jq -e ".[].mdb[] | \
310 select(.grp == \"$TEST_GROUP\" and \
311 .source_list != null and
312 .source_list[].address == \"192.0.2.21\")" &>/dev/null
313 check_fail $? "Wrong *,G entry source list, 192.0.2.21 entry still exists"
315 brmcast_check_sg_fwding 1 "${X[@]}" 192.0.2.100
316 brmcast_check_sg_fwding 0 "${Y[@]}"
318 log_test "IGMPv3 report $TEST_GROUP include -> to_exclude"
320 ip link set dev br0 type bridge mcast_last_member_interval 100
322 v3cleanup $swp1 $TEST_GROUP
325 v3exc_allow_test()
327 RET=0
328 local X=("192.0.2.1" "192.0.2.2" "192.0.2.20" "192.0.2.30")
329 local Y=("192.0.2.21")
331 v3exclude_prepare $h1 $ALL_MAC $ALL_GROUP
333 $MZ $h1 -c 1 -b $ALL_MAC -B $ALL_GROUP -t ip "proto=2,p=$MZPKT_ALLOW2" -q
334 sleep 1
335 brmcast_check_sg_entries "allow" "${X[@]}" "${Y[@]}"
337 brmcast_check_sg_state 0 "${X[@]}"
338 brmcast_check_sg_state 1 "${Y[@]}"
340 brmcast_check_sg_fwding 1 "${X[@]}" 192.0.2.100
341 brmcast_check_sg_fwding 0 "${Y[@]}"
343 log_test "IGMPv3 report $TEST_GROUP exclude -> allow"
345 v3cleanup $swp1 $TEST_GROUP
348 v3exc_is_include_test()
350 RET=0
351 local X=("192.0.2.1" "192.0.2.2" "192.0.2.20" "192.0.2.30")
352 local Y=("192.0.2.21")
354 v3exclude_prepare $h1 $ALL_MAC $ALL_GROUP
356 $MZ $h1 -c 1 -b $ALL_MAC -B $ALL_GROUP -t ip "proto=2,p=$MZPKT_IS_INC3" -q
357 sleep 1
358 brmcast_check_sg_entries "is_include" "${X[@]}" "${Y[@]}"
360 brmcast_check_sg_state 0 "${X[@]}"
361 brmcast_check_sg_state 1 "${Y[@]}"
363 brmcast_check_sg_fwding 1 "${X[@]}" 192.0.2.100
364 brmcast_check_sg_fwding 0 "${Y[@]}"
366 log_test "IGMPv3 report $TEST_GROUP exclude -> is_include"
368 v3cleanup $swp1 $TEST_GROUP
371 v3exc_is_exclude_test()
373 RET=0
374 local X=("192.0.2.30")
375 local Y=("192.0.2.20")
377 v3exclude_prepare $h1 $ALL_MAC $ALL_GROUP
379 $MZ $h1 -c 1 -b $ALL_MAC -B $ALL_GROUP -t ip "proto=2,p=$MZPKT_IS_EXC2" -q
380 sleep 1
381 brmcast_check_sg_entries "is_exclude" "${X[@]}" "${Y[@]}"
383 brmcast_check_sg_state 0 "${X[@]}"
384 brmcast_check_sg_state 1 "${Y[@]}"
386 brmcast_check_sg_fwding 1 "${X[@]}" 192.0.2.100
387 brmcast_check_sg_fwding 0 "${Y[@]}"
389 log_test "IGMPv3 report $TEST_GROUP exclude -> is_exclude"
391 v3cleanup $swp1 $TEST_GROUP
394 v3exc_to_exclude_test()
396 RET=0
397 local X=("192.0.2.1" "192.0.2.30")
398 local Y=("192.0.2.20")
400 v3exclude_prepare $h1 $ALL_MAC $ALL_GROUP
402 ip link set dev br0 type bridge mcast_last_member_interval 500
403 check_err $? "Could not change mcast_last_member_interval to 5s"
405 $MZ $h1 -c 1 -b $ALL_MAC -B $ALL_GROUP -t ip "proto=2,p=$MZPKT_TO_EXC" -q
406 sleep 1
407 brmcast_check_sg_entries "to_exclude" "${X[@]}" "${Y[@]}"
409 brmcast_check_sg_state 0 "${X[@]}"
410 brmcast_check_sg_state 1 "${Y[@]}"
412 brmcast_check_sg_fwding 1 "${X[@]}" 192.0.2.100
413 brmcast_check_sg_fwding 0 "${Y[@]}"
415 log_test "IGMPv3 report $TEST_GROUP exclude -> to_exclude"
417 ip link set dev br0 type bridge mcast_last_member_interval 100
419 v3cleanup $swp1 $TEST_GROUP
422 v3inc_block_test()
424 RET=0
425 local X=("192.0.2.2" "192.0.2.3")
427 v3include_prepare $h1 $ALL_MAC $ALL_GROUP
429 $MZ $h1 -c 1 -b $ALL_MAC -B $ALL_GROUP -t ip "proto=2,p=$MZPKT_BLOCK" -q
430 # make sure the lowered timers have expired (by default 2 seconds)
431 sleep 3
432 brmcast_check_sg_entries "block" "${X[@]}"
434 brmcast_check_sg_state 0 "${X[@]}"
436 bridge -j -d -s mdb show dev br0 \
437 | jq -e ".[].mdb[] | \
438 select(.grp == \"$TEST_GROUP\" and \
439 .source_list != null and
440 .source_list[].address == \"192.0.2.1\")" &>/dev/null
441 check_fail $? "Wrong *,G entry source list, 192.0.2.1 entry still exists"
443 brmcast_check_sg_fwding 1 "${X[@]}"
444 brmcast_check_sg_fwding 0 "192.0.2.100"
446 log_test "IGMPv3 report $TEST_GROUP include -> block"
448 v3cleanup $swp1 $TEST_GROUP
451 v3exc_block_test()
453 RET=0
454 local X=("192.0.2.1" "192.0.2.2" "192.0.2.30")
455 local Y=("192.0.2.20" "192.0.2.21")
457 v3exclude_prepare $h1 $ALL_MAC $ALL_GROUP
459 ip link set dev br0 type bridge mcast_last_member_interval 500
460 check_err $? "Could not change mcast_last_member_interval to 5s"
462 $MZ $h1 -c 1 -b $ALL_MAC -B $ALL_GROUP -t ip "proto=2,p=$MZPKT_BLOCK" -q
463 sleep 1
464 brmcast_check_sg_entries "block" "${X[@]}" "${Y[@]}"
466 brmcast_check_sg_state 0 "${X[@]}"
467 brmcast_check_sg_state 1 "${Y[@]}"
469 brmcast_check_sg_fwding 1 "${X[@]}" 192.0.2.100
470 brmcast_check_sg_fwding 0 "${Y[@]}"
472 log_test "IGMPv3 report $TEST_GROUP exclude -> block"
474 ip link set dev br0 type bridge mcast_last_member_interval 100
476 v3cleanup $swp1 $TEST_GROUP
479 v3exc_timeout_test()
481 RET=0
482 local X=("192.0.2.20" "192.0.2.30")
484 # GMI should be 3 seconds
485 ip link set dev br0 type bridge mcast_query_interval 100 mcast_query_response_interval 100
487 v3exclude_prepare $h1 $ALL_MAC $ALL_GROUP
488 ip link set dev br0 type bridge mcast_query_interval 500 mcast_query_response_interval 500
489 $MZ $h1 -c 1 -b $ALL_MAC -B $ALL_GROUP -t ip "proto=2,p=$MZPKT_ALLOW2" -q
490 sleep 3
491 bridge -j -d -s mdb show dev br0 \
492 | jq -e ".[].mdb[] | \
493 select(.grp == \"$TEST_GROUP\" and \
494 .source_list != null and .filter_mode == \"include\")" &>/dev/null
495 check_err $? "Wrong *,G entry filter mode"
497 bridge -j -d -s mdb show dev br0 \
498 | jq -e ".[].mdb[] | \
499 select(.grp == \"$TEST_GROUP\" and \
500 .source_list != null and
501 .source_list[].address == \"192.0.2.1\")" &>/dev/null
502 check_fail $? "Wrong *,G entry source list, 192.0.2.1 entry still exists"
503 bridge -j -d -s mdb show dev br0 \
504 | jq -e ".[].mdb[] | \
505 select(.grp == \"$TEST_GROUP\" and \
506 .source_list != null and
507 .source_list[].address == \"192.0.2.2\")" &>/dev/null
508 check_fail $? "Wrong *,G entry source list, 192.0.2.2 entry still exists"
510 brmcast_check_sg_entries "allow" "${X[@]}"
512 brmcast_check_sg_state 0 "${X[@]}"
514 brmcast_check_sg_fwding 1 "${X[@]}"
515 brmcast_check_sg_fwding 0 192.0.2.100
517 log_test "IGMPv3 group $TEST_GROUP exclude timeout"
519 ip link set dev br0 type bridge mcast_query_interval 12500 \
520 mcast_query_response_interval 1000
522 v3cleanup $swp1 $TEST_GROUP
525 v3star_ex_auto_add_test()
527 RET=0
529 v3exclude_prepare $h1 $ALL_MAC $ALL_GROUP
531 $MZ $h2 -c 1 -b $ALL_MAC -B $ALL_GROUP -t ip "proto=2,p=$MZPKT_IS_INC" -q
532 sleep 1
533 bridge -j -d -s mdb show dev br0 \
534 | jq -e ".[].mdb[] | \
535 select(.grp == \"$TEST_GROUP\" and .src == \"192.0.2.3\" and \
536 .port == \"$swp1\")" &>/dev/null
537 check_err $? "S,G entry for *,G port doesn't exist"
539 bridge -j -d -s mdb show dev br0 \
540 | jq -e ".[].mdb[] | \
541 select(.grp == \"$TEST_GROUP\" and .src == \"192.0.2.3\" and \
542 .port == \"$swp1\" and \
543 .flags[] == \"added_by_star_ex\")" &>/dev/null
544 check_err $? "Auto-added S,G entry doesn't have added_by_star_ex flag"
546 brmcast_check_sg_fwding 1 192.0.2.3
548 log_test "IGMPv3 S,G port entry automatic add to a *,G port"
550 v3cleanup $swp1 $TEST_GROUP
551 v3cleanup $swp2 $TEST_GROUP
554 trap cleanup EXIT
556 setup_prepare
557 setup_wait
559 tests_run
561 exit $EXIT_STATUS