162306a36Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0
262306a36Sopenharmony_ci
362306a36Sopenharmony_ci============
462306a36Sopenharmony_ciDevlink Trap
562306a36Sopenharmony_ci============
662306a36Sopenharmony_ci
762306a36Sopenharmony_ciBackground
862306a36Sopenharmony_ci==========
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ciDevices capable of offloading the kernel's datapath and perform functions such
1162306a36Sopenharmony_cias bridging and routing must also be able to send specific packets to the
1262306a36Sopenharmony_cikernel (i.e., the CPU) for processing.
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ciFor example, a device acting as a multicast-aware bridge must be able to send
1562306a36Sopenharmony_ciIGMP membership reports to the kernel for processing by the bridge module.
1662306a36Sopenharmony_ciWithout processing such packets, the bridge module could never populate its
1762306a36Sopenharmony_ciMDB.
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_ciAs another example, consider a device acting as router which has received an IP
2062306a36Sopenharmony_cipacket with a TTL of 1. Upon routing the packet the device must send it to the
2162306a36Sopenharmony_cikernel so that it will route it as well and generate an ICMP Time Exceeded
2262306a36Sopenharmony_cierror datagram. Without letting the kernel route such packets itself, utilities
2362306a36Sopenharmony_cisuch as ``traceroute`` could never work.
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_ciThe fundamental ability of sending certain packets to the kernel for processing
2662306a36Sopenharmony_ciis called "packet trapping".
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ciOverview
2962306a36Sopenharmony_ci========
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_ciThe ``devlink-trap`` mechanism allows capable device drivers to register their
3262306a36Sopenharmony_cisupported packet traps with ``devlink`` and report trapped packets to
3362306a36Sopenharmony_ci``devlink`` for further analysis.
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ciUpon receiving trapped packets, ``devlink`` will perform a per-trap packets and
3662306a36Sopenharmony_cibytes accounting and potentially report the packet to user space via a netlink
3762306a36Sopenharmony_cievent along with all the provided metadata (e.g., trap reason, timestamp, input
3862306a36Sopenharmony_ciport). This is especially useful for drop traps (see :ref:`Trap-Types`)
3962306a36Sopenharmony_cias it allows users to obtain further visibility into packet drops that would
4062306a36Sopenharmony_ciotherwise be invisible.
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ciThe following diagram provides a general overview of ``devlink-trap``::
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_ci                                    Netlink event: Packet w/ metadata
4562306a36Sopenharmony_ci                                                   Or a summary of recent drops
4662306a36Sopenharmony_ci                                  ^
4762306a36Sopenharmony_ci                                  |
4862306a36Sopenharmony_ci         Userspace                |
4962306a36Sopenharmony_ci        +---------------------------------------------------+
5062306a36Sopenharmony_ci         Kernel                   |
5162306a36Sopenharmony_ci                                  |
5262306a36Sopenharmony_ci                          +-------+--------+
5362306a36Sopenharmony_ci                          |                |
5462306a36Sopenharmony_ci                          |  drop_monitor  |
5562306a36Sopenharmony_ci                          |                |
5662306a36Sopenharmony_ci                          +-------^--------+
5762306a36Sopenharmony_ci                                  |
5862306a36Sopenharmony_ci                                  | Non-control traps
5962306a36Sopenharmony_ci                                  |
6062306a36Sopenharmony_ci                             +----+----+
6162306a36Sopenharmony_ci                             |         |      Kernel's Rx path
6262306a36Sopenharmony_ci                             | devlink |      (non-drop traps)
6362306a36Sopenharmony_ci                             |         |
6462306a36Sopenharmony_ci                             +----^----+      ^
6562306a36Sopenharmony_ci                                  |           |
6662306a36Sopenharmony_ci                                  +-----------+
6762306a36Sopenharmony_ci                                  |
6862306a36Sopenharmony_ci                          +-------+-------+
6962306a36Sopenharmony_ci                          |               |
7062306a36Sopenharmony_ci                          | Device driver |
7162306a36Sopenharmony_ci                          |               |
7262306a36Sopenharmony_ci                          +-------^-------+
7362306a36Sopenharmony_ci         Kernel                   |
7462306a36Sopenharmony_ci        +---------------------------------------------------+
7562306a36Sopenharmony_ci         Hardware                 |
7662306a36Sopenharmony_ci                                  | Trapped packet
7762306a36Sopenharmony_ci                                  |
7862306a36Sopenharmony_ci                               +--+---+
7962306a36Sopenharmony_ci                               |      |
8062306a36Sopenharmony_ci                               | ASIC |
8162306a36Sopenharmony_ci                               |      |
8262306a36Sopenharmony_ci                               +------+
8362306a36Sopenharmony_ci
8462306a36Sopenharmony_ci.. _Trap-Types:
8562306a36Sopenharmony_ci
8662306a36Sopenharmony_ciTrap Types
8762306a36Sopenharmony_ci==========
8862306a36Sopenharmony_ci
8962306a36Sopenharmony_ciThe ``devlink-trap`` mechanism supports the following packet trap types:
9062306a36Sopenharmony_ci
9162306a36Sopenharmony_ci  * ``drop``: Trapped packets were dropped by the underlying device. Packets
9262306a36Sopenharmony_ci    are only processed by ``devlink`` and not injected to the kernel's Rx path.
9362306a36Sopenharmony_ci    The trap action (see :ref:`Trap-Actions`) can be changed.
9462306a36Sopenharmony_ci  * ``exception``: Trapped packets were not forwarded as intended by the
9562306a36Sopenharmony_ci    underlying device due to an exception (e.g., TTL error, missing neighbour
9662306a36Sopenharmony_ci    entry) and trapped to the control plane for resolution. Packets are
9762306a36Sopenharmony_ci    processed by ``devlink`` and injected to the kernel's Rx path. Changing the
9862306a36Sopenharmony_ci    action of such traps is not allowed, as it can easily break the control
9962306a36Sopenharmony_ci    plane.
10062306a36Sopenharmony_ci  * ``control``: Trapped packets were trapped by the device because these are
10162306a36Sopenharmony_ci    control packets required for the correct functioning of the control plane.
10262306a36Sopenharmony_ci    For example, ARP request and IGMP query packets. Packets are injected to
10362306a36Sopenharmony_ci    the kernel's Rx path, but not reported to the kernel's drop monitor.
10462306a36Sopenharmony_ci    Changing the action of such traps is not allowed, as it can easily break
10562306a36Sopenharmony_ci    the control plane.
10662306a36Sopenharmony_ci
10762306a36Sopenharmony_ci.. _Trap-Actions:
10862306a36Sopenharmony_ci
10962306a36Sopenharmony_ciTrap Actions
11062306a36Sopenharmony_ci============
11162306a36Sopenharmony_ci
11262306a36Sopenharmony_ciThe ``devlink-trap`` mechanism supports the following packet trap actions:
11362306a36Sopenharmony_ci
11462306a36Sopenharmony_ci  * ``trap``: The sole copy of the packet is sent to the CPU.
11562306a36Sopenharmony_ci  * ``drop``: The packet is dropped by the underlying device and a copy is not
11662306a36Sopenharmony_ci    sent to the CPU.
11762306a36Sopenharmony_ci  * ``mirror``: The packet is forwarded by the underlying device and a copy is
11862306a36Sopenharmony_ci    sent to the CPU.
11962306a36Sopenharmony_ci
12062306a36Sopenharmony_ciGeneric Packet Traps
12162306a36Sopenharmony_ci====================
12262306a36Sopenharmony_ci
12362306a36Sopenharmony_ciGeneric packet traps are used to describe traps that trap well-defined packets
12462306a36Sopenharmony_cior packets that are trapped due to well-defined conditions (e.g., TTL error).
12562306a36Sopenharmony_ciSuch traps can be shared by multiple device drivers and their description must
12662306a36Sopenharmony_cibe added to the following table:
12762306a36Sopenharmony_ci
12862306a36Sopenharmony_ci.. list-table:: List of Generic Packet Traps
12962306a36Sopenharmony_ci   :widths: 5 5 90
13062306a36Sopenharmony_ci
13162306a36Sopenharmony_ci   * - Name
13262306a36Sopenharmony_ci     - Type
13362306a36Sopenharmony_ci     - Description
13462306a36Sopenharmony_ci   * - ``source_mac_is_multicast``
13562306a36Sopenharmony_ci     - ``drop``
13662306a36Sopenharmony_ci     - Traps incoming packets that the device decided to drop because of a
13762306a36Sopenharmony_ci       multicast source MAC
13862306a36Sopenharmony_ci   * - ``vlan_tag_mismatch``
13962306a36Sopenharmony_ci     - ``drop``
14062306a36Sopenharmony_ci     - Traps incoming packets that the device decided to drop in case of VLAN
14162306a36Sopenharmony_ci       tag mismatch: The ingress bridge port is not configured with a PVID and
14262306a36Sopenharmony_ci       the packet is untagged or prio-tagged
14362306a36Sopenharmony_ci   * - ``ingress_vlan_filter``
14462306a36Sopenharmony_ci     - ``drop``
14562306a36Sopenharmony_ci     - Traps incoming packets that the device decided to drop in case they are
14662306a36Sopenharmony_ci       tagged with a VLAN that is not configured on the ingress bridge port
14762306a36Sopenharmony_ci   * - ``ingress_spanning_tree_filter``
14862306a36Sopenharmony_ci     - ``drop``
14962306a36Sopenharmony_ci     - Traps incoming packets that the device decided to drop in case the STP
15062306a36Sopenharmony_ci       state of the ingress bridge port is not "forwarding"
15162306a36Sopenharmony_ci   * - ``port_list_is_empty``
15262306a36Sopenharmony_ci     - ``drop``
15362306a36Sopenharmony_ci     - Traps packets that the device decided to drop in case they need to be
15462306a36Sopenharmony_ci       flooded (e.g., unknown unicast, unregistered multicast) and there are
15562306a36Sopenharmony_ci       no ports the packets should be flooded to
15662306a36Sopenharmony_ci   * - ``port_loopback_filter``
15762306a36Sopenharmony_ci     - ``drop``
15862306a36Sopenharmony_ci     - Traps packets that the device decided to drop in case after layer 2
15962306a36Sopenharmony_ci       forwarding the only port from which they should be transmitted through
16062306a36Sopenharmony_ci       is the port from which they were received
16162306a36Sopenharmony_ci   * - ``blackhole_route``
16262306a36Sopenharmony_ci     - ``drop``
16362306a36Sopenharmony_ci     - Traps packets that the device decided to drop in case they hit a
16462306a36Sopenharmony_ci       blackhole route
16562306a36Sopenharmony_ci   * - ``ttl_value_is_too_small``
16662306a36Sopenharmony_ci     - ``exception``
16762306a36Sopenharmony_ci     - Traps unicast packets that should be forwarded by the device whose TTL
16862306a36Sopenharmony_ci       was decremented to 0 or less
16962306a36Sopenharmony_ci   * - ``tail_drop``
17062306a36Sopenharmony_ci     - ``drop``
17162306a36Sopenharmony_ci     - Traps packets that the device decided to drop because they could not be
17262306a36Sopenharmony_ci       enqueued to a transmission queue which is full
17362306a36Sopenharmony_ci   * - ``non_ip``
17462306a36Sopenharmony_ci     - ``drop``
17562306a36Sopenharmony_ci     - Traps packets that the device decided to drop because they need to
17662306a36Sopenharmony_ci       undergo a layer 3 lookup, but are not IP or MPLS packets
17762306a36Sopenharmony_ci   * - ``uc_dip_over_mc_dmac``
17862306a36Sopenharmony_ci     - ``drop``
17962306a36Sopenharmony_ci     - Traps packets that the device decided to drop because they need to be
18062306a36Sopenharmony_ci       routed and they have a unicast destination IP and a multicast destination
18162306a36Sopenharmony_ci       MAC
18262306a36Sopenharmony_ci   * - ``dip_is_loopback_address``
18362306a36Sopenharmony_ci     - ``drop``
18462306a36Sopenharmony_ci     - Traps packets that the device decided to drop because they need to be
18562306a36Sopenharmony_ci       routed and their destination IP is the loopback address (i.e., 127.0.0.0/8
18662306a36Sopenharmony_ci       and ::1/128)
18762306a36Sopenharmony_ci   * - ``sip_is_mc``
18862306a36Sopenharmony_ci     - ``drop``
18962306a36Sopenharmony_ci     - Traps packets that the device decided to drop because they need to be
19062306a36Sopenharmony_ci       routed and their source IP is multicast (i.e., 224.0.0.0/8 and ff::/8)
19162306a36Sopenharmony_ci   * - ``sip_is_loopback_address``
19262306a36Sopenharmony_ci     - ``drop``
19362306a36Sopenharmony_ci     - Traps packets that the device decided to drop because they need to be
19462306a36Sopenharmony_ci       routed and their source IP is the loopback address (i.e., 127.0.0.0/8 and ::1/128)
19562306a36Sopenharmony_ci   * - ``ip_header_corrupted``
19662306a36Sopenharmony_ci     - ``drop``
19762306a36Sopenharmony_ci     - Traps packets that the device decided to drop because they need to be
19862306a36Sopenharmony_ci       routed and their IP header is corrupted: wrong checksum, wrong IP version
19962306a36Sopenharmony_ci       or too short Internet Header Length (IHL)
20062306a36Sopenharmony_ci   * - ``ipv4_sip_is_limited_bc``
20162306a36Sopenharmony_ci     - ``drop``
20262306a36Sopenharmony_ci     - Traps packets that the device decided to drop because they need to be
20362306a36Sopenharmony_ci       routed and their source IP is limited broadcast (i.e., 255.255.255.255/32)
20462306a36Sopenharmony_ci   * - ``ipv6_mc_dip_reserved_scope``
20562306a36Sopenharmony_ci     - ``drop``
20662306a36Sopenharmony_ci     - Traps IPv6 packets that the device decided to drop because they need to
20762306a36Sopenharmony_ci       be routed and their IPv6 multicast destination IP has a reserved scope
20862306a36Sopenharmony_ci       (i.e., ffx0::/16)
20962306a36Sopenharmony_ci   * - ``ipv6_mc_dip_interface_local_scope``
21062306a36Sopenharmony_ci     - ``drop``
21162306a36Sopenharmony_ci     - Traps IPv6 packets that the device decided to drop because they need to
21262306a36Sopenharmony_ci       be routed and their IPv6 multicast destination IP has an interface-local scope
21362306a36Sopenharmony_ci       (i.e., ffx1::/16)
21462306a36Sopenharmony_ci   * - ``mtu_value_is_too_small``
21562306a36Sopenharmony_ci     - ``exception``
21662306a36Sopenharmony_ci     - Traps packets that should have been routed by the device, but were bigger
21762306a36Sopenharmony_ci       than the MTU of the egress interface
21862306a36Sopenharmony_ci   * - ``unresolved_neigh``
21962306a36Sopenharmony_ci     - ``exception``
22062306a36Sopenharmony_ci     - Traps packets that did not have a matching IP neighbour after routing
22162306a36Sopenharmony_ci   * - ``mc_reverse_path_forwarding``
22262306a36Sopenharmony_ci     - ``exception``
22362306a36Sopenharmony_ci     - Traps multicast IP packets that failed reverse-path forwarding (RPF)
22462306a36Sopenharmony_ci       check during multicast routing
22562306a36Sopenharmony_ci   * - ``reject_route``
22662306a36Sopenharmony_ci     - ``exception``
22762306a36Sopenharmony_ci     - Traps packets that hit reject routes (i.e., "unreachable", "prohibit")
22862306a36Sopenharmony_ci   * - ``ipv4_lpm_miss``
22962306a36Sopenharmony_ci     - ``exception``
23062306a36Sopenharmony_ci     - Traps unicast IPv4 packets that did not match any route
23162306a36Sopenharmony_ci   * - ``ipv6_lpm_miss``
23262306a36Sopenharmony_ci     - ``exception``
23362306a36Sopenharmony_ci     - Traps unicast IPv6 packets that did not match any route
23462306a36Sopenharmony_ci   * - ``non_routable_packet``
23562306a36Sopenharmony_ci     - ``drop``
23662306a36Sopenharmony_ci     - Traps packets that the device decided to drop because they are not
23762306a36Sopenharmony_ci       supposed to be routed. For example, IGMP queries can be flooded by the
23862306a36Sopenharmony_ci       device in layer 2 and reach the router. Such packets should not be
23962306a36Sopenharmony_ci       routed and instead dropped
24062306a36Sopenharmony_ci   * - ``decap_error``
24162306a36Sopenharmony_ci     - ``exception``
24262306a36Sopenharmony_ci     - Traps NVE and IPinIP packets that the device decided to drop because of
24362306a36Sopenharmony_ci       failure during decapsulation (e.g., packet being too short, reserved
24462306a36Sopenharmony_ci       bits set in VXLAN header)
24562306a36Sopenharmony_ci   * - ``overlay_smac_is_mc``
24662306a36Sopenharmony_ci     - ``drop``
24762306a36Sopenharmony_ci     - Traps NVE packets that the device decided to drop because their overlay
24862306a36Sopenharmony_ci       source MAC is multicast
24962306a36Sopenharmony_ci   * - ``ingress_flow_action_drop``
25062306a36Sopenharmony_ci     - ``drop``
25162306a36Sopenharmony_ci     - Traps packets dropped during processing of ingress flow action drop
25262306a36Sopenharmony_ci   * - ``egress_flow_action_drop``
25362306a36Sopenharmony_ci     - ``drop``
25462306a36Sopenharmony_ci     - Traps packets dropped during processing of egress flow action drop
25562306a36Sopenharmony_ci   * - ``stp``
25662306a36Sopenharmony_ci     - ``control``
25762306a36Sopenharmony_ci     - Traps STP packets
25862306a36Sopenharmony_ci   * - ``lacp``
25962306a36Sopenharmony_ci     - ``control``
26062306a36Sopenharmony_ci     - Traps LACP packets
26162306a36Sopenharmony_ci   * - ``lldp``
26262306a36Sopenharmony_ci     - ``control``
26362306a36Sopenharmony_ci     - Traps LLDP packets
26462306a36Sopenharmony_ci   * - ``igmp_query``
26562306a36Sopenharmony_ci     - ``control``
26662306a36Sopenharmony_ci     - Traps IGMP Membership Query packets
26762306a36Sopenharmony_ci   * - ``igmp_v1_report``
26862306a36Sopenharmony_ci     - ``control``
26962306a36Sopenharmony_ci     - Traps IGMP Version 1 Membership Report packets
27062306a36Sopenharmony_ci   * - ``igmp_v2_report``
27162306a36Sopenharmony_ci     - ``control``
27262306a36Sopenharmony_ci     - Traps IGMP Version 2 Membership Report packets
27362306a36Sopenharmony_ci   * - ``igmp_v3_report``
27462306a36Sopenharmony_ci     - ``control``
27562306a36Sopenharmony_ci     - Traps IGMP Version 3 Membership Report packets
27662306a36Sopenharmony_ci   * - ``igmp_v2_leave``
27762306a36Sopenharmony_ci     - ``control``
27862306a36Sopenharmony_ci     - Traps IGMP Version 2 Leave Group packets
27962306a36Sopenharmony_ci   * - ``mld_query``
28062306a36Sopenharmony_ci     - ``control``
28162306a36Sopenharmony_ci     - Traps MLD Multicast Listener Query packets
28262306a36Sopenharmony_ci   * - ``mld_v1_report``
28362306a36Sopenharmony_ci     - ``control``
28462306a36Sopenharmony_ci     - Traps MLD Version 1 Multicast Listener Report packets
28562306a36Sopenharmony_ci   * - ``mld_v2_report``
28662306a36Sopenharmony_ci     - ``control``
28762306a36Sopenharmony_ci     - Traps MLD Version 2 Multicast Listener Report packets
28862306a36Sopenharmony_ci   * - ``mld_v1_done``
28962306a36Sopenharmony_ci     - ``control``
29062306a36Sopenharmony_ci     - Traps MLD Version 1 Multicast Listener Done packets
29162306a36Sopenharmony_ci   * - ``ipv4_dhcp``
29262306a36Sopenharmony_ci     - ``control``
29362306a36Sopenharmony_ci     - Traps IPv4 DHCP packets
29462306a36Sopenharmony_ci   * - ``ipv6_dhcp``
29562306a36Sopenharmony_ci     - ``control``
29662306a36Sopenharmony_ci     - Traps IPv6 DHCP packets
29762306a36Sopenharmony_ci   * - ``arp_request``
29862306a36Sopenharmony_ci     - ``control``
29962306a36Sopenharmony_ci     - Traps ARP request packets
30062306a36Sopenharmony_ci   * - ``arp_response``
30162306a36Sopenharmony_ci     - ``control``
30262306a36Sopenharmony_ci     - Traps ARP response packets
30362306a36Sopenharmony_ci   * - ``arp_overlay``
30462306a36Sopenharmony_ci     - ``control``
30562306a36Sopenharmony_ci     - Traps NVE-decapsulated ARP packets that reached the overlay network.
30662306a36Sopenharmony_ci       This is required, for example, when the address that needs to be
30762306a36Sopenharmony_ci       resolved is a local address
30862306a36Sopenharmony_ci   * - ``ipv6_neigh_solicit``
30962306a36Sopenharmony_ci     - ``control``
31062306a36Sopenharmony_ci     - Traps IPv6 Neighbour Solicitation packets
31162306a36Sopenharmony_ci   * - ``ipv6_neigh_advert``
31262306a36Sopenharmony_ci     - ``control``
31362306a36Sopenharmony_ci     - Traps IPv6 Neighbour Advertisement packets
31462306a36Sopenharmony_ci   * - ``ipv4_bfd``
31562306a36Sopenharmony_ci     - ``control``
31662306a36Sopenharmony_ci     - Traps IPv4 BFD packets
31762306a36Sopenharmony_ci   * - ``ipv6_bfd``
31862306a36Sopenharmony_ci     - ``control``
31962306a36Sopenharmony_ci     - Traps IPv6 BFD packets
32062306a36Sopenharmony_ci   * - ``ipv4_ospf``
32162306a36Sopenharmony_ci     - ``control``
32262306a36Sopenharmony_ci     - Traps IPv4 OSPF packets
32362306a36Sopenharmony_ci   * - ``ipv6_ospf``
32462306a36Sopenharmony_ci     - ``control``
32562306a36Sopenharmony_ci     - Traps IPv6 OSPF packets
32662306a36Sopenharmony_ci   * - ``ipv4_bgp``
32762306a36Sopenharmony_ci     - ``control``
32862306a36Sopenharmony_ci     - Traps IPv4 BGP packets
32962306a36Sopenharmony_ci   * - ``ipv6_bgp``
33062306a36Sopenharmony_ci     - ``control``
33162306a36Sopenharmony_ci     - Traps IPv6 BGP packets
33262306a36Sopenharmony_ci   * - ``ipv4_vrrp``
33362306a36Sopenharmony_ci     - ``control``
33462306a36Sopenharmony_ci     - Traps IPv4 VRRP packets
33562306a36Sopenharmony_ci   * - ``ipv6_vrrp``
33662306a36Sopenharmony_ci     - ``control``
33762306a36Sopenharmony_ci     - Traps IPv6 VRRP packets
33862306a36Sopenharmony_ci   * - ``ipv4_pim``
33962306a36Sopenharmony_ci     - ``control``
34062306a36Sopenharmony_ci     - Traps IPv4 PIM packets
34162306a36Sopenharmony_ci   * - ``ipv6_pim``
34262306a36Sopenharmony_ci     - ``control``
34362306a36Sopenharmony_ci     - Traps IPv6 PIM packets
34462306a36Sopenharmony_ci   * - ``uc_loopback``
34562306a36Sopenharmony_ci     - ``control``
34662306a36Sopenharmony_ci     - Traps unicast packets that need to be routed through the same layer 3
34762306a36Sopenharmony_ci       interface from which they were received. Such packets are routed by the
34862306a36Sopenharmony_ci       kernel, but also cause it to potentially generate ICMP redirect packets
34962306a36Sopenharmony_ci   * - ``local_route``
35062306a36Sopenharmony_ci     - ``control``
35162306a36Sopenharmony_ci     - Traps unicast packets that hit a local route and need to be locally
35262306a36Sopenharmony_ci       delivered
35362306a36Sopenharmony_ci   * - ``external_route``
35462306a36Sopenharmony_ci     - ``control``
35562306a36Sopenharmony_ci     - Traps packets that should be routed through an external interface (e.g.,
35662306a36Sopenharmony_ci       management interface) that does not belong to the same device (e.g.,
35762306a36Sopenharmony_ci       switch ASIC) as the ingress interface
35862306a36Sopenharmony_ci   * - ``ipv6_uc_dip_link_local_scope``
35962306a36Sopenharmony_ci     - ``control``
36062306a36Sopenharmony_ci     - Traps unicast IPv6 packets that need to be routed and have a destination
36162306a36Sopenharmony_ci       IP address with a link-local scope (i.e., fe80::/10). The trap allows
36262306a36Sopenharmony_ci       device drivers to avoid programming link-local routes, but still receive
36362306a36Sopenharmony_ci       packets for local delivery
36462306a36Sopenharmony_ci   * - ``ipv6_dip_all_nodes``
36562306a36Sopenharmony_ci     - ``control``
36662306a36Sopenharmony_ci     - Traps IPv6 packets that their destination IP address is the "All Nodes
36762306a36Sopenharmony_ci       Address" (i.e., ff02::1)
36862306a36Sopenharmony_ci   * - ``ipv6_dip_all_routers``
36962306a36Sopenharmony_ci     - ``control``
37062306a36Sopenharmony_ci     - Traps IPv6 packets that their destination IP address is the "All Routers
37162306a36Sopenharmony_ci       Address" (i.e., ff02::2)
37262306a36Sopenharmony_ci   * - ``ipv6_router_solicit``
37362306a36Sopenharmony_ci     - ``control``
37462306a36Sopenharmony_ci     - Traps IPv6 Router Solicitation packets
37562306a36Sopenharmony_ci   * - ``ipv6_router_advert``
37662306a36Sopenharmony_ci     - ``control``
37762306a36Sopenharmony_ci     - Traps IPv6 Router Advertisement packets
37862306a36Sopenharmony_ci   * - ``ipv6_redirect``
37962306a36Sopenharmony_ci     - ``control``
38062306a36Sopenharmony_ci     - Traps IPv6 Redirect Message packets
38162306a36Sopenharmony_ci   * - ``ipv4_router_alert``
38262306a36Sopenharmony_ci     - ``control``
38362306a36Sopenharmony_ci     - Traps IPv4 packets that need to be routed and include the Router Alert
38462306a36Sopenharmony_ci       option. Such packets need to be locally delivered to raw sockets that
38562306a36Sopenharmony_ci       have the IP_ROUTER_ALERT socket option set
38662306a36Sopenharmony_ci   * - ``ipv6_router_alert``
38762306a36Sopenharmony_ci     - ``control``
38862306a36Sopenharmony_ci     - Traps IPv6 packets that need to be routed and include the Router Alert
38962306a36Sopenharmony_ci       option in their Hop-by-Hop extension header. Such packets need to be
39062306a36Sopenharmony_ci       locally delivered to raw sockets that have the IPV6_ROUTER_ALERT socket
39162306a36Sopenharmony_ci       option set
39262306a36Sopenharmony_ci   * - ``ptp_event``
39362306a36Sopenharmony_ci     - ``control``
39462306a36Sopenharmony_ci     - Traps PTP time-critical event messages (Sync, Delay_req, Pdelay_Req and
39562306a36Sopenharmony_ci       Pdelay_Resp)
39662306a36Sopenharmony_ci   * - ``ptp_general``
39762306a36Sopenharmony_ci     - ``control``
39862306a36Sopenharmony_ci     - Traps PTP general messages (Announce, Follow_Up, Delay_Resp,
39962306a36Sopenharmony_ci       Pdelay_Resp_Follow_Up, management and signaling)
40062306a36Sopenharmony_ci   * - ``flow_action_sample``
40162306a36Sopenharmony_ci     - ``control``
40262306a36Sopenharmony_ci     - Traps packets sampled during processing of flow action sample (e.g., via
40362306a36Sopenharmony_ci       tc's sample action)
40462306a36Sopenharmony_ci   * - ``flow_action_trap``
40562306a36Sopenharmony_ci     - ``control``
40662306a36Sopenharmony_ci     - Traps packets logged during processing of flow action trap (e.g., via
40762306a36Sopenharmony_ci       tc's trap action)
40862306a36Sopenharmony_ci   * - ``early_drop``
40962306a36Sopenharmony_ci     - ``drop``
41062306a36Sopenharmony_ci     - Traps packets dropped due to the RED (Random Early Detection) algorithm
41162306a36Sopenharmony_ci       (i.e., early drops)
41262306a36Sopenharmony_ci   * - ``vxlan_parsing``
41362306a36Sopenharmony_ci     - ``drop``
41462306a36Sopenharmony_ci     - Traps packets dropped due to an error in the VXLAN header parsing which
41562306a36Sopenharmony_ci       might be because of packet truncation or the I flag is not set.
41662306a36Sopenharmony_ci   * - ``llc_snap_parsing``
41762306a36Sopenharmony_ci     - ``drop``
41862306a36Sopenharmony_ci     - Traps packets dropped due to an error in the LLC+SNAP header parsing
41962306a36Sopenharmony_ci   * - ``vlan_parsing``
42062306a36Sopenharmony_ci     - ``drop``
42162306a36Sopenharmony_ci     - Traps packets dropped due to an error in the VLAN header parsing. Could
42262306a36Sopenharmony_ci       include unexpected packet truncation.
42362306a36Sopenharmony_ci   * - ``pppoe_ppp_parsing``
42462306a36Sopenharmony_ci     - ``drop``
42562306a36Sopenharmony_ci     - Traps packets dropped due to an error in the PPPoE+PPP header parsing.
42662306a36Sopenharmony_ci       This could include finding a session ID of 0xFFFF (which is reserved and
42762306a36Sopenharmony_ci       not for use), a PPPoE length which is larger than the frame received or
42862306a36Sopenharmony_ci       any common error on this type of header
42962306a36Sopenharmony_ci   * - ``mpls_parsing``
43062306a36Sopenharmony_ci     - ``drop``
43162306a36Sopenharmony_ci     - Traps packets dropped due to an error in the MPLS header parsing which
43262306a36Sopenharmony_ci       could include unexpected header truncation
43362306a36Sopenharmony_ci   * - ``arp_parsing``
43462306a36Sopenharmony_ci     - ``drop``
43562306a36Sopenharmony_ci     - Traps packets dropped due to an error in the ARP header parsing
43662306a36Sopenharmony_ci   * - ``ip_1_parsing``
43762306a36Sopenharmony_ci     - ``drop``
43862306a36Sopenharmony_ci     - Traps packets dropped due to an error in the first IP header parsing.
43962306a36Sopenharmony_ci       This packet trap could include packets which do not pass an IP checksum
44062306a36Sopenharmony_ci       check, a header length check (a minimum of 20 bytes), which might suffer
44162306a36Sopenharmony_ci       from packet truncation thus the total length field exceeds the received
44262306a36Sopenharmony_ci       packet length etc
44362306a36Sopenharmony_ci   * - ``ip_n_parsing``
44462306a36Sopenharmony_ci     - ``drop``
44562306a36Sopenharmony_ci     - Traps packets dropped due to an error in the parsing of the last IP
44662306a36Sopenharmony_ci       header (the inner one in case of an IP over IP tunnel). The same common
44762306a36Sopenharmony_ci       error checking is performed here as for the ip_1_parsing trap
44862306a36Sopenharmony_ci   * - ``gre_parsing``
44962306a36Sopenharmony_ci     - ``drop``
45062306a36Sopenharmony_ci     - Traps packets dropped due to an error in the GRE header parsing
45162306a36Sopenharmony_ci   * - ``udp_parsing``
45262306a36Sopenharmony_ci     - ``drop``
45362306a36Sopenharmony_ci     - Traps packets dropped due to an error in the UDP header parsing.
45462306a36Sopenharmony_ci       This packet trap could include checksum errorrs, an improper UDP
45562306a36Sopenharmony_ci       length detected (smaller than 8 bytes) or detection of header
45662306a36Sopenharmony_ci       truncation.
45762306a36Sopenharmony_ci   * - ``tcp_parsing``
45862306a36Sopenharmony_ci     - ``drop``
45962306a36Sopenharmony_ci     - Traps packets dropped due to an error in the TCP header parsing.
46062306a36Sopenharmony_ci       This could include TCP checksum errors, improper combination of SYN, FIN
46162306a36Sopenharmony_ci       and/or RESET etc.
46262306a36Sopenharmony_ci   * - ``ipsec_parsing``
46362306a36Sopenharmony_ci     - ``drop``
46462306a36Sopenharmony_ci     - Traps packets dropped due to an error in the IPSEC header parsing
46562306a36Sopenharmony_ci   * - ``sctp_parsing``
46662306a36Sopenharmony_ci     - ``drop``
46762306a36Sopenharmony_ci     - Traps packets dropped due to an error in the SCTP header parsing.
46862306a36Sopenharmony_ci       This would mean that port number 0 was used or that the header is
46962306a36Sopenharmony_ci       truncated.
47062306a36Sopenharmony_ci   * - ``dccp_parsing``
47162306a36Sopenharmony_ci     - ``drop``
47262306a36Sopenharmony_ci     - Traps packets dropped due to an error in the DCCP header parsing
47362306a36Sopenharmony_ci   * - ``gtp_parsing``
47462306a36Sopenharmony_ci     - ``drop``
47562306a36Sopenharmony_ci     - Traps packets dropped due to an error in the GTP header parsing
47662306a36Sopenharmony_ci   * - ``esp_parsing``
47762306a36Sopenharmony_ci     - ``drop``
47862306a36Sopenharmony_ci     - Traps packets dropped due to an error in the ESP header parsing
47962306a36Sopenharmony_ci   * - ``blackhole_nexthop``
48062306a36Sopenharmony_ci     - ``drop``
48162306a36Sopenharmony_ci     - Traps packets that the device decided to drop in case they hit a
48262306a36Sopenharmony_ci       blackhole nexthop
48362306a36Sopenharmony_ci   * - ``dmac_filter``
48462306a36Sopenharmony_ci     - ``drop``
48562306a36Sopenharmony_ci     - Traps incoming packets that the device decided to drop because
48662306a36Sopenharmony_ci       the destination MAC is not configured in the MAC table and
48762306a36Sopenharmony_ci       the interface is not in promiscuous mode
48862306a36Sopenharmony_ci   * - ``eapol``
48962306a36Sopenharmony_ci     - ``control``
49062306a36Sopenharmony_ci     - Traps "Extensible Authentication Protocol over LAN" (EAPOL) packets
49162306a36Sopenharmony_ci       specified in IEEE 802.1X
49262306a36Sopenharmony_ci   * - ``locked_port``
49362306a36Sopenharmony_ci     - ``drop``
49462306a36Sopenharmony_ci     - Traps packets that the device decided to drop because they failed the
49562306a36Sopenharmony_ci       locked bridge port check. That is, packets that were received via a
49662306a36Sopenharmony_ci       locked port and whose {SMAC, VID} does not correspond to an FDB entry
49762306a36Sopenharmony_ci       pointing to the port
49862306a36Sopenharmony_ci
49962306a36Sopenharmony_ciDriver-specific Packet Traps
50062306a36Sopenharmony_ci============================
50162306a36Sopenharmony_ci
50262306a36Sopenharmony_ciDevice drivers can register driver-specific packet traps, but these must be
50362306a36Sopenharmony_ciclearly documented. Such traps can correspond to device-specific exceptions and
50462306a36Sopenharmony_cihelp debug packet drops caused by these exceptions. The following list includes
50562306a36Sopenharmony_cilinks to the description of driver-specific traps registered by various device
50662306a36Sopenharmony_cidrivers:
50762306a36Sopenharmony_ci
50862306a36Sopenharmony_ci  * Documentation/networking/devlink/netdevsim.rst
50962306a36Sopenharmony_ci  * Documentation/networking/devlink/mlxsw.rst
51062306a36Sopenharmony_ci  * Documentation/networking/devlink/prestera.rst
51162306a36Sopenharmony_ci
51262306a36Sopenharmony_ci.. _Generic-Packet-Trap-Groups:
51362306a36Sopenharmony_ci
51462306a36Sopenharmony_ciGeneric Packet Trap Groups
51562306a36Sopenharmony_ci==========================
51662306a36Sopenharmony_ci
51762306a36Sopenharmony_ciGeneric packet trap groups are used to aggregate logically related packet
51862306a36Sopenharmony_citraps. These groups allow the user to batch operations such as setting the trap
51962306a36Sopenharmony_ciaction of all member traps. In addition, ``devlink-trap`` can report aggregated
52062306a36Sopenharmony_ciper-group packets and bytes statistics, in case per-trap statistics are too
52162306a36Sopenharmony_cinarrow. The description of these groups must be added to the following table:
52262306a36Sopenharmony_ci
52362306a36Sopenharmony_ci.. list-table:: List of Generic Packet Trap Groups
52462306a36Sopenharmony_ci   :widths: 10 90
52562306a36Sopenharmony_ci
52662306a36Sopenharmony_ci   * - Name
52762306a36Sopenharmony_ci     - Description
52862306a36Sopenharmony_ci   * - ``l2_drops``
52962306a36Sopenharmony_ci     - Contains packet traps for packets that were dropped by the device during
53062306a36Sopenharmony_ci       layer 2 forwarding (i.e., bridge)
53162306a36Sopenharmony_ci   * - ``l3_drops``
53262306a36Sopenharmony_ci     - Contains packet traps for packets that were dropped by the device during
53362306a36Sopenharmony_ci       layer 3 forwarding
53462306a36Sopenharmony_ci   * - ``l3_exceptions``
53562306a36Sopenharmony_ci     - Contains packet traps for packets that hit an exception (e.g., TTL
53662306a36Sopenharmony_ci       error) during layer 3 forwarding
53762306a36Sopenharmony_ci   * - ``buffer_drops``
53862306a36Sopenharmony_ci     - Contains packet traps for packets that were dropped by the device due to
53962306a36Sopenharmony_ci       an enqueue decision
54062306a36Sopenharmony_ci   * - ``tunnel_drops``
54162306a36Sopenharmony_ci     - Contains packet traps for packets that were dropped by the device during
54262306a36Sopenharmony_ci       tunnel encapsulation / decapsulation
54362306a36Sopenharmony_ci   * - ``acl_drops``
54462306a36Sopenharmony_ci     - Contains packet traps for packets that were dropped by the device during
54562306a36Sopenharmony_ci       ACL processing
54662306a36Sopenharmony_ci   * - ``stp``
54762306a36Sopenharmony_ci     - Contains packet traps for STP packets
54862306a36Sopenharmony_ci   * - ``lacp``
54962306a36Sopenharmony_ci     - Contains packet traps for LACP packets
55062306a36Sopenharmony_ci   * - ``lldp``
55162306a36Sopenharmony_ci     - Contains packet traps for LLDP packets
55262306a36Sopenharmony_ci   * - ``mc_snooping``
55362306a36Sopenharmony_ci     - Contains packet traps for IGMP and MLD packets required for multicast
55462306a36Sopenharmony_ci       snooping
55562306a36Sopenharmony_ci   * - ``dhcp``
55662306a36Sopenharmony_ci     - Contains packet traps for DHCP packets
55762306a36Sopenharmony_ci   * - ``neigh_discovery``
55862306a36Sopenharmony_ci     - Contains packet traps for neighbour discovery packets (e.g., ARP, IPv6
55962306a36Sopenharmony_ci       ND)
56062306a36Sopenharmony_ci   * - ``bfd``
56162306a36Sopenharmony_ci     - Contains packet traps for BFD packets
56262306a36Sopenharmony_ci   * - ``ospf``
56362306a36Sopenharmony_ci     - Contains packet traps for OSPF packets
56462306a36Sopenharmony_ci   * - ``bgp``
56562306a36Sopenharmony_ci     - Contains packet traps for BGP packets
56662306a36Sopenharmony_ci   * - ``vrrp``
56762306a36Sopenharmony_ci     - Contains packet traps for VRRP packets
56862306a36Sopenharmony_ci   * - ``pim``
56962306a36Sopenharmony_ci     - Contains packet traps for PIM packets
57062306a36Sopenharmony_ci   * - ``uc_loopback``
57162306a36Sopenharmony_ci     - Contains a packet trap for unicast loopback packets (i.e.,
57262306a36Sopenharmony_ci       ``uc_loopback``). This trap is singled-out because in cases such as
57362306a36Sopenharmony_ci       one-armed router it will be constantly triggered. To limit the impact on
57462306a36Sopenharmony_ci       the CPU usage, a packet trap policer with a low rate can be bound to the
57562306a36Sopenharmony_ci       group without affecting other traps
57662306a36Sopenharmony_ci   * - ``local_delivery``
57762306a36Sopenharmony_ci     - Contains packet traps for packets that should be locally delivered after
57862306a36Sopenharmony_ci       routing, but do not match more specific packet traps (e.g.,
57962306a36Sopenharmony_ci       ``ipv4_bgp``)
58062306a36Sopenharmony_ci   * - ``external_delivery``
58162306a36Sopenharmony_ci     - Contains packet traps for packets that should be routed through an
58262306a36Sopenharmony_ci       external interface (e.g., management interface) that does not belong to
58362306a36Sopenharmony_ci       the same device (e.g., switch ASIC) as the ingress interface
58462306a36Sopenharmony_ci   * - ``ipv6``
58562306a36Sopenharmony_ci     - Contains packet traps for various IPv6 control packets (e.g., Router
58662306a36Sopenharmony_ci       Advertisements)
58762306a36Sopenharmony_ci   * - ``ptp_event``
58862306a36Sopenharmony_ci     - Contains packet traps for PTP time-critical event messages (Sync,
58962306a36Sopenharmony_ci       Delay_req, Pdelay_Req and Pdelay_Resp)
59062306a36Sopenharmony_ci   * - ``ptp_general``
59162306a36Sopenharmony_ci     - Contains packet traps for PTP general messages (Announce, Follow_Up,
59262306a36Sopenharmony_ci       Delay_Resp, Pdelay_Resp_Follow_Up, management and signaling)
59362306a36Sopenharmony_ci   * - ``acl_sample``
59462306a36Sopenharmony_ci     - Contains packet traps for packets that were sampled by the device during
59562306a36Sopenharmony_ci       ACL processing
59662306a36Sopenharmony_ci   * - ``acl_trap``
59762306a36Sopenharmony_ci     - Contains packet traps for packets that were trapped (logged) by the
59862306a36Sopenharmony_ci       device during ACL processing
59962306a36Sopenharmony_ci   * - ``parser_error_drops``
60062306a36Sopenharmony_ci     - Contains packet traps for packets that were marked by the device during
60162306a36Sopenharmony_ci       parsing as erroneous
60262306a36Sopenharmony_ci   * - ``eapol``
60362306a36Sopenharmony_ci     - Contains packet traps for "Extensible Authentication Protocol over LAN"
60462306a36Sopenharmony_ci       (EAPOL) packets specified in IEEE 802.1X
60562306a36Sopenharmony_ci
60662306a36Sopenharmony_ciPacket Trap Policers
60762306a36Sopenharmony_ci====================
60862306a36Sopenharmony_ci
60962306a36Sopenharmony_ciAs previously explained, the underlying device can trap certain packets to the
61062306a36Sopenharmony_ciCPU for processing. In most cases, the underlying device is capable of handling
61162306a36Sopenharmony_cipacket rates that are several orders of magnitude higher compared to those that
61262306a36Sopenharmony_cican be handled by the CPU.
61362306a36Sopenharmony_ci
61462306a36Sopenharmony_ciTherefore, in order to prevent the underlying device from overwhelming the CPU,
61562306a36Sopenharmony_cidevices usually include packet trap policers that are able to police the
61662306a36Sopenharmony_citrapped packets to rates that can be handled by the CPU.
61762306a36Sopenharmony_ci
61862306a36Sopenharmony_ciThe ``devlink-trap`` mechanism allows capable device drivers to register their
61962306a36Sopenharmony_cisupported packet trap policers with ``devlink``. The device driver can choose
62062306a36Sopenharmony_cito associate these policers with supported packet trap groups (see
62162306a36Sopenharmony_ci:ref:`Generic-Packet-Trap-Groups`) during its initialization, thereby exposing
62262306a36Sopenharmony_ciits default control plane policy to user space.
62362306a36Sopenharmony_ci
62462306a36Sopenharmony_ciDevice drivers should allow user space to change the parameters of the policers
62562306a36Sopenharmony_ci(e.g., rate, burst size) as well as the association between the policers and
62662306a36Sopenharmony_citrap groups by implementing the relevant callbacks.
62762306a36Sopenharmony_ci
62862306a36Sopenharmony_ciIf possible, device drivers should implement a callback that allows user space
62962306a36Sopenharmony_cito retrieve the number of packets that were dropped by the policer because its
63062306a36Sopenharmony_ciconfigured policy was violated.
63162306a36Sopenharmony_ci
63262306a36Sopenharmony_ciTesting
63362306a36Sopenharmony_ci=======
63462306a36Sopenharmony_ci
63562306a36Sopenharmony_ciSee ``tools/testing/selftests/drivers/net/netdevsim/devlink_trap.sh`` for a
63662306a36Sopenharmony_citest covering the core infrastructure. Test cases should be added for any new
63762306a36Sopenharmony_cifunctionality.
63862306a36Sopenharmony_ci
63962306a36Sopenharmony_ciDevice drivers should focus their tests on device-specific functionality, such
64062306a36Sopenharmony_cias the triggering of supported packet traps.
641