ethdev: clarify flow API pattern items and actions
[dpdk.git] / doc / guides / prog_guide / rte_flow.rst
1 ..  BSD LICENSE
2     Copyright 2016 6WIND S.A.
3     Copyright 2016 Mellanox.
4
5     Redistribution and use in source and binary forms, with or without
6     modification, are permitted provided that the following conditions
7     are met:
8
9     * Redistributions of source code must retain the above copyright
10     notice, this list of conditions and the following disclaimer.
11     * Redistributions in binary form must reproduce the above copyright
12     notice, this list of conditions and the following disclaimer in
13     the documentation and/or other materials provided with the
14     distribution.
15     * Neither the name of 6WIND S.A. nor the names of its
16     contributors may be used to endorse or promote products derived
17     from this software without specific prior written permission.
18
19     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20     "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21     LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22     A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23     OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24     SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25     LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29     OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31 .. _Generic_flow_API:
32
33 Generic flow API (rte_flow)
34 ===========================
35
36 Overview
37 --------
38
39 This API provides a generic means to configure hardware to match specific
40 ingress or egress traffic, alter its fate and query related counters
41 according to any number of user-defined rules.
42
43 It is named *rte_flow* after the prefix used for all its symbols, and is
44 defined in ``rte_flow.h``.
45
46 - Matching can be performed on packet data (protocol headers, payload) and
47   properties (e.g. associated physical port, virtual device function ID).
48
49 - Possible operations include dropping traffic, diverting it to specific
50   queues, to virtual/physical device functions or ports, performing tunnel
51   offloads, adding marks and so on.
52
53 It is slightly higher-level than the legacy filtering framework which it
54 encompasses and supersedes (including all functions and filter types) in
55 order to expose a single interface with an unambiguous behavior that is
56 common to all poll-mode drivers (PMDs).
57
58 Several methods to migrate existing applications are described in `API
59 migration`_.
60
61 Flow rule
62 ---------
63
64 Description
65 ~~~~~~~~~~~
66
67 A flow rule is the combination of attributes with a matching pattern and a
68 list of actions. Flow rules form the basis of this API.
69
70 Flow rules can have several distinct actions (such as counting,
71 encapsulating, decapsulating before redirecting packets to a particular
72 queue, etc.), instead of relying on several rules to achieve this and having
73 applications deal with hardware implementation details regarding their
74 order.
75
76 Support for different priority levels on a rule basis is provided, for
77 example in order to force a more specific rule to come before a more generic
78 one for packets matched by both. However hardware support for more than a
79 single priority level cannot be guaranteed. When supported, the number of
80 available priority levels is usually low, which is why they can also be
81 implemented in software by PMDs (e.g. missing priority levels may be
82 emulated by reordering rules).
83
84 In order to remain as hardware-agnostic as possible, by default all rules
85 are considered to have the same priority, which means that the order between
86 overlapping rules (when a packet is matched by several filters) is
87 undefined.
88
89 PMDs may refuse to create overlapping rules at a given priority level when
90 they can be detected (e.g. if a pattern matches an existing filter).
91
92 Thus predictable results for a given priority level can only be achieved
93 with non-overlapping rules, using perfect matching on all protocol layers.
94
95 Flow rules can also be grouped, the flow rule priority is specific to the
96 group they belong to. All flow rules in a given group are thus processed
97 either before or after another group.
98
99 Support for multiple actions per rule may be implemented internally on top
100 of non-default hardware priorities, as a result both features may not be
101 simultaneously available to applications.
102
103 Considering that allowed pattern/actions combinations cannot be known in
104 advance and would result in an impractically large number of capabilities to
105 expose, a method is provided to validate a given rule from the current
106 device configuration state.
107
108 This enables applications to check if the rule types they need is supported
109 at initialization time, before starting their data path. This method can be
110 used anytime, its only requirement being that the resources needed by a rule
111 should exist (e.g. a target RX queue should be configured first).
112
113 Each defined rule is associated with an opaque handle managed by the PMD,
114 applications are responsible for keeping it. These can be used for queries
115 and rules management, such as retrieving counters or other data and
116 destroying them.
117
118 To avoid resource leaks on the PMD side, handles must be explicitly
119 destroyed by the application before releasing associated resources such as
120 queues and ports.
121
122 The following sections cover:
123
124 - **Attributes** (represented by ``struct rte_flow_attr``): properties of a
125   flow rule such as its direction (ingress or egress) and priority.
126
127 - **Pattern item** (represented by ``struct rte_flow_item``): part of a
128   matching pattern that either matches specific packet data or traffic
129   properties. It can also describe properties of the pattern itself, such as
130   inverted matching.
131
132 - **Matching pattern**: traffic properties to look for, a combination of any
133   number of items.
134
135 - **Actions** (represented by ``struct rte_flow_action``): operations to
136   perform whenever a packet is matched by a pattern.
137
138 Attributes
139 ~~~~~~~~~~
140
141 Attribute: Group
142 ^^^^^^^^^^^^^^^^
143
144 Flow rules can be grouped by assigning them a common group number. Lower
145 values have higher priority. Group 0 has the highest priority.
146
147 Although optional, applications are encouraged to group similar rules as
148 much as possible to fully take advantage of hardware capabilities
149 (e.g. optimized matching) and work around limitations (e.g. a single pattern
150 type possibly allowed in a given group).
151
152 Note that support for more than a single group is not guaranteed.
153
154 Attribute: Priority
155 ^^^^^^^^^^^^^^^^^^^
156
157 A priority level can be assigned to a flow rule. Like groups, lower values
158 denote higher priority, with 0 as the maximum.
159
160 A rule with priority 0 in group 8 is always matched after a rule with
161 priority 8 in group 0.
162
163 Group and priority levels are arbitrary and up to the application, they do
164 not need to be contiguous nor start from 0, however the maximum number
165 varies between devices and may be affected by existing flow rules.
166
167 If a packet is matched by several rules of a given group for a given
168 priority level, the outcome is undefined. It can take any path, may be
169 duplicated or even cause unrecoverable errors.
170
171 Note that support for more than a single priority level is not guaranteed.
172
173 Attribute: Traffic direction
174 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
175
176 Flow rules can apply to inbound and/or outbound traffic (ingress/egress).
177
178 Several pattern items and actions are valid and can be used in both
179 directions. At least one direction must be specified.
180
181 Specifying both directions at once for a given rule is not recommended but
182 may be valid in a few cases (e.g. shared counters).
183
184 Pattern item
185 ~~~~~~~~~~~~
186
187 Pattern items fall in two categories:
188
189 - Matching protocol headers and packet data, usually associated with a
190   specification structure. These must be stacked in the same order as the
191   protocol layers to match inside packets, starting from the lowest.
192
193 - Matching meta-data or affecting pattern processing, often without a
194   specification structure. Since they do not match packet contents, their
195   position in the list is usually not relevant.
196
197 Item specification structures are used to match specific values among
198 protocol fields (or item properties). Documentation describes for each item
199 whether they are associated with one and their type name if so.
200
201 Up to three structures of the same type can be set for a given item:
202
203 - ``spec``: values to match (e.g. a given IPv4 address).
204
205 - ``last``: upper bound for an inclusive range with corresponding fields in
206   ``spec``.
207
208 - ``mask``: bit-mask applied to both ``spec`` and ``last`` whose purpose is
209   to distinguish the values to take into account and/or partially mask them
210   out (e.g. in order to match an IPv4 address prefix).
211
212 Usage restrictions and expected behavior:
213
214 - Setting either ``mask`` or ``last`` without ``spec`` is an error.
215
216 - Field values in ``last`` which are either 0 or equal to the corresponding
217   values in ``spec`` are ignored; they do not generate a range. Nonzero
218   values lower than those in ``spec`` are not supported.
219
220 - Setting ``spec`` and optionally ``last`` without ``mask`` causes the PMD
221   to use the default mask defined for that item (defined as
222   ``rte_flow_item_{name}_mask`` constants).
223
224 - Not setting any of them (assuming item type allows it) is equivalent to
225   providing an empty (zeroed) ``mask`` for broad (nonspecific) matching.
226
227 - ``mask`` is a simple bit-mask applied before interpreting the contents of
228   ``spec`` and ``last``, which may yield unexpected results if not used
229   carefully. For example, if for an IPv4 address field, ``spec`` provides
230   *10.1.2.3*, ``last`` provides *10.3.4.5* and ``mask`` provides
231   *255.255.0.0*, the effective range becomes *10.1.0.0* to *10.3.255.255*.
232
233 Example of an item specification matching an Ethernet header:
234
235 .. _table_rte_flow_pattern_item_example:
236
237 .. table:: Ethernet item
238
239    +----------+----------+--------------------+
240    | Field    | Subfield | Value              |
241    +==========+==========+====================+
242    | ``spec`` | ``src``  | ``00:01:02:03:04`` |
243    |          +----------+--------------------+
244    |          | ``dst``  | ``00:2a:66:00:01`` |
245    |          +----------+--------------------+
246    |          | ``type`` | ``0x22aa``         |
247    +----------+----------+--------------------+
248    | ``last`` | unspecified                   |
249    +----------+----------+--------------------+
250    | ``mask`` | ``src``  | ``00:ff:ff:ff:00`` |
251    |          +----------+--------------------+
252    |          | ``dst``  | ``00:00:00:00:ff`` |
253    |          +----------+--------------------+
254    |          | ``type`` | ``0x0000``         |
255    +----------+----------+--------------------+
256
257 Non-masked bits stand for any value (shown as ``?`` below), Ethernet headers
258 with the following properties are thus matched:
259
260 - ``src``: ``??:01:02:03:??``
261 - ``dst``: ``??:??:??:??:01``
262 - ``type``: ``0x????``
263
264 Matching pattern
265 ~~~~~~~~~~~~~~~~
266
267 A pattern is formed by stacking items starting from the lowest protocol
268 layer to match. This stacking restriction does not apply to meta items which
269 can be placed anywhere in the stack without affecting the meaning of the
270 resulting pattern.
271
272 Patterns are terminated by END items.
273
274 Examples:
275
276 .. _table_rte_flow_tcpv4_as_l4:
277
278 .. table:: TCPv4 as L4
279
280    +-------+----------+
281    | Index | Item     |
282    +=======+==========+
283    | 0     | Ethernet |
284    +-------+----------+
285    | 1     | IPv4     |
286    +-------+----------+
287    | 2     | TCP      |
288    +-------+----------+
289    | 3     | END      |
290    +-------+----------+
291
292 |
293
294 .. _table_rte_flow_tcpv6_in_vxlan:
295
296 .. table:: TCPv6 in VXLAN
297
298    +-------+------------+
299    | Index | Item       |
300    +=======+============+
301    | 0     | Ethernet   |
302    +-------+------------+
303    | 1     | IPv4       |
304    +-------+------------+
305    | 2     | UDP        |
306    +-------+------------+
307    | 3     | VXLAN      |
308    +-------+------------+
309    | 4     | Ethernet   |
310    +-------+------------+
311    | 5     | IPv6       |
312    +-------+------------+
313    | 6     | TCP        |
314    +-------+------------+
315    | 7     | END        |
316    +-------+------------+
317
318 |
319
320 .. _table_rte_flow_tcpv4_as_l4_meta:
321
322 .. table:: TCPv4 as L4 with meta items
323
324    +-------+----------+
325    | Index | Item     |
326    +=======+==========+
327    | 0     | VOID     |
328    +-------+----------+
329    | 1     | Ethernet |
330    +-------+----------+
331    | 2     | VOID     |
332    +-------+----------+
333    | 3     | IPv4     |
334    +-------+----------+
335    | 4     | TCP      |
336    +-------+----------+
337    | 5     | VOID     |
338    +-------+----------+
339    | 6     | VOID     |
340    +-------+----------+
341    | 7     | END      |
342    +-------+----------+
343
344 The above example shows how meta items do not affect packet data matching
345 items, as long as those remain stacked properly. The resulting matching
346 pattern is identical to "TCPv4 as L4".
347
348 .. _table_rte_flow_udpv6_anywhere:
349
350 .. table:: UDPv6 anywhere
351
352    +-------+------+
353    | Index | Item |
354    +=======+======+
355    | 0     | IPv6 |
356    +-------+------+
357    | 1     | UDP  |
358    +-------+------+
359    | 2     | END  |
360    +-------+------+
361
362 If supported by the PMD, omitting one or several protocol layers at the
363 bottom of the stack as in the above example (missing an Ethernet
364 specification) enables looking up anywhere in packets.
365
366 It is unspecified whether the payload of supported encapsulations
367 (e.g. VXLAN payload) is matched by such a pattern, which may apply to inner,
368 outer or both packets.
369
370 .. _table_rte_flow_invalid_l3:
371
372 .. table:: Invalid, missing L3
373
374    +-------+----------+
375    | Index | Item     |
376    +=======+==========+
377    | 0     | Ethernet |
378    +-------+----------+
379    | 1     | UDP      |
380    +-------+----------+
381    | 2     | END      |
382    +-------+----------+
383
384 The above pattern is invalid due to a missing L3 specification between L2
385 (Ethernet) and L4 (UDP). Doing so is only allowed at the bottom and at the
386 top of the stack.
387
388 Meta item types
389 ~~~~~~~~~~~~~~~
390
391 They match meta-data or affect pattern processing instead of matching packet
392 data directly, most of them do not need a specification structure. This
393 particularity allows them to be specified anywhere in the stack without
394 causing any side effect.
395
396 Item: ``END``
397 ^^^^^^^^^^^^^
398
399 End marker for item lists. Prevents further processing of items, thereby
400 ending the pattern.
401
402 - Its numeric value is 0 for convenience.
403 - PMD support is mandatory.
404 - ``spec``, ``last`` and ``mask`` are ignored.
405
406 .. _table_rte_flow_item_end:
407
408 .. table:: END
409
410    +----------+---------+
411    | Field    | Value   |
412    +==========+=========+
413    | ``spec`` | ignored |
414    +----------+---------+
415    | ``last`` | ignored |
416    +----------+---------+
417    | ``mask`` | ignored |
418    +----------+---------+
419
420 Item: ``VOID``
421 ^^^^^^^^^^^^^^
422
423 Used as a placeholder for convenience. It is ignored and simply discarded by
424 PMDs.
425
426 - PMD support is mandatory.
427 - ``spec``, ``last`` and ``mask`` are ignored.
428
429 .. _table_rte_flow_item_void:
430
431 .. table:: VOID
432
433    +----------+---------+
434    | Field    | Value   |
435    +==========+=========+
436    | ``spec`` | ignored |
437    +----------+---------+
438    | ``last`` | ignored |
439    +----------+---------+
440    | ``mask`` | ignored |
441    +----------+---------+
442
443 One usage example for this type is generating rules that share a common
444 prefix quickly without reallocating memory, only by updating item types:
445
446 .. _table_rte_flow_item_void_example:
447
448 .. table:: TCP, UDP or ICMP as L4
449
450    +-------+--------------------+
451    | Index | Item               |
452    +=======+====================+
453    | 0     | Ethernet           |
454    +-------+--------------------+
455    | 1     | IPv4               |
456    +-------+------+------+------+
457    | 2     | UDP  | VOID | VOID |
458    +-------+------+------+------+
459    | 3     | VOID | TCP  | VOID |
460    +-------+------+------+------+
461    | 4     | VOID | VOID | ICMP |
462    +-------+------+------+------+
463    | 5     | END                |
464    +-------+--------------------+
465
466 Item: ``INVERT``
467 ^^^^^^^^^^^^^^^^
468
469 Inverted matching, i.e. process packets that do not match the pattern.
470
471 - ``spec``, ``last`` and ``mask`` are ignored.
472
473 .. _table_rte_flow_item_invert:
474
475 .. table:: INVERT
476
477    +----------+---------+
478    | Field    | Value   |
479    +==========+=========+
480    | ``spec`` | ignored |
481    +----------+---------+
482    | ``last`` | ignored |
483    +----------+---------+
484    | ``mask`` | ignored |
485    +----------+---------+
486
487 Usage example, matching non-TCPv4 packets only:
488
489 .. _table_rte_flow_item_invert_example:
490
491 .. table:: Anything but TCPv4
492
493    +-------+----------+
494    | Index | Item     |
495    +=======+==========+
496    | 0     | INVERT   |
497    +-------+----------+
498    | 1     | Ethernet |
499    +-------+----------+
500    | 2     | IPv4     |
501    +-------+----------+
502    | 3     | TCP      |
503    +-------+----------+
504    | 4     | END      |
505    +-------+----------+
506
507 Item: ``PF``
508 ^^^^^^^^^^^^
509
510 Matches packets addressed to the physical function of the device.
511
512 If the underlying device function differs from the one that would normally
513 receive the matched traffic, specifying this item prevents it from reaching
514 that device unless the flow rule contains a `Action: PF`_. Packets are not
515 duplicated between device instances by default.
516
517 - Likely to return an error or never match any traffic if applied to a VF
518   device.
519 - Can be combined with any number of `Item: VF`_ to match both PF and VF
520   traffic.
521 - ``spec``, ``last`` and ``mask`` must not be set.
522
523 .. _table_rte_flow_item_pf:
524
525 .. table:: PF
526
527    +----------+-------+
528    | Field    | Value |
529    +==========+=======+
530    | ``spec`` | unset |
531    +----------+-------+
532    | ``last`` | unset |
533    +----------+-------+
534    | ``mask`` | unset |
535    +----------+-------+
536
537 Item: ``VF``
538 ^^^^^^^^^^^^
539
540 Matches packets addressed to a virtual function ID of the device.
541
542 If the underlying device function differs from the one that would normally
543 receive the matched traffic, specifying this item prevents it from reaching
544 that device unless the flow rule contains a `Action: VF`_. Packets are not
545 duplicated between device instances by default.
546
547 - Likely to return an error or never match any traffic if this causes a VF
548   device to match traffic addressed to a different VF.
549 - Can be specified multiple times to match traffic addressed to several VF
550   IDs.
551 - Can be combined with a PF item to match both PF and VF traffic.
552 - Default ``mask`` matches any VF ID.
553
554 .. _table_rte_flow_item_vf:
555
556 .. table:: VF
557
558    +----------+----------+---------------------------+
559    | Field    | Subfield | Value                     |
560    +==========+==========+===========================+
561    | ``spec`` | ``id``   | destination VF ID         |
562    +----------+----------+---------------------------+
563    | ``last`` | ``id``   | upper range value         |
564    +----------+----------+---------------------------+
565    | ``mask`` | ``id``   | zeroed to match any VF ID |
566    +----------+----------+---------------------------+
567
568 Item: ``PORT``
569 ^^^^^^^^^^^^^^
570
571 Matches packets coming from the specified physical port of the underlying
572 device.
573
574 The first PORT item overrides the physical port normally associated with the
575 specified DPDK input port (port_id). This item can be provided several times
576 to match additional physical ports.
577
578 Note that physical ports are not necessarily tied to DPDK input ports
579 (port_id) when those are not under DPDK control. Possible values are
580 specific to each device, they are not necessarily indexed from zero and may
581 not be contiguous.
582
583 As a device property, the list of allowed values as well as the value
584 associated with a port_id should be retrieved by other means.
585
586 - Default ``mask`` matches any port index.
587
588 .. _table_rte_flow_item_port:
589
590 .. table:: PORT
591
592    +----------+-----------+--------------------------------+
593    | Field    | Subfield  | Value                          |
594    +==========+===========+================================+
595    | ``spec`` | ``index`` | physical port index            |
596    +----------+-----------+--------------------------------+
597    | ``last`` | ``index`` | upper range value              |
598    +----------+-----------+--------------------------------+
599    | ``mask`` | ``index`` | zeroed to match any port index |
600    +----------+-----------+--------------------------------+
601
602 Data matching item types
603 ~~~~~~~~~~~~~~~~~~~~~~~~
604
605 Most of these are basically protocol header definitions with associated
606 bit-masks. They must be specified (stacked) from lowest to highest protocol
607 layer to form a matching pattern.
608
609 The following list is not exhaustive, new protocols will be added in the
610 future.
611
612 Item: ``ANY``
613 ^^^^^^^^^^^^^
614
615 Matches any protocol in place of the current layer, a single ANY may also
616 stand for several protocol layers.
617
618 This is usually specified as the first pattern item when looking for a
619 protocol anywhere in a packet.
620
621 - Default ``mask`` stands for any number of layers.
622
623 .. _table_rte_flow_item_any:
624
625 .. table:: ANY
626
627    +----------+----------+--------------------------------------+
628    | Field    | Subfield | Value                                |
629    +==========+==========+======================================+
630    | ``spec`` | ``num``  | number of layers covered             |
631    +----------+----------+--------------------------------------+
632    | ``last`` | ``num``  | upper range value                    |
633    +----------+----------+--------------------------------------+
634    | ``mask`` | ``num``  | zeroed to cover any number of layers |
635    +----------+----------+--------------------------------------+
636
637 Example for VXLAN TCP payload matching regardless of outer L3 (IPv4 or IPv6)
638 and L4 (UDP) both matched by the first ANY specification, and inner L3 (IPv4
639 or IPv6) matched by the second ANY specification:
640
641 .. _table_rte_flow_item_any_example:
642
643 .. table:: TCP in VXLAN with wildcards
644
645    +-------+------+----------+----------+-------+
646    | Index | Item | Field    | Subfield | Value |
647    +=======+======+==========+==========+=======+
648    | 0     | Ethernet                           |
649    +-------+------+----------+----------+-------+
650    | 1     | ANY  | ``spec`` | ``num``  | 2     |
651    +-------+------+----------+----------+-------+
652    | 2     | VXLAN                              |
653    +-------+------------------------------------+
654    | 3     | Ethernet                           |
655    +-------+------+----------+----------+-------+
656    | 4     | ANY  | ``spec`` | ``num``  | 1     |
657    +-------+------+----------+----------+-------+
658    | 5     | TCP                                |
659    +-------+------------------------------------+
660    | 6     | END                                |
661    +-------+------------------------------------+
662
663 Item: ``RAW``
664 ^^^^^^^^^^^^^
665
666 Matches a byte string of a given length at a given offset.
667
668 Offset is either absolute (using the start of the packet) or relative to the
669 end of the previous matched item in the stack, in which case negative values
670 are allowed.
671
672 If search is enabled, offset is used as the starting point. The search area
673 can be delimited by setting limit to a nonzero value, which is the maximum
674 number of bytes after offset where the pattern may start.
675
676 Matching a zero-length pattern is allowed, doing so resets the relative
677 offset for subsequent items.
678
679 - This type does not support ranges (``last`` field).
680 - Default ``mask`` matches all fields exactly.
681
682 .. _table_rte_flow_item_raw:
683
684 .. table:: RAW
685
686    +----------+--------------+-------------------------------------------------+
687    | Field    | Subfield     | Value                                           |
688    +==========+==============+=================================================+
689    | ``spec`` | ``relative`` | look for pattern after the previous item        |
690    |          +--------------+-------------------------------------------------+
691    |          | ``search``   | search pattern from offset (see also ``limit``) |
692    |          +--------------+-------------------------------------------------+
693    |          | ``reserved`` | reserved, must be set to zero                   |
694    |          +--------------+-------------------------------------------------+
695    |          | ``offset``   | absolute or relative offset for ``pattern``     |
696    |          +--------------+-------------------------------------------------+
697    |          | ``limit``    | search area limit for start of ``pattern``      |
698    |          +--------------+-------------------------------------------------+
699    |          | ``length``   | ``pattern`` length                              |
700    |          +--------------+-------------------------------------------------+
701    |          | ``pattern``  | byte string to look for                         |
702    +----------+--------------+-------------------------------------------------+
703    | ``last`` | if specified, either all 0 or with the same values as ``spec`` |
704    +----------+----------------------------------------------------------------+
705    | ``mask`` | bit-mask applied to ``spec`` values with usual behavior        |
706    +----------+----------------------------------------------------------------+
707
708 Example pattern looking for several strings at various offsets of a UDP
709 payload, using combined RAW items:
710
711 .. _table_rte_flow_item_raw_example:
712
713 .. table:: UDP payload matching
714
715    +-------+------+----------+--------------+-------+
716    | Index | Item | Field    | Subfield     | Value |
717    +=======+======+==========+==============+=======+
718    | 0     | Ethernet                               |
719    +-------+----------------------------------------+
720    | 1     | IPv4                                   |
721    +-------+----------------------------------------+
722    | 2     | UDP                                    |
723    +-------+------+----------+--------------+-------+
724    | 3     | RAW  | ``spec`` | ``relative`` | 1     |
725    |       |      |          +--------------+-------+
726    |       |      |          | ``search``   | 1     |
727    |       |      |          +--------------+-------+
728    |       |      |          | ``offset``   | 10    |
729    |       |      |          +--------------+-------+
730    |       |      |          | ``limit``    | 0     |
731    |       |      |          +--------------+-------+
732    |       |      |          | ``length``   | 3     |
733    |       |      |          +--------------+-------+
734    |       |      |          | ``pattern``  | "foo" |
735    +-------+------+----------+--------------+-------+
736    | 4     | RAW  | ``spec`` | ``relative`` | 1     |
737    |       |      |          +--------------+-------+
738    |       |      |          | ``search``   | 0     |
739    |       |      |          +--------------+-------+
740    |       |      |          | ``offset``   | 20    |
741    |       |      |          +--------------+-------+
742    |       |      |          | ``limit``    | 0     |
743    |       |      |          +--------------+-------+
744    |       |      |          | ``length``   | 3     |
745    |       |      |          +--------------+-------+
746    |       |      |          | ``pattern``  | "bar" |
747    +-------+------+----------+--------------+-------+
748    | 5     | RAW  | ``spec`` | ``relative`` | 1     |
749    |       |      |          +--------------+-------+
750    |       |      |          | ``search``   | 0     |
751    |       |      |          +--------------+-------+
752    |       |      |          | ``offset``   | -29   |
753    |       |      |          +--------------+-------+
754    |       |      |          | ``limit``    | 0     |
755    |       |      |          +--------------+-------+
756    |       |      |          | ``length``   | 3     |
757    |       |      |          +--------------+-------+
758    |       |      |          | ``pattern``  | "baz" |
759    +-------+------+----------+--------------+-------+
760    | 6     | END                                    |
761    +-------+----------------------------------------+
762
763 This translates to:
764
765 - Locate "foo" at least 10 bytes deep inside UDP payload.
766 - Locate "bar" after "foo" plus 20 bytes.
767 - Locate "baz" after "bar" minus 29 bytes.
768
769 Such a packet may be represented as follows (not to scale)::
770
771  0                     >= 10 B           == 20 B
772  |                  |<--------->|     |<--------->|
773  |                  |           |     |           |
774  |-----|------|-----|-----|-----|-----|-----------|-----|------|
775  | ETH | IPv4 | UDP | ... | baz | foo | ......... | bar | .... |
776  |-----|------|-----|-----|-----|-----|-----------|-----|------|
777                           |                             |
778                           |<--------------------------->|
779                                       == 29 B
780
781 Note that matching subsequent pattern items would resume after "baz", not
782 "bar" since matching is always performed after the previous item of the
783 stack.
784
785 Item: ``ETH``
786 ^^^^^^^^^^^^^
787
788 Matches an Ethernet header.
789
790 - ``dst``: destination MAC.
791 - ``src``: source MAC.
792 - ``type``: EtherType.
793 - Default ``mask`` matches destination and source addresses only.
794
795 Item: ``VLAN``
796 ^^^^^^^^^^^^^^
797
798 Matches an 802.1Q/ad VLAN tag.
799
800 - ``tpid``: tag protocol identifier.
801 - ``tci``: tag control information.
802 - Default ``mask`` matches TCI only.
803
804 Item: ``IPV4``
805 ^^^^^^^^^^^^^^
806
807 Matches an IPv4 header.
808
809 Note: IPv4 options are handled by dedicated pattern items.
810
811 - ``hdr``: IPv4 header definition (``rte_ip.h``).
812 - Default ``mask`` matches source and destination addresses only.
813
814 Item: ``IPV6``
815 ^^^^^^^^^^^^^^
816
817 Matches an IPv6 header.
818
819 Note: IPv6 options are handled by dedicated pattern items.
820
821 - ``hdr``: IPv6 header definition (``rte_ip.h``).
822 - Default ``mask`` matches source and destination addresses only.
823
824 Item: ``ICMP``
825 ^^^^^^^^^^^^^^
826
827 Matches an ICMP header.
828
829 - ``hdr``: ICMP header definition (``rte_icmp.h``).
830 - Default ``mask`` matches ICMP type and code only.
831
832 Item: ``UDP``
833 ^^^^^^^^^^^^^
834
835 Matches a UDP header.
836
837 - ``hdr``: UDP header definition (``rte_udp.h``).
838 - Default ``mask`` matches source and destination ports only.
839
840 Item: ``TCP``
841 ^^^^^^^^^^^^^
842
843 Matches a TCP header.
844
845 - ``hdr``: TCP header definition (``rte_tcp.h``).
846 - Default ``mask`` matches source and destination ports only.
847
848 Item: ``SCTP``
849 ^^^^^^^^^^^^^^
850
851 Matches a SCTP header.
852
853 - ``hdr``: SCTP header definition (``rte_sctp.h``).
854 - Default ``mask`` matches source and destination ports only.
855
856 Item: ``VXLAN``
857 ^^^^^^^^^^^^^^^
858
859 Matches a VXLAN header (RFC 7348).
860
861 - ``flags``: normally 0x08 (I flag).
862 - ``rsvd0``: reserved, normally 0x000000.
863 - ``vni``: VXLAN network identifier.
864 - ``rsvd1``: reserved, normally 0x00.
865 - Default ``mask`` matches VNI only.
866
867 Item: ``E_TAG``
868 ^^^^^^^^^^^^^^^
869
870 Matches an IEEE 802.1BR E-Tag header.
871
872 - ``tpid``: tag protocol identifier (0x893F)
873 - ``epcp_edei_in_ecid_b``: E-Tag control information (E-TCI), E-PCP (3b),
874   E-DEI (1b), ingress E-CID base (12b).
875 - ``rsvd_grp_ecid_b``: reserved (2b), GRP (2b), E-CID base (12b).
876 - ``in_ecid_e``: ingress E-CID ext.
877 - ``ecid_e``: E-CID ext.
878 - Default ``mask`` simultaneously matches GRP and E-CID base.
879
880 Item: ``NVGRE``
881 ^^^^^^^^^^^^^^^
882
883 Matches a NVGRE header (RFC 7637).
884
885 - ``c_k_s_rsvd0_ver``: checksum (1b), undefined (1b), key bit (1b),
886   sequence number (1b), reserved 0 (9b), version (3b). This field must have
887   value 0x2000 according to RFC 7637.
888 - ``protocol``: protocol type (0x6558).
889 - ``tni``: virtual subnet ID.
890 - ``flow_id``: flow ID.
891 - Default ``mask`` matches TNI only.
892
893 Item: ``MPLS``
894 ^^^^^^^^^^^^^^
895
896 Matches a MPLS header.
897
898 - ``label_tc_s_ttl``: label, TC, Bottom of Stack and TTL.
899 - Default ``mask`` matches label only.
900
901 Item: ``GRE``
902 ^^^^^^^^^^^^^
903
904 Matches a GRE header.
905
906 - ``c_rsvd0_ver``: checksum, reserved 0 and version.
907 - ``protocol``: protocol type.
908 - Default ``mask`` matches protocol only.
909
910 Item: ``FUZZY``
911 ^^^^^^^^^^^^^^^
912
913 Fuzzy pattern match, expect faster than default.
914
915 This is for device that support fuzzy match option. Usually a fuzzy match is
916 fast but the cost is accuracy. i.e. Signature Match only match pattern's hash
917 value, but it is possible two different patterns have the same hash value.
918
919 Matching accuracy level can be configured by threshold. Driver can divide the
920 range of threshold and map to different accuracy levels that device support.
921
922 Threshold 0 means perfect match (no fuzziness), while threshold 0xffffffff
923 means fuzziest match.
924
925 .. _table_rte_flow_item_fuzzy:
926
927 .. table:: FUZZY
928
929    +----------+---------------+--------------------------------------------------+
930    | Field    |   Subfield    | Value                                            |
931    +==========+===============+==================================================+
932    | ``spec`` | ``threshold`` | 0 as perfect match, 0xffffffff as fuzziest match |
933    +----------+---------------+--------------------------------------------------+
934    | ``last`` | ``threshold`` | upper range value                                |
935    +----------+---------------+--------------------------------------------------+
936    | ``mask`` | ``threshold`` | bit-mask apply to "spec" and "last"              |
937    +----------+---------------+--------------------------------------------------+
938
939 Usage example, fuzzy match a TCPv4 packets:
940
941 .. _table_rte_flow_item_fuzzy_example:
942
943 .. table:: Fuzzy matching
944
945    +-------+----------+
946    | Index | Item     |
947    +=======+==========+
948    | 0     | FUZZY    |
949    +-------+----------+
950    | 1     | Ethernet |
951    +-------+----------+
952    | 2     | IPv4     |
953    +-------+----------+
954    | 3     | TCP      |
955    +-------+----------+
956    | 4     | END      |
957    +-------+----------+
958
959 Item: ``GTP``, ``GTPC``, ``GTPU``
960 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
961
962 Matches a GTPv1 header.
963
964 Note: GTP, GTPC and GTPU use the same structure. GTPC and GTPU item
965 are defined for a user-friendly API when creating GTP-C and GTP-U
966 flow rules.
967
968 - ``v_pt_rsv_flags``: version (3b), protocol type (1b), reserved (1b),
969   extension header flag (1b), sequence number flag (1b), N-PDU number
970   flag (1b).
971 - ``msg_type``: message type.
972 - ``msg_len``: message length.
973 - ``teid``: tunnel endpoint identifier.
974 - Default ``mask`` matches teid only.
975
976 Item: ``ESP``
977 ^^^^^^^^^^^^^
978
979 Matches an ESP header.
980
981 - ``hdr``: ESP header definition (``rte_esp.h``).
982 - Default ``mask`` matches SPI only.
983
984 Item: ``GENEVE``
985 ^^^^^^^^^^^^^^^^
986
987 Matches a GENEVE header.
988
989 - ``ver_opt_len_o_c_rsvd0``: version (2b), length of the options fields (6b),
990   OAM packet (1b), critical options present (1b), reserved 0 (6b).
991 - ``protocol``: protocol type.
992 - ``vni``: virtual network identifier.
993 - ``rsvd1``: reserved, normally 0x00.
994 - Default ``mask`` matches VNI only.
995
996 Actions
997 ~~~~~~~
998
999 Each possible action is represented by a type. Some have associated
1000 configuration structures. Several actions combined in a list can be assigned
1001 to a flow rule. That list is not ordered.
1002
1003 They fall in three categories:
1004
1005 - Terminating actions that prevent processing matched packets by subsequent
1006   flow rules, unless overridden with PASSTHRU.
1007
1008 - Non-terminating actions that leave matched packets up for additional
1009   processing by subsequent flow rules.
1010
1011 - Other non-terminating meta actions that do not affect the fate of packets.
1012
1013 When several actions are combined in a flow rule, they should all have
1014 different types (e.g. dropping a packet twice is not possible).
1015
1016 Only the last action of a given type is taken into account. PMDs still
1017 perform error checking on the entire list.
1018
1019 Like matching patterns, action lists are terminated by END items.
1020
1021 *Note that PASSTHRU is the only action able to override a terminating rule.*
1022
1023 Example of action that redirects packets to queue index 10:
1024
1025 .. _table_rte_flow_action_example:
1026
1027 .. table:: Queue action
1028
1029    +-----------+-------+
1030    | Field     | Value |
1031    +===========+=======+
1032    | ``index`` | 10    |
1033    +-----------+-------+
1034
1035 Action lists examples, their order is not significant, applications must
1036 consider all actions to be performed simultaneously:
1037
1038 .. _table_rte_flow_count_and_drop:
1039
1040 .. table:: Count and drop
1041
1042    +-------+--------+
1043    | Index | Action |
1044    +=======+========+
1045    | 0     | COUNT  |
1046    +-------+--------+
1047    | 1     | DROP   |
1048    +-------+--------+
1049    | 2     | END    |
1050    +-------+--------+
1051
1052 |
1053
1054 .. _table_rte_flow_mark_count_redirect:
1055
1056 .. table:: Mark, count and redirect
1057
1058    +-------+--------+-----------+-------+
1059    | Index | Action | Field     | Value |
1060    +=======+========+===========+=======+
1061    | 0     | MARK   | ``mark``  | 0x2a  |
1062    +-------+--------+-----------+-------+
1063    | 1     | COUNT                      |
1064    +-------+--------+-----------+-------+
1065    | 2     | QUEUE  | ``queue`` | 10    |
1066    +-------+--------+-----------+-------+
1067    | 3     | END                        |
1068    +-------+----------------------------+
1069
1070 |
1071
1072 .. _table_rte_flow_redirect_queue_5:
1073
1074 .. table:: Redirect to queue 5
1075
1076    +-------+--------+-----------+-------+
1077    | Index | Action | Field     | Value |
1078    +=======+========+===========+=======+
1079    | 0     | DROP                       |
1080    +-------+--------+-----------+-------+
1081    | 1     | QUEUE  | ``queue`` | 5     |
1082    +-------+--------+-----------+-------+
1083    | 2     | END                        |
1084    +-------+----------------------------+
1085
1086 In the above example, considering both actions are performed simultaneously,
1087 the end result is that only QUEUE has any effect.
1088
1089 .. _table_rte_flow_redirect_queue_3:
1090
1091 .. table:: Redirect to queue 3
1092
1093    +-------+--------+-----------+-------+
1094    | Index | Action | Field     | Value |
1095    +=======+========+===========+=======+
1096    | 0     | QUEUE  | ``queue`` | 5     |
1097    +-------+--------+-----------+-------+
1098    | 1     | VOID                       |
1099    +-------+--------+-----------+-------+
1100    | 2     | QUEUE  | ``queue`` | 3     |
1101    +-------+--------+-----------+-------+
1102    | 3     | END                        |
1103    +-------+----------------------------+
1104
1105 As previously described, only the last action of a given type found in the
1106 list is taken into account. The above example also shows that VOID is
1107 ignored.
1108
1109 Action types
1110 ~~~~~~~~~~~~
1111
1112 Common action types are described in this section. Like pattern item types,
1113 this list is not exhaustive as new actions will be added in the future.
1114
1115 Action: ``END``
1116 ^^^^^^^^^^^^^^^
1117
1118 End marker for action lists. Prevents further processing of actions, thereby
1119 ending the list.
1120
1121 - Its numeric value is 0 for convenience.
1122 - PMD support is mandatory.
1123 - No configurable properties.
1124
1125 .. _table_rte_flow_action_end:
1126
1127 .. table:: END
1128
1129    +---------------+
1130    | Field         |
1131    +===============+
1132    | no properties |
1133    +---------------+
1134
1135 Action: ``VOID``
1136 ^^^^^^^^^^^^^^^^
1137
1138 Used as a placeholder for convenience. It is ignored and simply discarded by
1139 PMDs.
1140
1141 - PMD support is mandatory.
1142 - No configurable properties.
1143
1144 .. _table_rte_flow_action_void:
1145
1146 .. table:: VOID
1147
1148    +---------------+
1149    | Field         |
1150    +===============+
1151    | no properties |
1152    +---------------+
1153
1154 Action: ``PASSTHRU``
1155 ^^^^^^^^^^^^^^^^^^^^
1156
1157 Leaves packets up for additional processing by subsequent flow rules. This
1158 is the default when a rule does not contain a terminating action, but can be
1159 specified to force a rule to become non-terminating.
1160
1161 - No configurable properties.
1162
1163 .. _table_rte_flow_action_passthru:
1164
1165 .. table:: PASSTHRU
1166
1167    +---------------+
1168    | Field         |
1169    +===============+
1170    | no properties |
1171    +---------------+
1172
1173 Example to copy a packet to a queue and continue processing by subsequent
1174 flow rules:
1175
1176 .. _table_rte_flow_action_passthru_example:
1177
1178 .. table:: Copy to queue 8
1179
1180    +-------+--------+-----------+-------+
1181    | Index | Action | Field     | Value |
1182    +=======+========+===========+=======+
1183    | 0     | PASSTHRU                   |
1184    +-------+--------+-----------+-------+
1185    | 1     | QUEUE  | ``queue`` | 8     |
1186    +-------+--------+-----------+-------+
1187    | 2     | END                        |
1188    +-------+----------------------------+
1189
1190 Action: ``MARK``
1191 ^^^^^^^^^^^^^^^^
1192
1193 Attaches an integer value to packets and sets ``PKT_RX_FDIR`` and
1194 ``PKT_RX_FDIR_ID`` mbuf flags.
1195
1196 This value is arbitrary and application-defined. Maximum allowed value
1197 depends on the underlying implementation. It is returned in the
1198 ``hash.fdir.hi`` mbuf field.
1199
1200 .. _table_rte_flow_action_mark:
1201
1202 .. table:: MARK
1203
1204    +--------+--------------------------------------+
1205    | Field  | Value                                |
1206    +========+======================================+
1207    | ``id`` | integer value to return with packets |
1208    +--------+--------------------------------------+
1209
1210 Action: ``FLAG``
1211 ^^^^^^^^^^^^^^^^
1212
1213 Flags packets. Similar to `Action: MARK`_ without a specific value; only
1214 sets the ``PKT_RX_FDIR`` mbuf flag.
1215
1216 - No configurable properties.
1217
1218 .. _table_rte_flow_action_flag:
1219
1220 .. table:: FLAG
1221
1222    +---------------+
1223    | Field         |
1224    +===============+
1225    | no properties |
1226    +---------------+
1227
1228 Action: ``QUEUE``
1229 ^^^^^^^^^^^^^^^^^
1230
1231 Assigns packets to a given queue index.
1232
1233 - Terminating by default.
1234
1235 .. _table_rte_flow_action_queue:
1236
1237 .. table:: QUEUE
1238
1239    +-----------+--------------------+
1240    | Field     | Value              |
1241    +===========+====================+
1242    | ``index`` | queue index to use |
1243    +-----------+--------------------+
1244
1245 Action: ``DROP``
1246 ^^^^^^^^^^^^^^^^
1247
1248 Drop packets.
1249
1250 - No configurable properties.
1251 - Terminating by default.
1252 - PASSTHRU overrides this action if both are specified.
1253
1254 .. _table_rte_flow_action_drop:
1255
1256 .. table:: DROP
1257
1258    +---------------+
1259    | Field         |
1260    +===============+
1261    | no properties |
1262    +---------------+
1263
1264 Action: ``COUNT``
1265 ^^^^^^^^^^^^^^^^^
1266
1267 Enables counters for this rule.
1268
1269 These counters can be retrieved and reset through ``rte_flow_query()``, see
1270 ``struct rte_flow_query_count``.
1271
1272 - Counters can be retrieved with ``rte_flow_query()``.
1273 - No configurable properties.
1274
1275 .. _table_rte_flow_action_count:
1276
1277 .. table:: COUNT
1278
1279    +---------------+
1280    | Field         |
1281    +===============+
1282    | no properties |
1283    +---------------+
1284
1285 Query structure to retrieve and reset flow rule counters:
1286
1287 .. _table_rte_flow_query_count:
1288
1289 .. table:: COUNT query
1290
1291    +---------------+-----+-----------------------------------+
1292    | Field         | I/O | Value                             |
1293    +===============+=====+===================================+
1294    | ``reset``     | in  | reset counter after query         |
1295    +---------------+-----+-----------------------------------+
1296    | ``hits_set``  | out | ``hits`` field is set             |
1297    +---------------+-----+-----------------------------------+
1298    | ``bytes_set`` | out | ``bytes`` field is set            |
1299    +---------------+-----+-----------------------------------+
1300    | ``hits``      | out | number of hits for this rule      |
1301    +---------------+-----+-----------------------------------+
1302    | ``bytes``     | out | number of bytes through this rule |
1303    +---------------+-----+-----------------------------------+
1304
1305 Action: ``DUP``
1306 ^^^^^^^^^^^^^^^
1307
1308 Duplicates packets to a given queue index.
1309
1310 This is normally combined with QUEUE, however when used alone, it is
1311 actually similar to QUEUE + PASSTHRU.
1312
1313 - Non-terminating by default.
1314
1315 .. _table_rte_flow_action_dup:
1316
1317 .. table:: DUP
1318
1319    +-----------+------------------------------------+
1320    | Field     | Value                              |
1321    +===========+====================================+
1322    | ``index`` | queue index to duplicate packet to |
1323    +-----------+------------------------------------+
1324
1325 Action: ``RSS``
1326 ^^^^^^^^^^^^^^^
1327
1328 Similar to QUEUE, except RSS is additionally performed on packets to spread
1329 them among several queues according to the provided parameters.
1330
1331 Note: RSS hash result is stored in the ``hash.rss`` mbuf field which
1332 overlaps ``hash.fdir.lo``. Since `Action: MARK`_ sets the ``hash.fdir.hi``
1333 field only, both can be requested simultaneously.
1334
1335 - Terminating by default.
1336
1337 .. _table_rte_flow_action_rss:
1338
1339 .. table:: RSS
1340
1341    +--------------+------------------------------+
1342    | Field        | Value                        |
1343    +==============+==============================+
1344    | ``rss_conf`` | RSS parameters               |
1345    +--------------+------------------------------+
1346    | ``num``      | number of entries in queue[] |
1347    +--------------+------------------------------+
1348    | ``queue[]``  | queue indices to use         |
1349    +--------------+------------------------------+
1350
1351 Action: ``PF``
1352 ^^^^^^^^^^^^^^
1353
1354 Redirects packets to the physical function (PF) of the current device.
1355
1356 - No configurable properties.
1357 - Terminating by default.
1358
1359 .. _table_rte_flow_action_pf:
1360
1361 .. table:: PF
1362
1363    +---------------+
1364    | Field         |
1365    +===============+
1366    | no properties |
1367    +---------------+
1368
1369 Action: ``VF``
1370 ^^^^^^^^^^^^^^
1371
1372 Redirects packets to a virtual function (VF) of the current device.
1373
1374 Packets matched by a VF pattern item can be redirected to their original VF
1375 ID instead of the specified one. This parameter may not be available and is
1376 not guaranteed to work properly if the VF part is matched by a prior flow
1377 rule or if packets are not addressed to a VF in the first place.
1378
1379 - Terminating by default.
1380
1381 .. _table_rte_flow_action_vf:
1382
1383 .. table:: VF
1384
1385    +--------------+--------------------------------+
1386    | Field        | Value                          |
1387    +==============+================================+
1388    | ``original`` | use original VF ID if possible |
1389    +--------------+--------------------------------+
1390    | ``vf``       | VF ID to redirect packets to   |
1391    +--------------+--------------------------------+
1392
1393 Action: ``METER``
1394 ^^^^^^^^^^^^^^^^^
1395
1396 Applies a stage of metering and policing.
1397
1398 The metering and policing (MTR) object has to be first created using the
1399 rte_mtr_create() API function. The ID of the MTR object is specified as
1400 action parameter. More than one flow can use the same MTR object through
1401 the meter action. The MTR object can be further updated or queried using
1402 the rte_mtr* API.
1403
1404 - Non-terminating by default.
1405
1406 .. _table_rte_flow_action_meter:
1407
1408 .. table:: METER
1409
1410    +--------------+---------------+
1411    | Field        | Value         |
1412    +==============+===============+
1413    | ``mtr_id``   | MTR object ID |
1414    +--------------+---------------+
1415
1416 Action: ``SECURITY``
1417 ^^^^^^^^^^^^^^^^^^^^
1418
1419 Perform the security action on flows matched by the pattern items
1420 according to the configuration of the security session.
1421
1422 This action modifies the payload of matched flows. For INLINE_CRYPTO, the
1423 security protocol headers and IV are fully provided by the application as
1424 specified in the flow pattern. The payload of matching packets is
1425 encrypted on egress, and decrypted and authenticated on ingress.
1426 For INLINE_PROTOCOL, the security protocol is fully offloaded to HW,
1427 providing full encapsulation and decapsulation of packets in security
1428 protocols. The flow pattern specifies both the outer security header fields
1429 and the inner packet fields. The security session specified in the action
1430 must match the pattern parameters.
1431
1432 The security session specified in the action must be created on the same
1433 port as the flow action that is being specified.
1434
1435 The ingress/egress flow attribute should match that specified in the
1436 security session if the security session supports the definition of the
1437 direction.
1438
1439 Multiple flows can be configured to use the same security session.
1440
1441 - Non-terminating by default.
1442
1443 .. _table_rte_flow_action_security:
1444
1445 .. table:: SECURITY
1446
1447    +----------------------+--------------------------------------+
1448    | Field                | Value                                |
1449    +======================+======================================+
1450    | ``security_session`` | security session to apply            |
1451    +----------------------+--------------------------------------+
1452
1453 The following is an example of configuring IPsec inline using the
1454 INLINE_CRYPTO security session:
1455
1456 The encryption algorithm, keys and salt are part of the opaque
1457 ``rte_security_session``. The SA is identified according to the IP and ESP
1458 fields in the pattern items.
1459
1460 .. _table_rte_flow_item_esp_inline_example:
1461
1462 .. table:: IPsec inline crypto flow pattern items.
1463
1464    +-------+----------+
1465    | Index | Item     |
1466    +=======+==========+
1467    | 0     | Ethernet |
1468    +-------+----------+
1469    | 1     | IPv4     |
1470    +-------+----------+
1471    | 2     | ESP      |
1472    +-------+----------+
1473    | 3     | END      |
1474    +-------+----------+
1475
1476 .. _table_rte_flow_action_esp_inline_example:
1477
1478 .. table:: IPsec inline flow actions.
1479
1480    +-------+----------+
1481    | Index | Action   |
1482    +=======+==========+
1483    | 0     | SECURITY |
1484    +-------+----------+
1485    | 1     | END      |
1486    +-------+----------+
1487
1488 Negative types
1489 ~~~~~~~~~~~~~~
1490
1491 All specified pattern items (``enum rte_flow_item_type``) and actions
1492 (``enum rte_flow_action_type``) use positive identifiers.
1493
1494 The negative space is reserved for dynamic types generated by PMDs during
1495 run-time. PMDs may encounter them as a result but must not accept negative
1496 identifiers they are not aware of.
1497
1498 A method to generate them remains to be defined.
1499
1500 Planned types
1501 ~~~~~~~~~~~~~
1502
1503 Pattern item types will be added as new protocols are implemented.
1504
1505 Variable headers support through dedicated pattern items, for example in
1506 order to match specific IPv4 options and IPv6 extension headers would be
1507 stacked after IPv4/IPv6 items.
1508
1509 Other action types are planned but are not defined yet. These include the
1510 ability to alter packet data in several ways, such as performing
1511 encapsulation/decapsulation of tunnel headers.
1512
1513 Rules management
1514 ----------------
1515
1516 A rather simple API with few functions is provided to fully manage flow
1517 rules.
1518
1519 Each created flow rule is associated with an opaque, PMD-specific handle
1520 pointer. The application is responsible for keeping it until the rule is
1521 destroyed.
1522
1523 Flows rules are represented by ``struct rte_flow`` objects.
1524
1525 Validation
1526 ~~~~~~~~~~
1527
1528 Given that expressing a definite set of device capabilities is not
1529 practical, a dedicated function is provided to check if a flow rule is
1530 supported and can be created.
1531
1532 .. code-block:: c
1533
1534    int
1535    rte_flow_validate(uint16_t port_id,
1536                      const struct rte_flow_attr *attr,
1537                      const struct rte_flow_item pattern[],
1538                      const struct rte_flow_action actions[],
1539                      struct rte_flow_error *error);
1540
1541 The flow rule is validated for correctness and whether it could be accepted
1542 by the device given sufficient resources. The rule is checked against the
1543 current device mode and queue configuration. The flow rule may also
1544 optionally be validated against existing flow rules and device resources.
1545 This function has no effect on the target device.
1546
1547 The returned value is guaranteed to remain valid only as long as no
1548 successful calls to ``rte_flow_create()`` or ``rte_flow_destroy()`` are made
1549 in the meantime and no device parameter affecting flow rules in any way are
1550 modified, due to possible collisions or resource limitations (although in
1551 such cases ``EINVAL`` should not be returned).
1552
1553 Arguments:
1554
1555 - ``port_id``: port identifier of Ethernet device.
1556 - ``attr``: flow rule attributes.
1557 - ``pattern``: pattern specification (list terminated by the END pattern
1558   item).
1559 - ``actions``: associated actions (list terminated by the END action).
1560 - ``error``: perform verbose error reporting if not NULL. PMDs initialize
1561   this structure in case of error only.
1562
1563 Return values:
1564
1565 - 0 if flow rule is valid and can be created. A negative errno value
1566   otherwise (``rte_errno`` is also set), the following errors are defined.
1567 - ``-ENOSYS``: underlying device does not support this functionality.
1568 - ``-EINVAL``: unknown or invalid rule specification.
1569 - ``-ENOTSUP``: valid but unsupported rule specification (e.g. partial
1570   bit-masks are unsupported).
1571 - ``EEXIST``: collision with an existing rule. Only returned if device
1572   supports flow rule collision checking and there was a flow rule
1573   collision. Not receiving this return code is no guarantee that creating
1574   the rule will not fail due to a collision.
1575 - ``ENOMEM``: not enough memory to execute the function, or if the device
1576   supports resource validation, resource limitation on the device.
1577 - ``-EBUSY``: action cannot be performed due to busy device resources, may
1578   succeed if the affected queues or even the entire port are in a stopped
1579   state (see ``rte_eth_dev_rx_queue_stop()`` and ``rte_eth_dev_stop()``).
1580
1581 Creation
1582 ~~~~~~~~
1583
1584 Creating a flow rule is similar to validating one, except the rule is
1585 actually created and a handle returned.
1586
1587 .. code-block:: c
1588
1589    struct rte_flow *
1590    rte_flow_create(uint16_t port_id,
1591                    const struct rte_flow_attr *attr,
1592                    const struct rte_flow_item pattern[],
1593                    const struct rte_flow_action *actions[],
1594                    struct rte_flow_error *error);
1595
1596 Arguments:
1597
1598 - ``port_id``: port identifier of Ethernet device.
1599 - ``attr``: flow rule attributes.
1600 - ``pattern``: pattern specification (list terminated by the END pattern
1601   item).
1602 - ``actions``: associated actions (list terminated by the END action).
1603 - ``error``: perform verbose error reporting if not NULL. PMDs initialize
1604   this structure in case of error only.
1605
1606 Return values:
1607
1608 A valid handle in case of success, NULL otherwise and ``rte_errno`` is set
1609 to the positive version of one of the error codes defined for
1610 ``rte_flow_validate()``.
1611
1612 Destruction
1613 ~~~~~~~~~~~
1614
1615 Flow rules destruction is not automatic, and a queue or a port should not be
1616 released if any are still attached to them. Applications must take care of
1617 performing this step before releasing resources.
1618
1619 .. code-block:: c
1620
1621    int
1622    rte_flow_destroy(uint16_t port_id,
1623                     struct rte_flow *flow,
1624                     struct rte_flow_error *error);
1625
1626
1627 Failure to destroy a flow rule handle may occur when other flow rules depend
1628 on it, and destroying it would result in an inconsistent state.
1629
1630 This function is only guaranteed to succeed if handles are destroyed in
1631 reverse order of their creation.
1632
1633 Arguments:
1634
1635 - ``port_id``: port identifier of Ethernet device.
1636 - ``flow``: flow rule handle to destroy.
1637 - ``error``: perform verbose error reporting if not NULL. PMDs initialize
1638   this structure in case of error only.
1639
1640 Return values:
1641
1642 - 0 on success, a negative errno value otherwise and ``rte_errno`` is set.
1643
1644 Flush
1645 ~~~~~
1646
1647 Convenience function to destroy all flow rule handles associated with a
1648 port. They are released as with successive calls to ``rte_flow_destroy()``.
1649
1650 .. code-block:: c
1651
1652    int
1653    rte_flow_flush(uint16_t port_id,
1654                   struct rte_flow_error *error);
1655
1656 In the unlikely event of failure, handles are still considered destroyed and
1657 no longer valid but the port must be assumed to be in an inconsistent state.
1658
1659 Arguments:
1660
1661 - ``port_id``: port identifier of Ethernet device.
1662 - ``error``: perform verbose error reporting if not NULL. PMDs initialize
1663   this structure in case of error only.
1664
1665 Return values:
1666
1667 - 0 on success, a negative errno value otherwise and ``rte_errno`` is set.
1668
1669 Query
1670 ~~~~~
1671
1672 Query an existing flow rule.
1673
1674 This function allows retrieving flow-specific data such as counters. Data
1675 is gathered by special actions which must be present in the flow rule
1676 definition.
1677
1678 .. code-block:: c
1679
1680    int
1681    rte_flow_query(uint16_t port_id,
1682                   struct rte_flow *flow,
1683                   enum rte_flow_action_type action,
1684                   void *data,
1685                   struct rte_flow_error *error);
1686
1687 Arguments:
1688
1689 - ``port_id``: port identifier of Ethernet device.
1690 - ``flow``: flow rule handle to query.
1691 - ``action``: action type to query.
1692 - ``data``: pointer to storage for the associated query data type.
1693 - ``error``: perform verbose error reporting if not NULL. PMDs initialize
1694   this structure in case of error only.
1695
1696 Return values:
1697
1698 - 0 on success, a negative errno value otherwise and ``rte_errno`` is set.
1699
1700 Isolated mode
1701 -------------
1702
1703 The general expectation for ingress traffic is that flow rules process it
1704 first; the remaining unmatched or pass-through traffic usually ends up in a
1705 queue (with or without RSS, locally or in some sub-device instance)
1706 depending on the global configuration settings of a port.
1707
1708 While fine from a compatibility standpoint, this approach makes drivers more
1709 complex as they have to check for possible side effects outside of this API
1710 when creating or destroying flow rules. It results in a more limited set of
1711 available rule types due to the way device resources are assigned (e.g. no
1712 support for the RSS action even on capable hardware).
1713
1714 Given that nonspecific traffic can be handled by flow rules as well,
1715 isolated mode is a means for applications to tell a driver that ingress on
1716 the underlying port must be injected from the defined flow rules only; that
1717 no default traffic is expected outside those rules.
1718
1719 This has the following benefits:
1720
1721 - Applications get finer-grained control over the kind of traffic they want
1722   to receive (no traffic by default).
1723
1724 - More importantly they control at what point nonspecific traffic is handled
1725   relative to other flow rules, by adjusting priority levels.
1726
1727 - Drivers can assign more hardware resources to flow rules and expand the
1728   set of supported rule types.
1729
1730 Because toggling isolated mode may cause profound changes to the ingress
1731 processing path of a driver, it may not be possible to leave it once
1732 entered. Likewise, existing flow rules or global configuration settings may
1733 prevent a driver from entering isolated mode.
1734
1735 Applications relying on this mode are therefore encouraged to toggle it as
1736 soon as possible after device initialization, ideally before the first call
1737 to ``rte_eth_dev_configure()`` to avoid possible failures due to conflicting
1738 settings.
1739
1740 Once effective, the following functionality has no effect on the underlying
1741 port and may return errors such as ``ENOTSUP`` ("not supported"):
1742
1743 - Toggling promiscuous mode.
1744 - Toggling allmulticast mode.
1745 - Configuring MAC addresses.
1746 - Configuring multicast addresses.
1747 - Configuring VLAN filters.
1748 - Configuring Rx filters through the legacy API (e.g. FDIR).
1749 - Configuring global RSS settings.
1750
1751 .. code-block:: c
1752
1753    int
1754    rte_flow_isolate(uint16_t port_id, int set, struct rte_flow_error *error);
1755
1756 Arguments:
1757
1758 - ``port_id``: port identifier of Ethernet device.
1759 - ``set``: nonzero to enter isolated mode, attempt to leave it otherwise.
1760 - ``error``: perform verbose error reporting if not NULL. PMDs initialize
1761   this structure in case of error only.
1762
1763 Return values:
1764
1765 - 0 on success, a negative errno value otherwise and ``rte_errno`` is set.
1766
1767 Verbose error reporting
1768 -----------------------
1769
1770 The defined *errno* values may not be accurate enough for users or
1771 application developers who want to investigate issues related to flow rules
1772 management. A dedicated error object is defined for this purpose:
1773
1774 .. code-block:: c
1775
1776    enum rte_flow_error_type {
1777        RTE_FLOW_ERROR_TYPE_NONE, /**< No error. */
1778        RTE_FLOW_ERROR_TYPE_UNSPECIFIED, /**< Cause unspecified. */
1779        RTE_FLOW_ERROR_TYPE_HANDLE, /**< Flow rule (handle). */
1780        RTE_FLOW_ERROR_TYPE_ATTR_GROUP, /**< Group field. */
1781        RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY, /**< Priority field. */
1782        RTE_FLOW_ERROR_TYPE_ATTR_INGRESS, /**< Ingress field. */
1783        RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, /**< Egress field. */
1784        RTE_FLOW_ERROR_TYPE_ATTR, /**< Attributes structure. */
1785        RTE_FLOW_ERROR_TYPE_ITEM_NUM, /**< Pattern length. */
1786        RTE_FLOW_ERROR_TYPE_ITEM, /**< Specific pattern item. */
1787        RTE_FLOW_ERROR_TYPE_ACTION_NUM, /**< Number of actions. */
1788        RTE_FLOW_ERROR_TYPE_ACTION, /**< Specific action. */
1789    };
1790
1791    struct rte_flow_error {
1792        enum rte_flow_error_type type; /**< Cause field and error types. */
1793        const void *cause; /**< Object responsible for the error. */
1794        const char *message; /**< Human-readable error message. */
1795    };
1796
1797 Error type ``RTE_FLOW_ERROR_TYPE_NONE`` stands for no error, in which case
1798 remaining fields can be ignored. Other error types describe the type of the
1799 object pointed by ``cause``.
1800
1801 If non-NULL, ``cause`` points to the object responsible for the error. For a
1802 flow rule, this may be a pattern item or an individual action.
1803
1804 If non-NULL, ``message`` provides a human-readable error message.
1805
1806 This object is normally allocated by applications and set by PMDs in case of
1807 error, the message points to a constant string which does not need to be
1808 freed by the application, however its pointer can be considered valid only
1809 as long as its associated DPDK port remains configured. Closing the
1810 underlying device or unloading the PMD invalidates it.
1811
1812 Helpers
1813 -------
1814
1815 Error initializer
1816 ~~~~~~~~~~~~~~~~~
1817
1818 .. code-block:: c
1819
1820    static inline int
1821    rte_flow_error_set(struct rte_flow_error *error,
1822                       int code,
1823                       enum rte_flow_error_type type,
1824                       const void *cause,
1825                       const char *message);
1826
1827 This function initializes ``error`` (if non-NULL) with the provided
1828 parameters and sets ``rte_errno`` to ``code``. A negative error ``code`` is
1829 then returned.
1830
1831 Caveats
1832 -------
1833
1834 - DPDK does not keep track of flow rules definitions or flow rule objects
1835   automatically. Applications may keep track of the former and must keep
1836   track of the latter. PMDs may also do it for internal needs, however this
1837   must not be relied on by applications.
1838
1839 - Flow rules are not maintained between successive port initializations. An
1840   application exiting without releasing them and restarting must re-create
1841   them from scratch.
1842
1843 - API operations are synchronous and blocking (``EAGAIN`` cannot be
1844   returned).
1845
1846 - There is no provision for reentrancy/multi-thread safety, although nothing
1847   should prevent different devices from being configured at the same
1848   time. PMDs may protect their control path functions accordingly.
1849
1850 - Stopping the data path (TX/RX) should not be necessary when managing flow
1851   rules. If this cannot be achieved naturally or with workarounds (such as
1852   temporarily replacing the burst function pointers), an appropriate error
1853   code must be returned (``EBUSY``).
1854
1855 - PMDs, not applications, are responsible for maintaining flow rules
1856   configuration when stopping and restarting a port or performing other
1857   actions which may affect them. They can only be destroyed explicitly by
1858   applications.
1859
1860 For devices exposing multiple ports sharing global settings affected by flow
1861 rules:
1862
1863 - All ports under DPDK control must behave consistently, PMDs are
1864   responsible for making sure that existing flow rules on a port are not
1865   affected by other ports.
1866
1867 - Ports not under DPDK control (unaffected or handled by other applications)
1868   are user's responsibility. They may affect existing flow rules and cause
1869   undefined behavior. PMDs aware of this may prevent flow rules creation
1870   altogether in such cases.
1871
1872 PMD interface
1873 -------------
1874
1875 The PMD interface is defined in ``rte_flow_driver.h``. It is not subject to
1876 API/ABI versioning constraints as it is not exposed to applications and may
1877 evolve independently.
1878
1879 It is currently implemented on top of the legacy filtering framework through
1880 filter type *RTE_ETH_FILTER_GENERIC* that accepts the single operation
1881 *RTE_ETH_FILTER_GET* to return PMD-specific *rte_flow* callbacks wrapped
1882 inside ``struct rte_flow_ops``.
1883
1884 This overhead is temporarily necessary in order to keep compatibility with
1885 the legacy filtering framework, which should eventually disappear.
1886
1887 - PMD callbacks implement exactly the interface described in `Rules
1888   management`_, except for the port ID argument which has already been
1889   converted to a pointer to the underlying ``struct rte_eth_dev``.
1890
1891 - Public API functions do not process flow rules definitions at all before
1892   calling PMD functions (no basic error checking, no validation
1893   whatsoever). They only make sure these callbacks are non-NULL or return
1894   the ``ENOSYS`` (function not supported) error.
1895
1896 This interface additionally defines the following helper function:
1897
1898 - ``rte_flow_ops_get()``: get generic flow operations structure from a
1899   port.
1900
1901 More will be added over time.
1902
1903 Device compatibility
1904 --------------------
1905
1906 No known implementation supports all the described features.
1907
1908 Unsupported features or combinations are not expected to be fully emulated
1909 in software by PMDs for performance reasons. Partially supported features
1910 may be completed in software as long as hardware performs most of the work
1911 (such as queue redirection and packet recognition).
1912
1913 However PMDs are expected to do their best to satisfy application requests
1914 by working around hardware limitations as long as doing so does not affect
1915 the behavior of existing flow rules.
1916
1917 The following sections provide a few examples of such cases and describe how
1918 PMDs should handle them, they are based on limitations built into the
1919 previous APIs.
1920
1921 Global bit-masks
1922 ~~~~~~~~~~~~~~~~
1923
1924 Each flow rule comes with its own, per-layer bit-masks, while hardware may
1925 support only a single, device-wide bit-mask for a given layer type, so that
1926 two IPv4 rules cannot use different bit-masks.
1927
1928 The expected behavior in this case is that PMDs automatically configure
1929 global bit-masks according to the needs of the first flow rule created.
1930
1931 Subsequent rules are allowed only if their bit-masks match those, the
1932 ``EEXIST`` error code should be returned otherwise.
1933
1934 Unsupported layer types
1935 ~~~~~~~~~~~~~~~~~~~~~~~
1936
1937 Many protocols can be simulated by crafting patterns with the `Item: RAW`_
1938 type.
1939
1940 PMDs can rely on this capability to simulate support for protocols with
1941 headers not directly recognized by hardware.
1942
1943 ``ANY`` pattern item
1944 ~~~~~~~~~~~~~~~~~~~~
1945
1946 This pattern item stands for anything, which can be difficult to translate
1947 to something hardware would understand, particularly if followed by more
1948 specific types.
1949
1950 Consider the following pattern:
1951
1952 .. _table_rte_flow_unsupported_any:
1953
1954 .. table:: Pattern with ANY as L3
1955
1956    +-------+-----------------------+
1957    | Index | Item                  |
1958    +=======+=======================+
1959    | 0     | ETHER                 |
1960    +-------+-----+---------+-------+
1961    | 1     | ANY | ``num`` | ``1`` |
1962    +-------+-----+---------+-------+
1963    | 2     | TCP                   |
1964    +-------+-----------------------+
1965    | 3     | END                   |
1966    +-------+-----------------------+
1967
1968 Knowing that TCP does not make sense with something other than IPv4 and IPv6
1969 as L3, such a pattern may be translated to two flow rules instead:
1970
1971 .. _table_rte_flow_unsupported_any_ipv4:
1972
1973 .. table:: ANY replaced with IPV4
1974
1975    +-------+--------------------+
1976    | Index | Item               |
1977    +=======+====================+
1978    | 0     | ETHER              |
1979    +-------+--------------------+
1980    | 1     | IPV4 (zeroed mask) |
1981    +-------+--------------------+
1982    | 2     | TCP                |
1983    +-------+--------------------+
1984    | 3     | END                |
1985    +-------+--------------------+
1986
1987 |
1988
1989 .. _table_rte_flow_unsupported_any_ipv6:
1990
1991 .. table:: ANY replaced with IPV6
1992
1993    +-------+--------------------+
1994    | Index | Item               |
1995    +=======+====================+
1996    | 0     | ETHER              |
1997    +-------+--------------------+
1998    | 1     | IPV6 (zeroed mask) |
1999    +-------+--------------------+
2000    | 2     | TCP                |
2001    +-------+--------------------+
2002    | 3     | END                |
2003    +-------+--------------------+
2004
2005 Note that as soon as a ANY rule covers several layers, this approach may
2006 yield a large number of hidden flow rules. It is thus suggested to only
2007 support the most common scenarios (anything as L2 and/or L3).
2008
2009 Unsupported actions
2010 ~~~~~~~~~~~~~~~~~~~
2011
2012 - When combined with `Action: QUEUE`_, packet counting (`Action: COUNT`_)
2013   and tagging (`Action: MARK`_ or `Action: FLAG`_) may be implemented in
2014   software as long as the target queue is used by a single rule.
2015
2016 - A rule specifying both `Action: DUP`_ + `Action: QUEUE`_ may be translated
2017   to two hidden rules combining `Action: QUEUE`_ and `Action: PASSTHRU`_.
2018
2019 - When a single target queue is provided, `Action: RSS`_ can also be
2020   implemented through `Action: QUEUE`_.
2021
2022 Flow rules priority
2023 ~~~~~~~~~~~~~~~~~~~
2024
2025 While it would naturally make sense, flow rules cannot be assumed to be
2026 processed by hardware in the same order as their creation for several
2027 reasons:
2028
2029 - They may be managed internally as a tree or a hash table instead of a
2030   list.
2031 - Removing a flow rule before adding another one can either put the new rule
2032   at the end of the list or reuse a freed entry.
2033 - Duplication may occur when packets are matched by several rules.
2034
2035 For overlapping rules (particularly in order to use `Action: PASSTHRU`_)
2036 predictable behavior is only guaranteed by using different priority levels.
2037
2038 Priority levels are not necessarily implemented in hardware, or may be
2039 severely limited (e.g. a single priority bit).
2040
2041 For these reasons, priority levels may be implemented purely in software by
2042 PMDs.
2043
2044 - For devices expecting flow rules to be added in the correct order, PMDs
2045   may destroy and re-create existing rules after adding a new one with
2046   a higher priority.
2047
2048 - A configurable number of dummy or empty rules can be created at
2049   initialization time to save high priority slots for later.
2050
2051 - In order to save priority levels, PMDs may evaluate whether rules are
2052   likely to collide and adjust their priority accordingly.
2053
2054 Future evolutions
2055 -----------------
2056
2057 - A device profile selection function which could be used to force a
2058   permanent profile instead of relying on its automatic configuration based
2059   on existing flow rules.
2060
2061 - A method to optimize *rte_flow* rules with specific pattern items and
2062   action types generated on the fly by PMDs. DPDK should assign negative
2063   numbers to these in order to not collide with the existing types. See
2064   `Negative types`_.
2065
2066 - Adding specific egress pattern items and actions as described in
2067   `Attribute: Traffic direction`_.
2068
2069 - Optional software fallback when PMDs are unable to handle requested flow
2070   rules so applications do not have to implement their own.
2071
2072 API migration
2073 -------------
2074
2075 Exhaustive list of deprecated filter types (normally prefixed with
2076 *RTE_ETH_FILTER_*) found in ``rte_eth_ctrl.h`` and methods to convert them
2077 to *rte_flow* rules.
2078
2079 ``MACVLAN`` to ``ETH`` → ``VF``, ``PF``
2080 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2081
2082 *MACVLAN* can be translated to a basic `Item: ETH`_ flow rule with a
2083 terminating `Action: VF`_ or `Action: PF`_.
2084
2085 .. _table_rte_flow_migration_macvlan:
2086
2087 .. table:: MACVLAN conversion
2088
2089    +--------------------------+---------+
2090    | Pattern                  | Actions |
2091    +===+=====+==========+=====+=========+
2092    | 0 | ETH | ``spec`` | any | VF,     |
2093    |   |     +----------+-----+ PF      |
2094    |   |     | ``last`` | N/A |         |
2095    |   |     +----------+-----+         |
2096    |   |     | ``mask`` | any |         |
2097    +---+-----+----------+-----+---------+
2098    | 1 | END                  | END     |
2099    +---+----------------------+---------+
2100
2101 ``ETHERTYPE`` to ``ETH`` → ``QUEUE``, ``DROP``
2102 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2103
2104 *ETHERTYPE* is basically an `Item: ETH`_ flow rule with a terminating
2105 `Action: QUEUE`_ or `Action: DROP`_.
2106
2107 .. _table_rte_flow_migration_ethertype:
2108
2109 .. table:: ETHERTYPE conversion
2110
2111    +--------------------------+---------+
2112    | Pattern                  | Actions |
2113    +===+=====+==========+=====+=========+
2114    | 0 | ETH | ``spec`` | any | QUEUE,  |
2115    |   |     +----------+-----+ DROP    |
2116    |   |     | ``last`` | N/A |         |
2117    |   |     +----------+-----+         |
2118    |   |     | ``mask`` | any |         |
2119    +---+-----+----------+-----+---------+
2120    | 1 | END                  | END     |
2121    +---+----------------------+---------+
2122
2123 ``FLEXIBLE`` to ``RAW`` → ``QUEUE``
2124 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2125
2126 *FLEXIBLE* can be translated to one `Item: RAW`_ pattern with a terminating
2127 `Action: QUEUE`_ and a defined priority level.
2128
2129 .. _table_rte_flow_migration_flexible:
2130
2131 .. table:: FLEXIBLE conversion
2132
2133    +--------------------------+---------+
2134    | Pattern                  | Actions |
2135    +===+=====+==========+=====+=========+
2136    | 0 | RAW | ``spec`` | any | QUEUE   |
2137    |   |     +----------+-----+         |
2138    |   |     | ``last`` | N/A |         |
2139    |   |     +----------+-----+         |
2140    |   |     | ``mask`` | any |         |
2141    +---+-----+----------+-----+---------+
2142    | 1 | END                  | END     |
2143    +---+----------------------+---------+
2144
2145 ``SYN`` to ``TCP`` → ``QUEUE``
2146 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2147
2148 *SYN* is a `Item: TCP`_ rule with only the ``syn`` bit enabled and masked,
2149 and a terminating `Action: QUEUE`_.
2150
2151 Priority level can be set to simulate the high priority bit.
2152
2153 .. _table_rte_flow_migration_syn:
2154
2155 .. table:: SYN conversion
2156
2157    +-----------------------------------+---------+
2158    | Pattern                           | Actions |
2159    +===+======+==========+=============+=========+
2160    | 0 | ETH  | ``spec`` | unset       | QUEUE   |
2161    |   |      +----------+-------------+         |
2162    |   |      | ``last`` | unset       |         |
2163    |   |      +----------+-------------+         |
2164    |   |      | ``mask`` | unset       |         |
2165    +---+------+----------+-------------+---------+
2166    | 1 | IPV4 | ``spec`` | unset       | END     |
2167    |   |      +----------+-------------+         |
2168    |   |      | ``mask`` | unset       |         |
2169    |   |      +----------+-------------+         |
2170    |   |      | ``mask`` | unset       |         |
2171    +---+------+----------+---------+---+         |
2172    | 2 | TCP  | ``spec`` | ``syn`` | 1 |         |
2173    |   |      +----------+---------+---+         |
2174    |   |      | ``mask`` | ``syn`` | 1 |         |
2175    +---+------+----------+---------+---+         |
2176    | 3 | END                           |         |
2177    +---+-------------------------------+---------+
2178
2179 ``NTUPLE`` to ``IPV4``, ``TCP``, ``UDP`` → ``QUEUE``
2180 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2181
2182 *NTUPLE* is similar to specifying an empty L2, `Item: IPV4`_ as L3 with
2183 `Item: TCP`_ or `Item: UDP`_ as L4 and a terminating `Action: QUEUE`_.
2184
2185 A priority level can be specified as well.
2186
2187 .. _table_rte_flow_migration_ntuple:
2188
2189 .. table:: NTUPLE conversion
2190
2191    +-----------------------------+---------+
2192    | Pattern                     | Actions |
2193    +===+======+==========+=======+=========+
2194    | 0 | ETH  | ``spec`` | unset | QUEUE   |
2195    |   |      +----------+-------+         |
2196    |   |      | ``last`` | unset |         |
2197    |   |      +----------+-------+         |
2198    |   |      | ``mask`` | unset |         |
2199    +---+------+----------+-------+---------+
2200    | 1 | IPV4 | ``spec`` | any   | END     |
2201    |   |      +----------+-------+         |
2202    |   |      | ``last`` | unset |         |
2203    |   |      +----------+-------+         |
2204    |   |      | ``mask`` | any   |         |
2205    +---+------+----------+-------+         |
2206    | 2 | TCP, | ``spec`` | any   |         |
2207    |   | UDP  +----------+-------+         |
2208    |   |      | ``last`` | unset |         |
2209    |   |      +----------+-------+         |
2210    |   |      | ``mask`` | any   |         |
2211    +---+------+----------+-------+         |
2212    | 3 | END                     |         |
2213    +---+-------------------------+---------+
2214
2215 ``TUNNEL`` to ``ETH``, ``IPV4``, ``IPV6``, ``VXLAN`` (or other) → ``QUEUE``
2216 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2217
2218 *TUNNEL* matches common IPv4 and IPv6 L3/L4-based tunnel types.
2219
2220 In the following table, `Item: ANY`_ is used to cover the optional L4.
2221
2222 .. _table_rte_flow_migration_tunnel:
2223
2224 .. table:: TUNNEL conversion
2225
2226    +-------------------------------------------------------+---------+
2227    | Pattern                                               | Actions |
2228    +===+==========================+==========+=============+=========+
2229    | 0 | ETH                      | ``spec`` | any         | QUEUE   |
2230    |   |                          +----------+-------------+         |
2231    |   |                          | ``last`` | unset       |         |
2232    |   |                          +----------+-------------+         |
2233    |   |                          | ``mask`` | any         |         |
2234    +---+--------------------------+----------+-------------+---------+
2235    | 1 | IPV4, IPV6               | ``spec`` | any         | END     |
2236    |   |                          +----------+-------------+         |
2237    |   |                          | ``last`` | unset       |         |
2238    |   |                          +----------+-------------+         |
2239    |   |                          | ``mask`` | any         |         |
2240    +---+--------------------------+----------+-------------+         |
2241    | 2 | ANY                      | ``spec`` | any         |         |
2242    |   |                          +----------+-------------+         |
2243    |   |                          | ``last`` | unset       |         |
2244    |   |                          +----------+---------+---+         |
2245    |   |                          | ``mask`` | ``num`` | 0 |         |
2246    +---+--------------------------+----------+---------+---+         |
2247    | 3 | VXLAN, GENEVE, TEREDO,   | ``spec`` | any         |         |
2248    |   | NVGRE, GRE, ...          +----------+-------------+         |
2249    |   |                          | ``last`` | unset       |         |
2250    |   |                          +----------+-------------+         |
2251    |   |                          | ``mask`` | any         |         |
2252    +---+--------------------------+----------+-------------+         |
2253    | 4 | END                                               |         |
2254    +---+---------------------------------------------------+---------+
2255
2256 ``FDIR`` to most item types → ``QUEUE``, ``DROP``, ``PASSTHRU``
2257 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2258
2259 *FDIR* is more complex than any other type, there are several methods to
2260 emulate its functionality. It is summarized for the most part in the table
2261 below.
2262
2263 A few features are intentionally not supported:
2264
2265 - The ability to configure the matching input set and masks for the entire
2266   device, PMDs should take care of it automatically according to the
2267   requested flow rules.
2268
2269   For example if a device supports only one bit-mask per protocol type,
2270   source/address IPv4 bit-masks can be made immutable by the first created
2271   rule. Subsequent IPv4 or TCPv4 rules can only be created if they are
2272   compatible.
2273
2274   Note that only protocol bit-masks affected by existing flow rules are
2275   immutable, others can be changed later. They become mutable again after
2276   the related flow rules are destroyed.
2277
2278 - Returning four or eight bytes of matched data when using flex bytes
2279   filtering. Although a specific action could implement it, it conflicts
2280   with the much more useful 32 bits tagging on devices that support it.
2281
2282 - Side effects on RSS processing of the entire device. Flow rules that
2283   conflict with the current device configuration should not be
2284   allowed. Similarly, device configuration should not be allowed when it
2285   affects existing flow rules.
2286
2287 - Device modes of operation. "none" is unsupported since filtering cannot be
2288   disabled as long as a flow rule is present.
2289
2290 - "MAC VLAN" or "tunnel" perfect matching modes should be automatically set
2291   according to the created flow rules.
2292
2293 - Signature mode of operation is not defined but could be handled through
2294   "FUZZY" item.
2295
2296 .. _table_rte_flow_migration_fdir:
2297
2298 .. table:: FDIR conversion
2299
2300    +----------------------------------------+-----------------------+
2301    | Pattern                                | Actions               |
2302    +===+===================+==========+=====+=======================+
2303    | 0 | ETH, RAW          | ``spec`` | any | QUEUE, DROP, PASSTHRU |
2304    |   |                   +----------+-----+                       |
2305    |   |                   | ``last`` | N/A |                       |
2306    |   |                   +----------+-----+                       |
2307    |   |                   | ``mask`` | any |                       |
2308    +---+-------------------+----------+-----+-----------------------+
2309    | 1 | IPV4, IPv6        | ``spec`` | any | MARK                  |
2310    |   |                   +----------+-----+                       |
2311    |   |                   | ``last`` | N/A |                       |
2312    |   |                   +----------+-----+                       |
2313    |   |                   | ``mask`` | any |                       |
2314    +---+-------------------+----------+-----+-----------------------+
2315    | 2 | TCP, UDP, SCTP    | ``spec`` | any | END                   |
2316    |   |                   +----------+-----+                       |
2317    |   |                   | ``last`` | N/A |                       |
2318    |   |                   +----------+-----+                       |
2319    |   |                   | ``mask`` | any |                       |
2320    +---+-------------------+----------+-----+                       |
2321    | 3 | VF, PF, FUZZY     | ``spec`` | any |                       |
2322    |   | (optional)        +----------+-----+                       |
2323    |   |                   | ``last`` | N/A |                       |
2324    |   |                   +----------+-----+                       |
2325    |   |                   | ``mask`` | any |                       |
2326    +---+-------------------+----------+-----+                       |
2327    | 4 | END                                |                       |
2328    +---+------------------------------------+-----------------------+
2329
2330 ``HASH``
2331 ~~~~~~~~
2332
2333 There is no counterpart to this filter type because it translates to a
2334 global device setting instead of a pattern item. Device settings are
2335 automatically set according to the created flow rules.
2336
2337 ``L2_TUNNEL`` to ``VOID`` → ``VXLAN`` (or others)
2338 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2339
2340 All packets are matched. This type alters incoming packets to encapsulate
2341 them in a chosen tunnel type, optionally redirect them to a VF as well.
2342
2343 The destination pool for tag based forwarding can be emulated with other
2344 flow rules using `Action: DUP`_.
2345
2346 .. _table_rte_flow_migration_l2tunnel:
2347
2348 .. table:: L2_TUNNEL conversion
2349
2350    +---------------------------+--------------------+
2351    | Pattern                   | Actions            |
2352    +===+======+==========+=====+====================+
2353    | 0 | VOID | ``spec`` | N/A | VXLAN, GENEVE, ... |
2354    |   |      |          |     |                    |
2355    |   |      |          |     |                    |
2356    |   |      +----------+-----+                    |
2357    |   |      | ``last`` | N/A |                    |
2358    |   |      +----------+-----+                    |
2359    |   |      | ``mask`` | N/A |                    |
2360    |   |      |          |     |                    |
2361    +---+------+----------+-----+--------------------+
2362    | 1 | END                   | VF (optional)      |
2363    +---+                       +--------------------+
2364    | 2 |                       | END                |
2365    +---+-----------------------+--------------------+