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