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_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 packets addressed to the physical function of the device.
157 * If the underlying device function differs from the one that would
158 * normally receive the matched traffic, specifying this item
159 * prevents it from reaching that device unless the flow rule
160 * contains a PF action. Packets are not duplicated between device
161 * instances by default.
163 * No associated specification structure.
165 RTE_FLOW_ITEM_TYPE_PF,
170 * Matches packets addressed to a virtual function ID of the device.
172 * If the underlying device function differs from the one that would
173 * normally receive the matched traffic, specifying this item
174 * prevents it from reaching that device unless the flow rule
175 * contains a VF action. Packets are not duplicated between device
176 * instances by default.
178 * See struct rte_flow_item_vf.
180 RTE_FLOW_ITEM_TYPE_VF,
185 * Matches packets coming from the specified physical port of the
188 * The first PORT item overrides the physical port normally
189 * associated with the specified DPDK input port (port_id). This
190 * item can be provided several times to match additional physical
193 * See struct rte_flow_item_port.
195 RTE_FLOW_ITEM_TYPE_PORT,
198 * Matches a byte string of a given length at a given offset.
200 * See struct rte_flow_item_raw.
202 RTE_FLOW_ITEM_TYPE_RAW,
205 * Matches an Ethernet header.
207 * See struct rte_flow_item_eth.
209 RTE_FLOW_ITEM_TYPE_ETH,
212 * Matches an 802.1Q/ad VLAN tag.
214 * See struct rte_flow_item_vlan.
216 RTE_FLOW_ITEM_TYPE_VLAN,
219 * Matches an IPv4 header.
221 * See struct rte_flow_item_ipv4.
223 RTE_FLOW_ITEM_TYPE_IPV4,
226 * Matches an IPv6 header.
228 * See struct rte_flow_item_ipv6.
230 RTE_FLOW_ITEM_TYPE_IPV6,
233 * Matches an ICMP header.
235 * See struct rte_flow_item_icmp.
237 RTE_FLOW_ITEM_TYPE_ICMP,
240 * Matches a UDP header.
242 * See struct rte_flow_item_udp.
244 RTE_FLOW_ITEM_TYPE_UDP,
247 * Matches a TCP header.
249 * See struct rte_flow_item_tcp.
251 RTE_FLOW_ITEM_TYPE_TCP,
254 * Matches a SCTP header.
256 * See struct rte_flow_item_sctp.
258 RTE_FLOW_ITEM_TYPE_SCTP,
261 * Matches a VXLAN header.
263 * See struct rte_flow_item_vxlan.
265 RTE_FLOW_ITEM_TYPE_VXLAN,
268 * Matches a E_TAG header.
270 * See struct rte_flow_item_e_tag.
272 RTE_FLOW_ITEM_TYPE_E_TAG,
275 * Matches a NVGRE header.
277 * See struct rte_flow_item_nvgre.
279 RTE_FLOW_ITEM_TYPE_NVGRE,
282 * Matches a MPLS header.
284 * See struct rte_flow_item_mpls.
286 RTE_FLOW_ITEM_TYPE_MPLS,
289 * Matches a GRE header.
291 * See struct rte_flow_item_gre.
293 RTE_FLOW_ITEM_TYPE_GRE,
298 * Fuzzy pattern match, expect faster than default.
300 * This is for device that support fuzzy matching option.
301 * Usually a fuzzy matching is fast but the cost is accuracy.
303 * See struct rte_flow_item_fuzzy.
305 RTE_FLOW_ITEM_TYPE_FUZZY,
308 * Matches a GTP header.
310 * Configure flow for GTP packets.
312 * See struct rte_flow_item_gtp.
314 RTE_FLOW_ITEM_TYPE_GTP,
317 * Matches a GTP header.
319 * Configure flow for GTP-C packets.
321 * See struct rte_flow_item_gtp.
323 RTE_FLOW_ITEM_TYPE_GTPC,
326 * Matches a GTP header.
328 * Configure flow for GTP-U packets.
330 * See struct rte_flow_item_gtp.
332 RTE_FLOW_ITEM_TYPE_GTPU,
335 * Matches a ESP header.
337 * See struct rte_flow_item_esp.
339 RTE_FLOW_ITEM_TYPE_ESP,
342 * Matches a GENEVE header.
344 * See struct rte_flow_item_geneve.
346 RTE_FLOW_ITEM_TYPE_GENEVE,
350 * RTE_FLOW_ITEM_TYPE_ANY
352 * Matches any protocol in place of the current layer, a single ANY may also
353 * stand for several protocol layers.
355 * This is usually specified as the first pattern item when looking for a
356 * protocol anywhere in a packet.
358 * A zeroed mask stands for any number of layers.
360 struct rte_flow_item_any {
361 uint32_t num; /**< Number of layers covered. */
364 /** Default mask for RTE_FLOW_ITEM_TYPE_ANY. */
366 static const struct rte_flow_item_any rte_flow_item_any_mask = {
372 * RTE_FLOW_ITEM_TYPE_VF
374 * Matches packets addressed to a virtual function ID of the device.
376 * If the underlying device function differs from the one that would
377 * normally receive the matched traffic, specifying this item prevents it
378 * from reaching that device unless the flow rule contains a VF
379 * action. Packets are not duplicated between device instances by default.
381 * - Likely to return an error or never match any traffic if this causes a
382 * VF device to match traffic addressed to a different VF.
383 * - Can be specified multiple times to match traffic addressed to several
385 * - Can be combined with a PF item to match both PF and VF traffic.
387 * A zeroed mask can be used to match any VF ID.
389 struct rte_flow_item_vf {
390 uint32_t id; /**< Destination VF ID. */
393 /** Default mask for RTE_FLOW_ITEM_TYPE_VF. */
395 static const struct rte_flow_item_vf rte_flow_item_vf_mask = {
401 * RTE_FLOW_ITEM_TYPE_PORT
403 * Matches packets coming from the specified physical port of the underlying
406 * The first PORT item overrides the physical port normally associated with
407 * the specified DPDK input port (port_id). This item can be provided
408 * several times to match additional physical ports.
410 * Note that physical ports are not necessarily tied to DPDK input ports
411 * (port_id) when those are not under DPDK control. Possible values are
412 * specific to each device, they are not necessarily indexed from zero and
413 * may not be contiguous.
415 * As a device property, the list of allowed values as well as the value
416 * associated with a port_id should be retrieved by other means.
418 * A zeroed mask can be used to match any port index.
420 struct rte_flow_item_port {
421 uint32_t index; /**< Physical port index. */
424 /** Default mask for RTE_FLOW_ITEM_TYPE_PORT. */
426 static const struct rte_flow_item_port rte_flow_item_port_mask = {
432 * RTE_FLOW_ITEM_TYPE_RAW
434 * Matches a byte string of a given length at a given offset.
436 * Offset is either absolute (using the start of the packet) or relative to
437 * the end of the previous matched item in the stack, in which case negative
438 * values are allowed.
440 * If search is enabled, offset is used as the starting point. The search
441 * area can be delimited by setting limit to a nonzero value, which is the
442 * maximum number of bytes after offset where the pattern may start.
444 * Matching a zero-length pattern is allowed, doing so resets the relative
445 * offset for subsequent items.
447 * This type does not support ranges (struct rte_flow_item.last).
449 struct rte_flow_item_raw {
450 uint32_t relative:1; /**< Look for pattern after the previous item. */
451 uint32_t search:1; /**< Search pattern from offset (see also limit). */
452 uint32_t reserved:30; /**< Reserved, must be set to zero. */
453 int32_t offset; /**< Absolute or relative offset for pattern. */
454 uint16_t limit; /**< Search area limit for start of pattern. */
455 uint16_t length; /**< Pattern length. */
456 const uint8_t *pattern; /**< Byte string to look for. */
459 /** Default mask for RTE_FLOW_ITEM_TYPE_RAW. */
461 static const struct rte_flow_item_raw rte_flow_item_raw_mask = {
464 .reserved = 0x3fffffff,
465 .offset = 0xffffffff,
473 * RTE_FLOW_ITEM_TYPE_ETH
475 * Matches an Ethernet header.
477 * The @p type field either stands for "EtherType" or "TPID" when followed
478 * by so-called layer 2.5 pattern items such as RTE_FLOW_ITEM_TYPE_VLAN. In
479 * the latter case, @p type refers to that of the outer header, with the
480 * inner EtherType/TPID provided by the subsequent pattern item. This is the
481 * same order as on the wire.
483 struct rte_flow_item_eth {
484 struct ether_addr dst; /**< Destination MAC. */
485 struct ether_addr src; /**< Source MAC. */
486 rte_be16_t type; /**< EtherType or TPID. */
489 /** Default mask for RTE_FLOW_ITEM_TYPE_ETH. */
491 static const struct rte_flow_item_eth rte_flow_item_eth_mask = {
492 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
493 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
494 .type = RTE_BE16(0x0000),
499 * RTE_FLOW_ITEM_TYPE_VLAN
501 * Matches an 802.1Q/ad VLAN tag.
503 * The corresponding standard outer EtherType (TPID) values are
504 * ETHER_TYPE_VLAN or ETHER_TYPE_QINQ. It can be overridden by the preceding
507 struct rte_flow_item_vlan {
508 rte_be16_t tci; /**< Tag control information. */
509 rte_be16_t inner_type; /**< Inner EtherType or TPID. */
512 /** Default mask for RTE_FLOW_ITEM_TYPE_VLAN. */
514 static const struct rte_flow_item_vlan rte_flow_item_vlan_mask = {
515 .tci = RTE_BE16(0x0fff),
516 .inner_type = RTE_BE16(0x0000),
521 * RTE_FLOW_ITEM_TYPE_IPV4
523 * Matches an IPv4 header.
525 * Note: IPv4 options are handled by dedicated pattern items.
527 struct rte_flow_item_ipv4 {
528 struct ipv4_hdr hdr; /**< IPv4 header definition. */
531 /** Default mask for RTE_FLOW_ITEM_TYPE_IPV4. */
533 static const struct rte_flow_item_ipv4 rte_flow_item_ipv4_mask = {
535 .src_addr = RTE_BE32(0xffffffff),
536 .dst_addr = RTE_BE32(0xffffffff),
542 * RTE_FLOW_ITEM_TYPE_IPV6.
544 * Matches an IPv6 header.
546 * Note: IPv6 options are handled by dedicated pattern items.
548 struct rte_flow_item_ipv6 {
549 struct ipv6_hdr hdr; /**< IPv6 header definition. */
552 /** Default mask for RTE_FLOW_ITEM_TYPE_IPV6. */
554 static const struct rte_flow_item_ipv6 rte_flow_item_ipv6_mask = {
557 "\xff\xff\xff\xff\xff\xff\xff\xff"
558 "\xff\xff\xff\xff\xff\xff\xff\xff",
560 "\xff\xff\xff\xff\xff\xff\xff\xff"
561 "\xff\xff\xff\xff\xff\xff\xff\xff",
567 * RTE_FLOW_ITEM_TYPE_ICMP.
569 * Matches an ICMP header.
571 struct rte_flow_item_icmp {
572 struct icmp_hdr hdr; /**< ICMP header definition. */
575 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP. */
577 static const struct rte_flow_item_icmp rte_flow_item_icmp_mask = {
586 * RTE_FLOW_ITEM_TYPE_UDP.
588 * Matches a UDP header.
590 struct rte_flow_item_udp {
591 struct udp_hdr hdr; /**< UDP header definition. */
594 /** Default mask for RTE_FLOW_ITEM_TYPE_UDP. */
596 static const struct rte_flow_item_udp rte_flow_item_udp_mask = {
598 .src_port = RTE_BE16(0xffff),
599 .dst_port = RTE_BE16(0xffff),
605 * RTE_FLOW_ITEM_TYPE_TCP.
607 * Matches a TCP header.
609 struct rte_flow_item_tcp {
610 struct tcp_hdr hdr; /**< TCP header definition. */
613 /** Default mask for RTE_FLOW_ITEM_TYPE_TCP. */
615 static const struct rte_flow_item_tcp rte_flow_item_tcp_mask = {
617 .src_port = RTE_BE16(0xffff),
618 .dst_port = RTE_BE16(0xffff),
624 * RTE_FLOW_ITEM_TYPE_SCTP.
626 * Matches a SCTP header.
628 struct rte_flow_item_sctp {
629 struct sctp_hdr hdr; /**< SCTP header definition. */
632 /** Default mask for RTE_FLOW_ITEM_TYPE_SCTP. */
634 static const struct rte_flow_item_sctp rte_flow_item_sctp_mask = {
636 .src_port = RTE_BE16(0xffff),
637 .dst_port = RTE_BE16(0xffff),
643 * RTE_FLOW_ITEM_TYPE_VXLAN.
645 * Matches a VXLAN header (RFC 7348).
647 struct rte_flow_item_vxlan {
648 uint8_t flags; /**< Normally 0x08 (I flag). */
649 uint8_t rsvd0[3]; /**< Reserved, normally 0x000000. */
650 uint8_t vni[3]; /**< VXLAN identifier. */
651 uint8_t rsvd1; /**< Reserved, normally 0x00. */
654 /** Default mask for RTE_FLOW_ITEM_TYPE_VXLAN. */
656 static const struct rte_flow_item_vxlan rte_flow_item_vxlan_mask = {
657 .vni = "\xff\xff\xff",
662 * RTE_FLOW_ITEM_TYPE_E_TAG.
664 * Matches a E-tag header.
666 * The corresponding standard outer EtherType (TPID) value is
667 * ETHER_TYPE_ETAG. It can be overridden by the preceding pattern item.
669 struct rte_flow_item_e_tag {
671 * E-Tag control information (E-TCI).
672 * E-PCP (3b), E-DEI (1b), ingress E-CID base (12b).
674 rte_be16_t epcp_edei_in_ecid_b;
675 /** Reserved (2b), GRP (2b), E-CID base (12b). */
676 rte_be16_t rsvd_grp_ecid_b;
677 uint8_t in_ecid_e; /**< Ingress E-CID ext. */
678 uint8_t ecid_e; /**< E-CID ext. */
679 rte_be16_t inner_type; /**< Inner EtherType or TPID. */
682 /** Default mask for RTE_FLOW_ITEM_TYPE_E_TAG. */
684 static const struct rte_flow_item_e_tag rte_flow_item_e_tag_mask = {
685 .rsvd_grp_ecid_b = RTE_BE16(0x3fff),
690 * RTE_FLOW_ITEM_TYPE_NVGRE.
692 * Matches a NVGRE header.
694 struct rte_flow_item_nvgre {
696 * Checksum (1b), undefined (1b), key bit (1b), sequence number (1b),
697 * reserved 0 (9b), version (3b).
699 * c_k_s_rsvd0_ver must have value 0x2000 according to RFC 7637.
701 rte_be16_t c_k_s_rsvd0_ver;
702 rte_be16_t protocol; /**< Protocol type (0x6558). */
703 uint8_t tni[3]; /**< Virtual subnet ID. */
704 uint8_t flow_id; /**< Flow ID. */
707 /** Default mask for RTE_FLOW_ITEM_TYPE_NVGRE. */
709 static const struct rte_flow_item_nvgre rte_flow_item_nvgre_mask = {
710 .tni = "\xff\xff\xff",
715 * RTE_FLOW_ITEM_TYPE_MPLS.
717 * Matches a MPLS header.
719 struct rte_flow_item_mpls {
721 * Label (20b), TC (3b), Bottom of Stack (1b).
723 uint8_t label_tc_s[3];
724 uint8_t ttl; /** Time-to-Live. */
727 /** Default mask for RTE_FLOW_ITEM_TYPE_MPLS. */
729 static const struct rte_flow_item_mpls rte_flow_item_mpls_mask = {
730 .label_tc_s = "\xff\xff\xf0",
735 * RTE_FLOW_ITEM_TYPE_GRE.
737 * Matches a GRE header.
739 struct rte_flow_item_gre {
741 * Checksum (1b), reserved 0 (12b), version (3b).
744 rte_be16_t c_rsvd0_ver;
745 rte_be16_t protocol; /**< Protocol type. */
748 /** Default mask for RTE_FLOW_ITEM_TYPE_GRE. */
750 static const struct rte_flow_item_gre rte_flow_item_gre_mask = {
751 .protocol = RTE_BE16(0xffff),
756 * RTE_FLOW_ITEM_TYPE_FUZZY
758 * Fuzzy pattern match, expect faster than default.
760 * This is for device that support fuzzy match option.
761 * Usually a fuzzy match is fast but the cost is accuracy.
762 * i.e. Signature Match only match pattern's hash value, but it is
763 * possible two different patterns have the same hash value.
765 * Matching accuracy level can be configure by threshold.
766 * Driver can divide the range of threshold and map to different
767 * accuracy levels that device support.
769 * Threshold 0 means perfect match (no fuzziness), while threshold
770 * 0xffffffff means fuzziest match.
772 struct rte_flow_item_fuzzy {
773 uint32_t thresh; /**< Accuracy threshold. */
776 /** Default mask for RTE_FLOW_ITEM_TYPE_FUZZY. */
778 static const struct rte_flow_item_fuzzy rte_flow_item_fuzzy_mask = {
779 .thresh = 0xffffffff,
784 * RTE_FLOW_ITEM_TYPE_GTP.
786 * Matches a GTPv1 header.
788 struct rte_flow_item_gtp {
790 * Version (3b), protocol type (1b), reserved (1b),
791 * Extension header flag (1b),
792 * Sequence number flag (1b),
793 * N-PDU number flag (1b).
795 uint8_t v_pt_rsv_flags;
796 uint8_t msg_type; /**< Message type. */
797 rte_be16_t msg_len; /**< Message length. */
798 rte_be32_t teid; /**< Tunnel endpoint identifier. */
801 /** Default mask for RTE_FLOW_ITEM_TYPE_GTP. */
803 static const struct rte_flow_item_gtp rte_flow_item_gtp_mask = {
804 .teid = RTE_BE32(0xffffffff),
809 * RTE_FLOW_ITEM_TYPE_ESP
811 * Matches an ESP header.
813 struct rte_flow_item_esp {
814 struct esp_hdr hdr; /**< ESP header definition. */
817 /** Default mask for RTE_FLOW_ITEM_TYPE_ESP. */
819 static const struct rte_flow_item_esp rte_flow_item_esp_mask = {
827 * RTE_FLOW_ITEM_TYPE_GENEVE.
829 * Matches a GENEVE header.
831 struct rte_flow_item_geneve {
833 * Version (2b), length of the options fields (6b), OAM packet (1b),
834 * critical options present (1b), reserved 0 (6b).
836 rte_be16_t ver_opt_len_o_c_rsvd0;
837 rte_be16_t protocol; /**< Protocol type. */
838 uint8_t vni[3]; /**< Virtual Network Identifier. */
839 uint8_t rsvd1; /**< Reserved, normally 0x00. */
842 /** Default mask for RTE_FLOW_ITEM_TYPE_GENEVE. */
844 static const struct rte_flow_item_geneve rte_flow_item_geneve_mask = {
845 .vni = "\xff\xff\xff",
850 * Matching pattern item definition.
852 * A pattern is formed by stacking items starting from the lowest protocol
853 * layer to match. This stacking restriction does not apply to meta items
854 * which can be placed anywhere in the stack without affecting the meaning
855 * of the resulting pattern.
857 * Patterns are terminated by END items.
859 * The spec field should be a valid pointer to a structure of the related
860 * item type. It may remain unspecified (NULL) in many cases to request
861 * broad (nonspecific) matching. In such cases, last and mask must also be
864 * Optionally, last can point to a structure of the same type to define an
865 * inclusive range. This is mostly supported by integer and address fields,
866 * may cause errors otherwise. Fields that do not support ranges must be set
867 * to 0 or to the same value as the corresponding fields in spec.
869 * Only the fields defined to nonzero values in the default masks (see
870 * rte_flow_item_{name}_mask constants) are considered relevant by
871 * default. This can be overridden by providing a mask structure of the
872 * same type with applicable bits set to one. It can also be used to
873 * partially filter out specific fields (e.g. as an alternate mean to match
874 * ranges of IP addresses).
876 * Mask is a simple bit-mask applied before interpreting the contents of
877 * spec and last, which may yield unexpected results if not used
878 * carefully. For example, if for an IPv4 address field, spec provides
879 * 10.1.2.3, last provides 10.3.4.5 and mask provides 255.255.0.0, the
880 * effective range becomes 10.1.0.0 to 10.3.255.255.
882 struct rte_flow_item {
883 enum rte_flow_item_type type; /**< Item type. */
884 const void *spec; /**< Pointer to item specification structure. */
885 const void *last; /**< Defines an inclusive range (spec to last). */
886 const void *mask; /**< Bit-mask applied to spec and last. */
892 * Each possible action is represented by a type. Some have associated
893 * configuration structures. Several actions combined in a list can be
894 * assigned to a flow rule and are performed in order.
896 * They fall in three categories:
898 * - Actions that modify the fate of matching traffic, for instance by
899 * dropping or assigning it a specific destination.
901 * - Actions that modify matching traffic contents or its properties. This
902 * includes adding/removing encapsulation, encryption, compression and
905 * - Actions related to the flow rule itself, such as updating counters or
906 * making it non-terminating.
908 * Flow rules being terminating by default, not specifying any action of the
909 * fate kind results in undefined behavior. This applies to both ingress and
912 * PASSTHRU, when supported, makes a flow rule non-terminating.
914 enum rte_flow_action_type {
916 * End marker for action lists. Prevents further processing of
917 * actions, thereby ending the list.
919 * No associated configuration structure.
921 RTE_FLOW_ACTION_TYPE_END,
924 * Used as a placeholder for convenience. It is ignored and simply
927 * No associated configuration structure.
929 RTE_FLOW_ACTION_TYPE_VOID,
932 * Leaves traffic up for additional processing by subsequent flow
933 * rules; makes a flow rule non-terminating.
935 * No associated configuration structure.
937 RTE_FLOW_ACTION_TYPE_PASSTHRU,
940 * Attaches an integer value to packets and sets PKT_RX_FDIR and
941 * PKT_RX_FDIR_ID mbuf flags.
943 * See struct rte_flow_action_mark.
945 RTE_FLOW_ACTION_TYPE_MARK,
948 * Flags packets. Similar to MARK without a specific value; only
949 * sets the PKT_RX_FDIR mbuf flag.
951 * No associated configuration structure.
953 RTE_FLOW_ACTION_TYPE_FLAG,
956 * Assigns packets to a given queue index.
958 * See struct rte_flow_action_queue.
960 RTE_FLOW_ACTION_TYPE_QUEUE,
965 * PASSTHRU overrides this action if both are specified.
967 * No associated configuration structure.
969 RTE_FLOW_ACTION_TYPE_DROP,
972 * Enables counters for this flow rule.
974 * These counters can be retrieved and reset through rte_flow_query(),
975 * see struct rte_flow_query_count.
977 * No associated configuration structure.
979 RTE_FLOW_ACTION_TYPE_COUNT,
982 * Similar to QUEUE, except RSS is additionally performed on packets
983 * to spread them among several queues according to the provided
986 * See struct rte_flow_action_rss.
988 RTE_FLOW_ACTION_TYPE_RSS,
991 * Redirects packets to the physical function (PF) of the current
994 * No associated configuration structure.
996 RTE_FLOW_ACTION_TYPE_PF,
999 * Redirects packets to the virtual function (VF) of the current
1000 * device with the specified ID.
1002 * See struct rte_flow_action_vf.
1004 RTE_FLOW_ACTION_TYPE_VF,
1007 * Traffic metering and policing (MTR).
1009 * See struct rte_flow_action_meter.
1010 * See file rte_mtr.h for MTR object configuration.
1012 RTE_FLOW_ACTION_TYPE_METER,
1015 * Redirects packets to security engine of current device for security
1016 * processing as specified by security session.
1018 * See struct rte_flow_action_security.
1020 RTE_FLOW_ACTION_TYPE_SECURITY
1024 * RTE_FLOW_ACTION_TYPE_MARK
1026 * Attaches an integer value to packets and sets PKT_RX_FDIR and
1027 * PKT_RX_FDIR_ID mbuf flags.
1029 * This value is arbitrary and application-defined. Maximum allowed value
1030 * depends on the underlying implementation. It is returned in the
1031 * hash.fdir.hi mbuf field.
1033 struct rte_flow_action_mark {
1034 uint32_t id; /**< Integer value to return with packets. */
1038 * RTE_FLOW_ACTION_TYPE_QUEUE
1040 * Assign packets to a given queue index.
1042 struct rte_flow_action_queue {
1043 uint16_t index; /**< Queue index to use. */
1047 * RTE_FLOW_ACTION_TYPE_COUNT (query)
1049 * Query structure to retrieve and reset flow rule counters.
1051 struct rte_flow_query_count {
1052 uint32_t reset:1; /**< Reset counters after query [in]. */
1053 uint32_t hits_set:1; /**< hits field is set [out]. */
1054 uint32_t bytes_set:1; /**< bytes field is set [out]. */
1055 uint32_t reserved:29; /**< Reserved, must be zero [in, out]. */
1056 uint64_t hits; /**< Number of hits for this rule [out]. */
1057 uint64_t bytes; /**< Number of bytes through this rule [out]. */
1061 * RTE_FLOW_ACTION_TYPE_RSS
1063 * Similar to QUEUE, except RSS is additionally performed on packets to
1064 * spread them among several queues according to the provided parameters.
1066 * Unlike global RSS settings used by other DPDK APIs, unsetting the
1067 * @p types field does not disable RSS in a flow rule. Doing so instead
1068 * requests safe unspecified "best-effort" settings from the underlying PMD,
1069 * which depending on the flow rule, may result in anything ranging from
1070 * empty (single queue) to all-inclusive RSS.
1072 * Note: RSS hash result is stored in the hash.rss mbuf field which overlaps
1073 * hash.fdir.lo. Since the MARK action sets the hash.fdir.hi field only,
1074 * both can be requested simultaneously.
1076 struct rte_flow_action_rss {
1077 enum rte_eth_hash_function func; /**< RSS hash function to apply. */
1079 * Packet encapsulation level RSS hash @p types apply to.
1081 * - @p 0 requests the default behavior. Depending on the packet
1082 * type, it can mean outermost, innermost, anything in between or
1085 * It basically stands for the innermost encapsulation level RSS
1086 * can be performed on according to PMD and device capabilities.
1088 * - @p 1 requests RSS to be performed on the outermost packet
1089 * encapsulation level.
1091 * - @p 2 and subsequent values request RSS to be performed on the
1092 * specified inner packet encapsulation level, from outermost to
1093 * innermost (lower to higher values).
1095 * Values other than @p 0 are not necessarily supported.
1097 * Requesting a specific RSS level on unrecognized traffic results
1098 * in undefined behavior. For predictable results, it is recommended
1099 * to make the flow rule pattern match packet headers up to the
1100 * requested encapsulation level so that only matching traffic goes
1104 uint64_t types; /**< Specific RSS hash types (see ETH_RSS_*). */
1105 uint32_t key_len; /**< Hash key length in bytes. */
1106 uint32_t queue_num; /**< Number of entries in @p queue. */
1107 const uint8_t *key; /**< Hash key. */
1108 const uint16_t *queue; /**< Queue indices to use. */
1112 * RTE_FLOW_ACTION_TYPE_VF
1114 * Redirects packets to a virtual function (VF) of the current device.
1116 * Packets matched by a VF pattern item can be redirected to their original
1117 * VF ID instead of the specified one. This parameter may not be available
1118 * and is not guaranteed to work properly if the VF part is matched by a
1119 * prior flow rule or if packets are not addressed to a VF in the first
1122 struct rte_flow_action_vf {
1123 uint32_t original:1; /**< Use original VF ID if possible. */
1124 uint32_t reserved:31; /**< Reserved, must be zero. */
1125 uint32_t id; /**< VF ID to redirect packets to. */
1129 * RTE_FLOW_ACTION_TYPE_METER
1131 * Traffic metering and policing (MTR).
1133 * Packets matched by items of this type can be either dropped or passed to the
1134 * next item with their color set by the MTR object.
1136 struct rte_flow_action_meter {
1137 uint32_t mtr_id; /**< MTR object ID created with rte_mtr_create(). */
1141 * RTE_FLOW_ACTION_TYPE_SECURITY
1143 * Perform the security action on flows matched by the pattern items
1144 * according to the configuration of the security session.
1146 * This action modifies the payload of matched flows. For INLINE_CRYPTO, the
1147 * security protocol headers and IV are fully provided by the application as
1148 * specified in the flow pattern. The payload of matching packets is
1149 * encrypted on egress, and decrypted and authenticated on ingress.
1150 * For INLINE_PROTOCOL, the security protocol is fully offloaded to HW,
1151 * providing full encapsulation and decapsulation of packets in security
1152 * protocols. The flow pattern specifies both the outer security header fields
1153 * and the inner packet fields. The security session specified in the action
1154 * must match the pattern parameters.
1156 * The security session specified in the action must be created on the same
1157 * port as the flow action that is being specified.
1159 * The ingress/egress flow attribute should match that specified in the
1160 * security session if the security session supports the definition of the
1163 * Multiple flows can be configured to use the same security session.
1165 struct rte_flow_action_security {
1166 void *security_session; /**< Pointer to security session structure. */
1170 * Definition of a single action.
1172 * A list of actions is terminated by a END action.
1174 * For simple actions without a configuration structure, conf remains NULL.
1176 struct rte_flow_action {
1177 enum rte_flow_action_type type; /**< Action type. */
1178 const void *conf; /**< Pointer to action configuration structure. */
1182 * Opaque type returned after successfully creating a flow.
1184 * This handle can be used to manage and query the related flow (e.g. to
1185 * destroy it or retrieve counters).
1190 * Verbose error types.
1192 * Most of them provide the type of the object referenced by struct
1193 * rte_flow_error.cause.
1195 enum rte_flow_error_type {
1196 RTE_FLOW_ERROR_TYPE_NONE, /**< No error. */
1197 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, /**< Cause unspecified. */
1198 RTE_FLOW_ERROR_TYPE_HANDLE, /**< Flow rule (handle). */
1199 RTE_FLOW_ERROR_TYPE_ATTR_GROUP, /**< Group field. */
1200 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY, /**< Priority field. */
1201 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS, /**< Ingress field. */
1202 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, /**< Egress field. */
1203 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER, /**< Transfer field. */
1204 RTE_FLOW_ERROR_TYPE_ATTR, /**< Attributes structure. */
1205 RTE_FLOW_ERROR_TYPE_ITEM_NUM, /**< Pattern length. */
1206 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, /**< Item specification. */
1207 RTE_FLOW_ERROR_TYPE_ITEM_LAST, /**< Item specification range. */
1208 RTE_FLOW_ERROR_TYPE_ITEM_MASK, /**< Item specification mask. */
1209 RTE_FLOW_ERROR_TYPE_ITEM, /**< Specific pattern item. */
1210 RTE_FLOW_ERROR_TYPE_ACTION_NUM, /**< Number of actions. */
1211 RTE_FLOW_ERROR_TYPE_ACTION_CONF, /**< Action configuration. */
1212 RTE_FLOW_ERROR_TYPE_ACTION, /**< Specific action. */
1216 * Verbose error structure definition.
1218 * This object is normally allocated by applications and set by PMDs, the
1219 * message points to a constant string which does not need to be freed by
1220 * the application, however its pointer can be considered valid only as long
1221 * as its associated DPDK port remains configured. Closing the underlying
1222 * device or unloading the PMD invalidates it.
1224 * Both cause and message may be NULL regardless of the error type.
1226 struct rte_flow_error {
1227 enum rte_flow_error_type type; /**< Cause field and error types. */
1228 const void *cause; /**< Object responsible for the error. */
1229 const char *message; /**< Human-readable error message. */
1233 * Check whether a flow rule can be created on a given port.
1235 * The flow rule is validated for correctness and whether it could be accepted
1236 * by the device given sufficient resources. The rule is checked against the
1237 * current device mode and queue configuration. The flow rule may also
1238 * optionally be validated against existing flow rules and device resources.
1239 * This function has no effect on the target device.
1241 * The returned value is guaranteed to remain valid only as long as no
1242 * successful calls to rte_flow_create() or rte_flow_destroy() are made in
1243 * the meantime and no device parameter affecting flow rules in any way are
1244 * modified, due to possible collisions or resource limitations (although in
1245 * such cases EINVAL should not be returned).
1248 * Port identifier of Ethernet device.
1250 * Flow rule attributes.
1251 * @param[in] pattern
1252 * Pattern specification (list terminated by the END pattern item).
1253 * @param[in] actions
1254 * Associated actions (list terminated by the END action).
1256 * Perform verbose error reporting if not NULL. PMDs initialize this
1257 * structure in case of error only.
1260 * 0 if flow rule is valid and can be created. A negative errno value
1261 * otherwise (rte_errno is also set), the following errors are defined:
1263 * -ENOSYS: underlying device does not support this functionality.
1265 * -EIO: underlying device is removed.
1267 * -EINVAL: unknown or invalid rule specification.
1269 * -ENOTSUP: valid but unsupported rule specification (e.g. partial
1270 * bit-masks are unsupported).
1272 * -EEXIST: collision with an existing rule. Only returned if device
1273 * supports flow rule collision checking and there was a flow rule
1274 * collision. Not receiving this return code is no guarantee that creating
1275 * the rule will not fail due to a collision.
1277 * -ENOMEM: not enough memory to execute the function, or if the device
1278 * supports resource validation, resource limitation on the device.
1280 * -EBUSY: action cannot be performed due to busy device resources, may
1281 * succeed if the affected queues or even the entire port are in a stopped
1282 * state (see rte_eth_dev_rx_queue_stop() and rte_eth_dev_stop()).
1285 rte_flow_validate(uint16_t port_id,
1286 const struct rte_flow_attr *attr,
1287 const struct rte_flow_item pattern[],
1288 const struct rte_flow_action actions[],
1289 struct rte_flow_error *error);
1292 * Create a flow rule on a given port.
1295 * Port identifier of Ethernet device.
1297 * Flow rule attributes.
1298 * @param[in] pattern
1299 * Pattern specification (list terminated by the END pattern item).
1300 * @param[in] actions
1301 * Associated actions (list terminated by the END action).
1303 * Perform verbose error reporting if not NULL. PMDs initialize this
1304 * structure in case of error only.
1307 * A valid handle in case of success, NULL otherwise and rte_errno is set
1308 * to the positive version of one of the error codes defined for
1309 * rte_flow_validate().
1312 rte_flow_create(uint16_t port_id,
1313 const struct rte_flow_attr *attr,
1314 const struct rte_flow_item pattern[],
1315 const struct rte_flow_action actions[],
1316 struct rte_flow_error *error);
1319 * Destroy a flow rule on a given port.
1321 * Failure to destroy a flow rule handle may occur when other flow rules
1322 * depend on it, and destroying it would result in an inconsistent state.
1324 * This function is only guaranteed to succeed if handles are destroyed in
1325 * reverse order of their creation.
1328 * Port identifier of Ethernet device.
1330 * Flow rule handle to destroy.
1332 * Perform verbose error reporting if not NULL. PMDs initialize this
1333 * structure in case of error only.
1336 * 0 on success, a negative errno value otherwise and rte_errno is set.
1339 rte_flow_destroy(uint16_t port_id,
1340 struct rte_flow *flow,
1341 struct rte_flow_error *error);
1344 * Destroy all flow rules associated with a port.
1346 * In the unlikely event of failure, handles are still considered destroyed
1347 * and no longer valid but the port must be assumed to be in an inconsistent
1351 * Port identifier of Ethernet device.
1353 * Perform verbose error reporting if not NULL. PMDs initialize this
1354 * structure in case of error only.
1357 * 0 on success, a negative errno value otherwise and rte_errno is set.
1360 rte_flow_flush(uint16_t port_id,
1361 struct rte_flow_error *error);
1364 * Query an existing flow rule.
1366 * This function allows retrieving flow-specific data such as counters.
1367 * Data is gathered by special actions which must be present in the flow
1370 * \see RTE_FLOW_ACTION_TYPE_COUNT
1373 * Port identifier of Ethernet device.
1375 * Flow rule handle to query.
1377 * Action type to query.
1378 * @param[in, out] data
1379 * Pointer to storage for the associated query data type.
1381 * Perform verbose error reporting if not NULL. PMDs initialize this
1382 * structure in case of error only.
1385 * 0 on success, a negative errno value otherwise and rte_errno is set.
1388 rte_flow_query(uint16_t port_id,
1389 struct rte_flow *flow,
1390 enum rte_flow_action_type action,
1392 struct rte_flow_error *error);
1395 * Restrict ingress traffic to the defined flow rules.
1397 * Isolated mode guarantees that all ingress traffic comes from defined flow
1398 * rules only (current and future).
1400 * Besides making ingress more deterministic, it allows PMDs to safely reuse
1401 * resources otherwise assigned to handle the remaining traffic, such as
1402 * global RSS configuration settings, VLAN filters, MAC address entries,
1403 * legacy filter API rules and so on in order to expand the set of possible
1406 * Calling this function as soon as possible after device initialization,
1407 * ideally before the first call to rte_eth_dev_configure(), is recommended
1408 * to avoid possible failures due to conflicting settings.
1410 * Once effective, leaving isolated mode may not be possible depending on
1411 * PMD implementation.
1413 * Additionally, the following functionality has no effect on the underlying
1414 * port and may return errors such as ENOTSUP ("not supported"):
1416 * - Toggling promiscuous mode.
1417 * - Toggling allmulticast mode.
1418 * - Configuring MAC addresses.
1419 * - Configuring multicast addresses.
1420 * - Configuring VLAN filters.
1421 * - Configuring Rx filters through the legacy API (e.g. FDIR).
1422 * - Configuring global RSS settings.
1425 * Port identifier of Ethernet device.
1427 * Nonzero to enter isolated mode, attempt to leave it otherwise.
1429 * Perform verbose error reporting if not NULL. PMDs initialize this
1430 * structure in case of error only.
1433 * 0 on success, a negative errno value otherwise and rte_errno is set.
1436 rte_flow_isolate(uint16_t port_id, int set, struct rte_flow_error *error);
1439 * Initialize flow error structure.
1442 * Pointer to flow error structure (may be NULL).
1444 * Related error code (rte_errno).
1446 * Cause field and error types.
1448 * Object responsible for the error.
1450 * Human-readable error message.
1453 * Negative error code (errno value) and rte_errno is set.
1456 rte_flow_error_set(struct rte_flow_error *error,
1458 enum rte_flow_error_type type,
1460 const char *message);
1463 * Generic flow representation.
1465 * This form is sufficient to describe an rte_flow independently from any
1466 * PMD implementation and allows for replayability and identification.
1468 struct rte_flow_desc {
1469 size_t size; /**< Allocated space including data[]. */
1470 struct rte_flow_attr attr; /**< Attributes. */
1471 struct rte_flow_item *items; /**< Items. */
1472 struct rte_flow_action *actions; /**< Actions. */
1473 uint8_t data[]; /**< Storage for items/actions. */
1477 * Copy an rte_flow rule description.
1480 * Flow rule description.
1482 * Total size of allocated data for the flow description.
1484 * Flow rule attributes.
1486 * Pattern specification (list terminated by the END pattern item).
1487 * @param[in] actions
1488 * Associated actions (list terminated by the END action).
1491 * If len is greater or equal to the size of the flow, the total size of the
1492 * flow description and its data.
1493 * If len is lower than the size of the flow, the number of bytes that would
1494 * have been written to desc had it been sufficient. Nothing is written.
1497 rte_flow_copy(struct rte_flow_desc *fd, size_t len,
1498 const struct rte_flow_attr *attr,
1499 const struct rte_flow_item *items,
1500 const struct rte_flow_action *actions);
1506 #endif /* RTE_FLOW_H_ */