xref: /OK3568_Linux_fs/kernel/Documentation/networking/devlink/devlink-trap.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun.. SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun
3*4882a593Smuzhiyun============
4*4882a593SmuzhiyunDevlink Trap
5*4882a593Smuzhiyun============
6*4882a593Smuzhiyun
7*4882a593SmuzhiyunBackground
8*4882a593Smuzhiyun==========
9*4882a593Smuzhiyun
10*4882a593SmuzhiyunDevices capable of offloading the kernel's datapath and perform functions such
11*4882a593Smuzhiyunas bridging and routing must also be able to send specific packets to the
12*4882a593Smuzhiyunkernel (i.e., the CPU) for processing.
13*4882a593Smuzhiyun
14*4882a593SmuzhiyunFor example, a device acting as a multicast-aware bridge must be able to send
15*4882a593SmuzhiyunIGMP membership reports to the kernel for processing by the bridge module.
16*4882a593SmuzhiyunWithout processing such packets, the bridge module could never populate its
17*4882a593SmuzhiyunMDB.
18*4882a593Smuzhiyun
19*4882a593SmuzhiyunAs another example, consider a device acting as router which has received an IP
20*4882a593Smuzhiyunpacket with a TTL of 1. Upon routing the packet the device must send it to the
21*4882a593Smuzhiyunkernel so that it will route it as well and generate an ICMP Time Exceeded
22*4882a593Smuzhiyunerror datagram. Without letting the kernel route such packets itself, utilities
23*4882a593Smuzhiyunsuch as ``traceroute`` could never work.
24*4882a593Smuzhiyun
25*4882a593SmuzhiyunThe fundamental ability of sending certain packets to the kernel for processing
26*4882a593Smuzhiyunis called "packet trapping".
27*4882a593Smuzhiyun
28*4882a593SmuzhiyunOverview
29*4882a593Smuzhiyun========
30*4882a593Smuzhiyun
31*4882a593SmuzhiyunThe ``devlink-trap`` mechanism allows capable device drivers to register their
32*4882a593Smuzhiyunsupported packet traps with ``devlink`` and report trapped packets to
33*4882a593Smuzhiyun``devlink`` for further analysis.
34*4882a593Smuzhiyun
35*4882a593SmuzhiyunUpon receiving trapped packets, ``devlink`` will perform a per-trap packets and
36*4882a593Smuzhiyunbytes accounting and potentially report the packet to user space via a netlink
37*4882a593Smuzhiyunevent along with all the provided metadata (e.g., trap reason, timestamp, input
38*4882a593Smuzhiyunport). This is especially useful for drop traps (see :ref:`Trap-Types`)
39*4882a593Smuzhiyunas it allows users to obtain further visibility into packet drops that would
40*4882a593Smuzhiyunotherwise be invisible.
41*4882a593Smuzhiyun
42*4882a593SmuzhiyunThe following diagram provides a general overview of ``devlink-trap``::
43*4882a593Smuzhiyun
44*4882a593Smuzhiyun                                    Netlink event: Packet w/ metadata
45*4882a593Smuzhiyun                                                   Or a summary of recent drops
46*4882a593Smuzhiyun                                  ^
47*4882a593Smuzhiyun                                  |
48*4882a593Smuzhiyun         Userspace                |
49*4882a593Smuzhiyun        +---------------------------------------------------+
50*4882a593Smuzhiyun         Kernel                   |
51*4882a593Smuzhiyun                                  |
52*4882a593Smuzhiyun                          +-------+--------+
53*4882a593Smuzhiyun                          |                |
54*4882a593Smuzhiyun                          |  drop_monitor  |
55*4882a593Smuzhiyun                          |                |
56*4882a593Smuzhiyun                          +-------^--------+
57*4882a593Smuzhiyun                                  |
58*4882a593Smuzhiyun                                  | Non-control traps
59*4882a593Smuzhiyun                                  |
60*4882a593Smuzhiyun                             +----+----+
61*4882a593Smuzhiyun                             |         |      Kernel's Rx path
62*4882a593Smuzhiyun                             | devlink |      (non-drop traps)
63*4882a593Smuzhiyun                             |         |
64*4882a593Smuzhiyun                             +----^----+      ^
65*4882a593Smuzhiyun                                  |           |
66*4882a593Smuzhiyun                                  +-----------+
67*4882a593Smuzhiyun                                  |
68*4882a593Smuzhiyun                          +-------+-------+
69*4882a593Smuzhiyun                          |               |
70*4882a593Smuzhiyun                          | Device driver |
71*4882a593Smuzhiyun                          |               |
72*4882a593Smuzhiyun                          +-------^-------+
73*4882a593Smuzhiyun         Kernel                   |
74*4882a593Smuzhiyun        +---------------------------------------------------+
75*4882a593Smuzhiyun         Hardware                 |
76*4882a593Smuzhiyun                                  | Trapped packet
77*4882a593Smuzhiyun                                  |
78*4882a593Smuzhiyun                               +--+---+
79*4882a593Smuzhiyun                               |      |
80*4882a593Smuzhiyun                               | ASIC |
81*4882a593Smuzhiyun                               |      |
82*4882a593Smuzhiyun                               +------+
83*4882a593Smuzhiyun
84*4882a593Smuzhiyun.. _Trap-Types:
85*4882a593Smuzhiyun
86*4882a593SmuzhiyunTrap Types
87*4882a593Smuzhiyun==========
88*4882a593Smuzhiyun
89*4882a593SmuzhiyunThe ``devlink-trap`` mechanism supports the following packet trap types:
90*4882a593Smuzhiyun
91*4882a593Smuzhiyun  * ``drop``: Trapped packets were dropped by the underlying device. Packets
92*4882a593Smuzhiyun    are only processed by ``devlink`` and not injected to the kernel's Rx path.
93*4882a593Smuzhiyun    The trap action (see :ref:`Trap-Actions`) can be changed.
94*4882a593Smuzhiyun  * ``exception``: Trapped packets were not forwarded as intended by the
95*4882a593Smuzhiyun    underlying device due to an exception (e.g., TTL error, missing neighbour
96*4882a593Smuzhiyun    entry) and trapped to the control plane for resolution. Packets are
97*4882a593Smuzhiyun    processed by ``devlink`` and injected to the kernel's Rx path. Changing the
98*4882a593Smuzhiyun    action of such traps is not allowed, as it can easily break the control
99*4882a593Smuzhiyun    plane.
100*4882a593Smuzhiyun  * ``control``: Trapped packets were trapped by the device because these are
101*4882a593Smuzhiyun    control packets required for the correct functioning of the control plane.
102*4882a593Smuzhiyun    For example, ARP request and IGMP query packets. Packets are injected to
103*4882a593Smuzhiyun    the kernel's Rx path, but not reported to the kernel's drop monitor.
104*4882a593Smuzhiyun    Changing the action of such traps is not allowed, as it can easily break
105*4882a593Smuzhiyun    the control plane.
106*4882a593Smuzhiyun
107*4882a593Smuzhiyun.. _Trap-Actions:
108*4882a593Smuzhiyun
109*4882a593SmuzhiyunTrap Actions
110*4882a593Smuzhiyun============
111*4882a593Smuzhiyun
112*4882a593SmuzhiyunThe ``devlink-trap`` mechanism supports the following packet trap actions:
113*4882a593Smuzhiyun
114*4882a593Smuzhiyun  * ``trap``: The sole copy of the packet is sent to the CPU.
115*4882a593Smuzhiyun  * ``drop``: The packet is dropped by the underlying device and a copy is not
116*4882a593Smuzhiyun    sent to the CPU.
117*4882a593Smuzhiyun  * ``mirror``: The packet is forwarded by the underlying device and a copy is
118*4882a593Smuzhiyun    sent to the CPU.
119*4882a593Smuzhiyun
120*4882a593SmuzhiyunGeneric Packet Traps
121*4882a593Smuzhiyun====================
122*4882a593Smuzhiyun
123*4882a593SmuzhiyunGeneric packet traps are used to describe traps that trap well-defined packets
124*4882a593Smuzhiyunor packets that are trapped due to well-defined conditions (e.g., TTL error).
125*4882a593SmuzhiyunSuch traps can be shared by multiple device drivers and their description must
126*4882a593Smuzhiyunbe added to the following table:
127*4882a593Smuzhiyun
128*4882a593Smuzhiyun.. list-table:: List of Generic Packet Traps
129*4882a593Smuzhiyun   :widths: 5 5 90
130*4882a593Smuzhiyun
131*4882a593Smuzhiyun   * - Name
132*4882a593Smuzhiyun     - Type
133*4882a593Smuzhiyun     - Description
134*4882a593Smuzhiyun   * - ``source_mac_is_multicast``
135*4882a593Smuzhiyun     - ``drop``
136*4882a593Smuzhiyun     - Traps incoming packets that the device decided to drop because of a
137*4882a593Smuzhiyun       multicast source MAC
138*4882a593Smuzhiyun   * - ``vlan_tag_mismatch``
139*4882a593Smuzhiyun     - ``drop``
140*4882a593Smuzhiyun     - Traps incoming packets that the device decided to drop in case of VLAN
141*4882a593Smuzhiyun       tag mismatch: The ingress bridge port is not configured with a PVID and
142*4882a593Smuzhiyun       the packet is untagged or prio-tagged
143*4882a593Smuzhiyun   * - ``ingress_vlan_filter``
144*4882a593Smuzhiyun     - ``drop``
145*4882a593Smuzhiyun     - Traps incoming packets that the device decided to drop in case they are
146*4882a593Smuzhiyun       tagged with a VLAN that is not configured on the ingress bridge port
147*4882a593Smuzhiyun   * - ``ingress_spanning_tree_filter``
148*4882a593Smuzhiyun     - ``drop``
149*4882a593Smuzhiyun     - Traps incoming packets that the device decided to drop in case the STP
150*4882a593Smuzhiyun       state of the ingress bridge port is not "forwarding"
151*4882a593Smuzhiyun   * - ``port_list_is_empty``
152*4882a593Smuzhiyun     - ``drop``
153*4882a593Smuzhiyun     - Traps packets that the device decided to drop in case they need to be
154*4882a593Smuzhiyun       flooded (e.g., unknown unicast, unregistered multicast) and there are
155*4882a593Smuzhiyun       no ports the packets should be flooded to
156*4882a593Smuzhiyun   * - ``port_loopback_filter``
157*4882a593Smuzhiyun     - ``drop``
158*4882a593Smuzhiyun     - Traps packets that the device decided to drop in case after layer 2
159*4882a593Smuzhiyun       forwarding the only port from which they should be transmitted through
160*4882a593Smuzhiyun       is the port from which they were received
161*4882a593Smuzhiyun   * - ``blackhole_route``
162*4882a593Smuzhiyun     - ``drop``
163*4882a593Smuzhiyun     - Traps packets that the device decided to drop in case they hit a
164*4882a593Smuzhiyun       blackhole route
165*4882a593Smuzhiyun   * - ``ttl_value_is_too_small``
166*4882a593Smuzhiyun     - ``exception``
167*4882a593Smuzhiyun     - Traps unicast packets that should be forwarded by the device whose TTL
168*4882a593Smuzhiyun       was decremented to 0 or less
169*4882a593Smuzhiyun   * - ``tail_drop``
170*4882a593Smuzhiyun     - ``drop``
171*4882a593Smuzhiyun     - Traps packets that the device decided to drop because they could not be
172*4882a593Smuzhiyun       enqueued to a transmission queue which is full
173*4882a593Smuzhiyun   * - ``non_ip``
174*4882a593Smuzhiyun     - ``drop``
175*4882a593Smuzhiyun     - Traps packets that the device decided to drop because they need to
176*4882a593Smuzhiyun       undergo a layer 3 lookup, but are not IP or MPLS packets
177*4882a593Smuzhiyun   * - ``uc_dip_over_mc_dmac``
178*4882a593Smuzhiyun     - ``drop``
179*4882a593Smuzhiyun     - Traps packets that the device decided to drop because they need to be
180*4882a593Smuzhiyun       routed and they have a unicast destination IP and a multicast destination
181*4882a593Smuzhiyun       MAC
182*4882a593Smuzhiyun   * - ``dip_is_loopback_address``
183*4882a593Smuzhiyun     - ``drop``
184*4882a593Smuzhiyun     - Traps packets that the device decided to drop because they need to be
185*4882a593Smuzhiyun       routed and their destination IP is the loopback address (i.e., 127.0.0.0/8
186*4882a593Smuzhiyun       and ::1/128)
187*4882a593Smuzhiyun   * - ``sip_is_mc``
188*4882a593Smuzhiyun     - ``drop``
189*4882a593Smuzhiyun     - Traps packets that the device decided to drop because they need to be
190*4882a593Smuzhiyun       routed and their source IP is multicast (i.e., 224.0.0.0/8 and ff::/8)
191*4882a593Smuzhiyun   * - ``sip_is_loopback_address``
192*4882a593Smuzhiyun     - ``drop``
193*4882a593Smuzhiyun     - Traps packets that the device decided to drop because they need to be
194*4882a593Smuzhiyun       routed and their source IP is the loopback address (i.e., 127.0.0.0/8 and ::1/128)
195*4882a593Smuzhiyun   * - ``ip_header_corrupted``
196*4882a593Smuzhiyun     - ``drop``
197*4882a593Smuzhiyun     - Traps packets that the device decided to drop because they need to be
198*4882a593Smuzhiyun       routed and their IP header is corrupted: wrong checksum, wrong IP version
199*4882a593Smuzhiyun       or too short Internet Header Length (IHL)
200*4882a593Smuzhiyun   * - ``ipv4_sip_is_limited_bc``
201*4882a593Smuzhiyun     - ``drop``
202*4882a593Smuzhiyun     - Traps packets that the device decided to drop because they need to be
203*4882a593Smuzhiyun       routed and their source IP is limited broadcast (i.e., 255.255.255.255/32)
204*4882a593Smuzhiyun   * - ``ipv6_mc_dip_reserved_scope``
205*4882a593Smuzhiyun     - ``drop``
206*4882a593Smuzhiyun     - Traps IPv6 packets that the device decided to drop because they need to
207*4882a593Smuzhiyun       be routed and their IPv6 multicast destination IP has a reserved scope
208*4882a593Smuzhiyun       (i.e., ffx0::/16)
209*4882a593Smuzhiyun   * - ``ipv6_mc_dip_interface_local_scope``
210*4882a593Smuzhiyun     - ``drop``
211*4882a593Smuzhiyun     - Traps IPv6 packets that the device decided to drop because they need to
212*4882a593Smuzhiyun       be routed and their IPv6 multicast destination IP has an interface-local scope
213*4882a593Smuzhiyun       (i.e., ffx1::/16)
214*4882a593Smuzhiyun   * - ``mtu_value_is_too_small``
215*4882a593Smuzhiyun     - ``exception``
216*4882a593Smuzhiyun     - Traps packets that should have been routed by the device, but were bigger
217*4882a593Smuzhiyun       than the MTU of the egress interface
218*4882a593Smuzhiyun   * - ``unresolved_neigh``
219*4882a593Smuzhiyun     - ``exception``
220*4882a593Smuzhiyun     - Traps packets that did not have a matching IP neighbour after routing
221*4882a593Smuzhiyun   * - ``mc_reverse_path_forwarding``
222*4882a593Smuzhiyun     - ``exception``
223*4882a593Smuzhiyun     - Traps multicast IP packets that failed reverse-path forwarding (RPF)
224*4882a593Smuzhiyun       check during multicast routing
225*4882a593Smuzhiyun   * - ``reject_route``
226*4882a593Smuzhiyun     - ``exception``
227*4882a593Smuzhiyun     - Traps packets that hit reject routes (i.e., "unreachable", "prohibit")
228*4882a593Smuzhiyun   * - ``ipv4_lpm_miss``
229*4882a593Smuzhiyun     - ``exception``
230*4882a593Smuzhiyun     - Traps unicast IPv4 packets that did not match any route
231*4882a593Smuzhiyun   * - ``ipv6_lpm_miss``
232*4882a593Smuzhiyun     - ``exception``
233*4882a593Smuzhiyun     - Traps unicast IPv6 packets that did not match any route
234*4882a593Smuzhiyun   * - ``non_routable_packet``
235*4882a593Smuzhiyun     - ``drop``
236*4882a593Smuzhiyun     - Traps packets that the device decided to drop because they are not
237*4882a593Smuzhiyun       supposed to be routed. For example, IGMP queries can be flooded by the
238*4882a593Smuzhiyun       device in layer 2 and reach the router. Such packets should not be
239*4882a593Smuzhiyun       routed and instead dropped
240*4882a593Smuzhiyun   * - ``decap_error``
241*4882a593Smuzhiyun     - ``exception``
242*4882a593Smuzhiyun     - Traps NVE and IPinIP packets that the device decided to drop because of
243*4882a593Smuzhiyun       failure during decapsulation (e.g., packet being too short, reserved
244*4882a593Smuzhiyun       bits set in VXLAN header)
245*4882a593Smuzhiyun   * - ``overlay_smac_is_mc``
246*4882a593Smuzhiyun     - ``drop``
247*4882a593Smuzhiyun     - Traps NVE packets that the device decided to drop because their overlay
248*4882a593Smuzhiyun       source MAC is multicast
249*4882a593Smuzhiyun   * - ``ingress_flow_action_drop``
250*4882a593Smuzhiyun     - ``drop``
251*4882a593Smuzhiyun     - Traps packets dropped during processing of ingress flow action drop
252*4882a593Smuzhiyun   * - ``egress_flow_action_drop``
253*4882a593Smuzhiyun     - ``drop``
254*4882a593Smuzhiyun     - Traps packets dropped during processing of egress flow action drop
255*4882a593Smuzhiyun   * - ``stp``
256*4882a593Smuzhiyun     - ``control``
257*4882a593Smuzhiyun     - Traps STP packets
258*4882a593Smuzhiyun   * - ``lacp``
259*4882a593Smuzhiyun     - ``control``
260*4882a593Smuzhiyun     - Traps LACP packets
261*4882a593Smuzhiyun   * - ``lldp``
262*4882a593Smuzhiyun     - ``control``
263*4882a593Smuzhiyun     - Traps LLDP packets
264*4882a593Smuzhiyun   * - ``igmp_query``
265*4882a593Smuzhiyun     - ``control``
266*4882a593Smuzhiyun     - Traps IGMP Membership Query packets
267*4882a593Smuzhiyun   * - ``igmp_v1_report``
268*4882a593Smuzhiyun     - ``control``
269*4882a593Smuzhiyun     - Traps IGMP Version 1 Membership Report packets
270*4882a593Smuzhiyun   * - ``igmp_v2_report``
271*4882a593Smuzhiyun     - ``control``
272*4882a593Smuzhiyun     - Traps IGMP Version 2 Membership Report packets
273*4882a593Smuzhiyun   * - ``igmp_v3_report``
274*4882a593Smuzhiyun     - ``control``
275*4882a593Smuzhiyun     - Traps IGMP Version 3 Membership Report packets
276*4882a593Smuzhiyun   * - ``igmp_v2_leave``
277*4882a593Smuzhiyun     - ``control``
278*4882a593Smuzhiyun     - Traps IGMP Version 2 Leave Group packets
279*4882a593Smuzhiyun   * - ``mld_query``
280*4882a593Smuzhiyun     - ``control``
281*4882a593Smuzhiyun     - Traps MLD Multicast Listener Query packets
282*4882a593Smuzhiyun   * - ``mld_v1_report``
283*4882a593Smuzhiyun     - ``control``
284*4882a593Smuzhiyun     - Traps MLD Version 1 Multicast Listener Report packets
285*4882a593Smuzhiyun   * - ``mld_v2_report``
286*4882a593Smuzhiyun     - ``control``
287*4882a593Smuzhiyun     - Traps MLD Version 2 Multicast Listener Report packets
288*4882a593Smuzhiyun   * - ``mld_v1_done``
289*4882a593Smuzhiyun     - ``control``
290*4882a593Smuzhiyun     - Traps MLD Version 1 Multicast Listener Done packets
291*4882a593Smuzhiyun   * - ``ipv4_dhcp``
292*4882a593Smuzhiyun     - ``control``
293*4882a593Smuzhiyun     - Traps IPv4 DHCP packets
294*4882a593Smuzhiyun   * - ``ipv6_dhcp``
295*4882a593Smuzhiyun     - ``control``
296*4882a593Smuzhiyun     - Traps IPv6 DHCP packets
297*4882a593Smuzhiyun   * - ``arp_request``
298*4882a593Smuzhiyun     - ``control``
299*4882a593Smuzhiyun     - Traps ARP request packets
300*4882a593Smuzhiyun   * - ``arp_response``
301*4882a593Smuzhiyun     - ``control``
302*4882a593Smuzhiyun     - Traps ARP response packets
303*4882a593Smuzhiyun   * - ``arp_overlay``
304*4882a593Smuzhiyun     - ``control``
305*4882a593Smuzhiyun     - Traps NVE-decapsulated ARP packets that reached the overlay network.
306*4882a593Smuzhiyun       This is required, for example, when the address that needs to be
307*4882a593Smuzhiyun       resolved is a local address
308*4882a593Smuzhiyun   * - ``ipv6_neigh_solicit``
309*4882a593Smuzhiyun     - ``control``
310*4882a593Smuzhiyun     - Traps IPv6 Neighbour Solicitation packets
311*4882a593Smuzhiyun   * - ``ipv6_neigh_advert``
312*4882a593Smuzhiyun     - ``control``
313*4882a593Smuzhiyun     - Traps IPv6 Neighbour Advertisement packets
314*4882a593Smuzhiyun   * - ``ipv4_bfd``
315*4882a593Smuzhiyun     - ``control``
316*4882a593Smuzhiyun     - Traps IPv4 BFD packets
317*4882a593Smuzhiyun   * - ``ipv6_bfd``
318*4882a593Smuzhiyun     - ``control``
319*4882a593Smuzhiyun     - Traps IPv6 BFD packets
320*4882a593Smuzhiyun   * - ``ipv4_ospf``
321*4882a593Smuzhiyun     - ``control``
322*4882a593Smuzhiyun     - Traps IPv4 OSPF packets
323*4882a593Smuzhiyun   * - ``ipv6_ospf``
324*4882a593Smuzhiyun     - ``control``
325*4882a593Smuzhiyun     - Traps IPv6 OSPF packets
326*4882a593Smuzhiyun   * - ``ipv4_bgp``
327*4882a593Smuzhiyun     - ``control``
328*4882a593Smuzhiyun     - Traps IPv4 BGP packets
329*4882a593Smuzhiyun   * - ``ipv6_bgp``
330*4882a593Smuzhiyun     - ``control``
331*4882a593Smuzhiyun     - Traps IPv6 BGP packets
332*4882a593Smuzhiyun   * - ``ipv4_vrrp``
333*4882a593Smuzhiyun     - ``control``
334*4882a593Smuzhiyun     - Traps IPv4 VRRP packets
335*4882a593Smuzhiyun   * - ``ipv6_vrrp``
336*4882a593Smuzhiyun     - ``control``
337*4882a593Smuzhiyun     - Traps IPv6 VRRP packets
338*4882a593Smuzhiyun   * - ``ipv4_pim``
339*4882a593Smuzhiyun     - ``control``
340*4882a593Smuzhiyun     - Traps IPv4 PIM packets
341*4882a593Smuzhiyun   * - ``ipv6_pim``
342*4882a593Smuzhiyun     - ``control``
343*4882a593Smuzhiyun     - Traps IPv6 PIM packets
344*4882a593Smuzhiyun   * - ``uc_loopback``
345*4882a593Smuzhiyun     - ``control``
346*4882a593Smuzhiyun     - Traps unicast packets that need to be routed through the same layer 3
347*4882a593Smuzhiyun       interface from which they were received. Such packets are routed by the
348*4882a593Smuzhiyun       kernel, but also cause it to potentially generate ICMP redirect packets
349*4882a593Smuzhiyun   * - ``local_route``
350*4882a593Smuzhiyun     - ``control``
351*4882a593Smuzhiyun     - Traps unicast packets that hit a local route and need to be locally
352*4882a593Smuzhiyun       delivered
353*4882a593Smuzhiyun   * - ``external_route``
354*4882a593Smuzhiyun     - ``control``
355*4882a593Smuzhiyun     - Traps packets that should be routed through an external interface (e.g.,
356*4882a593Smuzhiyun       management interface) that does not belong to the same device (e.g.,
357*4882a593Smuzhiyun       switch ASIC) as the ingress interface
358*4882a593Smuzhiyun   * - ``ipv6_uc_dip_link_local_scope``
359*4882a593Smuzhiyun     - ``control``
360*4882a593Smuzhiyun     - Traps unicast IPv6 packets that need to be routed and have a destination
361*4882a593Smuzhiyun       IP address with a link-local scope (i.e., fe80::/10). The trap allows
362*4882a593Smuzhiyun       device drivers to avoid programming link-local routes, but still receive
363*4882a593Smuzhiyun       packets for local delivery
364*4882a593Smuzhiyun   * - ``ipv6_dip_all_nodes``
365*4882a593Smuzhiyun     - ``control``
366*4882a593Smuzhiyun     - Traps IPv6 packets that their destination IP address is the "All Nodes
367*4882a593Smuzhiyun       Address" (i.e., ff02::1)
368*4882a593Smuzhiyun   * - ``ipv6_dip_all_routers``
369*4882a593Smuzhiyun     - ``control``
370*4882a593Smuzhiyun     - Traps IPv6 packets that their destination IP address is the "All Routers
371*4882a593Smuzhiyun       Address" (i.e., ff02::2)
372*4882a593Smuzhiyun   * - ``ipv6_router_solicit``
373*4882a593Smuzhiyun     - ``control``
374*4882a593Smuzhiyun     - Traps IPv6 Router Solicitation packets
375*4882a593Smuzhiyun   * - ``ipv6_router_advert``
376*4882a593Smuzhiyun     - ``control``
377*4882a593Smuzhiyun     - Traps IPv6 Router Advertisement packets
378*4882a593Smuzhiyun   * - ``ipv6_redirect``
379*4882a593Smuzhiyun     - ``control``
380*4882a593Smuzhiyun     - Traps IPv6 Redirect Message packets
381*4882a593Smuzhiyun   * - ``ipv4_router_alert``
382*4882a593Smuzhiyun     - ``control``
383*4882a593Smuzhiyun     - Traps IPv4 packets that need to be routed and include the Router Alert
384*4882a593Smuzhiyun       option. Such packets need to be locally delivered to raw sockets that
385*4882a593Smuzhiyun       have the IP_ROUTER_ALERT socket option set
386*4882a593Smuzhiyun   * - ``ipv6_router_alert``
387*4882a593Smuzhiyun     - ``control``
388*4882a593Smuzhiyun     - Traps IPv6 packets that need to be routed and include the Router Alert
389*4882a593Smuzhiyun       option in their Hop-by-Hop extension header. Such packets need to be
390*4882a593Smuzhiyun       locally delivered to raw sockets that have the IPV6_ROUTER_ALERT socket
391*4882a593Smuzhiyun       option set
392*4882a593Smuzhiyun   * - ``ptp_event``
393*4882a593Smuzhiyun     - ``control``
394*4882a593Smuzhiyun     - Traps PTP time-critical event messages (Sync, Delay_req, Pdelay_Req and
395*4882a593Smuzhiyun       Pdelay_Resp)
396*4882a593Smuzhiyun   * - ``ptp_general``
397*4882a593Smuzhiyun     - ``control``
398*4882a593Smuzhiyun     - Traps PTP general messages (Announce, Follow_Up, Delay_Resp,
399*4882a593Smuzhiyun       Pdelay_Resp_Follow_Up, management and signaling)
400*4882a593Smuzhiyun   * - ``flow_action_sample``
401*4882a593Smuzhiyun     - ``control``
402*4882a593Smuzhiyun     - Traps packets sampled during processing of flow action sample (e.g., via
403*4882a593Smuzhiyun       tc's sample action)
404*4882a593Smuzhiyun   * - ``flow_action_trap``
405*4882a593Smuzhiyun     - ``control``
406*4882a593Smuzhiyun     - Traps packets logged during processing of flow action trap (e.g., via
407*4882a593Smuzhiyun       tc's trap action)
408*4882a593Smuzhiyun   * - ``early_drop``
409*4882a593Smuzhiyun     - ``drop``
410*4882a593Smuzhiyun     - Traps packets dropped due to the RED (Random Early Detection) algorithm
411*4882a593Smuzhiyun       (i.e., early drops)
412*4882a593Smuzhiyun   * - ``vxlan_parsing``
413*4882a593Smuzhiyun     - ``drop``
414*4882a593Smuzhiyun     - Traps packets dropped due to an error in the VXLAN header parsing which
415*4882a593Smuzhiyun       might be because of packet truncation or the I flag is not set.
416*4882a593Smuzhiyun   * - ``llc_snap_parsing``
417*4882a593Smuzhiyun     - ``drop``
418*4882a593Smuzhiyun     - Traps packets dropped due to an error in the LLC+SNAP header parsing
419*4882a593Smuzhiyun   * - ``vlan_parsing``
420*4882a593Smuzhiyun     - ``drop``
421*4882a593Smuzhiyun     - Traps packets dropped due to an error in the VLAN header parsing. Could
422*4882a593Smuzhiyun       include unexpected packet truncation.
423*4882a593Smuzhiyun   * - ``pppoe_ppp_parsing``
424*4882a593Smuzhiyun     - ``drop``
425*4882a593Smuzhiyun     - Traps packets dropped due to an error in the PPPoE+PPP header parsing.
426*4882a593Smuzhiyun       This could include finding a session ID of 0xFFFF (which is reserved and
427*4882a593Smuzhiyun       not for use), a PPPoE length which is larger than the frame received or
428*4882a593Smuzhiyun       any common error on this type of header
429*4882a593Smuzhiyun   * - ``mpls_parsing``
430*4882a593Smuzhiyun     - ``drop``
431*4882a593Smuzhiyun     - Traps packets dropped due to an error in the MPLS header parsing which
432*4882a593Smuzhiyun       could include unexpected header truncation
433*4882a593Smuzhiyun   * - ``arp_parsing``
434*4882a593Smuzhiyun     - ``drop``
435*4882a593Smuzhiyun     - Traps packets dropped due to an error in the ARP header parsing
436*4882a593Smuzhiyun   * - ``ip_1_parsing``
437*4882a593Smuzhiyun     - ``drop``
438*4882a593Smuzhiyun     - Traps packets dropped due to an error in the first IP header parsing.
439*4882a593Smuzhiyun       This packet trap could include packets which do not pass an IP checksum
440*4882a593Smuzhiyun       check, a header length check (a minimum of 20 bytes), which might suffer
441*4882a593Smuzhiyun       from packet truncation thus the total length field exceeds the received
442*4882a593Smuzhiyun       packet length etc
443*4882a593Smuzhiyun   * - ``ip_n_parsing``
444*4882a593Smuzhiyun     - ``drop``
445*4882a593Smuzhiyun     - Traps packets dropped due to an error in the parsing of the last IP
446*4882a593Smuzhiyun       header (the inner one in case of an IP over IP tunnel). The same common
447*4882a593Smuzhiyun       error checking is performed here as for the ip_1_parsing trap
448*4882a593Smuzhiyun   * - ``gre_parsing``
449*4882a593Smuzhiyun     - ``drop``
450*4882a593Smuzhiyun     - Traps packets dropped due to an error in the GRE header parsing
451*4882a593Smuzhiyun   * - ``udp_parsing``
452*4882a593Smuzhiyun     - ``drop``
453*4882a593Smuzhiyun     - Traps packets dropped due to an error in the UDP header parsing.
454*4882a593Smuzhiyun       This packet trap could include checksum errorrs, an improper UDP
455*4882a593Smuzhiyun       length detected (smaller than 8 bytes) or detection of header
456*4882a593Smuzhiyun       truncation.
457*4882a593Smuzhiyun   * - ``tcp_parsing``
458*4882a593Smuzhiyun     - ``drop``
459*4882a593Smuzhiyun     - Traps packets dropped due to an error in the TCP header parsing.
460*4882a593Smuzhiyun       This could include TCP checksum errors, improper combination of SYN, FIN
461*4882a593Smuzhiyun       and/or RESET etc.
462*4882a593Smuzhiyun   * - ``ipsec_parsing``
463*4882a593Smuzhiyun     - ``drop``
464*4882a593Smuzhiyun     - Traps packets dropped due to an error in the IPSEC header parsing
465*4882a593Smuzhiyun   * - ``sctp_parsing``
466*4882a593Smuzhiyun     - ``drop``
467*4882a593Smuzhiyun     - Traps packets dropped due to an error in the SCTP header parsing.
468*4882a593Smuzhiyun       This would mean that port number 0 was used or that the header is
469*4882a593Smuzhiyun       truncated.
470*4882a593Smuzhiyun   * - ``dccp_parsing``
471*4882a593Smuzhiyun     - ``drop``
472*4882a593Smuzhiyun     - Traps packets dropped due to an error in the DCCP header parsing
473*4882a593Smuzhiyun   * - ``gtp_parsing``
474*4882a593Smuzhiyun     - ``drop``
475*4882a593Smuzhiyun     - Traps packets dropped due to an error in the GTP header parsing
476*4882a593Smuzhiyun   * - ``esp_parsing``
477*4882a593Smuzhiyun     - ``drop``
478*4882a593Smuzhiyun     - Traps packets dropped due to an error in the ESP header parsing
479*4882a593Smuzhiyun
480*4882a593SmuzhiyunDriver-specific Packet Traps
481*4882a593Smuzhiyun============================
482*4882a593Smuzhiyun
483*4882a593SmuzhiyunDevice drivers can register driver-specific packet traps, but these must be
484*4882a593Smuzhiyunclearly documented. Such traps can correspond to device-specific exceptions and
485*4882a593Smuzhiyunhelp debug packet drops caused by these exceptions. The following list includes
486*4882a593Smuzhiyunlinks to the description of driver-specific traps registered by various device
487*4882a593Smuzhiyundrivers:
488*4882a593Smuzhiyun
489*4882a593Smuzhiyun  * :doc:`netdevsim`
490*4882a593Smuzhiyun  * :doc:`mlxsw`
491*4882a593Smuzhiyun
492*4882a593Smuzhiyun.. _Generic-Packet-Trap-Groups:
493*4882a593Smuzhiyun
494*4882a593SmuzhiyunGeneric Packet Trap Groups
495*4882a593Smuzhiyun==========================
496*4882a593Smuzhiyun
497*4882a593SmuzhiyunGeneric packet trap groups are used to aggregate logically related packet
498*4882a593Smuzhiyuntraps. These groups allow the user to batch operations such as setting the trap
499*4882a593Smuzhiyunaction of all member traps. In addition, ``devlink-trap`` can report aggregated
500*4882a593Smuzhiyunper-group packets and bytes statistics, in case per-trap statistics are too
501*4882a593Smuzhiyunnarrow. The description of these groups must be added to the following table:
502*4882a593Smuzhiyun
503*4882a593Smuzhiyun.. list-table:: List of Generic Packet Trap Groups
504*4882a593Smuzhiyun   :widths: 10 90
505*4882a593Smuzhiyun
506*4882a593Smuzhiyun   * - Name
507*4882a593Smuzhiyun     - Description
508*4882a593Smuzhiyun   * - ``l2_drops``
509*4882a593Smuzhiyun     - Contains packet traps for packets that were dropped by the device during
510*4882a593Smuzhiyun       layer 2 forwarding (i.e., bridge)
511*4882a593Smuzhiyun   * - ``l3_drops``
512*4882a593Smuzhiyun     - Contains packet traps for packets that were dropped by the device during
513*4882a593Smuzhiyun       layer 3 forwarding
514*4882a593Smuzhiyun   * - ``l3_exceptions``
515*4882a593Smuzhiyun     - Contains packet traps for packets that hit an exception (e.g., TTL
516*4882a593Smuzhiyun       error) during layer 3 forwarding
517*4882a593Smuzhiyun   * - ``buffer_drops``
518*4882a593Smuzhiyun     - Contains packet traps for packets that were dropped by the device due to
519*4882a593Smuzhiyun       an enqueue decision
520*4882a593Smuzhiyun   * - ``tunnel_drops``
521*4882a593Smuzhiyun     - Contains packet traps for packets that were dropped by the device during
522*4882a593Smuzhiyun       tunnel encapsulation / decapsulation
523*4882a593Smuzhiyun   * - ``acl_drops``
524*4882a593Smuzhiyun     - Contains packet traps for packets that were dropped by the device during
525*4882a593Smuzhiyun       ACL processing
526*4882a593Smuzhiyun   * - ``stp``
527*4882a593Smuzhiyun     - Contains packet traps for STP packets
528*4882a593Smuzhiyun   * - ``lacp``
529*4882a593Smuzhiyun     - Contains packet traps for LACP packets
530*4882a593Smuzhiyun   * - ``lldp``
531*4882a593Smuzhiyun     - Contains packet traps for LLDP packets
532*4882a593Smuzhiyun   * - ``mc_snooping``
533*4882a593Smuzhiyun     - Contains packet traps for IGMP and MLD packets required for multicast
534*4882a593Smuzhiyun       snooping
535*4882a593Smuzhiyun   * - ``dhcp``
536*4882a593Smuzhiyun     - Contains packet traps for DHCP packets
537*4882a593Smuzhiyun   * - ``neigh_discovery``
538*4882a593Smuzhiyun     - Contains packet traps for neighbour discovery packets (e.g., ARP, IPv6
539*4882a593Smuzhiyun       ND)
540*4882a593Smuzhiyun   * - ``bfd``
541*4882a593Smuzhiyun     - Contains packet traps for BFD packets
542*4882a593Smuzhiyun   * - ``ospf``
543*4882a593Smuzhiyun     - Contains packet traps for OSPF packets
544*4882a593Smuzhiyun   * - ``bgp``
545*4882a593Smuzhiyun     - Contains packet traps for BGP packets
546*4882a593Smuzhiyun   * - ``vrrp``
547*4882a593Smuzhiyun     - Contains packet traps for VRRP packets
548*4882a593Smuzhiyun   * - ``pim``
549*4882a593Smuzhiyun     - Contains packet traps for PIM packets
550*4882a593Smuzhiyun   * - ``uc_loopback``
551*4882a593Smuzhiyun     - Contains a packet trap for unicast loopback packets (i.e.,
552*4882a593Smuzhiyun       ``uc_loopback``). This trap is singled-out because in cases such as
553*4882a593Smuzhiyun       one-armed router it will be constantly triggered. To limit the impact on
554*4882a593Smuzhiyun       the CPU usage, a packet trap policer with a low rate can be bound to the
555*4882a593Smuzhiyun       group without affecting other traps
556*4882a593Smuzhiyun   * - ``local_delivery``
557*4882a593Smuzhiyun     - Contains packet traps for packets that should be locally delivered after
558*4882a593Smuzhiyun       routing, but do not match more specific packet traps (e.g.,
559*4882a593Smuzhiyun       ``ipv4_bgp``)
560*4882a593Smuzhiyun   * - ``external_delivery``
561*4882a593Smuzhiyun     - Contains packet traps for packets that should be routed through an
562*4882a593Smuzhiyun       external interface (e.g., management interface) that does not belong to
563*4882a593Smuzhiyun       the same device (e.g., switch ASIC) as the ingress interface
564*4882a593Smuzhiyun   * - ``ipv6``
565*4882a593Smuzhiyun     - Contains packet traps for various IPv6 control packets (e.g., Router
566*4882a593Smuzhiyun       Advertisements)
567*4882a593Smuzhiyun   * - ``ptp_event``
568*4882a593Smuzhiyun     - Contains packet traps for PTP time-critical event messages (Sync,
569*4882a593Smuzhiyun       Delay_req, Pdelay_Req and Pdelay_Resp)
570*4882a593Smuzhiyun   * - ``ptp_general``
571*4882a593Smuzhiyun     - Contains packet traps for PTP general messages (Announce, Follow_Up,
572*4882a593Smuzhiyun       Delay_Resp, Pdelay_Resp_Follow_Up, management and signaling)
573*4882a593Smuzhiyun   * - ``acl_sample``
574*4882a593Smuzhiyun     - Contains packet traps for packets that were sampled by the device during
575*4882a593Smuzhiyun       ACL processing
576*4882a593Smuzhiyun   * - ``acl_trap``
577*4882a593Smuzhiyun     - Contains packet traps for packets that were trapped (logged) by the
578*4882a593Smuzhiyun       device during ACL processing
579*4882a593Smuzhiyun   * - ``parser_error_drops``
580*4882a593Smuzhiyun     - Contains packet traps for packets that were marked by the device during
581*4882a593Smuzhiyun       parsing as erroneous
582*4882a593Smuzhiyun
583*4882a593SmuzhiyunPacket Trap Policers
584*4882a593Smuzhiyun====================
585*4882a593Smuzhiyun
586*4882a593SmuzhiyunAs previously explained, the underlying device can trap certain packets to the
587*4882a593SmuzhiyunCPU for processing. In most cases, the underlying device is capable of handling
588*4882a593Smuzhiyunpacket rates that are several orders of magnitude higher compared to those that
589*4882a593Smuzhiyuncan be handled by the CPU.
590*4882a593Smuzhiyun
591*4882a593SmuzhiyunTherefore, in order to prevent the underlying device from overwhelming the CPU,
592*4882a593Smuzhiyundevices usually include packet trap policers that are able to police the
593*4882a593Smuzhiyuntrapped packets to rates that can be handled by the CPU.
594*4882a593Smuzhiyun
595*4882a593SmuzhiyunThe ``devlink-trap`` mechanism allows capable device drivers to register their
596*4882a593Smuzhiyunsupported packet trap policers with ``devlink``. The device driver can choose
597*4882a593Smuzhiyunto associate these policers with supported packet trap groups (see
598*4882a593Smuzhiyun:ref:`Generic-Packet-Trap-Groups`) during its initialization, thereby exposing
599*4882a593Smuzhiyunits default control plane policy to user space.
600*4882a593Smuzhiyun
601*4882a593SmuzhiyunDevice drivers should allow user space to change the parameters of the policers
602*4882a593Smuzhiyun(e.g., rate, burst size) as well as the association between the policers and
603*4882a593Smuzhiyuntrap groups by implementing the relevant callbacks.
604*4882a593Smuzhiyun
605*4882a593SmuzhiyunIf possible, device drivers should implement a callback that allows user space
606*4882a593Smuzhiyunto retrieve the number of packets that were dropped by the policer because its
607*4882a593Smuzhiyunconfigured policy was violated.
608*4882a593Smuzhiyun
609*4882a593SmuzhiyunTesting
610*4882a593Smuzhiyun=======
611*4882a593Smuzhiyun
612*4882a593SmuzhiyunSee ``tools/testing/selftests/drivers/net/netdevsim/devlink_trap.sh`` for a
613*4882a593Smuzhiyuntest covering the core infrastructure. Test cases should be added for any new
614*4882a593Smuzhiyunfunctionality.
615*4882a593Smuzhiyun
616*4882a593SmuzhiyunDevice drivers should focus their tests on device-specific functionality, such
617*4882a593Smuzhiyunas the triggering of supported packet traps.
618