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