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