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. */
52 /* Top-level command. */
54 /* Sub-leve commands. */
59 /* Top-level command. */
61 /* Sub-level commands. */
70 /* Destroy arguments. */
73 /* Query arguments. */
79 /* Validate/create arguments. */
86 /* Validate/create pattern. */
123 ITEM_VLAN_INNER_TYPE,
155 ITEM_E_TAG_GRP_ECID_B,
164 ITEM_GRE_C_RSVD0_VER,
180 ITEM_ARP_ETH_IPV4_SHA,
181 ITEM_ARP_ETH_IPV4_SPA,
182 ITEM_ARP_ETH_IPV4_THA,
183 ITEM_ARP_ETH_IPV4_TPA,
185 ITEM_IPV6_EXT_NEXT_HDR,
190 ITEM_ICMP6_ND_NS_TARGET_ADDR,
192 ITEM_ICMP6_ND_NA_TARGET_ADDR,
194 ITEM_ICMP6_ND_OPT_TYPE,
195 ITEM_ICMP6_ND_OPT_SLA_ETH,
196 ITEM_ICMP6_ND_OPT_SLA_ETH_SLA,
197 ITEM_ICMP6_ND_OPT_TLA_ETH,
198 ITEM_ICMP6_ND_OPT_TLA_ETH_TLA,
211 ITEM_HIGIG2_CLASSIFICATION,
217 /* Validate/create actions. */
237 ACTION_RSS_FUNC_DEFAULT,
238 ACTION_RSS_FUNC_TOEPLITZ,
239 ACTION_RSS_FUNC_SIMPLE_XOR,
240 ACTION_RSS_FUNC_SYMMETRIC_TOEPLITZ,
252 ACTION_PHY_PORT_ORIGINAL,
253 ACTION_PHY_PORT_INDEX,
255 ACTION_PORT_ID_ORIGINAL,
259 ACTION_OF_SET_MPLS_TTL,
260 ACTION_OF_SET_MPLS_TTL_MPLS_TTL,
261 ACTION_OF_DEC_MPLS_TTL,
262 ACTION_OF_SET_NW_TTL,
263 ACTION_OF_SET_NW_TTL_NW_TTL,
264 ACTION_OF_DEC_NW_TTL,
265 ACTION_OF_COPY_TTL_OUT,
266 ACTION_OF_COPY_TTL_IN,
269 ACTION_OF_PUSH_VLAN_ETHERTYPE,
270 ACTION_OF_SET_VLAN_VID,
271 ACTION_OF_SET_VLAN_VID_VLAN_VID,
272 ACTION_OF_SET_VLAN_PCP,
273 ACTION_OF_SET_VLAN_PCP_VLAN_PCP,
275 ACTION_OF_POP_MPLS_ETHERTYPE,
277 ACTION_OF_PUSH_MPLS_ETHERTYPE,
284 ACTION_MPLSOGRE_ENCAP,
285 ACTION_MPLSOGRE_DECAP,
286 ACTION_MPLSOUDP_ENCAP,
287 ACTION_MPLSOUDP_DECAP,
289 ACTION_SET_IPV4_SRC_IPV4_SRC,
291 ACTION_SET_IPV4_DST_IPV4_DST,
293 ACTION_SET_IPV6_SRC_IPV6_SRC,
295 ACTION_SET_IPV6_DST_IPV6_DST,
297 ACTION_SET_TP_SRC_TP_SRC,
299 ACTION_SET_TP_DST_TP_DST,
305 ACTION_SET_MAC_SRC_MAC_SRC,
307 ACTION_SET_MAC_DST_MAC_DST,
309 ACTION_INC_TCP_SEQ_VALUE,
311 ACTION_DEC_TCP_SEQ_VALUE,
313 ACTION_INC_TCP_ACK_VALUE,
315 ACTION_DEC_TCP_ACK_VALUE,
318 ACTION_RAW_ENCAP_INDEX,
319 ACTION_RAW_ENCAP_INDEX_VALUE,
320 ACTION_RAW_DECAP_INDEX,
321 ACTION_RAW_DECAP_INDEX_VALUE,
324 ACTION_SET_TAG_INDEX,
327 ACTION_SET_META_DATA,
328 ACTION_SET_META_MASK,
329 ACTION_SET_IPV4_DSCP,
330 ACTION_SET_IPV4_DSCP_VALUE,
331 ACTION_SET_IPV6_DSCP,
332 ACTION_SET_IPV6_DSCP_VALUE,
335 /** Maximum size for pattern in struct rte_flow_item_raw. */
336 #define ITEM_RAW_PATTERN_SIZE 40
338 /** Storage size for struct rte_flow_item_raw including pattern. */
339 #define ITEM_RAW_SIZE \
340 (sizeof(struct rte_flow_item_raw) + ITEM_RAW_PATTERN_SIZE)
342 /** Maximum number of queue indices in struct rte_flow_action_rss. */
343 #define ACTION_RSS_QUEUE_NUM 128
345 /** Storage for struct rte_flow_action_rss including external data. */
346 struct action_rss_data {
347 struct rte_flow_action_rss conf;
348 uint8_t key[RSS_HASH_KEY_LENGTH];
349 uint16_t queue[ACTION_RSS_QUEUE_NUM];
352 /** Maximum data size in struct rte_flow_action_raw_encap. */
353 #define ACTION_RAW_ENCAP_MAX_DATA 128
354 #define RAW_ENCAP_CONFS_MAX_NUM 8
356 /** Storage for struct rte_flow_action_raw_encap. */
357 struct raw_encap_conf {
358 uint8_t data[ACTION_RAW_ENCAP_MAX_DATA];
359 uint8_t preserve[ACTION_RAW_ENCAP_MAX_DATA];
363 struct raw_encap_conf raw_encap_confs[RAW_ENCAP_CONFS_MAX_NUM];
365 /** Storage for struct rte_flow_action_raw_encap including external data. */
366 struct action_raw_encap_data {
367 struct rte_flow_action_raw_encap conf;
368 uint8_t data[ACTION_RAW_ENCAP_MAX_DATA];
369 uint8_t preserve[ACTION_RAW_ENCAP_MAX_DATA];
373 /** Storage for struct rte_flow_action_raw_decap. */
374 struct raw_decap_conf {
375 uint8_t data[ACTION_RAW_ENCAP_MAX_DATA];
379 struct raw_decap_conf raw_decap_confs[RAW_ENCAP_CONFS_MAX_NUM];
381 /** Storage for struct rte_flow_action_raw_decap including external data. */
382 struct action_raw_decap_data {
383 struct rte_flow_action_raw_decap conf;
384 uint8_t data[ACTION_RAW_ENCAP_MAX_DATA];
388 struct vxlan_encap_conf vxlan_encap_conf = {
392 .vni = "\x00\x00\x00",
394 .udp_dst = RTE_BE16(4789),
395 .ipv4_src = RTE_IPV4(127, 0, 0, 1),
396 .ipv4_dst = RTE_IPV4(255, 255, 255, 255),
397 .ipv6_src = "\x00\x00\x00\x00\x00\x00\x00\x00"
398 "\x00\x00\x00\x00\x00\x00\x00\x01",
399 .ipv6_dst = "\x00\x00\x00\x00\x00\x00\x00\x00"
400 "\x00\x00\x00\x00\x00\x00\x11\x11",
404 .eth_src = "\x00\x00\x00\x00\x00\x00",
405 .eth_dst = "\xff\xff\xff\xff\xff\xff",
408 /** Maximum number of items in struct rte_flow_action_vxlan_encap. */
409 #define ACTION_VXLAN_ENCAP_ITEMS_NUM 6
411 /** Storage for struct rte_flow_action_vxlan_encap including external data. */
412 struct action_vxlan_encap_data {
413 struct rte_flow_action_vxlan_encap conf;
414 struct rte_flow_item items[ACTION_VXLAN_ENCAP_ITEMS_NUM];
415 struct rte_flow_item_eth item_eth;
416 struct rte_flow_item_vlan item_vlan;
418 struct rte_flow_item_ipv4 item_ipv4;
419 struct rte_flow_item_ipv6 item_ipv6;
421 struct rte_flow_item_udp item_udp;
422 struct rte_flow_item_vxlan item_vxlan;
425 struct nvgre_encap_conf nvgre_encap_conf = {
428 .tni = "\x00\x00\x00",
429 .ipv4_src = RTE_IPV4(127, 0, 0, 1),
430 .ipv4_dst = RTE_IPV4(255, 255, 255, 255),
431 .ipv6_src = "\x00\x00\x00\x00\x00\x00\x00\x00"
432 "\x00\x00\x00\x00\x00\x00\x00\x01",
433 .ipv6_dst = "\x00\x00\x00\x00\x00\x00\x00\x00"
434 "\x00\x00\x00\x00\x00\x00\x11\x11",
436 .eth_src = "\x00\x00\x00\x00\x00\x00",
437 .eth_dst = "\xff\xff\xff\xff\xff\xff",
440 /** Maximum number of items in struct rte_flow_action_nvgre_encap. */
441 #define ACTION_NVGRE_ENCAP_ITEMS_NUM 5
443 /** Storage for struct rte_flow_action_nvgre_encap including external data. */
444 struct action_nvgre_encap_data {
445 struct rte_flow_action_nvgre_encap conf;
446 struct rte_flow_item items[ACTION_NVGRE_ENCAP_ITEMS_NUM];
447 struct rte_flow_item_eth item_eth;
448 struct rte_flow_item_vlan item_vlan;
450 struct rte_flow_item_ipv4 item_ipv4;
451 struct rte_flow_item_ipv6 item_ipv6;
453 struct rte_flow_item_nvgre item_nvgre;
456 struct l2_encap_conf l2_encap_conf;
458 struct l2_decap_conf l2_decap_conf;
460 struct mplsogre_encap_conf mplsogre_encap_conf;
462 struct mplsogre_decap_conf mplsogre_decap_conf;
464 struct mplsoudp_encap_conf mplsoudp_encap_conf;
466 struct mplsoudp_decap_conf mplsoudp_decap_conf;
468 /** Maximum number of subsequent tokens and arguments on the stack. */
469 #define CTX_STACK_SIZE 16
471 /** Parser context. */
473 /** Stack of subsequent token lists to process. */
474 const enum index *next[CTX_STACK_SIZE];
475 /** Arguments for stacked tokens. */
476 const void *args[CTX_STACK_SIZE];
477 enum index curr; /**< Current token index. */
478 enum index prev; /**< Index of the last token seen. */
479 int next_num; /**< Number of entries in next[]. */
480 int args_num; /**< Number of entries in args[]. */
481 uint32_t eol:1; /**< EOL has been detected. */
482 uint32_t last:1; /**< No more arguments. */
483 portid_t port; /**< Current port ID (for completions). */
484 uint32_t objdata; /**< Object-specific data. */
485 void *object; /**< Address of current object for relative offsets. */
486 void *objmask; /**< Object a full mask must be written to. */
489 /** Token argument. */
491 uint32_t hton:1; /**< Use network byte ordering. */
492 uint32_t sign:1; /**< Value is signed. */
493 uint32_t bounded:1; /**< Value is bounded. */
494 uintmax_t min; /**< Minimum value if bounded. */
495 uintmax_t max; /**< Maximum value if bounded. */
496 uint32_t offset; /**< Relative offset from ctx->object. */
497 uint32_t size; /**< Field size. */
498 const uint8_t *mask; /**< Bit-mask to use instead of offset/size. */
501 /** Parser token definition. */
503 /** Type displayed during completion (defaults to "TOKEN"). */
505 /** Help displayed during completion (defaults to token name). */
507 /** Private data used by parser functions. */
510 * Lists of subsequent tokens to push on the stack. Each call to the
511 * parser consumes the last entry of that stack.
513 const enum index *const *next;
514 /** Arguments stack for subsequent tokens that need them. */
515 const struct arg *const *args;
517 * Token-processing callback, returns -1 in case of error, the
518 * length of the matched string otherwise. If NULL, attempts to
519 * match the token name.
521 * If buf is not NULL, the result should be stored in it according
522 * to context. An error is returned if not large enough.
524 int (*call)(struct context *ctx, const struct token *token,
525 const char *str, unsigned int len,
526 void *buf, unsigned int size);
528 * Callback that provides possible values for this token, used for
529 * completion. Returns -1 in case of error, the number of possible
530 * values otherwise. If NULL, the token name is used.
532 * If buf is not NULL, entry index ent is written to buf and the
533 * full length of the entry is returned (same behavior as
536 int (*comp)(struct context *ctx, const struct token *token,
537 unsigned int ent, char *buf, unsigned int size);
538 /** Mandatory token name, no default value. */
542 /** Static initializer for the next field. */
543 #define NEXT(...) (const enum index *const []){ __VA_ARGS__, NULL, }
545 /** Static initializer for a NEXT() entry. */
546 #define NEXT_ENTRY(...) (const enum index []){ __VA_ARGS__, ZERO, }
548 /** Static initializer for the args field. */
549 #define ARGS(...) (const struct arg *const []){ __VA_ARGS__, NULL, }
551 /** Static initializer for ARGS() to target a field. */
552 #define ARGS_ENTRY(s, f) \
553 (&(const struct arg){ \
554 .offset = offsetof(s, f), \
555 .size = sizeof(((s *)0)->f), \
558 /** Static initializer for ARGS() to target a bit-field. */
559 #define ARGS_ENTRY_BF(s, f, b) \
560 (&(const struct arg){ \
562 .mask = (const void *)&(const s){ .f = (1 << (b)) - 1 }, \
565 /** Static initializer for ARGS() to target an arbitrary bit-mask. */
566 #define ARGS_ENTRY_MASK(s, f, m) \
567 (&(const struct arg){ \
568 .offset = offsetof(s, f), \
569 .size = sizeof(((s *)0)->f), \
570 .mask = (const void *)(m), \
573 /** Same as ARGS_ENTRY_MASK() using network byte ordering for the value. */
574 #define ARGS_ENTRY_MASK_HTON(s, f, m) \
575 (&(const struct arg){ \
577 .offset = offsetof(s, f), \
578 .size = sizeof(((s *)0)->f), \
579 .mask = (const void *)(m), \
582 /** Static initializer for ARGS() to target a pointer. */
583 #define ARGS_ENTRY_PTR(s, f) \
584 (&(const struct arg){ \
585 .size = sizeof(*((s *)0)->f), \
588 /** Static initializer for ARGS() with arbitrary offset and size. */
589 #define ARGS_ENTRY_ARB(o, s) \
590 (&(const struct arg){ \
595 /** Same as ARGS_ENTRY_ARB() with bounded values. */
596 #define ARGS_ENTRY_ARB_BOUNDED(o, s, i, a) \
597 (&(const struct arg){ \
605 /** Same as ARGS_ENTRY() using network byte ordering. */
606 #define ARGS_ENTRY_HTON(s, f) \
607 (&(const struct arg){ \
609 .offset = offsetof(s, f), \
610 .size = sizeof(((s *)0)->f), \
613 /** Same as ARGS_ENTRY_HTON() for a single argument, without structure. */
614 #define ARG_ENTRY_HTON(s) \
615 (&(const struct arg){ \
621 /** Parser output buffer layout expected by cmd_flow_parsed(). */
623 enum index command; /**< Flow command. */
624 portid_t port; /**< Affected port ID. */
627 struct rte_flow_attr attr;
628 struct rte_flow_item *pattern;
629 struct rte_flow_action *actions;
633 } vc; /**< Validate/create arguments. */
637 } destroy; /**< Destroy arguments. */
640 struct rte_flow_action action;
641 } query; /**< Query arguments. */
645 } list; /**< List arguments. */
648 } isolate; /**< Isolated mode arguments. */
649 } args; /**< Command arguments. */
652 /** Private data for pattern items. */
653 struct parse_item_priv {
654 enum rte_flow_item_type type; /**< Item type. */
655 uint32_t size; /**< Size of item specification structure. */
658 #define PRIV_ITEM(t, s) \
659 (&(const struct parse_item_priv){ \
660 .type = RTE_FLOW_ITEM_TYPE_ ## t, \
664 /** Private data for actions. */
665 struct parse_action_priv {
666 enum rte_flow_action_type type; /**< Action type. */
667 uint32_t size; /**< Size of action configuration structure. */
670 #define PRIV_ACTION(t, s) \
671 (&(const struct parse_action_priv){ \
672 .type = RTE_FLOW_ACTION_TYPE_ ## t, \
676 static const enum index next_vc_attr[] = {
686 static const enum index next_destroy_attr[] = {
692 static const enum index next_list_attr[] = {
698 static const enum index item_param[] = {
707 static const enum index next_item[] = {
743 ITEM_ICMP6_ND_OPT_SLA_ETH,
744 ITEM_ICMP6_ND_OPT_TLA_ETH,
757 static const enum index item_fuzzy[] = {
763 static const enum index item_any[] = {
769 static const enum index item_vf[] = {
775 static const enum index item_phy_port[] = {
781 static const enum index item_port_id[] = {
787 static const enum index item_mark[] = {
793 static const enum index item_raw[] = {
803 static const enum index item_eth[] = {
811 static const enum index item_vlan[] = {
816 ITEM_VLAN_INNER_TYPE,
821 static const enum index item_ipv4[] = {
831 static const enum index item_ipv6[] = {
842 static const enum index item_icmp[] = {
849 static const enum index item_udp[] = {
856 static const enum index item_tcp[] = {
864 static const enum index item_sctp[] = {
873 static const enum index item_vxlan[] = {
879 static const enum index item_e_tag[] = {
880 ITEM_E_TAG_GRP_ECID_B,
885 static const enum index item_nvgre[] = {
891 static const enum index item_mpls[] = {
899 static const enum index item_gre[] = {
901 ITEM_GRE_C_RSVD0_VER,
909 static const enum index item_gre_key[] = {
915 static const enum index item_gtp[] = {
921 static const enum index item_geneve[] = {
928 static const enum index item_vxlan_gpe[] = {
934 static const enum index item_arp_eth_ipv4[] = {
935 ITEM_ARP_ETH_IPV4_SHA,
936 ITEM_ARP_ETH_IPV4_SPA,
937 ITEM_ARP_ETH_IPV4_THA,
938 ITEM_ARP_ETH_IPV4_TPA,
943 static const enum index item_ipv6_ext[] = {
944 ITEM_IPV6_EXT_NEXT_HDR,
949 static const enum index item_icmp6[] = {
956 static const enum index item_icmp6_nd_ns[] = {
957 ITEM_ICMP6_ND_NS_TARGET_ADDR,
962 static const enum index item_icmp6_nd_na[] = {
963 ITEM_ICMP6_ND_NA_TARGET_ADDR,
968 static const enum index item_icmp6_nd_opt[] = {
969 ITEM_ICMP6_ND_OPT_TYPE,
974 static const enum index item_icmp6_nd_opt_sla_eth[] = {
975 ITEM_ICMP6_ND_OPT_SLA_ETH_SLA,
980 static const enum index item_icmp6_nd_opt_tla_eth[] = {
981 ITEM_ICMP6_ND_OPT_TLA_ETH_TLA,
986 static const enum index item_meta[] = {
992 static const enum index item_gtp_psc[] = {
999 static const enum index item_pppoed[] = {
1005 static const enum index item_pppoes[] = {
1011 static const enum index item_pppoe_proto_id[] = {
1012 ITEM_PPPOE_PROTO_ID,
1017 static const enum index item_higig2[] = {
1018 ITEM_HIGIG2_CLASSIFICATION,
1024 static const enum index next_set_raw[] = {
1030 static const enum index item_tag[] = {
1037 static const enum index next_action[] = {
1053 ACTION_OF_SET_MPLS_TTL,
1054 ACTION_OF_DEC_MPLS_TTL,
1055 ACTION_OF_SET_NW_TTL,
1056 ACTION_OF_DEC_NW_TTL,
1057 ACTION_OF_COPY_TTL_OUT,
1058 ACTION_OF_COPY_TTL_IN,
1060 ACTION_OF_PUSH_VLAN,
1061 ACTION_OF_SET_VLAN_VID,
1062 ACTION_OF_SET_VLAN_PCP,
1064 ACTION_OF_PUSH_MPLS,
1071 ACTION_MPLSOGRE_ENCAP,
1072 ACTION_MPLSOGRE_DECAP,
1073 ACTION_MPLSOUDP_ENCAP,
1074 ACTION_MPLSOUDP_DECAP,
1075 ACTION_SET_IPV4_SRC,
1076 ACTION_SET_IPV4_DST,
1077 ACTION_SET_IPV6_SRC,
1078 ACTION_SET_IPV6_DST,
1094 ACTION_SET_IPV4_DSCP,
1095 ACTION_SET_IPV6_DSCP,
1099 static const enum index action_mark[] = {
1105 static const enum index action_queue[] = {
1111 static const enum index action_count[] = {
1113 ACTION_COUNT_SHARED,
1118 static const enum index action_rss[] = {
1129 static const enum index action_vf[] = {
1136 static const enum index action_phy_port[] = {
1137 ACTION_PHY_PORT_ORIGINAL,
1138 ACTION_PHY_PORT_INDEX,
1143 static const enum index action_port_id[] = {
1144 ACTION_PORT_ID_ORIGINAL,
1150 static const enum index action_meter[] = {
1156 static const enum index action_of_set_mpls_ttl[] = {
1157 ACTION_OF_SET_MPLS_TTL_MPLS_TTL,
1162 static const enum index action_of_set_nw_ttl[] = {
1163 ACTION_OF_SET_NW_TTL_NW_TTL,
1168 static const enum index action_of_push_vlan[] = {
1169 ACTION_OF_PUSH_VLAN_ETHERTYPE,
1174 static const enum index action_of_set_vlan_vid[] = {
1175 ACTION_OF_SET_VLAN_VID_VLAN_VID,
1180 static const enum index action_of_set_vlan_pcp[] = {
1181 ACTION_OF_SET_VLAN_PCP_VLAN_PCP,
1186 static const enum index action_of_pop_mpls[] = {
1187 ACTION_OF_POP_MPLS_ETHERTYPE,
1192 static const enum index action_of_push_mpls[] = {
1193 ACTION_OF_PUSH_MPLS_ETHERTYPE,
1198 static const enum index action_set_ipv4_src[] = {
1199 ACTION_SET_IPV4_SRC_IPV4_SRC,
1204 static const enum index action_set_mac_src[] = {
1205 ACTION_SET_MAC_SRC_MAC_SRC,
1210 static const enum index action_set_ipv4_dst[] = {
1211 ACTION_SET_IPV4_DST_IPV4_DST,
1216 static const enum index action_set_ipv6_src[] = {
1217 ACTION_SET_IPV6_SRC_IPV6_SRC,
1222 static const enum index action_set_ipv6_dst[] = {
1223 ACTION_SET_IPV6_DST_IPV6_DST,
1228 static const enum index action_set_tp_src[] = {
1229 ACTION_SET_TP_SRC_TP_SRC,
1234 static const enum index action_set_tp_dst[] = {
1235 ACTION_SET_TP_DST_TP_DST,
1240 static const enum index action_set_ttl[] = {
1246 static const enum index action_jump[] = {
1252 static const enum index action_set_mac_dst[] = {
1253 ACTION_SET_MAC_DST_MAC_DST,
1258 static const enum index action_inc_tcp_seq[] = {
1259 ACTION_INC_TCP_SEQ_VALUE,
1264 static const enum index action_dec_tcp_seq[] = {
1265 ACTION_DEC_TCP_SEQ_VALUE,
1270 static const enum index action_inc_tcp_ack[] = {
1271 ACTION_INC_TCP_ACK_VALUE,
1276 static const enum index action_dec_tcp_ack[] = {
1277 ACTION_DEC_TCP_ACK_VALUE,
1282 static const enum index action_raw_encap[] = {
1283 ACTION_RAW_ENCAP_INDEX,
1288 static const enum index action_raw_decap[] = {
1289 ACTION_RAW_DECAP_INDEX,
1294 static const enum index action_set_tag[] = {
1295 ACTION_SET_TAG_DATA,
1296 ACTION_SET_TAG_INDEX,
1297 ACTION_SET_TAG_MASK,
1302 static const enum index action_set_meta[] = {
1303 ACTION_SET_META_DATA,
1304 ACTION_SET_META_MASK,
1309 static const enum index action_set_ipv4_dscp[] = {
1310 ACTION_SET_IPV4_DSCP_VALUE,
1315 static const enum index action_set_ipv6_dscp[] = {
1316 ACTION_SET_IPV6_DSCP_VALUE,
1321 static int parse_set_raw_encap_decap(struct context *, const struct token *,
1322 const char *, unsigned int,
1323 void *, unsigned int);
1324 static int parse_set_init(struct context *, const struct token *,
1325 const char *, unsigned int,
1326 void *, unsigned int);
1327 static int parse_init(struct context *, const struct token *,
1328 const char *, unsigned int,
1329 void *, unsigned int);
1330 static int parse_vc(struct context *, const struct token *,
1331 const char *, unsigned int,
1332 void *, unsigned int);
1333 static int parse_vc_spec(struct context *, const struct token *,
1334 const char *, unsigned int, void *, unsigned int);
1335 static int parse_vc_conf(struct context *, const struct token *,
1336 const char *, unsigned int, void *, unsigned int);
1337 static int parse_vc_action_rss(struct context *, const struct token *,
1338 const char *, unsigned int, void *,
1340 static int parse_vc_action_rss_func(struct context *, const struct token *,
1341 const char *, unsigned int, void *,
1343 static int parse_vc_action_rss_type(struct context *, const struct token *,
1344 const char *, unsigned int, void *,
1346 static int parse_vc_action_rss_queue(struct context *, const struct token *,
1347 const char *, unsigned int, void *,
1349 static int parse_vc_action_vxlan_encap(struct context *, const struct token *,
1350 const char *, unsigned int, void *,
1352 static int parse_vc_action_nvgre_encap(struct context *, const struct token *,
1353 const char *, unsigned int, void *,
1355 static int parse_vc_action_l2_encap(struct context *, const struct token *,
1356 const char *, unsigned int, void *,
1358 static int parse_vc_action_l2_decap(struct context *, const struct token *,
1359 const char *, unsigned int, void *,
1361 static int parse_vc_action_mplsogre_encap(struct context *,
1362 const struct token *, const char *,
1363 unsigned int, void *, unsigned int);
1364 static int parse_vc_action_mplsogre_decap(struct context *,
1365 const struct token *, const char *,
1366 unsigned int, void *, unsigned int);
1367 static int parse_vc_action_mplsoudp_encap(struct context *,
1368 const struct token *, const char *,
1369 unsigned int, void *, unsigned int);
1370 static int parse_vc_action_mplsoudp_decap(struct context *,
1371 const struct token *, const char *,
1372 unsigned int, void *, unsigned int);
1373 static int parse_vc_action_raw_encap(struct context *,
1374 const struct token *, const char *,
1375 unsigned int, void *, unsigned int);
1376 static int parse_vc_action_raw_decap(struct context *,
1377 const struct token *, const char *,
1378 unsigned int, void *, unsigned int);
1379 static int parse_vc_action_raw_encap_index(struct context *,
1380 const struct token *, const char *,
1381 unsigned int, void *, unsigned int);
1382 static int parse_vc_action_raw_decap_index(struct context *,
1383 const struct token *, const char *,
1384 unsigned int, void *, unsigned int);
1385 static int parse_vc_action_set_meta(struct context *ctx,
1386 const struct token *token, const char *str,
1387 unsigned int len, void *buf,
1389 static int parse_destroy(struct context *, const struct token *,
1390 const char *, unsigned int,
1391 void *, unsigned int);
1392 static int parse_flush(struct context *, const struct token *,
1393 const char *, unsigned int,
1394 void *, unsigned int);
1395 static int parse_query(struct context *, const struct token *,
1396 const char *, unsigned int,
1397 void *, unsigned int);
1398 static int parse_action(struct context *, const struct token *,
1399 const char *, unsigned int,
1400 void *, unsigned int);
1401 static int parse_list(struct context *, const struct token *,
1402 const char *, unsigned int,
1403 void *, unsigned int);
1404 static int parse_isolate(struct context *, const struct token *,
1405 const char *, unsigned int,
1406 void *, unsigned int);
1407 static int parse_int(struct context *, const struct token *,
1408 const char *, unsigned int,
1409 void *, unsigned int);
1410 static int parse_prefix(struct context *, const struct token *,
1411 const char *, unsigned int,
1412 void *, unsigned int);
1413 static int parse_boolean(struct context *, const struct token *,
1414 const char *, unsigned int,
1415 void *, unsigned int);
1416 static int parse_string(struct context *, const struct token *,
1417 const char *, unsigned int,
1418 void *, unsigned int);
1419 static int parse_hex(struct context *ctx, const struct token *token,
1420 const char *str, unsigned int len,
1421 void *buf, unsigned int size);
1422 static int parse_mac_addr(struct context *, const struct token *,
1423 const char *, unsigned int,
1424 void *, unsigned int);
1425 static int parse_ipv4_addr(struct context *, const struct token *,
1426 const char *, unsigned int,
1427 void *, unsigned int);
1428 static int parse_ipv6_addr(struct context *, const struct token *,
1429 const char *, unsigned int,
1430 void *, unsigned int);
1431 static int parse_port(struct context *, const struct token *,
1432 const char *, unsigned int,
1433 void *, unsigned int);
1434 static int comp_none(struct context *, const struct token *,
1435 unsigned int, char *, unsigned int);
1436 static int comp_boolean(struct context *, const struct token *,
1437 unsigned int, char *, unsigned int);
1438 static int comp_action(struct context *, const struct token *,
1439 unsigned int, char *, unsigned int);
1440 static int comp_port(struct context *, const struct token *,
1441 unsigned int, char *, unsigned int);
1442 static int comp_rule_id(struct context *, const struct token *,
1443 unsigned int, char *, unsigned int);
1444 static int comp_vc_action_rss_type(struct context *, const struct token *,
1445 unsigned int, char *, unsigned int);
1446 static int comp_vc_action_rss_queue(struct context *, const struct token *,
1447 unsigned int, char *, unsigned int);
1448 static int comp_set_raw_index(struct context *, const struct token *,
1449 unsigned int, char *, unsigned int);
1451 /** Token definitions. */
1452 static const struct token token_list[] = {
1453 /* Special tokens. */
1456 .help = "null entry, abused as the entry point",
1457 .next = NEXT(NEXT_ENTRY(FLOW)),
1462 .help = "command may end here",
1465 .name = "START_SET",
1466 .help = "null entry, abused as the entry point for set",
1467 .next = NEXT(NEXT_ENTRY(SET)),
1472 .help = "set command may end here",
1474 /* Common tokens. */
1478 .help = "integer value",
1483 .name = "{unsigned}",
1485 .help = "unsigned integer value",
1492 .help = "prefix length for bit-mask",
1493 .call = parse_prefix,
1497 .name = "{boolean}",
1499 .help = "any boolean value",
1500 .call = parse_boolean,
1501 .comp = comp_boolean,
1506 .help = "fixed string",
1507 .call = parse_string,
1513 .help = "fixed string",
1518 .name = "{MAC address}",
1520 .help = "standard MAC address notation",
1521 .call = parse_mac_addr,
1525 .name = "{IPv4 address}",
1526 .type = "IPV4 ADDRESS",
1527 .help = "standard IPv4 address notation",
1528 .call = parse_ipv4_addr,
1532 .name = "{IPv6 address}",
1533 .type = "IPV6 ADDRESS",
1534 .help = "standard IPv6 address notation",
1535 .call = parse_ipv6_addr,
1539 .name = "{rule id}",
1541 .help = "rule identifier",
1543 .comp = comp_rule_id,
1546 .name = "{port_id}",
1548 .help = "port identifier",
1553 .name = "{group_id}",
1555 .help = "group identifier",
1559 [PRIORITY_LEVEL] = {
1562 .help = "priority level",
1566 /* Top-level command. */
1569 .type = "{command} {port_id} [{arg} [...]]",
1570 .help = "manage ingress/egress flow rules",
1571 .next = NEXT(NEXT_ENTRY
1581 /* Sub-level commands. */
1584 .help = "check whether a flow rule can be created",
1585 .next = NEXT(next_vc_attr, NEXT_ENTRY(PORT_ID)),
1586 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1591 .help = "create a flow rule",
1592 .next = NEXT(next_vc_attr, NEXT_ENTRY(PORT_ID)),
1593 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1598 .help = "destroy specific flow rules",
1599 .next = NEXT(NEXT_ENTRY(DESTROY_RULE), NEXT_ENTRY(PORT_ID)),
1600 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1601 .call = parse_destroy,
1605 .help = "destroy all flow rules",
1606 .next = NEXT(NEXT_ENTRY(PORT_ID)),
1607 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1608 .call = parse_flush,
1612 .help = "query an existing flow rule",
1613 .next = NEXT(NEXT_ENTRY(QUERY_ACTION),
1614 NEXT_ENTRY(RULE_ID),
1615 NEXT_ENTRY(PORT_ID)),
1616 .args = ARGS(ARGS_ENTRY(struct buffer, args.query.action.type),
1617 ARGS_ENTRY(struct buffer, args.query.rule),
1618 ARGS_ENTRY(struct buffer, port)),
1619 .call = parse_query,
1623 .help = "list existing flow rules",
1624 .next = NEXT(next_list_attr, NEXT_ENTRY(PORT_ID)),
1625 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1630 .help = "restrict ingress traffic to the defined flow rules",
1631 .next = NEXT(NEXT_ENTRY(BOOLEAN),
1632 NEXT_ENTRY(PORT_ID)),
1633 .args = ARGS(ARGS_ENTRY(struct buffer, args.isolate.set),
1634 ARGS_ENTRY(struct buffer, port)),
1635 .call = parse_isolate,
1637 /* Destroy arguments. */
1640 .help = "specify a rule identifier",
1641 .next = NEXT(next_destroy_attr, NEXT_ENTRY(RULE_ID)),
1642 .args = ARGS(ARGS_ENTRY_PTR(struct buffer, args.destroy.rule)),
1643 .call = parse_destroy,
1645 /* Query arguments. */
1649 .help = "action to query, must be part of the rule",
1650 .call = parse_action,
1651 .comp = comp_action,
1653 /* List arguments. */
1656 .help = "specify a group",
1657 .next = NEXT(next_list_attr, NEXT_ENTRY(GROUP_ID)),
1658 .args = ARGS(ARGS_ENTRY_PTR(struct buffer, args.list.group)),
1661 /* Validate/create attributes. */
1664 .help = "specify a group",
1665 .next = NEXT(next_vc_attr, NEXT_ENTRY(GROUP_ID)),
1666 .args = ARGS(ARGS_ENTRY(struct rte_flow_attr, group)),
1671 .help = "specify a priority level",
1672 .next = NEXT(next_vc_attr, NEXT_ENTRY(PRIORITY_LEVEL)),
1673 .args = ARGS(ARGS_ENTRY(struct rte_flow_attr, priority)),
1678 .help = "affect rule to ingress",
1679 .next = NEXT(next_vc_attr),
1684 .help = "affect rule to egress",
1685 .next = NEXT(next_vc_attr),
1690 .help = "apply rule directly to endpoints found in pattern",
1691 .next = NEXT(next_vc_attr),
1694 /* Validate/create pattern. */
1697 .help = "submit a list of pattern items",
1698 .next = NEXT(next_item),
1703 .help = "match value perfectly (with full bit-mask)",
1704 .call = parse_vc_spec,
1706 [ITEM_PARAM_SPEC] = {
1708 .help = "match value according to configured bit-mask",
1709 .call = parse_vc_spec,
1711 [ITEM_PARAM_LAST] = {
1713 .help = "specify upper bound to establish a range",
1714 .call = parse_vc_spec,
1716 [ITEM_PARAM_MASK] = {
1718 .help = "specify bit-mask with relevant bits set to one",
1719 .call = parse_vc_spec,
1721 [ITEM_PARAM_PREFIX] = {
1723 .help = "generate bit-mask from a prefix length",
1724 .call = parse_vc_spec,
1728 .help = "specify next pattern item",
1729 .next = NEXT(next_item),
1733 .help = "end list of pattern items",
1734 .priv = PRIV_ITEM(END, 0),
1735 .next = NEXT(NEXT_ENTRY(ACTIONS)),
1740 .help = "no-op pattern item",
1741 .priv = PRIV_ITEM(VOID, 0),
1742 .next = NEXT(NEXT_ENTRY(ITEM_NEXT)),
1747 .help = "perform actions when pattern does not match",
1748 .priv = PRIV_ITEM(INVERT, 0),
1749 .next = NEXT(NEXT_ENTRY(ITEM_NEXT)),
1754 .help = "match any protocol for the current layer",
1755 .priv = PRIV_ITEM(ANY, sizeof(struct rte_flow_item_any)),
1756 .next = NEXT(item_any),
1761 .help = "number of layers covered",
1762 .next = NEXT(item_any, NEXT_ENTRY(UNSIGNED), item_param),
1763 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_any, num)),
1767 .help = "match traffic from/to the physical function",
1768 .priv = PRIV_ITEM(PF, 0),
1769 .next = NEXT(NEXT_ENTRY(ITEM_NEXT)),
1774 .help = "match traffic from/to a virtual function ID",
1775 .priv = PRIV_ITEM(VF, sizeof(struct rte_flow_item_vf)),
1776 .next = NEXT(item_vf),
1782 .next = NEXT(item_vf, NEXT_ENTRY(UNSIGNED), item_param),
1783 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_vf, id)),
1787 .help = "match traffic from/to a specific physical port",
1788 .priv = PRIV_ITEM(PHY_PORT,
1789 sizeof(struct rte_flow_item_phy_port)),
1790 .next = NEXT(item_phy_port),
1793 [ITEM_PHY_PORT_INDEX] = {
1795 .help = "physical port index",
1796 .next = NEXT(item_phy_port, NEXT_ENTRY(UNSIGNED), item_param),
1797 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_phy_port, index)),
1801 .help = "match traffic from/to a given DPDK port ID",
1802 .priv = PRIV_ITEM(PORT_ID,
1803 sizeof(struct rte_flow_item_port_id)),
1804 .next = NEXT(item_port_id),
1807 [ITEM_PORT_ID_ID] = {
1809 .help = "DPDK port ID",
1810 .next = NEXT(item_port_id, NEXT_ENTRY(UNSIGNED), item_param),
1811 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_port_id, id)),
1815 .help = "match traffic against value set in previously matched rule",
1816 .priv = PRIV_ITEM(MARK, sizeof(struct rte_flow_item_mark)),
1817 .next = NEXT(item_mark),
1822 .help = "Integer value to match against",
1823 .next = NEXT(item_mark, NEXT_ENTRY(UNSIGNED), item_param),
1824 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_mark, id)),
1828 .help = "match an arbitrary byte string",
1829 .priv = PRIV_ITEM(RAW, ITEM_RAW_SIZE),
1830 .next = NEXT(item_raw),
1833 [ITEM_RAW_RELATIVE] = {
1835 .help = "look for pattern after the previous item",
1836 .next = NEXT(item_raw, NEXT_ENTRY(BOOLEAN), item_param),
1837 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_item_raw,
1840 [ITEM_RAW_SEARCH] = {
1842 .help = "search pattern from offset (see also limit)",
1843 .next = NEXT(item_raw, NEXT_ENTRY(BOOLEAN), item_param),
1844 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_item_raw,
1847 [ITEM_RAW_OFFSET] = {
1849 .help = "absolute or relative offset for pattern",
1850 .next = NEXT(item_raw, NEXT_ENTRY(INTEGER), item_param),
1851 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_raw, offset)),
1853 [ITEM_RAW_LIMIT] = {
1855 .help = "search area limit for start of pattern",
1856 .next = NEXT(item_raw, NEXT_ENTRY(UNSIGNED), item_param),
1857 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_raw, limit)),
1859 [ITEM_RAW_PATTERN] = {
1861 .help = "byte string to look for",
1862 .next = NEXT(item_raw,
1864 NEXT_ENTRY(ITEM_PARAM_IS,
1867 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_raw, pattern),
1868 ARGS_ENTRY(struct rte_flow_item_raw, length),
1869 ARGS_ENTRY_ARB(sizeof(struct rte_flow_item_raw),
1870 ITEM_RAW_PATTERN_SIZE)),
1874 .help = "match Ethernet header",
1875 .priv = PRIV_ITEM(ETH, sizeof(struct rte_flow_item_eth)),
1876 .next = NEXT(item_eth),
1881 .help = "destination MAC",
1882 .next = NEXT(item_eth, NEXT_ENTRY(MAC_ADDR), item_param),
1883 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_eth, dst)),
1887 .help = "source MAC",
1888 .next = NEXT(item_eth, NEXT_ENTRY(MAC_ADDR), item_param),
1889 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_eth, src)),
1893 .help = "EtherType",
1894 .next = NEXT(item_eth, NEXT_ENTRY(UNSIGNED), item_param),
1895 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_eth, type)),
1899 .help = "match 802.1Q/ad VLAN tag",
1900 .priv = PRIV_ITEM(VLAN, sizeof(struct rte_flow_item_vlan)),
1901 .next = NEXT(item_vlan),
1906 .help = "tag control information",
1907 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1908 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vlan, tci)),
1912 .help = "priority code point",
1913 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1914 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_vlan,
1919 .help = "drop eligible indicator",
1920 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1921 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_vlan,
1926 .help = "VLAN identifier",
1927 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1928 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_vlan,
1931 [ITEM_VLAN_INNER_TYPE] = {
1932 .name = "inner_type",
1933 .help = "inner EtherType",
1934 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1935 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vlan,
1940 .help = "match IPv4 header",
1941 .priv = PRIV_ITEM(IPV4, sizeof(struct rte_flow_item_ipv4)),
1942 .next = NEXT(item_ipv4),
1947 .help = "type of service",
1948 .next = NEXT(item_ipv4, NEXT_ENTRY(UNSIGNED), item_param),
1949 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
1950 hdr.type_of_service)),
1954 .help = "time to live",
1955 .next = NEXT(item_ipv4, NEXT_ENTRY(UNSIGNED), item_param),
1956 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
1959 [ITEM_IPV4_PROTO] = {
1961 .help = "next protocol ID",
1962 .next = NEXT(item_ipv4, NEXT_ENTRY(UNSIGNED), item_param),
1963 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
1964 hdr.next_proto_id)),
1968 .help = "source address",
1969 .next = NEXT(item_ipv4, NEXT_ENTRY(IPV4_ADDR), item_param),
1970 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
1975 .help = "destination address",
1976 .next = NEXT(item_ipv4, NEXT_ENTRY(IPV4_ADDR), item_param),
1977 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
1982 .help = "match IPv6 header",
1983 .priv = PRIV_ITEM(IPV6, sizeof(struct rte_flow_item_ipv6)),
1984 .next = NEXT(item_ipv6),
1989 .help = "traffic class",
1990 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
1991 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_ipv6,
1993 "\x0f\xf0\x00\x00")),
1995 [ITEM_IPV6_FLOW] = {
1997 .help = "flow label",
1998 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
1999 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_ipv6,
2001 "\x00\x0f\xff\xff")),
2003 [ITEM_IPV6_PROTO] = {
2005 .help = "protocol (next header)",
2006 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
2007 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
2012 .help = "hop limit",
2013 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
2014 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
2019 .help = "source address",
2020 .next = NEXT(item_ipv6, NEXT_ENTRY(IPV6_ADDR), item_param),
2021 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
2026 .help = "destination address",
2027 .next = NEXT(item_ipv6, NEXT_ENTRY(IPV6_ADDR), item_param),
2028 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
2033 .help = "match ICMP header",
2034 .priv = PRIV_ITEM(ICMP, sizeof(struct rte_flow_item_icmp)),
2035 .next = NEXT(item_icmp),
2038 [ITEM_ICMP_TYPE] = {
2040 .help = "ICMP packet type",
2041 .next = NEXT(item_icmp, NEXT_ENTRY(UNSIGNED), item_param),
2042 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp,
2045 [ITEM_ICMP_CODE] = {
2047 .help = "ICMP packet code",
2048 .next = NEXT(item_icmp, NEXT_ENTRY(UNSIGNED), item_param),
2049 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp,
2054 .help = "match UDP header",
2055 .priv = PRIV_ITEM(UDP, sizeof(struct rte_flow_item_udp)),
2056 .next = NEXT(item_udp),
2061 .help = "UDP source port",
2062 .next = NEXT(item_udp, NEXT_ENTRY(UNSIGNED), item_param),
2063 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_udp,
2068 .help = "UDP destination port",
2069 .next = NEXT(item_udp, NEXT_ENTRY(UNSIGNED), item_param),
2070 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_udp,
2075 .help = "match TCP header",
2076 .priv = PRIV_ITEM(TCP, sizeof(struct rte_flow_item_tcp)),
2077 .next = NEXT(item_tcp),
2082 .help = "TCP source port",
2083 .next = NEXT(item_tcp, NEXT_ENTRY(UNSIGNED), item_param),
2084 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_tcp,
2089 .help = "TCP destination port",
2090 .next = NEXT(item_tcp, NEXT_ENTRY(UNSIGNED), item_param),
2091 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_tcp,
2094 [ITEM_TCP_FLAGS] = {
2096 .help = "TCP flags",
2097 .next = NEXT(item_tcp, NEXT_ENTRY(UNSIGNED), item_param),
2098 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_tcp,
2103 .help = "match SCTP header",
2104 .priv = PRIV_ITEM(SCTP, sizeof(struct rte_flow_item_sctp)),
2105 .next = NEXT(item_sctp),
2110 .help = "SCTP source port",
2111 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
2112 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
2117 .help = "SCTP destination port",
2118 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
2119 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
2124 .help = "validation tag",
2125 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
2126 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
2129 [ITEM_SCTP_CKSUM] = {
2132 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
2133 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
2138 .help = "match VXLAN header",
2139 .priv = PRIV_ITEM(VXLAN, sizeof(struct rte_flow_item_vxlan)),
2140 .next = NEXT(item_vxlan),
2143 [ITEM_VXLAN_VNI] = {
2145 .help = "VXLAN identifier",
2146 .next = NEXT(item_vxlan, NEXT_ENTRY(UNSIGNED), item_param),
2147 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vxlan, vni)),
2151 .help = "match E-Tag header",
2152 .priv = PRIV_ITEM(E_TAG, sizeof(struct rte_flow_item_e_tag)),
2153 .next = NEXT(item_e_tag),
2156 [ITEM_E_TAG_GRP_ECID_B] = {
2157 .name = "grp_ecid_b",
2158 .help = "GRP and E-CID base",
2159 .next = NEXT(item_e_tag, NEXT_ENTRY(UNSIGNED), item_param),
2160 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_e_tag,
2166 .help = "match NVGRE header",
2167 .priv = PRIV_ITEM(NVGRE, sizeof(struct rte_flow_item_nvgre)),
2168 .next = NEXT(item_nvgre),
2171 [ITEM_NVGRE_TNI] = {
2173 .help = "virtual subnet ID",
2174 .next = NEXT(item_nvgre, NEXT_ENTRY(UNSIGNED), item_param),
2175 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_nvgre, tni)),
2179 .help = "match MPLS header",
2180 .priv = PRIV_ITEM(MPLS, sizeof(struct rte_flow_item_mpls)),
2181 .next = NEXT(item_mpls),
2184 [ITEM_MPLS_LABEL] = {
2186 .help = "MPLS label",
2187 .next = NEXT(item_mpls, NEXT_ENTRY(UNSIGNED), item_param),
2188 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_mpls,
2194 .help = "MPLS Traffic Class",
2195 .next = NEXT(item_mpls, NEXT_ENTRY(UNSIGNED), item_param),
2196 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_mpls,
2202 .help = "MPLS Bottom-of-Stack",
2203 .next = NEXT(item_mpls, NEXT_ENTRY(UNSIGNED), item_param),
2204 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_mpls,
2210 .help = "match GRE header",
2211 .priv = PRIV_ITEM(GRE, sizeof(struct rte_flow_item_gre)),
2212 .next = NEXT(item_gre),
2215 [ITEM_GRE_PROTO] = {
2217 .help = "GRE protocol type",
2218 .next = NEXT(item_gre, NEXT_ENTRY(UNSIGNED), item_param),
2219 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gre,
2222 [ITEM_GRE_C_RSVD0_VER] = {
2223 .name = "c_rsvd0_ver",
2225 "checksum (1b), undefined (1b), key bit (1b),"
2226 " sequence number (1b), reserved 0 (9b),"
2228 .next = NEXT(item_gre, NEXT_ENTRY(UNSIGNED), item_param),
2229 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gre,
2232 [ITEM_GRE_C_BIT] = {
2234 .help = "checksum bit (C)",
2235 .next = NEXT(item_gre, NEXT_ENTRY(BOOLEAN), item_param),
2236 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_gre,
2238 "\x80\x00\x00\x00")),
2240 [ITEM_GRE_S_BIT] = {
2242 .help = "sequence number bit (S)",
2243 .next = NEXT(item_gre, NEXT_ENTRY(BOOLEAN), item_param),
2244 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_gre,
2246 "\x10\x00\x00\x00")),
2248 [ITEM_GRE_K_BIT] = {
2250 .help = "key bit (K)",
2251 .next = NEXT(item_gre, NEXT_ENTRY(BOOLEAN), item_param),
2252 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_gre,
2254 "\x20\x00\x00\x00")),
2258 .help = "fuzzy pattern match, expect faster than default",
2259 .priv = PRIV_ITEM(FUZZY,
2260 sizeof(struct rte_flow_item_fuzzy)),
2261 .next = NEXT(item_fuzzy),
2264 [ITEM_FUZZY_THRESH] = {
2266 .help = "match accuracy threshold",
2267 .next = NEXT(item_fuzzy, NEXT_ENTRY(UNSIGNED), item_param),
2268 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_fuzzy,
2273 .help = "match GTP header",
2274 .priv = PRIV_ITEM(GTP, sizeof(struct rte_flow_item_gtp)),
2275 .next = NEXT(item_gtp),
2280 .help = "tunnel endpoint identifier",
2281 .next = NEXT(item_gtp, NEXT_ENTRY(UNSIGNED), item_param),
2282 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gtp, teid)),
2286 .help = "match GTP header",
2287 .priv = PRIV_ITEM(GTPC, sizeof(struct rte_flow_item_gtp)),
2288 .next = NEXT(item_gtp),
2293 .help = "match GTP header",
2294 .priv = PRIV_ITEM(GTPU, sizeof(struct rte_flow_item_gtp)),
2295 .next = NEXT(item_gtp),
2300 .help = "match GENEVE header",
2301 .priv = PRIV_ITEM(GENEVE, sizeof(struct rte_flow_item_geneve)),
2302 .next = NEXT(item_geneve),
2305 [ITEM_GENEVE_VNI] = {
2307 .help = "virtual network identifier",
2308 .next = NEXT(item_geneve, NEXT_ENTRY(UNSIGNED), item_param),
2309 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_geneve, vni)),
2311 [ITEM_GENEVE_PROTO] = {
2313 .help = "GENEVE protocol type",
2314 .next = NEXT(item_geneve, NEXT_ENTRY(UNSIGNED), item_param),
2315 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_geneve,
2318 [ITEM_VXLAN_GPE] = {
2319 .name = "vxlan-gpe",
2320 .help = "match VXLAN-GPE header",
2321 .priv = PRIV_ITEM(VXLAN_GPE,
2322 sizeof(struct rte_flow_item_vxlan_gpe)),
2323 .next = NEXT(item_vxlan_gpe),
2326 [ITEM_VXLAN_GPE_VNI] = {
2328 .help = "VXLAN-GPE identifier",
2329 .next = NEXT(item_vxlan_gpe, NEXT_ENTRY(UNSIGNED), item_param),
2330 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vxlan_gpe,
2333 [ITEM_ARP_ETH_IPV4] = {
2334 .name = "arp_eth_ipv4",
2335 .help = "match ARP header for Ethernet/IPv4",
2336 .priv = PRIV_ITEM(ARP_ETH_IPV4,
2337 sizeof(struct rte_flow_item_arp_eth_ipv4)),
2338 .next = NEXT(item_arp_eth_ipv4),
2341 [ITEM_ARP_ETH_IPV4_SHA] = {
2343 .help = "sender hardware address",
2344 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(MAC_ADDR),
2346 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
2349 [ITEM_ARP_ETH_IPV4_SPA] = {
2351 .help = "sender IPv4 address",
2352 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(IPV4_ADDR),
2354 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
2357 [ITEM_ARP_ETH_IPV4_THA] = {
2359 .help = "target hardware address",
2360 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(MAC_ADDR),
2362 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
2365 [ITEM_ARP_ETH_IPV4_TPA] = {
2367 .help = "target IPv4 address",
2368 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(IPV4_ADDR),
2370 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
2375 .help = "match presence of any IPv6 extension header",
2376 .priv = PRIV_ITEM(IPV6_EXT,
2377 sizeof(struct rte_flow_item_ipv6_ext)),
2378 .next = NEXT(item_ipv6_ext),
2381 [ITEM_IPV6_EXT_NEXT_HDR] = {
2383 .help = "next header",
2384 .next = NEXT(item_ipv6_ext, NEXT_ENTRY(UNSIGNED), item_param),
2385 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6_ext,
2390 .help = "match any ICMPv6 header",
2391 .priv = PRIV_ITEM(ICMP6, sizeof(struct rte_flow_item_icmp6)),
2392 .next = NEXT(item_icmp6),
2395 [ITEM_ICMP6_TYPE] = {
2397 .help = "ICMPv6 type",
2398 .next = NEXT(item_icmp6, NEXT_ENTRY(UNSIGNED), item_param),
2399 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6,
2402 [ITEM_ICMP6_CODE] = {
2404 .help = "ICMPv6 code",
2405 .next = NEXT(item_icmp6, NEXT_ENTRY(UNSIGNED), item_param),
2406 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6,
2409 [ITEM_ICMP6_ND_NS] = {
2410 .name = "icmp6_nd_ns",
2411 .help = "match ICMPv6 neighbor discovery solicitation",
2412 .priv = PRIV_ITEM(ICMP6_ND_NS,
2413 sizeof(struct rte_flow_item_icmp6_nd_ns)),
2414 .next = NEXT(item_icmp6_nd_ns),
2417 [ITEM_ICMP6_ND_NS_TARGET_ADDR] = {
2418 .name = "target_addr",
2419 .help = "target address",
2420 .next = NEXT(item_icmp6_nd_ns, NEXT_ENTRY(IPV6_ADDR),
2422 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6_nd_ns,
2425 [ITEM_ICMP6_ND_NA] = {
2426 .name = "icmp6_nd_na",
2427 .help = "match ICMPv6 neighbor discovery advertisement",
2428 .priv = PRIV_ITEM(ICMP6_ND_NA,
2429 sizeof(struct rte_flow_item_icmp6_nd_na)),
2430 .next = NEXT(item_icmp6_nd_na),
2433 [ITEM_ICMP6_ND_NA_TARGET_ADDR] = {
2434 .name = "target_addr",
2435 .help = "target address",
2436 .next = NEXT(item_icmp6_nd_na, NEXT_ENTRY(IPV6_ADDR),
2438 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6_nd_na,
2441 [ITEM_ICMP6_ND_OPT] = {
2442 .name = "icmp6_nd_opt",
2443 .help = "match presence of any ICMPv6 neighbor discovery"
2445 .priv = PRIV_ITEM(ICMP6_ND_OPT,
2446 sizeof(struct rte_flow_item_icmp6_nd_opt)),
2447 .next = NEXT(item_icmp6_nd_opt),
2450 [ITEM_ICMP6_ND_OPT_TYPE] = {
2452 .help = "ND option type",
2453 .next = NEXT(item_icmp6_nd_opt, NEXT_ENTRY(UNSIGNED),
2455 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6_nd_opt,
2458 [ITEM_ICMP6_ND_OPT_SLA_ETH] = {
2459 .name = "icmp6_nd_opt_sla_eth",
2460 .help = "match ICMPv6 neighbor discovery source Ethernet"
2461 " link-layer address option",
2463 (ICMP6_ND_OPT_SLA_ETH,
2464 sizeof(struct rte_flow_item_icmp6_nd_opt_sla_eth)),
2465 .next = NEXT(item_icmp6_nd_opt_sla_eth),
2468 [ITEM_ICMP6_ND_OPT_SLA_ETH_SLA] = {
2470 .help = "source Ethernet LLA",
2471 .next = NEXT(item_icmp6_nd_opt_sla_eth, NEXT_ENTRY(MAC_ADDR),
2473 .args = ARGS(ARGS_ENTRY_HTON
2474 (struct rte_flow_item_icmp6_nd_opt_sla_eth, sla)),
2476 [ITEM_ICMP6_ND_OPT_TLA_ETH] = {
2477 .name = "icmp6_nd_opt_tla_eth",
2478 .help = "match ICMPv6 neighbor discovery target Ethernet"
2479 " link-layer address option",
2481 (ICMP6_ND_OPT_TLA_ETH,
2482 sizeof(struct rte_flow_item_icmp6_nd_opt_tla_eth)),
2483 .next = NEXT(item_icmp6_nd_opt_tla_eth),
2486 [ITEM_ICMP6_ND_OPT_TLA_ETH_TLA] = {
2488 .help = "target Ethernet LLA",
2489 .next = NEXT(item_icmp6_nd_opt_tla_eth, NEXT_ENTRY(MAC_ADDR),
2491 .args = ARGS(ARGS_ENTRY_HTON
2492 (struct rte_flow_item_icmp6_nd_opt_tla_eth, tla)),
2496 .help = "match metadata header",
2497 .priv = PRIV_ITEM(META, sizeof(struct rte_flow_item_meta)),
2498 .next = NEXT(item_meta),
2501 [ITEM_META_DATA] = {
2503 .help = "metadata value",
2504 .next = NEXT(item_meta, NEXT_ENTRY(UNSIGNED), item_param),
2505 .args = ARGS(ARGS_ENTRY_MASK(struct rte_flow_item_meta,
2506 data, "\xff\xff\xff\xff")),
2510 .help = "match GRE key",
2511 .priv = PRIV_ITEM(GRE_KEY, sizeof(rte_be32_t)),
2512 .next = NEXT(item_gre_key),
2515 [ITEM_GRE_KEY_VALUE] = {
2517 .help = "key value",
2518 .next = NEXT(item_gre_key, NEXT_ENTRY(UNSIGNED), item_param),
2519 .args = ARGS(ARG_ENTRY_HTON(rte_be32_t)),
2523 .help = "match GTP extension header with type 0x85",
2524 .priv = PRIV_ITEM(GTP_PSC,
2525 sizeof(struct rte_flow_item_gtp_psc)),
2526 .next = NEXT(item_gtp_psc),
2529 [ITEM_GTP_PSC_QFI] = {
2531 .help = "QoS flow identifier",
2532 .next = NEXT(item_gtp_psc, NEXT_ENTRY(UNSIGNED), item_param),
2533 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gtp_psc,
2536 [ITEM_GTP_PSC_PDU_T] = {
2539 .next = NEXT(item_gtp_psc, NEXT_ENTRY(UNSIGNED), item_param),
2540 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gtp_psc,
2545 .help = "match PPPoE session header",
2546 .priv = PRIV_ITEM(PPPOES, sizeof(struct rte_flow_item_pppoe)),
2547 .next = NEXT(item_pppoes),
2552 .help = "match PPPoE discovery header",
2553 .priv = PRIV_ITEM(PPPOED, sizeof(struct rte_flow_item_pppoe)),
2554 .next = NEXT(item_pppoed),
2557 [ITEM_PPPOE_SEID] = {
2559 .help = "session identifier",
2560 .next = NEXT(item_pppoes, NEXT_ENTRY(UNSIGNED), item_param),
2561 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_pppoe,
2564 [ITEM_PPPOE_PROTO_ID] = {
2566 .help = "match PPPoE session protocol identifier",
2567 .priv = PRIV_ITEM(PPPOE_PROTO_ID,
2568 sizeof(struct rte_flow_item_pppoe_proto_id)),
2569 .next = NEXT(item_pppoe_proto_id),
2574 .help = "matches higig2 header",
2575 .priv = PRIV_ITEM(HIGIG2,
2576 sizeof(struct rte_flow_item_higig2_hdr)),
2577 .next = NEXT(item_higig2),
2580 [ITEM_HIGIG2_CLASSIFICATION] = {
2581 .name = "classification",
2582 .help = "matches classification of higig2 header",
2583 .next = NEXT(item_higig2, NEXT_ENTRY(UNSIGNED), item_param),
2584 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_higig2_hdr,
2585 hdr.ppt1.classification)),
2587 [ITEM_HIGIG2_VID] = {
2589 .help = "matches vid of higig2 header",
2590 .next = NEXT(item_higig2, NEXT_ENTRY(UNSIGNED), item_param),
2591 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_higig2_hdr,
2596 .help = "match tag value",
2597 .priv = PRIV_ITEM(TAG, sizeof(struct rte_flow_item_tag)),
2598 .next = NEXT(item_tag),
2603 .help = "tag value to match",
2604 .next = NEXT(item_tag, NEXT_ENTRY(UNSIGNED), item_param),
2605 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_tag, data)),
2607 [ITEM_TAG_INDEX] = {
2609 .help = "index of tag array to match",
2610 .next = NEXT(item_tag, NEXT_ENTRY(UNSIGNED),
2611 NEXT_ENTRY(ITEM_PARAM_IS)),
2612 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_tag, index)),
2614 /* Validate/create actions. */
2617 .help = "submit a list of associated actions",
2618 .next = NEXT(next_action),
2623 .help = "specify next action",
2624 .next = NEXT(next_action),
2628 .help = "end list of actions",
2629 .priv = PRIV_ACTION(END, 0),
2634 .help = "no-op action",
2635 .priv = PRIV_ACTION(VOID, 0),
2636 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2639 [ACTION_PASSTHRU] = {
2641 .help = "let subsequent rule process matched packets",
2642 .priv = PRIV_ACTION(PASSTHRU, 0),
2643 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2648 .help = "redirect traffic to a given group",
2649 .priv = PRIV_ACTION(JUMP, sizeof(struct rte_flow_action_jump)),
2650 .next = NEXT(action_jump),
2653 [ACTION_JUMP_GROUP] = {
2655 .help = "group to redirect traffic to",
2656 .next = NEXT(action_jump, NEXT_ENTRY(UNSIGNED)),
2657 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_jump, group)),
2658 .call = parse_vc_conf,
2662 .help = "attach 32 bit value to packets",
2663 .priv = PRIV_ACTION(MARK, sizeof(struct rte_flow_action_mark)),
2664 .next = NEXT(action_mark),
2667 [ACTION_MARK_ID] = {
2669 .help = "32 bit value to return with packets",
2670 .next = NEXT(action_mark, NEXT_ENTRY(UNSIGNED)),
2671 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_mark, id)),
2672 .call = parse_vc_conf,
2676 .help = "flag packets",
2677 .priv = PRIV_ACTION(FLAG, 0),
2678 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2683 .help = "assign packets to a given queue index",
2684 .priv = PRIV_ACTION(QUEUE,
2685 sizeof(struct rte_flow_action_queue)),
2686 .next = NEXT(action_queue),
2689 [ACTION_QUEUE_INDEX] = {
2691 .help = "queue index to use",
2692 .next = NEXT(action_queue, NEXT_ENTRY(UNSIGNED)),
2693 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_queue, index)),
2694 .call = parse_vc_conf,
2698 .help = "drop packets (note: passthru has priority)",
2699 .priv = PRIV_ACTION(DROP, 0),
2700 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2705 .help = "enable counters for this rule",
2706 .priv = PRIV_ACTION(COUNT,
2707 sizeof(struct rte_flow_action_count)),
2708 .next = NEXT(action_count),
2711 [ACTION_COUNT_ID] = {
2712 .name = "identifier",
2713 .help = "counter identifier to use",
2714 .next = NEXT(action_count, NEXT_ENTRY(UNSIGNED)),
2715 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_count, id)),
2716 .call = parse_vc_conf,
2718 [ACTION_COUNT_SHARED] = {
2720 .help = "shared counter",
2721 .next = NEXT(action_count, NEXT_ENTRY(BOOLEAN)),
2722 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_count,
2724 .call = parse_vc_conf,
2728 .help = "spread packets among several queues",
2729 .priv = PRIV_ACTION(RSS, sizeof(struct action_rss_data)),
2730 .next = NEXT(action_rss),
2731 .call = parse_vc_action_rss,
2733 [ACTION_RSS_FUNC] = {
2735 .help = "RSS hash function to apply",
2736 .next = NEXT(action_rss,
2737 NEXT_ENTRY(ACTION_RSS_FUNC_DEFAULT,
2738 ACTION_RSS_FUNC_TOEPLITZ,
2739 ACTION_RSS_FUNC_SIMPLE_XOR,
2740 ACTION_RSS_FUNC_SYMMETRIC_TOEPLITZ)),
2742 [ACTION_RSS_FUNC_DEFAULT] = {
2744 .help = "default hash function",
2745 .call = parse_vc_action_rss_func,
2747 [ACTION_RSS_FUNC_TOEPLITZ] = {
2749 .help = "Toeplitz hash function",
2750 .call = parse_vc_action_rss_func,
2752 [ACTION_RSS_FUNC_SIMPLE_XOR] = {
2753 .name = "simple_xor",
2754 .help = "simple XOR hash function",
2755 .call = parse_vc_action_rss_func,
2757 [ACTION_RSS_FUNC_SYMMETRIC_TOEPLITZ] = {
2758 .name = "symmetric_toeplitz",
2759 .help = "Symmetric Toeplitz hash function",
2760 .call = parse_vc_action_rss_func,
2762 [ACTION_RSS_LEVEL] = {
2764 .help = "encapsulation level for \"types\"",
2765 .next = NEXT(action_rss, NEXT_ENTRY(UNSIGNED)),
2766 .args = ARGS(ARGS_ENTRY_ARB
2767 (offsetof(struct action_rss_data, conf) +
2768 offsetof(struct rte_flow_action_rss, level),
2769 sizeof(((struct rte_flow_action_rss *)0)->
2772 [ACTION_RSS_TYPES] = {
2774 .help = "specific RSS hash types",
2775 .next = NEXT(action_rss, NEXT_ENTRY(ACTION_RSS_TYPE)),
2777 [ACTION_RSS_TYPE] = {
2779 .help = "RSS hash type",
2780 .call = parse_vc_action_rss_type,
2781 .comp = comp_vc_action_rss_type,
2783 [ACTION_RSS_KEY] = {
2785 .help = "RSS hash key",
2786 .next = NEXT(action_rss, NEXT_ENTRY(HEX)),
2787 .args = ARGS(ARGS_ENTRY_ARB(0, 0),
2789 (offsetof(struct action_rss_data, conf) +
2790 offsetof(struct rte_flow_action_rss, key_len),
2791 sizeof(((struct rte_flow_action_rss *)0)->
2793 ARGS_ENTRY(struct action_rss_data, key)),
2795 [ACTION_RSS_KEY_LEN] = {
2797 .help = "RSS hash key length in bytes",
2798 .next = NEXT(action_rss, NEXT_ENTRY(UNSIGNED)),
2799 .args = ARGS(ARGS_ENTRY_ARB_BOUNDED
2800 (offsetof(struct action_rss_data, conf) +
2801 offsetof(struct rte_flow_action_rss, key_len),
2802 sizeof(((struct rte_flow_action_rss *)0)->
2805 RSS_HASH_KEY_LENGTH)),
2807 [ACTION_RSS_QUEUES] = {
2809 .help = "queue indices to use",
2810 .next = NEXT(action_rss, NEXT_ENTRY(ACTION_RSS_QUEUE)),
2811 .call = parse_vc_conf,
2813 [ACTION_RSS_QUEUE] = {
2815 .help = "queue index",
2816 .call = parse_vc_action_rss_queue,
2817 .comp = comp_vc_action_rss_queue,
2821 .help = "direct traffic to physical function",
2822 .priv = PRIV_ACTION(PF, 0),
2823 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2828 .help = "direct traffic to a virtual function ID",
2829 .priv = PRIV_ACTION(VF, sizeof(struct rte_flow_action_vf)),
2830 .next = NEXT(action_vf),
2833 [ACTION_VF_ORIGINAL] = {
2835 .help = "use original VF ID if possible",
2836 .next = NEXT(action_vf, NEXT_ENTRY(BOOLEAN)),
2837 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_vf,
2839 .call = parse_vc_conf,
2844 .next = NEXT(action_vf, NEXT_ENTRY(UNSIGNED)),
2845 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_vf, id)),
2846 .call = parse_vc_conf,
2848 [ACTION_PHY_PORT] = {
2850 .help = "direct packets to physical port index",
2851 .priv = PRIV_ACTION(PHY_PORT,
2852 sizeof(struct rte_flow_action_phy_port)),
2853 .next = NEXT(action_phy_port),
2856 [ACTION_PHY_PORT_ORIGINAL] = {
2858 .help = "use original port index if possible",
2859 .next = NEXT(action_phy_port, NEXT_ENTRY(BOOLEAN)),
2860 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_phy_port,
2862 .call = parse_vc_conf,
2864 [ACTION_PHY_PORT_INDEX] = {
2866 .help = "physical port index",
2867 .next = NEXT(action_phy_port, NEXT_ENTRY(UNSIGNED)),
2868 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_phy_port,
2870 .call = parse_vc_conf,
2872 [ACTION_PORT_ID] = {
2874 .help = "direct matching traffic to a given DPDK port ID",
2875 .priv = PRIV_ACTION(PORT_ID,
2876 sizeof(struct rte_flow_action_port_id)),
2877 .next = NEXT(action_port_id),
2880 [ACTION_PORT_ID_ORIGINAL] = {
2882 .help = "use original DPDK port ID if possible",
2883 .next = NEXT(action_port_id, NEXT_ENTRY(BOOLEAN)),
2884 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_port_id,
2886 .call = parse_vc_conf,
2888 [ACTION_PORT_ID_ID] = {
2890 .help = "DPDK port ID",
2891 .next = NEXT(action_port_id, NEXT_ENTRY(UNSIGNED)),
2892 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_port_id, id)),
2893 .call = parse_vc_conf,
2897 .help = "meter the directed packets at given id",
2898 .priv = PRIV_ACTION(METER,
2899 sizeof(struct rte_flow_action_meter)),
2900 .next = NEXT(action_meter),
2903 [ACTION_METER_ID] = {
2905 .help = "meter id to use",
2906 .next = NEXT(action_meter, NEXT_ENTRY(UNSIGNED)),
2907 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_meter, mtr_id)),
2908 .call = parse_vc_conf,
2910 [ACTION_OF_SET_MPLS_TTL] = {
2911 .name = "of_set_mpls_ttl",
2912 .help = "OpenFlow's OFPAT_SET_MPLS_TTL",
2915 sizeof(struct rte_flow_action_of_set_mpls_ttl)),
2916 .next = NEXT(action_of_set_mpls_ttl),
2919 [ACTION_OF_SET_MPLS_TTL_MPLS_TTL] = {
2922 .next = NEXT(action_of_set_mpls_ttl, NEXT_ENTRY(UNSIGNED)),
2923 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_of_set_mpls_ttl,
2925 .call = parse_vc_conf,
2927 [ACTION_OF_DEC_MPLS_TTL] = {
2928 .name = "of_dec_mpls_ttl",
2929 .help = "OpenFlow's OFPAT_DEC_MPLS_TTL",
2930 .priv = PRIV_ACTION(OF_DEC_MPLS_TTL, 0),
2931 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2934 [ACTION_OF_SET_NW_TTL] = {
2935 .name = "of_set_nw_ttl",
2936 .help = "OpenFlow's OFPAT_SET_NW_TTL",
2939 sizeof(struct rte_flow_action_of_set_nw_ttl)),
2940 .next = NEXT(action_of_set_nw_ttl),
2943 [ACTION_OF_SET_NW_TTL_NW_TTL] = {
2946 .next = NEXT(action_of_set_nw_ttl, NEXT_ENTRY(UNSIGNED)),
2947 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_of_set_nw_ttl,
2949 .call = parse_vc_conf,
2951 [ACTION_OF_DEC_NW_TTL] = {
2952 .name = "of_dec_nw_ttl",
2953 .help = "OpenFlow's OFPAT_DEC_NW_TTL",
2954 .priv = PRIV_ACTION(OF_DEC_NW_TTL, 0),
2955 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2958 [ACTION_OF_COPY_TTL_OUT] = {
2959 .name = "of_copy_ttl_out",
2960 .help = "OpenFlow's OFPAT_COPY_TTL_OUT",
2961 .priv = PRIV_ACTION(OF_COPY_TTL_OUT, 0),
2962 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2965 [ACTION_OF_COPY_TTL_IN] = {
2966 .name = "of_copy_ttl_in",
2967 .help = "OpenFlow's OFPAT_COPY_TTL_IN",
2968 .priv = PRIV_ACTION(OF_COPY_TTL_IN, 0),
2969 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2972 [ACTION_OF_POP_VLAN] = {
2973 .name = "of_pop_vlan",
2974 .help = "OpenFlow's OFPAT_POP_VLAN",
2975 .priv = PRIV_ACTION(OF_POP_VLAN, 0),
2976 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2979 [ACTION_OF_PUSH_VLAN] = {
2980 .name = "of_push_vlan",
2981 .help = "OpenFlow's OFPAT_PUSH_VLAN",
2984 sizeof(struct rte_flow_action_of_push_vlan)),
2985 .next = NEXT(action_of_push_vlan),
2988 [ACTION_OF_PUSH_VLAN_ETHERTYPE] = {
2989 .name = "ethertype",
2990 .help = "EtherType",
2991 .next = NEXT(action_of_push_vlan, NEXT_ENTRY(UNSIGNED)),
2992 .args = ARGS(ARGS_ENTRY_HTON
2993 (struct rte_flow_action_of_push_vlan,
2995 .call = parse_vc_conf,
2997 [ACTION_OF_SET_VLAN_VID] = {
2998 .name = "of_set_vlan_vid",
2999 .help = "OpenFlow's OFPAT_SET_VLAN_VID",
3002 sizeof(struct rte_flow_action_of_set_vlan_vid)),
3003 .next = NEXT(action_of_set_vlan_vid),
3006 [ACTION_OF_SET_VLAN_VID_VLAN_VID] = {
3009 .next = NEXT(action_of_set_vlan_vid, NEXT_ENTRY(UNSIGNED)),
3010 .args = ARGS(ARGS_ENTRY_HTON
3011 (struct rte_flow_action_of_set_vlan_vid,
3013 .call = parse_vc_conf,
3015 [ACTION_OF_SET_VLAN_PCP] = {
3016 .name = "of_set_vlan_pcp",
3017 .help = "OpenFlow's OFPAT_SET_VLAN_PCP",
3020 sizeof(struct rte_flow_action_of_set_vlan_pcp)),
3021 .next = NEXT(action_of_set_vlan_pcp),
3024 [ACTION_OF_SET_VLAN_PCP_VLAN_PCP] = {
3026 .help = "VLAN priority",
3027 .next = NEXT(action_of_set_vlan_pcp, NEXT_ENTRY(UNSIGNED)),
3028 .args = ARGS(ARGS_ENTRY_HTON
3029 (struct rte_flow_action_of_set_vlan_pcp,
3031 .call = parse_vc_conf,
3033 [ACTION_OF_POP_MPLS] = {
3034 .name = "of_pop_mpls",
3035 .help = "OpenFlow's OFPAT_POP_MPLS",
3036 .priv = PRIV_ACTION(OF_POP_MPLS,
3037 sizeof(struct rte_flow_action_of_pop_mpls)),
3038 .next = NEXT(action_of_pop_mpls),
3041 [ACTION_OF_POP_MPLS_ETHERTYPE] = {
3042 .name = "ethertype",
3043 .help = "EtherType",
3044 .next = NEXT(action_of_pop_mpls, NEXT_ENTRY(UNSIGNED)),
3045 .args = ARGS(ARGS_ENTRY_HTON
3046 (struct rte_flow_action_of_pop_mpls,
3048 .call = parse_vc_conf,
3050 [ACTION_OF_PUSH_MPLS] = {
3051 .name = "of_push_mpls",
3052 .help = "OpenFlow's OFPAT_PUSH_MPLS",
3055 sizeof(struct rte_flow_action_of_push_mpls)),
3056 .next = NEXT(action_of_push_mpls),
3059 [ACTION_OF_PUSH_MPLS_ETHERTYPE] = {
3060 .name = "ethertype",
3061 .help = "EtherType",
3062 .next = NEXT(action_of_push_mpls, NEXT_ENTRY(UNSIGNED)),
3063 .args = ARGS(ARGS_ENTRY_HTON
3064 (struct rte_flow_action_of_push_mpls,
3066 .call = parse_vc_conf,
3068 [ACTION_VXLAN_ENCAP] = {
3069 .name = "vxlan_encap",
3070 .help = "VXLAN encapsulation, uses configuration set by \"set"
3072 .priv = PRIV_ACTION(VXLAN_ENCAP,
3073 sizeof(struct action_vxlan_encap_data)),
3074 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3075 .call = parse_vc_action_vxlan_encap,
3077 [ACTION_VXLAN_DECAP] = {
3078 .name = "vxlan_decap",
3079 .help = "Performs a decapsulation action by stripping all"
3080 " headers of the VXLAN tunnel network overlay from the"
3082 .priv = PRIV_ACTION(VXLAN_DECAP, 0),
3083 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3086 [ACTION_NVGRE_ENCAP] = {
3087 .name = "nvgre_encap",
3088 .help = "NVGRE encapsulation, uses configuration set by \"set"
3090 .priv = PRIV_ACTION(NVGRE_ENCAP,
3091 sizeof(struct action_nvgre_encap_data)),
3092 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3093 .call = parse_vc_action_nvgre_encap,
3095 [ACTION_NVGRE_DECAP] = {
3096 .name = "nvgre_decap",
3097 .help = "Performs a decapsulation action by stripping all"
3098 " headers of the NVGRE tunnel network overlay from the"
3100 .priv = PRIV_ACTION(NVGRE_DECAP, 0),
3101 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3104 [ACTION_L2_ENCAP] = {
3106 .help = "l2 encap, uses configuration set by"
3107 " \"set l2_encap\"",
3108 .priv = PRIV_ACTION(RAW_ENCAP,
3109 sizeof(struct action_raw_encap_data)),
3110 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3111 .call = parse_vc_action_l2_encap,
3113 [ACTION_L2_DECAP] = {
3115 .help = "l2 decap, uses configuration set by"
3116 " \"set l2_decap\"",
3117 .priv = PRIV_ACTION(RAW_DECAP,
3118 sizeof(struct action_raw_decap_data)),
3119 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3120 .call = parse_vc_action_l2_decap,
3122 [ACTION_MPLSOGRE_ENCAP] = {
3123 .name = "mplsogre_encap",
3124 .help = "mplsogre encapsulation, uses configuration set by"
3125 " \"set mplsogre_encap\"",
3126 .priv = PRIV_ACTION(RAW_ENCAP,
3127 sizeof(struct action_raw_encap_data)),
3128 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3129 .call = parse_vc_action_mplsogre_encap,
3131 [ACTION_MPLSOGRE_DECAP] = {
3132 .name = "mplsogre_decap",
3133 .help = "mplsogre decapsulation, uses configuration set by"
3134 " \"set mplsogre_decap\"",
3135 .priv = PRIV_ACTION(RAW_DECAP,
3136 sizeof(struct action_raw_decap_data)),
3137 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3138 .call = parse_vc_action_mplsogre_decap,
3140 [ACTION_MPLSOUDP_ENCAP] = {
3141 .name = "mplsoudp_encap",
3142 .help = "mplsoudp encapsulation, uses configuration set by"
3143 " \"set mplsoudp_encap\"",
3144 .priv = PRIV_ACTION(RAW_ENCAP,
3145 sizeof(struct action_raw_encap_data)),
3146 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3147 .call = parse_vc_action_mplsoudp_encap,
3149 [ACTION_MPLSOUDP_DECAP] = {
3150 .name = "mplsoudp_decap",
3151 .help = "mplsoudp decapsulation, uses configuration set by"
3152 " \"set mplsoudp_decap\"",
3153 .priv = PRIV_ACTION(RAW_DECAP,
3154 sizeof(struct action_raw_decap_data)),
3155 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3156 .call = parse_vc_action_mplsoudp_decap,
3158 [ACTION_SET_IPV4_SRC] = {
3159 .name = "set_ipv4_src",
3160 .help = "Set a new IPv4 source address in the outermost"
3162 .priv = PRIV_ACTION(SET_IPV4_SRC,
3163 sizeof(struct rte_flow_action_set_ipv4)),
3164 .next = NEXT(action_set_ipv4_src),
3167 [ACTION_SET_IPV4_SRC_IPV4_SRC] = {
3168 .name = "ipv4_addr",
3169 .help = "new IPv4 source address to set",
3170 .next = NEXT(action_set_ipv4_src, NEXT_ENTRY(IPV4_ADDR)),
3171 .args = ARGS(ARGS_ENTRY_HTON
3172 (struct rte_flow_action_set_ipv4, ipv4_addr)),
3173 .call = parse_vc_conf,
3175 [ACTION_SET_IPV4_DST] = {
3176 .name = "set_ipv4_dst",
3177 .help = "Set a new IPv4 destination address in the outermost"
3179 .priv = PRIV_ACTION(SET_IPV4_DST,
3180 sizeof(struct rte_flow_action_set_ipv4)),
3181 .next = NEXT(action_set_ipv4_dst),
3184 [ACTION_SET_IPV4_DST_IPV4_DST] = {
3185 .name = "ipv4_addr",
3186 .help = "new IPv4 destination address to set",
3187 .next = NEXT(action_set_ipv4_dst, NEXT_ENTRY(IPV4_ADDR)),
3188 .args = ARGS(ARGS_ENTRY_HTON
3189 (struct rte_flow_action_set_ipv4, ipv4_addr)),
3190 .call = parse_vc_conf,
3192 [ACTION_SET_IPV6_SRC] = {
3193 .name = "set_ipv6_src",
3194 .help = "Set a new IPv6 source address in the outermost"
3196 .priv = PRIV_ACTION(SET_IPV6_SRC,
3197 sizeof(struct rte_flow_action_set_ipv6)),
3198 .next = NEXT(action_set_ipv6_src),
3201 [ACTION_SET_IPV6_SRC_IPV6_SRC] = {
3202 .name = "ipv6_addr",
3203 .help = "new IPv6 source address to set",
3204 .next = NEXT(action_set_ipv6_src, NEXT_ENTRY(IPV6_ADDR)),
3205 .args = ARGS(ARGS_ENTRY_HTON
3206 (struct rte_flow_action_set_ipv6, ipv6_addr)),
3207 .call = parse_vc_conf,
3209 [ACTION_SET_IPV6_DST] = {
3210 .name = "set_ipv6_dst",
3211 .help = "Set a new IPv6 destination address in the outermost"
3213 .priv = PRIV_ACTION(SET_IPV6_DST,
3214 sizeof(struct rte_flow_action_set_ipv6)),
3215 .next = NEXT(action_set_ipv6_dst),
3218 [ACTION_SET_IPV6_DST_IPV6_DST] = {
3219 .name = "ipv6_addr",
3220 .help = "new IPv6 destination address to set",
3221 .next = NEXT(action_set_ipv6_dst, NEXT_ENTRY(IPV6_ADDR)),
3222 .args = ARGS(ARGS_ENTRY_HTON
3223 (struct rte_flow_action_set_ipv6, ipv6_addr)),
3224 .call = parse_vc_conf,
3226 [ACTION_SET_TP_SRC] = {
3227 .name = "set_tp_src",
3228 .help = "set a new source port number in the outermost"
3230 .priv = PRIV_ACTION(SET_TP_SRC,
3231 sizeof(struct rte_flow_action_set_tp)),
3232 .next = NEXT(action_set_tp_src),
3235 [ACTION_SET_TP_SRC_TP_SRC] = {
3237 .help = "new source port number to set",
3238 .next = NEXT(action_set_tp_src, NEXT_ENTRY(UNSIGNED)),
3239 .args = ARGS(ARGS_ENTRY_HTON
3240 (struct rte_flow_action_set_tp, port)),
3241 .call = parse_vc_conf,
3243 [ACTION_SET_TP_DST] = {
3244 .name = "set_tp_dst",
3245 .help = "set a new destination port number in the outermost"
3247 .priv = PRIV_ACTION(SET_TP_DST,
3248 sizeof(struct rte_flow_action_set_tp)),
3249 .next = NEXT(action_set_tp_dst),
3252 [ACTION_SET_TP_DST_TP_DST] = {
3254 .help = "new destination port number to set",
3255 .next = NEXT(action_set_tp_dst, NEXT_ENTRY(UNSIGNED)),
3256 .args = ARGS(ARGS_ENTRY_HTON
3257 (struct rte_flow_action_set_tp, port)),
3258 .call = parse_vc_conf,
3260 [ACTION_MAC_SWAP] = {
3262 .help = "Swap the source and destination MAC addresses"
3263 " in the outermost Ethernet header",
3264 .priv = PRIV_ACTION(MAC_SWAP, 0),
3265 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3268 [ACTION_DEC_TTL] = {
3270 .help = "decrease network TTL if available",
3271 .priv = PRIV_ACTION(DEC_TTL, 0),
3272 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3275 [ACTION_SET_TTL] = {
3277 .help = "set ttl value",
3278 .priv = PRIV_ACTION(SET_TTL,
3279 sizeof(struct rte_flow_action_set_ttl)),
3280 .next = NEXT(action_set_ttl),
3283 [ACTION_SET_TTL_TTL] = {
3284 .name = "ttl_value",
3285 .help = "new ttl value to set",
3286 .next = NEXT(action_set_ttl, NEXT_ENTRY(UNSIGNED)),
3287 .args = ARGS(ARGS_ENTRY_HTON
3288 (struct rte_flow_action_set_ttl, ttl_value)),
3289 .call = parse_vc_conf,
3291 [ACTION_SET_MAC_SRC] = {
3292 .name = "set_mac_src",
3293 .help = "set source mac address",
3294 .priv = PRIV_ACTION(SET_MAC_SRC,
3295 sizeof(struct rte_flow_action_set_mac)),
3296 .next = NEXT(action_set_mac_src),
3299 [ACTION_SET_MAC_SRC_MAC_SRC] = {
3301 .help = "new source mac address",
3302 .next = NEXT(action_set_mac_src, NEXT_ENTRY(MAC_ADDR)),
3303 .args = ARGS(ARGS_ENTRY_HTON
3304 (struct rte_flow_action_set_mac, mac_addr)),
3305 .call = parse_vc_conf,
3307 [ACTION_SET_MAC_DST] = {
3308 .name = "set_mac_dst",
3309 .help = "set destination mac address",
3310 .priv = PRIV_ACTION(SET_MAC_DST,
3311 sizeof(struct rte_flow_action_set_mac)),
3312 .next = NEXT(action_set_mac_dst),
3315 [ACTION_SET_MAC_DST_MAC_DST] = {
3317 .help = "new destination mac address to set",
3318 .next = NEXT(action_set_mac_dst, NEXT_ENTRY(MAC_ADDR)),
3319 .args = ARGS(ARGS_ENTRY_HTON
3320 (struct rte_flow_action_set_mac, mac_addr)),
3321 .call = parse_vc_conf,
3323 [ACTION_INC_TCP_SEQ] = {
3324 .name = "inc_tcp_seq",
3325 .help = "increase TCP sequence number",
3326 .priv = PRIV_ACTION(INC_TCP_SEQ, sizeof(rte_be32_t)),
3327 .next = NEXT(action_inc_tcp_seq),
3330 [ACTION_INC_TCP_SEQ_VALUE] = {
3332 .help = "the value to increase TCP sequence number by",
3333 .next = NEXT(action_inc_tcp_seq, NEXT_ENTRY(UNSIGNED)),
3334 .args = ARGS(ARG_ENTRY_HTON(rte_be32_t)),
3335 .call = parse_vc_conf,
3337 [ACTION_DEC_TCP_SEQ] = {
3338 .name = "dec_tcp_seq",
3339 .help = "decrease TCP sequence number",
3340 .priv = PRIV_ACTION(DEC_TCP_SEQ, sizeof(rte_be32_t)),
3341 .next = NEXT(action_dec_tcp_seq),
3344 [ACTION_DEC_TCP_SEQ_VALUE] = {
3346 .help = "the value to decrease TCP sequence number by",
3347 .next = NEXT(action_dec_tcp_seq, NEXT_ENTRY(UNSIGNED)),
3348 .args = ARGS(ARG_ENTRY_HTON(rte_be32_t)),
3349 .call = parse_vc_conf,
3351 [ACTION_INC_TCP_ACK] = {
3352 .name = "inc_tcp_ack",
3353 .help = "increase TCP acknowledgment number",
3354 .priv = PRIV_ACTION(INC_TCP_ACK, sizeof(rte_be32_t)),
3355 .next = NEXT(action_inc_tcp_ack),
3358 [ACTION_INC_TCP_ACK_VALUE] = {
3360 .help = "the value to increase TCP acknowledgment number by",
3361 .next = NEXT(action_inc_tcp_ack, NEXT_ENTRY(UNSIGNED)),
3362 .args = ARGS(ARG_ENTRY_HTON(rte_be32_t)),
3363 .call = parse_vc_conf,
3365 [ACTION_DEC_TCP_ACK] = {
3366 .name = "dec_tcp_ack",
3367 .help = "decrease TCP acknowledgment number",
3368 .priv = PRIV_ACTION(DEC_TCP_ACK, sizeof(rte_be32_t)),
3369 .next = NEXT(action_dec_tcp_ack),
3372 [ACTION_DEC_TCP_ACK_VALUE] = {
3374 .help = "the value to decrease TCP acknowledgment number by",
3375 .next = NEXT(action_dec_tcp_ack, NEXT_ENTRY(UNSIGNED)),
3376 .args = ARGS(ARG_ENTRY_HTON(rte_be32_t)),
3377 .call = parse_vc_conf,
3379 [ACTION_RAW_ENCAP] = {
3380 .name = "raw_encap",
3381 .help = "encapsulation data, defined by set raw_encap",
3382 .priv = PRIV_ACTION(RAW_ENCAP,
3383 sizeof(struct action_raw_encap_data)),
3384 .next = NEXT(action_raw_encap),
3385 .call = parse_vc_action_raw_encap,
3387 [ACTION_RAW_ENCAP_INDEX] = {
3389 .help = "the index of raw_encap_confs",
3390 .next = NEXT(NEXT_ENTRY(ACTION_RAW_ENCAP_INDEX_VALUE)),
3392 [ACTION_RAW_ENCAP_INDEX_VALUE] = {
3395 .help = "unsigned integer value",
3396 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3397 .call = parse_vc_action_raw_encap_index,
3398 .comp = comp_set_raw_index,
3400 [ACTION_RAW_DECAP] = {
3401 .name = "raw_decap",
3402 .help = "decapsulation data, defined by set raw_encap",
3403 .priv = PRIV_ACTION(RAW_DECAP,
3404 sizeof(struct action_raw_decap_data)),
3405 .next = NEXT(action_raw_decap),
3406 .call = parse_vc_action_raw_decap,
3408 [ACTION_RAW_DECAP_INDEX] = {
3410 .help = "the index of raw_encap_confs",
3411 .next = NEXT(NEXT_ENTRY(ACTION_RAW_DECAP_INDEX_VALUE)),
3413 [ACTION_RAW_DECAP_INDEX_VALUE] = {
3416 .help = "unsigned integer value",
3417 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3418 .call = parse_vc_action_raw_decap_index,
3419 .comp = comp_set_raw_index,
3421 /* Top level command. */
3424 .help = "set raw encap/decap data",
3425 .type = "set raw_encap|raw_decap <index> <pattern>",
3426 .next = NEXT(NEXT_ENTRY
3429 .call = parse_set_init,
3431 /* Sub-level commands. */
3433 .name = "raw_encap",
3434 .help = "set raw encap data",
3435 .next = NEXT(next_set_raw),
3436 .args = ARGS(ARGS_ENTRY_ARB_BOUNDED
3437 (offsetof(struct buffer, port),
3438 sizeof(((struct buffer *)0)->port),
3439 0, RAW_ENCAP_CONFS_MAX_NUM - 1)),
3440 .call = parse_set_raw_encap_decap,
3443 .name = "raw_decap",
3444 .help = "set raw decap data",
3445 .next = NEXT(next_set_raw),
3446 .args = ARGS(ARGS_ENTRY_ARB_BOUNDED
3447 (offsetof(struct buffer, port),
3448 sizeof(((struct buffer *)0)->port),
3449 0, RAW_ENCAP_CONFS_MAX_NUM - 1)),
3450 .call = parse_set_raw_encap_decap,
3455 .help = "index of raw_encap/raw_decap data",
3456 .next = NEXT(next_item),
3459 [ACTION_SET_TAG] = {
3462 .priv = PRIV_ACTION(SET_TAG,
3463 sizeof(struct rte_flow_action_set_tag)),
3464 .next = NEXT(action_set_tag),
3467 [ACTION_SET_TAG_INDEX] = {
3469 .help = "index of tag array",
3470 .next = NEXT(action_set_tag, NEXT_ENTRY(UNSIGNED)),
3471 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_set_tag, index)),
3472 .call = parse_vc_conf,
3474 [ACTION_SET_TAG_DATA] = {
3476 .help = "tag value",
3477 .next = NEXT(action_set_tag, NEXT_ENTRY(UNSIGNED)),
3478 .args = ARGS(ARGS_ENTRY
3479 (struct rte_flow_action_set_tag, data)),
3480 .call = parse_vc_conf,
3482 [ACTION_SET_TAG_MASK] = {
3484 .help = "mask for tag value",
3485 .next = NEXT(action_set_tag, NEXT_ENTRY(UNSIGNED)),
3486 .args = ARGS(ARGS_ENTRY
3487 (struct rte_flow_action_set_tag, mask)),
3488 .call = parse_vc_conf,
3490 [ACTION_SET_META] = {
3492 .help = "set metadata",
3493 .priv = PRIV_ACTION(SET_META,
3494 sizeof(struct rte_flow_action_set_meta)),
3495 .next = NEXT(action_set_meta),
3496 .call = parse_vc_action_set_meta,
3498 [ACTION_SET_META_DATA] = {
3500 .help = "metadata value",
3501 .next = NEXT(action_set_meta, NEXT_ENTRY(UNSIGNED)),
3502 .args = ARGS(ARGS_ENTRY
3503 (struct rte_flow_action_set_meta, data)),
3504 .call = parse_vc_conf,
3506 [ACTION_SET_META_MASK] = {
3508 .help = "mask for metadata value",
3509 .next = NEXT(action_set_meta, NEXT_ENTRY(UNSIGNED)),
3510 .args = ARGS(ARGS_ENTRY
3511 (struct rte_flow_action_set_meta, mask)),
3512 .call = parse_vc_conf,
3514 [ACTION_SET_IPV4_DSCP] = {
3515 .name = "set_ipv4_dscp",
3516 .help = "set DSCP value",
3517 .priv = PRIV_ACTION(SET_IPV4_DSCP,
3518 sizeof(struct rte_flow_action_set_dscp)),
3519 .next = NEXT(action_set_ipv4_dscp),
3522 [ACTION_SET_IPV4_DSCP_VALUE] = {
3523 .name = "dscp_value",
3524 .help = "new IPv4 DSCP value to set",
3525 .next = NEXT(action_set_ipv4_dscp, NEXT_ENTRY(UNSIGNED)),
3526 .args = ARGS(ARGS_ENTRY
3527 (struct rte_flow_action_set_dscp, dscp)),
3528 .call = parse_vc_conf,
3530 [ACTION_SET_IPV6_DSCP] = {
3531 .name = "set_ipv6_dscp",
3532 .help = "set DSCP value",
3533 .priv = PRIV_ACTION(SET_IPV6_DSCP,
3534 sizeof(struct rte_flow_action_set_dscp)),
3535 .next = NEXT(action_set_ipv6_dscp),
3538 [ACTION_SET_IPV6_DSCP_VALUE] = {
3539 .name = "dscp_value",
3540 .help = "new IPv6 DSCP value to set",
3541 .next = NEXT(action_set_ipv6_dscp, NEXT_ENTRY(UNSIGNED)),
3542 .args = ARGS(ARGS_ENTRY
3543 (struct rte_flow_action_set_dscp, dscp)),
3544 .call = parse_vc_conf,
3548 /** Remove and return last entry from argument stack. */
3549 static const struct arg *
3550 pop_args(struct context *ctx)
3552 return ctx->args_num ? ctx->args[--ctx->args_num] : NULL;
3555 /** Add entry on top of the argument stack. */
3557 push_args(struct context *ctx, const struct arg *arg)
3559 if (ctx->args_num == CTX_STACK_SIZE)
3561 ctx->args[ctx->args_num++] = arg;
3565 /** Spread value into buffer according to bit-mask. */
3567 arg_entry_bf_fill(void *dst, uintmax_t val, const struct arg *arg)
3569 uint32_t i = arg->size;
3577 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
3586 unsigned int shift = 0;
3587 uint8_t *buf = (uint8_t *)dst + arg->offset + (i -= sub);
3589 for (shift = 0; arg->mask[i] >> shift; ++shift) {
3590 if (!(arg->mask[i] & (1 << shift)))
3595 *buf &= ~(1 << shift);
3596 *buf |= (val & 1) << shift;
3604 /** Compare a string with a partial one of a given length. */
3606 strcmp_partial(const char *full, const char *partial, size_t partial_len)
3608 int r = strncmp(full, partial, partial_len);
3612 if (strlen(full) <= partial_len)
3614 return full[partial_len];
3618 * Parse a prefix length and generate a bit-mask.
3620 * Last argument (ctx->args) is retrieved to determine mask size, storage
3621 * location and whether the result must use network byte ordering.
3624 parse_prefix(struct context *ctx, const struct token *token,
3625 const char *str, unsigned int len,
3626 void *buf, unsigned int size)
3628 const struct arg *arg = pop_args(ctx);
3629 static const uint8_t conv[] = "\x00\x80\xc0\xe0\xf0\xf8\xfc\xfe\xff";
3636 /* Argument is expected. */
3640 u = strtoumax(str, &end, 0);
3641 if (errno || (size_t)(end - str) != len)
3646 extra = arg_entry_bf_fill(NULL, 0, arg);
3655 if (!arg_entry_bf_fill(ctx->object, v, arg) ||
3656 !arg_entry_bf_fill(ctx->objmask, -1, arg))
3663 if (bytes > size || bytes + !!extra > size)
3667 buf = (uint8_t *)ctx->object + arg->offset;
3668 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
3670 memset((uint8_t *)buf + size - bytes, 0xff, bytes);
3671 memset(buf, 0x00, size - bytes);
3673 ((uint8_t *)buf)[size - bytes - 1] = conv[extra];
3677 memset(buf, 0xff, bytes);
3678 memset((uint8_t *)buf + bytes, 0x00, size - bytes);
3680 ((uint8_t *)buf)[bytes] = conv[extra];
3683 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
3686 push_args(ctx, arg);
3690 /** Default parsing function for token name matching. */
3692 parse_default(struct context *ctx, const struct token *token,
3693 const char *str, unsigned int len,
3694 void *buf, unsigned int size)
3699 if (strcmp_partial(token->name, str, len))
3704 /** Parse flow command, initialize output buffer for subsequent tokens. */
3706 parse_init(struct context *ctx, const struct token *token,
3707 const char *str, unsigned int len,
3708 void *buf, unsigned int size)
3710 struct buffer *out = buf;
3712 /* Token name must match. */
3713 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
3715 /* Nothing else to do if there is no buffer. */
3718 /* Make sure buffer is large enough. */
3719 if (size < sizeof(*out))
3721 /* Initialize buffer. */
3722 memset(out, 0x00, sizeof(*out));
3723 memset((uint8_t *)out + sizeof(*out), 0x22, size - sizeof(*out));
3726 ctx->objmask = NULL;
3730 /** Parse tokens for validate/create commands. */
3732 parse_vc(struct context *ctx, const struct token *token,
3733 const char *str, unsigned int len,
3734 void *buf, unsigned int size)
3736 struct buffer *out = buf;
3740 /* Token name must match. */
3741 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
3743 /* Nothing else to do if there is no buffer. */
3746 if (!out->command) {
3747 if (ctx->curr != VALIDATE && ctx->curr != CREATE)
3749 if (sizeof(*out) > size)
3751 out->command = ctx->curr;
3754 ctx->objmask = NULL;
3755 out->args.vc.data = (uint8_t *)out + size;
3759 ctx->object = &out->args.vc.attr;
3760 ctx->objmask = NULL;
3761 switch (ctx->curr) {
3766 out->args.vc.attr.ingress = 1;
3769 out->args.vc.attr.egress = 1;
3772 out->args.vc.attr.transfer = 1;
3775 out->args.vc.pattern =
3776 (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
3778 ctx->object = out->args.vc.pattern;
3779 ctx->objmask = NULL;
3782 out->args.vc.actions =
3783 (void *)RTE_ALIGN_CEIL((uintptr_t)
3784 (out->args.vc.pattern +
3785 out->args.vc.pattern_n),
3787 ctx->object = out->args.vc.actions;
3788 ctx->objmask = NULL;
3795 if (!out->args.vc.actions) {
3796 const struct parse_item_priv *priv = token->priv;
3797 struct rte_flow_item *item =
3798 out->args.vc.pattern + out->args.vc.pattern_n;
3800 data_size = priv->size * 3; /* spec, last, mask */
3801 data = (void *)RTE_ALIGN_FLOOR((uintptr_t)
3802 (out->args.vc.data - data_size),
3804 if ((uint8_t *)item + sizeof(*item) > data)
3806 *item = (struct rte_flow_item){
3809 ++out->args.vc.pattern_n;
3811 ctx->objmask = NULL;
3813 const struct parse_action_priv *priv = token->priv;
3814 struct rte_flow_action *action =
3815 out->args.vc.actions + out->args.vc.actions_n;
3817 data_size = priv->size; /* configuration */
3818 data = (void *)RTE_ALIGN_FLOOR((uintptr_t)
3819 (out->args.vc.data - data_size),
3821 if ((uint8_t *)action + sizeof(*action) > data)
3823 *action = (struct rte_flow_action){
3825 .conf = data_size ? data : NULL,
3827 ++out->args.vc.actions_n;
3828 ctx->object = action;
3829 ctx->objmask = NULL;
3831 memset(data, 0, data_size);
3832 out->args.vc.data = data;
3833 ctx->objdata = data_size;
3837 /** Parse pattern item parameter type. */
3839 parse_vc_spec(struct context *ctx, const struct token *token,
3840 const char *str, unsigned int len,
3841 void *buf, unsigned int size)
3843 struct buffer *out = buf;
3844 struct rte_flow_item *item;
3850 /* Token name must match. */
3851 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
3853 /* Parse parameter types. */
3854 switch (ctx->curr) {
3855 static const enum index prefix[] = NEXT_ENTRY(PREFIX);
3861 case ITEM_PARAM_SPEC:
3864 case ITEM_PARAM_LAST:
3867 case ITEM_PARAM_PREFIX:
3868 /* Modify next token to expect a prefix. */
3869 if (ctx->next_num < 2)
3871 ctx->next[ctx->next_num - 2] = prefix;
3873 case ITEM_PARAM_MASK:
3879 /* Nothing else to do if there is no buffer. */
3882 if (!out->args.vc.pattern_n)
3884 item = &out->args.vc.pattern[out->args.vc.pattern_n - 1];
3885 data_size = ctx->objdata / 3; /* spec, last, mask */
3886 /* Point to selected object. */
3887 ctx->object = out->args.vc.data + (data_size * index);
3889 ctx->objmask = out->args.vc.data + (data_size * 2); /* mask */
3890 item->mask = ctx->objmask;
3892 ctx->objmask = NULL;
3893 /* Update relevant item pointer. */
3894 *((const void **[]){ &item->spec, &item->last, &item->mask })[index] =
3899 /** Parse action configuration field. */
3901 parse_vc_conf(struct context *ctx, const struct token *token,
3902 const char *str, unsigned int len,
3903 void *buf, unsigned int size)
3905 struct buffer *out = buf;
3908 /* Token name must match. */
3909 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
3911 /* Nothing else to do if there is no buffer. */
3914 /* Point to selected object. */
3915 ctx->object = out->args.vc.data;
3916 ctx->objmask = NULL;
3920 /** Parse RSS action. */
3922 parse_vc_action_rss(struct context *ctx, const struct token *token,
3923 const char *str, unsigned int len,
3924 void *buf, unsigned int size)
3926 struct buffer *out = buf;
3927 struct rte_flow_action *action;
3928 struct action_rss_data *action_rss_data;
3932 ret = parse_vc(ctx, token, str, len, buf, size);
3935 /* Nothing else to do if there is no buffer. */
3938 if (!out->args.vc.actions_n)
3940 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
3941 /* Point to selected object. */
3942 ctx->object = out->args.vc.data;
3943 ctx->objmask = NULL;
3944 /* Set up default configuration. */
3945 action_rss_data = ctx->object;
3946 *action_rss_data = (struct action_rss_data){
3947 .conf = (struct rte_flow_action_rss){
3948 .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
3951 .key_len = sizeof(action_rss_data->key),
3952 .queue_num = RTE_MIN(nb_rxq, ACTION_RSS_QUEUE_NUM),
3953 .key = action_rss_data->key,
3954 .queue = action_rss_data->queue,
3956 .key = "testpmd's default RSS hash key, "
3957 "override it for better balancing",
3960 for (i = 0; i < action_rss_data->conf.queue_num; ++i)
3961 action_rss_data->queue[i] = i;
3962 if (!port_id_is_invalid(ctx->port, DISABLED_WARN) &&
3963 ctx->port != (portid_t)RTE_PORT_ALL) {
3964 struct rte_eth_dev_info info;
3967 ret2 = rte_eth_dev_info_get(ctx->port, &info);
3971 action_rss_data->conf.key_len =
3972 RTE_MIN(sizeof(action_rss_data->key),
3973 info.hash_key_size);
3975 action->conf = &action_rss_data->conf;
3980 * Parse func field for RSS action.
3982 * The RTE_ETH_HASH_FUNCTION_* value to assign is derived from the
3983 * ACTION_RSS_FUNC_* index that called this function.
3986 parse_vc_action_rss_func(struct context *ctx, const struct token *token,
3987 const char *str, unsigned int len,
3988 void *buf, unsigned int size)
3990 struct action_rss_data *action_rss_data;
3991 enum rte_eth_hash_function func;
3995 /* Token name must match. */
3996 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
3998 switch (ctx->curr) {
3999 case ACTION_RSS_FUNC_DEFAULT:
4000 func = RTE_ETH_HASH_FUNCTION_DEFAULT;
4002 case ACTION_RSS_FUNC_TOEPLITZ:
4003 func = RTE_ETH_HASH_FUNCTION_TOEPLITZ;
4005 case ACTION_RSS_FUNC_SIMPLE_XOR:
4006 func = RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
4008 case ACTION_RSS_FUNC_SYMMETRIC_TOEPLITZ:
4009 func = RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ;
4016 action_rss_data = ctx->object;
4017 action_rss_data->conf.func = func;
4022 * Parse type field for RSS action.
4024 * Valid tokens are type field names and the "end" token.
4027 parse_vc_action_rss_type(struct context *ctx, const struct token *token,
4028 const char *str, unsigned int len,
4029 void *buf, unsigned int size)
4031 static const enum index next[] = NEXT_ENTRY(ACTION_RSS_TYPE);
4032 struct action_rss_data *action_rss_data;
4038 if (ctx->curr != ACTION_RSS_TYPE)
4040 if (!(ctx->objdata >> 16) && ctx->object) {
4041 action_rss_data = ctx->object;
4042 action_rss_data->conf.types = 0;
4044 if (!strcmp_partial("end", str, len)) {
4045 ctx->objdata &= 0xffff;
4048 for (i = 0; rss_type_table[i].str; ++i)
4049 if (!strcmp_partial(rss_type_table[i].str, str, len))
4051 if (!rss_type_table[i].str)
4053 ctx->objdata = 1 << 16 | (ctx->objdata & 0xffff);
4055 if (ctx->next_num == RTE_DIM(ctx->next))
4057 ctx->next[ctx->next_num++] = next;
4060 action_rss_data = ctx->object;
4061 action_rss_data->conf.types |= rss_type_table[i].rss_type;
4066 * Parse queue field for RSS action.
4068 * Valid tokens are queue indices and the "end" token.
4071 parse_vc_action_rss_queue(struct context *ctx, const struct token *token,
4072 const char *str, unsigned int len,
4073 void *buf, unsigned int size)
4075 static const enum index next[] = NEXT_ENTRY(ACTION_RSS_QUEUE);
4076 struct action_rss_data *action_rss_data;
4077 const struct arg *arg;
4084 if (ctx->curr != ACTION_RSS_QUEUE)
4086 i = ctx->objdata >> 16;
4087 if (!strcmp_partial("end", str, len)) {
4088 ctx->objdata &= 0xffff;
4091 if (i >= ACTION_RSS_QUEUE_NUM)
4093 arg = ARGS_ENTRY_ARB(offsetof(struct action_rss_data, queue) +
4094 i * sizeof(action_rss_data->queue[i]),
4095 sizeof(action_rss_data->queue[i]));
4096 if (push_args(ctx, arg))
4098 ret = parse_int(ctx, token, str, len, NULL, 0);
4104 ctx->objdata = i << 16 | (ctx->objdata & 0xffff);
4106 if (ctx->next_num == RTE_DIM(ctx->next))
4108 ctx->next[ctx->next_num++] = next;
4112 action_rss_data = ctx->object;
4113 action_rss_data->conf.queue_num = i;
4114 action_rss_data->conf.queue = i ? action_rss_data->queue : NULL;
4118 /** Parse VXLAN encap action. */
4120 parse_vc_action_vxlan_encap(struct context *ctx, const struct token *token,
4121 const char *str, unsigned int len,
4122 void *buf, unsigned int size)
4124 struct buffer *out = buf;
4125 struct rte_flow_action *action;
4126 struct action_vxlan_encap_data *action_vxlan_encap_data;
4129 ret = parse_vc(ctx, token, str, len, buf, size);
4132 /* Nothing else to do if there is no buffer. */
4135 if (!out->args.vc.actions_n)
4137 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4138 /* Point to selected object. */
4139 ctx->object = out->args.vc.data;
4140 ctx->objmask = NULL;
4141 /* Set up default configuration. */
4142 action_vxlan_encap_data = ctx->object;
4143 *action_vxlan_encap_data = (struct action_vxlan_encap_data){
4144 .conf = (struct rte_flow_action_vxlan_encap){
4145 .definition = action_vxlan_encap_data->items,
4149 .type = RTE_FLOW_ITEM_TYPE_ETH,
4150 .spec = &action_vxlan_encap_data->item_eth,
4151 .mask = &rte_flow_item_eth_mask,
4154 .type = RTE_FLOW_ITEM_TYPE_VLAN,
4155 .spec = &action_vxlan_encap_data->item_vlan,
4156 .mask = &rte_flow_item_vlan_mask,
4159 .type = RTE_FLOW_ITEM_TYPE_IPV4,
4160 .spec = &action_vxlan_encap_data->item_ipv4,
4161 .mask = &rte_flow_item_ipv4_mask,
4164 .type = RTE_FLOW_ITEM_TYPE_UDP,
4165 .spec = &action_vxlan_encap_data->item_udp,
4166 .mask = &rte_flow_item_udp_mask,
4169 .type = RTE_FLOW_ITEM_TYPE_VXLAN,
4170 .spec = &action_vxlan_encap_data->item_vxlan,
4171 .mask = &rte_flow_item_vxlan_mask,
4174 .type = RTE_FLOW_ITEM_TYPE_END,
4179 .tci = vxlan_encap_conf.vlan_tci,
4183 .src_addr = vxlan_encap_conf.ipv4_src,
4184 .dst_addr = vxlan_encap_conf.ipv4_dst,
4187 .src_port = vxlan_encap_conf.udp_src,
4188 .dst_port = vxlan_encap_conf.udp_dst,
4190 .item_vxlan.flags = 0,
4192 memcpy(action_vxlan_encap_data->item_eth.dst.addr_bytes,
4193 vxlan_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
4194 memcpy(action_vxlan_encap_data->item_eth.src.addr_bytes,
4195 vxlan_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
4196 if (!vxlan_encap_conf.select_ipv4) {
4197 memcpy(&action_vxlan_encap_data->item_ipv6.hdr.src_addr,
4198 &vxlan_encap_conf.ipv6_src,
4199 sizeof(vxlan_encap_conf.ipv6_src));
4200 memcpy(&action_vxlan_encap_data->item_ipv6.hdr.dst_addr,
4201 &vxlan_encap_conf.ipv6_dst,
4202 sizeof(vxlan_encap_conf.ipv6_dst));
4203 action_vxlan_encap_data->items[2] = (struct rte_flow_item){
4204 .type = RTE_FLOW_ITEM_TYPE_IPV6,
4205 .spec = &action_vxlan_encap_data->item_ipv6,
4206 .mask = &rte_flow_item_ipv6_mask,
4209 if (!vxlan_encap_conf.select_vlan)
4210 action_vxlan_encap_data->items[1].type =
4211 RTE_FLOW_ITEM_TYPE_VOID;
4212 if (vxlan_encap_conf.select_tos_ttl) {
4213 if (vxlan_encap_conf.select_ipv4) {
4214 static struct rte_flow_item_ipv4 ipv4_mask_tos;
4216 memcpy(&ipv4_mask_tos, &rte_flow_item_ipv4_mask,
4217 sizeof(ipv4_mask_tos));
4218 ipv4_mask_tos.hdr.type_of_service = 0xff;
4219 ipv4_mask_tos.hdr.time_to_live = 0xff;
4220 action_vxlan_encap_data->item_ipv4.hdr.type_of_service =
4221 vxlan_encap_conf.ip_tos;
4222 action_vxlan_encap_data->item_ipv4.hdr.time_to_live =
4223 vxlan_encap_conf.ip_ttl;
4224 action_vxlan_encap_data->items[2].mask =
4227 static struct rte_flow_item_ipv6 ipv6_mask_tos;
4229 memcpy(&ipv6_mask_tos, &rte_flow_item_ipv6_mask,
4230 sizeof(ipv6_mask_tos));
4231 ipv6_mask_tos.hdr.vtc_flow |=
4232 RTE_BE32(0xfful << RTE_IPV6_HDR_TC_SHIFT);
4233 ipv6_mask_tos.hdr.hop_limits = 0xff;
4234 action_vxlan_encap_data->item_ipv6.hdr.vtc_flow |=
4236 ((uint32_t)vxlan_encap_conf.ip_tos <<
4237 RTE_IPV6_HDR_TC_SHIFT);
4238 action_vxlan_encap_data->item_ipv6.hdr.hop_limits =
4239 vxlan_encap_conf.ip_ttl;
4240 action_vxlan_encap_data->items[2].mask =
4244 memcpy(action_vxlan_encap_data->item_vxlan.vni, vxlan_encap_conf.vni,
4245 RTE_DIM(vxlan_encap_conf.vni));
4246 action->conf = &action_vxlan_encap_data->conf;
4250 /** Parse NVGRE encap action. */
4252 parse_vc_action_nvgre_encap(struct context *ctx, const struct token *token,
4253 const char *str, unsigned int len,
4254 void *buf, unsigned int size)
4256 struct buffer *out = buf;
4257 struct rte_flow_action *action;
4258 struct action_nvgre_encap_data *action_nvgre_encap_data;
4261 ret = parse_vc(ctx, token, str, len, buf, size);
4264 /* Nothing else to do if there is no buffer. */
4267 if (!out->args.vc.actions_n)
4269 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4270 /* Point to selected object. */
4271 ctx->object = out->args.vc.data;
4272 ctx->objmask = NULL;
4273 /* Set up default configuration. */
4274 action_nvgre_encap_data = ctx->object;
4275 *action_nvgre_encap_data = (struct action_nvgre_encap_data){
4276 .conf = (struct rte_flow_action_nvgre_encap){
4277 .definition = action_nvgre_encap_data->items,
4281 .type = RTE_FLOW_ITEM_TYPE_ETH,
4282 .spec = &action_nvgre_encap_data->item_eth,
4283 .mask = &rte_flow_item_eth_mask,
4286 .type = RTE_FLOW_ITEM_TYPE_VLAN,
4287 .spec = &action_nvgre_encap_data->item_vlan,
4288 .mask = &rte_flow_item_vlan_mask,
4291 .type = RTE_FLOW_ITEM_TYPE_IPV4,
4292 .spec = &action_nvgre_encap_data->item_ipv4,
4293 .mask = &rte_flow_item_ipv4_mask,
4296 .type = RTE_FLOW_ITEM_TYPE_NVGRE,
4297 .spec = &action_nvgre_encap_data->item_nvgre,
4298 .mask = &rte_flow_item_nvgre_mask,
4301 .type = RTE_FLOW_ITEM_TYPE_END,
4306 .tci = nvgre_encap_conf.vlan_tci,
4310 .src_addr = nvgre_encap_conf.ipv4_src,
4311 .dst_addr = nvgre_encap_conf.ipv4_dst,
4313 .item_nvgre.flow_id = 0,
4315 memcpy(action_nvgre_encap_data->item_eth.dst.addr_bytes,
4316 nvgre_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
4317 memcpy(action_nvgre_encap_data->item_eth.src.addr_bytes,
4318 nvgre_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
4319 if (!nvgre_encap_conf.select_ipv4) {
4320 memcpy(&action_nvgre_encap_data->item_ipv6.hdr.src_addr,
4321 &nvgre_encap_conf.ipv6_src,
4322 sizeof(nvgre_encap_conf.ipv6_src));
4323 memcpy(&action_nvgre_encap_data->item_ipv6.hdr.dst_addr,
4324 &nvgre_encap_conf.ipv6_dst,
4325 sizeof(nvgre_encap_conf.ipv6_dst));
4326 action_nvgre_encap_data->items[2] = (struct rte_flow_item){
4327 .type = RTE_FLOW_ITEM_TYPE_IPV6,
4328 .spec = &action_nvgre_encap_data->item_ipv6,
4329 .mask = &rte_flow_item_ipv6_mask,
4332 if (!nvgre_encap_conf.select_vlan)
4333 action_nvgre_encap_data->items[1].type =
4334 RTE_FLOW_ITEM_TYPE_VOID;
4335 memcpy(action_nvgre_encap_data->item_nvgre.tni, nvgre_encap_conf.tni,
4336 RTE_DIM(nvgre_encap_conf.tni));
4337 action->conf = &action_nvgre_encap_data->conf;
4341 /** Parse l2 encap action. */
4343 parse_vc_action_l2_encap(struct context *ctx, const struct token *token,
4344 const char *str, unsigned int len,
4345 void *buf, unsigned int size)
4347 struct buffer *out = buf;
4348 struct rte_flow_action *action;
4349 struct action_raw_encap_data *action_encap_data;
4350 struct rte_flow_item_eth eth = { .type = 0, };
4351 struct rte_flow_item_vlan vlan = {
4352 .tci = mplsoudp_encap_conf.vlan_tci,
4358 ret = parse_vc(ctx, token, str, len, buf, size);
4361 /* Nothing else to do if there is no buffer. */
4364 if (!out->args.vc.actions_n)
4366 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4367 /* Point to selected object. */
4368 ctx->object = out->args.vc.data;
4369 ctx->objmask = NULL;
4370 /* Copy the headers to the buffer. */
4371 action_encap_data = ctx->object;
4372 *action_encap_data = (struct action_raw_encap_data) {
4373 .conf = (struct rte_flow_action_raw_encap){
4374 .data = action_encap_data->data,
4378 header = action_encap_data->data;
4379 if (l2_encap_conf.select_vlan)
4380 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
4381 else if (l2_encap_conf.select_ipv4)
4382 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4384 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4385 memcpy(eth.dst.addr_bytes,
4386 l2_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
4387 memcpy(eth.src.addr_bytes,
4388 l2_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
4389 memcpy(header, ð, sizeof(eth));
4390 header += sizeof(eth);
4391 if (l2_encap_conf.select_vlan) {
4392 if (l2_encap_conf.select_ipv4)
4393 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4395 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4396 memcpy(header, &vlan, sizeof(vlan));
4397 header += sizeof(vlan);
4399 action_encap_data->conf.size = header -
4400 action_encap_data->data;
4401 action->conf = &action_encap_data->conf;
4405 /** Parse l2 decap action. */
4407 parse_vc_action_l2_decap(struct context *ctx, const struct token *token,
4408 const char *str, unsigned int len,
4409 void *buf, unsigned int size)
4411 struct buffer *out = buf;
4412 struct rte_flow_action *action;
4413 struct action_raw_decap_data *action_decap_data;
4414 struct rte_flow_item_eth eth = { .type = 0, };
4415 struct rte_flow_item_vlan vlan = {
4416 .tci = mplsoudp_encap_conf.vlan_tci,
4422 ret = parse_vc(ctx, token, str, len, buf, size);
4425 /* Nothing else to do if there is no buffer. */
4428 if (!out->args.vc.actions_n)
4430 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4431 /* Point to selected object. */
4432 ctx->object = out->args.vc.data;
4433 ctx->objmask = NULL;
4434 /* Copy the headers to the buffer. */
4435 action_decap_data = ctx->object;
4436 *action_decap_data = (struct action_raw_decap_data) {
4437 .conf = (struct rte_flow_action_raw_decap){
4438 .data = action_decap_data->data,
4442 header = action_decap_data->data;
4443 if (l2_decap_conf.select_vlan)
4444 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
4445 memcpy(header, ð, sizeof(eth));
4446 header += sizeof(eth);
4447 if (l2_decap_conf.select_vlan) {
4448 memcpy(header, &vlan, sizeof(vlan));
4449 header += sizeof(vlan);
4451 action_decap_data->conf.size = header -
4452 action_decap_data->data;
4453 action->conf = &action_decap_data->conf;
4457 #define ETHER_TYPE_MPLS_UNICAST 0x8847
4459 /** Parse MPLSOGRE encap action. */
4461 parse_vc_action_mplsogre_encap(struct context *ctx, const struct token *token,
4462 const char *str, unsigned int len,
4463 void *buf, unsigned int size)
4465 struct buffer *out = buf;
4466 struct rte_flow_action *action;
4467 struct action_raw_encap_data *action_encap_data;
4468 struct rte_flow_item_eth eth = { .type = 0, };
4469 struct rte_flow_item_vlan vlan = {
4470 .tci = mplsogre_encap_conf.vlan_tci,
4473 struct rte_flow_item_ipv4 ipv4 = {
4475 .src_addr = mplsogre_encap_conf.ipv4_src,
4476 .dst_addr = mplsogre_encap_conf.ipv4_dst,
4477 .next_proto_id = IPPROTO_GRE,
4478 .version_ihl = RTE_IPV4_VHL_DEF,
4479 .time_to_live = IPDEFTTL,
4482 struct rte_flow_item_ipv6 ipv6 = {
4484 .proto = IPPROTO_GRE,
4485 .hop_limits = IPDEFTTL,
4488 struct rte_flow_item_gre gre = {
4489 .protocol = rte_cpu_to_be_16(ETHER_TYPE_MPLS_UNICAST),
4491 struct rte_flow_item_mpls mpls;
4495 ret = parse_vc(ctx, token, str, len, buf, size);
4498 /* Nothing else to do if there is no buffer. */
4501 if (!out->args.vc.actions_n)
4503 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4504 /* Point to selected object. */
4505 ctx->object = out->args.vc.data;
4506 ctx->objmask = NULL;
4507 /* Copy the headers to the buffer. */
4508 action_encap_data = ctx->object;
4509 *action_encap_data = (struct action_raw_encap_data) {
4510 .conf = (struct rte_flow_action_raw_encap){
4511 .data = action_encap_data->data,
4516 header = action_encap_data->data;
4517 if (mplsogre_encap_conf.select_vlan)
4518 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
4519 else if (mplsogre_encap_conf.select_ipv4)
4520 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4522 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4523 memcpy(eth.dst.addr_bytes,
4524 mplsogre_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
4525 memcpy(eth.src.addr_bytes,
4526 mplsogre_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
4527 memcpy(header, ð, sizeof(eth));
4528 header += sizeof(eth);
4529 if (mplsogre_encap_conf.select_vlan) {
4530 if (mplsogre_encap_conf.select_ipv4)
4531 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4533 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4534 memcpy(header, &vlan, sizeof(vlan));
4535 header += sizeof(vlan);
4537 if (mplsogre_encap_conf.select_ipv4) {
4538 memcpy(header, &ipv4, sizeof(ipv4));
4539 header += sizeof(ipv4);
4541 memcpy(&ipv6.hdr.src_addr,
4542 &mplsogre_encap_conf.ipv6_src,
4543 sizeof(mplsogre_encap_conf.ipv6_src));
4544 memcpy(&ipv6.hdr.dst_addr,
4545 &mplsogre_encap_conf.ipv6_dst,
4546 sizeof(mplsogre_encap_conf.ipv6_dst));
4547 memcpy(header, &ipv6, sizeof(ipv6));
4548 header += sizeof(ipv6);
4550 memcpy(header, &gre, sizeof(gre));
4551 header += sizeof(gre);
4552 memcpy(mpls.label_tc_s, mplsogre_encap_conf.label,
4553 RTE_DIM(mplsogre_encap_conf.label));
4554 mpls.label_tc_s[2] |= 0x1;
4555 memcpy(header, &mpls, sizeof(mpls));
4556 header += sizeof(mpls);
4557 action_encap_data->conf.size = header -
4558 action_encap_data->data;
4559 action->conf = &action_encap_data->conf;
4563 /** Parse MPLSOGRE decap action. */
4565 parse_vc_action_mplsogre_decap(struct context *ctx, const struct token *token,
4566 const char *str, unsigned int len,
4567 void *buf, unsigned int size)
4569 struct buffer *out = buf;
4570 struct rte_flow_action *action;
4571 struct action_raw_decap_data *action_decap_data;
4572 struct rte_flow_item_eth eth = { .type = 0, };
4573 struct rte_flow_item_vlan vlan = {.tci = 0};
4574 struct rte_flow_item_ipv4 ipv4 = {
4576 .next_proto_id = IPPROTO_GRE,
4579 struct rte_flow_item_ipv6 ipv6 = {
4581 .proto = IPPROTO_GRE,
4584 struct rte_flow_item_gre gre = {
4585 .protocol = rte_cpu_to_be_16(ETHER_TYPE_MPLS_UNICAST),
4587 struct rte_flow_item_mpls mpls;
4591 ret = parse_vc(ctx, token, str, len, buf, size);
4594 /* Nothing else to do if there is no buffer. */
4597 if (!out->args.vc.actions_n)
4599 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4600 /* Point to selected object. */
4601 ctx->object = out->args.vc.data;
4602 ctx->objmask = NULL;
4603 /* Copy the headers to the buffer. */
4604 action_decap_data = ctx->object;
4605 *action_decap_data = (struct action_raw_decap_data) {
4606 .conf = (struct rte_flow_action_raw_decap){
4607 .data = action_decap_data->data,
4611 header = action_decap_data->data;
4612 if (mplsogre_decap_conf.select_vlan)
4613 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
4614 else if (mplsogre_encap_conf.select_ipv4)
4615 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4617 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4618 memcpy(eth.dst.addr_bytes,
4619 mplsogre_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
4620 memcpy(eth.src.addr_bytes,
4621 mplsogre_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
4622 memcpy(header, ð, sizeof(eth));
4623 header += sizeof(eth);
4624 if (mplsogre_encap_conf.select_vlan) {
4625 if (mplsogre_encap_conf.select_ipv4)
4626 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4628 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4629 memcpy(header, &vlan, sizeof(vlan));
4630 header += sizeof(vlan);
4632 if (mplsogre_encap_conf.select_ipv4) {
4633 memcpy(header, &ipv4, sizeof(ipv4));
4634 header += sizeof(ipv4);
4636 memcpy(header, &ipv6, sizeof(ipv6));
4637 header += sizeof(ipv6);
4639 memcpy(header, &gre, sizeof(gre));
4640 header += sizeof(gre);
4641 memset(&mpls, 0, sizeof(mpls));
4642 memcpy(header, &mpls, sizeof(mpls));
4643 header += sizeof(mpls);
4644 action_decap_data->conf.size = header -
4645 action_decap_data->data;
4646 action->conf = &action_decap_data->conf;
4650 /** Parse MPLSOUDP encap action. */
4652 parse_vc_action_mplsoudp_encap(struct context *ctx, const struct token *token,
4653 const char *str, unsigned int len,
4654 void *buf, unsigned int size)
4656 struct buffer *out = buf;
4657 struct rte_flow_action *action;
4658 struct action_raw_encap_data *action_encap_data;
4659 struct rte_flow_item_eth eth = { .type = 0, };
4660 struct rte_flow_item_vlan vlan = {
4661 .tci = mplsoudp_encap_conf.vlan_tci,
4664 struct rte_flow_item_ipv4 ipv4 = {
4666 .src_addr = mplsoudp_encap_conf.ipv4_src,
4667 .dst_addr = mplsoudp_encap_conf.ipv4_dst,
4668 .next_proto_id = IPPROTO_UDP,
4669 .version_ihl = RTE_IPV4_VHL_DEF,
4670 .time_to_live = IPDEFTTL,
4673 struct rte_flow_item_ipv6 ipv6 = {
4675 .proto = IPPROTO_UDP,
4676 .hop_limits = IPDEFTTL,
4679 struct rte_flow_item_udp udp = {
4681 .src_port = mplsoudp_encap_conf.udp_src,
4682 .dst_port = mplsoudp_encap_conf.udp_dst,
4685 struct rte_flow_item_mpls mpls;
4689 ret = parse_vc(ctx, token, str, len, buf, size);
4692 /* Nothing else to do if there is no buffer. */
4695 if (!out->args.vc.actions_n)
4697 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4698 /* Point to selected object. */
4699 ctx->object = out->args.vc.data;
4700 ctx->objmask = NULL;
4701 /* Copy the headers to the buffer. */
4702 action_encap_data = ctx->object;
4703 *action_encap_data = (struct action_raw_encap_data) {
4704 .conf = (struct rte_flow_action_raw_encap){
4705 .data = action_encap_data->data,
4710 header = action_encap_data->data;
4711 if (mplsoudp_encap_conf.select_vlan)
4712 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
4713 else if (mplsoudp_encap_conf.select_ipv4)
4714 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4716 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4717 memcpy(eth.dst.addr_bytes,
4718 mplsoudp_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
4719 memcpy(eth.src.addr_bytes,
4720 mplsoudp_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
4721 memcpy(header, ð, sizeof(eth));
4722 header += sizeof(eth);
4723 if (mplsoudp_encap_conf.select_vlan) {
4724 if (mplsoudp_encap_conf.select_ipv4)
4725 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4727 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4728 memcpy(header, &vlan, sizeof(vlan));
4729 header += sizeof(vlan);
4731 if (mplsoudp_encap_conf.select_ipv4) {
4732 memcpy(header, &ipv4, sizeof(ipv4));
4733 header += sizeof(ipv4);
4735 memcpy(&ipv6.hdr.src_addr,
4736 &mplsoudp_encap_conf.ipv6_src,
4737 sizeof(mplsoudp_encap_conf.ipv6_src));
4738 memcpy(&ipv6.hdr.dst_addr,
4739 &mplsoudp_encap_conf.ipv6_dst,
4740 sizeof(mplsoudp_encap_conf.ipv6_dst));
4741 memcpy(header, &ipv6, sizeof(ipv6));
4742 header += sizeof(ipv6);
4744 memcpy(header, &udp, sizeof(udp));
4745 header += sizeof(udp);
4746 memcpy(mpls.label_tc_s, mplsoudp_encap_conf.label,
4747 RTE_DIM(mplsoudp_encap_conf.label));
4748 mpls.label_tc_s[2] |= 0x1;
4749 memcpy(header, &mpls, sizeof(mpls));
4750 header += sizeof(mpls);
4751 action_encap_data->conf.size = header -
4752 action_encap_data->data;
4753 action->conf = &action_encap_data->conf;
4757 /** Parse MPLSOUDP decap action. */
4759 parse_vc_action_mplsoudp_decap(struct context *ctx, const struct token *token,
4760 const char *str, unsigned int len,
4761 void *buf, unsigned int size)
4763 struct buffer *out = buf;
4764 struct rte_flow_action *action;
4765 struct action_raw_decap_data *action_decap_data;
4766 struct rte_flow_item_eth eth = { .type = 0, };
4767 struct rte_flow_item_vlan vlan = {.tci = 0};
4768 struct rte_flow_item_ipv4 ipv4 = {
4770 .next_proto_id = IPPROTO_UDP,
4773 struct rte_flow_item_ipv6 ipv6 = {
4775 .proto = IPPROTO_UDP,
4778 struct rte_flow_item_udp udp = {
4780 .dst_port = rte_cpu_to_be_16(6635),
4783 struct rte_flow_item_mpls mpls;
4787 ret = parse_vc(ctx, token, str, len, buf, size);
4790 /* Nothing else to do if there is no buffer. */
4793 if (!out->args.vc.actions_n)
4795 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4796 /* Point to selected object. */
4797 ctx->object = out->args.vc.data;
4798 ctx->objmask = NULL;
4799 /* Copy the headers to the buffer. */
4800 action_decap_data = ctx->object;
4801 *action_decap_data = (struct action_raw_decap_data) {
4802 .conf = (struct rte_flow_action_raw_decap){
4803 .data = action_decap_data->data,
4807 header = action_decap_data->data;
4808 if (mplsoudp_decap_conf.select_vlan)
4809 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
4810 else if (mplsoudp_encap_conf.select_ipv4)
4811 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4813 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4814 memcpy(eth.dst.addr_bytes,
4815 mplsoudp_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
4816 memcpy(eth.src.addr_bytes,
4817 mplsoudp_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
4818 memcpy(header, ð, sizeof(eth));
4819 header += sizeof(eth);
4820 if (mplsoudp_encap_conf.select_vlan) {
4821 if (mplsoudp_encap_conf.select_ipv4)
4822 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4824 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4825 memcpy(header, &vlan, sizeof(vlan));
4826 header += sizeof(vlan);
4828 if (mplsoudp_encap_conf.select_ipv4) {
4829 memcpy(header, &ipv4, sizeof(ipv4));
4830 header += sizeof(ipv4);
4832 memcpy(header, &ipv6, sizeof(ipv6));
4833 header += sizeof(ipv6);
4835 memcpy(header, &udp, sizeof(udp));
4836 header += sizeof(udp);
4837 memset(&mpls, 0, sizeof(mpls));
4838 memcpy(header, &mpls, sizeof(mpls));
4839 header += sizeof(mpls);
4840 action_decap_data->conf.size = header -
4841 action_decap_data->data;
4842 action->conf = &action_decap_data->conf;
4847 parse_vc_action_raw_decap_index(struct context *ctx, const struct token *token,
4848 const char *str, unsigned int len, void *buf,
4851 struct action_raw_decap_data *action_raw_decap_data;
4852 struct rte_flow_action *action;
4853 const struct arg *arg;
4854 struct buffer *out = buf;
4858 RTE_SET_USED(token);
4861 arg = ARGS_ENTRY_ARB_BOUNDED
4862 (offsetof(struct action_raw_decap_data, idx),
4863 sizeof(((struct action_raw_decap_data *)0)->idx),
4864 0, RAW_ENCAP_CONFS_MAX_NUM - 1);
4865 if (push_args(ctx, arg))
4867 ret = parse_int(ctx, token, str, len, NULL, 0);
4874 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4875 action_raw_decap_data = ctx->object;
4876 idx = action_raw_decap_data->idx;
4877 action_raw_decap_data->conf.data = raw_decap_confs[idx].data;
4878 action_raw_decap_data->conf.size = raw_decap_confs[idx].size;
4879 action->conf = &action_raw_decap_data->conf;
4885 parse_vc_action_raw_encap_index(struct context *ctx, const struct token *token,
4886 const char *str, unsigned int len, void *buf,
4889 struct action_raw_encap_data *action_raw_encap_data;
4890 struct rte_flow_action *action;
4891 const struct arg *arg;
4892 struct buffer *out = buf;
4896 RTE_SET_USED(token);
4899 if (ctx->curr != ACTION_RAW_ENCAP_INDEX_VALUE)
4901 arg = ARGS_ENTRY_ARB_BOUNDED
4902 (offsetof(struct action_raw_encap_data, idx),
4903 sizeof(((struct action_raw_encap_data *)0)->idx),
4904 0, RAW_ENCAP_CONFS_MAX_NUM - 1);
4905 if (push_args(ctx, arg))
4907 ret = parse_int(ctx, token, str, len, NULL, 0);
4914 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4915 action_raw_encap_data = ctx->object;
4916 idx = action_raw_encap_data->idx;
4917 action_raw_encap_data->conf.data = raw_encap_confs[idx].data;
4918 action_raw_encap_data->conf.size = raw_encap_confs[idx].size;
4919 action_raw_encap_data->conf.preserve = NULL;
4920 action->conf = &action_raw_encap_data->conf;
4925 parse_vc_action_raw_encap(struct context *ctx, const struct token *token,
4926 const char *str, unsigned int len, void *buf,
4929 struct buffer *out = buf;
4930 struct rte_flow_action *action;
4931 struct action_raw_encap_data *action_raw_encap_data = NULL;
4934 ret = parse_vc(ctx, token, str, len, buf, size);
4937 /* Nothing else to do if there is no buffer. */
4940 if (!out->args.vc.actions_n)
4942 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4943 /* Point to selected object. */
4944 ctx->object = out->args.vc.data;
4945 ctx->objmask = NULL;
4946 /* Copy the headers to the buffer. */
4947 action_raw_encap_data = ctx->object;
4948 action_raw_encap_data->conf.data = raw_encap_confs[0].data;
4949 action_raw_encap_data->conf.preserve = NULL;
4950 action_raw_encap_data->conf.size = raw_encap_confs[0].size;
4951 action->conf = &action_raw_encap_data->conf;
4956 parse_vc_action_raw_decap(struct context *ctx, const struct token *token,
4957 const char *str, unsigned int len, void *buf,
4960 struct buffer *out = buf;
4961 struct rte_flow_action *action;
4962 struct action_raw_decap_data *action_raw_decap_data = NULL;
4965 ret = parse_vc(ctx, token, str, len, buf, size);
4968 /* Nothing else to do if there is no buffer. */
4971 if (!out->args.vc.actions_n)
4973 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4974 /* Point to selected object. */
4975 ctx->object = out->args.vc.data;
4976 ctx->objmask = NULL;
4977 /* Copy the headers to the buffer. */
4978 action_raw_decap_data = ctx->object;
4979 action_raw_decap_data->conf.data = raw_decap_confs[0].data;
4980 action_raw_decap_data->conf.size = raw_decap_confs[0].size;
4981 action->conf = &action_raw_decap_data->conf;
4986 parse_vc_action_set_meta(struct context *ctx, const struct token *token,
4987 const char *str, unsigned int len, void *buf,
4992 ret = parse_vc(ctx, token, str, len, buf, size);
4995 ret = rte_flow_dynf_metadata_register();
5001 /** Parse tokens for destroy command. */
5003 parse_destroy(struct context *ctx, const struct token *token,
5004 const char *str, unsigned int len,
5005 void *buf, unsigned int size)
5007 struct buffer *out = buf;
5009 /* Token name must match. */
5010 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5012 /* Nothing else to do if there is no buffer. */
5015 if (!out->command) {
5016 if (ctx->curr != DESTROY)
5018 if (sizeof(*out) > size)
5020 out->command = ctx->curr;
5023 ctx->objmask = NULL;
5024 out->args.destroy.rule =
5025 (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
5029 if (((uint8_t *)(out->args.destroy.rule + out->args.destroy.rule_n) +
5030 sizeof(*out->args.destroy.rule)) > (uint8_t *)out + size)
5033 ctx->object = out->args.destroy.rule + out->args.destroy.rule_n++;
5034 ctx->objmask = NULL;
5038 /** Parse tokens for flush command. */
5040 parse_flush(struct context *ctx, const struct token *token,
5041 const char *str, unsigned int len,
5042 void *buf, unsigned int size)
5044 struct buffer *out = buf;
5046 /* Token name must match. */
5047 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5049 /* Nothing else to do if there is no buffer. */
5052 if (!out->command) {
5053 if (ctx->curr != FLUSH)
5055 if (sizeof(*out) > size)
5057 out->command = ctx->curr;
5060 ctx->objmask = NULL;
5065 /** Parse tokens for query command. */
5067 parse_query(struct context *ctx, const struct token *token,
5068 const char *str, unsigned int len,
5069 void *buf, unsigned int size)
5071 struct buffer *out = buf;
5073 /* Token name must match. */
5074 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5076 /* Nothing else to do if there is no buffer. */
5079 if (!out->command) {
5080 if (ctx->curr != QUERY)
5082 if (sizeof(*out) > size)
5084 out->command = ctx->curr;
5087 ctx->objmask = NULL;
5092 /** Parse action names. */
5094 parse_action(struct context *ctx, const struct token *token,
5095 const char *str, unsigned int len,
5096 void *buf, unsigned int size)
5098 struct buffer *out = buf;
5099 const struct arg *arg = pop_args(ctx);
5103 /* Argument is expected. */
5106 /* Parse action name. */
5107 for (i = 0; next_action[i]; ++i) {
5108 const struct parse_action_priv *priv;
5110 token = &token_list[next_action[i]];
5111 if (strcmp_partial(token->name, str, len))
5117 memcpy((uint8_t *)ctx->object + arg->offset,
5123 push_args(ctx, arg);
5127 /** Parse tokens for list command. */
5129 parse_list(struct context *ctx, const struct token *token,
5130 const char *str, unsigned int len,
5131 void *buf, unsigned int size)
5133 struct buffer *out = buf;
5135 /* Token name must match. */
5136 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5138 /* Nothing else to do if there is no buffer. */
5141 if (!out->command) {
5142 if (ctx->curr != LIST)
5144 if (sizeof(*out) > size)
5146 out->command = ctx->curr;
5149 ctx->objmask = NULL;
5150 out->args.list.group =
5151 (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
5155 if (((uint8_t *)(out->args.list.group + out->args.list.group_n) +
5156 sizeof(*out->args.list.group)) > (uint8_t *)out + size)
5159 ctx->object = out->args.list.group + out->args.list.group_n++;
5160 ctx->objmask = NULL;
5164 /** Parse tokens for isolate command. */
5166 parse_isolate(struct context *ctx, const struct token *token,
5167 const char *str, unsigned int len,
5168 void *buf, unsigned int size)
5170 struct buffer *out = buf;
5172 /* Token name must match. */
5173 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5175 /* Nothing else to do if there is no buffer. */
5178 if (!out->command) {
5179 if (ctx->curr != ISOLATE)
5181 if (sizeof(*out) > size)
5183 out->command = ctx->curr;
5186 ctx->objmask = NULL;
5192 * Parse signed/unsigned integers 8 to 64-bit long.
5194 * Last argument (ctx->args) is retrieved to determine integer type and
5198 parse_int(struct context *ctx, const struct token *token,
5199 const char *str, unsigned int len,
5200 void *buf, unsigned int size)
5202 const struct arg *arg = pop_args(ctx);
5207 /* Argument is expected. */
5212 (uintmax_t)strtoimax(str, &end, 0) :
5213 strtoumax(str, &end, 0);
5214 if (errno || (size_t)(end - str) != len)
5217 ((arg->sign && ((intmax_t)u < (intmax_t)arg->min ||
5218 (intmax_t)u > (intmax_t)arg->max)) ||
5219 (!arg->sign && (u < arg->min || u > arg->max))))
5224 if (!arg_entry_bf_fill(ctx->object, u, arg) ||
5225 !arg_entry_bf_fill(ctx->objmask, -1, arg))
5229 buf = (uint8_t *)ctx->object + arg->offset;
5231 if (u > RTE_LEN2MASK(size * CHAR_BIT, uint64_t))
5235 case sizeof(uint8_t):
5236 *(uint8_t *)buf = u;
5238 case sizeof(uint16_t):
5239 *(uint16_t *)buf = arg->hton ? rte_cpu_to_be_16(u) : u;
5241 case sizeof(uint8_t [3]):
5242 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
5244 ((uint8_t *)buf)[0] = u;
5245 ((uint8_t *)buf)[1] = u >> 8;
5246 ((uint8_t *)buf)[2] = u >> 16;
5250 ((uint8_t *)buf)[0] = u >> 16;
5251 ((uint8_t *)buf)[1] = u >> 8;
5252 ((uint8_t *)buf)[2] = u;
5254 case sizeof(uint32_t):
5255 *(uint32_t *)buf = arg->hton ? rte_cpu_to_be_32(u) : u;
5257 case sizeof(uint64_t):
5258 *(uint64_t *)buf = arg->hton ? rte_cpu_to_be_64(u) : u;
5263 if (ctx->objmask && buf != (uint8_t *)ctx->objmask + arg->offset) {
5265 buf = (uint8_t *)ctx->objmask + arg->offset;
5270 push_args(ctx, arg);
5277 * Three arguments (ctx->args) are retrieved from the stack to store data,
5278 * its actual length and address (in that order).
5281 parse_string(struct context *ctx, const struct token *token,
5282 const char *str, unsigned int len,
5283 void *buf, unsigned int size)
5285 const struct arg *arg_data = pop_args(ctx);
5286 const struct arg *arg_len = pop_args(ctx);
5287 const struct arg *arg_addr = pop_args(ctx);
5288 char tmp[16]; /* Ought to be enough. */
5291 /* Arguments are expected. */
5295 push_args(ctx, arg_data);
5299 push_args(ctx, arg_len);
5300 push_args(ctx, arg_data);
5303 size = arg_data->size;
5304 /* Bit-mask fill is not supported. */
5305 if (arg_data->mask || size < len)
5309 /* Let parse_int() fill length information first. */
5310 ret = snprintf(tmp, sizeof(tmp), "%u", len);
5313 push_args(ctx, arg_len);
5314 ret = parse_int(ctx, token, tmp, ret, NULL, 0);
5319 buf = (uint8_t *)ctx->object + arg_data->offset;
5320 /* Output buffer is not necessarily NUL-terminated. */
5321 memcpy(buf, str, len);
5322 memset((uint8_t *)buf + len, 0x00, size - len);
5324 memset((uint8_t *)ctx->objmask + arg_data->offset, 0xff, len);
5325 /* Save address if requested. */
5326 if (arg_addr->size) {
5327 memcpy((uint8_t *)ctx->object + arg_addr->offset,
5329 (uint8_t *)ctx->object + arg_data->offset
5333 memcpy((uint8_t *)ctx->objmask + arg_addr->offset,
5335 (uint8_t *)ctx->objmask + arg_data->offset
5341 push_args(ctx, arg_addr);
5342 push_args(ctx, arg_len);
5343 push_args(ctx, arg_data);
5348 parse_hex_string(const char *src, uint8_t *dst, uint32_t *size)
5354 /* Check input parameters */
5355 if ((src == NULL) ||
5361 /* Convert chars to bytes */
5362 for (i = 0, len = 0; i < *size; i += 2) {
5363 snprintf(tmp, 3, "%s", src + i);
5364 dst[len++] = strtoul(tmp, &c, 16);
5379 parse_hex(struct context *ctx, const struct token *token,
5380 const char *str, unsigned int len,
5381 void *buf, unsigned int size)
5383 const struct arg *arg_data = pop_args(ctx);
5384 const struct arg *arg_len = pop_args(ctx);
5385 const struct arg *arg_addr = pop_args(ctx);
5386 char tmp[16]; /* Ought to be enough. */
5388 unsigned int hexlen = len;
5389 unsigned int length = 256;
5390 uint8_t hex_tmp[length];
5392 /* Arguments are expected. */
5396 push_args(ctx, arg_data);
5400 push_args(ctx, arg_len);
5401 push_args(ctx, arg_data);
5404 size = arg_data->size;
5405 /* Bit-mask fill is not supported. */
5411 /* translate bytes string to array. */
5412 if (str[0] == '0' && ((str[1] == 'x') ||
5417 if (hexlen > length)
5419 ret = parse_hex_string(str, hex_tmp, &hexlen);
5422 /* Let parse_int() fill length information first. */
5423 ret = snprintf(tmp, sizeof(tmp), "%u", hexlen);
5426 push_args(ctx, arg_len);
5427 ret = parse_int(ctx, token, tmp, ret, NULL, 0);
5432 buf = (uint8_t *)ctx->object + arg_data->offset;
5433 /* Output buffer is not necessarily NUL-terminated. */
5434 memcpy(buf, hex_tmp, hexlen);
5435 memset((uint8_t *)buf + hexlen, 0x00, size - hexlen);
5437 memset((uint8_t *)ctx->objmask + arg_data->offset,
5439 /* Save address if requested. */
5440 if (arg_addr->size) {
5441 memcpy((uint8_t *)ctx->object + arg_addr->offset,
5443 (uint8_t *)ctx->object + arg_data->offset
5447 memcpy((uint8_t *)ctx->objmask + arg_addr->offset,
5449 (uint8_t *)ctx->objmask + arg_data->offset
5455 push_args(ctx, arg_addr);
5456 push_args(ctx, arg_len);
5457 push_args(ctx, arg_data);
5463 * Parse a MAC address.
5465 * Last argument (ctx->args) is retrieved to determine storage size and
5469 parse_mac_addr(struct context *ctx, const struct token *token,
5470 const char *str, unsigned int len,
5471 void *buf, unsigned int size)
5473 const struct arg *arg = pop_args(ctx);
5474 struct rte_ether_addr tmp;
5478 /* Argument is expected. */
5482 /* Bit-mask fill is not supported. */
5483 if (arg->mask || size != sizeof(tmp))
5485 /* Only network endian is supported. */
5488 ret = cmdline_parse_etheraddr(NULL, str, &tmp, size);
5489 if (ret < 0 || (unsigned int)ret != len)
5493 buf = (uint8_t *)ctx->object + arg->offset;
5494 memcpy(buf, &tmp, size);
5496 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
5499 push_args(ctx, arg);
5504 * Parse an IPv4 address.
5506 * Last argument (ctx->args) is retrieved to determine storage size and
5510 parse_ipv4_addr(struct context *ctx, const struct token *token,
5511 const char *str, unsigned int len,
5512 void *buf, unsigned int size)
5514 const struct arg *arg = pop_args(ctx);
5519 /* Argument is expected. */
5523 /* Bit-mask fill is not supported. */
5524 if (arg->mask || size != sizeof(tmp))
5526 /* Only network endian is supported. */
5529 memcpy(str2, str, len);
5531 ret = inet_pton(AF_INET, str2, &tmp);
5533 /* Attempt integer parsing. */
5534 push_args(ctx, arg);
5535 return parse_int(ctx, token, str, len, buf, size);
5539 buf = (uint8_t *)ctx->object + arg->offset;
5540 memcpy(buf, &tmp, size);
5542 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
5545 push_args(ctx, arg);
5550 * Parse an IPv6 address.
5552 * Last argument (ctx->args) is retrieved to determine storage size and
5556 parse_ipv6_addr(struct context *ctx, const struct token *token,
5557 const char *str, unsigned int len,
5558 void *buf, unsigned int size)
5560 const struct arg *arg = pop_args(ctx);
5562 struct in6_addr tmp;
5566 /* Argument is expected. */
5570 /* Bit-mask fill is not supported. */
5571 if (arg->mask || size != sizeof(tmp))
5573 /* Only network endian is supported. */
5576 memcpy(str2, str, len);
5578 ret = inet_pton(AF_INET6, str2, &tmp);
5583 buf = (uint8_t *)ctx->object + arg->offset;
5584 memcpy(buf, &tmp, size);
5586 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
5589 push_args(ctx, arg);
5593 /** Boolean values (even indices stand for false). */
5594 static const char *const boolean_name[] = {
5604 * Parse a boolean value.
5606 * Last argument (ctx->args) is retrieved to determine storage size and
5610 parse_boolean(struct context *ctx, const struct token *token,
5611 const char *str, unsigned int len,
5612 void *buf, unsigned int size)
5614 const struct arg *arg = pop_args(ctx);
5618 /* Argument is expected. */
5621 for (i = 0; boolean_name[i]; ++i)
5622 if (!strcmp_partial(boolean_name[i], str, len))
5624 /* Process token as integer. */
5625 if (boolean_name[i])
5626 str = i & 1 ? "1" : "0";
5627 push_args(ctx, arg);
5628 ret = parse_int(ctx, token, str, strlen(str), buf, size);
5629 return ret > 0 ? (int)len : ret;
5632 /** Parse port and update context. */
5634 parse_port(struct context *ctx, const struct token *token,
5635 const char *str, unsigned int len,
5636 void *buf, unsigned int size)
5638 struct buffer *out = &(struct buffer){ .port = 0 };
5646 ctx->objmask = NULL;
5647 size = sizeof(*out);
5649 ret = parse_int(ctx, token, str, len, out, size);
5651 ctx->port = out->port;
5657 /** Parse set command, initialize output buffer for subsequent tokens. */
5659 parse_set_raw_encap_decap(struct context *ctx, const struct token *token,
5660 const char *str, unsigned int len,
5661 void *buf, unsigned int size)
5663 struct buffer *out = buf;
5665 /* Token name must match. */
5666 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5668 /* Nothing else to do if there is no buffer. */
5671 /* Make sure buffer is large enough. */
5672 if (size < sizeof(*out))
5675 ctx->objmask = NULL;
5679 out->command = ctx->curr;
5684 * Parse set raw_encap/raw_decap command,
5685 * initialize output buffer for subsequent tokens.
5688 parse_set_init(struct context *ctx, const struct token *token,
5689 const char *str, unsigned int len,
5690 void *buf, unsigned int size)
5692 struct buffer *out = buf;
5694 /* Token name must match. */
5695 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5697 /* Nothing else to do if there is no buffer. */
5700 /* Make sure buffer is large enough. */
5701 if (size < sizeof(*out))
5703 /* Initialize buffer. */
5704 memset(out, 0x00, sizeof(*out));
5705 memset((uint8_t *)out + sizeof(*out), 0x22, size - sizeof(*out));
5708 ctx->objmask = NULL;
5709 if (!out->command) {
5710 if (ctx->curr != SET)
5712 if (sizeof(*out) > size)
5714 out->command = ctx->curr;
5715 out->args.vc.data = (uint8_t *)out + size;
5716 /* All we need is pattern */
5717 out->args.vc.pattern =
5718 (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
5720 ctx->object = out->args.vc.pattern;
5725 /** No completion. */
5727 comp_none(struct context *ctx, const struct token *token,
5728 unsigned int ent, char *buf, unsigned int size)
5738 /** Complete boolean values. */
5740 comp_boolean(struct context *ctx, const struct token *token,
5741 unsigned int ent, char *buf, unsigned int size)
5747 for (i = 0; boolean_name[i]; ++i)
5748 if (buf && i == ent)
5749 return strlcpy(buf, boolean_name[i], size);
5755 /** Complete action names. */
5757 comp_action(struct context *ctx, const struct token *token,
5758 unsigned int ent, char *buf, unsigned int size)
5764 for (i = 0; next_action[i]; ++i)
5765 if (buf && i == ent)
5766 return strlcpy(buf, token_list[next_action[i]].name,
5773 /** Complete available ports. */
5775 comp_port(struct context *ctx, const struct token *token,
5776 unsigned int ent, char *buf, unsigned int size)
5783 RTE_ETH_FOREACH_DEV(p) {
5784 if (buf && i == ent)
5785 return snprintf(buf, size, "%u", p);
5793 /** Complete available rule IDs. */
5795 comp_rule_id(struct context *ctx, const struct token *token,
5796 unsigned int ent, char *buf, unsigned int size)
5799 struct rte_port *port;
5800 struct port_flow *pf;
5803 if (port_id_is_invalid(ctx->port, DISABLED_WARN) ||
5804 ctx->port == (portid_t)RTE_PORT_ALL)
5806 port = &ports[ctx->port];
5807 for (pf = port->flow_list; pf != NULL; pf = pf->next) {
5808 if (buf && i == ent)
5809 return snprintf(buf, size, "%u", pf->id);
5817 /** Complete type field for RSS action. */
5819 comp_vc_action_rss_type(struct context *ctx, const struct token *token,
5820 unsigned int ent, char *buf, unsigned int size)
5826 for (i = 0; rss_type_table[i].str; ++i)
5831 return strlcpy(buf, rss_type_table[ent].str, size);
5833 return snprintf(buf, size, "end");
5837 /** Complete queue field for RSS action. */
5839 comp_vc_action_rss_queue(struct context *ctx, const struct token *token,
5840 unsigned int ent, char *buf, unsigned int size)
5847 return snprintf(buf, size, "%u", ent);
5849 return snprintf(buf, size, "end");
5853 /** Complete index number for set raw_encap/raw_decap commands. */
5855 comp_set_raw_index(struct context *ctx, const struct token *token,
5856 unsigned int ent, char *buf, unsigned int size)
5862 RTE_SET_USED(token);
5863 for (idx = 0; idx < RAW_ENCAP_CONFS_MAX_NUM; ++idx) {
5864 if (buf && idx == ent)
5865 return snprintf(buf, size, "%u", idx);
5871 /** Internal context. */
5872 static struct context cmd_flow_context;
5874 /** Global parser instance (cmdline API). */
5875 cmdline_parse_inst_t cmd_flow;
5876 cmdline_parse_inst_t cmd_set_raw;
5878 /** Initialize context. */
5880 cmd_flow_context_init(struct context *ctx)
5882 /* A full memset() is not necessary. */
5892 ctx->objmask = NULL;
5895 /** Parse a token (cmdline API). */
5897 cmd_flow_parse(cmdline_parse_token_hdr_t *hdr, const char *src, void *result,
5900 struct context *ctx = &cmd_flow_context;
5901 const struct token *token;
5902 const enum index *list;
5907 token = &token_list[ctx->curr];
5908 /* Check argument length. */
5911 for (len = 0; src[len]; ++len)
5912 if (src[len] == '#' || isspace(src[len]))
5916 /* Last argument and EOL detection. */
5917 for (i = len; src[i]; ++i)
5918 if (src[i] == '#' || src[i] == '\r' || src[i] == '\n')
5920 else if (!isspace(src[i])) {
5925 if (src[i] == '\r' || src[i] == '\n') {
5929 /* Initialize context if necessary. */
5930 if (!ctx->next_num) {
5933 ctx->next[ctx->next_num++] = token->next[0];
5935 /* Process argument through candidates. */
5936 ctx->prev = ctx->curr;
5937 list = ctx->next[ctx->next_num - 1];
5938 for (i = 0; list[i]; ++i) {
5939 const struct token *next = &token_list[list[i]];
5942 ctx->curr = list[i];
5944 tmp = next->call(ctx, next, src, len, result, size);
5946 tmp = parse_default(ctx, next, src, len, result, size);
5947 if (tmp == -1 || tmp != len)
5955 /* Push subsequent tokens if any. */
5957 for (i = 0; token->next[i]; ++i) {
5958 if (ctx->next_num == RTE_DIM(ctx->next))
5960 ctx->next[ctx->next_num++] = token->next[i];
5962 /* Push arguments if any. */
5964 for (i = 0; token->args[i]; ++i) {
5965 if (ctx->args_num == RTE_DIM(ctx->args))
5967 ctx->args[ctx->args_num++] = token->args[i];
5972 /** Return number of completion entries (cmdline API). */
5974 cmd_flow_complete_get_nb(cmdline_parse_token_hdr_t *hdr)
5976 struct context *ctx = &cmd_flow_context;
5977 const struct token *token = &token_list[ctx->curr];
5978 const enum index *list;
5982 /* Count number of tokens in current list. */
5984 list = ctx->next[ctx->next_num - 1];
5986 list = token->next[0];
5987 for (i = 0; list[i]; ++i)
5992 * If there is a single token, use its completion callback, otherwise
5993 * return the number of entries.
5995 token = &token_list[list[0]];
5996 if (i == 1 && token->comp) {
5997 /* Save index for cmd_flow_get_help(). */
5998 ctx->prev = list[0];
5999 return token->comp(ctx, token, 0, NULL, 0);
6004 /** Return a completion entry (cmdline API). */
6006 cmd_flow_complete_get_elt(cmdline_parse_token_hdr_t *hdr, int index,
6007 char *dst, unsigned int size)
6009 struct context *ctx = &cmd_flow_context;
6010 const struct token *token = &token_list[ctx->curr];
6011 const enum index *list;
6015 /* Count number of tokens in current list. */
6017 list = ctx->next[ctx->next_num - 1];
6019 list = token->next[0];
6020 for (i = 0; list[i]; ++i)
6024 /* If there is a single token, use its completion callback. */
6025 token = &token_list[list[0]];
6026 if (i == 1 && token->comp) {
6027 /* Save index for cmd_flow_get_help(). */
6028 ctx->prev = list[0];
6029 return token->comp(ctx, token, index, dst, size) < 0 ? -1 : 0;
6031 /* Otherwise make sure the index is valid and use defaults. */
6034 token = &token_list[list[index]];
6035 strlcpy(dst, token->name, size);
6036 /* Save index for cmd_flow_get_help(). */
6037 ctx->prev = list[index];
6041 /** Populate help strings for current token (cmdline API). */
6043 cmd_flow_get_help(cmdline_parse_token_hdr_t *hdr, char *dst, unsigned int size)
6045 struct context *ctx = &cmd_flow_context;
6046 const struct token *token = &token_list[ctx->prev];
6051 /* Set token type and update global help with details. */
6052 strlcpy(dst, (token->type ? token->type : "TOKEN"), size);
6054 cmd_flow.help_str = token->help;
6056 cmd_flow.help_str = token->name;
6060 /** Token definition template (cmdline API). */
6061 static struct cmdline_token_hdr cmd_flow_token_hdr = {
6062 .ops = &(struct cmdline_token_ops){
6063 .parse = cmd_flow_parse,
6064 .complete_get_nb = cmd_flow_complete_get_nb,
6065 .complete_get_elt = cmd_flow_complete_get_elt,
6066 .get_help = cmd_flow_get_help,
6071 /** Populate the next dynamic token. */
6073 cmd_flow_tok(cmdline_parse_token_hdr_t **hdr,
6074 cmdline_parse_token_hdr_t **hdr_inst)
6076 struct context *ctx = &cmd_flow_context;
6078 /* Always reinitialize context before requesting the first token. */
6079 if (!(hdr_inst - cmd_flow.tokens))
6080 cmd_flow_context_init(ctx);
6081 /* Return NULL when no more tokens are expected. */
6082 if (!ctx->next_num && ctx->curr) {
6086 /* Determine if command should end here. */
6087 if (ctx->eol && ctx->last && ctx->next_num) {
6088 const enum index *list = ctx->next[ctx->next_num - 1];
6091 for (i = 0; list[i]; ++i) {
6098 *hdr = &cmd_flow_token_hdr;
6101 /** Dispatch parsed buffer to function calls. */
6103 cmd_flow_parsed(const struct buffer *in)
6105 switch (in->command) {
6107 port_flow_validate(in->port, &in->args.vc.attr,
6108 in->args.vc.pattern, in->args.vc.actions);
6111 port_flow_create(in->port, &in->args.vc.attr,
6112 in->args.vc.pattern, in->args.vc.actions);
6115 port_flow_destroy(in->port, in->args.destroy.rule_n,
6116 in->args.destroy.rule);
6119 port_flow_flush(in->port);
6122 port_flow_query(in->port, in->args.query.rule,
6123 &in->args.query.action);
6126 port_flow_list(in->port, in->args.list.group_n,
6127 in->args.list.group);
6130 port_flow_isolate(in->port, in->args.isolate.set);
6137 /** Token generator and output processing callback (cmdline API). */
6139 cmd_flow_cb(void *arg0, struct cmdline *cl, void *arg2)
6142 cmd_flow_tok(arg0, arg2);
6144 cmd_flow_parsed(arg0);
6147 /** Global parser instance (cmdline API). */
6148 cmdline_parse_inst_t cmd_flow = {
6150 .data = NULL, /**< Unused. */
6151 .help_str = NULL, /**< Updated by cmd_flow_get_help(). */
6154 }, /**< Tokens are returned by cmd_flow_tok(). */
6157 /** set cmd facility. Reuse cmd flow's infrastructure as much as possible. */
6160 update_fields(uint8_t *buf, struct rte_flow_item *item, uint16_t next_proto)
6162 struct rte_flow_item_ipv4 *ipv4;
6163 struct rte_flow_item_eth *eth;
6164 struct rte_flow_item_ipv6 *ipv6;
6165 struct rte_flow_item_vxlan *vxlan;
6166 struct rte_flow_item_vxlan_gpe *gpe;
6167 struct rte_flow_item_nvgre *nvgre;
6168 uint32_t ipv6_vtc_flow;
6170 switch (item->type) {
6171 case RTE_FLOW_ITEM_TYPE_ETH:
6172 eth = (struct rte_flow_item_eth *)buf;
6174 eth->type = rte_cpu_to_be_16(next_proto);
6176 case RTE_FLOW_ITEM_TYPE_IPV4:
6177 ipv4 = (struct rte_flow_item_ipv4 *)buf;
6178 ipv4->hdr.version_ihl = 0x45;
6179 if (next_proto && ipv4->hdr.next_proto_id == 0)
6180 ipv4->hdr.next_proto_id = (uint8_t)next_proto;
6182 case RTE_FLOW_ITEM_TYPE_IPV6:
6183 ipv6 = (struct rte_flow_item_ipv6 *)buf;
6184 if (next_proto && ipv6->hdr.proto == 0)
6185 ipv6->hdr.proto = (uint8_t)next_proto;
6186 ipv6_vtc_flow = rte_be_to_cpu_32(ipv6->hdr.vtc_flow);
6187 ipv6_vtc_flow &= 0x0FFFFFFF; /*< reset version bits. */
6188 ipv6_vtc_flow |= 0x60000000; /*< set ipv6 version. */
6189 ipv6->hdr.vtc_flow = rte_cpu_to_be_32(ipv6_vtc_flow);
6191 case RTE_FLOW_ITEM_TYPE_VXLAN:
6192 vxlan = (struct rte_flow_item_vxlan *)buf;
6193 vxlan->flags = 0x08;
6195 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
6196 gpe = (struct rte_flow_item_vxlan_gpe *)buf;
6199 case RTE_FLOW_ITEM_TYPE_NVGRE:
6200 nvgre = (struct rte_flow_item_nvgre *)buf;
6201 nvgre->protocol = rte_cpu_to_be_16(0x6558);
6202 nvgre->c_k_s_rsvd0_ver = rte_cpu_to_be_16(0x2000);
6209 /** Helper of get item's default mask. */
6211 flow_item_default_mask(const struct rte_flow_item *item)
6213 const void *mask = NULL;
6214 static rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
6216 switch (item->type) {
6217 case RTE_FLOW_ITEM_TYPE_ANY:
6218 mask = &rte_flow_item_any_mask;
6220 case RTE_FLOW_ITEM_TYPE_VF:
6221 mask = &rte_flow_item_vf_mask;
6223 case RTE_FLOW_ITEM_TYPE_PORT_ID:
6224 mask = &rte_flow_item_port_id_mask;
6226 case RTE_FLOW_ITEM_TYPE_RAW:
6227 mask = &rte_flow_item_raw_mask;
6229 case RTE_FLOW_ITEM_TYPE_ETH:
6230 mask = &rte_flow_item_eth_mask;
6232 case RTE_FLOW_ITEM_TYPE_VLAN:
6233 mask = &rte_flow_item_vlan_mask;
6235 case RTE_FLOW_ITEM_TYPE_IPV4:
6236 mask = &rte_flow_item_ipv4_mask;
6238 case RTE_FLOW_ITEM_TYPE_IPV6:
6239 mask = &rte_flow_item_ipv6_mask;
6241 case RTE_FLOW_ITEM_TYPE_ICMP:
6242 mask = &rte_flow_item_icmp_mask;
6244 case RTE_FLOW_ITEM_TYPE_UDP:
6245 mask = &rte_flow_item_udp_mask;
6247 case RTE_FLOW_ITEM_TYPE_TCP:
6248 mask = &rte_flow_item_tcp_mask;
6250 case RTE_FLOW_ITEM_TYPE_SCTP:
6251 mask = &rte_flow_item_sctp_mask;
6253 case RTE_FLOW_ITEM_TYPE_VXLAN:
6254 mask = &rte_flow_item_vxlan_mask;
6256 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
6257 mask = &rte_flow_item_vxlan_gpe_mask;
6259 case RTE_FLOW_ITEM_TYPE_E_TAG:
6260 mask = &rte_flow_item_e_tag_mask;
6262 case RTE_FLOW_ITEM_TYPE_NVGRE:
6263 mask = &rte_flow_item_nvgre_mask;
6265 case RTE_FLOW_ITEM_TYPE_MPLS:
6266 mask = &rte_flow_item_mpls_mask;
6268 case RTE_FLOW_ITEM_TYPE_GRE:
6269 mask = &rte_flow_item_gre_mask;
6271 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
6272 mask = &gre_key_default_mask;
6274 case RTE_FLOW_ITEM_TYPE_META:
6275 mask = &rte_flow_item_meta_mask;
6277 case RTE_FLOW_ITEM_TYPE_FUZZY:
6278 mask = &rte_flow_item_fuzzy_mask;
6280 case RTE_FLOW_ITEM_TYPE_GTP:
6281 mask = &rte_flow_item_gtp_mask;
6283 case RTE_FLOW_ITEM_TYPE_ESP:
6284 mask = &rte_flow_item_esp_mask;
6286 case RTE_FLOW_ITEM_TYPE_GTP_PSC:
6287 mask = &rte_flow_item_gtp_psc_mask;
6289 case RTE_FLOW_ITEM_TYPE_GENEVE:
6290 mask = &rte_flow_item_geneve_mask;
6292 case RTE_FLOW_ITEM_TYPE_PPPOE_PROTO_ID:
6293 mask = &rte_flow_item_pppoe_proto_id_mask;
6302 /** Dispatch parsed buffer to function calls. */
6304 cmd_set_raw_parsed(const struct buffer *in)
6306 uint32_t n = in->args.vc.pattern_n;
6308 struct rte_flow_item *item = NULL;
6310 uint8_t *data = NULL;
6311 uint8_t *data_tail = NULL;
6312 size_t *total_size = NULL;
6313 uint16_t upper_layer = 0;
6315 uint16_t idx = in->port; /* We borrow port field as index */
6317 RTE_ASSERT(in->command == SET_RAW_ENCAP ||
6318 in->command == SET_RAW_DECAP);
6319 if (in->command == SET_RAW_ENCAP) {
6320 total_size = &raw_encap_confs[idx].size;
6321 data = (uint8_t *)&raw_encap_confs[idx].data;
6323 total_size = &raw_decap_confs[idx].size;
6324 data = (uint8_t *)&raw_decap_confs[idx].data;
6327 memset(data, 0x00, ACTION_RAW_ENCAP_MAX_DATA);
6328 /* process hdr from upper layer to low layer (L3/L4 -> L2). */
6329 data_tail = data + ACTION_RAW_ENCAP_MAX_DATA;
6330 for (i = n - 1 ; i >= 0; --i) {
6331 item = in->args.vc.pattern + i;
6332 if (item->spec == NULL)
6333 item->spec = flow_item_default_mask(item);
6334 switch (item->type) {
6335 case RTE_FLOW_ITEM_TYPE_ETH:
6336 size = sizeof(struct rte_flow_item_eth);
6338 case RTE_FLOW_ITEM_TYPE_VLAN:
6339 size = sizeof(struct rte_flow_item_vlan);
6340 proto = RTE_ETHER_TYPE_VLAN;
6342 case RTE_FLOW_ITEM_TYPE_IPV4:
6343 size = sizeof(struct rte_flow_item_ipv4);
6344 proto = RTE_ETHER_TYPE_IPV4;
6346 case RTE_FLOW_ITEM_TYPE_IPV6:
6347 size = sizeof(struct rte_flow_item_ipv6);
6348 proto = RTE_ETHER_TYPE_IPV6;
6350 case RTE_FLOW_ITEM_TYPE_UDP:
6351 size = sizeof(struct rte_flow_item_udp);
6354 case RTE_FLOW_ITEM_TYPE_TCP:
6355 size = sizeof(struct rte_flow_item_tcp);
6358 case RTE_FLOW_ITEM_TYPE_VXLAN:
6359 size = sizeof(struct rte_flow_item_vxlan);
6361 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
6362 size = sizeof(struct rte_flow_item_vxlan_gpe);
6364 case RTE_FLOW_ITEM_TYPE_GRE:
6365 size = sizeof(struct rte_flow_item_gre);
6368 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
6369 size = sizeof(rte_be32_t);
6372 case RTE_FLOW_ITEM_TYPE_MPLS:
6373 size = sizeof(struct rte_flow_item_mpls);
6376 case RTE_FLOW_ITEM_TYPE_NVGRE:
6377 size = sizeof(struct rte_flow_item_nvgre);
6380 case RTE_FLOW_ITEM_TYPE_GENEVE:
6381 size = sizeof(struct rte_flow_item_geneve);
6384 printf("Error - Not supported item\n");
6386 memset(data, 0x00, ACTION_RAW_ENCAP_MAX_DATA);
6389 *total_size += size;
6390 rte_memcpy(data_tail - (*total_size), item->spec, size);
6391 /* update some fields which cannot be set by cmdline */
6392 update_fields((data_tail - (*total_size)), item,
6394 upper_layer = proto;
6396 if (verbose_level & 0x1)
6397 printf("total data size is %zu\n", (*total_size));
6398 RTE_ASSERT((*total_size) <= ACTION_RAW_ENCAP_MAX_DATA);
6399 memmove(data, (data_tail - (*total_size)), *total_size);
6402 /** Populate help strings for current token (cmdline API). */
6404 cmd_set_raw_get_help(cmdline_parse_token_hdr_t *hdr, char *dst,
6407 struct context *ctx = &cmd_flow_context;
6408 const struct token *token = &token_list[ctx->prev];
6413 /* Set token type and update global help with details. */
6414 snprintf(dst, size, "%s", (token->type ? token->type : "TOKEN"));
6416 cmd_set_raw.help_str = token->help;
6418 cmd_set_raw.help_str = token->name;
6422 /** Token definition template (cmdline API). */
6423 static struct cmdline_token_hdr cmd_set_raw_token_hdr = {
6424 .ops = &(struct cmdline_token_ops){
6425 .parse = cmd_flow_parse,
6426 .complete_get_nb = cmd_flow_complete_get_nb,
6427 .complete_get_elt = cmd_flow_complete_get_elt,
6428 .get_help = cmd_set_raw_get_help,
6433 /** Populate the next dynamic token. */
6435 cmd_set_raw_tok(cmdline_parse_token_hdr_t **hdr,
6436 cmdline_parse_token_hdr_t **hdr_inst)
6438 struct context *ctx = &cmd_flow_context;
6440 /* Always reinitialize context before requesting the first token. */
6441 if (!(hdr_inst - cmd_set_raw.tokens)) {
6442 cmd_flow_context_init(ctx);
6443 ctx->curr = START_SET;
6445 /* Return NULL when no more tokens are expected. */
6446 if (!ctx->next_num && (ctx->curr != START_SET)) {
6450 /* Determine if command should end here. */
6451 if (ctx->eol && ctx->last && ctx->next_num) {
6452 const enum index *list = ctx->next[ctx->next_num - 1];
6455 for (i = 0; list[i]; ++i) {
6462 *hdr = &cmd_set_raw_token_hdr;
6465 /** Token generator and output processing callback (cmdline API). */
6467 cmd_set_raw_cb(void *arg0, struct cmdline *cl, void *arg2)
6470 cmd_set_raw_tok(arg0, arg2);
6472 cmd_set_raw_parsed(arg0);
6475 /** Global parser instance (cmdline API). */
6476 cmdline_parse_inst_t cmd_set_raw = {
6477 .f = cmd_set_raw_cb,
6478 .data = NULL, /**< Unused. */
6479 .help_str = NULL, /**< Updated by cmd_flow_get_help(). */
6482 }, /**< Tokens are returned by cmd_flow_tok(). */
6485 /* *** display raw_encap/raw_decap buf */
6486 struct cmd_show_set_raw_result {
6487 cmdline_fixed_string_t cmd_show;
6488 cmdline_fixed_string_t cmd_what;
6489 cmdline_fixed_string_t cmd_all;
6494 cmd_show_set_raw_parsed(void *parsed_result, struct cmdline *cl, void *data)
6496 struct cmd_show_set_raw_result *res = parsed_result;
6497 uint16_t index = res->cmd_index;
6499 uint8_t *raw_data = NULL;
6500 size_t raw_size = 0;
6501 char title[16] = {0};
6505 if (!strcmp(res->cmd_all, "all")) {
6508 } else if (index >= RAW_ENCAP_CONFS_MAX_NUM) {
6509 printf("index should be 0-%u\n", RAW_ENCAP_CONFS_MAX_NUM - 1);
6513 if (!strcmp(res->cmd_what, "raw_encap")) {
6514 raw_data = (uint8_t *)&raw_encap_confs[index].data;
6515 raw_size = raw_encap_confs[index].size;
6516 snprintf(title, 16, "\nindex: %u", index);
6517 rte_hexdump(stdout, title, raw_data, raw_size);
6519 raw_data = (uint8_t *)&raw_decap_confs[index].data;
6520 raw_size = raw_decap_confs[index].size;
6521 snprintf(title, 16, "\nindex: %u", index);
6522 rte_hexdump(stdout, title, raw_data, raw_size);
6524 } while (all && ++index < RAW_ENCAP_CONFS_MAX_NUM);
6527 cmdline_parse_token_string_t cmd_show_set_raw_cmd_show =
6528 TOKEN_STRING_INITIALIZER(struct cmd_show_set_raw_result,
6530 cmdline_parse_token_string_t cmd_show_set_raw_cmd_what =
6531 TOKEN_STRING_INITIALIZER(struct cmd_show_set_raw_result,
6532 cmd_what, "raw_encap#raw_decap");
6533 cmdline_parse_token_num_t cmd_show_set_raw_cmd_index =
6534 TOKEN_NUM_INITIALIZER(struct cmd_show_set_raw_result,
6536 cmdline_parse_token_string_t cmd_show_set_raw_cmd_all =
6537 TOKEN_STRING_INITIALIZER(struct cmd_show_set_raw_result,
6539 cmdline_parse_inst_t cmd_show_set_raw = {
6540 .f = cmd_show_set_raw_parsed,
6542 .help_str = "show <raw_encap|raw_decap> <index>",
6544 (void *)&cmd_show_set_raw_cmd_show,
6545 (void *)&cmd_show_set_raw_cmd_what,
6546 (void *)&cmd_show_set_raw_cmd_index,
6550 cmdline_parse_inst_t cmd_show_set_raw_all = {
6551 .f = cmd_show_set_raw_parsed,
6553 .help_str = "show <raw_encap|raw_decap> all",
6555 (void *)&cmd_show_set_raw_cmd_show,
6556 (void *)&cmd_show_set_raw_cmd_what,
6557 (void *)&cmd_show_set_raw_cmd_all,