New upstream version 18.08
[deb_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_ether.h>
22 #include <rte_eth_ctrl.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 /**
419  * RTE_FLOW_ITEM_TYPE_ANY
420  *
421  * Matches any protocol in place of the current layer, a single ANY may also
422  * stand for several protocol layers.
423  *
424  * This is usually specified as the first pattern item when looking for a
425  * protocol anywhere in a packet.
426  *
427  * A zeroed mask stands for any number of layers.
428  */
429 struct rte_flow_item_any {
430         uint32_t num; /**< Number of layers covered. */
431 };
432
433 /** Default mask for RTE_FLOW_ITEM_TYPE_ANY. */
434 #ifndef __cplusplus
435 static const struct rte_flow_item_any rte_flow_item_any_mask = {
436         .num = 0x00000000,
437 };
438 #endif
439
440 /**
441  * RTE_FLOW_ITEM_TYPE_VF
442  *
443  * Matches traffic originating from (ingress) or going to (egress) a given
444  * virtual function of the current device.
445  *
446  * If supported, should work even if the virtual function is not managed by
447  * the application and thus not associated with a DPDK port ID.
448  *
449  * Note this pattern item does not match VF representors traffic which, as
450  * separate entities, should be addressed through their own DPDK port IDs.
451  *
452  * - Can be specified multiple times to match traffic addressed to several
453  *   VF IDs.
454  * - Can be combined with a PF item to match both PF and VF traffic.
455  *
456  * A zeroed mask can be used to match any VF ID.
457  */
458 struct rte_flow_item_vf {
459         uint32_t id; /**< VF ID. */
460 };
461
462 /** Default mask for RTE_FLOW_ITEM_TYPE_VF. */
463 #ifndef __cplusplus
464 static const struct rte_flow_item_vf rte_flow_item_vf_mask = {
465         .id = 0x00000000,
466 };
467 #endif
468
469 /**
470  * RTE_FLOW_ITEM_TYPE_PHY_PORT
471  *
472  * Matches traffic originating from (ingress) or going to (egress) a
473  * physical port of the underlying device.
474  *
475  * The first PHY_PORT item overrides the physical port normally associated
476  * with the specified DPDK input port (port_id). This item can be provided
477  * several times to match additional physical ports.
478  *
479  * Note that physical ports are not necessarily tied to DPDK input ports
480  * (port_id) when those are not under DPDK control. Possible values are
481  * specific to each device, they are not necessarily indexed from zero and
482  * may not be contiguous.
483  *
484  * As a device property, the list of allowed values as well as the value
485  * associated with a port_id should be retrieved by other means.
486  *
487  * A zeroed mask can be used to match any port index.
488  */
489 struct rte_flow_item_phy_port {
490         uint32_t index; /**< Physical port index. */
491 };
492
493 /** Default mask for RTE_FLOW_ITEM_TYPE_PHY_PORT. */
494 #ifndef __cplusplus
495 static const struct rte_flow_item_phy_port rte_flow_item_phy_port_mask = {
496         .index = 0x00000000,
497 };
498 #endif
499
500 /**
501  * RTE_FLOW_ITEM_TYPE_PORT_ID
502  *
503  * Matches traffic originating from (ingress) or going to (egress) a given
504  * DPDK port ID.
505  *
506  * Normally only supported if the port ID in question is known by the
507  * underlying PMD and related to the device the flow rule is created
508  * against.
509  *
510  * This must not be confused with @p PHY_PORT which refers to the physical
511  * port of a device, whereas @p PORT_ID refers to a struct rte_eth_dev
512  * object on the application side (also known as "port representor"
513  * depending on the kind of underlying device).
514  */
515 struct rte_flow_item_port_id {
516         uint32_t id; /**< DPDK port ID. */
517 };
518
519 /** Default mask for RTE_FLOW_ITEM_TYPE_PORT_ID. */
520 #ifndef __cplusplus
521 static const struct rte_flow_item_port_id rte_flow_item_port_id_mask = {
522         .id = 0xffffffff,
523 };
524 #endif
525
526 /**
527  * RTE_FLOW_ITEM_TYPE_RAW
528  *
529  * Matches a byte string of a given length at a given offset.
530  *
531  * Offset is either absolute (using the start of the packet) or relative to
532  * the end of the previous matched item in the stack, in which case negative
533  * values are allowed.
534  *
535  * If search is enabled, offset is used as the starting point. The search
536  * area can be delimited by setting limit to a nonzero value, which is the
537  * maximum number of bytes after offset where the pattern may start.
538  *
539  * Matching a zero-length pattern is allowed, doing so resets the relative
540  * offset for subsequent items.
541  *
542  * This type does not support ranges (struct rte_flow_item.last).
543  */
544 struct rte_flow_item_raw {
545         uint32_t relative:1; /**< Look for pattern after the previous item. */
546         uint32_t search:1; /**< Search pattern from offset (see also limit). */
547         uint32_t reserved:30; /**< Reserved, must be set to zero. */
548         int32_t offset; /**< Absolute or relative offset for pattern. */
549         uint16_t limit; /**< Search area limit for start of pattern. */
550         uint16_t length; /**< Pattern length. */
551         const uint8_t *pattern; /**< Byte string to look for. */
552 };
553
554 /** Default mask for RTE_FLOW_ITEM_TYPE_RAW. */
555 #ifndef __cplusplus
556 static const struct rte_flow_item_raw rte_flow_item_raw_mask = {
557         .relative = 1,
558         .search = 1,
559         .reserved = 0x3fffffff,
560         .offset = 0xffffffff,
561         .limit = 0xffff,
562         .length = 0xffff,
563         .pattern = NULL,
564 };
565 #endif
566
567 /**
568  * RTE_FLOW_ITEM_TYPE_ETH
569  *
570  * Matches an Ethernet header.
571  *
572  * The @p type field either stands for "EtherType" or "TPID" when followed
573  * by so-called layer 2.5 pattern items such as RTE_FLOW_ITEM_TYPE_VLAN. In
574  * the latter case, @p type refers to that of the outer header, with the
575  * inner EtherType/TPID provided by the subsequent pattern item. This is the
576  * same order as on the wire.
577  */
578 struct rte_flow_item_eth {
579         struct ether_addr dst; /**< Destination MAC. */
580         struct ether_addr src; /**< Source MAC. */
581         rte_be16_t type; /**< EtherType or TPID. */
582 };
583
584 /** Default mask for RTE_FLOW_ITEM_TYPE_ETH. */
585 #ifndef __cplusplus
586 static const struct rte_flow_item_eth rte_flow_item_eth_mask = {
587         .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
588         .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
589         .type = RTE_BE16(0x0000),
590 };
591 #endif
592
593 /**
594  * RTE_FLOW_ITEM_TYPE_VLAN
595  *
596  * Matches an 802.1Q/ad VLAN tag.
597  *
598  * The corresponding standard outer EtherType (TPID) values are
599  * ETHER_TYPE_VLAN or ETHER_TYPE_QINQ. It can be overridden by the preceding
600  * pattern item.
601  */
602 struct rte_flow_item_vlan {
603         rte_be16_t tci; /**< Tag control information. */
604         rte_be16_t inner_type; /**< Inner EtherType or TPID. */
605 };
606
607 /** Default mask for RTE_FLOW_ITEM_TYPE_VLAN. */
608 #ifndef __cplusplus
609 static const struct rte_flow_item_vlan rte_flow_item_vlan_mask = {
610         .tci = RTE_BE16(0x0fff),
611         .inner_type = RTE_BE16(0x0000),
612 };
613 #endif
614
615 /**
616  * RTE_FLOW_ITEM_TYPE_IPV4
617  *
618  * Matches an IPv4 header.
619  *
620  * Note: IPv4 options are handled by dedicated pattern items.
621  */
622 struct rte_flow_item_ipv4 {
623         struct ipv4_hdr hdr; /**< IPv4 header definition. */
624 };
625
626 /** Default mask for RTE_FLOW_ITEM_TYPE_IPV4. */
627 #ifndef __cplusplus
628 static const struct rte_flow_item_ipv4 rte_flow_item_ipv4_mask = {
629         .hdr = {
630                 .src_addr = RTE_BE32(0xffffffff),
631                 .dst_addr = RTE_BE32(0xffffffff),
632         },
633 };
634 #endif
635
636 /**
637  * RTE_FLOW_ITEM_TYPE_IPV6.
638  *
639  * Matches an IPv6 header.
640  *
641  * Note: IPv6 options are handled by dedicated pattern items, see
642  * RTE_FLOW_ITEM_TYPE_IPV6_EXT.
643  */
644 struct rte_flow_item_ipv6 {
645         struct ipv6_hdr hdr; /**< IPv6 header definition. */
646 };
647
648 /** Default mask for RTE_FLOW_ITEM_TYPE_IPV6. */
649 #ifndef __cplusplus
650 static const struct rte_flow_item_ipv6 rte_flow_item_ipv6_mask = {
651         .hdr = {
652                 .src_addr =
653                         "\xff\xff\xff\xff\xff\xff\xff\xff"
654                         "\xff\xff\xff\xff\xff\xff\xff\xff",
655                 .dst_addr =
656                         "\xff\xff\xff\xff\xff\xff\xff\xff"
657                         "\xff\xff\xff\xff\xff\xff\xff\xff",
658         },
659 };
660 #endif
661
662 /**
663  * RTE_FLOW_ITEM_TYPE_ICMP.
664  *
665  * Matches an ICMP header.
666  */
667 struct rte_flow_item_icmp {
668         struct icmp_hdr hdr; /**< ICMP header definition. */
669 };
670
671 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP. */
672 #ifndef __cplusplus
673 static const struct rte_flow_item_icmp rte_flow_item_icmp_mask = {
674         .hdr = {
675                 .icmp_type = 0xff,
676                 .icmp_code = 0xff,
677         },
678 };
679 #endif
680
681 /**
682  * RTE_FLOW_ITEM_TYPE_UDP.
683  *
684  * Matches a UDP header.
685  */
686 struct rte_flow_item_udp {
687         struct udp_hdr hdr; /**< UDP header definition. */
688 };
689
690 /** Default mask for RTE_FLOW_ITEM_TYPE_UDP. */
691 #ifndef __cplusplus
692 static const struct rte_flow_item_udp rte_flow_item_udp_mask = {
693         .hdr = {
694                 .src_port = RTE_BE16(0xffff),
695                 .dst_port = RTE_BE16(0xffff),
696         },
697 };
698 #endif
699
700 /**
701  * RTE_FLOW_ITEM_TYPE_TCP.
702  *
703  * Matches a TCP header.
704  */
705 struct rte_flow_item_tcp {
706         struct tcp_hdr hdr; /**< TCP header definition. */
707 };
708
709 /** Default mask for RTE_FLOW_ITEM_TYPE_TCP. */
710 #ifndef __cplusplus
711 static const struct rte_flow_item_tcp rte_flow_item_tcp_mask = {
712         .hdr = {
713                 .src_port = RTE_BE16(0xffff),
714                 .dst_port = RTE_BE16(0xffff),
715         },
716 };
717 #endif
718
719 /**
720  * RTE_FLOW_ITEM_TYPE_SCTP.
721  *
722  * Matches a SCTP header.
723  */
724 struct rte_flow_item_sctp {
725         struct sctp_hdr hdr; /**< SCTP header definition. */
726 };
727
728 /** Default mask for RTE_FLOW_ITEM_TYPE_SCTP. */
729 #ifndef __cplusplus
730 static const struct rte_flow_item_sctp rte_flow_item_sctp_mask = {
731         .hdr = {
732                 .src_port = RTE_BE16(0xffff),
733                 .dst_port = RTE_BE16(0xffff),
734         },
735 };
736 #endif
737
738 /**
739  * RTE_FLOW_ITEM_TYPE_VXLAN.
740  *
741  * Matches a VXLAN header (RFC 7348).
742  */
743 struct rte_flow_item_vxlan {
744         uint8_t flags; /**< Normally 0x08 (I flag). */
745         uint8_t rsvd0[3]; /**< Reserved, normally 0x000000. */
746         uint8_t vni[3]; /**< VXLAN identifier. */
747         uint8_t rsvd1; /**< Reserved, normally 0x00. */
748 };
749
750 /** Default mask for RTE_FLOW_ITEM_TYPE_VXLAN. */
751 #ifndef __cplusplus
752 static const struct rte_flow_item_vxlan rte_flow_item_vxlan_mask = {
753         .vni = "\xff\xff\xff",
754 };
755 #endif
756
757 /**
758  * RTE_FLOW_ITEM_TYPE_E_TAG.
759  *
760  * Matches a E-tag header.
761  *
762  * The corresponding standard outer EtherType (TPID) value is
763  * ETHER_TYPE_ETAG. It can be overridden by the preceding pattern item.
764  */
765 struct rte_flow_item_e_tag {
766         /**
767          * E-Tag control information (E-TCI).
768          * E-PCP (3b), E-DEI (1b), ingress E-CID base (12b).
769          */
770         rte_be16_t epcp_edei_in_ecid_b;
771         /** Reserved (2b), GRP (2b), E-CID base (12b). */
772         rte_be16_t rsvd_grp_ecid_b;
773         uint8_t in_ecid_e; /**< Ingress E-CID ext. */
774         uint8_t ecid_e; /**< E-CID ext. */
775         rte_be16_t inner_type; /**< Inner EtherType or TPID. */
776 };
777
778 /** Default mask for RTE_FLOW_ITEM_TYPE_E_TAG. */
779 #ifndef __cplusplus
780 static const struct rte_flow_item_e_tag rte_flow_item_e_tag_mask = {
781         .rsvd_grp_ecid_b = RTE_BE16(0x3fff),
782 };
783 #endif
784
785 /**
786  * RTE_FLOW_ITEM_TYPE_NVGRE.
787  *
788  * Matches a NVGRE header.
789  */
790 struct rte_flow_item_nvgre {
791         /**
792          * Checksum (1b), undefined (1b), key bit (1b), sequence number (1b),
793          * reserved 0 (9b), version (3b).
794          *
795          * c_k_s_rsvd0_ver must have value 0x2000 according to RFC 7637.
796          */
797         rte_be16_t c_k_s_rsvd0_ver;
798         rte_be16_t protocol; /**< Protocol type (0x6558). */
799         uint8_t tni[3]; /**< Virtual subnet ID. */
800         uint8_t flow_id; /**< Flow ID. */
801 };
802
803 /** Default mask for RTE_FLOW_ITEM_TYPE_NVGRE. */
804 #ifndef __cplusplus
805 static const struct rte_flow_item_nvgre rte_flow_item_nvgre_mask = {
806         .tni = "\xff\xff\xff",
807 };
808 #endif
809
810 /**
811  * RTE_FLOW_ITEM_TYPE_MPLS.
812  *
813  * Matches a MPLS header.
814  */
815 struct rte_flow_item_mpls {
816         /**
817          * Label (20b), TC (3b), Bottom of Stack (1b).
818          */
819         uint8_t label_tc_s[3];
820         uint8_t ttl; /** Time-to-Live. */
821 };
822
823 /** Default mask for RTE_FLOW_ITEM_TYPE_MPLS. */
824 #ifndef __cplusplus
825 static const struct rte_flow_item_mpls rte_flow_item_mpls_mask = {
826         .label_tc_s = "\xff\xff\xf0",
827 };
828 #endif
829
830 /**
831  * RTE_FLOW_ITEM_TYPE_GRE.
832  *
833  * Matches a GRE header.
834  */
835 struct rte_flow_item_gre {
836         /**
837          * Checksum (1b), reserved 0 (12b), version (3b).
838          * Refer to RFC 2784.
839          */
840         rte_be16_t c_rsvd0_ver;
841         rte_be16_t protocol; /**< Protocol type. */
842 };
843
844 /** Default mask for RTE_FLOW_ITEM_TYPE_GRE. */
845 #ifndef __cplusplus
846 static const struct rte_flow_item_gre rte_flow_item_gre_mask = {
847         .protocol = RTE_BE16(0xffff),
848 };
849 #endif
850
851 /**
852  * RTE_FLOW_ITEM_TYPE_FUZZY
853  *
854  * Fuzzy pattern match, expect faster than default.
855  *
856  * This is for device that support fuzzy match option.
857  * Usually a fuzzy match is fast but the cost is accuracy.
858  * i.e. Signature Match only match pattern's hash value, but it is
859  * possible two different patterns have the same hash value.
860  *
861  * Matching accuracy level can be configure by threshold.
862  * Driver can divide the range of threshold and map to different
863  * accuracy levels that device support.
864  *
865  * Threshold 0 means perfect match (no fuzziness), while threshold
866  * 0xffffffff means fuzziest match.
867  */
868 struct rte_flow_item_fuzzy {
869         uint32_t thresh; /**< Accuracy threshold. */
870 };
871
872 /** Default mask for RTE_FLOW_ITEM_TYPE_FUZZY. */
873 #ifndef __cplusplus
874 static const struct rte_flow_item_fuzzy rte_flow_item_fuzzy_mask = {
875         .thresh = 0xffffffff,
876 };
877 #endif
878
879 /**
880  * RTE_FLOW_ITEM_TYPE_GTP.
881  *
882  * Matches a GTPv1 header.
883  */
884 struct rte_flow_item_gtp {
885         /**
886          * Version (3b), protocol type (1b), reserved (1b),
887          * Extension header flag (1b),
888          * Sequence number flag (1b),
889          * N-PDU number flag (1b).
890          */
891         uint8_t v_pt_rsv_flags;
892         uint8_t msg_type; /**< Message type. */
893         rte_be16_t msg_len; /**< Message length. */
894         rte_be32_t teid; /**< Tunnel endpoint identifier. */
895 };
896
897 /** Default mask for RTE_FLOW_ITEM_TYPE_GTP. */
898 #ifndef __cplusplus
899 static const struct rte_flow_item_gtp rte_flow_item_gtp_mask = {
900         .teid = RTE_BE32(0xffffffff),
901 };
902 #endif
903
904 /**
905  * RTE_FLOW_ITEM_TYPE_ESP
906  *
907  * Matches an ESP header.
908  */
909 struct rte_flow_item_esp {
910         struct esp_hdr hdr; /**< ESP header definition. */
911 };
912
913 /** Default mask for RTE_FLOW_ITEM_TYPE_ESP. */
914 #ifndef __cplusplus
915 static const struct rte_flow_item_esp rte_flow_item_esp_mask = {
916         .hdr = {
917                 .spi = 0xffffffff,
918         },
919 };
920 #endif
921
922 /**
923  * RTE_FLOW_ITEM_TYPE_GENEVE.
924  *
925  * Matches a GENEVE header.
926  */
927 struct rte_flow_item_geneve {
928         /**
929          * Version (2b), length of the options fields (6b), OAM packet (1b),
930          * critical options present (1b), reserved 0 (6b).
931          */
932         rte_be16_t ver_opt_len_o_c_rsvd0;
933         rte_be16_t protocol; /**< Protocol type. */
934         uint8_t vni[3]; /**< Virtual Network Identifier. */
935         uint8_t rsvd1; /**< Reserved, normally 0x00. */
936 };
937
938 /** Default mask for RTE_FLOW_ITEM_TYPE_GENEVE. */
939 #ifndef __cplusplus
940 static const struct rte_flow_item_geneve rte_flow_item_geneve_mask = {
941         .vni = "\xff\xff\xff",
942 };
943 #endif
944
945 /**
946  * RTE_FLOW_ITEM_TYPE_VXLAN_GPE (draft-ietf-nvo3-vxlan-gpe-05).
947  *
948  * Matches a VXLAN-GPE header.
949  */
950 struct rte_flow_item_vxlan_gpe {
951         uint8_t flags; /**< Normally 0x0c (I and P flags). */
952         uint8_t rsvd0[2]; /**< Reserved, normally 0x0000. */
953         uint8_t protocol; /**< Protocol type. */
954         uint8_t vni[3]; /**< VXLAN identifier. */
955         uint8_t rsvd1; /**< Reserved, normally 0x00. */
956 };
957
958 /** Default mask for RTE_FLOW_ITEM_TYPE_VXLAN_GPE. */
959 #ifndef __cplusplus
960 static const struct rte_flow_item_vxlan_gpe rte_flow_item_vxlan_gpe_mask = {
961         .vni = "\xff\xff\xff",
962 };
963 #endif
964
965 /**
966  * RTE_FLOW_ITEM_TYPE_ARP_ETH_IPV4
967  *
968  * Matches an ARP header for Ethernet/IPv4.
969  */
970 struct rte_flow_item_arp_eth_ipv4 {
971         rte_be16_t hrd; /**< Hardware type, normally 1. */
972         rte_be16_t pro; /**< Protocol type, normally 0x0800. */
973         uint8_t hln; /**< Hardware address length, normally 6. */
974         uint8_t pln; /**< Protocol address length, normally 4. */
975         rte_be16_t op; /**< Opcode (1 for request, 2 for reply). */
976         struct ether_addr sha; /**< Sender hardware address. */
977         rte_be32_t spa; /**< Sender IPv4 address. */
978         struct ether_addr tha; /**< Target hardware address. */
979         rte_be32_t tpa; /**< Target IPv4 address. */
980 };
981
982 /** Default mask for RTE_FLOW_ITEM_TYPE_ARP_ETH_IPV4. */
983 #ifndef __cplusplus
984 static const struct rte_flow_item_arp_eth_ipv4
985 rte_flow_item_arp_eth_ipv4_mask = {
986         .sha.addr_bytes = "\xff\xff\xff\xff\xff\xff",
987         .spa = RTE_BE32(0xffffffff),
988         .tha.addr_bytes = "\xff\xff\xff\xff\xff\xff",
989         .tpa = RTE_BE32(0xffffffff),
990 };
991 #endif
992
993 /**
994  * RTE_FLOW_ITEM_TYPE_IPV6_EXT
995  *
996  * Matches the presence of any IPv6 extension header.
997  *
998  * Normally preceded by any of:
999  *
1000  * - RTE_FLOW_ITEM_TYPE_IPV6
1001  * - RTE_FLOW_ITEM_TYPE_IPV6_EXT
1002  */
1003 struct rte_flow_item_ipv6_ext {
1004         uint8_t next_hdr; /**< Next header. */
1005 };
1006
1007 /** Default mask for RTE_FLOW_ITEM_TYPE_IPV6_EXT. */
1008 #ifndef __cplusplus
1009 static const
1010 struct rte_flow_item_ipv6_ext rte_flow_item_ipv6_ext_mask = {
1011         .next_hdr = 0xff,
1012 };
1013 #endif
1014
1015 /**
1016  * RTE_FLOW_ITEM_TYPE_ICMP6
1017  *
1018  * Matches any ICMPv6 header.
1019  */
1020 struct rte_flow_item_icmp6 {
1021         uint8_t type; /**< ICMPv6 type. */
1022         uint8_t code; /**< ICMPv6 code. */
1023         uint16_t checksum; /**< ICMPv6 checksum. */
1024 };
1025
1026 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP6. */
1027 #ifndef __cplusplus
1028 static const struct rte_flow_item_icmp6 rte_flow_item_icmp6_mask = {
1029         .type = 0xff,
1030         .code = 0xff,
1031 };
1032 #endif
1033
1034 /**
1035  * RTE_FLOW_ITEM_TYPE_ICMP6_ND_NS
1036  *
1037  * Matches an ICMPv6 neighbor discovery solicitation.
1038  */
1039 struct rte_flow_item_icmp6_nd_ns {
1040         uint8_t type; /**< ICMPv6 type, normally 135. */
1041         uint8_t code; /**< ICMPv6 code, normally 0. */
1042         rte_be16_t checksum; /**< ICMPv6 checksum. */
1043         rte_be32_t reserved; /**< Reserved, normally 0. */
1044         uint8_t target_addr[16]; /**< Target address. */
1045 };
1046
1047 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP6_ND_NS. */
1048 #ifndef __cplusplus
1049 static const
1050 struct rte_flow_item_icmp6_nd_ns rte_flow_item_icmp6_nd_ns_mask = {
1051         .target_addr =
1052                 "\xff\xff\xff\xff\xff\xff\xff\xff"
1053                 "\xff\xff\xff\xff\xff\xff\xff\xff",
1054 };
1055 #endif
1056
1057 /**
1058  * RTE_FLOW_ITEM_TYPE_ICMP6_ND_NA
1059  *
1060  * Matches an ICMPv6 neighbor discovery advertisement.
1061  */
1062 struct rte_flow_item_icmp6_nd_na {
1063         uint8_t type; /**< ICMPv6 type, normally 136. */
1064         uint8_t code; /**< ICMPv6 code, normally 0. */
1065         rte_be16_t checksum; /**< ICMPv6 checksum. */
1066         /**
1067          * Route flag (1b), solicited flag (1b), override flag (1b),
1068          * reserved (29b).
1069          */
1070         rte_be32_t rso_reserved;
1071         uint8_t target_addr[16]; /**< Target address. */
1072 };
1073
1074 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP6_ND_NA. */
1075 #ifndef __cplusplus
1076 static const
1077 struct rte_flow_item_icmp6_nd_na rte_flow_item_icmp6_nd_na_mask = {
1078         .target_addr =
1079                 "\xff\xff\xff\xff\xff\xff\xff\xff"
1080                 "\xff\xff\xff\xff\xff\xff\xff\xff",
1081 };
1082 #endif
1083
1084 /**
1085  * RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT
1086  *
1087  * Matches the presence of any ICMPv6 neighbor discovery option.
1088  *
1089  * Normally preceded by any of:
1090  *
1091  * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_NA
1092  * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_NS
1093  * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT
1094  */
1095 struct rte_flow_item_icmp6_nd_opt {
1096         uint8_t type; /**< ND option type. */
1097         uint8_t length; /**< ND option length. */
1098 };
1099
1100 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT. */
1101 #ifndef __cplusplus
1102 static const struct rte_flow_item_icmp6_nd_opt
1103 rte_flow_item_icmp6_nd_opt_mask = {
1104         .type = 0xff,
1105 };
1106 #endif
1107
1108 /**
1109  * RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT_SLA_ETH
1110  *
1111  * Matches an ICMPv6 neighbor discovery source Ethernet link-layer address
1112  * option.
1113  *
1114  * Normally preceded by any of:
1115  *
1116  * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_NA
1117  * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT
1118  */
1119 struct rte_flow_item_icmp6_nd_opt_sla_eth {
1120         uint8_t type; /**< ND option type, normally 1. */
1121         uint8_t length; /**< ND option length, normally 1. */
1122         struct ether_addr sla; /**< Source Ethernet LLA. */
1123 };
1124
1125 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT_SLA_ETH. */
1126 #ifndef __cplusplus
1127 static const struct rte_flow_item_icmp6_nd_opt_sla_eth
1128 rte_flow_item_icmp6_nd_opt_sla_eth_mask = {
1129         .sla.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1130 };
1131 #endif
1132
1133 /**
1134  * RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT_TLA_ETH
1135  *
1136  * Matches an ICMPv6 neighbor discovery target Ethernet link-layer address
1137  * option.
1138  *
1139  * Normally preceded by any of:
1140  *
1141  * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_NS
1142  * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT
1143  */
1144 struct rte_flow_item_icmp6_nd_opt_tla_eth {
1145         uint8_t type; /**< ND option type, normally 2. */
1146         uint8_t length; /**< ND option length, normally 1. */
1147         struct ether_addr tla; /**< Target Ethernet LLA. */
1148 };
1149
1150 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT_TLA_ETH. */
1151 #ifndef __cplusplus
1152 static const struct rte_flow_item_icmp6_nd_opt_tla_eth
1153 rte_flow_item_icmp6_nd_opt_tla_eth_mask = {
1154         .tla.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1155 };
1156 #endif
1157
1158 /**
1159  * @warning
1160  * @b EXPERIMENTAL: this structure may change without prior notice
1161  *
1162  * RTE_FLOW_ITEM_TYPE_MARK
1163  *
1164  * Matches an arbitrary integer value which was set using the ``MARK`` action
1165  * in a previously matched rule.
1166  *
1167  * This item can only be specified once as a match criteria as the ``MARK``
1168  * action can only be specified once in a flow action.
1169  *
1170  * This value is arbitrary and application-defined. Maximum allowed value
1171  * depends on the underlying implementation.
1172  *
1173  * Depending on the underlying implementation the MARK item may be supported on
1174  * the physical device, with virtual groups in the PMD or not at all.
1175  */
1176 struct rte_flow_item_mark {
1177         uint32_t id; /**< Integer value to match against. */
1178 };
1179
1180 /**
1181  * Matching pattern item definition.
1182  *
1183  * A pattern is formed by stacking items starting from the lowest protocol
1184  * layer to match. This stacking restriction does not apply to meta items
1185  * which can be placed anywhere in the stack without affecting the meaning
1186  * of the resulting pattern.
1187  *
1188  * Patterns are terminated by END items.
1189  *
1190  * The spec field should be a valid pointer to a structure of the related
1191  * item type. It may remain unspecified (NULL) in many cases to request
1192  * broad (nonspecific) matching. In such cases, last and mask must also be
1193  * set to NULL.
1194  *
1195  * Optionally, last can point to a structure of the same type to define an
1196  * inclusive range. This is mostly supported by integer and address fields,
1197  * may cause errors otherwise. Fields that do not support ranges must be set
1198  * to 0 or to the same value as the corresponding fields in spec.
1199  *
1200  * Only the fields defined to nonzero values in the default masks (see
1201  * rte_flow_item_{name}_mask constants) are considered relevant by
1202  * default. This can be overridden by providing a mask structure of the
1203  * same type with applicable bits set to one. It can also be used to
1204  * partially filter out specific fields (e.g. as an alternate mean to match
1205  * ranges of IP addresses).
1206  *
1207  * Mask is a simple bit-mask applied before interpreting the contents of
1208  * spec and last, which may yield unexpected results if not used
1209  * carefully. For example, if for an IPv4 address field, spec provides
1210  * 10.1.2.3, last provides 10.3.4.5 and mask provides 255.255.0.0, the
1211  * effective range becomes 10.1.0.0 to 10.3.255.255.
1212  */
1213 struct rte_flow_item {
1214         enum rte_flow_item_type type; /**< Item type. */
1215         const void *spec; /**< Pointer to item specification structure. */
1216         const void *last; /**< Defines an inclusive range (spec to last). */
1217         const void *mask; /**< Bit-mask applied to spec and last. */
1218 };
1219
1220 /**
1221  * Action types.
1222  *
1223  * Each possible action is represented by a type. Some have associated
1224  * configuration structures. Several actions combined in a list can be
1225  * assigned to a flow rule and are performed in order.
1226  *
1227  * They fall in three categories:
1228  *
1229  * - Actions that modify the fate of matching traffic, for instance by
1230  *   dropping or assigning it a specific destination.
1231  *
1232  * - Actions that modify matching traffic contents or its properties. This
1233  *   includes adding/removing encapsulation, encryption, compression and
1234  *   marks.
1235  *
1236  * - Actions related to the flow rule itself, such as updating counters or
1237  *   making it non-terminating.
1238  *
1239  * Flow rules being terminating by default, not specifying any action of the
1240  * fate kind results in undefined behavior. This applies to both ingress and
1241  * egress.
1242  *
1243  * PASSTHRU, when supported, makes a flow rule non-terminating.
1244  */
1245 enum rte_flow_action_type {
1246         /**
1247          * End marker for action lists. Prevents further processing of
1248          * actions, thereby ending the list.
1249          *
1250          * No associated configuration structure.
1251          */
1252         RTE_FLOW_ACTION_TYPE_END,
1253
1254         /**
1255          * Used as a placeholder for convenience. It is ignored and simply
1256          * discarded by PMDs.
1257          *
1258          * No associated configuration structure.
1259          */
1260         RTE_FLOW_ACTION_TYPE_VOID,
1261
1262         /**
1263          * Leaves traffic up for additional processing by subsequent flow
1264          * rules; makes a flow rule non-terminating.
1265          *
1266          * No associated configuration structure.
1267          */
1268         RTE_FLOW_ACTION_TYPE_PASSTHRU,
1269
1270         /**
1271          * RTE_FLOW_ACTION_TYPE_JUMP
1272          *
1273          * Redirects packets to a group on the current device.
1274          *
1275          * See struct rte_flow_action_jump.
1276          */
1277         RTE_FLOW_ACTION_TYPE_JUMP,
1278
1279         /**
1280          * Attaches an integer value to packets and sets PKT_RX_FDIR and
1281          * PKT_RX_FDIR_ID mbuf flags.
1282          *
1283          * See struct rte_flow_action_mark.
1284          */
1285         RTE_FLOW_ACTION_TYPE_MARK,
1286
1287         /**
1288          * Flags packets. Similar to MARK without a specific value; only
1289          * sets the PKT_RX_FDIR mbuf flag.
1290          *
1291          * No associated configuration structure.
1292          */
1293         RTE_FLOW_ACTION_TYPE_FLAG,
1294
1295         /**
1296          * Assigns packets to a given queue index.
1297          *
1298          * See struct rte_flow_action_queue.
1299          */
1300         RTE_FLOW_ACTION_TYPE_QUEUE,
1301
1302         /**
1303          * Drops packets.
1304          *
1305          * PASSTHRU overrides this action if both are specified.
1306          *
1307          * No associated configuration structure.
1308          */
1309         RTE_FLOW_ACTION_TYPE_DROP,
1310
1311         /**
1312          * Enables counters for this flow rule.
1313          *
1314          * These counters can be retrieved and reset through rte_flow_query(),
1315          * see struct rte_flow_query_count.
1316          *
1317          * See struct rte_flow_action_count.
1318          */
1319         RTE_FLOW_ACTION_TYPE_COUNT,
1320
1321         /**
1322          * Similar to QUEUE, except RSS is additionally performed on packets
1323          * to spread them among several queues according to the provided
1324          * parameters.
1325          *
1326          * See struct rte_flow_action_rss.
1327          */
1328         RTE_FLOW_ACTION_TYPE_RSS,
1329
1330         /**
1331          * Directs matching traffic to the physical function (PF) of the
1332          * current device.
1333          *
1334          * No associated configuration structure.
1335          */
1336         RTE_FLOW_ACTION_TYPE_PF,
1337
1338         /**
1339          * Directs matching traffic to a given virtual function of the
1340          * current device.
1341          *
1342          * See struct rte_flow_action_vf.
1343          */
1344         RTE_FLOW_ACTION_TYPE_VF,
1345
1346         /**
1347          * Directs packets to a given physical port index of the underlying
1348          * device.
1349          *
1350          * See struct rte_flow_action_phy_port.
1351          */
1352         RTE_FLOW_ACTION_TYPE_PHY_PORT,
1353
1354         /**
1355          * Directs matching traffic to a given DPDK port ID.
1356          *
1357          * See struct rte_flow_action_port_id.
1358          */
1359         RTE_FLOW_ACTION_TYPE_PORT_ID,
1360
1361         /**
1362          * Traffic metering and policing (MTR).
1363          *
1364          * See struct rte_flow_action_meter.
1365          * See file rte_mtr.h for MTR object configuration.
1366          */
1367         RTE_FLOW_ACTION_TYPE_METER,
1368
1369         /**
1370          * Redirects packets to security engine of current device for security
1371          * processing as specified by security session.
1372          *
1373          * See struct rte_flow_action_security.
1374          */
1375         RTE_FLOW_ACTION_TYPE_SECURITY,
1376
1377         /**
1378          * Implements OFPAT_SET_MPLS_TTL ("MPLS TTL") as defined by the
1379          * OpenFlow Switch Specification.
1380          *
1381          * See struct rte_flow_action_of_set_mpls_ttl.
1382          */
1383         RTE_FLOW_ACTION_TYPE_OF_SET_MPLS_TTL,
1384
1385         /**
1386          * Implements OFPAT_DEC_MPLS_TTL ("decrement MPLS TTL") as defined
1387          * by the OpenFlow Switch Specification.
1388          *
1389          * No associated configuration structure.
1390          */
1391         RTE_FLOW_ACTION_TYPE_OF_DEC_MPLS_TTL,
1392
1393         /**
1394          * Implements OFPAT_SET_NW_TTL ("IP TTL") as defined by the OpenFlow
1395          * Switch Specification.
1396          *
1397          * See struct rte_flow_action_of_set_nw_ttl.
1398          */
1399         RTE_FLOW_ACTION_TYPE_OF_SET_NW_TTL,
1400
1401         /**
1402          * Implements OFPAT_DEC_NW_TTL ("decrement IP TTL") as defined by
1403          * the OpenFlow Switch Specification.
1404          *
1405          * No associated configuration structure.
1406          */
1407         RTE_FLOW_ACTION_TYPE_OF_DEC_NW_TTL,
1408
1409         /**
1410          * Implements OFPAT_COPY_TTL_OUT ("copy TTL "outwards" -- from
1411          * next-to-outermost to outermost") as defined by the OpenFlow
1412          * Switch Specification.
1413          *
1414          * No associated configuration structure.
1415          */
1416         RTE_FLOW_ACTION_TYPE_OF_COPY_TTL_OUT,
1417
1418         /**
1419          * Implements OFPAT_COPY_TTL_IN ("copy TTL "inwards" -- from
1420          * outermost to next-to-outermost") as defined by the OpenFlow
1421          * Switch Specification.
1422          *
1423          * No associated configuration structure.
1424          */
1425         RTE_FLOW_ACTION_TYPE_OF_COPY_TTL_IN,
1426
1427         /**
1428          * Implements OFPAT_POP_VLAN ("pop the outer VLAN tag") as defined
1429          * by the OpenFlow Switch Specification.
1430          *
1431          * No associated configuration structure.
1432          */
1433         RTE_FLOW_ACTION_TYPE_OF_POP_VLAN,
1434
1435         /**
1436          * Implements OFPAT_PUSH_VLAN ("push a new VLAN tag") as defined by
1437          * the OpenFlow Switch Specification.
1438          *
1439          * See struct rte_flow_action_of_push_vlan.
1440          */
1441         RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN,
1442
1443         /**
1444          * Implements OFPAT_SET_VLAN_VID ("set the 802.1q VLAN id") as
1445          * defined by the OpenFlow Switch Specification.
1446          *
1447          * See struct rte_flow_action_of_set_vlan_vid.
1448          */
1449         RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID,
1450
1451         /**
1452          * Implements OFPAT_SET_LAN_PCP ("set the 802.1q priority") as
1453          * defined by the OpenFlow Switch Specification.
1454          *
1455          * See struct rte_flow_action_of_set_vlan_pcp.
1456          */
1457         RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP,
1458
1459         /**
1460          * Implements OFPAT_POP_MPLS ("pop the outer MPLS tag") as defined
1461          * by the OpenFlow Switch Specification.
1462          *
1463          * See struct rte_flow_action_of_pop_mpls.
1464          */
1465         RTE_FLOW_ACTION_TYPE_OF_POP_MPLS,
1466
1467         /**
1468          * Implements OFPAT_PUSH_MPLS ("push a new MPLS tag") as defined by
1469          * the OpenFlow Switch Specification.
1470          *
1471          * See struct rte_flow_action_of_push_mpls.
1472          */
1473         RTE_FLOW_ACTION_TYPE_OF_PUSH_MPLS,
1474
1475         /**
1476          * Encapsulate flow in VXLAN tunnel as defined in
1477          * rte_flow_action_vxlan_encap action structure.
1478          *
1479          * See struct rte_flow_action_vxlan_encap.
1480          */
1481         RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP,
1482
1483         /**
1484          * Decapsulate outer most VXLAN tunnel from matched flow.
1485          *
1486          * If flow pattern does not define a valid VXLAN tunnel (as specified by
1487          * RFC7348) then the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION
1488          * error.
1489          */
1490         RTE_FLOW_ACTION_TYPE_VXLAN_DECAP,
1491
1492         /**
1493          * Encapsulate flow in NVGRE tunnel defined in the
1494          * rte_flow_action_nvgre_encap action structure.
1495          *
1496          * See struct rte_flow_action_nvgre_encap.
1497          */
1498         RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP,
1499
1500         /**
1501          * Decapsulate outer most NVGRE tunnel from matched flow.
1502          *
1503          * If flow pattern does not define a valid NVGRE tunnel (as specified by
1504          * RFC7637) then the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION
1505          * error.
1506          */
1507         RTE_FLOW_ACTION_TYPE_NVGRE_DECAP,
1508 };
1509
1510 /**
1511  * RTE_FLOW_ACTION_TYPE_MARK
1512  *
1513  * Attaches an integer value to packets and sets PKT_RX_FDIR and
1514  * PKT_RX_FDIR_ID mbuf flags.
1515  *
1516  * This value is arbitrary and application-defined. Maximum allowed value
1517  * depends on the underlying implementation. It is returned in the
1518  * hash.fdir.hi mbuf field.
1519  */
1520 struct rte_flow_action_mark {
1521         uint32_t id; /**< Integer value to return with packets. */
1522 };
1523
1524 /**
1525  * @warning
1526  * @b EXPERIMENTAL: this structure may change without prior notice
1527  *
1528  * RTE_FLOW_ACTION_TYPE_JUMP
1529  *
1530  * Redirects packets to a group on the current device.
1531  *
1532  * In a hierarchy of groups, which can be used to represent physical or logical
1533  * flow tables on the device, this action allows the action to be a redirect to
1534  * a group on that device.
1535  */
1536 struct rte_flow_action_jump {
1537         uint32_t group;
1538 };
1539
1540 /**
1541  * RTE_FLOW_ACTION_TYPE_QUEUE
1542  *
1543  * Assign packets to a given queue index.
1544  */
1545 struct rte_flow_action_queue {
1546         uint16_t index; /**< Queue index to use. */
1547 };
1548
1549
1550 /**
1551  * @warning
1552  * @b EXPERIMENTAL: this structure may change without prior notice
1553  *
1554  * RTE_FLOW_ACTION_TYPE_COUNT
1555  *
1556  * Adds a counter action to a matched flow.
1557  *
1558  * If more than one count action is specified in a single flow rule, then each
1559  * action must specify a unique id.
1560  *
1561  * Counters can be retrieved and reset through ``rte_flow_query()``, see
1562  * ``struct rte_flow_query_count``.
1563  *
1564  * The shared flag indicates whether the counter is unique to the flow rule the
1565  * action is specified with, or whether it is a shared counter.
1566  *
1567  * For a count action with the shared flag set, then then a global device
1568  * namespace is assumed for the counter id, so that any matched flow rules using
1569  * a count action with the same counter id on the same port will contribute to
1570  * that counter.
1571  *
1572  * For ports within the same switch domain then the counter id namespace extends
1573  * to all ports within that switch domain.
1574  */
1575 struct rte_flow_action_count {
1576         uint32_t shared:1; /**< Share counter ID with other flow rules. */
1577         uint32_t reserved:31; /**< Reserved, must be zero. */
1578         uint32_t id; /**< Counter ID. */
1579 };
1580
1581 /**
1582  * RTE_FLOW_ACTION_TYPE_COUNT (query)
1583  *
1584  * Query structure to retrieve and reset flow rule counters.
1585  */
1586 struct rte_flow_query_count {
1587         uint32_t reset:1; /**< Reset counters after query [in]. */
1588         uint32_t hits_set:1; /**< hits field is set [out]. */
1589         uint32_t bytes_set:1; /**< bytes field is set [out]. */
1590         uint32_t reserved:29; /**< Reserved, must be zero [in, out]. */
1591         uint64_t hits; /**< Number of hits for this rule [out]. */
1592         uint64_t bytes; /**< Number of bytes through this rule [out]. */
1593 };
1594
1595 /**
1596  * RTE_FLOW_ACTION_TYPE_RSS
1597  *
1598  * Similar to QUEUE, except RSS is additionally performed on packets to
1599  * spread them among several queues according to the provided parameters.
1600  *
1601  * Unlike global RSS settings used by other DPDK APIs, unsetting the
1602  * @p types field does not disable RSS in a flow rule. Doing so instead
1603  * requests safe unspecified "best-effort" settings from the underlying PMD,
1604  * which depending on the flow rule, may result in anything ranging from
1605  * empty (single queue) to all-inclusive RSS.
1606  *
1607  * Note: RSS hash result is stored in the hash.rss mbuf field which overlaps
1608  * hash.fdir.lo. Since the MARK action sets the hash.fdir.hi field only,
1609  * both can be requested simultaneously.
1610  */
1611 struct rte_flow_action_rss {
1612         enum rte_eth_hash_function func; /**< RSS hash function to apply. */
1613         /**
1614          * Packet encapsulation level RSS hash @p types apply to.
1615          *
1616          * - @p 0 requests the default behavior. Depending on the packet
1617          *   type, it can mean outermost, innermost, anything in between or
1618          *   even no RSS.
1619          *
1620          *   It basically stands for the innermost encapsulation level RSS
1621          *   can be performed on according to PMD and device capabilities.
1622          *
1623          * - @p 1 requests RSS to be performed on the outermost packet
1624          *   encapsulation level.
1625          *
1626          * - @p 2 and subsequent values request RSS to be performed on the
1627          *   specified inner packet encapsulation level, from outermost to
1628          *   innermost (lower to higher values).
1629          *
1630          * Values other than @p 0 are not necessarily supported.
1631          *
1632          * Requesting a specific RSS level on unrecognized traffic results
1633          * in undefined behavior. For predictable results, it is recommended
1634          * to make the flow rule pattern match packet headers up to the
1635          * requested encapsulation level so that only matching traffic goes
1636          * through.
1637          */
1638         uint32_t level;
1639         uint64_t types; /**< Specific RSS hash types (see ETH_RSS_*). */
1640         uint32_t key_len; /**< Hash key length in bytes. */
1641         uint32_t queue_num; /**< Number of entries in @p queue. */
1642         const uint8_t *key; /**< Hash key. */
1643         const uint16_t *queue; /**< Queue indices to use. */
1644 };
1645
1646 /**
1647  * RTE_FLOW_ACTION_TYPE_VF
1648  *
1649  * Directs matching traffic to a given virtual function of the current
1650  * device.
1651  *
1652  * Packets matched by a VF pattern item can be redirected to their original
1653  * VF ID instead of the specified one. This parameter may not be available
1654  * and is not guaranteed to work properly if the VF part is matched by a
1655  * prior flow rule or if packets are not addressed to a VF in the first
1656  * place.
1657  */
1658 struct rte_flow_action_vf {
1659         uint32_t original:1; /**< Use original VF ID if possible. */
1660         uint32_t reserved:31; /**< Reserved, must be zero. */
1661         uint32_t id; /**< VF ID. */
1662 };
1663
1664 /**
1665  * RTE_FLOW_ACTION_TYPE_PHY_PORT
1666  *
1667  * Directs packets to a given physical port index of the underlying
1668  * device.
1669  *
1670  * @see RTE_FLOW_ITEM_TYPE_PHY_PORT
1671  */
1672 struct rte_flow_action_phy_port {
1673         uint32_t original:1; /**< Use original port index if possible. */
1674         uint32_t reserved:31; /**< Reserved, must be zero. */
1675         uint32_t index; /**< Physical port index. */
1676 };
1677
1678 /**
1679  * RTE_FLOW_ACTION_TYPE_PORT_ID
1680  *
1681  * Directs matching traffic to a given DPDK port ID.
1682  *
1683  * @see RTE_FLOW_ITEM_TYPE_PORT_ID
1684  */
1685 struct rte_flow_action_port_id {
1686         uint32_t original:1; /**< Use original DPDK port ID if possible. */
1687         uint32_t reserved:31; /**< Reserved, must be zero. */
1688         uint32_t id; /**< DPDK port ID. */
1689 };
1690
1691 /**
1692  * RTE_FLOW_ACTION_TYPE_METER
1693  *
1694  * Traffic metering and policing (MTR).
1695  *
1696  * Packets matched by items of this type can be either dropped or passed to the
1697  * next item with their color set by the MTR object.
1698  */
1699 struct rte_flow_action_meter {
1700         uint32_t mtr_id; /**< MTR object ID created with rte_mtr_create(). */
1701 };
1702
1703 /**
1704  * RTE_FLOW_ACTION_TYPE_SECURITY
1705  *
1706  * Perform the security action on flows matched by the pattern items
1707  * according to the configuration of the security session.
1708  *
1709  * This action modifies the payload of matched flows. For INLINE_CRYPTO, the
1710  * security protocol headers and IV are fully provided by the application as
1711  * specified in the flow pattern. The payload of matching packets is
1712  * encrypted on egress, and decrypted and authenticated on ingress.
1713  * For INLINE_PROTOCOL, the security protocol is fully offloaded to HW,
1714  * providing full encapsulation and decapsulation of packets in security
1715  * protocols. The flow pattern specifies both the outer security header fields
1716  * and the inner packet fields. The security session specified in the action
1717  * must match the pattern parameters.
1718  *
1719  * The security session specified in the action must be created on the same
1720  * port as the flow action that is being specified.
1721  *
1722  * The ingress/egress flow attribute should match that specified in the
1723  * security session if the security session supports the definition of the
1724  * direction.
1725  *
1726  * Multiple flows can be configured to use the same security session.
1727  */
1728 struct rte_flow_action_security {
1729         void *security_session; /**< Pointer to security session structure. */
1730 };
1731
1732 /**
1733  * RTE_FLOW_ACTION_TYPE_OF_SET_MPLS_TTL
1734  *
1735  * Implements OFPAT_SET_MPLS_TTL ("MPLS TTL") as defined by the OpenFlow
1736  * Switch Specification.
1737  */
1738 struct rte_flow_action_of_set_mpls_ttl {
1739         uint8_t mpls_ttl; /**< MPLS TTL. */
1740 };
1741
1742 /**
1743  * RTE_FLOW_ACTION_TYPE_OF_SET_NW_TTL
1744  *
1745  * Implements OFPAT_SET_NW_TTL ("IP TTL") as defined by the OpenFlow Switch
1746  * Specification.
1747  */
1748 struct rte_flow_action_of_set_nw_ttl {
1749         uint8_t nw_ttl; /**< IP TTL. */
1750 };
1751
1752 /**
1753  * RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN
1754  *
1755  * Implements OFPAT_PUSH_VLAN ("push a new VLAN tag") as defined by the
1756  * OpenFlow Switch Specification.
1757  */
1758 struct rte_flow_action_of_push_vlan {
1759         rte_be16_t ethertype; /**< EtherType. */
1760 };
1761
1762 /**
1763  * RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID
1764  *
1765  * Implements OFPAT_SET_VLAN_VID ("set the 802.1q VLAN id") as defined by
1766  * the OpenFlow Switch Specification.
1767  */
1768 struct rte_flow_action_of_set_vlan_vid {
1769         rte_be16_t vlan_vid; /**< VLAN id. */
1770 };
1771
1772 /**
1773  * RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP
1774  *
1775  * Implements OFPAT_SET_LAN_PCP ("set the 802.1q priority") as defined by
1776  * the OpenFlow Switch Specification.
1777  */
1778 struct rte_flow_action_of_set_vlan_pcp {
1779         uint8_t vlan_pcp; /**< VLAN priority. */
1780 };
1781
1782 /**
1783  * RTE_FLOW_ACTION_TYPE_OF_POP_MPLS
1784  *
1785  * Implements OFPAT_POP_MPLS ("pop the outer MPLS tag") as defined by the
1786  * OpenFlow Switch Specification.
1787  */
1788 struct rte_flow_action_of_pop_mpls {
1789         rte_be16_t ethertype; /**< EtherType. */
1790 };
1791
1792 /**
1793  * RTE_FLOW_ACTION_TYPE_OF_PUSH_MPLS
1794  *
1795  * Implements OFPAT_PUSH_MPLS ("push a new MPLS tag") as defined by the
1796  * OpenFlow Switch Specification.
1797  */
1798 struct rte_flow_action_of_push_mpls {
1799         rte_be16_t ethertype; /**< EtherType. */
1800 };
1801
1802 /**
1803  * @warning
1804  * @b EXPERIMENTAL: this structure may change without prior notice
1805  *
1806  * RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP
1807  *
1808  * VXLAN tunnel end-point encapsulation data definition
1809  *
1810  * The tunnel definition is provided through the flow item pattern, the
1811  * provided pattern must conform to RFC7348 for the tunnel specified. The flow
1812  * definition must be provided in order from the RTE_FLOW_ITEM_TYPE_ETH
1813  * definition up the end item which is specified by RTE_FLOW_ITEM_TYPE_END.
1814  *
1815  * The mask field allows user to specify which fields in the flow item
1816  * definitions can be ignored and which have valid data and can be used
1817  * verbatim.
1818  *
1819  * Note: the last field is not used in the definition of a tunnel and can be
1820  * ignored.
1821  *
1822  * Valid flow definition for RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP include:
1823  *
1824  * - ETH / IPV4 / UDP / VXLAN / END
1825  * - ETH / IPV6 / UDP / VXLAN / END
1826  * - ETH / VLAN / IPV4 / UDP / VXLAN / END
1827  *
1828  */
1829 struct rte_flow_action_vxlan_encap {
1830         /**
1831          * Encapsulating vxlan tunnel definition
1832          * (terminated by the END pattern item).
1833          */
1834         struct rte_flow_item *definition;
1835 };
1836
1837 /**
1838  * @warning
1839  * @b EXPERIMENTAL: this structure may change without prior notice
1840  *
1841  * RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP
1842  *
1843  * NVGRE tunnel end-point encapsulation data definition
1844  *
1845  * The tunnel definition is provided through the flow item pattern  the
1846  * provided pattern must conform with RFC7637. The flow definition must be
1847  * provided in order from the RTE_FLOW_ITEM_TYPE_ETH definition up the end item
1848  * which is specified by RTE_FLOW_ITEM_TYPE_END.
1849  *
1850  * The mask field allows user to specify which fields in the flow item
1851  * definitions can be ignored and which have valid data and can be used
1852  * verbatim.
1853  *
1854  * Note: the last field is not used in the definition of a tunnel and can be
1855  * ignored.
1856  *
1857  * Valid flow definition for RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP include:
1858  *
1859  * - ETH / IPV4 / NVGRE / END
1860  * - ETH / VLAN / IPV6 / NVGRE / END
1861  *
1862  */
1863 struct rte_flow_action_nvgre_encap {
1864         /**
1865          * Encapsulating vxlan tunnel definition
1866          * (terminated by the END pattern item).
1867          */
1868         struct rte_flow_item *definition;
1869 };
1870
1871 /*
1872  * Definition of a single action.
1873  *
1874  * A list of actions is terminated by a END action.
1875  *
1876  * For simple actions without a configuration structure, conf remains NULL.
1877  */
1878 struct rte_flow_action {
1879         enum rte_flow_action_type type; /**< Action type. */
1880         const void *conf; /**< Pointer to action configuration structure. */
1881 };
1882
1883 /**
1884  * Opaque type returned after successfully creating a flow.
1885  *
1886  * This handle can be used to manage and query the related flow (e.g. to
1887  * destroy it or retrieve counters).
1888  */
1889 struct rte_flow;
1890
1891 /**
1892  * Verbose error types.
1893  *
1894  * Most of them provide the type of the object referenced by struct
1895  * rte_flow_error.cause.
1896  */
1897 enum rte_flow_error_type {
1898         RTE_FLOW_ERROR_TYPE_NONE, /**< No error. */
1899         RTE_FLOW_ERROR_TYPE_UNSPECIFIED, /**< Cause unspecified. */
1900         RTE_FLOW_ERROR_TYPE_HANDLE, /**< Flow rule (handle). */
1901         RTE_FLOW_ERROR_TYPE_ATTR_GROUP, /**< Group field. */
1902         RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY, /**< Priority field. */
1903         RTE_FLOW_ERROR_TYPE_ATTR_INGRESS, /**< Ingress field. */
1904         RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, /**< Egress field. */
1905         RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER, /**< Transfer field. */
1906         RTE_FLOW_ERROR_TYPE_ATTR, /**< Attributes structure. */
1907         RTE_FLOW_ERROR_TYPE_ITEM_NUM, /**< Pattern length. */
1908         RTE_FLOW_ERROR_TYPE_ITEM_SPEC, /**< Item specification. */
1909         RTE_FLOW_ERROR_TYPE_ITEM_LAST, /**< Item specification range. */
1910         RTE_FLOW_ERROR_TYPE_ITEM_MASK, /**< Item specification mask. */
1911         RTE_FLOW_ERROR_TYPE_ITEM, /**< Specific pattern item. */
1912         RTE_FLOW_ERROR_TYPE_ACTION_NUM, /**< Number of actions. */
1913         RTE_FLOW_ERROR_TYPE_ACTION_CONF, /**< Action configuration. */
1914         RTE_FLOW_ERROR_TYPE_ACTION, /**< Specific action. */
1915 };
1916
1917 /**
1918  * Verbose error structure definition.
1919  *
1920  * This object is normally allocated by applications and set by PMDs, the
1921  * message points to a constant string which does not need to be freed by
1922  * the application, however its pointer can be considered valid only as long
1923  * as its associated DPDK port remains configured. Closing the underlying
1924  * device or unloading the PMD invalidates it.
1925  *
1926  * Both cause and message may be NULL regardless of the error type.
1927  */
1928 struct rte_flow_error {
1929         enum rte_flow_error_type type; /**< Cause field and error types. */
1930         const void *cause; /**< Object responsible for the error. */
1931         const char *message; /**< Human-readable error message. */
1932 };
1933
1934 /**
1935  * Check whether a flow rule can be created on a given port.
1936  *
1937  * The flow rule is validated for correctness and whether it could be accepted
1938  * by the device given sufficient resources. The rule is checked against the
1939  * current device mode and queue configuration. The flow rule may also
1940  * optionally be validated against existing flow rules and device resources.
1941  * This function has no effect on the target device.
1942  *
1943  * The returned value is guaranteed to remain valid only as long as no
1944  * successful calls to rte_flow_create() or rte_flow_destroy() are made in
1945  * the meantime and no device parameter affecting flow rules in any way are
1946  * modified, due to possible collisions or resource limitations (although in
1947  * such cases EINVAL should not be returned).
1948  *
1949  * @param port_id
1950  *   Port identifier of Ethernet device.
1951  * @param[in] attr
1952  *   Flow rule attributes.
1953  * @param[in] pattern
1954  *   Pattern specification (list terminated by the END pattern item).
1955  * @param[in] actions
1956  *   Associated actions (list terminated by the END action).
1957  * @param[out] error
1958  *   Perform verbose error reporting if not NULL. PMDs initialize this
1959  *   structure in case of error only.
1960  *
1961  * @return
1962  *   0 if flow rule is valid and can be created. A negative errno value
1963  *   otherwise (rte_errno is also set), the following errors are defined:
1964  *
1965  *   -ENOSYS: underlying device does not support this functionality.
1966  *
1967  *   -EIO: underlying device is removed.
1968  *
1969  *   -EINVAL: unknown or invalid rule specification.
1970  *
1971  *   -ENOTSUP: valid but unsupported rule specification (e.g. partial
1972  *   bit-masks are unsupported).
1973  *
1974  *   -EEXIST: collision with an existing rule. Only returned if device
1975  *   supports flow rule collision checking and there was a flow rule
1976  *   collision. Not receiving this return code is no guarantee that creating
1977  *   the rule will not fail due to a collision.
1978  *
1979  *   -ENOMEM: not enough memory to execute the function, or if the device
1980  *   supports resource validation, resource limitation on the device.
1981  *
1982  *   -EBUSY: action cannot be performed due to busy device resources, may
1983  *   succeed if the affected queues or even the entire port are in a stopped
1984  *   state (see rte_eth_dev_rx_queue_stop() and rte_eth_dev_stop()).
1985  */
1986 int
1987 rte_flow_validate(uint16_t port_id,
1988                   const struct rte_flow_attr *attr,
1989                   const struct rte_flow_item pattern[],
1990                   const struct rte_flow_action actions[],
1991                   struct rte_flow_error *error);
1992
1993 /**
1994  * Create a flow rule on a given port.
1995  *
1996  * @param port_id
1997  *   Port identifier of Ethernet device.
1998  * @param[in] attr
1999  *   Flow rule attributes.
2000  * @param[in] pattern
2001  *   Pattern specification (list terminated by the END pattern item).
2002  * @param[in] actions
2003  *   Associated actions (list terminated by the END action).
2004  * @param[out] error
2005  *   Perform verbose error reporting if not NULL. PMDs initialize this
2006  *   structure in case of error only.
2007  *
2008  * @return
2009  *   A valid handle in case of success, NULL otherwise and rte_errno is set
2010  *   to the positive version of one of the error codes defined for
2011  *   rte_flow_validate().
2012  */
2013 struct rte_flow *
2014 rte_flow_create(uint16_t port_id,
2015                 const struct rte_flow_attr *attr,
2016                 const struct rte_flow_item pattern[],
2017                 const struct rte_flow_action actions[],
2018                 struct rte_flow_error *error);
2019
2020 /**
2021  * Destroy a flow rule on a given port.
2022  *
2023  * Failure to destroy a flow rule handle may occur when other flow rules
2024  * depend on it, and destroying it would result in an inconsistent state.
2025  *
2026  * This function is only guaranteed to succeed if handles are destroyed in
2027  * reverse order of their creation.
2028  *
2029  * @param port_id
2030  *   Port identifier of Ethernet device.
2031  * @param flow
2032  *   Flow rule handle to destroy.
2033  * @param[out] error
2034  *   Perform verbose error reporting if not NULL. PMDs initialize this
2035  *   structure in case of error only.
2036  *
2037  * @return
2038  *   0 on success, a negative errno value otherwise and rte_errno is set.
2039  */
2040 int
2041 rte_flow_destroy(uint16_t port_id,
2042                  struct rte_flow *flow,
2043                  struct rte_flow_error *error);
2044
2045 /**
2046  * Destroy all flow rules associated with a port.
2047  *
2048  * In the unlikely event of failure, handles are still considered destroyed
2049  * and no longer valid but the port must be assumed to be in an inconsistent
2050  * state.
2051  *
2052  * @param port_id
2053  *   Port identifier of Ethernet device.
2054  * @param[out] error
2055  *   Perform verbose error reporting if not NULL. PMDs initialize this
2056  *   structure in case of error only.
2057  *
2058  * @return
2059  *   0 on success, a negative errno value otherwise and rte_errno is set.
2060  */
2061 int
2062 rte_flow_flush(uint16_t port_id,
2063                struct rte_flow_error *error);
2064
2065 /**
2066  * Query an existing flow rule.
2067  *
2068  * This function allows retrieving flow-specific data such as counters.
2069  * Data is gathered by special actions which must be present in the flow
2070  * rule definition.
2071  *
2072  * \see RTE_FLOW_ACTION_TYPE_COUNT
2073  *
2074  * @param port_id
2075  *   Port identifier of Ethernet device.
2076  * @param flow
2077  *   Flow rule handle to query.
2078  * @param action
2079  *   Action definition as defined in original flow rule.
2080  * @param[in, out] data
2081  *   Pointer to storage for the associated query data type.
2082  * @param[out] error
2083  *   Perform verbose error reporting if not NULL. PMDs initialize this
2084  *   structure in case of error only.
2085  *
2086  * @return
2087  *   0 on success, a negative errno value otherwise and rte_errno is set.
2088  */
2089 int
2090 rte_flow_query(uint16_t port_id,
2091                struct rte_flow *flow,
2092                const struct rte_flow_action *action,
2093                void *data,
2094                struct rte_flow_error *error);
2095
2096 /**
2097  * Restrict ingress traffic to the defined flow rules.
2098  *
2099  * Isolated mode guarantees that all ingress traffic comes from defined flow
2100  * rules only (current and future).
2101  *
2102  * Besides making ingress more deterministic, it allows PMDs to safely reuse
2103  * resources otherwise assigned to handle the remaining traffic, such as
2104  * global RSS configuration settings, VLAN filters, MAC address entries,
2105  * legacy filter API rules and so on in order to expand the set of possible
2106  * flow rule types.
2107  *
2108  * Calling this function as soon as possible after device initialization,
2109  * ideally before the first call to rte_eth_dev_configure(), is recommended
2110  * to avoid possible failures due to conflicting settings.
2111  *
2112  * Once effective, leaving isolated mode may not be possible depending on
2113  * PMD implementation.
2114  *
2115  * Additionally, the following functionality has no effect on the underlying
2116  * port and may return errors such as ENOTSUP ("not supported"):
2117  *
2118  * - Toggling promiscuous mode.
2119  * - Toggling allmulticast mode.
2120  * - Configuring MAC addresses.
2121  * - Configuring multicast addresses.
2122  * - Configuring VLAN filters.
2123  * - Configuring Rx filters through the legacy API (e.g. FDIR).
2124  * - Configuring global RSS settings.
2125  *
2126  * @param port_id
2127  *   Port identifier of Ethernet device.
2128  * @param set
2129  *   Nonzero to enter isolated mode, attempt to leave it otherwise.
2130  * @param[out] error
2131  *   Perform verbose error reporting if not NULL. PMDs initialize this
2132  *   structure in case of error only.
2133  *
2134  * @return
2135  *   0 on success, a negative errno value otherwise and rte_errno is set.
2136  */
2137 int
2138 rte_flow_isolate(uint16_t port_id, int set, struct rte_flow_error *error);
2139
2140 /**
2141  * Initialize flow error structure.
2142  *
2143  * @param[out] error
2144  *   Pointer to flow error structure (may be NULL).
2145  * @param code
2146  *   Related error code (rte_errno).
2147  * @param type
2148  *   Cause field and error types.
2149  * @param cause
2150  *   Object responsible for the error.
2151  * @param message
2152  *   Human-readable error message.
2153  *
2154  * @return
2155  *   Negative error code (errno value) and rte_errno is set.
2156  */
2157 int
2158 rte_flow_error_set(struct rte_flow_error *error,
2159                    int code,
2160                    enum rte_flow_error_type type,
2161                    const void *cause,
2162                    const char *message);
2163
2164 /**
2165  * Generic flow representation.
2166  *
2167  * This form is sufficient to describe an rte_flow independently from any
2168  * PMD implementation and allows for replayability and identification.
2169  */
2170 struct rte_flow_desc {
2171         size_t size; /**< Allocated space including data[]. */
2172         struct rte_flow_attr attr; /**< Attributes. */
2173         struct rte_flow_item *items; /**< Items. */
2174         struct rte_flow_action *actions; /**< Actions. */
2175         uint8_t data[]; /**< Storage for items/actions. */
2176 };
2177
2178 /**
2179  * Copy an rte_flow rule description.
2180  *
2181  * @param[in] fd
2182  *   Flow rule description.
2183  * @param[in] len
2184  *   Total size of allocated data for the flow description.
2185  * @param[in] attr
2186  *   Flow rule attributes.
2187  * @param[in] items
2188  *   Pattern specification (list terminated by the END pattern item).
2189  * @param[in] actions
2190  *   Associated actions (list terminated by the END action).
2191  *
2192  * @return
2193  *   If len is greater or equal to the size of the flow, the total size of the
2194  *   flow description and its data.
2195  *   If len is lower than the size of the flow, the number of bytes that would
2196  *   have been written to desc had it been sufficient. Nothing is written.
2197  */
2198 size_t
2199 rte_flow_copy(struct rte_flow_desc *fd, size_t len,
2200               const struct rte_flow_attr *attr,
2201               const struct rte_flow_item *items,
2202               const struct rte_flow_action *actions);
2203
2204 #ifdef __cplusplus
2205 }
2206 #endif
2207
2208 #endif /* RTE_FLOW_H_ */