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