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