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