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[] = {
1040 ITEM_PPPOE_PROTO_ID,
1045 static const enum index item_higig2[] = {
1046 ITEM_HIGIG2_CLASSIFICATION,
1052 static const enum index item_esp[] = {
1058 static const enum index item_ah[] = {
1064 static const enum index item_pfcp[] = {
1071 static const enum index next_set_raw[] = {
1077 static const enum index item_tag[] = {
1084 static const enum index item_l2tpv3oip[] = {
1085 ITEM_L2TPV3OIP_SESSION_ID,
1090 static const enum index next_action[] = {
1106 ACTION_OF_SET_MPLS_TTL,
1107 ACTION_OF_DEC_MPLS_TTL,
1108 ACTION_OF_SET_NW_TTL,
1109 ACTION_OF_DEC_NW_TTL,
1110 ACTION_OF_COPY_TTL_OUT,
1111 ACTION_OF_COPY_TTL_IN,
1113 ACTION_OF_PUSH_VLAN,
1114 ACTION_OF_SET_VLAN_VID,
1115 ACTION_OF_SET_VLAN_PCP,
1117 ACTION_OF_PUSH_MPLS,
1124 ACTION_MPLSOGRE_ENCAP,
1125 ACTION_MPLSOGRE_DECAP,
1126 ACTION_MPLSOUDP_ENCAP,
1127 ACTION_MPLSOUDP_DECAP,
1128 ACTION_SET_IPV4_SRC,
1129 ACTION_SET_IPV4_DST,
1130 ACTION_SET_IPV6_SRC,
1131 ACTION_SET_IPV6_DST,
1147 ACTION_SET_IPV4_DSCP,
1148 ACTION_SET_IPV6_DSCP,
1152 static const enum index action_mark[] = {
1158 static const enum index action_queue[] = {
1164 static const enum index action_count[] = {
1166 ACTION_COUNT_SHARED,
1171 static const enum index action_rss[] = {
1182 static const enum index action_vf[] = {
1189 static const enum index action_phy_port[] = {
1190 ACTION_PHY_PORT_ORIGINAL,
1191 ACTION_PHY_PORT_INDEX,
1196 static const enum index action_port_id[] = {
1197 ACTION_PORT_ID_ORIGINAL,
1203 static const enum index action_meter[] = {
1209 static const enum index action_of_set_mpls_ttl[] = {
1210 ACTION_OF_SET_MPLS_TTL_MPLS_TTL,
1215 static const enum index action_of_set_nw_ttl[] = {
1216 ACTION_OF_SET_NW_TTL_NW_TTL,
1221 static const enum index action_of_push_vlan[] = {
1222 ACTION_OF_PUSH_VLAN_ETHERTYPE,
1227 static const enum index action_of_set_vlan_vid[] = {
1228 ACTION_OF_SET_VLAN_VID_VLAN_VID,
1233 static const enum index action_of_set_vlan_pcp[] = {
1234 ACTION_OF_SET_VLAN_PCP_VLAN_PCP,
1239 static const enum index action_of_pop_mpls[] = {
1240 ACTION_OF_POP_MPLS_ETHERTYPE,
1245 static const enum index action_of_push_mpls[] = {
1246 ACTION_OF_PUSH_MPLS_ETHERTYPE,
1251 static const enum index action_set_ipv4_src[] = {
1252 ACTION_SET_IPV4_SRC_IPV4_SRC,
1257 static const enum index action_set_mac_src[] = {
1258 ACTION_SET_MAC_SRC_MAC_SRC,
1263 static const enum index action_set_ipv4_dst[] = {
1264 ACTION_SET_IPV4_DST_IPV4_DST,
1269 static const enum index action_set_ipv6_src[] = {
1270 ACTION_SET_IPV6_SRC_IPV6_SRC,
1275 static const enum index action_set_ipv6_dst[] = {
1276 ACTION_SET_IPV6_DST_IPV6_DST,
1281 static const enum index action_set_tp_src[] = {
1282 ACTION_SET_TP_SRC_TP_SRC,
1287 static const enum index action_set_tp_dst[] = {
1288 ACTION_SET_TP_DST_TP_DST,
1293 static const enum index action_set_ttl[] = {
1299 static const enum index action_jump[] = {
1305 static const enum index action_set_mac_dst[] = {
1306 ACTION_SET_MAC_DST_MAC_DST,
1311 static const enum index action_inc_tcp_seq[] = {
1312 ACTION_INC_TCP_SEQ_VALUE,
1317 static const enum index action_dec_tcp_seq[] = {
1318 ACTION_DEC_TCP_SEQ_VALUE,
1323 static const enum index action_inc_tcp_ack[] = {
1324 ACTION_INC_TCP_ACK_VALUE,
1329 static const enum index action_dec_tcp_ack[] = {
1330 ACTION_DEC_TCP_ACK_VALUE,
1335 static const enum index action_raw_encap[] = {
1336 ACTION_RAW_ENCAP_INDEX,
1341 static const enum index action_raw_decap[] = {
1342 ACTION_RAW_DECAP_INDEX,
1347 static const enum index action_set_tag[] = {
1348 ACTION_SET_TAG_DATA,
1349 ACTION_SET_TAG_INDEX,
1350 ACTION_SET_TAG_MASK,
1355 static const enum index action_set_meta[] = {
1356 ACTION_SET_META_DATA,
1357 ACTION_SET_META_MASK,
1362 static const enum index action_set_ipv4_dscp[] = {
1363 ACTION_SET_IPV4_DSCP_VALUE,
1368 static const enum index action_set_ipv6_dscp[] = {
1369 ACTION_SET_IPV6_DSCP_VALUE,
1374 static int parse_set_raw_encap_decap(struct context *, const struct token *,
1375 const char *, unsigned int,
1376 void *, unsigned int);
1377 static int parse_set_init(struct context *, const struct token *,
1378 const char *, unsigned int,
1379 void *, unsigned int);
1380 static int parse_init(struct context *, const struct token *,
1381 const char *, unsigned int,
1382 void *, unsigned int);
1383 static int parse_vc(struct context *, const struct token *,
1384 const char *, unsigned int,
1385 void *, unsigned int);
1386 static int parse_vc_spec(struct context *, const struct token *,
1387 const char *, unsigned int, void *, unsigned int);
1388 static int parse_vc_conf(struct context *, const struct token *,
1389 const char *, unsigned int, void *, unsigned int);
1390 static int parse_vc_action_rss(struct context *, const struct token *,
1391 const char *, unsigned int, void *,
1393 static int parse_vc_action_rss_func(struct context *, const struct token *,
1394 const char *, unsigned int, void *,
1396 static int parse_vc_action_rss_type(struct context *, const struct token *,
1397 const char *, unsigned int, void *,
1399 static int parse_vc_action_rss_queue(struct context *, const struct token *,
1400 const char *, unsigned int, void *,
1402 static int parse_vc_action_vxlan_encap(struct context *, const struct token *,
1403 const char *, unsigned int, void *,
1405 static int parse_vc_action_nvgre_encap(struct context *, const struct token *,
1406 const char *, unsigned int, void *,
1408 static int parse_vc_action_l2_encap(struct context *, const struct token *,
1409 const char *, unsigned int, void *,
1411 static int parse_vc_action_l2_decap(struct context *, const struct token *,
1412 const char *, unsigned int, void *,
1414 static int parse_vc_action_mplsogre_encap(struct context *,
1415 const struct token *, const char *,
1416 unsigned int, void *, unsigned int);
1417 static int parse_vc_action_mplsogre_decap(struct context *,
1418 const struct token *, const char *,
1419 unsigned int, void *, unsigned int);
1420 static int parse_vc_action_mplsoudp_encap(struct context *,
1421 const struct token *, const char *,
1422 unsigned int, void *, unsigned int);
1423 static int parse_vc_action_mplsoudp_decap(struct context *,
1424 const struct token *, const char *,
1425 unsigned int, void *, unsigned int);
1426 static int parse_vc_action_raw_encap(struct context *,
1427 const struct token *, const char *,
1428 unsigned int, void *, unsigned int);
1429 static int parse_vc_action_raw_decap(struct context *,
1430 const struct token *, const char *,
1431 unsigned int, void *, unsigned int);
1432 static int parse_vc_action_raw_encap_index(struct context *,
1433 const struct token *, const char *,
1434 unsigned int, void *, unsigned int);
1435 static int parse_vc_action_raw_decap_index(struct context *,
1436 const struct token *, const char *,
1437 unsigned int, void *, unsigned int);
1438 static int parse_vc_action_set_meta(struct context *ctx,
1439 const struct token *token, const char *str,
1440 unsigned int len, void *buf,
1442 static int parse_destroy(struct context *, const struct token *,
1443 const char *, unsigned int,
1444 void *, unsigned int);
1445 static int parse_flush(struct context *, const struct token *,
1446 const char *, unsigned int,
1447 void *, unsigned int);
1448 static int parse_dump(struct context *, const struct token *,
1449 const char *, unsigned int,
1450 void *, unsigned int);
1451 static int parse_query(struct context *, const struct token *,
1452 const char *, unsigned int,
1453 void *, unsigned int);
1454 static int parse_action(struct context *, const struct token *,
1455 const char *, unsigned int,
1456 void *, unsigned int);
1457 static int parse_list(struct context *, const struct token *,
1458 const char *, unsigned int,
1459 void *, unsigned int);
1460 static int parse_isolate(struct context *, const struct token *,
1461 const char *, unsigned int,
1462 void *, unsigned int);
1463 static int parse_int(struct context *, const struct token *,
1464 const char *, unsigned int,
1465 void *, unsigned int);
1466 static int parse_prefix(struct context *, const struct token *,
1467 const char *, unsigned int,
1468 void *, unsigned int);
1469 static int parse_boolean(struct context *, const struct token *,
1470 const char *, unsigned int,
1471 void *, unsigned int);
1472 static int parse_string(struct context *, const struct token *,
1473 const char *, unsigned int,
1474 void *, unsigned int);
1475 static int parse_hex(struct context *ctx, const struct token *token,
1476 const char *str, unsigned int len,
1477 void *buf, unsigned int size);
1478 static int parse_string0(struct context *, const struct token *,
1479 const char *, unsigned int,
1480 void *, unsigned int);
1481 static int parse_mac_addr(struct context *, const struct token *,
1482 const char *, unsigned int,
1483 void *, unsigned int);
1484 static int parse_ipv4_addr(struct context *, const struct token *,
1485 const char *, unsigned int,
1486 void *, unsigned int);
1487 static int parse_ipv6_addr(struct context *, const struct token *,
1488 const char *, unsigned int,
1489 void *, unsigned int);
1490 static int parse_port(struct context *, const struct token *,
1491 const char *, unsigned int,
1492 void *, unsigned int);
1493 static int comp_none(struct context *, const struct token *,
1494 unsigned int, char *, unsigned int);
1495 static int comp_boolean(struct context *, const struct token *,
1496 unsigned int, char *, unsigned int);
1497 static int comp_action(struct context *, const struct token *,
1498 unsigned int, char *, unsigned int);
1499 static int comp_port(struct context *, const struct token *,
1500 unsigned int, char *, unsigned int);
1501 static int comp_rule_id(struct context *, const struct token *,
1502 unsigned int, char *, unsigned int);
1503 static int comp_vc_action_rss_type(struct context *, const struct token *,
1504 unsigned int, char *, unsigned int);
1505 static int comp_vc_action_rss_queue(struct context *, const struct token *,
1506 unsigned int, char *, unsigned int);
1507 static int comp_set_raw_index(struct context *, const struct token *,
1508 unsigned int, char *, unsigned int);
1510 /** Token definitions. */
1511 static const struct token token_list[] = {
1512 /* Special tokens. */
1515 .help = "null entry, abused as the entry point",
1516 .next = NEXT(NEXT_ENTRY(FLOW)),
1521 .help = "command may end here",
1524 .name = "START_SET",
1525 .help = "null entry, abused as the entry point for set",
1526 .next = NEXT(NEXT_ENTRY(SET)),
1531 .help = "set command may end here",
1533 /* Common tokens. */
1537 .help = "integer value",
1542 .name = "{unsigned}",
1544 .help = "unsigned integer value",
1551 .help = "prefix length for bit-mask",
1552 .call = parse_prefix,
1556 .name = "{boolean}",
1558 .help = "any boolean value",
1559 .call = parse_boolean,
1560 .comp = comp_boolean,
1565 .help = "fixed string",
1566 .call = parse_string,
1572 .help = "fixed string",
1576 .name = "{file path}",
1578 .help = "file path",
1579 .call = parse_string0,
1583 .name = "{MAC address}",
1585 .help = "standard MAC address notation",
1586 .call = parse_mac_addr,
1590 .name = "{IPv4 address}",
1591 .type = "IPV4 ADDRESS",
1592 .help = "standard IPv4 address notation",
1593 .call = parse_ipv4_addr,
1597 .name = "{IPv6 address}",
1598 .type = "IPV6 ADDRESS",
1599 .help = "standard IPv6 address notation",
1600 .call = parse_ipv6_addr,
1604 .name = "{rule id}",
1606 .help = "rule identifier",
1608 .comp = comp_rule_id,
1611 .name = "{port_id}",
1613 .help = "port identifier",
1618 .name = "{group_id}",
1620 .help = "group identifier",
1624 [PRIORITY_LEVEL] = {
1627 .help = "priority level",
1631 /* Top-level command. */
1634 .type = "{command} {port_id} [{arg} [...]]",
1635 .help = "manage ingress/egress flow rules",
1636 .next = NEXT(NEXT_ENTRY
1647 /* Sub-level commands. */
1650 .help = "check whether a flow rule can be created",
1651 .next = NEXT(next_vc_attr, NEXT_ENTRY(PORT_ID)),
1652 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1657 .help = "create a flow rule",
1658 .next = NEXT(next_vc_attr, NEXT_ENTRY(PORT_ID)),
1659 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1664 .help = "destroy specific flow rules",
1665 .next = NEXT(NEXT_ENTRY(DESTROY_RULE), NEXT_ENTRY(PORT_ID)),
1666 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1667 .call = parse_destroy,
1671 .help = "destroy all flow rules",
1672 .next = NEXT(NEXT_ENTRY(PORT_ID)),
1673 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1674 .call = parse_flush,
1678 .help = "dump all flow rules to file",
1679 .next = NEXT(next_dump_attr, NEXT_ENTRY(PORT_ID)),
1680 .args = ARGS(ARGS_ENTRY(struct buffer, args.dump.file),
1681 ARGS_ENTRY(struct buffer, port)),
1686 .help = "query an existing flow rule",
1687 .next = NEXT(NEXT_ENTRY(QUERY_ACTION),
1688 NEXT_ENTRY(RULE_ID),
1689 NEXT_ENTRY(PORT_ID)),
1690 .args = ARGS(ARGS_ENTRY(struct buffer, args.query.action.type),
1691 ARGS_ENTRY(struct buffer, args.query.rule),
1692 ARGS_ENTRY(struct buffer, port)),
1693 .call = parse_query,
1697 .help = "list existing flow rules",
1698 .next = NEXT(next_list_attr, NEXT_ENTRY(PORT_ID)),
1699 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1704 .help = "restrict ingress traffic to the defined flow rules",
1705 .next = NEXT(NEXT_ENTRY(BOOLEAN),
1706 NEXT_ENTRY(PORT_ID)),
1707 .args = ARGS(ARGS_ENTRY(struct buffer, args.isolate.set),
1708 ARGS_ENTRY(struct buffer, port)),
1709 .call = parse_isolate,
1711 /* Destroy arguments. */
1714 .help = "specify a rule identifier",
1715 .next = NEXT(next_destroy_attr, NEXT_ENTRY(RULE_ID)),
1716 .args = ARGS(ARGS_ENTRY_PTR(struct buffer, args.destroy.rule)),
1717 .call = parse_destroy,
1719 /* Query arguments. */
1723 .help = "action to query, must be part of the rule",
1724 .call = parse_action,
1725 .comp = comp_action,
1727 /* List arguments. */
1730 .help = "specify a group",
1731 .next = NEXT(next_list_attr, NEXT_ENTRY(GROUP_ID)),
1732 .args = ARGS(ARGS_ENTRY_PTR(struct buffer, args.list.group)),
1735 /* Validate/create attributes. */
1738 .help = "specify a group",
1739 .next = NEXT(next_vc_attr, NEXT_ENTRY(GROUP_ID)),
1740 .args = ARGS(ARGS_ENTRY(struct rte_flow_attr, group)),
1745 .help = "specify a priority level",
1746 .next = NEXT(next_vc_attr, NEXT_ENTRY(PRIORITY_LEVEL)),
1747 .args = ARGS(ARGS_ENTRY(struct rte_flow_attr, priority)),
1752 .help = "affect rule to ingress",
1753 .next = NEXT(next_vc_attr),
1758 .help = "affect rule to egress",
1759 .next = NEXT(next_vc_attr),
1764 .help = "apply rule directly to endpoints found in pattern",
1765 .next = NEXT(next_vc_attr),
1768 /* Validate/create pattern. */
1771 .help = "submit a list of pattern items",
1772 .next = NEXT(next_item),
1777 .help = "match value perfectly (with full bit-mask)",
1778 .call = parse_vc_spec,
1780 [ITEM_PARAM_SPEC] = {
1782 .help = "match value according to configured bit-mask",
1783 .call = parse_vc_spec,
1785 [ITEM_PARAM_LAST] = {
1787 .help = "specify upper bound to establish a range",
1788 .call = parse_vc_spec,
1790 [ITEM_PARAM_MASK] = {
1792 .help = "specify bit-mask with relevant bits set to one",
1793 .call = parse_vc_spec,
1795 [ITEM_PARAM_PREFIX] = {
1797 .help = "generate bit-mask from a prefix length",
1798 .call = parse_vc_spec,
1802 .help = "specify next pattern item",
1803 .next = NEXT(next_item),
1807 .help = "end list of pattern items",
1808 .priv = PRIV_ITEM(END, 0),
1809 .next = NEXT(NEXT_ENTRY(ACTIONS)),
1814 .help = "no-op pattern item",
1815 .priv = PRIV_ITEM(VOID, 0),
1816 .next = NEXT(NEXT_ENTRY(ITEM_NEXT)),
1821 .help = "perform actions when pattern does not match",
1822 .priv = PRIV_ITEM(INVERT, 0),
1823 .next = NEXT(NEXT_ENTRY(ITEM_NEXT)),
1828 .help = "match any protocol for the current layer",
1829 .priv = PRIV_ITEM(ANY, sizeof(struct rte_flow_item_any)),
1830 .next = NEXT(item_any),
1835 .help = "number of layers covered",
1836 .next = NEXT(item_any, NEXT_ENTRY(UNSIGNED), item_param),
1837 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_any, num)),
1841 .help = "match traffic from/to the physical function",
1842 .priv = PRIV_ITEM(PF, 0),
1843 .next = NEXT(NEXT_ENTRY(ITEM_NEXT)),
1848 .help = "match traffic from/to a virtual function ID",
1849 .priv = PRIV_ITEM(VF, sizeof(struct rte_flow_item_vf)),
1850 .next = NEXT(item_vf),
1856 .next = NEXT(item_vf, NEXT_ENTRY(UNSIGNED), item_param),
1857 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_vf, id)),
1861 .help = "match traffic from/to a specific physical port",
1862 .priv = PRIV_ITEM(PHY_PORT,
1863 sizeof(struct rte_flow_item_phy_port)),
1864 .next = NEXT(item_phy_port),
1867 [ITEM_PHY_PORT_INDEX] = {
1869 .help = "physical port index",
1870 .next = NEXT(item_phy_port, NEXT_ENTRY(UNSIGNED), item_param),
1871 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_phy_port, index)),
1875 .help = "match traffic from/to a given DPDK port ID",
1876 .priv = PRIV_ITEM(PORT_ID,
1877 sizeof(struct rte_flow_item_port_id)),
1878 .next = NEXT(item_port_id),
1881 [ITEM_PORT_ID_ID] = {
1883 .help = "DPDK port ID",
1884 .next = NEXT(item_port_id, NEXT_ENTRY(UNSIGNED), item_param),
1885 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_port_id, id)),
1889 .help = "match traffic against value set in previously matched rule",
1890 .priv = PRIV_ITEM(MARK, sizeof(struct rte_flow_item_mark)),
1891 .next = NEXT(item_mark),
1896 .help = "Integer value to match against",
1897 .next = NEXT(item_mark, NEXT_ENTRY(UNSIGNED), item_param),
1898 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_mark, id)),
1902 .help = "match an arbitrary byte string",
1903 .priv = PRIV_ITEM(RAW, ITEM_RAW_SIZE),
1904 .next = NEXT(item_raw),
1907 [ITEM_RAW_RELATIVE] = {
1909 .help = "look for pattern after the previous item",
1910 .next = NEXT(item_raw, NEXT_ENTRY(BOOLEAN), item_param),
1911 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_item_raw,
1914 [ITEM_RAW_SEARCH] = {
1916 .help = "search pattern from offset (see also limit)",
1917 .next = NEXT(item_raw, NEXT_ENTRY(BOOLEAN), item_param),
1918 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_item_raw,
1921 [ITEM_RAW_OFFSET] = {
1923 .help = "absolute or relative offset for pattern",
1924 .next = NEXT(item_raw, NEXT_ENTRY(INTEGER), item_param),
1925 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_raw, offset)),
1927 [ITEM_RAW_LIMIT] = {
1929 .help = "search area limit for start of pattern",
1930 .next = NEXT(item_raw, NEXT_ENTRY(UNSIGNED), item_param),
1931 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_raw, limit)),
1933 [ITEM_RAW_PATTERN] = {
1935 .help = "byte string to look for",
1936 .next = NEXT(item_raw,
1938 NEXT_ENTRY(ITEM_PARAM_IS,
1941 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_raw, pattern),
1942 ARGS_ENTRY(struct rte_flow_item_raw, length),
1943 ARGS_ENTRY_ARB(sizeof(struct rte_flow_item_raw),
1944 ITEM_RAW_PATTERN_SIZE)),
1948 .help = "match Ethernet header",
1949 .priv = PRIV_ITEM(ETH, sizeof(struct rte_flow_item_eth)),
1950 .next = NEXT(item_eth),
1955 .help = "destination MAC",
1956 .next = NEXT(item_eth, NEXT_ENTRY(MAC_ADDR), item_param),
1957 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_eth, dst)),
1961 .help = "source MAC",
1962 .next = NEXT(item_eth, NEXT_ENTRY(MAC_ADDR), item_param),
1963 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_eth, src)),
1967 .help = "EtherType",
1968 .next = NEXT(item_eth, NEXT_ENTRY(UNSIGNED), item_param),
1969 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_eth, type)),
1973 .help = "match 802.1Q/ad VLAN tag",
1974 .priv = PRIV_ITEM(VLAN, sizeof(struct rte_flow_item_vlan)),
1975 .next = NEXT(item_vlan),
1980 .help = "tag control information",
1981 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1982 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vlan, tci)),
1986 .help = "priority code point",
1987 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1988 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_vlan,
1993 .help = "drop eligible indicator",
1994 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1995 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_vlan,
2000 .help = "VLAN identifier",
2001 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
2002 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_vlan,
2005 [ITEM_VLAN_INNER_TYPE] = {
2006 .name = "inner_type",
2007 .help = "inner EtherType",
2008 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
2009 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vlan,
2014 .help = "match IPv4 header",
2015 .priv = PRIV_ITEM(IPV4, sizeof(struct rte_flow_item_ipv4)),
2016 .next = NEXT(item_ipv4),
2021 .help = "type of service",
2022 .next = NEXT(item_ipv4, NEXT_ENTRY(UNSIGNED), item_param),
2023 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
2024 hdr.type_of_service)),
2028 .help = "time to live",
2029 .next = NEXT(item_ipv4, NEXT_ENTRY(UNSIGNED), item_param),
2030 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
2033 [ITEM_IPV4_PROTO] = {
2035 .help = "next protocol ID",
2036 .next = NEXT(item_ipv4, NEXT_ENTRY(UNSIGNED), item_param),
2037 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
2038 hdr.next_proto_id)),
2042 .help = "source address",
2043 .next = NEXT(item_ipv4, NEXT_ENTRY(IPV4_ADDR), item_param),
2044 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
2049 .help = "destination address",
2050 .next = NEXT(item_ipv4, NEXT_ENTRY(IPV4_ADDR), item_param),
2051 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
2056 .help = "match IPv6 header",
2057 .priv = PRIV_ITEM(IPV6, sizeof(struct rte_flow_item_ipv6)),
2058 .next = NEXT(item_ipv6),
2063 .help = "traffic class",
2064 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
2065 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_ipv6,
2067 "\x0f\xf0\x00\x00")),
2069 [ITEM_IPV6_FLOW] = {
2071 .help = "flow label",
2072 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
2073 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_ipv6,
2075 "\x00\x0f\xff\xff")),
2077 [ITEM_IPV6_PROTO] = {
2079 .help = "protocol (next header)",
2080 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
2081 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
2086 .help = "hop limit",
2087 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
2088 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
2093 .help = "source address",
2094 .next = NEXT(item_ipv6, NEXT_ENTRY(IPV6_ADDR), item_param),
2095 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
2100 .help = "destination address",
2101 .next = NEXT(item_ipv6, NEXT_ENTRY(IPV6_ADDR), item_param),
2102 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
2107 .help = "match ICMP header",
2108 .priv = PRIV_ITEM(ICMP, sizeof(struct rte_flow_item_icmp)),
2109 .next = NEXT(item_icmp),
2112 [ITEM_ICMP_TYPE] = {
2114 .help = "ICMP packet type",
2115 .next = NEXT(item_icmp, NEXT_ENTRY(UNSIGNED), item_param),
2116 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp,
2119 [ITEM_ICMP_CODE] = {
2121 .help = "ICMP packet code",
2122 .next = NEXT(item_icmp, NEXT_ENTRY(UNSIGNED), item_param),
2123 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp,
2128 .help = "match UDP header",
2129 .priv = PRIV_ITEM(UDP, sizeof(struct rte_flow_item_udp)),
2130 .next = NEXT(item_udp),
2135 .help = "UDP source port",
2136 .next = NEXT(item_udp, NEXT_ENTRY(UNSIGNED), item_param),
2137 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_udp,
2142 .help = "UDP destination port",
2143 .next = NEXT(item_udp, NEXT_ENTRY(UNSIGNED), item_param),
2144 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_udp,
2149 .help = "match TCP header",
2150 .priv = PRIV_ITEM(TCP, sizeof(struct rte_flow_item_tcp)),
2151 .next = NEXT(item_tcp),
2156 .help = "TCP source port",
2157 .next = NEXT(item_tcp, NEXT_ENTRY(UNSIGNED), item_param),
2158 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_tcp,
2163 .help = "TCP destination port",
2164 .next = NEXT(item_tcp, NEXT_ENTRY(UNSIGNED), item_param),
2165 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_tcp,
2168 [ITEM_TCP_FLAGS] = {
2170 .help = "TCP flags",
2171 .next = NEXT(item_tcp, NEXT_ENTRY(UNSIGNED), item_param),
2172 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_tcp,
2177 .help = "match SCTP header",
2178 .priv = PRIV_ITEM(SCTP, sizeof(struct rte_flow_item_sctp)),
2179 .next = NEXT(item_sctp),
2184 .help = "SCTP source port",
2185 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
2186 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
2191 .help = "SCTP destination port",
2192 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
2193 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
2198 .help = "validation tag",
2199 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
2200 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
2203 [ITEM_SCTP_CKSUM] = {
2206 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
2207 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
2212 .help = "match VXLAN header",
2213 .priv = PRIV_ITEM(VXLAN, sizeof(struct rte_flow_item_vxlan)),
2214 .next = NEXT(item_vxlan),
2217 [ITEM_VXLAN_VNI] = {
2219 .help = "VXLAN identifier",
2220 .next = NEXT(item_vxlan, NEXT_ENTRY(UNSIGNED), item_param),
2221 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vxlan, vni)),
2225 .help = "match E-Tag header",
2226 .priv = PRIV_ITEM(E_TAG, sizeof(struct rte_flow_item_e_tag)),
2227 .next = NEXT(item_e_tag),
2230 [ITEM_E_TAG_GRP_ECID_B] = {
2231 .name = "grp_ecid_b",
2232 .help = "GRP and E-CID base",
2233 .next = NEXT(item_e_tag, NEXT_ENTRY(UNSIGNED), item_param),
2234 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_e_tag,
2240 .help = "match NVGRE header",
2241 .priv = PRIV_ITEM(NVGRE, sizeof(struct rte_flow_item_nvgre)),
2242 .next = NEXT(item_nvgre),
2245 [ITEM_NVGRE_TNI] = {
2247 .help = "virtual subnet ID",
2248 .next = NEXT(item_nvgre, NEXT_ENTRY(UNSIGNED), item_param),
2249 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_nvgre, tni)),
2253 .help = "match MPLS header",
2254 .priv = PRIV_ITEM(MPLS, sizeof(struct rte_flow_item_mpls)),
2255 .next = NEXT(item_mpls),
2258 [ITEM_MPLS_LABEL] = {
2260 .help = "MPLS label",
2261 .next = NEXT(item_mpls, NEXT_ENTRY(UNSIGNED), item_param),
2262 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_mpls,
2268 .help = "MPLS Traffic Class",
2269 .next = NEXT(item_mpls, NEXT_ENTRY(UNSIGNED), item_param),
2270 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_mpls,
2276 .help = "MPLS Bottom-of-Stack",
2277 .next = NEXT(item_mpls, NEXT_ENTRY(UNSIGNED), item_param),
2278 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_mpls,
2284 .help = "match GRE header",
2285 .priv = PRIV_ITEM(GRE, sizeof(struct rte_flow_item_gre)),
2286 .next = NEXT(item_gre),
2289 [ITEM_GRE_PROTO] = {
2291 .help = "GRE protocol type",
2292 .next = NEXT(item_gre, NEXT_ENTRY(UNSIGNED), item_param),
2293 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gre,
2296 [ITEM_GRE_C_RSVD0_VER] = {
2297 .name = "c_rsvd0_ver",
2299 "checksum (1b), undefined (1b), key bit (1b),"
2300 " sequence number (1b), reserved 0 (9b),"
2302 .next = NEXT(item_gre, NEXT_ENTRY(UNSIGNED), item_param),
2303 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gre,
2306 [ITEM_GRE_C_BIT] = {
2308 .help = "checksum bit (C)",
2309 .next = NEXT(item_gre, NEXT_ENTRY(BOOLEAN), item_param),
2310 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_gre,
2312 "\x80\x00\x00\x00")),
2314 [ITEM_GRE_S_BIT] = {
2316 .help = "sequence number bit (S)",
2317 .next = NEXT(item_gre, NEXT_ENTRY(BOOLEAN), item_param),
2318 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_gre,
2320 "\x10\x00\x00\x00")),
2322 [ITEM_GRE_K_BIT] = {
2324 .help = "key bit (K)",
2325 .next = NEXT(item_gre, NEXT_ENTRY(BOOLEAN), item_param),
2326 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_gre,
2328 "\x20\x00\x00\x00")),
2332 .help = "fuzzy pattern match, expect faster than default",
2333 .priv = PRIV_ITEM(FUZZY,
2334 sizeof(struct rte_flow_item_fuzzy)),
2335 .next = NEXT(item_fuzzy),
2338 [ITEM_FUZZY_THRESH] = {
2340 .help = "match accuracy threshold",
2341 .next = NEXT(item_fuzzy, NEXT_ENTRY(UNSIGNED), item_param),
2342 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_fuzzy,
2347 .help = "match GTP header",
2348 .priv = PRIV_ITEM(GTP, sizeof(struct rte_flow_item_gtp)),
2349 .next = NEXT(item_gtp),
2352 [ITEM_GTP_FLAGS] = {
2353 .name = "v_pt_rsv_flags",
2354 .help = "GTP flags",
2355 .next = NEXT(item_gtp, NEXT_ENTRY(UNSIGNED), item_param),
2356 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_gtp,
2359 [ITEM_GTP_MSG_TYPE] = {
2361 .help = "GTP message type",
2362 .next = NEXT(item_gtp, NEXT_ENTRY(UNSIGNED), item_param),
2363 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_gtp, msg_type)),
2367 .help = "tunnel endpoint identifier",
2368 .next = NEXT(item_gtp, NEXT_ENTRY(UNSIGNED), item_param),
2369 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gtp, teid)),
2373 .help = "match GTP header",
2374 .priv = PRIV_ITEM(GTPC, sizeof(struct rte_flow_item_gtp)),
2375 .next = NEXT(item_gtp),
2380 .help = "match GTP header",
2381 .priv = PRIV_ITEM(GTPU, sizeof(struct rte_flow_item_gtp)),
2382 .next = NEXT(item_gtp),
2387 .help = "match GENEVE header",
2388 .priv = PRIV_ITEM(GENEVE, sizeof(struct rte_flow_item_geneve)),
2389 .next = NEXT(item_geneve),
2392 [ITEM_GENEVE_VNI] = {
2394 .help = "virtual network identifier",
2395 .next = NEXT(item_geneve, NEXT_ENTRY(UNSIGNED), item_param),
2396 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_geneve, vni)),
2398 [ITEM_GENEVE_PROTO] = {
2400 .help = "GENEVE protocol type",
2401 .next = NEXT(item_geneve, NEXT_ENTRY(UNSIGNED), item_param),
2402 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_geneve,
2405 [ITEM_VXLAN_GPE] = {
2406 .name = "vxlan-gpe",
2407 .help = "match VXLAN-GPE header",
2408 .priv = PRIV_ITEM(VXLAN_GPE,
2409 sizeof(struct rte_flow_item_vxlan_gpe)),
2410 .next = NEXT(item_vxlan_gpe),
2413 [ITEM_VXLAN_GPE_VNI] = {
2415 .help = "VXLAN-GPE identifier",
2416 .next = NEXT(item_vxlan_gpe, NEXT_ENTRY(UNSIGNED), item_param),
2417 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vxlan_gpe,
2420 [ITEM_ARP_ETH_IPV4] = {
2421 .name = "arp_eth_ipv4",
2422 .help = "match ARP header for Ethernet/IPv4",
2423 .priv = PRIV_ITEM(ARP_ETH_IPV4,
2424 sizeof(struct rte_flow_item_arp_eth_ipv4)),
2425 .next = NEXT(item_arp_eth_ipv4),
2428 [ITEM_ARP_ETH_IPV4_SHA] = {
2430 .help = "sender hardware address",
2431 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(MAC_ADDR),
2433 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
2436 [ITEM_ARP_ETH_IPV4_SPA] = {
2438 .help = "sender IPv4 address",
2439 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(IPV4_ADDR),
2441 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
2444 [ITEM_ARP_ETH_IPV4_THA] = {
2446 .help = "target hardware address",
2447 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(MAC_ADDR),
2449 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
2452 [ITEM_ARP_ETH_IPV4_TPA] = {
2454 .help = "target IPv4 address",
2455 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(IPV4_ADDR),
2457 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
2462 .help = "match presence of any IPv6 extension header",
2463 .priv = PRIV_ITEM(IPV6_EXT,
2464 sizeof(struct rte_flow_item_ipv6_ext)),
2465 .next = NEXT(item_ipv6_ext),
2468 [ITEM_IPV6_EXT_NEXT_HDR] = {
2470 .help = "next header",
2471 .next = NEXT(item_ipv6_ext, NEXT_ENTRY(UNSIGNED), item_param),
2472 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6_ext,
2477 .help = "match any ICMPv6 header",
2478 .priv = PRIV_ITEM(ICMP6, sizeof(struct rte_flow_item_icmp6)),
2479 .next = NEXT(item_icmp6),
2482 [ITEM_ICMP6_TYPE] = {
2484 .help = "ICMPv6 type",
2485 .next = NEXT(item_icmp6, NEXT_ENTRY(UNSIGNED), item_param),
2486 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6,
2489 [ITEM_ICMP6_CODE] = {
2491 .help = "ICMPv6 code",
2492 .next = NEXT(item_icmp6, NEXT_ENTRY(UNSIGNED), item_param),
2493 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6,
2496 [ITEM_ICMP6_ND_NS] = {
2497 .name = "icmp6_nd_ns",
2498 .help = "match ICMPv6 neighbor discovery solicitation",
2499 .priv = PRIV_ITEM(ICMP6_ND_NS,
2500 sizeof(struct rte_flow_item_icmp6_nd_ns)),
2501 .next = NEXT(item_icmp6_nd_ns),
2504 [ITEM_ICMP6_ND_NS_TARGET_ADDR] = {
2505 .name = "target_addr",
2506 .help = "target address",
2507 .next = NEXT(item_icmp6_nd_ns, NEXT_ENTRY(IPV6_ADDR),
2509 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6_nd_ns,
2512 [ITEM_ICMP6_ND_NA] = {
2513 .name = "icmp6_nd_na",
2514 .help = "match ICMPv6 neighbor discovery advertisement",
2515 .priv = PRIV_ITEM(ICMP6_ND_NA,
2516 sizeof(struct rte_flow_item_icmp6_nd_na)),
2517 .next = NEXT(item_icmp6_nd_na),
2520 [ITEM_ICMP6_ND_NA_TARGET_ADDR] = {
2521 .name = "target_addr",
2522 .help = "target address",
2523 .next = NEXT(item_icmp6_nd_na, NEXT_ENTRY(IPV6_ADDR),
2525 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6_nd_na,
2528 [ITEM_ICMP6_ND_OPT] = {
2529 .name = "icmp6_nd_opt",
2530 .help = "match presence of any ICMPv6 neighbor discovery"
2532 .priv = PRIV_ITEM(ICMP6_ND_OPT,
2533 sizeof(struct rte_flow_item_icmp6_nd_opt)),
2534 .next = NEXT(item_icmp6_nd_opt),
2537 [ITEM_ICMP6_ND_OPT_TYPE] = {
2539 .help = "ND option type",
2540 .next = NEXT(item_icmp6_nd_opt, NEXT_ENTRY(UNSIGNED),
2542 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6_nd_opt,
2545 [ITEM_ICMP6_ND_OPT_SLA_ETH] = {
2546 .name = "icmp6_nd_opt_sla_eth",
2547 .help = "match ICMPv6 neighbor discovery source Ethernet"
2548 " link-layer address option",
2550 (ICMP6_ND_OPT_SLA_ETH,
2551 sizeof(struct rte_flow_item_icmp6_nd_opt_sla_eth)),
2552 .next = NEXT(item_icmp6_nd_opt_sla_eth),
2555 [ITEM_ICMP6_ND_OPT_SLA_ETH_SLA] = {
2557 .help = "source Ethernet LLA",
2558 .next = NEXT(item_icmp6_nd_opt_sla_eth, NEXT_ENTRY(MAC_ADDR),
2560 .args = ARGS(ARGS_ENTRY_HTON
2561 (struct rte_flow_item_icmp6_nd_opt_sla_eth, sla)),
2563 [ITEM_ICMP6_ND_OPT_TLA_ETH] = {
2564 .name = "icmp6_nd_opt_tla_eth",
2565 .help = "match ICMPv6 neighbor discovery target Ethernet"
2566 " link-layer address option",
2568 (ICMP6_ND_OPT_TLA_ETH,
2569 sizeof(struct rte_flow_item_icmp6_nd_opt_tla_eth)),
2570 .next = NEXT(item_icmp6_nd_opt_tla_eth),
2573 [ITEM_ICMP6_ND_OPT_TLA_ETH_TLA] = {
2575 .help = "target Ethernet LLA",
2576 .next = NEXT(item_icmp6_nd_opt_tla_eth, NEXT_ENTRY(MAC_ADDR),
2578 .args = ARGS(ARGS_ENTRY_HTON
2579 (struct rte_flow_item_icmp6_nd_opt_tla_eth, tla)),
2583 .help = "match metadata header",
2584 .priv = PRIV_ITEM(META, sizeof(struct rte_flow_item_meta)),
2585 .next = NEXT(item_meta),
2588 [ITEM_META_DATA] = {
2590 .help = "metadata value",
2591 .next = NEXT(item_meta, NEXT_ENTRY(UNSIGNED), item_param),
2592 .args = ARGS(ARGS_ENTRY_MASK(struct rte_flow_item_meta,
2593 data, "\xff\xff\xff\xff")),
2597 .help = "match GRE key",
2598 .priv = PRIV_ITEM(GRE_KEY, sizeof(rte_be32_t)),
2599 .next = NEXT(item_gre_key),
2602 [ITEM_GRE_KEY_VALUE] = {
2604 .help = "key value",
2605 .next = NEXT(item_gre_key, NEXT_ENTRY(UNSIGNED), item_param),
2606 .args = ARGS(ARG_ENTRY_HTON(rte_be32_t)),
2610 .help = "match GTP extension header with type 0x85",
2611 .priv = PRIV_ITEM(GTP_PSC,
2612 sizeof(struct rte_flow_item_gtp_psc)),
2613 .next = NEXT(item_gtp_psc),
2616 [ITEM_GTP_PSC_QFI] = {
2618 .help = "QoS flow identifier",
2619 .next = NEXT(item_gtp_psc, NEXT_ENTRY(UNSIGNED), item_param),
2620 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gtp_psc,
2623 [ITEM_GTP_PSC_PDU_T] = {
2626 .next = NEXT(item_gtp_psc, NEXT_ENTRY(UNSIGNED), item_param),
2627 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gtp_psc,
2632 .help = "match PPPoE session header",
2633 .priv = PRIV_ITEM(PPPOES, sizeof(struct rte_flow_item_pppoe)),
2634 .next = NEXT(item_pppoes),
2639 .help = "match PPPoE discovery header",
2640 .priv = PRIV_ITEM(PPPOED, sizeof(struct rte_flow_item_pppoe)),
2641 .next = NEXT(item_pppoed),
2644 [ITEM_PPPOE_SEID] = {
2646 .help = "session identifier",
2647 .next = NEXT(item_pppoes, NEXT_ENTRY(UNSIGNED), item_param),
2648 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_pppoe,
2651 [ITEM_PPPOE_PROTO_ID] = {
2653 .help = "match PPPoE session protocol identifier",
2654 .priv = PRIV_ITEM(PPPOE_PROTO_ID,
2655 sizeof(struct rte_flow_item_pppoe_proto_id)),
2656 .next = NEXT(item_pppoe_proto_id),
2661 .help = "matches higig2 header",
2662 .priv = PRIV_ITEM(HIGIG2,
2663 sizeof(struct rte_flow_item_higig2_hdr)),
2664 .next = NEXT(item_higig2),
2667 [ITEM_HIGIG2_CLASSIFICATION] = {
2668 .name = "classification",
2669 .help = "matches classification of higig2 header",
2670 .next = NEXT(item_higig2, NEXT_ENTRY(UNSIGNED), item_param),
2671 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_higig2_hdr,
2672 hdr.ppt1.classification)),
2674 [ITEM_HIGIG2_VID] = {
2676 .help = "matches vid of higig2 header",
2677 .next = NEXT(item_higig2, NEXT_ENTRY(UNSIGNED), item_param),
2678 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_higig2_hdr,
2683 .help = "match tag value",
2684 .priv = PRIV_ITEM(TAG, sizeof(struct rte_flow_item_tag)),
2685 .next = NEXT(item_tag),
2690 .help = "tag value to match",
2691 .next = NEXT(item_tag, NEXT_ENTRY(UNSIGNED), item_param),
2692 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_tag, data)),
2694 [ITEM_TAG_INDEX] = {
2696 .help = "index of tag array to match",
2697 .next = NEXT(item_tag, NEXT_ENTRY(UNSIGNED),
2698 NEXT_ENTRY(ITEM_PARAM_IS)),
2699 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_tag, index)),
2701 [ITEM_L2TPV3OIP] = {
2702 .name = "l2tpv3oip",
2703 .help = "match L2TPv3 over IP header",
2704 .priv = PRIV_ITEM(L2TPV3OIP,
2705 sizeof(struct rte_flow_item_l2tpv3oip)),
2706 .next = NEXT(item_l2tpv3oip),
2709 [ITEM_L2TPV3OIP_SESSION_ID] = {
2710 .name = "session_id",
2711 .help = "session identifier",
2712 .next = NEXT(item_l2tpv3oip, NEXT_ENTRY(UNSIGNED), item_param),
2713 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_l2tpv3oip,
2718 .help = "match ESP header",
2719 .priv = PRIV_ITEM(ESP, sizeof(struct rte_flow_item_esp)),
2720 .next = NEXT(item_esp),
2725 .help = "security policy index",
2726 .next = NEXT(item_esp, NEXT_ENTRY(UNSIGNED), item_param),
2727 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_esp,
2732 .help = "match AH header",
2733 .priv = PRIV_ITEM(AH, sizeof(struct rte_flow_item_ah)),
2734 .next = NEXT(item_ah),
2739 .help = "security parameters index",
2740 .next = NEXT(item_ah, NEXT_ENTRY(UNSIGNED), item_param),
2741 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ah, spi)),
2745 .help = "match pfcp header",
2746 .priv = PRIV_ITEM(PFCP, sizeof(struct rte_flow_item_pfcp)),
2747 .next = NEXT(item_pfcp),
2750 [ITEM_PFCP_S_FIELD] = {
2753 .next = NEXT(item_pfcp, NEXT_ENTRY(UNSIGNED), item_param),
2754 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_pfcp,
2757 [ITEM_PFCP_SEID] = {
2759 .help = "session endpoint identifier",
2760 .next = NEXT(item_pfcp, NEXT_ENTRY(UNSIGNED), item_param),
2761 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_pfcp, seid)),
2763 /* Validate/create actions. */
2766 .help = "submit a list of associated actions",
2767 .next = NEXT(next_action),
2772 .help = "specify next action",
2773 .next = NEXT(next_action),
2777 .help = "end list of actions",
2778 .priv = PRIV_ACTION(END, 0),
2783 .help = "no-op action",
2784 .priv = PRIV_ACTION(VOID, 0),
2785 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2788 [ACTION_PASSTHRU] = {
2790 .help = "let subsequent rule process matched packets",
2791 .priv = PRIV_ACTION(PASSTHRU, 0),
2792 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2797 .help = "redirect traffic to a given group",
2798 .priv = PRIV_ACTION(JUMP, sizeof(struct rte_flow_action_jump)),
2799 .next = NEXT(action_jump),
2802 [ACTION_JUMP_GROUP] = {
2804 .help = "group to redirect traffic to",
2805 .next = NEXT(action_jump, NEXT_ENTRY(UNSIGNED)),
2806 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_jump, group)),
2807 .call = parse_vc_conf,
2811 .help = "attach 32 bit value to packets",
2812 .priv = PRIV_ACTION(MARK, sizeof(struct rte_flow_action_mark)),
2813 .next = NEXT(action_mark),
2816 [ACTION_MARK_ID] = {
2818 .help = "32 bit value to return with packets",
2819 .next = NEXT(action_mark, NEXT_ENTRY(UNSIGNED)),
2820 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_mark, id)),
2821 .call = parse_vc_conf,
2825 .help = "flag packets",
2826 .priv = PRIV_ACTION(FLAG, 0),
2827 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2832 .help = "assign packets to a given queue index",
2833 .priv = PRIV_ACTION(QUEUE,
2834 sizeof(struct rte_flow_action_queue)),
2835 .next = NEXT(action_queue),
2838 [ACTION_QUEUE_INDEX] = {
2840 .help = "queue index to use",
2841 .next = NEXT(action_queue, NEXT_ENTRY(UNSIGNED)),
2842 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_queue, index)),
2843 .call = parse_vc_conf,
2847 .help = "drop packets (note: passthru has priority)",
2848 .priv = PRIV_ACTION(DROP, 0),
2849 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2854 .help = "enable counters for this rule",
2855 .priv = PRIV_ACTION(COUNT,
2856 sizeof(struct rte_flow_action_count)),
2857 .next = NEXT(action_count),
2860 [ACTION_COUNT_ID] = {
2861 .name = "identifier",
2862 .help = "counter identifier to use",
2863 .next = NEXT(action_count, NEXT_ENTRY(UNSIGNED)),
2864 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_count, id)),
2865 .call = parse_vc_conf,
2867 [ACTION_COUNT_SHARED] = {
2869 .help = "shared counter",
2870 .next = NEXT(action_count, NEXT_ENTRY(BOOLEAN)),
2871 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_count,
2873 .call = parse_vc_conf,
2877 .help = "spread packets among several queues",
2878 .priv = PRIV_ACTION(RSS, sizeof(struct action_rss_data)),
2879 .next = NEXT(action_rss),
2880 .call = parse_vc_action_rss,
2882 [ACTION_RSS_FUNC] = {
2884 .help = "RSS hash function to apply",
2885 .next = NEXT(action_rss,
2886 NEXT_ENTRY(ACTION_RSS_FUNC_DEFAULT,
2887 ACTION_RSS_FUNC_TOEPLITZ,
2888 ACTION_RSS_FUNC_SIMPLE_XOR,
2889 ACTION_RSS_FUNC_SYMMETRIC_TOEPLITZ)),
2891 [ACTION_RSS_FUNC_DEFAULT] = {
2893 .help = "default hash function",
2894 .call = parse_vc_action_rss_func,
2896 [ACTION_RSS_FUNC_TOEPLITZ] = {
2898 .help = "Toeplitz hash function",
2899 .call = parse_vc_action_rss_func,
2901 [ACTION_RSS_FUNC_SIMPLE_XOR] = {
2902 .name = "simple_xor",
2903 .help = "simple XOR hash function",
2904 .call = parse_vc_action_rss_func,
2906 [ACTION_RSS_FUNC_SYMMETRIC_TOEPLITZ] = {
2907 .name = "symmetric_toeplitz",
2908 .help = "Symmetric Toeplitz hash function",
2909 .call = parse_vc_action_rss_func,
2911 [ACTION_RSS_LEVEL] = {
2913 .help = "encapsulation level for \"types\"",
2914 .next = NEXT(action_rss, NEXT_ENTRY(UNSIGNED)),
2915 .args = ARGS(ARGS_ENTRY_ARB
2916 (offsetof(struct action_rss_data, conf) +
2917 offsetof(struct rte_flow_action_rss, level),
2918 sizeof(((struct rte_flow_action_rss *)0)->
2921 [ACTION_RSS_TYPES] = {
2923 .help = "specific RSS hash types",
2924 .next = NEXT(action_rss, NEXT_ENTRY(ACTION_RSS_TYPE)),
2926 [ACTION_RSS_TYPE] = {
2928 .help = "RSS hash type",
2929 .call = parse_vc_action_rss_type,
2930 .comp = comp_vc_action_rss_type,
2932 [ACTION_RSS_KEY] = {
2934 .help = "RSS hash key",
2935 .next = NEXT(action_rss, NEXT_ENTRY(HEX)),
2936 .args = ARGS(ARGS_ENTRY_ARB(0, 0),
2938 (offsetof(struct action_rss_data, conf) +
2939 offsetof(struct rte_flow_action_rss, key_len),
2940 sizeof(((struct rte_flow_action_rss *)0)->
2942 ARGS_ENTRY(struct action_rss_data, key)),
2944 [ACTION_RSS_KEY_LEN] = {
2946 .help = "RSS hash key length in bytes",
2947 .next = NEXT(action_rss, NEXT_ENTRY(UNSIGNED)),
2948 .args = ARGS(ARGS_ENTRY_ARB_BOUNDED
2949 (offsetof(struct action_rss_data, conf) +
2950 offsetof(struct rte_flow_action_rss, key_len),
2951 sizeof(((struct rte_flow_action_rss *)0)->
2954 RSS_HASH_KEY_LENGTH)),
2956 [ACTION_RSS_QUEUES] = {
2958 .help = "queue indices to use",
2959 .next = NEXT(action_rss, NEXT_ENTRY(ACTION_RSS_QUEUE)),
2960 .call = parse_vc_conf,
2962 [ACTION_RSS_QUEUE] = {
2964 .help = "queue index",
2965 .call = parse_vc_action_rss_queue,
2966 .comp = comp_vc_action_rss_queue,
2970 .help = "direct traffic to physical function",
2971 .priv = PRIV_ACTION(PF, 0),
2972 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2977 .help = "direct traffic to a virtual function ID",
2978 .priv = PRIV_ACTION(VF, sizeof(struct rte_flow_action_vf)),
2979 .next = NEXT(action_vf),
2982 [ACTION_VF_ORIGINAL] = {
2984 .help = "use original VF ID if possible",
2985 .next = NEXT(action_vf, NEXT_ENTRY(BOOLEAN)),
2986 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_vf,
2988 .call = parse_vc_conf,
2993 .next = NEXT(action_vf, NEXT_ENTRY(UNSIGNED)),
2994 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_vf, id)),
2995 .call = parse_vc_conf,
2997 [ACTION_PHY_PORT] = {
2999 .help = "direct packets to physical port index",
3000 .priv = PRIV_ACTION(PHY_PORT,
3001 sizeof(struct rte_flow_action_phy_port)),
3002 .next = NEXT(action_phy_port),
3005 [ACTION_PHY_PORT_ORIGINAL] = {
3007 .help = "use original port index if possible",
3008 .next = NEXT(action_phy_port, NEXT_ENTRY(BOOLEAN)),
3009 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_phy_port,
3011 .call = parse_vc_conf,
3013 [ACTION_PHY_PORT_INDEX] = {
3015 .help = "physical port index",
3016 .next = NEXT(action_phy_port, NEXT_ENTRY(UNSIGNED)),
3017 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_phy_port,
3019 .call = parse_vc_conf,
3021 [ACTION_PORT_ID] = {
3023 .help = "direct matching traffic to a given DPDK port ID",
3024 .priv = PRIV_ACTION(PORT_ID,
3025 sizeof(struct rte_flow_action_port_id)),
3026 .next = NEXT(action_port_id),
3029 [ACTION_PORT_ID_ORIGINAL] = {
3031 .help = "use original DPDK port ID if possible",
3032 .next = NEXT(action_port_id, NEXT_ENTRY(BOOLEAN)),
3033 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_port_id,
3035 .call = parse_vc_conf,
3037 [ACTION_PORT_ID_ID] = {
3039 .help = "DPDK port ID",
3040 .next = NEXT(action_port_id, NEXT_ENTRY(UNSIGNED)),
3041 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_port_id, id)),
3042 .call = parse_vc_conf,
3046 .help = "meter the directed packets at given id",
3047 .priv = PRIV_ACTION(METER,
3048 sizeof(struct rte_flow_action_meter)),
3049 .next = NEXT(action_meter),
3052 [ACTION_METER_ID] = {
3054 .help = "meter id to use",
3055 .next = NEXT(action_meter, NEXT_ENTRY(UNSIGNED)),
3056 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_meter, mtr_id)),
3057 .call = parse_vc_conf,
3059 [ACTION_OF_SET_MPLS_TTL] = {
3060 .name = "of_set_mpls_ttl",
3061 .help = "OpenFlow's OFPAT_SET_MPLS_TTL",
3064 sizeof(struct rte_flow_action_of_set_mpls_ttl)),
3065 .next = NEXT(action_of_set_mpls_ttl),
3068 [ACTION_OF_SET_MPLS_TTL_MPLS_TTL] = {
3071 .next = NEXT(action_of_set_mpls_ttl, NEXT_ENTRY(UNSIGNED)),
3072 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_of_set_mpls_ttl,
3074 .call = parse_vc_conf,
3076 [ACTION_OF_DEC_MPLS_TTL] = {
3077 .name = "of_dec_mpls_ttl",
3078 .help = "OpenFlow's OFPAT_DEC_MPLS_TTL",
3079 .priv = PRIV_ACTION(OF_DEC_MPLS_TTL, 0),
3080 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3083 [ACTION_OF_SET_NW_TTL] = {
3084 .name = "of_set_nw_ttl",
3085 .help = "OpenFlow's OFPAT_SET_NW_TTL",
3088 sizeof(struct rte_flow_action_of_set_nw_ttl)),
3089 .next = NEXT(action_of_set_nw_ttl),
3092 [ACTION_OF_SET_NW_TTL_NW_TTL] = {
3095 .next = NEXT(action_of_set_nw_ttl, NEXT_ENTRY(UNSIGNED)),
3096 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_of_set_nw_ttl,
3098 .call = parse_vc_conf,
3100 [ACTION_OF_DEC_NW_TTL] = {
3101 .name = "of_dec_nw_ttl",
3102 .help = "OpenFlow's OFPAT_DEC_NW_TTL",
3103 .priv = PRIV_ACTION(OF_DEC_NW_TTL, 0),
3104 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3107 [ACTION_OF_COPY_TTL_OUT] = {
3108 .name = "of_copy_ttl_out",
3109 .help = "OpenFlow's OFPAT_COPY_TTL_OUT",
3110 .priv = PRIV_ACTION(OF_COPY_TTL_OUT, 0),
3111 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3114 [ACTION_OF_COPY_TTL_IN] = {
3115 .name = "of_copy_ttl_in",
3116 .help = "OpenFlow's OFPAT_COPY_TTL_IN",
3117 .priv = PRIV_ACTION(OF_COPY_TTL_IN, 0),
3118 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3121 [ACTION_OF_POP_VLAN] = {
3122 .name = "of_pop_vlan",
3123 .help = "OpenFlow's OFPAT_POP_VLAN",
3124 .priv = PRIV_ACTION(OF_POP_VLAN, 0),
3125 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3128 [ACTION_OF_PUSH_VLAN] = {
3129 .name = "of_push_vlan",
3130 .help = "OpenFlow's OFPAT_PUSH_VLAN",
3133 sizeof(struct rte_flow_action_of_push_vlan)),
3134 .next = NEXT(action_of_push_vlan),
3137 [ACTION_OF_PUSH_VLAN_ETHERTYPE] = {
3138 .name = "ethertype",
3139 .help = "EtherType",
3140 .next = NEXT(action_of_push_vlan, NEXT_ENTRY(UNSIGNED)),
3141 .args = ARGS(ARGS_ENTRY_HTON
3142 (struct rte_flow_action_of_push_vlan,
3144 .call = parse_vc_conf,
3146 [ACTION_OF_SET_VLAN_VID] = {
3147 .name = "of_set_vlan_vid",
3148 .help = "OpenFlow's OFPAT_SET_VLAN_VID",
3151 sizeof(struct rte_flow_action_of_set_vlan_vid)),
3152 .next = NEXT(action_of_set_vlan_vid),
3155 [ACTION_OF_SET_VLAN_VID_VLAN_VID] = {
3158 .next = NEXT(action_of_set_vlan_vid, NEXT_ENTRY(UNSIGNED)),
3159 .args = ARGS(ARGS_ENTRY_HTON
3160 (struct rte_flow_action_of_set_vlan_vid,
3162 .call = parse_vc_conf,
3164 [ACTION_OF_SET_VLAN_PCP] = {
3165 .name = "of_set_vlan_pcp",
3166 .help = "OpenFlow's OFPAT_SET_VLAN_PCP",
3169 sizeof(struct rte_flow_action_of_set_vlan_pcp)),
3170 .next = NEXT(action_of_set_vlan_pcp),
3173 [ACTION_OF_SET_VLAN_PCP_VLAN_PCP] = {
3175 .help = "VLAN priority",
3176 .next = NEXT(action_of_set_vlan_pcp, NEXT_ENTRY(UNSIGNED)),
3177 .args = ARGS(ARGS_ENTRY_HTON
3178 (struct rte_flow_action_of_set_vlan_pcp,
3180 .call = parse_vc_conf,
3182 [ACTION_OF_POP_MPLS] = {
3183 .name = "of_pop_mpls",
3184 .help = "OpenFlow's OFPAT_POP_MPLS",
3185 .priv = PRIV_ACTION(OF_POP_MPLS,
3186 sizeof(struct rte_flow_action_of_pop_mpls)),
3187 .next = NEXT(action_of_pop_mpls),
3190 [ACTION_OF_POP_MPLS_ETHERTYPE] = {
3191 .name = "ethertype",
3192 .help = "EtherType",
3193 .next = NEXT(action_of_pop_mpls, NEXT_ENTRY(UNSIGNED)),
3194 .args = ARGS(ARGS_ENTRY_HTON
3195 (struct rte_flow_action_of_pop_mpls,
3197 .call = parse_vc_conf,
3199 [ACTION_OF_PUSH_MPLS] = {
3200 .name = "of_push_mpls",
3201 .help = "OpenFlow's OFPAT_PUSH_MPLS",
3204 sizeof(struct rte_flow_action_of_push_mpls)),
3205 .next = NEXT(action_of_push_mpls),
3208 [ACTION_OF_PUSH_MPLS_ETHERTYPE] = {
3209 .name = "ethertype",
3210 .help = "EtherType",
3211 .next = NEXT(action_of_push_mpls, NEXT_ENTRY(UNSIGNED)),
3212 .args = ARGS(ARGS_ENTRY_HTON
3213 (struct rte_flow_action_of_push_mpls,
3215 .call = parse_vc_conf,
3217 [ACTION_VXLAN_ENCAP] = {
3218 .name = "vxlan_encap",
3219 .help = "VXLAN encapsulation, uses configuration set by \"set"
3221 .priv = PRIV_ACTION(VXLAN_ENCAP,
3222 sizeof(struct action_vxlan_encap_data)),
3223 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3224 .call = parse_vc_action_vxlan_encap,
3226 [ACTION_VXLAN_DECAP] = {
3227 .name = "vxlan_decap",
3228 .help = "Performs a decapsulation action by stripping all"
3229 " headers of the VXLAN tunnel network overlay from the"
3231 .priv = PRIV_ACTION(VXLAN_DECAP, 0),
3232 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3235 [ACTION_NVGRE_ENCAP] = {
3236 .name = "nvgre_encap",
3237 .help = "NVGRE encapsulation, uses configuration set by \"set"
3239 .priv = PRIV_ACTION(NVGRE_ENCAP,
3240 sizeof(struct action_nvgre_encap_data)),
3241 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3242 .call = parse_vc_action_nvgre_encap,
3244 [ACTION_NVGRE_DECAP] = {
3245 .name = "nvgre_decap",
3246 .help = "Performs a decapsulation action by stripping all"
3247 " headers of the NVGRE tunnel network overlay from the"
3249 .priv = PRIV_ACTION(NVGRE_DECAP, 0),
3250 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3253 [ACTION_L2_ENCAP] = {
3255 .help = "l2 encap, uses configuration set by"
3256 " \"set l2_encap\"",
3257 .priv = PRIV_ACTION(RAW_ENCAP,
3258 sizeof(struct action_raw_encap_data)),
3259 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3260 .call = parse_vc_action_l2_encap,
3262 [ACTION_L2_DECAP] = {
3264 .help = "l2 decap, uses configuration set by"
3265 " \"set l2_decap\"",
3266 .priv = PRIV_ACTION(RAW_DECAP,
3267 sizeof(struct action_raw_decap_data)),
3268 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3269 .call = parse_vc_action_l2_decap,
3271 [ACTION_MPLSOGRE_ENCAP] = {
3272 .name = "mplsogre_encap",
3273 .help = "mplsogre encapsulation, uses configuration set by"
3274 " \"set mplsogre_encap\"",
3275 .priv = PRIV_ACTION(RAW_ENCAP,
3276 sizeof(struct action_raw_encap_data)),
3277 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3278 .call = parse_vc_action_mplsogre_encap,
3280 [ACTION_MPLSOGRE_DECAP] = {
3281 .name = "mplsogre_decap",
3282 .help = "mplsogre decapsulation, uses configuration set by"
3283 " \"set mplsogre_decap\"",
3284 .priv = PRIV_ACTION(RAW_DECAP,
3285 sizeof(struct action_raw_decap_data)),
3286 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3287 .call = parse_vc_action_mplsogre_decap,
3289 [ACTION_MPLSOUDP_ENCAP] = {
3290 .name = "mplsoudp_encap",
3291 .help = "mplsoudp encapsulation, uses configuration set by"
3292 " \"set mplsoudp_encap\"",
3293 .priv = PRIV_ACTION(RAW_ENCAP,
3294 sizeof(struct action_raw_encap_data)),
3295 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3296 .call = parse_vc_action_mplsoudp_encap,
3298 [ACTION_MPLSOUDP_DECAP] = {
3299 .name = "mplsoudp_decap",
3300 .help = "mplsoudp decapsulation, uses configuration set by"
3301 " \"set mplsoudp_decap\"",
3302 .priv = PRIV_ACTION(RAW_DECAP,
3303 sizeof(struct action_raw_decap_data)),
3304 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3305 .call = parse_vc_action_mplsoudp_decap,
3307 [ACTION_SET_IPV4_SRC] = {
3308 .name = "set_ipv4_src",
3309 .help = "Set a new IPv4 source address in the outermost"
3311 .priv = PRIV_ACTION(SET_IPV4_SRC,
3312 sizeof(struct rte_flow_action_set_ipv4)),
3313 .next = NEXT(action_set_ipv4_src),
3316 [ACTION_SET_IPV4_SRC_IPV4_SRC] = {
3317 .name = "ipv4_addr",
3318 .help = "new IPv4 source address to set",
3319 .next = NEXT(action_set_ipv4_src, NEXT_ENTRY(IPV4_ADDR)),
3320 .args = ARGS(ARGS_ENTRY_HTON
3321 (struct rte_flow_action_set_ipv4, ipv4_addr)),
3322 .call = parse_vc_conf,
3324 [ACTION_SET_IPV4_DST] = {
3325 .name = "set_ipv4_dst",
3326 .help = "Set a new IPv4 destination address in the outermost"
3328 .priv = PRIV_ACTION(SET_IPV4_DST,
3329 sizeof(struct rte_flow_action_set_ipv4)),
3330 .next = NEXT(action_set_ipv4_dst),
3333 [ACTION_SET_IPV4_DST_IPV4_DST] = {
3334 .name = "ipv4_addr",
3335 .help = "new IPv4 destination address to set",
3336 .next = NEXT(action_set_ipv4_dst, NEXT_ENTRY(IPV4_ADDR)),
3337 .args = ARGS(ARGS_ENTRY_HTON
3338 (struct rte_flow_action_set_ipv4, ipv4_addr)),
3339 .call = parse_vc_conf,
3341 [ACTION_SET_IPV6_SRC] = {
3342 .name = "set_ipv6_src",
3343 .help = "Set a new IPv6 source address in the outermost"
3345 .priv = PRIV_ACTION(SET_IPV6_SRC,
3346 sizeof(struct rte_flow_action_set_ipv6)),
3347 .next = NEXT(action_set_ipv6_src),
3350 [ACTION_SET_IPV6_SRC_IPV6_SRC] = {
3351 .name = "ipv6_addr",
3352 .help = "new IPv6 source address to set",
3353 .next = NEXT(action_set_ipv6_src, NEXT_ENTRY(IPV6_ADDR)),
3354 .args = ARGS(ARGS_ENTRY_HTON
3355 (struct rte_flow_action_set_ipv6, ipv6_addr)),
3356 .call = parse_vc_conf,
3358 [ACTION_SET_IPV6_DST] = {
3359 .name = "set_ipv6_dst",
3360 .help = "Set a new IPv6 destination address in the outermost"
3362 .priv = PRIV_ACTION(SET_IPV6_DST,
3363 sizeof(struct rte_flow_action_set_ipv6)),
3364 .next = NEXT(action_set_ipv6_dst),
3367 [ACTION_SET_IPV6_DST_IPV6_DST] = {
3368 .name = "ipv6_addr",
3369 .help = "new IPv6 destination address to set",
3370 .next = NEXT(action_set_ipv6_dst, NEXT_ENTRY(IPV6_ADDR)),
3371 .args = ARGS(ARGS_ENTRY_HTON
3372 (struct rte_flow_action_set_ipv6, ipv6_addr)),
3373 .call = parse_vc_conf,
3375 [ACTION_SET_TP_SRC] = {
3376 .name = "set_tp_src",
3377 .help = "set a new source port number in the outermost"
3379 .priv = PRIV_ACTION(SET_TP_SRC,
3380 sizeof(struct rte_flow_action_set_tp)),
3381 .next = NEXT(action_set_tp_src),
3384 [ACTION_SET_TP_SRC_TP_SRC] = {
3386 .help = "new source port number to set",
3387 .next = NEXT(action_set_tp_src, NEXT_ENTRY(UNSIGNED)),
3388 .args = ARGS(ARGS_ENTRY_HTON
3389 (struct rte_flow_action_set_tp, port)),
3390 .call = parse_vc_conf,
3392 [ACTION_SET_TP_DST] = {
3393 .name = "set_tp_dst",
3394 .help = "set a new destination port number in the outermost"
3396 .priv = PRIV_ACTION(SET_TP_DST,
3397 sizeof(struct rte_flow_action_set_tp)),
3398 .next = NEXT(action_set_tp_dst),
3401 [ACTION_SET_TP_DST_TP_DST] = {
3403 .help = "new destination port number to set",
3404 .next = NEXT(action_set_tp_dst, NEXT_ENTRY(UNSIGNED)),
3405 .args = ARGS(ARGS_ENTRY_HTON
3406 (struct rte_flow_action_set_tp, port)),
3407 .call = parse_vc_conf,
3409 [ACTION_MAC_SWAP] = {
3411 .help = "Swap the source and destination MAC addresses"
3412 " in the outermost Ethernet header",
3413 .priv = PRIV_ACTION(MAC_SWAP, 0),
3414 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3417 [ACTION_DEC_TTL] = {
3419 .help = "decrease network TTL if available",
3420 .priv = PRIV_ACTION(DEC_TTL, 0),
3421 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3424 [ACTION_SET_TTL] = {
3426 .help = "set ttl value",
3427 .priv = PRIV_ACTION(SET_TTL,
3428 sizeof(struct rte_flow_action_set_ttl)),
3429 .next = NEXT(action_set_ttl),
3432 [ACTION_SET_TTL_TTL] = {
3433 .name = "ttl_value",
3434 .help = "new ttl value to set",
3435 .next = NEXT(action_set_ttl, NEXT_ENTRY(UNSIGNED)),
3436 .args = ARGS(ARGS_ENTRY_HTON
3437 (struct rte_flow_action_set_ttl, ttl_value)),
3438 .call = parse_vc_conf,
3440 [ACTION_SET_MAC_SRC] = {
3441 .name = "set_mac_src",
3442 .help = "set source mac address",
3443 .priv = PRIV_ACTION(SET_MAC_SRC,
3444 sizeof(struct rte_flow_action_set_mac)),
3445 .next = NEXT(action_set_mac_src),
3448 [ACTION_SET_MAC_SRC_MAC_SRC] = {
3450 .help = "new source mac address",
3451 .next = NEXT(action_set_mac_src, NEXT_ENTRY(MAC_ADDR)),
3452 .args = ARGS(ARGS_ENTRY_HTON
3453 (struct rte_flow_action_set_mac, mac_addr)),
3454 .call = parse_vc_conf,
3456 [ACTION_SET_MAC_DST] = {
3457 .name = "set_mac_dst",
3458 .help = "set destination mac address",
3459 .priv = PRIV_ACTION(SET_MAC_DST,
3460 sizeof(struct rte_flow_action_set_mac)),
3461 .next = NEXT(action_set_mac_dst),
3464 [ACTION_SET_MAC_DST_MAC_DST] = {
3466 .help = "new destination mac address to set",
3467 .next = NEXT(action_set_mac_dst, NEXT_ENTRY(MAC_ADDR)),
3468 .args = ARGS(ARGS_ENTRY_HTON
3469 (struct rte_flow_action_set_mac, mac_addr)),
3470 .call = parse_vc_conf,
3472 [ACTION_INC_TCP_SEQ] = {
3473 .name = "inc_tcp_seq",
3474 .help = "increase TCP sequence number",
3475 .priv = PRIV_ACTION(INC_TCP_SEQ, sizeof(rte_be32_t)),
3476 .next = NEXT(action_inc_tcp_seq),
3479 [ACTION_INC_TCP_SEQ_VALUE] = {
3481 .help = "the value to increase TCP sequence number by",
3482 .next = NEXT(action_inc_tcp_seq, NEXT_ENTRY(UNSIGNED)),
3483 .args = ARGS(ARG_ENTRY_HTON(rte_be32_t)),
3484 .call = parse_vc_conf,
3486 [ACTION_DEC_TCP_SEQ] = {
3487 .name = "dec_tcp_seq",
3488 .help = "decrease TCP sequence number",
3489 .priv = PRIV_ACTION(DEC_TCP_SEQ, sizeof(rte_be32_t)),
3490 .next = NEXT(action_dec_tcp_seq),
3493 [ACTION_DEC_TCP_SEQ_VALUE] = {
3495 .help = "the value to decrease TCP sequence number by",
3496 .next = NEXT(action_dec_tcp_seq, NEXT_ENTRY(UNSIGNED)),
3497 .args = ARGS(ARG_ENTRY_HTON(rte_be32_t)),
3498 .call = parse_vc_conf,
3500 [ACTION_INC_TCP_ACK] = {
3501 .name = "inc_tcp_ack",
3502 .help = "increase TCP acknowledgment number",
3503 .priv = PRIV_ACTION(INC_TCP_ACK, sizeof(rte_be32_t)),
3504 .next = NEXT(action_inc_tcp_ack),
3507 [ACTION_INC_TCP_ACK_VALUE] = {
3509 .help = "the value to increase TCP acknowledgment number by",
3510 .next = NEXT(action_inc_tcp_ack, NEXT_ENTRY(UNSIGNED)),
3511 .args = ARGS(ARG_ENTRY_HTON(rte_be32_t)),
3512 .call = parse_vc_conf,
3514 [ACTION_DEC_TCP_ACK] = {
3515 .name = "dec_tcp_ack",
3516 .help = "decrease TCP acknowledgment number",
3517 .priv = PRIV_ACTION(DEC_TCP_ACK, sizeof(rte_be32_t)),
3518 .next = NEXT(action_dec_tcp_ack),
3521 [ACTION_DEC_TCP_ACK_VALUE] = {
3523 .help = "the value to decrease TCP acknowledgment number by",
3524 .next = NEXT(action_dec_tcp_ack, NEXT_ENTRY(UNSIGNED)),
3525 .args = ARGS(ARG_ENTRY_HTON(rte_be32_t)),
3526 .call = parse_vc_conf,
3528 [ACTION_RAW_ENCAP] = {
3529 .name = "raw_encap",
3530 .help = "encapsulation data, defined by set raw_encap",
3531 .priv = PRIV_ACTION(RAW_ENCAP,
3532 sizeof(struct action_raw_encap_data)),
3533 .next = NEXT(action_raw_encap),
3534 .call = parse_vc_action_raw_encap,
3536 [ACTION_RAW_ENCAP_INDEX] = {
3538 .help = "the index of raw_encap_confs",
3539 .next = NEXT(NEXT_ENTRY(ACTION_RAW_ENCAP_INDEX_VALUE)),
3541 [ACTION_RAW_ENCAP_INDEX_VALUE] = {
3544 .help = "unsigned integer value",
3545 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3546 .call = parse_vc_action_raw_encap_index,
3547 .comp = comp_set_raw_index,
3549 [ACTION_RAW_DECAP] = {
3550 .name = "raw_decap",
3551 .help = "decapsulation data, defined by set raw_encap",
3552 .priv = PRIV_ACTION(RAW_DECAP,
3553 sizeof(struct action_raw_decap_data)),
3554 .next = NEXT(action_raw_decap),
3555 .call = parse_vc_action_raw_decap,
3557 [ACTION_RAW_DECAP_INDEX] = {
3559 .help = "the index of raw_encap_confs",
3560 .next = NEXT(NEXT_ENTRY(ACTION_RAW_DECAP_INDEX_VALUE)),
3562 [ACTION_RAW_DECAP_INDEX_VALUE] = {
3565 .help = "unsigned integer value",
3566 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3567 .call = parse_vc_action_raw_decap_index,
3568 .comp = comp_set_raw_index,
3570 /* Top level command. */
3573 .help = "set raw encap/decap data",
3574 .type = "set raw_encap|raw_decap <index> <pattern>",
3575 .next = NEXT(NEXT_ENTRY
3578 .call = parse_set_init,
3580 /* Sub-level commands. */
3582 .name = "raw_encap",
3583 .help = "set raw encap data",
3584 .next = NEXT(next_set_raw),
3585 .args = ARGS(ARGS_ENTRY_ARB_BOUNDED
3586 (offsetof(struct buffer, port),
3587 sizeof(((struct buffer *)0)->port),
3588 0, RAW_ENCAP_CONFS_MAX_NUM - 1)),
3589 .call = parse_set_raw_encap_decap,
3592 .name = "raw_decap",
3593 .help = "set raw decap data",
3594 .next = NEXT(next_set_raw),
3595 .args = ARGS(ARGS_ENTRY_ARB_BOUNDED
3596 (offsetof(struct buffer, port),
3597 sizeof(((struct buffer *)0)->port),
3598 0, RAW_ENCAP_CONFS_MAX_NUM - 1)),
3599 .call = parse_set_raw_encap_decap,
3604 .help = "index of raw_encap/raw_decap data",
3605 .next = NEXT(next_item),
3608 [ACTION_SET_TAG] = {
3611 .priv = PRIV_ACTION(SET_TAG,
3612 sizeof(struct rte_flow_action_set_tag)),
3613 .next = NEXT(action_set_tag),
3616 [ACTION_SET_TAG_INDEX] = {
3618 .help = "index of tag array",
3619 .next = NEXT(action_set_tag, NEXT_ENTRY(UNSIGNED)),
3620 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_set_tag, index)),
3621 .call = parse_vc_conf,
3623 [ACTION_SET_TAG_DATA] = {
3625 .help = "tag value",
3626 .next = NEXT(action_set_tag, NEXT_ENTRY(UNSIGNED)),
3627 .args = ARGS(ARGS_ENTRY
3628 (struct rte_flow_action_set_tag, data)),
3629 .call = parse_vc_conf,
3631 [ACTION_SET_TAG_MASK] = {
3633 .help = "mask for tag value",
3634 .next = NEXT(action_set_tag, NEXT_ENTRY(UNSIGNED)),
3635 .args = ARGS(ARGS_ENTRY
3636 (struct rte_flow_action_set_tag, mask)),
3637 .call = parse_vc_conf,
3639 [ACTION_SET_META] = {
3641 .help = "set metadata",
3642 .priv = PRIV_ACTION(SET_META,
3643 sizeof(struct rte_flow_action_set_meta)),
3644 .next = NEXT(action_set_meta),
3645 .call = parse_vc_action_set_meta,
3647 [ACTION_SET_META_DATA] = {
3649 .help = "metadata value",
3650 .next = NEXT(action_set_meta, NEXT_ENTRY(UNSIGNED)),
3651 .args = ARGS(ARGS_ENTRY
3652 (struct rte_flow_action_set_meta, data)),
3653 .call = parse_vc_conf,
3655 [ACTION_SET_META_MASK] = {
3657 .help = "mask for metadata value",
3658 .next = NEXT(action_set_meta, NEXT_ENTRY(UNSIGNED)),
3659 .args = ARGS(ARGS_ENTRY
3660 (struct rte_flow_action_set_meta, mask)),
3661 .call = parse_vc_conf,
3663 [ACTION_SET_IPV4_DSCP] = {
3664 .name = "set_ipv4_dscp",
3665 .help = "set DSCP value",
3666 .priv = PRIV_ACTION(SET_IPV4_DSCP,
3667 sizeof(struct rte_flow_action_set_dscp)),
3668 .next = NEXT(action_set_ipv4_dscp),
3671 [ACTION_SET_IPV4_DSCP_VALUE] = {
3672 .name = "dscp_value",
3673 .help = "new IPv4 DSCP value to set",
3674 .next = NEXT(action_set_ipv4_dscp, NEXT_ENTRY(UNSIGNED)),
3675 .args = ARGS(ARGS_ENTRY
3676 (struct rte_flow_action_set_dscp, dscp)),
3677 .call = parse_vc_conf,
3679 [ACTION_SET_IPV6_DSCP] = {
3680 .name = "set_ipv6_dscp",
3681 .help = "set DSCP value",
3682 .priv = PRIV_ACTION(SET_IPV6_DSCP,
3683 sizeof(struct rte_flow_action_set_dscp)),
3684 .next = NEXT(action_set_ipv6_dscp),
3687 [ACTION_SET_IPV6_DSCP_VALUE] = {
3688 .name = "dscp_value",
3689 .help = "new IPv6 DSCP value to set",
3690 .next = NEXT(action_set_ipv6_dscp, NEXT_ENTRY(UNSIGNED)),
3691 .args = ARGS(ARGS_ENTRY
3692 (struct rte_flow_action_set_dscp, dscp)),
3693 .call = parse_vc_conf,
3697 /** Remove and return last entry from argument stack. */
3698 static const struct arg *
3699 pop_args(struct context *ctx)
3701 return ctx->args_num ? ctx->args[--ctx->args_num] : NULL;
3704 /** Add entry on top of the argument stack. */
3706 push_args(struct context *ctx, const struct arg *arg)
3708 if (ctx->args_num == CTX_STACK_SIZE)
3710 ctx->args[ctx->args_num++] = arg;
3714 /** Spread value into buffer according to bit-mask. */
3716 arg_entry_bf_fill(void *dst, uintmax_t val, const struct arg *arg)
3718 uint32_t i = arg->size;
3726 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
3735 unsigned int shift = 0;
3736 uint8_t *buf = (uint8_t *)dst + arg->offset + (i -= sub);
3738 for (shift = 0; arg->mask[i] >> shift; ++shift) {
3739 if (!(arg->mask[i] & (1 << shift)))
3744 *buf &= ~(1 << shift);
3745 *buf |= (val & 1) << shift;
3753 /** Compare a string with a partial one of a given length. */
3755 strcmp_partial(const char *full, const char *partial, size_t partial_len)
3757 int r = strncmp(full, partial, partial_len);
3761 if (strlen(full) <= partial_len)
3763 return full[partial_len];
3767 * Parse a prefix length and generate a bit-mask.
3769 * Last argument (ctx->args) is retrieved to determine mask size, storage
3770 * location and whether the result must use network byte ordering.
3773 parse_prefix(struct context *ctx, const struct token *token,
3774 const char *str, unsigned int len,
3775 void *buf, unsigned int size)
3777 const struct arg *arg = pop_args(ctx);
3778 static const uint8_t conv[] = "\x00\x80\xc0\xe0\xf0\xf8\xfc\xfe\xff";
3785 /* Argument is expected. */
3789 u = strtoumax(str, &end, 0);
3790 if (errno || (size_t)(end - str) != len)
3795 extra = arg_entry_bf_fill(NULL, 0, arg);
3804 if (!arg_entry_bf_fill(ctx->object, v, arg) ||
3805 !arg_entry_bf_fill(ctx->objmask, -1, arg))
3812 if (bytes > size || bytes + !!extra > size)
3816 buf = (uint8_t *)ctx->object + arg->offset;
3817 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
3819 memset((uint8_t *)buf + size - bytes, 0xff, bytes);
3820 memset(buf, 0x00, size - bytes);
3822 ((uint8_t *)buf)[size - bytes - 1] = conv[extra];
3826 memset(buf, 0xff, bytes);
3827 memset((uint8_t *)buf + bytes, 0x00, size - bytes);
3829 ((uint8_t *)buf)[bytes] = conv[extra];
3832 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
3835 push_args(ctx, arg);
3839 /** Default parsing function for token name matching. */
3841 parse_default(struct context *ctx, const struct token *token,
3842 const char *str, unsigned int len,
3843 void *buf, unsigned int size)
3848 if (strcmp_partial(token->name, str, len))
3853 /** Parse flow command, initialize output buffer for subsequent tokens. */
3855 parse_init(struct context *ctx, const struct token *token,
3856 const char *str, unsigned int len,
3857 void *buf, unsigned int size)
3859 struct buffer *out = buf;
3861 /* Token name must match. */
3862 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
3864 /* Nothing else to do if there is no buffer. */
3867 /* Make sure buffer is large enough. */
3868 if (size < sizeof(*out))
3870 /* Initialize buffer. */
3871 memset(out, 0x00, sizeof(*out));
3872 memset((uint8_t *)out + sizeof(*out), 0x22, size - sizeof(*out));
3875 ctx->objmask = NULL;
3879 /** Parse tokens for validate/create commands. */
3881 parse_vc(struct context *ctx, const struct token *token,
3882 const char *str, unsigned int len,
3883 void *buf, unsigned int size)
3885 struct buffer *out = buf;
3889 /* Token name must match. */
3890 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
3892 /* Nothing else to do if there is no buffer. */
3895 if (!out->command) {
3896 if (ctx->curr != VALIDATE && ctx->curr != CREATE)
3898 if (sizeof(*out) > size)
3900 out->command = ctx->curr;
3903 ctx->objmask = NULL;
3904 out->args.vc.data = (uint8_t *)out + size;
3908 ctx->object = &out->args.vc.attr;
3909 ctx->objmask = NULL;
3910 switch (ctx->curr) {
3915 out->args.vc.attr.ingress = 1;
3918 out->args.vc.attr.egress = 1;
3921 out->args.vc.attr.transfer = 1;
3924 out->args.vc.pattern =
3925 (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
3927 ctx->object = out->args.vc.pattern;
3928 ctx->objmask = NULL;
3931 out->args.vc.actions =
3932 (void *)RTE_ALIGN_CEIL((uintptr_t)
3933 (out->args.vc.pattern +
3934 out->args.vc.pattern_n),
3936 ctx->object = out->args.vc.actions;
3937 ctx->objmask = NULL;
3944 if (!out->args.vc.actions) {
3945 const struct parse_item_priv *priv = token->priv;
3946 struct rte_flow_item *item =
3947 out->args.vc.pattern + out->args.vc.pattern_n;
3949 data_size = priv->size * 3; /* spec, last, mask */
3950 data = (void *)RTE_ALIGN_FLOOR((uintptr_t)
3951 (out->args.vc.data - data_size),
3953 if ((uint8_t *)item + sizeof(*item) > data)
3955 *item = (struct rte_flow_item){
3958 ++out->args.vc.pattern_n;
3960 ctx->objmask = NULL;
3962 const struct parse_action_priv *priv = token->priv;
3963 struct rte_flow_action *action =
3964 out->args.vc.actions + out->args.vc.actions_n;
3966 data_size = priv->size; /* configuration */
3967 data = (void *)RTE_ALIGN_FLOOR((uintptr_t)
3968 (out->args.vc.data - data_size),
3970 if ((uint8_t *)action + sizeof(*action) > data)
3972 *action = (struct rte_flow_action){
3974 .conf = data_size ? data : NULL,
3976 ++out->args.vc.actions_n;
3977 ctx->object = action;
3978 ctx->objmask = NULL;
3980 memset(data, 0, data_size);
3981 out->args.vc.data = data;
3982 ctx->objdata = data_size;
3986 /** Parse pattern item parameter type. */
3988 parse_vc_spec(struct context *ctx, const struct token *token,
3989 const char *str, unsigned int len,
3990 void *buf, unsigned int size)
3992 struct buffer *out = buf;
3993 struct rte_flow_item *item;
3999 /* Token name must match. */
4000 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
4002 /* Parse parameter types. */
4003 switch (ctx->curr) {
4004 static const enum index prefix[] = NEXT_ENTRY(PREFIX);
4010 case ITEM_PARAM_SPEC:
4013 case ITEM_PARAM_LAST:
4016 case ITEM_PARAM_PREFIX:
4017 /* Modify next token to expect a prefix. */
4018 if (ctx->next_num < 2)
4020 ctx->next[ctx->next_num - 2] = prefix;
4022 case ITEM_PARAM_MASK:
4028 /* Nothing else to do if there is no buffer. */
4031 if (!out->args.vc.pattern_n)
4033 item = &out->args.vc.pattern[out->args.vc.pattern_n - 1];
4034 data_size = ctx->objdata / 3; /* spec, last, mask */
4035 /* Point to selected object. */
4036 ctx->object = out->args.vc.data + (data_size * index);
4038 ctx->objmask = out->args.vc.data + (data_size * 2); /* mask */
4039 item->mask = ctx->objmask;
4041 ctx->objmask = NULL;
4042 /* Update relevant item pointer. */
4043 *((const void **[]){ &item->spec, &item->last, &item->mask })[index] =
4048 /** Parse action configuration field. */
4050 parse_vc_conf(struct context *ctx, const struct token *token,
4051 const char *str, unsigned int len,
4052 void *buf, unsigned int size)
4054 struct buffer *out = buf;
4057 /* Token name must match. */
4058 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
4060 /* Nothing else to do if there is no buffer. */
4063 /* Point to selected object. */
4064 ctx->object = out->args.vc.data;
4065 ctx->objmask = NULL;
4069 /** Parse RSS action. */
4071 parse_vc_action_rss(struct context *ctx, const struct token *token,
4072 const char *str, unsigned int len,
4073 void *buf, unsigned int size)
4075 struct buffer *out = buf;
4076 struct rte_flow_action *action;
4077 struct action_rss_data *action_rss_data;
4081 ret = parse_vc(ctx, token, str, len, buf, size);
4084 /* Nothing else to do if there is no buffer. */
4087 if (!out->args.vc.actions_n)
4089 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4090 /* Point to selected object. */
4091 ctx->object = out->args.vc.data;
4092 ctx->objmask = NULL;
4093 /* Set up default configuration. */
4094 action_rss_data = ctx->object;
4095 *action_rss_data = (struct action_rss_data){
4096 .conf = (struct rte_flow_action_rss){
4097 .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
4100 .key_len = sizeof(action_rss_data->key),
4101 .queue_num = RTE_MIN(nb_rxq, ACTION_RSS_QUEUE_NUM),
4102 .key = action_rss_data->key,
4103 .queue = action_rss_data->queue,
4105 .key = "testpmd's default RSS hash key, "
4106 "override it for better balancing",
4109 for (i = 0; i < action_rss_data->conf.queue_num; ++i)
4110 action_rss_data->queue[i] = i;
4111 if (!port_id_is_invalid(ctx->port, DISABLED_WARN) &&
4112 ctx->port != (portid_t)RTE_PORT_ALL) {
4113 struct rte_eth_dev_info info;
4116 ret2 = rte_eth_dev_info_get(ctx->port, &info);
4120 action_rss_data->conf.key_len =
4121 RTE_MIN(sizeof(action_rss_data->key),
4122 info.hash_key_size);
4124 action->conf = &action_rss_data->conf;
4129 * Parse func field for RSS action.
4131 * The RTE_ETH_HASH_FUNCTION_* value to assign is derived from the
4132 * ACTION_RSS_FUNC_* index that called this function.
4135 parse_vc_action_rss_func(struct context *ctx, const struct token *token,
4136 const char *str, unsigned int len,
4137 void *buf, unsigned int size)
4139 struct action_rss_data *action_rss_data;
4140 enum rte_eth_hash_function func;
4144 /* Token name must match. */
4145 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
4147 switch (ctx->curr) {
4148 case ACTION_RSS_FUNC_DEFAULT:
4149 func = RTE_ETH_HASH_FUNCTION_DEFAULT;
4151 case ACTION_RSS_FUNC_TOEPLITZ:
4152 func = RTE_ETH_HASH_FUNCTION_TOEPLITZ;
4154 case ACTION_RSS_FUNC_SIMPLE_XOR:
4155 func = RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
4157 case ACTION_RSS_FUNC_SYMMETRIC_TOEPLITZ:
4158 func = RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ;
4165 action_rss_data = ctx->object;
4166 action_rss_data->conf.func = func;
4171 * Parse type field for RSS action.
4173 * Valid tokens are type field names and the "end" token.
4176 parse_vc_action_rss_type(struct context *ctx, const struct token *token,
4177 const char *str, unsigned int len,
4178 void *buf, unsigned int size)
4180 static const enum index next[] = NEXT_ENTRY(ACTION_RSS_TYPE);
4181 struct action_rss_data *action_rss_data;
4187 if (ctx->curr != ACTION_RSS_TYPE)
4189 if (!(ctx->objdata >> 16) && ctx->object) {
4190 action_rss_data = ctx->object;
4191 action_rss_data->conf.types = 0;
4193 if (!strcmp_partial("end", str, len)) {
4194 ctx->objdata &= 0xffff;
4197 for (i = 0; rss_type_table[i].str; ++i)
4198 if (!strcmp_partial(rss_type_table[i].str, str, len))
4200 if (!rss_type_table[i].str)
4202 ctx->objdata = 1 << 16 | (ctx->objdata & 0xffff);
4204 if (ctx->next_num == RTE_DIM(ctx->next))
4206 ctx->next[ctx->next_num++] = next;
4209 action_rss_data = ctx->object;
4210 action_rss_data->conf.types |= rss_type_table[i].rss_type;
4215 * Parse queue field for RSS action.
4217 * Valid tokens are queue indices and the "end" token.
4220 parse_vc_action_rss_queue(struct context *ctx, const struct token *token,
4221 const char *str, unsigned int len,
4222 void *buf, unsigned int size)
4224 static const enum index next[] = NEXT_ENTRY(ACTION_RSS_QUEUE);
4225 struct action_rss_data *action_rss_data;
4226 const struct arg *arg;
4233 if (ctx->curr != ACTION_RSS_QUEUE)
4235 i = ctx->objdata >> 16;
4236 if (!strcmp_partial("end", str, len)) {
4237 ctx->objdata &= 0xffff;
4240 if (i >= ACTION_RSS_QUEUE_NUM)
4242 arg = ARGS_ENTRY_ARB(offsetof(struct action_rss_data, queue) +
4243 i * sizeof(action_rss_data->queue[i]),
4244 sizeof(action_rss_data->queue[i]));
4245 if (push_args(ctx, arg))
4247 ret = parse_int(ctx, token, str, len, NULL, 0);
4253 ctx->objdata = i << 16 | (ctx->objdata & 0xffff);
4255 if (ctx->next_num == RTE_DIM(ctx->next))
4257 ctx->next[ctx->next_num++] = next;
4261 action_rss_data = ctx->object;
4262 action_rss_data->conf.queue_num = i;
4263 action_rss_data->conf.queue = i ? action_rss_data->queue : NULL;
4267 /** Parse VXLAN encap action. */
4269 parse_vc_action_vxlan_encap(struct context *ctx, const struct token *token,
4270 const char *str, unsigned int len,
4271 void *buf, unsigned int size)
4273 struct buffer *out = buf;
4274 struct rte_flow_action *action;
4275 struct action_vxlan_encap_data *action_vxlan_encap_data;
4278 ret = parse_vc(ctx, token, str, len, buf, size);
4281 /* Nothing else to do if there is no buffer. */
4284 if (!out->args.vc.actions_n)
4286 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4287 /* Point to selected object. */
4288 ctx->object = out->args.vc.data;
4289 ctx->objmask = NULL;
4290 /* Set up default configuration. */
4291 action_vxlan_encap_data = ctx->object;
4292 *action_vxlan_encap_data = (struct action_vxlan_encap_data){
4293 .conf = (struct rte_flow_action_vxlan_encap){
4294 .definition = action_vxlan_encap_data->items,
4298 .type = RTE_FLOW_ITEM_TYPE_ETH,
4299 .spec = &action_vxlan_encap_data->item_eth,
4300 .mask = &rte_flow_item_eth_mask,
4303 .type = RTE_FLOW_ITEM_TYPE_VLAN,
4304 .spec = &action_vxlan_encap_data->item_vlan,
4305 .mask = &rte_flow_item_vlan_mask,
4308 .type = RTE_FLOW_ITEM_TYPE_IPV4,
4309 .spec = &action_vxlan_encap_data->item_ipv4,
4310 .mask = &rte_flow_item_ipv4_mask,
4313 .type = RTE_FLOW_ITEM_TYPE_UDP,
4314 .spec = &action_vxlan_encap_data->item_udp,
4315 .mask = &rte_flow_item_udp_mask,
4318 .type = RTE_FLOW_ITEM_TYPE_VXLAN,
4319 .spec = &action_vxlan_encap_data->item_vxlan,
4320 .mask = &rte_flow_item_vxlan_mask,
4323 .type = RTE_FLOW_ITEM_TYPE_END,
4328 .tci = vxlan_encap_conf.vlan_tci,
4332 .src_addr = vxlan_encap_conf.ipv4_src,
4333 .dst_addr = vxlan_encap_conf.ipv4_dst,
4336 .src_port = vxlan_encap_conf.udp_src,
4337 .dst_port = vxlan_encap_conf.udp_dst,
4339 .item_vxlan.flags = 0,
4341 memcpy(action_vxlan_encap_data->item_eth.dst.addr_bytes,
4342 vxlan_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
4343 memcpy(action_vxlan_encap_data->item_eth.src.addr_bytes,
4344 vxlan_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
4345 if (!vxlan_encap_conf.select_ipv4) {
4346 memcpy(&action_vxlan_encap_data->item_ipv6.hdr.src_addr,
4347 &vxlan_encap_conf.ipv6_src,
4348 sizeof(vxlan_encap_conf.ipv6_src));
4349 memcpy(&action_vxlan_encap_data->item_ipv6.hdr.dst_addr,
4350 &vxlan_encap_conf.ipv6_dst,
4351 sizeof(vxlan_encap_conf.ipv6_dst));
4352 action_vxlan_encap_data->items[2] = (struct rte_flow_item){
4353 .type = RTE_FLOW_ITEM_TYPE_IPV6,
4354 .spec = &action_vxlan_encap_data->item_ipv6,
4355 .mask = &rte_flow_item_ipv6_mask,
4358 if (!vxlan_encap_conf.select_vlan)
4359 action_vxlan_encap_data->items[1].type =
4360 RTE_FLOW_ITEM_TYPE_VOID;
4361 if (vxlan_encap_conf.select_tos_ttl) {
4362 if (vxlan_encap_conf.select_ipv4) {
4363 static struct rte_flow_item_ipv4 ipv4_mask_tos;
4365 memcpy(&ipv4_mask_tos, &rte_flow_item_ipv4_mask,
4366 sizeof(ipv4_mask_tos));
4367 ipv4_mask_tos.hdr.type_of_service = 0xff;
4368 ipv4_mask_tos.hdr.time_to_live = 0xff;
4369 action_vxlan_encap_data->item_ipv4.hdr.type_of_service =
4370 vxlan_encap_conf.ip_tos;
4371 action_vxlan_encap_data->item_ipv4.hdr.time_to_live =
4372 vxlan_encap_conf.ip_ttl;
4373 action_vxlan_encap_data->items[2].mask =
4376 static struct rte_flow_item_ipv6 ipv6_mask_tos;
4378 memcpy(&ipv6_mask_tos, &rte_flow_item_ipv6_mask,
4379 sizeof(ipv6_mask_tos));
4380 ipv6_mask_tos.hdr.vtc_flow |=
4381 RTE_BE32(0xfful << RTE_IPV6_HDR_TC_SHIFT);
4382 ipv6_mask_tos.hdr.hop_limits = 0xff;
4383 action_vxlan_encap_data->item_ipv6.hdr.vtc_flow |=
4385 ((uint32_t)vxlan_encap_conf.ip_tos <<
4386 RTE_IPV6_HDR_TC_SHIFT);
4387 action_vxlan_encap_data->item_ipv6.hdr.hop_limits =
4388 vxlan_encap_conf.ip_ttl;
4389 action_vxlan_encap_data->items[2].mask =
4393 memcpy(action_vxlan_encap_data->item_vxlan.vni, vxlan_encap_conf.vni,
4394 RTE_DIM(vxlan_encap_conf.vni));
4395 action->conf = &action_vxlan_encap_data->conf;
4399 /** Parse NVGRE encap action. */
4401 parse_vc_action_nvgre_encap(struct context *ctx, const struct token *token,
4402 const char *str, unsigned int len,
4403 void *buf, unsigned int size)
4405 struct buffer *out = buf;
4406 struct rte_flow_action *action;
4407 struct action_nvgre_encap_data *action_nvgre_encap_data;
4410 ret = parse_vc(ctx, token, str, len, buf, size);
4413 /* Nothing else to do if there is no buffer. */
4416 if (!out->args.vc.actions_n)
4418 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4419 /* Point to selected object. */
4420 ctx->object = out->args.vc.data;
4421 ctx->objmask = NULL;
4422 /* Set up default configuration. */
4423 action_nvgre_encap_data = ctx->object;
4424 *action_nvgre_encap_data = (struct action_nvgre_encap_data){
4425 .conf = (struct rte_flow_action_nvgre_encap){
4426 .definition = action_nvgre_encap_data->items,
4430 .type = RTE_FLOW_ITEM_TYPE_ETH,
4431 .spec = &action_nvgre_encap_data->item_eth,
4432 .mask = &rte_flow_item_eth_mask,
4435 .type = RTE_FLOW_ITEM_TYPE_VLAN,
4436 .spec = &action_nvgre_encap_data->item_vlan,
4437 .mask = &rte_flow_item_vlan_mask,
4440 .type = RTE_FLOW_ITEM_TYPE_IPV4,
4441 .spec = &action_nvgre_encap_data->item_ipv4,
4442 .mask = &rte_flow_item_ipv4_mask,
4445 .type = RTE_FLOW_ITEM_TYPE_NVGRE,
4446 .spec = &action_nvgre_encap_data->item_nvgre,
4447 .mask = &rte_flow_item_nvgre_mask,
4450 .type = RTE_FLOW_ITEM_TYPE_END,
4455 .tci = nvgre_encap_conf.vlan_tci,
4459 .src_addr = nvgre_encap_conf.ipv4_src,
4460 .dst_addr = nvgre_encap_conf.ipv4_dst,
4462 .item_nvgre.flow_id = 0,
4464 memcpy(action_nvgre_encap_data->item_eth.dst.addr_bytes,
4465 nvgre_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
4466 memcpy(action_nvgre_encap_data->item_eth.src.addr_bytes,
4467 nvgre_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
4468 if (!nvgre_encap_conf.select_ipv4) {
4469 memcpy(&action_nvgre_encap_data->item_ipv6.hdr.src_addr,
4470 &nvgre_encap_conf.ipv6_src,
4471 sizeof(nvgre_encap_conf.ipv6_src));
4472 memcpy(&action_nvgre_encap_data->item_ipv6.hdr.dst_addr,
4473 &nvgre_encap_conf.ipv6_dst,
4474 sizeof(nvgre_encap_conf.ipv6_dst));
4475 action_nvgre_encap_data->items[2] = (struct rte_flow_item){
4476 .type = RTE_FLOW_ITEM_TYPE_IPV6,
4477 .spec = &action_nvgre_encap_data->item_ipv6,
4478 .mask = &rte_flow_item_ipv6_mask,
4481 if (!nvgre_encap_conf.select_vlan)
4482 action_nvgre_encap_data->items[1].type =
4483 RTE_FLOW_ITEM_TYPE_VOID;
4484 memcpy(action_nvgre_encap_data->item_nvgre.tni, nvgre_encap_conf.tni,
4485 RTE_DIM(nvgre_encap_conf.tni));
4486 action->conf = &action_nvgre_encap_data->conf;
4490 /** Parse l2 encap action. */
4492 parse_vc_action_l2_encap(struct context *ctx, const struct token *token,
4493 const char *str, unsigned int len,
4494 void *buf, unsigned int size)
4496 struct buffer *out = buf;
4497 struct rte_flow_action *action;
4498 struct action_raw_encap_data *action_encap_data;
4499 struct rte_flow_item_eth eth = { .type = 0, };
4500 struct rte_flow_item_vlan vlan = {
4501 .tci = mplsoudp_encap_conf.vlan_tci,
4507 ret = parse_vc(ctx, token, str, len, buf, size);
4510 /* Nothing else to do if there is no buffer. */
4513 if (!out->args.vc.actions_n)
4515 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4516 /* Point to selected object. */
4517 ctx->object = out->args.vc.data;
4518 ctx->objmask = NULL;
4519 /* Copy the headers to the buffer. */
4520 action_encap_data = ctx->object;
4521 *action_encap_data = (struct action_raw_encap_data) {
4522 .conf = (struct rte_flow_action_raw_encap){
4523 .data = action_encap_data->data,
4527 header = action_encap_data->data;
4528 if (l2_encap_conf.select_vlan)
4529 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
4530 else if (l2_encap_conf.select_ipv4)
4531 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4533 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4534 memcpy(eth.dst.addr_bytes,
4535 l2_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
4536 memcpy(eth.src.addr_bytes,
4537 l2_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
4538 memcpy(header, ð, sizeof(eth));
4539 header += sizeof(eth);
4540 if (l2_encap_conf.select_vlan) {
4541 if (l2_encap_conf.select_ipv4)
4542 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4544 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4545 memcpy(header, &vlan, sizeof(vlan));
4546 header += sizeof(vlan);
4548 action_encap_data->conf.size = header -
4549 action_encap_data->data;
4550 action->conf = &action_encap_data->conf;
4554 /** Parse l2 decap action. */
4556 parse_vc_action_l2_decap(struct context *ctx, const struct token *token,
4557 const char *str, unsigned int len,
4558 void *buf, unsigned int size)
4560 struct buffer *out = buf;
4561 struct rte_flow_action *action;
4562 struct action_raw_decap_data *action_decap_data;
4563 struct rte_flow_item_eth eth = { .type = 0, };
4564 struct rte_flow_item_vlan vlan = {
4565 .tci = mplsoudp_encap_conf.vlan_tci,
4571 ret = parse_vc(ctx, token, str, len, buf, size);
4574 /* Nothing else to do if there is no buffer. */
4577 if (!out->args.vc.actions_n)
4579 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4580 /* Point to selected object. */
4581 ctx->object = out->args.vc.data;
4582 ctx->objmask = NULL;
4583 /* Copy the headers to the buffer. */
4584 action_decap_data = ctx->object;
4585 *action_decap_data = (struct action_raw_decap_data) {
4586 .conf = (struct rte_flow_action_raw_decap){
4587 .data = action_decap_data->data,
4591 header = action_decap_data->data;
4592 if (l2_decap_conf.select_vlan)
4593 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
4594 memcpy(header, ð, sizeof(eth));
4595 header += sizeof(eth);
4596 if (l2_decap_conf.select_vlan) {
4597 memcpy(header, &vlan, sizeof(vlan));
4598 header += sizeof(vlan);
4600 action_decap_data->conf.size = header -
4601 action_decap_data->data;
4602 action->conf = &action_decap_data->conf;
4606 #define ETHER_TYPE_MPLS_UNICAST 0x8847
4608 /** Parse MPLSOGRE encap action. */
4610 parse_vc_action_mplsogre_encap(struct context *ctx, const struct token *token,
4611 const char *str, unsigned int len,
4612 void *buf, unsigned int size)
4614 struct buffer *out = buf;
4615 struct rte_flow_action *action;
4616 struct action_raw_encap_data *action_encap_data;
4617 struct rte_flow_item_eth eth = { .type = 0, };
4618 struct rte_flow_item_vlan vlan = {
4619 .tci = mplsogre_encap_conf.vlan_tci,
4622 struct rte_flow_item_ipv4 ipv4 = {
4624 .src_addr = mplsogre_encap_conf.ipv4_src,
4625 .dst_addr = mplsogre_encap_conf.ipv4_dst,
4626 .next_proto_id = IPPROTO_GRE,
4627 .version_ihl = RTE_IPV4_VHL_DEF,
4628 .time_to_live = IPDEFTTL,
4631 struct rte_flow_item_ipv6 ipv6 = {
4633 .proto = IPPROTO_GRE,
4634 .hop_limits = IPDEFTTL,
4637 struct rte_flow_item_gre gre = {
4638 .protocol = rte_cpu_to_be_16(ETHER_TYPE_MPLS_UNICAST),
4640 struct rte_flow_item_mpls mpls = {
4646 ret = parse_vc(ctx, token, str, len, buf, size);
4649 /* Nothing else to do if there is no buffer. */
4652 if (!out->args.vc.actions_n)
4654 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4655 /* Point to selected object. */
4656 ctx->object = out->args.vc.data;
4657 ctx->objmask = NULL;
4658 /* Copy the headers to the buffer. */
4659 action_encap_data = ctx->object;
4660 *action_encap_data = (struct action_raw_encap_data) {
4661 .conf = (struct rte_flow_action_raw_encap){
4662 .data = action_encap_data->data,
4667 header = action_encap_data->data;
4668 if (mplsogre_encap_conf.select_vlan)
4669 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
4670 else if (mplsogre_encap_conf.select_ipv4)
4671 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4673 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4674 memcpy(eth.dst.addr_bytes,
4675 mplsogre_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
4676 memcpy(eth.src.addr_bytes,
4677 mplsogre_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
4678 memcpy(header, ð, sizeof(eth));
4679 header += sizeof(eth);
4680 if (mplsogre_encap_conf.select_vlan) {
4681 if (mplsogre_encap_conf.select_ipv4)
4682 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4684 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4685 memcpy(header, &vlan, sizeof(vlan));
4686 header += sizeof(vlan);
4688 if (mplsogre_encap_conf.select_ipv4) {
4689 memcpy(header, &ipv4, sizeof(ipv4));
4690 header += sizeof(ipv4);
4692 memcpy(&ipv6.hdr.src_addr,
4693 &mplsogre_encap_conf.ipv6_src,
4694 sizeof(mplsogre_encap_conf.ipv6_src));
4695 memcpy(&ipv6.hdr.dst_addr,
4696 &mplsogre_encap_conf.ipv6_dst,
4697 sizeof(mplsogre_encap_conf.ipv6_dst));
4698 memcpy(header, &ipv6, sizeof(ipv6));
4699 header += sizeof(ipv6);
4701 memcpy(header, &gre, sizeof(gre));
4702 header += sizeof(gre);
4703 memcpy(mpls.label_tc_s, mplsogre_encap_conf.label,
4704 RTE_DIM(mplsogre_encap_conf.label));
4705 mpls.label_tc_s[2] |= 0x1;
4706 memcpy(header, &mpls, sizeof(mpls));
4707 header += sizeof(mpls);
4708 action_encap_data->conf.size = header -
4709 action_encap_data->data;
4710 action->conf = &action_encap_data->conf;
4714 /** Parse MPLSOGRE decap action. */
4716 parse_vc_action_mplsogre_decap(struct context *ctx, const struct token *token,
4717 const char *str, unsigned int len,
4718 void *buf, unsigned int size)
4720 struct buffer *out = buf;
4721 struct rte_flow_action *action;
4722 struct action_raw_decap_data *action_decap_data;
4723 struct rte_flow_item_eth eth = { .type = 0, };
4724 struct rte_flow_item_vlan vlan = {.tci = 0};
4725 struct rte_flow_item_ipv4 ipv4 = {
4727 .next_proto_id = IPPROTO_GRE,
4730 struct rte_flow_item_ipv6 ipv6 = {
4732 .proto = IPPROTO_GRE,
4735 struct rte_flow_item_gre gre = {
4736 .protocol = rte_cpu_to_be_16(ETHER_TYPE_MPLS_UNICAST),
4738 struct rte_flow_item_mpls mpls;
4742 ret = parse_vc(ctx, token, str, len, buf, size);
4745 /* Nothing else to do if there is no buffer. */
4748 if (!out->args.vc.actions_n)
4750 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4751 /* Point to selected object. */
4752 ctx->object = out->args.vc.data;
4753 ctx->objmask = NULL;
4754 /* Copy the headers to the buffer. */
4755 action_decap_data = ctx->object;
4756 *action_decap_data = (struct action_raw_decap_data) {
4757 .conf = (struct rte_flow_action_raw_decap){
4758 .data = action_decap_data->data,
4762 header = action_decap_data->data;
4763 if (mplsogre_decap_conf.select_vlan)
4764 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
4765 else if (mplsogre_encap_conf.select_ipv4)
4766 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4768 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4769 memcpy(eth.dst.addr_bytes,
4770 mplsogre_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
4771 memcpy(eth.src.addr_bytes,
4772 mplsogre_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
4773 memcpy(header, ð, sizeof(eth));
4774 header += sizeof(eth);
4775 if (mplsogre_encap_conf.select_vlan) {
4776 if (mplsogre_encap_conf.select_ipv4)
4777 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4779 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4780 memcpy(header, &vlan, sizeof(vlan));
4781 header += sizeof(vlan);
4783 if (mplsogre_encap_conf.select_ipv4) {
4784 memcpy(header, &ipv4, sizeof(ipv4));
4785 header += sizeof(ipv4);
4787 memcpy(header, &ipv6, sizeof(ipv6));
4788 header += sizeof(ipv6);
4790 memcpy(header, &gre, sizeof(gre));
4791 header += sizeof(gre);
4792 memset(&mpls, 0, sizeof(mpls));
4793 memcpy(header, &mpls, sizeof(mpls));
4794 header += sizeof(mpls);
4795 action_decap_data->conf.size = header -
4796 action_decap_data->data;
4797 action->conf = &action_decap_data->conf;
4801 /** Parse MPLSOUDP encap action. */
4803 parse_vc_action_mplsoudp_encap(struct context *ctx, const struct token *token,
4804 const char *str, unsigned int len,
4805 void *buf, unsigned int size)
4807 struct buffer *out = buf;
4808 struct rte_flow_action *action;
4809 struct action_raw_encap_data *action_encap_data;
4810 struct rte_flow_item_eth eth = { .type = 0, };
4811 struct rte_flow_item_vlan vlan = {
4812 .tci = mplsoudp_encap_conf.vlan_tci,
4815 struct rte_flow_item_ipv4 ipv4 = {
4817 .src_addr = mplsoudp_encap_conf.ipv4_src,
4818 .dst_addr = mplsoudp_encap_conf.ipv4_dst,
4819 .next_proto_id = IPPROTO_UDP,
4820 .version_ihl = RTE_IPV4_VHL_DEF,
4821 .time_to_live = IPDEFTTL,
4824 struct rte_flow_item_ipv6 ipv6 = {
4826 .proto = IPPROTO_UDP,
4827 .hop_limits = IPDEFTTL,
4830 struct rte_flow_item_udp udp = {
4832 .src_port = mplsoudp_encap_conf.udp_src,
4833 .dst_port = mplsoudp_encap_conf.udp_dst,
4836 struct rte_flow_item_mpls mpls;
4840 ret = parse_vc(ctx, token, str, len, buf, size);
4843 /* Nothing else to do if there is no buffer. */
4846 if (!out->args.vc.actions_n)
4848 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4849 /* Point to selected object. */
4850 ctx->object = out->args.vc.data;
4851 ctx->objmask = NULL;
4852 /* Copy the headers to the buffer. */
4853 action_encap_data = ctx->object;
4854 *action_encap_data = (struct action_raw_encap_data) {
4855 .conf = (struct rte_flow_action_raw_encap){
4856 .data = action_encap_data->data,
4861 header = action_encap_data->data;
4862 if (mplsoudp_encap_conf.select_vlan)
4863 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
4864 else if (mplsoudp_encap_conf.select_ipv4)
4865 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4867 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4868 memcpy(eth.dst.addr_bytes,
4869 mplsoudp_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
4870 memcpy(eth.src.addr_bytes,
4871 mplsoudp_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
4872 memcpy(header, ð, sizeof(eth));
4873 header += sizeof(eth);
4874 if (mplsoudp_encap_conf.select_vlan) {
4875 if (mplsoudp_encap_conf.select_ipv4)
4876 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4878 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4879 memcpy(header, &vlan, sizeof(vlan));
4880 header += sizeof(vlan);
4882 if (mplsoudp_encap_conf.select_ipv4) {
4883 memcpy(header, &ipv4, sizeof(ipv4));
4884 header += sizeof(ipv4);
4886 memcpy(&ipv6.hdr.src_addr,
4887 &mplsoudp_encap_conf.ipv6_src,
4888 sizeof(mplsoudp_encap_conf.ipv6_src));
4889 memcpy(&ipv6.hdr.dst_addr,
4890 &mplsoudp_encap_conf.ipv6_dst,
4891 sizeof(mplsoudp_encap_conf.ipv6_dst));
4892 memcpy(header, &ipv6, sizeof(ipv6));
4893 header += sizeof(ipv6);
4895 memcpy(header, &udp, sizeof(udp));
4896 header += sizeof(udp);
4897 memcpy(mpls.label_tc_s, mplsoudp_encap_conf.label,
4898 RTE_DIM(mplsoudp_encap_conf.label));
4899 mpls.label_tc_s[2] |= 0x1;
4900 memcpy(header, &mpls, sizeof(mpls));
4901 header += sizeof(mpls);
4902 action_encap_data->conf.size = header -
4903 action_encap_data->data;
4904 action->conf = &action_encap_data->conf;
4908 /** Parse MPLSOUDP decap action. */
4910 parse_vc_action_mplsoudp_decap(struct context *ctx, const struct token *token,
4911 const char *str, unsigned int len,
4912 void *buf, unsigned int size)
4914 struct buffer *out = buf;
4915 struct rte_flow_action *action;
4916 struct action_raw_decap_data *action_decap_data;
4917 struct rte_flow_item_eth eth = { .type = 0, };
4918 struct rte_flow_item_vlan vlan = {.tci = 0};
4919 struct rte_flow_item_ipv4 ipv4 = {
4921 .next_proto_id = IPPROTO_UDP,
4924 struct rte_flow_item_ipv6 ipv6 = {
4926 .proto = IPPROTO_UDP,
4929 struct rte_flow_item_udp udp = {
4931 .dst_port = rte_cpu_to_be_16(6635),
4934 struct rte_flow_item_mpls mpls;
4938 ret = parse_vc(ctx, token, str, len, buf, size);
4941 /* Nothing else to do if there is no buffer. */
4944 if (!out->args.vc.actions_n)
4946 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4947 /* Point to selected object. */
4948 ctx->object = out->args.vc.data;
4949 ctx->objmask = NULL;
4950 /* Copy the headers to the buffer. */
4951 action_decap_data = ctx->object;
4952 *action_decap_data = (struct action_raw_decap_data) {
4953 .conf = (struct rte_flow_action_raw_decap){
4954 .data = action_decap_data->data,
4958 header = action_decap_data->data;
4959 if (mplsoudp_decap_conf.select_vlan)
4960 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
4961 else if (mplsoudp_encap_conf.select_ipv4)
4962 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4964 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4965 memcpy(eth.dst.addr_bytes,
4966 mplsoudp_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
4967 memcpy(eth.src.addr_bytes,
4968 mplsoudp_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
4969 memcpy(header, ð, sizeof(eth));
4970 header += sizeof(eth);
4971 if (mplsoudp_encap_conf.select_vlan) {
4972 if (mplsoudp_encap_conf.select_ipv4)
4973 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4975 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4976 memcpy(header, &vlan, sizeof(vlan));
4977 header += sizeof(vlan);
4979 if (mplsoudp_encap_conf.select_ipv4) {
4980 memcpy(header, &ipv4, sizeof(ipv4));
4981 header += sizeof(ipv4);
4983 memcpy(header, &ipv6, sizeof(ipv6));
4984 header += sizeof(ipv6);
4986 memcpy(header, &udp, sizeof(udp));
4987 header += sizeof(udp);
4988 memset(&mpls, 0, sizeof(mpls));
4989 memcpy(header, &mpls, sizeof(mpls));
4990 header += sizeof(mpls);
4991 action_decap_data->conf.size = header -
4992 action_decap_data->data;
4993 action->conf = &action_decap_data->conf;
4998 parse_vc_action_raw_decap_index(struct context *ctx, const struct token *token,
4999 const char *str, unsigned int len, void *buf,
5002 struct action_raw_decap_data *action_raw_decap_data;
5003 struct rte_flow_action *action;
5004 const struct arg *arg;
5005 struct buffer *out = buf;
5009 RTE_SET_USED(token);
5012 arg = ARGS_ENTRY_ARB_BOUNDED
5013 (offsetof(struct action_raw_decap_data, idx),
5014 sizeof(((struct action_raw_decap_data *)0)->idx),
5015 0, RAW_ENCAP_CONFS_MAX_NUM - 1);
5016 if (push_args(ctx, arg))
5018 ret = parse_int(ctx, token, str, len, NULL, 0);
5025 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
5026 action_raw_decap_data = ctx->object;
5027 idx = action_raw_decap_data->idx;
5028 action_raw_decap_data->conf.data = raw_decap_confs[idx].data;
5029 action_raw_decap_data->conf.size = raw_decap_confs[idx].size;
5030 action->conf = &action_raw_decap_data->conf;
5036 parse_vc_action_raw_encap_index(struct context *ctx, const struct token *token,
5037 const char *str, unsigned int len, void *buf,
5040 struct action_raw_encap_data *action_raw_encap_data;
5041 struct rte_flow_action *action;
5042 const struct arg *arg;
5043 struct buffer *out = buf;
5047 RTE_SET_USED(token);
5050 if (ctx->curr != ACTION_RAW_ENCAP_INDEX_VALUE)
5052 arg = ARGS_ENTRY_ARB_BOUNDED
5053 (offsetof(struct action_raw_encap_data, idx),
5054 sizeof(((struct action_raw_encap_data *)0)->idx),
5055 0, RAW_ENCAP_CONFS_MAX_NUM - 1);
5056 if (push_args(ctx, arg))
5058 ret = parse_int(ctx, token, str, len, NULL, 0);
5065 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
5066 action_raw_encap_data = ctx->object;
5067 idx = action_raw_encap_data->idx;
5068 action_raw_encap_data->conf.data = raw_encap_confs[idx].data;
5069 action_raw_encap_data->conf.size = raw_encap_confs[idx].size;
5070 action_raw_encap_data->conf.preserve = NULL;
5071 action->conf = &action_raw_encap_data->conf;
5076 parse_vc_action_raw_encap(struct context *ctx, const struct token *token,
5077 const char *str, unsigned int len, void *buf,
5080 struct buffer *out = buf;
5081 struct rte_flow_action *action;
5082 struct action_raw_encap_data *action_raw_encap_data = NULL;
5085 ret = parse_vc(ctx, token, str, len, buf, size);
5088 /* Nothing else to do if there is no buffer. */
5091 if (!out->args.vc.actions_n)
5093 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
5094 /* Point to selected object. */
5095 ctx->object = out->args.vc.data;
5096 ctx->objmask = NULL;
5097 /* Copy the headers to the buffer. */
5098 action_raw_encap_data = ctx->object;
5099 action_raw_encap_data->conf.data = raw_encap_confs[0].data;
5100 action_raw_encap_data->conf.preserve = NULL;
5101 action_raw_encap_data->conf.size = raw_encap_confs[0].size;
5102 action->conf = &action_raw_encap_data->conf;
5107 parse_vc_action_raw_decap(struct context *ctx, const struct token *token,
5108 const char *str, unsigned int len, void *buf,
5111 struct buffer *out = buf;
5112 struct rte_flow_action *action;
5113 struct action_raw_decap_data *action_raw_decap_data = NULL;
5116 ret = parse_vc(ctx, token, str, len, buf, size);
5119 /* Nothing else to do if there is no buffer. */
5122 if (!out->args.vc.actions_n)
5124 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
5125 /* Point to selected object. */
5126 ctx->object = out->args.vc.data;
5127 ctx->objmask = NULL;
5128 /* Copy the headers to the buffer. */
5129 action_raw_decap_data = ctx->object;
5130 action_raw_decap_data->conf.data = raw_decap_confs[0].data;
5131 action_raw_decap_data->conf.size = raw_decap_confs[0].size;
5132 action->conf = &action_raw_decap_data->conf;
5137 parse_vc_action_set_meta(struct context *ctx, const struct token *token,
5138 const char *str, unsigned int len, void *buf,
5143 ret = parse_vc(ctx, token, str, len, buf, size);
5146 ret = rte_flow_dynf_metadata_register();
5152 /** Parse tokens for destroy command. */
5154 parse_destroy(struct context *ctx, const struct token *token,
5155 const char *str, unsigned int len,
5156 void *buf, unsigned int size)
5158 struct buffer *out = buf;
5160 /* Token name must match. */
5161 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5163 /* Nothing else to do if there is no buffer. */
5166 if (!out->command) {
5167 if (ctx->curr != DESTROY)
5169 if (sizeof(*out) > size)
5171 out->command = ctx->curr;
5174 ctx->objmask = NULL;
5175 out->args.destroy.rule =
5176 (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
5180 if (((uint8_t *)(out->args.destroy.rule + out->args.destroy.rule_n) +
5181 sizeof(*out->args.destroy.rule)) > (uint8_t *)out + size)
5184 ctx->object = out->args.destroy.rule + out->args.destroy.rule_n++;
5185 ctx->objmask = NULL;
5189 /** Parse tokens for flush command. */
5191 parse_flush(struct context *ctx, const struct token *token,
5192 const char *str, unsigned int len,
5193 void *buf, unsigned int size)
5195 struct buffer *out = buf;
5197 /* Token name must match. */
5198 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5200 /* Nothing else to do if there is no buffer. */
5203 if (!out->command) {
5204 if (ctx->curr != FLUSH)
5206 if (sizeof(*out) > size)
5208 out->command = ctx->curr;
5211 ctx->objmask = NULL;
5216 /** Parse tokens for dump command. */
5218 parse_dump(struct context *ctx, const struct token *token,
5219 const char *str, unsigned int len,
5220 void *buf, unsigned int size)
5222 struct buffer *out = buf;
5224 /* Token name must match. */
5225 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5227 /* Nothing else to do if there is no buffer. */
5230 if (!out->command) {
5231 if (ctx->curr != DUMP)
5233 if (sizeof(*out) > size)
5235 out->command = ctx->curr;
5238 ctx->objmask = NULL;
5243 /** Parse tokens for query command. */
5245 parse_query(struct context *ctx, const struct token *token,
5246 const char *str, unsigned int len,
5247 void *buf, unsigned int size)
5249 struct buffer *out = buf;
5251 /* Token name must match. */
5252 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5254 /* Nothing else to do if there is no buffer. */
5257 if (!out->command) {
5258 if (ctx->curr != QUERY)
5260 if (sizeof(*out) > size)
5262 out->command = ctx->curr;
5265 ctx->objmask = NULL;
5270 /** Parse action names. */
5272 parse_action(struct context *ctx, const struct token *token,
5273 const char *str, unsigned int len,
5274 void *buf, unsigned int size)
5276 struct buffer *out = buf;
5277 const struct arg *arg = pop_args(ctx);
5281 /* Argument is expected. */
5284 /* Parse action name. */
5285 for (i = 0; next_action[i]; ++i) {
5286 const struct parse_action_priv *priv;
5288 token = &token_list[next_action[i]];
5289 if (strcmp_partial(token->name, str, len))
5295 memcpy((uint8_t *)ctx->object + arg->offset,
5301 push_args(ctx, arg);
5305 /** Parse tokens for list command. */
5307 parse_list(struct context *ctx, const struct token *token,
5308 const char *str, unsigned int len,
5309 void *buf, unsigned int size)
5311 struct buffer *out = buf;
5313 /* Token name must match. */
5314 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5316 /* Nothing else to do if there is no buffer. */
5319 if (!out->command) {
5320 if (ctx->curr != LIST)
5322 if (sizeof(*out) > size)
5324 out->command = ctx->curr;
5327 ctx->objmask = NULL;
5328 out->args.list.group =
5329 (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
5333 if (((uint8_t *)(out->args.list.group + out->args.list.group_n) +
5334 sizeof(*out->args.list.group)) > (uint8_t *)out + size)
5337 ctx->object = out->args.list.group + out->args.list.group_n++;
5338 ctx->objmask = NULL;
5342 /** Parse tokens for isolate command. */
5344 parse_isolate(struct context *ctx, const struct token *token,
5345 const char *str, unsigned int len,
5346 void *buf, unsigned int size)
5348 struct buffer *out = buf;
5350 /* Token name must match. */
5351 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5353 /* Nothing else to do if there is no buffer. */
5356 if (!out->command) {
5357 if (ctx->curr != ISOLATE)
5359 if (sizeof(*out) > size)
5361 out->command = ctx->curr;
5364 ctx->objmask = NULL;
5370 * Parse signed/unsigned integers 8 to 64-bit long.
5372 * Last argument (ctx->args) is retrieved to determine integer type and
5376 parse_int(struct context *ctx, const struct token *token,
5377 const char *str, unsigned int len,
5378 void *buf, unsigned int size)
5380 const struct arg *arg = pop_args(ctx);
5385 /* Argument is expected. */
5390 (uintmax_t)strtoimax(str, &end, 0) :
5391 strtoumax(str, &end, 0);
5392 if (errno || (size_t)(end - str) != len)
5395 ((arg->sign && ((intmax_t)u < (intmax_t)arg->min ||
5396 (intmax_t)u > (intmax_t)arg->max)) ||
5397 (!arg->sign && (u < arg->min || u > arg->max))))
5402 if (!arg_entry_bf_fill(ctx->object, u, arg) ||
5403 !arg_entry_bf_fill(ctx->objmask, -1, arg))
5407 buf = (uint8_t *)ctx->object + arg->offset;
5409 if (u > RTE_LEN2MASK(size * CHAR_BIT, uint64_t))
5413 case sizeof(uint8_t):
5414 *(uint8_t *)buf = u;
5416 case sizeof(uint16_t):
5417 *(uint16_t *)buf = arg->hton ? rte_cpu_to_be_16(u) : u;
5419 case sizeof(uint8_t [3]):
5420 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
5422 ((uint8_t *)buf)[0] = u;
5423 ((uint8_t *)buf)[1] = u >> 8;
5424 ((uint8_t *)buf)[2] = u >> 16;
5428 ((uint8_t *)buf)[0] = u >> 16;
5429 ((uint8_t *)buf)[1] = u >> 8;
5430 ((uint8_t *)buf)[2] = u;
5432 case sizeof(uint32_t):
5433 *(uint32_t *)buf = arg->hton ? rte_cpu_to_be_32(u) : u;
5435 case sizeof(uint64_t):
5436 *(uint64_t *)buf = arg->hton ? rte_cpu_to_be_64(u) : u;
5441 if (ctx->objmask && buf != (uint8_t *)ctx->objmask + arg->offset) {
5443 buf = (uint8_t *)ctx->objmask + arg->offset;
5448 push_args(ctx, arg);
5455 * Three arguments (ctx->args) are retrieved from the stack to store data,
5456 * its actual length and address (in that order).
5459 parse_string(struct context *ctx, const struct token *token,
5460 const char *str, unsigned int len,
5461 void *buf, unsigned int size)
5463 const struct arg *arg_data = pop_args(ctx);
5464 const struct arg *arg_len = pop_args(ctx);
5465 const struct arg *arg_addr = pop_args(ctx);
5466 char tmp[16]; /* Ought to be enough. */
5469 /* Arguments are expected. */
5473 push_args(ctx, arg_data);
5477 push_args(ctx, arg_len);
5478 push_args(ctx, arg_data);
5481 size = arg_data->size;
5482 /* Bit-mask fill is not supported. */
5483 if (arg_data->mask || size < len)
5487 /* Let parse_int() fill length information first. */
5488 ret = snprintf(tmp, sizeof(tmp), "%u", len);
5491 push_args(ctx, arg_len);
5492 ret = parse_int(ctx, token, tmp, ret, NULL, 0);
5497 buf = (uint8_t *)ctx->object + arg_data->offset;
5498 /* Output buffer is not necessarily NUL-terminated. */
5499 memcpy(buf, str, len);
5500 memset((uint8_t *)buf + len, 0x00, size - len);
5502 memset((uint8_t *)ctx->objmask + arg_data->offset, 0xff, len);
5503 /* Save address if requested. */
5504 if (arg_addr->size) {
5505 memcpy((uint8_t *)ctx->object + arg_addr->offset,
5507 (uint8_t *)ctx->object + arg_data->offset
5511 memcpy((uint8_t *)ctx->objmask + arg_addr->offset,
5513 (uint8_t *)ctx->objmask + arg_data->offset
5519 push_args(ctx, arg_addr);
5520 push_args(ctx, arg_len);
5521 push_args(ctx, arg_data);
5526 parse_hex_string(const char *src, uint8_t *dst, uint32_t *size)
5532 /* Check input parameters */
5533 if ((src == NULL) ||
5539 /* Convert chars to bytes */
5540 for (i = 0, len = 0; i < *size; i += 2) {
5541 snprintf(tmp, 3, "%s", src + i);
5542 dst[len++] = strtoul(tmp, &c, 16);
5557 parse_hex(struct context *ctx, const struct token *token,
5558 const char *str, unsigned int len,
5559 void *buf, unsigned int size)
5561 const struct arg *arg_data = pop_args(ctx);
5562 const struct arg *arg_len = pop_args(ctx);
5563 const struct arg *arg_addr = pop_args(ctx);
5564 char tmp[16]; /* Ought to be enough. */
5566 unsigned int hexlen = len;
5567 unsigned int length = 256;
5568 uint8_t hex_tmp[length];
5570 /* Arguments are expected. */
5574 push_args(ctx, arg_data);
5578 push_args(ctx, arg_len);
5579 push_args(ctx, arg_data);
5582 size = arg_data->size;
5583 /* Bit-mask fill is not supported. */
5589 /* translate bytes string to array. */
5590 if (str[0] == '0' && ((str[1] == 'x') ||
5595 if (hexlen > length)
5597 ret = parse_hex_string(str, hex_tmp, &hexlen);
5600 /* Let parse_int() fill length information first. */
5601 ret = snprintf(tmp, sizeof(tmp), "%u", hexlen);
5604 push_args(ctx, arg_len);
5605 ret = parse_int(ctx, token, tmp, ret, NULL, 0);
5610 buf = (uint8_t *)ctx->object + arg_data->offset;
5611 /* Output buffer is not necessarily NUL-terminated. */
5612 memcpy(buf, hex_tmp, hexlen);
5613 memset((uint8_t *)buf + hexlen, 0x00, size - hexlen);
5615 memset((uint8_t *)ctx->objmask + arg_data->offset,
5617 /* Save address if requested. */
5618 if (arg_addr->size) {
5619 memcpy((uint8_t *)ctx->object + arg_addr->offset,
5621 (uint8_t *)ctx->object + arg_data->offset
5625 memcpy((uint8_t *)ctx->objmask + arg_addr->offset,
5627 (uint8_t *)ctx->objmask + arg_data->offset
5633 push_args(ctx, arg_addr);
5634 push_args(ctx, arg_len);
5635 push_args(ctx, arg_data);
5641 * Parse a zero-ended string.
5644 parse_string0(struct context *ctx, const struct token *token __rte_unused,
5645 const char *str, unsigned int len,
5646 void *buf, unsigned int size)
5648 const struct arg *arg_data = pop_args(ctx);
5650 /* Arguments are expected. */
5653 size = arg_data->size;
5654 /* Bit-mask fill is not supported. */
5655 if (arg_data->mask || size < len + 1)
5659 buf = (uint8_t *)ctx->object + arg_data->offset;
5660 strncpy(buf, str, len);
5662 memset((uint8_t *)ctx->objmask + arg_data->offset, 0xff, len);
5665 push_args(ctx, arg_data);
5670 * Parse a MAC address.
5672 * Last argument (ctx->args) is retrieved to determine storage size and
5676 parse_mac_addr(struct context *ctx, const struct token *token,
5677 const char *str, unsigned int len,
5678 void *buf, unsigned int size)
5680 const struct arg *arg = pop_args(ctx);
5681 struct rte_ether_addr tmp;
5685 /* Argument is expected. */
5689 /* Bit-mask fill is not supported. */
5690 if (arg->mask || size != sizeof(tmp))
5692 /* Only network endian is supported. */
5695 ret = cmdline_parse_etheraddr(NULL, str, &tmp, size);
5696 if (ret < 0 || (unsigned int)ret != len)
5700 buf = (uint8_t *)ctx->object + arg->offset;
5701 memcpy(buf, &tmp, size);
5703 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
5706 push_args(ctx, arg);
5711 * Parse an IPv4 address.
5713 * Last argument (ctx->args) is retrieved to determine storage size and
5717 parse_ipv4_addr(struct context *ctx, const struct token *token,
5718 const char *str, unsigned int len,
5719 void *buf, unsigned int size)
5721 const struct arg *arg = pop_args(ctx);
5726 /* Argument is expected. */
5730 /* Bit-mask fill is not supported. */
5731 if (arg->mask || size != sizeof(tmp))
5733 /* Only network endian is supported. */
5736 memcpy(str2, str, len);
5738 ret = inet_pton(AF_INET, str2, &tmp);
5740 /* Attempt integer parsing. */
5741 push_args(ctx, arg);
5742 return parse_int(ctx, token, str, len, buf, size);
5746 buf = (uint8_t *)ctx->object + arg->offset;
5747 memcpy(buf, &tmp, size);
5749 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
5752 push_args(ctx, arg);
5757 * Parse an IPv6 address.
5759 * Last argument (ctx->args) is retrieved to determine storage size and
5763 parse_ipv6_addr(struct context *ctx, const struct token *token,
5764 const char *str, unsigned int len,
5765 void *buf, unsigned int size)
5767 const struct arg *arg = pop_args(ctx);
5769 struct in6_addr tmp;
5773 /* Argument is expected. */
5777 /* Bit-mask fill is not supported. */
5778 if (arg->mask || size != sizeof(tmp))
5780 /* Only network endian is supported. */
5783 memcpy(str2, str, len);
5785 ret = inet_pton(AF_INET6, str2, &tmp);
5790 buf = (uint8_t *)ctx->object + arg->offset;
5791 memcpy(buf, &tmp, size);
5793 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
5796 push_args(ctx, arg);
5800 /** Boolean values (even indices stand for false). */
5801 static const char *const boolean_name[] = {
5811 * Parse a boolean value.
5813 * Last argument (ctx->args) is retrieved to determine storage size and
5817 parse_boolean(struct context *ctx, const struct token *token,
5818 const char *str, unsigned int len,
5819 void *buf, unsigned int size)
5821 const struct arg *arg = pop_args(ctx);
5825 /* Argument is expected. */
5828 for (i = 0; boolean_name[i]; ++i)
5829 if (!strcmp_partial(boolean_name[i], str, len))
5831 /* Process token as integer. */
5832 if (boolean_name[i])
5833 str = i & 1 ? "1" : "0";
5834 push_args(ctx, arg);
5835 ret = parse_int(ctx, token, str, strlen(str), buf, size);
5836 return ret > 0 ? (int)len : ret;
5839 /** Parse port and update context. */
5841 parse_port(struct context *ctx, const struct token *token,
5842 const char *str, unsigned int len,
5843 void *buf, unsigned int size)
5845 struct buffer *out = &(struct buffer){ .port = 0 };
5853 ctx->objmask = NULL;
5854 size = sizeof(*out);
5856 ret = parse_int(ctx, token, str, len, out, size);
5858 ctx->port = out->port;
5864 /** Parse set command, initialize output buffer for subsequent tokens. */
5866 parse_set_raw_encap_decap(struct context *ctx, const struct token *token,
5867 const char *str, unsigned int len,
5868 void *buf, unsigned int size)
5870 struct buffer *out = buf;
5872 /* Token name must match. */
5873 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5875 /* Nothing else to do if there is no buffer. */
5878 /* Make sure buffer is large enough. */
5879 if (size < sizeof(*out))
5882 ctx->objmask = NULL;
5886 out->command = ctx->curr;
5891 * Parse set raw_encap/raw_decap command,
5892 * initialize output buffer for subsequent tokens.
5895 parse_set_init(struct context *ctx, const struct token *token,
5896 const char *str, unsigned int len,
5897 void *buf, unsigned int size)
5899 struct buffer *out = buf;
5901 /* Token name must match. */
5902 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5904 /* Nothing else to do if there is no buffer. */
5907 /* Make sure buffer is large enough. */
5908 if (size < sizeof(*out))
5910 /* Initialize buffer. */
5911 memset(out, 0x00, sizeof(*out));
5912 memset((uint8_t *)out + sizeof(*out), 0x22, size - sizeof(*out));
5915 ctx->objmask = NULL;
5916 if (!out->command) {
5917 if (ctx->curr != SET)
5919 if (sizeof(*out) > size)
5921 out->command = ctx->curr;
5922 out->args.vc.data = (uint8_t *)out + size;
5923 /* All we need is pattern */
5924 out->args.vc.pattern =
5925 (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
5927 ctx->object = out->args.vc.pattern;
5932 /** No completion. */
5934 comp_none(struct context *ctx, const struct token *token,
5935 unsigned int ent, char *buf, unsigned int size)
5945 /** Complete boolean values. */
5947 comp_boolean(struct context *ctx, const struct token *token,
5948 unsigned int ent, char *buf, unsigned int size)
5954 for (i = 0; boolean_name[i]; ++i)
5955 if (buf && i == ent)
5956 return strlcpy(buf, boolean_name[i], size);
5962 /** Complete action names. */
5964 comp_action(struct context *ctx, const struct token *token,
5965 unsigned int ent, char *buf, unsigned int size)
5971 for (i = 0; next_action[i]; ++i)
5972 if (buf && i == ent)
5973 return strlcpy(buf, token_list[next_action[i]].name,
5980 /** Complete available ports. */
5982 comp_port(struct context *ctx, const struct token *token,
5983 unsigned int ent, char *buf, unsigned int size)
5990 RTE_ETH_FOREACH_DEV(p) {
5991 if (buf && i == ent)
5992 return snprintf(buf, size, "%u", p);
6000 /** Complete available rule IDs. */
6002 comp_rule_id(struct context *ctx, const struct token *token,
6003 unsigned int ent, char *buf, unsigned int size)
6006 struct rte_port *port;
6007 struct port_flow *pf;
6010 if (port_id_is_invalid(ctx->port, DISABLED_WARN) ||
6011 ctx->port == (portid_t)RTE_PORT_ALL)
6013 port = &ports[ctx->port];
6014 for (pf = port->flow_list; pf != NULL; pf = pf->next) {
6015 if (buf && i == ent)
6016 return snprintf(buf, size, "%u", pf->id);
6024 /** Complete type field for RSS action. */
6026 comp_vc_action_rss_type(struct context *ctx, const struct token *token,
6027 unsigned int ent, char *buf, unsigned int size)
6033 for (i = 0; rss_type_table[i].str; ++i)
6038 return strlcpy(buf, rss_type_table[ent].str, size);
6040 return snprintf(buf, size, "end");
6044 /** Complete queue field for RSS action. */
6046 comp_vc_action_rss_queue(struct context *ctx, const struct token *token,
6047 unsigned int ent, char *buf, unsigned int size)
6054 return snprintf(buf, size, "%u", ent);
6056 return snprintf(buf, size, "end");
6060 /** Complete index number for set raw_encap/raw_decap commands. */
6062 comp_set_raw_index(struct context *ctx, const struct token *token,
6063 unsigned int ent, char *buf, unsigned int size)
6069 RTE_SET_USED(token);
6070 for (idx = 0; idx < RAW_ENCAP_CONFS_MAX_NUM; ++idx) {
6071 if (buf && idx == ent)
6072 return snprintf(buf, size, "%u", idx);
6078 /** Internal context. */
6079 static struct context cmd_flow_context;
6081 /** Global parser instance (cmdline API). */
6082 cmdline_parse_inst_t cmd_flow;
6083 cmdline_parse_inst_t cmd_set_raw;
6085 /** Initialize context. */
6087 cmd_flow_context_init(struct context *ctx)
6089 /* A full memset() is not necessary. */
6099 ctx->objmask = NULL;
6102 /** Parse a token (cmdline API). */
6104 cmd_flow_parse(cmdline_parse_token_hdr_t *hdr, const char *src, void *result,
6107 struct context *ctx = &cmd_flow_context;
6108 const struct token *token;
6109 const enum index *list;
6114 token = &token_list[ctx->curr];
6115 /* Check argument length. */
6118 for (len = 0; src[len]; ++len)
6119 if (src[len] == '#' || isspace(src[len]))
6123 /* Last argument and EOL detection. */
6124 for (i = len; src[i]; ++i)
6125 if (src[i] == '#' || src[i] == '\r' || src[i] == '\n')
6127 else if (!isspace(src[i])) {
6132 if (src[i] == '\r' || src[i] == '\n') {
6136 /* Initialize context if necessary. */
6137 if (!ctx->next_num) {
6140 ctx->next[ctx->next_num++] = token->next[0];
6142 /* Process argument through candidates. */
6143 ctx->prev = ctx->curr;
6144 list = ctx->next[ctx->next_num - 1];
6145 for (i = 0; list[i]; ++i) {
6146 const struct token *next = &token_list[list[i]];
6149 ctx->curr = list[i];
6151 tmp = next->call(ctx, next, src, len, result, size);
6153 tmp = parse_default(ctx, next, src, len, result, size);
6154 if (tmp == -1 || tmp != len)
6162 /* Push subsequent tokens if any. */
6164 for (i = 0; token->next[i]; ++i) {
6165 if (ctx->next_num == RTE_DIM(ctx->next))
6167 ctx->next[ctx->next_num++] = token->next[i];
6169 /* Push arguments if any. */
6171 for (i = 0; token->args[i]; ++i) {
6172 if (ctx->args_num == RTE_DIM(ctx->args))
6174 ctx->args[ctx->args_num++] = token->args[i];
6179 /** Return number of completion entries (cmdline API). */
6181 cmd_flow_complete_get_nb(cmdline_parse_token_hdr_t *hdr)
6183 struct context *ctx = &cmd_flow_context;
6184 const struct token *token = &token_list[ctx->curr];
6185 const enum index *list;
6189 /* Count number of tokens in current list. */
6191 list = ctx->next[ctx->next_num - 1];
6193 list = token->next[0];
6194 for (i = 0; list[i]; ++i)
6199 * If there is a single token, use its completion callback, otherwise
6200 * return the number of entries.
6202 token = &token_list[list[0]];
6203 if (i == 1 && token->comp) {
6204 /* Save index for cmd_flow_get_help(). */
6205 ctx->prev = list[0];
6206 return token->comp(ctx, token, 0, NULL, 0);
6211 /** Return a completion entry (cmdline API). */
6213 cmd_flow_complete_get_elt(cmdline_parse_token_hdr_t *hdr, int index,
6214 char *dst, unsigned int size)
6216 struct context *ctx = &cmd_flow_context;
6217 const struct token *token = &token_list[ctx->curr];
6218 const enum index *list;
6222 /* Count number of tokens in current list. */
6224 list = ctx->next[ctx->next_num - 1];
6226 list = token->next[0];
6227 for (i = 0; list[i]; ++i)
6231 /* If there is a single token, use its completion callback. */
6232 token = &token_list[list[0]];
6233 if (i == 1 && token->comp) {
6234 /* Save index for cmd_flow_get_help(). */
6235 ctx->prev = list[0];
6236 return token->comp(ctx, token, index, dst, size) < 0 ? -1 : 0;
6238 /* Otherwise make sure the index is valid and use defaults. */
6241 token = &token_list[list[index]];
6242 strlcpy(dst, token->name, size);
6243 /* Save index for cmd_flow_get_help(). */
6244 ctx->prev = list[index];
6248 /** Populate help strings for current token (cmdline API). */
6250 cmd_flow_get_help(cmdline_parse_token_hdr_t *hdr, char *dst, unsigned int size)
6252 struct context *ctx = &cmd_flow_context;
6253 const struct token *token = &token_list[ctx->prev];
6258 /* Set token type and update global help with details. */
6259 strlcpy(dst, (token->type ? token->type : "TOKEN"), size);
6261 cmd_flow.help_str = token->help;
6263 cmd_flow.help_str = token->name;
6267 /** Token definition template (cmdline API). */
6268 static struct cmdline_token_hdr cmd_flow_token_hdr = {
6269 .ops = &(struct cmdline_token_ops){
6270 .parse = cmd_flow_parse,
6271 .complete_get_nb = cmd_flow_complete_get_nb,
6272 .complete_get_elt = cmd_flow_complete_get_elt,
6273 .get_help = cmd_flow_get_help,
6278 /** Populate the next dynamic token. */
6280 cmd_flow_tok(cmdline_parse_token_hdr_t **hdr,
6281 cmdline_parse_token_hdr_t **hdr_inst)
6283 struct context *ctx = &cmd_flow_context;
6285 /* Always reinitialize context before requesting the first token. */
6286 if (!(hdr_inst - cmd_flow.tokens))
6287 cmd_flow_context_init(ctx);
6288 /* Return NULL when no more tokens are expected. */
6289 if (!ctx->next_num && ctx->curr) {
6293 /* Determine if command should end here. */
6294 if (ctx->eol && ctx->last && ctx->next_num) {
6295 const enum index *list = ctx->next[ctx->next_num - 1];
6298 for (i = 0; list[i]; ++i) {
6305 *hdr = &cmd_flow_token_hdr;
6308 /** Dispatch parsed buffer to function calls. */
6310 cmd_flow_parsed(const struct buffer *in)
6312 switch (in->command) {
6314 port_flow_validate(in->port, &in->args.vc.attr,
6315 in->args.vc.pattern, in->args.vc.actions);
6318 port_flow_create(in->port, &in->args.vc.attr,
6319 in->args.vc.pattern, in->args.vc.actions);
6322 port_flow_destroy(in->port, in->args.destroy.rule_n,
6323 in->args.destroy.rule);
6326 port_flow_flush(in->port);
6329 port_flow_dump(in->port, in->args.dump.file);
6332 port_flow_query(in->port, in->args.query.rule,
6333 &in->args.query.action);
6336 port_flow_list(in->port, in->args.list.group_n,
6337 in->args.list.group);
6340 port_flow_isolate(in->port, in->args.isolate.set);
6347 /** Token generator and output processing callback (cmdline API). */
6349 cmd_flow_cb(void *arg0, struct cmdline *cl, void *arg2)
6352 cmd_flow_tok(arg0, arg2);
6354 cmd_flow_parsed(arg0);
6357 /** Global parser instance (cmdline API). */
6358 cmdline_parse_inst_t cmd_flow = {
6360 .data = NULL, /**< Unused. */
6361 .help_str = NULL, /**< Updated by cmd_flow_get_help(). */
6364 }, /**< Tokens are returned by cmd_flow_tok(). */
6367 /** set cmd facility. Reuse cmd flow's infrastructure as much as possible. */
6370 update_fields(uint8_t *buf, struct rte_flow_item *item, uint16_t next_proto)
6372 struct rte_flow_item_ipv4 *ipv4;
6373 struct rte_flow_item_eth *eth;
6374 struct rte_flow_item_ipv6 *ipv6;
6375 struct rte_flow_item_vxlan *vxlan;
6376 struct rte_flow_item_vxlan_gpe *gpe;
6377 struct rte_flow_item_nvgre *nvgre;
6378 uint32_t ipv6_vtc_flow;
6380 switch (item->type) {
6381 case RTE_FLOW_ITEM_TYPE_ETH:
6382 eth = (struct rte_flow_item_eth *)buf;
6384 eth->type = rte_cpu_to_be_16(next_proto);
6386 case RTE_FLOW_ITEM_TYPE_IPV4:
6387 ipv4 = (struct rte_flow_item_ipv4 *)buf;
6388 ipv4->hdr.version_ihl = 0x45;
6389 if (next_proto && ipv4->hdr.next_proto_id == 0)
6390 ipv4->hdr.next_proto_id = (uint8_t)next_proto;
6392 case RTE_FLOW_ITEM_TYPE_IPV6:
6393 ipv6 = (struct rte_flow_item_ipv6 *)buf;
6394 if (next_proto && ipv6->hdr.proto == 0)
6395 ipv6->hdr.proto = (uint8_t)next_proto;
6396 ipv6_vtc_flow = rte_be_to_cpu_32(ipv6->hdr.vtc_flow);
6397 ipv6_vtc_flow &= 0x0FFFFFFF; /*< reset version bits. */
6398 ipv6_vtc_flow |= 0x60000000; /*< set ipv6 version. */
6399 ipv6->hdr.vtc_flow = rte_cpu_to_be_32(ipv6_vtc_flow);
6401 case RTE_FLOW_ITEM_TYPE_VXLAN:
6402 vxlan = (struct rte_flow_item_vxlan *)buf;
6403 vxlan->flags = 0x08;
6405 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
6406 gpe = (struct rte_flow_item_vxlan_gpe *)buf;
6409 case RTE_FLOW_ITEM_TYPE_NVGRE:
6410 nvgre = (struct rte_flow_item_nvgre *)buf;
6411 nvgre->protocol = rte_cpu_to_be_16(0x6558);
6412 nvgre->c_k_s_rsvd0_ver = rte_cpu_to_be_16(0x2000);
6419 /** Helper of get item's default mask. */
6421 flow_item_default_mask(const struct rte_flow_item *item)
6423 const void *mask = NULL;
6424 static rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
6426 switch (item->type) {
6427 case RTE_FLOW_ITEM_TYPE_ANY:
6428 mask = &rte_flow_item_any_mask;
6430 case RTE_FLOW_ITEM_TYPE_VF:
6431 mask = &rte_flow_item_vf_mask;
6433 case RTE_FLOW_ITEM_TYPE_PORT_ID:
6434 mask = &rte_flow_item_port_id_mask;
6436 case RTE_FLOW_ITEM_TYPE_RAW:
6437 mask = &rte_flow_item_raw_mask;
6439 case RTE_FLOW_ITEM_TYPE_ETH:
6440 mask = &rte_flow_item_eth_mask;
6442 case RTE_FLOW_ITEM_TYPE_VLAN:
6443 mask = &rte_flow_item_vlan_mask;
6445 case RTE_FLOW_ITEM_TYPE_IPV4:
6446 mask = &rte_flow_item_ipv4_mask;
6448 case RTE_FLOW_ITEM_TYPE_IPV6:
6449 mask = &rte_flow_item_ipv6_mask;
6451 case RTE_FLOW_ITEM_TYPE_ICMP:
6452 mask = &rte_flow_item_icmp_mask;
6454 case RTE_FLOW_ITEM_TYPE_UDP:
6455 mask = &rte_flow_item_udp_mask;
6457 case RTE_FLOW_ITEM_TYPE_TCP:
6458 mask = &rte_flow_item_tcp_mask;
6460 case RTE_FLOW_ITEM_TYPE_SCTP:
6461 mask = &rte_flow_item_sctp_mask;
6463 case RTE_FLOW_ITEM_TYPE_VXLAN:
6464 mask = &rte_flow_item_vxlan_mask;
6466 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
6467 mask = &rte_flow_item_vxlan_gpe_mask;
6469 case RTE_FLOW_ITEM_TYPE_E_TAG:
6470 mask = &rte_flow_item_e_tag_mask;
6472 case RTE_FLOW_ITEM_TYPE_NVGRE:
6473 mask = &rte_flow_item_nvgre_mask;
6475 case RTE_FLOW_ITEM_TYPE_MPLS:
6476 mask = &rte_flow_item_mpls_mask;
6478 case RTE_FLOW_ITEM_TYPE_GRE:
6479 mask = &rte_flow_item_gre_mask;
6481 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
6482 mask = &gre_key_default_mask;
6484 case RTE_FLOW_ITEM_TYPE_META:
6485 mask = &rte_flow_item_meta_mask;
6487 case RTE_FLOW_ITEM_TYPE_FUZZY:
6488 mask = &rte_flow_item_fuzzy_mask;
6490 case RTE_FLOW_ITEM_TYPE_GTP:
6491 mask = &rte_flow_item_gtp_mask;
6493 case RTE_FLOW_ITEM_TYPE_GTP_PSC:
6494 mask = &rte_flow_item_gtp_psc_mask;
6496 case RTE_FLOW_ITEM_TYPE_GENEVE:
6497 mask = &rte_flow_item_geneve_mask;
6499 case RTE_FLOW_ITEM_TYPE_PPPOE_PROTO_ID:
6500 mask = &rte_flow_item_pppoe_proto_id_mask;
6502 case RTE_FLOW_ITEM_TYPE_L2TPV3OIP:
6503 mask = &rte_flow_item_l2tpv3oip_mask;
6505 case RTE_FLOW_ITEM_TYPE_ESP:
6506 mask = &rte_flow_item_esp_mask;
6508 case RTE_FLOW_ITEM_TYPE_AH:
6509 mask = &rte_flow_item_ah_mask;
6511 case RTE_FLOW_ITEM_TYPE_PFCP:
6512 mask = &rte_flow_item_pfcp_mask;
6522 /** Dispatch parsed buffer to function calls. */
6524 cmd_set_raw_parsed(const struct buffer *in)
6526 uint32_t n = in->args.vc.pattern_n;
6528 struct rte_flow_item *item = NULL;
6530 uint8_t *data = NULL;
6531 uint8_t *data_tail = NULL;
6532 size_t *total_size = NULL;
6533 uint16_t upper_layer = 0;
6535 uint16_t idx = in->port; /* We borrow port field as index */
6537 RTE_ASSERT(in->command == SET_RAW_ENCAP ||
6538 in->command == SET_RAW_DECAP);
6539 if (in->command == SET_RAW_ENCAP) {
6540 total_size = &raw_encap_confs[idx].size;
6541 data = (uint8_t *)&raw_encap_confs[idx].data;
6543 total_size = &raw_decap_confs[idx].size;
6544 data = (uint8_t *)&raw_decap_confs[idx].data;
6547 memset(data, 0x00, ACTION_RAW_ENCAP_MAX_DATA);
6548 /* process hdr from upper layer to low layer (L3/L4 -> L2). */
6549 data_tail = data + ACTION_RAW_ENCAP_MAX_DATA;
6550 for (i = n - 1 ; i >= 0; --i) {
6551 item = in->args.vc.pattern + i;
6552 if (item->spec == NULL)
6553 item->spec = flow_item_default_mask(item);
6554 switch (item->type) {
6555 case RTE_FLOW_ITEM_TYPE_ETH:
6556 size = sizeof(struct rte_flow_item_eth);
6558 case RTE_FLOW_ITEM_TYPE_VLAN:
6559 size = sizeof(struct rte_flow_item_vlan);
6560 proto = RTE_ETHER_TYPE_VLAN;
6562 case RTE_FLOW_ITEM_TYPE_IPV4:
6563 size = sizeof(struct rte_flow_item_ipv4);
6564 proto = RTE_ETHER_TYPE_IPV4;
6566 case RTE_FLOW_ITEM_TYPE_IPV6:
6567 size = sizeof(struct rte_flow_item_ipv6);
6568 proto = RTE_ETHER_TYPE_IPV6;
6570 case RTE_FLOW_ITEM_TYPE_UDP:
6571 size = sizeof(struct rte_flow_item_udp);
6574 case RTE_FLOW_ITEM_TYPE_TCP:
6575 size = sizeof(struct rte_flow_item_tcp);
6578 case RTE_FLOW_ITEM_TYPE_VXLAN:
6579 size = sizeof(struct rte_flow_item_vxlan);
6581 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
6582 size = sizeof(struct rte_flow_item_vxlan_gpe);
6584 case RTE_FLOW_ITEM_TYPE_GRE:
6585 size = sizeof(struct rte_flow_item_gre);
6588 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
6589 size = sizeof(rte_be32_t);
6592 case RTE_FLOW_ITEM_TYPE_MPLS:
6593 size = sizeof(struct rte_flow_item_mpls);
6596 case RTE_FLOW_ITEM_TYPE_NVGRE:
6597 size = sizeof(struct rte_flow_item_nvgre);
6600 case RTE_FLOW_ITEM_TYPE_GENEVE:
6601 size = sizeof(struct rte_flow_item_geneve);
6603 case RTE_FLOW_ITEM_TYPE_L2TPV3OIP:
6604 size = sizeof(struct rte_flow_item_l2tpv3oip);
6607 case RTE_FLOW_ITEM_TYPE_ESP:
6608 size = sizeof(struct rte_flow_item_esp);
6611 case RTE_FLOW_ITEM_TYPE_AH:
6612 size = sizeof(struct rte_flow_item_ah);
6615 case RTE_FLOW_ITEM_TYPE_GTP:
6616 size = sizeof(struct rte_flow_item_gtp);
6618 case RTE_FLOW_ITEM_TYPE_PFCP:
6619 size = sizeof(struct rte_flow_item_pfcp);
6622 printf("Error - Not supported item\n");
6624 memset(data, 0x00, ACTION_RAW_ENCAP_MAX_DATA);
6627 *total_size += size;
6628 rte_memcpy(data_tail - (*total_size), item->spec, size);
6629 /* update some fields which cannot be set by cmdline */
6630 update_fields((data_tail - (*total_size)), item,
6632 upper_layer = proto;
6634 if (verbose_level & 0x1)
6635 printf("total data size is %zu\n", (*total_size));
6636 RTE_ASSERT((*total_size) <= ACTION_RAW_ENCAP_MAX_DATA);
6637 memmove(data, (data_tail - (*total_size)), *total_size);
6640 /** Populate help strings for current token (cmdline API). */
6642 cmd_set_raw_get_help(cmdline_parse_token_hdr_t *hdr, char *dst,
6645 struct context *ctx = &cmd_flow_context;
6646 const struct token *token = &token_list[ctx->prev];
6651 /* Set token type and update global help with details. */
6652 snprintf(dst, size, "%s", (token->type ? token->type : "TOKEN"));
6654 cmd_set_raw.help_str = token->help;
6656 cmd_set_raw.help_str = token->name;
6660 /** Token definition template (cmdline API). */
6661 static struct cmdline_token_hdr cmd_set_raw_token_hdr = {
6662 .ops = &(struct cmdline_token_ops){
6663 .parse = cmd_flow_parse,
6664 .complete_get_nb = cmd_flow_complete_get_nb,
6665 .complete_get_elt = cmd_flow_complete_get_elt,
6666 .get_help = cmd_set_raw_get_help,
6671 /** Populate the next dynamic token. */
6673 cmd_set_raw_tok(cmdline_parse_token_hdr_t **hdr,
6674 cmdline_parse_token_hdr_t **hdr_inst)
6676 struct context *ctx = &cmd_flow_context;
6678 /* Always reinitialize context before requesting the first token. */
6679 if (!(hdr_inst - cmd_set_raw.tokens)) {
6680 cmd_flow_context_init(ctx);
6681 ctx->curr = START_SET;
6683 /* Return NULL when no more tokens are expected. */
6684 if (!ctx->next_num && (ctx->curr != START_SET)) {
6688 /* Determine if command should end here. */
6689 if (ctx->eol && ctx->last && ctx->next_num) {
6690 const enum index *list = ctx->next[ctx->next_num - 1];
6693 for (i = 0; list[i]; ++i) {
6700 *hdr = &cmd_set_raw_token_hdr;
6703 /** Token generator and output processing callback (cmdline API). */
6705 cmd_set_raw_cb(void *arg0, struct cmdline *cl, void *arg2)
6708 cmd_set_raw_tok(arg0, arg2);
6710 cmd_set_raw_parsed(arg0);
6713 /** Global parser instance (cmdline API). */
6714 cmdline_parse_inst_t cmd_set_raw = {
6715 .f = cmd_set_raw_cb,
6716 .data = NULL, /**< Unused. */
6717 .help_str = NULL, /**< Updated by cmd_flow_get_help(). */
6720 }, /**< Tokens are returned by cmd_flow_tok(). */
6723 /* *** display raw_encap/raw_decap buf */
6724 struct cmd_show_set_raw_result {
6725 cmdline_fixed_string_t cmd_show;
6726 cmdline_fixed_string_t cmd_what;
6727 cmdline_fixed_string_t cmd_all;
6732 cmd_show_set_raw_parsed(void *parsed_result, struct cmdline *cl, void *data)
6734 struct cmd_show_set_raw_result *res = parsed_result;
6735 uint16_t index = res->cmd_index;
6737 uint8_t *raw_data = NULL;
6738 size_t raw_size = 0;
6739 char title[16] = {0};
6743 if (!strcmp(res->cmd_all, "all")) {
6746 } else if (index >= RAW_ENCAP_CONFS_MAX_NUM) {
6747 printf("index should be 0-%u\n", RAW_ENCAP_CONFS_MAX_NUM - 1);
6751 if (!strcmp(res->cmd_what, "raw_encap")) {
6752 raw_data = (uint8_t *)&raw_encap_confs[index].data;
6753 raw_size = raw_encap_confs[index].size;
6754 snprintf(title, 16, "\nindex: %u", index);
6755 rte_hexdump(stdout, title, raw_data, raw_size);
6757 raw_data = (uint8_t *)&raw_decap_confs[index].data;
6758 raw_size = raw_decap_confs[index].size;
6759 snprintf(title, 16, "\nindex: %u", index);
6760 rte_hexdump(stdout, title, raw_data, raw_size);
6762 } while (all && ++index < RAW_ENCAP_CONFS_MAX_NUM);
6765 cmdline_parse_token_string_t cmd_show_set_raw_cmd_show =
6766 TOKEN_STRING_INITIALIZER(struct cmd_show_set_raw_result,
6768 cmdline_parse_token_string_t cmd_show_set_raw_cmd_what =
6769 TOKEN_STRING_INITIALIZER(struct cmd_show_set_raw_result,
6770 cmd_what, "raw_encap#raw_decap");
6771 cmdline_parse_token_num_t cmd_show_set_raw_cmd_index =
6772 TOKEN_NUM_INITIALIZER(struct cmd_show_set_raw_result,
6774 cmdline_parse_token_string_t cmd_show_set_raw_cmd_all =
6775 TOKEN_STRING_INITIALIZER(struct cmd_show_set_raw_result,
6777 cmdline_parse_inst_t cmd_show_set_raw = {
6778 .f = cmd_show_set_raw_parsed,
6780 .help_str = "show <raw_encap|raw_decap> <index>",
6782 (void *)&cmd_show_set_raw_cmd_show,
6783 (void *)&cmd_show_set_raw_cmd_what,
6784 (void *)&cmd_show_set_raw_cmd_index,
6788 cmdline_parse_inst_t cmd_show_set_raw_all = {
6789 .f = cmd_show_set_raw_parsed,
6791 .help_str = "show <raw_encap|raw_decap> all",
6793 (void *)&cmd_show_set_raw_cmd_show,
6794 (void *)&cmd_show_set_raw_cmd_what,
6795 (void *)&cmd_show_set_raw_cmd_all,