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