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