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