1 .. SPDX-License-Identifier: BSD-3-Clause
2 Copyright 2016 6WIND S.A.
3 Copyright 2016 Mellanox Technologies, Ltd
5 Generic flow API (rte_flow)
6 ===========================
11 This API provides a generic means to configure hardware to match specific
12 ingress or egress traffic, alter its fate and query related counters
13 according to any number of user-defined rules.
15 It is named *rte_flow* after the prefix used for all its symbols, and is
16 defined in ``rte_flow.h``.
18 - Matching can be performed on packet data (protocol headers, payload) and
19 properties (e.g. associated physical port, virtual device function ID).
21 - Possible operations include dropping traffic, diverting it to specific
22 queues, to virtual/physical device functions or ports, performing tunnel
23 offloads, adding marks and so on.
25 It is slightly higher-level than the legacy filtering framework which it
26 encompasses and supersedes (including all functions and filter types) in
27 order to expose a single interface with an unambiguous behavior that is
28 common to all poll-mode drivers (PMDs).
36 A flow rule is the combination of attributes with a matching pattern and a
37 list of actions. Flow rules form the basis of this API.
39 Flow rules can have several distinct actions (such as counting,
40 encapsulating, decapsulating before redirecting packets to a particular
41 queue, etc.), instead of relying on several rules to achieve this and having
42 applications deal with hardware implementation details regarding their
45 Support for different priority levels on a rule basis is provided, for
46 example in order to force a more specific rule to come before a more generic
47 one for packets matched by both. However hardware support for more than a
48 single priority level cannot be guaranteed. When supported, the number of
49 available priority levels is usually low, which is why they can also be
50 implemented in software by PMDs (e.g. missing priority levels may be
51 emulated by reordering rules).
53 In order to remain as hardware-agnostic as possible, by default all rules
54 are considered to have the same priority, which means that the order between
55 overlapping rules (when a packet is matched by several filters) is
58 PMDs may refuse to create overlapping rules at a given priority level when
59 they can be detected (e.g. if a pattern matches an existing filter).
61 Thus predictable results for a given priority level can only be achieved
62 with non-overlapping rules, using perfect matching on all protocol layers.
64 Flow rules can also be grouped, the flow rule priority is specific to the
65 group they belong to. All flow rules in a given group are thus processed within
66 the context of that group. Groups are not linked by default, so the logical
67 hierarchy of groups must be explicitly defined by flow rules themselves in each
68 group using the JUMP action to define the next group to redirect too. Only flow
69 rules defined in the default group 0 are guarantee to be matched against, this
70 makes group 0 the origin of any group hierarchy defined by an application.
72 Support for multiple actions per rule may be implemented internally on top
73 of non-default hardware priorities, as a result both features may not be
74 simultaneously available to applications.
76 Considering that allowed pattern/actions combinations cannot be known in
77 advance and would result in an impractically large number of capabilities to
78 expose, a method is provided to validate a given rule from the current
79 device configuration state.
81 This enables applications to check if the rule types they need is supported
82 at initialization time, before starting their data path. This method can be
83 used anytime, its only requirement being that the resources needed by a rule
84 should exist (e.g. a target RX queue should be configured first).
86 Each defined rule is associated with an opaque handle managed by the PMD,
87 applications are responsible for keeping it. These can be used for queries
88 and rules management, such as retrieving counters or other data and
91 To avoid resource leaks on the PMD side, handles must be explicitly
92 destroyed by the application before releasing associated resources such as
95 The following sections cover:
97 - **Attributes** (represented by ``struct rte_flow_attr``): properties of a
98 flow rule such as its direction (ingress or egress) and priority.
100 - **Pattern item** (represented by ``struct rte_flow_item``): part of a
101 matching pattern that either matches specific packet data or traffic
102 properties. It can also describe properties of the pattern itself, such as
105 - **Matching pattern**: traffic properties to look for, a combination of any
108 - **Actions** (represented by ``struct rte_flow_action``): operations to
109 perform whenever a packet is matched by a pattern.
117 Flow rules can be grouped by assigning them a common group number. Groups
118 allow a logical hierarchy of flow rule groups (tables) to be defined. These
119 groups can be supported virtually in the PMD or in the physical device.
120 Group 0 is the default group and this is the only group which flows are
121 guarantee to matched against, all subsequent groups can only be reached by
122 way of the JUMP action from a matched flow rule.
124 Although optional, applications are encouraged to group similar rules as
125 much as possible to fully take advantage of hardware capabilities
126 (e.g. optimized matching) and work around limitations (e.g. a single pattern
127 type possibly allowed in a given group), while being aware that the groups
128 hierarchies must be programmed explicitly.
130 Note that support for more than a single group is not guaranteed.
135 A priority level can be assigned to a flow rule, lower values
136 denote higher priority, with 0 as the maximum.
138 Priority levels are arbitrary and up to the application, they do
139 not need to be contiguous nor start from 0, however the maximum number
140 varies between devices and may be affected by existing flow rules.
142 A flow which matches multiple rules in the same group will always matched by
143 the rule with the highest priority in that group.
145 If a packet is matched by several rules of a given group for a given
146 priority level, the outcome is undefined. It can take any path, may be
147 duplicated or even cause unrecoverable errors.
149 Note that support for more than a single priority level is not guaranteed.
151 Attribute: Traffic direction
152 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
154 Flow rule patterns apply to inbound and/or outbound traffic.
156 In the context of this API, **ingress** and **egress** respectively stand
157 for **inbound** and **outbound** based on the standpoint of the application
158 creating a flow rule.
160 There are no exceptions to this definition.
162 Several pattern items and actions are valid and can be used in both
163 directions. At least one direction must be specified.
165 Specifying both directions at once for a given rule is not recommended but
166 may be valid in a few cases (e.g. shared counters).
171 Instead of simply matching the properties of traffic as it would appear on a
172 given DPDK port ID, enabling this attribute transfers a flow rule to the
173 lowest possible level of any device endpoints found in the pattern.
175 When supported, this effectively enables an application to reroute traffic
176 not necessarily intended for it (e.g. coming from or addressed to different
177 physical ports, VFs or applications) at the device level.
179 It complements the behavior of some pattern items such as `Item: PHY_PORT`_
180 and is meaningless without them.
182 When transferring flow rules, **ingress** and **egress** attributes
183 (`Attribute: Traffic direction`_) keep their original meaning, as if
184 processing traffic emitted or received by the application.
189 Pattern items fall in two categories:
191 - Matching protocol headers and packet data, usually associated with a
192 specification structure. These must be stacked in the same order as the
193 protocol layers to match inside packets, starting from the lowest.
195 - Matching meta-data or affecting pattern processing, often without a
196 specification structure. Since they do not match packet contents, their
197 position in the list is usually not relevant.
199 Item specification structures are used to match specific values among
200 protocol fields (or item properties). Documentation describes for each item
201 whether they are associated with one and their type name if so.
203 Up to three structures of the same type can be set for a given item:
205 - ``spec``: values to match (e.g. a given IPv4 address).
207 - ``last``: upper bound for an inclusive range with corresponding fields in
210 - ``mask``: bit-mask applied to both ``spec`` and ``last`` whose purpose is
211 to distinguish the values to take into account and/or partially mask them
212 out (e.g. in order to match an IPv4 address prefix).
214 Usage restrictions and expected behavior:
216 - Setting either ``mask`` or ``last`` without ``spec`` is an error.
218 - Field values in ``last`` which are either 0 or equal to the corresponding
219 values in ``spec`` are ignored; they do not generate a range. Nonzero
220 values lower than those in ``spec`` are not supported.
222 - Setting ``spec`` and optionally ``last`` without ``mask`` causes the PMD
223 to use the default mask defined for that item (defined as
224 ``rte_flow_item_{name}_mask`` constants).
226 - Not setting any of them (assuming item type allows it) is equivalent to
227 providing an empty (zeroed) ``mask`` for broad (nonspecific) matching.
229 - ``mask`` is a simple bit-mask applied before interpreting the contents of
230 ``spec`` and ``last``, which may yield unexpected results if not used
231 carefully. For example, if for an IPv4 address field, ``spec`` provides
232 *10.1.2.3*, ``last`` provides *10.3.4.5* and ``mask`` provides
233 *255.255.0.0*, the effective range becomes *10.1.0.0* to *10.3.255.255*.
235 Example of an item specification matching an Ethernet header:
237 .. _table_rte_flow_pattern_item_example:
239 .. table:: Ethernet item
241 +----------+----------+--------------------+
242 | Field | Subfield | Value |
243 +==========+==========+====================+
244 | ``spec`` | ``src`` | ``00:01:02:03:04`` |
245 | +----------+--------------------+
246 | | ``dst`` | ``00:2a:66:00:01`` |
247 | +----------+--------------------+
248 | | ``type`` | ``0x22aa`` |
249 +----------+----------+--------------------+
250 | ``last`` | unspecified |
251 +----------+----------+--------------------+
252 | ``mask`` | ``src`` | ``00:ff:ff:ff:00`` |
253 | +----------+--------------------+
254 | | ``dst`` | ``00:00:00:00:ff`` |
255 | +----------+--------------------+
256 | | ``type`` | ``0x0000`` |
257 +----------+----------+--------------------+
259 Non-masked bits stand for any value (shown as ``?`` below), Ethernet headers
260 with the following properties are thus matched:
262 - ``src``: ``??:01:02:03:??``
263 - ``dst``: ``??:??:??:??:01``
264 - ``type``: ``0x????``
269 A pattern is formed by stacking items starting from the lowest protocol
270 layer to match. This stacking restriction does not apply to meta items which
271 can be placed anywhere in the stack without affecting the meaning of the
274 Patterns are terminated by END items.
278 .. _table_rte_flow_tcpv4_as_l4:
280 .. table:: TCPv4 as L4
296 .. _table_rte_flow_tcpv6_in_vxlan:
298 .. table:: TCPv6 in VXLAN
300 +-------+------------+
302 +=======+============+
304 +-------+------------+
306 +-------+------------+
308 +-------+------------+
310 +-------+------------+
312 +-------+------------+
314 +-------+------------+
316 +-------+------------+
318 +-------+------------+
322 .. _table_rte_flow_tcpv4_as_l4_meta:
324 .. table:: TCPv4 as L4 with meta items
346 The above example shows how meta items do not affect packet data matching
347 items, as long as those remain stacked properly. The resulting matching
348 pattern is identical to "TCPv4 as L4".
350 .. _table_rte_flow_udpv6_anywhere:
352 .. table:: UDPv6 anywhere
364 If supported by the PMD, omitting one or several protocol layers at the
365 bottom of the stack as in the above example (missing an Ethernet
366 specification) enables looking up anywhere in packets.
368 It is unspecified whether the payload of supported encapsulations
369 (e.g. VXLAN payload) is matched by such a pattern, which may apply to inner,
370 outer or both packets.
372 .. _table_rte_flow_invalid_l3:
374 .. table:: Invalid, missing L3
386 The above pattern is invalid due to a missing L3 specification between L2
387 (Ethernet) and L4 (UDP). Doing so is only allowed at the bottom and at the
393 They match meta-data or affect pattern processing instead of matching packet
394 data directly, most of them do not need a specification structure. This
395 particularity allows them to be specified anywhere in the stack without
396 causing any side effect.
401 End marker for item lists. Prevents further processing of items, thereby
404 - Its numeric value is 0 for convenience.
405 - PMD support is mandatory.
406 - ``spec``, ``last`` and ``mask`` are ignored.
408 .. _table_rte_flow_item_end:
412 +----------+---------+
414 +==========+=========+
415 | ``spec`` | ignored |
416 +----------+---------+
417 | ``last`` | ignored |
418 +----------+---------+
419 | ``mask`` | ignored |
420 +----------+---------+
425 Used as a placeholder for convenience. It is ignored and simply discarded by
428 - PMD support is mandatory.
429 - ``spec``, ``last`` and ``mask`` are ignored.
431 .. _table_rte_flow_item_void:
435 +----------+---------+
437 +==========+=========+
438 | ``spec`` | ignored |
439 +----------+---------+
440 | ``last`` | ignored |
441 +----------+---------+
442 | ``mask`` | ignored |
443 +----------+---------+
445 One usage example for this type is generating rules that share a common
446 prefix quickly without reallocating memory, only by updating item types:
448 .. _table_rte_flow_item_void_example:
450 .. table:: TCP, UDP or ICMP as L4
452 +-------+--------------------+
454 +=======+====================+
456 +-------+--------------------+
458 +-------+------+------+------+
459 | 2 | UDP | VOID | VOID |
460 +-------+------+------+------+
461 | 3 | VOID | TCP | VOID |
462 +-------+------+------+------+
463 | 4 | VOID | VOID | ICMP |
464 +-------+------+------+------+
466 +-------+--------------------+
471 Inverted matching, i.e. process packets that do not match the pattern.
473 - ``spec``, ``last`` and ``mask`` are ignored.
475 .. _table_rte_flow_item_invert:
479 +----------+---------+
481 +==========+=========+
482 | ``spec`` | ignored |
483 +----------+---------+
484 | ``last`` | ignored |
485 +----------+---------+
486 | ``mask`` | ignored |
487 +----------+---------+
489 Usage example, matching non-TCPv4 packets only:
491 .. _table_rte_flow_item_invert_example:
493 .. table:: Anything but TCPv4
512 Matches traffic originating from (ingress) or going to (egress) the physical
513 function of the current device.
515 If supported, should work even if the physical function is not managed by
516 the application and thus not associated with a DPDK port ID.
518 - Can be combined with any number of `Item: VF`_ to match both PF and VF
520 - ``spec``, ``last`` and ``mask`` must not be set.
522 .. _table_rte_flow_item_pf:
539 Matches traffic originating from (ingress) or going to (egress) a given
540 virtual function of the current device.
542 If supported, should work even if the virtual function is not managed by the
543 application and thus not associated with a DPDK port ID.
545 Note this pattern item does not match VF representors traffic which, as
546 separate entities, should be addressed through their own DPDK port IDs.
548 - Can be specified multiple times to match traffic addressed to several VF
550 - Can be combined with a PF item to match both PF and VF traffic.
551 - Default ``mask`` matches any VF ID.
553 .. _table_rte_flow_item_vf:
557 +----------+----------+---------------------------+
558 | Field | Subfield | Value |
559 +==========+==========+===========================+
560 | ``spec`` | ``id`` | destination VF ID |
561 +----------+----------+---------------------------+
562 | ``last`` | ``id`` | upper range value |
563 +----------+----------+---------------------------+
564 | ``mask`` | ``id`` | zeroed to match any VF ID |
565 +----------+----------+---------------------------+
570 Matches traffic originating from (ingress) or going to (egress) a physical
571 port of the underlying device.
573 The first PHY_PORT item overrides the physical port normally associated with
574 the specified DPDK input port (port_id). This item can be provided several
575 times to match additional physical ports.
577 Note that physical ports are not necessarily tied to DPDK input ports
578 (port_id) when those are not under DPDK control. Possible values are
579 specific to each device, they are not necessarily indexed from zero and may
582 As a device property, the list of allowed values as well as the value
583 associated with a port_id should be retrieved by other means.
585 - Default ``mask`` matches any port index.
587 .. _table_rte_flow_item_phy_port:
591 +----------+-----------+--------------------------------+
592 | Field | Subfield | Value |
593 +==========+===========+================================+
594 | ``spec`` | ``index`` | physical port index |
595 +----------+-----------+--------------------------------+
596 | ``last`` | ``index`` | upper range value |
597 +----------+-----------+--------------------------------+
598 | ``mask`` | ``index`` | zeroed to match any port index |
599 +----------+-----------+--------------------------------+
604 Matches traffic originating from (ingress) or going to (egress) a given DPDK
607 Normally only supported if the port ID in question is known by the
608 underlying PMD and related to the device the flow rule is created against.
610 This must not be confused with `Item: PHY_PORT`_ which refers to the
611 physical port of a device, whereas `Item: PORT_ID`_ refers to a ``struct
612 rte_eth_dev`` object on the application side (also known as "port
613 representor" depending on the kind of underlying device).
615 - Default ``mask`` matches the specified DPDK port ID.
617 .. _table_rte_flow_item_port_id:
621 +----------+----------+-----------------------------+
622 | Field | Subfield | Value |
623 +==========+==========+=============================+
624 | ``spec`` | ``id`` | DPDK port ID |
625 +----------+----------+-----------------------------+
626 | ``last`` | ``id`` | upper range value |
627 +----------+----------+-----------------------------+
628 | ``mask`` | ``id`` | zeroed to match any port ID |
629 +----------+----------+-----------------------------+
634 Matches an arbitrary integer value which was set using the ``MARK`` action in
635 a previously matched rule.
637 This item can only specified once as a match criteria as the ``MARK`` action can
638 only be specified once in a flow action.
640 Note the value of MARK field is arbitrary and application defined.
642 Depending on the underlying implementation the MARK item may be supported on
643 the physical device, with virtual groups in the PMD or not at all.
645 - Default ``mask`` matches any integer value.
647 .. _table_rte_flow_item_mark:
651 +----------+----------+---------------------------+
652 | Field | Subfield | Value |
653 +==========+==========+===========================+
654 | ``spec`` | ``id`` | integer value |
655 +----------+--------------------------------------+
656 | ``last`` | ``id`` | upper range value |
657 +----------+----------+---------------------------+
658 | ``mask`` | ``id`` | zeroed to match any value |
659 +----------+----------+---------------------------+
661 Data matching item types
662 ~~~~~~~~~~~~~~~~~~~~~~~~
664 Most of these are basically protocol header definitions with associated
665 bit-masks. They must be specified (stacked) from lowest to highest protocol
666 layer to form a matching pattern.
668 The following list is not exhaustive, new protocols will be added in the
674 Matches any protocol in place of the current layer, a single ANY may also
675 stand for several protocol layers.
677 This is usually specified as the first pattern item when looking for a
678 protocol anywhere in a packet.
680 - Default ``mask`` stands for any number of layers.
682 .. _table_rte_flow_item_any:
686 +----------+----------+--------------------------------------+
687 | Field | Subfield | Value |
688 +==========+==========+======================================+
689 | ``spec`` | ``num`` | number of layers covered |
690 +----------+----------+--------------------------------------+
691 | ``last`` | ``num`` | upper range value |
692 +----------+----------+--------------------------------------+
693 | ``mask`` | ``num`` | zeroed to cover any number of layers |
694 +----------+----------+--------------------------------------+
696 Example for VXLAN TCP payload matching regardless of outer L3 (IPv4 or IPv6)
697 and L4 (UDP) both matched by the first ANY specification, and inner L3 (IPv4
698 or IPv6) matched by the second ANY specification:
700 .. _table_rte_flow_item_any_example:
702 .. table:: TCP in VXLAN with wildcards
704 +-------+------+----------+----------+-------+
705 | Index | Item | Field | Subfield | Value |
706 +=======+======+==========+==========+=======+
708 +-------+------+----------+----------+-------+
709 | 1 | ANY | ``spec`` | ``num`` | 2 |
710 +-------+------+----------+----------+-------+
712 +-------+------------------------------------+
714 +-------+------+----------+----------+-------+
715 | 4 | ANY | ``spec`` | ``num`` | 1 |
716 +-------+------+----------+----------+-------+
718 +-------+------------------------------------+
720 +-------+------------------------------------+
725 Matches a byte string of a given length at a given offset.
727 Offset is either absolute (using the start of the packet) or relative to the
728 end of the previous matched item in the stack, in which case negative values
731 If search is enabled, offset is used as the starting point. The search area
732 can be delimited by setting limit to a nonzero value, which is the maximum
733 number of bytes after offset where the pattern may start.
735 Matching a zero-length pattern is allowed, doing so resets the relative
736 offset for subsequent items.
738 - This type does not support ranges (``last`` field).
739 - Default ``mask`` matches all fields exactly.
741 .. _table_rte_flow_item_raw:
745 +----------+--------------+-------------------------------------------------+
746 | Field | Subfield | Value |
747 +==========+==============+=================================================+
748 | ``spec`` | ``relative`` | look for pattern after the previous item |
749 | +--------------+-------------------------------------------------+
750 | | ``search`` | search pattern from offset (see also ``limit``) |
751 | +--------------+-------------------------------------------------+
752 | | ``reserved`` | reserved, must be set to zero |
753 | +--------------+-------------------------------------------------+
754 | | ``offset`` | absolute or relative offset for ``pattern`` |
755 | +--------------+-------------------------------------------------+
756 | | ``limit`` | search area limit for start of ``pattern`` |
757 | +--------------+-------------------------------------------------+
758 | | ``length`` | ``pattern`` length |
759 | +--------------+-------------------------------------------------+
760 | | ``pattern`` | byte string to look for |
761 +----------+--------------+-------------------------------------------------+
762 | ``last`` | if specified, either all 0 or with the same values as ``spec`` |
763 +----------+----------------------------------------------------------------+
764 | ``mask`` | bit-mask applied to ``spec`` values with usual behavior |
765 +----------+----------------------------------------------------------------+
767 Example pattern looking for several strings at various offsets of a UDP
768 payload, using combined RAW items:
770 .. _table_rte_flow_item_raw_example:
772 .. table:: UDP payload matching
774 +-------+------+----------+--------------+-------+
775 | Index | Item | Field | Subfield | Value |
776 +=======+======+==========+==============+=======+
778 +-------+----------------------------------------+
780 +-------+----------------------------------------+
782 +-------+------+----------+--------------+-------+
783 | 3 | RAW | ``spec`` | ``relative`` | 1 |
784 | | | +--------------+-------+
785 | | | | ``search`` | 1 |
786 | | | +--------------+-------+
787 | | | | ``offset`` | 10 |
788 | | | +--------------+-------+
789 | | | | ``limit`` | 0 |
790 | | | +--------------+-------+
791 | | | | ``length`` | 3 |
792 | | | +--------------+-------+
793 | | | | ``pattern`` | "foo" |
794 +-------+------+----------+--------------+-------+
795 | 4 | RAW | ``spec`` | ``relative`` | 1 |
796 | | | +--------------+-------+
797 | | | | ``search`` | 0 |
798 | | | +--------------+-------+
799 | | | | ``offset`` | 20 |
800 | | | +--------------+-------+
801 | | | | ``limit`` | 0 |
802 | | | +--------------+-------+
803 | | | | ``length`` | 3 |
804 | | | +--------------+-------+
805 | | | | ``pattern`` | "bar" |
806 +-------+------+----------+--------------+-------+
807 | 5 | RAW | ``spec`` | ``relative`` | 1 |
808 | | | +--------------+-------+
809 | | | | ``search`` | 0 |
810 | | | +--------------+-------+
811 | | | | ``offset`` | -29 |
812 | | | +--------------+-------+
813 | | | | ``limit`` | 0 |
814 | | | +--------------+-------+
815 | | | | ``length`` | 3 |
816 | | | +--------------+-------+
817 | | | | ``pattern`` | "baz" |
818 +-------+------+----------+--------------+-------+
820 +-------+----------------------------------------+
824 - Locate "foo" at least 10 bytes deep inside UDP payload.
825 - Locate "bar" after "foo" plus 20 bytes.
826 - Locate "baz" after "bar" minus 29 bytes.
828 Such a packet may be represented as follows (not to scale)::
831 | |<--------->| |<--------->|
833 |-----|------|-----|-----|-----|-----|-----------|-----|------|
834 | ETH | IPv4 | UDP | ... | baz | foo | ......... | bar | .... |
835 |-----|------|-----|-----|-----|-----|-----------|-----|------|
837 |<--------------------------->|
840 Note that matching subsequent pattern items would resume after "baz", not
841 "bar" since matching is always performed after the previous item of the
847 Matches an Ethernet header.
849 The ``type`` field either stands for "EtherType" or "TPID" when followed by
850 so-called layer 2.5 pattern items such as ``RTE_FLOW_ITEM_TYPE_VLAN``. In
851 the latter case, ``type`` refers to that of the outer header, with the inner
852 EtherType/TPID provided by the subsequent pattern item. This is the same
853 order as on the wire.
855 - ``dst``: destination MAC.
856 - ``src``: source MAC.
857 - ``type``: EtherType or TPID.
858 - Default ``mask`` matches destination and source addresses only.
863 Matches an 802.1Q/ad VLAN tag.
865 The corresponding standard outer EtherType (TPID) values are
866 ``RTE_ETHER_TYPE_VLAN`` or ``RTE_ETHER_TYPE_QINQ``. It can be overridden by the
867 preceding pattern item.
869 - ``tci``: tag control information.
870 - ``inner_type``: inner EtherType or TPID.
871 - Default ``mask`` matches the VID part of TCI only (lower 12 bits).
876 Matches an IPv4 header.
878 Note: IPv4 options are handled by dedicated pattern items.
880 - ``hdr``: IPv4 header definition (``rte_ip.h``).
881 - Default ``mask`` matches source and destination addresses only.
886 Matches an IPv6 header.
888 Note: IPv6 options are handled by dedicated pattern items, see `Item:
891 - ``hdr``: IPv6 header definition (``rte_ip.h``).
892 - Default ``mask`` matches source and destination addresses only.
897 Matches an ICMP header.
899 - ``hdr``: ICMP header definition (``rte_icmp.h``).
900 - Default ``mask`` matches ICMP type and code only.
905 Matches a UDP header.
907 - ``hdr``: UDP header definition (``rte_udp.h``).
908 - Default ``mask`` matches source and destination ports only.
913 Matches a TCP header.
915 - ``hdr``: TCP header definition (``rte_tcp.h``).
916 - Default ``mask`` matches source and destination ports only.
921 Matches a SCTP header.
923 - ``hdr``: SCTP header definition (``rte_sctp.h``).
924 - Default ``mask`` matches source and destination ports only.
929 Matches a VXLAN header (RFC 7348).
931 - ``flags``: normally 0x08 (I flag).
932 - ``rsvd0``: reserved, normally 0x000000.
933 - ``vni``: VXLAN network identifier.
934 - ``rsvd1``: reserved, normally 0x00.
935 - Default ``mask`` matches VNI only.
940 Matches an IEEE 802.1BR E-Tag header.
942 The corresponding standard outer EtherType (TPID) value is
943 ``RTE_ETHER_TYPE_ETAG``. It can be overridden by the preceding pattern item.
945 - ``epcp_edei_in_ecid_b``: E-Tag control information (E-TCI), E-PCP (3b),
946 E-DEI (1b), ingress E-CID base (12b).
947 - ``rsvd_grp_ecid_b``: reserved (2b), GRP (2b), E-CID base (12b).
948 - ``in_ecid_e``: ingress E-CID ext.
949 - ``ecid_e``: E-CID ext.
950 - ``inner_type``: inner EtherType or TPID.
951 - Default ``mask`` simultaneously matches GRP and E-CID base.
956 Matches a NVGRE header (RFC 7637).
958 - ``c_k_s_rsvd0_ver``: checksum (1b), undefined (1b), key bit (1b),
959 sequence number (1b), reserved 0 (9b), version (3b). This field must have
960 value 0x2000 according to RFC 7637.
961 - ``protocol``: protocol type (0x6558).
962 - ``tni``: virtual subnet ID.
963 - ``flow_id``: flow ID.
964 - Default ``mask`` matches TNI only.
969 Matches a MPLS header.
971 - ``label_tc_s_ttl``: label, TC, Bottom of Stack and TTL.
972 - Default ``mask`` matches label only.
977 Matches a GRE header.
979 - ``c_rsvd0_ver``: checksum, reserved 0 and version.
980 - ``protocol``: protocol type.
981 - Default ``mask`` matches protocol only.
986 Fuzzy pattern match, expect faster than default.
988 This is for device that support fuzzy match option. Usually a fuzzy match is
989 fast but the cost is accuracy. i.e. Signature Match only match pattern's hash
990 value, but it is possible two different patterns have the same hash value.
992 Matching accuracy level can be configured by threshold. Driver can divide the
993 range of threshold and map to different accuracy levels that device support.
995 Threshold 0 means perfect match (no fuzziness), while threshold 0xffffffff
996 means fuzziest match.
998 .. _table_rte_flow_item_fuzzy:
1002 +----------+---------------+--------------------------------------------------+
1003 | Field | Subfield | Value |
1004 +==========+===============+==================================================+
1005 | ``spec`` | ``threshold`` | 0 as perfect match, 0xffffffff as fuzziest match |
1006 +----------+---------------+--------------------------------------------------+
1007 | ``last`` | ``threshold`` | upper range value |
1008 +----------+---------------+--------------------------------------------------+
1009 | ``mask`` | ``threshold`` | bit-mask apply to "spec" and "last" |
1010 +----------+---------------+--------------------------------------------------+
1012 Usage example, fuzzy match a TCPv4 packets:
1014 .. _table_rte_flow_item_fuzzy_example:
1016 .. table:: Fuzzy matching
1018 +-------+----------+
1020 +=======+==========+
1022 +-------+----------+
1024 +-------+----------+
1026 +-------+----------+
1028 +-------+----------+
1030 +-------+----------+
1032 Item: ``GTP``, ``GTPC``, ``GTPU``
1033 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1035 Matches a GTPv1 header.
1037 Note: GTP, GTPC and GTPU use the same structure. GTPC and GTPU item
1038 are defined for a user-friendly API when creating GTP-C and GTP-U
1041 - ``v_pt_rsv_flags``: version (3b), protocol type (1b), reserved (1b),
1042 extension header flag (1b), sequence number flag (1b), N-PDU number
1044 - ``msg_type``: message type.
1045 - ``msg_len``: message length.
1046 - ``teid``: tunnel endpoint identifier.
1047 - Default ``mask`` matches teid only.
1052 Matches an ESP header.
1054 - ``hdr``: ESP header definition (``rte_esp.h``).
1055 - Default ``mask`` matches SPI only.
1060 Matches a GENEVE header.
1062 - ``ver_opt_len_o_c_rsvd0``: version (2b), length of the options fields (6b),
1063 OAM packet (1b), critical options present (1b), reserved 0 (6b).
1064 - ``protocol``: protocol type.
1065 - ``vni``: virtual network identifier.
1066 - ``rsvd1``: reserved, normally 0x00.
1067 - Default ``mask`` matches VNI only.
1072 Matches a VXLAN-GPE header (draft-ietf-nvo3-vxlan-gpe-05).
1074 - ``flags``: normally 0x0C (I and P flags).
1075 - ``rsvd0``: reserved, normally 0x0000.
1076 - ``protocol``: protocol type.
1077 - ``vni``: VXLAN network identifier.
1078 - ``rsvd1``: reserved, normally 0x00.
1079 - Default ``mask`` matches VNI only.
1081 Item: ``ARP_ETH_IPV4``
1082 ^^^^^^^^^^^^^^^^^^^^^^
1084 Matches an ARP header for Ethernet/IPv4.
1086 - ``hdr``: hardware type, normally 1.
1087 - ``pro``: protocol type, normally 0x0800.
1088 - ``hln``: hardware address length, normally 6.
1089 - ``pln``: protocol address length, normally 4.
1090 - ``op``: opcode (1 for request, 2 for reply).
1091 - ``sha``: sender hardware address.
1092 - ``spa``: sender IPv4 address.
1093 - ``tha``: target hardware address.
1094 - ``tpa``: target IPv4 address.
1095 - Default ``mask`` matches SHA, SPA, THA and TPA.
1100 Matches the presence of any IPv6 extension header.
1102 - ``next_hdr``: next header.
1103 - Default ``mask`` matches ``next_hdr``.
1105 Normally preceded by any of:
1113 Matches any ICMPv6 header.
1115 - ``type``: ICMPv6 type.
1116 - ``code``: ICMPv6 code.
1117 - ``checksum``: ICMPv6 checksum.
1118 - Default ``mask`` matches ``type`` and ``code``.
1120 Item: ``ICMP6_ND_NS``
1121 ^^^^^^^^^^^^^^^^^^^^^
1123 Matches an ICMPv6 neighbor discovery solicitation.
1125 - ``type``: ICMPv6 type, normally 135.
1126 - ``code``: ICMPv6 code, normally 0.
1127 - ``checksum``: ICMPv6 checksum.
1128 - ``reserved``: reserved, normally 0.
1129 - ``target_addr``: target address.
1130 - Default ``mask`` matches target address only.
1132 Item: ``ICMP6_ND_NA``
1133 ^^^^^^^^^^^^^^^^^^^^^
1135 Matches an ICMPv6 neighbor discovery advertisement.
1137 - ``type``: ICMPv6 type, normally 136.
1138 - ``code``: ICMPv6 code, normally 0.
1139 - ``checksum``: ICMPv6 checksum.
1140 - ``rso_reserved``: route flag (1b), solicited flag (1b), override flag
1141 (1b), reserved (29b).
1142 - ``target_addr``: target address.
1143 - Default ``mask`` matches target address only.
1145 Item: ``ICMP6_ND_OPT``
1146 ^^^^^^^^^^^^^^^^^^^^^^
1148 Matches the presence of any ICMPv6 neighbor discovery option.
1150 - ``type``: ND option type.
1151 - ``length``: ND option length.
1152 - Default ``mask`` matches type only.
1154 Normally preceded by any of:
1156 - `Item: ICMP6_ND_NA`_
1157 - `Item: ICMP6_ND_NS`_
1158 - `Item: ICMP6_ND_OPT`_
1160 Item: ``ICMP6_ND_OPT_SLA_ETH``
1161 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1163 Matches an ICMPv6 neighbor discovery source Ethernet link-layer address
1166 - ``type``: ND option type, normally 1.
1167 - ``length``: ND option length, normally 1.
1168 - ``sla``: source Ethernet LLA.
1169 - Default ``mask`` matches source link-layer address only.
1171 Normally preceded by any of:
1173 - `Item: ICMP6_ND_NA`_
1174 - `Item: ICMP6_ND_OPT`_
1176 Item: ``ICMP6_ND_OPT_TLA_ETH``
1177 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1179 Matches an ICMPv6 neighbor discovery target Ethernet link-layer address
1182 - ``type``: ND option type, normally 2.
1183 - ``length``: ND option length, normally 1.
1184 - ``tla``: target Ethernet LLA.
1185 - Default ``mask`` matches target link-layer address only.
1187 Normally preceded by any of:
1189 - `Item: ICMP6_ND_NS`_
1190 - `Item: ICMP6_ND_OPT`_
1195 Matches an application specific 32 bit metadata item.
1197 - Default ``mask`` matches the specified metadata value.
1199 .. _table_rte_flow_item_meta:
1203 +----------+----------+---------------------------------------+
1204 | Field | Subfield | Value |
1205 +==========+==========+=======================================+
1206 | ``spec`` | ``data`` | 32 bit metadata value |
1207 +----------+--------------------------------------------------+
1208 | ``last`` | ``data`` | upper range value |
1209 +----------+----------+---------------------------------------+
1210 | ``mask`` | ``data`` | bit-mask applies to "spec" and "last" |
1211 +----------+----------+---------------------------------------+
1216 Each possible action is represented by a type.
1217 An action can have an associated configuration object.
1218 Several actions combined in a list can be assigned
1219 to a flow rule and are performed in order.
1221 They fall in three categories:
1223 - Actions that modify the fate of matching traffic, for instance by dropping
1224 or assigning it a specific destination.
1226 - Actions that modify matching traffic contents or its properties. This
1227 includes adding/removing encapsulation, encryption, compression and marks.
1229 - Actions related to the flow rule itself, such as updating counters or
1230 making it non-terminating.
1232 Flow rules being terminating by default, not specifying any action of the
1233 fate kind results in undefined behavior. This applies to both ingress and
1236 PASSTHRU, when supported, makes a flow rule non-terminating.
1238 Like matching patterns, action lists are terminated by END items.
1240 Example of action that redirects packets to queue index 10:
1242 .. _table_rte_flow_action_example:
1244 .. table:: Queue action
1246 +-----------+-------+
1248 +===========+=======+
1250 +-----------+-------+
1252 Actions are performed in list order:
1254 .. _table_rte_flow_count_then_drop:
1256 .. table:: Count then drop
1270 .. _table_rte_flow_mark_count_redirect:
1272 .. table:: Mark, count then redirect
1274 +-------+--------+------------+-------+
1275 | Index | Action | Field | Value |
1276 +=======+========+============+=======+
1277 | 0 | MARK | ``mark`` | 0x2a |
1278 +-------+--------+------------+-------+
1279 | 1 | COUNT | ``shared`` | 0 |
1280 | | +------------+-------+
1282 +-------+--------+------------+-------+
1283 | 2 | QUEUE | ``queue`` | 10 |
1284 +-------+--------+------------+-------+
1286 +-------+-----------------------------+
1290 .. _table_rte_flow_redirect_queue_5:
1292 .. table:: Redirect to queue 5
1294 +-------+--------+-----------+-------+
1295 | Index | Action | Field | Value |
1296 +=======+========+===========+=======+
1298 +-------+--------+-----------+-------+
1299 | 1 | QUEUE | ``queue`` | 5 |
1300 +-------+--------+-----------+-------+
1302 +-------+----------------------------+
1304 In the above example, while DROP and QUEUE must be performed in order, both
1305 have to happen before reaching END. Only QUEUE has a visible effect.
1307 Note that such a list may be thought as ambiguous and rejected on that
1310 .. _table_rte_flow_redirect_queue_5_3:
1312 .. table:: Redirect to queues 5 and 3
1314 +-------+--------+-----------+-------+
1315 | Index | Action | Field | Value |
1316 +=======+========+===========+=======+
1317 | 0 | QUEUE | ``queue`` | 5 |
1318 +-------+--------+-----------+-------+
1320 +-------+--------+-----------+-------+
1321 | 2 | QUEUE | ``queue`` | 3 |
1322 +-------+--------+-----------+-------+
1324 +-------+----------------------------+
1326 As previously described, all actions must be taken into account. This
1327 effectively duplicates traffic to both queues. The above example also shows
1328 that VOID is ignored.
1333 Common action types are described in this section. Like pattern item types,
1334 this list is not exhaustive as new actions will be added in the future.
1339 End marker for action lists. Prevents further processing of actions, thereby
1342 - Its numeric value is 0 for convenience.
1343 - PMD support is mandatory.
1344 - No configurable properties.
1346 .. _table_rte_flow_action_end:
1359 Used as a placeholder for convenience. It is ignored and simply discarded by
1362 - PMD support is mandatory.
1363 - No configurable properties.
1365 .. _table_rte_flow_action_void:
1375 Action: ``PASSTHRU``
1376 ^^^^^^^^^^^^^^^^^^^^
1378 Leaves traffic up for additional processing by subsequent flow rules; makes
1379 a flow rule non-terminating.
1381 - No configurable properties.
1383 .. _table_rte_flow_action_passthru:
1393 Example to copy a packet to a queue and continue processing by subsequent
1396 .. _table_rte_flow_action_passthru_example:
1398 .. table:: Copy to queue 8
1400 +-------+--------+-----------+-------+
1401 | Index | Action | Field | Value |
1402 +=======+========+===========+=======+
1404 +-------+--------+-----------+-------+
1405 | 1 | QUEUE | ``queue`` | 8 |
1406 +-------+--------+-----------+-------+
1408 +-------+----------------------------+
1413 Redirects packets to a group on the current device.
1415 In a hierarchy of groups, which can be used to represent physical or logical
1416 flow group/tables on the device, this action redirects the matched flow to
1417 the specified group on that device.
1419 If a matched flow is redirected to a table which doesn't contain a matching
1420 rule for that flow then the behavior is undefined and the resulting behavior
1421 is up to the specific device. Best practice when using groups would be define
1422 a default flow rule for each group which a defines the default actions in that
1423 group so a consistent behavior is defined.
1425 Defining an action for matched flow in a group to jump to a group which is
1426 higher in the group hierarchy may not be supported by physical devices,
1427 depending on how groups are mapped to the physical devices. In the
1428 definitions of jump actions, applications should be aware that it may be
1429 possible to define flow rules which trigger an undefined behavior causing
1430 flows to loop between groups.
1432 .. _table_rte_flow_action_jump:
1436 +-----------+------------------------------+
1438 +===========+==============================+
1439 | ``group`` | Group to redirect packets to |
1440 +-----------+------------------------------+
1445 Attaches an integer value to packets and sets ``PKT_RX_FDIR`` and
1446 ``PKT_RX_FDIR_ID`` mbuf flags.
1448 This value is arbitrary and application-defined. Maximum allowed value
1449 depends on the underlying implementation. It is returned in the
1450 ``hash.fdir.hi`` mbuf field.
1452 .. _table_rte_flow_action_mark:
1456 +--------+--------------------------------------+
1458 +========+======================================+
1459 | ``id`` | integer value to return with packets |
1460 +--------+--------------------------------------+
1465 Flags packets. Similar to `Action: MARK`_ without a specific value; only
1466 sets the ``PKT_RX_FDIR`` mbuf flag.
1468 - No configurable properties.
1470 .. _table_rte_flow_action_flag:
1483 Assigns packets to a given queue index.
1485 .. _table_rte_flow_action_queue:
1489 +-----------+--------------------+
1491 +===========+====================+
1492 | ``index`` | queue index to use |
1493 +-----------+--------------------+
1500 - No configurable properties.
1502 .. _table_rte_flow_action_drop:
1515 Adds a counter action to a matched flow.
1517 If more than one count action is specified in a single flow rule, then each
1518 action must specify a unique id.
1520 Counters can be retrieved and reset through ``rte_flow_query()``, see
1521 ``struct rte_flow_query_count``.
1523 The shared flag indicates whether the counter is unique to the flow rule the
1524 action is specified with, or whether it is a shared counter.
1526 For a count action with the shared flag set, then then a global device
1527 namespace is assumed for the counter id, so that any matched flow rules using
1528 a count action with the same counter id on the same port will contribute to
1531 For ports within the same switch domain then the counter id namespace extends
1532 to all ports within that switch domain.
1534 .. _table_rte_flow_action_count:
1538 +------------+---------------------+
1540 +============+=====================+
1541 | ``shared`` | shared counter flag |
1542 +------------+---------------------+
1543 | ``id`` | counter id |
1544 +------------+---------------------+
1546 Query structure to retrieve and reset flow rule counters:
1548 .. _table_rte_flow_query_count:
1550 .. table:: COUNT query
1552 +---------------+-----+-----------------------------------+
1553 | Field | I/O | Value |
1554 +===============+=====+===================================+
1555 | ``reset`` | in | reset counter after query |
1556 +---------------+-----+-----------------------------------+
1557 | ``hits_set`` | out | ``hits`` field is set |
1558 +---------------+-----+-----------------------------------+
1559 | ``bytes_set`` | out | ``bytes`` field is set |
1560 +---------------+-----+-----------------------------------+
1561 | ``hits`` | out | number of hits for this rule |
1562 +---------------+-----+-----------------------------------+
1563 | ``bytes`` | out | number of bytes through this rule |
1564 +---------------+-----+-----------------------------------+
1569 Similar to QUEUE, except RSS is additionally performed on packets to spread
1570 them among several queues according to the provided parameters.
1572 Unlike global RSS settings used by other DPDK APIs, unsetting the ``types``
1573 field does not disable RSS in a flow rule. Doing so instead requests safe
1574 unspecified "best-effort" settings from the underlying PMD, which depending
1575 on the flow rule, may result in anything ranging from empty (single queue)
1576 to all-inclusive RSS.
1578 Note: RSS hash result is stored in the ``hash.rss`` mbuf field which
1579 overlaps ``hash.fdir.lo``. Since `Action: MARK`_ sets the ``hash.fdir.hi``
1580 field only, both can be requested simultaneously.
1582 Also, regarding packet encapsulation ``level``:
1584 - ``0`` requests the default behavior. Depending on the packet type, it can
1585 mean outermost, innermost, anything in between or even no RSS.
1587 It basically stands for the innermost encapsulation level RSS can be
1588 performed on according to PMD and device capabilities.
1590 - ``1`` requests RSS to be performed on the outermost packet encapsulation
1593 - ``2`` and subsequent values request RSS to be performed on the specified
1594 inner packet encapsulation level, from outermost to innermost (lower to
1597 Values other than ``0`` are not necessarily supported.
1599 Requesting a specific RSS level on unrecognized traffic results in undefined
1600 behavior. For predictable results, it is recommended to make the flow rule
1601 pattern match packet headers up to the requested encapsulation level so that
1602 only matching traffic goes through.
1604 .. _table_rte_flow_action_rss:
1608 +---------------+---------------------------------------------+
1610 +===============+=============================================+
1611 | ``func`` | RSS hash function to apply |
1612 +---------------+---------------------------------------------+
1613 | ``level`` | encapsulation level for ``types`` |
1614 +---------------+---------------------------------------------+
1615 | ``types`` | specific RSS hash types (see ``ETH_RSS_*``) |
1616 +---------------+---------------------------------------------+
1617 | ``key_len`` | hash key length in bytes |
1618 +---------------+---------------------------------------------+
1619 | ``queue_num`` | number of entries in ``queue`` |
1620 +---------------+---------------------------------------------+
1621 | ``key`` | hash key |
1622 +---------------+---------------------------------------------+
1623 | ``queue`` | queue indices to use |
1624 +---------------+---------------------------------------------+
1629 Directs matching traffic to the physical function (PF) of the current
1634 - No configurable properties.
1636 .. _table_rte_flow_action_pf:
1649 Directs matching traffic to a given virtual function of the current device.
1651 Packets matched by a VF pattern item can be redirected to their original VF
1652 ID instead of the specified one. This parameter may not be available and is
1653 not guaranteed to work properly if the VF part is matched by a prior flow
1654 rule or if packets are not addressed to a VF in the first place.
1658 .. _table_rte_flow_action_vf:
1662 +--------------+--------------------------------+
1664 +==============+================================+
1665 | ``original`` | use original VF ID if possible |
1666 +--------------+--------------------------------+
1668 +--------------+--------------------------------+
1670 Action: ``PHY_PORT``
1671 ^^^^^^^^^^^^^^^^^^^^
1673 Directs matching traffic to a given physical port index of the underlying
1676 See `Item: PHY_PORT`_.
1678 .. _table_rte_flow_action_phy_port:
1682 +--------------+-------------------------------------+
1684 +==============+=====================================+
1685 | ``original`` | use original port index if possible |
1686 +--------------+-------------------------------------+
1687 | ``index`` | physical port index |
1688 +--------------+-------------------------------------+
1692 Directs matching traffic to a given DPDK port ID.
1694 See `Item: PORT_ID`_.
1696 .. _table_rte_flow_action_port_id:
1700 +--------------+---------------------------------------+
1702 +==============+=======================================+
1703 | ``original`` | use original DPDK port ID if possible |
1704 +--------------+---------------------------------------+
1705 | ``id`` | DPDK port ID |
1706 +--------------+---------------------------------------+
1711 Applies a stage of metering and policing.
1713 The metering and policing (MTR) object has to be first created using the
1714 rte_mtr_create() API function. The ID of the MTR object is specified as
1715 action parameter. More than one flow can use the same MTR object through
1716 the meter action. The MTR object can be further updated or queried using
1719 .. _table_rte_flow_action_meter:
1723 +--------------+---------------+
1725 +==============+===============+
1726 | ``mtr_id`` | MTR object ID |
1727 +--------------+---------------+
1729 Action: ``SECURITY``
1730 ^^^^^^^^^^^^^^^^^^^^
1732 Perform the security action on flows matched by the pattern items
1733 according to the configuration of the security session.
1735 This action modifies the payload of matched flows. For INLINE_CRYPTO, the
1736 security protocol headers and IV are fully provided by the application as
1737 specified in the flow pattern. The payload of matching packets is
1738 encrypted on egress, and decrypted and authenticated on ingress.
1739 For INLINE_PROTOCOL, the security protocol is fully offloaded to HW,
1740 providing full encapsulation and decapsulation of packets in security
1741 protocols. The flow pattern specifies both the outer security header fields
1742 and the inner packet fields. The security session specified in the action
1743 must match the pattern parameters.
1745 The security session specified in the action must be created on the same
1746 port as the flow action that is being specified.
1748 The ingress/egress flow attribute should match that specified in the
1749 security session if the security session supports the definition of the
1752 Multiple flows can be configured to use the same security session.
1754 .. _table_rte_flow_action_security:
1758 +----------------------+--------------------------------------+
1760 +======================+======================================+
1761 | ``security_session`` | security session to apply |
1762 +----------------------+--------------------------------------+
1764 The following is an example of configuring IPsec inline using the
1765 INLINE_CRYPTO security session:
1767 The encryption algorithm, keys and salt are part of the opaque
1768 ``rte_security_session``. The SA is identified according to the IP and ESP
1769 fields in the pattern items.
1771 .. _table_rte_flow_item_esp_inline_example:
1773 .. table:: IPsec inline crypto flow pattern items.
1775 +-------+----------+
1777 +=======+==========+
1779 +-------+----------+
1781 +-------+----------+
1783 +-------+----------+
1785 +-------+----------+
1787 .. _table_rte_flow_action_esp_inline_example:
1789 .. table:: IPsec inline flow actions.
1791 +-------+----------+
1793 +=======+==========+
1795 +-------+----------+
1797 +-------+----------+
1799 Action: ``OF_SET_MPLS_TTL``
1800 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1802 Implements ``OFPAT_SET_MPLS_TTL`` ("MPLS TTL") as defined by the `OpenFlow
1803 Switch Specification`_.
1805 .. _table_rte_flow_action_of_set_mpls_ttl:
1807 .. table:: OF_SET_MPLS_TTL
1809 +--------------+----------+
1811 +==============+==========+
1812 | ``mpls_ttl`` | MPLS TTL |
1813 +--------------+----------+
1815 Action: ``OF_DEC_MPLS_TTL``
1816 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1818 Implements ``OFPAT_DEC_MPLS_TTL`` ("decrement MPLS TTL") as defined by the
1819 `OpenFlow Switch Specification`_.
1821 .. _table_rte_flow_action_of_dec_mpls_ttl:
1823 .. table:: OF_DEC_MPLS_TTL
1831 Action: ``OF_SET_NW_TTL``
1832 ^^^^^^^^^^^^^^^^^^^^^^^^^
1834 Implements ``OFPAT_SET_NW_TTL`` ("IP TTL") as defined by the `OpenFlow
1835 Switch Specification`_.
1837 .. _table_rte_flow_action_of_set_nw_ttl:
1839 .. table:: OF_SET_NW_TTL
1841 +------------+--------+
1843 +============+========+
1844 | ``nw_ttl`` | IP TTL |
1845 +------------+--------+
1847 Action: ``OF_DEC_NW_TTL``
1848 ^^^^^^^^^^^^^^^^^^^^^^^^^
1850 Implements ``OFPAT_DEC_NW_TTL`` ("decrement IP TTL") as defined by the
1851 `OpenFlow Switch Specification`_.
1853 .. _table_rte_flow_action_of_dec_nw_ttl:
1855 .. table:: OF_DEC_NW_TTL
1863 Action: ``OF_COPY_TTL_OUT``
1864 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1866 Implements ``OFPAT_COPY_TTL_OUT`` ("copy TTL "outwards" -- from
1867 next-to-outermost to outermost") as defined by the `OpenFlow Switch
1870 .. _table_rte_flow_action_of_copy_ttl_out:
1872 .. table:: OF_COPY_TTL_OUT
1880 Action: ``OF_COPY_TTL_IN``
1881 ^^^^^^^^^^^^^^^^^^^^^^^^^^
1883 Implements ``OFPAT_COPY_TTL_IN`` ("copy TTL "inwards" -- from outermost to
1884 next-to-outermost") as defined by the `OpenFlow Switch Specification`_.
1886 .. _table_rte_flow_action_of_copy_ttl_in:
1888 .. table:: OF_COPY_TTL_IN
1896 Action: ``OF_POP_VLAN``
1897 ^^^^^^^^^^^^^^^^^^^^^^^
1899 Implements ``OFPAT_POP_VLAN`` ("pop the outer VLAN tag") as defined
1900 by the `OpenFlow Switch Specification`_.
1902 .. _table_rte_flow_action_of_pop_vlan:
1904 .. table:: OF_POP_VLAN
1912 Action: ``OF_PUSH_VLAN``
1913 ^^^^^^^^^^^^^^^^^^^^^^^^
1915 Implements ``OFPAT_PUSH_VLAN`` ("push a new VLAN tag") as defined by the
1916 `OpenFlow Switch Specification`_.
1918 .. _table_rte_flow_action_of_push_vlan:
1920 .. table:: OF_PUSH_VLAN
1922 +---------------+-----------+
1924 +===============+===========+
1925 | ``ethertype`` | EtherType |
1926 +---------------+-----------+
1928 Action: ``OF_SET_VLAN_VID``
1929 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1931 Implements ``OFPAT_SET_VLAN_VID`` ("set the 802.1q VLAN id") as defined by
1932 the `OpenFlow Switch Specification`_.
1934 .. _table_rte_flow_action_of_set_vlan_vid:
1936 .. table:: OF_SET_VLAN_VID
1938 +--------------+---------+
1940 +==============+=========+
1941 | ``vlan_vid`` | VLAN id |
1942 +--------------+---------+
1944 Action: ``OF_SET_VLAN_PCP``
1945 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1947 Implements ``OFPAT_SET_LAN_PCP`` ("set the 802.1q priority") as defined by
1948 the `OpenFlow Switch Specification`_.
1950 .. _table_rte_flow_action_of_set_vlan_pcp:
1952 .. table:: OF_SET_VLAN_PCP
1954 +--------------+---------------+
1956 +==============+===============+
1957 | ``vlan_pcp`` | VLAN priority |
1958 +--------------+---------------+
1960 Action: ``OF_POP_MPLS``
1961 ^^^^^^^^^^^^^^^^^^^^^^^
1963 Implements ``OFPAT_POP_MPLS`` ("pop the outer MPLS tag") as defined by the
1964 `OpenFlow Switch Specification`_.
1966 .. _table_rte_flow_action_of_pop_mpls:
1968 .. table:: OF_POP_MPLS
1970 +---------------+-----------+
1972 +===============+===========+
1973 | ``ethertype`` | EtherType |
1974 +---------------+-----------+
1976 Action: ``OF_PUSH_MPLS``
1977 ^^^^^^^^^^^^^^^^^^^^^^^^
1979 Implements ``OFPAT_PUSH_MPLS`` ("push a new MPLS tag") as defined by the
1980 `OpenFlow Switch Specification`_.
1982 .. _table_rte_flow_action_of_push_mpls:
1984 .. table:: OF_PUSH_MPLS
1986 +---------------+-----------+
1988 +===============+===========+
1989 | ``ethertype`` | EtherType |
1990 +---------------+-----------+
1992 Action: ``VXLAN_ENCAP``
1993 ^^^^^^^^^^^^^^^^^^^^^^^
1995 Performs a VXLAN encapsulation action by encapsulating the matched flow in the
1996 VXLAN tunnel as defined in the``rte_flow_action_vxlan_encap`` flow items
1999 This action modifies the payload of matched flows. The flow definition specified
2000 in the ``rte_flow_action_tunnel_encap`` action structure must define a valid
2001 VLXAN network overlay which conforms with RFC 7348 (Virtual eXtensible Local
2002 Area Network (VXLAN): A Framework for Overlaying Virtualized Layer 2 Networks
2003 over Layer 3 Networks). The pattern must be terminated with the
2004 RTE_FLOW_ITEM_TYPE_END item type.
2006 .. _table_rte_flow_action_vxlan_encap:
2008 .. table:: VXLAN_ENCAP
2010 +----------------+-------------------------------------+
2012 +================+=====================================+
2013 | ``definition`` | Tunnel end-point overlay definition |
2014 +----------------+-------------------------------------+
2016 .. _table_rte_flow_action_vxlan_encap_example:
2018 .. table:: IPv4 VxLAN flow pattern example.
2020 +-------+----------+
2022 +=======+==========+
2024 +-------+----------+
2026 +-------+----------+
2028 +-------+----------+
2030 +-------+----------+
2032 +-------+----------+
2034 Action: ``VXLAN_DECAP``
2035 ^^^^^^^^^^^^^^^^^^^^^^^
2037 Performs a decapsulation action by stripping all headers of the VXLAN tunnel
2038 network overlay from the matched flow.
2040 The flow items pattern defined for the flow rule with which a ``VXLAN_DECAP``
2041 action is specified, must define a valid VXLAN tunnel as per RFC7348. If the
2042 flow pattern does not specify a valid VXLAN tunnel then a
2043 RTE_FLOW_ERROR_TYPE_ACTION error should be returned.
2045 This action modifies the payload of matched flows.
2047 Action: ``NVGRE_ENCAP``
2048 ^^^^^^^^^^^^^^^^^^^^^^^
2050 Performs a NVGRE encapsulation action by encapsulating the matched flow in the
2051 NVGRE tunnel as defined in the``rte_flow_action_tunnel_encap`` flow item
2054 This action modifies the payload of matched flows. The flow definition specified
2055 in the ``rte_flow_action_tunnel_encap`` action structure must defined a valid
2056 NVGRE network overlay which conforms with RFC 7637 (NVGRE: Network
2057 Virtualization Using Generic Routing Encapsulation). The pattern must be
2058 terminated with the RTE_FLOW_ITEM_TYPE_END item type.
2060 .. _table_rte_flow_action_nvgre_encap:
2062 .. table:: NVGRE_ENCAP
2064 +----------------+-------------------------------------+
2066 +================+=====================================+
2067 | ``definition`` | NVGRE end-point overlay definition |
2068 +----------------+-------------------------------------+
2070 .. _table_rte_flow_action_nvgre_encap_example:
2072 .. table:: IPv4 NVGRE flow pattern example.
2074 +-------+----------+
2076 +=======+==========+
2078 +-------+----------+
2080 +-------+----------+
2082 +-------+----------+
2084 +-------+----------+
2086 Action: ``NVGRE_DECAP``
2087 ^^^^^^^^^^^^^^^^^^^^^^^
2089 Performs a decapsulation action by stripping all headers of the NVGRE tunnel
2090 network overlay from the matched flow.
2092 The flow items pattern defined for the flow rule with which a ``NVGRE_DECAP``
2093 action is specified, must define a valid NVGRE tunnel as per RFC7637. If the
2094 flow pattern does not specify a valid NVGRE tunnel then a
2095 RTE_FLOW_ERROR_TYPE_ACTION error should be returned.
2097 This action modifies the payload of matched flows.
2099 Action: ``RAW_ENCAP``
2100 ^^^^^^^^^^^^^^^^^^^^^
2102 Adds outer header whose template is provided in its data buffer,
2103 as defined in the ``rte_flow_action_raw_encap`` definition.
2105 This action modifies the payload of matched flows. The data supplied must
2106 be a valid header, either holding layer 2 data in case of adding layer 2 after
2107 decap layer 3 tunnel (for example MPLSoGRE) or complete tunnel definition
2108 starting from layer 2 and moving to the tunnel item itself. When applied to
2109 the original packet the resulting packet must be a valid packet.
2111 .. _table_rte_flow_action_raw_encap:
2113 .. table:: RAW_ENCAP
2115 +----------------+----------------------------------------+
2117 +================+========================================+
2118 | ``data`` | Encapsulation data |
2119 +----------------+----------------------------------------+
2120 | ``preserve`` | Bit-mask of data to preserve on output |
2121 +----------------+----------------------------------------+
2122 | ``size`` | Size of data and preserve |
2123 +----------------+----------------------------------------+
2125 Action: ``RAW_DECAP``
2126 ^^^^^^^^^^^^^^^^^^^^^^^
2128 Remove outer header whose template is provided in its data buffer,
2129 as defined in the ``rte_flow_action_raw_decap``
2131 This action modifies the payload of matched flows. The data supplied must
2132 be a valid header, either holding layer 2 data in case of removing layer 2
2133 before encapsulation of layer 3 tunnel (for example MPLSoGRE) or complete
2134 tunnel definition starting from layer 2 and moving to the tunnel item itself.
2135 When applied to the original packet the resulting packet must be a
2138 .. _table_rte_flow_action_raw_decap:
2140 .. table:: RAW_DECAP
2142 +----------------+----------------------------------------+
2144 +================+========================================+
2145 | ``data`` | Decapsulation data |
2146 +----------------+----------------------------------------+
2147 | ``size`` | Size of data |
2148 +----------------+----------------------------------------+
2150 Action: ``SET_IPV4_SRC``
2151 ^^^^^^^^^^^^^^^^^^^^^^^^
2153 Set a new IPv4 source address in the outermost IPv4 header.
2155 It must be used with a valid RTE_FLOW_ITEM_TYPE_IPV4 flow pattern item.
2156 Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be returned.
2158 .. _table_rte_flow_action_set_ipv4_src:
2160 .. table:: SET_IPV4_SRC
2162 +-----------------------------------------+
2164 +===============+=========================+
2165 | ``ipv4_addr`` | new IPv4 source address |
2166 +---------------+-------------------------+
2168 Action: ``SET_IPV4_DST``
2169 ^^^^^^^^^^^^^^^^^^^^^^^^
2171 Set a new IPv4 destination address in the outermost IPv4 header.
2173 It must be used with a valid RTE_FLOW_ITEM_TYPE_IPV4 flow pattern item.
2174 Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be returned.
2176 .. _table_rte_flow_action_set_ipv4_dst:
2178 .. table:: SET_IPV4_DST
2180 +---------------+------------------------------+
2182 +===============+==============================+
2183 | ``ipv4_addr`` | new IPv4 destination address |
2184 +---------------+------------------------------+
2186 Action: ``SET_IPV6_SRC``
2187 ^^^^^^^^^^^^^^^^^^^^^^^^
2189 Set a new IPv6 source address in the outermost IPv6 header.
2191 It must be used with a valid RTE_FLOW_ITEM_TYPE_IPV6 flow pattern item.
2192 Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be returned.
2194 .. _table_rte_flow_action_set_ipv6_src:
2196 .. table:: SET_IPV6_SRC
2198 +---------------+-------------------------+
2200 +===============+=========================+
2201 | ``ipv6_addr`` | new IPv6 source address |
2202 +---------------+-------------------------+
2204 Action: ``SET_IPV6_DST``
2205 ^^^^^^^^^^^^^^^^^^^^^^^^
2207 Set a new IPv6 destination address in the outermost IPv6 header.
2209 It must be used with a valid RTE_FLOW_ITEM_TYPE_IPV6 flow pattern item.
2210 Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be returned.
2212 .. _table_rte_flow_action_set_ipv6_dst:
2214 .. table:: SET_IPV6_DST
2216 +---------------+------------------------------+
2218 +===============+==============================+
2219 | ``ipv6_addr`` | new IPv6 destination address |
2220 +---------------+------------------------------+
2222 Action: ``SET_TP_SRC``
2223 ^^^^^^^^^^^^^^^^^^^^^^^^^
2225 Set a new source port number in the outermost TCP/UDP header.
2227 It must be used with a valid RTE_FLOW_ITEM_TYPE_TCP or RTE_FLOW_ITEM_TYPE_UDP
2228 flow pattern item. Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be returned.
2230 .. _table_rte_flow_action_set_tp_src:
2232 .. table:: SET_TP_SRC
2234 +----------+-------------------------+
2236 +==========+=========================+
2237 | ``port`` | new TCP/UDP source port |
2238 +---------------+--------------------+
2240 Action: ``SET_TP_DST``
2241 ^^^^^^^^^^^^^^^^^^^^^^^^^
2243 Set a new destination port number in the outermost TCP/UDP header.
2245 It must be used with a valid RTE_FLOW_ITEM_TYPE_TCP or RTE_FLOW_ITEM_TYPE_UDP
2246 flow pattern item. Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be returned.
2248 .. _table_rte_flow_action_set_tp_dst:
2250 .. table:: SET_TP_DST
2252 +----------+------------------------------+
2254 +==========+==============================+
2255 | ``port`` | new TCP/UDP destination port |
2256 +---------------+-------------------------+
2258 Action: ``MAC_SWAP``
2259 ^^^^^^^^^^^^^^^^^^^^^^^^^
2261 Swap the source and destination MAC addresses in the outermost Ethernet
2264 It must be used with a valid RTE_FLOW_ITEM_TYPE_ETH flow pattern item.
2265 Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be returned.
2267 .. _table_rte_flow_action_mac_swap:
2282 If there is no valid RTE_FLOW_ITEM_TYPE_IPV4 or RTE_FLOW_ITEM_TYPE_IPV6
2283 in pattern, Some PMDs will reject rule because behavior will be undefined.
2285 .. _table_rte_flow_action_dec_ttl:
2298 Assigns a new TTL value.
2300 If there is no valid RTE_FLOW_ITEM_TYPE_IPV4 or RTE_FLOW_ITEM_TYPE_IPV6
2301 in pattern, Some PMDs will reject rule because behavior will be undefined.
2303 .. _table_rte_flow_action_set_ttl:
2307 +---------------+--------------------+
2309 +===============+====================+
2310 | ``ttl_value`` | new TTL value |
2311 +---------------+--------------------+
2313 Action: ``SET_MAC_SRC``
2314 ^^^^^^^^^^^^^^^^^^^^^^^
2316 Set source MAC address.
2318 It must be used with a valid RTE_FLOW_ITEM_TYPE_ETH flow pattern item.
2319 Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be returned.
2321 .. _table_rte_flow_action_set_mac_src:
2323 .. table:: SET_MAC_SRC
2325 +--------------+---------------+
2327 +==============+===============+
2328 | ``mac_addr`` | MAC address |
2329 +--------------+---------------+
2331 Action: ``SET_MAC_DST``
2332 ^^^^^^^^^^^^^^^^^^^^^^^
2334 Set destination MAC address.
2336 It must be used with a valid RTE_FLOW_ITEM_TYPE_ETH flow pattern item.
2337 Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be returned.
2339 .. _table_rte_flow_action_set_mac_dst:
2341 .. table:: SET_MAC_DST
2343 +--------------+---------------+
2345 +==============+===============+
2346 | ``mac_addr`` | MAC address |
2347 +--------------+---------------+
2349 Action: ``INC_TCP_SEQ``
2350 ^^^^^^^^^^^^^^^^^^^^^^^
2352 Increase sequence number in the outermost TCP header.
2353 Value to increase TCP sequence number by is a big-endian 32 bit integer.
2355 Using this action on non-matching traffic will result in undefined behavior.
2357 Action: ``DEC_TCP_SEQ``
2358 ^^^^^^^^^^^^^^^^^^^^^^^
2360 Decrease sequence number in the outermost TCP header.
2361 Value to decrease TCP sequence number by is a big-endian 32 bit integer.
2363 Using this action on non-matching traffic will result in undefined behavior.
2365 Action: ``INC_TCP_ACK``
2366 ^^^^^^^^^^^^^^^^^^^^^^^
2368 Increase acknowledgment number in the outermost TCP header.
2369 Value to increase TCP acknowledgment number by is a big-endian 32 bit integer.
2371 Using this action on non-matching traffic will result in undefined behavior.
2373 Action: ``DEC_TCP_ACK``
2374 ^^^^^^^^^^^^^^^^^^^^^^^
2376 Decrease acknowledgment number in the outermost TCP header.
2377 Value to decrease TCP acknowledgment number by is a big-endian 32 bit integer.
2379 Using this action on non-matching traffic will result in undefined behavior.
2384 All specified pattern items (``enum rte_flow_item_type``) and actions
2385 (``enum rte_flow_action_type``) use positive identifiers.
2387 The negative space is reserved for dynamic types generated by PMDs during
2388 run-time. PMDs may encounter them as a result but must not accept negative
2389 identifiers they are not aware of.
2391 A method to generate them remains to be defined.
2396 Pattern item types will be added as new protocols are implemented.
2398 Variable headers support through dedicated pattern items, for example in
2399 order to match specific IPv4 options and IPv6 extension headers would be
2400 stacked after IPv4/IPv6 items.
2402 Other action types are planned but are not defined yet. These include the
2403 ability to alter packet data in several ways, such as performing
2404 encapsulation/decapsulation of tunnel headers.
2409 A rather simple API with few functions is provided to fully manage flow
2412 Each created flow rule is associated with an opaque, PMD-specific handle
2413 pointer. The application is responsible for keeping it until the rule is
2416 Flows rules are represented by ``struct rte_flow`` objects.
2421 Given that expressing a definite set of device capabilities is not
2422 practical, a dedicated function is provided to check if a flow rule is
2423 supported and can be created.
2428 rte_flow_validate(uint16_t port_id,
2429 const struct rte_flow_attr *attr,
2430 const struct rte_flow_item pattern[],
2431 const struct rte_flow_action actions[],
2432 struct rte_flow_error *error);
2434 The flow rule is validated for correctness and whether it could be accepted
2435 by the device given sufficient resources. The rule is checked against the
2436 current device mode and queue configuration. The flow rule may also
2437 optionally be validated against existing flow rules and device resources.
2438 This function has no effect on the target device.
2440 The returned value is guaranteed to remain valid only as long as no
2441 successful calls to ``rte_flow_create()`` or ``rte_flow_destroy()`` are made
2442 in the meantime and no device parameter affecting flow rules in any way are
2443 modified, due to possible collisions or resource limitations (although in
2444 such cases ``EINVAL`` should not be returned).
2448 - ``port_id``: port identifier of Ethernet device.
2449 - ``attr``: flow rule attributes.
2450 - ``pattern``: pattern specification (list terminated by the END pattern
2452 - ``actions``: associated actions (list terminated by the END action).
2453 - ``error``: perform verbose error reporting if not NULL. PMDs initialize
2454 this structure in case of error only.
2458 - 0 if flow rule is valid and can be created. A negative errno value
2459 otherwise (``rte_errno`` is also set), the following errors are defined.
2460 - ``-ENOSYS``: underlying device does not support this functionality.
2461 - ``-EINVAL``: unknown or invalid rule specification.
2462 - ``-ENOTSUP``: valid but unsupported rule specification (e.g. partial
2463 bit-masks are unsupported).
2464 - ``EEXIST``: collision with an existing rule. Only returned if device
2465 supports flow rule collision checking and there was a flow rule
2466 collision. Not receiving this return code is no guarantee that creating
2467 the rule will not fail due to a collision.
2468 - ``ENOMEM``: not enough memory to execute the function, or if the device
2469 supports resource validation, resource limitation on the device.
2470 - ``-EBUSY``: action cannot be performed due to busy device resources, may
2471 succeed if the affected queues or even the entire port are in a stopped
2472 state (see ``rte_eth_dev_rx_queue_stop()`` and ``rte_eth_dev_stop()``).
2477 Creating a flow rule is similar to validating one, except the rule is
2478 actually created and a handle returned.
2483 rte_flow_create(uint16_t port_id,
2484 const struct rte_flow_attr *attr,
2485 const struct rte_flow_item pattern[],
2486 const struct rte_flow_action *actions[],
2487 struct rte_flow_error *error);
2491 - ``port_id``: port identifier of Ethernet device.
2492 - ``attr``: flow rule attributes.
2493 - ``pattern``: pattern specification (list terminated by the END pattern
2495 - ``actions``: associated actions (list terminated by the END action).
2496 - ``error``: perform verbose error reporting if not NULL. PMDs initialize
2497 this structure in case of error only.
2501 A valid handle in case of success, NULL otherwise and ``rte_errno`` is set
2502 to the positive version of one of the error codes defined for
2503 ``rte_flow_validate()``.
2508 Flow rules destruction is not automatic, and a queue or a port should not be
2509 released if any are still attached to them. Applications must take care of
2510 performing this step before releasing resources.
2515 rte_flow_destroy(uint16_t port_id,
2516 struct rte_flow *flow,
2517 struct rte_flow_error *error);
2520 Failure to destroy a flow rule handle may occur when other flow rules depend
2521 on it, and destroying it would result in an inconsistent state.
2523 This function is only guaranteed to succeed if handles are destroyed in
2524 reverse order of their creation.
2528 - ``port_id``: port identifier of Ethernet device.
2529 - ``flow``: flow rule handle to destroy.
2530 - ``error``: perform verbose error reporting if not NULL. PMDs initialize
2531 this structure in case of error only.
2535 - 0 on success, a negative errno value otherwise and ``rte_errno`` is set.
2540 Convenience function to destroy all flow rule handles associated with a
2541 port. They are released as with successive calls to ``rte_flow_destroy()``.
2546 rte_flow_flush(uint16_t port_id,
2547 struct rte_flow_error *error);
2549 In the unlikely event of failure, handles are still considered destroyed and
2550 no longer valid but the port must be assumed to be in an inconsistent state.
2554 - ``port_id``: port identifier of Ethernet device.
2555 - ``error``: perform verbose error reporting if not NULL. PMDs initialize
2556 this structure in case of error only.
2560 - 0 on success, a negative errno value otherwise and ``rte_errno`` is set.
2565 Query an existing flow rule.
2567 This function allows retrieving flow-specific data such as counters. Data
2568 is gathered by special actions which must be present in the flow rule
2574 rte_flow_query(uint16_t port_id,
2575 struct rte_flow *flow,
2576 const struct rte_flow_action *action,
2578 struct rte_flow_error *error);
2582 - ``port_id``: port identifier of Ethernet device.
2583 - ``flow``: flow rule handle to query.
2584 - ``action``: action to query, this must match prototype from flow rule.
2585 - ``data``: pointer to storage for the associated query data type.
2586 - ``error``: perform verbose error reporting if not NULL. PMDs initialize
2587 this structure in case of error only.
2591 - 0 on success, a negative errno value otherwise and ``rte_errno`` is set.
2593 .. _flow_isolated_mode:
2598 The general expectation for ingress traffic is that flow rules process it
2599 first; the remaining unmatched or pass-through traffic usually ends up in a
2600 queue (with or without RSS, locally or in some sub-device instance)
2601 depending on the global configuration settings of a port.
2603 While fine from a compatibility standpoint, this approach makes drivers more
2604 complex as they have to check for possible side effects outside of this API
2605 when creating or destroying flow rules. It results in a more limited set of
2606 available rule types due to the way device resources are assigned (e.g. no
2607 support for the RSS action even on capable hardware).
2609 Given that nonspecific traffic can be handled by flow rules as well,
2610 isolated mode is a means for applications to tell a driver that ingress on
2611 the underlying port must be injected from the defined flow rules only; that
2612 no default traffic is expected outside those rules.
2614 This has the following benefits:
2616 - Applications get finer-grained control over the kind of traffic they want
2617 to receive (no traffic by default).
2619 - More importantly they control at what point nonspecific traffic is handled
2620 relative to other flow rules, by adjusting priority levels.
2622 - Drivers can assign more hardware resources to flow rules and expand the
2623 set of supported rule types.
2625 Because toggling isolated mode may cause profound changes to the ingress
2626 processing path of a driver, it may not be possible to leave it once
2627 entered. Likewise, existing flow rules or global configuration settings may
2628 prevent a driver from entering isolated mode.
2630 Applications relying on this mode are therefore encouraged to toggle it as
2631 soon as possible after device initialization, ideally before the first call
2632 to ``rte_eth_dev_configure()`` to avoid possible failures due to conflicting
2635 Once effective, the following functionality has no effect on the underlying
2636 port and may return errors such as ``ENOTSUP`` ("not supported"):
2638 - Toggling promiscuous mode.
2639 - Toggling allmulticast mode.
2640 - Configuring MAC addresses.
2641 - Configuring multicast addresses.
2642 - Configuring VLAN filters.
2643 - Configuring Rx filters through the legacy API (e.g. FDIR).
2644 - Configuring global RSS settings.
2649 rte_flow_isolate(uint16_t port_id, int set, struct rte_flow_error *error);
2653 - ``port_id``: port identifier of Ethernet device.
2654 - ``set``: nonzero to enter isolated mode, attempt to leave it otherwise.
2655 - ``error``: perform verbose error reporting if not NULL. PMDs initialize
2656 this structure in case of error only.
2660 - 0 on success, a negative errno value otherwise and ``rte_errno`` is set.
2662 Verbose error reporting
2663 -----------------------
2665 The defined *errno* values may not be accurate enough for users or
2666 application developers who want to investigate issues related to flow rules
2667 management. A dedicated error object is defined for this purpose:
2671 enum rte_flow_error_type {
2672 RTE_FLOW_ERROR_TYPE_NONE, /**< No error. */
2673 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, /**< Cause unspecified. */
2674 RTE_FLOW_ERROR_TYPE_HANDLE, /**< Flow rule (handle). */
2675 RTE_FLOW_ERROR_TYPE_ATTR_GROUP, /**< Group field. */
2676 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY, /**< Priority field. */
2677 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS, /**< Ingress field. */
2678 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, /**< Egress field. */
2679 RTE_FLOW_ERROR_TYPE_ATTR, /**< Attributes structure. */
2680 RTE_FLOW_ERROR_TYPE_ITEM_NUM, /**< Pattern length. */
2681 RTE_FLOW_ERROR_TYPE_ITEM, /**< Specific pattern item. */
2682 RTE_FLOW_ERROR_TYPE_ACTION_NUM, /**< Number of actions. */
2683 RTE_FLOW_ERROR_TYPE_ACTION, /**< Specific action. */
2686 struct rte_flow_error {
2687 enum rte_flow_error_type type; /**< Cause field and error types. */
2688 const void *cause; /**< Object responsible for the error. */
2689 const char *message; /**< Human-readable error message. */
2692 Error type ``RTE_FLOW_ERROR_TYPE_NONE`` stands for no error, in which case
2693 remaining fields can be ignored. Other error types describe the type of the
2694 object pointed by ``cause``.
2696 If non-NULL, ``cause`` points to the object responsible for the error. For a
2697 flow rule, this may be a pattern item or an individual action.
2699 If non-NULL, ``message`` provides a human-readable error message.
2701 This object is normally allocated by applications and set by PMDs in case of
2702 error, the message points to a constant string which does not need to be
2703 freed by the application, however its pointer can be considered valid only
2704 as long as its associated DPDK port remains configured. Closing the
2705 underlying device or unloading the PMD invalidates it.
2716 rte_flow_error_set(struct rte_flow_error *error,
2718 enum rte_flow_error_type type,
2720 const char *message);
2722 This function initializes ``error`` (if non-NULL) with the provided
2723 parameters and sets ``rte_errno`` to ``code``. A negative error ``code`` is
2732 rte_flow_conv(enum rte_flow_conv_op op,
2736 struct rte_flow_error *error);
2738 Convert ``src`` to ``dst`` according to operation ``op``. Possible
2741 - Attributes, pattern item or action duplication.
2742 - Duplication of an entire pattern or list of actions.
2743 - Duplication of a complete flow rule description.
2744 - Pattern item or action name retrieval.
2749 - DPDK does not keep track of flow rules definitions or flow rule objects
2750 automatically. Applications may keep track of the former and must keep
2751 track of the latter. PMDs may also do it for internal needs, however this
2752 must not be relied on by applications.
2754 - Flow rules are not maintained between successive port initializations. An
2755 application exiting without releasing them and restarting must re-create
2758 - API operations are synchronous and blocking (``EAGAIN`` cannot be
2761 - There is no provision for re-entrancy/multi-thread safety, although nothing
2762 should prevent different devices from being configured at the same
2763 time. PMDs may protect their control path functions accordingly.
2765 - Stopping the data path (TX/RX) should not be necessary when managing flow
2766 rules. If this cannot be achieved naturally or with workarounds (such as
2767 temporarily replacing the burst function pointers), an appropriate error
2768 code must be returned (``EBUSY``).
2770 - PMDs, not applications, are responsible for maintaining flow rules
2771 configuration when stopping and restarting a port or performing other
2772 actions which may affect them. They can only be destroyed explicitly by
2775 For devices exposing multiple ports sharing global settings affected by flow
2778 - All ports under DPDK control must behave consistently, PMDs are
2779 responsible for making sure that existing flow rules on a port are not
2780 affected by other ports.
2782 - Ports not under DPDK control (unaffected or handled by other applications)
2783 are user's responsibility. They may affect existing flow rules and cause
2784 undefined behavior. PMDs aware of this may prevent flow rules creation
2785 altogether in such cases.
2790 The PMD interface is defined in ``rte_flow_driver.h``. It is not subject to
2791 API/ABI versioning constraints as it is not exposed to applications and may
2792 evolve independently.
2794 It is currently implemented on top of the legacy filtering framework through
2795 filter type *RTE_ETH_FILTER_GENERIC* that accepts the single operation
2796 *RTE_ETH_FILTER_GET* to return PMD-specific *rte_flow* callbacks wrapped
2797 inside ``struct rte_flow_ops``.
2799 This overhead is temporarily necessary in order to keep compatibility with
2800 the legacy filtering framework, which should eventually disappear.
2802 - PMD callbacks implement exactly the interface described in `Rules
2803 management`_, except for the port ID argument which has already been
2804 converted to a pointer to the underlying ``struct rte_eth_dev``.
2806 - Public API functions do not process flow rules definitions at all before
2807 calling PMD functions (no basic error checking, no validation
2808 whatsoever). They only make sure these callbacks are non-NULL or return
2809 the ``ENOSYS`` (function not supported) error.
2811 This interface additionally defines the following helper function:
2813 - ``rte_flow_ops_get()``: get generic flow operations structure from a
2816 More will be added over time.
2818 Device compatibility
2819 --------------------
2821 No known implementation supports all the described features.
2823 Unsupported features or combinations are not expected to be fully emulated
2824 in software by PMDs for performance reasons. Partially supported features
2825 may be completed in software as long as hardware performs most of the work
2826 (such as queue redirection and packet recognition).
2828 However PMDs are expected to do their best to satisfy application requests
2829 by working around hardware limitations as long as doing so does not affect
2830 the behavior of existing flow rules.
2832 The following sections provide a few examples of such cases and describe how
2833 PMDs should handle them, they are based on limitations built into the
2839 Each flow rule comes with its own, per-layer bit-masks, while hardware may
2840 support only a single, device-wide bit-mask for a given layer type, so that
2841 two IPv4 rules cannot use different bit-masks.
2843 The expected behavior in this case is that PMDs automatically configure
2844 global bit-masks according to the needs of the first flow rule created.
2846 Subsequent rules are allowed only if their bit-masks match those, the
2847 ``EEXIST`` error code should be returned otherwise.
2849 Unsupported layer types
2850 ~~~~~~~~~~~~~~~~~~~~~~~
2852 Many protocols can be simulated by crafting patterns with the `Item: RAW`_
2855 PMDs can rely on this capability to simulate support for protocols with
2856 headers not directly recognized by hardware.
2858 ``ANY`` pattern item
2859 ~~~~~~~~~~~~~~~~~~~~
2861 This pattern item stands for anything, which can be difficult to translate
2862 to something hardware would understand, particularly if followed by more
2865 Consider the following pattern:
2867 .. _table_rte_flow_unsupported_any:
2869 .. table:: Pattern with ANY as L3
2871 +-------+-----------------------+
2873 +=======+=======================+
2875 +-------+-----+---------+-------+
2876 | 1 | ANY | ``num`` | ``1`` |
2877 +-------+-----+---------+-------+
2879 +-------+-----------------------+
2881 +-------+-----------------------+
2883 Knowing that TCP does not make sense with something other than IPv4 and IPv6
2884 as L3, such a pattern may be translated to two flow rules instead:
2886 .. _table_rte_flow_unsupported_any_ipv4:
2888 .. table:: ANY replaced with IPV4
2890 +-------+--------------------+
2892 +=======+====================+
2894 +-------+--------------------+
2895 | 1 | IPV4 (zeroed mask) |
2896 +-------+--------------------+
2898 +-------+--------------------+
2900 +-------+--------------------+
2904 .. _table_rte_flow_unsupported_any_ipv6:
2906 .. table:: ANY replaced with IPV6
2908 +-------+--------------------+
2910 +=======+====================+
2912 +-------+--------------------+
2913 | 1 | IPV6 (zeroed mask) |
2914 +-------+--------------------+
2916 +-------+--------------------+
2918 +-------+--------------------+
2920 Note that as soon as a ANY rule covers several layers, this approach may
2921 yield a large number of hidden flow rules. It is thus suggested to only
2922 support the most common scenarios (anything as L2 and/or L3).
2927 - When combined with `Action: QUEUE`_, packet counting (`Action: COUNT`_)
2928 and tagging (`Action: MARK`_ or `Action: FLAG`_) may be implemented in
2929 software as long as the target queue is used by a single rule.
2931 - When a single target queue is provided, `Action: RSS`_ can also be
2932 implemented through `Action: QUEUE`_.
2937 While it would naturally make sense, flow rules cannot be assumed to be
2938 processed by hardware in the same order as their creation for several
2941 - They may be managed internally as a tree or a hash table instead of a
2943 - Removing a flow rule before adding another one can either put the new rule
2944 at the end of the list or reuse a freed entry.
2945 - Duplication may occur when packets are matched by several rules.
2947 For overlapping rules (particularly in order to use `Action: PASSTHRU`_)
2948 predictable behavior is only guaranteed by using different priority levels.
2950 Priority levels are not necessarily implemented in hardware, or may be
2951 severely limited (e.g. a single priority bit).
2953 For these reasons, priority levels may be implemented purely in software by
2956 - For devices expecting flow rules to be added in the correct order, PMDs
2957 may destroy and re-create existing rules after adding a new one with
2960 - A configurable number of dummy or empty rules can be created at
2961 initialization time to save high priority slots for later.
2963 - In order to save priority levels, PMDs may evaluate whether rules are
2964 likely to collide and adjust their priority accordingly.
2969 - A device profile selection function which could be used to force a
2970 permanent profile instead of relying on its automatic configuration based
2971 on existing flow rules.
2973 - A method to optimize *rte_flow* rules with specific pattern items and
2974 action types generated on the fly by PMDs. DPDK should assign negative
2975 numbers to these in order to not collide with the existing types. See
2978 - Adding specific egress pattern items and actions as described in
2979 `Attribute: Traffic direction`_.
2981 - Optional software fallback when PMDs are unable to handle requested flow
2982 rules so applications do not have to implement their own.
2984 .. _OpenFlow Switch Specification: https://www.opennetworking.org/software-defined-standards/specifications/