ethdev: introduce new tunnel VXLAN-GPE
[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 two levels: per group and per rule within groups.
39  *
40  * Lower values denote higher priority, the highest priority for both levels
41  * is 0, so that a rule with priority 0 in group 8 is always matched after a
42  * rule with priority 8 in group 0.
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).
48  *
49  * Group and priority levels are arbitrary and up to the application, they
50  * do not need to be contiguous nor start from 0, however the maximum number
51  * varies between devices and may be affected by existing flow rules.
52  *
53  * If a packet is matched by several rules of a given group for a given
54  * priority level, the outcome is undefined. It can take any path, may be
55  * duplicated or even cause unrecoverable errors.
56  *
57  * Note that support for more than a single group and priority level is not
58  * guaranteed.
59  *
60  * Flow rules can apply to inbound and/or outbound traffic (ingress/egress).
61  *
62  * Several pattern items and actions are valid and can be used in both
63  * directions. Those valid for only one direction are described as such.
64  *
65  * At least one direction must be specified.
66  *
67  * Specifying both directions at once for a given rule is not recommended
68  * but may be valid in a few cases (e.g. shared counter).
69  */
70 struct rte_flow_attr {
71         uint32_t group; /**< Priority group. */
72         uint32_t priority; /**< Priority level within group. */
73         uint32_t ingress:1; /**< Rule applies to ingress traffic. */
74         uint32_t egress:1; /**< Rule applies to egress traffic. */
75         /**
76          * Instead of simply matching the properties of traffic as it would
77          * appear on a given DPDK port ID, enabling this attribute transfers
78          * a flow rule to the lowest possible level of any device endpoints
79          * found in the pattern.
80          *
81          * When supported, this effectively enables an application to
82          * re-route traffic not necessarily intended for it (e.g. coming
83          * from or addressed to different physical ports, VFs or
84          * applications) at the device level.
85          *
86          * It complements the behavior of some pattern items such as
87          * RTE_FLOW_ITEM_TYPE_PHY_PORT and is meaningless without them.
88          *
89          * When transferring flow rules, ingress and egress attributes keep
90          * their original meaning, as if processing traffic emitted or
91          * received by the application.
92          */
93         uint32_t transfer:1;
94         uint32_t reserved:29; /**< Reserved, must be zero. */
95 };
96
97 /**
98  * Matching pattern item types.
99  *
100  * Pattern items fall in two categories:
101  *
102  * - Matching protocol headers and packet data, usually associated with a
103  *   specification structure. These must be stacked in the same order as the
104  *   protocol layers to match inside packets, starting from the lowest.
105  *
106  * - Matching meta-data or affecting pattern processing, often without a
107  *   specification structure. Since they do not match packet contents, their
108  *   position in the list is usually not relevant.
109  *
110  * See the description of individual types for more information. Those
111  * marked with [META] fall into the second category.
112  */
113 enum rte_flow_item_type {
114         /**
115          * [META]
116          *
117          * End marker for item lists. Prevents further processing of items,
118          * thereby ending the pattern.
119          *
120          * No associated specification structure.
121          */
122         RTE_FLOW_ITEM_TYPE_END,
123
124         /**
125          * [META]
126          *
127          * Used as a placeholder for convenience. It is ignored and simply
128          * discarded by PMDs.
129          *
130          * No associated specification structure.
131          */
132         RTE_FLOW_ITEM_TYPE_VOID,
133
134         /**
135          * [META]
136          *
137          * Inverted matching, i.e. process packets that do not match the
138          * pattern.
139          *
140          * No associated specification structure.
141          */
142         RTE_FLOW_ITEM_TYPE_INVERT,
143
144         /**
145          * Matches any protocol in place of the current layer, a single ANY
146          * may also stand for several protocol layers.
147          *
148          * See struct rte_flow_item_any.
149          */
150         RTE_FLOW_ITEM_TYPE_ANY,
151
152         /**
153          * [META]
154          *
155          * Matches traffic originating from (ingress) or going to (egress)
156          * the physical function of the current device.
157          *
158          * No associated specification structure.
159          */
160         RTE_FLOW_ITEM_TYPE_PF,
161
162         /**
163          * [META]
164          *
165          * Matches traffic originating from (ingress) or going to (egress) a
166          * given virtual function of the current device.
167          *
168          * See struct rte_flow_item_vf.
169          */
170         RTE_FLOW_ITEM_TYPE_VF,
171
172         /**
173          * [META]
174          *
175          * Matches traffic originating from (ingress) or going to (egress) a
176          * physical port of the underlying device.
177          *
178          * See struct rte_flow_item_phy_port.
179          */
180         RTE_FLOW_ITEM_TYPE_PHY_PORT,
181
182         /**
183          * [META]
184          *
185          * Matches traffic originating from (ingress) or going to (egress) a
186          * given DPDK port ID.
187          *
188          * See struct rte_flow_item_port_id.
189          */
190         RTE_FLOW_ITEM_TYPE_PORT_ID,
191
192         /**
193          * Matches a byte string of a given length at a given offset.
194          *
195          * See struct rte_flow_item_raw.
196          */
197         RTE_FLOW_ITEM_TYPE_RAW,
198
199         /**
200          * Matches an Ethernet header.
201          *
202          * See struct rte_flow_item_eth.
203          */
204         RTE_FLOW_ITEM_TYPE_ETH,
205
206         /**
207          * Matches an 802.1Q/ad VLAN tag.
208          *
209          * See struct rte_flow_item_vlan.
210          */
211         RTE_FLOW_ITEM_TYPE_VLAN,
212
213         /**
214          * Matches an IPv4 header.
215          *
216          * See struct rte_flow_item_ipv4.
217          */
218         RTE_FLOW_ITEM_TYPE_IPV4,
219
220         /**
221          * Matches an IPv6 header.
222          *
223          * See struct rte_flow_item_ipv6.
224          */
225         RTE_FLOW_ITEM_TYPE_IPV6,
226
227         /**
228          * Matches an ICMP header.
229          *
230          * See struct rte_flow_item_icmp.
231          */
232         RTE_FLOW_ITEM_TYPE_ICMP,
233
234         /**
235          * Matches a UDP header.
236          *
237          * See struct rte_flow_item_udp.
238          */
239         RTE_FLOW_ITEM_TYPE_UDP,
240
241         /**
242          * Matches a TCP header.
243          *
244          * See struct rte_flow_item_tcp.
245          */
246         RTE_FLOW_ITEM_TYPE_TCP,
247
248         /**
249          * Matches a SCTP header.
250          *
251          * See struct rte_flow_item_sctp.
252          */
253         RTE_FLOW_ITEM_TYPE_SCTP,
254
255         /**
256          * Matches a VXLAN header.
257          *
258          * See struct rte_flow_item_vxlan.
259          */
260         RTE_FLOW_ITEM_TYPE_VXLAN,
261
262         /**
263          * Matches a E_TAG header.
264          *
265          * See struct rte_flow_item_e_tag.
266          */
267         RTE_FLOW_ITEM_TYPE_E_TAG,
268
269         /**
270          * Matches a NVGRE header.
271          *
272          * See struct rte_flow_item_nvgre.
273          */
274         RTE_FLOW_ITEM_TYPE_NVGRE,
275
276         /**
277          * Matches a MPLS header.
278          *
279          * See struct rte_flow_item_mpls.
280          */
281         RTE_FLOW_ITEM_TYPE_MPLS,
282
283         /**
284          * Matches a GRE header.
285          *
286          * See struct rte_flow_item_gre.
287          */
288         RTE_FLOW_ITEM_TYPE_GRE,
289
290         /**
291          * [META]
292          *
293          * Fuzzy pattern match, expect faster than default.
294          *
295          * This is for device that support fuzzy matching option.
296          * Usually a fuzzy matching is fast but the cost is accuracy.
297          *
298          * See struct rte_flow_item_fuzzy.
299          */
300         RTE_FLOW_ITEM_TYPE_FUZZY,
301
302         /**
303          * Matches a GTP header.
304          *
305          * Configure flow for GTP packets.
306          *
307          * See struct rte_flow_item_gtp.
308          */
309         RTE_FLOW_ITEM_TYPE_GTP,
310
311         /**
312          * Matches a GTP header.
313          *
314          * Configure flow for GTP-C packets.
315          *
316          * See struct rte_flow_item_gtp.
317          */
318         RTE_FLOW_ITEM_TYPE_GTPC,
319
320         /**
321          * Matches a GTP header.
322          *
323          * Configure flow for GTP-U packets.
324          *
325          * See struct rte_flow_item_gtp.
326          */
327         RTE_FLOW_ITEM_TYPE_GTPU,
328
329         /**
330          * Matches a ESP header.
331          *
332          * See struct rte_flow_item_esp.
333          */
334         RTE_FLOW_ITEM_TYPE_ESP,
335
336         /**
337          * Matches a GENEVE header.
338          *
339          * See struct rte_flow_item_geneve.
340          */
341         RTE_FLOW_ITEM_TYPE_GENEVE,
342
343         /**
344          * Matches a VXLAN-GPE header.
345          *
346          * See struct rte_flow_item_vxlan_gpe.
347          */
348         RTE_FLOW_ITEM_TYPE_VXLAN_GPE,
349 };
350
351 /**
352  * RTE_FLOW_ITEM_TYPE_ANY
353  *
354  * Matches any protocol in place of the current layer, a single ANY may also
355  * stand for several protocol layers.
356  *
357  * This is usually specified as the first pattern item when looking for a
358  * protocol anywhere in a packet.
359  *
360  * A zeroed mask stands for any number of layers.
361  */
362 struct rte_flow_item_any {
363         uint32_t num; /**< Number of layers covered. */
364 };
365
366 /** Default mask for RTE_FLOW_ITEM_TYPE_ANY. */
367 #ifndef __cplusplus
368 static const struct rte_flow_item_any rte_flow_item_any_mask = {
369         .num = 0x00000000,
370 };
371 #endif
372
373 /**
374  * RTE_FLOW_ITEM_TYPE_VF
375  *
376  * Matches traffic originating from (ingress) or going to (egress) a given
377  * virtual function of the current device.
378  *
379  * If supported, should work even if the virtual function is not managed by
380  * the application and thus not associated with a DPDK port ID.
381  *
382  * Note this pattern item does not match VF representors traffic which, as
383  * separate entities, should be addressed through their own DPDK port IDs.
384  *
385  * - Can be specified multiple times to match traffic addressed to several
386  *   VF IDs.
387  * - Can be combined with a PF item to match both PF and VF traffic.
388  *
389  * A zeroed mask can be used to match any VF ID.
390  */
391 struct rte_flow_item_vf {
392         uint32_t id; /**< VF ID. */
393 };
394
395 /** Default mask for RTE_FLOW_ITEM_TYPE_VF. */
396 #ifndef __cplusplus
397 static const struct rte_flow_item_vf rte_flow_item_vf_mask = {
398         .id = 0x00000000,
399 };
400 #endif
401
402 /**
403  * RTE_FLOW_ITEM_TYPE_PHY_PORT
404  *
405  * Matches traffic originating from (ingress) or going to (egress) a
406  * physical port of the underlying device.
407  *
408  * The first PHY_PORT item overrides the physical port normally associated
409  * with the specified DPDK input port (port_id). This item can be provided
410  * several times to match additional physical ports.
411  *
412  * Note that physical ports are not necessarily tied to DPDK input ports
413  * (port_id) when those are not under DPDK control. Possible values are
414  * specific to each device, they are not necessarily indexed from zero and
415  * may not be contiguous.
416  *
417  * As a device property, the list of allowed values as well as the value
418  * associated with a port_id should be retrieved by other means.
419  *
420  * A zeroed mask can be used to match any port index.
421  */
422 struct rte_flow_item_phy_port {
423         uint32_t index; /**< Physical port index. */
424 };
425
426 /** Default mask for RTE_FLOW_ITEM_TYPE_PHY_PORT. */
427 #ifndef __cplusplus
428 static const struct rte_flow_item_phy_port rte_flow_item_phy_port_mask = {
429         .index = 0x00000000,
430 };
431 #endif
432
433 /**
434  * RTE_FLOW_ITEM_TYPE_PORT_ID
435  *
436  * Matches traffic originating from (ingress) or going to (egress) a given
437  * DPDK port ID.
438  *
439  * Normally only supported if the port ID in question is known by the
440  * underlying PMD and related to the device the flow rule is created
441  * against.
442  *
443  * This must not be confused with @p PHY_PORT which refers to the physical
444  * port of a device, whereas @p PORT_ID refers to a struct rte_eth_dev
445  * object on the application side (also known as "port representor"
446  * depending on the kind of underlying device).
447  */
448 struct rte_flow_item_port_id {
449         uint32_t id; /**< DPDK port ID. */
450 };
451
452 /** Default mask for RTE_FLOW_ITEM_TYPE_PORT_ID. */
453 #ifndef __cplusplus
454 static const struct rte_flow_item_port_id rte_flow_item_port_id_mask = {
455         .id = 0xffffffff,
456 };
457 #endif
458
459 /**
460  * RTE_FLOW_ITEM_TYPE_RAW
461  *
462  * Matches a byte string of a given length at a given offset.
463  *
464  * Offset is either absolute (using the start of the packet) or relative to
465  * the end of the previous matched item in the stack, in which case negative
466  * values are allowed.
467  *
468  * If search is enabled, offset is used as the starting point. The search
469  * area can be delimited by setting limit to a nonzero value, which is the
470  * maximum number of bytes after offset where the pattern may start.
471  *
472  * Matching a zero-length pattern is allowed, doing so resets the relative
473  * offset for subsequent items.
474  *
475  * This type does not support ranges (struct rte_flow_item.last).
476  */
477 struct rte_flow_item_raw {
478         uint32_t relative:1; /**< Look for pattern after the previous item. */
479         uint32_t search:1; /**< Search pattern from offset (see also limit). */
480         uint32_t reserved:30; /**< Reserved, must be set to zero. */
481         int32_t offset; /**< Absolute or relative offset for pattern. */
482         uint16_t limit; /**< Search area limit for start of pattern. */
483         uint16_t length; /**< Pattern length. */
484         const uint8_t *pattern; /**< Byte string to look for. */
485 };
486
487 /** Default mask for RTE_FLOW_ITEM_TYPE_RAW. */
488 #ifndef __cplusplus
489 static const struct rte_flow_item_raw rte_flow_item_raw_mask = {
490         .relative = 1,
491         .search = 1,
492         .reserved = 0x3fffffff,
493         .offset = 0xffffffff,
494         .limit = 0xffff,
495         .length = 0xffff,
496         .pattern = NULL,
497 };
498 #endif
499
500 /**
501  * RTE_FLOW_ITEM_TYPE_ETH
502  *
503  * Matches an Ethernet header.
504  *
505  * The @p type field either stands for "EtherType" or "TPID" when followed
506  * by so-called layer 2.5 pattern items such as RTE_FLOW_ITEM_TYPE_VLAN. In
507  * the latter case, @p type refers to that of the outer header, with the
508  * inner EtherType/TPID provided by the subsequent pattern item. This is the
509  * same order as on the wire.
510  */
511 struct rte_flow_item_eth {
512         struct ether_addr dst; /**< Destination MAC. */
513         struct ether_addr src; /**< Source MAC. */
514         rte_be16_t type; /**< EtherType or TPID. */
515 };
516
517 /** Default mask for RTE_FLOW_ITEM_TYPE_ETH. */
518 #ifndef __cplusplus
519 static const struct rte_flow_item_eth rte_flow_item_eth_mask = {
520         .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
521         .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
522         .type = RTE_BE16(0x0000),
523 };
524 #endif
525
526 /**
527  * RTE_FLOW_ITEM_TYPE_VLAN
528  *
529  * Matches an 802.1Q/ad VLAN tag.
530  *
531  * The corresponding standard outer EtherType (TPID) values are
532  * ETHER_TYPE_VLAN or ETHER_TYPE_QINQ. It can be overridden by the preceding
533  * pattern item.
534  */
535 struct rte_flow_item_vlan {
536         rte_be16_t tci; /**< Tag control information. */
537         rte_be16_t inner_type; /**< Inner EtherType or TPID. */
538 };
539
540 /** Default mask for RTE_FLOW_ITEM_TYPE_VLAN. */
541 #ifndef __cplusplus
542 static const struct rte_flow_item_vlan rte_flow_item_vlan_mask = {
543         .tci = RTE_BE16(0x0fff),
544         .inner_type = RTE_BE16(0x0000),
545 };
546 #endif
547
548 /**
549  * RTE_FLOW_ITEM_TYPE_IPV4
550  *
551  * Matches an IPv4 header.
552  *
553  * Note: IPv4 options are handled by dedicated pattern items.
554  */
555 struct rte_flow_item_ipv4 {
556         struct ipv4_hdr hdr; /**< IPv4 header definition. */
557 };
558
559 /** Default mask for RTE_FLOW_ITEM_TYPE_IPV4. */
560 #ifndef __cplusplus
561 static const struct rte_flow_item_ipv4 rte_flow_item_ipv4_mask = {
562         .hdr = {
563                 .src_addr = RTE_BE32(0xffffffff),
564                 .dst_addr = RTE_BE32(0xffffffff),
565         },
566 };
567 #endif
568
569 /**
570  * RTE_FLOW_ITEM_TYPE_IPV6.
571  *
572  * Matches an IPv6 header.
573  *
574  * Note: IPv6 options are handled by dedicated pattern items.
575  */
576 struct rte_flow_item_ipv6 {
577         struct ipv6_hdr hdr; /**< IPv6 header definition. */
578 };
579
580 /** Default mask for RTE_FLOW_ITEM_TYPE_IPV6. */
581 #ifndef __cplusplus
582 static const struct rte_flow_item_ipv6 rte_flow_item_ipv6_mask = {
583         .hdr = {
584                 .src_addr =
585                         "\xff\xff\xff\xff\xff\xff\xff\xff"
586                         "\xff\xff\xff\xff\xff\xff\xff\xff",
587                 .dst_addr =
588                         "\xff\xff\xff\xff\xff\xff\xff\xff"
589                         "\xff\xff\xff\xff\xff\xff\xff\xff",
590         },
591 };
592 #endif
593
594 /**
595  * RTE_FLOW_ITEM_TYPE_ICMP.
596  *
597  * Matches an ICMP header.
598  */
599 struct rte_flow_item_icmp {
600         struct icmp_hdr hdr; /**< ICMP header definition. */
601 };
602
603 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP. */
604 #ifndef __cplusplus
605 static const struct rte_flow_item_icmp rte_flow_item_icmp_mask = {
606         .hdr = {
607                 .icmp_type = 0xff,
608                 .icmp_code = 0xff,
609         },
610 };
611 #endif
612
613 /**
614  * RTE_FLOW_ITEM_TYPE_UDP.
615  *
616  * Matches a UDP header.
617  */
618 struct rte_flow_item_udp {
619         struct udp_hdr hdr; /**< UDP header definition. */
620 };
621
622 /** Default mask for RTE_FLOW_ITEM_TYPE_UDP. */
623 #ifndef __cplusplus
624 static const struct rte_flow_item_udp rte_flow_item_udp_mask = {
625         .hdr = {
626                 .src_port = RTE_BE16(0xffff),
627                 .dst_port = RTE_BE16(0xffff),
628         },
629 };
630 #endif
631
632 /**
633  * RTE_FLOW_ITEM_TYPE_TCP.
634  *
635  * Matches a TCP header.
636  */
637 struct rte_flow_item_tcp {
638         struct tcp_hdr hdr; /**< TCP header definition. */
639 };
640
641 /** Default mask for RTE_FLOW_ITEM_TYPE_TCP. */
642 #ifndef __cplusplus
643 static const struct rte_flow_item_tcp rte_flow_item_tcp_mask = {
644         .hdr = {
645                 .src_port = RTE_BE16(0xffff),
646                 .dst_port = RTE_BE16(0xffff),
647         },
648 };
649 #endif
650
651 /**
652  * RTE_FLOW_ITEM_TYPE_SCTP.
653  *
654  * Matches a SCTP header.
655  */
656 struct rte_flow_item_sctp {
657         struct sctp_hdr hdr; /**< SCTP header definition. */
658 };
659
660 /** Default mask for RTE_FLOW_ITEM_TYPE_SCTP. */
661 #ifndef __cplusplus
662 static const struct rte_flow_item_sctp rte_flow_item_sctp_mask = {
663         .hdr = {
664                 .src_port = RTE_BE16(0xffff),
665                 .dst_port = RTE_BE16(0xffff),
666         },
667 };
668 #endif
669
670 /**
671  * RTE_FLOW_ITEM_TYPE_VXLAN.
672  *
673  * Matches a VXLAN header (RFC 7348).
674  */
675 struct rte_flow_item_vxlan {
676         uint8_t flags; /**< Normally 0x08 (I flag). */
677         uint8_t rsvd0[3]; /**< Reserved, normally 0x000000. */
678         uint8_t vni[3]; /**< VXLAN identifier. */
679         uint8_t rsvd1; /**< Reserved, normally 0x00. */
680 };
681
682 /** Default mask for RTE_FLOW_ITEM_TYPE_VXLAN. */
683 #ifndef __cplusplus
684 static const struct rte_flow_item_vxlan rte_flow_item_vxlan_mask = {
685         .vni = "\xff\xff\xff",
686 };
687 #endif
688
689 /**
690  * RTE_FLOW_ITEM_TYPE_E_TAG.
691  *
692  * Matches a E-tag header.
693  *
694  * The corresponding standard outer EtherType (TPID) value is
695  * ETHER_TYPE_ETAG. It can be overridden by the preceding pattern item.
696  */
697 struct rte_flow_item_e_tag {
698         /**
699          * E-Tag control information (E-TCI).
700          * E-PCP (3b), E-DEI (1b), ingress E-CID base (12b).
701          */
702         rte_be16_t epcp_edei_in_ecid_b;
703         /** Reserved (2b), GRP (2b), E-CID base (12b). */
704         rte_be16_t rsvd_grp_ecid_b;
705         uint8_t in_ecid_e; /**< Ingress E-CID ext. */
706         uint8_t ecid_e; /**< E-CID ext. */
707         rte_be16_t inner_type; /**< Inner EtherType or TPID. */
708 };
709
710 /** Default mask for RTE_FLOW_ITEM_TYPE_E_TAG. */
711 #ifndef __cplusplus
712 static const struct rte_flow_item_e_tag rte_flow_item_e_tag_mask = {
713         .rsvd_grp_ecid_b = RTE_BE16(0x3fff),
714 };
715 #endif
716
717 /**
718  * RTE_FLOW_ITEM_TYPE_NVGRE.
719  *
720  * Matches a NVGRE header.
721  */
722 struct rte_flow_item_nvgre {
723         /**
724          * Checksum (1b), undefined (1b), key bit (1b), sequence number (1b),
725          * reserved 0 (9b), version (3b).
726          *
727          * c_k_s_rsvd0_ver must have value 0x2000 according to RFC 7637.
728          */
729         rte_be16_t c_k_s_rsvd0_ver;
730         rte_be16_t protocol; /**< Protocol type (0x6558). */
731         uint8_t tni[3]; /**< Virtual subnet ID. */
732         uint8_t flow_id; /**< Flow ID. */
733 };
734
735 /** Default mask for RTE_FLOW_ITEM_TYPE_NVGRE. */
736 #ifndef __cplusplus
737 static const struct rte_flow_item_nvgre rte_flow_item_nvgre_mask = {
738         .tni = "\xff\xff\xff",
739 };
740 #endif
741
742 /**
743  * RTE_FLOW_ITEM_TYPE_MPLS.
744  *
745  * Matches a MPLS header.
746  */
747 struct rte_flow_item_mpls {
748         /**
749          * Label (20b), TC (3b), Bottom of Stack (1b).
750          */
751         uint8_t label_tc_s[3];
752         uint8_t ttl; /** Time-to-Live. */
753 };
754
755 /** Default mask for RTE_FLOW_ITEM_TYPE_MPLS. */
756 #ifndef __cplusplus
757 static const struct rte_flow_item_mpls rte_flow_item_mpls_mask = {
758         .label_tc_s = "\xff\xff\xf0",
759 };
760 #endif
761
762 /**
763  * RTE_FLOW_ITEM_TYPE_GRE.
764  *
765  * Matches a GRE header.
766  */
767 struct rte_flow_item_gre {
768         /**
769          * Checksum (1b), reserved 0 (12b), version (3b).
770          * Refer to RFC 2784.
771          */
772         rte_be16_t c_rsvd0_ver;
773         rte_be16_t protocol; /**< Protocol type. */
774 };
775
776 /** Default mask for RTE_FLOW_ITEM_TYPE_GRE. */
777 #ifndef __cplusplus
778 static const struct rte_flow_item_gre rte_flow_item_gre_mask = {
779         .protocol = RTE_BE16(0xffff),
780 };
781 #endif
782
783 /**
784  * RTE_FLOW_ITEM_TYPE_FUZZY
785  *
786  * Fuzzy pattern match, expect faster than default.
787  *
788  * This is for device that support fuzzy match option.
789  * Usually a fuzzy match is fast but the cost is accuracy.
790  * i.e. Signature Match only match pattern's hash value, but it is
791  * possible two different patterns have the same hash value.
792  *
793  * Matching accuracy level can be configure by threshold.
794  * Driver can divide the range of threshold and map to different
795  * accuracy levels that device support.
796  *
797  * Threshold 0 means perfect match (no fuzziness), while threshold
798  * 0xffffffff means fuzziest match.
799  */
800 struct rte_flow_item_fuzzy {
801         uint32_t thresh; /**< Accuracy threshold. */
802 };
803
804 /** Default mask for RTE_FLOW_ITEM_TYPE_FUZZY. */
805 #ifndef __cplusplus
806 static const struct rte_flow_item_fuzzy rte_flow_item_fuzzy_mask = {
807         .thresh = 0xffffffff,
808 };
809 #endif
810
811 /**
812  * RTE_FLOW_ITEM_TYPE_GTP.
813  *
814  * Matches a GTPv1 header.
815  */
816 struct rte_flow_item_gtp {
817         /**
818          * Version (3b), protocol type (1b), reserved (1b),
819          * Extension header flag (1b),
820          * Sequence number flag (1b),
821          * N-PDU number flag (1b).
822          */
823         uint8_t v_pt_rsv_flags;
824         uint8_t msg_type; /**< Message type. */
825         rte_be16_t msg_len; /**< Message length. */
826         rte_be32_t teid; /**< Tunnel endpoint identifier. */
827 };
828
829 /** Default mask for RTE_FLOW_ITEM_TYPE_GTP. */
830 #ifndef __cplusplus
831 static const struct rte_flow_item_gtp rte_flow_item_gtp_mask = {
832         .teid = RTE_BE32(0xffffffff),
833 };
834 #endif
835
836 /**
837  * RTE_FLOW_ITEM_TYPE_ESP
838  *
839  * Matches an ESP header.
840  */
841 struct rte_flow_item_esp {
842         struct esp_hdr hdr; /**< ESP header definition. */
843 };
844
845 /** Default mask for RTE_FLOW_ITEM_TYPE_ESP. */
846 #ifndef __cplusplus
847 static const struct rte_flow_item_esp rte_flow_item_esp_mask = {
848         .hdr = {
849                 .spi = 0xffffffff,
850         },
851 };
852 #endif
853
854 /**
855  * RTE_FLOW_ITEM_TYPE_GENEVE.
856  *
857  * Matches a GENEVE header.
858  */
859 struct rte_flow_item_geneve {
860         /**
861          * Version (2b), length of the options fields (6b), OAM packet (1b),
862          * critical options present (1b), reserved 0 (6b).
863          */
864         rte_be16_t ver_opt_len_o_c_rsvd0;
865         rte_be16_t protocol; /**< Protocol type. */
866         uint8_t vni[3]; /**< Virtual Network Identifier. */
867         uint8_t rsvd1; /**< Reserved, normally 0x00. */
868 };
869
870 /** Default mask for RTE_FLOW_ITEM_TYPE_GENEVE. */
871 #ifndef __cplusplus
872 static const struct rte_flow_item_geneve rte_flow_item_geneve_mask = {
873         .vni = "\xff\xff\xff",
874 };
875 #endif
876
877 /**
878  * RTE_FLOW_ITEM_TYPE_VXLAN_GPE (draft-ietf-nvo3-vxlan-gpe-05).
879  *
880  * Matches a VXLAN-GPE header.
881  */
882 struct rte_flow_item_vxlan_gpe {
883         uint8_t flags; /**< Normally 0x0c (I and P flags). */
884         uint8_t rsvd0[2]; /**< Reserved, normally 0x0000. */
885         uint8_t protocol; /**< Protocol type. */
886         uint8_t vni[3]; /**< VXLAN identifier. */
887         uint8_t rsvd1; /**< Reserved, normally 0x00. */
888 };
889
890 /** Default mask for RTE_FLOW_ITEM_TYPE_VXLAN_GPE. */
891 #ifndef __cplusplus
892 static const struct rte_flow_item_vxlan_gpe rte_flow_item_vxlan_gpe_mask = {
893         .vni = "\xff\xff\xff",
894 };
895 #endif
896
897 /**
898  * Matching pattern item definition.
899  *
900  * A pattern is formed by stacking items starting from the lowest protocol
901  * layer to match. This stacking restriction does not apply to meta items
902  * which can be placed anywhere in the stack without affecting the meaning
903  * of the resulting pattern.
904  *
905  * Patterns are terminated by END items.
906  *
907  * The spec field should be a valid pointer to a structure of the related
908  * item type. It may remain unspecified (NULL) in many cases to request
909  * broad (nonspecific) matching. In such cases, last and mask must also be
910  * set to NULL.
911  *
912  * Optionally, last can point to a structure of the same type to define an
913  * inclusive range. This is mostly supported by integer and address fields,
914  * may cause errors otherwise. Fields that do not support ranges must be set
915  * to 0 or to the same value as the corresponding fields in spec.
916  *
917  * Only the fields defined to nonzero values in the default masks (see
918  * rte_flow_item_{name}_mask constants) are considered relevant by
919  * default. This can be overridden by providing a mask structure of the
920  * same type with applicable bits set to one. It can also be used to
921  * partially filter out specific fields (e.g. as an alternate mean to match
922  * ranges of IP addresses).
923  *
924  * Mask is a simple bit-mask applied before interpreting the contents of
925  * spec and last, which may yield unexpected results if not used
926  * carefully. For example, if for an IPv4 address field, spec provides
927  * 10.1.2.3, last provides 10.3.4.5 and mask provides 255.255.0.0, the
928  * effective range becomes 10.1.0.0 to 10.3.255.255.
929  */
930 struct rte_flow_item {
931         enum rte_flow_item_type type; /**< Item type. */
932         const void *spec; /**< Pointer to item specification structure. */
933         const void *last; /**< Defines an inclusive range (spec to last). */
934         const void *mask; /**< Bit-mask applied to spec and last. */
935 };
936
937 /**
938  * Action types.
939  *
940  * Each possible action is represented by a type. Some have associated
941  * configuration structures. Several actions combined in a list can be
942  * assigned to a flow rule and are performed in order.
943  *
944  * They fall in three categories:
945  *
946  * - Actions that modify the fate of matching traffic, for instance by
947  *   dropping or assigning it a specific destination.
948  *
949  * - Actions that modify matching traffic contents or its properties. This
950  *   includes adding/removing encapsulation, encryption, compression and
951  *   marks.
952  *
953  * - Actions related to the flow rule itself, such as updating counters or
954  *   making it non-terminating.
955  *
956  * Flow rules being terminating by default, not specifying any action of the
957  * fate kind results in undefined behavior. This applies to both ingress and
958  * egress.
959  *
960  * PASSTHRU, when supported, makes a flow rule non-terminating.
961  */
962 enum rte_flow_action_type {
963         /**
964          * End marker for action lists. Prevents further processing of
965          * actions, thereby ending the list.
966          *
967          * No associated configuration structure.
968          */
969         RTE_FLOW_ACTION_TYPE_END,
970
971         /**
972          * Used as a placeholder for convenience. It is ignored and simply
973          * discarded by PMDs.
974          *
975          * No associated configuration structure.
976          */
977         RTE_FLOW_ACTION_TYPE_VOID,
978
979         /**
980          * Leaves traffic up for additional processing by subsequent flow
981          * rules; makes a flow rule non-terminating.
982          *
983          * No associated configuration structure.
984          */
985         RTE_FLOW_ACTION_TYPE_PASSTHRU,
986
987         /**
988          * Attaches an integer value to packets and sets PKT_RX_FDIR and
989          * PKT_RX_FDIR_ID mbuf flags.
990          *
991          * See struct rte_flow_action_mark.
992          */
993         RTE_FLOW_ACTION_TYPE_MARK,
994
995         /**
996          * Flags packets. Similar to MARK without a specific value; only
997          * sets the PKT_RX_FDIR mbuf flag.
998          *
999          * No associated configuration structure.
1000          */
1001         RTE_FLOW_ACTION_TYPE_FLAG,
1002
1003         /**
1004          * Assigns packets to a given queue index.
1005          *
1006          * See struct rte_flow_action_queue.
1007          */
1008         RTE_FLOW_ACTION_TYPE_QUEUE,
1009
1010         /**
1011          * Drops packets.
1012          *
1013          * PASSTHRU overrides this action if both are specified.
1014          *
1015          * No associated configuration structure.
1016          */
1017         RTE_FLOW_ACTION_TYPE_DROP,
1018
1019         /**
1020          * Enables counters for this flow rule.
1021          *
1022          * These counters can be retrieved and reset through rte_flow_query(),
1023          * see struct rte_flow_query_count.
1024          *
1025          * No associated configuration structure.
1026          */
1027         RTE_FLOW_ACTION_TYPE_COUNT,
1028
1029         /**
1030          * Similar to QUEUE, except RSS is additionally performed on packets
1031          * to spread them among several queues according to the provided
1032          * parameters.
1033          *
1034          * See struct rte_flow_action_rss.
1035          */
1036         RTE_FLOW_ACTION_TYPE_RSS,
1037
1038         /**
1039          * Directs matching traffic to the physical function (PF) of the
1040          * current device.
1041          *
1042          * No associated configuration structure.
1043          */
1044         RTE_FLOW_ACTION_TYPE_PF,
1045
1046         /**
1047          * Directs matching traffic to a given virtual function of the
1048          * current device.
1049          *
1050          * See struct rte_flow_action_vf.
1051          */
1052         RTE_FLOW_ACTION_TYPE_VF,
1053
1054         /**
1055          * Directs packets to a given physical port index of the underlying
1056          * device.
1057          *
1058          * See struct rte_flow_action_phy_port.
1059          */
1060         RTE_FLOW_ACTION_TYPE_PHY_PORT,
1061
1062         /**
1063          * Directs matching traffic to a given DPDK port ID.
1064          *
1065          * See struct rte_flow_action_port_id.
1066          */
1067         RTE_FLOW_ACTION_TYPE_PORT_ID,
1068
1069         /**
1070          * Traffic metering and policing (MTR).
1071          *
1072          * See struct rte_flow_action_meter.
1073          * See file rte_mtr.h for MTR object configuration.
1074          */
1075         RTE_FLOW_ACTION_TYPE_METER,
1076
1077         /**
1078          * Redirects packets to security engine of current device for security
1079          * processing as specified by security session.
1080          *
1081          * See struct rte_flow_action_security.
1082          */
1083         RTE_FLOW_ACTION_TYPE_SECURITY
1084 };
1085
1086 /**
1087  * RTE_FLOW_ACTION_TYPE_MARK
1088  *
1089  * Attaches an integer value to packets and sets PKT_RX_FDIR and
1090  * PKT_RX_FDIR_ID mbuf flags.
1091  *
1092  * This value is arbitrary and application-defined. Maximum allowed value
1093  * depends on the underlying implementation. It is returned in the
1094  * hash.fdir.hi mbuf field.
1095  */
1096 struct rte_flow_action_mark {
1097         uint32_t id; /**< Integer value to return with packets. */
1098 };
1099
1100 /**
1101  * RTE_FLOW_ACTION_TYPE_QUEUE
1102  *
1103  * Assign packets to a given queue index.
1104  */
1105 struct rte_flow_action_queue {
1106         uint16_t index; /**< Queue index to use. */
1107 };
1108
1109 /**
1110  * RTE_FLOW_ACTION_TYPE_COUNT (query)
1111  *
1112  * Query structure to retrieve and reset flow rule counters.
1113  */
1114 struct rte_flow_query_count {
1115         uint32_t reset:1; /**< Reset counters after query [in]. */
1116         uint32_t hits_set:1; /**< hits field is set [out]. */
1117         uint32_t bytes_set:1; /**< bytes field is set [out]. */
1118         uint32_t reserved:29; /**< Reserved, must be zero [in, out]. */
1119         uint64_t hits; /**< Number of hits for this rule [out]. */
1120         uint64_t bytes; /**< Number of bytes through this rule [out]. */
1121 };
1122
1123 /**
1124  * RTE_FLOW_ACTION_TYPE_RSS
1125  *
1126  * Similar to QUEUE, except RSS is additionally performed on packets to
1127  * spread them among several queues according to the provided parameters.
1128  *
1129  * Unlike global RSS settings used by other DPDK APIs, unsetting the
1130  * @p types field does not disable RSS in a flow rule. Doing so instead
1131  * requests safe unspecified "best-effort" settings from the underlying PMD,
1132  * which depending on the flow rule, may result in anything ranging from
1133  * empty (single queue) to all-inclusive RSS.
1134  *
1135  * Note: RSS hash result is stored in the hash.rss mbuf field which overlaps
1136  * hash.fdir.lo. Since the MARK action sets the hash.fdir.hi field only,
1137  * both can be requested simultaneously.
1138  */
1139 struct rte_flow_action_rss {
1140         enum rte_eth_hash_function func; /**< RSS hash function to apply. */
1141         /**
1142          * Packet encapsulation level RSS hash @p types apply to.
1143          *
1144          * - @p 0 requests the default behavior. Depending on the packet
1145          *   type, it can mean outermost, innermost, anything in between or
1146          *   even no RSS.
1147          *
1148          *   It basically stands for the innermost encapsulation level RSS
1149          *   can be performed on according to PMD and device capabilities.
1150          *
1151          * - @p 1 requests RSS to be performed on the outermost packet
1152          *   encapsulation level.
1153          *
1154          * - @p 2 and subsequent values request RSS to be performed on the
1155          *   specified inner packet encapsulation level, from outermost to
1156          *   innermost (lower to higher values).
1157          *
1158          * Values other than @p 0 are not necessarily supported.
1159          *
1160          * Requesting a specific RSS level on unrecognized traffic results
1161          * in undefined behavior. For predictable results, it is recommended
1162          * to make the flow rule pattern match packet headers up to the
1163          * requested encapsulation level so that only matching traffic goes
1164          * through.
1165          */
1166         uint32_t level;
1167         uint64_t types; /**< Specific RSS hash types (see ETH_RSS_*). */
1168         uint32_t key_len; /**< Hash key length in bytes. */
1169         uint32_t queue_num; /**< Number of entries in @p queue. */
1170         const uint8_t *key; /**< Hash key. */
1171         const uint16_t *queue; /**< Queue indices to use. */
1172 };
1173
1174 /**
1175  * RTE_FLOW_ACTION_TYPE_VF
1176  *
1177  * Directs matching traffic to a given virtual function of the current
1178  * device.
1179  *
1180  * Packets matched by a VF pattern item can be redirected to their original
1181  * VF ID instead of the specified one. This parameter may not be available
1182  * and is not guaranteed to work properly if the VF part is matched by a
1183  * prior flow rule or if packets are not addressed to a VF in the first
1184  * place.
1185  */
1186 struct rte_flow_action_vf {
1187         uint32_t original:1; /**< Use original VF ID if possible. */
1188         uint32_t reserved:31; /**< Reserved, must be zero. */
1189         uint32_t id; /**< VF ID. */
1190 };
1191
1192 /**
1193  * RTE_FLOW_ACTION_TYPE_PHY_PORT
1194  *
1195  * Directs packets to a given physical port index of the underlying
1196  * device.
1197  *
1198  * @see RTE_FLOW_ITEM_TYPE_PHY_PORT
1199  */
1200 struct rte_flow_action_phy_port {
1201         uint32_t original:1; /**< Use original port index if possible. */
1202         uint32_t reserved:31; /**< Reserved, must be zero. */
1203         uint32_t index; /**< Physical port index. */
1204 };
1205
1206 /**
1207  * RTE_FLOW_ACTION_TYPE_PORT_ID
1208  *
1209  * Directs matching traffic to a given DPDK port ID.
1210  *
1211  * @see RTE_FLOW_ITEM_TYPE_PORT_ID
1212  */
1213 struct rte_flow_action_port_id {
1214         uint32_t original:1; /**< Use original DPDK port ID if possible. */
1215         uint32_t reserved:31; /**< Reserved, must be zero. */
1216         uint32_t id; /**< DPDK port ID. */
1217 };
1218
1219 /**
1220  * RTE_FLOW_ACTION_TYPE_METER
1221  *
1222  * Traffic metering and policing (MTR).
1223  *
1224  * Packets matched by items of this type can be either dropped or passed to the
1225  * next item with their color set by the MTR object.
1226  */
1227 struct rte_flow_action_meter {
1228         uint32_t mtr_id; /**< MTR object ID created with rte_mtr_create(). */
1229 };
1230
1231 /**
1232  * RTE_FLOW_ACTION_TYPE_SECURITY
1233  *
1234  * Perform the security action on flows matched by the pattern items
1235  * according to the configuration of the security session.
1236  *
1237  * This action modifies the payload of matched flows. For INLINE_CRYPTO, the
1238  * security protocol headers and IV are fully provided by the application as
1239  * specified in the flow pattern. The payload of matching packets is
1240  * encrypted on egress, and decrypted and authenticated on ingress.
1241  * For INLINE_PROTOCOL, the security protocol is fully offloaded to HW,
1242  * providing full encapsulation and decapsulation of packets in security
1243  * protocols. The flow pattern specifies both the outer security header fields
1244  * and the inner packet fields. The security session specified in the action
1245  * must match the pattern parameters.
1246  *
1247  * The security session specified in the action must be created on the same
1248  * port as the flow action that is being specified.
1249  *
1250  * The ingress/egress flow attribute should match that specified in the
1251  * security session if the security session supports the definition of the
1252  * direction.
1253  *
1254  * Multiple flows can be configured to use the same security session.
1255  */
1256 struct rte_flow_action_security {
1257         void *security_session; /**< Pointer to security session structure. */
1258 };
1259
1260 /**
1261  * Definition of a single action.
1262  *
1263  * A list of actions is terminated by a END action.
1264  *
1265  * For simple actions without a configuration structure, conf remains NULL.
1266  */
1267 struct rte_flow_action {
1268         enum rte_flow_action_type type; /**< Action type. */
1269         const void *conf; /**< Pointer to action configuration structure. */
1270 };
1271
1272 /**
1273  * Opaque type returned after successfully creating a flow.
1274  *
1275  * This handle can be used to manage and query the related flow (e.g. to
1276  * destroy it or retrieve counters).
1277  */
1278 struct rte_flow;
1279
1280 /**
1281  * Verbose error types.
1282  *
1283  * Most of them provide the type of the object referenced by struct
1284  * rte_flow_error.cause.
1285  */
1286 enum rte_flow_error_type {
1287         RTE_FLOW_ERROR_TYPE_NONE, /**< No error. */
1288         RTE_FLOW_ERROR_TYPE_UNSPECIFIED, /**< Cause unspecified. */
1289         RTE_FLOW_ERROR_TYPE_HANDLE, /**< Flow rule (handle). */
1290         RTE_FLOW_ERROR_TYPE_ATTR_GROUP, /**< Group field. */
1291         RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY, /**< Priority field. */
1292         RTE_FLOW_ERROR_TYPE_ATTR_INGRESS, /**< Ingress field. */
1293         RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, /**< Egress field. */
1294         RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER, /**< Transfer field. */
1295         RTE_FLOW_ERROR_TYPE_ATTR, /**< Attributes structure. */
1296         RTE_FLOW_ERROR_TYPE_ITEM_NUM, /**< Pattern length. */
1297         RTE_FLOW_ERROR_TYPE_ITEM_SPEC, /**< Item specification. */
1298         RTE_FLOW_ERROR_TYPE_ITEM_LAST, /**< Item specification range. */
1299         RTE_FLOW_ERROR_TYPE_ITEM_MASK, /**< Item specification mask. */
1300         RTE_FLOW_ERROR_TYPE_ITEM, /**< Specific pattern item. */
1301         RTE_FLOW_ERROR_TYPE_ACTION_NUM, /**< Number of actions. */
1302         RTE_FLOW_ERROR_TYPE_ACTION_CONF, /**< Action configuration. */
1303         RTE_FLOW_ERROR_TYPE_ACTION, /**< Specific action. */
1304 };
1305
1306 /**
1307  * Verbose error structure definition.
1308  *
1309  * This object is normally allocated by applications and set by PMDs, the
1310  * message points to a constant string which does not need to be freed by
1311  * the application, however its pointer can be considered valid only as long
1312  * as its associated DPDK port remains configured. Closing the underlying
1313  * device or unloading the PMD invalidates it.
1314  *
1315  * Both cause and message may be NULL regardless of the error type.
1316  */
1317 struct rte_flow_error {
1318         enum rte_flow_error_type type; /**< Cause field and error types. */
1319         const void *cause; /**< Object responsible for the error. */
1320         const char *message; /**< Human-readable error message. */
1321 };
1322
1323 /**
1324  * Check whether a flow rule can be created on a given port.
1325  *
1326  * The flow rule is validated for correctness and whether it could be accepted
1327  * by the device given sufficient resources. The rule is checked against the
1328  * current device mode and queue configuration. The flow rule may also
1329  * optionally be validated against existing flow rules and device resources.
1330  * This function has no effect on the target device.
1331  *
1332  * The returned value is guaranteed to remain valid only as long as no
1333  * successful calls to rte_flow_create() or rte_flow_destroy() are made in
1334  * the meantime and no device parameter affecting flow rules in any way are
1335  * modified, due to possible collisions or resource limitations (although in
1336  * such cases EINVAL should not be returned).
1337  *
1338  * @param port_id
1339  *   Port identifier of Ethernet device.
1340  * @param[in] attr
1341  *   Flow rule attributes.
1342  * @param[in] pattern
1343  *   Pattern specification (list terminated by the END pattern item).
1344  * @param[in] actions
1345  *   Associated actions (list terminated by the END action).
1346  * @param[out] error
1347  *   Perform verbose error reporting if not NULL. PMDs initialize this
1348  *   structure in case of error only.
1349  *
1350  * @return
1351  *   0 if flow rule is valid and can be created. A negative errno value
1352  *   otherwise (rte_errno is also set), the following errors are defined:
1353  *
1354  *   -ENOSYS: underlying device does not support this functionality.
1355  *
1356  *   -EIO: underlying device is removed.
1357  *
1358  *   -EINVAL: unknown or invalid rule specification.
1359  *
1360  *   -ENOTSUP: valid but unsupported rule specification (e.g. partial
1361  *   bit-masks are unsupported).
1362  *
1363  *   -EEXIST: collision with an existing rule. Only returned if device
1364  *   supports flow rule collision checking and there was a flow rule
1365  *   collision. Not receiving this return code is no guarantee that creating
1366  *   the rule will not fail due to a collision.
1367  *
1368  *   -ENOMEM: not enough memory to execute the function, or if the device
1369  *   supports resource validation, resource limitation on the device.
1370  *
1371  *   -EBUSY: action cannot be performed due to busy device resources, may
1372  *   succeed if the affected queues or even the entire port are in a stopped
1373  *   state (see rte_eth_dev_rx_queue_stop() and rte_eth_dev_stop()).
1374  */
1375 int
1376 rte_flow_validate(uint16_t port_id,
1377                   const struct rte_flow_attr *attr,
1378                   const struct rte_flow_item pattern[],
1379                   const struct rte_flow_action actions[],
1380                   struct rte_flow_error *error);
1381
1382 /**
1383  * Create a flow rule on a given port.
1384  *
1385  * @param port_id
1386  *   Port identifier of Ethernet device.
1387  * @param[in] attr
1388  *   Flow rule attributes.
1389  * @param[in] pattern
1390  *   Pattern specification (list terminated by the END pattern item).
1391  * @param[in] actions
1392  *   Associated actions (list terminated by the END action).
1393  * @param[out] error
1394  *   Perform verbose error reporting if not NULL. PMDs initialize this
1395  *   structure in case of error only.
1396  *
1397  * @return
1398  *   A valid handle in case of success, NULL otherwise and rte_errno is set
1399  *   to the positive version of one of the error codes defined for
1400  *   rte_flow_validate().
1401  */
1402 struct rte_flow *
1403 rte_flow_create(uint16_t port_id,
1404                 const struct rte_flow_attr *attr,
1405                 const struct rte_flow_item pattern[],
1406                 const struct rte_flow_action actions[],
1407                 struct rte_flow_error *error);
1408
1409 /**
1410  * Destroy a flow rule on a given port.
1411  *
1412  * Failure to destroy a flow rule handle may occur when other flow rules
1413  * depend on it, and destroying it would result in an inconsistent state.
1414  *
1415  * This function is only guaranteed to succeed if handles are destroyed in
1416  * reverse order of their creation.
1417  *
1418  * @param port_id
1419  *   Port identifier of Ethernet device.
1420  * @param flow
1421  *   Flow rule handle to destroy.
1422  * @param[out] error
1423  *   Perform verbose error reporting if not NULL. PMDs initialize this
1424  *   structure in case of error only.
1425  *
1426  * @return
1427  *   0 on success, a negative errno value otherwise and rte_errno is set.
1428  */
1429 int
1430 rte_flow_destroy(uint16_t port_id,
1431                  struct rte_flow *flow,
1432                  struct rte_flow_error *error);
1433
1434 /**
1435  * Destroy all flow rules associated with a port.
1436  *
1437  * In the unlikely event of failure, handles are still considered destroyed
1438  * and no longer valid but the port must be assumed to be in an inconsistent
1439  * state.
1440  *
1441  * @param port_id
1442  *   Port identifier of Ethernet device.
1443  * @param[out] error
1444  *   Perform verbose error reporting if not NULL. PMDs initialize this
1445  *   structure in case of error only.
1446  *
1447  * @return
1448  *   0 on success, a negative errno value otherwise and rte_errno is set.
1449  */
1450 int
1451 rte_flow_flush(uint16_t port_id,
1452                struct rte_flow_error *error);
1453
1454 /**
1455  * Query an existing flow rule.
1456  *
1457  * This function allows retrieving flow-specific data such as counters.
1458  * Data is gathered by special actions which must be present in the flow
1459  * rule definition.
1460  *
1461  * \see RTE_FLOW_ACTION_TYPE_COUNT
1462  *
1463  * @param port_id
1464  *   Port identifier of Ethernet device.
1465  * @param flow
1466  *   Flow rule handle to query.
1467  * @param action
1468  *   Action type to query.
1469  * @param[in, out] data
1470  *   Pointer to storage for the associated query data type.
1471  * @param[out] error
1472  *   Perform verbose error reporting if not NULL. PMDs initialize this
1473  *   structure in case of error only.
1474  *
1475  * @return
1476  *   0 on success, a negative errno value otherwise and rte_errno is set.
1477  */
1478 int
1479 rte_flow_query(uint16_t port_id,
1480                struct rte_flow *flow,
1481                enum rte_flow_action_type action,
1482                void *data,
1483                struct rte_flow_error *error);
1484
1485 /**
1486  * Restrict ingress traffic to the defined flow rules.
1487  *
1488  * Isolated mode guarantees that all ingress traffic comes from defined flow
1489  * rules only (current and future).
1490  *
1491  * Besides making ingress more deterministic, it allows PMDs to safely reuse
1492  * resources otherwise assigned to handle the remaining traffic, such as
1493  * global RSS configuration settings, VLAN filters, MAC address entries,
1494  * legacy filter API rules and so on in order to expand the set of possible
1495  * flow rule types.
1496  *
1497  * Calling this function as soon as possible after device initialization,
1498  * ideally before the first call to rte_eth_dev_configure(), is recommended
1499  * to avoid possible failures due to conflicting settings.
1500  *
1501  * Once effective, leaving isolated mode may not be possible depending on
1502  * PMD implementation.
1503  *
1504  * Additionally, the following functionality has no effect on the underlying
1505  * port and may return errors such as ENOTSUP ("not supported"):
1506  *
1507  * - Toggling promiscuous mode.
1508  * - Toggling allmulticast mode.
1509  * - Configuring MAC addresses.
1510  * - Configuring multicast addresses.
1511  * - Configuring VLAN filters.
1512  * - Configuring Rx filters through the legacy API (e.g. FDIR).
1513  * - Configuring global RSS settings.
1514  *
1515  * @param port_id
1516  *   Port identifier of Ethernet device.
1517  * @param set
1518  *   Nonzero to enter isolated mode, attempt to leave it otherwise.
1519  * @param[out] error
1520  *   Perform verbose error reporting if not NULL. PMDs initialize this
1521  *   structure in case of error only.
1522  *
1523  * @return
1524  *   0 on success, a negative errno value otherwise and rte_errno is set.
1525  */
1526 int
1527 rte_flow_isolate(uint16_t port_id, int set, struct rte_flow_error *error);
1528
1529 /**
1530  * Initialize flow error structure.
1531  *
1532  * @param[out] error
1533  *   Pointer to flow error structure (may be NULL).
1534  * @param code
1535  *   Related error code (rte_errno).
1536  * @param type
1537  *   Cause field and error types.
1538  * @param cause
1539  *   Object responsible for the error.
1540  * @param message
1541  *   Human-readable error message.
1542  *
1543  * @return
1544  *   Negative error code (errno value) and rte_errno is set.
1545  */
1546 int
1547 rte_flow_error_set(struct rte_flow_error *error,
1548                    int code,
1549                    enum rte_flow_error_type type,
1550                    const void *cause,
1551                    const char *message);
1552
1553 /**
1554  * Generic flow representation.
1555  *
1556  * This form is sufficient to describe an rte_flow independently from any
1557  * PMD implementation and allows for replayability and identification.
1558  */
1559 struct rte_flow_desc {
1560         size_t size; /**< Allocated space including data[]. */
1561         struct rte_flow_attr attr; /**< Attributes. */
1562         struct rte_flow_item *items; /**< Items. */
1563         struct rte_flow_action *actions; /**< Actions. */
1564         uint8_t data[]; /**< Storage for items/actions. */
1565 };
1566
1567 /**
1568  * Copy an rte_flow rule description.
1569  *
1570  * @param[in] fd
1571  *   Flow rule description.
1572  * @param[in] len
1573  *   Total size of allocated data for the flow description.
1574  * @param[in] attr
1575  *   Flow rule attributes.
1576  * @param[in] items
1577  *   Pattern specification (list terminated by the END pattern item).
1578  * @param[in] actions
1579  *   Associated actions (list terminated by the END action).
1580  *
1581  * @return
1582  *   If len is greater or equal to the size of the flow, the total size of the
1583  *   flow description and its data.
1584  *   If len is lower than the size of the flow, the number of bytes that would
1585  *   have been written to desc had it been sufficient. Nothing is written.
1586  */
1587 size_t
1588 rte_flow_copy(struct rte_flow_desc *fd, size_t len,
1589               const struct rte_flow_attr *attr,
1590               const struct rte_flow_item *items,
1591               const struct rte_flow_action *actions);
1592
1593 #ifdef __cplusplus
1594 }
1595 #endif
1596
1597 #endif /* RTE_FLOW_H_ */