cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

devlink_trap_control.sh (18293B)


      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
     90source mlxsw_lib.sh
     91
     92h1_create()
     93{
     94	simple_if_init $h1 192.0.2.1/24 2001:db8:1::1/64
     95
     96	ip -4 route add default vrf v$h1 nexthop via 192.0.2.2
     97	ip -6 route add default vrf v$h1 nexthop via 2001:db8:1::2
     98}
     99
    100h1_destroy()
    101{
    102	ip -6 route del default vrf v$h1 nexthop via 2001:db8:1::2
    103	ip -4 route del default vrf v$h1 nexthop via 192.0.2.2
    104
    105	simple_if_fini $h1 192.0.2.1/24 2001:db8:1::1/64
    106}
    107
    108h2_create()
    109{
    110	simple_if_init $h2 198.51.100.1/24 2001:db8:2::1/64
    111
    112	ip -4 route add default vrf v$h2 nexthop via 198.51.100.2
    113	ip -6 route add default vrf v$h2 nexthop via 2001:db8:2::2
    114}
    115
    116h2_destroy()
    117{
    118	ip -6 route del default vrf v$h2 nexthop via 2001:db8:2::2
    119	ip -4 route del default vrf v$h2 nexthop via 198.51.100.2
    120
    121	simple_if_fini $h2 198.51.100.1/24 2001:db8:2::1/64
    122}
    123
    124router_create()
    125{
    126	ip link set dev $rp1 up
    127	ip link set dev $rp2 up
    128
    129	__addr_add_del $rp1 add 192.0.2.2/24 2001:db8:1::2/64
    130	__addr_add_del $rp2 add 198.51.100.2/24 2001:db8:2::2/64
    131}
    132
    133router_destroy()
    134{
    135	__addr_add_del $rp2 del 198.51.100.2/24 2001:db8:2::2/64
    136	__addr_add_del $rp1 del 192.0.2.2/24 2001:db8:1::2/64
    137
    138	ip link set dev $rp2 down
    139	ip link set dev $rp1 down
    140}
    141
    142setup_prepare()
    143{
    144	h1=${NETIFS[p1]}
    145	rp1=${NETIFS[p2]}
    146
    147	rp2=${NETIFS[p3]}
    148	h2=${NETIFS[p4]}
    149
    150	vrf_prepare
    151	forwarding_enable
    152
    153	h1_create
    154	h2_create
    155	router_create
    156}
    157
    158cleanup()
    159{
    160	pre_cleanup
    161
    162	router_destroy
    163	h2_destroy
    164	h1_destroy
    165
    166	forwarding_restore
    167	vrf_cleanup
    168}
    169
    170stp_test()
    171{
    172	devlink_trap_stats_test "STP" "stp" $MZ $h1 -c 1 -t bpdu -q
    173}
    174
    175lacp_payload_get()
    176{
    177	local source_mac=$1; shift
    178	local p
    179
    180	p=$(:
    181		)"01:80:C2:00:00:02:"$(       : ETH daddr
    182		)"$source_mac:"$(             : ETH saddr
    183		)"88:09:"$(                   : ETH type
    184		)
    185	echo $p
    186}
    187
    188lacp_test()
    189{
    190	local h1mac=$(mac_get $h1)
    191
    192	devlink_trap_stats_test "LACP" "lacp" $MZ $h1 -c 1 \
    193		$(lacp_payload_get $h1mac) -p 100 -q
    194}
    195
    196lldp_payload_get()
    197{
    198	local source_mac=$1; shift
    199	local p
    200
    201	p=$(:
    202		)"01:80:C2:00:00:0E:"$(       : ETH daddr
    203		)"$source_mac:"$(             : ETH saddr
    204		)"88:CC:"$(                   : ETH type
    205		)
    206	echo $p
    207}
    208
    209lldp_test()
    210{
    211	local h1mac=$(mac_get $h1)
    212
    213	devlink_trap_stats_test "LLDP" "lldp" $MZ $h1 -c 1 \
    214		$(lldp_payload_get $h1mac) -p 100 -q
    215}
    216
    217igmp_query_test()
    218{
    219	# IGMP (IP Protocol 2) Membership Query (Type 0x11)
    220	devlink_trap_stats_test "IGMP Membership Query" "igmp_query" \
    221		$MZ $h1 -c 1 -a own -b 01:00:5E:00:00:01 \
    222		-A 192.0.2.1 -B 224.0.0.1 -t ip proto=2,p=11 -p 100 -q
    223}
    224
    225igmp_v1_report_test()
    226{
    227	# IGMP (IP Protocol 2) Version 1 Membership Report (Type 0x12)
    228	devlink_trap_stats_test "IGMP Version 1 Membership Report" \
    229		"igmp_v1_report" $MZ $h1 -c 1 -a own -b 01:00:5E:00:00:01 \
    230		-A 192.0.2.1 -B 244.0.0.1 -t ip proto=2,p=12 -p 100 -q
    231}
    232
    233igmp_v2_report_test()
    234{
    235	# IGMP (IP Protocol 2) Version 2 Membership Report (Type 0x16)
    236	devlink_trap_stats_test "IGMP Version 2 Membership Report" \
    237		"igmp_v2_report" $MZ $h1 -c 1 -a own -b 01:00:5E:00:00:01 \
    238		-A 192.0.2.1 -B 244.0.0.1 -t ip proto=2,p=16 -p 100 -q
    239}
    240
    241igmp_v3_report_test()
    242{
    243	# IGMP (IP Protocol 2) Version 3 Membership Report (Type 0x22)
    244	devlink_trap_stats_test "IGMP Version 3 Membership Report" \
    245		"igmp_v3_report" $MZ $h1 -c 1 -a own -b 01:00:5E:00:00:01 \
    246		-A 192.0.2.1 -B 244.0.0.1 -t ip proto=2,p=22 -p 100 -q
    247}
    248
    249igmp_v2_leave_test()
    250{
    251	# IGMP (IP Protocol 2) Version 2 Leave Group (Type 0x17)
    252	devlink_trap_stats_test "IGMP Version 2 Leave Group" \
    253		"igmp_v2_leave" $MZ $h1 -c 1 -a own -b 01:00:5E:00:00:02 \
    254		-A 192.0.2.1 -B 224.0.0.2 -t ip proto=2,p=17 -p 100 -q
    255}
    256
    257mld_payload_get()
    258{
    259	local type=$1; shift
    260	local p
    261
    262	type=$(printf "%x" $type)
    263	p=$(:
    264		)"3A:"$(			: Next Header - ICMPv6
    265		)"00:"$(			: Hdr Ext Len
    266		)"00:00:00:00:00:00:"$(		: Options and Padding
    267		)"$type:"$(			: ICMPv6.type
    268		)"00:"$(			: ICMPv6.code
    269		)"00:"$(			: ICMPv6.checksum
    270		)
    271	echo $p
    272}
    273
    274mld_query_test()
    275{
    276	# MLD Multicast Listener Query (Type 130)
    277	devlink_trap_stats_test "MLD Multicast Listener Query" "mld_query" \
    278		$MZ $h1 -6 -c 1 -A fe80::1 -B ff02::1 \
    279		-t ip hop=1,next=0,payload=$(mld_payload_get 130) -p 100 -q
    280}
    281
    282mld_v1_report_test()
    283{
    284	# MLD Version 1 Multicast Listener Report (Type 131)
    285	devlink_trap_stats_test "MLD Version 1 Multicast Listener Report" \
    286		"mld_v1_report" $MZ $h1 -6 -c 1 -A fe80::1 -B ff02::16 \
    287		-t ip hop=1,next=0,payload=$(mld_payload_get 131) -p 100 -q
    288}
    289
    290mld_v2_report_test()
    291{
    292	# MLD Version 2 Multicast Listener Report (Type 143)
    293	devlink_trap_stats_test "MLD Version 2 Multicast Listener Report" \
    294		"mld_v2_report" $MZ $h1 -6 -c 1 -A fe80::1 -B ff02::16 \
    295		-t ip hop=1,next=0,payload=$(mld_payload_get 143) -p 100 -q
    296}
    297
    298mld_v1_done_test()
    299{
    300	# MLD Version 1 Multicast Listener Done (Type 132)
    301	devlink_trap_stats_test "MLD Version 1 Multicast Listener Done" \
    302		"mld_v1_done" $MZ $h1 -6 -c 1 -A fe80::1 -B ff02::16 \
    303		-t ip hop=1,next=0,payload=$(mld_payload_get 132) -p 100 -q
    304}
    305
    306ipv4_dhcp_test()
    307{
    308	devlink_trap_stats_test "IPv4 DHCP Port 67" "ipv4_dhcp" \
    309		$MZ $h1 -c 1 -a own -b bcast -A 0.0.0.0 -B 255.255.255.255 \
    310		-t udp sp=68,dp=67 -p 100 -q
    311
    312	devlink_trap_stats_test "IPv4 DHCP Port 68" "ipv4_dhcp" \
    313		$MZ $h1 -c 1 -a own -b $(mac_get $rp1) -A 192.0.2.1 \
    314		-B 255.255.255.255 -t udp sp=67,dp=68 -p 100 -q
    315}
    316
    317ipv6_dhcp_test()
    318{
    319	devlink_trap_stats_test "IPv6 DHCP Port 547" "ipv6_dhcp" \
    320		$MZ $h1 -6 -c 1 -A fe80::1 -B ff02::1:2 -t udp sp=546,dp=547 \
    321		-p 100 -q
    322
    323	devlink_trap_stats_test "IPv6 DHCP Port 546" "ipv6_dhcp" \
    324		$MZ $h1 -6 -c 1 -A fe80::1 -B ff02::1:2 -t udp sp=547,dp=546 \
    325		-p 100 -q
    326}
    327
    328arp_request_test()
    329{
    330	devlink_trap_stats_test "ARP Request" "arp_request" \
    331		$MZ $h1 -c 1 -a own -b bcast -t arp request -p 100 -q
    332}
    333
    334arp_response_test()
    335{
    336	devlink_trap_stats_test "ARP Response" "arp_response" \
    337		$MZ $h1 -c 1 -a own -b $(mac_get $rp1) -t arp reply -p 100 -q
    338}
    339
    340icmpv6_header_get()
    341{
    342	local type=$1; shift
    343	local p
    344
    345	type=$(printf "%x" $type)
    346	p=$(:
    347		)"$type:"$(			: ICMPv6.type
    348		)"00:"$(			: ICMPv6.code
    349		)"00:"$(			: ICMPv6.checksum
    350		)
    351	echo $p
    352}
    353
    354ipv6_neigh_solicit_test()
    355{
    356	devlink_trap_stats_test "IPv6 Neighbour Solicitation" \
    357		"ipv6_neigh_solicit" $MZ $h1 -6 -c 1 \
    358		-A fe80::1 -B ff02::1:ff00:02 \
    359		-t ip hop=1,next=58,payload=$(icmpv6_header_get 135) -p 100 -q
    360}
    361
    362ipv6_neigh_advert_test()
    363{
    364	devlink_trap_stats_test "IPv6 Neighbour Advertisement" \
    365		"ipv6_neigh_advert" $MZ $h1 -6 -c 1 -a own -b $(mac_get $rp1) \
    366		-A fe80::1 -B 2001:db8:1::2 \
    367		-t ip hop=1,next=58,payload=$(icmpv6_header_get 136) -p 100 -q
    368}
    369
    370ipv4_bfd_test()
    371{
    372	devlink_trap_stats_test "IPv4 BFD Control - Port 3784" "ipv4_bfd" \
    373		$MZ $h1 -c 1 -a own -b $(mac_get $rp1) \
    374		-A 192.0.2.1 -B 192.0.2.2 -t udp sp=49153,dp=3784 -p 100 -q
    375
    376	devlink_trap_stats_test "IPv4 BFD Echo - Port 3785" "ipv4_bfd" \
    377		$MZ $h1 -c 1 -a own -b $(mac_get $rp1) \
    378		-A 192.0.2.1 -B 192.0.2.2 -t udp sp=49153,dp=3785 -p 100 -q
    379}
    380
    381ipv6_bfd_test()
    382{
    383	devlink_trap_stats_test "IPv6 BFD Control - Port 3784" "ipv6_bfd" \
    384		$MZ $h1 -6 -c 1 -a own -b $(mac_get $rp1) \
    385		-A 2001:db8:1::1 -B 2001:db8:1::2 \
    386		-t udp sp=49153,dp=3784 -p 100 -q
    387
    388	devlink_trap_stats_test "IPv6 BFD Echo - Port 3785" "ipv6_bfd" \
    389		$MZ $h1 -6 -c 1 -a own -b $(mac_get $rp1) \
    390		-A 2001:db8:1::1 -B 2001:db8:1::2 \
    391		-t udp sp=49153,dp=3785 -p 100 -q
    392}
    393
    394ipv4_ospf_test()
    395{
    396	devlink_trap_stats_test "IPv4 OSPF - Multicast" "ipv4_ospf" \
    397		$MZ $h1 -c 1 -a own -b 01:00:5e:00:00:05 \
    398		-A 192.0.2.1 -B 224.0.0.5 -t ip proto=89 -p 100 -q
    399
    400	devlink_trap_stats_test "IPv4 OSPF - Unicast" "ipv4_ospf" \
    401		$MZ $h1 -c 1 -a own -b $(mac_get $rp1) \
    402		-A 192.0.2.1 -B 192.0.2.2 -t ip proto=89 -p 100 -q
    403}
    404
    405ipv6_ospf_test()
    406{
    407	devlink_trap_stats_test "IPv6 OSPF - Multicast" "ipv6_ospf" \
    408		$MZ $h1 -6 -c 1 -a own -b 33:33:00:00:00:05 \
    409		-A fe80::1 -B ff02::5 -t ip next=89 -p 100 -q
    410
    411	devlink_trap_stats_test "IPv6 OSPF - Unicast" "ipv6_ospf" \
    412		$MZ $h1 -6 -c 1 -a own -b $(mac_get $rp1) \
    413		-A 2001:db8:1::1 -B 2001:db8:1::2 -t ip next=89 -p 100 -q
    414}
    415
    416ipv4_bgp_test()
    417{
    418	devlink_trap_stats_test "IPv4 BGP" "ipv4_bgp" \
    419		$MZ $h1 -c 1 -a own -b $(mac_get $rp1) \
    420		-A 192.0.2.1 -B 192.0.2.2 -t tcp sp=54321,dp=179,flags=rst \
    421		-p 100 -q
    422}
    423
    424ipv6_bgp_test()
    425{
    426	devlink_trap_stats_test "IPv6 BGP" "ipv6_bgp" \
    427		$MZ $h1 -6 -c 1 -a own -b $(mac_get $rp1) \
    428		-A 2001:db8:1::1 -B 2001:db8:1::2 \
    429		-t tcp sp=54321,dp=179,flags=rst -p 100 -q
    430}
    431
    432ipv4_vrrp_test()
    433{
    434	devlink_trap_stats_test "IPv4 VRRP" "ipv4_vrrp" \
    435		$MZ $h1 -c 1 -a own -b 01:00:5e:00:00:12 \
    436		-A 192.0.2.1 -B 224.0.0.18 -t ip proto=112 -p 100 -q
    437}
    438
    439ipv6_vrrp_test()
    440{
    441	devlink_trap_stats_test "IPv6 VRRP" "ipv6_vrrp" \
    442		$MZ $h1 -6 -c 1 -a own -b 33:33:00:00:00:12 \
    443		-A fe80::1 -B ff02::12 -t ip next=112 -p 100 -q
    444}
    445
    446ipv4_pim_test()
    447{
    448	devlink_trap_stats_test "IPv4 PIM - Multicast" "ipv4_pim" \
    449		$MZ $h1 -c 1 -a own -b 01:00:5e:00:00:0d \
    450		-A 192.0.2.1 -B 224.0.0.13 -t ip proto=103 -p 100 -q
    451
    452	devlink_trap_stats_test "IPv4 PIM - Unicast" "ipv4_pim" \
    453		$MZ $h1 -c 1 -a own -b $(mac_get $rp1) \
    454		-A 192.0.2.1 -B 192.0.2.2 -t ip proto=103 -p 100 -q
    455}
    456
    457ipv6_pim_test()
    458{
    459	devlink_trap_stats_test "IPv6 PIM - Multicast" "ipv6_pim" \
    460		$MZ $h1 -6 -c 1 -a own -b 33:33:00:00:00:0d \
    461		-A fe80::1 -B ff02::d -t ip next=103 -p 100 -q
    462
    463	devlink_trap_stats_test "IPv6 PIM - Unicast" "ipv6_pim" \
    464		$MZ $h1 -6 -c 1 -a own -b $(mac_get $rp1) \
    465		-A fe80::1 -B 2001:db8:1::2 -t ip next=103 -p 100 -q
    466}
    467
    468uc_loopback_test()
    469{
    470	# Add neighbours to the fake destination IPs, so that the packets are
    471	# routed in the device and not trapped due to an unresolved neighbour
    472	# exception.
    473	ip -4 neigh add 192.0.2.3 lladdr 00:11:22:33:44:55 nud permanent \
    474		dev $rp1
    475	ip -6 neigh add 2001:db8:1::3 lladdr 00:11:22:33:44:55 nud permanent \
    476		dev $rp1
    477
    478	devlink_trap_stats_test "IPv4 Unicast Loopback" "uc_loopback" \
    479		$MZ $h1 -c 1 -a own -b $(mac_get $rp1) \
    480		-A 192.0.2.1 -B 192.0.2.3 -t udp sp=54321,dp=12345 -p 100 -q
    481
    482	devlink_trap_stats_test "IPv6 Unicast Loopback" "uc_loopback" \
    483		$MZ $h1 -6 -c 1 -a own -b $(mac_get $rp1) \
    484		-A 2001:db8:1::1 -B 2001:db8:1::3 -t udp sp=54321,dp=12345 \
    485		-p 100 -q
    486
    487	ip -6 neigh del 2001:db8:1::3 dev $rp1
    488	ip -4 neigh del 192.0.2.3 dev $rp1
    489}
    490
    491local_route_test()
    492{
    493	# Use a fake source IP to prevent the trap from being triggered twice
    494	# when the router sends back a port unreachable message.
    495	devlink_trap_stats_test "IPv4 Local Route" "local_route" \
    496		$MZ $h1 -c 1 -a own -b $(mac_get $rp1) \
    497		-A 192.0.2.3 -B 192.0.2.2 -t udp sp=54321,dp=12345 -p 100 -q
    498
    499	devlink_trap_stats_test "IPv6 Local Route" "local_route" \
    500		$MZ $h1 -6 -c 1 -a own -b $(mac_get $rp1) \
    501		-A 2001:db8:1::3 -B 2001:db8:1::2 -t udp sp=54321,sp=12345 \
    502		-p 100 -q
    503}
    504
    505external_route_test()
    506{
    507	# Add a dummy device through which the incoming packets should be
    508	# routed.
    509	ip link add name dummy10 up type dummy
    510	ip address add 203.0.113.1/24 dev dummy10
    511	ip -6 address add 2001:db8:10::1/64 dev dummy10
    512
    513	devlink_trap_stats_test "IPv4 External Route" "external_route" \
    514		$MZ $h1 -c 1 -a own -b $(mac_get $rp1) \
    515		-A 192.0.2.1 -B 203.0.113.2 -t udp sp=54321,dp=12345 -p 100 -q
    516
    517	devlink_trap_stats_test "IPv6 External Route" "external_route" \
    518		$MZ $h1 -6 -c 1 -a own -b $(mac_get $rp1) \
    519		-A 2001:db8:1::1 -B 2001:db8:10::2 -t udp sp=54321,sp=12345 \
    520		-p 100 -q
    521
    522	ip -6 address del 2001:db8:10::1/64 dev dummy10
    523	ip address del 203.0.113.1/24 dev dummy10
    524	ip link del dev dummy10
    525}
    526
    527ipv6_uc_dip_link_local_scope_test()
    528{
    529	# Add a dummy link-local prefix route to allow the packet to be routed.
    530	ip -6 route add fe80:1::/64 dev $rp2
    531
    532	devlink_trap_stats_test \
    533		"IPv6 Unicast Destination IP With Link-Local Scope" \
    534		"ipv6_uc_dip_link_local_scope" \
    535		$MZ $h1 -6 -c 1 -a own -b $(mac_get $rp1) \
    536		-A fe80::1 -B fe80:1::2 -t udp sp=54321,sp=12345 \
    537		-p 100 -q
    538
    539	ip -6 route del fe80:1::/64 dev $rp2
    540}
    541
    542ipv4_router_alert_get()
    543{
    544	local p
    545
    546	# https://en.wikipedia.org/wiki/IPv4#Options
    547	p=$(:
    548		)"94:"$(			: Option Number
    549		)"04:"$(			: Option Length
    550		)"00:00:"$(			: Option Data
    551		)
    552	echo $p
    553}
    554
    555ipv4_router_alert_test()
    556{
    557	devlink_trap_stats_test "IPv4 Router Alert" "ipv4_router_alert" \
    558		$MZ $h1 -c 1 -a own -b $(mac_get $rp1) \
    559		-A 192.0.2.1 -B 198.51.100.3 \
    560		-t ip option=$(ipv4_router_alert_get) -p 100 -q
    561}
    562
    563ipv6_router_alert_get()
    564{
    565	local p
    566
    567	# https://en.wikipedia.org/wiki/IPv6_packet#Hop-by-hop_options_and_destination_options
    568	# https://tools.ietf.org/html/rfc2711#section-2.1
    569	p=$(:
    570		)"11:"$(			: Next Header - UDP
    571		)"00:"$(			: Hdr Ext Len
    572		)"05:02:00:00:00:00:"$(		: Option Data
    573		)
    574	echo $p
    575}
    576
    577ipv6_router_alert_test()
    578{
    579	devlink_trap_stats_test "IPv6 Router Alert" "ipv6_router_alert" \
    580		$MZ $h1 -6 -c 1 -a own -b $(mac_get $rp1) \
    581		-A 2001:db8:1::1 -B 2001:db8:1::3 \
    582		-t ip next=0,payload=$(ipv6_router_alert_get) -p 100 -q
    583}
    584
    585ipv6_dip_all_nodes_test()
    586{
    587	devlink_trap_stats_test "IPv6 Destination IP \"All Nodes Address\"" \
    588		"ipv6_dip_all_nodes" \
    589		$MZ $h1 -6 -c 1 -a own -b 33:33:00:00:00:01 \
    590		-A 2001:db8:1::1 -B ff02::1 -t udp sp=12345,dp=54321 -p 100 -q
    591}
    592
    593ipv6_dip_all_routers_test()
    594{
    595	devlink_trap_stats_test "IPv6 Destination IP \"All Routers Address\"" \
    596		"ipv6_dip_all_routers" \
    597		$MZ $h1 -6 -c 1 -a own -b 33:33:00:00:00:02 \
    598		-A 2001:db8:1::1 -B ff02::2 -t udp sp=12345,dp=54321 -p 100 -q
    599}
    600
    601ipv6_router_solicit_test()
    602{
    603	devlink_trap_stats_test "IPv6 Router Solicitation" \
    604		"ipv6_router_solicit" \
    605		$MZ $h1 -6 -c 1 -a own -b 33:33:00:00:00:02 \
    606		-A fe80::1 -B ff02::2 \
    607		-t ip hop=1,next=58,payload=$(icmpv6_header_get 133) -p 100 -q
    608}
    609
    610ipv6_router_advert_test()
    611{
    612	devlink_trap_stats_test "IPv6 Router Advertisement" \
    613		"ipv6_router_advert" \
    614		$MZ $h1 -6 -c 1 -a own -b 33:33:00:00:00:01 \
    615		-A fe80::1 -B ff02::1 \
    616		-t ip hop=1,next=58,payload=$(icmpv6_header_get 134) -p 100 -q
    617}
    618
    619ipv6_redirect_test()
    620{
    621	devlink_trap_stats_test "IPv6 Redirect Message" \
    622		"ipv6_redirect" \
    623		$MZ $h1 -6 -c 1 -a own -b $(mac_get $rp1) \
    624		-A fe80::1 -B 2001:db8:1::2 \
    625		-t ip hop=1,next=58,payload=$(icmpv6_header_get 137) -p 100 -q
    626}
    627
    628ptp_event_test()
    629{
    630	mlxsw_only_on_spectrum 1 || 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	mlxsw_only_on_spectrum 1 || return
    642
    643	# PTP Announce (b)
    644	devlink_trap_stats_test "PTP General Message" "ptp_general" \
    645		$MZ $h1 -c 1 -a own -b 01:00:5e:00:01:81 \
    646		-A 192.0.2.1 -B 224.0.1.129 \
    647		-t udp sp=12345,dp=320,payload=1b -p 100 -q
    648}
    649
    650flow_action_sample_test()
    651{
    652	# Install a filter that samples every incoming packet.
    653	tc qdisc add dev $rp1 clsact
    654	tc filter add dev $rp1 ingress proto all pref 1 handle 101 matchall \
    655		skip_sw action sample rate 1 group 1
    656
    657	devlink_trap_stats_test "Flow Sampling" "flow_action_sample" \
    658		$MZ $h1 -c 1 -a own -b $(mac_get $rp1) \
    659		-A 192.0.2.1 -B 198.51.100.1 -t udp sp=12345,dp=54321 -p 100 -q
    660
    661	tc filter del dev $rp1 ingress proto all pref 1 handle 101 matchall
    662	tc qdisc del dev $rp1 clsact
    663}
    664
    665flow_action_trap_test()
    666{
    667	# Install a filter that traps a specific flow.
    668	tc qdisc add dev $rp1 clsact
    669	tc filter add dev $rp1 ingress proto ip pref 1 handle 101 flower \
    670		skip_sw ip_proto udp src_port 12345 dst_port 54321 action trap
    671
    672	devlink_trap_stats_test "Flow Trapping (Logging)" "flow_action_trap" \
    673		$MZ $h1 -c 1 -a own -b $(mac_get $rp1) \
    674		-A 192.0.2.1 -B 198.51.100.1 -t udp sp=12345,dp=54321 -p 100 -q
    675
    676	tc filter del dev $rp1 ingress proto ip pref 1 handle 101 flower
    677	tc qdisc del dev $rp1 clsact
    678}
    679
    680trap cleanup EXIT
    681
    682setup_prepare
    683setup_wait
    684
    685tests_run
    686
    687exit $EXIT_STATUS