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