xref: /linux/tools/testing/selftests/net/forwarding/bridge_mdb_host.sh (revision 156010ed9c2ac1e9df6c11b1f688cf8a6e0152e6)
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3#
4# Verify that adding host mdb entries work as intended for all types of
5# multicast filters: ipv4, ipv6, and mac
6
7ALL_TESTS="mdb_add_del_test"
8NUM_NETIFS=2
9
10TEST_GROUP_IP4="225.1.2.3"
11TEST_GROUP_IP6="ff02::42"
12TEST_GROUP_MAC="01:00:01:c0:ff:ee"
13
14source lib.sh
15
16h1_create()
17{
18	simple_if_init $h1 192.0.2.1/24 2001:db8:1::1/64
19}
20
21h1_destroy()
22{
23	simple_if_fini $h1 192.0.2.1/24 2001:db8:1::1/64
24}
25
26switch_create()
27{
28	# Enable multicast filtering
29	ip link add dev br0 type bridge mcast_snooping 1
30
31	ip link set dev $swp1 master br0
32
33	ip link set dev br0 up
34	ip link set dev $swp1 up
35}
36
37switch_destroy()
38{
39	ip link set dev $swp1 down
40	ip link del dev br0
41}
42
43setup_prepare()
44{
45	h1=${NETIFS[p1]}
46	swp1=${NETIFS[p2]}
47
48	vrf_prepare
49
50	h1_create
51	switch_create
52}
53
54cleanup()
55{
56	pre_cleanup
57
58	switch_destroy
59	h1_destroy
60
61	vrf_cleanup
62}
63
64do_mdb_add_del()
65{
66	local group=$1
67	local flag=$2
68
69	RET=0
70	bridge mdb add dev br0 port br0 grp $group $flag 2>/dev/null
71	check_err $? "Failed adding $group to br0, port br0"
72
73	if [ -z "$flag" ]; then
74	    flag="temp"
75	fi
76
77	bridge mdb show dev br0 | grep $group | grep -q $flag 2>/dev/null
78	check_err $? "$group not added with $flag flag"
79
80	bridge mdb del dev br0 port br0 grp $group 2>/dev/null
81	check_err $? "Failed deleting $group from br0, port br0"
82
83	bridge mdb show dev br0 | grep -q $group >/dev/null
84	check_err_fail 1 $? "$group still in mdb after delete"
85
86	log_test "MDB add/del group $group to bridge port br0"
87}
88
89mdb_add_del_test()
90{
91	do_mdb_add_del $TEST_GROUP_MAC permanent
92	do_mdb_add_del $TEST_GROUP_IP4
93	do_mdb_add_del $TEST_GROUP_IP6
94}
95
96trap cleanup EXIT
97
98setup_prepare
99setup_wait
100
101tests_run
102
103exit $EXIT_STATUS
104