1#!/bin/bash 2# SPDX-License-Identifier: GPL-2.0 3# 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 6# conditions. 7# 8# +---------------------------------+ 9# | H1 (vrf) | 10# | + $h1 | 11# | | 192.0.2.1/24 | 12# | | 2001:db8:1::1/64 | 13# | | | 14# | | default via 192.0.2.2 | 15# | | default via 2001:db8:1::2 | 16# +----|----------------------------+ 17# | 18# +----|----------------------------------------------------------------------+ 19# | SW | | 20# | + $rp1 | 21# | 192.0.2.2/24 | 22# | 2001:db8:1::2/64 | 23# | | 24# | 2001:db8:2::2/64 | 25# | 198.51.100.2/24 | 26# | + $rp2 | 27# | | | 28# +----|----------------------------------------------------------------------+ 29# | 30# +----|----------------------------+ 31# | | default via 198.51.100.2 | 32# | | default via 2001:db8:2::2 | 33# | | | 34# | | 2001:db8:2::1/64 | 35# | | 198.51.100.1/24 | 36# | + $h2 | 37# | H2 (vrf) | 38# +---------------------------------+ 39 40lib_dir=$(dirname $0)/../../../net/forwarding 41 42ALL_TESTS=" 43 stp_test 44 lacp_test 45 lldp_test 46 igmp_query_test 47 igmp_v1_report_test 48 igmp_v2_report_test 49 igmp_v3_report_test 50 igmp_v2_leave_test 51 mld_query_test 52 mld_v1_report_test 53 mld_v2_report_test 54 mld_v1_done_test 55 ipv4_dhcp_test 56 ipv6_dhcp_test 57 arp_request_test 58 arp_response_test 59 ipv6_neigh_solicit_test 60 ipv6_neigh_advert_test 61 ipv4_bfd_test 62 ipv6_bfd_test 63 ipv4_ospf_test 64 ipv6_ospf_test 65 ipv4_bgp_test 66 ipv6_bgp_test 67 ipv4_vrrp_test 68 ipv6_vrrp_test 69 ipv4_pim_test 70 ipv6_pim_test 71 uc_loopback_test 72 local_route_test 73 external_route_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 81 ipv6_redirect_test 82 ptp_event_test 83 ptp_general_test 84 flow_action_sample_test 85 flow_action_trap_test 86" 87NUM_NETIFS=4 88source $lib_dir/lib.sh 89source $lib_dir/devlink_lib.sh 90 91h1_create() 92{ 93 simple_if_init $h1 192.0.2.1/24 2001:db8:1::1/64 94 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 97} 98 99h1_destroy() 100{ 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 103 104 simple_if_fini $h1 192.0.2.1/24 2001:db8:1::1/64 105} 106 107h2_create() 108{ 109 simple_if_init $h2 198.51.100.1/24 2001:db8:2::1/64 110 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 113} 114 115h2_destroy() 116{ 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 119 120 simple_if_fini $h2 198.51.100.1/24 2001:db8:2::1/64 121} 122 123router_create() 124{ 125 ip link set dev $rp1 up 126 ip link set dev $rp2 up 127 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 130} 131 132router_destroy() 133{ 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 136 137 ip link set dev $rp2 down 138 ip link set dev $rp1 down 139} 140 141setup_prepare() 142{ 143 h1=${NETIFS[p1]} 144 rp1=${NETIFS[p2]} 145 146 rp2=${NETIFS[p3]} 147 h2=${NETIFS[p4]} 148 149 vrf_prepare 150 forwarding_enable 151 152 h1_create 153 h2_create 154 router_create 155} 156 157cleanup() 158{ 159 pre_cleanup 160 161 router_destroy 162 h2_destroy 163 h1_destroy 164 165 forwarding_restore 166 vrf_cleanup 167} 168 169stp_test() 170{ 171 devlink_trap_stats_test "STP" "stp" $MZ $h1 -c 1 -t bpdu -q 172} 173 174lacp_payload_get() 175{ 176 local source_mac=$1; shift 177 local p 178 179 p=$(: 180 )"01:80:C2:00:00:02:"$( : ETH daddr 181 )"$source_mac:"$( : ETH saddr 182 )"88:09:"$( : ETH type 183 ) 184 echo $p 185} 186 187lacp_test() 188{ 189 local h1mac=$(mac_get $h1) 190 191 devlink_trap_stats_test "LACP" "lacp" $MZ $h1 -c 1 \ 192 $(lacp_payload_get $h1mac) -p 100 -q 193} 194 195lldp_payload_get() 196{ 197 local source_mac=$1; shift 198 local p 199 200 p=$(: 201 )"01:80:C2:00:00:0E:"$( : ETH daddr 202 )"$source_mac:"$( : ETH saddr 203 )"88:CC:"$( : ETH type 204 ) 205 echo $p 206} 207 208lldp_test() 209{ 210 local h1mac=$(mac_get $h1) 211 212 devlink_trap_stats_test "LLDP" "lldp" $MZ $h1 -c 1 \ 213 $(lldp_payload_get $h1mac) -p 100 -q 214} 215 216igmp_query_test() 217{ 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 222} 223 224igmp_v1_report_test() 225{ 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 230} 231 232igmp_v2_report_test() 233{ 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 238} 239 240igmp_v3_report_test() 241{ 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 246} 247 248igmp_v2_leave_test() 249{ 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 254} 255 256mld_payload_get() 257{ 258 local type=$1; shift 259 local p 260 261 type=$(printf "%x" $type) 262 p=$(: 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 269 ) 270 echo $p 271} 272 273mld_query_test() 274{ 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 279} 280 281mld_v1_report_test() 282{ 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 287} 288 289mld_v2_report_test() 290{ 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 295} 296 297mld_v1_done_test() 298{ 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 303} 304 305ipv4_dhcp_test() 306{ 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 310 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 314} 315 316ipv6_dhcp_test() 317{ 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 \ 320 -p 100 -q 321 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 \ 324 -p 100 -q 325} 326 327arp_request_test() 328{ 329 devlink_trap_stats_test "ARP Request" "arp_request" \ 330 $MZ $h1 -c 1 -a own -b bcast -t arp request -p 100 -q 331} 332 333arp_response_test() 334{ 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 337} 338 339icmpv6_header_get() 340{ 341 local type=$1; shift 342 local p 343 344 type=$(printf "%x" $type) 345 p=$(: 346 )"$type:"$( : ICMPv6.type 347 )"00:"$( : ICMPv6.code 348 )"00:"$( : ICMPv6.checksum 349 ) 350 echo $p 351} 352 353ipv6_neigh_solicit_test() 354{ 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 359} 360 361ipv6_neigh_advert_test() 362{ 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 367} 368 369ipv4_bfd_test() 370{ 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 374 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 378} 379 380ipv6_bfd_test() 381{ 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 386 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 391} 392 393ipv4_ospf_test() 394{ 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 398 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 402} 403 404ipv6_ospf_test() 405{ 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 409 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 413} 414 415ipv4_bgp_test() 416{ 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 \ 420 -p 100 -q 421} 422 423ipv6_bgp_test() 424{ 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 429} 430 431ipv4_vrrp_test() 432{ 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 436} 437 438ipv6_vrrp_test() 439{ 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 443} 444 445ipv4_pim_test() 446{ 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 450 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 454} 455 456ipv6_pim_test() 457{ 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 461 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 465} 466 467uc_loopback_test() 468{ 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 471 # exception. 472 ip -4 neigh add 192.0.2.3 lladdr 00:11:22:33:44:55 nud permanent \ 473 dev $rp1 474 ip -6 neigh add 2001:db8:1::3 lladdr 00:11:22:33:44:55 nud permanent \ 475 dev $rp1 476 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 480 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 \ 484 -p 100 -q 485 486 ip -6 neigh del 2001:db8:1::3 dev $rp1 487 ip -4 neigh del 192.0.2.3 dev $rp1 488} 489 490local_route_test() 491{ 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 497 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 \ 501 -p 100 -q 502} 503 504external_route_test() 505{ 506 # Add a dummy device through which the incoming packets should be 507 # routed. 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 511 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 515 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 \ 519 -p 100 -q 520 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 524} 525 526ipv6_uc_dip_link_local_scope_test() 527{ 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 530 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 \ 536 -p 100 -q 537 538 ip -6 route del fe80:1::/64 dev $rp2 539} 540 541ipv4_router_alert_get() 542{ 543 local p 544 545 # https://en.wikipedia.org/wiki/IPv4#Options 546 p=$(: 547 )"94:"$( : Option Number 548 )"04:"$( : Option Length 549 )"00:00:"$( : Option Data 550 ) 551 echo $p 552} 553 554ipv4_router_alert_test() 555{ 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 560} 561 562ipv6_router_alert_get() 563{ 564 local p 565 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 568 p=$(: 569 )"11:"$( : Next Header - UDP 570 )"00:"$( : Hdr Ext Len 571 )"05:02:00:00:00:00:"$( : Option Data 572 ) 573 echo $p 574} 575 576ipv6_router_alert_test() 577{ 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 582} 583 584ipv6_dip_all_nodes_test() 585{ 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 590} 591 592ipv6_dip_all_routers_test() 593{ 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 598} 599 600ipv6_router_solicit_test() 601{ 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 607} 608 609ipv6_router_advert_test() 610{ 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 616} 617 618ipv6_redirect_test() 619{ 620 devlink_trap_stats_test "IPv6 Redirect Message" \ 621 "ipv6_redirect" \ 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 625} 626 627ptp_event_test() 628{ 629 # PTP is only supported on Spectrum-1, for now. 630 [[ "$DEVLINK_VIDDID" != "15b3:cb84" ]] && return 631 632 # PTP Sync (0) 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 637} 638 639ptp_general_test() 640{ 641 # PTP is only supported on Spectrum-1, for now. 642 [[ "$DEVLINK_VIDDID" != "15b3:cb84" ]] && return 643 644 # PTP Announce (b) 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 649} 650 651flow_action_sample_test() 652{ 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 657 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 661 662 tc filter del dev $rp1 ingress proto all pref 1 handle 101 matchall 663 tc qdisc del dev $rp1 clsact 664} 665 666flow_action_trap_test() 667{ 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 672 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 676 677 tc filter del dev $rp1 ingress proto ip pref 1 handle 101 flower 678 tc qdisc del dev $rp1 clsact 679} 680 681trap cleanup EXIT 682 683setup_prepare 684setup_wait 685 686tests_run 687 688exit $EXIT_STATUS 689