xref: /dpdk/doc/guides/prog_guide/rte_flow.rst (revision cf8a8a8f)
1..  SPDX-License-Identifier: BSD-3-Clause
2    Copyright 2016 6WIND S.A.
3    Copyright 2016 Mellanox Technologies, Ltd
4
5Generic flow API (rte_flow)
6===========================
7
8Overview
9--------
10
11This API provides a generic means to configure hardware to match specific
12ingress or egress traffic, alter its fate and query related counters
13according to any number of user-defined rules.
14
15It is named *rte_flow* after the prefix used for all its symbols, and is
16defined in ``rte_flow.h``.
17
18- Matching can be performed on packet data (protocol headers, payload) and
19  properties (e.g. associated physical port, virtual device function ID).
20
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.
24
25Flow rule
26---------
27
28Description
29~~~~~~~~~~~
30
31A flow rule is the combination of attributes with a matching pattern and a
32list of actions. Flow rules form the basis of this API.
33
34Flow rules can have several distinct actions (such as counting,
35encapsulating, decapsulating before redirecting packets to a particular
36queue, etc.), instead of relying on several rules to achieve this and having
37applications deal with hardware implementation details regarding their
38order.
39
40Support for different priority levels on a rule basis is provided, for
41example in order to force a more specific rule to come before a more generic
42one for packets matched by both. However hardware support for more than a
43single priority level cannot be guaranteed. When supported, the number of
44available priority levels is usually low, which is why they can also be
45implemented in software by PMDs (e.g. missing priority levels may be
46emulated by reordering rules).
47
48In order to remain as hardware-agnostic as possible, by default all rules
49are considered to have the same priority, which means that the order between
50overlapping rules (when a packet is matched by several filters) is
51undefined.
52
53PMDs may refuse to create overlapping rules at a given priority level when
54they can be detected (e.g. if a pattern matches an existing filter).
55
56Thus predictable results for a given priority level can only be achieved
57with non-overlapping rules, using perfect matching on all protocol layers.
58
59Flow rules can also be grouped, the flow rule priority is specific to the
60group they belong to. All flow rules in a given group are thus processed within
61the context of that group. Groups are not linked by default, so the logical
62hierarchy of groups must be explicitly defined by flow rules themselves in each
63group using the JUMP action to define the next group to redirect too. Only flow
64rules defined in the default group 0 are guarantee to be matched against, this
65makes group 0 the origin of any group hierarchy defined by an application.
66
67Support for multiple actions per rule may be implemented internally on top
68of non-default hardware priorities, as a result both features may not be
69simultaneously available to applications.
70
71Considering that allowed pattern/actions combinations cannot be known in
72advance and would result in an impractically large number of capabilities to
73expose, a method is provided to validate a given rule from the current
74device configuration state.
75
76This enables applications to check if the rule types they need is supported
77at initialization time, before starting their data path. This method can be
78used anytime, its only requirement being that the resources needed by a rule
79should exist (e.g. a target RX queue should be configured first).
80
81Each defined rule is associated with an opaque handle managed by the PMD,
82applications are responsible for keeping it. These can be used for queries
83and rules management, such as retrieving counters or other data and
84destroying them.
85
86To avoid resource leaks on the PMD side, handles must be explicitly
87destroyed by the application before releasing associated resources such as
88queues and ports.
89
90The following sections cover:
91
92- **Attributes** (represented by ``struct rte_flow_attr``): properties of a
93  flow rule such as its direction (ingress or egress) and priority.
94
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
98  inverted matching.
99
100- **Matching pattern**: traffic properties to look for, a combination of any
101  number of items.
102
103- **Actions** (represented by ``struct rte_flow_action``): operations to
104  perform whenever a packet is matched by a pattern.
105
106Attributes
107~~~~~~~~~~
108
109Attribute: Group
110^^^^^^^^^^^^^^^^
111
112Flow rules can be grouped by assigning them a common group number. Groups
113allow a logical hierarchy of flow rule groups (tables) to be defined. These
114groups can be supported virtually in the PMD or in the physical device.
115Group 0 is the default group and this is the only group which flows are
116guarantee to matched against, all subsequent groups can only be reached by
117way of the JUMP action from a matched flow rule.
118
119Although optional, applications are encouraged to group similar rules as
120much as possible to fully take advantage of hardware capabilities
121(e.g. optimized matching) and work around limitations (e.g. a single pattern
122type possibly allowed in a given group), while being aware that the groups
123hierarchies must be programmed explicitly.
124
125Note that support for more than a single group is not guaranteed.
126
127Attribute: Priority
128^^^^^^^^^^^^^^^^^^^
129
130A priority level can be assigned to a flow rule, lower values
131denote higher priority, with 0 as the maximum.
132
133Priority levels are arbitrary and up to the application, they do
134not need to be contiguous nor start from 0, however the maximum number
135varies between devices and may be affected by existing flow rules.
136
137A flow which matches multiple rules in the same group will always matched by
138the rule with the highest priority in that group.
139
140If a packet is matched by several rules of a given group for a given
141priority level, the outcome is undefined. It can take any path, may be
142duplicated or even cause unrecoverable errors.
143
144Note that support for more than a single priority level is not guaranteed.
145
146Attribute: Traffic direction
147^^^^^^^^^^^^^^^^^^^^^^^^^^^^
148
149Flow rule patterns apply to inbound and/or outbound traffic.
150
151In the context of this API, **ingress** and **egress** respectively stand
152for **inbound** and **outbound** based on the standpoint of the application
153creating a flow rule.
154
155There are no exceptions to this definition.
156
157Several pattern items and actions are valid and can be used in both
158directions. At least one direction must be specified.
159
160Specifying both directions at once for a given rule is not recommended but
161may be valid in a few cases (e.g. shared counters).
162
163Attribute: Transfer
164^^^^^^^^^^^^^^^^^^^
165
166Instead of simply matching the properties of traffic as it would appear on a
167given DPDK port ID, enabling this attribute transfers a flow rule to the
168lowest possible level of any device endpoints found in the pattern.
169
170When supported, this effectively enables an application to reroute traffic
171not necessarily intended for it (e.g. coming from or addressed to different
172physical ports, VFs or applications) at the device level.
173
174It complements the behavior of some pattern items such as `Item: PHY_PORT`_
175and is meaningless without them.
176
177When transferring flow rules, **ingress** and **egress** attributes
178(`Attribute: Traffic direction`_) keep their original meaning, as if
179processing traffic emitted or received by the application.
180
181Pattern item
182~~~~~~~~~~~~
183
184Pattern items fall in two categories:
185
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.
189
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.
193
194Item specification structures are used to match specific values among
195protocol fields (or item properties). Documentation describes for each item
196whether they are associated with one and their type name if so.
197
198Up to three structures of the same type can be set for a given item:
199
200- ``spec``: values to match (e.g. a given IPv4 address).
201
202- ``last``: upper bound for an inclusive range with corresponding fields in
203  ``spec``.
204
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).
208
209Usage restrictions and expected behavior:
210
211- Setting either ``mask`` or ``last`` without ``spec`` is an error.
212
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.
216
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).
220
221- Not setting any of them (assuming item type allows it) is equivalent to
222  providing an empty (zeroed) ``mask`` for broad (nonspecific) matching.
223
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*.
229
230Example of an item specification matching an Ethernet header:
231
232.. _table_rte_flow_pattern_item_example:
233
234.. table:: Ethernet item
235
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   +----------+----------+-----------------------+
253
254Non-masked bits stand for any value (shown as ``?`` below), Ethernet headers
255with the following properties are thus matched:
256
257- ``src``: ``??:??:01:02:03:??``
258- ``dst``: ``??:??:??:??:??:01``
259- ``type``: ``0x????``
260
261Matching pattern
262~~~~~~~~~~~~~~~~
263
264A pattern is formed by stacking items starting from the lowest protocol
265layer to match. This stacking restriction does not apply to meta items which
266can be placed anywhere in the stack without affecting the meaning of the
267resulting pattern.
268
269Patterns are terminated by END items.
270
271Examples:
272
273.. _table_rte_flow_tcpv4_as_l4:
274
275.. table:: TCPv4 as L4
276
277   +-------+----------+
278   | Index | Item     |
279   +=======+==========+
280   | 0     | Ethernet |
281   +-------+----------+
282   | 1     | IPv4     |
283   +-------+----------+
284   | 2     | TCP      |
285   +-------+----------+
286   | 3     | END      |
287   +-------+----------+
288
289|
290
291.. _table_rte_flow_tcpv6_in_vxlan:
292
293.. table:: TCPv6 in VXLAN
294
295   +-------+------------+
296   | Index | Item       |
297   +=======+============+
298   | 0     | Ethernet   |
299   +-------+------------+
300   | 1     | IPv4       |
301   +-------+------------+
302   | 2     | UDP        |
303   +-------+------------+
304   | 3     | VXLAN      |
305   +-------+------------+
306   | 4     | Ethernet   |
307   +-------+------------+
308   | 5     | IPv6       |
309   +-------+------------+
310   | 6     | TCP        |
311   +-------+------------+
312   | 7     | END        |
313   +-------+------------+
314
315|
316
317.. _table_rte_flow_tcpv4_as_l4_meta:
318
319.. table:: TCPv4 as L4 with meta items
320
321   +-------+----------+
322   | Index | Item     |
323   +=======+==========+
324   | 0     | VOID     |
325   +-------+----------+
326   | 1     | Ethernet |
327   +-------+----------+
328   | 2     | VOID     |
329   +-------+----------+
330   | 3     | IPv4     |
331   +-------+----------+
332   | 4     | TCP      |
333   +-------+----------+
334   | 5     | VOID     |
335   +-------+----------+
336   | 6     | VOID     |
337   +-------+----------+
338   | 7     | END      |
339   +-------+----------+
340
341The above example shows how meta items do not affect packet data matching
342items, as long as those remain stacked properly. The resulting matching
343pattern is identical to "TCPv4 as L4".
344
345.. _table_rte_flow_udpv6_anywhere:
346
347.. table:: UDPv6 anywhere
348
349   +-------+------+
350   | Index | Item |
351   +=======+======+
352   | 0     | IPv6 |
353   +-------+------+
354   | 1     | UDP  |
355   +-------+------+
356   | 2     | END  |
357   +-------+------+
358
359If supported by the PMD, omitting one or several protocol layers at the
360bottom of the stack as in the above example (missing an Ethernet
361specification) enables looking up anywhere in packets.
362
363It is unspecified whether the payload of supported encapsulations
364(e.g. VXLAN payload) is matched by such a pattern, which may apply to inner,
365outer or both packets.
366
367.. _table_rte_flow_invalid_l3:
368
369.. table:: Invalid, missing L3
370
371   +-------+----------+
372   | Index | Item     |
373   +=======+==========+
374   | 0     | Ethernet |
375   +-------+----------+
376   | 1     | UDP      |
377   +-------+----------+
378   | 2     | END      |
379   +-------+----------+
380
381The 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
383top of the stack.
384
385Meta item types
386~~~~~~~~~~~~~~~
387
388They match meta-data or affect pattern processing instead of matching packet
389data directly, most of them do not need a specification structure. This
390particularity allows them to be specified anywhere in the stack without
391causing any side effect.
392
393Item: ``END``
394^^^^^^^^^^^^^
395
396End marker for item lists. Prevents further processing of items, thereby
397ending the pattern.
398
399- Its numeric value is 0 for convenience.
400- PMD support is mandatory.
401- ``spec``, ``last`` and ``mask`` are ignored.
402
403.. _table_rte_flow_item_end:
404
405.. table:: END
406
407   +----------+---------+
408   | Field    | Value   |
409   +==========+=========+
410   | ``spec`` | ignored |
411   +----------+---------+
412   | ``last`` | ignored |
413   +----------+---------+
414   | ``mask`` | ignored |
415   +----------+---------+
416
417Item: ``VOID``
418^^^^^^^^^^^^^^
419
420Used as a placeholder for convenience. It is ignored and simply discarded by
421PMDs.
422
423- PMD support is mandatory.
424- ``spec``, ``last`` and ``mask`` are ignored.
425
426.. _table_rte_flow_item_void:
427
428.. table:: VOID
429
430   +----------+---------+
431   | Field    | Value   |
432   +==========+=========+
433   | ``spec`` | ignored |
434   +----------+---------+
435   | ``last`` | ignored |
436   +----------+---------+
437   | ``mask`` | ignored |
438   +----------+---------+
439
440One usage example for this type is generating rules that share a common
441prefix quickly without reallocating memory, only by updating item types:
442
443.. _table_rte_flow_item_void_example:
444
445.. table:: TCP, UDP or ICMP as L4
446
447   +-------+--------------------+
448   | Index | Item               |
449   +=======+====================+
450   | 0     | Ethernet           |
451   +-------+--------------------+
452   | 1     | IPv4               |
453   +-------+------+------+------+
454   | 2     | UDP  | VOID | VOID |
455   +-------+------+------+------+
456   | 3     | VOID | TCP  | VOID |
457   +-------+------+------+------+
458   | 4     | VOID | VOID | ICMP |
459   +-------+------+------+------+
460   | 5     | END                |
461   +-------+--------------------+
462
463Item: ``INVERT``
464^^^^^^^^^^^^^^^^
465
466Inverted matching, i.e. process packets that do not match the pattern.
467
468- ``spec``, ``last`` and ``mask`` are ignored.
469
470.. _table_rte_flow_item_invert:
471
472.. table:: INVERT
473
474   +----------+---------+
475   | Field    | Value   |
476   +==========+=========+
477   | ``spec`` | ignored |
478   +----------+---------+
479   | ``last`` | ignored |
480   +----------+---------+
481   | ``mask`` | ignored |
482   +----------+---------+
483
484Usage example, matching non-TCPv4 packets only:
485
486.. _table_rte_flow_item_invert_example:
487
488.. table:: Anything but TCPv4
489
490   +-------+----------+
491   | Index | Item     |
492   +=======+==========+
493   | 0     | INVERT   |
494   +-------+----------+
495   | 1     | Ethernet |
496   +-------+----------+
497   | 2     | IPv4     |
498   +-------+----------+
499   | 3     | TCP      |
500   +-------+----------+
501   | 4     | END      |
502   +-------+----------+
503
504Item: ``PF``
505^^^^^^^^^^^^
506
507Matches traffic originating from (ingress) or going to (egress) the physical
508function of the current device.
509
510If supported, should work even if the physical function is not managed by
511the application and thus not associated with a DPDK port ID.
512
513- Can be combined with any number of `Item: VF`_ to match both PF and VF
514  traffic.
515- ``spec``, ``last`` and ``mask`` must not be set.
516
517.. _table_rte_flow_item_pf:
518
519.. table:: PF
520
521   +----------+-------+
522   | Field    | Value |
523   +==========+=======+
524   | ``spec`` | unset |
525   +----------+-------+
526   | ``last`` | unset |
527   +----------+-------+
528   | ``mask`` | unset |
529   +----------+-------+
530
531Item: ``VF``
532^^^^^^^^^^^^
533
534Matches traffic originating from (ingress) or going to (egress) a given
535virtual function of the current device.
536
537If supported, should work even if the virtual function is not managed by the
538application and thus not associated with a DPDK port ID.
539
540Note this pattern item does not match VF representors traffic which, as
541separate entities, should be addressed through their own DPDK port IDs.
542
543- Can be specified multiple times to match traffic addressed to several VF
544  IDs.
545- Can be combined with a PF item to match both PF and VF traffic.
546- Default ``mask`` matches any VF ID.
547
548.. _table_rte_flow_item_vf:
549
550.. table:: VF
551
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   +----------+----------+---------------------------+
561
562Item: ``PHY_PORT``
563^^^^^^^^^^^^^^^^^^
564
565Matches traffic originating from (ingress) or going to (egress) a physical
566port of the underlying device.
567
568The first PHY_PORT item overrides the physical port normally associated with
569the specified DPDK input port (port_id). This item can be provided several
570times to match additional physical ports.
571
572Note that physical ports are not necessarily tied to DPDK input ports
573(port_id) when those are not under DPDK control. Possible values are
574specific to each device, they are not necessarily indexed from zero and may
575not be contiguous.
576
577As a device property, the list of allowed values as well as the value
578associated with a port_id should be retrieved by other means.
579
580- Default ``mask`` matches any port index.
581
582.. _table_rte_flow_item_phy_port:
583
584.. table:: PHY_PORT
585
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   +----------+-----------+--------------------------------+
595
596Item: ``PORT_ID``
597^^^^^^^^^^^^^^^^^
598
599Matches traffic originating from (ingress) or going to (egress) a given DPDK
600port ID.
601
602Normally only supported if the port ID in question is known by the
603underlying PMD and related to the device the flow rule is created against.
604
605This must not be confused with `Item: PHY_PORT`_ which refers to the
606physical port of a device, whereas `Item: PORT_ID`_ refers to a ``struct
607rte_eth_dev`` object on the application side (also known as "port
608representor" depending on the kind of underlying device).
609
610- Default ``mask`` matches the specified DPDK port ID.
611
612.. _table_rte_flow_item_port_id:
613
614.. table:: PORT_ID
615
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   +----------+----------+-----------------------------+
625
626Item: ``MARK``
627^^^^^^^^^^^^^^
628
629Matches an arbitrary integer value which was set using the ``MARK`` action in
630a previously matched rule.
631
632This item can only specified once as a match criteria as the ``MARK`` action can
633only be specified once in a flow action.
634
635Note the value of MARK field is arbitrary and application defined.
636
637Depending on the underlying implementation the MARK item may be supported on
638the physical device, with virtual groups in the PMD or not at all.
639
640- Default ``mask`` matches any integer value.
641
642.. _table_rte_flow_item_mark:
643
644.. table:: MARK
645
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   +----------+----------+---------------------------+
655
656Item: ``TAG``
657^^^^^^^^^^^^^
658
659Matches tag item set by other flows. Multiple tags are supported by specifying
660``index``.
661
662- Default ``mask`` matches the specified tag value and index.
663
664.. _table_rte_flow_item_tag:
665
666.. table:: TAG
667
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   +----------+-----------+---------------------------------------+
683
684Item: ``META``
685^^^^^^^^^^^^^^^^^
686
687Matches 32 bit metadata item set.
688
689On egress, metadata can be set either by mbuf metadata field with
690PKT_TX_DYNF_METADATA flag or ``SET_META`` action. On ingress, ``SET_META``
691action 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.
693
694- Default ``mask`` matches the specified Rx metadata value.
695
696.. _table_rte_flow_item_meta:
697
698.. table:: META
699
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   +----------+----------+---------------------------------------+
709
710Data matching item types
711~~~~~~~~~~~~~~~~~~~~~~~~
712
713Most of these are basically protocol header definitions with associated
714bit-masks. They must be specified (stacked) from lowest to highest protocol
715layer to form a matching pattern.
716
717Item: ``ANY``
718^^^^^^^^^^^^^
719
720Matches any protocol in place of the current layer, a single ANY may also
721stand for several protocol layers.
722
723This is usually specified as the first pattern item when looking for a
724protocol anywhere in a packet.
725
726- Default ``mask`` stands for any number of layers.
727
728.. _table_rte_flow_item_any:
729
730.. table:: ANY
731
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   +----------+----------+--------------------------------------+
741
742Example for VXLAN TCP payload matching regardless of outer L3 (IPv4 or IPv6)
743and L4 (UDP) both matched by the first ANY specification, and inner L3 (IPv4
744or IPv6) matched by the second ANY specification:
745
746.. _table_rte_flow_item_any_example:
747
748.. table:: TCP in VXLAN with wildcards
749
750   +-------+------+----------+----------+-------+
751   | Index | Item | Field    | Subfield | Value |
752   +=======+======+==========+==========+=======+
753   | 0     | Ethernet                           |
754   +-------+------+----------+----------+-------+
755   | 1     | ANY  | ``spec`` | ``num``  | 2     |
756   +-------+------+----------+----------+-------+
757   | 2     | VXLAN                              |
758   +-------+------------------------------------+
759   | 3     | Ethernet                           |
760   +-------+------+----------+----------+-------+
761   | 4     | ANY  | ``spec`` | ``num``  | 1     |
762   +-------+------+----------+----------+-------+
763   | 5     | TCP                                |
764   +-------+------------------------------------+
765   | 6     | END                                |
766   +-------+------------------------------------+
767
768Item: ``RAW``
769^^^^^^^^^^^^^
770
771Matches a byte string of a given length at a given offset.
772
773Offset is either absolute (using the start of the packet) or relative to the
774end of the previous matched item in the stack, in which case negative values
775are allowed.
776
777If search is enabled, offset is used as the starting point. The search area
778can be delimited by setting limit to a nonzero value, which is the maximum
779number of bytes after offset where the pattern may start.
780
781Matching a zero-length pattern is allowed, doing so resets the relative
782offset for subsequent items.
783
784- This type does not support ranges (``last`` field).
785- Default ``mask`` matches all fields exactly.
786
787.. _table_rte_flow_item_raw:
788
789.. table:: RAW
790
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   +----------+----------------------------------------------------------------+
812
813Example pattern looking for several strings at various offsets of a UDP
814payload, using combined RAW items:
815
816.. _table_rte_flow_item_raw_example:
817
818.. table:: UDP payload matching
819
820   +-------+------+----------+--------------+-------+
821   | Index | Item | Field    | Subfield     | Value |
822   +=======+======+==========+==============+=======+
823   | 0     | Ethernet                               |
824   +-------+----------------------------------------+
825   | 1     | IPv4                                   |
826   +-------+----------------------------------------+
827   | 2     | UDP                                    |
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   +-------+------+----------+--------------+-------+
865   | 6     | END                                    |
866   +-------+----------------------------------------+
867
868This translates to:
869
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.
873
874Such a packet may be represented as follows (not to scale)::
875
876 0                     >= 10 B           == 20 B
877 |                  |<--------->|     |<--------->|
878 |                  |           |     |           |
879 |-----|------|-----|-----|-----|-----|-----------|-----|------|
880 | ETH | IPv4 | UDP | ... | baz | foo | ......... | bar | .... |
881 |-----|------|-----|-----|-----|-----|-----------|-----|------|
882                          |                             |
883                          |<--------------------------->|
884                                      == 29 B
885
886Note that matching subsequent pattern items would resume after "baz", not
887"bar" since matching is always performed after the previous item of the
888stack.
889
890Item: ``ETH``
891^^^^^^^^^^^^^
892
893Matches an Ethernet header.
894
895The ``type`` field either stands for "EtherType" or "TPID" when followed by
896so-called layer 2.5 pattern items such as ``RTE_FLOW_ITEM_TYPE_VLAN``. In
897the latter case, ``type`` refers to that of the outer header, with the inner
898EtherType/TPID provided by the subsequent pattern item. This is the same
899order as on the wire.
900If the ``type`` field contains a TPID value, then only tagged packets with the
901specified TPID will match the pattern.
902The field ``has_vlan`` can be used to match any type of tagged packets,
903instead of using the ``type`` field.
904If the ``type`` and ``has_vlan`` fields are not specified, then both tagged
905and untagged packets will match the pattern.
906
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.
912
913Item: ``VLAN``
914^^^^^^^^^^^^^^
915
916Matches an 802.1Q/ad VLAN tag.
917
918The corresponding standard outer EtherType (TPID) values are
919``RTE_ETHER_TYPE_VLAN`` or ``RTE_ETHER_TYPE_QINQ``. It can be overridden by the
920preceding pattern item.
921If a ``VLAN`` item is present in the pattern, then only tagged packets will
922match the pattern.
923The field ``has_more_vlan`` can be used to match any type of tagged packets,
924instead of using the ``inner_type field``.
925If the ``inner_type`` and ``has_more_vlan`` fields are not specified,
926then any tagged packets will match the pattern.
927
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).
932
933Item: ``IPV4``
934^^^^^^^^^^^^^^
935
936Matches an IPv4 header.
937
938Note: IPv4 options are handled by dedicated pattern items.
939
940- ``hdr``: IPv4 header definition (``rte_ip.h``).
941- Default ``mask`` matches source and destination addresses only.
942
943Item: ``IPV6``
944^^^^^^^^^^^^^^
945
946Matches an IPv6 header.
947
948Dedicated flags indicate if header contains specific extension headers.
949To match on packets containing a specific extension header, an application
950should match on the dedicated flag set to 1.
951To match on packets not containing a specific extension header, an application
952should match on the dedicated flag clear to 0.
953In case application doesn't care about the existence of a specific extension
954header, it should not specify the dedicated flag for matching.
955
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.
967
968Item: ``ICMP``
969^^^^^^^^^^^^^^
970
971Matches an ICMP header.
972
973- ``hdr``: ICMP header definition (``rte_icmp.h``).
974- Default ``mask`` matches ICMP type and code only.
975
976Item: ``UDP``
977^^^^^^^^^^^^^
978
979Matches a UDP header.
980
981- ``hdr``: UDP header definition (``rte_udp.h``).
982- Default ``mask`` matches source and destination ports only.
983
984Item: ``TCP``
985^^^^^^^^^^^^^
986
987Matches a TCP header.
988
989- ``hdr``: TCP header definition (``rte_tcp.h``).
990- Default ``mask`` matches source and destination ports only.
991
992Item: ``SCTP``
993^^^^^^^^^^^^^^
994
995Matches a SCTP header.
996
997- ``hdr``: SCTP header definition (``rte_sctp.h``).
998- Default ``mask`` matches source and destination ports only.
999
1000Item: ``VXLAN``
1001^^^^^^^^^^^^^^^
1002
1003Matches a VXLAN header (RFC 7348).
1004
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.
1010
1011Item: ``E_TAG``
1012^^^^^^^^^^^^^^^
1013
1014Matches an IEEE 802.1BR E-Tag header.
1015
1016The corresponding standard outer EtherType (TPID) value is
1017``RTE_ETHER_TYPE_ETAG``. It can be overridden by the preceding pattern item.
1018
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.
1026
1027Item: ``NVGRE``
1028^^^^^^^^^^^^^^^
1029
1030Matches a NVGRE header (RFC 7637).
1031
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.
1039
1040Item: ``MPLS``
1041^^^^^^^^^^^^^^
1042
1043Matches a MPLS header.
1044
1045- ``label_tc_s_ttl``: label, TC, Bottom of Stack and TTL.
1046- Default ``mask`` matches label only.
1047
1048Item: ``GRE``
1049^^^^^^^^^^^^^
1050
1051Matches a GRE header.
1052
1053- ``c_rsvd0_ver``: checksum, reserved 0 and version.
1054- ``protocol``: protocol type.
1055- Default ``mask`` matches protocol only.
1056
1057Item: ``GRE_KEY``
1058^^^^^^^^^^^^^^^^^
1059
1060Matches a GRE key field.
1061This should be preceded by item ``GRE``.
1062
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"
1065
1066Item: ``FUZZY``
1067^^^^^^^^^^^^^^^
1068
1069Fuzzy pattern match, expect faster than default.
1070
1071This is for device that support fuzzy match option. Usually a fuzzy match is
1072fast but the cost is accuracy. i.e. Signature Match only match pattern's hash
1073value, but it is possible two different patterns have the same hash value.
1074
1075Matching accuracy level can be configured by threshold. Driver can divide the
1076range of threshold and map to different accuracy levels that device support.
1077
1078Threshold 0 means perfect match (no fuzziness), while threshold 0xffffffff
1079means fuzziest match.
1080
1081.. _table_rte_flow_item_fuzzy:
1082
1083.. table:: FUZZY
1084
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   +----------+---------------+--------------------------------------------------+
1094
1095Usage example, fuzzy match a TCPv4 packets:
1096
1097.. _table_rte_flow_item_fuzzy_example:
1098
1099.. table:: Fuzzy matching
1100
1101   +-------+----------+
1102   | Index | Item     |
1103   +=======+==========+
1104   | 0     | FUZZY    |
1105   +-------+----------+
1106   | 1     | Ethernet |
1107   +-------+----------+
1108   | 2     | IPv4     |
1109   +-------+----------+
1110   | 3     | TCP      |
1111   +-------+----------+
1112   | 4     | END      |
1113   +-------+----------+
1114
1115Item: ``GTP``, ``GTPC``, ``GTPU``
1116^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1117
1118Matches a GTPv1 header.
1119
1120Note: GTP, GTPC and GTPU use the same structure. GTPC and GTPU item
1121are defined for a user-friendly API when creating GTP-C and GTP-U
1122flow rules.
1123
1124- ``v_pt_rsv_flags``: version (3b), protocol type (1b), reserved (1b),
1125  extension header flag (1b), sequence number flag (1b), N-PDU number
1126  flag (1b).
1127- ``msg_type``: message type.
1128- ``msg_len``: message length.
1129- ``teid``: tunnel endpoint identifier.
1130- Default ``mask`` matches teid only.
1131
1132Item: ``ESP``
1133^^^^^^^^^^^^^
1134
1135Matches an ESP header.
1136
1137- ``hdr``: ESP header definition (``rte_esp.h``).
1138- Default ``mask`` matches SPI only.
1139
1140Item: ``GENEVE``
1141^^^^^^^^^^^^^^^^
1142
1143Matches a GENEVE header.
1144
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.
1151
1152Item: ``VXLAN-GPE``
1153^^^^^^^^^^^^^^^^^^^
1154
1155Matches a VXLAN-GPE header (draft-ietf-nvo3-vxlan-gpe-05).
1156
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.
1163
1164Item: ``ARP_ETH_IPV4``
1165^^^^^^^^^^^^^^^^^^^^^^
1166
1167Matches an ARP header for Ethernet/IPv4.
1168
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.
1179
1180Item: ``IPV6_EXT``
1181^^^^^^^^^^^^^^^^^^
1182
1183Matches the presence of any IPv6 extension header.
1184
1185- ``next_hdr``: next header.
1186- Default ``mask`` matches ``next_hdr``.
1187
1188Normally preceded by any of:
1189
1190- `Item: IPV6`_
1191- `Item: IPV6_EXT`_
1192
1193Item: ``IPV6_FRAG_EXT``
1194^^^^^^^^^^^^^^^^^^^^^^^
1195
1196Matches the presence of IPv6 fragment extension header.
1197
1198- ``hdr``: IPv6 fragment extension header definition (``rte_ip.h``).
1199
1200Normally preceded by any of:
1201
1202- `Item: IPV6`_
1203- `Item: IPV6_EXT`_
1204
1205Item: ``ICMP6``
1206^^^^^^^^^^^^^^^
1207
1208Matches any ICMPv6 header.
1209
1210- ``type``: ICMPv6 type.
1211- ``code``: ICMPv6 code.
1212- ``checksum``: ICMPv6 checksum.
1213- Default ``mask`` matches ``type`` and ``code``.
1214
1215Item: ``ICMP6_ND_NS``
1216^^^^^^^^^^^^^^^^^^^^^
1217
1218Matches an ICMPv6 neighbor discovery solicitation.
1219
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.
1226
1227Item: ``ICMP6_ND_NA``
1228^^^^^^^^^^^^^^^^^^^^^
1229
1230Matches an ICMPv6 neighbor discovery advertisement.
1231
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.
1239
1240Item: ``ICMP6_ND_OPT``
1241^^^^^^^^^^^^^^^^^^^^^^
1242
1243Matches the presence of any ICMPv6 neighbor discovery option.
1244
1245- ``type``: ND option type.
1246- ``length``: ND option length.
1247- Default ``mask`` matches type only.
1248
1249Normally preceded by any of:
1250
1251- `Item: ICMP6_ND_NA`_
1252- `Item: ICMP6_ND_NS`_
1253- `Item: ICMP6_ND_OPT`_
1254
1255Item: ``ICMP6_ND_OPT_SLA_ETH``
1256^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1257
1258Matches an ICMPv6 neighbor discovery source Ethernet link-layer address
1259option.
1260
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.
1265
1266Normally preceded by any of:
1267
1268- `Item: ICMP6_ND_NA`_
1269- `Item: ICMP6_ND_OPT`_
1270
1271Item: ``ICMP6_ND_OPT_TLA_ETH``
1272^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1273
1274Matches an ICMPv6 neighbor discovery target Ethernet link-layer address
1275option.
1276
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.
1281
1282Normally preceded by any of:
1283
1284- `Item: ICMP6_ND_NS`_
1285- `Item: ICMP6_ND_OPT`_
1286
1287Item: ``META``
1288^^^^^^^^^^^^^^
1289
1290Matches an application specific 32 bit metadata item.
1291
1292- Default ``mask`` matches the specified metadata value.
1293
1294Item: ``GTP_PSC``
1295^^^^^^^^^^^^^^^^^
1296
1297Matches a GTP PDU extension header with type 0x85.
1298
1299- ``pdu_type``: PDU type.
1300- ``qfi``: QoS flow identifier.
1301- Default ``mask`` matches QFI only.
1302
1303Item: ``PPPOES``, ``PPPOED``
1304^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1305
1306Matches a PPPoE header.
1307
1308- ``version_type``: version (4b), type (4b).
1309- ``code``: message type.
1310- ``session_id``: session identifier.
1311- ``length``: payload length.
1312
1313Item: ``PPPOE_PROTO_ID``
1314^^^^^^^^^^^^^^^^^^^^^^^^
1315
1316Matches a PPPoE session protocol identifier.
1317
1318- ``proto_id``: PPP protocol identifier.
1319- Default ``mask`` matches proto_id only.
1320
1321Item: ``NSH``
1322^^^^^^^^^^^^^
1323
1324Matches a network service header (RFC 8300).
1325
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.
1337
1338
1339Item: ``IGMP``
1340^^^^^^^^^^^^^^
1341
1342Matches a Internet Group Management Protocol (RFC 2236).
1343
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.
1349
1350
1351Item: ``AH``
1352^^^^^^^^^^^^
1353
1354Matches a IP Authentication Header (RFC 4302).
1355
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.
1362
1363Item: ``HIGIG2``
1364^^^^^^^^^^^^^^^^^
1365
1366Matches a HIGIG2 header field. It is layer 2.5 protocol and used in
1367Broadcom switches.
1368
1369- Default ``mask`` matches classification and vlan.
1370
1371Item: ``L2TPV3OIP``
1372^^^^^^^^^^^^^^^^^^^
1373
1374Matches a L2TPv3 over IP header.
1375
1376- ``session_id``: L2TPv3 over IP session identifier.
1377- Default ``mask`` matches session_id only.
1378
1379Item: ``PFCP``
1380^^^^^^^^^^^^^^
1381
1382Matches a PFCP Header.
1383
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.
1389
1390Item: ``ECPRI``
1391^^^^^^^^^^^^^^^
1392
1393Matches a eCPRI header.
1394
1395- ``hdr``: eCPRI header definition (``rte_ecpri.h``).
1396- Default ``mask`` matches nothing, for all eCPRI messages.
1397
1398Item: ``PACKET_INTEGRITY_CHECKS``
1399^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1400
1401Matches packet integrity.
1402For some devices application needs to enable integration checks in HW
1403before using this item.
1404
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.
1419
1420Item: ``CONNTRACK``
1421^^^^^^^^^^^^^^^^^^^
1422
1423Matches a conntrack state after conntrack action.
1424
1425- ``flags``: conntrack packet state flags.
1426- Default ``mask`` matches all state bits.
1427
1428Actions
1429~~~~~~~
1430
1431Each possible action is represented by a type.
1432An action can have an associated configuration object.
1433Several actions combined in a list can be assigned
1434to a flow rule and are performed in order.
1435
1436They fall in three categories:
1437
1438- Actions that modify the fate of matching traffic, for instance by dropping
1439  or assigning it a specific destination.
1440
1441- Actions that modify matching traffic contents or its properties. This
1442  includes adding/removing encapsulation, encryption, compression and marks.
1443
1444- Actions related to the flow rule itself, such as updating counters or
1445  making it non-terminating.
1446
1447Flow rules being terminating by default, not specifying any action of the
1448fate kind results in undefined behavior. This applies to both ingress and
1449egress.
1450
1451PASSTHRU, when supported, makes a flow rule non-terminating.
1452
1453Like matching patterns, action lists are terminated by END items.
1454
1455Example of action that redirects packets to queue index 10:
1456
1457.. _table_rte_flow_action_example:
1458
1459.. table:: Queue action
1460
1461   +-----------+-------+
1462   | Field     | Value |
1463   +===========+=======+
1464   | ``index`` | 10    |
1465   +-----------+-------+
1466
1467Actions are performed in list order:
1468
1469.. _table_rte_flow_count_then_drop:
1470
1471.. table:: Count then drop
1472
1473   +-------+--------+
1474   | Index | Action |
1475   +=======+========+
1476   | 0     | COUNT  |
1477   +-------+--------+
1478   | 1     | DROP   |
1479   +-------+--------+
1480   | 2     | END    |
1481   +-------+--------+
1482
1483|
1484
1485.. _table_rte_flow_mark_count_redirect:
1486
1487.. table:: Mark, count then redirect
1488
1489   +-------+--------+------------+-------+
1490   | Index | Action | Field      | Value |
1491   +=======+========+============+=======+
1492   | 0     | MARK   | ``mark``   | 0x2a  |
1493   +-------+--------+------------+-------+
1494   | 1     | COUNT  | ``shared`` | 0     |
1495   |       |        +------------+-------+
1496   |       |        | ``id``     | 0     |
1497   +-------+--------+------------+-------+
1498   | 2     | QUEUE  | ``queue``  | 10    |
1499   +-------+--------+------------+-------+
1500   | 3     | END                         |
1501   +-------+-----------------------------+
1502
1503|
1504
1505.. _table_rte_flow_redirect_queue_5:
1506
1507.. table:: Redirect to queue 5
1508
1509   +-------+--------+-----------+-------+
1510   | Index | Action | Field     | Value |
1511   +=======+========+===========+=======+
1512   | 0     | DROP                       |
1513   +-------+--------+-----------+-------+
1514   | 1     | QUEUE  | ``queue`` | 5     |
1515   +-------+--------+-----------+-------+
1516   | 2     | END                        |
1517   +-------+----------------------------+
1518
1519In the above example, while DROP and QUEUE must be performed in order, both
1520have to happen before reaching END. Only QUEUE has a visible effect.
1521
1522Note that such a list may be thought as ambiguous and rejected on that
1523basis.
1524
1525.. _table_rte_flow_redirect_queue_5_3:
1526
1527.. table:: Redirect to queues 5 and 3
1528
1529   +-------+--------+-----------+-------+
1530   | Index | Action | Field     | Value |
1531   +=======+========+===========+=======+
1532   | 0     | QUEUE  | ``queue`` | 5     |
1533   +-------+--------+-----------+-------+
1534   | 1     | VOID                       |
1535   +-------+--------+-----------+-------+
1536   | 2     | QUEUE  | ``queue`` | 3     |
1537   +-------+--------+-----------+-------+
1538   | 3     | END                        |
1539   +-------+----------------------------+
1540
1541As previously described, all actions must be taken into account. This
1542effectively duplicates traffic to both queues. The above example also shows
1543that VOID is ignored.
1544
1545Action types
1546~~~~~~~~~~~~
1547
1548Common action types are described in this section.
1549
1550Action: ``END``
1551^^^^^^^^^^^^^^^
1552
1553End marker for action lists. Prevents further processing of actions, thereby
1554ending the list.
1555
1556- Its numeric value is 0 for convenience.
1557- PMD support is mandatory.
1558- No configurable properties.
1559
1560.. _table_rte_flow_action_end:
1561
1562.. table:: END
1563
1564   +---------------+
1565   | Field         |
1566   +===============+
1567   | no properties |
1568   +---------------+
1569
1570Action: ``VOID``
1571^^^^^^^^^^^^^^^^
1572
1573Used as a placeholder for convenience. It is ignored and simply discarded by
1574PMDs.
1575
1576- PMD support is mandatory.
1577- No configurable properties.
1578
1579.. _table_rte_flow_action_void:
1580
1581.. table:: VOID
1582
1583   +---------------+
1584   | Field         |
1585   +===============+
1586   | no properties |
1587   +---------------+
1588
1589Action: ``PASSTHRU``
1590^^^^^^^^^^^^^^^^^^^^
1591
1592Leaves traffic up for additional processing by subsequent flow rules; makes
1593a flow rule non-terminating.
1594
1595- No configurable properties.
1596
1597.. _table_rte_flow_action_passthru:
1598
1599.. table:: PASSTHRU
1600
1601   +---------------+
1602   | Field         |
1603   +===============+
1604   | no properties |
1605   +---------------+
1606
1607Example to copy a packet to a queue and continue processing by subsequent
1608flow rules:
1609
1610.. _table_rte_flow_action_passthru_example:
1611
1612.. table:: Copy to queue 8
1613
1614   +-------+--------+-----------+-------+
1615   | Index | Action | Field     | Value |
1616   +=======+========+===========+=======+
1617   | 0     | PASSTHRU                   |
1618   +-------+--------+-----------+-------+
1619   | 1     | QUEUE  | ``queue`` | 8     |
1620   +-------+--------+-----------+-------+
1621   | 2     | END                        |
1622   +-------+----------------------------+
1623
1624Action: ``JUMP``
1625^^^^^^^^^^^^^^^^
1626
1627Redirects packets to a group on the current device.
1628
1629In a hierarchy of groups, which can be used to represent physical or logical
1630flow group/tables on the device, this action redirects the matched flow to
1631the specified group on that device.
1632
1633If a matched flow is redirected to a table which doesn't contain a matching
1634rule for that flow then the behavior is undefined and the resulting behavior
1635is up to the specific device. Best practice when using groups would be define
1636a default flow rule for each group which a defines the default actions in that
1637group so a consistent behavior is defined.
1638
1639Defining an action for matched flow in a group to jump to a group which is
1640higher in the group hierarchy may not be supported by physical devices,
1641depending on how groups are mapped to the physical devices. In the
1642definitions of jump actions, applications should be aware that it may be
1643possible to define flow rules which trigger an undefined behavior causing
1644flows to loop between groups.
1645
1646.. _table_rte_flow_action_jump:
1647
1648.. table:: JUMP
1649
1650   +-----------+------------------------------+
1651   | Field     | Value                        |
1652   +===========+==============================+
1653   | ``group`` | Group to redirect packets to |
1654   +-----------+------------------------------+
1655
1656Action: ``MARK``
1657^^^^^^^^^^^^^^^^
1658
1659Attaches an integer value to packets and sets ``PKT_RX_FDIR`` and
1660``PKT_RX_FDIR_ID`` mbuf flags.
1661
1662This value is arbitrary and application-defined. Maximum allowed value
1663depends on the underlying implementation. It is returned in the
1664``hash.fdir.hi`` mbuf field.
1665
1666.. _table_rte_flow_action_mark:
1667
1668.. table:: MARK
1669
1670   +--------+--------------------------------------+
1671   | Field  | Value                                |
1672   +========+======================================+
1673   | ``id`` | integer value to return with packets |
1674   +--------+--------------------------------------+
1675
1676Action: ``FLAG``
1677^^^^^^^^^^^^^^^^
1678
1679Flags packets. Similar to `Action: MARK`_ without a specific value; only
1680sets the ``PKT_RX_FDIR`` mbuf flag.
1681
1682- No configurable properties.
1683
1684.. _table_rte_flow_action_flag:
1685
1686.. table:: FLAG
1687
1688   +---------------+
1689   | Field         |
1690   +===============+
1691   | no properties |
1692   +---------------+
1693
1694Action: ``QUEUE``
1695^^^^^^^^^^^^^^^^^
1696
1697Assigns packets to a given queue index.
1698
1699.. _table_rte_flow_action_queue:
1700
1701.. table:: QUEUE
1702
1703   +-----------+--------------------+
1704   | Field     | Value              |
1705   +===========+====================+
1706   | ``index`` | queue index to use |
1707   +-----------+--------------------+
1708
1709Action: ``DROP``
1710^^^^^^^^^^^^^^^^
1711
1712Drop packets.
1713
1714- No configurable properties.
1715
1716.. _table_rte_flow_action_drop:
1717
1718.. table:: DROP
1719
1720   +---------------+
1721   | Field         |
1722   +===============+
1723   | no properties |
1724   +---------------+
1725
1726Action: ``COUNT``
1727^^^^^^^^^^^^^^^^^
1728
1729Adds a counter action to a matched flow.
1730
1731If more than one count action is specified in a single flow rule, then each
1732action must specify a unique id.
1733
1734Counters can be retrieved and reset through ``rte_flow_query()``, see
1735``struct rte_flow_query_count``.
1736
1737The shared flag indicates whether the counter is unique to the flow rule the
1738action is specified with, or whether it is a shared counter.
1739
1740For a count action with the shared flag set, then a global device
1741namespace is assumed for the counter id, so that any matched flow rules using
1742a count action with the same counter id on the same port will contribute to
1743that counter.
1744
1745For ports within the same switch domain then the counter id namespace extends
1746to all ports within that switch domain.
1747
1748The shared flag is DEPRECATED and ``INDIRECT`` ``COUNT`` action should be used
1749to make shared counters.
1750
1751.. _table_rte_flow_action_count:
1752
1753.. table:: COUNT
1754
1755   +------------+---------------------------------+
1756   | Field      | Value                           |
1757   +============+=================================+
1758   | ``shared`` | DEPRECATED, shared counter flag |
1759   +------------+---------------------------------+
1760   | ``id``     | counter id                      |
1761   +------------+---------------------------------+
1762
1763Query structure to retrieve and reset flow rule counters:
1764
1765.. _table_rte_flow_query_count:
1766
1767.. table:: COUNT query
1768
1769   +---------------+-----+-----------------------------------+
1770   | Field         | I/O | Value                             |
1771   +===============+=====+===================================+
1772   | ``reset``     | in  | reset counter after query         |
1773   +---------------+-----+-----------------------------------+
1774   | ``hits_set``  | out | ``hits`` field is set             |
1775   +---------------+-----+-----------------------------------+
1776   | ``bytes_set`` | out | ``bytes`` field is set            |
1777   +---------------+-----+-----------------------------------+
1778   | ``hits``      | out | number of hits for this rule      |
1779   +---------------+-----+-----------------------------------+
1780   | ``bytes``     | out | number of bytes through this rule |
1781   +---------------+-----+-----------------------------------+
1782
1783Action: ``RSS``
1784^^^^^^^^^^^^^^^
1785
1786Similar to QUEUE, except RSS is additionally performed on packets to spread
1787them among several queues according to the provided parameters.
1788
1789Unlike global RSS settings used by other DPDK APIs, unsetting the ``types``
1790field does not disable RSS in a flow rule. Doing so instead requests safe
1791unspecified "best-effort" settings from the underlying PMD, which depending
1792on the flow rule, may result in anything ranging from empty (single queue)
1793to all-inclusive RSS.
1794
1795If non-applicable for matching packets RSS types are requested,
1796these RSS types are simply ignored. For example, it happens if:
1797
1798- Hashing of both TCP and UDP ports is requested
1799  (only one can be present in a packet).
1800
1801- Requested RSS types contradict to flow rule pattern
1802  (e.g. pattern has UDP item, but RSS types contain TCP).
1803
1804If requested RSS hash types are not supported by the Ethernet device at all
1805(not reported in ``dev_info.flow_type_rss_offloads``),
1806the flow creation will fail.
1807
1808Note: RSS hash result is stored in the ``hash.rss`` mbuf field which
1809overlaps ``hash.fdir.lo``. Since `Action: MARK`_ sets the ``hash.fdir.hi``
1810field only, both can be requested simultaneously.
1811
1812Also, regarding packet encapsulation ``level``:
1813
1814- ``0`` requests the default behavior. Depending on the packet type, it can
1815  mean outermost, innermost, anything in between or even no RSS.
1816
1817  It basically stands for the innermost encapsulation level RSS can be
1818  performed on according to PMD and device capabilities.
1819
1820- ``1`` requests RSS to be performed on the outermost packet encapsulation
1821  level.
1822
1823- ``2`` and subsequent values request RSS to be performed on the specified
1824   inner packet encapsulation level, from outermost to innermost (lower to
1825   higher values).
1826
1827Values other than ``0`` are not necessarily supported.
1828
1829Requesting a specific RSS level on unrecognized traffic results in undefined
1830behavior. For predictable results, it is recommended to make the flow rule
1831pattern match packet headers up to the requested encapsulation level so that
1832only matching traffic goes through.
1833
1834.. _table_rte_flow_action_rss:
1835
1836.. table:: RSS
1837
1838   +---------------+---------------------------------------------+
1839   | Field         | Value                                       |
1840   +===============+=============================================+
1841   | ``func``      | RSS hash function to apply                  |
1842   +---------------+---------------------------------------------+
1843   | ``level``     | encapsulation level for ``types``           |
1844   +---------------+---------------------------------------------+
1845   | ``types``     | specific RSS hash types (see ``ETH_RSS_*``) |
1846   +---------------+---------------------------------------------+
1847   | ``key_len``   | hash key length in bytes                    |
1848   +---------------+---------------------------------------------+
1849   | ``queue_num`` | number of entries in ``queue``              |
1850   +---------------+---------------------------------------------+
1851   | ``key``       | hash key                                    |
1852   +---------------+---------------------------------------------+
1853   | ``queue``     | queue indices to use                        |
1854   +---------------+---------------------------------------------+
1855
1856Action: ``PF``
1857^^^^^^^^^^^^^^
1858
1859Directs matching traffic to the physical function (PF) of the current
1860device.
1861
1862See `Item: PF`_.
1863
1864- No configurable properties.
1865
1866.. _table_rte_flow_action_pf:
1867
1868.. table:: PF
1869
1870   +---------------+
1871   | Field         |
1872   +===============+
1873   | no properties |
1874   +---------------+
1875
1876Action: ``VF``
1877^^^^^^^^^^^^^^
1878
1879Directs matching traffic to a given virtual function of the current device.
1880
1881Packets matched by a VF pattern item can be redirected to their original VF
1882ID instead of the specified one. This parameter may not be available and is
1883not guaranteed to work properly if the VF part is matched by a prior flow
1884rule or if packets are not addressed to a VF in the first place.
1885
1886See `Item: VF`_.
1887
1888.. _table_rte_flow_action_vf:
1889
1890.. table:: VF
1891
1892   +--------------+--------------------------------+
1893   | Field        | Value                          |
1894   +==============+================================+
1895   | ``original`` | use original VF ID if possible |
1896   +--------------+--------------------------------+
1897   | ``id``       | VF ID                          |
1898   +--------------+--------------------------------+
1899
1900Action: ``PHY_PORT``
1901^^^^^^^^^^^^^^^^^^^^
1902
1903Directs matching traffic to a given physical port index of the underlying
1904device.
1905
1906See `Item: PHY_PORT`_.
1907
1908.. _table_rte_flow_action_phy_port:
1909
1910.. table:: PHY_PORT
1911
1912   +--------------+-------------------------------------+
1913   | Field        | Value                               |
1914   +==============+=====================================+
1915   | ``original`` | use original port index if possible |
1916   +--------------+-------------------------------------+
1917   | ``index``    | physical port index                 |
1918   +--------------+-------------------------------------+
1919
1920Action: ``PORT_ID``
1921^^^^^^^^^^^^^^^^^^^
1922Directs matching traffic to a given DPDK port ID.
1923
1924See `Item: PORT_ID`_.
1925
1926.. _table_rte_flow_action_port_id:
1927
1928.. table:: PORT_ID
1929
1930   +--------------+---------------------------------------+
1931   | Field        | Value                                 |
1932   +==============+=======================================+
1933   | ``original`` | use original DPDK port ID if possible |
1934   +--------------+---------------------------------------+
1935   | ``id``       | DPDK port ID                          |
1936   +--------------+---------------------------------------+
1937
1938Action: ``METER``
1939^^^^^^^^^^^^^^^^^
1940
1941Applies a stage of metering and policing.
1942
1943The metering and policing (MTR) object has to be first created using the
1944rte_mtr_create() API function. The ID of the MTR object is specified as
1945action parameter. More than one flow can use the same MTR object through
1946the meter action. The MTR object can be further updated or queried using
1947the rte_mtr* API.
1948
1949.. _table_rte_flow_action_meter:
1950
1951.. table:: METER
1952
1953   +--------------+---------------+
1954   | Field        | Value         |
1955   +==============+===============+
1956   | ``mtr_id``   | MTR object ID |
1957   +--------------+---------------+
1958
1959Action: ``SECURITY``
1960^^^^^^^^^^^^^^^^^^^^
1961
1962Perform the security action on flows matched by the pattern items
1963according to the configuration of the security session.
1964
1965This action modifies the payload of matched flows. For INLINE_CRYPTO, the
1966security protocol headers and IV are fully provided by the application as
1967specified in the flow pattern. The payload of matching packets is
1968encrypted on egress, and decrypted and authenticated on ingress.
1969For INLINE_PROTOCOL, the security protocol is fully offloaded to HW,
1970providing full encapsulation and decapsulation of packets in security
1971protocols. The flow pattern specifies both the outer security header fields
1972and the inner packet fields. The security session specified in the action
1973must match the pattern parameters.
1974
1975The security session specified in the action must be created on the same
1976port as the flow action that is being specified.
1977
1978The ingress/egress flow attribute should match that specified in the
1979security session if the security session supports the definition of the
1980direction.
1981
1982Multiple flows can be configured to use the same security session.
1983
1984.. _table_rte_flow_action_security:
1985
1986.. table:: SECURITY
1987
1988   +----------------------+--------------------------------------+
1989   | Field                | Value                                |
1990   +======================+======================================+
1991   | ``security_session`` | security session to apply            |
1992   +----------------------+--------------------------------------+
1993
1994The following is an example of configuring IPsec inline using the
1995INLINE_CRYPTO security session:
1996
1997The encryption algorithm, keys and salt are part of the opaque
1998``rte_security_session``. The SA is identified according to the IP and ESP
1999fields in the pattern items.
2000
2001.. _table_rte_flow_item_esp_inline_example:
2002
2003.. table:: IPsec inline crypto flow pattern items.
2004
2005   +-------+----------+
2006   | Index | Item     |
2007   +=======+==========+
2008   | 0     | Ethernet |
2009   +-------+----------+
2010   | 1     | IPv4     |
2011   +-------+----------+
2012   | 2     | ESP      |
2013   +-------+----------+
2014   | 3     | END      |
2015   +-------+----------+
2016
2017.. _table_rte_flow_action_esp_inline_example:
2018
2019.. table:: IPsec inline flow actions.
2020
2021   +-------+----------+
2022   | Index | Action   |
2023   +=======+==========+
2024   | 0     | SECURITY |
2025   +-------+----------+
2026   | 1     | END      |
2027   +-------+----------+
2028
2029Action: ``OF_SET_MPLS_TTL``
2030^^^^^^^^^^^^^^^^^^^^^^^^^^^
2031
2032Implements ``OFPAT_SET_MPLS_TTL`` ("MPLS TTL") as defined by the `OpenFlow
2033Switch Specification`_.
2034
2035.. _table_rte_flow_action_of_set_mpls_ttl:
2036
2037.. table:: OF_SET_MPLS_TTL
2038
2039   +--------------+----------+
2040   | Field        | Value    |
2041   +==============+==========+
2042   | ``mpls_ttl`` | MPLS TTL |
2043   +--------------+----------+
2044
2045Action: ``OF_DEC_MPLS_TTL``
2046^^^^^^^^^^^^^^^^^^^^^^^^^^^
2047
2048Implements ``OFPAT_DEC_MPLS_TTL`` ("decrement MPLS TTL") as defined by the
2049`OpenFlow Switch Specification`_.
2050
2051.. _table_rte_flow_action_of_dec_mpls_ttl:
2052
2053.. table:: OF_DEC_MPLS_TTL
2054
2055   +---------------+
2056   | Field         |
2057   +===============+
2058   | no properties |
2059   +---------------+
2060
2061Action: ``OF_SET_NW_TTL``
2062^^^^^^^^^^^^^^^^^^^^^^^^^
2063
2064Implements ``OFPAT_SET_NW_TTL`` ("IP TTL") as defined by the `OpenFlow
2065Switch Specification`_.
2066
2067.. _table_rte_flow_action_of_set_nw_ttl:
2068
2069.. table:: OF_SET_NW_TTL
2070
2071   +------------+--------+
2072   | Field      | Value  |
2073   +============+========+
2074   | ``nw_ttl`` | IP TTL |
2075   +------------+--------+
2076
2077Action: ``OF_DEC_NW_TTL``
2078^^^^^^^^^^^^^^^^^^^^^^^^^
2079
2080Implements ``OFPAT_DEC_NW_TTL`` ("decrement IP TTL") as defined by the
2081`OpenFlow Switch Specification`_.
2082
2083.. _table_rte_flow_action_of_dec_nw_ttl:
2084
2085.. table:: OF_DEC_NW_TTL
2086
2087   +---------------+
2088   | Field         |
2089   +===============+
2090   | no properties |
2091   +---------------+
2092
2093Action: ``OF_COPY_TTL_OUT``
2094^^^^^^^^^^^^^^^^^^^^^^^^^^^
2095
2096Implements ``OFPAT_COPY_TTL_OUT`` ("copy TTL "outwards" -- from
2097next-to-outermost to outermost") as defined by the `OpenFlow Switch
2098Specification`_.
2099
2100.. _table_rte_flow_action_of_copy_ttl_out:
2101
2102.. table:: OF_COPY_TTL_OUT
2103
2104   +---------------+
2105   | Field         |
2106   +===============+
2107   | no properties |
2108   +---------------+
2109
2110Action: ``OF_COPY_TTL_IN``
2111^^^^^^^^^^^^^^^^^^^^^^^^^^
2112
2113Implements ``OFPAT_COPY_TTL_IN`` ("copy TTL "inwards" -- from outermost to
2114next-to-outermost") as defined by the `OpenFlow Switch Specification`_.
2115
2116.. _table_rte_flow_action_of_copy_ttl_in:
2117
2118.. table:: OF_COPY_TTL_IN
2119
2120   +---------------+
2121   | Field         |
2122   +===============+
2123   | no properties |
2124   +---------------+
2125
2126Action: ``OF_POP_VLAN``
2127^^^^^^^^^^^^^^^^^^^^^^^
2128
2129Implements ``OFPAT_POP_VLAN`` ("pop the outer VLAN tag") as defined
2130by the `OpenFlow Switch Specification`_.
2131
2132.. _table_rte_flow_action_of_pop_vlan:
2133
2134.. table:: OF_POP_VLAN
2135
2136   +---------------+
2137   | Field         |
2138   +===============+
2139   | no properties |
2140   +---------------+
2141
2142Action: ``OF_PUSH_VLAN``
2143^^^^^^^^^^^^^^^^^^^^^^^^
2144
2145Implements ``OFPAT_PUSH_VLAN`` ("push a new VLAN tag") as defined by the
2146`OpenFlow Switch Specification`_.
2147
2148.. _table_rte_flow_action_of_push_vlan:
2149
2150.. table:: OF_PUSH_VLAN
2151
2152   +---------------+-----------+
2153   | Field         | Value     |
2154   +===============+===========+
2155   | ``ethertype`` | EtherType |
2156   +---------------+-----------+
2157
2158Action: ``OF_SET_VLAN_VID``
2159^^^^^^^^^^^^^^^^^^^^^^^^^^^
2160
2161Implements ``OFPAT_SET_VLAN_VID`` ("set the 802.1q VLAN id") as defined by
2162the `OpenFlow Switch Specification`_.
2163
2164.. _table_rte_flow_action_of_set_vlan_vid:
2165
2166.. table:: OF_SET_VLAN_VID
2167
2168   +--------------+---------+
2169   | Field        | Value   |
2170   +==============+=========+
2171   | ``vlan_vid`` | VLAN id |
2172   +--------------+---------+
2173
2174Action: ``OF_SET_VLAN_PCP``
2175^^^^^^^^^^^^^^^^^^^^^^^^^^^
2176
2177Implements ``OFPAT_SET_LAN_PCP`` ("set the 802.1q priority") as defined by
2178the `OpenFlow Switch Specification`_.
2179
2180.. _table_rte_flow_action_of_set_vlan_pcp:
2181
2182.. table:: OF_SET_VLAN_PCP
2183
2184   +--------------+---------------+
2185   | Field        | Value         |
2186   +==============+===============+
2187   | ``vlan_pcp`` | VLAN priority |
2188   +--------------+---------------+
2189
2190Action: ``OF_POP_MPLS``
2191^^^^^^^^^^^^^^^^^^^^^^^
2192
2193Implements ``OFPAT_POP_MPLS`` ("pop the outer MPLS tag") as defined by the
2194`OpenFlow Switch Specification`_.
2195
2196.. _table_rte_flow_action_of_pop_mpls:
2197
2198.. table:: OF_POP_MPLS
2199
2200   +---------------+-----------+
2201   | Field         | Value     |
2202   +===============+===========+
2203   | ``ethertype`` | EtherType |
2204   +---------------+-----------+
2205
2206Action: ``OF_PUSH_MPLS``
2207^^^^^^^^^^^^^^^^^^^^^^^^
2208
2209Implements ``OFPAT_PUSH_MPLS`` ("push a new MPLS tag") as defined by the
2210`OpenFlow Switch Specification`_.
2211
2212.. _table_rte_flow_action_of_push_mpls:
2213
2214.. table:: OF_PUSH_MPLS
2215
2216   +---------------+-----------+
2217   | Field         | Value     |
2218   +===============+===========+
2219   | ``ethertype`` | EtherType |
2220   +---------------+-----------+
2221
2222Action: ``VXLAN_ENCAP``
2223^^^^^^^^^^^^^^^^^^^^^^^
2224
2225Performs a VXLAN encapsulation action by encapsulating the matched flow in the
2226VXLAN tunnel as defined in the``rte_flow_action_vxlan_encap`` flow items
2227definition.
2228
2229This action modifies the payload of matched flows. The flow definition specified
2230in the ``rte_flow_action_tunnel_encap`` action structure must define a valid
2231VLXAN network overlay which conforms with RFC 7348 (Virtual eXtensible Local
2232Area Network (VXLAN): A Framework for Overlaying Virtualized Layer 2 Networks
2233over Layer 3 Networks). The pattern must be terminated with the
2234RTE_FLOW_ITEM_TYPE_END item type.
2235
2236.. _table_rte_flow_action_vxlan_encap:
2237
2238.. table:: VXLAN_ENCAP
2239
2240   +----------------+-------------------------------------+
2241   | Field          | Value                               |
2242   +================+=====================================+
2243   | ``definition`` | Tunnel end-point overlay definition |
2244   +----------------+-------------------------------------+
2245
2246.. _table_rte_flow_action_vxlan_encap_example:
2247
2248.. table:: IPv4 VxLAN flow pattern example.
2249
2250   +-------+----------+
2251   | Index | Item     |
2252   +=======+==========+
2253   | 0     | Ethernet |
2254   +-------+----------+
2255   | 1     | IPv4     |
2256   +-------+----------+
2257   | 2     | UDP      |
2258   +-------+----------+
2259   | 3     | VXLAN    |
2260   +-------+----------+
2261   | 4     | END      |
2262   +-------+----------+
2263
2264Action: ``VXLAN_DECAP``
2265^^^^^^^^^^^^^^^^^^^^^^^
2266
2267Performs a decapsulation action by stripping all headers of the VXLAN tunnel
2268network overlay from the matched flow.
2269
2270The flow items pattern defined for the flow rule with which a ``VXLAN_DECAP``
2271action is specified, must define a valid VXLAN tunnel as per RFC7348. If the
2272flow pattern does not specify a valid VXLAN tunnel then a
2273RTE_FLOW_ERROR_TYPE_ACTION error should be returned.
2274
2275This action modifies the payload of matched flows.
2276
2277Action: ``NVGRE_ENCAP``
2278^^^^^^^^^^^^^^^^^^^^^^^
2279
2280Performs a NVGRE encapsulation action by encapsulating the matched flow in the
2281NVGRE tunnel as defined in the``rte_flow_action_tunnel_encap`` flow item
2282definition.
2283
2284This action modifies the payload of matched flows. The flow definition specified
2285in the ``rte_flow_action_tunnel_encap`` action structure must defined a valid
2286NVGRE network overlay which conforms with RFC 7637 (NVGRE: Network
2287Virtualization Using Generic Routing Encapsulation). The pattern must be
2288terminated with the RTE_FLOW_ITEM_TYPE_END item type.
2289
2290.. _table_rte_flow_action_nvgre_encap:
2291
2292.. table:: NVGRE_ENCAP
2293
2294   +----------------+-------------------------------------+
2295   | Field          | Value                               |
2296   +================+=====================================+
2297   | ``definition`` | NVGRE end-point overlay definition  |
2298   +----------------+-------------------------------------+
2299
2300.. _table_rte_flow_action_nvgre_encap_example:
2301
2302.. table:: IPv4 NVGRE flow pattern example.
2303
2304   +-------+----------+
2305   | Index | Item     |
2306   +=======+==========+
2307   | 0     | Ethernet |
2308   +-------+----------+
2309   | 1     | IPv4     |
2310   +-------+----------+
2311   | 2     | NVGRE    |
2312   +-------+----------+
2313   | 3     | END      |
2314   +-------+----------+
2315
2316Action: ``NVGRE_DECAP``
2317^^^^^^^^^^^^^^^^^^^^^^^
2318
2319Performs a decapsulation action by stripping all headers of the NVGRE tunnel
2320network overlay from the matched flow.
2321
2322The flow items pattern defined for the flow rule with which a ``NVGRE_DECAP``
2323action is specified, must define a valid NVGRE tunnel as per RFC7637. If the
2324flow pattern does not specify a valid NVGRE tunnel then a
2325RTE_FLOW_ERROR_TYPE_ACTION error should be returned.
2326
2327This action modifies the payload of matched flows.
2328
2329Action: ``RAW_ENCAP``
2330^^^^^^^^^^^^^^^^^^^^^
2331
2332Adds outer header whose template is provided in its data buffer,
2333as defined in the ``rte_flow_action_raw_encap`` definition.
2334
2335This action modifies the payload of matched flows. The data supplied must
2336be a valid header, either holding layer 2 data in case of adding layer 2 after
2337decap layer 3 tunnel (for example MPLSoGRE) or complete tunnel definition
2338starting from layer 2 and moving to the tunnel item itself. When applied to
2339the original packet the resulting packet must be a valid packet.
2340
2341.. _table_rte_flow_action_raw_encap:
2342
2343.. table:: RAW_ENCAP
2344
2345   +----------------+----------------------------------------+
2346   | Field          | Value                                  |
2347   +================+========================================+
2348   | ``data``       | Encapsulation data                     |
2349   +----------------+----------------------------------------+
2350   | ``preserve``   | Bit-mask of data to preserve on output |
2351   +----------------+----------------------------------------+
2352   | ``size``       | Size of data and preserve              |
2353   +----------------+----------------------------------------+
2354
2355Action: ``RAW_DECAP``
2356^^^^^^^^^^^^^^^^^^^^^^^
2357
2358Remove outer header whose template is provided in its data buffer,
2359as defined in the ``rte_flow_action_raw_decap``
2360
2361This action modifies the payload of matched flows. The data supplied must
2362be a valid header, either holding layer 2 data in case of removing layer 2
2363before encapsulation of layer 3 tunnel (for example MPLSoGRE) or complete
2364tunnel definition starting from layer 2 and moving to the tunnel item itself.
2365When applied to the original packet the resulting packet must be a
2366valid packet.
2367
2368.. _table_rte_flow_action_raw_decap:
2369
2370.. table:: RAW_DECAP
2371
2372   +----------------+----------------------------------------+
2373   | Field          | Value                                  |
2374   +================+========================================+
2375   | ``data``       | Decapsulation data                     |
2376   +----------------+----------------------------------------+
2377   | ``size``       | Size of data                           |
2378   +----------------+----------------------------------------+
2379
2380Action: ``SET_IPV4_SRC``
2381^^^^^^^^^^^^^^^^^^^^^^^^
2382
2383Set a new IPv4 source address in the outermost IPv4 header.
2384
2385It must be used with a valid RTE_FLOW_ITEM_TYPE_IPV4 flow pattern item.
2386Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be returned.
2387
2388.. _table_rte_flow_action_set_ipv4_src:
2389
2390.. table:: SET_IPV4_SRC
2391
2392   +-----------------------------------------+
2393   | Field         | Value                   |
2394   +===============+=========================+
2395   | ``ipv4_addr`` | new IPv4 source address |
2396   +---------------+-------------------------+
2397
2398Action: ``SET_IPV4_DST``
2399^^^^^^^^^^^^^^^^^^^^^^^^
2400
2401Set a new IPv4 destination address in the outermost IPv4 header.
2402
2403It must be used with a valid RTE_FLOW_ITEM_TYPE_IPV4 flow pattern item.
2404Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be returned.
2405
2406.. _table_rte_flow_action_set_ipv4_dst:
2407
2408.. table:: SET_IPV4_DST
2409
2410   +---------------+------------------------------+
2411   | Field         | Value                        |
2412   +===============+==============================+
2413   | ``ipv4_addr`` | new IPv4 destination address |
2414   +---------------+------------------------------+
2415
2416Action: ``SET_IPV6_SRC``
2417^^^^^^^^^^^^^^^^^^^^^^^^
2418
2419Set a new IPv6 source address in the outermost IPv6 header.
2420
2421It must be used with a valid RTE_FLOW_ITEM_TYPE_IPV6 flow pattern item.
2422Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be returned.
2423
2424.. _table_rte_flow_action_set_ipv6_src:
2425
2426.. table:: SET_IPV6_SRC
2427
2428   +---------------+-------------------------+
2429   | Field         | Value                   |
2430   +===============+=========================+
2431   | ``ipv6_addr`` | new IPv6 source address |
2432   +---------------+-------------------------+
2433
2434Action: ``SET_IPV6_DST``
2435^^^^^^^^^^^^^^^^^^^^^^^^
2436
2437Set a new IPv6 destination address in the outermost IPv6 header.
2438
2439It must be used with a valid RTE_FLOW_ITEM_TYPE_IPV6 flow pattern item.
2440Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be returned.
2441
2442.. _table_rte_flow_action_set_ipv6_dst:
2443
2444.. table:: SET_IPV6_DST
2445
2446   +---------------+------------------------------+
2447   | Field         | Value                        |
2448   +===============+==============================+
2449   | ``ipv6_addr`` | new IPv6 destination address |
2450   +---------------+------------------------------+
2451
2452Action: ``SET_TP_SRC``
2453^^^^^^^^^^^^^^^^^^^^^^^^^
2454
2455Set a new source port number in the outermost TCP/UDP header.
2456
2457It must be used with a valid RTE_FLOW_ITEM_TYPE_TCP or RTE_FLOW_ITEM_TYPE_UDP
2458flow pattern item. Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be returned.
2459
2460.. _table_rte_flow_action_set_tp_src:
2461
2462.. table:: SET_TP_SRC
2463
2464   +----------+-------------------------+
2465   | Field    | Value                   |
2466   +==========+=========================+
2467   | ``port`` | new TCP/UDP source port |
2468   +---------------+--------------------+
2469
2470Action: ``SET_TP_DST``
2471^^^^^^^^^^^^^^^^^^^^^^^^^
2472
2473Set a new destination port number in the outermost TCP/UDP header.
2474
2475It must be used with a valid RTE_FLOW_ITEM_TYPE_TCP or RTE_FLOW_ITEM_TYPE_UDP
2476flow pattern item. Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be returned.
2477
2478.. _table_rte_flow_action_set_tp_dst:
2479
2480.. table:: SET_TP_DST
2481
2482   +----------+------------------------------+
2483   | Field    | Value                        |
2484   +==========+==============================+
2485   | ``port`` | new TCP/UDP destination port |
2486   +---------------+-------------------------+
2487
2488Action: ``MAC_SWAP``
2489^^^^^^^^^^^^^^^^^^^^^^^^^
2490
2491Swap the source and destination MAC addresses in the outermost Ethernet
2492header.
2493
2494It must be used with a valid RTE_FLOW_ITEM_TYPE_ETH flow pattern item.
2495Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be returned.
2496
2497.. _table_rte_flow_action_mac_swap:
2498
2499.. table:: MAC_SWAP
2500
2501   +---------------+
2502   | Field         |
2503   +===============+
2504   | no properties |
2505   +---------------+
2506
2507Action: ``DEC_TTL``
2508^^^^^^^^^^^^^^^^^^^
2509
2510Decrease TTL value.
2511
2512If there is no valid RTE_FLOW_ITEM_TYPE_IPV4 or RTE_FLOW_ITEM_TYPE_IPV6
2513in pattern, Some PMDs will reject rule because behavior will be undefined.
2514
2515.. _table_rte_flow_action_dec_ttl:
2516
2517.. table:: DEC_TTL
2518
2519   +---------------+
2520   | Field         |
2521   +===============+
2522   | no properties |
2523   +---------------+
2524
2525Action: ``SET_TTL``
2526^^^^^^^^^^^^^^^^^^^
2527
2528Assigns a new TTL value.
2529
2530If there is no valid RTE_FLOW_ITEM_TYPE_IPV4 or RTE_FLOW_ITEM_TYPE_IPV6
2531in pattern, Some PMDs will reject rule because behavior will be undefined.
2532
2533.. _table_rte_flow_action_set_ttl:
2534
2535.. table:: SET_TTL
2536
2537   +---------------+--------------------+
2538   | Field         | Value              |
2539   +===============+====================+
2540   | ``ttl_value`` | new TTL value      |
2541   +---------------+--------------------+
2542
2543Action: ``SET_MAC_SRC``
2544^^^^^^^^^^^^^^^^^^^^^^^
2545
2546Set source MAC address.
2547
2548It must be used with a valid RTE_FLOW_ITEM_TYPE_ETH flow pattern item.
2549Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be returned.
2550
2551.. _table_rte_flow_action_set_mac_src:
2552
2553.. table:: SET_MAC_SRC
2554
2555   +--------------+---------------+
2556   | Field        | Value         |
2557   +==============+===============+
2558   | ``mac_addr`` | MAC address   |
2559   +--------------+---------------+
2560
2561Action: ``SET_MAC_DST``
2562^^^^^^^^^^^^^^^^^^^^^^^
2563
2564Set destination MAC address.
2565
2566It must be used with a valid RTE_FLOW_ITEM_TYPE_ETH flow pattern item.
2567Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be returned.
2568
2569.. _table_rte_flow_action_set_mac_dst:
2570
2571.. table:: SET_MAC_DST
2572
2573   +--------------+---------------+
2574   | Field        | Value         |
2575   +==============+===============+
2576   | ``mac_addr`` | MAC address   |
2577   +--------------+---------------+
2578
2579Action: ``INC_TCP_SEQ``
2580^^^^^^^^^^^^^^^^^^^^^^^
2581
2582Increase sequence number in the outermost TCP header.
2583Value to increase TCP sequence number by is a big-endian 32 bit integer.
2584
2585Using this action on non-matching traffic will result in undefined behavior.
2586
2587Action: ``DEC_TCP_SEQ``
2588^^^^^^^^^^^^^^^^^^^^^^^
2589
2590Decrease sequence number in the outermost TCP header.
2591Value to decrease TCP sequence number by is a big-endian 32 bit integer.
2592
2593Using this action on non-matching traffic will result in undefined behavior.
2594
2595Action: ``INC_TCP_ACK``
2596^^^^^^^^^^^^^^^^^^^^^^^
2597
2598Increase acknowledgment number in the outermost TCP header.
2599Value to increase TCP acknowledgment number by is a big-endian 32 bit integer.
2600
2601Using this action on non-matching traffic will result in undefined behavior.
2602
2603Action: ``DEC_TCP_ACK``
2604^^^^^^^^^^^^^^^^^^^^^^^
2605
2606Decrease acknowledgment number in the outermost TCP header.
2607Value to decrease TCP acknowledgment number by is a big-endian 32 bit integer.
2608
2609Using this action on non-matching traffic will result in undefined behavior.
2610
2611Action: ``SET_TAG``
2612^^^^^^^^^^^^^^^^^^^
2613
2614Set Tag.
2615
2616Tag is a transient data used during flow matching. This is not delivered to
2617application. Multiple tags are supported by specifying index.
2618
2619.. _table_rte_flow_action_set_tag:
2620
2621.. table:: SET_TAG
2622
2623   +-----------+----------------------------+
2624   | Field     | Value                      |
2625   +===========+============================+
2626   | ``data``  | 32 bit tag value           |
2627   +-----------+----------------------------+
2628   | ``mask``  | bit-mask applies to "data" |
2629   +-----------+----------------------------+
2630   | ``index`` | index of tag to set        |
2631   +-----------+----------------------------+
2632
2633Action: ``SET_META``
2634^^^^^^^^^^^^^^^^^^^^^^^
2635
2636Set metadata. Item ``META`` matches metadata.
2637
2638Metadata set by mbuf metadata field with PKT_TX_DYNF_METADATA flag on egress
2639will be overridden by this action. On ingress, the metadata will be carried by
2640``metadata`` dynamic field of ``rte_mbuf`` which can be accessed by
2641``RTE_FLOW_DYNF_METADATA()``. PKT_RX_DYNF_METADATA flag will be set along
2642with the data.
2643
2644The mbuf dynamic field must be registered by calling
2645``rte_flow_dynf_metadata_register()`` prior to use ``SET_META`` action.
2646
2647Altering partial bits is supported with ``mask``. For bits which have never been
2648set, unpredictable value will be seen depending on driver implementation. For
2649loopback/hairpin packet, metadata set on Rx/Tx may or may not be propagated to
2650the other path depending on HW capability.
2651
2652In hairpin case with Tx explicit flow mode, metadata could (not mandatory) be
2653used to connect the Rx and Tx flows if it can be propagated from Rx to Tx path.
2654
2655.. _table_rte_flow_action_set_meta:
2656
2657.. table:: SET_META
2658
2659   +----------+----------------------------+
2660   | Field    | Value                      |
2661   +==========+============================+
2662   | ``data`` | 32 bit metadata value      |
2663   +----------+----------------------------+
2664   | ``mask`` | bit-mask applies to "data" |
2665   +----------+----------------------------+
2666
2667Action: ``SET_IPV4_DSCP``
2668^^^^^^^^^^^^^^^^^^^^^^^^^
2669
2670Set IPv4 DSCP.
2671
2672Modify DSCP in IPv4 header.
2673
2674It must be used with RTE_FLOW_ITEM_TYPE_IPV4 in pattern.
2675Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be returned.
2676
2677.. _table_rte_flow_action_set_ipv4_dscp:
2678
2679.. table:: SET_IPV4_DSCP
2680
2681   +-----------+---------------------------------+
2682   | Field     | Value                           |
2683   +===========+=================================+
2684   | ``dscp``  | DSCP in low 6 bits, rest ignore |
2685   +-----------+---------------------------------+
2686
2687Action: ``SET_IPV6_DSCP``
2688^^^^^^^^^^^^^^^^^^^^^^^^^
2689
2690Set IPv6 DSCP.
2691
2692Modify DSCP in IPv6 header.
2693
2694It must be used with RTE_FLOW_ITEM_TYPE_IPV6 in pattern.
2695Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be returned.
2696
2697.. _table_rte_flow_action_set_ipv6_dscp:
2698
2699.. table:: SET_IPV6_DSCP
2700
2701   +-----------+---------------------------------+
2702   | Field     | Value                           |
2703   +===========+=================================+
2704   | ``dscp``  | DSCP in low 6 bits, rest ignore |
2705   +-----------+---------------------------------+
2706
2707Action: ``AGE``
2708^^^^^^^^^^^^^^^
2709
2710Set ageing timeout configuration to a flow.
2711
2712Event RTE_ETH_EVENT_FLOW_AGED will be reported if
2713timeout passed without any matching on the flow.
2714
2715.. _table_rte_flow_action_age:
2716
2717.. table:: AGE
2718
2719   +--------------+---------------------------------+
2720   | Field        | Value                           |
2721   +==============+=================================+
2722   | ``timeout``  | 24 bits timeout value           |
2723   +--------------+---------------------------------+
2724   | ``reserved`` | 8 bits reserved, must be zero   |
2725   +--------------+---------------------------------+
2726   | ``context``  | user input flow context         |
2727   +--------------+---------------------------------+
2728
2729Query structure to retrieve ageing status information of a
2730shared AGE action, or a flow rule using the AGE action:
2731
2732.. _table_rte_flow_query_age:
2733
2734.. table:: AGE query
2735
2736   +------------------------------+-----+----------------------------------------+
2737   | Field                        | I/O | Value                                  |
2738   +==============================+=====+========================================+
2739   | ``aged``                     | out | Aging timeout expired                  |
2740   +------------------------------+-----+----------------------------------------+
2741   | ``sec_since_last_hit_valid`` | out | ``sec_since_last_hit`` value is valid  |
2742   +------------------------------+-----+----------------------------------------+
2743   | ``sec_since_last_hit``       | out | Seconds since last traffic hit         |
2744   +------------------------------+-----+----------------------------------------+
2745
2746Action: ``SAMPLE``
2747^^^^^^^^^^^^^^^^^^
2748
2749Adds a sample action to a matched flow.
2750
2751The matching packets will be duplicated with the specified ``ratio`` and
2752applied with own set of actions with a fate action, the packets sampled
2753equals is '1/ratio'. All the packets continue to the target destination.
2754
2755When the ``ratio`` is set to 1 then the packets will be 100% mirrored.
2756``actions`` represent the different set of actions for the sampled or mirrored
2757packets, and must have a fate action.
2758
2759.. _table_rte_flow_action_sample:
2760
2761.. table:: SAMPLE
2762
2763   +--------------+---------------------------------+
2764   | Field        | Value                           |
2765   +==============+=================================+
2766   | ``ratio``    | 32 bits sample ratio value      |
2767   +--------------+---------------------------------+
2768   | ``actions``  | sub-action list for sampling    |
2769   +--------------+---------------------------------+
2770
2771Action: ``INDIRECT``
2772^^^^^^^^^^^^^^^^^^^^
2773
2774Flow utilize indirect action by handle as returned from
2775``rte_flow_action_handle_create()``.
2776
2777The behaviour of the indirect action defined by ``action`` argument of type
2778``struct rte_flow_action`` passed to ``rte_flow_action_handle_create()``.
2779
2780The indirect action can be used by a single flow or shared among multiple flows.
2781The indirect action can be in-place updated by ``rte_flow_action_handle_update()``
2782without destroying flow and creating flow again. The fields that could be
2783updated depend on the type of the ``action`` and different for every type.
2784
2785The indirect action specified data (e.g. counter) can be queried by
2786``rte_flow_action_handle_query()``.
2787
2788.. _table_rte_flow_action_handle:
2789
2790.. table:: INDIRECT
2791
2792   +---------------+
2793   | Field         |
2794   +===============+
2795   | no properties |
2796   +---------------+
2797
2798Action: ``MODIFY_FIELD``
2799^^^^^^^^^^^^^^^^^^^^^^^^
2800
2801Modify ``dst`` field according to ``op`` selected (set, addition,
2802subtraction) with ``width`` bits of data from ``src`` field.
2803
2804Any arbitrary header field (as well as mark, metadata or tag values)
2805can be used as both source and destination fields as set by ``field``.
2806The immediate value ``RTE_FLOW_FIELD_VALUE`` (or a pointer to it
2807``RTE_FLOW_FIELD_POINTER``) is allowed as a source only.
2808``RTE_FLOW_FIELD_START`` is used to point to the beginning of a packet.
2809See ``enum rte_flow_field_id`` for the list of supported fields.
2810
2811``op`` selects the operation to perform on a destination field.
2812- ``set`` copies the data from ``src`` field to ``dst`` field.
2813- ``add`` adds together ``dst`` and ``src`` and stores the result into ``dst``.
2814- ``sub`` subtracts ``src`` from ``dst`` and stores the result into ``dst``
2815
2816``width`` defines a number of bits to use from ``src`` field.
2817
2818``level`` is used to access any packet field on any encapsulation level
2819as well as any tag element in the tag array.
2820- ``0`` means the default behaviour. Depending on the packet type, it can
2821mean outermost, innermost or anything in between.
2822- ``1`` requests access to the outermost packet encapsulation level.
2823- ``2`` and subsequent values requests access to the specified packet
2824encapsulation level, from outermost to innermost (lower to higher values).
2825For the tag array (in case of multiple tags are supported and present)
2826``level`` translates directly into the array index.
2827
2828``offset`` specifies the number of bits to skip from a field's start.
2829That allows performing a partial copy of the needed part or to divide a big
2830packet field into multiple smaller fields. Alternatively, ``offset`` allows
2831going past the specified packet field boundary to copy a field to an
2832arbitrary place in a packet, essentially providing a way to copy any part of
2833a packet to any other part of it.
2834
2835``value`` sets an immediate value to be used as a source or points to a
2836location of the value in memory. It is used instead of ``level`` and ``offset``
2837for ``RTE_FLOW_FIELD_VALUE`` and ``RTE_FLOW_FIELD_POINTER`` respectively.
2838
2839.. _table_rte_flow_action_modify_field:
2840
2841.. table:: MODIFY_FIELD
2842
2843   +---------------+-------------------------+
2844   | Field         | Value                   |
2845   +===============+=========================+
2846   | ``op``        | operation to perform    |
2847   +---------------+-------------------------+
2848   | ``dst``       | destination field       |
2849   +---------------+-------------------------+
2850   | ``src``       | source field            |
2851   +---------------+-------------------------+
2852   | ``width``     | number of bits to use   |
2853   +---------------+-------------------------+
2854
2855.. _table_rte_flow_action_modify_data:
2856
2857.. table:: destination/source field definition
2858
2859   +---------------+----------------------------------------------------------+
2860   | Field         | Value                                                    |
2861   +===============+==========================================================+
2862   | ``field``     | ID: packet field, mark, meta, tag, immediate, pointer    |
2863   +---------------+----------------------------------------------------------+
2864   | ``level``     | encapsulation level of a packet field or tag array index |
2865   +---------------+----------------------------------------------------------+
2866   | ``offset``    | number of bits to skip at the beginning                  |
2867   +---------------+----------------------------------------------------------+
2868   | ``value``     | immediate value or a pointer to this value               |
2869   +---------------+----------------------------------------------------------+
2870
2871Action: ``CONNTRACK``
2872^^^^^^^^^^^^^^^^^^^^^
2873
2874Create a conntrack (connection tracking) context with the provided information.
2875
2876In stateful session like TCP, the conntrack action provides the ability to
2877examine every packet of this connection and associate the state to every
2878packet. It will help to realize the stateful offload of connections with little
2879software participation. For example, the packets with invalid state may be
2880handled by the software. The control packets could be handled in the hardware.
2881The software just need to query the state of a connection when needed, and then
2882decide how to handle the flow rules and conntrack context.
2883
2884A conntrack context should be created via ``rte_flow_action_handle_create()``
2885before using. Then the handle with ``INDIRECT`` type is used for a flow rule
2886creation. If a flow rule with an opposite direction needs to be created, the
2887``rte_flow_action_handle_update()`` should be used to modify the direction.
2888
2889Not all the fields of the ``struct rte_flow_action_conntrack`` will be used
2890for a conntrack context creating, depending on the HW, and they should be
2891in host byte order. PMD should convert them into network byte order when
2892needed by the HW.
2893
2894The ``struct rte_flow_modify_conntrack`` should be used for an updating.
2895
2896The current conntrack context information could be queried via the
2897``rte_flow_action_handle_query()`` interface.
2898
2899.. _table_rte_flow_action_conntrack:
2900
2901.. table:: CONNTRACK
2902
2903   +--------------------------+-------------------------------------------------------------+
2904   | Field                    | Value                                                       |
2905   +==========================+=============================================================+
2906   | ``peer_port``            | peer port number                                            |
2907   +--------------------------+-------------------------------------------------------------+
2908   | ``is_original_dir``      | direction of this connection for creating flow rule         |
2909   +--------------------------+-------------------------------------------------------------+
2910   | ``enable``               | enable the conntrack context                                |
2911   +--------------------------+-------------------------------------------------------------+
2912   | ``live_connection``      | one ack was seen for this connection                        |
2913   +--------------------------+-------------------------------------------------------------+
2914   | ``selective_ack``        | SACK enabled                                                |
2915   +--------------------------+-------------------------------------------------------------+
2916   | ``challenge_ack_passed`` | a challenge ack has passed                                  |
2917   +--------------------------+-------------------------------------------------------------+
2918   | ``last_direction``       | direction of the last passed packet                         |
2919   +--------------------------+-------------------------------------------------------------+
2920   | ``liberal_mode``         | only report state change                                    |
2921   +--------------------------+-------------------------------------------------------------+
2922   | ``state``                | current state                                               |
2923   +--------------------------+-------------------------------------------------------------+
2924   | ``max_ack_window``       | maximal window scaling factor                               |
2925   +--------------------------+-------------------------------------------------------------+
2926   | ``retransmission_limit`` | maximal retransmission times                                |
2927   +--------------------------+-------------------------------------------------------------+
2928   | ``original_dir``         | TCP parameters of the original direction                    |
2929   +--------------------------+-------------------------------------------------------------+
2930   | ``reply_dir``            | TCP parameters of the reply direction                       |
2931   +--------------------------+-------------------------------------------------------------+
2932   | ``last_window``          | window size of the last passed packet                       |
2933   +--------------------------+-------------------------------------------------------------+
2934   | ``last_seq``             | sequence number of the last passed packet                   |
2935   +--------------------------+-------------------------------------------------------------+
2936   | ``last_ack``             | acknowledgment number the last passed packet                |
2937   +--------------------------+-------------------------------------------------------------+
2938   | ``last_end``             | sum of ack number and length of the last passed packet      |
2939   +--------------------------+-------------------------------------------------------------+
2940
2941.. _table_rte_flow_tcp_dir_param:
2942
2943.. table:: configuration parameters for each direction
2944
2945   +---------------------+---------------------------------------------------------+
2946   | Field               | Value                                                   |
2947   +=====================+=========================================================+
2948   | ``scale``           | TCP window scaling factor                               |
2949   +---------------------+---------------------------------------------------------+
2950   | ``close_initiated`` | FIN sent from this direction                            |
2951   +---------------------+---------------------------------------------------------+
2952   | ``last_ack_seen``   | an ACK packet received                                  |
2953   +---------------------+---------------------------------------------------------+
2954   | ``data_unacked``    | unacknowledged data for packets from this direction     |
2955   +---------------------+---------------------------------------------------------+
2956   | ``sent_end``        | max{seq + len} seen in sent packets                     |
2957   +---------------------+---------------------------------------------------------+
2958   | ``reply_end``       | max{sack + max{win, 1}} seen in reply packets           |
2959   +---------------------+---------------------------------------------------------+
2960   | ``max_win``         | max{max{win, 1}} + {sack - ack} seen in sent packets    |
2961   +---------------------+---------------------------------------------------------+
2962   | ``max_ack``         | max{ack} + seen in sent packets                         |
2963   +---------------------+---------------------------------------------------------+
2964
2965.. _table_rte_flow_modify_conntrack:
2966
2967.. table:: update a conntrack context
2968
2969   +----------------+-------------------------------------------------+
2970   | Field          | Value                                           |
2971   +================+=================================================+
2972   | ``new_ct``     | new conntrack information                       |
2973   +----------------+-------------------------------------------------+
2974   | ``direction``  | direction will be updated                       |
2975   +----------------+-------------------------------------------------+
2976   | ``state``      | other fields except direction will be updated   |
2977   +----------------+-------------------------------------------------+
2978   | ``reserved``   | reserved bits                                   |
2979   +----------------+-------------------------------------------------+
2980
2981Action: ``METER_COLOR``
2982^^^^^^^^^^^^^^^^^^^^^^^
2983
2984Color the packet to reflect the meter color result.
2985
2986The meter action must be configured before meter color action.
2987Meter color action is set to a color to reflect the meter color result.
2988Set the meter color in the mbuf to the selected color.
2989The meter color action output color is the output color of the packet,
2990which is set in the packet meta-data (i.e. struct ``rte_mbuf::sched::color``)
2991
2992.. _table_rte_flow_action_meter_color:
2993
2994.. table:: METER_COLOR
2995
2996   +-----------------+--------------+
2997   | Field           | Value        |
2998   +=================+==============+
2999   | ``meter_color`` | Packet color |
3000   +-----------------+--------------+
3001
3002Negative types
3003~~~~~~~~~~~~~~
3004
3005All specified pattern items (``enum rte_flow_item_type``) and actions
3006(``enum rte_flow_action_type``) use positive identifiers.
3007
3008The negative space is reserved for dynamic types generated by PMDs during
3009run-time. PMDs may encounter them as a result but must not accept negative
3010identifiers they are not aware of.
3011
3012A method to generate them remains to be defined.
3013
3014Application may use PMD dynamic items or actions in flow rules. In that case
3015size of configuration object in dynamic element must be a pointer size.
3016
3017Rules management
3018----------------
3019
3020A rather simple API with few functions is provided to fully manage flow
3021rules.
3022
3023Each created flow rule is associated with an opaque, PMD-specific handle
3024pointer. The application is responsible for keeping it until the rule is
3025destroyed.
3026
3027Flows rules are represented by ``struct rte_flow`` objects.
3028
3029Validation
3030~~~~~~~~~~
3031
3032Given that expressing a definite set of device capabilities is not
3033practical, a dedicated function is provided to check if a flow rule is
3034supported and can be created.
3035
3036.. code-block:: c
3037
3038   int
3039   rte_flow_validate(uint16_t port_id,
3040                     const struct rte_flow_attr *attr,
3041                     const struct rte_flow_item pattern[],
3042                     const struct rte_flow_action actions[],
3043                     struct rte_flow_error *error);
3044
3045The flow rule is validated for correctness and whether it could be accepted
3046by the device given sufficient resources. The rule is checked against the
3047current device mode and queue configuration. The flow rule may also
3048optionally be validated against existing flow rules and device resources.
3049This function has no effect on the target device.
3050
3051The returned value is guaranteed to remain valid only as long as no
3052successful calls to ``rte_flow_create()`` or ``rte_flow_destroy()`` are made
3053in the meantime and no device parameter affecting flow rules in any way are
3054modified, due to possible collisions or resource limitations (although in
3055such cases ``EINVAL`` should not be returned).
3056
3057Arguments:
3058
3059- ``port_id``: port identifier of Ethernet device.
3060- ``attr``: flow rule attributes.
3061- ``pattern``: pattern specification (list terminated by the END pattern
3062  item).
3063- ``actions``: associated actions (list terminated by the END action).
3064- ``error``: perform verbose error reporting if not NULL. PMDs initialize
3065  this structure in case of error only.
3066
3067Return values:
3068
3069- 0 if flow rule is valid and can be created. A negative errno value
3070  otherwise (``rte_errno`` is also set), the following errors are defined.
3071- ``-ENOSYS``: underlying device does not support this functionality.
3072- ``-EINVAL``: unknown or invalid rule specification.
3073- ``-ENOTSUP``: valid but unsupported rule specification (e.g. partial
3074  bit-masks are unsupported).
3075- ``EEXIST``: collision with an existing rule. Only returned if device
3076  supports flow rule collision checking and there was a flow rule
3077  collision. Not receiving this return code is no guarantee that creating
3078  the rule will not fail due to a collision.
3079- ``ENOMEM``: not enough memory to execute the function, or if the device
3080  supports resource validation, resource limitation on the device.
3081- ``-EBUSY``: action cannot be performed due to busy device resources, may
3082  succeed if the affected queues or even the entire port are in a stopped
3083  state (see ``rte_eth_dev_rx_queue_stop()`` and ``rte_eth_dev_stop()``).
3084
3085Creation
3086~~~~~~~~
3087
3088Creating a flow rule is similar to validating one, except the rule is
3089actually created and a handle returned.
3090
3091.. code-block:: c
3092
3093   struct rte_flow *
3094   rte_flow_create(uint16_t port_id,
3095                   const struct rte_flow_attr *attr,
3096                   const struct rte_flow_item pattern[],
3097                   const struct rte_flow_action *actions[],
3098                   struct rte_flow_error *error);
3099
3100Arguments:
3101
3102- ``port_id``: port identifier of Ethernet device.
3103- ``attr``: flow rule attributes.
3104- ``pattern``: pattern specification (list terminated by the END pattern
3105  item).
3106- ``actions``: associated actions (list terminated by the END action).
3107- ``error``: perform verbose error reporting if not NULL. PMDs initialize
3108  this structure in case of error only.
3109
3110Return values:
3111
3112A valid handle in case of success, NULL otherwise and ``rte_errno`` is set
3113to the positive version of one of the error codes defined for
3114``rte_flow_validate()``.
3115
3116Destruction
3117~~~~~~~~~~~
3118
3119Flow rules destruction is not automatic, and a queue or a port should not be
3120released if any are still attached to them. Applications must take care of
3121performing this step before releasing resources.
3122
3123.. code-block:: c
3124
3125   int
3126   rte_flow_destroy(uint16_t port_id,
3127                    struct rte_flow *flow,
3128                    struct rte_flow_error *error);
3129
3130
3131Failure to destroy a flow rule handle may occur when other flow rules depend
3132on it, and destroying it would result in an inconsistent state.
3133
3134This function is only guaranteed to succeed if handles are destroyed in
3135reverse order of their creation.
3136
3137Arguments:
3138
3139- ``port_id``: port identifier of Ethernet device.
3140- ``flow``: flow rule handle to destroy.
3141- ``error``: perform verbose error reporting if not NULL. PMDs initialize
3142  this structure in case of error only.
3143
3144Return values:
3145
3146- 0 on success, a negative errno value otherwise and ``rte_errno`` is set.
3147
3148Flush
3149~~~~~
3150
3151Convenience function to destroy all flow rule handles associated with a
3152port. They are released as with successive calls to ``rte_flow_destroy()``.
3153
3154.. code-block:: c
3155
3156   int
3157   rte_flow_flush(uint16_t port_id,
3158                  struct rte_flow_error *error);
3159
3160In the unlikely event of failure, handles are still considered destroyed and
3161no longer valid but the port must be assumed to be in an inconsistent state.
3162
3163Arguments:
3164
3165- ``port_id``: port identifier of Ethernet device.
3166- ``error``: perform verbose error reporting if not NULL. PMDs initialize
3167  this structure in case of error only.
3168
3169Return values:
3170
3171- 0 on success, a negative errno value otherwise and ``rte_errno`` is set.
3172
3173Query
3174~~~~~
3175
3176Query an existing flow rule.
3177
3178This function allows retrieving flow-specific data such as counters. Data
3179is gathered by special actions which must be present in the flow rule
3180definition.
3181
3182.. code-block:: c
3183
3184   int
3185   rte_flow_query(uint16_t port_id,
3186                  struct rte_flow *flow,
3187                  const struct rte_flow_action *action,
3188                  void *data,
3189                  struct rte_flow_error *error);
3190
3191Arguments:
3192
3193- ``port_id``: port identifier of Ethernet device.
3194- ``flow``: flow rule handle to query.
3195- ``action``: action to query, this must match prototype from flow rule.
3196- ``data``: pointer to storage for the associated query data type.
3197- ``error``: perform verbose error reporting if not NULL. PMDs initialize
3198  this structure in case of error only.
3199
3200Return values:
3201
3202- 0 on success, a negative errno value otherwise and ``rte_errno`` is set.
3203
3204.. _flow_isolated_mode:
3205
3206Flow isolated mode
3207------------------
3208
3209The general expectation for ingress traffic is that flow rules process it
3210first; the remaining unmatched or pass-through traffic usually ends up in a
3211queue (with or without RSS, locally or in some sub-device instance)
3212depending on the global configuration settings of a port.
3213
3214While fine from a compatibility standpoint, this approach makes drivers more
3215complex as they have to check for possible side effects outside of this API
3216when creating or destroying flow rules. It results in a more limited set of
3217available rule types due to the way device resources are assigned (e.g. no
3218support for the RSS action even on capable hardware).
3219
3220Given that nonspecific traffic can be handled by flow rules as well,
3221isolated mode is a means for applications to tell a driver that ingress on
3222the underlying port must be injected from the defined flow rules only; that
3223no default traffic is expected outside those rules.
3224
3225This has the following benefits:
3226
3227- Applications get finer-grained control over the kind of traffic they want
3228  to receive (no traffic by default).
3229
3230- More importantly they control at what point nonspecific traffic is handled
3231  relative to other flow rules, by adjusting priority levels.
3232
3233- Drivers can assign more hardware resources to flow rules and expand the
3234  set of supported rule types.
3235
3236Because toggling isolated mode may cause profound changes to the ingress
3237processing path of a driver, it may not be possible to leave it once
3238entered. Likewise, existing flow rules or global configuration settings may
3239prevent a driver from entering isolated mode.
3240
3241Applications relying on this mode are therefore encouraged to toggle it as
3242soon as possible after device initialization, ideally before the first call
3243to ``rte_eth_dev_configure()`` to avoid possible failures due to conflicting
3244settings.
3245
3246Once effective, the following functionality has no effect on the underlying
3247port and may return errors such as ``ENOTSUP`` ("not supported"):
3248
3249- Toggling promiscuous mode.
3250- Toggling allmulticast mode.
3251- Configuring MAC addresses.
3252- Configuring multicast addresses.
3253- Configuring VLAN filters.
3254- Configuring global RSS settings.
3255
3256.. code-block:: c
3257
3258   int
3259   rte_flow_isolate(uint16_t port_id, int set, struct rte_flow_error *error);
3260
3261Arguments:
3262
3263- ``port_id``: port identifier of Ethernet device.
3264- ``set``: nonzero to enter isolated mode, attempt to leave it otherwise.
3265- ``error``: perform verbose error reporting if not NULL. PMDs initialize
3266  this structure in case of error only.
3267
3268Return values:
3269
3270- 0 on success, a negative errno value otherwise and ``rte_errno`` is set.
3271
3272Verbose error reporting
3273-----------------------
3274
3275The defined *errno* values may not be accurate enough for users or
3276application developers who want to investigate issues related to flow rules
3277management. A dedicated error object is defined for this purpose:
3278
3279.. code-block:: c
3280
3281   enum rte_flow_error_type {
3282       RTE_FLOW_ERROR_TYPE_NONE, /**< No error. */
3283       RTE_FLOW_ERROR_TYPE_UNSPECIFIED, /**< Cause unspecified. */
3284       RTE_FLOW_ERROR_TYPE_HANDLE, /**< Flow rule (handle). */
3285       RTE_FLOW_ERROR_TYPE_ATTR_GROUP, /**< Group field. */
3286       RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY, /**< Priority field. */
3287       RTE_FLOW_ERROR_TYPE_ATTR_INGRESS, /**< Ingress field. */
3288       RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, /**< Egress field. */
3289       RTE_FLOW_ERROR_TYPE_ATTR, /**< Attributes structure. */
3290       RTE_FLOW_ERROR_TYPE_ITEM_NUM, /**< Pattern length. */
3291       RTE_FLOW_ERROR_TYPE_ITEM, /**< Specific pattern item. */
3292       RTE_FLOW_ERROR_TYPE_ACTION_NUM, /**< Number of actions. */
3293       RTE_FLOW_ERROR_TYPE_ACTION, /**< Specific action. */
3294   };
3295
3296   struct rte_flow_error {
3297       enum rte_flow_error_type type; /**< Cause field and error types. */
3298       const void *cause; /**< Object responsible for the error. */
3299       const char *message; /**< Human-readable error message. */
3300   };
3301
3302Error type ``RTE_FLOW_ERROR_TYPE_NONE`` stands for no error, in which case
3303remaining fields can be ignored. Other error types describe the type of the
3304object pointed by ``cause``.
3305
3306If non-NULL, ``cause`` points to the object responsible for the error. For a
3307flow rule, this may be a pattern item or an individual action.
3308
3309If non-NULL, ``message`` provides a human-readable error message.
3310
3311This object is normally allocated by applications and set by PMDs in case of
3312error, the message points to a constant string which does not need to be
3313freed by the application, however its pointer can be considered valid only
3314as long as its associated DPDK port remains configured. Closing the
3315underlying device or unloading the PMD invalidates it.
3316
3317Helpers
3318-------
3319
3320Error initializer
3321~~~~~~~~~~~~~~~~~
3322
3323.. code-block:: c
3324
3325   static inline int
3326   rte_flow_error_set(struct rte_flow_error *error,
3327                      int code,
3328                      enum rte_flow_error_type type,
3329                      const void *cause,
3330                      const char *message);
3331
3332This function initializes ``error`` (if non-NULL) with the provided
3333parameters and sets ``rte_errno`` to ``code``. A negative error ``code`` is
3334then returned.
3335
3336Object conversion
3337~~~~~~~~~~~~~~~~~
3338
3339.. code-block:: c
3340
3341   int
3342   rte_flow_conv(enum rte_flow_conv_op op,
3343                 void *dst,
3344                 size_t size,
3345                 const void *src,
3346                 struct rte_flow_error *error);
3347
3348Convert ``src`` to ``dst`` according to operation ``op``. Possible
3349operations include:
3350
3351- Attributes, pattern item or action duplication.
3352- Duplication of an entire pattern or list of actions.
3353- Duplication of a complete flow rule description.
3354- Pattern item or action name retrieval.
3355
3356Tunneled traffic offload
3357~~~~~~~~~~~~~~~~~~~~~~~~
3358
3359rte_flow API provides the building blocks for vendor-agnostic flow
3360classification offloads. The rte_flow "patterns" and "actions"
3361primitives are fine-grained, thus enabling DPDK applications the
3362flexibility to offload network stacks and complex pipelines.
3363Applications wishing to offload tunneled traffic are required to use
3364the rte_flow primitives, such as group, meta, mark, tag, and others to
3365model their high-level objects.  The hardware model design for
3366high-level software objects is not trivial.  Furthermore, an optimal
3367design is often vendor-specific.
3368
3369When hardware offloads tunneled traffic in multi-group logic,
3370partially offloaded packets may arrive to the application after they
3371were modified in hardware. In this case, the application may need to
3372restore the original packet headers. Consider the following sequence:
3373The application decaps a packet in one group and jumps to a second
3374group where it tries to match on a 5-tuple, that will miss and send
3375the packet to the application. In this case, the application does not
3376receive the original packet but a modified one. Also, in this case,
3377the application cannot match on the outer header fields, such as VXLAN
3378vni and 5-tuple.
3379
3380There are several possible ways to use rte_flow "patterns" and
3381"actions" to resolve the issues above. For example:
3382
33831 Mapping headers to a hardware registers using the
3384rte_flow_action_mark/rte_flow_action_tag/rte_flow_set_meta objects.
3385
33862 Apply the decap only at the last offload stage after all the
3387"patterns" were matched and the packet will be fully offloaded.
3388
3389Every approach has its pros and cons and is highly dependent on the
3390hardware vendor.  For example, some hardware may have a limited number
3391of registers while other hardware could not support inner actions and
3392must decap before accessing inner headers.
3393
3394The tunnel offload model resolves these issues. The model goals are:
3395
33961 Provide a unified application API to offload tunneled traffic that
3397is capable to match on outer headers after decap.
3398
33992 Allow the application to restore the outer header of partially
3400offloaded packets.
3401
3402The tunnel offload model does not introduce new elements to the
3403existing RTE flow model and is implemented as a set of helper
3404functions.
3405
3406For the application to work with the tunnel offload API it
3407has to adjust flow rules in multi-table tunnel offload in the
3408following way:
3409
34101 Remove explicit call to decap action and replace it with PMD actions
3411obtained from rte_flow_tunnel_decap_and_set() helper.
3412
34132 Add PMD items obtained from rte_flow_tunnel_match() helper to all
3414other rules in the tunnel offload sequence.
3415
3416The model requirements:
3417
3418Software application must initialize
3419rte_tunnel object with tunnel parameters before calling
3420rte_flow_tunnel_decap_set() & rte_flow_tunnel_match().
3421
3422PMD actions array obtained in rte_flow_tunnel_decap_set() must be
3423released by application with rte_flow_action_release() call.
3424
3425PMD items array obtained with rte_flow_tunnel_match() must be released
3426by application with rte_flow_item_release() call.  Application can
3427release PMD items and actions after rule was created. However, if the
3428application needs to create additional rule for the same tunnel it
3429will need to obtain PMD items again.
3430
3431Application cannot destroy rte_tunnel object before it releases all
3432PMD actions & PMD items referencing that tunnel.
3433
3434Caveats
3435-------
3436
3437- DPDK does not keep track of flow rules definitions or flow rule objects
3438  automatically. Applications may keep track of the former and must keep
3439  track of the latter. PMDs may also do it for internal needs, however this
3440  must not be relied on by applications.
3441
3442- Flow rules are not maintained between successive port initializations. An
3443  application exiting without releasing them and restarting must re-create
3444  them from scratch.
3445
3446- API operations are synchronous and blocking (``EAGAIN`` cannot be
3447  returned).
3448
3449- Stopping the data path (TX/RX) should not be necessary when managing flow
3450  rules. If this cannot be achieved naturally or with workarounds (such as
3451  temporarily replacing the burst function pointers), an appropriate error
3452  code must be returned (``EBUSY``).
3453
3454- Applications, not PMDs, are responsible for maintaining flow rules
3455  configuration when closing, stopping or restarting a port or performing other
3456  actions which may affect them.
3457  Applications must assume that after port close, stop or restart all flows
3458  related to that port are not valid, hardware rules are destroyed and relevant
3459  PMD resources are released.
3460
3461For devices exposing multiple ports sharing global settings affected by flow
3462rules:
3463
3464- All ports under DPDK control must behave consistently, PMDs are
3465  responsible for making sure that existing flow rules on a port are not
3466  affected by other ports.
3467
3468- Ports not under DPDK control (unaffected or handled by other applications)
3469  are user's responsibility. They may affect existing flow rules and cause
3470  undefined behavior. PMDs aware of this may prevent flow rules creation
3471  altogether in such cases.
3472
3473PMD interface
3474-------------
3475
3476The PMD interface is defined in ``rte_flow_driver.h``. It is not subject to
3477API/ABI versioning constraints as it is not exposed to applications and may
3478evolve independently.
3479
3480The PMD interface is based on callbacks pointed by the ``struct rte_flow_ops``.
3481
3482- PMD callbacks implement exactly the interface described in `Rules
3483  management`_, except for the port ID argument which has already been
3484  converted to a pointer to the underlying ``struct rte_eth_dev``.
3485
3486- Public API functions do not process flow rules definitions at all before
3487  calling PMD functions (no basic error checking, no validation
3488  whatsoever). They only make sure these callbacks are non-NULL or return
3489  the ``ENOSYS`` (function not supported) error.
3490
3491This interface additionally defines the following helper function:
3492
3493- ``rte_flow_ops_get()``: get generic flow operations structure from a
3494  port.
3495
3496If PMD interfaces don't support re-entrancy/multi-thread safety,
3497the rte_flow API functions will protect threads by mutex per port.
3498The application can check whether ``RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE``
3499is set in ``dev_flags``, meaning the PMD is thread-safe regarding rte_flow,
3500so the API level protection is disabled.
3501Please note that this API-level mutex protects only rte_flow functions,
3502other control path functions are not in scope.
3503
3504Device compatibility
3505--------------------
3506
3507No known implementation supports all the described features.
3508
3509Unsupported features or combinations are not expected to be fully emulated
3510in software by PMDs for performance reasons. Partially supported features
3511may be completed in software as long as hardware performs most of the work
3512(such as queue redirection and packet recognition).
3513
3514However PMDs are expected to do their best to satisfy application requests
3515by working around hardware limitations as long as doing so does not affect
3516the behavior of existing flow rules.
3517
3518The following sections provide a few examples of such cases and describe how
3519PMDs should handle them, they are based on limitations built into the
3520previous APIs.
3521
3522Global bit-masks
3523~~~~~~~~~~~~~~~~
3524
3525Each flow rule comes with its own, per-layer bit-masks, while hardware may
3526support only a single, device-wide bit-mask for a given layer type, so that
3527two IPv4 rules cannot use different bit-masks.
3528
3529The expected behavior in this case is that PMDs automatically configure
3530global bit-masks according to the needs of the first flow rule created.
3531
3532Subsequent rules are allowed only if their bit-masks match those, the
3533``EEXIST`` error code should be returned otherwise.
3534
3535Unsupported layer types
3536~~~~~~~~~~~~~~~~~~~~~~~
3537
3538Many protocols can be simulated by crafting patterns with the `Item: RAW`_
3539type.
3540
3541PMDs can rely on this capability to simulate support for protocols with
3542headers not directly recognized by hardware.
3543
3544``ANY`` pattern item
3545~~~~~~~~~~~~~~~~~~~~
3546
3547This pattern item stands for anything, which can be difficult to translate
3548to something hardware would understand, particularly if followed by more
3549specific types.
3550
3551Consider the following pattern:
3552
3553.. _table_rte_flow_unsupported_any:
3554
3555.. table:: Pattern with ANY as L3
3556
3557   +-------+-----------------------+
3558   | Index | Item                  |
3559   +=======+=======================+
3560   | 0     | ETHER                 |
3561   +-------+-----+---------+-------+
3562   | 1     | ANY | ``num`` | ``1`` |
3563   +-------+-----+---------+-------+
3564   | 2     | TCP                   |
3565   +-------+-----------------------+
3566   | 3     | END                   |
3567   +-------+-----------------------+
3568
3569Knowing that TCP does not make sense with something other than IPv4 and IPv6
3570as L3, such a pattern may be translated to two flow rules instead:
3571
3572.. _table_rte_flow_unsupported_any_ipv4:
3573
3574.. table:: ANY replaced with IPV4
3575
3576   +-------+--------------------+
3577   | Index | Item               |
3578   +=======+====================+
3579   | 0     | ETHER              |
3580   +-------+--------------------+
3581   | 1     | IPV4 (zeroed mask) |
3582   +-------+--------------------+
3583   | 2     | TCP                |
3584   +-------+--------------------+
3585   | 3     | END                |
3586   +-------+--------------------+
3587
3588|
3589
3590.. _table_rte_flow_unsupported_any_ipv6:
3591
3592.. table:: ANY replaced with IPV6
3593
3594   +-------+--------------------+
3595   | Index | Item               |
3596   +=======+====================+
3597   | 0     | ETHER              |
3598   +-------+--------------------+
3599   | 1     | IPV6 (zeroed mask) |
3600   +-------+--------------------+
3601   | 2     | TCP                |
3602   +-------+--------------------+
3603   | 3     | END                |
3604   +-------+--------------------+
3605
3606Note that as soon as a ANY rule covers several layers, this approach may
3607yield a large number of hidden flow rules. It is thus suggested to only
3608support the most common scenarios (anything as L2 and/or L3).
3609
3610Unsupported actions
3611~~~~~~~~~~~~~~~~~~~
3612
3613- When combined with `Action: QUEUE`_, packet counting (`Action: COUNT`_)
3614  and tagging (`Action: MARK`_ or `Action: FLAG`_) may be implemented in
3615  software as long as the target queue is used by a single rule.
3616
3617- When a single target queue is provided, `Action: RSS`_ can also be
3618  implemented through `Action: QUEUE`_.
3619
3620Flow rules priority
3621~~~~~~~~~~~~~~~~~~~
3622
3623While it would naturally make sense, flow rules cannot be assumed to be
3624processed by hardware in the same order as their creation for several
3625reasons:
3626
3627- They may be managed internally as a tree or a hash table instead of a
3628  list.
3629- Removing a flow rule before adding another one can either put the new rule
3630  at the end of the list or reuse a freed entry.
3631- Duplication may occur when packets are matched by several rules.
3632
3633For overlapping rules (particularly in order to use `Action: PASSTHRU`_)
3634predictable behavior is only guaranteed by using different priority levels.
3635
3636Priority levels are not necessarily implemented in hardware, or may be
3637severely limited (e.g. a single priority bit).
3638
3639For these reasons, priority levels may be implemented purely in software by
3640PMDs.
3641
3642- For devices expecting flow rules to be added in the correct order, PMDs
3643  may destroy and re-create existing rules after adding a new one with
3644  a higher priority.
3645
3646- A configurable number of dummy or empty rules can be created at
3647  initialization time to save high priority slots for later.
3648
3649- In order to save priority levels, PMDs may evaluate whether rules are
3650  likely to collide and adjust their priority accordingly.
3651
3652
3653.. _OpenFlow Switch Specification: https://www.opennetworking.org/software-defined-standards/specifications/
3654