6ace24ff4d20779ac1893fc3ed527f31facd6db7
[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          * Similar to QUEUE, except RSS is additionally performed on packets
965          * to spread them among several queues according to the provided
966          * parameters.
967          *
968          * See struct rte_flow_action_rss.
969          */
970         RTE_FLOW_ACTION_TYPE_RSS,
971
972         /**
973          * Redirects packets to the physical function (PF) of the current
974          * device.
975          *
976          * No associated configuration structure.
977          */
978         RTE_FLOW_ACTION_TYPE_PF,
979
980         /**
981          * Redirects packets to the virtual function (VF) of the current
982          * device with the specified ID.
983          *
984          * See struct rte_flow_action_vf.
985          */
986         RTE_FLOW_ACTION_TYPE_VF,
987
988         /**
989          * Traffic metering and policing (MTR).
990          *
991          * See struct rte_flow_action_meter.
992          * See file rte_mtr.h for MTR object configuration.
993          */
994         RTE_FLOW_ACTION_TYPE_METER,
995
996         /**
997          * Redirects packets to security engine of current device for security
998          * processing as specified by security session.
999          *
1000          * See struct rte_flow_action_security.
1001          */
1002         RTE_FLOW_ACTION_TYPE_SECURITY
1003 };
1004
1005 /**
1006  * RTE_FLOW_ACTION_TYPE_MARK
1007  *
1008  * Attaches an integer value to packets and sets PKT_RX_FDIR and
1009  * PKT_RX_FDIR_ID mbuf flags.
1010  *
1011  * This value is arbitrary and application-defined. Maximum allowed value
1012  * depends on the underlying implementation. It is returned in the
1013  * hash.fdir.hi mbuf field.
1014  */
1015 struct rte_flow_action_mark {
1016         uint32_t id; /**< Integer value to return with packets. */
1017 };
1018
1019 /**
1020  * RTE_FLOW_ACTION_TYPE_QUEUE
1021  *
1022  * Assign packets to a given queue index.
1023  *
1024  * Terminating by default.
1025  */
1026 struct rte_flow_action_queue {
1027         uint16_t index; /**< Queue index to use. */
1028 };
1029
1030 /**
1031  * RTE_FLOW_ACTION_TYPE_COUNT (query)
1032  *
1033  * Query structure to retrieve and reset flow rule counters.
1034  */
1035 struct rte_flow_query_count {
1036         uint32_t reset:1; /**< Reset counters after query [in]. */
1037         uint32_t hits_set:1; /**< hits field is set [out]. */
1038         uint32_t bytes_set:1; /**< bytes field is set [out]. */
1039         uint32_t reserved:29; /**< Reserved, must be zero [in, out]. */
1040         uint64_t hits; /**< Number of hits for this rule [out]. */
1041         uint64_t bytes; /**< Number of bytes through this rule [out]. */
1042 };
1043
1044 /**
1045  * RTE_FLOW_ACTION_TYPE_RSS
1046  *
1047  * Similar to QUEUE, except RSS is additionally performed on packets to
1048  * spread them among several queues according to the provided parameters.
1049  *
1050  * Note: RSS hash result is stored in the hash.rss mbuf field which overlaps
1051  * hash.fdir.lo. Since the MARK action sets the hash.fdir.hi field only,
1052  * both can be requested simultaneously.
1053  *
1054  * Terminating by default.
1055  */
1056 struct rte_flow_action_rss {
1057         const struct rte_eth_rss_conf *rss_conf; /**< RSS parameters. */
1058         uint16_t num; /**< Number of entries in queue[]. */
1059         uint16_t queue[]; /**< Queues indices to use. */
1060 };
1061
1062 /**
1063  * RTE_FLOW_ACTION_TYPE_VF
1064  *
1065  * Redirects packets to a virtual function (VF) of the current device.
1066  *
1067  * Packets matched by a VF pattern item can be redirected to their original
1068  * VF ID instead of the specified one. This parameter may not be available
1069  * and is not guaranteed to work properly if the VF part is matched by a
1070  * prior flow rule or if packets are not addressed to a VF in the first
1071  * place.
1072  *
1073  * Terminating by default.
1074  */
1075 struct rte_flow_action_vf {
1076         uint32_t original:1; /**< Use original VF ID if possible. */
1077         uint32_t reserved:31; /**< Reserved, must be zero. */
1078         uint32_t id; /**< VF ID to redirect packets to. */
1079 };
1080
1081 /**
1082  * RTE_FLOW_ACTION_TYPE_METER
1083  *
1084  * Traffic metering and policing (MTR).
1085  *
1086  * Packets matched by items of this type can be either dropped or passed to the
1087  * next item with their color set by the MTR object.
1088  *
1089  * Non-terminating by default.
1090  */
1091 struct rte_flow_action_meter {
1092         uint32_t mtr_id; /**< MTR object ID created with rte_mtr_create(). */
1093 };
1094
1095 /**
1096  * RTE_FLOW_ACTION_TYPE_SECURITY
1097  *
1098  * Perform the security action on flows matched by the pattern items
1099  * according to the configuration of the security session.
1100  *
1101  * This action modifies the payload of matched flows. For INLINE_CRYPTO, the
1102  * security protocol headers and IV are fully provided by the application as
1103  * specified in the flow pattern. The payload of matching packets is
1104  * encrypted on egress, and decrypted and authenticated on ingress.
1105  * For INLINE_PROTOCOL, the security protocol is fully offloaded to HW,
1106  * providing full encapsulation and decapsulation of packets in security
1107  * protocols. The flow pattern specifies both the outer security header fields
1108  * and the inner packet fields. The security session specified in the action
1109  * must match the pattern parameters.
1110  *
1111  * The security session specified in the action must be created on the same
1112  * port as the flow action that is being specified.
1113  *
1114  * The ingress/egress flow attribute should match that specified in the
1115  * security session if the security session supports the definition of the
1116  * direction.
1117  *
1118  * Multiple flows can be configured to use the same security session.
1119  *
1120  * Non-terminating by default.
1121  */
1122 struct rte_flow_action_security {
1123         void *security_session; /**< Pointer to security session structure. */
1124 };
1125
1126 /**
1127  * Definition of a single action.
1128  *
1129  * A list of actions is terminated by a END action.
1130  *
1131  * For simple actions without a configuration structure, conf remains NULL.
1132  */
1133 struct rte_flow_action {
1134         enum rte_flow_action_type type; /**< Action type. */
1135         const void *conf; /**< Pointer to action configuration structure. */
1136 };
1137
1138 /**
1139  * Opaque type returned after successfully creating a flow.
1140  *
1141  * This handle can be used to manage and query the related flow (e.g. to
1142  * destroy it or retrieve counters).
1143  */
1144 struct rte_flow;
1145
1146 /**
1147  * Verbose error types.
1148  *
1149  * Most of them provide the type of the object referenced by struct
1150  * rte_flow_error.cause.
1151  */
1152 enum rte_flow_error_type {
1153         RTE_FLOW_ERROR_TYPE_NONE, /**< No error. */
1154         RTE_FLOW_ERROR_TYPE_UNSPECIFIED, /**< Cause unspecified. */
1155         RTE_FLOW_ERROR_TYPE_HANDLE, /**< Flow rule (handle). */
1156         RTE_FLOW_ERROR_TYPE_ATTR_GROUP, /**< Group field. */
1157         RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY, /**< Priority field. */
1158         RTE_FLOW_ERROR_TYPE_ATTR_INGRESS, /**< Ingress field. */
1159         RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, /**< Egress field. */
1160         RTE_FLOW_ERROR_TYPE_ATTR, /**< Attributes structure. */
1161         RTE_FLOW_ERROR_TYPE_ITEM_NUM, /**< Pattern length. */
1162         RTE_FLOW_ERROR_TYPE_ITEM_SPEC, /**< Item specification. */
1163         RTE_FLOW_ERROR_TYPE_ITEM_LAST, /**< Item specification range. */
1164         RTE_FLOW_ERROR_TYPE_ITEM_MASK, /**< Item specification mask. */
1165         RTE_FLOW_ERROR_TYPE_ITEM, /**< Specific pattern item. */
1166         RTE_FLOW_ERROR_TYPE_ACTION_NUM, /**< Number of actions. */
1167         RTE_FLOW_ERROR_TYPE_ACTION_CONF, /**< Action configuration. */
1168         RTE_FLOW_ERROR_TYPE_ACTION, /**< Specific action. */
1169 };
1170
1171 /**
1172  * Verbose error structure definition.
1173  *
1174  * This object is normally allocated by applications and set by PMDs, the
1175  * message points to a constant string which does not need to be freed by
1176  * the application, however its pointer can be considered valid only as long
1177  * as its associated DPDK port remains configured. Closing the underlying
1178  * device or unloading the PMD invalidates it.
1179  *
1180  * Both cause and message may be NULL regardless of the error type.
1181  */
1182 struct rte_flow_error {
1183         enum rte_flow_error_type type; /**< Cause field and error types. */
1184         const void *cause; /**< Object responsible for the error. */
1185         const char *message; /**< Human-readable error message. */
1186 };
1187
1188 /**
1189  * Check whether a flow rule can be created on a given port.
1190  *
1191  * The flow rule is validated for correctness and whether it could be accepted
1192  * by the device given sufficient resources. The rule is checked against the
1193  * current device mode and queue configuration. The flow rule may also
1194  * optionally be validated against existing flow rules and device resources.
1195  * This function has no effect on the target device.
1196  *
1197  * The returned value is guaranteed to remain valid only as long as no
1198  * successful calls to rte_flow_create() or rte_flow_destroy() are made in
1199  * the meantime and no device parameter affecting flow rules in any way are
1200  * modified, due to possible collisions or resource limitations (although in
1201  * such cases EINVAL should not be returned).
1202  *
1203  * @param port_id
1204  *   Port identifier of Ethernet device.
1205  * @param[in] attr
1206  *   Flow rule attributes.
1207  * @param[in] pattern
1208  *   Pattern specification (list terminated by the END pattern item).
1209  * @param[in] actions
1210  *   Associated actions (list terminated by the END action).
1211  * @param[out] error
1212  *   Perform verbose error reporting if not NULL. PMDs initialize this
1213  *   structure in case of error only.
1214  *
1215  * @return
1216  *   0 if flow rule is valid and can be created. A negative errno value
1217  *   otherwise (rte_errno is also set), the following errors are defined:
1218  *
1219  *   -ENOSYS: underlying device does not support this functionality.
1220  *
1221  *   -EIO: underlying device is removed.
1222  *
1223  *   -EINVAL: unknown or invalid rule specification.
1224  *
1225  *   -ENOTSUP: valid but unsupported rule specification (e.g. partial
1226  *   bit-masks are unsupported).
1227  *
1228  *   -EEXIST: collision with an existing rule. Only returned if device
1229  *   supports flow rule collision checking and there was a flow rule
1230  *   collision. Not receiving this return code is no guarantee that creating
1231  *   the rule will not fail due to a collision.
1232  *
1233  *   -ENOMEM: not enough memory to execute the function, or if the device
1234  *   supports resource validation, resource limitation on the device.
1235  *
1236  *   -EBUSY: action cannot be performed due to busy device resources, may
1237  *   succeed if the affected queues or even the entire port are in a stopped
1238  *   state (see rte_eth_dev_rx_queue_stop() and rte_eth_dev_stop()).
1239  */
1240 int
1241 rte_flow_validate(uint16_t port_id,
1242                   const struct rte_flow_attr *attr,
1243                   const struct rte_flow_item pattern[],
1244                   const struct rte_flow_action actions[],
1245                   struct rte_flow_error *error);
1246
1247 /**
1248  * Create a flow rule on a given port.
1249  *
1250  * @param port_id
1251  *   Port identifier of Ethernet device.
1252  * @param[in] attr
1253  *   Flow rule attributes.
1254  * @param[in] pattern
1255  *   Pattern specification (list terminated by the END pattern item).
1256  * @param[in] actions
1257  *   Associated actions (list terminated by the END action).
1258  * @param[out] error
1259  *   Perform verbose error reporting if not NULL. PMDs initialize this
1260  *   structure in case of error only.
1261  *
1262  * @return
1263  *   A valid handle in case of success, NULL otherwise and rte_errno is set
1264  *   to the positive version of one of the error codes defined for
1265  *   rte_flow_validate().
1266  */
1267 struct rte_flow *
1268 rte_flow_create(uint16_t port_id,
1269                 const struct rte_flow_attr *attr,
1270                 const struct rte_flow_item pattern[],
1271                 const struct rte_flow_action actions[],
1272                 struct rte_flow_error *error);
1273
1274 /**
1275  * Destroy a flow rule on a given port.
1276  *
1277  * Failure to destroy a flow rule handle may occur when other flow rules
1278  * depend on it, and destroying it would result in an inconsistent state.
1279  *
1280  * This function is only guaranteed to succeed if handles are destroyed in
1281  * reverse order of their creation.
1282  *
1283  * @param port_id
1284  *   Port identifier of Ethernet device.
1285  * @param flow
1286  *   Flow rule handle to destroy.
1287  * @param[out] error
1288  *   Perform verbose error reporting if not NULL. PMDs initialize this
1289  *   structure in case of error only.
1290  *
1291  * @return
1292  *   0 on success, a negative errno value otherwise and rte_errno is set.
1293  */
1294 int
1295 rte_flow_destroy(uint16_t port_id,
1296                  struct rte_flow *flow,
1297                  struct rte_flow_error *error);
1298
1299 /**
1300  * Destroy all flow rules associated with a port.
1301  *
1302  * In the unlikely event of failure, handles are still considered destroyed
1303  * and no longer valid but the port must be assumed to be in an inconsistent
1304  * state.
1305  *
1306  * @param port_id
1307  *   Port identifier of Ethernet device.
1308  * @param[out] error
1309  *   Perform verbose error reporting if not NULL. PMDs initialize this
1310  *   structure in case of error only.
1311  *
1312  * @return
1313  *   0 on success, a negative errno value otherwise and rte_errno is set.
1314  */
1315 int
1316 rte_flow_flush(uint16_t port_id,
1317                struct rte_flow_error *error);
1318
1319 /**
1320  * Query an existing flow rule.
1321  *
1322  * This function allows retrieving flow-specific data such as counters.
1323  * Data is gathered by special actions which must be present in the flow
1324  * rule definition.
1325  *
1326  * \see RTE_FLOW_ACTION_TYPE_COUNT
1327  *
1328  * @param port_id
1329  *   Port identifier of Ethernet device.
1330  * @param flow
1331  *   Flow rule handle to query.
1332  * @param action
1333  *   Action type to query.
1334  * @param[in, out] data
1335  *   Pointer to storage for the associated query data type.
1336  * @param[out] error
1337  *   Perform verbose error reporting if not NULL. PMDs initialize this
1338  *   structure in case of error only.
1339  *
1340  * @return
1341  *   0 on success, a negative errno value otherwise and rte_errno is set.
1342  */
1343 int
1344 rte_flow_query(uint16_t port_id,
1345                struct rte_flow *flow,
1346                enum rte_flow_action_type action,
1347                void *data,
1348                struct rte_flow_error *error);
1349
1350 /**
1351  * Restrict ingress traffic to the defined flow rules.
1352  *
1353  * Isolated mode guarantees that all ingress traffic comes from defined flow
1354  * rules only (current and future).
1355  *
1356  * Besides making ingress more deterministic, it allows PMDs to safely reuse
1357  * resources otherwise assigned to handle the remaining traffic, such as
1358  * global RSS configuration settings, VLAN filters, MAC address entries,
1359  * legacy filter API rules and so on in order to expand the set of possible
1360  * flow rule types.
1361  *
1362  * Calling this function as soon as possible after device initialization,
1363  * ideally before the first call to rte_eth_dev_configure(), is recommended
1364  * to avoid possible failures due to conflicting settings.
1365  *
1366  * Once effective, leaving isolated mode may not be possible depending on
1367  * PMD implementation.
1368  *
1369  * Additionally, the following functionality has no effect on the underlying
1370  * port and may return errors such as ENOTSUP ("not supported"):
1371  *
1372  * - Toggling promiscuous mode.
1373  * - Toggling allmulticast mode.
1374  * - Configuring MAC addresses.
1375  * - Configuring multicast addresses.
1376  * - Configuring VLAN filters.
1377  * - Configuring Rx filters through the legacy API (e.g. FDIR).
1378  * - Configuring global RSS settings.
1379  *
1380  * @param port_id
1381  *   Port identifier of Ethernet device.
1382  * @param set
1383  *   Nonzero to enter isolated mode, attempt to leave it otherwise.
1384  * @param[out] error
1385  *   Perform verbose error reporting if not NULL. PMDs initialize this
1386  *   structure in case of error only.
1387  *
1388  * @return
1389  *   0 on success, a negative errno value otherwise and rte_errno is set.
1390  */
1391 int
1392 rte_flow_isolate(uint16_t port_id, int set, struct rte_flow_error *error);
1393
1394 /**
1395  * Initialize flow error structure.
1396  *
1397  * @param[out] error
1398  *   Pointer to flow error structure (may be NULL).
1399  * @param code
1400  *   Related error code (rte_errno).
1401  * @param type
1402  *   Cause field and error types.
1403  * @param cause
1404  *   Object responsible for the error.
1405  * @param message
1406  *   Human-readable error message.
1407  *
1408  * @return
1409  *   Negative error code (errno value) and rte_errno is set.
1410  */
1411 int
1412 rte_flow_error_set(struct rte_flow_error *error,
1413                    int code,
1414                    enum rte_flow_error_type type,
1415                    const void *cause,
1416                    const char *message);
1417
1418 /**
1419  * Generic flow representation.
1420  *
1421  * This form is sufficient to describe an rte_flow independently from any
1422  * PMD implementation and allows for replayability and identification.
1423  */
1424 struct rte_flow_desc {
1425         size_t size; /**< Allocated space including data[]. */
1426         struct rte_flow_attr attr; /**< Attributes. */
1427         struct rte_flow_item *items; /**< Items. */
1428         struct rte_flow_action *actions; /**< Actions. */
1429         uint8_t data[]; /**< Storage for items/actions. */
1430 };
1431
1432 /**
1433  * Copy an rte_flow rule description.
1434  *
1435  * @param[in] fd
1436  *   Flow rule description.
1437  * @param[in] len
1438  *   Total size of allocated data for the flow description.
1439  * @param[in] attr
1440  *   Flow rule attributes.
1441  * @param[in] items
1442  *   Pattern specification (list terminated by the END pattern item).
1443  * @param[in] actions
1444  *   Associated actions (list terminated by the END action).
1445  *
1446  * @return
1447  *   If len is greater or equal to the size of the flow, the total size of the
1448  *   flow description and its data.
1449  *   If len is lower than the size of the flow, the number of bytes that would
1450  *   have been written to desc had it been sufficient. Nothing is written.
1451  */
1452 size_t
1453 rte_flow_copy(struct rte_flow_desc *fd, size_t len,
1454               const struct rte_flow_attr *attr,
1455               const struct rte_flow_item *items,
1456               const struct rte_flow_action *actions);
1457
1458 #ifdef __cplusplus
1459 }
1460 #endif
1461
1462 #endif /* RTE_FLOW_H_ */