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