2 # SPDX-License-Identifier: GPL-2.0
4 # Test devlink-trap L2 drops functionality over mlxsw. Each registered L2 drop
5 # packet trap is tested to make sure it is triggered under the right
8 lib_dir
=$
(dirname $0)/..
/..
/..
/net
/forwarding
11 source_mac_is_multicast_test
12 vlan_tag_mismatch_test
13 ingress_vlan_filter_test
14 ingress_stp_filter_test
15 port_list_is_empty_test
16 port_loopback_filter_test
19 source $lib_dir/tc_common.sh
20 source $lib_dir/lib.sh
21 source $lib_dir/devlink_lib.sh
45 ip link add dev br0
type bridge vlan_filtering
1 mcast_snooping
0
47 ip link
set dev
$swp1 master br0
48 ip link
set dev
$swp2 master br0
50 ip link
set dev br0 up
51 ip link
set dev
$swp1 up
52 ip link
set dev
$swp2 up
54 tc qdisc add dev
$swp2 clsact
59 tc qdisc del dev
$swp2 clsact
61 ip link
set dev
$swp2 down
62 ip link
set dev
$swp1 down
95 source_mac_is_multicast_test
()
97 local trap_name
="source_mac_is_multicast"
98 local smac
=01:02:03:04:05:06
101 tc filter add dev
$swp2 egress protocol ip pref
1 handle
101 \
102 flower src_mac
$smac action drop
104 $MZ $h1 -c 0 -p 100 -a $smac -b bcast
-t ip
-d 1msec
-q &
109 devlink_trap_drop_test
$trap_name $swp2 101
111 log_test
"Source MAC is multicast"
113 devlink_trap_drop_cleanup
$mz_pid $swp2 ip
1 101
116 __vlan_tag_mismatch_test
()
118 local trap_name
="vlan_tag_mismatch"
119 local dmac
=de
:ad
:be
:ef
:13:37
123 # Remove PVID flag. This should prevent untagged and prio-tagged
124 # packets from entering the bridge.
125 bridge vlan add vid
1 dev
$swp1 untagged master
127 tc filter add dev
$swp2 egress protocol ip pref
1 handle
101 \
128 flower dst_mac
$dmac action drop
130 $MZ $h1 "$opt" -c 0 -p 100 -a own
-b $dmac -t ip
-d 1msec
-q &
133 devlink_trap_drop_test
$trap_name $swp2 101
135 # Add PVID and make sure packets are no longer dropped.
136 bridge vlan add vid
1 dev
$swp1 pvid untagged master
137 devlink_trap_action_set
$trap_name "trap"
139 devlink_trap_stats_idle_test
$trap_name
140 check_err $?
"Trap stats not idle when packets should not be dropped"
141 devlink_trap_group_stats_idle_test $
(devlink_trap_group_get
$trap_name)
142 check_err $?
"Trap group stats not idle with when packets should not be dropped"
144 tc_check_packets
"dev $swp2 egress" 101 0
145 check_fail $?
"Packets not forwarded when should"
147 devlink_trap_action_set
$trap_name "drop"
149 devlink_trap_drop_cleanup
$mz_pid $swp2 ip
1 101
152 vlan_tag_mismatch_untagged_test
()
156 __vlan_tag_mismatch_test
158 log_test
"VLAN tag mismatch - untagged packets"
161 vlan_tag_mismatch_vid_0_test
()
165 __vlan_tag_mismatch_test
"-Q 0"
167 log_test
"VLAN tag mismatch - prio-tagged packets"
170 vlan_tag_mismatch_test
()
172 vlan_tag_mismatch_untagged_test
173 vlan_tag_mismatch_vid_0_test
176 ingress_vlan_filter_test
()
178 local trap_name
="ingress_vlan_filter"
179 local dmac
=de
:ad
:be
:ef
:13:37
183 bridge vlan add vid
$vid dev
$swp2 master
187 tc filter add dev
$swp2 egress protocol ip pref
1 handle
101 \
188 flower dst_mac
$dmac action drop
190 $MZ $h1 -Q $vid -c 0 -p 100 -a own
-b $dmac -t ip
-d 1msec
-q &
193 devlink_trap_drop_test
$trap_name $swp2 101
195 # Add the VLAN on the bridge port and make sure packets are no longer
197 bridge vlan add vid
$vid dev
$swp1 master
198 devlink_trap_action_set
$trap_name "trap"
200 devlink_trap_stats_idle_test
$trap_name
201 check_err $?
"Trap stats not idle when packets should not be dropped"
202 devlink_trap_group_stats_idle_test $
(devlink_trap_group_get
$trap_name)
203 check_err $?
"Trap group stats not idle with when packets should not be dropped"
205 tc_check_packets
"dev $swp2 egress" 101 0
206 check_fail $?
"Packets not forwarded when should"
208 devlink_trap_action_set
$trap_name "drop"
210 log_test
"Ingress VLAN filter"
212 devlink_trap_drop_cleanup
$mz_pid $swp2 ip
1 101
214 bridge vlan del vid
$vid dev
$swp1 master
215 bridge vlan del vid
$vid dev
$swp2 master
218 __ingress_stp_filter_test
()
220 local trap_name
="ingress_spanning_tree_filter"
221 local dmac
=de
:ad
:be
:ef
:13:37
222 local state
=$1; shift
226 bridge vlan add vid
$vid dev
$swp2 master
227 bridge vlan add vid
$vid dev
$swp1 master
228 ip link
set dev
$swp1 type bridge_slave state
$state
230 tc filter add dev
$swp2 egress protocol ip pref
1 handle
101 \
231 flower dst_mac
$dmac action drop
233 $MZ $h1 -Q $vid -c 0 -p 100 -a own
-b $dmac -t ip
-d 1msec
-q &
236 devlink_trap_drop_test
$trap_name $swp2 101
238 # Change STP state to forwarding and make sure packets are no longer
240 ip link
set dev
$swp1 type bridge_slave state
3
241 devlink_trap_action_set
$trap_name "trap"
243 devlink_trap_stats_idle_test
$trap_name
244 check_err $?
"Trap stats not idle when packets should not be dropped"
245 devlink_trap_group_stats_idle_test $
(devlink_trap_group_get
$trap_name)
246 check_err $?
"Trap group stats not idle with when packets should not be dropped"
248 tc_check_packets
"dev $swp2 egress" 101 0
249 check_fail $?
"Packets not forwarded when should"
251 devlink_trap_action_set
$trap_name "drop"
253 devlink_trap_drop_cleanup
$mz_pid $swp2 ip
1 101
255 bridge vlan del vid
$vid dev
$swp1 master
256 bridge vlan del vid
$vid dev
$swp2 master
259 ingress_stp_filter_listening_test
()
261 local state
=$1; shift
265 __ingress_stp_filter_test
$state
267 log_test
"Ingress STP filter - listening state"
270 ingress_stp_filter_learning_test
()
272 local state
=$1; shift
276 __ingress_stp_filter_test
$state
278 log_test
"Ingress STP filter - learning state"
281 ingress_stp_filter_test
()
283 ingress_stp_filter_listening_test
1
284 ingress_stp_filter_learning_test
2
287 port_list_is_empty_uc_test
()
289 local trap_name
="port_list_is_empty"
290 local dmac
=de
:ad
:be
:ef
:13:37
293 # Disable unicast flooding on both ports, so that packets cannot egress
295 ip link
set dev
$swp1 type bridge_slave flood off
296 ip link
set dev
$swp2 type bridge_slave flood off
300 tc filter add dev
$swp2 egress protocol ip pref
1 handle
101 \
301 flower dst_mac
$dmac action drop
303 $MZ $h1 -c 0 -p 100 -a own
-b $dmac -t ip
-d 1msec
-q &
306 devlink_trap_drop_test
$trap_name $swp2 101
308 # Allow packets to be flooded to one port.
309 ip link
set dev
$swp2 type bridge_slave flood on
310 devlink_trap_action_set
$trap_name "trap"
312 devlink_trap_stats_idle_test
$trap_name
313 check_err $?
"Trap stats not idle when packets should not be dropped"
314 devlink_trap_group_stats_idle_test $
(devlink_trap_group_get
$trap_name)
315 check_err $?
"Trap group stats not idle with when packets should not be dropped"
317 tc_check_packets
"dev $swp2 egress" 101 0
318 check_fail $?
"Packets not forwarded when should"
320 devlink_trap_action_set
$trap_name "drop"
322 log_test
"Port list is empty - unicast"
324 devlink_trap_drop_cleanup
$mz_pid $swp2 ip
1 101
326 ip link
set dev
$swp1 type bridge_slave flood on
329 port_list_is_empty_mc_test
()
331 local trap_name
="port_list_is_empty"
332 local dmac
=01:00:5e
:00:00:01
336 # Disable multicast flooding on both ports, so that packets cannot
337 # egress any port. We also need to flush IP addresses from the bridge
338 # in order to prevent packets from being flooded to the router port.
339 ip link
set dev
$swp1 type bridge_slave mcast_flood off
340 ip link
set dev
$swp2 type bridge_slave mcast_flood off
341 ip address flush dev br0
345 tc filter add dev
$swp2 egress protocol ip pref
1 handle
101 \
346 flower dst_mac
$dmac action drop
348 $MZ $h1 -c 0 -p 100 -a own
-b $dmac -t ip
-B $dip -d 1msec
-q &
351 devlink_trap_drop_test
$trap_name $swp2 101
353 # Allow packets to be flooded to one port.
354 ip link
set dev
$swp2 type bridge_slave mcast_flood on
355 devlink_trap_action_set
$trap_name "trap"
357 devlink_trap_stats_idle_test
$trap_name
358 check_err $?
"Trap stats not idle when packets should not be dropped"
359 devlink_trap_group_stats_idle_test $
(devlink_trap_group_get
$trap_name)
360 check_err $?
"Trap group stats not idle with when packets should not be dropped"
362 tc_check_packets
"dev $swp2 egress" 101 0
363 check_fail $?
"Packets not forwarded when should"
365 devlink_trap_action_set
$trap_name "drop"
367 log_test
"Port list is empty - multicast"
369 devlink_trap_drop_cleanup
$mz_pid $swp2 ip
1 101
371 ip link
set dev
$swp1 type bridge_slave mcast_flood on
374 port_list_is_empty_test
()
376 port_list_is_empty_uc_test
377 port_list_is_empty_mc_test
380 port_loopback_filter_uc_test
()
382 local trap_name
="port_loopback_filter"
383 local dmac
=de
:ad
:be
:ef
:13:37
386 # Make sure packets can only egress the input port.
387 ip link
set dev
$swp2 type bridge_slave flood off
391 tc filter add dev
$swp2 egress protocol ip pref
1 handle
101 \
392 flower dst_mac
$dmac action drop
394 $MZ $h1 -c 0 -p 100 -a own
-b $dmac -t ip
-d 1msec
-q &
397 devlink_trap_drop_test
$trap_name $swp2 101
399 # Allow packets to be flooded.
400 ip link
set dev
$swp2 type bridge_slave flood on
401 devlink_trap_action_set
$trap_name "trap"
403 devlink_trap_stats_idle_test
$trap_name
404 check_err $?
"Trap stats not idle when packets should not be dropped"
405 devlink_trap_group_stats_idle_test $
(devlink_trap_group_get
$trap_name)
406 check_err $?
"Trap group stats not idle with when packets should not be dropped"
408 tc_check_packets
"dev $swp2 egress" 101 0
409 check_fail $?
"Packets not forwarded when should"
411 devlink_trap_action_set
$trap_name "drop"
413 log_test
"Port loopback filter - unicast"
415 devlink_trap_drop_cleanup
$mz_pid $swp2 ip
1 101
418 port_loopback_filter_test
()
420 port_loopback_filter_uc_test