ethdev: add PPPoE to flow API
[dpdk.git] / lib / librte_ethdev / rte_flow.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2016 6WIND S.A.
3  * Copyright 2016 Mellanox Technologies, Ltd
4  */
5
6 #ifndef RTE_FLOW_H_
7 #define RTE_FLOW_H_
8
9 /**
10  * @file
11  * RTE generic flow API
12  *
13  * This interface provides the ability to program packet matching and
14  * associated actions in hardware through flow rules.
15  */
16
17 #include <stddef.h>
18 #include <stdint.h>
19
20 #include <rte_arp.h>
21 #include <rte_common.h>
22 #include <rte_ether.h>
23 #include <rte_icmp.h>
24 #include <rte_ip.h>
25 #include <rte_sctp.h>
26 #include <rte_tcp.h>
27 #include <rte_udp.h>
28 #include <rte_byteorder.h>
29 #include <rte_esp.h>
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35 /**
36  * Flow rule attributes.
37  *
38  * Priorities are set on a per rule based within groups.
39  *
40  * Lower values denote higher priority, the highest priority for a flow rule
41  * is 0, so that a flow that matches for than one rule, the rule with the
42  * lowest priority value will always be matched.
43  *
44  * Although optional, applications are encouraged to group similar rules as
45  * much as possible to fully take advantage of hardware capabilities
46  * (e.g. optimized matching) and work around limitations (e.g. a single
47  * pattern type possibly allowed in a given group). Applications should be
48  * aware that groups are not linked by default, and that they must be
49  * explicitly linked by the application using the JUMP action.
50  *
51  * Priority levels are arbitrary and up to the application, they
52  * do not need to be contiguous nor start from 0, however the maximum number
53  * varies between devices and may be affected by existing flow rules.
54  *
55  * If a packet is matched by several rules of a given group for a given
56  * priority level, the outcome is undefined. It can take any path, may be
57  * duplicated or even cause unrecoverable errors.
58  *
59  * Note that support for more than a single group and priority level is not
60  * guaranteed.
61  *
62  * Flow rules can apply to inbound and/or outbound traffic (ingress/egress).
63  *
64  * Several pattern items and actions are valid and can be used in both
65  * directions. Those valid for only one direction are described as such.
66  *
67  * At least one direction must be specified.
68  *
69  * Specifying both directions at once for a given rule is not recommended
70  * but may be valid in a few cases (e.g. shared counter).
71  */
72 struct rte_flow_attr {
73         uint32_t group; /**< Priority group. */
74         uint32_t priority; /**< Rule priority level within group. */
75         uint32_t ingress:1; /**< Rule applies to ingress traffic. */
76         uint32_t egress:1; /**< Rule applies to egress traffic. */
77         /**
78          * Instead of simply matching the properties of traffic as it would
79          * appear on a given DPDK port ID, enabling this attribute transfers
80          * a flow rule to the lowest possible level of any device endpoints
81          * found in the pattern.
82          *
83          * When supported, this effectively enables an application to
84          * re-route traffic not necessarily intended for it (e.g. coming
85          * from or addressed to different physical ports, VFs or
86          * applications) at the device level.
87          *
88          * It complements the behavior of some pattern items such as
89          * RTE_FLOW_ITEM_TYPE_PHY_PORT and is meaningless without them.
90          *
91          * When transferring flow rules, ingress and egress attributes keep
92          * their original meaning, as if processing traffic emitted or
93          * received by the application.
94          */
95         uint32_t transfer:1;
96         uint32_t reserved:29; /**< Reserved, must be zero. */
97 };
98
99 /**
100  * Matching pattern item types.
101  *
102  * Pattern items fall in two categories:
103  *
104  * - Matching protocol headers and packet data, usually associated with a
105  *   specification structure. These must be stacked in the same order as the
106  *   protocol layers to match inside packets, starting from the lowest.
107  *
108  * - Matching meta-data or affecting pattern processing, often without a
109  *   specification structure. Since they do not match packet contents, their
110  *   position in the list is usually not relevant.
111  *
112  * See the description of individual types for more information. Those
113  * marked with [META] fall into the second category.
114  */
115 enum rte_flow_item_type {
116         /**
117          * [META]
118          *
119          * End marker for item lists. Prevents further processing of items,
120          * thereby ending the pattern.
121          *
122          * No associated specification structure.
123          */
124         RTE_FLOW_ITEM_TYPE_END,
125
126         /**
127          * [META]
128          *
129          * Used as a placeholder for convenience. It is ignored and simply
130          * discarded by PMDs.
131          *
132          * No associated specification structure.
133          */
134         RTE_FLOW_ITEM_TYPE_VOID,
135
136         /**
137          * [META]
138          *
139          * Inverted matching, i.e. process packets that do not match the
140          * pattern.
141          *
142          * No associated specification structure.
143          */
144         RTE_FLOW_ITEM_TYPE_INVERT,
145
146         /**
147          * Matches any protocol in place of the current layer, a single ANY
148          * may also stand for several protocol layers.
149          *
150          * See struct rte_flow_item_any.
151          */
152         RTE_FLOW_ITEM_TYPE_ANY,
153
154         /**
155          * [META]
156          *
157          * Matches traffic originating from (ingress) or going to (egress)
158          * the physical function of the current device.
159          *
160          * No associated specification structure.
161          */
162         RTE_FLOW_ITEM_TYPE_PF,
163
164         /**
165          * [META]
166          *
167          * Matches traffic originating from (ingress) or going to (egress) a
168          * given virtual function of the current device.
169          *
170          * See struct rte_flow_item_vf.
171          */
172         RTE_FLOW_ITEM_TYPE_VF,
173
174         /**
175          * [META]
176          *
177          * Matches traffic originating from (ingress) or going to (egress) a
178          * physical port of the underlying device.
179          *
180          * See struct rte_flow_item_phy_port.
181          */
182         RTE_FLOW_ITEM_TYPE_PHY_PORT,
183
184         /**
185          * [META]
186          *
187          * Matches traffic originating from (ingress) or going to (egress) a
188          * given DPDK port ID.
189          *
190          * See struct rte_flow_item_port_id.
191          */
192         RTE_FLOW_ITEM_TYPE_PORT_ID,
193
194         /**
195          * Matches a byte string of a given length at a given offset.
196          *
197          * See struct rte_flow_item_raw.
198          */
199         RTE_FLOW_ITEM_TYPE_RAW,
200
201         /**
202          * Matches an Ethernet header.
203          *
204          * See struct rte_flow_item_eth.
205          */
206         RTE_FLOW_ITEM_TYPE_ETH,
207
208         /**
209          * Matches an 802.1Q/ad VLAN tag.
210          *
211          * See struct rte_flow_item_vlan.
212          */
213         RTE_FLOW_ITEM_TYPE_VLAN,
214
215         /**
216          * Matches an IPv4 header.
217          *
218          * See struct rte_flow_item_ipv4.
219          */
220         RTE_FLOW_ITEM_TYPE_IPV4,
221
222         /**
223          * Matches an IPv6 header.
224          *
225          * See struct rte_flow_item_ipv6.
226          */
227         RTE_FLOW_ITEM_TYPE_IPV6,
228
229         /**
230          * Matches an ICMP header.
231          *
232          * See struct rte_flow_item_icmp.
233          */
234         RTE_FLOW_ITEM_TYPE_ICMP,
235
236         /**
237          * Matches a UDP header.
238          *
239          * See struct rte_flow_item_udp.
240          */
241         RTE_FLOW_ITEM_TYPE_UDP,
242
243         /**
244          * Matches a TCP header.
245          *
246          * See struct rte_flow_item_tcp.
247          */
248         RTE_FLOW_ITEM_TYPE_TCP,
249
250         /**
251          * Matches a SCTP header.
252          *
253          * See struct rte_flow_item_sctp.
254          */
255         RTE_FLOW_ITEM_TYPE_SCTP,
256
257         /**
258          * Matches a VXLAN header.
259          *
260          * See struct rte_flow_item_vxlan.
261          */
262         RTE_FLOW_ITEM_TYPE_VXLAN,
263
264         /**
265          * Matches a E_TAG header.
266          *
267          * See struct rte_flow_item_e_tag.
268          */
269         RTE_FLOW_ITEM_TYPE_E_TAG,
270
271         /**
272          * Matches a NVGRE header.
273          *
274          * See struct rte_flow_item_nvgre.
275          */
276         RTE_FLOW_ITEM_TYPE_NVGRE,
277
278         /**
279          * Matches a MPLS header.
280          *
281          * See struct rte_flow_item_mpls.
282          */
283         RTE_FLOW_ITEM_TYPE_MPLS,
284
285         /**
286          * Matches a GRE header.
287          *
288          * See struct rte_flow_item_gre.
289          */
290         RTE_FLOW_ITEM_TYPE_GRE,
291
292         /**
293          * [META]
294          *
295          * Fuzzy pattern match, expect faster than default.
296          *
297          * This is for device that support fuzzy matching option.
298          * Usually a fuzzy matching is fast but the cost is accuracy.
299          *
300          * See struct rte_flow_item_fuzzy.
301          */
302         RTE_FLOW_ITEM_TYPE_FUZZY,
303
304         /**
305          * Matches a GTP header.
306          *
307          * Configure flow for GTP packets.
308          *
309          * See struct rte_flow_item_gtp.
310          */
311         RTE_FLOW_ITEM_TYPE_GTP,
312
313         /**
314          * Matches a GTP header.
315          *
316          * Configure flow for GTP-C packets.
317          *
318          * See struct rte_flow_item_gtp.
319          */
320         RTE_FLOW_ITEM_TYPE_GTPC,
321
322         /**
323          * Matches a GTP header.
324          *
325          * Configure flow for GTP-U packets.
326          *
327          * See struct rte_flow_item_gtp.
328          */
329         RTE_FLOW_ITEM_TYPE_GTPU,
330
331         /**
332          * Matches a ESP header.
333          *
334          * See struct rte_flow_item_esp.
335          */
336         RTE_FLOW_ITEM_TYPE_ESP,
337
338         /**
339          * Matches a GENEVE header.
340          *
341          * See struct rte_flow_item_geneve.
342          */
343         RTE_FLOW_ITEM_TYPE_GENEVE,
344
345         /**
346          * Matches a VXLAN-GPE header.
347          *
348          * See struct rte_flow_item_vxlan_gpe.
349          */
350         RTE_FLOW_ITEM_TYPE_VXLAN_GPE,
351
352         /**
353          * Matches an ARP header for Ethernet/IPv4.
354          *
355          * See struct rte_flow_item_arp_eth_ipv4.
356          */
357         RTE_FLOW_ITEM_TYPE_ARP_ETH_IPV4,
358
359         /**
360          * Matches the presence of any IPv6 extension header.
361          *
362          * See struct rte_flow_item_ipv6_ext.
363          */
364         RTE_FLOW_ITEM_TYPE_IPV6_EXT,
365
366         /**
367          * Matches any ICMPv6 header.
368          *
369          * See struct rte_flow_item_icmp6.
370          */
371         RTE_FLOW_ITEM_TYPE_ICMP6,
372
373         /**
374          * Matches an ICMPv6 neighbor discovery solicitation.
375          *
376          * See struct rte_flow_item_icmp6_nd_ns.
377          */
378         RTE_FLOW_ITEM_TYPE_ICMP6_ND_NS,
379
380         /**
381          * Matches an ICMPv6 neighbor discovery advertisement.
382          *
383          * See struct rte_flow_item_icmp6_nd_na.
384          */
385         RTE_FLOW_ITEM_TYPE_ICMP6_ND_NA,
386
387         /**
388          * Matches the presence of any ICMPv6 neighbor discovery option.
389          *
390          * See struct rte_flow_item_icmp6_nd_opt.
391          */
392         RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT,
393
394         /**
395          * Matches an ICMPv6 neighbor discovery source Ethernet link-layer
396          * address option.
397          *
398          * See struct rte_flow_item_icmp6_nd_opt_sla_eth.
399          */
400         RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT_SLA_ETH,
401
402         /**
403          * Matches an ICMPv6 neighbor discovery target Ethernet link-layer
404          * address option.
405          *
406          * See struct rte_flow_item_icmp6_nd_opt_tla_eth.
407          */
408         RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT_TLA_ETH,
409
410         /**
411          * Matches specified mark field.
412          *
413          * See struct rte_flow_item_mark.
414          */
415         RTE_FLOW_ITEM_TYPE_MARK,
416
417         /**
418          * [META]
419          *
420          * Matches a metadata value specified in mbuf metadata field.
421          * See struct rte_flow_item_meta.
422          */
423         RTE_FLOW_ITEM_TYPE_META,
424
425         /**
426          * Matches a GRE optional key field.
427          *
428          * The value should a big-endian 32bit integer.
429          *
430          * When this item present the K bit is implicitly matched as "1"
431          * in the default mask.
432          *
433          * @p spec/mask type:
434          * @code rte_be32_t * @endcode
435          */
436         RTE_FLOW_ITEM_TYPE_GRE_KEY,
437
438         /**
439          * Matches a GTP extension header: PDU session container.
440          *
441          * Configure flow for GTP packets with extension header type 0x85.
442          *
443          * See struct rte_flow_item_gtp_psc.
444          */
445         RTE_FLOW_ITEM_TYPE_GTP_PSC,
446
447         /**
448          * Matches a PPPoE header.
449          *
450          * Configure flow for PPPoE session packets.
451          *
452          * See struct rte_flow_item_pppoe.
453          */
454         RTE_FLOW_ITEM_TYPE_PPPOES,
455
456         /**
457          * Matches a PPPoE header.
458          *
459          * Configure flow for PPPoE discovery packets.
460          *
461          * See struct rte_flow_item_pppoe.
462          */
463         RTE_FLOW_ITEM_TYPE_PPPOED,
464
465         /**
466          * Matches a PPPoE optional proto_id field.
467          *
468          * It only applies to PPPoE session packets.
469          *
470          * See struct rte_flow_item_pppoe_proto_id.
471          */
472         RTE_FLOW_ITEM_TYPE_PPPOE_PROTO_ID,
473 };
474
475 /**
476  * RTE_FLOW_ITEM_TYPE_ANY
477  *
478  * Matches any protocol in place of the current layer, a single ANY may also
479  * stand for several protocol layers.
480  *
481  * This is usually specified as the first pattern item when looking for a
482  * protocol anywhere in a packet.
483  *
484  * A zeroed mask stands for any number of layers.
485  */
486 struct rte_flow_item_any {
487         uint32_t num; /**< Number of layers covered. */
488 };
489
490 /** Default mask for RTE_FLOW_ITEM_TYPE_ANY. */
491 #ifndef __cplusplus
492 static const struct rte_flow_item_any rte_flow_item_any_mask = {
493         .num = 0x00000000,
494 };
495 #endif
496
497 /**
498  * RTE_FLOW_ITEM_TYPE_VF
499  *
500  * Matches traffic originating from (ingress) or going to (egress) a given
501  * virtual function of the current device.
502  *
503  * If supported, should work even if the virtual function is not managed by
504  * the application and thus not associated with a DPDK port ID.
505  *
506  * Note this pattern item does not match VF representors traffic which, as
507  * separate entities, should be addressed through their own DPDK port IDs.
508  *
509  * - Can be specified multiple times to match traffic addressed to several
510  *   VF IDs.
511  * - Can be combined with a PF item to match both PF and VF traffic.
512  *
513  * A zeroed mask can be used to match any VF ID.
514  */
515 struct rte_flow_item_vf {
516         uint32_t id; /**< VF ID. */
517 };
518
519 /** Default mask for RTE_FLOW_ITEM_TYPE_VF. */
520 #ifndef __cplusplus
521 static const struct rte_flow_item_vf rte_flow_item_vf_mask = {
522         .id = 0x00000000,
523 };
524 #endif
525
526 /**
527  * RTE_FLOW_ITEM_TYPE_PHY_PORT
528  *
529  * Matches traffic originating from (ingress) or going to (egress) a
530  * physical port of the underlying device.
531  *
532  * The first PHY_PORT item overrides the physical port normally associated
533  * with the specified DPDK input port (port_id). This item can be provided
534  * several times to match additional physical ports.
535  *
536  * Note that physical ports are not necessarily tied to DPDK input ports
537  * (port_id) when those are not under DPDK control. Possible values are
538  * specific to each device, they are not necessarily indexed from zero and
539  * may not be contiguous.
540  *
541  * As a device property, the list of allowed values as well as the value
542  * associated with a port_id should be retrieved by other means.
543  *
544  * A zeroed mask can be used to match any port index.
545  */
546 struct rte_flow_item_phy_port {
547         uint32_t index; /**< Physical port index. */
548 };
549
550 /** Default mask for RTE_FLOW_ITEM_TYPE_PHY_PORT. */
551 #ifndef __cplusplus
552 static const struct rte_flow_item_phy_port rte_flow_item_phy_port_mask = {
553         .index = 0x00000000,
554 };
555 #endif
556
557 /**
558  * RTE_FLOW_ITEM_TYPE_PORT_ID
559  *
560  * Matches traffic originating from (ingress) or going to (egress) a given
561  * DPDK port ID.
562  *
563  * Normally only supported if the port ID in question is known by the
564  * underlying PMD and related to the device the flow rule is created
565  * against.
566  *
567  * This must not be confused with @p PHY_PORT which refers to the physical
568  * port of a device, whereas @p PORT_ID refers to a struct rte_eth_dev
569  * object on the application side (also known as "port representor"
570  * depending on the kind of underlying device).
571  */
572 struct rte_flow_item_port_id {
573         uint32_t id; /**< DPDK port ID. */
574 };
575
576 /** Default mask for RTE_FLOW_ITEM_TYPE_PORT_ID. */
577 #ifndef __cplusplus
578 static const struct rte_flow_item_port_id rte_flow_item_port_id_mask = {
579         .id = 0xffffffff,
580 };
581 #endif
582
583 /**
584  * RTE_FLOW_ITEM_TYPE_RAW
585  *
586  * Matches a byte string of a given length at a given offset.
587  *
588  * Offset is either absolute (using the start of the packet) or relative to
589  * the end of the previous matched item in the stack, in which case negative
590  * values are allowed.
591  *
592  * If search is enabled, offset is used as the starting point. The search
593  * area can be delimited by setting limit to a nonzero value, which is the
594  * maximum number of bytes after offset where the pattern may start.
595  *
596  * Matching a zero-length pattern is allowed, doing so resets the relative
597  * offset for subsequent items.
598  *
599  * This type does not support ranges (struct rte_flow_item.last).
600  */
601 struct rte_flow_item_raw {
602         uint32_t relative:1; /**< Look for pattern after the previous item. */
603         uint32_t search:1; /**< Search pattern from offset (see also limit). */
604         uint32_t reserved:30; /**< Reserved, must be set to zero. */
605         int32_t offset; /**< Absolute or relative offset for pattern. */
606         uint16_t limit; /**< Search area limit for start of pattern. */
607         uint16_t length; /**< Pattern length. */
608         const uint8_t *pattern; /**< Byte string to look for. */
609 };
610
611 /** Default mask for RTE_FLOW_ITEM_TYPE_RAW. */
612 #ifndef __cplusplus
613 static const struct rte_flow_item_raw rte_flow_item_raw_mask = {
614         .relative = 1,
615         .search = 1,
616         .reserved = 0x3fffffff,
617         .offset = 0xffffffff,
618         .limit = 0xffff,
619         .length = 0xffff,
620         .pattern = NULL,
621 };
622 #endif
623
624 /**
625  * RTE_FLOW_ITEM_TYPE_ETH
626  *
627  * Matches an Ethernet header.
628  *
629  * The @p type field either stands for "EtherType" or "TPID" when followed
630  * by so-called layer 2.5 pattern items such as RTE_FLOW_ITEM_TYPE_VLAN. In
631  * the latter case, @p type refers to that of the outer header, with the
632  * inner EtherType/TPID provided by the subsequent pattern item. This is the
633  * same order as on the wire.
634  */
635 struct rte_flow_item_eth {
636         struct rte_ether_addr dst; /**< Destination MAC. */
637         struct rte_ether_addr src; /**< Source MAC. */
638         rte_be16_t type; /**< EtherType or TPID. */
639 };
640
641 /** Default mask for RTE_FLOW_ITEM_TYPE_ETH. */
642 #ifndef __cplusplus
643 static const struct rte_flow_item_eth rte_flow_item_eth_mask = {
644         .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
645         .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
646         .type = RTE_BE16(0x0000),
647 };
648 #endif
649
650 /**
651  * RTE_FLOW_ITEM_TYPE_VLAN
652  *
653  * Matches an 802.1Q/ad VLAN tag.
654  *
655  * The corresponding standard outer EtherType (TPID) values are
656  * RTE_ETHER_TYPE_VLAN or RTE_ETHER_TYPE_QINQ. It can be overridden by
657  * the preceding pattern item.
658  */
659 struct rte_flow_item_vlan {
660         rte_be16_t tci; /**< Tag control information. */
661         rte_be16_t inner_type; /**< Inner EtherType or TPID. */
662 };
663
664 /** Default mask for RTE_FLOW_ITEM_TYPE_VLAN. */
665 #ifndef __cplusplus
666 static const struct rte_flow_item_vlan rte_flow_item_vlan_mask = {
667         .tci = RTE_BE16(0x0fff),
668         .inner_type = RTE_BE16(0x0000),
669 };
670 #endif
671
672 /**
673  * RTE_FLOW_ITEM_TYPE_IPV4
674  *
675  * Matches an IPv4 header.
676  *
677  * Note: IPv4 options are handled by dedicated pattern items.
678  */
679 struct rte_flow_item_ipv4 {
680         struct rte_ipv4_hdr hdr; /**< IPv4 header definition. */
681 };
682
683 /** Default mask for RTE_FLOW_ITEM_TYPE_IPV4. */
684 #ifndef __cplusplus
685 static const struct rte_flow_item_ipv4 rte_flow_item_ipv4_mask = {
686         .hdr = {
687                 .src_addr = RTE_BE32(0xffffffff),
688                 .dst_addr = RTE_BE32(0xffffffff),
689         },
690 };
691 #endif
692
693 /**
694  * RTE_FLOW_ITEM_TYPE_IPV6.
695  *
696  * Matches an IPv6 header.
697  *
698  * Note: IPv6 options are handled by dedicated pattern items, see
699  * RTE_FLOW_ITEM_TYPE_IPV6_EXT.
700  */
701 struct rte_flow_item_ipv6 {
702         struct rte_ipv6_hdr hdr; /**< IPv6 header definition. */
703 };
704
705 /** Default mask for RTE_FLOW_ITEM_TYPE_IPV6. */
706 #ifndef __cplusplus
707 static const struct rte_flow_item_ipv6 rte_flow_item_ipv6_mask = {
708         .hdr = {
709                 .src_addr =
710                         "\xff\xff\xff\xff\xff\xff\xff\xff"
711                         "\xff\xff\xff\xff\xff\xff\xff\xff",
712                 .dst_addr =
713                         "\xff\xff\xff\xff\xff\xff\xff\xff"
714                         "\xff\xff\xff\xff\xff\xff\xff\xff",
715         },
716 };
717 #endif
718
719 /**
720  * RTE_FLOW_ITEM_TYPE_ICMP.
721  *
722  * Matches an ICMP header.
723  */
724 struct rte_flow_item_icmp {
725         struct rte_icmp_hdr hdr; /**< ICMP header definition. */
726 };
727
728 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP. */
729 #ifndef __cplusplus
730 static const struct rte_flow_item_icmp rte_flow_item_icmp_mask = {
731         .hdr = {
732                 .icmp_type = 0xff,
733                 .icmp_code = 0xff,
734         },
735 };
736 #endif
737
738 /**
739  * RTE_FLOW_ITEM_TYPE_UDP.
740  *
741  * Matches a UDP header.
742  */
743 struct rte_flow_item_udp {
744         struct rte_udp_hdr hdr; /**< UDP header definition. */
745 };
746
747 /** Default mask for RTE_FLOW_ITEM_TYPE_UDP. */
748 #ifndef __cplusplus
749 static const struct rte_flow_item_udp rte_flow_item_udp_mask = {
750         .hdr = {
751                 .src_port = RTE_BE16(0xffff),
752                 .dst_port = RTE_BE16(0xffff),
753         },
754 };
755 #endif
756
757 /**
758  * RTE_FLOW_ITEM_TYPE_TCP.
759  *
760  * Matches a TCP header.
761  */
762 struct rte_flow_item_tcp {
763         struct rte_tcp_hdr hdr; /**< TCP header definition. */
764 };
765
766 /** Default mask for RTE_FLOW_ITEM_TYPE_TCP. */
767 #ifndef __cplusplus
768 static const struct rte_flow_item_tcp rte_flow_item_tcp_mask = {
769         .hdr = {
770                 .src_port = RTE_BE16(0xffff),
771                 .dst_port = RTE_BE16(0xffff),
772         },
773 };
774 #endif
775
776 /**
777  * RTE_FLOW_ITEM_TYPE_SCTP.
778  *
779  * Matches a SCTP header.
780  */
781 struct rte_flow_item_sctp {
782         struct rte_sctp_hdr hdr; /**< SCTP header definition. */
783 };
784
785 /** Default mask for RTE_FLOW_ITEM_TYPE_SCTP. */
786 #ifndef __cplusplus
787 static const struct rte_flow_item_sctp rte_flow_item_sctp_mask = {
788         .hdr = {
789                 .src_port = RTE_BE16(0xffff),
790                 .dst_port = RTE_BE16(0xffff),
791         },
792 };
793 #endif
794
795 /**
796  * RTE_FLOW_ITEM_TYPE_VXLAN.
797  *
798  * Matches a VXLAN header (RFC 7348).
799  */
800 struct rte_flow_item_vxlan {
801         uint8_t flags; /**< Normally 0x08 (I flag). */
802         uint8_t rsvd0[3]; /**< Reserved, normally 0x000000. */
803         uint8_t vni[3]; /**< VXLAN identifier. */
804         uint8_t rsvd1; /**< Reserved, normally 0x00. */
805 };
806
807 /** Default mask for RTE_FLOW_ITEM_TYPE_VXLAN. */
808 #ifndef __cplusplus
809 static const struct rte_flow_item_vxlan rte_flow_item_vxlan_mask = {
810         .vni = "\xff\xff\xff",
811 };
812 #endif
813
814 /**
815  * RTE_FLOW_ITEM_TYPE_E_TAG.
816  *
817  * Matches a E-tag header.
818  *
819  * The corresponding standard outer EtherType (TPID) value is
820  * RTE_ETHER_TYPE_ETAG. It can be overridden by the preceding pattern item.
821  */
822 struct rte_flow_item_e_tag {
823         /**
824          * E-Tag control information (E-TCI).
825          * E-PCP (3b), E-DEI (1b), ingress E-CID base (12b).
826          */
827         rte_be16_t epcp_edei_in_ecid_b;
828         /** Reserved (2b), GRP (2b), E-CID base (12b). */
829         rte_be16_t rsvd_grp_ecid_b;
830         uint8_t in_ecid_e; /**< Ingress E-CID ext. */
831         uint8_t ecid_e; /**< E-CID ext. */
832         rte_be16_t inner_type; /**< Inner EtherType or TPID. */
833 };
834
835 /** Default mask for RTE_FLOW_ITEM_TYPE_E_TAG. */
836 #ifndef __cplusplus
837 static const struct rte_flow_item_e_tag rte_flow_item_e_tag_mask = {
838         .rsvd_grp_ecid_b = RTE_BE16(0x3fff),
839 };
840 #endif
841
842 /**
843  * RTE_FLOW_ITEM_TYPE_NVGRE.
844  *
845  * Matches a NVGRE header.
846  */
847 struct rte_flow_item_nvgre {
848         /**
849          * Checksum (1b), undefined (1b), key bit (1b), sequence number (1b),
850          * reserved 0 (9b), version (3b).
851          *
852          * c_k_s_rsvd0_ver must have value 0x2000 according to RFC 7637.
853          */
854         rte_be16_t c_k_s_rsvd0_ver;
855         rte_be16_t protocol; /**< Protocol type (0x6558). */
856         uint8_t tni[3]; /**< Virtual subnet ID. */
857         uint8_t flow_id; /**< Flow ID. */
858 };
859
860 /** Default mask for RTE_FLOW_ITEM_TYPE_NVGRE. */
861 #ifndef __cplusplus
862 static const struct rte_flow_item_nvgre rte_flow_item_nvgre_mask = {
863         .tni = "\xff\xff\xff",
864 };
865 #endif
866
867 /**
868  * RTE_FLOW_ITEM_TYPE_MPLS.
869  *
870  * Matches a MPLS header.
871  */
872 struct rte_flow_item_mpls {
873         /**
874          * Label (20b), TC (3b), Bottom of Stack (1b).
875          */
876         uint8_t label_tc_s[3];
877         uint8_t ttl; /** Time-to-Live. */
878 };
879
880 /** Default mask for RTE_FLOW_ITEM_TYPE_MPLS. */
881 #ifndef __cplusplus
882 static const struct rte_flow_item_mpls rte_flow_item_mpls_mask = {
883         .label_tc_s = "\xff\xff\xf0",
884 };
885 #endif
886
887 /**
888  * RTE_FLOW_ITEM_TYPE_GRE.
889  *
890  * Matches a GRE header.
891  */
892 struct rte_flow_item_gre {
893         /**
894          * Checksum (1b), reserved 0 (12b), version (3b).
895          * Refer to RFC 2784.
896          */
897         rte_be16_t c_rsvd0_ver;
898         rte_be16_t protocol; /**< Protocol type. */
899 };
900
901 /** Default mask for RTE_FLOW_ITEM_TYPE_GRE. */
902 #ifndef __cplusplus
903 static const struct rte_flow_item_gre rte_flow_item_gre_mask = {
904         .protocol = RTE_BE16(0xffff),
905 };
906 #endif
907
908 /**
909  * RTE_FLOW_ITEM_TYPE_FUZZY
910  *
911  * Fuzzy pattern match, expect faster than default.
912  *
913  * This is for device that support fuzzy match option.
914  * Usually a fuzzy match is fast but the cost is accuracy.
915  * i.e. Signature Match only match pattern's hash value, but it is
916  * possible two different patterns have the same hash value.
917  *
918  * Matching accuracy level can be configure by threshold.
919  * Driver can divide the range of threshold and map to different
920  * accuracy levels that device support.
921  *
922  * Threshold 0 means perfect match (no fuzziness), while threshold
923  * 0xffffffff means fuzziest match.
924  */
925 struct rte_flow_item_fuzzy {
926         uint32_t thresh; /**< Accuracy threshold. */
927 };
928
929 /** Default mask for RTE_FLOW_ITEM_TYPE_FUZZY. */
930 #ifndef __cplusplus
931 static const struct rte_flow_item_fuzzy rte_flow_item_fuzzy_mask = {
932         .thresh = 0xffffffff,
933 };
934 #endif
935
936 /**
937  * RTE_FLOW_ITEM_TYPE_GTP.
938  *
939  * Matches a GTPv1 header.
940  */
941 struct rte_flow_item_gtp {
942         /**
943          * Version (3b), protocol type (1b), reserved (1b),
944          * Extension header flag (1b),
945          * Sequence number flag (1b),
946          * N-PDU number flag (1b).
947          */
948         uint8_t v_pt_rsv_flags;
949         uint8_t msg_type; /**< Message type. */
950         rte_be16_t msg_len; /**< Message length. */
951         rte_be32_t teid; /**< Tunnel endpoint identifier. */
952 };
953
954 /** Default mask for RTE_FLOW_ITEM_TYPE_GTP. */
955 #ifndef __cplusplus
956 static const struct rte_flow_item_gtp rte_flow_item_gtp_mask = {
957         .teid = RTE_BE32(0xffffffff),
958 };
959 #endif
960
961 /**
962  * RTE_FLOW_ITEM_TYPE_ESP
963  *
964  * Matches an ESP header.
965  */
966 struct rte_flow_item_esp {
967         struct rte_esp_hdr hdr; /**< ESP header definition. */
968 };
969
970 /** Default mask for RTE_FLOW_ITEM_TYPE_ESP. */
971 #ifndef __cplusplus
972 static const struct rte_flow_item_esp rte_flow_item_esp_mask = {
973         .hdr = {
974                 .spi = RTE_BE32(0xffffffff),
975         },
976 };
977 #endif
978
979 /**
980  * RTE_FLOW_ITEM_TYPE_GENEVE.
981  *
982  * Matches a GENEVE header.
983  */
984 struct rte_flow_item_geneve {
985         /**
986          * Version (2b), length of the options fields (6b), OAM packet (1b),
987          * critical options present (1b), reserved 0 (6b).
988          */
989         rte_be16_t ver_opt_len_o_c_rsvd0;
990         rte_be16_t protocol; /**< Protocol type. */
991         uint8_t vni[3]; /**< Virtual Network Identifier. */
992         uint8_t rsvd1; /**< Reserved, normally 0x00. */
993 };
994
995 /** Default mask for RTE_FLOW_ITEM_TYPE_GENEVE. */
996 #ifndef __cplusplus
997 static const struct rte_flow_item_geneve rte_flow_item_geneve_mask = {
998         .vni = "\xff\xff\xff",
999 };
1000 #endif
1001
1002 /**
1003  * RTE_FLOW_ITEM_TYPE_VXLAN_GPE (draft-ietf-nvo3-vxlan-gpe-05).
1004  *
1005  * Matches a VXLAN-GPE header.
1006  */
1007 struct rte_flow_item_vxlan_gpe {
1008         uint8_t flags; /**< Normally 0x0c (I and P flags). */
1009         uint8_t rsvd0[2]; /**< Reserved, normally 0x0000. */
1010         uint8_t protocol; /**< Protocol type. */
1011         uint8_t vni[3]; /**< VXLAN identifier. */
1012         uint8_t rsvd1; /**< Reserved, normally 0x00. */
1013 };
1014
1015 /** Default mask for RTE_FLOW_ITEM_TYPE_VXLAN_GPE. */
1016 #ifndef __cplusplus
1017 static const struct rte_flow_item_vxlan_gpe rte_flow_item_vxlan_gpe_mask = {
1018         .vni = "\xff\xff\xff",
1019 };
1020 #endif
1021
1022 /**
1023  * RTE_FLOW_ITEM_TYPE_ARP_ETH_IPV4
1024  *
1025  * Matches an ARP header for Ethernet/IPv4.
1026  */
1027 struct rte_flow_item_arp_eth_ipv4 {
1028         rte_be16_t hrd; /**< Hardware type, normally 1. */
1029         rte_be16_t pro; /**< Protocol type, normally 0x0800. */
1030         uint8_t hln; /**< Hardware address length, normally 6. */
1031         uint8_t pln; /**< Protocol address length, normally 4. */
1032         rte_be16_t op; /**< Opcode (1 for request, 2 for reply). */
1033         struct rte_ether_addr sha; /**< Sender hardware address. */
1034         rte_be32_t spa; /**< Sender IPv4 address. */
1035         struct rte_ether_addr tha; /**< Target hardware address. */
1036         rte_be32_t tpa; /**< Target IPv4 address. */
1037 };
1038
1039 /** Default mask for RTE_FLOW_ITEM_TYPE_ARP_ETH_IPV4. */
1040 #ifndef __cplusplus
1041 static const struct rte_flow_item_arp_eth_ipv4
1042 rte_flow_item_arp_eth_ipv4_mask = {
1043         .sha.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1044         .spa = RTE_BE32(0xffffffff),
1045         .tha.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1046         .tpa = RTE_BE32(0xffffffff),
1047 };
1048 #endif
1049
1050 /**
1051  * RTE_FLOW_ITEM_TYPE_IPV6_EXT
1052  *
1053  * Matches the presence of any IPv6 extension header.
1054  *
1055  * Normally preceded by any of:
1056  *
1057  * - RTE_FLOW_ITEM_TYPE_IPV6
1058  * - RTE_FLOW_ITEM_TYPE_IPV6_EXT
1059  */
1060 struct rte_flow_item_ipv6_ext {
1061         uint8_t next_hdr; /**< Next header. */
1062 };
1063
1064 /** Default mask for RTE_FLOW_ITEM_TYPE_IPV6_EXT. */
1065 #ifndef __cplusplus
1066 static const
1067 struct rte_flow_item_ipv6_ext rte_flow_item_ipv6_ext_mask = {
1068         .next_hdr = 0xff,
1069 };
1070 #endif
1071
1072 /**
1073  * RTE_FLOW_ITEM_TYPE_ICMP6
1074  *
1075  * Matches any ICMPv6 header.
1076  */
1077 struct rte_flow_item_icmp6 {
1078         uint8_t type; /**< ICMPv6 type. */
1079         uint8_t code; /**< ICMPv6 code. */
1080         uint16_t checksum; /**< ICMPv6 checksum. */
1081 };
1082
1083 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP6. */
1084 #ifndef __cplusplus
1085 static const struct rte_flow_item_icmp6 rte_flow_item_icmp6_mask = {
1086         .type = 0xff,
1087         .code = 0xff,
1088 };
1089 #endif
1090
1091 /**
1092  * RTE_FLOW_ITEM_TYPE_ICMP6_ND_NS
1093  *
1094  * Matches an ICMPv6 neighbor discovery solicitation.
1095  */
1096 struct rte_flow_item_icmp6_nd_ns {
1097         uint8_t type; /**< ICMPv6 type, normally 135. */
1098         uint8_t code; /**< ICMPv6 code, normally 0. */
1099         rte_be16_t checksum; /**< ICMPv6 checksum. */
1100         rte_be32_t reserved; /**< Reserved, normally 0. */
1101         uint8_t target_addr[16]; /**< Target address. */
1102 };
1103
1104 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP6_ND_NS. */
1105 #ifndef __cplusplus
1106 static const
1107 struct rte_flow_item_icmp6_nd_ns rte_flow_item_icmp6_nd_ns_mask = {
1108         .target_addr =
1109                 "\xff\xff\xff\xff\xff\xff\xff\xff"
1110                 "\xff\xff\xff\xff\xff\xff\xff\xff",
1111 };
1112 #endif
1113
1114 /**
1115  * RTE_FLOW_ITEM_TYPE_ICMP6_ND_NA
1116  *
1117  * Matches an ICMPv6 neighbor discovery advertisement.
1118  */
1119 struct rte_flow_item_icmp6_nd_na {
1120         uint8_t type; /**< ICMPv6 type, normally 136. */
1121         uint8_t code; /**< ICMPv6 code, normally 0. */
1122         rte_be16_t checksum; /**< ICMPv6 checksum. */
1123         /**
1124          * Route flag (1b), solicited flag (1b), override flag (1b),
1125          * reserved (29b).
1126          */
1127         rte_be32_t rso_reserved;
1128         uint8_t target_addr[16]; /**< Target address. */
1129 };
1130
1131 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP6_ND_NA. */
1132 #ifndef __cplusplus
1133 static const
1134 struct rte_flow_item_icmp6_nd_na rte_flow_item_icmp6_nd_na_mask = {
1135         .target_addr =
1136                 "\xff\xff\xff\xff\xff\xff\xff\xff"
1137                 "\xff\xff\xff\xff\xff\xff\xff\xff",
1138 };
1139 #endif
1140
1141 /**
1142  * RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT
1143  *
1144  * Matches the presence of any ICMPv6 neighbor discovery option.
1145  *
1146  * Normally preceded by any of:
1147  *
1148  * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_NA
1149  * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_NS
1150  * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT
1151  */
1152 struct rte_flow_item_icmp6_nd_opt {
1153         uint8_t type; /**< ND option type. */
1154         uint8_t length; /**< ND option length. */
1155 };
1156
1157 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT. */
1158 #ifndef __cplusplus
1159 static const struct rte_flow_item_icmp6_nd_opt
1160 rte_flow_item_icmp6_nd_opt_mask = {
1161         .type = 0xff,
1162 };
1163 #endif
1164
1165 /**
1166  * RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT_SLA_ETH
1167  *
1168  * Matches an ICMPv6 neighbor discovery source Ethernet link-layer address
1169  * option.
1170  *
1171  * Normally preceded by any of:
1172  *
1173  * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_NA
1174  * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT
1175  */
1176 struct rte_flow_item_icmp6_nd_opt_sla_eth {
1177         uint8_t type; /**< ND option type, normally 1. */
1178         uint8_t length; /**< ND option length, normally 1. */
1179         struct rte_ether_addr sla; /**< Source Ethernet LLA. */
1180 };
1181
1182 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT_SLA_ETH. */
1183 #ifndef __cplusplus
1184 static const struct rte_flow_item_icmp6_nd_opt_sla_eth
1185 rte_flow_item_icmp6_nd_opt_sla_eth_mask = {
1186         .sla.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1187 };
1188 #endif
1189
1190 /**
1191  * RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT_TLA_ETH
1192  *
1193  * Matches an ICMPv6 neighbor discovery target Ethernet link-layer address
1194  * option.
1195  *
1196  * Normally preceded by any of:
1197  *
1198  * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_NS
1199  * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT
1200  */
1201 struct rte_flow_item_icmp6_nd_opt_tla_eth {
1202         uint8_t type; /**< ND option type, normally 2. */
1203         uint8_t length; /**< ND option length, normally 1. */
1204         struct rte_ether_addr tla; /**< Target Ethernet LLA. */
1205 };
1206
1207 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT_TLA_ETH. */
1208 #ifndef __cplusplus
1209 static const struct rte_flow_item_icmp6_nd_opt_tla_eth
1210 rte_flow_item_icmp6_nd_opt_tla_eth_mask = {
1211         .tla.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1212 };
1213 #endif
1214
1215 /**
1216  * RTE_FLOW_ITEM_TYPE_META.
1217  *
1218  * Matches a specified metadata value.
1219  */
1220 struct rte_flow_item_meta {
1221         rte_be32_t data;
1222 };
1223
1224 /** Default mask for RTE_FLOW_ITEM_TYPE_META. */
1225 #ifndef __cplusplus
1226 static const struct rte_flow_item_meta rte_flow_item_meta_mask = {
1227         .data = RTE_BE32(UINT32_MAX),
1228 };
1229 #endif
1230
1231 /**
1232  * RTE_FLOW_ITEM_TYPE_GTP_PSC.
1233  *
1234  * Matches a GTP PDU extension header with type 0x85.
1235  */
1236 struct rte_flow_item_gtp_psc {
1237         uint8_t pdu_type; /**< PDU type. */
1238         uint8_t qfi; /**< QoS flow identifier. */
1239 };
1240
1241 /** Default mask for RTE_FLOW_ITEM_TYPE_GTP_PSC. */
1242 #ifndef __cplusplus
1243 static const struct rte_flow_item_gtp_psc
1244 rte_flow_item_gtp_psc_mask = {
1245         .qfi = 0x3f,
1246 };
1247 #endif
1248
1249 /**
1250  * RTE_FLOW_ITEM_TYPE_PPPOE.
1251  *
1252  * Matches a PPPoE header.
1253  */
1254 struct rte_flow_item_pppoe {
1255         /**
1256          * Version (4b), type (4b).
1257          */
1258         uint8_t version_type;
1259         uint8_t code; /**< Message type. */
1260         rte_be16_t session_id; /**< Session identifier. */
1261         rte_be16_t length; /**< Payload length. */
1262 };
1263
1264 /**
1265  * RTE_FLOW_ITEM_TYPE_PPPOE_PROTO_ID.
1266  *
1267  * Matches a PPPoE optional proto_id field.
1268  *
1269  * It only applies to PPPoE session packets.
1270  *
1271  * Normally preceded by any of:
1272  *
1273  * - RTE_FLOW_ITEM_TYPE_PPPOE
1274  * - RTE_FLOW_ITEM_TYPE_PPPOE_PROTO_ID
1275  */
1276 struct rte_flow_item_pppoe_proto_id {
1277         rte_be16_t proto_id; /**< PPP protocol identifier. */
1278 };
1279
1280 /** Default mask for RTE_FLOW_ITEM_TYPE_PPPOE_PROTO_ID. */
1281 #ifndef __cplusplus
1282 static const struct rte_flow_item_pppoe_proto_id
1283 rte_flow_item_pppoe_proto_id_mask = {
1284         .proto_id = RTE_BE16(0xffff),
1285 };
1286 #endif
1287
1288 /**
1289  * @warning
1290  * @b EXPERIMENTAL: this structure may change without prior notice
1291  *
1292  * RTE_FLOW_ITEM_TYPE_MARK
1293  *
1294  * Matches an arbitrary integer value which was set using the ``MARK`` action
1295  * in a previously matched rule.
1296  *
1297  * This item can only be specified once as a match criteria as the ``MARK``
1298  * action can only be specified once in a flow action.
1299  *
1300  * This value is arbitrary and application-defined. Maximum allowed value
1301  * depends on the underlying implementation.
1302  *
1303  * Depending on the underlying implementation the MARK item may be supported on
1304  * the physical device, with virtual groups in the PMD or not at all.
1305  */
1306 struct rte_flow_item_mark {
1307         uint32_t id; /**< Integer value to match against. */
1308 };
1309
1310 /**
1311  * Matching pattern item definition.
1312  *
1313  * A pattern is formed by stacking items starting from the lowest protocol
1314  * layer to match. This stacking restriction does not apply to meta items
1315  * which can be placed anywhere in the stack without affecting the meaning
1316  * of the resulting pattern.
1317  *
1318  * Patterns are terminated by END items.
1319  *
1320  * The spec field should be a valid pointer to a structure of the related
1321  * item type. It may remain unspecified (NULL) in many cases to request
1322  * broad (nonspecific) matching. In such cases, last and mask must also be
1323  * set to NULL.
1324  *
1325  * Optionally, last can point to a structure of the same type to define an
1326  * inclusive range. This is mostly supported by integer and address fields,
1327  * may cause errors otherwise. Fields that do not support ranges must be set
1328  * to 0 or to the same value as the corresponding fields in spec.
1329  *
1330  * Only the fields defined to nonzero values in the default masks (see
1331  * rte_flow_item_{name}_mask constants) are considered relevant by
1332  * default. This can be overridden by providing a mask structure of the
1333  * same type with applicable bits set to one. It can also be used to
1334  * partially filter out specific fields (e.g. as an alternate mean to match
1335  * ranges of IP addresses).
1336  *
1337  * Mask is a simple bit-mask applied before interpreting the contents of
1338  * spec and last, which may yield unexpected results if not used
1339  * carefully. For example, if for an IPv4 address field, spec provides
1340  * 10.1.2.3, last provides 10.3.4.5 and mask provides 255.255.0.0, the
1341  * effective range becomes 10.1.0.0 to 10.3.255.255.
1342  */
1343 struct rte_flow_item {
1344         enum rte_flow_item_type type; /**< Item type. */
1345         const void *spec; /**< Pointer to item specification structure. */
1346         const void *last; /**< Defines an inclusive range (spec to last). */
1347         const void *mask; /**< Bit-mask applied to spec and last. */
1348 };
1349
1350 /**
1351  * Action types.
1352  *
1353  * Each possible action is represented by a type.
1354  * An action can have an associated configuration object.
1355  * Several actions combined in a list can be assigned
1356  * to a flow rule and are performed in order.
1357  *
1358  * They fall in three categories:
1359  *
1360  * - Actions that modify the fate of matching traffic, for instance by
1361  *   dropping or assigning it a specific destination.
1362  *
1363  * - Actions that modify matching traffic contents or its properties. This
1364  *   includes adding/removing encapsulation, encryption, compression and
1365  *   marks.
1366  *
1367  * - Actions related to the flow rule itself, such as updating counters or
1368  *   making it non-terminating.
1369  *
1370  * Flow rules being terminating by default, not specifying any action of the
1371  * fate kind results in undefined behavior. This applies to both ingress and
1372  * egress.
1373  *
1374  * PASSTHRU, when supported, makes a flow rule non-terminating.
1375  */
1376 enum rte_flow_action_type {
1377         /**
1378          * End marker for action lists. Prevents further processing of
1379          * actions, thereby ending the list.
1380          *
1381          * No associated configuration structure.
1382          */
1383         RTE_FLOW_ACTION_TYPE_END,
1384
1385         /**
1386          * Used as a placeholder for convenience. It is ignored and simply
1387          * discarded by PMDs.
1388          *
1389          * No associated configuration structure.
1390          */
1391         RTE_FLOW_ACTION_TYPE_VOID,
1392
1393         /**
1394          * Leaves traffic up for additional processing by subsequent flow
1395          * rules; makes a flow rule non-terminating.
1396          *
1397          * No associated configuration structure.
1398          */
1399         RTE_FLOW_ACTION_TYPE_PASSTHRU,
1400
1401         /**
1402          * RTE_FLOW_ACTION_TYPE_JUMP
1403          *
1404          * Redirects packets to a group on the current device.
1405          *
1406          * See struct rte_flow_action_jump.
1407          */
1408         RTE_FLOW_ACTION_TYPE_JUMP,
1409
1410         /**
1411          * Attaches an integer value to packets and sets PKT_RX_FDIR and
1412          * PKT_RX_FDIR_ID mbuf flags.
1413          *
1414          * See struct rte_flow_action_mark.
1415          */
1416         RTE_FLOW_ACTION_TYPE_MARK,
1417
1418         /**
1419          * Flags packets. Similar to MARK without a specific value; only
1420          * sets the PKT_RX_FDIR mbuf flag.
1421          *
1422          * No associated configuration structure.
1423          */
1424         RTE_FLOW_ACTION_TYPE_FLAG,
1425
1426         /**
1427          * Assigns packets to a given queue index.
1428          *
1429          * See struct rte_flow_action_queue.
1430          */
1431         RTE_FLOW_ACTION_TYPE_QUEUE,
1432
1433         /**
1434          * Drops packets.
1435          *
1436          * PASSTHRU overrides this action if both are specified.
1437          *
1438          * No associated configuration structure.
1439          */
1440         RTE_FLOW_ACTION_TYPE_DROP,
1441
1442         /**
1443          * Enables counters for this flow rule.
1444          *
1445          * These counters can be retrieved and reset through rte_flow_query(),
1446          * see struct rte_flow_query_count.
1447          *
1448          * See struct rte_flow_action_count.
1449          */
1450         RTE_FLOW_ACTION_TYPE_COUNT,
1451
1452         /**
1453          * Similar to QUEUE, except RSS is additionally performed on packets
1454          * to spread them among several queues according to the provided
1455          * parameters.
1456          *
1457          * See struct rte_flow_action_rss.
1458          */
1459         RTE_FLOW_ACTION_TYPE_RSS,
1460
1461         /**
1462          * Directs matching traffic to the physical function (PF) of the
1463          * current device.
1464          *
1465          * No associated configuration structure.
1466          */
1467         RTE_FLOW_ACTION_TYPE_PF,
1468
1469         /**
1470          * Directs matching traffic to a given virtual function of the
1471          * current device.
1472          *
1473          * See struct rte_flow_action_vf.
1474          */
1475         RTE_FLOW_ACTION_TYPE_VF,
1476
1477         /**
1478          * Directs packets to a given physical port index of the underlying
1479          * device.
1480          *
1481          * See struct rte_flow_action_phy_port.
1482          */
1483         RTE_FLOW_ACTION_TYPE_PHY_PORT,
1484
1485         /**
1486          * Directs matching traffic to a given DPDK port ID.
1487          *
1488          * See struct rte_flow_action_port_id.
1489          */
1490         RTE_FLOW_ACTION_TYPE_PORT_ID,
1491
1492         /**
1493          * Traffic metering and policing (MTR).
1494          *
1495          * See struct rte_flow_action_meter.
1496          * See file rte_mtr.h for MTR object configuration.
1497          */
1498         RTE_FLOW_ACTION_TYPE_METER,
1499
1500         /**
1501          * Redirects packets to security engine of current device for security
1502          * processing as specified by security session.
1503          *
1504          * See struct rte_flow_action_security.
1505          */
1506         RTE_FLOW_ACTION_TYPE_SECURITY,
1507
1508         /**
1509          * Implements OFPAT_SET_MPLS_TTL ("MPLS TTL") as defined by the
1510          * OpenFlow Switch Specification.
1511          *
1512          * See struct rte_flow_action_of_set_mpls_ttl.
1513          */
1514         RTE_FLOW_ACTION_TYPE_OF_SET_MPLS_TTL,
1515
1516         /**
1517          * Implements OFPAT_DEC_MPLS_TTL ("decrement MPLS TTL") as defined
1518          * by the OpenFlow Switch Specification.
1519          *
1520          * No associated configuration structure.
1521          */
1522         RTE_FLOW_ACTION_TYPE_OF_DEC_MPLS_TTL,
1523
1524         /**
1525          * Implements OFPAT_SET_NW_TTL ("IP TTL") as defined by the OpenFlow
1526          * Switch Specification.
1527          *
1528          * See struct rte_flow_action_of_set_nw_ttl.
1529          */
1530         RTE_FLOW_ACTION_TYPE_OF_SET_NW_TTL,
1531
1532         /**
1533          * Implements OFPAT_DEC_NW_TTL ("decrement IP TTL") as defined by
1534          * the OpenFlow Switch Specification.
1535          *
1536          * No associated configuration structure.
1537          */
1538         RTE_FLOW_ACTION_TYPE_OF_DEC_NW_TTL,
1539
1540         /**
1541          * Implements OFPAT_COPY_TTL_OUT ("copy TTL "outwards" -- from
1542          * next-to-outermost to outermost") as defined by the OpenFlow
1543          * Switch Specification.
1544          *
1545          * No associated configuration structure.
1546          */
1547         RTE_FLOW_ACTION_TYPE_OF_COPY_TTL_OUT,
1548
1549         /**
1550          * Implements OFPAT_COPY_TTL_IN ("copy TTL "inwards" -- from
1551          * outermost to next-to-outermost") as defined by the OpenFlow
1552          * Switch Specification.
1553          *
1554          * No associated configuration structure.
1555          */
1556         RTE_FLOW_ACTION_TYPE_OF_COPY_TTL_IN,
1557
1558         /**
1559          * Implements OFPAT_POP_VLAN ("pop the outer VLAN tag") as defined
1560          * by the OpenFlow Switch Specification.
1561          *
1562          * No associated configuration structure.
1563          */
1564         RTE_FLOW_ACTION_TYPE_OF_POP_VLAN,
1565
1566         /**
1567          * Implements OFPAT_PUSH_VLAN ("push a new VLAN tag") as defined by
1568          * the OpenFlow Switch Specification.
1569          *
1570          * See struct rte_flow_action_of_push_vlan.
1571          */
1572         RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN,
1573
1574         /**
1575          * Implements OFPAT_SET_VLAN_VID ("set the 802.1q VLAN id") as
1576          * defined by the OpenFlow Switch Specification.
1577          *
1578          * See struct rte_flow_action_of_set_vlan_vid.
1579          */
1580         RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID,
1581
1582         /**
1583          * Implements OFPAT_SET_LAN_PCP ("set the 802.1q priority") as
1584          * defined by the OpenFlow Switch Specification.
1585          *
1586          * See struct rte_flow_action_of_set_vlan_pcp.
1587          */
1588         RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP,
1589
1590         /**
1591          * Implements OFPAT_POP_MPLS ("pop the outer MPLS tag") as defined
1592          * by the OpenFlow Switch Specification.
1593          *
1594          * See struct rte_flow_action_of_pop_mpls.
1595          */
1596         RTE_FLOW_ACTION_TYPE_OF_POP_MPLS,
1597
1598         /**
1599          * Implements OFPAT_PUSH_MPLS ("push a new MPLS tag") as defined by
1600          * the OpenFlow Switch Specification.
1601          *
1602          * See struct rte_flow_action_of_push_mpls.
1603          */
1604         RTE_FLOW_ACTION_TYPE_OF_PUSH_MPLS,
1605
1606         /**
1607          * Encapsulate flow in VXLAN tunnel as defined in
1608          * rte_flow_action_vxlan_encap action structure.
1609          *
1610          * See struct rte_flow_action_vxlan_encap.
1611          */
1612         RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP,
1613
1614         /**
1615          * Decapsulate outer most VXLAN tunnel from matched flow.
1616          *
1617          * If flow pattern does not define a valid VXLAN tunnel (as specified by
1618          * RFC7348) then the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION
1619          * error.
1620          */
1621         RTE_FLOW_ACTION_TYPE_VXLAN_DECAP,
1622
1623         /**
1624          * Encapsulate flow in NVGRE tunnel defined in the
1625          * rte_flow_action_nvgre_encap action structure.
1626          *
1627          * See struct rte_flow_action_nvgre_encap.
1628          */
1629         RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP,
1630
1631         /**
1632          * Decapsulate outer most NVGRE tunnel from matched flow.
1633          *
1634          * If flow pattern does not define a valid NVGRE tunnel (as specified by
1635          * RFC7637) then the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION
1636          * error.
1637          */
1638         RTE_FLOW_ACTION_TYPE_NVGRE_DECAP,
1639
1640         /**
1641          * Add outer header whose template is provided in its data buffer
1642          *
1643          * See struct rte_flow_action_raw_encap.
1644          */
1645         RTE_FLOW_ACTION_TYPE_RAW_ENCAP,
1646
1647         /**
1648          * Remove outer header whose template is provided in its data buffer.
1649          *
1650          * See struct rte_flow_action_raw_decap
1651          */
1652         RTE_FLOW_ACTION_TYPE_RAW_DECAP,
1653
1654         /**
1655          * Modify IPv4 source address in the outermost IPv4 header.
1656          *
1657          * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_IPV4,
1658          * then the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION error.
1659          *
1660          * See struct rte_flow_action_set_ipv4.
1661          */
1662         RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC,
1663
1664         /**
1665          * Modify IPv4 destination address in the outermost IPv4 header.
1666          *
1667          * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_IPV4,
1668          * then the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION error.
1669          *
1670          * See struct rte_flow_action_set_ipv4.
1671          */
1672         RTE_FLOW_ACTION_TYPE_SET_IPV4_DST,
1673
1674         /**
1675          * Modify IPv6 source address in the outermost IPv6 header.
1676          *
1677          * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_IPV6,
1678          * then the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION error.
1679          *
1680          * See struct rte_flow_action_set_ipv6.
1681          */
1682         RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC,
1683
1684         /**
1685          * Modify IPv6 destination address in the outermost IPv6 header.
1686          *
1687          * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_IPV6,
1688          * then the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION error.
1689          *
1690          * See struct rte_flow_action_set_ipv6.
1691          */
1692         RTE_FLOW_ACTION_TYPE_SET_IPV6_DST,
1693
1694         /**
1695          * Modify source port number in the outermost TCP/UDP header.
1696          *
1697          * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_TCP
1698          * or RTE_FLOW_ITEM_TYPE_UDP, then the PMD should return a
1699          * RTE_FLOW_ERROR_TYPE_ACTION error.
1700          *
1701          * See struct rte_flow_action_set_tp.
1702          */
1703         RTE_FLOW_ACTION_TYPE_SET_TP_SRC,
1704
1705         /**
1706          * Modify destination port number in the outermost TCP/UDP header.
1707          *
1708          * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_TCP
1709          * or RTE_FLOW_ITEM_TYPE_UDP, then the PMD should return a
1710          * RTE_FLOW_ERROR_TYPE_ACTION error.
1711          *
1712          * See struct rte_flow_action_set_tp.
1713          */
1714         RTE_FLOW_ACTION_TYPE_SET_TP_DST,
1715
1716         /**
1717          * Swap the source and destination MAC addresses in the outermost
1718          * Ethernet header.
1719          *
1720          * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_ETH,
1721          * then the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION error.
1722          *
1723          * No associated configuration structure.
1724          */
1725         RTE_FLOW_ACTION_TYPE_MAC_SWAP,
1726
1727         /**
1728          * Decrease TTL value directly
1729          *
1730          * No associated configuration structure.
1731          */
1732         RTE_FLOW_ACTION_TYPE_DEC_TTL,
1733
1734         /**
1735          * Set TTL value
1736          *
1737          * See struct rte_flow_action_set_ttl
1738          */
1739         RTE_FLOW_ACTION_TYPE_SET_TTL,
1740
1741         /**
1742          * Set source MAC address from matched flow.
1743          *
1744          * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_ETH,
1745          * the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION error.
1746          *
1747          * See struct rte_flow_action_set_mac.
1748          */
1749         RTE_FLOW_ACTION_TYPE_SET_MAC_SRC,
1750
1751         /**
1752          * Set destination MAC address from matched flow.
1753          *
1754          * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_ETH,
1755          * the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION error.
1756          *
1757          * See struct rte_flow_action_set_mac.
1758          */
1759         RTE_FLOW_ACTION_TYPE_SET_MAC_DST,
1760
1761         /**
1762          * Increase sequence number in the outermost TCP header.
1763          *
1764          * Action configuration specifies the value to increase
1765          * TCP sequence number as a big-endian 32 bit integer.
1766          *
1767          * @p conf type:
1768          * @code rte_be32_t * @endcode
1769          *
1770          * Using this action on non-matching traffic will result in
1771          * undefined behavior.
1772          */
1773         RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ,
1774
1775         /**
1776          * Decrease sequence number in the outermost TCP header.
1777          *
1778          * Action configuration specifies the value to decrease
1779          * TCP sequence number as a big-endian 32 bit integer.
1780          *
1781          * @p conf type:
1782          * @code rte_be32_t * @endcode
1783          *
1784          * Using this action on non-matching traffic will result in
1785          * undefined behavior.
1786          */
1787         RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ,
1788
1789         /**
1790          * Increase acknowledgment number in the outermost TCP header.
1791          *
1792          * Action configuration specifies the value to increase
1793          * TCP acknowledgment number as a big-endian 32 bit integer.
1794          *
1795          * @p conf type:
1796          * @code rte_be32_t * @endcode
1797
1798          * Using this action on non-matching traffic will result in
1799          * undefined behavior.
1800          */
1801         RTE_FLOW_ACTION_TYPE_INC_TCP_ACK,
1802
1803         /**
1804          * Decrease acknowledgment number in the outermost TCP header.
1805          *
1806          * Action configuration specifies the value to decrease
1807          * TCP acknowledgment number as a big-endian 32 bit integer.
1808          *
1809          * @p conf type:
1810          * @code rte_be32_t * @endcode
1811          *
1812          * Using this action on non-matching traffic will result in
1813          * undefined behavior.
1814          */
1815         RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK,
1816 };
1817
1818 /**
1819  * RTE_FLOW_ACTION_TYPE_MARK
1820  *
1821  * Attaches an integer value to packets and sets PKT_RX_FDIR and
1822  * PKT_RX_FDIR_ID mbuf flags.
1823  *
1824  * This value is arbitrary and application-defined. Maximum allowed value
1825  * depends on the underlying implementation. It is returned in the
1826  * hash.fdir.hi mbuf field.
1827  */
1828 struct rte_flow_action_mark {
1829         uint32_t id; /**< Integer value to return with packets. */
1830 };
1831
1832 /**
1833  * @warning
1834  * @b EXPERIMENTAL: this structure may change without prior notice
1835  *
1836  * RTE_FLOW_ACTION_TYPE_JUMP
1837  *
1838  * Redirects packets to a group on the current device.
1839  *
1840  * In a hierarchy of groups, which can be used to represent physical or logical
1841  * flow tables on the device, this action allows the action to be a redirect to
1842  * a group on that device.
1843  */
1844 struct rte_flow_action_jump {
1845         uint32_t group;
1846 };
1847
1848 /**
1849  * RTE_FLOW_ACTION_TYPE_QUEUE
1850  *
1851  * Assign packets to a given queue index.
1852  */
1853 struct rte_flow_action_queue {
1854         uint16_t index; /**< Queue index to use. */
1855 };
1856
1857
1858 /**
1859  * @warning
1860  * @b EXPERIMENTAL: this structure may change without prior notice
1861  *
1862  * RTE_FLOW_ACTION_TYPE_COUNT
1863  *
1864  * Adds a counter action to a matched flow.
1865  *
1866  * If more than one count action is specified in a single flow rule, then each
1867  * action must specify a unique id.
1868  *
1869  * Counters can be retrieved and reset through ``rte_flow_query()``, see
1870  * ``struct rte_flow_query_count``.
1871  *
1872  * The shared flag indicates whether the counter is unique to the flow rule the
1873  * action is specified with, or whether it is a shared counter.
1874  *
1875  * For a count action with the shared flag set, then then a global device
1876  * namespace is assumed for the counter id, so that any matched flow rules using
1877  * a count action with the same counter id on the same port will contribute to
1878  * that counter.
1879  *
1880  * For ports within the same switch domain then the counter id namespace extends
1881  * to all ports within that switch domain.
1882  */
1883 struct rte_flow_action_count {
1884         uint32_t shared:1; /**< Share counter ID with other flow rules. */
1885         uint32_t reserved:31; /**< Reserved, must be zero. */
1886         uint32_t id; /**< Counter ID. */
1887 };
1888
1889 /**
1890  * RTE_FLOW_ACTION_TYPE_COUNT (query)
1891  *
1892  * Query structure to retrieve and reset flow rule counters.
1893  */
1894 struct rte_flow_query_count {
1895         uint32_t reset:1; /**< Reset counters after query [in]. */
1896         uint32_t hits_set:1; /**< hits field is set [out]. */
1897         uint32_t bytes_set:1; /**< bytes field is set [out]. */
1898         uint32_t reserved:29; /**< Reserved, must be zero [in, out]. */
1899         uint64_t hits; /**< Number of hits for this rule [out]. */
1900         uint64_t bytes; /**< Number of bytes through this rule [out]. */
1901 };
1902
1903 /**
1904  * Hash function types.
1905  */
1906 enum rte_eth_hash_function {
1907         RTE_ETH_HASH_FUNCTION_DEFAULT = 0,
1908         RTE_ETH_HASH_FUNCTION_TOEPLITZ, /**< Toeplitz */
1909         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR, /**< Simple XOR */
1910         RTE_ETH_HASH_FUNCTION_MAX,
1911 };
1912
1913 /**
1914  * RTE_FLOW_ACTION_TYPE_RSS
1915  *
1916  * Similar to QUEUE, except RSS is additionally performed on packets to
1917  * spread them among several queues according to the provided parameters.
1918  *
1919  * Unlike global RSS settings used by other DPDK APIs, unsetting the
1920  * @p types field does not disable RSS in a flow rule. Doing so instead
1921  * requests safe unspecified "best-effort" settings from the underlying PMD,
1922  * which depending on the flow rule, may result in anything ranging from
1923  * empty (single queue) to all-inclusive RSS.
1924  *
1925  * Note: RSS hash result is stored in the hash.rss mbuf field which overlaps
1926  * hash.fdir.lo. Since the MARK action sets the hash.fdir.hi field only,
1927  * both can be requested simultaneously.
1928  */
1929 struct rte_flow_action_rss {
1930         enum rte_eth_hash_function func; /**< RSS hash function to apply. */
1931         /**
1932          * Packet encapsulation level RSS hash @p types apply to.
1933          *
1934          * - @p 0 requests the default behavior. Depending on the packet
1935          *   type, it can mean outermost, innermost, anything in between or
1936          *   even no RSS.
1937          *
1938          *   It basically stands for the innermost encapsulation level RSS
1939          *   can be performed on according to PMD and device capabilities.
1940          *
1941          * - @p 1 requests RSS to be performed on the outermost packet
1942          *   encapsulation level.
1943          *
1944          * - @p 2 and subsequent values request RSS to be performed on the
1945          *   specified inner packet encapsulation level, from outermost to
1946          *   innermost (lower to higher values).
1947          *
1948          * Values other than @p 0 are not necessarily supported.
1949          *
1950          * Requesting a specific RSS level on unrecognized traffic results
1951          * in undefined behavior. For predictable results, it is recommended
1952          * to make the flow rule pattern match packet headers up to the
1953          * requested encapsulation level so that only matching traffic goes
1954          * through.
1955          */
1956         uint32_t level;
1957         uint64_t types; /**< Specific RSS hash types (see ETH_RSS_*). */
1958         uint32_t key_len; /**< Hash key length in bytes. */
1959         uint32_t queue_num; /**< Number of entries in @p queue. */
1960         const uint8_t *key; /**< Hash key. */
1961         const uint16_t *queue; /**< Queue indices to use. */
1962 };
1963
1964 /**
1965  * RTE_FLOW_ACTION_TYPE_VF
1966  *
1967  * Directs matching traffic to a given virtual function of the current
1968  * device.
1969  *
1970  * Packets matched by a VF pattern item can be redirected to their original
1971  * VF ID instead of the specified one. This parameter may not be available
1972  * and is not guaranteed to work properly if the VF part is matched by a
1973  * prior flow rule or if packets are not addressed to a VF in the first
1974  * place.
1975  */
1976 struct rte_flow_action_vf {
1977         uint32_t original:1; /**< Use original VF ID if possible. */
1978         uint32_t reserved:31; /**< Reserved, must be zero. */
1979         uint32_t id; /**< VF ID. */
1980 };
1981
1982 /**
1983  * RTE_FLOW_ACTION_TYPE_PHY_PORT
1984  *
1985  * Directs packets to a given physical port index of the underlying
1986  * device.
1987  *
1988  * @see RTE_FLOW_ITEM_TYPE_PHY_PORT
1989  */
1990 struct rte_flow_action_phy_port {
1991         uint32_t original:1; /**< Use original port index if possible. */
1992         uint32_t reserved:31; /**< Reserved, must be zero. */
1993         uint32_t index; /**< Physical port index. */
1994 };
1995
1996 /**
1997  * RTE_FLOW_ACTION_TYPE_PORT_ID
1998  *
1999  * Directs matching traffic to a given DPDK port ID.
2000  *
2001  * @see RTE_FLOW_ITEM_TYPE_PORT_ID
2002  */
2003 struct rte_flow_action_port_id {
2004         uint32_t original:1; /**< Use original DPDK port ID if possible. */
2005         uint32_t reserved:31; /**< Reserved, must be zero. */
2006         uint32_t id; /**< DPDK port ID. */
2007 };
2008
2009 /**
2010  * RTE_FLOW_ACTION_TYPE_METER
2011  *
2012  * Traffic metering and policing (MTR).
2013  *
2014  * Packets matched by items of this type can be either dropped or passed to the
2015  * next item with their color set by the MTR object.
2016  */
2017 struct rte_flow_action_meter {
2018         uint32_t mtr_id; /**< MTR object ID created with rte_mtr_create(). */
2019 };
2020
2021 /**
2022  * RTE_FLOW_ACTION_TYPE_SECURITY
2023  *
2024  * Perform the security action on flows matched by the pattern items
2025  * according to the configuration of the security session.
2026  *
2027  * This action modifies the payload of matched flows. For INLINE_CRYPTO, the
2028  * security protocol headers and IV are fully provided by the application as
2029  * specified in the flow pattern. The payload of matching packets is
2030  * encrypted on egress, and decrypted and authenticated on ingress.
2031  * For INLINE_PROTOCOL, the security protocol is fully offloaded to HW,
2032  * providing full encapsulation and decapsulation of packets in security
2033  * protocols. The flow pattern specifies both the outer security header fields
2034  * and the inner packet fields. The security session specified in the action
2035  * must match the pattern parameters.
2036  *
2037  * The security session specified in the action must be created on the same
2038  * port as the flow action that is being specified.
2039  *
2040  * The ingress/egress flow attribute should match that specified in the
2041  * security session if the security session supports the definition of the
2042  * direction.
2043  *
2044  * Multiple flows can be configured to use the same security session.
2045  */
2046 struct rte_flow_action_security {
2047         void *security_session; /**< Pointer to security session structure. */
2048 };
2049
2050 /**
2051  * RTE_FLOW_ACTION_TYPE_OF_SET_MPLS_TTL
2052  *
2053  * Implements OFPAT_SET_MPLS_TTL ("MPLS TTL") as defined by the OpenFlow
2054  * Switch Specification.
2055  */
2056 struct rte_flow_action_of_set_mpls_ttl {
2057         uint8_t mpls_ttl; /**< MPLS TTL. */
2058 };
2059
2060 /**
2061  * RTE_FLOW_ACTION_TYPE_OF_SET_NW_TTL
2062  *
2063  * Implements OFPAT_SET_NW_TTL ("IP TTL") as defined by the OpenFlow Switch
2064  * Specification.
2065  */
2066 struct rte_flow_action_of_set_nw_ttl {
2067         uint8_t nw_ttl; /**< IP TTL. */
2068 };
2069
2070 /**
2071  * RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN
2072  *
2073  * Implements OFPAT_PUSH_VLAN ("push a new VLAN tag") as defined by the
2074  * OpenFlow Switch Specification.
2075  */
2076 struct rte_flow_action_of_push_vlan {
2077         rte_be16_t ethertype; /**< EtherType. */
2078 };
2079
2080 /**
2081  * RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID
2082  *
2083  * Implements OFPAT_SET_VLAN_VID ("set the 802.1q VLAN id") as defined by
2084  * the OpenFlow Switch Specification.
2085  */
2086 struct rte_flow_action_of_set_vlan_vid {
2087         rte_be16_t vlan_vid; /**< VLAN id. */
2088 };
2089
2090 /**
2091  * RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP
2092  *
2093  * Implements OFPAT_SET_LAN_PCP ("set the 802.1q priority") as defined by
2094  * the OpenFlow Switch Specification.
2095  */
2096 struct rte_flow_action_of_set_vlan_pcp {
2097         uint8_t vlan_pcp; /**< VLAN priority. */
2098 };
2099
2100 /**
2101  * RTE_FLOW_ACTION_TYPE_OF_POP_MPLS
2102  *
2103  * Implements OFPAT_POP_MPLS ("pop the outer MPLS tag") as defined by the
2104  * OpenFlow Switch Specification.
2105  */
2106 struct rte_flow_action_of_pop_mpls {
2107         rte_be16_t ethertype; /**< EtherType. */
2108 };
2109
2110 /**
2111  * RTE_FLOW_ACTION_TYPE_OF_PUSH_MPLS
2112  *
2113  * Implements OFPAT_PUSH_MPLS ("push a new MPLS tag") as defined by the
2114  * OpenFlow Switch Specification.
2115  */
2116 struct rte_flow_action_of_push_mpls {
2117         rte_be16_t ethertype; /**< EtherType. */
2118 };
2119
2120 /**
2121  * @warning
2122  * @b EXPERIMENTAL: this structure may change without prior notice
2123  *
2124  * RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP
2125  *
2126  * VXLAN tunnel end-point encapsulation data definition
2127  *
2128  * The tunnel definition is provided through the flow item pattern, the
2129  * provided pattern must conform to RFC7348 for the tunnel specified. The flow
2130  * definition must be provided in order from the RTE_FLOW_ITEM_TYPE_ETH
2131  * definition up the end item which is specified by RTE_FLOW_ITEM_TYPE_END.
2132  *
2133  * The mask field allows user to specify which fields in the flow item
2134  * definitions can be ignored and which have valid data and can be used
2135  * verbatim.
2136  *
2137  * Note: the last field is not used in the definition of a tunnel and can be
2138  * ignored.
2139  *
2140  * Valid flow definition for RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP include:
2141  *
2142  * - ETH / IPV4 / UDP / VXLAN / END
2143  * - ETH / IPV6 / UDP / VXLAN / END
2144  * - ETH / VLAN / IPV4 / UDP / VXLAN / END
2145  *
2146  */
2147 struct rte_flow_action_vxlan_encap {
2148         /**
2149          * Encapsulating vxlan tunnel definition
2150          * (terminated by the END pattern item).
2151          */
2152         struct rte_flow_item *definition;
2153 };
2154
2155 /**
2156  * @warning
2157  * @b EXPERIMENTAL: this structure may change without prior notice
2158  *
2159  * RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP
2160  *
2161  * NVGRE tunnel end-point encapsulation data definition
2162  *
2163  * The tunnel definition is provided through the flow item pattern  the
2164  * provided pattern must conform with RFC7637. The flow definition must be
2165  * provided in order from the RTE_FLOW_ITEM_TYPE_ETH definition up the end item
2166  * which is specified by RTE_FLOW_ITEM_TYPE_END.
2167  *
2168  * The mask field allows user to specify which fields in the flow item
2169  * definitions can be ignored and which have valid data and can be used
2170  * verbatim.
2171  *
2172  * Note: the last field is not used in the definition of a tunnel and can be
2173  * ignored.
2174  *
2175  * Valid flow definition for RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP include:
2176  *
2177  * - ETH / IPV4 / NVGRE / END
2178  * - ETH / VLAN / IPV6 / NVGRE / END
2179  *
2180  */
2181 struct rte_flow_action_nvgre_encap {
2182         /**
2183          * Encapsulating vxlan tunnel definition
2184          * (terminated by the END pattern item).
2185          */
2186         struct rte_flow_item *definition;
2187 };
2188
2189 /**
2190  * @warning
2191  * @b EXPERIMENTAL: this structure may change without prior notice
2192  *
2193  * RTE_FLOW_ACTION_TYPE_RAW_ENCAP
2194  *
2195  * Raw tunnel end-point encapsulation data definition.
2196  *
2197  * The data holds the headers definitions to be applied on the packet.
2198  * The data must start with ETH header up to the tunnel item header itself.
2199  * When used right after RAW_DECAP (for decapsulating L3 tunnel type for
2200  * example MPLSoGRE) the data will just hold layer 2 header.
2201  *
2202  * The preserve parameter holds which bits in the packet the PMD is not allowed
2203  * to change, this parameter can also be NULL and then the PMD is allowed
2204  * to update any field.
2205  *
2206  * size holds the number of bytes in @p data and @p preserve.
2207  */
2208 struct rte_flow_action_raw_encap {
2209         uint8_t *data; /**< Encapsulation data. */
2210         uint8_t *preserve; /**< Bit-mask of @p data to preserve on output. */
2211         size_t size; /**< Size of @p data and @p preserve. */
2212 };
2213
2214 /**
2215  * @warning
2216  * @b EXPERIMENTAL: this structure may change without prior notice
2217  *
2218  * RTE_FLOW_ACTION_TYPE_RAW_DECAP
2219  *
2220  * Raw tunnel end-point decapsulation data definition.
2221  *
2222  * The data holds the headers definitions to be removed from the packet.
2223  * The data must start with ETH header up to the tunnel item header itself.
2224  * When used right before RAW_DECAP (for encapsulating L3 tunnel type for
2225  * example MPLSoGRE) the data will just hold layer 2 header.
2226  *
2227  * size holds the number of bytes in @p data.
2228  */
2229 struct rte_flow_action_raw_decap {
2230         uint8_t *data; /**< Encapsulation data. */
2231         size_t size; /**< Size of @p data and @p preserve. */
2232 };
2233
2234 /**
2235  * @warning
2236  * @b EXPERIMENTAL: this structure may change without prior notice
2237  *
2238  * RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC
2239  * RTE_FLOW_ACTION_TYPE_SET_IPV4_DST
2240  *
2241  * Allows modification of IPv4 source (RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC)
2242  * and destination address (RTE_FLOW_ACTION_TYPE_SET_IPV4_DST) in the
2243  * specified outermost IPv4 header.
2244  */
2245 struct rte_flow_action_set_ipv4 {
2246         rte_be32_t ipv4_addr;
2247 };
2248
2249 /**
2250  * @warning
2251  * @b EXPERIMENTAL: this structure may change without prior notice
2252  *
2253  * RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC
2254  * RTE_FLOW_ACTION_TYPE_SET_IPV6_DST
2255  *
2256  * Allows modification of IPv6 source (RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC)
2257  * and destination address (RTE_FLOW_ACTION_TYPE_SET_IPV6_DST) in the
2258  * specified outermost IPv6 header.
2259  */
2260 struct rte_flow_action_set_ipv6 {
2261         uint8_t ipv6_addr[16];
2262 };
2263
2264 /**
2265  * @warning
2266  * @b EXPERIMENTAL: this structure may change without prior notice
2267  *
2268  * RTE_FLOW_ACTION_TYPE_SET_TP_SRC
2269  * RTE_FLOW_ACTION_TYPE_SET_TP_DST
2270  *
2271  * Allows modification of source (RTE_FLOW_ACTION_TYPE_SET_TP_SRC)
2272  * and destination (RTE_FLOW_ACTION_TYPE_SET_TP_DST) port numbers
2273  * in the specified outermost TCP/UDP header.
2274  */
2275 struct rte_flow_action_set_tp {
2276         rte_be16_t port;
2277 };
2278
2279 /**
2280  * RTE_FLOW_ACTION_TYPE_SET_TTL
2281  *
2282  * Set the TTL value directly for IPv4 or IPv6
2283  */
2284 struct rte_flow_action_set_ttl {
2285         uint8_t ttl_value;
2286 };
2287
2288 /**
2289  * RTE_FLOW_ACTION_TYPE_SET_MAC
2290  *
2291  * Set MAC address from the matched flow
2292  */
2293 struct rte_flow_action_set_mac {
2294         uint8_t mac_addr[RTE_ETHER_ADDR_LEN];
2295 };
2296
2297 /*
2298  * Definition of a single action.
2299  *
2300  * A list of actions is terminated by a END action.
2301  *
2302  * For simple actions without a configuration object, conf remains NULL.
2303  */
2304 struct rte_flow_action {
2305         enum rte_flow_action_type type; /**< Action type. */
2306         const void *conf; /**< Pointer to action configuration object. */
2307 };
2308
2309 /**
2310  * Opaque type returned after successfully creating a flow.
2311  *
2312  * This handle can be used to manage and query the related flow (e.g. to
2313  * destroy it or retrieve counters).
2314  */
2315 struct rte_flow;
2316
2317 /**
2318  * Verbose error types.
2319  *
2320  * Most of them provide the type of the object referenced by struct
2321  * rte_flow_error.cause.
2322  */
2323 enum rte_flow_error_type {
2324         RTE_FLOW_ERROR_TYPE_NONE, /**< No error. */
2325         RTE_FLOW_ERROR_TYPE_UNSPECIFIED, /**< Cause unspecified. */
2326         RTE_FLOW_ERROR_TYPE_HANDLE, /**< Flow rule (handle). */
2327         RTE_FLOW_ERROR_TYPE_ATTR_GROUP, /**< Group field. */
2328         RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY, /**< Priority field. */
2329         RTE_FLOW_ERROR_TYPE_ATTR_INGRESS, /**< Ingress field. */
2330         RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, /**< Egress field. */
2331         RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER, /**< Transfer field. */
2332         RTE_FLOW_ERROR_TYPE_ATTR, /**< Attributes structure. */
2333         RTE_FLOW_ERROR_TYPE_ITEM_NUM, /**< Pattern length. */
2334         RTE_FLOW_ERROR_TYPE_ITEM_SPEC, /**< Item specification. */
2335         RTE_FLOW_ERROR_TYPE_ITEM_LAST, /**< Item specification range. */
2336         RTE_FLOW_ERROR_TYPE_ITEM_MASK, /**< Item specification mask. */
2337         RTE_FLOW_ERROR_TYPE_ITEM, /**< Specific pattern item. */
2338         RTE_FLOW_ERROR_TYPE_ACTION_NUM, /**< Number of actions. */
2339         RTE_FLOW_ERROR_TYPE_ACTION_CONF, /**< Action configuration. */
2340         RTE_FLOW_ERROR_TYPE_ACTION, /**< Specific action. */
2341 };
2342
2343 /**
2344  * Verbose error structure definition.
2345  *
2346  * This object is normally allocated by applications and set by PMDs, the
2347  * message points to a constant string which does not need to be freed by
2348  * the application, however its pointer can be considered valid only as long
2349  * as its associated DPDK port remains configured. Closing the underlying
2350  * device or unloading the PMD invalidates it.
2351  *
2352  * Both cause and message may be NULL regardless of the error type.
2353  */
2354 struct rte_flow_error {
2355         enum rte_flow_error_type type; /**< Cause field and error types. */
2356         const void *cause; /**< Object responsible for the error. */
2357         const char *message; /**< Human-readable error message. */
2358 };
2359
2360 /**
2361  * Complete flow rule description.
2362  *
2363  * This object type is used when converting a flow rule description.
2364  *
2365  * @see RTE_FLOW_CONV_OP_RULE
2366  * @see rte_flow_conv()
2367  */
2368 RTE_STD_C11
2369 struct rte_flow_conv_rule {
2370         union {
2371                 const struct rte_flow_attr *attr_ro; /**< RO attributes. */
2372                 struct rte_flow_attr *attr; /**< Attributes. */
2373         };
2374         union {
2375                 const struct rte_flow_item *pattern_ro; /**< RO pattern. */
2376                 struct rte_flow_item *pattern; /**< Pattern items. */
2377         };
2378         union {
2379                 const struct rte_flow_action *actions_ro; /**< RO actions. */
2380                 struct rte_flow_action *actions; /**< List of actions. */
2381         };
2382 };
2383
2384 /**
2385  * Conversion operations for flow API objects.
2386  *
2387  * @see rte_flow_conv()
2388  */
2389 enum rte_flow_conv_op {
2390         /**
2391          * No operation to perform.
2392          *
2393          * rte_flow_conv() simply returns 0.
2394          */
2395         RTE_FLOW_CONV_OP_NONE,
2396
2397         /**
2398          * Convert attributes structure.
2399          *
2400          * This is a basic copy of an attributes structure.
2401          *
2402          * - @p src type:
2403          *   @code const struct rte_flow_attr * @endcode
2404          * - @p dst type:
2405          *   @code struct rte_flow_attr * @endcode
2406          */
2407         RTE_FLOW_CONV_OP_ATTR,
2408
2409         /**
2410          * Convert a single item.
2411          *
2412          * Duplicates @p spec, @p last and @p mask but not outside objects.
2413          *
2414          * - @p src type:
2415          *   @code const struct rte_flow_item * @endcode
2416          * - @p dst type:
2417          *   @code struct rte_flow_item * @endcode
2418          */
2419         RTE_FLOW_CONV_OP_ITEM,
2420
2421         /**
2422          * Convert a single action.
2423          *
2424          * Duplicates @p conf but not outside objects.
2425          *
2426          * - @p src type:
2427          *   @code const struct rte_flow_action * @endcode
2428          * - @p dst type:
2429          *   @code struct rte_flow_action * @endcode
2430          */
2431         RTE_FLOW_CONV_OP_ACTION,
2432
2433         /**
2434          * Convert an entire pattern.
2435          *
2436          * Duplicates all pattern items at once with the same constraints as
2437          * RTE_FLOW_CONV_OP_ITEM.
2438          *
2439          * - @p src type:
2440          *   @code const struct rte_flow_item * @endcode
2441          * - @p dst type:
2442          *   @code struct rte_flow_item * @endcode
2443          */
2444         RTE_FLOW_CONV_OP_PATTERN,
2445
2446         /**
2447          * Convert a list of actions.
2448          *
2449          * Duplicates the entire list of actions at once with the same
2450          * constraints as RTE_FLOW_CONV_OP_ACTION.
2451          *
2452          * - @p src type:
2453          *   @code const struct rte_flow_action * @endcode
2454          * - @p dst type:
2455          *   @code struct rte_flow_action * @endcode
2456          */
2457         RTE_FLOW_CONV_OP_ACTIONS,
2458
2459         /**
2460          * Convert a complete flow rule description.
2461          *
2462          * Comprises attributes, pattern and actions together at once with
2463          * the usual constraints.
2464          *
2465          * - @p src type:
2466          *   @code const struct rte_flow_conv_rule * @endcode
2467          * - @p dst type:
2468          *   @code struct rte_flow_conv_rule * @endcode
2469          */
2470         RTE_FLOW_CONV_OP_RULE,
2471
2472         /**
2473          * Convert item type to its name string.
2474          *
2475          * Writes a NUL-terminated string to @p dst. Like snprintf(), the
2476          * returned value excludes the terminator which is always written
2477          * nonetheless.
2478          *
2479          * - @p src type:
2480          *   @code (const void *)enum rte_flow_item_type @endcode
2481          * - @p dst type:
2482          *   @code char * @endcode
2483          **/
2484         RTE_FLOW_CONV_OP_ITEM_NAME,
2485
2486         /**
2487          * Convert action type to its name string.
2488          *
2489          * Writes a NUL-terminated string to @p dst. Like snprintf(), the
2490          * returned value excludes the terminator which is always written
2491          * nonetheless.
2492          *
2493          * - @p src type:
2494          *   @code (const void *)enum rte_flow_action_type @endcode
2495          * - @p dst type:
2496          *   @code char * @endcode
2497          **/
2498         RTE_FLOW_CONV_OP_ACTION_NAME,
2499
2500         /**
2501          * Convert item type to pointer to item name.
2502          *
2503          * Retrieves item name pointer from its type. The string itself is
2504          * not copied; instead, a unique pointer to an internal static
2505          * constant storage is written to @p dst.
2506          *
2507          * - @p src type:
2508          *   @code (const void *)enum rte_flow_item_type @endcode
2509          * - @p dst type:
2510          *   @code const char ** @endcode
2511          */
2512         RTE_FLOW_CONV_OP_ITEM_NAME_PTR,
2513
2514         /**
2515          * Convert action type to pointer to action name.
2516          *
2517          * Retrieves action name pointer from its type. The string itself is
2518          * not copied; instead, a unique pointer to an internal static
2519          * constant storage is written to @p dst.
2520          *
2521          * - @p src type:
2522          *   @code (const void *)enum rte_flow_action_type @endcode
2523          * - @p dst type:
2524          *   @code const char ** @endcode
2525          */
2526         RTE_FLOW_CONV_OP_ACTION_NAME_PTR,
2527 };
2528
2529 /**
2530  * Check whether a flow rule can be created on a given port.
2531  *
2532  * The flow rule is validated for correctness and whether it could be accepted
2533  * by the device given sufficient resources. The rule is checked against the
2534  * current device mode and queue configuration. The flow rule may also
2535  * optionally be validated against existing flow rules and device resources.
2536  * This function has no effect on the target device.
2537  *
2538  * The returned value is guaranteed to remain valid only as long as no
2539  * successful calls to rte_flow_create() or rte_flow_destroy() are made in
2540  * the meantime and no device parameter affecting flow rules in any way are
2541  * modified, due to possible collisions or resource limitations (although in
2542  * such cases EINVAL should not be returned).
2543  *
2544  * @param port_id
2545  *   Port identifier of Ethernet device.
2546  * @param[in] attr
2547  *   Flow rule attributes.
2548  * @param[in] pattern
2549  *   Pattern specification (list terminated by the END pattern item).
2550  * @param[in] actions
2551  *   Associated actions (list terminated by the END action).
2552  * @param[out] error
2553  *   Perform verbose error reporting if not NULL. PMDs initialize this
2554  *   structure in case of error only.
2555  *
2556  * @return
2557  *   0 if flow rule is valid and can be created. A negative errno value
2558  *   otherwise (rte_errno is also set), the following errors are defined:
2559  *
2560  *   -ENOSYS: underlying device does not support this functionality.
2561  *
2562  *   -EIO: underlying device is removed.
2563  *
2564  *   -EINVAL: unknown or invalid rule specification.
2565  *
2566  *   -ENOTSUP: valid but unsupported rule specification (e.g. partial
2567  *   bit-masks are unsupported).
2568  *
2569  *   -EEXIST: collision with an existing rule. Only returned if device
2570  *   supports flow rule collision checking and there was a flow rule
2571  *   collision. Not receiving this return code is no guarantee that creating
2572  *   the rule will not fail due to a collision.
2573  *
2574  *   -ENOMEM: not enough memory to execute the function, or if the device
2575  *   supports resource validation, resource limitation on the device.
2576  *
2577  *   -EBUSY: action cannot be performed due to busy device resources, may
2578  *   succeed if the affected queues or even the entire port are in a stopped
2579  *   state (see rte_eth_dev_rx_queue_stop() and rte_eth_dev_stop()).
2580  */
2581 int
2582 rte_flow_validate(uint16_t port_id,
2583                   const struct rte_flow_attr *attr,
2584                   const struct rte_flow_item pattern[],
2585                   const struct rte_flow_action actions[],
2586                   struct rte_flow_error *error);
2587
2588 /**
2589  * Create a flow rule on a given port.
2590  *
2591  * @param port_id
2592  *   Port identifier of Ethernet device.
2593  * @param[in] attr
2594  *   Flow rule attributes.
2595  * @param[in] pattern
2596  *   Pattern specification (list terminated by the END pattern item).
2597  * @param[in] actions
2598  *   Associated actions (list terminated by the END action).
2599  * @param[out] error
2600  *   Perform verbose error reporting if not NULL. PMDs initialize this
2601  *   structure in case of error only.
2602  *
2603  * @return
2604  *   A valid handle in case of success, NULL otherwise and rte_errno is set
2605  *   to the positive version of one of the error codes defined for
2606  *   rte_flow_validate().
2607  */
2608 struct rte_flow *
2609 rte_flow_create(uint16_t port_id,
2610                 const struct rte_flow_attr *attr,
2611                 const struct rte_flow_item pattern[],
2612                 const struct rte_flow_action actions[],
2613                 struct rte_flow_error *error);
2614
2615 /**
2616  * Destroy a flow rule on a given port.
2617  *
2618  * Failure to destroy a flow rule handle may occur when other flow rules
2619  * depend on it, and destroying it would result in an inconsistent state.
2620  *
2621  * This function is only guaranteed to succeed if handles are destroyed in
2622  * reverse order of their creation.
2623  *
2624  * @param port_id
2625  *   Port identifier of Ethernet device.
2626  * @param flow
2627  *   Flow rule handle to destroy.
2628  * @param[out] error
2629  *   Perform verbose error reporting if not NULL. PMDs initialize this
2630  *   structure in case of error only.
2631  *
2632  * @return
2633  *   0 on success, a negative errno value otherwise and rte_errno is set.
2634  */
2635 int
2636 rte_flow_destroy(uint16_t port_id,
2637                  struct rte_flow *flow,
2638                  struct rte_flow_error *error);
2639
2640 /**
2641  * Destroy all flow rules associated with a port.
2642  *
2643  * In the unlikely event of failure, handles are still considered destroyed
2644  * and no longer valid but the port must be assumed to be in an inconsistent
2645  * state.
2646  *
2647  * @param port_id
2648  *   Port identifier of Ethernet device.
2649  * @param[out] error
2650  *   Perform verbose error reporting if not NULL. PMDs initialize this
2651  *   structure in case of error only.
2652  *
2653  * @return
2654  *   0 on success, a negative errno value otherwise and rte_errno is set.
2655  */
2656 int
2657 rte_flow_flush(uint16_t port_id,
2658                struct rte_flow_error *error);
2659
2660 /**
2661  * Query an existing flow rule.
2662  *
2663  * This function allows retrieving flow-specific data such as counters.
2664  * Data is gathered by special actions which must be present in the flow
2665  * rule definition.
2666  *
2667  * \see RTE_FLOW_ACTION_TYPE_COUNT
2668  *
2669  * @param port_id
2670  *   Port identifier of Ethernet device.
2671  * @param flow
2672  *   Flow rule handle to query.
2673  * @param action
2674  *   Action definition as defined in original flow rule.
2675  * @param[in, out] data
2676  *   Pointer to storage for the associated query data type.
2677  * @param[out] error
2678  *   Perform verbose error reporting if not NULL. PMDs initialize this
2679  *   structure in case of error only.
2680  *
2681  * @return
2682  *   0 on success, a negative errno value otherwise and rte_errno is set.
2683  */
2684 int
2685 rte_flow_query(uint16_t port_id,
2686                struct rte_flow *flow,
2687                const struct rte_flow_action *action,
2688                void *data,
2689                struct rte_flow_error *error);
2690
2691 /**
2692  * Restrict ingress traffic to the defined flow rules.
2693  *
2694  * Isolated mode guarantees that all ingress traffic comes from defined flow
2695  * rules only (current and future).
2696  *
2697  * Besides making ingress more deterministic, it allows PMDs to safely reuse
2698  * resources otherwise assigned to handle the remaining traffic, such as
2699  * global RSS configuration settings, VLAN filters, MAC address entries,
2700  * legacy filter API rules and so on in order to expand the set of possible
2701  * flow rule types.
2702  *
2703  * Calling this function as soon as possible after device initialization,
2704  * ideally before the first call to rte_eth_dev_configure(), is recommended
2705  * to avoid possible failures due to conflicting settings.
2706  *
2707  * Once effective, leaving isolated mode may not be possible depending on
2708  * PMD implementation.
2709  *
2710  * Additionally, the following functionality has no effect on the underlying
2711  * port and may return errors such as ENOTSUP ("not supported"):
2712  *
2713  * - Toggling promiscuous mode.
2714  * - Toggling allmulticast mode.
2715  * - Configuring MAC addresses.
2716  * - Configuring multicast addresses.
2717  * - Configuring VLAN filters.
2718  * - Configuring Rx filters through the legacy API (e.g. FDIR).
2719  * - Configuring global RSS settings.
2720  *
2721  * @param port_id
2722  *   Port identifier of Ethernet device.
2723  * @param set
2724  *   Nonzero to enter isolated mode, attempt to leave it otherwise.
2725  * @param[out] error
2726  *   Perform verbose error reporting if not NULL. PMDs initialize this
2727  *   structure in case of error only.
2728  *
2729  * @return
2730  *   0 on success, a negative errno value otherwise and rte_errno is set.
2731  */
2732 int
2733 rte_flow_isolate(uint16_t port_id, int set, struct rte_flow_error *error);
2734
2735 /**
2736  * Initialize flow error structure.
2737  *
2738  * @param[out] error
2739  *   Pointer to flow error structure (may be NULL).
2740  * @param code
2741  *   Related error code (rte_errno).
2742  * @param type
2743  *   Cause field and error types.
2744  * @param cause
2745  *   Object responsible for the error.
2746  * @param message
2747  *   Human-readable error message.
2748  *
2749  * @return
2750  *   Negative error code (errno value) and rte_errno is set.
2751  */
2752 int
2753 rte_flow_error_set(struct rte_flow_error *error,
2754                    int code,
2755                    enum rte_flow_error_type type,
2756                    const void *cause,
2757                    const char *message);
2758
2759 /**
2760  * @deprecated
2761  * @see rte_flow_copy()
2762  */
2763 struct rte_flow_desc {
2764         size_t size; /**< Allocated space including data[]. */
2765         struct rte_flow_attr attr; /**< Attributes. */
2766         struct rte_flow_item *items; /**< Items. */
2767         struct rte_flow_action *actions; /**< Actions. */
2768         uint8_t data[]; /**< Storage for items/actions. */
2769 };
2770
2771 /**
2772  * @deprecated
2773  * Copy an rte_flow rule description.
2774  *
2775  * This interface is kept for compatibility with older applications but is
2776  * implemented as a wrapper to rte_flow_conv(). It is deprecated due to its
2777  * lack of flexibility and reliance on a type unusable with C++ programs
2778  * (struct rte_flow_desc).
2779  *
2780  * @param[in] fd
2781  *   Flow rule description.
2782  * @param[in] len
2783  *   Total size of allocated data for the flow description.
2784  * @param[in] attr
2785  *   Flow rule attributes.
2786  * @param[in] items
2787  *   Pattern specification (list terminated by the END pattern item).
2788  * @param[in] actions
2789  *   Associated actions (list terminated by the END action).
2790  *
2791  * @return
2792  *   If len is greater or equal to the size of the flow, the total size of the
2793  *   flow description and its data.
2794  *   If len is lower than the size of the flow, the number of bytes that would
2795  *   have been written to desc had it been sufficient. Nothing is written.
2796  */
2797 __rte_deprecated
2798 size_t
2799 rte_flow_copy(struct rte_flow_desc *fd, size_t len,
2800               const struct rte_flow_attr *attr,
2801               const struct rte_flow_item *items,
2802               const struct rte_flow_action *actions);
2803
2804 /**
2805  * Flow object conversion helper.
2806  *
2807  * This function performs conversion of various flow API objects to a
2808  * pre-allocated destination buffer. See enum rte_flow_conv_op for possible
2809  * operations and details about each of them.
2810  *
2811  * Since destination buffer must be large enough, it works in a manner
2812  * reminiscent of snprintf():
2813  *
2814  * - If @p size is 0, @p dst may be a NULL pointer, otherwise @p dst must be
2815  *   non-NULL.
2816  * - If positive, the returned value represents the number of bytes needed
2817  *   to store the conversion of @p src to @p dst according to @p op
2818  *   regardless of the @p size parameter.
2819  * - Since no more than @p size bytes can be written to @p dst, output is
2820  *   truncated and may be inconsistent when the returned value is larger
2821  *   than that.
2822  * - In case of conversion error, a negative error code is returned and
2823  *   @p dst contents are unspecified.
2824  *
2825  * @param op
2826  *   Operation to perform, related to the object type of @p dst.
2827  * @param[out] dst
2828  *   Destination buffer address. Must be suitably aligned by the caller.
2829  * @param size
2830  *   Destination buffer size in bytes.
2831  * @param[in] src
2832  *   Source object to copy. Depending on @p op, its type may differ from
2833  *   that of @p dst.
2834  * @param[out] error
2835  *   Perform verbose error reporting if not NULL. Initialized in case of
2836  *   error only.
2837  *
2838  * @return
2839  *   The number of bytes required to convert @p src to @p dst on success, a
2840  *   negative errno value otherwise and rte_errno is set.
2841  *
2842  * @see rte_flow_conv_op
2843  */
2844 __rte_experimental
2845 int
2846 rte_flow_conv(enum rte_flow_conv_op op,
2847               void *dst,
2848               size_t size,
2849               const void *src,
2850               struct rte_flow_error *error);
2851
2852 #ifdef __cplusplus
2853 }
2854 #endif
2855
2856 #endif /* RTE_FLOW_H_ */