d3e8d8a9c28441d1f015532e64b0d8af449aaa07
[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  * Otherwise, only untagged packets will match the pattern.
732  * If the @p ETH item is the only item in the pattern, and the @p type field
733  * is not specified, then both tagged and untagged packets will match the
734  * 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 };
741
742 /** Default mask for RTE_FLOW_ITEM_TYPE_ETH. */
743 #ifndef __cplusplus
744 static const struct rte_flow_item_eth rte_flow_item_eth_mask = {
745         .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
746         .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
747         .type = RTE_BE16(0x0000),
748 };
749 #endif
750
751 /**
752  * RTE_FLOW_ITEM_TYPE_VLAN
753  *
754  * Matches an 802.1Q/ad VLAN tag.
755  *
756  * The corresponding standard outer EtherType (TPID) values are
757  * RTE_ETHER_TYPE_VLAN or RTE_ETHER_TYPE_QINQ. It can be overridden by
758  * the preceding pattern item.
759  * If a @p VLAN item is present in the pattern, then only tagged packets will
760  * match the pattern.
761  */
762 struct rte_flow_item_vlan {
763         rte_be16_t tci; /**< Tag control information. */
764         rte_be16_t inner_type; /**< Inner EtherType or TPID. */
765 };
766
767 /** Default mask for RTE_FLOW_ITEM_TYPE_VLAN. */
768 #ifndef __cplusplus
769 static const struct rte_flow_item_vlan rte_flow_item_vlan_mask = {
770         .tci = RTE_BE16(0x0fff),
771         .inner_type = RTE_BE16(0x0000),
772 };
773 #endif
774
775 /**
776  * RTE_FLOW_ITEM_TYPE_IPV4
777  *
778  * Matches an IPv4 header.
779  *
780  * Note: IPv4 options are handled by dedicated pattern items.
781  */
782 struct rte_flow_item_ipv4 {
783         struct rte_ipv4_hdr hdr; /**< IPv4 header definition. */
784 };
785
786 /** Default mask for RTE_FLOW_ITEM_TYPE_IPV4. */
787 #ifndef __cplusplus
788 static const struct rte_flow_item_ipv4 rte_flow_item_ipv4_mask = {
789         .hdr = {
790                 .src_addr = RTE_BE32(0xffffffff),
791                 .dst_addr = RTE_BE32(0xffffffff),
792         },
793 };
794 #endif
795
796 /**
797  * RTE_FLOW_ITEM_TYPE_IPV6.
798  *
799  * Matches an IPv6 header.
800  *
801  * Dedicated flags indicate if header contains specific extension headers.
802  */
803 struct rte_flow_item_ipv6 {
804         struct rte_ipv6_hdr hdr; /**< IPv6 header definition. */
805         uint32_t has_hop_ext:1;
806         /**< Header contains Hop-by-Hop Options extension header. */
807         uint32_t has_route_ext:1;
808         /**< Header contains Routing extension header. */
809         uint32_t has_frag_ext:1;
810         /**< Header contains Fragment extension header. */
811         uint32_t has_auth_ext:1;
812         /**< Header contains Authentication extension header. */
813         uint32_t has_esp_ext:1;
814         /**< Header contains Encapsulation Security Payload extension header. */
815         uint32_t has_dest_ext:1;
816         /**< Header contains Destination Options extension header. */
817         uint32_t has_mobil_ext:1;
818         /**< Header contains Mobility extension header. */
819         uint32_t has_hip_ext:1;
820         /**< Header contains Host Identity Protocol extension header. */
821         uint32_t has_shim6_ext:1;
822         /**< Header contains Shim6 Protocol extension header. */
823         uint32_t reserved:23;
824         /**< Reserved for future extension headers, must be zero. */
825 };
826
827 /** Default mask for RTE_FLOW_ITEM_TYPE_IPV6. */
828 #ifndef __cplusplus
829 static const struct rte_flow_item_ipv6 rte_flow_item_ipv6_mask = {
830         .hdr = {
831                 .src_addr =
832                         "\xff\xff\xff\xff\xff\xff\xff\xff"
833                         "\xff\xff\xff\xff\xff\xff\xff\xff",
834                 .dst_addr =
835                         "\xff\xff\xff\xff\xff\xff\xff\xff"
836                         "\xff\xff\xff\xff\xff\xff\xff\xff",
837         },
838 };
839 #endif
840
841 /**
842  * RTE_FLOW_ITEM_TYPE_ICMP.
843  *
844  * Matches an ICMP header.
845  */
846 struct rte_flow_item_icmp {
847         struct rte_icmp_hdr hdr; /**< ICMP header definition. */
848 };
849
850 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP. */
851 #ifndef __cplusplus
852 static const struct rte_flow_item_icmp rte_flow_item_icmp_mask = {
853         .hdr = {
854                 .icmp_type = 0xff,
855                 .icmp_code = 0xff,
856         },
857 };
858 #endif
859
860 /**
861  * RTE_FLOW_ITEM_TYPE_UDP.
862  *
863  * Matches a UDP header.
864  */
865 struct rte_flow_item_udp {
866         struct rte_udp_hdr hdr; /**< UDP header definition. */
867 };
868
869 /** Default mask for RTE_FLOW_ITEM_TYPE_UDP. */
870 #ifndef __cplusplus
871 static const struct rte_flow_item_udp rte_flow_item_udp_mask = {
872         .hdr = {
873                 .src_port = RTE_BE16(0xffff),
874                 .dst_port = RTE_BE16(0xffff),
875         },
876 };
877 #endif
878
879 /**
880  * RTE_FLOW_ITEM_TYPE_TCP.
881  *
882  * Matches a TCP header.
883  */
884 struct rte_flow_item_tcp {
885         struct rte_tcp_hdr hdr; /**< TCP header definition. */
886 };
887
888 /** Default mask for RTE_FLOW_ITEM_TYPE_TCP. */
889 #ifndef __cplusplus
890 static const struct rte_flow_item_tcp rte_flow_item_tcp_mask = {
891         .hdr = {
892                 .src_port = RTE_BE16(0xffff),
893                 .dst_port = RTE_BE16(0xffff),
894         },
895 };
896 #endif
897
898 /**
899  * RTE_FLOW_ITEM_TYPE_SCTP.
900  *
901  * Matches a SCTP header.
902  */
903 struct rte_flow_item_sctp {
904         struct rte_sctp_hdr hdr; /**< SCTP header definition. */
905 };
906
907 /** Default mask for RTE_FLOW_ITEM_TYPE_SCTP. */
908 #ifndef __cplusplus
909 static const struct rte_flow_item_sctp rte_flow_item_sctp_mask = {
910         .hdr = {
911                 .src_port = RTE_BE16(0xffff),
912                 .dst_port = RTE_BE16(0xffff),
913         },
914 };
915 #endif
916
917 /**
918  * RTE_FLOW_ITEM_TYPE_VXLAN.
919  *
920  * Matches a VXLAN header (RFC 7348).
921  */
922 struct rte_flow_item_vxlan {
923         uint8_t flags; /**< Normally 0x08 (I flag). */
924         uint8_t rsvd0[3]; /**< Reserved, normally 0x000000. */
925         uint8_t vni[3]; /**< VXLAN identifier. */
926         uint8_t rsvd1; /**< Reserved, normally 0x00. */
927 };
928
929 /** Default mask for RTE_FLOW_ITEM_TYPE_VXLAN. */
930 #ifndef __cplusplus
931 static const struct rte_flow_item_vxlan rte_flow_item_vxlan_mask = {
932         .vni = "\xff\xff\xff",
933 };
934 #endif
935
936 /**
937  * RTE_FLOW_ITEM_TYPE_E_TAG.
938  *
939  * Matches a E-tag header.
940  *
941  * The corresponding standard outer EtherType (TPID) value is
942  * RTE_ETHER_TYPE_ETAG. It can be overridden by the preceding pattern item.
943  */
944 struct rte_flow_item_e_tag {
945         /**
946          * E-Tag control information (E-TCI).
947          * E-PCP (3b), E-DEI (1b), ingress E-CID base (12b).
948          */
949         rte_be16_t epcp_edei_in_ecid_b;
950         /** Reserved (2b), GRP (2b), E-CID base (12b). */
951         rte_be16_t rsvd_grp_ecid_b;
952         uint8_t in_ecid_e; /**< Ingress E-CID ext. */
953         uint8_t ecid_e; /**< E-CID ext. */
954         rte_be16_t inner_type; /**< Inner EtherType or TPID. */
955 };
956
957 /** Default mask for RTE_FLOW_ITEM_TYPE_E_TAG. */
958 #ifndef __cplusplus
959 static const struct rte_flow_item_e_tag rte_flow_item_e_tag_mask = {
960         .rsvd_grp_ecid_b = RTE_BE16(0x3fff),
961 };
962 #endif
963
964 /**
965  * RTE_FLOW_ITEM_TYPE_NVGRE.
966  *
967  * Matches a NVGRE header.
968  */
969 struct rte_flow_item_nvgre {
970         /**
971          * Checksum (1b), undefined (1b), key bit (1b), sequence number (1b),
972          * reserved 0 (9b), version (3b).
973          *
974          * c_k_s_rsvd0_ver must have value 0x2000 according to RFC 7637.
975          */
976         rte_be16_t c_k_s_rsvd0_ver;
977         rte_be16_t protocol; /**< Protocol type (0x6558). */
978         uint8_t tni[3]; /**< Virtual subnet ID. */
979         uint8_t flow_id; /**< Flow ID. */
980 };
981
982 /** Default mask for RTE_FLOW_ITEM_TYPE_NVGRE. */
983 #ifndef __cplusplus
984 static const struct rte_flow_item_nvgre rte_flow_item_nvgre_mask = {
985         .tni = "\xff\xff\xff",
986 };
987 #endif
988
989 /**
990  * RTE_FLOW_ITEM_TYPE_MPLS.
991  *
992  * Matches a MPLS header.
993  */
994 struct rte_flow_item_mpls {
995         /**
996          * Label (20b), TC (3b), Bottom of Stack (1b).
997          */
998         uint8_t label_tc_s[3];
999         uint8_t ttl; /** Time-to-Live. */
1000 };
1001
1002 /** Default mask for RTE_FLOW_ITEM_TYPE_MPLS. */
1003 #ifndef __cplusplus
1004 static const struct rte_flow_item_mpls rte_flow_item_mpls_mask = {
1005         .label_tc_s = "\xff\xff\xf0",
1006 };
1007 #endif
1008
1009 /**
1010  * RTE_FLOW_ITEM_TYPE_GRE.
1011  *
1012  * Matches a GRE header.
1013  */
1014 struct rte_flow_item_gre {
1015         /**
1016          * Checksum (1b), reserved 0 (12b), version (3b).
1017          * Refer to RFC 2784.
1018          */
1019         rte_be16_t c_rsvd0_ver;
1020         rte_be16_t protocol; /**< Protocol type. */
1021 };
1022
1023 /** Default mask for RTE_FLOW_ITEM_TYPE_GRE. */
1024 #ifndef __cplusplus
1025 static const struct rte_flow_item_gre rte_flow_item_gre_mask = {
1026         .protocol = RTE_BE16(0xffff),
1027 };
1028 #endif
1029
1030 /**
1031  * RTE_FLOW_ITEM_TYPE_FUZZY
1032  *
1033  * Fuzzy pattern match, expect faster than default.
1034  *
1035  * This is for device that support fuzzy match option.
1036  * Usually a fuzzy match is fast but the cost is accuracy.
1037  * i.e. Signature Match only match pattern's hash value, but it is
1038  * possible two different patterns have the same hash value.
1039  *
1040  * Matching accuracy level can be configure by threshold.
1041  * Driver can divide the range of threshold and map to different
1042  * accuracy levels that device support.
1043  *
1044  * Threshold 0 means perfect match (no fuzziness), while threshold
1045  * 0xffffffff means fuzziest match.
1046  */
1047 struct rte_flow_item_fuzzy {
1048         uint32_t thresh; /**< Accuracy threshold. */
1049 };
1050
1051 /** Default mask for RTE_FLOW_ITEM_TYPE_FUZZY. */
1052 #ifndef __cplusplus
1053 static const struct rte_flow_item_fuzzy rte_flow_item_fuzzy_mask = {
1054         .thresh = 0xffffffff,
1055 };
1056 #endif
1057
1058 /**
1059  * RTE_FLOW_ITEM_TYPE_GTP.
1060  *
1061  * Matches a GTPv1 header.
1062  */
1063 struct rte_flow_item_gtp {
1064         /**
1065          * Version (3b), protocol type (1b), reserved (1b),
1066          * Extension header flag (1b),
1067          * Sequence number flag (1b),
1068          * N-PDU number flag (1b).
1069          */
1070         uint8_t v_pt_rsv_flags;
1071         uint8_t msg_type; /**< Message type. */
1072         rte_be16_t msg_len; /**< Message length. */
1073         rte_be32_t teid; /**< Tunnel endpoint identifier. */
1074 };
1075
1076 /** Default mask for RTE_FLOW_ITEM_TYPE_GTP. */
1077 #ifndef __cplusplus
1078 static const struct rte_flow_item_gtp rte_flow_item_gtp_mask = {
1079         .teid = RTE_BE32(0xffffffff),
1080 };
1081 #endif
1082
1083 /**
1084  * RTE_FLOW_ITEM_TYPE_ESP
1085  *
1086  * Matches an ESP header.
1087  */
1088 struct rte_flow_item_esp {
1089         struct rte_esp_hdr hdr; /**< ESP header definition. */
1090 };
1091
1092 /** Default mask for RTE_FLOW_ITEM_TYPE_ESP. */
1093 #ifndef __cplusplus
1094 static const struct rte_flow_item_esp rte_flow_item_esp_mask = {
1095         .hdr = {
1096                 .spi = RTE_BE32(0xffffffff),
1097         },
1098 };
1099 #endif
1100
1101 /**
1102  * RTE_FLOW_ITEM_TYPE_GENEVE.
1103  *
1104  * Matches a GENEVE header.
1105  */
1106 struct rte_flow_item_geneve {
1107         /**
1108          * Version (2b), length of the options fields (6b), OAM packet (1b),
1109          * critical options present (1b), reserved 0 (6b).
1110          */
1111         rte_be16_t ver_opt_len_o_c_rsvd0;
1112         rte_be16_t protocol; /**< Protocol type. */
1113         uint8_t vni[3]; /**< Virtual Network Identifier. */
1114         uint8_t rsvd1; /**< Reserved, normally 0x00. */
1115 };
1116
1117 /** Default mask for RTE_FLOW_ITEM_TYPE_GENEVE. */
1118 #ifndef __cplusplus
1119 static const struct rte_flow_item_geneve rte_flow_item_geneve_mask = {
1120         .vni = "\xff\xff\xff",
1121 };
1122 #endif
1123
1124 /**
1125  * RTE_FLOW_ITEM_TYPE_VXLAN_GPE (draft-ietf-nvo3-vxlan-gpe-05).
1126  *
1127  * Matches a VXLAN-GPE header.
1128  */
1129 struct rte_flow_item_vxlan_gpe {
1130         uint8_t flags; /**< Normally 0x0c (I and P flags). */
1131         uint8_t rsvd0[2]; /**< Reserved, normally 0x0000. */
1132         uint8_t protocol; /**< Protocol type. */
1133         uint8_t vni[3]; /**< VXLAN identifier. */
1134         uint8_t rsvd1; /**< Reserved, normally 0x00. */
1135 };
1136
1137 /** Default mask for RTE_FLOW_ITEM_TYPE_VXLAN_GPE. */
1138 #ifndef __cplusplus
1139 static const struct rte_flow_item_vxlan_gpe rte_flow_item_vxlan_gpe_mask = {
1140         .vni = "\xff\xff\xff",
1141 };
1142 #endif
1143
1144 /**
1145  * RTE_FLOW_ITEM_TYPE_ARP_ETH_IPV4
1146  *
1147  * Matches an ARP header for Ethernet/IPv4.
1148  */
1149 struct rte_flow_item_arp_eth_ipv4 {
1150         rte_be16_t hrd; /**< Hardware type, normally 1. */
1151         rte_be16_t pro; /**< Protocol type, normally 0x0800. */
1152         uint8_t hln; /**< Hardware address length, normally 6. */
1153         uint8_t pln; /**< Protocol address length, normally 4. */
1154         rte_be16_t op; /**< Opcode (1 for request, 2 for reply). */
1155         struct rte_ether_addr sha; /**< Sender hardware address. */
1156         rte_be32_t spa; /**< Sender IPv4 address. */
1157         struct rte_ether_addr tha; /**< Target hardware address. */
1158         rte_be32_t tpa; /**< Target IPv4 address. */
1159 };
1160
1161 /** Default mask for RTE_FLOW_ITEM_TYPE_ARP_ETH_IPV4. */
1162 #ifndef __cplusplus
1163 static const struct rte_flow_item_arp_eth_ipv4
1164 rte_flow_item_arp_eth_ipv4_mask = {
1165         .sha.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1166         .spa = RTE_BE32(0xffffffff),
1167         .tha.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1168         .tpa = RTE_BE32(0xffffffff),
1169 };
1170 #endif
1171
1172 /**
1173  * RTE_FLOW_ITEM_TYPE_IPV6_EXT
1174  *
1175  * Matches the presence of any IPv6 extension header.
1176  *
1177  * Normally preceded by any of:
1178  *
1179  * - RTE_FLOW_ITEM_TYPE_IPV6
1180  * - RTE_FLOW_ITEM_TYPE_IPV6_EXT
1181  */
1182 struct rte_flow_item_ipv6_ext {
1183         uint8_t next_hdr; /**< Next header. */
1184 };
1185
1186 /** Default mask for RTE_FLOW_ITEM_TYPE_IPV6_EXT. */
1187 #ifndef __cplusplus
1188 static const
1189 struct rte_flow_item_ipv6_ext rte_flow_item_ipv6_ext_mask = {
1190         .next_hdr = 0xff,
1191 };
1192 #endif
1193
1194 /**
1195  * RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT
1196  *
1197  * Matches the presence of IPv6 fragment extension header.
1198  *
1199  * Preceded by any of:
1200  *
1201  * - RTE_FLOW_ITEM_TYPE_IPV6
1202  * - RTE_FLOW_ITEM_TYPE_IPV6_EXT
1203  */
1204 struct rte_flow_item_ipv6_frag_ext {
1205         struct rte_ipv6_fragment_ext hdr;
1206 };
1207
1208 /**
1209  * RTE_FLOW_ITEM_TYPE_ICMP6
1210  *
1211  * Matches any ICMPv6 header.
1212  */
1213 struct rte_flow_item_icmp6 {
1214         uint8_t type; /**< ICMPv6 type. */
1215         uint8_t code; /**< ICMPv6 code. */
1216         uint16_t checksum; /**< ICMPv6 checksum. */
1217 };
1218
1219 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP6. */
1220 #ifndef __cplusplus
1221 static const struct rte_flow_item_icmp6 rte_flow_item_icmp6_mask = {
1222         .type = 0xff,
1223         .code = 0xff,
1224 };
1225 #endif
1226
1227 /**
1228  * RTE_FLOW_ITEM_TYPE_ICMP6_ND_NS
1229  *
1230  * Matches an ICMPv6 neighbor discovery solicitation.
1231  */
1232 struct rte_flow_item_icmp6_nd_ns {
1233         uint8_t type; /**< ICMPv6 type, normally 135. */
1234         uint8_t code; /**< ICMPv6 code, normally 0. */
1235         rte_be16_t checksum; /**< ICMPv6 checksum. */
1236         rte_be32_t reserved; /**< Reserved, normally 0. */
1237         uint8_t target_addr[16]; /**< Target address. */
1238 };
1239
1240 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP6_ND_NS. */
1241 #ifndef __cplusplus
1242 static const
1243 struct rte_flow_item_icmp6_nd_ns rte_flow_item_icmp6_nd_ns_mask = {
1244         .target_addr =
1245                 "\xff\xff\xff\xff\xff\xff\xff\xff"
1246                 "\xff\xff\xff\xff\xff\xff\xff\xff",
1247 };
1248 #endif
1249
1250 /**
1251  * RTE_FLOW_ITEM_TYPE_ICMP6_ND_NA
1252  *
1253  * Matches an ICMPv6 neighbor discovery advertisement.
1254  */
1255 struct rte_flow_item_icmp6_nd_na {
1256         uint8_t type; /**< ICMPv6 type, normally 136. */
1257         uint8_t code; /**< ICMPv6 code, normally 0. */
1258         rte_be16_t checksum; /**< ICMPv6 checksum. */
1259         /**
1260          * Route flag (1b), solicited flag (1b), override flag (1b),
1261          * reserved (29b).
1262          */
1263         rte_be32_t rso_reserved;
1264         uint8_t target_addr[16]; /**< Target address. */
1265 };
1266
1267 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP6_ND_NA. */
1268 #ifndef __cplusplus
1269 static const
1270 struct rte_flow_item_icmp6_nd_na rte_flow_item_icmp6_nd_na_mask = {
1271         .target_addr =
1272                 "\xff\xff\xff\xff\xff\xff\xff\xff"
1273                 "\xff\xff\xff\xff\xff\xff\xff\xff",
1274 };
1275 #endif
1276
1277 /**
1278  * RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT
1279  *
1280  * Matches the presence of any ICMPv6 neighbor discovery option.
1281  *
1282  * Normally preceded by any of:
1283  *
1284  * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_NA
1285  * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_NS
1286  * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT
1287  */
1288 struct rte_flow_item_icmp6_nd_opt {
1289         uint8_t type; /**< ND option type. */
1290         uint8_t length; /**< ND option length. */
1291 };
1292
1293 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT. */
1294 #ifndef __cplusplus
1295 static const struct rte_flow_item_icmp6_nd_opt
1296 rte_flow_item_icmp6_nd_opt_mask = {
1297         .type = 0xff,
1298 };
1299 #endif
1300
1301 /**
1302  * RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT_SLA_ETH
1303  *
1304  * Matches an ICMPv6 neighbor discovery source Ethernet link-layer address
1305  * option.
1306  *
1307  * Normally preceded by any of:
1308  *
1309  * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_NA
1310  * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT
1311  */
1312 struct rte_flow_item_icmp6_nd_opt_sla_eth {
1313         uint8_t type; /**< ND option type, normally 1. */
1314         uint8_t length; /**< ND option length, normally 1. */
1315         struct rte_ether_addr sla; /**< Source Ethernet LLA. */
1316 };
1317
1318 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT_SLA_ETH. */
1319 #ifndef __cplusplus
1320 static const struct rte_flow_item_icmp6_nd_opt_sla_eth
1321 rte_flow_item_icmp6_nd_opt_sla_eth_mask = {
1322         .sla.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1323 };
1324 #endif
1325
1326 /**
1327  * RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT_TLA_ETH
1328  *
1329  * Matches an ICMPv6 neighbor discovery target Ethernet link-layer address
1330  * option.
1331  *
1332  * Normally preceded by any of:
1333  *
1334  * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_NS
1335  * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT
1336  */
1337 struct rte_flow_item_icmp6_nd_opt_tla_eth {
1338         uint8_t type; /**< ND option type, normally 2. */
1339         uint8_t length; /**< ND option length, normally 1. */
1340         struct rte_ether_addr tla; /**< Target Ethernet LLA. */
1341 };
1342
1343 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT_TLA_ETH. */
1344 #ifndef __cplusplus
1345 static const struct rte_flow_item_icmp6_nd_opt_tla_eth
1346 rte_flow_item_icmp6_nd_opt_tla_eth_mask = {
1347         .tla.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1348 };
1349 #endif
1350
1351 /**
1352  * RTE_FLOW_ITEM_TYPE_META
1353  *
1354  * Matches a specified metadata value. On egress, metadata can be set
1355  * either by mbuf dynamic metadata field with PKT_TX_DYNF_METADATA flag or
1356  * RTE_FLOW_ACTION_TYPE_SET_META. On ingress, RTE_FLOW_ACTION_TYPE_SET_META
1357  * sets metadata for a packet and the metadata will be reported via mbuf
1358  * metadata dynamic field with PKT_RX_DYNF_METADATA flag. The dynamic mbuf
1359  * field must be registered in advance by rte_flow_dynf_metadata_register().
1360  */
1361 struct rte_flow_item_meta {
1362         uint32_t data;
1363 };
1364
1365 /** Default mask for RTE_FLOW_ITEM_TYPE_META. */
1366 #ifndef __cplusplus
1367 static const struct rte_flow_item_meta rte_flow_item_meta_mask = {
1368         .data = UINT32_MAX,
1369 };
1370 #endif
1371
1372 /**
1373  * RTE_FLOW_ITEM_TYPE_GTP_PSC.
1374  *
1375  * Matches a GTP PDU extension header with type 0x85.
1376  */
1377 struct rte_flow_item_gtp_psc {
1378         uint8_t pdu_type; /**< PDU type. */
1379         uint8_t qfi; /**< QoS flow identifier. */
1380 };
1381
1382 /** Default mask for RTE_FLOW_ITEM_TYPE_GTP_PSC. */
1383 #ifndef __cplusplus
1384 static const struct rte_flow_item_gtp_psc
1385 rte_flow_item_gtp_psc_mask = {
1386         .qfi = 0x3f,
1387 };
1388 #endif
1389
1390 /**
1391  * RTE_FLOW_ITEM_TYPE_PPPOE.
1392  *
1393  * Matches a PPPoE header.
1394  */
1395 struct rte_flow_item_pppoe {
1396         /**
1397          * Version (4b), type (4b).
1398          */
1399         uint8_t version_type;
1400         uint8_t code; /**< Message type. */
1401         rte_be16_t session_id; /**< Session identifier. */
1402         rte_be16_t length; /**< Payload length. */
1403 };
1404
1405 /**
1406  * RTE_FLOW_ITEM_TYPE_PPPOE_PROTO_ID.
1407  *
1408  * Matches a PPPoE optional proto_id field.
1409  *
1410  * It only applies to PPPoE session packets.
1411  *
1412  * Normally preceded by any of:
1413  *
1414  * - RTE_FLOW_ITEM_TYPE_PPPOE
1415  * - RTE_FLOW_ITEM_TYPE_PPPOE_PROTO_ID
1416  */
1417 struct rte_flow_item_pppoe_proto_id {
1418         rte_be16_t proto_id; /**< PPP protocol identifier. */
1419 };
1420
1421 /** Default mask for RTE_FLOW_ITEM_TYPE_PPPOE_PROTO_ID. */
1422 #ifndef __cplusplus
1423 static const struct rte_flow_item_pppoe_proto_id
1424 rte_flow_item_pppoe_proto_id_mask = {
1425         .proto_id = RTE_BE16(0xffff),
1426 };
1427 #endif
1428
1429 /**
1430  * @warning
1431  * @b EXPERIMENTAL: this structure may change without prior notice
1432  *
1433  * RTE_FLOW_ITEM_TYPE_TAG
1434  *
1435  * Matches a specified tag value at the specified index.
1436  */
1437 struct rte_flow_item_tag {
1438         uint32_t data;
1439         uint8_t index;
1440 };
1441
1442 /** Default mask for RTE_FLOW_ITEM_TYPE_TAG. */
1443 #ifndef __cplusplus
1444 static const struct rte_flow_item_tag rte_flow_item_tag_mask = {
1445         .data = 0xffffffff,
1446         .index = 0xff,
1447 };
1448 #endif
1449
1450 /**
1451  * RTE_FLOW_ITEM_TYPE_L2TPV3OIP.
1452  *
1453  * Matches a L2TPv3 over IP header.
1454  */
1455 struct rte_flow_item_l2tpv3oip {
1456         rte_be32_t session_id; /**< Session ID. */
1457 };
1458
1459 /** Default mask for RTE_FLOW_ITEM_TYPE_L2TPV3OIP. */
1460 #ifndef __cplusplus
1461 static const struct rte_flow_item_l2tpv3oip rte_flow_item_l2tpv3oip_mask = {
1462         .session_id = RTE_BE32(UINT32_MAX),
1463 };
1464 #endif
1465
1466
1467 /**
1468  * @warning
1469  * @b EXPERIMENTAL: this structure may change without prior notice
1470  *
1471  * RTE_FLOW_ITEM_TYPE_MARK
1472  *
1473  * Matches an arbitrary integer value which was set using the ``MARK`` action
1474  * in a previously matched rule.
1475  *
1476  * This item can only be specified once as a match criteria as the ``MARK``
1477  * action can only be specified once in a flow action.
1478  *
1479  * This value is arbitrary and application-defined. Maximum allowed value
1480  * depends on the underlying implementation.
1481  *
1482  * Depending on the underlying implementation the MARK item may be supported on
1483  * the physical device, with virtual groups in the PMD or not at all.
1484  */
1485 struct rte_flow_item_mark {
1486         uint32_t id; /**< Integer value to match against. */
1487 };
1488
1489 /** Default mask for RTE_FLOW_ITEM_TYPE_MARK. */
1490 #ifndef __cplusplus
1491 static const struct rte_flow_item_mark rte_flow_item_mark_mask = {
1492         .id = 0xffffffff,
1493 };
1494 #endif
1495
1496 /**
1497  * @warning
1498  * @b EXPERIMENTAL: this structure may change without prior notice
1499  *
1500  * RTE_FLOW_ITEM_TYPE_NSH
1501  *
1502  * Match network service header (NSH), RFC 8300
1503  *
1504  */
1505 struct rte_flow_item_nsh {
1506         uint32_t version:2;
1507         uint32_t oam_pkt:1;
1508         uint32_t reserved:1;
1509         uint32_t ttl:6;
1510         uint32_t length:6;
1511         uint32_t reserved1:4;
1512         uint32_t mdtype:4;
1513         uint32_t next_proto:8;
1514         uint32_t spi:24;
1515         uint32_t sindex:8;
1516 };
1517
1518 /** Default mask for RTE_FLOW_ITEM_TYPE_NSH. */
1519 #ifndef __cplusplus
1520 static const struct rte_flow_item_nsh rte_flow_item_nsh_mask = {
1521         .mdtype = 0xf,
1522         .next_proto = 0xff,
1523         .spi = 0xffffff,
1524         .sindex = 0xff,
1525 };
1526 #endif
1527
1528 /**
1529  * @warning
1530  * @b EXPERIMENTAL: this structure may change without prior notice
1531  *
1532  * RTE_FLOW_ITEM_TYPE_IGMP
1533  *
1534  * Match Internet Group Management Protocol (IGMP), RFC 2236
1535  *
1536  */
1537 struct rte_flow_item_igmp {
1538         uint32_t type:8;
1539         uint32_t max_resp_time:8;
1540         uint32_t checksum:16;
1541         uint32_t group_addr;
1542 };
1543
1544 /** Default mask for RTE_FLOW_ITEM_TYPE_IGMP. */
1545 #ifndef __cplusplus
1546 static const struct rte_flow_item_igmp rte_flow_item_igmp_mask = {
1547         .group_addr = 0xffffffff,
1548 };
1549 #endif
1550
1551 /**
1552  * @warning
1553  * @b EXPERIMENTAL: this structure may change without prior notice
1554  *
1555  * RTE_FLOW_ITEM_TYPE_AH
1556  *
1557  * Match IP Authentication Header (AH), RFC 4302
1558  *
1559  */
1560 struct rte_flow_item_ah {
1561         uint32_t next_hdr:8;
1562         uint32_t payload_len:8;
1563         uint32_t reserved:16;
1564         uint32_t spi;
1565         uint32_t seq_num;
1566 };
1567
1568 /** Default mask for RTE_FLOW_ITEM_TYPE_AH. */
1569 #ifndef __cplusplus
1570 static const struct rte_flow_item_ah rte_flow_item_ah_mask = {
1571         .spi = 0xffffffff,
1572 };
1573 #endif
1574
1575 /**
1576  * @warning
1577  * @b EXPERIMENTAL: this structure may change without prior notice
1578  *
1579  * RTE_FLOW_ITEM_TYPE_PFCP
1580  *
1581  * Match PFCP Header
1582  */
1583 struct rte_flow_item_pfcp {
1584         uint8_t s_field;
1585         uint8_t msg_type;
1586         rte_be16_t msg_len;
1587         rte_be64_t seid;
1588 };
1589
1590 /** Default mask for RTE_FLOW_ITEM_TYPE_PFCP. */
1591 #ifndef __cplusplus
1592 static const struct rte_flow_item_pfcp rte_flow_item_pfcp_mask = {
1593         .s_field = 0x01,
1594         .seid = RTE_BE64(UINT64_C(0xffffffffffffffff)),
1595 };
1596 #endif
1597
1598 /**
1599  * @warning
1600  * @b EXPERIMENTAL: this structure may change without prior notice
1601  *
1602  * RTE_FLOW_ITEM_TYPE_ECPRI
1603  *
1604  * Match eCPRI Header
1605  */
1606 struct rte_flow_item_ecpri {
1607         struct rte_ecpri_combined_msg_hdr hdr;
1608 };
1609
1610 /** Default mask for RTE_FLOW_ITEM_TYPE_ECPRI. */
1611 #ifndef __cplusplus
1612 static const struct rte_flow_item_ecpri rte_flow_item_ecpri_mask = {
1613         .hdr = {
1614                 .common = {
1615                         .u32 = 0x0,
1616                 },
1617         },
1618 };
1619 #endif
1620
1621 /**
1622  * Matching pattern item definition.
1623  *
1624  * A pattern is formed by stacking items starting from the lowest protocol
1625  * layer to match. This stacking restriction does not apply to meta items
1626  * which can be placed anywhere in the stack without affecting the meaning
1627  * of the resulting pattern.
1628  *
1629  * Patterns are terminated by END items.
1630  *
1631  * The spec field should be a valid pointer to a structure of the related
1632  * item type. It may remain unspecified (NULL) in many cases to request
1633  * broad (nonspecific) matching. In such cases, last and mask must also be
1634  * set to NULL.
1635  *
1636  * Optionally, last can point to a structure of the same type to define an
1637  * inclusive range. This is mostly supported by integer and address fields,
1638  * may cause errors otherwise. Fields that do not support ranges must be set
1639  * to 0 or to the same value as the corresponding fields in spec.
1640  *
1641  * Only the fields defined to nonzero values in the default masks (see
1642  * rte_flow_item_{name}_mask constants) are considered relevant by
1643  * default. This can be overridden by providing a mask structure of the
1644  * same type with applicable bits set to one. It can also be used to
1645  * partially filter out specific fields (e.g. as an alternate mean to match
1646  * ranges of IP addresses).
1647  *
1648  * Mask is a simple bit-mask applied before interpreting the contents of
1649  * spec and last, which may yield unexpected results if not used
1650  * carefully. For example, if for an IPv4 address field, spec provides
1651  * 10.1.2.3, last provides 10.3.4.5 and mask provides 255.255.0.0, the
1652  * effective range becomes 10.1.0.0 to 10.3.255.255.
1653  */
1654 struct rte_flow_item {
1655         enum rte_flow_item_type type; /**< Item type. */
1656         const void *spec; /**< Pointer to item specification structure. */
1657         const void *last; /**< Defines an inclusive range (spec to last). */
1658         const void *mask; /**< Bit-mask applied to spec and last. */
1659 };
1660
1661 /**
1662  * Action types.
1663  *
1664  * Each possible action is represented by a type.
1665  * An action can have an associated configuration object.
1666  * Several actions combined in a list can be assigned
1667  * to a flow rule and are performed in order.
1668  *
1669  * They fall in three categories:
1670  *
1671  * - Actions that modify the fate of matching traffic, for instance by
1672  *   dropping or assigning it a specific destination.
1673  *
1674  * - Actions that modify matching traffic contents or its properties. This
1675  *   includes adding/removing encapsulation, encryption, compression and
1676  *   marks.
1677  *
1678  * - Actions related to the flow rule itself, such as updating counters or
1679  *   making it non-terminating.
1680  *
1681  * Flow rules being terminating by default, not specifying any action of the
1682  * fate kind results in undefined behavior. This applies to both ingress and
1683  * egress.
1684  *
1685  * PASSTHRU, when supported, makes a flow rule non-terminating.
1686  */
1687 enum rte_flow_action_type {
1688         /**
1689          * End marker for action lists. Prevents further processing of
1690          * actions, thereby ending the list.
1691          *
1692          * No associated configuration structure.
1693          */
1694         RTE_FLOW_ACTION_TYPE_END,
1695
1696         /**
1697          * Used as a placeholder for convenience. It is ignored and simply
1698          * discarded by PMDs.
1699          *
1700          * No associated configuration structure.
1701          */
1702         RTE_FLOW_ACTION_TYPE_VOID,
1703
1704         /**
1705          * Leaves traffic up for additional processing by subsequent flow
1706          * rules; makes a flow rule non-terminating.
1707          *
1708          * No associated configuration structure.
1709          */
1710         RTE_FLOW_ACTION_TYPE_PASSTHRU,
1711
1712         /**
1713          * RTE_FLOW_ACTION_TYPE_JUMP
1714          *
1715          * Redirects packets to a group on the current device.
1716          *
1717          * See struct rte_flow_action_jump.
1718          */
1719         RTE_FLOW_ACTION_TYPE_JUMP,
1720
1721         /**
1722          * Attaches an integer value to packets and sets PKT_RX_FDIR and
1723          * PKT_RX_FDIR_ID mbuf flags.
1724          *
1725          * See struct rte_flow_action_mark.
1726          */
1727         RTE_FLOW_ACTION_TYPE_MARK,
1728
1729         /**
1730          * Flags packets. Similar to MARK without a specific value; only
1731          * sets the PKT_RX_FDIR mbuf flag.
1732          *
1733          * No associated configuration structure.
1734          */
1735         RTE_FLOW_ACTION_TYPE_FLAG,
1736
1737         /**
1738          * Assigns packets to a given queue index.
1739          *
1740          * See struct rte_flow_action_queue.
1741          */
1742         RTE_FLOW_ACTION_TYPE_QUEUE,
1743
1744         /**
1745          * Drops packets.
1746          *
1747          * PASSTHRU overrides this action if both are specified.
1748          *
1749          * No associated configuration structure.
1750          */
1751         RTE_FLOW_ACTION_TYPE_DROP,
1752
1753         /**
1754          * Enables counters for this flow rule.
1755          *
1756          * These counters can be retrieved and reset through rte_flow_query() or
1757          * rte_flow_shared_action_query() if the action provided via handle,
1758          * see struct rte_flow_query_count.
1759          *
1760          * See struct rte_flow_action_count.
1761          */
1762         RTE_FLOW_ACTION_TYPE_COUNT,
1763
1764         /**
1765          * Similar to QUEUE, except RSS is additionally performed on packets
1766          * to spread them among several queues according to the provided
1767          * parameters.
1768          *
1769          * See struct rte_flow_action_rss.
1770          */
1771         RTE_FLOW_ACTION_TYPE_RSS,
1772
1773         /**
1774          * Directs matching traffic to the physical function (PF) of the
1775          * current device.
1776          *
1777          * No associated configuration structure.
1778          */
1779         RTE_FLOW_ACTION_TYPE_PF,
1780
1781         /**
1782          * Directs matching traffic to a given virtual function of the
1783          * current device.
1784          *
1785          * See struct rte_flow_action_vf.
1786          */
1787         RTE_FLOW_ACTION_TYPE_VF,
1788
1789         /**
1790          * Directs packets to a given physical port index of the underlying
1791          * device.
1792          *
1793          * See struct rte_flow_action_phy_port.
1794          */
1795         RTE_FLOW_ACTION_TYPE_PHY_PORT,
1796
1797         /**
1798          * Directs matching traffic to a given DPDK port ID.
1799          *
1800          * See struct rte_flow_action_port_id.
1801          */
1802         RTE_FLOW_ACTION_TYPE_PORT_ID,
1803
1804         /**
1805          * Traffic metering and policing (MTR).
1806          *
1807          * See struct rte_flow_action_meter.
1808          * See file rte_mtr.h for MTR object configuration.
1809          */
1810         RTE_FLOW_ACTION_TYPE_METER,
1811
1812         /**
1813          * Redirects packets to security engine of current device for security
1814          * processing as specified by security session.
1815          *
1816          * See struct rte_flow_action_security.
1817          */
1818         RTE_FLOW_ACTION_TYPE_SECURITY,
1819
1820         /**
1821          * Implements OFPAT_SET_MPLS_TTL ("MPLS TTL") as defined by the
1822          * OpenFlow Switch Specification.
1823          *
1824          * See struct rte_flow_action_of_set_mpls_ttl.
1825          */
1826         RTE_FLOW_ACTION_TYPE_OF_SET_MPLS_TTL,
1827
1828         /**
1829          * Implements OFPAT_DEC_MPLS_TTL ("decrement MPLS TTL") as defined
1830          * by the OpenFlow Switch Specification.
1831          *
1832          * No associated configuration structure.
1833          */
1834         RTE_FLOW_ACTION_TYPE_OF_DEC_MPLS_TTL,
1835
1836         /**
1837          * Implements OFPAT_SET_NW_TTL ("IP TTL") as defined by the OpenFlow
1838          * Switch Specification.
1839          *
1840          * See struct rte_flow_action_of_set_nw_ttl.
1841          */
1842         RTE_FLOW_ACTION_TYPE_OF_SET_NW_TTL,
1843
1844         /**
1845          * Implements OFPAT_DEC_NW_TTL ("decrement IP TTL") as defined by
1846          * the OpenFlow Switch Specification.
1847          *
1848          * No associated configuration structure.
1849          */
1850         RTE_FLOW_ACTION_TYPE_OF_DEC_NW_TTL,
1851
1852         /**
1853          * Implements OFPAT_COPY_TTL_OUT ("copy TTL "outwards" -- from
1854          * next-to-outermost to outermost") as defined by the OpenFlow
1855          * Switch Specification.
1856          *
1857          * No associated configuration structure.
1858          */
1859         RTE_FLOW_ACTION_TYPE_OF_COPY_TTL_OUT,
1860
1861         /**
1862          * Implements OFPAT_COPY_TTL_IN ("copy TTL "inwards" -- from
1863          * outermost to next-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_IN,
1869
1870         /**
1871          * Implements OFPAT_POP_VLAN ("pop the outer VLAN tag") as defined
1872          * by the OpenFlow Switch Specification.
1873          *
1874          * No associated configuration structure.
1875          */
1876         RTE_FLOW_ACTION_TYPE_OF_POP_VLAN,
1877
1878         /**
1879          * Implements OFPAT_PUSH_VLAN ("push a new VLAN tag") as defined by
1880          * the OpenFlow Switch Specification.
1881          *
1882          * See struct rte_flow_action_of_push_vlan.
1883          */
1884         RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN,
1885
1886         /**
1887          * Implements OFPAT_SET_VLAN_VID ("set the 802.1q VLAN id") as
1888          * defined by the OpenFlow Switch Specification.
1889          *
1890          * See struct rte_flow_action_of_set_vlan_vid.
1891          */
1892         RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID,
1893
1894         /**
1895          * Implements OFPAT_SET_LAN_PCP ("set the 802.1q priority") as
1896          * defined by the OpenFlow Switch Specification.
1897          *
1898          * See struct rte_flow_action_of_set_vlan_pcp.
1899          */
1900         RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP,
1901
1902         /**
1903          * Implements OFPAT_POP_MPLS ("pop the outer MPLS tag") as defined
1904          * by the OpenFlow Switch Specification.
1905          *
1906          * See struct rte_flow_action_of_pop_mpls.
1907          */
1908         RTE_FLOW_ACTION_TYPE_OF_POP_MPLS,
1909
1910         /**
1911          * Implements OFPAT_PUSH_MPLS ("push a new MPLS tag") as defined by
1912          * the OpenFlow Switch Specification.
1913          *
1914          * See struct rte_flow_action_of_push_mpls.
1915          */
1916         RTE_FLOW_ACTION_TYPE_OF_PUSH_MPLS,
1917
1918         /**
1919          * Encapsulate flow in VXLAN tunnel as defined in
1920          * rte_flow_action_vxlan_encap action structure.
1921          *
1922          * See struct rte_flow_action_vxlan_encap.
1923          */
1924         RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP,
1925
1926         /**
1927          * Decapsulate outer most VXLAN tunnel from matched flow.
1928          *
1929          * If flow pattern does not define a valid VXLAN tunnel (as specified by
1930          * RFC7348) then the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION
1931          * error.
1932          */
1933         RTE_FLOW_ACTION_TYPE_VXLAN_DECAP,
1934
1935         /**
1936          * Encapsulate flow in NVGRE tunnel defined in the
1937          * rte_flow_action_nvgre_encap action structure.
1938          *
1939          * See struct rte_flow_action_nvgre_encap.
1940          */
1941         RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP,
1942
1943         /**
1944          * Decapsulate outer most NVGRE tunnel from matched flow.
1945          *
1946          * If flow pattern does not define a valid NVGRE tunnel (as specified by
1947          * RFC7637) then the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION
1948          * error.
1949          */
1950         RTE_FLOW_ACTION_TYPE_NVGRE_DECAP,
1951
1952         /**
1953          * Add outer header whose template is provided in its data buffer
1954          *
1955          * See struct rte_flow_action_raw_encap.
1956          */
1957         RTE_FLOW_ACTION_TYPE_RAW_ENCAP,
1958
1959         /**
1960          * Remove outer header whose template is provided in its data buffer.
1961          *
1962          * See struct rte_flow_action_raw_decap
1963          */
1964         RTE_FLOW_ACTION_TYPE_RAW_DECAP,
1965
1966         /**
1967          * Modify IPv4 source address in the outermost IPv4 header.
1968          *
1969          * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_IPV4,
1970          * then the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION error.
1971          *
1972          * See struct rte_flow_action_set_ipv4.
1973          */
1974         RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC,
1975
1976         /**
1977          * Modify IPv4 destination address in the outermost IPv4 header.
1978          *
1979          * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_IPV4,
1980          * then the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION error.
1981          *
1982          * See struct rte_flow_action_set_ipv4.
1983          */
1984         RTE_FLOW_ACTION_TYPE_SET_IPV4_DST,
1985
1986         /**
1987          * Modify IPv6 source address in the outermost IPv6 header.
1988          *
1989          * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_IPV6,
1990          * then the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION error.
1991          *
1992          * See struct rte_flow_action_set_ipv6.
1993          */
1994         RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC,
1995
1996         /**
1997          * Modify IPv6 destination address in the outermost IPv6 header.
1998          *
1999          * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_IPV6,
2000          * then the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION error.
2001          *
2002          * See struct rte_flow_action_set_ipv6.
2003          */
2004         RTE_FLOW_ACTION_TYPE_SET_IPV6_DST,
2005
2006         /**
2007          * Modify source port number in the outermost TCP/UDP header.
2008          *
2009          * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_TCP
2010          * or RTE_FLOW_ITEM_TYPE_UDP, then the PMD should return a
2011          * RTE_FLOW_ERROR_TYPE_ACTION error.
2012          *
2013          * See struct rte_flow_action_set_tp.
2014          */
2015         RTE_FLOW_ACTION_TYPE_SET_TP_SRC,
2016
2017         /**
2018          * Modify destination port number in the outermost TCP/UDP header.
2019          *
2020          * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_TCP
2021          * or RTE_FLOW_ITEM_TYPE_UDP, then the PMD should return a
2022          * RTE_FLOW_ERROR_TYPE_ACTION error.
2023          *
2024          * See struct rte_flow_action_set_tp.
2025          */
2026         RTE_FLOW_ACTION_TYPE_SET_TP_DST,
2027
2028         /**
2029          * Swap the source and destination MAC addresses in the outermost
2030          * Ethernet header.
2031          *
2032          * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_ETH,
2033          * then the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION error.
2034          *
2035          * No associated configuration structure.
2036          */
2037         RTE_FLOW_ACTION_TYPE_MAC_SWAP,
2038
2039         /**
2040          * Decrease TTL value directly
2041          *
2042          * No associated configuration structure.
2043          */
2044         RTE_FLOW_ACTION_TYPE_DEC_TTL,
2045
2046         /**
2047          * Set TTL value
2048          *
2049          * See struct rte_flow_action_set_ttl
2050          */
2051         RTE_FLOW_ACTION_TYPE_SET_TTL,
2052
2053         /**
2054          * Set source MAC address from matched flow.
2055          *
2056          * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_ETH,
2057          * the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION error.
2058          *
2059          * See struct rte_flow_action_set_mac.
2060          */
2061         RTE_FLOW_ACTION_TYPE_SET_MAC_SRC,
2062
2063         /**
2064          * Set destination MAC address from matched flow.
2065          *
2066          * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_ETH,
2067          * the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION error.
2068          *
2069          * See struct rte_flow_action_set_mac.
2070          */
2071         RTE_FLOW_ACTION_TYPE_SET_MAC_DST,
2072
2073         /**
2074          * Increase sequence number in the outermost TCP header.
2075          *
2076          * Action configuration specifies the value to increase
2077          * TCP sequence number as a big-endian 32 bit integer.
2078          *
2079          * @p conf type:
2080          * @code rte_be32_t * @endcode
2081          *
2082          * Using this action on non-matching traffic will result in
2083          * undefined behavior.
2084          */
2085         RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ,
2086
2087         /**
2088          * Decrease sequence number in the outermost TCP header.
2089          *
2090          * Action configuration specifies the value to decrease
2091          * TCP sequence number as a big-endian 32 bit integer.
2092          *
2093          * @p conf type:
2094          * @code rte_be32_t * @endcode
2095          *
2096          * Using this action on non-matching traffic will result in
2097          * undefined behavior.
2098          */
2099         RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ,
2100
2101         /**
2102          * Increase acknowledgment number in the outermost TCP header.
2103          *
2104          * Action configuration specifies the value to increase
2105          * TCP acknowledgment number as a big-endian 32 bit integer.
2106          *
2107          * @p conf type:
2108          * @code rte_be32_t * @endcode
2109
2110          * Using this action on non-matching traffic will result in
2111          * undefined behavior.
2112          */
2113         RTE_FLOW_ACTION_TYPE_INC_TCP_ACK,
2114
2115         /**
2116          * Decrease acknowledgment number in the outermost TCP header.
2117          *
2118          * Action configuration specifies the value to decrease
2119          * TCP acknowledgment number as a big-endian 32 bit integer.
2120          *
2121          * @p conf type:
2122          * @code rte_be32_t * @endcode
2123          *
2124          * Using this action on non-matching traffic will result in
2125          * undefined behavior.
2126          */
2127         RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK,
2128
2129         /**
2130          * Set Tag.
2131          *
2132          * Tag is for internal flow usage only and
2133          * is not delivered to the application.
2134          *
2135          * See struct rte_flow_action_set_tag.
2136          */
2137         RTE_FLOW_ACTION_TYPE_SET_TAG,
2138
2139         /**
2140          * Set metadata on ingress or egress path.
2141          *
2142          * See struct rte_flow_action_set_meta.
2143          */
2144         RTE_FLOW_ACTION_TYPE_SET_META,
2145
2146         /**
2147          * Modify IPv4 DSCP in the outermost IP header.
2148          *
2149          * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_IPV4,
2150          * then the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION error.
2151          *
2152          * See struct rte_flow_action_set_dscp.
2153          */
2154         RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP,
2155
2156         /**
2157          * Modify IPv6 DSCP in the outermost IP header.
2158          *
2159          * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_IPV6,
2160          * then the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION error.
2161          *
2162          * See struct rte_flow_action_set_dscp.
2163          */
2164         RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP,
2165
2166         /**
2167          * Report as aged flow if timeout passed without any matching on the
2168          * flow.
2169          *
2170          * See struct rte_flow_action_age.
2171          * See function rte_flow_get_aged_flows
2172          * see enum RTE_ETH_EVENT_FLOW_AGED
2173          * See struct rte_flow_query_age
2174          */
2175         RTE_FLOW_ACTION_TYPE_AGE,
2176
2177         /**
2178          * The matching packets will be duplicated with specified ratio and
2179          * applied with own set of actions with a fate action.
2180          *
2181          * See struct rte_flow_action_sample.
2182          */
2183         RTE_FLOW_ACTION_TYPE_SAMPLE,
2184
2185         /**
2186          * Describe action shared across multiple flow rules.
2187          *
2188          * Allow multiple rules reference the same action by handle (see
2189          * struct rte_flow_shared_action).
2190          */
2191         RTE_FLOW_ACTION_TYPE_SHARED,
2192 };
2193
2194 /**
2195  * RTE_FLOW_ACTION_TYPE_MARK
2196  *
2197  * Attaches an integer value to packets and sets PKT_RX_FDIR and
2198  * PKT_RX_FDIR_ID mbuf flags.
2199  *
2200  * This value is arbitrary and application-defined. Maximum allowed value
2201  * depends on the underlying implementation. It is returned in the
2202  * hash.fdir.hi mbuf field.
2203  */
2204 struct rte_flow_action_mark {
2205         uint32_t id; /**< Integer value to return with packets. */
2206 };
2207
2208 /**
2209  * @warning
2210  * @b EXPERIMENTAL: this structure may change without prior notice
2211  *
2212  * RTE_FLOW_ACTION_TYPE_JUMP
2213  *
2214  * Redirects packets to a group on the current device.
2215  *
2216  * In a hierarchy of groups, which can be used to represent physical or logical
2217  * flow tables on the device, this action allows the action to be a redirect to
2218  * a group on that device.
2219  */
2220 struct rte_flow_action_jump {
2221         uint32_t group;
2222 };
2223
2224 /**
2225  * RTE_FLOW_ACTION_TYPE_QUEUE
2226  *
2227  * Assign packets to a given queue index.
2228  */
2229 struct rte_flow_action_queue {
2230         uint16_t index; /**< Queue index to use. */
2231 };
2232
2233 /**
2234  * @warning
2235  * @b EXPERIMENTAL: this structure may change without prior notice
2236  *
2237  * RTE_FLOW_ACTION_TYPE_AGE
2238  *
2239  * Report flow as aged-out if timeout passed without any matching
2240  * on the flow. RTE_ETH_EVENT_FLOW_AGED event is triggered when a
2241  * port detects new aged-out flows.
2242  *
2243  * The flow context and the flow handle will be reported by the
2244  * rte_flow_get_aged_flows API.
2245  */
2246 struct rte_flow_action_age {
2247         uint32_t timeout:24; /**< Time in seconds. */
2248         uint32_t reserved:8; /**< Reserved, must be zero. */
2249         void *context;
2250                 /**< The user flow context, NULL means the rte_flow pointer. */
2251 };
2252
2253 /**
2254  * RTE_FLOW_ACTION_TYPE_AGE (query)
2255  *
2256  * Query structure to retrieve the aging status information of a
2257  * shared AGE action, or a flow rule using the AGE action.
2258  */
2259 struct rte_flow_query_age {
2260         uint32_t reserved:6; /**< Reserved, must be zero. */
2261         uint32_t aged:1; /**< 1 if aging timeout expired, 0 otherwise. */
2262         uint32_t sec_since_last_hit_valid:1;
2263         /**< sec_since_last_hit value is valid. */
2264         uint32_t sec_since_last_hit:24; /**< Seconds since last traffic hit. */
2265 };
2266
2267 /**
2268  * @warning
2269  * @b EXPERIMENTAL: this structure may change without prior notice
2270  *
2271  * RTE_FLOW_ACTION_TYPE_COUNT
2272  *
2273  * Adds a counter action to a matched flow.
2274  *
2275  * If more than one count action is specified in a single flow rule, then each
2276  * action must specify a unique id.
2277  *
2278  * Counters can be retrieved and reset through ``rte_flow_query()``, see
2279  * ``struct rte_flow_query_count``.
2280  *
2281  * The shared flag indicates whether the counter is unique to the flow rule the
2282  * action is specified with, or whether it is a shared counter.
2283  *
2284  * For a count action with the shared flag set, then then a global device
2285  * namespace is assumed for the counter id, so that any matched flow rules using
2286  * a count action with the same counter id on the same port will contribute to
2287  * that counter.
2288  *
2289  * For ports within the same switch domain then the counter id namespace extends
2290  * to all ports within that switch domain.
2291  */
2292 struct rte_flow_action_count {
2293         uint32_t shared:1; /**< Share counter ID with other flow rules. */
2294         uint32_t reserved:31; /**< Reserved, must be zero. */
2295         uint32_t id; /**< Counter ID. */
2296 };
2297
2298 /**
2299  * RTE_FLOW_ACTION_TYPE_COUNT (query)
2300  *
2301  * Query structure to retrieve and reset flow rule counters.
2302  */
2303 struct rte_flow_query_count {
2304         uint32_t reset:1; /**< Reset counters after query [in]. */
2305         uint32_t hits_set:1; /**< hits field is set [out]. */
2306         uint32_t bytes_set:1; /**< bytes field is set [out]. */
2307         uint32_t reserved:29; /**< Reserved, must be zero [in, out]. */
2308         uint64_t hits; /**< Number of hits for this rule [out]. */
2309         uint64_t bytes; /**< Number of bytes through this rule [out]. */
2310 };
2311
2312 /**
2313  * Hash function types.
2314  */
2315 enum rte_eth_hash_function {
2316         RTE_ETH_HASH_FUNCTION_DEFAULT = 0,
2317         RTE_ETH_HASH_FUNCTION_TOEPLITZ, /**< Toeplitz */
2318         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR, /**< Simple XOR */
2319         /**
2320          * Symmetric Toeplitz: src, dst will be replaced by
2321          * xor(src, dst). For the case with src/dst only,
2322          * src or dst address will xor with zero pair.
2323          */
2324         RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ,
2325         RTE_ETH_HASH_FUNCTION_MAX,
2326 };
2327
2328 /**
2329  * RTE_FLOW_ACTION_TYPE_RSS
2330  *
2331  * Similar to QUEUE, except RSS is additionally performed on packets to
2332  * spread them among several queues according to the provided parameters.
2333  *
2334  * Unlike global RSS settings used by other DPDK APIs, unsetting the
2335  * @p types field does not disable RSS in a flow rule. Doing so instead
2336  * requests safe unspecified "best-effort" settings from the underlying PMD,
2337  * which depending on the flow rule, may result in anything ranging from
2338  * empty (single queue) to all-inclusive RSS.
2339  *
2340  * Note: RSS hash result is stored in the hash.rss mbuf field which overlaps
2341  * hash.fdir.lo. Since the MARK action sets the hash.fdir.hi field only,
2342  * both can be requested simultaneously.
2343  */
2344 struct rte_flow_action_rss {
2345         enum rte_eth_hash_function func; /**< RSS hash function to apply. */
2346         /**
2347          * Packet encapsulation level RSS hash @p types apply to.
2348          *
2349          * - @p 0 requests the default behavior. Depending on the packet
2350          *   type, it can mean outermost, innermost, anything in between or
2351          *   even no RSS.
2352          *
2353          *   It basically stands for the innermost encapsulation level RSS
2354          *   can be performed on according to PMD and device capabilities.
2355          *
2356          * - @p 1 requests RSS to be performed on the outermost packet
2357          *   encapsulation level.
2358          *
2359          * - @p 2 and subsequent values request RSS to be performed on the
2360          *   specified inner packet encapsulation level, from outermost to
2361          *   innermost (lower to higher values).
2362          *
2363          * Values other than @p 0 are not necessarily supported.
2364          *
2365          * Requesting a specific RSS level on unrecognized traffic results
2366          * in undefined behavior. For predictable results, it is recommended
2367          * to make the flow rule pattern match packet headers up to the
2368          * requested encapsulation level so that only matching traffic goes
2369          * through.
2370          */
2371         uint32_t level;
2372         uint64_t types; /**< Specific RSS hash types (see ETH_RSS_*). */
2373         uint32_t key_len; /**< Hash key length in bytes. */
2374         uint32_t queue_num; /**< Number of entries in @p queue. */
2375         const uint8_t *key; /**< Hash key. */
2376         const uint16_t *queue; /**< Queue indices to use. */
2377 };
2378
2379 /**
2380  * RTE_FLOW_ACTION_TYPE_VF
2381  *
2382  * Directs matching traffic to a given virtual function of the current
2383  * device.
2384  *
2385  * Packets matched by a VF pattern item can be redirected to their original
2386  * VF ID instead of the specified one. This parameter may not be available
2387  * and is not guaranteed to work properly if the VF part is matched by a
2388  * prior flow rule or if packets are not addressed to a VF in the first
2389  * place.
2390  */
2391 struct rte_flow_action_vf {
2392         uint32_t original:1; /**< Use original VF ID if possible. */
2393         uint32_t reserved:31; /**< Reserved, must be zero. */
2394         uint32_t id; /**< VF ID. */
2395 };
2396
2397 /**
2398  * RTE_FLOW_ACTION_TYPE_PHY_PORT
2399  *
2400  * Directs packets to a given physical port index of the underlying
2401  * device.
2402  *
2403  * @see RTE_FLOW_ITEM_TYPE_PHY_PORT
2404  */
2405 struct rte_flow_action_phy_port {
2406         uint32_t original:1; /**< Use original port index if possible. */
2407         uint32_t reserved:31; /**< Reserved, must be zero. */
2408         uint32_t index; /**< Physical port index. */
2409 };
2410
2411 /**
2412  * RTE_FLOW_ACTION_TYPE_PORT_ID
2413  *
2414  * Directs matching traffic to a given DPDK port ID.
2415  *
2416  * @see RTE_FLOW_ITEM_TYPE_PORT_ID
2417  */
2418 struct rte_flow_action_port_id {
2419         uint32_t original:1; /**< Use original DPDK port ID if possible. */
2420         uint32_t reserved:31; /**< Reserved, must be zero. */
2421         uint32_t id; /**< DPDK port ID. */
2422 };
2423
2424 /**
2425  * RTE_FLOW_ACTION_TYPE_METER
2426  *
2427  * Traffic metering and policing (MTR).
2428  *
2429  * Packets matched by items of this type can be either dropped or passed to the
2430  * next item with their color set by the MTR object.
2431  */
2432 struct rte_flow_action_meter {
2433         uint32_t mtr_id; /**< MTR object ID created with rte_mtr_create(). */
2434 };
2435
2436 /**
2437  * RTE_FLOW_ACTION_TYPE_SECURITY
2438  *
2439  * Perform the security action on flows matched by the pattern items
2440  * according to the configuration of the security session.
2441  *
2442  * This action modifies the payload of matched flows. For INLINE_CRYPTO, the
2443  * security protocol headers and IV are fully provided by the application as
2444  * specified in the flow pattern. The payload of matching packets is
2445  * encrypted on egress, and decrypted and authenticated on ingress.
2446  * For INLINE_PROTOCOL, the security protocol is fully offloaded to HW,
2447  * providing full encapsulation and decapsulation of packets in security
2448  * protocols. The flow pattern specifies both the outer security header fields
2449  * and the inner packet fields. The security session specified in the action
2450  * must match the pattern parameters.
2451  *
2452  * The security session specified in the action must be created on the same
2453  * port as the flow action that is being specified.
2454  *
2455  * The ingress/egress flow attribute should match that specified in the
2456  * security session if the security session supports the definition of the
2457  * direction.
2458  *
2459  * Multiple flows can be configured to use the same security session.
2460  *
2461  * The NULL value is allowed for security session. If security session is NULL,
2462  * then SPI field in ESP flow item and IP addresses in flow items 'IPv4' and
2463  * 'IPv6' will be allowed to be a range. The rule thus created can enable
2464  * security processing on multiple flows.
2465  */
2466 struct rte_flow_action_security {
2467         void *security_session; /**< Pointer to security session structure. */
2468 };
2469
2470 /**
2471  * RTE_FLOW_ACTION_TYPE_OF_SET_MPLS_TTL
2472  *
2473  * Implements OFPAT_SET_MPLS_TTL ("MPLS TTL") as defined by the OpenFlow
2474  * Switch Specification.
2475  */
2476 struct rte_flow_action_of_set_mpls_ttl {
2477         uint8_t mpls_ttl; /**< MPLS TTL. */
2478 };
2479
2480 /**
2481  * RTE_FLOW_ACTION_TYPE_OF_SET_NW_TTL
2482  *
2483  * Implements OFPAT_SET_NW_TTL ("IP TTL") as defined by the OpenFlow Switch
2484  * Specification.
2485  */
2486 struct rte_flow_action_of_set_nw_ttl {
2487         uint8_t nw_ttl; /**< IP TTL. */
2488 };
2489
2490 /**
2491  * RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN
2492  *
2493  * Implements OFPAT_PUSH_VLAN ("push a new VLAN tag") as defined by the
2494  * OpenFlow Switch Specification.
2495  */
2496 struct rte_flow_action_of_push_vlan {
2497         rte_be16_t ethertype; /**< EtherType. */
2498 };
2499
2500 /**
2501  * RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID
2502  *
2503  * Implements OFPAT_SET_VLAN_VID ("set the 802.1q VLAN id") as defined by
2504  * the OpenFlow Switch Specification.
2505  */
2506 struct rte_flow_action_of_set_vlan_vid {
2507         rte_be16_t vlan_vid; /**< VLAN id. */
2508 };
2509
2510 /**
2511  * RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP
2512  *
2513  * Implements OFPAT_SET_LAN_PCP ("set the 802.1q priority") as defined by
2514  * the OpenFlow Switch Specification.
2515  */
2516 struct rte_flow_action_of_set_vlan_pcp {
2517         uint8_t vlan_pcp; /**< VLAN priority. */
2518 };
2519
2520 /**
2521  * RTE_FLOW_ACTION_TYPE_OF_POP_MPLS
2522  *
2523  * Implements OFPAT_POP_MPLS ("pop the outer MPLS tag") as defined by the
2524  * OpenFlow Switch Specification.
2525  */
2526 struct rte_flow_action_of_pop_mpls {
2527         rte_be16_t ethertype; /**< EtherType. */
2528 };
2529
2530 /**
2531  * RTE_FLOW_ACTION_TYPE_OF_PUSH_MPLS
2532  *
2533  * Implements OFPAT_PUSH_MPLS ("push a new MPLS tag") as defined by the
2534  * OpenFlow Switch Specification.
2535  */
2536 struct rte_flow_action_of_push_mpls {
2537         rte_be16_t ethertype; /**< EtherType. */
2538 };
2539
2540 /**
2541  * @warning
2542  * @b EXPERIMENTAL: this structure may change without prior notice
2543  *
2544  * RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP
2545  *
2546  * VXLAN tunnel end-point encapsulation data definition
2547  *
2548  * The tunnel definition is provided through the flow item pattern, the
2549  * provided pattern must conform to RFC7348 for the tunnel specified. The flow
2550  * definition must be provided in order from the RTE_FLOW_ITEM_TYPE_ETH
2551  * definition up the end item which is specified by RTE_FLOW_ITEM_TYPE_END.
2552  *
2553  * The mask field allows user to specify which fields in the flow item
2554  * definitions can be ignored and which have valid data and can be used
2555  * verbatim.
2556  *
2557  * Note: the last field is not used in the definition of a tunnel and can be
2558  * ignored.
2559  *
2560  * Valid flow definition for RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP include:
2561  *
2562  * - ETH / IPV4 / UDP / VXLAN / END
2563  * - ETH / IPV6 / UDP / VXLAN / END
2564  * - ETH / VLAN / IPV4 / UDP / VXLAN / END
2565  *
2566  */
2567 struct rte_flow_action_vxlan_encap {
2568         /**
2569          * Encapsulating vxlan tunnel definition
2570          * (terminated by the END pattern item).
2571          */
2572         struct rte_flow_item *definition;
2573 };
2574
2575 /**
2576  * @warning
2577  * @b EXPERIMENTAL: this structure may change without prior notice
2578  *
2579  * RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP
2580  *
2581  * NVGRE tunnel end-point encapsulation data definition
2582  *
2583  * The tunnel definition is provided through the flow item pattern  the
2584  * provided pattern must conform with RFC7637. The flow definition must be
2585  * provided in order from the RTE_FLOW_ITEM_TYPE_ETH definition up the end item
2586  * which is specified by RTE_FLOW_ITEM_TYPE_END.
2587  *
2588  * The mask field allows user to specify which fields in the flow item
2589  * definitions can be ignored and which have valid data and can be used
2590  * verbatim.
2591  *
2592  * Note: the last field is not used in the definition of a tunnel and can be
2593  * ignored.
2594  *
2595  * Valid flow definition for RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP include:
2596  *
2597  * - ETH / IPV4 / NVGRE / END
2598  * - ETH / VLAN / IPV6 / NVGRE / END
2599  *
2600  */
2601 struct rte_flow_action_nvgre_encap {
2602         /**
2603          * Encapsulating vxlan tunnel definition
2604          * (terminated by the END pattern item).
2605          */
2606         struct rte_flow_item *definition;
2607 };
2608
2609 /**
2610  * @warning
2611  * @b EXPERIMENTAL: this structure may change without prior notice
2612  *
2613  * RTE_FLOW_ACTION_TYPE_RAW_ENCAP
2614  *
2615  * Raw tunnel end-point encapsulation data definition.
2616  *
2617  * The data holds the headers definitions to be applied on the packet.
2618  * The data must start with ETH header up to the tunnel item header itself.
2619  * When used right after RAW_DECAP (for decapsulating L3 tunnel type for
2620  * example MPLSoGRE) the data will just hold layer 2 header.
2621  *
2622  * The preserve parameter holds which bits in the packet the PMD is not allowed
2623  * to change, this parameter can also be NULL and then the PMD is allowed
2624  * to update any field.
2625  *
2626  * size holds the number of bytes in @p data and @p preserve.
2627  */
2628 struct rte_flow_action_raw_encap {
2629         uint8_t *data; /**< Encapsulation data. */
2630         uint8_t *preserve; /**< Bit-mask of @p data to preserve on output. */
2631         size_t size; /**< Size of @p data and @p preserve. */
2632 };
2633
2634 /**
2635  * @warning
2636  * @b EXPERIMENTAL: this structure may change without prior notice
2637  *
2638  * RTE_FLOW_ACTION_TYPE_RAW_DECAP
2639  *
2640  * Raw tunnel end-point decapsulation data definition.
2641  *
2642  * The data holds the headers definitions to be removed from the packet.
2643  * The data must start with ETH header up to the tunnel item header itself.
2644  * When used right before RAW_DECAP (for encapsulating L3 tunnel type for
2645  * example MPLSoGRE) the data will just hold layer 2 header.
2646  *
2647  * size holds the number of bytes in @p data.
2648  */
2649 struct rte_flow_action_raw_decap {
2650         uint8_t *data; /**< Encapsulation data. */
2651         size_t size; /**< Size of @p data and @p preserve. */
2652 };
2653
2654 /**
2655  * @warning
2656  * @b EXPERIMENTAL: this structure may change without prior notice
2657  *
2658  * RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC
2659  * RTE_FLOW_ACTION_TYPE_SET_IPV4_DST
2660  *
2661  * Allows modification of IPv4 source (RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC)
2662  * and destination address (RTE_FLOW_ACTION_TYPE_SET_IPV4_DST) in the
2663  * specified outermost IPv4 header.
2664  */
2665 struct rte_flow_action_set_ipv4 {
2666         rte_be32_t ipv4_addr;
2667 };
2668
2669 /**
2670  * @warning
2671  * @b EXPERIMENTAL: this structure may change without prior notice
2672  *
2673  * RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC
2674  * RTE_FLOW_ACTION_TYPE_SET_IPV6_DST
2675  *
2676  * Allows modification of IPv6 source (RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC)
2677  * and destination address (RTE_FLOW_ACTION_TYPE_SET_IPV6_DST) in the
2678  * specified outermost IPv6 header.
2679  */
2680 struct rte_flow_action_set_ipv6 {
2681         uint8_t ipv6_addr[16];
2682 };
2683
2684 /**
2685  * @warning
2686  * @b EXPERIMENTAL: this structure may change without prior notice
2687  *
2688  * RTE_FLOW_ACTION_TYPE_SET_TP_SRC
2689  * RTE_FLOW_ACTION_TYPE_SET_TP_DST
2690  *
2691  * Allows modification of source (RTE_FLOW_ACTION_TYPE_SET_TP_SRC)
2692  * and destination (RTE_FLOW_ACTION_TYPE_SET_TP_DST) port numbers
2693  * in the specified outermost TCP/UDP header.
2694  */
2695 struct rte_flow_action_set_tp {
2696         rte_be16_t port;
2697 };
2698
2699 /**
2700  * RTE_FLOW_ACTION_TYPE_SET_TTL
2701  *
2702  * Set the TTL value directly for IPv4 or IPv6
2703  */
2704 struct rte_flow_action_set_ttl {
2705         uint8_t ttl_value;
2706 };
2707
2708 /**
2709  * RTE_FLOW_ACTION_TYPE_SET_MAC
2710  *
2711  * Set MAC address from the matched flow
2712  */
2713 struct rte_flow_action_set_mac {
2714         uint8_t mac_addr[RTE_ETHER_ADDR_LEN];
2715 };
2716
2717 /**
2718  * @warning
2719  * @b EXPERIMENTAL: this structure may change without prior notice
2720  *
2721  * RTE_FLOW_ACTION_TYPE_SET_TAG
2722  *
2723  * Set a tag which is a transient data used during flow matching. This is not
2724  * delivered to application. Multiple tags are supported by specifying index.
2725  */
2726 struct rte_flow_action_set_tag {
2727         uint32_t data;
2728         uint32_t mask;
2729         uint8_t index;
2730 };
2731
2732 /**
2733  * @warning
2734  * @b EXPERIMENTAL: this structure may change without prior notice
2735  *
2736  * RTE_FLOW_ACTION_TYPE_SET_META
2737  *
2738  * Set metadata. Metadata set by mbuf metadata dynamic field with
2739  * PKT_TX_DYNF_DATA flag on egress will be overridden by this action. On
2740  * ingress, the metadata will be carried by mbuf metadata dynamic field
2741  * with PKT_RX_DYNF_METADATA flag if set.  The dynamic mbuf field must be
2742  * registered in advance by rte_flow_dynf_metadata_register().
2743  *
2744  * Altering partial bits is supported with mask. For bits which have never
2745  * been set, unpredictable value will be seen depending on driver
2746  * implementation. For loopback/hairpin packet, metadata set on Rx/Tx may
2747  * or may not be propagated to the other path depending on HW capability.
2748  *
2749  * RTE_FLOW_ITEM_TYPE_META matches metadata.
2750  */
2751 struct rte_flow_action_set_meta {
2752         uint32_t data;
2753         uint32_t mask;
2754 };
2755
2756 /**
2757  * RTE_FLOW_ACTION_TYPE_SET_IPV4_DSCP
2758  * RTE_FLOW_ACTION_TYPE_SET_IPV6_DSCP
2759  *
2760  * Set the DSCP value for IPv4/IPv6 header.
2761  * DSCP in low 6 bits, rest ignored.
2762  */
2763 struct rte_flow_action_set_dscp {
2764         uint8_t dscp;
2765 };
2766
2767
2768 /**
2769  * RTE_FLOW_ACTION_TYPE_SHARED
2770  *
2771  * Opaque type returned after successfully creating a shared action.
2772  *
2773  * This handle can be used to manage and query the related action:
2774  * - share it across multiple flow rules
2775  * - update action configuration
2776  * - query action data
2777  * - destroy action
2778  */
2779 struct rte_flow_shared_action;
2780
2781 /* Mbuf dynamic field offset for metadata. */
2782 extern int32_t rte_flow_dynf_metadata_offs;
2783
2784 /* Mbuf dynamic field flag mask for metadata. */
2785 extern uint64_t rte_flow_dynf_metadata_mask;
2786
2787 /* Mbuf dynamic field pointer for metadata. */
2788 #define RTE_FLOW_DYNF_METADATA(m) \
2789         RTE_MBUF_DYNFIELD((m), rte_flow_dynf_metadata_offs, uint32_t *)
2790
2791 /* Mbuf dynamic flags for metadata. */
2792 #define PKT_RX_DYNF_METADATA (rte_flow_dynf_metadata_mask)
2793 #define PKT_TX_DYNF_METADATA (rte_flow_dynf_metadata_mask)
2794
2795 __rte_experimental
2796 static inline uint32_t
2797 rte_flow_dynf_metadata_get(struct rte_mbuf *m)
2798 {
2799         return *RTE_FLOW_DYNF_METADATA(m);
2800 }
2801
2802 __rte_experimental
2803 static inline void
2804 rte_flow_dynf_metadata_set(struct rte_mbuf *m, uint32_t v)
2805 {
2806         *RTE_FLOW_DYNF_METADATA(m) = v;
2807 }
2808
2809 /*
2810  * Definition of a single action.
2811  *
2812  * A list of actions is terminated by a END action.
2813  *
2814  * For simple actions without a configuration object, conf remains NULL.
2815  */
2816 struct rte_flow_action {
2817         enum rte_flow_action_type type; /**< Action type. */
2818         const void *conf; /**< Pointer to action configuration object. */
2819 };
2820
2821 /**
2822  * Opaque type returned after successfully creating a flow.
2823  *
2824  * This handle can be used to manage and query the related flow (e.g. to
2825  * destroy it or retrieve counters).
2826  */
2827 struct rte_flow;
2828
2829 /**
2830  * @warning
2831  * @b EXPERIMENTAL: this structure may change without prior notice
2832  *
2833  * RTE_FLOW_ACTION_TYPE_SAMPLE
2834  *
2835  * Adds a sample action to a matched flow.
2836  *
2837  * The matching packets will be duplicated with specified ratio and applied
2838  * with own set of actions with a fate action, the sampled packet could be
2839  * redirected to queue or port. All the packets continue processing on the
2840  * default flow path.
2841  *
2842  * When the sample ratio is set to 1 then the packets will be 100% mirrored.
2843  * Additional action list be supported to add for sampled or mirrored packets.
2844  */
2845 struct rte_flow_action_sample {
2846         uint32_t ratio; /**< packets sampled equals to '1/ratio'. */
2847         const struct rte_flow_action *actions;
2848                 /**< sub-action list specific for the sampling hit cases. */
2849 };
2850
2851 /**
2852  * Verbose error types.
2853  *
2854  * Most of them provide the type of the object referenced by struct
2855  * rte_flow_error.cause.
2856  */
2857 enum rte_flow_error_type {
2858         RTE_FLOW_ERROR_TYPE_NONE, /**< No error. */
2859         RTE_FLOW_ERROR_TYPE_UNSPECIFIED, /**< Cause unspecified. */
2860         RTE_FLOW_ERROR_TYPE_HANDLE, /**< Flow rule (handle). */
2861         RTE_FLOW_ERROR_TYPE_ATTR_GROUP, /**< Group field. */
2862         RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY, /**< Priority field. */
2863         RTE_FLOW_ERROR_TYPE_ATTR_INGRESS, /**< Ingress field. */
2864         RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, /**< Egress field. */
2865         RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER, /**< Transfer field. */
2866         RTE_FLOW_ERROR_TYPE_ATTR, /**< Attributes structure. */
2867         RTE_FLOW_ERROR_TYPE_ITEM_NUM, /**< Pattern length. */
2868         RTE_FLOW_ERROR_TYPE_ITEM_SPEC, /**< Item specification. */
2869         RTE_FLOW_ERROR_TYPE_ITEM_LAST, /**< Item specification range. */
2870         RTE_FLOW_ERROR_TYPE_ITEM_MASK, /**< Item specification mask. */
2871         RTE_FLOW_ERROR_TYPE_ITEM, /**< Specific pattern item. */
2872         RTE_FLOW_ERROR_TYPE_ACTION_NUM, /**< Number of actions. */
2873         RTE_FLOW_ERROR_TYPE_ACTION_CONF, /**< Action configuration. */
2874         RTE_FLOW_ERROR_TYPE_ACTION, /**< Specific action. */
2875 };
2876
2877 /**
2878  * Verbose error structure definition.
2879  *
2880  * This object is normally allocated by applications and set by PMDs, the
2881  * message points to a constant string which does not need to be freed by
2882  * the application, however its pointer can be considered valid only as long
2883  * as its associated DPDK port remains configured. Closing the underlying
2884  * device or unloading the PMD invalidates it.
2885  *
2886  * Both cause and message may be NULL regardless of the error type.
2887  */
2888 struct rte_flow_error {
2889         enum rte_flow_error_type type; /**< Cause field and error types. */
2890         const void *cause; /**< Object responsible for the error. */
2891         const char *message; /**< Human-readable error message. */
2892 };
2893
2894 /**
2895  * Complete flow rule description.
2896  *
2897  * This object type is used when converting a flow rule description.
2898  *
2899  * @see RTE_FLOW_CONV_OP_RULE
2900  * @see rte_flow_conv()
2901  */
2902 RTE_STD_C11
2903 struct rte_flow_conv_rule {
2904         union {
2905                 const struct rte_flow_attr *attr_ro; /**< RO attributes. */
2906                 struct rte_flow_attr *attr; /**< Attributes. */
2907         };
2908         union {
2909                 const struct rte_flow_item *pattern_ro; /**< RO pattern. */
2910                 struct rte_flow_item *pattern; /**< Pattern items. */
2911         };
2912         union {
2913                 const struct rte_flow_action *actions_ro; /**< RO actions. */
2914                 struct rte_flow_action *actions; /**< List of actions. */
2915         };
2916 };
2917
2918 /**
2919  * Conversion operations for flow API objects.
2920  *
2921  * @see rte_flow_conv()
2922  */
2923 enum rte_flow_conv_op {
2924         /**
2925          * No operation to perform.
2926          *
2927          * rte_flow_conv() simply returns 0.
2928          */
2929         RTE_FLOW_CONV_OP_NONE,
2930
2931         /**
2932          * Convert attributes structure.
2933          *
2934          * This is a basic copy of an attributes structure.
2935          *
2936          * - @p src type:
2937          *   @code const struct rte_flow_attr * @endcode
2938          * - @p dst type:
2939          *   @code struct rte_flow_attr * @endcode
2940          */
2941         RTE_FLOW_CONV_OP_ATTR,
2942
2943         /**
2944          * Convert a single item.
2945          *
2946          * Duplicates @p spec, @p last and @p mask but not outside objects.
2947          *
2948          * - @p src type:
2949          *   @code const struct rte_flow_item * @endcode
2950          * - @p dst type:
2951          *   @code struct rte_flow_item * @endcode
2952          */
2953         RTE_FLOW_CONV_OP_ITEM,
2954
2955         /**
2956          * Convert a single action.
2957          *
2958          * Duplicates @p conf but not outside objects.
2959          *
2960          * - @p src type:
2961          *   @code const struct rte_flow_action * @endcode
2962          * - @p dst type:
2963          *   @code struct rte_flow_action * @endcode
2964          */
2965         RTE_FLOW_CONV_OP_ACTION,
2966
2967         /**
2968          * Convert an entire pattern.
2969          *
2970          * Duplicates all pattern items at once with the same constraints as
2971          * RTE_FLOW_CONV_OP_ITEM.
2972          *
2973          * - @p src type:
2974          *   @code const struct rte_flow_item * @endcode
2975          * - @p dst type:
2976          *   @code struct rte_flow_item * @endcode
2977          */
2978         RTE_FLOW_CONV_OP_PATTERN,
2979
2980         /**
2981          * Convert a list of actions.
2982          *
2983          * Duplicates the entire list of actions at once with the same
2984          * constraints as RTE_FLOW_CONV_OP_ACTION.
2985          *
2986          * - @p src type:
2987          *   @code const struct rte_flow_action * @endcode
2988          * - @p dst type:
2989          *   @code struct rte_flow_action * @endcode
2990          */
2991         RTE_FLOW_CONV_OP_ACTIONS,
2992
2993         /**
2994          * Convert a complete flow rule description.
2995          *
2996          * Comprises attributes, pattern and actions together at once with
2997          * the usual constraints.
2998          *
2999          * - @p src type:
3000          *   @code const struct rte_flow_conv_rule * @endcode
3001          * - @p dst type:
3002          *   @code struct rte_flow_conv_rule * @endcode
3003          */
3004         RTE_FLOW_CONV_OP_RULE,
3005
3006         /**
3007          * Convert item type to its name string.
3008          *
3009          * Writes a NUL-terminated string to @p dst. Like snprintf(), the
3010          * returned value excludes the terminator which is always written
3011          * nonetheless.
3012          *
3013          * - @p src type:
3014          *   @code (const void *)enum rte_flow_item_type @endcode
3015          * - @p dst type:
3016          *   @code char * @endcode
3017          **/
3018         RTE_FLOW_CONV_OP_ITEM_NAME,
3019
3020         /**
3021          * Convert action type to its name string.
3022          *
3023          * Writes a NUL-terminated string to @p dst. Like snprintf(), the
3024          * returned value excludes the terminator which is always written
3025          * nonetheless.
3026          *
3027          * - @p src type:
3028          *   @code (const void *)enum rte_flow_action_type @endcode
3029          * - @p dst type:
3030          *   @code char * @endcode
3031          **/
3032         RTE_FLOW_CONV_OP_ACTION_NAME,
3033
3034         /**
3035          * Convert item type to pointer to item name.
3036          *
3037          * Retrieves item name pointer from its type. The string itself is
3038          * not copied; instead, a unique pointer to an internal static
3039          * constant storage is written to @p dst.
3040          *
3041          * - @p src type:
3042          *   @code (const void *)enum rte_flow_item_type @endcode
3043          * - @p dst type:
3044          *   @code const char ** @endcode
3045          */
3046         RTE_FLOW_CONV_OP_ITEM_NAME_PTR,
3047
3048         /**
3049          * Convert action type to pointer to action name.
3050          *
3051          * Retrieves action name pointer from its type. The string itself is
3052          * not copied; instead, a unique pointer to an internal static
3053          * constant storage is written to @p dst.
3054          *
3055          * - @p src type:
3056          *   @code (const void *)enum rte_flow_action_type @endcode
3057          * - @p dst type:
3058          *   @code const char ** @endcode
3059          */
3060         RTE_FLOW_CONV_OP_ACTION_NAME_PTR,
3061 };
3062
3063 /**
3064  * @warning
3065  * @b EXPERIMENTAL: this API may change without prior notice.
3066  *
3067  * Dump hardware internal representation information of
3068  * rte flow to file.
3069  *
3070  * @param[in] port_id
3071  *    The port identifier of the Ethernet device.
3072  * @param[in] file
3073  *   A pointer to a file for output.
3074  * @param[out] error
3075  *   Perform verbose error reporting if not NULL. PMDs initialize this
3076  *   structure in case of error only.
3077  * @return
3078  *   0 on success, a nagative value otherwise.
3079  */
3080 __rte_experimental
3081 int
3082 rte_flow_dev_dump(uint16_t port_id, FILE *file, struct rte_flow_error *error);
3083
3084 /**
3085  * Check if mbuf dynamic field for metadata is registered.
3086  *
3087  * @return
3088  *   True if registered, false otherwise.
3089  */
3090 __rte_experimental
3091 static inline int
3092 rte_flow_dynf_metadata_avail(void)
3093 {
3094         return !!rte_flow_dynf_metadata_mask;
3095 }
3096
3097 /**
3098  * Register mbuf dynamic field and flag for metadata.
3099  *
3100  * This function must be called prior to use SET_META action in order to
3101  * register the dynamic mbuf field. Otherwise, the data cannot be delivered to
3102  * application.
3103  *
3104  * @return
3105  *   0 on success, a negative errno value otherwise and rte_errno is set.
3106  */
3107 __rte_experimental
3108 int
3109 rte_flow_dynf_metadata_register(void);
3110
3111 /**
3112  * Check whether a flow rule can be created on a given port.
3113  *
3114  * The flow rule is validated for correctness and whether it could be accepted
3115  * by the device given sufficient resources. The rule is checked against the
3116  * current device mode and queue configuration. The flow rule may also
3117  * optionally be validated against existing flow rules and device resources.
3118  * This function has no effect on the target device.
3119  *
3120  * The returned value is guaranteed to remain valid only as long as no
3121  * successful calls to rte_flow_create() or rte_flow_destroy() are made in
3122  * the meantime and no device parameter affecting flow rules in any way are
3123  * modified, due to possible collisions or resource limitations (although in
3124  * such cases EINVAL should not be returned).
3125  *
3126  * @param port_id
3127  *   Port identifier of Ethernet device.
3128  * @param[in] attr
3129  *   Flow rule attributes.
3130  * @param[in] pattern
3131  *   Pattern specification (list terminated by the END pattern item).
3132  * @param[in] actions
3133  *   Associated actions (list terminated by the END action).
3134  * @param[out] error
3135  *   Perform verbose error reporting if not NULL. PMDs initialize this
3136  *   structure in case of error only.
3137  *
3138  * @return
3139  *   0 if flow rule is valid and can be created. A negative errno value
3140  *   otherwise (rte_errno is also set), the following errors are defined:
3141  *
3142  *   -ENOSYS: underlying device does not support this functionality.
3143  *
3144  *   -EIO: underlying device is removed.
3145  *
3146  *   -EINVAL: unknown or invalid rule specification.
3147  *
3148  *   -ENOTSUP: valid but unsupported rule specification (e.g. partial
3149  *   bit-masks are unsupported).
3150  *
3151  *   -EEXIST: collision with an existing rule. Only returned if device
3152  *   supports flow rule collision checking and there was a flow rule
3153  *   collision. Not receiving this return code is no guarantee that creating
3154  *   the rule will not fail due to a collision.
3155  *
3156  *   -ENOMEM: not enough memory to execute the function, or if the device
3157  *   supports resource validation, resource limitation on the device.
3158  *
3159  *   -EBUSY: action cannot be performed due to busy device resources, may
3160  *   succeed if the affected queues or even the entire port are in a stopped
3161  *   state (see rte_eth_dev_rx_queue_stop() and rte_eth_dev_stop()).
3162  */
3163 int
3164 rte_flow_validate(uint16_t port_id,
3165                   const struct rte_flow_attr *attr,
3166                   const struct rte_flow_item pattern[],
3167                   const struct rte_flow_action actions[],
3168                   struct rte_flow_error *error);
3169
3170 /**
3171  * Create a flow rule on a given port.
3172  *
3173  * @param port_id
3174  *   Port identifier of Ethernet device.
3175  * @param[in] attr
3176  *   Flow rule attributes.
3177  * @param[in] pattern
3178  *   Pattern specification (list terminated by the END pattern item).
3179  * @param[in] actions
3180  *   Associated actions (list terminated by the END action).
3181  * @param[out] error
3182  *   Perform verbose error reporting if not NULL. PMDs initialize this
3183  *   structure in case of error only.
3184  *
3185  * @return
3186  *   A valid handle in case of success, NULL otherwise and rte_errno is set
3187  *   to the positive version of one of the error codes defined for
3188  *   rte_flow_validate().
3189  */
3190 struct rte_flow *
3191 rte_flow_create(uint16_t port_id,
3192                 const struct rte_flow_attr *attr,
3193                 const struct rte_flow_item pattern[],
3194                 const struct rte_flow_action actions[],
3195                 struct rte_flow_error *error);
3196
3197 /**
3198  * Destroy a flow rule on a given port.
3199  *
3200  * Failure to destroy a flow rule handle may occur when other flow rules
3201  * depend on it, and destroying it would result in an inconsistent state.
3202  *
3203  * This function is only guaranteed to succeed if handles are destroyed in
3204  * reverse order of their creation.
3205  *
3206  * @param port_id
3207  *   Port identifier of Ethernet device.
3208  * @param flow
3209  *   Flow rule handle to destroy.
3210  * @param[out] error
3211  *   Perform verbose error reporting if not NULL. PMDs initialize this
3212  *   structure in case of error only.
3213  *
3214  * @return
3215  *   0 on success, a negative errno value otherwise and rte_errno is set.
3216  */
3217 int
3218 rte_flow_destroy(uint16_t port_id,
3219                  struct rte_flow *flow,
3220                  struct rte_flow_error *error);
3221
3222 /**
3223  * Destroy all flow rules associated with a port.
3224  *
3225  * In the unlikely event of failure, handles are still considered destroyed
3226  * and no longer valid but the port must be assumed to be in an inconsistent
3227  * state.
3228  *
3229  * @param port_id
3230  *   Port identifier of Ethernet device.
3231  * @param[out] error
3232  *   Perform verbose error reporting if not NULL. PMDs initialize this
3233  *   structure in case of error only.
3234  *
3235  * @return
3236  *   0 on success, a negative errno value otherwise and rte_errno is set.
3237  */
3238 int
3239 rte_flow_flush(uint16_t port_id,
3240                struct rte_flow_error *error);
3241
3242 /**
3243  * Query an existing flow rule.
3244  *
3245  * This function allows retrieving flow-specific data such as counters.
3246  * Data is gathered by special actions which must be present in the flow
3247  * rule definition.
3248  *
3249  * \see RTE_FLOW_ACTION_TYPE_COUNT
3250  *
3251  * @param port_id
3252  *   Port identifier of Ethernet device.
3253  * @param flow
3254  *   Flow rule handle to query.
3255  * @param action
3256  *   Action definition as defined in original flow rule.
3257  * @param[in, out] data
3258  *   Pointer to storage for the associated query data type.
3259  * @param[out] error
3260  *   Perform verbose error reporting if not NULL. PMDs initialize this
3261  *   structure in case of error only.
3262  *
3263  * @return
3264  *   0 on success, a negative errno value otherwise and rte_errno is set.
3265  */
3266 int
3267 rte_flow_query(uint16_t port_id,
3268                struct rte_flow *flow,
3269                const struct rte_flow_action *action,
3270                void *data,
3271                struct rte_flow_error *error);
3272
3273 /**
3274  * Restrict ingress traffic to the defined flow rules.
3275  *
3276  * Isolated mode guarantees that all ingress traffic comes from defined flow
3277  * rules only (current and future).
3278  *
3279  * Besides making ingress more deterministic, it allows PMDs to safely reuse
3280  * resources otherwise assigned to handle the remaining traffic, such as
3281  * global RSS configuration settings, VLAN filters, MAC address entries,
3282  * legacy filter API rules and so on in order to expand the set of possible
3283  * flow rule types.
3284  *
3285  * Calling this function as soon as possible after device initialization,
3286  * ideally before the first call to rte_eth_dev_configure(), is recommended
3287  * to avoid possible failures due to conflicting settings.
3288  *
3289  * Once effective, leaving isolated mode may not be possible depending on
3290  * PMD implementation.
3291  *
3292  * Additionally, the following functionality has no effect on the underlying
3293  * port and may return errors such as ENOTSUP ("not supported"):
3294  *
3295  * - Toggling promiscuous mode.
3296  * - Toggling allmulticast mode.
3297  * - Configuring MAC addresses.
3298  * - Configuring multicast addresses.
3299  * - Configuring VLAN filters.
3300  * - Configuring Rx filters through the legacy API (e.g. FDIR).
3301  * - Configuring global RSS settings.
3302  *
3303  * @param port_id
3304  *   Port identifier of Ethernet device.
3305  * @param set
3306  *   Nonzero to enter isolated mode, attempt to leave it otherwise.
3307  * @param[out] error
3308  *   Perform verbose error reporting if not NULL. PMDs initialize this
3309  *   structure in case of error only.
3310  *
3311  * @return
3312  *   0 on success, a negative errno value otherwise and rte_errno is set.
3313  */
3314 int
3315 rte_flow_isolate(uint16_t port_id, int set, struct rte_flow_error *error);
3316
3317 /**
3318  * Initialize flow error structure.
3319  *
3320  * @param[out] error
3321  *   Pointer to flow error structure (may be NULL).
3322  * @param code
3323  *   Related error code (rte_errno).
3324  * @param type
3325  *   Cause field and error types.
3326  * @param cause
3327  *   Object responsible for the error.
3328  * @param message
3329  *   Human-readable error message.
3330  *
3331  * @return
3332  *   Negative error code (errno value) and rte_errno is set.
3333  */
3334 int
3335 rte_flow_error_set(struct rte_flow_error *error,
3336                    int code,
3337                    enum rte_flow_error_type type,
3338                    const void *cause,
3339                    const char *message);
3340
3341 /**
3342  * @deprecated
3343  * @see rte_flow_copy()
3344  */
3345 struct rte_flow_desc {
3346         size_t size; /**< Allocated space including data[]. */
3347         struct rte_flow_attr attr; /**< Attributes. */
3348         struct rte_flow_item *items; /**< Items. */
3349         struct rte_flow_action *actions; /**< Actions. */
3350         uint8_t data[]; /**< Storage for items/actions. */
3351 };
3352
3353 /**
3354  * @deprecated
3355  * Copy an rte_flow rule description.
3356  *
3357  * This interface is kept for compatibility with older applications but is
3358  * implemented as a wrapper to rte_flow_conv(). It is deprecated due to its
3359  * lack of flexibility and reliance on a type unusable with C++ programs
3360  * (struct rte_flow_desc).
3361  *
3362  * @param[in] fd
3363  *   Flow rule description.
3364  * @param[in] len
3365  *   Total size of allocated data for the flow description.
3366  * @param[in] attr
3367  *   Flow rule attributes.
3368  * @param[in] items
3369  *   Pattern specification (list terminated by the END pattern item).
3370  * @param[in] actions
3371  *   Associated actions (list terminated by the END action).
3372  *
3373  * @return
3374  *   If len is greater or equal to the size of the flow, the total size of the
3375  *   flow description and its data.
3376  *   If len is lower than the size of the flow, the number of bytes that would
3377  *   have been written to desc had it been sufficient. Nothing is written.
3378  */
3379 __rte_deprecated
3380 size_t
3381 rte_flow_copy(struct rte_flow_desc *fd, size_t len,
3382               const struct rte_flow_attr *attr,
3383               const struct rte_flow_item *items,
3384               const struct rte_flow_action *actions);
3385
3386 /**
3387  * Flow object conversion helper.
3388  *
3389  * This function performs conversion of various flow API objects to a
3390  * pre-allocated destination buffer. See enum rte_flow_conv_op for possible
3391  * operations and details about each of them.
3392  *
3393  * Since destination buffer must be large enough, it works in a manner
3394  * reminiscent of snprintf():
3395  *
3396  * - If @p size is 0, @p dst may be a NULL pointer, otherwise @p dst must be
3397  *   non-NULL.
3398  * - If positive, the returned value represents the number of bytes needed
3399  *   to store the conversion of @p src to @p dst according to @p op
3400  *   regardless of the @p size parameter.
3401  * - Since no more than @p size bytes can be written to @p dst, output is
3402  *   truncated and may be inconsistent when the returned value is larger
3403  *   than that.
3404  * - In case of conversion error, a negative error code is returned and
3405  *   @p dst contents are unspecified.
3406  *
3407  * @param op
3408  *   Operation to perform, related to the object type of @p dst.
3409  * @param[out] dst
3410  *   Destination buffer address. Must be suitably aligned by the caller.
3411  * @param size
3412  *   Destination buffer size in bytes.
3413  * @param[in] src
3414  *   Source object to copy. Depending on @p op, its type may differ from
3415  *   that of @p dst.
3416  * @param[out] error
3417  *   Perform verbose error reporting if not NULL. Initialized in case of
3418  *   error only.
3419  *
3420  * @return
3421  *   The number of bytes required to convert @p src to @p dst on success, a
3422  *   negative errno value otherwise and rte_errno is set.
3423  *
3424  * @see rte_flow_conv_op
3425  */
3426 __rte_experimental
3427 int
3428 rte_flow_conv(enum rte_flow_conv_op op,
3429               void *dst,
3430               size_t size,
3431               const void *src,
3432               struct rte_flow_error *error);
3433
3434 /**
3435  * Get aged-out flows of a given port.
3436  *
3437  * RTE_ETH_EVENT_FLOW_AGED event will be triggered when at least one new aged
3438  * out flow was detected after the last call to rte_flow_get_aged_flows.
3439  * This function can be called to get the aged flows usynchronously from the
3440  * event callback or synchronously regardless the event.
3441  * This is not safe to call rte_flow_get_aged_flows function with other flow
3442  * functions from multiple threads simultaneously.
3443  *
3444  * @param port_id
3445  *   Port identifier of Ethernet device.
3446  * @param[in, out] contexts
3447  *   The address of an array of pointers to the aged-out flows contexts.
3448  * @param[in] nb_contexts
3449  *   The length of context array pointers.
3450  * @param[out] error
3451  *   Perform verbose error reporting if not NULL. Initialized in case of
3452  *   error only.
3453  *
3454  * @return
3455  *   if nb_contexts is 0, return the amount of all aged contexts.
3456  *   if nb_contexts is not 0 , return the amount of aged flows reported
3457  *   in the context array, otherwise negative errno value.
3458  *
3459  * @see rte_flow_action_age
3460  * @see RTE_ETH_EVENT_FLOW_AGED
3461  */
3462 __rte_experimental
3463 int
3464 rte_flow_get_aged_flows(uint16_t port_id, void **contexts,
3465                         uint32_t nb_contexts, struct rte_flow_error *error);
3466
3467 /**
3468  * Specify shared action configuration
3469  */
3470 struct rte_flow_shared_action_conf {
3471         /**
3472          * Flow direction for shared action configuration.
3473          *
3474          * Shared action should be valid at least for one flow direction,
3475          * otherwise it is invalid for both ingress and egress rules.
3476          */
3477         uint32_t ingress:1;
3478         /**< Action valid for rules applied to ingress traffic. */
3479         uint32_t egress:1;
3480         /**< Action valid for rules applied to egress traffic. */
3481 };
3482
3483 /**
3484  * @warning
3485  * @b EXPERIMENTAL: this API may change without prior notice.
3486  *
3487  * Create shared action for reuse in multiple flow rules.
3488  * The created shared action has single state and configuration
3489  * across all flow rules using it.
3490  *
3491  * @param[in] port_id
3492  *    The port identifier of the Ethernet device.
3493  * @param[in] conf
3494  *   Shared action configuration.
3495  * @param[in] action
3496  *   Action configuration for shared action creation.
3497  * @param[out] error
3498  *   Perform verbose error reporting if not NULL. PMDs initialize this
3499  *   structure in case of error only.
3500  * @return
3501  *   A valid handle in case of success, NULL otherwise and rte_errno is set
3502  *   to one of the error codes defined:
3503  *   - (ENODEV) if *port_id* invalid.
3504  *   - (ENOSYS) if underlying device does not support this functionality.
3505  *   - (EIO) if underlying device is removed.
3506  *   - (EINVAL) if *action* invalid.
3507  *   - (ENOTSUP) if *action* valid but unsupported.
3508  */
3509 __rte_experimental
3510 struct rte_flow_shared_action *
3511 rte_flow_shared_action_create(uint16_t port_id,
3512                               const struct rte_flow_shared_action_conf *conf,
3513                               const struct rte_flow_action *action,
3514                               struct rte_flow_error *error);
3515
3516 /**
3517  * @warning
3518  * @b EXPERIMENTAL: this API may change without prior notice.
3519  *
3520  * Destroy the shared action by handle.
3521  *
3522  * @param[in] port_id
3523  *    The port identifier of the Ethernet device.
3524  * @param[in] action
3525  *   Handle for the shared action to be destroyed.
3526  * @param[out] error
3527  *   Perform verbose error reporting if not NULL. PMDs initialize this
3528  *   structure in case of error only.
3529  * @return
3530  *   - (0) if success.
3531  *   - (-ENODEV) if *port_id* invalid.
3532  *   - (-ENOSYS) if underlying device does not support this functionality.
3533  *   - (-EIO) if underlying device is removed.
3534  *   - (-ENOENT) if action pointed by *action* handle was not found.
3535  *   - (-ETOOMANYREFS) if action pointed by *action* handle still used by one or
3536  *     more rules
3537  *   rte_errno is also set.
3538  */
3539 __rte_experimental
3540 int
3541 rte_flow_shared_action_destroy(uint16_t port_id,
3542                                struct rte_flow_shared_action *action,
3543                                struct rte_flow_error *error);
3544
3545 /**
3546  * @warning
3547  * @b EXPERIMENTAL: this API may change without prior notice.
3548  *
3549  * Update in-place the shared action configuration pointed by *action* handle
3550  * with the configuration provided as *update* argument.
3551  * The update of the shared action configuration effects all flow rules reusing
3552  * the action via handle.
3553  *
3554  * @param[in] port_id
3555  *    The port identifier of the Ethernet device.
3556  * @param[in] action
3557  *   Handle for the shared action to be updated.
3558  * @param[in] update
3559  *   Action specification used to modify the action pointed by handle.
3560  *   *update* should be of same type with the action pointed by the *action*
3561  *   handle argument, otherwise considered as invalid.
3562  * @param[out] error
3563  *   Perform verbose error reporting if not NULL. PMDs initialize this
3564  *   structure in case of error only.
3565  * @return
3566  *   - (0) if success.
3567  *   - (-ENODEV) if *port_id* invalid.
3568  *   - (-ENOSYS) if underlying device does not support this functionality.
3569  *   - (-EIO) if underlying device is removed.
3570  *   - (-EINVAL) if *update* invalid.
3571  *   - (-ENOTSUP) if *update* valid but unsupported.
3572  *   - (-ENOENT) if action pointed by *ctx* was not found.
3573  *   rte_errno is also set.
3574  */
3575 __rte_experimental
3576 int
3577 rte_flow_shared_action_update(uint16_t port_id,
3578                               struct rte_flow_shared_action *action,
3579                               const struct rte_flow_action *update,
3580                               struct rte_flow_error *error);
3581
3582 /**
3583  * @warning
3584  * @b EXPERIMENTAL: this API may change without prior notice.
3585  *
3586  * Query the shared action by handle.
3587  *
3588  * Retrieve action-specific data such as counters.
3589  * Data is gathered by special action which may be present/referenced in
3590  * more than one flow rule definition.
3591  *
3592  * \see RTE_FLOW_ACTION_TYPE_COUNT
3593  *
3594  * @param port_id
3595  *   Port identifier of Ethernet device.
3596  * @param[in] action
3597  *   Handle for the shared action to query.
3598  * @param[in, out] data
3599  *   Pointer to storage for the associated query data type.
3600  * @param[out] error
3601  *   Perform verbose error reporting if not NULL. PMDs initialize this
3602  *   structure in case of error only.
3603  *
3604  * @return
3605  *   0 on success, a negative errno value otherwise and rte_errno is set.
3606  */
3607 __rte_experimental
3608 int
3609 rte_flow_shared_action_query(uint16_t port_id,
3610                              const struct rte_flow_shared_action *action,
3611                              void *data,
3612                              struct rte_flow_error *error);
3613
3614 #ifdef __cplusplus
3615 }
3616 #endif
3617
3618 #endif /* RTE_FLOW_H_ */