1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3
4# Test that a link aggregation device (bonding, team) removes the hardware
5# addresses that it adds on its underlying devices.
6test_LAG_cleanup()
7{
8	local driver=$1
9	local mode=$2
10	local ucaddr="02:00:00:12:34:56"
11	local addr6="fe80::78:9abc/64"
12	local mcaddr="33:33:ff:78:9a:bc"
13	local name
14
15	ip link add dummy1 type dummy
16	ip link add dummy2 type dummy
17	if [ "$driver" = "bonding" ]; then
18		name="bond1"
19		ip link add "$name" up type bond mode "$mode"
20		ip link set dev dummy1 master "$name"
21		ip link set dev dummy2 master "$name"
22	elif [ "$driver" = "team" ]; then
23		name="team0"
24		teamd -d -c '
25			{
26				"device": "'"$name"'",
27				"runner": {
28					"name": "'"$mode"'"
29				},
30				"ports": {
31					"dummy1":
32						{},
33					"dummy2":
34						{}
35				}
36			}
37		'
38		ip link set dev "$name" up
39	else
40		check_err 1
41		log_test test_LAG_cleanup ": unknown driver \"$driver\""
42		return
43	fi
44
45	# Used to test dev->uc handling
46	ip link add mv0 link "$name" up address "$ucaddr" type macvlan
47	# Used to test dev->mc handling
48	ip address add "$addr6" dev "$name"
49	ip link set dev "$name" down
50	ip link del "$name"
51
52	not grep_bridge_fdb "$ucaddr" bridge fdb show >/dev/null
53	check_err $? "macvlan unicast address still present on a slave"
54
55	not grep_bridge_fdb "$mcaddr" bridge fdb show >/dev/null
56	check_err $? "IPv6 solicited-node multicast mac address still present on a slave"
57
58	cleanup
59
60	log_test "$driver cleanup mode $mode"
61}
62