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,
183 ITEM_ARP_ETH_IPV4_SHA,
184 ITEM_ARP_ETH_IPV4_SPA,
185 ITEM_ARP_ETH_IPV4_THA,
186 ITEM_ARP_ETH_IPV4_TPA,
188 ITEM_IPV6_EXT_NEXT_HDR,
193 ITEM_ICMP6_ND_NS_TARGET_ADDR,
195 ITEM_ICMP6_ND_NA_TARGET_ADDR,
197 ITEM_ICMP6_ND_OPT_TYPE,
198 ITEM_ICMP6_ND_OPT_SLA_ETH,
199 ITEM_ICMP6_ND_OPT_SLA_ETH_SLA,
200 ITEM_ICMP6_ND_OPT_TLA_ETH,
201 ITEM_ICMP6_ND_OPT_TLA_ETH_TLA,
214 ITEM_HIGIG2_CLASSIFICATION,
220 ITEM_L2TPV3OIP_SESSION_ID,
229 /* Validate/create actions. */
249 ACTION_RSS_FUNC_DEFAULT,
250 ACTION_RSS_FUNC_TOEPLITZ,
251 ACTION_RSS_FUNC_SIMPLE_XOR,
252 ACTION_RSS_FUNC_SYMMETRIC_TOEPLITZ,
264 ACTION_PHY_PORT_ORIGINAL,
265 ACTION_PHY_PORT_INDEX,
267 ACTION_PORT_ID_ORIGINAL,
271 ACTION_OF_SET_MPLS_TTL,
272 ACTION_OF_SET_MPLS_TTL_MPLS_TTL,
273 ACTION_OF_DEC_MPLS_TTL,
274 ACTION_OF_SET_NW_TTL,
275 ACTION_OF_SET_NW_TTL_NW_TTL,
276 ACTION_OF_DEC_NW_TTL,
277 ACTION_OF_COPY_TTL_OUT,
278 ACTION_OF_COPY_TTL_IN,
281 ACTION_OF_PUSH_VLAN_ETHERTYPE,
282 ACTION_OF_SET_VLAN_VID,
283 ACTION_OF_SET_VLAN_VID_VLAN_VID,
284 ACTION_OF_SET_VLAN_PCP,
285 ACTION_OF_SET_VLAN_PCP_VLAN_PCP,
287 ACTION_OF_POP_MPLS_ETHERTYPE,
289 ACTION_OF_PUSH_MPLS_ETHERTYPE,
296 ACTION_MPLSOGRE_ENCAP,
297 ACTION_MPLSOGRE_DECAP,
298 ACTION_MPLSOUDP_ENCAP,
299 ACTION_MPLSOUDP_DECAP,
301 ACTION_SET_IPV4_SRC_IPV4_SRC,
303 ACTION_SET_IPV4_DST_IPV4_DST,
305 ACTION_SET_IPV6_SRC_IPV6_SRC,
307 ACTION_SET_IPV6_DST_IPV6_DST,
309 ACTION_SET_TP_SRC_TP_SRC,
311 ACTION_SET_TP_DST_TP_DST,
317 ACTION_SET_MAC_SRC_MAC_SRC,
319 ACTION_SET_MAC_DST_MAC_DST,
321 ACTION_INC_TCP_SEQ_VALUE,
323 ACTION_DEC_TCP_SEQ_VALUE,
325 ACTION_INC_TCP_ACK_VALUE,
327 ACTION_DEC_TCP_ACK_VALUE,
330 ACTION_RAW_ENCAP_INDEX,
331 ACTION_RAW_ENCAP_INDEX_VALUE,
332 ACTION_RAW_DECAP_INDEX,
333 ACTION_RAW_DECAP_INDEX_VALUE,
336 ACTION_SET_TAG_INDEX,
339 ACTION_SET_META_DATA,
340 ACTION_SET_META_MASK,
341 ACTION_SET_IPV4_DSCP,
342 ACTION_SET_IPV4_DSCP_VALUE,
343 ACTION_SET_IPV6_DSCP,
344 ACTION_SET_IPV6_DSCP_VALUE,
347 /** Maximum size for pattern in struct rte_flow_item_raw. */
348 #define ITEM_RAW_PATTERN_SIZE 40
350 /** Storage size for struct rte_flow_item_raw including pattern. */
351 #define ITEM_RAW_SIZE \
352 (sizeof(struct rte_flow_item_raw) + ITEM_RAW_PATTERN_SIZE)
354 /** Maximum number of queue indices in struct rte_flow_action_rss. */
355 #define ACTION_RSS_QUEUE_NUM 128
357 /** Storage for struct rte_flow_action_rss including external data. */
358 struct action_rss_data {
359 struct rte_flow_action_rss conf;
360 uint8_t key[RSS_HASH_KEY_LENGTH];
361 uint16_t queue[ACTION_RSS_QUEUE_NUM];
364 /** Maximum data size in struct rte_flow_action_raw_encap. */
365 #define ACTION_RAW_ENCAP_MAX_DATA 128
366 #define RAW_ENCAP_CONFS_MAX_NUM 8
368 /** Storage for struct rte_flow_action_raw_encap. */
369 struct raw_encap_conf {
370 uint8_t data[ACTION_RAW_ENCAP_MAX_DATA];
371 uint8_t preserve[ACTION_RAW_ENCAP_MAX_DATA];
375 struct raw_encap_conf raw_encap_confs[RAW_ENCAP_CONFS_MAX_NUM];
377 /** Storage for struct rte_flow_action_raw_encap including external data. */
378 struct action_raw_encap_data {
379 struct rte_flow_action_raw_encap conf;
380 uint8_t data[ACTION_RAW_ENCAP_MAX_DATA];
381 uint8_t preserve[ACTION_RAW_ENCAP_MAX_DATA];
385 /** Storage for struct rte_flow_action_raw_decap. */
386 struct raw_decap_conf {
387 uint8_t data[ACTION_RAW_ENCAP_MAX_DATA];
391 struct raw_decap_conf raw_decap_confs[RAW_ENCAP_CONFS_MAX_NUM];
393 /** Storage for struct rte_flow_action_raw_decap including external data. */
394 struct action_raw_decap_data {
395 struct rte_flow_action_raw_decap conf;
396 uint8_t data[ACTION_RAW_ENCAP_MAX_DATA];
400 struct vxlan_encap_conf vxlan_encap_conf = {
404 .vni = "\x00\x00\x00",
406 .udp_dst = RTE_BE16(4789),
407 .ipv4_src = RTE_IPV4(127, 0, 0, 1),
408 .ipv4_dst = RTE_IPV4(255, 255, 255, 255),
409 .ipv6_src = "\x00\x00\x00\x00\x00\x00\x00\x00"
410 "\x00\x00\x00\x00\x00\x00\x00\x01",
411 .ipv6_dst = "\x00\x00\x00\x00\x00\x00\x00\x00"
412 "\x00\x00\x00\x00\x00\x00\x11\x11",
416 .eth_src = "\x00\x00\x00\x00\x00\x00",
417 .eth_dst = "\xff\xff\xff\xff\xff\xff",
420 /** Maximum number of items in struct rte_flow_action_vxlan_encap. */
421 #define ACTION_VXLAN_ENCAP_ITEMS_NUM 6
423 /** Storage for struct rte_flow_action_vxlan_encap including external data. */
424 struct action_vxlan_encap_data {
425 struct rte_flow_action_vxlan_encap conf;
426 struct rte_flow_item items[ACTION_VXLAN_ENCAP_ITEMS_NUM];
427 struct rte_flow_item_eth item_eth;
428 struct rte_flow_item_vlan item_vlan;
430 struct rte_flow_item_ipv4 item_ipv4;
431 struct rte_flow_item_ipv6 item_ipv6;
433 struct rte_flow_item_udp item_udp;
434 struct rte_flow_item_vxlan item_vxlan;
437 struct nvgre_encap_conf nvgre_encap_conf = {
440 .tni = "\x00\x00\x00",
441 .ipv4_src = RTE_IPV4(127, 0, 0, 1),
442 .ipv4_dst = RTE_IPV4(255, 255, 255, 255),
443 .ipv6_src = "\x00\x00\x00\x00\x00\x00\x00\x00"
444 "\x00\x00\x00\x00\x00\x00\x00\x01",
445 .ipv6_dst = "\x00\x00\x00\x00\x00\x00\x00\x00"
446 "\x00\x00\x00\x00\x00\x00\x11\x11",
448 .eth_src = "\x00\x00\x00\x00\x00\x00",
449 .eth_dst = "\xff\xff\xff\xff\xff\xff",
452 /** Maximum number of items in struct rte_flow_action_nvgre_encap. */
453 #define ACTION_NVGRE_ENCAP_ITEMS_NUM 5
455 /** Storage for struct rte_flow_action_nvgre_encap including external data. */
456 struct action_nvgre_encap_data {
457 struct rte_flow_action_nvgre_encap conf;
458 struct rte_flow_item items[ACTION_NVGRE_ENCAP_ITEMS_NUM];
459 struct rte_flow_item_eth item_eth;
460 struct rte_flow_item_vlan item_vlan;
462 struct rte_flow_item_ipv4 item_ipv4;
463 struct rte_flow_item_ipv6 item_ipv6;
465 struct rte_flow_item_nvgre item_nvgre;
468 struct l2_encap_conf l2_encap_conf;
470 struct l2_decap_conf l2_decap_conf;
472 struct mplsogre_encap_conf mplsogre_encap_conf;
474 struct mplsogre_decap_conf mplsogre_decap_conf;
476 struct mplsoudp_encap_conf mplsoudp_encap_conf;
478 struct mplsoudp_decap_conf mplsoudp_decap_conf;
480 /** Maximum number of subsequent tokens and arguments on the stack. */
481 #define CTX_STACK_SIZE 16
483 /** Parser context. */
485 /** Stack of subsequent token lists to process. */
486 const enum index *next[CTX_STACK_SIZE];
487 /** Arguments for stacked tokens. */
488 const void *args[CTX_STACK_SIZE];
489 enum index curr; /**< Current token index. */
490 enum index prev; /**< Index of the last token seen. */
491 int next_num; /**< Number of entries in next[]. */
492 int args_num; /**< Number of entries in args[]. */
493 uint32_t eol:1; /**< EOL has been detected. */
494 uint32_t last:1; /**< No more arguments. */
495 portid_t port; /**< Current port ID (for completions). */
496 uint32_t objdata; /**< Object-specific data. */
497 void *object; /**< Address of current object for relative offsets. */
498 void *objmask; /**< Object a full mask must be written to. */
501 /** Token argument. */
503 uint32_t hton:1; /**< Use network byte ordering. */
504 uint32_t sign:1; /**< Value is signed. */
505 uint32_t bounded:1; /**< Value is bounded. */
506 uintmax_t min; /**< Minimum value if bounded. */
507 uintmax_t max; /**< Maximum value if bounded. */
508 uint32_t offset; /**< Relative offset from ctx->object. */
509 uint32_t size; /**< Field size. */
510 const uint8_t *mask; /**< Bit-mask to use instead of offset/size. */
513 /** Parser token definition. */
515 /** Type displayed during completion (defaults to "TOKEN"). */
517 /** Help displayed during completion (defaults to token name). */
519 /** Private data used by parser functions. */
522 * Lists of subsequent tokens to push on the stack. Each call to the
523 * parser consumes the last entry of that stack.
525 const enum index *const *next;
526 /** Arguments stack for subsequent tokens that need them. */
527 const struct arg *const *args;
529 * Token-processing callback, returns -1 in case of error, the
530 * length of the matched string otherwise. If NULL, attempts to
531 * match the token name.
533 * If buf is not NULL, the result should be stored in it according
534 * to context. An error is returned if not large enough.
536 int (*call)(struct context *ctx, const struct token *token,
537 const char *str, unsigned int len,
538 void *buf, unsigned int size);
540 * Callback that provides possible values for this token, used for
541 * completion. Returns -1 in case of error, the number of possible
542 * values otherwise. If NULL, the token name is used.
544 * If buf is not NULL, entry index ent is written to buf and the
545 * full length of the entry is returned (same behavior as
548 int (*comp)(struct context *ctx, const struct token *token,
549 unsigned int ent, char *buf, unsigned int size);
550 /** Mandatory token name, no default value. */
554 /** Static initializer for the next field. */
555 #define NEXT(...) (const enum index *const []){ __VA_ARGS__, NULL, }
557 /** Static initializer for a NEXT() entry. */
558 #define NEXT_ENTRY(...) (const enum index []){ __VA_ARGS__, ZERO, }
560 /** Static initializer for the args field. */
561 #define ARGS(...) (const struct arg *const []){ __VA_ARGS__, NULL, }
563 /** Static initializer for ARGS() to target a field. */
564 #define ARGS_ENTRY(s, f) \
565 (&(const struct arg){ \
566 .offset = offsetof(s, f), \
567 .size = sizeof(((s *)0)->f), \
570 /** Static initializer for ARGS() to target a bit-field. */
571 #define ARGS_ENTRY_BF(s, f, b) \
572 (&(const struct arg){ \
574 .mask = (const void *)&(const s){ .f = (1 << (b)) - 1 }, \
577 /** Static initializer for ARGS() to target an arbitrary bit-mask. */
578 #define ARGS_ENTRY_MASK(s, f, m) \
579 (&(const struct arg){ \
580 .offset = offsetof(s, f), \
581 .size = sizeof(((s *)0)->f), \
582 .mask = (const void *)(m), \
585 /** Same as ARGS_ENTRY_MASK() using network byte ordering for the value. */
586 #define ARGS_ENTRY_MASK_HTON(s, f, m) \
587 (&(const struct arg){ \
589 .offset = offsetof(s, f), \
590 .size = sizeof(((s *)0)->f), \
591 .mask = (const void *)(m), \
594 /** Static initializer for ARGS() to target a pointer. */
595 #define ARGS_ENTRY_PTR(s, f) \
596 (&(const struct arg){ \
597 .size = sizeof(*((s *)0)->f), \
600 /** Static initializer for ARGS() with arbitrary offset and size. */
601 #define ARGS_ENTRY_ARB(o, s) \
602 (&(const struct arg){ \
607 /** Same as ARGS_ENTRY_ARB() with bounded values. */
608 #define ARGS_ENTRY_ARB_BOUNDED(o, s, i, a) \
609 (&(const struct arg){ \
617 /** Same as ARGS_ENTRY() using network byte ordering. */
618 #define ARGS_ENTRY_HTON(s, f) \
619 (&(const struct arg){ \
621 .offset = offsetof(s, f), \
622 .size = sizeof(((s *)0)->f), \
625 /** Same as ARGS_ENTRY_HTON() for a single argument, without structure. */
626 #define ARG_ENTRY_HTON(s) \
627 (&(const struct arg){ \
633 /** Parser output buffer layout expected by cmd_flow_parsed(). */
635 enum index command; /**< Flow command. */
636 portid_t port; /**< Affected port ID. */
639 struct rte_flow_attr attr;
640 struct rte_flow_item *pattern;
641 struct rte_flow_action *actions;
645 } vc; /**< Validate/create arguments. */
649 } destroy; /**< Destroy arguments. */
652 } dump; /**< Dump arguments. */
655 struct rte_flow_action action;
656 } query; /**< Query arguments. */
660 } list; /**< List arguments. */
663 } isolate; /**< Isolated mode arguments. */
664 } args; /**< Command arguments. */
667 /** Private data for pattern items. */
668 struct parse_item_priv {
669 enum rte_flow_item_type type; /**< Item type. */
670 uint32_t size; /**< Size of item specification structure. */
673 #define PRIV_ITEM(t, s) \
674 (&(const struct parse_item_priv){ \
675 .type = RTE_FLOW_ITEM_TYPE_ ## t, \
679 /** Private data for actions. */
680 struct parse_action_priv {
681 enum rte_flow_action_type type; /**< Action type. */
682 uint32_t size; /**< Size of action configuration structure. */
685 #define PRIV_ACTION(t, s) \
686 (&(const struct parse_action_priv){ \
687 .type = RTE_FLOW_ACTION_TYPE_ ## t, \
691 static const enum index next_vc_attr[] = {
701 static const enum index next_destroy_attr[] = {
707 static const enum index next_dump_attr[] = {
713 static const enum index next_list_attr[] = {
719 static const enum index item_param[] = {
728 static const enum index next_item[] = {
764 ITEM_ICMP6_ND_OPT_SLA_ETH,
765 ITEM_ICMP6_ND_OPT_TLA_ETH,
782 static const enum index item_fuzzy[] = {
788 static const enum index item_any[] = {
794 static const enum index item_vf[] = {
800 static const enum index item_phy_port[] = {
806 static const enum index item_port_id[] = {
812 static const enum index item_mark[] = {
818 static const enum index item_raw[] = {
828 static const enum index item_eth[] = {
836 static const enum index item_vlan[] = {
841 ITEM_VLAN_INNER_TYPE,
846 static const enum index item_ipv4[] = {
856 static const enum index item_ipv6[] = {
867 static const enum index item_icmp[] = {
874 static const enum index item_udp[] = {
881 static const enum index item_tcp[] = {
889 static const enum index item_sctp[] = {
898 static const enum index item_vxlan[] = {
904 static const enum index item_e_tag[] = {
905 ITEM_E_TAG_GRP_ECID_B,
910 static const enum index item_nvgre[] = {
916 static const enum index item_mpls[] = {
924 static const enum index item_gre[] = {
926 ITEM_GRE_C_RSVD0_VER,
934 static const enum index item_gre_key[] = {
940 static const enum index item_gtp[] = {
947 static const enum index item_geneve[] = {
954 static const enum index item_vxlan_gpe[] = {
960 static const enum index item_arp_eth_ipv4[] = {
961 ITEM_ARP_ETH_IPV4_SHA,
962 ITEM_ARP_ETH_IPV4_SPA,
963 ITEM_ARP_ETH_IPV4_THA,
964 ITEM_ARP_ETH_IPV4_TPA,
969 static const enum index item_ipv6_ext[] = {
970 ITEM_IPV6_EXT_NEXT_HDR,
975 static const enum index item_icmp6[] = {
982 static const enum index item_icmp6_nd_ns[] = {
983 ITEM_ICMP6_ND_NS_TARGET_ADDR,
988 static const enum index item_icmp6_nd_na[] = {
989 ITEM_ICMP6_ND_NA_TARGET_ADDR,
994 static const enum index item_icmp6_nd_opt[] = {
995 ITEM_ICMP6_ND_OPT_TYPE,
1000 static const enum index item_icmp6_nd_opt_sla_eth[] = {
1001 ITEM_ICMP6_ND_OPT_SLA_ETH_SLA,
1006 static const enum index item_icmp6_nd_opt_tla_eth[] = {
1007 ITEM_ICMP6_ND_OPT_TLA_ETH_TLA,
1012 static const enum index item_meta[] = {
1018 static const enum index item_gtp_psc[] = {
1025 static const enum index item_pppoed[] = {
1031 static const enum index item_pppoes[] = {
1037 static const enum index item_pppoe_proto_id[] = {
1038 ITEM_PPPOE_PROTO_ID,
1043 static const enum index item_higig2[] = {
1044 ITEM_HIGIG2_CLASSIFICATION,
1050 static const enum index item_esp[] = {
1056 static const enum index item_ah[] = {
1062 static const enum index item_pfcp[] = {
1069 static const enum index next_set_raw[] = {
1075 static const enum index item_tag[] = {
1082 static const enum index item_l2tpv3oip[] = {
1083 ITEM_L2TPV3OIP_SESSION_ID,
1088 static const enum index next_action[] = {
1104 ACTION_OF_SET_MPLS_TTL,
1105 ACTION_OF_DEC_MPLS_TTL,
1106 ACTION_OF_SET_NW_TTL,
1107 ACTION_OF_DEC_NW_TTL,
1108 ACTION_OF_COPY_TTL_OUT,
1109 ACTION_OF_COPY_TTL_IN,
1111 ACTION_OF_PUSH_VLAN,
1112 ACTION_OF_SET_VLAN_VID,
1113 ACTION_OF_SET_VLAN_PCP,
1115 ACTION_OF_PUSH_MPLS,
1122 ACTION_MPLSOGRE_ENCAP,
1123 ACTION_MPLSOGRE_DECAP,
1124 ACTION_MPLSOUDP_ENCAP,
1125 ACTION_MPLSOUDP_DECAP,
1126 ACTION_SET_IPV4_SRC,
1127 ACTION_SET_IPV4_DST,
1128 ACTION_SET_IPV6_SRC,
1129 ACTION_SET_IPV6_DST,
1145 ACTION_SET_IPV4_DSCP,
1146 ACTION_SET_IPV6_DSCP,
1150 static const enum index action_mark[] = {
1156 static const enum index action_queue[] = {
1162 static const enum index action_count[] = {
1164 ACTION_COUNT_SHARED,
1169 static const enum index action_rss[] = {
1180 static const enum index action_vf[] = {
1187 static const enum index action_phy_port[] = {
1188 ACTION_PHY_PORT_ORIGINAL,
1189 ACTION_PHY_PORT_INDEX,
1194 static const enum index action_port_id[] = {
1195 ACTION_PORT_ID_ORIGINAL,
1201 static const enum index action_meter[] = {
1207 static const enum index action_of_set_mpls_ttl[] = {
1208 ACTION_OF_SET_MPLS_TTL_MPLS_TTL,
1213 static const enum index action_of_set_nw_ttl[] = {
1214 ACTION_OF_SET_NW_TTL_NW_TTL,
1219 static const enum index action_of_push_vlan[] = {
1220 ACTION_OF_PUSH_VLAN_ETHERTYPE,
1225 static const enum index action_of_set_vlan_vid[] = {
1226 ACTION_OF_SET_VLAN_VID_VLAN_VID,
1231 static const enum index action_of_set_vlan_pcp[] = {
1232 ACTION_OF_SET_VLAN_PCP_VLAN_PCP,
1237 static const enum index action_of_pop_mpls[] = {
1238 ACTION_OF_POP_MPLS_ETHERTYPE,
1243 static const enum index action_of_push_mpls[] = {
1244 ACTION_OF_PUSH_MPLS_ETHERTYPE,
1249 static const enum index action_set_ipv4_src[] = {
1250 ACTION_SET_IPV4_SRC_IPV4_SRC,
1255 static const enum index action_set_mac_src[] = {
1256 ACTION_SET_MAC_SRC_MAC_SRC,
1261 static const enum index action_set_ipv4_dst[] = {
1262 ACTION_SET_IPV4_DST_IPV4_DST,
1267 static const enum index action_set_ipv6_src[] = {
1268 ACTION_SET_IPV6_SRC_IPV6_SRC,
1273 static const enum index action_set_ipv6_dst[] = {
1274 ACTION_SET_IPV6_DST_IPV6_DST,
1279 static const enum index action_set_tp_src[] = {
1280 ACTION_SET_TP_SRC_TP_SRC,
1285 static const enum index action_set_tp_dst[] = {
1286 ACTION_SET_TP_DST_TP_DST,
1291 static const enum index action_set_ttl[] = {
1297 static const enum index action_jump[] = {
1303 static const enum index action_set_mac_dst[] = {
1304 ACTION_SET_MAC_DST_MAC_DST,
1309 static const enum index action_inc_tcp_seq[] = {
1310 ACTION_INC_TCP_SEQ_VALUE,
1315 static const enum index action_dec_tcp_seq[] = {
1316 ACTION_DEC_TCP_SEQ_VALUE,
1321 static const enum index action_inc_tcp_ack[] = {
1322 ACTION_INC_TCP_ACK_VALUE,
1327 static const enum index action_dec_tcp_ack[] = {
1328 ACTION_DEC_TCP_ACK_VALUE,
1333 static const enum index action_raw_encap[] = {
1334 ACTION_RAW_ENCAP_INDEX,
1339 static const enum index action_raw_decap[] = {
1340 ACTION_RAW_DECAP_INDEX,
1345 static const enum index action_set_tag[] = {
1346 ACTION_SET_TAG_DATA,
1347 ACTION_SET_TAG_INDEX,
1348 ACTION_SET_TAG_MASK,
1353 static const enum index action_set_meta[] = {
1354 ACTION_SET_META_DATA,
1355 ACTION_SET_META_MASK,
1360 static const enum index action_set_ipv4_dscp[] = {
1361 ACTION_SET_IPV4_DSCP_VALUE,
1366 static const enum index action_set_ipv6_dscp[] = {
1367 ACTION_SET_IPV6_DSCP_VALUE,
1372 static int parse_set_raw_encap_decap(struct context *, const struct token *,
1373 const char *, unsigned int,
1374 void *, unsigned int);
1375 static int parse_set_init(struct context *, const struct token *,
1376 const char *, unsigned int,
1377 void *, unsigned int);
1378 static int parse_init(struct context *, const struct token *,
1379 const char *, unsigned int,
1380 void *, unsigned int);
1381 static int parse_vc(struct context *, const struct token *,
1382 const char *, unsigned int,
1383 void *, unsigned int);
1384 static int parse_vc_spec(struct context *, const struct token *,
1385 const char *, unsigned int, void *, unsigned int);
1386 static int parse_vc_conf(struct context *, const struct token *,
1387 const char *, unsigned int, void *, unsigned int);
1388 static int parse_vc_action_rss(struct context *, const struct token *,
1389 const char *, unsigned int, void *,
1391 static int parse_vc_action_rss_func(struct context *, const struct token *,
1392 const char *, unsigned int, void *,
1394 static int parse_vc_action_rss_type(struct context *, const struct token *,
1395 const char *, unsigned int, void *,
1397 static int parse_vc_action_rss_queue(struct context *, const struct token *,
1398 const char *, unsigned int, void *,
1400 static int parse_vc_action_vxlan_encap(struct context *, const struct token *,
1401 const char *, unsigned int, void *,
1403 static int parse_vc_action_nvgre_encap(struct context *, const struct token *,
1404 const char *, unsigned int, void *,
1406 static int parse_vc_action_l2_encap(struct context *, const struct token *,
1407 const char *, unsigned int, void *,
1409 static int parse_vc_action_l2_decap(struct context *, const struct token *,
1410 const char *, unsigned int, void *,
1412 static int parse_vc_action_mplsogre_encap(struct context *,
1413 const struct token *, const char *,
1414 unsigned int, void *, unsigned int);
1415 static int parse_vc_action_mplsogre_decap(struct context *,
1416 const struct token *, const char *,
1417 unsigned int, void *, unsigned int);
1418 static int parse_vc_action_mplsoudp_encap(struct context *,
1419 const struct token *, const char *,
1420 unsigned int, void *, unsigned int);
1421 static int parse_vc_action_mplsoudp_decap(struct context *,
1422 const struct token *, const char *,
1423 unsigned int, void *, unsigned int);
1424 static int parse_vc_action_raw_encap(struct context *,
1425 const struct token *, const char *,
1426 unsigned int, void *, unsigned int);
1427 static int parse_vc_action_raw_decap(struct context *,
1428 const struct token *, const char *,
1429 unsigned int, void *, unsigned int);
1430 static int parse_vc_action_raw_encap_index(struct context *,
1431 const struct token *, const char *,
1432 unsigned int, void *, unsigned int);
1433 static int parse_vc_action_raw_decap_index(struct context *,
1434 const struct token *, const char *,
1435 unsigned int, void *, unsigned int);
1436 static int parse_vc_action_set_meta(struct context *ctx,
1437 const struct token *token, const char *str,
1438 unsigned int len, void *buf,
1440 static int parse_destroy(struct context *, const struct token *,
1441 const char *, unsigned int,
1442 void *, unsigned int);
1443 static int parse_flush(struct context *, const struct token *,
1444 const char *, unsigned int,
1445 void *, unsigned int);
1446 static int parse_dump(struct context *, const struct token *,
1447 const char *, unsigned int,
1448 void *, unsigned int);
1449 static int parse_query(struct context *, const struct token *,
1450 const char *, unsigned int,
1451 void *, unsigned int);
1452 static int parse_action(struct context *, const struct token *,
1453 const char *, unsigned int,
1454 void *, unsigned int);
1455 static int parse_list(struct context *, const struct token *,
1456 const char *, unsigned int,
1457 void *, unsigned int);
1458 static int parse_isolate(struct context *, const struct token *,
1459 const char *, unsigned int,
1460 void *, unsigned int);
1461 static int parse_int(struct context *, const struct token *,
1462 const char *, unsigned int,
1463 void *, unsigned int);
1464 static int parse_prefix(struct context *, const struct token *,
1465 const char *, unsigned int,
1466 void *, unsigned int);
1467 static int parse_boolean(struct context *, const struct token *,
1468 const char *, unsigned int,
1469 void *, unsigned int);
1470 static int parse_string(struct context *, const struct token *,
1471 const char *, unsigned int,
1472 void *, unsigned int);
1473 static int parse_hex(struct context *ctx, const struct token *token,
1474 const char *str, unsigned int len,
1475 void *buf, unsigned int size);
1476 static int parse_string0(struct context *, const struct token *,
1477 const char *, unsigned int,
1478 void *, unsigned int);
1479 static int parse_mac_addr(struct context *, const struct token *,
1480 const char *, unsigned int,
1481 void *, unsigned int);
1482 static int parse_ipv4_addr(struct context *, const struct token *,
1483 const char *, unsigned int,
1484 void *, unsigned int);
1485 static int parse_ipv6_addr(struct context *, const struct token *,
1486 const char *, unsigned int,
1487 void *, unsigned int);
1488 static int parse_port(struct context *, const struct token *,
1489 const char *, unsigned int,
1490 void *, unsigned int);
1491 static int comp_none(struct context *, const struct token *,
1492 unsigned int, char *, unsigned int);
1493 static int comp_boolean(struct context *, const struct token *,
1494 unsigned int, char *, unsigned int);
1495 static int comp_action(struct context *, const struct token *,
1496 unsigned int, char *, unsigned int);
1497 static int comp_port(struct context *, const struct token *,
1498 unsigned int, char *, unsigned int);
1499 static int comp_rule_id(struct context *, const struct token *,
1500 unsigned int, char *, unsigned int);
1501 static int comp_vc_action_rss_type(struct context *, const struct token *,
1502 unsigned int, char *, unsigned int);
1503 static int comp_vc_action_rss_queue(struct context *, const struct token *,
1504 unsigned int, char *, unsigned int);
1505 static int comp_set_raw_index(struct context *, const struct token *,
1506 unsigned int, char *, unsigned int);
1508 /** Token definitions. */
1509 static const struct token token_list[] = {
1510 /* Special tokens. */
1513 .help = "null entry, abused as the entry point",
1514 .next = NEXT(NEXT_ENTRY(FLOW)),
1519 .help = "command may end here",
1522 .name = "START_SET",
1523 .help = "null entry, abused as the entry point for set",
1524 .next = NEXT(NEXT_ENTRY(SET)),
1529 .help = "set command may end here",
1531 /* Common tokens. */
1535 .help = "integer value",
1540 .name = "{unsigned}",
1542 .help = "unsigned integer value",
1549 .help = "prefix length for bit-mask",
1550 .call = parse_prefix,
1554 .name = "{boolean}",
1556 .help = "any boolean value",
1557 .call = parse_boolean,
1558 .comp = comp_boolean,
1563 .help = "fixed string",
1564 .call = parse_string,
1570 .help = "fixed string",
1574 .name = "{file path}",
1576 .help = "file path",
1577 .call = parse_string0,
1581 .name = "{MAC address}",
1583 .help = "standard MAC address notation",
1584 .call = parse_mac_addr,
1588 .name = "{IPv4 address}",
1589 .type = "IPV4 ADDRESS",
1590 .help = "standard IPv4 address notation",
1591 .call = parse_ipv4_addr,
1595 .name = "{IPv6 address}",
1596 .type = "IPV6 ADDRESS",
1597 .help = "standard IPv6 address notation",
1598 .call = parse_ipv6_addr,
1602 .name = "{rule id}",
1604 .help = "rule identifier",
1606 .comp = comp_rule_id,
1609 .name = "{port_id}",
1611 .help = "port identifier",
1616 .name = "{group_id}",
1618 .help = "group identifier",
1622 [PRIORITY_LEVEL] = {
1625 .help = "priority level",
1629 /* Top-level command. */
1632 .type = "{command} {port_id} [{arg} [...]]",
1633 .help = "manage ingress/egress flow rules",
1634 .next = NEXT(NEXT_ENTRY
1645 /* Sub-level commands. */
1648 .help = "check whether a flow rule can be created",
1649 .next = NEXT(next_vc_attr, NEXT_ENTRY(PORT_ID)),
1650 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1655 .help = "create a flow rule",
1656 .next = NEXT(next_vc_attr, NEXT_ENTRY(PORT_ID)),
1657 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1662 .help = "destroy specific flow rules",
1663 .next = NEXT(NEXT_ENTRY(DESTROY_RULE), NEXT_ENTRY(PORT_ID)),
1664 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1665 .call = parse_destroy,
1669 .help = "destroy all flow rules",
1670 .next = NEXT(NEXT_ENTRY(PORT_ID)),
1671 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1672 .call = parse_flush,
1676 .help = "dump all flow rules to file",
1677 .next = NEXT(next_dump_attr, NEXT_ENTRY(PORT_ID)),
1678 .args = ARGS(ARGS_ENTRY(struct buffer, args.dump.file),
1679 ARGS_ENTRY(struct buffer, port)),
1684 .help = "query an existing flow rule",
1685 .next = NEXT(NEXT_ENTRY(QUERY_ACTION),
1686 NEXT_ENTRY(RULE_ID),
1687 NEXT_ENTRY(PORT_ID)),
1688 .args = ARGS(ARGS_ENTRY(struct buffer, args.query.action.type),
1689 ARGS_ENTRY(struct buffer, args.query.rule),
1690 ARGS_ENTRY(struct buffer, port)),
1691 .call = parse_query,
1695 .help = "list existing flow rules",
1696 .next = NEXT(next_list_attr, NEXT_ENTRY(PORT_ID)),
1697 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1702 .help = "restrict ingress traffic to the defined flow rules",
1703 .next = NEXT(NEXT_ENTRY(BOOLEAN),
1704 NEXT_ENTRY(PORT_ID)),
1705 .args = ARGS(ARGS_ENTRY(struct buffer, args.isolate.set),
1706 ARGS_ENTRY(struct buffer, port)),
1707 .call = parse_isolate,
1709 /* Destroy arguments. */
1712 .help = "specify a rule identifier",
1713 .next = NEXT(next_destroy_attr, NEXT_ENTRY(RULE_ID)),
1714 .args = ARGS(ARGS_ENTRY_PTR(struct buffer, args.destroy.rule)),
1715 .call = parse_destroy,
1717 /* Query arguments. */
1721 .help = "action to query, must be part of the rule",
1722 .call = parse_action,
1723 .comp = comp_action,
1725 /* List arguments. */
1728 .help = "specify a group",
1729 .next = NEXT(next_list_attr, NEXT_ENTRY(GROUP_ID)),
1730 .args = ARGS(ARGS_ENTRY_PTR(struct buffer, args.list.group)),
1733 /* Validate/create attributes. */
1736 .help = "specify a group",
1737 .next = NEXT(next_vc_attr, NEXT_ENTRY(GROUP_ID)),
1738 .args = ARGS(ARGS_ENTRY(struct rte_flow_attr, group)),
1743 .help = "specify a priority level",
1744 .next = NEXT(next_vc_attr, NEXT_ENTRY(PRIORITY_LEVEL)),
1745 .args = ARGS(ARGS_ENTRY(struct rte_flow_attr, priority)),
1750 .help = "affect rule to ingress",
1751 .next = NEXT(next_vc_attr),
1756 .help = "affect rule to egress",
1757 .next = NEXT(next_vc_attr),
1762 .help = "apply rule directly to endpoints found in pattern",
1763 .next = NEXT(next_vc_attr),
1766 /* Validate/create pattern. */
1769 .help = "submit a list of pattern items",
1770 .next = NEXT(next_item),
1775 .help = "match value perfectly (with full bit-mask)",
1776 .call = parse_vc_spec,
1778 [ITEM_PARAM_SPEC] = {
1780 .help = "match value according to configured bit-mask",
1781 .call = parse_vc_spec,
1783 [ITEM_PARAM_LAST] = {
1785 .help = "specify upper bound to establish a range",
1786 .call = parse_vc_spec,
1788 [ITEM_PARAM_MASK] = {
1790 .help = "specify bit-mask with relevant bits set to one",
1791 .call = parse_vc_spec,
1793 [ITEM_PARAM_PREFIX] = {
1795 .help = "generate bit-mask from a prefix length",
1796 .call = parse_vc_spec,
1800 .help = "specify next pattern item",
1801 .next = NEXT(next_item),
1805 .help = "end list of pattern items",
1806 .priv = PRIV_ITEM(END, 0),
1807 .next = NEXT(NEXT_ENTRY(ACTIONS)),
1812 .help = "no-op pattern item",
1813 .priv = PRIV_ITEM(VOID, 0),
1814 .next = NEXT(NEXT_ENTRY(ITEM_NEXT)),
1819 .help = "perform actions when pattern does not match",
1820 .priv = PRIV_ITEM(INVERT, 0),
1821 .next = NEXT(NEXT_ENTRY(ITEM_NEXT)),
1826 .help = "match any protocol for the current layer",
1827 .priv = PRIV_ITEM(ANY, sizeof(struct rte_flow_item_any)),
1828 .next = NEXT(item_any),
1833 .help = "number of layers covered",
1834 .next = NEXT(item_any, NEXT_ENTRY(UNSIGNED), item_param),
1835 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_any, num)),
1839 .help = "match traffic from/to the physical function",
1840 .priv = PRIV_ITEM(PF, 0),
1841 .next = NEXT(NEXT_ENTRY(ITEM_NEXT)),
1846 .help = "match traffic from/to a virtual function ID",
1847 .priv = PRIV_ITEM(VF, sizeof(struct rte_flow_item_vf)),
1848 .next = NEXT(item_vf),
1854 .next = NEXT(item_vf, NEXT_ENTRY(UNSIGNED), item_param),
1855 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_vf, id)),
1859 .help = "match traffic from/to a specific physical port",
1860 .priv = PRIV_ITEM(PHY_PORT,
1861 sizeof(struct rte_flow_item_phy_port)),
1862 .next = NEXT(item_phy_port),
1865 [ITEM_PHY_PORT_INDEX] = {
1867 .help = "physical port index",
1868 .next = NEXT(item_phy_port, NEXT_ENTRY(UNSIGNED), item_param),
1869 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_phy_port, index)),
1873 .help = "match traffic from/to a given DPDK port ID",
1874 .priv = PRIV_ITEM(PORT_ID,
1875 sizeof(struct rte_flow_item_port_id)),
1876 .next = NEXT(item_port_id),
1879 [ITEM_PORT_ID_ID] = {
1881 .help = "DPDK port ID",
1882 .next = NEXT(item_port_id, NEXT_ENTRY(UNSIGNED), item_param),
1883 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_port_id, id)),
1887 .help = "match traffic against value set in previously matched rule",
1888 .priv = PRIV_ITEM(MARK, sizeof(struct rte_flow_item_mark)),
1889 .next = NEXT(item_mark),
1894 .help = "Integer value to match against",
1895 .next = NEXT(item_mark, NEXT_ENTRY(UNSIGNED), item_param),
1896 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_mark, id)),
1900 .help = "match an arbitrary byte string",
1901 .priv = PRIV_ITEM(RAW, ITEM_RAW_SIZE),
1902 .next = NEXT(item_raw),
1905 [ITEM_RAW_RELATIVE] = {
1907 .help = "look for pattern after the previous item",
1908 .next = NEXT(item_raw, NEXT_ENTRY(BOOLEAN), item_param),
1909 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_item_raw,
1912 [ITEM_RAW_SEARCH] = {
1914 .help = "search pattern from offset (see also limit)",
1915 .next = NEXT(item_raw, NEXT_ENTRY(BOOLEAN), item_param),
1916 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_item_raw,
1919 [ITEM_RAW_OFFSET] = {
1921 .help = "absolute or relative offset for pattern",
1922 .next = NEXT(item_raw, NEXT_ENTRY(INTEGER), item_param),
1923 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_raw, offset)),
1925 [ITEM_RAW_LIMIT] = {
1927 .help = "search area limit for start of pattern",
1928 .next = NEXT(item_raw, NEXT_ENTRY(UNSIGNED), item_param),
1929 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_raw, limit)),
1931 [ITEM_RAW_PATTERN] = {
1933 .help = "byte string to look for",
1934 .next = NEXT(item_raw,
1936 NEXT_ENTRY(ITEM_PARAM_IS,
1939 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_raw, pattern),
1940 ARGS_ENTRY(struct rte_flow_item_raw, length),
1941 ARGS_ENTRY_ARB(sizeof(struct rte_flow_item_raw),
1942 ITEM_RAW_PATTERN_SIZE)),
1946 .help = "match Ethernet header",
1947 .priv = PRIV_ITEM(ETH, sizeof(struct rte_flow_item_eth)),
1948 .next = NEXT(item_eth),
1953 .help = "destination MAC",
1954 .next = NEXT(item_eth, NEXT_ENTRY(MAC_ADDR), item_param),
1955 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_eth, dst)),
1959 .help = "source MAC",
1960 .next = NEXT(item_eth, NEXT_ENTRY(MAC_ADDR), item_param),
1961 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_eth, src)),
1965 .help = "EtherType",
1966 .next = NEXT(item_eth, NEXT_ENTRY(UNSIGNED), item_param),
1967 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_eth, type)),
1971 .help = "match 802.1Q/ad VLAN tag",
1972 .priv = PRIV_ITEM(VLAN, sizeof(struct rte_flow_item_vlan)),
1973 .next = NEXT(item_vlan),
1978 .help = "tag control information",
1979 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1980 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vlan, tci)),
1984 .help = "priority code point",
1985 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1986 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_vlan,
1991 .help = "drop eligible indicator",
1992 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1993 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_vlan,
1998 .help = "VLAN identifier",
1999 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
2000 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_vlan,
2003 [ITEM_VLAN_INNER_TYPE] = {
2004 .name = "inner_type",
2005 .help = "inner EtherType",
2006 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
2007 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vlan,
2012 .help = "match IPv4 header",
2013 .priv = PRIV_ITEM(IPV4, sizeof(struct rte_flow_item_ipv4)),
2014 .next = NEXT(item_ipv4),
2019 .help = "type of service",
2020 .next = NEXT(item_ipv4, NEXT_ENTRY(UNSIGNED), item_param),
2021 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
2022 hdr.type_of_service)),
2026 .help = "time to live",
2027 .next = NEXT(item_ipv4, NEXT_ENTRY(UNSIGNED), item_param),
2028 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
2031 [ITEM_IPV4_PROTO] = {
2033 .help = "next protocol ID",
2034 .next = NEXT(item_ipv4, NEXT_ENTRY(UNSIGNED), item_param),
2035 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
2036 hdr.next_proto_id)),
2040 .help = "source address",
2041 .next = NEXT(item_ipv4, NEXT_ENTRY(IPV4_ADDR), item_param),
2042 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
2047 .help = "destination address",
2048 .next = NEXT(item_ipv4, NEXT_ENTRY(IPV4_ADDR), item_param),
2049 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
2054 .help = "match IPv6 header",
2055 .priv = PRIV_ITEM(IPV6, sizeof(struct rte_flow_item_ipv6)),
2056 .next = NEXT(item_ipv6),
2061 .help = "traffic class",
2062 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
2063 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_ipv6,
2065 "\x0f\xf0\x00\x00")),
2067 [ITEM_IPV6_FLOW] = {
2069 .help = "flow label",
2070 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
2071 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_ipv6,
2073 "\x00\x0f\xff\xff")),
2075 [ITEM_IPV6_PROTO] = {
2077 .help = "protocol (next header)",
2078 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
2079 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
2084 .help = "hop limit",
2085 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
2086 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
2091 .help = "source address",
2092 .next = NEXT(item_ipv6, NEXT_ENTRY(IPV6_ADDR), item_param),
2093 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
2098 .help = "destination address",
2099 .next = NEXT(item_ipv6, NEXT_ENTRY(IPV6_ADDR), item_param),
2100 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
2105 .help = "match ICMP header",
2106 .priv = PRIV_ITEM(ICMP, sizeof(struct rte_flow_item_icmp)),
2107 .next = NEXT(item_icmp),
2110 [ITEM_ICMP_TYPE] = {
2112 .help = "ICMP packet type",
2113 .next = NEXT(item_icmp, NEXT_ENTRY(UNSIGNED), item_param),
2114 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp,
2117 [ITEM_ICMP_CODE] = {
2119 .help = "ICMP packet code",
2120 .next = NEXT(item_icmp, NEXT_ENTRY(UNSIGNED), item_param),
2121 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp,
2126 .help = "match UDP header",
2127 .priv = PRIV_ITEM(UDP, sizeof(struct rte_flow_item_udp)),
2128 .next = NEXT(item_udp),
2133 .help = "UDP source port",
2134 .next = NEXT(item_udp, NEXT_ENTRY(UNSIGNED), item_param),
2135 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_udp,
2140 .help = "UDP destination port",
2141 .next = NEXT(item_udp, NEXT_ENTRY(UNSIGNED), item_param),
2142 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_udp,
2147 .help = "match TCP header",
2148 .priv = PRIV_ITEM(TCP, sizeof(struct rte_flow_item_tcp)),
2149 .next = NEXT(item_tcp),
2154 .help = "TCP source port",
2155 .next = NEXT(item_tcp, NEXT_ENTRY(UNSIGNED), item_param),
2156 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_tcp,
2161 .help = "TCP destination port",
2162 .next = NEXT(item_tcp, NEXT_ENTRY(UNSIGNED), item_param),
2163 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_tcp,
2166 [ITEM_TCP_FLAGS] = {
2168 .help = "TCP flags",
2169 .next = NEXT(item_tcp, NEXT_ENTRY(UNSIGNED), item_param),
2170 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_tcp,
2175 .help = "match SCTP header",
2176 .priv = PRIV_ITEM(SCTP, sizeof(struct rte_flow_item_sctp)),
2177 .next = NEXT(item_sctp),
2182 .help = "SCTP source port",
2183 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
2184 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
2189 .help = "SCTP destination port",
2190 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
2191 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
2196 .help = "validation tag",
2197 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
2198 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
2201 [ITEM_SCTP_CKSUM] = {
2204 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
2205 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
2210 .help = "match VXLAN header",
2211 .priv = PRIV_ITEM(VXLAN, sizeof(struct rte_flow_item_vxlan)),
2212 .next = NEXT(item_vxlan),
2215 [ITEM_VXLAN_VNI] = {
2217 .help = "VXLAN identifier",
2218 .next = NEXT(item_vxlan, NEXT_ENTRY(UNSIGNED), item_param),
2219 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vxlan, vni)),
2223 .help = "match E-Tag header",
2224 .priv = PRIV_ITEM(E_TAG, sizeof(struct rte_flow_item_e_tag)),
2225 .next = NEXT(item_e_tag),
2228 [ITEM_E_TAG_GRP_ECID_B] = {
2229 .name = "grp_ecid_b",
2230 .help = "GRP and E-CID base",
2231 .next = NEXT(item_e_tag, NEXT_ENTRY(UNSIGNED), item_param),
2232 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_e_tag,
2238 .help = "match NVGRE header",
2239 .priv = PRIV_ITEM(NVGRE, sizeof(struct rte_flow_item_nvgre)),
2240 .next = NEXT(item_nvgre),
2243 [ITEM_NVGRE_TNI] = {
2245 .help = "virtual subnet ID",
2246 .next = NEXT(item_nvgre, NEXT_ENTRY(UNSIGNED), item_param),
2247 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_nvgre, tni)),
2251 .help = "match MPLS header",
2252 .priv = PRIV_ITEM(MPLS, sizeof(struct rte_flow_item_mpls)),
2253 .next = NEXT(item_mpls),
2256 [ITEM_MPLS_LABEL] = {
2258 .help = "MPLS label",
2259 .next = NEXT(item_mpls, NEXT_ENTRY(UNSIGNED), item_param),
2260 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_mpls,
2266 .help = "MPLS Traffic Class",
2267 .next = NEXT(item_mpls, NEXT_ENTRY(UNSIGNED), item_param),
2268 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_mpls,
2274 .help = "MPLS Bottom-of-Stack",
2275 .next = NEXT(item_mpls, NEXT_ENTRY(UNSIGNED), item_param),
2276 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_mpls,
2282 .help = "match GRE header",
2283 .priv = PRIV_ITEM(GRE, sizeof(struct rte_flow_item_gre)),
2284 .next = NEXT(item_gre),
2287 [ITEM_GRE_PROTO] = {
2289 .help = "GRE protocol type",
2290 .next = NEXT(item_gre, NEXT_ENTRY(UNSIGNED), item_param),
2291 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gre,
2294 [ITEM_GRE_C_RSVD0_VER] = {
2295 .name = "c_rsvd0_ver",
2297 "checksum (1b), undefined (1b), key bit (1b),"
2298 " sequence number (1b), reserved 0 (9b),"
2300 .next = NEXT(item_gre, NEXT_ENTRY(UNSIGNED), item_param),
2301 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gre,
2304 [ITEM_GRE_C_BIT] = {
2306 .help = "checksum bit (C)",
2307 .next = NEXT(item_gre, NEXT_ENTRY(BOOLEAN), item_param),
2308 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_gre,
2310 "\x80\x00\x00\x00")),
2312 [ITEM_GRE_S_BIT] = {
2314 .help = "sequence number bit (S)",
2315 .next = NEXT(item_gre, NEXT_ENTRY(BOOLEAN), item_param),
2316 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_gre,
2318 "\x10\x00\x00\x00")),
2320 [ITEM_GRE_K_BIT] = {
2322 .help = "key bit (K)",
2323 .next = NEXT(item_gre, NEXT_ENTRY(BOOLEAN), item_param),
2324 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_gre,
2326 "\x20\x00\x00\x00")),
2330 .help = "fuzzy pattern match, expect faster than default",
2331 .priv = PRIV_ITEM(FUZZY,
2332 sizeof(struct rte_flow_item_fuzzy)),
2333 .next = NEXT(item_fuzzy),
2336 [ITEM_FUZZY_THRESH] = {
2338 .help = "match accuracy threshold",
2339 .next = NEXT(item_fuzzy, NEXT_ENTRY(UNSIGNED), item_param),
2340 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_fuzzy,
2345 .help = "match GTP header",
2346 .priv = PRIV_ITEM(GTP, sizeof(struct rte_flow_item_gtp)),
2347 .next = NEXT(item_gtp),
2350 [ITEM_GTP_MSG_TYPE] = {
2352 .help = "GTP message type",
2353 .next = NEXT(item_gtp, NEXT_ENTRY(UNSIGNED), item_param),
2354 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gtp,
2359 .help = "tunnel endpoint identifier",
2360 .next = NEXT(item_gtp, NEXT_ENTRY(UNSIGNED), item_param),
2361 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gtp, teid)),
2365 .help = "match GTP header",
2366 .priv = PRIV_ITEM(GTPC, sizeof(struct rte_flow_item_gtp)),
2367 .next = NEXT(item_gtp),
2372 .help = "match GTP header",
2373 .priv = PRIV_ITEM(GTPU, sizeof(struct rte_flow_item_gtp)),
2374 .next = NEXT(item_gtp),
2379 .help = "match GENEVE header",
2380 .priv = PRIV_ITEM(GENEVE, sizeof(struct rte_flow_item_geneve)),
2381 .next = NEXT(item_geneve),
2384 [ITEM_GENEVE_VNI] = {
2386 .help = "virtual network identifier",
2387 .next = NEXT(item_geneve, NEXT_ENTRY(UNSIGNED), item_param),
2388 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_geneve, vni)),
2390 [ITEM_GENEVE_PROTO] = {
2392 .help = "GENEVE protocol type",
2393 .next = NEXT(item_geneve, NEXT_ENTRY(UNSIGNED), item_param),
2394 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_geneve,
2397 [ITEM_VXLAN_GPE] = {
2398 .name = "vxlan-gpe",
2399 .help = "match VXLAN-GPE header",
2400 .priv = PRIV_ITEM(VXLAN_GPE,
2401 sizeof(struct rte_flow_item_vxlan_gpe)),
2402 .next = NEXT(item_vxlan_gpe),
2405 [ITEM_VXLAN_GPE_VNI] = {
2407 .help = "VXLAN-GPE identifier",
2408 .next = NEXT(item_vxlan_gpe, NEXT_ENTRY(UNSIGNED), item_param),
2409 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vxlan_gpe,
2412 [ITEM_ARP_ETH_IPV4] = {
2413 .name = "arp_eth_ipv4",
2414 .help = "match ARP header for Ethernet/IPv4",
2415 .priv = PRIV_ITEM(ARP_ETH_IPV4,
2416 sizeof(struct rte_flow_item_arp_eth_ipv4)),
2417 .next = NEXT(item_arp_eth_ipv4),
2420 [ITEM_ARP_ETH_IPV4_SHA] = {
2422 .help = "sender hardware address",
2423 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(MAC_ADDR),
2425 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
2428 [ITEM_ARP_ETH_IPV4_SPA] = {
2430 .help = "sender IPv4 address",
2431 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(IPV4_ADDR),
2433 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
2436 [ITEM_ARP_ETH_IPV4_THA] = {
2438 .help = "target hardware address",
2439 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(MAC_ADDR),
2441 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
2444 [ITEM_ARP_ETH_IPV4_TPA] = {
2446 .help = "target IPv4 address",
2447 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(IPV4_ADDR),
2449 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
2454 .help = "match presence of any IPv6 extension header",
2455 .priv = PRIV_ITEM(IPV6_EXT,
2456 sizeof(struct rte_flow_item_ipv6_ext)),
2457 .next = NEXT(item_ipv6_ext),
2460 [ITEM_IPV6_EXT_NEXT_HDR] = {
2462 .help = "next header",
2463 .next = NEXT(item_ipv6_ext, NEXT_ENTRY(UNSIGNED), item_param),
2464 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6_ext,
2469 .help = "match any ICMPv6 header",
2470 .priv = PRIV_ITEM(ICMP6, sizeof(struct rte_flow_item_icmp6)),
2471 .next = NEXT(item_icmp6),
2474 [ITEM_ICMP6_TYPE] = {
2476 .help = "ICMPv6 type",
2477 .next = NEXT(item_icmp6, NEXT_ENTRY(UNSIGNED), item_param),
2478 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6,
2481 [ITEM_ICMP6_CODE] = {
2483 .help = "ICMPv6 code",
2484 .next = NEXT(item_icmp6, NEXT_ENTRY(UNSIGNED), item_param),
2485 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6,
2488 [ITEM_ICMP6_ND_NS] = {
2489 .name = "icmp6_nd_ns",
2490 .help = "match ICMPv6 neighbor discovery solicitation",
2491 .priv = PRIV_ITEM(ICMP6_ND_NS,
2492 sizeof(struct rte_flow_item_icmp6_nd_ns)),
2493 .next = NEXT(item_icmp6_nd_ns),
2496 [ITEM_ICMP6_ND_NS_TARGET_ADDR] = {
2497 .name = "target_addr",
2498 .help = "target address",
2499 .next = NEXT(item_icmp6_nd_ns, NEXT_ENTRY(IPV6_ADDR),
2501 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6_nd_ns,
2504 [ITEM_ICMP6_ND_NA] = {
2505 .name = "icmp6_nd_na",
2506 .help = "match ICMPv6 neighbor discovery advertisement",
2507 .priv = PRIV_ITEM(ICMP6_ND_NA,
2508 sizeof(struct rte_flow_item_icmp6_nd_na)),
2509 .next = NEXT(item_icmp6_nd_na),
2512 [ITEM_ICMP6_ND_NA_TARGET_ADDR] = {
2513 .name = "target_addr",
2514 .help = "target address",
2515 .next = NEXT(item_icmp6_nd_na, NEXT_ENTRY(IPV6_ADDR),
2517 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6_nd_na,
2520 [ITEM_ICMP6_ND_OPT] = {
2521 .name = "icmp6_nd_opt",
2522 .help = "match presence of any ICMPv6 neighbor discovery"
2524 .priv = PRIV_ITEM(ICMP6_ND_OPT,
2525 sizeof(struct rte_flow_item_icmp6_nd_opt)),
2526 .next = NEXT(item_icmp6_nd_opt),
2529 [ITEM_ICMP6_ND_OPT_TYPE] = {
2531 .help = "ND option type",
2532 .next = NEXT(item_icmp6_nd_opt, NEXT_ENTRY(UNSIGNED),
2534 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6_nd_opt,
2537 [ITEM_ICMP6_ND_OPT_SLA_ETH] = {
2538 .name = "icmp6_nd_opt_sla_eth",
2539 .help = "match ICMPv6 neighbor discovery source Ethernet"
2540 " link-layer address option",
2542 (ICMP6_ND_OPT_SLA_ETH,
2543 sizeof(struct rte_flow_item_icmp6_nd_opt_sla_eth)),
2544 .next = NEXT(item_icmp6_nd_opt_sla_eth),
2547 [ITEM_ICMP6_ND_OPT_SLA_ETH_SLA] = {
2549 .help = "source Ethernet LLA",
2550 .next = NEXT(item_icmp6_nd_opt_sla_eth, NEXT_ENTRY(MAC_ADDR),
2552 .args = ARGS(ARGS_ENTRY_HTON
2553 (struct rte_flow_item_icmp6_nd_opt_sla_eth, sla)),
2555 [ITEM_ICMP6_ND_OPT_TLA_ETH] = {
2556 .name = "icmp6_nd_opt_tla_eth",
2557 .help = "match ICMPv6 neighbor discovery target Ethernet"
2558 " link-layer address option",
2560 (ICMP6_ND_OPT_TLA_ETH,
2561 sizeof(struct rte_flow_item_icmp6_nd_opt_tla_eth)),
2562 .next = NEXT(item_icmp6_nd_opt_tla_eth),
2565 [ITEM_ICMP6_ND_OPT_TLA_ETH_TLA] = {
2567 .help = "target Ethernet LLA",
2568 .next = NEXT(item_icmp6_nd_opt_tla_eth, NEXT_ENTRY(MAC_ADDR),
2570 .args = ARGS(ARGS_ENTRY_HTON
2571 (struct rte_flow_item_icmp6_nd_opt_tla_eth, tla)),
2575 .help = "match metadata header",
2576 .priv = PRIV_ITEM(META, sizeof(struct rte_flow_item_meta)),
2577 .next = NEXT(item_meta),
2580 [ITEM_META_DATA] = {
2582 .help = "metadata value",
2583 .next = NEXT(item_meta, NEXT_ENTRY(UNSIGNED), item_param),
2584 .args = ARGS(ARGS_ENTRY_MASK(struct rte_flow_item_meta,
2585 data, "\xff\xff\xff\xff")),
2589 .help = "match GRE key",
2590 .priv = PRIV_ITEM(GRE_KEY, sizeof(rte_be32_t)),
2591 .next = NEXT(item_gre_key),
2594 [ITEM_GRE_KEY_VALUE] = {
2596 .help = "key value",
2597 .next = NEXT(item_gre_key, NEXT_ENTRY(UNSIGNED), item_param),
2598 .args = ARGS(ARG_ENTRY_HTON(rte_be32_t)),
2602 .help = "match GTP extension header with type 0x85",
2603 .priv = PRIV_ITEM(GTP_PSC,
2604 sizeof(struct rte_flow_item_gtp_psc)),
2605 .next = NEXT(item_gtp_psc),
2608 [ITEM_GTP_PSC_QFI] = {
2610 .help = "QoS flow identifier",
2611 .next = NEXT(item_gtp_psc, NEXT_ENTRY(UNSIGNED), item_param),
2612 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gtp_psc,
2615 [ITEM_GTP_PSC_PDU_T] = {
2618 .next = NEXT(item_gtp_psc, NEXT_ENTRY(UNSIGNED), item_param),
2619 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gtp_psc,
2624 .help = "match PPPoE session header",
2625 .priv = PRIV_ITEM(PPPOES, sizeof(struct rte_flow_item_pppoe)),
2626 .next = NEXT(item_pppoes),
2631 .help = "match PPPoE discovery header",
2632 .priv = PRIV_ITEM(PPPOED, sizeof(struct rte_flow_item_pppoe)),
2633 .next = NEXT(item_pppoed),
2636 [ITEM_PPPOE_SEID] = {
2638 .help = "session identifier",
2639 .next = NEXT(item_pppoes, NEXT_ENTRY(UNSIGNED), item_param),
2640 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_pppoe,
2643 [ITEM_PPPOE_PROTO_ID] = {
2645 .help = "match PPPoE session protocol identifier",
2646 .priv = PRIV_ITEM(PPPOE_PROTO_ID,
2647 sizeof(struct rte_flow_item_pppoe_proto_id)),
2648 .next = NEXT(item_pppoe_proto_id),
2653 .help = "matches higig2 header",
2654 .priv = PRIV_ITEM(HIGIG2,
2655 sizeof(struct rte_flow_item_higig2_hdr)),
2656 .next = NEXT(item_higig2),
2659 [ITEM_HIGIG2_CLASSIFICATION] = {
2660 .name = "classification",
2661 .help = "matches classification of higig2 header",
2662 .next = NEXT(item_higig2, NEXT_ENTRY(UNSIGNED), item_param),
2663 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_higig2_hdr,
2664 hdr.ppt1.classification)),
2666 [ITEM_HIGIG2_VID] = {
2668 .help = "matches vid of higig2 header",
2669 .next = NEXT(item_higig2, NEXT_ENTRY(UNSIGNED), item_param),
2670 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_higig2_hdr,
2675 .help = "match tag value",
2676 .priv = PRIV_ITEM(TAG, sizeof(struct rte_flow_item_tag)),
2677 .next = NEXT(item_tag),
2682 .help = "tag value to match",
2683 .next = NEXT(item_tag, NEXT_ENTRY(UNSIGNED), item_param),
2684 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_tag, data)),
2686 [ITEM_TAG_INDEX] = {
2688 .help = "index of tag array to match",
2689 .next = NEXT(item_tag, NEXT_ENTRY(UNSIGNED),
2690 NEXT_ENTRY(ITEM_PARAM_IS)),
2691 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_tag, index)),
2693 [ITEM_L2TPV3OIP] = {
2694 .name = "l2tpv3oip",
2695 .help = "match L2TPv3 over IP header",
2696 .priv = PRIV_ITEM(L2TPV3OIP,
2697 sizeof(struct rte_flow_item_l2tpv3oip)),
2698 .next = NEXT(item_l2tpv3oip),
2701 [ITEM_L2TPV3OIP_SESSION_ID] = {
2702 .name = "session_id",
2703 .help = "session identifier",
2704 .next = NEXT(item_l2tpv3oip, NEXT_ENTRY(UNSIGNED), item_param),
2705 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_l2tpv3oip,
2710 .help = "match ESP header",
2711 .priv = PRIV_ITEM(ESP, sizeof(struct rte_flow_item_esp)),
2712 .next = NEXT(item_esp),
2717 .help = "security policy index",
2718 .next = NEXT(item_esp, NEXT_ENTRY(UNSIGNED), item_param),
2719 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_esp,
2724 .help = "match AH header",
2725 .priv = PRIV_ITEM(AH, sizeof(struct rte_flow_item_ah)),
2726 .next = NEXT(item_ah),
2731 .help = "security parameters index",
2732 .next = NEXT(item_ah, NEXT_ENTRY(UNSIGNED), item_param),
2733 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ah, spi)),
2737 .help = "match pfcp header",
2738 .priv = PRIV_ITEM(PFCP, sizeof(struct rte_flow_item_pfcp)),
2739 .next = NEXT(item_pfcp),
2742 [ITEM_PFCP_S_FIELD] = {
2745 .next = NEXT(item_pfcp, NEXT_ENTRY(UNSIGNED), item_param),
2746 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_pfcp,
2749 [ITEM_PFCP_SEID] = {
2751 .help = "session endpoint identifier",
2752 .next = NEXT(item_pfcp, NEXT_ENTRY(UNSIGNED), item_param),
2753 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_pfcp, seid)),
2755 /* Validate/create actions. */
2758 .help = "submit a list of associated actions",
2759 .next = NEXT(next_action),
2764 .help = "specify next action",
2765 .next = NEXT(next_action),
2769 .help = "end list of actions",
2770 .priv = PRIV_ACTION(END, 0),
2775 .help = "no-op action",
2776 .priv = PRIV_ACTION(VOID, 0),
2777 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2780 [ACTION_PASSTHRU] = {
2782 .help = "let subsequent rule process matched packets",
2783 .priv = PRIV_ACTION(PASSTHRU, 0),
2784 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2789 .help = "redirect traffic to a given group",
2790 .priv = PRIV_ACTION(JUMP, sizeof(struct rte_flow_action_jump)),
2791 .next = NEXT(action_jump),
2794 [ACTION_JUMP_GROUP] = {
2796 .help = "group to redirect traffic to",
2797 .next = NEXT(action_jump, NEXT_ENTRY(UNSIGNED)),
2798 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_jump, group)),
2799 .call = parse_vc_conf,
2803 .help = "attach 32 bit value to packets",
2804 .priv = PRIV_ACTION(MARK, sizeof(struct rte_flow_action_mark)),
2805 .next = NEXT(action_mark),
2808 [ACTION_MARK_ID] = {
2810 .help = "32 bit value to return with packets",
2811 .next = NEXT(action_mark, NEXT_ENTRY(UNSIGNED)),
2812 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_mark, id)),
2813 .call = parse_vc_conf,
2817 .help = "flag packets",
2818 .priv = PRIV_ACTION(FLAG, 0),
2819 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2824 .help = "assign packets to a given queue index",
2825 .priv = PRIV_ACTION(QUEUE,
2826 sizeof(struct rte_flow_action_queue)),
2827 .next = NEXT(action_queue),
2830 [ACTION_QUEUE_INDEX] = {
2832 .help = "queue index to use",
2833 .next = NEXT(action_queue, NEXT_ENTRY(UNSIGNED)),
2834 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_queue, index)),
2835 .call = parse_vc_conf,
2839 .help = "drop packets (note: passthru has priority)",
2840 .priv = PRIV_ACTION(DROP, 0),
2841 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2846 .help = "enable counters for this rule",
2847 .priv = PRIV_ACTION(COUNT,
2848 sizeof(struct rte_flow_action_count)),
2849 .next = NEXT(action_count),
2852 [ACTION_COUNT_ID] = {
2853 .name = "identifier",
2854 .help = "counter identifier to use",
2855 .next = NEXT(action_count, NEXT_ENTRY(UNSIGNED)),
2856 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_count, id)),
2857 .call = parse_vc_conf,
2859 [ACTION_COUNT_SHARED] = {
2861 .help = "shared counter",
2862 .next = NEXT(action_count, NEXT_ENTRY(BOOLEAN)),
2863 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_count,
2865 .call = parse_vc_conf,
2869 .help = "spread packets among several queues",
2870 .priv = PRIV_ACTION(RSS, sizeof(struct action_rss_data)),
2871 .next = NEXT(action_rss),
2872 .call = parse_vc_action_rss,
2874 [ACTION_RSS_FUNC] = {
2876 .help = "RSS hash function to apply",
2877 .next = NEXT(action_rss,
2878 NEXT_ENTRY(ACTION_RSS_FUNC_DEFAULT,
2879 ACTION_RSS_FUNC_TOEPLITZ,
2880 ACTION_RSS_FUNC_SIMPLE_XOR,
2881 ACTION_RSS_FUNC_SYMMETRIC_TOEPLITZ)),
2883 [ACTION_RSS_FUNC_DEFAULT] = {
2885 .help = "default hash function",
2886 .call = parse_vc_action_rss_func,
2888 [ACTION_RSS_FUNC_TOEPLITZ] = {
2890 .help = "Toeplitz hash function",
2891 .call = parse_vc_action_rss_func,
2893 [ACTION_RSS_FUNC_SIMPLE_XOR] = {
2894 .name = "simple_xor",
2895 .help = "simple XOR hash function",
2896 .call = parse_vc_action_rss_func,
2898 [ACTION_RSS_FUNC_SYMMETRIC_TOEPLITZ] = {
2899 .name = "symmetric_toeplitz",
2900 .help = "Symmetric Toeplitz hash function",
2901 .call = parse_vc_action_rss_func,
2903 [ACTION_RSS_LEVEL] = {
2905 .help = "encapsulation level for \"types\"",
2906 .next = NEXT(action_rss, NEXT_ENTRY(UNSIGNED)),
2907 .args = ARGS(ARGS_ENTRY_ARB
2908 (offsetof(struct action_rss_data, conf) +
2909 offsetof(struct rte_flow_action_rss, level),
2910 sizeof(((struct rte_flow_action_rss *)0)->
2913 [ACTION_RSS_TYPES] = {
2915 .help = "specific RSS hash types",
2916 .next = NEXT(action_rss, NEXT_ENTRY(ACTION_RSS_TYPE)),
2918 [ACTION_RSS_TYPE] = {
2920 .help = "RSS hash type",
2921 .call = parse_vc_action_rss_type,
2922 .comp = comp_vc_action_rss_type,
2924 [ACTION_RSS_KEY] = {
2926 .help = "RSS hash key",
2927 .next = NEXT(action_rss, NEXT_ENTRY(HEX)),
2928 .args = ARGS(ARGS_ENTRY_ARB(0, 0),
2930 (offsetof(struct action_rss_data, conf) +
2931 offsetof(struct rte_flow_action_rss, key_len),
2932 sizeof(((struct rte_flow_action_rss *)0)->
2934 ARGS_ENTRY(struct action_rss_data, key)),
2936 [ACTION_RSS_KEY_LEN] = {
2938 .help = "RSS hash key length in bytes",
2939 .next = NEXT(action_rss, NEXT_ENTRY(UNSIGNED)),
2940 .args = ARGS(ARGS_ENTRY_ARB_BOUNDED
2941 (offsetof(struct action_rss_data, conf) +
2942 offsetof(struct rte_flow_action_rss, key_len),
2943 sizeof(((struct rte_flow_action_rss *)0)->
2946 RSS_HASH_KEY_LENGTH)),
2948 [ACTION_RSS_QUEUES] = {
2950 .help = "queue indices to use",
2951 .next = NEXT(action_rss, NEXT_ENTRY(ACTION_RSS_QUEUE)),
2952 .call = parse_vc_conf,
2954 [ACTION_RSS_QUEUE] = {
2956 .help = "queue index",
2957 .call = parse_vc_action_rss_queue,
2958 .comp = comp_vc_action_rss_queue,
2962 .help = "direct traffic to physical function",
2963 .priv = PRIV_ACTION(PF, 0),
2964 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2969 .help = "direct traffic to a virtual function ID",
2970 .priv = PRIV_ACTION(VF, sizeof(struct rte_flow_action_vf)),
2971 .next = NEXT(action_vf),
2974 [ACTION_VF_ORIGINAL] = {
2976 .help = "use original VF ID if possible",
2977 .next = NEXT(action_vf, NEXT_ENTRY(BOOLEAN)),
2978 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_vf,
2980 .call = parse_vc_conf,
2985 .next = NEXT(action_vf, NEXT_ENTRY(UNSIGNED)),
2986 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_vf, id)),
2987 .call = parse_vc_conf,
2989 [ACTION_PHY_PORT] = {
2991 .help = "direct packets to physical port index",
2992 .priv = PRIV_ACTION(PHY_PORT,
2993 sizeof(struct rte_flow_action_phy_port)),
2994 .next = NEXT(action_phy_port),
2997 [ACTION_PHY_PORT_ORIGINAL] = {
2999 .help = "use original port index if possible",
3000 .next = NEXT(action_phy_port, NEXT_ENTRY(BOOLEAN)),
3001 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_phy_port,
3003 .call = parse_vc_conf,
3005 [ACTION_PHY_PORT_INDEX] = {
3007 .help = "physical port index",
3008 .next = NEXT(action_phy_port, NEXT_ENTRY(UNSIGNED)),
3009 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_phy_port,
3011 .call = parse_vc_conf,
3013 [ACTION_PORT_ID] = {
3015 .help = "direct matching traffic to a given DPDK port ID",
3016 .priv = PRIV_ACTION(PORT_ID,
3017 sizeof(struct rte_flow_action_port_id)),
3018 .next = NEXT(action_port_id),
3021 [ACTION_PORT_ID_ORIGINAL] = {
3023 .help = "use original DPDK port ID if possible",
3024 .next = NEXT(action_port_id, NEXT_ENTRY(BOOLEAN)),
3025 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_port_id,
3027 .call = parse_vc_conf,
3029 [ACTION_PORT_ID_ID] = {
3031 .help = "DPDK port ID",
3032 .next = NEXT(action_port_id, NEXT_ENTRY(UNSIGNED)),
3033 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_port_id, id)),
3034 .call = parse_vc_conf,
3038 .help = "meter the directed packets at given id",
3039 .priv = PRIV_ACTION(METER,
3040 sizeof(struct rte_flow_action_meter)),
3041 .next = NEXT(action_meter),
3044 [ACTION_METER_ID] = {
3046 .help = "meter id to use",
3047 .next = NEXT(action_meter, NEXT_ENTRY(UNSIGNED)),
3048 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_meter, mtr_id)),
3049 .call = parse_vc_conf,
3051 [ACTION_OF_SET_MPLS_TTL] = {
3052 .name = "of_set_mpls_ttl",
3053 .help = "OpenFlow's OFPAT_SET_MPLS_TTL",
3056 sizeof(struct rte_flow_action_of_set_mpls_ttl)),
3057 .next = NEXT(action_of_set_mpls_ttl),
3060 [ACTION_OF_SET_MPLS_TTL_MPLS_TTL] = {
3063 .next = NEXT(action_of_set_mpls_ttl, NEXT_ENTRY(UNSIGNED)),
3064 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_of_set_mpls_ttl,
3066 .call = parse_vc_conf,
3068 [ACTION_OF_DEC_MPLS_TTL] = {
3069 .name = "of_dec_mpls_ttl",
3070 .help = "OpenFlow's OFPAT_DEC_MPLS_TTL",
3071 .priv = PRIV_ACTION(OF_DEC_MPLS_TTL, 0),
3072 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3075 [ACTION_OF_SET_NW_TTL] = {
3076 .name = "of_set_nw_ttl",
3077 .help = "OpenFlow's OFPAT_SET_NW_TTL",
3080 sizeof(struct rte_flow_action_of_set_nw_ttl)),
3081 .next = NEXT(action_of_set_nw_ttl),
3084 [ACTION_OF_SET_NW_TTL_NW_TTL] = {
3087 .next = NEXT(action_of_set_nw_ttl, NEXT_ENTRY(UNSIGNED)),
3088 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_of_set_nw_ttl,
3090 .call = parse_vc_conf,
3092 [ACTION_OF_DEC_NW_TTL] = {
3093 .name = "of_dec_nw_ttl",
3094 .help = "OpenFlow's OFPAT_DEC_NW_TTL",
3095 .priv = PRIV_ACTION(OF_DEC_NW_TTL, 0),
3096 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3099 [ACTION_OF_COPY_TTL_OUT] = {
3100 .name = "of_copy_ttl_out",
3101 .help = "OpenFlow's OFPAT_COPY_TTL_OUT",
3102 .priv = PRIV_ACTION(OF_COPY_TTL_OUT, 0),
3103 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3106 [ACTION_OF_COPY_TTL_IN] = {
3107 .name = "of_copy_ttl_in",
3108 .help = "OpenFlow's OFPAT_COPY_TTL_IN",
3109 .priv = PRIV_ACTION(OF_COPY_TTL_IN, 0),
3110 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3113 [ACTION_OF_POP_VLAN] = {
3114 .name = "of_pop_vlan",
3115 .help = "OpenFlow's OFPAT_POP_VLAN",
3116 .priv = PRIV_ACTION(OF_POP_VLAN, 0),
3117 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3120 [ACTION_OF_PUSH_VLAN] = {
3121 .name = "of_push_vlan",
3122 .help = "OpenFlow's OFPAT_PUSH_VLAN",
3125 sizeof(struct rte_flow_action_of_push_vlan)),
3126 .next = NEXT(action_of_push_vlan),
3129 [ACTION_OF_PUSH_VLAN_ETHERTYPE] = {
3130 .name = "ethertype",
3131 .help = "EtherType",
3132 .next = NEXT(action_of_push_vlan, NEXT_ENTRY(UNSIGNED)),
3133 .args = ARGS(ARGS_ENTRY_HTON
3134 (struct rte_flow_action_of_push_vlan,
3136 .call = parse_vc_conf,
3138 [ACTION_OF_SET_VLAN_VID] = {
3139 .name = "of_set_vlan_vid",
3140 .help = "OpenFlow's OFPAT_SET_VLAN_VID",
3143 sizeof(struct rte_flow_action_of_set_vlan_vid)),
3144 .next = NEXT(action_of_set_vlan_vid),
3147 [ACTION_OF_SET_VLAN_VID_VLAN_VID] = {
3150 .next = NEXT(action_of_set_vlan_vid, NEXT_ENTRY(UNSIGNED)),
3151 .args = ARGS(ARGS_ENTRY_HTON
3152 (struct rte_flow_action_of_set_vlan_vid,
3154 .call = parse_vc_conf,
3156 [ACTION_OF_SET_VLAN_PCP] = {
3157 .name = "of_set_vlan_pcp",
3158 .help = "OpenFlow's OFPAT_SET_VLAN_PCP",
3161 sizeof(struct rte_flow_action_of_set_vlan_pcp)),
3162 .next = NEXT(action_of_set_vlan_pcp),
3165 [ACTION_OF_SET_VLAN_PCP_VLAN_PCP] = {
3167 .help = "VLAN priority",
3168 .next = NEXT(action_of_set_vlan_pcp, NEXT_ENTRY(UNSIGNED)),
3169 .args = ARGS(ARGS_ENTRY_HTON
3170 (struct rte_flow_action_of_set_vlan_pcp,
3172 .call = parse_vc_conf,
3174 [ACTION_OF_POP_MPLS] = {
3175 .name = "of_pop_mpls",
3176 .help = "OpenFlow's OFPAT_POP_MPLS",
3177 .priv = PRIV_ACTION(OF_POP_MPLS,
3178 sizeof(struct rte_flow_action_of_pop_mpls)),
3179 .next = NEXT(action_of_pop_mpls),
3182 [ACTION_OF_POP_MPLS_ETHERTYPE] = {
3183 .name = "ethertype",
3184 .help = "EtherType",
3185 .next = NEXT(action_of_pop_mpls, NEXT_ENTRY(UNSIGNED)),
3186 .args = ARGS(ARGS_ENTRY_HTON
3187 (struct rte_flow_action_of_pop_mpls,
3189 .call = parse_vc_conf,
3191 [ACTION_OF_PUSH_MPLS] = {
3192 .name = "of_push_mpls",
3193 .help = "OpenFlow's OFPAT_PUSH_MPLS",
3196 sizeof(struct rte_flow_action_of_push_mpls)),
3197 .next = NEXT(action_of_push_mpls),
3200 [ACTION_OF_PUSH_MPLS_ETHERTYPE] = {
3201 .name = "ethertype",
3202 .help = "EtherType",
3203 .next = NEXT(action_of_push_mpls, NEXT_ENTRY(UNSIGNED)),
3204 .args = ARGS(ARGS_ENTRY_HTON
3205 (struct rte_flow_action_of_push_mpls,
3207 .call = parse_vc_conf,
3209 [ACTION_VXLAN_ENCAP] = {
3210 .name = "vxlan_encap",
3211 .help = "VXLAN encapsulation, uses configuration set by \"set"
3213 .priv = PRIV_ACTION(VXLAN_ENCAP,
3214 sizeof(struct action_vxlan_encap_data)),
3215 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3216 .call = parse_vc_action_vxlan_encap,
3218 [ACTION_VXLAN_DECAP] = {
3219 .name = "vxlan_decap",
3220 .help = "Performs a decapsulation action by stripping all"
3221 " headers of the VXLAN tunnel network overlay from the"
3223 .priv = PRIV_ACTION(VXLAN_DECAP, 0),
3224 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3227 [ACTION_NVGRE_ENCAP] = {
3228 .name = "nvgre_encap",
3229 .help = "NVGRE encapsulation, uses configuration set by \"set"
3231 .priv = PRIV_ACTION(NVGRE_ENCAP,
3232 sizeof(struct action_nvgre_encap_data)),
3233 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3234 .call = parse_vc_action_nvgre_encap,
3236 [ACTION_NVGRE_DECAP] = {
3237 .name = "nvgre_decap",
3238 .help = "Performs a decapsulation action by stripping all"
3239 " headers of the NVGRE tunnel network overlay from the"
3241 .priv = PRIV_ACTION(NVGRE_DECAP, 0),
3242 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3245 [ACTION_L2_ENCAP] = {
3247 .help = "l2 encap, uses configuration set by"
3248 " \"set l2_encap\"",
3249 .priv = PRIV_ACTION(RAW_ENCAP,
3250 sizeof(struct action_raw_encap_data)),
3251 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3252 .call = parse_vc_action_l2_encap,
3254 [ACTION_L2_DECAP] = {
3256 .help = "l2 decap, uses configuration set by"
3257 " \"set l2_decap\"",
3258 .priv = PRIV_ACTION(RAW_DECAP,
3259 sizeof(struct action_raw_decap_data)),
3260 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3261 .call = parse_vc_action_l2_decap,
3263 [ACTION_MPLSOGRE_ENCAP] = {
3264 .name = "mplsogre_encap",
3265 .help = "mplsogre encapsulation, uses configuration set by"
3266 " \"set mplsogre_encap\"",
3267 .priv = PRIV_ACTION(RAW_ENCAP,
3268 sizeof(struct action_raw_encap_data)),
3269 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3270 .call = parse_vc_action_mplsogre_encap,
3272 [ACTION_MPLSOGRE_DECAP] = {
3273 .name = "mplsogre_decap",
3274 .help = "mplsogre decapsulation, uses configuration set by"
3275 " \"set mplsogre_decap\"",
3276 .priv = PRIV_ACTION(RAW_DECAP,
3277 sizeof(struct action_raw_decap_data)),
3278 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3279 .call = parse_vc_action_mplsogre_decap,
3281 [ACTION_MPLSOUDP_ENCAP] = {
3282 .name = "mplsoudp_encap",
3283 .help = "mplsoudp encapsulation, uses configuration set by"
3284 " \"set mplsoudp_encap\"",
3285 .priv = PRIV_ACTION(RAW_ENCAP,
3286 sizeof(struct action_raw_encap_data)),
3287 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3288 .call = parse_vc_action_mplsoudp_encap,
3290 [ACTION_MPLSOUDP_DECAP] = {
3291 .name = "mplsoudp_decap",
3292 .help = "mplsoudp decapsulation, uses configuration set by"
3293 " \"set mplsoudp_decap\"",
3294 .priv = PRIV_ACTION(RAW_DECAP,
3295 sizeof(struct action_raw_decap_data)),
3296 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3297 .call = parse_vc_action_mplsoudp_decap,
3299 [ACTION_SET_IPV4_SRC] = {
3300 .name = "set_ipv4_src",
3301 .help = "Set a new IPv4 source address in the outermost"
3303 .priv = PRIV_ACTION(SET_IPV4_SRC,
3304 sizeof(struct rte_flow_action_set_ipv4)),
3305 .next = NEXT(action_set_ipv4_src),
3308 [ACTION_SET_IPV4_SRC_IPV4_SRC] = {
3309 .name = "ipv4_addr",
3310 .help = "new IPv4 source address to set",
3311 .next = NEXT(action_set_ipv4_src, NEXT_ENTRY(IPV4_ADDR)),
3312 .args = ARGS(ARGS_ENTRY_HTON
3313 (struct rte_flow_action_set_ipv4, ipv4_addr)),
3314 .call = parse_vc_conf,
3316 [ACTION_SET_IPV4_DST] = {
3317 .name = "set_ipv4_dst",
3318 .help = "Set a new IPv4 destination address in the outermost"
3320 .priv = PRIV_ACTION(SET_IPV4_DST,
3321 sizeof(struct rte_flow_action_set_ipv4)),
3322 .next = NEXT(action_set_ipv4_dst),
3325 [ACTION_SET_IPV4_DST_IPV4_DST] = {
3326 .name = "ipv4_addr",
3327 .help = "new IPv4 destination address to set",
3328 .next = NEXT(action_set_ipv4_dst, NEXT_ENTRY(IPV4_ADDR)),
3329 .args = ARGS(ARGS_ENTRY_HTON
3330 (struct rte_flow_action_set_ipv4, ipv4_addr)),
3331 .call = parse_vc_conf,
3333 [ACTION_SET_IPV6_SRC] = {
3334 .name = "set_ipv6_src",
3335 .help = "Set a new IPv6 source address in the outermost"
3337 .priv = PRIV_ACTION(SET_IPV6_SRC,
3338 sizeof(struct rte_flow_action_set_ipv6)),
3339 .next = NEXT(action_set_ipv6_src),
3342 [ACTION_SET_IPV6_SRC_IPV6_SRC] = {
3343 .name = "ipv6_addr",
3344 .help = "new IPv6 source address to set",
3345 .next = NEXT(action_set_ipv6_src, NEXT_ENTRY(IPV6_ADDR)),
3346 .args = ARGS(ARGS_ENTRY_HTON
3347 (struct rte_flow_action_set_ipv6, ipv6_addr)),
3348 .call = parse_vc_conf,
3350 [ACTION_SET_IPV6_DST] = {
3351 .name = "set_ipv6_dst",
3352 .help = "Set a new IPv6 destination address in the outermost"
3354 .priv = PRIV_ACTION(SET_IPV6_DST,
3355 sizeof(struct rte_flow_action_set_ipv6)),
3356 .next = NEXT(action_set_ipv6_dst),
3359 [ACTION_SET_IPV6_DST_IPV6_DST] = {
3360 .name = "ipv6_addr",
3361 .help = "new IPv6 destination address to set",
3362 .next = NEXT(action_set_ipv6_dst, NEXT_ENTRY(IPV6_ADDR)),
3363 .args = ARGS(ARGS_ENTRY_HTON
3364 (struct rte_flow_action_set_ipv6, ipv6_addr)),
3365 .call = parse_vc_conf,
3367 [ACTION_SET_TP_SRC] = {
3368 .name = "set_tp_src",
3369 .help = "set a new source port number in the outermost"
3371 .priv = PRIV_ACTION(SET_TP_SRC,
3372 sizeof(struct rte_flow_action_set_tp)),
3373 .next = NEXT(action_set_tp_src),
3376 [ACTION_SET_TP_SRC_TP_SRC] = {
3378 .help = "new source port number to set",
3379 .next = NEXT(action_set_tp_src, NEXT_ENTRY(UNSIGNED)),
3380 .args = ARGS(ARGS_ENTRY_HTON
3381 (struct rte_flow_action_set_tp, port)),
3382 .call = parse_vc_conf,
3384 [ACTION_SET_TP_DST] = {
3385 .name = "set_tp_dst",
3386 .help = "set a new destination port number in the outermost"
3388 .priv = PRIV_ACTION(SET_TP_DST,
3389 sizeof(struct rte_flow_action_set_tp)),
3390 .next = NEXT(action_set_tp_dst),
3393 [ACTION_SET_TP_DST_TP_DST] = {
3395 .help = "new destination port number to set",
3396 .next = NEXT(action_set_tp_dst, NEXT_ENTRY(UNSIGNED)),
3397 .args = ARGS(ARGS_ENTRY_HTON
3398 (struct rte_flow_action_set_tp, port)),
3399 .call = parse_vc_conf,
3401 [ACTION_MAC_SWAP] = {
3403 .help = "Swap the source and destination MAC addresses"
3404 " in the outermost Ethernet header",
3405 .priv = PRIV_ACTION(MAC_SWAP, 0),
3406 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3409 [ACTION_DEC_TTL] = {
3411 .help = "decrease network TTL if available",
3412 .priv = PRIV_ACTION(DEC_TTL, 0),
3413 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3416 [ACTION_SET_TTL] = {
3418 .help = "set ttl value",
3419 .priv = PRIV_ACTION(SET_TTL,
3420 sizeof(struct rte_flow_action_set_ttl)),
3421 .next = NEXT(action_set_ttl),
3424 [ACTION_SET_TTL_TTL] = {
3425 .name = "ttl_value",
3426 .help = "new ttl value to set",
3427 .next = NEXT(action_set_ttl, NEXT_ENTRY(UNSIGNED)),
3428 .args = ARGS(ARGS_ENTRY_HTON
3429 (struct rte_flow_action_set_ttl, ttl_value)),
3430 .call = parse_vc_conf,
3432 [ACTION_SET_MAC_SRC] = {
3433 .name = "set_mac_src",
3434 .help = "set source mac address",
3435 .priv = PRIV_ACTION(SET_MAC_SRC,
3436 sizeof(struct rte_flow_action_set_mac)),
3437 .next = NEXT(action_set_mac_src),
3440 [ACTION_SET_MAC_SRC_MAC_SRC] = {
3442 .help = "new source mac address",
3443 .next = NEXT(action_set_mac_src, NEXT_ENTRY(MAC_ADDR)),
3444 .args = ARGS(ARGS_ENTRY_HTON
3445 (struct rte_flow_action_set_mac, mac_addr)),
3446 .call = parse_vc_conf,
3448 [ACTION_SET_MAC_DST] = {
3449 .name = "set_mac_dst",
3450 .help = "set destination mac address",
3451 .priv = PRIV_ACTION(SET_MAC_DST,
3452 sizeof(struct rte_flow_action_set_mac)),
3453 .next = NEXT(action_set_mac_dst),
3456 [ACTION_SET_MAC_DST_MAC_DST] = {
3458 .help = "new destination mac address to set",
3459 .next = NEXT(action_set_mac_dst, NEXT_ENTRY(MAC_ADDR)),
3460 .args = ARGS(ARGS_ENTRY_HTON
3461 (struct rte_flow_action_set_mac, mac_addr)),
3462 .call = parse_vc_conf,
3464 [ACTION_INC_TCP_SEQ] = {
3465 .name = "inc_tcp_seq",
3466 .help = "increase TCP sequence number",
3467 .priv = PRIV_ACTION(INC_TCP_SEQ, sizeof(rte_be32_t)),
3468 .next = NEXT(action_inc_tcp_seq),
3471 [ACTION_INC_TCP_SEQ_VALUE] = {
3473 .help = "the value to increase TCP sequence number by",
3474 .next = NEXT(action_inc_tcp_seq, NEXT_ENTRY(UNSIGNED)),
3475 .args = ARGS(ARG_ENTRY_HTON(rte_be32_t)),
3476 .call = parse_vc_conf,
3478 [ACTION_DEC_TCP_SEQ] = {
3479 .name = "dec_tcp_seq",
3480 .help = "decrease TCP sequence number",
3481 .priv = PRIV_ACTION(DEC_TCP_SEQ, sizeof(rte_be32_t)),
3482 .next = NEXT(action_dec_tcp_seq),
3485 [ACTION_DEC_TCP_SEQ_VALUE] = {
3487 .help = "the value to decrease TCP sequence number by",
3488 .next = NEXT(action_dec_tcp_seq, NEXT_ENTRY(UNSIGNED)),
3489 .args = ARGS(ARG_ENTRY_HTON(rte_be32_t)),
3490 .call = parse_vc_conf,
3492 [ACTION_INC_TCP_ACK] = {
3493 .name = "inc_tcp_ack",
3494 .help = "increase TCP acknowledgment number",
3495 .priv = PRIV_ACTION(INC_TCP_ACK, sizeof(rte_be32_t)),
3496 .next = NEXT(action_inc_tcp_ack),
3499 [ACTION_INC_TCP_ACK_VALUE] = {
3501 .help = "the value to increase TCP acknowledgment number by",
3502 .next = NEXT(action_inc_tcp_ack, NEXT_ENTRY(UNSIGNED)),
3503 .args = ARGS(ARG_ENTRY_HTON(rte_be32_t)),
3504 .call = parse_vc_conf,
3506 [ACTION_DEC_TCP_ACK] = {
3507 .name = "dec_tcp_ack",
3508 .help = "decrease TCP acknowledgment number",
3509 .priv = PRIV_ACTION(DEC_TCP_ACK, sizeof(rte_be32_t)),
3510 .next = NEXT(action_dec_tcp_ack),
3513 [ACTION_DEC_TCP_ACK_VALUE] = {
3515 .help = "the value to decrease TCP acknowledgment number by",
3516 .next = NEXT(action_dec_tcp_ack, NEXT_ENTRY(UNSIGNED)),
3517 .args = ARGS(ARG_ENTRY_HTON(rte_be32_t)),
3518 .call = parse_vc_conf,
3520 [ACTION_RAW_ENCAP] = {
3521 .name = "raw_encap",
3522 .help = "encapsulation data, defined by set raw_encap",
3523 .priv = PRIV_ACTION(RAW_ENCAP,
3524 sizeof(struct action_raw_encap_data)),
3525 .next = NEXT(action_raw_encap),
3526 .call = parse_vc_action_raw_encap,
3528 [ACTION_RAW_ENCAP_INDEX] = {
3530 .help = "the index of raw_encap_confs",
3531 .next = NEXT(NEXT_ENTRY(ACTION_RAW_ENCAP_INDEX_VALUE)),
3533 [ACTION_RAW_ENCAP_INDEX_VALUE] = {
3536 .help = "unsigned integer value",
3537 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3538 .call = parse_vc_action_raw_encap_index,
3539 .comp = comp_set_raw_index,
3541 [ACTION_RAW_DECAP] = {
3542 .name = "raw_decap",
3543 .help = "decapsulation data, defined by set raw_encap",
3544 .priv = PRIV_ACTION(RAW_DECAP,
3545 sizeof(struct action_raw_decap_data)),
3546 .next = NEXT(action_raw_decap),
3547 .call = parse_vc_action_raw_decap,
3549 [ACTION_RAW_DECAP_INDEX] = {
3551 .help = "the index of raw_encap_confs",
3552 .next = NEXT(NEXT_ENTRY(ACTION_RAW_DECAP_INDEX_VALUE)),
3554 [ACTION_RAW_DECAP_INDEX_VALUE] = {
3557 .help = "unsigned integer value",
3558 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3559 .call = parse_vc_action_raw_decap_index,
3560 .comp = comp_set_raw_index,
3562 /* Top level command. */
3565 .help = "set raw encap/decap data",
3566 .type = "set raw_encap|raw_decap <index> <pattern>",
3567 .next = NEXT(NEXT_ENTRY
3570 .call = parse_set_init,
3572 /* Sub-level commands. */
3574 .name = "raw_encap",
3575 .help = "set raw encap data",
3576 .next = NEXT(next_set_raw),
3577 .args = ARGS(ARGS_ENTRY_ARB_BOUNDED
3578 (offsetof(struct buffer, port),
3579 sizeof(((struct buffer *)0)->port),
3580 0, RAW_ENCAP_CONFS_MAX_NUM - 1)),
3581 .call = parse_set_raw_encap_decap,
3584 .name = "raw_decap",
3585 .help = "set raw decap data",
3586 .next = NEXT(next_set_raw),
3587 .args = ARGS(ARGS_ENTRY_ARB_BOUNDED
3588 (offsetof(struct buffer, port),
3589 sizeof(((struct buffer *)0)->port),
3590 0, RAW_ENCAP_CONFS_MAX_NUM - 1)),
3591 .call = parse_set_raw_encap_decap,
3596 .help = "index of raw_encap/raw_decap data",
3597 .next = NEXT(next_item),
3600 [ACTION_SET_TAG] = {
3603 .priv = PRIV_ACTION(SET_TAG,
3604 sizeof(struct rte_flow_action_set_tag)),
3605 .next = NEXT(action_set_tag),
3608 [ACTION_SET_TAG_INDEX] = {
3610 .help = "index of tag array",
3611 .next = NEXT(action_set_tag, NEXT_ENTRY(UNSIGNED)),
3612 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_set_tag, index)),
3613 .call = parse_vc_conf,
3615 [ACTION_SET_TAG_DATA] = {
3617 .help = "tag value",
3618 .next = NEXT(action_set_tag, NEXT_ENTRY(UNSIGNED)),
3619 .args = ARGS(ARGS_ENTRY
3620 (struct rte_flow_action_set_tag, data)),
3621 .call = parse_vc_conf,
3623 [ACTION_SET_TAG_MASK] = {
3625 .help = "mask for tag value",
3626 .next = NEXT(action_set_tag, NEXT_ENTRY(UNSIGNED)),
3627 .args = ARGS(ARGS_ENTRY
3628 (struct rte_flow_action_set_tag, mask)),
3629 .call = parse_vc_conf,
3631 [ACTION_SET_META] = {
3633 .help = "set metadata",
3634 .priv = PRIV_ACTION(SET_META,
3635 sizeof(struct rte_flow_action_set_meta)),
3636 .next = NEXT(action_set_meta),
3637 .call = parse_vc_action_set_meta,
3639 [ACTION_SET_META_DATA] = {
3641 .help = "metadata value",
3642 .next = NEXT(action_set_meta, NEXT_ENTRY(UNSIGNED)),
3643 .args = ARGS(ARGS_ENTRY
3644 (struct rte_flow_action_set_meta, data)),
3645 .call = parse_vc_conf,
3647 [ACTION_SET_META_MASK] = {
3649 .help = "mask for metadata value",
3650 .next = NEXT(action_set_meta, NEXT_ENTRY(UNSIGNED)),
3651 .args = ARGS(ARGS_ENTRY
3652 (struct rte_flow_action_set_meta, mask)),
3653 .call = parse_vc_conf,
3655 [ACTION_SET_IPV4_DSCP] = {
3656 .name = "set_ipv4_dscp",
3657 .help = "set DSCP value",
3658 .priv = PRIV_ACTION(SET_IPV4_DSCP,
3659 sizeof(struct rte_flow_action_set_dscp)),
3660 .next = NEXT(action_set_ipv4_dscp),
3663 [ACTION_SET_IPV4_DSCP_VALUE] = {
3664 .name = "dscp_value",
3665 .help = "new IPv4 DSCP value to set",
3666 .next = NEXT(action_set_ipv4_dscp, NEXT_ENTRY(UNSIGNED)),
3667 .args = ARGS(ARGS_ENTRY
3668 (struct rte_flow_action_set_dscp, dscp)),
3669 .call = parse_vc_conf,
3671 [ACTION_SET_IPV6_DSCP] = {
3672 .name = "set_ipv6_dscp",
3673 .help = "set DSCP value",
3674 .priv = PRIV_ACTION(SET_IPV6_DSCP,
3675 sizeof(struct rte_flow_action_set_dscp)),
3676 .next = NEXT(action_set_ipv6_dscp),
3679 [ACTION_SET_IPV6_DSCP_VALUE] = {
3680 .name = "dscp_value",
3681 .help = "new IPv6 DSCP value to set",
3682 .next = NEXT(action_set_ipv6_dscp, NEXT_ENTRY(UNSIGNED)),
3683 .args = ARGS(ARGS_ENTRY
3684 (struct rte_flow_action_set_dscp, dscp)),
3685 .call = parse_vc_conf,
3689 /** Remove and return last entry from argument stack. */
3690 static const struct arg *
3691 pop_args(struct context *ctx)
3693 return ctx->args_num ? ctx->args[--ctx->args_num] : NULL;
3696 /** Add entry on top of the argument stack. */
3698 push_args(struct context *ctx, const struct arg *arg)
3700 if (ctx->args_num == CTX_STACK_SIZE)
3702 ctx->args[ctx->args_num++] = arg;
3706 /** Spread value into buffer according to bit-mask. */
3708 arg_entry_bf_fill(void *dst, uintmax_t val, const struct arg *arg)
3710 uint32_t i = arg->size;
3718 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
3727 unsigned int shift = 0;
3728 uint8_t *buf = (uint8_t *)dst + arg->offset + (i -= sub);
3730 for (shift = 0; arg->mask[i] >> shift; ++shift) {
3731 if (!(arg->mask[i] & (1 << shift)))
3736 *buf &= ~(1 << shift);
3737 *buf |= (val & 1) << shift;
3745 /** Compare a string with a partial one of a given length. */
3747 strcmp_partial(const char *full, const char *partial, size_t partial_len)
3749 int r = strncmp(full, partial, partial_len);
3753 if (strlen(full) <= partial_len)
3755 return full[partial_len];
3759 * Parse a prefix length and generate a bit-mask.
3761 * Last argument (ctx->args) is retrieved to determine mask size, storage
3762 * location and whether the result must use network byte ordering.
3765 parse_prefix(struct context *ctx, const struct token *token,
3766 const char *str, unsigned int len,
3767 void *buf, unsigned int size)
3769 const struct arg *arg = pop_args(ctx);
3770 static const uint8_t conv[] = "\x00\x80\xc0\xe0\xf0\xf8\xfc\xfe\xff";
3777 /* Argument is expected. */
3781 u = strtoumax(str, &end, 0);
3782 if (errno || (size_t)(end - str) != len)
3787 extra = arg_entry_bf_fill(NULL, 0, arg);
3796 if (!arg_entry_bf_fill(ctx->object, v, arg) ||
3797 !arg_entry_bf_fill(ctx->objmask, -1, arg))
3804 if (bytes > size || bytes + !!extra > size)
3808 buf = (uint8_t *)ctx->object + arg->offset;
3809 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
3811 memset((uint8_t *)buf + size - bytes, 0xff, bytes);
3812 memset(buf, 0x00, size - bytes);
3814 ((uint8_t *)buf)[size - bytes - 1] = conv[extra];
3818 memset(buf, 0xff, bytes);
3819 memset((uint8_t *)buf + bytes, 0x00, size - bytes);
3821 ((uint8_t *)buf)[bytes] = conv[extra];
3824 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
3827 push_args(ctx, arg);
3831 /** Default parsing function for token name matching. */
3833 parse_default(struct context *ctx, const struct token *token,
3834 const char *str, unsigned int len,
3835 void *buf, unsigned int size)
3840 if (strcmp_partial(token->name, str, len))
3845 /** Parse flow command, initialize output buffer for subsequent tokens. */
3847 parse_init(struct context *ctx, const struct token *token,
3848 const char *str, unsigned int len,
3849 void *buf, unsigned int size)
3851 struct buffer *out = buf;
3853 /* Token name must match. */
3854 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
3856 /* Nothing else to do if there is no buffer. */
3859 /* Make sure buffer is large enough. */
3860 if (size < sizeof(*out))
3862 /* Initialize buffer. */
3863 memset(out, 0x00, sizeof(*out));
3864 memset((uint8_t *)out + sizeof(*out), 0x22, size - sizeof(*out));
3867 ctx->objmask = NULL;
3871 /** Parse tokens for validate/create commands. */
3873 parse_vc(struct context *ctx, const struct token *token,
3874 const char *str, unsigned int len,
3875 void *buf, unsigned int size)
3877 struct buffer *out = buf;
3881 /* Token name must match. */
3882 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
3884 /* Nothing else to do if there is no buffer. */
3887 if (!out->command) {
3888 if (ctx->curr != VALIDATE && ctx->curr != CREATE)
3890 if (sizeof(*out) > size)
3892 out->command = ctx->curr;
3895 ctx->objmask = NULL;
3896 out->args.vc.data = (uint8_t *)out + size;
3900 ctx->object = &out->args.vc.attr;
3901 ctx->objmask = NULL;
3902 switch (ctx->curr) {
3907 out->args.vc.attr.ingress = 1;
3910 out->args.vc.attr.egress = 1;
3913 out->args.vc.attr.transfer = 1;
3916 out->args.vc.pattern =
3917 (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
3919 ctx->object = out->args.vc.pattern;
3920 ctx->objmask = NULL;
3923 out->args.vc.actions =
3924 (void *)RTE_ALIGN_CEIL((uintptr_t)
3925 (out->args.vc.pattern +
3926 out->args.vc.pattern_n),
3928 ctx->object = out->args.vc.actions;
3929 ctx->objmask = NULL;
3936 if (!out->args.vc.actions) {
3937 const struct parse_item_priv *priv = token->priv;
3938 struct rte_flow_item *item =
3939 out->args.vc.pattern + out->args.vc.pattern_n;
3941 data_size = priv->size * 3; /* spec, last, mask */
3942 data = (void *)RTE_ALIGN_FLOOR((uintptr_t)
3943 (out->args.vc.data - data_size),
3945 if ((uint8_t *)item + sizeof(*item) > data)
3947 *item = (struct rte_flow_item){
3950 ++out->args.vc.pattern_n;
3952 ctx->objmask = NULL;
3954 const struct parse_action_priv *priv = token->priv;
3955 struct rte_flow_action *action =
3956 out->args.vc.actions + out->args.vc.actions_n;
3958 data_size = priv->size; /* configuration */
3959 data = (void *)RTE_ALIGN_FLOOR((uintptr_t)
3960 (out->args.vc.data - data_size),
3962 if ((uint8_t *)action + sizeof(*action) > data)
3964 *action = (struct rte_flow_action){
3966 .conf = data_size ? data : NULL,
3968 ++out->args.vc.actions_n;
3969 ctx->object = action;
3970 ctx->objmask = NULL;
3972 memset(data, 0, data_size);
3973 out->args.vc.data = data;
3974 ctx->objdata = data_size;
3978 /** Parse pattern item parameter type. */
3980 parse_vc_spec(struct context *ctx, const struct token *token,
3981 const char *str, unsigned int len,
3982 void *buf, unsigned int size)
3984 struct buffer *out = buf;
3985 struct rte_flow_item *item;
3991 /* Token name must match. */
3992 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
3994 /* Parse parameter types. */
3995 switch (ctx->curr) {
3996 static const enum index prefix[] = NEXT_ENTRY(PREFIX);
4002 case ITEM_PARAM_SPEC:
4005 case ITEM_PARAM_LAST:
4008 case ITEM_PARAM_PREFIX:
4009 /* Modify next token to expect a prefix. */
4010 if (ctx->next_num < 2)
4012 ctx->next[ctx->next_num - 2] = prefix;
4014 case ITEM_PARAM_MASK:
4020 /* Nothing else to do if there is no buffer. */
4023 if (!out->args.vc.pattern_n)
4025 item = &out->args.vc.pattern[out->args.vc.pattern_n - 1];
4026 data_size = ctx->objdata / 3; /* spec, last, mask */
4027 /* Point to selected object. */
4028 ctx->object = out->args.vc.data + (data_size * index);
4030 ctx->objmask = out->args.vc.data + (data_size * 2); /* mask */
4031 item->mask = ctx->objmask;
4033 ctx->objmask = NULL;
4034 /* Update relevant item pointer. */
4035 *((const void **[]){ &item->spec, &item->last, &item->mask })[index] =
4040 /** Parse action configuration field. */
4042 parse_vc_conf(struct context *ctx, const struct token *token,
4043 const char *str, unsigned int len,
4044 void *buf, unsigned int size)
4046 struct buffer *out = buf;
4049 /* Token name must match. */
4050 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
4052 /* Nothing else to do if there is no buffer. */
4055 /* Point to selected object. */
4056 ctx->object = out->args.vc.data;
4057 ctx->objmask = NULL;
4061 /** Parse RSS action. */
4063 parse_vc_action_rss(struct context *ctx, const struct token *token,
4064 const char *str, unsigned int len,
4065 void *buf, unsigned int size)
4067 struct buffer *out = buf;
4068 struct rte_flow_action *action;
4069 struct action_rss_data *action_rss_data;
4073 ret = parse_vc(ctx, token, str, len, buf, size);
4076 /* Nothing else to do if there is no buffer. */
4079 if (!out->args.vc.actions_n)
4081 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4082 /* Point to selected object. */
4083 ctx->object = out->args.vc.data;
4084 ctx->objmask = NULL;
4085 /* Set up default configuration. */
4086 action_rss_data = ctx->object;
4087 *action_rss_data = (struct action_rss_data){
4088 .conf = (struct rte_flow_action_rss){
4089 .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
4092 .key_len = sizeof(action_rss_data->key),
4093 .queue_num = RTE_MIN(nb_rxq, ACTION_RSS_QUEUE_NUM),
4094 .key = action_rss_data->key,
4095 .queue = action_rss_data->queue,
4097 .key = "testpmd's default RSS hash key, "
4098 "override it for better balancing",
4101 for (i = 0; i < action_rss_data->conf.queue_num; ++i)
4102 action_rss_data->queue[i] = i;
4103 if (!port_id_is_invalid(ctx->port, DISABLED_WARN) &&
4104 ctx->port != (portid_t)RTE_PORT_ALL) {
4105 struct rte_eth_dev_info info;
4108 ret2 = rte_eth_dev_info_get(ctx->port, &info);
4112 action_rss_data->conf.key_len =
4113 RTE_MIN(sizeof(action_rss_data->key),
4114 info.hash_key_size);
4116 action->conf = &action_rss_data->conf;
4121 * Parse func field for RSS action.
4123 * The RTE_ETH_HASH_FUNCTION_* value to assign is derived from the
4124 * ACTION_RSS_FUNC_* index that called this function.
4127 parse_vc_action_rss_func(struct context *ctx, const struct token *token,
4128 const char *str, unsigned int len,
4129 void *buf, unsigned int size)
4131 struct action_rss_data *action_rss_data;
4132 enum rte_eth_hash_function func;
4136 /* Token name must match. */
4137 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
4139 switch (ctx->curr) {
4140 case ACTION_RSS_FUNC_DEFAULT:
4141 func = RTE_ETH_HASH_FUNCTION_DEFAULT;
4143 case ACTION_RSS_FUNC_TOEPLITZ:
4144 func = RTE_ETH_HASH_FUNCTION_TOEPLITZ;
4146 case ACTION_RSS_FUNC_SIMPLE_XOR:
4147 func = RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
4149 case ACTION_RSS_FUNC_SYMMETRIC_TOEPLITZ:
4150 func = RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ;
4157 action_rss_data = ctx->object;
4158 action_rss_data->conf.func = func;
4163 * Parse type field for RSS action.
4165 * Valid tokens are type field names and the "end" token.
4168 parse_vc_action_rss_type(struct context *ctx, const struct token *token,
4169 const char *str, unsigned int len,
4170 void *buf, unsigned int size)
4172 static const enum index next[] = NEXT_ENTRY(ACTION_RSS_TYPE);
4173 struct action_rss_data *action_rss_data;
4179 if (ctx->curr != ACTION_RSS_TYPE)
4181 if (!(ctx->objdata >> 16) && ctx->object) {
4182 action_rss_data = ctx->object;
4183 action_rss_data->conf.types = 0;
4185 if (!strcmp_partial("end", str, len)) {
4186 ctx->objdata &= 0xffff;
4189 for (i = 0; rss_type_table[i].str; ++i)
4190 if (!strcmp_partial(rss_type_table[i].str, str, len))
4192 if (!rss_type_table[i].str)
4194 ctx->objdata = 1 << 16 | (ctx->objdata & 0xffff);
4196 if (ctx->next_num == RTE_DIM(ctx->next))
4198 ctx->next[ctx->next_num++] = next;
4201 action_rss_data = ctx->object;
4202 action_rss_data->conf.types |= rss_type_table[i].rss_type;
4207 * Parse queue field for RSS action.
4209 * Valid tokens are queue indices and the "end" token.
4212 parse_vc_action_rss_queue(struct context *ctx, const struct token *token,
4213 const char *str, unsigned int len,
4214 void *buf, unsigned int size)
4216 static const enum index next[] = NEXT_ENTRY(ACTION_RSS_QUEUE);
4217 struct action_rss_data *action_rss_data;
4218 const struct arg *arg;
4225 if (ctx->curr != ACTION_RSS_QUEUE)
4227 i = ctx->objdata >> 16;
4228 if (!strcmp_partial("end", str, len)) {
4229 ctx->objdata &= 0xffff;
4232 if (i >= ACTION_RSS_QUEUE_NUM)
4234 arg = ARGS_ENTRY_ARB(offsetof(struct action_rss_data, queue) +
4235 i * sizeof(action_rss_data->queue[i]),
4236 sizeof(action_rss_data->queue[i]));
4237 if (push_args(ctx, arg))
4239 ret = parse_int(ctx, token, str, len, NULL, 0);
4245 ctx->objdata = i << 16 | (ctx->objdata & 0xffff);
4247 if (ctx->next_num == RTE_DIM(ctx->next))
4249 ctx->next[ctx->next_num++] = next;
4253 action_rss_data = ctx->object;
4254 action_rss_data->conf.queue_num = i;
4255 action_rss_data->conf.queue = i ? action_rss_data->queue : NULL;
4259 /** Parse VXLAN encap action. */
4261 parse_vc_action_vxlan_encap(struct context *ctx, const struct token *token,
4262 const char *str, unsigned int len,
4263 void *buf, unsigned int size)
4265 struct buffer *out = buf;
4266 struct rte_flow_action *action;
4267 struct action_vxlan_encap_data *action_vxlan_encap_data;
4270 ret = parse_vc(ctx, token, str, len, buf, size);
4273 /* Nothing else to do if there is no buffer. */
4276 if (!out->args.vc.actions_n)
4278 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4279 /* Point to selected object. */
4280 ctx->object = out->args.vc.data;
4281 ctx->objmask = NULL;
4282 /* Set up default configuration. */
4283 action_vxlan_encap_data = ctx->object;
4284 *action_vxlan_encap_data = (struct action_vxlan_encap_data){
4285 .conf = (struct rte_flow_action_vxlan_encap){
4286 .definition = action_vxlan_encap_data->items,
4290 .type = RTE_FLOW_ITEM_TYPE_ETH,
4291 .spec = &action_vxlan_encap_data->item_eth,
4292 .mask = &rte_flow_item_eth_mask,
4295 .type = RTE_FLOW_ITEM_TYPE_VLAN,
4296 .spec = &action_vxlan_encap_data->item_vlan,
4297 .mask = &rte_flow_item_vlan_mask,
4300 .type = RTE_FLOW_ITEM_TYPE_IPV4,
4301 .spec = &action_vxlan_encap_data->item_ipv4,
4302 .mask = &rte_flow_item_ipv4_mask,
4305 .type = RTE_FLOW_ITEM_TYPE_UDP,
4306 .spec = &action_vxlan_encap_data->item_udp,
4307 .mask = &rte_flow_item_udp_mask,
4310 .type = RTE_FLOW_ITEM_TYPE_VXLAN,
4311 .spec = &action_vxlan_encap_data->item_vxlan,
4312 .mask = &rte_flow_item_vxlan_mask,
4315 .type = RTE_FLOW_ITEM_TYPE_END,
4320 .tci = vxlan_encap_conf.vlan_tci,
4324 .src_addr = vxlan_encap_conf.ipv4_src,
4325 .dst_addr = vxlan_encap_conf.ipv4_dst,
4328 .src_port = vxlan_encap_conf.udp_src,
4329 .dst_port = vxlan_encap_conf.udp_dst,
4331 .item_vxlan.flags = 0,
4333 memcpy(action_vxlan_encap_data->item_eth.dst.addr_bytes,
4334 vxlan_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
4335 memcpy(action_vxlan_encap_data->item_eth.src.addr_bytes,
4336 vxlan_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
4337 if (!vxlan_encap_conf.select_ipv4) {
4338 memcpy(&action_vxlan_encap_data->item_ipv6.hdr.src_addr,
4339 &vxlan_encap_conf.ipv6_src,
4340 sizeof(vxlan_encap_conf.ipv6_src));
4341 memcpy(&action_vxlan_encap_data->item_ipv6.hdr.dst_addr,
4342 &vxlan_encap_conf.ipv6_dst,
4343 sizeof(vxlan_encap_conf.ipv6_dst));
4344 action_vxlan_encap_data->items[2] = (struct rte_flow_item){
4345 .type = RTE_FLOW_ITEM_TYPE_IPV6,
4346 .spec = &action_vxlan_encap_data->item_ipv6,
4347 .mask = &rte_flow_item_ipv6_mask,
4350 if (!vxlan_encap_conf.select_vlan)
4351 action_vxlan_encap_data->items[1].type =
4352 RTE_FLOW_ITEM_TYPE_VOID;
4353 if (vxlan_encap_conf.select_tos_ttl) {
4354 if (vxlan_encap_conf.select_ipv4) {
4355 static struct rte_flow_item_ipv4 ipv4_mask_tos;
4357 memcpy(&ipv4_mask_tos, &rte_flow_item_ipv4_mask,
4358 sizeof(ipv4_mask_tos));
4359 ipv4_mask_tos.hdr.type_of_service = 0xff;
4360 ipv4_mask_tos.hdr.time_to_live = 0xff;
4361 action_vxlan_encap_data->item_ipv4.hdr.type_of_service =
4362 vxlan_encap_conf.ip_tos;
4363 action_vxlan_encap_data->item_ipv4.hdr.time_to_live =
4364 vxlan_encap_conf.ip_ttl;
4365 action_vxlan_encap_data->items[2].mask =
4368 static struct rte_flow_item_ipv6 ipv6_mask_tos;
4370 memcpy(&ipv6_mask_tos, &rte_flow_item_ipv6_mask,
4371 sizeof(ipv6_mask_tos));
4372 ipv6_mask_tos.hdr.vtc_flow |=
4373 RTE_BE32(0xfful << RTE_IPV6_HDR_TC_SHIFT);
4374 ipv6_mask_tos.hdr.hop_limits = 0xff;
4375 action_vxlan_encap_data->item_ipv6.hdr.vtc_flow |=
4377 ((uint32_t)vxlan_encap_conf.ip_tos <<
4378 RTE_IPV6_HDR_TC_SHIFT);
4379 action_vxlan_encap_data->item_ipv6.hdr.hop_limits =
4380 vxlan_encap_conf.ip_ttl;
4381 action_vxlan_encap_data->items[2].mask =
4385 memcpy(action_vxlan_encap_data->item_vxlan.vni, vxlan_encap_conf.vni,
4386 RTE_DIM(vxlan_encap_conf.vni));
4387 action->conf = &action_vxlan_encap_data->conf;
4391 /** Parse NVGRE encap action. */
4393 parse_vc_action_nvgre_encap(struct context *ctx, const struct token *token,
4394 const char *str, unsigned int len,
4395 void *buf, unsigned int size)
4397 struct buffer *out = buf;
4398 struct rte_flow_action *action;
4399 struct action_nvgre_encap_data *action_nvgre_encap_data;
4402 ret = parse_vc(ctx, token, str, len, buf, size);
4405 /* Nothing else to do if there is no buffer. */
4408 if (!out->args.vc.actions_n)
4410 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4411 /* Point to selected object. */
4412 ctx->object = out->args.vc.data;
4413 ctx->objmask = NULL;
4414 /* Set up default configuration. */
4415 action_nvgre_encap_data = ctx->object;
4416 *action_nvgre_encap_data = (struct action_nvgre_encap_data){
4417 .conf = (struct rte_flow_action_nvgre_encap){
4418 .definition = action_nvgre_encap_data->items,
4422 .type = RTE_FLOW_ITEM_TYPE_ETH,
4423 .spec = &action_nvgre_encap_data->item_eth,
4424 .mask = &rte_flow_item_eth_mask,
4427 .type = RTE_FLOW_ITEM_TYPE_VLAN,
4428 .spec = &action_nvgre_encap_data->item_vlan,
4429 .mask = &rte_flow_item_vlan_mask,
4432 .type = RTE_FLOW_ITEM_TYPE_IPV4,
4433 .spec = &action_nvgre_encap_data->item_ipv4,
4434 .mask = &rte_flow_item_ipv4_mask,
4437 .type = RTE_FLOW_ITEM_TYPE_NVGRE,
4438 .spec = &action_nvgre_encap_data->item_nvgre,
4439 .mask = &rte_flow_item_nvgre_mask,
4442 .type = RTE_FLOW_ITEM_TYPE_END,
4447 .tci = nvgre_encap_conf.vlan_tci,
4451 .src_addr = nvgre_encap_conf.ipv4_src,
4452 .dst_addr = nvgre_encap_conf.ipv4_dst,
4454 .item_nvgre.flow_id = 0,
4456 memcpy(action_nvgre_encap_data->item_eth.dst.addr_bytes,
4457 nvgre_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
4458 memcpy(action_nvgre_encap_data->item_eth.src.addr_bytes,
4459 nvgre_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
4460 if (!nvgre_encap_conf.select_ipv4) {
4461 memcpy(&action_nvgre_encap_data->item_ipv6.hdr.src_addr,
4462 &nvgre_encap_conf.ipv6_src,
4463 sizeof(nvgre_encap_conf.ipv6_src));
4464 memcpy(&action_nvgre_encap_data->item_ipv6.hdr.dst_addr,
4465 &nvgre_encap_conf.ipv6_dst,
4466 sizeof(nvgre_encap_conf.ipv6_dst));
4467 action_nvgre_encap_data->items[2] = (struct rte_flow_item){
4468 .type = RTE_FLOW_ITEM_TYPE_IPV6,
4469 .spec = &action_nvgre_encap_data->item_ipv6,
4470 .mask = &rte_flow_item_ipv6_mask,
4473 if (!nvgre_encap_conf.select_vlan)
4474 action_nvgre_encap_data->items[1].type =
4475 RTE_FLOW_ITEM_TYPE_VOID;
4476 memcpy(action_nvgre_encap_data->item_nvgre.tni, nvgre_encap_conf.tni,
4477 RTE_DIM(nvgre_encap_conf.tni));
4478 action->conf = &action_nvgre_encap_data->conf;
4482 /** Parse l2 encap action. */
4484 parse_vc_action_l2_encap(struct context *ctx, const struct token *token,
4485 const char *str, unsigned int len,
4486 void *buf, unsigned int size)
4488 struct buffer *out = buf;
4489 struct rte_flow_action *action;
4490 struct action_raw_encap_data *action_encap_data;
4491 struct rte_flow_item_eth eth = { .type = 0, };
4492 struct rte_flow_item_vlan vlan = {
4493 .tci = mplsoudp_encap_conf.vlan_tci,
4499 ret = parse_vc(ctx, token, str, len, buf, size);
4502 /* Nothing else to do if there is no buffer. */
4505 if (!out->args.vc.actions_n)
4507 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4508 /* Point to selected object. */
4509 ctx->object = out->args.vc.data;
4510 ctx->objmask = NULL;
4511 /* Copy the headers to the buffer. */
4512 action_encap_data = ctx->object;
4513 *action_encap_data = (struct action_raw_encap_data) {
4514 .conf = (struct rte_flow_action_raw_encap){
4515 .data = action_encap_data->data,
4519 header = action_encap_data->data;
4520 if (l2_encap_conf.select_vlan)
4521 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
4522 else if (l2_encap_conf.select_ipv4)
4523 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4525 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4526 memcpy(eth.dst.addr_bytes,
4527 l2_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
4528 memcpy(eth.src.addr_bytes,
4529 l2_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
4530 memcpy(header, ð, sizeof(eth));
4531 header += sizeof(eth);
4532 if (l2_encap_conf.select_vlan) {
4533 if (l2_encap_conf.select_ipv4)
4534 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4536 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4537 memcpy(header, &vlan, sizeof(vlan));
4538 header += sizeof(vlan);
4540 action_encap_data->conf.size = header -
4541 action_encap_data->data;
4542 action->conf = &action_encap_data->conf;
4546 /** Parse l2 decap action. */
4548 parse_vc_action_l2_decap(struct context *ctx, const struct token *token,
4549 const char *str, unsigned int len,
4550 void *buf, unsigned int size)
4552 struct buffer *out = buf;
4553 struct rte_flow_action *action;
4554 struct action_raw_decap_data *action_decap_data;
4555 struct rte_flow_item_eth eth = { .type = 0, };
4556 struct rte_flow_item_vlan vlan = {
4557 .tci = mplsoudp_encap_conf.vlan_tci,
4563 ret = parse_vc(ctx, token, str, len, buf, size);
4566 /* Nothing else to do if there is no buffer. */
4569 if (!out->args.vc.actions_n)
4571 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4572 /* Point to selected object. */
4573 ctx->object = out->args.vc.data;
4574 ctx->objmask = NULL;
4575 /* Copy the headers to the buffer. */
4576 action_decap_data = ctx->object;
4577 *action_decap_data = (struct action_raw_decap_data) {
4578 .conf = (struct rte_flow_action_raw_decap){
4579 .data = action_decap_data->data,
4583 header = action_decap_data->data;
4584 if (l2_decap_conf.select_vlan)
4585 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
4586 memcpy(header, ð, sizeof(eth));
4587 header += sizeof(eth);
4588 if (l2_decap_conf.select_vlan) {
4589 memcpy(header, &vlan, sizeof(vlan));
4590 header += sizeof(vlan);
4592 action_decap_data->conf.size = header -
4593 action_decap_data->data;
4594 action->conf = &action_decap_data->conf;
4598 #define ETHER_TYPE_MPLS_UNICAST 0x8847
4600 /** Parse MPLSOGRE encap action. */
4602 parse_vc_action_mplsogre_encap(struct context *ctx, const struct token *token,
4603 const char *str, unsigned int len,
4604 void *buf, unsigned int size)
4606 struct buffer *out = buf;
4607 struct rte_flow_action *action;
4608 struct action_raw_encap_data *action_encap_data;
4609 struct rte_flow_item_eth eth = { .type = 0, };
4610 struct rte_flow_item_vlan vlan = {
4611 .tci = mplsogre_encap_conf.vlan_tci,
4614 struct rte_flow_item_ipv4 ipv4 = {
4616 .src_addr = mplsogre_encap_conf.ipv4_src,
4617 .dst_addr = mplsogre_encap_conf.ipv4_dst,
4618 .next_proto_id = IPPROTO_GRE,
4619 .version_ihl = RTE_IPV4_VHL_DEF,
4620 .time_to_live = IPDEFTTL,
4623 struct rte_flow_item_ipv6 ipv6 = {
4625 .proto = IPPROTO_GRE,
4626 .hop_limits = IPDEFTTL,
4629 struct rte_flow_item_gre gre = {
4630 .protocol = rte_cpu_to_be_16(ETHER_TYPE_MPLS_UNICAST),
4632 struct rte_flow_item_mpls mpls = {
4638 ret = parse_vc(ctx, token, str, len, buf, size);
4641 /* Nothing else to do if there is no buffer. */
4644 if (!out->args.vc.actions_n)
4646 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4647 /* Point to selected object. */
4648 ctx->object = out->args.vc.data;
4649 ctx->objmask = NULL;
4650 /* Copy the headers to the buffer. */
4651 action_encap_data = ctx->object;
4652 *action_encap_data = (struct action_raw_encap_data) {
4653 .conf = (struct rte_flow_action_raw_encap){
4654 .data = action_encap_data->data,
4659 header = action_encap_data->data;
4660 if (mplsogre_encap_conf.select_vlan)
4661 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
4662 else if (mplsogre_encap_conf.select_ipv4)
4663 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4665 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4666 memcpy(eth.dst.addr_bytes,
4667 mplsogre_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
4668 memcpy(eth.src.addr_bytes,
4669 mplsogre_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
4670 memcpy(header, ð, sizeof(eth));
4671 header += sizeof(eth);
4672 if (mplsogre_encap_conf.select_vlan) {
4673 if (mplsogre_encap_conf.select_ipv4)
4674 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4676 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4677 memcpy(header, &vlan, sizeof(vlan));
4678 header += sizeof(vlan);
4680 if (mplsogre_encap_conf.select_ipv4) {
4681 memcpy(header, &ipv4, sizeof(ipv4));
4682 header += sizeof(ipv4);
4684 memcpy(&ipv6.hdr.src_addr,
4685 &mplsogre_encap_conf.ipv6_src,
4686 sizeof(mplsogre_encap_conf.ipv6_src));
4687 memcpy(&ipv6.hdr.dst_addr,
4688 &mplsogre_encap_conf.ipv6_dst,
4689 sizeof(mplsogre_encap_conf.ipv6_dst));
4690 memcpy(header, &ipv6, sizeof(ipv6));
4691 header += sizeof(ipv6);
4693 memcpy(header, &gre, sizeof(gre));
4694 header += sizeof(gre);
4695 memcpy(mpls.label_tc_s, mplsogre_encap_conf.label,
4696 RTE_DIM(mplsogre_encap_conf.label));
4697 mpls.label_tc_s[2] |= 0x1;
4698 memcpy(header, &mpls, sizeof(mpls));
4699 header += sizeof(mpls);
4700 action_encap_data->conf.size = header -
4701 action_encap_data->data;
4702 action->conf = &action_encap_data->conf;
4706 /** Parse MPLSOGRE decap action. */
4708 parse_vc_action_mplsogre_decap(struct context *ctx, const struct token *token,
4709 const char *str, unsigned int len,
4710 void *buf, unsigned int size)
4712 struct buffer *out = buf;
4713 struct rte_flow_action *action;
4714 struct action_raw_decap_data *action_decap_data;
4715 struct rte_flow_item_eth eth = { .type = 0, };
4716 struct rte_flow_item_vlan vlan = {.tci = 0};
4717 struct rte_flow_item_ipv4 ipv4 = {
4719 .next_proto_id = IPPROTO_GRE,
4722 struct rte_flow_item_ipv6 ipv6 = {
4724 .proto = IPPROTO_GRE,
4727 struct rte_flow_item_gre gre = {
4728 .protocol = rte_cpu_to_be_16(ETHER_TYPE_MPLS_UNICAST),
4730 struct rte_flow_item_mpls mpls;
4734 ret = parse_vc(ctx, token, str, len, buf, size);
4737 /* Nothing else to do if there is no buffer. */
4740 if (!out->args.vc.actions_n)
4742 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4743 /* Point to selected object. */
4744 ctx->object = out->args.vc.data;
4745 ctx->objmask = NULL;
4746 /* Copy the headers to the buffer. */
4747 action_decap_data = ctx->object;
4748 *action_decap_data = (struct action_raw_decap_data) {
4749 .conf = (struct rte_flow_action_raw_decap){
4750 .data = action_decap_data->data,
4754 header = action_decap_data->data;
4755 if (mplsogre_decap_conf.select_vlan)
4756 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
4757 else if (mplsogre_encap_conf.select_ipv4)
4758 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4760 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4761 memcpy(eth.dst.addr_bytes,
4762 mplsogre_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
4763 memcpy(eth.src.addr_bytes,
4764 mplsogre_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
4765 memcpy(header, ð, sizeof(eth));
4766 header += sizeof(eth);
4767 if (mplsogre_encap_conf.select_vlan) {
4768 if (mplsogre_encap_conf.select_ipv4)
4769 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4771 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4772 memcpy(header, &vlan, sizeof(vlan));
4773 header += sizeof(vlan);
4775 if (mplsogre_encap_conf.select_ipv4) {
4776 memcpy(header, &ipv4, sizeof(ipv4));
4777 header += sizeof(ipv4);
4779 memcpy(header, &ipv6, sizeof(ipv6));
4780 header += sizeof(ipv6);
4782 memcpy(header, &gre, sizeof(gre));
4783 header += sizeof(gre);
4784 memset(&mpls, 0, sizeof(mpls));
4785 memcpy(header, &mpls, sizeof(mpls));
4786 header += sizeof(mpls);
4787 action_decap_data->conf.size = header -
4788 action_decap_data->data;
4789 action->conf = &action_decap_data->conf;
4793 /** Parse MPLSOUDP encap action. */
4795 parse_vc_action_mplsoudp_encap(struct context *ctx, const struct token *token,
4796 const char *str, unsigned int len,
4797 void *buf, unsigned int size)
4799 struct buffer *out = buf;
4800 struct rte_flow_action *action;
4801 struct action_raw_encap_data *action_encap_data;
4802 struct rte_flow_item_eth eth = { .type = 0, };
4803 struct rte_flow_item_vlan vlan = {
4804 .tci = mplsoudp_encap_conf.vlan_tci,
4807 struct rte_flow_item_ipv4 ipv4 = {
4809 .src_addr = mplsoudp_encap_conf.ipv4_src,
4810 .dst_addr = mplsoudp_encap_conf.ipv4_dst,
4811 .next_proto_id = IPPROTO_UDP,
4812 .version_ihl = RTE_IPV4_VHL_DEF,
4813 .time_to_live = IPDEFTTL,
4816 struct rte_flow_item_ipv6 ipv6 = {
4818 .proto = IPPROTO_UDP,
4819 .hop_limits = IPDEFTTL,
4822 struct rte_flow_item_udp udp = {
4824 .src_port = mplsoudp_encap_conf.udp_src,
4825 .dst_port = mplsoudp_encap_conf.udp_dst,
4828 struct rte_flow_item_mpls mpls;
4832 ret = parse_vc(ctx, token, str, len, buf, size);
4835 /* Nothing else to do if there is no buffer. */
4838 if (!out->args.vc.actions_n)
4840 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4841 /* Point to selected object. */
4842 ctx->object = out->args.vc.data;
4843 ctx->objmask = NULL;
4844 /* Copy the headers to the buffer. */
4845 action_encap_data = ctx->object;
4846 *action_encap_data = (struct action_raw_encap_data) {
4847 .conf = (struct rte_flow_action_raw_encap){
4848 .data = action_encap_data->data,
4853 header = action_encap_data->data;
4854 if (mplsoudp_encap_conf.select_vlan)
4855 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
4856 else if (mplsoudp_encap_conf.select_ipv4)
4857 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4859 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4860 memcpy(eth.dst.addr_bytes,
4861 mplsoudp_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
4862 memcpy(eth.src.addr_bytes,
4863 mplsoudp_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
4864 memcpy(header, ð, sizeof(eth));
4865 header += sizeof(eth);
4866 if (mplsoudp_encap_conf.select_vlan) {
4867 if (mplsoudp_encap_conf.select_ipv4)
4868 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4870 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4871 memcpy(header, &vlan, sizeof(vlan));
4872 header += sizeof(vlan);
4874 if (mplsoudp_encap_conf.select_ipv4) {
4875 memcpy(header, &ipv4, sizeof(ipv4));
4876 header += sizeof(ipv4);
4878 memcpy(&ipv6.hdr.src_addr,
4879 &mplsoudp_encap_conf.ipv6_src,
4880 sizeof(mplsoudp_encap_conf.ipv6_src));
4881 memcpy(&ipv6.hdr.dst_addr,
4882 &mplsoudp_encap_conf.ipv6_dst,
4883 sizeof(mplsoudp_encap_conf.ipv6_dst));
4884 memcpy(header, &ipv6, sizeof(ipv6));
4885 header += sizeof(ipv6);
4887 memcpy(header, &udp, sizeof(udp));
4888 header += sizeof(udp);
4889 memcpy(mpls.label_tc_s, mplsoudp_encap_conf.label,
4890 RTE_DIM(mplsoudp_encap_conf.label));
4891 mpls.label_tc_s[2] |= 0x1;
4892 memcpy(header, &mpls, sizeof(mpls));
4893 header += sizeof(mpls);
4894 action_encap_data->conf.size = header -
4895 action_encap_data->data;
4896 action->conf = &action_encap_data->conf;
4900 /** Parse MPLSOUDP decap action. */
4902 parse_vc_action_mplsoudp_decap(struct context *ctx, const struct token *token,
4903 const char *str, unsigned int len,
4904 void *buf, unsigned int size)
4906 struct buffer *out = buf;
4907 struct rte_flow_action *action;
4908 struct action_raw_decap_data *action_decap_data;
4909 struct rte_flow_item_eth eth = { .type = 0, };
4910 struct rte_flow_item_vlan vlan = {.tci = 0};
4911 struct rte_flow_item_ipv4 ipv4 = {
4913 .next_proto_id = IPPROTO_UDP,
4916 struct rte_flow_item_ipv6 ipv6 = {
4918 .proto = IPPROTO_UDP,
4921 struct rte_flow_item_udp udp = {
4923 .dst_port = rte_cpu_to_be_16(6635),
4926 struct rte_flow_item_mpls mpls;
4930 ret = parse_vc(ctx, token, str, len, buf, size);
4933 /* Nothing else to do if there is no buffer. */
4936 if (!out->args.vc.actions_n)
4938 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4939 /* Point to selected object. */
4940 ctx->object = out->args.vc.data;
4941 ctx->objmask = NULL;
4942 /* Copy the headers to the buffer. */
4943 action_decap_data = ctx->object;
4944 *action_decap_data = (struct action_raw_decap_data) {
4945 .conf = (struct rte_flow_action_raw_decap){
4946 .data = action_decap_data->data,
4950 header = action_decap_data->data;
4951 if (mplsoudp_decap_conf.select_vlan)
4952 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
4953 else if (mplsoudp_encap_conf.select_ipv4)
4954 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4956 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4957 memcpy(eth.dst.addr_bytes,
4958 mplsoudp_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
4959 memcpy(eth.src.addr_bytes,
4960 mplsoudp_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
4961 memcpy(header, ð, sizeof(eth));
4962 header += sizeof(eth);
4963 if (mplsoudp_encap_conf.select_vlan) {
4964 if (mplsoudp_encap_conf.select_ipv4)
4965 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4967 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4968 memcpy(header, &vlan, sizeof(vlan));
4969 header += sizeof(vlan);
4971 if (mplsoudp_encap_conf.select_ipv4) {
4972 memcpy(header, &ipv4, sizeof(ipv4));
4973 header += sizeof(ipv4);
4975 memcpy(header, &ipv6, sizeof(ipv6));
4976 header += sizeof(ipv6);
4978 memcpy(header, &udp, sizeof(udp));
4979 header += sizeof(udp);
4980 memset(&mpls, 0, sizeof(mpls));
4981 memcpy(header, &mpls, sizeof(mpls));
4982 header += sizeof(mpls);
4983 action_decap_data->conf.size = header -
4984 action_decap_data->data;
4985 action->conf = &action_decap_data->conf;
4990 parse_vc_action_raw_decap_index(struct context *ctx, const struct token *token,
4991 const char *str, unsigned int len, void *buf,
4994 struct action_raw_decap_data *action_raw_decap_data;
4995 struct rte_flow_action *action;
4996 const struct arg *arg;
4997 struct buffer *out = buf;
5001 RTE_SET_USED(token);
5004 arg = ARGS_ENTRY_ARB_BOUNDED
5005 (offsetof(struct action_raw_decap_data, idx),
5006 sizeof(((struct action_raw_decap_data *)0)->idx),
5007 0, RAW_ENCAP_CONFS_MAX_NUM - 1);
5008 if (push_args(ctx, arg))
5010 ret = parse_int(ctx, token, str, len, NULL, 0);
5017 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
5018 action_raw_decap_data = ctx->object;
5019 idx = action_raw_decap_data->idx;
5020 action_raw_decap_data->conf.data = raw_decap_confs[idx].data;
5021 action_raw_decap_data->conf.size = raw_decap_confs[idx].size;
5022 action->conf = &action_raw_decap_data->conf;
5028 parse_vc_action_raw_encap_index(struct context *ctx, const struct token *token,
5029 const char *str, unsigned int len, void *buf,
5032 struct action_raw_encap_data *action_raw_encap_data;
5033 struct rte_flow_action *action;
5034 const struct arg *arg;
5035 struct buffer *out = buf;
5039 RTE_SET_USED(token);
5042 if (ctx->curr != ACTION_RAW_ENCAP_INDEX_VALUE)
5044 arg = ARGS_ENTRY_ARB_BOUNDED
5045 (offsetof(struct action_raw_encap_data, idx),
5046 sizeof(((struct action_raw_encap_data *)0)->idx),
5047 0, RAW_ENCAP_CONFS_MAX_NUM - 1);
5048 if (push_args(ctx, arg))
5050 ret = parse_int(ctx, token, str, len, NULL, 0);
5057 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
5058 action_raw_encap_data = ctx->object;
5059 idx = action_raw_encap_data->idx;
5060 action_raw_encap_data->conf.data = raw_encap_confs[idx].data;
5061 action_raw_encap_data->conf.size = raw_encap_confs[idx].size;
5062 action_raw_encap_data->conf.preserve = NULL;
5063 action->conf = &action_raw_encap_data->conf;
5068 parse_vc_action_raw_encap(struct context *ctx, const struct token *token,
5069 const char *str, unsigned int len, void *buf,
5072 struct buffer *out = buf;
5073 struct rte_flow_action *action;
5074 struct action_raw_encap_data *action_raw_encap_data = NULL;
5077 ret = parse_vc(ctx, token, str, len, buf, size);
5080 /* Nothing else to do if there is no buffer. */
5083 if (!out->args.vc.actions_n)
5085 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
5086 /* Point to selected object. */
5087 ctx->object = out->args.vc.data;
5088 ctx->objmask = NULL;
5089 /* Copy the headers to the buffer. */
5090 action_raw_encap_data = ctx->object;
5091 action_raw_encap_data->conf.data = raw_encap_confs[0].data;
5092 action_raw_encap_data->conf.preserve = NULL;
5093 action_raw_encap_data->conf.size = raw_encap_confs[0].size;
5094 action->conf = &action_raw_encap_data->conf;
5099 parse_vc_action_raw_decap(struct context *ctx, const struct token *token,
5100 const char *str, unsigned int len, void *buf,
5103 struct buffer *out = buf;
5104 struct rte_flow_action *action;
5105 struct action_raw_decap_data *action_raw_decap_data = NULL;
5108 ret = parse_vc(ctx, token, str, len, buf, size);
5111 /* Nothing else to do if there is no buffer. */
5114 if (!out->args.vc.actions_n)
5116 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
5117 /* Point to selected object. */
5118 ctx->object = out->args.vc.data;
5119 ctx->objmask = NULL;
5120 /* Copy the headers to the buffer. */
5121 action_raw_decap_data = ctx->object;
5122 action_raw_decap_data->conf.data = raw_decap_confs[0].data;
5123 action_raw_decap_data->conf.size = raw_decap_confs[0].size;
5124 action->conf = &action_raw_decap_data->conf;
5129 parse_vc_action_set_meta(struct context *ctx, const struct token *token,
5130 const char *str, unsigned int len, void *buf,
5135 ret = parse_vc(ctx, token, str, len, buf, size);
5138 ret = rte_flow_dynf_metadata_register();
5144 /** Parse tokens for destroy command. */
5146 parse_destroy(struct context *ctx, const struct token *token,
5147 const char *str, unsigned int len,
5148 void *buf, unsigned int size)
5150 struct buffer *out = buf;
5152 /* Token name must match. */
5153 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5155 /* Nothing else to do if there is no buffer. */
5158 if (!out->command) {
5159 if (ctx->curr != DESTROY)
5161 if (sizeof(*out) > size)
5163 out->command = ctx->curr;
5166 ctx->objmask = NULL;
5167 out->args.destroy.rule =
5168 (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
5172 if (((uint8_t *)(out->args.destroy.rule + out->args.destroy.rule_n) +
5173 sizeof(*out->args.destroy.rule)) > (uint8_t *)out + size)
5176 ctx->object = out->args.destroy.rule + out->args.destroy.rule_n++;
5177 ctx->objmask = NULL;
5181 /** Parse tokens for flush command. */
5183 parse_flush(struct context *ctx, const struct token *token,
5184 const char *str, unsigned int len,
5185 void *buf, unsigned int size)
5187 struct buffer *out = buf;
5189 /* Token name must match. */
5190 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5192 /* Nothing else to do if there is no buffer. */
5195 if (!out->command) {
5196 if (ctx->curr != FLUSH)
5198 if (sizeof(*out) > size)
5200 out->command = ctx->curr;
5203 ctx->objmask = NULL;
5208 /** Parse tokens for dump command. */
5210 parse_dump(struct context *ctx, const struct token *token,
5211 const char *str, unsigned int len,
5212 void *buf, unsigned int size)
5214 struct buffer *out = buf;
5216 /* Token name must match. */
5217 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5219 /* Nothing else to do if there is no buffer. */
5222 if (!out->command) {
5223 if (ctx->curr != DUMP)
5225 if (sizeof(*out) > size)
5227 out->command = ctx->curr;
5230 ctx->objmask = NULL;
5235 /** Parse tokens for query command. */
5237 parse_query(struct context *ctx, const struct token *token,
5238 const char *str, unsigned int len,
5239 void *buf, unsigned int size)
5241 struct buffer *out = buf;
5243 /* Token name must match. */
5244 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5246 /* Nothing else to do if there is no buffer. */
5249 if (!out->command) {
5250 if (ctx->curr != QUERY)
5252 if (sizeof(*out) > size)
5254 out->command = ctx->curr;
5257 ctx->objmask = NULL;
5262 /** Parse action names. */
5264 parse_action(struct context *ctx, const struct token *token,
5265 const char *str, unsigned int len,
5266 void *buf, unsigned int size)
5268 struct buffer *out = buf;
5269 const struct arg *arg = pop_args(ctx);
5273 /* Argument is expected. */
5276 /* Parse action name. */
5277 for (i = 0; next_action[i]; ++i) {
5278 const struct parse_action_priv *priv;
5280 token = &token_list[next_action[i]];
5281 if (strcmp_partial(token->name, str, len))
5287 memcpy((uint8_t *)ctx->object + arg->offset,
5293 push_args(ctx, arg);
5297 /** Parse tokens for list command. */
5299 parse_list(struct context *ctx, const struct token *token,
5300 const char *str, unsigned int len,
5301 void *buf, unsigned int size)
5303 struct buffer *out = buf;
5305 /* Token name must match. */
5306 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5308 /* Nothing else to do if there is no buffer. */
5311 if (!out->command) {
5312 if (ctx->curr != LIST)
5314 if (sizeof(*out) > size)
5316 out->command = ctx->curr;
5319 ctx->objmask = NULL;
5320 out->args.list.group =
5321 (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
5325 if (((uint8_t *)(out->args.list.group + out->args.list.group_n) +
5326 sizeof(*out->args.list.group)) > (uint8_t *)out + size)
5329 ctx->object = out->args.list.group + out->args.list.group_n++;
5330 ctx->objmask = NULL;
5334 /** Parse tokens for isolate command. */
5336 parse_isolate(struct context *ctx, const struct token *token,
5337 const char *str, unsigned int len,
5338 void *buf, unsigned int size)
5340 struct buffer *out = buf;
5342 /* Token name must match. */
5343 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5345 /* Nothing else to do if there is no buffer. */
5348 if (!out->command) {
5349 if (ctx->curr != ISOLATE)
5351 if (sizeof(*out) > size)
5353 out->command = ctx->curr;
5356 ctx->objmask = NULL;
5362 * Parse signed/unsigned integers 8 to 64-bit long.
5364 * Last argument (ctx->args) is retrieved to determine integer type and
5368 parse_int(struct context *ctx, const struct token *token,
5369 const char *str, unsigned int len,
5370 void *buf, unsigned int size)
5372 const struct arg *arg = pop_args(ctx);
5377 /* Argument is expected. */
5382 (uintmax_t)strtoimax(str, &end, 0) :
5383 strtoumax(str, &end, 0);
5384 if (errno || (size_t)(end - str) != len)
5387 ((arg->sign && ((intmax_t)u < (intmax_t)arg->min ||
5388 (intmax_t)u > (intmax_t)arg->max)) ||
5389 (!arg->sign && (u < arg->min || u > arg->max))))
5394 if (!arg_entry_bf_fill(ctx->object, u, arg) ||
5395 !arg_entry_bf_fill(ctx->objmask, -1, arg))
5399 buf = (uint8_t *)ctx->object + arg->offset;
5401 if (u > RTE_LEN2MASK(size * CHAR_BIT, uint64_t))
5405 case sizeof(uint8_t):
5406 *(uint8_t *)buf = u;
5408 case sizeof(uint16_t):
5409 *(uint16_t *)buf = arg->hton ? rte_cpu_to_be_16(u) : u;
5411 case sizeof(uint8_t [3]):
5412 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
5414 ((uint8_t *)buf)[0] = u;
5415 ((uint8_t *)buf)[1] = u >> 8;
5416 ((uint8_t *)buf)[2] = u >> 16;
5420 ((uint8_t *)buf)[0] = u >> 16;
5421 ((uint8_t *)buf)[1] = u >> 8;
5422 ((uint8_t *)buf)[2] = u;
5424 case sizeof(uint32_t):
5425 *(uint32_t *)buf = arg->hton ? rte_cpu_to_be_32(u) : u;
5427 case sizeof(uint64_t):
5428 *(uint64_t *)buf = arg->hton ? rte_cpu_to_be_64(u) : u;
5433 if (ctx->objmask && buf != (uint8_t *)ctx->objmask + arg->offset) {
5435 buf = (uint8_t *)ctx->objmask + arg->offset;
5440 push_args(ctx, arg);
5447 * Three arguments (ctx->args) are retrieved from the stack to store data,
5448 * its actual length and address (in that order).
5451 parse_string(struct context *ctx, const struct token *token,
5452 const char *str, unsigned int len,
5453 void *buf, unsigned int size)
5455 const struct arg *arg_data = pop_args(ctx);
5456 const struct arg *arg_len = pop_args(ctx);
5457 const struct arg *arg_addr = pop_args(ctx);
5458 char tmp[16]; /* Ought to be enough. */
5461 /* Arguments are expected. */
5465 push_args(ctx, arg_data);
5469 push_args(ctx, arg_len);
5470 push_args(ctx, arg_data);
5473 size = arg_data->size;
5474 /* Bit-mask fill is not supported. */
5475 if (arg_data->mask || size < len)
5479 /* Let parse_int() fill length information first. */
5480 ret = snprintf(tmp, sizeof(tmp), "%u", len);
5483 push_args(ctx, arg_len);
5484 ret = parse_int(ctx, token, tmp, ret, NULL, 0);
5489 buf = (uint8_t *)ctx->object + arg_data->offset;
5490 /* Output buffer is not necessarily NUL-terminated. */
5491 memcpy(buf, str, len);
5492 memset((uint8_t *)buf + len, 0x00, size - len);
5494 memset((uint8_t *)ctx->objmask + arg_data->offset, 0xff, len);
5495 /* Save address if requested. */
5496 if (arg_addr->size) {
5497 memcpy((uint8_t *)ctx->object + arg_addr->offset,
5499 (uint8_t *)ctx->object + arg_data->offset
5503 memcpy((uint8_t *)ctx->objmask + arg_addr->offset,
5505 (uint8_t *)ctx->objmask + arg_data->offset
5511 push_args(ctx, arg_addr);
5512 push_args(ctx, arg_len);
5513 push_args(ctx, arg_data);
5518 parse_hex_string(const char *src, uint8_t *dst, uint32_t *size)
5524 /* Check input parameters */
5525 if ((src == NULL) ||
5531 /* Convert chars to bytes */
5532 for (i = 0, len = 0; i < *size; i += 2) {
5533 snprintf(tmp, 3, "%s", src + i);
5534 dst[len++] = strtoul(tmp, &c, 16);
5549 parse_hex(struct context *ctx, const struct token *token,
5550 const char *str, unsigned int len,
5551 void *buf, unsigned int size)
5553 const struct arg *arg_data = pop_args(ctx);
5554 const struct arg *arg_len = pop_args(ctx);
5555 const struct arg *arg_addr = pop_args(ctx);
5556 char tmp[16]; /* Ought to be enough. */
5558 unsigned int hexlen = len;
5559 unsigned int length = 256;
5560 uint8_t hex_tmp[length];
5562 /* Arguments are expected. */
5566 push_args(ctx, arg_data);
5570 push_args(ctx, arg_len);
5571 push_args(ctx, arg_data);
5574 size = arg_data->size;
5575 /* Bit-mask fill is not supported. */
5581 /* translate bytes string to array. */
5582 if (str[0] == '0' && ((str[1] == 'x') ||
5587 if (hexlen > length)
5589 ret = parse_hex_string(str, hex_tmp, &hexlen);
5592 /* Let parse_int() fill length information first. */
5593 ret = snprintf(tmp, sizeof(tmp), "%u", hexlen);
5596 push_args(ctx, arg_len);
5597 ret = parse_int(ctx, token, tmp, ret, NULL, 0);
5602 buf = (uint8_t *)ctx->object + arg_data->offset;
5603 /* Output buffer is not necessarily NUL-terminated. */
5604 memcpy(buf, hex_tmp, hexlen);
5605 memset((uint8_t *)buf + hexlen, 0x00, size - hexlen);
5607 memset((uint8_t *)ctx->objmask + arg_data->offset,
5609 /* Save address if requested. */
5610 if (arg_addr->size) {
5611 memcpy((uint8_t *)ctx->object + arg_addr->offset,
5613 (uint8_t *)ctx->object + arg_data->offset
5617 memcpy((uint8_t *)ctx->objmask + arg_addr->offset,
5619 (uint8_t *)ctx->objmask + arg_data->offset
5625 push_args(ctx, arg_addr);
5626 push_args(ctx, arg_len);
5627 push_args(ctx, arg_data);
5633 * Parse a zero-ended string.
5636 parse_string0(struct context *ctx, const struct token *token __rte_unused,
5637 const char *str, unsigned int len,
5638 void *buf, unsigned int size)
5640 const struct arg *arg_data = pop_args(ctx);
5642 /* Arguments are expected. */
5645 size = arg_data->size;
5646 /* Bit-mask fill is not supported. */
5647 if (arg_data->mask || size < len + 1)
5651 buf = (uint8_t *)ctx->object + arg_data->offset;
5652 strncpy(buf, str, len);
5654 memset((uint8_t *)ctx->objmask + arg_data->offset, 0xff, len);
5657 push_args(ctx, arg_data);
5662 * Parse a MAC address.
5664 * Last argument (ctx->args) is retrieved to determine storage size and
5668 parse_mac_addr(struct context *ctx, const struct token *token,
5669 const char *str, unsigned int len,
5670 void *buf, unsigned int size)
5672 const struct arg *arg = pop_args(ctx);
5673 struct rte_ether_addr tmp;
5677 /* Argument is expected. */
5681 /* Bit-mask fill is not supported. */
5682 if (arg->mask || size != sizeof(tmp))
5684 /* Only network endian is supported. */
5687 ret = cmdline_parse_etheraddr(NULL, str, &tmp, size);
5688 if (ret < 0 || (unsigned int)ret != len)
5692 buf = (uint8_t *)ctx->object + arg->offset;
5693 memcpy(buf, &tmp, size);
5695 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
5698 push_args(ctx, arg);
5703 * Parse an IPv4 address.
5705 * Last argument (ctx->args) is retrieved to determine storage size and
5709 parse_ipv4_addr(struct context *ctx, const struct token *token,
5710 const char *str, unsigned int len,
5711 void *buf, unsigned int size)
5713 const struct arg *arg = pop_args(ctx);
5718 /* Argument is expected. */
5722 /* Bit-mask fill is not supported. */
5723 if (arg->mask || size != sizeof(tmp))
5725 /* Only network endian is supported. */
5728 memcpy(str2, str, len);
5730 ret = inet_pton(AF_INET, str2, &tmp);
5732 /* Attempt integer parsing. */
5733 push_args(ctx, arg);
5734 return parse_int(ctx, token, str, len, buf, size);
5738 buf = (uint8_t *)ctx->object + arg->offset;
5739 memcpy(buf, &tmp, size);
5741 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
5744 push_args(ctx, arg);
5749 * Parse an IPv6 address.
5751 * Last argument (ctx->args) is retrieved to determine storage size and
5755 parse_ipv6_addr(struct context *ctx, const struct token *token,
5756 const char *str, unsigned int len,
5757 void *buf, unsigned int size)
5759 const struct arg *arg = pop_args(ctx);
5761 struct in6_addr tmp;
5765 /* Argument is expected. */
5769 /* Bit-mask fill is not supported. */
5770 if (arg->mask || size != sizeof(tmp))
5772 /* Only network endian is supported. */
5775 memcpy(str2, str, len);
5777 ret = inet_pton(AF_INET6, str2, &tmp);
5782 buf = (uint8_t *)ctx->object + arg->offset;
5783 memcpy(buf, &tmp, size);
5785 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
5788 push_args(ctx, arg);
5792 /** Boolean values (even indices stand for false). */
5793 static const char *const boolean_name[] = {
5803 * Parse a boolean value.
5805 * Last argument (ctx->args) is retrieved to determine storage size and
5809 parse_boolean(struct context *ctx, const struct token *token,
5810 const char *str, unsigned int len,
5811 void *buf, unsigned int size)
5813 const struct arg *arg = pop_args(ctx);
5817 /* Argument is expected. */
5820 for (i = 0; boolean_name[i]; ++i)
5821 if (!strcmp_partial(boolean_name[i], str, len))
5823 /* Process token as integer. */
5824 if (boolean_name[i])
5825 str = i & 1 ? "1" : "0";
5826 push_args(ctx, arg);
5827 ret = parse_int(ctx, token, str, strlen(str), buf, size);
5828 return ret > 0 ? (int)len : ret;
5831 /** Parse port and update context. */
5833 parse_port(struct context *ctx, const struct token *token,
5834 const char *str, unsigned int len,
5835 void *buf, unsigned int size)
5837 struct buffer *out = &(struct buffer){ .port = 0 };
5845 ctx->objmask = NULL;
5846 size = sizeof(*out);
5848 ret = parse_int(ctx, token, str, len, out, size);
5850 ctx->port = out->port;
5856 /** Parse set command, initialize output buffer for subsequent tokens. */
5858 parse_set_raw_encap_decap(struct context *ctx, const struct token *token,
5859 const char *str, unsigned int len,
5860 void *buf, unsigned int size)
5862 struct buffer *out = buf;
5864 /* Token name must match. */
5865 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5867 /* Nothing else to do if there is no buffer. */
5870 /* Make sure buffer is large enough. */
5871 if (size < sizeof(*out))
5874 ctx->objmask = NULL;
5878 out->command = ctx->curr;
5883 * Parse set raw_encap/raw_decap command,
5884 * initialize output buffer for subsequent tokens.
5887 parse_set_init(struct context *ctx, const struct token *token,
5888 const char *str, unsigned int len,
5889 void *buf, unsigned int size)
5891 struct buffer *out = buf;
5893 /* Token name must match. */
5894 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5896 /* Nothing else to do if there is no buffer. */
5899 /* Make sure buffer is large enough. */
5900 if (size < sizeof(*out))
5902 /* Initialize buffer. */
5903 memset(out, 0x00, sizeof(*out));
5904 memset((uint8_t *)out + sizeof(*out), 0x22, size - sizeof(*out));
5907 ctx->objmask = NULL;
5908 if (!out->command) {
5909 if (ctx->curr != SET)
5911 if (sizeof(*out) > size)
5913 out->command = ctx->curr;
5914 out->args.vc.data = (uint8_t *)out + size;
5915 /* All we need is pattern */
5916 out->args.vc.pattern =
5917 (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
5919 ctx->object = out->args.vc.pattern;
5924 /** No completion. */
5926 comp_none(struct context *ctx, const struct token *token,
5927 unsigned int ent, char *buf, unsigned int size)
5937 /** Complete boolean values. */
5939 comp_boolean(struct context *ctx, const struct token *token,
5940 unsigned int ent, char *buf, unsigned int size)
5946 for (i = 0; boolean_name[i]; ++i)
5947 if (buf && i == ent)
5948 return strlcpy(buf, boolean_name[i], size);
5954 /** Complete action names. */
5956 comp_action(struct context *ctx, const struct token *token,
5957 unsigned int ent, char *buf, unsigned int size)
5963 for (i = 0; next_action[i]; ++i)
5964 if (buf && i == ent)
5965 return strlcpy(buf, token_list[next_action[i]].name,
5972 /** Complete available ports. */
5974 comp_port(struct context *ctx, const struct token *token,
5975 unsigned int ent, char *buf, unsigned int size)
5982 RTE_ETH_FOREACH_DEV(p) {
5983 if (buf && i == ent)
5984 return snprintf(buf, size, "%u", p);
5992 /** Complete available rule IDs. */
5994 comp_rule_id(struct context *ctx, const struct token *token,
5995 unsigned int ent, char *buf, unsigned int size)
5998 struct rte_port *port;
5999 struct port_flow *pf;
6002 if (port_id_is_invalid(ctx->port, DISABLED_WARN) ||
6003 ctx->port == (portid_t)RTE_PORT_ALL)
6005 port = &ports[ctx->port];
6006 for (pf = port->flow_list; pf != NULL; pf = pf->next) {
6007 if (buf && i == ent)
6008 return snprintf(buf, size, "%u", pf->id);
6016 /** Complete type field for RSS action. */
6018 comp_vc_action_rss_type(struct context *ctx, const struct token *token,
6019 unsigned int ent, char *buf, unsigned int size)
6025 for (i = 0; rss_type_table[i].str; ++i)
6030 return strlcpy(buf, rss_type_table[ent].str, size);
6032 return snprintf(buf, size, "end");
6036 /** Complete queue field for RSS action. */
6038 comp_vc_action_rss_queue(struct context *ctx, const struct token *token,
6039 unsigned int ent, char *buf, unsigned int size)
6046 return snprintf(buf, size, "%u", ent);
6048 return snprintf(buf, size, "end");
6052 /** Complete index number for set raw_encap/raw_decap commands. */
6054 comp_set_raw_index(struct context *ctx, const struct token *token,
6055 unsigned int ent, char *buf, unsigned int size)
6061 RTE_SET_USED(token);
6062 for (idx = 0; idx < RAW_ENCAP_CONFS_MAX_NUM; ++idx) {
6063 if (buf && idx == ent)
6064 return snprintf(buf, size, "%u", idx);
6070 /** Internal context. */
6071 static struct context cmd_flow_context;
6073 /** Global parser instance (cmdline API). */
6074 cmdline_parse_inst_t cmd_flow;
6075 cmdline_parse_inst_t cmd_set_raw;
6077 /** Initialize context. */
6079 cmd_flow_context_init(struct context *ctx)
6081 /* A full memset() is not necessary. */
6091 ctx->objmask = NULL;
6094 /** Parse a token (cmdline API). */
6096 cmd_flow_parse(cmdline_parse_token_hdr_t *hdr, const char *src, void *result,
6099 struct context *ctx = &cmd_flow_context;
6100 const struct token *token;
6101 const enum index *list;
6106 token = &token_list[ctx->curr];
6107 /* Check argument length. */
6110 for (len = 0; src[len]; ++len)
6111 if (src[len] == '#' || isspace(src[len]))
6115 /* Last argument and EOL detection. */
6116 for (i = len; src[i]; ++i)
6117 if (src[i] == '#' || src[i] == '\r' || src[i] == '\n')
6119 else if (!isspace(src[i])) {
6124 if (src[i] == '\r' || src[i] == '\n') {
6128 /* Initialize context if necessary. */
6129 if (!ctx->next_num) {
6132 ctx->next[ctx->next_num++] = token->next[0];
6134 /* Process argument through candidates. */
6135 ctx->prev = ctx->curr;
6136 list = ctx->next[ctx->next_num - 1];
6137 for (i = 0; list[i]; ++i) {
6138 const struct token *next = &token_list[list[i]];
6141 ctx->curr = list[i];
6143 tmp = next->call(ctx, next, src, len, result, size);
6145 tmp = parse_default(ctx, next, src, len, result, size);
6146 if (tmp == -1 || tmp != len)
6154 /* Push subsequent tokens if any. */
6156 for (i = 0; token->next[i]; ++i) {
6157 if (ctx->next_num == RTE_DIM(ctx->next))
6159 ctx->next[ctx->next_num++] = token->next[i];
6161 /* Push arguments if any. */
6163 for (i = 0; token->args[i]; ++i) {
6164 if (ctx->args_num == RTE_DIM(ctx->args))
6166 ctx->args[ctx->args_num++] = token->args[i];
6171 /** Return number of completion entries (cmdline API). */
6173 cmd_flow_complete_get_nb(cmdline_parse_token_hdr_t *hdr)
6175 struct context *ctx = &cmd_flow_context;
6176 const struct token *token = &token_list[ctx->curr];
6177 const enum index *list;
6181 /* Count number of tokens in current list. */
6183 list = ctx->next[ctx->next_num - 1];
6185 list = token->next[0];
6186 for (i = 0; list[i]; ++i)
6191 * If there is a single token, use its completion callback, otherwise
6192 * return the number of entries.
6194 token = &token_list[list[0]];
6195 if (i == 1 && token->comp) {
6196 /* Save index for cmd_flow_get_help(). */
6197 ctx->prev = list[0];
6198 return token->comp(ctx, token, 0, NULL, 0);
6203 /** Return a completion entry (cmdline API). */
6205 cmd_flow_complete_get_elt(cmdline_parse_token_hdr_t *hdr, int index,
6206 char *dst, unsigned int size)
6208 struct context *ctx = &cmd_flow_context;
6209 const struct token *token = &token_list[ctx->curr];
6210 const enum index *list;
6214 /* Count number of tokens in current list. */
6216 list = ctx->next[ctx->next_num - 1];
6218 list = token->next[0];
6219 for (i = 0; list[i]; ++i)
6223 /* If there is a single token, use its completion callback. */
6224 token = &token_list[list[0]];
6225 if (i == 1 && token->comp) {
6226 /* Save index for cmd_flow_get_help(). */
6227 ctx->prev = list[0];
6228 return token->comp(ctx, token, index, dst, size) < 0 ? -1 : 0;
6230 /* Otherwise make sure the index is valid and use defaults. */
6233 token = &token_list[list[index]];
6234 strlcpy(dst, token->name, size);
6235 /* Save index for cmd_flow_get_help(). */
6236 ctx->prev = list[index];
6240 /** Populate help strings for current token (cmdline API). */
6242 cmd_flow_get_help(cmdline_parse_token_hdr_t *hdr, char *dst, unsigned int size)
6244 struct context *ctx = &cmd_flow_context;
6245 const struct token *token = &token_list[ctx->prev];
6250 /* Set token type and update global help with details. */
6251 strlcpy(dst, (token->type ? token->type : "TOKEN"), size);
6253 cmd_flow.help_str = token->help;
6255 cmd_flow.help_str = token->name;
6259 /** Token definition template (cmdline API). */
6260 static struct cmdline_token_hdr cmd_flow_token_hdr = {
6261 .ops = &(struct cmdline_token_ops){
6262 .parse = cmd_flow_parse,
6263 .complete_get_nb = cmd_flow_complete_get_nb,
6264 .complete_get_elt = cmd_flow_complete_get_elt,
6265 .get_help = cmd_flow_get_help,
6270 /** Populate the next dynamic token. */
6272 cmd_flow_tok(cmdline_parse_token_hdr_t **hdr,
6273 cmdline_parse_token_hdr_t **hdr_inst)
6275 struct context *ctx = &cmd_flow_context;
6277 /* Always reinitialize context before requesting the first token. */
6278 if (!(hdr_inst - cmd_flow.tokens))
6279 cmd_flow_context_init(ctx);
6280 /* Return NULL when no more tokens are expected. */
6281 if (!ctx->next_num && ctx->curr) {
6285 /* Determine if command should end here. */
6286 if (ctx->eol && ctx->last && ctx->next_num) {
6287 const enum index *list = ctx->next[ctx->next_num - 1];
6290 for (i = 0; list[i]; ++i) {
6297 *hdr = &cmd_flow_token_hdr;
6300 /** Dispatch parsed buffer to function calls. */
6302 cmd_flow_parsed(const struct buffer *in)
6304 switch (in->command) {
6306 port_flow_validate(in->port, &in->args.vc.attr,
6307 in->args.vc.pattern, in->args.vc.actions);
6310 port_flow_create(in->port, &in->args.vc.attr,
6311 in->args.vc.pattern, in->args.vc.actions);
6314 port_flow_destroy(in->port, in->args.destroy.rule_n,
6315 in->args.destroy.rule);
6318 port_flow_flush(in->port);
6321 port_flow_dump(in->port, in->args.dump.file);
6324 port_flow_query(in->port, in->args.query.rule,
6325 &in->args.query.action);
6328 port_flow_list(in->port, in->args.list.group_n,
6329 in->args.list.group);
6332 port_flow_isolate(in->port, in->args.isolate.set);
6339 /** Token generator and output processing callback (cmdline API). */
6341 cmd_flow_cb(void *arg0, struct cmdline *cl, void *arg2)
6344 cmd_flow_tok(arg0, arg2);
6346 cmd_flow_parsed(arg0);
6349 /** Global parser instance (cmdline API). */
6350 cmdline_parse_inst_t cmd_flow = {
6352 .data = NULL, /**< Unused. */
6353 .help_str = NULL, /**< Updated by cmd_flow_get_help(). */
6356 }, /**< Tokens are returned by cmd_flow_tok(). */
6359 /** set cmd facility. Reuse cmd flow's infrastructure as much as possible. */
6362 update_fields(uint8_t *buf, struct rte_flow_item *item, uint16_t next_proto)
6364 struct rte_flow_item_ipv4 *ipv4;
6365 struct rte_flow_item_eth *eth;
6366 struct rte_flow_item_ipv6 *ipv6;
6367 struct rte_flow_item_vxlan *vxlan;
6368 struct rte_flow_item_vxlan_gpe *gpe;
6369 struct rte_flow_item_nvgre *nvgre;
6370 uint32_t ipv6_vtc_flow;
6372 switch (item->type) {
6373 case RTE_FLOW_ITEM_TYPE_ETH:
6374 eth = (struct rte_flow_item_eth *)buf;
6376 eth->type = rte_cpu_to_be_16(next_proto);
6378 case RTE_FLOW_ITEM_TYPE_IPV4:
6379 ipv4 = (struct rte_flow_item_ipv4 *)buf;
6380 ipv4->hdr.version_ihl = 0x45;
6381 if (next_proto && ipv4->hdr.next_proto_id == 0)
6382 ipv4->hdr.next_proto_id = (uint8_t)next_proto;
6384 case RTE_FLOW_ITEM_TYPE_IPV6:
6385 ipv6 = (struct rte_flow_item_ipv6 *)buf;
6386 if (next_proto && ipv6->hdr.proto == 0)
6387 ipv6->hdr.proto = (uint8_t)next_proto;
6388 ipv6_vtc_flow = rte_be_to_cpu_32(ipv6->hdr.vtc_flow);
6389 ipv6_vtc_flow &= 0x0FFFFFFF; /*< reset version bits. */
6390 ipv6_vtc_flow |= 0x60000000; /*< set ipv6 version. */
6391 ipv6->hdr.vtc_flow = rte_cpu_to_be_32(ipv6_vtc_flow);
6393 case RTE_FLOW_ITEM_TYPE_VXLAN:
6394 vxlan = (struct rte_flow_item_vxlan *)buf;
6395 vxlan->flags = 0x08;
6397 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
6398 gpe = (struct rte_flow_item_vxlan_gpe *)buf;
6401 case RTE_FLOW_ITEM_TYPE_NVGRE:
6402 nvgre = (struct rte_flow_item_nvgre *)buf;
6403 nvgre->protocol = rte_cpu_to_be_16(0x6558);
6404 nvgre->c_k_s_rsvd0_ver = rte_cpu_to_be_16(0x2000);
6411 /** Helper of get item's default mask. */
6413 flow_item_default_mask(const struct rte_flow_item *item)
6415 const void *mask = NULL;
6416 static rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
6418 switch (item->type) {
6419 case RTE_FLOW_ITEM_TYPE_ANY:
6420 mask = &rte_flow_item_any_mask;
6422 case RTE_FLOW_ITEM_TYPE_VF:
6423 mask = &rte_flow_item_vf_mask;
6425 case RTE_FLOW_ITEM_TYPE_PORT_ID:
6426 mask = &rte_flow_item_port_id_mask;
6428 case RTE_FLOW_ITEM_TYPE_RAW:
6429 mask = &rte_flow_item_raw_mask;
6431 case RTE_FLOW_ITEM_TYPE_ETH:
6432 mask = &rte_flow_item_eth_mask;
6434 case RTE_FLOW_ITEM_TYPE_VLAN:
6435 mask = &rte_flow_item_vlan_mask;
6437 case RTE_FLOW_ITEM_TYPE_IPV4:
6438 mask = &rte_flow_item_ipv4_mask;
6440 case RTE_FLOW_ITEM_TYPE_IPV6:
6441 mask = &rte_flow_item_ipv6_mask;
6443 case RTE_FLOW_ITEM_TYPE_ICMP:
6444 mask = &rte_flow_item_icmp_mask;
6446 case RTE_FLOW_ITEM_TYPE_UDP:
6447 mask = &rte_flow_item_udp_mask;
6449 case RTE_FLOW_ITEM_TYPE_TCP:
6450 mask = &rte_flow_item_tcp_mask;
6452 case RTE_FLOW_ITEM_TYPE_SCTP:
6453 mask = &rte_flow_item_sctp_mask;
6455 case RTE_FLOW_ITEM_TYPE_VXLAN:
6456 mask = &rte_flow_item_vxlan_mask;
6458 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
6459 mask = &rte_flow_item_vxlan_gpe_mask;
6461 case RTE_FLOW_ITEM_TYPE_E_TAG:
6462 mask = &rte_flow_item_e_tag_mask;
6464 case RTE_FLOW_ITEM_TYPE_NVGRE:
6465 mask = &rte_flow_item_nvgre_mask;
6467 case RTE_FLOW_ITEM_TYPE_MPLS:
6468 mask = &rte_flow_item_mpls_mask;
6470 case RTE_FLOW_ITEM_TYPE_GRE:
6471 mask = &rte_flow_item_gre_mask;
6473 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
6474 mask = &gre_key_default_mask;
6476 case RTE_FLOW_ITEM_TYPE_META:
6477 mask = &rte_flow_item_meta_mask;
6479 case RTE_FLOW_ITEM_TYPE_FUZZY:
6480 mask = &rte_flow_item_fuzzy_mask;
6482 case RTE_FLOW_ITEM_TYPE_GTP:
6483 mask = &rte_flow_item_gtp_mask;
6485 case RTE_FLOW_ITEM_TYPE_GTP_PSC:
6486 mask = &rte_flow_item_gtp_psc_mask;
6488 case RTE_FLOW_ITEM_TYPE_GENEVE:
6489 mask = &rte_flow_item_geneve_mask;
6491 case RTE_FLOW_ITEM_TYPE_PPPOE_PROTO_ID:
6492 mask = &rte_flow_item_pppoe_proto_id_mask;
6494 case RTE_FLOW_ITEM_TYPE_L2TPV3OIP:
6495 mask = &rte_flow_item_l2tpv3oip_mask;
6497 case RTE_FLOW_ITEM_TYPE_ESP:
6498 mask = &rte_flow_item_esp_mask;
6500 case RTE_FLOW_ITEM_TYPE_AH:
6501 mask = &rte_flow_item_ah_mask;
6503 case RTE_FLOW_ITEM_TYPE_PFCP:
6504 mask = &rte_flow_item_pfcp_mask;
6514 /** Dispatch parsed buffer to function calls. */
6516 cmd_set_raw_parsed(const struct buffer *in)
6518 uint32_t n = in->args.vc.pattern_n;
6520 struct rte_flow_item *item = NULL;
6522 uint8_t *data = NULL;
6523 uint8_t *data_tail = NULL;
6524 size_t *total_size = NULL;
6525 uint16_t upper_layer = 0;
6527 uint16_t idx = in->port; /* We borrow port field as index */
6529 RTE_ASSERT(in->command == SET_RAW_ENCAP ||
6530 in->command == SET_RAW_DECAP);
6531 if (in->command == SET_RAW_ENCAP) {
6532 total_size = &raw_encap_confs[idx].size;
6533 data = (uint8_t *)&raw_encap_confs[idx].data;
6535 total_size = &raw_decap_confs[idx].size;
6536 data = (uint8_t *)&raw_decap_confs[idx].data;
6539 memset(data, 0x00, ACTION_RAW_ENCAP_MAX_DATA);
6540 /* process hdr from upper layer to low layer (L3/L4 -> L2). */
6541 data_tail = data + ACTION_RAW_ENCAP_MAX_DATA;
6542 for (i = n - 1 ; i >= 0; --i) {
6543 item = in->args.vc.pattern + i;
6544 if (item->spec == NULL)
6545 item->spec = flow_item_default_mask(item);
6546 switch (item->type) {
6547 case RTE_FLOW_ITEM_TYPE_ETH:
6548 size = sizeof(struct rte_flow_item_eth);
6550 case RTE_FLOW_ITEM_TYPE_VLAN:
6551 size = sizeof(struct rte_flow_item_vlan);
6552 proto = RTE_ETHER_TYPE_VLAN;
6554 case RTE_FLOW_ITEM_TYPE_IPV4:
6555 size = sizeof(struct rte_flow_item_ipv4);
6556 proto = RTE_ETHER_TYPE_IPV4;
6558 case RTE_FLOW_ITEM_TYPE_IPV6:
6559 size = sizeof(struct rte_flow_item_ipv6);
6560 proto = RTE_ETHER_TYPE_IPV6;
6562 case RTE_FLOW_ITEM_TYPE_UDP:
6563 size = sizeof(struct rte_flow_item_udp);
6566 case RTE_FLOW_ITEM_TYPE_TCP:
6567 size = sizeof(struct rte_flow_item_tcp);
6570 case RTE_FLOW_ITEM_TYPE_VXLAN:
6571 size = sizeof(struct rte_flow_item_vxlan);
6573 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
6574 size = sizeof(struct rte_flow_item_vxlan_gpe);
6576 case RTE_FLOW_ITEM_TYPE_GRE:
6577 size = sizeof(struct rte_flow_item_gre);
6580 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
6581 size = sizeof(rte_be32_t);
6584 case RTE_FLOW_ITEM_TYPE_MPLS:
6585 size = sizeof(struct rte_flow_item_mpls);
6588 case RTE_FLOW_ITEM_TYPE_NVGRE:
6589 size = sizeof(struct rte_flow_item_nvgre);
6592 case RTE_FLOW_ITEM_TYPE_GENEVE:
6593 size = sizeof(struct rte_flow_item_geneve);
6595 case RTE_FLOW_ITEM_TYPE_L2TPV3OIP:
6596 size = sizeof(struct rte_flow_item_l2tpv3oip);
6599 case RTE_FLOW_ITEM_TYPE_ESP:
6600 size = sizeof(struct rte_flow_item_esp);
6603 case RTE_FLOW_ITEM_TYPE_AH:
6604 size = sizeof(struct rte_flow_item_ah);
6607 case RTE_FLOW_ITEM_TYPE_PFCP:
6608 size = sizeof(struct rte_flow_item_pfcp);
6611 printf("Error - Not supported item\n");
6613 memset(data, 0x00, ACTION_RAW_ENCAP_MAX_DATA);
6616 *total_size += size;
6617 rte_memcpy(data_tail - (*total_size), item->spec, size);
6618 /* update some fields which cannot be set by cmdline */
6619 update_fields((data_tail - (*total_size)), item,
6621 upper_layer = proto;
6623 if (verbose_level & 0x1)
6624 printf("total data size is %zu\n", (*total_size));
6625 RTE_ASSERT((*total_size) <= ACTION_RAW_ENCAP_MAX_DATA);
6626 memmove(data, (data_tail - (*total_size)), *total_size);
6629 /** Populate help strings for current token (cmdline API). */
6631 cmd_set_raw_get_help(cmdline_parse_token_hdr_t *hdr, char *dst,
6634 struct context *ctx = &cmd_flow_context;
6635 const struct token *token = &token_list[ctx->prev];
6640 /* Set token type and update global help with details. */
6641 snprintf(dst, size, "%s", (token->type ? token->type : "TOKEN"));
6643 cmd_set_raw.help_str = token->help;
6645 cmd_set_raw.help_str = token->name;
6649 /** Token definition template (cmdline API). */
6650 static struct cmdline_token_hdr cmd_set_raw_token_hdr = {
6651 .ops = &(struct cmdline_token_ops){
6652 .parse = cmd_flow_parse,
6653 .complete_get_nb = cmd_flow_complete_get_nb,
6654 .complete_get_elt = cmd_flow_complete_get_elt,
6655 .get_help = cmd_set_raw_get_help,
6660 /** Populate the next dynamic token. */
6662 cmd_set_raw_tok(cmdline_parse_token_hdr_t **hdr,
6663 cmdline_parse_token_hdr_t **hdr_inst)
6665 struct context *ctx = &cmd_flow_context;
6667 /* Always reinitialize context before requesting the first token. */
6668 if (!(hdr_inst - cmd_set_raw.tokens)) {
6669 cmd_flow_context_init(ctx);
6670 ctx->curr = START_SET;
6672 /* Return NULL when no more tokens are expected. */
6673 if (!ctx->next_num && (ctx->curr != START_SET)) {
6677 /* Determine if command should end here. */
6678 if (ctx->eol && ctx->last && ctx->next_num) {
6679 const enum index *list = ctx->next[ctx->next_num - 1];
6682 for (i = 0; list[i]; ++i) {
6689 *hdr = &cmd_set_raw_token_hdr;
6692 /** Token generator and output processing callback (cmdline API). */
6694 cmd_set_raw_cb(void *arg0, struct cmdline *cl, void *arg2)
6697 cmd_set_raw_tok(arg0, arg2);
6699 cmd_set_raw_parsed(arg0);
6702 /** Global parser instance (cmdline API). */
6703 cmdline_parse_inst_t cmd_set_raw = {
6704 .f = cmd_set_raw_cb,
6705 .data = NULL, /**< Unused. */
6706 .help_str = NULL, /**< Updated by cmd_flow_get_help(). */
6709 }, /**< Tokens are returned by cmd_flow_tok(). */
6712 /* *** display raw_encap/raw_decap buf */
6713 struct cmd_show_set_raw_result {
6714 cmdline_fixed_string_t cmd_show;
6715 cmdline_fixed_string_t cmd_what;
6716 cmdline_fixed_string_t cmd_all;
6721 cmd_show_set_raw_parsed(void *parsed_result, struct cmdline *cl, void *data)
6723 struct cmd_show_set_raw_result *res = parsed_result;
6724 uint16_t index = res->cmd_index;
6726 uint8_t *raw_data = NULL;
6727 size_t raw_size = 0;
6728 char title[16] = {0};
6732 if (!strcmp(res->cmd_all, "all")) {
6735 } else if (index >= RAW_ENCAP_CONFS_MAX_NUM) {
6736 printf("index should be 0-%u\n", RAW_ENCAP_CONFS_MAX_NUM - 1);
6740 if (!strcmp(res->cmd_what, "raw_encap")) {
6741 raw_data = (uint8_t *)&raw_encap_confs[index].data;
6742 raw_size = raw_encap_confs[index].size;
6743 snprintf(title, 16, "\nindex: %u", index);
6744 rte_hexdump(stdout, title, raw_data, raw_size);
6746 raw_data = (uint8_t *)&raw_decap_confs[index].data;
6747 raw_size = raw_decap_confs[index].size;
6748 snprintf(title, 16, "\nindex: %u", index);
6749 rte_hexdump(stdout, title, raw_data, raw_size);
6751 } while (all && ++index < RAW_ENCAP_CONFS_MAX_NUM);
6754 cmdline_parse_token_string_t cmd_show_set_raw_cmd_show =
6755 TOKEN_STRING_INITIALIZER(struct cmd_show_set_raw_result,
6757 cmdline_parse_token_string_t cmd_show_set_raw_cmd_what =
6758 TOKEN_STRING_INITIALIZER(struct cmd_show_set_raw_result,
6759 cmd_what, "raw_encap#raw_decap");
6760 cmdline_parse_token_num_t cmd_show_set_raw_cmd_index =
6761 TOKEN_NUM_INITIALIZER(struct cmd_show_set_raw_result,
6763 cmdline_parse_token_string_t cmd_show_set_raw_cmd_all =
6764 TOKEN_STRING_INITIALIZER(struct cmd_show_set_raw_result,
6766 cmdline_parse_inst_t cmd_show_set_raw = {
6767 .f = cmd_show_set_raw_parsed,
6769 .help_str = "show <raw_encap|raw_decap> <index>",
6771 (void *)&cmd_show_set_raw_cmd_show,
6772 (void *)&cmd_show_set_raw_cmd_what,
6773 (void *)&cmd_show_set_raw_cmd_index,
6777 cmdline_parse_inst_t cmd_show_set_raw_all = {
6778 .f = cmd_show_set_raw_parsed,
6780 .help_str = "show <raw_encap|raw_decap> all",
6782 (void *)&cmd_show_set_raw_cmd_show,
6783 (void *)&cmd_show_set_raw_cmd_what,
6784 (void *)&cmd_show_set_raw_cmd_all,