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