2fde0f2136cb4cff7375599450452cb4bf0250fc
[dpdk.git] / lib / librte_ether / rte_flow.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2016 6WIND S.A.
3  * Copyright 2016 Mellanox Technologies, Ltd
4  */
5
6 #ifndef RTE_FLOW_H_
7 #define RTE_FLOW_H_
8
9 /**
10  * @file
11  * RTE generic flow API
12  *
13  * This interface provides the ability to program packet matching and
14  * associated actions in hardware through flow rules.
15  */
16
17 #include <stddef.h>
18 #include <stdint.h>
19
20 #include <rte_arp.h>
21 #include <rte_ether.h>
22 #include <rte_eth_ctrl.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 two levels: per group and per rule within groups.
39  *
40  * Lower values denote higher priority, the highest priority for both levels
41  * is 0, so that a rule with priority 0 in group 8 is always matched after a
42  * rule with priority 8 in group 0.
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).
48  *
49  * Group and priority levels are arbitrary and up to the application, they
50  * do not need to be contiguous nor start from 0, however the maximum number
51  * varies between devices and may be affected by existing flow rules.
52  *
53  * If a packet is matched by several rules of a given group for a given
54  * priority level, the outcome is undefined. It can take any path, may be
55  * duplicated or even cause unrecoverable errors.
56  *
57  * Note that support for more than a single group and priority level is not
58  * guaranteed.
59  *
60  * Flow rules can apply to inbound and/or outbound traffic (ingress/egress).
61  *
62  * Several pattern items and actions are valid and can be used in both
63  * directions. Those valid for only one direction are described as such.
64  *
65  * At least one direction must be specified.
66  *
67  * Specifying both directions at once for a given rule is not recommended
68  * but may be valid in a few cases (e.g. shared counter).
69  */
70 struct rte_flow_attr {
71         uint32_t group; /**< Priority group. */
72         uint32_t priority; /**< Priority level within group. */
73         uint32_t ingress:1; /**< Rule applies to ingress traffic. */
74         uint32_t egress:1; /**< Rule applies to egress traffic. */
75         /**
76          * Instead of simply matching the properties of traffic as it would
77          * appear on a given DPDK port ID, enabling this attribute transfers
78          * a flow rule to the lowest possible level of any device endpoints
79          * found in the pattern.
80          *
81          * When supported, this effectively enables an application to
82          * re-route traffic not necessarily intended for it (e.g. coming
83          * from or addressed to different physical ports, VFs or
84          * applications) at the device level.
85          *
86          * It complements the behavior of some pattern items such as
87          * RTE_FLOW_ITEM_TYPE_PHY_PORT and is meaningless without them.
88          *
89          * When transferring flow rules, ingress and egress attributes keep
90          * their original meaning, as if processing traffic emitted or
91          * received by the application.
92          */
93         uint32_t transfer:1;
94         uint32_t reserved:29; /**< Reserved, must be zero. */
95 };
96
97 /**
98  * Matching pattern item types.
99  *
100  * Pattern items fall in two categories:
101  *
102  * - Matching protocol headers and packet data, usually associated with a
103  *   specification structure. These must be stacked in the same order as the
104  *   protocol layers to match inside packets, starting from the lowest.
105  *
106  * - Matching meta-data or affecting pattern processing, often without a
107  *   specification structure. Since they do not match packet contents, their
108  *   position in the list is usually not relevant.
109  *
110  * See the description of individual types for more information. Those
111  * marked with [META] fall into the second category.
112  */
113 enum rte_flow_item_type {
114         /**
115          * [META]
116          *
117          * End marker for item lists. Prevents further processing of items,
118          * thereby ending the pattern.
119          *
120          * No associated specification structure.
121          */
122         RTE_FLOW_ITEM_TYPE_END,
123
124         /**
125          * [META]
126          *
127          * Used as a placeholder for convenience. It is ignored and simply
128          * discarded by PMDs.
129          *
130          * No associated specification structure.
131          */
132         RTE_FLOW_ITEM_TYPE_VOID,
133
134         /**
135          * [META]
136          *
137          * Inverted matching, i.e. process packets that do not match the
138          * pattern.
139          *
140          * No associated specification structure.
141          */
142         RTE_FLOW_ITEM_TYPE_INVERT,
143
144         /**
145          * Matches any protocol in place of the current layer, a single ANY
146          * may also stand for several protocol layers.
147          *
148          * See struct rte_flow_item_any.
149          */
150         RTE_FLOW_ITEM_TYPE_ANY,
151
152         /**
153          * [META]
154          *
155          * Matches traffic originating from (ingress) or going to (egress)
156          * the physical function of the current device.
157          *
158          * No associated specification structure.
159          */
160         RTE_FLOW_ITEM_TYPE_PF,
161
162         /**
163          * [META]
164          *
165          * Matches traffic originating from (ingress) or going to (egress) a
166          * given virtual function of the current device.
167          *
168          * See struct rte_flow_item_vf.
169          */
170         RTE_FLOW_ITEM_TYPE_VF,
171
172         /**
173          * [META]
174          *
175          * Matches traffic originating from (ingress) or going to (egress) a
176          * physical port of the underlying device.
177          *
178          * See struct rte_flow_item_phy_port.
179          */
180         RTE_FLOW_ITEM_TYPE_PHY_PORT,
181
182         /**
183          * [META]
184          *
185          * Matches traffic originating from (ingress) or going to (egress) a
186          * given DPDK port ID.
187          *
188          * See struct rte_flow_item_port_id.
189          */
190         RTE_FLOW_ITEM_TYPE_PORT_ID,
191
192         /**
193          * Matches a byte string of a given length at a given offset.
194          *
195          * See struct rte_flow_item_raw.
196          */
197         RTE_FLOW_ITEM_TYPE_RAW,
198
199         /**
200          * Matches an Ethernet header.
201          *
202          * See struct rte_flow_item_eth.
203          */
204         RTE_FLOW_ITEM_TYPE_ETH,
205
206         /**
207          * Matches an 802.1Q/ad VLAN tag.
208          *
209          * See struct rte_flow_item_vlan.
210          */
211         RTE_FLOW_ITEM_TYPE_VLAN,
212
213         /**
214          * Matches an IPv4 header.
215          *
216          * See struct rte_flow_item_ipv4.
217          */
218         RTE_FLOW_ITEM_TYPE_IPV4,
219
220         /**
221          * Matches an IPv6 header.
222          *
223          * See struct rte_flow_item_ipv6.
224          */
225         RTE_FLOW_ITEM_TYPE_IPV6,
226
227         /**
228          * Matches an ICMP header.
229          *
230          * See struct rte_flow_item_icmp.
231          */
232         RTE_FLOW_ITEM_TYPE_ICMP,
233
234         /**
235          * Matches a UDP header.
236          *
237          * See struct rte_flow_item_udp.
238          */
239         RTE_FLOW_ITEM_TYPE_UDP,
240
241         /**
242          * Matches a TCP header.
243          *
244          * See struct rte_flow_item_tcp.
245          */
246         RTE_FLOW_ITEM_TYPE_TCP,
247
248         /**
249          * Matches a SCTP header.
250          *
251          * See struct rte_flow_item_sctp.
252          */
253         RTE_FLOW_ITEM_TYPE_SCTP,
254
255         /**
256          * Matches a VXLAN header.
257          *
258          * See struct rte_flow_item_vxlan.
259          */
260         RTE_FLOW_ITEM_TYPE_VXLAN,
261
262         /**
263          * Matches a E_TAG header.
264          *
265          * See struct rte_flow_item_e_tag.
266          */
267         RTE_FLOW_ITEM_TYPE_E_TAG,
268
269         /**
270          * Matches a NVGRE header.
271          *
272          * See struct rte_flow_item_nvgre.
273          */
274         RTE_FLOW_ITEM_TYPE_NVGRE,
275
276         /**
277          * Matches a MPLS header.
278          *
279          * See struct rte_flow_item_mpls.
280          */
281         RTE_FLOW_ITEM_TYPE_MPLS,
282
283         /**
284          * Matches a GRE header.
285          *
286          * See struct rte_flow_item_gre.
287          */
288         RTE_FLOW_ITEM_TYPE_GRE,
289
290         /**
291          * [META]
292          *
293          * Fuzzy pattern match, expect faster than default.
294          *
295          * This is for device that support fuzzy matching option.
296          * Usually a fuzzy matching is fast but the cost is accuracy.
297          *
298          * See struct rte_flow_item_fuzzy.
299          */
300         RTE_FLOW_ITEM_TYPE_FUZZY,
301
302         /**
303          * Matches a GTP header.
304          *
305          * Configure flow for GTP packets.
306          *
307          * See struct rte_flow_item_gtp.
308          */
309         RTE_FLOW_ITEM_TYPE_GTP,
310
311         /**
312          * Matches a GTP header.
313          *
314          * Configure flow for GTP-C packets.
315          *
316          * See struct rte_flow_item_gtp.
317          */
318         RTE_FLOW_ITEM_TYPE_GTPC,
319
320         /**
321          * Matches a GTP header.
322          *
323          * Configure flow for GTP-U packets.
324          *
325          * See struct rte_flow_item_gtp.
326          */
327         RTE_FLOW_ITEM_TYPE_GTPU,
328
329         /**
330          * Matches a ESP header.
331          *
332          * See struct rte_flow_item_esp.
333          */
334         RTE_FLOW_ITEM_TYPE_ESP,
335
336         /**
337          * Matches a GENEVE header.
338          *
339          * See struct rte_flow_item_geneve.
340          */
341         RTE_FLOW_ITEM_TYPE_GENEVE,
342
343         /**
344          * Matches a VXLAN-GPE header.
345          *
346          * See struct rte_flow_item_vxlan_gpe.
347          */
348         RTE_FLOW_ITEM_TYPE_VXLAN_GPE,
349
350         /**
351          * Matches an ARP header for Ethernet/IPv4.
352          *
353          * See struct rte_flow_item_arp_eth_ipv4.
354          */
355         RTE_FLOW_ITEM_TYPE_ARP_ETH_IPV4,
356
357         /**
358          * Matches the presence of any IPv6 extension header.
359          *
360          * See struct rte_flow_item_ipv6_ext.
361          */
362         RTE_FLOW_ITEM_TYPE_IPV6_EXT,
363
364         /**
365          * Matches any ICMPv6 header.
366          *
367          * See struct rte_flow_item_icmp6.
368          */
369         RTE_FLOW_ITEM_TYPE_ICMP6,
370
371         /**
372          * Matches an ICMPv6 neighbor discovery solicitation.
373          *
374          * See struct rte_flow_item_icmp6_nd_ns.
375          */
376         RTE_FLOW_ITEM_TYPE_ICMP6_ND_NS,
377
378         /**
379          * Matches an ICMPv6 neighbor discovery advertisement.
380          *
381          * See struct rte_flow_item_icmp6_nd_na.
382          */
383         RTE_FLOW_ITEM_TYPE_ICMP6_ND_NA,
384
385         /**
386          * Matches the presence of any ICMPv6 neighbor discovery option.
387          *
388          * See struct rte_flow_item_icmp6_nd_opt.
389          */
390         RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT,
391
392         /**
393          * Matches an ICMPv6 neighbor discovery source Ethernet link-layer
394          * address option.
395          *
396          * See struct rte_flow_item_icmp6_nd_opt_sla_eth.
397          */
398         RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT_SLA_ETH,
399
400         /**
401          * Matches an ICMPv6 neighbor discovery target Ethernet link-layer
402          * address option.
403          *
404          * See struct rte_flow_item_icmp6_nd_opt_tla_eth.
405          */
406         RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT_TLA_ETH,
407 };
408
409 /**
410  * RTE_FLOW_ITEM_TYPE_ANY
411  *
412  * Matches any protocol in place of the current layer, a single ANY may also
413  * stand for several protocol layers.
414  *
415  * This is usually specified as the first pattern item when looking for a
416  * protocol anywhere in a packet.
417  *
418  * A zeroed mask stands for any number of layers.
419  */
420 struct rte_flow_item_any {
421         uint32_t num; /**< Number of layers covered. */
422 };
423
424 /** Default mask for RTE_FLOW_ITEM_TYPE_ANY. */
425 #ifndef __cplusplus
426 static const struct rte_flow_item_any rte_flow_item_any_mask = {
427         .num = 0x00000000,
428 };
429 #endif
430
431 /**
432  * RTE_FLOW_ITEM_TYPE_VF
433  *
434  * Matches traffic originating from (ingress) or going to (egress) a given
435  * virtual function of the current device.
436  *
437  * If supported, should work even if the virtual function is not managed by
438  * the application and thus not associated with a DPDK port ID.
439  *
440  * Note this pattern item does not match VF representors traffic which, as
441  * separate entities, should be addressed through their own DPDK port IDs.
442  *
443  * - Can be specified multiple times to match traffic addressed to several
444  *   VF IDs.
445  * - Can be combined with a PF item to match both PF and VF traffic.
446  *
447  * A zeroed mask can be used to match any VF ID.
448  */
449 struct rte_flow_item_vf {
450         uint32_t id; /**< VF ID. */
451 };
452
453 /** Default mask for RTE_FLOW_ITEM_TYPE_VF. */
454 #ifndef __cplusplus
455 static const struct rte_flow_item_vf rte_flow_item_vf_mask = {
456         .id = 0x00000000,
457 };
458 #endif
459
460 /**
461  * RTE_FLOW_ITEM_TYPE_PHY_PORT
462  *
463  * Matches traffic originating from (ingress) or going to (egress) a
464  * physical port of the underlying device.
465  *
466  * The first PHY_PORT item overrides the physical port normally associated
467  * with the specified DPDK input port (port_id). This item can be provided
468  * several times to match additional physical ports.
469  *
470  * Note that physical ports are not necessarily tied to DPDK input ports
471  * (port_id) when those are not under DPDK control. Possible values are
472  * specific to each device, they are not necessarily indexed from zero and
473  * may not be contiguous.
474  *
475  * As a device property, the list of allowed values as well as the value
476  * associated with a port_id should be retrieved by other means.
477  *
478  * A zeroed mask can be used to match any port index.
479  */
480 struct rte_flow_item_phy_port {
481         uint32_t index; /**< Physical port index. */
482 };
483
484 /** Default mask for RTE_FLOW_ITEM_TYPE_PHY_PORT. */
485 #ifndef __cplusplus
486 static const struct rte_flow_item_phy_port rte_flow_item_phy_port_mask = {
487         .index = 0x00000000,
488 };
489 #endif
490
491 /**
492  * RTE_FLOW_ITEM_TYPE_PORT_ID
493  *
494  * Matches traffic originating from (ingress) or going to (egress) a given
495  * DPDK port ID.
496  *
497  * Normally only supported if the port ID in question is known by the
498  * underlying PMD and related to the device the flow rule is created
499  * against.
500  *
501  * This must not be confused with @p PHY_PORT which refers to the physical
502  * port of a device, whereas @p PORT_ID refers to a struct rte_eth_dev
503  * object on the application side (also known as "port representor"
504  * depending on the kind of underlying device).
505  */
506 struct rte_flow_item_port_id {
507         uint32_t id; /**< DPDK port ID. */
508 };
509
510 /** Default mask for RTE_FLOW_ITEM_TYPE_PORT_ID. */
511 #ifndef __cplusplus
512 static const struct rte_flow_item_port_id rte_flow_item_port_id_mask = {
513         .id = 0xffffffff,
514 };
515 #endif
516
517 /**
518  * RTE_FLOW_ITEM_TYPE_RAW
519  *
520  * Matches a byte string of a given length at a given offset.
521  *
522  * Offset is either absolute (using the start of the packet) or relative to
523  * the end of the previous matched item in the stack, in which case negative
524  * values are allowed.
525  *
526  * If search is enabled, offset is used as the starting point. The search
527  * area can be delimited by setting limit to a nonzero value, which is the
528  * maximum number of bytes after offset where the pattern may start.
529  *
530  * Matching a zero-length pattern is allowed, doing so resets the relative
531  * offset for subsequent items.
532  *
533  * This type does not support ranges (struct rte_flow_item.last).
534  */
535 struct rte_flow_item_raw {
536         uint32_t relative:1; /**< Look for pattern after the previous item. */
537         uint32_t search:1; /**< Search pattern from offset (see also limit). */
538         uint32_t reserved:30; /**< Reserved, must be set to zero. */
539         int32_t offset; /**< Absolute or relative offset for pattern. */
540         uint16_t limit; /**< Search area limit for start of pattern. */
541         uint16_t length; /**< Pattern length. */
542         const uint8_t *pattern; /**< Byte string to look for. */
543 };
544
545 /** Default mask for RTE_FLOW_ITEM_TYPE_RAW. */
546 #ifndef __cplusplus
547 static const struct rte_flow_item_raw rte_flow_item_raw_mask = {
548         .relative = 1,
549         .search = 1,
550         .reserved = 0x3fffffff,
551         .offset = 0xffffffff,
552         .limit = 0xffff,
553         .length = 0xffff,
554         .pattern = NULL,
555 };
556 #endif
557
558 /**
559  * RTE_FLOW_ITEM_TYPE_ETH
560  *
561  * Matches an Ethernet header.
562  *
563  * The @p type field either stands for "EtherType" or "TPID" when followed
564  * by so-called layer 2.5 pattern items such as RTE_FLOW_ITEM_TYPE_VLAN. In
565  * the latter case, @p type refers to that of the outer header, with the
566  * inner EtherType/TPID provided by the subsequent pattern item. This is the
567  * same order as on the wire.
568  */
569 struct rte_flow_item_eth {
570         struct ether_addr dst; /**< Destination MAC. */
571         struct ether_addr src; /**< Source MAC. */
572         rte_be16_t type; /**< EtherType or TPID. */
573 };
574
575 /** Default mask for RTE_FLOW_ITEM_TYPE_ETH. */
576 #ifndef __cplusplus
577 static const struct rte_flow_item_eth rte_flow_item_eth_mask = {
578         .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
579         .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
580         .type = RTE_BE16(0x0000),
581 };
582 #endif
583
584 /**
585  * RTE_FLOW_ITEM_TYPE_VLAN
586  *
587  * Matches an 802.1Q/ad VLAN tag.
588  *
589  * The corresponding standard outer EtherType (TPID) values are
590  * ETHER_TYPE_VLAN or ETHER_TYPE_QINQ. It can be overridden by the preceding
591  * pattern item.
592  */
593 struct rte_flow_item_vlan {
594         rte_be16_t tci; /**< Tag control information. */
595         rte_be16_t inner_type; /**< Inner EtherType or TPID. */
596 };
597
598 /** Default mask for RTE_FLOW_ITEM_TYPE_VLAN. */
599 #ifndef __cplusplus
600 static const struct rte_flow_item_vlan rte_flow_item_vlan_mask = {
601         .tci = RTE_BE16(0x0fff),
602         .inner_type = RTE_BE16(0x0000),
603 };
604 #endif
605
606 /**
607  * RTE_FLOW_ITEM_TYPE_IPV4
608  *
609  * Matches an IPv4 header.
610  *
611  * Note: IPv4 options are handled by dedicated pattern items.
612  */
613 struct rte_flow_item_ipv4 {
614         struct ipv4_hdr hdr; /**< IPv4 header definition. */
615 };
616
617 /** Default mask for RTE_FLOW_ITEM_TYPE_IPV4. */
618 #ifndef __cplusplus
619 static const struct rte_flow_item_ipv4 rte_flow_item_ipv4_mask = {
620         .hdr = {
621                 .src_addr = RTE_BE32(0xffffffff),
622                 .dst_addr = RTE_BE32(0xffffffff),
623         },
624 };
625 #endif
626
627 /**
628  * RTE_FLOW_ITEM_TYPE_IPV6.
629  *
630  * Matches an IPv6 header.
631  *
632  * Note: IPv6 options are handled by dedicated pattern items, see
633  * RTE_FLOW_ITEM_TYPE_IPV6_EXT.
634  */
635 struct rte_flow_item_ipv6 {
636         struct ipv6_hdr hdr; /**< IPv6 header definition. */
637 };
638
639 /** Default mask for RTE_FLOW_ITEM_TYPE_IPV6. */
640 #ifndef __cplusplus
641 static const struct rte_flow_item_ipv6 rte_flow_item_ipv6_mask = {
642         .hdr = {
643                 .src_addr =
644                         "\xff\xff\xff\xff\xff\xff\xff\xff"
645                         "\xff\xff\xff\xff\xff\xff\xff\xff",
646                 .dst_addr =
647                         "\xff\xff\xff\xff\xff\xff\xff\xff"
648                         "\xff\xff\xff\xff\xff\xff\xff\xff",
649         },
650 };
651 #endif
652
653 /**
654  * RTE_FLOW_ITEM_TYPE_ICMP.
655  *
656  * Matches an ICMP header.
657  */
658 struct rte_flow_item_icmp {
659         struct icmp_hdr hdr; /**< ICMP header definition. */
660 };
661
662 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP. */
663 #ifndef __cplusplus
664 static const struct rte_flow_item_icmp rte_flow_item_icmp_mask = {
665         .hdr = {
666                 .icmp_type = 0xff,
667                 .icmp_code = 0xff,
668         },
669 };
670 #endif
671
672 /**
673  * RTE_FLOW_ITEM_TYPE_UDP.
674  *
675  * Matches a UDP header.
676  */
677 struct rte_flow_item_udp {
678         struct udp_hdr hdr; /**< UDP header definition. */
679 };
680
681 /** Default mask for RTE_FLOW_ITEM_TYPE_UDP. */
682 #ifndef __cplusplus
683 static const struct rte_flow_item_udp rte_flow_item_udp_mask = {
684         .hdr = {
685                 .src_port = RTE_BE16(0xffff),
686                 .dst_port = RTE_BE16(0xffff),
687         },
688 };
689 #endif
690
691 /**
692  * RTE_FLOW_ITEM_TYPE_TCP.
693  *
694  * Matches a TCP header.
695  */
696 struct rte_flow_item_tcp {
697         struct tcp_hdr hdr; /**< TCP header definition. */
698 };
699
700 /** Default mask for RTE_FLOW_ITEM_TYPE_TCP. */
701 #ifndef __cplusplus
702 static const struct rte_flow_item_tcp rte_flow_item_tcp_mask = {
703         .hdr = {
704                 .src_port = RTE_BE16(0xffff),
705                 .dst_port = RTE_BE16(0xffff),
706         },
707 };
708 #endif
709
710 /**
711  * RTE_FLOW_ITEM_TYPE_SCTP.
712  *
713  * Matches a SCTP header.
714  */
715 struct rte_flow_item_sctp {
716         struct sctp_hdr hdr; /**< SCTP header definition. */
717 };
718
719 /** Default mask for RTE_FLOW_ITEM_TYPE_SCTP. */
720 #ifndef __cplusplus
721 static const struct rte_flow_item_sctp rte_flow_item_sctp_mask = {
722         .hdr = {
723                 .src_port = RTE_BE16(0xffff),
724                 .dst_port = RTE_BE16(0xffff),
725         },
726 };
727 #endif
728
729 /**
730  * RTE_FLOW_ITEM_TYPE_VXLAN.
731  *
732  * Matches a VXLAN header (RFC 7348).
733  */
734 struct rte_flow_item_vxlan {
735         uint8_t flags; /**< Normally 0x08 (I flag). */
736         uint8_t rsvd0[3]; /**< Reserved, normally 0x000000. */
737         uint8_t vni[3]; /**< VXLAN identifier. */
738         uint8_t rsvd1; /**< Reserved, normally 0x00. */
739 };
740
741 /** Default mask for RTE_FLOW_ITEM_TYPE_VXLAN. */
742 #ifndef __cplusplus
743 static const struct rte_flow_item_vxlan rte_flow_item_vxlan_mask = {
744         .vni = "\xff\xff\xff",
745 };
746 #endif
747
748 /**
749  * RTE_FLOW_ITEM_TYPE_E_TAG.
750  *
751  * Matches a E-tag header.
752  *
753  * The corresponding standard outer EtherType (TPID) value is
754  * ETHER_TYPE_ETAG. It can be overridden by the preceding pattern item.
755  */
756 struct rte_flow_item_e_tag {
757         /**
758          * E-Tag control information (E-TCI).
759          * E-PCP (3b), E-DEI (1b), ingress E-CID base (12b).
760          */
761         rte_be16_t epcp_edei_in_ecid_b;
762         /** Reserved (2b), GRP (2b), E-CID base (12b). */
763         rte_be16_t rsvd_grp_ecid_b;
764         uint8_t in_ecid_e; /**< Ingress E-CID ext. */
765         uint8_t ecid_e; /**< E-CID ext. */
766         rte_be16_t inner_type; /**< Inner EtherType or TPID. */
767 };
768
769 /** Default mask for RTE_FLOW_ITEM_TYPE_E_TAG. */
770 #ifndef __cplusplus
771 static const struct rte_flow_item_e_tag rte_flow_item_e_tag_mask = {
772         .rsvd_grp_ecid_b = RTE_BE16(0x3fff),
773 };
774 #endif
775
776 /**
777  * RTE_FLOW_ITEM_TYPE_NVGRE.
778  *
779  * Matches a NVGRE header.
780  */
781 struct rte_flow_item_nvgre {
782         /**
783          * Checksum (1b), undefined (1b), key bit (1b), sequence number (1b),
784          * reserved 0 (9b), version (3b).
785          *
786          * c_k_s_rsvd0_ver must have value 0x2000 according to RFC 7637.
787          */
788         rte_be16_t c_k_s_rsvd0_ver;
789         rte_be16_t protocol; /**< Protocol type (0x6558). */
790         uint8_t tni[3]; /**< Virtual subnet ID. */
791         uint8_t flow_id; /**< Flow ID. */
792 };
793
794 /** Default mask for RTE_FLOW_ITEM_TYPE_NVGRE. */
795 #ifndef __cplusplus
796 static const struct rte_flow_item_nvgre rte_flow_item_nvgre_mask = {
797         .tni = "\xff\xff\xff",
798 };
799 #endif
800
801 /**
802  * RTE_FLOW_ITEM_TYPE_MPLS.
803  *
804  * Matches a MPLS header.
805  */
806 struct rte_flow_item_mpls {
807         /**
808          * Label (20b), TC (3b), Bottom of Stack (1b).
809          */
810         uint8_t label_tc_s[3];
811         uint8_t ttl; /** Time-to-Live. */
812 };
813
814 /** Default mask for RTE_FLOW_ITEM_TYPE_MPLS. */
815 #ifndef __cplusplus
816 static const struct rte_flow_item_mpls rte_flow_item_mpls_mask = {
817         .label_tc_s = "\xff\xff\xf0",
818 };
819 #endif
820
821 /**
822  * RTE_FLOW_ITEM_TYPE_GRE.
823  *
824  * Matches a GRE header.
825  */
826 struct rte_flow_item_gre {
827         /**
828          * Checksum (1b), reserved 0 (12b), version (3b).
829          * Refer to RFC 2784.
830          */
831         rte_be16_t c_rsvd0_ver;
832         rte_be16_t protocol; /**< Protocol type. */
833 };
834
835 /** Default mask for RTE_FLOW_ITEM_TYPE_GRE. */
836 #ifndef __cplusplus
837 static const struct rte_flow_item_gre rte_flow_item_gre_mask = {
838         .protocol = RTE_BE16(0xffff),
839 };
840 #endif
841
842 /**
843  * RTE_FLOW_ITEM_TYPE_FUZZY
844  *
845  * Fuzzy pattern match, expect faster than default.
846  *
847  * This is for device that support fuzzy match option.
848  * Usually a fuzzy match is fast but the cost is accuracy.
849  * i.e. Signature Match only match pattern's hash value, but it is
850  * possible two different patterns have the same hash value.
851  *
852  * Matching accuracy level can be configure by threshold.
853  * Driver can divide the range of threshold and map to different
854  * accuracy levels that device support.
855  *
856  * Threshold 0 means perfect match (no fuzziness), while threshold
857  * 0xffffffff means fuzziest match.
858  */
859 struct rte_flow_item_fuzzy {
860         uint32_t thresh; /**< Accuracy threshold. */
861 };
862
863 /** Default mask for RTE_FLOW_ITEM_TYPE_FUZZY. */
864 #ifndef __cplusplus
865 static const struct rte_flow_item_fuzzy rte_flow_item_fuzzy_mask = {
866         .thresh = 0xffffffff,
867 };
868 #endif
869
870 /**
871  * RTE_FLOW_ITEM_TYPE_GTP.
872  *
873  * Matches a GTPv1 header.
874  */
875 struct rte_flow_item_gtp {
876         /**
877          * Version (3b), protocol type (1b), reserved (1b),
878          * Extension header flag (1b),
879          * Sequence number flag (1b),
880          * N-PDU number flag (1b).
881          */
882         uint8_t v_pt_rsv_flags;
883         uint8_t msg_type; /**< Message type. */
884         rte_be16_t msg_len; /**< Message length. */
885         rte_be32_t teid; /**< Tunnel endpoint identifier. */
886 };
887
888 /** Default mask for RTE_FLOW_ITEM_TYPE_GTP. */
889 #ifndef __cplusplus
890 static const struct rte_flow_item_gtp rte_flow_item_gtp_mask = {
891         .teid = RTE_BE32(0xffffffff),
892 };
893 #endif
894
895 /**
896  * RTE_FLOW_ITEM_TYPE_ESP
897  *
898  * Matches an ESP header.
899  */
900 struct rte_flow_item_esp {
901         struct esp_hdr hdr; /**< ESP header definition. */
902 };
903
904 /** Default mask for RTE_FLOW_ITEM_TYPE_ESP. */
905 #ifndef __cplusplus
906 static const struct rte_flow_item_esp rte_flow_item_esp_mask = {
907         .hdr = {
908                 .spi = 0xffffffff,
909         },
910 };
911 #endif
912
913 /**
914  * RTE_FLOW_ITEM_TYPE_GENEVE.
915  *
916  * Matches a GENEVE header.
917  */
918 struct rte_flow_item_geneve {
919         /**
920          * Version (2b), length of the options fields (6b), OAM packet (1b),
921          * critical options present (1b), reserved 0 (6b).
922          */
923         rte_be16_t ver_opt_len_o_c_rsvd0;
924         rte_be16_t protocol; /**< Protocol type. */
925         uint8_t vni[3]; /**< Virtual Network Identifier. */
926         uint8_t rsvd1; /**< Reserved, normally 0x00. */
927 };
928
929 /** Default mask for RTE_FLOW_ITEM_TYPE_GENEVE. */
930 #ifndef __cplusplus
931 static const struct rte_flow_item_geneve rte_flow_item_geneve_mask = {
932         .vni = "\xff\xff\xff",
933 };
934 #endif
935
936 /**
937  * RTE_FLOW_ITEM_TYPE_VXLAN_GPE (draft-ietf-nvo3-vxlan-gpe-05).
938  *
939  * Matches a VXLAN-GPE header.
940  */
941 struct rte_flow_item_vxlan_gpe {
942         uint8_t flags; /**< Normally 0x0c (I and P flags). */
943         uint8_t rsvd0[2]; /**< Reserved, normally 0x0000. */
944         uint8_t protocol; /**< Protocol type. */
945         uint8_t vni[3]; /**< VXLAN identifier. */
946         uint8_t rsvd1; /**< Reserved, normally 0x00. */
947 };
948
949 /** Default mask for RTE_FLOW_ITEM_TYPE_VXLAN_GPE. */
950 #ifndef __cplusplus
951 static const struct rte_flow_item_vxlan_gpe rte_flow_item_vxlan_gpe_mask = {
952         .vni = "\xff\xff\xff",
953 };
954 #endif
955
956 /**
957  * RTE_FLOW_ITEM_TYPE_ARP_ETH_IPV4
958  *
959  * Matches an ARP header for Ethernet/IPv4.
960  */
961 struct rte_flow_item_arp_eth_ipv4 {
962         rte_be16_t hrd; /**< Hardware type, normally 1. */
963         rte_be16_t pro; /**< Protocol type, normally 0x0800. */
964         uint8_t hln; /**< Hardware address length, normally 6. */
965         uint8_t pln; /**< Protocol address length, normally 4. */
966         rte_be16_t op; /**< Opcode (1 for request, 2 for reply). */
967         struct ether_addr sha; /**< Sender hardware address. */
968         rte_be32_t spa; /**< Sender IPv4 address. */
969         struct ether_addr tha; /**< Target hardware address. */
970         rte_be32_t tpa; /**< Target IPv4 address. */
971 };
972
973 /** Default mask for RTE_FLOW_ITEM_TYPE_ARP_ETH_IPV4. */
974 #ifndef __cplusplus
975 static const struct rte_flow_item_arp_eth_ipv4
976 rte_flow_item_arp_eth_ipv4_mask = {
977         .sha.addr_bytes = "\xff\xff\xff\xff\xff\xff",
978         .spa = RTE_BE32(0xffffffff),
979         .tha.addr_bytes = "\xff\xff\xff\xff\xff\xff",
980         .tpa = RTE_BE32(0xffffffff),
981 };
982 #endif
983
984 /**
985  * RTE_FLOW_ITEM_TYPE_IPV6_EXT
986  *
987  * Matches the presence of any IPv6 extension header.
988  *
989  * Normally preceded by any of:
990  *
991  * - RTE_FLOW_ITEM_TYPE_IPV6
992  * - RTE_FLOW_ITEM_TYPE_IPV6_EXT
993  */
994 struct rte_flow_item_ipv6_ext {
995         uint8_t next_hdr; /**< Next header. */
996 };
997
998 /** Default mask for RTE_FLOW_ITEM_TYPE_IPV6_EXT. */
999 #ifndef __cplusplus
1000 static const
1001 struct rte_flow_item_ipv6_ext rte_flow_item_ipv6_ext_mask = {
1002         .next_hdr = 0xff,
1003 };
1004 #endif
1005
1006 /**
1007  * RTE_FLOW_ITEM_TYPE_ICMP6
1008  *
1009  * Matches any ICMPv6 header.
1010  */
1011 struct rte_flow_item_icmp6 {
1012         uint8_t type; /**< ICMPv6 type. */
1013         uint8_t code; /**< ICMPv6 code. */
1014         uint16_t checksum; /**< ICMPv6 checksum. */
1015 };
1016
1017 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP6. */
1018 #ifndef __cplusplus
1019 static const struct rte_flow_item_icmp6 rte_flow_item_icmp6_mask = {
1020         .type = 0xff,
1021         .code = 0xff,
1022 };
1023 #endif
1024
1025 /**
1026  * RTE_FLOW_ITEM_TYPE_ICMP6_ND_NS
1027  *
1028  * Matches an ICMPv6 neighbor discovery solicitation.
1029  */
1030 struct rte_flow_item_icmp6_nd_ns {
1031         uint8_t type; /**< ICMPv6 type, normally 135. */
1032         uint8_t code; /**< ICMPv6 code, normally 0. */
1033         rte_be16_t checksum; /**< ICMPv6 checksum. */
1034         rte_be32_t reserved; /**< Reserved, normally 0. */
1035         uint8_t target_addr[16]; /**< Target address. */
1036 };
1037
1038 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP6_ND_NS. */
1039 #ifndef __cplusplus
1040 static const
1041 struct rte_flow_item_icmp6_nd_ns rte_flow_item_icmp6_nd_ns_mask = {
1042         .target_addr =
1043                 "\xff\xff\xff\xff\xff\xff\xff\xff"
1044                 "\xff\xff\xff\xff\xff\xff\xff\xff",
1045 };
1046 #endif
1047
1048 /**
1049  * RTE_FLOW_ITEM_TYPE_ICMP6_ND_NA
1050  *
1051  * Matches an ICMPv6 neighbor discovery advertisement.
1052  */
1053 struct rte_flow_item_icmp6_nd_na {
1054         uint8_t type; /**< ICMPv6 type, normally 136. */
1055         uint8_t code; /**< ICMPv6 code, normally 0. */
1056         rte_be16_t checksum; /**< ICMPv6 checksum. */
1057         /**
1058          * Route flag (1b), solicited flag (1b), override flag (1b),
1059          * reserved (29b).
1060          */
1061         rte_be32_t rso_reserved;
1062         uint8_t target_addr[16]; /**< Target address. */
1063 };
1064
1065 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP6_ND_NA. */
1066 #ifndef __cplusplus
1067 static const
1068 struct rte_flow_item_icmp6_nd_na rte_flow_item_icmp6_nd_na_mask = {
1069         .target_addr =
1070                 "\xff\xff\xff\xff\xff\xff\xff\xff"
1071                 "\xff\xff\xff\xff\xff\xff\xff\xff",
1072 };
1073 #endif
1074
1075 /**
1076  * RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT
1077  *
1078  * Matches the presence of any ICMPv6 neighbor discovery option.
1079  *
1080  * Normally preceded by any of:
1081  *
1082  * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_NA
1083  * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_NS
1084  * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT
1085  */
1086 struct rte_flow_item_icmp6_nd_opt {
1087         uint8_t type; /**< ND option type. */
1088         uint8_t length; /**< ND option length. */
1089 };
1090
1091 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT. */
1092 #ifndef __cplusplus
1093 static const struct rte_flow_item_icmp6_nd_opt
1094 rte_flow_item_icmp6_nd_opt_mask = {
1095         .type = 0xff,
1096 };
1097 #endif
1098
1099 /**
1100  * RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT_SLA_ETH
1101  *
1102  * Matches an ICMPv6 neighbor discovery source Ethernet link-layer address
1103  * option.
1104  *
1105  * Normally preceded by any of:
1106  *
1107  * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_NA
1108  * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT
1109  */
1110 struct rte_flow_item_icmp6_nd_opt_sla_eth {
1111         uint8_t type; /**< ND option type, normally 1. */
1112         uint8_t length; /**< ND option length, normally 1. */
1113         struct ether_addr sla; /**< Source Ethernet LLA. */
1114 };
1115
1116 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT_SLA_ETH. */
1117 #ifndef __cplusplus
1118 static const struct rte_flow_item_icmp6_nd_opt_sla_eth
1119 rte_flow_item_icmp6_nd_opt_sla_eth_mask = {
1120         .sla.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1121 };
1122 #endif
1123
1124 /**
1125  * RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT_TLA_ETH
1126  *
1127  * Matches an ICMPv6 neighbor discovery target Ethernet link-layer address
1128  * option.
1129  *
1130  * Normally preceded by any of:
1131  *
1132  * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_NS
1133  * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT
1134  */
1135 struct rte_flow_item_icmp6_nd_opt_tla_eth {
1136         uint8_t type; /**< ND option type, normally 2. */
1137         uint8_t length; /**< ND option length, normally 1. */
1138         struct ether_addr tla; /**< Target Ethernet LLA. */
1139 };
1140
1141 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT_TLA_ETH. */
1142 #ifndef __cplusplus
1143 static const struct rte_flow_item_icmp6_nd_opt_tla_eth
1144 rte_flow_item_icmp6_nd_opt_tla_eth_mask = {
1145         .tla.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1146 };
1147 #endif
1148
1149 /**
1150  * Matching pattern item definition.
1151  *
1152  * A pattern is formed by stacking items starting from the lowest protocol
1153  * layer to match. This stacking restriction does not apply to meta items
1154  * which can be placed anywhere in the stack without affecting the meaning
1155  * of the resulting pattern.
1156  *
1157  * Patterns are terminated by END items.
1158  *
1159  * The spec field should be a valid pointer to a structure of the related
1160  * item type. It may remain unspecified (NULL) in many cases to request
1161  * broad (nonspecific) matching. In such cases, last and mask must also be
1162  * set to NULL.
1163  *
1164  * Optionally, last can point to a structure of the same type to define an
1165  * inclusive range. This is mostly supported by integer and address fields,
1166  * may cause errors otherwise. Fields that do not support ranges must be set
1167  * to 0 or to the same value as the corresponding fields in spec.
1168  *
1169  * Only the fields defined to nonzero values in the default masks (see
1170  * rte_flow_item_{name}_mask constants) are considered relevant by
1171  * default. This can be overridden by providing a mask structure of the
1172  * same type with applicable bits set to one. It can also be used to
1173  * partially filter out specific fields (e.g. as an alternate mean to match
1174  * ranges of IP addresses).
1175  *
1176  * Mask is a simple bit-mask applied before interpreting the contents of
1177  * spec and last, which may yield unexpected results if not used
1178  * carefully. For example, if for an IPv4 address field, spec provides
1179  * 10.1.2.3, last provides 10.3.4.5 and mask provides 255.255.0.0, the
1180  * effective range becomes 10.1.0.0 to 10.3.255.255.
1181  */
1182 struct rte_flow_item {
1183         enum rte_flow_item_type type; /**< Item type. */
1184         const void *spec; /**< Pointer to item specification structure. */
1185         const void *last; /**< Defines an inclusive range (spec to last). */
1186         const void *mask; /**< Bit-mask applied to spec and last. */
1187 };
1188
1189 /**
1190  * Action types.
1191  *
1192  * Each possible action is represented by a type. Some have associated
1193  * configuration structures. Several actions combined in a list can be
1194  * assigned to a flow rule and are performed in order.
1195  *
1196  * They fall in three categories:
1197  *
1198  * - Actions that modify the fate of matching traffic, for instance by
1199  *   dropping or assigning it a specific destination.
1200  *
1201  * - Actions that modify matching traffic contents or its properties. This
1202  *   includes adding/removing encapsulation, encryption, compression and
1203  *   marks.
1204  *
1205  * - Actions related to the flow rule itself, such as updating counters or
1206  *   making it non-terminating.
1207  *
1208  * Flow rules being terminating by default, not specifying any action of the
1209  * fate kind results in undefined behavior. This applies to both ingress and
1210  * egress.
1211  *
1212  * PASSTHRU, when supported, makes a flow rule non-terminating.
1213  */
1214 enum rte_flow_action_type {
1215         /**
1216          * End marker for action lists. Prevents further processing of
1217          * actions, thereby ending the list.
1218          *
1219          * No associated configuration structure.
1220          */
1221         RTE_FLOW_ACTION_TYPE_END,
1222
1223         /**
1224          * Used as a placeholder for convenience. It is ignored and simply
1225          * discarded by PMDs.
1226          *
1227          * No associated configuration structure.
1228          */
1229         RTE_FLOW_ACTION_TYPE_VOID,
1230
1231         /**
1232          * Leaves traffic up for additional processing by subsequent flow
1233          * rules; makes a flow rule non-terminating.
1234          *
1235          * No associated configuration structure.
1236          */
1237         RTE_FLOW_ACTION_TYPE_PASSTHRU,
1238
1239         /**
1240          * Attaches an integer value to packets and sets PKT_RX_FDIR and
1241          * PKT_RX_FDIR_ID mbuf flags.
1242          *
1243          * See struct rte_flow_action_mark.
1244          */
1245         RTE_FLOW_ACTION_TYPE_MARK,
1246
1247         /**
1248          * Flags packets. Similar to MARK without a specific value; only
1249          * sets the PKT_RX_FDIR mbuf flag.
1250          *
1251          * No associated configuration structure.
1252          */
1253         RTE_FLOW_ACTION_TYPE_FLAG,
1254
1255         /**
1256          * Assigns packets to a given queue index.
1257          *
1258          * See struct rte_flow_action_queue.
1259          */
1260         RTE_FLOW_ACTION_TYPE_QUEUE,
1261
1262         /**
1263          * Drops packets.
1264          *
1265          * PASSTHRU overrides this action if both are specified.
1266          *
1267          * No associated configuration structure.
1268          */
1269         RTE_FLOW_ACTION_TYPE_DROP,
1270
1271         /**
1272          * Enables counters for this flow rule.
1273          *
1274          * These counters can be retrieved and reset through rte_flow_query(),
1275          * see struct rte_flow_query_count.
1276          *
1277          * No associated configuration structure.
1278          */
1279         RTE_FLOW_ACTION_TYPE_COUNT,
1280
1281         /**
1282          * Similar to QUEUE, except RSS is additionally performed on packets
1283          * to spread them among several queues according to the provided
1284          * parameters.
1285          *
1286          * See struct rte_flow_action_rss.
1287          */
1288         RTE_FLOW_ACTION_TYPE_RSS,
1289
1290         /**
1291          * Directs matching traffic to the physical function (PF) of the
1292          * current device.
1293          *
1294          * No associated configuration structure.
1295          */
1296         RTE_FLOW_ACTION_TYPE_PF,
1297
1298         /**
1299          * Directs matching traffic to a given virtual function of the
1300          * current device.
1301          *
1302          * See struct rte_flow_action_vf.
1303          */
1304         RTE_FLOW_ACTION_TYPE_VF,
1305
1306         /**
1307          * Directs packets to a given physical port index of the underlying
1308          * device.
1309          *
1310          * See struct rte_flow_action_phy_port.
1311          */
1312         RTE_FLOW_ACTION_TYPE_PHY_PORT,
1313
1314         /**
1315          * Directs matching traffic to a given DPDK port ID.
1316          *
1317          * See struct rte_flow_action_port_id.
1318          */
1319         RTE_FLOW_ACTION_TYPE_PORT_ID,
1320
1321         /**
1322          * Traffic metering and policing (MTR).
1323          *
1324          * See struct rte_flow_action_meter.
1325          * See file rte_mtr.h for MTR object configuration.
1326          */
1327         RTE_FLOW_ACTION_TYPE_METER,
1328
1329         /**
1330          * Redirects packets to security engine of current device for security
1331          * processing as specified by security session.
1332          *
1333          * See struct rte_flow_action_security.
1334          */
1335         RTE_FLOW_ACTION_TYPE_SECURITY
1336 };
1337
1338 /**
1339  * RTE_FLOW_ACTION_TYPE_MARK
1340  *
1341  * Attaches an integer value to packets and sets PKT_RX_FDIR and
1342  * PKT_RX_FDIR_ID mbuf flags.
1343  *
1344  * This value is arbitrary and application-defined. Maximum allowed value
1345  * depends on the underlying implementation. It is returned in the
1346  * hash.fdir.hi mbuf field.
1347  */
1348 struct rte_flow_action_mark {
1349         uint32_t id; /**< Integer value to return with packets. */
1350 };
1351
1352 /**
1353  * RTE_FLOW_ACTION_TYPE_QUEUE
1354  *
1355  * Assign packets to a given queue index.
1356  */
1357 struct rte_flow_action_queue {
1358         uint16_t index; /**< Queue index to use. */
1359 };
1360
1361 /**
1362  * RTE_FLOW_ACTION_TYPE_COUNT (query)
1363  *
1364  * Query structure to retrieve and reset flow rule counters.
1365  */
1366 struct rte_flow_query_count {
1367         uint32_t reset:1; /**< Reset counters after query [in]. */
1368         uint32_t hits_set:1; /**< hits field is set [out]. */
1369         uint32_t bytes_set:1; /**< bytes field is set [out]. */
1370         uint32_t reserved:29; /**< Reserved, must be zero [in, out]. */
1371         uint64_t hits; /**< Number of hits for this rule [out]. */
1372         uint64_t bytes; /**< Number of bytes through this rule [out]. */
1373 };
1374
1375 /**
1376  * RTE_FLOW_ACTION_TYPE_RSS
1377  *
1378  * Similar to QUEUE, except RSS is additionally performed on packets to
1379  * spread them among several queues according to the provided parameters.
1380  *
1381  * Unlike global RSS settings used by other DPDK APIs, unsetting the
1382  * @p types field does not disable RSS in a flow rule. Doing so instead
1383  * requests safe unspecified "best-effort" settings from the underlying PMD,
1384  * which depending on the flow rule, may result in anything ranging from
1385  * empty (single queue) to all-inclusive RSS.
1386  *
1387  * Note: RSS hash result is stored in the hash.rss mbuf field which overlaps
1388  * hash.fdir.lo. Since the MARK action sets the hash.fdir.hi field only,
1389  * both can be requested simultaneously.
1390  */
1391 struct rte_flow_action_rss {
1392         enum rte_eth_hash_function func; /**< RSS hash function to apply. */
1393         /**
1394          * Packet encapsulation level RSS hash @p types apply to.
1395          *
1396          * - @p 0 requests the default behavior. Depending on the packet
1397          *   type, it can mean outermost, innermost, anything in between or
1398          *   even no RSS.
1399          *
1400          *   It basically stands for the innermost encapsulation level RSS
1401          *   can be performed on according to PMD and device capabilities.
1402          *
1403          * - @p 1 requests RSS to be performed on the outermost packet
1404          *   encapsulation level.
1405          *
1406          * - @p 2 and subsequent values request RSS to be performed on the
1407          *   specified inner packet encapsulation level, from outermost to
1408          *   innermost (lower to higher values).
1409          *
1410          * Values other than @p 0 are not necessarily supported.
1411          *
1412          * Requesting a specific RSS level on unrecognized traffic results
1413          * in undefined behavior. For predictable results, it is recommended
1414          * to make the flow rule pattern match packet headers up to the
1415          * requested encapsulation level so that only matching traffic goes
1416          * through.
1417          */
1418         uint32_t level;
1419         uint64_t types; /**< Specific RSS hash types (see ETH_RSS_*). */
1420         uint32_t key_len; /**< Hash key length in bytes. */
1421         uint32_t queue_num; /**< Number of entries in @p queue. */
1422         const uint8_t *key; /**< Hash key. */
1423         const uint16_t *queue; /**< Queue indices to use. */
1424 };
1425
1426 /**
1427  * RTE_FLOW_ACTION_TYPE_VF
1428  *
1429  * Directs matching traffic to a given virtual function of the current
1430  * device.
1431  *
1432  * Packets matched by a VF pattern item can be redirected to their original
1433  * VF ID instead of the specified one. This parameter may not be available
1434  * and is not guaranteed to work properly if the VF part is matched by a
1435  * prior flow rule or if packets are not addressed to a VF in the first
1436  * place.
1437  */
1438 struct rte_flow_action_vf {
1439         uint32_t original:1; /**< Use original VF ID if possible. */
1440         uint32_t reserved:31; /**< Reserved, must be zero. */
1441         uint32_t id; /**< VF ID. */
1442 };
1443
1444 /**
1445  * RTE_FLOW_ACTION_TYPE_PHY_PORT
1446  *
1447  * Directs packets to a given physical port index of the underlying
1448  * device.
1449  *
1450  * @see RTE_FLOW_ITEM_TYPE_PHY_PORT
1451  */
1452 struct rte_flow_action_phy_port {
1453         uint32_t original:1; /**< Use original port index if possible. */
1454         uint32_t reserved:31; /**< Reserved, must be zero. */
1455         uint32_t index; /**< Physical port index. */
1456 };
1457
1458 /**
1459  * RTE_FLOW_ACTION_TYPE_PORT_ID
1460  *
1461  * Directs matching traffic to a given DPDK port ID.
1462  *
1463  * @see RTE_FLOW_ITEM_TYPE_PORT_ID
1464  */
1465 struct rte_flow_action_port_id {
1466         uint32_t original:1; /**< Use original DPDK port ID if possible. */
1467         uint32_t reserved:31; /**< Reserved, must be zero. */
1468         uint32_t id; /**< DPDK port ID. */
1469 };
1470
1471 /**
1472  * RTE_FLOW_ACTION_TYPE_METER
1473  *
1474  * Traffic metering and policing (MTR).
1475  *
1476  * Packets matched by items of this type can be either dropped or passed to the
1477  * next item with their color set by the MTR object.
1478  */
1479 struct rte_flow_action_meter {
1480         uint32_t mtr_id; /**< MTR object ID created with rte_mtr_create(). */
1481 };
1482
1483 /**
1484  * RTE_FLOW_ACTION_TYPE_SECURITY
1485  *
1486  * Perform the security action on flows matched by the pattern items
1487  * according to the configuration of the security session.
1488  *
1489  * This action modifies the payload of matched flows. For INLINE_CRYPTO, the
1490  * security protocol headers and IV are fully provided by the application as
1491  * specified in the flow pattern. The payload of matching packets is
1492  * encrypted on egress, and decrypted and authenticated on ingress.
1493  * For INLINE_PROTOCOL, the security protocol is fully offloaded to HW,
1494  * providing full encapsulation and decapsulation of packets in security
1495  * protocols. The flow pattern specifies both the outer security header fields
1496  * and the inner packet fields. The security session specified in the action
1497  * must match the pattern parameters.
1498  *
1499  * The security session specified in the action must be created on the same
1500  * port as the flow action that is being specified.
1501  *
1502  * The ingress/egress flow attribute should match that specified in the
1503  * security session if the security session supports the definition of the
1504  * direction.
1505  *
1506  * Multiple flows can be configured to use the same security session.
1507  */
1508 struct rte_flow_action_security {
1509         void *security_session; /**< Pointer to security session structure. */
1510 };
1511
1512 /**
1513  * Definition of a single action.
1514  *
1515  * A list of actions is terminated by a END action.
1516  *
1517  * For simple actions without a configuration structure, conf remains NULL.
1518  */
1519 struct rte_flow_action {
1520         enum rte_flow_action_type type; /**< Action type. */
1521         const void *conf; /**< Pointer to action configuration structure. */
1522 };
1523
1524 /**
1525  * Opaque type returned after successfully creating a flow.
1526  *
1527  * This handle can be used to manage and query the related flow (e.g. to
1528  * destroy it or retrieve counters).
1529  */
1530 struct rte_flow;
1531
1532 /**
1533  * Verbose error types.
1534  *
1535  * Most of them provide the type of the object referenced by struct
1536  * rte_flow_error.cause.
1537  */
1538 enum rte_flow_error_type {
1539         RTE_FLOW_ERROR_TYPE_NONE, /**< No error. */
1540         RTE_FLOW_ERROR_TYPE_UNSPECIFIED, /**< Cause unspecified. */
1541         RTE_FLOW_ERROR_TYPE_HANDLE, /**< Flow rule (handle). */
1542         RTE_FLOW_ERROR_TYPE_ATTR_GROUP, /**< Group field. */
1543         RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY, /**< Priority field. */
1544         RTE_FLOW_ERROR_TYPE_ATTR_INGRESS, /**< Ingress field. */
1545         RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, /**< Egress field. */
1546         RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER, /**< Transfer field. */
1547         RTE_FLOW_ERROR_TYPE_ATTR, /**< Attributes structure. */
1548         RTE_FLOW_ERROR_TYPE_ITEM_NUM, /**< Pattern length. */
1549         RTE_FLOW_ERROR_TYPE_ITEM_SPEC, /**< Item specification. */
1550         RTE_FLOW_ERROR_TYPE_ITEM_LAST, /**< Item specification range. */
1551         RTE_FLOW_ERROR_TYPE_ITEM_MASK, /**< Item specification mask. */
1552         RTE_FLOW_ERROR_TYPE_ITEM, /**< Specific pattern item. */
1553         RTE_FLOW_ERROR_TYPE_ACTION_NUM, /**< Number of actions. */
1554         RTE_FLOW_ERROR_TYPE_ACTION_CONF, /**< Action configuration. */
1555         RTE_FLOW_ERROR_TYPE_ACTION, /**< Specific action. */
1556 };
1557
1558 /**
1559  * Verbose error structure definition.
1560  *
1561  * This object is normally allocated by applications and set by PMDs, the
1562  * message points to a constant string which does not need to be freed by
1563  * the application, however its pointer can be considered valid only as long
1564  * as its associated DPDK port remains configured. Closing the underlying
1565  * device or unloading the PMD invalidates it.
1566  *
1567  * Both cause and message may be NULL regardless of the error type.
1568  */
1569 struct rte_flow_error {
1570         enum rte_flow_error_type type; /**< Cause field and error types. */
1571         const void *cause; /**< Object responsible for the error. */
1572         const char *message; /**< Human-readable error message. */
1573 };
1574
1575 /**
1576  * Check whether a flow rule can be created on a given port.
1577  *
1578  * The flow rule is validated for correctness and whether it could be accepted
1579  * by the device given sufficient resources. The rule is checked against the
1580  * current device mode and queue configuration. The flow rule may also
1581  * optionally be validated against existing flow rules and device resources.
1582  * This function has no effect on the target device.
1583  *
1584  * The returned value is guaranteed to remain valid only as long as no
1585  * successful calls to rte_flow_create() or rte_flow_destroy() are made in
1586  * the meantime and no device parameter affecting flow rules in any way are
1587  * modified, due to possible collisions or resource limitations (although in
1588  * such cases EINVAL should not be returned).
1589  *
1590  * @param port_id
1591  *   Port identifier of Ethernet device.
1592  * @param[in] attr
1593  *   Flow rule attributes.
1594  * @param[in] pattern
1595  *   Pattern specification (list terminated by the END pattern item).
1596  * @param[in] actions
1597  *   Associated actions (list terminated by the END action).
1598  * @param[out] error
1599  *   Perform verbose error reporting if not NULL. PMDs initialize this
1600  *   structure in case of error only.
1601  *
1602  * @return
1603  *   0 if flow rule is valid and can be created. A negative errno value
1604  *   otherwise (rte_errno is also set), the following errors are defined:
1605  *
1606  *   -ENOSYS: underlying device does not support this functionality.
1607  *
1608  *   -EIO: underlying device is removed.
1609  *
1610  *   -EINVAL: unknown or invalid rule specification.
1611  *
1612  *   -ENOTSUP: valid but unsupported rule specification (e.g. partial
1613  *   bit-masks are unsupported).
1614  *
1615  *   -EEXIST: collision with an existing rule. Only returned if device
1616  *   supports flow rule collision checking and there was a flow rule
1617  *   collision. Not receiving this return code is no guarantee that creating
1618  *   the rule will not fail due to a collision.
1619  *
1620  *   -ENOMEM: not enough memory to execute the function, or if the device
1621  *   supports resource validation, resource limitation on the device.
1622  *
1623  *   -EBUSY: action cannot be performed due to busy device resources, may
1624  *   succeed if the affected queues or even the entire port are in a stopped
1625  *   state (see rte_eth_dev_rx_queue_stop() and rte_eth_dev_stop()).
1626  */
1627 int
1628 rte_flow_validate(uint16_t port_id,
1629                   const struct rte_flow_attr *attr,
1630                   const struct rte_flow_item pattern[],
1631                   const struct rte_flow_action actions[],
1632                   struct rte_flow_error *error);
1633
1634 /**
1635  * Create a flow rule on a given port.
1636  *
1637  * @param port_id
1638  *   Port identifier of Ethernet device.
1639  * @param[in] attr
1640  *   Flow rule attributes.
1641  * @param[in] pattern
1642  *   Pattern specification (list terminated by the END pattern item).
1643  * @param[in] actions
1644  *   Associated actions (list terminated by the END action).
1645  * @param[out] error
1646  *   Perform verbose error reporting if not NULL. PMDs initialize this
1647  *   structure in case of error only.
1648  *
1649  * @return
1650  *   A valid handle in case of success, NULL otherwise and rte_errno is set
1651  *   to the positive version of one of the error codes defined for
1652  *   rte_flow_validate().
1653  */
1654 struct rte_flow *
1655 rte_flow_create(uint16_t port_id,
1656                 const struct rte_flow_attr *attr,
1657                 const struct rte_flow_item pattern[],
1658                 const struct rte_flow_action actions[],
1659                 struct rte_flow_error *error);
1660
1661 /**
1662  * Destroy a flow rule on a given port.
1663  *
1664  * Failure to destroy a flow rule handle may occur when other flow rules
1665  * depend on it, and destroying it would result in an inconsistent state.
1666  *
1667  * This function is only guaranteed to succeed if handles are destroyed in
1668  * reverse order of their creation.
1669  *
1670  * @param port_id
1671  *   Port identifier of Ethernet device.
1672  * @param flow
1673  *   Flow rule handle to destroy.
1674  * @param[out] error
1675  *   Perform verbose error reporting if not NULL. PMDs initialize this
1676  *   structure in case of error only.
1677  *
1678  * @return
1679  *   0 on success, a negative errno value otherwise and rte_errno is set.
1680  */
1681 int
1682 rte_flow_destroy(uint16_t port_id,
1683                  struct rte_flow *flow,
1684                  struct rte_flow_error *error);
1685
1686 /**
1687  * Destroy all flow rules associated with a port.
1688  *
1689  * In the unlikely event of failure, handles are still considered destroyed
1690  * and no longer valid but the port must be assumed to be in an inconsistent
1691  * state.
1692  *
1693  * @param port_id
1694  *   Port identifier of Ethernet device.
1695  * @param[out] error
1696  *   Perform verbose error reporting if not NULL. PMDs initialize this
1697  *   structure in case of error only.
1698  *
1699  * @return
1700  *   0 on success, a negative errno value otherwise and rte_errno is set.
1701  */
1702 int
1703 rte_flow_flush(uint16_t port_id,
1704                struct rte_flow_error *error);
1705
1706 /**
1707  * Query an existing flow rule.
1708  *
1709  * This function allows retrieving flow-specific data such as counters.
1710  * Data is gathered by special actions which must be present in the flow
1711  * rule definition.
1712  *
1713  * \see RTE_FLOW_ACTION_TYPE_COUNT
1714  *
1715  * @param port_id
1716  *   Port identifier of Ethernet device.
1717  * @param flow
1718  *   Flow rule handle to query.
1719  * @param action
1720  *   Action type to query.
1721  * @param[in, out] data
1722  *   Pointer to storage for the associated query data type.
1723  * @param[out] error
1724  *   Perform verbose error reporting if not NULL. PMDs initialize this
1725  *   structure in case of error only.
1726  *
1727  * @return
1728  *   0 on success, a negative errno value otherwise and rte_errno is set.
1729  */
1730 int
1731 rte_flow_query(uint16_t port_id,
1732                struct rte_flow *flow,
1733                enum rte_flow_action_type action,
1734                void *data,
1735                struct rte_flow_error *error);
1736
1737 /**
1738  * Restrict ingress traffic to the defined flow rules.
1739  *
1740  * Isolated mode guarantees that all ingress traffic comes from defined flow
1741  * rules only (current and future).
1742  *
1743  * Besides making ingress more deterministic, it allows PMDs to safely reuse
1744  * resources otherwise assigned to handle the remaining traffic, such as
1745  * global RSS configuration settings, VLAN filters, MAC address entries,
1746  * legacy filter API rules and so on in order to expand the set of possible
1747  * flow rule types.
1748  *
1749  * Calling this function as soon as possible after device initialization,
1750  * ideally before the first call to rte_eth_dev_configure(), is recommended
1751  * to avoid possible failures due to conflicting settings.
1752  *
1753  * Once effective, leaving isolated mode may not be possible depending on
1754  * PMD implementation.
1755  *
1756  * Additionally, the following functionality has no effect on the underlying
1757  * port and may return errors such as ENOTSUP ("not supported"):
1758  *
1759  * - Toggling promiscuous mode.
1760  * - Toggling allmulticast mode.
1761  * - Configuring MAC addresses.
1762  * - Configuring multicast addresses.
1763  * - Configuring VLAN filters.
1764  * - Configuring Rx filters through the legacy API (e.g. FDIR).
1765  * - Configuring global RSS settings.
1766  *
1767  * @param port_id
1768  *   Port identifier of Ethernet device.
1769  * @param set
1770  *   Nonzero to enter isolated mode, attempt to leave it otherwise.
1771  * @param[out] error
1772  *   Perform verbose error reporting if not NULL. PMDs initialize this
1773  *   structure in case of error only.
1774  *
1775  * @return
1776  *   0 on success, a negative errno value otherwise and rte_errno is set.
1777  */
1778 int
1779 rte_flow_isolate(uint16_t port_id, int set, struct rte_flow_error *error);
1780
1781 /**
1782  * Initialize flow error structure.
1783  *
1784  * @param[out] error
1785  *   Pointer to flow error structure (may be NULL).
1786  * @param code
1787  *   Related error code (rte_errno).
1788  * @param type
1789  *   Cause field and error types.
1790  * @param cause
1791  *   Object responsible for the error.
1792  * @param message
1793  *   Human-readable error message.
1794  *
1795  * @return
1796  *   Negative error code (errno value) and rte_errno is set.
1797  */
1798 int
1799 rte_flow_error_set(struct rte_flow_error *error,
1800                    int code,
1801                    enum rte_flow_error_type type,
1802                    const void *cause,
1803                    const char *message);
1804
1805 /**
1806  * Generic flow representation.
1807  *
1808  * This form is sufficient to describe an rte_flow independently from any
1809  * PMD implementation and allows for replayability and identification.
1810  */
1811 struct rte_flow_desc {
1812         size_t size; /**< Allocated space including data[]. */
1813         struct rte_flow_attr attr; /**< Attributes. */
1814         struct rte_flow_item *items; /**< Items. */
1815         struct rte_flow_action *actions; /**< Actions. */
1816         uint8_t data[]; /**< Storage for items/actions. */
1817 };
1818
1819 /**
1820  * Copy an rte_flow rule description.
1821  *
1822  * @param[in] fd
1823  *   Flow rule description.
1824  * @param[in] len
1825  *   Total size of allocated data for the flow description.
1826  * @param[in] attr
1827  *   Flow rule attributes.
1828  * @param[in] items
1829  *   Pattern specification (list terminated by the END pattern item).
1830  * @param[in] actions
1831  *   Associated actions (list terminated by the END action).
1832  *
1833  * @return
1834  *   If len is greater or equal to the size of the flow, the total size of the
1835  *   flow description and its data.
1836  *   If len is lower than the size of the flow, the number of bytes that would
1837  *   have been written to desc had it been sufficient. Nothing is written.
1838  */
1839 size_t
1840 rte_flow_copy(struct rte_flow_desc *fd, size_t len,
1841               const struct rte_flow_attr *attr,
1842               const struct rte_flow_item *items,
1843               const struct rte_flow_action *actions);
1844
1845 #ifdef __cplusplus
1846 }
1847 #endif
1848
1849 #endif /* RTE_FLOW_H_ */