1 .. SPDX-License-Identifier: BSD-3-Clause
2 Copyright 2016 6WIND S.A.
3 Copyright 2016 Mellanox Technologies, Ltd
5 Generic flow API (rte_flow)
6 ===========================
11 This API provides a generic means to configure hardware to match specific
12 ingress or egress traffic, alter its fate and query related counters
13 according to any number of user-defined rules.
15 It is named *rte_flow* after the prefix used for all its symbols, and is
16 defined in ``rte_flow.h``.
18 - Matching can be performed on packet data (protocol headers, payload) and
19 properties (e.g. associated physical port, virtual device function ID).
21 - Possible operations include dropping traffic, diverting it to specific
22 queues, to virtual/physical device functions or ports, performing tunnel
23 offloads, adding marks and so on.
31 A flow rule is the combination of attributes with a matching pattern and a
32 list of actions. Flow rules form the basis of this API.
34 Flow rules can have several distinct actions (such as counting,
35 encapsulating, decapsulating before redirecting packets to a particular
36 queue, etc.), instead of relying on several rules to achieve this and having
37 applications deal with hardware implementation details regarding their
40 Support for different priority levels on a rule basis is provided, for
41 example in order to force a more specific rule to come before a more generic
42 one for packets matched by both. However hardware support for more than a
43 single priority level cannot be guaranteed. When supported, the number of
44 available priority levels is usually low, which is why they can also be
45 implemented in software by PMDs (e.g. missing priority levels may be
46 emulated by reordering rules).
48 In order to remain as hardware-agnostic as possible, by default all rules
49 are considered to have the same priority, which means that the order between
50 overlapping rules (when a packet is matched by several filters) is
53 PMDs may refuse to create overlapping rules at a given priority level when
54 they can be detected (e.g. if a pattern matches an existing filter).
56 Thus predictable results for a given priority level can only be achieved
57 with non-overlapping rules, using perfect matching on all protocol layers.
59 Flow rules can also be grouped, the flow rule priority is specific to the
60 group they belong to. All flow rules in a given group are thus processed within
61 the context of that group. Groups are not linked by default, so the logical
62 hierarchy of groups must be explicitly defined by flow rules themselves in each
63 group using the JUMP action to define the next group to redirect too. Only flow
64 rules defined in the default group 0 are guarantee to be matched against, this
65 makes group 0 the origin of any group hierarchy defined by an application.
67 Support for multiple actions per rule may be implemented internally on top
68 of non-default hardware priorities, as a result both features may not be
69 simultaneously available to applications.
71 Considering that allowed pattern/actions combinations cannot be known in
72 advance and would result in an impractically large number of capabilities to
73 expose, a method is provided to validate a given rule from the current
74 device configuration state.
76 This enables applications to check if the rule types they need is supported
77 at initialization time, before starting their data path. This method can be
78 used anytime, its only requirement being that the resources needed by a rule
79 should exist (e.g. a target RX queue should be configured first).
81 Each defined rule is associated with an opaque handle managed by the PMD,
82 applications are responsible for keeping it. These can be used for queries
83 and rules management, such as retrieving counters or other data and
86 To avoid resource leaks on the PMD side, handles must be explicitly
87 destroyed by the application before releasing associated resources such as
90 The following sections cover:
92 - **Attributes** (represented by ``struct rte_flow_attr``): properties of a
93 flow rule such as its direction (ingress or egress) and priority.
95 - **Pattern item** (represented by ``struct rte_flow_item``): part of a
96 matching pattern that either matches specific packet data or traffic
97 properties. It can also describe properties of the pattern itself, such as
100 - **Matching pattern**: traffic properties to look for, a combination of any
103 - **Actions** (represented by ``struct rte_flow_action``): operations to
104 perform whenever a packet is matched by a pattern.
112 Flow rules can be grouped by assigning them a common group number. Groups
113 allow a logical hierarchy of flow rule groups (tables) to be defined. These
114 groups can be supported virtually in the PMD or in the physical device.
115 Group 0 is the default group and this is the only group which flows are
116 guarantee to matched against, all subsequent groups can only be reached by
117 way of the JUMP action from a matched flow rule.
119 Although optional, applications are encouraged to group similar rules as
120 much as possible to fully take advantage of hardware capabilities
121 (e.g. optimized matching) and work around limitations (e.g. a single pattern
122 type possibly allowed in a given group), while being aware that the groups
123 hierarchies must be programmed explicitly.
125 Note that support for more than a single group is not guaranteed.
130 A priority level can be assigned to a flow rule, lower values
131 denote higher priority, with 0 as the maximum.
133 Priority levels are arbitrary and up to the application, they do
134 not need to be contiguous nor start from 0, however the maximum number
135 varies between devices and may be affected by existing flow rules.
137 A flow which matches multiple rules in the same group will always matched by
138 the rule with the highest priority in that group.
140 If a packet is matched by several rules of a given group for a given
141 priority level, the outcome is undefined. It can take any path, may be
142 duplicated or even cause unrecoverable errors.
144 Note that support for more than a single priority level is not guaranteed.
146 Attribute: Traffic direction
147 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
149 Flow rule patterns apply to inbound and/or outbound traffic.
151 In the context of this API, **ingress** and **egress** respectively stand
152 for **inbound** and **outbound** based on the standpoint of the application
153 creating a flow rule.
155 There are no exceptions to this definition.
157 Several pattern items and actions are valid and can be used in both
158 directions. At least one direction must be specified.
160 Specifying both directions at once for a given rule is not recommended but
161 may be valid in a few cases.
166 Instead of simply matching the properties of traffic as it would appear on a
167 given DPDK port ID, enabling this attribute transfers a flow rule to the
168 lowest possible level of any device endpoints found in the pattern.
170 When supported, this effectively enables an application to reroute traffic
171 not necessarily intended for it (e.g. coming from or addressed to different
172 physical ports, VFs or applications) at the device level.
174 It complements the behavior of some pattern items such as `Item: PHY_PORT`_
175 and is meaningless without them.
177 When transferring flow rules, **ingress** and **egress** attributes
178 (`Attribute: Traffic direction`_) keep their original meaning, as if
179 processing traffic emitted or received by the application.
184 Pattern items fall in two categories:
186 - Matching protocol headers and packet data, usually associated with a
187 specification structure. These must be stacked in the same order as the
188 protocol layers to match inside packets, starting from the lowest.
190 - Matching meta-data or affecting pattern processing, often without a
191 specification structure. Since they do not match packet contents, their
192 position in the list is usually not relevant.
194 Item specification structures are used to match specific values among
195 protocol fields (or item properties). Documentation describes for each item
196 whether they are associated with one and their type name if so.
198 Up to three structures of the same type can be set for a given item:
200 - ``spec``: values to match (e.g. a given IPv4 address).
202 - ``last``: upper bound for an inclusive range with corresponding fields in
205 - ``mask``: bit-mask applied to both ``spec`` and ``last`` whose purpose is
206 to distinguish the values to take into account and/or partially mask them
207 out (e.g. in order to match an IPv4 address prefix).
209 Usage restrictions and expected behavior:
211 - Setting either ``mask`` or ``last`` without ``spec`` is an error.
213 - Field values in ``last`` which are either 0 or equal to the corresponding
214 values in ``spec`` are ignored; they do not generate a range. Nonzero
215 values lower than those in ``spec`` are not supported.
217 - Setting ``spec`` and optionally ``last`` without ``mask`` causes the PMD
218 to use the default mask defined for that item (defined as
219 ``rte_flow_item_{name}_mask`` constants).
221 - Not setting any of them (assuming item type allows it) is equivalent to
222 providing an empty (zeroed) ``mask`` for broad (nonspecific) matching.
224 - ``mask`` is a simple bit-mask applied before interpreting the contents of
225 ``spec`` and ``last``, which may yield unexpected results if not used
226 carefully. For example, if for an IPv4 address field, ``spec`` provides
227 *10.1.2.3*, ``last`` provides *10.3.4.5* and ``mask`` provides
228 *255.255.0.0*, the effective range becomes *10.1.0.0* to *10.3.255.255*.
230 Example of an item specification matching an Ethernet header:
232 .. _table_rte_flow_pattern_item_example:
234 .. table:: Ethernet item
236 +----------+----------+-----------------------+
237 | Field | Subfield | Value |
238 +==========+==========+=======================+
239 | ``spec`` | ``src`` | ``00:00:01:02:03:04`` |
240 | +----------+-----------------------+
241 | | ``dst`` | ``00:00:2a:66:00:01`` |
242 | +----------+-----------------------+
243 | | ``type`` | ``0x22aa`` |
244 +----------+----------+-----------------------+
245 | ``last`` | unspecified |
246 +----------+----------+-----------------------+
247 | ``mask`` | ``src`` | ``00:00:ff:ff:ff:00`` |
248 | +----------+-----------------------+
249 | | ``dst`` | ``00:00:00:00:00:ff`` |
250 | +----------+-----------------------+
251 | | ``type`` | ``0x0000`` |
252 +----------+----------+-----------------------+
254 Non-masked bits stand for any value (shown as ``?`` below), Ethernet headers
255 with the following properties are thus matched:
257 - ``src``: ``??:??:01:02:03:??``
258 - ``dst``: ``??:??:??:??:??:01``
259 - ``type``: ``0x????``
264 A pattern is formed by stacking items starting from the lowest protocol
265 layer to match. This stacking restriction does not apply to meta items which
266 can be placed anywhere in the stack without affecting the meaning of the
269 Patterns are terminated by END items.
273 .. _table_rte_flow_tcpv4_as_l4:
275 .. table:: TCPv4 as L4
291 .. _table_rte_flow_tcpv6_in_vxlan:
293 .. table:: TCPv6 in VXLAN
295 +-------+------------+
297 +=======+============+
299 +-------+------------+
301 +-------+------------+
303 +-------+------------+
305 +-------+------------+
307 +-------+------------+
309 +-------+------------+
311 +-------+------------+
313 +-------+------------+
317 .. _table_rte_flow_tcpv4_as_l4_meta:
319 .. table:: TCPv4 as L4 with meta items
341 The above example shows how meta items do not affect packet data matching
342 items, as long as those remain stacked properly. The resulting matching
343 pattern is identical to "TCPv4 as L4".
345 .. _table_rte_flow_udpv6_anywhere:
347 .. table:: UDPv6 anywhere
359 If supported by the PMD, omitting one or several protocol layers at the
360 bottom of the stack as in the above example (missing an Ethernet
361 specification) enables looking up anywhere in packets.
363 It is unspecified whether the payload of supported encapsulations
364 (e.g. VXLAN payload) is matched by such a pattern, which may apply to inner,
365 outer or both packets.
367 .. _table_rte_flow_invalid_l3:
369 .. table:: Invalid, missing L3
381 The above pattern is invalid due to a missing L3 specification between L2
382 (Ethernet) and L4 (UDP). Doing so is only allowed at the bottom and at the
388 They match meta-data or affect pattern processing instead of matching packet
389 data directly, most of them do not need a specification structure. This
390 particularity allows them to be specified anywhere in the stack without
391 causing any side effect.
396 End marker for item lists. Prevents further processing of items, thereby
399 - Its numeric value is 0 for convenience.
400 - PMD support is mandatory.
401 - ``spec``, ``last`` and ``mask`` are ignored.
403 .. _table_rte_flow_item_end:
407 +----------+---------+
409 +==========+=========+
410 | ``spec`` | ignored |
411 +----------+---------+
412 | ``last`` | ignored |
413 +----------+---------+
414 | ``mask`` | ignored |
415 +----------+---------+
420 Used as a placeholder for convenience. It is ignored and simply discarded by
423 - PMD support is mandatory.
424 - ``spec``, ``last`` and ``mask`` are ignored.
426 .. _table_rte_flow_item_void:
430 +----------+---------+
432 +==========+=========+
433 | ``spec`` | ignored |
434 +----------+---------+
435 | ``last`` | ignored |
436 +----------+---------+
437 | ``mask`` | ignored |
438 +----------+---------+
440 One usage example for this type is generating rules that share a common
441 prefix quickly without reallocating memory, only by updating item types:
443 .. _table_rte_flow_item_void_example:
445 .. table:: TCP, UDP or ICMP as L4
447 +-------+--------------------+
449 +=======+====================+
451 +-------+--------------------+
453 +-------+------+------+------+
454 | 2 | UDP | VOID | VOID |
455 +-------+------+------+------+
456 | 3 | VOID | TCP | VOID |
457 +-------+------+------+------+
458 | 4 | VOID | VOID | ICMP |
459 +-------+------+------+------+
461 +-------+--------------------+
466 Inverted matching, i.e. process packets that do not match the pattern.
468 - ``spec``, ``last`` and ``mask`` are ignored.
470 .. _table_rte_flow_item_invert:
474 +----------+---------+
476 +==========+=========+
477 | ``spec`` | ignored |
478 +----------+---------+
479 | ``last`` | ignored |
480 +----------+---------+
481 | ``mask`` | ignored |
482 +----------+---------+
484 Usage example, matching non-TCPv4 packets only:
486 .. _table_rte_flow_item_invert_example:
488 .. table:: Anything but TCPv4
507 Matches traffic originating from (ingress) or going to (egress) the physical
508 function of the current device.
510 If supported, should work even if the physical function is not managed by
511 the application and thus not associated with a DPDK port ID.
513 - Can be combined with any number of `Item: VF`_ to match both PF and VF
515 - ``spec``, ``last`` and ``mask`` must not be set.
517 .. _table_rte_flow_item_pf:
534 Matches traffic originating from (ingress) or going to (egress) a given
535 virtual function of the current device.
537 If supported, should work even if the virtual function is not managed by the
538 application and thus not associated with a DPDK port ID.
540 Note this pattern item does not match VF representors traffic which, as
541 separate entities, should be addressed through their own DPDK port IDs.
543 - Can be specified multiple times to match traffic addressed to several VF
545 - Can be combined with a PF item to match both PF and VF traffic.
546 - Default ``mask`` matches any VF ID.
548 .. _table_rte_flow_item_vf:
552 +----------+----------+---------------------------+
553 | Field | Subfield | Value |
554 +==========+==========+===========================+
555 | ``spec`` | ``id`` | destination VF ID |
556 +----------+----------+---------------------------+
557 | ``last`` | ``id`` | upper range value |
558 +----------+----------+---------------------------+
559 | ``mask`` | ``id`` | zeroed to match any VF ID |
560 +----------+----------+---------------------------+
565 Matches traffic originating from (ingress) or going to (egress) a physical
566 port of the underlying device.
568 The first PHY_PORT item overrides the physical port normally associated with
569 the specified DPDK input port (port_id). This item can be provided several
570 times to match additional physical ports.
572 Note that physical ports are not necessarily tied to DPDK input ports
573 (port_id) when those are not under DPDK control. Possible values are
574 specific to each device, they are not necessarily indexed from zero and may
577 As a device property, the list of allowed values as well as the value
578 associated with a port_id should be retrieved by other means.
580 - Default ``mask`` matches any port index.
582 .. _table_rte_flow_item_phy_port:
586 +----------+-----------+--------------------------------+
587 | Field | Subfield | Value |
588 +==========+===========+================================+
589 | ``spec`` | ``index`` | physical port index |
590 +----------+-----------+--------------------------------+
591 | ``last`` | ``index`` | upper range value |
592 +----------+-----------+--------------------------------+
593 | ``mask`` | ``index`` | zeroed to match any port index |
594 +----------+-----------+--------------------------------+
599 Matches traffic originating from (ingress) or going to (egress) a given DPDK
602 Normally only supported if the port ID in question is known by the
603 underlying PMD and related to the device the flow rule is created against.
605 This must not be confused with `Item: PHY_PORT`_ which refers to the
606 physical port of a device, whereas `Item: PORT_ID`_ refers to a ``struct
607 rte_eth_dev`` object on the application side (also known as "port
608 representor" depending on the kind of underlying device).
610 - Default ``mask`` matches the specified DPDK port ID.
612 .. _table_rte_flow_item_port_id:
616 +----------+----------+-----------------------------+
617 | Field | Subfield | Value |
618 +==========+==========+=============================+
619 | ``spec`` | ``id`` | DPDK port ID |
620 +----------+----------+-----------------------------+
621 | ``last`` | ``id`` | upper range value |
622 +----------+----------+-----------------------------+
623 | ``mask`` | ``id`` | zeroed to match any port ID |
624 +----------+----------+-----------------------------+
629 Matches an arbitrary integer value which was set using the ``MARK`` action in
630 a previously matched rule.
632 This item can only specified once as a match criteria as the ``MARK`` action can
633 only be specified once in a flow action.
635 Note the value of MARK field is arbitrary and application defined.
637 Depending on the underlying implementation the MARK item may be supported on
638 the physical device, with virtual groups in the PMD or not at all.
640 - Default ``mask`` matches any integer value.
642 .. _table_rte_flow_item_mark:
646 +----------+----------+---------------------------+
647 | Field | Subfield | Value |
648 +==========+==========+===========================+
649 | ``spec`` | ``id`` | integer value |
650 +----------+--------------------------------------+
651 | ``last`` | ``id`` | upper range value |
652 +----------+----------+---------------------------+
653 | ``mask`` | ``id`` | zeroed to match any value |
654 +----------+----------+---------------------------+
659 Matches tag item set by other flows. Multiple tags are supported by specifying
662 - Default ``mask`` matches the specified tag value and index.
664 .. _table_rte_flow_item_tag:
668 +----------+----------+----------------------------------------+
669 | Field | Subfield | Value |
670 +==========+===========+=======================================+
671 | ``spec`` | ``data`` | 32 bit flow tag value |
672 | +-----------+---------------------------------------+
673 | | ``index`` | index of flow tag |
674 +----------+-----------+---------------------------------------+
675 | ``last`` | ``data`` | upper range value |
676 | +-----------+---------------------------------------+
677 | | ``index`` | field is ignored |
678 +----------+-----------+---------------------------------------+
679 | ``mask`` | ``data`` | bit-mask applies to "spec" and "last" |
680 | +-----------+---------------------------------------+
681 | | ``index`` | field is ignored |
682 +----------+-----------+---------------------------------------+
687 Matches 32 bit metadata item set.
689 On egress, metadata can be set either by mbuf metadata field with
690 PKT_TX_DYNF_METADATA flag or ``SET_META`` action. On ingress, ``SET_META``
691 action sets metadata for a packet and the metadata will be reported via
692 ``metadata`` dynamic field of ``rte_mbuf`` with PKT_RX_DYNF_METADATA flag.
694 - Default ``mask`` matches the specified Rx metadata value.
696 .. _table_rte_flow_item_meta:
700 +----------+----------+---------------------------------------+
701 | Field | Subfield | Value |
702 +==========+==========+=======================================+
703 | ``spec`` | ``data`` | 32 bit metadata value |
704 +----------+----------+---------------------------------------+
705 | ``last`` | ``data`` | upper range value |
706 +----------+----------+---------------------------------------+
707 | ``mask`` | ``data`` | bit-mask applies to "spec" and "last" |
708 +----------+----------+---------------------------------------+
710 Data matching item types
711 ~~~~~~~~~~~~~~~~~~~~~~~~
713 Most of these are basically protocol header definitions with associated
714 bit-masks. They must be specified (stacked) from lowest to highest protocol
715 layer to form a matching pattern.
720 Matches any protocol in place of the current layer, a single ANY may also
721 stand for several protocol layers.
723 This is usually specified as the first pattern item when looking for a
724 protocol anywhere in a packet.
726 - Default ``mask`` stands for any number of layers.
728 .. _table_rte_flow_item_any:
732 +----------+----------+--------------------------------------+
733 | Field | Subfield | Value |
734 +==========+==========+======================================+
735 | ``spec`` | ``num`` | number of layers covered |
736 +----------+----------+--------------------------------------+
737 | ``last`` | ``num`` | upper range value |
738 +----------+----------+--------------------------------------+
739 | ``mask`` | ``num`` | zeroed to cover any number of layers |
740 +----------+----------+--------------------------------------+
742 Example for VXLAN TCP payload matching regardless of outer L3 (IPv4 or IPv6)
743 and L4 (UDP) both matched by the first ANY specification, and inner L3 (IPv4
744 or IPv6) matched by the second ANY specification:
746 .. _table_rte_flow_item_any_example:
748 .. table:: TCP in VXLAN with wildcards
750 +-------+------+----------+----------+-------+
751 | Index | Item | Field | Subfield | Value |
752 +=======+======+==========+==========+=======+
754 +-------+------+----------+----------+-------+
755 | 1 | ANY | ``spec`` | ``num`` | 2 |
756 +-------+------+----------+----------+-------+
758 +-------+------------------------------------+
760 +-------+------+----------+----------+-------+
761 | 4 | ANY | ``spec`` | ``num`` | 1 |
762 +-------+------+----------+----------+-------+
764 +-------+------------------------------------+
766 +-------+------------------------------------+
771 Matches a byte string of a given length at a given offset.
773 Offset is either absolute (using the start of the packet) or relative to the
774 end of the previous matched item in the stack, in which case negative values
777 If search is enabled, offset is used as the starting point. The search area
778 can be delimited by setting limit to a nonzero value, which is the maximum
779 number of bytes after offset where the pattern may start.
781 Matching a zero-length pattern is allowed, doing so resets the relative
782 offset for subsequent items.
784 - This type does not support ranges (``last`` field).
785 - Default ``mask`` matches all fields exactly.
787 .. _table_rte_flow_item_raw:
791 +----------+--------------+-------------------------------------------------+
792 | Field | Subfield | Value |
793 +==========+==============+=================================================+
794 | ``spec`` | ``relative`` | look for pattern after the previous item |
795 | +--------------+-------------------------------------------------+
796 | | ``search`` | search pattern from offset (see also ``limit``) |
797 | +--------------+-------------------------------------------------+
798 | | ``reserved`` | reserved, must be set to zero |
799 | +--------------+-------------------------------------------------+
800 | | ``offset`` | absolute or relative offset for ``pattern`` |
801 | +--------------+-------------------------------------------------+
802 | | ``limit`` | search area limit for start of ``pattern`` |
803 | +--------------+-------------------------------------------------+
804 | | ``length`` | ``pattern`` length |
805 | +--------------+-------------------------------------------------+
806 | | ``pattern`` | byte string to look for |
807 +----------+--------------+-------------------------------------------------+
808 | ``last`` | if specified, either all 0 or with the same values as ``spec`` |
809 +----------+----------------------------------------------------------------+
810 | ``mask`` | bit-mask applied to ``spec`` values with usual behavior |
811 +----------+----------------------------------------------------------------+
813 Example pattern looking for several strings at various offsets of a UDP
814 payload, using combined RAW items:
816 .. _table_rte_flow_item_raw_example:
818 .. table:: UDP payload matching
820 +-------+------+----------+--------------+-------+
821 | Index | Item | Field | Subfield | Value |
822 +=======+======+==========+==============+=======+
824 +-------+----------------------------------------+
826 +-------+----------------------------------------+
828 +-------+------+----------+--------------+-------+
829 | 3 | RAW | ``spec`` | ``relative`` | 1 |
830 | | | +--------------+-------+
831 | | | | ``search`` | 1 |
832 | | | +--------------+-------+
833 | | | | ``offset`` | 10 |
834 | | | +--------------+-------+
835 | | | | ``limit`` | 0 |
836 | | | +--------------+-------+
837 | | | | ``length`` | 3 |
838 | | | +--------------+-------+
839 | | | | ``pattern`` | "foo" |
840 +-------+------+----------+--------------+-------+
841 | 4 | RAW | ``spec`` | ``relative`` | 1 |
842 | | | +--------------+-------+
843 | | | | ``search`` | 0 |
844 | | | +--------------+-------+
845 | | | | ``offset`` | 20 |
846 | | | +--------------+-------+
847 | | | | ``limit`` | 0 |
848 | | | +--------------+-------+
849 | | | | ``length`` | 3 |
850 | | | +--------------+-------+
851 | | | | ``pattern`` | "bar" |
852 +-------+------+----------+--------------+-------+
853 | 5 | RAW | ``spec`` | ``relative`` | 1 |
854 | | | +--------------+-------+
855 | | | | ``search`` | 0 |
856 | | | +--------------+-------+
857 | | | | ``offset`` | -29 |
858 | | | +--------------+-------+
859 | | | | ``limit`` | 0 |
860 | | | +--------------+-------+
861 | | | | ``length`` | 3 |
862 | | | +--------------+-------+
863 | | | | ``pattern`` | "baz" |
864 +-------+------+----------+--------------+-------+
866 +-------+----------------------------------------+
870 - Locate "foo" at least 10 bytes deep inside UDP payload.
871 - Locate "bar" after "foo" plus 20 bytes.
872 - Locate "baz" after "bar" minus 29 bytes.
874 Such a packet may be represented as follows (not to scale)::
877 | |<--------->| |<--------->|
879 |-----|------|-----|-----|-----|-----|-----------|-----|------|
880 | ETH | IPv4 | UDP | ... | baz | foo | ......... | bar | .... |
881 |-----|------|-----|-----|-----|-----|-----------|-----|------|
883 |<--------------------------->|
886 Note that matching subsequent pattern items would resume after "baz", not
887 "bar" since matching is always performed after the previous item of the
893 Matches an Ethernet header.
895 The ``type`` field either stands for "EtherType" or "TPID" when followed by
896 so-called layer 2.5 pattern items such as ``RTE_FLOW_ITEM_TYPE_VLAN``. In
897 the latter case, ``type`` refers to that of the outer header, with the inner
898 EtherType/TPID provided by the subsequent pattern item. This is the same
899 order as on the wire.
900 If the ``type`` field contains a TPID value, then only tagged packets with the
901 specified TPID will match the pattern.
902 The field ``has_vlan`` can be used to match any type of tagged packets,
903 instead of using the ``type`` field.
904 If the ``type`` and ``has_vlan`` fields are not specified, then both tagged
905 and untagged packets will match the pattern.
907 - ``dst``: destination MAC.
908 - ``src``: source MAC.
909 - ``type``: EtherType or TPID.
910 - ``has_vlan``: packet header contains at least one VLAN.
911 - Default ``mask`` matches destination and source addresses only.
916 Matches an 802.1Q/ad VLAN tag.
918 The corresponding standard outer EtherType (TPID) values are
919 ``RTE_ETHER_TYPE_VLAN`` or ``RTE_ETHER_TYPE_QINQ``. It can be overridden by the
920 preceding pattern item.
921 If a ``VLAN`` item is present in the pattern, then only tagged packets will
923 The field ``has_more_vlan`` can be used to match any type of tagged packets,
924 instead of using the ``inner_type field``.
925 If the ``inner_type`` and ``has_more_vlan`` fields are not specified,
926 then any tagged packets will match the pattern.
928 - ``tci``: tag control information.
929 - ``inner_type``: inner EtherType or TPID.
930 - ``has_more_vlan``: packet header contains at least one more VLAN, after this VLAN.
931 - Default ``mask`` matches the VID part of TCI only (lower 12 bits).
936 Matches an IPv4 header.
938 Note: IPv4 options are handled by dedicated pattern items.
940 - ``hdr``: IPv4 header definition (``rte_ip.h``).
941 - Default ``mask`` matches source and destination addresses only.
946 Matches an IPv6 header.
948 Dedicated flags indicate if header contains specific extension headers.
949 To match on packets containing a specific extension header, an application
950 should match on the dedicated flag set to 1.
951 To match on packets not containing a specific extension header, an application
952 should match on the dedicated flag clear to 0.
953 In case application doesn't care about the existence of a specific extension
954 header, it should not specify the dedicated flag for matching.
956 - ``hdr``: IPv6 header definition (``rte_ip.h``).
957 - ``has_hop_ext``: header contains Hop-by-Hop Options extension header.
958 - ``has_route_ext``: header contains Routing extension header.
959 - ``has_frag_ext``: header contains Fragment extension header.
960 - ``has_auth_ext``: header contains Authentication extension header.
961 - ``has_esp_ext``: header contains Encapsulation Security Payload extension header.
962 - ``has_dest_ext``: header contains Destination Options extension header.
963 - ``has_mobil_ext``: header contains Mobility extension header.
964 - ``has_hip_ext``: header contains Host Identity Protocol extension header.
965 - ``has_shim6_ext``: header contains Shim6 Protocol extension header.
966 - Default ``mask`` matches ``hdr`` source and destination addresses only.
971 Matches an ICMP header.
973 - ``hdr``: ICMP header definition (``rte_icmp.h``).
974 - Default ``mask`` matches ICMP type and code only.
979 Matches a UDP header.
981 - ``hdr``: UDP header definition (``rte_udp.h``).
982 - Default ``mask`` matches source and destination ports only.
987 Matches a TCP header.
989 - ``hdr``: TCP header definition (``rte_tcp.h``).
990 - Default ``mask`` matches source and destination ports only.
995 Matches a SCTP header.
997 - ``hdr``: SCTP header definition (``rte_sctp.h``).
998 - Default ``mask`` matches source and destination ports only.
1003 Matches a VXLAN header (RFC 7348).
1005 - ``flags``: normally 0x08 (I flag).
1006 - ``rsvd0``: reserved, normally 0x000000.
1007 - ``vni``: VXLAN network identifier.
1008 - ``rsvd1``: reserved, normally 0x00.
1009 - Default ``mask`` matches VNI only.
1014 Matches an IEEE 802.1BR E-Tag header.
1016 The corresponding standard outer EtherType (TPID) value is
1017 ``RTE_ETHER_TYPE_ETAG``. It can be overridden by the preceding pattern item.
1019 - ``epcp_edei_in_ecid_b``: E-Tag control information (E-TCI), E-PCP (3b),
1020 E-DEI (1b), ingress E-CID base (12b).
1021 - ``rsvd_grp_ecid_b``: reserved (2b), GRP (2b), E-CID base (12b).
1022 - ``in_ecid_e``: ingress E-CID ext.
1023 - ``ecid_e``: E-CID ext.
1024 - ``inner_type``: inner EtherType or TPID.
1025 - Default ``mask`` simultaneously matches GRP and E-CID base.
1030 Matches a NVGRE header (RFC 7637).
1032 - ``c_k_s_rsvd0_ver``: checksum (1b), undefined (1b), key bit (1b),
1033 sequence number (1b), reserved 0 (9b), version (3b). This field must have
1034 value 0x2000 according to RFC 7637.
1035 - ``protocol``: protocol type (0x6558).
1036 - ``tni``: virtual subnet ID.
1037 - ``flow_id``: flow ID.
1038 - Default ``mask`` matches TNI only.
1043 Matches a MPLS header.
1045 - ``label_tc_s_ttl``: label, TC, Bottom of Stack and TTL.
1046 - Default ``mask`` matches label only.
1051 Matches a GRE header.
1053 - ``c_rsvd0_ver``: checksum, reserved 0 and version.
1054 - ``protocol``: protocol type.
1055 - Default ``mask`` matches protocol only.
1060 Matches a GRE key field.
1061 This should be preceded by item ``GRE``.
1063 - Value to be matched is a big-endian 32 bit integer.
1064 - When this item present it implicitly match K bit in default mask as "1"
1069 Fuzzy pattern match, expect faster than default.
1071 This is for device that support fuzzy match option. Usually a fuzzy match is
1072 fast but the cost is accuracy. i.e. Signature Match only match pattern's hash
1073 value, but it is possible two different patterns have the same hash value.
1075 Matching accuracy level can be configured by threshold. Driver can divide the
1076 range of threshold and map to different accuracy levels that device support.
1078 Threshold 0 means perfect match (no fuzziness), while threshold 0xffffffff
1079 means fuzziest match.
1081 .. _table_rte_flow_item_fuzzy:
1085 +----------+---------------+--------------------------------------------------+
1086 | Field | Subfield | Value |
1087 +==========+===============+==================================================+
1088 | ``spec`` | ``threshold`` | 0 as perfect match, 0xffffffff as fuzziest match |
1089 +----------+---------------+--------------------------------------------------+
1090 | ``last`` | ``threshold`` | upper range value |
1091 +----------+---------------+--------------------------------------------------+
1092 | ``mask`` | ``threshold`` | bit-mask apply to "spec" and "last" |
1093 +----------+---------------+--------------------------------------------------+
1095 Usage example, fuzzy match a TCPv4 packets:
1097 .. _table_rte_flow_item_fuzzy_example:
1099 .. table:: Fuzzy matching
1101 +-------+----------+
1103 +=======+==========+
1105 +-------+----------+
1107 +-------+----------+
1109 +-------+----------+
1111 +-------+----------+
1113 +-------+----------+
1115 Item: ``GTP``, ``GTPC``, ``GTPU``
1116 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1118 Matches a GTPv1 header.
1120 Note: GTP, GTPC and GTPU use the same structure. GTPC and GTPU item
1121 are defined for a user-friendly API when creating GTP-C and GTP-U
1124 - ``v_pt_rsv_flags``: version (3b), protocol type (1b), reserved (1b),
1125 extension header flag (1b), sequence number flag (1b), N-PDU number
1127 - ``msg_type``: message type.
1128 - ``msg_len``: message length.
1129 - ``teid``: tunnel endpoint identifier.
1130 - Default ``mask`` matches teid only.
1135 Matches an ESP header.
1137 - ``hdr``: ESP header definition (``rte_esp.h``).
1138 - Default ``mask`` matches SPI only.
1143 Matches a GENEVE header.
1145 - ``ver_opt_len_o_c_rsvd0``: version (2b), length of the options fields (6b),
1146 OAM packet (1b), critical options present (1b), reserved 0 (6b).
1147 - ``protocol``: protocol type.
1148 - ``vni``: virtual network identifier.
1149 - ``rsvd1``: reserved, normally 0x00.
1150 - Default ``mask`` matches VNI only.
1155 Matches a VXLAN-GPE header (draft-ietf-nvo3-vxlan-gpe-05).
1157 - ``flags``: normally 0x0C (I and P flags).
1158 - ``rsvd0``: reserved, normally 0x0000.
1159 - ``protocol``: protocol type.
1160 - ``vni``: VXLAN network identifier.
1161 - ``rsvd1``: reserved, normally 0x00.
1162 - Default ``mask`` matches VNI only.
1164 Item: ``ARP_ETH_IPV4``
1165 ^^^^^^^^^^^^^^^^^^^^^^
1167 Matches an ARP header for Ethernet/IPv4.
1169 - ``hdr``: hardware type, normally 1.
1170 - ``pro``: protocol type, normally 0x0800.
1171 - ``hln``: hardware address length, normally 6.
1172 - ``pln``: protocol address length, normally 4.
1173 - ``op``: opcode (1 for request, 2 for reply).
1174 - ``sha``: sender hardware address.
1175 - ``spa``: sender IPv4 address.
1176 - ``tha``: target hardware address.
1177 - ``tpa``: target IPv4 address.
1178 - Default ``mask`` matches SHA, SPA, THA and TPA.
1183 Matches the presence of any IPv6 extension header.
1185 - ``next_hdr``: next header.
1186 - Default ``mask`` matches ``next_hdr``.
1188 Normally preceded by any of:
1193 Item: ``IPV6_FRAG_EXT``
1194 ^^^^^^^^^^^^^^^^^^^^^^^
1196 Matches the presence of IPv6 fragment extension header.
1198 - ``hdr``: IPv6 fragment extension header definition (``rte_ip.h``).
1200 Normally preceded by any of:
1208 Matches any ICMPv6 header.
1210 - ``type``: ICMPv6 type.
1211 - ``code``: ICMPv6 code.
1212 - ``checksum``: ICMPv6 checksum.
1213 - Default ``mask`` matches ``type`` and ``code``.
1215 Item: ``ICMP6_ND_NS``
1216 ^^^^^^^^^^^^^^^^^^^^^
1218 Matches an ICMPv6 neighbor discovery solicitation.
1220 - ``type``: ICMPv6 type, normally 135.
1221 - ``code``: ICMPv6 code, normally 0.
1222 - ``checksum``: ICMPv6 checksum.
1223 - ``reserved``: reserved, normally 0.
1224 - ``target_addr``: target address.
1225 - Default ``mask`` matches target address only.
1227 Item: ``ICMP6_ND_NA``
1228 ^^^^^^^^^^^^^^^^^^^^^
1230 Matches an ICMPv6 neighbor discovery advertisement.
1232 - ``type``: ICMPv6 type, normally 136.
1233 - ``code``: ICMPv6 code, normally 0.
1234 - ``checksum``: ICMPv6 checksum.
1235 - ``rso_reserved``: route flag (1b), solicited flag (1b), override flag
1236 (1b), reserved (29b).
1237 - ``target_addr``: target address.
1238 - Default ``mask`` matches target address only.
1240 Item: ``ICMP6_ND_OPT``
1241 ^^^^^^^^^^^^^^^^^^^^^^
1243 Matches the presence of any ICMPv6 neighbor discovery option.
1245 - ``type``: ND option type.
1246 - ``length``: ND option length.
1247 - Default ``mask`` matches type only.
1249 Normally preceded by any of:
1251 - `Item: ICMP6_ND_NA`_
1252 - `Item: ICMP6_ND_NS`_
1253 - `Item: ICMP6_ND_OPT`_
1255 Item: ``ICMP6_ND_OPT_SLA_ETH``
1256 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1258 Matches an ICMPv6 neighbor discovery source Ethernet link-layer address
1261 - ``type``: ND option type, normally 1.
1262 - ``length``: ND option length, normally 1.
1263 - ``sla``: source Ethernet LLA.
1264 - Default ``mask`` matches source link-layer address only.
1266 Normally preceded by any of:
1268 - `Item: ICMP6_ND_NA`_
1269 - `Item: ICMP6_ND_OPT`_
1271 Item: ``ICMP6_ND_OPT_TLA_ETH``
1272 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1274 Matches an ICMPv6 neighbor discovery target Ethernet link-layer address
1277 - ``type``: ND option type, normally 2.
1278 - ``length``: ND option length, normally 1.
1279 - ``tla``: target Ethernet LLA.
1280 - Default ``mask`` matches target link-layer address only.
1282 Normally preceded by any of:
1284 - `Item: ICMP6_ND_NS`_
1285 - `Item: ICMP6_ND_OPT`_
1290 Matches an application specific 32 bit metadata item.
1292 - Default ``mask`` matches the specified metadata value.
1297 Matches a GTP PDU extension header with type 0x85.
1299 - ``pdu_type``: PDU type.
1300 - ``qfi``: QoS flow identifier.
1301 - Default ``mask`` matches QFI only.
1303 Item: ``PPPOES``, ``PPPOED``
1304 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1306 Matches a PPPoE header.
1308 - ``version_type``: version (4b), type (4b).
1309 - ``code``: message type.
1310 - ``session_id``: session identifier.
1311 - ``length``: payload length.
1313 Item: ``PPPOE_PROTO_ID``
1314 ^^^^^^^^^^^^^^^^^^^^^^^^
1316 Matches a PPPoE session protocol identifier.
1318 - ``proto_id``: PPP protocol identifier.
1319 - Default ``mask`` matches proto_id only.
1324 Matches a network service header (RFC 8300).
1326 - ``version``: normally 0x0 (2 bits).
1327 - ``oam_pkt``: indicate oam packet (1 bit).
1328 - ``reserved``: reserved bit (1 bit).
1329 - ``ttl``: maximum SFF hopes (6 bits).
1330 - ``length``: total length in 4 bytes words (6 bits).
1331 - ``reserved1``: reserved1 bits (4 bits).
1332 - ``mdtype``: ndicates format of NSH header (4 bits).
1333 - ``next_proto``: indicates protocol type of encap data (8 bits).
1334 - ``spi``: service path identifier (3 bytes).
1335 - ``sindex``: service index (1 byte).
1336 - Default ``mask`` matches mdtype, next_proto, spi, sindex.
1342 Matches a Internet Group Management Protocol (RFC 2236).
1344 - ``type``: IGMP message type (Query/Report).
1345 - ``max_resp_time``: max time allowed before sending report.
1346 - ``checksum``: checksum, 1s complement of whole IGMP message.
1347 - ``group_addr``: group address, for Query value will be 0.
1348 - Default ``mask`` matches group_addr.
1354 Matches a IP Authentication Header (RFC 4302).
1356 - ``next_hdr``: next payload after AH.
1357 - ``payload_len``: total length of AH in 4B words.
1358 - ``reserved``: reserved bits.
1359 - ``spi``: security parameters index.
1360 - ``seq_num``: counter value increased by 1 on each packet sent.
1361 - Default ``mask`` matches spi.
1366 Matches a HIGIG2 header field. It is layer 2.5 protocol and used in
1369 - Default ``mask`` matches classification and vlan.
1374 Matches a L2TPv3 over IP header.
1376 - ``session_id``: L2TPv3 over IP session identifier.
1377 - Default ``mask`` matches session_id only.
1382 Matches a PFCP Header.
1384 - ``s_field``: S field.
1385 - ``msg_type``: message type.
1386 - ``msg_len``: message length.
1387 - ``seid``: session endpoint identifier.
1388 - Default ``mask`` matches s_field and seid.
1393 Matches a eCPRI header.
1395 - ``hdr``: eCPRI header definition (``rte_ecpri.h``).
1396 - Default ``mask`` matches nothing, for all eCPRI messages.
1398 Item: ``PACKET_INTEGRITY_CHECKS``
1399 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1401 Matches packet integrity.
1402 For some devices application needs to enable integration checks in HW
1403 before using this item.
1405 - ``level``: the encapsulation level that should be checked:
1406 - ``level == 0`` means the default PMD mode (can be inner most / outermost).
1407 - ``level == 1`` means outermost header.
1408 - ``level > 1`` means inner header. See also RSS level.
1409 - ``packet_ok``: All HW packet integrity checks have passed based on the
1410 topmost network layer. For example, for ICMP packet the topmost network
1411 layer is L3 and for TCP or UDP packet the topmost network layer is L4.
1412 - ``l2_ok``: all layer 2 HW integrity checks passed.
1413 - ``l3_ok``: all layer 3 HW integrity checks passed.
1414 - ``l4_ok``: all layer 4 HW integrity checks passed.
1415 - ``l2_crc_ok``: layer 2 CRC check passed.
1416 - ``ipv4_csum_ok``: IPv4 checksum check passed.
1417 - ``l4_csum_ok``: layer 4 checksum check passed.
1418 - ``l3_len_ok``: the layer 3 length is smaller than the frame length.
1423 Matches a conntrack state after conntrack action.
1425 - ``flags``: conntrack packet state flags.
1426 - Default ``mask`` matches all state bits.
1428 Item: ``PORT_REPRESENTOR``
1429 ^^^^^^^^^^^^^^^^^^^^^^^^^^
1431 Matches traffic entering the embedded switch from the given ethdev.
1433 Term **ethdev** and the concept of **port representor** are synonymous.
1434 The **represented port** is an *entity* plugged to the embedded switch
1435 at the opposite end of the "wire" leading to the ethdev.
1439 .--------------------.
1440 | PORT_REPRESENTOR | Ethdev (Application Port Referred to by its ID)
1441 '--------------------'
1463 .--------------------.
1464 | REPRESENTED_PORT | Net / Guest / Another Ethdev (Same Application)
1465 '--------------------'
1468 - Incompatible with `Attribute: Traffic direction`_.
1469 - Requires `Attribute: Transfer`_.
1471 .. _table_rte_flow_item_ethdev:
1473 .. table:: ``struct rte_flow_item_ethdev``
1475 +----------+-------------+---------------------------+
1476 | Field | Subfield | Value |
1477 +==========+=============+===========================+
1478 | ``spec`` | ``port_id`` | ethdev port ID |
1479 +----------+-------------+---------------------------+
1480 | ``last`` | ``port_id`` | upper range value |
1481 +----------+-------------+---------------------------+
1482 | ``mask`` | ``port_id`` | zeroed for wildcard match |
1483 +----------+-------------+---------------------------+
1485 - Default ``mask`` provides exact match behaviour.
1487 See also `Action: PORT_REPRESENTOR`_.
1489 Item: ``REPRESENTED_PORT``
1490 ^^^^^^^^^^^^^^^^^^^^^^^^^^
1492 Matches traffic entering the embedded switch from
1493 the entity represented by the given ethdev.
1495 Term **ethdev** and the concept of **port representor** are synonymous.
1496 The **represented port** is an *entity* plugged to the embedded switch
1497 at the opposite end of the "wire" leading to the ethdev.
1501 .--------------------.
1502 | PORT_REPRESENTOR | Ethdev (Application Port Referred to by its ID)
1503 '--------------------'
1525 .--------------------.
1526 | REPRESENTED_PORT | Net / Guest / Another Ethdev (Same Application)
1527 '--------------------'
1530 - Incompatible with `Attribute: Traffic direction`_.
1531 - Requires `Attribute: Transfer`_.
1533 This item is meant to use the same structure as `Item: PORT_REPRESENTOR`_.
1535 See also `Action: REPRESENTED_PORT`_.
1540 Each possible action is represented by a type.
1541 An action can have an associated configuration object.
1542 Several actions combined in a list can be assigned
1543 to a flow rule and are performed in order.
1545 They fall in three categories:
1547 - Actions that modify the fate of matching traffic, for instance by dropping
1548 or assigning it a specific destination.
1550 - Actions that modify matching traffic contents or its properties. This
1551 includes adding/removing encapsulation, encryption, compression and marks.
1553 - Actions related to the flow rule itself, such as updating counters or
1554 making it non-terminating.
1556 Flow rules being terminating by default, not specifying any action of the
1557 fate kind results in undefined behavior. This applies to both ingress and
1560 PASSTHRU, when supported, makes a flow rule non-terminating.
1562 Like matching patterns, action lists are terminated by END items.
1564 Example of action that redirects packets to queue index 10:
1566 .. _table_rte_flow_action_example:
1568 .. table:: Queue action
1570 +-----------+-------+
1572 +===========+=======+
1574 +-----------+-------+
1576 Actions are performed in list order:
1578 .. _table_rte_flow_count_then_drop:
1580 .. table:: Count then drop
1594 .. _table_rte_flow_mark_count_redirect:
1596 .. table:: Mark, count then redirect
1598 +-------+--------+------------+-------+
1599 | Index | Action | Field | Value |
1600 +=======+========+============+=======+
1601 | 0 | MARK | ``mark`` | 0x2a |
1602 +-------+--------+------------+-------+
1603 | 1 | COUNT | ``id`` | 0 |
1604 +-------+--------+------------+-------+
1605 | 2 | QUEUE | ``queue`` | 10 |
1606 +-------+--------+------------+-------+
1608 +-------+-----------------------------+
1612 .. _table_rte_flow_redirect_queue_5:
1614 .. table:: Redirect to queue 5
1616 +-------+--------+-----------+-------+
1617 | Index | Action | Field | Value |
1618 +=======+========+===========+=======+
1620 +-------+--------+-----------+-------+
1621 | 1 | QUEUE | ``queue`` | 5 |
1622 +-------+--------+-----------+-------+
1624 +-------+----------------------------+
1626 In the above example, while DROP and QUEUE must be performed in order, both
1627 have to happen before reaching END. Only QUEUE has a visible effect.
1629 Note that such a list may be thought as ambiguous and rejected on that
1632 .. _table_rte_flow_redirect_queue_5_3:
1634 .. table:: Redirect to queues 5 and 3
1636 +-------+--------+-----------+-------+
1637 | Index | Action | Field | Value |
1638 +=======+========+===========+=======+
1639 | 0 | QUEUE | ``queue`` | 5 |
1640 +-------+--------+-----------+-------+
1642 +-------+--------+-----------+-------+
1643 | 2 | QUEUE | ``queue`` | 3 |
1644 +-------+--------+-----------+-------+
1646 +-------+----------------------------+
1648 As previously described, all actions must be taken into account. This
1649 effectively duplicates traffic to both queues. The above example also shows
1650 that VOID is ignored.
1655 Common action types are described in this section.
1660 End marker for action lists. Prevents further processing of actions, thereby
1663 - Its numeric value is 0 for convenience.
1664 - PMD support is mandatory.
1665 - No configurable properties.
1667 .. _table_rte_flow_action_end:
1680 Used as a placeholder for convenience. It is ignored and simply discarded by
1683 - PMD support is mandatory.
1684 - No configurable properties.
1686 .. _table_rte_flow_action_void:
1696 Action: ``PASSTHRU``
1697 ^^^^^^^^^^^^^^^^^^^^
1699 Leaves traffic up for additional processing by subsequent flow rules; makes
1700 a flow rule non-terminating.
1702 - No configurable properties.
1704 .. _table_rte_flow_action_passthru:
1714 Example to copy a packet to a queue and continue processing by subsequent
1717 .. _table_rte_flow_action_passthru_example:
1719 .. table:: Copy to queue 8
1721 +-------+--------+-----------+-------+
1722 | Index | Action | Field | Value |
1723 +=======+========+===========+=======+
1725 +-------+--------+-----------+-------+
1726 | 1 | QUEUE | ``queue`` | 8 |
1727 +-------+--------+-----------+-------+
1729 +-------+----------------------------+
1734 Redirects packets to a group on the current device.
1736 In a hierarchy of groups, which can be used to represent physical or logical
1737 flow group/tables on the device, this action redirects the matched flow to
1738 the specified group on that device.
1740 If a matched flow is redirected to a table which doesn't contain a matching
1741 rule for that flow then the behavior is undefined and the resulting behavior
1742 is up to the specific device. Best practice when using groups would be define
1743 a default flow rule for each group which a defines the default actions in that
1744 group so a consistent behavior is defined.
1746 Defining an action for matched flow in a group to jump to a group which is
1747 higher in the group hierarchy may not be supported by physical devices,
1748 depending on how groups are mapped to the physical devices. In the
1749 definitions of jump actions, applications should be aware that it may be
1750 possible to define flow rules which trigger an undefined behavior causing
1751 flows to loop between groups.
1753 .. _table_rte_flow_action_jump:
1757 +-----------+------------------------------+
1759 +===========+==============================+
1760 | ``group`` | Group to redirect packets to |
1761 +-----------+------------------------------+
1766 Attaches an integer value to packets and sets ``PKT_RX_FDIR`` and
1767 ``PKT_RX_FDIR_ID`` mbuf flags.
1769 This value is arbitrary and application-defined. Maximum allowed value
1770 depends on the underlying implementation. It is returned in the
1771 ``hash.fdir.hi`` mbuf field.
1773 .. _table_rte_flow_action_mark:
1777 +--------+--------------------------------------+
1779 +========+======================================+
1780 | ``id`` | integer value to return with packets |
1781 +--------+--------------------------------------+
1786 Flags packets. Similar to `Action: MARK`_ without a specific value; only
1787 sets the ``PKT_RX_FDIR`` mbuf flag.
1789 - No configurable properties.
1791 .. _table_rte_flow_action_flag:
1804 Assigns packets to a given queue index.
1806 .. _table_rte_flow_action_queue:
1810 +-----------+--------------------+
1812 +===========+====================+
1813 | ``index`` | queue index to use |
1814 +-----------+--------------------+
1821 - No configurable properties.
1823 .. _table_rte_flow_action_drop:
1836 Adds a counter action to a matched flow.
1838 If more than one count action is specified in a single flow rule, then each
1839 action must specify a unique id.
1841 Counters can be retrieved and reset through ``rte_flow_query()``, see
1842 ``struct rte_flow_query_count``.
1844 For ports within the same switch domain then the counter id namespace extends
1845 to all ports within that switch domain.
1847 .. _table_rte_flow_action_count:
1851 +------------+---------------------------------+
1853 +============+=================================+
1854 | ``id`` | counter id |
1855 +------------+---------------------------------+
1857 Query structure to retrieve and reset flow rule counters:
1859 .. _table_rte_flow_query_count:
1861 .. table:: COUNT query
1863 +---------------+-----+-----------------------------------+
1864 | Field | I/O | Value |
1865 +===============+=====+===================================+
1866 | ``reset`` | in | reset counter after query |
1867 +---------------+-----+-----------------------------------+
1868 | ``hits_set`` | out | ``hits`` field is set |
1869 +---------------+-----+-----------------------------------+
1870 | ``bytes_set`` | out | ``bytes`` field is set |
1871 +---------------+-----+-----------------------------------+
1872 | ``hits`` | out | number of hits for this rule |
1873 +---------------+-----+-----------------------------------+
1874 | ``bytes`` | out | number of bytes through this rule |
1875 +---------------+-----+-----------------------------------+
1880 Similar to QUEUE, except RSS is additionally performed on packets to spread
1881 them among several queues according to the provided parameters.
1883 Unlike global RSS settings used by other DPDK APIs, unsetting the ``types``
1884 field does not disable RSS in a flow rule. Doing so instead requests safe
1885 unspecified "best-effort" settings from the underlying PMD, which depending
1886 on the flow rule, may result in anything ranging from empty (single queue)
1887 to all-inclusive RSS.
1889 If non-applicable for matching packets RSS types are requested,
1890 these RSS types are simply ignored. For example, it happens if:
1892 - Hashing of both TCP and UDP ports is requested
1893 (only one can be present in a packet).
1895 - Requested RSS types contradict to flow rule pattern
1896 (e.g. pattern has UDP item, but RSS types contain TCP).
1898 If requested RSS hash types are not supported by the Ethernet device at all
1899 (not reported in ``dev_info.flow_type_rss_offloads``),
1900 the flow creation will fail.
1902 Note: RSS hash result is stored in the ``hash.rss`` mbuf field which
1903 overlaps ``hash.fdir.lo``. Since `Action: MARK`_ sets the ``hash.fdir.hi``
1904 field only, both can be requested simultaneously.
1906 Also, regarding packet encapsulation ``level``:
1908 - ``0`` requests the default behavior. Depending on the packet type, it can
1909 mean outermost, innermost, anything in between or even no RSS.
1911 It basically stands for the innermost encapsulation level RSS can be
1912 performed on according to PMD and device capabilities.
1914 - ``1`` requests RSS to be performed on the outermost packet encapsulation
1917 - ``2`` and subsequent values request RSS to be performed on the specified
1918 inner packet encapsulation level, from outermost to innermost (lower to
1921 Values other than ``0`` are not necessarily supported.
1923 Requesting a specific RSS level on unrecognized traffic results in undefined
1924 behavior. For predictable results, it is recommended to make the flow rule
1925 pattern match packet headers up to the requested encapsulation level so that
1926 only matching traffic goes through.
1928 .. _table_rte_flow_action_rss:
1932 +---------------+---------------------------------------------+
1934 +===============+=============================================+
1935 | ``func`` | RSS hash function to apply |
1936 +---------------+---------------------------------------------+
1937 | ``level`` | encapsulation level for ``types`` |
1938 +---------------+---------------------------------------------+
1939 | ``types`` | specific RSS hash types (see ``ETH_RSS_*``) |
1940 +---------------+---------------------------------------------+
1941 | ``key_len`` | hash key length in bytes |
1942 +---------------+---------------------------------------------+
1943 | ``queue_num`` | number of entries in ``queue`` |
1944 +---------------+---------------------------------------------+
1945 | ``key`` | hash key |
1946 +---------------+---------------------------------------------+
1947 | ``queue`` | queue indices to use |
1948 +---------------+---------------------------------------------+
1953 Directs matching traffic to the physical function (PF) of the current
1958 - No configurable properties.
1960 .. _table_rte_flow_action_pf:
1973 Directs matching traffic to a given virtual function of the current device.
1975 Packets matched by a VF pattern item can be redirected to their original VF
1976 ID instead of the specified one. This parameter may not be available and is
1977 not guaranteed to work properly if the VF part is matched by a prior flow
1978 rule or if packets are not addressed to a VF in the first place.
1982 .. _table_rte_flow_action_vf:
1986 +--------------+--------------------------------+
1988 +==============+================================+
1989 | ``original`` | use original VF ID if possible |
1990 +--------------+--------------------------------+
1992 +--------------+--------------------------------+
1994 Action: ``PHY_PORT``
1995 ^^^^^^^^^^^^^^^^^^^^
1997 Directs matching traffic to a given physical port index of the underlying
2000 See `Item: PHY_PORT`_.
2002 .. _table_rte_flow_action_phy_port:
2006 +--------------+-------------------------------------+
2008 +==============+=====================================+
2009 | ``original`` | use original port index if possible |
2010 +--------------+-------------------------------------+
2011 | ``index`` | physical port index |
2012 +--------------+-------------------------------------+
2016 Directs matching traffic to a given DPDK port ID.
2018 See `Item: PORT_ID`_.
2020 .. _table_rte_flow_action_port_id:
2024 +--------------+---------------------------------------+
2026 +==============+=======================================+
2027 | ``original`` | use original DPDK port ID if possible |
2028 +--------------+---------------------------------------+
2029 | ``id`` | DPDK port ID |
2030 +--------------+---------------------------------------+
2035 Applies a stage of metering and policing.
2037 The metering and policing (MTR) object has to be first created using the
2038 rte_mtr_create() API function. The ID of the MTR object is specified as
2039 action parameter. More than one flow can use the same MTR object through
2040 the meter action. The MTR object can be further updated or queried using
2043 .. _table_rte_flow_action_meter:
2047 +--------------+---------------+
2049 +==============+===============+
2050 | ``mtr_id`` | MTR object ID |
2051 +--------------+---------------+
2053 Action: ``SECURITY``
2054 ^^^^^^^^^^^^^^^^^^^^
2056 Perform the security action on flows matched by the pattern items
2057 according to the configuration of the security session.
2059 This action modifies the payload of matched flows. For INLINE_CRYPTO, the
2060 security protocol headers and IV are fully provided by the application as
2061 specified in the flow pattern. The payload of matching packets is
2062 encrypted on egress, and decrypted and authenticated on ingress.
2063 For INLINE_PROTOCOL, the security protocol is fully offloaded to HW,
2064 providing full encapsulation and decapsulation of packets in security
2065 protocols. The flow pattern specifies both the outer security header fields
2066 and the inner packet fields. The security session specified in the action
2067 must match the pattern parameters.
2069 The security session specified in the action must be created on the same
2070 port as the flow action that is being specified.
2072 The ingress/egress flow attribute should match that specified in the
2073 security session if the security session supports the definition of the
2076 Multiple flows can be configured to use the same security session.
2078 .. _table_rte_flow_action_security:
2082 +----------------------+--------------------------------------+
2084 +======================+======================================+
2085 | ``security_session`` | security session to apply |
2086 +----------------------+--------------------------------------+
2088 The following is an example of configuring IPsec inline using the
2089 INLINE_CRYPTO security session:
2091 The encryption algorithm, keys and salt are part of the opaque
2092 ``rte_security_session``. The SA is identified according to the IP and ESP
2093 fields in the pattern items.
2095 .. _table_rte_flow_item_esp_inline_example:
2097 .. table:: IPsec inline crypto flow pattern items.
2099 +-------+----------+
2101 +=======+==========+
2103 +-------+----------+
2105 +-------+----------+
2107 +-------+----------+
2109 +-------+----------+
2111 .. _table_rte_flow_action_esp_inline_example:
2113 .. table:: IPsec inline flow actions.
2115 +-------+----------+
2117 +=======+==========+
2119 +-------+----------+
2121 +-------+----------+
2123 Action: ``OF_SET_MPLS_TTL``
2124 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2126 Implements ``OFPAT_SET_MPLS_TTL`` ("MPLS TTL") as defined by the `OpenFlow
2127 Switch Specification`_.
2129 .. _table_rte_flow_action_of_set_mpls_ttl:
2131 .. table:: OF_SET_MPLS_TTL
2133 +--------------+----------+
2135 +==============+==========+
2136 | ``mpls_ttl`` | MPLS TTL |
2137 +--------------+----------+
2139 Action: ``OF_DEC_MPLS_TTL``
2140 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2142 Implements ``OFPAT_DEC_MPLS_TTL`` ("decrement MPLS TTL") as defined by the
2143 `OpenFlow Switch Specification`_.
2145 .. _table_rte_flow_action_of_dec_mpls_ttl:
2147 .. table:: OF_DEC_MPLS_TTL
2155 Action: ``OF_SET_NW_TTL``
2156 ^^^^^^^^^^^^^^^^^^^^^^^^^
2158 Implements ``OFPAT_SET_NW_TTL`` ("IP TTL") as defined by the `OpenFlow
2159 Switch Specification`_.
2161 .. _table_rte_flow_action_of_set_nw_ttl:
2163 .. table:: OF_SET_NW_TTL
2165 +------------+--------+
2167 +============+========+
2168 | ``nw_ttl`` | IP TTL |
2169 +------------+--------+
2171 Action: ``OF_DEC_NW_TTL``
2172 ^^^^^^^^^^^^^^^^^^^^^^^^^
2174 Implements ``OFPAT_DEC_NW_TTL`` ("decrement IP TTL") as defined by the
2175 `OpenFlow Switch Specification`_.
2177 .. _table_rte_flow_action_of_dec_nw_ttl:
2179 .. table:: OF_DEC_NW_TTL
2187 Action: ``OF_COPY_TTL_OUT``
2188 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2190 Implements ``OFPAT_COPY_TTL_OUT`` ("copy TTL "outwards" -- from
2191 next-to-outermost to outermost") as defined by the `OpenFlow Switch
2194 .. _table_rte_flow_action_of_copy_ttl_out:
2196 .. table:: OF_COPY_TTL_OUT
2204 Action: ``OF_COPY_TTL_IN``
2205 ^^^^^^^^^^^^^^^^^^^^^^^^^^
2207 Implements ``OFPAT_COPY_TTL_IN`` ("copy TTL "inwards" -- from outermost to
2208 next-to-outermost") as defined by the `OpenFlow Switch Specification`_.
2210 .. _table_rte_flow_action_of_copy_ttl_in:
2212 .. table:: OF_COPY_TTL_IN
2220 Action: ``OF_POP_VLAN``
2221 ^^^^^^^^^^^^^^^^^^^^^^^
2223 Implements ``OFPAT_POP_VLAN`` ("pop the outer VLAN tag") as defined
2224 by the `OpenFlow Switch Specification`_.
2226 .. _table_rte_flow_action_of_pop_vlan:
2228 .. table:: OF_POP_VLAN
2236 Action: ``OF_PUSH_VLAN``
2237 ^^^^^^^^^^^^^^^^^^^^^^^^
2239 Implements ``OFPAT_PUSH_VLAN`` ("push a new VLAN tag") as defined by the
2240 `OpenFlow Switch Specification`_.
2242 .. _table_rte_flow_action_of_push_vlan:
2244 .. table:: OF_PUSH_VLAN
2246 +---------------+-----------+
2248 +===============+===========+
2249 | ``ethertype`` | EtherType |
2250 +---------------+-----------+
2252 Action: ``OF_SET_VLAN_VID``
2253 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2255 Implements ``OFPAT_SET_VLAN_VID`` ("set the 802.1q VLAN id") as defined by
2256 the `OpenFlow Switch Specification`_.
2258 .. _table_rte_flow_action_of_set_vlan_vid:
2260 .. table:: OF_SET_VLAN_VID
2262 +--------------+---------+
2264 +==============+=========+
2265 | ``vlan_vid`` | VLAN id |
2266 +--------------+---------+
2268 Action: ``OF_SET_VLAN_PCP``
2269 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2271 Implements ``OFPAT_SET_LAN_PCP`` ("set the 802.1q priority") as defined by
2272 the `OpenFlow Switch Specification`_.
2274 .. _table_rte_flow_action_of_set_vlan_pcp:
2276 .. table:: OF_SET_VLAN_PCP
2278 +--------------+---------------+
2280 +==============+===============+
2281 | ``vlan_pcp`` | VLAN priority |
2282 +--------------+---------------+
2284 Action: ``OF_POP_MPLS``
2285 ^^^^^^^^^^^^^^^^^^^^^^^
2287 Implements ``OFPAT_POP_MPLS`` ("pop the outer MPLS tag") as defined by the
2288 `OpenFlow Switch Specification`_.
2290 .. _table_rte_flow_action_of_pop_mpls:
2292 .. table:: OF_POP_MPLS
2294 +---------------+-----------+
2296 +===============+===========+
2297 | ``ethertype`` | EtherType |
2298 +---------------+-----------+
2300 Action: ``OF_PUSH_MPLS``
2301 ^^^^^^^^^^^^^^^^^^^^^^^^
2303 Implements ``OFPAT_PUSH_MPLS`` ("push a new MPLS tag") as defined by the
2304 `OpenFlow Switch Specification`_.
2306 .. _table_rte_flow_action_of_push_mpls:
2308 .. table:: OF_PUSH_MPLS
2310 +---------------+-----------+
2312 +===============+===========+
2313 | ``ethertype`` | EtherType |
2314 +---------------+-----------+
2316 Action: ``VXLAN_ENCAP``
2317 ^^^^^^^^^^^^^^^^^^^^^^^
2319 Performs a VXLAN encapsulation action by encapsulating the matched flow in the
2320 VXLAN tunnel as defined in the``rte_flow_action_vxlan_encap`` flow items
2323 This action modifies the payload of matched flows. The flow definition specified
2324 in the ``rte_flow_action_tunnel_encap`` action structure must define a valid
2325 VLXAN network overlay which conforms with RFC 7348 (Virtual eXtensible Local
2326 Area Network (VXLAN): A Framework for Overlaying Virtualized Layer 2 Networks
2327 over Layer 3 Networks). The pattern must be terminated with the
2328 RTE_FLOW_ITEM_TYPE_END item type.
2330 .. _table_rte_flow_action_vxlan_encap:
2332 .. table:: VXLAN_ENCAP
2334 +----------------+-------------------------------------+
2336 +================+=====================================+
2337 | ``definition`` | Tunnel end-point overlay definition |
2338 +----------------+-------------------------------------+
2340 .. _table_rte_flow_action_vxlan_encap_example:
2342 .. table:: IPv4 VxLAN flow pattern example.
2344 +-------+----------+
2346 +=======+==========+
2348 +-------+----------+
2350 +-------+----------+
2352 +-------+----------+
2354 +-------+----------+
2356 +-------+----------+
2358 Action: ``VXLAN_DECAP``
2359 ^^^^^^^^^^^^^^^^^^^^^^^
2361 Performs a decapsulation action by stripping all headers of the VXLAN tunnel
2362 network overlay from the matched flow.
2364 The flow items pattern defined for the flow rule with which a ``VXLAN_DECAP``
2365 action is specified, must define a valid VXLAN tunnel as per RFC7348. If the
2366 flow pattern does not specify a valid VXLAN tunnel then a
2367 RTE_FLOW_ERROR_TYPE_ACTION error should be returned.
2369 This action modifies the payload of matched flows.
2371 Action: ``NVGRE_ENCAP``
2372 ^^^^^^^^^^^^^^^^^^^^^^^
2374 Performs a NVGRE encapsulation action by encapsulating the matched flow in the
2375 NVGRE tunnel as defined in the``rte_flow_action_tunnel_encap`` flow item
2378 This action modifies the payload of matched flows. The flow definition specified
2379 in the ``rte_flow_action_tunnel_encap`` action structure must defined a valid
2380 NVGRE network overlay which conforms with RFC 7637 (NVGRE: Network
2381 Virtualization Using Generic Routing Encapsulation). The pattern must be
2382 terminated with the RTE_FLOW_ITEM_TYPE_END item type.
2384 .. _table_rte_flow_action_nvgre_encap:
2386 .. table:: NVGRE_ENCAP
2388 +----------------+-------------------------------------+
2390 +================+=====================================+
2391 | ``definition`` | NVGRE end-point overlay definition |
2392 +----------------+-------------------------------------+
2394 .. _table_rte_flow_action_nvgre_encap_example:
2396 .. table:: IPv4 NVGRE flow pattern example.
2398 +-------+----------+
2400 +=======+==========+
2402 +-------+----------+
2404 +-------+----------+
2406 +-------+----------+
2408 +-------+----------+
2410 Action: ``NVGRE_DECAP``
2411 ^^^^^^^^^^^^^^^^^^^^^^^
2413 Performs a decapsulation action by stripping all headers of the NVGRE tunnel
2414 network overlay from the matched flow.
2416 The flow items pattern defined for the flow rule with which a ``NVGRE_DECAP``
2417 action is specified, must define a valid NVGRE tunnel as per RFC7637. If the
2418 flow pattern does not specify a valid NVGRE tunnel then a
2419 RTE_FLOW_ERROR_TYPE_ACTION error should be returned.
2421 This action modifies the payload of matched flows.
2423 Action: ``RAW_ENCAP``
2424 ^^^^^^^^^^^^^^^^^^^^^
2426 Adds outer header whose template is provided in its data buffer,
2427 as defined in the ``rte_flow_action_raw_encap`` definition.
2429 This action modifies the payload of matched flows. The data supplied must
2430 be a valid header, either holding layer 2 data in case of adding layer 2 after
2431 decap layer 3 tunnel (for example MPLSoGRE) or complete tunnel definition
2432 starting from layer 2 and moving to the tunnel item itself. When applied to
2433 the original packet the resulting packet must be a valid packet.
2435 .. _table_rte_flow_action_raw_encap:
2437 .. table:: RAW_ENCAP
2439 +----------------+----------------------------------------+
2441 +================+========================================+
2442 | ``data`` | Encapsulation data |
2443 +----------------+----------------------------------------+
2444 | ``preserve`` | Bit-mask of data to preserve on output |
2445 +----------------+----------------------------------------+
2446 | ``size`` | Size of data and preserve |
2447 +----------------+----------------------------------------+
2449 Action: ``RAW_DECAP``
2450 ^^^^^^^^^^^^^^^^^^^^^^^
2452 Remove outer header whose template is provided in its data buffer,
2453 as defined in the ``rte_flow_action_raw_decap``
2455 This action modifies the payload of matched flows. The data supplied must
2456 be a valid header, either holding layer 2 data in case of removing layer 2
2457 before encapsulation of layer 3 tunnel (for example MPLSoGRE) or complete
2458 tunnel definition starting from layer 2 and moving to the tunnel item itself.
2459 When applied to the original packet the resulting packet must be a
2462 .. _table_rte_flow_action_raw_decap:
2464 .. table:: RAW_DECAP
2466 +----------------+----------------------------------------+
2468 +================+========================================+
2469 | ``data`` | Decapsulation data |
2470 +----------------+----------------------------------------+
2471 | ``size`` | Size of data |
2472 +----------------+----------------------------------------+
2474 Action: ``SET_IPV4_SRC``
2475 ^^^^^^^^^^^^^^^^^^^^^^^^
2477 Set a new IPv4 source address in the outermost IPv4 header.
2479 It must be used with a valid RTE_FLOW_ITEM_TYPE_IPV4 flow pattern item.
2480 Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be returned.
2482 .. _table_rte_flow_action_set_ipv4_src:
2484 .. table:: SET_IPV4_SRC
2486 +-----------------------------------------+
2488 +===============+=========================+
2489 | ``ipv4_addr`` | new IPv4 source address |
2490 +---------------+-------------------------+
2492 Action: ``SET_IPV4_DST``
2493 ^^^^^^^^^^^^^^^^^^^^^^^^
2495 Set a new IPv4 destination address in the outermost IPv4 header.
2497 It must be used with a valid RTE_FLOW_ITEM_TYPE_IPV4 flow pattern item.
2498 Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be returned.
2500 .. _table_rte_flow_action_set_ipv4_dst:
2502 .. table:: SET_IPV4_DST
2504 +---------------+------------------------------+
2506 +===============+==============================+
2507 | ``ipv4_addr`` | new IPv4 destination address |
2508 +---------------+------------------------------+
2510 Action: ``SET_IPV6_SRC``
2511 ^^^^^^^^^^^^^^^^^^^^^^^^
2513 Set a new IPv6 source address in the outermost IPv6 header.
2515 It must be used with a valid RTE_FLOW_ITEM_TYPE_IPV6 flow pattern item.
2516 Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be returned.
2518 .. _table_rte_flow_action_set_ipv6_src:
2520 .. table:: SET_IPV6_SRC
2522 +---------------+-------------------------+
2524 +===============+=========================+
2525 | ``ipv6_addr`` | new IPv6 source address |
2526 +---------------+-------------------------+
2528 Action: ``SET_IPV6_DST``
2529 ^^^^^^^^^^^^^^^^^^^^^^^^
2531 Set a new IPv6 destination address in the outermost IPv6 header.
2533 It must be used with a valid RTE_FLOW_ITEM_TYPE_IPV6 flow pattern item.
2534 Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be returned.
2536 .. _table_rte_flow_action_set_ipv6_dst:
2538 .. table:: SET_IPV6_DST
2540 +---------------+------------------------------+
2542 +===============+==============================+
2543 | ``ipv6_addr`` | new IPv6 destination address |
2544 +---------------+------------------------------+
2546 Action: ``SET_TP_SRC``
2547 ^^^^^^^^^^^^^^^^^^^^^^^^^
2549 Set a new source port number in the outermost TCP/UDP header.
2551 It must be used with a valid RTE_FLOW_ITEM_TYPE_TCP or RTE_FLOW_ITEM_TYPE_UDP
2552 flow pattern item. Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be returned.
2554 .. _table_rte_flow_action_set_tp_src:
2556 .. table:: SET_TP_SRC
2558 +----------+-------------------------+
2560 +==========+=========================+
2561 | ``port`` | new TCP/UDP source port |
2562 +---------------+--------------------+
2564 Action: ``SET_TP_DST``
2565 ^^^^^^^^^^^^^^^^^^^^^^^^^
2567 Set a new destination port number in the outermost TCP/UDP header.
2569 It must be used with a valid RTE_FLOW_ITEM_TYPE_TCP or RTE_FLOW_ITEM_TYPE_UDP
2570 flow pattern item. Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be returned.
2572 .. _table_rte_flow_action_set_tp_dst:
2574 .. table:: SET_TP_DST
2576 +----------+------------------------------+
2578 +==========+==============================+
2579 | ``port`` | new TCP/UDP destination port |
2580 +---------------+-------------------------+
2582 Action: ``MAC_SWAP``
2583 ^^^^^^^^^^^^^^^^^^^^^^^^^
2585 Swap the source and destination MAC addresses in the outermost Ethernet
2588 It must be used with a valid RTE_FLOW_ITEM_TYPE_ETH flow pattern item.
2589 Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be returned.
2591 .. _table_rte_flow_action_mac_swap:
2606 If there is no valid RTE_FLOW_ITEM_TYPE_IPV4 or RTE_FLOW_ITEM_TYPE_IPV6
2607 in pattern, Some PMDs will reject rule because behavior will be undefined.
2609 .. _table_rte_flow_action_dec_ttl:
2622 Assigns a new TTL value.
2624 If there is no valid RTE_FLOW_ITEM_TYPE_IPV4 or RTE_FLOW_ITEM_TYPE_IPV6
2625 in pattern, Some PMDs will reject rule because behavior will be undefined.
2627 .. _table_rte_flow_action_set_ttl:
2631 +---------------+--------------------+
2633 +===============+====================+
2634 | ``ttl_value`` | new TTL value |
2635 +---------------+--------------------+
2637 Action: ``SET_MAC_SRC``
2638 ^^^^^^^^^^^^^^^^^^^^^^^
2640 Set source MAC address.
2642 It must be used with a valid RTE_FLOW_ITEM_TYPE_ETH flow pattern item.
2643 Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be returned.
2645 .. _table_rte_flow_action_set_mac_src:
2647 .. table:: SET_MAC_SRC
2649 +--------------+---------------+
2651 +==============+===============+
2652 | ``mac_addr`` | MAC address |
2653 +--------------+---------------+
2655 Action: ``SET_MAC_DST``
2656 ^^^^^^^^^^^^^^^^^^^^^^^
2658 Set destination MAC address.
2660 It must be used with a valid RTE_FLOW_ITEM_TYPE_ETH flow pattern item.
2661 Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be returned.
2663 .. _table_rte_flow_action_set_mac_dst:
2665 .. table:: SET_MAC_DST
2667 +--------------+---------------+
2669 +==============+===============+
2670 | ``mac_addr`` | MAC address |
2671 +--------------+---------------+
2673 Action: ``INC_TCP_SEQ``
2674 ^^^^^^^^^^^^^^^^^^^^^^^
2676 Increase sequence number in the outermost TCP header.
2677 Value to increase TCP sequence number by is a big-endian 32 bit integer.
2679 Using this action on non-matching traffic will result in undefined behavior.
2681 Action: ``DEC_TCP_SEQ``
2682 ^^^^^^^^^^^^^^^^^^^^^^^
2684 Decrease sequence number in the outermost TCP header.
2685 Value to decrease TCP sequence number by is a big-endian 32 bit integer.
2687 Using this action on non-matching traffic will result in undefined behavior.
2689 Action: ``INC_TCP_ACK``
2690 ^^^^^^^^^^^^^^^^^^^^^^^
2692 Increase acknowledgment number in the outermost TCP header.
2693 Value to increase TCP acknowledgment number by is a big-endian 32 bit integer.
2695 Using this action on non-matching traffic will result in undefined behavior.
2697 Action: ``DEC_TCP_ACK``
2698 ^^^^^^^^^^^^^^^^^^^^^^^
2700 Decrease acknowledgment number in the outermost TCP header.
2701 Value to decrease TCP acknowledgment number by is a big-endian 32 bit integer.
2703 Using this action on non-matching traffic will result in undefined behavior.
2710 Tag is a transient data used during flow matching. This is not delivered to
2711 application. Multiple tags are supported by specifying index.
2713 .. _table_rte_flow_action_set_tag:
2717 +-----------+----------------------------+
2719 +===========+============================+
2720 | ``data`` | 32 bit tag value |
2721 +-----------+----------------------------+
2722 | ``mask`` | bit-mask applies to "data" |
2723 +-----------+----------------------------+
2724 | ``index`` | index of tag to set |
2725 +-----------+----------------------------+
2727 Action: ``SET_META``
2728 ^^^^^^^^^^^^^^^^^^^^^^^
2730 Set metadata. Item ``META`` matches metadata.
2732 Metadata set by mbuf metadata field with PKT_TX_DYNF_METADATA flag on egress
2733 will be overridden by this action. On ingress, the metadata will be carried by
2734 ``metadata`` dynamic field of ``rte_mbuf`` which can be accessed by
2735 ``RTE_FLOW_DYNF_METADATA()``. PKT_RX_DYNF_METADATA flag will be set along
2738 The mbuf dynamic field must be registered by calling
2739 ``rte_flow_dynf_metadata_register()`` prior to use ``SET_META`` action.
2741 Altering partial bits is supported with ``mask``. For bits which have never been
2742 set, unpredictable value will be seen depending on driver implementation. For
2743 loopback/hairpin packet, metadata set on Rx/Tx may or may not be propagated to
2744 the other path depending on HW capability.
2746 In hairpin case with Tx explicit flow mode, metadata could (not mandatory) be
2747 used to connect the Rx and Tx flows if it can be propagated from Rx to Tx path.
2749 .. _table_rte_flow_action_set_meta:
2753 +----------+----------------------------+
2755 +==========+============================+
2756 | ``data`` | 32 bit metadata value |
2757 +----------+----------------------------+
2758 | ``mask`` | bit-mask applies to "data" |
2759 +----------+----------------------------+
2761 Action: ``SET_IPV4_DSCP``
2762 ^^^^^^^^^^^^^^^^^^^^^^^^^
2766 Modify DSCP in IPv4 header.
2768 It must be used with RTE_FLOW_ITEM_TYPE_IPV4 in pattern.
2769 Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be returned.
2771 .. _table_rte_flow_action_set_ipv4_dscp:
2773 .. table:: SET_IPV4_DSCP
2775 +-----------+---------------------------------+
2777 +===========+=================================+
2778 | ``dscp`` | DSCP in low 6 bits, rest ignore |
2779 +-----------+---------------------------------+
2781 Action: ``SET_IPV6_DSCP``
2782 ^^^^^^^^^^^^^^^^^^^^^^^^^
2786 Modify DSCP in IPv6 header.
2788 It must be used with RTE_FLOW_ITEM_TYPE_IPV6 in pattern.
2789 Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be returned.
2791 .. _table_rte_flow_action_set_ipv6_dscp:
2793 .. table:: SET_IPV6_DSCP
2795 +-----------+---------------------------------+
2797 +===========+=================================+
2798 | ``dscp`` | DSCP in low 6 bits, rest ignore |
2799 +-----------+---------------------------------+
2804 Set ageing timeout configuration to a flow.
2806 Event RTE_ETH_EVENT_FLOW_AGED will be reported if
2807 timeout passed without any matching on the flow.
2809 .. _table_rte_flow_action_age:
2813 +--------------+---------------------------------+
2815 +==============+=================================+
2816 | ``timeout`` | 24 bits timeout value |
2817 +--------------+---------------------------------+
2818 | ``reserved`` | 8 bits reserved, must be zero |
2819 +--------------+---------------------------------+
2820 | ``context`` | user input flow context |
2821 +--------------+---------------------------------+
2823 Query structure to retrieve ageing status information of a
2824 shared AGE action, or a flow rule using the AGE action:
2826 .. _table_rte_flow_query_age:
2828 .. table:: AGE query
2830 +------------------------------+-----+----------------------------------------+
2831 | Field | I/O | Value |
2832 +==============================+=====+========================================+
2833 | ``aged`` | out | Aging timeout expired |
2834 +------------------------------+-----+----------------------------------------+
2835 | ``sec_since_last_hit_valid`` | out | ``sec_since_last_hit`` value is valid |
2836 +------------------------------+-----+----------------------------------------+
2837 | ``sec_since_last_hit`` | out | Seconds since last traffic hit |
2838 +------------------------------+-----+----------------------------------------+
2843 Adds a sample action to a matched flow.
2845 The matching packets will be duplicated with the specified ``ratio`` and
2846 applied with own set of actions with a fate action, the packets sampled
2847 equals is '1/ratio'. All the packets continue to the target destination.
2849 When the ``ratio`` is set to 1 then the packets will be 100% mirrored.
2850 ``actions`` represent the different set of actions for the sampled or mirrored
2851 packets, and must have a fate action.
2853 .. _table_rte_flow_action_sample:
2857 +--------------+---------------------------------+
2859 +==============+=================================+
2860 | ``ratio`` | 32 bits sample ratio value |
2861 +--------------+---------------------------------+
2862 | ``actions`` | sub-action list for sampling |
2863 +--------------+---------------------------------+
2865 Action: ``INDIRECT``
2866 ^^^^^^^^^^^^^^^^^^^^
2868 Flow utilize indirect action by handle as returned from
2869 ``rte_flow_action_handle_create()``.
2871 The behaviour of the indirect action defined by ``action`` argument of type
2872 ``struct rte_flow_action`` passed to ``rte_flow_action_handle_create()``.
2874 The indirect action can be used by a single flow or shared among multiple flows.
2875 The indirect action can be in-place updated by ``rte_flow_action_handle_update()``
2876 without destroying flow and creating flow again. The fields that could be
2877 updated depend on the type of the ``action`` and different for every type.
2879 The indirect action specified data (e.g. counter) can be queried by
2880 ``rte_flow_action_handle_query()``.
2882 .. _table_rte_flow_action_handle:
2892 Action: ``MODIFY_FIELD``
2893 ^^^^^^^^^^^^^^^^^^^^^^^^
2895 Modify ``dst`` field according to ``op`` selected (set, addition,
2896 subtraction) with ``width`` bits of data from ``src`` field.
2898 Any arbitrary header field (as well as mark, metadata or tag values)
2899 can be used as both source and destination fields as set by ``field``.
2900 The immediate value ``RTE_FLOW_FIELD_VALUE`` (or a pointer to it
2901 ``RTE_FLOW_FIELD_POINTER``) is allowed as a source only.
2902 ``RTE_FLOW_FIELD_START`` is used to point to the beginning of a packet.
2903 See ``enum rte_flow_field_id`` for the list of supported fields.
2905 ``op`` selects the operation to perform on a destination field.
2906 - ``set`` copies the data from ``src`` field to ``dst`` field.
2907 - ``add`` adds together ``dst`` and ``src`` and stores the result into ``dst``.
2908 - ``sub`` subtracts ``src`` from ``dst`` and stores the result into ``dst``
2910 ``width`` defines a number of bits to use from ``src`` field.
2912 ``level`` is used to access any packet field on any encapsulation level
2913 as well as any tag element in the tag array.
2914 - ``0`` means the default behaviour. Depending on the packet type, it can
2915 mean outermost, innermost or anything in between.
2916 - ``1`` requests access to the outermost packet encapsulation level.
2917 - ``2`` and subsequent values requests access to the specified packet
2918 encapsulation level, from outermost to innermost (lower to higher values).
2919 For the tag array (in case of multiple tags are supported and present)
2920 ``level`` translates directly into the array index.
2922 ``offset`` specifies the number of bits to skip from a field's start.
2923 That allows performing a partial copy of the needed part or to divide a big
2924 packet field into multiple smaller fields. Alternatively, ``offset`` allows
2925 going past the specified packet field boundary to copy a field to an
2926 arbitrary place in a packet, essentially providing a way to copy any part of
2927 a packet to any other part of it.
2929 ``value`` sets an immediate value to be used as a source or points to a
2930 location of the value in memory. It is used instead of ``level`` and ``offset``
2931 for ``RTE_FLOW_FIELD_VALUE`` and ``RTE_FLOW_FIELD_POINTER`` respectively.
2933 .. _table_rte_flow_action_modify_field:
2935 .. table:: MODIFY_FIELD
2937 +---------------+-------------------------+
2939 +===============+=========================+
2940 | ``op`` | operation to perform |
2941 +---------------+-------------------------+
2942 | ``dst`` | destination field |
2943 +---------------+-------------------------+
2944 | ``src`` | source field |
2945 +---------------+-------------------------+
2946 | ``width`` | number of bits to use |
2947 +---------------+-------------------------+
2949 .. _table_rte_flow_action_modify_data:
2951 .. table:: destination/source field definition
2953 +---------------+----------------------------------------------------------+
2955 +===============+==========================================================+
2956 | ``field`` | ID: packet field, mark, meta, tag, immediate, pointer |
2957 +---------------+----------------------------------------------------------+
2958 | ``level`` | encapsulation level of a packet field or tag array index |
2959 +---------------+----------------------------------------------------------+
2960 | ``offset`` | number of bits to skip at the beginning |
2961 +---------------+----------------------------------------------------------+
2962 | ``value`` | immediate value or a pointer to this value |
2963 +---------------+----------------------------------------------------------+
2965 Action: ``CONNTRACK``
2966 ^^^^^^^^^^^^^^^^^^^^^
2968 Create a conntrack (connection tracking) context with the provided information.
2970 In stateful session like TCP, the conntrack action provides the ability to
2971 examine every packet of this connection and associate the state to every
2972 packet. It will help to realize the stateful offload of connections with little
2973 software participation. For example, the packets with invalid state may be
2974 handled by the software. The control packets could be handled in the hardware.
2975 The software just need to query the state of a connection when needed, and then
2976 decide how to handle the flow rules and conntrack context.
2978 A conntrack context should be created via ``rte_flow_action_handle_create()``
2979 before using. Then the handle with ``INDIRECT`` type is used for a flow rule
2980 creation. If a flow rule with an opposite direction needs to be created, the
2981 ``rte_flow_action_handle_update()`` should be used to modify the direction.
2983 Not all the fields of the ``struct rte_flow_action_conntrack`` will be used
2984 for a conntrack context creating, depending on the HW, and they should be
2985 in host byte order. PMD should convert them into network byte order when
2988 The ``struct rte_flow_modify_conntrack`` should be used for an updating.
2990 The current conntrack context information could be queried via the
2991 ``rte_flow_action_handle_query()`` interface.
2993 .. _table_rte_flow_action_conntrack:
2995 .. table:: CONNTRACK
2997 +--------------------------+-------------------------------------------------------------+
2999 +==========================+=============================================================+
3000 | ``peer_port`` | peer port number |
3001 +--------------------------+-------------------------------------------------------------+
3002 | ``is_original_dir`` | direction of this connection for creating flow rule |
3003 +--------------------------+-------------------------------------------------------------+
3004 | ``enable`` | enable the conntrack context |
3005 +--------------------------+-------------------------------------------------------------+
3006 | ``live_connection`` | one ack was seen for this connection |
3007 +--------------------------+-------------------------------------------------------------+
3008 | ``selective_ack`` | SACK enabled |
3009 +--------------------------+-------------------------------------------------------------+
3010 | ``challenge_ack_passed`` | a challenge ack has passed |
3011 +--------------------------+-------------------------------------------------------------+
3012 | ``last_direction`` | direction of the last passed packet |
3013 +--------------------------+-------------------------------------------------------------+
3014 | ``liberal_mode`` | only report state change |
3015 +--------------------------+-------------------------------------------------------------+
3016 | ``state`` | current state |
3017 +--------------------------+-------------------------------------------------------------+
3018 | ``max_ack_window`` | maximal window scaling factor |
3019 +--------------------------+-------------------------------------------------------------+
3020 | ``retransmission_limit`` | maximal retransmission times |
3021 +--------------------------+-------------------------------------------------------------+
3022 | ``original_dir`` | TCP parameters of the original direction |
3023 +--------------------------+-------------------------------------------------------------+
3024 | ``reply_dir`` | TCP parameters of the reply direction |
3025 +--------------------------+-------------------------------------------------------------+
3026 | ``last_window`` | window size of the last passed packet |
3027 +--------------------------+-------------------------------------------------------------+
3028 | ``last_seq`` | sequence number of the last passed packet |
3029 +--------------------------+-------------------------------------------------------------+
3030 | ``last_ack`` | acknowledgment number the last passed packet |
3031 +--------------------------+-------------------------------------------------------------+
3032 | ``last_end`` | sum of ack number and length of the last passed packet |
3033 +--------------------------+-------------------------------------------------------------+
3035 .. _table_rte_flow_tcp_dir_param:
3037 .. table:: configuration parameters for each direction
3039 +---------------------+---------------------------------------------------------+
3041 +=====================+=========================================================+
3042 | ``scale`` | TCP window scaling factor |
3043 +---------------------+---------------------------------------------------------+
3044 | ``close_initiated`` | FIN sent from this direction |
3045 +---------------------+---------------------------------------------------------+
3046 | ``last_ack_seen`` | an ACK packet received |
3047 +---------------------+---------------------------------------------------------+
3048 | ``data_unacked`` | unacknowledged data for packets from this direction |
3049 +---------------------+---------------------------------------------------------+
3050 | ``sent_end`` | max{seq + len} seen in sent packets |
3051 +---------------------+---------------------------------------------------------+
3052 | ``reply_end`` | max{sack + max{win, 1}} seen in reply packets |
3053 +---------------------+---------------------------------------------------------+
3054 | ``max_win`` | max{max{win, 1}} + {sack - ack} seen in sent packets |
3055 +---------------------+---------------------------------------------------------+
3056 | ``max_ack`` | max{ack} + seen in sent packets |
3057 +---------------------+---------------------------------------------------------+
3059 .. _table_rte_flow_modify_conntrack:
3061 .. table:: update a conntrack context
3063 +----------------+-------------------------------------------------+
3065 +================+=================================================+
3066 | ``new_ct`` | new conntrack information |
3067 +----------------+-------------------------------------------------+
3068 | ``direction`` | direction will be updated |
3069 +----------------+-------------------------------------------------+
3070 | ``state`` | other fields except direction will be updated |
3071 +----------------+-------------------------------------------------+
3072 | ``reserved`` | reserved bits |
3073 +----------------+-------------------------------------------------+
3075 Action: ``METER_COLOR``
3076 ^^^^^^^^^^^^^^^^^^^^^^^
3078 Color the packet to reflect the meter color result.
3080 The meter action must be configured before meter color action.
3081 Meter color action is set to a color to reflect the meter color result.
3082 Set the meter color in the mbuf to the selected color.
3083 The meter color action output color is the output color of the packet,
3084 which is set in the packet meta-data (i.e. struct ``rte_mbuf::sched::color``)
3086 .. _table_rte_flow_action_meter_color:
3088 .. table:: METER_COLOR
3090 +-----------------+--------------+
3092 +=================+==============+
3093 | ``meter_color`` | Packet color |
3094 +-----------------+--------------+
3096 Action: ``PORT_REPRESENTOR``
3097 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3099 At embedded switch level, send matching traffic to the given ethdev.
3101 Term **ethdev** and the concept of **port representor** are synonymous.
3102 The **represented port** is an *entity* plugged to the embedded switch
3103 at the opposite end of the "wire" leading to the ethdev.
3107 .--------------------.
3108 | PORT_REPRESENTOR | Ethdev (Application Port Referred to by its ID)
3109 '--------------------'
3119 .----------. .--------------------.
3120 | Switch | <== | Matching Traffic |
3121 '----------' '--------------------'
3131 .--------------------.
3132 | REPRESENTED_PORT | Net / Guest / Another Ethdev (Same Application)
3133 '--------------------'
3136 - Requires `Attribute: Transfer`_.
3138 .. _table_rte_flow_action_ethdev:
3140 .. table:: ``struct rte_flow_action_ethdev``
3142 +-------------+----------------+
3144 +=============+================+
3145 | ``port_id`` | ethdev port ID |
3146 +-------------+----------------+
3148 See also `Item: PORT_REPRESENTOR`_.
3150 Action: ``REPRESENTED_PORT``
3151 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3153 At embedded switch level, send matching traffic to
3154 the entity represented by the given ethdev.
3156 Term **ethdev** and the concept of **port representor** are synonymous.
3157 The **represented port** is an *entity* plugged to the embedded switch
3158 at the opposite end of the "wire" leading to the ethdev.
3162 .--------------------.
3163 | PORT_REPRESENTOR | Ethdev (Application Port Referred to by its ID)
3164 '--------------------'
3174 .----------. .--------------------.
3175 | Switch | <== | Matching Traffic |
3176 '----------' '--------------------'
3186 .--------------------.
3187 | REPRESENTED_PORT | Net / Guest / Another Ethdev (Same Application)
3188 '--------------------'
3191 - Requires `Attribute: Transfer`_.
3193 This action is meant to use the same structure as `Action: PORT_REPRESENTOR`_.
3195 See also `Item: REPRESENTED_PORT`_.
3200 All specified pattern items (``enum rte_flow_item_type``) and actions
3201 (``enum rte_flow_action_type``) use positive identifiers.
3203 The negative space is reserved for dynamic types generated by PMDs during
3204 run-time. PMDs may encounter them as a result but must not accept negative
3205 identifiers they are not aware of.
3207 A method to generate them remains to be defined.
3209 Application may use PMD dynamic items or actions in flow rules. In that case
3210 size of configuration object in dynamic element must be a pointer size.
3215 A rather simple API with few functions is provided to fully manage flow
3218 Each created flow rule is associated with an opaque, PMD-specific handle
3219 pointer. The application is responsible for keeping it until the rule is
3222 Flows rules are represented by ``struct rte_flow`` objects.
3227 Given that expressing a definite set of device capabilities is not
3228 practical, a dedicated function is provided to check if a flow rule is
3229 supported and can be created.
3234 rte_flow_validate(uint16_t port_id,
3235 const struct rte_flow_attr *attr,
3236 const struct rte_flow_item pattern[],
3237 const struct rte_flow_action actions[],
3238 struct rte_flow_error *error);
3240 The flow rule is validated for correctness and whether it could be accepted
3241 by the device given sufficient resources. The rule is checked against the
3242 current device mode and queue configuration. The flow rule may also
3243 optionally be validated against existing flow rules and device resources.
3244 This function has no effect on the target device.
3246 The returned value is guaranteed to remain valid only as long as no
3247 successful calls to ``rte_flow_create()`` or ``rte_flow_destroy()`` are made
3248 in the meantime and no device parameter affecting flow rules in any way are
3249 modified, due to possible collisions or resource limitations (although in
3250 such cases ``EINVAL`` should not be returned).
3254 - ``port_id``: port identifier of Ethernet device.
3255 - ``attr``: flow rule attributes.
3256 - ``pattern``: pattern specification (list terminated by the END pattern
3258 - ``actions``: associated actions (list terminated by the END action).
3259 - ``error``: perform verbose error reporting if not NULL. PMDs initialize
3260 this structure in case of error only.
3264 - 0 if flow rule is valid and can be created. A negative errno value
3265 otherwise (``rte_errno`` is also set), the following errors are defined.
3266 - ``-ENOSYS``: underlying device does not support this functionality.
3267 - ``-EINVAL``: unknown or invalid rule specification.
3268 - ``-ENOTSUP``: valid but unsupported rule specification (e.g. partial
3269 bit-masks are unsupported).
3270 - ``EEXIST``: collision with an existing rule. Only returned if device
3271 supports flow rule collision checking and there was a flow rule
3272 collision. Not receiving this return code is no guarantee that creating
3273 the rule will not fail due to a collision.
3274 - ``ENOMEM``: not enough memory to execute the function, or if the device
3275 supports resource validation, resource limitation on the device.
3276 - ``-EBUSY``: action cannot be performed due to busy device resources, may
3277 succeed if the affected queues or even the entire port are in a stopped
3278 state (see ``rte_eth_dev_rx_queue_stop()`` and ``rte_eth_dev_stop()``).
3283 Creating a flow rule is similar to validating one, except the rule is
3284 actually created and a handle returned.
3289 rte_flow_create(uint16_t port_id,
3290 const struct rte_flow_attr *attr,
3291 const struct rte_flow_item pattern[],
3292 const struct rte_flow_action *actions[],
3293 struct rte_flow_error *error);
3297 - ``port_id``: port identifier of Ethernet device.
3298 - ``attr``: flow rule attributes.
3299 - ``pattern``: pattern specification (list terminated by the END pattern
3301 - ``actions``: associated actions (list terminated by the END action).
3302 - ``error``: perform verbose error reporting if not NULL. PMDs initialize
3303 this structure in case of error only.
3307 A valid handle in case of success, NULL otherwise and ``rte_errno`` is set
3308 to the positive version of one of the error codes defined for
3309 ``rte_flow_validate()``.
3314 Flow rules destruction is not automatic, and a queue or a port should not be
3315 released if any are still attached to them. Applications must take care of
3316 performing this step before releasing resources.
3321 rte_flow_destroy(uint16_t port_id,
3322 struct rte_flow *flow,
3323 struct rte_flow_error *error);
3326 Failure to destroy a flow rule handle may occur when other flow rules depend
3327 on it, and destroying it would result in an inconsistent state.
3329 This function is only guaranteed to succeed if handles are destroyed in
3330 reverse order of their creation.
3334 - ``port_id``: port identifier of Ethernet device.
3335 - ``flow``: flow rule handle to destroy.
3336 - ``error``: perform verbose error reporting if not NULL. PMDs initialize
3337 this structure in case of error only.
3341 - 0 on success, a negative errno value otherwise and ``rte_errno`` is set.
3346 Convenience function to destroy all flow rule handles associated with a
3347 port. They are released as with successive calls to ``rte_flow_destroy()``.
3352 rte_flow_flush(uint16_t port_id,
3353 struct rte_flow_error *error);
3355 In the unlikely event of failure, handles are still considered destroyed and
3356 no longer valid but the port must be assumed to be in an inconsistent state.
3360 - ``port_id``: port identifier of Ethernet device.
3361 - ``error``: perform verbose error reporting if not NULL. PMDs initialize
3362 this structure in case of error only.
3366 - 0 on success, a negative errno value otherwise and ``rte_errno`` is set.
3371 Query an existing flow rule.
3373 This function allows retrieving flow-specific data such as counters. Data
3374 is gathered by special actions which must be present in the flow rule
3380 rte_flow_query(uint16_t port_id,
3381 struct rte_flow *flow,
3382 const struct rte_flow_action *action,
3384 struct rte_flow_error *error);
3388 - ``port_id``: port identifier of Ethernet device.
3389 - ``flow``: flow rule handle to query.
3390 - ``action``: action to query, this must match prototype from flow rule.
3391 - ``data``: pointer to storage for the associated query data type.
3392 - ``error``: perform verbose error reporting if not NULL. PMDs initialize
3393 this structure in case of error only.
3397 - 0 on success, a negative errno value otherwise and ``rte_errno`` is set.
3399 .. _flow_isolated_mode:
3404 The general expectation for ingress traffic is that flow rules process it
3405 first; the remaining unmatched or pass-through traffic usually ends up in a
3406 queue (with or without RSS, locally or in some sub-device instance)
3407 depending on the global configuration settings of a port.
3409 While fine from a compatibility standpoint, this approach makes drivers more
3410 complex as they have to check for possible side effects outside of this API
3411 when creating or destroying flow rules. It results in a more limited set of
3412 available rule types due to the way device resources are assigned (e.g. no
3413 support for the RSS action even on capable hardware).
3415 Given that nonspecific traffic can be handled by flow rules as well,
3416 isolated mode is a means for applications to tell a driver that ingress on
3417 the underlying port must be injected from the defined flow rules only; that
3418 no default traffic is expected outside those rules.
3420 This has the following benefits:
3422 - Applications get finer-grained control over the kind of traffic they want
3423 to receive (no traffic by default).
3425 - More importantly they control at what point nonspecific traffic is handled
3426 relative to other flow rules, by adjusting priority levels.
3428 - Drivers can assign more hardware resources to flow rules and expand the
3429 set of supported rule types.
3431 Because toggling isolated mode may cause profound changes to the ingress
3432 processing path of a driver, it may not be possible to leave it once
3433 entered. Likewise, existing flow rules or global configuration settings may
3434 prevent a driver from entering isolated mode.
3436 Applications relying on this mode are therefore encouraged to toggle it as
3437 soon as possible after device initialization, ideally before the first call
3438 to ``rte_eth_dev_configure()`` to avoid possible failures due to conflicting
3441 Once effective, the following functionality has no effect on the underlying
3442 port and may return errors such as ``ENOTSUP`` ("not supported"):
3444 - Toggling promiscuous mode.
3445 - Toggling allmulticast mode.
3446 - Configuring MAC addresses.
3447 - Configuring multicast addresses.
3448 - Configuring VLAN filters.
3449 - Configuring global RSS settings.
3454 rte_flow_isolate(uint16_t port_id, int set, struct rte_flow_error *error);
3458 - ``port_id``: port identifier of Ethernet device.
3459 - ``set``: nonzero to enter isolated mode, attempt to leave it otherwise.
3460 - ``error``: perform verbose error reporting if not NULL. PMDs initialize
3461 this structure in case of error only.
3465 - 0 on success, a negative errno value otherwise and ``rte_errno`` is set.
3467 Verbose error reporting
3468 -----------------------
3470 The defined *errno* values may not be accurate enough for users or
3471 application developers who want to investigate issues related to flow rules
3472 management. A dedicated error object is defined for this purpose:
3476 enum rte_flow_error_type {
3477 RTE_FLOW_ERROR_TYPE_NONE, /**< No error. */
3478 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, /**< Cause unspecified. */
3479 RTE_FLOW_ERROR_TYPE_HANDLE, /**< Flow rule (handle). */
3480 RTE_FLOW_ERROR_TYPE_ATTR_GROUP, /**< Group field. */
3481 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY, /**< Priority field. */
3482 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS, /**< Ingress field. */
3483 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, /**< Egress field. */
3484 RTE_FLOW_ERROR_TYPE_ATTR, /**< Attributes structure. */
3485 RTE_FLOW_ERROR_TYPE_ITEM_NUM, /**< Pattern length. */
3486 RTE_FLOW_ERROR_TYPE_ITEM, /**< Specific pattern item. */
3487 RTE_FLOW_ERROR_TYPE_ACTION_NUM, /**< Number of actions. */
3488 RTE_FLOW_ERROR_TYPE_ACTION, /**< Specific action. */
3491 struct rte_flow_error {
3492 enum rte_flow_error_type type; /**< Cause field and error types. */
3493 const void *cause; /**< Object responsible for the error. */
3494 const char *message; /**< Human-readable error message. */
3497 Error type ``RTE_FLOW_ERROR_TYPE_NONE`` stands for no error, in which case
3498 remaining fields can be ignored. Other error types describe the type of the
3499 object pointed by ``cause``.
3501 If non-NULL, ``cause`` points to the object responsible for the error. For a
3502 flow rule, this may be a pattern item or an individual action.
3504 If non-NULL, ``message`` provides a human-readable error message.
3506 This object is normally allocated by applications and set by PMDs in case of
3507 error, the message points to a constant string which does not need to be
3508 freed by the application, however its pointer can be considered valid only
3509 as long as its associated DPDK port remains configured. Closing the
3510 underlying device or unloading the PMD invalidates it.
3521 rte_flow_error_set(struct rte_flow_error *error,
3523 enum rte_flow_error_type type,
3525 const char *message);
3527 This function initializes ``error`` (if non-NULL) with the provided
3528 parameters and sets ``rte_errno`` to ``code``. A negative error ``code`` is
3537 rte_flow_conv(enum rte_flow_conv_op op,
3541 struct rte_flow_error *error);
3543 Convert ``src`` to ``dst`` according to operation ``op``. Possible
3546 - Attributes, pattern item or action duplication.
3547 - Duplication of an entire pattern or list of actions.
3548 - Duplication of a complete flow rule description.
3549 - Pattern item or action name retrieval.
3551 Tunneled traffic offload
3552 ~~~~~~~~~~~~~~~~~~~~~~~~
3554 rte_flow API provides the building blocks for vendor-agnostic flow
3555 classification offloads. The rte_flow "patterns" and "actions"
3556 primitives are fine-grained, thus enabling DPDK applications the
3557 flexibility to offload network stacks and complex pipelines.
3558 Applications wishing to offload tunneled traffic are required to use
3559 the rte_flow primitives, such as group, meta, mark, tag, and others to
3560 model their high-level objects. The hardware model design for
3561 high-level software objects is not trivial. Furthermore, an optimal
3562 design is often vendor-specific.
3564 When hardware offloads tunneled traffic in multi-group logic,
3565 partially offloaded packets may arrive to the application after they
3566 were modified in hardware. In this case, the application may need to
3567 restore the original packet headers. Consider the following sequence:
3568 The application decaps a packet in one group and jumps to a second
3569 group where it tries to match on a 5-tuple, that will miss and send
3570 the packet to the application. In this case, the application does not
3571 receive the original packet but a modified one. Also, in this case,
3572 the application cannot match on the outer header fields, such as VXLAN
3575 There are several possible ways to use rte_flow "patterns" and
3576 "actions" to resolve the issues above. For example:
3578 1 Mapping headers to a hardware registers using the
3579 rte_flow_action_mark/rte_flow_action_tag/rte_flow_set_meta objects.
3581 2 Apply the decap only at the last offload stage after all the
3582 "patterns" were matched and the packet will be fully offloaded.
3584 Every approach has its pros and cons and is highly dependent on the
3585 hardware vendor. For example, some hardware may have a limited number
3586 of registers while other hardware could not support inner actions and
3587 must decap before accessing inner headers.
3589 The tunnel offload model resolves these issues. The model goals are:
3591 1 Provide a unified application API to offload tunneled traffic that
3592 is capable to match on outer headers after decap.
3594 2 Allow the application to restore the outer header of partially
3597 The tunnel offload model does not introduce new elements to the
3598 existing RTE flow model and is implemented as a set of helper
3601 For the application to work with the tunnel offload API it
3602 has to adjust flow rules in multi-table tunnel offload in the
3605 1 Remove explicit call to decap action and replace it with PMD actions
3606 obtained from rte_flow_tunnel_decap_and_set() helper.
3608 2 Add PMD items obtained from rte_flow_tunnel_match() helper to all
3609 other rules in the tunnel offload sequence.
3611 The model requirements:
3613 Software application must initialize
3614 rte_tunnel object with tunnel parameters before calling
3615 rte_flow_tunnel_decap_set() & rte_flow_tunnel_match().
3617 PMD actions array obtained in rte_flow_tunnel_decap_set() must be
3618 released by application with rte_flow_action_release() call.
3620 PMD items array obtained with rte_flow_tunnel_match() must be released
3621 by application with rte_flow_item_release() call. Application can
3622 release PMD items and actions after rule was created. However, if the
3623 application needs to create additional rule for the same tunnel it
3624 will need to obtain PMD items again.
3626 Application cannot destroy rte_tunnel object before it releases all
3627 PMD actions & PMD items referencing that tunnel.
3632 - DPDK does not keep track of flow rules definitions or flow rule objects
3633 automatically. Applications may keep track of the former and must keep
3634 track of the latter. PMDs may also do it for internal needs, however this
3635 must not be relied on by applications.
3637 - Flow rules are not maintained between successive port initializations. An
3638 application exiting without releasing them and restarting must re-create
3641 - API operations are synchronous and blocking (``EAGAIN`` cannot be
3644 - Stopping the data path (TX/RX) should not be necessary when managing flow
3645 rules. If this cannot be achieved naturally or with workarounds (such as
3646 temporarily replacing the burst function pointers), an appropriate error
3647 code must be returned (``EBUSY``).
3649 - Applications, not PMDs, are responsible for maintaining flow rules
3650 configuration when closing, stopping or restarting a port or performing other
3651 actions which may affect them.
3652 Applications must assume that after port close, stop or restart all flows
3653 related to that port are not valid, hardware rules are destroyed and relevant
3654 PMD resources are released.
3656 For devices exposing multiple ports sharing global settings affected by flow
3659 - All ports under DPDK control must behave consistently, PMDs are
3660 responsible for making sure that existing flow rules on a port are not
3661 affected by other ports.
3663 - Ports not under DPDK control (unaffected or handled by other applications)
3664 are user's responsibility. They may affect existing flow rules and cause
3665 undefined behavior. PMDs aware of this may prevent flow rules creation
3666 altogether in such cases.
3671 The PMD interface is defined in ``rte_flow_driver.h``. It is not subject to
3672 API/ABI versioning constraints as it is not exposed to applications and may
3673 evolve independently.
3675 The PMD interface is based on callbacks pointed by the ``struct rte_flow_ops``.
3677 - PMD callbacks implement exactly the interface described in `Rules
3678 management`_, except for the port ID argument which has already been
3679 converted to a pointer to the underlying ``struct rte_eth_dev``.
3681 - Public API functions do not process flow rules definitions at all before
3682 calling PMD functions (no basic error checking, no validation
3683 whatsoever). They only make sure these callbacks are non-NULL or return
3684 the ``ENOSYS`` (function not supported) error.
3686 This interface additionally defines the following helper function:
3688 - ``rte_flow_ops_get()``: get generic flow operations structure from a
3691 If PMD interfaces don't support re-entrancy/multi-thread safety,
3692 the rte_flow API functions will protect threads by mutex per port.
3693 The application can check whether ``RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE``
3694 is set in ``dev_flags``, meaning the PMD is thread-safe regarding rte_flow,
3695 so the API level protection is disabled.
3696 Please note that this API-level mutex protects only rte_flow functions,
3697 other control path functions are not in scope.
3699 Device compatibility
3700 --------------------
3702 No known implementation supports all the described features.
3704 Unsupported features or combinations are not expected to be fully emulated
3705 in software by PMDs for performance reasons. Partially supported features
3706 may be completed in software as long as hardware performs most of the work
3707 (such as queue redirection and packet recognition).
3709 However PMDs are expected to do their best to satisfy application requests
3710 by working around hardware limitations as long as doing so does not affect
3711 the behavior of existing flow rules.
3713 The following sections provide a few examples of such cases and describe how
3714 PMDs should handle them, they are based on limitations built into the
3720 Each flow rule comes with its own, per-layer bit-masks, while hardware may
3721 support only a single, device-wide bit-mask for a given layer type, so that
3722 two IPv4 rules cannot use different bit-masks.
3724 The expected behavior in this case is that PMDs automatically configure
3725 global bit-masks according to the needs of the first flow rule created.
3727 Subsequent rules are allowed only if their bit-masks match those, the
3728 ``EEXIST`` error code should be returned otherwise.
3730 Unsupported layer types
3731 ~~~~~~~~~~~~~~~~~~~~~~~
3733 Many protocols can be simulated by crafting patterns with the `Item: RAW`_
3736 PMDs can rely on this capability to simulate support for protocols with
3737 headers not directly recognized by hardware.
3739 ``ANY`` pattern item
3740 ~~~~~~~~~~~~~~~~~~~~
3742 This pattern item stands for anything, which can be difficult to translate
3743 to something hardware would understand, particularly if followed by more
3746 Consider the following pattern:
3748 .. _table_rte_flow_unsupported_any:
3750 .. table:: Pattern with ANY as L3
3752 +-------+-----------------------+
3754 +=======+=======================+
3756 +-------+-----+---------+-------+
3757 | 1 | ANY | ``num`` | ``1`` |
3758 +-------+-----+---------+-------+
3760 +-------+-----------------------+
3762 +-------+-----------------------+
3764 Knowing that TCP does not make sense with something other than IPv4 and IPv6
3765 as L3, such a pattern may be translated to two flow rules instead:
3767 .. _table_rte_flow_unsupported_any_ipv4:
3769 .. table:: ANY replaced with IPV4
3771 +-------+--------------------+
3773 +=======+====================+
3775 +-------+--------------------+
3776 | 1 | IPV4 (zeroed mask) |
3777 +-------+--------------------+
3779 +-------+--------------------+
3781 +-------+--------------------+
3785 .. _table_rte_flow_unsupported_any_ipv6:
3787 .. table:: ANY replaced with IPV6
3789 +-------+--------------------+
3791 +=======+====================+
3793 +-------+--------------------+
3794 | 1 | IPV6 (zeroed mask) |
3795 +-------+--------------------+
3797 +-------+--------------------+
3799 +-------+--------------------+
3801 Note that as soon as a ANY rule covers several layers, this approach may
3802 yield a large number of hidden flow rules. It is thus suggested to only
3803 support the most common scenarios (anything as L2 and/or L3).
3808 - When combined with `Action: QUEUE`_, packet counting (`Action: COUNT`_)
3809 and tagging (`Action: MARK`_ or `Action: FLAG`_) may be implemented in
3810 software as long as the target queue is used by a single rule.
3812 - When a single target queue is provided, `Action: RSS`_ can also be
3813 implemented through `Action: QUEUE`_.
3818 While it would naturally make sense, flow rules cannot be assumed to be
3819 processed by hardware in the same order as their creation for several
3822 - They may be managed internally as a tree or a hash table instead of a
3824 - Removing a flow rule before adding another one can either put the new rule
3825 at the end of the list or reuse a freed entry.
3826 - Duplication may occur when packets are matched by several rules.
3828 For overlapping rules (particularly in order to use `Action: PASSTHRU`_)
3829 predictable behavior is only guaranteed by using different priority levels.
3831 Priority levels are not necessarily implemented in hardware, or may be
3832 severely limited (e.g. a single priority bit).
3834 For these reasons, priority levels may be implemented purely in software by
3837 - For devices expecting flow rules to be added in the correct order, PMDs
3838 may destroy and re-create existing rules after adding a new one with
3841 - A configurable number of dummy or empty rules can be created at
3842 initialization time to save high priority slots for later.
3844 - In order to save priority levels, PMDs may evaluate whether rules are
3845 likely to collide and adjust their priority accordingly.
3848 .. _OpenFlow Switch Specification: https://www.opennetworking.org/software-defined-standards/specifications/