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