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