ethdev: add AH key field to flow API
[dpdk.git] / lib / librte_ethdev / rte_flow.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2016 6WIND S.A.
3  * Copyright 2016 Mellanox Technologies, Ltd
4  */
5
6 #ifndef RTE_FLOW_H_
7 #define RTE_FLOW_H_
8
9 /**
10  * @file
11  * RTE generic flow API
12  *
13  * This interface provides the ability to program packet matching and
14  * associated actions in hardware through flow rules.
15  */
16
17 #include <stddef.h>
18 #include <stdint.h>
19
20 #include <rte_arp.h>
21 #include <rte_common.h>
22 #include <rte_ether.h>
23 #include <rte_icmp.h>
24 #include <rte_ip.h>
25 #include <rte_sctp.h>
26 #include <rte_tcp.h>
27 #include <rte_udp.h>
28 #include <rte_byteorder.h>
29 #include <rte_esp.h>
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35 /**
36  * Flow rule attributes.
37  *
38  * Priorities are set on a per rule based within groups.
39  *
40  * Lower values denote higher priority, the highest priority for a flow rule
41  * is 0, so that a flow that matches for than one rule, the rule with the
42  * lowest priority value will always be matched.
43  *
44  * Although optional, applications are encouraged to group similar rules as
45  * much as possible to fully take advantage of hardware capabilities
46  * (e.g. optimized matching) and work around limitations (e.g. a single
47  * pattern type possibly allowed in a given group). Applications should be
48  * aware that groups are not linked by default, and that they must be
49  * explicitly linked by the application using the JUMP action.
50  *
51  * Priority levels are arbitrary and up to the application, they
52  * do not need to be contiguous nor start from 0, however the maximum number
53  * varies between devices and may be affected by existing flow rules.
54  *
55  * If a packet is matched by several rules of a given group for a given
56  * priority level, the outcome is undefined. It can take any path, may be
57  * duplicated or even cause unrecoverable errors.
58  *
59  * Note that support for more than a single group and priority level is not
60  * guaranteed.
61  *
62  * Flow rules can apply to inbound and/or outbound traffic (ingress/egress).
63  *
64  * Several pattern items and actions are valid and can be used in both
65  * directions. Those valid for only one direction are described as such.
66  *
67  * At least one direction must be specified.
68  *
69  * Specifying both directions at once for a given rule is not recommended
70  * but may be valid in a few cases (e.g. shared counter).
71  */
72 struct rte_flow_attr {
73         uint32_t group; /**< Priority group. */
74         uint32_t priority; /**< Rule priority level within group. */
75         uint32_t ingress:1; /**< Rule applies to ingress traffic. */
76         uint32_t egress:1; /**< Rule applies to egress traffic. */
77         /**
78          * Instead of simply matching the properties of traffic as it would
79          * appear on a given DPDK port ID, enabling this attribute transfers
80          * a flow rule to the lowest possible level of any device endpoints
81          * found in the pattern.
82          *
83          * When supported, this effectively enables an application to
84          * re-route traffic not necessarily intended for it (e.g. coming
85          * from or addressed to different physical ports, VFs or
86          * applications) at the device level.
87          *
88          * It complements the behavior of some pattern items such as
89          * RTE_FLOW_ITEM_TYPE_PHY_PORT and is meaningless without them.
90          *
91          * When transferring flow rules, ingress and egress attributes keep
92          * their original meaning, as if processing traffic emitted or
93          * received by the application.
94          */
95         uint32_t transfer:1;
96         uint32_t reserved:29; /**< Reserved, must be zero. */
97 };
98
99 /**
100  * Matching pattern item types.
101  *
102  * Pattern items fall in two categories:
103  *
104  * - Matching protocol headers and packet data, usually associated with a
105  *   specification structure. These must be stacked in the same order as the
106  *   protocol layers to match inside packets, starting from the lowest.
107  *
108  * - Matching meta-data or affecting pattern processing, often without a
109  *   specification structure. Since they do not match packet contents, their
110  *   position in the list is usually not relevant.
111  *
112  * See the description of individual types for more information. Those
113  * marked with [META] fall into the second category.
114  */
115 enum rte_flow_item_type {
116         /**
117          * [META]
118          *
119          * End marker for item lists. Prevents further processing of items,
120          * thereby ending the pattern.
121          *
122          * No associated specification structure.
123          */
124         RTE_FLOW_ITEM_TYPE_END,
125
126         /**
127          * [META]
128          *
129          * Used as a placeholder for convenience. It is ignored and simply
130          * discarded by PMDs.
131          *
132          * No associated specification structure.
133          */
134         RTE_FLOW_ITEM_TYPE_VOID,
135
136         /**
137          * [META]
138          *
139          * Inverted matching, i.e. process packets that do not match the
140          * pattern.
141          *
142          * No associated specification structure.
143          */
144         RTE_FLOW_ITEM_TYPE_INVERT,
145
146         /**
147          * Matches any protocol in place of the current layer, a single ANY
148          * may also stand for several protocol layers.
149          *
150          * See struct rte_flow_item_any.
151          */
152         RTE_FLOW_ITEM_TYPE_ANY,
153
154         /**
155          * [META]
156          *
157          * Matches traffic originating from (ingress) or going to (egress)
158          * the physical function of the current device.
159          *
160          * No associated specification structure.
161          */
162         RTE_FLOW_ITEM_TYPE_PF,
163
164         /**
165          * [META]
166          *
167          * Matches traffic originating from (ingress) or going to (egress) a
168          * given virtual function of the current device.
169          *
170          * See struct rte_flow_item_vf.
171          */
172         RTE_FLOW_ITEM_TYPE_VF,
173
174         /**
175          * [META]
176          *
177          * Matches traffic originating from (ingress) or going to (egress) a
178          * physical port of the underlying device.
179          *
180          * See struct rte_flow_item_phy_port.
181          */
182         RTE_FLOW_ITEM_TYPE_PHY_PORT,
183
184         /**
185          * [META]
186          *
187          * Matches traffic originating from (ingress) or going to (egress) a
188          * given DPDK port ID.
189          *
190          * See struct rte_flow_item_port_id.
191          */
192         RTE_FLOW_ITEM_TYPE_PORT_ID,
193
194         /**
195          * Matches a byte string of a given length at a given offset.
196          *
197          * See struct rte_flow_item_raw.
198          */
199         RTE_FLOW_ITEM_TYPE_RAW,
200
201         /**
202          * Matches an Ethernet header.
203          *
204          * See struct rte_flow_item_eth.
205          */
206         RTE_FLOW_ITEM_TYPE_ETH,
207
208         /**
209          * Matches an 802.1Q/ad VLAN tag.
210          *
211          * See struct rte_flow_item_vlan.
212          */
213         RTE_FLOW_ITEM_TYPE_VLAN,
214
215         /**
216          * Matches an IPv4 header.
217          *
218          * See struct rte_flow_item_ipv4.
219          */
220         RTE_FLOW_ITEM_TYPE_IPV4,
221
222         /**
223          * Matches an IPv6 header.
224          *
225          * See struct rte_flow_item_ipv6.
226          */
227         RTE_FLOW_ITEM_TYPE_IPV6,
228
229         /**
230          * Matches an ICMP header.
231          *
232          * See struct rte_flow_item_icmp.
233          */
234         RTE_FLOW_ITEM_TYPE_ICMP,
235
236         /**
237          * Matches a UDP header.
238          *
239          * See struct rte_flow_item_udp.
240          */
241         RTE_FLOW_ITEM_TYPE_UDP,
242
243         /**
244          * Matches a TCP header.
245          *
246          * See struct rte_flow_item_tcp.
247          */
248         RTE_FLOW_ITEM_TYPE_TCP,
249
250         /**
251          * Matches a SCTP header.
252          *
253          * See struct rte_flow_item_sctp.
254          */
255         RTE_FLOW_ITEM_TYPE_SCTP,
256
257         /**
258          * Matches a VXLAN header.
259          *
260          * See struct rte_flow_item_vxlan.
261          */
262         RTE_FLOW_ITEM_TYPE_VXLAN,
263
264         /**
265          * Matches a E_TAG header.
266          *
267          * See struct rte_flow_item_e_tag.
268          */
269         RTE_FLOW_ITEM_TYPE_E_TAG,
270
271         /**
272          * Matches a NVGRE header.
273          *
274          * See struct rte_flow_item_nvgre.
275          */
276         RTE_FLOW_ITEM_TYPE_NVGRE,
277
278         /**
279          * Matches a MPLS header.
280          *
281          * See struct rte_flow_item_mpls.
282          */
283         RTE_FLOW_ITEM_TYPE_MPLS,
284
285         /**
286          * Matches a GRE header.
287          *
288          * See struct rte_flow_item_gre.
289          */
290         RTE_FLOW_ITEM_TYPE_GRE,
291
292         /**
293          * [META]
294          *
295          * Fuzzy pattern match, expect faster than default.
296          *
297          * This is for device that support fuzzy matching option.
298          * Usually a fuzzy matching is fast but the cost is accuracy.
299          *
300          * See struct rte_flow_item_fuzzy.
301          */
302         RTE_FLOW_ITEM_TYPE_FUZZY,
303
304         /**
305          * Matches a GTP header.
306          *
307          * Configure flow for GTP packets.
308          *
309          * See struct rte_flow_item_gtp.
310          */
311         RTE_FLOW_ITEM_TYPE_GTP,
312
313         /**
314          * Matches a GTP header.
315          *
316          * Configure flow for GTP-C packets.
317          *
318          * See struct rte_flow_item_gtp.
319          */
320         RTE_FLOW_ITEM_TYPE_GTPC,
321
322         /**
323          * Matches a GTP header.
324          *
325          * Configure flow for GTP-U packets.
326          *
327          * See struct rte_flow_item_gtp.
328          */
329         RTE_FLOW_ITEM_TYPE_GTPU,
330
331         /**
332          * Matches a ESP header.
333          *
334          * See struct rte_flow_item_esp.
335          */
336         RTE_FLOW_ITEM_TYPE_ESP,
337
338         /**
339          * Matches a GENEVE header.
340          *
341          * See struct rte_flow_item_geneve.
342          */
343         RTE_FLOW_ITEM_TYPE_GENEVE,
344
345         /**
346          * Matches a VXLAN-GPE header.
347          *
348          * See struct rte_flow_item_vxlan_gpe.
349          */
350         RTE_FLOW_ITEM_TYPE_VXLAN_GPE,
351
352         /**
353          * Matches an ARP header for Ethernet/IPv4.
354          *
355          * See struct rte_flow_item_arp_eth_ipv4.
356          */
357         RTE_FLOW_ITEM_TYPE_ARP_ETH_IPV4,
358
359         /**
360          * Matches the presence of any IPv6 extension header.
361          *
362          * See struct rte_flow_item_ipv6_ext.
363          */
364         RTE_FLOW_ITEM_TYPE_IPV6_EXT,
365
366         /**
367          * Matches any ICMPv6 header.
368          *
369          * See struct rte_flow_item_icmp6.
370          */
371         RTE_FLOW_ITEM_TYPE_ICMP6,
372
373         /**
374          * Matches an ICMPv6 neighbor discovery solicitation.
375          *
376          * See struct rte_flow_item_icmp6_nd_ns.
377          */
378         RTE_FLOW_ITEM_TYPE_ICMP6_ND_NS,
379
380         /**
381          * Matches an ICMPv6 neighbor discovery advertisement.
382          *
383          * See struct rte_flow_item_icmp6_nd_na.
384          */
385         RTE_FLOW_ITEM_TYPE_ICMP6_ND_NA,
386
387         /**
388          * Matches the presence of any ICMPv6 neighbor discovery option.
389          *
390          * See struct rte_flow_item_icmp6_nd_opt.
391          */
392         RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT,
393
394         /**
395          * Matches an ICMPv6 neighbor discovery source Ethernet link-layer
396          * address option.
397          *
398          * See struct rte_flow_item_icmp6_nd_opt_sla_eth.
399          */
400         RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT_SLA_ETH,
401
402         /**
403          * Matches an ICMPv6 neighbor discovery target Ethernet link-layer
404          * address option.
405          *
406          * See struct rte_flow_item_icmp6_nd_opt_tla_eth.
407          */
408         RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT_TLA_ETH,
409
410         /**
411          * Matches specified mark field.
412          *
413          * See struct rte_flow_item_mark.
414          */
415         RTE_FLOW_ITEM_TYPE_MARK,
416
417         /**
418          * [META]
419          *
420          * Matches a metadata value specified in mbuf metadata field.
421          * See struct rte_flow_item_meta.
422          */
423         RTE_FLOW_ITEM_TYPE_META,
424
425         /**
426          * Matches a GRE optional key field.
427          *
428          * The value should a big-endian 32bit integer.
429          *
430          * When this item present the K bit is implicitly matched as "1"
431          * in the default mask.
432          *
433          * @p spec/mask type:
434          * @code rte_be32_t * @endcode
435          */
436         RTE_FLOW_ITEM_TYPE_GRE_KEY,
437
438         /**
439          * Matches a GTP extension header: PDU session container.
440          *
441          * Configure flow for GTP packets with extension header type 0x85.
442          *
443          * See struct rte_flow_item_gtp_psc.
444          */
445         RTE_FLOW_ITEM_TYPE_GTP_PSC,
446
447         /**
448          * Matches a PPPoE header.
449          *
450          * Configure flow for PPPoE session packets.
451          *
452          * See struct rte_flow_item_pppoe.
453          */
454         RTE_FLOW_ITEM_TYPE_PPPOES,
455
456         /**
457          * Matches a PPPoE header.
458          *
459          * Configure flow for PPPoE discovery packets.
460          *
461          * See struct rte_flow_item_pppoe.
462          */
463         RTE_FLOW_ITEM_TYPE_PPPOED,
464
465         /**
466          * Matches a PPPoE optional proto_id field.
467          *
468          * It only applies to PPPoE session packets.
469          *
470          * See struct rte_flow_item_pppoe_proto_id.
471          */
472         RTE_FLOW_ITEM_TYPE_PPPOE_PROTO_ID,
473
474         /**
475          * Matches Network service header (NSH).
476          * See struct rte_flow_item_nsh.
477          *
478          */
479         RTE_FLOW_ITEM_TYPE_NSH,
480
481         /**
482          * Matches Internet Group Management Protocol (IGMP).
483          * See struct rte_flow_item_igmp.
484          *
485          */
486         RTE_FLOW_ITEM_TYPE_IGMP,
487
488         /**
489          * Matches IP Authentication Header (AH).
490          * See struct rte_flow_item_ah.
491          *
492          */
493         RTE_FLOW_ITEM_TYPE_AH,
494 };
495
496 /**
497  * RTE_FLOW_ITEM_TYPE_ANY
498  *
499  * Matches any protocol in place of the current layer, a single ANY may also
500  * stand for several protocol layers.
501  *
502  * This is usually specified as the first pattern item when looking for a
503  * protocol anywhere in a packet.
504  *
505  * A zeroed mask stands for any number of layers.
506  */
507 struct rte_flow_item_any {
508         uint32_t num; /**< Number of layers covered. */
509 };
510
511 /** Default mask for RTE_FLOW_ITEM_TYPE_ANY. */
512 #ifndef __cplusplus
513 static const struct rte_flow_item_any rte_flow_item_any_mask = {
514         .num = 0x00000000,
515 };
516 #endif
517
518 /**
519  * RTE_FLOW_ITEM_TYPE_VF
520  *
521  * Matches traffic originating from (ingress) or going to (egress) a given
522  * virtual function of the current device.
523  *
524  * If supported, should work even if the virtual function is not managed by
525  * the application and thus not associated with a DPDK port ID.
526  *
527  * Note this pattern item does not match VF representors traffic which, as
528  * separate entities, should be addressed through their own DPDK port IDs.
529  *
530  * - Can be specified multiple times to match traffic addressed to several
531  *   VF IDs.
532  * - Can be combined with a PF item to match both PF and VF traffic.
533  *
534  * A zeroed mask can be used to match any VF ID.
535  */
536 struct rte_flow_item_vf {
537         uint32_t id; /**< VF ID. */
538 };
539
540 /** Default mask for RTE_FLOW_ITEM_TYPE_VF. */
541 #ifndef __cplusplus
542 static const struct rte_flow_item_vf rte_flow_item_vf_mask = {
543         .id = 0x00000000,
544 };
545 #endif
546
547 /**
548  * RTE_FLOW_ITEM_TYPE_PHY_PORT
549  *
550  * Matches traffic originating from (ingress) or going to (egress) a
551  * physical port of the underlying device.
552  *
553  * The first PHY_PORT item overrides the physical port normally associated
554  * with the specified DPDK input port (port_id). This item can be provided
555  * several times to match additional physical ports.
556  *
557  * Note that physical ports are not necessarily tied to DPDK input ports
558  * (port_id) when those are not under DPDK control. Possible values are
559  * specific to each device, they are not necessarily indexed from zero and
560  * may not be contiguous.
561  *
562  * As a device property, the list of allowed values as well as the value
563  * associated with a port_id should be retrieved by other means.
564  *
565  * A zeroed mask can be used to match any port index.
566  */
567 struct rte_flow_item_phy_port {
568         uint32_t index; /**< Physical port index. */
569 };
570
571 /** Default mask for RTE_FLOW_ITEM_TYPE_PHY_PORT. */
572 #ifndef __cplusplus
573 static const struct rte_flow_item_phy_port rte_flow_item_phy_port_mask = {
574         .index = 0x00000000,
575 };
576 #endif
577
578 /**
579  * RTE_FLOW_ITEM_TYPE_PORT_ID
580  *
581  * Matches traffic originating from (ingress) or going to (egress) a given
582  * DPDK port ID.
583  *
584  * Normally only supported if the port ID in question is known by the
585  * underlying PMD and related to the device the flow rule is created
586  * against.
587  *
588  * This must not be confused with @p PHY_PORT which refers to the physical
589  * port of a device, whereas @p PORT_ID refers to a struct rte_eth_dev
590  * object on the application side (also known as "port representor"
591  * depending on the kind of underlying device).
592  */
593 struct rte_flow_item_port_id {
594         uint32_t id; /**< DPDK port ID. */
595 };
596
597 /** Default mask for RTE_FLOW_ITEM_TYPE_PORT_ID. */
598 #ifndef __cplusplus
599 static const struct rte_flow_item_port_id rte_flow_item_port_id_mask = {
600         .id = 0xffffffff,
601 };
602 #endif
603
604 /**
605  * RTE_FLOW_ITEM_TYPE_RAW
606  *
607  * Matches a byte string of a given length at a given offset.
608  *
609  * Offset is either absolute (using the start of the packet) or relative to
610  * the end of the previous matched item in the stack, in which case negative
611  * values are allowed.
612  *
613  * If search is enabled, offset is used as the starting point. The search
614  * area can be delimited by setting limit to a nonzero value, which is the
615  * maximum number of bytes after offset where the pattern may start.
616  *
617  * Matching a zero-length pattern is allowed, doing so resets the relative
618  * offset for subsequent items.
619  *
620  * This type does not support ranges (struct rte_flow_item.last).
621  */
622 struct rte_flow_item_raw {
623         uint32_t relative:1; /**< Look for pattern after the previous item. */
624         uint32_t search:1; /**< Search pattern from offset (see also limit). */
625         uint32_t reserved:30; /**< Reserved, must be set to zero. */
626         int32_t offset; /**< Absolute or relative offset for pattern. */
627         uint16_t limit; /**< Search area limit for start of pattern. */
628         uint16_t length; /**< Pattern length. */
629         const uint8_t *pattern; /**< Byte string to look for. */
630 };
631
632 /** Default mask for RTE_FLOW_ITEM_TYPE_RAW. */
633 #ifndef __cplusplus
634 static const struct rte_flow_item_raw rte_flow_item_raw_mask = {
635         .relative = 1,
636         .search = 1,
637         .reserved = 0x3fffffff,
638         .offset = 0xffffffff,
639         .limit = 0xffff,
640         .length = 0xffff,
641         .pattern = NULL,
642 };
643 #endif
644
645 /**
646  * RTE_FLOW_ITEM_TYPE_ETH
647  *
648  * Matches an Ethernet header.
649  *
650  * The @p type field either stands for "EtherType" or "TPID" when followed
651  * by so-called layer 2.5 pattern items such as RTE_FLOW_ITEM_TYPE_VLAN. In
652  * the latter case, @p type refers to that of the outer header, with the
653  * inner EtherType/TPID provided by the subsequent pattern item. This is the
654  * same order as on the wire.
655  */
656 struct rte_flow_item_eth {
657         struct rte_ether_addr dst; /**< Destination MAC. */
658         struct rte_ether_addr src; /**< Source MAC. */
659         rte_be16_t type; /**< EtherType or TPID. */
660 };
661
662 /** Default mask for RTE_FLOW_ITEM_TYPE_ETH. */
663 #ifndef __cplusplus
664 static const struct rte_flow_item_eth rte_flow_item_eth_mask = {
665         .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
666         .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
667         .type = RTE_BE16(0x0000),
668 };
669 #endif
670
671 /**
672  * RTE_FLOW_ITEM_TYPE_VLAN
673  *
674  * Matches an 802.1Q/ad VLAN tag.
675  *
676  * The corresponding standard outer EtherType (TPID) values are
677  * RTE_ETHER_TYPE_VLAN or RTE_ETHER_TYPE_QINQ. It can be overridden by
678  * the preceding pattern item.
679  */
680 struct rte_flow_item_vlan {
681         rte_be16_t tci; /**< Tag control information. */
682         rte_be16_t inner_type; /**< Inner EtherType or TPID. */
683 };
684
685 /** Default mask for RTE_FLOW_ITEM_TYPE_VLAN. */
686 #ifndef __cplusplus
687 static const struct rte_flow_item_vlan rte_flow_item_vlan_mask = {
688         .tci = RTE_BE16(0x0fff),
689         .inner_type = RTE_BE16(0x0000),
690 };
691 #endif
692
693 /**
694  * RTE_FLOW_ITEM_TYPE_IPV4
695  *
696  * Matches an IPv4 header.
697  *
698  * Note: IPv4 options are handled by dedicated pattern items.
699  */
700 struct rte_flow_item_ipv4 {
701         struct rte_ipv4_hdr hdr; /**< IPv4 header definition. */
702 };
703
704 /** Default mask for RTE_FLOW_ITEM_TYPE_IPV4. */
705 #ifndef __cplusplus
706 static const struct rte_flow_item_ipv4 rte_flow_item_ipv4_mask = {
707         .hdr = {
708                 .src_addr = RTE_BE32(0xffffffff),
709                 .dst_addr = RTE_BE32(0xffffffff),
710         },
711 };
712 #endif
713
714 /**
715  * RTE_FLOW_ITEM_TYPE_IPV6.
716  *
717  * Matches an IPv6 header.
718  *
719  * Note: IPv6 options are handled by dedicated pattern items, see
720  * RTE_FLOW_ITEM_TYPE_IPV6_EXT.
721  */
722 struct rte_flow_item_ipv6 {
723         struct rte_ipv6_hdr hdr; /**< IPv6 header definition. */
724 };
725
726 /** Default mask for RTE_FLOW_ITEM_TYPE_IPV6. */
727 #ifndef __cplusplus
728 static const struct rte_flow_item_ipv6 rte_flow_item_ipv6_mask = {
729         .hdr = {
730                 .src_addr =
731                         "\xff\xff\xff\xff\xff\xff\xff\xff"
732                         "\xff\xff\xff\xff\xff\xff\xff\xff",
733                 .dst_addr =
734                         "\xff\xff\xff\xff\xff\xff\xff\xff"
735                         "\xff\xff\xff\xff\xff\xff\xff\xff",
736         },
737 };
738 #endif
739
740 /**
741  * RTE_FLOW_ITEM_TYPE_ICMP.
742  *
743  * Matches an ICMP header.
744  */
745 struct rte_flow_item_icmp {
746         struct rte_icmp_hdr hdr; /**< ICMP header definition. */
747 };
748
749 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP. */
750 #ifndef __cplusplus
751 static const struct rte_flow_item_icmp rte_flow_item_icmp_mask = {
752         .hdr = {
753                 .icmp_type = 0xff,
754                 .icmp_code = 0xff,
755         },
756 };
757 #endif
758
759 /**
760  * RTE_FLOW_ITEM_TYPE_UDP.
761  *
762  * Matches a UDP header.
763  */
764 struct rte_flow_item_udp {
765         struct rte_udp_hdr hdr; /**< UDP header definition. */
766 };
767
768 /** Default mask for RTE_FLOW_ITEM_TYPE_UDP. */
769 #ifndef __cplusplus
770 static const struct rte_flow_item_udp rte_flow_item_udp_mask = {
771         .hdr = {
772                 .src_port = RTE_BE16(0xffff),
773                 .dst_port = RTE_BE16(0xffff),
774         },
775 };
776 #endif
777
778 /**
779  * RTE_FLOW_ITEM_TYPE_TCP.
780  *
781  * Matches a TCP header.
782  */
783 struct rte_flow_item_tcp {
784         struct rte_tcp_hdr hdr; /**< TCP header definition. */
785 };
786
787 /** Default mask for RTE_FLOW_ITEM_TYPE_TCP. */
788 #ifndef __cplusplus
789 static const struct rte_flow_item_tcp rte_flow_item_tcp_mask = {
790         .hdr = {
791                 .src_port = RTE_BE16(0xffff),
792                 .dst_port = RTE_BE16(0xffff),
793         },
794 };
795 #endif
796
797 /**
798  * RTE_FLOW_ITEM_TYPE_SCTP.
799  *
800  * Matches a SCTP header.
801  */
802 struct rte_flow_item_sctp {
803         struct rte_sctp_hdr hdr; /**< SCTP header definition. */
804 };
805
806 /** Default mask for RTE_FLOW_ITEM_TYPE_SCTP. */
807 #ifndef __cplusplus
808 static const struct rte_flow_item_sctp rte_flow_item_sctp_mask = {
809         .hdr = {
810                 .src_port = RTE_BE16(0xffff),
811                 .dst_port = RTE_BE16(0xffff),
812         },
813 };
814 #endif
815
816 /**
817  * RTE_FLOW_ITEM_TYPE_VXLAN.
818  *
819  * Matches a VXLAN header (RFC 7348).
820  */
821 struct rte_flow_item_vxlan {
822         uint8_t flags; /**< Normally 0x08 (I flag). */
823         uint8_t rsvd0[3]; /**< Reserved, normally 0x000000. */
824         uint8_t vni[3]; /**< VXLAN identifier. */
825         uint8_t rsvd1; /**< Reserved, normally 0x00. */
826 };
827
828 /** Default mask for RTE_FLOW_ITEM_TYPE_VXLAN. */
829 #ifndef __cplusplus
830 static const struct rte_flow_item_vxlan rte_flow_item_vxlan_mask = {
831         .vni = "\xff\xff\xff",
832 };
833 #endif
834
835 /**
836  * RTE_FLOW_ITEM_TYPE_E_TAG.
837  *
838  * Matches a E-tag header.
839  *
840  * The corresponding standard outer EtherType (TPID) value is
841  * RTE_ETHER_TYPE_ETAG. It can be overridden by the preceding pattern item.
842  */
843 struct rte_flow_item_e_tag {
844         /**
845          * E-Tag control information (E-TCI).
846          * E-PCP (3b), E-DEI (1b), ingress E-CID base (12b).
847          */
848         rte_be16_t epcp_edei_in_ecid_b;
849         /** Reserved (2b), GRP (2b), E-CID base (12b). */
850         rte_be16_t rsvd_grp_ecid_b;
851         uint8_t in_ecid_e; /**< Ingress E-CID ext. */
852         uint8_t ecid_e; /**< E-CID ext. */
853         rte_be16_t inner_type; /**< Inner EtherType or TPID. */
854 };
855
856 /** Default mask for RTE_FLOW_ITEM_TYPE_E_TAG. */
857 #ifndef __cplusplus
858 static const struct rte_flow_item_e_tag rte_flow_item_e_tag_mask = {
859         .rsvd_grp_ecid_b = RTE_BE16(0x3fff),
860 };
861 #endif
862
863 /**
864  * RTE_FLOW_ITEM_TYPE_NVGRE.
865  *
866  * Matches a NVGRE header.
867  */
868 struct rte_flow_item_nvgre {
869         /**
870          * Checksum (1b), undefined (1b), key bit (1b), sequence number (1b),
871          * reserved 0 (9b), version (3b).
872          *
873          * c_k_s_rsvd0_ver must have value 0x2000 according to RFC 7637.
874          */
875         rte_be16_t c_k_s_rsvd0_ver;
876         rte_be16_t protocol; /**< Protocol type (0x6558). */
877         uint8_t tni[3]; /**< Virtual subnet ID. */
878         uint8_t flow_id; /**< Flow ID. */
879 };
880
881 /** Default mask for RTE_FLOW_ITEM_TYPE_NVGRE. */
882 #ifndef __cplusplus
883 static const struct rte_flow_item_nvgre rte_flow_item_nvgre_mask = {
884         .tni = "\xff\xff\xff",
885 };
886 #endif
887
888 /**
889  * RTE_FLOW_ITEM_TYPE_MPLS.
890  *
891  * Matches a MPLS header.
892  */
893 struct rte_flow_item_mpls {
894         /**
895          * Label (20b), TC (3b), Bottom of Stack (1b).
896          */
897         uint8_t label_tc_s[3];
898         uint8_t ttl; /** Time-to-Live. */
899 };
900
901 /** Default mask for RTE_FLOW_ITEM_TYPE_MPLS. */
902 #ifndef __cplusplus
903 static const struct rte_flow_item_mpls rte_flow_item_mpls_mask = {
904         .label_tc_s = "\xff\xff\xf0",
905 };
906 #endif
907
908 /**
909  * RTE_FLOW_ITEM_TYPE_GRE.
910  *
911  * Matches a GRE header.
912  */
913 struct rte_flow_item_gre {
914         /**
915          * Checksum (1b), reserved 0 (12b), version (3b).
916          * Refer to RFC 2784.
917          */
918         rte_be16_t c_rsvd0_ver;
919         rte_be16_t protocol; /**< Protocol type. */
920 };
921
922 /** Default mask for RTE_FLOW_ITEM_TYPE_GRE. */
923 #ifndef __cplusplus
924 static const struct rte_flow_item_gre rte_flow_item_gre_mask = {
925         .protocol = RTE_BE16(0xffff),
926 };
927 #endif
928
929 /**
930  * RTE_FLOW_ITEM_TYPE_FUZZY
931  *
932  * Fuzzy pattern match, expect faster than default.
933  *
934  * This is for device that support fuzzy match option.
935  * Usually a fuzzy match is fast but the cost is accuracy.
936  * i.e. Signature Match only match pattern's hash value, but it is
937  * possible two different patterns have the same hash value.
938  *
939  * Matching accuracy level can be configure by threshold.
940  * Driver can divide the range of threshold and map to different
941  * accuracy levels that device support.
942  *
943  * Threshold 0 means perfect match (no fuzziness), while threshold
944  * 0xffffffff means fuzziest match.
945  */
946 struct rte_flow_item_fuzzy {
947         uint32_t thresh; /**< Accuracy threshold. */
948 };
949
950 /** Default mask for RTE_FLOW_ITEM_TYPE_FUZZY. */
951 #ifndef __cplusplus
952 static const struct rte_flow_item_fuzzy rte_flow_item_fuzzy_mask = {
953         .thresh = 0xffffffff,
954 };
955 #endif
956
957 /**
958  * RTE_FLOW_ITEM_TYPE_GTP.
959  *
960  * Matches a GTPv1 header.
961  */
962 struct rte_flow_item_gtp {
963         /**
964          * Version (3b), protocol type (1b), reserved (1b),
965          * Extension header flag (1b),
966          * Sequence number flag (1b),
967          * N-PDU number flag (1b).
968          */
969         uint8_t v_pt_rsv_flags;
970         uint8_t msg_type; /**< Message type. */
971         rte_be16_t msg_len; /**< Message length. */
972         rte_be32_t teid; /**< Tunnel endpoint identifier. */
973 };
974
975 /** Default mask for RTE_FLOW_ITEM_TYPE_GTP. */
976 #ifndef __cplusplus
977 static const struct rte_flow_item_gtp rte_flow_item_gtp_mask = {
978         .teid = RTE_BE32(0xffffffff),
979 };
980 #endif
981
982 /**
983  * RTE_FLOW_ITEM_TYPE_ESP
984  *
985  * Matches an ESP header.
986  */
987 struct rte_flow_item_esp {
988         struct rte_esp_hdr hdr; /**< ESP header definition. */
989 };
990
991 /** Default mask for RTE_FLOW_ITEM_TYPE_ESP. */
992 #ifndef __cplusplus
993 static const struct rte_flow_item_esp rte_flow_item_esp_mask = {
994         .hdr = {
995                 .spi = RTE_BE32(0xffffffff),
996         },
997 };
998 #endif
999
1000 /**
1001  * RTE_FLOW_ITEM_TYPE_GENEVE.
1002  *
1003  * Matches a GENEVE header.
1004  */
1005 struct rte_flow_item_geneve {
1006         /**
1007          * Version (2b), length of the options fields (6b), OAM packet (1b),
1008          * critical options present (1b), reserved 0 (6b).
1009          */
1010         rte_be16_t ver_opt_len_o_c_rsvd0;
1011         rte_be16_t protocol; /**< Protocol type. */
1012         uint8_t vni[3]; /**< Virtual Network Identifier. */
1013         uint8_t rsvd1; /**< Reserved, normally 0x00. */
1014 };
1015
1016 /** Default mask for RTE_FLOW_ITEM_TYPE_GENEVE. */
1017 #ifndef __cplusplus
1018 static const struct rte_flow_item_geneve rte_flow_item_geneve_mask = {
1019         .vni = "\xff\xff\xff",
1020 };
1021 #endif
1022
1023 /**
1024  * RTE_FLOW_ITEM_TYPE_VXLAN_GPE (draft-ietf-nvo3-vxlan-gpe-05).
1025  *
1026  * Matches a VXLAN-GPE header.
1027  */
1028 struct rte_flow_item_vxlan_gpe {
1029         uint8_t flags; /**< Normally 0x0c (I and P flags). */
1030         uint8_t rsvd0[2]; /**< Reserved, normally 0x0000. */
1031         uint8_t protocol; /**< Protocol type. */
1032         uint8_t vni[3]; /**< VXLAN identifier. */
1033         uint8_t rsvd1; /**< Reserved, normally 0x00. */
1034 };
1035
1036 /** Default mask for RTE_FLOW_ITEM_TYPE_VXLAN_GPE. */
1037 #ifndef __cplusplus
1038 static const struct rte_flow_item_vxlan_gpe rte_flow_item_vxlan_gpe_mask = {
1039         .vni = "\xff\xff\xff",
1040 };
1041 #endif
1042
1043 /**
1044  * RTE_FLOW_ITEM_TYPE_ARP_ETH_IPV4
1045  *
1046  * Matches an ARP header for Ethernet/IPv4.
1047  */
1048 struct rte_flow_item_arp_eth_ipv4 {
1049         rte_be16_t hrd; /**< Hardware type, normally 1. */
1050         rte_be16_t pro; /**< Protocol type, normally 0x0800. */
1051         uint8_t hln; /**< Hardware address length, normally 6. */
1052         uint8_t pln; /**< Protocol address length, normally 4. */
1053         rte_be16_t op; /**< Opcode (1 for request, 2 for reply). */
1054         struct rte_ether_addr sha; /**< Sender hardware address. */
1055         rte_be32_t spa; /**< Sender IPv4 address. */
1056         struct rte_ether_addr tha; /**< Target hardware address. */
1057         rte_be32_t tpa; /**< Target IPv4 address. */
1058 };
1059
1060 /** Default mask for RTE_FLOW_ITEM_TYPE_ARP_ETH_IPV4. */
1061 #ifndef __cplusplus
1062 static const struct rte_flow_item_arp_eth_ipv4
1063 rte_flow_item_arp_eth_ipv4_mask = {
1064         .sha.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1065         .spa = RTE_BE32(0xffffffff),
1066         .tha.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1067         .tpa = RTE_BE32(0xffffffff),
1068 };
1069 #endif
1070
1071 /**
1072  * RTE_FLOW_ITEM_TYPE_IPV6_EXT
1073  *
1074  * Matches the presence of any IPv6 extension header.
1075  *
1076  * Normally preceded by any of:
1077  *
1078  * - RTE_FLOW_ITEM_TYPE_IPV6
1079  * - RTE_FLOW_ITEM_TYPE_IPV6_EXT
1080  */
1081 struct rte_flow_item_ipv6_ext {
1082         uint8_t next_hdr; /**< Next header. */
1083 };
1084
1085 /** Default mask for RTE_FLOW_ITEM_TYPE_IPV6_EXT. */
1086 #ifndef __cplusplus
1087 static const
1088 struct rte_flow_item_ipv6_ext rte_flow_item_ipv6_ext_mask = {
1089         .next_hdr = 0xff,
1090 };
1091 #endif
1092
1093 /**
1094  * RTE_FLOW_ITEM_TYPE_ICMP6
1095  *
1096  * Matches any ICMPv6 header.
1097  */
1098 struct rte_flow_item_icmp6 {
1099         uint8_t type; /**< ICMPv6 type. */
1100         uint8_t code; /**< ICMPv6 code. */
1101         uint16_t checksum; /**< ICMPv6 checksum. */
1102 };
1103
1104 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP6. */
1105 #ifndef __cplusplus
1106 static const struct rte_flow_item_icmp6 rte_flow_item_icmp6_mask = {
1107         .type = 0xff,
1108         .code = 0xff,
1109 };
1110 #endif
1111
1112 /**
1113  * RTE_FLOW_ITEM_TYPE_ICMP6_ND_NS
1114  *
1115  * Matches an ICMPv6 neighbor discovery solicitation.
1116  */
1117 struct rte_flow_item_icmp6_nd_ns {
1118         uint8_t type; /**< ICMPv6 type, normally 135. */
1119         uint8_t code; /**< ICMPv6 code, normally 0. */
1120         rte_be16_t checksum; /**< ICMPv6 checksum. */
1121         rte_be32_t reserved; /**< Reserved, normally 0. */
1122         uint8_t target_addr[16]; /**< Target address. */
1123 };
1124
1125 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP6_ND_NS. */
1126 #ifndef __cplusplus
1127 static const
1128 struct rte_flow_item_icmp6_nd_ns rte_flow_item_icmp6_nd_ns_mask = {
1129         .target_addr =
1130                 "\xff\xff\xff\xff\xff\xff\xff\xff"
1131                 "\xff\xff\xff\xff\xff\xff\xff\xff",
1132 };
1133 #endif
1134
1135 /**
1136  * RTE_FLOW_ITEM_TYPE_ICMP6_ND_NA
1137  *
1138  * Matches an ICMPv6 neighbor discovery advertisement.
1139  */
1140 struct rte_flow_item_icmp6_nd_na {
1141         uint8_t type; /**< ICMPv6 type, normally 136. */
1142         uint8_t code; /**< ICMPv6 code, normally 0. */
1143         rte_be16_t checksum; /**< ICMPv6 checksum. */
1144         /**
1145          * Route flag (1b), solicited flag (1b), override flag (1b),
1146          * reserved (29b).
1147          */
1148         rte_be32_t rso_reserved;
1149         uint8_t target_addr[16]; /**< Target address. */
1150 };
1151
1152 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP6_ND_NA. */
1153 #ifndef __cplusplus
1154 static const
1155 struct rte_flow_item_icmp6_nd_na rte_flow_item_icmp6_nd_na_mask = {
1156         .target_addr =
1157                 "\xff\xff\xff\xff\xff\xff\xff\xff"
1158                 "\xff\xff\xff\xff\xff\xff\xff\xff",
1159 };
1160 #endif
1161
1162 /**
1163  * RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT
1164  *
1165  * Matches the presence of any ICMPv6 neighbor discovery option.
1166  *
1167  * Normally preceded by any of:
1168  *
1169  * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_NA
1170  * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_NS
1171  * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT
1172  */
1173 struct rte_flow_item_icmp6_nd_opt {
1174         uint8_t type; /**< ND option type. */
1175         uint8_t length; /**< ND option length. */
1176 };
1177
1178 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT. */
1179 #ifndef __cplusplus
1180 static const struct rte_flow_item_icmp6_nd_opt
1181 rte_flow_item_icmp6_nd_opt_mask = {
1182         .type = 0xff,
1183 };
1184 #endif
1185
1186 /**
1187  * RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT_SLA_ETH
1188  *
1189  * Matches an ICMPv6 neighbor discovery source Ethernet link-layer address
1190  * option.
1191  *
1192  * Normally preceded by any of:
1193  *
1194  * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_NA
1195  * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT
1196  */
1197 struct rte_flow_item_icmp6_nd_opt_sla_eth {
1198         uint8_t type; /**< ND option type, normally 1. */
1199         uint8_t length; /**< ND option length, normally 1. */
1200         struct rte_ether_addr sla; /**< Source Ethernet LLA. */
1201 };
1202
1203 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT_SLA_ETH. */
1204 #ifndef __cplusplus
1205 static const struct rte_flow_item_icmp6_nd_opt_sla_eth
1206 rte_flow_item_icmp6_nd_opt_sla_eth_mask = {
1207         .sla.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1208 };
1209 #endif
1210
1211 /**
1212  * RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT_TLA_ETH
1213  *
1214  * Matches an ICMPv6 neighbor discovery target Ethernet link-layer address
1215  * option.
1216  *
1217  * Normally preceded by any of:
1218  *
1219  * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_NS
1220  * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT
1221  */
1222 struct rte_flow_item_icmp6_nd_opt_tla_eth {
1223         uint8_t type; /**< ND option type, normally 2. */
1224         uint8_t length; /**< ND option length, normally 1. */
1225         struct rte_ether_addr tla; /**< Target Ethernet LLA. */
1226 };
1227
1228 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT_TLA_ETH. */
1229 #ifndef __cplusplus
1230 static const struct rte_flow_item_icmp6_nd_opt_tla_eth
1231 rte_flow_item_icmp6_nd_opt_tla_eth_mask = {
1232         .tla.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1233 };
1234 #endif
1235
1236 /**
1237  * RTE_FLOW_ITEM_TYPE_META.
1238  *
1239  * Matches a specified metadata value.
1240  */
1241 struct rte_flow_item_meta {
1242         rte_be32_t data;
1243 };
1244
1245 /** Default mask for RTE_FLOW_ITEM_TYPE_META. */
1246 #ifndef __cplusplus
1247 static const struct rte_flow_item_meta rte_flow_item_meta_mask = {
1248         .data = RTE_BE32(UINT32_MAX),
1249 };
1250 #endif
1251
1252 /**
1253  * RTE_FLOW_ITEM_TYPE_GTP_PSC.
1254  *
1255  * Matches a GTP PDU extension header with type 0x85.
1256  */
1257 struct rte_flow_item_gtp_psc {
1258         uint8_t pdu_type; /**< PDU type. */
1259         uint8_t qfi; /**< QoS flow identifier. */
1260 };
1261
1262 /** Default mask for RTE_FLOW_ITEM_TYPE_GTP_PSC. */
1263 #ifndef __cplusplus
1264 static const struct rte_flow_item_gtp_psc
1265 rte_flow_item_gtp_psc_mask = {
1266         .qfi = 0x3f,
1267 };
1268 #endif
1269
1270 /**
1271  * RTE_FLOW_ITEM_TYPE_PPPOE.
1272  *
1273  * Matches a PPPoE header.
1274  */
1275 struct rte_flow_item_pppoe {
1276         /**
1277          * Version (4b), type (4b).
1278          */
1279         uint8_t version_type;
1280         uint8_t code; /**< Message type. */
1281         rte_be16_t session_id; /**< Session identifier. */
1282         rte_be16_t length; /**< Payload length. */
1283 };
1284
1285 /**
1286  * RTE_FLOW_ITEM_TYPE_PPPOE_PROTO_ID.
1287  *
1288  * Matches a PPPoE optional proto_id field.
1289  *
1290  * It only applies to PPPoE session packets.
1291  *
1292  * Normally preceded by any of:
1293  *
1294  * - RTE_FLOW_ITEM_TYPE_PPPOE
1295  * - RTE_FLOW_ITEM_TYPE_PPPOE_PROTO_ID
1296  */
1297 struct rte_flow_item_pppoe_proto_id {
1298         rte_be16_t proto_id; /**< PPP protocol identifier. */
1299 };
1300
1301 /** Default mask for RTE_FLOW_ITEM_TYPE_PPPOE_PROTO_ID. */
1302 #ifndef __cplusplus
1303 static const struct rte_flow_item_pppoe_proto_id
1304 rte_flow_item_pppoe_proto_id_mask = {
1305         .proto_id = RTE_BE16(0xffff),
1306 };
1307 #endif
1308
1309 /**
1310  * @warning
1311  * @b EXPERIMENTAL: this structure may change without prior notice
1312  *
1313  * RTE_FLOW_ITEM_TYPE_MARK
1314  *
1315  * Matches an arbitrary integer value which was set using the ``MARK`` action
1316  * in a previously matched rule.
1317  *
1318  * This item can only be specified once as a match criteria as the ``MARK``
1319  * action can only be specified once in a flow action.
1320  *
1321  * This value is arbitrary and application-defined. Maximum allowed value
1322  * depends on the underlying implementation.
1323  *
1324  * Depending on the underlying implementation the MARK item may be supported on
1325  * the physical device, with virtual groups in the PMD or not at all.
1326  */
1327 struct rte_flow_item_mark {
1328         uint32_t id; /**< Integer value to match against. */
1329 };
1330
1331 /**
1332  * @warning
1333  * @b EXPERIMENTAL: this structure may change without prior notice
1334  *
1335  * RTE_FLOW_ITEM_TYPE_NSH
1336  *
1337  * Match network service header (NSH), RFC 8300
1338  *
1339  */
1340 struct rte_flow_item_nsh {
1341         uint32_t version:2;
1342         uint32_t oam_pkt:1;
1343         uint32_t reserved:1;
1344         uint32_t ttl:6;
1345         uint32_t length:6;
1346         uint32_t reserved1:4;
1347         uint32_t mdtype:4;
1348         uint32_t next_proto:8;
1349         uint32_t spi:24;
1350         uint32_t sindex:8;
1351 };
1352
1353 /** Default mask for RTE_FLOW_ITEM_TYPE_NSH. */
1354 #ifndef __cplusplus
1355 static const struct rte_flow_item_nsh rte_flow_item_nsh_mask = {
1356         .mdtype = 0xf,
1357         .next_proto = 0xff,
1358         .spi = 0xffffff,
1359         .sindex = 0xff,
1360 };
1361 #endif
1362
1363 /**
1364  * @warning
1365  * @b EXPERIMENTAL: this structure may change without prior notice
1366  *
1367  * RTE_FLOW_ITEM_TYPE_IGMP
1368  *
1369  * Match Internet Group Management Protocol (IGMP), RFC 2236
1370  *
1371  */
1372 struct rte_flow_item_igmp {
1373         uint32_t type:8;
1374         uint32_t max_resp_time:8;
1375         uint32_t checksum:16;
1376         uint32_t group_addr;
1377 };
1378
1379 /** Default mask for RTE_FLOW_ITEM_TYPE_IGMP. */
1380 #ifndef __cplusplus
1381 static const struct rte_flow_item_igmp rte_flow_item_igmp_mask = {
1382         .group_addr = 0xffffffff,
1383 };
1384 #endif
1385
1386 /**
1387  * @warning
1388  * @b EXPERIMENTAL: this structure may change without prior notice
1389  *
1390  * RTE_FLOW_ITEM_TYPE_AH
1391  *
1392  * Match IP Authentication Header (AH), RFC 4302
1393  *
1394  */
1395 struct rte_flow_item_ah {
1396         uint32_t next_hdr:8;
1397         uint32_t payload_len:8;
1398         uint32_t reserved:16;
1399         uint32_t spi;
1400         uint32_t seq_num;
1401 };
1402
1403 /** Default mask for RTE_FLOW_ITEM_TYPE_AH. */
1404 #ifndef __cplusplus
1405 static const struct rte_flow_item_ah rte_flow_item_ah_mask = {
1406         .spi = 0xffffffff,
1407 };
1408 #endif
1409
1410 /**
1411  * Matching pattern item definition.
1412  *
1413  * A pattern is formed by stacking items starting from the lowest protocol
1414  * layer to match. This stacking restriction does not apply to meta items
1415  * which can be placed anywhere in the stack without affecting the meaning
1416  * of the resulting pattern.
1417  *
1418  * Patterns are terminated by END items.
1419  *
1420  * The spec field should be a valid pointer to a structure of the related
1421  * item type. It may remain unspecified (NULL) in many cases to request
1422  * broad (nonspecific) matching. In such cases, last and mask must also be
1423  * set to NULL.
1424  *
1425  * Optionally, last can point to a structure of the same type to define an
1426  * inclusive range. This is mostly supported by integer and address fields,
1427  * may cause errors otherwise. Fields that do not support ranges must be set
1428  * to 0 or to the same value as the corresponding fields in spec.
1429  *
1430  * Only the fields defined to nonzero values in the default masks (see
1431  * rte_flow_item_{name}_mask constants) are considered relevant by
1432  * default. This can be overridden by providing a mask structure of the
1433  * same type with applicable bits set to one. It can also be used to
1434  * partially filter out specific fields (e.g. as an alternate mean to match
1435  * ranges of IP addresses).
1436  *
1437  * Mask is a simple bit-mask applied before interpreting the contents of
1438  * spec and last, which may yield unexpected results if not used
1439  * carefully. For example, if for an IPv4 address field, spec provides
1440  * 10.1.2.3, last provides 10.3.4.5 and mask provides 255.255.0.0, the
1441  * effective range becomes 10.1.0.0 to 10.3.255.255.
1442  */
1443 struct rte_flow_item {
1444         enum rte_flow_item_type type; /**< Item type. */
1445         const void *spec; /**< Pointer to item specification structure. */
1446         const void *last; /**< Defines an inclusive range (spec to last). */
1447         const void *mask; /**< Bit-mask applied to spec and last. */
1448 };
1449
1450 /**
1451  * Action types.
1452  *
1453  * Each possible action is represented by a type.
1454  * An action can have an associated configuration object.
1455  * Several actions combined in a list can be assigned
1456  * to a flow rule and are performed in order.
1457  *
1458  * They fall in three categories:
1459  *
1460  * - Actions that modify the fate of matching traffic, for instance by
1461  *   dropping or assigning it a specific destination.
1462  *
1463  * - Actions that modify matching traffic contents or its properties. This
1464  *   includes adding/removing encapsulation, encryption, compression and
1465  *   marks.
1466  *
1467  * - Actions related to the flow rule itself, such as updating counters or
1468  *   making it non-terminating.
1469  *
1470  * Flow rules being terminating by default, not specifying any action of the
1471  * fate kind results in undefined behavior. This applies to both ingress and
1472  * egress.
1473  *
1474  * PASSTHRU, when supported, makes a flow rule non-terminating.
1475  */
1476 enum rte_flow_action_type {
1477         /**
1478          * End marker for action lists. Prevents further processing of
1479          * actions, thereby ending the list.
1480          *
1481          * No associated configuration structure.
1482          */
1483         RTE_FLOW_ACTION_TYPE_END,
1484
1485         /**
1486          * Used as a placeholder for convenience. It is ignored and simply
1487          * discarded by PMDs.
1488          *
1489          * No associated configuration structure.
1490          */
1491         RTE_FLOW_ACTION_TYPE_VOID,
1492
1493         /**
1494          * Leaves traffic up for additional processing by subsequent flow
1495          * rules; makes a flow rule non-terminating.
1496          *
1497          * No associated configuration structure.
1498          */
1499         RTE_FLOW_ACTION_TYPE_PASSTHRU,
1500
1501         /**
1502          * RTE_FLOW_ACTION_TYPE_JUMP
1503          *
1504          * Redirects packets to a group on the current device.
1505          *
1506          * See struct rte_flow_action_jump.
1507          */
1508         RTE_FLOW_ACTION_TYPE_JUMP,
1509
1510         /**
1511          * Attaches an integer value to packets and sets PKT_RX_FDIR and
1512          * PKT_RX_FDIR_ID mbuf flags.
1513          *
1514          * See struct rte_flow_action_mark.
1515          */
1516         RTE_FLOW_ACTION_TYPE_MARK,
1517
1518         /**
1519          * Flags packets. Similar to MARK without a specific value; only
1520          * sets the PKT_RX_FDIR mbuf flag.
1521          *
1522          * No associated configuration structure.
1523          */
1524         RTE_FLOW_ACTION_TYPE_FLAG,
1525
1526         /**
1527          * Assigns packets to a given queue index.
1528          *
1529          * See struct rte_flow_action_queue.
1530          */
1531         RTE_FLOW_ACTION_TYPE_QUEUE,
1532
1533         /**
1534          * Drops packets.
1535          *
1536          * PASSTHRU overrides this action if both are specified.
1537          *
1538          * No associated configuration structure.
1539          */
1540         RTE_FLOW_ACTION_TYPE_DROP,
1541
1542         /**
1543          * Enables counters for this flow rule.
1544          *
1545          * These counters can be retrieved and reset through rte_flow_query(),
1546          * see struct rte_flow_query_count.
1547          *
1548          * See struct rte_flow_action_count.
1549          */
1550         RTE_FLOW_ACTION_TYPE_COUNT,
1551
1552         /**
1553          * Similar to QUEUE, except RSS is additionally performed on packets
1554          * to spread them among several queues according to the provided
1555          * parameters.
1556          *
1557          * See struct rte_flow_action_rss.
1558          */
1559         RTE_FLOW_ACTION_TYPE_RSS,
1560
1561         /**
1562          * Directs matching traffic to the physical function (PF) of the
1563          * current device.
1564          *
1565          * No associated configuration structure.
1566          */
1567         RTE_FLOW_ACTION_TYPE_PF,
1568
1569         /**
1570          * Directs matching traffic to a given virtual function of the
1571          * current device.
1572          *
1573          * See struct rte_flow_action_vf.
1574          */
1575         RTE_FLOW_ACTION_TYPE_VF,
1576
1577         /**
1578          * Directs packets to a given physical port index of the underlying
1579          * device.
1580          *
1581          * See struct rte_flow_action_phy_port.
1582          */
1583         RTE_FLOW_ACTION_TYPE_PHY_PORT,
1584
1585         /**
1586          * Directs matching traffic to a given DPDK port ID.
1587          *
1588          * See struct rte_flow_action_port_id.
1589          */
1590         RTE_FLOW_ACTION_TYPE_PORT_ID,
1591
1592         /**
1593          * Traffic metering and policing (MTR).
1594          *
1595          * See struct rte_flow_action_meter.
1596          * See file rte_mtr.h for MTR object configuration.
1597          */
1598         RTE_FLOW_ACTION_TYPE_METER,
1599
1600         /**
1601          * Redirects packets to security engine of current device for security
1602          * processing as specified by security session.
1603          *
1604          * See struct rte_flow_action_security.
1605          */
1606         RTE_FLOW_ACTION_TYPE_SECURITY,
1607
1608         /**
1609          * Implements OFPAT_SET_MPLS_TTL ("MPLS TTL") as defined by the
1610          * OpenFlow Switch Specification.
1611          *
1612          * See struct rte_flow_action_of_set_mpls_ttl.
1613          */
1614         RTE_FLOW_ACTION_TYPE_OF_SET_MPLS_TTL,
1615
1616         /**
1617          * Implements OFPAT_DEC_MPLS_TTL ("decrement MPLS TTL") as defined
1618          * by the OpenFlow Switch Specification.
1619          *
1620          * No associated configuration structure.
1621          */
1622         RTE_FLOW_ACTION_TYPE_OF_DEC_MPLS_TTL,
1623
1624         /**
1625          * Implements OFPAT_SET_NW_TTL ("IP TTL") as defined by the OpenFlow
1626          * Switch Specification.
1627          *
1628          * See struct rte_flow_action_of_set_nw_ttl.
1629          */
1630         RTE_FLOW_ACTION_TYPE_OF_SET_NW_TTL,
1631
1632         /**
1633          * Implements OFPAT_DEC_NW_TTL ("decrement IP TTL") as defined by
1634          * the OpenFlow Switch Specification.
1635          *
1636          * No associated configuration structure.
1637          */
1638         RTE_FLOW_ACTION_TYPE_OF_DEC_NW_TTL,
1639
1640         /**
1641          * Implements OFPAT_COPY_TTL_OUT ("copy TTL "outwards" -- from
1642          * next-to-outermost to outermost") as defined by the OpenFlow
1643          * Switch Specification.
1644          *
1645          * No associated configuration structure.
1646          */
1647         RTE_FLOW_ACTION_TYPE_OF_COPY_TTL_OUT,
1648
1649         /**
1650          * Implements OFPAT_COPY_TTL_IN ("copy TTL "inwards" -- from
1651          * outermost to next-to-outermost") as defined by the OpenFlow
1652          * Switch Specification.
1653          *
1654          * No associated configuration structure.
1655          */
1656         RTE_FLOW_ACTION_TYPE_OF_COPY_TTL_IN,
1657
1658         /**
1659          * Implements OFPAT_POP_VLAN ("pop the outer VLAN tag") as defined
1660          * by the OpenFlow Switch Specification.
1661          *
1662          * No associated configuration structure.
1663          */
1664         RTE_FLOW_ACTION_TYPE_OF_POP_VLAN,
1665
1666         /**
1667          * Implements OFPAT_PUSH_VLAN ("push a new VLAN tag") as defined by
1668          * the OpenFlow Switch Specification.
1669          *
1670          * See struct rte_flow_action_of_push_vlan.
1671          */
1672         RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN,
1673
1674         /**
1675          * Implements OFPAT_SET_VLAN_VID ("set the 802.1q VLAN id") as
1676          * defined by the OpenFlow Switch Specification.
1677          *
1678          * See struct rte_flow_action_of_set_vlan_vid.
1679          */
1680         RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID,
1681
1682         /**
1683          * Implements OFPAT_SET_LAN_PCP ("set the 802.1q priority") as
1684          * defined by the OpenFlow Switch Specification.
1685          *
1686          * See struct rte_flow_action_of_set_vlan_pcp.
1687          */
1688         RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP,
1689
1690         /**
1691          * Implements OFPAT_POP_MPLS ("pop the outer MPLS tag") as defined
1692          * by the OpenFlow Switch Specification.
1693          *
1694          * See struct rte_flow_action_of_pop_mpls.
1695          */
1696         RTE_FLOW_ACTION_TYPE_OF_POP_MPLS,
1697
1698         /**
1699          * Implements OFPAT_PUSH_MPLS ("push a new MPLS tag") as defined by
1700          * the OpenFlow Switch Specification.
1701          *
1702          * See struct rte_flow_action_of_push_mpls.
1703          */
1704         RTE_FLOW_ACTION_TYPE_OF_PUSH_MPLS,
1705
1706         /**
1707          * Encapsulate flow in VXLAN tunnel as defined in
1708          * rte_flow_action_vxlan_encap action structure.
1709          *
1710          * See struct rte_flow_action_vxlan_encap.
1711          */
1712         RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP,
1713
1714         /**
1715          * Decapsulate outer most VXLAN tunnel from matched flow.
1716          *
1717          * If flow pattern does not define a valid VXLAN tunnel (as specified by
1718          * RFC7348) then the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION
1719          * error.
1720          */
1721         RTE_FLOW_ACTION_TYPE_VXLAN_DECAP,
1722
1723         /**
1724          * Encapsulate flow in NVGRE tunnel defined in the
1725          * rte_flow_action_nvgre_encap action structure.
1726          *
1727          * See struct rte_flow_action_nvgre_encap.
1728          */
1729         RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP,
1730
1731         /**
1732          * Decapsulate outer most NVGRE tunnel from matched flow.
1733          *
1734          * If flow pattern does not define a valid NVGRE tunnel (as specified by
1735          * RFC7637) then the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION
1736          * error.
1737          */
1738         RTE_FLOW_ACTION_TYPE_NVGRE_DECAP,
1739
1740         /**
1741          * Add outer header whose template is provided in its data buffer
1742          *
1743          * See struct rte_flow_action_raw_encap.
1744          */
1745         RTE_FLOW_ACTION_TYPE_RAW_ENCAP,
1746
1747         /**
1748          * Remove outer header whose template is provided in its data buffer.
1749          *
1750          * See struct rte_flow_action_raw_decap
1751          */
1752         RTE_FLOW_ACTION_TYPE_RAW_DECAP,
1753
1754         /**
1755          * Modify IPv4 source address in the outermost IPv4 header.
1756          *
1757          * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_IPV4,
1758          * then the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION error.
1759          *
1760          * See struct rte_flow_action_set_ipv4.
1761          */
1762         RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC,
1763
1764         /**
1765          * Modify IPv4 destination address in the outermost IPv4 header.
1766          *
1767          * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_IPV4,
1768          * then the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION error.
1769          *
1770          * See struct rte_flow_action_set_ipv4.
1771          */
1772         RTE_FLOW_ACTION_TYPE_SET_IPV4_DST,
1773
1774         /**
1775          * Modify IPv6 source address in the outermost IPv6 header.
1776          *
1777          * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_IPV6,
1778          * then the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION error.
1779          *
1780          * See struct rte_flow_action_set_ipv6.
1781          */
1782         RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC,
1783
1784         /**
1785          * Modify IPv6 destination address in the outermost IPv6 header.
1786          *
1787          * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_IPV6,
1788          * then the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION error.
1789          *
1790          * See struct rte_flow_action_set_ipv6.
1791          */
1792         RTE_FLOW_ACTION_TYPE_SET_IPV6_DST,
1793
1794         /**
1795          * Modify source port number in the outermost TCP/UDP header.
1796          *
1797          * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_TCP
1798          * or RTE_FLOW_ITEM_TYPE_UDP, then the PMD should return a
1799          * RTE_FLOW_ERROR_TYPE_ACTION error.
1800          *
1801          * See struct rte_flow_action_set_tp.
1802          */
1803         RTE_FLOW_ACTION_TYPE_SET_TP_SRC,
1804
1805         /**
1806          * Modify destination port number in the outermost TCP/UDP header.
1807          *
1808          * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_TCP
1809          * or RTE_FLOW_ITEM_TYPE_UDP, then the PMD should return a
1810          * RTE_FLOW_ERROR_TYPE_ACTION error.
1811          *
1812          * See struct rte_flow_action_set_tp.
1813          */
1814         RTE_FLOW_ACTION_TYPE_SET_TP_DST,
1815
1816         /**
1817          * Swap the source and destination MAC addresses in the outermost
1818          * Ethernet header.
1819          *
1820          * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_ETH,
1821          * then the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION error.
1822          *
1823          * No associated configuration structure.
1824          */
1825         RTE_FLOW_ACTION_TYPE_MAC_SWAP,
1826
1827         /**
1828          * Decrease TTL value directly
1829          *
1830          * No associated configuration structure.
1831          */
1832         RTE_FLOW_ACTION_TYPE_DEC_TTL,
1833
1834         /**
1835          * Set TTL value
1836          *
1837          * See struct rte_flow_action_set_ttl
1838          */
1839         RTE_FLOW_ACTION_TYPE_SET_TTL,
1840
1841         /**
1842          * Set source MAC address from matched flow.
1843          *
1844          * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_ETH,
1845          * the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION error.
1846          *
1847          * See struct rte_flow_action_set_mac.
1848          */
1849         RTE_FLOW_ACTION_TYPE_SET_MAC_SRC,
1850
1851         /**
1852          * Set destination MAC address from matched flow.
1853          *
1854          * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_ETH,
1855          * the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION error.
1856          *
1857          * See struct rte_flow_action_set_mac.
1858          */
1859         RTE_FLOW_ACTION_TYPE_SET_MAC_DST,
1860
1861         /**
1862          * Increase sequence number in the outermost TCP header.
1863          *
1864          * Action configuration specifies the value to increase
1865          * TCP sequence number as a big-endian 32 bit integer.
1866          *
1867          * @p conf type:
1868          * @code rte_be32_t * @endcode
1869          *
1870          * Using this action on non-matching traffic will result in
1871          * undefined behavior.
1872          */
1873         RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ,
1874
1875         /**
1876          * Decrease sequence number in the outermost TCP header.
1877          *
1878          * Action configuration specifies the value to decrease
1879          * TCP sequence number as a big-endian 32 bit integer.
1880          *
1881          * @p conf type:
1882          * @code rte_be32_t * @endcode
1883          *
1884          * Using this action on non-matching traffic will result in
1885          * undefined behavior.
1886          */
1887         RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ,
1888
1889         /**
1890          * Increase acknowledgment number in the outermost TCP header.
1891          *
1892          * Action configuration specifies the value to increase
1893          * TCP acknowledgment number as a big-endian 32 bit integer.
1894          *
1895          * @p conf type:
1896          * @code rte_be32_t * @endcode
1897
1898          * Using this action on non-matching traffic will result in
1899          * undefined behavior.
1900          */
1901         RTE_FLOW_ACTION_TYPE_INC_TCP_ACK,
1902
1903         /**
1904          * Decrease acknowledgment number in the outermost TCP header.
1905          *
1906          * Action configuration specifies the value to decrease
1907          * TCP acknowledgment number as a big-endian 32 bit integer.
1908          *
1909          * @p conf type:
1910          * @code rte_be32_t * @endcode
1911          *
1912          * Using this action on non-matching traffic will result in
1913          * undefined behavior.
1914          */
1915         RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK,
1916 };
1917
1918 /**
1919  * RTE_FLOW_ACTION_TYPE_MARK
1920  *
1921  * Attaches an integer value to packets and sets PKT_RX_FDIR and
1922  * PKT_RX_FDIR_ID mbuf flags.
1923  *
1924  * This value is arbitrary and application-defined. Maximum allowed value
1925  * depends on the underlying implementation. It is returned in the
1926  * hash.fdir.hi mbuf field.
1927  */
1928 struct rte_flow_action_mark {
1929         uint32_t id; /**< Integer value to return with packets. */
1930 };
1931
1932 /**
1933  * @warning
1934  * @b EXPERIMENTAL: this structure may change without prior notice
1935  *
1936  * RTE_FLOW_ACTION_TYPE_JUMP
1937  *
1938  * Redirects packets to a group on the current device.
1939  *
1940  * In a hierarchy of groups, which can be used to represent physical or logical
1941  * flow tables on the device, this action allows the action to be a redirect to
1942  * a group on that device.
1943  */
1944 struct rte_flow_action_jump {
1945         uint32_t group;
1946 };
1947
1948 /**
1949  * RTE_FLOW_ACTION_TYPE_QUEUE
1950  *
1951  * Assign packets to a given queue index.
1952  */
1953 struct rte_flow_action_queue {
1954         uint16_t index; /**< Queue index to use. */
1955 };
1956
1957
1958 /**
1959  * @warning
1960  * @b EXPERIMENTAL: this structure may change without prior notice
1961  *
1962  * RTE_FLOW_ACTION_TYPE_COUNT
1963  *
1964  * Adds a counter action to a matched flow.
1965  *
1966  * If more than one count action is specified in a single flow rule, then each
1967  * action must specify a unique id.
1968  *
1969  * Counters can be retrieved and reset through ``rte_flow_query()``, see
1970  * ``struct rte_flow_query_count``.
1971  *
1972  * The shared flag indicates whether the counter is unique to the flow rule the
1973  * action is specified with, or whether it is a shared counter.
1974  *
1975  * For a count action with the shared flag set, then then a global device
1976  * namespace is assumed for the counter id, so that any matched flow rules using
1977  * a count action with the same counter id on the same port will contribute to
1978  * that counter.
1979  *
1980  * For ports within the same switch domain then the counter id namespace extends
1981  * to all ports within that switch domain.
1982  */
1983 struct rte_flow_action_count {
1984         uint32_t shared:1; /**< Share counter ID with other flow rules. */
1985         uint32_t reserved:31; /**< Reserved, must be zero. */
1986         uint32_t id; /**< Counter ID. */
1987 };
1988
1989 /**
1990  * RTE_FLOW_ACTION_TYPE_COUNT (query)
1991  *
1992  * Query structure to retrieve and reset flow rule counters.
1993  */
1994 struct rte_flow_query_count {
1995         uint32_t reset:1; /**< Reset counters after query [in]. */
1996         uint32_t hits_set:1; /**< hits field is set [out]. */
1997         uint32_t bytes_set:1; /**< bytes field is set [out]. */
1998         uint32_t reserved:29; /**< Reserved, must be zero [in, out]. */
1999         uint64_t hits; /**< Number of hits for this rule [out]. */
2000         uint64_t bytes; /**< Number of bytes through this rule [out]. */
2001 };
2002
2003 /**
2004  * Hash function types.
2005  */
2006 enum rte_eth_hash_function {
2007         RTE_ETH_HASH_FUNCTION_DEFAULT = 0,
2008         RTE_ETH_HASH_FUNCTION_TOEPLITZ, /**< Toeplitz */
2009         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR, /**< Simple XOR */
2010         /**
2011          * Symmetric Toeplitz: src, dst will be replaced by
2012          * xor(src, dst). For the case with src/dst only,
2013          * src or dst address will xor with zero pair.
2014          */
2015         RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ,
2016         RTE_ETH_HASH_FUNCTION_MAX,
2017 };
2018
2019 /**
2020  * RTE_FLOW_ACTION_TYPE_RSS
2021  *
2022  * Similar to QUEUE, except RSS is additionally performed on packets to
2023  * spread them among several queues according to the provided parameters.
2024  *
2025  * Unlike global RSS settings used by other DPDK APIs, unsetting the
2026  * @p types field does not disable RSS in a flow rule. Doing so instead
2027  * requests safe unspecified "best-effort" settings from the underlying PMD,
2028  * which depending on the flow rule, may result in anything ranging from
2029  * empty (single queue) to all-inclusive RSS.
2030  *
2031  * Note: RSS hash result is stored in the hash.rss mbuf field which overlaps
2032  * hash.fdir.lo. Since the MARK action sets the hash.fdir.hi field only,
2033  * both can be requested simultaneously.
2034  */
2035 struct rte_flow_action_rss {
2036         enum rte_eth_hash_function func; /**< RSS hash function to apply. */
2037         /**
2038          * Packet encapsulation level RSS hash @p types apply to.
2039          *
2040          * - @p 0 requests the default behavior. Depending on the packet
2041          *   type, it can mean outermost, innermost, anything in between or
2042          *   even no RSS.
2043          *
2044          *   It basically stands for the innermost encapsulation level RSS
2045          *   can be performed on according to PMD and device capabilities.
2046          *
2047          * - @p 1 requests RSS to be performed on the outermost packet
2048          *   encapsulation level.
2049          *
2050          * - @p 2 and subsequent values request RSS to be performed on the
2051          *   specified inner packet encapsulation level, from outermost to
2052          *   innermost (lower to higher values).
2053          *
2054          * Values other than @p 0 are not necessarily supported.
2055          *
2056          * Requesting a specific RSS level on unrecognized traffic results
2057          * in undefined behavior. For predictable results, it is recommended
2058          * to make the flow rule pattern match packet headers up to the
2059          * requested encapsulation level so that only matching traffic goes
2060          * through.
2061          */
2062         uint32_t level;
2063         uint64_t types; /**< Specific RSS hash types (see ETH_RSS_*). */
2064         uint32_t key_len; /**< Hash key length in bytes. */
2065         uint32_t queue_num; /**< Number of entries in @p queue. */
2066         const uint8_t *key; /**< Hash key. */
2067         const uint16_t *queue; /**< Queue indices to use. */
2068 };
2069
2070 /**
2071  * RTE_FLOW_ACTION_TYPE_VF
2072  *
2073  * Directs matching traffic to a given virtual function of the current
2074  * device.
2075  *
2076  * Packets matched by a VF pattern item can be redirected to their original
2077  * VF ID instead of the specified one. This parameter may not be available
2078  * and is not guaranteed to work properly if the VF part is matched by a
2079  * prior flow rule or if packets are not addressed to a VF in the first
2080  * place.
2081  */
2082 struct rte_flow_action_vf {
2083         uint32_t original:1; /**< Use original VF ID if possible. */
2084         uint32_t reserved:31; /**< Reserved, must be zero. */
2085         uint32_t id; /**< VF ID. */
2086 };
2087
2088 /**
2089  * RTE_FLOW_ACTION_TYPE_PHY_PORT
2090  *
2091  * Directs packets to a given physical port index of the underlying
2092  * device.
2093  *
2094  * @see RTE_FLOW_ITEM_TYPE_PHY_PORT
2095  */
2096 struct rte_flow_action_phy_port {
2097         uint32_t original:1; /**< Use original port index if possible. */
2098         uint32_t reserved:31; /**< Reserved, must be zero. */
2099         uint32_t index; /**< Physical port index. */
2100 };
2101
2102 /**
2103  * RTE_FLOW_ACTION_TYPE_PORT_ID
2104  *
2105  * Directs matching traffic to a given DPDK port ID.
2106  *
2107  * @see RTE_FLOW_ITEM_TYPE_PORT_ID
2108  */
2109 struct rte_flow_action_port_id {
2110         uint32_t original:1; /**< Use original DPDK port ID if possible. */
2111         uint32_t reserved:31; /**< Reserved, must be zero. */
2112         uint32_t id; /**< DPDK port ID. */
2113 };
2114
2115 /**
2116  * RTE_FLOW_ACTION_TYPE_METER
2117  *
2118  * Traffic metering and policing (MTR).
2119  *
2120  * Packets matched by items of this type can be either dropped or passed to the
2121  * next item with their color set by the MTR object.
2122  */
2123 struct rte_flow_action_meter {
2124         uint32_t mtr_id; /**< MTR object ID created with rte_mtr_create(). */
2125 };
2126
2127 /**
2128  * RTE_FLOW_ACTION_TYPE_SECURITY
2129  *
2130  * Perform the security action on flows matched by the pattern items
2131  * according to the configuration of the security session.
2132  *
2133  * This action modifies the payload of matched flows. For INLINE_CRYPTO, the
2134  * security protocol headers and IV are fully provided by the application as
2135  * specified in the flow pattern. The payload of matching packets is
2136  * encrypted on egress, and decrypted and authenticated on ingress.
2137  * For INLINE_PROTOCOL, the security protocol is fully offloaded to HW,
2138  * providing full encapsulation and decapsulation of packets in security
2139  * protocols. The flow pattern specifies both the outer security header fields
2140  * and the inner packet fields. The security session specified in the action
2141  * must match the pattern parameters.
2142  *
2143  * The security session specified in the action must be created on the same
2144  * port as the flow action that is being specified.
2145  *
2146  * The ingress/egress flow attribute should match that specified in the
2147  * security session if the security session supports the definition of the
2148  * direction.
2149  *
2150  * Multiple flows can be configured to use the same security session.
2151  */
2152 struct rte_flow_action_security {
2153         void *security_session; /**< Pointer to security session structure. */
2154 };
2155
2156 /**
2157  * RTE_FLOW_ACTION_TYPE_OF_SET_MPLS_TTL
2158  *
2159  * Implements OFPAT_SET_MPLS_TTL ("MPLS TTL") as defined by the OpenFlow
2160  * Switch Specification.
2161  */
2162 struct rte_flow_action_of_set_mpls_ttl {
2163         uint8_t mpls_ttl; /**< MPLS TTL. */
2164 };
2165
2166 /**
2167  * RTE_FLOW_ACTION_TYPE_OF_SET_NW_TTL
2168  *
2169  * Implements OFPAT_SET_NW_TTL ("IP TTL") as defined by the OpenFlow Switch
2170  * Specification.
2171  */
2172 struct rte_flow_action_of_set_nw_ttl {
2173         uint8_t nw_ttl; /**< IP TTL. */
2174 };
2175
2176 /**
2177  * RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN
2178  *
2179  * Implements OFPAT_PUSH_VLAN ("push a new VLAN tag") as defined by the
2180  * OpenFlow Switch Specification.
2181  */
2182 struct rte_flow_action_of_push_vlan {
2183         rte_be16_t ethertype; /**< EtherType. */
2184 };
2185
2186 /**
2187  * RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID
2188  *
2189  * Implements OFPAT_SET_VLAN_VID ("set the 802.1q VLAN id") as defined by
2190  * the OpenFlow Switch Specification.
2191  */
2192 struct rte_flow_action_of_set_vlan_vid {
2193         rte_be16_t vlan_vid; /**< VLAN id. */
2194 };
2195
2196 /**
2197  * RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP
2198  *
2199  * Implements OFPAT_SET_LAN_PCP ("set the 802.1q priority") as defined by
2200  * the OpenFlow Switch Specification.
2201  */
2202 struct rte_flow_action_of_set_vlan_pcp {
2203         uint8_t vlan_pcp; /**< VLAN priority. */
2204 };
2205
2206 /**
2207  * RTE_FLOW_ACTION_TYPE_OF_POP_MPLS
2208  *
2209  * Implements OFPAT_POP_MPLS ("pop the outer MPLS tag") as defined by the
2210  * OpenFlow Switch Specification.
2211  */
2212 struct rte_flow_action_of_pop_mpls {
2213         rte_be16_t ethertype; /**< EtherType. */
2214 };
2215
2216 /**
2217  * RTE_FLOW_ACTION_TYPE_OF_PUSH_MPLS
2218  *
2219  * Implements OFPAT_PUSH_MPLS ("push a new MPLS tag") as defined by the
2220  * OpenFlow Switch Specification.
2221  */
2222 struct rte_flow_action_of_push_mpls {
2223         rte_be16_t ethertype; /**< EtherType. */
2224 };
2225
2226 /**
2227  * @warning
2228  * @b EXPERIMENTAL: this structure may change without prior notice
2229  *
2230  * RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP
2231  *
2232  * VXLAN tunnel end-point encapsulation data definition
2233  *
2234  * The tunnel definition is provided through the flow item pattern, the
2235  * provided pattern must conform to RFC7348 for the tunnel specified. The flow
2236  * definition must be provided in order from the RTE_FLOW_ITEM_TYPE_ETH
2237  * definition up the end item which is specified by RTE_FLOW_ITEM_TYPE_END.
2238  *
2239  * The mask field allows user to specify which fields in the flow item
2240  * definitions can be ignored and which have valid data and can be used
2241  * verbatim.
2242  *
2243  * Note: the last field is not used in the definition of a tunnel and can be
2244  * ignored.
2245  *
2246  * Valid flow definition for RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP include:
2247  *
2248  * - ETH / IPV4 / UDP / VXLAN / END
2249  * - ETH / IPV6 / UDP / VXLAN / END
2250  * - ETH / VLAN / IPV4 / UDP / VXLAN / END
2251  *
2252  */
2253 struct rte_flow_action_vxlan_encap {
2254         /**
2255          * Encapsulating vxlan tunnel definition
2256          * (terminated by the END pattern item).
2257          */
2258         struct rte_flow_item *definition;
2259 };
2260
2261 /**
2262  * @warning
2263  * @b EXPERIMENTAL: this structure may change without prior notice
2264  *
2265  * RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP
2266  *
2267  * NVGRE tunnel end-point encapsulation data definition
2268  *
2269  * The tunnel definition is provided through the flow item pattern  the
2270  * provided pattern must conform with RFC7637. The flow definition must be
2271  * provided in order from the RTE_FLOW_ITEM_TYPE_ETH definition up the end item
2272  * which is specified by RTE_FLOW_ITEM_TYPE_END.
2273  *
2274  * The mask field allows user to specify which fields in the flow item
2275  * definitions can be ignored and which have valid data and can be used
2276  * verbatim.
2277  *
2278  * Note: the last field is not used in the definition of a tunnel and can be
2279  * ignored.
2280  *
2281  * Valid flow definition for RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP include:
2282  *
2283  * - ETH / IPV4 / NVGRE / END
2284  * - ETH / VLAN / IPV6 / NVGRE / END
2285  *
2286  */
2287 struct rte_flow_action_nvgre_encap {
2288         /**
2289          * Encapsulating vxlan tunnel definition
2290          * (terminated by the END pattern item).
2291          */
2292         struct rte_flow_item *definition;
2293 };
2294
2295 /**
2296  * @warning
2297  * @b EXPERIMENTAL: this structure may change without prior notice
2298  *
2299  * RTE_FLOW_ACTION_TYPE_RAW_ENCAP
2300  *
2301  * Raw tunnel end-point encapsulation data definition.
2302  *
2303  * The data holds the headers definitions to be applied on the packet.
2304  * The data must start with ETH header up to the tunnel item header itself.
2305  * When used right after RAW_DECAP (for decapsulating L3 tunnel type for
2306  * example MPLSoGRE) the data will just hold layer 2 header.
2307  *
2308  * The preserve parameter holds which bits in the packet the PMD is not allowed
2309  * to change, this parameter can also be NULL and then the PMD is allowed
2310  * to update any field.
2311  *
2312  * size holds the number of bytes in @p data and @p preserve.
2313  */
2314 struct rte_flow_action_raw_encap {
2315         uint8_t *data; /**< Encapsulation data. */
2316         uint8_t *preserve; /**< Bit-mask of @p data to preserve on output. */
2317         size_t size; /**< Size of @p data and @p preserve. */
2318 };
2319
2320 /**
2321  * @warning
2322  * @b EXPERIMENTAL: this structure may change without prior notice
2323  *
2324  * RTE_FLOW_ACTION_TYPE_RAW_DECAP
2325  *
2326  * Raw tunnel end-point decapsulation data definition.
2327  *
2328  * The data holds the headers definitions to be removed from the packet.
2329  * The data must start with ETH header up to the tunnel item header itself.
2330  * When used right before RAW_DECAP (for encapsulating L3 tunnel type for
2331  * example MPLSoGRE) the data will just hold layer 2 header.
2332  *
2333  * size holds the number of bytes in @p data.
2334  */
2335 struct rte_flow_action_raw_decap {
2336         uint8_t *data; /**< Encapsulation data. */
2337         size_t size; /**< Size of @p data and @p preserve. */
2338 };
2339
2340 /**
2341  * @warning
2342  * @b EXPERIMENTAL: this structure may change without prior notice
2343  *
2344  * RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC
2345  * RTE_FLOW_ACTION_TYPE_SET_IPV4_DST
2346  *
2347  * Allows modification of IPv4 source (RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC)
2348  * and destination address (RTE_FLOW_ACTION_TYPE_SET_IPV4_DST) in the
2349  * specified outermost IPv4 header.
2350  */
2351 struct rte_flow_action_set_ipv4 {
2352         rte_be32_t ipv4_addr;
2353 };
2354
2355 /**
2356  * @warning
2357  * @b EXPERIMENTAL: this structure may change without prior notice
2358  *
2359  * RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC
2360  * RTE_FLOW_ACTION_TYPE_SET_IPV6_DST
2361  *
2362  * Allows modification of IPv6 source (RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC)
2363  * and destination address (RTE_FLOW_ACTION_TYPE_SET_IPV6_DST) in the
2364  * specified outermost IPv6 header.
2365  */
2366 struct rte_flow_action_set_ipv6 {
2367         uint8_t ipv6_addr[16];
2368 };
2369
2370 /**
2371  * @warning
2372  * @b EXPERIMENTAL: this structure may change without prior notice
2373  *
2374  * RTE_FLOW_ACTION_TYPE_SET_TP_SRC
2375  * RTE_FLOW_ACTION_TYPE_SET_TP_DST
2376  *
2377  * Allows modification of source (RTE_FLOW_ACTION_TYPE_SET_TP_SRC)
2378  * and destination (RTE_FLOW_ACTION_TYPE_SET_TP_DST) port numbers
2379  * in the specified outermost TCP/UDP header.
2380  */
2381 struct rte_flow_action_set_tp {
2382         rte_be16_t port;
2383 };
2384
2385 /**
2386  * RTE_FLOW_ACTION_TYPE_SET_TTL
2387  *
2388  * Set the TTL value directly for IPv4 or IPv6
2389  */
2390 struct rte_flow_action_set_ttl {
2391         uint8_t ttl_value;
2392 };
2393
2394 /**
2395  * RTE_FLOW_ACTION_TYPE_SET_MAC
2396  *
2397  * Set MAC address from the matched flow
2398  */
2399 struct rte_flow_action_set_mac {
2400         uint8_t mac_addr[RTE_ETHER_ADDR_LEN];
2401 };
2402
2403 /*
2404  * Definition of a single action.
2405  *
2406  * A list of actions is terminated by a END action.
2407  *
2408  * For simple actions without a configuration object, conf remains NULL.
2409  */
2410 struct rte_flow_action {
2411         enum rte_flow_action_type type; /**< Action type. */
2412         const void *conf; /**< Pointer to action configuration object. */
2413 };
2414
2415 /**
2416  * Opaque type returned after successfully creating a flow.
2417  *
2418  * This handle can be used to manage and query the related flow (e.g. to
2419  * destroy it or retrieve counters).
2420  */
2421 struct rte_flow;
2422
2423 /**
2424  * Verbose error types.
2425  *
2426  * Most of them provide the type of the object referenced by struct
2427  * rte_flow_error.cause.
2428  */
2429 enum rte_flow_error_type {
2430         RTE_FLOW_ERROR_TYPE_NONE, /**< No error. */
2431         RTE_FLOW_ERROR_TYPE_UNSPECIFIED, /**< Cause unspecified. */
2432         RTE_FLOW_ERROR_TYPE_HANDLE, /**< Flow rule (handle). */
2433         RTE_FLOW_ERROR_TYPE_ATTR_GROUP, /**< Group field. */
2434         RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY, /**< Priority field. */
2435         RTE_FLOW_ERROR_TYPE_ATTR_INGRESS, /**< Ingress field. */
2436         RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, /**< Egress field. */
2437         RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER, /**< Transfer field. */
2438         RTE_FLOW_ERROR_TYPE_ATTR, /**< Attributes structure. */
2439         RTE_FLOW_ERROR_TYPE_ITEM_NUM, /**< Pattern length. */
2440         RTE_FLOW_ERROR_TYPE_ITEM_SPEC, /**< Item specification. */
2441         RTE_FLOW_ERROR_TYPE_ITEM_LAST, /**< Item specification range. */
2442         RTE_FLOW_ERROR_TYPE_ITEM_MASK, /**< Item specification mask. */
2443         RTE_FLOW_ERROR_TYPE_ITEM, /**< Specific pattern item. */
2444         RTE_FLOW_ERROR_TYPE_ACTION_NUM, /**< Number of actions. */
2445         RTE_FLOW_ERROR_TYPE_ACTION_CONF, /**< Action configuration. */
2446         RTE_FLOW_ERROR_TYPE_ACTION, /**< Specific action. */
2447 };
2448
2449 /**
2450  * Verbose error structure definition.
2451  *
2452  * This object is normally allocated by applications and set by PMDs, the
2453  * message points to a constant string which does not need to be freed by
2454  * the application, however its pointer can be considered valid only as long
2455  * as its associated DPDK port remains configured. Closing the underlying
2456  * device or unloading the PMD invalidates it.
2457  *
2458  * Both cause and message may be NULL regardless of the error type.
2459  */
2460 struct rte_flow_error {
2461         enum rte_flow_error_type type; /**< Cause field and error types. */
2462         const void *cause; /**< Object responsible for the error. */
2463         const char *message; /**< Human-readable error message. */
2464 };
2465
2466 /**
2467  * Complete flow rule description.
2468  *
2469  * This object type is used when converting a flow rule description.
2470  *
2471  * @see RTE_FLOW_CONV_OP_RULE
2472  * @see rte_flow_conv()
2473  */
2474 RTE_STD_C11
2475 struct rte_flow_conv_rule {
2476         union {
2477                 const struct rte_flow_attr *attr_ro; /**< RO attributes. */
2478                 struct rte_flow_attr *attr; /**< Attributes. */
2479         };
2480         union {
2481                 const struct rte_flow_item *pattern_ro; /**< RO pattern. */
2482                 struct rte_flow_item *pattern; /**< Pattern items. */
2483         };
2484         union {
2485                 const struct rte_flow_action *actions_ro; /**< RO actions. */
2486                 struct rte_flow_action *actions; /**< List of actions. */
2487         };
2488 };
2489
2490 /**
2491  * Conversion operations for flow API objects.
2492  *
2493  * @see rte_flow_conv()
2494  */
2495 enum rte_flow_conv_op {
2496         /**
2497          * No operation to perform.
2498          *
2499          * rte_flow_conv() simply returns 0.
2500          */
2501         RTE_FLOW_CONV_OP_NONE,
2502
2503         /**
2504          * Convert attributes structure.
2505          *
2506          * This is a basic copy of an attributes structure.
2507          *
2508          * - @p src type:
2509          *   @code const struct rte_flow_attr * @endcode
2510          * - @p dst type:
2511          *   @code struct rte_flow_attr * @endcode
2512          */
2513         RTE_FLOW_CONV_OP_ATTR,
2514
2515         /**
2516          * Convert a single item.
2517          *
2518          * Duplicates @p spec, @p last and @p mask but not outside objects.
2519          *
2520          * - @p src type:
2521          *   @code const struct rte_flow_item * @endcode
2522          * - @p dst type:
2523          *   @code struct rte_flow_item * @endcode
2524          */
2525         RTE_FLOW_CONV_OP_ITEM,
2526
2527         /**
2528          * Convert a single action.
2529          *
2530          * Duplicates @p conf but not outside objects.
2531          *
2532          * - @p src type:
2533          *   @code const struct rte_flow_action * @endcode
2534          * - @p dst type:
2535          *   @code struct rte_flow_action * @endcode
2536          */
2537         RTE_FLOW_CONV_OP_ACTION,
2538
2539         /**
2540          * Convert an entire pattern.
2541          *
2542          * Duplicates all pattern items at once with the same constraints as
2543          * RTE_FLOW_CONV_OP_ITEM.
2544          *
2545          * - @p src type:
2546          *   @code const struct rte_flow_item * @endcode
2547          * - @p dst type:
2548          *   @code struct rte_flow_item * @endcode
2549          */
2550         RTE_FLOW_CONV_OP_PATTERN,
2551
2552         /**
2553          * Convert a list of actions.
2554          *
2555          * Duplicates the entire list of actions at once with the same
2556          * constraints as RTE_FLOW_CONV_OP_ACTION.
2557          *
2558          * - @p src type:
2559          *   @code const struct rte_flow_action * @endcode
2560          * - @p dst type:
2561          *   @code struct rte_flow_action * @endcode
2562          */
2563         RTE_FLOW_CONV_OP_ACTIONS,
2564
2565         /**
2566          * Convert a complete flow rule description.
2567          *
2568          * Comprises attributes, pattern and actions together at once with
2569          * the usual constraints.
2570          *
2571          * - @p src type:
2572          *   @code const struct rte_flow_conv_rule * @endcode
2573          * - @p dst type:
2574          *   @code struct rte_flow_conv_rule * @endcode
2575          */
2576         RTE_FLOW_CONV_OP_RULE,
2577
2578         /**
2579          * Convert item type to its name string.
2580          *
2581          * Writes a NUL-terminated string to @p dst. Like snprintf(), the
2582          * returned value excludes the terminator which is always written
2583          * nonetheless.
2584          *
2585          * - @p src type:
2586          *   @code (const void *)enum rte_flow_item_type @endcode
2587          * - @p dst type:
2588          *   @code char * @endcode
2589          **/
2590         RTE_FLOW_CONV_OP_ITEM_NAME,
2591
2592         /**
2593          * Convert action type to its name string.
2594          *
2595          * Writes a NUL-terminated string to @p dst. Like snprintf(), the
2596          * returned value excludes the terminator which is always written
2597          * nonetheless.
2598          *
2599          * - @p src type:
2600          *   @code (const void *)enum rte_flow_action_type @endcode
2601          * - @p dst type:
2602          *   @code char * @endcode
2603          **/
2604         RTE_FLOW_CONV_OP_ACTION_NAME,
2605
2606         /**
2607          * Convert item type to pointer to item name.
2608          *
2609          * Retrieves item name pointer from its type. The string itself is
2610          * not copied; instead, a unique pointer to an internal static
2611          * constant storage is written to @p dst.
2612          *
2613          * - @p src type:
2614          *   @code (const void *)enum rte_flow_item_type @endcode
2615          * - @p dst type:
2616          *   @code const char ** @endcode
2617          */
2618         RTE_FLOW_CONV_OP_ITEM_NAME_PTR,
2619
2620         /**
2621          * Convert action type to pointer to action name.
2622          *
2623          * Retrieves action name pointer from its type. The string itself is
2624          * not copied; instead, a unique pointer to an internal static
2625          * constant storage is written to @p dst.
2626          *
2627          * - @p src type:
2628          *   @code (const void *)enum rte_flow_action_type @endcode
2629          * - @p dst type:
2630          *   @code const char ** @endcode
2631          */
2632         RTE_FLOW_CONV_OP_ACTION_NAME_PTR,
2633 };
2634
2635 /**
2636  * Check whether a flow rule can be created on a given port.
2637  *
2638  * The flow rule is validated for correctness and whether it could be accepted
2639  * by the device given sufficient resources. The rule is checked against the
2640  * current device mode and queue configuration. The flow rule may also
2641  * optionally be validated against existing flow rules and device resources.
2642  * This function has no effect on the target device.
2643  *
2644  * The returned value is guaranteed to remain valid only as long as no
2645  * successful calls to rte_flow_create() or rte_flow_destroy() are made in
2646  * the meantime and no device parameter affecting flow rules in any way are
2647  * modified, due to possible collisions or resource limitations (although in
2648  * such cases EINVAL should not be returned).
2649  *
2650  * @param port_id
2651  *   Port identifier of Ethernet device.
2652  * @param[in] attr
2653  *   Flow rule attributes.
2654  * @param[in] pattern
2655  *   Pattern specification (list terminated by the END pattern item).
2656  * @param[in] actions
2657  *   Associated actions (list terminated by the END action).
2658  * @param[out] error
2659  *   Perform verbose error reporting if not NULL. PMDs initialize this
2660  *   structure in case of error only.
2661  *
2662  * @return
2663  *   0 if flow rule is valid and can be created. A negative errno value
2664  *   otherwise (rte_errno is also set), the following errors are defined:
2665  *
2666  *   -ENOSYS: underlying device does not support this functionality.
2667  *
2668  *   -EIO: underlying device is removed.
2669  *
2670  *   -EINVAL: unknown or invalid rule specification.
2671  *
2672  *   -ENOTSUP: valid but unsupported rule specification (e.g. partial
2673  *   bit-masks are unsupported).
2674  *
2675  *   -EEXIST: collision with an existing rule. Only returned if device
2676  *   supports flow rule collision checking and there was a flow rule
2677  *   collision. Not receiving this return code is no guarantee that creating
2678  *   the rule will not fail due to a collision.
2679  *
2680  *   -ENOMEM: not enough memory to execute the function, or if the device
2681  *   supports resource validation, resource limitation on the device.
2682  *
2683  *   -EBUSY: action cannot be performed due to busy device resources, may
2684  *   succeed if the affected queues or even the entire port are in a stopped
2685  *   state (see rte_eth_dev_rx_queue_stop() and rte_eth_dev_stop()).
2686  */
2687 int
2688 rte_flow_validate(uint16_t port_id,
2689                   const struct rte_flow_attr *attr,
2690                   const struct rte_flow_item pattern[],
2691                   const struct rte_flow_action actions[],
2692                   struct rte_flow_error *error);
2693
2694 /**
2695  * Create a flow rule on a given port.
2696  *
2697  * @param port_id
2698  *   Port identifier of Ethernet device.
2699  * @param[in] attr
2700  *   Flow rule attributes.
2701  * @param[in] pattern
2702  *   Pattern specification (list terminated by the END pattern item).
2703  * @param[in] actions
2704  *   Associated actions (list terminated by the END action).
2705  * @param[out] error
2706  *   Perform verbose error reporting if not NULL. PMDs initialize this
2707  *   structure in case of error only.
2708  *
2709  * @return
2710  *   A valid handle in case of success, NULL otherwise and rte_errno is set
2711  *   to the positive version of one of the error codes defined for
2712  *   rte_flow_validate().
2713  */
2714 struct rte_flow *
2715 rte_flow_create(uint16_t port_id,
2716                 const struct rte_flow_attr *attr,
2717                 const struct rte_flow_item pattern[],
2718                 const struct rte_flow_action actions[],
2719                 struct rte_flow_error *error);
2720
2721 /**
2722  * Destroy a flow rule on a given port.
2723  *
2724  * Failure to destroy a flow rule handle may occur when other flow rules
2725  * depend on it, and destroying it would result in an inconsistent state.
2726  *
2727  * This function is only guaranteed to succeed if handles are destroyed in
2728  * reverse order of their creation.
2729  *
2730  * @param port_id
2731  *   Port identifier of Ethernet device.
2732  * @param flow
2733  *   Flow rule handle to destroy.
2734  * @param[out] error
2735  *   Perform verbose error reporting if not NULL. PMDs initialize this
2736  *   structure in case of error only.
2737  *
2738  * @return
2739  *   0 on success, a negative errno value otherwise and rte_errno is set.
2740  */
2741 int
2742 rte_flow_destroy(uint16_t port_id,
2743                  struct rte_flow *flow,
2744                  struct rte_flow_error *error);
2745
2746 /**
2747  * Destroy all flow rules associated with a port.
2748  *
2749  * In the unlikely event of failure, handles are still considered destroyed
2750  * and no longer valid but the port must be assumed to be in an inconsistent
2751  * state.
2752  *
2753  * @param port_id
2754  *   Port identifier of Ethernet device.
2755  * @param[out] error
2756  *   Perform verbose error reporting if not NULL. PMDs initialize this
2757  *   structure in case of error only.
2758  *
2759  * @return
2760  *   0 on success, a negative errno value otherwise and rte_errno is set.
2761  */
2762 int
2763 rte_flow_flush(uint16_t port_id,
2764                struct rte_flow_error *error);
2765
2766 /**
2767  * Query an existing flow rule.
2768  *
2769  * This function allows retrieving flow-specific data such as counters.
2770  * Data is gathered by special actions which must be present in the flow
2771  * rule definition.
2772  *
2773  * \see RTE_FLOW_ACTION_TYPE_COUNT
2774  *
2775  * @param port_id
2776  *   Port identifier of Ethernet device.
2777  * @param flow
2778  *   Flow rule handle to query.
2779  * @param action
2780  *   Action definition as defined in original flow rule.
2781  * @param[in, out] data
2782  *   Pointer to storage for the associated query data type.
2783  * @param[out] error
2784  *   Perform verbose error reporting if not NULL. PMDs initialize this
2785  *   structure in case of error only.
2786  *
2787  * @return
2788  *   0 on success, a negative errno value otherwise and rte_errno is set.
2789  */
2790 int
2791 rte_flow_query(uint16_t port_id,
2792                struct rte_flow *flow,
2793                const struct rte_flow_action *action,
2794                void *data,
2795                struct rte_flow_error *error);
2796
2797 /**
2798  * Restrict ingress traffic to the defined flow rules.
2799  *
2800  * Isolated mode guarantees that all ingress traffic comes from defined flow
2801  * rules only (current and future).
2802  *
2803  * Besides making ingress more deterministic, it allows PMDs to safely reuse
2804  * resources otherwise assigned to handle the remaining traffic, such as
2805  * global RSS configuration settings, VLAN filters, MAC address entries,
2806  * legacy filter API rules and so on in order to expand the set of possible
2807  * flow rule types.
2808  *
2809  * Calling this function as soon as possible after device initialization,
2810  * ideally before the first call to rte_eth_dev_configure(), is recommended
2811  * to avoid possible failures due to conflicting settings.
2812  *
2813  * Once effective, leaving isolated mode may not be possible depending on
2814  * PMD implementation.
2815  *
2816  * Additionally, the following functionality has no effect on the underlying
2817  * port and may return errors such as ENOTSUP ("not supported"):
2818  *
2819  * - Toggling promiscuous mode.
2820  * - Toggling allmulticast mode.
2821  * - Configuring MAC addresses.
2822  * - Configuring multicast addresses.
2823  * - Configuring VLAN filters.
2824  * - Configuring Rx filters through the legacy API (e.g. FDIR).
2825  * - Configuring global RSS settings.
2826  *
2827  * @param port_id
2828  *   Port identifier of Ethernet device.
2829  * @param set
2830  *   Nonzero to enter isolated mode, attempt to leave it otherwise.
2831  * @param[out] error
2832  *   Perform verbose error reporting if not NULL. PMDs initialize this
2833  *   structure in case of error only.
2834  *
2835  * @return
2836  *   0 on success, a negative errno value otherwise and rte_errno is set.
2837  */
2838 int
2839 rte_flow_isolate(uint16_t port_id, int set, struct rte_flow_error *error);
2840
2841 /**
2842  * Initialize flow error structure.
2843  *
2844  * @param[out] error
2845  *   Pointer to flow error structure (may be NULL).
2846  * @param code
2847  *   Related error code (rte_errno).
2848  * @param type
2849  *   Cause field and error types.
2850  * @param cause
2851  *   Object responsible for the error.
2852  * @param message
2853  *   Human-readable error message.
2854  *
2855  * @return
2856  *   Negative error code (errno value) and rte_errno is set.
2857  */
2858 int
2859 rte_flow_error_set(struct rte_flow_error *error,
2860                    int code,
2861                    enum rte_flow_error_type type,
2862                    const void *cause,
2863                    const char *message);
2864
2865 /**
2866  * @deprecated
2867  * @see rte_flow_copy()
2868  */
2869 struct rte_flow_desc {
2870         size_t size; /**< Allocated space including data[]. */
2871         struct rte_flow_attr attr; /**< Attributes. */
2872         struct rte_flow_item *items; /**< Items. */
2873         struct rte_flow_action *actions; /**< Actions. */
2874         uint8_t data[]; /**< Storage for items/actions. */
2875 };
2876
2877 /**
2878  * @deprecated
2879  * Copy an rte_flow rule description.
2880  *
2881  * This interface is kept for compatibility with older applications but is
2882  * implemented as a wrapper to rte_flow_conv(). It is deprecated due to its
2883  * lack of flexibility and reliance on a type unusable with C++ programs
2884  * (struct rte_flow_desc).
2885  *
2886  * @param[in] fd
2887  *   Flow rule description.
2888  * @param[in] len
2889  *   Total size of allocated data for the flow description.
2890  * @param[in] attr
2891  *   Flow rule attributes.
2892  * @param[in] items
2893  *   Pattern specification (list terminated by the END pattern item).
2894  * @param[in] actions
2895  *   Associated actions (list terminated by the END action).
2896  *
2897  * @return
2898  *   If len is greater or equal to the size of the flow, the total size of the
2899  *   flow description and its data.
2900  *   If len is lower than the size of the flow, the number of bytes that would
2901  *   have been written to desc had it been sufficient. Nothing is written.
2902  */
2903 __rte_deprecated
2904 size_t
2905 rte_flow_copy(struct rte_flow_desc *fd, size_t len,
2906               const struct rte_flow_attr *attr,
2907               const struct rte_flow_item *items,
2908               const struct rte_flow_action *actions);
2909
2910 /**
2911  * Flow object conversion helper.
2912  *
2913  * This function performs conversion of various flow API objects to a
2914  * pre-allocated destination buffer. See enum rte_flow_conv_op for possible
2915  * operations and details about each of them.
2916  *
2917  * Since destination buffer must be large enough, it works in a manner
2918  * reminiscent of snprintf():
2919  *
2920  * - If @p size is 0, @p dst may be a NULL pointer, otherwise @p dst must be
2921  *   non-NULL.
2922  * - If positive, the returned value represents the number of bytes needed
2923  *   to store the conversion of @p src to @p dst according to @p op
2924  *   regardless of the @p size parameter.
2925  * - Since no more than @p size bytes can be written to @p dst, output is
2926  *   truncated and may be inconsistent when the returned value is larger
2927  *   than that.
2928  * - In case of conversion error, a negative error code is returned and
2929  *   @p dst contents are unspecified.
2930  *
2931  * @param op
2932  *   Operation to perform, related to the object type of @p dst.
2933  * @param[out] dst
2934  *   Destination buffer address. Must be suitably aligned by the caller.
2935  * @param size
2936  *   Destination buffer size in bytes.
2937  * @param[in] src
2938  *   Source object to copy. Depending on @p op, its type may differ from
2939  *   that of @p dst.
2940  * @param[out] error
2941  *   Perform verbose error reporting if not NULL. Initialized in case of
2942  *   error only.
2943  *
2944  * @return
2945  *   The number of bytes required to convert @p src to @p dst on success, a
2946  *   negative errno value otherwise and rte_errno is set.
2947  *
2948  * @see rte_flow_conv_op
2949  */
2950 __rte_experimental
2951 int
2952 rte_flow_conv(enum rte_flow_conv_op op,
2953               void *dst,
2954               size_t size,
2955               const void *src,
2956               struct rte_flow_error *error);
2957
2958 #ifdef __cplusplus
2959 }
2960 #endif
2961
2962 #endif /* RTE_FLOW_H_ */