1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2016 6WIND S.A.
3 * Copyright 2016 Mellanox Technologies, Ltd
13 #include <arpa/inet.h>
14 #include <sys/socket.h>
16 #include <rte_string_fns.h>
17 #include <rte_common.h>
18 #include <rte_ethdev.h>
19 #include <rte_byteorder.h>
20 #include <cmdline_parse.h>
21 #include <cmdline_parse_etheraddr.h>
22 #include <cmdline_parse_string.h>
23 #include <cmdline_parse_num.h>
25 #include <rte_hexdump.h>
26 #include <rte_vxlan.h>
30 /** Parser token indices. */
54 /* Top-level command. */
56 /* Sub-leve commands. */
63 /* Top-level command. */
65 /* Sub-level commands. */
76 /* Destroy arguments. */
79 /* Query arguments. */
85 /* Destroy aged flow arguments. */
88 /* Validate/create arguments. */
95 /* Validate/create pattern. */
132 ITEM_VLAN_INNER_TYPE,
166 ITEM_E_TAG_GRP_ECID_B,
175 ITEM_GRE_C_RSVD0_VER,
193 ITEM_ARP_ETH_IPV4_SHA,
194 ITEM_ARP_ETH_IPV4_SPA,
195 ITEM_ARP_ETH_IPV4_THA,
196 ITEM_ARP_ETH_IPV4_TPA,
198 ITEM_IPV6_EXT_NEXT_HDR,
203 ITEM_ICMP6_ND_NS_TARGET_ADDR,
205 ITEM_ICMP6_ND_NA_TARGET_ADDR,
207 ITEM_ICMP6_ND_OPT_TYPE,
208 ITEM_ICMP6_ND_OPT_SLA_ETH,
209 ITEM_ICMP6_ND_OPT_SLA_ETH_SLA,
210 ITEM_ICMP6_ND_OPT_TLA_ETH,
211 ITEM_ICMP6_ND_OPT_TLA_ETH_TLA,
224 ITEM_HIGIG2_CLASSIFICATION,
230 ITEM_L2TPV3OIP_SESSION_ID,
240 ITEM_ECPRI_COMMON_TYPE,
241 ITEM_ECPRI_COMMON_TYPE_IQ_DATA,
242 ITEM_ECPRI_COMMON_TYPE_RTC_CTRL,
243 ITEM_ECPRI_COMMON_TYPE_DLY_MSR,
244 ITEM_ECPRI_MSG_IQ_DATA_PCID,
245 ITEM_ECPRI_MSG_RTC_CTRL_RTCID,
246 ITEM_ECPRI_MSG_DLY_MSR_MSRID,
248 /* Validate/create actions. */
268 ACTION_RSS_FUNC_DEFAULT,
269 ACTION_RSS_FUNC_TOEPLITZ,
270 ACTION_RSS_FUNC_SIMPLE_XOR,
271 ACTION_RSS_FUNC_SYMMETRIC_TOEPLITZ,
283 ACTION_PHY_PORT_ORIGINAL,
284 ACTION_PHY_PORT_INDEX,
286 ACTION_PORT_ID_ORIGINAL,
290 ACTION_OF_SET_MPLS_TTL,
291 ACTION_OF_SET_MPLS_TTL_MPLS_TTL,
292 ACTION_OF_DEC_MPLS_TTL,
293 ACTION_OF_SET_NW_TTL,
294 ACTION_OF_SET_NW_TTL_NW_TTL,
295 ACTION_OF_DEC_NW_TTL,
296 ACTION_OF_COPY_TTL_OUT,
297 ACTION_OF_COPY_TTL_IN,
300 ACTION_OF_PUSH_VLAN_ETHERTYPE,
301 ACTION_OF_SET_VLAN_VID,
302 ACTION_OF_SET_VLAN_VID_VLAN_VID,
303 ACTION_OF_SET_VLAN_PCP,
304 ACTION_OF_SET_VLAN_PCP_VLAN_PCP,
306 ACTION_OF_POP_MPLS_ETHERTYPE,
308 ACTION_OF_PUSH_MPLS_ETHERTYPE,
315 ACTION_MPLSOGRE_ENCAP,
316 ACTION_MPLSOGRE_DECAP,
317 ACTION_MPLSOUDP_ENCAP,
318 ACTION_MPLSOUDP_DECAP,
320 ACTION_SET_IPV4_SRC_IPV4_SRC,
322 ACTION_SET_IPV4_DST_IPV4_DST,
324 ACTION_SET_IPV6_SRC_IPV6_SRC,
326 ACTION_SET_IPV6_DST_IPV6_DST,
328 ACTION_SET_TP_SRC_TP_SRC,
330 ACTION_SET_TP_DST_TP_DST,
336 ACTION_SET_MAC_SRC_MAC_SRC,
338 ACTION_SET_MAC_DST_MAC_DST,
340 ACTION_INC_TCP_SEQ_VALUE,
342 ACTION_DEC_TCP_SEQ_VALUE,
344 ACTION_INC_TCP_ACK_VALUE,
346 ACTION_DEC_TCP_ACK_VALUE,
349 ACTION_RAW_ENCAP_INDEX,
350 ACTION_RAW_ENCAP_INDEX_VALUE,
351 ACTION_RAW_DECAP_INDEX,
352 ACTION_RAW_DECAP_INDEX_VALUE,
355 ACTION_SET_TAG_INDEX,
358 ACTION_SET_META_DATA,
359 ACTION_SET_META_MASK,
360 ACTION_SET_IPV4_DSCP,
361 ACTION_SET_IPV4_DSCP_VALUE,
362 ACTION_SET_IPV6_DSCP,
363 ACTION_SET_IPV6_DSCP_VALUE,
369 ACTION_SAMPLE_INDEX_VALUE,
372 /** Maximum size for pattern in struct rte_flow_item_raw. */
373 #define ITEM_RAW_PATTERN_SIZE 40
375 /** Storage size for struct rte_flow_item_raw including pattern. */
376 #define ITEM_RAW_SIZE \
377 (sizeof(struct rte_flow_item_raw) + ITEM_RAW_PATTERN_SIZE)
379 /** Maximum number of queue indices in struct rte_flow_action_rss. */
380 #define ACTION_RSS_QUEUE_NUM 128
382 /** Storage for struct rte_flow_action_rss including external data. */
383 struct action_rss_data {
384 struct rte_flow_action_rss conf;
385 uint8_t key[RSS_HASH_KEY_LENGTH];
386 uint16_t queue[ACTION_RSS_QUEUE_NUM];
389 /** Maximum data size in struct rte_flow_action_raw_encap. */
390 #define ACTION_RAW_ENCAP_MAX_DATA 128
391 #define RAW_ENCAP_CONFS_MAX_NUM 8
393 /** Storage for struct rte_flow_action_raw_encap. */
394 struct raw_encap_conf {
395 uint8_t data[ACTION_RAW_ENCAP_MAX_DATA];
396 uint8_t preserve[ACTION_RAW_ENCAP_MAX_DATA];
400 struct raw_encap_conf raw_encap_confs[RAW_ENCAP_CONFS_MAX_NUM];
402 /** Storage for struct rte_flow_action_raw_encap including external data. */
403 struct action_raw_encap_data {
404 struct rte_flow_action_raw_encap conf;
405 uint8_t data[ACTION_RAW_ENCAP_MAX_DATA];
406 uint8_t preserve[ACTION_RAW_ENCAP_MAX_DATA];
410 /** Storage for struct rte_flow_action_raw_decap. */
411 struct raw_decap_conf {
412 uint8_t data[ACTION_RAW_ENCAP_MAX_DATA];
416 struct raw_decap_conf raw_decap_confs[RAW_ENCAP_CONFS_MAX_NUM];
418 /** Storage for struct rte_flow_action_raw_decap including external data. */
419 struct action_raw_decap_data {
420 struct rte_flow_action_raw_decap conf;
421 uint8_t data[ACTION_RAW_ENCAP_MAX_DATA];
425 struct vxlan_encap_conf vxlan_encap_conf = {
429 .vni = "\x00\x00\x00",
431 .udp_dst = RTE_BE16(RTE_VXLAN_DEFAULT_PORT),
432 .ipv4_src = RTE_IPV4(127, 0, 0, 1),
433 .ipv4_dst = RTE_IPV4(255, 255, 255, 255),
434 .ipv6_src = "\x00\x00\x00\x00\x00\x00\x00\x00"
435 "\x00\x00\x00\x00\x00\x00\x00\x01",
436 .ipv6_dst = "\x00\x00\x00\x00\x00\x00\x00\x00"
437 "\x00\x00\x00\x00\x00\x00\x11\x11",
441 .eth_src = "\x00\x00\x00\x00\x00\x00",
442 .eth_dst = "\xff\xff\xff\xff\xff\xff",
445 /** Maximum number of items in struct rte_flow_action_vxlan_encap. */
446 #define ACTION_VXLAN_ENCAP_ITEMS_NUM 6
448 /** Storage for struct rte_flow_action_vxlan_encap including external data. */
449 struct action_vxlan_encap_data {
450 struct rte_flow_action_vxlan_encap conf;
451 struct rte_flow_item items[ACTION_VXLAN_ENCAP_ITEMS_NUM];
452 struct rte_flow_item_eth item_eth;
453 struct rte_flow_item_vlan item_vlan;
455 struct rte_flow_item_ipv4 item_ipv4;
456 struct rte_flow_item_ipv6 item_ipv6;
458 struct rte_flow_item_udp item_udp;
459 struct rte_flow_item_vxlan item_vxlan;
462 struct nvgre_encap_conf nvgre_encap_conf = {
465 .tni = "\x00\x00\x00",
466 .ipv4_src = RTE_IPV4(127, 0, 0, 1),
467 .ipv4_dst = RTE_IPV4(255, 255, 255, 255),
468 .ipv6_src = "\x00\x00\x00\x00\x00\x00\x00\x00"
469 "\x00\x00\x00\x00\x00\x00\x00\x01",
470 .ipv6_dst = "\x00\x00\x00\x00\x00\x00\x00\x00"
471 "\x00\x00\x00\x00\x00\x00\x11\x11",
473 .eth_src = "\x00\x00\x00\x00\x00\x00",
474 .eth_dst = "\xff\xff\xff\xff\xff\xff",
477 /** Maximum number of items in struct rte_flow_action_nvgre_encap. */
478 #define ACTION_NVGRE_ENCAP_ITEMS_NUM 5
480 /** Storage for struct rte_flow_action_nvgre_encap including external data. */
481 struct action_nvgre_encap_data {
482 struct rte_flow_action_nvgre_encap conf;
483 struct rte_flow_item items[ACTION_NVGRE_ENCAP_ITEMS_NUM];
484 struct rte_flow_item_eth item_eth;
485 struct rte_flow_item_vlan item_vlan;
487 struct rte_flow_item_ipv4 item_ipv4;
488 struct rte_flow_item_ipv6 item_ipv6;
490 struct rte_flow_item_nvgre item_nvgre;
493 struct l2_encap_conf l2_encap_conf;
495 struct l2_decap_conf l2_decap_conf;
497 struct mplsogre_encap_conf mplsogre_encap_conf;
499 struct mplsogre_decap_conf mplsogre_decap_conf;
501 struct mplsoudp_encap_conf mplsoudp_encap_conf;
503 struct mplsoudp_decap_conf mplsoudp_decap_conf;
505 #define ACTION_SAMPLE_ACTIONS_NUM 10
506 #define RAW_SAMPLE_CONFS_MAX_NUM 8
507 /** Storage for struct rte_flow_action_sample including external data. */
508 struct action_sample_data {
509 struct rte_flow_action_sample conf;
512 /** Storage for struct rte_flow_action_sample. */
513 struct raw_sample_conf {
514 struct rte_flow_action data[ACTION_SAMPLE_ACTIONS_NUM];
516 struct raw_sample_conf raw_sample_confs[RAW_SAMPLE_CONFS_MAX_NUM];
517 struct rte_flow_action_mark sample_mark[RAW_SAMPLE_CONFS_MAX_NUM];
518 struct rte_flow_action_queue sample_queue[RAW_SAMPLE_CONFS_MAX_NUM];
519 struct rte_flow_action_count sample_count[RAW_SAMPLE_CONFS_MAX_NUM];
521 /** Maximum number of subsequent tokens and arguments on the stack. */
522 #define CTX_STACK_SIZE 16
524 /** Parser context. */
526 /** Stack of subsequent token lists to process. */
527 const enum index *next[CTX_STACK_SIZE];
528 /** Arguments for stacked tokens. */
529 const void *args[CTX_STACK_SIZE];
530 enum index curr; /**< Current token index. */
531 enum index prev; /**< Index of the last token seen. */
532 int next_num; /**< Number of entries in next[]. */
533 int args_num; /**< Number of entries in args[]. */
534 uint32_t eol:1; /**< EOL has been detected. */
535 uint32_t last:1; /**< No more arguments. */
536 portid_t port; /**< Current port ID (for completions). */
537 uint32_t objdata; /**< Object-specific data. */
538 void *object; /**< Address of current object for relative offsets. */
539 void *objmask; /**< Object a full mask must be written to. */
542 /** Token argument. */
544 uint32_t hton:1; /**< Use network byte ordering. */
545 uint32_t sign:1; /**< Value is signed. */
546 uint32_t bounded:1; /**< Value is bounded. */
547 uintmax_t min; /**< Minimum value if bounded. */
548 uintmax_t max; /**< Maximum value if bounded. */
549 uint32_t offset; /**< Relative offset from ctx->object. */
550 uint32_t size; /**< Field size. */
551 const uint8_t *mask; /**< Bit-mask to use instead of offset/size. */
554 /** Parser token definition. */
556 /** Type displayed during completion (defaults to "TOKEN"). */
558 /** Help displayed during completion (defaults to token name). */
560 /** Private data used by parser functions. */
563 * Lists of subsequent tokens to push on the stack. Each call to the
564 * parser consumes the last entry of that stack.
566 const enum index *const *next;
567 /** Arguments stack for subsequent tokens that need them. */
568 const struct arg *const *args;
570 * Token-processing callback, returns -1 in case of error, the
571 * length of the matched string otherwise. If NULL, attempts to
572 * match the token name.
574 * If buf is not NULL, the result should be stored in it according
575 * to context. An error is returned if not large enough.
577 int (*call)(struct context *ctx, const struct token *token,
578 const char *str, unsigned int len,
579 void *buf, unsigned int size);
581 * Callback that provides possible values for this token, used for
582 * completion. Returns -1 in case of error, the number of possible
583 * values otherwise. If NULL, the token name is used.
585 * If buf is not NULL, entry index ent is written to buf and the
586 * full length of the entry is returned (same behavior as
589 int (*comp)(struct context *ctx, const struct token *token,
590 unsigned int ent, char *buf, unsigned int size);
591 /** Mandatory token name, no default value. */
595 /** Static initializer for the next field. */
596 #define NEXT(...) (const enum index *const []){ __VA_ARGS__, NULL, }
598 /** Static initializer for a NEXT() entry. */
599 #define NEXT_ENTRY(...) (const enum index []){ __VA_ARGS__, ZERO, }
601 /** Static initializer for the args field. */
602 #define ARGS(...) (const struct arg *const []){ __VA_ARGS__, NULL, }
604 /** Static initializer for ARGS() to target a field. */
605 #define ARGS_ENTRY(s, f) \
606 (&(const struct arg){ \
607 .offset = offsetof(s, f), \
608 .size = sizeof(((s *)0)->f), \
611 /** Static initializer for ARGS() to target a bit-field. */
612 #define ARGS_ENTRY_BF(s, f, b) \
613 (&(const struct arg){ \
615 .mask = (const void *)&(const s){ .f = (1 << (b)) - 1 }, \
618 /** Static initializer for ARGS() to target an arbitrary bit-mask. */
619 #define ARGS_ENTRY_MASK(s, f, m) \
620 (&(const struct arg){ \
621 .offset = offsetof(s, f), \
622 .size = sizeof(((s *)0)->f), \
623 .mask = (const void *)(m), \
626 /** Same as ARGS_ENTRY_MASK() using network byte ordering for the value. */
627 #define ARGS_ENTRY_MASK_HTON(s, f, m) \
628 (&(const struct arg){ \
630 .offset = offsetof(s, f), \
631 .size = sizeof(((s *)0)->f), \
632 .mask = (const void *)(m), \
635 /** Static initializer for ARGS() to target a pointer. */
636 #define ARGS_ENTRY_PTR(s, f) \
637 (&(const struct arg){ \
638 .size = sizeof(*((s *)0)->f), \
641 /** Static initializer for ARGS() with arbitrary offset and size. */
642 #define ARGS_ENTRY_ARB(o, s) \
643 (&(const struct arg){ \
648 /** Same as ARGS_ENTRY_ARB() with bounded values. */
649 #define ARGS_ENTRY_ARB_BOUNDED(o, s, i, a) \
650 (&(const struct arg){ \
658 /** Same as ARGS_ENTRY() using network byte ordering. */
659 #define ARGS_ENTRY_HTON(s, f) \
660 (&(const struct arg){ \
662 .offset = offsetof(s, f), \
663 .size = sizeof(((s *)0)->f), \
666 /** Same as ARGS_ENTRY_HTON() for a single argument, without structure. */
667 #define ARG_ENTRY_HTON(s) \
668 (&(const struct arg){ \
674 /** Parser output buffer layout expected by cmd_flow_parsed(). */
676 enum index command; /**< Flow command. */
677 portid_t port; /**< Affected port ID. */
680 struct rte_flow_attr attr;
681 struct rte_flow_item *pattern;
682 struct rte_flow_action *actions;
686 } vc; /**< Validate/create arguments. */
690 } destroy; /**< Destroy arguments. */
693 } dump; /**< Dump arguments. */
696 struct rte_flow_action action;
697 } query; /**< Query arguments. */
701 } list; /**< List arguments. */
704 } isolate; /**< Isolated mode arguments. */
707 } aged; /**< Aged arguments. */
708 } args; /**< Command arguments. */
711 /** Private data for pattern items. */
712 struct parse_item_priv {
713 enum rte_flow_item_type type; /**< Item type. */
714 uint32_t size; /**< Size of item specification structure. */
717 #define PRIV_ITEM(t, s) \
718 (&(const struct parse_item_priv){ \
719 .type = RTE_FLOW_ITEM_TYPE_ ## t, \
723 /** Private data for actions. */
724 struct parse_action_priv {
725 enum rte_flow_action_type type; /**< Action type. */
726 uint32_t size; /**< Size of action configuration structure. */
729 #define PRIV_ACTION(t, s) \
730 (&(const struct parse_action_priv){ \
731 .type = RTE_FLOW_ACTION_TYPE_ ## t, \
735 static const enum index next_vc_attr[] = {
745 static const enum index next_destroy_attr[] = {
751 static const enum index next_dump_attr[] = {
757 static const enum index next_list_attr[] = {
763 static const enum index next_aged_attr[] = {
769 static const enum index item_param[] = {
778 static const enum index next_item[] = {
814 ITEM_ICMP6_ND_OPT_SLA_ETH,
815 ITEM_ICMP6_ND_OPT_TLA_ETH,
833 static const enum index item_fuzzy[] = {
839 static const enum index item_any[] = {
845 static const enum index item_vf[] = {
851 static const enum index item_phy_port[] = {
857 static const enum index item_port_id[] = {
863 static const enum index item_mark[] = {
869 static const enum index item_raw[] = {
879 static const enum index item_eth[] = {
887 static const enum index item_vlan[] = {
892 ITEM_VLAN_INNER_TYPE,
897 static const enum index item_ipv4[] = {
907 static const enum index item_ipv6[] = {
918 static const enum index item_icmp[] = {
927 static const enum index item_udp[] = {
934 static const enum index item_tcp[] = {
942 static const enum index item_sctp[] = {
951 static const enum index item_vxlan[] = {
957 static const enum index item_e_tag[] = {
958 ITEM_E_TAG_GRP_ECID_B,
963 static const enum index item_nvgre[] = {
969 static const enum index item_mpls[] = {
977 static const enum index item_gre[] = {
979 ITEM_GRE_C_RSVD0_VER,
987 static const enum index item_gre_key[] = {
993 static const enum index item_gtp[] = {
1001 static const enum index item_geneve[] = {
1008 static const enum index item_vxlan_gpe[] = {
1014 static const enum index item_arp_eth_ipv4[] = {
1015 ITEM_ARP_ETH_IPV4_SHA,
1016 ITEM_ARP_ETH_IPV4_SPA,
1017 ITEM_ARP_ETH_IPV4_THA,
1018 ITEM_ARP_ETH_IPV4_TPA,
1023 static const enum index item_ipv6_ext[] = {
1024 ITEM_IPV6_EXT_NEXT_HDR,
1029 static const enum index item_icmp6[] = {
1036 static const enum index item_icmp6_nd_ns[] = {
1037 ITEM_ICMP6_ND_NS_TARGET_ADDR,
1042 static const enum index item_icmp6_nd_na[] = {
1043 ITEM_ICMP6_ND_NA_TARGET_ADDR,
1048 static const enum index item_icmp6_nd_opt[] = {
1049 ITEM_ICMP6_ND_OPT_TYPE,
1054 static const enum index item_icmp6_nd_opt_sla_eth[] = {
1055 ITEM_ICMP6_ND_OPT_SLA_ETH_SLA,
1060 static const enum index item_icmp6_nd_opt_tla_eth[] = {
1061 ITEM_ICMP6_ND_OPT_TLA_ETH_TLA,
1066 static const enum index item_meta[] = {
1072 static const enum index item_gtp_psc[] = {
1079 static const enum index item_pppoed[] = {
1085 static const enum index item_pppoes[] = {
1091 static const enum index item_pppoe_proto_id[] = {
1096 static const enum index item_higig2[] = {
1097 ITEM_HIGIG2_CLASSIFICATION,
1103 static const enum index item_esp[] = {
1109 static const enum index item_ah[] = {
1115 static const enum index item_pfcp[] = {
1122 static const enum index next_set_raw[] = {
1128 static const enum index item_tag[] = {
1135 static const enum index item_l2tpv3oip[] = {
1136 ITEM_L2TPV3OIP_SESSION_ID,
1141 static const enum index item_ecpri[] = {
1147 static const enum index item_ecpri_common[] = {
1148 ITEM_ECPRI_COMMON_TYPE,
1152 static const enum index item_ecpri_common_type[] = {
1153 ITEM_ECPRI_COMMON_TYPE_IQ_DATA,
1154 ITEM_ECPRI_COMMON_TYPE_RTC_CTRL,
1155 ITEM_ECPRI_COMMON_TYPE_DLY_MSR,
1159 static const enum index next_action[] = {
1175 ACTION_OF_SET_MPLS_TTL,
1176 ACTION_OF_DEC_MPLS_TTL,
1177 ACTION_OF_SET_NW_TTL,
1178 ACTION_OF_DEC_NW_TTL,
1179 ACTION_OF_COPY_TTL_OUT,
1180 ACTION_OF_COPY_TTL_IN,
1182 ACTION_OF_PUSH_VLAN,
1183 ACTION_OF_SET_VLAN_VID,
1184 ACTION_OF_SET_VLAN_PCP,
1186 ACTION_OF_PUSH_MPLS,
1193 ACTION_MPLSOGRE_ENCAP,
1194 ACTION_MPLSOGRE_DECAP,
1195 ACTION_MPLSOUDP_ENCAP,
1196 ACTION_MPLSOUDP_DECAP,
1197 ACTION_SET_IPV4_SRC,
1198 ACTION_SET_IPV4_DST,
1199 ACTION_SET_IPV6_SRC,
1200 ACTION_SET_IPV6_DST,
1216 ACTION_SET_IPV4_DSCP,
1217 ACTION_SET_IPV6_DSCP,
1223 static const enum index action_mark[] = {
1229 static const enum index action_queue[] = {
1235 static const enum index action_count[] = {
1237 ACTION_COUNT_SHARED,
1242 static const enum index action_rss[] = {
1253 static const enum index action_vf[] = {
1260 static const enum index action_phy_port[] = {
1261 ACTION_PHY_PORT_ORIGINAL,
1262 ACTION_PHY_PORT_INDEX,
1267 static const enum index action_port_id[] = {
1268 ACTION_PORT_ID_ORIGINAL,
1274 static const enum index action_meter[] = {
1280 static const enum index action_of_set_mpls_ttl[] = {
1281 ACTION_OF_SET_MPLS_TTL_MPLS_TTL,
1286 static const enum index action_of_set_nw_ttl[] = {
1287 ACTION_OF_SET_NW_TTL_NW_TTL,
1292 static const enum index action_of_push_vlan[] = {
1293 ACTION_OF_PUSH_VLAN_ETHERTYPE,
1298 static const enum index action_of_set_vlan_vid[] = {
1299 ACTION_OF_SET_VLAN_VID_VLAN_VID,
1304 static const enum index action_of_set_vlan_pcp[] = {
1305 ACTION_OF_SET_VLAN_PCP_VLAN_PCP,
1310 static const enum index action_of_pop_mpls[] = {
1311 ACTION_OF_POP_MPLS_ETHERTYPE,
1316 static const enum index action_of_push_mpls[] = {
1317 ACTION_OF_PUSH_MPLS_ETHERTYPE,
1322 static const enum index action_set_ipv4_src[] = {
1323 ACTION_SET_IPV4_SRC_IPV4_SRC,
1328 static const enum index action_set_mac_src[] = {
1329 ACTION_SET_MAC_SRC_MAC_SRC,
1334 static const enum index action_set_ipv4_dst[] = {
1335 ACTION_SET_IPV4_DST_IPV4_DST,
1340 static const enum index action_set_ipv6_src[] = {
1341 ACTION_SET_IPV6_SRC_IPV6_SRC,
1346 static const enum index action_set_ipv6_dst[] = {
1347 ACTION_SET_IPV6_DST_IPV6_DST,
1352 static const enum index action_set_tp_src[] = {
1353 ACTION_SET_TP_SRC_TP_SRC,
1358 static const enum index action_set_tp_dst[] = {
1359 ACTION_SET_TP_DST_TP_DST,
1364 static const enum index action_set_ttl[] = {
1370 static const enum index action_jump[] = {
1376 static const enum index action_set_mac_dst[] = {
1377 ACTION_SET_MAC_DST_MAC_DST,
1382 static const enum index action_inc_tcp_seq[] = {
1383 ACTION_INC_TCP_SEQ_VALUE,
1388 static const enum index action_dec_tcp_seq[] = {
1389 ACTION_DEC_TCP_SEQ_VALUE,
1394 static const enum index action_inc_tcp_ack[] = {
1395 ACTION_INC_TCP_ACK_VALUE,
1400 static const enum index action_dec_tcp_ack[] = {
1401 ACTION_DEC_TCP_ACK_VALUE,
1406 static const enum index action_raw_encap[] = {
1407 ACTION_RAW_ENCAP_INDEX,
1412 static const enum index action_raw_decap[] = {
1413 ACTION_RAW_DECAP_INDEX,
1418 static const enum index action_set_tag[] = {
1419 ACTION_SET_TAG_DATA,
1420 ACTION_SET_TAG_INDEX,
1421 ACTION_SET_TAG_MASK,
1426 static const enum index action_set_meta[] = {
1427 ACTION_SET_META_DATA,
1428 ACTION_SET_META_MASK,
1433 static const enum index action_set_ipv4_dscp[] = {
1434 ACTION_SET_IPV4_DSCP_VALUE,
1439 static const enum index action_set_ipv6_dscp[] = {
1440 ACTION_SET_IPV6_DSCP_VALUE,
1445 static const enum index action_age[] = {
1452 static const enum index action_sample[] = {
1454 ACTION_SAMPLE_RATIO,
1455 ACTION_SAMPLE_INDEX,
1460 static const enum index next_action_sample[] = {
1468 static int parse_set_raw_encap_decap(struct context *, const struct token *,
1469 const char *, unsigned int,
1470 void *, unsigned int);
1471 static int parse_set_sample_action(struct context *, const struct token *,
1472 const char *, unsigned int,
1473 void *, unsigned int);
1474 static int parse_set_init(struct context *, const struct token *,
1475 const char *, unsigned int,
1476 void *, unsigned int);
1477 static int parse_init(struct context *, const struct token *,
1478 const char *, unsigned int,
1479 void *, unsigned int);
1480 static int parse_vc(struct context *, const struct token *,
1481 const char *, unsigned int,
1482 void *, unsigned int);
1483 static int parse_vc_spec(struct context *, const struct token *,
1484 const char *, unsigned int, void *, unsigned int);
1485 static int parse_vc_conf(struct context *, const struct token *,
1486 const char *, unsigned int, void *, unsigned int);
1487 static int parse_vc_item_ecpri_type(struct context *, const struct token *,
1488 const char *, unsigned int,
1489 void *, unsigned int);
1490 static int parse_vc_action_rss(struct context *, const struct token *,
1491 const char *, unsigned int, void *,
1493 static int parse_vc_action_rss_func(struct context *, const struct token *,
1494 const char *, unsigned int, void *,
1496 static int parse_vc_action_rss_type(struct context *, const struct token *,
1497 const char *, unsigned int, void *,
1499 static int parse_vc_action_rss_queue(struct context *, const struct token *,
1500 const char *, unsigned int, void *,
1502 static int parse_vc_action_vxlan_encap(struct context *, const struct token *,
1503 const char *, unsigned int, void *,
1505 static int parse_vc_action_nvgre_encap(struct context *, const struct token *,
1506 const char *, unsigned int, void *,
1508 static int parse_vc_action_l2_encap(struct context *, const struct token *,
1509 const char *, unsigned int, void *,
1511 static int parse_vc_action_l2_decap(struct context *, const struct token *,
1512 const char *, unsigned int, void *,
1514 static int parse_vc_action_mplsogre_encap(struct context *,
1515 const struct token *, const char *,
1516 unsigned int, void *, unsigned int);
1517 static int parse_vc_action_mplsogre_decap(struct context *,
1518 const struct token *, const char *,
1519 unsigned int, void *, unsigned int);
1520 static int parse_vc_action_mplsoudp_encap(struct context *,
1521 const struct token *, const char *,
1522 unsigned int, void *, unsigned int);
1523 static int parse_vc_action_mplsoudp_decap(struct context *,
1524 const struct token *, const char *,
1525 unsigned int, void *, unsigned int);
1526 static int parse_vc_action_raw_encap(struct context *,
1527 const struct token *, const char *,
1528 unsigned int, void *, unsigned int);
1529 static int parse_vc_action_raw_decap(struct context *,
1530 const struct token *, const char *,
1531 unsigned int, void *, unsigned int);
1532 static int parse_vc_action_raw_encap_index(struct context *,
1533 const struct token *, const char *,
1534 unsigned int, void *, unsigned int);
1535 static int parse_vc_action_raw_decap_index(struct context *,
1536 const struct token *, const char *,
1537 unsigned int, void *, unsigned int);
1538 static int parse_vc_action_set_meta(struct context *ctx,
1539 const struct token *token, const char *str,
1540 unsigned int len, void *buf,
1542 static int parse_vc_action_sample(struct context *ctx,
1543 const struct token *token, const char *str,
1544 unsigned int len, void *buf,
1547 parse_vc_action_sample_index(struct context *ctx, const struct token *token,
1548 const char *str, unsigned int len, void *buf,
1550 static int parse_destroy(struct context *, const struct token *,
1551 const char *, unsigned int,
1552 void *, unsigned int);
1553 static int parse_flush(struct context *, const struct token *,
1554 const char *, unsigned int,
1555 void *, unsigned int);
1556 static int parse_dump(struct context *, const struct token *,
1557 const char *, unsigned int,
1558 void *, unsigned int);
1559 static int parse_query(struct context *, const struct token *,
1560 const char *, unsigned int,
1561 void *, unsigned int);
1562 static int parse_action(struct context *, const struct token *,
1563 const char *, unsigned int,
1564 void *, unsigned int);
1565 static int parse_list(struct context *, const struct token *,
1566 const char *, unsigned int,
1567 void *, unsigned int);
1568 static int parse_aged(struct context *, const struct token *,
1569 const char *, unsigned int,
1570 void *, unsigned int);
1571 static int parse_isolate(struct context *, const struct token *,
1572 const char *, unsigned int,
1573 void *, unsigned int);
1574 static int parse_int(struct context *, const struct token *,
1575 const char *, unsigned int,
1576 void *, unsigned int);
1577 static int parse_prefix(struct context *, const struct token *,
1578 const char *, unsigned int,
1579 void *, unsigned int);
1580 static int parse_boolean(struct context *, const struct token *,
1581 const char *, unsigned int,
1582 void *, unsigned int);
1583 static int parse_string(struct context *, const struct token *,
1584 const char *, unsigned int,
1585 void *, unsigned int);
1586 static int parse_hex(struct context *ctx, const struct token *token,
1587 const char *str, unsigned int len,
1588 void *buf, unsigned int size);
1589 static int parse_string0(struct context *, const struct token *,
1590 const char *, unsigned int,
1591 void *, unsigned int);
1592 static int parse_mac_addr(struct context *, const struct token *,
1593 const char *, unsigned int,
1594 void *, unsigned int);
1595 static int parse_ipv4_addr(struct context *, const struct token *,
1596 const char *, unsigned int,
1597 void *, unsigned int);
1598 static int parse_ipv6_addr(struct context *, const struct token *,
1599 const char *, unsigned int,
1600 void *, unsigned int);
1601 static int parse_port(struct context *, const struct token *,
1602 const char *, unsigned int,
1603 void *, unsigned int);
1604 static int comp_none(struct context *, const struct token *,
1605 unsigned int, char *, unsigned int);
1606 static int comp_boolean(struct context *, const struct token *,
1607 unsigned int, char *, unsigned int);
1608 static int comp_action(struct context *, const struct token *,
1609 unsigned int, char *, unsigned int);
1610 static int comp_port(struct context *, const struct token *,
1611 unsigned int, char *, unsigned int);
1612 static int comp_rule_id(struct context *, const struct token *,
1613 unsigned int, char *, unsigned int);
1614 static int comp_vc_action_rss_type(struct context *, const struct token *,
1615 unsigned int, char *, unsigned int);
1616 static int comp_vc_action_rss_queue(struct context *, const struct token *,
1617 unsigned int, char *, unsigned int);
1618 static int comp_set_raw_index(struct context *, const struct token *,
1619 unsigned int, char *, unsigned int);
1620 static int comp_set_sample_index(struct context *, const struct token *,
1621 unsigned int, char *, unsigned int);
1623 /** Token definitions. */
1624 static const struct token token_list[] = {
1625 /* Special tokens. */
1628 .help = "null entry, abused as the entry point",
1629 .next = NEXT(NEXT_ENTRY(FLOW)),
1634 .help = "command may end here",
1637 .name = "START_SET",
1638 .help = "null entry, abused as the entry point for set",
1639 .next = NEXT(NEXT_ENTRY(SET)),
1644 .help = "set command may end here",
1646 /* Common tokens. */
1650 .help = "integer value",
1655 .name = "{unsigned}",
1657 .help = "unsigned integer value",
1664 .help = "prefix length for bit-mask",
1665 .call = parse_prefix,
1669 .name = "{boolean}",
1671 .help = "any boolean value",
1672 .call = parse_boolean,
1673 .comp = comp_boolean,
1678 .help = "fixed string",
1679 .call = parse_string,
1685 .help = "fixed string",
1689 .name = "{file path}",
1691 .help = "file path",
1692 .call = parse_string0,
1696 .name = "{MAC address}",
1698 .help = "standard MAC address notation",
1699 .call = parse_mac_addr,
1703 .name = "{IPv4 address}",
1704 .type = "IPV4 ADDRESS",
1705 .help = "standard IPv4 address notation",
1706 .call = parse_ipv4_addr,
1710 .name = "{IPv6 address}",
1711 .type = "IPV6 ADDRESS",
1712 .help = "standard IPv6 address notation",
1713 .call = parse_ipv6_addr,
1717 .name = "{rule id}",
1719 .help = "rule identifier",
1721 .comp = comp_rule_id,
1724 .name = "{port_id}",
1726 .help = "port identifier",
1731 .name = "{group_id}",
1733 .help = "group identifier",
1737 [PRIORITY_LEVEL] = {
1740 .help = "priority level",
1744 /* Top-level command. */
1747 .type = "{command} {port_id} [{arg} [...]]",
1748 .help = "manage ingress/egress flow rules",
1749 .next = NEXT(NEXT_ENTRY
1761 /* Sub-level commands. */
1764 .help = "check whether a flow rule can be created",
1765 .next = NEXT(next_vc_attr, NEXT_ENTRY(PORT_ID)),
1766 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1771 .help = "create a flow rule",
1772 .next = NEXT(next_vc_attr, NEXT_ENTRY(PORT_ID)),
1773 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1778 .help = "destroy specific flow rules",
1779 .next = NEXT(NEXT_ENTRY(DESTROY_RULE), NEXT_ENTRY(PORT_ID)),
1780 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1781 .call = parse_destroy,
1785 .help = "destroy all flow rules",
1786 .next = NEXT(NEXT_ENTRY(PORT_ID)),
1787 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1788 .call = parse_flush,
1792 .help = "dump all flow rules to file",
1793 .next = NEXT(next_dump_attr, NEXT_ENTRY(PORT_ID)),
1794 .args = ARGS(ARGS_ENTRY(struct buffer, args.dump.file),
1795 ARGS_ENTRY(struct buffer, port)),
1800 .help = "query an existing flow rule",
1801 .next = NEXT(NEXT_ENTRY(QUERY_ACTION),
1802 NEXT_ENTRY(RULE_ID),
1803 NEXT_ENTRY(PORT_ID)),
1804 .args = ARGS(ARGS_ENTRY(struct buffer, args.query.action.type),
1805 ARGS_ENTRY(struct buffer, args.query.rule),
1806 ARGS_ENTRY(struct buffer, port)),
1807 .call = parse_query,
1811 .help = "list existing flow rules",
1812 .next = NEXT(next_list_attr, NEXT_ENTRY(PORT_ID)),
1813 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1818 .help = "list and destroy aged flows",
1819 .next = NEXT(next_aged_attr, NEXT_ENTRY(PORT_ID)),
1820 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1825 .help = "restrict ingress traffic to the defined flow rules",
1826 .next = NEXT(NEXT_ENTRY(BOOLEAN),
1827 NEXT_ENTRY(PORT_ID)),
1828 .args = ARGS(ARGS_ENTRY(struct buffer, args.isolate.set),
1829 ARGS_ENTRY(struct buffer, port)),
1830 .call = parse_isolate,
1832 /* Destroy arguments. */
1835 .help = "specify a rule identifier",
1836 .next = NEXT(next_destroy_attr, NEXT_ENTRY(RULE_ID)),
1837 .args = ARGS(ARGS_ENTRY_PTR(struct buffer, args.destroy.rule)),
1838 .call = parse_destroy,
1840 /* Query arguments. */
1844 .help = "action to query, must be part of the rule",
1845 .call = parse_action,
1846 .comp = comp_action,
1848 /* List arguments. */
1851 .help = "specify a group",
1852 .next = NEXT(next_list_attr, NEXT_ENTRY(GROUP_ID)),
1853 .args = ARGS(ARGS_ENTRY_PTR(struct buffer, args.list.group)),
1858 .help = "specify aged flows need be destroyed",
1862 /* Validate/create attributes. */
1865 .help = "specify a group",
1866 .next = NEXT(next_vc_attr, NEXT_ENTRY(GROUP_ID)),
1867 .args = ARGS(ARGS_ENTRY(struct rte_flow_attr, group)),
1872 .help = "specify a priority level",
1873 .next = NEXT(next_vc_attr, NEXT_ENTRY(PRIORITY_LEVEL)),
1874 .args = ARGS(ARGS_ENTRY(struct rte_flow_attr, priority)),
1879 .help = "affect rule to ingress",
1880 .next = NEXT(next_vc_attr),
1885 .help = "affect rule to egress",
1886 .next = NEXT(next_vc_attr),
1891 .help = "apply rule directly to endpoints found in pattern",
1892 .next = NEXT(next_vc_attr),
1895 /* Validate/create pattern. */
1898 .help = "submit a list of pattern items",
1899 .next = NEXT(next_item),
1904 .help = "match value perfectly (with full bit-mask)",
1905 .call = parse_vc_spec,
1907 [ITEM_PARAM_SPEC] = {
1909 .help = "match value according to configured bit-mask",
1910 .call = parse_vc_spec,
1912 [ITEM_PARAM_LAST] = {
1914 .help = "specify upper bound to establish a range",
1915 .call = parse_vc_spec,
1917 [ITEM_PARAM_MASK] = {
1919 .help = "specify bit-mask with relevant bits set to one",
1920 .call = parse_vc_spec,
1922 [ITEM_PARAM_PREFIX] = {
1924 .help = "generate bit-mask from a prefix length",
1925 .call = parse_vc_spec,
1929 .help = "specify next pattern item",
1930 .next = NEXT(next_item),
1934 .help = "end list of pattern items",
1935 .priv = PRIV_ITEM(END, 0),
1936 .next = NEXT(NEXT_ENTRY(ACTIONS)),
1941 .help = "no-op pattern item",
1942 .priv = PRIV_ITEM(VOID, 0),
1943 .next = NEXT(NEXT_ENTRY(ITEM_NEXT)),
1948 .help = "perform actions when pattern does not match",
1949 .priv = PRIV_ITEM(INVERT, 0),
1950 .next = NEXT(NEXT_ENTRY(ITEM_NEXT)),
1955 .help = "match any protocol for the current layer",
1956 .priv = PRIV_ITEM(ANY, sizeof(struct rte_flow_item_any)),
1957 .next = NEXT(item_any),
1962 .help = "number of layers covered",
1963 .next = NEXT(item_any, NEXT_ENTRY(UNSIGNED), item_param),
1964 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_any, num)),
1968 .help = "match traffic from/to the physical function",
1969 .priv = PRIV_ITEM(PF, 0),
1970 .next = NEXT(NEXT_ENTRY(ITEM_NEXT)),
1975 .help = "match traffic from/to a virtual function ID",
1976 .priv = PRIV_ITEM(VF, sizeof(struct rte_flow_item_vf)),
1977 .next = NEXT(item_vf),
1983 .next = NEXT(item_vf, NEXT_ENTRY(UNSIGNED), item_param),
1984 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_vf, id)),
1988 .help = "match traffic from/to a specific physical port",
1989 .priv = PRIV_ITEM(PHY_PORT,
1990 sizeof(struct rte_flow_item_phy_port)),
1991 .next = NEXT(item_phy_port),
1994 [ITEM_PHY_PORT_INDEX] = {
1996 .help = "physical port index",
1997 .next = NEXT(item_phy_port, NEXT_ENTRY(UNSIGNED), item_param),
1998 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_phy_port, index)),
2002 .help = "match traffic from/to a given DPDK port ID",
2003 .priv = PRIV_ITEM(PORT_ID,
2004 sizeof(struct rte_flow_item_port_id)),
2005 .next = NEXT(item_port_id),
2008 [ITEM_PORT_ID_ID] = {
2010 .help = "DPDK port ID",
2011 .next = NEXT(item_port_id, NEXT_ENTRY(UNSIGNED), item_param),
2012 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_port_id, id)),
2016 .help = "match traffic against value set in previously matched rule",
2017 .priv = PRIV_ITEM(MARK, sizeof(struct rte_flow_item_mark)),
2018 .next = NEXT(item_mark),
2023 .help = "Integer value to match against",
2024 .next = NEXT(item_mark, NEXT_ENTRY(UNSIGNED), item_param),
2025 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_mark, id)),
2029 .help = "match an arbitrary byte string",
2030 .priv = PRIV_ITEM(RAW, ITEM_RAW_SIZE),
2031 .next = NEXT(item_raw),
2034 [ITEM_RAW_RELATIVE] = {
2036 .help = "look for pattern after the previous item",
2037 .next = NEXT(item_raw, NEXT_ENTRY(BOOLEAN), item_param),
2038 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_item_raw,
2041 [ITEM_RAW_SEARCH] = {
2043 .help = "search pattern from offset (see also limit)",
2044 .next = NEXT(item_raw, NEXT_ENTRY(BOOLEAN), item_param),
2045 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_item_raw,
2048 [ITEM_RAW_OFFSET] = {
2050 .help = "absolute or relative offset for pattern",
2051 .next = NEXT(item_raw, NEXT_ENTRY(INTEGER), item_param),
2052 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_raw, offset)),
2054 [ITEM_RAW_LIMIT] = {
2056 .help = "search area limit for start of pattern",
2057 .next = NEXT(item_raw, NEXT_ENTRY(UNSIGNED), item_param),
2058 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_raw, limit)),
2060 [ITEM_RAW_PATTERN] = {
2062 .help = "byte string to look for",
2063 .next = NEXT(item_raw,
2065 NEXT_ENTRY(ITEM_PARAM_IS,
2068 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_raw, pattern),
2069 ARGS_ENTRY(struct rte_flow_item_raw, length),
2070 ARGS_ENTRY_ARB(sizeof(struct rte_flow_item_raw),
2071 ITEM_RAW_PATTERN_SIZE)),
2075 .help = "match Ethernet header",
2076 .priv = PRIV_ITEM(ETH, sizeof(struct rte_flow_item_eth)),
2077 .next = NEXT(item_eth),
2082 .help = "destination MAC",
2083 .next = NEXT(item_eth, NEXT_ENTRY(MAC_ADDR), item_param),
2084 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_eth, dst)),
2088 .help = "source MAC",
2089 .next = NEXT(item_eth, NEXT_ENTRY(MAC_ADDR), item_param),
2090 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_eth, src)),
2094 .help = "EtherType",
2095 .next = NEXT(item_eth, NEXT_ENTRY(UNSIGNED), item_param),
2096 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_eth, type)),
2100 .help = "match 802.1Q/ad VLAN tag",
2101 .priv = PRIV_ITEM(VLAN, sizeof(struct rte_flow_item_vlan)),
2102 .next = NEXT(item_vlan),
2107 .help = "tag control information",
2108 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
2109 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vlan, tci)),
2113 .help = "priority code point",
2114 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
2115 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_vlan,
2120 .help = "drop eligible indicator",
2121 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
2122 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_vlan,
2127 .help = "VLAN identifier",
2128 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
2129 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_vlan,
2132 [ITEM_VLAN_INNER_TYPE] = {
2133 .name = "inner_type",
2134 .help = "inner EtherType",
2135 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
2136 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vlan,
2141 .help = "match IPv4 header",
2142 .priv = PRIV_ITEM(IPV4, sizeof(struct rte_flow_item_ipv4)),
2143 .next = NEXT(item_ipv4),
2148 .help = "type of service",
2149 .next = NEXT(item_ipv4, NEXT_ENTRY(UNSIGNED), item_param),
2150 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
2151 hdr.type_of_service)),
2155 .help = "time to live",
2156 .next = NEXT(item_ipv4, NEXT_ENTRY(UNSIGNED), item_param),
2157 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
2160 [ITEM_IPV4_PROTO] = {
2162 .help = "next protocol ID",
2163 .next = NEXT(item_ipv4, NEXT_ENTRY(UNSIGNED), item_param),
2164 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
2165 hdr.next_proto_id)),
2169 .help = "source address",
2170 .next = NEXT(item_ipv4, NEXT_ENTRY(IPV4_ADDR), item_param),
2171 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
2176 .help = "destination address",
2177 .next = NEXT(item_ipv4, NEXT_ENTRY(IPV4_ADDR), item_param),
2178 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
2183 .help = "match IPv6 header",
2184 .priv = PRIV_ITEM(IPV6, sizeof(struct rte_flow_item_ipv6)),
2185 .next = NEXT(item_ipv6),
2190 .help = "traffic class",
2191 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
2192 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_ipv6,
2194 "\x0f\xf0\x00\x00")),
2196 [ITEM_IPV6_FLOW] = {
2198 .help = "flow label",
2199 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
2200 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_ipv6,
2202 "\x00\x0f\xff\xff")),
2204 [ITEM_IPV6_PROTO] = {
2206 .help = "protocol (next header)",
2207 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
2208 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
2213 .help = "hop limit",
2214 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
2215 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
2220 .help = "source address",
2221 .next = NEXT(item_ipv6, NEXT_ENTRY(IPV6_ADDR), item_param),
2222 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
2227 .help = "destination address",
2228 .next = NEXT(item_ipv6, NEXT_ENTRY(IPV6_ADDR), item_param),
2229 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
2234 .help = "match ICMP header",
2235 .priv = PRIV_ITEM(ICMP, sizeof(struct rte_flow_item_icmp)),
2236 .next = NEXT(item_icmp),
2239 [ITEM_ICMP_TYPE] = {
2241 .help = "ICMP packet type",
2242 .next = NEXT(item_icmp, NEXT_ENTRY(UNSIGNED), item_param),
2243 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp,
2246 [ITEM_ICMP_CODE] = {
2248 .help = "ICMP packet code",
2249 .next = NEXT(item_icmp, NEXT_ENTRY(UNSIGNED), item_param),
2250 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp,
2253 [ITEM_ICMP_IDENT] = {
2255 .help = "ICMP packet identifier",
2256 .next = NEXT(item_icmp, NEXT_ENTRY(UNSIGNED), item_param),
2257 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp,
2262 .help = "ICMP packet sequence number",
2263 .next = NEXT(item_icmp, NEXT_ENTRY(UNSIGNED), item_param),
2264 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp,
2269 .help = "match UDP header",
2270 .priv = PRIV_ITEM(UDP, sizeof(struct rte_flow_item_udp)),
2271 .next = NEXT(item_udp),
2276 .help = "UDP source port",
2277 .next = NEXT(item_udp, NEXT_ENTRY(UNSIGNED), item_param),
2278 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_udp,
2283 .help = "UDP destination port",
2284 .next = NEXT(item_udp, NEXT_ENTRY(UNSIGNED), item_param),
2285 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_udp,
2290 .help = "match TCP header",
2291 .priv = PRIV_ITEM(TCP, sizeof(struct rte_flow_item_tcp)),
2292 .next = NEXT(item_tcp),
2297 .help = "TCP source port",
2298 .next = NEXT(item_tcp, NEXT_ENTRY(UNSIGNED), item_param),
2299 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_tcp,
2304 .help = "TCP destination port",
2305 .next = NEXT(item_tcp, NEXT_ENTRY(UNSIGNED), item_param),
2306 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_tcp,
2309 [ITEM_TCP_FLAGS] = {
2311 .help = "TCP flags",
2312 .next = NEXT(item_tcp, NEXT_ENTRY(UNSIGNED), item_param),
2313 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_tcp,
2318 .help = "match SCTP header",
2319 .priv = PRIV_ITEM(SCTP, sizeof(struct rte_flow_item_sctp)),
2320 .next = NEXT(item_sctp),
2325 .help = "SCTP source port",
2326 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
2327 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
2332 .help = "SCTP destination port",
2333 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
2334 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
2339 .help = "validation tag",
2340 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
2341 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
2344 [ITEM_SCTP_CKSUM] = {
2347 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
2348 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
2353 .help = "match VXLAN header",
2354 .priv = PRIV_ITEM(VXLAN, sizeof(struct rte_flow_item_vxlan)),
2355 .next = NEXT(item_vxlan),
2358 [ITEM_VXLAN_VNI] = {
2360 .help = "VXLAN identifier",
2361 .next = NEXT(item_vxlan, NEXT_ENTRY(UNSIGNED), item_param),
2362 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vxlan, vni)),
2366 .help = "match E-Tag header",
2367 .priv = PRIV_ITEM(E_TAG, sizeof(struct rte_flow_item_e_tag)),
2368 .next = NEXT(item_e_tag),
2371 [ITEM_E_TAG_GRP_ECID_B] = {
2372 .name = "grp_ecid_b",
2373 .help = "GRP and E-CID base",
2374 .next = NEXT(item_e_tag, NEXT_ENTRY(UNSIGNED), item_param),
2375 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_e_tag,
2381 .help = "match NVGRE header",
2382 .priv = PRIV_ITEM(NVGRE, sizeof(struct rte_flow_item_nvgre)),
2383 .next = NEXT(item_nvgre),
2386 [ITEM_NVGRE_TNI] = {
2388 .help = "virtual subnet ID",
2389 .next = NEXT(item_nvgre, NEXT_ENTRY(UNSIGNED), item_param),
2390 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_nvgre, tni)),
2394 .help = "match MPLS header",
2395 .priv = PRIV_ITEM(MPLS, sizeof(struct rte_flow_item_mpls)),
2396 .next = NEXT(item_mpls),
2399 [ITEM_MPLS_LABEL] = {
2401 .help = "MPLS label",
2402 .next = NEXT(item_mpls, NEXT_ENTRY(UNSIGNED), item_param),
2403 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_mpls,
2409 .help = "MPLS Traffic Class",
2410 .next = NEXT(item_mpls, NEXT_ENTRY(UNSIGNED), item_param),
2411 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_mpls,
2417 .help = "MPLS Bottom-of-Stack",
2418 .next = NEXT(item_mpls, NEXT_ENTRY(UNSIGNED), item_param),
2419 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_mpls,
2425 .help = "match GRE header",
2426 .priv = PRIV_ITEM(GRE, sizeof(struct rte_flow_item_gre)),
2427 .next = NEXT(item_gre),
2430 [ITEM_GRE_PROTO] = {
2432 .help = "GRE protocol type",
2433 .next = NEXT(item_gre, NEXT_ENTRY(UNSIGNED), item_param),
2434 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gre,
2437 [ITEM_GRE_C_RSVD0_VER] = {
2438 .name = "c_rsvd0_ver",
2440 "checksum (1b), undefined (1b), key bit (1b),"
2441 " sequence number (1b), reserved 0 (9b),"
2443 .next = NEXT(item_gre, NEXT_ENTRY(UNSIGNED), item_param),
2444 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gre,
2447 [ITEM_GRE_C_BIT] = {
2449 .help = "checksum bit (C)",
2450 .next = NEXT(item_gre, NEXT_ENTRY(BOOLEAN), item_param),
2451 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_gre,
2453 "\x80\x00\x00\x00")),
2455 [ITEM_GRE_S_BIT] = {
2457 .help = "sequence number bit (S)",
2458 .next = NEXT(item_gre, NEXT_ENTRY(BOOLEAN), item_param),
2459 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_gre,
2461 "\x10\x00\x00\x00")),
2463 [ITEM_GRE_K_BIT] = {
2465 .help = "key bit (K)",
2466 .next = NEXT(item_gre, NEXT_ENTRY(BOOLEAN), item_param),
2467 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_gre,
2469 "\x20\x00\x00\x00")),
2473 .help = "fuzzy pattern match, expect faster than default",
2474 .priv = PRIV_ITEM(FUZZY,
2475 sizeof(struct rte_flow_item_fuzzy)),
2476 .next = NEXT(item_fuzzy),
2479 [ITEM_FUZZY_THRESH] = {
2481 .help = "match accuracy threshold",
2482 .next = NEXT(item_fuzzy, NEXT_ENTRY(UNSIGNED), item_param),
2483 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_fuzzy,
2488 .help = "match GTP header",
2489 .priv = PRIV_ITEM(GTP, sizeof(struct rte_flow_item_gtp)),
2490 .next = NEXT(item_gtp),
2493 [ITEM_GTP_FLAGS] = {
2494 .name = "v_pt_rsv_flags",
2495 .help = "GTP flags",
2496 .next = NEXT(item_gtp, NEXT_ENTRY(UNSIGNED), item_param),
2497 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_gtp,
2500 [ITEM_GTP_MSG_TYPE] = {
2502 .help = "GTP message type",
2503 .next = NEXT(item_gtp, NEXT_ENTRY(UNSIGNED), item_param),
2504 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_gtp, msg_type)),
2508 .help = "tunnel endpoint identifier",
2509 .next = NEXT(item_gtp, NEXT_ENTRY(UNSIGNED), item_param),
2510 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gtp, teid)),
2514 .help = "match GTP header",
2515 .priv = PRIV_ITEM(GTPC, sizeof(struct rte_flow_item_gtp)),
2516 .next = NEXT(item_gtp),
2521 .help = "match GTP header",
2522 .priv = PRIV_ITEM(GTPU, sizeof(struct rte_flow_item_gtp)),
2523 .next = NEXT(item_gtp),
2528 .help = "match GENEVE header",
2529 .priv = PRIV_ITEM(GENEVE, sizeof(struct rte_flow_item_geneve)),
2530 .next = NEXT(item_geneve),
2533 [ITEM_GENEVE_VNI] = {
2535 .help = "virtual network identifier",
2536 .next = NEXT(item_geneve, NEXT_ENTRY(UNSIGNED), item_param),
2537 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_geneve, vni)),
2539 [ITEM_GENEVE_PROTO] = {
2541 .help = "GENEVE protocol type",
2542 .next = NEXT(item_geneve, NEXT_ENTRY(UNSIGNED), item_param),
2543 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_geneve,
2546 [ITEM_VXLAN_GPE] = {
2547 .name = "vxlan-gpe",
2548 .help = "match VXLAN-GPE header",
2549 .priv = PRIV_ITEM(VXLAN_GPE,
2550 sizeof(struct rte_flow_item_vxlan_gpe)),
2551 .next = NEXT(item_vxlan_gpe),
2554 [ITEM_VXLAN_GPE_VNI] = {
2556 .help = "VXLAN-GPE identifier",
2557 .next = NEXT(item_vxlan_gpe, NEXT_ENTRY(UNSIGNED), item_param),
2558 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vxlan_gpe,
2561 [ITEM_ARP_ETH_IPV4] = {
2562 .name = "arp_eth_ipv4",
2563 .help = "match ARP header for Ethernet/IPv4",
2564 .priv = PRIV_ITEM(ARP_ETH_IPV4,
2565 sizeof(struct rte_flow_item_arp_eth_ipv4)),
2566 .next = NEXT(item_arp_eth_ipv4),
2569 [ITEM_ARP_ETH_IPV4_SHA] = {
2571 .help = "sender hardware address",
2572 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(MAC_ADDR),
2574 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
2577 [ITEM_ARP_ETH_IPV4_SPA] = {
2579 .help = "sender IPv4 address",
2580 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(IPV4_ADDR),
2582 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
2585 [ITEM_ARP_ETH_IPV4_THA] = {
2587 .help = "target hardware address",
2588 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(MAC_ADDR),
2590 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
2593 [ITEM_ARP_ETH_IPV4_TPA] = {
2595 .help = "target IPv4 address",
2596 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(IPV4_ADDR),
2598 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
2603 .help = "match presence of any IPv6 extension header",
2604 .priv = PRIV_ITEM(IPV6_EXT,
2605 sizeof(struct rte_flow_item_ipv6_ext)),
2606 .next = NEXT(item_ipv6_ext),
2609 [ITEM_IPV6_EXT_NEXT_HDR] = {
2611 .help = "next header",
2612 .next = NEXT(item_ipv6_ext, NEXT_ENTRY(UNSIGNED), item_param),
2613 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6_ext,
2618 .help = "match any ICMPv6 header",
2619 .priv = PRIV_ITEM(ICMP6, sizeof(struct rte_flow_item_icmp6)),
2620 .next = NEXT(item_icmp6),
2623 [ITEM_ICMP6_TYPE] = {
2625 .help = "ICMPv6 type",
2626 .next = NEXT(item_icmp6, NEXT_ENTRY(UNSIGNED), item_param),
2627 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6,
2630 [ITEM_ICMP6_CODE] = {
2632 .help = "ICMPv6 code",
2633 .next = NEXT(item_icmp6, NEXT_ENTRY(UNSIGNED), item_param),
2634 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6,
2637 [ITEM_ICMP6_ND_NS] = {
2638 .name = "icmp6_nd_ns",
2639 .help = "match ICMPv6 neighbor discovery solicitation",
2640 .priv = PRIV_ITEM(ICMP6_ND_NS,
2641 sizeof(struct rte_flow_item_icmp6_nd_ns)),
2642 .next = NEXT(item_icmp6_nd_ns),
2645 [ITEM_ICMP6_ND_NS_TARGET_ADDR] = {
2646 .name = "target_addr",
2647 .help = "target address",
2648 .next = NEXT(item_icmp6_nd_ns, NEXT_ENTRY(IPV6_ADDR),
2650 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6_nd_ns,
2653 [ITEM_ICMP6_ND_NA] = {
2654 .name = "icmp6_nd_na",
2655 .help = "match ICMPv6 neighbor discovery advertisement",
2656 .priv = PRIV_ITEM(ICMP6_ND_NA,
2657 sizeof(struct rte_flow_item_icmp6_nd_na)),
2658 .next = NEXT(item_icmp6_nd_na),
2661 [ITEM_ICMP6_ND_NA_TARGET_ADDR] = {
2662 .name = "target_addr",
2663 .help = "target address",
2664 .next = NEXT(item_icmp6_nd_na, NEXT_ENTRY(IPV6_ADDR),
2666 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6_nd_na,
2669 [ITEM_ICMP6_ND_OPT] = {
2670 .name = "icmp6_nd_opt",
2671 .help = "match presence of any ICMPv6 neighbor discovery"
2673 .priv = PRIV_ITEM(ICMP6_ND_OPT,
2674 sizeof(struct rte_flow_item_icmp6_nd_opt)),
2675 .next = NEXT(item_icmp6_nd_opt),
2678 [ITEM_ICMP6_ND_OPT_TYPE] = {
2680 .help = "ND option type",
2681 .next = NEXT(item_icmp6_nd_opt, NEXT_ENTRY(UNSIGNED),
2683 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6_nd_opt,
2686 [ITEM_ICMP6_ND_OPT_SLA_ETH] = {
2687 .name = "icmp6_nd_opt_sla_eth",
2688 .help = "match ICMPv6 neighbor discovery source Ethernet"
2689 " link-layer address option",
2691 (ICMP6_ND_OPT_SLA_ETH,
2692 sizeof(struct rte_flow_item_icmp6_nd_opt_sla_eth)),
2693 .next = NEXT(item_icmp6_nd_opt_sla_eth),
2696 [ITEM_ICMP6_ND_OPT_SLA_ETH_SLA] = {
2698 .help = "source Ethernet LLA",
2699 .next = NEXT(item_icmp6_nd_opt_sla_eth, NEXT_ENTRY(MAC_ADDR),
2701 .args = ARGS(ARGS_ENTRY_HTON
2702 (struct rte_flow_item_icmp6_nd_opt_sla_eth, sla)),
2704 [ITEM_ICMP6_ND_OPT_TLA_ETH] = {
2705 .name = "icmp6_nd_opt_tla_eth",
2706 .help = "match ICMPv6 neighbor discovery target Ethernet"
2707 " link-layer address option",
2709 (ICMP6_ND_OPT_TLA_ETH,
2710 sizeof(struct rte_flow_item_icmp6_nd_opt_tla_eth)),
2711 .next = NEXT(item_icmp6_nd_opt_tla_eth),
2714 [ITEM_ICMP6_ND_OPT_TLA_ETH_TLA] = {
2716 .help = "target Ethernet LLA",
2717 .next = NEXT(item_icmp6_nd_opt_tla_eth, NEXT_ENTRY(MAC_ADDR),
2719 .args = ARGS(ARGS_ENTRY_HTON
2720 (struct rte_flow_item_icmp6_nd_opt_tla_eth, tla)),
2724 .help = "match metadata header",
2725 .priv = PRIV_ITEM(META, sizeof(struct rte_flow_item_meta)),
2726 .next = NEXT(item_meta),
2729 [ITEM_META_DATA] = {
2731 .help = "metadata value",
2732 .next = NEXT(item_meta, NEXT_ENTRY(UNSIGNED), item_param),
2733 .args = ARGS(ARGS_ENTRY_MASK(struct rte_flow_item_meta,
2734 data, "\xff\xff\xff\xff")),
2738 .help = "match GRE key",
2739 .priv = PRIV_ITEM(GRE_KEY, sizeof(rte_be32_t)),
2740 .next = NEXT(item_gre_key),
2743 [ITEM_GRE_KEY_VALUE] = {
2745 .help = "key value",
2746 .next = NEXT(item_gre_key, NEXT_ENTRY(UNSIGNED), item_param),
2747 .args = ARGS(ARG_ENTRY_HTON(rte_be32_t)),
2751 .help = "match GTP extension header with type 0x85",
2752 .priv = PRIV_ITEM(GTP_PSC,
2753 sizeof(struct rte_flow_item_gtp_psc)),
2754 .next = NEXT(item_gtp_psc),
2757 [ITEM_GTP_PSC_QFI] = {
2759 .help = "QoS flow identifier",
2760 .next = NEXT(item_gtp_psc, NEXT_ENTRY(UNSIGNED), item_param),
2761 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gtp_psc,
2764 [ITEM_GTP_PSC_PDU_T] = {
2767 .next = NEXT(item_gtp_psc, NEXT_ENTRY(UNSIGNED), item_param),
2768 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gtp_psc,
2773 .help = "match PPPoE session header",
2774 .priv = PRIV_ITEM(PPPOES, sizeof(struct rte_flow_item_pppoe)),
2775 .next = NEXT(item_pppoes),
2780 .help = "match PPPoE discovery header",
2781 .priv = PRIV_ITEM(PPPOED, sizeof(struct rte_flow_item_pppoe)),
2782 .next = NEXT(item_pppoed),
2785 [ITEM_PPPOE_SEID] = {
2787 .help = "session identifier",
2788 .next = NEXT(item_pppoes, NEXT_ENTRY(UNSIGNED), item_param),
2789 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_pppoe,
2792 [ITEM_PPPOE_PROTO_ID] = {
2793 .name = "pppoe_proto_id",
2794 .help = "match PPPoE session protocol identifier",
2795 .priv = PRIV_ITEM(PPPOE_PROTO_ID,
2796 sizeof(struct rte_flow_item_pppoe_proto_id)),
2797 .next = NEXT(item_pppoe_proto_id, NEXT_ENTRY(UNSIGNED),
2799 .args = ARGS(ARGS_ENTRY_HTON
2800 (struct rte_flow_item_pppoe_proto_id, proto_id)),
2805 .help = "matches higig2 header",
2806 .priv = PRIV_ITEM(HIGIG2,
2807 sizeof(struct rte_flow_item_higig2_hdr)),
2808 .next = NEXT(item_higig2),
2811 [ITEM_HIGIG2_CLASSIFICATION] = {
2812 .name = "classification",
2813 .help = "matches classification of higig2 header",
2814 .next = NEXT(item_higig2, NEXT_ENTRY(UNSIGNED), item_param),
2815 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_higig2_hdr,
2816 hdr.ppt1.classification)),
2818 [ITEM_HIGIG2_VID] = {
2820 .help = "matches vid of higig2 header",
2821 .next = NEXT(item_higig2, NEXT_ENTRY(UNSIGNED), item_param),
2822 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_higig2_hdr,
2827 .help = "match tag value",
2828 .priv = PRIV_ITEM(TAG, sizeof(struct rte_flow_item_tag)),
2829 .next = NEXT(item_tag),
2834 .help = "tag value to match",
2835 .next = NEXT(item_tag, NEXT_ENTRY(UNSIGNED), item_param),
2836 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_tag, data)),
2838 [ITEM_TAG_INDEX] = {
2840 .help = "index of tag array to match",
2841 .next = NEXT(item_tag, NEXT_ENTRY(UNSIGNED),
2842 NEXT_ENTRY(ITEM_PARAM_IS)),
2843 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_tag, index)),
2845 [ITEM_L2TPV3OIP] = {
2846 .name = "l2tpv3oip",
2847 .help = "match L2TPv3 over IP header",
2848 .priv = PRIV_ITEM(L2TPV3OIP,
2849 sizeof(struct rte_flow_item_l2tpv3oip)),
2850 .next = NEXT(item_l2tpv3oip),
2853 [ITEM_L2TPV3OIP_SESSION_ID] = {
2854 .name = "session_id",
2855 .help = "session identifier",
2856 .next = NEXT(item_l2tpv3oip, NEXT_ENTRY(UNSIGNED), item_param),
2857 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_l2tpv3oip,
2862 .help = "match ESP header",
2863 .priv = PRIV_ITEM(ESP, sizeof(struct rte_flow_item_esp)),
2864 .next = NEXT(item_esp),
2869 .help = "security policy index",
2870 .next = NEXT(item_esp, NEXT_ENTRY(UNSIGNED), item_param),
2871 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_esp,
2876 .help = "match AH header",
2877 .priv = PRIV_ITEM(AH, sizeof(struct rte_flow_item_ah)),
2878 .next = NEXT(item_ah),
2883 .help = "security parameters index",
2884 .next = NEXT(item_ah, NEXT_ENTRY(UNSIGNED), item_param),
2885 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ah, spi)),
2889 .help = "match pfcp header",
2890 .priv = PRIV_ITEM(PFCP, sizeof(struct rte_flow_item_pfcp)),
2891 .next = NEXT(item_pfcp),
2894 [ITEM_PFCP_S_FIELD] = {
2897 .next = NEXT(item_pfcp, NEXT_ENTRY(UNSIGNED), item_param),
2898 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_pfcp,
2901 [ITEM_PFCP_SEID] = {
2903 .help = "session endpoint identifier",
2904 .next = NEXT(item_pfcp, NEXT_ENTRY(UNSIGNED), item_param),
2905 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_pfcp, seid)),
2909 .help = "match eCPRI header",
2910 .priv = PRIV_ITEM(ECPRI, sizeof(struct rte_flow_item_ecpri)),
2911 .next = NEXT(item_ecpri),
2914 [ITEM_ECPRI_COMMON] = {
2916 .help = "eCPRI common header",
2917 .next = NEXT(item_ecpri_common),
2919 [ITEM_ECPRI_COMMON_TYPE] = {
2921 .help = "type of common header",
2922 .next = NEXT(item_ecpri_common_type),
2923 .args = ARGS(ARG_ENTRY_HTON(struct rte_flow_item_ecpri)),
2925 [ITEM_ECPRI_COMMON_TYPE_IQ_DATA] = {
2927 .help = "Type #0: IQ Data",
2928 .next = NEXT(NEXT_ENTRY(ITEM_ECPRI_MSG_IQ_DATA_PCID,
2930 .call = parse_vc_item_ecpri_type,
2932 [ITEM_ECPRI_MSG_IQ_DATA_PCID] = {
2934 .help = "Physical Channel ID",
2935 .next = NEXT(item_ecpri, NEXT_ENTRY(UNSIGNED), item_param),
2936 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ecpri,
2939 [ITEM_ECPRI_COMMON_TYPE_RTC_CTRL] = {
2941 .help = "Type #2: Real-Time Control Data",
2942 .next = NEXT(NEXT_ENTRY(ITEM_ECPRI_MSG_RTC_CTRL_RTCID,
2944 .call = parse_vc_item_ecpri_type,
2946 [ITEM_ECPRI_MSG_RTC_CTRL_RTCID] = {
2948 .help = "Real-Time Control Data ID",
2949 .next = NEXT(item_ecpri, NEXT_ENTRY(UNSIGNED), item_param),
2950 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ecpri,
2953 [ITEM_ECPRI_COMMON_TYPE_DLY_MSR] = {
2954 .name = "delay_measure",
2955 .help = "Type #5: One-Way Delay Measurement",
2956 .next = NEXT(NEXT_ENTRY(ITEM_ECPRI_MSG_DLY_MSR_MSRID,
2958 .call = parse_vc_item_ecpri_type,
2960 [ITEM_ECPRI_MSG_DLY_MSR_MSRID] = {
2962 .help = "Measurement ID",
2963 .next = NEXT(item_ecpri, NEXT_ENTRY(UNSIGNED), item_param),
2964 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ecpri,
2967 /* Validate/create actions. */
2970 .help = "submit a list of associated actions",
2971 .next = NEXT(next_action),
2976 .help = "specify next action",
2977 .next = NEXT(next_action),
2981 .help = "end list of actions",
2982 .priv = PRIV_ACTION(END, 0),
2987 .help = "no-op action",
2988 .priv = PRIV_ACTION(VOID, 0),
2989 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2992 [ACTION_PASSTHRU] = {
2994 .help = "let subsequent rule process matched packets",
2995 .priv = PRIV_ACTION(PASSTHRU, 0),
2996 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3001 .help = "redirect traffic to a given group",
3002 .priv = PRIV_ACTION(JUMP, sizeof(struct rte_flow_action_jump)),
3003 .next = NEXT(action_jump),
3006 [ACTION_JUMP_GROUP] = {
3008 .help = "group to redirect traffic to",
3009 .next = NEXT(action_jump, NEXT_ENTRY(UNSIGNED)),
3010 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_jump, group)),
3011 .call = parse_vc_conf,
3015 .help = "attach 32 bit value to packets",
3016 .priv = PRIV_ACTION(MARK, sizeof(struct rte_flow_action_mark)),
3017 .next = NEXT(action_mark),
3020 [ACTION_MARK_ID] = {
3022 .help = "32 bit value to return with packets",
3023 .next = NEXT(action_mark, NEXT_ENTRY(UNSIGNED)),
3024 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_mark, id)),
3025 .call = parse_vc_conf,
3029 .help = "flag packets",
3030 .priv = PRIV_ACTION(FLAG, 0),
3031 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3036 .help = "assign packets to a given queue index",
3037 .priv = PRIV_ACTION(QUEUE,
3038 sizeof(struct rte_flow_action_queue)),
3039 .next = NEXT(action_queue),
3042 [ACTION_QUEUE_INDEX] = {
3044 .help = "queue index to use",
3045 .next = NEXT(action_queue, NEXT_ENTRY(UNSIGNED)),
3046 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_queue, index)),
3047 .call = parse_vc_conf,
3051 .help = "drop packets (note: passthru has priority)",
3052 .priv = PRIV_ACTION(DROP, 0),
3053 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3058 .help = "enable counters for this rule",
3059 .priv = PRIV_ACTION(COUNT,
3060 sizeof(struct rte_flow_action_count)),
3061 .next = NEXT(action_count),
3064 [ACTION_COUNT_ID] = {
3065 .name = "identifier",
3066 .help = "counter identifier to use",
3067 .next = NEXT(action_count, NEXT_ENTRY(UNSIGNED)),
3068 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_count, id)),
3069 .call = parse_vc_conf,
3071 [ACTION_COUNT_SHARED] = {
3073 .help = "shared counter",
3074 .next = NEXT(action_count, NEXT_ENTRY(BOOLEAN)),
3075 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_count,
3077 .call = parse_vc_conf,
3081 .help = "spread packets among several queues",
3082 .priv = PRIV_ACTION(RSS, sizeof(struct action_rss_data)),
3083 .next = NEXT(action_rss),
3084 .call = parse_vc_action_rss,
3086 [ACTION_RSS_FUNC] = {
3088 .help = "RSS hash function to apply",
3089 .next = NEXT(action_rss,
3090 NEXT_ENTRY(ACTION_RSS_FUNC_DEFAULT,
3091 ACTION_RSS_FUNC_TOEPLITZ,
3092 ACTION_RSS_FUNC_SIMPLE_XOR,
3093 ACTION_RSS_FUNC_SYMMETRIC_TOEPLITZ)),
3095 [ACTION_RSS_FUNC_DEFAULT] = {
3097 .help = "default hash function",
3098 .call = parse_vc_action_rss_func,
3100 [ACTION_RSS_FUNC_TOEPLITZ] = {
3102 .help = "Toeplitz hash function",
3103 .call = parse_vc_action_rss_func,
3105 [ACTION_RSS_FUNC_SIMPLE_XOR] = {
3106 .name = "simple_xor",
3107 .help = "simple XOR hash function",
3108 .call = parse_vc_action_rss_func,
3110 [ACTION_RSS_FUNC_SYMMETRIC_TOEPLITZ] = {
3111 .name = "symmetric_toeplitz",
3112 .help = "Symmetric Toeplitz hash function",
3113 .call = parse_vc_action_rss_func,
3115 [ACTION_RSS_LEVEL] = {
3117 .help = "encapsulation level for \"types\"",
3118 .next = NEXT(action_rss, NEXT_ENTRY(UNSIGNED)),
3119 .args = ARGS(ARGS_ENTRY_ARB
3120 (offsetof(struct action_rss_data, conf) +
3121 offsetof(struct rte_flow_action_rss, level),
3122 sizeof(((struct rte_flow_action_rss *)0)->
3125 [ACTION_RSS_TYPES] = {
3127 .help = "specific RSS hash types",
3128 .next = NEXT(action_rss, NEXT_ENTRY(ACTION_RSS_TYPE)),
3130 [ACTION_RSS_TYPE] = {
3132 .help = "RSS hash type",
3133 .call = parse_vc_action_rss_type,
3134 .comp = comp_vc_action_rss_type,
3136 [ACTION_RSS_KEY] = {
3138 .help = "RSS hash key",
3139 .next = NEXT(action_rss, NEXT_ENTRY(HEX)),
3140 .args = ARGS(ARGS_ENTRY_ARB(0, 0),
3142 (offsetof(struct action_rss_data, conf) +
3143 offsetof(struct rte_flow_action_rss, key_len),
3144 sizeof(((struct rte_flow_action_rss *)0)->
3146 ARGS_ENTRY(struct action_rss_data, key)),
3148 [ACTION_RSS_KEY_LEN] = {
3150 .help = "RSS hash key length in bytes",
3151 .next = NEXT(action_rss, NEXT_ENTRY(UNSIGNED)),
3152 .args = ARGS(ARGS_ENTRY_ARB_BOUNDED
3153 (offsetof(struct action_rss_data, conf) +
3154 offsetof(struct rte_flow_action_rss, key_len),
3155 sizeof(((struct rte_flow_action_rss *)0)->
3158 RSS_HASH_KEY_LENGTH)),
3160 [ACTION_RSS_QUEUES] = {
3162 .help = "queue indices to use",
3163 .next = NEXT(action_rss, NEXT_ENTRY(ACTION_RSS_QUEUE)),
3164 .call = parse_vc_conf,
3166 [ACTION_RSS_QUEUE] = {
3168 .help = "queue index",
3169 .call = parse_vc_action_rss_queue,
3170 .comp = comp_vc_action_rss_queue,
3174 .help = "direct traffic to physical function",
3175 .priv = PRIV_ACTION(PF, 0),
3176 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3181 .help = "direct traffic to a virtual function ID",
3182 .priv = PRIV_ACTION(VF, sizeof(struct rte_flow_action_vf)),
3183 .next = NEXT(action_vf),
3186 [ACTION_VF_ORIGINAL] = {
3188 .help = "use original VF ID if possible",
3189 .next = NEXT(action_vf, NEXT_ENTRY(BOOLEAN)),
3190 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_vf,
3192 .call = parse_vc_conf,
3197 .next = NEXT(action_vf, NEXT_ENTRY(UNSIGNED)),
3198 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_vf, id)),
3199 .call = parse_vc_conf,
3201 [ACTION_PHY_PORT] = {
3203 .help = "direct packets to physical port index",
3204 .priv = PRIV_ACTION(PHY_PORT,
3205 sizeof(struct rte_flow_action_phy_port)),
3206 .next = NEXT(action_phy_port),
3209 [ACTION_PHY_PORT_ORIGINAL] = {
3211 .help = "use original port index if possible",
3212 .next = NEXT(action_phy_port, NEXT_ENTRY(BOOLEAN)),
3213 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_phy_port,
3215 .call = parse_vc_conf,
3217 [ACTION_PHY_PORT_INDEX] = {
3219 .help = "physical port index",
3220 .next = NEXT(action_phy_port, NEXT_ENTRY(UNSIGNED)),
3221 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_phy_port,
3223 .call = parse_vc_conf,
3225 [ACTION_PORT_ID] = {
3227 .help = "direct matching traffic to a given DPDK port ID",
3228 .priv = PRIV_ACTION(PORT_ID,
3229 sizeof(struct rte_flow_action_port_id)),
3230 .next = NEXT(action_port_id),
3233 [ACTION_PORT_ID_ORIGINAL] = {
3235 .help = "use original DPDK port ID if possible",
3236 .next = NEXT(action_port_id, NEXT_ENTRY(BOOLEAN)),
3237 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_port_id,
3239 .call = parse_vc_conf,
3241 [ACTION_PORT_ID_ID] = {
3243 .help = "DPDK port ID",
3244 .next = NEXT(action_port_id, NEXT_ENTRY(UNSIGNED)),
3245 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_port_id, id)),
3246 .call = parse_vc_conf,
3250 .help = "meter the directed packets at given id",
3251 .priv = PRIV_ACTION(METER,
3252 sizeof(struct rte_flow_action_meter)),
3253 .next = NEXT(action_meter),
3256 [ACTION_METER_ID] = {
3258 .help = "meter id to use",
3259 .next = NEXT(action_meter, NEXT_ENTRY(UNSIGNED)),
3260 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_meter, mtr_id)),
3261 .call = parse_vc_conf,
3263 [ACTION_OF_SET_MPLS_TTL] = {
3264 .name = "of_set_mpls_ttl",
3265 .help = "OpenFlow's OFPAT_SET_MPLS_TTL",
3268 sizeof(struct rte_flow_action_of_set_mpls_ttl)),
3269 .next = NEXT(action_of_set_mpls_ttl),
3272 [ACTION_OF_SET_MPLS_TTL_MPLS_TTL] = {
3275 .next = NEXT(action_of_set_mpls_ttl, NEXT_ENTRY(UNSIGNED)),
3276 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_of_set_mpls_ttl,
3278 .call = parse_vc_conf,
3280 [ACTION_OF_DEC_MPLS_TTL] = {
3281 .name = "of_dec_mpls_ttl",
3282 .help = "OpenFlow's OFPAT_DEC_MPLS_TTL",
3283 .priv = PRIV_ACTION(OF_DEC_MPLS_TTL, 0),
3284 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3287 [ACTION_OF_SET_NW_TTL] = {
3288 .name = "of_set_nw_ttl",
3289 .help = "OpenFlow's OFPAT_SET_NW_TTL",
3292 sizeof(struct rte_flow_action_of_set_nw_ttl)),
3293 .next = NEXT(action_of_set_nw_ttl),
3296 [ACTION_OF_SET_NW_TTL_NW_TTL] = {
3299 .next = NEXT(action_of_set_nw_ttl, NEXT_ENTRY(UNSIGNED)),
3300 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_of_set_nw_ttl,
3302 .call = parse_vc_conf,
3304 [ACTION_OF_DEC_NW_TTL] = {
3305 .name = "of_dec_nw_ttl",
3306 .help = "OpenFlow's OFPAT_DEC_NW_TTL",
3307 .priv = PRIV_ACTION(OF_DEC_NW_TTL, 0),
3308 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3311 [ACTION_OF_COPY_TTL_OUT] = {
3312 .name = "of_copy_ttl_out",
3313 .help = "OpenFlow's OFPAT_COPY_TTL_OUT",
3314 .priv = PRIV_ACTION(OF_COPY_TTL_OUT, 0),
3315 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3318 [ACTION_OF_COPY_TTL_IN] = {
3319 .name = "of_copy_ttl_in",
3320 .help = "OpenFlow's OFPAT_COPY_TTL_IN",
3321 .priv = PRIV_ACTION(OF_COPY_TTL_IN, 0),
3322 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3325 [ACTION_OF_POP_VLAN] = {
3326 .name = "of_pop_vlan",
3327 .help = "OpenFlow's OFPAT_POP_VLAN",
3328 .priv = PRIV_ACTION(OF_POP_VLAN, 0),
3329 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3332 [ACTION_OF_PUSH_VLAN] = {
3333 .name = "of_push_vlan",
3334 .help = "OpenFlow's OFPAT_PUSH_VLAN",
3337 sizeof(struct rte_flow_action_of_push_vlan)),
3338 .next = NEXT(action_of_push_vlan),
3341 [ACTION_OF_PUSH_VLAN_ETHERTYPE] = {
3342 .name = "ethertype",
3343 .help = "EtherType",
3344 .next = NEXT(action_of_push_vlan, NEXT_ENTRY(UNSIGNED)),
3345 .args = ARGS(ARGS_ENTRY_HTON
3346 (struct rte_flow_action_of_push_vlan,
3348 .call = parse_vc_conf,
3350 [ACTION_OF_SET_VLAN_VID] = {
3351 .name = "of_set_vlan_vid",
3352 .help = "OpenFlow's OFPAT_SET_VLAN_VID",
3355 sizeof(struct rte_flow_action_of_set_vlan_vid)),
3356 .next = NEXT(action_of_set_vlan_vid),
3359 [ACTION_OF_SET_VLAN_VID_VLAN_VID] = {
3362 .next = NEXT(action_of_set_vlan_vid, NEXT_ENTRY(UNSIGNED)),
3363 .args = ARGS(ARGS_ENTRY_HTON
3364 (struct rte_flow_action_of_set_vlan_vid,
3366 .call = parse_vc_conf,
3368 [ACTION_OF_SET_VLAN_PCP] = {
3369 .name = "of_set_vlan_pcp",
3370 .help = "OpenFlow's OFPAT_SET_VLAN_PCP",
3373 sizeof(struct rte_flow_action_of_set_vlan_pcp)),
3374 .next = NEXT(action_of_set_vlan_pcp),
3377 [ACTION_OF_SET_VLAN_PCP_VLAN_PCP] = {
3379 .help = "VLAN priority",
3380 .next = NEXT(action_of_set_vlan_pcp, NEXT_ENTRY(UNSIGNED)),
3381 .args = ARGS(ARGS_ENTRY_HTON
3382 (struct rte_flow_action_of_set_vlan_pcp,
3384 .call = parse_vc_conf,
3386 [ACTION_OF_POP_MPLS] = {
3387 .name = "of_pop_mpls",
3388 .help = "OpenFlow's OFPAT_POP_MPLS",
3389 .priv = PRIV_ACTION(OF_POP_MPLS,
3390 sizeof(struct rte_flow_action_of_pop_mpls)),
3391 .next = NEXT(action_of_pop_mpls),
3394 [ACTION_OF_POP_MPLS_ETHERTYPE] = {
3395 .name = "ethertype",
3396 .help = "EtherType",
3397 .next = NEXT(action_of_pop_mpls, NEXT_ENTRY(UNSIGNED)),
3398 .args = ARGS(ARGS_ENTRY_HTON
3399 (struct rte_flow_action_of_pop_mpls,
3401 .call = parse_vc_conf,
3403 [ACTION_OF_PUSH_MPLS] = {
3404 .name = "of_push_mpls",
3405 .help = "OpenFlow's OFPAT_PUSH_MPLS",
3408 sizeof(struct rte_flow_action_of_push_mpls)),
3409 .next = NEXT(action_of_push_mpls),
3412 [ACTION_OF_PUSH_MPLS_ETHERTYPE] = {
3413 .name = "ethertype",
3414 .help = "EtherType",
3415 .next = NEXT(action_of_push_mpls, NEXT_ENTRY(UNSIGNED)),
3416 .args = ARGS(ARGS_ENTRY_HTON
3417 (struct rte_flow_action_of_push_mpls,
3419 .call = parse_vc_conf,
3421 [ACTION_VXLAN_ENCAP] = {
3422 .name = "vxlan_encap",
3423 .help = "VXLAN encapsulation, uses configuration set by \"set"
3425 .priv = PRIV_ACTION(VXLAN_ENCAP,
3426 sizeof(struct action_vxlan_encap_data)),
3427 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3428 .call = parse_vc_action_vxlan_encap,
3430 [ACTION_VXLAN_DECAP] = {
3431 .name = "vxlan_decap",
3432 .help = "Performs a decapsulation action by stripping all"
3433 " headers of the VXLAN tunnel network overlay from the"
3435 .priv = PRIV_ACTION(VXLAN_DECAP, 0),
3436 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3439 [ACTION_NVGRE_ENCAP] = {
3440 .name = "nvgre_encap",
3441 .help = "NVGRE encapsulation, uses configuration set by \"set"
3443 .priv = PRIV_ACTION(NVGRE_ENCAP,
3444 sizeof(struct action_nvgre_encap_data)),
3445 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3446 .call = parse_vc_action_nvgre_encap,
3448 [ACTION_NVGRE_DECAP] = {
3449 .name = "nvgre_decap",
3450 .help = "Performs a decapsulation action by stripping all"
3451 " headers of the NVGRE tunnel network overlay from the"
3453 .priv = PRIV_ACTION(NVGRE_DECAP, 0),
3454 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3457 [ACTION_L2_ENCAP] = {
3459 .help = "l2 encap, uses configuration set by"
3460 " \"set l2_encap\"",
3461 .priv = PRIV_ACTION(RAW_ENCAP,
3462 sizeof(struct action_raw_encap_data)),
3463 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3464 .call = parse_vc_action_l2_encap,
3466 [ACTION_L2_DECAP] = {
3468 .help = "l2 decap, uses configuration set by"
3469 " \"set l2_decap\"",
3470 .priv = PRIV_ACTION(RAW_DECAP,
3471 sizeof(struct action_raw_decap_data)),
3472 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3473 .call = parse_vc_action_l2_decap,
3475 [ACTION_MPLSOGRE_ENCAP] = {
3476 .name = "mplsogre_encap",
3477 .help = "mplsogre encapsulation, uses configuration set by"
3478 " \"set mplsogre_encap\"",
3479 .priv = PRIV_ACTION(RAW_ENCAP,
3480 sizeof(struct action_raw_encap_data)),
3481 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3482 .call = parse_vc_action_mplsogre_encap,
3484 [ACTION_MPLSOGRE_DECAP] = {
3485 .name = "mplsogre_decap",
3486 .help = "mplsogre decapsulation, uses configuration set by"
3487 " \"set mplsogre_decap\"",
3488 .priv = PRIV_ACTION(RAW_DECAP,
3489 sizeof(struct action_raw_decap_data)),
3490 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3491 .call = parse_vc_action_mplsogre_decap,
3493 [ACTION_MPLSOUDP_ENCAP] = {
3494 .name = "mplsoudp_encap",
3495 .help = "mplsoudp encapsulation, uses configuration set by"
3496 " \"set mplsoudp_encap\"",
3497 .priv = PRIV_ACTION(RAW_ENCAP,
3498 sizeof(struct action_raw_encap_data)),
3499 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3500 .call = parse_vc_action_mplsoudp_encap,
3502 [ACTION_MPLSOUDP_DECAP] = {
3503 .name = "mplsoudp_decap",
3504 .help = "mplsoudp decapsulation, uses configuration set by"
3505 " \"set mplsoudp_decap\"",
3506 .priv = PRIV_ACTION(RAW_DECAP,
3507 sizeof(struct action_raw_decap_data)),
3508 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3509 .call = parse_vc_action_mplsoudp_decap,
3511 [ACTION_SET_IPV4_SRC] = {
3512 .name = "set_ipv4_src",
3513 .help = "Set a new IPv4 source address in the outermost"
3515 .priv = PRIV_ACTION(SET_IPV4_SRC,
3516 sizeof(struct rte_flow_action_set_ipv4)),
3517 .next = NEXT(action_set_ipv4_src),
3520 [ACTION_SET_IPV4_SRC_IPV4_SRC] = {
3521 .name = "ipv4_addr",
3522 .help = "new IPv4 source address to set",
3523 .next = NEXT(action_set_ipv4_src, NEXT_ENTRY(IPV4_ADDR)),
3524 .args = ARGS(ARGS_ENTRY_HTON
3525 (struct rte_flow_action_set_ipv4, ipv4_addr)),
3526 .call = parse_vc_conf,
3528 [ACTION_SET_IPV4_DST] = {
3529 .name = "set_ipv4_dst",
3530 .help = "Set a new IPv4 destination address in the outermost"
3532 .priv = PRIV_ACTION(SET_IPV4_DST,
3533 sizeof(struct rte_flow_action_set_ipv4)),
3534 .next = NEXT(action_set_ipv4_dst),
3537 [ACTION_SET_IPV4_DST_IPV4_DST] = {
3538 .name = "ipv4_addr",
3539 .help = "new IPv4 destination address to set",
3540 .next = NEXT(action_set_ipv4_dst, NEXT_ENTRY(IPV4_ADDR)),
3541 .args = ARGS(ARGS_ENTRY_HTON
3542 (struct rte_flow_action_set_ipv4, ipv4_addr)),
3543 .call = parse_vc_conf,
3545 [ACTION_SET_IPV6_SRC] = {
3546 .name = "set_ipv6_src",
3547 .help = "Set a new IPv6 source address in the outermost"
3549 .priv = PRIV_ACTION(SET_IPV6_SRC,
3550 sizeof(struct rte_flow_action_set_ipv6)),
3551 .next = NEXT(action_set_ipv6_src),
3554 [ACTION_SET_IPV6_SRC_IPV6_SRC] = {
3555 .name = "ipv6_addr",
3556 .help = "new IPv6 source address to set",
3557 .next = NEXT(action_set_ipv6_src, NEXT_ENTRY(IPV6_ADDR)),
3558 .args = ARGS(ARGS_ENTRY_HTON
3559 (struct rte_flow_action_set_ipv6, ipv6_addr)),
3560 .call = parse_vc_conf,
3562 [ACTION_SET_IPV6_DST] = {
3563 .name = "set_ipv6_dst",
3564 .help = "Set a new IPv6 destination address in the outermost"
3566 .priv = PRIV_ACTION(SET_IPV6_DST,
3567 sizeof(struct rte_flow_action_set_ipv6)),
3568 .next = NEXT(action_set_ipv6_dst),
3571 [ACTION_SET_IPV6_DST_IPV6_DST] = {
3572 .name = "ipv6_addr",
3573 .help = "new IPv6 destination address to set",
3574 .next = NEXT(action_set_ipv6_dst, NEXT_ENTRY(IPV6_ADDR)),
3575 .args = ARGS(ARGS_ENTRY_HTON
3576 (struct rte_flow_action_set_ipv6, ipv6_addr)),
3577 .call = parse_vc_conf,
3579 [ACTION_SET_TP_SRC] = {
3580 .name = "set_tp_src",
3581 .help = "set a new source port number in the outermost"
3583 .priv = PRIV_ACTION(SET_TP_SRC,
3584 sizeof(struct rte_flow_action_set_tp)),
3585 .next = NEXT(action_set_tp_src),
3588 [ACTION_SET_TP_SRC_TP_SRC] = {
3590 .help = "new source port number to set",
3591 .next = NEXT(action_set_tp_src, NEXT_ENTRY(UNSIGNED)),
3592 .args = ARGS(ARGS_ENTRY_HTON
3593 (struct rte_flow_action_set_tp, port)),
3594 .call = parse_vc_conf,
3596 [ACTION_SET_TP_DST] = {
3597 .name = "set_tp_dst",
3598 .help = "set a new destination port number in the outermost"
3600 .priv = PRIV_ACTION(SET_TP_DST,
3601 sizeof(struct rte_flow_action_set_tp)),
3602 .next = NEXT(action_set_tp_dst),
3605 [ACTION_SET_TP_DST_TP_DST] = {
3607 .help = "new destination port number to set",
3608 .next = NEXT(action_set_tp_dst, NEXT_ENTRY(UNSIGNED)),
3609 .args = ARGS(ARGS_ENTRY_HTON
3610 (struct rte_flow_action_set_tp, port)),
3611 .call = parse_vc_conf,
3613 [ACTION_MAC_SWAP] = {
3615 .help = "Swap the source and destination MAC addresses"
3616 " in the outermost Ethernet header",
3617 .priv = PRIV_ACTION(MAC_SWAP, 0),
3618 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3621 [ACTION_DEC_TTL] = {
3623 .help = "decrease network TTL if available",
3624 .priv = PRIV_ACTION(DEC_TTL, 0),
3625 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3628 [ACTION_SET_TTL] = {
3630 .help = "set ttl value",
3631 .priv = PRIV_ACTION(SET_TTL,
3632 sizeof(struct rte_flow_action_set_ttl)),
3633 .next = NEXT(action_set_ttl),
3636 [ACTION_SET_TTL_TTL] = {
3637 .name = "ttl_value",
3638 .help = "new ttl value to set",
3639 .next = NEXT(action_set_ttl, NEXT_ENTRY(UNSIGNED)),
3640 .args = ARGS(ARGS_ENTRY_HTON
3641 (struct rte_flow_action_set_ttl, ttl_value)),
3642 .call = parse_vc_conf,
3644 [ACTION_SET_MAC_SRC] = {
3645 .name = "set_mac_src",
3646 .help = "set source mac address",
3647 .priv = PRIV_ACTION(SET_MAC_SRC,
3648 sizeof(struct rte_flow_action_set_mac)),
3649 .next = NEXT(action_set_mac_src),
3652 [ACTION_SET_MAC_SRC_MAC_SRC] = {
3654 .help = "new source mac address",
3655 .next = NEXT(action_set_mac_src, NEXT_ENTRY(MAC_ADDR)),
3656 .args = ARGS(ARGS_ENTRY_HTON
3657 (struct rte_flow_action_set_mac, mac_addr)),
3658 .call = parse_vc_conf,
3660 [ACTION_SET_MAC_DST] = {
3661 .name = "set_mac_dst",
3662 .help = "set destination mac address",
3663 .priv = PRIV_ACTION(SET_MAC_DST,
3664 sizeof(struct rte_flow_action_set_mac)),
3665 .next = NEXT(action_set_mac_dst),
3668 [ACTION_SET_MAC_DST_MAC_DST] = {
3670 .help = "new destination mac address to set",
3671 .next = NEXT(action_set_mac_dst, NEXT_ENTRY(MAC_ADDR)),
3672 .args = ARGS(ARGS_ENTRY_HTON
3673 (struct rte_flow_action_set_mac, mac_addr)),
3674 .call = parse_vc_conf,
3676 [ACTION_INC_TCP_SEQ] = {
3677 .name = "inc_tcp_seq",
3678 .help = "increase TCP sequence number",
3679 .priv = PRIV_ACTION(INC_TCP_SEQ, sizeof(rte_be32_t)),
3680 .next = NEXT(action_inc_tcp_seq),
3683 [ACTION_INC_TCP_SEQ_VALUE] = {
3685 .help = "the value to increase TCP sequence number by",
3686 .next = NEXT(action_inc_tcp_seq, NEXT_ENTRY(UNSIGNED)),
3687 .args = ARGS(ARG_ENTRY_HTON(rte_be32_t)),
3688 .call = parse_vc_conf,
3690 [ACTION_DEC_TCP_SEQ] = {
3691 .name = "dec_tcp_seq",
3692 .help = "decrease TCP sequence number",
3693 .priv = PRIV_ACTION(DEC_TCP_SEQ, sizeof(rte_be32_t)),
3694 .next = NEXT(action_dec_tcp_seq),
3697 [ACTION_DEC_TCP_SEQ_VALUE] = {
3699 .help = "the value to decrease TCP sequence number by",
3700 .next = NEXT(action_dec_tcp_seq, NEXT_ENTRY(UNSIGNED)),
3701 .args = ARGS(ARG_ENTRY_HTON(rte_be32_t)),
3702 .call = parse_vc_conf,
3704 [ACTION_INC_TCP_ACK] = {
3705 .name = "inc_tcp_ack",
3706 .help = "increase TCP acknowledgment number",
3707 .priv = PRIV_ACTION(INC_TCP_ACK, sizeof(rte_be32_t)),
3708 .next = NEXT(action_inc_tcp_ack),
3711 [ACTION_INC_TCP_ACK_VALUE] = {
3713 .help = "the value to increase TCP acknowledgment number by",
3714 .next = NEXT(action_inc_tcp_ack, NEXT_ENTRY(UNSIGNED)),
3715 .args = ARGS(ARG_ENTRY_HTON(rte_be32_t)),
3716 .call = parse_vc_conf,
3718 [ACTION_DEC_TCP_ACK] = {
3719 .name = "dec_tcp_ack",
3720 .help = "decrease TCP acknowledgment number",
3721 .priv = PRIV_ACTION(DEC_TCP_ACK, sizeof(rte_be32_t)),
3722 .next = NEXT(action_dec_tcp_ack),
3725 [ACTION_DEC_TCP_ACK_VALUE] = {
3727 .help = "the value to decrease TCP acknowledgment number by",
3728 .next = NEXT(action_dec_tcp_ack, NEXT_ENTRY(UNSIGNED)),
3729 .args = ARGS(ARG_ENTRY_HTON(rte_be32_t)),
3730 .call = parse_vc_conf,
3732 [ACTION_RAW_ENCAP] = {
3733 .name = "raw_encap",
3734 .help = "encapsulation data, defined by set raw_encap",
3735 .priv = PRIV_ACTION(RAW_ENCAP,
3736 sizeof(struct action_raw_encap_data)),
3737 .next = NEXT(action_raw_encap),
3738 .call = parse_vc_action_raw_encap,
3740 [ACTION_RAW_ENCAP_INDEX] = {
3742 .help = "the index of raw_encap_confs",
3743 .next = NEXT(NEXT_ENTRY(ACTION_RAW_ENCAP_INDEX_VALUE)),
3745 [ACTION_RAW_ENCAP_INDEX_VALUE] = {
3748 .help = "unsigned integer value",
3749 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3750 .call = parse_vc_action_raw_encap_index,
3751 .comp = comp_set_raw_index,
3753 [ACTION_RAW_DECAP] = {
3754 .name = "raw_decap",
3755 .help = "decapsulation data, defined by set raw_encap",
3756 .priv = PRIV_ACTION(RAW_DECAP,
3757 sizeof(struct action_raw_decap_data)),
3758 .next = NEXT(action_raw_decap),
3759 .call = parse_vc_action_raw_decap,
3761 [ACTION_RAW_DECAP_INDEX] = {
3763 .help = "the index of raw_encap_confs",
3764 .next = NEXT(NEXT_ENTRY(ACTION_RAW_DECAP_INDEX_VALUE)),
3766 [ACTION_RAW_DECAP_INDEX_VALUE] = {
3769 .help = "unsigned integer value",
3770 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3771 .call = parse_vc_action_raw_decap_index,
3772 .comp = comp_set_raw_index,
3774 /* Top level command. */
3777 .help = "set raw encap/decap/sample data",
3778 .type = "set raw_encap|raw_decap <index> <pattern>"
3779 " or set sample_actions <index> <action>",
3780 .next = NEXT(NEXT_ENTRY
3783 SET_SAMPLE_ACTIONS)),
3784 .call = parse_set_init,
3786 /* Sub-level commands. */
3788 .name = "raw_encap",
3789 .help = "set raw encap data",
3790 .next = NEXT(next_set_raw),
3791 .args = ARGS(ARGS_ENTRY_ARB_BOUNDED
3792 (offsetof(struct buffer, port),
3793 sizeof(((struct buffer *)0)->port),
3794 0, RAW_ENCAP_CONFS_MAX_NUM - 1)),
3795 .call = parse_set_raw_encap_decap,
3798 .name = "raw_decap",
3799 .help = "set raw decap data",
3800 .next = NEXT(next_set_raw),
3801 .args = ARGS(ARGS_ENTRY_ARB_BOUNDED
3802 (offsetof(struct buffer, port),
3803 sizeof(((struct buffer *)0)->port),
3804 0, RAW_ENCAP_CONFS_MAX_NUM - 1)),
3805 .call = parse_set_raw_encap_decap,
3810 .help = "index of raw_encap/raw_decap data",
3811 .next = NEXT(next_item),
3814 [SET_SAMPLE_INDEX] = {
3817 .help = "index of sample actions",
3818 .next = NEXT(next_action_sample),
3821 [SET_SAMPLE_ACTIONS] = {
3822 .name = "sample_actions",
3823 .help = "set sample actions list",
3824 .next = NEXT(NEXT_ENTRY(SET_SAMPLE_INDEX)),
3825 .args = ARGS(ARGS_ENTRY_ARB_BOUNDED
3826 (offsetof(struct buffer, port),
3827 sizeof(((struct buffer *)0)->port),
3828 0, RAW_SAMPLE_CONFS_MAX_NUM - 1)),
3829 .call = parse_set_sample_action,
3831 [ACTION_SET_TAG] = {
3834 .priv = PRIV_ACTION(SET_TAG,
3835 sizeof(struct rte_flow_action_set_tag)),
3836 .next = NEXT(action_set_tag),
3839 [ACTION_SET_TAG_INDEX] = {
3841 .help = "index of tag array",
3842 .next = NEXT(action_set_tag, NEXT_ENTRY(UNSIGNED)),
3843 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_set_tag, index)),
3844 .call = parse_vc_conf,
3846 [ACTION_SET_TAG_DATA] = {
3848 .help = "tag value",
3849 .next = NEXT(action_set_tag, NEXT_ENTRY(UNSIGNED)),
3850 .args = ARGS(ARGS_ENTRY
3851 (struct rte_flow_action_set_tag, data)),
3852 .call = parse_vc_conf,
3854 [ACTION_SET_TAG_MASK] = {
3856 .help = "mask for tag value",
3857 .next = NEXT(action_set_tag, NEXT_ENTRY(UNSIGNED)),
3858 .args = ARGS(ARGS_ENTRY
3859 (struct rte_flow_action_set_tag, mask)),
3860 .call = parse_vc_conf,
3862 [ACTION_SET_META] = {
3864 .help = "set metadata",
3865 .priv = PRIV_ACTION(SET_META,
3866 sizeof(struct rte_flow_action_set_meta)),
3867 .next = NEXT(action_set_meta),
3868 .call = parse_vc_action_set_meta,
3870 [ACTION_SET_META_DATA] = {
3872 .help = "metadata value",
3873 .next = NEXT(action_set_meta, NEXT_ENTRY(UNSIGNED)),
3874 .args = ARGS(ARGS_ENTRY
3875 (struct rte_flow_action_set_meta, data)),
3876 .call = parse_vc_conf,
3878 [ACTION_SET_META_MASK] = {
3880 .help = "mask for metadata value",
3881 .next = NEXT(action_set_meta, NEXT_ENTRY(UNSIGNED)),
3882 .args = ARGS(ARGS_ENTRY
3883 (struct rte_flow_action_set_meta, mask)),
3884 .call = parse_vc_conf,
3886 [ACTION_SET_IPV4_DSCP] = {
3887 .name = "set_ipv4_dscp",
3888 .help = "set DSCP value",
3889 .priv = PRIV_ACTION(SET_IPV4_DSCP,
3890 sizeof(struct rte_flow_action_set_dscp)),
3891 .next = NEXT(action_set_ipv4_dscp),
3894 [ACTION_SET_IPV4_DSCP_VALUE] = {
3895 .name = "dscp_value",
3896 .help = "new IPv4 DSCP value to set",
3897 .next = NEXT(action_set_ipv4_dscp, NEXT_ENTRY(UNSIGNED)),
3898 .args = ARGS(ARGS_ENTRY
3899 (struct rte_flow_action_set_dscp, dscp)),
3900 .call = parse_vc_conf,
3902 [ACTION_SET_IPV6_DSCP] = {
3903 .name = "set_ipv6_dscp",
3904 .help = "set DSCP value",
3905 .priv = PRIV_ACTION(SET_IPV6_DSCP,
3906 sizeof(struct rte_flow_action_set_dscp)),
3907 .next = NEXT(action_set_ipv6_dscp),
3910 [ACTION_SET_IPV6_DSCP_VALUE] = {
3911 .name = "dscp_value",
3912 .help = "new IPv6 DSCP value to set",
3913 .next = NEXT(action_set_ipv6_dscp, NEXT_ENTRY(UNSIGNED)),
3914 .args = ARGS(ARGS_ENTRY
3915 (struct rte_flow_action_set_dscp, dscp)),
3916 .call = parse_vc_conf,
3920 .help = "set a specific metadata header",
3921 .next = NEXT(action_age),
3922 .priv = PRIV_ACTION(AGE,
3923 sizeof(struct rte_flow_action_age)),
3926 [ACTION_AGE_TIMEOUT] = {
3928 .help = "flow age timeout value",
3929 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_age,
3931 .next = NEXT(action_age, NEXT_ENTRY(UNSIGNED)),
3932 .call = parse_vc_conf,
3936 .help = "set a sample action",
3937 .next = NEXT(action_sample),
3938 .priv = PRIV_ACTION(SAMPLE,
3939 sizeof(struct action_sample_data)),
3940 .call = parse_vc_action_sample,
3942 [ACTION_SAMPLE_RATIO] = {
3944 .help = "flow sample ratio value",
3945 .next = NEXT(action_sample, NEXT_ENTRY(UNSIGNED)),
3946 .args = ARGS(ARGS_ENTRY_ARB
3947 (offsetof(struct action_sample_data, conf) +
3948 offsetof(struct rte_flow_action_sample, ratio),
3949 sizeof(((struct rte_flow_action_sample *)0)->
3952 [ACTION_SAMPLE_INDEX] = {
3954 .help = "the index of sample actions list",
3955 .next = NEXT(NEXT_ENTRY(ACTION_SAMPLE_INDEX_VALUE)),
3957 [ACTION_SAMPLE_INDEX_VALUE] = {
3960 .help = "unsigned integer value",
3961 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3962 .call = parse_vc_action_sample_index,
3963 .comp = comp_set_sample_index,
3967 /** Remove and return last entry from argument stack. */
3968 static const struct arg *
3969 pop_args(struct context *ctx)
3971 return ctx->args_num ? ctx->args[--ctx->args_num] : NULL;
3974 /** Add entry on top of the argument stack. */
3976 push_args(struct context *ctx, const struct arg *arg)
3978 if (ctx->args_num == CTX_STACK_SIZE)
3980 ctx->args[ctx->args_num++] = arg;
3984 /** Spread value into buffer according to bit-mask. */
3986 arg_entry_bf_fill(void *dst, uintmax_t val, const struct arg *arg)
3988 uint32_t i = arg->size;
3996 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
4005 unsigned int shift = 0;
4006 uint8_t *buf = (uint8_t *)dst + arg->offset + (i -= sub);
4008 for (shift = 0; arg->mask[i] >> shift; ++shift) {
4009 if (!(arg->mask[i] & (1 << shift)))
4014 *buf &= ~(1 << shift);
4015 *buf |= (val & 1) << shift;
4023 /** Compare a string with a partial one of a given length. */
4025 strcmp_partial(const char *full, const char *partial, size_t partial_len)
4027 int r = strncmp(full, partial, partial_len);
4031 if (strlen(full) <= partial_len)
4033 return full[partial_len];
4037 * Parse a prefix length and generate a bit-mask.
4039 * Last argument (ctx->args) is retrieved to determine mask size, storage
4040 * location and whether the result must use network byte ordering.
4043 parse_prefix(struct context *ctx, const struct token *token,
4044 const char *str, unsigned int len,
4045 void *buf, unsigned int size)
4047 const struct arg *arg = pop_args(ctx);
4048 static const uint8_t conv[] = "\x00\x80\xc0\xe0\xf0\xf8\xfc\xfe\xff";
4055 /* Argument is expected. */
4059 u = strtoumax(str, &end, 0);
4060 if (errno || (size_t)(end - str) != len)
4065 extra = arg_entry_bf_fill(NULL, 0, arg);
4074 if (!arg_entry_bf_fill(ctx->object, v, arg) ||
4075 !arg_entry_bf_fill(ctx->objmask, -1, arg))
4082 if (bytes > size || bytes + !!extra > size)
4086 buf = (uint8_t *)ctx->object + arg->offset;
4087 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
4089 memset((uint8_t *)buf + size - bytes, 0xff, bytes);
4090 memset(buf, 0x00, size - bytes);
4092 ((uint8_t *)buf)[size - bytes - 1] = conv[extra];
4096 memset(buf, 0xff, bytes);
4097 memset((uint8_t *)buf + bytes, 0x00, size - bytes);
4099 ((uint8_t *)buf)[bytes] = conv[extra];
4102 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
4105 push_args(ctx, arg);
4109 /** Default parsing function for token name matching. */
4111 parse_default(struct context *ctx, const struct token *token,
4112 const char *str, unsigned int len,
4113 void *buf, unsigned int size)
4118 if (strcmp_partial(token->name, str, len))
4123 /** Parse flow command, initialize output buffer for subsequent tokens. */
4125 parse_init(struct context *ctx, const struct token *token,
4126 const char *str, unsigned int len,
4127 void *buf, unsigned int size)
4129 struct buffer *out = buf;
4131 /* Token name must match. */
4132 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
4134 /* Nothing else to do if there is no buffer. */
4137 /* Make sure buffer is large enough. */
4138 if (size < sizeof(*out))
4140 /* Initialize buffer. */
4141 memset(out, 0x00, sizeof(*out));
4142 memset((uint8_t *)out + sizeof(*out), 0x22, size - sizeof(*out));
4145 ctx->objmask = NULL;
4149 /** Parse tokens for validate/create commands. */
4151 parse_vc(struct context *ctx, const struct token *token,
4152 const char *str, unsigned int len,
4153 void *buf, unsigned int size)
4155 struct buffer *out = buf;
4159 /* Token name must match. */
4160 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
4162 /* Nothing else to do if there is no buffer. */
4165 if (!out->command) {
4166 if (ctx->curr != VALIDATE && ctx->curr != CREATE)
4168 if (sizeof(*out) > size)
4170 out->command = ctx->curr;
4173 ctx->objmask = NULL;
4174 out->args.vc.data = (uint8_t *)out + size;
4178 ctx->object = &out->args.vc.attr;
4179 ctx->objmask = NULL;
4180 switch (ctx->curr) {
4185 out->args.vc.attr.ingress = 1;
4188 out->args.vc.attr.egress = 1;
4191 out->args.vc.attr.transfer = 1;
4194 out->args.vc.pattern =
4195 (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
4197 ctx->object = out->args.vc.pattern;
4198 ctx->objmask = NULL;
4201 out->args.vc.actions =
4202 (void *)RTE_ALIGN_CEIL((uintptr_t)
4203 (out->args.vc.pattern +
4204 out->args.vc.pattern_n),
4206 ctx->object = out->args.vc.actions;
4207 ctx->objmask = NULL;
4214 if (!out->args.vc.actions) {
4215 const struct parse_item_priv *priv = token->priv;
4216 struct rte_flow_item *item =
4217 out->args.vc.pattern + out->args.vc.pattern_n;
4219 data_size = priv->size * 3; /* spec, last, mask */
4220 data = (void *)RTE_ALIGN_FLOOR((uintptr_t)
4221 (out->args.vc.data - data_size),
4223 if ((uint8_t *)item + sizeof(*item) > data)
4225 *item = (struct rte_flow_item){
4228 ++out->args.vc.pattern_n;
4230 ctx->objmask = NULL;
4232 const struct parse_action_priv *priv = token->priv;
4233 struct rte_flow_action *action =
4234 out->args.vc.actions + out->args.vc.actions_n;
4236 data_size = priv->size; /* configuration */
4237 data = (void *)RTE_ALIGN_FLOOR((uintptr_t)
4238 (out->args.vc.data - data_size),
4240 if ((uint8_t *)action + sizeof(*action) > data)
4242 *action = (struct rte_flow_action){
4244 .conf = data_size ? data : NULL,
4246 ++out->args.vc.actions_n;
4247 ctx->object = action;
4248 ctx->objmask = NULL;
4250 memset(data, 0, data_size);
4251 out->args.vc.data = data;
4252 ctx->objdata = data_size;
4256 /** Parse pattern item parameter type. */
4258 parse_vc_spec(struct context *ctx, const struct token *token,
4259 const char *str, unsigned int len,
4260 void *buf, unsigned int size)
4262 struct buffer *out = buf;
4263 struct rte_flow_item *item;
4269 /* Token name must match. */
4270 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
4272 /* Parse parameter types. */
4273 switch (ctx->curr) {
4274 static const enum index prefix[] = NEXT_ENTRY(PREFIX);
4280 case ITEM_PARAM_SPEC:
4283 case ITEM_PARAM_LAST:
4286 case ITEM_PARAM_PREFIX:
4287 /* Modify next token to expect a prefix. */
4288 if (ctx->next_num < 2)
4290 ctx->next[ctx->next_num - 2] = prefix;
4292 case ITEM_PARAM_MASK:
4298 /* Nothing else to do if there is no buffer. */
4301 if (!out->args.vc.pattern_n)
4303 item = &out->args.vc.pattern[out->args.vc.pattern_n - 1];
4304 data_size = ctx->objdata / 3; /* spec, last, mask */
4305 /* Point to selected object. */
4306 ctx->object = out->args.vc.data + (data_size * index);
4308 ctx->objmask = out->args.vc.data + (data_size * 2); /* mask */
4309 item->mask = ctx->objmask;
4311 ctx->objmask = NULL;
4312 /* Update relevant item pointer. */
4313 *((const void **[]){ &item->spec, &item->last, &item->mask })[index] =
4318 /** Parse action configuration field. */
4320 parse_vc_conf(struct context *ctx, const struct token *token,
4321 const char *str, unsigned int len,
4322 void *buf, unsigned int size)
4324 struct buffer *out = buf;
4327 /* Token name must match. */
4328 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
4330 /* Nothing else to do if there is no buffer. */
4333 /* Point to selected object. */
4334 ctx->object = out->args.vc.data;
4335 ctx->objmask = NULL;
4339 /** Parse eCPRI common header type field. */
4341 parse_vc_item_ecpri_type(struct context *ctx, const struct token *token,
4342 const char *str, unsigned int len,
4343 void *buf, unsigned int size)
4345 struct rte_flow_item_ecpri *ecpri;
4346 struct rte_flow_item_ecpri *ecpri_mask;
4347 struct rte_flow_item *item;
4350 struct buffer *out = buf;
4351 const struct arg *arg;
4354 /* Token name must match. */
4355 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
4357 switch (ctx->curr) {
4358 case ITEM_ECPRI_COMMON_TYPE_IQ_DATA:
4359 msg_type = RTE_ECPRI_MSG_TYPE_IQ_DATA;
4361 case ITEM_ECPRI_COMMON_TYPE_RTC_CTRL:
4362 msg_type = RTE_ECPRI_MSG_TYPE_RTC_CTRL;
4364 case ITEM_ECPRI_COMMON_TYPE_DLY_MSR:
4365 msg_type = RTE_ECPRI_MSG_TYPE_DLY_MSR;
4372 arg = pop_args(ctx);
4375 ecpri = (struct rte_flow_item_ecpri *)out->args.vc.data;
4376 ecpri->hdr.common.type = msg_type;
4377 data_size = ctx->objdata / 3; /* spec, last, mask */
4378 ecpri_mask = (struct rte_flow_item_ecpri *)(out->args.vc.data +
4380 ecpri_mask->hdr.common.type = 0xFF;
4382 ecpri->hdr.common.u32 = rte_cpu_to_be_32(ecpri->hdr.common.u32);
4383 ecpri_mask->hdr.common.u32 =
4384 rte_cpu_to_be_32(ecpri_mask->hdr.common.u32);
4386 item = &out->args.vc.pattern[out->args.vc.pattern_n - 1];
4388 item->mask = ecpri_mask;
4392 /** Parse RSS action. */
4394 parse_vc_action_rss(struct context *ctx, const struct token *token,
4395 const char *str, unsigned int len,
4396 void *buf, unsigned int size)
4398 struct buffer *out = buf;
4399 struct rte_flow_action *action;
4400 struct action_rss_data *action_rss_data;
4404 ret = parse_vc(ctx, token, str, len, buf, size);
4407 /* Nothing else to do if there is no buffer. */
4410 if (!out->args.vc.actions_n)
4412 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4413 /* Point to selected object. */
4414 ctx->object = out->args.vc.data;
4415 ctx->objmask = NULL;
4416 /* Set up default configuration. */
4417 action_rss_data = ctx->object;
4418 *action_rss_data = (struct action_rss_data){
4419 .conf = (struct rte_flow_action_rss){
4420 .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
4423 .key_len = sizeof(action_rss_data->key),
4424 .queue_num = RTE_MIN(nb_rxq, ACTION_RSS_QUEUE_NUM),
4425 .key = action_rss_data->key,
4426 .queue = action_rss_data->queue,
4428 .key = "testpmd's default RSS hash key, "
4429 "override it for better balancing",
4432 for (i = 0; i < action_rss_data->conf.queue_num; ++i)
4433 action_rss_data->queue[i] = i;
4434 if (!port_id_is_invalid(ctx->port, DISABLED_WARN) &&
4435 ctx->port != (portid_t)RTE_PORT_ALL) {
4436 struct rte_eth_dev_info info;
4439 ret2 = rte_eth_dev_info_get(ctx->port, &info);
4443 action_rss_data->conf.key_len =
4444 RTE_MIN(sizeof(action_rss_data->key),
4445 info.hash_key_size);
4447 action->conf = &action_rss_data->conf;
4452 * Parse func field for RSS action.
4454 * The RTE_ETH_HASH_FUNCTION_* value to assign is derived from the
4455 * ACTION_RSS_FUNC_* index that called this function.
4458 parse_vc_action_rss_func(struct context *ctx, const struct token *token,
4459 const char *str, unsigned int len,
4460 void *buf, unsigned int size)
4462 struct action_rss_data *action_rss_data;
4463 enum rte_eth_hash_function func;
4467 /* Token name must match. */
4468 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
4470 switch (ctx->curr) {
4471 case ACTION_RSS_FUNC_DEFAULT:
4472 func = RTE_ETH_HASH_FUNCTION_DEFAULT;
4474 case ACTION_RSS_FUNC_TOEPLITZ:
4475 func = RTE_ETH_HASH_FUNCTION_TOEPLITZ;
4477 case ACTION_RSS_FUNC_SIMPLE_XOR:
4478 func = RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
4480 case ACTION_RSS_FUNC_SYMMETRIC_TOEPLITZ:
4481 func = RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ;
4488 action_rss_data = ctx->object;
4489 action_rss_data->conf.func = func;
4494 * Parse type field for RSS action.
4496 * Valid tokens are type field names and the "end" token.
4499 parse_vc_action_rss_type(struct context *ctx, const struct token *token,
4500 const char *str, unsigned int len,
4501 void *buf, unsigned int size)
4503 static const enum index next[] = NEXT_ENTRY(ACTION_RSS_TYPE);
4504 struct action_rss_data *action_rss_data;
4510 if (ctx->curr != ACTION_RSS_TYPE)
4512 if (!(ctx->objdata >> 16) && ctx->object) {
4513 action_rss_data = ctx->object;
4514 action_rss_data->conf.types = 0;
4516 if (!strcmp_partial("end", str, len)) {
4517 ctx->objdata &= 0xffff;
4520 for (i = 0; rss_type_table[i].str; ++i)
4521 if (!strcmp_partial(rss_type_table[i].str, str, len))
4523 if (!rss_type_table[i].str)
4525 ctx->objdata = 1 << 16 | (ctx->objdata & 0xffff);
4527 if (ctx->next_num == RTE_DIM(ctx->next))
4529 ctx->next[ctx->next_num++] = next;
4532 action_rss_data = ctx->object;
4533 action_rss_data->conf.types |= rss_type_table[i].rss_type;
4538 * Parse queue field for RSS action.
4540 * Valid tokens are queue indices and the "end" token.
4543 parse_vc_action_rss_queue(struct context *ctx, const struct token *token,
4544 const char *str, unsigned int len,
4545 void *buf, unsigned int size)
4547 static const enum index next[] = NEXT_ENTRY(ACTION_RSS_QUEUE);
4548 struct action_rss_data *action_rss_data;
4549 const struct arg *arg;
4556 if (ctx->curr != ACTION_RSS_QUEUE)
4558 i = ctx->objdata >> 16;
4559 if (!strcmp_partial("end", str, len)) {
4560 ctx->objdata &= 0xffff;
4563 if (i >= ACTION_RSS_QUEUE_NUM)
4565 arg = ARGS_ENTRY_ARB(offsetof(struct action_rss_data, queue) +
4566 i * sizeof(action_rss_data->queue[i]),
4567 sizeof(action_rss_data->queue[i]));
4568 if (push_args(ctx, arg))
4570 ret = parse_int(ctx, token, str, len, NULL, 0);
4576 ctx->objdata = i << 16 | (ctx->objdata & 0xffff);
4578 if (ctx->next_num == RTE_DIM(ctx->next))
4580 ctx->next[ctx->next_num++] = next;
4584 action_rss_data = ctx->object;
4585 action_rss_data->conf.queue_num = i;
4586 action_rss_data->conf.queue = i ? action_rss_data->queue : NULL;
4590 /** Parse VXLAN encap action. */
4592 parse_vc_action_vxlan_encap(struct context *ctx, const struct token *token,
4593 const char *str, unsigned int len,
4594 void *buf, unsigned int size)
4596 struct buffer *out = buf;
4597 struct rte_flow_action *action;
4598 struct action_vxlan_encap_data *action_vxlan_encap_data;
4601 ret = parse_vc(ctx, token, str, len, buf, size);
4604 /* Nothing else to do if there is no buffer. */
4607 if (!out->args.vc.actions_n)
4609 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4610 /* Point to selected object. */
4611 ctx->object = out->args.vc.data;
4612 ctx->objmask = NULL;
4613 /* Set up default configuration. */
4614 action_vxlan_encap_data = ctx->object;
4615 *action_vxlan_encap_data = (struct action_vxlan_encap_data){
4616 .conf = (struct rte_flow_action_vxlan_encap){
4617 .definition = action_vxlan_encap_data->items,
4621 .type = RTE_FLOW_ITEM_TYPE_ETH,
4622 .spec = &action_vxlan_encap_data->item_eth,
4623 .mask = &rte_flow_item_eth_mask,
4626 .type = RTE_FLOW_ITEM_TYPE_VLAN,
4627 .spec = &action_vxlan_encap_data->item_vlan,
4628 .mask = &rte_flow_item_vlan_mask,
4631 .type = RTE_FLOW_ITEM_TYPE_IPV4,
4632 .spec = &action_vxlan_encap_data->item_ipv4,
4633 .mask = &rte_flow_item_ipv4_mask,
4636 .type = RTE_FLOW_ITEM_TYPE_UDP,
4637 .spec = &action_vxlan_encap_data->item_udp,
4638 .mask = &rte_flow_item_udp_mask,
4641 .type = RTE_FLOW_ITEM_TYPE_VXLAN,
4642 .spec = &action_vxlan_encap_data->item_vxlan,
4643 .mask = &rte_flow_item_vxlan_mask,
4646 .type = RTE_FLOW_ITEM_TYPE_END,
4651 .tci = vxlan_encap_conf.vlan_tci,
4655 .src_addr = vxlan_encap_conf.ipv4_src,
4656 .dst_addr = vxlan_encap_conf.ipv4_dst,
4659 .src_port = vxlan_encap_conf.udp_src,
4660 .dst_port = vxlan_encap_conf.udp_dst,
4662 .item_vxlan.flags = 0,
4664 memcpy(action_vxlan_encap_data->item_eth.dst.addr_bytes,
4665 vxlan_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
4666 memcpy(action_vxlan_encap_data->item_eth.src.addr_bytes,
4667 vxlan_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
4668 if (!vxlan_encap_conf.select_ipv4) {
4669 memcpy(&action_vxlan_encap_data->item_ipv6.hdr.src_addr,
4670 &vxlan_encap_conf.ipv6_src,
4671 sizeof(vxlan_encap_conf.ipv6_src));
4672 memcpy(&action_vxlan_encap_data->item_ipv6.hdr.dst_addr,
4673 &vxlan_encap_conf.ipv6_dst,
4674 sizeof(vxlan_encap_conf.ipv6_dst));
4675 action_vxlan_encap_data->items[2] = (struct rte_flow_item){
4676 .type = RTE_FLOW_ITEM_TYPE_IPV6,
4677 .spec = &action_vxlan_encap_data->item_ipv6,
4678 .mask = &rte_flow_item_ipv6_mask,
4681 if (!vxlan_encap_conf.select_vlan)
4682 action_vxlan_encap_data->items[1].type =
4683 RTE_FLOW_ITEM_TYPE_VOID;
4684 if (vxlan_encap_conf.select_tos_ttl) {
4685 if (vxlan_encap_conf.select_ipv4) {
4686 static struct rte_flow_item_ipv4 ipv4_mask_tos;
4688 memcpy(&ipv4_mask_tos, &rte_flow_item_ipv4_mask,
4689 sizeof(ipv4_mask_tos));
4690 ipv4_mask_tos.hdr.type_of_service = 0xff;
4691 ipv4_mask_tos.hdr.time_to_live = 0xff;
4692 action_vxlan_encap_data->item_ipv4.hdr.type_of_service =
4693 vxlan_encap_conf.ip_tos;
4694 action_vxlan_encap_data->item_ipv4.hdr.time_to_live =
4695 vxlan_encap_conf.ip_ttl;
4696 action_vxlan_encap_data->items[2].mask =
4699 static struct rte_flow_item_ipv6 ipv6_mask_tos;
4701 memcpy(&ipv6_mask_tos, &rte_flow_item_ipv6_mask,
4702 sizeof(ipv6_mask_tos));
4703 ipv6_mask_tos.hdr.vtc_flow |=
4704 RTE_BE32(0xfful << RTE_IPV6_HDR_TC_SHIFT);
4705 ipv6_mask_tos.hdr.hop_limits = 0xff;
4706 action_vxlan_encap_data->item_ipv6.hdr.vtc_flow |=
4708 ((uint32_t)vxlan_encap_conf.ip_tos <<
4709 RTE_IPV6_HDR_TC_SHIFT);
4710 action_vxlan_encap_data->item_ipv6.hdr.hop_limits =
4711 vxlan_encap_conf.ip_ttl;
4712 action_vxlan_encap_data->items[2].mask =
4716 memcpy(action_vxlan_encap_data->item_vxlan.vni, vxlan_encap_conf.vni,
4717 RTE_DIM(vxlan_encap_conf.vni));
4718 action->conf = &action_vxlan_encap_data->conf;
4722 /** Parse NVGRE encap action. */
4724 parse_vc_action_nvgre_encap(struct context *ctx, const struct token *token,
4725 const char *str, unsigned int len,
4726 void *buf, unsigned int size)
4728 struct buffer *out = buf;
4729 struct rte_flow_action *action;
4730 struct action_nvgre_encap_data *action_nvgre_encap_data;
4733 ret = parse_vc(ctx, token, str, len, buf, size);
4736 /* Nothing else to do if there is no buffer. */
4739 if (!out->args.vc.actions_n)
4741 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4742 /* Point to selected object. */
4743 ctx->object = out->args.vc.data;
4744 ctx->objmask = NULL;
4745 /* Set up default configuration. */
4746 action_nvgre_encap_data = ctx->object;
4747 *action_nvgre_encap_data = (struct action_nvgre_encap_data){
4748 .conf = (struct rte_flow_action_nvgre_encap){
4749 .definition = action_nvgre_encap_data->items,
4753 .type = RTE_FLOW_ITEM_TYPE_ETH,
4754 .spec = &action_nvgre_encap_data->item_eth,
4755 .mask = &rte_flow_item_eth_mask,
4758 .type = RTE_FLOW_ITEM_TYPE_VLAN,
4759 .spec = &action_nvgre_encap_data->item_vlan,
4760 .mask = &rte_flow_item_vlan_mask,
4763 .type = RTE_FLOW_ITEM_TYPE_IPV4,
4764 .spec = &action_nvgre_encap_data->item_ipv4,
4765 .mask = &rte_flow_item_ipv4_mask,
4768 .type = RTE_FLOW_ITEM_TYPE_NVGRE,
4769 .spec = &action_nvgre_encap_data->item_nvgre,
4770 .mask = &rte_flow_item_nvgre_mask,
4773 .type = RTE_FLOW_ITEM_TYPE_END,
4778 .tci = nvgre_encap_conf.vlan_tci,
4782 .src_addr = nvgre_encap_conf.ipv4_src,
4783 .dst_addr = nvgre_encap_conf.ipv4_dst,
4785 .item_nvgre.flow_id = 0,
4787 memcpy(action_nvgre_encap_data->item_eth.dst.addr_bytes,
4788 nvgre_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
4789 memcpy(action_nvgre_encap_data->item_eth.src.addr_bytes,
4790 nvgre_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
4791 if (!nvgre_encap_conf.select_ipv4) {
4792 memcpy(&action_nvgre_encap_data->item_ipv6.hdr.src_addr,
4793 &nvgre_encap_conf.ipv6_src,
4794 sizeof(nvgre_encap_conf.ipv6_src));
4795 memcpy(&action_nvgre_encap_data->item_ipv6.hdr.dst_addr,
4796 &nvgre_encap_conf.ipv6_dst,
4797 sizeof(nvgre_encap_conf.ipv6_dst));
4798 action_nvgre_encap_data->items[2] = (struct rte_flow_item){
4799 .type = RTE_FLOW_ITEM_TYPE_IPV6,
4800 .spec = &action_nvgre_encap_data->item_ipv6,
4801 .mask = &rte_flow_item_ipv6_mask,
4804 if (!nvgre_encap_conf.select_vlan)
4805 action_nvgre_encap_data->items[1].type =
4806 RTE_FLOW_ITEM_TYPE_VOID;
4807 memcpy(action_nvgre_encap_data->item_nvgre.tni, nvgre_encap_conf.tni,
4808 RTE_DIM(nvgre_encap_conf.tni));
4809 action->conf = &action_nvgre_encap_data->conf;
4813 /** Parse l2 encap action. */
4815 parse_vc_action_l2_encap(struct context *ctx, const struct token *token,
4816 const char *str, unsigned int len,
4817 void *buf, unsigned int size)
4819 struct buffer *out = buf;
4820 struct rte_flow_action *action;
4821 struct action_raw_encap_data *action_encap_data;
4822 struct rte_flow_item_eth eth = { .type = 0, };
4823 struct rte_flow_item_vlan vlan = {
4824 .tci = mplsoudp_encap_conf.vlan_tci,
4830 ret = parse_vc(ctx, token, str, len, buf, size);
4833 /* Nothing else to do if there is no buffer. */
4836 if (!out->args.vc.actions_n)
4838 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4839 /* Point to selected object. */
4840 ctx->object = out->args.vc.data;
4841 ctx->objmask = NULL;
4842 /* Copy the headers to the buffer. */
4843 action_encap_data = ctx->object;
4844 *action_encap_data = (struct action_raw_encap_data) {
4845 .conf = (struct rte_flow_action_raw_encap){
4846 .data = action_encap_data->data,
4850 header = action_encap_data->data;
4851 if (l2_encap_conf.select_vlan)
4852 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
4853 else if (l2_encap_conf.select_ipv4)
4854 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4856 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4857 memcpy(eth.dst.addr_bytes,
4858 l2_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
4859 memcpy(eth.src.addr_bytes,
4860 l2_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
4861 memcpy(header, ð, sizeof(eth));
4862 header += sizeof(eth);
4863 if (l2_encap_conf.select_vlan) {
4864 if (l2_encap_conf.select_ipv4)
4865 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4867 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4868 memcpy(header, &vlan, sizeof(vlan));
4869 header += sizeof(vlan);
4871 action_encap_data->conf.size = header -
4872 action_encap_data->data;
4873 action->conf = &action_encap_data->conf;
4877 /** Parse l2 decap action. */
4879 parse_vc_action_l2_decap(struct context *ctx, const struct token *token,
4880 const char *str, unsigned int len,
4881 void *buf, unsigned int size)
4883 struct buffer *out = buf;
4884 struct rte_flow_action *action;
4885 struct action_raw_decap_data *action_decap_data;
4886 struct rte_flow_item_eth eth = { .type = 0, };
4887 struct rte_flow_item_vlan vlan = {
4888 .tci = mplsoudp_encap_conf.vlan_tci,
4894 ret = parse_vc(ctx, token, str, len, buf, size);
4897 /* Nothing else to do if there is no buffer. */
4900 if (!out->args.vc.actions_n)
4902 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4903 /* Point to selected object. */
4904 ctx->object = out->args.vc.data;
4905 ctx->objmask = NULL;
4906 /* Copy the headers to the buffer. */
4907 action_decap_data = ctx->object;
4908 *action_decap_data = (struct action_raw_decap_data) {
4909 .conf = (struct rte_flow_action_raw_decap){
4910 .data = action_decap_data->data,
4914 header = action_decap_data->data;
4915 if (l2_decap_conf.select_vlan)
4916 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
4917 memcpy(header, ð, sizeof(eth));
4918 header += sizeof(eth);
4919 if (l2_decap_conf.select_vlan) {
4920 memcpy(header, &vlan, sizeof(vlan));
4921 header += sizeof(vlan);
4923 action_decap_data->conf.size = header -
4924 action_decap_data->data;
4925 action->conf = &action_decap_data->conf;
4929 #define ETHER_TYPE_MPLS_UNICAST 0x8847
4931 /** Parse MPLSOGRE encap action. */
4933 parse_vc_action_mplsogre_encap(struct context *ctx, const struct token *token,
4934 const char *str, unsigned int len,
4935 void *buf, unsigned int size)
4937 struct buffer *out = buf;
4938 struct rte_flow_action *action;
4939 struct action_raw_encap_data *action_encap_data;
4940 struct rte_flow_item_eth eth = { .type = 0, };
4941 struct rte_flow_item_vlan vlan = {
4942 .tci = mplsogre_encap_conf.vlan_tci,
4945 struct rte_flow_item_ipv4 ipv4 = {
4947 .src_addr = mplsogre_encap_conf.ipv4_src,
4948 .dst_addr = mplsogre_encap_conf.ipv4_dst,
4949 .next_proto_id = IPPROTO_GRE,
4950 .version_ihl = RTE_IPV4_VHL_DEF,
4951 .time_to_live = IPDEFTTL,
4954 struct rte_flow_item_ipv6 ipv6 = {
4956 .proto = IPPROTO_GRE,
4957 .hop_limits = IPDEFTTL,
4960 struct rte_flow_item_gre gre = {
4961 .protocol = rte_cpu_to_be_16(ETHER_TYPE_MPLS_UNICAST),
4963 struct rte_flow_item_mpls mpls = {
4969 ret = parse_vc(ctx, token, str, len, buf, size);
4972 /* Nothing else to do if there is no buffer. */
4975 if (!out->args.vc.actions_n)
4977 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4978 /* Point to selected object. */
4979 ctx->object = out->args.vc.data;
4980 ctx->objmask = NULL;
4981 /* Copy the headers to the buffer. */
4982 action_encap_data = ctx->object;
4983 *action_encap_data = (struct action_raw_encap_data) {
4984 .conf = (struct rte_flow_action_raw_encap){
4985 .data = action_encap_data->data,
4990 header = action_encap_data->data;
4991 if (mplsogre_encap_conf.select_vlan)
4992 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
4993 else if (mplsogre_encap_conf.select_ipv4)
4994 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4996 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4997 memcpy(eth.dst.addr_bytes,
4998 mplsogre_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
4999 memcpy(eth.src.addr_bytes,
5000 mplsogre_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
5001 memcpy(header, ð, sizeof(eth));
5002 header += sizeof(eth);
5003 if (mplsogre_encap_conf.select_vlan) {
5004 if (mplsogre_encap_conf.select_ipv4)
5005 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
5007 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
5008 memcpy(header, &vlan, sizeof(vlan));
5009 header += sizeof(vlan);
5011 if (mplsogre_encap_conf.select_ipv4) {
5012 memcpy(header, &ipv4, sizeof(ipv4));
5013 header += sizeof(ipv4);
5015 memcpy(&ipv6.hdr.src_addr,
5016 &mplsogre_encap_conf.ipv6_src,
5017 sizeof(mplsogre_encap_conf.ipv6_src));
5018 memcpy(&ipv6.hdr.dst_addr,
5019 &mplsogre_encap_conf.ipv6_dst,
5020 sizeof(mplsogre_encap_conf.ipv6_dst));
5021 memcpy(header, &ipv6, sizeof(ipv6));
5022 header += sizeof(ipv6);
5024 memcpy(header, &gre, sizeof(gre));
5025 header += sizeof(gre);
5026 memcpy(mpls.label_tc_s, mplsogre_encap_conf.label,
5027 RTE_DIM(mplsogre_encap_conf.label));
5028 mpls.label_tc_s[2] |= 0x1;
5029 memcpy(header, &mpls, sizeof(mpls));
5030 header += sizeof(mpls);
5031 action_encap_data->conf.size = header -
5032 action_encap_data->data;
5033 action->conf = &action_encap_data->conf;
5037 /** Parse MPLSOGRE decap action. */
5039 parse_vc_action_mplsogre_decap(struct context *ctx, const struct token *token,
5040 const char *str, unsigned int len,
5041 void *buf, unsigned int size)
5043 struct buffer *out = buf;
5044 struct rte_flow_action *action;
5045 struct action_raw_decap_data *action_decap_data;
5046 struct rte_flow_item_eth eth = { .type = 0, };
5047 struct rte_flow_item_vlan vlan = {.tci = 0};
5048 struct rte_flow_item_ipv4 ipv4 = {
5050 .next_proto_id = IPPROTO_GRE,
5053 struct rte_flow_item_ipv6 ipv6 = {
5055 .proto = IPPROTO_GRE,
5058 struct rte_flow_item_gre gre = {
5059 .protocol = rte_cpu_to_be_16(ETHER_TYPE_MPLS_UNICAST),
5061 struct rte_flow_item_mpls mpls;
5065 ret = parse_vc(ctx, token, str, len, buf, size);
5068 /* Nothing else to do if there is no buffer. */
5071 if (!out->args.vc.actions_n)
5073 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
5074 /* Point to selected object. */
5075 ctx->object = out->args.vc.data;
5076 ctx->objmask = NULL;
5077 /* Copy the headers to the buffer. */
5078 action_decap_data = ctx->object;
5079 *action_decap_data = (struct action_raw_decap_data) {
5080 .conf = (struct rte_flow_action_raw_decap){
5081 .data = action_decap_data->data,
5085 header = action_decap_data->data;
5086 if (mplsogre_decap_conf.select_vlan)
5087 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
5088 else if (mplsogre_encap_conf.select_ipv4)
5089 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
5091 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
5092 memcpy(eth.dst.addr_bytes,
5093 mplsogre_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
5094 memcpy(eth.src.addr_bytes,
5095 mplsogre_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
5096 memcpy(header, ð, sizeof(eth));
5097 header += sizeof(eth);
5098 if (mplsogre_encap_conf.select_vlan) {
5099 if (mplsogre_encap_conf.select_ipv4)
5100 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
5102 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
5103 memcpy(header, &vlan, sizeof(vlan));
5104 header += sizeof(vlan);
5106 if (mplsogre_encap_conf.select_ipv4) {
5107 memcpy(header, &ipv4, sizeof(ipv4));
5108 header += sizeof(ipv4);
5110 memcpy(header, &ipv6, sizeof(ipv6));
5111 header += sizeof(ipv6);
5113 memcpy(header, &gre, sizeof(gre));
5114 header += sizeof(gre);
5115 memset(&mpls, 0, sizeof(mpls));
5116 memcpy(header, &mpls, sizeof(mpls));
5117 header += sizeof(mpls);
5118 action_decap_data->conf.size = header -
5119 action_decap_data->data;
5120 action->conf = &action_decap_data->conf;
5124 /** Parse MPLSOUDP encap action. */
5126 parse_vc_action_mplsoudp_encap(struct context *ctx, const struct token *token,
5127 const char *str, unsigned int len,
5128 void *buf, unsigned int size)
5130 struct buffer *out = buf;
5131 struct rte_flow_action *action;
5132 struct action_raw_encap_data *action_encap_data;
5133 struct rte_flow_item_eth eth = { .type = 0, };
5134 struct rte_flow_item_vlan vlan = {
5135 .tci = mplsoudp_encap_conf.vlan_tci,
5138 struct rte_flow_item_ipv4 ipv4 = {
5140 .src_addr = mplsoudp_encap_conf.ipv4_src,
5141 .dst_addr = mplsoudp_encap_conf.ipv4_dst,
5142 .next_proto_id = IPPROTO_UDP,
5143 .version_ihl = RTE_IPV4_VHL_DEF,
5144 .time_to_live = IPDEFTTL,
5147 struct rte_flow_item_ipv6 ipv6 = {
5149 .proto = IPPROTO_UDP,
5150 .hop_limits = IPDEFTTL,
5153 struct rte_flow_item_udp udp = {
5155 .src_port = mplsoudp_encap_conf.udp_src,
5156 .dst_port = mplsoudp_encap_conf.udp_dst,
5159 struct rte_flow_item_mpls mpls;
5163 ret = parse_vc(ctx, token, str, len, buf, size);
5166 /* Nothing else to do if there is no buffer. */
5169 if (!out->args.vc.actions_n)
5171 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
5172 /* Point to selected object. */
5173 ctx->object = out->args.vc.data;
5174 ctx->objmask = NULL;
5175 /* Copy the headers to the buffer. */
5176 action_encap_data = ctx->object;
5177 *action_encap_data = (struct action_raw_encap_data) {
5178 .conf = (struct rte_flow_action_raw_encap){
5179 .data = action_encap_data->data,
5184 header = action_encap_data->data;
5185 if (mplsoudp_encap_conf.select_vlan)
5186 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
5187 else if (mplsoudp_encap_conf.select_ipv4)
5188 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
5190 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
5191 memcpy(eth.dst.addr_bytes,
5192 mplsoudp_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
5193 memcpy(eth.src.addr_bytes,
5194 mplsoudp_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
5195 memcpy(header, ð, sizeof(eth));
5196 header += sizeof(eth);
5197 if (mplsoudp_encap_conf.select_vlan) {
5198 if (mplsoudp_encap_conf.select_ipv4)
5199 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
5201 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
5202 memcpy(header, &vlan, sizeof(vlan));
5203 header += sizeof(vlan);
5205 if (mplsoudp_encap_conf.select_ipv4) {
5206 memcpy(header, &ipv4, sizeof(ipv4));
5207 header += sizeof(ipv4);
5209 memcpy(&ipv6.hdr.src_addr,
5210 &mplsoudp_encap_conf.ipv6_src,
5211 sizeof(mplsoudp_encap_conf.ipv6_src));
5212 memcpy(&ipv6.hdr.dst_addr,
5213 &mplsoudp_encap_conf.ipv6_dst,
5214 sizeof(mplsoudp_encap_conf.ipv6_dst));
5215 memcpy(header, &ipv6, sizeof(ipv6));
5216 header += sizeof(ipv6);
5218 memcpy(header, &udp, sizeof(udp));
5219 header += sizeof(udp);
5220 memcpy(mpls.label_tc_s, mplsoudp_encap_conf.label,
5221 RTE_DIM(mplsoudp_encap_conf.label));
5222 mpls.label_tc_s[2] |= 0x1;
5223 memcpy(header, &mpls, sizeof(mpls));
5224 header += sizeof(mpls);
5225 action_encap_data->conf.size = header -
5226 action_encap_data->data;
5227 action->conf = &action_encap_data->conf;
5231 /** Parse MPLSOUDP decap action. */
5233 parse_vc_action_mplsoudp_decap(struct context *ctx, const struct token *token,
5234 const char *str, unsigned int len,
5235 void *buf, unsigned int size)
5237 struct buffer *out = buf;
5238 struct rte_flow_action *action;
5239 struct action_raw_decap_data *action_decap_data;
5240 struct rte_flow_item_eth eth = { .type = 0, };
5241 struct rte_flow_item_vlan vlan = {.tci = 0};
5242 struct rte_flow_item_ipv4 ipv4 = {
5244 .next_proto_id = IPPROTO_UDP,
5247 struct rte_flow_item_ipv6 ipv6 = {
5249 .proto = IPPROTO_UDP,
5252 struct rte_flow_item_udp udp = {
5254 .dst_port = rte_cpu_to_be_16(6635),
5257 struct rte_flow_item_mpls mpls;
5261 ret = parse_vc(ctx, token, str, len, buf, size);
5264 /* Nothing else to do if there is no buffer. */
5267 if (!out->args.vc.actions_n)
5269 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
5270 /* Point to selected object. */
5271 ctx->object = out->args.vc.data;
5272 ctx->objmask = NULL;
5273 /* Copy the headers to the buffer. */
5274 action_decap_data = ctx->object;
5275 *action_decap_data = (struct action_raw_decap_data) {
5276 .conf = (struct rte_flow_action_raw_decap){
5277 .data = action_decap_data->data,
5281 header = action_decap_data->data;
5282 if (mplsoudp_decap_conf.select_vlan)
5283 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
5284 else if (mplsoudp_encap_conf.select_ipv4)
5285 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
5287 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
5288 memcpy(eth.dst.addr_bytes,
5289 mplsoudp_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
5290 memcpy(eth.src.addr_bytes,
5291 mplsoudp_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
5292 memcpy(header, ð, sizeof(eth));
5293 header += sizeof(eth);
5294 if (mplsoudp_encap_conf.select_vlan) {
5295 if (mplsoudp_encap_conf.select_ipv4)
5296 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
5298 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
5299 memcpy(header, &vlan, sizeof(vlan));
5300 header += sizeof(vlan);
5302 if (mplsoudp_encap_conf.select_ipv4) {
5303 memcpy(header, &ipv4, sizeof(ipv4));
5304 header += sizeof(ipv4);
5306 memcpy(header, &ipv6, sizeof(ipv6));
5307 header += sizeof(ipv6);
5309 memcpy(header, &udp, sizeof(udp));
5310 header += sizeof(udp);
5311 memset(&mpls, 0, sizeof(mpls));
5312 memcpy(header, &mpls, sizeof(mpls));
5313 header += sizeof(mpls);
5314 action_decap_data->conf.size = header -
5315 action_decap_data->data;
5316 action->conf = &action_decap_data->conf;
5321 parse_vc_action_raw_decap_index(struct context *ctx, const struct token *token,
5322 const char *str, unsigned int len, void *buf,
5325 struct action_raw_decap_data *action_raw_decap_data;
5326 struct rte_flow_action *action;
5327 const struct arg *arg;
5328 struct buffer *out = buf;
5332 RTE_SET_USED(token);
5335 arg = ARGS_ENTRY_ARB_BOUNDED
5336 (offsetof(struct action_raw_decap_data, idx),
5337 sizeof(((struct action_raw_decap_data *)0)->idx),
5338 0, RAW_ENCAP_CONFS_MAX_NUM - 1);
5339 if (push_args(ctx, arg))
5341 ret = parse_int(ctx, token, str, len, NULL, 0);
5348 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
5349 action_raw_decap_data = ctx->object;
5350 idx = action_raw_decap_data->idx;
5351 action_raw_decap_data->conf.data = raw_decap_confs[idx].data;
5352 action_raw_decap_data->conf.size = raw_decap_confs[idx].size;
5353 action->conf = &action_raw_decap_data->conf;
5359 parse_vc_action_raw_encap_index(struct context *ctx, const struct token *token,
5360 const char *str, unsigned int len, void *buf,
5363 struct action_raw_encap_data *action_raw_encap_data;
5364 struct rte_flow_action *action;
5365 const struct arg *arg;
5366 struct buffer *out = buf;
5370 RTE_SET_USED(token);
5373 if (ctx->curr != ACTION_RAW_ENCAP_INDEX_VALUE)
5375 arg = ARGS_ENTRY_ARB_BOUNDED
5376 (offsetof(struct action_raw_encap_data, idx),
5377 sizeof(((struct action_raw_encap_data *)0)->idx),
5378 0, RAW_ENCAP_CONFS_MAX_NUM - 1);
5379 if (push_args(ctx, arg))
5381 ret = parse_int(ctx, token, str, len, NULL, 0);
5388 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
5389 action_raw_encap_data = ctx->object;
5390 idx = action_raw_encap_data->idx;
5391 action_raw_encap_data->conf.data = raw_encap_confs[idx].data;
5392 action_raw_encap_data->conf.size = raw_encap_confs[idx].size;
5393 action_raw_encap_data->conf.preserve = NULL;
5394 action->conf = &action_raw_encap_data->conf;
5399 parse_vc_action_raw_encap(struct context *ctx, const struct token *token,
5400 const char *str, unsigned int len, void *buf,
5403 struct buffer *out = buf;
5404 struct rte_flow_action *action;
5405 struct action_raw_encap_data *action_raw_encap_data = NULL;
5408 ret = parse_vc(ctx, token, str, len, buf, size);
5411 /* Nothing else to do if there is no buffer. */
5414 if (!out->args.vc.actions_n)
5416 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
5417 /* Point to selected object. */
5418 ctx->object = out->args.vc.data;
5419 ctx->objmask = NULL;
5420 /* Copy the headers to the buffer. */
5421 action_raw_encap_data = ctx->object;
5422 action_raw_encap_data->conf.data = raw_encap_confs[0].data;
5423 action_raw_encap_data->conf.preserve = NULL;
5424 action_raw_encap_data->conf.size = raw_encap_confs[0].size;
5425 action->conf = &action_raw_encap_data->conf;
5430 parse_vc_action_raw_decap(struct context *ctx, const struct token *token,
5431 const char *str, unsigned int len, void *buf,
5434 struct buffer *out = buf;
5435 struct rte_flow_action *action;
5436 struct action_raw_decap_data *action_raw_decap_data = NULL;
5439 ret = parse_vc(ctx, token, str, len, buf, size);
5442 /* Nothing else to do if there is no buffer. */
5445 if (!out->args.vc.actions_n)
5447 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
5448 /* Point to selected object. */
5449 ctx->object = out->args.vc.data;
5450 ctx->objmask = NULL;
5451 /* Copy the headers to the buffer. */
5452 action_raw_decap_data = ctx->object;
5453 action_raw_decap_data->conf.data = raw_decap_confs[0].data;
5454 action_raw_decap_data->conf.size = raw_decap_confs[0].size;
5455 action->conf = &action_raw_decap_data->conf;
5460 parse_vc_action_set_meta(struct context *ctx, const struct token *token,
5461 const char *str, unsigned int len, void *buf,
5466 ret = parse_vc(ctx, token, str, len, buf, size);
5469 ret = rte_flow_dynf_metadata_register();
5476 parse_vc_action_sample(struct context *ctx, const struct token *token,
5477 const char *str, unsigned int len, void *buf,
5480 struct buffer *out = buf;
5481 struct rte_flow_action *action;
5482 struct action_sample_data *action_sample_data = NULL;
5483 static struct rte_flow_action end_action = {
5484 RTE_FLOW_ACTION_TYPE_END, 0
5488 ret = parse_vc(ctx, token, str, len, buf, size);
5491 /* Nothing else to do if there is no buffer. */
5494 if (!out->args.vc.actions_n)
5496 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
5497 /* Point to selected object. */
5498 ctx->object = out->args.vc.data;
5499 ctx->objmask = NULL;
5500 /* Copy the headers to the buffer. */
5501 action_sample_data = ctx->object;
5502 action_sample_data->conf.actions = &end_action;
5503 action->conf = &action_sample_data->conf;
5508 parse_vc_action_sample_index(struct context *ctx, const struct token *token,
5509 const char *str, unsigned int len, void *buf,
5512 struct action_sample_data *action_sample_data;
5513 struct rte_flow_action *action;
5514 const struct arg *arg;
5515 struct buffer *out = buf;
5519 RTE_SET_USED(token);
5522 if (ctx->curr != ACTION_SAMPLE_INDEX_VALUE)
5524 arg = ARGS_ENTRY_ARB_BOUNDED
5525 (offsetof(struct action_sample_data, idx),
5526 sizeof(((struct action_sample_data *)0)->idx),
5527 0, RAW_SAMPLE_CONFS_MAX_NUM - 1);
5528 if (push_args(ctx, arg))
5530 ret = parse_int(ctx, token, str, len, NULL, 0);
5537 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
5538 action_sample_data = ctx->object;
5539 idx = action_sample_data->idx;
5540 action_sample_data->conf.actions = raw_sample_confs[idx].data;
5541 action->conf = &action_sample_data->conf;
5545 /** Parse tokens for destroy command. */
5547 parse_destroy(struct context *ctx, const struct token *token,
5548 const char *str, unsigned int len,
5549 void *buf, unsigned int size)
5551 struct buffer *out = buf;
5553 /* Token name must match. */
5554 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5556 /* Nothing else to do if there is no buffer. */
5559 if (!out->command) {
5560 if (ctx->curr != DESTROY)
5562 if (sizeof(*out) > size)
5564 out->command = ctx->curr;
5567 ctx->objmask = NULL;
5568 out->args.destroy.rule =
5569 (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
5573 if (((uint8_t *)(out->args.destroy.rule + out->args.destroy.rule_n) +
5574 sizeof(*out->args.destroy.rule)) > (uint8_t *)out + size)
5577 ctx->object = out->args.destroy.rule + out->args.destroy.rule_n++;
5578 ctx->objmask = NULL;
5582 /** Parse tokens for flush command. */
5584 parse_flush(struct context *ctx, const struct token *token,
5585 const char *str, unsigned int len,
5586 void *buf, unsigned int size)
5588 struct buffer *out = buf;
5590 /* Token name must match. */
5591 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5593 /* Nothing else to do if there is no buffer. */
5596 if (!out->command) {
5597 if (ctx->curr != FLUSH)
5599 if (sizeof(*out) > size)
5601 out->command = ctx->curr;
5604 ctx->objmask = NULL;
5609 /** Parse tokens for dump command. */
5611 parse_dump(struct context *ctx, const struct token *token,
5612 const char *str, unsigned int len,
5613 void *buf, unsigned int size)
5615 struct buffer *out = buf;
5617 /* Token name must match. */
5618 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5620 /* Nothing else to do if there is no buffer. */
5623 if (!out->command) {
5624 if (ctx->curr != DUMP)
5626 if (sizeof(*out) > size)
5628 out->command = ctx->curr;
5631 ctx->objmask = NULL;
5636 /** Parse tokens for query command. */
5638 parse_query(struct context *ctx, const struct token *token,
5639 const char *str, unsigned int len,
5640 void *buf, unsigned int size)
5642 struct buffer *out = buf;
5644 /* Token name must match. */
5645 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5647 /* Nothing else to do if there is no buffer. */
5650 if (!out->command) {
5651 if (ctx->curr != QUERY)
5653 if (sizeof(*out) > size)
5655 out->command = ctx->curr;
5658 ctx->objmask = NULL;
5663 /** Parse action names. */
5665 parse_action(struct context *ctx, const struct token *token,
5666 const char *str, unsigned int len,
5667 void *buf, unsigned int size)
5669 struct buffer *out = buf;
5670 const struct arg *arg = pop_args(ctx);
5674 /* Argument is expected. */
5677 /* Parse action name. */
5678 for (i = 0; next_action[i]; ++i) {
5679 const struct parse_action_priv *priv;
5681 token = &token_list[next_action[i]];
5682 if (strcmp_partial(token->name, str, len))
5688 memcpy((uint8_t *)ctx->object + arg->offset,
5694 push_args(ctx, arg);
5698 /** Parse tokens for list command. */
5700 parse_list(struct context *ctx, const struct token *token,
5701 const char *str, unsigned int len,
5702 void *buf, unsigned int size)
5704 struct buffer *out = buf;
5706 /* Token name must match. */
5707 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5709 /* Nothing else to do if there is no buffer. */
5712 if (!out->command) {
5713 if (ctx->curr != LIST)
5715 if (sizeof(*out) > size)
5717 out->command = ctx->curr;
5720 ctx->objmask = NULL;
5721 out->args.list.group =
5722 (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
5726 if (((uint8_t *)(out->args.list.group + out->args.list.group_n) +
5727 sizeof(*out->args.list.group)) > (uint8_t *)out + size)
5730 ctx->object = out->args.list.group + out->args.list.group_n++;
5731 ctx->objmask = NULL;
5735 /** Parse tokens for list all aged flows command. */
5737 parse_aged(struct context *ctx, const struct token *token,
5738 const char *str, unsigned int len,
5739 void *buf, unsigned int size)
5741 struct buffer *out = buf;
5743 /* Token name must match. */
5744 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5746 /* Nothing else to do if there is no buffer. */
5749 if (!out->command) {
5750 if (ctx->curr != AGED)
5752 if (sizeof(*out) > size)
5754 out->command = ctx->curr;
5757 ctx->objmask = NULL;
5759 if (ctx->curr == AGED_DESTROY)
5760 out->args.aged.destroy = 1;
5764 /** Parse tokens for isolate command. */
5766 parse_isolate(struct context *ctx, const struct token *token,
5767 const char *str, unsigned int len,
5768 void *buf, unsigned int size)
5770 struct buffer *out = buf;
5772 /* Token name must match. */
5773 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5775 /* Nothing else to do if there is no buffer. */
5778 if (!out->command) {
5779 if (ctx->curr != ISOLATE)
5781 if (sizeof(*out) > size)
5783 out->command = ctx->curr;
5786 ctx->objmask = NULL;
5792 * Parse signed/unsigned integers 8 to 64-bit long.
5794 * Last argument (ctx->args) is retrieved to determine integer type and
5798 parse_int(struct context *ctx, const struct token *token,
5799 const char *str, unsigned int len,
5800 void *buf, unsigned int size)
5802 const struct arg *arg = pop_args(ctx);
5807 /* Argument is expected. */
5812 (uintmax_t)strtoimax(str, &end, 0) :
5813 strtoumax(str, &end, 0);
5814 if (errno || (size_t)(end - str) != len)
5817 ((arg->sign && ((intmax_t)u < (intmax_t)arg->min ||
5818 (intmax_t)u > (intmax_t)arg->max)) ||
5819 (!arg->sign && (u < arg->min || u > arg->max))))
5824 if (!arg_entry_bf_fill(ctx->object, u, arg) ||
5825 !arg_entry_bf_fill(ctx->objmask, -1, arg))
5829 buf = (uint8_t *)ctx->object + arg->offset;
5831 if (u > RTE_LEN2MASK(size * CHAR_BIT, uint64_t))
5835 case sizeof(uint8_t):
5836 *(uint8_t *)buf = u;
5838 case sizeof(uint16_t):
5839 *(uint16_t *)buf = arg->hton ? rte_cpu_to_be_16(u) : u;
5841 case sizeof(uint8_t [3]):
5842 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
5844 ((uint8_t *)buf)[0] = u;
5845 ((uint8_t *)buf)[1] = u >> 8;
5846 ((uint8_t *)buf)[2] = u >> 16;
5850 ((uint8_t *)buf)[0] = u >> 16;
5851 ((uint8_t *)buf)[1] = u >> 8;
5852 ((uint8_t *)buf)[2] = u;
5854 case sizeof(uint32_t):
5855 *(uint32_t *)buf = arg->hton ? rte_cpu_to_be_32(u) : u;
5857 case sizeof(uint64_t):
5858 *(uint64_t *)buf = arg->hton ? rte_cpu_to_be_64(u) : u;
5863 if (ctx->objmask && buf != (uint8_t *)ctx->objmask + arg->offset) {
5865 buf = (uint8_t *)ctx->objmask + arg->offset;
5870 push_args(ctx, arg);
5877 * Three arguments (ctx->args) are retrieved from the stack to store data,
5878 * its actual length and address (in that order).
5881 parse_string(struct context *ctx, const struct token *token,
5882 const char *str, unsigned int len,
5883 void *buf, unsigned int size)
5885 const struct arg *arg_data = pop_args(ctx);
5886 const struct arg *arg_len = pop_args(ctx);
5887 const struct arg *arg_addr = pop_args(ctx);
5888 char tmp[16]; /* Ought to be enough. */
5891 /* Arguments are expected. */
5895 push_args(ctx, arg_data);
5899 push_args(ctx, arg_len);
5900 push_args(ctx, arg_data);
5903 size = arg_data->size;
5904 /* Bit-mask fill is not supported. */
5905 if (arg_data->mask || size < len)
5909 /* Let parse_int() fill length information first. */
5910 ret = snprintf(tmp, sizeof(tmp), "%u", len);
5913 push_args(ctx, arg_len);
5914 ret = parse_int(ctx, token, tmp, ret, NULL, 0);
5919 buf = (uint8_t *)ctx->object + arg_data->offset;
5920 /* Output buffer is not necessarily NUL-terminated. */
5921 memcpy(buf, str, len);
5922 memset((uint8_t *)buf + len, 0x00, size - len);
5924 memset((uint8_t *)ctx->objmask + arg_data->offset, 0xff, len);
5925 /* Save address if requested. */
5926 if (arg_addr->size) {
5927 memcpy((uint8_t *)ctx->object + arg_addr->offset,
5929 (uint8_t *)ctx->object + arg_data->offset
5933 memcpy((uint8_t *)ctx->objmask + arg_addr->offset,
5935 (uint8_t *)ctx->objmask + arg_data->offset
5941 push_args(ctx, arg_addr);
5942 push_args(ctx, arg_len);
5943 push_args(ctx, arg_data);
5948 parse_hex_string(const char *src, uint8_t *dst, uint32_t *size)
5954 /* Check input parameters */
5955 if ((src == NULL) ||
5961 /* Convert chars to bytes */
5962 for (i = 0, len = 0; i < *size; i += 2) {
5963 snprintf(tmp, 3, "%s", src + i);
5964 dst[len++] = strtoul(tmp, &c, 16);
5979 parse_hex(struct context *ctx, const struct token *token,
5980 const char *str, unsigned int len,
5981 void *buf, unsigned int size)
5983 const struct arg *arg_data = pop_args(ctx);
5984 const struct arg *arg_len = pop_args(ctx);
5985 const struct arg *arg_addr = pop_args(ctx);
5986 char tmp[16]; /* Ought to be enough. */
5988 unsigned int hexlen = len;
5989 unsigned int length = 256;
5990 uint8_t hex_tmp[length];
5992 /* Arguments are expected. */
5996 push_args(ctx, arg_data);
6000 push_args(ctx, arg_len);
6001 push_args(ctx, arg_data);
6004 size = arg_data->size;
6005 /* Bit-mask fill is not supported. */
6011 /* translate bytes string to array. */
6012 if (str[0] == '0' && ((str[1] == 'x') ||
6017 if (hexlen > length)
6019 ret = parse_hex_string(str, hex_tmp, &hexlen);
6022 /* Let parse_int() fill length information first. */
6023 ret = snprintf(tmp, sizeof(tmp), "%u", hexlen);
6026 push_args(ctx, arg_len);
6027 ret = parse_int(ctx, token, tmp, ret, NULL, 0);
6032 buf = (uint8_t *)ctx->object + arg_data->offset;
6033 /* Output buffer is not necessarily NUL-terminated. */
6034 memcpy(buf, hex_tmp, hexlen);
6035 memset((uint8_t *)buf + hexlen, 0x00, size - hexlen);
6037 memset((uint8_t *)ctx->objmask + arg_data->offset,
6039 /* Save address if requested. */
6040 if (arg_addr->size) {
6041 memcpy((uint8_t *)ctx->object + arg_addr->offset,
6043 (uint8_t *)ctx->object + arg_data->offset
6047 memcpy((uint8_t *)ctx->objmask + arg_addr->offset,
6049 (uint8_t *)ctx->objmask + arg_data->offset
6055 push_args(ctx, arg_addr);
6056 push_args(ctx, arg_len);
6057 push_args(ctx, arg_data);
6063 * Parse a zero-ended string.
6066 parse_string0(struct context *ctx, const struct token *token __rte_unused,
6067 const char *str, unsigned int len,
6068 void *buf, unsigned int size)
6070 const struct arg *arg_data = pop_args(ctx);
6072 /* Arguments are expected. */
6075 size = arg_data->size;
6076 /* Bit-mask fill is not supported. */
6077 if (arg_data->mask || size < len + 1)
6081 buf = (uint8_t *)ctx->object + arg_data->offset;
6082 strncpy(buf, str, len);
6084 memset((uint8_t *)ctx->objmask + arg_data->offset, 0xff, len);
6087 push_args(ctx, arg_data);
6092 * Parse a MAC address.
6094 * Last argument (ctx->args) is retrieved to determine storage size and
6098 parse_mac_addr(struct context *ctx, const struct token *token,
6099 const char *str, unsigned int len,
6100 void *buf, unsigned int size)
6102 const struct arg *arg = pop_args(ctx);
6103 struct rte_ether_addr tmp;
6107 /* Argument is expected. */
6111 /* Bit-mask fill is not supported. */
6112 if (arg->mask || size != sizeof(tmp))
6114 /* Only network endian is supported. */
6117 ret = cmdline_parse_etheraddr(NULL, str, &tmp, size);
6118 if (ret < 0 || (unsigned int)ret != len)
6122 buf = (uint8_t *)ctx->object + arg->offset;
6123 memcpy(buf, &tmp, size);
6125 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
6128 push_args(ctx, arg);
6133 * Parse an IPv4 address.
6135 * Last argument (ctx->args) is retrieved to determine storage size and
6139 parse_ipv4_addr(struct context *ctx, const struct token *token,
6140 const char *str, unsigned int len,
6141 void *buf, unsigned int size)
6143 const struct arg *arg = pop_args(ctx);
6148 /* Argument is expected. */
6152 /* Bit-mask fill is not supported. */
6153 if (arg->mask || size != sizeof(tmp))
6155 /* Only network endian is supported. */
6158 memcpy(str2, str, len);
6160 ret = inet_pton(AF_INET, str2, &tmp);
6162 /* Attempt integer parsing. */
6163 push_args(ctx, arg);
6164 return parse_int(ctx, token, str, len, buf, size);
6168 buf = (uint8_t *)ctx->object + arg->offset;
6169 memcpy(buf, &tmp, size);
6171 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
6174 push_args(ctx, arg);
6179 * Parse an IPv6 address.
6181 * Last argument (ctx->args) is retrieved to determine storage size and
6185 parse_ipv6_addr(struct context *ctx, const struct token *token,
6186 const char *str, unsigned int len,
6187 void *buf, unsigned int size)
6189 const struct arg *arg = pop_args(ctx);
6191 struct in6_addr tmp;
6195 /* Argument is expected. */
6199 /* Bit-mask fill is not supported. */
6200 if (arg->mask || size != sizeof(tmp))
6202 /* Only network endian is supported. */
6205 memcpy(str2, str, len);
6207 ret = inet_pton(AF_INET6, str2, &tmp);
6212 buf = (uint8_t *)ctx->object + arg->offset;
6213 memcpy(buf, &tmp, size);
6215 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
6218 push_args(ctx, arg);
6222 /** Boolean values (even indices stand for false). */
6223 static const char *const boolean_name[] = {
6233 * Parse a boolean value.
6235 * Last argument (ctx->args) is retrieved to determine storage size and
6239 parse_boolean(struct context *ctx, const struct token *token,
6240 const char *str, unsigned int len,
6241 void *buf, unsigned int size)
6243 const struct arg *arg = pop_args(ctx);
6247 /* Argument is expected. */
6250 for (i = 0; boolean_name[i]; ++i)
6251 if (!strcmp_partial(boolean_name[i], str, len))
6253 /* Process token as integer. */
6254 if (boolean_name[i])
6255 str = i & 1 ? "1" : "0";
6256 push_args(ctx, arg);
6257 ret = parse_int(ctx, token, str, strlen(str), buf, size);
6258 return ret > 0 ? (int)len : ret;
6261 /** Parse port and update context. */
6263 parse_port(struct context *ctx, const struct token *token,
6264 const char *str, unsigned int len,
6265 void *buf, unsigned int size)
6267 struct buffer *out = &(struct buffer){ .port = 0 };
6275 ctx->objmask = NULL;
6276 size = sizeof(*out);
6278 ret = parse_int(ctx, token, str, len, out, size);
6280 ctx->port = out->port;
6286 /** Parse set command, initialize output buffer for subsequent tokens. */
6288 parse_set_raw_encap_decap(struct context *ctx, const struct token *token,
6289 const char *str, unsigned int len,
6290 void *buf, unsigned int size)
6292 struct buffer *out = buf;
6294 /* Token name must match. */
6295 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
6297 /* Nothing else to do if there is no buffer. */
6300 /* Make sure buffer is large enough. */
6301 if (size < sizeof(*out))
6304 ctx->objmask = NULL;
6308 out->command = ctx->curr;
6309 /* For encap/decap we need is pattern */
6310 out->args.vc.pattern = (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
6315 /** Parse set command, initialize output buffer for subsequent tokens. */
6317 parse_set_sample_action(struct context *ctx, const struct token *token,
6318 const char *str, unsigned int len,
6319 void *buf, unsigned int size)
6321 struct buffer *out = buf;
6323 /* Token name must match. */
6324 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
6326 /* Nothing else to do if there is no buffer. */
6329 /* Make sure buffer is large enough. */
6330 if (size < sizeof(*out))
6333 ctx->objmask = NULL;
6337 out->command = ctx->curr;
6338 /* For sampler we need is actions */
6339 out->args.vc.actions = (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
6345 * Parse set raw_encap/raw_decap command,
6346 * initialize output buffer for subsequent tokens.
6349 parse_set_init(struct context *ctx, const struct token *token,
6350 const char *str, unsigned int len,
6351 void *buf, unsigned int size)
6353 struct buffer *out = buf;
6355 /* Token name must match. */
6356 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
6358 /* Nothing else to do if there is no buffer. */
6361 /* Make sure buffer is large enough. */
6362 if (size < sizeof(*out))
6364 /* Initialize buffer. */
6365 memset(out, 0x00, sizeof(*out));
6366 memset((uint8_t *)out + sizeof(*out), 0x22, size - sizeof(*out));
6369 ctx->objmask = NULL;
6370 if (!out->command) {
6371 if (ctx->curr != SET)
6373 if (sizeof(*out) > size)
6375 out->command = ctx->curr;
6376 out->args.vc.data = (uint8_t *)out + size;
6377 ctx->object = (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
6383 /** No completion. */
6385 comp_none(struct context *ctx, const struct token *token,
6386 unsigned int ent, char *buf, unsigned int size)
6396 /** Complete boolean values. */
6398 comp_boolean(struct context *ctx, const struct token *token,
6399 unsigned int ent, char *buf, unsigned int size)
6405 for (i = 0; boolean_name[i]; ++i)
6406 if (buf && i == ent)
6407 return strlcpy(buf, boolean_name[i], size);
6413 /** Complete action names. */
6415 comp_action(struct context *ctx, const struct token *token,
6416 unsigned int ent, char *buf, unsigned int size)
6422 for (i = 0; next_action[i]; ++i)
6423 if (buf && i == ent)
6424 return strlcpy(buf, token_list[next_action[i]].name,
6431 /** Complete available ports. */
6433 comp_port(struct context *ctx, const struct token *token,
6434 unsigned int ent, char *buf, unsigned int size)
6441 RTE_ETH_FOREACH_DEV(p) {
6442 if (buf && i == ent)
6443 return snprintf(buf, size, "%u", p);
6451 /** Complete available rule IDs. */
6453 comp_rule_id(struct context *ctx, const struct token *token,
6454 unsigned int ent, char *buf, unsigned int size)
6457 struct rte_port *port;
6458 struct port_flow *pf;
6461 if (port_id_is_invalid(ctx->port, DISABLED_WARN) ||
6462 ctx->port == (portid_t)RTE_PORT_ALL)
6464 port = &ports[ctx->port];
6465 for (pf = port->flow_list; pf != NULL; pf = pf->next) {
6466 if (buf && i == ent)
6467 return snprintf(buf, size, "%u", pf->id);
6475 /** Complete type field for RSS action. */
6477 comp_vc_action_rss_type(struct context *ctx, const struct token *token,
6478 unsigned int ent, char *buf, unsigned int size)
6484 for (i = 0; rss_type_table[i].str; ++i)
6489 return strlcpy(buf, rss_type_table[ent].str, size);
6491 return snprintf(buf, size, "end");
6495 /** Complete queue field for RSS action. */
6497 comp_vc_action_rss_queue(struct context *ctx, const struct token *token,
6498 unsigned int ent, char *buf, unsigned int size)
6505 return snprintf(buf, size, "%u", ent);
6507 return snprintf(buf, size, "end");
6511 /** Complete index number for set raw_encap/raw_decap commands. */
6513 comp_set_raw_index(struct context *ctx, const struct token *token,
6514 unsigned int ent, char *buf, unsigned int size)
6520 RTE_SET_USED(token);
6521 for (idx = 0; idx < RAW_ENCAP_CONFS_MAX_NUM; ++idx) {
6522 if (buf && idx == ent)
6523 return snprintf(buf, size, "%u", idx);
6529 /** Complete index number for set raw_encap/raw_decap commands. */
6531 comp_set_sample_index(struct context *ctx, const struct token *token,
6532 unsigned int ent, char *buf, unsigned int size)
6538 RTE_SET_USED(token);
6539 for (idx = 0; idx < RAW_SAMPLE_CONFS_MAX_NUM; ++idx) {
6540 if (buf && idx == ent)
6541 return snprintf(buf, size, "%u", idx);
6547 /** Internal context. */
6548 static struct context cmd_flow_context;
6550 /** Global parser instance (cmdline API). */
6551 cmdline_parse_inst_t cmd_flow;
6552 cmdline_parse_inst_t cmd_set_raw;
6554 /** Initialize context. */
6556 cmd_flow_context_init(struct context *ctx)
6558 /* A full memset() is not necessary. */
6568 ctx->objmask = NULL;
6571 /** Parse a token (cmdline API). */
6573 cmd_flow_parse(cmdline_parse_token_hdr_t *hdr, const char *src, void *result,
6576 struct context *ctx = &cmd_flow_context;
6577 const struct token *token;
6578 const enum index *list;
6583 token = &token_list[ctx->curr];
6584 /* Check argument length. */
6587 for (len = 0; src[len]; ++len)
6588 if (src[len] == '#' || isspace(src[len]))
6592 /* Last argument and EOL detection. */
6593 for (i = len; src[i]; ++i)
6594 if (src[i] == '#' || src[i] == '\r' || src[i] == '\n')
6596 else if (!isspace(src[i])) {
6601 if (src[i] == '\r' || src[i] == '\n') {
6605 /* Initialize context if necessary. */
6606 if (!ctx->next_num) {
6609 ctx->next[ctx->next_num++] = token->next[0];
6611 /* Process argument through candidates. */
6612 ctx->prev = ctx->curr;
6613 list = ctx->next[ctx->next_num - 1];
6614 for (i = 0; list[i]; ++i) {
6615 const struct token *next = &token_list[list[i]];
6618 ctx->curr = list[i];
6620 tmp = next->call(ctx, next, src, len, result, size);
6622 tmp = parse_default(ctx, next, src, len, result, size);
6623 if (tmp == -1 || tmp != len)
6631 /* Push subsequent tokens if any. */
6633 for (i = 0; token->next[i]; ++i) {
6634 if (ctx->next_num == RTE_DIM(ctx->next))
6636 ctx->next[ctx->next_num++] = token->next[i];
6638 /* Push arguments if any. */
6640 for (i = 0; token->args[i]; ++i) {
6641 if (ctx->args_num == RTE_DIM(ctx->args))
6643 ctx->args[ctx->args_num++] = token->args[i];
6648 /** Return number of completion entries (cmdline API). */
6650 cmd_flow_complete_get_nb(cmdline_parse_token_hdr_t *hdr)
6652 struct context *ctx = &cmd_flow_context;
6653 const struct token *token = &token_list[ctx->curr];
6654 const enum index *list;
6658 /* Count number of tokens in current list. */
6660 list = ctx->next[ctx->next_num - 1];
6662 list = token->next[0];
6663 for (i = 0; list[i]; ++i)
6668 * If there is a single token, use its completion callback, otherwise
6669 * return the number of entries.
6671 token = &token_list[list[0]];
6672 if (i == 1 && token->comp) {
6673 /* Save index for cmd_flow_get_help(). */
6674 ctx->prev = list[0];
6675 return token->comp(ctx, token, 0, NULL, 0);
6680 /** Return a completion entry (cmdline API). */
6682 cmd_flow_complete_get_elt(cmdline_parse_token_hdr_t *hdr, int index,
6683 char *dst, unsigned int size)
6685 struct context *ctx = &cmd_flow_context;
6686 const struct token *token = &token_list[ctx->curr];
6687 const enum index *list;
6691 /* Count number of tokens in current list. */
6693 list = ctx->next[ctx->next_num - 1];
6695 list = token->next[0];
6696 for (i = 0; list[i]; ++i)
6700 /* If there is a single token, use its completion callback. */
6701 token = &token_list[list[0]];
6702 if (i == 1 && token->comp) {
6703 /* Save index for cmd_flow_get_help(). */
6704 ctx->prev = list[0];
6705 return token->comp(ctx, token, index, dst, size) < 0 ? -1 : 0;
6707 /* Otherwise make sure the index is valid and use defaults. */
6710 token = &token_list[list[index]];
6711 strlcpy(dst, token->name, size);
6712 /* Save index for cmd_flow_get_help(). */
6713 ctx->prev = list[index];
6717 /** Populate help strings for current token (cmdline API). */
6719 cmd_flow_get_help(cmdline_parse_token_hdr_t *hdr, char *dst, unsigned int size)
6721 struct context *ctx = &cmd_flow_context;
6722 const struct token *token = &token_list[ctx->prev];
6727 /* Set token type and update global help with details. */
6728 strlcpy(dst, (token->type ? token->type : "TOKEN"), size);
6730 cmd_flow.help_str = token->help;
6732 cmd_flow.help_str = token->name;
6736 /** Token definition template (cmdline API). */
6737 static struct cmdline_token_hdr cmd_flow_token_hdr = {
6738 .ops = &(struct cmdline_token_ops){
6739 .parse = cmd_flow_parse,
6740 .complete_get_nb = cmd_flow_complete_get_nb,
6741 .complete_get_elt = cmd_flow_complete_get_elt,
6742 .get_help = cmd_flow_get_help,
6747 /** Populate the next dynamic token. */
6749 cmd_flow_tok(cmdline_parse_token_hdr_t **hdr,
6750 cmdline_parse_token_hdr_t **hdr_inst)
6752 struct context *ctx = &cmd_flow_context;
6754 /* Always reinitialize context before requesting the first token. */
6755 if (!(hdr_inst - cmd_flow.tokens))
6756 cmd_flow_context_init(ctx);
6757 /* Return NULL when no more tokens are expected. */
6758 if (!ctx->next_num && ctx->curr) {
6762 /* Determine if command should end here. */
6763 if (ctx->eol && ctx->last && ctx->next_num) {
6764 const enum index *list = ctx->next[ctx->next_num - 1];
6767 for (i = 0; list[i]; ++i) {
6774 *hdr = &cmd_flow_token_hdr;
6777 /** Dispatch parsed buffer to function calls. */
6779 cmd_flow_parsed(const struct buffer *in)
6781 switch (in->command) {
6783 port_flow_validate(in->port, &in->args.vc.attr,
6784 in->args.vc.pattern, in->args.vc.actions);
6787 port_flow_create(in->port, &in->args.vc.attr,
6788 in->args.vc.pattern, in->args.vc.actions);
6791 port_flow_destroy(in->port, in->args.destroy.rule_n,
6792 in->args.destroy.rule);
6795 port_flow_flush(in->port);
6798 port_flow_dump(in->port, in->args.dump.file);
6801 port_flow_query(in->port, in->args.query.rule,
6802 &in->args.query.action);
6805 port_flow_list(in->port, in->args.list.group_n,
6806 in->args.list.group);
6809 port_flow_isolate(in->port, in->args.isolate.set);
6812 port_flow_aged(in->port, in->args.aged.destroy);
6819 /** Token generator and output processing callback (cmdline API). */
6821 cmd_flow_cb(void *arg0, struct cmdline *cl, void *arg2)
6824 cmd_flow_tok(arg0, arg2);
6826 cmd_flow_parsed(arg0);
6829 /** Global parser instance (cmdline API). */
6830 cmdline_parse_inst_t cmd_flow = {
6832 .data = NULL, /**< Unused. */
6833 .help_str = NULL, /**< Updated by cmd_flow_get_help(). */
6836 }, /**< Tokens are returned by cmd_flow_tok(). */
6839 /** set cmd facility. Reuse cmd flow's infrastructure as much as possible. */
6842 update_fields(uint8_t *buf, struct rte_flow_item *item, uint16_t next_proto)
6844 struct rte_flow_item_ipv4 *ipv4;
6845 struct rte_flow_item_eth *eth;
6846 struct rte_flow_item_ipv6 *ipv6;
6847 struct rte_flow_item_vxlan *vxlan;
6848 struct rte_flow_item_vxlan_gpe *gpe;
6849 struct rte_flow_item_nvgre *nvgre;
6850 uint32_t ipv6_vtc_flow;
6852 switch (item->type) {
6853 case RTE_FLOW_ITEM_TYPE_ETH:
6854 eth = (struct rte_flow_item_eth *)buf;
6856 eth->type = rte_cpu_to_be_16(next_proto);
6858 case RTE_FLOW_ITEM_TYPE_IPV4:
6859 ipv4 = (struct rte_flow_item_ipv4 *)buf;
6860 ipv4->hdr.version_ihl = 0x45;
6861 if (next_proto && ipv4->hdr.next_proto_id == 0)
6862 ipv4->hdr.next_proto_id = (uint8_t)next_proto;
6864 case RTE_FLOW_ITEM_TYPE_IPV6:
6865 ipv6 = (struct rte_flow_item_ipv6 *)buf;
6866 if (next_proto && ipv6->hdr.proto == 0)
6867 ipv6->hdr.proto = (uint8_t)next_proto;
6868 ipv6_vtc_flow = rte_be_to_cpu_32(ipv6->hdr.vtc_flow);
6869 ipv6_vtc_flow &= 0x0FFFFFFF; /*< reset version bits. */
6870 ipv6_vtc_flow |= 0x60000000; /*< set ipv6 version. */
6871 ipv6->hdr.vtc_flow = rte_cpu_to_be_32(ipv6_vtc_flow);
6873 case RTE_FLOW_ITEM_TYPE_VXLAN:
6874 vxlan = (struct rte_flow_item_vxlan *)buf;
6875 vxlan->flags = 0x08;
6877 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
6878 gpe = (struct rte_flow_item_vxlan_gpe *)buf;
6881 case RTE_FLOW_ITEM_TYPE_NVGRE:
6882 nvgre = (struct rte_flow_item_nvgre *)buf;
6883 nvgre->protocol = rte_cpu_to_be_16(0x6558);
6884 nvgre->c_k_s_rsvd0_ver = rte_cpu_to_be_16(0x2000);
6891 /** Helper of get item's default mask. */
6893 flow_item_default_mask(const struct rte_flow_item *item)
6895 const void *mask = NULL;
6896 static rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
6898 switch (item->type) {
6899 case RTE_FLOW_ITEM_TYPE_ANY:
6900 mask = &rte_flow_item_any_mask;
6902 case RTE_FLOW_ITEM_TYPE_VF:
6903 mask = &rte_flow_item_vf_mask;
6905 case RTE_FLOW_ITEM_TYPE_PORT_ID:
6906 mask = &rte_flow_item_port_id_mask;
6908 case RTE_FLOW_ITEM_TYPE_RAW:
6909 mask = &rte_flow_item_raw_mask;
6911 case RTE_FLOW_ITEM_TYPE_ETH:
6912 mask = &rte_flow_item_eth_mask;
6914 case RTE_FLOW_ITEM_TYPE_VLAN:
6915 mask = &rte_flow_item_vlan_mask;
6917 case RTE_FLOW_ITEM_TYPE_IPV4:
6918 mask = &rte_flow_item_ipv4_mask;
6920 case RTE_FLOW_ITEM_TYPE_IPV6:
6921 mask = &rte_flow_item_ipv6_mask;
6923 case RTE_FLOW_ITEM_TYPE_ICMP:
6924 mask = &rte_flow_item_icmp_mask;
6926 case RTE_FLOW_ITEM_TYPE_UDP:
6927 mask = &rte_flow_item_udp_mask;
6929 case RTE_FLOW_ITEM_TYPE_TCP:
6930 mask = &rte_flow_item_tcp_mask;
6932 case RTE_FLOW_ITEM_TYPE_SCTP:
6933 mask = &rte_flow_item_sctp_mask;
6935 case RTE_FLOW_ITEM_TYPE_VXLAN:
6936 mask = &rte_flow_item_vxlan_mask;
6938 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
6939 mask = &rte_flow_item_vxlan_gpe_mask;
6941 case RTE_FLOW_ITEM_TYPE_E_TAG:
6942 mask = &rte_flow_item_e_tag_mask;
6944 case RTE_FLOW_ITEM_TYPE_NVGRE:
6945 mask = &rte_flow_item_nvgre_mask;
6947 case RTE_FLOW_ITEM_TYPE_MPLS:
6948 mask = &rte_flow_item_mpls_mask;
6950 case RTE_FLOW_ITEM_TYPE_GRE:
6951 mask = &rte_flow_item_gre_mask;
6953 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
6954 mask = &gre_key_default_mask;
6956 case RTE_FLOW_ITEM_TYPE_META:
6957 mask = &rte_flow_item_meta_mask;
6959 case RTE_FLOW_ITEM_TYPE_FUZZY:
6960 mask = &rte_flow_item_fuzzy_mask;
6962 case RTE_FLOW_ITEM_TYPE_GTP:
6963 mask = &rte_flow_item_gtp_mask;
6965 case RTE_FLOW_ITEM_TYPE_GTP_PSC:
6966 mask = &rte_flow_item_gtp_psc_mask;
6968 case RTE_FLOW_ITEM_TYPE_GENEVE:
6969 mask = &rte_flow_item_geneve_mask;
6971 case RTE_FLOW_ITEM_TYPE_PPPOE_PROTO_ID:
6972 mask = &rte_flow_item_pppoe_proto_id_mask;
6974 case RTE_FLOW_ITEM_TYPE_L2TPV3OIP:
6975 mask = &rte_flow_item_l2tpv3oip_mask;
6977 case RTE_FLOW_ITEM_TYPE_ESP:
6978 mask = &rte_flow_item_esp_mask;
6980 case RTE_FLOW_ITEM_TYPE_AH:
6981 mask = &rte_flow_item_ah_mask;
6983 case RTE_FLOW_ITEM_TYPE_PFCP:
6984 mask = &rte_flow_item_pfcp_mask;
6992 /** Dispatch parsed buffer to function calls. */
6994 cmd_set_raw_parsed_sample(const struct buffer *in)
6996 uint32_t n = in->args.vc.actions_n;
6998 struct rte_flow_action *action = NULL;
6999 struct rte_flow_action *data = NULL;
7001 uint16_t idx = in->port; /* We borrow port field as index */
7002 uint32_t max_size = sizeof(struct rte_flow_action) *
7003 ACTION_SAMPLE_ACTIONS_NUM;
7005 RTE_ASSERT(in->command == SET_SAMPLE_ACTIONS);
7006 data = (struct rte_flow_action *)&raw_sample_confs[idx].data;
7007 memset(data, 0x00, max_size);
7008 for (; i <= n - 1; i++) {
7009 action = in->args.vc.actions + i;
7010 if (action->type == RTE_FLOW_ACTION_TYPE_END)
7012 switch (action->type) {
7013 case RTE_FLOW_ACTION_TYPE_MARK:
7014 size = sizeof(struct rte_flow_action_mark);
7015 rte_memcpy(&sample_mark[idx],
7016 (const void *)action->conf, size);
7017 action->conf = &sample_mark[idx];
7019 case RTE_FLOW_ACTION_TYPE_COUNT:
7020 size = sizeof(struct rte_flow_action_count);
7021 rte_memcpy(&sample_count[idx],
7022 (const void *)action->conf, size);
7023 action->conf = &sample_count[idx];
7025 case RTE_FLOW_ACTION_TYPE_QUEUE:
7026 size = sizeof(struct rte_flow_action_queue);
7027 rte_memcpy(&sample_queue[idx],
7028 (const void *)action->conf, size);
7029 action->conf = &sample_queue[idx];
7032 printf("Error - Not supported action\n");
7035 rte_memcpy(data, action, sizeof(struct rte_flow_action));
7040 /** Dispatch parsed buffer to function calls. */
7042 cmd_set_raw_parsed(const struct buffer *in)
7044 uint32_t n = in->args.vc.pattern_n;
7046 struct rte_flow_item *item = NULL;
7048 uint8_t *data = NULL;
7049 uint8_t *data_tail = NULL;
7050 size_t *total_size = NULL;
7051 uint16_t upper_layer = 0;
7053 uint16_t idx = in->port; /* We borrow port field as index */
7055 if (in->command == SET_SAMPLE_ACTIONS)
7056 return cmd_set_raw_parsed_sample(in);
7057 RTE_ASSERT(in->command == SET_RAW_ENCAP ||
7058 in->command == SET_RAW_DECAP);
7059 if (in->command == SET_RAW_ENCAP) {
7060 total_size = &raw_encap_confs[idx].size;
7061 data = (uint8_t *)&raw_encap_confs[idx].data;
7063 total_size = &raw_decap_confs[idx].size;
7064 data = (uint8_t *)&raw_decap_confs[idx].data;
7067 memset(data, 0x00, ACTION_RAW_ENCAP_MAX_DATA);
7068 /* process hdr from upper layer to low layer (L3/L4 -> L2). */
7069 data_tail = data + ACTION_RAW_ENCAP_MAX_DATA;
7070 for (i = n - 1 ; i >= 0; --i) {
7071 item = in->args.vc.pattern + i;
7072 if (item->spec == NULL)
7073 item->spec = flow_item_default_mask(item);
7074 switch (item->type) {
7075 case RTE_FLOW_ITEM_TYPE_ETH:
7076 size = sizeof(struct rte_flow_item_eth);
7078 case RTE_FLOW_ITEM_TYPE_VLAN:
7079 size = sizeof(struct rte_flow_item_vlan);
7080 proto = RTE_ETHER_TYPE_VLAN;
7082 case RTE_FLOW_ITEM_TYPE_IPV4:
7083 size = sizeof(struct rte_flow_item_ipv4);
7084 proto = RTE_ETHER_TYPE_IPV4;
7086 case RTE_FLOW_ITEM_TYPE_IPV6:
7087 size = sizeof(struct rte_flow_item_ipv6);
7088 proto = RTE_ETHER_TYPE_IPV6;
7090 case RTE_FLOW_ITEM_TYPE_UDP:
7091 size = sizeof(struct rte_flow_item_udp);
7094 case RTE_FLOW_ITEM_TYPE_TCP:
7095 size = sizeof(struct rte_flow_item_tcp);
7098 case RTE_FLOW_ITEM_TYPE_VXLAN:
7099 size = sizeof(struct rte_flow_item_vxlan);
7101 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
7102 size = sizeof(struct rte_flow_item_vxlan_gpe);
7104 case RTE_FLOW_ITEM_TYPE_GRE:
7105 size = sizeof(struct rte_flow_item_gre);
7108 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
7109 size = sizeof(rte_be32_t);
7112 case RTE_FLOW_ITEM_TYPE_MPLS:
7113 size = sizeof(struct rte_flow_item_mpls);
7116 case RTE_FLOW_ITEM_TYPE_NVGRE:
7117 size = sizeof(struct rte_flow_item_nvgre);
7120 case RTE_FLOW_ITEM_TYPE_GENEVE:
7121 size = sizeof(struct rte_flow_item_geneve);
7123 case RTE_FLOW_ITEM_TYPE_L2TPV3OIP:
7124 size = sizeof(struct rte_flow_item_l2tpv3oip);
7127 case RTE_FLOW_ITEM_TYPE_ESP:
7128 size = sizeof(struct rte_flow_item_esp);
7131 case RTE_FLOW_ITEM_TYPE_AH:
7132 size = sizeof(struct rte_flow_item_ah);
7135 case RTE_FLOW_ITEM_TYPE_GTP:
7136 size = sizeof(struct rte_flow_item_gtp);
7138 case RTE_FLOW_ITEM_TYPE_PFCP:
7139 size = sizeof(struct rte_flow_item_pfcp);
7142 printf("Error - Not supported item\n");
7144 memset(data, 0x00, ACTION_RAW_ENCAP_MAX_DATA);
7147 *total_size += size;
7148 rte_memcpy(data_tail - (*total_size), item->spec, size);
7149 /* update some fields which cannot be set by cmdline */
7150 update_fields((data_tail - (*total_size)), item,
7152 upper_layer = proto;
7154 if (verbose_level & 0x1)
7155 printf("total data size is %zu\n", (*total_size));
7156 RTE_ASSERT((*total_size) <= ACTION_RAW_ENCAP_MAX_DATA);
7157 memmove(data, (data_tail - (*total_size)), *total_size);
7160 /** Populate help strings for current token (cmdline API). */
7162 cmd_set_raw_get_help(cmdline_parse_token_hdr_t *hdr, char *dst,
7165 struct context *ctx = &cmd_flow_context;
7166 const struct token *token = &token_list[ctx->prev];
7171 /* Set token type and update global help with details. */
7172 snprintf(dst, size, "%s", (token->type ? token->type : "TOKEN"));
7174 cmd_set_raw.help_str = token->help;
7176 cmd_set_raw.help_str = token->name;
7180 /** Token definition template (cmdline API). */
7181 static struct cmdline_token_hdr cmd_set_raw_token_hdr = {
7182 .ops = &(struct cmdline_token_ops){
7183 .parse = cmd_flow_parse,
7184 .complete_get_nb = cmd_flow_complete_get_nb,
7185 .complete_get_elt = cmd_flow_complete_get_elt,
7186 .get_help = cmd_set_raw_get_help,
7191 /** Populate the next dynamic token. */
7193 cmd_set_raw_tok(cmdline_parse_token_hdr_t **hdr,
7194 cmdline_parse_token_hdr_t **hdr_inst)
7196 struct context *ctx = &cmd_flow_context;
7198 /* Always reinitialize context before requesting the first token. */
7199 if (!(hdr_inst - cmd_set_raw.tokens)) {
7200 cmd_flow_context_init(ctx);
7201 ctx->curr = START_SET;
7203 /* Return NULL when no more tokens are expected. */
7204 if (!ctx->next_num && (ctx->curr != START_SET)) {
7208 /* Determine if command should end here. */
7209 if (ctx->eol && ctx->last && ctx->next_num) {
7210 const enum index *list = ctx->next[ctx->next_num - 1];
7213 for (i = 0; list[i]; ++i) {
7220 *hdr = &cmd_set_raw_token_hdr;
7223 /** Token generator and output processing callback (cmdline API). */
7225 cmd_set_raw_cb(void *arg0, struct cmdline *cl, void *arg2)
7228 cmd_set_raw_tok(arg0, arg2);
7230 cmd_set_raw_parsed(arg0);
7233 /** Global parser instance (cmdline API). */
7234 cmdline_parse_inst_t cmd_set_raw = {
7235 .f = cmd_set_raw_cb,
7236 .data = NULL, /**< Unused. */
7237 .help_str = NULL, /**< Updated by cmd_flow_get_help(). */
7240 }, /**< Tokens are returned by cmd_flow_tok(). */
7243 /* *** display raw_encap/raw_decap buf */
7244 struct cmd_show_set_raw_result {
7245 cmdline_fixed_string_t cmd_show;
7246 cmdline_fixed_string_t cmd_what;
7247 cmdline_fixed_string_t cmd_all;
7252 cmd_show_set_raw_parsed(void *parsed_result, struct cmdline *cl, void *data)
7254 struct cmd_show_set_raw_result *res = parsed_result;
7255 uint16_t index = res->cmd_index;
7257 uint8_t *raw_data = NULL;
7258 size_t raw_size = 0;
7259 char title[16] = {0};
7263 if (!strcmp(res->cmd_all, "all")) {
7266 } else if (index >= RAW_ENCAP_CONFS_MAX_NUM) {
7267 printf("index should be 0-%u\n", RAW_ENCAP_CONFS_MAX_NUM - 1);
7271 if (!strcmp(res->cmd_what, "raw_encap")) {
7272 raw_data = (uint8_t *)&raw_encap_confs[index].data;
7273 raw_size = raw_encap_confs[index].size;
7274 snprintf(title, 16, "\nindex: %u", index);
7275 rte_hexdump(stdout, title, raw_data, raw_size);
7277 raw_data = (uint8_t *)&raw_decap_confs[index].data;
7278 raw_size = raw_decap_confs[index].size;
7279 snprintf(title, 16, "\nindex: %u", index);
7280 rte_hexdump(stdout, title, raw_data, raw_size);
7282 } while (all && ++index < RAW_ENCAP_CONFS_MAX_NUM);
7285 cmdline_parse_token_string_t cmd_show_set_raw_cmd_show =
7286 TOKEN_STRING_INITIALIZER(struct cmd_show_set_raw_result,
7288 cmdline_parse_token_string_t cmd_show_set_raw_cmd_what =
7289 TOKEN_STRING_INITIALIZER(struct cmd_show_set_raw_result,
7290 cmd_what, "raw_encap#raw_decap");
7291 cmdline_parse_token_num_t cmd_show_set_raw_cmd_index =
7292 TOKEN_NUM_INITIALIZER(struct cmd_show_set_raw_result,
7294 cmdline_parse_token_string_t cmd_show_set_raw_cmd_all =
7295 TOKEN_STRING_INITIALIZER(struct cmd_show_set_raw_result,
7297 cmdline_parse_inst_t cmd_show_set_raw = {
7298 .f = cmd_show_set_raw_parsed,
7300 .help_str = "show <raw_encap|raw_decap> <index>",
7302 (void *)&cmd_show_set_raw_cmd_show,
7303 (void *)&cmd_show_set_raw_cmd_what,
7304 (void *)&cmd_show_set_raw_cmd_index,
7308 cmdline_parse_inst_t cmd_show_set_raw_all = {
7309 .f = cmd_show_set_raw_parsed,
7311 .help_str = "show <raw_encap|raw_decap> all",
7313 (void *)&cmd_show_set_raw_cmd_show,
7314 (void *)&cmd_show_set_raw_cmd_what,
7315 (void *)&cmd_show_set_raw_cmd_all,