1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright 2016 6WIND S.A. 3 * Copyright 2016 Mellanox Technologies, Ltd 4 */ 5 6 #ifndef RTE_FLOW_H_ 7 #define RTE_FLOW_H_ 8 9 /** 10 * @file 11 * RTE generic flow API 12 * 13 * This interface provides the ability to program packet matching and 14 * associated actions in hardware through flow rules. 15 */ 16 17 #include <stddef.h> 18 #include <stdint.h> 19 20 #include <rte_arp.h> 21 #include <rte_common.h> 22 #include <rte_ether.h> 23 #include <rte_icmp.h> 24 #include <rte_ip.h> 25 #include <rte_sctp.h> 26 #include <rte_tcp.h> 27 #include <rte_udp.h> 28 #include <rte_byteorder.h> 29 #include <rte_esp.h> 30 #include <rte_higig.h> 31 #include <rte_mbuf.h> 32 #include <rte_mbuf_dyn.h> 33 34 #ifdef __cplusplus 35 extern "C" { 36 #endif 37 38 /** 39 * Flow rule attributes. 40 * 41 * Priorities are set on a per rule based within groups. 42 * 43 * Lower values denote higher priority, the highest priority for a flow rule 44 * is 0, so that a flow that matches for than one rule, the rule with the 45 * lowest priority value will always be matched. 46 * 47 * Although optional, applications are encouraged to group similar rules as 48 * much as possible to fully take advantage of hardware capabilities 49 * (e.g. optimized matching) and work around limitations (e.g. a single 50 * pattern type possibly allowed in a given group). Applications should be 51 * aware that groups are not linked by default, and that they must be 52 * explicitly linked by the application using the JUMP action. 53 * 54 * Priority levels are arbitrary and up to the application, they 55 * do not need to be contiguous nor start from 0, however the maximum number 56 * varies between devices and may be affected by existing flow rules. 57 * 58 * If a packet is matched by several rules of a given group for a given 59 * priority level, the outcome is undefined. It can take any path, may be 60 * duplicated or even cause unrecoverable errors. 61 * 62 * Note that support for more than a single group and priority level is not 63 * guaranteed. 64 * 65 * Flow rules can apply to inbound and/or outbound traffic (ingress/egress). 66 * 67 * Several pattern items and actions are valid and can be used in both 68 * directions. Those valid for only one direction are described as such. 69 * 70 * At least one direction must be specified. 71 * 72 * Specifying both directions at once for a given rule is not recommended 73 * but may be valid in a few cases (e.g. shared counter). 74 */ 75 struct rte_flow_attr { 76 uint32_t group; /**< Priority group. */ 77 uint32_t priority; /**< Rule priority level within group. */ 78 uint32_t ingress:1; /**< Rule applies to ingress traffic. */ 79 uint32_t egress:1; /**< Rule applies to egress traffic. */ 80 /** 81 * Instead of simply matching the properties of traffic as it would 82 * appear on a given DPDK port ID, enabling this attribute transfers 83 * a flow rule to the lowest possible level of any device endpoints 84 * found in the pattern. 85 * 86 * When supported, this effectively enables an application to 87 * re-route traffic not necessarily intended for it (e.g. coming 88 * from or addressed to different physical ports, VFs or 89 * applications) at the device level. 90 * 91 * It complements the behavior of some pattern items such as 92 * RTE_FLOW_ITEM_TYPE_PHY_PORT and is meaningless without them. 93 * 94 * When transferring flow rules, ingress and egress attributes keep 95 * their original meaning, as if processing traffic emitted or 96 * received by the application. 97 */ 98 uint32_t transfer:1; 99 uint32_t reserved:29; /**< Reserved, must be zero. */ 100 }; 101 102 /** 103 * Matching pattern item types. 104 * 105 * Pattern items fall in two categories: 106 * 107 * - Matching protocol headers and packet data, usually associated with a 108 * specification structure. These must be stacked in the same order as the 109 * protocol layers to match inside packets, starting from the lowest. 110 * 111 * - Matching meta-data or affecting pattern processing, often without a 112 * specification structure. Since they do not match packet contents, their 113 * position in the list is usually not relevant. 114 * 115 * See the description of individual types for more information. Those 116 * marked with [META] fall into the second category. 117 */ 118 enum rte_flow_item_type { 119 /** 120 * [META] 121 * 122 * End marker for item lists. Prevents further processing of items, 123 * thereby ending the pattern. 124 * 125 * No associated specification structure. 126 */ 127 RTE_FLOW_ITEM_TYPE_END, 128 129 /** 130 * [META] 131 * 132 * Used as a placeholder for convenience. It is ignored and simply 133 * discarded by PMDs. 134 * 135 * No associated specification structure. 136 */ 137 RTE_FLOW_ITEM_TYPE_VOID, 138 139 /** 140 * [META] 141 * 142 * Inverted matching, i.e. process packets that do not match the 143 * pattern. 144 * 145 * No associated specification structure. 146 */ 147 RTE_FLOW_ITEM_TYPE_INVERT, 148 149 /** 150 * Matches any protocol in place of the current layer, a single ANY 151 * may also stand for several protocol layers. 152 * 153 * See struct rte_flow_item_any. 154 */ 155 RTE_FLOW_ITEM_TYPE_ANY, 156 157 /** 158 * [META] 159 * 160 * Matches traffic originating from (ingress) or going to (egress) 161 * the physical function of the current device. 162 * 163 * No associated specification structure. 164 */ 165 RTE_FLOW_ITEM_TYPE_PF, 166 167 /** 168 * [META] 169 * 170 * Matches traffic originating from (ingress) or going to (egress) a 171 * given virtual function of the current device. 172 * 173 * See struct rte_flow_item_vf. 174 */ 175 RTE_FLOW_ITEM_TYPE_VF, 176 177 /** 178 * [META] 179 * 180 * Matches traffic originating from (ingress) or going to (egress) a 181 * physical port of the underlying device. 182 * 183 * See struct rte_flow_item_phy_port. 184 */ 185 RTE_FLOW_ITEM_TYPE_PHY_PORT, 186 187 /** 188 * [META] 189 * 190 * Matches traffic originating from (ingress) or going to (egress) a 191 * given DPDK port ID. 192 * 193 * See struct rte_flow_item_port_id. 194 */ 195 RTE_FLOW_ITEM_TYPE_PORT_ID, 196 197 /** 198 * Matches a byte string of a given length at a given offset. 199 * 200 * See struct rte_flow_item_raw. 201 */ 202 RTE_FLOW_ITEM_TYPE_RAW, 203 204 /** 205 * Matches an Ethernet header. 206 * 207 * See struct rte_flow_item_eth. 208 */ 209 RTE_FLOW_ITEM_TYPE_ETH, 210 211 /** 212 * Matches an 802.1Q/ad VLAN tag. 213 * 214 * See struct rte_flow_item_vlan. 215 */ 216 RTE_FLOW_ITEM_TYPE_VLAN, 217 218 /** 219 * Matches an IPv4 header. 220 * 221 * See struct rte_flow_item_ipv4. 222 */ 223 RTE_FLOW_ITEM_TYPE_IPV4, 224 225 /** 226 * Matches an IPv6 header. 227 * 228 * See struct rte_flow_item_ipv6. 229 */ 230 RTE_FLOW_ITEM_TYPE_IPV6, 231 232 /** 233 * Matches an ICMP header. 234 * 235 * See struct rte_flow_item_icmp. 236 */ 237 RTE_FLOW_ITEM_TYPE_ICMP, 238 239 /** 240 * Matches a UDP header. 241 * 242 * See struct rte_flow_item_udp. 243 */ 244 RTE_FLOW_ITEM_TYPE_UDP, 245 246 /** 247 * Matches a TCP header. 248 * 249 * See struct rte_flow_item_tcp. 250 */ 251 RTE_FLOW_ITEM_TYPE_TCP, 252 253 /** 254 * Matches a SCTP header. 255 * 256 * See struct rte_flow_item_sctp. 257 */ 258 RTE_FLOW_ITEM_TYPE_SCTP, 259 260 /** 261 * Matches a VXLAN header. 262 * 263 * See struct rte_flow_item_vxlan. 264 */ 265 RTE_FLOW_ITEM_TYPE_VXLAN, 266 267 /** 268 * Matches a E_TAG header. 269 * 270 * See struct rte_flow_item_e_tag. 271 */ 272 RTE_FLOW_ITEM_TYPE_E_TAG, 273 274 /** 275 * Matches a NVGRE header. 276 * 277 * See struct rte_flow_item_nvgre. 278 */ 279 RTE_FLOW_ITEM_TYPE_NVGRE, 280 281 /** 282 * Matches a MPLS header. 283 * 284 * See struct rte_flow_item_mpls. 285 */ 286 RTE_FLOW_ITEM_TYPE_MPLS, 287 288 /** 289 * Matches a GRE header. 290 * 291 * See struct rte_flow_item_gre. 292 */ 293 RTE_FLOW_ITEM_TYPE_GRE, 294 295 /** 296 * [META] 297 * 298 * Fuzzy pattern match, expect faster than default. 299 * 300 * This is for device that support fuzzy matching option. 301 * Usually a fuzzy matching is fast but the cost is accuracy. 302 * 303 * See struct rte_flow_item_fuzzy. 304 */ 305 RTE_FLOW_ITEM_TYPE_FUZZY, 306 307 /** 308 * Matches a GTP header. 309 * 310 * Configure flow for GTP packets. 311 * 312 * See struct rte_flow_item_gtp. 313 */ 314 RTE_FLOW_ITEM_TYPE_GTP, 315 316 /** 317 * Matches a GTP header. 318 * 319 * Configure flow for GTP-C packets. 320 * 321 * See struct rte_flow_item_gtp. 322 */ 323 RTE_FLOW_ITEM_TYPE_GTPC, 324 325 /** 326 * Matches a GTP header. 327 * 328 * Configure flow for GTP-U packets. 329 * 330 * See struct rte_flow_item_gtp. 331 */ 332 RTE_FLOW_ITEM_TYPE_GTPU, 333 334 /** 335 * Matches a ESP header. 336 * 337 * See struct rte_flow_item_esp. 338 */ 339 RTE_FLOW_ITEM_TYPE_ESP, 340 341 /** 342 * Matches a GENEVE header. 343 * 344 * See struct rte_flow_item_geneve. 345 */ 346 RTE_FLOW_ITEM_TYPE_GENEVE, 347 348 /** 349 * Matches a VXLAN-GPE header. 350 * 351 * See struct rte_flow_item_vxlan_gpe. 352 */ 353 RTE_FLOW_ITEM_TYPE_VXLAN_GPE, 354 355 /** 356 * Matches an ARP header for Ethernet/IPv4. 357 * 358 * See struct rte_flow_item_arp_eth_ipv4. 359 */ 360 RTE_FLOW_ITEM_TYPE_ARP_ETH_IPV4, 361 362 /** 363 * Matches the presence of any IPv6 extension header. 364 * 365 * See struct rte_flow_item_ipv6_ext. 366 */ 367 RTE_FLOW_ITEM_TYPE_IPV6_EXT, 368 369 /** 370 * Matches any ICMPv6 header. 371 * 372 * See struct rte_flow_item_icmp6. 373 */ 374 RTE_FLOW_ITEM_TYPE_ICMP6, 375 376 /** 377 * Matches an ICMPv6 neighbor discovery solicitation. 378 * 379 * See struct rte_flow_item_icmp6_nd_ns. 380 */ 381 RTE_FLOW_ITEM_TYPE_ICMP6_ND_NS, 382 383 /** 384 * Matches an ICMPv6 neighbor discovery advertisement. 385 * 386 * See struct rte_flow_item_icmp6_nd_na. 387 */ 388 RTE_FLOW_ITEM_TYPE_ICMP6_ND_NA, 389 390 /** 391 * Matches the presence of any ICMPv6 neighbor discovery option. 392 * 393 * See struct rte_flow_item_icmp6_nd_opt. 394 */ 395 RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT, 396 397 /** 398 * Matches an ICMPv6 neighbor discovery source Ethernet link-layer 399 * address option. 400 * 401 * See struct rte_flow_item_icmp6_nd_opt_sla_eth. 402 */ 403 RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT_SLA_ETH, 404 405 /** 406 * Matches an ICMPv6 neighbor discovery target Ethernet link-layer 407 * address option. 408 * 409 * See struct rte_flow_item_icmp6_nd_opt_tla_eth. 410 */ 411 RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT_TLA_ETH, 412 413 /** 414 * Matches specified mark field. 415 * 416 * See struct rte_flow_item_mark. 417 */ 418 RTE_FLOW_ITEM_TYPE_MARK, 419 420 /** 421 * [META] 422 * 423 * Matches a metadata value. 424 * 425 * See struct rte_flow_item_meta. 426 */ 427 RTE_FLOW_ITEM_TYPE_META, 428 429 /** 430 * Matches a GRE optional key field. 431 * 432 * The value should a big-endian 32bit integer. 433 * 434 * When this item present the K bit is implicitly matched as "1" 435 * in the default mask. 436 * 437 * @p spec/mask type: 438 * @code rte_be32_t * @endcode 439 */ 440 RTE_FLOW_ITEM_TYPE_GRE_KEY, 441 442 /** 443 * Matches a GTP extension header: PDU session container. 444 * 445 * Configure flow for GTP packets with extension header type 0x85. 446 * 447 * See struct rte_flow_item_gtp_psc. 448 */ 449 RTE_FLOW_ITEM_TYPE_GTP_PSC, 450 451 /** 452 * Matches a PPPoE header. 453 * 454 * Configure flow for PPPoE session packets. 455 * 456 * See struct rte_flow_item_pppoe. 457 */ 458 RTE_FLOW_ITEM_TYPE_PPPOES, 459 460 /** 461 * Matches a PPPoE header. 462 * 463 * Configure flow for PPPoE discovery packets. 464 * 465 * See struct rte_flow_item_pppoe. 466 */ 467 RTE_FLOW_ITEM_TYPE_PPPOED, 468 469 /** 470 * Matches a PPPoE optional proto_id field. 471 * 472 * It only applies to PPPoE session packets. 473 * 474 * See struct rte_flow_item_pppoe_proto_id. 475 */ 476 RTE_FLOW_ITEM_TYPE_PPPOE_PROTO_ID, 477 478 /** 479 * Matches Network service header (NSH). 480 * See struct rte_flow_item_nsh. 481 * 482 */ 483 RTE_FLOW_ITEM_TYPE_NSH, 484 485 /** 486 * Matches Internet Group Management Protocol (IGMP). 487 * See struct rte_flow_item_igmp. 488 * 489 */ 490 RTE_FLOW_ITEM_TYPE_IGMP, 491 492 /** 493 * Matches IP Authentication Header (AH). 494 * See struct rte_flow_item_ah. 495 * 496 */ 497 RTE_FLOW_ITEM_TYPE_AH, 498 499 /** 500 * Matches a HIGIG header. 501 * see struct rte_flow_item_higig2_hdr. 502 */ 503 RTE_FLOW_ITEM_TYPE_HIGIG2, 504 505 /** 506 * [META] 507 * 508 * Matches a tag value. 509 * 510 * See struct rte_flow_item_tag. 511 */ 512 RTE_FLOW_ITEM_TYPE_TAG, 513 }; 514 515 /** 516 * 517 * RTE_FLOW_ITEM_TYPE_HIGIG2 518 * Matches higig2 header 519 */ 520 RTE_STD_C11 521 struct rte_flow_item_higig2_hdr { 522 struct rte_higig2_hdr hdr; 523 }; 524 525 /** Default mask for RTE_FLOW_ITEM_TYPE_HIGIG2. */ 526 #ifndef __cplusplus 527 static const struct rte_flow_item_higig2_hdr rte_flow_item_higig2_hdr_mask = { 528 .hdr = { 529 .ppt1 = { 530 .classification = 0xffff, 531 .vid = 0xfff, 532 }, 533 }, 534 }; 535 #endif 536 537 /** 538 * RTE_FLOW_ITEM_TYPE_ANY 539 * 540 * Matches any protocol in place of the current layer, a single ANY may also 541 * stand for several protocol layers. 542 * 543 * This is usually specified as the first pattern item when looking for a 544 * protocol anywhere in a packet. 545 * 546 * A zeroed mask stands for any number of layers. 547 */ 548 struct rte_flow_item_any { 549 uint32_t num; /**< Number of layers covered. */ 550 }; 551 552 /** Default mask for RTE_FLOW_ITEM_TYPE_ANY. */ 553 #ifndef __cplusplus 554 static const struct rte_flow_item_any rte_flow_item_any_mask = { 555 .num = 0x00000000, 556 }; 557 #endif 558 559 /** 560 * RTE_FLOW_ITEM_TYPE_VF 561 * 562 * Matches traffic originating from (ingress) or going to (egress) a given 563 * virtual function of the current device. 564 * 565 * If supported, should work even if the virtual function is not managed by 566 * the application and thus not associated with a DPDK port ID. 567 * 568 * Note this pattern item does not match VF representors traffic which, as 569 * separate entities, should be addressed through their own DPDK port IDs. 570 * 571 * - Can be specified multiple times to match traffic addressed to several 572 * VF IDs. 573 * - Can be combined with a PF item to match both PF and VF traffic. 574 * 575 * A zeroed mask can be used to match any VF ID. 576 */ 577 struct rte_flow_item_vf { 578 uint32_t id; /**< VF ID. */ 579 }; 580 581 /** Default mask for RTE_FLOW_ITEM_TYPE_VF. */ 582 #ifndef __cplusplus 583 static const struct rte_flow_item_vf rte_flow_item_vf_mask = { 584 .id = 0x00000000, 585 }; 586 #endif 587 588 /** 589 * RTE_FLOW_ITEM_TYPE_PHY_PORT 590 * 591 * Matches traffic originating from (ingress) or going to (egress) a 592 * physical port of the underlying device. 593 * 594 * The first PHY_PORT item overrides the physical port normally associated 595 * with the specified DPDK input port (port_id). This item can be provided 596 * several times to match additional physical ports. 597 * 598 * Note that physical ports are not necessarily tied to DPDK input ports 599 * (port_id) when those are not under DPDK control. Possible values are 600 * specific to each device, they are not necessarily indexed from zero and 601 * may not be contiguous. 602 * 603 * As a device property, the list of allowed values as well as the value 604 * associated with a port_id should be retrieved by other means. 605 * 606 * A zeroed mask can be used to match any port index. 607 */ 608 struct rte_flow_item_phy_port { 609 uint32_t index; /**< Physical port index. */ 610 }; 611 612 /** Default mask for RTE_FLOW_ITEM_TYPE_PHY_PORT. */ 613 #ifndef __cplusplus 614 static const struct rte_flow_item_phy_port rte_flow_item_phy_port_mask = { 615 .index = 0x00000000, 616 }; 617 #endif 618 619 /** 620 * RTE_FLOW_ITEM_TYPE_PORT_ID 621 * 622 * Matches traffic originating from (ingress) or going to (egress) a given 623 * DPDK port ID. 624 * 625 * Normally only supported if the port ID in question is known by the 626 * underlying PMD and related to the device the flow rule is created 627 * against. 628 * 629 * This must not be confused with @p PHY_PORT which refers to the physical 630 * port of a device, whereas @p PORT_ID refers to a struct rte_eth_dev 631 * object on the application side (also known as "port representor" 632 * depending on the kind of underlying device). 633 */ 634 struct rte_flow_item_port_id { 635 uint32_t id; /**< DPDK port ID. */ 636 }; 637 638 /** Default mask for RTE_FLOW_ITEM_TYPE_PORT_ID. */ 639 #ifndef __cplusplus 640 static const struct rte_flow_item_port_id rte_flow_item_port_id_mask = { 641 .id = 0xffffffff, 642 }; 643 #endif 644 645 /** 646 * RTE_FLOW_ITEM_TYPE_RAW 647 * 648 * Matches a byte string of a given length at a given offset. 649 * 650 * Offset is either absolute (using the start of the packet) or relative to 651 * the end of the previous matched item in the stack, in which case negative 652 * values are allowed. 653 * 654 * If search is enabled, offset is used as the starting point. The search 655 * area can be delimited by setting limit to a nonzero value, which is the 656 * maximum number of bytes after offset where the pattern may start. 657 * 658 * Matching a zero-length pattern is allowed, doing so resets the relative 659 * offset for subsequent items. 660 * 661 * This type does not support ranges (struct rte_flow_item.last). 662 */ 663 struct rte_flow_item_raw { 664 uint32_t relative:1; /**< Look for pattern after the previous item. */ 665 uint32_t search:1; /**< Search pattern from offset (see also limit). */ 666 uint32_t reserved:30; /**< Reserved, must be set to zero. */ 667 int32_t offset; /**< Absolute or relative offset for pattern. */ 668 uint16_t limit; /**< Search area limit for start of pattern. */ 669 uint16_t length; /**< Pattern length. */ 670 const uint8_t *pattern; /**< Byte string to look for. */ 671 }; 672 673 /** Default mask for RTE_FLOW_ITEM_TYPE_RAW. */ 674 #ifndef __cplusplus 675 static const struct rte_flow_item_raw rte_flow_item_raw_mask = { 676 .relative = 1, 677 .search = 1, 678 .reserved = 0x3fffffff, 679 .offset = 0xffffffff, 680 .limit = 0xffff, 681 .length = 0xffff, 682 .pattern = NULL, 683 }; 684 #endif 685 686 /** 687 * RTE_FLOW_ITEM_TYPE_ETH 688 * 689 * Matches an Ethernet header. 690 * 691 * The @p type field either stands for "EtherType" or "TPID" when followed 692 * by so-called layer 2.5 pattern items such as RTE_FLOW_ITEM_TYPE_VLAN. In 693 * the latter case, @p type refers to that of the outer header, with the 694 * inner EtherType/TPID provided by the subsequent pattern item. This is the 695 * same order as on the wire. 696 */ 697 struct rte_flow_item_eth { 698 struct rte_ether_addr dst; /**< Destination MAC. */ 699 struct rte_ether_addr src; /**< Source MAC. */ 700 rte_be16_t type; /**< EtherType or TPID. */ 701 }; 702 703 /** Default mask for RTE_FLOW_ITEM_TYPE_ETH. */ 704 #ifndef __cplusplus 705 static const struct rte_flow_item_eth rte_flow_item_eth_mask = { 706 .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff", 707 .src.addr_bytes = "\xff\xff\xff\xff\xff\xff", 708 .type = RTE_BE16(0x0000), 709 }; 710 #endif 711 712 /** 713 * RTE_FLOW_ITEM_TYPE_VLAN 714 * 715 * Matches an 802.1Q/ad VLAN tag. 716 * 717 * The corresponding standard outer EtherType (TPID) values are 718 * RTE_ETHER_TYPE_VLAN or RTE_ETHER_TYPE_QINQ. It can be overridden by 719 * the preceding pattern item. 720 */ 721 struct rte_flow_item_vlan { 722 rte_be16_t tci; /**< Tag control information. */ 723 rte_be16_t inner_type; /**< Inner EtherType or TPID. */ 724 }; 725 726 /** Default mask for RTE_FLOW_ITEM_TYPE_VLAN. */ 727 #ifndef __cplusplus 728 static const struct rte_flow_item_vlan rte_flow_item_vlan_mask = { 729 .tci = RTE_BE16(0x0fff), 730 .inner_type = RTE_BE16(0x0000), 731 }; 732 #endif 733 734 /** 735 * RTE_FLOW_ITEM_TYPE_IPV4 736 * 737 * Matches an IPv4 header. 738 * 739 * Note: IPv4 options are handled by dedicated pattern items. 740 */ 741 struct rte_flow_item_ipv4 { 742 struct rte_ipv4_hdr hdr; /**< IPv4 header definition. */ 743 }; 744 745 /** Default mask for RTE_FLOW_ITEM_TYPE_IPV4. */ 746 #ifndef __cplusplus 747 static const struct rte_flow_item_ipv4 rte_flow_item_ipv4_mask = { 748 .hdr = { 749 .src_addr = RTE_BE32(0xffffffff), 750 .dst_addr = RTE_BE32(0xffffffff), 751 }, 752 }; 753 #endif 754 755 /** 756 * RTE_FLOW_ITEM_TYPE_IPV6. 757 * 758 * Matches an IPv6 header. 759 * 760 * Note: IPv6 options are handled by dedicated pattern items, see 761 * RTE_FLOW_ITEM_TYPE_IPV6_EXT. 762 */ 763 struct rte_flow_item_ipv6 { 764 struct rte_ipv6_hdr hdr; /**< IPv6 header definition. */ 765 }; 766 767 /** Default mask for RTE_FLOW_ITEM_TYPE_IPV6. */ 768 #ifndef __cplusplus 769 static const struct rte_flow_item_ipv6 rte_flow_item_ipv6_mask = { 770 .hdr = { 771 .src_addr = 772 "\xff\xff\xff\xff\xff\xff\xff\xff" 773 "\xff\xff\xff\xff\xff\xff\xff\xff", 774 .dst_addr = 775 "\xff\xff\xff\xff\xff\xff\xff\xff" 776 "\xff\xff\xff\xff\xff\xff\xff\xff", 777 }, 778 }; 779 #endif 780 781 /** 782 * RTE_FLOW_ITEM_TYPE_ICMP. 783 * 784 * Matches an ICMP header. 785 */ 786 struct rte_flow_item_icmp { 787 struct rte_icmp_hdr hdr; /**< ICMP header definition. */ 788 }; 789 790 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP. */ 791 #ifndef __cplusplus 792 static const struct rte_flow_item_icmp rte_flow_item_icmp_mask = { 793 .hdr = { 794 .icmp_type = 0xff, 795 .icmp_code = 0xff, 796 }, 797 }; 798 #endif 799 800 /** 801 * RTE_FLOW_ITEM_TYPE_UDP. 802 * 803 * Matches a UDP header. 804 */ 805 struct rte_flow_item_udp { 806 struct rte_udp_hdr hdr; /**< UDP header definition. */ 807 }; 808 809 /** Default mask for RTE_FLOW_ITEM_TYPE_UDP. */ 810 #ifndef __cplusplus 811 static const struct rte_flow_item_udp rte_flow_item_udp_mask = { 812 .hdr = { 813 .src_port = RTE_BE16(0xffff), 814 .dst_port = RTE_BE16(0xffff), 815 }, 816 }; 817 #endif 818 819 /** 820 * RTE_FLOW_ITEM_TYPE_TCP. 821 * 822 * Matches a TCP header. 823 */ 824 struct rte_flow_item_tcp { 825 struct rte_tcp_hdr hdr; /**< TCP header definition. */ 826 }; 827 828 /** Default mask for RTE_FLOW_ITEM_TYPE_TCP. */ 829 #ifndef __cplusplus 830 static const struct rte_flow_item_tcp rte_flow_item_tcp_mask = { 831 .hdr = { 832 .src_port = RTE_BE16(0xffff), 833 .dst_port = RTE_BE16(0xffff), 834 }, 835 }; 836 #endif 837 838 /** 839 * RTE_FLOW_ITEM_TYPE_SCTP. 840 * 841 * Matches a SCTP header. 842 */ 843 struct rte_flow_item_sctp { 844 struct rte_sctp_hdr hdr; /**< SCTP header definition. */ 845 }; 846 847 /** Default mask for RTE_FLOW_ITEM_TYPE_SCTP. */ 848 #ifndef __cplusplus 849 static const struct rte_flow_item_sctp rte_flow_item_sctp_mask = { 850 .hdr = { 851 .src_port = RTE_BE16(0xffff), 852 .dst_port = RTE_BE16(0xffff), 853 }, 854 }; 855 #endif 856 857 /** 858 * RTE_FLOW_ITEM_TYPE_VXLAN. 859 * 860 * Matches a VXLAN header (RFC 7348). 861 */ 862 struct rte_flow_item_vxlan { 863 uint8_t flags; /**< Normally 0x08 (I flag). */ 864 uint8_t rsvd0[3]; /**< Reserved, normally 0x000000. */ 865 uint8_t vni[3]; /**< VXLAN identifier. */ 866 uint8_t rsvd1; /**< Reserved, normally 0x00. */ 867 }; 868 869 /** Default mask for RTE_FLOW_ITEM_TYPE_VXLAN. */ 870 #ifndef __cplusplus 871 static const struct rte_flow_item_vxlan rte_flow_item_vxlan_mask = { 872 .vni = "\xff\xff\xff", 873 }; 874 #endif 875 876 /** 877 * RTE_FLOW_ITEM_TYPE_E_TAG. 878 * 879 * Matches a E-tag header. 880 * 881 * The corresponding standard outer EtherType (TPID) value is 882 * RTE_ETHER_TYPE_ETAG. It can be overridden by the preceding pattern item. 883 */ 884 struct rte_flow_item_e_tag { 885 /** 886 * E-Tag control information (E-TCI). 887 * E-PCP (3b), E-DEI (1b), ingress E-CID base (12b). 888 */ 889 rte_be16_t epcp_edei_in_ecid_b; 890 /** Reserved (2b), GRP (2b), E-CID base (12b). */ 891 rte_be16_t rsvd_grp_ecid_b; 892 uint8_t in_ecid_e; /**< Ingress E-CID ext. */ 893 uint8_t ecid_e; /**< E-CID ext. */ 894 rte_be16_t inner_type; /**< Inner EtherType or TPID. */ 895 }; 896 897 /** Default mask for RTE_FLOW_ITEM_TYPE_E_TAG. */ 898 #ifndef __cplusplus 899 static const struct rte_flow_item_e_tag rte_flow_item_e_tag_mask = { 900 .rsvd_grp_ecid_b = RTE_BE16(0x3fff), 901 }; 902 #endif 903 904 /** 905 * RTE_FLOW_ITEM_TYPE_NVGRE. 906 * 907 * Matches a NVGRE header. 908 */ 909 struct rte_flow_item_nvgre { 910 /** 911 * Checksum (1b), undefined (1b), key bit (1b), sequence number (1b), 912 * reserved 0 (9b), version (3b). 913 * 914 * c_k_s_rsvd0_ver must have value 0x2000 according to RFC 7637. 915 */ 916 rte_be16_t c_k_s_rsvd0_ver; 917 rte_be16_t protocol; /**< Protocol type (0x6558). */ 918 uint8_t tni[3]; /**< Virtual subnet ID. */ 919 uint8_t flow_id; /**< Flow ID. */ 920 }; 921 922 /** Default mask for RTE_FLOW_ITEM_TYPE_NVGRE. */ 923 #ifndef __cplusplus 924 static const struct rte_flow_item_nvgre rte_flow_item_nvgre_mask = { 925 .tni = "\xff\xff\xff", 926 }; 927 #endif 928 929 /** 930 * RTE_FLOW_ITEM_TYPE_MPLS. 931 * 932 * Matches a MPLS header. 933 */ 934 struct rte_flow_item_mpls { 935 /** 936 * Label (20b), TC (3b), Bottom of Stack (1b). 937 */ 938 uint8_t label_tc_s[3]; 939 uint8_t ttl; /** Time-to-Live. */ 940 }; 941 942 /** Default mask for RTE_FLOW_ITEM_TYPE_MPLS. */ 943 #ifndef __cplusplus 944 static const struct rte_flow_item_mpls rte_flow_item_mpls_mask = { 945 .label_tc_s = "\xff\xff\xf0", 946 }; 947 #endif 948 949 /** 950 * RTE_FLOW_ITEM_TYPE_GRE. 951 * 952 * Matches a GRE header. 953 */ 954 struct rte_flow_item_gre { 955 /** 956 * Checksum (1b), reserved 0 (12b), version (3b). 957 * Refer to RFC 2784. 958 */ 959 rte_be16_t c_rsvd0_ver; 960 rte_be16_t protocol; /**< Protocol type. */ 961 }; 962 963 /** Default mask for RTE_FLOW_ITEM_TYPE_GRE. */ 964 #ifndef __cplusplus 965 static const struct rte_flow_item_gre rte_flow_item_gre_mask = { 966 .protocol = RTE_BE16(0xffff), 967 }; 968 #endif 969 970 /** 971 * RTE_FLOW_ITEM_TYPE_FUZZY 972 * 973 * Fuzzy pattern match, expect faster than default. 974 * 975 * This is for device that support fuzzy match option. 976 * Usually a fuzzy match is fast but the cost is accuracy. 977 * i.e. Signature Match only match pattern's hash value, but it is 978 * possible two different patterns have the same hash value. 979 * 980 * Matching accuracy level can be configure by threshold. 981 * Driver can divide the range of threshold and map to different 982 * accuracy levels that device support. 983 * 984 * Threshold 0 means perfect match (no fuzziness), while threshold 985 * 0xffffffff means fuzziest match. 986 */ 987 struct rte_flow_item_fuzzy { 988 uint32_t thresh; /**< Accuracy threshold. */ 989 }; 990 991 /** Default mask for RTE_FLOW_ITEM_TYPE_FUZZY. */ 992 #ifndef __cplusplus 993 static const struct rte_flow_item_fuzzy rte_flow_item_fuzzy_mask = { 994 .thresh = 0xffffffff, 995 }; 996 #endif 997 998 /** 999 * RTE_FLOW_ITEM_TYPE_GTP. 1000 * 1001 * Matches a GTPv1 header. 1002 */ 1003 struct rte_flow_item_gtp { 1004 /** 1005 * Version (3b), protocol type (1b), reserved (1b), 1006 * Extension header flag (1b), 1007 * Sequence number flag (1b), 1008 * N-PDU number flag (1b). 1009 */ 1010 uint8_t v_pt_rsv_flags; 1011 uint8_t msg_type; /**< Message type. */ 1012 rte_be16_t msg_len; /**< Message length. */ 1013 rte_be32_t teid; /**< Tunnel endpoint identifier. */ 1014 }; 1015 1016 /** Default mask for RTE_FLOW_ITEM_TYPE_GTP. */ 1017 #ifndef __cplusplus 1018 static const struct rte_flow_item_gtp rte_flow_item_gtp_mask = { 1019 .teid = RTE_BE32(0xffffffff), 1020 }; 1021 #endif 1022 1023 /** 1024 * RTE_FLOW_ITEM_TYPE_ESP 1025 * 1026 * Matches an ESP header. 1027 */ 1028 struct rte_flow_item_esp { 1029 struct rte_esp_hdr hdr; /**< ESP header definition. */ 1030 }; 1031 1032 /** Default mask for RTE_FLOW_ITEM_TYPE_ESP. */ 1033 #ifndef __cplusplus 1034 static const struct rte_flow_item_esp rte_flow_item_esp_mask = { 1035 .hdr = { 1036 .spi = RTE_BE32(0xffffffff), 1037 }, 1038 }; 1039 #endif 1040 1041 /** 1042 * RTE_FLOW_ITEM_TYPE_GENEVE. 1043 * 1044 * Matches a GENEVE header. 1045 */ 1046 struct rte_flow_item_geneve { 1047 /** 1048 * Version (2b), length of the options fields (6b), OAM packet (1b), 1049 * critical options present (1b), reserved 0 (6b). 1050 */ 1051 rte_be16_t ver_opt_len_o_c_rsvd0; 1052 rte_be16_t protocol; /**< Protocol type. */ 1053 uint8_t vni[3]; /**< Virtual Network Identifier. */ 1054 uint8_t rsvd1; /**< Reserved, normally 0x00. */ 1055 }; 1056 1057 /** Default mask for RTE_FLOW_ITEM_TYPE_GENEVE. */ 1058 #ifndef __cplusplus 1059 static const struct rte_flow_item_geneve rte_flow_item_geneve_mask = { 1060 .vni = "\xff\xff\xff", 1061 }; 1062 #endif 1063 1064 /** 1065 * RTE_FLOW_ITEM_TYPE_VXLAN_GPE (draft-ietf-nvo3-vxlan-gpe-05). 1066 * 1067 * Matches a VXLAN-GPE header. 1068 */ 1069 struct rte_flow_item_vxlan_gpe { 1070 uint8_t flags; /**< Normally 0x0c (I and P flags). */ 1071 uint8_t rsvd0[2]; /**< Reserved, normally 0x0000. */ 1072 uint8_t protocol; /**< Protocol type. */ 1073 uint8_t vni[3]; /**< VXLAN identifier. */ 1074 uint8_t rsvd1; /**< Reserved, normally 0x00. */ 1075 }; 1076 1077 /** Default mask for RTE_FLOW_ITEM_TYPE_VXLAN_GPE. */ 1078 #ifndef __cplusplus 1079 static const struct rte_flow_item_vxlan_gpe rte_flow_item_vxlan_gpe_mask = { 1080 .vni = "\xff\xff\xff", 1081 }; 1082 #endif 1083 1084 /** 1085 * RTE_FLOW_ITEM_TYPE_ARP_ETH_IPV4 1086 * 1087 * Matches an ARP header for Ethernet/IPv4. 1088 */ 1089 struct rte_flow_item_arp_eth_ipv4 { 1090 rte_be16_t hrd; /**< Hardware type, normally 1. */ 1091 rte_be16_t pro; /**< Protocol type, normally 0x0800. */ 1092 uint8_t hln; /**< Hardware address length, normally 6. */ 1093 uint8_t pln; /**< Protocol address length, normally 4. */ 1094 rte_be16_t op; /**< Opcode (1 for request, 2 for reply). */ 1095 struct rte_ether_addr sha; /**< Sender hardware address. */ 1096 rte_be32_t spa; /**< Sender IPv4 address. */ 1097 struct rte_ether_addr tha; /**< Target hardware address. */ 1098 rte_be32_t tpa; /**< Target IPv4 address. */ 1099 }; 1100 1101 /** Default mask for RTE_FLOW_ITEM_TYPE_ARP_ETH_IPV4. */ 1102 #ifndef __cplusplus 1103 static const struct rte_flow_item_arp_eth_ipv4 1104 rte_flow_item_arp_eth_ipv4_mask = { 1105 .sha.addr_bytes = "\xff\xff\xff\xff\xff\xff", 1106 .spa = RTE_BE32(0xffffffff), 1107 .tha.addr_bytes = "\xff\xff\xff\xff\xff\xff", 1108 .tpa = RTE_BE32(0xffffffff), 1109 }; 1110 #endif 1111 1112 /** 1113 * RTE_FLOW_ITEM_TYPE_IPV6_EXT 1114 * 1115 * Matches the presence of any IPv6 extension header. 1116 * 1117 * Normally preceded by any of: 1118 * 1119 * - RTE_FLOW_ITEM_TYPE_IPV6 1120 * - RTE_FLOW_ITEM_TYPE_IPV6_EXT 1121 */ 1122 struct rte_flow_item_ipv6_ext { 1123 uint8_t next_hdr; /**< Next header. */ 1124 }; 1125 1126 /** Default mask for RTE_FLOW_ITEM_TYPE_IPV6_EXT. */ 1127 #ifndef __cplusplus 1128 static const 1129 struct rte_flow_item_ipv6_ext rte_flow_item_ipv6_ext_mask = { 1130 .next_hdr = 0xff, 1131 }; 1132 #endif 1133 1134 /** 1135 * RTE_FLOW_ITEM_TYPE_ICMP6 1136 * 1137 * Matches any ICMPv6 header. 1138 */ 1139 struct rte_flow_item_icmp6 { 1140 uint8_t type; /**< ICMPv6 type. */ 1141 uint8_t code; /**< ICMPv6 code. */ 1142 uint16_t checksum; /**< ICMPv6 checksum. */ 1143 }; 1144 1145 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP6. */ 1146 #ifndef __cplusplus 1147 static const struct rte_flow_item_icmp6 rte_flow_item_icmp6_mask = { 1148 .type = 0xff, 1149 .code = 0xff, 1150 }; 1151 #endif 1152 1153 /** 1154 * RTE_FLOW_ITEM_TYPE_ICMP6_ND_NS 1155 * 1156 * Matches an ICMPv6 neighbor discovery solicitation. 1157 */ 1158 struct rte_flow_item_icmp6_nd_ns { 1159 uint8_t type; /**< ICMPv6 type, normally 135. */ 1160 uint8_t code; /**< ICMPv6 code, normally 0. */ 1161 rte_be16_t checksum; /**< ICMPv6 checksum. */ 1162 rte_be32_t reserved; /**< Reserved, normally 0. */ 1163 uint8_t target_addr[16]; /**< Target address. */ 1164 }; 1165 1166 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP6_ND_NS. */ 1167 #ifndef __cplusplus 1168 static const 1169 struct rte_flow_item_icmp6_nd_ns rte_flow_item_icmp6_nd_ns_mask = { 1170 .target_addr = 1171 "\xff\xff\xff\xff\xff\xff\xff\xff" 1172 "\xff\xff\xff\xff\xff\xff\xff\xff", 1173 }; 1174 #endif 1175 1176 /** 1177 * RTE_FLOW_ITEM_TYPE_ICMP6_ND_NA 1178 * 1179 * Matches an ICMPv6 neighbor discovery advertisement. 1180 */ 1181 struct rte_flow_item_icmp6_nd_na { 1182 uint8_t type; /**< ICMPv6 type, normally 136. */ 1183 uint8_t code; /**< ICMPv6 code, normally 0. */ 1184 rte_be16_t checksum; /**< ICMPv6 checksum. */ 1185 /** 1186 * Route flag (1b), solicited flag (1b), override flag (1b), 1187 * reserved (29b). 1188 */ 1189 rte_be32_t rso_reserved; 1190 uint8_t target_addr[16]; /**< Target address. */ 1191 }; 1192 1193 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP6_ND_NA. */ 1194 #ifndef __cplusplus 1195 static const 1196 struct rte_flow_item_icmp6_nd_na rte_flow_item_icmp6_nd_na_mask = { 1197 .target_addr = 1198 "\xff\xff\xff\xff\xff\xff\xff\xff" 1199 "\xff\xff\xff\xff\xff\xff\xff\xff", 1200 }; 1201 #endif 1202 1203 /** 1204 * RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT 1205 * 1206 * Matches the presence of any ICMPv6 neighbor discovery option. 1207 * 1208 * Normally preceded by any of: 1209 * 1210 * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_NA 1211 * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_NS 1212 * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT 1213 */ 1214 struct rte_flow_item_icmp6_nd_opt { 1215 uint8_t type; /**< ND option type. */ 1216 uint8_t length; /**< ND option length. */ 1217 }; 1218 1219 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT. */ 1220 #ifndef __cplusplus 1221 static const struct rte_flow_item_icmp6_nd_opt 1222 rte_flow_item_icmp6_nd_opt_mask = { 1223 .type = 0xff, 1224 }; 1225 #endif 1226 1227 /** 1228 * RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT_SLA_ETH 1229 * 1230 * Matches an ICMPv6 neighbor discovery source Ethernet link-layer address 1231 * option. 1232 * 1233 * Normally preceded by any of: 1234 * 1235 * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_NA 1236 * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT 1237 */ 1238 struct rte_flow_item_icmp6_nd_opt_sla_eth { 1239 uint8_t type; /**< ND option type, normally 1. */ 1240 uint8_t length; /**< ND option length, normally 1. */ 1241 struct rte_ether_addr sla; /**< Source Ethernet LLA. */ 1242 }; 1243 1244 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT_SLA_ETH. */ 1245 #ifndef __cplusplus 1246 static const struct rte_flow_item_icmp6_nd_opt_sla_eth 1247 rte_flow_item_icmp6_nd_opt_sla_eth_mask = { 1248 .sla.addr_bytes = "\xff\xff\xff\xff\xff\xff", 1249 }; 1250 #endif 1251 1252 /** 1253 * RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT_TLA_ETH 1254 * 1255 * Matches an ICMPv6 neighbor discovery target Ethernet link-layer address 1256 * option. 1257 * 1258 * Normally preceded by any of: 1259 * 1260 * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_NS 1261 * - RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT 1262 */ 1263 struct rte_flow_item_icmp6_nd_opt_tla_eth { 1264 uint8_t type; /**< ND option type, normally 2. */ 1265 uint8_t length; /**< ND option length, normally 1. */ 1266 struct rte_ether_addr tla; /**< Target Ethernet LLA. */ 1267 }; 1268 1269 /** Default mask for RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT_TLA_ETH. */ 1270 #ifndef __cplusplus 1271 static const struct rte_flow_item_icmp6_nd_opt_tla_eth 1272 rte_flow_item_icmp6_nd_opt_tla_eth_mask = { 1273 .tla.addr_bytes = "\xff\xff\xff\xff\xff\xff", 1274 }; 1275 #endif 1276 1277 /** 1278 * RTE_FLOW_ITEM_TYPE_META 1279 * 1280 * Matches a specified metadata value. On egress, metadata can be set 1281 * either by mbuf dynamic metadata field with PKT_TX_DYNF_METADATA flag or 1282 * RTE_FLOW_ACTION_TYPE_SET_META. On ingress, RTE_FLOW_ACTION_TYPE_SET_META 1283 * sets metadata for a packet and the metadata will be reported via mbuf 1284 * metadata dynamic field with PKT_RX_DYNF_METADATA flag. The dynamic mbuf 1285 * field must be registered in advance by rte_flow_dynf_metadata_register(). 1286 */ 1287 struct rte_flow_item_meta { 1288 uint32_t data; 1289 }; 1290 1291 /** Default mask for RTE_FLOW_ITEM_TYPE_META. */ 1292 #ifndef __cplusplus 1293 static const struct rte_flow_item_meta rte_flow_item_meta_mask = { 1294 .data = UINT32_MAX, 1295 }; 1296 #endif 1297 1298 /** 1299 * RTE_FLOW_ITEM_TYPE_GTP_PSC. 1300 * 1301 * Matches a GTP PDU extension header with type 0x85. 1302 */ 1303 struct rte_flow_item_gtp_psc { 1304 uint8_t pdu_type; /**< PDU type. */ 1305 uint8_t qfi; /**< QoS flow identifier. */ 1306 }; 1307 1308 /** Default mask for RTE_FLOW_ITEM_TYPE_GTP_PSC. */ 1309 #ifndef __cplusplus 1310 static const struct rte_flow_item_gtp_psc 1311 rte_flow_item_gtp_psc_mask = { 1312 .qfi = 0x3f, 1313 }; 1314 #endif 1315 1316 /** 1317 * RTE_FLOW_ITEM_TYPE_PPPOE. 1318 * 1319 * Matches a PPPoE header. 1320 */ 1321 struct rte_flow_item_pppoe { 1322 /** 1323 * Version (4b), type (4b). 1324 */ 1325 uint8_t version_type; 1326 uint8_t code; /**< Message type. */ 1327 rte_be16_t session_id; /**< Session identifier. */ 1328 rte_be16_t length; /**< Payload length. */ 1329 }; 1330 1331 /** 1332 * RTE_FLOW_ITEM_TYPE_PPPOE_PROTO_ID. 1333 * 1334 * Matches a PPPoE optional proto_id field. 1335 * 1336 * It only applies to PPPoE session packets. 1337 * 1338 * Normally preceded by any of: 1339 * 1340 * - RTE_FLOW_ITEM_TYPE_PPPOE 1341 * - RTE_FLOW_ITEM_TYPE_PPPOE_PROTO_ID 1342 */ 1343 struct rte_flow_item_pppoe_proto_id { 1344 rte_be16_t proto_id; /**< PPP protocol identifier. */ 1345 }; 1346 1347 /** Default mask for RTE_FLOW_ITEM_TYPE_PPPOE_PROTO_ID. */ 1348 #ifndef __cplusplus 1349 static const struct rte_flow_item_pppoe_proto_id 1350 rte_flow_item_pppoe_proto_id_mask = { 1351 .proto_id = RTE_BE16(0xffff), 1352 }; 1353 #endif 1354 1355 /** 1356 * @warning 1357 * @b EXPERIMENTAL: this structure may change without prior notice 1358 * 1359 * RTE_FLOW_ITEM_TYPE_TAG 1360 * 1361 * Matches a specified tag value at the specified index. 1362 */ 1363 struct rte_flow_item_tag { 1364 uint32_t data; 1365 uint8_t index; 1366 }; 1367 1368 /** Default mask for RTE_FLOW_ITEM_TYPE_TAG. */ 1369 #ifndef __cplusplus 1370 static const struct rte_flow_item_tag rte_flow_item_tag_mask = { 1371 .data = 0xffffffff, 1372 .index = 0xff, 1373 }; 1374 #endif 1375 1376 /** 1377 * @warning 1378 * @b EXPERIMENTAL: this structure may change without prior notice 1379 * 1380 * RTE_FLOW_ITEM_TYPE_MARK 1381 * 1382 * Matches an arbitrary integer value which was set using the ``MARK`` action 1383 * in a previously matched rule. 1384 * 1385 * This item can only be specified once as a match criteria as the ``MARK`` 1386 * action can only be specified once in a flow action. 1387 * 1388 * This value is arbitrary and application-defined. Maximum allowed value 1389 * depends on the underlying implementation. 1390 * 1391 * Depending on the underlying implementation the MARK item may be supported on 1392 * the physical device, with virtual groups in the PMD or not at all. 1393 */ 1394 struct rte_flow_item_mark { 1395 uint32_t id; /**< Integer value to match against. */ 1396 }; 1397 1398 /** Default mask for RTE_FLOW_ITEM_TYPE_MARK. */ 1399 #ifndef __cplusplus 1400 static const struct rte_flow_item_mark rte_flow_item_mark_mask = { 1401 .id = 0xffffffff, 1402 }; 1403 #endif 1404 1405 /** 1406 * @warning 1407 * @b EXPERIMENTAL: this structure may change without prior notice 1408 * 1409 * RTE_FLOW_ITEM_TYPE_NSH 1410 * 1411 * Match network service header (NSH), RFC 8300 1412 * 1413 */ 1414 struct rte_flow_item_nsh { 1415 uint32_t version:2; 1416 uint32_t oam_pkt:1; 1417 uint32_t reserved:1; 1418 uint32_t ttl:6; 1419 uint32_t length:6; 1420 uint32_t reserved1:4; 1421 uint32_t mdtype:4; 1422 uint32_t next_proto:8; 1423 uint32_t spi:24; 1424 uint32_t sindex:8; 1425 }; 1426 1427 /** Default mask for RTE_FLOW_ITEM_TYPE_NSH. */ 1428 #ifndef __cplusplus 1429 static const struct rte_flow_item_nsh rte_flow_item_nsh_mask = { 1430 .mdtype = 0xf, 1431 .next_proto = 0xff, 1432 .spi = 0xffffff, 1433 .sindex = 0xff, 1434 }; 1435 #endif 1436 1437 /** 1438 * @warning 1439 * @b EXPERIMENTAL: this structure may change without prior notice 1440 * 1441 * RTE_FLOW_ITEM_TYPE_IGMP 1442 * 1443 * Match Internet Group Management Protocol (IGMP), RFC 2236 1444 * 1445 */ 1446 struct rte_flow_item_igmp { 1447 uint32_t type:8; 1448 uint32_t max_resp_time:8; 1449 uint32_t checksum:16; 1450 uint32_t group_addr; 1451 }; 1452 1453 /** Default mask for RTE_FLOW_ITEM_TYPE_IGMP. */ 1454 #ifndef __cplusplus 1455 static const struct rte_flow_item_igmp rte_flow_item_igmp_mask = { 1456 .group_addr = 0xffffffff, 1457 }; 1458 #endif 1459 1460 /** 1461 * @warning 1462 * @b EXPERIMENTAL: this structure may change without prior notice 1463 * 1464 * RTE_FLOW_ITEM_TYPE_AH 1465 * 1466 * Match IP Authentication Header (AH), RFC 4302 1467 * 1468 */ 1469 struct rte_flow_item_ah { 1470 uint32_t next_hdr:8; 1471 uint32_t payload_len:8; 1472 uint32_t reserved:16; 1473 uint32_t spi; 1474 uint32_t seq_num; 1475 }; 1476 1477 /** Default mask for RTE_FLOW_ITEM_TYPE_AH. */ 1478 #ifndef __cplusplus 1479 static const struct rte_flow_item_ah rte_flow_item_ah_mask = { 1480 .spi = 0xffffffff, 1481 }; 1482 #endif 1483 1484 /** 1485 * Matching pattern item definition. 1486 * 1487 * A pattern is formed by stacking items starting from the lowest protocol 1488 * layer to match. This stacking restriction does not apply to meta items 1489 * which can be placed anywhere in the stack without affecting the meaning 1490 * of the resulting pattern. 1491 * 1492 * Patterns are terminated by END items. 1493 * 1494 * The spec field should be a valid pointer to a structure of the related 1495 * item type. It may remain unspecified (NULL) in many cases to request 1496 * broad (nonspecific) matching. In such cases, last and mask must also be 1497 * set to NULL. 1498 * 1499 * Optionally, last can point to a structure of the same type to define an 1500 * inclusive range. This is mostly supported by integer and address fields, 1501 * may cause errors otherwise. Fields that do not support ranges must be set 1502 * to 0 or to the same value as the corresponding fields in spec. 1503 * 1504 * Only the fields defined to nonzero values in the default masks (see 1505 * rte_flow_item_{name}_mask constants) are considered relevant by 1506 * default. This can be overridden by providing a mask structure of the 1507 * same type with applicable bits set to one. It can also be used to 1508 * partially filter out specific fields (e.g. as an alternate mean to match 1509 * ranges of IP addresses). 1510 * 1511 * Mask is a simple bit-mask applied before interpreting the contents of 1512 * spec and last, which may yield unexpected results if not used 1513 * carefully. For example, if for an IPv4 address field, spec provides 1514 * 10.1.2.3, last provides 10.3.4.5 and mask provides 255.255.0.0, the 1515 * effective range becomes 10.1.0.0 to 10.3.255.255. 1516 */ 1517 struct rte_flow_item { 1518 enum rte_flow_item_type type; /**< Item type. */ 1519 const void *spec; /**< Pointer to item specification structure. */ 1520 const void *last; /**< Defines an inclusive range (spec to last). */ 1521 const void *mask; /**< Bit-mask applied to spec and last. */ 1522 }; 1523 1524 /** 1525 * Action types. 1526 * 1527 * Each possible action is represented by a type. 1528 * An action can have an associated configuration object. 1529 * Several actions combined in a list can be assigned 1530 * to a flow rule and are performed in order. 1531 * 1532 * They fall in three categories: 1533 * 1534 * - Actions that modify the fate of matching traffic, for instance by 1535 * dropping or assigning it a specific destination. 1536 * 1537 * - Actions that modify matching traffic contents or its properties. This 1538 * includes adding/removing encapsulation, encryption, compression and 1539 * marks. 1540 * 1541 * - Actions related to the flow rule itself, such as updating counters or 1542 * making it non-terminating. 1543 * 1544 * Flow rules being terminating by default, not specifying any action of the 1545 * fate kind results in undefined behavior. This applies to both ingress and 1546 * egress. 1547 * 1548 * PASSTHRU, when supported, makes a flow rule non-terminating. 1549 */ 1550 enum rte_flow_action_type { 1551 /** 1552 * End marker for action lists. Prevents further processing of 1553 * actions, thereby ending the list. 1554 * 1555 * No associated configuration structure. 1556 */ 1557 RTE_FLOW_ACTION_TYPE_END, 1558 1559 /** 1560 * Used as a placeholder for convenience. It is ignored and simply 1561 * discarded by PMDs. 1562 * 1563 * No associated configuration structure. 1564 */ 1565 RTE_FLOW_ACTION_TYPE_VOID, 1566 1567 /** 1568 * Leaves traffic up for additional processing by subsequent flow 1569 * rules; makes a flow rule non-terminating. 1570 * 1571 * No associated configuration structure. 1572 */ 1573 RTE_FLOW_ACTION_TYPE_PASSTHRU, 1574 1575 /** 1576 * RTE_FLOW_ACTION_TYPE_JUMP 1577 * 1578 * Redirects packets to a group on the current device. 1579 * 1580 * See struct rte_flow_action_jump. 1581 */ 1582 RTE_FLOW_ACTION_TYPE_JUMP, 1583 1584 /** 1585 * Attaches an integer value to packets and sets PKT_RX_FDIR and 1586 * PKT_RX_FDIR_ID mbuf flags. 1587 * 1588 * See struct rte_flow_action_mark. 1589 */ 1590 RTE_FLOW_ACTION_TYPE_MARK, 1591 1592 /** 1593 * Flags packets. Similar to MARK without a specific value; only 1594 * sets the PKT_RX_FDIR mbuf flag. 1595 * 1596 * No associated configuration structure. 1597 */ 1598 RTE_FLOW_ACTION_TYPE_FLAG, 1599 1600 /** 1601 * Assigns packets to a given queue index. 1602 * 1603 * See struct rte_flow_action_queue. 1604 */ 1605 RTE_FLOW_ACTION_TYPE_QUEUE, 1606 1607 /** 1608 * Drops packets. 1609 * 1610 * PASSTHRU overrides this action if both are specified. 1611 * 1612 * No associated configuration structure. 1613 */ 1614 RTE_FLOW_ACTION_TYPE_DROP, 1615 1616 /** 1617 * Enables counters for this flow rule. 1618 * 1619 * These counters can be retrieved and reset through rte_flow_query(), 1620 * see struct rte_flow_query_count. 1621 * 1622 * See struct rte_flow_action_count. 1623 */ 1624 RTE_FLOW_ACTION_TYPE_COUNT, 1625 1626 /** 1627 * Similar to QUEUE, except RSS is additionally performed on packets 1628 * to spread them among several queues according to the provided 1629 * parameters. 1630 * 1631 * See struct rte_flow_action_rss. 1632 */ 1633 RTE_FLOW_ACTION_TYPE_RSS, 1634 1635 /** 1636 * Directs matching traffic to the physical function (PF) of the 1637 * current device. 1638 * 1639 * No associated configuration structure. 1640 */ 1641 RTE_FLOW_ACTION_TYPE_PF, 1642 1643 /** 1644 * Directs matching traffic to a given virtual function of the 1645 * current device. 1646 * 1647 * See struct rte_flow_action_vf. 1648 */ 1649 RTE_FLOW_ACTION_TYPE_VF, 1650 1651 /** 1652 * Directs packets to a given physical port index of the underlying 1653 * device. 1654 * 1655 * See struct rte_flow_action_phy_port. 1656 */ 1657 RTE_FLOW_ACTION_TYPE_PHY_PORT, 1658 1659 /** 1660 * Directs matching traffic to a given DPDK port ID. 1661 * 1662 * See struct rte_flow_action_port_id. 1663 */ 1664 RTE_FLOW_ACTION_TYPE_PORT_ID, 1665 1666 /** 1667 * Traffic metering and policing (MTR). 1668 * 1669 * See struct rte_flow_action_meter. 1670 * See file rte_mtr.h for MTR object configuration. 1671 */ 1672 RTE_FLOW_ACTION_TYPE_METER, 1673 1674 /** 1675 * Redirects packets to security engine of current device for security 1676 * processing as specified by security session. 1677 * 1678 * See struct rte_flow_action_security. 1679 */ 1680 RTE_FLOW_ACTION_TYPE_SECURITY, 1681 1682 /** 1683 * Implements OFPAT_SET_MPLS_TTL ("MPLS TTL") as defined by the 1684 * OpenFlow Switch Specification. 1685 * 1686 * See struct rte_flow_action_of_set_mpls_ttl. 1687 */ 1688 RTE_FLOW_ACTION_TYPE_OF_SET_MPLS_TTL, 1689 1690 /** 1691 * Implements OFPAT_DEC_MPLS_TTL ("decrement MPLS TTL") as defined 1692 * by the OpenFlow Switch Specification. 1693 * 1694 * No associated configuration structure. 1695 */ 1696 RTE_FLOW_ACTION_TYPE_OF_DEC_MPLS_TTL, 1697 1698 /** 1699 * Implements OFPAT_SET_NW_TTL ("IP TTL") as defined by the OpenFlow 1700 * Switch Specification. 1701 * 1702 * See struct rte_flow_action_of_set_nw_ttl. 1703 */ 1704 RTE_FLOW_ACTION_TYPE_OF_SET_NW_TTL, 1705 1706 /** 1707 * Implements OFPAT_DEC_NW_TTL ("decrement IP TTL") as defined by 1708 * the OpenFlow Switch Specification. 1709 * 1710 * No associated configuration structure. 1711 */ 1712 RTE_FLOW_ACTION_TYPE_OF_DEC_NW_TTL, 1713 1714 /** 1715 * Implements OFPAT_COPY_TTL_OUT ("copy TTL "outwards" -- from 1716 * next-to-outermost to outermost") as defined by the OpenFlow 1717 * Switch Specification. 1718 * 1719 * No associated configuration structure. 1720 */ 1721 RTE_FLOW_ACTION_TYPE_OF_COPY_TTL_OUT, 1722 1723 /** 1724 * Implements OFPAT_COPY_TTL_IN ("copy TTL "inwards" -- from 1725 * outermost to next-to-outermost") as defined by the OpenFlow 1726 * Switch Specification. 1727 * 1728 * No associated configuration structure. 1729 */ 1730 RTE_FLOW_ACTION_TYPE_OF_COPY_TTL_IN, 1731 1732 /** 1733 * Implements OFPAT_POP_VLAN ("pop the outer VLAN tag") as defined 1734 * by the OpenFlow Switch Specification. 1735 * 1736 * No associated configuration structure. 1737 */ 1738 RTE_FLOW_ACTION_TYPE_OF_POP_VLAN, 1739 1740 /** 1741 * Implements OFPAT_PUSH_VLAN ("push a new VLAN tag") as defined by 1742 * the OpenFlow Switch Specification. 1743 * 1744 * See struct rte_flow_action_of_push_vlan. 1745 */ 1746 RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN, 1747 1748 /** 1749 * Implements OFPAT_SET_VLAN_VID ("set the 802.1q VLAN id") as 1750 * defined by the OpenFlow Switch Specification. 1751 * 1752 * See struct rte_flow_action_of_set_vlan_vid. 1753 */ 1754 RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID, 1755 1756 /** 1757 * Implements OFPAT_SET_LAN_PCP ("set the 802.1q priority") as 1758 * defined by the OpenFlow Switch Specification. 1759 * 1760 * See struct rte_flow_action_of_set_vlan_pcp. 1761 */ 1762 RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP, 1763 1764 /** 1765 * Implements OFPAT_POP_MPLS ("pop the outer MPLS tag") as defined 1766 * by the OpenFlow Switch Specification. 1767 * 1768 * See struct rte_flow_action_of_pop_mpls. 1769 */ 1770 RTE_FLOW_ACTION_TYPE_OF_POP_MPLS, 1771 1772 /** 1773 * Implements OFPAT_PUSH_MPLS ("push a new MPLS tag") as defined by 1774 * the OpenFlow Switch Specification. 1775 * 1776 * See struct rte_flow_action_of_push_mpls. 1777 */ 1778 RTE_FLOW_ACTION_TYPE_OF_PUSH_MPLS, 1779 1780 /** 1781 * Encapsulate flow in VXLAN tunnel as defined in 1782 * rte_flow_action_vxlan_encap action structure. 1783 * 1784 * See struct rte_flow_action_vxlan_encap. 1785 */ 1786 RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP, 1787 1788 /** 1789 * Decapsulate outer most VXLAN tunnel from matched flow. 1790 * 1791 * If flow pattern does not define a valid VXLAN tunnel (as specified by 1792 * RFC7348) then the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION 1793 * error. 1794 */ 1795 RTE_FLOW_ACTION_TYPE_VXLAN_DECAP, 1796 1797 /** 1798 * Encapsulate flow in NVGRE tunnel defined in the 1799 * rte_flow_action_nvgre_encap action structure. 1800 * 1801 * See struct rte_flow_action_nvgre_encap. 1802 */ 1803 RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP, 1804 1805 /** 1806 * Decapsulate outer most NVGRE tunnel from matched flow. 1807 * 1808 * If flow pattern does not define a valid NVGRE tunnel (as specified by 1809 * RFC7637) then the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION 1810 * error. 1811 */ 1812 RTE_FLOW_ACTION_TYPE_NVGRE_DECAP, 1813 1814 /** 1815 * Add outer header whose template is provided in its data buffer 1816 * 1817 * See struct rte_flow_action_raw_encap. 1818 */ 1819 RTE_FLOW_ACTION_TYPE_RAW_ENCAP, 1820 1821 /** 1822 * Remove outer header whose template is provided in its data buffer. 1823 * 1824 * See struct rte_flow_action_raw_decap 1825 */ 1826 RTE_FLOW_ACTION_TYPE_RAW_DECAP, 1827 1828 /** 1829 * Modify IPv4 source address in the outermost IPv4 header. 1830 * 1831 * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_IPV4, 1832 * then the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION error. 1833 * 1834 * See struct rte_flow_action_set_ipv4. 1835 */ 1836 RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC, 1837 1838 /** 1839 * Modify IPv4 destination address in the outermost IPv4 header. 1840 * 1841 * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_IPV4, 1842 * then the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION error. 1843 * 1844 * See struct rte_flow_action_set_ipv4. 1845 */ 1846 RTE_FLOW_ACTION_TYPE_SET_IPV4_DST, 1847 1848 /** 1849 * Modify IPv6 source address in the outermost IPv6 header. 1850 * 1851 * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_IPV6, 1852 * then the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION error. 1853 * 1854 * See struct rte_flow_action_set_ipv6. 1855 */ 1856 RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC, 1857 1858 /** 1859 * Modify IPv6 destination address in the outermost IPv6 header. 1860 * 1861 * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_IPV6, 1862 * then the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION error. 1863 * 1864 * See struct rte_flow_action_set_ipv6. 1865 */ 1866 RTE_FLOW_ACTION_TYPE_SET_IPV6_DST, 1867 1868 /** 1869 * Modify source port number in the outermost TCP/UDP header. 1870 * 1871 * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_TCP 1872 * or RTE_FLOW_ITEM_TYPE_UDP, then the PMD should return a 1873 * RTE_FLOW_ERROR_TYPE_ACTION error. 1874 * 1875 * See struct rte_flow_action_set_tp. 1876 */ 1877 RTE_FLOW_ACTION_TYPE_SET_TP_SRC, 1878 1879 /** 1880 * Modify destination port number in the outermost TCP/UDP header. 1881 * 1882 * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_TCP 1883 * or RTE_FLOW_ITEM_TYPE_UDP, then the PMD should return a 1884 * RTE_FLOW_ERROR_TYPE_ACTION error. 1885 * 1886 * See struct rte_flow_action_set_tp. 1887 */ 1888 RTE_FLOW_ACTION_TYPE_SET_TP_DST, 1889 1890 /** 1891 * Swap the source and destination MAC addresses in the outermost 1892 * Ethernet header. 1893 * 1894 * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_ETH, 1895 * then the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION error. 1896 * 1897 * No associated configuration structure. 1898 */ 1899 RTE_FLOW_ACTION_TYPE_MAC_SWAP, 1900 1901 /** 1902 * Decrease TTL value directly 1903 * 1904 * No associated configuration structure. 1905 */ 1906 RTE_FLOW_ACTION_TYPE_DEC_TTL, 1907 1908 /** 1909 * Set TTL value 1910 * 1911 * See struct rte_flow_action_set_ttl 1912 */ 1913 RTE_FLOW_ACTION_TYPE_SET_TTL, 1914 1915 /** 1916 * Set source MAC address from matched flow. 1917 * 1918 * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_ETH, 1919 * the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION error. 1920 * 1921 * See struct rte_flow_action_set_mac. 1922 */ 1923 RTE_FLOW_ACTION_TYPE_SET_MAC_SRC, 1924 1925 /** 1926 * Set destination MAC address from matched flow. 1927 * 1928 * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_ETH, 1929 * the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION error. 1930 * 1931 * See struct rte_flow_action_set_mac. 1932 */ 1933 RTE_FLOW_ACTION_TYPE_SET_MAC_DST, 1934 1935 /** 1936 * Increase sequence number in the outermost TCP header. 1937 * 1938 * Action configuration specifies the value to increase 1939 * TCP sequence number as a big-endian 32 bit integer. 1940 * 1941 * @p conf type: 1942 * @code rte_be32_t * @endcode 1943 * 1944 * Using this action on non-matching traffic will result in 1945 * undefined behavior. 1946 */ 1947 RTE_FLOW_ACTION_TYPE_INC_TCP_SEQ, 1948 1949 /** 1950 * Decrease sequence number in the outermost TCP header. 1951 * 1952 * Action configuration specifies the value to decrease 1953 * TCP sequence number as a big-endian 32 bit integer. 1954 * 1955 * @p conf type: 1956 * @code rte_be32_t * @endcode 1957 * 1958 * Using this action on non-matching traffic will result in 1959 * undefined behavior. 1960 */ 1961 RTE_FLOW_ACTION_TYPE_DEC_TCP_SEQ, 1962 1963 /** 1964 * Increase acknowledgment number in the outermost TCP header. 1965 * 1966 * Action configuration specifies the value to increase 1967 * TCP acknowledgment number as a big-endian 32 bit integer. 1968 * 1969 * @p conf type: 1970 * @code rte_be32_t * @endcode 1971 1972 * Using this action on non-matching traffic will result in 1973 * undefined behavior. 1974 */ 1975 RTE_FLOW_ACTION_TYPE_INC_TCP_ACK, 1976 1977 /** 1978 * Decrease acknowledgment number in the outermost TCP header. 1979 * 1980 * Action configuration specifies the value to decrease 1981 * TCP acknowledgment number as a big-endian 32 bit integer. 1982 * 1983 * @p conf type: 1984 * @code rte_be32_t * @endcode 1985 * 1986 * Using this action on non-matching traffic will result in 1987 * undefined behavior. 1988 */ 1989 RTE_FLOW_ACTION_TYPE_DEC_TCP_ACK, 1990 1991 /** 1992 * Set Tag. 1993 * 1994 * Tag is for internal flow usage only and 1995 * is not delivered to the application. 1996 * 1997 * See struct rte_flow_action_set_tag. 1998 */ 1999 RTE_FLOW_ACTION_TYPE_SET_TAG, 2000 2001 /** 2002 * Set metadata on ingress or egress path. 2003 * 2004 * See struct rte_flow_action_set_meta. 2005 */ 2006 RTE_FLOW_ACTION_TYPE_SET_META, 2007 }; 2008 2009 /** 2010 * RTE_FLOW_ACTION_TYPE_MARK 2011 * 2012 * Attaches an integer value to packets and sets PKT_RX_FDIR and 2013 * PKT_RX_FDIR_ID mbuf flags. 2014 * 2015 * This value is arbitrary and application-defined. Maximum allowed value 2016 * depends on the underlying implementation. It is returned in the 2017 * hash.fdir.hi mbuf field. 2018 */ 2019 struct rte_flow_action_mark { 2020 uint32_t id; /**< Integer value to return with packets. */ 2021 }; 2022 2023 /** 2024 * @warning 2025 * @b EXPERIMENTAL: this structure may change without prior notice 2026 * 2027 * RTE_FLOW_ACTION_TYPE_JUMP 2028 * 2029 * Redirects packets to a group on the current device. 2030 * 2031 * In a hierarchy of groups, which can be used to represent physical or logical 2032 * flow tables on the device, this action allows the action to be a redirect to 2033 * a group on that device. 2034 */ 2035 struct rte_flow_action_jump { 2036 uint32_t group; 2037 }; 2038 2039 /** 2040 * RTE_FLOW_ACTION_TYPE_QUEUE 2041 * 2042 * Assign packets to a given queue index. 2043 */ 2044 struct rte_flow_action_queue { 2045 uint16_t index; /**< Queue index to use. */ 2046 }; 2047 2048 2049 /** 2050 * @warning 2051 * @b EXPERIMENTAL: this structure may change without prior notice 2052 * 2053 * RTE_FLOW_ACTION_TYPE_COUNT 2054 * 2055 * Adds a counter action to a matched flow. 2056 * 2057 * If more than one count action is specified in a single flow rule, then each 2058 * action must specify a unique id. 2059 * 2060 * Counters can be retrieved and reset through ``rte_flow_query()``, see 2061 * ``struct rte_flow_query_count``. 2062 * 2063 * The shared flag indicates whether the counter is unique to the flow rule the 2064 * action is specified with, or whether it is a shared counter. 2065 * 2066 * For a count action with the shared flag set, then then a global device 2067 * namespace is assumed for the counter id, so that any matched flow rules using 2068 * a count action with the same counter id on the same port will contribute to 2069 * that counter. 2070 * 2071 * For ports within the same switch domain then the counter id namespace extends 2072 * to all ports within that switch domain. 2073 */ 2074 struct rte_flow_action_count { 2075 uint32_t shared:1; /**< Share counter ID with other flow rules. */ 2076 uint32_t reserved:31; /**< Reserved, must be zero. */ 2077 uint32_t id; /**< Counter ID. */ 2078 }; 2079 2080 /** 2081 * RTE_FLOW_ACTION_TYPE_COUNT (query) 2082 * 2083 * Query structure to retrieve and reset flow rule counters. 2084 */ 2085 struct rte_flow_query_count { 2086 uint32_t reset:1; /**< Reset counters after query [in]. */ 2087 uint32_t hits_set:1; /**< hits field is set [out]. */ 2088 uint32_t bytes_set:1; /**< bytes field is set [out]. */ 2089 uint32_t reserved:29; /**< Reserved, must be zero [in, out]. */ 2090 uint64_t hits; /**< Number of hits for this rule [out]. */ 2091 uint64_t bytes; /**< Number of bytes through this rule [out]. */ 2092 }; 2093 2094 /** 2095 * Hash function types. 2096 */ 2097 enum rte_eth_hash_function { 2098 RTE_ETH_HASH_FUNCTION_DEFAULT = 0, 2099 RTE_ETH_HASH_FUNCTION_TOEPLITZ, /**< Toeplitz */ 2100 RTE_ETH_HASH_FUNCTION_SIMPLE_XOR, /**< Simple XOR */ 2101 /** 2102 * Symmetric Toeplitz: src, dst will be replaced by 2103 * xor(src, dst). For the case with src/dst only, 2104 * src or dst address will xor with zero pair. 2105 */ 2106 RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ, 2107 RTE_ETH_HASH_FUNCTION_MAX, 2108 }; 2109 2110 /** 2111 * RTE_FLOW_ACTION_TYPE_RSS 2112 * 2113 * Similar to QUEUE, except RSS is additionally performed on packets to 2114 * spread them among several queues according to the provided parameters. 2115 * 2116 * Unlike global RSS settings used by other DPDK APIs, unsetting the 2117 * @p types field does not disable RSS in a flow rule. Doing so instead 2118 * requests safe unspecified "best-effort" settings from the underlying PMD, 2119 * which depending on the flow rule, may result in anything ranging from 2120 * empty (single queue) to all-inclusive RSS. 2121 * 2122 * Note: RSS hash result is stored in the hash.rss mbuf field which overlaps 2123 * hash.fdir.lo. Since the MARK action sets the hash.fdir.hi field only, 2124 * both can be requested simultaneously. 2125 */ 2126 struct rte_flow_action_rss { 2127 enum rte_eth_hash_function func; /**< RSS hash function to apply. */ 2128 /** 2129 * Packet encapsulation level RSS hash @p types apply to. 2130 * 2131 * - @p 0 requests the default behavior. Depending on the packet 2132 * type, it can mean outermost, innermost, anything in between or 2133 * even no RSS. 2134 * 2135 * It basically stands for the innermost encapsulation level RSS 2136 * can be performed on according to PMD and device capabilities. 2137 * 2138 * - @p 1 requests RSS to be performed on the outermost packet 2139 * encapsulation level. 2140 * 2141 * - @p 2 and subsequent values request RSS to be performed on the 2142 * specified inner packet encapsulation level, from outermost to 2143 * innermost (lower to higher values). 2144 * 2145 * Values other than @p 0 are not necessarily supported. 2146 * 2147 * Requesting a specific RSS level on unrecognized traffic results 2148 * in undefined behavior. For predictable results, it is recommended 2149 * to make the flow rule pattern match packet headers up to the 2150 * requested encapsulation level so that only matching traffic goes 2151 * through. 2152 */ 2153 uint32_t level; 2154 uint64_t types; /**< Specific RSS hash types (see ETH_RSS_*). */ 2155 uint32_t key_len; /**< Hash key length in bytes. */ 2156 uint32_t queue_num; /**< Number of entries in @p queue. */ 2157 const uint8_t *key; /**< Hash key. */ 2158 const uint16_t *queue; /**< Queue indices to use. */ 2159 }; 2160 2161 /** 2162 * RTE_FLOW_ACTION_TYPE_VF 2163 * 2164 * Directs matching traffic to a given virtual function of the current 2165 * device. 2166 * 2167 * Packets matched by a VF pattern item can be redirected to their original 2168 * VF ID instead of the specified one. This parameter may not be available 2169 * and is not guaranteed to work properly if the VF part is matched by a 2170 * prior flow rule or if packets are not addressed to a VF in the first 2171 * place. 2172 */ 2173 struct rte_flow_action_vf { 2174 uint32_t original:1; /**< Use original VF ID if possible. */ 2175 uint32_t reserved:31; /**< Reserved, must be zero. */ 2176 uint32_t id; /**< VF ID. */ 2177 }; 2178 2179 /** 2180 * RTE_FLOW_ACTION_TYPE_PHY_PORT 2181 * 2182 * Directs packets to a given physical port index of the underlying 2183 * device. 2184 * 2185 * @see RTE_FLOW_ITEM_TYPE_PHY_PORT 2186 */ 2187 struct rte_flow_action_phy_port { 2188 uint32_t original:1; /**< Use original port index if possible. */ 2189 uint32_t reserved:31; /**< Reserved, must be zero. */ 2190 uint32_t index; /**< Physical port index. */ 2191 }; 2192 2193 /** 2194 * RTE_FLOW_ACTION_TYPE_PORT_ID 2195 * 2196 * Directs matching traffic to a given DPDK port ID. 2197 * 2198 * @see RTE_FLOW_ITEM_TYPE_PORT_ID 2199 */ 2200 struct rte_flow_action_port_id { 2201 uint32_t original:1; /**< Use original DPDK port ID if possible. */ 2202 uint32_t reserved:31; /**< Reserved, must be zero. */ 2203 uint32_t id; /**< DPDK port ID. */ 2204 }; 2205 2206 /** 2207 * RTE_FLOW_ACTION_TYPE_METER 2208 * 2209 * Traffic metering and policing (MTR). 2210 * 2211 * Packets matched by items of this type can be either dropped or passed to the 2212 * next item with their color set by the MTR object. 2213 */ 2214 struct rte_flow_action_meter { 2215 uint32_t mtr_id; /**< MTR object ID created with rte_mtr_create(). */ 2216 }; 2217 2218 /** 2219 * RTE_FLOW_ACTION_TYPE_SECURITY 2220 * 2221 * Perform the security action on flows matched by the pattern items 2222 * according to the configuration of the security session. 2223 * 2224 * This action modifies the payload of matched flows. For INLINE_CRYPTO, the 2225 * security protocol headers and IV are fully provided by the application as 2226 * specified in the flow pattern. The payload of matching packets is 2227 * encrypted on egress, and decrypted and authenticated on ingress. 2228 * For INLINE_PROTOCOL, the security protocol is fully offloaded to HW, 2229 * providing full encapsulation and decapsulation of packets in security 2230 * protocols. The flow pattern specifies both the outer security header fields 2231 * and the inner packet fields. The security session specified in the action 2232 * must match the pattern parameters. 2233 * 2234 * The security session specified in the action must be created on the same 2235 * port as the flow action that is being specified. 2236 * 2237 * The ingress/egress flow attribute should match that specified in the 2238 * security session if the security session supports the definition of the 2239 * direction. 2240 * 2241 * Multiple flows can be configured to use the same security session. 2242 */ 2243 struct rte_flow_action_security { 2244 void *security_session; /**< Pointer to security session structure. */ 2245 }; 2246 2247 /** 2248 * RTE_FLOW_ACTION_TYPE_OF_SET_MPLS_TTL 2249 * 2250 * Implements OFPAT_SET_MPLS_TTL ("MPLS TTL") as defined by the OpenFlow 2251 * Switch Specification. 2252 */ 2253 struct rte_flow_action_of_set_mpls_ttl { 2254 uint8_t mpls_ttl; /**< MPLS TTL. */ 2255 }; 2256 2257 /** 2258 * RTE_FLOW_ACTION_TYPE_OF_SET_NW_TTL 2259 * 2260 * Implements OFPAT_SET_NW_TTL ("IP TTL") as defined by the OpenFlow Switch 2261 * Specification. 2262 */ 2263 struct rte_flow_action_of_set_nw_ttl { 2264 uint8_t nw_ttl; /**< IP TTL. */ 2265 }; 2266 2267 /** 2268 * RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN 2269 * 2270 * Implements OFPAT_PUSH_VLAN ("push a new VLAN tag") as defined by the 2271 * OpenFlow Switch Specification. 2272 */ 2273 struct rte_flow_action_of_push_vlan { 2274 rte_be16_t ethertype; /**< EtherType. */ 2275 }; 2276 2277 /** 2278 * RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID 2279 * 2280 * Implements OFPAT_SET_VLAN_VID ("set the 802.1q VLAN id") as defined by 2281 * the OpenFlow Switch Specification. 2282 */ 2283 struct rte_flow_action_of_set_vlan_vid { 2284 rte_be16_t vlan_vid; /**< VLAN id. */ 2285 }; 2286 2287 /** 2288 * RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP 2289 * 2290 * Implements OFPAT_SET_LAN_PCP ("set the 802.1q priority") as defined by 2291 * the OpenFlow Switch Specification. 2292 */ 2293 struct rte_flow_action_of_set_vlan_pcp { 2294 uint8_t vlan_pcp; /**< VLAN priority. */ 2295 }; 2296 2297 /** 2298 * RTE_FLOW_ACTION_TYPE_OF_POP_MPLS 2299 * 2300 * Implements OFPAT_POP_MPLS ("pop the outer MPLS tag") as defined by the 2301 * OpenFlow Switch Specification. 2302 */ 2303 struct rte_flow_action_of_pop_mpls { 2304 rte_be16_t ethertype; /**< EtherType. */ 2305 }; 2306 2307 /** 2308 * RTE_FLOW_ACTION_TYPE_OF_PUSH_MPLS 2309 * 2310 * Implements OFPAT_PUSH_MPLS ("push a new MPLS tag") as defined by the 2311 * OpenFlow Switch Specification. 2312 */ 2313 struct rte_flow_action_of_push_mpls { 2314 rte_be16_t ethertype; /**< EtherType. */ 2315 }; 2316 2317 /** 2318 * @warning 2319 * @b EXPERIMENTAL: this structure may change without prior notice 2320 * 2321 * RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP 2322 * 2323 * VXLAN tunnel end-point encapsulation data definition 2324 * 2325 * The tunnel definition is provided through the flow item pattern, the 2326 * provided pattern must conform to RFC7348 for the tunnel specified. The flow 2327 * definition must be provided in order from the RTE_FLOW_ITEM_TYPE_ETH 2328 * definition up the end item which is specified by RTE_FLOW_ITEM_TYPE_END. 2329 * 2330 * The mask field allows user to specify which fields in the flow item 2331 * definitions can be ignored and which have valid data and can be used 2332 * verbatim. 2333 * 2334 * Note: the last field is not used in the definition of a tunnel and can be 2335 * ignored. 2336 * 2337 * Valid flow definition for RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP include: 2338 * 2339 * - ETH / IPV4 / UDP / VXLAN / END 2340 * - ETH / IPV6 / UDP / VXLAN / END 2341 * - ETH / VLAN / IPV4 / UDP / VXLAN / END 2342 * 2343 */ 2344 struct rte_flow_action_vxlan_encap { 2345 /** 2346 * Encapsulating vxlan tunnel definition 2347 * (terminated by the END pattern item). 2348 */ 2349 struct rte_flow_item *definition; 2350 }; 2351 2352 /** 2353 * @warning 2354 * @b EXPERIMENTAL: this structure may change without prior notice 2355 * 2356 * RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP 2357 * 2358 * NVGRE tunnel end-point encapsulation data definition 2359 * 2360 * The tunnel definition is provided through the flow item pattern the 2361 * provided pattern must conform with RFC7637. The flow definition must be 2362 * provided in order from the RTE_FLOW_ITEM_TYPE_ETH definition up the end item 2363 * which is specified by RTE_FLOW_ITEM_TYPE_END. 2364 * 2365 * The mask field allows user to specify which fields in the flow item 2366 * definitions can be ignored and which have valid data and can be used 2367 * verbatim. 2368 * 2369 * Note: the last field is not used in the definition of a tunnel and can be 2370 * ignored. 2371 * 2372 * Valid flow definition for RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP include: 2373 * 2374 * - ETH / IPV4 / NVGRE / END 2375 * - ETH / VLAN / IPV6 / NVGRE / END 2376 * 2377 */ 2378 struct rte_flow_action_nvgre_encap { 2379 /** 2380 * Encapsulating vxlan tunnel definition 2381 * (terminated by the END pattern item). 2382 */ 2383 struct rte_flow_item *definition; 2384 }; 2385 2386 /** 2387 * @warning 2388 * @b EXPERIMENTAL: this structure may change without prior notice 2389 * 2390 * RTE_FLOW_ACTION_TYPE_RAW_ENCAP 2391 * 2392 * Raw tunnel end-point encapsulation data definition. 2393 * 2394 * The data holds the headers definitions to be applied on the packet. 2395 * The data must start with ETH header up to the tunnel item header itself. 2396 * When used right after RAW_DECAP (for decapsulating L3 tunnel type for 2397 * example MPLSoGRE) the data will just hold layer 2 header. 2398 * 2399 * The preserve parameter holds which bits in the packet the PMD is not allowed 2400 * to change, this parameter can also be NULL and then the PMD is allowed 2401 * to update any field. 2402 * 2403 * size holds the number of bytes in @p data and @p preserve. 2404 */ 2405 struct rte_flow_action_raw_encap { 2406 uint8_t *data; /**< Encapsulation data. */ 2407 uint8_t *preserve; /**< Bit-mask of @p data to preserve on output. */ 2408 size_t size; /**< Size of @p data and @p preserve. */ 2409 }; 2410 2411 /** 2412 * @warning 2413 * @b EXPERIMENTAL: this structure may change without prior notice 2414 * 2415 * RTE_FLOW_ACTION_TYPE_RAW_DECAP 2416 * 2417 * Raw tunnel end-point decapsulation data definition. 2418 * 2419 * The data holds the headers definitions to be removed from the packet. 2420 * The data must start with ETH header up to the tunnel item header itself. 2421 * When used right before RAW_DECAP (for encapsulating L3 tunnel type for 2422 * example MPLSoGRE) the data will just hold layer 2 header. 2423 * 2424 * size holds the number of bytes in @p data. 2425 */ 2426 struct rte_flow_action_raw_decap { 2427 uint8_t *data; /**< Encapsulation data. */ 2428 size_t size; /**< Size of @p data and @p preserve. */ 2429 }; 2430 2431 /** 2432 * @warning 2433 * @b EXPERIMENTAL: this structure may change without prior notice 2434 * 2435 * RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC 2436 * RTE_FLOW_ACTION_TYPE_SET_IPV4_DST 2437 * 2438 * Allows modification of IPv4 source (RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC) 2439 * and destination address (RTE_FLOW_ACTION_TYPE_SET_IPV4_DST) in the 2440 * specified outermost IPv4 header. 2441 */ 2442 struct rte_flow_action_set_ipv4 { 2443 rte_be32_t ipv4_addr; 2444 }; 2445 2446 /** 2447 * @warning 2448 * @b EXPERIMENTAL: this structure may change without prior notice 2449 * 2450 * RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC 2451 * RTE_FLOW_ACTION_TYPE_SET_IPV6_DST 2452 * 2453 * Allows modification of IPv6 source (RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC) 2454 * and destination address (RTE_FLOW_ACTION_TYPE_SET_IPV6_DST) in the 2455 * specified outermost IPv6 header. 2456 */ 2457 struct rte_flow_action_set_ipv6 { 2458 uint8_t ipv6_addr[16]; 2459 }; 2460 2461 /** 2462 * @warning 2463 * @b EXPERIMENTAL: this structure may change without prior notice 2464 * 2465 * RTE_FLOW_ACTION_TYPE_SET_TP_SRC 2466 * RTE_FLOW_ACTION_TYPE_SET_TP_DST 2467 * 2468 * Allows modification of source (RTE_FLOW_ACTION_TYPE_SET_TP_SRC) 2469 * and destination (RTE_FLOW_ACTION_TYPE_SET_TP_DST) port numbers 2470 * in the specified outermost TCP/UDP header. 2471 */ 2472 struct rte_flow_action_set_tp { 2473 rte_be16_t port; 2474 }; 2475 2476 /** 2477 * RTE_FLOW_ACTION_TYPE_SET_TTL 2478 * 2479 * Set the TTL value directly for IPv4 or IPv6 2480 */ 2481 struct rte_flow_action_set_ttl { 2482 uint8_t ttl_value; 2483 }; 2484 2485 /** 2486 * RTE_FLOW_ACTION_TYPE_SET_MAC 2487 * 2488 * Set MAC address from the matched flow 2489 */ 2490 struct rte_flow_action_set_mac { 2491 uint8_t mac_addr[RTE_ETHER_ADDR_LEN]; 2492 }; 2493 2494 /** 2495 * @warning 2496 * @b EXPERIMENTAL: this structure may change without prior notice 2497 * 2498 * RTE_FLOW_ACTION_TYPE_SET_TAG 2499 * 2500 * Set a tag which is a transient data used during flow matching. This is not 2501 * delivered to application. Multiple tags are supported by specifying index. 2502 */ 2503 struct rte_flow_action_set_tag { 2504 uint32_t data; 2505 uint32_t mask; 2506 uint8_t index; 2507 }; 2508 2509 /** 2510 * @warning 2511 * @b EXPERIMENTAL: this structure may change without prior notice 2512 * 2513 * RTE_FLOW_ACTION_TYPE_SET_META 2514 * 2515 * Set metadata. Metadata set by mbuf metadata dynamic field with 2516 * PKT_TX_DYNF_DATA flag on egress will be overridden by this action. On 2517 * ingress, the metadata will be carried by mbuf metadata dynamic field 2518 * with PKT_RX_DYNF_METADATA flag if set. The dynamic mbuf field must be 2519 * registered in advance by rte_flow_dynf_metadata_register(). 2520 * 2521 * Altering partial bits is supported with mask. For bits which have never 2522 * been set, unpredictable value will be seen depending on driver 2523 * implementation. For loopback/hairpin packet, metadata set on Rx/Tx may 2524 * or may not be propagated to the other path depending on HW capability. 2525 * 2526 * RTE_FLOW_ITEM_TYPE_META matches metadata. 2527 */ 2528 struct rte_flow_action_set_meta { 2529 uint32_t data; 2530 uint32_t mask; 2531 }; 2532 2533 /* Mbuf dynamic field offset for metadata. */ 2534 extern int32_t rte_flow_dynf_metadata_offs; 2535 2536 /* Mbuf dynamic field flag mask for metadata. */ 2537 extern uint64_t rte_flow_dynf_metadata_mask; 2538 2539 /* Mbuf dynamic field pointer for metadata. */ 2540 #define RTE_FLOW_DYNF_METADATA(m) \ 2541 RTE_MBUF_DYNFIELD((m), rte_flow_dynf_metadata_offs, uint32_t *) 2542 2543 /* Mbuf dynamic flags for metadata. */ 2544 #define PKT_RX_DYNF_METADATA (rte_flow_dynf_metadata_mask) 2545 #define PKT_TX_DYNF_METADATA (rte_flow_dynf_metadata_mask) 2546 2547 __rte_experimental 2548 static inline uint32_t 2549 rte_flow_dynf_metadata_get(struct rte_mbuf *m) 2550 { 2551 return *RTE_FLOW_DYNF_METADATA(m); 2552 } 2553 2554 __rte_experimental 2555 static inline void 2556 rte_flow_dynf_metadata_set(struct rte_mbuf *m, uint32_t v) 2557 { 2558 *RTE_FLOW_DYNF_METADATA(m) = v; 2559 } 2560 2561 /* 2562 * Definition of a single action. 2563 * 2564 * A list of actions is terminated by a END action. 2565 * 2566 * For simple actions without a configuration object, conf remains NULL. 2567 */ 2568 struct rte_flow_action { 2569 enum rte_flow_action_type type; /**< Action type. */ 2570 const void *conf; /**< Pointer to action configuration object. */ 2571 }; 2572 2573 /** 2574 * Opaque type returned after successfully creating a flow. 2575 * 2576 * This handle can be used to manage and query the related flow (e.g. to 2577 * destroy it or retrieve counters). 2578 */ 2579 struct rte_flow; 2580 2581 /** 2582 * Verbose error types. 2583 * 2584 * Most of them provide the type of the object referenced by struct 2585 * rte_flow_error.cause. 2586 */ 2587 enum rte_flow_error_type { 2588 RTE_FLOW_ERROR_TYPE_NONE, /**< No error. */ 2589 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, /**< Cause unspecified. */ 2590 RTE_FLOW_ERROR_TYPE_HANDLE, /**< Flow rule (handle). */ 2591 RTE_FLOW_ERROR_TYPE_ATTR_GROUP, /**< Group field. */ 2592 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY, /**< Priority field. */ 2593 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS, /**< Ingress field. */ 2594 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, /**< Egress field. */ 2595 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER, /**< Transfer field. */ 2596 RTE_FLOW_ERROR_TYPE_ATTR, /**< Attributes structure. */ 2597 RTE_FLOW_ERROR_TYPE_ITEM_NUM, /**< Pattern length. */ 2598 RTE_FLOW_ERROR_TYPE_ITEM_SPEC, /**< Item specification. */ 2599 RTE_FLOW_ERROR_TYPE_ITEM_LAST, /**< Item specification range. */ 2600 RTE_FLOW_ERROR_TYPE_ITEM_MASK, /**< Item specification mask. */ 2601 RTE_FLOW_ERROR_TYPE_ITEM, /**< Specific pattern item. */ 2602 RTE_FLOW_ERROR_TYPE_ACTION_NUM, /**< Number of actions. */ 2603 RTE_FLOW_ERROR_TYPE_ACTION_CONF, /**< Action configuration. */ 2604 RTE_FLOW_ERROR_TYPE_ACTION, /**< Specific action. */ 2605 }; 2606 2607 /** 2608 * Verbose error structure definition. 2609 * 2610 * This object is normally allocated by applications and set by PMDs, the 2611 * message points to a constant string which does not need to be freed by 2612 * the application, however its pointer can be considered valid only as long 2613 * as its associated DPDK port remains configured. Closing the underlying 2614 * device or unloading the PMD invalidates it. 2615 * 2616 * Both cause and message may be NULL regardless of the error type. 2617 */ 2618 struct rte_flow_error { 2619 enum rte_flow_error_type type; /**< Cause field and error types. */ 2620 const void *cause; /**< Object responsible for the error. */ 2621 const char *message; /**< Human-readable error message. */ 2622 }; 2623 2624 /** 2625 * Complete flow rule description. 2626 * 2627 * This object type is used when converting a flow rule description. 2628 * 2629 * @see RTE_FLOW_CONV_OP_RULE 2630 * @see rte_flow_conv() 2631 */ 2632 RTE_STD_C11 2633 struct rte_flow_conv_rule { 2634 union { 2635 const struct rte_flow_attr *attr_ro; /**< RO attributes. */ 2636 struct rte_flow_attr *attr; /**< Attributes. */ 2637 }; 2638 union { 2639 const struct rte_flow_item *pattern_ro; /**< RO pattern. */ 2640 struct rte_flow_item *pattern; /**< Pattern items. */ 2641 }; 2642 union { 2643 const struct rte_flow_action *actions_ro; /**< RO actions. */ 2644 struct rte_flow_action *actions; /**< List of actions. */ 2645 }; 2646 }; 2647 2648 /** 2649 * Conversion operations for flow API objects. 2650 * 2651 * @see rte_flow_conv() 2652 */ 2653 enum rte_flow_conv_op { 2654 /** 2655 * No operation to perform. 2656 * 2657 * rte_flow_conv() simply returns 0. 2658 */ 2659 RTE_FLOW_CONV_OP_NONE, 2660 2661 /** 2662 * Convert attributes structure. 2663 * 2664 * This is a basic copy of an attributes structure. 2665 * 2666 * - @p src type: 2667 * @code const struct rte_flow_attr * @endcode 2668 * - @p dst type: 2669 * @code struct rte_flow_attr * @endcode 2670 */ 2671 RTE_FLOW_CONV_OP_ATTR, 2672 2673 /** 2674 * Convert a single item. 2675 * 2676 * Duplicates @p spec, @p last and @p mask but not outside objects. 2677 * 2678 * - @p src type: 2679 * @code const struct rte_flow_item * @endcode 2680 * - @p dst type: 2681 * @code struct rte_flow_item * @endcode 2682 */ 2683 RTE_FLOW_CONV_OP_ITEM, 2684 2685 /** 2686 * Convert a single action. 2687 * 2688 * Duplicates @p conf but not outside objects. 2689 * 2690 * - @p src type: 2691 * @code const struct rte_flow_action * @endcode 2692 * - @p dst type: 2693 * @code struct rte_flow_action * @endcode 2694 */ 2695 RTE_FLOW_CONV_OP_ACTION, 2696 2697 /** 2698 * Convert an entire pattern. 2699 * 2700 * Duplicates all pattern items at once with the same constraints as 2701 * RTE_FLOW_CONV_OP_ITEM. 2702 * 2703 * - @p src type: 2704 * @code const struct rte_flow_item * @endcode 2705 * - @p dst type: 2706 * @code struct rte_flow_item * @endcode 2707 */ 2708 RTE_FLOW_CONV_OP_PATTERN, 2709 2710 /** 2711 * Convert a list of actions. 2712 * 2713 * Duplicates the entire list of actions at once with the same 2714 * constraints as RTE_FLOW_CONV_OP_ACTION. 2715 * 2716 * - @p src type: 2717 * @code const struct rte_flow_action * @endcode 2718 * - @p dst type: 2719 * @code struct rte_flow_action * @endcode 2720 */ 2721 RTE_FLOW_CONV_OP_ACTIONS, 2722 2723 /** 2724 * Convert a complete flow rule description. 2725 * 2726 * Comprises attributes, pattern and actions together at once with 2727 * the usual constraints. 2728 * 2729 * - @p src type: 2730 * @code const struct rte_flow_conv_rule * @endcode 2731 * - @p dst type: 2732 * @code struct rte_flow_conv_rule * @endcode 2733 */ 2734 RTE_FLOW_CONV_OP_RULE, 2735 2736 /** 2737 * Convert item type to its name string. 2738 * 2739 * Writes a NUL-terminated string to @p dst. Like snprintf(), the 2740 * returned value excludes the terminator which is always written 2741 * nonetheless. 2742 * 2743 * - @p src type: 2744 * @code (const void *)enum rte_flow_item_type @endcode 2745 * - @p dst type: 2746 * @code char * @endcode 2747 **/ 2748 RTE_FLOW_CONV_OP_ITEM_NAME, 2749 2750 /** 2751 * Convert action type to its name string. 2752 * 2753 * Writes a NUL-terminated string to @p dst. Like snprintf(), the 2754 * returned value excludes the terminator which is always written 2755 * nonetheless. 2756 * 2757 * - @p src type: 2758 * @code (const void *)enum rte_flow_action_type @endcode 2759 * - @p dst type: 2760 * @code char * @endcode 2761 **/ 2762 RTE_FLOW_CONV_OP_ACTION_NAME, 2763 2764 /** 2765 * Convert item type to pointer to item name. 2766 * 2767 * Retrieves item name pointer from its type. The string itself is 2768 * not copied; instead, a unique pointer to an internal static 2769 * constant storage is written to @p dst. 2770 * 2771 * - @p src type: 2772 * @code (const void *)enum rte_flow_item_type @endcode 2773 * - @p dst type: 2774 * @code const char ** @endcode 2775 */ 2776 RTE_FLOW_CONV_OP_ITEM_NAME_PTR, 2777 2778 /** 2779 * Convert action type to pointer to action name. 2780 * 2781 * Retrieves action name pointer from its type. The string itself is 2782 * not copied; instead, a unique pointer to an internal static 2783 * constant storage is written to @p dst. 2784 * 2785 * - @p src type: 2786 * @code (const void *)enum rte_flow_action_type @endcode 2787 * - @p dst type: 2788 * @code const char ** @endcode 2789 */ 2790 RTE_FLOW_CONV_OP_ACTION_NAME_PTR, 2791 }; 2792 2793 /** 2794 * Check if mbuf dynamic field for metadata is registered. 2795 * 2796 * @return 2797 * True if registered, false otherwise. 2798 */ 2799 __rte_experimental 2800 static inline int 2801 rte_flow_dynf_metadata_avail(void) 2802 { 2803 return !!rte_flow_dynf_metadata_mask; 2804 } 2805 2806 /** 2807 * Register mbuf dynamic field and flag for metadata. 2808 * 2809 * This function must be called prior to use SET_META action in order to 2810 * register the dynamic mbuf field. Otherwise, the data cannot be delivered to 2811 * application. 2812 * 2813 * @return 2814 * 0 on success, a negative errno value otherwise and rte_errno is set. 2815 */ 2816 __rte_experimental 2817 int 2818 rte_flow_dynf_metadata_register(void); 2819 2820 /** 2821 * Check whether a flow rule can be created on a given port. 2822 * 2823 * The flow rule is validated for correctness and whether it could be accepted 2824 * by the device given sufficient resources. The rule is checked against the 2825 * current device mode and queue configuration. The flow rule may also 2826 * optionally be validated against existing flow rules and device resources. 2827 * This function has no effect on the target device. 2828 * 2829 * The returned value is guaranteed to remain valid only as long as no 2830 * successful calls to rte_flow_create() or rte_flow_destroy() are made in 2831 * the meantime and no device parameter affecting flow rules in any way are 2832 * modified, due to possible collisions or resource limitations (although in 2833 * such cases EINVAL should not be returned). 2834 * 2835 * @param port_id 2836 * Port identifier of Ethernet device. 2837 * @param[in] attr 2838 * Flow rule attributes. 2839 * @param[in] pattern 2840 * Pattern specification (list terminated by the END pattern item). 2841 * @param[in] actions 2842 * Associated actions (list terminated by the END action). 2843 * @param[out] error 2844 * Perform verbose error reporting if not NULL. PMDs initialize this 2845 * structure in case of error only. 2846 * 2847 * @return 2848 * 0 if flow rule is valid and can be created. A negative errno value 2849 * otherwise (rte_errno is also set), the following errors are defined: 2850 * 2851 * -ENOSYS: underlying device does not support this functionality. 2852 * 2853 * -EIO: underlying device is removed. 2854 * 2855 * -EINVAL: unknown or invalid rule specification. 2856 * 2857 * -ENOTSUP: valid but unsupported rule specification (e.g. partial 2858 * bit-masks are unsupported). 2859 * 2860 * -EEXIST: collision with an existing rule. Only returned if device 2861 * supports flow rule collision checking and there was a flow rule 2862 * collision. Not receiving this return code is no guarantee that creating 2863 * the rule will not fail due to a collision. 2864 * 2865 * -ENOMEM: not enough memory to execute the function, or if the device 2866 * supports resource validation, resource limitation on the device. 2867 * 2868 * -EBUSY: action cannot be performed due to busy device resources, may 2869 * succeed if the affected queues or even the entire port are in a stopped 2870 * state (see rte_eth_dev_rx_queue_stop() and rte_eth_dev_stop()). 2871 */ 2872 int 2873 rte_flow_validate(uint16_t port_id, 2874 const struct rte_flow_attr *attr, 2875 const struct rte_flow_item pattern[], 2876 const struct rte_flow_action actions[], 2877 struct rte_flow_error *error); 2878 2879 /** 2880 * Create a flow rule on a given port. 2881 * 2882 * @param port_id 2883 * Port identifier of Ethernet device. 2884 * @param[in] attr 2885 * Flow rule attributes. 2886 * @param[in] pattern 2887 * Pattern specification (list terminated by the END pattern item). 2888 * @param[in] actions 2889 * Associated actions (list terminated by the END action). 2890 * @param[out] error 2891 * Perform verbose error reporting if not NULL. PMDs initialize this 2892 * structure in case of error only. 2893 * 2894 * @return 2895 * A valid handle in case of success, NULL otherwise and rte_errno is set 2896 * to the positive version of one of the error codes defined for 2897 * rte_flow_validate(). 2898 */ 2899 struct rte_flow * 2900 rte_flow_create(uint16_t port_id, 2901 const struct rte_flow_attr *attr, 2902 const struct rte_flow_item pattern[], 2903 const struct rte_flow_action actions[], 2904 struct rte_flow_error *error); 2905 2906 /** 2907 * Destroy a flow rule on a given port. 2908 * 2909 * Failure to destroy a flow rule handle may occur when other flow rules 2910 * depend on it, and destroying it would result in an inconsistent state. 2911 * 2912 * This function is only guaranteed to succeed if handles are destroyed in 2913 * reverse order of their creation. 2914 * 2915 * @param port_id 2916 * Port identifier of Ethernet device. 2917 * @param flow 2918 * Flow rule handle to destroy. 2919 * @param[out] error 2920 * Perform verbose error reporting if not NULL. PMDs initialize this 2921 * structure in case of error only. 2922 * 2923 * @return 2924 * 0 on success, a negative errno value otherwise and rte_errno is set. 2925 */ 2926 int 2927 rte_flow_destroy(uint16_t port_id, 2928 struct rte_flow *flow, 2929 struct rte_flow_error *error); 2930 2931 /** 2932 * Destroy all flow rules associated with a port. 2933 * 2934 * In the unlikely event of failure, handles are still considered destroyed 2935 * and no longer valid but the port must be assumed to be in an inconsistent 2936 * state. 2937 * 2938 * @param port_id 2939 * Port identifier of Ethernet device. 2940 * @param[out] error 2941 * Perform verbose error reporting if not NULL. PMDs initialize this 2942 * structure in case of error only. 2943 * 2944 * @return 2945 * 0 on success, a negative errno value otherwise and rte_errno is set. 2946 */ 2947 int 2948 rte_flow_flush(uint16_t port_id, 2949 struct rte_flow_error *error); 2950 2951 /** 2952 * Query an existing flow rule. 2953 * 2954 * This function allows retrieving flow-specific data such as counters. 2955 * Data is gathered by special actions which must be present in the flow 2956 * rule definition. 2957 * 2958 * \see RTE_FLOW_ACTION_TYPE_COUNT 2959 * 2960 * @param port_id 2961 * Port identifier of Ethernet device. 2962 * @param flow 2963 * Flow rule handle to query. 2964 * @param action 2965 * Action definition as defined in original flow rule. 2966 * @param[in, out] data 2967 * Pointer to storage for the associated query data type. 2968 * @param[out] error 2969 * Perform verbose error reporting if not NULL. PMDs initialize this 2970 * structure in case of error only. 2971 * 2972 * @return 2973 * 0 on success, a negative errno value otherwise and rte_errno is set. 2974 */ 2975 int 2976 rte_flow_query(uint16_t port_id, 2977 struct rte_flow *flow, 2978 const struct rte_flow_action *action, 2979 void *data, 2980 struct rte_flow_error *error); 2981 2982 /** 2983 * Restrict ingress traffic to the defined flow rules. 2984 * 2985 * Isolated mode guarantees that all ingress traffic comes from defined flow 2986 * rules only (current and future). 2987 * 2988 * Besides making ingress more deterministic, it allows PMDs to safely reuse 2989 * resources otherwise assigned to handle the remaining traffic, such as 2990 * global RSS configuration settings, VLAN filters, MAC address entries, 2991 * legacy filter API rules and so on in order to expand the set of possible 2992 * flow rule types. 2993 * 2994 * Calling this function as soon as possible after device initialization, 2995 * ideally before the first call to rte_eth_dev_configure(), is recommended 2996 * to avoid possible failures due to conflicting settings. 2997 * 2998 * Once effective, leaving isolated mode may not be possible depending on 2999 * PMD implementation. 3000 * 3001 * Additionally, the following functionality has no effect on the underlying 3002 * port and may return errors such as ENOTSUP ("not supported"): 3003 * 3004 * - Toggling promiscuous mode. 3005 * - Toggling allmulticast mode. 3006 * - Configuring MAC addresses. 3007 * - Configuring multicast addresses. 3008 * - Configuring VLAN filters. 3009 * - Configuring Rx filters through the legacy API (e.g. FDIR). 3010 * - Configuring global RSS settings. 3011 * 3012 * @param port_id 3013 * Port identifier of Ethernet device. 3014 * @param set 3015 * Nonzero to enter isolated mode, attempt to leave it otherwise. 3016 * @param[out] error 3017 * Perform verbose error reporting if not NULL. PMDs initialize this 3018 * structure in case of error only. 3019 * 3020 * @return 3021 * 0 on success, a negative errno value otherwise and rte_errno is set. 3022 */ 3023 int 3024 rte_flow_isolate(uint16_t port_id, int set, struct rte_flow_error *error); 3025 3026 /** 3027 * Initialize flow error structure. 3028 * 3029 * @param[out] error 3030 * Pointer to flow error structure (may be NULL). 3031 * @param code 3032 * Related error code (rte_errno). 3033 * @param type 3034 * Cause field and error types. 3035 * @param cause 3036 * Object responsible for the error. 3037 * @param message 3038 * Human-readable error message. 3039 * 3040 * @return 3041 * Negative error code (errno value) and rte_errno is set. 3042 */ 3043 int 3044 rte_flow_error_set(struct rte_flow_error *error, 3045 int code, 3046 enum rte_flow_error_type type, 3047 const void *cause, 3048 const char *message); 3049 3050 /** 3051 * @deprecated 3052 * @see rte_flow_copy() 3053 */ 3054 struct rte_flow_desc { 3055 size_t size; /**< Allocated space including data[]. */ 3056 struct rte_flow_attr attr; /**< Attributes. */ 3057 struct rte_flow_item *items; /**< Items. */ 3058 struct rte_flow_action *actions; /**< Actions. */ 3059 uint8_t data[]; /**< Storage for items/actions. */ 3060 }; 3061 3062 /** 3063 * @deprecated 3064 * Copy an rte_flow rule description. 3065 * 3066 * This interface is kept for compatibility with older applications but is 3067 * implemented as a wrapper to rte_flow_conv(). It is deprecated due to its 3068 * lack of flexibility and reliance on a type unusable with C++ programs 3069 * (struct rte_flow_desc). 3070 * 3071 * @param[in] fd 3072 * Flow rule description. 3073 * @param[in] len 3074 * Total size of allocated data for the flow description. 3075 * @param[in] attr 3076 * Flow rule attributes. 3077 * @param[in] items 3078 * Pattern specification (list terminated by the END pattern item). 3079 * @param[in] actions 3080 * Associated actions (list terminated by the END action). 3081 * 3082 * @return 3083 * If len is greater or equal to the size of the flow, the total size of the 3084 * flow description and its data. 3085 * If len is lower than the size of the flow, the number of bytes that would 3086 * have been written to desc had it been sufficient. Nothing is written. 3087 */ 3088 __rte_deprecated 3089 size_t 3090 rte_flow_copy(struct rte_flow_desc *fd, size_t len, 3091 const struct rte_flow_attr *attr, 3092 const struct rte_flow_item *items, 3093 const struct rte_flow_action *actions); 3094 3095 /** 3096 * Flow object conversion helper. 3097 * 3098 * This function performs conversion of various flow API objects to a 3099 * pre-allocated destination buffer. See enum rte_flow_conv_op for possible 3100 * operations and details about each of them. 3101 * 3102 * Since destination buffer must be large enough, it works in a manner 3103 * reminiscent of snprintf(): 3104 * 3105 * - If @p size is 0, @p dst may be a NULL pointer, otherwise @p dst must be 3106 * non-NULL. 3107 * - If positive, the returned value represents the number of bytes needed 3108 * to store the conversion of @p src to @p dst according to @p op 3109 * regardless of the @p size parameter. 3110 * - Since no more than @p size bytes can be written to @p dst, output is 3111 * truncated and may be inconsistent when the returned value is larger 3112 * than that. 3113 * - In case of conversion error, a negative error code is returned and 3114 * @p dst contents are unspecified. 3115 * 3116 * @param op 3117 * Operation to perform, related to the object type of @p dst. 3118 * @param[out] dst 3119 * Destination buffer address. Must be suitably aligned by the caller. 3120 * @param size 3121 * Destination buffer size in bytes. 3122 * @param[in] src 3123 * Source object to copy. Depending on @p op, its type may differ from 3124 * that of @p dst. 3125 * @param[out] error 3126 * Perform verbose error reporting if not NULL. Initialized in case of 3127 * error only. 3128 * 3129 * @return 3130 * The number of bytes required to convert @p src to @p dst on success, a 3131 * negative errno value otherwise and rte_errno is set. 3132 * 3133 * @see rte_flow_conv_op 3134 */ 3135 __rte_experimental 3136 int 3137 rte_flow_conv(enum rte_flow_conv_op op, 3138 void *dst, 3139 size_t size, 3140 const void *src, 3141 struct rte_flow_error *error); 3142 3143 #ifdef __cplusplus 3144 } 3145 #endif 3146 3147 #endif /* RTE_FLOW_H_ */ 3148