4 * Copyright 2016 6WIND S.A.
5 * Copyright 2016 Mellanox.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of 6WIND S.A. nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 * RTE generic flow API
41 * This interface provides the ability to program packet matching and
42 * associated actions in hardware through flow rules.
46 #include <rte_ether.h>
52 #include <rte_byteorder.h>
59 * Flow rule attributes.
61 * Priorities are set on two levels: per group and per rule within groups.
63 * Lower values denote higher priority, the highest priority for both levels
64 * is 0, so that a rule with priority 0 in group 8 is always matched after a
65 * rule with priority 8 in group 0.
67 * Although optional, applications are encouraged to group similar rules as
68 * much as possible to fully take advantage of hardware capabilities
69 * (e.g. optimized matching) and work around limitations (e.g. a single
70 * pattern type possibly allowed in a given group).
72 * Group and priority levels are arbitrary and up to the application, they
73 * do not need to be contiguous nor start from 0, however the maximum number
74 * varies between devices and may be affected by existing flow rules.
76 * If a packet is matched by several rules of a given group for a given
77 * priority level, the outcome is undefined. It can take any path, may be
78 * duplicated or even cause unrecoverable errors.
80 * Note that support for more than a single group and priority level is not
83 * Flow rules can apply to inbound and/or outbound traffic (ingress/egress).
85 * Several pattern items and actions are valid and can be used in both
86 * directions. Those valid for only one direction are described as such.
88 * At least one direction must be specified.
90 * Specifying both directions at once for a given rule is not recommended
91 * but may be valid in a few cases (e.g. shared counter).
93 struct rte_flow_attr {
94 uint32_t group; /**< Priority group. */
95 uint32_t priority; /**< Priority level within group. */
96 uint32_t ingress:1; /**< Rule applies to ingress traffic. */
97 uint32_t egress:1; /**< Rule applies to egress traffic. */
98 uint32_t reserved:30; /**< Reserved, must be zero. */
102 * Matching pattern item types.
104 * Pattern items fall in two categories:
106 * - Matching protocol headers and packet data (ANY, RAW, ETH, VLAN, IPV4,
107 * IPV6, ICMP, UDP, TCP, SCTP, VXLAN and so on), usually associated with a
108 * specification structure. These must be stacked in the same order as the
109 * protocol layers to match, starting from the lowest.
111 * - Matching meta-data or affecting pattern processing (END, VOID, INVERT,
112 * PF, VF, PORT and so on), often without a specification structure. Since
113 * they do not match packet contents, these can be specified anywhere
114 * within item lists without affecting others.
116 * See the description of individual types for more information. Those
117 * marked with [META] fall into the second category.
119 enum rte_flow_item_type {
123 * End marker for item lists. Prevents further processing of items,
124 * thereby ending the pattern.
126 * No associated specification structure.
128 RTE_FLOW_ITEM_TYPE_END,
133 * Used as a placeholder for convenience. It is ignored and simply
136 * No associated specification structure.
138 RTE_FLOW_ITEM_TYPE_VOID,
143 * Inverted matching, i.e. process packets that do not match the
146 * No associated specification structure.
148 RTE_FLOW_ITEM_TYPE_INVERT,
151 * Matches any protocol in place of the current layer, a single ANY
152 * may also stand for several protocol layers.
154 * See struct rte_flow_item_any.
156 RTE_FLOW_ITEM_TYPE_ANY,
161 * Matches packets addressed to the physical function of the device.
163 * If the underlying device function differs from the one that would
164 * normally receive the matched traffic, specifying this item
165 * prevents it from reaching that device unless the flow rule
166 * contains a PF action. Packets are not duplicated between device
167 * instances by default.
169 * No associated specification structure.
171 RTE_FLOW_ITEM_TYPE_PF,
176 * Matches packets addressed to a virtual function ID of the device.
178 * If the underlying device function differs from the one that would
179 * normally receive the matched traffic, specifying this item
180 * prevents it from reaching that device unless the flow rule
181 * contains a VF action. Packets are not duplicated between device
182 * instances by default.
184 * See struct rte_flow_item_vf.
186 RTE_FLOW_ITEM_TYPE_VF,
191 * Matches packets coming from the specified physical port of the
194 * The first PORT item overrides the physical port normally
195 * associated with the specified DPDK input port (port_id). This
196 * item can be provided several times to match additional physical
199 * See struct rte_flow_item_port.
201 RTE_FLOW_ITEM_TYPE_PORT,
204 * Matches a byte string of a given length at a given offset.
206 * See struct rte_flow_item_raw.
208 RTE_FLOW_ITEM_TYPE_RAW,
211 * Matches an Ethernet header.
213 * See struct rte_flow_item_eth.
215 RTE_FLOW_ITEM_TYPE_ETH,
218 * Matches an 802.1Q/ad VLAN tag.
220 * See struct rte_flow_item_vlan.
222 RTE_FLOW_ITEM_TYPE_VLAN,
225 * Matches an IPv4 header.
227 * See struct rte_flow_item_ipv4.
229 RTE_FLOW_ITEM_TYPE_IPV4,
232 * Matches an IPv6 header.
234 * See struct rte_flow_item_ipv6.
236 RTE_FLOW_ITEM_TYPE_IPV6,
239 * Matches an ICMP header.
241 * See struct rte_flow_item_icmp.
243 RTE_FLOW_ITEM_TYPE_ICMP,
246 * Matches a UDP header.
248 * See struct rte_flow_item_udp.
250 RTE_FLOW_ITEM_TYPE_UDP,
253 * Matches a TCP header.
255 * See struct rte_flow_item_tcp.
257 RTE_FLOW_ITEM_TYPE_TCP,
260 * Matches a SCTP header.
262 * See struct rte_flow_item_sctp.
264 RTE_FLOW_ITEM_TYPE_SCTP,
267 * Matches a VXLAN header.
269 * See struct rte_flow_item_vxlan.
271 RTE_FLOW_ITEM_TYPE_VXLAN,
274 * Matches a E_TAG header.
276 * See struct rte_flow_item_e_tag.
278 RTE_FLOW_ITEM_TYPE_E_TAG,
281 * Matches a NVGRE header.
283 * See struct rte_flow_item_nvgre.
285 RTE_FLOW_ITEM_TYPE_NVGRE,
288 * Matches a MPLS header.
290 * See struct rte_flow_item_mpls.
292 RTE_FLOW_ITEM_TYPE_MPLS,
295 * Matches a GRE header.
297 * See struct rte_flow_item_gre.
299 RTE_FLOW_ITEM_TYPE_GRE,
304 * Fuzzy pattern match, expect faster than default.
306 * This is for device that support fuzzy matching option.
307 * Usually a fuzzy matching is fast but the cost is accuracy.
309 * See struct rte_flow_item_fuzzy.
311 RTE_FLOW_ITEM_TYPE_FUZZY,
314 * Matches a GTP header.
316 * Configure flow for GTP packets.
318 * See struct rte_flow_item_gtp.
320 RTE_FLOW_ITEM_TYPE_GTP,
323 * Matches a GTP header.
325 * Configure flow for GTP-C packets.
327 * See struct rte_flow_item_gtp.
329 RTE_FLOW_ITEM_TYPE_GTPC,
332 * Matches a GTP header.
334 * Configure flow for GTP-U packets.
336 * See struct rte_flow_item_gtp.
338 RTE_FLOW_ITEM_TYPE_GTPU,
342 * RTE_FLOW_ITEM_TYPE_ANY
344 * Matches any protocol in place of the current layer, a single ANY may also
345 * stand for several protocol layers.
347 * This is usually specified as the first pattern item when looking for a
348 * protocol anywhere in a packet.
350 * A zeroed mask stands for any number of layers.
352 struct rte_flow_item_any {
353 uint32_t num; /**< Number of layers covered. */
356 /** Default mask for RTE_FLOW_ITEM_TYPE_ANY. */
358 static const struct rte_flow_item_any rte_flow_item_any_mask = {
364 * RTE_FLOW_ITEM_TYPE_VF
366 * Matches packets addressed to a virtual function ID of the device.
368 * If the underlying device function differs from the one that would
369 * normally receive the matched traffic, specifying this item prevents it
370 * from reaching that device unless the flow rule contains a VF
371 * action. Packets are not duplicated between device instances by default.
373 * - Likely to return an error or never match any traffic if this causes a
374 * VF device to match traffic addressed to a different VF.
375 * - Can be specified multiple times to match traffic addressed to several
377 * - Can be combined with a PF item to match both PF and VF traffic.
379 * A zeroed mask can be used to match any VF ID.
381 struct rte_flow_item_vf {
382 uint32_t id; /**< Destination VF ID. */
385 /** Default mask for RTE_FLOW_ITEM_TYPE_VF. */
387 static const struct rte_flow_item_vf rte_flow_item_vf_mask = {
393 * RTE_FLOW_ITEM_TYPE_PORT
395 * Matches packets coming from the specified physical port of the underlying
398 * The first PORT item overrides the physical port normally associated with
399 * the specified DPDK input port (port_id). This item can be provided
400 * several times to match additional physical ports.
402 * Note that physical ports are not necessarily tied to DPDK input ports
403 * (port_id) when those are not under DPDK control. Possible values are
404 * specific to each device, they are not necessarily indexed from zero and
405 * may not be contiguous.
407 * As a device property, the list of allowed values as well as the value
408 * associated with a port_id should be retrieved by other means.
410 * A zeroed mask can be used to match any port index.
412 struct rte_flow_item_port {
413 uint32_t index; /**< Physical port index. */
416 /** Default mask for RTE_FLOW_ITEM_TYPE_PORT. */
418 static const struct rte_flow_item_port rte_flow_item_port_mask = {
424 * RTE_FLOW_ITEM_TYPE_RAW
426 * Matches a byte string of a given length at a given offset.
428 * Offset is either absolute (using the start of the packet) or relative to
429 * the end of the previous matched item in the stack, in which case negative
430 * values are allowed.
432 * If search is enabled, offset is used as the starting point. The search
433 * area can be delimited by setting limit to a nonzero value, which is the
434 * maximum number of bytes after offset where the pattern may start.
436 * Matching a zero-length pattern is allowed, doing so resets the relative
437 * offset for subsequent items.
439 * This type does not support ranges (struct rte_flow_item.last).
441 struct rte_flow_item_raw {
442 uint32_t relative:1; /**< Look for pattern after the previous item. */
443 uint32_t search:1; /**< Search pattern from offset (see also limit). */
444 uint32_t reserved:30; /**< Reserved, must be set to zero. */
445 int32_t offset; /**< Absolute or relative offset for pattern. */
446 uint16_t limit; /**< Search area limit for start of pattern. */
447 uint16_t length; /**< Pattern length. */
448 uint8_t pattern[]; /**< Byte string to look for. */
451 /** Default mask for RTE_FLOW_ITEM_TYPE_RAW. */
453 static const struct rte_flow_item_raw rte_flow_item_raw_mask = {
456 .reserved = 0x3fffffff,
457 .offset = 0xffffffff,
464 * RTE_FLOW_ITEM_TYPE_ETH
466 * Matches an Ethernet header.
468 struct rte_flow_item_eth {
469 struct ether_addr dst; /**< Destination MAC. */
470 struct ether_addr src; /**< Source MAC. */
471 rte_be16_t type; /**< EtherType. */
474 /** Default mask for RTE_FLOW_ITEM_TYPE_ETH. */
476 static const struct rte_flow_item_eth rte_flow_item_eth_mask = {
477 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
478 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
479 .type = RTE_BE16(0x0000),
484 * RTE_FLOW_ITEM_TYPE_VLAN
486 * Matches an 802.1Q/ad VLAN tag.
488 * This type normally follows either RTE_FLOW_ITEM_TYPE_ETH or
489 * RTE_FLOW_ITEM_TYPE_VLAN.
491 struct rte_flow_item_vlan {
492 rte_be16_t tpid; /**< Tag protocol identifier. */
493 rte_be16_t tci; /**< Tag control information. */
496 /** Default mask for RTE_FLOW_ITEM_TYPE_VLAN. */
498 static const struct rte_flow_item_vlan rte_flow_item_vlan_mask = {
499 .tpid = RTE_BE16(0x0000),
500 .tci = RTE_BE16(0xffff),
505 * RTE_FLOW_ITEM_TYPE_IPV4
507 * Matches an IPv4 header.
509 * Note: IPv4 options are handled by dedicated pattern items.
511 struct rte_flow_item_ipv4 {
512 struct ipv4_hdr hdr; /**< IPv4 header definition. */
515 /** Default mask for RTE_FLOW_ITEM_TYPE_IPV4. */
517 static const struct rte_flow_item_ipv4 rte_flow_item_ipv4_mask = {
519 .src_addr = RTE_BE32(0xffffffff),
520 .dst_addr = RTE_BE32(0xffffffff),
526 * RTE_FLOW_ITEM_TYPE_IPV6.
528 * Matches an IPv6 header.
530 * Note: IPv6 options are handled by dedicated pattern items.
532 struct rte_flow_item_ipv6 {
533 struct ipv6_hdr hdr; /**< IPv6 header definition. */
536 /** Default mask for RTE_FLOW_ITEM_TYPE_IPV6. */
538 static const struct rte_flow_item_ipv6 rte_flow_item_ipv6_mask = {
541 "\xff\xff\xff\xff\xff\xff\xff\xff"
542 "\xff\xff\xff\xff\xff\xff\xff\xff",
544 "\xff\xff\xff\xff\xff\xff\xff\xff"
545 "\xff\xff\xff\xff\xff\xff\xff\xff",
551 * RTE_FLOW_ITEM_TYPE_ICMP.
553 * Matches an ICMP header.
555 struct rte_flow_item_icmp {
556 struct icmp_hdr hdr; /**< ICMP header definition. */
559 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP. */
561 static const struct rte_flow_item_icmp rte_flow_item_icmp_mask = {
570 * RTE_FLOW_ITEM_TYPE_UDP.
572 * Matches a UDP header.
574 struct rte_flow_item_udp {
575 struct udp_hdr hdr; /**< UDP header definition. */
578 /** Default mask for RTE_FLOW_ITEM_TYPE_UDP. */
580 static const struct rte_flow_item_udp rte_flow_item_udp_mask = {
582 .src_port = RTE_BE16(0xffff),
583 .dst_port = RTE_BE16(0xffff),
589 * RTE_FLOW_ITEM_TYPE_TCP.
591 * Matches a TCP header.
593 struct rte_flow_item_tcp {
594 struct tcp_hdr hdr; /**< TCP header definition. */
597 /** Default mask for RTE_FLOW_ITEM_TYPE_TCP. */
599 static const struct rte_flow_item_tcp rte_flow_item_tcp_mask = {
601 .src_port = RTE_BE16(0xffff),
602 .dst_port = RTE_BE16(0xffff),
608 * RTE_FLOW_ITEM_TYPE_SCTP.
610 * Matches a SCTP header.
612 struct rte_flow_item_sctp {
613 struct sctp_hdr hdr; /**< SCTP header definition. */
616 /** Default mask for RTE_FLOW_ITEM_TYPE_SCTP. */
618 static const struct rte_flow_item_sctp rte_flow_item_sctp_mask = {
620 .src_port = RTE_BE16(0xffff),
621 .dst_port = RTE_BE16(0xffff),
627 * RTE_FLOW_ITEM_TYPE_VXLAN.
629 * Matches a VXLAN header (RFC 7348).
631 struct rte_flow_item_vxlan {
632 uint8_t flags; /**< Normally 0x08 (I flag). */
633 uint8_t rsvd0[3]; /**< Reserved, normally 0x000000. */
634 uint8_t vni[3]; /**< VXLAN identifier. */
635 uint8_t rsvd1; /**< Reserved, normally 0x00. */
638 /** Default mask for RTE_FLOW_ITEM_TYPE_VXLAN. */
640 static const struct rte_flow_item_vxlan rte_flow_item_vxlan_mask = {
641 .vni = "\xff\xff\xff",
646 * RTE_FLOW_ITEM_TYPE_E_TAG.
648 * Matches a E-tag header.
650 struct rte_flow_item_e_tag {
651 rte_be16_t tpid; /**< Tag protocol identifier (0x893F). */
653 * E-Tag control information (E-TCI).
654 * E-PCP (3b), E-DEI (1b), ingress E-CID base (12b).
656 rte_be16_t epcp_edei_in_ecid_b;
657 /** Reserved (2b), GRP (2b), E-CID base (12b). */
658 rte_be16_t rsvd_grp_ecid_b;
659 uint8_t in_ecid_e; /**< Ingress E-CID ext. */
660 uint8_t ecid_e; /**< E-CID ext. */
663 /** Default mask for RTE_FLOW_ITEM_TYPE_E_TAG. */
665 static const struct rte_flow_item_e_tag rte_flow_item_e_tag_mask = {
666 .rsvd_grp_ecid_b = RTE_BE16(0x3fff),
671 * RTE_FLOW_ITEM_TYPE_NVGRE.
673 * Matches a NVGRE header.
675 struct rte_flow_item_nvgre {
677 * Checksum (1b), undefined (1b), key bit (1b), sequence number (1b),
678 * reserved 0 (9b), version (3b).
680 * c_k_s_rsvd0_ver must have value 0x2000 according to RFC 7637.
682 rte_be16_t c_k_s_rsvd0_ver;
683 rte_be16_t protocol; /**< Protocol type (0x6558). */
684 uint8_t tni[3]; /**< Virtual subnet ID. */
685 uint8_t flow_id; /**< Flow ID. */
688 /** Default mask for RTE_FLOW_ITEM_TYPE_NVGRE. */
690 static const struct rte_flow_item_nvgre rte_flow_item_nvgre_mask = {
691 .tni = "\xff\xff\xff",
696 * RTE_FLOW_ITEM_TYPE_MPLS.
698 * Matches a MPLS header.
700 struct rte_flow_item_mpls {
702 * Label (20b), TC (3b), Bottom of Stack (1b).
704 uint8_t label_tc_s[3];
705 uint8_t ttl; /** Time-to-Live. */
708 /** Default mask for RTE_FLOW_ITEM_TYPE_MPLS. */
710 static const struct rte_flow_item_mpls rte_flow_item_mpls_mask = {
711 .label_tc_s = "\xff\xff\xf0",
716 * RTE_FLOW_ITEM_TYPE_GRE.
718 * Matches a GRE header.
720 struct rte_flow_item_gre {
722 * Checksum (1b), reserved 0 (12b), version (3b).
725 rte_be16_t c_rsvd0_ver;
726 rte_be16_t protocol; /**< Protocol type. */
729 /** Default mask for RTE_FLOW_ITEM_TYPE_GRE. */
731 static const struct rte_flow_item_gre rte_flow_item_gre_mask = {
732 .protocol = RTE_BE16(0xffff),
737 * RTE_FLOW_ITEM_TYPE_FUZZY
739 * Fuzzy pattern match, expect faster than default.
741 * This is for device that support fuzzy match option.
742 * Usually a fuzzy match is fast but the cost is accuracy.
743 * i.e. Signature Match only match pattern's hash value, but it is
744 * possible two different patterns have the same hash value.
746 * Matching accuracy level can be configure by threshold.
747 * Driver can divide the range of threshold and map to different
748 * accuracy levels that device support.
750 * Threshold 0 means perfect match (no fuzziness), while threshold
751 * 0xffffffff means fuzziest match.
753 struct rte_flow_item_fuzzy {
754 uint32_t thresh; /**< Accuracy threshold. */
757 /** Default mask for RTE_FLOW_ITEM_TYPE_FUZZY. */
759 static const struct rte_flow_item_fuzzy rte_flow_item_fuzzy_mask = {
760 .thresh = 0xffffffff,
765 * RTE_FLOW_ITEM_TYPE_GTP.
767 * Matches a GTPv1 header.
769 struct rte_flow_item_gtp {
771 * Version (3b), protocol type (1b), reserved (1b),
772 * Extension header flag (1b),
773 * Sequence number flag (1b),
774 * N-PDU number flag (1b).
776 uint8_t v_pt_rsv_flags;
777 uint8_t msg_type; /**< Message type. */
778 rte_be16_t msg_len; /**< Message length. */
779 rte_be32_t teid; /**< Tunnel endpoint identifier. */
782 /** Default mask for RTE_FLOW_ITEM_TYPE_GTP. */
784 static const struct rte_flow_item_gtp rte_flow_item_gtp_mask = {
785 .teid = RTE_BE32(0xffffffff),
790 * Matching pattern item definition.
792 * A pattern is formed by stacking items starting from the lowest protocol
793 * layer to match. This stacking restriction does not apply to meta items
794 * which can be placed anywhere in the stack without affecting the meaning
795 * of the resulting pattern.
797 * Patterns are terminated by END items.
799 * The spec field should be a valid pointer to a structure of the related
800 * item type. It may remain unspecified (NULL) in many cases to request
801 * broad (nonspecific) matching. In such cases, last and mask must also be
804 * Optionally, last can point to a structure of the same type to define an
805 * inclusive range. This is mostly supported by integer and address fields,
806 * may cause errors otherwise. Fields that do not support ranges must be set
807 * to 0 or to the same value as the corresponding fields in spec.
809 * Only the fields defined to nonzero values in the default masks (see
810 * rte_flow_item_{name}_mask constants) are considered relevant by
811 * default. This can be overridden by providing a mask structure of the
812 * same type with applicable bits set to one. It can also be used to
813 * partially filter out specific fields (e.g. as an alternate mean to match
814 * ranges of IP addresses).
816 * Mask is a simple bit-mask applied before interpreting the contents of
817 * spec and last, which may yield unexpected results if not used
818 * carefully. For example, if for an IPv4 address field, spec provides
819 * 10.1.2.3, last provides 10.3.4.5 and mask provides 255.255.0.0, the
820 * effective range becomes 10.1.0.0 to 10.3.255.255.
822 struct rte_flow_item {
823 enum rte_flow_item_type type; /**< Item type. */
824 const void *spec; /**< Pointer to item specification structure. */
825 const void *last; /**< Defines an inclusive range (spec to last). */
826 const void *mask; /**< Bit-mask applied to spec and last. */
832 * Each possible action is represented by a type. Some have associated
833 * configuration structures. Several actions combined in a list can be
834 * affected to a flow rule. That list is not ordered.
836 * They fall in three categories:
838 * - Terminating actions (such as QUEUE, DROP, RSS, PF, VF) that prevent
839 * processing matched packets by subsequent flow rules, unless overridden
842 * - Non terminating actions (PASSTHRU, DUP) that leave matched packets up
843 * for additional processing by subsequent flow rules.
845 * - Other non terminating meta actions that do not affect the fate of
846 * packets (END, VOID, MARK, FLAG, COUNT).
848 * When several actions are combined in a flow rule, they should all have
849 * different types (e.g. dropping a packet twice is not possible).
851 * Only the last action of a given type is taken into account. PMDs still
852 * perform error checking on the entire list.
854 * Note that PASSTHRU is the only action able to override a terminating
857 enum rte_flow_action_type {
861 * End marker for action lists. Prevents further processing of
862 * actions, thereby ending the list.
864 * No associated configuration structure.
866 RTE_FLOW_ACTION_TYPE_END,
871 * Used as a placeholder for convenience. It is ignored and simply
874 * No associated configuration structure.
876 RTE_FLOW_ACTION_TYPE_VOID,
879 * Leaves packets up for additional processing by subsequent flow
880 * rules. This is the default when a rule does not contain a
881 * terminating action, but can be specified to force a rule to
882 * become non-terminating.
884 * No associated configuration structure.
886 RTE_FLOW_ACTION_TYPE_PASSTHRU,
891 * Attaches an integer value to packets and sets PKT_RX_FDIR and
892 * PKT_RX_FDIR_ID mbuf flags.
894 * See struct rte_flow_action_mark.
896 RTE_FLOW_ACTION_TYPE_MARK,
901 * Flags packets. Similar to MARK without a specific value; only
902 * sets the PKT_RX_FDIR mbuf flag.
904 * No associated configuration structure.
906 RTE_FLOW_ACTION_TYPE_FLAG,
909 * Assigns packets to a given queue index.
911 * See struct rte_flow_action_queue.
913 RTE_FLOW_ACTION_TYPE_QUEUE,
918 * PASSTHRU overrides this action if both are specified.
920 * No associated configuration structure.
922 RTE_FLOW_ACTION_TYPE_DROP,
927 * Enables counters for this rule.
929 * These counters can be retrieved and reset through rte_flow_query(),
930 * see struct rte_flow_query_count.
932 * No associated configuration structure.
934 RTE_FLOW_ACTION_TYPE_COUNT,
937 * Duplicates packets to a given queue index.
939 * This is normally combined with QUEUE, however when used alone, it
940 * is actually similar to QUEUE + PASSTHRU.
942 * See struct rte_flow_action_dup.
944 RTE_FLOW_ACTION_TYPE_DUP,
947 * Similar to QUEUE, except RSS is additionally performed on packets
948 * to spread them among several queues according to the provided
951 * See struct rte_flow_action_rss.
953 RTE_FLOW_ACTION_TYPE_RSS,
956 * Redirects packets to the physical function (PF) of the current
959 * No associated configuration structure.
961 RTE_FLOW_ACTION_TYPE_PF,
964 * Redirects packets to the virtual function (VF) of the current
965 * device with the specified ID.
967 * See struct rte_flow_action_vf.
969 RTE_FLOW_ACTION_TYPE_VF,
973 * RTE_FLOW_ACTION_TYPE_MARK
975 * Attaches an integer value to packets and sets PKT_RX_FDIR and
976 * PKT_RX_FDIR_ID mbuf flags.
978 * This value is arbitrary and application-defined. Maximum allowed value
979 * depends on the underlying implementation. It is returned in the
980 * hash.fdir.hi mbuf field.
982 struct rte_flow_action_mark {
983 uint32_t id; /**< Integer value to return with packets. */
987 * RTE_FLOW_ACTION_TYPE_QUEUE
989 * Assign packets to a given queue index.
991 * Terminating by default.
993 struct rte_flow_action_queue {
994 uint16_t index; /**< Queue index to use. */
998 * RTE_FLOW_ACTION_TYPE_COUNT (query)
1000 * Query structure to retrieve and reset flow rule counters.
1002 struct rte_flow_query_count {
1003 uint32_t reset:1; /**< Reset counters after query [in]. */
1004 uint32_t hits_set:1; /**< hits field is set [out]. */
1005 uint32_t bytes_set:1; /**< bytes field is set [out]. */
1006 uint32_t reserved:29; /**< Reserved, must be zero [in, out]. */
1007 uint64_t hits; /**< Number of hits for this rule [out]. */
1008 uint64_t bytes; /**< Number of bytes through this rule [out]. */
1012 * RTE_FLOW_ACTION_TYPE_DUP
1014 * Duplicates packets to a given queue index.
1016 * This is normally combined with QUEUE, however when used alone, it is
1017 * actually similar to QUEUE + PASSTHRU.
1019 * Non-terminating by default.
1021 struct rte_flow_action_dup {
1022 uint16_t index; /**< Queue index to duplicate packets to. */
1026 * RTE_FLOW_ACTION_TYPE_RSS
1028 * Similar to QUEUE, except RSS is additionally performed on packets to
1029 * spread them among several queues according to the provided parameters.
1031 * Note: RSS hash result is stored in the hash.rss mbuf field which overlaps
1032 * hash.fdir.lo. Since the MARK action sets the hash.fdir.hi field only,
1033 * both can be requested simultaneously.
1035 * Terminating by default.
1037 struct rte_flow_action_rss {
1038 const struct rte_eth_rss_conf *rss_conf; /**< RSS parameters. */
1039 uint16_t num; /**< Number of entries in queue[]. */
1040 uint16_t queue[]; /**< Queues indices to use. */
1044 * RTE_FLOW_ACTION_TYPE_VF
1046 * Redirects packets to a virtual function (VF) of the current device.
1048 * Packets matched by a VF pattern item can be redirected to their original
1049 * VF ID instead of the specified one. This parameter may not be available
1050 * and is not guaranteed to work properly if the VF part is matched by a
1051 * prior flow rule or if packets are not addressed to a VF in the first
1054 * Terminating by default.
1056 struct rte_flow_action_vf {
1057 uint32_t original:1; /**< Use original VF ID if possible. */
1058 uint32_t reserved:31; /**< Reserved, must be zero. */
1059 uint32_t id; /**< VF ID to redirect packets to. */
1063 * Definition of a single action.
1065 * A list of actions is terminated by a END action.
1067 * For simple actions without a configuration structure, conf remains NULL.
1069 struct rte_flow_action {
1070 enum rte_flow_action_type type; /**< Action type. */
1071 const void *conf; /**< Pointer to action configuration structure. */
1075 * Opaque type returned after successfully creating a flow.
1077 * This handle can be used to manage and query the related flow (e.g. to
1078 * destroy it or retrieve counters).
1083 * Verbose error types.
1085 * Most of them provide the type of the object referenced by struct
1086 * rte_flow_error.cause.
1088 enum rte_flow_error_type {
1089 RTE_FLOW_ERROR_TYPE_NONE, /**< No error. */
1090 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, /**< Cause unspecified. */
1091 RTE_FLOW_ERROR_TYPE_HANDLE, /**< Flow rule (handle). */
1092 RTE_FLOW_ERROR_TYPE_ATTR_GROUP, /**< Group field. */
1093 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY, /**< Priority field. */
1094 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS, /**< Ingress field. */
1095 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, /**< Egress field. */
1096 RTE_FLOW_ERROR_TYPE_ATTR, /**< Attributes structure. */
1097 RTE_FLOW_ERROR_TYPE_ITEM_NUM, /**< Pattern length. */
1098 RTE_FLOW_ERROR_TYPE_ITEM, /**< Specific pattern item. */
1099 RTE_FLOW_ERROR_TYPE_ACTION_NUM, /**< Number of actions. */
1100 RTE_FLOW_ERROR_TYPE_ACTION, /**< Specific action. */
1104 * Verbose error structure definition.
1106 * This object is normally allocated by applications and set by PMDs, the
1107 * message points to a constant string which does not need to be freed by
1108 * the application, however its pointer can be considered valid only as long
1109 * as its associated DPDK port remains configured. Closing the underlying
1110 * device or unloading the PMD invalidates it.
1112 * Both cause and message may be NULL regardless of the error type.
1114 struct rte_flow_error {
1115 enum rte_flow_error_type type; /**< Cause field and error types. */
1116 const void *cause; /**< Object responsible for the error. */
1117 const char *message; /**< Human-readable error message. */
1121 * Check whether a flow rule can be created on a given port.
1123 * The flow rule is validated for correctness and whether it could be accepted
1124 * by the device given sufficient resources. The rule is checked against the
1125 * current device mode and queue configuration. The flow rule may also
1126 * optionally be validated against existing flow rules and device resources.
1127 * This function has no effect on the target device.
1129 * The returned value is guaranteed to remain valid only as long as no
1130 * successful calls to rte_flow_create() or rte_flow_destroy() are made in
1131 * the meantime and no device parameter affecting flow rules in any way are
1132 * modified, due to possible collisions or resource limitations (although in
1133 * such cases EINVAL should not be returned).
1136 * Port identifier of Ethernet device.
1138 * Flow rule attributes.
1139 * @param[in] pattern
1140 * Pattern specification (list terminated by the END pattern item).
1141 * @param[in] actions
1142 * Associated actions (list terminated by the END action).
1144 * Perform verbose error reporting if not NULL. PMDs initialize this
1145 * structure in case of error only.
1148 * 0 if flow rule is valid and can be created. A negative errno value
1149 * otherwise (rte_errno is also set), the following errors are defined:
1151 * -ENOSYS: underlying device does not support this functionality.
1153 * -EINVAL: unknown or invalid rule specification.
1155 * -ENOTSUP: valid but unsupported rule specification (e.g. partial
1156 * bit-masks are unsupported).
1158 * -EEXIST: collision with an existing rule. Only returned if device
1159 * supports flow rule collision checking and there was a flow rule
1160 * collision. Not receiving this return code is no guarantee that creating
1161 * the rule will not fail due to a collision.
1163 * -ENOMEM: not enough memory to execute the function, or if the device
1164 * supports resource validation, resource limitation on the device.
1166 * -EBUSY: action cannot be performed due to busy device resources, may
1167 * succeed if the affected queues or even the entire port are in a stopped
1168 * state (see rte_eth_dev_rx_queue_stop() and rte_eth_dev_stop()).
1171 rte_flow_validate(uint16_t port_id,
1172 const struct rte_flow_attr *attr,
1173 const struct rte_flow_item pattern[],
1174 const struct rte_flow_action actions[],
1175 struct rte_flow_error *error);
1178 * Create a flow rule on a given port.
1181 * Port identifier of Ethernet device.
1183 * Flow rule attributes.
1184 * @param[in] pattern
1185 * Pattern specification (list terminated by the END pattern item).
1186 * @param[in] actions
1187 * Associated actions (list terminated by the END action).
1189 * Perform verbose error reporting if not NULL. PMDs initialize this
1190 * structure in case of error only.
1193 * A valid handle in case of success, NULL otherwise and rte_errno is set
1194 * to the positive version of one of the error codes defined for
1195 * rte_flow_validate().
1198 rte_flow_create(uint16_t port_id,
1199 const struct rte_flow_attr *attr,
1200 const struct rte_flow_item pattern[],
1201 const struct rte_flow_action actions[],
1202 struct rte_flow_error *error);
1205 * Destroy a flow rule on a given port.
1207 * Failure to destroy a flow rule handle may occur when other flow rules
1208 * depend on it, and destroying it would result in an inconsistent state.
1210 * This function is only guaranteed to succeed if handles are destroyed in
1211 * reverse order of their creation.
1214 * Port identifier of Ethernet device.
1216 * Flow rule handle to destroy.
1218 * Perform verbose error reporting if not NULL. PMDs initialize this
1219 * structure in case of error only.
1222 * 0 on success, a negative errno value otherwise and rte_errno is set.
1225 rte_flow_destroy(uint16_t port_id,
1226 struct rte_flow *flow,
1227 struct rte_flow_error *error);
1230 * Destroy all flow rules associated with a port.
1232 * In the unlikely event of failure, handles are still considered destroyed
1233 * and no longer valid but the port must be assumed to be in an inconsistent
1237 * Port identifier of Ethernet device.
1239 * Perform verbose error reporting if not NULL. PMDs initialize this
1240 * structure in case of error only.
1243 * 0 on success, a negative errno value otherwise and rte_errno is set.
1246 rte_flow_flush(uint16_t port_id,
1247 struct rte_flow_error *error);
1250 * Query an existing flow rule.
1252 * This function allows retrieving flow-specific data such as counters.
1253 * Data is gathered by special actions which must be present in the flow
1256 * \see RTE_FLOW_ACTION_TYPE_COUNT
1259 * Port identifier of Ethernet device.
1261 * Flow rule handle to query.
1263 * Action type to query.
1264 * @param[in, out] data
1265 * Pointer to storage for the associated query data type.
1267 * Perform verbose error reporting if not NULL. PMDs initialize this
1268 * structure in case of error only.
1271 * 0 on success, a negative errno value otherwise and rte_errno is set.
1274 rte_flow_query(uint16_t port_id,
1275 struct rte_flow *flow,
1276 enum rte_flow_action_type action,
1278 struct rte_flow_error *error);
1281 * Restrict ingress traffic to the defined flow rules.
1283 * Isolated mode guarantees that all ingress traffic comes from defined flow
1284 * rules only (current and future).
1286 * Besides making ingress more deterministic, it allows PMDs to safely reuse
1287 * resources otherwise assigned to handle the remaining traffic, such as
1288 * global RSS configuration settings, VLAN filters, MAC address entries,
1289 * legacy filter API rules and so on in order to expand the set of possible
1292 * Calling this function as soon as possible after device initialization,
1293 * ideally before the first call to rte_eth_dev_configure(), is recommended
1294 * to avoid possible failures due to conflicting settings.
1296 * Once effective, leaving isolated mode may not be possible depending on
1297 * PMD implementation.
1299 * Additionally, the following functionality has no effect on the underlying
1300 * port and may return errors such as ENOTSUP ("not supported"):
1302 * - Toggling promiscuous mode.
1303 * - Toggling allmulticast mode.
1304 * - Configuring MAC addresses.
1305 * - Configuring multicast addresses.
1306 * - Configuring VLAN filters.
1307 * - Configuring Rx filters through the legacy API (e.g. FDIR).
1308 * - Configuring global RSS settings.
1311 * Port identifier of Ethernet device.
1313 * Nonzero to enter isolated mode, attempt to leave it otherwise.
1315 * Perform verbose error reporting if not NULL. PMDs initialize this
1316 * structure in case of error only.
1319 * 0 on success, a negative errno value otherwise and rte_errno is set.
1322 rte_flow_isolate(uint16_t port_id, int set, struct rte_flow_error *error);
1325 * Generic flow representation.
1327 * This form is sufficient to describe an rte_flow independently from any
1328 * PMD implementation and allows for replayability and identification.
1330 struct rte_flow_desc {
1331 size_t size; /**< Allocated space including data[]. */
1332 struct rte_flow_attr attr; /**< Attributes. */
1333 struct rte_flow_item *items; /**< Items. */
1334 struct rte_flow_action *actions; /**< Actions. */
1335 uint8_t data[]; /**< Storage for items/actions. */
1339 * Copy an rte_flow rule description.
1342 * Flow rule description.
1344 * Total size of allocated data for the flow description.
1346 * Flow rule attributes.
1348 * Pattern specification (list terminated by the END pattern item).
1349 * @param[in] actions
1350 * Associated actions (list terminated by the END action).
1353 * If len is greater or equal to the size of the flow, the total size of the
1354 * flow description and its data.
1355 * If len is lower than the size of the flow, the number of bytes that would
1356 * have been written to desc had it been sufficient. Nothing is written.
1359 rte_flow_copy(struct rte_flow_desc *fd, size_t len,
1360 const struct rte_flow_attr *attr,
1361 const struct rte_flow_item *items,
1362 const struct rte_flow_action *actions);
1368 #endif /* RTE_FLOW_H_ */