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