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