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