1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2016 6WIND S.A.
3 * Copyright 2016 Mellanox Technologies, Ltd
11 * RTE generic flow API
13 * This interface provides the ability to program packet matching and
14 * associated actions in hardware through flow rules.
21 #include <rte_ether.h>
22 #include <rte_eth_ctrl.h>
28 #include <rte_byteorder.h>
36 * Flow rule attributes.
38 * Priorities are set on two levels: per group and per rule within groups.
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.
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).
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.
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.
57 * Note that support for more than a single group and priority level is not
60 * Flow rules can apply to inbound and/or outbound traffic (ingress/egress).
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.
65 * At least one direction must be specified.
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).
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. */
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.
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.
86 * It complements the behavior of some pattern items such as
87 * RTE_FLOW_ITEM_TYPE_PHY_PORT and is meaningless without them.
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.
94 uint32_t reserved:29; /**< Reserved, must be zero. */
98 * Matching pattern item types.
100 * Pattern items fall in two categories:
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.
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.
110 * See the description of individual types for more information. Those
111 * marked with [META] fall into the second category.
113 enum rte_flow_item_type {
117 * End marker for item lists. Prevents further processing of items,
118 * thereby ending the pattern.
120 * No associated specification structure.
122 RTE_FLOW_ITEM_TYPE_END,
127 * Used as a placeholder for convenience. It is ignored and simply
130 * No associated specification structure.
132 RTE_FLOW_ITEM_TYPE_VOID,
137 * Inverted matching, i.e. process packets that do not match the
140 * No associated specification structure.
142 RTE_FLOW_ITEM_TYPE_INVERT,
145 * Matches any protocol in place of the current layer, a single ANY
146 * may also stand for several protocol layers.
148 * See struct rte_flow_item_any.
150 RTE_FLOW_ITEM_TYPE_ANY,
155 * Matches traffic originating from (ingress) or going to (egress)
156 * the physical function of the current device.
158 * No associated specification structure.
160 RTE_FLOW_ITEM_TYPE_PF,
165 * Matches traffic originating from (ingress) or going to (egress) a
166 * given virtual function of the current device.
168 * See struct rte_flow_item_vf.
170 RTE_FLOW_ITEM_TYPE_VF,
175 * Matches traffic originating from (ingress) or going to (egress) a
176 * physical port of the underlying device.
178 * See struct rte_flow_item_phy_port.
180 RTE_FLOW_ITEM_TYPE_PHY_PORT,
183 * Matches a byte string of a given length at a given offset.
185 * See struct rte_flow_item_raw.
187 RTE_FLOW_ITEM_TYPE_RAW,
190 * Matches an Ethernet header.
192 * See struct rte_flow_item_eth.
194 RTE_FLOW_ITEM_TYPE_ETH,
197 * Matches an 802.1Q/ad VLAN tag.
199 * See struct rte_flow_item_vlan.
201 RTE_FLOW_ITEM_TYPE_VLAN,
204 * Matches an IPv4 header.
206 * See struct rte_flow_item_ipv4.
208 RTE_FLOW_ITEM_TYPE_IPV4,
211 * Matches an IPv6 header.
213 * See struct rte_flow_item_ipv6.
215 RTE_FLOW_ITEM_TYPE_IPV6,
218 * Matches an ICMP header.
220 * See struct rte_flow_item_icmp.
222 RTE_FLOW_ITEM_TYPE_ICMP,
225 * Matches a UDP header.
227 * See struct rte_flow_item_udp.
229 RTE_FLOW_ITEM_TYPE_UDP,
232 * Matches a TCP header.
234 * See struct rte_flow_item_tcp.
236 RTE_FLOW_ITEM_TYPE_TCP,
239 * Matches a SCTP header.
241 * See struct rte_flow_item_sctp.
243 RTE_FLOW_ITEM_TYPE_SCTP,
246 * Matches a VXLAN header.
248 * See struct rte_flow_item_vxlan.
250 RTE_FLOW_ITEM_TYPE_VXLAN,
253 * Matches a E_TAG header.
255 * See struct rte_flow_item_e_tag.
257 RTE_FLOW_ITEM_TYPE_E_TAG,
260 * Matches a NVGRE header.
262 * See struct rte_flow_item_nvgre.
264 RTE_FLOW_ITEM_TYPE_NVGRE,
267 * Matches a MPLS header.
269 * See struct rte_flow_item_mpls.
271 RTE_FLOW_ITEM_TYPE_MPLS,
274 * Matches a GRE header.
276 * See struct rte_flow_item_gre.
278 RTE_FLOW_ITEM_TYPE_GRE,
283 * Fuzzy pattern match, expect faster than default.
285 * This is for device that support fuzzy matching option.
286 * Usually a fuzzy matching is fast but the cost is accuracy.
288 * See struct rte_flow_item_fuzzy.
290 RTE_FLOW_ITEM_TYPE_FUZZY,
293 * Matches a GTP header.
295 * Configure flow for GTP packets.
297 * See struct rte_flow_item_gtp.
299 RTE_FLOW_ITEM_TYPE_GTP,
302 * Matches a GTP header.
304 * Configure flow for GTP-C packets.
306 * See struct rte_flow_item_gtp.
308 RTE_FLOW_ITEM_TYPE_GTPC,
311 * Matches a GTP header.
313 * Configure flow for GTP-U packets.
315 * See struct rte_flow_item_gtp.
317 RTE_FLOW_ITEM_TYPE_GTPU,
320 * Matches a ESP header.
322 * See struct rte_flow_item_esp.
324 RTE_FLOW_ITEM_TYPE_ESP,
327 * Matches a GENEVE header.
329 * See struct rte_flow_item_geneve.
331 RTE_FLOW_ITEM_TYPE_GENEVE,
335 * RTE_FLOW_ITEM_TYPE_ANY
337 * Matches any protocol in place of the current layer, a single ANY may also
338 * stand for several protocol layers.
340 * This is usually specified as the first pattern item when looking for a
341 * protocol anywhere in a packet.
343 * A zeroed mask stands for any number of layers.
345 struct rte_flow_item_any {
346 uint32_t num; /**< Number of layers covered. */
349 /** Default mask for RTE_FLOW_ITEM_TYPE_ANY. */
351 static const struct rte_flow_item_any rte_flow_item_any_mask = {
357 * RTE_FLOW_ITEM_TYPE_VF
359 * Matches traffic originating from (ingress) or going to (egress) a given
360 * virtual function of the current device.
362 * If supported, should work even if the virtual function is not managed by
363 * the application and thus not associated with a DPDK port ID.
365 * Note this pattern item does not match VF representors traffic which, as
366 * separate entities, should be addressed through their own DPDK port IDs.
368 * - Can be specified multiple times to match traffic addressed to several
370 * - Can be combined with a PF item to match both PF and VF traffic.
372 * A zeroed mask can be used to match any VF ID.
374 struct rte_flow_item_vf {
375 uint32_t id; /**< VF ID. */
378 /** Default mask for RTE_FLOW_ITEM_TYPE_VF. */
380 static const struct rte_flow_item_vf rte_flow_item_vf_mask = {
386 * RTE_FLOW_ITEM_TYPE_PHY_PORT
388 * Matches traffic originating from (ingress) or going to (egress) a
389 * physical port of the underlying device.
391 * The first PHY_PORT item overrides the physical port normally associated
392 * with the specified DPDK input port (port_id). This item can be provided
393 * several times to match additional physical ports.
395 * Note that physical ports are not necessarily tied to DPDK input ports
396 * (port_id) when those are not under DPDK control. Possible values are
397 * specific to each device, they are not necessarily indexed from zero and
398 * may not be contiguous.
400 * As a device property, the list of allowed values as well as the value
401 * associated with a port_id should be retrieved by other means.
403 * A zeroed mask can be used to match any port index.
405 struct rte_flow_item_phy_port {
406 uint32_t index; /**< Physical port index. */
409 /** Default mask for RTE_FLOW_ITEM_TYPE_PHY_PORT. */
411 static const struct rte_flow_item_phy_port rte_flow_item_phy_port_mask = {
417 * RTE_FLOW_ITEM_TYPE_RAW
419 * Matches a byte string of a given length at a given offset.
421 * Offset is either absolute (using the start of the packet) or relative to
422 * the end of the previous matched item in the stack, in which case negative
423 * values are allowed.
425 * If search is enabled, offset is used as the starting point. The search
426 * area can be delimited by setting limit to a nonzero value, which is the
427 * maximum number of bytes after offset where the pattern may start.
429 * Matching a zero-length pattern is allowed, doing so resets the relative
430 * offset for subsequent items.
432 * This type does not support ranges (struct rte_flow_item.last).
434 struct rte_flow_item_raw {
435 uint32_t relative:1; /**< Look for pattern after the previous item. */
436 uint32_t search:1; /**< Search pattern from offset (see also limit). */
437 uint32_t reserved:30; /**< Reserved, must be set to zero. */
438 int32_t offset; /**< Absolute or relative offset for pattern. */
439 uint16_t limit; /**< Search area limit for start of pattern. */
440 uint16_t length; /**< Pattern length. */
441 const uint8_t *pattern; /**< Byte string to look for. */
444 /** Default mask for RTE_FLOW_ITEM_TYPE_RAW. */
446 static const struct rte_flow_item_raw rte_flow_item_raw_mask = {
449 .reserved = 0x3fffffff,
450 .offset = 0xffffffff,
458 * RTE_FLOW_ITEM_TYPE_ETH
460 * Matches an Ethernet header.
462 * The @p type field either stands for "EtherType" or "TPID" when followed
463 * by so-called layer 2.5 pattern items such as RTE_FLOW_ITEM_TYPE_VLAN. In
464 * the latter case, @p type refers to that of the outer header, with the
465 * inner EtherType/TPID provided by the subsequent pattern item. This is the
466 * same order as on the wire.
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 or TPID. */
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 * The corresponding standard outer EtherType (TPID) values are
489 * ETHER_TYPE_VLAN or ETHER_TYPE_QINQ. It can be overridden by the preceding
492 struct rte_flow_item_vlan {
493 rte_be16_t tci; /**< Tag control information. */
494 rte_be16_t inner_type; /**< Inner EtherType or TPID. */
497 /** Default mask for RTE_FLOW_ITEM_TYPE_VLAN. */
499 static const struct rte_flow_item_vlan rte_flow_item_vlan_mask = {
500 .tci = RTE_BE16(0x0fff),
501 .inner_type = RTE_BE16(0x0000),
506 * RTE_FLOW_ITEM_TYPE_IPV4
508 * Matches an IPv4 header.
510 * Note: IPv4 options are handled by dedicated pattern items.
512 struct rte_flow_item_ipv4 {
513 struct ipv4_hdr hdr; /**< IPv4 header definition. */
516 /** Default mask for RTE_FLOW_ITEM_TYPE_IPV4. */
518 static const struct rte_flow_item_ipv4 rte_flow_item_ipv4_mask = {
520 .src_addr = RTE_BE32(0xffffffff),
521 .dst_addr = RTE_BE32(0xffffffff),
527 * RTE_FLOW_ITEM_TYPE_IPV6.
529 * Matches an IPv6 header.
531 * Note: IPv6 options are handled by dedicated pattern items.
533 struct rte_flow_item_ipv6 {
534 struct ipv6_hdr hdr; /**< IPv6 header definition. */
537 /** Default mask for RTE_FLOW_ITEM_TYPE_IPV6. */
539 static const struct rte_flow_item_ipv6 rte_flow_item_ipv6_mask = {
542 "\xff\xff\xff\xff\xff\xff\xff\xff"
543 "\xff\xff\xff\xff\xff\xff\xff\xff",
545 "\xff\xff\xff\xff\xff\xff\xff\xff"
546 "\xff\xff\xff\xff\xff\xff\xff\xff",
552 * RTE_FLOW_ITEM_TYPE_ICMP.
554 * Matches an ICMP header.
556 struct rte_flow_item_icmp {
557 struct icmp_hdr hdr; /**< ICMP header definition. */
560 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP. */
562 static const struct rte_flow_item_icmp rte_flow_item_icmp_mask = {
571 * RTE_FLOW_ITEM_TYPE_UDP.
573 * Matches a UDP header.
575 struct rte_flow_item_udp {
576 struct udp_hdr hdr; /**< UDP header definition. */
579 /** Default mask for RTE_FLOW_ITEM_TYPE_UDP. */
581 static const struct rte_flow_item_udp rte_flow_item_udp_mask = {
583 .src_port = RTE_BE16(0xffff),
584 .dst_port = RTE_BE16(0xffff),
590 * RTE_FLOW_ITEM_TYPE_TCP.
592 * Matches a TCP header.
594 struct rte_flow_item_tcp {
595 struct tcp_hdr hdr; /**< TCP header definition. */
598 /** Default mask for RTE_FLOW_ITEM_TYPE_TCP. */
600 static const struct rte_flow_item_tcp rte_flow_item_tcp_mask = {
602 .src_port = RTE_BE16(0xffff),
603 .dst_port = RTE_BE16(0xffff),
609 * RTE_FLOW_ITEM_TYPE_SCTP.
611 * Matches a SCTP header.
613 struct rte_flow_item_sctp {
614 struct sctp_hdr hdr; /**< SCTP header definition. */
617 /** Default mask for RTE_FLOW_ITEM_TYPE_SCTP. */
619 static const struct rte_flow_item_sctp rte_flow_item_sctp_mask = {
621 .src_port = RTE_BE16(0xffff),
622 .dst_port = RTE_BE16(0xffff),
628 * RTE_FLOW_ITEM_TYPE_VXLAN.
630 * Matches a VXLAN header (RFC 7348).
632 struct rte_flow_item_vxlan {
633 uint8_t flags; /**< Normally 0x08 (I flag). */
634 uint8_t rsvd0[3]; /**< Reserved, normally 0x000000. */
635 uint8_t vni[3]; /**< VXLAN identifier. */
636 uint8_t rsvd1; /**< Reserved, normally 0x00. */
639 /** Default mask for RTE_FLOW_ITEM_TYPE_VXLAN. */
641 static const struct rte_flow_item_vxlan rte_flow_item_vxlan_mask = {
642 .vni = "\xff\xff\xff",
647 * RTE_FLOW_ITEM_TYPE_E_TAG.
649 * Matches a E-tag header.
651 * The corresponding standard outer EtherType (TPID) value is
652 * ETHER_TYPE_ETAG. It can be overridden by the preceding pattern item.
654 struct rte_flow_item_e_tag {
656 * E-Tag control information (E-TCI).
657 * E-PCP (3b), E-DEI (1b), ingress E-CID base (12b).
659 rte_be16_t epcp_edei_in_ecid_b;
660 /** Reserved (2b), GRP (2b), E-CID base (12b). */
661 rte_be16_t rsvd_grp_ecid_b;
662 uint8_t in_ecid_e; /**< Ingress E-CID ext. */
663 uint8_t ecid_e; /**< E-CID ext. */
664 rte_be16_t inner_type; /**< Inner EtherType or TPID. */
667 /** Default mask for RTE_FLOW_ITEM_TYPE_E_TAG. */
669 static const struct rte_flow_item_e_tag rte_flow_item_e_tag_mask = {
670 .rsvd_grp_ecid_b = RTE_BE16(0x3fff),
675 * RTE_FLOW_ITEM_TYPE_NVGRE.
677 * Matches a NVGRE header.
679 struct rte_flow_item_nvgre {
681 * Checksum (1b), undefined (1b), key bit (1b), sequence number (1b),
682 * reserved 0 (9b), version (3b).
684 * c_k_s_rsvd0_ver must have value 0x2000 according to RFC 7637.
686 rte_be16_t c_k_s_rsvd0_ver;
687 rte_be16_t protocol; /**< Protocol type (0x6558). */
688 uint8_t tni[3]; /**< Virtual subnet ID. */
689 uint8_t flow_id; /**< Flow ID. */
692 /** Default mask for RTE_FLOW_ITEM_TYPE_NVGRE. */
694 static const struct rte_flow_item_nvgre rte_flow_item_nvgre_mask = {
695 .tni = "\xff\xff\xff",
700 * RTE_FLOW_ITEM_TYPE_MPLS.
702 * Matches a MPLS header.
704 struct rte_flow_item_mpls {
706 * Label (20b), TC (3b), Bottom of Stack (1b).
708 uint8_t label_tc_s[3];
709 uint8_t ttl; /** Time-to-Live. */
712 /** Default mask for RTE_FLOW_ITEM_TYPE_MPLS. */
714 static const struct rte_flow_item_mpls rte_flow_item_mpls_mask = {
715 .label_tc_s = "\xff\xff\xf0",
720 * RTE_FLOW_ITEM_TYPE_GRE.
722 * Matches a GRE header.
724 struct rte_flow_item_gre {
726 * Checksum (1b), reserved 0 (12b), version (3b).
729 rte_be16_t c_rsvd0_ver;
730 rte_be16_t protocol; /**< Protocol type. */
733 /** Default mask for RTE_FLOW_ITEM_TYPE_GRE. */
735 static const struct rte_flow_item_gre rte_flow_item_gre_mask = {
736 .protocol = RTE_BE16(0xffff),
741 * RTE_FLOW_ITEM_TYPE_FUZZY
743 * Fuzzy pattern match, expect faster than default.
745 * This is for device that support fuzzy match option.
746 * Usually a fuzzy match is fast but the cost is accuracy.
747 * i.e. Signature Match only match pattern's hash value, but it is
748 * possible two different patterns have the same hash value.
750 * Matching accuracy level can be configure by threshold.
751 * Driver can divide the range of threshold and map to different
752 * accuracy levels that device support.
754 * Threshold 0 means perfect match (no fuzziness), while threshold
755 * 0xffffffff means fuzziest match.
757 struct rte_flow_item_fuzzy {
758 uint32_t thresh; /**< Accuracy threshold. */
761 /** Default mask for RTE_FLOW_ITEM_TYPE_FUZZY. */
763 static const struct rte_flow_item_fuzzy rte_flow_item_fuzzy_mask = {
764 .thresh = 0xffffffff,
769 * RTE_FLOW_ITEM_TYPE_GTP.
771 * Matches a GTPv1 header.
773 struct rte_flow_item_gtp {
775 * Version (3b), protocol type (1b), reserved (1b),
776 * Extension header flag (1b),
777 * Sequence number flag (1b),
778 * N-PDU number flag (1b).
780 uint8_t v_pt_rsv_flags;
781 uint8_t msg_type; /**< Message type. */
782 rte_be16_t msg_len; /**< Message length. */
783 rte_be32_t teid; /**< Tunnel endpoint identifier. */
786 /** Default mask for RTE_FLOW_ITEM_TYPE_GTP. */
788 static const struct rte_flow_item_gtp rte_flow_item_gtp_mask = {
789 .teid = RTE_BE32(0xffffffff),
794 * RTE_FLOW_ITEM_TYPE_ESP
796 * Matches an ESP header.
798 struct rte_flow_item_esp {
799 struct esp_hdr hdr; /**< ESP header definition. */
802 /** Default mask for RTE_FLOW_ITEM_TYPE_ESP. */
804 static const struct rte_flow_item_esp rte_flow_item_esp_mask = {
812 * RTE_FLOW_ITEM_TYPE_GENEVE.
814 * Matches a GENEVE header.
816 struct rte_flow_item_geneve {
818 * Version (2b), length of the options fields (6b), OAM packet (1b),
819 * critical options present (1b), reserved 0 (6b).
821 rte_be16_t ver_opt_len_o_c_rsvd0;
822 rte_be16_t protocol; /**< Protocol type. */
823 uint8_t vni[3]; /**< Virtual Network Identifier. */
824 uint8_t rsvd1; /**< Reserved, normally 0x00. */
827 /** Default mask for RTE_FLOW_ITEM_TYPE_GENEVE. */
829 static const struct rte_flow_item_geneve rte_flow_item_geneve_mask = {
830 .vni = "\xff\xff\xff",
835 * Matching pattern item definition.
837 * A pattern is formed by stacking items starting from the lowest protocol
838 * layer to match. This stacking restriction does not apply to meta items
839 * which can be placed anywhere in the stack without affecting the meaning
840 * of the resulting pattern.
842 * Patterns are terminated by END items.
844 * The spec field should be a valid pointer to a structure of the related
845 * item type. It may remain unspecified (NULL) in many cases to request
846 * broad (nonspecific) matching. In such cases, last and mask must also be
849 * Optionally, last can point to a structure of the same type to define an
850 * inclusive range. This is mostly supported by integer and address fields,
851 * may cause errors otherwise. Fields that do not support ranges must be set
852 * to 0 or to the same value as the corresponding fields in spec.
854 * Only the fields defined to nonzero values in the default masks (see
855 * rte_flow_item_{name}_mask constants) are considered relevant by
856 * default. This can be overridden by providing a mask structure of the
857 * same type with applicable bits set to one. It can also be used to
858 * partially filter out specific fields (e.g. as an alternate mean to match
859 * ranges of IP addresses).
861 * Mask is a simple bit-mask applied before interpreting the contents of
862 * spec and last, which may yield unexpected results if not used
863 * carefully. For example, if for an IPv4 address field, spec provides
864 * 10.1.2.3, last provides 10.3.4.5 and mask provides 255.255.0.0, the
865 * effective range becomes 10.1.0.0 to 10.3.255.255.
867 struct rte_flow_item {
868 enum rte_flow_item_type type; /**< Item type. */
869 const void *spec; /**< Pointer to item specification structure. */
870 const void *last; /**< Defines an inclusive range (spec to last). */
871 const void *mask; /**< Bit-mask applied to spec and last. */
877 * Each possible action is represented by a type. Some have associated
878 * configuration structures. Several actions combined in a list can be
879 * assigned to a flow rule and are performed in order.
881 * They fall in three categories:
883 * - Actions that modify the fate of matching traffic, for instance by
884 * dropping or assigning it a specific destination.
886 * - Actions that modify matching traffic contents or its properties. This
887 * includes adding/removing encapsulation, encryption, compression and
890 * - Actions related to the flow rule itself, such as updating counters or
891 * making it non-terminating.
893 * Flow rules being terminating by default, not specifying any action of the
894 * fate kind results in undefined behavior. This applies to both ingress and
897 * PASSTHRU, when supported, makes a flow rule non-terminating.
899 enum rte_flow_action_type {
901 * End marker for action lists. Prevents further processing of
902 * actions, thereby ending the list.
904 * No associated configuration structure.
906 RTE_FLOW_ACTION_TYPE_END,
909 * Used as a placeholder for convenience. It is ignored and simply
912 * No associated configuration structure.
914 RTE_FLOW_ACTION_TYPE_VOID,
917 * Leaves traffic up for additional processing by subsequent flow
918 * rules; makes a flow rule non-terminating.
920 * No associated configuration structure.
922 RTE_FLOW_ACTION_TYPE_PASSTHRU,
925 * Attaches an integer value to packets and sets PKT_RX_FDIR and
926 * PKT_RX_FDIR_ID mbuf flags.
928 * See struct rte_flow_action_mark.
930 RTE_FLOW_ACTION_TYPE_MARK,
933 * Flags packets. Similar to MARK without a specific value; only
934 * sets the PKT_RX_FDIR mbuf flag.
936 * No associated configuration structure.
938 RTE_FLOW_ACTION_TYPE_FLAG,
941 * Assigns packets to a given queue index.
943 * See struct rte_flow_action_queue.
945 RTE_FLOW_ACTION_TYPE_QUEUE,
950 * PASSTHRU overrides this action if both are specified.
952 * No associated configuration structure.
954 RTE_FLOW_ACTION_TYPE_DROP,
957 * Enables counters for this flow rule.
959 * These counters can be retrieved and reset through rte_flow_query(),
960 * see struct rte_flow_query_count.
962 * No associated configuration structure.
964 RTE_FLOW_ACTION_TYPE_COUNT,
967 * Similar to QUEUE, except RSS is additionally performed on packets
968 * to spread them among several queues according to the provided
971 * See struct rte_flow_action_rss.
973 RTE_FLOW_ACTION_TYPE_RSS,
976 * Directs matching traffic to the physical function (PF) of the
979 * No associated configuration structure.
981 RTE_FLOW_ACTION_TYPE_PF,
984 * Directs matching traffic to a given virtual function of the
987 * See struct rte_flow_action_vf.
989 RTE_FLOW_ACTION_TYPE_VF,
992 * Directs packets to a given physical port index of the underlying
995 * See struct rte_flow_action_phy_port.
997 RTE_FLOW_ACTION_TYPE_PHY_PORT,
1000 * Traffic metering and policing (MTR).
1002 * See struct rte_flow_action_meter.
1003 * See file rte_mtr.h for MTR object configuration.
1005 RTE_FLOW_ACTION_TYPE_METER,
1008 * Redirects packets to security engine of current device for security
1009 * processing as specified by security session.
1011 * See struct rte_flow_action_security.
1013 RTE_FLOW_ACTION_TYPE_SECURITY
1017 * RTE_FLOW_ACTION_TYPE_MARK
1019 * Attaches an integer value to packets and sets PKT_RX_FDIR and
1020 * PKT_RX_FDIR_ID mbuf flags.
1022 * This value is arbitrary and application-defined. Maximum allowed value
1023 * depends on the underlying implementation. It is returned in the
1024 * hash.fdir.hi mbuf field.
1026 struct rte_flow_action_mark {
1027 uint32_t id; /**< Integer value to return with packets. */
1031 * RTE_FLOW_ACTION_TYPE_QUEUE
1033 * Assign packets to a given queue index.
1035 struct rte_flow_action_queue {
1036 uint16_t index; /**< Queue index to use. */
1040 * RTE_FLOW_ACTION_TYPE_COUNT (query)
1042 * Query structure to retrieve and reset flow rule counters.
1044 struct rte_flow_query_count {
1045 uint32_t reset:1; /**< Reset counters after query [in]. */
1046 uint32_t hits_set:1; /**< hits field is set [out]. */
1047 uint32_t bytes_set:1; /**< bytes field is set [out]. */
1048 uint32_t reserved:29; /**< Reserved, must be zero [in, out]. */
1049 uint64_t hits; /**< Number of hits for this rule [out]. */
1050 uint64_t bytes; /**< Number of bytes through this rule [out]. */
1054 * RTE_FLOW_ACTION_TYPE_RSS
1056 * Similar to QUEUE, except RSS is additionally performed on packets to
1057 * spread them among several queues according to the provided parameters.
1059 * Unlike global RSS settings used by other DPDK APIs, unsetting the
1060 * @p types field does not disable RSS in a flow rule. Doing so instead
1061 * requests safe unspecified "best-effort" settings from the underlying PMD,
1062 * which depending on the flow rule, may result in anything ranging from
1063 * empty (single queue) to all-inclusive RSS.
1065 * Note: RSS hash result is stored in the hash.rss mbuf field which overlaps
1066 * hash.fdir.lo. Since the MARK action sets the hash.fdir.hi field only,
1067 * both can be requested simultaneously.
1069 struct rte_flow_action_rss {
1070 enum rte_eth_hash_function func; /**< RSS hash function to apply. */
1072 * Packet encapsulation level RSS hash @p types apply to.
1074 * - @p 0 requests the default behavior. Depending on the packet
1075 * type, it can mean outermost, innermost, anything in between or
1078 * It basically stands for the innermost encapsulation level RSS
1079 * can be performed on according to PMD and device capabilities.
1081 * - @p 1 requests RSS to be performed on the outermost packet
1082 * encapsulation level.
1084 * - @p 2 and subsequent values request RSS to be performed on the
1085 * specified inner packet encapsulation level, from outermost to
1086 * innermost (lower to higher values).
1088 * Values other than @p 0 are not necessarily supported.
1090 * Requesting a specific RSS level on unrecognized traffic results
1091 * in undefined behavior. For predictable results, it is recommended
1092 * to make the flow rule pattern match packet headers up to the
1093 * requested encapsulation level so that only matching traffic goes
1097 uint64_t types; /**< Specific RSS hash types (see ETH_RSS_*). */
1098 uint32_t key_len; /**< Hash key length in bytes. */
1099 uint32_t queue_num; /**< Number of entries in @p queue. */
1100 const uint8_t *key; /**< Hash key. */
1101 const uint16_t *queue; /**< Queue indices to use. */
1105 * RTE_FLOW_ACTION_TYPE_VF
1107 * Directs matching traffic to a given virtual function of the current
1110 * Packets matched by a VF pattern item can be redirected to their original
1111 * VF ID instead of the specified one. This parameter may not be available
1112 * and is not guaranteed to work properly if the VF part is matched by a
1113 * prior flow rule or if packets are not addressed to a VF in the first
1116 struct rte_flow_action_vf {
1117 uint32_t original:1; /**< Use original VF ID if possible. */
1118 uint32_t reserved:31; /**< Reserved, must be zero. */
1119 uint32_t id; /**< VF ID. */
1123 * RTE_FLOW_ACTION_TYPE_PHY_PORT
1125 * Directs packets to a given physical port index of the underlying
1128 * @see RTE_FLOW_ITEM_TYPE_PHY_PORT
1130 struct rte_flow_action_phy_port {
1131 uint32_t original:1; /**< Use original port index if possible. */
1132 uint32_t reserved:31; /**< Reserved, must be zero. */
1133 uint32_t index; /**< Physical port index. */
1137 * RTE_FLOW_ACTION_TYPE_METER
1139 * Traffic metering and policing (MTR).
1141 * Packets matched by items of this type can be either dropped or passed to the
1142 * next item with their color set by the MTR object.
1144 struct rte_flow_action_meter {
1145 uint32_t mtr_id; /**< MTR object ID created with rte_mtr_create(). */
1149 * RTE_FLOW_ACTION_TYPE_SECURITY
1151 * Perform the security action on flows matched by the pattern items
1152 * according to the configuration of the security session.
1154 * This action modifies the payload of matched flows. For INLINE_CRYPTO, the
1155 * security protocol headers and IV are fully provided by the application as
1156 * specified in the flow pattern. The payload of matching packets is
1157 * encrypted on egress, and decrypted and authenticated on ingress.
1158 * For INLINE_PROTOCOL, the security protocol is fully offloaded to HW,
1159 * providing full encapsulation and decapsulation of packets in security
1160 * protocols. The flow pattern specifies both the outer security header fields
1161 * and the inner packet fields. The security session specified in the action
1162 * must match the pattern parameters.
1164 * The security session specified in the action must be created on the same
1165 * port as the flow action that is being specified.
1167 * The ingress/egress flow attribute should match that specified in the
1168 * security session if the security session supports the definition of the
1171 * Multiple flows can be configured to use the same security session.
1173 struct rte_flow_action_security {
1174 void *security_session; /**< Pointer to security session structure. */
1178 * Definition of a single action.
1180 * A list of actions is terminated by a END action.
1182 * For simple actions without a configuration structure, conf remains NULL.
1184 struct rte_flow_action {
1185 enum rte_flow_action_type type; /**< Action type. */
1186 const void *conf; /**< Pointer to action configuration structure. */
1190 * Opaque type returned after successfully creating a flow.
1192 * This handle can be used to manage and query the related flow (e.g. to
1193 * destroy it or retrieve counters).
1198 * Verbose error types.
1200 * Most of them provide the type of the object referenced by struct
1201 * rte_flow_error.cause.
1203 enum rte_flow_error_type {
1204 RTE_FLOW_ERROR_TYPE_NONE, /**< No error. */
1205 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, /**< Cause unspecified. */
1206 RTE_FLOW_ERROR_TYPE_HANDLE, /**< Flow rule (handle). */
1207 RTE_FLOW_ERROR_TYPE_ATTR_GROUP, /**< Group field. */
1208 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY, /**< Priority field. */
1209 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS, /**< Ingress field. */
1210 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, /**< Egress field. */
1211 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER, /**< Transfer field. */
1212 RTE_FLOW_ERROR_TYPE_ATTR, /**< Attributes structure. */
1213 RTE_FLOW_ERROR_TYPE_ITEM_NUM, /**< Pattern length. */
1214 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, /**< Item specification. */
1215 RTE_FLOW_ERROR_TYPE_ITEM_LAST, /**< Item specification range. */
1216 RTE_FLOW_ERROR_TYPE_ITEM_MASK, /**< Item specification mask. */
1217 RTE_FLOW_ERROR_TYPE_ITEM, /**< Specific pattern item. */
1218 RTE_FLOW_ERROR_TYPE_ACTION_NUM, /**< Number of actions. */
1219 RTE_FLOW_ERROR_TYPE_ACTION_CONF, /**< Action configuration. */
1220 RTE_FLOW_ERROR_TYPE_ACTION, /**< Specific action. */
1224 * Verbose error structure definition.
1226 * This object is normally allocated by applications and set by PMDs, the
1227 * message points to a constant string which does not need to be freed by
1228 * the application, however its pointer can be considered valid only as long
1229 * as its associated DPDK port remains configured. Closing the underlying
1230 * device or unloading the PMD invalidates it.
1232 * Both cause and message may be NULL regardless of the error type.
1234 struct rte_flow_error {
1235 enum rte_flow_error_type type; /**< Cause field and error types. */
1236 const void *cause; /**< Object responsible for the error. */
1237 const char *message; /**< Human-readable error message. */
1241 * Check whether a flow rule can be created on a given port.
1243 * The flow rule is validated for correctness and whether it could be accepted
1244 * by the device given sufficient resources. The rule is checked against the
1245 * current device mode and queue configuration. The flow rule may also
1246 * optionally be validated against existing flow rules and device resources.
1247 * This function has no effect on the target device.
1249 * The returned value is guaranteed to remain valid only as long as no
1250 * successful calls to rte_flow_create() or rte_flow_destroy() are made in
1251 * the meantime and no device parameter affecting flow rules in any way are
1252 * modified, due to possible collisions or resource limitations (although in
1253 * such cases EINVAL should not be returned).
1256 * Port identifier of Ethernet device.
1258 * Flow rule attributes.
1259 * @param[in] pattern
1260 * Pattern specification (list terminated by the END pattern item).
1261 * @param[in] actions
1262 * Associated actions (list terminated by the END action).
1264 * Perform verbose error reporting if not NULL. PMDs initialize this
1265 * structure in case of error only.
1268 * 0 if flow rule is valid and can be created. A negative errno value
1269 * otherwise (rte_errno is also set), the following errors are defined:
1271 * -ENOSYS: underlying device does not support this functionality.
1273 * -EIO: underlying device is removed.
1275 * -EINVAL: unknown or invalid rule specification.
1277 * -ENOTSUP: valid but unsupported rule specification (e.g. partial
1278 * bit-masks are unsupported).
1280 * -EEXIST: collision with an existing rule. Only returned if device
1281 * supports flow rule collision checking and there was a flow rule
1282 * collision. Not receiving this return code is no guarantee that creating
1283 * the rule will not fail due to a collision.
1285 * -ENOMEM: not enough memory to execute the function, or if the device
1286 * supports resource validation, resource limitation on the device.
1288 * -EBUSY: action cannot be performed due to busy device resources, may
1289 * succeed if the affected queues or even the entire port are in a stopped
1290 * state (see rte_eth_dev_rx_queue_stop() and rte_eth_dev_stop()).
1293 rte_flow_validate(uint16_t port_id,
1294 const struct rte_flow_attr *attr,
1295 const struct rte_flow_item pattern[],
1296 const struct rte_flow_action actions[],
1297 struct rte_flow_error *error);
1300 * Create a flow rule on a given port.
1303 * Port identifier of Ethernet device.
1305 * Flow rule attributes.
1306 * @param[in] pattern
1307 * Pattern specification (list terminated by the END pattern item).
1308 * @param[in] actions
1309 * Associated actions (list terminated by the END action).
1311 * Perform verbose error reporting if not NULL. PMDs initialize this
1312 * structure in case of error only.
1315 * A valid handle in case of success, NULL otherwise and rte_errno is set
1316 * to the positive version of one of the error codes defined for
1317 * rte_flow_validate().
1320 rte_flow_create(uint16_t port_id,
1321 const struct rte_flow_attr *attr,
1322 const struct rte_flow_item pattern[],
1323 const struct rte_flow_action actions[],
1324 struct rte_flow_error *error);
1327 * Destroy a flow rule on a given port.
1329 * Failure to destroy a flow rule handle may occur when other flow rules
1330 * depend on it, and destroying it would result in an inconsistent state.
1332 * This function is only guaranteed to succeed if handles are destroyed in
1333 * reverse order of their creation.
1336 * Port identifier of Ethernet device.
1338 * Flow rule handle to destroy.
1340 * Perform verbose error reporting if not NULL. PMDs initialize this
1341 * structure in case of error only.
1344 * 0 on success, a negative errno value otherwise and rte_errno is set.
1347 rte_flow_destroy(uint16_t port_id,
1348 struct rte_flow *flow,
1349 struct rte_flow_error *error);
1352 * Destroy all flow rules associated with a port.
1354 * In the unlikely event of failure, handles are still considered destroyed
1355 * and no longer valid but the port must be assumed to be in an inconsistent
1359 * Port identifier of Ethernet device.
1361 * Perform verbose error reporting if not NULL. PMDs initialize this
1362 * structure in case of error only.
1365 * 0 on success, a negative errno value otherwise and rte_errno is set.
1368 rte_flow_flush(uint16_t port_id,
1369 struct rte_flow_error *error);
1372 * Query an existing flow rule.
1374 * This function allows retrieving flow-specific data such as counters.
1375 * Data is gathered by special actions which must be present in the flow
1378 * \see RTE_FLOW_ACTION_TYPE_COUNT
1381 * Port identifier of Ethernet device.
1383 * Flow rule handle to query.
1385 * Action type to query.
1386 * @param[in, out] data
1387 * Pointer to storage for the associated query data type.
1389 * Perform verbose error reporting if not NULL. PMDs initialize this
1390 * structure in case of error only.
1393 * 0 on success, a negative errno value otherwise and rte_errno is set.
1396 rte_flow_query(uint16_t port_id,
1397 struct rte_flow *flow,
1398 enum rte_flow_action_type action,
1400 struct rte_flow_error *error);
1403 * Restrict ingress traffic to the defined flow rules.
1405 * Isolated mode guarantees that all ingress traffic comes from defined flow
1406 * rules only (current and future).
1408 * Besides making ingress more deterministic, it allows PMDs to safely reuse
1409 * resources otherwise assigned to handle the remaining traffic, such as
1410 * global RSS configuration settings, VLAN filters, MAC address entries,
1411 * legacy filter API rules and so on in order to expand the set of possible
1414 * Calling this function as soon as possible after device initialization,
1415 * ideally before the first call to rte_eth_dev_configure(), is recommended
1416 * to avoid possible failures due to conflicting settings.
1418 * Once effective, leaving isolated mode may not be possible depending on
1419 * PMD implementation.
1421 * Additionally, the following functionality has no effect on the underlying
1422 * port and may return errors such as ENOTSUP ("not supported"):
1424 * - Toggling promiscuous mode.
1425 * - Toggling allmulticast mode.
1426 * - Configuring MAC addresses.
1427 * - Configuring multicast addresses.
1428 * - Configuring VLAN filters.
1429 * - Configuring Rx filters through the legacy API (e.g. FDIR).
1430 * - Configuring global RSS settings.
1433 * Port identifier of Ethernet device.
1435 * Nonzero to enter isolated mode, attempt to leave it otherwise.
1437 * Perform verbose error reporting if not NULL. PMDs initialize this
1438 * structure in case of error only.
1441 * 0 on success, a negative errno value otherwise and rte_errno is set.
1444 rte_flow_isolate(uint16_t port_id, int set, struct rte_flow_error *error);
1447 * Initialize flow error structure.
1450 * Pointer to flow error structure (may be NULL).
1452 * Related error code (rte_errno).
1454 * Cause field and error types.
1456 * Object responsible for the error.
1458 * Human-readable error message.
1461 * Negative error code (errno value) and rte_errno is set.
1464 rte_flow_error_set(struct rte_flow_error *error,
1466 enum rte_flow_error_type type,
1468 const char *message);
1471 * Generic flow representation.
1473 * This form is sufficient to describe an rte_flow independently from any
1474 * PMD implementation and allows for replayability and identification.
1476 struct rte_flow_desc {
1477 size_t size; /**< Allocated space including data[]. */
1478 struct rte_flow_attr attr; /**< Attributes. */
1479 struct rte_flow_item *items; /**< Items. */
1480 struct rte_flow_action *actions; /**< Actions. */
1481 uint8_t data[]; /**< Storage for items/actions. */
1485 * Copy an rte_flow rule description.
1488 * Flow rule description.
1490 * Total size of allocated data for the flow description.
1492 * Flow rule attributes.
1494 * Pattern specification (list terminated by the END pattern item).
1495 * @param[in] actions
1496 * Associated actions (list terminated by the END action).
1499 * If len is greater or equal to the size of the flow, the total size of the
1500 * flow description and its data.
1501 * If len is lower than the size of the flow, the number of bytes that would
1502 * have been written to desc had it been sufficient. Nothing is written.
1505 rte_flow_copy(struct rte_flow_desc *fd, size_t len,
1506 const struct rte_flow_attr *attr,
1507 const struct rte_flow_item *items,
1508 const struct rte_flow_action *actions);
1514 #endif /* RTE_FLOW_H_ */