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