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).
58 Several methods to migrate existing applications are described in `API
67 A flow rule is the combination of attributes with a matching pattern and a
68 list of actions. Flow rules form the basis of this API.
70 Flow rules can have several distinct actions (such as counting,
71 encapsulating, decapsulating before redirecting packets to a particular
72 queue, etc.), instead of relying on several rules to achieve this and having
73 applications deal with hardware implementation details regarding their
76 Support for different priority levels on a rule basis is provided, for
77 example in order to force a more specific rule to come before a more generic
78 one for packets matched by both. However hardware support for more than a
79 single priority level cannot be guaranteed. When supported, the number of
80 available priority levels is usually low, which is why they can also be
81 implemented in software by PMDs (e.g. missing priority levels may be
82 emulated by reordering rules).
84 In order to remain as hardware-agnostic as possible, by default all rules
85 are considered to have the same priority, which means that the order between
86 overlapping rules (when a packet is matched by several filters) is
89 PMDs may refuse to create overlapping rules at a given priority level when
90 they can be detected (e.g. if a pattern matches an existing filter).
92 Thus predictable results for a given priority level can only be achieved
93 with non-overlapping rules, using perfect matching on all protocol layers.
95 Flow rules can also be grouped, the flow rule priority is specific to the
96 group they belong to. All flow rules in a given group are thus processed
97 either before or after another group.
99 Support for multiple actions per rule may be implemented internally on top
100 of non-default hardware priorities, as a result both features may not be
101 simultaneously available to applications.
103 Considering that allowed pattern/actions combinations cannot be known in
104 advance and would result in an impractically large number of capabilities to
105 expose, a method is provided to validate a given rule from the current
106 device configuration state.
108 This enables applications to check if the rule types they need is supported
109 at initialization time, before starting their data path. This method can be
110 used anytime, its only requirement being that the resources needed by a rule
111 should exist (e.g. a target RX queue should be configured first).
113 Each defined rule is associated with an opaque handle managed by the PMD,
114 applications are responsible for keeping it. These can be used for queries
115 and rules management, such as retrieving counters or other data and
118 To avoid resource leaks on the PMD side, handles must be explicitly
119 destroyed by the application before releasing associated resources such as
122 The following sections cover:
124 - **Attributes** (represented by ``struct rte_flow_attr``): properties of a
125 flow rule such as its direction (ingress or egress) and priority.
127 - **Pattern item** (represented by ``struct rte_flow_item``): part of a
128 matching pattern that either matches specific packet data or traffic
129 properties. It can also describe properties of the pattern itself, such as
132 - **Matching pattern**: traffic properties to look for, a combination of any
135 - **Actions** (represented by ``struct rte_flow_action``): operations to
136 perform whenever a packet is matched by a pattern.
144 Flow rules can be grouped by assigning them a common group number. Lower
145 values have higher priority. Group 0 has the highest priority.
147 Although optional, applications are encouraged to group similar rules as
148 much as possible to fully take advantage of hardware capabilities
149 (e.g. optimized matching) and work around limitations (e.g. a single pattern
150 type possibly allowed in a given group).
152 Note that support for more than a single group is not guaranteed.
157 A priority level can be assigned to a flow rule. Like groups, lower values
158 denote higher priority, with 0 as the maximum.
160 A rule with priority 0 in group 8 is always matched after a rule with
161 priority 8 in group 0.
163 Group and priority levels are arbitrary and up to the application, they do
164 not need to be contiguous nor start from 0, however the maximum number
165 varies between devices and may be affected by existing flow rules.
167 If a packet is matched by several rules of a given group for a given
168 priority level, the outcome is undefined. It can take any path, may be
169 duplicated or even cause unrecoverable errors.
171 Note that support for more than a single priority level is not guaranteed.
173 Attribute: Traffic direction
174 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
176 Flow rules can apply to inbound and/or outbound traffic (ingress/egress).
178 Several pattern items and actions are valid and can be used in both
179 directions. At least one direction must be specified.
181 Specifying both directions at once for a given rule is not recommended but
182 may be valid in a few cases (e.g. shared counters).
187 Pattern items fall in two categories:
189 - Matching protocol headers and packet data (ANY, RAW, ETH, VLAN, IPV4,
190 IPV6, ICMP, UDP, TCP, SCTP, VXLAN, MPLS, GRE and so on), usually
191 associated with a specification structure.
193 - Matching meta-data or affecting pattern processing (END, VOID, INVERT, PF,
194 VF, PORT and so on), often without a specification structure.
196 Item specification structures are used to match specific values among
197 protocol fields (or item properties). Documentation describes for each item
198 whether they are associated with one and their type name if so.
200 Up to three structures of the same type can be set for a given item:
202 - ``spec``: values to match (e.g. a given IPv4 address).
204 - ``last``: upper bound for an inclusive range with corresponding fields in
207 - ``mask``: bit-mask applied to both ``spec`` and ``last`` whose purpose is
208 to distinguish the values to take into account and/or partially mask them
209 out (e.g. in order to match an IPv4 address prefix).
211 Usage restrictions and expected behavior:
213 - Setting either ``mask`` or ``last`` without ``spec`` is an error.
215 - Field values in ``last`` which are either 0 or equal to the corresponding
216 values in ``spec`` are ignored; they do not generate a range. Nonzero
217 values lower than those in ``spec`` are not supported.
219 - Setting ``spec`` and optionally ``last`` without ``mask`` causes the PMD
220 to use the default mask defined for that item (defined as
221 ``rte_flow_item_{name}_mask`` constants).
223 - Not setting any of them (assuming item type allows it) is equivalent to
224 providing an empty (zeroed) ``mask`` for broad (nonspecific) matching.
226 - ``mask`` is a simple bit-mask applied before interpreting the contents of
227 ``spec`` and ``last``, which may yield unexpected results if not used
228 carefully. For example, if for an IPv4 address field, ``spec`` provides
229 *10.1.2.3*, ``last`` provides *10.3.4.5* and ``mask`` provides
230 *255.255.0.0*, the effective range becomes *10.1.0.0* to *10.3.255.255*.
232 Example of an item specification matching an Ethernet header:
234 .. _table_rte_flow_pattern_item_example:
236 .. table:: Ethernet item
238 +----------+----------+--------------------+
239 | Field | Subfield | Value |
240 +==========+==========+====================+
241 | ``spec`` | ``src`` | ``00:01:02:03:04`` |
242 | +----------+--------------------+
243 | | ``dst`` | ``00:2a:66:00:01`` |
244 | +----------+--------------------+
245 | | ``type`` | ``0x22aa`` |
246 +----------+----------+--------------------+
247 | ``last`` | unspecified |
248 +----------+----------+--------------------+
249 | ``mask`` | ``src`` | ``00:ff:ff:ff:00`` |
250 | +----------+--------------------+
251 | | ``dst`` | ``00:00:00:00:ff`` |
252 | +----------+--------------------+
253 | | ``type`` | ``0x0000`` |
254 +----------+----------+--------------------+
256 Non-masked bits stand for any value (shown as ``?`` below), Ethernet headers
257 with the following properties are thus matched:
259 - ``src``: ``??:01:02:03:??``
260 - ``dst``: ``??:??:??:??:01``
261 - ``type``: ``0x????``
266 A pattern is formed by stacking items starting from the lowest protocol
267 layer to match. This stacking restriction does not apply to meta items which
268 can be placed anywhere in the stack without affecting the meaning of the
271 Patterns are terminated by END items.
275 .. _table_rte_flow_tcpv4_as_l4:
277 .. table:: TCPv4 as L4
293 .. _table_rte_flow_tcpv6_in_vxlan:
295 .. table:: TCPv6 in VXLAN
297 +-------+------------+
299 +=======+============+
301 +-------+------------+
303 +-------+------------+
305 +-------+------------+
307 +-------+------------+
309 +-------+------------+
311 +-------+------------+
313 +-------+------------+
315 +-------+------------+
319 .. _table_rte_flow_tcpv4_as_l4_meta:
321 .. table:: TCPv4 as L4 with meta items
343 The above example shows how meta items do not affect packet data matching
344 items, as long as those remain stacked properly. The resulting matching
345 pattern is identical to "TCPv4 as L4".
347 .. _table_rte_flow_udpv6_anywhere:
349 .. table:: UDPv6 anywhere
361 If supported by the PMD, omitting one or several protocol layers at the
362 bottom of the stack as in the above example (missing an Ethernet
363 specification) enables looking up anywhere in packets.
365 It is unspecified whether the payload of supported encapsulations
366 (e.g. VXLAN payload) is matched by such a pattern, which may apply to inner,
367 outer or both packets.
369 .. _table_rte_flow_invalid_l3:
371 .. table:: Invalid, missing L3
383 The above pattern is invalid due to a missing L3 specification between L2
384 (Ethernet) and L4 (UDP). Doing so is only allowed at the bottom and at the
390 They match meta-data or affect pattern processing instead of matching packet
391 data directly, most of them do not need a specification structure. This
392 particularity allows them to be specified anywhere in the stack without
393 causing any side effect.
398 End marker for item lists. Prevents further processing of items, thereby
401 - Its numeric value is 0 for convenience.
402 - PMD support is mandatory.
403 - ``spec``, ``last`` and ``mask`` are ignored.
405 .. _table_rte_flow_item_end:
409 +----------+---------+
411 +==========+=========+
412 | ``spec`` | ignored |
413 +----------+---------+
414 | ``last`` | ignored |
415 +----------+---------+
416 | ``mask`` | ignored |
417 +----------+---------+
422 Used as a placeholder for convenience. It is ignored and simply discarded by
425 - PMD support is mandatory.
426 - ``spec``, ``last`` and ``mask`` are ignored.
428 .. _table_rte_flow_item_void:
432 +----------+---------+
434 +==========+=========+
435 | ``spec`` | ignored |
436 +----------+---------+
437 | ``last`` | ignored |
438 +----------+---------+
439 | ``mask`` | ignored |
440 +----------+---------+
442 One usage example for this type is generating rules that share a common
443 prefix quickly without reallocating memory, only by updating item types:
445 .. _table_rte_flow_item_void_example:
447 .. table:: TCP, UDP or ICMP as L4
449 +-------+--------------------+
451 +=======+====================+
453 +-------+--------------------+
455 +-------+------+------+------+
456 | 2 | UDP | VOID | VOID |
457 +-------+------+------+------+
458 | 3 | VOID | TCP | VOID |
459 +-------+------+------+------+
460 | 4 | VOID | VOID | ICMP |
461 +-------+------+------+------+
463 +-------+--------------------+
468 Inverted matching, i.e. process packets that do not match the pattern.
470 - ``spec``, ``last`` and ``mask`` are ignored.
472 .. _table_rte_flow_item_invert:
476 +----------+---------+
478 +==========+=========+
479 | ``spec`` | ignored |
480 +----------+---------+
481 | ``last`` | ignored |
482 +----------+---------+
483 | ``mask`` | ignored |
484 +----------+---------+
486 Usage example, matching non-TCPv4 packets only:
488 .. _table_rte_flow_item_invert_example:
490 .. table:: Anything but TCPv4
509 Matches packets addressed to the physical function of the device.
511 If the underlying device function differs from the one that would normally
512 receive the matched traffic, specifying this item prevents it from reaching
513 that device unless the flow rule contains a `Action: PF`_. Packets are not
514 duplicated between device instances by default.
516 - Likely to return an error or never match any traffic if applied to a VF
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 packets addressed to a virtual function ID of the device.
541 If the underlying device function differs from the one that would normally
542 receive the matched traffic, specifying this item prevents it from reaching
543 that device unless the flow rule contains a `Action: VF`_. Packets are not
544 duplicated between device instances by default.
546 - Likely to return an error or never match any traffic if this causes a VF
547 device to match traffic addressed to a different VF.
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 packets coming from the specified physical port of the underlying
573 The first PORT item overrides the physical port normally associated with the
574 specified DPDK input port (port_id). This item can be provided several times
575 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_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 +----------+-----------+--------------------------------+
601 Data matching item types
602 ~~~~~~~~~~~~~~~~~~~~~~~~
604 Most of these are basically protocol header definitions with associated
605 bit-masks. They must be specified (stacked) from lowest to highest protocol
606 layer to form a matching pattern.
608 The following list is not exhaustive, new protocols will be added in the
614 Matches any protocol in place of the current layer, a single ANY may also
615 stand for several protocol layers.
617 This is usually specified as the first pattern item when looking for a
618 protocol anywhere in a packet.
620 - Default ``mask`` stands for any number of layers.
622 .. _table_rte_flow_item_any:
626 +----------+----------+--------------------------------------+
627 | Field | Subfield | Value |
628 +==========+==========+======================================+
629 | ``spec`` | ``num`` | number of layers covered |
630 +----------+----------+--------------------------------------+
631 | ``last`` | ``num`` | upper range value |
632 +----------+----------+--------------------------------------+
633 | ``mask`` | ``num`` | zeroed to cover any number of layers |
634 +----------+----------+--------------------------------------+
636 Example for VXLAN TCP payload matching regardless of outer L3 (IPv4 or IPv6)
637 and L4 (UDP) both matched by the first ANY specification, and inner L3 (IPv4
638 or IPv6) matched by the second ANY specification:
640 .. _table_rte_flow_item_any_example:
642 .. table:: TCP in VXLAN with wildcards
644 +-------+------+----------+----------+-------+
645 | Index | Item | Field | Subfield | Value |
646 +=======+======+==========+==========+=======+
648 +-------+------+----------+----------+-------+
649 | 1 | ANY | ``spec`` | ``num`` | 2 |
650 +-------+------+----------+----------+-------+
652 +-------+------------------------------------+
654 +-------+------+----------+----------+-------+
655 | 4 | ANY | ``spec`` | ``num`` | 1 |
656 +-------+------+----------+----------+-------+
658 +-------+------------------------------------+
660 +-------+------------------------------------+
665 Matches a byte string of a given length at a given offset.
667 Offset is either absolute (using the start of the packet) or relative to the
668 end of the previous matched item in the stack, in which case negative values
671 If search is enabled, offset is used as the starting point. The search area
672 can be delimited by setting limit to a nonzero value, which is the maximum
673 number of bytes after offset where the pattern may start.
675 Matching a zero-length pattern is allowed, doing so resets the relative
676 offset for subsequent items.
678 - This type does not support ranges (``last`` field).
679 - Default ``mask`` matches all fields exactly.
681 .. _table_rte_flow_item_raw:
685 +----------+--------------+-------------------------------------------------+
686 | Field | Subfield | Value |
687 +==========+==============+=================================================+
688 | ``spec`` | ``relative`` | look for pattern after the previous item |
689 | +--------------+-------------------------------------------------+
690 | | ``search`` | search pattern from offset (see also ``limit``) |
691 | +--------------+-------------------------------------------------+
692 | | ``reserved`` | reserved, must be set to zero |
693 | +--------------+-------------------------------------------------+
694 | | ``offset`` | absolute or relative offset for ``pattern`` |
695 | +--------------+-------------------------------------------------+
696 | | ``limit`` | search area limit for start of ``pattern`` |
697 | +--------------+-------------------------------------------------+
698 | | ``length`` | ``pattern`` length |
699 | +--------------+-------------------------------------------------+
700 | | ``pattern`` | byte string to look for |
701 +----------+--------------+-------------------------------------------------+
702 | ``last`` | if specified, either all 0 or with the same values as ``spec`` |
703 +----------+----------------------------------------------------------------+
704 | ``mask`` | bit-mask applied to ``spec`` values with usual behavior |
705 +----------+----------------------------------------------------------------+
707 Example pattern looking for several strings at various offsets of a UDP
708 payload, using combined RAW items:
710 .. _table_rte_flow_item_raw_example:
712 .. table:: UDP payload matching
714 +-------+------+----------+--------------+-------+
715 | Index | Item | Field | Subfield | Value |
716 +=======+======+==========+==============+=======+
718 +-------+----------------------------------------+
720 +-------+----------------------------------------+
722 +-------+------+----------+--------------+-------+
723 | 3 | RAW | ``spec`` | ``relative`` | 1 |
724 | | | +--------------+-------+
725 | | | | ``search`` | 1 |
726 | | | +--------------+-------+
727 | | | | ``offset`` | 10 |
728 | | | +--------------+-------+
729 | | | | ``limit`` | 0 |
730 | | | +--------------+-------+
731 | | | | ``length`` | 3 |
732 | | | +--------------+-------+
733 | | | | ``pattern`` | "foo" |
734 +-------+------+----------+--------------+-------+
735 | 4 | RAW | ``spec`` | ``relative`` | 1 |
736 | | | +--------------+-------+
737 | | | | ``search`` | 0 |
738 | | | +--------------+-------+
739 | | | | ``offset`` | 20 |
740 | | | +--------------+-------+
741 | | | | ``limit`` | 0 |
742 | | | +--------------+-------+
743 | | | | ``length`` | 3 |
744 | | | +--------------+-------+
745 | | | | ``pattern`` | "bar" |
746 +-------+------+----------+--------------+-------+
747 | 5 | RAW | ``spec`` | ``relative`` | 1 |
748 | | | +--------------+-------+
749 | | | | ``search`` | 0 |
750 | | | +--------------+-------+
751 | | | | ``offset`` | -29 |
752 | | | +--------------+-------+
753 | | | | ``limit`` | 0 |
754 | | | +--------------+-------+
755 | | | | ``length`` | 3 |
756 | | | +--------------+-------+
757 | | | | ``pattern`` | "baz" |
758 +-------+------+----------+--------------+-------+
760 +-------+----------------------------------------+
764 - Locate "foo" at least 10 bytes deep inside UDP payload.
765 - Locate "bar" after "foo" plus 20 bytes.
766 - Locate "baz" after "bar" minus 29 bytes.
768 Such a packet may be represented as follows (not to scale)::
771 | |<--------->| |<--------->|
773 |-----|------|-----|-----|-----|-----|-----------|-----|------|
774 | ETH | IPv4 | UDP | ... | baz | foo | ......... | bar | .... |
775 |-----|------|-----|-----|-----|-----|-----------|-----|------|
777 |<--------------------------->|
780 Note that matching subsequent pattern items would resume after "baz", not
781 "bar" since matching is always performed after the previous item of the
787 Matches an Ethernet header.
789 - ``dst``: destination MAC.
790 - ``src``: source MAC.
791 - ``type``: EtherType.
792 - Default ``mask`` matches destination and source addresses only.
797 Matches an 802.1Q/ad VLAN tag.
799 - ``tpid``: tag protocol identifier.
800 - ``tci``: tag control information.
801 - Default ``mask`` matches TCI only.
806 Matches an IPv4 header.
808 Note: IPv4 options are handled by dedicated pattern items.
810 - ``hdr``: IPv4 header definition (``rte_ip.h``).
811 - Default ``mask`` matches source and destination addresses only.
816 Matches an IPv6 header.
818 Note: IPv6 options are handled by dedicated pattern items.
820 - ``hdr``: IPv6 header definition (``rte_ip.h``).
821 - Default ``mask`` matches source and destination addresses only.
826 Matches an ICMP header.
828 - ``hdr``: ICMP header definition (``rte_icmp.h``).
829 - Default ``mask`` matches ICMP type and code only.
834 Matches a UDP header.
836 - ``hdr``: UDP header definition (``rte_udp.h``).
837 - Default ``mask`` matches source and destination ports only.
842 Matches a TCP header.
844 - ``hdr``: TCP header definition (``rte_tcp.h``).
845 - Default ``mask`` matches source and destination ports only.
850 Matches a SCTP header.
852 - ``hdr``: SCTP header definition (``rte_sctp.h``).
853 - Default ``mask`` matches source and destination ports only.
858 Matches a VXLAN header (RFC 7348).
860 - ``flags``: normally 0x08 (I flag).
861 - ``rsvd0``: reserved, normally 0x000000.
862 - ``vni``: VXLAN network identifier.
863 - ``rsvd1``: reserved, normally 0x00.
864 - Default ``mask`` matches VNI only.
869 Matches an IEEE 802.1BR E-Tag header.
871 - ``tpid``: tag protocol identifier (0x893F)
872 - ``epcp_edei_in_ecid_b``: E-Tag control information (E-TCI), E-PCP (3b),
873 E-DEI (1b), ingress E-CID base (12b).
874 - ``rsvd_grp_ecid_b``: reserved (2b), GRP (2b), E-CID base (12b).
875 - ``in_ecid_e``: ingress E-CID ext.
876 - ``ecid_e``: E-CID ext.
877 - Default ``mask`` simultaneously matches GRP and E-CID base.
882 Matches a NVGRE header (RFC 7637).
884 - ``c_k_s_rsvd0_ver``: checksum (1b), undefined (1b), key bit (1b),
885 sequence number (1b), reserved 0 (9b), version (3b). This field must have
886 value 0x2000 according to RFC 7637.
887 - ``protocol``: protocol type (0x6558).
888 - ``tni``: virtual subnet ID.
889 - ``flow_id``: flow ID.
890 - Default ``mask`` matches TNI only.
895 Matches a MPLS header.
897 - ``label_tc_s_ttl``: label, TC, Bottom of Stack and TTL.
898 - Default ``mask`` matches label only.
903 Matches a GRE header.
905 - ``c_rsvd0_ver``: checksum, reserved 0 and version.
906 - ``protocol``: protocol type.
907 - Default ``mask`` matches protocol only.
912 Fuzzy pattern match, expect faster than default.
914 This is for device that support fuzzy match option. Usually a fuzzy match is
915 fast but the cost is accuracy. i.e. Signature Match only match pattern's hash
916 value, but it is possible two different patterns have the same hash value.
918 Matching accuracy level can be configured by threshold. Driver can divide the
919 range of threshold and map to different accuracy levels that device support.
921 Threshold 0 means perfect match (no fuzziness), while threshold 0xffffffff
922 means fuzziest match.
924 .. _table_rte_flow_item_fuzzy:
928 +----------+---------------+--------------------------------------------------+
929 | Field | Subfield | Value |
930 +==========+===============+==================================================+
931 | ``spec`` | ``threshold`` | 0 as perfect match, 0xffffffff as fuzziest match |
932 +----------+---------------+--------------------------------------------------+
933 | ``last`` | ``threshold`` | upper range value |
934 +----------+---------------+--------------------------------------------------+
935 | ``mask`` | ``threshold`` | bit-mask apply to "spec" and "last" |
936 +----------+---------------+--------------------------------------------------+
938 Usage example, fuzzy match a TCPv4 packets:
940 .. _table_rte_flow_item_fuzzy_example:
942 .. table:: Fuzzy matching
958 Item: ``GTP``, ``GTPC``, ``GTPU``
959 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
961 Matches a GTPv1 header.
963 Note: GTP, GTPC and GTPU use the same structure. GTPC and GTPU item
964 are defined for a user-friendly API when creating GTP-C and GTP-U
967 - ``v_pt_rsv_flags``: version (3b), protocol type (1b), reserved (1b),
968 extension header flag (1b), sequence number flag (1b), N-PDU number
970 - ``msg_type``: message type.
971 - ``msg_len``: message length.
972 - ``teid``: tunnel endpoint identifier.
973 - Default ``mask`` matches teid only.
978 Each possible action is represented by a type. Some have associated
979 configuration structures. Several actions combined in a list can be affected
980 to a flow rule. That list is not ordered.
982 They fall in three categories:
984 - Terminating actions (such as QUEUE, DROP, RSS, PF, VF) that prevent
985 processing matched packets by subsequent flow rules, unless overridden
988 - Non-terminating actions (PASSTHRU, DUP) that leave matched packets up for
989 additional processing by subsequent flow rules.
991 - Other non-terminating meta actions that do not affect the fate of packets
992 (END, VOID, MARK, FLAG, COUNT).
994 When several actions are combined in a flow rule, they should all have
995 different types (e.g. dropping a packet twice is not possible).
997 Only the last action of a given type is taken into account. PMDs still
998 perform error checking on the entire list.
1000 Like matching patterns, action lists are terminated by END items.
1002 *Note that PASSTHRU is the only action able to override a terminating rule.*
1004 Example of action that redirects packets to queue index 10:
1006 .. _table_rte_flow_action_example:
1008 .. table:: Queue action
1010 +-----------+-------+
1012 +===========+=======+
1014 +-----------+-------+
1016 Action lists examples, their order is not significant, applications must
1017 consider all actions to be performed simultaneously:
1019 .. _table_rte_flow_count_and_drop:
1021 .. table:: Count and drop
1035 .. _table_rte_flow_mark_count_redirect:
1037 .. table:: Mark, count and redirect
1039 +-------+--------+-----------+-------+
1040 | Index | Action | Field | Value |
1041 +=======+========+===========+=======+
1042 | 0 | MARK | ``mark`` | 0x2a |
1043 +-------+--------+-----------+-------+
1045 +-------+--------+-----------+-------+
1046 | 2 | QUEUE | ``queue`` | 10 |
1047 +-------+--------+-----------+-------+
1049 +-------+----------------------------+
1053 .. _table_rte_flow_redirect_queue_5:
1055 .. table:: Redirect to queue 5
1057 +-------+--------+-----------+-------+
1058 | Index | Action | Field | Value |
1059 +=======+========+===========+=======+
1061 +-------+--------+-----------+-------+
1062 | 1 | QUEUE | ``queue`` | 5 |
1063 +-------+--------+-----------+-------+
1065 +-------+----------------------------+
1067 In the above example, considering both actions are performed simultaneously,
1068 the end result is that only QUEUE has any effect.
1070 .. _table_rte_flow_redirect_queue_3:
1072 .. table:: Redirect to queue 3
1074 +-------+--------+-----------+-------+
1075 | Index | Action | Field | Value |
1076 +=======+========+===========+=======+
1077 | 0 | QUEUE | ``queue`` | 5 |
1078 +-------+--------+-----------+-------+
1080 +-------+--------+-----------+-------+
1081 | 2 | QUEUE | ``queue`` | 3 |
1082 +-------+--------+-----------+-------+
1084 +-------+----------------------------+
1086 As previously described, only the last action of a given type found in the
1087 list is taken into account. The above example also shows that VOID is
1093 Common action types are described in this section. Like pattern item types,
1094 this list is not exhaustive as new actions will be added in the future.
1099 End marker for action lists. Prevents further processing of actions, thereby
1102 - Its numeric value is 0 for convenience.
1103 - PMD support is mandatory.
1104 - No configurable properties.
1106 .. _table_rte_flow_action_end:
1119 Used as a placeholder for convenience. It is ignored and simply discarded by
1122 - PMD support is mandatory.
1123 - No configurable properties.
1125 .. _table_rte_flow_action_void:
1135 Action: ``PASSTHRU``
1136 ^^^^^^^^^^^^^^^^^^^^
1138 Leaves packets up for additional processing by subsequent flow rules. This
1139 is the default when a rule does not contain a terminating action, but can be
1140 specified to force a rule to become non-terminating.
1142 - No configurable properties.
1144 .. _table_rte_flow_action_passthru:
1154 Example to copy a packet to a queue and continue processing by subsequent
1157 .. _table_rte_flow_action_passthru_example:
1159 .. table:: Copy to queue 8
1161 +-------+--------+-----------+-------+
1162 | Index | Action | Field | Value |
1163 +=======+========+===========+=======+
1165 +-------+--------+-----------+-------+
1166 | 1 | QUEUE | ``queue`` | 8 |
1167 +-------+--------+-----------+-------+
1169 +-------+----------------------------+
1174 Attaches an integer value to packets and sets ``PKT_RX_FDIR`` and
1175 ``PKT_RX_FDIR_ID`` mbuf flags.
1177 This value is arbitrary and application-defined. Maximum allowed value
1178 depends on the underlying implementation. It is returned in the
1179 ``hash.fdir.hi`` mbuf field.
1181 .. _table_rte_flow_action_mark:
1185 +--------+--------------------------------------+
1187 +========+======================================+
1188 | ``id`` | integer value to return with packets |
1189 +--------+--------------------------------------+
1194 Flags packets. Similar to `Action: MARK`_ without a specific value; only
1195 sets the ``PKT_RX_FDIR`` mbuf flag.
1197 - No configurable properties.
1199 .. _table_rte_flow_action_flag:
1212 Assigns packets to a given queue index.
1214 - Terminating by default.
1216 .. _table_rte_flow_action_queue:
1220 +-----------+--------------------+
1222 +===========+====================+
1223 | ``index`` | queue index to use |
1224 +-----------+--------------------+
1231 - No configurable properties.
1232 - Terminating by default.
1233 - PASSTHRU overrides this action if both are specified.
1235 .. _table_rte_flow_action_drop:
1248 Enables counters for this rule.
1250 These counters can be retrieved and reset through ``rte_flow_query()``, see
1251 ``struct rte_flow_query_count``.
1253 - Counters can be retrieved with ``rte_flow_query()``.
1254 - No configurable properties.
1256 .. _table_rte_flow_action_count:
1266 Query structure to retrieve and reset flow rule counters:
1268 .. _table_rte_flow_query_count:
1270 .. table:: COUNT query
1272 +---------------+-----+-----------------------------------+
1273 | Field | I/O | Value |
1274 +===============+=====+===================================+
1275 | ``reset`` | in | reset counter after query |
1276 +---------------+-----+-----------------------------------+
1277 | ``hits_set`` | out | ``hits`` field is set |
1278 +---------------+-----+-----------------------------------+
1279 | ``bytes_set`` | out | ``bytes`` field is set |
1280 +---------------+-----+-----------------------------------+
1281 | ``hits`` | out | number of hits for this rule |
1282 +---------------+-----+-----------------------------------+
1283 | ``bytes`` | out | number of bytes through this rule |
1284 +---------------+-----+-----------------------------------+
1289 Duplicates packets to a given queue index.
1291 This is normally combined with QUEUE, however when used alone, it is
1292 actually similar to QUEUE + PASSTHRU.
1294 - Non-terminating by default.
1296 .. _table_rte_flow_action_dup:
1300 +-----------+------------------------------------+
1302 +===========+====================================+
1303 | ``index`` | queue index to duplicate packet to |
1304 +-----------+------------------------------------+
1309 Similar to QUEUE, except RSS is additionally performed on packets to spread
1310 them among several queues according to the provided parameters.
1312 Note: RSS hash result is stored in the ``hash.rss`` mbuf field which
1313 overlaps ``hash.fdir.lo``. Since `Action: MARK`_ sets the ``hash.fdir.hi``
1314 field only, both can be requested simultaneously.
1316 - Terminating by default.
1318 .. _table_rte_flow_action_rss:
1322 +--------------+------------------------------+
1324 +==============+==============================+
1325 | ``rss_conf`` | RSS parameters |
1326 +--------------+------------------------------+
1327 | ``num`` | number of entries in queue[] |
1328 +--------------+------------------------------+
1329 | ``queue[]`` | queue indices to use |
1330 +--------------+------------------------------+
1335 Redirects packets to the physical function (PF) of the current device.
1337 - No configurable properties.
1338 - Terminating by default.
1340 .. _table_rte_flow_action_pf:
1353 Redirects packets to a virtual function (VF) of the current device.
1355 Packets matched by a VF pattern item can be redirected to their original VF
1356 ID instead of the specified one. This parameter may not be available and is
1357 not guaranteed to work properly if the VF part is matched by a prior flow
1358 rule or if packets are not addressed to a VF in the first place.
1360 - Terminating by default.
1362 .. _table_rte_flow_action_vf:
1366 +--------------+--------------------------------+
1368 +==============+================================+
1369 | ``original`` | use original VF ID if possible |
1370 +--------------+--------------------------------+
1371 | ``vf`` | VF ID to redirect packets to |
1372 +--------------+--------------------------------+
1377 Applies a stage of metering and policing.
1379 The metering and policing (MTR) object has to be first created using the
1380 rte_mtr_create() API function. The ID of the MTR object is specified as
1381 action parameter. More than one flow can use the same MTR object through
1382 the meter action. The MTR object can be further updated or queried using
1385 - Non-terminating by default.
1387 .. _table_rte_flow_action_meter:
1391 +--------------+---------------+
1393 +==============+===============+
1394 | ``mtr_id`` | MTR object ID |
1395 +--------------+---------------+
1400 All specified pattern items (``enum rte_flow_item_type``) and actions
1401 (``enum rte_flow_action_type``) use positive identifiers.
1403 The negative space is reserved for dynamic types generated by PMDs during
1404 run-time. PMDs may encounter them as a result but must not accept negative
1405 identifiers they are not aware of.
1407 A method to generate them remains to be defined.
1412 Pattern item types will be added as new protocols are implemented.
1414 Variable headers support through dedicated pattern items, for example in
1415 order to match specific IPv4 options and IPv6 extension headers would be
1416 stacked after IPv4/IPv6 items.
1418 Other action types are planned but are not defined yet. These include the
1419 ability to alter packet data in several ways, such as performing
1420 encapsulation/decapsulation of tunnel headers.
1425 A rather simple API with few functions is provided to fully manage flow
1428 Each created flow rule is associated with an opaque, PMD-specific handle
1429 pointer. The application is responsible for keeping it until the rule is
1432 Flows rules are represented by ``struct rte_flow`` objects.
1437 Given that expressing a definite set of device capabilities is not
1438 practical, a dedicated function is provided to check if a flow rule is
1439 supported and can be created.
1444 rte_flow_validate(uint16_t port_id,
1445 const struct rte_flow_attr *attr,
1446 const struct rte_flow_item pattern[],
1447 const struct rte_flow_action actions[],
1448 struct rte_flow_error *error);
1450 The flow rule is validated for correctness and whether it could be accepted
1451 by the device given sufficient resources. The rule is checked against the
1452 current device mode and queue configuration. The flow rule may also
1453 optionally be validated against existing flow rules and device resources.
1454 This function has no effect on the target device.
1456 The returned value is guaranteed to remain valid only as long as no
1457 successful calls to ``rte_flow_create()`` or ``rte_flow_destroy()`` are made
1458 in the meantime and no device parameter affecting flow rules in any way are
1459 modified, due to possible collisions or resource limitations (although in
1460 such cases ``EINVAL`` should not be returned).
1464 - ``port_id``: port identifier of Ethernet device.
1465 - ``attr``: flow rule attributes.
1466 - ``pattern``: pattern specification (list terminated by the END pattern
1468 - ``actions``: associated actions (list terminated by the END action).
1469 - ``error``: perform verbose error reporting if not NULL. PMDs initialize
1470 this structure in case of error only.
1474 - 0 if flow rule is valid and can be created. A negative errno value
1475 otherwise (``rte_errno`` is also set), the following errors are defined.
1476 - ``-ENOSYS``: underlying device does not support this functionality.
1477 - ``-EINVAL``: unknown or invalid rule specification.
1478 - ``-ENOTSUP``: valid but unsupported rule specification (e.g. partial
1479 bit-masks are unsupported).
1480 - ``EEXIST``: collision with an existing rule. Only returned if device
1481 supports flow rule collision checking and there was a flow rule
1482 collision. Not receiving this return code is no guarantee that creating
1483 the rule will not fail due to a collision.
1484 - ``ENOMEM``: not enough memory to execute the function, or if the device
1485 supports resource validation, resource limitation on the device.
1486 - ``-EBUSY``: action cannot be performed due to busy device resources, may
1487 succeed if the affected queues or even the entire port are in a stopped
1488 state (see ``rte_eth_dev_rx_queue_stop()`` and ``rte_eth_dev_stop()``).
1493 Creating a flow rule is similar to validating one, except the rule is
1494 actually created and a handle returned.
1499 rte_flow_create(uint16_t port_id,
1500 const struct rte_flow_attr *attr,
1501 const struct rte_flow_item pattern[],
1502 const struct rte_flow_action *actions[],
1503 struct rte_flow_error *error);
1507 - ``port_id``: port identifier of Ethernet device.
1508 - ``attr``: flow rule attributes.
1509 - ``pattern``: pattern specification (list terminated by the END pattern
1511 - ``actions``: associated actions (list terminated by the END action).
1512 - ``error``: perform verbose error reporting if not NULL. PMDs initialize
1513 this structure in case of error only.
1517 A valid handle in case of success, NULL otherwise and ``rte_errno`` is set
1518 to the positive version of one of the error codes defined for
1519 ``rte_flow_validate()``.
1524 Flow rules destruction is not automatic, and a queue or a port should not be
1525 released if any are still attached to them. Applications must take care of
1526 performing this step before releasing resources.
1531 rte_flow_destroy(uint16_t port_id,
1532 struct rte_flow *flow,
1533 struct rte_flow_error *error);
1536 Failure to destroy a flow rule handle may occur when other flow rules depend
1537 on it, and destroying it would result in an inconsistent state.
1539 This function is only guaranteed to succeed if handles are destroyed in
1540 reverse order of their creation.
1544 - ``port_id``: port identifier of Ethernet device.
1545 - ``flow``: flow rule handle to destroy.
1546 - ``error``: perform verbose error reporting if not NULL. PMDs initialize
1547 this structure in case of error only.
1551 - 0 on success, a negative errno value otherwise and ``rte_errno`` is set.
1556 Convenience function to destroy all flow rule handles associated with a
1557 port. They are released as with successive calls to ``rte_flow_destroy()``.
1562 rte_flow_flush(uint16_t port_id,
1563 struct rte_flow_error *error);
1565 In the unlikely event of failure, handles are still considered destroyed and
1566 no longer valid but the port must be assumed to be in an inconsistent state.
1570 - ``port_id``: port identifier of Ethernet device.
1571 - ``error``: perform verbose error reporting if not NULL. PMDs initialize
1572 this structure in case of error only.
1576 - 0 on success, a negative errno value otherwise and ``rte_errno`` is set.
1581 Query an existing flow rule.
1583 This function allows retrieving flow-specific data such as counters. Data
1584 is gathered by special actions which must be present in the flow rule
1590 rte_flow_query(uint16_t port_id,
1591 struct rte_flow *flow,
1592 enum rte_flow_action_type action,
1594 struct rte_flow_error *error);
1598 - ``port_id``: port identifier of Ethernet device.
1599 - ``flow``: flow rule handle to query.
1600 - ``action``: action type to query.
1601 - ``data``: pointer to storage for the associated query data type.
1602 - ``error``: perform verbose error reporting if not NULL. PMDs initialize
1603 this structure in case of error only.
1607 - 0 on success, a negative errno value otherwise and ``rte_errno`` is set.
1612 The general expectation for ingress traffic is that flow rules process it
1613 first; the remaining unmatched or pass-through traffic usually ends up in a
1614 queue (with or without RSS, locally or in some sub-device instance)
1615 depending on the global configuration settings of a port.
1617 While fine from a compatibility standpoint, this approach makes drivers more
1618 complex as they have to check for possible side effects outside of this API
1619 when creating or destroying flow rules. It results in a more limited set of
1620 available rule types due to the way device resources are assigned (e.g. no
1621 support for the RSS action even on capable hardware).
1623 Given that nonspecific traffic can be handled by flow rules as well,
1624 isolated mode is a means for applications to tell a driver that ingress on
1625 the underlying port must be injected from the defined flow rules only; that
1626 no default traffic is expected outside those rules.
1628 This has the following benefits:
1630 - Applications get finer-grained control over the kind of traffic they want
1631 to receive (no traffic by default).
1633 - More importantly they control at what point nonspecific traffic is handled
1634 relative to other flow rules, by adjusting priority levels.
1636 - Drivers can assign more hardware resources to flow rules and expand the
1637 set of supported rule types.
1639 Because toggling isolated mode may cause profound changes to the ingress
1640 processing path of a driver, it may not be possible to leave it once
1641 entered. Likewise, existing flow rules or global configuration settings may
1642 prevent a driver from entering isolated mode.
1644 Applications relying on this mode are therefore encouraged to toggle it as
1645 soon as possible after device initialization, ideally before the first call
1646 to ``rte_eth_dev_configure()`` to avoid possible failures due to conflicting
1649 Once effective, the following functionality has no effect on the underlying
1650 port and may return errors such as ``ENOTSUP`` ("not supported"):
1652 - Toggling promiscuous mode.
1653 - Toggling allmulticast mode.
1654 - Configuring MAC addresses.
1655 - Configuring multicast addresses.
1656 - Configuring VLAN filters.
1657 - Configuring Rx filters through the legacy API (e.g. FDIR).
1658 - Configuring global RSS settings.
1663 rte_flow_isolate(uint16_t port_id, int set, struct rte_flow_error *error);
1667 - ``port_id``: port identifier of Ethernet device.
1668 - ``set``: nonzero to enter isolated mode, attempt to leave it otherwise.
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.
1676 Verbose error reporting
1677 -----------------------
1679 The defined *errno* values may not be accurate enough for users or
1680 application developers who want to investigate issues related to flow rules
1681 management. A dedicated error object is defined for this purpose:
1685 enum rte_flow_error_type {
1686 RTE_FLOW_ERROR_TYPE_NONE, /**< No error. */
1687 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, /**< Cause unspecified. */
1688 RTE_FLOW_ERROR_TYPE_HANDLE, /**< Flow rule (handle). */
1689 RTE_FLOW_ERROR_TYPE_ATTR_GROUP, /**< Group field. */
1690 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY, /**< Priority field. */
1691 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS, /**< Ingress field. */
1692 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, /**< Egress field. */
1693 RTE_FLOW_ERROR_TYPE_ATTR, /**< Attributes structure. */
1694 RTE_FLOW_ERROR_TYPE_ITEM_NUM, /**< Pattern length. */
1695 RTE_FLOW_ERROR_TYPE_ITEM, /**< Specific pattern item. */
1696 RTE_FLOW_ERROR_TYPE_ACTION_NUM, /**< Number of actions. */
1697 RTE_FLOW_ERROR_TYPE_ACTION, /**< Specific action. */
1700 struct rte_flow_error {
1701 enum rte_flow_error_type type; /**< Cause field and error types. */
1702 const void *cause; /**< Object responsible for the error. */
1703 const char *message; /**< Human-readable error message. */
1706 Error type ``RTE_FLOW_ERROR_TYPE_NONE`` stands for no error, in which case
1707 remaining fields can be ignored. Other error types describe the type of the
1708 object pointed by ``cause``.
1710 If non-NULL, ``cause`` points to the object responsible for the error. For a
1711 flow rule, this may be a pattern item or an individual action.
1713 If non-NULL, ``message`` provides a human-readable error message.
1715 This object is normally allocated by applications and set by PMDs in case of
1716 error, the message points to a constant string which does not need to be
1717 freed by the application, however its pointer can be considered valid only
1718 as long as its associated DPDK port remains configured. Closing the
1719 underlying device or unloading the PMD invalidates it.
1730 rte_flow_error_set(struct rte_flow_error *error,
1732 enum rte_flow_error_type type,
1734 const char *message);
1736 This function initializes ``error`` (if non-NULL) with the provided
1737 parameters and sets ``rte_errno`` to ``code``. A negative error ``code`` is
1743 - DPDK does not keep track of flow rules definitions or flow rule objects
1744 automatically. Applications may keep track of the former and must keep
1745 track of the latter. PMDs may also do it for internal needs, however this
1746 must not be relied on by applications.
1748 - Flow rules are not maintained between successive port initializations. An
1749 application exiting without releasing them and restarting must re-create
1752 - API operations are synchronous and blocking (``EAGAIN`` cannot be
1755 - There is no provision for reentrancy/multi-thread safety, although nothing
1756 should prevent different devices from being configured at the same
1757 time. PMDs may protect their control path functions accordingly.
1759 - Stopping the data path (TX/RX) should not be necessary when managing flow
1760 rules. If this cannot be achieved naturally or with workarounds (such as
1761 temporarily replacing the burst function pointers), an appropriate error
1762 code must be returned (``EBUSY``).
1764 - PMDs, not applications, are responsible for maintaining flow rules
1765 configuration when stopping and restarting a port or performing other
1766 actions which may affect them. They can only be destroyed explicitly by
1769 For devices exposing multiple ports sharing global settings affected by flow
1772 - All ports under DPDK control must behave consistently, PMDs are
1773 responsible for making sure that existing flow rules on a port are not
1774 affected by other ports.
1776 - Ports not under DPDK control (unaffected or handled by other applications)
1777 are user's responsibility. They may affect existing flow rules and cause
1778 undefined behavior. PMDs aware of this may prevent flow rules creation
1779 altogether in such cases.
1784 The PMD interface is defined in ``rte_flow_driver.h``. It is not subject to
1785 API/ABI versioning constraints as it is not exposed to applications and may
1786 evolve independently.
1788 It is currently implemented on top of the legacy filtering framework through
1789 filter type *RTE_ETH_FILTER_GENERIC* that accepts the single operation
1790 *RTE_ETH_FILTER_GET* to return PMD-specific *rte_flow* callbacks wrapped
1791 inside ``struct rte_flow_ops``.
1793 This overhead is temporarily necessary in order to keep compatibility with
1794 the legacy filtering framework, which should eventually disappear.
1796 - PMD callbacks implement exactly the interface described in `Rules
1797 management`_, except for the port ID argument which has already been
1798 converted to a pointer to the underlying ``struct rte_eth_dev``.
1800 - Public API functions do not process flow rules definitions at all before
1801 calling PMD functions (no basic error checking, no validation
1802 whatsoever). They only make sure these callbacks are non-NULL or return
1803 the ``ENOSYS`` (function not supported) error.
1805 This interface additionally defines the following helper function:
1807 - ``rte_flow_ops_get()``: get generic flow operations structure from a
1810 More will be added over time.
1812 Device compatibility
1813 --------------------
1815 No known implementation supports all the described features.
1817 Unsupported features or combinations are not expected to be fully emulated
1818 in software by PMDs for performance reasons. Partially supported features
1819 may be completed in software as long as hardware performs most of the work
1820 (such as queue redirection and packet recognition).
1822 However PMDs are expected to do their best to satisfy application requests
1823 by working around hardware limitations as long as doing so does not affect
1824 the behavior of existing flow rules.
1826 The following sections provide a few examples of such cases and describe how
1827 PMDs should handle them, they are based on limitations built into the
1833 Each flow rule comes with its own, per-layer bit-masks, while hardware may
1834 support only a single, device-wide bit-mask for a given layer type, so that
1835 two IPv4 rules cannot use different bit-masks.
1837 The expected behavior in this case is that PMDs automatically configure
1838 global bit-masks according to the needs of the first flow rule created.
1840 Subsequent rules are allowed only if their bit-masks match those, the
1841 ``EEXIST`` error code should be returned otherwise.
1843 Unsupported layer types
1844 ~~~~~~~~~~~~~~~~~~~~~~~
1846 Many protocols can be simulated by crafting patterns with the `Item: RAW`_
1849 PMDs can rely on this capability to simulate support for protocols with
1850 headers not directly recognized by hardware.
1852 ``ANY`` pattern item
1853 ~~~~~~~~~~~~~~~~~~~~
1855 This pattern item stands for anything, which can be difficult to translate
1856 to something hardware would understand, particularly if followed by more
1859 Consider the following pattern:
1861 .. _table_rte_flow_unsupported_any:
1863 .. table:: Pattern with ANY as L3
1865 +-------+-----------------------+
1867 +=======+=======================+
1869 +-------+-----+---------+-------+
1870 | 1 | ANY | ``num`` | ``1`` |
1871 +-------+-----+---------+-------+
1873 +-------+-----------------------+
1875 +-------+-----------------------+
1877 Knowing that TCP does not make sense with something other than IPv4 and IPv6
1878 as L3, such a pattern may be translated to two flow rules instead:
1880 .. _table_rte_flow_unsupported_any_ipv4:
1882 .. table:: ANY replaced with IPV4
1884 +-------+--------------------+
1886 +=======+====================+
1888 +-------+--------------------+
1889 | 1 | IPV4 (zeroed mask) |
1890 +-------+--------------------+
1892 +-------+--------------------+
1894 +-------+--------------------+
1898 .. _table_rte_flow_unsupported_any_ipv6:
1900 .. table:: ANY replaced with IPV6
1902 +-------+--------------------+
1904 +=======+====================+
1906 +-------+--------------------+
1907 | 1 | IPV6 (zeroed mask) |
1908 +-------+--------------------+
1910 +-------+--------------------+
1912 +-------+--------------------+
1914 Note that as soon as a ANY rule covers several layers, this approach may
1915 yield a large number of hidden flow rules. It is thus suggested to only
1916 support the most common scenarios (anything as L2 and/or L3).
1921 - When combined with `Action: QUEUE`_, packet counting (`Action: COUNT`_)
1922 and tagging (`Action: MARK`_ or `Action: FLAG`_) may be implemented in
1923 software as long as the target queue is used by a single rule.
1925 - A rule specifying both `Action: DUP`_ + `Action: QUEUE`_ may be translated
1926 to two hidden rules combining `Action: QUEUE`_ and `Action: PASSTHRU`_.
1928 - When a single target queue is provided, `Action: RSS`_ can also be
1929 implemented through `Action: QUEUE`_.
1934 While it would naturally make sense, flow rules cannot be assumed to be
1935 processed by hardware in the same order as their creation for several
1938 - They may be managed internally as a tree or a hash table instead of a
1940 - Removing a flow rule before adding another one can either put the new rule
1941 at the end of the list or reuse a freed entry.
1942 - Duplication may occur when packets are matched by several rules.
1944 For overlapping rules (particularly in order to use `Action: PASSTHRU`_)
1945 predictable behavior is only guaranteed by using different priority levels.
1947 Priority levels are not necessarily implemented in hardware, or may be
1948 severely limited (e.g. a single priority bit).
1950 For these reasons, priority levels may be implemented purely in software by
1953 - For devices expecting flow rules to be added in the correct order, PMDs
1954 may destroy and re-create existing rules after adding a new one with
1957 - A configurable number of dummy or empty rules can be created at
1958 initialization time to save high priority slots for later.
1960 - In order to save priority levels, PMDs may evaluate whether rules are
1961 likely to collide and adjust their priority accordingly.
1966 - A device profile selection function which could be used to force a
1967 permanent profile instead of relying on its automatic configuration based
1968 on existing flow rules.
1970 - A method to optimize *rte_flow* rules with specific pattern items and
1971 action types generated on the fly by PMDs. DPDK should assign negative
1972 numbers to these in order to not collide with the existing types. See
1975 - Adding specific egress pattern items and actions as described in
1976 `Attribute: Traffic direction`_.
1978 - Optional software fallback when PMDs are unable to handle requested flow
1979 rules so applications do not have to implement their own.
1984 Exhaustive list of deprecated filter types (normally prefixed with
1985 *RTE_ETH_FILTER_*) found in ``rte_eth_ctrl.h`` and methods to convert them
1986 to *rte_flow* rules.
1988 ``MACVLAN`` to ``ETH`` → ``VF``, ``PF``
1989 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1991 *MACVLAN* can be translated to a basic `Item: ETH`_ flow rule with a
1992 terminating `Action: VF`_ or `Action: PF`_.
1994 .. _table_rte_flow_migration_macvlan:
1996 .. table:: MACVLAN conversion
1998 +--------------------------+---------+
1999 | Pattern | Actions |
2000 +===+=====+==========+=====+=========+
2001 | 0 | ETH | ``spec`` | any | VF, |
2002 | | +----------+-----+ PF |
2003 | | | ``last`` | N/A | |
2004 | | +----------+-----+ |
2005 | | | ``mask`` | any | |
2006 +---+-----+----------+-----+---------+
2008 +---+----------------------+---------+
2010 ``ETHERTYPE`` to ``ETH`` → ``QUEUE``, ``DROP``
2011 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2013 *ETHERTYPE* is basically an `Item: ETH`_ flow rule with a terminating
2014 `Action: QUEUE`_ or `Action: DROP`_.
2016 .. _table_rte_flow_migration_ethertype:
2018 .. table:: ETHERTYPE conversion
2020 +--------------------------+---------+
2021 | Pattern | Actions |
2022 +===+=====+==========+=====+=========+
2023 | 0 | ETH | ``spec`` | any | QUEUE, |
2024 | | +----------+-----+ DROP |
2025 | | | ``last`` | N/A | |
2026 | | +----------+-----+ |
2027 | | | ``mask`` | any | |
2028 +---+-----+----------+-----+---------+
2030 +---+----------------------+---------+
2032 ``FLEXIBLE`` to ``RAW`` → ``QUEUE``
2033 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2035 *FLEXIBLE* can be translated to one `Item: RAW`_ pattern with a terminating
2036 `Action: QUEUE`_ and a defined priority level.
2038 .. _table_rte_flow_migration_flexible:
2040 .. table:: FLEXIBLE conversion
2042 +--------------------------+---------+
2043 | Pattern | Actions |
2044 +===+=====+==========+=====+=========+
2045 | 0 | RAW | ``spec`` | any | QUEUE |
2046 | | +----------+-----+ |
2047 | | | ``last`` | N/A | |
2048 | | +----------+-----+ |
2049 | | | ``mask`` | any | |
2050 +---+-----+----------+-----+---------+
2052 +---+----------------------+---------+
2054 ``SYN`` to ``TCP`` → ``QUEUE``
2055 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2057 *SYN* is a `Item: TCP`_ rule with only the ``syn`` bit enabled and masked,
2058 and a terminating `Action: QUEUE`_.
2060 Priority level can be set to simulate the high priority bit.
2062 .. _table_rte_flow_migration_syn:
2064 .. table:: SYN conversion
2066 +-----------------------------------+---------+
2067 | Pattern | Actions |
2068 +===+======+==========+=============+=========+
2069 | 0 | ETH | ``spec`` | unset | QUEUE |
2070 | | +----------+-------------+ |
2071 | | | ``last`` | unset | |
2072 | | +----------+-------------+ |
2073 | | | ``mask`` | unset | |
2074 +---+------+----------+-------------+---------+
2075 | 1 | IPV4 | ``spec`` | unset | END |
2076 | | +----------+-------------+ |
2077 | | | ``mask`` | unset | |
2078 | | +----------+-------------+ |
2079 | | | ``mask`` | unset | |
2080 +---+------+----------+---------+---+ |
2081 | 2 | TCP | ``spec`` | ``syn`` | 1 | |
2082 | | +----------+---------+---+ |
2083 | | | ``mask`` | ``syn`` | 1 | |
2084 +---+------+----------+---------+---+ |
2086 +---+-------------------------------+---------+
2088 ``NTUPLE`` to ``IPV4``, ``TCP``, ``UDP`` → ``QUEUE``
2089 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2091 *NTUPLE* is similar to specifying an empty L2, `Item: IPV4`_ as L3 with
2092 `Item: TCP`_ or `Item: UDP`_ as L4 and a terminating `Action: QUEUE`_.
2094 A priority level can be specified as well.
2096 .. _table_rte_flow_migration_ntuple:
2098 .. table:: NTUPLE conversion
2100 +-----------------------------+---------+
2101 | Pattern | Actions |
2102 +===+======+==========+=======+=========+
2103 | 0 | ETH | ``spec`` | unset | QUEUE |
2104 | | +----------+-------+ |
2105 | | | ``last`` | unset | |
2106 | | +----------+-------+ |
2107 | | | ``mask`` | unset | |
2108 +---+------+----------+-------+---------+
2109 | 1 | IPV4 | ``spec`` | any | END |
2110 | | +----------+-------+ |
2111 | | | ``last`` | unset | |
2112 | | +----------+-------+ |
2113 | | | ``mask`` | any | |
2114 +---+------+----------+-------+ |
2115 | 2 | TCP, | ``spec`` | any | |
2116 | | UDP +----------+-------+ |
2117 | | | ``last`` | unset | |
2118 | | +----------+-------+ |
2119 | | | ``mask`` | any | |
2120 +---+------+----------+-------+ |
2122 +---+-------------------------+---------+
2124 ``TUNNEL`` to ``ETH``, ``IPV4``, ``IPV6``, ``VXLAN`` (or other) → ``QUEUE``
2125 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2127 *TUNNEL* matches common IPv4 and IPv6 L3/L4-based tunnel types.
2129 In the following table, `Item: ANY`_ is used to cover the optional L4.
2131 .. _table_rte_flow_migration_tunnel:
2133 .. table:: TUNNEL conversion
2135 +-------------------------------------------------------+---------+
2136 | Pattern | Actions |
2137 +===+==========================+==========+=============+=========+
2138 | 0 | ETH | ``spec`` | any | QUEUE |
2139 | | +----------+-------------+ |
2140 | | | ``last`` | unset | |
2141 | | +----------+-------------+ |
2142 | | | ``mask`` | any | |
2143 +---+--------------------------+----------+-------------+---------+
2144 | 1 | IPV4, IPV6 | ``spec`` | any | END |
2145 | | +----------+-------------+ |
2146 | | | ``last`` | unset | |
2147 | | +----------+-------------+ |
2148 | | | ``mask`` | any | |
2149 +---+--------------------------+----------+-------------+ |
2150 | 2 | ANY | ``spec`` | any | |
2151 | | +----------+-------------+ |
2152 | | | ``last`` | unset | |
2153 | | +----------+---------+---+ |
2154 | | | ``mask`` | ``num`` | 0 | |
2155 +---+--------------------------+----------+---------+---+ |
2156 | 3 | VXLAN, GENEVE, TEREDO, | ``spec`` | any | |
2157 | | NVGRE, GRE, ... +----------+-------------+ |
2158 | | | ``last`` | unset | |
2159 | | +----------+-------------+ |
2160 | | | ``mask`` | any | |
2161 +---+--------------------------+----------+-------------+ |
2163 +---+---------------------------------------------------+---------+
2165 ``FDIR`` to most item types → ``QUEUE``, ``DROP``, ``PASSTHRU``
2166 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2168 *FDIR* is more complex than any other type, there are several methods to
2169 emulate its functionality. It is summarized for the most part in the table
2172 A few features are intentionally not supported:
2174 - The ability to configure the matching input set and masks for the entire
2175 device, PMDs should take care of it automatically according to the
2176 requested flow rules.
2178 For example if a device supports only one bit-mask per protocol type,
2179 source/address IPv4 bit-masks can be made immutable by the first created
2180 rule. Subsequent IPv4 or TCPv4 rules can only be created if they are
2183 Note that only protocol bit-masks affected by existing flow rules are
2184 immutable, others can be changed later. They become mutable again after
2185 the related flow rules are destroyed.
2187 - Returning four or eight bytes of matched data when using flex bytes
2188 filtering. Although a specific action could implement it, it conflicts
2189 with the much more useful 32 bits tagging on devices that support it.
2191 - Side effects on RSS processing of the entire device. Flow rules that
2192 conflict with the current device configuration should not be
2193 allowed. Similarly, device configuration should not be allowed when it
2194 affects existing flow rules.
2196 - Device modes of operation. "none" is unsupported since filtering cannot be
2197 disabled as long as a flow rule is present.
2199 - "MAC VLAN" or "tunnel" perfect matching modes should be automatically set
2200 according to the created flow rules.
2202 - Signature mode of operation is not defined but could be handled through
2205 .. _table_rte_flow_migration_fdir:
2207 .. table:: FDIR conversion
2209 +----------------------------------------+-----------------------+
2210 | Pattern | Actions |
2211 +===+===================+==========+=====+=======================+
2212 | 0 | ETH, RAW | ``spec`` | any | QUEUE, DROP, PASSTHRU |
2213 | | +----------+-----+ |
2214 | | | ``last`` | N/A | |
2215 | | +----------+-----+ |
2216 | | | ``mask`` | any | |
2217 +---+-------------------+----------+-----+-----------------------+
2218 | 1 | IPV4, IPv6 | ``spec`` | any | MARK |
2219 | | +----------+-----+ |
2220 | | | ``last`` | N/A | |
2221 | | +----------+-----+ |
2222 | | | ``mask`` | any | |
2223 +---+-------------------+----------+-----+-----------------------+
2224 | 2 | TCP, UDP, SCTP | ``spec`` | any | END |
2225 | | +----------+-----+ |
2226 | | | ``last`` | N/A | |
2227 | | +----------+-----+ |
2228 | | | ``mask`` | any | |
2229 +---+-------------------+----------+-----+ |
2230 | 3 | VF, PF, FUZZY | ``spec`` | any | |
2231 | | (optional) +----------+-----+ |
2232 | | | ``last`` | N/A | |
2233 | | +----------+-----+ |
2234 | | | ``mask`` | any | |
2235 +---+-------------------+----------+-----+ |
2237 +---+------------------------------------+-----------------------+
2242 There is no counterpart to this filter type because it translates to a
2243 global device setting instead of a pattern item. Device settings are
2244 automatically set according to the created flow rules.
2246 ``L2_TUNNEL`` to ``VOID`` → ``VXLAN`` (or others)
2247 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2249 All packets are matched. This type alters incoming packets to encapsulate
2250 them in a chosen tunnel type, optionally redirect them to a VF as well.
2252 The destination pool for tag based forwarding can be emulated with other
2253 flow rules using `Action: DUP`_.
2255 .. _table_rte_flow_migration_l2tunnel:
2257 .. table:: L2_TUNNEL conversion
2259 +---------------------------+--------------------+
2260 | Pattern | Actions |
2261 +===+======+==========+=====+====================+
2262 | 0 | VOID | ``spec`` | N/A | VXLAN, GENEVE, ... |
2265 | | +----------+-----+ |
2266 | | | ``last`` | N/A | |
2267 | | +----------+-----+ |
2268 | | | ``mask`` | N/A | |
2270 +---+------+----------+-----+--------------------+
2271 | 1 | END | VF (optional) |
2272 +---+ +--------------------+
2274 +---+-----------------------+--------------------+