2 # SPDX-License-Identifier: GPL-2.0
4 # Test devlink-trap control trap functionality over mlxsw. Each registered
5 # control packet trap is tested to make sure it is triggered under the right
8 # +---------------------------------+
12 # | | 2001:db8:1::1/64 |
14 # | | default via 192.0.2.2 |
15 # | | default via 2001:db8:1::2 |
16 # +----|----------------------------+
18 # +----|----------------------------------------------------------------------+
22 # | 2001:db8:1::2/64 |
24 # | 2001:db8:2::2/64 |
28 # +----|----------------------------------------------------------------------+
30 # +----|----------------------------+
31 # | | default via 198.51.100.2 |
32 # | | default via 2001:db8:2::2 |
34 # | | 2001:db8:2::1/64 |
35 # | | 198.51.100.1/24 |
38 # +---------------------------------+
40 lib_dir
=$
(dirname $0)/..
/..
/..
/net
/forwarding
59 ipv6_neigh_solicit_test
60 ipv6_neigh_advert_test
74 ipv6_uc_dip_link_local_scope_test
75 ipv4_router_alert_test
76 ipv6_router_alert_test
77 ipv6_dip_all_nodes_test
78 ipv6_dip_all_routers_test
79 ipv6_router_solicit_test
80 ipv6_router_advert_test
84 flow_action_sample_test
88 source $lib_dir/lib.sh
89 source $lib_dir/devlink_lib.sh
93 simple_if_init
$h1 192.0.2.1/24 2001:db8
:1::1/64
95 ip
-4 route add default vrf v
$h1 nexthop via
192.0.2.2
96 ip
-6 route add default vrf v
$h1 nexthop via
2001:db8
:1::2
101 ip
-6 route del default vrf v
$h1 nexthop via
2001:db8
:1::2
102 ip
-4 route del default vrf v
$h1 nexthop via
192.0.2.2
104 simple_if_fini
$h1 192.0.2.1/24 2001:db8
:1::1/64
109 simple_if_init
$h2 198.51.100.1/24 2001:db8
:2::1/64
111 ip
-4 route add default vrf v
$h2 nexthop via
198.51.100.2
112 ip
-6 route add default vrf v
$h2 nexthop via
2001:db8
:2::2
117 ip
-6 route del default vrf v
$h2 nexthop via
2001:db8
:2::2
118 ip
-4 route del default vrf v
$h2 nexthop via
198.51.100.2
120 simple_if_fini
$h2 198.51.100.1/24 2001:db8
:2::1/64
125 ip link
set dev
$rp1 up
126 ip link
set dev
$rp2 up
128 __addr_add_del
$rp1 add
192.0.2.2/24 2001:db8
:1::2/64
129 __addr_add_del
$rp2 add
198.51.100.2/24 2001:db8
:2::2/64
134 __addr_add_del
$rp2 del
198.51.100.2/24 2001:db8
:2::2/64
135 __addr_add_del
$rp1 del
192.0.2.2/24 2001:db8
:1::2/64
137 ip link
set dev
$rp2 down
138 ip link
set dev
$rp1 down
171 devlink_trap_stats_test
"STP" "stp" $MZ $h1 -c 1 -t bpdu
-q
176 local source_mac
=$1; shift
180 )"01:80:C2:00:00:02:"$
( : ETH daddr
181 )"$source_mac:"$
( : ETH saddr
182 )"88:09:"$
( : ETH
type
189 local h1mac
=$
(mac_get
$h1)
191 devlink_trap_stats_test
"LACP" "lacp" $MZ $h1 -c 1 \
192 $
(lacp_payload_get
$h1mac) -p 100 -q
197 local source_mac
=$1; shift
201 )"01:80:C2:00:00:0E:"$
( : ETH daddr
202 )"$source_mac:"$
( : ETH saddr
203 )"88:CC:"$
( : ETH
type
210 local h1mac
=$
(mac_get
$h1)
212 devlink_trap_stats_test
"LLDP" "lldp" $MZ $h1 -c 1 \
213 $
(lldp_payload_get
$h1mac) -p 100 -q
218 # IGMP (IP Protocol 2) Membership Query (Type 0x11)
219 devlink_trap_stats_test
"IGMP Membership Query" "igmp_query" \
220 $MZ $h1 -c 1 -a own
-b 01:00:5E
:00:00:01 \
221 -A 192.0.2.1 -B 224.0.0.1 -t ip proto
=2,p
=11 -p 100 -q
224 igmp_v1_report_test
()
226 # IGMP (IP Protocol 2) Version 1 Membership Report (Type 0x12)
227 devlink_trap_stats_test
"IGMP Version 1 Membership Report" \
228 "igmp_v1_report" $MZ $h1 -c 1 -a own
-b 01:00:5E
:00:00:01 \
229 -A 192.0.2.1 -B 244.0.0.1 -t ip proto
=2,p
=12 -p 100 -q
232 igmp_v2_report_test
()
234 # IGMP (IP Protocol 2) Version 2 Membership Report (Type 0x16)
235 devlink_trap_stats_test
"IGMP Version 2 Membership Report" \
236 "igmp_v2_report" $MZ $h1 -c 1 -a own
-b 01:00:5E
:00:00:01 \
237 -A 192.0.2.1 -B 244.0.0.1 -t ip proto
=2,p
=16 -p 100 -q
240 igmp_v3_report_test
()
242 # IGMP (IP Protocol 2) Version 3 Membership Report (Type 0x22)
243 devlink_trap_stats_test
"IGMP Version 3 Membership Report" \
244 "igmp_v3_report" $MZ $h1 -c 1 -a own
-b 01:00:5E
:00:00:01 \
245 -A 192.0.2.1 -B 244.0.0.1 -t ip proto
=2,p
=22 -p 100 -q
250 # IGMP (IP Protocol 2) Version 2 Leave Group (Type 0x17)
251 devlink_trap_stats_test
"IGMP Version 2 Leave Group" \
252 "igmp_v2_leave" $MZ $h1 -c 1 -a own
-b 01:00:5E
:00:00:02 \
253 -A 192.0.2.1 -B 224.0.0.2 -t ip proto
=2,p
=17 -p 100 -q
261 type=$
(printf "%x" $type)
263 )"3A:"$
( : Next Header
- ICMPv6
264 )"00:"$
( : Hdr Ext Len
265 )"00:00:00:00:00:00:"$
( : Options and Padding
266 )"$type:"$
( : ICMPv6.
type
267 )"00:"$
( : ICMPv6.code
268 )"00:"$
( : ICMPv6.checksum
275 # MLD Multicast Listener Query (Type 130)
276 devlink_trap_stats_test
"MLD Multicast Listener Query" "mld_query" \
277 $MZ $h1 -6 -c 1 -A fe80
::1 -B ff02
::1 \
278 -t ip hop
=1,next
=0,payload
=$
(mld_payload_get
130) -p 100 -q
283 # MLD Version 1 Multicast Listener Report (Type 131)
284 devlink_trap_stats_test
"MLD Version 1 Multicast Listener Report" \
285 "mld_v1_report" $MZ $h1 -6 -c 1 -A fe80
::1 -B ff02
::16 \
286 -t ip hop
=1,next
=0,payload
=$
(mld_payload_get
131) -p 100 -q
291 # MLD Version 2 Multicast Listener Report (Type 143)
292 devlink_trap_stats_test
"MLD Version 2 Multicast Listener Report" \
293 "mld_v2_report" $MZ $h1 -6 -c 1 -A fe80
::1 -B ff02
::16 \
294 -t ip hop
=1,next
=0,payload
=$
(mld_payload_get
143) -p 100 -q
299 # MLD Version 1 Multicast Listener Done (Type 132)
300 devlink_trap_stats_test
"MLD Version 1 Multicast Listener Done" \
301 "mld_v1_done" $MZ $h1 -6 -c 1 -A fe80
::1 -B ff02
::16 \
302 -t ip hop
=1,next
=0,payload
=$
(mld_payload_get
132) -p 100 -q
307 devlink_trap_stats_test
"IPv4 DHCP Port 67" "ipv4_dhcp" \
308 $MZ $h1 -c 1 -a own
-b bcast
-A 0.0.0.0 -B 255.255.255.255 \
309 -t udp sp
=68,dp
=67 -p 100 -q
311 devlink_trap_stats_test
"IPv4 DHCP Port 68" "ipv4_dhcp" \
312 $MZ $h1 -c 1 -a own
-b $
(mac_get
$rp1) -A 192.0.2.1 \
313 -B 255.255.255.255 -t udp sp
=67,dp
=68 -p 100 -q
318 devlink_trap_stats_test
"IPv6 DHCP Port 547" "ipv6_dhcp" \
319 $MZ $h1 -6 -c 1 -A fe80
::1 -B ff02
::1:2 -t udp sp
=546,dp
=547 \
322 devlink_trap_stats_test
"IPv6 DHCP Port 546" "ipv6_dhcp" \
323 $MZ $h1 -6 -c 1 -A fe80
::1 -B ff02
::1:2 -t udp sp
=547,dp
=546 \
329 devlink_trap_stats_test
"ARP Request" "arp_request" \
330 $MZ $h1 -c 1 -a own
-b bcast
-t arp request
-p 100 -q
335 devlink_trap_stats_test
"ARP Response" "arp_response" \
336 $MZ $h1 -c 1 -a own
-b $
(mac_get
$rp1) -t arp reply
-p 100 -q
344 type=$
(printf "%x" $type)
346 )"$type:"$
( : ICMPv6.
type
347 )"00:"$
( : ICMPv6.code
348 )"00:"$
( : ICMPv6.checksum
353 ipv6_neigh_solicit_test
()
355 devlink_trap_stats_test
"IPv6 Neighbour Solicitation" \
356 "ipv6_neigh_solicit" $MZ $h1 -6 -c 1 \
357 -A fe80
::1 -B ff02
::1:ff00
:02 \
358 -t ip hop
=1,next
=58,payload
=$
(icmpv6_header_get
135) -p 100 -q
361 ipv6_neigh_advert_test
()
363 devlink_trap_stats_test
"IPv6 Neighbour Advertisement" \
364 "ipv6_neigh_advert" $MZ $h1 -6 -c 1 -a own
-b $
(mac_get
$rp1) \
365 -A fe80
::1 -B 2001:db8
:1::2 \
366 -t ip hop
=1,next
=58,payload
=$
(icmpv6_header_get
136) -p 100 -q
371 devlink_trap_stats_test
"IPv4 BFD Control - Port 3784" "ipv4_bfd" \
372 $MZ $h1 -c 1 -a own
-b $
(mac_get
$rp1) \
373 -A 192.0.2.1 -B 192.0.2.2 -t udp sp
=49153,dp
=3784 -p 100 -q
375 devlink_trap_stats_test
"IPv4 BFD Echo - Port 3785" "ipv4_bfd" \
376 $MZ $h1 -c 1 -a own
-b $
(mac_get
$rp1) \
377 -A 192.0.2.1 -B 192.0.2.2 -t udp sp
=49153,dp
=3785 -p 100 -q
382 devlink_trap_stats_test
"IPv6 BFD Control - Port 3784" "ipv6_bfd" \
383 $MZ $h1 -6 -c 1 -a own
-b $
(mac_get
$rp1) \
384 -A 2001:db8
:1::1 -B 2001:db8
:1::2 \
385 -t udp sp
=49153,dp
=3784 -p 100 -q
387 devlink_trap_stats_test
"IPv6 BFD Echo - Port 3785" "ipv6_bfd" \
388 $MZ $h1 -6 -c 1 -a own
-b $
(mac_get
$rp1) \
389 -A 2001:db8
:1::1 -B 2001:db8
:1::2 \
390 -t udp sp
=49153,dp
=3785 -p 100 -q
395 devlink_trap_stats_test
"IPv4 OSPF - Multicast" "ipv4_ospf" \
396 $MZ $h1 -c 1 -a own
-b 01:00:5e
:00:00:05 \
397 -A 192.0.2.1 -B 224.0.0.5 -t ip proto
=89 -p 100 -q
399 devlink_trap_stats_test
"IPv4 OSPF - Unicast" "ipv4_ospf" \
400 $MZ $h1 -c 1 -a own
-b $
(mac_get
$rp1) \
401 -A 192.0.2.1 -B 192.0.2.2 -t ip proto
=89 -p 100 -q
406 devlink_trap_stats_test
"IPv6 OSPF - Multicast" "ipv6_ospf" \
407 $MZ $h1 -6 -c 1 -a own
-b 33:33:00:00:00:05 \
408 -A fe80
::1 -B ff02
::5 -t ip next
=89 -p 100 -q
410 devlink_trap_stats_test
"IPv6 OSPF - Unicast" "ipv6_ospf" \
411 $MZ $h1 -6 -c 1 -a own
-b $
(mac_get
$rp1) \
412 -A 2001:db8
:1::1 -B 2001:db8
:1::2 -t ip next
=89 -p 100 -q
417 devlink_trap_stats_test
"IPv4 BGP" "ipv4_bgp" \
418 $MZ $h1 -c 1 -a own
-b $
(mac_get
$rp1) \
419 -A 192.0.2.1 -B 192.0.2.2 -t tcp sp
=54321,dp
=179,flags
=rst \
425 devlink_trap_stats_test
"IPv6 BGP" "ipv6_bgp" \
426 $MZ $h1 -6 -c 1 -a own
-b $
(mac_get
$rp1) \
427 -A 2001:db8
:1::1 -B 2001:db8
:1::2 \
428 -t tcp sp
=54321,dp
=179,flags
=rst
-p 100 -q
433 devlink_trap_stats_test
"IPv4 VRRP" "ipv4_vrrp" \
434 $MZ $h1 -c 1 -a own
-b 01:00:5e
:00:00:12 \
435 -A 192.0.2.1 -B 224.0.0.18 -t ip proto
=112 -p 100 -q
440 devlink_trap_stats_test
"IPv6 VRRP" "ipv6_vrrp" \
441 $MZ $h1 -6 -c 1 -a own
-b 33:33:00:00:00:12 \
442 -A fe80
::1 -B ff02
::12 -t ip next
=112 -p 100 -q
447 devlink_trap_stats_test
"IPv4 PIM - Multicast" "ipv4_pim" \
448 $MZ $h1 -c 1 -a own
-b 01:00:5e
:00:00:0d \
449 -A 192.0.2.1 -B 224.0.0.13 -t ip proto
=103 -p 100 -q
451 devlink_trap_stats_test
"IPv4 PIM - Unicast" "ipv4_pim" \
452 $MZ $h1 -c 1 -a own
-b $
(mac_get
$rp1) \
453 -A 192.0.2.1 -B 192.0.2.2 -t ip proto
=103 -p 100 -q
458 devlink_trap_stats_test
"IPv6 PIM - Multicast" "ipv6_pim" \
459 $MZ $h1 -6 -c 1 -a own
-b 33:33:00:00:00:0d \
460 -A fe80
::1 -B ff02
::d
-t ip next
=103 -p 100 -q
462 devlink_trap_stats_test
"IPv6 PIM - Unicast" "ipv6_pim" \
463 $MZ $h1 -6 -c 1 -a own
-b $
(mac_get
$rp1) \
464 -A fe80
::1 -B 2001:db8
:1::2 -t ip next
=103 -p 100 -q
469 # Add neighbours to the fake destination IPs, so that the packets are
470 # routed in the device and not trapped due to an unresolved neighbour
472 ip
-4 neigh add
192.0.2.3 lladdr
00:11:22:33:44:55 nud permanent \
474 ip
-6 neigh add
2001:db8
:1::3 lladdr
00:11:22:33:44:55 nud permanent \
477 devlink_trap_stats_test
"IPv4 Unicast Loopback" "uc_loopback" \
478 $MZ $h1 -c 1 -a own
-b $
(mac_get
$rp1) \
479 -A 192.0.2.1 -B 192.0.2.3 -t udp sp
=54321,dp
=12345 -p 100 -q
481 devlink_trap_stats_test
"IPv6 Unicast Loopback" "uc_loopback" \
482 $MZ $h1 -6 -c 1 -a own
-b $
(mac_get
$rp1) \
483 -A 2001:db8
:1::1 -B 2001:db8
:1::3 -t udp sp
=54321,dp
=12345 \
486 ip
-6 neigh del
2001:db8
:1::3 dev
$rp1
487 ip
-4 neigh del
192.0.2.3 dev
$rp1
492 # Use a fake source IP to prevent the trap from being triggered twice
493 # when the router sends back a port unreachable message.
494 devlink_trap_stats_test
"IPv4 Local Route" "local_route" \
495 $MZ $h1 -c 1 -a own
-b $
(mac_get
$rp1) \
496 -A 192.0.2.3 -B 192.0.2.2 -t udp sp
=54321,dp
=12345 -p 100 -q
498 devlink_trap_stats_test
"IPv6 Local Route" "local_route" \
499 $MZ $h1 -6 -c 1 -a own
-b $
(mac_get
$rp1) \
500 -A 2001:db8
:1::3 -B 2001:db8
:1::2 -t udp sp
=54321,sp
=12345 \
504 external_route_test
()
506 # Add a dummy device through which the incoming packets should be
508 ip link add name dummy10 up
type dummy
509 ip address add
203.0.113.1/24 dev dummy10
510 ip
-6 address add
2001:db8
:10::1/64 dev dummy10
512 devlink_trap_stats_test
"IPv4 External Route" "external_route" \
513 $MZ $h1 -c 1 -a own
-b $
(mac_get
$rp1) \
514 -A 192.0.2.1 -B 203.0.113.2 -t udp sp
=54321,dp
=12345 -p 100 -q
516 devlink_trap_stats_test
"IPv6 External Route" "external_route" \
517 $MZ $h1 -6 -c 1 -a own
-b $
(mac_get
$rp1) \
518 -A 2001:db8
:1::1 -B 2001:db8
:10::2 -t udp sp
=54321,sp
=12345 \
521 ip
-6 address del
2001:db8
:10::1/64 dev dummy10
522 ip address del
203.0.113.1/24 dev dummy10
523 ip link del dev dummy10
526 ipv6_uc_dip_link_local_scope_test
()
528 # Add a dummy link-local prefix route to allow the packet to be routed.
529 ip
-6 route add fe80
:1::/64 dev
$rp2
531 devlink_trap_stats_test \
532 "IPv6 Unicast Destination IP With Link-Local Scope" \
533 "ipv6_uc_dip_link_local_scope" \
534 $MZ $h1 -6 -c 1 -a own
-b $
(mac_get
$rp1) \
535 -A fe80
::1 -B fe80
:1::2 -t udp sp
=54321,sp
=12345 \
538 ip
-6 route del fe80
:1::/64 dev
$rp2
541 ipv4_router_alert_get
()
545 # https://en.wikipedia.org/wiki/IPv4#Options
547 )"94:"$
( : Option Number
548 )"04:"$
( : Option Length
549 )"00:00:"$
( : Option Data
554 ipv4_router_alert_test
()
556 devlink_trap_stats_test
"IPv4 Router Alert" "ipv4_router_alert" \
557 $MZ $h1 -c 1 -a own
-b $
(mac_get
$rp1) \
558 -A 192.0.2.1 -B 198.51.100.3 \
559 -t ip option
=$
(ipv4_router_alert_get
) -p 100 -q
562 ipv6_router_alert_get
()
566 # https://en.wikipedia.org/wiki/IPv6_packet#Hop-by-hop_options_and_destination_options
567 # https://tools.ietf.org/html/rfc2711#section-2.1
569 )"11:"$
( : Next Header
- UDP
570 )"00:"$
( : Hdr Ext Len
571 )"05:02:00:00:00:00:"$
( : Option Data
576 ipv6_router_alert_test
()
578 devlink_trap_stats_test
"IPv6 Router Alert" "ipv6_router_alert" \
579 $MZ $h1 -6 -c 1 -a own
-b $
(mac_get
$rp1) \
580 -A 2001:db8
:1::1 -B 2001:db8
:1::3 \
581 -t ip next
=0,payload
=$
(ipv6_router_alert_get
) -p 100 -q
584 ipv6_dip_all_nodes_test
()
586 devlink_trap_stats_test
"IPv6 Destination IP \"All Nodes Address\"" \
587 "ipv6_dip_all_nodes" \
588 $MZ $h1 -6 -c 1 -a own
-b 33:33:00:00:00:01 \
589 -A 2001:db8
:1::1 -B ff02
::1 -t udp sp
=12345,dp
=54321 -p 100 -q
592 ipv6_dip_all_routers_test
()
594 devlink_trap_stats_test
"IPv6 Destination IP \"All Routers Address\"" \
595 "ipv6_dip_all_routers" \
596 $MZ $h1 -6 -c 1 -a own
-b 33:33:00:00:00:02 \
597 -A 2001:db8
:1::1 -B ff02
::2 -t udp sp
=12345,dp
=54321 -p 100 -q
600 ipv6_router_solicit_test
()
602 devlink_trap_stats_test
"IPv6 Router Solicitation" \
603 "ipv6_router_solicit" \
604 $MZ $h1 -6 -c 1 -a own
-b 33:33:00:00:00:02 \
605 -A fe80
::1 -B ff02
::2 \
606 -t ip hop
=1,next
=58,payload
=$
(icmpv6_header_get
133) -p 100 -q
609 ipv6_router_advert_test
()
611 devlink_trap_stats_test
"IPv6 Router Advertisement" \
612 "ipv6_router_advert" \
613 $MZ $h1 -6 -c 1 -a own
-b 33:33:00:00:00:01 \
614 -A fe80
::1 -B ff02
::1 \
615 -t ip hop
=1,next
=58,payload
=$
(icmpv6_header_get
134) -p 100 -q
620 devlink_trap_stats_test
"IPv6 Redirect Message" \
622 $MZ $h1 -6 -c 1 -a own
-b $
(mac_get
$rp1) \
623 -A fe80
::1 -B 2001:db8
:1::2 \
624 -t ip hop
=1,next
=58,payload
=$
(icmpv6_header_get
137) -p 100 -q
629 # PTP is only supported on Spectrum-1, for now.
630 [[ "$DEVLINK_VIDDID" != "15b3:cb84" ]] && return
633 devlink_trap_stats_test
"PTP Time-Critical Event Message" "ptp_event" \
634 $MZ $h1 -c 1 -a own
-b 01:00:5e
:00:01:81 \
635 -A 192.0.2.1 -B 224.0.1.129 \
636 -t udp sp
=12345,dp
=319,payload
=10 -p 100 -q
641 # PTP is only supported on Spectrum-1, for now.
642 [[ "$DEVLINK_VIDDID" != "15b3:cb84" ]] && return
645 devlink_trap_stats_test
"PTP General Message" "ptp_general" \
646 $MZ $h1 -c 1 -a own
-b 01:00:5e
:00:01:81 \
647 -A 192.0.2.1 -B 224.0.1.129 \
648 -t udp sp
=12345,dp
=320,payload
=1b
-p 100 -q
651 flow_action_sample_test
()
653 # Install a filter that samples every incoming packet.
654 tc qdisc add dev
$rp1 clsact
655 tc filter add dev
$rp1 ingress proto all pref
1 handle
101 matchall \
656 skip_sw action sample rate
1 group
1
658 devlink_trap_stats_test
"Flow Sampling" "flow_action_sample" \
659 $MZ $h1 -c 1 -a own
-b $
(mac_get
$rp1) \
660 -A 192.0.2.1 -B 198.51.100.1 -t udp sp
=12345,dp
=54321 -p 100 -q
662 tc filter del dev
$rp1 ingress proto all pref
1 handle
101 matchall
663 tc qdisc del dev
$rp1 clsact
666 flow_action_trap_test
()
668 # Install a filter that traps a specific flow.
669 tc qdisc add dev
$rp1 clsact
670 tc filter add dev
$rp1 ingress proto ip pref
1 handle
101 flower \
671 skip_sw ip_proto udp src_port
12345 dst_port
54321 action
trap
673 devlink_trap_stats_test
"Flow Trapping (Logging)" "flow_action_trap" \
674 $MZ $h1 -c 1 -a own
-b $
(mac_get
$rp1) \
675 -A 192.0.2.1 -B 198.51.100.1 -t udp sp
=12345,dp
=54321 -p 100 -q
677 tc filter del dev
$rp1 ingress proto ip pref
1 handle
101 flower
678 tc qdisc del dev
$rp1 clsact