1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3#
4# Test vetoing of FDB entries that mlxsw can not offload. This exercises several
5# different veto vectors to test various rollback scenarios in the vxlan driver.
6
7lib_dir=$(dirname $0)/../../../net/forwarding
8
9ALL_TESTS="
10	fdb_create_veto_test
11	fdb_replace_veto_test
12	fdb_append_veto_test
13	fdb_changelink_veto_test
14"
15NUM_NETIFS=2
16source $lib_dir/lib.sh
17
18setup_prepare()
19{
20	swp1=${NETIFS[p1]}
21	swp2=${NETIFS[p2]}
22
23	ip link add dev br0 type bridge mcast_snooping 0
24
25	ip link set dev $swp1 up
26	ip link set dev $swp1 master br0
27	ip link set dev $swp2 up
28
29	ip link add name vxlan0 up type vxlan id 10 nolearning noudpcsum \
30		ttl 20 tos inherit local 198.51.100.1 dstport 4789
31	ip link set dev vxlan0 master br0
32}
33
34cleanup()
35{
36	pre_cleanup
37
38	ip link set dev vxlan0 nomaster
39	ip link del dev vxlan0
40
41	ip link set dev $swp2 down
42	ip link set dev $swp1 nomaster
43	ip link set dev $swp1 down
44
45	ip link del dev br0
46}
47
48fdb_create_veto_test()
49{
50	RET=0
51
52	bridge fdb add 01:02:03:04:05:06 dev vxlan0 self static \
53	       dst 198.51.100.2 2>/dev/null
54	check_fail $? "multicast MAC not rejected"
55
56	bridge fdb add 01:02:03:04:05:06 dev vxlan0 self static \
57	       dst 198.51.100.2 2>&1 >/dev/null | grep -q mlxsw_spectrum
58	check_err $? "multicast MAC rejected without extack"
59
60	log_test "vxlan FDB veto - create"
61}
62
63fdb_replace_veto_test()
64{
65	RET=0
66
67	bridge fdb add 00:01:02:03:04:05 dev vxlan0 self static \
68	       dst 198.51.100.2
69	check_err $? "valid FDB rejected"
70
71	bridge fdb replace 00:01:02:03:04:05 dev vxlan0 self static \
72	       dst 198.51.100.2 port 1234 2>/dev/null
73	check_fail $? "FDB with an explicit port not rejected"
74
75	bridge fdb replace 00:01:02:03:04:05 dev vxlan0 self static \
76	       dst 198.51.100.2 port 1234 2>&1 >/dev/null \
77	    | grep -q mlxsw_spectrum
78	check_err $? "FDB with an explicit port rejected without extack"
79
80	log_test "vxlan FDB veto - replace"
81}
82
83fdb_append_veto_test()
84{
85	RET=0
86
87	bridge fdb add 00:00:00:00:00:00 dev vxlan0 self static \
88	       dst 198.51.100.2
89	check_err $? "valid FDB rejected"
90
91	bridge fdb append 00:00:00:00:00:00 dev vxlan0 self static \
92	       dst 198.51.100.3 port 1234 2>/dev/null
93	check_fail $? "FDB with an explicit port not rejected"
94
95	bridge fdb append 00:00:00:00:00:00 dev vxlan0 self static \
96	       dst 198.51.100.3 port 1234 2>&1 >/dev/null \
97	    | grep -q mlxsw_spectrum
98	check_err $? "FDB with an explicit port rejected without extack"
99
100	log_test "vxlan FDB veto - append"
101}
102
103fdb_changelink_veto_test()
104{
105	RET=0
106
107	ip link set dev vxlan0 type vxlan \
108	   group 224.0.0.1 dev lo 2>/dev/null
109	check_fail $? "FDB with a multicast IP not rejected"
110
111	ip link set dev vxlan0 type vxlan \
112	   group 224.0.0.1 dev lo 2>&1 >/dev/null \
113	    | grep -q mlxsw_spectrum
114	check_err $? "FDB with a multicast IP rejected without extack"
115
116	log_test "vxlan FDB veto - changelink"
117}
118
119trap cleanup EXIT
120
121setup_prepare
122setup_wait
123
124tests_run
125
126exit $EXIT_STATUS
127