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 rules can apply to inbound and/or outbound traffic (ingress/egress).
175 Several pattern items and actions are valid and can be used in both
176 directions. At least one direction must be specified.
178 Specifying both directions at once for a given rule is not recommended but
179 may be valid in a few cases (e.g. shared counters).
184 Pattern items fall in two categories:
186 - Matching protocol headers and packet data, usually associated with a
187 specification structure. These must be stacked in the same order as the
188 protocol layers to match inside packets, starting from the lowest.
190 - Matching meta-data or affecting pattern processing, often without a
191 specification structure. Since they do not match packet contents, their
192 position in the list is usually not relevant.
194 Item specification structures are used to match specific values among
195 protocol fields (or item properties). Documentation describes for each item
196 whether they are associated with one and their type name if so.
198 Up to three structures of the same type can be set for a given item:
200 - ``spec``: values to match (e.g. a given IPv4 address).
202 - ``last``: upper bound for an inclusive range with corresponding fields in
205 - ``mask``: bit-mask applied to both ``spec`` and ``last`` whose purpose is
206 to distinguish the values to take into account and/or partially mask them
207 out (e.g. in order to match an IPv4 address prefix).
209 Usage restrictions and expected behavior:
211 - Setting either ``mask`` or ``last`` without ``spec`` is an error.
213 - Field values in ``last`` which are either 0 or equal to the corresponding
214 values in ``spec`` are ignored; they do not generate a range. Nonzero
215 values lower than those in ``spec`` are not supported.
217 - Setting ``spec`` and optionally ``last`` without ``mask`` causes the PMD
218 to use the default mask defined for that item (defined as
219 ``rte_flow_item_{name}_mask`` constants).
221 - Not setting any of them (assuming item type allows it) is equivalent to
222 providing an empty (zeroed) ``mask`` for broad (nonspecific) matching.
224 - ``mask`` is a simple bit-mask applied before interpreting the contents of
225 ``spec`` and ``last``, which may yield unexpected results if not used
226 carefully. For example, if for an IPv4 address field, ``spec`` provides
227 *10.1.2.3*, ``last`` provides *10.3.4.5* and ``mask`` provides
228 *255.255.0.0*, the effective range becomes *10.1.0.0* to *10.3.255.255*.
230 Example of an item specification matching an Ethernet header:
232 .. _table_rte_flow_pattern_item_example:
234 .. table:: Ethernet item
236 +----------+----------+--------------------+
237 | Field | Subfield | Value |
238 +==========+==========+====================+
239 | ``spec`` | ``src`` | ``00:01:02:03:04`` |
240 | +----------+--------------------+
241 | | ``dst`` | ``00:2a:66:00:01`` |
242 | +----------+--------------------+
243 | | ``type`` | ``0x22aa`` |
244 +----------+----------+--------------------+
245 | ``last`` | unspecified |
246 +----------+----------+--------------------+
247 | ``mask`` | ``src`` | ``00:ff:ff:ff:00`` |
248 | +----------+--------------------+
249 | | ``dst`` | ``00:00:00:00:ff`` |
250 | +----------+--------------------+
251 | | ``type`` | ``0x0000`` |
252 +----------+----------+--------------------+
254 Non-masked bits stand for any value (shown as ``?`` below), Ethernet headers
255 with the following properties are thus matched:
257 - ``src``: ``??:01:02:03:??``
258 - ``dst``: ``??:??:??:??:01``
259 - ``type``: ``0x????``
264 A pattern is formed by stacking items starting from the lowest protocol
265 layer to match. This stacking restriction does not apply to meta items which
266 can be placed anywhere in the stack without affecting the meaning of the
269 Patterns are terminated by END items.
273 .. _table_rte_flow_tcpv4_as_l4:
275 .. table:: TCPv4 as L4
291 .. _table_rte_flow_tcpv6_in_vxlan:
293 .. table:: TCPv6 in VXLAN
295 +-------+------------+
297 +=======+============+
299 +-------+------------+
301 +-------+------------+
303 +-------+------------+
305 +-------+------------+
307 +-------+------------+
309 +-------+------------+
311 +-------+------------+
313 +-------+------------+
317 .. _table_rte_flow_tcpv4_as_l4_meta:
319 .. table:: TCPv4 as L4 with meta items
341 The above example shows how meta items do not affect packet data matching
342 items, as long as those remain stacked properly. The resulting matching
343 pattern is identical to "TCPv4 as L4".
345 .. _table_rte_flow_udpv6_anywhere:
347 .. table:: UDPv6 anywhere
359 If supported by the PMD, omitting one or several protocol layers at the
360 bottom of the stack as in the above example (missing an Ethernet
361 specification) enables looking up anywhere in packets.
363 It is unspecified whether the payload of supported encapsulations
364 (e.g. VXLAN payload) is matched by such a pattern, which may apply to inner,
365 outer or both packets.
367 .. _table_rte_flow_invalid_l3:
369 .. table:: Invalid, missing L3
381 The above pattern is invalid due to a missing L3 specification between L2
382 (Ethernet) and L4 (UDP). Doing so is only allowed at the bottom and at the
388 They match meta-data or affect pattern processing instead of matching packet
389 data directly, most of them do not need a specification structure. This
390 particularity allows them to be specified anywhere in the stack without
391 causing any side effect.
396 End marker for item lists. Prevents further processing of items, thereby
399 - Its numeric value is 0 for convenience.
400 - PMD support is mandatory.
401 - ``spec``, ``last`` and ``mask`` are ignored.
403 .. _table_rte_flow_item_end:
407 +----------+---------+
409 +==========+=========+
410 | ``spec`` | ignored |
411 +----------+---------+
412 | ``last`` | ignored |
413 +----------+---------+
414 | ``mask`` | ignored |
415 +----------+---------+
420 Used as a placeholder for convenience. It is ignored and simply discarded by
423 - PMD support is mandatory.
424 - ``spec``, ``last`` and ``mask`` are ignored.
426 .. _table_rte_flow_item_void:
430 +----------+---------+
432 +==========+=========+
433 | ``spec`` | ignored |
434 +----------+---------+
435 | ``last`` | ignored |
436 +----------+---------+
437 | ``mask`` | ignored |
438 +----------+---------+
440 One usage example for this type is generating rules that share a common
441 prefix quickly without reallocating memory, only by updating item types:
443 .. _table_rte_flow_item_void_example:
445 .. table:: TCP, UDP or ICMP as L4
447 +-------+--------------------+
449 +=======+====================+
451 +-------+--------------------+
453 +-------+------+------+------+
454 | 2 | UDP | VOID | VOID |
455 +-------+------+------+------+
456 | 3 | VOID | TCP | VOID |
457 +-------+------+------+------+
458 | 4 | VOID | VOID | ICMP |
459 +-------+------+------+------+
461 +-------+--------------------+
466 Inverted matching, i.e. process packets that do not match the pattern.
468 - ``spec``, ``last`` and ``mask`` are ignored.
470 .. _table_rte_flow_item_invert:
474 +----------+---------+
476 +==========+=========+
477 | ``spec`` | ignored |
478 +----------+---------+
479 | ``last`` | ignored |
480 +----------+---------+
481 | ``mask`` | ignored |
482 +----------+---------+
484 Usage example, matching non-TCPv4 packets only:
486 .. _table_rte_flow_item_invert_example:
488 .. table:: Anything but TCPv4
507 Matches packets addressed to the physical function of the device.
509 If the underlying device function differs from the one that would normally
510 receive the matched traffic, specifying this item prevents it from reaching
511 that device unless the flow rule contains a `Action: PF`_. Packets are not
512 duplicated between device instances by default.
514 - Likely to return an error or never match any traffic if applied to a VF
516 - Can be combined with any number of `Item: VF`_ to match both PF and VF
518 - ``spec``, ``last`` and ``mask`` must not be set.
520 .. _table_rte_flow_item_pf:
537 Matches packets addressed to a virtual function ID of the device.
539 If the underlying device function differs from the one that would normally
540 receive the matched traffic, specifying this item prevents it from reaching
541 that device unless the flow rule contains a `Action: VF`_. Packets are not
542 duplicated between device instances by default.
544 - Likely to return an error or never match any traffic if this causes a VF
545 device to match traffic addressed to a different VF.
546 - Can be specified multiple times to match traffic addressed to several VF
548 - Can be combined with a PF item to match both PF and VF traffic.
549 - Default ``mask`` matches any VF ID.
551 .. _table_rte_flow_item_vf:
555 +----------+----------+---------------------------+
556 | Field | Subfield | Value |
557 +==========+==========+===========================+
558 | ``spec`` | ``id`` | destination VF ID |
559 +----------+----------+---------------------------+
560 | ``last`` | ``id`` | upper range value |
561 +----------+----------+---------------------------+
562 | ``mask`` | ``id`` | zeroed to match any VF ID |
563 +----------+----------+---------------------------+
568 Matches packets coming from the specified physical port of the underlying
571 The first PORT item overrides the physical port normally associated with the
572 specified DPDK input port (port_id). This item can be provided several times
573 to match additional physical ports.
575 Note that physical ports are not necessarily tied to DPDK input ports
576 (port_id) when those are not under DPDK control. Possible values are
577 specific to each device, they are not necessarily indexed from zero and may
580 As a device property, the list of allowed values as well as the value
581 associated with a port_id should be retrieved by other means.
583 - Default ``mask`` matches any port index.
585 .. _table_rte_flow_item_port:
589 +----------+-----------+--------------------------------+
590 | Field | Subfield | Value |
591 +==========+===========+================================+
592 | ``spec`` | ``index`` | physical port index |
593 +----------+-----------+--------------------------------+
594 | ``last`` | ``index`` | upper range value |
595 +----------+-----------+--------------------------------+
596 | ``mask`` | ``index`` | zeroed to match any port index |
597 +----------+-----------+--------------------------------+
599 Data matching item types
600 ~~~~~~~~~~~~~~~~~~~~~~~~
602 Most of these are basically protocol header definitions with associated
603 bit-masks. They must be specified (stacked) from lowest to highest protocol
604 layer to form a matching pattern.
606 The following list is not exhaustive, new protocols will be added in the
612 Matches any protocol in place of the current layer, a single ANY may also
613 stand for several protocol layers.
615 This is usually specified as the first pattern item when looking for a
616 protocol anywhere in a packet.
618 - Default ``mask`` stands for any number of layers.
620 .. _table_rte_flow_item_any:
624 +----------+----------+--------------------------------------+
625 | Field | Subfield | Value |
626 +==========+==========+======================================+
627 | ``spec`` | ``num`` | number of layers covered |
628 +----------+----------+--------------------------------------+
629 | ``last`` | ``num`` | upper range value |
630 +----------+----------+--------------------------------------+
631 | ``mask`` | ``num`` | zeroed to cover any number of layers |
632 +----------+----------+--------------------------------------+
634 Example for VXLAN TCP payload matching regardless of outer L3 (IPv4 or IPv6)
635 and L4 (UDP) both matched by the first ANY specification, and inner L3 (IPv4
636 or IPv6) matched by the second ANY specification:
638 .. _table_rte_flow_item_any_example:
640 .. table:: TCP in VXLAN with wildcards
642 +-------+------+----------+----------+-------+
643 | Index | Item | Field | Subfield | Value |
644 +=======+======+==========+==========+=======+
646 +-------+------+----------+----------+-------+
647 | 1 | ANY | ``spec`` | ``num`` | 2 |
648 +-------+------+----------+----------+-------+
650 +-------+------------------------------------+
652 +-------+------+----------+----------+-------+
653 | 4 | ANY | ``spec`` | ``num`` | 1 |
654 +-------+------+----------+----------+-------+
656 +-------+------------------------------------+
658 +-------+------------------------------------+
663 Matches a byte string of a given length at a given offset.
665 Offset is either absolute (using the start of the packet) or relative to the
666 end of the previous matched item in the stack, in which case negative values
669 If search is enabled, offset is used as the starting point. The search area
670 can be delimited by setting limit to a nonzero value, which is the maximum
671 number of bytes after offset where the pattern may start.
673 Matching a zero-length pattern is allowed, doing so resets the relative
674 offset for subsequent items.
676 - This type does not support ranges (``last`` field).
677 - Default ``mask`` matches all fields exactly.
679 .. _table_rte_flow_item_raw:
683 +----------+--------------+-------------------------------------------------+
684 | Field | Subfield | Value |
685 +==========+==============+=================================================+
686 | ``spec`` | ``relative`` | look for pattern after the previous item |
687 | +--------------+-------------------------------------------------+
688 | | ``search`` | search pattern from offset (see also ``limit``) |
689 | +--------------+-------------------------------------------------+
690 | | ``reserved`` | reserved, must be set to zero |
691 | +--------------+-------------------------------------------------+
692 | | ``offset`` | absolute or relative offset for ``pattern`` |
693 | +--------------+-------------------------------------------------+
694 | | ``limit`` | search area limit for start of ``pattern`` |
695 | +--------------+-------------------------------------------------+
696 | | ``length`` | ``pattern`` length |
697 | +--------------+-------------------------------------------------+
698 | | ``pattern`` | byte string to look for |
699 +----------+--------------+-------------------------------------------------+
700 | ``last`` | if specified, either all 0 or with the same values as ``spec`` |
701 +----------+----------------------------------------------------------------+
702 | ``mask`` | bit-mask applied to ``spec`` values with usual behavior |
703 +----------+----------------------------------------------------------------+
705 Example pattern looking for several strings at various offsets of a UDP
706 payload, using combined RAW items:
708 .. _table_rte_flow_item_raw_example:
710 .. table:: UDP payload matching
712 +-------+------+----------+--------------+-------+
713 | Index | Item | Field | Subfield | Value |
714 +=======+======+==========+==============+=======+
716 +-------+----------------------------------------+
718 +-------+----------------------------------------+
720 +-------+------+----------+--------------+-------+
721 | 3 | RAW | ``spec`` | ``relative`` | 1 |
722 | | | +--------------+-------+
723 | | | | ``search`` | 1 |
724 | | | +--------------+-------+
725 | | | | ``offset`` | 10 |
726 | | | +--------------+-------+
727 | | | | ``limit`` | 0 |
728 | | | +--------------+-------+
729 | | | | ``length`` | 3 |
730 | | | +--------------+-------+
731 | | | | ``pattern`` | "foo" |
732 +-------+------+----------+--------------+-------+
733 | 4 | RAW | ``spec`` | ``relative`` | 1 |
734 | | | +--------------+-------+
735 | | | | ``search`` | 0 |
736 | | | +--------------+-------+
737 | | | | ``offset`` | 20 |
738 | | | +--------------+-------+
739 | | | | ``limit`` | 0 |
740 | | | +--------------+-------+
741 | | | | ``length`` | 3 |
742 | | | +--------------+-------+
743 | | | | ``pattern`` | "bar" |
744 +-------+------+----------+--------------+-------+
745 | 5 | RAW | ``spec`` | ``relative`` | 1 |
746 | | | +--------------+-------+
747 | | | | ``search`` | 0 |
748 | | | +--------------+-------+
749 | | | | ``offset`` | -29 |
750 | | | +--------------+-------+
751 | | | | ``limit`` | 0 |
752 | | | +--------------+-------+
753 | | | | ``length`` | 3 |
754 | | | +--------------+-------+
755 | | | | ``pattern`` | "baz" |
756 +-------+------+----------+--------------+-------+
758 +-------+----------------------------------------+
762 - Locate "foo" at least 10 bytes deep inside UDP payload.
763 - Locate "bar" after "foo" plus 20 bytes.
764 - Locate "baz" after "bar" minus 29 bytes.
766 Such a packet may be represented as follows (not to scale)::
769 | |<--------->| |<--------->|
771 |-----|------|-----|-----|-----|-----|-----------|-----|------|
772 | ETH | IPv4 | UDP | ... | baz | foo | ......... | bar | .... |
773 |-----|------|-----|-----|-----|-----|-----------|-----|------|
775 |<--------------------------->|
778 Note that matching subsequent pattern items would resume after "baz", not
779 "bar" since matching is always performed after the previous item of the
785 Matches an Ethernet header.
787 - ``dst``: destination MAC.
788 - ``src``: source MAC.
789 - ``type``: EtherType.
790 - Default ``mask`` matches destination and source addresses only.
795 Matches an 802.1Q/ad VLAN tag.
797 - ``tpid``: tag protocol identifier.
798 - ``tci``: tag control information.
799 - Default ``mask`` matches TCI only.
804 Matches an IPv4 header.
806 Note: IPv4 options are handled by dedicated pattern items.
808 - ``hdr``: IPv4 header definition (``rte_ip.h``).
809 - Default ``mask`` matches source and destination addresses only.
814 Matches an IPv6 header.
816 Note: IPv6 options are handled by dedicated pattern items.
818 - ``hdr``: IPv6 header definition (``rte_ip.h``).
819 - Default ``mask`` matches source and destination addresses only.
824 Matches an ICMP header.
826 - ``hdr``: ICMP header definition (``rte_icmp.h``).
827 - Default ``mask`` matches ICMP type and code only.
832 Matches a UDP header.
834 - ``hdr``: UDP header definition (``rte_udp.h``).
835 - Default ``mask`` matches source and destination ports only.
840 Matches a TCP header.
842 - ``hdr``: TCP header definition (``rte_tcp.h``).
843 - Default ``mask`` matches source and destination ports only.
848 Matches a SCTP header.
850 - ``hdr``: SCTP header definition (``rte_sctp.h``).
851 - Default ``mask`` matches source and destination ports only.
856 Matches a VXLAN header (RFC 7348).
858 - ``flags``: normally 0x08 (I flag).
859 - ``rsvd0``: reserved, normally 0x000000.
860 - ``vni``: VXLAN network identifier.
861 - ``rsvd1``: reserved, normally 0x00.
862 - Default ``mask`` matches VNI only.
867 Matches an IEEE 802.1BR E-Tag header.
869 - ``tpid``: tag protocol identifier (0x893F)
870 - ``epcp_edei_in_ecid_b``: E-Tag control information (E-TCI), E-PCP (3b),
871 E-DEI (1b), ingress E-CID base (12b).
872 - ``rsvd_grp_ecid_b``: reserved (2b), GRP (2b), E-CID base (12b).
873 - ``in_ecid_e``: ingress E-CID ext.
874 - ``ecid_e``: E-CID ext.
875 - Default ``mask`` simultaneously matches GRP and E-CID base.
880 Matches a NVGRE header (RFC 7637).
882 - ``c_k_s_rsvd0_ver``: checksum (1b), undefined (1b), key bit (1b),
883 sequence number (1b), reserved 0 (9b), version (3b). This field must have
884 value 0x2000 according to RFC 7637.
885 - ``protocol``: protocol type (0x6558).
886 - ``tni``: virtual subnet ID.
887 - ``flow_id``: flow ID.
888 - Default ``mask`` matches TNI only.
893 Matches a MPLS header.
895 - ``label_tc_s_ttl``: label, TC, Bottom of Stack and TTL.
896 - Default ``mask`` matches label only.
901 Matches a GRE header.
903 - ``c_rsvd0_ver``: checksum, reserved 0 and version.
904 - ``protocol``: protocol type.
905 - Default ``mask`` matches protocol only.
910 Fuzzy pattern match, expect faster than default.
912 This is for device that support fuzzy match option. Usually a fuzzy match is
913 fast but the cost is accuracy. i.e. Signature Match only match pattern's hash
914 value, but it is possible two different patterns have the same hash value.
916 Matching accuracy level can be configured by threshold. Driver can divide the
917 range of threshold and map to different accuracy levels that device support.
919 Threshold 0 means perfect match (no fuzziness), while threshold 0xffffffff
920 means fuzziest match.
922 .. _table_rte_flow_item_fuzzy:
926 +----------+---------------+--------------------------------------------------+
927 | Field | Subfield | Value |
928 +==========+===============+==================================================+
929 | ``spec`` | ``threshold`` | 0 as perfect match, 0xffffffff as fuzziest match |
930 +----------+---------------+--------------------------------------------------+
931 | ``last`` | ``threshold`` | upper range value |
932 +----------+---------------+--------------------------------------------------+
933 | ``mask`` | ``threshold`` | bit-mask apply to "spec" and "last" |
934 +----------+---------------+--------------------------------------------------+
936 Usage example, fuzzy match a TCPv4 packets:
938 .. _table_rte_flow_item_fuzzy_example:
940 .. table:: Fuzzy matching
956 Item: ``GTP``, ``GTPC``, ``GTPU``
957 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
959 Matches a GTPv1 header.
961 Note: GTP, GTPC and GTPU use the same structure. GTPC and GTPU item
962 are defined for a user-friendly API when creating GTP-C and GTP-U
965 - ``v_pt_rsv_flags``: version (3b), protocol type (1b), reserved (1b),
966 extension header flag (1b), sequence number flag (1b), N-PDU number
968 - ``msg_type``: message type.
969 - ``msg_len``: message length.
970 - ``teid``: tunnel endpoint identifier.
971 - Default ``mask`` matches teid only.
976 Matches an ESP header.
978 - ``hdr``: ESP header definition (``rte_esp.h``).
979 - Default ``mask`` matches SPI only.
984 Matches a GENEVE header.
986 - ``ver_opt_len_o_c_rsvd0``: version (2b), length of the options fields (6b),
987 OAM packet (1b), critical options present (1b), reserved 0 (6b).
988 - ``protocol``: protocol type.
989 - ``vni``: virtual network identifier.
990 - ``rsvd1``: reserved, normally 0x00.
991 - Default ``mask`` matches VNI only.
996 Each possible action is represented by a type. Some have associated
997 configuration structures. Several actions combined in a list can be assigned
998 to a flow rule and are performed in order.
1000 They fall in three categories:
1002 - Actions that modify the fate of matching traffic, for instance by dropping
1003 or assigning it a specific destination.
1005 - Actions that modify matching traffic contents or its properties. This
1006 includes adding/removing encapsulation, encryption, compression and marks.
1008 - Actions related to the flow rule itself, such as updating counters or
1009 making it non-terminating.
1011 Flow rules being terminating by default, not specifying any action of the
1012 fate kind results in undefined behavior. This applies to both ingress and
1015 PASSTHRU, when supported, makes a flow rule non-terminating.
1017 Like matching patterns, action lists are terminated by END items.
1019 Example of action that redirects packets to queue index 10:
1021 .. _table_rte_flow_action_example:
1023 .. table:: Queue action
1025 +-----------+-------+
1027 +===========+=======+
1029 +-----------+-------+
1031 Actions are performed in list order:
1033 .. _table_rte_flow_count_then_drop:
1035 .. table:: Count then drop
1049 .. _table_rte_flow_mark_count_redirect:
1051 .. table:: Mark, count then redirect
1053 +-------+--------+-----------+-------+
1054 | Index | Action | Field | Value |
1055 +=======+========+===========+=======+
1056 | 0 | MARK | ``mark`` | 0x2a |
1057 +-------+--------+-----------+-------+
1059 +-------+--------+-----------+-------+
1060 | 2 | QUEUE | ``queue`` | 10 |
1061 +-------+--------+-----------+-------+
1063 +-------+----------------------------+
1067 .. _table_rte_flow_redirect_queue_5:
1069 .. table:: Redirect to queue 5
1071 +-------+--------+-----------+-------+
1072 | Index | Action | Field | Value |
1073 +=======+========+===========+=======+
1075 +-------+--------+-----------+-------+
1076 | 1 | QUEUE | ``queue`` | 5 |
1077 +-------+--------+-----------+-------+
1079 +-------+----------------------------+
1081 In the above example, while DROP and QUEUE must be performed in order, both
1082 have to happen before reaching END. Only QUEUE has a visible effect.
1084 Note that such a list may be thought as ambiguous and rejected on that
1087 .. _table_rte_flow_redirect_queue_5_3:
1089 .. table:: Redirect to queues 5 and 3
1091 +-------+--------+-----------+-------+
1092 | Index | Action | Field | Value |
1093 +=======+========+===========+=======+
1094 | 0 | QUEUE | ``queue`` | 5 |
1095 +-------+--------+-----------+-------+
1097 +-------+--------+-----------+-------+
1098 | 2 | QUEUE | ``queue`` | 3 |
1099 +-------+--------+-----------+-------+
1101 +-------+----------------------------+
1103 As previously described, all actions must be taken into account. This
1104 effectively duplicates traffic to both queues. The above example also shows
1105 that VOID is ignored.
1110 Common action types are described in this section. Like pattern item types,
1111 this list is not exhaustive as new actions will be added in the future.
1116 End marker for action lists. Prevents further processing of actions, thereby
1119 - Its numeric value is 0 for convenience.
1120 - PMD support is mandatory.
1121 - No configurable properties.
1123 .. _table_rte_flow_action_end:
1136 Used as a placeholder for convenience. It is ignored and simply discarded by
1139 - PMD support is mandatory.
1140 - No configurable properties.
1142 .. _table_rte_flow_action_void:
1152 Action: ``PASSTHRU``
1153 ^^^^^^^^^^^^^^^^^^^^
1155 Leaves traffic up for additional processing by subsequent flow rules; makes
1156 a flow rule non-terminating.
1158 - No configurable properties.
1160 .. _table_rte_flow_action_passthru:
1170 Example to copy a packet to a queue and continue processing by subsequent
1173 .. _table_rte_flow_action_passthru_example:
1175 .. table:: Copy to queue 8
1177 +-------+--------+-----------+-------+
1178 | Index | Action | Field | Value |
1179 +=======+========+===========+=======+
1181 +-------+--------+-----------+-------+
1182 | 1 | QUEUE | ``queue`` | 8 |
1183 +-------+--------+-----------+-------+
1185 +-------+----------------------------+
1190 Attaches an integer value to packets and sets ``PKT_RX_FDIR`` and
1191 ``PKT_RX_FDIR_ID`` mbuf flags.
1193 This value is arbitrary and application-defined. Maximum allowed value
1194 depends on the underlying implementation. It is returned in the
1195 ``hash.fdir.hi`` mbuf field.
1197 .. _table_rte_flow_action_mark:
1201 +--------+--------------------------------------+
1203 +========+======================================+
1204 | ``id`` | integer value to return with packets |
1205 +--------+--------------------------------------+
1210 Flags packets. Similar to `Action: MARK`_ without a specific value; only
1211 sets the ``PKT_RX_FDIR`` mbuf flag.
1213 - No configurable properties.
1215 .. _table_rte_flow_action_flag:
1228 Assigns packets to a given queue index.
1230 .. _table_rte_flow_action_queue:
1234 +-----------+--------------------+
1236 +===========+====================+
1237 | ``index`` | queue index to use |
1238 +-----------+--------------------+
1245 - No configurable properties.
1247 .. _table_rte_flow_action_drop:
1260 Enables counters for this rule.
1262 These counters can be retrieved and reset through ``rte_flow_query()``, see
1263 ``struct rte_flow_query_count``.
1265 - Counters can be retrieved with ``rte_flow_query()``.
1266 - No configurable properties.
1268 .. _table_rte_flow_action_count:
1278 Query structure to retrieve and reset flow rule counters:
1280 .. _table_rte_flow_query_count:
1282 .. table:: COUNT query
1284 +---------------+-----+-----------------------------------+
1285 | Field | I/O | Value |
1286 +===============+=====+===================================+
1287 | ``reset`` | in | reset counter after query |
1288 +---------------+-----+-----------------------------------+
1289 | ``hits_set`` | out | ``hits`` field is set |
1290 +---------------+-----+-----------------------------------+
1291 | ``bytes_set`` | out | ``bytes`` field is set |
1292 +---------------+-----+-----------------------------------+
1293 | ``hits`` | out | number of hits for this rule |
1294 +---------------+-----+-----------------------------------+
1295 | ``bytes`` | out | number of bytes through this rule |
1296 +---------------+-----+-----------------------------------+
1301 Similar to QUEUE, except RSS is additionally performed on packets to spread
1302 them among several queues according to the provided parameters.
1304 Unlike global RSS settings used by other DPDK APIs, unsetting the ``types``
1305 field does not disable RSS in a flow rule. Doing so instead requests safe
1306 unspecified "best-effort" settings from the underlying PMD, which depending
1307 on the flow rule, may result in anything ranging from empty (single queue)
1308 to all-inclusive RSS.
1310 Note: RSS hash result is stored in the ``hash.rss`` mbuf field which
1311 overlaps ``hash.fdir.lo``. Since `Action: MARK`_ sets the ``hash.fdir.hi``
1312 field only, both can be requested simultaneously.
1314 .. _table_rte_flow_action_rss:
1318 +---------------+---------------------------------------------+
1320 +===============+=============================================+
1321 | ``func`` | RSS hash function to apply |
1322 +---------------+---------------------------------------------+
1323 | ``types`` | specific RSS hash types (see ``ETH_RSS_*``) |
1324 +---------------+---------------------------------------------+
1325 | ``key_len`` | hash key length in bytes |
1326 +---------------+---------------------------------------------+
1327 | ``queue_num`` | number of entries in ``queue`` |
1328 +---------------+---------------------------------------------+
1329 | ``key`` | hash key |
1330 +---------------+---------------------------------------------+
1331 | ``queue`` | queue indices to use |
1332 +---------------+---------------------------------------------+
1337 Redirects packets to the physical function (PF) of the current device.
1339 - No configurable properties.
1341 .. _table_rte_flow_action_pf:
1354 Redirects packets to a virtual function (VF) of the current device.
1356 Packets matched by a VF pattern item can be redirected to their original VF
1357 ID instead of the specified one. This parameter may not be available and is
1358 not guaranteed to work properly if the VF part is matched by a prior flow
1359 rule or if packets are not addressed to a VF in the first place.
1361 .. _table_rte_flow_action_vf:
1365 +--------------+--------------------------------+
1367 +==============+================================+
1368 | ``original`` | use original VF ID if possible |
1369 +--------------+--------------------------------+
1370 | ``vf`` | VF ID to redirect packets to |
1371 +--------------+--------------------------------+
1376 Applies a stage of metering and policing.
1378 The metering and policing (MTR) object has to be first created using the
1379 rte_mtr_create() API function. The ID of the MTR object is specified as
1380 action parameter. More than one flow can use the same MTR object through
1381 the meter action. The MTR object can be further updated or queried using
1384 .. _table_rte_flow_action_meter:
1388 +--------------+---------------+
1390 +==============+===============+
1391 | ``mtr_id`` | MTR object ID |
1392 +--------------+---------------+
1394 Action: ``SECURITY``
1395 ^^^^^^^^^^^^^^^^^^^^
1397 Perform the security action on flows matched by the pattern items
1398 according to the configuration of the security session.
1400 This action modifies the payload of matched flows. For INLINE_CRYPTO, the
1401 security protocol headers and IV are fully provided by the application as
1402 specified in the flow pattern. The payload of matching packets is
1403 encrypted on egress, and decrypted and authenticated on ingress.
1404 For INLINE_PROTOCOL, the security protocol is fully offloaded to HW,
1405 providing full encapsulation and decapsulation of packets in security
1406 protocols. The flow pattern specifies both the outer security header fields
1407 and the inner packet fields. The security session specified in the action
1408 must match the pattern parameters.
1410 The security session specified in the action must be created on the same
1411 port as the flow action that is being specified.
1413 The ingress/egress flow attribute should match that specified in the
1414 security session if the security session supports the definition of the
1417 Multiple flows can be configured to use the same security session.
1419 .. _table_rte_flow_action_security:
1423 +----------------------+--------------------------------------+
1425 +======================+======================================+
1426 | ``security_session`` | security session to apply |
1427 +----------------------+--------------------------------------+
1429 The following is an example of configuring IPsec inline using the
1430 INLINE_CRYPTO security session:
1432 The encryption algorithm, keys and salt are part of the opaque
1433 ``rte_security_session``. The SA is identified according to the IP and ESP
1434 fields in the pattern items.
1436 .. _table_rte_flow_item_esp_inline_example:
1438 .. table:: IPsec inline crypto flow pattern items.
1440 +-------+----------+
1442 +=======+==========+
1444 +-------+----------+
1446 +-------+----------+
1448 +-------+----------+
1450 +-------+----------+
1452 .. _table_rte_flow_action_esp_inline_example:
1454 .. table:: IPsec inline flow actions.
1456 +-------+----------+
1458 +=======+==========+
1460 +-------+----------+
1462 +-------+----------+
1467 All specified pattern items (``enum rte_flow_item_type``) and actions
1468 (``enum rte_flow_action_type``) use positive identifiers.
1470 The negative space is reserved for dynamic types generated by PMDs during
1471 run-time. PMDs may encounter them as a result but must not accept negative
1472 identifiers they are not aware of.
1474 A method to generate them remains to be defined.
1479 Pattern item types will be added as new protocols are implemented.
1481 Variable headers support through dedicated pattern items, for example in
1482 order to match specific IPv4 options and IPv6 extension headers would be
1483 stacked after IPv4/IPv6 items.
1485 Other action types are planned but are not defined yet. These include the
1486 ability to alter packet data in several ways, such as performing
1487 encapsulation/decapsulation of tunnel headers.
1492 A rather simple API with few functions is provided to fully manage flow
1495 Each created flow rule is associated with an opaque, PMD-specific handle
1496 pointer. The application is responsible for keeping it until the rule is
1499 Flows rules are represented by ``struct rte_flow`` objects.
1504 Given that expressing a definite set of device capabilities is not
1505 practical, a dedicated function is provided to check if a flow rule is
1506 supported and can be created.
1511 rte_flow_validate(uint16_t port_id,
1512 const struct rte_flow_attr *attr,
1513 const struct rte_flow_item pattern[],
1514 const struct rte_flow_action actions[],
1515 struct rte_flow_error *error);
1517 The flow rule is validated for correctness and whether it could be accepted
1518 by the device given sufficient resources. The rule is checked against the
1519 current device mode and queue configuration. The flow rule may also
1520 optionally be validated against existing flow rules and device resources.
1521 This function has no effect on the target device.
1523 The returned value is guaranteed to remain valid only as long as no
1524 successful calls to ``rte_flow_create()`` or ``rte_flow_destroy()`` are made
1525 in the meantime and no device parameter affecting flow rules in any way are
1526 modified, due to possible collisions or resource limitations (although in
1527 such cases ``EINVAL`` should not be returned).
1531 - ``port_id``: port identifier of Ethernet device.
1532 - ``attr``: flow rule attributes.
1533 - ``pattern``: pattern specification (list terminated by the END pattern
1535 - ``actions``: associated actions (list terminated by the END action).
1536 - ``error``: perform verbose error reporting if not NULL. PMDs initialize
1537 this structure in case of error only.
1541 - 0 if flow rule is valid and can be created. A negative errno value
1542 otherwise (``rte_errno`` is also set), the following errors are defined.
1543 - ``-ENOSYS``: underlying device does not support this functionality.
1544 - ``-EINVAL``: unknown or invalid rule specification.
1545 - ``-ENOTSUP``: valid but unsupported rule specification (e.g. partial
1546 bit-masks are unsupported).
1547 - ``EEXIST``: collision with an existing rule. Only returned if device
1548 supports flow rule collision checking and there was a flow rule
1549 collision. Not receiving this return code is no guarantee that creating
1550 the rule will not fail due to a collision.
1551 - ``ENOMEM``: not enough memory to execute the function, or if the device
1552 supports resource validation, resource limitation on the device.
1553 - ``-EBUSY``: action cannot be performed due to busy device resources, may
1554 succeed if the affected queues or even the entire port are in a stopped
1555 state (see ``rte_eth_dev_rx_queue_stop()`` and ``rte_eth_dev_stop()``).
1560 Creating a flow rule is similar to validating one, except the rule is
1561 actually created and a handle returned.
1566 rte_flow_create(uint16_t port_id,
1567 const struct rte_flow_attr *attr,
1568 const struct rte_flow_item pattern[],
1569 const struct rte_flow_action *actions[],
1570 struct rte_flow_error *error);
1574 - ``port_id``: port identifier of Ethernet device.
1575 - ``attr``: flow rule attributes.
1576 - ``pattern``: pattern specification (list terminated by the END pattern
1578 - ``actions``: associated actions (list terminated by the END action).
1579 - ``error``: perform verbose error reporting if not NULL. PMDs initialize
1580 this structure in case of error only.
1584 A valid handle in case of success, NULL otherwise and ``rte_errno`` is set
1585 to the positive version of one of the error codes defined for
1586 ``rte_flow_validate()``.
1591 Flow rules destruction is not automatic, and a queue or a port should not be
1592 released if any are still attached to them. Applications must take care of
1593 performing this step before releasing resources.
1598 rte_flow_destroy(uint16_t port_id,
1599 struct rte_flow *flow,
1600 struct rte_flow_error *error);
1603 Failure to destroy a flow rule handle may occur when other flow rules depend
1604 on it, and destroying it would result in an inconsistent state.
1606 This function is only guaranteed to succeed if handles are destroyed in
1607 reverse order of their creation.
1611 - ``port_id``: port identifier of Ethernet device.
1612 - ``flow``: flow rule handle to destroy.
1613 - ``error``: perform verbose error reporting if not NULL. PMDs initialize
1614 this structure in case of error only.
1618 - 0 on success, a negative errno value otherwise and ``rte_errno`` is set.
1623 Convenience function to destroy all flow rule handles associated with a
1624 port. They are released as with successive calls to ``rte_flow_destroy()``.
1629 rte_flow_flush(uint16_t port_id,
1630 struct rte_flow_error *error);
1632 In the unlikely event of failure, handles are still considered destroyed and
1633 no longer valid but the port must be assumed to be in an inconsistent state.
1637 - ``port_id``: port identifier of Ethernet device.
1638 - ``error``: perform verbose error reporting if not NULL. PMDs initialize
1639 this structure in case of error only.
1643 - 0 on success, a negative errno value otherwise and ``rte_errno`` is set.
1648 Query an existing flow rule.
1650 This function allows retrieving flow-specific data such as counters. Data
1651 is gathered by special actions which must be present in the flow rule
1657 rte_flow_query(uint16_t port_id,
1658 struct rte_flow *flow,
1659 enum rte_flow_action_type action,
1661 struct rte_flow_error *error);
1665 - ``port_id``: port identifier of Ethernet device.
1666 - ``flow``: flow rule handle to query.
1667 - ``action``: action type to query.
1668 - ``data``: pointer to storage for the associated query data type.
1669 - ``error``: perform verbose error reporting if not NULL. PMDs initialize
1670 this structure in case of error only.
1674 - 0 on success, a negative errno value otherwise and ``rte_errno`` is set.
1679 The general expectation for ingress traffic is that flow rules process it
1680 first; the remaining unmatched or pass-through traffic usually ends up in a
1681 queue (with or without RSS, locally or in some sub-device instance)
1682 depending on the global configuration settings of a port.
1684 While fine from a compatibility standpoint, this approach makes drivers more
1685 complex as they have to check for possible side effects outside of this API
1686 when creating or destroying flow rules. It results in a more limited set of
1687 available rule types due to the way device resources are assigned (e.g. no
1688 support for the RSS action even on capable hardware).
1690 Given that nonspecific traffic can be handled by flow rules as well,
1691 isolated mode is a means for applications to tell a driver that ingress on
1692 the underlying port must be injected from the defined flow rules only; that
1693 no default traffic is expected outside those rules.
1695 This has the following benefits:
1697 - Applications get finer-grained control over the kind of traffic they want
1698 to receive (no traffic by default).
1700 - More importantly they control at what point nonspecific traffic is handled
1701 relative to other flow rules, by adjusting priority levels.
1703 - Drivers can assign more hardware resources to flow rules and expand the
1704 set of supported rule types.
1706 Because toggling isolated mode may cause profound changes to the ingress
1707 processing path of a driver, it may not be possible to leave it once
1708 entered. Likewise, existing flow rules or global configuration settings may
1709 prevent a driver from entering isolated mode.
1711 Applications relying on this mode are therefore encouraged to toggle it as
1712 soon as possible after device initialization, ideally before the first call
1713 to ``rte_eth_dev_configure()`` to avoid possible failures due to conflicting
1716 Once effective, the following functionality has no effect on the underlying
1717 port and may return errors such as ``ENOTSUP`` ("not supported"):
1719 - Toggling promiscuous mode.
1720 - Toggling allmulticast mode.
1721 - Configuring MAC addresses.
1722 - Configuring multicast addresses.
1723 - Configuring VLAN filters.
1724 - Configuring Rx filters through the legacy API (e.g. FDIR).
1725 - Configuring global RSS settings.
1730 rte_flow_isolate(uint16_t port_id, int set, struct rte_flow_error *error);
1734 - ``port_id``: port identifier of Ethernet device.
1735 - ``set``: nonzero to enter isolated mode, attempt to leave it otherwise.
1736 - ``error``: perform verbose error reporting if not NULL. PMDs initialize
1737 this structure in case of error only.
1741 - 0 on success, a negative errno value otherwise and ``rte_errno`` is set.
1743 Verbose error reporting
1744 -----------------------
1746 The defined *errno* values may not be accurate enough for users or
1747 application developers who want to investigate issues related to flow rules
1748 management. A dedicated error object is defined for this purpose:
1752 enum rte_flow_error_type {
1753 RTE_FLOW_ERROR_TYPE_NONE, /**< No error. */
1754 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, /**< Cause unspecified. */
1755 RTE_FLOW_ERROR_TYPE_HANDLE, /**< Flow rule (handle). */
1756 RTE_FLOW_ERROR_TYPE_ATTR_GROUP, /**< Group field. */
1757 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY, /**< Priority field. */
1758 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS, /**< Ingress field. */
1759 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, /**< Egress field. */
1760 RTE_FLOW_ERROR_TYPE_ATTR, /**< Attributes structure. */
1761 RTE_FLOW_ERROR_TYPE_ITEM_NUM, /**< Pattern length. */
1762 RTE_FLOW_ERROR_TYPE_ITEM, /**< Specific pattern item. */
1763 RTE_FLOW_ERROR_TYPE_ACTION_NUM, /**< Number of actions. */
1764 RTE_FLOW_ERROR_TYPE_ACTION, /**< Specific action. */
1767 struct rte_flow_error {
1768 enum rte_flow_error_type type; /**< Cause field and error types. */
1769 const void *cause; /**< Object responsible for the error. */
1770 const char *message; /**< Human-readable error message. */
1773 Error type ``RTE_FLOW_ERROR_TYPE_NONE`` stands for no error, in which case
1774 remaining fields can be ignored. Other error types describe the type of the
1775 object pointed by ``cause``.
1777 If non-NULL, ``cause`` points to the object responsible for the error. For a
1778 flow rule, this may be a pattern item or an individual action.
1780 If non-NULL, ``message`` provides a human-readable error message.
1782 This object is normally allocated by applications and set by PMDs in case of
1783 error, the message points to a constant string which does not need to be
1784 freed by the application, however its pointer can be considered valid only
1785 as long as its associated DPDK port remains configured. Closing the
1786 underlying device or unloading the PMD invalidates it.
1797 rte_flow_error_set(struct rte_flow_error *error,
1799 enum rte_flow_error_type type,
1801 const char *message);
1803 This function initializes ``error`` (if non-NULL) with the provided
1804 parameters and sets ``rte_errno`` to ``code``. A negative error ``code`` is
1810 - DPDK does not keep track of flow rules definitions or flow rule objects
1811 automatically. Applications may keep track of the former and must keep
1812 track of the latter. PMDs may also do it for internal needs, however this
1813 must not be relied on by applications.
1815 - Flow rules are not maintained between successive port initializations. An
1816 application exiting without releasing them and restarting must re-create
1819 - API operations are synchronous and blocking (``EAGAIN`` cannot be
1822 - There is no provision for reentrancy/multi-thread safety, although nothing
1823 should prevent different devices from being configured at the same
1824 time. PMDs may protect their control path functions accordingly.
1826 - Stopping the data path (TX/RX) should not be necessary when managing flow
1827 rules. If this cannot be achieved naturally or with workarounds (such as
1828 temporarily replacing the burst function pointers), an appropriate error
1829 code must be returned (``EBUSY``).
1831 - PMDs, not applications, are responsible for maintaining flow rules
1832 configuration when stopping and restarting a port or performing other
1833 actions which may affect them. They can only be destroyed explicitly by
1836 For devices exposing multiple ports sharing global settings affected by flow
1839 - All ports under DPDK control must behave consistently, PMDs are
1840 responsible for making sure that existing flow rules on a port are not
1841 affected by other ports.
1843 - Ports not under DPDK control (unaffected or handled by other applications)
1844 are user's responsibility. They may affect existing flow rules and cause
1845 undefined behavior. PMDs aware of this may prevent flow rules creation
1846 altogether in such cases.
1851 The PMD interface is defined in ``rte_flow_driver.h``. It is not subject to
1852 API/ABI versioning constraints as it is not exposed to applications and may
1853 evolve independently.
1855 It is currently implemented on top of the legacy filtering framework through
1856 filter type *RTE_ETH_FILTER_GENERIC* that accepts the single operation
1857 *RTE_ETH_FILTER_GET* to return PMD-specific *rte_flow* callbacks wrapped
1858 inside ``struct rte_flow_ops``.
1860 This overhead is temporarily necessary in order to keep compatibility with
1861 the legacy filtering framework, which should eventually disappear.
1863 - PMD callbacks implement exactly the interface described in `Rules
1864 management`_, except for the port ID argument which has already been
1865 converted to a pointer to the underlying ``struct rte_eth_dev``.
1867 - Public API functions do not process flow rules definitions at all before
1868 calling PMD functions (no basic error checking, no validation
1869 whatsoever). They only make sure these callbacks are non-NULL or return
1870 the ``ENOSYS`` (function not supported) error.
1872 This interface additionally defines the following helper function:
1874 - ``rte_flow_ops_get()``: get generic flow operations structure from a
1877 More will be added over time.
1879 Device compatibility
1880 --------------------
1882 No known implementation supports all the described features.
1884 Unsupported features or combinations are not expected to be fully emulated
1885 in software by PMDs for performance reasons. Partially supported features
1886 may be completed in software as long as hardware performs most of the work
1887 (such as queue redirection and packet recognition).
1889 However PMDs are expected to do their best to satisfy application requests
1890 by working around hardware limitations as long as doing so does not affect
1891 the behavior of existing flow rules.
1893 The following sections provide a few examples of such cases and describe how
1894 PMDs should handle them, they are based on limitations built into the
1900 Each flow rule comes with its own, per-layer bit-masks, while hardware may
1901 support only a single, device-wide bit-mask for a given layer type, so that
1902 two IPv4 rules cannot use different bit-masks.
1904 The expected behavior in this case is that PMDs automatically configure
1905 global bit-masks according to the needs of the first flow rule created.
1907 Subsequent rules are allowed only if their bit-masks match those, the
1908 ``EEXIST`` error code should be returned otherwise.
1910 Unsupported layer types
1911 ~~~~~~~~~~~~~~~~~~~~~~~
1913 Many protocols can be simulated by crafting patterns with the `Item: RAW`_
1916 PMDs can rely on this capability to simulate support for protocols with
1917 headers not directly recognized by hardware.
1919 ``ANY`` pattern item
1920 ~~~~~~~~~~~~~~~~~~~~
1922 This pattern item stands for anything, which can be difficult to translate
1923 to something hardware would understand, particularly if followed by more
1926 Consider the following pattern:
1928 .. _table_rte_flow_unsupported_any:
1930 .. table:: Pattern with ANY as L3
1932 +-------+-----------------------+
1934 +=======+=======================+
1936 +-------+-----+---------+-------+
1937 | 1 | ANY | ``num`` | ``1`` |
1938 +-------+-----+---------+-------+
1940 +-------+-----------------------+
1942 +-------+-----------------------+
1944 Knowing that TCP does not make sense with something other than IPv4 and IPv6
1945 as L3, such a pattern may be translated to two flow rules instead:
1947 .. _table_rte_flow_unsupported_any_ipv4:
1949 .. table:: ANY replaced with IPV4
1951 +-------+--------------------+
1953 +=======+====================+
1955 +-------+--------------------+
1956 | 1 | IPV4 (zeroed mask) |
1957 +-------+--------------------+
1959 +-------+--------------------+
1961 +-------+--------------------+
1965 .. _table_rte_flow_unsupported_any_ipv6:
1967 .. table:: ANY replaced with IPV6
1969 +-------+--------------------+
1971 +=======+====================+
1973 +-------+--------------------+
1974 | 1 | IPV6 (zeroed mask) |
1975 +-------+--------------------+
1977 +-------+--------------------+
1979 +-------+--------------------+
1981 Note that as soon as a ANY rule covers several layers, this approach may
1982 yield a large number of hidden flow rules. It is thus suggested to only
1983 support the most common scenarios (anything as L2 and/or L3).
1988 - When combined with `Action: QUEUE`_, packet counting (`Action: COUNT`_)
1989 and tagging (`Action: MARK`_ or `Action: FLAG`_) may be implemented in
1990 software as long as the target queue is used by a single rule.
1992 - When a single target queue is provided, `Action: RSS`_ can also be
1993 implemented through `Action: QUEUE`_.
1998 While it would naturally make sense, flow rules cannot be assumed to be
1999 processed by hardware in the same order as their creation for several
2002 - They may be managed internally as a tree or a hash table instead of a
2004 - Removing a flow rule before adding another one can either put the new rule
2005 at the end of the list or reuse a freed entry.
2006 - Duplication may occur when packets are matched by several rules.
2008 For overlapping rules (particularly in order to use `Action: PASSTHRU`_)
2009 predictable behavior is only guaranteed by using different priority levels.
2011 Priority levels are not necessarily implemented in hardware, or may be
2012 severely limited (e.g. a single priority bit).
2014 For these reasons, priority levels may be implemented purely in software by
2017 - For devices expecting flow rules to be added in the correct order, PMDs
2018 may destroy and re-create existing rules after adding a new one with
2021 - A configurable number of dummy or empty rules can be created at
2022 initialization time to save high priority slots for later.
2024 - In order to save priority levels, PMDs may evaluate whether rules are
2025 likely to collide and adjust their priority accordingly.
2030 - A device profile selection function which could be used to force a
2031 permanent profile instead of relying on its automatic configuration based
2032 on existing flow rules.
2034 - A method to optimize *rte_flow* rules with specific pattern items and
2035 action types generated on the fly by PMDs. DPDK should assign negative
2036 numbers to these in order to not collide with the existing types. See
2039 - Adding specific egress pattern items and actions as described in
2040 `Attribute: Traffic direction`_.
2042 - Optional software fallback when PMDs are unable to handle requested flow
2043 rules so applications do not have to implement their own.