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