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