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,
185 * Matches traffic originating from (ingress) or going to (egress) a
186 * given DPDK port ID.
188 * See struct rte_flow_item_port_id.
190 RTE_FLOW_ITEM_TYPE_PORT_ID,
193 * Matches a byte string of a given length at a given offset.
195 * See struct rte_flow_item_raw.
197 RTE_FLOW_ITEM_TYPE_RAW,
200 * Matches an Ethernet header.
202 * See struct rte_flow_item_eth.
204 RTE_FLOW_ITEM_TYPE_ETH,
207 * Matches an 802.1Q/ad VLAN tag.
209 * See struct rte_flow_item_vlan.
211 RTE_FLOW_ITEM_TYPE_VLAN,
214 * Matches an IPv4 header.
216 * See struct rte_flow_item_ipv4.
218 RTE_FLOW_ITEM_TYPE_IPV4,
221 * Matches an IPv6 header.
223 * See struct rte_flow_item_ipv6.
225 RTE_FLOW_ITEM_TYPE_IPV6,
228 * Matches an ICMP header.
230 * See struct rte_flow_item_icmp.
232 RTE_FLOW_ITEM_TYPE_ICMP,
235 * Matches a UDP header.
237 * See struct rte_flow_item_udp.
239 RTE_FLOW_ITEM_TYPE_UDP,
242 * Matches a TCP header.
244 * See struct rte_flow_item_tcp.
246 RTE_FLOW_ITEM_TYPE_TCP,
249 * Matches a SCTP header.
251 * See struct rte_flow_item_sctp.
253 RTE_FLOW_ITEM_TYPE_SCTP,
256 * Matches a VXLAN header.
258 * See struct rte_flow_item_vxlan.
260 RTE_FLOW_ITEM_TYPE_VXLAN,
263 * Matches a E_TAG header.
265 * See struct rte_flow_item_e_tag.
267 RTE_FLOW_ITEM_TYPE_E_TAG,
270 * Matches a NVGRE header.
272 * See struct rte_flow_item_nvgre.
274 RTE_FLOW_ITEM_TYPE_NVGRE,
277 * Matches a MPLS header.
279 * See struct rte_flow_item_mpls.
281 RTE_FLOW_ITEM_TYPE_MPLS,
284 * Matches a GRE header.
286 * See struct rte_flow_item_gre.
288 RTE_FLOW_ITEM_TYPE_GRE,
293 * Fuzzy pattern match, expect faster than default.
295 * This is for device that support fuzzy matching option.
296 * Usually a fuzzy matching is fast but the cost is accuracy.
298 * See struct rte_flow_item_fuzzy.
300 RTE_FLOW_ITEM_TYPE_FUZZY,
303 * Matches a GTP header.
305 * Configure flow for GTP packets.
307 * See struct rte_flow_item_gtp.
309 RTE_FLOW_ITEM_TYPE_GTP,
312 * Matches a GTP header.
314 * Configure flow for GTP-C packets.
316 * See struct rte_flow_item_gtp.
318 RTE_FLOW_ITEM_TYPE_GTPC,
321 * Matches a GTP header.
323 * Configure flow for GTP-U packets.
325 * See struct rte_flow_item_gtp.
327 RTE_FLOW_ITEM_TYPE_GTPU,
330 * Matches a ESP header.
332 * See struct rte_flow_item_esp.
334 RTE_FLOW_ITEM_TYPE_ESP,
337 * Matches a GENEVE header.
339 * See struct rte_flow_item_geneve.
341 RTE_FLOW_ITEM_TYPE_GENEVE,
344 * Matches a VXLAN-GPE header.
346 * See struct rte_flow_item_vxlan_gpe.
348 RTE_FLOW_ITEM_TYPE_VXLAN_GPE,
352 * RTE_FLOW_ITEM_TYPE_ANY
354 * Matches any protocol in place of the current layer, a single ANY may also
355 * stand for several protocol layers.
357 * This is usually specified as the first pattern item when looking for a
358 * protocol anywhere in a packet.
360 * A zeroed mask stands for any number of layers.
362 struct rte_flow_item_any {
363 uint32_t num; /**< Number of layers covered. */
366 /** Default mask for RTE_FLOW_ITEM_TYPE_ANY. */
368 static const struct rte_flow_item_any rte_flow_item_any_mask = {
374 * RTE_FLOW_ITEM_TYPE_VF
376 * Matches traffic originating from (ingress) or going to (egress) a given
377 * virtual function of the current device.
379 * If supported, should work even if the virtual function is not managed by
380 * the application and thus not associated with a DPDK port ID.
382 * Note this pattern item does not match VF representors traffic which, as
383 * separate entities, should be addressed through their own DPDK port IDs.
385 * - Can be specified multiple times to match traffic addressed to several
387 * - Can be combined with a PF item to match both PF and VF traffic.
389 * A zeroed mask can be used to match any VF ID.
391 struct rte_flow_item_vf {
392 uint32_t id; /**< VF ID. */
395 /** Default mask for RTE_FLOW_ITEM_TYPE_VF. */
397 static const struct rte_flow_item_vf rte_flow_item_vf_mask = {
403 * RTE_FLOW_ITEM_TYPE_PHY_PORT
405 * Matches traffic originating from (ingress) or going to (egress) a
406 * physical port of the underlying device.
408 * The first PHY_PORT item overrides the physical port normally associated
409 * with the specified DPDK input port (port_id). This item can be provided
410 * several times to match additional physical ports.
412 * Note that physical ports are not necessarily tied to DPDK input ports
413 * (port_id) when those are not under DPDK control. Possible values are
414 * specific to each device, they are not necessarily indexed from zero and
415 * may not be contiguous.
417 * As a device property, the list of allowed values as well as the value
418 * associated with a port_id should be retrieved by other means.
420 * A zeroed mask can be used to match any port index.
422 struct rte_flow_item_phy_port {
423 uint32_t index; /**< Physical port index. */
426 /** Default mask for RTE_FLOW_ITEM_TYPE_PHY_PORT. */
428 static const struct rte_flow_item_phy_port rte_flow_item_phy_port_mask = {
434 * RTE_FLOW_ITEM_TYPE_PORT_ID
436 * Matches traffic originating from (ingress) or going to (egress) a given
439 * Normally only supported if the port ID in question is known by the
440 * underlying PMD and related to the device the flow rule is created
443 * This must not be confused with @p PHY_PORT which refers to the physical
444 * port of a device, whereas @p PORT_ID refers to a struct rte_eth_dev
445 * object on the application side (also known as "port representor"
446 * depending on the kind of underlying device).
448 struct rte_flow_item_port_id {
449 uint32_t id; /**< DPDK port ID. */
452 /** Default mask for RTE_FLOW_ITEM_TYPE_PORT_ID. */
454 static const struct rte_flow_item_port_id rte_flow_item_port_id_mask = {
460 * RTE_FLOW_ITEM_TYPE_RAW
462 * Matches a byte string of a given length at a given offset.
464 * Offset is either absolute (using the start of the packet) or relative to
465 * the end of the previous matched item in the stack, in which case negative
466 * values are allowed.
468 * If search is enabled, offset is used as the starting point. The search
469 * area can be delimited by setting limit to a nonzero value, which is the
470 * maximum number of bytes after offset where the pattern may start.
472 * Matching a zero-length pattern is allowed, doing so resets the relative
473 * offset for subsequent items.
475 * This type does not support ranges (struct rte_flow_item.last).
477 struct rte_flow_item_raw {
478 uint32_t relative:1; /**< Look for pattern after the previous item. */
479 uint32_t search:1; /**< Search pattern from offset (see also limit). */
480 uint32_t reserved:30; /**< Reserved, must be set to zero. */
481 int32_t offset; /**< Absolute or relative offset for pattern. */
482 uint16_t limit; /**< Search area limit for start of pattern. */
483 uint16_t length; /**< Pattern length. */
484 const uint8_t *pattern; /**< Byte string to look for. */
487 /** Default mask for RTE_FLOW_ITEM_TYPE_RAW. */
489 static const struct rte_flow_item_raw rte_flow_item_raw_mask = {
492 .reserved = 0x3fffffff,
493 .offset = 0xffffffff,
501 * RTE_FLOW_ITEM_TYPE_ETH
503 * Matches an Ethernet header.
505 * The @p type field either stands for "EtherType" or "TPID" when followed
506 * by so-called layer 2.5 pattern items such as RTE_FLOW_ITEM_TYPE_VLAN. In
507 * the latter case, @p type refers to that of the outer header, with the
508 * inner EtherType/TPID provided by the subsequent pattern item. This is the
509 * same order as on the wire.
511 struct rte_flow_item_eth {
512 struct ether_addr dst; /**< Destination MAC. */
513 struct ether_addr src; /**< Source MAC. */
514 rte_be16_t type; /**< EtherType or TPID. */
517 /** Default mask for RTE_FLOW_ITEM_TYPE_ETH. */
519 static const struct rte_flow_item_eth rte_flow_item_eth_mask = {
520 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
521 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
522 .type = RTE_BE16(0x0000),
527 * RTE_FLOW_ITEM_TYPE_VLAN
529 * Matches an 802.1Q/ad VLAN tag.
531 * The corresponding standard outer EtherType (TPID) values are
532 * ETHER_TYPE_VLAN or ETHER_TYPE_QINQ. It can be overridden by the preceding
535 struct rte_flow_item_vlan {
536 rte_be16_t tci; /**< Tag control information. */
537 rte_be16_t inner_type; /**< Inner EtherType or TPID. */
540 /** Default mask for RTE_FLOW_ITEM_TYPE_VLAN. */
542 static const struct rte_flow_item_vlan rte_flow_item_vlan_mask = {
543 .tci = RTE_BE16(0x0fff),
544 .inner_type = RTE_BE16(0x0000),
549 * RTE_FLOW_ITEM_TYPE_IPV4
551 * Matches an IPv4 header.
553 * Note: IPv4 options are handled by dedicated pattern items.
555 struct rte_flow_item_ipv4 {
556 struct ipv4_hdr hdr; /**< IPv4 header definition. */
559 /** Default mask for RTE_FLOW_ITEM_TYPE_IPV4. */
561 static const struct rte_flow_item_ipv4 rte_flow_item_ipv4_mask = {
563 .src_addr = RTE_BE32(0xffffffff),
564 .dst_addr = RTE_BE32(0xffffffff),
570 * RTE_FLOW_ITEM_TYPE_IPV6.
572 * Matches an IPv6 header.
574 * Note: IPv6 options are handled by dedicated pattern items.
576 struct rte_flow_item_ipv6 {
577 struct ipv6_hdr hdr; /**< IPv6 header definition. */
580 /** Default mask for RTE_FLOW_ITEM_TYPE_IPV6. */
582 static const struct rte_flow_item_ipv6 rte_flow_item_ipv6_mask = {
585 "\xff\xff\xff\xff\xff\xff\xff\xff"
586 "\xff\xff\xff\xff\xff\xff\xff\xff",
588 "\xff\xff\xff\xff\xff\xff\xff\xff"
589 "\xff\xff\xff\xff\xff\xff\xff\xff",
595 * RTE_FLOW_ITEM_TYPE_ICMP.
597 * Matches an ICMP header.
599 struct rte_flow_item_icmp {
600 struct icmp_hdr hdr; /**< ICMP header definition. */
603 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP. */
605 static const struct rte_flow_item_icmp rte_flow_item_icmp_mask = {
614 * RTE_FLOW_ITEM_TYPE_UDP.
616 * Matches a UDP header.
618 struct rte_flow_item_udp {
619 struct udp_hdr hdr; /**< UDP header definition. */
622 /** Default mask for RTE_FLOW_ITEM_TYPE_UDP. */
624 static const struct rte_flow_item_udp rte_flow_item_udp_mask = {
626 .src_port = RTE_BE16(0xffff),
627 .dst_port = RTE_BE16(0xffff),
633 * RTE_FLOW_ITEM_TYPE_TCP.
635 * Matches a TCP header.
637 struct rte_flow_item_tcp {
638 struct tcp_hdr hdr; /**< TCP header definition. */
641 /** Default mask for RTE_FLOW_ITEM_TYPE_TCP. */
643 static const struct rte_flow_item_tcp rte_flow_item_tcp_mask = {
645 .src_port = RTE_BE16(0xffff),
646 .dst_port = RTE_BE16(0xffff),
652 * RTE_FLOW_ITEM_TYPE_SCTP.
654 * Matches a SCTP header.
656 struct rte_flow_item_sctp {
657 struct sctp_hdr hdr; /**< SCTP header definition. */
660 /** Default mask for RTE_FLOW_ITEM_TYPE_SCTP. */
662 static const struct rte_flow_item_sctp rte_flow_item_sctp_mask = {
664 .src_port = RTE_BE16(0xffff),
665 .dst_port = RTE_BE16(0xffff),
671 * RTE_FLOW_ITEM_TYPE_VXLAN.
673 * Matches a VXLAN header (RFC 7348).
675 struct rte_flow_item_vxlan {
676 uint8_t flags; /**< Normally 0x08 (I flag). */
677 uint8_t rsvd0[3]; /**< Reserved, normally 0x000000. */
678 uint8_t vni[3]; /**< VXLAN identifier. */
679 uint8_t rsvd1; /**< Reserved, normally 0x00. */
682 /** Default mask for RTE_FLOW_ITEM_TYPE_VXLAN. */
684 static const struct rte_flow_item_vxlan rte_flow_item_vxlan_mask = {
685 .vni = "\xff\xff\xff",
690 * RTE_FLOW_ITEM_TYPE_E_TAG.
692 * Matches a E-tag header.
694 * The corresponding standard outer EtherType (TPID) value is
695 * ETHER_TYPE_ETAG. It can be overridden by the preceding pattern item.
697 struct rte_flow_item_e_tag {
699 * E-Tag control information (E-TCI).
700 * E-PCP (3b), E-DEI (1b), ingress E-CID base (12b).
702 rte_be16_t epcp_edei_in_ecid_b;
703 /** Reserved (2b), GRP (2b), E-CID base (12b). */
704 rte_be16_t rsvd_grp_ecid_b;
705 uint8_t in_ecid_e; /**< Ingress E-CID ext. */
706 uint8_t ecid_e; /**< E-CID ext. */
707 rte_be16_t inner_type; /**< Inner EtherType or TPID. */
710 /** Default mask for RTE_FLOW_ITEM_TYPE_E_TAG. */
712 static const struct rte_flow_item_e_tag rte_flow_item_e_tag_mask = {
713 .rsvd_grp_ecid_b = RTE_BE16(0x3fff),
718 * RTE_FLOW_ITEM_TYPE_NVGRE.
720 * Matches a NVGRE header.
722 struct rte_flow_item_nvgre {
724 * Checksum (1b), undefined (1b), key bit (1b), sequence number (1b),
725 * reserved 0 (9b), version (3b).
727 * c_k_s_rsvd0_ver must have value 0x2000 according to RFC 7637.
729 rte_be16_t c_k_s_rsvd0_ver;
730 rte_be16_t protocol; /**< Protocol type (0x6558). */
731 uint8_t tni[3]; /**< Virtual subnet ID. */
732 uint8_t flow_id; /**< Flow ID. */
735 /** Default mask for RTE_FLOW_ITEM_TYPE_NVGRE. */
737 static const struct rte_flow_item_nvgre rte_flow_item_nvgre_mask = {
738 .tni = "\xff\xff\xff",
743 * RTE_FLOW_ITEM_TYPE_MPLS.
745 * Matches a MPLS header.
747 struct rte_flow_item_mpls {
749 * Label (20b), TC (3b), Bottom of Stack (1b).
751 uint8_t label_tc_s[3];
752 uint8_t ttl; /** Time-to-Live. */
755 /** Default mask for RTE_FLOW_ITEM_TYPE_MPLS. */
757 static const struct rte_flow_item_mpls rte_flow_item_mpls_mask = {
758 .label_tc_s = "\xff\xff\xf0",
763 * RTE_FLOW_ITEM_TYPE_GRE.
765 * Matches a GRE header.
767 struct rte_flow_item_gre {
769 * Checksum (1b), reserved 0 (12b), version (3b).
772 rte_be16_t c_rsvd0_ver;
773 rte_be16_t protocol; /**< Protocol type. */
776 /** Default mask for RTE_FLOW_ITEM_TYPE_GRE. */
778 static const struct rte_flow_item_gre rte_flow_item_gre_mask = {
779 .protocol = RTE_BE16(0xffff),
784 * RTE_FLOW_ITEM_TYPE_FUZZY
786 * Fuzzy pattern match, expect faster than default.
788 * This is for device that support fuzzy match option.
789 * Usually a fuzzy match is fast but the cost is accuracy.
790 * i.e. Signature Match only match pattern's hash value, but it is
791 * possible two different patterns have the same hash value.
793 * Matching accuracy level can be configure by threshold.
794 * Driver can divide the range of threshold and map to different
795 * accuracy levels that device support.
797 * Threshold 0 means perfect match (no fuzziness), while threshold
798 * 0xffffffff means fuzziest match.
800 struct rte_flow_item_fuzzy {
801 uint32_t thresh; /**< Accuracy threshold. */
804 /** Default mask for RTE_FLOW_ITEM_TYPE_FUZZY. */
806 static const struct rte_flow_item_fuzzy rte_flow_item_fuzzy_mask = {
807 .thresh = 0xffffffff,
812 * RTE_FLOW_ITEM_TYPE_GTP.
814 * Matches a GTPv1 header.
816 struct rte_flow_item_gtp {
818 * Version (3b), protocol type (1b), reserved (1b),
819 * Extension header flag (1b),
820 * Sequence number flag (1b),
821 * N-PDU number flag (1b).
823 uint8_t v_pt_rsv_flags;
824 uint8_t msg_type; /**< Message type. */
825 rte_be16_t msg_len; /**< Message length. */
826 rte_be32_t teid; /**< Tunnel endpoint identifier. */
829 /** Default mask for RTE_FLOW_ITEM_TYPE_GTP. */
831 static const struct rte_flow_item_gtp rte_flow_item_gtp_mask = {
832 .teid = RTE_BE32(0xffffffff),
837 * RTE_FLOW_ITEM_TYPE_ESP
839 * Matches an ESP header.
841 struct rte_flow_item_esp {
842 struct esp_hdr hdr; /**< ESP header definition. */
845 /** Default mask for RTE_FLOW_ITEM_TYPE_ESP. */
847 static const struct rte_flow_item_esp rte_flow_item_esp_mask = {
855 * RTE_FLOW_ITEM_TYPE_GENEVE.
857 * Matches a GENEVE header.
859 struct rte_flow_item_geneve {
861 * Version (2b), length of the options fields (6b), OAM packet (1b),
862 * critical options present (1b), reserved 0 (6b).
864 rte_be16_t ver_opt_len_o_c_rsvd0;
865 rte_be16_t protocol; /**< Protocol type. */
866 uint8_t vni[3]; /**< Virtual Network Identifier. */
867 uint8_t rsvd1; /**< Reserved, normally 0x00. */
870 /** Default mask for RTE_FLOW_ITEM_TYPE_GENEVE. */
872 static const struct rte_flow_item_geneve rte_flow_item_geneve_mask = {
873 .vni = "\xff\xff\xff",
878 * RTE_FLOW_ITEM_TYPE_VXLAN_GPE (draft-ietf-nvo3-vxlan-gpe-05).
880 * Matches a VXLAN-GPE header.
882 struct rte_flow_item_vxlan_gpe {
883 uint8_t flags; /**< Normally 0x0c (I and P flags). */
884 uint8_t rsvd0[2]; /**< Reserved, normally 0x0000. */
885 uint8_t protocol; /**< Protocol type. */
886 uint8_t vni[3]; /**< VXLAN identifier. */
887 uint8_t rsvd1; /**< Reserved, normally 0x00. */
890 /** Default mask for RTE_FLOW_ITEM_TYPE_VXLAN_GPE. */
892 static const struct rte_flow_item_vxlan_gpe rte_flow_item_vxlan_gpe_mask = {
893 .vni = "\xff\xff\xff",
898 * Matching pattern item definition.
900 * A pattern is formed by stacking items starting from the lowest protocol
901 * layer to match. This stacking restriction does not apply to meta items
902 * which can be placed anywhere in the stack without affecting the meaning
903 * of the resulting pattern.
905 * Patterns are terminated by END items.
907 * The spec field should be a valid pointer to a structure of the related
908 * item type. It may remain unspecified (NULL) in many cases to request
909 * broad (nonspecific) matching. In such cases, last and mask must also be
912 * Optionally, last can point to a structure of the same type to define an
913 * inclusive range. This is mostly supported by integer and address fields,
914 * may cause errors otherwise. Fields that do not support ranges must be set
915 * to 0 or to the same value as the corresponding fields in spec.
917 * Only the fields defined to nonzero values in the default masks (see
918 * rte_flow_item_{name}_mask constants) are considered relevant by
919 * default. This can be overridden by providing a mask structure of the
920 * same type with applicable bits set to one. It can also be used to
921 * partially filter out specific fields (e.g. as an alternate mean to match
922 * ranges of IP addresses).
924 * Mask is a simple bit-mask applied before interpreting the contents of
925 * spec and last, which may yield unexpected results if not used
926 * carefully. For example, if for an IPv4 address field, spec provides
927 * 10.1.2.3, last provides 10.3.4.5 and mask provides 255.255.0.0, the
928 * effective range becomes 10.1.0.0 to 10.3.255.255.
930 struct rte_flow_item {
931 enum rte_flow_item_type type; /**< Item type. */
932 const void *spec; /**< Pointer to item specification structure. */
933 const void *last; /**< Defines an inclusive range (spec to last). */
934 const void *mask; /**< Bit-mask applied to spec and last. */
940 * Each possible action is represented by a type. Some have associated
941 * configuration structures. Several actions combined in a list can be
942 * assigned to a flow rule and are performed in order.
944 * They fall in three categories:
946 * - Actions that modify the fate of matching traffic, for instance by
947 * dropping or assigning it a specific destination.
949 * - Actions that modify matching traffic contents or its properties. This
950 * includes adding/removing encapsulation, encryption, compression and
953 * - Actions related to the flow rule itself, such as updating counters or
954 * making it non-terminating.
956 * Flow rules being terminating by default, not specifying any action of the
957 * fate kind results in undefined behavior. This applies to both ingress and
960 * PASSTHRU, when supported, makes a flow rule non-terminating.
962 enum rte_flow_action_type {
964 * End marker for action lists. Prevents further processing of
965 * actions, thereby ending the list.
967 * No associated configuration structure.
969 RTE_FLOW_ACTION_TYPE_END,
972 * Used as a placeholder for convenience. It is ignored and simply
975 * No associated configuration structure.
977 RTE_FLOW_ACTION_TYPE_VOID,
980 * Leaves traffic up for additional processing by subsequent flow
981 * rules; makes a flow rule non-terminating.
983 * No associated configuration structure.
985 RTE_FLOW_ACTION_TYPE_PASSTHRU,
988 * Attaches an integer value to packets and sets PKT_RX_FDIR and
989 * PKT_RX_FDIR_ID mbuf flags.
991 * See struct rte_flow_action_mark.
993 RTE_FLOW_ACTION_TYPE_MARK,
996 * Flags packets. Similar to MARK without a specific value; only
997 * sets the PKT_RX_FDIR mbuf flag.
999 * No associated configuration structure.
1001 RTE_FLOW_ACTION_TYPE_FLAG,
1004 * Assigns packets to a given queue index.
1006 * See struct rte_flow_action_queue.
1008 RTE_FLOW_ACTION_TYPE_QUEUE,
1013 * PASSTHRU overrides this action if both are specified.
1015 * No associated configuration structure.
1017 RTE_FLOW_ACTION_TYPE_DROP,
1020 * Enables counters for this flow rule.
1022 * These counters can be retrieved and reset through rte_flow_query(),
1023 * see struct rte_flow_query_count.
1025 * No associated configuration structure.
1027 RTE_FLOW_ACTION_TYPE_COUNT,
1030 * Similar to QUEUE, except RSS is additionally performed on packets
1031 * to spread them among several queues according to the provided
1034 * See struct rte_flow_action_rss.
1036 RTE_FLOW_ACTION_TYPE_RSS,
1039 * Directs matching traffic to the physical function (PF) of the
1042 * No associated configuration structure.
1044 RTE_FLOW_ACTION_TYPE_PF,
1047 * Directs matching traffic to a given virtual function of the
1050 * See struct rte_flow_action_vf.
1052 RTE_FLOW_ACTION_TYPE_VF,
1055 * Directs packets to a given physical port index of the underlying
1058 * See struct rte_flow_action_phy_port.
1060 RTE_FLOW_ACTION_TYPE_PHY_PORT,
1063 * Directs matching traffic to a given DPDK port ID.
1065 * See struct rte_flow_action_port_id.
1067 RTE_FLOW_ACTION_TYPE_PORT_ID,
1070 * Traffic metering and policing (MTR).
1072 * See struct rte_flow_action_meter.
1073 * See file rte_mtr.h for MTR object configuration.
1075 RTE_FLOW_ACTION_TYPE_METER,
1078 * Redirects packets to security engine of current device for security
1079 * processing as specified by security session.
1081 * See struct rte_flow_action_security.
1083 RTE_FLOW_ACTION_TYPE_SECURITY
1087 * RTE_FLOW_ACTION_TYPE_MARK
1089 * Attaches an integer value to packets and sets PKT_RX_FDIR and
1090 * PKT_RX_FDIR_ID mbuf flags.
1092 * This value is arbitrary and application-defined. Maximum allowed value
1093 * depends on the underlying implementation. It is returned in the
1094 * hash.fdir.hi mbuf field.
1096 struct rte_flow_action_mark {
1097 uint32_t id; /**< Integer value to return with packets. */
1101 * RTE_FLOW_ACTION_TYPE_QUEUE
1103 * Assign packets to a given queue index.
1105 struct rte_flow_action_queue {
1106 uint16_t index; /**< Queue index to use. */
1110 * RTE_FLOW_ACTION_TYPE_COUNT (query)
1112 * Query structure to retrieve and reset flow rule counters.
1114 struct rte_flow_query_count {
1115 uint32_t reset:1; /**< Reset counters after query [in]. */
1116 uint32_t hits_set:1; /**< hits field is set [out]. */
1117 uint32_t bytes_set:1; /**< bytes field is set [out]. */
1118 uint32_t reserved:29; /**< Reserved, must be zero [in, out]. */
1119 uint64_t hits; /**< Number of hits for this rule [out]. */
1120 uint64_t bytes; /**< Number of bytes through this rule [out]. */
1124 * RTE_FLOW_ACTION_TYPE_RSS
1126 * Similar to QUEUE, except RSS is additionally performed on packets to
1127 * spread them among several queues according to the provided parameters.
1129 * Unlike global RSS settings used by other DPDK APIs, unsetting the
1130 * @p types field does not disable RSS in a flow rule. Doing so instead
1131 * requests safe unspecified "best-effort" settings from the underlying PMD,
1132 * which depending on the flow rule, may result in anything ranging from
1133 * empty (single queue) to all-inclusive RSS.
1135 * Note: RSS hash result is stored in the hash.rss mbuf field which overlaps
1136 * hash.fdir.lo. Since the MARK action sets the hash.fdir.hi field only,
1137 * both can be requested simultaneously.
1139 struct rte_flow_action_rss {
1140 enum rte_eth_hash_function func; /**< RSS hash function to apply. */
1142 * Packet encapsulation level RSS hash @p types apply to.
1144 * - @p 0 requests the default behavior. Depending on the packet
1145 * type, it can mean outermost, innermost, anything in between or
1148 * It basically stands for the innermost encapsulation level RSS
1149 * can be performed on according to PMD and device capabilities.
1151 * - @p 1 requests RSS to be performed on the outermost packet
1152 * encapsulation level.
1154 * - @p 2 and subsequent values request RSS to be performed on the
1155 * specified inner packet encapsulation level, from outermost to
1156 * innermost (lower to higher values).
1158 * Values other than @p 0 are not necessarily supported.
1160 * Requesting a specific RSS level on unrecognized traffic results
1161 * in undefined behavior. For predictable results, it is recommended
1162 * to make the flow rule pattern match packet headers up to the
1163 * requested encapsulation level so that only matching traffic goes
1167 uint64_t types; /**< Specific RSS hash types (see ETH_RSS_*). */
1168 uint32_t key_len; /**< Hash key length in bytes. */
1169 uint32_t queue_num; /**< Number of entries in @p queue. */
1170 const uint8_t *key; /**< Hash key. */
1171 const uint16_t *queue; /**< Queue indices to use. */
1175 * RTE_FLOW_ACTION_TYPE_VF
1177 * Directs matching traffic to a given virtual function of the current
1180 * Packets matched by a VF pattern item can be redirected to their original
1181 * VF ID instead of the specified one. This parameter may not be available
1182 * and is not guaranteed to work properly if the VF part is matched by a
1183 * prior flow rule or if packets are not addressed to a VF in the first
1186 struct rte_flow_action_vf {
1187 uint32_t original:1; /**< Use original VF ID if possible. */
1188 uint32_t reserved:31; /**< Reserved, must be zero. */
1189 uint32_t id; /**< VF ID. */
1193 * RTE_FLOW_ACTION_TYPE_PHY_PORT
1195 * Directs packets to a given physical port index of the underlying
1198 * @see RTE_FLOW_ITEM_TYPE_PHY_PORT
1200 struct rte_flow_action_phy_port {
1201 uint32_t original:1; /**< Use original port index if possible. */
1202 uint32_t reserved:31; /**< Reserved, must be zero. */
1203 uint32_t index; /**< Physical port index. */
1207 * RTE_FLOW_ACTION_TYPE_PORT_ID
1209 * Directs matching traffic to a given DPDK port ID.
1211 * @see RTE_FLOW_ITEM_TYPE_PORT_ID
1213 struct rte_flow_action_port_id {
1214 uint32_t original:1; /**< Use original DPDK port ID if possible. */
1215 uint32_t reserved:31; /**< Reserved, must be zero. */
1216 uint32_t id; /**< DPDK port ID. */
1220 * RTE_FLOW_ACTION_TYPE_METER
1222 * Traffic metering and policing (MTR).
1224 * Packets matched by items of this type can be either dropped or passed to the
1225 * next item with their color set by the MTR object.
1227 struct rte_flow_action_meter {
1228 uint32_t mtr_id; /**< MTR object ID created with rte_mtr_create(). */
1232 * RTE_FLOW_ACTION_TYPE_SECURITY
1234 * Perform the security action on flows matched by the pattern items
1235 * according to the configuration of the security session.
1237 * This action modifies the payload of matched flows. For INLINE_CRYPTO, the
1238 * security protocol headers and IV are fully provided by the application as
1239 * specified in the flow pattern. The payload of matching packets is
1240 * encrypted on egress, and decrypted and authenticated on ingress.
1241 * For INLINE_PROTOCOL, the security protocol is fully offloaded to HW,
1242 * providing full encapsulation and decapsulation of packets in security
1243 * protocols. The flow pattern specifies both the outer security header fields
1244 * and the inner packet fields. The security session specified in the action
1245 * must match the pattern parameters.
1247 * The security session specified in the action must be created on the same
1248 * port as the flow action that is being specified.
1250 * The ingress/egress flow attribute should match that specified in the
1251 * security session if the security session supports the definition of the
1254 * Multiple flows can be configured to use the same security session.
1256 struct rte_flow_action_security {
1257 void *security_session; /**< Pointer to security session structure. */
1261 * Definition of a single action.
1263 * A list of actions is terminated by a END action.
1265 * For simple actions without a configuration structure, conf remains NULL.
1267 struct rte_flow_action {
1268 enum rte_flow_action_type type; /**< Action type. */
1269 const void *conf; /**< Pointer to action configuration structure. */
1273 * Opaque type returned after successfully creating a flow.
1275 * This handle can be used to manage and query the related flow (e.g. to
1276 * destroy it or retrieve counters).
1281 * Verbose error types.
1283 * Most of them provide the type of the object referenced by struct
1284 * rte_flow_error.cause.
1286 enum rte_flow_error_type {
1287 RTE_FLOW_ERROR_TYPE_NONE, /**< No error. */
1288 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, /**< Cause unspecified. */
1289 RTE_FLOW_ERROR_TYPE_HANDLE, /**< Flow rule (handle). */
1290 RTE_FLOW_ERROR_TYPE_ATTR_GROUP, /**< Group field. */
1291 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY, /**< Priority field. */
1292 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS, /**< Ingress field. */
1293 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, /**< Egress field. */
1294 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER, /**< Transfer field. */
1295 RTE_FLOW_ERROR_TYPE_ATTR, /**< Attributes structure. */
1296 RTE_FLOW_ERROR_TYPE_ITEM_NUM, /**< Pattern length. */
1297 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, /**< Item specification. */
1298 RTE_FLOW_ERROR_TYPE_ITEM_LAST, /**< Item specification range. */
1299 RTE_FLOW_ERROR_TYPE_ITEM_MASK, /**< Item specification mask. */
1300 RTE_FLOW_ERROR_TYPE_ITEM, /**< Specific pattern item. */
1301 RTE_FLOW_ERROR_TYPE_ACTION_NUM, /**< Number of actions. */
1302 RTE_FLOW_ERROR_TYPE_ACTION_CONF, /**< Action configuration. */
1303 RTE_FLOW_ERROR_TYPE_ACTION, /**< Specific action. */
1307 * Verbose error structure definition.
1309 * This object is normally allocated by applications and set by PMDs, the
1310 * message points to a constant string which does not need to be freed by
1311 * the application, however its pointer can be considered valid only as long
1312 * as its associated DPDK port remains configured. Closing the underlying
1313 * device or unloading the PMD invalidates it.
1315 * Both cause and message may be NULL regardless of the error type.
1317 struct rte_flow_error {
1318 enum rte_flow_error_type type; /**< Cause field and error types. */
1319 const void *cause; /**< Object responsible for the error. */
1320 const char *message; /**< Human-readable error message. */
1324 * Check whether a flow rule can be created on a given port.
1326 * The flow rule is validated for correctness and whether it could be accepted
1327 * by the device given sufficient resources. The rule is checked against the
1328 * current device mode and queue configuration. The flow rule may also
1329 * optionally be validated against existing flow rules and device resources.
1330 * This function has no effect on the target device.
1332 * The returned value is guaranteed to remain valid only as long as no
1333 * successful calls to rte_flow_create() or rte_flow_destroy() are made in
1334 * the meantime and no device parameter affecting flow rules in any way are
1335 * modified, due to possible collisions or resource limitations (although in
1336 * such cases EINVAL should not be returned).
1339 * Port identifier of Ethernet device.
1341 * Flow rule attributes.
1342 * @param[in] pattern
1343 * Pattern specification (list terminated by the END pattern item).
1344 * @param[in] actions
1345 * Associated actions (list terminated by the END action).
1347 * Perform verbose error reporting if not NULL. PMDs initialize this
1348 * structure in case of error only.
1351 * 0 if flow rule is valid and can be created. A negative errno value
1352 * otherwise (rte_errno is also set), the following errors are defined:
1354 * -ENOSYS: underlying device does not support this functionality.
1356 * -EIO: underlying device is removed.
1358 * -EINVAL: unknown or invalid rule specification.
1360 * -ENOTSUP: valid but unsupported rule specification (e.g. partial
1361 * bit-masks are unsupported).
1363 * -EEXIST: collision with an existing rule. Only returned if device
1364 * supports flow rule collision checking and there was a flow rule
1365 * collision. Not receiving this return code is no guarantee that creating
1366 * the rule will not fail due to a collision.
1368 * -ENOMEM: not enough memory to execute the function, or if the device
1369 * supports resource validation, resource limitation on the device.
1371 * -EBUSY: action cannot be performed due to busy device resources, may
1372 * succeed if the affected queues or even the entire port are in a stopped
1373 * state (see rte_eth_dev_rx_queue_stop() and rte_eth_dev_stop()).
1376 rte_flow_validate(uint16_t port_id,
1377 const struct rte_flow_attr *attr,
1378 const struct rte_flow_item pattern[],
1379 const struct rte_flow_action actions[],
1380 struct rte_flow_error *error);
1383 * Create a flow rule on a given port.
1386 * Port identifier of Ethernet device.
1388 * Flow rule attributes.
1389 * @param[in] pattern
1390 * Pattern specification (list terminated by the END pattern item).
1391 * @param[in] actions
1392 * Associated actions (list terminated by the END action).
1394 * Perform verbose error reporting if not NULL. PMDs initialize this
1395 * structure in case of error only.
1398 * A valid handle in case of success, NULL otherwise and rte_errno is set
1399 * to the positive version of one of the error codes defined for
1400 * rte_flow_validate().
1403 rte_flow_create(uint16_t port_id,
1404 const struct rte_flow_attr *attr,
1405 const struct rte_flow_item pattern[],
1406 const struct rte_flow_action actions[],
1407 struct rte_flow_error *error);
1410 * Destroy a flow rule on a given port.
1412 * Failure to destroy a flow rule handle may occur when other flow rules
1413 * depend on it, and destroying it would result in an inconsistent state.
1415 * This function is only guaranteed to succeed if handles are destroyed in
1416 * reverse order of their creation.
1419 * Port identifier of Ethernet device.
1421 * Flow rule handle to destroy.
1423 * Perform verbose error reporting if not NULL. PMDs initialize this
1424 * structure in case of error only.
1427 * 0 on success, a negative errno value otherwise and rte_errno is set.
1430 rte_flow_destroy(uint16_t port_id,
1431 struct rte_flow *flow,
1432 struct rte_flow_error *error);
1435 * Destroy all flow rules associated with a port.
1437 * In the unlikely event of failure, handles are still considered destroyed
1438 * and no longer valid but the port must be assumed to be in an inconsistent
1442 * Port identifier of Ethernet device.
1444 * Perform verbose error reporting if not NULL. PMDs initialize this
1445 * structure in case of error only.
1448 * 0 on success, a negative errno value otherwise and rte_errno is set.
1451 rte_flow_flush(uint16_t port_id,
1452 struct rte_flow_error *error);
1455 * Query an existing flow rule.
1457 * This function allows retrieving flow-specific data such as counters.
1458 * Data is gathered by special actions which must be present in the flow
1461 * \see RTE_FLOW_ACTION_TYPE_COUNT
1464 * Port identifier of Ethernet device.
1466 * Flow rule handle to query.
1468 * Action type to query.
1469 * @param[in, out] data
1470 * Pointer to storage for the associated query data type.
1472 * Perform verbose error reporting if not NULL. PMDs initialize this
1473 * structure in case of error only.
1476 * 0 on success, a negative errno value otherwise and rte_errno is set.
1479 rte_flow_query(uint16_t port_id,
1480 struct rte_flow *flow,
1481 enum rte_flow_action_type action,
1483 struct rte_flow_error *error);
1486 * Restrict ingress traffic to the defined flow rules.
1488 * Isolated mode guarantees that all ingress traffic comes from defined flow
1489 * rules only (current and future).
1491 * Besides making ingress more deterministic, it allows PMDs to safely reuse
1492 * resources otherwise assigned to handle the remaining traffic, such as
1493 * global RSS configuration settings, VLAN filters, MAC address entries,
1494 * legacy filter API rules and so on in order to expand the set of possible
1497 * Calling this function as soon as possible after device initialization,
1498 * ideally before the first call to rte_eth_dev_configure(), is recommended
1499 * to avoid possible failures due to conflicting settings.
1501 * Once effective, leaving isolated mode may not be possible depending on
1502 * PMD implementation.
1504 * Additionally, the following functionality has no effect on the underlying
1505 * port and may return errors such as ENOTSUP ("not supported"):
1507 * - Toggling promiscuous mode.
1508 * - Toggling allmulticast mode.
1509 * - Configuring MAC addresses.
1510 * - Configuring multicast addresses.
1511 * - Configuring VLAN filters.
1512 * - Configuring Rx filters through the legacy API (e.g. FDIR).
1513 * - Configuring global RSS settings.
1516 * Port identifier of Ethernet device.
1518 * Nonzero to enter isolated mode, attempt to leave it otherwise.
1520 * Perform verbose error reporting if not NULL. PMDs initialize this
1521 * structure in case of error only.
1524 * 0 on success, a negative errno value otherwise and rte_errno is set.
1527 rte_flow_isolate(uint16_t port_id, int set, struct rte_flow_error *error);
1530 * Initialize flow error structure.
1533 * Pointer to flow error structure (may be NULL).
1535 * Related error code (rte_errno).
1537 * Cause field and error types.
1539 * Object responsible for the error.
1541 * Human-readable error message.
1544 * Negative error code (errno value) and rte_errno is set.
1547 rte_flow_error_set(struct rte_flow_error *error,
1549 enum rte_flow_error_type type,
1551 const char *message);
1554 * Generic flow representation.
1556 * This form is sufficient to describe an rte_flow independently from any
1557 * PMD implementation and allows for replayability and identification.
1559 struct rte_flow_desc {
1560 size_t size; /**< Allocated space including data[]. */
1561 struct rte_flow_attr attr; /**< Attributes. */
1562 struct rte_flow_item *items; /**< Items. */
1563 struct rte_flow_action *actions; /**< Actions. */
1564 uint8_t data[]; /**< Storage for items/actions. */
1568 * Copy an rte_flow rule description.
1571 * Flow rule description.
1573 * Total size of allocated data for the flow description.
1575 * Flow rule attributes.
1577 * Pattern specification (list terminated by the END pattern item).
1578 * @param[in] actions
1579 * Associated actions (list terminated by the END action).
1582 * If len is greater or equal to the size of the flow, the total size of the
1583 * flow description and its data.
1584 * If len is lower than the size of the flow, the number of bytes that would
1585 * have been written to desc had it been sufficient. Nothing is written.
1588 rte_flow_copy(struct rte_flow_desc *fd, size_t len,
1589 const struct rte_flow_attr *attr,
1590 const struct rte_flow_item *items,
1591 const struct rte_flow_action *actions);
1597 #endif /* RTE_FLOW_H_ */