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