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>
29 /** Parser token indices. */
53 /* Top-level command. */
55 /* Sub-leve commands. */
60 /* Top-level command. */
62 /* Sub-level commands. */
72 /* Destroy arguments. */
75 /* Query arguments. */
81 /* Validate/create arguments. */
88 /* Validate/create pattern. */
125 ITEM_VLAN_INNER_TYPE,
157 ITEM_E_TAG_GRP_ECID_B,
166 ITEM_GRE_C_RSVD0_VER,
184 ITEM_ARP_ETH_IPV4_SHA,
185 ITEM_ARP_ETH_IPV4_SPA,
186 ITEM_ARP_ETH_IPV4_THA,
187 ITEM_ARP_ETH_IPV4_TPA,
189 ITEM_IPV6_EXT_NEXT_HDR,
194 ITEM_ICMP6_ND_NS_TARGET_ADDR,
196 ITEM_ICMP6_ND_NA_TARGET_ADDR,
198 ITEM_ICMP6_ND_OPT_TYPE,
199 ITEM_ICMP6_ND_OPT_SLA_ETH,
200 ITEM_ICMP6_ND_OPT_SLA_ETH_SLA,
201 ITEM_ICMP6_ND_OPT_TLA_ETH,
202 ITEM_ICMP6_ND_OPT_TLA_ETH_TLA,
215 ITEM_HIGIG2_CLASSIFICATION,
221 ITEM_L2TPV3OIP_SESSION_ID,
230 /* Validate/create actions. */
250 ACTION_RSS_FUNC_DEFAULT,
251 ACTION_RSS_FUNC_TOEPLITZ,
252 ACTION_RSS_FUNC_SIMPLE_XOR,
253 ACTION_RSS_FUNC_SYMMETRIC_TOEPLITZ,
265 ACTION_PHY_PORT_ORIGINAL,
266 ACTION_PHY_PORT_INDEX,
268 ACTION_PORT_ID_ORIGINAL,
272 ACTION_OF_SET_MPLS_TTL,
273 ACTION_OF_SET_MPLS_TTL_MPLS_TTL,
274 ACTION_OF_DEC_MPLS_TTL,
275 ACTION_OF_SET_NW_TTL,
276 ACTION_OF_SET_NW_TTL_NW_TTL,
277 ACTION_OF_DEC_NW_TTL,
278 ACTION_OF_COPY_TTL_OUT,
279 ACTION_OF_COPY_TTL_IN,
282 ACTION_OF_PUSH_VLAN_ETHERTYPE,
283 ACTION_OF_SET_VLAN_VID,
284 ACTION_OF_SET_VLAN_VID_VLAN_VID,
285 ACTION_OF_SET_VLAN_PCP,
286 ACTION_OF_SET_VLAN_PCP_VLAN_PCP,
288 ACTION_OF_POP_MPLS_ETHERTYPE,
290 ACTION_OF_PUSH_MPLS_ETHERTYPE,
297 ACTION_MPLSOGRE_ENCAP,
298 ACTION_MPLSOGRE_DECAP,
299 ACTION_MPLSOUDP_ENCAP,
300 ACTION_MPLSOUDP_DECAP,
302 ACTION_SET_IPV4_SRC_IPV4_SRC,
304 ACTION_SET_IPV4_DST_IPV4_DST,
306 ACTION_SET_IPV6_SRC_IPV6_SRC,
308 ACTION_SET_IPV6_DST_IPV6_DST,
310 ACTION_SET_TP_SRC_TP_SRC,
312 ACTION_SET_TP_DST_TP_DST,
318 ACTION_SET_MAC_SRC_MAC_SRC,
320 ACTION_SET_MAC_DST_MAC_DST,
322 ACTION_INC_TCP_SEQ_VALUE,
324 ACTION_DEC_TCP_SEQ_VALUE,
326 ACTION_INC_TCP_ACK_VALUE,
328 ACTION_DEC_TCP_ACK_VALUE,
331 ACTION_RAW_ENCAP_INDEX,
332 ACTION_RAW_ENCAP_INDEX_VALUE,
333 ACTION_RAW_DECAP_INDEX,
334 ACTION_RAW_DECAP_INDEX_VALUE,
337 ACTION_SET_TAG_INDEX,
340 ACTION_SET_META_DATA,
341 ACTION_SET_META_MASK,
342 ACTION_SET_IPV4_DSCP,
343 ACTION_SET_IPV4_DSCP_VALUE,
344 ACTION_SET_IPV6_DSCP,
345 ACTION_SET_IPV6_DSCP_VALUE,
348 /** Maximum size for pattern in struct rte_flow_item_raw. */
349 #define ITEM_RAW_PATTERN_SIZE 40
351 /** Storage size for struct rte_flow_item_raw including pattern. */
352 #define ITEM_RAW_SIZE \
353 (sizeof(struct rte_flow_item_raw) + ITEM_RAW_PATTERN_SIZE)
355 /** Maximum number of queue indices in struct rte_flow_action_rss. */
356 #define ACTION_RSS_QUEUE_NUM 128
358 /** Storage for struct rte_flow_action_rss including external data. */
359 struct action_rss_data {
360 struct rte_flow_action_rss conf;
361 uint8_t key[RSS_HASH_KEY_LENGTH];
362 uint16_t queue[ACTION_RSS_QUEUE_NUM];
365 /** Maximum data size in struct rte_flow_action_raw_encap. */
366 #define ACTION_RAW_ENCAP_MAX_DATA 128
367 #define RAW_ENCAP_CONFS_MAX_NUM 8
369 /** Storage for struct rte_flow_action_raw_encap. */
370 struct raw_encap_conf {
371 uint8_t data[ACTION_RAW_ENCAP_MAX_DATA];
372 uint8_t preserve[ACTION_RAW_ENCAP_MAX_DATA];
376 struct raw_encap_conf raw_encap_confs[RAW_ENCAP_CONFS_MAX_NUM];
378 /** Storage for struct rte_flow_action_raw_encap including external data. */
379 struct action_raw_encap_data {
380 struct rte_flow_action_raw_encap conf;
381 uint8_t data[ACTION_RAW_ENCAP_MAX_DATA];
382 uint8_t preserve[ACTION_RAW_ENCAP_MAX_DATA];
386 /** Storage for struct rte_flow_action_raw_decap. */
387 struct raw_decap_conf {
388 uint8_t data[ACTION_RAW_ENCAP_MAX_DATA];
392 struct raw_decap_conf raw_decap_confs[RAW_ENCAP_CONFS_MAX_NUM];
394 /** Storage for struct rte_flow_action_raw_decap including external data. */
395 struct action_raw_decap_data {
396 struct rte_flow_action_raw_decap conf;
397 uint8_t data[ACTION_RAW_ENCAP_MAX_DATA];
401 struct vxlan_encap_conf vxlan_encap_conf = {
405 .vni = "\x00\x00\x00",
407 .udp_dst = RTE_BE16(4789),
408 .ipv4_src = RTE_IPV4(127, 0, 0, 1),
409 .ipv4_dst = RTE_IPV4(255, 255, 255, 255),
410 .ipv6_src = "\x00\x00\x00\x00\x00\x00\x00\x00"
411 "\x00\x00\x00\x00\x00\x00\x00\x01",
412 .ipv6_dst = "\x00\x00\x00\x00\x00\x00\x00\x00"
413 "\x00\x00\x00\x00\x00\x00\x11\x11",
417 .eth_src = "\x00\x00\x00\x00\x00\x00",
418 .eth_dst = "\xff\xff\xff\xff\xff\xff",
421 /** Maximum number of items in struct rte_flow_action_vxlan_encap. */
422 #define ACTION_VXLAN_ENCAP_ITEMS_NUM 6
424 /** Storage for struct rte_flow_action_vxlan_encap including external data. */
425 struct action_vxlan_encap_data {
426 struct rte_flow_action_vxlan_encap conf;
427 struct rte_flow_item items[ACTION_VXLAN_ENCAP_ITEMS_NUM];
428 struct rte_flow_item_eth item_eth;
429 struct rte_flow_item_vlan item_vlan;
431 struct rte_flow_item_ipv4 item_ipv4;
432 struct rte_flow_item_ipv6 item_ipv6;
434 struct rte_flow_item_udp item_udp;
435 struct rte_flow_item_vxlan item_vxlan;
438 struct nvgre_encap_conf nvgre_encap_conf = {
441 .tni = "\x00\x00\x00",
442 .ipv4_src = RTE_IPV4(127, 0, 0, 1),
443 .ipv4_dst = RTE_IPV4(255, 255, 255, 255),
444 .ipv6_src = "\x00\x00\x00\x00\x00\x00\x00\x00"
445 "\x00\x00\x00\x00\x00\x00\x00\x01",
446 .ipv6_dst = "\x00\x00\x00\x00\x00\x00\x00\x00"
447 "\x00\x00\x00\x00\x00\x00\x11\x11",
449 .eth_src = "\x00\x00\x00\x00\x00\x00",
450 .eth_dst = "\xff\xff\xff\xff\xff\xff",
453 /** Maximum number of items in struct rte_flow_action_nvgre_encap. */
454 #define ACTION_NVGRE_ENCAP_ITEMS_NUM 5
456 /** Storage for struct rte_flow_action_nvgre_encap including external data. */
457 struct action_nvgre_encap_data {
458 struct rte_flow_action_nvgre_encap conf;
459 struct rte_flow_item items[ACTION_NVGRE_ENCAP_ITEMS_NUM];
460 struct rte_flow_item_eth item_eth;
461 struct rte_flow_item_vlan item_vlan;
463 struct rte_flow_item_ipv4 item_ipv4;
464 struct rte_flow_item_ipv6 item_ipv6;
466 struct rte_flow_item_nvgre item_nvgre;
469 struct l2_encap_conf l2_encap_conf;
471 struct l2_decap_conf l2_decap_conf;
473 struct mplsogre_encap_conf mplsogre_encap_conf;
475 struct mplsogre_decap_conf mplsogre_decap_conf;
477 struct mplsoudp_encap_conf mplsoudp_encap_conf;
479 struct mplsoudp_decap_conf mplsoudp_decap_conf;
481 /** Maximum number of subsequent tokens and arguments on the stack. */
482 #define CTX_STACK_SIZE 16
484 /** Parser context. */
486 /** Stack of subsequent token lists to process. */
487 const enum index *next[CTX_STACK_SIZE];
488 /** Arguments for stacked tokens. */
489 const void *args[CTX_STACK_SIZE];
490 enum index curr; /**< Current token index. */
491 enum index prev; /**< Index of the last token seen. */
492 int next_num; /**< Number of entries in next[]. */
493 int args_num; /**< Number of entries in args[]. */
494 uint32_t eol:1; /**< EOL has been detected. */
495 uint32_t last:1; /**< No more arguments. */
496 portid_t port; /**< Current port ID (for completions). */
497 uint32_t objdata; /**< Object-specific data. */
498 void *object; /**< Address of current object for relative offsets. */
499 void *objmask; /**< Object a full mask must be written to. */
502 /** Token argument. */
504 uint32_t hton:1; /**< Use network byte ordering. */
505 uint32_t sign:1; /**< Value is signed. */
506 uint32_t bounded:1; /**< Value is bounded. */
507 uintmax_t min; /**< Minimum value if bounded. */
508 uintmax_t max; /**< Maximum value if bounded. */
509 uint32_t offset; /**< Relative offset from ctx->object. */
510 uint32_t size; /**< Field size. */
511 const uint8_t *mask; /**< Bit-mask to use instead of offset/size. */
514 /** Parser token definition. */
516 /** Type displayed during completion (defaults to "TOKEN"). */
518 /** Help displayed during completion (defaults to token name). */
520 /** Private data used by parser functions. */
523 * Lists of subsequent tokens to push on the stack. Each call to the
524 * parser consumes the last entry of that stack.
526 const enum index *const *next;
527 /** Arguments stack for subsequent tokens that need them. */
528 const struct arg *const *args;
530 * Token-processing callback, returns -1 in case of error, the
531 * length of the matched string otherwise. If NULL, attempts to
532 * match the token name.
534 * If buf is not NULL, the result should be stored in it according
535 * to context. An error is returned if not large enough.
537 int (*call)(struct context *ctx, const struct token *token,
538 const char *str, unsigned int len,
539 void *buf, unsigned int size);
541 * Callback that provides possible values for this token, used for
542 * completion. Returns -1 in case of error, the number of possible
543 * values otherwise. If NULL, the token name is used.
545 * If buf is not NULL, entry index ent is written to buf and the
546 * full length of the entry is returned (same behavior as
549 int (*comp)(struct context *ctx, const struct token *token,
550 unsigned int ent, char *buf, unsigned int size);
551 /** Mandatory token name, no default value. */
555 /** Static initializer for the next field. */
556 #define NEXT(...) (const enum index *const []){ __VA_ARGS__, NULL, }
558 /** Static initializer for a NEXT() entry. */
559 #define NEXT_ENTRY(...) (const enum index []){ __VA_ARGS__, ZERO, }
561 /** Static initializer for the args field. */
562 #define ARGS(...) (const struct arg *const []){ __VA_ARGS__, NULL, }
564 /** Static initializer for ARGS() to target a field. */
565 #define ARGS_ENTRY(s, f) \
566 (&(const struct arg){ \
567 .offset = offsetof(s, f), \
568 .size = sizeof(((s *)0)->f), \
571 /** Static initializer for ARGS() to target a bit-field. */
572 #define ARGS_ENTRY_BF(s, f, b) \
573 (&(const struct arg){ \
575 .mask = (const void *)&(const s){ .f = (1 << (b)) - 1 }, \
578 /** Static initializer for ARGS() to target an arbitrary bit-mask. */
579 #define ARGS_ENTRY_MASK(s, f, m) \
580 (&(const struct arg){ \
581 .offset = offsetof(s, f), \
582 .size = sizeof(((s *)0)->f), \
583 .mask = (const void *)(m), \
586 /** Same as ARGS_ENTRY_MASK() using network byte ordering for the value. */
587 #define ARGS_ENTRY_MASK_HTON(s, f, m) \
588 (&(const struct arg){ \
590 .offset = offsetof(s, f), \
591 .size = sizeof(((s *)0)->f), \
592 .mask = (const void *)(m), \
595 /** Static initializer for ARGS() to target a pointer. */
596 #define ARGS_ENTRY_PTR(s, f) \
597 (&(const struct arg){ \
598 .size = sizeof(*((s *)0)->f), \
601 /** Static initializer for ARGS() with arbitrary offset and size. */
602 #define ARGS_ENTRY_ARB(o, s) \
603 (&(const struct arg){ \
608 /** Same as ARGS_ENTRY_ARB() with bounded values. */
609 #define ARGS_ENTRY_ARB_BOUNDED(o, s, i, a) \
610 (&(const struct arg){ \
618 /** Same as ARGS_ENTRY() using network byte ordering. */
619 #define ARGS_ENTRY_HTON(s, f) \
620 (&(const struct arg){ \
622 .offset = offsetof(s, f), \
623 .size = sizeof(((s *)0)->f), \
626 /** Same as ARGS_ENTRY_HTON() for a single argument, without structure. */
627 #define ARG_ENTRY_HTON(s) \
628 (&(const struct arg){ \
634 /** Parser output buffer layout expected by cmd_flow_parsed(). */
636 enum index command; /**< Flow command. */
637 portid_t port; /**< Affected port ID. */
640 struct rte_flow_attr attr;
641 struct rte_flow_item *pattern;
642 struct rte_flow_action *actions;
646 } vc; /**< Validate/create arguments. */
650 } destroy; /**< Destroy arguments. */
653 } dump; /**< Dump arguments. */
656 struct rte_flow_action action;
657 } query; /**< Query arguments. */
661 } list; /**< List arguments. */
664 } isolate; /**< Isolated mode arguments. */
665 } args; /**< Command arguments. */
668 /** Private data for pattern items. */
669 struct parse_item_priv {
670 enum rte_flow_item_type type; /**< Item type. */
671 uint32_t size; /**< Size of item specification structure. */
674 #define PRIV_ITEM(t, s) \
675 (&(const struct parse_item_priv){ \
676 .type = RTE_FLOW_ITEM_TYPE_ ## t, \
680 /** Private data for actions. */
681 struct parse_action_priv {
682 enum rte_flow_action_type type; /**< Action type. */
683 uint32_t size; /**< Size of action configuration structure. */
686 #define PRIV_ACTION(t, s) \
687 (&(const struct parse_action_priv){ \
688 .type = RTE_FLOW_ACTION_TYPE_ ## t, \
692 static const enum index next_vc_attr[] = {
702 static const enum index next_destroy_attr[] = {
708 static const enum index next_dump_attr[] = {
714 static const enum index next_list_attr[] = {
720 static const enum index item_param[] = {
729 static const enum index next_item[] = {
765 ITEM_ICMP6_ND_OPT_SLA_ETH,
766 ITEM_ICMP6_ND_OPT_TLA_ETH,
783 static const enum index item_fuzzy[] = {
789 static const enum index item_any[] = {
795 static const enum index item_vf[] = {
801 static const enum index item_phy_port[] = {
807 static const enum index item_port_id[] = {
813 static const enum index item_mark[] = {
819 static const enum index item_raw[] = {
829 static const enum index item_eth[] = {
837 static const enum index item_vlan[] = {
842 ITEM_VLAN_INNER_TYPE,
847 static const enum index item_ipv4[] = {
857 static const enum index item_ipv6[] = {
868 static const enum index item_icmp[] = {
875 static const enum index item_udp[] = {
882 static const enum index item_tcp[] = {
890 static const enum index item_sctp[] = {
899 static const enum index item_vxlan[] = {
905 static const enum index item_e_tag[] = {
906 ITEM_E_TAG_GRP_ECID_B,
911 static const enum index item_nvgre[] = {
917 static const enum index item_mpls[] = {
925 static const enum index item_gre[] = {
927 ITEM_GRE_C_RSVD0_VER,
935 static const enum index item_gre_key[] = {
941 static const enum index item_gtp[] = {
949 static const enum index item_geneve[] = {
956 static const enum index item_vxlan_gpe[] = {
962 static const enum index item_arp_eth_ipv4[] = {
963 ITEM_ARP_ETH_IPV4_SHA,
964 ITEM_ARP_ETH_IPV4_SPA,
965 ITEM_ARP_ETH_IPV4_THA,
966 ITEM_ARP_ETH_IPV4_TPA,
971 static const enum index item_ipv6_ext[] = {
972 ITEM_IPV6_EXT_NEXT_HDR,
977 static const enum index item_icmp6[] = {
984 static const enum index item_icmp6_nd_ns[] = {
985 ITEM_ICMP6_ND_NS_TARGET_ADDR,
990 static const enum index item_icmp6_nd_na[] = {
991 ITEM_ICMP6_ND_NA_TARGET_ADDR,
996 static const enum index item_icmp6_nd_opt[] = {
997 ITEM_ICMP6_ND_OPT_TYPE,
1002 static const enum index item_icmp6_nd_opt_sla_eth[] = {
1003 ITEM_ICMP6_ND_OPT_SLA_ETH_SLA,
1008 static const enum index item_icmp6_nd_opt_tla_eth[] = {
1009 ITEM_ICMP6_ND_OPT_TLA_ETH_TLA,
1014 static const enum index item_meta[] = {
1020 static const enum index item_gtp_psc[] = {
1027 static const enum index item_pppoed[] = {
1033 static const enum index item_pppoes[] = {
1039 static const enum index item_pppoe_proto_id[] = {
1044 static const enum index item_higig2[] = {
1045 ITEM_HIGIG2_CLASSIFICATION,
1051 static const enum index item_esp[] = {
1057 static const enum index item_ah[] = {
1063 static const enum index item_pfcp[] = {
1070 static const enum index next_set_raw[] = {
1076 static const enum index item_tag[] = {
1083 static const enum index item_l2tpv3oip[] = {
1084 ITEM_L2TPV3OIP_SESSION_ID,
1089 static const enum index next_action[] = {
1105 ACTION_OF_SET_MPLS_TTL,
1106 ACTION_OF_DEC_MPLS_TTL,
1107 ACTION_OF_SET_NW_TTL,
1108 ACTION_OF_DEC_NW_TTL,
1109 ACTION_OF_COPY_TTL_OUT,
1110 ACTION_OF_COPY_TTL_IN,
1112 ACTION_OF_PUSH_VLAN,
1113 ACTION_OF_SET_VLAN_VID,
1114 ACTION_OF_SET_VLAN_PCP,
1116 ACTION_OF_PUSH_MPLS,
1123 ACTION_MPLSOGRE_ENCAP,
1124 ACTION_MPLSOGRE_DECAP,
1125 ACTION_MPLSOUDP_ENCAP,
1126 ACTION_MPLSOUDP_DECAP,
1127 ACTION_SET_IPV4_SRC,
1128 ACTION_SET_IPV4_DST,
1129 ACTION_SET_IPV6_SRC,
1130 ACTION_SET_IPV6_DST,
1146 ACTION_SET_IPV4_DSCP,
1147 ACTION_SET_IPV6_DSCP,
1151 static const enum index action_mark[] = {
1157 static const enum index action_queue[] = {
1163 static const enum index action_count[] = {
1165 ACTION_COUNT_SHARED,
1170 static const enum index action_rss[] = {
1181 static const enum index action_vf[] = {
1188 static const enum index action_phy_port[] = {
1189 ACTION_PHY_PORT_ORIGINAL,
1190 ACTION_PHY_PORT_INDEX,
1195 static const enum index action_port_id[] = {
1196 ACTION_PORT_ID_ORIGINAL,
1202 static const enum index action_meter[] = {
1208 static const enum index action_of_set_mpls_ttl[] = {
1209 ACTION_OF_SET_MPLS_TTL_MPLS_TTL,
1214 static const enum index action_of_set_nw_ttl[] = {
1215 ACTION_OF_SET_NW_TTL_NW_TTL,
1220 static const enum index action_of_push_vlan[] = {
1221 ACTION_OF_PUSH_VLAN_ETHERTYPE,
1226 static const enum index action_of_set_vlan_vid[] = {
1227 ACTION_OF_SET_VLAN_VID_VLAN_VID,
1232 static const enum index action_of_set_vlan_pcp[] = {
1233 ACTION_OF_SET_VLAN_PCP_VLAN_PCP,
1238 static const enum index action_of_pop_mpls[] = {
1239 ACTION_OF_POP_MPLS_ETHERTYPE,
1244 static const enum index action_of_push_mpls[] = {
1245 ACTION_OF_PUSH_MPLS_ETHERTYPE,
1250 static const enum index action_set_ipv4_src[] = {
1251 ACTION_SET_IPV4_SRC_IPV4_SRC,
1256 static const enum index action_set_mac_src[] = {
1257 ACTION_SET_MAC_SRC_MAC_SRC,
1262 static const enum index action_set_ipv4_dst[] = {
1263 ACTION_SET_IPV4_DST_IPV4_DST,
1268 static const enum index action_set_ipv6_src[] = {
1269 ACTION_SET_IPV6_SRC_IPV6_SRC,
1274 static const enum index action_set_ipv6_dst[] = {
1275 ACTION_SET_IPV6_DST_IPV6_DST,
1280 static const enum index action_set_tp_src[] = {
1281 ACTION_SET_TP_SRC_TP_SRC,
1286 static const enum index action_set_tp_dst[] = {
1287 ACTION_SET_TP_DST_TP_DST,
1292 static const enum index action_set_ttl[] = {
1298 static const enum index action_jump[] = {
1304 static const enum index action_set_mac_dst[] = {
1305 ACTION_SET_MAC_DST_MAC_DST,
1310 static const enum index action_inc_tcp_seq[] = {
1311 ACTION_INC_TCP_SEQ_VALUE,
1316 static const enum index action_dec_tcp_seq[] = {
1317 ACTION_DEC_TCP_SEQ_VALUE,
1322 static const enum index action_inc_tcp_ack[] = {
1323 ACTION_INC_TCP_ACK_VALUE,
1328 static const enum index action_dec_tcp_ack[] = {
1329 ACTION_DEC_TCP_ACK_VALUE,
1334 static const enum index action_raw_encap[] = {
1335 ACTION_RAW_ENCAP_INDEX,
1340 static const enum index action_raw_decap[] = {
1341 ACTION_RAW_DECAP_INDEX,
1346 static const enum index action_set_tag[] = {
1347 ACTION_SET_TAG_DATA,
1348 ACTION_SET_TAG_INDEX,
1349 ACTION_SET_TAG_MASK,
1354 static const enum index action_set_meta[] = {
1355 ACTION_SET_META_DATA,
1356 ACTION_SET_META_MASK,
1361 static const enum index action_set_ipv4_dscp[] = {
1362 ACTION_SET_IPV4_DSCP_VALUE,
1367 static const enum index action_set_ipv6_dscp[] = {
1368 ACTION_SET_IPV6_DSCP_VALUE,
1373 static int parse_set_raw_encap_decap(struct context *, const struct token *,
1374 const char *, unsigned int,
1375 void *, unsigned int);
1376 static int parse_set_init(struct context *, const struct token *,
1377 const char *, unsigned int,
1378 void *, unsigned int);
1379 static int parse_init(struct context *, const struct token *,
1380 const char *, unsigned int,
1381 void *, unsigned int);
1382 static int parse_vc(struct context *, const struct token *,
1383 const char *, unsigned int,
1384 void *, unsigned int);
1385 static int parse_vc_spec(struct context *, const struct token *,
1386 const char *, unsigned int, void *, unsigned int);
1387 static int parse_vc_conf(struct context *, const struct token *,
1388 const char *, unsigned int, void *, unsigned int);
1389 static int parse_vc_action_rss(struct context *, const struct token *,
1390 const char *, unsigned int, void *,
1392 static int parse_vc_action_rss_func(struct context *, const struct token *,
1393 const char *, unsigned int, void *,
1395 static int parse_vc_action_rss_type(struct context *, const struct token *,
1396 const char *, unsigned int, void *,
1398 static int parse_vc_action_rss_queue(struct context *, const struct token *,
1399 const char *, unsigned int, void *,
1401 static int parse_vc_action_vxlan_encap(struct context *, const struct token *,
1402 const char *, unsigned int, void *,
1404 static int parse_vc_action_nvgre_encap(struct context *, const struct token *,
1405 const char *, unsigned int, void *,
1407 static int parse_vc_action_l2_encap(struct context *, const struct token *,
1408 const char *, unsigned int, void *,
1410 static int parse_vc_action_l2_decap(struct context *, const struct token *,
1411 const char *, unsigned int, void *,
1413 static int parse_vc_action_mplsogre_encap(struct context *,
1414 const struct token *, const char *,
1415 unsigned int, void *, unsigned int);
1416 static int parse_vc_action_mplsogre_decap(struct context *,
1417 const struct token *, const char *,
1418 unsigned int, void *, unsigned int);
1419 static int parse_vc_action_mplsoudp_encap(struct context *,
1420 const struct token *, const char *,
1421 unsigned int, void *, unsigned int);
1422 static int parse_vc_action_mplsoudp_decap(struct context *,
1423 const struct token *, const char *,
1424 unsigned int, void *, unsigned int);
1425 static int parse_vc_action_raw_encap(struct context *,
1426 const struct token *, const char *,
1427 unsigned int, void *, unsigned int);
1428 static int parse_vc_action_raw_decap(struct context *,
1429 const struct token *, const char *,
1430 unsigned int, void *, unsigned int);
1431 static int parse_vc_action_raw_encap_index(struct context *,
1432 const struct token *, const char *,
1433 unsigned int, void *, unsigned int);
1434 static int parse_vc_action_raw_decap_index(struct context *,
1435 const struct token *, const char *,
1436 unsigned int, void *, unsigned int);
1437 static int parse_vc_action_set_meta(struct context *ctx,
1438 const struct token *token, const char *str,
1439 unsigned int len, void *buf,
1441 static int parse_destroy(struct context *, const struct token *,
1442 const char *, unsigned int,
1443 void *, unsigned int);
1444 static int parse_flush(struct context *, const struct token *,
1445 const char *, unsigned int,
1446 void *, unsigned int);
1447 static int parse_dump(struct context *, const struct token *,
1448 const char *, unsigned int,
1449 void *, unsigned int);
1450 static int parse_query(struct context *, const struct token *,
1451 const char *, unsigned int,
1452 void *, unsigned int);
1453 static int parse_action(struct context *, const struct token *,
1454 const char *, unsigned int,
1455 void *, unsigned int);
1456 static int parse_list(struct context *, const struct token *,
1457 const char *, unsigned int,
1458 void *, unsigned int);
1459 static int parse_isolate(struct context *, const struct token *,
1460 const char *, unsigned int,
1461 void *, unsigned int);
1462 static int parse_int(struct context *, const struct token *,
1463 const char *, unsigned int,
1464 void *, unsigned int);
1465 static int parse_prefix(struct context *, const struct token *,
1466 const char *, unsigned int,
1467 void *, unsigned int);
1468 static int parse_boolean(struct context *, const struct token *,
1469 const char *, unsigned int,
1470 void *, unsigned int);
1471 static int parse_string(struct context *, const struct token *,
1472 const char *, unsigned int,
1473 void *, unsigned int);
1474 static int parse_hex(struct context *ctx, const struct token *token,
1475 const char *str, unsigned int len,
1476 void *buf, unsigned int size);
1477 static int parse_string0(struct context *, const struct token *,
1478 const char *, unsigned int,
1479 void *, unsigned int);
1480 static int parse_mac_addr(struct context *, const struct token *,
1481 const char *, unsigned int,
1482 void *, unsigned int);
1483 static int parse_ipv4_addr(struct context *, const struct token *,
1484 const char *, unsigned int,
1485 void *, unsigned int);
1486 static int parse_ipv6_addr(struct context *, const struct token *,
1487 const char *, unsigned int,
1488 void *, unsigned int);
1489 static int parse_port(struct context *, const struct token *,
1490 const char *, unsigned int,
1491 void *, unsigned int);
1492 static int comp_none(struct context *, const struct token *,
1493 unsigned int, char *, unsigned int);
1494 static int comp_boolean(struct context *, const struct token *,
1495 unsigned int, char *, unsigned int);
1496 static int comp_action(struct context *, const struct token *,
1497 unsigned int, char *, unsigned int);
1498 static int comp_port(struct context *, const struct token *,
1499 unsigned int, char *, unsigned int);
1500 static int comp_rule_id(struct context *, const struct token *,
1501 unsigned int, char *, unsigned int);
1502 static int comp_vc_action_rss_type(struct context *, const struct token *,
1503 unsigned int, char *, unsigned int);
1504 static int comp_vc_action_rss_queue(struct context *, const struct token *,
1505 unsigned int, char *, unsigned int);
1506 static int comp_set_raw_index(struct context *, const struct token *,
1507 unsigned int, char *, unsigned int);
1509 /** Token definitions. */
1510 static const struct token token_list[] = {
1511 /* Special tokens. */
1514 .help = "null entry, abused as the entry point",
1515 .next = NEXT(NEXT_ENTRY(FLOW)),
1520 .help = "command may end here",
1523 .name = "START_SET",
1524 .help = "null entry, abused as the entry point for set",
1525 .next = NEXT(NEXT_ENTRY(SET)),
1530 .help = "set command may end here",
1532 /* Common tokens. */
1536 .help = "integer value",
1541 .name = "{unsigned}",
1543 .help = "unsigned integer value",
1550 .help = "prefix length for bit-mask",
1551 .call = parse_prefix,
1555 .name = "{boolean}",
1557 .help = "any boolean value",
1558 .call = parse_boolean,
1559 .comp = comp_boolean,
1564 .help = "fixed string",
1565 .call = parse_string,
1571 .help = "fixed string",
1575 .name = "{file path}",
1577 .help = "file path",
1578 .call = parse_string0,
1582 .name = "{MAC address}",
1584 .help = "standard MAC address notation",
1585 .call = parse_mac_addr,
1589 .name = "{IPv4 address}",
1590 .type = "IPV4 ADDRESS",
1591 .help = "standard IPv4 address notation",
1592 .call = parse_ipv4_addr,
1596 .name = "{IPv6 address}",
1597 .type = "IPV6 ADDRESS",
1598 .help = "standard IPv6 address notation",
1599 .call = parse_ipv6_addr,
1603 .name = "{rule id}",
1605 .help = "rule identifier",
1607 .comp = comp_rule_id,
1610 .name = "{port_id}",
1612 .help = "port identifier",
1617 .name = "{group_id}",
1619 .help = "group identifier",
1623 [PRIORITY_LEVEL] = {
1626 .help = "priority level",
1630 /* Top-level command. */
1633 .type = "{command} {port_id} [{arg} [...]]",
1634 .help = "manage ingress/egress flow rules",
1635 .next = NEXT(NEXT_ENTRY
1646 /* Sub-level commands. */
1649 .help = "check whether a flow rule can be created",
1650 .next = NEXT(next_vc_attr, NEXT_ENTRY(PORT_ID)),
1651 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1656 .help = "create a flow rule",
1657 .next = NEXT(next_vc_attr, NEXT_ENTRY(PORT_ID)),
1658 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1663 .help = "destroy specific flow rules",
1664 .next = NEXT(NEXT_ENTRY(DESTROY_RULE), NEXT_ENTRY(PORT_ID)),
1665 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1666 .call = parse_destroy,
1670 .help = "destroy all flow rules",
1671 .next = NEXT(NEXT_ENTRY(PORT_ID)),
1672 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1673 .call = parse_flush,
1677 .help = "dump all flow rules to file",
1678 .next = NEXT(next_dump_attr, NEXT_ENTRY(PORT_ID)),
1679 .args = ARGS(ARGS_ENTRY(struct buffer, args.dump.file),
1680 ARGS_ENTRY(struct buffer, port)),
1685 .help = "query an existing flow rule",
1686 .next = NEXT(NEXT_ENTRY(QUERY_ACTION),
1687 NEXT_ENTRY(RULE_ID),
1688 NEXT_ENTRY(PORT_ID)),
1689 .args = ARGS(ARGS_ENTRY(struct buffer, args.query.action.type),
1690 ARGS_ENTRY(struct buffer, args.query.rule),
1691 ARGS_ENTRY(struct buffer, port)),
1692 .call = parse_query,
1696 .help = "list existing flow rules",
1697 .next = NEXT(next_list_attr, NEXT_ENTRY(PORT_ID)),
1698 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1703 .help = "restrict ingress traffic to the defined flow rules",
1704 .next = NEXT(NEXT_ENTRY(BOOLEAN),
1705 NEXT_ENTRY(PORT_ID)),
1706 .args = ARGS(ARGS_ENTRY(struct buffer, args.isolate.set),
1707 ARGS_ENTRY(struct buffer, port)),
1708 .call = parse_isolate,
1710 /* Destroy arguments. */
1713 .help = "specify a rule identifier",
1714 .next = NEXT(next_destroy_attr, NEXT_ENTRY(RULE_ID)),
1715 .args = ARGS(ARGS_ENTRY_PTR(struct buffer, args.destroy.rule)),
1716 .call = parse_destroy,
1718 /* Query arguments. */
1722 .help = "action to query, must be part of the rule",
1723 .call = parse_action,
1724 .comp = comp_action,
1726 /* List arguments. */
1729 .help = "specify a group",
1730 .next = NEXT(next_list_attr, NEXT_ENTRY(GROUP_ID)),
1731 .args = ARGS(ARGS_ENTRY_PTR(struct buffer, args.list.group)),
1734 /* Validate/create attributes. */
1737 .help = "specify a group",
1738 .next = NEXT(next_vc_attr, NEXT_ENTRY(GROUP_ID)),
1739 .args = ARGS(ARGS_ENTRY(struct rte_flow_attr, group)),
1744 .help = "specify a priority level",
1745 .next = NEXT(next_vc_attr, NEXT_ENTRY(PRIORITY_LEVEL)),
1746 .args = ARGS(ARGS_ENTRY(struct rte_flow_attr, priority)),
1751 .help = "affect rule to ingress",
1752 .next = NEXT(next_vc_attr),
1757 .help = "affect rule to egress",
1758 .next = NEXT(next_vc_attr),
1763 .help = "apply rule directly to endpoints found in pattern",
1764 .next = NEXT(next_vc_attr),
1767 /* Validate/create pattern. */
1770 .help = "submit a list of pattern items",
1771 .next = NEXT(next_item),
1776 .help = "match value perfectly (with full bit-mask)",
1777 .call = parse_vc_spec,
1779 [ITEM_PARAM_SPEC] = {
1781 .help = "match value according to configured bit-mask",
1782 .call = parse_vc_spec,
1784 [ITEM_PARAM_LAST] = {
1786 .help = "specify upper bound to establish a range",
1787 .call = parse_vc_spec,
1789 [ITEM_PARAM_MASK] = {
1791 .help = "specify bit-mask with relevant bits set to one",
1792 .call = parse_vc_spec,
1794 [ITEM_PARAM_PREFIX] = {
1796 .help = "generate bit-mask from a prefix length",
1797 .call = parse_vc_spec,
1801 .help = "specify next pattern item",
1802 .next = NEXT(next_item),
1806 .help = "end list of pattern items",
1807 .priv = PRIV_ITEM(END, 0),
1808 .next = NEXT(NEXT_ENTRY(ACTIONS)),
1813 .help = "no-op pattern item",
1814 .priv = PRIV_ITEM(VOID, 0),
1815 .next = NEXT(NEXT_ENTRY(ITEM_NEXT)),
1820 .help = "perform actions when pattern does not match",
1821 .priv = PRIV_ITEM(INVERT, 0),
1822 .next = NEXT(NEXT_ENTRY(ITEM_NEXT)),
1827 .help = "match any protocol for the current layer",
1828 .priv = PRIV_ITEM(ANY, sizeof(struct rte_flow_item_any)),
1829 .next = NEXT(item_any),
1834 .help = "number of layers covered",
1835 .next = NEXT(item_any, NEXT_ENTRY(UNSIGNED), item_param),
1836 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_any, num)),
1840 .help = "match traffic from/to the physical function",
1841 .priv = PRIV_ITEM(PF, 0),
1842 .next = NEXT(NEXT_ENTRY(ITEM_NEXT)),
1847 .help = "match traffic from/to a virtual function ID",
1848 .priv = PRIV_ITEM(VF, sizeof(struct rte_flow_item_vf)),
1849 .next = NEXT(item_vf),
1855 .next = NEXT(item_vf, NEXT_ENTRY(UNSIGNED), item_param),
1856 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_vf, id)),
1860 .help = "match traffic from/to a specific physical port",
1861 .priv = PRIV_ITEM(PHY_PORT,
1862 sizeof(struct rte_flow_item_phy_port)),
1863 .next = NEXT(item_phy_port),
1866 [ITEM_PHY_PORT_INDEX] = {
1868 .help = "physical port index",
1869 .next = NEXT(item_phy_port, NEXT_ENTRY(UNSIGNED), item_param),
1870 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_phy_port, index)),
1874 .help = "match traffic from/to a given DPDK port ID",
1875 .priv = PRIV_ITEM(PORT_ID,
1876 sizeof(struct rte_flow_item_port_id)),
1877 .next = NEXT(item_port_id),
1880 [ITEM_PORT_ID_ID] = {
1882 .help = "DPDK port ID",
1883 .next = NEXT(item_port_id, NEXT_ENTRY(UNSIGNED), item_param),
1884 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_port_id, id)),
1888 .help = "match traffic against value set in previously matched rule",
1889 .priv = PRIV_ITEM(MARK, sizeof(struct rte_flow_item_mark)),
1890 .next = NEXT(item_mark),
1895 .help = "Integer value to match against",
1896 .next = NEXT(item_mark, NEXT_ENTRY(UNSIGNED), item_param),
1897 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_mark, id)),
1901 .help = "match an arbitrary byte string",
1902 .priv = PRIV_ITEM(RAW, ITEM_RAW_SIZE),
1903 .next = NEXT(item_raw),
1906 [ITEM_RAW_RELATIVE] = {
1908 .help = "look for pattern after the previous item",
1909 .next = NEXT(item_raw, NEXT_ENTRY(BOOLEAN), item_param),
1910 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_item_raw,
1913 [ITEM_RAW_SEARCH] = {
1915 .help = "search pattern from offset (see also limit)",
1916 .next = NEXT(item_raw, NEXT_ENTRY(BOOLEAN), item_param),
1917 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_item_raw,
1920 [ITEM_RAW_OFFSET] = {
1922 .help = "absolute or relative offset for pattern",
1923 .next = NEXT(item_raw, NEXT_ENTRY(INTEGER), item_param),
1924 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_raw, offset)),
1926 [ITEM_RAW_LIMIT] = {
1928 .help = "search area limit for start of pattern",
1929 .next = NEXT(item_raw, NEXT_ENTRY(UNSIGNED), item_param),
1930 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_raw, limit)),
1932 [ITEM_RAW_PATTERN] = {
1934 .help = "byte string to look for",
1935 .next = NEXT(item_raw,
1937 NEXT_ENTRY(ITEM_PARAM_IS,
1940 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_raw, pattern),
1941 ARGS_ENTRY(struct rte_flow_item_raw, length),
1942 ARGS_ENTRY_ARB(sizeof(struct rte_flow_item_raw),
1943 ITEM_RAW_PATTERN_SIZE)),
1947 .help = "match Ethernet header",
1948 .priv = PRIV_ITEM(ETH, sizeof(struct rte_flow_item_eth)),
1949 .next = NEXT(item_eth),
1954 .help = "destination MAC",
1955 .next = NEXT(item_eth, NEXT_ENTRY(MAC_ADDR), item_param),
1956 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_eth, dst)),
1960 .help = "source MAC",
1961 .next = NEXT(item_eth, NEXT_ENTRY(MAC_ADDR), item_param),
1962 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_eth, src)),
1966 .help = "EtherType",
1967 .next = NEXT(item_eth, NEXT_ENTRY(UNSIGNED), item_param),
1968 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_eth, type)),
1972 .help = "match 802.1Q/ad VLAN tag",
1973 .priv = PRIV_ITEM(VLAN, sizeof(struct rte_flow_item_vlan)),
1974 .next = NEXT(item_vlan),
1979 .help = "tag control information",
1980 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1981 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vlan, tci)),
1985 .help = "priority code point",
1986 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1987 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_vlan,
1992 .help = "drop eligible indicator",
1993 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1994 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_vlan,
1999 .help = "VLAN identifier",
2000 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
2001 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_vlan,
2004 [ITEM_VLAN_INNER_TYPE] = {
2005 .name = "inner_type",
2006 .help = "inner EtherType",
2007 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
2008 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vlan,
2013 .help = "match IPv4 header",
2014 .priv = PRIV_ITEM(IPV4, sizeof(struct rte_flow_item_ipv4)),
2015 .next = NEXT(item_ipv4),
2020 .help = "type of service",
2021 .next = NEXT(item_ipv4, NEXT_ENTRY(UNSIGNED), item_param),
2022 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
2023 hdr.type_of_service)),
2027 .help = "time to live",
2028 .next = NEXT(item_ipv4, NEXT_ENTRY(UNSIGNED), item_param),
2029 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
2032 [ITEM_IPV4_PROTO] = {
2034 .help = "next protocol ID",
2035 .next = NEXT(item_ipv4, NEXT_ENTRY(UNSIGNED), item_param),
2036 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
2037 hdr.next_proto_id)),
2041 .help = "source address",
2042 .next = NEXT(item_ipv4, NEXT_ENTRY(IPV4_ADDR), item_param),
2043 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
2048 .help = "destination address",
2049 .next = NEXT(item_ipv4, NEXT_ENTRY(IPV4_ADDR), item_param),
2050 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
2055 .help = "match IPv6 header",
2056 .priv = PRIV_ITEM(IPV6, sizeof(struct rte_flow_item_ipv6)),
2057 .next = NEXT(item_ipv6),
2062 .help = "traffic class",
2063 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
2064 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_ipv6,
2066 "\x0f\xf0\x00\x00")),
2068 [ITEM_IPV6_FLOW] = {
2070 .help = "flow label",
2071 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
2072 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_ipv6,
2074 "\x00\x0f\xff\xff")),
2076 [ITEM_IPV6_PROTO] = {
2078 .help = "protocol (next header)",
2079 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
2080 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
2085 .help = "hop limit",
2086 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
2087 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
2092 .help = "source address",
2093 .next = NEXT(item_ipv6, NEXT_ENTRY(IPV6_ADDR), item_param),
2094 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
2099 .help = "destination address",
2100 .next = NEXT(item_ipv6, NEXT_ENTRY(IPV6_ADDR), item_param),
2101 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
2106 .help = "match ICMP header",
2107 .priv = PRIV_ITEM(ICMP, sizeof(struct rte_flow_item_icmp)),
2108 .next = NEXT(item_icmp),
2111 [ITEM_ICMP_TYPE] = {
2113 .help = "ICMP packet type",
2114 .next = NEXT(item_icmp, NEXT_ENTRY(UNSIGNED), item_param),
2115 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp,
2118 [ITEM_ICMP_CODE] = {
2120 .help = "ICMP packet code",
2121 .next = NEXT(item_icmp, NEXT_ENTRY(UNSIGNED), item_param),
2122 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp,
2127 .help = "match UDP header",
2128 .priv = PRIV_ITEM(UDP, sizeof(struct rte_flow_item_udp)),
2129 .next = NEXT(item_udp),
2134 .help = "UDP source port",
2135 .next = NEXT(item_udp, NEXT_ENTRY(UNSIGNED), item_param),
2136 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_udp,
2141 .help = "UDP destination port",
2142 .next = NEXT(item_udp, NEXT_ENTRY(UNSIGNED), item_param),
2143 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_udp,
2148 .help = "match TCP header",
2149 .priv = PRIV_ITEM(TCP, sizeof(struct rte_flow_item_tcp)),
2150 .next = NEXT(item_tcp),
2155 .help = "TCP source port",
2156 .next = NEXT(item_tcp, NEXT_ENTRY(UNSIGNED), item_param),
2157 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_tcp,
2162 .help = "TCP destination port",
2163 .next = NEXT(item_tcp, NEXT_ENTRY(UNSIGNED), item_param),
2164 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_tcp,
2167 [ITEM_TCP_FLAGS] = {
2169 .help = "TCP flags",
2170 .next = NEXT(item_tcp, NEXT_ENTRY(UNSIGNED), item_param),
2171 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_tcp,
2176 .help = "match SCTP header",
2177 .priv = PRIV_ITEM(SCTP, sizeof(struct rte_flow_item_sctp)),
2178 .next = NEXT(item_sctp),
2183 .help = "SCTP source port",
2184 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
2185 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
2190 .help = "SCTP destination port",
2191 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
2192 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
2197 .help = "validation tag",
2198 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
2199 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
2202 [ITEM_SCTP_CKSUM] = {
2205 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
2206 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
2211 .help = "match VXLAN header",
2212 .priv = PRIV_ITEM(VXLAN, sizeof(struct rte_flow_item_vxlan)),
2213 .next = NEXT(item_vxlan),
2216 [ITEM_VXLAN_VNI] = {
2218 .help = "VXLAN identifier",
2219 .next = NEXT(item_vxlan, NEXT_ENTRY(UNSIGNED), item_param),
2220 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vxlan, vni)),
2224 .help = "match E-Tag header",
2225 .priv = PRIV_ITEM(E_TAG, sizeof(struct rte_flow_item_e_tag)),
2226 .next = NEXT(item_e_tag),
2229 [ITEM_E_TAG_GRP_ECID_B] = {
2230 .name = "grp_ecid_b",
2231 .help = "GRP and E-CID base",
2232 .next = NEXT(item_e_tag, NEXT_ENTRY(UNSIGNED), item_param),
2233 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_e_tag,
2239 .help = "match NVGRE header",
2240 .priv = PRIV_ITEM(NVGRE, sizeof(struct rte_flow_item_nvgre)),
2241 .next = NEXT(item_nvgre),
2244 [ITEM_NVGRE_TNI] = {
2246 .help = "virtual subnet ID",
2247 .next = NEXT(item_nvgre, NEXT_ENTRY(UNSIGNED), item_param),
2248 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_nvgre, tni)),
2252 .help = "match MPLS header",
2253 .priv = PRIV_ITEM(MPLS, sizeof(struct rte_flow_item_mpls)),
2254 .next = NEXT(item_mpls),
2257 [ITEM_MPLS_LABEL] = {
2259 .help = "MPLS label",
2260 .next = NEXT(item_mpls, NEXT_ENTRY(UNSIGNED), item_param),
2261 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_mpls,
2267 .help = "MPLS Traffic Class",
2268 .next = NEXT(item_mpls, NEXT_ENTRY(UNSIGNED), item_param),
2269 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_mpls,
2275 .help = "MPLS Bottom-of-Stack",
2276 .next = NEXT(item_mpls, NEXT_ENTRY(UNSIGNED), item_param),
2277 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_mpls,
2283 .help = "match GRE header",
2284 .priv = PRIV_ITEM(GRE, sizeof(struct rte_flow_item_gre)),
2285 .next = NEXT(item_gre),
2288 [ITEM_GRE_PROTO] = {
2290 .help = "GRE protocol type",
2291 .next = NEXT(item_gre, NEXT_ENTRY(UNSIGNED), item_param),
2292 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gre,
2295 [ITEM_GRE_C_RSVD0_VER] = {
2296 .name = "c_rsvd0_ver",
2298 "checksum (1b), undefined (1b), key bit (1b),"
2299 " sequence number (1b), reserved 0 (9b),"
2301 .next = NEXT(item_gre, NEXT_ENTRY(UNSIGNED), item_param),
2302 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gre,
2305 [ITEM_GRE_C_BIT] = {
2307 .help = "checksum bit (C)",
2308 .next = NEXT(item_gre, NEXT_ENTRY(BOOLEAN), item_param),
2309 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_gre,
2311 "\x80\x00\x00\x00")),
2313 [ITEM_GRE_S_BIT] = {
2315 .help = "sequence number bit (S)",
2316 .next = NEXT(item_gre, NEXT_ENTRY(BOOLEAN), item_param),
2317 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_gre,
2319 "\x10\x00\x00\x00")),
2321 [ITEM_GRE_K_BIT] = {
2323 .help = "key bit (K)",
2324 .next = NEXT(item_gre, NEXT_ENTRY(BOOLEAN), item_param),
2325 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_gre,
2327 "\x20\x00\x00\x00")),
2331 .help = "fuzzy pattern match, expect faster than default",
2332 .priv = PRIV_ITEM(FUZZY,
2333 sizeof(struct rte_flow_item_fuzzy)),
2334 .next = NEXT(item_fuzzy),
2337 [ITEM_FUZZY_THRESH] = {
2339 .help = "match accuracy threshold",
2340 .next = NEXT(item_fuzzy, NEXT_ENTRY(UNSIGNED), item_param),
2341 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_fuzzy,
2346 .help = "match GTP header",
2347 .priv = PRIV_ITEM(GTP, sizeof(struct rte_flow_item_gtp)),
2348 .next = NEXT(item_gtp),
2351 [ITEM_GTP_FLAGS] = {
2352 .name = "v_pt_rsv_flags",
2353 .help = "GTP flags",
2354 .next = NEXT(item_gtp, NEXT_ENTRY(UNSIGNED), item_param),
2355 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_gtp,
2358 [ITEM_GTP_MSG_TYPE] = {
2360 .help = "GTP message type",
2361 .next = NEXT(item_gtp, NEXT_ENTRY(UNSIGNED), item_param),
2362 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_gtp, msg_type)),
2366 .help = "tunnel endpoint identifier",
2367 .next = NEXT(item_gtp, NEXT_ENTRY(UNSIGNED), item_param),
2368 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gtp, teid)),
2372 .help = "match GTP header",
2373 .priv = PRIV_ITEM(GTPC, sizeof(struct rte_flow_item_gtp)),
2374 .next = NEXT(item_gtp),
2379 .help = "match GTP header",
2380 .priv = PRIV_ITEM(GTPU, sizeof(struct rte_flow_item_gtp)),
2381 .next = NEXT(item_gtp),
2386 .help = "match GENEVE header",
2387 .priv = PRIV_ITEM(GENEVE, sizeof(struct rte_flow_item_geneve)),
2388 .next = NEXT(item_geneve),
2391 [ITEM_GENEVE_VNI] = {
2393 .help = "virtual network identifier",
2394 .next = NEXT(item_geneve, NEXT_ENTRY(UNSIGNED), item_param),
2395 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_geneve, vni)),
2397 [ITEM_GENEVE_PROTO] = {
2399 .help = "GENEVE protocol type",
2400 .next = NEXT(item_geneve, NEXT_ENTRY(UNSIGNED), item_param),
2401 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_geneve,
2404 [ITEM_VXLAN_GPE] = {
2405 .name = "vxlan-gpe",
2406 .help = "match VXLAN-GPE header",
2407 .priv = PRIV_ITEM(VXLAN_GPE,
2408 sizeof(struct rte_flow_item_vxlan_gpe)),
2409 .next = NEXT(item_vxlan_gpe),
2412 [ITEM_VXLAN_GPE_VNI] = {
2414 .help = "VXLAN-GPE identifier",
2415 .next = NEXT(item_vxlan_gpe, NEXT_ENTRY(UNSIGNED), item_param),
2416 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vxlan_gpe,
2419 [ITEM_ARP_ETH_IPV4] = {
2420 .name = "arp_eth_ipv4",
2421 .help = "match ARP header for Ethernet/IPv4",
2422 .priv = PRIV_ITEM(ARP_ETH_IPV4,
2423 sizeof(struct rte_flow_item_arp_eth_ipv4)),
2424 .next = NEXT(item_arp_eth_ipv4),
2427 [ITEM_ARP_ETH_IPV4_SHA] = {
2429 .help = "sender hardware address",
2430 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(MAC_ADDR),
2432 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
2435 [ITEM_ARP_ETH_IPV4_SPA] = {
2437 .help = "sender IPv4 address",
2438 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(IPV4_ADDR),
2440 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
2443 [ITEM_ARP_ETH_IPV4_THA] = {
2445 .help = "target hardware address",
2446 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(MAC_ADDR),
2448 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
2451 [ITEM_ARP_ETH_IPV4_TPA] = {
2453 .help = "target IPv4 address",
2454 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(IPV4_ADDR),
2456 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
2461 .help = "match presence of any IPv6 extension header",
2462 .priv = PRIV_ITEM(IPV6_EXT,
2463 sizeof(struct rte_flow_item_ipv6_ext)),
2464 .next = NEXT(item_ipv6_ext),
2467 [ITEM_IPV6_EXT_NEXT_HDR] = {
2469 .help = "next header",
2470 .next = NEXT(item_ipv6_ext, NEXT_ENTRY(UNSIGNED), item_param),
2471 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6_ext,
2476 .help = "match any ICMPv6 header",
2477 .priv = PRIV_ITEM(ICMP6, sizeof(struct rte_flow_item_icmp6)),
2478 .next = NEXT(item_icmp6),
2481 [ITEM_ICMP6_TYPE] = {
2483 .help = "ICMPv6 type",
2484 .next = NEXT(item_icmp6, NEXT_ENTRY(UNSIGNED), item_param),
2485 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6,
2488 [ITEM_ICMP6_CODE] = {
2490 .help = "ICMPv6 code",
2491 .next = NEXT(item_icmp6, NEXT_ENTRY(UNSIGNED), item_param),
2492 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6,
2495 [ITEM_ICMP6_ND_NS] = {
2496 .name = "icmp6_nd_ns",
2497 .help = "match ICMPv6 neighbor discovery solicitation",
2498 .priv = PRIV_ITEM(ICMP6_ND_NS,
2499 sizeof(struct rte_flow_item_icmp6_nd_ns)),
2500 .next = NEXT(item_icmp6_nd_ns),
2503 [ITEM_ICMP6_ND_NS_TARGET_ADDR] = {
2504 .name = "target_addr",
2505 .help = "target address",
2506 .next = NEXT(item_icmp6_nd_ns, NEXT_ENTRY(IPV6_ADDR),
2508 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6_nd_ns,
2511 [ITEM_ICMP6_ND_NA] = {
2512 .name = "icmp6_nd_na",
2513 .help = "match ICMPv6 neighbor discovery advertisement",
2514 .priv = PRIV_ITEM(ICMP6_ND_NA,
2515 sizeof(struct rte_flow_item_icmp6_nd_na)),
2516 .next = NEXT(item_icmp6_nd_na),
2519 [ITEM_ICMP6_ND_NA_TARGET_ADDR] = {
2520 .name = "target_addr",
2521 .help = "target address",
2522 .next = NEXT(item_icmp6_nd_na, NEXT_ENTRY(IPV6_ADDR),
2524 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6_nd_na,
2527 [ITEM_ICMP6_ND_OPT] = {
2528 .name = "icmp6_nd_opt",
2529 .help = "match presence of any ICMPv6 neighbor discovery"
2531 .priv = PRIV_ITEM(ICMP6_ND_OPT,
2532 sizeof(struct rte_flow_item_icmp6_nd_opt)),
2533 .next = NEXT(item_icmp6_nd_opt),
2536 [ITEM_ICMP6_ND_OPT_TYPE] = {
2538 .help = "ND option type",
2539 .next = NEXT(item_icmp6_nd_opt, NEXT_ENTRY(UNSIGNED),
2541 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6_nd_opt,
2544 [ITEM_ICMP6_ND_OPT_SLA_ETH] = {
2545 .name = "icmp6_nd_opt_sla_eth",
2546 .help = "match ICMPv6 neighbor discovery source Ethernet"
2547 " link-layer address option",
2549 (ICMP6_ND_OPT_SLA_ETH,
2550 sizeof(struct rte_flow_item_icmp6_nd_opt_sla_eth)),
2551 .next = NEXT(item_icmp6_nd_opt_sla_eth),
2554 [ITEM_ICMP6_ND_OPT_SLA_ETH_SLA] = {
2556 .help = "source Ethernet LLA",
2557 .next = NEXT(item_icmp6_nd_opt_sla_eth, NEXT_ENTRY(MAC_ADDR),
2559 .args = ARGS(ARGS_ENTRY_HTON
2560 (struct rte_flow_item_icmp6_nd_opt_sla_eth, sla)),
2562 [ITEM_ICMP6_ND_OPT_TLA_ETH] = {
2563 .name = "icmp6_nd_opt_tla_eth",
2564 .help = "match ICMPv6 neighbor discovery target Ethernet"
2565 " link-layer address option",
2567 (ICMP6_ND_OPT_TLA_ETH,
2568 sizeof(struct rte_flow_item_icmp6_nd_opt_tla_eth)),
2569 .next = NEXT(item_icmp6_nd_opt_tla_eth),
2572 [ITEM_ICMP6_ND_OPT_TLA_ETH_TLA] = {
2574 .help = "target Ethernet LLA",
2575 .next = NEXT(item_icmp6_nd_opt_tla_eth, NEXT_ENTRY(MAC_ADDR),
2577 .args = ARGS(ARGS_ENTRY_HTON
2578 (struct rte_flow_item_icmp6_nd_opt_tla_eth, tla)),
2582 .help = "match metadata header",
2583 .priv = PRIV_ITEM(META, sizeof(struct rte_flow_item_meta)),
2584 .next = NEXT(item_meta),
2587 [ITEM_META_DATA] = {
2589 .help = "metadata value",
2590 .next = NEXT(item_meta, NEXT_ENTRY(UNSIGNED), item_param),
2591 .args = ARGS(ARGS_ENTRY_MASK(struct rte_flow_item_meta,
2592 data, "\xff\xff\xff\xff")),
2596 .help = "match GRE key",
2597 .priv = PRIV_ITEM(GRE_KEY, sizeof(rte_be32_t)),
2598 .next = NEXT(item_gre_key),
2601 [ITEM_GRE_KEY_VALUE] = {
2603 .help = "key value",
2604 .next = NEXT(item_gre_key, NEXT_ENTRY(UNSIGNED), item_param),
2605 .args = ARGS(ARG_ENTRY_HTON(rte_be32_t)),
2609 .help = "match GTP extension header with type 0x85",
2610 .priv = PRIV_ITEM(GTP_PSC,
2611 sizeof(struct rte_flow_item_gtp_psc)),
2612 .next = NEXT(item_gtp_psc),
2615 [ITEM_GTP_PSC_QFI] = {
2617 .help = "QoS flow identifier",
2618 .next = NEXT(item_gtp_psc, NEXT_ENTRY(UNSIGNED), item_param),
2619 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gtp_psc,
2622 [ITEM_GTP_PSC_PDU_T] = {
2625 .next = NEXT(item_gtp_psc, NEXT_ENTRY(UNSIGNED), item_param),
2626 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gtp_psc,
2631 .help = "match PPPoE session header",
2632 .priv = PRIV_ITEM(PPPOES, sizeof(struct rte_flow_item_pppoe)),
2633 .next = NEXT(item_pppoes),
2638 .help = "match PPPoE discovery header",
2639 .priv = PRIV_ITEM(PPPOED, sizeof(struct rte_flow_item_pppoe)),
2640 .next = NEXT(item_pppoed),
2643 [ITEM_PPPOE_SEID] = {
2645 .help = "session identifier",
2646 .next = NEXT(item_pppoes, NEXT_ENTRY(UNSIGNED), item_param),
2647 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_pppoe,
2650 [ITEM_PPPOE_PROTO_ID] = {
2651 .name = "pppoe_proto_id",
2652 .help = "match PPPoE session protocol identifier",
2653 .priv = PRIV_ITEM(PPPOE_PROTO_ID,
2654 sizeof(struct rte_flow_item_pppoe_proto_id)),
2655 .next = NEXT(item_pppoe_proto_id, NEXT_ENTRY(UNSIGNED),
2657 .args = ARGS(ARGS_ENTRY_HTON
2658 (struct rte_flow_item_pppoe_proto_id, proto_id)),
2663 .help = "matches higig2 header",
2664 .priv = PRIV_ITEM(HIGIG2,
2665 sizeof(struct rte_flow_item_higig2_hdr)),
2666 .next = NEXT(item_higig2),
2669 [ITEM_HIGIG2_CLASSIFICATION] = {
2670 .name = "classification",
2671 .help = "matches classification of higig2 header",
2672 .next = NEXT(item_higig2, NEXT_ENTRY(UNSIGNED), item_param),
2673 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_higig2_hdr,
2674 hdr.ppt1.classification)),
2676 [ITEM_HIGIG2_VID] = {
2678 .help = "matches vid of higig2 header",
2679 .next = NEXT(item_higig2, NEXT_ENTRY(UNSIGNED), item_param),
2680 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_higig2_hdr,
2685 .help = "match tag value",
2686 .priv = PRIV_ITEM(TAG, sizeof(struct rte_flow_item_tag)),
2687 .next = NEXT(item_tag),
2692 .help = "tag value to match",
2693 .next = NEXT(item_tag, NEXT_ENTRY(UNSIGNED), item_param),
2694 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_tag, data)),
2696 [ITEM_TAG_INDEX] = {
2698 .help = "index of tag array to match",
2699 .next = NEXT(item_tag, NEXT_ENTRY(UNSIGNED),
2700 NEXT_ENTRY(ITEM_PARAM_IS)),
2701 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_tag, index)),
2703 [ITEM_L2TPV3OIP] = {
2704 .name = "l2tpv3oip",
2705 .help = "match L2TPv3 over IP header",
2706 .priv = PRIV_ITEM(L2TPV3OIP,
2707 sizeof(struct rte_flow_item_l2tpv3oip)),
2708 .next = NEXT(item_l2tpv3oip),
2711 [ITEM_L2TPV3OIP_SESSION_ID] = {
2712 .name = "session_id",
2713 .help = "session identifier",
2714 .next = NEXT(item_l2tpv3oip, NEXT_ENTRY(UNSIGNED), item_param),
2715 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_l2tpv3oip,
2720 .help = "match ESP header",
2721 .priv = PRIV_ITEM(ESP, sizeof(struct rte_flow_item_esp)),
2722 .next = NEXT(item_esp),
2727 .help = "security policy index",
2728 .next = NEXT(item_esp, NEXT_ENTRY(UNSIGNED), item_param),
2729 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_esp,
2734 .help = "match AH header",
2735 .priv = PRIV_ITEM(AH, sizeof(struct rte_flow_item_ah)),
2736 .next = NEXT(item_ah),
2741 .help = "security parameters index",
2742 .next = NEXT(item_ah, NEXT_ENTRY(UNSIGNED), item_param),
2743 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ah, spi)),
2747 .help = "match pfcp header",
2748 .priv = PRIV_ITEM(PFCP, sizeof(struct rte_flow_item_pfcp)),
2749 .next = NEXT(item_pfcp),
2752 [ITEM_PFCP_S_FIELD] = {
2755 .next = NEXT(item_pfcp, NEXT_ENTRY(UNSIGNED), item_param),
2756 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_pfcp,
2759 [ITEM_PFCP_SEID] = {
2761 .help = "session endpoint identifier",
2762 .next = NEXT(item_pfcp, NEXT_ENTRY(UNSIGNED), item_param),
2763 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_pfcp, seid)),
2765 /* Validate/create actions. */
2768 .help = "submit a list of associated actions",
2769 .next = NEXT(next_action),
2774 .help = "specify next action",
2775 .next = NEXT(next_action),
2779 .help = "end list of actions",
2780 .priv = PRIV_ACTION(END, 0),
2785 .help = "no-op action",
2786 .priv = PRIV_ACTION(VOID, 0),
2787 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2790 [ACTION_PASSTHRU] = {
2792 .help = "let subsequent rule process matched packets",
2793 .priv = PRIV_ACTION(PASSTHRU, 0),
2794 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2799 .help = "redirect traffic to a given group",
2800 .priv = PRIV_ACTION(JUMP, sizeof(struct rte_flow_action_jump)),
2801 .next = NEXT(action_jump),
2804 [ACTION_JUMP_GROUP] = {
2806 .help = "group to redirect traffic to",
2807 .next = NEXT(action_jump, NEXT_ENTRY(UNSIGNED)),
2808 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_jump, group)),
2809 .call = parse_vc_conf,
2813 .help = "attach 32 bit value to packets",
2814 .priv = PRIV_ACTION(MARK, sizeof(struct rte_flow_action_mark)),
2815 .next = NEXT(action_mark),
2818 [ACTION_MARK_ID] = {
2820 .help = "32 bit value to return with packets",
2821 .next = NEXT(action_mark, NEXT_ENTRY(UNSIGNED)),
2822 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_mark, id)),
2823 .call = parse_vc_conf,
2827 .help = "flag packets",
2828 .priv = PRIV_ACTION(FLAG, 0),
2829 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2834 .help = "assign packets to a given queue index",
2835 .priv = PRIV_ACTION(QUEUE,
2836 sizeof(struct rte_flow_action_queue)),
2837 .next = NEXT(action_queue),
2840 [ACTION_QUEUE_INDEX] = {
2842 .help = "queue index to use",
2843 .next = NEXT(action_queue, NEXT_ENTRY(UNSIGNED)),
2844 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_queue, index)),
2845 .call = parse_vc_conf,
2849 .help = "drop packets (note: passthru has priority)",
2850 .priv = PRIV_ACTION(DROP, 0),
2851 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2856 .help = "enable counters for this rule",
2857 .priv = PRIV_ACTION(COUNT,
2858 sizeof(struct rte_flow_action_count)),
2859 .next = NEXT(action_count),
2862 [ACTION_COUNT_ID] = {
2863 .name = "identifier",
2864 .help = "counter identifier to use",
2865 .next = NEXT(action_count, NEXT_ENTRY(UNSIGNED)),
2866 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_count, id)),
2867 .call = parse_vc_conf,
2869 [ACTION_COUNT_SHARED] = {
2871 .help = "shared counter",
2872 .next = NEXT(action_count, NEXT_ENTRY(BOOLEAN)),
2873 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_count,
2875 .call = parse_vc_conf,
2879 .help = "spread packets among several queues",
2880 .priv = PRIV_ACTION(RSS, sizeof(struct action_rss_data)),
2881 .next = NEXT(action_rss),
2882 .call = parse_vc_action_rss,
2884 [ACTION_RSS_FUNC] = {
2886 .help = "RSS hash function to apply",
2887 .next = NEXT(action_rss,
2888 NEXT_ENTRY(ACTION_RSS_FUNC_DEFAULT,
2889 ACTION_RSS_FUNC_TOEPLITZ,
2890 ACTION_RSS_FUNC_SIMPLE_XOR,
2891 ACTION_RSS_FUNC_SYMMETRIC_TOEPLITZ)),
2893 [ACTION_RSS_FUNC_DEFAULT] = {
2895 .help = "default hash function",
2896 .call = parse_vc_action_rss_func,
2898 [ACTION_RSS_FUNC_TOEPLITZ] = {
2900 .help = "Toeplitz hash function",
2901 .call = parse_vc_action_rss_func,
2903 [ACTION_RSS_FUNC_SIMPLE_XOR] = {
2904 .name = "simple_xor",
2905 .help = "simple XOR hash function",
2906 .call = parse_vc_action_rss_func,
2908 [ACTION_RSS_FUNC_SYMMETRIC_TOEPLITZ] = {
2909 .name = "symmetric_toeplitz",
2910 .help = "Symmetric Toeplitz hash function",
2911 .call = parse_vc_action_rss_func,
2913 [ACTION_RSS_LEVEL] = {
2915 .help = "encapsulation level for \"types\"",
2916 .next = NEXT(action_rss, NEXT_ENTRY(UNSIGNED)),
2917 .args = ARGS(ARGS_ENTRY_ARB
2918 (offsetof(struct action_rss_data, conf) +
2919 offsetof(struct rte_flow_action_rss, level),
2920 sizeof(((struct rte_flow_action_rss *)0)->
2923 [ACTION_RSS_TYPES] = {
2925 .help = "specific RSS hash types",
2926 .next = NEXT(action_rss, NEXT_ENTRY(ACTION_RSS_TYPE)),
2928 [ACTION_RSS_TYPE] = {
2930 .help = "RSS hash type",
2931 .call = parse_vc_action_rss_type,
2932 .comp = comp_vc_action_rss_type,
2934 [ACTION_RSS_KEY] = {
2936 .help = "RSS hash key",
2937 .next = NEXT(action_rss, NEXT_ENTRY(HEX)),
2938 .args = ARGS(ARGS_ENTRY_ARB(0, 0),
2940 (offsetof(struct action_rss_data, conf) +
2941 offsetof(struct rte_flow_action_rss, key_len),
2942 sizeof(((struct rte_flow_action_rss *)0)->
2944 ARGS_ENTRY(struct action_rss_data, key)),
2946 [ACTION_RSS_KEY_LEN] = {
2948 .help = "RSS hash key length in bytes",
2949 .next = NEXT(action_rss, NEXT_ENTRY(UNSIGNED)),
2950 .args = ARGS(ARGS_ENTRY_ARB_BOUNDED
2951 (offsetof(struct action_rss_data, conf) +
2952 offsetof(struct rte_flow_action_rss, key_len),
2953 sizeof(((struct rte_flow_action_rss *)0)->
2956 RSS_HASH_KEY_LENGTH)),
2958 [ACTION_RSS_QUEUES] = {
2960 .help = "queue indices to use",
2961 .next = NEXT(action_rss, NEXT_ENTRY(ACTION_RSS_QUEUE)),
2962 .call = parse_vc_conf,
2964 [ACTION_RSS_QUEUE] = {
2966 .help = "queue index",
2967 .call = parse_vc_action_rss_queue,
2968 .comp = comp_vc_action_rss_queue,
2972 .help = "direct traffic to physical function",
2973 .priv = PRIV_ACTION(PF, 0),
2974 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2979 .help = "direct traffic to a virtual function ID",
2980 .priv = PRIV_ACTION(VF, sizeof(struct rte_flow_action_vf)),
2981 .next = NEXT(action_vf),
2984 [ACTION_VF_ORIGINAL] = {
2986 .help = "use original VF ID if possible",
2987 .next = NEXT(action_vf, NEXT_ENTRY(BOOLEAN)),
2988 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_vf,
2990 .call = parse_vc_conf,
2995 .next = NEXT(action_vf, NEXT_ENTRY(UNSIGNED)),
2996 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_vf, id)),
2997 .call = parse_vc_conf,
2999 [ACTION_PHY_PORT] = {
3001 .help = "direct packets to physical port index",
3002 .priv = PRIV_ACTION(PHY_PORT,
3003 sizeof(struct rte_flow_action_phy_port)),
3004 .next = NEXT(action_phy_port),
3007 [ACTION_PHY_PORT_ORIGINAL] = {
3009 .help = "use original port index if possible",
3010 .next = NEXT(action_phy_port, NEXT_ENTRY(BOOLEAN)),
3011 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_phy_port,
3013 .call = parse_vc_conf,
3015 [ACTION_PHY_PORT_INDEX] = {
3017 .help = "physical port index",
3018 .next = NEXT(action_phy_port, NEXT_ENTRY(UNSIGNED)),
3019 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_phy_port,
3021 .call = parse_vc_conf,
3023 [ACTION_PORT_ID] = {
3025 .help = "direct matching traffic to a given DPDK port ID",
3026 .priv = PRIV_ACTION(PORT_ID,
3027 sizeof(struct rte_flow_action_port_id)),
3028 .next = NEXT(action_port_id),
3031 [ACTION_PORT_ID_ORIGINAL] = {
3033 .help = "use original DPDK port ID if possible",
3034 .next = NEXT(action_port_id, NEXT_ENTRY(BOOLEAN)),
3035 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_port_id,
3037 .call = parse_vc_conf,
3039 [ACTION_PORT_ID_ID] = {
3041 .help = "DPDK port ID",
3042 .next = NEXT(action_port_id, NEXT_ENTRY(UNSIGNED)),
3043 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_port_id, id)),
3044 .call = parse_vc_conf,
3048 .help = "meter the directed packets at given id",
3049 .priv = PRIV_ACTION(METER,
3050 sizeof(struct rte_flow_action_meter)),
3051 .next = NEXT(action_meter),
3054 [ACTION_METER_ID] = {
3056 .help = "meter id to use",
3057 .next = NEXT(action_meter, NEXT_ENTRY(UNSIGNED)),
3058 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_meter, mtr_id)),
3059 .call = parse_vc_conf,
3061 [ACTION_OF_SET_MPLS_TTL] = {
3062 .name = "of_set_mpls_ttl",
3063 .help = "OpenFlow's OFPAT_SET_MPLS_TTL",
3066 sizeof(struct rte_flow_action_of_set_mpls_ttl)),
3067 .next = NEXT(action_of_set_mpls_ttl),
3070 [ACTION_OF_SET_MPLS_TTL_MPLS_TTL] = {
3073 .next = NEXT(action_of_set_mpls_ttl, NEXT_ENTRY(UNSIGNED)),
3074 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_of_set_mpls_ttl,
3076 .call = parse_vc_conf,
3078 [ACTION_OF_DEC_MPLS_TTL] = {
3079 .name = "of_dec_mpls_ttl",
3080 .help = "OpenFlow's OFPAT_DEC_MPLS_TTL",
3081 .priv = PRIV_ACTION(OF_DEC_MPLS_TTL, 0),
3082 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3085 [ACTION_OF_SET_NW_TTL] = {
3086 .name = "of_set_nw_ttl",
3087 .help = "OpenFlow's OFPAT_SET_NW_TTL",
3090 sizeof(struct rte_flow_action_of_set_nw_ttl)),
3091 .next = NEXT(action_of_set_nw_ttl),
3094 [ACTION_OF_SET_NW_TTL_NW_TTL] = {
3097 .next = NEXT(action_of_set_nw_ttl, NEXT_ENTRY(UNSIGNED)),
3098 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_of_set_nw_ttl,
3100 .call = parse_vc_conf,
3102 [ACTION_OF_DEC_NW_TTL] = {
3103 .name = "of_dec_nw_ttl",
3104 .help = "OpenFlow's OFPAT_DEC_NW_TTL",
3105 .priv = PRIV_ACTION(OF_DEC_NW_TTL, 0),
3106 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3109 [ACTION_OF_COPY_TTL_OUT] = {
3110 .name = "of_copy_ttl_out",
3111 .help = "OpenFlow's OFPAT_COPY_TTL_OUT",
3112 .priv = PRIV_ACTION(OF_COPY_TTL_OUT, 0),
3113 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3116 [ACTION_OF_COPY_TTL_IN] = {
3117 .name = "of_copy_ttl_in",
3118 .help = "OpenFlow's OFPAT_COPY_TTL_IN",
3119 .priv = PRIV_ACTION(OF_COPY_TTL_IN, 0),
3120 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3123 [ACTION_OF_POP_VLAN] = {
3124 .name = "of_pop_vlan",
3125 .help = "OpenFlow's OFPAT_POP_VLAN",
3126 .priv = PRIV_ACTION(OF_POP_VLAN, 0),
3127 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3130 [ACTION_OF_PUSH_VLAN] = {
3131 .name = "of_push_vlan",
3132 .help = "OpenFlow's OFPAT_PUSH_VLAN",
3135 sizeof(struct rte_flow_action_of_push_vlan)),
3136 .next = NEXT(action_of_push_vlan),
3139 [ACTION_OF_PUSH_VLAN_ETHERTYPE] = {
3140 .name = "ethertype",
3141 .help = "EtherType",
3142 .next = NEXT(action_of_push_vlan, NEXT_ENTRY(UNSIGNED)),
3143 .args = ARGS(ARGS_ENTRY_HTON
3144 (struct rte_flow_action_of_push_vlan,
3146 .call = parse_vc_conf,
3148 [ACTION_OF_SET_VLAN_VID] = {
3149 .name = "of_set_vlan_vid",
3150 .help = "OpenFlow's OFPAT_SET_VLAN_VID",
3153 sizeof(struct rte_flow_action_of_set_vlan_vid)),
3154 .next = NEXT(action_of_set_vlan_vid),
3157 [ACTION_OF_SET_VLAN_VID_VLAN_VID] = {
3160 .next = NEXT(action_of_set_vlan_vid, NEXT_ENTRY(UNSIGNED)),
3161 .args = ARGS(ARGS_ENTRY_HTON
3162 (struct rte_flow_action_of_set_vlan_vid,
3164 .call = parse_vc_conf,
3166 [ACTION_OF_SET_VLAN_PCP] = {
3167 .name = "of_set_vlan_pcp",
3168 .help = "OpenFlow's OFPAT_SET_VLAN_PCP",
3171 sizeof(struct rte_flow_action_of_set_vlan_pcp)),
3172 .next = NEXT(action_of_set_vlan_pcp),
3175 [ACTION_OF_SET_VLAN_PCP_VLAN_PCP] = {
3177 .help = "VLAN priority",
3178 .next = NEXT(action_of_set_vlan_pcp, NEXT_ENTRY(UNSIGNED)),
3179 .args = ARGS(ARGS_ENTRY_HTON
3180 (struct rte_flow_action_of_set_vlan_pcp,
3182 .call = parse_vc_conf,
3184 [ACTION_OF_POP_MPLS] = {
3185 .name = "of_pop_mpls",
3186 .help = "OpenFlow's OFPAT_POP_MPLS",
3187 .priv = PRIV_ACTION(OF_POP_MPLS,
3188 sizeof(struct rte_flow_action_of_pop_mpls)),
3189 .next = NEXT(action_of_pop_mpls),
3192 [ACTION_OF_POP_MPLS_ETHERTYPE] = {
3193 .name = "ethertype",
3194 .help = "EtherType",
3195 .next = NEXT(action_of_pop_mpls, NEXT_ENTRY(UNSIGNED)),
3196 .args = ARGS(ARGS_ENTRY_HTON
3197 (struct rte_flow_action_of_pop_mpls,
3199 .call = parse_vc_conf,
3201 [ACTION_OF_PUSH_MPLS] = {
3202 .name = "of_push_mpls",
3203 .help = "OpenFlow's OFPAT_PUSH_MPLS",
3206 sizeof(struct rte_flow_action_of_push_mpls)),
3207 .next = NEXT(action_of_push_mpls),
3210 [ACTION_OF_PUSH_MPLS_ETHERTYPE] = {
3211 .name = "ethertype",
3212 .help = "EtherType",
3213 .next = NEXT(action_of_push_mpls, NEXT_ENTRY(UNSIGNED)),
3214 .args = ARGS(ARGS_ENTRY_HTON
3215 (struct rte_flow_action_of_push_mpls,
3217 .call = parse_vc_conf,
3219 [ACTION_VXLAN_ENCAP] = {
3220 .name = "vxlan_encap",
3221 .help = "VXLAN encapsulation, uses configuration set by \"set"
3223 .priv = PRIV_ACTION(VXLAN_ENCAP,
3224 sizeof(struct action_vxlan_encap_data)),
3225 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3226 .call = parse_vc_action_vxlan_encap,
3228 [ACTION_VXLAN_DECAP] = {
3229 .name = "vxlan_decap",
3230 .help = "Performs a decapsulation action by stripping all"
3231 " headers of the VXLAN tunnel network overlay from the"
3233 .priv = PRIV_ACTION(VXLAN_DECAP, 0),
3234 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3237 [ACTION_NVGRE_ENCAP] = {
3238 .name = "nvgre_encap",
3239 .help = "NVGRE encapsulation, uses configuration set by \"set"
3241 .priv = PRIV_ACTION(NVGRE_ENCAP,
3242 sizeof(struct action_nvgre_encap_data)),
3243 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3244 .call = parse_vc_action_nvgre_encap,
3246 [ACTION_NVGRE_DECAP] = {
3247 .name = "nvgre_decap",
3248 .help = "Performs a decapsulation action by stripping all"
3249 " headers of the NVGRE tunnel network overlay from the"
3251 .priv = PRIV_ACTION(NVGRE_DECAP, 0),
3252 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3255 [ACTION_L2_ENCAP] = {
3257 .help = "l2 encap, uses configuration set by"
3258 " \"set l2_encap\"",
3259 .priv = PRIV_ACTION(RAW_ENCAP,
3260 sizeof(struct action_raw_encap_data)),
3261 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3262 .call = parse_vc_action_l2_encap,
3264 [ACTION_L2_DECAP] = {
3266 .help = "l2 decap, uses configuration set by"
3267 " \"set l2_decap\"",
3268 .priv = PRIV_ACTION(RAW_DECAP,
3269 sizeof(struct action_raw_decap_data)),
3270 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3271 .call = parse_vc_action_l2_decap,
3273 [ACTION_MPLSOGRE_ENCAP] = {
3274 .name = "mplsogre_encap",
3275 .help = "mplsogre encapsulation, uses configuration set by"
3276 " \"set mplsogre_encap\"",
3277 .priv = PRIV_ACTION(RAW_ENCAP,
3278 sizeof(struct action_raw_encap_data)),
3279 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3280 .call = parse_vc_action_mplsogre_encap,
3282 [ACTION_MPLSOGRE_DECAP] = {
3283 .name = "mplsogre_decap",
3284 .help = "mplsogre decapsulation, uses configuration set by"
3285 " \"set mplsogre_decap\"",
3286 .priv = PRIV_ACTION(RAW_DECAP,
3287 sizeof(struct action_raw_decap_data)),
3288 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3289 .call = parse_vc_action_mplsogre_decap,
3291 [ACTION_MPLSOUDP_ENCAP] = {
3292 .name = "mplsoudp_encap",
3293 .help = "mplsoudp encapsulation, uses configuration set by"
3294 " \"set mplsoudp_encap\"",
3295 .priv = PRIV_ACTION(RAW_ENCAP,
3296 sizeof(struct action_raw_encap_data)),
3297 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3298 .call = parse_vc_action_mplsoudp_encap,
3300 [ACTION_MPLSOUDP_DECAP] = {
3301 .name = "mplsoudp_decap",
3302 .help = "mplsoudp decapsulation, uses configuration set by"
3303 " \"set mplsoudp_decap\"",
3304 .priv = PRIV_ACTION(RAW_DECAP,
3305 sizeof(struct action_raw_decap_data)),
3306 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3307 .call = parse_vc_action_mplsoudp_decap,
3309 [ACTION_SET_IPV4_SRC] = {
3310 .name = "set_ipv4_src",
3311 .help = "Set a new IPv4 source address in the outermost"
3313 .priv = PRIV_ACTION(SET_IPV4_SRC,
3314 sizeof(struct rte_flow_action_set_ipv4)),
3315 .next = NEXT(action_set_ipv4_src),
3318 [ACTION_SET_IPV4_SRC_IPV4_SRC] = {
3319 .name = "ipv4_addr",
3320 .help = "new IPv4 source address to set",
3321 .next = NEXT(action_set_ipv4_src, NEXT_ENTRY(IPV4_ADDR)),
3322 .args = ARGS(ARGS_ENTRY_HTON
3323 (struct rte_flow_action_set_ipv4, ipv4_addr)),
3324 .call = parse_vc_conf,
3326 [ACTION_SET_IPV4_DST] = {
3327 .name = "set_ipv4_dst",
3328 .help = "Set a new IPv4 destination address in the outermost"
3330 .priv = PRIV_ACTION(SET_IPV4_DST,
3331 sizeof(struct rte_flow_action_set_ipv4)),
3332 .next = NEXT(action_set_ipv4_dst),
3335 [ACTION_SET_IPV4_DST_IPV4_DST] = {
3336 .name = "ipv4_addr",
3337 .help = "new IPv4 destination address to set",
3338 .next = NEXT(action_set_ipv4_dst, NEXT_ENTRY(IPV4_ADDR)),
3339 .args = ARGS(ARGS_ENTRY_HTON
3340 (struct rte_flow_action_set_ipv4, ipv4_addr)),
3341 .call = parse_vc_conf,
3343 [ACTION_SET_IPV6_SRC] = {
3344 .name = "set_ipv6_src",
3345 .help = "Set a new IPv6 source address in the outermost"
3347 .priv = PRIV_ACTION(SET_IPV6_SRC,
3348 sizeof(struct rte_flow_action_set_ipv6)),
3349 .next = NEXT(action_set_ipv6_src),
3352 [ACTION_SET_IPV6_SRC_IPV6_SRC] = {
3353 .name = "ipv6_addr",
3354 .help = "new IPv6 source address to set",
3355 .next = NEXT(action_set_ipv6_src, NEXT_ENTRY(IPV6_ADDR)),
3356 .args = ARGS(ARGS_ENTRY_HTON
3357 (struct rte_flow_action_set_ipv6, ipv6_addr)),
3358 .call = parse_vc_conf,
3360 [ACTION_SET_IPV6_DST] = {
3361 .name = "set_ipv6_dst",
3362 .help = "Set a new IPv6 destination address in the outermost"
3364 .priv = PRIV_ACTION(SET_IPV6_DST,
3365 sizeof(struct rte_flow_action_set_ipv6)),
3366 .next = NEXT(action_set_ipv6_dst),
3369 [ACTION_SET_IPV6_DST_IPV6_DST] = {
3370 .name = "ipv6_addr",
3371 .help = "new IPv6 destination address to set",
3372 .next = NEXT(action_set_ipv6_dst, NEXT_ENTRY(IPV6_ADDR)),
3373 .args = ARGS(ARGS_ENTRY_HTON
3374 (struct rte_flow_action_set_ipv6, ipv6_addr)),
3375 .call = parse_vc_conf,
3377 [ACTION_SET_TP_SRC] = {
3378 .name = "set_tp_src",
3379 .help = "set a new source port number in the outermost"
3381 .priv = PRIV_ACTION(SET_TP_SRC,
3382 sizeof(struct rte_flow_action_set_tp)),
3383 .next = NEXT(action_set_tp_src),
3386 [ACTION_SET_TP_SRC_TP_SRC] = {
3388 .help = "new source port number to set",
3389 .next = NEXT(action_set_tp_src, NEXT_ENTRY(UNSIGNED)),
3390 .args = ARGS(ARGS_ENTRY_HTON
3391 (struct rte_flow_action_set_tp, port)),
3392 .call = parse_vc_conf,
3394 [ACTION_SET_TP_DST] = {
3395 .name = "set_tp_dst",
3396 .help = "set a new destination port number in the outermost"
3398 .priv = PRIV_ACTION(SET_TP_DST,
3399 sizeof(struct rte_flow_action_set_tp)),
3400 .next = NEXT(action_set_tp_dst),
3403 [ACTION_SET_TP_DST_TP_DST] = {
3405 .help = "new destination port number to set",
3406 .next = NEXT(action_set_tp_dst, NEXT_ENTRY(UNSIGNED)),
3407 .args = ARGS(ARGS_ENTRY_HTON
3408 (struct rte_flow_action_set_tp, port)),
3409 .call = parse_vc_conf,
3411 [ACTION_MAC_SWAP] = {
3413 .help = "Swap the source and destination MAC addresses"
3414 " in the outermost Ethernet header",
3415 .priv = PRIV_ACTION(MAC_SWAP, 0),
3416 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3419 [ACTION_DEC_TTL] = {
3421 .help = "decrease network TTL if available",
3422 .priv = PRIV_ACTION(DEC_TTL, 0),
3423 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3426 [ACTION_SET_TTL] = {
3428 .help = "set ttl value",
3429 .priv = PRIV_ACTION(SET_TTL,
3430 sizeof(struct rte_flow_action_set_ttl)),
3431 .next = NEXT(action_set_ttl),
3434 [ACTION_SET_TTL_TTL] = {
3435 .name = "ttl_value",
3436 .help = "new ttl value to set",
3437 .next = NEXT(action_set_ttl, NEXT_ENTRY(UNSIGNED)),
3438 .args = ARGS(ARGS_ENTRY_HTON
3439 (struct rte_flow_action_set_ttl, ttl_value)),
3440 .call = parse_vc_conf,
3442 [ACTION_SET_MAC_SRC] = {
3443 .name = "set_mac_src",
3444 .help = "set source mac address",
3445 .priv = PRIV_ACTION(SET_MAC_SRC,
3446 sizeof(struct rte_flow_action_set_mac)),
3447 .next = NEXT(action_set_mac_src),
3450 [ACTION_SET_MAC_SRC_MAC_SRC] = {
3452 .help = "new source mac address",
3453 .next = NEXT(action_set_mac_src, NEXT_ENTRY(MAC_ADDR)),
3454 .args = ARGS(ARGS_ENTRY_HTON
3455 (struct rte_flow_action_set_mac, mac_addr)),
3456 .call = parse_vc_conf,
3458 [ACTION_SET_MAC_DST] = {
3459 .name = "set_mac_dst",
3460 .help = "set destination mac address",
3461 .priv = PRIV_ACTION(SET_MAC_DST,
3462 sizeof(struct rte_flow_action_set_mac)),
3463 .next = NEXT(action_set_mac_dst),
3466 [ACTION_SET_MAC_DST_MAC_DST] = {
3468 .help = "new destination mac address to set",
3469 .next = NEXT(action_set_mac_dst, NEXT_ENTRY(MAC_ADDR)),
3470 .args = ARGS(ARGS_ENTRY_HTON
3471 (struct rte_flow_action_set_mac, mac_addr)),
3472 .call = parse_vc_conf,
3474 [ACTION_INC_TCP_SEQ] = {
3475 .name = "inc_tcp_seq",
3476 .help = "increase TCP sequence number",
3477 .priv = PRIV_ACTION(INC_TCP_SEQ, sizeof(rte_be32_t)),
3478 .next = NEXT(action_inc_tcp_seq),
3481 [ACTION_INC_TCP_SEQ_VALUE] = {
3483 .help = "the value to increase TCP sequence number by",
3484 .next = NEXT(action_inc_tcp_seq, NEXT_ENTRY(UNSIGNED)),
3485 .args = ARGS(ARG_ENTRY_HTON(rte_be32_t)),
3486 .call = parse_vc_conf,
3488 [ACTION_DEC_TCP_SEQ] = {
3489 .name = "dec_tcp_seq",
3490 .help = "decrease TCP sequence number",
3491 .priv = PRIV_ACTION(DEC_TCP_SEQ, sizeof(rte_be32_t)),
3492 .next = NEXT(action_dec_tcp_seq),
3495 [ACTION_DEC_TCP_SEQ_VALUE] = {
3497 .help = "the value to decrease TCP sequence number by",
3498 .next = NEXT(action_dec_tcp_seq, NEXT_ENTRY(UNSIGNED)),
3499 .args = ARGS(ARG_ENTRY_HTON(rte_be32_t)),
3500 .call = parse_vc_conf,
3502 [ACTION_INC_TCP_ACK] = {
3503 .name = "inc_tcp_ack",
3504 .help = "increase TCP acknowledgment number",
3505 .priv = PRIV_ACTION(INC_TCP_ACK, sizeof(rte_be32_t)),
3506 .next = NEXT(action_inc_tcp_ack),
3509 [ACTION_INC_TCP_ACK_VALUE] = {
3511 .help = "the value to increase TCP acknowledgment number by",
3512 .next = NEXT(action_inc_tcp_ack, NEXT_ENTRY(UNSIGNED)),
3513 .args = ARGS(ARG_ENTRY_HTON(rte_be32_t)),
3514 .call = parse_vc_conf,
3516 [ACTION_DEC_TCP_ACK] = {
3517 .name = "dec_tcp_ack",
3518 .help = "decrease TCP acknowledgment number",
3519 .priv = PRIV_ACTION(DEC_TCP_ACK, sizeof(rte_be32_t)),
3520 .next = NEXT(action_dec_tcp_ack),
3523 [ACTION_DEC_TCP_ACK_VALUE] = {
3525 .help = "the value to decrease TCP acknowledgment number by",
3526 .next = NEXT(action_dec_tcp_ack, NEXT_ENTRY(UNSIGNED)),
3527 .args = ARGS(ARG_ENTRY_HTON(rte_be32_t)),
3528 .call = parse_vc_conf,
3530 [ACTION_RAW_ENCAP] = {
3531 .name = "raw_encap",
3532 .help = "encapsulation data, defined by set raw_encap",
3533 .priv = PRIV_ACTION(RAW_ENCAP,
3534 sizeof(struct action_raw_encap_data)),
3535 .next = NEXT(action_raw_encap),
3536 .call = parse_vc_action_raw_encap,
3538 [ACTION_RAW_ENCAP_INDEX] = {
3540 .help = "the index of raw_encap_confs",
3541 .next = NEXT(NEXT_ENTRY(ACTION_RAW_ENCAP_INDEX_VALUE)),
3543 [ACTION_RAW_ENCAP_INDEX_VALUE] = {
3546 .help = "unsigned integer value",
3547 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3548 .call = parse_vc_action_raw_encap_index,
3549 .comp = comp_set_raw_index,
3551 [ACTION_RAW_DECAP] = {
3552 .name = "raw_decap",
3553 .help = "decapsulation data, defined by set raw_encap",
3554 .priv = PRIV_ACTION(RAW_DECAP,
3555 sizeof(struct action_raw_decap_data)),
3556 .next = NEXT(action_raw_decap),
3557 .call = parse_vc_action_raw_decap,
3559 [ACTION_RAW_DECAP_INDEX] = {
3561 .help = "the index of raw_encap_confs",
3562 .next = NEXT(NEXT_ENTRY(ACTION_RAW_DECAP_INDEX_VALUE)),
3564 [ACTION_RAW_DECAP_INDEX_VALUE] = {
3567 .help = "unsigned integer value",
3568 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3569 .call = parse_vc_action_raw_decap_index,
3570 .comp = comp_set_raw_index,
3572 /* Top level command. */
3575 .help = "set raw encap/decap data",
3576 .type = "set raw_encap|raw_decap <index> <pattern>",
3577 .next = NEXT(NEXT_ENTRY
3580 .call = parse_set_init,
3582 /* Sub-level commands. */
3584 .name = "raw_encap",
3585 .help = "set raw encap data",
3586 .next = NEXT(next_set_raw),
3587 .args = ARGS(ARGS_ENTRY_ARB_BOUNDED
3588 (offsetof(struct buffer, port),
3589 sizeof(((struct buffer *)0)->port),
3590 0, RAW_ENCAP_CONFS_MAX_NUM - 1)),
3591 .call = parse_set_raw_encap_decap,
3594 .name = "raw_decap",
3595 .help = "set raw decap data",
3596 .next = NEXT(next_set_raw),
3597 .args = ARGS(ARGS_ENTRY_ARB_BOUNDED
3598 (offsetof(struct buffer, port),
3599 sizeof(((struct buffer *)0)->port),
3600 0, RAW_ENCAP_CONFS_MAX_NUM - 1)),
3601 .call = parse_set_raw_encap_decap,
3606 .help = "index of raw_encap/raw_decap data",
3607 .next = NEXT(next_item),
3610 [ACTION_SET_TAG] = {
3613 .priv = PRIV_ACTION(SET_TAG,
3614 sizeof(struct rte_flow_action_set_tag)),
3615 .next = NEXT(action_set_tag),
3618 [ACTION_SET_TAG_INDEX] = {
3620 .help = "index of tag array",
3621 .next = NEXT(action_set_tag, NEXT_ENTRY(UNSIGNED)),
3622 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_set_tag, index)),
3623 .call = parse_vc_conf,
3625 [ACTION_SET_TAG_DATA] = {
3627 .help = "tag value",
3628 .next = NEXT(action_set_tag, NEXT_ENTRY(UNSIGNED)),
3629 .args = ARGS(ARGS_ENTRY
3630 (struct rte_flow_action_set_tag, data)),
3631 .call = parse_vc_conf,
3633 [ACTION_SET_TAG_MASK] = {
3635 .help = "mask for tag value",
3636 .next = NEXT(action_set_tag, NEXT_ENTRY(UNSIGNED)),
3637 .args = ARGS(ARGS_ENTRY
3638 (struct rte_flow_action_set_tag, mask)),
3639 .call = parse_vc_conf,
3641 [ACTION_SET_META] = {
3643 .help = "set metadata",
3644 .priv = PRIV_ACTION(SET_META,
3645 sizeof(struct rte_flow_action_set_meta)),
3646 .next = NEXT(action_set_meta),
3647 .call = parse_vc_action_set_meta,
3649 [ACTION_SET_META_DATA] = {
3651 .help = "metadata value",
3652 .next = NEXT(action_set_meta, NEXT_ENTRY(UNSIGNED)),
3653 .args = ARGS(ARGS_ENTRY
3654 (struct rte_flow_action_set_meta, data)),
3655 .call = parse_vc_conf,
3657 [ACTION_SET_META_MASK] = {
3659 .help = "mask for metadata value",
3660 .next = NEXT(action_set_meta, NEXT_ENTRY(UNSIGNED)),
3661 .args = ARGS(ARGS_ENTRY
3662 (struct rte_flow_action_set_meta, mask)),
3663 .call = parse_vc_conf,
3665 [ACTION_SET_IPV4_DSCP] = {
3666 .name = "set_ipv4_dscp",
3667 .help = "set DSCP value",
3668 .priv = PRIV_ACTION(SET_IPV4_DSCP,
3669 sizeof(struct rte_flow_action_set_dscp)),
3670 .next = NEXT(action_set_ipv4_dscp),
3673 [ACTION_SET_IPV4_DSCP_VALUE] = {
3674 .name = "dscp_value",
3675 .help = "new IPv4 DSCP value to set",
3676 .next = NEXT(action_set_ipv4_dscp, NEXT_ENTRY(UNSIGNED)),
3677 .args = ARGS(ARGS_ENTRY
3678 (struct rte_flow_action_set_dscp, dscp)),
3679 .call = parse_vc_conf,
3681 [ACTION_SET_IPV6_DSCP] = {
3682 .name = "set_ipv6_dscp",
3683 .help = "set DSCP value",
3684 .priv = PRIV_ACTION(SET_IPV6_DSCP,
3685 sizeof(struct rte_flow_action_set_dscp)),
3686 .next = NEXT(action_set_ipv6_dscp),
3689 [ACTION_SET_IPV6_DSCP_VALUE] = {
3690 .name = "dscp_value",
3691 .help = "new IPv6 DSCP value to set",
3692 .next = NEXT(action_set_ipv6_dscp, NEXT_ENTRY(UNSIGNED)),
3693 .args = ARGS(ARGS_ENTRY
3694 (struct rte_flow_action_set_dscp, dscp)),
3695 .call = parse_vc_conf,
3699 /** Remove and return last entry from argument stack. */
3700 static const struct arg *
3701 pop_args(struct context *ctx)
3703 return ctx->args_num ? ctx->args[--ctx->args_num] : NULL;
3706 /** Add entry on top of the argument stack. */
3708 push_args(struct context *ctx, const struct arg *arg)
3710 if (ctx->args_num == CTX_STACK_SIZE)
3712 ctx->args[ctx->args_num++] = arg;
3716 /** Spread value into buffer according to bit-mask. */
3718 arg_entry_bf_fill(void *dst, uintmax_t val, const struct arg *arg)
3720 uint32_t i = arg->size;
3728 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
3737 unsigned int shift = 0;
3738 uint8_t *buf = (uint8_t *)dst + arg->offset + (i -= sub);
3740 for (shift = 0; arg->mask[i] >> shift; ++shift) {
3741 if (!(arg->mask[i] & (1 << shift)))
3746 *buf &= ~(1 << shift);
3747 *buf |= (val & 1) << shift;
3755 /** Compare a string with a partial one of a given length. */
3757 strcmp_partial(const char *full, const char *partial, size_t partial_len)
3759 int r = strncmp(full, partial, partial_len);
3763 if (strlen(full) <= partial_len)
3765 return full[partial_len];
3769 * Parse a prefix length and generate a bit-mask.
3771 * Last argument (ctx->args) is retrieved to determine mask size, storage
3772 * location and whether the result must use network byte ordering.
3775 parse_prefix(struct context *ctx, const struct token *token,
3776 const char *str, unsigned int len,
3777 void *buf, unsigned int size)
3779 const struct arg *arg = pop_args(ctx);
3780 static const uint8_t conv[] = "\x00\x80\xc0\xe0\xf0\xf8\xfc\xfe\xff";
3787 /* Argument is expected. */
3791 u = strtoumax(str, &end, 0);
3792 if (errno || (size_t)(end - str) != len)
3797 extra = arg_entry_bf_fill(NULL, 0, arg);
3806 if (!arg_entry_bf_fill(ctx->object, v, arg) ||
3807 !arg_entry_bf_fill(ctx->objmask, -1, arg))
3814 if (bytes > size || bytes + !!extra > size)
3818 buf = (uint8_t *)ctx->object + arg->offset;
3819 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
3821 memset((uint8_t *)buf + size - bytes, 0xff, bytes);
3822 memset(buf, 0x00, size - bytes);
3824 ((uint8_t *)buf)[size - bytes - 1] = conv[extra];
3828 memset(buf, 0xff, bytes);
3829 memset((uint8_t *)buf + bytes, 0x00, size - bytes);
3831 ((uint8_t *)buf)[bytes] = conv[extra];
3834 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
3837 push_args(ctx, arg);
3841 /** Default parsing function for token name matching. */
3843 parse_default(struct context *ctx, const struct token *token,
3844 const char *str, unsigned int len,
3845 void *buf, unsigned int size)
3850 if (strcmp_partial(token->name, str, len))
3855 /** Parse flow command, initialize output buffer for subsequent tokens. */
3857 parse_init(struct context *ctx, const struct token *token,
3858 const char *str, unsigned int len,
3859 void *buf, unsigned int size)
3861 struct buffer *out = buf;
3863 /* Token name must match. */
3864 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
3866 /* Nothing else to do if there is no buffer. */
3869 /* Make sure buffer is large enough. */
3870 if (size < sizeof(*out))
3872 /* Initialize buffer. */
3873 memset(out, 0x00, sizeof(*out));
3874 memset((uint8_t *)out + sizeof(*out), 0x22, size - sizeof(*out));
3877 ctx->objmask = NULL;
3881 /** Parse tokens for validate/create commands. */
3883 parse_vc(struct context *ctx, const struct token *token,
3884 const char *str, unsigned int len,
3885 void *buf, unsigned int size)
3887 struct buffer *out = buf;
3891 /* Token name must match. */
3892 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
3894 /* Nothing else to do if there is no buffer. */
3897 if (!out->command) {
3898 if (ctx->curr != VALIDATE && ctx->curr != CREATE)
3900 if (sizeof(*out) > size)
3902 out->command = ctx->curr;
3905 ctx->objmask = NULL;
3906 out->args.vc.data = (uint8_t *)out + size;
3910 ctx->object = &out->args.vc.attr;
3911 ctx->objmask = NULL;
3912 switch (ctx->curr) {
3917 out->args.vc.attr.ingress = 1;
3920 out->args.vc.attr.egress = 1;
3923 out->args.vc.attr.transfer = 1;
3926 out->args.vc.pattern =
3927 (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
3929 ctx->object = out->args.vc.pattern;
3930 ctx->objmask = NULL;
3933 out->args.vc.actions =
3934 (void *)RTE_ALIGN_CEIL((uintptr_t)
3935 (out->args.vc.pattern +
3936 out->args.vc.pattern_n),
3938 ctx->object = out->args.vc.actions;
3939 ctx->objmask = NULL;
3946 if (!out->args.vc.actions) {
3947 const struct parse_item_priv *priv = token->priv;
3948 struct rte_flow_item *item =
3949 out->args.vc.pattern + out->args.vc.pattern_n;
3951 data_size = priv->size * 3; /* spec, last, mask */
3952 data = (void *)RTE_ALIGN_FLOOR((uintptr_t)
3953 (out->args.vc.data - data_size),
3955 if ((uint8_t *)item + sizeof(*item) > data)
3957 *item = (struct rte_flow_item){
3960 ++out->args.vc.pattern_n;
3962 ctx->objmask = NULL;
3964 const struct parse_action_priv *priv = token->priv;
3965 struct rte_flow_action *action =
3966 out->args.vc.actions + out->args.vc.actions_n;
3968 data_size = priv->size; /* configuration */
3969 data = (void *)RTE_ALIGN_FLOOR((uintptr_t)
3970 (out->args.vc.data - data_size),
3972 if ((uint8_t *)action + sizeof(*action) > data)
3974 *action = (struct rte_flow_action){
3976 .conf = data_size ? data : NULL,
3978 ++out->args.vc.actions_n;
3979 ctx->object = action;
3980 ctx->objmask = NULL;
3982 memset(data, 0, data_size);
3983 out->args.vc.data = data;
3984 ctx->objdata = data_size;
3988 /** Parse pattern item parameter type. */
3990 parse_vc_spec(struct context *ctx, const struct token *token,
3991 const char *str, unsigned int len,
3992 void *buf, unsigned int size)
3994 struct buffer *out = buf;
3995 struct rte_flow_item *item;
4001 /* Token name must match. */
4002 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
4004 /* Parse parameter types. */
4005 switch (ctx->curr) {
4006 static const enum index prefix[] = NEXT_ENTRY(PREFIX);
4012 case ITEM_PARAM_SPEC:
4015 case ITEM_PARAM_LAST:
4018 case ITEM_PARAM_PREFIX:
4019 /* Modify next token to expect a prefix. */
4020 if (ctx->next_num < 2)
4022 ctx->next[ctx->next_num - 2] = prefix;
4024 case ITEM_PARAM_MASK:
4030 /* Nothing else to do if there is no buffer. */
4033 if (!out->args.vc.pattern_n)
4035 item = &out->args.vc.pattern[out->args.vc.pattern_n - 1];
4036 data_size = ctx->objdata / 3; /* spec, last, mask */
4037 /* Point to selected object. */
4038 ctx->object = out->args.vc.data + (data_size * index);
4040 ctx->objmask = out->args.vc.data + (data_size * 2); /* mask */
4041 item->mask = ctx->objmask;
4043 ctx->objmask = NULL;
4044 /* Update relevant item pointer. */
4045 *((const void **[]){ &item->spec, &item->last, &item->mask })[index] =
4050 /** Parse action configuration field. */
4052 parse_vc_conf(struct context *ctx, const struct token *token,
4053 const char *str, unsigned int len,
4054 void *buf, unsigned int size)
4056 struct buffer *out = buf;
4059 /* Token name must match. */
4060 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
4062 /* Nothing else to do if there is no buffer. */
4065 /* Point to selected object. */
4066 ctx->object = out->args.vc.data;
4067 ctx->objmask = NULL;
4071 /** Parse RSS action. */
4073 parse_vc_action_rss(struct context *ctx, const struct token *token,
4074 const char *str, unsigned int len,
4075 void *buf, unsigned int size)
4077 struct buffer *out = buf;
4078 struct rte_flow_action *action;
4079 struct action_rss_data *action_rss_data;
4083 ret = parse_vc(ctx, token, str, len, buf, size);
4086 /* Nothing else to do if there is no buffer. */
4089 if (!out->args.vc.actions_n)
4091 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4092 /* Point to selected object. */
4093 ctx->object = out->args.vc.data;
4094 ctx->objmask = NULL;
4095 /* Set up default configuration. */
4096 action_rss_data = ctx->object;
4097 *action_rss_data = (struct action_rss_data){
4098 .conf = (struct rte_flow_action_rss){
4099 .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
4102 .key_len = sizeof(action_rss_data->key),
4103 .queue_num = RTE_MIN(nb_rxq, ACTION_RSS_QUEUE_NUM),
4104 .key = action_rss_data->key,
4105 .queue = action_rss_data->queue,
4107 .key = "testpmd's default RSS hash key, "
4108 "override it for better balancing",
4111 for (i = 0; i < action_rss_data->conf.queue_num; ++i)
4112 action_rss_data->queue[i] = i;
4113 if (!port_id_is_invalid(ctx->port, DISABLED_WARN) &&
4114 ctx->port != (portid_t)RTE_PORT_ALL) {
4115 struct rte_eth_dev_info info;
4118 ret2 = rte_eth_dev_info_get(ctx->port, &info);
4122 action_rss_data->conf.key_len =
4123 RTE_MIN(sizeof(action_rss_data->key),
4124 info.hash_key_size);
4126 action->conf = &action_rss_data->conf;
4131 * Parse func field for RSS action.
4133 * The RTE_ETH_HASH_FUNCTION_* value to assign is derived from the
4134 * ACTION_RSS_FUNC_* index that called this function.
4137 parse_vc_action_rss_func(struct context *ctx, const struct token *token,
4138 const char *str, unsigned int len,
4139 void *buf, unsigned int size)
4141 struct action_rss_data *action_rss_data;
4142 enum rte_eth_hash_function func;
4146 /* Token name must match. */
4147 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
4149 switch (ctx->curr) {
4150 case ACTION_RSS_FUNC_DEFAULT:
4151 func = RTE_ETH_HASH_FUNCTION_DEFAULT;
4153 case ACTION_RSS_FUNC_TOEPLITZ:
4154 func = RTE_ETH_HASH_FUNCTION_TOEPLITZ;
4156 case ACTION_RSS_FUNC_SIMPLE_XOR:
4157 func = RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
4159 case ACTION_RSS_FUNC_SYMMETRIC_TOEPLITZ:
4160 func = RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ;
4167 action_rss_data = ctx->object;
4168 action_rss_data->conf.func = func;
4173 * Parse type field for RSS action.
4175 * Valid tokens are type field names and the "end" token.
4178 parse_vc_action_rss_type(struct context *ctx, const struct token *token,
4179 const char *str, unsigned int len,
4180 void *buf, unsigned int size)
4182 static const enum index next[] = NEXT_ENTRY(ACTION_RSS_TYPE);
4183 struct action_rss_data *action_rss_data;
4189 if (ctx->curr != ACTION_RSS_TYPE)
4191 if (!(ctx->objdata >> 16) && ctx->object) {
4192 action_rss_data = ctx->object;
4193 action_rss_data->conf.types = 0;
4195 if (!strcmp_partial("end", str, len)) {
4196 ctx->objdata &= 0xffff;
4199 for (i = 0; rss_type_table[i].str; ++i)
4200 if (!strcmp_partial(rss_type_table[i].str, str, len))
4202 if (!rss_type_table[i].str)
4204 ctx->objdata = 1 << 16 | (ctx->objdata & 0xffff);
4206 if (ctx->next_num == RTE_DIM(ctx->next))
4208 ctx->next[ctx->next_num++] = next;
4211 action_rss_data = ctx->object;
4212 action_rss_data->conf.types |= rss_type_table[i].rss_type;
4217 * Parse queue field for RSS action.
4219 * Valid tokens are queue indices and the "end" token.
4222 parse_vc_action_rss_queue(struct context *ctx, const struct token *token,
4223 const char *str, unsigned int len,
4224 void *buf, unsigned int size)
4226 static const enum index next[] = NEXT_ENTRY(ACTION_RSS_QUEUE);
4227 struct action_rss_data *action_rss_data;
4228 const struct arg *arg;
4235 if (ctx->curr != ACTION_RSS_QUEUE)
4237 i = ctx->objdata >> 16;
4238 if (!strcmp_partial("end", str, len)) {
4239 ctx->objdata &= 0xffff;
4242 if (i >= ACTION_RSS_QUEUE_NUM)
4244 arg = ARGS_ENTRY_ARB(offsetof(struct action_rss_data, queue) +
4245 i * sizeof(action_rss_data->queue[i]),
4246 sizeof(action_rss_data->queue[i]));
4247 if (push_args(ctx, arg))
4249 ret = parse_int(ctx, token, str, len, NULL, 0);
4255 ctx->objdata = i << 16 | (ctx->objdata & 0xffff);
4257 if (ctx->next_num == RTE_DIM(ctx->next))
4259 ctx->next[ctx->next_num++] = next;
4263 action_rss_data = ctx->object;
4264 action_rss_data->conf.queue_num = i;
4265 action_rss_data->conf.queue = i ? action_rss_data->queue : NULL;
4269 /** Parse VXLAN encap action. */
4271 parse_vc_action_vxlan_encap(struct context *ctx, const struct token *token,
4272 const char *str, unsigned int len,
4273 void *buf, unsigned int size)
4275 struct buffer *out = buf;
4276 struct rte_flow_action *action;
4277 struct action_vxlan_encap_data *action_vxlan_encap_data;
4280 ret = parse_vc(ctx, token, str, len, buf, size);
4283 /* Nothing else to do if there is no buffer. */
4286 if (!out->args.vc.actions_n)
4288 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4289 /* Point to selected object. */
4290 ctx->object = out->args.vc.data;
4291 ctx->objmask = NULL;
4292 /* Set up default configuration. */
4293 action_vxlan_encap_data = ctx->object;
4294 *action_vxlan_encap_data = (struct action_vxlan_encap_data){
4295 .conf = (struct rte_flow_action_vxlan_encap){
4296 .definition = action_vxlan_encap_data->items,
4300 .type = RTE_FLOW_ITEM_TYPE_ETH,
4301 .spec = &action_vxlan_encap_data->item_eth,
4302 .mask = &rte_flow_item_eth_mask,
4305 .type = RTE_FLOW_ITEM_TYPE_VLAN,
4306 .spec = &action_vxlan_encap_data->item_vlan,
4307 .mask = &rte_flow_item_vlan_mask,
4310 .type = RTE_FLOW_ITEM_TYPE_IPV4,
4311 .spec = &action_vxlan_encap_data->item_ipv4,
4312 .mask = &rte_flow_item_ipv4_mask,
4315 .type = RTE_FLOW_ITEM_TYPE_UDP,
4316 .spec = &action_vxlan_encap_data->item_udp,
4317 .mask = &rte_flow_item_udp_mask,
4320 .type = RTE_FLOW_ITEM_TYPE_VXLAN,
4321 .spec = &action_vxlan_encap_data->item_vxlan,
4322 .mask = &rte_flow_item_vxlan_mask,
4325 .type = RTE_FLOW_ITEM_TYPE_END,
4330 .tci = vxlan_encap_conf.vlan_tci,
4334 .src_addr = vxlan_encap_conf.ipv4_src,
4335 .dst_addr = vxlan_encap_conf.ipv4_dst,
4338 .src_port = vxlan_encap_conf.udp_src,
4339 .dst_port = vxlan_encap_conf.udp_dst,
4341 .item_vxlan.flags = 0,
4343 memcpy(action_vxlan_encap_data->item_eth.dst.addr_bytes,
4344 vxlan_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
4345 memcpy(action_vxlan_encap_data->item_eth.src.addr_bytes,
4346 vxlan_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
4347 if (!vxlan_encap_conf.select_ipv4) {
4348 memcpy(&action_vxlan_encap_data->item_ipv6.hdr.src_addr,
4349 &vxlan_encap_conf.ipv6_src,
4350 sizeof(vxlan_encap_conf.ipv6_src));
4351 memcpy(&action_vxlan_encap_data->item_ipv6.hdr.dst_addr,
4352 &vxlan_encap_conf.ipv6_dst,
4353 sizeof(vxlan_encap_conf.ipv6_dst));
4354 action_vxlan_encap_data->items[2] = (struct rte_flow_item){
4355 .type = RTE_FLOW_ITEM_TYPE_IPV6,
4356 .spec = &action_vxlan_encap_data->item_ipv6,
4357 .mask = &rte_flow_item_ipv6_mask,
4360 if (!vxlan_encap_conf.select_vlan)
4361 action_vxlan_encap_data->items[1].type =
4362 RTE_FLOW_ITEM_TYPE_VOID;
4363 if (vxlan_encap_conf.select_tos_ttl) {
4364 if (vxlan_encap_conf.select_ipv4) {
4365 static struct rte_flow_item_ipv4 ipv4_mask_tos;
4367 memcpy(&ipv4_mask_tos, &rte_flow_item_ipv4_mask,
4368 sizeof(ipv4_mask_tos));
4369 ipv4_mask_tos.hdr.type_of_service = 0xff;
4370 ipv4_mask_tos.hdr.time_to_live = 0xff;
4371 action_vxlan_encap_data->item_ipv4.hdr.type_of_service =
4372 vxlan_encap_conf.ip_tos;
4373 action_vxlan_encap_data->item_ipv4.hdr.time_to_live =
4374 vxlan_encap_conf.ip_ttl;
4375 action_vxlan_encap_data->items[2].mask =
4378 static struct rte_flow_item_ipv6 ipv6_mask_tos;
4380 memcpy(&ipv6_mask_tos, &rte_flow_item_ipv6_mask,
4381 sizeof(ipv6_mask_tos));
4382 ipv6_mask_tos.hdr.vtc_flow |=
4383 RTE_BE32(0xfful << RTE_IPV6_HDR_TC_SHIFT);
4384 ipv6_mask_tos.hdr.hop_limits = 0xff;
4385 action_vxlan_encap_data->item_ipv6.hdr.vtc_flow |=
4387 ((uint32_t)vxlan_encap_conf.ip_tos <<
4388 RTE_IPV6_HDR_TC_SHIFT);
4389 action_vxlan_encap_data->item_ipv6.hdr.hop_limits =
4390 vxlan_encap_conf.ip_ttl;
4391 action_vxlan_encap_data->items[2].mask =
4395 memcpy(action_vxlan_encap_data->item_vxlan.vni, vxlan_encap_conf.vni,
4396 RTE_DIM(vxlan_encap_conf.vni));
4397 action->conf = &action_vxlan_encap_data->conf;
4401 /** Parse NVGRE encap action. */
4403 parse_vc_action_nvgre_encap(struct context *ctx, const struct token *token,
4404 const char *str, unsigned int len,
4405 void *buf, unsigned int size)
4407 struct buffer *out = buf;
4408 struct rte_flow_action *action;
4409 struct action_nvgre_encap_data *action_nvgre_encap_data;
4412 ret = parse_vc(ctx, token, str, len, buf, size);
4415 /* Nothing else to do if there is no buffer. */
4418 if (!out->args.vc.actions_n)
4420 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4421 /* Point to selected object. */
4422 ctx->object = out->args.vc.data;
4423 ctx->objmask = NULL;
4424 /* Set up default configuration. */
4425 action_nvgre_encap_data = ctx->object;
4426 *action_nvgre_encap_data = (struct action_nvgre_encap_data){
4427 .conf = (struct rte_flow_action_nvgre_encap){
4428 .definition = action_nvgre_encap_data->items,
4432 .type = RTE_FLOW_ITEM_TYPE_ETH,
4433 .spec = &action_nvgre_encap_data->item_eth,
4434 .mask = &rte_flow_item_eth_mask,
4437 .type = RTE_FLOW_ITEM_TYPE_VLAN,
4438 .spec = &action_nvgre_encap_data->item_vlan,
4439 .mask = &rte_flow_item_vlan_mask,
4442 .type = RTE_FLOW_ITEM_TYPE_IPV4,
4443 .spec = &action_nvgre_encap_data->item_ipv4,
4444 .mask = &rte_flow_item_ipv4_mask,
4447 .type = RTE_FLOW_ITEM_TYPE_NVGRE,
4448 .spec = &action_nvgre_encap_data->item_nvgre,
4449 .mask = &rte_flow_item_nvgre_mask,
4452 .type = RTE_FLOW_ITEM_TYPE_END,
4457 .tci = nvgre_encap_conf.vlan_tci,
4461 .src_addr = nvgre_encap_conf.ipv4_src,
4462 .dst_addr = nvgre_encap_conf.ipv4_dst,
4464 .item_nvgre.flow_id = 0,
4466 memcpy(action_nvgre_encap_data->item_eth.dst.addr_bytes,
4467 nvgre_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
4468 memcpy(action_nvgre_encap_data->item_eth.src.addr_bytes,
4469 nvgre_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
4470 if (!nvgre_encap_conf.select_ipv4) {
4471 memcpy(&action_nvgre_encap_data->item_ipv6.hdr.src_addr,
4472 &nvgre_encap_conf.ipv6_src,
4473 sizeof(nvgre_encap_conf.ipv6_src));
4474 memcpy(&action_nvgre_encap_data->item_ipv6.hdr.dst_addr,
4475 &nvgre_encap_conf.ipv6_dst,
4476 sizeof(nvgre_encap_conf.ipv6_dst));
4477 action_nvgre_encap_data->items[2] = (struct rte_flow_item){
4478 .type = RTE_FLOW_ITEM_TYPE_IPV6,
4479 .spec = &action_nvgre_encap_data->item_ipv6,
4480 .mask = &rte_flow_item_ipv6_mask,
4483 if (!nvgre_encap_conf.select_vlan)
4484 action_nvgre_encap_data->items[1].type =
4485 RTE_FLOW_ITEM_TYPE_VOID;
4486 memcpy(action_nvgre_encap_data->item_nvgre.tni, nvgre_encap_conf.tni,
4487 RTE_DIM(nvgre_encap_conf.tni));
4488 action->conf = &action_nvgre_encap_data->conf;
4492 /** Parse l2 encap action. */
4494 parse_vc_action_l2_encap(struct context *ctx, const struct token *token,
4495 const char *str, unsigned int len,
4496 void *buf, unsigned int size)
4498 struct buffer *out = buf;
4499 struct rte_flow_action *action;
4500 struct action_raw_encap_data *action_encap_data;
4501 struct rte_flow_item_eth eth = { .type = 0, };
4502 struct rte_flow_item_vlan vlan = {
4503 .tci = mplsoudp_encap_conf.vlan_tci,
4509 ret = parse_vc(ctx, token, str, len, buf, size);
4512 /* Nothing else to do if there is no buffer. */
4515 if (!out->args.vc.actions_n)
4517 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4518 /* Point to selected object. */
4519 ctx->object = out->args.vc.data;
4520 ctx->objmask = NULL;
4521 /* Copy the headers to the buffer. */
4522 action_encap_data = ctx->object;
4523 *action_encap_data = (struct action_raw_encap_data) {
4524 .conf = (struct rte_flow_action_raw_encap){
4525 .data = action_encap_data->data,
4529 header = action_encap_data->data;
4530 if (l2_encap_conf.select_vlan)
4531 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
4532 else if (l2_encap_conf.select_ipv4)
4533 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4535 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4536 memcpy(eth.dst.addr_bytes,
4537 l2_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
4538 memcpy(eth.src.addr_bytes,
4539 l2_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
4540 memcpy(header, ð, sizeof(eth));
4541 header += sizeof(eth);
4542 if (l2_encap_conf.select_vlan) {
4543 if (l2_encap_conf.select_ipv4)
4544 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4546 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4547 memcpy(header, &vlan, sizeof(vlan));
4548 header += sizeof(vlan);
4550 action_encap_data->conf.size = header -
4551 action_encap_data->data;
4552 action->conf = &action_encap_data->conf;
4556 /** Parse l2 decap action. */
4558 parse_vc_action_l2_decap(struct context *ctx, const struct token *token,
4559 const char *str, unsigned int len,
4560 void *buf, unsigned int size)
4562 struct buffer *out = buf;
4563 struct rte_flow_action *action;
4564 struct action_raw_decap_data *action_decap_data;
4565 struct rte_flow_item_eth eth = { .type = 0, };
4566 struct rte_flow_item_vlan vlan = {
4567 .tci = mplsoudp_encap_conf.vlan_tci,
4573 ret = parse_vc(ctx, token, str, len, buf, size);
4576 /* Nothing else to do if there is no buffer. */
4579 if (!out->args.vc.actions_n)
4581 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4582 /* Point to selected object. */
4583 ctx->object = out->args.vc.data;
4584 ctx->objmask = NULL;
4585 /* Copy the headers to the buffer. */
4586 action_decap_data = ctx->object;
4587 *action_decap_data = (struct action_raw_decap_data) {
4588 .conf = (struct rte_flow_action_raw_decap){
4589 .data = action_decap_data->data,
4593 header = action_decap_data->data;
4594 if (l2_decap_conf.select_vlan)
4595 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
4596 memcpy(header, ð, sizeof(eth));
4597 header += sizeof(eth);
4598 if (l2_decap_conf.select_vlan) {
4599 memcpy(header, &vlan, sizeof(vlan));
4600 header += sizeof(vlan);
4602 action_decap_data->conf.size = header -
4603 action_decap_data->data;
4604 action->conf = &action_decap_data->conf;
4608 #define ETHER_TYPE_MPLS_UNICAST 0x8847
4610 /** Parse MPLSOGRE encap action. */
4612 parse_vc_action_mplsogre_encap(struct context *ctx, const struct token *token,
4613 const char *str, unsigned int len,
4614 void *buf, unsigned int size)
4616 struct buffer *out = buf;
4617 struct rte_flow_action *action;
4618 struct action_raw_encap_data *action_encap_data;
4619 struct rte_flow_item_eth eth = { .type = 0, };
4620 struct rte_flow_item_vlan vlan = {
4621 .tci = mplsogre_encap_conf.vlan_tci,
4624 struct rte_flow_item_ipv4 ipv4 = {
4626 .src_addr = mplsogre_encap_conf.ipv4_src,
4627 .dst_addr = mplsogre_encap_conf.ipv4_dst,
4628 .next_proto_id = IPPROTO_GRE,
4629 .version_ihl = RTE_IPV4_VHL_DEF,
4630 .time_to_live = IPDEFTTL,
4633 struct rte_flow_item_ipv6 ipv6 = {
4635 .proto = IPPROTO_GRE,
4636 .hop_limits = IPDEFTTL,
4639 struct rte_flow_item_gre gre = {
4640 .protocol = rte_cpu_to_be_16(ETHER_TYPE_MPLS_UNICAST),
4642 struct rte_flow_item_mpls mpls = {
4648 ret = parse_vc(ctx, token, str, len, buf, size);
4651 /* Nothing else to do if there is no buffer. */
4654 if (!out->args.vc.actions_n)
4656 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4657 /* Point to selected object. */
4658 ctx->object = out->args.vc.data;
4659 ctx->objmask = NULL;
4660 /* Copy the headers to the buffer. */
4661 action_encap_data = ctx->object;
4662 *action_encap_data = (struct action_raw_encap_data) {
4663 .conf = (struct rte_flow_action_raw_encap){
4664 .data = action_encap_data->data,
4669 header = action_encap_data->data;
4670 if (mplsogre_encap_conf.select_vlan)
4671 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
4672 else if (mplsogre_encap_conf.select_ipv4)
4673 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4675 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4676 memcpy(eth.dst.addr_bytes,
4677 mplsogre_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
4678 memcpy(eth.src.addr_bytes,
4679 mplsogre_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
4680 memcpy(header, ð, sizeof(eth));
4681 header += sizeof(eth);
4682 if (mplsogre_encap_conf.select_vlan) {
4683 if (mplsogre_encap_conf.select_ipv4)
4684 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4686 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4687 memcpy(header, &vlan, sizeof(vlan));
4688 header += sizeof(vlan);
4690 if (mplsogre_encap_conf.select_ipv4) {
4691 memcpy(header, &ipv4, sizeof(ipv4));
4692 header += sizeof(ipv4);
4694 memcpy(&ipv6.hdr.src_addr,
4695 &mplsogre_encap_conf.ipv6_src,
4696 sizeof(mplsogre_encap_conf.ipv6_src));
4697 memcpy(&ipv6.hdr.dst_addr,
4698 &mplsogre_encap_conf.ipv6_dst,
4699 sizeof(mplsogre_encap_conf.ipv6_dst));
4700 memcpy(header, &ipv6, sizeof(ipv6));
4701 header += sizeof(ipv6);
4703 memcpy(header, &gre, sizeof(gre));
4704 header += sizeof(gre);
4705 memcpy(mpls.label_tc_s, mplsogre_encap_conf.label,
4706 RTE_DIM(mplsogre_encap_conf.label));
4707 mpls.label_tc_s[2] |= 0x1;
4708 memcpy(header, &mpls, sizeof(mpls));
4709 header += sizeof(mpls);
4710 action_encap_data->conf.size = header -
4711 action_encap_data->data;
4712 action->conf = &action_encap_data->conf;
4716 /** Parse MPLSOGRE decap action. */
4718 parse_vc_action_mplsogre_decap(struct context *ctx, const struct token *token,
4719 const char *str, unsigned int len,
4720 void *buf, unsigned int size)
4722 struct buffer *out = buf;
4723 struct rte_flow_action *action;
4724 struct action_raw_decap_data *action_decap_data;
4725 struct rte_flow_item_eth eth = { .type = 0, };
4726 struct rte_flow_item_vlan vlan = {.tci = 0};
4727 struct rte_flow_item_ipv4 ipv4 = {
4729 .next_proto_id = IPPROTO_GRE,
4732 struct rte_flow_item_ipv6 ipv6 = {
4734 .proto = IPPROTO_GRE,
4737 struct rte_flow_item_gre gre = {
4738 .protocol = rte_cpu_to_be_16(ETHER_TYPE_MPLS_UNICAST),
4740 struct rte_flow_item_mpls mpls;
4744 ret = parse_vc(ctx, token, str, len, buf, size);
4747 /* Nothing else to do if there is no buffer. */
4750 if (!out->args.vc.actions_n)
4752 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4753 /* Point to selected object. */
4754 ctx->object = out->args.vc.data;
4755 ctx->objmask = NULL;
4756 /* Copy the headers to the buffer. */
4757 action_decap_data = ctx->object;
4758 *action_decap_data = (struct action_raw_decap_data) {
4759 .conf = (struct rte_flow_action_raw_decap){
4760 .data = action_decap_data->data,
4764 header = action_decap_data->data;
4765 if (mplsogre_decap_conf.select_vlan)
4766 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
4767 else if (mplsogre_encap_conf.select_ipv4)
4768 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4770 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4771 memcpy(eth.dst.addr_bytes,
4772 mplsogre_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
4773 memcpy(eth.src.addr_bytes,
4774 mplsogre_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
4775 memcpy(header, ð, sizeof(eth));
4776 header += sizeof(eth);
4777 if (mplsogre_encap_conf.select_vlan) {
4778 if (mplsogre_encap_conf.select_ipv4)
4779 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4781 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4782 memcpy(header, &vlan, sizeof(vlan));
4783 header += sizeof(vlan);
4785 if (mplsogre_encap_conf.select_ipv4) {
4786 memcpy(header, &ipv4, sizeof(ipv4));
4787 header += sizeof(ipv4);
4789 memcpy(header, &ipv6, sizeof(ipv6));
4790 header += sizeof(ipv6);
4792 memcpy(header, &gre, sizeof(gre));
4793 header += sizeof(gre);
4794 memset(&mpls, 0, sizeof(mpls));
4795 memcpy(header, &mpls, sizeof(mpls));
4796 header += sizeof(mpls);
4797 action_decap_data->conf.size = header -
4798 action_decap_data->data;
4799 action->conf = &action_decap_data->conf;
4803 /** Parse MPLSOUDP encap action. */
4805 parse_vc_action_mplsoudp_encap(struct context *ctx, const struct token *token,
4806 const char *str, unsigned int len,
4807 void *buf, unsigned int size)
4809 struct buffer *out = buf;
4810 struct rte_flow_action *action;
4811 struct action_raw_encap_data *action_encap_data;
4812 struct rte_flow_item_eth eth = { .type = 0, };
4813 struct rte_flow_item_vlan vlan = {
4814 .tci = mplsoudp_encap_conf.vlan_tci,
4817 struct rte_flow_item_ipv4 ipv4 = {
4819 .src_addr = mplsoudp_encap_conf.ipv4_src,
4820 .dst_addr = mplsoudp_encap_conf.ipv4_dst,
4821 .next_proto_id = IPPROTO_UDP,
4822 .version_ihl = RTE_IPV4_VHL_DEF,
4823 .time_to_live = IPDEFTTL,
4826 struct rte_flow_item_ipv6 ipv6 = {
4828 .proto = IPPROTO_UDP,
4829 .hop_limits = IPDEFTTL,
4832 struct rte_flow_item_udp udp = {
4834 .src_port = mplsoudp_encap_conf.udp_src,
4835 .dst_port = mplsoudp_encap_conf.udp_dst,
4838 struct rte_flow_item_mpls mpls;
4842 ret = parse_vc(ctx, token, str, len, buf, size);
4845 /* Nothing else to do if there is no buffer. */
4848 if (!out->args.vc.actions_n)
4850 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4851 /* Point to selected object. */
4852 ctx->object = out->args.vc.data;
4853 ctx->objmask = NULL;
4854 /* Copy the headers to the buffer. */
4855 action_encap_data = ctx->object;
4856 *action_encap_data = (struct action_raw_encap_data) {
4857 .conf = (struct rte_flow_action_raw_encap){
4858 .data = action_encap_data->data,
4863 header = action_encap_data->data;
4864 if (mplsoudp_encap_conf.select_vlan)
4865 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
4866 else if (mplsoudp_encap_conf.select_ipv4)
4867 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4869 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4870 memcpy(eth.dst.addr_bytes,
4871 mplsoudp_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
4872 memcpy(eth.src.addr_bytes,
4873 mplsoudp_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
4874 memcpy(header, ð, sizeof(eth));
4875 header += sizeof(eth);
4876 if (mplsoudp_encap_conf.select_vlan) {
4877 if (mplsoudp_encap_conf.select_ipv4)
4878 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4880 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4881 memcpy(header, &vlan, sizeof(vlan));
4882 header += sizeof(vlan);
4884 if (mplsoudp_encap_conf.select_ipv4) {
4885 memcpy(header, &ipv4, sizeof(ipv4));
4886 header += sizeof(ipv4);
4888 memcpy(&ipv6.hdr.src_addr,
4889 &mplsoudp_encap_conf.ipv6_src,
4890 sizeof(mplsoudp_encap_conf.ipv6_src));
4891 memcpy(&ipv6.hdr.dst_addr,
4892 &mplsoudp_encap_conf.ipv6_dst,
4893 sizeof(mplsoudp_encap_conf.ipv6_dst));
4894 memcpy(header, &ipv6, sizeof(ipv6));
4895 header += sizeof(ipv6);
4897 memcpy(header, &udp, sizeof(udp));
4898 header += sizeof(udp);
4899 memcpy(mpls.label_tc_s, mplsoudp_encap_conf.label,
4900 RTE_DIM(mplsoudp_encap_conf.label));
4901 mpls.label_tc_s[2] |= 0x1;
4902 memcpy(header, &mpls, sizeof(mpls));
4903 header += sizeof(mpls);
4904 action_encap_data->conf.size = header -
4905 action_encap_data->data;
4906 action->conf = &action_encap_data->conf;
4910 /** Parse MPLSOUDP decap action. */
4912 parse_vc_action_mplsoudp_decap(struct context *ctx, const struct token *token,
4913 const char *str, unsigned int len,
4914 void *buf, unsigned int size)
4916 struct buffer *out = buf;
4917 struct rte_flow_action *action;
4918 struct action_raw_decap_data *action_decap_data;
4919 struct rte_flow_item_eth eth = { .type = 0, };
4920 struct rte_flow_item_vlan vlan = {.tci = 0};
4921 struct rte_flow_item_ipv4 ipv4 = {
4923 .next_proto_id = IPPROTO_UDP,
4926 struct rte_flow_item_ipv6 ipv6 = {
4928 .proto = IPPROTO_UDP,
4931 struct rte_flow_item_udp udp = {
4933 .dst_port = rte_cpu_to_be_16(6635),
4936 struct rte_flow_item_mpls mpls;
4940 ret = parse_vc(ctx, token, str, len, buf, size);
4943 /* Nothing else to do if there is no buffer. */
4946 if (!out->args.vc.actions_n)
4948 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4949 /* Point to selected object. */
4950 ctx->object = out->args.vc.data;
4951 ctx->objmask = NULL;
4952 /* Copy the headers to the buffer. */
4953 action_decap_data = ctx->object;
4954 *action_decap_data = (struct action_raw_decap_data) {
4955 .conf = (struct rte_flow_action_raw_decap){
4956 .data = action_decap_data->data,
4960 header = action_decap_data->data;
4961 if (mplsoudp_decap_conf.select_vlan)
4962 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
4963 else if (mplsoudp_encap_conf.select_ipv4)
4964 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4966 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4967 memcpy(eth.dst.addr_bytes,
4968 mplsoudp_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
4969 memcpy(eth.src.addr_bytes,
4970 mplsoudp_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
4971 memcpy(header, ð, sizeof(eth));
4972 header += sizeof(eth);
4973 if (mplsoudp_encap_conf.select_vlan) {
4974 if (mplsoudp_encap_conf.select_ipv4)
4975 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4977 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4978 memcpy(header, &vlan, sizeof(vlan));
4979 header += sizeof(vlan);
4981 if (mplsoudp_encap_conf.select_ipv4) {
4982 memcpy(header, &ipv4, sizeof(ipv4));
4983 header += sizeof(ipv4);
4985 memcpy(header, &ipv6, sizeof(ipv6));
4986 header += sizeof(ipv6);
4988 memcpy(header, &udp, sizeof(udp));
4989 header += sizeof(udp);
4990 memset(&mpls, 0, sizeof(mpls));
4991 memcpy(header, &mpls, sizeof(mpls));
4992 header += sizeof(mpls);
4993 action_decap_data->conf.size = header -
4994 action_decap_data->data;
4995 action->conf = &action_decap_data->conf;
5000 parse_vc_action_raw_decap_index(struct context *ctx, const struct token *token,
5001 const char *str, unsigned int len, void *buf,
5004 struct action_raw_decap_data *action_raw_decap_data;
5005 struct rte_flow_action *action;
5006 const struct arg *arg;
5007 struct buffer *out = buf;
5011 RTE_SET_USED(token);
5014 arg = ARGS_ENTRY_ARB_BOUNDED
5015 (offsetof(struct action_raw_decap_data, idx),
5016 sizeof(((struct action_raw_decap_data *)0)->idx),
5017 0, RAW_ENCAP_CONFS_MAX_NUM - 1);
5018 if (push_args(ctx, arg))
5020 ret = parse_int(ctx, token, str, len, NULL, 0);
5027 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
5028 action_raw_decap_data = ctx->object;
5029 idx = action_raw_decap_data->idx;
5030 action_raw_decap_data->conf.data = raw_decap_confs[idx].data;
5031 action_raw_decap_data->conf.size = raw_decap_confs[idx].size;
5032 action->conf = &action_raw_decap_data->conf;
5038 parse_vc_action_raw_encap_index(struct context *ctx, const struct token *token,
5039 const char *str, unsigned int len, void *buf,
5042 struct action_raw_encap_data *action_raw_encap_data;
5043 struct rte_flow_action *action;
5044 const struct arg *arg;
5045 struct buffer *out = buf;
5049 RTE_SET_USED(token);
5052 if (ctx->curr != ACTION_RAW_ENCAP_INDEX_VALUE)
5054 arg = ARGS_ENTRY_ARB_BOUNDED
5055 (offsetof(struct action_raw_encap_data, idx),
5056 sizeof(((struct action_raw_encap_data *)0)->idx),
5057 0, RAW_ENCAP_CONFS_MAX_NUM - 1);
5058 if (push_args(ctx, arg))
5060 ret = parse_int(ctx, token, str, len, NULL, 0);
5067 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
5068 action_raw_encap_data = ctx->object;
5069 idx = action_raw_encap_data->idx;
5070 action_raw_encap_data->conf.data = raw_encap_confs[idx].data;
5071 action_raw_encap_data->conf.size = raw_encap_confs[idx].size;
5072 action_raw_encap_data->conf.preserve = NULL;
5073 action->conf = &action_raw_encap_data->conf;
5078 parse_vc_action_raw_encap(struct context *ctx, const struct token *token,
5079 const char *str, unsigned int len, void *buf,
5082 struct buffer *out = buf;
5083 struct rte_flow_action *action;
5084 struct action_raw_encap_data *action_raw_encap_data = NULL;
5087 ret = parse_vc(ctx, token, str, len, buf, size);
5090 /* Nothing else to do if there is no buffer. */
5093 if (!out->args.vc.actions_n)
5095 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
5096 /* Point to selected object. */
5097 ctx->object = out->args.vc.data;
5098 ctx->objmask = NULL;
5099 /* Copy the headers to the buffer. */
5100 action_raw_encap_data = ctx->object;
5101 action_raw_encap_data->conf.data = raw_encap_confs[0].data;
5102 action_raw_encap_data->conf.preserve = NULL;
5103 action_raw_encap_data->conf.size = raw_encap_confs[0].size;
5104 action->conf = &action_raw_encap_data->conf;
5109 parse_vc_action_raw_decap(struct context *ctx, const struct token *token,
5110 const char *str, unsigned int len, void *buf,
5113 struct buffer *out = buf;
5114 struct rte_flow_action *action;
5115 struct action_raw_decap_data *action_raw_decap_data = NULL;
5118 ret = parse_vc(ctx, token, str, len, buf, size);
5121 /* Nothing else to do if there is no buffer. */
5124 if (!out->args.vc.actions_n)
5126 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
5127 /* Point to selected object. */
5128 ctx->object = out->args.vc.data;
5129 ctx->objmask = NULL;
5130 /* Copy the headers to the buffer. */
5131 action_raw_decap_data = ctx->object;
5132 action_raw_decap_data->conf.data = raw_decap_confs[0].data;
5133 action_raw_decap_data->conf.size = raw_decap_confs[0].size;
5134 action->conf = &action_raw_decap_data->conf;
5139 parse_vc_action_set_meta(struct context *ctx, const struct token *token,
5140 const char *str, unsigned int len, void *buf,
5145 ret = parse_vc(ctx, token, str, len, buf, size);
5148 ret = rte_flow_dynf_metadata_register();
5154 /** Parse tokens for destroy command. */
5156 parse_destroy(struct context *ctx, const struct token *token,
5157 const char *str, unsigned int len,
5158 void *buf, unsigned int size)
5160 struct buffer *out = buf;
5162 /* Token name must match. */
5163 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5165 /* Nothing else to do if there is no buffer. */
5168 if (!out->command) {
5169 if (ctx->curr != DESTROY)
5171 if (sizeof(*out) > size)
5173 out->command = ctx->curr;
5176 ctx->objmask = NULL;
5177 out->args.destroy.rule =
5178 (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
5182 if (((uint8_t *)(out->args.destroy.rule + out->args.destroy.rule_n) +
5183 sizeof(*out->args.destroy.rule)) > (uint8_t *)out + size)
5186 ctx->object = out->args.destroy.rule + out->args.destroy.rule_n++;
5187 ctx->objmask = NULL;
5191 /** Parse tokens for flush command. */
5193 parse_flush(struct context *ctx, const struct token *token,
5194 const char *str, unsigned int len,
5195 void *buf, unsigned int size)
5197 struct buffer *out = buf;
5199 /* Token name must match. */
5200 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5202 /* Nothing else to do if there is no buffer. */
5205 if (!out->command) {
5206 if (ctx->curr != FLUSH)
5208 if (sizeof(*out) > size)
5210 out->command = ctx->curr;
5213 ctx->objmask = NULL;
5218 /** Parse tokens for dump command. */
5220 parse_dump(struct context *ctx, const struct token *token,
5221 const char *str, unsigned int len,
5222 void *buf, unsigned int size)
5224 struct buffer *out = buf;
5226 /* Token name must match. */
5227 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5229 /* Nothing else to do if there is no buffer. */
5232 if (!out->command) {
5233 if (ctx->curr != DUMP)
5235 if (sizeof(*out) > size)
5237 out->command = ctx->curr;
5240 ctx->objmask = NULL;
5245 /** Parse tokens for query command. */
5247 parse_query(struct context *ctx, const struct token *token,
5248 const char *str, unsigned int len,
5249 void *buf, unsigned int size)
5251 struct buffer *out = buf;
5253 /* Token name must match. */
5254 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5256 /* Nothing else to do if there is no buffer. */
5259 if (!out->command) {
5260 if (ctx->curr != QUERY)
5262 if (sizeof(*out) > size)
5264 out->command = ctx->curr;
5267 ctx->objmask = NULL;
5272 /** Parse action names. */
5274 parse_action(struct context *ctx, const struct token *token,
5275 const char *str, unsigned int len,
5276 void *buf, unsigned int size)
5278 struct buffer *out = buf;
5279 const struct arg *arg = pop_args(ctx);
5283 /* Argument is expected. */
5286 /* Parse action name. */
5287 for (i = 0; next_action[i]; ++i) {
5288 const struct parse_action_priv *priv;
5290 token = &token_list[next_action[i]];
5291 if (strcmp_partial(token->name, str, len))
5297 memcpy((uint8_t *)ctx->object + arg->offset,
5303 push_args(ctx, arg);
5307 /** Parse tokens for list command. */
5309 parse_list(struct context *ctx, const struct token *token,
5310 const char *str, unsigned int len,
5311 void *buf, unsigned int size)
5313 struct buffer *out = buf;
5315 /* Token name must match. */
5316 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5318 /* Nothing else to do if there is no buffer. */
5321 if (!out->command) {
5322 if (ctx->curr != LIST)
5324 if (sizeof(*out) > size)
5326 out->command = ctx->curr;
5329 ctx->objmask = NULL;
5330 out->args.list.group =
5331 (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
5335 if (((uint8_t *)(out->args.list.group + out->args.list.group_n) +
5336 sizeof(*out->args.list.group)) > (uint8_t *)out + size)
5339 ctx->object = out->args.list.group + out->args.list.group_n++;
5340 ctx->objmask = NULL;
5344 /** Parse tokens for isolate command. */
5346 parse_isolate(struct context *ctx, const struct token *token,
5347 const char *str, unsigned int len,
5348 void *buf, unsigned int size)
5350 struct buffer *out = buf;
5352 /* Token name must match. */
5353 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5355 /* Nothing else to do if there is no buffer. */
5358 if (!out->command) {
5359 if (ctx->curr != ISOLATE)
5361 if (sizeof(*out) > size)
5363 out->command = ctx->curr;
5366 ctx->objmask = NULL;
5372 * Parse signed/unsigned integers 8 to 64-bit long.
5374 * Last argument (ctx->args) is retrieved to determine integer type and
5378 parse_int(struct context *ctx, const struct token *token,
5379 const char *str, unsigned int len,
5380 void *buf, unsigned int size)
5382 const struct arg *arg = pop_args(ctx);
5387 /* Argument is expected. */
5392 (uintmax_t)strtoimax(str, &end, 0) :
5393 strtoumax(str, &end, 0);
5394 if (errno || (size_t)(end - str) != len)
5397 ((arg->sign && ((intmax_t)u < (intmax_t)arg->min ||
5398 (intmax_t)u > (intmax_t)arg->max)) ||
5399 (!arg->sign && (u < arg->min || u > arg->max))))
5404 if (!arg_entry_bf_fill(ctx->object, u, arg) ||
5405 !arg_entry_bf_fill(ctx->objmask, -1, arg))
5409 buf = (uint8_t *)ctx->object + arg->offset;
5411 if (u > RTE_LEN2MASK(size * CHAR_BIT, uint64_t))
5415 case sizeof(uint8_t):
5416 *(uint8_t *)buf = u;
5418 case sizeof(uint16_t):
5419 *(uint16_t *)buf = arg->hton ? rte_cpu_to_be_16(u) : u;
5421 case sizeof(uint8_t [3]):
5422 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
5424 ((uint8_t *)buf)[0] = u;
5425 ((uint8_t *)buf)[1] = u >> 8;
5426 ((uint8_t *)buf)[2] = u >> 16;
5430 ((uint8_t *)buf)[0] = u >> 16;
5431 ((uint8_t *)buf)[1] = u >> 8;
5432 ((uint8_t *)buf)[2] = u;
5434 case sizeof(uint32_t):
5435 *(uint32_t *)buf = arg->hton ? rte_cpu_to_be_32(u) : u;
5437 case sizeof(uint64_t):
5438 *(uint64_t *)buf = arg->hton ? rte_cpu_to_be_64(u) : u;
5443 if (ctx->objmask && buf != (uint8_t *)ctx->objmask + arg->offset) {
5445 buf = (uint8_t *)ctx->objmask + arg->offset;
5450 push_args(ctx, arg);
5457 * Three arguments (ctx->args) are retrieved from the stack to store data,
5458 * its actual length and address (in that order).
5461 parse_string(struct context *ctx, const struct token *token,
5462 const char *str, unsigned int len,
5463 void *buf, unsigned int size)
5465 const struct arg *arg_data = pop_args(ctx);
5466 const struct arg *arg_len = pop_args(ctx);
5467 const struct arg *arg_addr = pop_args(ctx);
5468 char tmp[16]; /* Ought to be enough. */
5471 /* Arguments are expected. */
5475 push_args(ctx, arg_data);
5479 push_args(ctx, arg_len);
5480 push_args(ctx, arg_data);
5483 size = arg_data->size;
5484 /* Bit-mask fill is not supported. */
5485 if (arg_data->mask || size < len)
5489 /* Let parse_int() fill length information first. */
5490 ret = snprintf(tmp, sizeof(tmp), "%u", len);
5493 push_args(ctx, arg_len);
5494 ret = parse_int(ctx, token, tmp, ret, NULL, 0);
5499 buf = (uint8_t *)ctx->object + arg_data->offset;
5500 /* Output buffer is not necessarily NUL-terminated. */
5501 memcpy(buf, str, len);
5502 memset((uint8_t *)buf + len, 0x00, size - len);
5504 memset((uint8_t *)ctx->objmask + arg_data->offset, 0xff, len);
5505 /* Save address if requested. */
5506 if (arg_addr->size) {
5507 memcpy((uint8_t *)ctx->object + arg_addr->offset,
5509 (uint8_t *)ctx->object + arg_data->offset
5513 memcpy((uint8_t *)ctx->objmask + arg_addr->offset,
5515 (uint8_t *)ctx->objmask + arg_data->offset
5521 push_args(ctx, arg_addr);
5522 push_args(ctx, arg_len);
5523 push_args(ctx, arg_data);
5528 parse_hex_string(const char *src, uint8_t *dst, uint32_t *size)
5534 /* Check input parameters */
5535 if ((src == NULL) ||
5541 /* Convert chars to bytes */
5542 for (i = 0, len = 0; i < *size; i += 2) {
5543 snprintf(tmp, 3, "%s", src + i);
5544 dst[len++] = strtoul(tmp, &c, 16);
5559 parse_hex(struct context *ctx, const struct token *token,
5560 const char *str, unsigned int len,
5561 void *buf, unsigned int size)
5563 const struct arg *arg_data = pop_args(ctx);
5564 const struct arg *arg_len = pop_args(ctx);
5565 const struct arg *arg_addr = pop_args(ctx);
5566 char tmp[16]; /* Ought to be enough. */
5568 unsigned int hexlen = len;
5569 unsigned int length = 256;
5570 uint8_t hex_tmp[length];
5572 /* Arguments are expected. */
5576 push_args(ctx, arg_data);
5580 push_args(ctx, arg_len);
5581 push_args(ctx, arg_data);
5584 size = arg_data->size;
5585 /* Bit-mask fill is not supported. */
5591 /* translate bytes string to array. */
5592 if (str[0] == '0' && ((str[1] == 'x') ||
5597 if (hexlen > length)
5599 ret = parse_hex_string(str, hex_tmp, &hexlen);
5602 /* Let parse_int() fill length information first. */
5603 ret = snprintf(tmp, sizeof(tmp), "%u", hexlen);
5606 push_args(ctx, arg_len);
5607 ret = parse_int(ctx, token, tmp, ret, NULL, 0);
5612 buf = (uint8_t *)ctx->object + arg_data->offset;
5613 /* Output buffer is not necessarily NUL-terminated. */
5614 memcpy(buf, hex_tmp, hexlen);
5615 memset((uint8_t *)buf + hexlen, 0x00, size - hexlen);
5617 memset((uint8_t *)ctx->objmask + arg_data->offset,
5619 /* Save address if requested. */
5620 if (arg_addr->size) {
5621 memcpy((uint8_t *)ctx->object + arg_addr->offset,
5623 (uint8_t *)ctx->object + arg_data->offset
5627 memcpy((uint8_t *)ctx->objmask + arg_addr->offset,
5629 (uint8_t *)ctx->objmask + arg_data->offset
5635 push_args(ctx, arg_addr);
5636 push_args(ctx, arg_len);
5637 push_args(ctx, arg_data);
5643 * Parse a zero-ended string.
5646 parse_string0(struct context *ctx, const struct token *token __rte_unused,
5647 const char *str, unsigned int len,
5648 void *buf, unsigned int size)
5650 const struct arg *arg_data = pop_args(ctx);
5652 /* Arguments are expected. */
5655 size = arg_data->size;
5656 /* Bit-mask fill is not supported. */
5657 if (arg_data->mask || size < len + 1)
5661 buf = (uint8_t *)ctx->object + arg_data->offset;
5662 strncpy(buf, str, len);
5664 memset((uint8_t *)ctx->objmask + arg_data->offset, 0xff, len);
5667 push_args(ctx, arg_data);
5672 * Parse a MAC address.
5674 * Last argument (ctx->args) is retrieved to determine storage size and
5678 parse_mac_addr(struct context *ctx, const struct token *token,
5679 const char *str, unsigned int len,
5680 void *buf, unsigned int size)
5682 const struct arg *arg = pop_args(ctx);
5683 struct rte_ether_addr tmp;
5687 /* Argument is expected. */
5691 /* Bit-mask fill is not supported. */
5692 if (arg->mask || size != sizeof(tmp))
5694 /* Only network endian is supported. */
5697 ret = cmdline_parse_etheraddr(NULL, str, &tmp, size);
5698 if (ret < 0 || (unsigned int)ret != len)
5702 buf = (uint8_t *)ctx->object + arg->offset;
5703 memcpy(buf, &tmp, size);
5705 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
5708 push_args(ctx, arg);
5713 * Parse an IPv4 address.
5715 * Last argument (ctx->args) is retrieved to determine storage size and
5719 parse_ipv4_addr(struct context *ctx, const struct token *token,
5720 const char *str, unsigned int len,
5721 void *buf, unsigned int size)
5723 const struct arg *arg = pop_args(ctx);
5728 /* Argument is expected. */
5732 /* Bit-mask fill is not supported. */
5733 if (arg->mask || size != sizeof(tmp))
5735 /* Only network endian is supported. */
5738 memcpy(str2, str, len);
5740 ret = inet_pton(AF_INET, str2, &tmp);
5742 /* Attempt integer parsing. */
5743 push_args(ctx, arg);
5744 return parse_int(ctx, token, str, len, buf, size);
5748 buf = (uint8_t *)ctx->object + arg->offset;
5749 memcpy(buf, &tmp, size);
5751 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
5754 push_args(ctx, arg);
5759 * Parse an IPv6 address.
5761 * Last argument (ctx->args) is retrieved to determine storage size and
5765 parse_ipv6_addr(struct context *ctx, const struct token *token,
5766 const char *str, unsigned int len,
5767 void *buf, unsigned int size)
5769 const struct arg *arg = pop_args(ctx);
5771 struct in6_addr tmp;
5775 /* Argument is expected. */
5779 /* Bit-mask fill is not supported. */
5780 if (arg->mask || size != sizeof(tmp))
5782 /* Only network endian is supported. */
5785 memcpy(str2, str, len);
5787 ret = inet_pton(AF_INET6, str2, &tmp);
5792 buf = (uint8_t *)ctx->object + arg->offset;
5793 memcpy(buf, &tmp, size);
5795 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
5798 push_args(ctx, arg);
5802 /** Boolean values (even indices stand for false). */
5803 static const char *const boolean_name[] = {
5813 * Parse a boolean value.
5815 * Last argument (ctx->args) is retrieved to determine storage size and
5819 parse_boolean(struct context *ctx, const struct token *token,
5820 const char *str, unsigned int len,
5821 void *buf, unsigned int size)
5823 const struct arg *arg = pop_args(ctx);
5827 /* Argument is expected. */
5830 for (i = 0; boolean_name[i]; ++i)
5831 if (!strcmp_partial(boolean_name[i], str, len))
5833 /* Process token as integer. */
5834 if (boolean_name[i])
5835 str = i & 1 ? "1" : "0";
5836 push_args(ctx, arg);
5837 ret = parse_int(ctx, token, str, strlen(str), buf, size);
5838 return ret > 0 ? (int)len : ret;
5841 /** Parse port and update context. */
5843 parse_port(struct context *ctx, const struct token *token,
5844 const char *str, unsigned int len,
5845 void *buf, unsigned int size)
5847 struct buffer *out = &(struct buffer){ .port = 0 };
5855 ctx->objmask = NULL;
5856 size = sizeof(*out);
5858 ret = parse_int(ctx, token, str, len, out, size);
5860 ctx->port = out->port;
5866 /** Parse set command, initialize output buffer for subsequent tokens. */
5868 parse_set_raw_encap_decap(struct context *ctx, const struct token *token,
5869 const char *str, unsigned int len,
5870 void *buf, unsigned int size)
5872 struct buffer *out = buf;
5874 /* Token name must match. */
5875 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5877 /* Nothing else to do if there is no buffer. */
5880 /* Make sure buffer is large enough. */
5881 if (size < sizeof(*out))
5884 ctx->objmask = NULL;
5888 out->command = ctx->curr;
5893 * Parse set raw_encap/raw_decap command,
5894 * initialize output buffer for subsequent tokens.
5897 parse_set_init(struct context *ctx, const struct token *token,
5898 const char *str, unsigned int len,
5899 void *buf, unsigned int size)
5901 struct buffer *out = buf;
5903 /* Token name must match. */
5904 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5906 /* Nothing else to do if there is no buffer. */
5909 /* Make sure buffer is large enough. */
5910 if (size < sizeof(*out))
5912 /* Initialize buffer. */
5913 memset(out, 0x00, sizeof(*out));
5914 memset((uint8_t *)out + sizeof(*out), 0x22, size - sizeof(*out));
5917 ctx->objmask = NULL;
5918 if (!out->command) {
5919 if (ctx->curr != SET)
5921 if (sizeof(*out) > size)
5923 out->command = ctx->curr;
5924 out->args.vc.data = (uint8_t *)out + size;
5925 /* All we need is pattern */
5926 out->args.vc.pattern =
5927 (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
5929 ctx->object = out->args.vc.pattern;
5934 /** No completion. */
5936 comp_none(struct context *ctx, const struct token *token,
5937 unsigned int ent, char *buf, unsigned int size)
5947 /** Complete boolean values. */
5949 comp_boolean(struct context *ctx, const struct token *token,
5950 unsigned int ent, char *buf, unsigned int size)
5956 for (i = 0; boolean_name[i]; ++i)
5957 if (buf && i == ent)
5958 return strlcpy(buf, boolean_name[i], size);
5964 /** Complete action names. */
5966 comp_action(struct context *ctx, const struct token *token,
5967 unsigned int ent, char *buf, unsigned int size)
5973 for (i = 0; next_action[i]; ++i)
5974 if (buf && i == ent)
5975 return strlcpy(buf, token_list[next_action[i]].name,
5982 /** Complete available ports. */
5984 comp_port(struct context *ctx, const struct token *token,
5985 unsigned int ent, char *buf, unsigned int size)
5992 RTE_ETH_FOREACH_DEV(p) {
5993 if (buf && i == ent)
5994 return snprintf(buf, size, "%u", p);
6002 /** Complete available rule IDs. */
6004 comp_rule_id(struct context *ctx, const struct token *token,
6005 unsigned int ent, char *buf, unsigned int size)
6008 struct rte_port *port;
6009 struct port_flow *pf;
6012 if (port_id_is_invalid(ctx->port, DISABLED_WARN) ||
6013 ctx->port == (portid_t)RTE_PORT_ALL)
6015 port = &ports[ctx->port];
6016 for (pf = port->flow_list; pf != NULL; pf = pf->next) {
6017 if (buf && i == ent)
6018 return snprintf(buf, size, "%u", pf->id);
6026 /** Complete type field for RSS action. */
6028 comp_vc_action_rss_type(struct context *ctx, const struct token *token,
6029 unsigned int ent, char *buf, unsigned int size)
6035 for (i = 0; rss_type_table[i].str; ++i)
6040 return strlcpy(buf, rss_type_table[ent].str, size);
6042 return snprintf(buf, size, "end");
6046 /** Complete queue field for RSS action. */
6048 comp_vc_action_rss_queue(struct context *ctx, const struct token *token,
6049 unsigned int ent, char *buf, unsigned int size)
6056 return snprintf(buf, size, "%u", ent);
6058 return snprintf(buf, size, "end");
6062 /** Complete index number for set raw_encap/raw_decap commands. */
6064 comp_set_raw_index(struct context *ctx, const struct token *token,
6065 unsigned int ent, char *buf, unsigned int size)
6071 RTE_SET_USED(token);
6072 for (idx = 0; idx < RAW_ENCAP_CONFS_MAX_NUM; ++idx) {
6073 if (buf && idx == ent)
6074 return snprintf(buf, size, "%u", idx);
6080 /** Internal context. */
6081 static struct context cmd_flow_context;
6083 /** Global parser instance (cmdline API). */
6084 cmdline_parse_inst_t cmd_flow;
6085 cmdline_parse_inst_t cmd_set_raw;
6087 /** Initialize context. */
6089 cmd_flow_context_init(struct context *ctx)
6091 /* A full memset() is not necessary. */
6101 ctx->objmask = NULL;
6104 /** Parse a token (cmdline API). */
6106 cmd_flow_parse(cmdline_parse_token_hdr_t *hdr, const char *src, void *result,
6109 struct context *ctx = &cmd_flow_context;
6110 const struct token *token;
6111 const enum index *list;
6116 token = &token_list[ctx->curr];
6117 /* Check argument length. */
6120 for (len = 0; src[len]; ++len)
6121 if (src[len] == '#' || isspace(src[len]))
6125 /* Last argument and EOL detection. */
6126 for (i = len; src[i]; ++i)
6127 if (src[i] == '#' || src[i] == '\r' || src[i] == '\n')
6129 else if (!isspace(src[i])) {
6134 if (src[i] == '\r' || src[i] == '\n') {
6138 /* Initialize context if necessary. */
6139 if (!ctx->next_num) {
6142 ctx->next[ctx->next_num++] = token->next[0];
6144 /* Process argument through candidates. */
6145 ctx->prev = ctx->curr;
6146 list = ctx->next[ctx->next_num - 1];
6147 for (i = 0; list[i]; ++i) {
6148 const struct token *next = &token_list[list[i]];
6151 ctx->curr = list[i];
6153 tmp = next->call(ctx, next, src, len, result, size);
6155 tmp = parse_default(ctx, next, src, len, result, size);
6156 if (tmp == -1 || tmp != len)
6164 /* Push subsequent tokens if any. */
6166 for (i = 0; token->next[i]; ++i) {
6167 if (ctx->next_num == RTE_DIM(ctx->next))
6169 ctx->next[ctx->next_num++] = token->next[i];
6171 /* Push arguments if any. */
6173 for (i = 0; token->args[i]; ++i) {
6174 if (ctx->args_num == RTE_DIM(ctx->args))
6176 ctx->args[ctx->args_num++] = token->args[i];
6181 /** Return number of completion entries (cmdline API). */
6183 cmd_flow_complete_get_nb(cmdline_parse_token_hdr_t *hdr)
6185 struct context *ctx = &cmd_flow_context;
6186 const struct token *token = &token_list[ctx->curr];
6187 const enum index *list;
6191 /* Count number of tokens in current list. */
6193 list = ctx->next[ctx->next_num - 1];
6195 list = token->next[0];
6196 for (i = 0; list[i]; ++i)
6201 * If there is a single token, use its completion callback, otherwise
6202 * return the number of entries.
6204 token = &token_list[list[0]];
6205 if (i == 1 && token->comp) {
6206 /* Save index for cmd_flow_get_help(). */
6207 ctx->prev = list[0];
6208 return token->comp(ctx, token, 0, NULL, 0);
6213 /** Return a completion entry (cmdline API). */
6215 cmd_flow_complete_get_elt(cmdline_parse_token_hdr_t *hdr, int index,
6216 char *dst, unsigned int size)
6218 struct context *ctx = &cmd_flow_context;
6219 const struct token *token = &token_list[ctx->curr];
6220 const enum index *list;
6224 /* Count number of tokens in current list. */
6226 list = ctx->next[ctx->next_num - 1];
6228 list = token->next[0];
6229 for (i = 0; list[i]; ++i)
6233 /* If there is a single token, use its completion callback. */
6234 token = &token_list[list[0]];
6235 if (i == 1 && token->comp) {
6236 /* Save index for cmd_flow_get_help(). */
6237 ctx->prev = list[0];
6238 return token->comp(ctx, token, index, dst, size) < 0 ? -1 : 0;
6240 /* Otherwise make sure the index is valid and use defaults. */
6243 token = &token_list[list[index]];
6244 strlcpy(dst, token->name, size);
6245 /* Save index for cmd_flow_get_help(). */
6246 ctx->prev = list[index];
6250 /** Populate help strings for current token (cmdline API). */
6252 cmd_flow_get_help(cmdline_parse_token_hdr_t *hdr, char *dst, unsigned int size)
6254 struct context *ctx = &cmd_flow_context;
6255 const struct token *token = &token_list[ctx->prev];
6260 /* Set token type and update global help with details. */
6261 strlcpy(dst, (token->type ? token->type : "TOKEN"), size);
6263 cmd_flow.help_str = token->help;
6265 cmd_flow.help_str = token->name;
6269 /** Token definition template (cmdline API). */
6270 static struct cmdline_token_hdr cmd_flow_token_hdr = {
6271 .ops = &(struct cmdline_token_ops){
6272 .parse = cmd_flow_parse,
6273 .complete_get_nb = cmd_flow_complete_get_nb,
6274 .complete_get_elt = cmd_flow_complete_get_elt,
6275 .get_help = cmd_flow_get_help,
6280 /** Populate the next dynamic token. */
6282 cmd_flow_tok(cmdline_parse_token_hdr_t **hdr,
6283 cmdline_parse_token_hdr_t **hdr_inst)
6285 struct context *ctx = &cmd_flow_context;
6287 /* Always reinitialize context before requesting the first token. */
6288 if (!(hdr_inst - cmd_flow.tokens))
6289 cmd_flow_context_init(ctx);
6290 /* Return NULL when no more tokens are expected. */
6291 if (!ctx->next_num && ctx->curr) {
6295 /* Determine if command should end here. */
6296 if (ctx->eol && ctx->last && ctx->next_num) {
6297 const enum index *list = ctx->next[ctx->next_num - 1];
6300 for (i = 0; list[i]; ++i) {
6307 *hdr = &cmd_flow_token_hdr;
6310 /** Dispatch parsed buffer to function calls. */
6312 cmd_flow_parsed(const struct buffer *in)
6314 switch (in->command) {
6316 port_flow_validate(in->port, &in->args.vc.attr,
6317 in->args.vc.pattern, in->args.vc.actions);
6320 port_flow_create(in->port, &in->args.vc.attr,
6321 in->args.vc.pattern, in->args.vc.actions);
6324 port_flow_destroy(in->port, in->args.destroy.rule_n,
6325 in->args.destroy.rule);
6328 port_flow_flush(in->port);
6331 port_flow_dump(in->port, in->args.dump.file);
6334 port_flow_query(in->port, in->args.query.rule,
6335 &in->args.query.action);
6338 port_flow_list(in->port, in->args.list.group_n,
6339 in->args.list.group);
6342 port_flow_isolate(in->port, in->args.isolate.set);
6349 /** Token generator and output processing callback (cmdline API). */
6351 cmd_flow_cb(void *arg0, struct cmdline *cl, void *arg2)
6354 cmd_flow_tok(arg0, arg2);
6356 cmd_flow_parsed(arg0);
6359 /** Global parser instance (cmdline API). */
6360 cmdline_parse_inst_t cmd_flow = {
6362 .data = NULL, /**< Unused. */
6363 .help_str = NULL, /**< Updated by cmd_flow_get_help(). */
6366 }, /**< Tokens are returned by cmd_flow_tok(). */
6369 /** set cmd facility. Reuse cmd flow's infrastructure as much as possible. */
6372 update_fields(uint8_t *buf, struct rte_flow_item *item, uint16_t next_proto)
6374 struct rte_flow_item_ipv4 *ipv4;
6375 struct rte_flow_item_eth *eth;
6376 struct rte_flow_item_ipv6 *ipv6;
6377 struct rte_flow_item_vxlan *vxlan;
6378 struct rte_flow_item_vxlan_gpe *gpe;
6379 struct rte_flow_item_nvgre *nvgre;
6380 uint32_t ipv6_vtc_flow;
6382 switch (item->type) {
6383 case RTE_FLOW_ITEM_TYPE_ETH:
6384 eth = (struct rte_flow_item_eth *)buf;
6386 eth->type = rte_cpu_to_be_16(next_proto);
6388 case RTE_FLOW_ITEM_TYPE_IPV4:
6389 ipv4 = (struct rte_flow_item_ipv4 *)buf;
6390 ipv4->hdr.version_ihl = 0x45;
6391 if (next_proto && ipv4->hdr.next_proto_id == 0)
6392 ipv4->hdr.next_proto_id = (uint8_t)next_proto;
6394 case RTE_FLOW_ITEM_TYPE_IPV6:
6395 ipv6 = (struct rte_flow_item_ipv6 *)buf;
6396 if (next_proto && ipv6->hdr.proto == 0)
6397 ipv6->hdr.proto = (uint8_t)next_proto;
6398 ipv6_vtc_flow = rte_be_to_cpu_32(ipv6->hdr.vtc_flow);
6399 ipv6_vtc_flow &= 0x0FFFFFFF; /*< reset version bits. */
6400 ipv6_vtc_flow |= 0x60000000; /*< set ipv6 version. */
6401 ipv6->hdr.vtc_flow = rte_cpu_to_be_32(ipv6_vtc_flow);
6403 case RTE_FLOW_ITEM_TYPE_VXLAN:
6404 vxlan = (struct rte_flow_item_vxlan *)buf;
6405 vxlan->flags = 0x08;
6407 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
6408 gpe = (struct rte_flow_item_vxlan_gpe *)buf;
6411 case RTE_FLOW_ITEM_TYPE_NVGRE:
6412 nvgre = (struct rte_flow_item_nvgre *)buf;
6413 nvgre->protocol = rte_cpu_to_be_16(0x6558);
6414 nvgre->c_k_s_rsvd0_ver = rte_cpu_to_be_16(0x2000);
6421 /** Helper of get item's default mask. */
6423 flow_item_default_mask(const struct rte_flow_item *item)
6425 const void *mask = NULL;
6426 static rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
6428 switch (item->type) {
6429 case RTE_FLOW_ITEM_TYPE_ANY:
6430 mask = &rte_flow_item_any_mask;
6432 case RTE_FLOW_ITEM_TYPE_VF:
6433 mask = &rte_flow_item_vf_mask;
6435 case RTE_FLOW_ITEM_TYPE_PORT_ID:
6436 mask = &rte_flow_item_port_id_mask;
6438 case RTE_FLOW_ITEM_TYPE_RAW:
6439 mask = &rte_flow_item_raw_mask;
6441 case RTE_FLOW_ITEM_TYPE_ETH:
6442 mask = &rte_flow_item_eth_mask;
6444 case RTE_FLOW_ITEM_TYPE_VLAN:
6445 mask = &rte_flow_item_vlan_mask;
6447 case RTE_FLOW_ITEM_TYPE_IPV4:
6448 mask = &rte_flow_item_ipv4_mask;
6450 case RTE_FLOW_ITEM_TYPE_IPV6:
6451 mask = &rte_flow_item_ipv6_mask;
6453 case RTE_FLOW_ITEM_TYPE_ICMP:
6454 mask = &rte_flow_item_icmp_mask;
6456 case RTE_FLOW_ITEM_TYPE_UDP:
6457 mask = &rte_flow_item_udp_mask;
6459 case RTE_FLOW_ITEM_TYPE_TCP:
6460 mask = &rte_flow_item_tcp_mask;
6462 case RTE_FLOW_ITEM_TYPE_SCTP:
6463 mask = &rte_flow_item_sctp_mask;
6465 case RTE_FLOW_ITEM_TYPE_VXLAN:
6466 mask = &rte_flow_item_vxlan_mask;
6468 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
6469 mask = &rte_flow_item_vxlan_gpe_mask;
6471 case RTE_FLOW_ITEM_TYPE_E_TAG:
6472 mask = &rte_flow_item_e_tag_mask;
6474 case RTE_FLOW_ITEM_TYPE_NVGRE:
6475 mask = &rte_flow_item_nvgre_mask;
6477 case RTE_FLOW_ITEM_TYPE_MPLS:
6478 mask = &rte_flow_item_mpls_mask;
6480 case RTE_FLOW_ITEM_TYPE_GRE:
6481 mask = &rte_flow_item_gre_mask;
6483 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
6484 mask = &gre_key_default_mask;
6486 case RTE_FLOW_ITEM_TYPE_META:
6487 mask = &rte_flow_item_meta_mask;
6489 case RTE_FLOW_ITEM_TYPE_FUZZY:
6490 mask = &rte_flow_item_fuzzy_mask;
6492 case RTE_FLOW_ITEM_TYPE_GTP:
6493 mask = &rte_flow_item_gtp_mask;
6495 case RTE_FLOW_ITEM_TYPE_GTP_PSC:
6496 mask = &rte_flow_item_gtp_psc_mask;
6498 case RTE_FLOW_ITEM_TYPE_GENEVE:
6499 mask = &rte_flow_item_geneve_mask;
6501 case RTE_FLOW_ITEM_TYPE_PPPOE_PROTO_ID:
6502 mask = &rte_flow_item_pppoe_proto_id_mask;
6504 case RTE_FLOW_ITEM_TYPE_L2TPV3OIP:
6505 mask = &rte_flow_item_l2tpv3oip_mask;
6507 case RTE_FLOW_ITEM_TYPE_ESP:
6508 mask = &rte_flow_item_esp_mask;
6510 case RTE_FLOW_ITEM_TYPE_AH:
6511 mask = &rte_flow_item_ah_mask;
6513 case RTE_FLOW_ITEM_TYPE_PFCP:
6514 mask = &rte_flow_item_pfcp_mask;
6524 /** Dispatch parsed buffer to function calls. */
6526 cmd_set_raw_parsed(const struct buffer *in)
6528 uint32_t n = in->args.vc.pattern_n;
6530 struct rte_flow_item *item = NULL;
6532 uint8_t *data = NULL;
6533 uint8_t *data_tail = NULL;
6534 size_t *total_size = NULL;
6535 uint16_t upper_layer = 0;
6537 uint16_t idx = in->port; /* We borrow port field as index */
6539 RTE_ASSERT(in->command == SET_RAW_ENCAP ||
6540 in->command == SET_RAW_DECAP);
6541 if (in->command == SET_RAW_ENCAP) {
6542 total_size = &raw_encap_confs[idx].size;
6543 data = (uint8_t *)&raw_encap_confs[idx].data;
6545 total_size = &raw_decap_confs[idx].size;
6546 data = (uint8_t *)&raw_decap_confs[idx].data;
6549 memset(data, 0x00, ACTION_RAW_ENCAP_MAX_DATA);
6550 /* process hdr from upper layer to low layer (L3/L4 -> L2). */
6551 data_tail = data + ACTION_RAW_ENCAP_MAX_DATA;
6552 for (i = n - 1 ; i >= 0; --i) {
6553 item = in->args.vc.pattern + i;
6554 if (item->spec == NULL)
6555 item->spec = flow_item_default_mask(item);
6556 switch (item->type) {
6557 case RTE_FLOW_ITEM_TYPE_ETH:
6558 size = sizeof(struct rte_flow_item_eth);
6560 case RTE_FLOW_ITEM_TYPE_VLAN:
6561 size = sizeof(struct rte_flow_item_vlan);
6562 proto = RTE_ETHER_TYPE_VLAN;
6564 case RTE_FLOW_ITEM_TYPE_IPV4:
6565 size = sizeof(struct rte_flow_item_ipv4);
6566 proto = RTE_ETHER_TYPE_IPV4;
6568 case RTE_FLOW_ITEM_TYPE_IPV6:
6569 size = sizeof(struct rte_flow_item_ipv6);
6570 proto = RTE_ETHER_TYPE_IPV6;
6572 case RTE_FLOW_ITEM_TYPE_UDP:
6573 size = sizeof(struct rte_flow_item_udp);
6576 case RTE_FLOW_ITEM_TYPE_TCP:
6577 size = sizeof(struct rte_flow_item_tcp);
6580 case RTE_FLOW_ITEM_TYPE_VXLAN:
6581 size = sizeof(struct rte_flow_item_vxlan);
6583 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
6584 size = sizeof(struct rte_flow_item_vxlan_gpe);
6586 case RTE_FLOW_ITEM_TYPE_GRE:
6587 size = sizeof(struct rte_flow_item_gre);
6590 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
6591 size = sizeof(rte_be32_t);
6594 case RTE_FLOW_ITEM_TYPE_MPLS:
6595 size = sizeof(struct rte_flow_item_mpls);
6598 case RTE_FLOW_ITEM_TYPE_NVGRE:
6599 size = sizeof(struct rte_flow_item_nvgre);
6602 case RTE_FLOW_ITEM_TYPE_GENEVE:
6603 size = sizeof(struct rte_flow_item_geneve);
6605 case RTE_FLOW_ITEM_TYPE_L2TPV3OIP:
6606 size = sizeof(struct rte_flow_item_l2tpv3oip);
6609 case RTE_FLOW_ITEM_TYPE_ESP:
6610 size = sizeof(struct rte_flow_item_esp);
6613 case RTE_FLOW_ITEM_TYPE_AH:
6614 size = sizeof(struct rte_flow_item_ah);
6617 case RTE_FLOW_ITEM_TYPE_GTP:
6618 size = sizeof(struct rte_flow_item_gtp);
6620 case RTE_FLOW_ITEM_TYPE_PFCP:
6621 size = sizeof(struct rte_flow_item_pfcp);
6624 printf("Error - Not supported item\n");
6626 memset(data, 0x00, ACTION_RAW_ENCAP_MAX_DATA);
6629 *total_size += size;
6630 rte_memcpy(data_tail - (*total_size), item->spec, size);
6631 /* update some fields which cannot be set by cmdline */
6632 update_fields((data_tail - (*total_size)), item,
6634 upper_layer = proto;
6636 if (verbose_level & 0x1)
6637 printf("total data size is %zu\n", (*total_size));
6638 RTE_ASSERT((*total_size) <= ACTION_RAW_ENCAP_MAX_DATA);
6639 memmove(data, (data_tail - (*total_size)), *total_size);
6642 /** Populate help strings for current token (cmdline API). */
6644 cmd_set_raw_get_help(cmdline_parse_token_hdr_t *hdr, char *dst,
6647 struct context *ctx = &cmd_flow_context;
6648 const struct token *token = &token_list[ctx->prev];
6653 /* Set token type and update global help with details. */
6654 snprintf(dst, size, "%s", (token->type ? token->type : "TOKEN"));
6656 cmd_set_raw.help_str = token->help;
6658 cmd_set_raw.help_str = token->name;
6662 /** Token definition template (cmdline API). */
6663 static struct cmdline_token_hdr cmd_set_raw_token_hdr = {
6664 .ops = &(struct cmdline_token_ops){
6665 .parse = cmd_flow_parse,
6666 .complete_get_nb = cmd_flow_complete_get_nb,
6667 .complete_get_elt = cmd_flow_complete_get_elt,
6668 .get_help = cmd_set_raw_get_help,
6673 /** Populate the next dynamic token. */
6675 cmd_set_raw_tok(cmdline_parse_token_hdr_t **hdr,
6676 cmdline_parse_token_hdr_t **hdr_inst)
6678 struct context *ctx = &cmd_flow_context;
6680 /* Always reinitialize context before requesting the first token. */
6681 if (!(hdr_inst - cmd_set_raw.tokens)) {
6682 cmd_flow_context_init(ctx);
6683 ctx->curr = START_SET;
6685 /* Return NULL when no more tokens are expected. */
6686 if (!ctx->next_num && (ctx->curr != START_SET)) {
6690 /* Determine if command should end here. */
6691 if (ctx->eol && ctx->last && ctx->next_num) {
6692 const enum index *list = ctx->next[ctx->next_num - 1];
6695 for (i = 0; list[i]; ++i) {
6702 *hdr = &cmd_set_raw_token_hdr;
6705 /** Token generator and output processing callback (cmdline API). */
6707 cmd_set_raw_cb(void *arg0, struct cmdline *cl, void *arg2)
6710 cmd_set_raw_tok(arg0, arg2);
6712 cmd_set_raw_parsed(arg0);
6715 /** Global parser instance (cmdline API). */
6716 cmdline_parse_inst_t cmd_set_raw = {
6717 .f = cmd_set_raw_cb,
6718 .data = NULL, /**< Unused. */
6719 .help_str = NULL, /**< Updated by cmd_flow_get_help(). */
6722 }, /**< Tokens are returned by cmd_flow_tok(). */
6725 /* *** display raw_encap/raw_decap buf */
6726 struct cmd_show_set_raw_result {
6727 cmdline_fixed_string_t cmd_show;
6728 cmdline_fixed_string_t cmd_what;
6729 cmdline_fixed_string_t cmd_all;
6734 cmd_show_set_raw_parsed(void *parsed_result, struct cmdline *cl, void *data)
6736 struct cmd_show_set_raw_result *res = parsed_result;
6737 uint16_t index = res->cmd_index;
6739 uint8_t *raw_data = NULL;
6740 size_t raw_size = 0;
6741 char title[16] = {0};
6745 if (!strcmp(res->cmd_all, "all")) {
6748 } else if (index >= RAW_ENCAP_CONFS_MAX_NUM) {
6749 printf("index should be 0-%u\n", RAW_ENCAP_CONFS_MAX_NUM - 1);
6753 if (!strcmp(res->cmd_what, "raw_encap")) {
6754 raw_data = (uint8_t *)&raw_encap_confs[index].data;
6755 raw_size = raw_encap_confs[index].size;
6756 snprintf(title, 16, "\nindex: %u", index);
6757 rte_hexdump(stdout, title, raw_data, raw_size);
6759 raw_data = (uint8_t *)&raw_decap_confs[index].data;
6760 raw_size = raw_decap_confs[index].size;
6761 snprintf(title, 16, "\nindex: %u", index);
6762 rte_hexdump(stdout, title, raw_data, raw_size);
6764 } while (all && ++index < RAW_ENCAP_CONFS_MAX_NUM);
6767 cmdline_parse_token_string_t cmd_show_set_raw_cmd_show =
6768 TOKEN_STRING_INITIALIZER(struct cmd_show_set_raw_result,
6770 cmdline_parse_token_string_t cmd_show_set_raw_cmd_what =
6771 TOKEN_STRING_INITIALIZER(struct cmd_show_set_raw_result,
6772 cmd_what, "raw_encap#raw_decap");
6773 cmdline_parse_token_num_t cmd_show_set_raw_cmd_index =
6774 TOKEN_NUM_INITIALIZER(struct cmd_show_set_raw_result,
6776 cmdline_parse_token_string_t cmd_show_set_raw_cmd_all =
6777 TOKEN_STRING_INITIALIZER(struct cmd_show_set_raw_result,
6779 cmdline_parse_inst_t cmd_show_set_raw = {
6780 .f = cmd_show_set_raw_parsed,
6782 .help_str = "show <raw_encap|raw_decap> <index>",
6784 (void *)&cmd_show_set_raw_cmd_show,
6785 (void *)&cmd_show_set_raw_cmd_what,
6786 (void *)&cmd_show_set_raw_cmd_index,
6790 cmdline_parse_inst_t cmd_show_set_raw_all = {
6791 .f = cmd_show_set_raw_parsed,
6793 .help_str = "show <raw_encap|raw_decap> all",
6795 (void *)&cmd_show_set_raw_cmd_show,
6796 (void *)&cmd_show_set_raw_cmd_what,
6797 (void *)&cmd_show_set_raw_cmd_all,