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 within
94 the context of that group. Groups are not linked by default, so the logical
95 hierarchy of groups must be explicitly defined by flow rules themselves in each
96 group using the JUMP action to define the next group to redirect too. Only flow
97 rules defined in the default group 0 are guarantee to be matched against, this
98 makes group 0 the origin of any group hierarchy defined by an application.
100 Support for multiple actions per rule may be implemented internally on top
101 of non-default hardware priorities, as a result both features may not be
102 simultaneously available to applications.
104 Considering that allowed pattern/actions combinations cannot be known in
105 advance and would result in an impractically large number of capabilities to
106 expose, a method is provided to validate a given rule from the current
107 device configuration state.
109 This enables applications to check if the rule types they need is supported
110 at initialization time, before starting their data path. This method can be
111 used anytime, its only requirement being that the resources needed by a rule
112 should exist (e.g. a target RX queue should be configured first).
114 Each defined rule is associated with an opaque handle managed by the PMD,
115 applications are responsible for keeping it. These can be used for queries
116 and rules management, such as retrieving counters or other data and
119 To avoid resource leaks on the PMD side, handles must be explicitly
120 destroyed by the application before releasing associated resources such as
123 The following sections cover:
125 - **Attributes** (represented by ``struct rte_flow_attr``): properties of a
126 flow rule such as its direction (ingress or egress) and priority.
128 - **Pattern item** (represented by ``struct rte_flow_item``): part of a
129 matching pattern that either matches specific packet data or traffic
130 properties. It can also describe properties of the pattern itself, such as
133 - **Matching pattern**: traffic properties to look for, a combination of any
136 - **Actions** (represented by ``struct rte_flow_action``): operations to
137 perform whenever a packet is matched by a pattern.
145 Flow rules can be grouped by assigning them a common group number. Groups
146 allow a logical hierarchy of flow rule groups (tables) to be defined. These
147 groups can be supported virtually in the PMD or in the physical device.
148 Group 0 is the default group and this is the only group which flows are
149 guarantee to matched against, all subsequent groups can only be reached by
150 way of the JUMP action from a matched flow rule.
152 Although optional, applications are encouraged to group similar rules as
153 much as possible to fully take advantage of hardware capabilities
154 (e.g. optimized matching) and work around limitations (e.g. a single pattern
155 type possibly allowed in a given group), while being aware that the groups
156 hierarchies must be programmed explicitly.
158 Note that support for more than a single group is not guaranteed.
163 A priority level can be assigned to a flow rule, lower values
164 denote higher priority, with 0 as the maximum.
166 Priority levels are arbitrary and up to the application, they do
167 not need to be contiguous nor start from 0, however the maximum number
168 varies between devices and may be affected by existing flow rules.
170 A flow which matches multiple rules in the same group will always matched by
171 the rule with the highest priority in that group.
173 If a packet is matched by several rules of a given group for a given
174 priority level, the outcome is undefined. It can take any path, may be
175 duplicated or even cause unrecoverable errors.
177 Note that support for more than a single priority level is not guaranteed.
179 Attribute: Traffic direction
180 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
182 Flow rule patterns apply to inbound and/or outbound traffic.
184 In the context of this API, **ingress** and **egress** respectively stand
185 for **inbound** and **outbound** based on the standpoint of the application
186 creating a flow rule.
188 There are no exceptions to this definition.
190 Several pattern items and actions are valid and can be used in both
191 directions. At least one direction must be specified.
193 Specifying both directions at once for a given rule is not recommended but
194 may be valid in a few cases (e.g. shared counters).
199 Instead of simply matching the properties of traffic as it would appear on a
200 given DPDK port ID, enabling this attribute transfers a flow rule to the
201 lowest possible level of any device endpoints found in the pattern.
203 When supported, this effectively enables an application to reroute traffic
204 not necessarily intended for it (e.g. coming from or addressed to different
205 physical ports, VFs or applications) at the device level.
207 It complements the behavior of some pattern items such as `Item: PHY_PORT`_
208 and is meaningless without them.
210 When transferring flow rules, **ingress** and **egress** attributes
211 (`Attribute: Traffic direction`_) keep their original meaning, as if
212 processing traffic emitted or received by the application.
217 Pattern items fall in two categories:
219 - Matching protocol headers and packet data, usually associated with a
220 specification structure. These must be stacked in the same order as the
221 protocol layers to match inside packets, starting from the lowest.
223 - Matching meta-data or affecting pattern processing, often without a
224 specification structure. Since they do not match packet contents, their
225 position in the list is usually not relevant.
227 Item specification structures are used to match specific values among
228 protocol fields (or item properties). Documentation describes for each item
229 whether they are associated with one and their type name if so.
231 Up to three structures of the same type can be set for a given item:
233 - ``spec``: values to match (e.g. a given IPv4 address).
235 - ``last``: upper bound for an inclusive range with corresponding fields in
238 - ``mask``: bit-mask applied to both ``spec`` and ``last`` whose purpose is
239 to distinguish the values to take into account and/or partially mask them
240 out (e.g. in order to match an IPv4 address prefix).
242 Usage restrictions and expected behavior:
244 - Setting either ``mask`` or ``last`` without ``spec`` is an error.
246 - Field values in ``last`` which are either 0 or equal to the corresponding
247 values in ``spec`` are ignored; they do not generate a range. Nonzero
248 values lower than those in ``spec`` are not supported.
250 - Setting ``spec`` and optionally ``last`` without ``mask`` causes the PMD
251 to use the default mask defined for that item (defined as
252 ``rte_flow_item_{name}_mask`` constants).
254 - Not setting any of them (assuming item type allows it) is equivalent to
255 providing an empty (zeroed) ``mask`` for broad (nonspecific) matching.
257 - ``mask`` is a simple bit-mask applied before interpreting the contents of
258 ``spec`` and ``last``, which may yield unexpected results if not used
259 carefully. For example, if for an IPv4 address field, ``spec`` provides
260 *10.1.2.3*, ``last`` provides *10.3.4.5* and ``mask`` provides
261 *255.255.0.0*, the effective range becomes *10.1.0.0* to *10.3.255.255*.
263 Example of an item specification matching an Ethernet header:
265 .. _table_rte_flow_pattern_item_example:
267 .. table:: Ethernet item
269 +----------+----------+--------------------+
270 | Field | Subfield | Value |
271 +==========+==========+====================+
272 | ``spec`` | ``src`` | ``00:01:02:03:04`` |
273 | +----------+--------------------+
274 | | ``dst`` | ``00:2a:66:00:01`` |
275 | +----------+--------------------+
276 | | ``type`` | ``0x22aa`` |
277 +----------+----------+--------------------+
278 | ``last`` | unspecified |
279 +----------+----------+--------------------+
280 | ``mask`` | ``src`` | ``00:ff:ff:ff:00`` |
281 | +----------+--------------------+
282 | | ``dst`` | ``00:00:00:00:ff`` |
283 | +----------+--------------------+
284 | | ``type`` | ``0x0000`` |
285 +----------+----------+--------------------+
287 Non-masked bits stand for any value (shown as ``?`` below), Ethernet headers
288 with the following properties are thus matched:
290 - ``src``: ``??:01:02:03:??``
291 - ``dst``: ``??:??:??:??:01``
292 - ``type``: ``0x????``
297 A pattern is formed by stacking items starting from the lowest protocol
298 layer to match. This stacking restriction does not apply to meta items which
299 can be placed anywhere in the stack without affecting the meaning of the
302 Patterns are terminated by END items.
306 .. _table_rte_flow_tcpv4_as_l4:
308 .. table:: TCPv4 as L4
324 .. _table_rte_flow_tcpv6_in_vxlan:
326 .. table:: TCPv6 in VXLAN
328 +-------+------------+
330 +=======+============+
332 +-------+------------+
334 +-------+------------+
336 +-------+------------+
338 +-------+------------+
340 +-------+------------+
342 +-------+------------+
344 +-------+------------+
346 +-------+------------+
350 .. _table_rte_flow_tcpv4_as_l4_meta:
352 .. table:: TCPv4 as L4 with meta items
374 The above example shows how meta items do not affect packet data matching
375 items, as long as those remain stacked properly. The resulting matching
376 pattern is identical to "TCPv4 as L4".
378 .. _table_rte_flow_udpv6_anywhere:
380 .. table:: UDPv6 anywhere
392 If supported by the PMD, omitting one or several protocol layers at the
393 bottom of the stack as in the above example (missing an Ethernet
394 specification) enables looking up anywhere in packets.
396 It is unspecified whether the payload of supported encapsulations
397 (e.g. VXLAN payload) is matched by such a pattern, which may apply to inner,
398 outer or both packets.
400 .. _table_rte_flow_invalid_l3:
402 .. table:: Invalid, missing L3
414 The above pattern is invalid due to a missing L3 specification between L2
415 (Ethernet) and L4 (UDP). Doing so is only allowed at the bottom and at the
421 They match meta-data or affect pattern processing instead of matching packet
422 data directly, most of them do not need a specification structure. This
423 particularity allows them to be specified anywhere in the stack without
424 causing any side effect.
429 End marker for item lists. Prevents further processing of items, thereby
432 - Its numeric value is 0 for convenience.
433 - PMD support is mandatory.
434 - ``spec``, ``last`` and ``mask`` are ignored.
436 .. _table_rte_flow_item_end:
440 +----------+---------+
442 +==========+=========+
443 | ``spec`` | ignored |
444 +----------+---------+
445 | ``last`` | ignored |
446 +----------+---------+
447 | ``mask`` | ignored |
448 +----------+---------+
453 Used as a placeholder for convenience. It is ignored and simply discarded by
456 - PMD support is mandatory.
457 - ``spec``, ``last`` and ``mask`` are ignored.
459 .. _table_rte_flow_item_void:
463 +----------+---------+
465 +==========+=========+
466 | ``spec`` | ignored |
467 +----------+---------+
468 | ``last`` | ignored |
469 +----------+---------+
470 | ``mask`` | ignored |
471 +----------+---------+
473 One usage example for this type is generating rules that share a common
474 prefix quickly without reallocating memory, only by updating item types:
476 .. _table_rte_flow_item_void_example:
478 .. table:: TCP, UDP or ICMP as L4
480 +-------+--------------------+
482 +=======+====================+
484 +-------+--------------------+
486 +-------+------+------+------+
487 | 2 | UDP | VOID | VOID |
488 +-------+------+------+------+
489 | 3 | VOID | TCP | VOID |
490 +-------+------+------+------+
491 | 4 | VOID | VOID | ICMP |
492 +-------+------+------+------+
494 +-------+--------------------+
499 Inverted matching, i.e. process packets that do not match the pattern.
501 - ``spec``, ``last`` and ``mask`` are ignored.
503 .. _table_rte_flow_item_invert:
507 +----------+---------+
509 +==========+=========+
510 | ``spec`` | ignored |
511 +----------+---------+
512 | ``last`` | ignored |
513 +----------+---------+
514 | ``mask`` | ignored |
515 +----------+---------+
517 Usage example, matching non-TCPv4 packets only:
519 .. _table_rte_flow_item_invert_example:
521 .. table:: Anything but TCPv4
540 Matches traffic originating from (ingress) or going to (egress) the physical
541 function of the current device.
543 If supported, should work even if the physical function is not managed by
544 the application and thus not associated with a DPDK port ID.
546 - Can be combined with any number of `Item: VF`_ to match both PF and VF
548 - ``spec``, ``last`` and ``mask`` must not be set.
550 .. _table_rte_flow_item_pf:
567 Matches traffic originating from (ingress) or going to (egress) a given
568 virtual function of the current device.
570 If supported, should work even if the virtual function is not managed by the
571 application and thus not associated with a DPDK port ID.
573 Note this pattern item does not match VF representors traffic which, as
574 separate entities, should be addressed through their own DPDK port IDs.
576 - Can be specified multiple times to match traffic addressed to several VF
578 - Can be combined with a PF item to match both PF and VF traffic.
579 - Default ``mask`` matches any VF ID.
581 .. _table_rte_flow_item_vf:
585 +----------+----------+---------------------------+
586 | Field | Subfield | Value |
587 +==========+==========+===========================+
588 | ``spec`` | ``id`` | destination VF ID |
589 +----------+----------+---------------------------+
590 | ``last`` | ``id`` | upper range value |
591 +----------+----------+---------------------------+
592 | ``mask`` | ``id`` | zeroed to match any VF ID |
593 +----------+----------+---------------------------+
598 Matches traffic originating from (ingress) or going to (egress) a physical
599 port of the underlying device.
601 The first PHY_PORT item overrides the physical port normally associated with
602 the specified DPDK input port (port_id). This item can be provided several
603 times to match additional physical ports.
605 Note that physical ports are not necessarily tied to DPDK input ports
606 (port_id) when those are not under DPDK control. Possible values are
607 specific to each device, they are not necessarily indexed from zero and may
610 As a device property, the list of allowed values as well as the value
611 associated with a port_id should be retrieved by other means.
613 - Default ``mask`` matches any port index.
615 .. _table_rte_flow_item_phy_port:
619 +----------+-----------+--------------------------------+
620 | Field | Subfield | Value |
621 +==========+===========+================================+
622 | ``spec`` | ``index`` | physical port index |
623 +----------+-----------+--------------------------------+
624 | ``last`` | ``index`` | upper range value |
625 +----------+-----------+--------------------------------+
626 | ``mask`` | ``index`` | zeroed to match any port index |
627 +----------+-----------+--------------------------------+
632 Matches traffic originating from (ingress) or going to (egress) a given DPDK
635 Normally only supported if the port ID in question is known by the
636 underlying PMD and related to the device the flow rule is created against.
638 This must not be confused with `Item: PHY_PORT`_ which refers to the
639 physical port of a device, whereas `Item: PORT_ID`_ refers to a ``struct
640 rte_eth_dev`` object on the application side (also known as "port
641 representor" depending on the kind of underlying device).
643 - Default ``mask`` matches the specified DPDK port ID.
645 .. _table_rte_flow_item_port_id:
649 +----------+----------+-----------------------------+
650 | Field | Subfield | Value |
651 +==========+==========+=============================+
652 | ``spec`` | ``id`` | DPDK port ID |
653 +----------+----------+-----------------------------+
654 | ``last`` | ``id`` | upper range value |
655 +----------+----------+-----------------------------+
656 | ``mask`` | ``id`` | zeroed to match any port ID |
657 +----------+----------+-----------------------------+
662 Matches an arbitrary integer value which was set using the ``MARK`` action in
663 a previously matched rule.
665 This item can only specified once as a match criteria as the ``MARK`` action can
666 only be specified once in a flow action.
668 Note the value of MARK field is arbitrary and application defined.
670 Depending on the underlying implementation the MARK item may be supported on
671 the physical device, with virtual groups in the PMD or not at all.
673 - Default ``mask`` matches any integer value.
675 .. _table_rte_flow_item_mark:
679 +----------+----------+---------------------------+
680 | Field | Subfield | Value |
681 +==========+==========+===========================+
682 | ``spec`` | ``id`` | integer value |
683 +----------+--------------------------------------+
684 | ``last`` | ``id`` | upper range value |
685 +----------+----------+---------------------------+
686 | ``mask`` | ``id`` | zeroed to match any value |
687 +----------+----------+---------------------------+
689 Data matching item types
690 ~~~~~~~~~~~~~~~~~~~~~~~~
692 Most of these are basically protocol header definitions with associated
693 bit-masks. They must be specified (stacked) from lowest to highest protocol
694 layer to form a matching pattern.
696 The following list is not exhaustive, new protocols will be added in the
702 Matches any protocol in place of the current layer, a single ANY may also
703 stand for several protocol layers.
705 This is usually specified as the first pattern item when looking for a
706 protocol anywhere in a packet.
708 - Default ``mask`` stands for any number of layers.
710 .. _table_rte_flow_item_any:
714 +----------+----------+--------------------------------------+
715 | Field | Subfield | Value |
716 +==========+==========+======================================+
717 | ``spec`` | ``num`` | number of layers covered |
718 +----------+----------+--------------------------------------+
719 | ``last`` | ``num`` | upper range value |
720 +----------+----------+--------------------------------------+
721 | ``mask`` | ``num`` | zeroed to cover any number of layers |
722 +----------+----------+--------------------------------------+
724 Example for VXLAN TCP payload matching regardless of outer L3 (IPv4 or IPv6)
725 and L4 (UDP) both matched by the first ANY specification, and inner L3 (IPv4
726 or IPv6) matched by the second ANY specification:
728 .. _table_rte_flow_item_any_example:
730 .. table:: TCP in VXLAN with wildcards
732 +-------+------+----------+----------+-------+
733 | Index | Item | Field | Subfield | Value |
734 +=======+======+==========+==========+=======+
736 +-------+------+----------+----------+-------+
737 | 1 | ANY | ``spec`` | ``num`` | 2 |
738 +-------+------+----------+----------+-------+
740 +-------+------------------------------------+
742 +-------+------+----------+----------+-------+
743 | 4 | ANY | ``spec`` | ``num`` | 1 |
744 +-------+------+----------+----------+-------+
746 +-------+------------------------------------+
748 +-------+------------------------------------+
753 Matches a byte string of a given length at a given offset.
755 Offset is either absolute (using the start of the packet) or relative to the
756 end of the previous matched item in the stack, in which case negative values
759 If search is enabled, offset is used as the starting point. The search area
760 can be delimited by setting limit to a nonzero value, which is the maximum
761 number of bytes after offset where the pattern may start.
763 Matching a zero-length pattern is allowed, doing so resets the relative
764 offset for subsequent items.
766 - This type does not support ranges (``last`` field).
767 - Default ``mask`` matches all fields exactly.
769 .. _table_rte_flow_item_raw:
773 +----------+--------------+-------------------------------------------------+
774 | Field | Subfield | Value |
775 +==========+==============+=================================================+
776 | ``spec`` | ``relative`` | look for pattern after the previous item |
777 | +--------------+-------------------------------------------------+
778 | | ``search`` | search pattern from offset (see also ``limit``) |
779 | +--------------+-------------------------------------------------+
780 | | ``reserved`` | reserved, must be set to zero |
781 | +--------------+-------------------------------------------------+
782 | | ``offset`` | absolute or relative offset for ``pattern`` |
783 | +--------------+-------------------------------------------------+
784 | | ``limit`` | search area limit for start of ``pattern`` |
785 | +--------------+-------------------------------------------------+
786 | | ``length`` | ``pattern`` length |
787 | +--------------+-------------------------------------------------+
788 | | ``pattern`` | byte string to look for |
789 +----------+--------------+-------------------------------------------------+
790 | ``last`` | if specified, either all 0 or with the same values as ``spec`` |
791 +----------+----------------------------------------------------------------+
792 | ``mask`` | bit-mask applied to ``spec`` values with usual behavior |
793 +----------+----------------------------------------------------------------+
795 Example pattern looking for several strings at various offsets of a UDP
796 payload, using combined RAW items:
798 .. _table_rte_flow_item_raw_example:
800 .. table:: UDP payload matching
802 +-------+------+----------+--------------+-------+
803 | Index | Item | Field | Subfield | Value |
804 +=======+======+==========+==============+=======+
806 +-------+----------------------------------------+
808 +-------+----------------------------------------+
810 +-------+------+----------+--------------+-------+
811 | 3 | RAW | ``spec`` | ``relative`` | 1 |
812 | | | +--------------+-------+
813 | | | | ``search`` | 1 |
814 | | | +--------------+-------+
815 | | | | ``offset`` | 10 |
816 | | | +--------------+-------+
817 | | | | ``limit`` | 0 |
818 | | | +--------------+-------+
819 | | | | ``length`` | 3 |
820 | | | +--------------+-------+
821 | | | | ``pattern`` | "foo" |
822 +-------+------+----------+--------------+-------+
823 | 4 | RAW | ``spec`` | ``relative`` | 1 |
824 | | | +--------------+-------+
825 | | | | ``search`` | 0 |
826 | | | +--------------+-------+
827 | | | | ``offset`` | 20 |
828 | | | +--------------+-------+
829 | | | | ``limit`` | 0 |
830 | | | +--------------+-------+
831 | | | | ``length`` | 3 |
832 | | | +--------------+-------+
833 | | | | ``pattern`` | "bar" |
834 +-------+------+----------+--------------+-------+
835 | 5 | RAW | ``spec`` | ``relative`` | 1 |
836 | | | +--------------+-------+
837 | | | | ``search`` | 0 |
838 | | | +--------------+-------+
839 | | | | ``offset`` | -29 |
840 | | | +--------------+-------+
841 | | | | ``limit`` | 0 |
842 | | | +--------------+-------+
843 | | | | ``length`` | 3 |
844 | | | +--------------+-------+
845 | | | | ``pattern`` | "baz" |
846 +-------+------+----------+--------------+-------+
848 +-------+----------------------------------------+
852 - Locate "foo" at least 10 bytes deep inside UDP payload.
853 - Locate "bar" after "foo" plus 20 bytes.
854 - Locate "baz" after "bar" minus 29 bytes.
856 Such a packet may be represented as follows (not to scale)::
859 | |<--------->| |<--------->|
861 |-----|------|-----|-----|-----|-----|-----------|-----|------|
862 | ETH | IPv4 | UDP | ... | baz | foo | ......... | bar | .... |
863 |-----|------|-----|-----|-----|-----|-----------|-----|------|
865 |<--------------------------->|
868 Note that matching subsequent pattern items would resume after "baz", not
869 "bar" since matching is always performed after the previous item of the
875 Matches an Ethernet header.
877 The ``type`` field either stands for "EtherType" or "TPID" when followed by
878 so-called layer 2.5 pattern items such as ``RTE_FLOW_ITEM_TYPE_VLAN``. In
879 the latter case, ``type`` refers to that of the outer header, with the inner
880 EtherType/TPID provided by the subsequent pattern item. This is the same
881 order as on the wire.
883 - ``dst``: destination MAC.
884 - ``src``: source MAC.
885 - ``type``: EtherType or TPID.
886 - Default ``mask`` matches destination and source addresses only.
891 Matches an 802.1Q/ad VLAN tag.
893 The corresponding standard outer EtherType (TPID) values are
894 ``ETHER_TYPE_VLAN`` or ``ETHER_TYPE_QINQ``. It can be overridden by the
895 preceding pattern item.
897 - ``tci``: tag control information.
898 - ``inner_type``: inner EtherType or TPID.
899 - Default ``mask`` matches the VID part of TCI only (lower 12 bits).
904 Matches an IPv4 header.
906 Note: IPv4 options are handled by dedicated pattern items.
908 - ``hdr``: IPv4 header definition (``rte_ip.h``).
909 - Default ``mask`` matches source and destination addresses only.
914 Matches an IPv6 header.
916 Note: IPv6 options are handled by dedicated pattern items, see `Item:
919 - ``hdr``: IPv6 header definition (``rte_ip.h``).
920 - Default ``mask`` matches source and destination addresses only.
925 Matches an ICMP header.
927 - ``hdr``: ICMP header definition (``rte_icmp.h``).
928 - Default ``mask`` matches ICMP type and code only.
933 Matches a UDP header.
935 - ``hdr``: UDP header definition (``rte_udp.h``).
936 - Default ``mask`` matches source and destination ports only.
941 Matches a TCP header.
943 - ``hdr``: TCP header definition (``rte_tcp.h``).
944 - Default ``mask`` matches source and destination ports only.
949 Matches a SCTP header.
951 - ``hdr``: SCTP header definition (``rte_sctp.h``).
952 - Default ``mask`` matches source and destination ports only.
957 Matches a VXLAN header (RFC 7348).
959 - ``flags``: normally 0x08 (I flag).
960 - ``rsvd0``: reserved, normally 0x000000.
961 - ``vni``: VXLAN network identifier.
962 - ``rsvd1``: reserved, normally 0x00.
963 - Default ``mask`` matches VNI only.
968 Matches an IEEE 802.1BR E-Tag header.
970 The corresponding standard outer EtherType (TPID) value is
971 ``ETHER_TYPE_ETAG``. It can be overridden by the preceding pattern item.
973 - ``epcp_edei_in_ecid_b``: E-Tag control information (E-TCI), E-PCP (3b),
974 E-DEI (1b), ingress E-CID base (12b).
975 - ``rsvd_grp_ecid_b``: reserved (2b), GRP (2b), E-CID base (12b).
976 - ``in_ecid_e``: ingress E-CID ext.
977 - ``ecid_e``: E-CID ext.
978 - ``inner_type``: inner EtherType or TPID.
979 - Default ``mask`` simultaneously matches GRP and E-CID base.
984 Matches a NVGRE header (RFC 7637).
986 - ``c_k_s_rsvd0_ver``: checksum (1b), undefined (1b), key bit (1b),
987 sequence number (1b), reserved 0 (9b), version (3b). This field must have
988 value 0x2000 according to RFC 7637.
989 - ``protocol``: protocol type (0x6558).
990 - ``tni``: virtual subnet ID.
991 - ``flow_id``: flow ID.
992 - Default ``mask`` matches TNI only.
997 Matches a MPLS header.
999 - ``label_tc_s_ttl``: label, TC, Bottom of Stack and TTL.
1000 - Default ``mask`` matches label only.
1005 Matches a GRE header.
1007 - ``c_rsvd0_ver``: checksum, reserved 0 and version.
1008 - ``protocol``: protocol type.
1009 - Default ``mask`` matches protocol only.
1014 Fuzzy pattern match, expect faster than default.
1016 This is for device that support fuzzy match option. Usually a fuzzy match is
1017 fast but the cost is accuracy. i.e. Signature Match only match pattern's hash
1018 value, but it is possible two different patterns have the same hash value.
1020 Matching accuracy level can be configured by threshold. Driver can divide the
1021 range of threshold and map to different accuracy levels that device support.
1023 Threshold 0 means perfect match (no fuzziness), while threshold 0xffffffff
1024 means fuzziest match.
1026 .. _table_rte_flow_item_fuzzy:
1030 +----------+---------------+--------------------------------------------------+
1031 | Field | Subfield | Value |
1032 +==========+===============+==================================================+
1033 | ``spec`` | ``threshold`` | 0 as perfect match, 0xffffffff as fuzziest match |
1034 +----------+---------------+--------------------------------------------------+
1035 | ``last`` | ``threshold`` | upper range value |
1036 +----------+---------------+--------------------------------------------------+
1037 | ``mask`` | ``threshold`` | bit-mask apply to "spec" and "last" |
1038 +----------+---------------+--------------------------------------------------+
1040 Usage example, fuzzy match a TCPv4 packets:
1042 .. _table_rte_flow_item_fuzzy_example:
1044 .. table:: Fuzzy matching
1046 +-------+----------+
1048 +=======+==========+
1050 +-------+----------+
1052 +-------+----------+
1054 +-------+----------+
1056 +-------+----------+
1058 +-------+----------+
1060 Item: ``GTP``, ``GTPC``, ``GTPU``
1061 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1063 Matches a GTPv1 header.
1065 Note: GTP, GTPC and GTPU use the same structure. GTPC and GTPU item
1066 are defined for a user-friendly API when creating GTP-C and GTP-U
1069 - ``v_pt_rsv_flags``: version (3b), protocol type (1b), reserved (1b),
1070 extension header flag (1b), sequence number flag (1b), N-PDU number
1072 - ``msg_type``: message type.
1073 - ``msg_len``: message length.
1074 - ``teid``: tunnel endpoint identifier.
1075 - Default ``mask`` matches teid only.
1080 Matches an ESP header.
1082 - ``hdr``: ESP header definition (``rte_esp.h``).
1083 - Default ``mask`` matches SPI only.
1088 Matches a GENEVE header.
1090 - ``ver_opt_len_o_c_rsvd0``: version (2b), length of the options fields (6b),
1091 OAM packet (1b), critical options present (1b), reserved 0 (6b).
1092 - ``protocol``: protocol type.
1093 - ``vni``: virtual network identifier.
1094 - ``rsvd1``: reserved, normally 0x00.
1095 - Default ``mask`` matches VNI only.
1100 Matches a VXLAN-GPE header (draft-ietf-nvo3-vxlan-gpe-05).
1102 - ``flags``: normally 0x0C (I and P flags).
1103 - ``rsvd0``: reserved, normally 0x0000.
1104 - ``protocol``: protocol type.
1105 - ``vni``: VXLAN network identifier.
1106 - ``rsvd1``: reserved, normally 0x00.
1107 - Default ``mask`` matches VNI only.
1109 Item: ``ARP_ETH_IPV4``
1110 ^^^^^^^^^^^^^^^^^^^^^^
1112 Matches an ARP header for Ethernet/IPv4.
1114 - ``hdr``: hardware type, normally 1.
1115 - ``pro``: protocol type, normally 0x0800.
1116 - ``hln``: hardware address length, normally 6.
1117 - ``pln``: protocol address length, normally 4.
1118 - ``op``: opcode (1 for request, 2 for reply).
1119 - ``sha``: sender hardware address.
1120 - ``spa``: sender IPv4 address.
1121 - ``tha``: target hardware address.
1122 - ``tpa``: target IPv4 address.
1123 - Default ``mask`` matches SHA, SPA, THA and TPA.
1128 Matches the presence of any IPv6 extension header.
1130 - ``next_hdr``: next header.
1131 - Default ``mask`` matches ``next_hdr``.
1133 Normally preceded by any of:
1141 Matches any ICMPv6 header.
1143 - ``type``: ICMPv6 type.
1144 - ``code``: ICMPv6 code.
1145 - ``checksum``: ICMPv6 checksum.
1146 - Default ``mask`` matches ``type`` and ``code``.
1148 Item: ``ICMP6_ND_NS``
1149 ^^^^^^^^^^^^^^^^^^^^^
1151 Matches an ICMPv6 neighbor discovery solicitation.
1153 - ``type``: ICMPv6 type, normally 135.
1154 - ``code``: ICMPv6 code, normally 0.
1155 - ``checksum``: ICMPv6 checksum.
1156 - ``reserved``: reserved, normally 0.
1157 - ``target_addr``: target address.
1158 - Default ``mask`` matches target address only.
1160 Item: ``ICMP6_ND_NA``
1161 ^^^^^^^^^^^^^^^^^^^^^
1163 Matches an ICMPv6 neighbor discovery advertisement.
1165 - ``type``: ICMPv6 type, normally 136.
1166 - ``code``: ICMPv6 code, normally 0.
1167 - ``checksum``: ICMPv6 checksum.
1168 - ``rso_reserved``: route flag (1b), solicited flag (1b), override flag
1169 (1b), reserved (29b).
1170 - ``target_addr``: target address.
1171 - Default ``mask`` matches target address only.
1173 Item: ``ICMP6_ND_OPT``
1174 ^^^^^^^^^^^^^^^^^^^^^^
1176 Matches the presence of any ICMPv6 neighbor discovery option.
1178 - ``type``: ND option type.
1179 - ``length``: ND option length.
1180 - Default ``mask`` matches type only.
1182 Normally preceded by any of:
1184 - `Item: ICMP6_ND_NA`_
1185 - `Item: ICMP6_ND_NS`_
1186 - `Item: ICMP6_ND_OPT`_
1188 Item: ``ICMP6_ND_OPT_SLA_ETH``
1189 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1191 Matches an ICMPv6 neighbor discovery source Ethernet link-layer address
1194 - ``type``: ND option type, normally 1.
1195 - ``length``: ND option length, normally 1.
1196 - ``sla``: source Ethernet LLA.
1197 - Default ``mask`` matches source link-layer address only.
1199 Normally preceded by any of:
1201 - `Item: ICMP6_ND_NA`_
1202 - `Item: ICMP6_ND_OPT`_
1204 Item: ``ICMP6_ND_OPT_TLA_ETH``
1205 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1207 Matches an ICMPv6 neighbor discovery target Ethernet link-layer address
1210 - ``type``: ND option type, normally 2.
1211 - ``length``: ND option length, normally 1.
1212 - ``tla``: target Ethernet LLA.
1213 - Default ``mask`` matches target link-layer address only.
1215 Normally preceded by any of:
1217 - `Item: ICMP6_ND_NS`_
1218 - `Item: ICMP6_ND_OPT`_
1223 Each possible action is represented by a type. Some have associated
1224 configuration structures. Several actions combined in a list can be assigned
1225 to a flow rule and are performed in order.
1227 They fall in three categories:
1229 - Actions that modify the fate of matching traffic, for instance by dropping
1230 or assigning it a specific destination.
1232 - Actions that modify matching traffic contents or its properties. This
1233 includes adding/removing encapsulation, encryption, compression and marks.
1235 - Actions related to the flow rule itself, such as updating counters or
1236 making it non-terminating.
1238 Flow rules being terminating by default, not specifying any action of the
1239 fate kind results in undefined behavior. This applies to both ingress and
1242 PASSTHRU, when supported, makes a flow rule non-terminating.
1244 Like matching patterns, action lists are terminated by END items.
1246 Example of action that redirects packets to queue index 10:
1248 .. _table_rte_flow_action_example:
1250 .. table:: Queue action
1252 +-----------+-------+
1254 +===========+=======+
1256 +-----------+-------+
1258 Actions are performed in list order:
1260 .. _table_rte_flow_count_then_drop:
1262 .. table:: Count then drop
1276 .. _table_rte_flow_mark_count_redirect:
1278 .. table:: Mark, count then redirect
1280 +-------+--------+------------+-------+
1281 | Index | Action | Field | Value |
1282 +=======+========+============+=======+
1283 | 0 | MARK | ``mark`` | 0x2a |
1284 +-------+--------+------------+-------+
1285 | 1 | COUNT | ``shared`` | 0 |
1286 | | +------------+-------+
1288 +-------+--------+------------+-------+
1289 | 2 | QUEUE | ``queue`` | 10 |
1290 +-------+--------+------------+-------+
1292 +-------+-----------------------------+
1296 .. _table_rte_flow_redirect_queue_5:
1298 .. table:: Redirect to queue 5
1300 +-------+--------+-----------+-------+
1301 | Index | Action | Field | Value |
1302 +=======+========+===========+=======+
1304 +-------+--------+-----------+-------+
1305 | 1 | QUEUE | ``queue`` | 5 |
1306 +-------+--------+-----------+-------+
1308 +-------+----------------------------+
1310 In the above example, while DROP and QUEUE must be performed in order, both
1311 have to happen before reaching END. Only QUEUE has a visible effect.
1313 Note that such a list may be thought as ambiguous and rejected on that
1316 .. _table_rte_flow_redirect_queue_5_3:
1318 .. table:: Redirect to queues 5 and 3
1320 +-------+--------+-----------+-------+
1321 | Index | Action | Field | Value |
1322 +=======+========+===========+=======+
1323 | 0 | QUEUE | ``queue`` | 5 |
1324 +-------+--------+-----------+-------+
1326 +-------+--------+-----------+-------+
1327 | 2 | QUEUE | ``queue`` | 3 |
1328 +-------+--------+-----------+-------+
1330 +-------+----------------------------+
1332 As previously described, all actions must be taken into account. This
1333 effectively duplicates traffic to both queues. The above example also shows
1334 that VOID is ignored.
1339 Common action types are described in this section. Like pattern item types,
1340 this list is not exhaustive as new actions will be added in the future.
1345 End marker for action lists. Prevents further processing of actions, thereby
1348 - Its numeric value is 0 for convenience.
1349 - PMD support is mandatory.
1350 - No configurable properties.
1352 .. _table_rte_flow_action_end:
1365 Used as a placeholder for convenience. It is ignored and simply discarded by
1368 - PMD support is mandatory.
1369 - No configurable properties.
1371 .. _table_rte_flow_action_void:
1381 Action: ``PASSTHRU``
1382 ^^^^^^^^^^^^^^^^^^^^
1384 Leaves traffic up for additional processing by subsequent flow rules; makes
1385 a flow rule non-terminating.
1387 - No configurable properties.
1389 .. _table_rte_flow_action_passthru:
1399 Example to copy a packet to a queue and continue processing by subsequent
1402 .. _table_rte_flow_action_passthru_example:
1404 .. table:: Copy to queue 8
1406 +-------+--------+-----------+-------+
1407 | Index | Action | Field | Value |
1408 +=======+========+===========+=======+
1410 +-------+--------+-----------+-------+
1411 | 1 | QUEUE | ``queue`` | 8 |
1412 +-------+--------+-----------+-------+
1414 +-------+----------------------------+
1419 Redirects packets to a group on the current device.
1421 In a hierarchy of groups, which can be used to represent physical or logical
1422 flow group/tables on the device, this action redirects the matched flow to
1423 the specified group on that device.
1425 If a matched flow is redirected to a table which doesn't contain a matching
1426 rule for that flow then the behavior is undefined and the resulting behavior
1427 is up to the specific device. Best practice when using groups would be define
1428 a default flow rule for each group which a defines the default actions in that
1429 group so a consistent behavior is defined.
1431 Defining an action for matched flow in a group to jump to a group which is
1432 higher in the group hierarchy may not be supported by physical devices,
1433 depending on how groups are mapped to the physical devices. In the
1434 definitions of jump actions, applications should be aware that it may be
1435 possible to define flow rules which trigger an undefined behavior causing
1436 flows to loop between groups.
1438 .. _table_rte_flow_action_jump:
1442 +-----------+------------------------------+
1444 +===========+==============================+
1445 | ``group`` | Group to redirect packets to |
1446 +-----------+------------------------------+
1451 Attaches an integer value to packets and sets ``PKT_RX_FDIR`` and
1452 ``PKT_RX_FDIR_ID`` mbuf flags.
1454 This value is arbitrary and application-defined. Maximum allowed value
1455 depends on the underlying implementation. It is returned in the
1456 ``hash.fdir.hi`` mbuf field.
1458 .. _table_rte_flow_action_mark:
1462 +--------+--------------------------------------+
1464 +========+======================================+
1465 | ``id`` | integer value to return with packets |
1466 +--------+--------------------------------------+
1471 Flags packets. Similar to `Action: MARK`_ without a specific value; only
1472 sets the ``PKT_RX_FDIR`` mbuf flag.
1474 - No configurable properties.
1476 .. _table_rte_flow_action_flag:
1489 Assigns packets to a given queue index.
1491 .. _table_rte_flow_action_queue:
1495 +-----------+--------------------+
1497 +===========+====================+
1498 | ``index`` | queue index to use |
1499 +-----------+--------------------+
1506 - No configurable properties.
1508 .. _table_rte_flow_action_drop:
1521 Adds a counter action to a matched flow.
1523 If more than one count action is specified in a single flow rule, then each
1524 action must specify a unique id.
1526 Counters can be retrieved and reset through ``rte_flow_query()``, see
1527 ``struct rte_flow_query_count``.
1529 The shared flag indicates whether the counter is unique to the flow rule the
1530 action is specified with, or whether it is a shared counter.
1532 For a count action with the shared flag set, then then a global device
1533 namespace is assumed for the counter id, so that any matched flow rules using
1534 a count action with the same counter id on the same port will contribute to
1537 For ports within the same switch domain then the counter id namespace extends
1538 to all ports within that switch domain.
1540 .. _table_rte_flow_action_count:
1544 +------------+---------------------+
1546 +============+=====================+
1547 | ``shared`` | shared counter flag |
1548 +------------+---------------------+
1549 | ``id`` | counter id |
1550 +------------+---------------------+
1552 Query structure to retrieve and reset flow rule counters:
1554 .. _table_rte_flow_query_count:
1556 .. table:: COUNT query
1558 +---------------+-----+-----------------------------------+
1559 | Field | I/O | Value |
1560 +===============+=====+===================================+
1561 | ``reset`` | in | reset counter after query |
1562 +---------------+-----+-----------------------------------+
1563 | ``hits_set`` | out | ``hits`` field is set |
1564 +---------------+-----+-----------------------------------+
1565 | ``bytes_set`` | out | ``bytes`` field is set |
1566 +---------------+-----+-----------------------------------+
1567 | ``hits`` | out | number of hits for this rule |
1568 +---------------+-----+-----------------------------------+
1569 | ``bytes`` | out | number of bytes through this rule |
1570 +---------------+-----+-----------------------------------+
1575 Similar to QUEUE, except RSS is additionally performed on packets to spread
1576 them among several queues according to the provided parameters.
1578 Unlike global RSS settings used by other DPDK APIs, unsetting the ``types``
1579 field does not disable RSS in a flow rule. Doing so instead requests safe
1580 unspecified "best-effort" settings from the underlying PMD, which depending
1581 on the flow rule, may result in anything ranging from empty (single queue)
1582 to all-inclusive RSS.
1584 Note: RSS hash result is stored in the ``hash.rss`` mbuf field which
1585 overlaps ``hash.fdir.lo``. Since `Action: MARK`_ sets the ``hash.fdir.hi``
1586 field only, both can be requested simultaneously.
1588 Also, regarding packet encapsulation ``level``:
1590 - ``0`` requests the default behavior. Depending on the packet type, it can
1591 mean outermost, innermost, anything in between or even no RSS.
1593 It basically stands for the innermost encapsulation level RSS can be
1594 performed on according to PMD and device capabilities.
1596 - ``1`` requests RSS to be performed on the outermost packet encapsulation
1599 - ``2`` and subsequent values request RSS to be performed on the specified
1600 inner packet encapsulation level, from outermost to innermost (lower to
1603 Values other than ``0`` are not necessarily supported.
1605 Requesting a specific RSS level on unrecognized traffic results in undefined
1606 behavior. For predictable results, it is recommended to make the flow rule
1607 pattern match packet headers up to the requested encapsulation level so that
1608 only matching traffic goes through.
1610 .. _table_rte_flow_action_rss:
1614 +---------------+---------------------------------------------+
1616 +===============+=============================================+
1617 | ``func`` | RSS hash function to apply |
1618 +---------------+---------------------------------------------+
1619 | ``level`` | encapsulation level for ``types`` |
1620 +---------------+---------------------------------------------+
1621 | ``types`` | specific RSS hash types (see ``ETH_RSS_*``) |
1622 +---------------+---------------------------------------------+
1623 | ``key_len`` | hash key length in bytes |
1624 +---------------+---------------------------------------------+
1625 | ``queue_num`` | number of entries in ``queue`` |
1626 +---------------+---------------------------------------------+
1627 | ``key`` | hash key |
1628 +---------------+---------------------------------------------+
1629 | ``queue`` | queue indices to use |
1630 +---------------+---------------------------------------------+
1635 Directs matching traffic to the physical function (PF) of the current
1640 - No configurable properties.
1642 .. _table_rte_flow_action_pf:
1655 Directs matching traffic to a given virtual function of the current device.
1657 Packets matched by a VF pattern item can be redirected to their original VF
1658 ID instead of the specified one. This parameter may not be available and is
1659 not guaranteed to work properly if the VF part is matched by a prior flow
1660 rule or if packets are not addressed to a VF in the first place.
1664 .. _table_rte_flow_action_vf:
1668 +--------------+--------------------------------+
1670 +==============+================================+
1671 | ``original`` | use original VF ID if possible |
1672 +--------------+--------------------------------+
1674 +--------------+--------------------------------+
1676 Action: ``PHY_PORT``
1677 ^^^^^^^^^^^^^^^^^^^^
1679 Directs matching traffic to a given physical port index of the underlying
1682 See `Item: PHY_PORT`_.
1684 .. _table_rte_flow_action_phy_port:
1688 +--------------+-------------------------------------+
1690 +==============+=====================================+
1691 | ``original`` | use original port index if possible |
1692 +--------------+-------------------------------------+
1693 | ``index`` | physical port index |
1694 +--------------+-------------------------------------+
1698 Directs matching traffic to a given DPDK port ID.
1700 See `Item: PORT_ID`_.
1702 .. _table_rte_flow_action_port_id:
1706 +--------------+---------------------------------------+
1708 +==============+=======================================+
1709 | ``original`` | use original DPDK port ID if possible |
1710 +--------------+---------------------------------------+
1711 | ``id`` | DPDK port ID |
1712 +--------------+---------------------------------------+
1717 Applies a stage of metering and policing.
1719 The metering and policing (MTR) object has to be first created using the
1720 rte_mtr_create() API function. The ID of the MTR object is specified as
1721 action parameter. More than one flow can use the same MTR object through
1722 the meter action. The MTR object can be further updated or queried using
1725 .. _table_rte_flow_action_meter:
1729 +--------------+---------------+
1731 +==============+===============+
1732 | ``mtr_id`` | MTR object ID |
1733 +--------------+---------------+
1735 Action: ``SECURITY``
1736 ^^^^^^^^^^^^^^^^^^^^
1738 Perform the security action on flows matched by the pattern items
1739 according to the configuration of the security session.
1741 This action modifies the payload of matched flows. For INLINE_CRYPTO, the
1742 security protocol headers and IV are fully provided by the application as
1743 specified in the flow pattern. The payload of matching packets is
1744 encrypted on egress, and decrypted and authenticated on ingress.
1745 For INLINE_PROTOCOL, the security protocol is fully offloaded to HW,
1746 providing full encapsulation and decapsulation of packets in security
1747 protocols. The flow pattern specifies both the outer security header fields
1748 and the inner packet fields. The security session specified in the action
1749 must match the pattern parameters.
1751 The security session specified in the action must be created on the same
1752 port as the flow action that is being specified.
1754 The ingress/egress flow attribute should match that specified in the
1755 security session if the security session supports the definition of the
1758 Multiple flows can be configured to use the same security session.
1760 .. _table_rte_flow_action_security:
1764 +----------------------+--------------------------------------+
1766 +======================+======================================+
1767 | ``security_session`` | security session to apply |
1768 +----------------------+--------------------------------------+
1770 The following is an example of configuring IPsec inline using the
1771 INLINE_CRYPTO security session:
1773 The encryption algorithm, keys and salt are part of the opaque
1774 ``rte_security_session``. The SA is identified according to the IP and ESP
1775 fields in the pattern items.
1777 .. _table_rte_flow_item_esp_inline_example:
1779 .. table:: IPsec inline crypto flow pattern items.
1781 +-------+----------+
1783 +=======+==========+
1785 +-------+----------+
1787 +-------+----------+
1789 +-------+----------+
1791 +-------+----------+
1793 .. _table_rte_flow_action_esp_inline_example:
1795 .. table:: IPsec inline flow actions.
1797 +-------+----------+
1799 +=======+==========+
1801 +-------+----------+
1803 +-------+----------+
1805 Action: ``OF_SET_MPLS_TTL``
1806 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1808 Implements ``OFPAT_SET_MPLS_TTL`` ("MPLS TTL") as defined by the `OpenFlow
1809 Switch Specification`_.
1811 .. _table_rte_flow_action_of_set_mpls_ttl:
1813 .. table:: OF_SET_MPLS_TTL
1815 +--------------+----------+
1817 +==============+==========+
1818 | ``mpls_ttl`` | MPLS TTL |
1819 +--------------+----------+
1821 Action: ``OF_DEC_MPLS_TTL``
1822 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1824 Implements ``OFPAT_DEC_MPLS_TTL`` ("decrement MPLS TTL") as defined by the
1825 `OpenFlow Switch Specification`_.
1827 .. _table_rte_flow_action_of_dec_mpls_ttl:
1829 .. table:: OF_DEC_MPLS_TTL
1837 Action: ``OF_SET_NW_TTL``
1838 ^^^^^^^^^^^^^^^^^^^^^^^^^
1840 Implements ``OFPAT_SET_NW_TTL`` ("IP TTL") as defined by the `OpenFlow
1841 Switch Specification`_.
1843 .. _table_rte_flow_action_of_set_nw_ttl:
1845 .. table:: OF_SET_NW_TTL
1847 +------------+--------+
1849 +============+========+
1850 | ``nw_ttl`` | IP TTL |
1851 +------------+--------+
1853 Action: ``OF_DEC_NW_TTL``
1854 ^^^^^^^^^^^^^^^^^^^^^^^^^
1856 Implements ``OFPAT_DEC_NW_TTL`` ("decrement IP TTL") as defined by the
1857 `OpenFlow Switch Specification`_.
1859 .. _table_rte_flow_action_of_dec_nw_ttl:
1861 .. table:: OF_DEC_NW_TTL
1869 Action: ``OF_COPY_TTL_OUT``
1870 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1872 Implements ``OFPAT_COPY_TTL_OUT`` ("copy TTL "outwards" -- from
1873 next-to-outermost to outermost") as defined by the `OpenFlow Switch
1876 .. _table_rte_flow_action_of_copy_ttl_out:
1878 .. table:: OF_COPY_TTL_OUT
1886 Action: ``OF_COPY_TTL_IN``
1887 ^^^^^^^^^^^^^^^^^^^^^^^^^^
1889 Implements ``OFPAT_COPY_TTL_IN`` ("copy TTL "inwards" -- from outermost to
1890 next-to-outermost") as defined by the `OpenFlow Switch Specification`_.
1892 .. _table_rte_flow_action_of_copy_ttl_in:
1894 .. table:: OF_COPY_TTL_IN
1902 Action: ``OF_POP_VLAN``
1903 ^^^^^^^^^^^^^^^^^^^^^^^
1905 Implements ``OFPAT_POP_VLAN`` ("pop the outer VLAN tag") as defined
1906 by the `OpenFlow Switch Specification`_.
1908 .. _table_rte_flow_action_of_pop_vlan:
1910 .. table:: OF_POP_VLAN
1918 Action: ``OF_PUSH_VLAN``
1919 ^^^^^^^^^^^^^^^^^^^^^^^^
1921 Implements ``OFPAT_PUSH_VLAN`` ("push a new VLAN tag") as defined by the
1922 `OpenFlow Switch Specification`_.
1924 .. _table_rte_flow_action_of_push_vlan:
1926 .. table:: OF_PUSH_VLAN
1928 +---------------+-----------+
1930 +===============+===========+
1931 | ``ethertype`` | EtherType |
1932 +---------------+-----------+
1934 Action: ``OF_SET_VLAN_VID``
1935 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1937 Implements ``OFPAT_SET_VLAN_VID`` ("set the 802.1q VLAN id") as defined by
1938 the `OpenFlow Switch Specification`_.
1940 .. _table_rte_flow_action_of_set_vlan_vid:
1942 .. table:: OF_SET_VLAN_VID
1944 +--------------+---------+
1946 +==============+=========+
1947 | ``vlan_vid`` | VLAN id |
1948 +--------------+---------+
1950 Action: ``OF_SET_VLAN_PCP``
1951 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1953 Implements ``OFPAT_SET_LAN_PCP`` ("set the 802.1q priority") as defined by
1954 the `OpenFlow Switch Specification`_.
1956 .. _table_rte_flow_action_of_set_vlan_pcp:
1958 .. table:: OF_SET_VLAN_PCP
1960 +--------------+---------------+
1962 +==============+===============+
1963 | ``vlan_pcp`` | VLAN priority |
1964 +--------------+---------------+
1966 Action: ``OF_POP_MPLS``
1967 ^^^^^^^^^^^^^^^^^^^^^^^
1969 Implements ``OFPAT_POP_MPLS`` ("pop the outer MPLS tag") as defined by the
1970 `OpenFlow Switch Specification`_.
1972 .. _table_rte_flow_action_of_pop_mpls:
1974 .. table:: OF_POP_MPLS
1976 +---------------+-----------+
1978 +===============+===========+
1979 | ``ethertype`` | EtherType |
1980 +---------------+-----------+
1982 Action: ``OF_PUSH_MPLS``
1983 ^^^^^^^^^^^^^^^^^^^^^^^^
1985 Implements ``OFPAT_PUSH_MPLS`` ("push a new MPLS tag") as defined by the
1986 `OpenFlow Switch Specification`_.
1988 .. _table_rte_flow_action_of_push_mpls:
1990 .. table:: OF_PUSH_MPLS
1992 +---------------+-----------+
1994 +===============+===========+
1995 | ``ethertype`` | EtherType |
1996 +---------------+-----------+
1998 Action: ``VXLAN_ENCAP``
1999 ^^^^^^^^^^^^^^^^^^^^^^^
2001 Performs a VXLAN encapsulation action by encapsulating the matched flow in the
2002 VXLAN tunnel as defined in the``rte_flow_action_vxlan_encap`` flow items
2005 This action modifies the payload of matched flows. The flow definition specified
2006 in the ``rte_flow_action_tunnel_encap`` action structure must define a valid
2007 VLXAN network overlay which conforms with RFC 7348 (Virtual eXtensible Local
2008 Area Network (VXLAN): A Framework for Overlaying Virtualized Layer 2 Networks
2009 over Layer 3 Networks). The pattern must be terminated with the
2010 RTE_FLOW_ITEM_TYPE_END item type.
2012 .. _table_rte_flow_action_vxlan_encap:
2014 .. table:: VXLAN_ENCAP
2016 +----------------+-------------------------------------+
2018 +================+=====================================+
2019 | ``definition`` | Tunnel end-point overlay definition |
2020 +----------------+-------------------------------------+
2022 .. _table_rte_flow_action_vxlan_encap_example:
2024 .. table:: IPv4 VxLAN flow pattern example.
2026 +-------+----------+
2028 +=======+==========+
2030 +-------+----------+
2032 +-------+----------+
2034 +-------+----------+
2036 +-------+----------+
2038 +-------+----------+
2040 Action: ``VXLAN_DECAP``
2041 ^^^^^^^^^^^^^^^^^^^^^^^
2043 Performs a decapsulation action by stripping all headers of the VXLAN tunnel
2044 network overlay from the matched flow.
2046 The flow items pattern defined for the flow rule with which a ``VXLAN_DECAP``
2047 action is specified, must define a valid VXLAN tunnel as per RFC7348. If the
2048 flow pattern does not specify a valid VXLAN tunnel then a
2049 RTE_FLOW_ERROR_TYPE_ACTION error should be returned.
2051 This action modifies the payload of matched flows.
2053 Action: ``NVGRE_ENCAP``
2054 ^^^^^^^^^^^^^^^^^^^^^^^
2056 Performs a NVGRE encapsulation action by encapsulating the matched flow in the
2057 NVGRE tunnel as defined in the``rte_flow_action_tunnel_encap`` flow item
2060 This action modifies the payload of matched flows. The flow definition specified
2061 in the ``rte_flow_action_tunnel_encap`` action structure must defined a valid
2062 NVGRE network overlay which conforms with RFC 7637 (NVGRE: Network
2063 Virtualization Using Generic Routing Encapsulation). The pattern must be
2064 terminated with the RTE_FLOW_ITEM_TYPE_END item type.
2066 .. _table_rte_flow_action_nvgre_encap:
2068 .. table:: NVGRE_ENCAP
2070 +----------------+-------------------------------------+
2072 +================+=====================================+
2073 | ``definition`` | NVGRE end-point overlay definition |
2074 +----------------+-------------------------------------+
2076 .. _table_rte_flow_action_nvgre_encap_example:
2078 .. table:: IPv4 NVGRE flow pattern example.
2080 +-------+----------+
2082 +=======+==========+
2084 +-------+----------+
2086 +-------+----------+
2088 +-------+----------+
2090 +-------+----------+
2092 Action: ``NVGRE_DECAP``
2093 ^^^^^^^^^^^^^^^^^^^^^^^
2095 Performs a decapsulation action by stripping all headers of the NVGRE tunnel
2096 network overlay from the matched flow.
2098 The flow items pattern defined for the flow rule with which a ``NVGRE_DECAP``
2099 action is specified, must define a valid NVGRE tunnel as per RFC7637. If the
2100 flow pattern does not specify a valid NVGRE tunnel then a
2101 RTE_FLOW_ERROR_TYPE_ACTION error should be returned.
2103 This action modifies the payload of matched flows.
2108 All specified pattern items (``enum rte_flow_item_type``) and actions
2109 (``enum rte_flow_action_type``) use positive identifiers.
2111 The negative space is reserved for dynamic types generated by PMDs during
2112 run-time. PMDs may encounter them as a result but must not accept negative
2113 identifiers they are not aware of.
2115 A method to generate them remains to be defined.
2120 Pattern item types will be added as new protocols are implemented.
2122 Variable headers support through dedicated pattern items, for example in
2123 order to match specific IPv4 options and IPv6 extension headers would be
2124 stacked after IPv4/IPv6 items.
2126 Other action types are planned but are not defined yet. These include the
2127 ability to alter packet data in several ways, such as performing
2128 encapsulation/decapsulation of tunnel headers.
2133 A rather simple API with few functions is provided to fully manage flow
2136 Each created flow rule is associated with an opaque, PMD-specific handle
2137 pointer. The application is responsible for keeping it until the rule is
2140 Flows rules are represented by ``struct rte_flow`` objects.
2145 Given that expressing a definite set of device capabilities is not
2146 practical, a dedicated function is provided to check if a flow rule is
2147 supported and can be created.
2152 rte_flow_validate(uint16_t port_id,
2153 const struct rte_flow_attr *attr,
2154 const struct rte_flow_item pattern[],
2155 const struct rte_flow_action actions[],
2156 struct rte_flow_error *error);
2158 The flow rule is validated for correctness and whether it could be accepted
2159 by the device given sufficient resources. The rule is checked against the
2160 current device mode and queue configuration. The flow rule may also
2161 optionally be validated against existing flow rules and device resources.
2162 This function has no effect on the target device.
2164 The returned value is guaranteed to remain valid only as long as no
2165 successful calls to ``rte_flow_create()`` or ``rte_flow_destroy()`` are made
2166 in the meantime and no device parameter affecting flow rules in any way are
2167 modified, due to possible collisions or resource limitations (although in
2168 such cases ``EINVAL`` should not be returned).
2172 - ``port_id``: port identifier of Ethernet device.
2173 - ``attr``: flow rule attributes.
2174 - ``pattern``: pattern specification (list terminated by the END pattern
2176 - ``actions``: associated actions (list terminated by the END action).
2177 - ``error``: perform verbose error reporting if not NULL. PMDs initialize
2178 this structure in case of error only.
2182 - 0 if flow rule is valid and can be created. A negative errno value
2183 otherwise (``rte_errno`` is also set), the following errors are defined.
2184 - ``-ENOSYS``: underlying device does not support this functionality.
2185 - ``-EINVAL``: unknown or invalid rule specification.
2186 - ``-ENOTSUP``: valid but unsupported rule specification (e.g. partial
2187 bit-masks are unsupported).
2188 - ``EEXIST``: collision with an existing rule. Only returned if device
2189 supports flow rule collision checking and there was a flow rule
2190 collision. Not receiving this return code is no guarantee that creating
2191 the rule will not fail due to a collision.
2192 - ``ENOMEM``: not enough memory to execute the function, or if the device
2193 supports resource validation, resource limitation on the device.
2194 - ``-EBUSY``: action cannot be performed due to busy device resources, may
2195 succeed if the affected queues or even the entire port are in a stopped
2196 state (see ``rte_eth_dev_rx_queue_stop()`` and ``rte_eth_dev_stop()``).
2201 Creating a flow rule is similar to validating one, except the rule is
2202 actually created and a handle returned.
2207 rte_flow_create(uint16_t port_id,
2208 const struct rte_flow_attr *attr,
2209 const struct rte_flow_item pattern[],
2210 const struct rte_flow_action *actions[],
2211 struct rte_flow_error *error);
2215 - ``port_id``: port identifier of Ethernet device.
2216 - ``attr``: flow rule attributes.
2217 - ``pattern``: pattern specification (list terminated by the END pattern
2219 - ``actions``: associated actions (list terminated by the END action).
2220 - ``error``: perform verbose error reporting if not NULL. PMDs initialize
2221 this structure in case of error only.
2225 A valid handle in case of success, NULL otherwise and ``rte_errno`` is set
2226 to the positive version of one of the error codes defined for
2227 ``rte_flow_validate()``.
2232 Flow rules destruction is not automatic, and a queue or a port should not be
2233 released if any are still attached to them. Applications must take care of
2234 performing this step before releasing resources.
2239 rte_flow_destroy(uint16_t port_id,
2240 struct rte_flow *flow,
2241 struct rte_flow_error *error);
2244 Failure to destroy a flow rule handle may occur when other flow rules depend
2245 on it, and destroying it would result in an inconsistent state.
2247 This function is only guaranteed to succeed if handles are destroyed in
2248 reverse order of their creation.
2252 - ``port_id``: port identifier of Ethernet device.
2253 - ``flow``: flow rule handle to destroy.
2254 - ``error``: perform verbose error reporting if not NULL. PMDs initialize
2255 this structure in case of error only.
2259 - 0 on success, a negative errno value otherwise and ``rte_errno`` is set.
2264 Convenience function to destroy all flow rule handles associated with a
2265 port. They are released as with successive calls to ``rte_flow_destroy()``.
2270 rte_flow_flush(uint16_t port_id,
2271 struct rte_flow_error *error);
2273 In the unlikely event of failure, handles are still considered destroyed and
2274 no longer valid but the port must be assumed to be in an inconsistent state.
2278 - ``port_id``: port identifier of Ethernet device.
2279 - ``error``: perform verbose error reporting if not NULL. PMDs initialize
2280 this structure in case of error only.
2284 - 0 on success, a negative errno value otherwise and ``rte_errno`` is set.
2289 Query an existing flow rule.
2291 This function allows retrieving flow-specific data such as counters. Data
2292 is gathered by special actions which must be present in the flow rule
2298 rte_flow_query(uint16_t port_id,
2299 struct rte_flow *flow,
2300 const struct rte_flow_action *action,
2302 struct rte_flow_error *error);
2306 - ``port_id``: port identifier of Ethernet device.
2307 - ``flow``: flow rule handle to query.
2308 - ``action``: action to query, this must match prototype from flow rule.
2309 - ``data``: pointer to storage for the associated query data type.
2310 - ``error``: perform verbose error reporting if not NULL. PMDs initialize
2311 this structure in case of error only.
2315 - 0 on success, a negative errno value otherwise and ``rte_errno`` is set.
2320 The general expectation for ingress traffic is that flow rules process it
2321 first; the remaining unmatched or pass-through traffic usually ends up in a
2322 queue (with or without RSS, locally or in some sub-device instance)
2323 depending on the global configuration settings of a port.
2325 While fine from a compatibility standpoint, this approach makes drivers more
2326 complex as they have to check for possible side effects outside of this API
2327 when creating or destroying flow rules. It results in a more limited set of
2328 available rule types due to the way device resources are assigned (e.g. no
2329 support for the RSS action even on capable hardware).
2331 Given that nonspecific traffic can be handled by flow rules as well,
2332 isolated mode is a means for applications to tell a driver that ingress on
2333 the underlying port must be injected from the defined flow rules only; that
2334 no default traffic is expected outside those rules.
2336 This has the following benefits:
2338 - Applications get finer-grained control over the kind of traffic they want
2339 to receive (no traffic by default).
2341 - More importantly they control at what point nonspecific traffic is handled
2342 relative to other flow rules, by adjusting priority levels.
2344 - Drivers can assign more hardware resources to flow rules and expand the
2345 set of supported rule types.
2347 Because toggling isolated mode may cause profound changes to the ingress
2348 processing path of a driver, it may not be possible to leave it once
2349 entered. Likewise, existing flow rules or global configuration settings may
2350 prevent a driver from entering isolated mode.
2352 Applications relying on this mode are therefore encouraged to toggle it as
2353 soon as possible after device initialization, ideally before the first call
2354 to ``rte_eth_dev_configure()`` to avoid possible failures due to conflicting
2357 Once effective, the following functionality has no effect on the underlying
2358 port and may return errors such as ``ENOTSUP`` ("not supported"):
2360 - Toggling promiscuous mode.
2361 - Toggling allmulticast mode.
2362 - Configuring MAC addresses.
2363 - Configuring multicast addresses.
2364 - Configuring VLAN filters.
2365 - Configuring Rx filters through the legacy API (e.g. FDIR).
2366 - Configuring global RSS settings.
2371 rte_flow_isolate(uint16_t port_id, int set, struct rte_flow_error *error);
2375 - ``port_id``: port identifier of Ethernet device.
2376 - ``set``: nonzero to enter isolated mode, attempt to leave it otherwise.
2377 - ``error``: perform verbose error reporting if not NULL. PMDs initialize
2378 this structure in case of error only.
2382 - 0 on success, a negative errno value otherwise and ``rte_errno`` is set.
2384 Verbose error reporting
2385 -----------------------
2387 The defined *errno* values may not be accurate enough for users or
2388 application developers who want to investigate issues related to flow rules
2389 management. A dedicated error object is defined for this purpose:
2393 enum rte_flow_error_type {
2394 RTE_FLOW_ERROR_TYPE_NONE, /**< No error. */
2395 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, /**< Cause unspecified. */
2396 RTE_FLOW_ERROR_TYPE_HANDLE, /**< Flow rule (handle). */
2397 RTE_FLOW_ERROR_TYPE_ATTR_GROUP, /**< Group field. */
2398 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY, /**< Priority field. */
2399 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS, /**< Ingress field. */
2400 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, /**< Egress field. */
2401 RTE_FLOW_ERROR_TYPE_ATTR, /**< Attributes structure. */
2402 RTE_FLOW_ERROR_TYPE_ITEM_NUM, /**< Pattern length. */
2403 RTE_FLOW_ERROR_TYPE_ITEM, /**< Specific pattern item. */
2404 RTE_FLOW_ERROR_TYPE_ACTION_NUM, /**< Number of actions. */
2405 RTE_FLOW_ERROR_TYPE_ACTION, /**< Specific action. */
2408 struct rte_flow_error {
2409 enum rte_flow_error_type type; /**< Cause field and error types. */
2410 const void *cause; /**< Object responsible for the error. */
2411 const char *message; /**< Human-readable error message. */
2414 Error type ``RTE_FLOW_ERROR_TYPE_NONE`` stands for no error, in which case
2415 remaining fields can be ignored. Other error types describe the type of the
2416 object pointed by ``cause``.
2418 If non-NULL, ``cause`` points to the object responsible for the error. For a
2419 flow rule, this may be a pattern item or an individual action.
2421 If non-NULL, ``message`` provides a human-readable error message.
2423 This object is normally allocated by applications and set by PMDs in case of
2424 error, the message points to a constant string which does not need to be
2425 freed by the application, however its pointer can be considered valid only
2426 as long as its associated DPDK port remains configured. Closing the
2427 underlying device or unloading the PMD invalidates it.
2438 rte_flow_error_set(struct rte_flow_error *error,
2440 enum rte_flow_error_type type,
2442 const char *message);
2444 This function initializes ``error`` (if non-NULL) with the provided
2445 parameters and sets ``rte_errno`` to ``code``. A negative error ``code`` is
2451 - DPDK does not keep track of flow rules definitions or flow rule objects
2452 automatically. Applications may keep track of the former and must keep
2453 track of the latter. PMDs may also do it for internal needs, however this
2454 must not be relied on by applications.
2456 - Flow rules are not maintained between successive port initializations. An
2457 application exiting without releasing them and restarting must re-create
2460 - API operations are synchronous and blocking (``EAGAIN`` cannot be
2463 - There is no provision for reentrancy/multi-thread safety, although nothing
2464 should prevent different devices from being configured at the same
2465 time. PMDs may protect their control path functions accordingly.
2467 - Stopping the data path (TX/RX) should not be necessary when managing flow
2468 rules. If this cannot be achieved naturally or with workarounds (such as
2469 temporarily replacing the burst function pointers), an appropriate error
2470 code must be returned (``EBUSY``).
2472 - PMDs, not applications, are responsible for maintaining flow rules
2473 configuration when stopping and restarting a port or performing other
2474 actions which may affect them. They can only be destroyed explicitly by
2477 For devices exposing multiple ports sharing global settings affected by flow
2480 - All ports under DPDK control must behave consistently, PMDs are
2481 responsible for making sure that existing flow rules on a port are not
2482 affected by other ports.
2484 - Ports not under DPDK control (unaffected or handled by other applications)
2485 are user's responsibility. They may affect existing flow rules and cause
2486 undefined behavior. PMDs aware of this may prevent flow rules creation
2487 altogether in such cases.
2492 The PMD interface is defined in ``rte_flow_driver.h``. It is not subject to
2493 API/ABI versioning constraints as it is not exposed to applications and may
2494 evolve independently.
2496 It is currently implemented on top of the legacy filtering framework through
2497 filter type *RTE_ETH_FILTER_GENERIC* that accepts the single operation
2498 *RTE_ETH_FILTER_GET* to return PMD-specific *rte_flow* callbacks wrapped
2499 inside ``struct rte_flow_ops``.
2501 This overhead is temporarily necessary in order to keep compatibility with
2502 the legacy filtering framework, which should eventually disappear.
2504 - PMD callbacks implement exactly the interface described in `Rules
2505 management`_, except for the port ID argument which has already been
2506 converted to a pointer to the underlying ``struct rte_eth_dev``.
2508 - Public API functions do not process flow rules definitions at all before
2509 calling PMD functions (no basic error checking, no validation
2510 whatsoever). They only make sure these callbacks are non-NULL or return
2511 the ``ENOSYS`` (function not supported) error.
2513 This interface additionally defines the following helper function:
2515 - ``rte_flow_ops_get()``: get generic flow operations structure from a
2518 More will be added over time.
2520 Device compatibility
2521 --------------------
2523 No known implementation supports all the described features.
2525 Unsupported features or combinations are not expected to be fully emulated
2526 in software by PMDs for performance reasons. Partially supported features
2527 may be completed in software as long as hardware performs most of the work
2528 (such as queue redirection and packet recognition).
2530 However PMDs are expected to do their best to satisfy application requests
2531 by working around hardware limitations as long as doing so does not affect
2532 the behavior of existing flow rules.
2534 The following sections provide a few examples of such cases and describe how
2535 PMDs should handle them, they are based on limitations built into the
2541 Each flow rule comes with its own, per-layer bit-masks, while hardware may
2542 support only a single, device-wide bit-mask for a given layer type, so that
2543 two IPv4 rules cannot use different bit-masks.
2545 The expected behavior in this case is that PMDs automatically configure
2546 global bit-masks according to the needs of the first flow rule created.
2548 Subsequent rules are allowed only if their bit-masks match those, the
2549 ``EEXIST`` error code should be returned otherwise.
2551 Unsupported layer types
2552 ~~~~~~~~~~~~~~~~~~~~~~~
2554 Many protocols can be simulated by crafting patterns with the `Item: RAW`_
2557 PMDs can rely on this capability to simulate support for protocols with
2558 headers not directly recognized by hardware.
2560 ``ANY`` pattern item
2561 ~~~~~~~~~~~~~~~~~~~~
2563 This pattern item stands for anything, which can be difficult to translate
2564 to something hardware would understand, particularly if followed by more
2567 Consider the following pattern:
2569 .. _table_rte_flow_unsupported_any:
2571 .. table:: Pattern with ANY as L3
2573 +-------+-----------------------+
2575 +=======+=======================+
2577 +-------+-----+---------+-------+
2578 | 1 | ANY | ``num`` | ``1`` |
2579 +-------+-----+---------+-------+
2581 +-------+-----------------------+
2583 +-------+-----------------------+
2585 Knowing that TCP does not make sense with something other than IPv4 and IPv6
2586 as L3, such a pattern may be translated to two flow rules instead:
2588 .. _table_rte_flow_unsupported_any_ipv4:
2590 .. table:: ANY replaced with IPV4
2592 +-------+--------------------+
2594 +=======+====================+
2596 +-------+--------------------+
2597 | 1 | IPV4 (zeroed mask) |
2598 +-------+--------------------+
2600 +-------+--------------------+
2602 +-------+--------------------+
2606 .. _table_rte_flow_unsupported_any_ipv6:
2608 .. table:: ANY replaced with IPV6
2610 +-------+--------------------+
2612 +=======+====================+
2614 +-------+--------------------+
2615 | 1 | IPV6 (zeroed mask) |
2616 +-------+--------------------+
2618 +-------+--------------------+
2620 +-------+--------------------+
2622 Note that as soon as a ANY rule covers several layers, this approach may
2623 yield a large number of hidden flow rules. It is thus suggested to only
2624 support the most common scenarios (anything as L2 and/or L3).
2629 - When combined with `Action: QUEUE`_, packet counting (`Action: COUNT`_)
2630 and tagging (`Action: MARK`_ or `Action: FLAG`_) may be implemented in
2631 software as long as the target queue is used by a single rule.
2633 - When a single target queue is provided, `Action: RSS`_ can also be
2634 implemented through `Action: QUEUE`_.
2639 While it would naturally make sense, flow rules cannot be assumed to be
2640 processed by hardware in the same order as their creation for several
2643 - They may be managed internally as a tree or a hash table instead of a
2645 - Removing a flow rule before adding another one can either put the new rule
2646 at the end of the list or reuse a freed entry.
2647 - Duplication may occur when packets are matched by several rules.
2649 For overlapping rules (particularly in order to use `Action: PASSTHRU`_)
2650 predictable behavior is only guaranteed by using different priority levels.
2652 Priority levels are not necessarily implemented in hardware, or may be
2653 severely limited (e.g. a single priority bit).
2655 For these reasons, priority levels may be implemented purely in software by
2658 - For devices expecting flow rules to be added in the correct order, PMDs
2659 may destroy and re-create existing rules after adding a new one with
2662 - A configurable number of dummy or empty rules can be created at
2663 initialization time to save high priority slots for later.
2665 - In order to save priority levels, PMDs may evaluate whether rules are
2666 likely to collide and adjust their priority accordingly.
2671 - A device profile selection function which could be used to force a
2672 permanent profile instead of relying on its automatic configuration based
2673 on existing flow rules.
2675 - A method to optimize *rte_flow* rules with specific pattern items and
2676 action types generated on the fly by PMDs. DPDK should assign negative
2677 numbers to these in order to not collide with the existing types. See
2680 - Adding specific egress pattern items and actions as described in
2681 `Attribute: Traffic direction`_.
2683 - Optional software fallback when PMDs are unable to handle requested flow
2684 rules so applications do not have to implement their own.
2686 .. _OpenFlow Switch Specification: https://www.opennetworking.org/software-defined-standards/specifications/