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