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