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