Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / tools / testing / selftests / net / forwarding / bridge_mdb_max.sh
blob3da9d93ab36fb9b6cea1160a9889ee4869f84623
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
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 # +---------------------------------------------------------------------------+
27 ALL_TESTS="
28 test_8021d
29 test_8021q
30 test_8021qvs
33 NUM_NETIFS=4
34 source lib.sh
35 source tc_common.sh
37 h1_create()
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
44 h1_destroy()
46 vlan_destroy $h1 20
47 vlan_destroy $h1 10
48 simple_if_fini $h1
51 h2_create()
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
58 h2_destroy()
60 vlan_destroy $h2 20
61 vlan_destroy $h2 10
62 simple_if_fini $h2
65 switch_create_8021d()
67 log_info "802.1d tests"
69 ip link add name br0 type bridge vlan_filtering 0 \
70 mcast_snooping 1 \
71 mcast_igmp_version 3 mcast_mld_version 2
72 ip link set dev br0 up
74 ip link set dev $swp1 master br0
75 ip link set dev $swp1 up
76 bridge link set dev $swp1 fastleave on
78 ip link set dev $swp2 master br0
79 ip link set dev $swp2 up
82 switch_create_8021q()
84 local br_flags=$1; shift
86 log_info "802.1q $br_flags${br_flags:+ }tests"
88 ip link add name br0 type bridge vlan_filtering 1 vlan_default_pvid 0 \
89 mcast_snooping 1 $br_flags \
90 mcast_igmp_version 3 mcast_mld_version 2
91 bridge vlan add vid 10 dev br0 self
92 bridge vlan add vid 20 dev br0 self
93 ip link set dev br0 up
95 ip link set dev $swp1 master br0
96 ip link set dev $swp1 up
97 bridge link set dev $swp1 fastleave on
98 bridge vlan add vid 10 dev $swp1
99 bridge vlan add vid 20 dev $swp1
101 ip link set dev $swp2 master br0
102 ip link set dev $swp2 up
103 bridge vlan add vid 10 dev $swp2
104 bridge vlan add vid 20 dev $swp2
107 switch_create_8021qvs()
109 switch_create_8021q "mcast_vlan_snooping 1"
110 bridge vlan global set dev br0 vid 10 mcast_igmp_version 3
111 bridge vlan global set dev br0 vid 10 mcast_mld_version 2
112 bridge vlan global set dev br0 vid 20 mcast_igmp_version 3
113 bridge vlan global set dev br0 vid 20 mcast_mld_version 2
116 switch_destroy()
118 ip link set dev $swp2 down
119 ip link set dev $swp2 nomaster
121 ip link set dev $swp1 down
122 ip link set dev $swp1 nomaster
124 ip link set dev br0 down
125 ip link del dev br0
128 setup_prepare()
130 h1=${NETIFS[p1]}
131 swp1=${NETIFS[p2]}
133 swp2=${NETIFS[p3]}
134 h2=${NETIFS[p4]}
136 vrf_prepare
137 forwarding_enable
139 h1_create
140 h2_create
143 cleanup()
145 pre_cleanup
147 switch_destroy 2>/dev/null
148 h2_destroy
149 h1_destroy
151 forwarding_restore
152 vrf_cleanup
155 cfg_src_list()
157 local IPs=("$@")
158 local IPstr=$(echo ${IPs[@]} | tr '[:space:]' , | sed 's/,$//')
160 echo ${IPstr:+source_list }${IPstr}
163 cfg_group_op()
165 local op=$1; shift
166 local locus=$1; shift
167 local GRP=$1; shift
168 local state=$1; shift
169 local IPs=("$@")
171 local source_list=$(cfg_src_list ${IPs[@]})
173 # Everything besides `bridge mdb' uses the "dev X vid Y" syntax,
174 # so we use it here as well and convert.
175 local br_locus=$(echo "$locus" | sed 's/^dev /port /')
177 bridge mdb $op dev br0 $br_locus grp $GRP $state \
178 filter_mode include $source_list
181 cfg4_entries_op()
183 local op=$1; shift
184 local locus=$1; shift
185 local state=$1; shift
186 local n=$1; shift
187 local grp=${1:-1}; shift
189 local GRP=239.1.1.${grp}
190 local IPs=$(seq -f 192.0.2.%g 1 $((n - 1)))
191 cfg_group_op "$op" "$locus" "$GRP" "$state" ${IPs[@]}
194 cfg4_entries_add()
196 cfg4_entries_op add "$@"
199 cfg4_entries_del()
201 cfg4_entries_op del "$@"
204 cfg6_entries_op()
206 local op=$1; shift
207 local locus=$1; shift
208 local state=$1; shift
209 local n=$1; shift
210 local grp=${1:-1}; shift
212 local GRP=ff0e::${grp}
213 local IPs=$(printf "2001:db8:1::%x\n" $(seq 1 $((n - 1))))
214 cfg_group_op "$op" "$locus" "$GRP" "$state" ${IPs[@]}
217 cfg6_entries_add()
219 cfg6_entries_op add "$@"
222 cfg6_entries_del()
224 cfg6_entries_op del "$@"
227 locus_dev_peer()
229 local dev_kw=$1; shift
230 local dev=$1; shift
231 local vid_kw=$1; shift
232 local vid=$1; shift
234 echo "$h1.${vid:-10}"
237 locus_dev()
239 local dev_kw=$1; shift
240 local dev=$1; shift
242 echo $dev
245 ctl4_entries_add()
247 local locus=$1; shift
248 local state=$1; shift
249 local n=$1; shift
250 local grp=${1:-1}; shift
252 local IPs=$(seq -f 192.0.2.%g 1 $((n - 1)))
253 local peer=$(locus_dev_peer $locus)
254 local GRP=239.1.1.${grp}
255 local dmac=01:00:5e:01:01:$(printf "%02x" $grp)
256 $MZ $peer -a own -b $dmac -c 1 -A 192.0.2.1 -B $GRP \
257 -t ip proto=2,p=$(igmpv3_is_in_get $GRP $IPs) -q
258 sleep 1
260 local nn=$(bridge mdb show dev br0 | grep $GRP | wc -l)
261 if ((nn != n)); then
262 echo mcast_max_groups > /dev/stderr
263 false
267 ctl4_entries_del()
269 local locus=$1; shift
270 local state=$1; shift
271 local n=$1; shift
272 local grp=${1:-1}; shift
274 local peer=$(locus_dev_peer $locus)
275 local GRP=239.1.1.${grp}
276 local dmac=01:00:5e:00:00:02
277 $MZ $peer -a own -b $dmac -c 1 -A 192.0.2.1 -B 224.0.0.2 \
278 -t ip proto=2,p=$(igmpv2_leave_get $GRP) -q
279 sleep 1
280 ! bridge mdb show dev br0 | grep -q $GRP
283 ctl6_entries_add()
285 local locus=$1; shift
286 local state=$1; shift
287 local n=$1; shift
288 local grp=${1:-1}; shift
290 local IPs=$(printf "2001:db8:1::%x\n" $(seq 1 $((n - 1))))
291 local peer=$(locus_dev_peer $locus)
292 local SIP=fe80::1
293 local GRP=ff0e::${grp}
294 local dmac=33:33:00:00:00:$(printf "%02x" $grp)
295 local p=$(mldv2_is_in_get $SIP $GRP $IPs)
296 $MZ -6 $peer -a own -b $dmac -c 1 -A $SIP -B $GRP \
297 -t ip hop=1,next=0,p="$p" -q
298 sleep 1
300 local nn=$(bridge mdb show dev br0 | grep $GRP | wc -l)
301 if ((nn != n)); then
302 echo mcast_max_groups > /dev/stderr
303 false
307 ctl6_entries_del()
309 local locus=$1; shift
310 local state=$1; shift
311 local n=$1; shift
312 local grp=${1:-1}; shift
314 local peer=$(locus_dev_peer $locus)
315 local SIP=fe80::1
316 local GRP=ff0e::${grp}
317 local dmac=33:33:00:00:00:$(printf "%02x" $grp)
318 local p=$(mldv1_done_get $SIP $GRP)
319 $MZ -6 $peer -a own -b $dmac -c 1 -A $SIP -B $GRP \
320 -t ip hop=1,next=0,p="$p" -q
321 sleep 1
322 ! bridge mdb show dev br0 | grep -q $GRP
325 bridge_maxgroups_errmsg_check_cfg()
327 local msg=$1; shift
328 local needle=$1; shift
330 echo "$msg" | grep -q mcast_max_groups
331 check_err $? "Adding MDB entries failed for the wrong reason: $msg"
334 bridge_maxgroups_errmsg_check_cfg4()
336 bridge_maxgroups_errmsg_check_cfg "$@"
339 bridge_maxgroups_errmsg_check_cfg6()
341 bridge_maxgroups_errmsg_check_cfg "$@"
344 bridge_maxgroups_errmsg_check_ctl4()
349 bridge_maxgroups_errmsg_check_ctl6()
354 bridge_port_ngroups_get()
356 local locus=$1; shift
358 bridge -j -d link show $locus |
359 jq '.[].mcast_n_groups'
362 bridge_port_maxgroups_get()
364 local locus=$1; shift
366 bridge -j -d link show $locus |
367 jq '.[].mcast_max_groups'
370 bridge_port_maxgroups_set()
372 local locus=$1; shift
373 local max=$1; shift
375 bridge link set dev $(locus_dev $locus) mcast_max_groups $max
378 bridge_port_vlan_ngroups_get()
380 local locus=$1; shift
382 bridge -j -d vlan show $locus |
383 jq '.[].vlans[].mcast_n_groups'
386 bridge_port_vlan_maxgroups_get()
388 local locus=$1; shift
390 bridge -j -d vlan show $locus |
391 jq '.[].vlans[].mcast_max_groups'
394 bridge_port_vlan_maxgroups_set()
396 local locus=$1; shift
397 local max=$1; shift
399 bridge vlan set $locus mcast_max_groups $max
402 test_ngroups_reporting()
404 local CFG=$1; shift
405 local context=$1; shift
406 local locus=$1; shift
408 RET=0
410 local n0=$(bridge_${context}_ngroups_get "$locus")
411 ${CFG}_entries_add "$locus" temp 5
412 check_err $? "Couldn't add MDB entries"
413 local n1=$(bridge_${context}_ngroups_get "$locus")
415 ((n1 == n0 + 5))
416 check_err $? "Number of groups was $n0, now is $n1, but $((n0 + 5)) expected"
418 ${CFG}_entries_del "$locus" temp 5
419 check_err $? "Couldn't delete MDB entries"
420 local n2=$(bridge_${context}_ngroups_get "$locus")
422 ((n2 == n0))
423 check_err $? "Number of groups was $n0, now is $n2, but should be back to $n0"
425 log_test "$CFG: $context: ngroups reporting"
428 test_8021d_ngroups_reporting_cfg4()
430 test_ngroups_reporting cfg4 port "dev $swp1"
433 test_8021d_ngroups_reporting_ctl4()
435 test_ngroups_reporting ctl4 port "dev $swp1"
438 test_8021d_ngroups_reporting_cfg6()
440 test_ngroups_reporting cfg6 port "dev $swp1"
443 test_8021d_ngroups_reporting_ctl6()
445 test_ngroups_reporting ctl6 port "dev $swp1"
448 test_8021q_ngroups_reporting_cfg4()
450 test_ngroups_reporting cfg4 port "dev $swp1 vid 10"
453 test_8021q_ngroups_reporting_ctl4()
455 test_ngroups_reporting ctl4 port "dev $swp1 vid 10"
458 test_8021q_ngroups_reporting_cfg6()
460 test_ngroups_reporting cfg6 port "dev $swp1 vid 10"
463 test_8021q_ngroups_reporting_ctl6()
465 test_ngroups_reporting ctl6 port "dev $swp1 vid 10"
468 test_8021qvs_ngroups_reporting_cfg4()
470 test_ngroups_reporting cfg4 port_vlan "dev $swp1 vid 10"
473 test_8021qvs_ngroups_reporting_ctl4()
475 test_ngroups_reporting ctl4 port_vlan "dev $swp1 vid 10"
478 test_8021qvs_ngroups_reporting_cfg6()
480 test_ngroups_reporting cfg6 port_vlan "dev $swp1 vid 10"
483 test_8021qvs_ngroups_reporting_ctl6()
485 test_ngroups_reporting ctl6 port_vlan "dev $swp1 vid 10"
488 test_ngroups_cross_vlan()
490 local CFG=$1; shift
492 local locus1="dev $swp1 vid 10"
493 local locus2="dev $swp1 vid 20"
495 RET=0
497 local n10=$(bridge_port_vlan_ngroups_get "$locus1")
498 local n20=$(bridge_port_vlan_ngroups_get "$locus2")
499 ${CFG}_entries_add "$locus1" temp 5 111
500 check_err $? "Couldn't add MDB entries to VLAN 10"
501 local n11=$(bridge_port_vlan_ngroups_get "$locus1")
502 local n21=$(bridge_port_vlan_ngroups_get "$locus2")
504 ((n11 == n10 + 5))
505 check_err $? "Number of groups at VLAN 10 was $n10, now is $n11, but 5 entries added on VLAN 10, $((n10 + 5)) expected"
507 ((n21 == n20))
508 check_err $? "Number of groups at VLAN 20 was $n20, now is $n21, but no change expected on VLAN 20"
510 ${CFG}_entries_add "$locus2" temp 5 112
511 check_err $? "Couldn't add MDB entries to VLAN 20"
512 local n12=$(bridge_port_vlan_ngroups_get "$locus1")
513 local n22=$(bridge_port_vlan_ngroups_get "$locus2")
515 ((n12 == n11))
516 check_err $? "Number of groups at VLAN 10 was $n11, now is $n12, but no change expected on VLAN 10"
518 ((n22 == n21 + 5))
519 check_err $? "Number of groups at VLAN 20 was $n21, now is $n22, but 5 entries added on VLAN 20, $((n21 + 5)) expected"
521 ${CFG}_entries_del "$locus1" temp 5 111
522 check_err $? "Couldn't delete MDB entries from VLAN 10"
523 ${CFG}_entries_del "$locus2" temp 5 112
524 check_err $? "Couldn't delete MDB entries from VLAN 20"
525 local n13=$(bridge_port_vlan_ngroups_get "$locus1")
526 local n23=$(bridge_port_vlan_ngroups_get "$locus2")
528 ((n13 == n10))
529 check_err $? "Number of groups at VLAN 10 was $n10, now is $n13, but should be back to $n10"
531 ((n23 == n20))
532 check_err $? "Number of groups at VLAN 20 was $n20, now is $n23, but should be back to $n20"
534 log_test "$CFG: port_vlan: isolation of port and per-VLAN ngroups"
537 test_8021qvs_ngroups_cross_vlan_cfg4()
539 test_ngroups_cross_vlan cfg4
542 test_8021qvs_ngroups_cross_vlan_ctl4()
544 test_ngroups_cross_vlan ctl4
547 test_8021qvs_ngroups_cross_vlan_cfg6()
549 test_ngroups_cross_vlan cfg6
552 test_8021qvs_ngroups_cross_vlan_ctl6()
554 test_ngroups_cross_vlan ctl6
557 test_maxgroups_zero()
559 local CFG=$1; shift
560 local context=$1; shift
561 local locus=$1; shift
563 RET=0
564 local max
566 max=$(bridge_${context}_maxgroups_get "$locus")
567 ((max == 0))
568 check_err $? "Max groups on $locus should be 0, but $max reported"
570 bridge_${context}_maxgroups_set "$locus" 100
571 check_err $? "Failed to set max to 100"
572 max=$(bridge_${context}_maxgroups_get "$locus")
573 ((max == 100))
574 check_err $? "Max groups expected to be 100, but $max reported"
576 bridge_${context}_maxgroups_set "$locus" 0
577 check_err $? "Couldn't set maximum to 0"
579 # Test that setting 0 explicitly still serves as infinity.
580 ${CFG}_entries_add "$locus" temp 5
581 check_err $? "Adding 5 MDB entries failed but should have passed"
582 ${CFG}_entries_del "$locus" temp 5
583 check_err $? "Couldn't delete MDB entries"
585 log_test "$CFG: $context maxgroups: reporting and treatment of 0"
588 test_8021d_maxgroups_zero_cfg4()
590 test_maxgroups_zero cfg4 port "dev $swp1"
593 test_8021d_maxgroups_zero_ctl4()
595 test_maxgroups_zero ctl4 port "dev $swp1"
598 test_8021d_maxgroups_zero_cfg6()
600 test_maxgroups_zero cfg6 port "dev $swp1"
603 test_8021d_maxgroups_zero_ctl6()
605 test_maxgroups_zero ctl6 port "dev $swp1"
608 test_8021q_maxgroups_zero_cfg4()
610 test_maxgroups_zero cfg4 port "dev $swp1 vid 10"
613 test_8021q_maxgroups_zero_ctl4()
615 test_maxgroups_zero ctl4 port "dev $swp1 vid 10"
618 test_8021q_maxgroups_zero_cfg6()
620 test_maxgroups_zero cfg6 port "dev $swp1 vid 10"
623 test_8021q_maxgroups_zero_ctl6()
625 test_maxgroups_zero ctl6 port "dev $swp1 vid 10"
628 test_8021qvs_maxgroups_zero_cfg4()
630 test_maxgroups_zero cfg4 port_vlan "dev $swp1 vid 10"
633 test_8021qvs_maxgroups_zero_ctl4()
635 test_maxgroups_zero ctl4 port_vlan "dev $swp1 vid 10"
638 test_8021qvs_maxgroups_zero_cfg6()
640 test_maxgroups_zero cfg6 port_vlan "dev $swp1 vid 10"
643 test_8021qvs_maxgroups_zero_ctl6()
645 test_maxgroups_zero ctl6 port_vlan "dev $swp1 vid 10"
648 test_maxgroups_zero_cross_vlan()
650 local CFG=$1; shift
652 local locus0="dev $swp1"
653 local locus1="dev $swp1 vid 10"
654 local locus2="dev $swp1 vid 20"
655 local max
657 RET=0
659 bridge_port_vlan_maxgroups_set "$locus1" 100
660 check_err $? "$locus1: Failed to set max to 100"
662 max=$(bridge_port_maxgroups_get "$locus0")
663 ((max == 0))
664 check_err $? "$locus0: Max groups expected to be 0, but $max reported"
666 max=$(bridge_port_vlan_maxgroups_get "$locus2")
667 ((max == 0))
668 check_err $? "$locus2: Max groups expected to be 0, but $max reported"
670 bridge_port_vlan_maxgroups_set "$locus2" 100
671 check_err $? "$locus2: Failed to set max to 100"
673 max=$(bridge_port_maxgroups_get "$locus0")
674 ((max == 0))
675 check_err $? "$locus0: Max groups expected to be 0, but $max reported"
677 max=$(bridge_port_vlan_maxgroups_get "$locus2")
678 ((max == 100))
679 check_err $? "$locus2: Max groups expected to be 100, but $max reported"
681 bridge_port_maxgroups_set "$locus0" 100
682 check_err $? "$locus0: Failed to set max to 100"
684 max=$(bridge_port_maxgroups_get "$locus0")
685 ((max == 100))
686 check_err $? "$locus0: Max groups expected to be 100, but $max reported"
688 max=$(bridge_port_vlan_maxgroups_get "$locus2")
689 ((max == 100))
690 check_err $? "$locus2: Max groups expected to be 100, but $max reported"
692 bridge_port_vlan_maxgroups_set "$locus1" 0
693 check_err $? "$locus1: Failed to set max to 0"
695 max=$(bridge_port_maxgroups_get "$locus0")
696 ((max == 100))
697 check_err $? "$locus0: Max groups expected to be 100, but $max reported"
699 max=$(bridge_port_vlan_maxgroups_get "$locus2")
700 ((max == 100))
701 check_err $? "$locus2: Max groups expected to be 100, but $max reported"
703 bridge_port_vlan_maxgroups_set "$locus2" 0
704 check_err $? "$locus2: Failed to set max to 0"
706 max=$(bridge_port_maxgroups_get "$locus0")
707 ((max == 100))
708 check_err $? "$locus0: Max groups expected to be 100, but $max reported"
710 max=$(bridge_port_vlan_maxgroups_get "$locus2")
711 ((max == 0))
712 check_err $? "$locus2: Max groups expected to be 0 but $max reported"
714 bridge_port_maxgroups_set "$locus0" 0
715 check_err $? "$locus0: Failed to set max to 0"
717 max=$(bridge_port_maxgroups_get "$locus0")
718 ((max == 0))
719 check_err $? "$locus0: Max groups expected to be 0, but $max reported"
721 max=$(bridge_port_vlan_maxgroups_get "$locus2")
722 ((max == 0))
723 check_err $? "$locus2: Max groups expected to be 0, but $max reported"
725 log_test "$CFG: port_vlan maxgroups: isolation of port and per-VLAN maximums"
728 test_8021qvs_maxgroups_zero_cross_vlan_cfg4()
730 test_maxgroups_zero_cross_vlan cfg4
733 test_8021qvs_maxgroups_zero_cross_vlan_ctl4()
735 test_maxgroups_zero_cross_vlan ctl4
738 test_8021qvs_maxgroups_zero_cross_vlan_cfg6()
740 test_maxgroups_zero_cross_vlan cfg6
743 test_8021qvs_maxgroups_zero_cross_vlan_ctl6()
745 test_maxgroups_zero_cross_vlan ctl6
748 test_maxgroups_too_low()
750 local CFG=$1; shift
751 local context=$1; shift
752 local locus=$1; shift
754 RET=0
756 local n=$(bridge_${context}_ngroups_get "$locus")
757 local msg
759 ${CFG}_entries_add "$locus" temp 5 111
760 check_err $? "$locus: Couldn't add MDB entries"
762 bridge_${context}_maxgroups_set "$locus" $((n+2))
763 check_err $? "$locus: Setting maxgroups to $((n+2)) failed"
765 msg=$(${CFG}_entries_add "$locus" temp 2 112 2>&1)
766 check_fail $? "$locus: Adding more entries passed when max<n"
767 bridge_maxgroups_errmsg_check_cfg "$msg"
769 ${CFG}_entries_del "$locus" temp 5 111
770 check_err $? "$locus: Couldn't delete MDB entries"
772 ${CFG}_entries_add "$locus" temp 2 112
773 check_err $? "$locus: Adding more entries failed"
775 ${CFG}_entries_del "$locus" temp 2 112
776 check_err $? "$locus: Deleting more entries failed"
778 bridge_${context}_maxgroups_set "$locus" 0
779 check_err $? "$locus: Couldn't set maximum to 0"
781 log_test "$CFG: $context maxgroups: configure below ngroups"
784 test_8021d_maxgroups_too_low_cfg4()
786 test_maxgroups_too_low cfg4 port "dev $swp1"
789 test_8021d_maxgroups_too_low_ctl4()
791 test_maxgroups_too_low ctl4 port "dev $swp1"
794 test_8021d_maxgroups_too_low_cfg6()
796 test_maxgroups_too_low cfg6 port "dev $swp1"
799 test_8021d_maxgroups_too_low_ctl6()
801 test_maxgroups_too_low ctl6 port "dev $swp1"
804 test_8021q_maxgroups_too_low_cfg4()
806 test_maxgroups_too_low cfg4 port "dev $swp1 vid 10"
809 test_8021q_maxgroups_too_low_ctl4()
811 test_maxgroups_too_low ctl4 port "dev $swp1 vid 10"
814 test_8021q_maxgroups_too_low_cfg6()
816 test_maxgroups_too_low cfg6 port "dev $swp1 vid 10"
819 test_8021q_maxgroups_too_low_ctl6()
821 test_maxgroups_too_low ctl6 port "dev $swp1 vid 10"
824 test_8021qvs_maxgroups_too_low_cfg4()
826 test_maxgroups_too_low cfg4 port_vlan "dev $swp1 vid 10"
829 test_8021qvs_maxgroups_too_low_ctl4()
831 test_maxgroups_too_low ctl4 port_vlan "dev $swp1 vid 10"
834 test_8021qvs_maxgroups_too_low_cfg6()
836 test_maxgroups_too_low cfg6 port_vlan "dev $swp1 vid 10"
839 test_8021qvs_maxgroups_too_low_ctl6()
841 test_maxgroups_too_low ctl6 port_vlan "dev $swp1 vid 10"
844 test_maxgroups_too_many_entries()
846 local CFG=$1; shift
847 local context=$1; shift
848 local locus=$1; shift
850 RET=0
852 local n=$(bridge_${context}_ngroups_get "$locus")
853 local msg
855 # Configure a low maximum
856 bridge_${context}_maxgroups_set "$locus" $((n+1))
857 check_err $? "$locus: Couldn't set maximum"
859 # Try to add more entries than the configured maximum
860 msg=$(${CFG}_entries_add "$locus" temp 5 2>&1)
861 check_fail $? "Adding 5 MDB entries passed, but should have failed"
862 bridge_maxgroups_errmsg_check_${CFG} "$msg"
864 # When adding entries through the control path, as many as possible
865 # get created. That's consistent with the mcast_hash_max behavior.
866 # So there, drop the entries explicitly.
867 if [[ ${CFG%[46]} == ctl ]]; then
868 ${CFG}_entries_del "$locus" temp 17 2>&1
871 local n2=$(bridge_${context}_ngroups_get "$locus")
872 ((n2 == n))
873 check_err $? "Number of groups was $n, but after a failed attempt to add MDB entries it changed to $n2"
875 bridge_${context}_maxgroups_set "$locus" 0
876 check_err $? "$locus: Couldn't set maximum to 0"
878 log_test "$CFG: $context maxgroups: add too many MDB entries"
881 test_8021d_maxgroups_too_many_entries_cfg4()
883 test_maxgroups_too_many_entries cfg4 port "dev $swp1"
886 test_8021d_maxgroups_too_many_entries_ctl4()
888 test_maxgroups_too_many_entries ctl4 port "dev $swp1"
891 test_8021d_maxgroups_too_many_entries_cfg6()
893 test_maxgroups_too_many_entries cfg6 port "dev $swp1"
896 test_8021d_maxgroups_too_many_entries_ctl6()
898 test_maxgroups_too_many_entries ctl6 port "dev $swp1"
901 test_8021q_maxgroups_too_many_entries_cfg4()
903 test_maxgroups_too_many_entries cfg4 port "dev $swp1 vid 10"
906 test_8021q_maxgroups_too_many_entries_ctl4()
908 test_maxgroups_too_many_entries ctl4 port "dev $swp1 vid 10"
911 test_8021q_maxgroups_too_many_entries_cfg6()
913 test_maxgroups_too_many_entries cfg6 port "dev $swp1 vid 10"
916 test_8021q_maxgroups_too_many_entries_ctl6()
918 test_maxgroups_too_many_entries ctl6 port "dev $swp1 vid 10"
921 test_8021qvs_maxgroups_too_many_entries_cfg4()
923 test_maxgroups_too_many_entries cfg4 port_vlan "dev $swp1 vid 10"
926 test_8021qvs_maxgroups_too_many_entries_ctl4()
928 test_maxgroups_too_many_entries ctl4 port_vlan "dev $swp1 vid 10"
931 test_8021qvs_maxgroups_too_many_entries_cfg6()
933 test_maxgroups_too_many_entries cfg6 port_vlan "dev $swp1 vid 10"
936 test_8021qvs_maxgroups_too_many_entries_ctl6()
938 test_maxgroups_too_many_entries ctl6 port_vlan "dev $swp1 vid 10"
941 test_maxgroups_too_many_cross_vlan()
943 local CFG=$1; shift
945 RET=0
947 local locus0="dev $swp1"
948 local locus1="dev $swp1 vid 10"
949 local locus2="dev $swp1 vid 20"
950 local n1=$(bridge_port_vlan_ngroups_get "$locus1")
951 local n2=$(bridge_port_vlan_ngroups_get "$locus2")
952 local msg
954 if ((n1 > n2)); then
955 local tmp=$n1
956 n1=$n2
957 n2=$tmp
959 tmp="$locus1"
960 locus1="$locus2"
961 locus2="$tmp"
964 # Now 0 <= n1 <= n2.
965 ${CFG}_entries_add "$locus2" temp 5 112
966 check_err $? "Couldn't add 5 entries"
968 n2=$(bridge_port_vlan_ngroups_get "$locus2")
969 # Now 0 <= n1 < n2-1.
971 # Setting locus1'maxgroups to n2-1 should pass. The number is
972 # smaller than both the absolute number of MDB entries, and in
973 # particular than number of locus2's number of entries, but it is
974 # large enough to cover locus1's entries. Thus we check that
975 # individual VLAN's ngroups are independent.
976 bridge_port_vlan_maxgroups_set "$locus1" $((n2-1))
977 check_err $? "Setting ${locus1}'s maxgroups to $((n2-1)) failed"
979 msg=$(${CFG}_entries_add "$locus1" temp $n2 111 2>&1)
980 check_fail $? "$locus1: Adding $n2 MDB entries passed, but should have failed"
981 bridge_maxgroups_errmsg_check_${CFG} "$msg"
983 bridge_port_maxgroups_set "$locus0" $((n1 + n2 + 2))
984 check_err $? "$locus0: Couldn't set maximum"
986 msg=$(${CFG}_entries_add "$locus1" temp 5 111 2>&1)
987 check_fail $? "$locus1: Adding 5 MDB entries passed, but should have failed"
988 bridge_maxgroups_errmsg_check_${CFG} "$msg"
990 # IGMP/MLD packets can cause several entries to be added, before
991 # the maximum is hit and the rest is then bounced. Remove what was
992 # committed, if anything.
993 ${CFG}_entries_del "$locus1" temp 5 111 2>/dev/null
995 ${CFG}_entries_add "$locus1" temp 2 111
996 check_err $? "$locus1: Adding 2 MDB entries failed, but should have passed"
998 ${CFG}_entries_del "$locus1" temp 2 111
999 check_err $? "Couldn't delete MDB entries"
1001 ${CFG}_entries_del "$locus2" temp 5 112
1002 check_err $? "Couldn't delete MDB entries"
1004 bridge_port_vlan_maxgroups_set "$locus1" 0
1005 check_err $? "$locus1: Couldn't set maximum to 0"
1007 bridge_port_maxgroups_set "$locus0" 0
1008 check_err $? "$locus0: Couldn't set maximum to 0"
1010 log_test "$CFG: port_vlan maxgroups: isolation of port and per-VLAN ngroups"
1013 test_8021qvs_maxgroups_too_many_cross_vlan_cfg4()
1015 test_maxgroups_too_many_cross_vlan cfg4
1018 test_8021qvs_maxgroups_too_many_cross_vlan_ctl4()
1020 test_maxgroups_too_many_cross_vlan ctl4
1023 test_8021qvs_maxgroups_too_many_cross_vlan_cfg6()
1025 test_maxgroups_too_many_cross_vlan cfg6
1028 test_8021qvs_maxgroups_too_many_cross_vlan_ctl6()
1030 test_maxgroups_too_many_cross_vlan ctl6
1033 test_vlan_attributes()
1035 local locus=$1; shift
1036 local expect=$1; shift
1038 RET=0
1040 local max=$(bridge_port_vlan_maxgroups_get "$locus")
1041 local n=$(bridge_port_vlan_ngroups_get "$locus")
1043 eval "[[ $max $expect ]]"
1044 check_err $? "$locus: maxgroups attribute expected to be $expect, but was $max"
1046 eval "[[ $n $expect ]]"
1047 check_err $? "$locus: ngroups attribute expected to be $expect, but was $n"
1049 log_test "port_vlan: presence of ngroups and maxgroups attributes"
1052 test_8021q_vlan_attributes()
1054 test_vlan_attributes "dev $swp1 vid 10" "== null"
1057 test_8021qvs_vlan_attributes()
1059 test_vlan_attributes "dev $swp1 vid 10" "-ge 0"
1062 test_toggle_vlan_snooping()
1064 local mode=$1; shift
1066 RET=0
1068 local CFG=cfg4
1069 local context=port_vlan
1070 local locus="dev $swp1 vid 10"
1072 ${CFG}_entries_add "$locus" $mode 5
1073 check_err $? "Couldn't add MDB entries"
1075 bridge_${context}_maxgroups_set "$locus" 100
1076 check_err $? "Failed to set max to 100"
1078 ip link set dev br0 type bridge mcast_vlan_snooping 0
1079 sleep 1
1080 ip link set dev br0 type bridge mcast_vlan_snooping 1
1082 local n=$(bridge_${context}_ngroups_get "$locus")
1083 local nn=$(bridge mdb show dev br0 | grep $swp1 | wc -l)
1084 ((nn == n))
1085 check_err $? "mcast_n_groups expected to be $nn, but $n reported"
1087 local max=$(bridge_${context}_maxgroups_get "$locus")
1088 ((max == 100))
1089 check_err $? "Max groups expected to be 100 but $max reported"
1091 bridge_${context}_maxgroups_set "$locus" 0
1092 check_err $? "Failed to set max to 0"
1094 log_test "$CFG: $context: $mode: mcast_vlan_snooping toggle"
1097 test_toggle_vlan_snooping_temp()
1099 test_toggle_vlan_snooping temp
1102 test_toggle_vlan_snooping_permanent()
1104 test_toggle_vlan_snooping permanent
1107 # ngroup test suites
1109 test_8021d_ngroups_cfg4()
1111 test_8021d_ngroups_reporting_cfg4
1114 test_8021d_ngroups_ctl4()
1116 test_8021d_ngroups_reporting_ctl4
1119 test_8021d_ngroups_cfg6()
1121 test_8021d_ngroups_reporting_cfg6
1124 test_8021d_ngroups_ctl6()
1126 test_8021d_ngroups_reporting_ctl6
1129 test_8021q_ngroups_cfg4()
1131 test_8021q_ngroups_reporting_cfg4
1134 test_8021q_ngroups_ctl4()
1136 test_8021q_ngroups_reporting_ctl4
1139 test_8021q_ngroups_cfg6()
1141 test_8021q_ngroups_reporting_cfg6
1144 test_8021q_ngroups_ctl6()
1146 test_8021q_ngroups_reporting_ctl6
1149 test_8021qvs_ngroups_cfg4()
1151 test_8021qvs_ngroups_reporting_cfg4
1152 test_8021qvs_ngroups_cross_vlan_cfg4
1155 test_8021qvs_ngroups_ctl4()
1157 test_8021qvs_ngroups_reporting_ctl4
1158 test_8021qvs_ngroups_cross_vlan_ctl4
1161 test_8021qvs_ngroups_cfg6()
1163 test_8021qvs_ngroups_reporting_cfg6
1164 test_8021qvs_ngroups_cross_vlan_cfg6
1167 test_8021qvs_ngroups_ctl6()
1169 test_8021qvs_ngroups_reporting_ctl6
1170 test_8021qvs_ngroups_cross_vlan_ctl6
1173 # maxgroups test suites
1175 test_8021d_maxgroups_cfg4()
1177 test_8021d_maxgroups_zero_cfg4
1178 test_8021d_maxgroups_too_low_cfg4
1179 test_8021d_maxgroups_too_many_entries_cfg4
1182 test_8021d_maxgroups_ctl4()
1184 test_8021d_maxgroups_zero_ctl4
1185 test_8021d_maxgroups_too_low_ctl4
1186 test_8021d_maxgroups_too_many_entries_ctl4
1189 test_8021d_maxgroups_cfg6()
1191 test_8021d_maxgroups_zero_cfg6
1192 test_8021d_maxgroups_too_low_cfg6
1193 test_8021d_maxgroups_too_many_entries_cfg6
1196 test_8021d_maxgroups_ctl6()
1198 test_8021d_maxgroups_zero_ctl6
1199 test_8021d_maxgroups_too_low_ctl6
1200 test_8021d_maxgroups_too_many_entries_ctl6
1203 test_8021q_maxgroups_cfg4()
1205 test_8021q_maxgroups_zero_cfg4
1206 test_8021q_maxgroups_too_low_cfg4
1207 test_8021q_maxgroups_too_many_entries_cfg4
1210 test_8021q_maxgroups_ctl4()
1212 test_8021q_maxgroups_zero_ctl4
1213 test_8021q_maxgroups_too_low_ctl4
1214 test_8021q_maxgroups_too_many_entries_ctl4
1217 test_8021q_maxgroups_cfg6()
1219 test_8021q_maxgroups_zero_cfg6
1220 test_8021q_maxgroups_too_low_cfg6
1221 test_8021q_maxgroups_too_many_entries_cfg6
1224 test_8021q_maxgroups_ctl6()
1226 test_8021q_maxgroups_zero_ctl6
1227 test_8021q_maxgroups_too_low_ctl6
1228 test_8021q_maxgroups_too_many_entries_ctl6
1231 test_8021qvs_maxgroups_cfg4()
1233 test_8021qvs_maxgroups_zero_cfg4
1234 test_8021qvs_maxgroups_zero_cross_vlan_cfg4
1235 test_8021qvs_maxgroups_too_low_cfg4
1236 test_8021qvs_maxgroups_too_many_entries_cfg4
1237 test_8021qvs_maxgroups_too_many_cross_vlan_cfg4
1240 test_8021qvs_maxgroups_ctl4()
1242 test_8021qvs_maxgroups_zero_ctl4
1243 test_8021qvs_maxgroups_zero_cross_vlan_ctl4
1244 test_8021qvs_maxgroups_too_low_ctl4
1245 test_8021qvs_maxgroups_too_many_entries_ctl4
1246 test_8021qvs_maxgroups_too_many_cross_vlan_ctl4
1249 test_8021qvs_maxgroups_cfg6()
1251 test_8021qvs_maxgroups_zero_cfg6
1252 test_8021qvs_maxgroups_zero_cross_vlan_cfg6
1253 test_8021qvs_maxgroups_too_low_cfg6
1254 test_8021qvs_maxgroups_too_many_entries_cfg6
1255 test_8021qvs_maxgroups_too_many_cross_vlan_cfg6
1258 test_8021qvs_maxgroups_ctl6()
1260 test_8021qvs_maxgroups_zero_ctl6
1261 test_8021qvs_maxgroups_zero_cross_vlan_ctl6
1262 test_8021qvs_maxgroups_too_low_ctl6
1263 test_8021qvs_maxgroups_too_many_entries_ctl6
1264 test_8021qvs_maxgroups_too_many_cross_vlan_ctl6
1267 # other test suites
1269 test_8021qvs_toggle_vlan_snooping()
1271 test_toggle_vlan_snooping_temp
1272 test_toggle_vlan_snooping_permanent
1275 # test groups
1277 test_8021d()
1279 # Tests for vlan_filtering 0 mcast_vlan_snooping 0.
1281 switch_create_8021d
1282 setup_wait
1284 test_8021d_ngroups_cfg4
1285 test_8021d_ngroups_ctl4
1286 test_8021d_ngroups_cfg6
1287 test_8021d_ngroups_ctl6
1288 test_8021d_maxgroups_cfg4
1289 test_8021d_maxgroups_ctl4
1290 test_8021d_maxgroups_cfg6
1291 test_8021d_maxgroups_ctl6
1293 switch_destroy
1296 test_8021q()
1298 # Tests for vlan_filtering 1 mcast_vlan_snooping 0.
1300 switch_create_8021q
1301 setup_wait
1303 test_8021q_vlan_attributes
1304 test_8021q_ngroups_cfg4
1305 test_8021q_ngroups_ctl4
1306 test_8021q_ngroups_cfg6
1307 test_8021q_ngroups_ctl6
1308 test_8021q_maxgroups_cfg4
1309 test_8021q_maxgroups_ctl4
1310 test_8021q_maxgroups_cfg6
1311 test_8021q_maxgroups_ctl6
1313 switch_destroy
1316 test_8021qvs()
1318 # Tests for vlan_filtering 1 mcast_vlan_snooping 1.
1320 switch_create_8021qvs
1321 setup_wait
1323 test_8021qvs_vlan_attributes
1324 test_8021qvs_ngroups_cfg4
1325 test_8021qvs_ngroups_ctl4
1326 test_8021qvs_ngroups_cfg6
1327 test_8021qvs_ngroups_ctl6
1328 test_8021qvs_maxgroups_cfg4
1329 test_8021qvs_maxgroups_ctl4
1330 test_8021qvs_maxgroups_cfg6
1331 test_8021qvs_maxgroups_ctl6
1332 test_8021qvs_toggle_vlan_snooping
1334 switch_destroy
1337 if ! bridge link help 2>&1 | grep -q "mcast_max_groups"; then
1338 echo "SKIP: iproute2 too old, missing bridge \"mcast_max_groups\" support"
1339 exit $ksft_skip
1342 trap cleanup EXIT
1344 setup_prepare
1345 tests_run
1347 exit $EXIT_STATUS