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 a per rule based within groups.
40 * Lower values denote higher priority, the highest priority for a flow rule
41 * is 0, so that a flow that matches for than one rule, the rule with the
42 * lowest priority value will always be matched.
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). Applications should be
48 * aware that groups are not linked by default, and that they must be
49 * explicitly linked by the application using the JUMP action.
51 * Priority levels are arbitrary and up to the application, they
52 * do not need to be contiguous nor start from 0, however the maximum number
53 * varies between devices and may be affected by existing flow rules.
55 * If a packet is matched by several rules of a given group for a given
56 * priority level, the outcome is undefined. It can take any path, may be
57 * duplicated or even cause unrecoverable errors.
59 * Note that support for more than a single group and priority level is not
62 * Flow rules can apply to inbound and/or outbound traffic (ingress/egress).
64 * Several pattern items and actions are valid and can be used in both
65 * directions. Those valid for only one direction are described as such.
67 * At least one direction must be specified.
69 * Specifying both directions at once for a given rule is not recommended
70 * but may be valid in a few cases (e.g. shared counter).
72 struct rte_flow_attr {
73 uint32_t group; /**< Priority group. */
74 uint32_t priority; /**< Rule priority level within group. */
75 uint32_t ingress:1; /**< Rule applies to ingress traffic. */
76 uint32_t egress:1; /**< Rule applies to egress traffic. */
78 * Instead of simply matching the properties of traffic as it would
79 * appear on a given DPDK port ID, enabling this attribute transfers
80 * a flow rule to the lowest possible level of any device endpoints
81 * found in the pattern.
83 * When supported, this effectively enables an application to
84 * re-route traffic not necessarily intended for it (e.g. coming
85 * from or addressed to different physical ports, VFs or
86 * applications) at the device level.
88 * It complements the behavior of some pattern items such as
89 * RTE_FLOW_ITEM_TYPE_PHY_PORT and is meaningless without them.
91 * When transferring flow rules, ingress and egress attributes keep
92 * their original meaning, as if processing traffic emitted or
93 * received by the application.
96 uint32_t reserved:29; /**< Reserved, must be zero. */
100 * Matching pattern item types.
102 * Pattern items fall in two categories:
104 * - Matching protocol headers and packet data, usually associated with a
105 * specification structure. These must be stacked in the same order as the
106 * protocol layers to match inside packets, starting from the lowest.
108 * - Matching meta-data or affecting pattern processing, often without a
109 * specification structure. Since they do not match packet contents, their
110 * position in the list is usually not relevant.
112 * See the description of individual types for more information. Those
113 * marked with [META] fall into the second category.
115 enum rte_flow_item_type {
119 * End marker for item lists. Prevents further processing of items,
120 * thereby ending the pattern.
122 * No associated specification structure.
124 RTE_FLOW_ITEM_TYPE_END,
129 * Used as a placeholder for convenience. It is ignored and simply
132 * No associated specification structure.
134 RTE_FLOW_ITEM_TYPE_VOID,
139 * Inverted matching, i.e. process packets that do not match the
142 * No associated specification structure.
144 RTE_FLOW_ITEM_TYPE_INVERT,
147 * Matches any protocol in place of the current layer, a single ANY
148 * may also stand for several protocol layers.
150 * See struct rte_flow_item_any.
152 RTE_FLOW_ITEM_TYPE_ANY,
157 * Matches traffic originating from (ingress) or going to (egress)
158 * the physical function of the current device.
160 * No associated specification structure.
162 RTE_FLOW_ITEM_TYPE_PF,
167 * Matches traffic originating from (ingress) or going to (egress) a
168 * given virtual function of the current device.
170 * See struct rte_flow_item_vf.
172 RTE_FLOW_ITEM_TYPE_VF,
177 * Matches traffic originating from (ingress) or going to (egress) a
178 * physical port of the underlying device.
180 * See struct rte_flow_item_phy_port.
182 RTE_FLOW_ITEM_TYPE_PHY_PORT,
187 * Matches traffic originating from (ingress) or going to (egress) a
188 * given DPDK port ID.
190 * See struct rte_flow_item_port_id.
192 RTE_FLOW_ITEM_TYPE_PORT_ID,
195 * Matches a byte string of a given length at a given offset.
197 * See struct rte_flow_item_raw.
199 RTE_FLOW_ITEM_TYPE_RAW,
202 * Matches an Ethernet header.
204 * See struct rte_flow_item_eth.
206 RTE_FLOW_ITEM_TYPE_ETH,
209 * Matches an 802.1Q/ad VLAN tag.
211 * See struct rte_flow_item_vlan.
213 RTE_FLOW_ITEM_TYPE_VLAN,
216 * Matches an IPv4 header.
218 * See struct rte_flow_item_ipv4.
220 RTE_FLOW_ITEM_TYPE_IPV4,
223 * Matches an IPv6 header.
225 * See struct rte_flow_item_ipv6.
227 RTE_FLOW_ITEM_TYPE_IPV6,
230 * Matches an ICMP header.
232 * See struct rte_flow_item_icmp.
234 RTE_FLOW_ITEM_TYPE_ICMP,
237 * Matches a UDP header.
239 * See struct rte_flow_item_udp.
241 RTE_FLOW_ITEM_TYPE_UDP,
244 * Matches a TCP header.
246 * See struct rte_flow_item_tcp.
248 RTE_FLOW_ITEM_TYPE_TCP,
251 * Matches a SCTP header.
253 * See struct rte_flow_item_sctp.
255 RTE_FLOW_ITEM_TYPE_SCTP,
258 * Matches a VXLAN header.
260 * See struct rte_flow_item_vxlan.
262 RTE_FLOW_ITEM_TYPE_VXLAN,
265 * Matches a E_TAG header.
267 * See struct rte_flow_item_e_tag.
269 RTE_FLOW_ITEM_TYPE_E_TAG,
272 * Matches a NVGRE header.
274 * See struct rte_flow_item_nvgre.
276 RTE_FLOW_ITEM_TYPE_NVGRE,
279 * Matches a MPLS header.
281 * See struct rte_flow_item_mpls.
283 RTE_FLOW_ITEM_TYPE_MPLS,
286 * Matches a GRE header.
288 * See struct rte_flow_item_gre.
290 RTE_FLOW_ITEM_TYPE_GRE,
295 * Fuzzy pattern match, expect faster than default.
297 * This is for device that support fuzzy matching option.
298 * Usually a fuzzy matching is fast but the cost is accuracy.
300 * See struct rte_flow_item_fuzzy.
302 RTE_FLOW_ITEM_TYPE_FUZZY,
305 * Matches a GTP header.
307 * Configure flow for GTP packets.
309 * See struct rte_flow_item_gtp.
311 RTE_FLOW_ITEM_TYPE_GTP,
314 * Matches a GTP header.
316 * Configure flow for GTP-C packets.
318 * See struct rte_flow_item_gtp.
320 RTE_FLOW_ITEM_TYPE_GTPC,
323 * Matches a GTP header.
325 * Configure flow for GTP-U packets.
327 * See struct rte_flow_item_gtp.
329 RTE_FLOW_ITEM_TYPE_GTPU,
332 * Matches a ESP header.
334 * See struct rte_flow_item_esp.
336 RTE_FLOW_ITEM_TYPE_ESP,
339 * Matches a GENEVE header.
341 * See struct rte_flow_item_geneve.
343 RTE_FLOW_ITEM_TYPE_GENEVE,
346 * Matches a VXLAN-GPE header.
348 * See struct rte_flow_item_vxlan_gpe.
350 RTE_FLOW_ITEM_TYPE_VXLAN_GPE,
353 * Matches an ARP header for Ethernet/IPv4.
355 * See struct rte_flow_item_arp_eth_ipv4.
357 RTE_FLOW_ITEM_TYPE_ARP_ETH_IPV4,
360 * Matches the presence of any IPv6 extension header.
362 * See struct rte_flow_item_ipv6_ext.
364 RTE_FLOW_ITEM_TYPE_IPV6_EXT,
367 * Matches any ICMPv6 header.
369 * See struct rte_flow_item_icmp6.
371 RTE_FLOW_ITEM_TYPE_ICMP6,
374 * Matches an ICMPv6 neighbor discovery solicitation.
376 * See struct rte_flow_item_icmp6_nd_ns.
378 RTE_FLOW_ITEM_TYPE_ICMP6_ND_NS,
381 * Matches an ICMPv6 neighbor discovery advertisement.
383 * See struct rte_flow_item_icmp6_nd_na.
385 RTE_FLOW_ITEM_TYPE_ICMP6_ND_NA,
388 * Matches the presence of any ICMPv6 neighbor discovery option.
390 * See struct rte_flow_item_icmp6_nd_opt.
392 RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT,
395 * Matches an ICMPv6 neighbor discovery source Ethernet link-layer
398 * See struct rte_flow_item_icmp6_nd_opt_sla_eth.
400 RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT_SLA_ETH,
403 * Matches an ICMPv6 neighbor discovery target Ethernet link-layer
406 * See struct rte_flow_item_icmp6_nd_opt_tla_eth.
408 RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT_TLA_ETH,
412 * RTE_FLOW_ITEM_TYPE_ANY
414 * Matches any protocol in place of the current layer, a single ANY may also
415 * stand for several protocol layers.
417 * This is usually specified as the first pattern item when looking for a
418 * protocol anywhere in a packet.
420 * A zeroed mask stands for any number of layers.
422 struct rte_flow_item_any {
423 uint32_t num; /**< Number of layers covered. */
426 /** Default mask for RTE_FLOW_ITEM_TYPE_ANY. */
428 static const struct rte_flow_item_any rte_flow_item_any_mask = {
434 * RTE_FLOW_ITEM_TYPE_VF
436 * Matches traffic originating from (ingress) or going to (egress) a given
437 * virtual function of the current device.
439 * If supported, should work even if the virtual function is not managed by
440 * the application and thus not associated with a DPDK port ID.
442 * Note this pattern item does not match VF representors traffic which, as
443 * separate entities, should be addressed through their own DPDK port IDs.
445 * - Can be specified multiple times to match traffic addressed to several
447 * - Can be combined with a PF item to match both PF and VF traffic.
449 * A zeroed mask can be used to match any VF ID.
451 struct rte_flow_item_vf {
452 uint32_t id; /**< VF ID. */
455 /** Default mask for RTE_FLOW_ITEM_TYPE_VF. */
457 static const struct rte_flow_item_vf rte_flow_item_vf_mask = {
463 * RTE_FLOW_ITEM_TYPE_PHY_PORT
465 * Matches traffic originating from (ingress) or going to (egress) a
466 * physical port of the underlying device.
468 * The first PHY_PORT item overrides the physical port normally associated
469 * with the specified DPDK input port (port_id). This item can be provided
470 * several times to match additional physical ports.
472 * Note that physical ports are not necessarily tied to DPDK input ports
473 * (port_id) when those are not under DPDK control. Possible values are
474 * specific to each device, they are not necessarily indexed from zero and
475 * may not be contiguous.
477 * As a device property, the list of allowed values as well as the value
478 * associated with a port_id should be retrieved by other means.
480 * A zeroed mask can be used to match any port index.
482 struct rte_flow_item_phy_port {
483 uint32_t index; /**< Physical port index. */
486 /** Default mask for RTE_FLOW_ITEM_TYPE_PHY_PORT. */
488 static const struct rte_flow_item_phy_port rte_flow_item_phy_port_mask = {
494 * RTE_FLOW_ITEM_TYPE_PORT_ID
496 * Matches traffic originating from (ingress) or going to (egress) a given
499 * Normally only supported if the port ID in question is known by the
500 * underlying PMD and related to the device the flow rule is created
503 * This must not be confused with @p PHY_PORT which refers to the physical
504 * port of a device, whereas @p PORT_ID refers to a struct rte_eth_dev
505 * object on the application side (also known as "port representor"
506 * depending on the kind of underlying device).
508 struct rte_flow_item_port_id {
509 uint32_t id; /**< DPDK port ID. */
512 /** Default mask for RTE_FLOW_ITEM_TYPE_PORT_ID. */
514 static const struct rte_flow_item_port_id rte_flow_item_port_id_mask = {
520 * RTE_FLOW_ITEM_TYPE_RAW
522 * Matches a byte string of a given length at a given offset.
524 * Offset is either absolute (using the start of the packet) or relative to
525 * the end of the previous matched item in the stack, in which case negative
526 * values are allowed.
528 * If search is enabled, offset is used as the starting point. The search
529 * area can be delimited by setting limit to a nonzero value, which is the
530 * maximum number of bytes after offset where the pattern may start.
532 * Matching a zero-length pattern is allowed, doing so resets the relative
533 * offset for subsequent items.
535 * This type does not support ranges (struct rte_flow_item.last).
537 struct rte_flow_item_raw {
538 uint32_t relative:1; /**< Look for pattern after the previous item. */
539 uint32_t search:1; /**< Search pattern from offset (see also limit). */
540 uint32_t reserved:30; /**< Reserved, must be set to zero. */
541 int32_t offset; /**< Absolute or relative offset for pattern. */
542 uint16_t limit; /**< Search area limit for start of pattern. */
543 uint16_t length; /**< Pattern length. */
544 const uint8_t *pattern; /**< Byte string to look for. */
547 /** Default mask for RTE_FLOW_ITEM_TYPE_RAW. */
549 static const struct rte_flow_item_raw rte_flow_item_raw_mask = {
552 .reserved = 0x3fffffff,
553 .offset = 0xffffffff,
561 * RTE_FLOW_ITEM_TYPE_ETH
563 * Matches an Ethernet header.
565 * The @p type field either stands for "EtherType" or "TPID" when followed
566 * by so-called layer 2.5 pattern items such as RTE_FLOW_ITEM_TYPE_VLAN. In
567 * the latter case, @p type refers to that of the outer header, with the
568 * inner EtherType/TPID provided by the subsequent pattern item. This is the
569 * same order as on the wire.
571 struct rte_flow_item_eth {
572 struct ether_addr dst; /**< Destination MAC. */
573 struct ether_addr src; /**< Source MAC. */
574 rte_be16_t type; /**< EtherType or TPID. */
577 /** Default mask for RTE_FLOW_ITEM_TYPE_ETH. */
579 static const struct rte_flow_item_eth rte_flow_item_eth_mask = {
580 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
581 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
582 .type = RTE_BE16(0x0000),
587 * RTE_FLOW_ITEM_TYPE_VLAN
589 * Matches an 802.1Q/ad VLAN tag.
591 * The corresponding standard outer EtherType (TPID) values are
592 * ETHER_TYPE_VLAN or ETHER_TYPE_QINQ. It can be overridden by the preceding
595 struct rte_flow_item_vlan {
596 rte_be16_t tci; /**< Tag control information. */
597 rte_be16_t inner_type; /**< Inner EtherType or TPID. */
600 /** Default mask for RTE_FLOW_ITEM_TYPE_VLAN. */
602 static const struct rte_flow_item_vlan rte_flow_item_vlan_mask = {
603 .tci = RTE_BE16(0x0fff),
604 .inner_type = RTE_BE16(0x0000),
609 * RTE_FLOW_ITEM_TYPE_IPV4
611 * Matches an IPv4 header.
613 * Note: IPv4 options are handled by dedicated pattern items.
615 struct rte_flow_item_ipv4 {
616 struct ipv4_hdr hdr; /**< IPv4 header definition. */
619 /** Default mask for RTE_FLOW_ITEM_TYPE_IPV4. */
621 static const struct rte_flow_item_ipv4 rte_flow_item_ipv4_mask = {
623 .src_addr = RTE_BE32(0xffffffff),
624 .dst_addr = RTE_BE32(0xffffffff),
630 * RTE_FLOW_ITEM_TYPE_IPV6.
632 * Matches an IPv6 header.
634 * Note: IPv6 options are handled by dedicated pattern items, see
635 * RTE_FLOW_ITEM_TYPE_IPV6_EXT.
637 struct rte_flow_item_ipv6 {
638 struct ipv6_hdr hdr; /**< IPv6 header definition. */
641 /** Default mask for RTE_FLOW_ITEM_TYPE_IPV6. */
643 static const struct rte_flow_item_ipv6 rte_flow_item_ipv6_mask = {
646 "\xff\xff\xff\xff\xff\xff\xff\xff"
647 "\xff\xff\xff\xff\xff\xff\xff\xff",
649 "\xff\xff\xff\xff\xff\xff\xff\xff"
650 "\xff\xff\xff\xff\xff\xff\xff\xff",
656 * RTE_FLOW_ITEM_TYPE_ICMP.
658 * Matches an ICMP header.
660 struct rte_flow_item_icmp {
661 struct icmp_hdr hdr; /**< ICMP header definition. */
664 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP. */
666 static const struct rte_flow_item_icmp rte_flow_item_icmp_mask = {
675 * RTE_FLOW_ITEM_TYPE_UDP.
677 * Matches a UDP header.
679 struct rte_flow_item_udp {
680 struct udp_hdr hdr; /**< UDP header definition. */
683 /** Default mask for RTE_FLOW_ITEM_TYPE_UDP. */
685 static const struct rte_flow_item_udp rte_flow_item_udp_mask = {
687 .src_port = RTE_BE16(0xffff),
688 .dst_port = RTE_BE16(0xffff),
694 * RTE_FLOW_ITEM_TYPE_TCP.
696 * Matches a TCP header.
698 struct rte_flow_item_tcp {
699 struct tcp_hdr hdr; /**< TCP header definition. */
702 /** Default mask for RTE_FLOW_ITEM_TYPE_TCP. */
704 static const struct rte_flow_item_tcp rte_flow_item_tcp_mask = {
706 .src_port = RTE_BE16(0xffff),
707 .dst_port = RTE_BE16(0xffff),
713 * RTE_FLOW_ITEM_TYPE_SCTP.
715 * Matches a SCTP header.
717 struct rte_flow_item_sctp {
718 struct sctp_hdr hdr; /**< SCTP header definition. */
721 /** Default mask for RTE_FLOW_ITEM_TYPE_SCTP. */
723 static const struct rte_flow_item_sctp rte_flow_item_sctp_mask = {
725 .src_port = RTE_BE16(0xffff),
726 .dst_port = RTE_BE16(0xffff),
732 * RTE_FLOW_ITEM_TYPE_VXLAN.
734 * Matches a VXLAN header (RFC 7348).
736 struct rte_flow_item_vxlan {
737 uint8_t flags; /**< Normally 0x08 (I flag). */
738 uint8_t rsvd0[3]; /**< Reserved, normally 0x000000. */
739 uint8_t vni[3]; /**< VXLAN identifier. */
740 uint8_t rsvd1; /**< Reserved, normally 0x00. */
743 /** Default mask for RTE_FLOW_ITEM_TYPE_VXLAN. */
745 static const struct rte_flow_item_vxlan rte_flow_item_vxlan_mask = {
746 .vni = "\xff\xff\xff",
751 * RTE_FLOW_ITEM_TYPE_E_TAG.
753 * Matches a E-tag header.
755 * The corresponding standard outer EtherType (TPID) value is
756 * ETHER_TYPE_ETAG. It can be overridden by the preceding pattern item.
758 struct rte_flow_item_e_tag {
760 * E-Tag control information (E-TCI).
761 * E-PCP (3b), E-DEI (1b), ingress E-CID base (12b).
763 rte_be16_t epcp_edei_in_ecid_b;
764 /** Reserved (2b), GRP (2b), E-CID base (12b). */
765 rte_be16_t rsvd_grp_ecid_b;
766 uint8_t in_ecid_e; /**< Ingress E-CID ext. */
767 uint8_t ecid_e; /**< E-CID ext. */
768 rte_be16_t inner_type; /**< Inner EtherType or TPID. */
771 /** Default mask for RTE_FLOW_ITEM_TYPE_E_TAG. */
773 static const struct rte_flow_item_e_tag rte_flow_item_e_tag_mask = {
774 .rsvd_grp_ecid_b = RTE_BE16(0x3fff),
779 * RTE_FLOW_ITEM_TYPE_NVGRE.
781 * Matches a NVGRE header.
783 struct rte_flow_item_nvgre {
785 * Checksum (1b), undefined (1b), key bit (1b), sequence number (1b),
786 * reserved 0 (9b), version (3b).
788 * c_k_s_rsvd0_ver must have value 0x2000 according to RFC 7637.
790 rte_be16_t c_k_s_rsvd0_ver;
791 rte_be16_t protocol; /**< Protocol type (0x6558). */
792 uint8_t tni[3]; /**< Virtual subnet ID. */
793 uint8_t flow_id; /**< Flow ID. */
796 /** Default mask for RTE_FLOW_ITEM_TYPE_NVGRE. */
798 static const struct rte_flow_item_nvgre rte_flow_item_nvgre_mask = {
799 .tni = "\xff\xff\xff",
804 * RTE_FLOW_ITEM_TYPE_MPLS.
806 * Matches a MPLS header.
808 struct rte_flow_item_mpls {
810 * Label (20b), TC (3b), Bottom of Stack (1b).
812 uint8_t label_tc_s[3];
813 uint8_t ttl; /** Time-to-Live. */
816 /** Default mask for RTE_FLOW_ITEM_TYPE_MPLS. */
818 static const struct rte_flow_item_mpls rte_flow_item_mpls_mask = {
819 .label_tc_s = "\xff\xff\xf0",
824 * RTE_FLOW_ITEM_TYPE_GRE.
826 * Matches a GRE header.
828 struct rte_flow_item_gre {
830 * Checksum (1b), reserved 0 (12b), version (3b).
833 rte_be16_t c_rsvd0_ver;
834 rte_be16_t protocol; /**< Protocol type. */
837 /** Default mask for RTE_FLOW_ITEM_TYPE_GRE. */
839 static const struct rte_flow_item_gre rte_flow_item_gre_mask = {
840 .protocol = RTE_BE16(0xffff),
845 * RTE_FLOW_ITEM_TYPE_FUZZY
847 * Fuzzy pattern match, expect faster than default.
849 * This is for device that support fuzzy match option.
850 * Usually a fuzzy match is fast but the cost is accuracy.
851 * i.e. Signature Match only match pattern's hash value, but it is
852 * possible two different patterns have the same hash value.
854 * Matching accuracy level can be configure by threshold.
855 * Driver can divide the range of threshold and map to different
856 * accuracy levels that device support.
858 * Threshold 0 means perfect match (no fuzziness), while threshold
859 * 0xffffffff means fuzziest match.
861 struct rte_flow_item_fuzzy {
862 uint32_t thresh; /**< Accuracy threshold. */
865 /** Default mask for RTE_FLOW_ITEM_TYPE_FUZZY. */
867 static const struct rte_flow_item_fuzzy rte_flow_item_fuzzy_mask = {
868 .thresh = 0xffffffff,
873 * RTE_FLOW_ITEM_TYPE_GTP.
875 * Matches a GTPv1 header.
877 struct rte_flow_item_gtp {
879 * Version (3b), protocol type (1b), reserved (1b),
880 * Extension header flag (1b),
881 * Sequence number flag (1b),
882 * N-PDU number flag (1b).
884 uint8_t v_pt_rsv_flags;
885 uint8_t msg_type; /**< Message type. */
886 rte_be16_t msg_len; /**< Message length. */
887 rte_be32_t teid; /**< Tunnel endpoint identifier. */
890 /** Default mask for RTE_FLOW_ITEM_TYPE_GTP. */
892 static const struct rte_flow_item_gtp rte_flow_item_gtp_mask = {
893 .teid = RTE_BE32(0xffffffff),
898 * RTE_FLOW_ITEM_TYPE_ESP
900 * Matches an ESP header.
902 struct rte_flow_item_esp {
903 struct esp_hdr hdr; /**< ESP header definition. */
906 /** Default mask for RTE_FLOW_ITEM_TYPE_ESP. */
908 static const struct rte_flow_item_esp rte_flow_item_esp_mask = {
916 * RTE_FLOW_ITEM_TYPE_GENEVE.
918 * Matches a GENEVE header.
920 struct rte_flow_item_geneve {
922 * Version (2b), length of the options fields (6b), OAM packet (1b),
923 * critical options present (1b), reserved 0 (6b).
925 rte_be16_t ver_opt_len_o_c_rsvd0;
926 rte_be16_t protocol; /**< Protocol type. */
927 uint8_t vni[3]; /**< Virtual Network Identifier. */
928 uint8_t rsvd1; /**< Reserved, normally 0x00. */
931 /** Default mask for RTE_FLOW_ITEM_TYPE_GENEVE. */
933 static const struct rte_flow_item_geneve rte_flow_item_geneve_mask = {
934 .vni = "\xff\xff\xff",
939 * RTE_FLOW_ITEM_TYPE_VXLAN_GPE (draft-ietf-nvo3-vxlan-gpe-05).
941 * Matches a VXLAN-GPE header.
943 struct rte_flow_item_vxlan_gpe {
944 uint8_t flags; /**< Normally 0x0c (I and P flags). */
945 uint8_t rsvd0[2]; /**< Reserved, normally 0x0000. */
946 uint8_t protocol; /**< Protocol type. */
947 uint8_t vni[3]; /**< VXLAN identifier. */
948 uint8_t rsvd1; /**< Reserved, normally 0x00. */
951 /** Default mask for RTE_FLOW_ITEM_TYPE_VXLAN_GPE. */
953 static const struct rte_flow_item_vxlan_gpe rte_flow_item_vxlan_gpe_mask = {
954 .vni = "\xff\xff\xff",
959 * RTE_FLOW_ITEM_TYPE_ARP_ETH_IPV4
961 * Matches an ARP header for Ethernet/IPv4.
963 struct rte_flow_item_arp_eth_ipv4 {
964 rte_be16_t hrd; /**< Hardware type, normally 1. */
965 rte_be16_t pro; /**< Protocol type, normally 0x0800. */
966 uint8_t hln; /**< Hardware address length, normally 6. */
967 uint8_t pln; /**< Protocol address length, normally 4. */
968 rte_be16_t op; /**< Opcode (1 for request, 2 for reply). */
969 struct ether_addr sha; /**< Sender hardware address. */
970 rte_be32_t spa; /**< Sender IPv4 address. */
971 struct ether_addr tha; /**< Target hardware address. */
972 rte_be32_t tpa; /**< Target IPv4 address. */
975 /** Default mask for RTE_FLOW_ITEM_TYPE_ARP_ETH_IPV4. */
977 static const struct rte_flow_item_arp_eth_ipv4
978 rte_flow_item_arp_eth_ipv4_mask = {
979 .sha.addr_bytes = "\xff\xff\xff\xff\xff\xff",
980 .spa = RTE_BE32(0xffffffff),
981 .tha.addr_bytes = "\xff\xff\xff\xff\xff\xff",
982 .tpa = RTE_BE32(0xffffffff),
987 * RTE_FLOW_ITEM_TYPE_IPV6_EXT
989 * Matches the presence of any IPv6 extension header.
991 * Normally preceded by any of:
993 * - RTE_FLOW_ITEM_TYPE_IPV6
994 * - RTE_FLOW_ITEM_TYPE_IPV6_EXT
996 struct rte_flow_item_ipv6_ext {
997 uint8_t next_hdr; /**< Next header. */
1000 /** Default mask for RTE_FLOW_ITEM_TYPE_IPV6_EXT. */
1003 struct rte_flow_item_ipv6_ext rte_flow_item_ipv6_ext_mask = {
1009 * RTE_FLOW_ITEM_TYPE_ICMP6
1011 * Matches any ICMPv6 header.
1013 struct rte_flow_item_icmp6 {
1014 uint8_t type; /**< ICMPv6 type. */
1015 uint8_t code; /**< ICMPv6 code. */
1016 uint16_t checksum; /**< ICMPv6 checksum. */
1019 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP6. */
1021 static const struct rte_flow_item_icmp6 rte_flow_item_icmp6_mask = {
1028 * RTE_FLOW_ITEM_TYPE_ICMP6_ND_NS
1030 * Matches an ICMPv6 neighbor discovery solicitation.
1032 struct rte_flow_item_icmp6_nd_ns {
1033 uint8_t type; /**< ICMPv6 type, normally 135. */
1034 uint8_t code; /**< ICMPv6 code, normally 0. */
1035 rte_be16_t checksum; /**< ICMPv6 checksum. */
1036 rte_be32_t reserved; /**< Reserved, normally 0. */
1037 uint8_t target_addr[16]; /**< Target address. */
1040 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP6_ND_NS. */
1043 struct rte_flow_item_icmp6_nd_ns rte_flow_item_icmp6_nd_ns_mask = {
1045 "\xff\xff\xff\xff\xff\xff\xff\xff"
1046 "\xff\xff\xff\xff\xff\xff\xff\xff",
1051 * RTE_FLOW_ITEM_TYPE_ICMP6_ND_NA
1053 * Matches an ICMPv6 neighbor discovery advertisement.
1055 struct rte_flow_item_icmp6_nd_na {
1056 uint8_t type; /**< ICMPv6 type, normally 136. */
1057 uint8_t code; /**< ICMPv6 code, normally 0. */
1058 rte_be16_t checksum; /**< ICMPv6 checksum. */
1060 * Route flag (1b), solicited flag (1b), override flag (1b),
1063 rte_be32_t rso_reserved;
1064 uint8_t target_addr[16]; /**< Target address. */
1067 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP6_ND_NA. */
1070 struct rte_flow_item_icmp6_nd_na rte_flow_item_icmp6_nd_na_mask = {
1072 "\xff\xff\xff\xff\xff\xff\xff\xff"
1073 "\xff\xff\xff\xff\xff\xff\xff\xff",
1078 * RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT
1080 * Matches the presence of any ICMPv6 neighbor discovery option.
1082 * Normally preceded by any of:
1084 * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_NA
1085 * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_NS
1086 * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT
1088 struct rte_flow_item_icmp6_nd_opt {
1089 uint8_t type; /**< ND option type. */
1090 uint8_t length; /**< ND option length. */
1093 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT. */
1095 static const struct rte_flow_item_icmp6_nd_opt
1096 rte_flow_item_icmp6_nd_opt_mask = {
1102 * RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT_SLA_ETH
1104 * Matches an ICMPv6 neighbor discovery source Ethernet link-layer address
1107 * Normally preceded by any of:
1109 * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_NA
1110 * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT
1112 struct rte_flow_item_icmp6_nd_opt_sla_eth {
1113 uint8_t type; /**< ND option type, normally 1. */
1114 uint8_t length; /**< ND option length, normally 1. */
1115 struct ether_addr sla; /**< Source Ethernet LLA. */
1118 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT_SLA_ETH. */
1120 static const struct rte_flow_item_icmp6_nd_opt_sla_eth
1121 rte_flow_item_icmp6_nd_opt_sla_eth_mask = {
1122 .sla.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1127 * RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT_TLA_ETH
1129 * Matches an ICMPv6 neighbor discovery target Ethernet link-layer address
1132 * Normally preceded by any of:
1134 * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_NS
1135 * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT
1137 struct rte_flow_item_icmp6_nd_opt_tla_eth {
1138 uint8_t type; /**< ND option type, normally 2. */
1139 uint8_t length; /**< ND option length, normally 1. */
1140 struct ether_addr tla; /**< Target Ethernet LLA. */
1143 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT_TLA_ETH. */
1145 static const struct rte_flow_item_icmp6_nd_opt_tla_eth
1146 rte_flow_item_icmp6_nd_opt_tla_eth_mask = {
1147 .tla.addr_bytes = "\xff\xff\xff\xff\xff\xff",
1152 * Matching pattern item definition.
1154 * A pattern is formed by stacking items starting from the lowest protocol
1155 * layer to match. This stacking restriction does not apply to meta items
1156 * which can be placed anywhere in the stack without affecting the meaning
1157 * of the resulting pattern.
1159 * Patterns are terminated by END items.
1161 * The spec field should be a valid pointer to a structure of the related
1162 * item type. It may remain unspecified (NULL) in many cases to request
1163 * broad (nonspecific) matching. In such cases, last and mask must also be
1166 * Optionally, last can point to a structure of the same type to define an
1167 * inclusive range. This is mostly supported by integer and address fields,
1168 * may cause errors otherwise. Fields that do not support ranges must be set
1169 * to 0 or to the same value as the corresponding fields in spec.
1171 * Only the fields defined to nonzero values in the default masks (see
1172 * rte_flow_item_{name}_mask constants) are considered relevant by
1173 * default. This can be overridden by providing a mask structure of the
1174 * same type with applicable bits set to one. It can also be used to
1175 * partially filter out specific fields (e.g. as an alternate mean to match
1176 * ranges of IP addresses).
1178 * Mask is a simple bit-mask applied before interpreting the contents of
1179 * spec and last, which may yield unexpected results if not used
1180 * carefully. For example, if for an IPv4 address field, spec provides
1181 * 10.1.2.3, last provides 10.3.4.5 and mask provides 255.255.0.0, the
1182 * effective range becomes 10.1.0.0 to 10.3.255.255.
1184 struct rte_flow_item {
1185 enum rte_flow_item_type type; /**< Item type. */
1186 const void *spec; /**< Pointer to item specification structure. */
1187 const void *last; /**< Defines an inclusive range (spec to last). */
1188 const void *mask; /**< Bit-mask applied to spec and last. */
1194 * Each possible action is represented by a type. Some have associated
1195 * configuration structures. Several actions combined in a list can be
1196 * assigned to a flow rule and are performed in order.
1198 * They fall in three categories:
1200 * - Actions that modify the fate of matching traffic, for instance by
1201 * dropping or assigning it a specific destination.
1203 * - Actions that modify matching traffic contents or its properties. This
1204 * includes adding/removing encapsulation, encryption, compression and
1207 * - Actions related to the flow rule itself, such as updating counters or
1208 * making it non-terminating.
1210 * Flow rules being terminating by default, not specifying any action of the
1211 * fate kind results in undefined behavior. This applies to both ingress and
1214 * PASSTHRU, when supported, makes a flow rule non-terminating.
1216 enum rte_flow_action_type {
1218 * End marker for action lists. Prevents further processing of
1219 * actions, thereby ending the list.
1221 * No associated configuration structure.
1223 RTE_FLOW_ACTION_TYPE_END,
1226 * Used as a placeholder for convenience. It is ignored and simply
1227 * discarded by PMDs.
1229 * No associated configuration structure.
1231 RTE_FLOW_ACTION_TYPE_VOID,
1234 * Leaves traffic up for additional processing by subsequent flow
1235 * rules; makes a flow rule non-terminating.
1237 * No associated configuration structure.
1239 RTE_FLOW_ACTION_TYPE_PASSTHRU,
1242 * RTE_FLOW_ACTION_TYPE_JUMP
1244 * Redirects packets to a group on the current device.
1246 * See struct rte_flow_action_jump.
1248 RTE_FLOW_ACTION_TYPE_JUMP,
1251 * Attaches an integer value to packets and sets PKT_RX_FDIR and
1252 * PKT_RX_FDIR_ID mbuf flags.
1254 * See struct rte_flow_action_mark.
1256 RTE_FLOW_ACTION_TYPE_MARK,
1259 * Flags packets. Similar to MARK without a specific value; only
1260 * sets the PKT_RX_FDIR mbuf flag.
1262 * No associated configuration structure.
1264 RTE_FLOW_ACTION_TYPE_FLAG,
1267 * Assigns packets to a given queue index.
1269 * See struct rte_flow_action_queue.
1271 RTE_FLOW_ACTION_TYPE_QUEUE,
1276 * PASSTHRU overrides this action if both are specified.
1278 * No associated configuration structure.
1280 RTE_FLOW_ACTION_TYPE_DROP,
1283 * Enables counters for this flow rule.
1285 * These counters can be retrieved and reset through rte_flow_query(),
1286 * see struct rte_flow_query_count.
1288 * No associated configuration structure.
1290 RTE_FLOW_ACTION_TYPE_COUNT,
1293 * Similar to QUEUE, except RSS is additionally performed on packets
1294 * to spread them among several queues according to the provided
1297 * See struct rte_flow_action_rss.
1299 RTE_FLOW_ACTION_TYPE_RSS,
1302 * Directs matching traffic to the physical function (PF) of the
1305 * No associated configuration structure.
1307 RTE_FLOW_ACTION_TYPE_PF,
1310 * Directs matching traffic to a given virtual function of the
1313 * See struct rte_flow_action_vf.
1315 RTE_FLOW_ACTION_TYPE_VF,
1318 * Directs packets to a given physical port index of the underlying
1321 * See struct rte_flow_action_phy_port.
1323 RTE_FLOW_ACTION_TYPE_PHY_PORT,
1326 * Directs matching traffic to a given DPDK port ID.
1328 * See struct rte_flow_action_port_id.
1330 RTE_FLOW_ACTION_TYPE_PORT_ID,
1333 * Traffic metering and policing (MTR).
1335 * See struct rte_flow_action_meter.
1336 * See file rte_mtr.h for MTR object configuration.
1338 RTE_FLOW_ACTION_TYPE_METER,
1341 * Redirects packets to security engine of current device for security
1342 * processing as specified by security session.
1344 * See struct rte_flow_action_security.
1346 RTE_FLOW_ACTION_TYPE_SECURITY,
1349 * Implements OFPAT_SET_MPLS_TTL ("MPLS TTL") as defined by the
1350 * OpenFlow Switch Specification.
1352 * See struct rte_flow_action_of_set_mpls_ttl.
1354 RTE_FLOW_ACTION_TYPE_OF_SET_MPLS_TTL,
1357 * Implements OFPAT_DEC_MPLS_TTL ("decrement MPLS TTL") as defined
1358 * by the OpenFlow Switch Specification.
1360 * No associated configuration structure.
1362 RTE_FLOW_ACTION_TYPE_OF_DEC_MPLS_TTL,
1365 * Implements OFPAT_SET_NW_TTL ("IP TTL") as defined by the OpenFlow
1366 * Switch Specification.
1368 * See struct rte_flow_action_of_set_nw_ttl.
1370 RTE_FLOW_ACTION_TYPE_OF_SET_NW_TTL,
1373 * Implements OFPAT_DEC_NW_TTL ("decrement IP TTL") as defined by
1374 * the OpenFlow Switch Specification.
1376 * No associated configuration structure.
1378 RTE_FLOW_ACTION_TYPE_OF_DEC_NW_TTL,
1381 * Implements OFPAT_COPY_TTL_OUT ("copy TTL "outwards" -- from
1382 * next-to-outermost to outermost") as defined by the OpenFlow
1383 * Switch Specification.
1385 * No associated configuration structure.
1387 RTE_FLOW_ACTION_TYPE_OF_COPY_TTL_OUT,
1390 * Implements OFPAT_COPY_TTL_IN ("copy TTL "inwards" -- from
1391 * outermost to next-to-outermost") as defined by the OpenFlow
1392 * Switch Specification.
1394 * No associated configuration structure.
1396 RTE_FLOW_ACTION_TYPE_OF_COPY_TTL_IN,
1399 * Implements OFPAT_POP_VLAN ("pop the outer VLAN tag") as defined
1400 * by the OpenFlow Switch Specification.
1402 * No associated configuration structure.
1404 RTE_FLOW_ACTION_TYPE_OF_POP_VLAN,
1407 * Implements OFPAT_PUSH_VLAN ("push a new VLAN tag") as defined by
1408 * the OpenFlow Switch Specification.
1410 * See struct rte_flow_action_of_push_vlan.
1412 RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN,
1415 * Implements OFPAT_SET_VLAN_VID ("set the 802.1q VLAN id") as
1416 * defined by the OpenFlow Switch Specification.
1418 * See struct rte_flow_action_of_set_vlan_vid.
1420 RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID,
1423 * Implements OFPAT_SET_LAN_PCP ("set the 802.1q priority") as
1424 * defined by the OpenFlow Switch Specification.
1426 * See struct rte_flow_action_of_set_vlan_pcp.
1428 RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP,
1431 * Implements OFPAT_POP_MPLS ("pop the outer MPLS tag") as defined
1432 * by the OpenFlow Switch Specification.
1434 * See struct rte_flow_action_of_pop_mpls.
1436 RTE_FLOW_ACTION_TYPE_OF_POP_MPLS,
1439 * Implements OFPAT_PUSH_MPLS ("push a new MPLS tag") as defined by
1440 * the OpenFlow Switch Specification.
1442 * See struct rte_flow_action_of_push_mpls.
1444 RTE_FLOW_ACTION_TYPE_OF_PUSH_MPLS,
1447 * Encapsulate flow in VXLAN tunnel as defined in
1448 * rte_flow_action_vxlan_encap action structure.
1450 * See struct rte_flow_action_vxlan_encap.
1452 RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP,
1455 * Decapsulate outer most VXLAN tunnel from matched flow.
1457 * If flow pattern does not define a valid VXLAN tunnel (as specified by
1458 * RFC7348) then the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION
1461 RTE_FLOW_ACTION_TYPE_VXLAN_DECAP,
1464 * Encapsulate flow in NVGRE tunnel defined in the
1465 * rte_flow_action_nvgre_encap action structure.
1467 * See struct rte_flow_action_nvgre_encap.
1469 RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP,
1472 * Decapsulate outer most NVGRE tunnel from matched flow.
1474 * If flow pattern does not define a valid NVGRE tunnel (as specified by
1475 * RFC7637) then the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION
1478 RTE_FLOW_ACTION_TYPE_NVGRE_DECAP,
1482 * RTE_FLOW_ACTION_TYPE_MARK
1484 * Attaches an integer value to packets and sets PKT_RX_FDIR and
1485 * PKT_RX_FDIR_ID mbuf flags.
1487 * This value is arbitrary and application-defined. Maximum allowed value
1488 * depends on the underlying implementation. It is returned in the
1489 * hash.fdir.hi mbuf field.
1491 struct rte_flow_action_mark {
1492 uint32_t id; /**< Integer value to return with packets. */
1497 * @b EXPERIMENTAL: this structure may change without prior notice
1499 * RTE_FLOW_ACTION_TYPE_JUMP
1501 * Redirects packets to a group on the current device.
1503 * In a hierarchy of groups, which can be used to represent physical or logical
1504 * flow tables on the device, this action allows the action to be a redirect to
1505 * a group on that device.
1507 struct rte_flow_action_jump {
1512 * RTE_FLOW_ACTION_TYPE_QUEUE
1514 * Assign packets to a given queue index.
1516 struct rte_flow_action_queue {
1517 uint16_t index; /**< Queue index to use. */
1521 * RTE_FLOW_ACTION_TYPE_COUNT (query)
1523 * Query structure to retrieve and reset flow rule counters.
1525 struct rte_flow_query_count {
1526 uint32_t reset:1; /**< Reset counters after query [in]. */
1527 uint32_t hits_set:1; /**< hits field is set [out]. */
1528 uint32_t bytes_set:1; /**< bytes field is set [out]. */
1529 uint32_t reserved:29; /**< Reserved, must be zero [in, out]. */
1530 uint64_t hits; /**< Number of hits for this rule [out]. */
1531 uint64_t bytes; /**< Number of bytes through this rule [out]. */
1535 * RTE_FLOW_ACTION_TYPE_RSS
1537 * Similar to QUEUE, except RSS is additionally performed on packets to
1538 * spread them among several queues according to the provided parameters.
1540 * Unlike global RSS settings used by other DPDK APIs, unsetting the
1541 * @p types field does not disable RSS in a flow rule. Doing so instead
1542 * requests safe unspecified "best-effort" settings from the underlying PMD,
1543 * which depending on the flow rule, may result in anything ranging from
1544 * empty (single queue) to all-inclusive RSS.
1546 * Note: RSS hash result is stored in the hash.rss mbuf field which overlaps
1547 * hash.fdir.lo. Since the MARK action sets the hash.fdir.hi field only,
1548 * both can be requested simultaneously.
1550 struct rte_flow_action_rss {
1551 enum rte_eth_hash_function func; /**< RSS hash function to apply. */
1553 * Packet encapsulation level RSS hash @p types apply to.
1555 * - @p 0 requests the default behavior. Depending on the packet
1556 * type, it can mean outermost, innermost, anything in between or
1559 * It basically stands for the innermost encapsulation level RSS
1560 * can be performed on according to PMD and device capabilities.
1562 * - @p 1 requests RSS to be performed on the outermost packet
1563 * encapsulation level.
1565 * - @p 2 and subsequent values request RSS to be performed on the
1566 * specified inner packet encapsulation level, from outermost to
1567 * innermost (lower to higher values).
1569 * Values other than @p 0 are not necessarily supported.
1571 * Requesting a specific RSS level on unrecognized traffic results
1572 * in undefined behavior. For predictable results, it is recommended
1573 * to make the flow rule pattern match packet headers up to the
1574 * requested encapsulation level so that only matching traffic goes
1578 uint64_t types; /**< Specific RSS hash types (see ETH_RSS_*). */
1579 uint32_t key_len; /**< Hash key length in bytes. */
1580 uint32_t queue_num; /**< Number of entries in @p queue. */
1581 const uint8_t *key; /**< Hash key. */
1582 const uint16_t *queue; /**< Queue indices to use. */
1586 * RTE_FLOW_ACTION_TYPE_VF
1588 * Directs matching traffic to a given virtual function of the current
1591 * Packets matched by a VF pattern item can be redirected to their original
1592 * VF ID instead of the specified one. This parameter may not be available
1593 * and is not guaranteed to work properly if the VF part is matched by a
1594 * prior flow rule or if packets are not addressed to a VF in the first
1597 struct rte_flow_action_vf {
1598 uint32_t original:1; /**< Use original VF ID if possible. */
1599 uint32_t reserved:31; /**< Reserved, must be zero. */
1600 uint32_t id; /**< VF ID. */
1604 * RTE_FLOW_ACTION_TYPE_PHY_PORT
1606 * Directs packets to a given physical port index of the underlying
1609 * @see RTE_FLOW_ITEM_TYPE_PHY_PORT
1611 struct rte_flow_action_phy_port {
1612 uint32_t original:1; /**< Use original port index if possible. */
1613 uint32_t reserved:31; /**< Reserved, must be zero. */
1614 uint32_t index; /**< Physical port index. */
1618 * RTE_FLOW_ACTION_TYPE_PORT_ID
1620 * Directs matching traffic to a given DPDK port ID.
1622 * @see RTE_FLOW_ITEM_TYPE_PORT_ID
1624 struct rte_flow_action_port_id {
1625 uint32_t original:1; /**< Use original DPDK port ID if possible. */
1626 uint32_t reserved:31; /**< Reserved, must be zero. */
1627 uint32_t id; /**< DPDK port ID. */
1631 * RTE_FLOW_ACTION_TYPE_METER
1633 * Traffic metering and policing (MTR).
1635 * Packets matched by items of this type can be either dropped or passed to the
1636 * next item with their color set by the MTR object.
1638 struct rte_flow_action_meter {
1639 uint32_t mtr_id; /**< MTR object ID created with rte_mtr_create(). */
1643 * RTE_FLOW_ACTION_TYPE_SECURITY
1645 * Perform the security action on flows matched by the pattern items
1646 * according to the configuration of the security session.
1648 * This action modifies the payload of matched flows. For INLINE_CRYPTO, the
1649 * security protocol headers and IV are fully provided by the application as
1650 * specified in the flow pattern. The payload of matching packets is
1651 * encrypted on egress, and decrypted and authenticated on ingress.
1652 * For INLINE_PROTOCOL, the security protocol is fully offloaded to HW,
1653 * providing full encapsulation and decapsulation of packets in security
1654 * protocols. The flow pattern specifies both the outer security header fields
1655 * and the inner packet fields. The security session specified in the action
1656 * must match the pattern parameters.
1658 * The security session specified in the action must be created on the same
1659 * port as the flow action that is being specified.
1661 * The ingress/egress flow attribute should match that specified in the
1662 * security session if the security session supports the definition of the
1665 * Multiple flows can be configured to use the same security session.
1667 struct rte_flow_action_security {
1668 void *security_session; /**< Pointer to security session structure. */
1672 * RTE_FLOW_ACTION_TYPE_OF_SET_MPLS_TTL
1674 * Implements OFPAT_SET_MPLS_TTL ("MPLS TTL") as defined by the OpenFlow
1675 * Switch Specification.
1677 struct rte_flow_action_of_set_mpls_ttl {
1678 uint8_t mpls_ttl; /**< MPLS TTL. */
1682 * RTE_FLOW_ACTION_TYPE_OF_SET_NW_TTL
1684 * Implements OFPAT_SET_NW_TTL ("IP TTL") as defined by the OpenFlow Switch
1687 struct rte_flow_action_of_set_nw_ttl {
1688 uint8_t nw_ttl; /**< IP TTL. */
1692 * RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN
1694 * Implements OFPAT_PUSH_VLAN ("push a new VLAN tag") as defined by the
1695 * OpenFlow Switch Specification.
1697 struct rte_flow_action_of_push_vlan {
1698 rte_be16_t ethertype; /**< EtherType. */
1702 * RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID
1704 * Implements OFPAT_SET_VLAN_VID ("set the 802.1q VLAN id") as defined by
1705 * the OpenFlow Switch Specification.
1707 struct rte_flow_action_of_set_vlan_vid {
1708 rte_be16_t vlan_vid; /**< VLAN id. */
1712 * RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP
1714 * Implements OFPAT_SET_LAN_PCP ("set the 802.1q priority") as defined by
1715 * the OpenFlow Switch Specification.
1717 struct rte_flow_action_of_set_vlan_pcp {
1718 uint8_t vlan_pcp; /**< VLAN priority. */
1722 * RTE_FLOW_ACTION_TYPE_OF_POP_MPLS
1724 * Implements OFPAT_POP_MPLS ("pop the outer MPLS tag") as defined by the
1725 * OpenFlow Switch Specification.
1727 struct rte_flow_action_of_pop_mpls {
1728 rte_be16_t ethertype; /**< EtherType. */
1732 * RTE_FLOW_ACTION_TYPE_OF_PUSH_MPLS
1734 * Implements OFPAT_PUSH_MPLS ("push a new MPLS tag") as defined by the
1735 * OpenFlow Switch Specification.
1737 struct rte_flow_action_of_push_mpls {
1738 rte_be16_t ethertype; /**< EtherType. */
1743 * @b EXPERIMENTAL: this structure may change without prior notice
1745 * RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP
1747 * VXLAN tunnel end-point encapsulation data definition
1749 * The tunnel definition is provided through the flow item pattern, the
1750 * provided pattern must conform to RFC7348 for the tunnel specified. The flow
1751 * definition must be provided in order from the RTE_FLOW_ITEM_TYPE_ETH
1752 * definition up the end item which is specified by RTE_FLOW_ITEM_TYPE_END.
1754 * The mask field allows user to specify which fields in the flow item
1755 * definitions can be ignored and which have valid data and can be used
1758 * Note: the last field is not used in the definition of a tunnel and can be
1761 * Valid flow definition for RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP include:
1763 * - ETH / IPV4 / UDP / VXLAN / END
1764 * - ETH / IPV6 / UDP / VXLAN / END
1765 * - ETH / VLAN / IPV4 / UDP / VXLAN / END
1768 struct rte_flow_action_vxlan_encap {
1770 * Encapsulating vxlan tunnel definition
1771 * (terminated by the END pattern item).
1773 struct rte_flow_item *definition;
1778 * @b EXPERIMENTAL: this structure may change without prior notice
1780 * RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP
1782 * NVGRE tunnel end-point encapsulation data definition
1784 * The tunnel definition is provided through the flow item pattern the
1785 * provided pattern must conform with RFC7637. The flow definition must be
1786 * provided in order from the RTE_FLOW_ITEM_TYPE_ETH definition up the end item
1787 * which is specified by RTE_FLOW_ITEM_TYPE_END.
1789 * The mask field allows user to specify which fields in the flow item
1790 * definitions can be ignored and which have valid data and can be used
1793 * Note: the last field is not used in the definition of a tunnel and can be
1796 * Valid flow definition for RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP include:
1798 * - ETH / IPV4 / NVGRE / END
1799 * - ETH / VLAN / IPV6 / NVGRE / END
1802 struct rte_flow_action_nvgre_encap {
1804 * Encapsulating vxlan tunnel definition
1805 * (terminated by the END pattern item).
1807 struct rte_flow_item *definition;
1811 * Definition of a single action.
1813 * A list of actions is terminated by a END action.
1815 * For simple actions without a configuration structure, conf remains NULL.
1817 struct rte_flow_action {
1818 enum rte_flow_action_type type; /**< Action type. */
1819 const void *conf; /**< Pointer to action configuration structure. */
1823 * Opaque type returned after successfully creating a flow.
1825 * This handle can be used to manage and query the related flow (e.g. to
1826 * destroy it or retrieve counters).
1831 * Verbose error types.
1833 * Most of them provide the type of the object referenced by struct
1834 * rte_flow_error.cause.
1836 enum rte_flow_error_type {
1837 RTE_FLOW_ERROR_TYPE_NONE, /**< No error. */
1838 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, /**< Cause unspecified. */
1839 RTE_FLOW_ERROR_TYPE_HANDLE, /**< Flow rule (handle). */
1840 RTE_FLOW_ERROR_TYPE_ATTR_GROUP, /**< Group field. */
1841 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY, /**< Priority field. */
1842 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS, /**< Ingress field. */
1843 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, /**< Egress field. */
1844 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER, /**< Transfer field. */
1845 RTE_FLOW_ERROR_TYPE_ATTR, /**< Attributes structure. */
1846 RTE_FLOW_ERROR_TYPE_ITEM_NUM, /**< Pattern length. */
1847 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, /**< Item specification. */
1848 RTE_FLOW_ERROR_TYPE_ITEM_LAST, /**< Item specification range. */
1849 RTE_FLOW_ERROR_TYPE_ITEM_MASK, /**< Item specification mask. */
1850 RTE_FLOW_ERROR_TYPE_ITEM, /**< Specific pattern item. */
1851 RTE_FLOW_ERROR_TYPE_ACTION_NUM, /**< Number of actions. */
1852 RTE_FLOW_ERROR_TYPE_ACTION_CONF, /**< Action configuration. */
1853 RTE_FLOW_ERROR_TYPE_ACTION, /**< Specific action. */
1857 * Verbose error structure definition.
1859 * This object is normally allocated by applications and set by PMDs, the
1860 * message points to a constant string which does not need to be freed by
1861 * the application, however its pointer can be considered valid only as long
1862 * as its associated DPDK port remains configured. Closing the underlying
1863 * device or unloading the PMD invalidates it.
1865 * Both cause and message may be NULL regardless of the error type.
1867 struct rte_flow_error {
1868 enum rte_flow_error_type type; /**< Cause field and error types. */
1869 const void *cause; /**< Object responsible for the error. */
1870 const char *message; /**< Human-readable error message. */
1874 * Check whether a flow rule can be created on a given port.
1876 * The flow rule is validated for correctness and whether it could be accepted
1877 * by the device given sufficient resources. The rule is checked against the
1878 * current device mode and queue configuration. The flow rule may also
1879 * optionally be validated against existing flow rules and device resources.
1880 * This function has no effect on the target device.
1882 * The returned value is guaranteed to remain valid only as long as no
1883 * successful calls to rte_flow_create() or rte_flow_destroy() are made in
1884 * the meantime and no device parameter affecting flow rules in any way are
1885 * modified, due to possible collisions or resource limitations (although in
1886 * such cases EINVAL should not be returned).
1889 * Port identifier of Ethernet device.
1891 * Flow rule attributes.
1892 * @param[in] pattern
1893 * Pattern specification (list terminated by the END pattern item).
1894 * @param[in] actions
1895 * Associated actions (list terminated by the END action).
1897 * Perform verbose error reporting if not NULL. PMDs initialize this
1898 * structure in case of error only.
1901 * 0 if flow rule is valid and can be created. A negative errno value
1902 * otherwise (rte_errno is also set), the following errors are defined:
1904 * -ENOSYS: underlying device does not support this functionality.
1906 * -EIO: underlying device is removed.
1908 * -EINVAL: unknown or invalid rule specification.
1910 * -ENOTSUP: valid but unsupported rule specification (e.g. partial
1911 * bit-masks are unsupported).
1913 * -EEXIST: collision with an existing rule. Only returned if device
1914 * supports flow rule collision checking and there was a flow rule
1915 * collision. Not receiving this return code is no guarantee that creating
1916 * the rule will not fail due to a collision.
1918 * -ENOMEM: not enough memory to execute the function, or if the device
1919 * supports resource validation, resource limitation on the device.
1921 * -EBUSY: action cannot be performed due to busy device resources, may
1922 * succeed if the affected queues or even the entire port are in a stopped
1923 * state (see rte_eth_dev_rx_queue_stop() and rte_eth_dev_stop()).
1926 rte_flow_validate(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 * Create a flow rule on a given port.
1936 * Port identifier of Ethernet device.
1938 * Flow rule attributes.
1939 * @param[in] pattern
1940 * Pattern specification (list terminated by the END pattern item).
1941 * @param[in] actions
1942 * Associated actions (list terminated by the END action).
1944 * Perform verbose error reporting if not NULL. PMDs initialize this
1945 * structure in case of error only.
1948 * A valid handle in case of success, NULL otherwise and rte_errno is set
1949 * to the positive version of one of the error codes defined for
1950 * rte_flow_validate().
1953 rte_flow_create(uint16_t port_id,
1954 const struct rte_flow_attr *attr,
1955 const struct rte_flow_item pattern[],
1956 const struct rte_flow_action actions[],
1957 struct rte_flow_error *error);
1960 * Destroy a flow rule on a given port.
1962 * Failure to destroy a flow rule handle may occur when other flow rules
1963 * depend on it, and destroying it would result in an inconsistent state.
1965 * This function is only guaranteed to succeed if handles are destroyed in
1966 * reverse order of their creation.
1969 * Port identifier of Ethernet device.
1971 * Flow rule handle to destroy.
1973 * Perform verbose error reporting if not NULL. PMDs initialize this
1974 * structure in case of error only.
1977 * 0 on success, a negative errno value otherwise and rte_errno is set.
1980 rte_flow_destroy(uint16_t port_id,
1981 struct rte_flow *flow,
1982 struct rte_flow_error *error);
1985 * Destroy all flow rules associated with a port.
1987 * In the unlikely event of failure, handles are still considered destroyed
1988 * and no longer valid but the port must be assumed to be in an inconsistent
1992 * Port identifier of Ethernet device.
1994 * Perform verbose error reporting if not NULL. PMDs initialize this
1995 * structure in case of error only.
1998 * 0 on success, a negative errno value otherwise and rte_errno is set.
2001 rte_flow_flush(uint16_t port_id,
2002 struct rte_flow_error *error);
2005 * Query an existing flow rule.
2007 * This function allows retrieving flow-specific data such as counters.
2008 * Data is gathered by special actions which must be present in the flow
2011 * \see RTE_FLOW_ACTION_TYPE_COUNT
2014 * Port identifier of Ethernet device.
2016 * Flow rule handle to query.
2018 * Action type to query.
2019 * @param[in, out] data
2020 * Pointer to storage for the associated query data type.
2022 * Perform verbose error reporting if not NULL. PMDs initialize this
2023 * structure in case of error only.
2026 * 0 on success, a negative errno value otherwise and rte_errno is set.
2029 rte_flow_query(uint16_t port_id,
2030 struct rte_flow *flow,
2031 enum rte_flow_action_type action,
2033 struct rte_flow_error *error);
2036 * Restrict ingress traffic to the defined flow rules.
2038 * Isolated mode guarantees that all ingress traffic comes from defined flow
2039 * rules only (current and future).
2041 * Besides making ingress more deterministic, it allows PMDs to safely reuse
2042 * resources otherwise assigned to handle the remaining traffic, such as
2043 * global RSS configuration settings, VLAN filters, MAC address entries,
2044 * legacy filter API rules and so on in order to expand the set of possible
2047 * Calling this function as soon as possible after device initialization,
2048 * ideally before the first call to rte_eth_dev_configure(), is recommended
2049 * to avoid possible failures due to conflicting settings.
2051 * Once effective, leaving isolated mode may not be possible depending on
2052 * PMD implementation.
2054 * Additionally, the following functionality has no effect on the underlying
2055 * port and may return errors such as ENOTSUP ("not supported"):
2057 * - Toggling promiscuous mode.
2058 * - Toggling allmulticast mode.
2059 * - Configuring MAC addresses.
2060 * - Configuring multicast addresses.
2061 * - Configuring VLAN filters.
2062 * - Configuring Rx filters through the legacy API (e.g. FDIR).
2063 * - Configuring global RSS settings.
2066 * Port identifier of Ethernet device.
2068 * Nonzero to enter isolated mode, attempt to leave it otherwise.
2070 * Perform verbose error reporting if not NULL. PMDs initialize this
2071 * structure in case of error only.
2074 * 0 on success, a negative errno value otherwise and rte_errno is set.
2077 rte_flow_isolate(uint16_t port_id, int set, struct rte_flow_error *error);
2080 * Initialize flow error structure.
2083 * Pointer to flow error structure (may be NULL).
2085 * Related error code (rte_errno).
2087 * Cause field and error types.
2089 * Object responsible for the error.
2091 * Human-readable error message.
2094 * Negative error code (errno value) and rte_errno is set.
2097 rte_flow_error_set(struct rte_flow_error *error,
2099 enum rte_flow_error_type type,
2101 const char *message);
2104 * Generic flow representation.
2106 * This form is sufficient to describe an rte_flow independently from any
2107 * PMD implementation and allows for replayability and identification.
2109 struct rte_flow_desc {
2110 size_t size; /**< Allocated space including data[]. */
2111 struct rte_flow_attr attr; /**< Attributes. */
2112 struct rte_flow_item *items; /**< Items. */
2113 struct rte_flow_action *actions; /**< Actions. */
2114 uint8_t data[]; /**< Storage for items/actions. */
2118 * Copy an rte_flow rule description.
2121 * Flow rule description.
2123 * Total size of allocated data for the flow description.
2125 * Flow rule attributes.
2127 * Pattern specification (list terminated by the END pattern item).
2128 * @param[in] actions
2129 * Associated actions (list terminated by the END action).
2132 * If len is greater or equal to the size of the flow, the total size of the
2133 * flow description and its data.
2134 * If len is lower than the size of the flow, the number of bytes that would
2135 * have been written to desc had it been sufficient. Nothing is written.
2138 rte_flow_copy(struct rte_flow_desc *fd, size_t len,
2139 const struct rte_flow_attr *attr,
2140 const struct rte_flow_item *items,
2141 const struct rte_flow_action *actions);
2147 #endif /* RTE_FLOW_H_ */