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,
345 * RTE_FLOW_ITEM_TYPE_ANY
347 * Matches any protocol in place of the current layer, a single ANY may also
348 * stand for several protocol layers.
350 * This is usually specified as the first pattern item when looking for a
351 * protocol anywhere in a packet.
353 * A zeroed mask stands for any number of layers.
355 struct rte_flow_item_any {
356 uint32_t num; /**< Number of layers covered. */
359 /** Default mask for RTE_FLOW_ITEM_TYPE_ANY. */
361 static const struct rte_flow_item_any rte_flow_item_any_mask = {
367 * RTE_FLOW_ITEM_TYPE_VF
369 * Matches traffic originating from (ingress) or going to (egress) a given
370 * virtual function of the current device.
372 * If supported, should work even if the virtual function is not managed by
373 * the application and thus not associated with a DPDK port ID.
375 * Note this pattern item does not match VF representors traffic which, as
376 * separate entities, should be addressed through their own DPDK port IDs.
378 * - Can be specified multiple times to match traffic addressed to several
380 * - Can be combined with a PF item to match both PF and VF traffic.
382 * A zeroed mask can be used to match any VF ID.
384 struct rte_flow_item_vf {
385 uint32_t id; /**< VF ID. */
388 /** Default mask for RTE_FLOW_ITEM_TYPE_VF. */
390 static const struct rte_flow_item_vf rte_flow_item_vf_mask = {
396 * RTE_FLOW_ITEM_TYPE_PHY_PORT
398 * Matches traffic originating from (ingress) or going to (egress) a
399 * physical port of the underlying device.
401 * The first PHY_PORT item overrides the physical port normally associated
402 * with the specified DPDK input port (port_id). This item can be provided
403 * several times to match additional physical ports.
405 * Note that physical ports are not necessarily tied to DPDK input ports
406 * (port_id) when those are not under DPDK control. Possible values are
407 * specific to each device, they are not necessarily indexed from zero and
408 * may not be contiguous.
410 * As a device property, the list of allowed values as well as the value
411 * associated with a port_id should be retrieved by other means.
413 * A zeroed mask can be used to match any port index.
415 struct rte_flow_item_phy_port {
416 uint32_t index; /**< Physical port index. */
419 /** Default mask for RTE_FLOW_ITEM_TYPE_PHY_PORT. */
421 static const struct rte_flow_item_phy_port rte_flow_item_phy_port_mask = {
427 * RTE_FLOW_ITEM_TYPE_PORT_ID
429 * Matches traffic originating from (ingress) or going to (egress) a given
432 * Normally only supported if the port ID in question is known by the
433 * underlying PMD and related to the device the flow rule is created
436 * This must not be confused with @p PHY_PORT which refers to the physical
437 * port of a device, whereas @p PORT_ID refers to a struct rte_eth_dev
438 * object on the application side (also known as "port representor"
439 * depending on the kind of underlying device).
441 struct rte_flow_item_port_id {
442 uint32_t id; /**< DPDK port ID. */
445 /** Default mask for RTE_FLOW_ITEM_TYPE_PORT_ID. */
447 static const struct rte_flow_item_port_id rte_flow_item_port_id_mask = {
453 * RTE_FLOW_ITEM_TYPE_RAW
455 * Matches a byte string of a given length at a given offset.
457 * Offset is either absolute (using the start of the packet) or relative to
458 * the end of the previous matched item in the stack, in which case negative
459 * values are allowed.
461 * If search is enabled, offset is used as the starting point. The search
462 * area can be delimited by setting limit to a nonzero value, which is the
463 * maximum number of bytes after offset where the pattern may start.
465 * Matching a zero-length pattern is allowed, doing so resets the relative
466 * offset for subsequent items.
468 * This type does not support ranges (struct rte_flow_item.last).
470 struct rte_flow_item_raw {
471 uint32_t relative:1; /**< Look for pattern after the previous item. */
472 uint32_t search:1; /**< Search pattern from offset (see also limit). */
473 uint32_t reserved:30; /**< Reserved, must be set to zero. */
474 int32_t offset; /**< Absolute or relative offset for pattern. */
475 uint16_t limit; /**< Search area limit for start of pattern. */
476 uint16_t length; /**< Pattern length. */
477 const uint8_t *pattern; /**< Byte string to look for. */
480 /** Default mask for RTE_FLOW_ITEM_TYPE_RAW. */
482 static const struct rte_flow_item_raw rte_flow_item_raw_mask = {
485 .reserved = 0x3fffffff,
486 .offset = 0xffffffff,
494 * RTE_FLOW_ITEM_TYPE_ETH
496 * Matches an Ethernet header.
498 * The @p type field either stands for "EtherType" or "TPID" when followed
499 * by so-called layer 2.5 pattern items such as RTE_FLOW_ITEM_TYPE_VLAN. In
500 * the latter case, @p type refers to that of the outer header, with the
501 * inner EtherType/TPID provided by the subsequent pattern item. This is the
502 * same order as on the wire.
504 struct rte_flow_item_eth {
505 struct ether_addr dst; /**< Destination MAC. */
506 struct ether_addr src; /**< Source MAC. */
507 rte_be16_t type; /**< EtherType or TPID. */
510 /** Default mask for RTE_FLOW_ITEM_TYPE_ETH. */
512 static const struct rte_flow_item_eth rte_flow_item_eth_mask = {
513 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
514 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
515 .type = RTE_BE16(0x0000),
520 * RTE_FLOW_ITEM_TYPE_VLAN
522 * Matches an 802.1Q/ad VLAN tag.
524 * The corresponding standard outer EtherType (TPID) values are
525 * ETHER_TYPE_VLAN or ETHER_TYPE_QINQ. It can be overridden by the preceding
528 struct rte_flow_item_vlan {
529 rte_be16_t tci; /**< Tag control information. */
530 rte_be16_t inner_type; /**< Inner EtherType or TPID. */
533 /** Default mask for RTE_FLOW_ITEM_TYPE_VLAN. */
535 static const struct rte_flow_item_vlan rte_flow_item_vlan_mask = {
536 .tci = RTE_BE16(0x0fff),
537 .inner_type = RTE_BE16(0x0000),
542 * RTE_FLOW_ITEM_TYPE_IPV4
544 * Matches an IPv4 header.
546 * Note: IPv4 options are handled by dedicated pattern items.
548 struct rte_flow_item_ipv4 {
549 struct ipv4_hdr hdr; /**< IPv4 header definition. */
552 /** Default mask for RTE_FLOW_ITEM_TYPE_IPV4. */
554 static const struct rte_flow_item_ipv4 rte_flow_item_ipv4_mask = {
556 .src_addr = RTE_BE32(0xffffffff),
557 .dst_addr = RTE_BE32(0xffffffff),
563 * RTE_FLOW_ITEM_TYPE_IPV6.
565 * Matches an IPv6 header.
567 * Note: IPv6 options are handled by dedicated pattern items.
569 struct rte_flow_item_ipv6 {
570 struct ipv6_hdr hdr; /**< IPv6 header definition. */
573 /** Default mask for RTE_FLOW_ITEM_TYPE_IPV6. */
575 static const struct rte_flow_item_ipv6 rte_flow_item_ipv6_mask = {
578 "\xff\xff\xff\xff\xff\xff\xff\xff"
579 "\xff\xff\xff\xff\xff\xff\xff\xff",
581 "\xff\xff\xff\xff\xff\xff\xff\xff"
582 "\xff\xff\xff\xff\xff\xff\xff\xff",
588 * RTE_FLOW_ITEM_TYPE_ICMP.
590 * Matches an ICMP header.
592 struct rte_flow_item_icmp {
593 struct icmp_hdr hdr; /**< ICMP header definition. */
596 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP. */
598 static const struct rte_flow_item_icmp rte_flow_item_icmp_mask = {
607 * RTE_FLOW_ITEM_TYPE_UDP.
609 * Matches a UDP header.
611 struct rte_flow_item_udp {
612 struct udp_hdr hdr; /**< UDP header definition. */
615 /** Default mask for RTE_FLOW_ITEM_TYPE_UDP. */
617 static const struct rte_flow_item_udp rte_flow_item_udp_mask = {
619 .src_port = RTE_BE16(0xffff),
620 .dst_port = RTE_BE16(0xffff),
626 * RTE_FLOW_ITEM_TYPE_TCP.
628 * Matches a TCP header.
630 struct rte_flow_item_tcp {
631 struct tcp_hdr hdr; /**< TCP header definition. */
634 /** Default mask for RTE_FLOW_ITEM_TYPE_TCP. */
636 static const struct rte_flow_item_tcp rte_flow_item_tcp_mask = {
638 .src_port = RTE_BE16(0xffff),
639 .dst_port = RTE_BE16(0xffff),
645 * RTE_FLOW_ITEM_TYPE_SCTP.
647 * Matches a SCTP header.
649 struct rte_flow_item_sctp {
650 struct sctp_hdr hdr; /**< SCTP header definition. */
653 /** Default mask for RTE_FLOW_ITEM_TYPE_SCTP. */
655 static const struct rte_flow_item_sctp rte_flow_item_sctp_mask = {
657 .src_port = RTE_BE16(0xffff),
658 .dst_port = RTE_BE16(0xffff),
664 * RTE_FLOW_ITEM_TYPE_VXLAN.
666 * Matches a VXLAN header (RFC 7348).
668 struct rte_flow_item_vxlan {
669 uint8_t flags; /**< Normally 0x08 (I flag). */
670 uint8_t rsvd0[3]; /**< Reserved, normally 0x000000. */
671 uint8_t vni[3]; /**< VXLAN identifier. */
672 uint8_t rsvd1; /**< Reserved, normally 0x00. */
675 /** Default mask for RTE_FLOW_ITEM_TYPE_VXLAN. */
677 static const struct rte_flow_item_vxlan rte_flow_item_vxlan_mask = {
678 .vni = "\xff\xff\xff",
683 * RTE_FLOW_ITEM_TYPE_E_TAG.
685 * Matches a E-tag header.
687 * The corresponding standard outer EtherType (TPID) value is
688 * ETHER_TYPE_ETAG. It can be overridden by the preceding pattern item.
690 struct rte_flow_item_e_tag {
692 * E-Tag control information (E-TCI).
693 * E-PCP (3b), E-DEI (1b), ingress E-CID base (12b).
695 rte_be16_t epcp_edei_in_ecid_b;
696 /** Reserved (2b), GRP (2b), E-CID base (12b). */
697 rte_be16_t rsvd_grp_ecid_b;
698 uint8_t in_ecid_e; /**< Ingress E-CID ext. */
699 uint8_t ecid_e; /**< E-CID ext. */
700 rte_be16_t inner_type; /**< Inner EtherType or TPID. */
703 /** Default mask for RTE_FLOW_ITEM_TYPE_E_TAG. */
705 static const struct rte_flow_item_e_tag rte_flow_item_e_tag_mask = {
706 .rsvd_grp_ecid_b = RTE_BE16(0x3fff),
711 * RTE_FLOW_ITEM_TYPE_NVGRE.
713 * Matches a NVGRE header.
715 struct rte_flow_item_nvgre {
717 * Checksum (1b), undefined (1b), key bit (1b), sequence number (1b),
718 * reserved 0 (9b), version (3b).
720 * c_k_s_rsvd0_ver must have value 0x2000 according to RFC 7637.
722 rte_be16_t c_k_s_rsvd0_ver;
723 rte_be16_t protocol; /**< Protocol type (0x6558). */
724 uint8_t tni[3]; /**< Virtual subnet ID. */
725 uint8_t flow_id; /**< Flow ID. */
728 /** Default mask for RTE_FLOW_ITEM_TYPE_NVGRE. */
730 static const struct rte_flow_item_nvgre rte_flow_item_nvgre_mask = {
731 .tni = "\xff\xff\xff",
736 * RTE_FLOW_ITEM_TYPE_MPLS.
738 * Matches a MPLS header.
740 struct rte_flow_item_mpls {
742 * Label (20b), TC (3b), Bottom of Stack (1b).
744 uint8_t label_tc_s[3];
745 uint8_t ttl; /** Time-to-Live. */
748 /** Default mask for RTE_FLOW_ITEM_TYPE_MPLS. */
750 static const struct rte_flow_item_mpls rte_flow_item_mpls_mask = {
751 .label_tc_s = "\xff\xff\xf0",
756 * RTE_FLOW_ITEM_TYPE_GRE.
758 * Matches a GRE header.
760 struct rte_flow_item_gre {
762 * Checksum (1b), reserved 0 (12b), version (3b).
765 rte_be16_t c_rsvd0_ver;
766 rte_be16_t protocol; /**< Protocol type. */
769 /** Default mask for RTE_FLOW_ITEM_TYPE_GRE. */
771 static const struct rte_flow_item_gre rte_flow_item_gre_mask = {
772 .protocol = RTE_BE16(0xffff),
777 * RTE_FLOW_ITEM_TYPE_FUZZY
779 * Fuzzy pattern match, expect faster than default.
781 * This is for device that support fuzzy match option.
782 * Usually a fuzzy match is fast but the cost is accuracy.
783 * i.e. Signature Match only match pattern's hash value, but it is
784 * possible two different patterns have the same hash value.
786 * Matching accuracy level can be configure by threshold.
787 * Driver can divide the range of threshold and map to different
788 * accuracy levels that device support.
790 * Threshold 0 means perfect match (no fuzziness), while threshold
791 * 0xffffffff means fuzziest match.
793 struct rte_flow_item_fuzzy {
794 uint32_t thresh; /**< Accuracy threshold. */
797 /** Default mask for RTE_FLOW_ITEM_TYPE_FUZZY. */
799 static const struct rte_flow_item_fuzzy rte_flow_item_fuzzy_mask = {
800 .thresh = 0xffffffff,
805 * RTE_FLOW_ITEM_TYPE_GTP.
807 * Matches a GTPv1 header.
809 struct rte_flow_item_gtp {
811 * Version (3b), protocol type (1b), reserved (1b),
812 * Extension header flag (1b),
813 * Sequence number flag (1b),
814 * N-PDU number flag (1b).
816 uint8_t v_pt_rsv_flags;
817 uint8_t msg_type; /**< Message type. */
818 rte_be16_t msg_len; /**< Message length. */
819 rte_be32_t teid; /**< Tunnel endpoint identifier. */
822 /** Default mask for RTE_FLOW_ITEM_TYPE_GTP. */
824 static const struct rte_flow_item_gtp rte_flow_item_gtp_mask = {
825 .teid = RTE_BE32(0xffffffff),
830 * RTE_FLOW_ITEM_TYPE_ESP
832 * Matches an ESP header.
834 struct rte_flow_item_esp {
835 struct esp_hdr hdr; /**< ESP header definition. */
838 /** Default mask for RTE_FLOW_ITEM_TYPE_ESP. */
840 static const struct rte_flow_item_esp rte_flow_item_esp_mask = {
848 * RTE_FLOW_ITEM_TYPE_GENEVE.
850 * Matches a GENEVE header.
852 struct rte_flow_item_geneve {
854 * Version (2b), length of the options fields (6b), OAM packet (1b),
855 * critical options present (1b), reserved 0 (6b).
857 rte_be16_t ver_opt_len_o_c_rsvd0;
858 rte_be16_t protocol; /**< Protocol type. */
859 uint8_t vni[3]; /**< Virtual Network Identifier. */
860 uint8_t rsvd1; /**< Reserved, normally 0x00. */
863 /** Default mask for RTE_FLOW_ITEM_TYPE_GENEVE. */
865 static const struct rte_flow_item_geneve rte_flow_item_geneve_mask = {
866 .vni = "\xff\xff\xff",
871 * Matching pattern item definition.
873 * A pattern is formed by stacking items starting from the lowest protocol
874 * layer to match. This stacking restriction does not apply to meta items
875 * which can be placed anywhere in the stack without affecting the meaning
876 * of the resulting pattern.
878 * Patterns are terminated by END items.
880 * The spec field should be a valid pointer to a structure of the related
881 * item type. It may remain unspecified (NULL) in many cases to request
882 * broad (nonspecific) matching. In such cases, last and mask must also be
885 * Optionally, last can point to a structure of the same type to define an
886 * inclusive range. This is mostly supported by integer and address fields,
887 * may cause errors otherwise. Fields that do not support ranges must be set
888 * to 0 or to the same value as the corresponding fields in spec.
890 * Only the fields defined to nonzero values in the default masks (see
891 * rte_flow_item_{name}_mask constants) are considered relevant by
892 * default. This can be overridden by providing a mask structure of the
893 * same type with applicable bits set to one. It can also be used to
894 * partially filter out specific fields (e.g. as an alternate mean to match
895 * ranges of IP addresses).
897 * Mask is a simple bit-mask applied before interpreting the contents of
898 * spec and last, which may yield unexpected results if not used
899 * carefully. For example, if for an IPv4 address field, spec provides
900 * 10.1.2.3, last provides 10.3.4.5 and mask provides 255.255.0.0, the
901 * effective range becomes 10.1.0.0 to 10.3.255.255.
903 struct rte_flow_item {
904 enum rte_flow_item_type type; /**< Item type. */
905 const void *spec; /**< Pointer to item specification structure. */
906 const void *last; /**< Defines an inclusive range (spec to last). */
907 const void *mask; /**< Bit-mask applied to spec and last. */
913 * Each possible action is represented by a type. Some have associated
914 * configuration structures. Several actions combined in a list can be
915 * assigned to a flow rule and are performed in order.
917 * They fall in three categories:
919 * - Actions that modify the fate of matching traffic, for instance by
920 * dropping or assigning it a specific destination.
922 * - Actions that modify matching traffic contents or its properties. This
923 * includes adding/removing encapsulation, encryption, compression and
926 * - Actions related to the flow rule itself, such as updating counters or
927 * making it non-terminating.
929 * Flow rules being terminating by default, not specifying any action of the
930 * fate kind results in undefined behavior. This applies to both ingress and
933 * PASSTHRU, when supported, makes a flow rule non-terminating.
935 enum rte_flow_action_type {
937 * End marker for action lists. Prevents further processing of
938 * actions, thereby ending the list.
940 * No associated configuration structure.
942 RTE_FLOW_ACTION_TYPE_END,
945 * Used as a placeholder for convenience. It is ignored and simply
948 * No associated configuration structure.
950 RTE_FLOW_ACTION_TYPE_VOID,
953 * Leaves traffic up for additional processing by subsequent flow
954 * rules; makes a flow rule non-terminating.
956 * No associated configuration structure.
958 RTE_FLOW_ACTION_TYPE_PASSTHRU,
961 * Attaches an integer value to packets and sets PKT_RX_FDIR and
962 * PKT_RX_FDIR_ID mbuf flags.
964 * See struct rte_flow_action_mark.
966 RTE_FLOW_ACTION_TYPE_MARK,
969 * Flags packets. Similar to MARK without a specific value; only
970 * sets the PKT_RX_FDIR mbuf flag.
972 * No associated configuration structure.
974 RTE_FLOW_ACTION_TYPE_FLAG,
977 * Assigns packets to a given queue index.
979 * See struct rte_flow_action_queue.
981 RTE_FLOW_ACTION_TYPE_QUEUE,
986 * PASSTHRU overrides this action if both are specified.
988 * No associated configuration structure.
990 RTE_FLOW_ACTION_TYPE_DROP,
993 * Enables counters for this flow rule.
995 * These counters can be retrieved and reset through rte_flow_query(),
996 * see struct rte_flow_query_count.
998 * No associated configuration structure.
1000 RTE_FLOW_ACTION_TYPE_COUNT,
1003 * Similar to QUEUE, except RSS is additionally performed on packets
1004 * to spread them among several queues according to the provided
1007 * See struct rte_flow_action_rss.
1009 RTE_FLOW_ACTION_TYPE_RSS,
1012 * Directs matching traffic to the physical function (PF) of the
1015 * No associated configuration structure.
1017 RTE_FLOW_ACTION_TYPE_PF,
1020 * Directs matching traffic to a given virtual function of the
1023 * See struct rte_flow_action_vf.
1025 RTE_FLOW_ACTION_TYPE_VF,
1028 * Directs packets to a given physical port index of the underlying
1031 * See struct rte_flow_action_phy_port.
1033 RTE_FLOW_ACTION_TYPE_PHY_PORT,
1036 * Directs matching traffic to a given DPDK port ID.
1038 * See struct rte_flow_action_port_id.
1040 RTE_FLOW_ACTION_TYPE_PORT_ID,
1043 * Traffic metering and policing (MTR).
1045 * See struct rte_flow_action_meter.
1046 * See file rte_mtr.h for MTR object configuration.
1048 RTE_FLOW_ACTION_TYPE_METER,
1051 * Redirects packets to security engine of current device for security
1052 * processing as specified by security session.
1054 * See struct rte_flow_action_security.
1056 RTE_FLOW_ACTION_TYPE_SECURITY
1060 * RTE_FLOW_ACTION_TYPE_MARK
1062 * Attaches an integer value to packets and sets PKT_RX_FDIR and
1063 * PKT_RX_FDIR_ID mbuf flags.
1065 * This value is arbitrary and application-defined. Maximum allowed value
1066 * depends on the underlying implementation. It is returned in the
1067 * hash.fdir.hi mbuf field.
1069 struct rte_flow_action_mark {
1070 uint32_t id; /**< Integer value to return with packets. */
1074 * RTE_FLOW_ACTION_TYPE_QUEUE
1076 * Assign packets to a given queue index.
1078 struct rte_flow_action_queue {
1079 uint16_t index; /**< Queue index to use. */
1083 * RTE_FLOW_ACTION_TYPE_COUNT (query)
1085 * Query structure to retrieve and reset flow rule counters.
1087 struct rte_flow_query_count {
1088 uint32_t reset:1; /**< Reset counters after query [in]. */
1089 uint32_t hits_set:1; /**< hits field is set [out]. */
1090 uint32_t bytes_set:1; /**< bytes field is set [out]. */
1091 uint32_t reserved:29; /**< Reserved, must be zero [in, out]. */
1092 uint64_t hits; /**< Number of hits for this rule [out]. */
1093 uint64_t bytes; /**< Number of bytes through this rule [out]. */
1097 * RTE_FLOW_ACTION_TYPE_RSS
1099 * Similar to QUEUE, except RSS is additionally performed on packets to
1100 * spread them among several queues according to the provided parameters.
1102 * Unlike global RSS settings used by other DPDK APIs, unsetting the
1103 * @p types field does not disable RSS in a flow rule. Doing so instead
1104 * requests safe unspecified "best-effort" settings from the underlying PMD,
1105 * which depending on the flow rule, may result in anything ranging from
1106 * empty (single queue) to all-inclusive RSS.
1108 * Note: RSS hash result is stored in the hash.rss mbuf field which overlaps
1109 * hash.fdir.lo. Since the MARK action sets the hash.fdir.hi field only,
1110 * both can be requested simultaneously.
1112 struct rte_flow_action_rss {
1113 enum rte_eth_hash_function func; /**< RSS hash function to apply. */
1115 * Packet encapsulation level RSS hash @p types apply to.
1117 * - @p 0 requests the default behavior. Depending on the packet
1118 * type, it can mean outermost, innermost, anything in between or
1121 * It basically stands for the innermost encapsulation level RSS
1122 * can be performed on according to PMD and device capabilities.
1124 * - @p 1 requests RSS to be performed on the outermost packet
1125 * encapsulation level.
1127 * - @p 2 and subsequent values request RSS to be performed on the
1128 * specified inner packet encapsulation level, from outermost to
1129 * innermost (lower to higher values).
1131 * Values other than @p 0 are not necessarily supported.
1133 * Requesting a specific RSS level on unrecognized traffic results
1134 * in undefined behavior. For predictable results, it is recommended
1135 * to make the flow rule pattern match packet headers up to the
1136 * requested encapsulation level so that only matching traffic goes
1140 uint64_t types; /**< Specific RSS hash types (see ETH_RSS_*). */
1141 uint32_t key_len; /**< Hash key length in bytes. */
1142 uint32_t queue_num; /**< Number of entries in @p queue. */
1143 const uint8_t *key; /**< Hash key. */
1144 const uint16_t *queue; /**< Queue indices to use. */
1148 * RTE_FLOW_ACTION_TYPE_VF
1150 * Directs matching traffic to a given virtual function of the current
1153 * Packets matched by a VF pattern item can be redirected to their original
1154 * VF ID instead of the specified one. This parameter may not be available
1155 * and is not guaranteed to work properly if the VF part is matched by a
1156 * prior flow rule or if packets are not addressed to a VF in the first
1159 struct rte_flow_action_vf {
1160 uint32_t original:1; /**< Use original VF ID if possible. */
1161 uint32_t reserved:31; /**< Reserved, must be zero. */
1162 uint32_t id; /**< VF ID. */
1166 * RTE_FLOW_ACTION_TYPE_PHY_PORT
1168 * Directs packets to a given physical port index of the underlying
1171 * @see RTE_FLOW_ITEM_TYPE_PHY_PORT
1173 struct rte_flow_action_phy_port {
1174 uint32_t original:1; /**< Use original port index if possible. */
1175 uint32_t reserved:31; /**< Reserved, must be zero. */
1176 uint32_t index; /**< Physical port index. */
1180 * RTE_FLOW_ACTION_TYPE_PORT_ID
1182 * Directs matching traffic to a given DPDK port ID.
1184 * @see RTE_FLOW_ITEM_TYPE_PORT_ID
1186 struct rte_flow_action_port_id {
1187 uint32_t original:1; /**< Use original DPDK port ID if possible. */
1188 uint32_t reserved:31; /**< Reserved, must be zero. */
1189 uint32_t id; /**< DPDK port ID. */
1193 * RTE_FLOW_ACTION_TYPE_METER
1195 * Traffic metering and policing (MTR).
1197 * Packets matched by items of this type can be either dropped or passed to the
1198 * next item with their color set by the MTR object.
1200 struct rte_flow_action_meter {
1201 uint32_t mtr_id; /**< MTR object ID created with rte_mtr_create(). */
1205 * RTE_FLOW_ACTION_TYPE_SECURITY
1207 * Perform the security action on flows matched by the pattern items
1208 * according to the configuration of the security session.
1210 * This action modifies the payload of matched flows. For INLINE_CRYPTO, the
1211 * security protocol headers and IV are fully provided by the application as
1212 * specified in the flow pattern. The payload of matching packets is
1213 * encrypted on egress, and decrypted and authenticated on ingress.
1214 * For INLINE_PROTOCOL, the security protocol is fully offloaded to HW,
1215 * providing full encapsulation and decapsulation of packets in security
1216 * protocols. The flow pattern specifies both the outer security header fields
1217 * and the inner packet fields. The security session specified in the action
1218 * must match the pattern parameters.
1220 * The security session specified in the action must be created on the same
1221 * port as the flow action that is being specified.
1223 * The ingress/egress flow attribute should match that specified in the
1224 * security session if the security session supports the definition of the
1227 * Multiple flows can be configured to use the same security session.
1229 struct rte_flow_action_security {
1230 void *security_session; /**< Pointer to security session structure. */
1234 * Definition of a single action.
1236 * A list of actions is terminated by a END action.
1238 * For simple actions without a configuration structure, conf remains NULL.
1240 struct rte_flow_action {
1241 enum rte_flow_action_type type; /**< Action type. */
1242 const void *conf; /**< Pointer to action configuration structure. */
1246 * Opaque type returned after successfully creating a flow.
1248 * This handle can be used to manage and query the related flow (e.g. to
1249 * destroy it or retrieve counters).
1254 * Verbose error types.
1256 * Most of them provide the type of the object referenced by struct
1257 * rte_flow_error.cause.
1259 enum rte_flow_error_type {
1260 RTE_FLOW_ERROR_TYPE_NONE, /**< No error. */
1261 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, /**< Cause unspecified. */
1262 RTE_FLOW_ERROR_TYPE_HANDLE, /**< Flow rule (handle). */
1263 RTE_FLOW_ERROR_TYPE_ATTR_GROUP, /**< Group field. */
1264 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY, /**< Priority field. */
1265 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS, /**< Ingress field. */
1266 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, /**< Egress field. */
1267 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER, /**< Transfer field. */
1268 RTE_FLOW_ERROR_TYPE_ATTR, /**< Attributes structure. */
1269 RTE_FLOW_ERROR_TYPE_ITEM_NUM, /**< Pattern length. */
1270 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, /**< Item specification. */
1271 RTE_FLOW_ERROR_TYPE_ITEM_LAST, /**< Item specification range. */
1272 RTE_FLOW_ERROR_TYPE_ITEM_MASK, /**< Item specification mask. */
1273 RTE_FLOW_ERROR_TYPE_ITEM, /**< Specific pattern item. */
1274 RTE_FLOW_ERROR_TYPE_ACTION_NUM, /**< Number of actions. */
1275 RTE_FLOW_ERROR_TYPE_ACTION_CONF, /**< Action configuration. */
1276 RTE_FLOW_ERROR_TYPE_ACTION, /**< Specific action. */
1280 * Verbose error structure definition.
1282 * This object is normally allocated by applications and set by PMDs, the
1283 * message points to a constant string which does not need to be freed by
1284 * the application, however its pointer can be considered valid only as long
1285 * as its associated DPDK port remains configured. Closing the underlying
1286 * device or unloading the PMD invalidates it.
1288 * Both cause and message may be NULL regardless of the error type.
1290 struct rte_flow_error {
1291 enum rte_flow_error_type type; /**< Cause field and error types. */
1292 const void *cause; /**< Object responsible for the error. */
1293 const char *message; /**< Human-readable error message. */
1297 * Check whether a flow rule can be created on a given port.
1299 * The flow rule is validated for correctness and whether it could be accepted
1300 * by the device given sufficient resources. The rule is checked against the
1301 * current device mode and queue configuration. The flow rule may also
1302 * optionally be validated against existing flow rules and device resources.
1303 * This function has no effect on the target device.
1305 * The returned value is guaranteed to remain valid only as long as no
1306 * successful calls to rte_flow_create() or rte_flow_destroy() are made in
1307 * the meantime and no device parameter affecting flow rules in any way are
1308 * modified, due to possible collisions or resource limitations (although in
1309 * such cases EINVAL should not be returned).
1312 * Port identifier of Ethernet device.
1314 * Flow rule attributes.
1315 * @param[in] pattern
1316 * Pattern specification (list terminated by the END pattern item).
1317 * @param[in] actions
1318 * Associated actions (list terminated by the END action).
1320 * Perform verbose error reporting if not NULL. PMDs initialize this
1321 * structure in case of error only.
1324 * 0 if flow rule is valid and can be created. A negative errno value
1325 * otherwise (rte_errno is also set), the following errors are defined:
1327 * -ENOSYS: underlying device does not support this functionality.
1329 * -EIO: underlying device is removed.
1331 * -EINVAL: unknown or invalid rule specification.
1333 * -ENOTSUP: valid but unsupported rule specification (e.g. partial
1334 * bit-masks are unsupported).
1336 * -EEXIST: collision with an existing rule. Only returned if device
1337 * supports flow rule collision checking and there was a flow rule
1338 * collision. Not receiving this return code is no guarantee that creating
1339 * the rule will not fail due to a collision.
1341 * -ENOMEM: not enough memory to execute the function, or if the device
1342 * supports resource validation, resource limitation on the device.
1344 * -EBUSY: action cannot be performed due to busy device resources, may
1345 * succeed if the affected queues or even the entire port are in a stopped
1346 * state (see rte_eth_dev_rx_queue_stop() and rte_eth_dev_stop()).
1349 rte_flow_validate(uint16_t port_id,
1350 const struct rte_flow_attr *attr,
1351 const struct rte_flow_item pattern[],
1352 const struct rte_flow_action actions[],
1353 struct rte_flow_error *error);
1356 * Create a flow rule on a given port.
1359 * Port identifier of Ethernet device.
1361 * Flow rule attributes.
1362 * @param[in] pattern
1363 * Pattern specification (list terminated by the END pattern item).
1364 * @param[in] actions
1365 * Associated actions (list terminated by the END action).
1367 * Perform verbose error reporting if not NULL. PMDs initialize this
1368 * structure in case of error only.
1371 * A valid handle in case of success, NULL otherwise and rte_errno is set
1372 * to the positive version of one of the error codes defined for
1373 * rte_flow_validate().
1376 rte_flow_create(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 * Destroy a flow rule on a given port.
1385 * Failure to destroy a flow rule handle may occur when other flow rules
1386 * depend on it, and destroying it would result in an inconsistent state.
1388 * This function is only guaranteed to succeed if handles are destroyed in
1389 * reverse order of their creation.
1392 * Port identifier of Ethernet device.
1394 * Flow rule handle to destroy.
1396 * Perform verbose error reporting if not NULL. PMDs initialize this
1397 * structure in case of error only.
1400 * 0 on success, a negative errno value otherwise and rte_errno is set.
1403 rte_flow_destroy(uint16_t port_id,
1404 struct rte_flow *flow,
1405 struct rte_flow_error *error);
1408 * Destroy all flow rules associated with a port.
1410 * In the unlikely event of failure, handles are still considered destroyed
1411 * and no longer valid but the port must be assumed to be in an inconsistent
1415 * Port identifier of Ethernet device.
1417 * Perform verbose error reporting if not NULL. PMDs initialize this
1418 * structure in case of error only.
1421 * 0 on success, a negative errno value otherwise and rte_errno is set.
1424 rte_flow_flush(uint16_t port_id,
1425 struct rte_flow_error *error);
1428 * Query an existing flow rule.
1430 * This function allows retrieving flow-specific data such as counters.
1431 * Data is gathered by special actions which must be present in the flow
1434 * \see RTE_FLOW_ACTION_TYPE_COUNT
1437 * Port identifier of Ethernet device.
1439 * Flow rule handle to query.
1441 * Action type to query.
1442 * @param[in, out] data
1443 * Pointer to storage for the associated query data type.
1445 * Perform verbose error reporting if not NULL. PMDs initialize this
1446 * structure in case of error only.
1449 * 0 on success, a negative errno value otherwise and rte_errno is set.
1452 rte_flow_query(uint16_t port_id,
1453 struct rte_flow *flow,
1454 enum rte_flow_action_type action,
1456 struct rte_flow_error *error);
1459 * Restrict ingress traffic to the defined flow rules.
1461 * Isolated mode guarantees that all ingress traffic comes from defined flow
1462 * rules only (current and future).
1464 * Besides making ingress more deterministic, it allows PMDs to safely reuse
1465 * resources otherwise assigned to handle the remaining traffic, such as
1466 * global RSS configuration settings, VLAN filters, MAC address entries,
1467 * legacy filter API rules and so on in order to expand the set of possible
1470 * Calling this function as soon as possible after device initialization,
1471 * ideally before the first call to rte_eth_dev_configure(), is recommended
1472 * to avoid possible failures due to conflicting settings.
1474 * Once effective, leaving isolated mode may not be possible depending on
1475 * PMD implementation.
1477 * Additionally, the following functionality has no effect on the underlying
1478 * port and may return errors such as ENOTSUP ("not supported"):
1480 * - Toggling promiscuous mode.
1481 * - Toggling allmulticast mode.
1482 * - Configuring MAC addresses.
1483 * - Configuring multicast addresses.
1484 * - Configuring VLAN filters.
1485 * - Configuring Rx filters through the legacy API (e.g. FDIR).
1486 * - Configuring global RSS settings.
1489 * Port identifier of Ethernet device.
1491 * Nonzero to enter isolated mode, attempt to leave it otherwise.
1493 * Perform verbose error reporting if not NULL. PMDs initialize this
1494 * structure in case of error only.
1497 * 0 on success, a negative errno value otherwise and rte_errno is set.
1500 rte_flow_isolate(uint16_t port_id, int set, struct rte_flow_error *error);
1503 * Initialize flow error structure.
1506 * Pointer to flow error structure (may be NULL).
1508 * Related error code (rte_errno).
1510 * Cause field and error types.
1512 * Object responsible for the error.
1514 * Human-readable error message.
1517 * Negative error code (errno value) and rte_errno is set.
1520 rte_flow_error_set(struct rte_flow_error *error,
1522 enum rte_flow_error_type type,
1524 const char *message);
1527 * Generic flow representation.
1529 * This form is sufficient to describe an rte_flow independently from any
1530 * PMD implementation and allows for replayability and identification.
1532 struct rte_flow_desc {
1533 size_t size; /**< Allocated space including data[]. */
1534 struct rte_flow_attr attr; /**< Attributes. */
1535 struct rte_flow_item *items; /**< Items. */
1536 struct rte_flow_action *actions; /**< Actions. */
1537 uint8_t data[]; /**< Storage for items/actions. */
1541 * Copy an rte_flow rule description.
1544 * Flow rule description.
1546 * Total size of allocated data for the flow description.
1548 * Flow rule attributes.
1550 * Pattern specification (list terminated by the END pattern item).
1551 * @param[in] actions
1552 * Associated actions (list terminated by the END action).
1555 * If len is greater or equal to the size of the flow, the total size of the
1556 * flow description and its data.
1557 * If len is lower than the size of the flow, the number of bytes that would
1558 * have been written to desc had it been sufficient. Nothing is written.
1561 rte_flow_copy(struct rte_flow_desc *fd, size_t len,
1562 const struct rte_flow_attr *attr,
1563 const struct rte_flow_item *items,
1564 const struct rte_flow_action *actions);
1570 #endif /* RTE_FLOW_H_ */