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