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,
351 * Matches an ARP header for Ethernet/IPv4.
353 * See struct rte_flow_item_arp_eth_ipv4.
355 RTE_FLOW_ITEM_TYPE_ARP_ETH_IPV4,
358 * Matches the presence of any IPv6 extension header.
360 * See struct rte_flow_item_ipv6_ext.
362 RTE_FLOW_ITEM_TYPE_IPV6_EXT,
365 * Matches any ICMPv6 header.
367 * See struct rte_flow_item_icmp6.
369 RTE_FLOW_ITEM_TYPE_ICMP6,
372 * Matches an ICMPv6 neighbor discovery solicitation.
374 * See struct rte_flow_item_icmp6_nd_ns.
376 RTE_FLOW_ITEM_TYPE_ICMP6_ND_NS,
379 * Matches an ICMPv6 neighbor discovery advertisement.
381 * See struct rte_flow_item_icmp6_nd_na.
383 RTE_FLOW_ITEM_TYPE_ICMP6_ND_NA,
386 * Matches the presence of any ICMPv6 neighbor discovery option.
388 * See struct rte_flow_item_icmp6_nd_opt.
390 RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT,
393 * Matches an ICMPv6 neighbor discovery source Ethernet link-layer
396 * See struct rte_flow_item_icmp6_nd_opt_sla_eth.
398 RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT_SLA_ETH,
401 * Matches an ICMPv6 neighbor discovery target Ethernet link-layer
404 * See struct rte_flow_item_icmp6_nd_opt_tla_eth.
406 RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT_TLA_ETH,
410 * RTE_FLOW_ITEM_TYPE_ANY
412 * Matches any protocol in place of the current layer, a single ANY may also
413 * stand for several protocol layers.
415 * This is usually specified as the first pattern item when looking for a
416 * protocol anywhere in a packet.
418 * A zeroed mask stands for any number of layers.
420 struct rte_flow_item_any {
421 uint32_t num; /**< Number of layers covered. */
424 /** Default mask for RTE_FLOW_ITEM_TYPE_ANY. */
426 static const struct rte_flow_item_any rte_flow_item_any_mask = {
432 * RTE_FLOW_ITEM_TYPE_VF
434 * Matches traffic originating from (ingress) or going to (egress) a given
435 * virtual function of the current device.
437 * If supported, should work even if the virtual function is not managed by
438 * the application and thus not associated with a DPDK port ID.
440 * Note this pattern item does not match VF representors traffic which, as
441 * separate entities, should be addressed through their own DPDK port IDs.
443 * - Can be specified multiple times to match traffic addressed to several
445 * - Can be combined with a PF item to match both PF and VF traffic.
447 * A zeroed mask can be used to match any VF ID.
449 struct rte_flow_item_vf {
450 uint32_t id; /**< VF ID. */
453 /** Default mask for RTE_FLOW_ITEM_TYPE_VF. */
455 static const struct rte_flow_item_vf rte_flow_item_vf_mask = {
461 * RTE_FLOW_ITEM_TYPE_PHY_PORT
463 * Matches traffic originating from (ingress) or going to (egress) a
464 * physical port of the underlying device.
466 * The first PHY_PORT item overrides the physical port normally associated
467 * with the specified DPDK input port (port_id). This item can be provided
468 * several times to match additional physical ports.
470 * Note that physical ports are not necessarily tied to DPDK input ports
471 * (port_id) when those are not under DPDK control. Possible values are
472 * specific to each device, they are not necessarily indexed from zero and
473 * may not be contiguous.
475 * As a device property, the list of allowed values as well as the value
476 * associated with a port_id should be retrieved by other means.
478 * A zeroed mask can be used to match any port index.
480 struct rte_flow_item_phy_port {
481 uint32_t index; /**< Physical port index. */
484 /** Default mask for RTE_FLOW_ITEM_TYPE_PHY_PORT. */
486 static const struct rte_flow_item_phy_port rte_flow_item_phy_port_mask = {
492 * RTE_FLOW_ITEM_TYPE_PORT_ID
494 * Matches traffic originating from (ingress) or going to (egress) a given
497 * Normally only supported if the port ID in question is known by the
498 * underlying PMD and related to the device the flow rule is created
501 * This must not be confused with @p PHY_PORT which refers to the physical
502 * port of a device, whereas @p PORT_ID refers to a struct rte_eth_dev
503 * object on the application side (also known as "port representor"
504 * depending on the kind of underlying device).
506 struct rte_flow_item_port_id {
507 uint32_t id; /**< DPDK port ID. */
510 /** Default mask for RTE_FLOW_ITEM_TYPE_PORT_ID. */
512 static const struct rte_flow_item_port_id rte_flow_item_port_id_mask = {
518 * RTE_FLOW_ITEM_TYPE_RAW
520 * Matches a byte string of a given length at a given offset.
522 * Offset is either absolute (using the start of the packet) or relative to
523 * the end of the previous matched item in the stack, in which case negative
524 * values are allowed.
526 * If search is enabled, offset is used as the starting point. The search
527 * area can be delimited by setting limit to a nonzero value, which is the
528 * maximum number of bytes after offset where the pattern may start.
530 * Matching a zero-length pattern is allowed, doing so resets the relative
531 * offset for subsequent items.
533 * This type does not support ranges (struct rte_flow_item.last).
535 struct rte_flow_item_raw {
536 uint32_t relative:1; /**< Look for pattern after the previous item. */
537 uint32_t search:1; /**< Search pattern from offset (see also limit). */
538 uint32_t reserved:30; /**< Reserved, must be set to zero. */
539 int32_t offset; /**< Absolute or relative offset for pattern. */
540 uint16_t limit; /**< Search area limit for start of pattern. */
541 uint16_t length; /**< Pattern length. */
542 const uint8_t *pattern; /**< Byte string to look for. */
545 /** Default mask for RTE_FLOW_ITEM_TYPE_RAW. */
547 static const struct rte_flow_item_raw rte_flow_item_raw_mask = {
550 .reserved = 0x3fffffff,
551 .offset = 0xffffffff,
559 * RTE_FLOW_ITEM_TYPE_ETH
561 * Matches an Ethernet header.
563 * The @p type field either stands for "EtherType" or "TPID" when followed
564 * by so-called layer 2.5 pattern items such as RTE_FLOW_ITEM_TYPE_VLAN. In
565 * the latter case, @p type refers to that of the outer header, with the
566 * inner EtherType/TPID provided by the subsequent pattern item. This is the
567 * same order as on the wire.
569 struct rte_flow_item_eth {
570 struct ether_addr dst; /**< Destination MAC. */
571 struct ether_addr src; /**< Source MAC. */
572 rte_be16_t type; /**< EtherType or TPID. */
575 /** Default mask for RTE_FLOW_ITEM_TYPE_ETH. */
577 static const struct rte_flow_item_eth rte_flow_item_eth_mask = {
578 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
579 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
580 .type = RTE_BE16(0x0000),
585 * RTE_FLOW_ITEM_TYPE_VLAN
587 * Matches an 802.1Q/ad VLAN tag.
589 * The corresponding standard outer EtherType (TPID) values are
590 * ETHER_TYPE_VLAN or ETHER_TYPE_QINQ. It can be overridden by the preceding
593 struct rte_flow_item_vlan {
594 rte_be16_t tci; /**< Tag control information. */
595 rte_be16_t inner_type; /**< Inner EtherType or TPID. */
598 /** Default mask for RTE_FLOW_ITEM_TYPE_VLAN. */
600 static const struct rte_flow_item_vlan rte_flow_item_vlan_mask = {
601 .tci = RTE_BE16(0x0fff),
602 .inner_type = RTE_BE16(0x0000),
607 * RTE_FLOW_ITEM_TYPE_IPV4
609 * Matches an IPv4 header.
611 * Note: IPv4 options are handled by dedicated pattern items.
613 struct rte_flow_item_ipv4 {
614 struct ipv4_hdr hdr; /**< IPv4 header definition. */
617 /** Default mask for RTE_FLOW_ITEM_TYPE_IPV4. */
619 static const struct rte_flow_item_ipv4 rte_flow_item_ipv4_mask = {
621 .src_addr = RTE_BE32(0xffffffff),
622 .dst_addr = RTE_BE32(0xffffffff),
628 * RTE_FLOW_ITEM_TYPE_IPV6.
630 * Matches an IPv6 header.
632 * Note: IPv6 options are handled by dedicated pattern items, see
633 * RTE_FLOW_ITEM_TYPE_IPV6_EXT.
635 struct rte_flow_item_ipv6 {
636 struct ipv6_hdr hdr; /**< IPv6 header definition. */
639 /** Default mask for RTE_FLOW_ITEM_TYPE_IPV6. */
641 static const struct rte_flow_item_ipv6 rte_flow_item_ipv6_mask = {
644 "\xff\xff\xff\xff\xff\xff\xff\xff"
645 "\xff\xff\xff\xff\xff\xff\xff\xff",
647 "\xff\xff\xff\xff\xff\xff\xff\xff"
648 "\xff\xff\xff\xff\xff\xff\xff\xff",
654 * RTE_FLOW_ITEM_TYPE_ICMP.
656 * Matches an ICMP header.
658 struct rte_flow_item_icmp {
659 struct icmp_hdr hdr; /**< ICMP header definition. */
662 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP. */
664 static const struct rte_flow_item_icmp rte_flow_item_icmp_mask = {
673 * RTE_FLOW_ITEM_TYPE_UDP.
675 * Matches a UDP header.
677 struct rte_flow_item_udp {
678 struct udp_hdr hdr; /**< UDP header definition. */
681 /** Default mask for RTE_FLOW_ITEM_TYPE_UDP. */
683 static const struct rte_flow_item_udp rte_flow_item_udp_mask = {
685 .src_port = RTE_BE16(0xffff),
686 .dst_port = RTE_BE16(0xffff),
692 * RTE_FLOW_ITEM_TYPE_TCP.
694 * Matches a TCP header.
696 struct rte_flow_item_tcp {
697 struct tcp_hdr hdr; /**< TCP header definition. */
700 /** Default mask for RTE_FLOW_ITEM_TYPE_TCP. */
702 static const struct rte_flow_item_tcp rte_flow_item_tcp_mask = {
704 .src_port = RTE_BE16(0xffff),
705 .dst_port = RTE_BE16(0xffff),
711 * RTE_FLOW_ITEM_TYPE_SCTP.
713 * Matches a SCTP header.
715 struct rte_flow_item_sctp {
716 struct sctp_hdr hdr; /**< SCTP header definition. */
719 /** Default mask for RTE_FLOW_ITEM_TYPE_SCTP. */
721 static const struct rte_flow_item_sctp rte_flow_item_sctp_mask = {
723 .src_port = RTE_BE16(0xffff),
724 .dst_port = RTE_BE16(0xffff),
730 * RTE_FLOW_ITEM_TYPE_VXLAN.
732 * Matches a VXLAN header (RFC 7348).
734 struct rte_flow_item_vxlan {
735 uint8_t flags; /**< Normally 0x08 (I flag). */
736 uint8_t rsvd0[3]; /**< Reserved, normally 0x000000. */
737 uint8_t vni[3]; /**< VXLAN identifier. */
738 uint8_t rsvd1; /**< Reserved, normally 0x00. */
741 /** Default mask for RTE_FLOW_ITEM_TYPE_VXLAN. */
743 static const struct rte_flow_item_vxlan rte_flow_item_vxlan_mask = {
744 .vni = "\xff\xff\xff",
749 * RTE_FLOW_ITEM_TYPE_E_TAG.
751 * Matches a E-tag header.
753 * The corresponding standard outer EtherType (TPID) value is
754 * ETHER_TYPE_ETAG. It can be overridden by the preceding pattern item.
756 struct rte_flow_item_e_tag {
758 * E-Tag control information (E-TCI).
759 * E-PCP (3b), E-DEI (1b), ingress E-CID base (12b).
761 rte_be16_t epcp_edei_in_ecid_b;
762 /** Reserved (2b), GRP (2b), E-CID base (12b). */
763 rte_be16_t rsvd_grp_ecid_b;
764 uint8_t in_ecid_e; /**< Ingress E-CID ext. */
765 uint8_t ecid_e; /**< E-CID ext. */
766 rte_be16_t inner_type; /**< Inner EtherType or TPID. */
769 /** Default mask for RTE_FLOW_ITEM_TYPE_E_TAG. */
771 static const struct rte_flow_item_e_tag rte_flow_item_e_tag_mask = {
772 .rsvd_grp_ecid_b = RTE_BE16(0x3fff),
777 * RTE_FLOW_ITEM_TYPE_NVGRE.
779 * Matches a NVGRE header.
781 struct rte_flow_item_nvgre {
783 * Checksum (1b), undefined (1b), key bit (1b), sequence number (1b),
784 * reserved 0 (9b), version (3b).
786 * c_k_s_rsvd0_ver must have value 0x2000 according to RFC 7637.
788 rte_be16_t c_k_s_rsvd0_ver;
789 rte_be16_t protocol; /**< Protocol type (0x6558). */
790 uint8_t tni[3]; /**< Virtual subnet ID. */
791 uint8_t flow_id; /**< Flow ID. */
794 /** Default mask for RTE_FLOW_ITEM_TYPE_NVGRE. */
796 static const struct rte_flow_item_nvgre rte_flow_item_nvgre_mask = {
797 .tni = "\xff\xff\xff",
802 * RTE_FLOW_ITEM_TYPE_MPLS.
804 * Matches a MPLS header.
806 struct rte_flow_item_mpls {
808 * Label (20b), TC (3b), Bottom of Stack (1b).
810 uint8_t label_tc_s[3];
811 uint8_t ttl; /** Time-to-Live. */
814 /** Default mask for RTE_FLOW_ITEM_TYPE_MPLS. */
816 static const struct rte_flow_item_mpls rte_flow_item_mpls_mask = {
817 .label_tc_s = "\xff\xff\xf0",
822 * RTE_FLOW_ITEM_TYPE_GRE.
824 * Matches a GRE header.
826 struct rte_flow_item_gre {
828 * Checksum (1b), reserved 0 (12b), version (3b).
831 rte_be16_t c_rsvd0_ver;
832 rte_be16_t protocol; /**< Protocol type. */
835 /** Default mask for RTE_FLOW_ITEM_TYPE_GRE. */
837 static const struct rte_flow_item_gre rte_flow_item_gre_mask = {
838 .protocol = RTE_BE16(0xffff),
843 * RTE_FLOW_ITEM_TYPE_FUZZY
845 * Fuzzy pattern match, expect faster than default.
847 * This is for device that support fuzzy match option.
848 * Usually a fuzzy match is fast but the cost is accuracy.
849 * i.e. Signature Match only match pattern's hash value, but it is
850 * possible two different patterns have the same hash value.
852 * Matching accuracy level can be configure by threshold.
853 * Driver can divide the range of threshold and map to different
854 * accuracy levels that device support.
856 * Threshold 0 means perfect match (no fuzziness), while threshold
857 * 0xffffffff means fuzziest match.
859 struct rte_flow_item_fuzzy {
860 uint32_t thresh; /**< Accuracy threshold. */
863 /** Default mask for RTE_FLOW_ITEM_TYPE_FUZZY. */
865 static const struct rte_flow_item_fuzzy rte_flow_item_fuzzy_mask = {
866 .thresh = 0xffffffff,
871 * RTE_FLOW_ITEM_TYPE_GTP.
873 * Matches a GTPv1 header.
875 struct rte_flow_item_gtp {
877 * Version (3b), protocol type (1b), reserved (1b),
878 * Extension header flag (1b),
879 * Sequence number flag (1b),
880 * N-PDU number flag (1b).
882 uint8_t v_pt_rsv_flags;
883 uint8_t msg_type; /**< Message type. */
884 rte_be16_t msg_len; /**< Message length. */
885 rte_be32_t teid; /**< Tunnel endpoint identifier. */
888 /** Default mask for RTE_FLOW_ITEM_TYPE_GTP. */
890 static const struct rte_flow_item_gtp rte_flow_item_gtp_mask = {
891 .teid = RTE_BE32(0xffffffff),
896 * RTE_FLOW_ITEM_TYPE_ESP
898 * Matches an ESP header.
900 struct rte_flow_item_esp {
901 struct esp_hdr hdr; /**< ESP header definition. */
904 /** Default mask for RTE_FLOW_ITEM_TYPE_ESP. */
906 static const struct rte_flow_item_esp rte_flow_item_esp_mask = {
914 * RTE_FLOW_ITEM_TYPE_GENEVE.
916 * Matches a GENEVE header.
918 struct rte_flow_item_geneve {
920 * Version (2b), length of the options fields (6b), OAM packet (1b),
921 * critical options present (1b), reserved 0 (6b).
923 rte_be16_t ver_opt_len_o_c_rsvd0;
924 rte_be16_t protocol; /**< Protocol type. */
925 uint8_t vni[3]; /**< Virtual Network Identifier. */
926 uint8_t rsvd1; /**< Reserved, normally 0x00. */
929 /** Default mask for RTE_FLOW_ITEM_TYPE_GENEVE. */
931 static const struct rte_flow_item_geneve rte_flow_item_geneve_mask = {
932 .vni = "\xff\xff\xff",
937 * RTE_FLOW_ITEM_TYPE_VXLAN_GPE (draft-ietf-nvo3-vxlan-gpe-05).
939 * Matches a VXLAN-GPE header.
941 struct rte_flow_item_vxlan_gpe {
942 uint8_t flags; /**< Normally 0x0c (I and P flags). */
943 uint8_t rsvd0[2]; /**< Reserved, normally 0x0000. */
944 uint8_t protocol; /**< Protocol type. */
945 uint8_t vni[3]; /**< VXLAN identifier. */
946 uint8_t rsvd1; /**< Reserved, normally 0x00. */
949 /** Default mask for RTE_FLOW_ITEM_TYPE_VXLAN_GPE. */
951 static const struct rte_flow_item_vxlan_gpe rte_flow_item_vxlan_gpe_mask = {
952 .vni = "\xff\xff\xff",
957 * RTE_FLOW_ITEM_TYPE_ARP_ETH_IPV4
959 * Matches an ARP header for Ethernet/IPv4.
961 struct rte_flow_item_arp_eth_ipv4 {
962 rte_be16_t hrd; /**< Hardware type, normally 1. */
963 rte_be16_t pro; /**< Protocol type, normally 0x0800. */
964 uint8_t hln; /**< Hardware address length, normally 6. */
965 uint8_t pln; /**< Protocol address length, normally 4. */
966 rte_be16_t op; /**< Opcode (1 for request, 2 for reply). */
967 struct ether_addr sha; /**< Sender hardware address. */
968 rte_be32_t spa; /**< Sender IPv4 address. */
969 struct ether_addr tha; /**< Target hardware address. */
970 rte_be32_t tpa; /**< Target IPv4 address. */
973 /** Default mask for RTE_FLOW_ITEM_TYPE_ARP_ETH_IPV4. */
975 static const struct rte_flow_item_arp_eth_ipv4
976 rte_flow_item_arp_eth_ipv4_mask = {
977 .sha.addr_bytes = "\xff\xff\xff\xff\xff\xff",
978 .spa = RTE_BE32(0xffffffff),
979 .tha.addr_bytes = "\xff\xff\xff\xff\xff\xff",
980 .tpa = RTE_BE32(0xffffffff),
985 * RTE_FLOW_ITEM_TYPE_IPV6_EXT
987 * Matches the presence of any IPv6 extension header.
989 * Normally preceded by any of:
991 * - RTE_FLOW_ITEM_TYPE_IPV6
992 * - RTE_FLOW_ITEM_TYPE_IPV6_EXT
994 struct rte_flow_item_ipv6_ext {
995 uint8_t next_hdr; /**< Next header. */
998 /** Default mask for RTE_FLOW_ITEM_TYPE_IPV6_EXT. */
1001 struct rte_flow_item_ipv6_ext rte_flow_item_ipv6_ext_mask = {
1007 * RTE_FLOW_ITEM_TYPE_ICMP6
1009 * Matches any ICMPv6 header.
1011 struct rte_flow_item_icmp6 {
1012 uint8_t type; /**< ICMPv6 type. */
1013 uint8_t code; /**< ICMPv6 code. */
1014 uint16_t checksum; /**< ICMPv6 checksum. */
1017 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP6. */
1019 static const struct rte_flow_item_icmp6 rte_flow_item_icmp6_mask = {
1026 * RTE_FLOW_ITEM_TYPE_ICMP6_ND_NS
1028 * Matches an ICMPv6 neighbor discovery solicitation.
1030 struct rte_flow_item_icmp6_nd_ns {
1031 uint8_t type; /**< ICMPv6 type, normally 135. */
1032 uint8_t code; /**< ICMPv6 code, normally 0. */
1033 rte_be16_t checksum; /**< ICMPv6 checksum. */
1034 rte_be32_t reserved; /**< Reserved, normally 0. */
1035 uint8_t target_addr[16]; /**< Target address. */
1038 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP6_ND_NS. */
1041 struct rte_flow_item_icmp6_nd_ns rte_flow_item_icmp6_nd_ns_mask = {
1043 "\xff\xff\xff\xff\xff\xff\xff\xff"
1044 "\xff\xff\xff\xff\xff\xff\xff\xff",
1049 * RTE_FLOW_ITEM_TYPE_ICMP6_ND_NA
1051 * Matches an ICMPv6 neighbor discovery advertisement.
1053 struct rte_flow_item_icmp6_nd_na {
1054 uint8_t type; /**< ICMPv6 type, normally 136. */
1055 uint8_t code; /**< ICMPv6 code, normally 0. */
1056 rte_be16_t checksum; /**< ICMPv6 checksum. */
1058 * Route flag (1b), solicited flag (1b), override flag (1b),
1061 rte_be32_t rso_reserved;
1062 uint8_t target_addr[16]; /**< Target address. */
1065 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP6_ND_NA. */
1068 struct rte_flow_item_icmp6_nd_na rte_flow_item_icmp6_nd_na_mask = {
1070 "\xff\xff\xff\xff\xff\xff\xff\xff"
1071 "\xff\xff\xff\xff\xff\xff\xff\xff",
1076 * RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT
1078 * Matches the presence of any ICMPv6 neighbor discovery option.
1080 * Normally preceded by any of:
1082 * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_NA
1083 * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_NS
1084 * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT
1086 struct rte_flow_item_icmp6_nd_opt {
1087 uint8_t type; /**< ND option type. */
1088 uint8_t length; /**< ND option length. */
1091 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT. */
1093 static const struct rte_flow_item_icmp6_nd_opt
1094 rte_flow_item_icmp6_nd_opt_mask = {
1100 * RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT_SLA_ETH
1102 * Matches an ICMPv6 neighbor discovery source Ethernet link-layer address
1105 * Normally preceded by any of:
1107 * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_NA
1108 * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT
1110 struct rte_flow_item_icmp6_nd_opt_sla_eth {
1111 uint8_t type; /**< ND option type, normally 1. */
1112 uint8_t length; /**< ND option length, normally 1. */
1113 struct ether_addr sla; /**< Source Ethernet LLA. */
1116 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT_SLA_ETH. */
1118 static const struct rte_flow_item_icmp6_nd_opt_sla_eth
1119 rte_flow_item_icmp6_nd_opt_sla_eth_mask = {
1120 .sla.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1125 * RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT_TLA_ETH
1127 * Matches an ICMPv6 neighbor discovery target Ethernet link-layer address
1130 * Normally preceded by any of:
1132 * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_NS
1133 * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT
1135 struct rte_flow_item_icmp6_nd_opt_tla_eth {
1136 uint8_t type; /**< ND option type, normally 2. */
1137 uint8_t length; /**< ND option length, normally 1. */
1138 struct ether_addr tla; /**< Target Ethernet LLA. */
1141 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT_TLA_ETH. */
1143 static const struct rte_flow_item_icmp6_nd_opt_tla_eth
1144 rte_flow_item_icmp6_nd_opt_tla_eth_mask = {
1145 .tla.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1150 * Matching pattern item definition.
1152 * A pattern is formed by stacking items starting from the lowest protocol
1153 * layer to match. This stacking restriction does not apply to meta items
1154 * which can be placed anywhere in the stack without affecting the meaning
1155 * of the resulting pattern.
1157 * Patterns are terminated by END items.
1159 * The spec field should be a valid pointer to a structure of the related
1160 * item type. It may remain unspecified (NULL) in many cases to request
1161 * broad (nonspecific) matching. In such cases, last and mask must also be
1164 * Optionally, last can point to a structure of the same type to define an
1165 * inclusive range. This is mostly supported by integer and address fields,
1166 * may cause errors otherwise. Fields that do not support ranges must be set
1167 * to 0 or to the same value as the corresponding fields in spec.
1169 * Only the fields defined to nonzero values in the default masks (see
1170 * rte_flow_item_{name}_mask constants) are considered relevant by
1171 * default. This can be overridden by providing a mask structure of the
1172 * same type with applicable bits set to one. It can also be used to
1173 * partially filter out specific fields (e.g. as an alternate mean to match
1174 * ranges of IP addresses).
1176 * Mask is a simple bit-mask applied before interpreting the contents of
1177 * spec and last, which may yield unexpected results if not used
1178 * carefully. For example, if for an IPv4 address field, spec provides
1179 * 10.1.2.3, last provides 10.3.4.5 and mask provides 255.255.0.0, the
1180 * effective range becomes 10.1.0.0 to 10.3.255.255.
1182 struct rte_flow_item {
1183 enum rte_flow_item_type type; /**< Item type. */
1184 const void *spec; /**< Pointer to item specification structure. */
1185 const void *last; /**< Defines an inclusive range (spec to last). */
1186 const void *mask; /**< Bit-mask applied to spec and last. */
1192 * Each possible action is represented by a type. Some have associated
1193 * configuration structures. Several actions combined in a list can be
1194 * assigned to a flow rule and are performed in order.
1196 * They fall in three categories:
1198 * - Actions that modify the fate of matching traffic, for instance by
1199 * dropping or assigning it a specific destination.
1201 * - Actions that modify matching traffic contents or its properties. This
1202 * includes adding/removing encapsulation, encryption, compression and
1205 * - Actions related to the flow rule itself, such as updating counters or
1206 * making it non-terminating.
1208 * Flow rules being terminating by default, not specifying any action of the
1209 * fate kind results in undefined behavior. This applies to both ingress and
1212 * PASSTHRU, when supported, makes a flow rule non-terminating.
1214 enum rte_flow_action_type {
1216 * End marker for action lists. Prevents further processing of
1217 * actions, thereby ending the list.
1219 * No associated configuration structure.
1221 RTE_FLOW_ACTION_TYPE_END,
1224 * Used as a placeholder for convenience. It is ignored and simply
1225 * discarded by PMDs.
1227 * No associated configuration structure.
1229 RTE_FLOW_ACTION_TYPE_VOID,
1232 * Leaves traffic up for additional processing by subsequent flow
1233 * rules; makes a flow rule non-terminating.
1235 * No associated configuration structure.
1237 RTE_FLOW_ACTION_TYPE_PASSTHRU,
1240 * Attaches an integer value to packets and sets PKT_RX_FDIR and
1241 * PKT_RX_FDIR_ID mbuf flags.
1243 * See struct rte_flow_action_mark.
1245 RTE_FLOW_ACTION_TYPE_MARK,
1248 * Flags packets. Similar to MARK without a specific value; only
1249 * sets the PKT_RX_FDIR mbuf flag.
1251 * No associated configuration structure.
1253 RTE_FLOW_ACTION_TYPE_FLAG,
1256 * Assigns packets to a given queue index.
1258 * See struct rte_flow_action_queue.
1260 RTE_FLOW_ACTION_TYPE_QUEUE,
1265 * PASSTHRU overrides this action if both are specified.
1267 * No associated configuration structure.
1269 RTE_FLOW_ACTION_TYPE_DROP,
1272 * Enables counters for this flow rule.
1274 * These counters can be retrieved and reset through rte_flow_query(),
1275 * see struct rte_flow_query_count.
1277 * No associated configuration structure.
1279 RTE_FLOW_ACTION_TYPE_COUNT,
1282 * Similar to QUEUE, except RSS is additionally performed on packets
1283 * to spread them among several queues according to the provided
1286 * See struct rte_flow_action_rss.
1288 RTE_FLOW_ACTION_TYPE_RSS,
1291 * Directs matching traffic to the physical function (PF) of the
1294 * No associated configuration structure.
1296 RTE_FLOW_ACTION_TYPE_PF,
1299 * Directs matching traffic to a given virtual function of the
1302 * See struct rte_flow_action_vf.
1304 RTE_FLOW_ACTION_TYPE_VF,
1307 * Directs packets to a given physical port index of the underlying
1310 * See struct rte_flow_action_phy_port.
1312 RTE_FLOW_ACTION_TYPE_PHY_PORT,
1315 * Directs matching traffic to a given DPDK port ID.
1317 * See struct rte_flow_action_port_id.
1319 RTE_FLOW_ACTION_TYPE_PORT_ID,
1322 * Traffic metering and policing (MTR).
1324 * See struct rte_flow_action_meter.
1325 * See file rte_mtr.h for MTR object configuration.
1327 RTE_FLOW_ACTION_TYPE_METER,
1330 * Redirects packets to security engine of current device for security
1331 * processing as specified by security session.
1333 * See struct rte_flow_action_security.
1335 RTE_FLOW_ACTION_TYPE_SECURITY,
1338 * Implements OFPAT_SET_MPLS_TTL ("MPLS TTL") as defined by the
1339 * OpenFlow Switch Specification.
1341 * See struct rte_flow_action_of_set_mpls_ttl.
1343 RTE_FLOW_ACTION_TYPE_OF_SET_MPLS_TTL,
1346 * Implements OFPAT_DEC_MPLS_TTL ("decrement MPLS TTL") as defined
1347 * by the OpenFlow Switch Specification.
1349 * No associated configuration structure.
1351 RTE_FLOW_ACTION_TYPE_OF_DEC_MPLS_TTL,
1354 * Implements OFPAT_SET_NW_TTL ("IP TTL") as defined by the OpenFlow
1355 * Switch Specification.
1357 * See struct rte_flow_action_of_set_nw_ttl.
1359 RTE_FLOW_ACTION_TYPE_OF_SET_NW_TTL,
1362 * Implements OFPAT_DEC_NW_TTL ("decrement IP TTL") as defined by
1363 * the OpenFlow Switch Specification.
1365 * No associated configuration structure.
1367 RTE_FLOW_ACTION_TYPE_OF_DEC_NW_TTL,
1370 * Implements OFPAT_COPY_TTL_OUT ("copy TTL "outwards" -- from
1371 * next-to-outermost to outermost") as defined by the OpenFlow
1372 * Switch Specification.
1374 * No associated configuration structure.
1376 RTE_FLOW_ACTION_TYPE_OF_COPY_TTL_OUT,
1379 * Implements OFPAT_COPY_TTL_IN ("copy TTL "inwards" -- from
1380 * outermost to next-to-outermost") as defined by the OpenFlow
1381 * Switch Specification.
1383 * No associated configuration structure.
1385 RTE_FLOW_ACTION_TYPE_OF_COPY_TTL_IN,
1388 * Implements OFPAT_POP_VLAN ("pop the outer VLAN tag") as defined
1389 * by the OpenFlow Switch Specification.
1391 * No associated configuration structure.
1393 RTE_FLOW_ACTION_TYPE_OF_POP_VLAN,
1396 * Implements OFPAT_PUSH_VLAN ("push a new VLAN tag") as defined by
1397 * the OpenFlow Switch Specification.
1399 * See struct rte_flow_action_of_push_vlan.
1401 RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN,
1404 * Implements OFPAT_SET_VLAN_VID ("set the 802.1q VLAN id") as
1405 * defined by the OpenFlow Switch Specification.
1407 * See struct rte_flow_action_of_set_vlan_vid.
1409 RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID,
1412 * Implements OFPAT_SET_LAN_PCP ("set the 802.1q priority") as
1413 * defined by the OpenFlow Switch Specification.
1415 * See struct rte_flow_action_of_set_vlan_pcp.
1417 RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP,
1420 * Implements OFPAT_POP_MPLS ("pop the outer MPLS tag") as defined
1421 * by the OpenFlow Switch Specification.
1423 * See struct rte_flow_action_of_pop_mpls.
1425 RTE_FLOW_ACTION_TYPE_OF_POP_MPLS,
1428 * Implements OFPAT_PUSH_MPLS ("push a new MPLS tag") as defined by
1429 * the OpenFlow Switch Specification.
1431 * See struct rte_flow_action_of_push_mpls.
1433 RTE_FLOW_ACTION_TYPE_OF_PUSH_MPLS,
1436 * Encapsulate flow in VXLAN tunnel as defined in
1437 * rte_flow_action_vxlan_encap action structure.
1439 * See struct rte_flow_action_vxlan_encap.
1441 RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP,
1444 * Decapsulate outer most VXLAN tunnel from matched flow.
1446 * If flow pattern does not define a valid VXLAN tunnel (as specified by
1447 * RFC7348) then the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION
1450 RTE_FLOW_ACTION_TYPE_VXLAN_DECAP,
1453 * Encapsulate flow in NVGRE tunnel defined in the
1454 * rte_flow_action_nvgre_encap action structure.
1456 * See struct rte_flow_action_nvgre_encap.
1458 RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP,
1461 * Decapsulate outer most NVGRE tunnel from matched flow.
1463 * If flow pattern does not define a valid NVGRE tunnel (as specified by
1464 * RFC7637) then the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION
1467 RTE_FLOW_ACTION_TYPE_NVGRE_DECAP,
1471 * RTE_FLOW_ACTION_TYPE_MARK
1473 * Attaches an integer value to packets and sets PKT_RX_FDIR and
1474 * PKT_RX_FDIR_ID mbuf flags.
1476 * This value is arbitrary and application-defined. Maximum allowed value
1477 * depends on the underlying implementation. It is returned in the
1478 * hash.fdir.hi mbuf field.
1480 struct rte_flow_action_mark {
1481 uint32_t id; /**< Integer value to return with packets. */
1485 * RTE_FLOW_ACTION_TYPE_QUEUE
1487 * Assign packets to a given queue index.
1489 struct rte_flow_action_queue {
1490 uint16_t index; /**< Queue index to use. */
1494 * RTE_FLOW_ACTION_TYPE_COUNT (query)
1496 * Query structure to retrieve and reset flow rule counters.
1498 struct rte_flow_query_count {
1499 uint32_t reset:1; /**< Reset counters after query [in]. */
1500 uint32_t hits_set:1; /**< hits field is set [out]. */
1501 uint32_t bytes_set:1; /**< bytes field is set [out]. */
1502 uint32_t reserved:29; /**< Reserved, must be zero [in, out]. */
1503 uint64_t hits; /**< Number of hits for this rule [out]. */
1504 uint64_t bytes; /**< Number of bytes through this rule [out]. */
1508 * RTE_FLOW_ACTION_TYPE_RSS
1510 * Similar to QUEUE, except RSS is additionally performed on packets to
1511 * spread them among several queues according to the provided parameters.
1513 * Unlike global RSS settings used by other DPDK APIs, unsetting the
1514 * @p types field does not disable RSS in a flow rule. Doing so instead
1515 * requests safe unspecified "best-effort" settings from the underlying PMD,
1516 * which depending on the flow rule, may result in anything ranging from
1517 * empty (single queue) to all-inclusive RSS.
1519 * Note: RSS hash result is stored in the hash.rss mbuf field which overlaps
1520 * hash.fdir.lo. Since the MARK action sets the hash.fdir.hi field only,
1521 * both can be requested simultaneously.
1523 struct rte_flow_action_rss {
1524 enum rte_eth_hash_function func; /**< RSS hash function to apply. */
1526 * Packet encapsulation level RSS hash @p types apply to.
1528 * - @p 0 requests the default behavior. Depending on the packet
1529 * type, it can mean outermost, innermost, anything in between or
1532 * It basically stands for the innermost encapsulation level RSS
1533 * can be performed on according to PMD and device capabilities.
1535 * - @p 1 requests RSS to be performed on the outermost packet
1536 * encapsulation level.
1538 * - @p 2 and subsequent values request RSS to be performed on the
1539 * specified inner packet encapsulation level, from outermost to
1540 * innermost (lower to higher values).
1542 * Values other than @p 0 are not necessarily supported.
1544 * Requesting a specific RSS level on unrecognized traffic results
1545 * in undefined behavior. For predictable results, it is recommended
1546 * to make the flow rule pattern match packet headers up to the
1547 * requested encapsulation level so that only matching traffic goes
1551 uint64_t types; /**< Specific RSS hash types (see ETH_RSS_*). */
1552 uint32_t key_len; /**< Hash key length in bytes. */
1553 uint32_t queue_num; /**< Number of entries in @p queue. */
1554 const uint8_t *key; /**< Hash key. */
1555 const uint16_t *queue; /**< Queue indices to use. */
1559 * RTE_FLOW_ACTION_TYPE_VF
1561 * Directs matching traffic to a given virtual function of the current
1564 * Packets matched by a VF pattern item can be redirected to their original
1565 * VF ID instead of the specified one. This parameter may not be available
1566 * and is not guaranteed to work properly if the VF part is matched by a
1567 * prior flow rule or if packets are not addressed to a VF in the first
1570 struct rte_flow_action_vf {
1571 uint32_t original:1; /**< Use original VF ID if possible. */
1572 uint32_t reserved:31; /**< Reserved, must be zero. */
1573 uint32_t id; /**< VF ID. */
1577 * RTE_FLOW_ACTION_TYPE_PHY_PORT
1579 * Directs packets to a given physical port index of the underlying
1582 * @see RTE_FLOW_ITEM_TYPE_PHY_PORT
1584 struct rte_flow_action_phy_port {
1585 uint32_t original:1; /**< Use original port index if possible. */
1586 uint32_t reserved:31; /**< Reserved, must be zero. */
1587 uint32_t index; /**< Physical port index. */
1591 * RTE_FLOW_ACTION_TYPE_PORT_ID
1593 * Directs matching traffic to a given DPDK port ID.
1595 * @see RTE_FLOW_ITEM_TYPE_PORT_ID
1597 struct rte_flow_action_port_id {
1598 uint32_t original:1; /**< Use original DPDK port ID if possible. */
1599 uint32_t reserved:31; /**< Reserved, must be zero. */
1600 uint32_t id; /**< DPDK port ID. */
1604 * RTE_FLOW_ACTION_TYPE_METER
1606 * Traffic metering and policing (MTR).
1608 * Packets matched by items of this type can be either dropped or passed to the
1609 * next item with their color set by the MTR object.
1611 struct rte_flow_action_meter {
1612 uint32_t mtr_id; /**< MTR object ID created with rte_mtr_create(). */
1616 * RTE_FLOW_ACTION_TYPE_SECURITY
1618 * Perform the security action on flows matched by the pattern items
1619 * according to the configuration of the security session.
1621 * This action modifies the payload of matched flows. For INLINE_CRYPTO, the
1622 * security protocol headers and IV are fully provided by the application as
1623 * specified in the flow pattern. The payload of matching packets is
1624 * encrypted on egress, and decrypted and authenticated on ingress.
1625 * For INLINE_PROTOCOL, the security protocol is fully offloaded to HW,
1626 * providing full encapsulation and decapsulation of packets in security
1627 * protocols. The flow pattern specifies both the outer security header fields
1628 * and the inner packet fields. The security session specified in the action
1629 * must match the pattern parameters.
1631 * The security session specified in the action must be created on the same
1632 * port as the flow action that is being specified.
1634 * The ingress/egress flow attribute should match that specified in the
1635 * security session if the security session supports the definition of the
1638 * Multiple flows can be configured to use the same security session.
1640 struct rte_flow_action_security {
1641 void *security_session; /**< Pointer to security session structure. */
1645 * RTE_FLOW_ACTION_TYPE_OF_SET_MPLS_TTL
1647 * Implements OFPAT_SET_MPLS_TTL ("MPLS TTL") as defined by the OpenFlow
1648 * Switch Specification.
1650 struct rte_flow_action_of_set_mpls_ttl {
1651 uint8_t mpls_ttl; /**< MPLS TTL. */
1655 * RTE_FLOW_ACTION_TYPE_OF_SET_NW_TTL
1657 * Implements OFPAT_SET_NW_TTL ("IP TTL") as defined by the OpenFlow Switch
1660 struct rte_flow_action_of_set_nw_ttl {
1661 uint8_t nw_ttl; /**< IP TTL. */
1665 * RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN
1667 * Implements OFPAT_PUSH_VLAN ("push a new VLAN tag") as defined by the
1668 * OpenFlow Switch Specification.
1670 struct rte_flow_action_of_push_vlan {
1671 rte_be16_t ethertype; /**< EtherType. */
1675 * RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID
1677 * Implements OFPAT_SET_VLAN_VID ("set the 802.1q VLAN id") as defined by
1678 * the OpenFlow Switch Specification.
1680 struct rte_flow_action_of_set_vlan_vid {
1681 rte_be16_t vlan_vid; /**< VLAN id. */
1685 * RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP
1687 * Implements OFPAT_SET_LAN_PCP ("set the 802.1q priority") as defined by
1688 * the OpenFlow Switch Specification.
1690 struct rte_flow_action_of_set_vlan_pcp {
1691 uint8_t vlan_pcp; /**< VLAN priority. */
1695 * RTE_FLOW_ACTION_TYPE_OF_POP_MPLS
1697 * Implements OFPAT_POP_MPLS ("pop the outer MPLS tag") as defined by the
1698 * OpenFlow Switch Specification.
1700 struct rte_flow_action_of_pop_mpls {
1701 rte_be16_t ethertype; /**< EtherType. */
1705 * RTE_FLOW_ACTION_TYPE_OF_PUSH_MPLS
1707 * Implements OFPAT_PUSH_MPLS ("push a new MPLS tag") as defined by the
1708 * OpenFlow Switch Specification.
1710 struct rte_flow_action_of_push_mpls {
1711 rte_be16_t ethertype; /**< EtherType. */
1716 * @b EXPERIMENTAL: this structure may change without prior notice
1718 * RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP
1720 * VXLAN tunnel end-point encapsulation data definition
1722 * The tunnel definition is provided through the flow item pattern, the
1723 * provided pattern must conform to RFC7348 for the tunnel specified. The flow
1724 * definition must be provided in order from the RTE_FLOW_ITEM_TYPE_ETH
1725 * definition up the end item which is specified by RTE_FLOW_ITEM_TYPE_END.
1727 * The mask field allows user to specify which fields in the flow item
1728 * definitions can be ignored and which have valid data and can be used
1731 * Note: the last field is not used in the definition of a tunnel and can be
1734 * Valid flow definition for RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP include:
1736 * - ETH / IPV4 / UDP / VXLAN / END
1737 * - ETH / IPV6 / UDP / VXLAN / END
1738 * - ETH / VLAN / IPV4 / UDP / VXLAN / END
1741 struct rte_flow_action_vxlan_encap {
1743 * Encapsulating vxlan tunnel definition
1744 * (terminated by the END pattern item).
1746 struct rte_flow_item *definition;
1751 * @b EXPERIMENTAL: this structure may change without prior notice
1753 * RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP
1755 * NVGRE tunnel end-point encapsulation data definition
1757 * The tunnel definition is provided through the flow item pattern the
1758 * provided pattern must conform with RFC7637. The flow definition must be
1759 * provided in order from the RTE_FLOW_ITEM_TYPE_ETH definition up the end item
1760 * which is specified by RTE_FLOW_ITEM_TYPE_END.
1762 * The mask field allows user to specify which fields in the flow item
1763 * definitions can be ignored and which have valid data and can be used
1766 * Note: the last field is not used in the definition of a tunnel and can be
1769 * Valid flow definition for RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP include:
1771 * - ETH / IPV4 / NVGRE / END
1772 * - ETH / VLAN / IPV6 / NVGRE / END
1775 struct rte_flow_action_nvgre_encap {
1777 * Encapsulating vxlan tunnel definition
1778 * (terminated by the END pattern item).
1780 struct rte_flow_item *definition;
1784 * Definition of a single action.
1786 * A list of actions is terminated by a END action.
1788 * For simple actions without a configuration structure, conf remains NULL.
1790 struct rte_flow_action {
1791 enum rte_flow_action_type type; /**< Action type. */
1792 const void *conf; /**< Pointer to action configuration structure. */
1796 * Opaque type returned after successfully creating a flow.
1798 * This handle can be used to manage and query the related flow (e.g. to
1799 * destroy it or retrieve counters).
1804 * Verbose error types.
1806 * Most of them provide the type of the object referenced by struct
1807 * rte_flow_error.cause.
1809 enum rte_flow_error_type {
1810 RTE_FLOW_ERROR_TYPE_NONE, /**< No error. */
1811 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, /**< Cause unspecified. */
1812 RTE_FLOW_ERROR_TYPE_HANDLE, /**< Flow rule (handle). */
1813 RTE_FLOW_ERROR_TYPE_ATTR_GROUP, /**< Group field. */
1814 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY, /**< Priority field. */
1815 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS, /**< Ingress field. */
1816 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, /**< Egress field. */
1817 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER, /**< Transfer field. */
1818 RTE_FLOW_ERROR_TYPE_ATTR, /**< Attributes structure. */
1819 RTE_FLOW_ERROR_TYPE_ITEM_NUM, /**< Pattern length. */
1820 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, /**< Item specification. */
1821 RTE_FLOW_ERROR_TYPE_ITEM_LAST, /**< Item specification range. */
1822 RTE_FLOW_ERROR_TYPE_ITEM_MASK, /**< Item specification mask. */
1823 RTE_FLOW_ERROR_TYPE_ITEM, /**< Specific pattern item. */
1824 RTE_FLOW_ERROR_TYPE_ACTION_NUM, /**< Number of actions. */
1825 RTE_FLOW_ERROR_TYPE_ACTION_CONF, /**< Action configuration. */
1826 RTE_FLOW_ERROR_TYPE_ACTION, /**< Specific action. */
1830 * Verbose error structure definition.
1832 * This object is normally allocated by applications and set by PMDs, the
1833 * message points to a constant string which does not need to be freed by
1834 * the application, however its pointer can be considered valid only as long
1835 * as its associated DPDK port remains configured. Closing the underlying
1836 * device or unloading the PMD invalidates it.
1838 * Both cause and message may be NULL regardless of the error type.
1840 struct rte_flow_error {
1841 enum rte_flow_error_type type; /**< Cause field and error types. */
1842 const void *cause; /**< Object responsible for the error. */
1843 const char *message; /**< Human-readable error message. */
1847 * Check whether a flow rule can be created on a given port.
1849 * The flow rule is validated for correctness and whether it could be accepted
1850 * by the device given sufficient resources. The rule is checked against the
1851 * current device mode and queue configuration. The flow rule may also
1852 * optionally be validated against existing flow rules and device resources.
1853 * This function has no effect on the target device.
1855 * The returned value is guaranteed to remain valid only as long as no
1856 * successful calls to rte_flow_create() or rte_flow_destroy() are made in
1857 * the meantime and no device parameter affecting flow rules in any way are
1858 * modified, due to possible collisions or resource limitations (although in
1859 * such cases EINVAL should not be returned).
1862 * Port identifier of Ethernet device.
1864 * Flow rule attributes.
1865 * @param[in] pattern
1866 * Pattern specification (list terminated by the END pattern item).
1867 * @param[in] actions
1868 * Associated actions (list terminated by the END action).
1870 * Perform verbose error reporting if not NULL. PMDs initialize this
1871 * structure in case of error only.
1874 * 0 if flow rule is valid and can be created. A negative errno value
1875 * otherwise (rte_errno is also set), the following errors are defined:
1877 * -ENOSYS: underlying device does not support this functionality.
1879 * -EIO: underlying device is removed.
1881 * -EINVAL: unknown or invalid rule specification.
1883 * -ENOTSUP: valid but unsupported rule specification (e.g. partial
1884 * bit-masks are unsupported).
1886 * -EEXIST: collision with an existing rule. Only returned if device
1887 * supports flow rule collision checking and there was a flow rule
1888 * collision. Not receiving this return code is no guarantee that creating
1889 * the rule will not fail due to a collision.
1891 * -ENOMEM: not enough memory to execute the function, or if the device
1892 * supports resource validation, resource limitation on the device.
1894 * -EBUSY: action cannot be performed due to busy device resources, may
1895 * succeed if the affected queues or even the entire port are in a stopped
1896 * state (see rte_eth_dev_rx_queue_stop() and rte_eth_dev_stop()).
1899 rte_flow_validate(uint16_t port_id,
1900 const struct rte_flow_attr *attr,
1901 const struct rte_flow_item pattern[],
1902 const struct rte_flow_action actions[],
1903 struct rte_flow_error *error);
1906 * Create a flow rule on a given port.
1909 * Port identifier of Ethernet device.
1911 * Flow rule attributes.
1912 * @param[in] pattern
1913 * Pattern specification (list terminated by the END pattern item).
1914 * @param[in] actions
1915 * Associated actions (list terminated by the END action).
1917 * Perform verbose error reporting if not NULL. PMDs initialize this
1918 * structure in case of error only.
1921 * A valid handle in case of success, NULL otherwise and rte_errno is set
1922 * to the positive version of one of the error codes defined for
1923 * rte_flow_validate().
1926 rte_flow_create(uint16_t port_id,
1927 const struct rte_flow_attr *attr,
1928 const struct rte_flow_item pattern[],
1929 const struct rte_flow_action actions[],
1930 struct rte_flow_error *error);
1933 * Destroy a flow rule on a given port.
1935 * Failure to destroy a flow rule handle may occur when other flow rules
1936 * depend on it, and destroying it would result in an inconsistent state.
1938 * This function is only guaranteed to succeed if handles are destroyed in
1939 * reverse order of their creation.
1942 * Port identifier of Ethernet device.
1944 * Flow rule handle to destroy.
1946 * Perform verbose error reporting if not NULL. PMDs initialize this
1947 * structure in case of error only.
1950 * 0 on success, a negative errno value otherwise and rte_errno is set.
1953 rte_flow_destroy(uint16_t port_id,
1954 struct rte_flow *flow,
1955 struct rte_flow_error *error);
1958 * Destroy all flow rules associated with a port.
1960 * In the unlikely event of failure, handles are still considered destroyed
1961 * and no longer valid but the port must be assumed to be in an inconsistent
1965 * Port identifier of Ethernet device.
1967 * Perform verbose error reporting if not NULL. PMDs initialize this
1968 * structure in case of error only.
1971 * 0 on success, a negative errno value otherwise and rte_errno is set.
1974 rte_flow_flush(uint16_t port_id,
1975 struct rte_flow_error *error);
1978 * Query an existing flow rule.
1980 * This function allows retrieving flow-specific data such as counters.
1981 * Data is gathered by special actions which must be present in the flow
1984 * \see RTE_FLOW_ACTION_TYPE_COUNT
1987 * Port identifier of Ethernet device.
1989 * Flow rule handle to query.
1991 * Action type to query.
1992 * @param[in, out] data
1993 * Pointer to storage for the associated query data type.
1995 * Perform verbose error reporting if not NULL. PMDs initialize this
1996 * structure in case of error only.
1999 * 0 on success, a negative errno value otherwise and rte_errno is set.
2002 rte_flow_query(uint16_t port_id,
2003 struct rte_flow *flow,
2004 enum rte_flow_action_type action,
2006 struct rte_flow_error *error);
2009 * Restrict ingress traffic to the defined flow rules.
2011 * Isolated mode guarantees that all ingress traffic comes from defined flow
2012 * rules only (current and future).
2014 * Besides making ingress more deterministic, it allows PMDs to safely reuse
2015 * resources otherwise assigned to handle the remaining traffic, such as
2016 * global RSS configuration settings, VLAN filters, MAC address entries,
2017 * legacy filter API rules and so on in order to expand the set of possible
2020 * Calling this function as soon as possible after device initialization,
2021 * ideally before the first call to rte_eth_dev_configure(), is recommended
2022 * to avoid possible failures due to conflicting settings.
2024 * Once effective, leaving isolated mode may not be possible depending on
2025 * PMD implementation.
2027 * Additionally, the following functionality has no effect on the underlying
2028 * port and may return errors such as ENOTSUP ("not supported"):
2030 * - Toggling promiscuous mode.
2031 * - Toggling allmulticast mode.
2032 * - Configuring MAC addresses.
2033 * - Configuring multicast addresses.
2034 * - Configuring VLAN filters.
2035 * - Configuring Rx filters through the legacy API (e.g. FDIR).
2036 * - Configuring global RSS settings.
2039 * Port identifier of Ethernet device.
2041 * Nonzero to enter isolated mode, attempt to leave it otherwise.
2043 * Perform verbose error reporting if not NULL. PMDs initialize this
2044 * structure in case of error only.
2047 * 0 on success, a negative errno value otherwise and rte_errno is set.
2050 rte_flow_isolate(uint16_t port_id, int set, struct rte_flow_error *error);
2053 * Initialize flow error structure.
2056 * Pointer to flow error structure (may be NULL).
2058 * Related error code (rte_errno).
2060 * Cause field and error types.
2062 * Object responsible for the error.
2064 * Human-readable error message.
2067 * Negative error code (errno value) and rte_errno is set.
2070 rte_flow_error_set(struct rte_flow_error *error,
2072 enum rte_flow_error_type type,
2074 const char *message);
2077 * Generic flow representation.
2079 * This form is sufficient to describe an rte_flow independently from any
2080 * PMD implementation and allows for replayability and identification.
2082 struct rte_flow_desc {
2083 size_t size; /**< Allocated space including data[]. */
2084 struct rte_flow_attr attr; /**< Attributes. */
2085 struct rte_flow_item *items; /**< Items. */
2086 struct rte_flow_action *actions; /**< Actions. */
2087 uint8_t data[]; /**< Storage for items/actions. */
2091 * Copy an rte_flow rule description.
2094 * Flow rule description.
2096 * Total size of allocated data for the flow description.
2098 * Flow rule attributes.
2100 * Pattern specification (list terminated by the END pattern item).
2101 * @param[in] actions
2102 * Associated actions (list terminated by the END action).
2105 * If len is greater or equal to the size of the flow, the total size of the
2106 * flow description and its data.
2107 * If len is lower than the size of the flow, the number of bytes that would
2108 * have been written to desc had it been sufficient. Nothing is written.
2111 rte_flow_copy(struct rte_flow_desc *fd, size_t len,
2112 const struct rte_flow_attr *attr,
2113 const struct rte_flow_item *items,
2114 const struct rte_flow_action *actions);
2120 #endif /* RTE_FLOW_H_ */