2 Copyright 2016 6WIND S.A.
3 Copyright 2016 Mellanox.
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
9 * Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
11 * Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in
13 the documentation and/or other materials provided with the
15 * Neither the name of 6WIND S.A. nor the names of its
16 contributors may be used to endorse or promote products derived
17 from this software without specific prior written permission.
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 Generic flow API (rte_flow)
34 ===========================
39 This API provides a generic means to configure hardware to match specific
40 ingress or egress traffic, alter its fate and query related counters
41 according to any number of user-defined rules.
43 It is named *rte_flow* after the prefix used for all its symbols, and is
44 defined in ``rte_flow.h``.
46 - Matching can be performed on packet data (protocol headers, payload) and
47 properties (e.g. associated physical port, virtual device function ID).
49 - Possible operations include dropping traffic, diverting it to specific
50 queues, to virtual/physical device functions or ports, performing tunnel
51 offloads, adding marks and so on.
53 It is slightly higher-level than the legacy filtering framework which it
54 encompasses and supersedes (including all functions and filter types) in
55 order to expose a single interface with an unambiguous behavior that is
56 common to all poll-mode drivers (PMDs).
64 A flow rule is the combination of attributes with a matching pattern and a
65 list of actions. Flow rules form the basis of this API.
67 Flow rules can have several distinct actions (such as counting,
68 encapsulating, decapsulating before redirecting packets to a particular
69 queue, etc.), instead of relying on several rules to achieve this and having
70 applications deal with hardware implementation details regarding their
73 Support for different priority levels on a rule basis is provided, for
74 example in order to force a more specific rule to come before a more generic
75 one for packets matched by both. However hardware support for more than a
76 single priority level cannot be guaranteed. When supported, the number of
77 available priority levels is usually low, which is why they can also be
78 implemented in software by PMDs (e.g. missing priority levels may be
79 emulated by reordering rules).
81 In order to remain as hardware-agnostic as possible, by default all rules
82 are considered to have the same priority, which means that the order between
83 overlapping rules (when a packet is matched by several filters) is
86 PMDs may refuse to create overlapping rules at a given priority level when
87 they can be detected (e.g. if a pattern matches an existing filter).
89 Thus predictable results for a given priority level can only be achieved
90 with non-overlapping rules, using perfect matching on all protocol layers.
92 Flow rules can also be grouped, the flow rule priority is specific to the
93 group they belong to. All flow rules in a given group are thus processed
94 either before or after another group.
96 Support for multiple actions per rule may be implemented internally on top
97 of non-default hardware priorities, as a result both features may not be
98 simultaneously available to applications.
100 Considering that allowed pattern/actions combinations cannot be known in
101 advance and would result in an impractically large number of capabilities to
102 expose, a method is provided to validate a given rule from the current
103 device configuration state.
105 This enables applications to check if the rule types they need is supported
106 at initialization time, before starting their data path. This method can be
107 used anytime, its only requirement being that the resources needed by a rule
108 should exist (e.g. a target RX queue should be configured first).
110 Each defined rule is associated with an opaque handle managed by the PMD,
111 applications are responsible for keeping it. These can be used for queries
112 and rules management, such as retrieving counters or other data and
115 To avoid resource leaks on the PMD side, handles must be explicitly
116 destroyed by the application before releasing associated resources such as
119 The following sections cover:
121 - **Attributes** (represented by ``struct rte_flow_attr``): properties of a
122 flow rule such as its direction (ingress or egress) and priority.
124 - **Pattern item** (represented by ``struct rte_flow_item``): part of a
125 matching pattern that either matches specific packet data or traffic
126 properties. It can also describe properties of the pattern itself, such as
129 - **Matching pattern**: traffic properties to look for, a combination of any
132 - **Actions** (represented by ``struct rte_flow_action``): operations to
133 perform whenever a packet is matched by a pattern.
141 Flow rules can be grouped by assigning them a common group number. Lower
142 values have higher priority. Group 0 has the highest priority.
144 Although optional, applications are encouraged to group similar rules as
145 much as possible to fully take advantage of hardware capabilities
146 (e.g. optimized matching) and work around limitations (e.g. a single pattern
147 type possibly allowed in a given group).
149 Note that support for more than a single group is not guaranteed.
154 A priority level can be assigned to a flow rule. Like groups, lower values
155 denote higher priority, with 0 as the maximum.
157 A rule with priority 0 in group 8 is always matched after a rule with
158 priority 8 in group 0.
160 Group and priority levels are arbitrary and up to the application, they do
161 not need to be contiguous nor start from 0, however the maximum number
162 varies between devices and may be affected by existing flow rules.
164 If a packet is matched by several rules of a given group for a given
165 priority level, the outcome is undefined. It can take any path, may be
166 duplicated or even cause unrecoverable errors.
168 Note that support for more than a single priority level is not guaranteed.
170 Attribute: Traffic direction
171 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
173 Flow rule patterns apply to inbound and/or outbound traffic.
175 In the context of this API, **ingress** and **egress** respectively stand
176 for **inbound** and **outbound** based on the standpoint of the application
177 creating a flow rule.
179 There are no exceptions to this definition.
181 Several pattern items and actions are valid and can be used in both
182 directions. At least one direction must be specified.
184 Specifying both directions at once for a given rule is not recommended but
185 may be valid in a few cases (e.g. shared counters).
190 Instead of simply matching the properties of traffic as it would appear on a
191 given DPDK port ID, enabling this attribute transfers a flow rule to the
192 lowest possible level of any device endpoints found in the pattern.
194 When supported, this effectively enables an application to reroute traffic
195 not necessarily intended for it (e.g. coming from or addressed to different
196 physical ports, VFs or applications) at the device level.
198 It complements the behavior of some pattern items such as `Item: PHY_PORT`_
199 and is meaningless without them.
201 When transferring flow rules, **ingress** and **egress** attributes
202 (`Attribute: Traffic direction`_) keep their original meaning, as if
203 processing traffic emitted or received by the application.
208 Pattern items fall in two categories:
210 - Matching protocol headers and packet data, usually associated with a
211 specification structure. These must be stacked in the same order as the
212 protocol layers to match inside packets, starting from the lowest.
214 - Matching meta-data or affecting pattern processing, often without a
215 specification structure. Since they do not match packet contents, their
216 position in the list is usually not relevant.
218 Item specification structures are used to match specific values among
219 protocol fields (or item properties). Documentation describes for each item
220 whether they are associated with one and their type name if so.
222 Up to three structures of the same type can be set for a given item:
224 - ``spec``: values to match (e.g. a given IPv4 address).
226 - ``last``: upper bound for an inclusive range with corresponding fields in
229 - ``mask``: bit-mask applied to both ``spec`` and ``last`` whose purpose is
230 to distinguish the values to take into account and/or partially mask them
231 out (e.g. in order to match an IPv4 address prefix).
233 Usage restrictions and expected behavior:
235 - Setting either ``mask`` or ``last`` without ``spec`` is an error.
237 - Field values in ``last`` which are either 0 or equal to the corresponding
238 values in ``spec`` are ignored; they do not generate a range. Nonzero
239 values lower than those in ``spec`` are not supported.
241 - Setting ``spec`` and optionally ``last`` without ``mask`` causes the PMD
242 to use the default mask defined for that item (defined as
243 ``rte_flow_item_{name}_mask`` constants).
245 - Not setting any of them (assuming item type allows it) is equivalent to
246 providing an empty (zeroed) ``mask`` for broad (nonspecific) matching.
248 - ``mask`` is a simple bit-mask applied before interpreting the contents of
249 ``spec`` and ``last``, which may yield unexpected results if not used
250 carefully. For example, if for an IPv4 address field, ``spec`` provides
251 *10.1.2.3*, ``last`` provides *10.3.4.5* and ``mask`` provides
252 *255.255.0.0*, the effective range becomes *10.1.0.0* to *10.3.255.255*.
254 Example of an item specification matching an Ethernet header:
256 .. _table_rte_flow_pattern_item_example:
258 .. table:: Ethernet item
260 +----------+----------+--------------------+
261 | Field | Subfield | Value |
262 +==========+==========+====================+
263 | ``spec`` | ``src`` | ``00:01:02:03:04`` |
264 | +----------+--------------------+
265 | | ``dst`` | ``00:2a:66:00:01`` |
266 | +----------+--------------------+
267 | | ``type`` | ``0x22aa`` |
268 +----------+----------+--------------------+
269 | ``last`` | unspecified |
270 +----------+----------+--------------------+
271 | ``mask`` | ``src`` | ``00:ff:ff:ff:00`` |
272 | +----------+--------------------+
273 | | ``dst`` | ``00:00:00:00:ff`` |
274 | +----------+--------------------+
275 | | ``type`` | ``0x0000`` |
276 +----------+----------+--------------------+
278 Non-masked bits stand for any value (shown as ``?`` below), Ethernet headers
279 with the following properties are thus matched:
281 - ``src``: ``??:01:02:03:??``
282 - ``dst``: ``??:??:??:??:01``
283 - ``type``: ``0x????``
288 A pattern is formed by stacking items starting from the lowest protocol
289 layer to match. This stacking restriction does not apply to meta items which
290 can be placed anywhere in the stack without affecting the meaning of the
293 Patterns are terminated by END items.
297 .. _table_rte_flow_tcpv4_as_l4:
299 .. table:: TCPv4 as L4
315 .. _table_rte_flow_tcpv6_in_vxlan:
317 .. table:: TCPv6 in VXLAN
319 +-------+------------+
321 +=======+============+
323 +-------+------------+
325 +-------+------------+
327 +-------+------------+
329 +-------+------------+
331 +-------+------------+
333 +-------+------------+
335 +-------+------------+
337 +-------+------------+
341 .. _table_rte_flow_tcpv4_as_l4_meta:
343 .. table:: TCPv4 as L4 with meta items
365 The above example shows how meta items do not affect packet data matching
366 items, as long as those remain stacked properly. The resulting matching
367 pattern is identical to "TCPv4 as L4".
369 .. _table_rte_flow_udpv6_anywhere:
371 .. table:: UDPv6 anywhere
383 If supported by the PMD, omitting one or several protocol layers at the
384 bottom of the stack as in the above example (missing an Ethernet
385 specification) enables looking up anywhere in packets.
387 It is unspecified whether the payload of supported encapsulations
388 (e.g. VXLAN payload) is matched by such a pattern, which may apply to inner,
389 outer or both packets.
391 .. _table_rte_flow_invalid_l3:
393 .. table:: Invalid, missing L3
405 The above pattern is invalid due to a missing L3 specification between L2
406 (Ethernet) and L4 (UDP). Doing so is only allowed at the bottom and at the
412 They match meta-data or affect pattern processing instead of matching packet
413 data directly, most of them do not need a specification structure. This
414 particularity allows them to be specified anywhere in the stack without
415 causing any side effect.
420 End marker for item lists. Prevents further processing of items, thereby
423 - Its numeric value is 0 for convenience.
424 - PMD support is mandatory.
425 - ``spec``, ``last`` and ``mask`` are ignored.
427 .. _table_rte_flow_item_end:
431 +----------+---------+
433 +==========+=========+
434 | ``spec`` | ignored |
435 +----------+---------+
436 | ``last`` | ignored |
437 +----------+---------+
438 | ``mask`` | ignored |
439 +----------+---------+
444 Used as a placeholder for convenience. It is ignored and simply discarded by
447 - PMD support is mandatory.
448 - ``spec``, ``last`` and ``mask`` are ignored.
450 .. _table_rte_flow_item_void:
454 +----------+---------+
456 +==========+=========+
457 | ``spec`` | ignored |
458 +----------+---------+
459 | ``last`` | ignored |
460 +----------+---------+
461 | ``mask`` | ignored |
462 +----------+---------+
464 One usage example for this type is generating rules that share a common
465 prefix quickly without reallocating memory, only by updating item types:
467 .. _table_rte_flow_item_void_example:
469 .. table:: TCP, UDP or ICMP as L4
471 +-------+--------------------+
473 +=======+====================+
475 +-------+--------------------+
477 +-------+------+------+------+
478 | 2 | UDP | VOID | VOID |
479 +-------+------+------+------+
480 | 3 | VOID | TCP | VOID |
481 +-------+------+------+------+
482 | 4 | VOID | VOID | ICMP |
483 +-------+------+------+------+
485 +-------+--------------------+
490 Inverted matching, i.e. process packets that do not match the pattern.
492 - ``spec``, ``last`` and ``mask`` are ignored.
494 .. _table_rte_flow_item_invert:
498 +----------+---------+
500 +==========+=========+
501 | ``spec`` | ignored |
502 +----------+---------+
503 | ``last`` | ignored |
504 +----------+---------+
505 | ``mask`` | ignored |
506 +----------+---------+
508 Usage example, matching non-TCPv4 packets only:
510 .. _table_rte_flow_item_invert_example:
512 .. table:: Anything but TCPv4
531 Matches traffic originating from (ingress) or going to (egress) the physical
532 function of the current device.
534 If supported, should work even if the physical function is not managed by
535 the application and thus not associated with a DPDK port ID.
537 - Can be combined with any number of `Item: VF`_ to match both PF and VF
539 - ``spec``, ``last`` and ``mask`` must not be set.
541 .. _table_rte_flow_item_pf:
558 Matches traffic originating from (ingress) or going to (egress) a given
559 virtual function of the current device.
561 If supported, should work even if the virtual function is not managed by the
562 application and thus not associated with a DPDK port ID.
564 Note this pattern item does not match VF representors traffic which, as
565 separate entities, should be addressed through their own DPDK port IDs.
567 - Can be specified multiple times to match traffic addressed to several VF
569 - Can be combined with a PF item to match both PF and VF traffic.
570 - Default ``mask`` matches any VF ID.
572 .. _table_rte_flow_item_vf:
576 +----------+----------+---------------------------+
577 | Field | Subfield | Value |
578 +==========+==========+===========================+
579 | ``spec`` | ``id`` | destination VF ID |
580 +----------+----------+---------------------------+
581 | ``last`` | ``id`` | upper range value |
582 +----------+----------+---------------------------+
583 | ``mask`` | ``id`` | zeroed to match any VF ID |
584 +----------+----------+---------------------------+
589 Matches traffic originating from (ingress) or going to (egress) a physical
590 port of the underlying device.
592 The first PHY_PORT item overrides the physical port normally associated with
593 the specified DPDK input port (port_id). This item can be provided several
594 times to match additional physical ports.
596 Note that physical ports are not necessarily tied to DPDK input ports
597 (port_id) when those are not under DPDK control. Possible values are
598 specific to each device, they are not necessarily indexed from zero and may
601 As a device property, the list of allowed values as well as the value
602 associated with a port_id should be retrieved by other means.
604 - Default ``mask`` matches any port index.
606 .. _table_rte_flow_item_phy_port:
610 +----------+-----------+--------------------------------+
611 | Field | Subfield | Value |
612 +==========+===========+================================+
613 | ``spec`` | ``index`` | physical port index |
614 +----------+-----------+--------------------------------+
615 | ``last`` | ``index`` | upper range value |
616 +----------+-----------+--------------------------------+
617 | ``mask`` | ``index`` | zeroed to match any port index |
618 +----------+-----------+--------------------------------+
623 Matches traffic originating from (ingress) or going to (egress) a given DPDK
626 Normally only supported if the port ID in question is known by the
627 underlying PMD and related to the device the flow rule is created against.
629 This must not be confused with `Item: PHY_PORT`_ which refers to the
630 physical port of a device, whereas `Item: PORT_ID`_ refers to a ``struct
631 rte_eth_dev`` object on the application side (also known as "port
632 representor" depending on the kind of underlying device).
634 - Default ``mask`` matches the specified DPDK port ID.
636 .. _table_rte_flow_item_port_id:
640 +----------+----------+-----------------------------+
641 | Field | Subfield | Value |
642 +==========+==========+=============================+
643 | ``spec`` | ``id`` | DPDK port ID |
644 +----------+----------+-----------------------------+
645 | ``last`` | ``id`` | upper range value |
646 +----------+----------+-----------------------------+
647 | ``mask`` | ``id`` | zeroed to match any port ID |
648 +----------+----------+-----------------------------+
650 Data matching item types
651 ~~~~~~~~~~~~~~~~~~~~~~~~
653 Most of these are basically protocol header definitions with associated
654 bit-masks. They must be specified (stacked) from lowest to highest protocol
655 layer to form a matching pattern.
657 The following list is not exhaustive, new protocols will be added in the
663 Matches any protocol in place of the current layer, a single ANY may also
664 stand for several protocol layers.
666 This is usually specified as the first pattern item when looking for a
667 protocol anywhere in a packet.
669 - Default ``mask`` stands for any number of layers.
671 .. _table_rte_flow_item_any:
675 +----------+----------+--------------------------------------+
676 | Field | Subfield | Value |
677 +==========+==========+======================================+
678 | ``spec`` | ``num`` | number of layers covered |
679 +----------+----------+--------------------------------------+
680 | ``last`` | ``num`` | upper range value |
681 +----------+----------+--------------------------------------+
682 | ``mask`` | ``num`` | zeroed to cover any number of layers |
683 +----------+----------+--------------------------------------+
685 Example for VXLAN TCP payload matching regardless of outer L3 (IPv4 or IPv6)
686 and L4 (UDP) both matched by the first ANY specification, and inner L3 (IPv4
687 or IPv6) matched by the second ANY specification:
689 .. _table_rte_flow_item_any_example:
691 .. table:: TCP in VXLAN with wildcards
693 +-------+------+----------+----------+-------+
694 | Index | Item | Field | Subfield | Value |
695 +=======+======+==========+==========+=======+
697 +-------+------+----------+----------+-------+
698 | 1 | ANY | ``spec`` | ``num`` | 2 |
699 +-------+------+----------+----------+-------+
701 +-------+------------------------------------+
703 +-------+------+----------+----------+-------+
704 | 4 | ANY | ``spec`` | ``num`` | 1 |
705 +-------+------+----------+----------+-------+
707 +-------+------------------------------------+
709 +-------+------------------------------------+
714 Matches a byte string of a given length at a given offset.
716 Offset is either absolute (using the start of the packet) or relative to the
717 end of the previous matched item in the stack, in which case negative values
720 If search is enabled, offset is used as the starting point. The search area
721 can be delimited by setting limit to a nonzero value, which is the maximum
722 number of bytes after offset where the pattern may start.
724 Matching a zero-length pattern is allowed, doing so resets the relative
725 offset for subsequent items.
727 - This type does not support ranges (``last`` field).
728 - Default ``mask`` matches all fields exactly.
730 .. _table_rte_flow_item_raw:
734 +----------+--------------+-------------------------------------------------+
735 | Field | Subfield | Value |
736 +==========+==============+=================================================+
737 | ``spec`` | ``relative`` | look for pattern after the previous item |
738 | +--------------+-------------------------------------------------+
739 | | ``search`` | search pattern from offset (see also ``limit``) |
740 | +--------------+-------------------------------------------------+
741 | | ``reserved`` | reserved, must be set to zero |
742 | +--------------+-------------------------------------------------+
743 | | ``offset`` | absolute or relative offset for ``pattern`` |
744 | +--------------+-------------------------------------------------+
745 | | ``limit`` | search area limit for start of ``pattern`` |
746 | +--------------+-------------------------------------------------+
747 | | ``length`` | ``pattern`` length |
748 | +--------------+-------------------------------------------------+
749 | | ``pattern`` | byte string to look for |
750 +----------+--------------+-------------------------------------------------+
751 | ``last`` | if specified, either all 0 or with the same values as ``spec`` |
752 +----------+----------------------------------------------------------------+
753 | ``mask`` | bit-mask applied to ``spec`` values with usual behavior |
754 +----------+----------------------------------------------------------------+
756 Example pattern looking for several strings at various offsets of a UDP
757 payload, using combined RAW items:
759 .. _table_rte_flow_item_raw_example:
761 .. table:: UDP payload matching
763 +-------+------+----------+--------------+-------+
764 | Index | Item | Field | Subfield | Value |
765 +=======+======+==========+==============+=======+
767 +-------+----------------------------------------+
769 +-------+----------------------------------------+
771 +-------+------+----------+--------------+-------+
772 | 3 | RAW | ``spec`` | ``relative`` | 1 |
773 | | | +--------------+-------+
774 | | | | ``search`` | 1 |
775 | | | +--------------+-------+
776 | | | | ``offset`` | 10 |
777 | | | +--------------+-------+
778 | | | | ``limit`` | 0 |
779 | | | +--------------+-------+
780 | | | | ``length`` | 3 |
781 | | | +--------------+-------+
782 | | | | ``pattern`` | "foo" |
783 +-------+------+----------+--------------+-------+
784 | 4 | RAW | ``spec`` | ``relative`` | 1 |
785 | | | +--------------+-------+
786 | | | | ``search`` | 0 |
787 | | | +--------------+-------+
788 | | | | ``offset`` | 20 |
789 | | | +--------------+-------+
790 | | | | ``limit`` | 0 |
791 | | | +--------------+-------+
792 | | | | ``length`` | 3 |
793 | | | +--------------+-------+
794 | | | | ``pattern`` | "bar" |
795 +-------+------+----------+--------------+-------+
796 | 5 | RAW | ``spec`` | ``relative`` | 1 |
797 | | | +--------------+-------+
798 | | | | ``search`` | 0 |
799 | | | +--------------+-------+
800 | | | | ``offset`` | -29 |
801 | | | +--------------+-------+
802 | | | | ``limit`` | 0 |
803 | | | +--------------+-------+
804 | | | | ``length`` | 3 |
805 | | | +--------------+-------+
806 | | | | ``pattern`` | "baz" |
807 +-------+------+----------+--------------+-------+
809 +-------+----------------------------------------+
813 - Locate "foo" at least 10 bytes deep inside UDP payload.
814 - Locate "bar" after "foo" plus 20 bytes.
815 - Locate "baz" after "bar" minus 29 bytes.
817 Such a packet may be represented as follows (not to scale)::
820 | |<--------->| |<--------->|
822 |-----|------|-----|-----|-----|-----|-----------|-----|------|
823 | ETH | IPv4 | UDP | ... | baz | foo | ......... | bar | .... |
824 |-----|------|-----|-----|-----|-----|-----------|-----|------|
826 |<--------------------------->|
829 Note that matching subsequent pattern items would resume after "baz", not
830 "bar" since matching is always performed after the previous item of the
836 Matches an Ethernet header.
838 The ``type`` field either stands for "EtherType" or "TPID" when followed by
839 so-called layer 2.5 pattern items such as ``RTE_FLOW_ITEM_TYPE_VLAN``. In
840 the latter case, ``type`` refers to that of the outer header, with the inner
841 EtherType/TPID provided by the subsequent pattern item. This is the same
842 order as on the wire.
844 - ``dst``: destination MAC.
845 - ``src``: source MAC.
846 - ``type``: EtherType or TPID.
847 - Default ``mask`` matches destination and source addresses only.
852 Matches an 802.1Q/ad VLAN tag.
854 The corresponding standard outer EtherType (TPID) values are
855 ``ETHER_TYPE_VLAN`` or ``ETHER_TYPE_QINQ``. It can be overridden by the
856 preceding pattern item.
858 - ``tci``: tag control information.
859 - ``inner_type``: inner EtherType or TPID.
860 - Default ``mask`` matches the VID part of TCI only (lower 12 bits).
865 Matches an IPv4 header.
867 Note: IPv4 options are handled by dedicated pattern items.
869 - ``hdr``: IPv4 header definition (``rte_ip.h``).
870 - Default ``mask`` matches source and destination addresses only.
875 Matches an IPv6 header.
877 Note: IPv6 options are handled by dedicated pattern items, see `Item:
880 - ``hdr``: IPv6 header definition (``rte_ip.h``).
881 - Default ``mask`` matches source and destination addresses only.
886 Matches an ICMP header.
888 - ``hdr``: ICMP header definition (``rte_icmp.h``).
889 - Default ``mask`` matches ICMP type and code only.
894 Matches a UDP header.
896 - ``hdr``: UDP header definition (``rte_udp.h``).
897 - Default ``mask`` matches source and destination ports only.
902 Matches a TCP header.
904 - ``hdr``: TCP header definition (``rte_tcp.h``).
905 - Default ``mask`` matches source and destination ports only.
910 Matches a SCTP header.
912 - ``hdr``: SCTP header definition (``rte_sctp.h``).
913 - Default ``mask`` matches source and destination ports only.
918 Matches a VXLAN header (RFC 7348).
920 - ``flags``: normally 0x08 (I flag).
921 - ``rsvd0``: reserved, normally 0x000000.
922 - ``vni``: VXLAN network identifier.
923 - ``rsvd1``: reserved, normally 0x00.
924 - Default ``mask`` matches VNI only.
929 Matches an IEEE 802.1BR E-Tag header.
931 The corresponding standard outer EtherType (TPID) value is
932 ``ETHER_TYPE_ETAG``. It can be overridden by the preceding pattern item.
934 - ``epcp_edei_in_ecid_b``: E-Tag control information (E-TCI), E-PCP (3b),
935 E-DEI (1b), ingress E-CID base (12b).
936 - ``rsvd_grp_ecid_b``: reserved (2b), GRP (2b), E-CID base (12b).
937 - ``in_ecid_e``: ingress E-CID ext.
938 - ``ecid_e``: E-CID ext.
939 - ``inner_type``: inner EtherType or TPID.
940 - Default ``mask`` simultaneously matches GRP and E-CID base.
945 Matches a NVGRE header (RFC 7637).
947 - ``c_k_s_rsvd0_ver``: checksum (1b), undefined (1b), key bit (1b),
948 sequence number (1b), reserved 0 (9b), version (3b). This field must have
949 value 0x2000 according to RFC 7637.
950 - ``protocol``: protocol type (0x6558).
951 - ``tni``: virtual subnet ID.
952 - ``flow_id``: flow ID.
953 - Default ``mask`` matches TNI only.
958 Matches a MPLS header.
960 - ``label_tc_s_ttl``: label, TC, Bottom of Stack and TTL.
961 - Default ``mask`` matches label only.
966 Matches a GRE header.
968 - ``c_rsvd0_ver``: checksum, reserved 0 and version.
969 - ``protocol``: protocol type.
970 - Default ``mask`` matches protocol only.
975 Fuzzy pattern match, expect faster than default.
977 This is for device that support fuzzy match option. Usually a fuzzy match is
978 fast but the cost is accuracy. i.e. Signature Match only match pattern's hash
979 value, but it is possible two different patterns have the same hash value.
981 Matching accuracy level can be configured by threshold. Driver can divide the
982 range of threshold and map to different accuracy levels that device support.
984 Threshold 0 means perfect match (no fuzziness), while threshold 0xffffffff
985 means fuzziest match.
987 .. _table_rte_flow_item_fuzzy:
991 +----------+---------------+--------------------------------------------------+
992 | Field | Subfield | Value |
993 +==========+===============+==================================================+
994 | ``spec`` | ``threshold`` | 0 as perfect match, 0xffffffff as fuzziest match |
995 +----------+---------------+--------------------------------------------------+
996 | ``last`` | ``threshold`` | upper range value |
997 +----------+---------------+--------------------------------------------------+
998 | ``mask`` | ``threshold`` | bit-mask apply to "spec" and "last" |
999 +----------+---------------+--------------------------------------------------+
1001 Usage example, fuzzy match a TCPv4 packets:
1003 .. _table_rte_flow_item_fuzzy_example:
1005 .. table:: Fuzzy matching
1007 +-------+----------+
1009 +=======+==========+
1011 +-------+----------+
1013 +-------+----------+
1015 +-------+----------+
1017 +-------+----------+
1019 +-------+----------+
1021 Item: ``GTP``, ``GTPC``, ``GTPU``
1022 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1024 Matches a GTPv1 header.
1026 Note: GTP, GTPC and GTPU use the same structure. GTPC and GTPU item
1027 are defined for a user-friendly API when creating GTP-C and GTP-U
1030 - ``v_pt_rsv_flags``: version (3b), protocol type (1b), reserved (1b),
1031 extension header flag (1b), sequence number flag (1b), N-PDU number
1033 - ``msg_type``: message type.
1034 - ``msg_len``: message length.
1035 - ``teid``: tunnel endpoint identifier.
1036 - Default ``mask`` matches teid only.
1041 Matches an ESP header.
1043 - ``hdr``: ESP header definition (``rte_esp.h``).
1044 - Default ``mask`` matches SPI only.
1049 Matches a GENEVE header.
1051 - ``ver_opt_len_o_c_rsvd0``: version (2b), length of the options fields (6b),
1052 OAM packet (1b), critical options present (1b), reserved 0 (6b).
1053 - ``protocol``: protocol type.
1054 - ``vni``: virtual network identifier.
1055 - ``rsvd1``: reserved, normally 0x00.
1056 - Default ``mask`` matches VNI only.
1061 Matches a VXLAN-GPE header (draft-ietf-nvo3-vxlan-gpe-05).
1063 - ``flags``: normally 0x0C (I and P flags).
1064 - ``rsvd0``: reserved, normally 0x0000.
1065 - ``protocol``: protocol type.
1066 - ``vni``: VXLAN network identifier.
1067 - ``rsvd1``: reserved, normally 0x00.
1068 - Default ``mask`` matches VNI only.
1070 Item: ``ARP_ETH_IPV4``
1071 ^^^^^^^^^^^^^^^^^^^^^^
1073 Matches an ARP header for Ethernet/IPv4.
1075 - ``hdr``: hardware type, normally 1.
1076 - ``pro``: protocol type, normally 0x0800.
1077 - ``hln``: hardware address length, normally 6.
1078 - ``pln``: protocol address length, normally 4.
1079 - ``op``: opcode (1 for request, 2 for reply).
1080 - ``sha``: sender hardware address.
1081 - ``spa``: sender IPv4 address.
1082 - ``tha``: target hardware address.
1083 - ``tpa``: target IPv4 address.
1084 - Default ``mask`` matches SHA, SPA, THA and TPA.
1089 Matches the presence of any IPv6 extension header.
1091 - ``next_hdr``: next header.
1092 - Default ``mask`` matches ``next_hdr``.
1094 Normally preceded by any of:
1102 Matches any ICMPv6 header.
1104 - ``type``: ICMPv6 type.
1105 - ``code``: ICMPv6 code.
1106 - ``checksum``: ICMPv6 checksum.
1107 - Default ``mask`` matches ``type`` and ``code``.
1109 Item: ``ICMP6_ND_NS``
1110 ^^^^^^^^^^^^^^^^^^^^^
1112 Matches an ICMPv6 neighbor discovery solicitation.
1114 - ``type``: ICMPv6 type, normally 135.
1115 - ``code``: ICMPv6 code, normally 0.
1116 - ``checksum``: ICMPv6 checksum.
1117 - ``reserved``: reserved, normally 0.
1118 - ``target_addr``: target address.
1119 - Default ``mask`` matches target address only.
1121 Item: ``ICMP6_ND_NA``
1122 ^^^^^^^^^^^^^^^^^^^^^
1124 Matches an ICMPv6 neighbor discovery advertisement.
1126 - ``type``: ICMPv6 type, normally 136.
1127 - ``code``: ICMPv6 code, normally 0.
1128 - ``checksum``: ICMPv6 checksum.
1129 - ``rso_reserved``: route flag (1b), solicited flag (1b), override flag
1130 (1b), reserved (29b).
1131 - ``target_addr``: target address.
1132 - Default ``mask`` matches target address only.
1134 Item: ``ICMP6_ND_OPT``
1135 ^^^^^^^^^^^^^^^^^^^^^^
1137 Matches the presence of any ICMPv6 neighbor discovery option.
1139 - ``type``: ND option type.
1140 - ``length``: ND option length.
1141 - Default ``mask`` matches type only.
1143 Normally preceded by any of:
1145 - `Item: ICMP6_ND_NA`_
1146 - `Item: ICMP6_ND_NS`_
1147 - `Item: ICMP6_ND_OPT`_
1149 Item: ``ICMP6_ND_OPT_SLA_ETH``
1150 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1152 Matches an ICMPv6 neighbor discovery source Ethernet link-layer address
1155 - ``type``: ND option type, normally 1.
1156 - ``length``: ND option length, normally 1.
1157 - ``sla``: source Ethernet LLA.
1158 - Default ``mask`` matches source link-layer address only.
1160 Normally preceded by any of:
1162 - `Item: ICMP6_ND_NA`_
1163 - `Item: ICMP6_ND_OPT`_
1165 Item: ``ICMP6_ND_OPT_TLA_ETH``
1166 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1168 Matches an ICMPv6 neighbor discovery target Ethernet link-layer address
1171 - ``type``: ND option type, normally 2.
1172 - ``length``: ND option length, normally 1.
1173 - ``tla``: target Ethernet LLA.
1174 - Default ``mask`` matches target link-layer address only.
1176 Normally preceded by any of:
1178 - `Item: ICMP6_ND_NS`_
1179 - `Item: ICMP6_ND_OPT`_
1184 Each possible action is represented by a type. Some have associated
1185 configuration structures. Several actions combined in a list can be assigned
1186 to a flow rule and are performed in order.
1188 They fall in three categories:
1190 - Actions that modify the fate of matching traffic, for instance by dropping
1191 or assigning it a specific destination.
1193 - Actions that modify matching traffic contents or its properties. This
1194 includes adding/removing encapsulation, encryption, compression and marks.
1196 - Actions related to the flow rule itself, such as updating counters or
1197 making it non-terminating.
1199 Flow rules being terminating by default, not specifying any action of the
1200 fate kind results in undefined behavior. This applies to both ingress and
1203 PASSTHRU, when supported, makes a flow rule non-terminating.
1205 Like matching patterns, action lists are terminated by END items.
1207 Example of action that redirects packets to queue index 10:
1209 .. _table_rte_flow_action_example:
1211 .. table:: Queue action
1213 +-----------+-------+
1215 +===========+=======+
1217 +-----------+-------+
1219 Actions are performed in list order:
1221 .. _table_rte_flow_count_then_drop:
1223 .. table:: Count then drop
1237 .. _table_rte_flow_mark_count_redirect:
1239 .. table:: Mark, count then redirect
1241 +-------+--------+-----------+-------+
1242 | Index | Action | Field | Value |
1243 +=======+========+===========+=======+
1244 | 0 | MARK | ``mark`` | 0x2a |
1245 +-------+--------+-----------+-------+
1247 +-------+--------+-----------+-------+
1248 | 2 | QUEUE | ``queue`` | 10 |
1249 +-------+--------+-----------+-------+
1251 +-------+----------------------------+
1255 .. _table_rte_flow_redirect_queue_5:
1257 .. table:: Redirect to queue 5
1259 +-------+--------+-----------+-------+
1260 | Index | Action | Field | Value |
1261 +=======+========+===========+=======+
1263 +-------+--------+-----------+-------+
1264 | 1 | QUEUE | ``queue`` | 5 |
1265 +-------+--------+-----------+-------+
1267 +-------+----------------------------+
1269 In the above example, while DROP and QUEUE must be performed in order, both
1270 have to happen before reaching END. Only QUEUE has a visible effect.
1272 Note that such a list may be thought as ambiguous and rejected on that
1275 .. _table_rte_flow_redirect_queue_5_3:
1277 .. table:: Redirect to queues 5 and 3
1279 +-------+--------+-----------+-------+
1280 | Index | Action | Field | Value |
1281 +=======+========+===========+=======+
1282 | 0 | QUEUE | ``queue`` | 5 |
1283 +-------+--------+-----------+-------+
1285 +-------+--------+-----------+-------+
1286 | 2 | QUEUE | ``queue`` | 3 |
1287 +-------+--------+-----------+-------+
1289 +-------+----------------------------+
1291 As previously described, all actions must be taken into account. This
1292 effectively duplicates traffic to both queues. The above example also shows
1293 that VOID is ignored.
1298 Common action types are described in this section. Like pattern item types,
1299 this list is not exhaustive as new actions will be added in the future.
1304 End marker for action lists. Prevents further processing of actions, thereby
1307 - Its numeric value is 0 for convenience.
1308 - PMD support is mandatory.
1309 - No configurable properties.
1311 .. _table_rte_flow_action_end:
1324 Used as a placeholder for convenience. It is ignored and simply discarded by
1327 - PMD support is mandatory.
1328 - No configurable properties.
1330 .. _table_rte_flow_action_void:
1340 Action: ``PASSTHRU``
1341 ^^^^^^^^^^^^^^^^^^^^
1343 Leaves traffic up for additional processing by subsequent flow rules; makes
1344 a flow rule non-terminating.
1346 - No configurable properties.
1348 .. _table_rte_flow_action_passthru:
1358 Example to copy a packet to a queue and continue processing by subsequent
1361 .. _table_rte_flow_action_passthru_example:
1363 .. table:: Copy to queue 8
1365 +-------+--------+-----------+-------+
1366 | Index | Action | Field | Value |
1367 +=======+========+===========+=======+
1369 +-------+--------+-----------+-------+
1370 | 1 | QUEUE | ``queue`` | 8 |
1371 +-------+--------+-----------+-------+
1373 +-------+----------------------------+
1378 Attaches an integer value to packets and sets ``PKT_RX_FDIR`` and
1379 ``PKT_RX_FDIR_ID`` mbuf flags.
1381 This value is arbitrary and application-defined. Maximum allowed value
1382 depends on the underlying implementation. It is returned in the
1383 ``hash.fdir.hi`` mbuf field.
1385 .. _table_rte_flow_action_mark:
1389 +--------+--------------------------------------+
1391 +========+======================================+
1392 | ``id`` | integer value to return with packets |
1393 +--------+--------------------------------------+
1398 Flags packets. Similar to `Action: MARK`_ without a specific value; only
1399 sets the ``PKT_RX_FDIR`` mbuf flag.
1401 - No configurable properties.
1403 .. _table_rte_flow_action_flag:
1416 Assigns packets to a given queue index.
1418 .. _table_rte_flow_action_queue:
1422 +-----------+--------------------+
1424 +===========+====================+
1425 | ``index`` | queue index to use |
1426 +-----------+--------------------+
1433 - No configurable properties.
1435 .. _table_rte_flow_action_drop:
1448 Enables counters for this rule.
1450 These counters can be retrieved and reset through ``rte_flow_query()``, see
1451 ``struct rte_flow_query_count``.
1453 - Counters can be retrieved with ``rte_flow_query()``.
1454 - No configurable properties.
1456 .. _table_rte_flow_action_count:
1466 Query structure to retrieve and reset flow rule counters:
1468 .. _table_rte_flow_query_count:
1470 .. table:: COUNT query
1472 +---------------+-----+-----------------------------------+
1473 | Field | I/O | Value |
1474 +===============+=====+===================================+
1475 | ``reset`` | in | reset counter after query |
1476 +---------------+-----+-----------------------------------+
1477 | ``hits_set`` | out | ``hits`` field is set |
1478 +---------------+-----+-----------------------------------+
1479 | ``bytes_set`` | out | ``bytes`` field is set |
1480 +---------------+-----+-----------------------------------+
1481 | ``hits`` | out | number of hits for this rule |
1482 +---------------+-----+-----------------------------------+
1483 | ``bytes`` | out | number of bytes through this rule |
1484 +---------------+-----+-----------------------------------+
1489 Similar to QUEUE, except RSS is additionally performed on packets to spread
1490 them among several queues according to the provided parameters.
1492 Unlike global RSS settings used by other DPDK APIs, unsetting the ``types``
1493 field does not disable RSS in a flow rule. Doing so instead requests safe
1494 unspecified "best-effort" settings from the underlying PMD, which depending
1495 on the flow rule, may result in anything ranging from empty (single queue)
1496 to all-inclusive RSS.
1498 Note: RSS hash result is stored in the ``hash.rss`` mbuf field which
1499 overlaps ``hash.fdir.lo``. Since `Action: MARK`_ sets the ``hash.fdir.hi``
1500 field only, both can be requested simultaneously.
1502 Also, regarding packet encapsulation ``level``:
1504 - ``0`` requests the default behavior. Depending on the packet type, it can
1505 mean outermost, innermost, anything in between or even no RSS.
1507 It basically stands for the innermost encapsulation level RSS can be
1508 performed on according to PMD and device capabilities.
1510 - ``1`` requests RSS to be performed on the outermost packet encapsulation
1513 - ``2`` and subsequent values request RSS to be performed on the specified
1514 inner packet encapsulation level, from outermost to innermost (lower to
1517 Values other than ``0`` are not necessarily supported.
1519 Requesting a specific RSS level on unrecognized traffic results in undefined
1520 behavior. For predictable results, it is recommended to make the flow rule
1521 pattern match packet headers up to the requested encapsulation level so that
1522 only matching traffic goes through.
1524 .. _table_rte_flow_action_rss:
1528 +---------------+---------------------------------------------+
1530 +===============+=============================================+
1531 | ``func`` | RSS hash function to apply |
1532 +---------------+---------------------------------------------+
1533 | ``level`` | encapsulation level for ``types`` |
1534 +---------------+---------------------------------------------+
1535 | ``types`` | specific RSS hash types (see ``ETH_RSS_*``) |
1536 +---------------+---------------------------------------------+
1537 | ``key_len`` | hash key length in bytes |
1538 +---------------+---------------------------------------------+
1539 | ``queue_num`` | number of entries in ``queue`` |
1540 +---------------+---------------------------------------------+
1541 | ``key`` | hash key |
1542 +---------------+---------------------------------------------+
1543 | ``queue`` | queue indices to use |
1544 +---------------+---------------------------------------------+
1549 Directs matching traffic to the physical function (PF) of the current
1554 - No configurable properties.
1556 .. _table_rte_flow_action_pf:
1569 Directs matching traffic to a given virtual function of the current device.
1571 Packets matched by a VF pattern item can be redirected to their original VF
1572 ID instead of the specified one. This parameter may not be available and is
1573 not guaranteed to work properly if the VF part is matched by a prior flow
1574 rule or if packets are not addressed to a VF in the first place.
1578 .. _table_rte_flow_action_vf:
1582 +--------------+--------------------------------+
1584 +==============+================================+
1585 | ``original`` | use original VF ID if possible |
1586 +--------------+--------------------------------+
1588 +--------------+--------------------------------+
1590 Action: ``PHY_PORT``
1591 ^^^^^^^^^^^^^^^^^^^^
1593 Directs matching traffic to a given physical port index of the underlying
1596 See `Item: PHY_PORT`_.
1598 .. _table_rte_flow_action_phy_port:
1602 +--------------+-------------------------------------+
1604 +==============+=====================================+
1605 | ``original`` | use original port index if possible |
1606 +--------------+-------------------------------------+
1607 | ``index`` | physical port index |
1608 +--------------+-------------------------------------+
1612 Directs matching traffic to a given DPDK port ID.
1614 See `Item: PORT_ID`_.
1616 .. _table_rte_flow_action_port_id:
1620 +--------------+---------------------------------------+
1622 +==============+=======================================+
1623 | ``original`` | use original DPDK port ID if possible |
1624 +--------------+---------------------------------------+
1625 | ``id`` | DPDK port ID |
1626 +--------------+---------------------------------------+
1631 Applies a stage of metering and policing.
1633 The metering and policing (MTR) object has to be first created using the
1634 rte_mtr_create() API function. The ID of the MTR object is specified as
1635 action parameter. More than one flow can use the same MTR object through
1636 the meter action. The MTR object can be further updated or queried using
1639 .. _table_rte_flow_action_meter:
1643 +--------------+---------------+
1645 +==============+===============+
1646 | ``mtr_id`` | MTR object ID |
1647 +--------------+---------------+
1649 Action: ``SECURITY``
1650 ^^^^^^^^^^^^^^^^^^^^
1652 Perform the security action on flows matched by the pattern items
1653 according to the configuration of the security session.
1655 This action modifies the payload of matched flows. For INLINE_CRYPTO, the
1656 security protocol headers and IV are fully provided by the application as
1657 specified in the flow pattern. The payload of matching packets is
1658 encrypted on egress, and decrypted and authenticated on ingress.
1659 For INLINE_PROTOCOL, the security protocol is fully offloaded to HW,
1660 providing full encapsulation and decapsulation of packets in security
1661 protocols. The flow pattern specifies both the outer security header fields
1662 and the inner packet fields. The security session specified in the action
1663 must match the pattern parameters.
1665 The security session specified in the action must be created on the same
1666 port as the flow action that is being specified.
1668 The ingress/egress flow attribute should match that specified in the
1669 security session if the security session supports the definition of the
1672 Multiple flows can be configured to use the same security session.
1674 .. _table_rte_flow_action_security:
1678 +----------------------+--------------------------------------+
1680 +======================+======================================+
1681 | ``security_session`` | security session to apply |
1682 +----------------------+--------------------------------------+
1684 The following is an example of configuring IPsec inline using the
1685 INLINE_CRYPTO security session:
1687 The encryption algorithm, keys and salt are part of the opaque
1688 ``rte_security_session``. The SA is identified according to the IP and ESP
1689 fields in the pattern items.
1691 .. _table_rte_flow_item_esp_inline_example:
1693 .. table:: IPsec inline crypto flow pattern items.
1695 +-------+----------+
1697 +=======+==========+
1699 +-------+----------+
1701 +-------+----------+
1703 +-------+----------+
1705 +-------+----------+
1707 .. _table_rte_flow_action_esp_inline_example:
1709 .. table:: IPsec inline flow actions.
1711 +-------+----------+
1713 +=======+==========+
1715 +-------+----------+
1717 +-------+----------+
1719 Action: ``OF_SET_MPLS_TTL``
1720 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1722 Implements ``OFPAT_SET_MPLS_TTL`` ("MPLS TTL") as defined by the `OpenFlow
1723 Switch Specification`_.
1725 .. _table_rte_flow_action_of_set_mpls_ttl:
1727 .. table:: OF_SET_MPLS_TTL
1729 +--------------+----------+
1731 +==============+==========+
1732 | ``mpls_ttl`` | MPLS TTL |
1733 +--------------+----------+
1735 Action: ``OF_DEC_MPLS_TTL``
1736 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1738 Implements ``OFPAT_DEC_MPLS_TTL`` ("decrement MPLS TTL") as defined by the
1739 `OpenFlow Switch Specification`_.
1741 .. _table_rte_flow_action_of_dec_mpls_ttl:
1743 .. table:: OF_DEC_MPLS_TTL
1751 Action: ``OF_SET_NW_TTL``
1752 ^^^^^^^^^^^^^^^^^^^^^^^^^
1754 Implements ``OFPAT_SET_NW_TTL`` ("IP TTL") as defined by the `OpenFlow
1755 Switch Specification`_.
1757 .. _table_rte_flow_action_of_set_nw_ttl:
1759 .. table:: OF_SET_NW_TTL
1761 +------------+--------+
1763 +============+========+
1764 | ``nw_ttl`` | IP TTL |
1765 +------------+--------+
1767 Action: ``OF_DEC_NW_TTL``
1768 ^^^^^^^^^^^^^^^^^^^^^^^^^
1770 Implements ``OFPAT_DEC_NW_TTL`` ("decrement IP TTL") as defined by the
1771 `OpenFlow Switch Specification`_.
1773 .. _table_rte_flow_action_of_dec_nw_ttl:
1775 .. table:: OF_DEC_NW_TTL
1783 Action: ``OF_COPY_TTL_OUT``
1784 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1786 Implements ``OFPAT_COPY_TTL_OUT`` ("copy TTL "outwards" -- from
1787 next-to-outermost to outermost") as defined by the `OpenFlow Switch
1790 .. _table_rte_flow_action_of_copy_ttl_out:
1792 .. table:: OF_COPY_TTL_OUT
1800 Action: ``OF_COPY_TTL_IN``
1801 ^^^^^^^^^^^^^^^^^^^^^^^^^^
1803 Implements ``OFPAT_COPY_TTL_IN`` ("copy TTL "inwards" -- from outermost to
1804 next-to-outermost") as defined by the `OpenFlow Switch Specification`_.
1806 .. _table_rte_flow_action_of_copy_ttl_in:
1808 .. table:: OF_COPY_TTL_IN
1819 All specified pattern items (``enum rte_flow_item_type``) and actions
1820 (``enum rte_flow_action_type``) use positive identifiers.
1822 The negative space is reserved for dynamic types generated by PMDs during
1823 run-time. PMDs may encounter them as a result but must not accept negative
1824 identifiers they are not aware of.
1826 A method to generate them remains to be defined.
1831 Pattern item types will be added as new protocols are implemented.
1833 Variable headers support through dedicated pattern items, for example in
1834 order to match specific IPv4 options and IPv6 extension headers would be
1835 stacked after IPv4/IPv6 items.
1837 Other action types are planned but are not defined yet. These include the
1838 ability to alter packet data in several ways, such as performing
1839 encapsulation/decapsulation of tunnel headers.
1844 A rather simple API with few functions is provided to fully manage flow
1847 Each created flow rule is associated with an opaque, PMD-specific handle
1848 pointer. The application is responsible for keeping it until the rule is
1851 Flows rules are represented by ``struct rte_flow`` objects.
1856 Given that expressing a definite set of device capabilities is not
1857 practical, a dedicated function is provided to check if a flow rule is
1858 supported and can be created.
1863 rte_flow_validate(uint16_t port_id,
1864 const struct rte_flow_attr *attr,
1865 const struct rte_flow_item pattern[],
1866 const struct rte_flow_action actions[],
1867 struct rte_flow_error *error);
1869 The flow rule is validated for correctness and whether it could be accepted
1870 by the device given sufficient resources. The rule is checked against the
1871 current device mode and queue configuration. The flow rule may also
1872 optionally be validated against existing flow rules and device resources.
1873 This function has no effect on the target device.
1875 The returned value is guaranteed to remain valid only as long as no
1876 successful calls to ``rte_flow_create()`` or ``rte_flow_destroy()`` are made
1877 in the meantime and no device parameter affecting flow rules in any way are
1878 modified, due to possible collisions or resource limitations (although in
1879 such cases ``EINVAL`` should not be returned).
1883 - ``port_id``: port identifier of Ethernet device.
1884 - ``attr``: flow rule attributes.
1885 - ``pattern``: pattern specification (list terminated by the END pattern
1887 - ``actions``: associated actions (list terminated by the END action).
1888 - ``error``: perform verbose error reporting if not NULL. PMDs initialize
1889 this structure in case of error only.
1893 - 0 if flow rule is valid and can be created. A negative errno value
1894 otherwise (``rte_errno`` is also set), the following errors are defined.
1895 - ``-ENOSYS``: underlying device does not support this functionality.
1896 - ``-EINVAL``: unknown or invalid rule specification.
1897 - ``-ENOTSUP``: valid but unsupported rule specification (e.g. partial
1898 bit-masks are unsupported).
1899 - ``EEXIST``: collision with an existing rule. Only returned if device
1900 supports flow rule collision checking and there was a flow rule
1901 collision. Not receiving this return code is no guarantee that creating
1902 the rule will not fail due to a collision.
1903 - ``ENOMEM``: not enough memory to execute the function, or if the device
1904 supports resource validation, resource limitation on the device.
1905 - ``-EBUSY``: action cannot be performed due to busy device resources, may
1906 succeed if the affected queues or even the entire port are in a stopped
1907 state (see ``rte_eth_dev_rx_queue_stop()`` and ``rte_eth_dev_stop()``).
1912 Creating a flow rule is similar to validating one, except the rule is
1913 actually created and a handle returned.
1918 rte_flow_create(uint16_t port_id,
1919 const struct rte_flow_attr *attr,
1920 const struct rte_flow_item pattern[],
1921 const struct rte_flow_action *actions[],
1922 struct rte_flow_error *error);
1926 - ``port_id``: port identifier of Ethernet device.
1927 - ``attr``: flow rule attributes.
1928 - ``pattern``: pattern specification (list terminated by the END pattern
1930 - ``actions``: associated actions (list terminated by the END action).
1931 - ``error``: perform verbose error reporting if not NULL. PMDs initialize
1932 this structure in case of error only.
1936 A valid handle in case of success, NULL otherwise and ``rte_errno`` is set
1937 to the positive version of one of the error codes defined for
1938 ``rte_flow_validate()``.
1943 Flow rules destruction is not automatic, and a queue or a port should not be
1944 released if any are still attached to them. Applications must take care of
1945 performing this step before releasing resources.
1950 rte_flow_destroy(uint16_t port_id,
1951 struct rte_flow *flow,
1952 struct rte_flow_error *error);
1955 Failure to destroy a flow rule handle may occur when other flow rules depend
1956 on it, and destroying it would result in an inconsistent state.
1958 This function is only guaranteed to succeed if handles are destroyed in
1959 reverse order of their creation.
1963 - ``port_id``: port identifier of Ethernet device.
1964 - ``flow``: flow rule handle to destroy.
1965 - ``error``: perform verbose error reporting if not NULL. PMDs initialize
1966 this structure in case of error only.
1970 - 0 on success, a negative errno value otherwise and ``rte_errno`` is set.
1975 Convenience function to destroy all flow rule handles associated with a
1976 port. They are released as with successive calls to ``rte_flow_destroy()``.
1981 rte_flow_flush(uint16_t port_id,
1982 struct rte_flow_error *error);
1984 In the unlikely event of failure, handles are still considered destroyed and
1985 no longer valid but the port must be assumed to be in an inconsistent state.
1989 - ``port_id``: port identifier of Ethernet device.
1990 - ``error``: perform verbose error reporting if not NULL. PMDs initialize
1991 this structure in case of error only.
1995 - 0 on success, a negative errno value otherwise and ``rte_errno`` is set.
2000 Query an existing flow rule.
2002 This function allows retrieving flow-specific data such as counters. Data
2003 is gathered by special actions which must be present in the flow rule
2009 rte_flow_query(uint16_t port_id,
2010 struct rte_flow *flow,
2011 enum rte_flow_action_type action,
2013 struct rte_flow_error *error);
2017 - ``port_id``: port identifier of Ethernet device.
2018 - ``flow``: flow rule handle to query.
2019 - ``action``: action type to query.
2020 - ``data``: pointer to storage for the associated query data type.
2021 - ``error``: perform verbose error reporting if not NULL. PMDs initialize
2022 this structure in case of error only.
2026 - 0 on success, a negative errno value otherwise and ``rte_errno`` is set.
2031 The general expectation for ingress traffic is that flow rules process it
2032 first; the remaining unmatched or pass-through traffic usually ends up in a
2033 queue (with or without RSS, locally or in some sub-device instance)
2034 depending on the global configuration settings of a port.
2036 While fine from a compatibility standpoint, this approach makes drivers more
2037 complex as they have to check for possible side effects outside of this API
2038 when creating or destroying flow rules. It results in a more limited set of
2039 available rule types due to the way device resources are assigned (e.g. no
2040 support for the RSS action even on capable hardware).
2042 Given that nonspecific traffic can be handled by flow rules as well,
2043 isolated mode is a means for applications to tell a driver that ingress on
2044 the underlying port must be injected from the defined flow rules only; that
2045 no default traffic is expected outside those rules.
2047 This has the following benefits:
2049 - Applications get finer-grained control over the kind of traffic they want
2050 to receive (no traffic by default).
2052 - More importantly they control at what point nonspecific traffic is handled
2053 relative to other flow rules, by adjusting priority levels.
2055 - Drivers can assign more hardware resources to flow rules and expand the
2056 set of supported rule types.
2058 Because toggling isolated mode may cause profound changes to the ingress
2059 processing path of a driver, it may not be possible to leave it once
2060 entered. Likewise, existing flow rules or global configuration settings may
2061 prevent a driver from entering isolated mode.
2063 Applications relying on this mode are therefore encouraged to toggle it as
2064 soon as possible after device initialization, ideally before the first call
2065 to ``rte_eth_dev_configure()`` to avoid possible failures due to conflicting
2068 Once effective, the following functionality has no effect on the underlying
2069 port and may return errors such as ``ENOTSUP`` ("not supported"):
2071 - Toggling promiscuous mode.
2072 - Toggling allmulticast mode.
2073 - Configuring MAC addresses.
2074 - Configuring multicast addresses.
2075 - Configuring VLAN filters.
2076 - Configuring Rx filters through the legacy API (e.g. FDIR).
2077 - Configuring global RSS settings.
2082 rte_flow_isolate(uint16_t port_id, int set, struct rte_flow_error *error);
2086 - ``port_id``: port identifier of Ethernet device.
2087 - ``set``: nonzero to enter isolated mode, attempt to leave it otherwise.
2088 - ``error``: perform verbose error reporting if not NULL. PMDs initialize
2089 this structure in case of error only.
2093 - 0 on success, a negative errno value otherwise and ``rte_errno`` is set.
2095 Verbose error reporting
2096 -----------------------
2098 The defined *errno* values may not be accurate enough for users or
2099 application developers who want to investigate issues related to flow rules
2100 management. A dedicated error object is defined for this purpose:
2104 enum rte_flow_error_type {
2105 RTE_FLOW_ERROR_TYPE_NONE, /**< No error. */
2106 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, /**< Cause unspecified. */
2107 RTE_FLOW_ERROR_TYPE_HANDLE, /**< Flow rule (handle). */
2108 RTE_FLOW_ERROR_TYPE_ATTR_GROUP, /**< Group field. */
2109 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY, /**< Priority field. */
2110 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS, /**< Ingress field. */
2111 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, /**< Egress field. */
2112 RTE_FLOW_ERROR_TYPE_ATTR, /**< Attributes structure. */
2113 RTE_FLOW_ERROR_TYPE_ITEM_NUM, /**< Pattern length. */
2114 RTE_FLOW_ERROR_TYPE_ITEM, /**< Specific pattern item. */
2115 RTE_FLOW_ERROR_TYPE_ACTION_NUM, /**< Number of actions. */
2116 RTE_FLOW_ERROR_TYPE_ACTION, /**< Specific action. */
2119 struct rte_flow_error {
2120 enum rte_flow_error_type type; /**< Cause field and error types. */
2121 const void *cause; /**< Object responsible for the error. */
2122 const char *message; /**< Human-readable error message. */
2125 Error type ``RTE_FLOW_ERROR_TYPE_NONE`` stands for no error, in which case
2126 remaining fields can be ignored. Other error types describe the type of the
2127 object pointed by ``cause``.
2129 If non-NULL, ``cause`` points to the object responsible for the error. For a
2130 flow rule, this may be a pattern item or an individual action.
2132 If non-NULL, ``message`` provides a human-readable error message.
2134 This object is normally allocated by applications and set by PMDs in case of
2135 error, the message points to a constant string which does not need to be
2136 freed by the application, however its pointer can be considered valid only
2137 as long as its associated DPDK port remains configured. Closing the
2138 underlying device or unloading the PMD invalidates it.
2149 rte_flow_error_set(struct rte_flow_error *error,
2151 enum rte_flow_error_type type,
2153 const char *message);
2155 This function initializes ``error`` (if non-NULL) with the provided
2156 parameters and sets ``rte_errno`` to ``code``. A negative error ``code`` is
2162 - DPDK does not keep track of flow rules definitions or flow rule objects
2163 automatically. Applications may keep track of the former and must keep
2164 track of the latter. PMDs may also do it for internal needs, however this
2165 must not be relied on by applications.
2167 - Flow rules are not maintained between successive port initializations. An
2168 application exiting without releasing them and restarting must re-create
2171 - API operations are synchronous and blocking (``EAGAIN`` cannot be
2174 - There is no provision for reentrancy/multi-thread safety, although nothing
2175 should prevent different devices from being configured at the same
2176 time. PMDs may protect their control path functions accordingly.
2178 - Stopping the data path (TX/RX) should not be necessary when managing flow
2179 rules. If this cannot be achieved naturally or with workarounds (such as
2180 temporarily replacing the burst function pointers), an appropriate error
2181 code must be returned (``EBUSY``).
2183 - PMDs, not applications, are responsible for maintaining flow rules
2184 configuration when stopping and restarting a port or performing other
2185 actions which may affect them. They can only be destroyed explicitly by
2188 For devices exposing multiple ports sharing global settings affected by flow
2191 - All ports under DPDK control must behave consistently, PMDs are
2192 responsible for making sure that existing flow rules on a port are not
2193 affected by other ports.
2195 - Ports not under DPDK control (unaffected or handled by other applications)
2196 are user's responsibility. They may affect existing flow rules and cause
2197 undefined behavior. PMDs aware of this may prevent flow rules creation
2198 altogether in such cases.
2203 The PMD interface is defined in ``rte_flow_driver.h``. It is not subject to
2204 API/ABI versioning constraints as it is not exposed to applications and may
2205 evolve independently.
2207 It is currently implemented on top of the legacy filtering framework through
2208 filter type *RTE_ETH_FILTER_GENERIC* that accepts the single operation
2209 *RTE_ETH_FILTER_GET* to return PMD-specific *rte_flow* callbacks wrapped
2210 inside ``struct rte_flow_ops``.
2212 This overhead is temporarily necessary in order to keep compatibility with
2213 the legacy filtering framework, which should eventually disappear.
2215 - PMD callbacks implement exactly the interface described in `Rules
2216 management`_, except for the port ID argument which has already been
2217 converted to a pointer to the underlying ``struct rte_eth_dev``.
2219 - Public API functions do not process flow rules definitions at all before
2220 calling PMD functions (no basic error checking, no validation
2221 whatsoever). They only make sure these callbacks are non-NULL or return
2222 the ``ENOSYS`` (function not supported) error.
2224 This interface additionally defines the following helper function:
2226 - ``rte_flow_ops_get()``: get generic flow operations structure from a
2229 More will be added over time.
2231 Device compatibility
2232 --------------------
2234 No known implementation supports all the described features.
2236 Unsupported features or combinations are not expected to be fully emulated
2237 in software by PMDs for performance reasons. Partially supported features
2238 may be completed in software as long as hardware performs most of the work
2239 (such as queue redirection and packet recognition).
2241 However PMDs are expected to do their best to satisfy application requests
2242 by working around hardware limitations as long as doing so does not affect
2243 the behavior of existing flow rules.
2245 The following sections provide a few examples of such cases and describe how
2246 PMDs should handle them, they are based on limitations built into the
2252 Each flow rule comes with its own, per-layer bit-masks, while hardware may
2253 support only a single, device-wide bit-mask for a given layer type, so that
2254 two IPv4 rules cannot use different bit-masks.
2256 The expected behavior in this case is that PMDs automatically configure
2257 global bit-masks according to the needs of the first flow rule created.
2259 Subsequent rules are allowed only if their bit-masks match those, the
2260 ``EEXIST`` error code should be returned otherwise.
2262 Unsupported layer types
2263 ~~~~~~~~~~~~~~~~~~~~~~~
2265 Many protocols can be simulated by crafting patterns with the `Item: RAW`_
2268 PMDs can rely on this capability to simulate support for protocols with
2269 headers not directly recognized by hardware.
2271 ``ANY`` pattern item
2272 ~~~~~~~~~~~~~~~~~~~~
2274 This pattern item stands for anything, which can be difficult to translate
2275 to something hardware would understand, particularly if followed by more
2278 Consider the following pattern:
2280 .. _table_rte_flow_unsupported_any:
2282 .. table:: Pattern with ANY as L3
2284 +-------+-----------------------+
2286 +=======+=======================+
2288 +-------+-----+---------+-------+
2289 | 1 | ANY | ``num`` | ``1`` |
2290 +-------+-----+---------+-------+
2292 +-------+-----------------------+
2294 +-------+-----------------------+
2296 Knowing that TCP does not make sense with something other than IPv4 and IPv6
2297 as L3, such a pattern may be translated to two flow rules instead:
2299 .. _table_rte_flow_unsupported_any_ipv4:
2301 .. table:: ANY replaced with IPV4
2303 +-------+--------------------+
2305 +=======+====================+
2307 +-------+--------------------+
2308 | 1 | IPV4 (zeroed mask) |
2309 +-------+--------------------+
2311 +-------+--------------------+
2313 +-------+--------------------+
2317 .. _table_rte_flow_unsupported_any_ipv6:
2319 .. table:: ANY replaced with IPV6
2321 +-------+--------------------+
2323 +=======+====================+
2325 +-------+--------------------+
2326 | 1 | IPV6 (zeroed mask) |
2327 +-------+--------------------+
2329 +-------+--------------------+
2331 +-------+--------------------+
2333 Note that as soon as a ANY rule covers several layers, this approach may
2334 yield a large number of hidden flow rules. It is thus suggested to only
2335 support the most common scenarios (anything as L2 and/or L3).
2340 - When combined with `Action: QUEUE`_, packet counting (`Action: COUNT`_)
2341 and tagging (`Action: MARK`_ or `Action: FLAG`_) may be implemented in
2342 software as long as the target queue is used by a single rule.
2344 - When a single target queue is provided, `Action: RSS`_ can also be
2345 implemented through `Action: QUEUE`_.
2350 While it would naturally make sense, flow rules cannot be assumed to be
2351 processed by hardware in the same order as their creation for several
2354 - They may be managed internally as a tree or a hash table instead of a
2356 - Removing a flow rule before adding another one can either put the new rule
2357 at the end of the list or reuse a freed entry.
2358 - Duplication may occur when packets are matched by several rules.
2360 For overlapping rules (particularly in order to use `Action: PASSTHRU`_)
2361 predictable behavior is only guaranteed by using different priority levels.
2363 Priority levels are not necessarily implemented in hardware, or may be
2364 severely limited (e.g. a single priority bit).
2366 For these reasons, priority levels may be implemented purely in software by
2369 - For devices expecting flow rules to be added in the correct order, PMDs
2370 may destroy and re-create existing rules after adding a new one with
2373 - A configurable number of dummy or empty rules can be created at
2374 initialization time to save high priority slots for later.
2376 - In order to save priority levels, PMDs may evaluate whether rules are
2377 likely to collide and adjust their priority accordingly.
2382 - A device profile selection function which could be used to force a
2383 permanent profile instead of relying on its automatic configuration based
2384 on existing flow rules.
2386 - A method to optimize *rte_flow* rules with specific pattern items and
2387 action types generated on the fly by PMDs. DPDK should assign negative
2388 numbers to these in order to not collide with the existing types. See
2391 - Adding specific egress pattern items and actions as described in
2392 `Attribute: Traffic direction`_.
2394 - Optional software fallback when PMDs are unable to handle requested flow
2395 rules so applications do not have to implement their own.
2397 .. _OpenFlow Switch Specification: https://www.opennetworking.org/software-defined-standards/specifications/