1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2016 6WIND S.A.
3 * Copyright 2016 Mellanox Technologies, Ltd
13 #include <arpa/inet.h>
14 #include <sys/socket.h>
16 #include <rte_string_fns.h>
17 #include <rte_common.h>
18 #include <rte_ethdev.h>
19 #include <rte_byteorder.h>
20 #include <cmdline_parse.h>
21 #include <cmdline_parse_etheraddr.h>
22 #include <cmdline_parse_string.h>
23 #include <cmdline_parse_num.h>
25 #include <rte_hexdump.h>
29 /** Parser token indices. */
53 /* Top-level command. */
55 /* Sub-leve commands. */
60 /* Top-level command. */
62 /* Sub-level commands. */
73 /* Destroy arguments. */
76 /* Query arguments. */
82 /* Destroy aged flow arguments. */
85 /* Validate/create arguments. */
92 /* Validate/create pattern. */
129 ITEM_VLAN_INNER_TYPE,
161 ITEM_E_TAG_GRP_ECID_B,
170 ITEM_GRE_C_RSVD0_VER,
188 ITEM_ARP_ETH_IPV4_SHA,
189 ITEM_ARP_ETH_IPV4_SPA,
190 ITEM_ARP_ETH_IPV4_THA,
191 ITEM_ARP_ETH_IPV4_TPA,
193 ITEM_IPV6_EXT_NEXT_HDR,
198 ITEM_ICMP6_ND_NS_TARGET_ADDR,
200 ITEM_ICMP6_ND_NA_TARGET_ADDR,
202 ITEM_ICMP6_ND_OPT_TYPE,
203 ITEM_ICMP6_ND_OPT_SLA_ETH,
204 ITEM_ICMP6_ND_OPT_SLA_ETH_SLA,
205 ITEM_ICMP6_ND_OPT_TLA_ETH,
206 ITEM_ICMP6_ND_OPT_TLA_ETH_TLA,
219 ITEM_HIGIG2_CLASSIFICATION,
225 ITEM_L2TPV3OIP_SESSION_ID,
234 /* Validate/create actions. */
254 ACTION_RSS_FUNC_DEFAULT,
255 ACTION_RSS_FUNC_TOEPLITZ,
256 ACTION_RSS_FUNC_SIMPLE_XOR,
257 ACTION_RSS_FUNC_SYMMETRIC_TOEPLITZ,
269 ACTION_PHY_PORT_ORIGINAL,
270 ACTION_PHY_PORT_INDEX,
272 ACTION_PORT_ID_ORIGINAL,
276 ACTION_OF_SET_MPLS_TTL,
277 ACTION_OF_SET_MPLS_TTL_MPLS_TTL,
278 ACTION_OF_DEC_MPLS_TTL,
279 ACTION_OF_SET_NW_TTL,
280 ACTION_OF_SET_NW_TTL_NW_TTL,
281 ACTION_OF_DEC_NW_TTL,
282 ACTION_OF_COPY_TTL_OUT,
283 ACTION_OF_COPY_TTL_IN,
286 ACTION_OF_PUSH_VLAN_ETHERTYPE,
287 ACTION_OF_SET_VLAN_VID,
288 ACTION_OF_SET_VLAN_VID_VLAN_VID,
289 ACTION_OF_SET_VLAN_PCP,
290 ACTION_OF_SET_VLAN_PCP_VLAN_PCP,
292 ACTION_OF_POP_MPLS_ETHERTYPE,
294 ACTION_OF_PUSH_MPLS_ETHERTYPE,
301 ACTION_MPLSOGRE_ENCAP,
302 ACTION_MPLSOGRE_DECAP,
303 ACTION_MPLSOUDP_ENCAP,
304 ACTION_MPLSOUDP_DECAP,
306 ACTION_SET_IPV4_SRC_IPV4_SRC,
308 ACTION_SET_IPV4_DST_IPV4_DST,
310 ACTION_SET_IPV6_SRC_IPV6_SRC,
312 ACTION_SET_IPV6_DST_IPV6_DST,
314 ACTION_SET_TP_SRC_TP_SRC,
316 ACTION_SET_TP_DST_TP_DST,
322 ACTION_SET_MAC_SRC_MAC_SRC,
324 ACTION_SET_MAC_DST_MAC_DST,
326 ACTION_INC_TCP_SEQ_VALUE,
328 ACTION_DEC_TCP_SEQ_VALUE,
330 ACTION_INC_TCP_ACK_VALUE,
332 ACTION_DEC_TCP_ACK_VALUE,
335 ACTION_RAW_ENCAP_INDEX,
336 ACTION_RAW_ENCAP_INDEX_VALUE,
337 ACTION_RAW_DECAP_INDEX,
338 ACTION_RAW_DECAP_INDEX_VALUE,
341 ACTION_SET_TAG_INDEX,
344 ACTION_SET_META_DATA,
345 ACTION_SET_META_MASK,
346 ACTION_SET_IPV4_DSCP,
347 ACTION_SET_IPV4_DSCP_VALUE,
348 ACTION_SET_IPV6_DSCP,
349 ACTION_SET_IPV6_DSCP_VALUE,
354 /** Maximum size for pattern in struct rte_flow_item_raw. */
355 #define ITEM_RAW_PATTERN_SIZE 40
357 /** Storage size for struct rte_flow_item_raw including pattern. */
358 #define ITEM_RAW_SIZE \
359 (sizeof(struct rte_flow_item_raw) + ITEM_RAW_PATTERN_SIZE)
361 /** Maximum number of queue indices in struct rte_flow_action_rss. */
362 #define ACTION_RSS_QUEUE_NUM 128
364 /** Storage for struct rte_flow_action_rss including external data. */
365 struct action_rss_data {
366 struct rte_flow_action_rss conf;
367 uint8_t key[RSS_HASH_KEY_LENGTH];
368 uint16_t queue[ACTION_RSS_QUEUE_NUM];
371 /** Maximum data size in struct rte_flow_action_raw_encap. */
372 #define ACTION_RAW_ENCAP_MAX_DATA 128
373 #define RAW_ENCAP_CONFS_MAX_NUM 8
375 /** Storage for struct rte_flow_action_raw_encap. */
376 struct raw_encap_conf {
377 uint8_t data[ACTION_RAW_ENCAP_MAX_DATA];
378 uint8_t preserve[ACTION_RAW_ENCAP_MAX_DATA];
382 struct raw_encap_conf raw_encap_confs[RAW_ENCAP_CONFS_MAX_NUM];
384 /** Storage for struct rte_flow_action_raw_encap including external data. */
385 struct action_raw_encap_data {
386 struct rte_flow_action_raw_encap conf;
387 uint8_t data[ACTION_RAW_ENCAP_MAX_DATA];
388 uint8_t preserve[ACTION_RAW_ENCAP_MAX_DATA];
392 /** Storage for struct rte_flow_action_raw_decap. */
393 struct raw_decap_conf {
394 uint8_t data[ACTION_RAW_ENCAP_MAX_DATA];
398 struct raw_decap_conf raw_decap_confs[RAW_ENCAP_CONFS_MAX_NUM];
400 /** Storage for struct rte_flow_action_raw_decap including external data. */
401 struct action_raw_decap_data {
402 struct rte_flow_action_raw_decap conf;
403 uint8_t data[ACTION_RAW_ENCAP_MAX_DATA];
407 struct vxlan_encap_conf vxlan_encap_conf = {
411 .vni = "\x00\x00\x00",
413 .udp_dst = RTE_BE16(4789),
414 .ipv4_src = RTE_IPV4(127, 0, 0, 1),
415 .ipv4_dst = RTE_IPV4(255, 255, 255, 255),
416 .ipv6_src = "\x00\x00\x00\x00\x00\x00\x00\x00"
417 "\x00\x00\x00\x00\x00\x00\x00\x01",
418 .ipv6_dst = "\x00\x00\x00\x00\x00\x00\x00\x00"
419 "\x00\x00\x00\x00\x00\x00\x11\x11",
423 .eth_src = "\x00\x00\x00\x00\x00\x00",
424 .eth_dst = "\xff\xff\xff\xff\xff\xff",
427 /** Maximum number of items in struct rte_flow_action_vxlan_encap. */
428 #define ACTION_VXLAN_ENCAP_ITEMS_NUM 6
430 /** Storage for struct rte_flow_action_vxlan_encap including external data. */
431 struct action_vxlan_encap_data {
432 struct rte_flow_action_vxlan_encap conf;
433 struct rte_flow_item items[ACTION_VXLAN_ENCAP_ITEMS_NUM];
434 struct rte_flow_item_eth item_eth;
435 struct rte_flow_item_vlan item_vlan;
437 struct rte_flow_item_ipv4 item_ipv4;
438 struct rte_flow_item_ipv6 item_ipv6;
440 struct rte_flow_item_udp item_udp;
441 struct rte_flow_item_vxlan item_vxlan;
444 struct nvgre_encap_conf nvgre_encap_conf = {
447 .tni = "\x00\x00\x00",
448 .ipv4_src = RTE_IPV4(127, 0, 0, 1),
449 .ipv4_dst = RTE_IPV4(255, 255, 255, 255),
450 .ipv6_src = "\x00\x00\x00\x00\x00\x00\x00\x00"
451 "\x00\x00\x00\x00\x00\x00\x00\x01",
452 .ipv6_dst = "\x00\x00\x00\x00\x00\x00\x00\x00"
453 "\x00\x00\x00\x00\x00\x00\x11\x11",
455 .eth_src = "\x00\x00\x00\x00\x00\x00",
456 .eth_dst = "\xff\xff\xff\xff\xff\xff",
459 /** Maximum number of items in struct rte_flow_action_nvgre_encap. */
460 #define ACTION_NVGRE_ENCAP_ITEMS_NUM 5
462 /** Storage for struct rte_flow_action_nvgre_encap including external data. */
463 struct action_nvgre_encap_data {
464 struct rte_flow_action_nvgre_encap conf;
465 struct rte_flow_item items[ACTION_NVGRE_ENCAP_ITEMS_NUM];
466 struct rte_flow_item_eth item_eth;
467 struct rte_flow_item_vlan item_vlan;
469 struct rte_flow_item_ipv4 item_ipv4;
470 struct rte_flow_item_ipv6 item_ipv6;
472 struct rte_flow_item_nvgre item_nvgre;
475 struct l2_encap_conf l2_encap_conf;
477 struct l2_decap_conf l2_decap_conf;
479 struct mplsogre_encap_conf mplsogre_encap_conf;
481 struct mplsogre_decap_conf mplsogre_decap_conf;
483 struct mplsoudp_encap_conf mplsoudp_encap_conf;
485 struct mplsoudp_decap_conf mplsoudp_decap_conf;
487 /** Maximum number of subsequent tokens and arguments on the stack. */
488 #define CTX_STACK_SIZE 16
490 /** Parser context. */
492 /** Stack of subsequent token lists to process. */
493 const enum index *next[CTX_STACK_SIZE];
494 /** Arguments for stacked tokens. */
495 const void *args[CTX_STACK_SIZE];
496 enum index curr; /**< Current token index. */
497 enum index prev; /**< Index of the last token seen. */
498 int next_num; /**< Number of entries in next[]. */
499 int args_num; /**< Number of entries in args[]. */
500 uint32_t eol:1; /**< EOL has been detected. */
501 uint32_t last:1; /**< No more arguments. */
502 portid_t port; /**< Current port ID (for completions). */
503 uint32_t objdata; /**< Object-specific data. */
504 void *object; /**< Address of current object for relative offsets. */
505 void *objmask; /**< Object a full mask must be written to. */
508 /** Token argument. */
510 uint32_t hton:1; /**< Use network byte ordering. */
511 uint32_t sign:1; /**< Value is signed. */
512 uint32_t bounded:1; /**< Value is bounded. */
513 uintmax_t min; /**< Minimum value if bounded. */
514 uintmax_t max; /**< Maximum value if bounded. */
515 uint32_t offset; /**< Relative offset from ctx->object. */
516 uint32_t size; /**< Field size. */
517 const uint8_t *mask; /**< Bit-mask to use instead of offset/size. */
520 /** Parser token definition. */
522 /** Type displayed during completion (defaults to "TOKEN"). */
524 /** Help displayed during completion (defaults to token name). */
526 /** Private data used by parser functions. */
529 * Lists of subsequent tokens to push on the stack. Each call to the
530 * parser consumes the last entry of that stack.
532 const enum index *const *next;
533 /** Arguments stack for subsequent tokens that need them. */
534 const struct arg *const *args;
536 * Token-processing callback, returns -1 in case of error, the
537 * length of the matched string otherwise. If NULL, attempts to
538 * match the token name.
540 * If buf is not NULL, the result should be stored in it according
541 * to context. An error is returned if not large enough.
543 int (*call)(struct context *ctx, const struct token *token,
544 const char *str, unsigned int len,
545 void *buf, unsigned int size);
547 * Callback that provides possible values for this token, used for
548 * completion. Returns -1 in case of error, the number of possible
549 * values otherwise. If NULL, the token name is used.
551 * If buf is not NULL, entry index ent is written to buf and the
552 * full length of the entry is returned (same behavior as
555 int (*comp)(struct context *ctx, const struct token *token,
556 unsigned int ent, char *buf, unsigned int size);
557 /** Mandatory token name, no default value. */
561 /** Static initializer for the next field. */
562 #define NEXT(...) (const enum index *const []){ __VA_ARGS__, NULL, }
564 /** Static initializer for a NEXT() entry. */
565 #define NEXT_ENTRY(...) (const enum index []){ __VA_ARGS__, ZERO, }
567 /** Static initializer for the args field. */
568 #define ARGS(...) (const struct arg *const []){ __VA_ARGS__, NULL, }
570 /** Static initializer for ARGS() to target a field. */
571 #define ARGS_ENTRY(s, f) \
572 (&(const struct arg){ \
573 .offset = offsetof(s, f), \
574 .size = sizeof(((s *)0)->f), \
577 /** Static initializer for ARGS() to target a bit-field. */
578 #define ARGS_ENTRY_BF(s, f, b) \
579 (&(const struct arg){ \
581 .mask = (const void *)&(const s){ .f = (1 << (b)) - 1 }, \
584 /** Static initializer for ARGS() to target an arbitrary bit-mask. */
585 #define ARGS_ENTRY_MASK(s, f, m) \
586 (&(const struct arg){ \
587 .offset = offsetof(s, f), \
588 .size = sizeof(((s *)0)->f), \
589 .mask = (const void *)(m), \
592 /** Same as ARGS_ENTRY_MASK() using network byte ordering for the value. */
593 #define ARGS_ENTRY_MASK_HTON(s, f, m) \
594 (&(const struct arg){ \
596 .offset = offsetof(s, f), \
597 .size = sizeof(((s *)0)->f), \
598 .mask = (const void *)(m), \
601 /** Static initializer for ARGS() to target a pointer. */
602 #define ARGS_ENTRY_PTR(s, f) \
603 (&(const struct arg){ \
604 .size = sizeof(*((s *)0)->f), \
607 /** Static initializer for ARGS() with arbitrary offset and size. */
608 #define ARGS_ENTRY_ARB(o, s) \
609 (&(const struct arg){ \
614 /** Same as ARGS_ENTRY_ARB() with bounded values. */
615 #define ARGS_ENTRY_ARB_BOUNDED(o, s, i, a) \
616 (&(const struct arg){ \
624 /** Same as ARGS_ENTRY() using network byte ordering. */
625 #define ARGS_ENTRY_HTON(s, f) \
626 (&(const struct arg){ \
628 .offset = offsetof(s, f), \
629 .size = sizeof(((s *)0)->f), \
632 /** Same as ARGS_ENTRY_HTON() for a single argument, without structure. */
633 #define ARG_ENTRY_HTON(s) \
634 (&(const struct arg){ \
640 /** Parser output buffer layout expected by cmd_flow_parsed(). */
642 enum index command; /**< Flow command. */
643 portid_t port; /**< Affected port ID. */
646 struct rte_flow_attr attr;
647 struct rte_flow_item *pattern;
648 struct rte_flow_action *actions;
652 } vc; /**< Validate/create arguments. */
656 } destroy; /**< Destroy arguments. */
659 } dump; /**< Dump arguments. */
662 struct rte_flow_action action;
663 } query; /**< Query arguments. */
667 } list; /**< List arguments. */
670 } isolate; /**< Isolated mode arguments. */
673 } aged; /**< Aged arguments. */
674 } args; /**< Command arguments. */
677 /** Private data for pattern items. */
678 struct parse_item_priv {
679 enum rte_flow_item_type type; /**< Item type. */
680 uint32_t size; /**< Size of item specification structure. */
683 #define PRIV_ITEM(t, s) \
684 (&(const struct parse_item_priv){ \
685 .type = RTE_FLOW_ITEM_TYPE_ ## t, \
689 /** Private data for actions. */
690 struct parse_action_priv {
691 enum rte_flow_action_type type; /**< Action type. */
692 uint32_t size; /**< Size of action configuration structure. */
695 #define PRIV_ACTION(t, s) \
696 (&(const struct parse_action_priv){ \
697 .type = RTE_FLOW_ACTION_TYPE_ ## t, \
701 static const enum index next_vc_attr[] = {
711 static const enum index next_destroy_attr[] = {
717 static const enum index next_dump_attr[] = {
723 static const enum index next_list_attr[] = {
729 static const enum index next_aged_attr[] = {
735 static const enum index item_param[] = {
744 static const enum index next_item[] = {
780 ITEM_ICMP6_ND_OPT_SLA_ETH,
781 ITEM_ICMP6_ND_OPT_TLA_ETH,
798 static const enum index item_fuzzy[] = {
804 static const enum index item_any[] = {
810 static const enum index item_vf[] = {
816 static const enum index item_phy_port[] = {
822 static const enum index item_port_id[] = {
828 static const enum index item_mark[] = {
834 static const enum index item_raw[] = {
844 static const enum index item_eth[] = {
852 static const enum index item_vlan[] = {
857 ITEM_VLAN_INNER_TYPE,
862 static const enum index item_ipv4[] = {
872 static const enum index item_ipv6[] = {
883 static const enum index item_icmp[] = {
890 static const enum index item_udp[] = {
897 static const enum index item_tcp[] = {
905 static const enum index item_sctp[] = {
914 static const enum index item_vxlan[] = {
920 static const enum index item_e_tag[] = {
921 ITEM_E_TAG_GRP_ECID_B,
926 static const enum index item_nvgre[] = {
932 static const enum index item_mpls[] = {
940 static const enum index item_gre[] = {
942 ITEM_GRE_C_RSVD0_VER,
950 static const enum index item_gre_key[] = {
956 static const enum index item_gtp[] = {
964 static const enum index item_geneve[] = {
971 static const enum index item_vxlan_gpe[] = {
977 static const enum index item_arp_eth_ipv4[] = {
978 ITEM_ARP_ETH_IPV4_SHA,
979 ITEM_ARP_ETH_IPV4_SPA,
980 ITEM_ARP_ETH_IPV4_THA,
981 ITEM_ARP_ETH_IPV4_TPA,
986 static const enum index item_ipv6_ext[] = {
987 ITEM_IPV6_EXT_NEXT_HDR,
992 static const enum index item_icmp6[] = {
999 static const enum index item_icmp6_nd_ns[] = {
1000 ITEM_ICMP6_ND_NS_TARGET_ADDR,
1005 static const enum index item_icmp6_nd_na[] = {
1006 ITEM_ICMP6_ND_NA_TARGET_ADDR,
1011 static const enum index item_icmp6_nd_opt[] = {
1012 ITEM_ICMP6_ND_OPT_TYPE,
1017 static const enum index item_icmp6_nd_opt_sla_eth[] = {
1018 ITEM_ICMP6_ND_OPT_SLA_ETH_SLA,
1023 static const enum index item_icmp6_nd_opt_tla_eth[] = {
1024 ITEM_ICMP6_ND_OPT_TLA_ETH_TLA,
1029 static const enum index item_meta[] = {
1035 static const enum index item_gtp_psc[] = {
1042 static const enum index item_pppoed[] = {
1048 static const enum index item_pppoes[] = {
1054 static const enum index item_pppoe_proto_id[] = {
1059 static const enum index item_higig2[] = {
1060 ITEM_HIGIG2_CLASSIFICATION,
1066 static const enum index item_esp[] = {
1072 static const enum index item_ah[] = {
1078 static const enum index item_pfcp[] = {
1085 static const enum index next_set_raw[] = {
1091 static const enum index item_tag[] = {
1098 static const enum index item_l2tpv3oip[] = {
1099 ITEM_L2TPV3OIP_SESSION_ID,
1104 static const enum index next_action[] = {
1120 ACTION_OF_SET_MPLS_TTL,
1121 ACTION_OF_DEC_MPLS_TTL,
1122 ACTION_OF_SET_NW_TTL,
1123 ACTION_OF_DEC_NW_TTL,
1124 ACTION_OF_COPY_TTL_OUT,
1125 ACTION_OF_COPY_TTL_IN,
1127 ACTION_OF_PUSH_VLAN,
1128 ACTION_OF_SET_VLAN_VID,
1129 ACTION_OF_SET_VLAN_PCP,
1131 ACTION_OF_PUSH_MPLS,
1138 ACTION_MPLSOGRE_ENCAP,
1139 ACTION_MPLSOGRE_DECAP,
1140 ACTION_MPLSOUDP_ENCAP,
1141 ACTION_MPLSOUDP_DECAP,
1142 ACTION_SET_IPV4_SRC,
1143 ACTION_SET_IPV4_DST,
1144 ACTION_SET_IPV6_SRC,
1145 ACTION_SET_IPV6_DST,
1161 ACTION_SET_IPV4_DSCP,
1162 ACTION_SET_IPV6_DSCP,
1167 static const enum index action_mark[] = {
1173 static const enum index action_queue[] = {
1179 static const enum index action_count[] = {
1181 ACTION_COUNT_SHARED,
1186 static const enum index action_rss[] = {
1197 static const enum index action_vf[] = {
1204 static const enum index action_phy_port[] = {
1205 ACTION_PHY_PORT_ORIGINAL,
1206 ACTION_PHY_PORT_INDEX,
1211 static const enum index action_port_id[] = {
1212 ACTION_PORT_ID_ORIGINAL,
1218 static const enum index action_meter[] = {
1224 static const enum index action_of_set_mpls_ttl[] = {
1225 ACTION_OF_SET_MPLS_TTL_MPLS_TTL,
1230 static const enum index action_of_set_nw_ttl[] = {
1231 ACTION_OF_SET_NW_TTL_NW_TTL,
1236 static const enum index action_of_push_vlan[] = {
1237 ACTION_OF_PUSH_VLAN_ETHERTYPE,
1242 static const enum index action_of_set_vlan_vid[] = {
1243 ACTION_OF_SET_VLAN_VID_VLAN_VID,
1248 static const enum index action_of_set_vlan_pcp[] = {
1249 ACTION_OF_SET_VLAN_PCP_VLAN_PCP,
1254 static const enum index action_of_pop_mpls[] = {
1255 ACTION_OF_POP_MPLS_ETHERTYPE,
1260 static const enum index action_of_push_mpls[] = {
1261 ACTION_OF_PUSH_MPLS_ETHERTYPE,
1266 static const enum index action_set_ipv4_src[] = {
1267 ACTION_SET_IPV4_SRC_IPV4_SRC,
1272 static const enum index action_set_mac_src[] = {
1273 ACTION_SET_MAC_SRC_MAC_SRC,
1278 static const enum index action_set_ipv4_dst[] = {
1279 ACTION_SET_IPV4_DST_IPV4_DST,
1284 static const enum index action_set_ipv6_src[] = {
1285 ACTION_SET_IPV6_SRC_IPV6_SRC,
1290 static const enum index action_set_ipv6_dst[] = {
1291 ACTION_SET_IPV6_DST_IPV6_DST,
1296 static const enum index action_set_tp_src[] = {
1297 ACTION_SET_TP_SRC_TP_SRC,
1302 static const enum index action_set_tp_dst[] = {
1303 ACTION_SET_TP_DST_TP_DST,
1308 static const enum index action_set_ttl[] = {
1314 static const enum index action_jump[] = {
1320 static const enum index action_set_mac_dst[] = {
1321 ACTION_SET_MAC_DST_MAC_DST,
1326 static const enum index action_inc_tcp_seq[] = {
1327 ACTION_INC_TCP_SEQ_VALUE,
1332 static const enum index action_dec_tcp_seq[] = {
1333 ACTION_DEC_TCP_SEQ_VALUE,
1338 static const enum index action_inc_tcp_ack[] = {
1339 ACTION_INC_TCP_ACK_VALUE,
1344 static const enum index action_dec_tcp_ack[] = {
1345 ACTION_DEC_TCP_ACK_VALUE,
1350 static const enum index action_raw_encap[] = {
1351 ACTION_RAW_ENCAP_INDEX,
1356 static const enum index action_raw_decap[] = {
1357 ACTION_RAW_DECAP_INDEX,
1362 static const enum index action_set_tag[] = {
1363 ACTION_SET_TAG_DATA,
1364 ACTION_SET_TAG_INDEX,
1365 ACTION_SET_TAG_MASK,
1370 static const enum index action_set_meta[] = {
1371 ACTION_SET_META_DATA,
1372 ACTION_SET_META_MASK,
1377 static const enum index action_set_ipv4_dscp[] = {
1378 ACTION_SET_IPV4_DSCP_VALUE,
1383 static const enum index action_set_ipv6_dscp[] = {
1384 ACTION_SET_IPV6_DSCP_VALUE,
1389 static const enum index action_age[] = {
1396 static int parse_set_raw_encap_decap(struct context *, const struct token *,
1397 const char *, unsigned int,
1398 void *, unsigned int);
1399 static int parse_set_init(struct context *, const struct token *,
1400 const char *, unsigned int,
1401 void *, unsigned int);
1402 static int parse_init(struct context *, const struct token *,
1403 const char *, unsigned int,
1404 void *, unsigned int);
1405 static int parse_vc(struct context *, const struct token *,
1406 const char *, unsigned int,
1407 void *, unsigned int);
1408 static int parse_vc_spec(struct context *, const struct token *,
1409 const char *, unsigned int, void *, unsigned int);
1410 static int parse_vc_conf(struct context *, const struct token *,
1411 const char *, unsigned int, void *, unsigned int);
1412 static int parse_vc_action_rss(struct context *, const struct token *,
1413 const char *, unsigned int, void *,
1415 static int parse_vc_action_rss_func(struct context *, const struct token *,
1416 const char *, unsigned int, void *,
1418 static int parse_vc_action_rss_type(struct context *, const struct token *,
1419 const char *, unsigned int, void *,
1421 static int parse_vc_action_rss_queue(struct context *, const struct token *,
1422 const char *, unsigned int, void *,
1424 static int parse_vc_action_vxlan_encap(struct context *, const struct token *,
1425 const char *, unsigned int, void *,
1427 static int parse_vc_action_nvgre_encap(struct context *, const struct token *,
1428 const char *, unsigned int, void *,
1430 static int parse_vc_action_l2_encap(struct context *, const struct token *,
1431 const char *, unsigned int, void *,
1433 static int parse_vc_action_l2_decap(struct context *, const struct token *,
1434 const char *, unsigned int, void *,
1436 static int parse_vc_action_mplsogre_encap(struct context *,
1437 const struct token *, const char *,
1438 unsigned int, void *, unsigned int);
1439 static int parse_vc_action_mplsogre_decap(struct context *,
1440 const struct token *, const char *,
1441 unsigned int, void *, unsigned int);
1442 static int parse_vc_action_mplsoudp_encap(struct context *,
1443 const struct token *, const char *,
1444 unsigned int, void *, unsigned int);
1445 static int parse_vc_action_mplsoudp_decap(struct context *,
1446 const struct token *, const char *,
1447 unsigned int, void *, unsigned int);
1448 static int parse_vc_action_raw_encap(struct context *,
1449 const struct token *, const char *,
1450 unsigned int, void *, unsigned int);
1451 static int parse_vc_action_raw_decap(struct context *,
1452 const struct token *, const char *,
1453 unsigned int, void *, unsigned int);
1454 static int parse_vc_action_raw_encap_index(struct context *,
1455 const struct token *, const char *,
1456 unsigned int, void *, unsigned int);
1457 static int parse_vc_action_raw_decap_index(struct context *,
1458 const struct token *, const char *,
1459 unsigned int, void *, unsigned int);
1460 static int parse_vc_action_set_meta(struct context *ctx,
1461 const struct token *token, const char *str,
1462 unsigned int len, void *buf,
1464 static int parse_destroy(struct context *, const struct token *,
1465 const char *, unsigned int,
1466 void *, unsigned int);
1467 static int parse_flush(struct context *, const struct token *,
1468 const char *, unsigned int,
1469 void *, unsigned int);
1470 static int parse_dump(struct context *, const struct token *,
1471 const char *, unsigned int,
1472 void *, unsigned int);
1473 static int parse_query(struct context *, const struct token *,
1474 const char *, unsigned int,
1475 void *, unsigned int);
1476 static int parse_action(struct context *, const struct token *,
1477 const char *, unsigned int,
1478 void *, unsigned int);
1479 static int parse_list(struct context *, const struct token *,
1480 const char *, unsigned int,
1481 void *, unsigned int);
1482 static int parse_aged(struct context *, const struct token *,
1483 const char *, unsigned int,
1484 void *, unsigned int);
1485 static int parse_isolate(struct context *, const struct token *,
1486 const char *, unsigned int,
1487 void *, unsigned int);
1488 static int parse_int(struct context *, const struct token *,
1489 const char *, unsigned int,
1490 void *, unsigned int);
1491 static int parse_prefix(struct context *, const struct token *,
1492 const char *, unsigned int,
1493 void *, unsigned int);
1494 static int parse_boolean(struct context *, const struct token *,
1495 const char *, unsigned int,
1496 void *, unsigned int);
1497 static int parse_string(struct context *, const struct token *,
1498 const char *, unsigned int,
1499 void *, unsigned int);
1500 static int parse_hex(struct context *ctx, const struct token *token,
1501 const char *str, unsigned int len,
1502 void *buf, unsigned int size);
1503 static int parse_string0(struct context *, const struct token *,
1504 const char *, unsigned int,
1505 void *, unsigned int);
1506 static int parse_mac_addr(struct context *, const struct token *,
1507 const char *, unsigned int,
1508 void *, unsigned int);
1509 static int parse_ipv4_addr(struct context *, const struct token *,
1510 const char *, unsigned int,
1511 void *, unsigned int);
1512 static int parse_ipv6_addr(struct context *, const struct token *,
1513 const char *, unsigned int,
1514 void *, unsigned int);
1515 static int parse_port(struct context *, const struct token *,
1516 const char *, unsigned int,
1517 void *, unsigned int);
1518 static int comp_none(struct context *, const struct token *,
1519 unsigned int, char *, unsigned int);
1520 static int comp_boolean(struct context *, const struct token *,
1521 unsigned int, char *, unsigned int);
1522 static int comp_action(struct context *, const struct token *,
1523 unsigned int, char *, unsigned int);
1524 static int comp_port(struct context *, const struct token *,
1525 unsigned int, char *, unsigned int);
1526 static int comp_rule_id(struct context *, const struct token *,
1527 unsigned int, char *, unsigned int);
1528 static int comp_vc_action_rss_type(struct context *, const struct token *,
1529 unsigned int, char *, unsigned int);
1530 static int comp_vc_action_rss_queue(struct context *, const struct token *,
1531 unsigned int, char *, unsigned int);
1532 static int comp_set_raw_index(struct context *, const struct token *,
1533 unsigned int, char *, unsigned int);
1535 /** Token definitions. */
1536 static const struct token token_list[] = {
1537 /* Special tokens. */
1540 .help = "null entry, abused as the entry point",
1541 .next = NEXT(NEXT_ENTRY(FLOW)),
1546 .help = "command may end here",
1549 .name = "START_SET",
1550 .help = "null entry, abused as the entry point for set",
1551 .next = NEXT(NEXT_ENTRY(SET)),
1556 .help = "set command may end here",
1558 /* Common tokens. */
1562 .help = "integer value",
1567 .name = "{unsigned}",
1569 .help = "unsigned integer value",
1576 .help = "prefix length for bit-mask",
1577 .call = parse_prefix,
1581 .name = "{boolean}",
1583 .help = "any boolean value",
1584 .call = parse_boolean,
1585 .comp = comp_boolean,
1590 .help = "fixed string",
1591 .call = parse_string,
1597 .help = "fixed string",
1601 .name = "{file path}",
1603 .help = "file path",
1604 .call = parse_string0,
1608 .name = "{MAC address}",
1610 .help = "standard MAC address notation",
1611 .call = parse_mac_addr,
1615 .name = "{IPv4 address}",
1616 .type = "IPV4 ADDRESS",
1617 .help = "standard IPv4 address notation",
1618 .call = parse_ipv4_addr,
1622 .name = "{IPv6 address}",
1623 .type = "IPV6 ADDRESS",
1624 .help = "standard IPv6 address notation",
1625 .call = parse_ipv6_addr,
1629 .name = "{rule id}",
1631 .help = "rule identifier",
1633 .comp = comp_rule_id,
1636 .name = "{port_id}",
1638 .help = "port identifier",
1643 .name = "{group_id}",
1645 .help = "group identifier",
1649 [PRIORITY_LEVEL] = {
1652 .help = "priority level",
1656 /* Top-level command. */
1659 .type = "{command} {port_id} [{arg} [...]]",
1660 .help = "manage ingress/egress flow rules",
1661 .next = NEXT(NEXT_ENTRY
1673 /* Sub-level commands. */
1676 .help = "check whether a flow rule can be created",
1677 .next = NEXT(next_vc_attr, NEXT_ENTRY(PORT_ID)),
1678 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1683 .help = "create a flow rule",
1684 .next = NEXT(next_vc_attr, NEXT_ENTRY(PORT_ID)),
1685 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1690 .help = "destroy specific flow rules",
1691 .next = NEXT(NEXT_ENTRY(DESTROY_RULE), NEXT_ENTRY(PORT_ID)),
1692 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1693 .call = parse_destroy,
1697 .help = "destroy all flow rules",
1698 .next = NEXT(NEXT_ENTRY(PORT_ID)),
1699 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1700 .call = parse_flush,
1704 .help = "dump all flow rules to file",
1705 .next = NEXT(next_dump_attr, NEXT_ENTRY(PORT_ID)),
1706 .args = ARGS(ARGS_ENTRY(struct buffer, args.dump.file),
1707 ARGS_ENTRY(struct buffer, port)),
1712 .help = "query an existing flow rule",
1713 .next = NEXT(NEXT_ENTRY(QUERY_ACTION),
1714 NEXT_ENTRY(RULE_ID),
1715 NEXT_ENTRY(PORT_ID)),
1716 .args = ARGS(ARGS_ENTRY(struct buffer, args.query.action.type),
1717 ARGS_ENTRY(struct buffer, args.query.rule),
1718 ARGS_ENTRY(struct buffer, port)),
1719 .call = parse_query,
1723 .help = "list existing flow rules",
1724 .next = NEXT(next_list_attr, NEXT_ENTRY(PORT_ID)),
1725 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1730 .help = "list and destroy aged flows",
1731 .next = NEXT(next_aged_attr, NEXT_ENTRY(PORT_ID)),
1732 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1737 .help = "restrict ingress traffic to the defined flow rules",
1738 .next = NEXT(NEXT_ENTRY(BOOLEAN),
1739 NEXT_ENTRY(PORT_ID)),
1740 .args = ARGS(ARGS_ENTRY(struct buffer, args.isolate.set),
1741 ARGS_ENTRY(struct buffer, port)),
1742 .call = parse_isolate,
1744 /* Destroy arguments. */
1747 .help = "specify a rule identifier",
1748 .next = NEXT(next_destroy_attr, NEXT_ENTRY(RULE_ID)),
1749 .args = ARGS(ARGS_ENTRY_PTR(struct buffer, args.destroy.rule)),
1750 .call = parse_destroy,
1752 /* Query arguments. */
1756 .help = "action to query, must be part of the rule",
1757 .call = parse_action,
1758 .comp = comp_action,
1760 /* List arguments. */
1763 .help = "specify a group",
1764 .next = NEXT(next_list_attr, NEXT_ENTRY(GROUP_ID)),
1765 .args = ARGS(ARGS_ENTRY_PTR(struct buffer, args.list.group)),
1770 .help = "specify aged flows need be destroyed",
1774 /* Validate/create attributes. */
1777 .help = "specify a group",
1778 .next = NEXT(next_vc_attr, NEXT_ENTRY(GROUP_ID)),
1779 .args = ARGS(ARGS_ENTRY(struct rte_flow_attr, group)),
1784 .help = "specify a priority level",
1785 .next = NEXT(next_vc_attr, NEXT_ENTRY(PRIORITY_LEVEL)),
1786 .args = ARGS(ARGS_ENTRY(struct rte_flow_attr, priority)),
1791 .help = "affect rule to ingress",
1792 .next = NEXT(next_vc_attr),
1797 .help = "affect rule to egress",
1798 .next = NEXT(next_vc_attr),
1803 .help = "apply rule directly to endpoints found in pattern",
1804 .next = NEXT(next_vc_attr),
1807 /* Validate/create pattern. */
1810 .help = "submit a list of pattern items",
1811 .next = NEXT(next_item),
1816 .help = "match value perfectly (with full bit-mask)",
1817 .call = parse_vc_spec,
1819 [ITEM_PARAM_SPEC] = {
1821 .help = "match value according to configured bit-mask",
1822 .call = parse_vc_spec,
1824 [ITEM_PARAM_LAST] = {
1826 .help = "specify upper bound to establish a range",
1827 .call = parse_vc_spec,
1829 [ITEM_PARAM_MASK] = {
1831 .help = "specify bit-mask with relevant bits set to one",
1832 .call = parse_vc_spec,
1834 [ITEM_PARAM_PREFIX] = {
1836 .help = "generate bit-mask from a prefix length",
1837 .call = parse_vc_spec,
1841 .help = "specify next pattern item",
1842 .next = NEXT(next_item),
1846 .help = "end list of pattern items",
1847 .priv = PRIV_ITEM(END, 0),
1848 .next = NEXT(NEXT_ENTRY(ACTIONS)),
1853 .help = "no-op pattern item",
1854 .priv = PRIV_ITEM(VOID, 0),
1855 .next = NEXT(NEXT_ENTRY(ITEM_NEXT)),
1860 .help = "perform actions when pattern does not match",
1861 .priv = PRIV_ITEM(INVERT, 0),
1862 .next = NEXT(NEXT_ENTRY(ITEM_NEXT)),
1867 .help = "match any protocol for the current layer",
1868 .priv = PRIV_ITEM(ANY, sizeof(struct rte_flow_item_any)),
1869 .next = NEXT(item_any),
1874 .help = "number of layers covered",
1875 .next = NEXT(item_any, NEXT_ENTRY(UNSIGNED), item_param),
1876 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_any, num)),
1880 .help = "match traffic from/to the physical function",
1881 .priv = PRIV_ITEM(PF, 0),
1882 .next = NEXT(NEXT_ENTRY(ITEM_NEXT)),
1887 .help = "match traffic from/to a virtual function ID",
1888 .priv = PRIV_ITEM(VF, sizeof(struct rte_flow_item_vf)),
1889 .next = NEXT(item_vf),
1895 .next = NEXT(item_vf, NEXT_ENTRY(UNSIGNED), item_param),
1896 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_vf, id)),
1900 .help = "match traffic from/to a specific physical port",
1901 .priv = PRIV_ITEM(PHY_PORT,
1902 sizeof(struct rte_flow_item_phy_port)),
1903 .next = NEXT(item_phy_port),
1906 [ITEM_PHY_PORT_INDEX] = {
1908 .help = "physical port index",
1909 .next = NEXT(item_phy_port, NEXT_ENTRY(UNSIGNED), item_param),
1910 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_phy_port, index)),
1914 .help = "match traffic from/to a given DPDK port ID",
1915 .priv = PRIV_ITEM(PORT_ID,
1916 sizeof(struct rte_flow_item_port_id)),
1917 .next = NEXT(item_port_id),
1920 [ITEM_PORT_ID_ID] = {
1922 .help = "DPDK port ID",
1923 .next = NEXT(item_port_id, NEXT_ENTRY(UNSIGNED), item_param),
1924 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_port_id, id)),
1928 .help = "match traffic against value set in previously matched rule",
1929 .priv = PRIV_ITEM(MARK, sizeof(struct rte_flow_item_mark)),
1930 .next = NEXT(item_mark),
1935 .help = "Integer value to match against",
1936 .next = NEXT(item_mark, NEXT_ENTRY(UNSIGNED), item_param),
1937 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_mark, id)),
1941 .help = "match an arbitrary byte string",
1942 .priv = PRIV_ITEM(RAW, ITEM_RAW_SIZE),
1943 .next = NEXT(item_raw),
1946 [ITEM_RAW_RELATIVE] = {
1948 .help = "look for pattern after the previous item",
1949 .next = NEXT(item_raw, NEXT_ENTRY(BOOLEAN), item_param),
1950 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_item_raw,
1953 [ITEM_RAW_SEARCH] = {
1955 .help = "search pattern from offset (see also limit)",
1956 .next = NEXT(item_raw, NEXT_ENTRY(BOOLEAN), item_param),
1957 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_item_raw,
1960 [ITEM_RAW_OFFSET] = {
1962 .help = "absolute or relative offset for pattern",
1963 .next = NEXT(item_raw, NEXT_ENTRY(INTEGER), item_param),
1964 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_raw, offset)),
1966 [ITEM_RAW_LIMIT] = {
1968 .help = "search area limit for start of pattern",
1969 .next = NEXT(item_raw, NEXT_ENTRY(UNSIGNED), item_param),
1970 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_raw, limit)),
1972 [ITEM_RAW_PATTERN] = {
1974 .help = "byte string to look for",
1975 .next = NEXT(item_raw,
1977 NEXT_ENTRY(ITEM_PARAM_IS,
1980 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_raw, pattern),
1981 ARGS_ENTRY(struct rte_flow_item_raw, length),
1982 ARGS_ENTRY_ARB(sizeof(struct rte_flow_item_raw),
1983 ITEM_RAW_PATTERN_SIZE)),
1987 .help = "match Ethernet header",
1988 .priv = PRIV_ITEM(ETH, sizeof(struct rte_flow_item_eth)),
1989 .next = NEXT(item_eth),
1994 .help = "destination MAC",
1995 .next = NEXT(item_eth, NEXT_ENTRY(MAC_ADDR), item_param),
1996 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_eth, dst)),
2000 .help = "source MAC",
2001 .next = NEXT(item_eth, NEXT_ENTRY(MAC_ADDR), item_param),
2002 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_eth, src)),
2006 .help = "EtherType",
2007 .next = NEXT(item_eth, NEXT_ENTRY(UNSIGNED), item_param),
2008 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_eth, type)),
2012 .help = "match 802.1Q/ad VLAN tag",
2013 .priv = PRIV_ITEM(VLAN, sizeof(struct rte_flow_item_vlan)),
2014 .next = NEXT(item_vlan),
2019 .help = "tag control information",
2020 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
2021 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vlan, tci)),
2025 .help = "priority code point",
2026 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
2027 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_vlan,
2032 .help = "drop eligible indicator",
2033 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
2034 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_vlan,
2039 .help = "VLAN identifier",
2040 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
2041 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_vlan,
2044 [ITEM_VLAN_INNER_TYPE] = {
2045 .name = "inner_type",
2046 .help = "inner EtherType",
2047 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
2048 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vlan,
2053 .help = "match IPv4 header",
2054 .priv = PRIV_ITEM(IPV4, sizeof(struct rte_flow_item_ipv4)),
2055 .next = NEXT(item_ipv4),
2060 .help = "type of service",
2061 .next = NEXT(item_ipv4, NEXT_ENTRY(UNSIGNED), item_param),
2062 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
2063 hdr.type_of_service)),
2067 .help = "time to live",
2068 .next = NEXT(item_ipv4, NEXT_ENTRY(UNSIGNED), item_param),
2069 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
2072 [ITEM_IPV4_PROTO] = {
2074 .help = "next protocol ID",
2075 .next = NEXT(item_ipv4, NEXT_ENTRY(UNSIGNED), item_param),
2076 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
2077 hdr.next_proto_id)),
2081 .help = "source address",
2082 .next = NEXT(item_ipv4, NEXT_ENTRY(IPV4_ADDR), item_param),
2083 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
2088 .help = "destination address",
2089 .next = NEXT(item_ipv4, NEXT_ENTRY(IPV4_ADDR), item_param),
2090 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
2095 .help = "match IPv6 header",
2096 .priv = PRIV_ITEM(IPV6, sizeof(struct rte_flow_item_ipv6)),
2097 .next = NEXT(item_ipv6),
2102 .help = "traffic class",
2103 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
2104 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_ipv6,
2106 "\x0f\xf0\x00\x00")),
2108 [ITEM_IPV6_FLOW] = {
2110 .help = "flow label",
2111 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
2112 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_ipv6,
2114 "\x00\x0f\xff\xff")),
2116 [ITEM_IPV6_PROTO] = {
2118 .help = "protocol (next header)",
2119 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
2120 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
2125 .help = "hop limit",
2126 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
2127 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
2132 .help = "source address",
2133 .next = NEXT(item_ipv6, NEXT_ENTRY(IPV6_ADDR), item_param),
2134 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
2139 .help = "destination address",
2140 .next = NEXT(item_ipv6, NEXT_ENTRY(IPV6_ADDR), item_param),
2141 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
2146 .help = "match ICMP header",
2147 .priv = PRIV_ITEM(ICMP, sizeof(struct rte_flow_item_icmp)),
2148 .next = NEXT(item_icmp),
2151 [ITEM_ICMP_TYPE] = {
2153 .help = "ICMP packet type",
2154 .next = NEXT(item_icmp, NEXT_ENTRY(UNSIGNED), item_param),
2155 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp,
2158 [ITEM_ICMP_CODE] = {
2160 .help = "ICMP packet code",
2161 .next = NEXT(item_icmp, NEXT_ENTRY(UNSIGNED), item_param),
2162 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp,
2167 .help = "match UDP header",
2168 .priv = PRIV_ITEM(UDP, sizeof(struct rte_flow_item_udp)),
2169 .next = NEXT(item_udp),
2174 .help = "UDP source port",
2175 .next = NEXT(item_udp, NEXT_ENTRY(UNSIGNED), item_param),
2176 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_udp,
2181 .help = "UDP destination port",
2182 .next = NEXT(item_udp, NEXT_ENTRY(UNSIGNED), item_param),
2183 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_udp,
2188 .help = "match TCP header",
2189 .priv = PRIV_ITEM(TCP, sizeof(struct rte_flow_item_tcp)),
2190 .next = NEXT(item_tcp),
2195 .help = "TCP source port",
2196 .next = NEXT(item_tcp, NEXT_ENTRY(UNSIGNED), item_param),
2197 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_tcp,
2202 .help = "TCP destination port",
2203 .next = NEXT(item_tcp, NEXT_ENTRY(UNSIGNED), item_param),
2204 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_tcp,
2207 [ITEM_TCP_FLAGS] = {
2209 .help = "TCP flags",
2210 .next = NEXT(item_tcp, NEXT_ENTRY(UNSIGNED), item_param),
2211 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_tcp,
2216 .help = "match SCTP header",
2217 .priv = PRIV_ITEM(SCTP, sizeof(struct rte_flow_item_sctp)),
2218 .next = NEXT(item_sctp),
2223 .help = "SCTP source port",
2224 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
2225 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
2230 .help = "SCTP destination port",
2231 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
2232 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
2237 .help = "validation tag",
2238 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
2239 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
2242 [ITEM_SCTP_CKSUM] = {
2245 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
2246 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
2251 .help = "match VXLAN header",
2252 .priv = PRIV_ITEM(VXLAN, sizeof(struct rte_flow_item_vxlan)),
2253 .next = NEXT(item_vxlan),
2256 [ITEM_VXLAN_VNI] = {
2258 .help = "VXLAN identifier",
2259 .next = NEXT(item_vxlan, NEXT_ENTRY(UNSIGNED), item_param),
2260 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vxlan, vni)),
2264 .help = "match E-Tag header",
2265 .priv = PRIV_ITEM(E_TAG, sizeof(struct rte_flow_item_e_tag)),
2266 .next = NEXT(item_e_tag),
2269 [ITEM_E_TAG_GRP_ECID_B] = {
2270 .name = "grp_ecid_b",
2271 .help = "GRP and E-CID base",
2272 .next = NEXT(item_e_tag, NEXT_ENTRY(UNSIGNED), item_param),
2273 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_e_tag,
2279 .help = "match NVGRE header",
2280 .priv = PRIV_ITEM(NVGRE, sizeof(struct rte_flow_item_nvgre)),
2281 .next = NEXT(item_nvgre),
2284 [ITEM_NVGRE_TNI] = {
2286 .help = "virtual subnet ID",
2287 .next = NEXT(item_nvgre, NEXT_ENTRY(UNSIGNED), item_param),
2288 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_nvgre, tni)),
2292 .help = "match MPLS header",
2293 .priv = PRIV_ITEM(MPLS, sizeof(struct rte_flow_item_mpls)),
2294 .next = NEXT(item_mpls),
2297 [ITEM_MPLS_LABEL] = {
2299 .help = "MPLS label",
2300 .next = NEXT(item_mpls, NEXT_ENTRY(UNSIGNED), item_param),
2301 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_mpls,
2307 .help = "MPLS Traffic Class",
2308 .next = NEXT(item_mpls, NEXT_ENTRY(UNSIGNED), item_param),
2309 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_mpls,
2315 .help = "MPLS Bottom-of-Stack",
2316 .next = NEXT(item_mpls, NEXT_ENTRY(UNSIGNED), item_param),
2317 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_mpls,
2323 .help = "match GRE header",
2324 .priv = PRIV_ITEM(GRE, sizeof(struct rte_flow_item_gre)),
2325 .next = NEXT(item_gre),
2328 [ITEM_GRE_PROTO] = {
2330 .help = "GRE protocol type",
2331 .next = NEXT(item_gre, NEXT_ENTRY(UNSIGNED), item_param),
2332 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gre,
2335 [ITEM_GRE_C_RSVD0_VER] = {
2336 .name = "c_rsvd0_ver",
2338 "checksum (1b), undefined (1b), key bit (1b),"
2339 " sequence number (1b), reserved 0 (9b),"
2341 .next = NEXT(item_gre, NEXT_ENTRY(UNSIGNED), item_param),
2342 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gre,
2345 [ITEM_GRE_C_BIT] = {
2347 .help = "checksum bit (C)",
2348 .next = NEXT(item_gre, NEXT_ENTRY(BOOLEAN), item_param),
2349 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_gre,
2351 "\x80\x00\x00\x00")),
2353 [ITEM_GRE_S_BIT] = {
2355 .help = "sequence number bit (S)",
2356 .next = NEXT(item_gre, NEXT_ENTRY(BOOLEAN), item_param),
2357 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_gre,
2359 "\x10\x00\x00\x00")),
2361 [ITEM_GRE_K_BIT] = {
2363 .help = "key bit (K)",
2364 .next = NEXT(item_gre, NEXT_ENTRY(BOOLEAN), item_param),
2365 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_gre,
2367 "\x20\x00\x00\x00")),
2371 .help = "fuzzy pattern match, expect faster than default",
2372 .priv = PRIV_ITEM(FUZZY,
2373 sizeof(struct rte_flow_item_fuzzy)),
2374 .next = NEXT(item_fuzzy),
2377 [ITEM_FUZZY_THRESH] = {
2379 .help = "match accuracy threshold",
2380 .next = NEXT(item_fuzzy, NEXT_ENTRY(UNSIGNED), item_param),
2381 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_fuzzy,
2386 .help = "match GTP header",
2387 .priv = PRIV_ITEM(GTP, sizeof(struct rte_flow_item_gtp)),
2388 .next = NEXT(item_gtp),
2391 [ITEM_GTP_FLAGS] = {
2392 .name = "v_pt_rsv_flags",
2393 .help = "GTP flags",
2394 .next = NEXT(item_gtp, NEXT_ENTRY(UNSIGNED), item_param),
2395 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_gtp,
2398 [ITEM_GTP_MSG_TYPE] = {
2400 .help = "GTP message type",
2401 .next = NEXT(item_gtp, NEXT_ENTRY(UNSIGNED), item_param),
2402 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_gtp, msg_type)),
2406 .help = "tunnel endpoint identifier",
2407 .next = NEXT(item_gtp, NEXT_ENTRY(UNSIGNED), item_param),
2408 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gtp, teid)),
2412 .help = "match GTP header",
2413 .priv = PRIV_ITEM(GTPC, sizeof(struct rte_flow_item_gtp)),
2414 .next = NEXT(item_gtp),
2419 .help = "match GTP header",
2420 .priv = PRIV_ITEM(GTPU, sizeof(struct rte_flow_item_gtp)),
2421 .next = NEXT(item_gtp),
2426 .help = "match GENEVE header",
2427 .priv = PRIV_ITEM(GENEVE, sizeof(struct rte_flow_item_geneve)),
2428 .next = NEXT(item_geneve),
2431 [ITEM_GENEVE_VNI] = {
2433 .help = "virtual network identifier",
2434 .next = NEXT(item_geneve, NEXT_ENTRY(UNSIGNED), item_param),
2435 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_geneve, vni)),
2437 [ITEM_GENEVE_PROTO] = {
2439 .help = "GENEVE protocol type",
2440 .next = NEXT(item_geneve, NEXT_ENTRY(UNSIGNED), item_param),
2441 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_geneve,
2444 [ITEM_VXLAN_GPE] = {
2445 .name = "vxlan-gpe",
2446 .help = "match VXLAN-GPE header",
2447 .priv = PRIV_ITEM(VXLAN_GPE,
2448 sizeof(struct rte_flow_item_vxlan_gpe)),
2449 .next = NEXT(item_vxlan_gpe),
2452 [ITEM_VXLAN_GPE_VNI] = {
2454 .help = "VXLAN-GPE identifier",
2455 .next = NEXT(item_vxlan_gpe, NEXT_ENTRY(UNSIGNED), item_param),
2456 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vxlan_gpe,
2459 [ITEM_ARP_ETH_IPV4] = {
2460 .name = "arp_eth_ipv4",
2461 .help = "match ARP header for Ethernet/IPv4",
2462 .priv = PRIV_ITEM(ARP_ETH_IPV4,
2463 sizeof(struct rte_flow_item_arp_eth_ipv4)),
2464 .next = NEXT(item_arp_eth_ipv4),
2467 [ITEM_ARP_ETH_IPV4_SHA] = {
2469 .help = "sender hardware address",
2470 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(MAC_ADDR),
2472 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
2475 [ITEM_ARP_ETH_IPV4_SPA] = {
2477 .help = "sender IPv4 address",
2478 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(IPV4_ADDR),
2480 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
2483 [ITEM_ARP_ETH_IPV4_THA] = {
2485 .help = "target hardware address",
2486 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(MAC_ADDR),
2488 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
2491 [ITEM_ARP_ETH_IPV4_TPA] = {
2493 .help = "target IPv4 address",
2494 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(IPV4_ADDR),
2496 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
2501 .help = "match presence of any IPv6 extension header",
2502 .priv = PRIV_ITEM(IPV6_EXT,
2503 sizeof(struct rte_flow_item_ipv6_ext)),
2504 .next = NEXT(item_ipv6_ext),
2507 [ITEM_IPV6_EXT_NEXT_HDR] = {
2509 .help = "next header",
2510 .next = NEXT(item_ipv6_ext, NEXT_ENTRY(UNSIGNED), item_param),
2511 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6_ext,
2516 .help = "match any ICMPv6 header",
2517 .priv = PRIV_ITEM(ICMP6, sizeof(struct rte_flow_item_icmp6)),
2518 .next = NEXT(item_icmp6),
2521 [ITEM_ICMP6_TYPE] = {
2523 .help = "ICMPv6 type",
2524 .next = NEXT(item_icmp6, NEXT_ENTRY(UNSIGNED), item_param),
2525 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6,
2528 [ITEM_ICMP6_CODE] = {
2530 .help = "ICMPv6 code",
2531 .next = NEXT(item_icmp6, NEXT_ENTRY(UNSIGNED), item_param),
2532 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6,
2535 [ITEM_ICMP6_ND_NS] = {
2536 .name = "icmp6_nd_ns",
2537 .help = "match ICMPv6 neighbor discovery solicitation",
2538 .priv = PRIV_ITEM(ICMP6_ND_NS,
2539 sizeof(struct rte_flow_item_icmp6_nd_ns)),
2540 .next = NEXT(item_icmp6_nd_ns),
2543 [ITEM_ICMP6_ND_NS_TARGET_ADDR] = {
2544 .name = "target_addr",
2545 .help = "target address",
2546 .next = NEXT(item_icmp6_nd_ns, NEXT_ENTRY(IPV6_ADDR),
2548 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6_nd_ns,
2551 [ITEM_ICMP6_ND_NA] = {
2552 .name = "icmp6_nd_na",
2553 .help = "match ICMPv6 neighbor discovery advertisement",
2554 .priv = PRIV_ITEM(ICMP6_ND_NA,
2555 sizeof(struct rte_flow_item_icmp6_nd_na)),
2556 .next = NEXT(item_icmp6_nd_na),
2559 [ITEM_ICMP6_ND_NA_TARGET_ADDR] = {
2560 .name = "target_addr",
2561 .help = "target address",
2562 .next = NEXT(item_icmp6_nd_na, NEXT_ENTRY(IPV6_ADDR),
2564 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6_nd_na,
2567 [ITEM_ICMP6_ND_OPT] = {
2568 .name = "icmp6_nd_opt",
2569 .help = "match presence of any ICMPv6 neighbor discovery"
2571 .priv = PRIV_ITEM(ICMP6_ND_OPT,
2572 sizeof(struct rte_flow_item_icmp6_nd_opt)),
2573 .next = NEXT(item_icmp6_nd_opt),
2576 [ITEM_ICMP6_ND_OPT_TYPE] = {
2578 .help = "ND option type",
2579 .next = NEXT(item_icmp6_nd_opt, NEXT_ENTRY(UNSIGNED),
2581 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6_nd_opt,
2584 [ITEM_ICMP6_ND_OPT_SLA_ETH] = {
2585 .name = "icmp6_nd_opt_sla_eth",
2586 .help = "match ICMPv6 neighbor discovery source Ethernet"
2587 " link-layer address option",
2589 (ICMP6_ND_OPT_SLA_ETH,
2590 sizeof(struct rte_flow_item_icmp6_nd_opt_sla_eth)),
2591 .next = NEXT(item_icmp6_nd_opt_sla_eth),
2594 [ITEM_ICMP6_ND_OPT_SLA_ETH_SLA] = {
2596 .help = "source Ethernet LLA",
2597 .next = NEXT(item_icmp6_nd_opt_sla_eth, NEXT_ENTRY(MAC_ADDR),
2599 .args = ARGS(ARGS_ENTRY_HTON
2600 (struct rte_flow_item_icmp6_nd_opt_sla_eth, sla)),
2602 [ITEM_ICMP6_ND_OPT_TLA_ETH] = {
2603 .name = "icmp6_nd_opt_tla_eth",
2604 .help = "match ICMPv6 neighbor discovery target Ethernet"
2605 " link-layer address option",
2607 (ICMP6_ND_OPT_TLA_ETH,
2608 sizeof(struct rte_flow_item_icmp6_nd_opt_tla_eth)),
2609 .next = NEXT(item_icmp6_nd_opt_tla_eth),
2612 [ITEM_ICMP6_ND_OPT_TLA_ETH_TLA] = {
2614 .help = "target Ethernet LLA",
2615 .next = NEXT(item_icmp6_nd_opt_tla_eth, NEXT_ENTRY(MAC_ADDR),
2617 .args = ARGS(ARGS_ENTRY_HTON
2618 (struct rte_flow_item_icmp6_nd_opt_tla_eth, tla)),
2622 .help = "match metadata header",
2623 .priv = PRIV_ITEM(META, sizeof(struct rte_flow_item_meta)),
2624 .next = NEXT(item_meta),
2627 [ITEM_META_DATA] = {
2629 .help = "metadata value",
2630 .next = NEXT(item_meta, NEXT_ENTRY(UNSIGNED), item_param),
2631 .args = ARGS(ARGS_ENTRY_MASK(struct rte_flow_item_meta,
2632 data, "\xff\xff\xff\xff")),
2636 .help = "match GRE key",
2637 .priv = PRIV_ITEM(GRE_KEY, sizeof(rte_be32_t)),
2638 .next = NEXT(item_gre_key),
2641 [ITEM_GRE_KEY_VALUE] = {
2643 .help = "key value",
2644 .next = NEXT(item_gre_key, NEXT_ENTRY(UNSIGNED), item_param),
2645 .args = ARGS(ARG_ENTRY_HTON(rte_be32_t)),
2649 .help = "match GTP extension header with type 0x85",
2650 .priv = PRIV_ITEM(GTP_PSC,
2651 sizeof(struct rte_flow_item_gtp_psc)),
2652 .next = NEXT(item_gtp_psc),
2655 [ITEM_GTP_PSC_QFI] = {
2657 .help = "QoS flow identifier",
2658 .next = NEXT(item_gtp_psc, NEXT_ENTRY(UNSIGNED), item_param),
2659 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gtp_psc,
2662 [ITEM_GTP_PSC_PDU_T] = {
2665 .next = NEXT(item_gtp_psc, NEXT_ENTRY(UNSIGNED), item_param),
2666 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gtp_psc,
2671 .help = "match PPPoE session header",
2672 .priv = PRIV_ITEM(PPPOES, sizeof(struct rte_flow_item_pppoe)),
2673 .next = NEXT(item_pppoes),
2678 .help = "match PPPoE discovery header",
2679 .priv = PRIV_ITEM(PPPOED, sizeof(struct rte_flow_item_pppoe)),
2680 .next = NEXT(item_pppoed),
2683 [ITEM_PPPOE_SEID] = {
2685 .help = "session identifier",
2686 .next = NEXT(item_pppoes, NEXT_ENTRY(UNSIGNED), item_param),
2687 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_pppoe,
2690 [ITEM_PPPOE_PROTO_ID] = {
2691 .name = "pppoe_proto_id",
2692 .help = "match PPPoE session protocol identifier",
2693 .priv = PRIV_ITEM(PPPOE_PROTO_ID,
2694 sizeof(struct rte_flow_item_pppoe_proto_id)),
2695 .next = NEXT(item_pppoe_proto_id, NEXT_ENTRY(UNSIGNED),
2697 .args = ARGS(ARGS_ENTRY_HTON
2698 (struct rte_flow_item_pppoe_proto_id, proto_id)),
2703 .help = "matches higig2 header",
2704 .priv = PRIV_ITEM(HIGIG2,
2705 sizeof(struct rte_flow_item_higig2_hdr)),
2706 .next = NEXT(item_higig2),
2709 [ITEM_HIGIG2_CLASSIFICATION] = {
2710 .name = "classification",
2711 .help = "matches classification of higig2 header",
2712 .next = NEXT(item_higig2, NEXT_ENTRY(UNSIGNED), item_param),
2713 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_higig2_hdr,
2714 hdr.ppt1.classification)),
2716 [ITEM_HIGIG2_VID] = {
2718 .help = "matches vid of higig2 header",
2719 .next = NEXT(item_higig2, NEXT_ENTRY(UNSIGNED), item_param),
2720 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_higig2_hdr,
2725 .help = "match tag value",
2726 .priv = PRIV_ITEM(TAG, sizeof(struct rte_flow_item_tag)),
2727 .next = NEXT(item_tag),
2732 .help = "tag value to match",
2733 .next = NEXT(item_tag, NEXT_ENTRY(UNSIGNED), item_param),
2734 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_tag, data)),
2736 [ITEM_TAG_INDEX] = {
2738 .help = "index of tag array to match",
2739 .next = NEXT(item_tag, NEXT_ENTRY(UNSIGNED),
2740 NEXT_ENTRY(ITEM_PARAM_IS)),
2741 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_tag, index)),
2743 [ITEM_L2TPV3OIP] = {
2744 .name = "l2tpv3oip",
2745 .help = "match L2TPv3 over IP header",
2746 .priv = PRIV_ITEM(L2TPV3OIP,
2747 sizeof(struct rte_flow_item_l2tpv3oip)),
2748 .next = NEXT(item_l2tpv3oip),
2751 [ITEM_L2TPV3OIP_SESSION_ID] = {
2752 .name = "session_id",
2753 .help = "session identifier",
2754 .next = NEXT(item_l2tpv3oip, NEXT_ENTRY(UNSIGNED), item_param),
2755 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_l2tpv3oip,
2760 .help = "match ESP header",
2761 .priv = PRIV_ITEM(ESP, sizeof(struct rte_flow_item_esp)),
2762 .next = NEXT(item_esp),
2767 .help = "security policy index",
2768 .next = NEXT(item_esp, NEXT_ENTRY(UNSIGNED), item_param),
2769 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_esp,
2774 .help = "match AH header",
2775 .priv = PRIV_ITEM(AH, sizeof(struct rte_flow_item_ah)),
2776 .next = NEXT(item_ah),
2781 .help = "security parameters index",
2782 .next = NEXT(item_ah, NEXT_ENTRY(UNSIGNED), item_param),
2783 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ah, spi)),
2787 .help = "match pfcp header",
2788 .priv = PRIV_ITEM(PFCP, sizeof(struct rte_flow_item_pfcp)),
2789 .next = NEXT(item_pfcp),
2792 [ITEM_PFCP_S_FIELD] = {
2795 .next = NEXT(item_pfcp, NEXT_ENTRY(UNSIGNED), item_param),
2796 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_pfcp,
2799 [ITEM_PFCP_SEID] = {
2801 .help = "session endpoint identifier",
2802 .next = NEXT(item_pfcp, NEXT_ENTRY(UNSIGNED), item_param),
2803 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_pfcp, seid)),
2805 /* Validate/create actions. */
2808 .help = "submit a list of associated actions",
2809 .next = NEXT(next_action),
2814 .help = "specify next action",
2815 .next = NEXT(next_action),
2819 .help = "end list of actions",
2820 .priv = PRIV_ACTION(END, 0),
2825 .help = "no-op action",
2826 .priv = PRIV_ACTION(VOID, 0),
2827 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2830 [ACTION_PASSTHRU] = {
2832 .help = "let subsequent rule process matched packets",
2833 .priv = PRIV_ACTION(PASSTHRU, 0),
2834 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2839 .help = "redirect traffic to a given group",
2840 .priv = PRIV_ACTION(JUMP, sizeof(struct rte_flow_action_jump)),
2841 .next = NEXT(action_jump),
2844 [ACTION_JUMP_GROUP] = {
2846 .help = "group to redirect traffic to",
2847 .next = NEXT(action_jump, NEXT_ENTRY(UNSIGNED)),
2848 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_jump, group)),
2849 .call = parse_vc_conf,
2853 .help = "attach 32 bit value to packets",
2854 .priv = PRIV_ACTION(MARK, sizeof(struct rte_flow_action_mark)),
2855 .next = NEXT(action_mark),
2858 [ACTION_MARK_ID] = {
2860 .help = "32 bit value to return with packets",
2861 .next = NEXT(action_mark, NEXT_ENTRY(UNSIGNED)),
2862 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_mark, id)),
2863 .call = parse_vc_conf,
2867 .help = "flag packets",
2868 .priv = PRIV_ACTION(FLAG, 0),
2869 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2874 .help = "assign packets to a given queue index",
2875 .priv = PRIV_ACTION(QUEUE,
2876 sizeof(struct rte_flow_action_queue)),
2877 .next = NEXT(action_queue),
2880 [ACTION_QUEUE_INDEX] = {
2882 .help = "queue index to use",
2883 .next = NEXT(action_queue, NEXT_ENTRY(UNSIGNED)),
2884 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_queue, index)),
2885 .call = parse_vc_conf,
2889 .help = "drop packets (note: passthru has priority)",
2890 .priv = PRIV_ACTION(DROP, 0),
2891 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2896 .help = "enable counters for this rule",
2897 .priv = PRIV_ACTION(COUNT,
2898 sizeof(struct rte_flow_action_count)),
2899 .next = NEXT(action_count),
2902 [ACTION_COUNT_ID] = {
2903 .name = "identifier",
2904 .help = "counter identifier to use",
2905 .next = NEXT(action_count, NEXT_ENTRY(UNSIGNED)),
2906 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_count, id)),
2907 .call = parse_vc_conf,
2909 [ACTION_COUNT_SHARED] = {
2911 .help = "shared counter",
2912 .next = NEXT(action_count, NEXT_ENTRY(BOOLEAN)),
2913 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_count,
2915 .call = parse_vc_conf,
2919 .help = "spread packets among several queues",
2920 .priv = PRIV_ACTION(RSS, sizeof(struct action_rss_data)),
2921 .next = NEXT(action_rss),
2922 .call = parse_vc_action_rss,
2924 [ACTION_RSS_FUNC] = {
2926 .help = "RSS hash function to apply",
2927 .next = NEXT(action_rss,
2928 NEXT_ENTRY(ACTION_RSS_FUNC_DEFAULT,
2929 ACTION_RSS_FUNC_TOEPLITZ,
2930 ACTION_RSS_FUNC_SIMPLE_XOR,
2931 ACTION_RSS_FUNC_SYMMETRIC_TOEPLITZ)),
2933 [ACTION_RSS_FUNC_DEFAULT] = {
2935 .help = "default hash function",
2936 .call = parse_vc_action_rss_func,
2938 [ACTION_RSS_FUNC_TOEPLITZ] = {
2940 .help = "Toeplitz hash function",
2941 .call = parse_vc_action_rss_func,
2943 [ACTION_RSS_FUNC_SIMPLE_XOR] = {
2944 .name = "simple_xor",
2945 .help = "simple XOR hash function",
2946 .call = parse_vc_action_rss_func,
2948 [ACTION_RSS_FUNC_SYMMETRIC_TOEPLITZ] = {
2949 .name = "symmetric_toeplitz",
2950 .help = "Symmetric Toeplitz hash function",
2951 .call = parse_vc_action_rss_func,
2953 [ACTION_RSS_LEVEL] = {
2955 .help = "encapsulation level for \"types\"",
2956 .next = NEXT(action_rss, NEXT_ENTRY(UNSIGNED)),
2957 .args = ARGS(ARGS_ENTRY_ARB
2958 (offsetof(struct action_rss_data, conf) +
2959 offsetof(struct rte_flow_action_rss, level),
2960 sizeof(((struct rte_flow_action_rss *)0)->
2963 [ACTION_RSS_TYPES] = {
2965 .help = "specific RSS hash types",
2966 .next = NEXT(action_rss, NEXT_ENTRY(ACTION_RSS_TYPE)),
2968 [ACTION_RSS_TYPE] = {
2970 .help = "RSS hash type",
2971 .call = parse_vc_action_rss_type,
2972 .comp = comp_vc_action_rss_type,
2974 [ACTION_RSS_KEY] = {
2976 .help = "RSS hash key",
2977 .next = NEXT(action_rss, NEXT_ENTRY(HEX)),
2978 .args = ARGS(ARGS_ENTRY_ARB(0, 0),
2980 (offsetof(struct action_rss_data, conf) +
2981 offsetof(struct rte_flow_action_rss, key_len),
2982 sizeof(((struct rte_flow_action_rss *)0)->
2984 ARGS_ENTRY(struct action_rss_data, key)),
2986 [ACTION_RSS_KEY_LEN] = {
2988 .help = "RSS hash key length in bytes",
2989 .next = NEXT(action_rss, NEXT_ENTRY(UNSIGNED)),
2990 .args = ARGS(ARGS_ENTRY_ARB_BOUNDED
2991 (offsetof(struct action_rss_data, conf) +
2992 offsetof(struct rte_flow_action_rss, key_len),
2993 sizeof(((struct rte_flow_action_rss *)0)->
2996 RSS_HASH_KEY_LENGTH)),
2998 [ACTION_RSS_QUEUES] = {
3000 .help = "queue indices to use",
3001 .next = NEXT(action_rss, NEXT_ENTRY(ACTION_RSS_QUEUE)),
3002 .call = parse_vc_conf,
3004 [ACTION_RSS_QUEUE] = {
3006 .help = "queue index",
3007 .call = parse_vc_action_rss_queue,
3008 .comp = comp_vc_action_rss_queue,
3012 .help = "direct traffic to physical function",
3013 .priv = PRIV_ACTION(PF, 0),
3014 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3019 .help = "direct traffic to a virtual function ID",
3020 .priv = PRIV_ACTION(VF, sizeof(struct rte_flow_action_vf)),
3021 .next = NEXT(action_vf),
3024 [ACTION_VF_ORIGINAL] = {
3026 .help = "use original VF ID if possible",
3027 .next = NEXT(action_vf, NEXT_ENTRY(BOOLEAN)),
3028 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_vf,
3030 .call = parse_vc_conf,
3035 .next = NEXT(action_vf, NEXT_ENTRY(UNSIGNED)),
3036 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_vf, id)),
3037 .call = parse_vc_conf,
3039 [ACTION_PHY_PORT] = {
3041 .help = "direct packets to physical port index",
3042 .priv = PRIV_ACTION(PHY_PORT,
3043 sizeof(struct rte_flow_action_phy_port)),
3044 .next = NEXT(action_phy_port),
3047 [ACTION_PHY_PORT_ORIGINAL] = {
3049 .help = "use original port index if possible",
3050 .next = NEXT(action_phy_port, NEXT_ENTRY(BOOLEAN)),
3051 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_phy_port,
3053 .call = parse_vc_conf,
3055 [ACTION_PHY_PORT_INDEX] = {
3057 .help = "physical port index",
3058 .next = NEXT(action_phy_port, NEXT_ENTRY(UNSIGNED)),
3059 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_phy_port,
3061 .call = parse_vc_conf,
3063 [ACTION_PORT_ID] = {
3065 .help = "direct matching traffic to a given DPDK port ID",
3066 .priv = PRIV_ACTION(PORT_ID,
3067 sizeof(struct rte_flow_action_port_id)),
3068 .next = NEXT(action_port_id),
3071 [ACTION_PORT_ID_ORIGINAL] = {
3073 .help = "use original DPDK port ID if possible",
3074 .next = NEXT(action_port_id, NEXT_ENTRY(BOOLEAN)),
3075 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_port_id,
3077 .call = parse_vc_conf,
3079 [ACTION_PORT_ID_ID] = {
3081 .help = "DPDK port ID",
3082 .next = NEXT(action_port_id, NEXT_ENTRY(UNSIGNED)),
3083 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_port_id, id)),
3084 .call = parse_vc_conf,
3088 .help = "meter the directed packets at given id",
3089 .priv = PRIV_ACTION(METER,
3090 sizeof(struct rte_flow_action_meter)),
3091 .next = NEXT(action_meter),
3094 [ACTION_METER_ID] = {
3096 .help = "meter id to use",
3097 .next = NEXT(action_meter, NEXT_ENTRY(UNSIGNED)),
3098 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_meter, mtr_id)),
3099 .call = parse_vc_conf,
3101 [ACTION_OF_SET_MPLS_TTL] = {
3102 .name = "of_set_mpls_ttl",
3103 .help = "OpenFlow's OFPAT_SET_MPLS_TTL",
3106 sizeof(struct rte_flow_action_of_set_mpls_ttl)),
3107 .next = NEXT(action_of_set_mpls_ttl),
3110 [ACTION_OF_SET_MPLS_TTL_MPLS_TTL] = {
3113 .next = NEXT(action_of_set_mpls_ttl, NEXT_ENTRY(UNSIGNED)),
3114 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_of_set_mpls_ttl,
3116 .call = parse_vc_conf,
3118 [ACTION_OF_DEC_MPLS_TTL] = {
3119 .name = "of_dec_mpls_ttl",
3120 .help = "OpenFlow's OFPAT_DEC_MPLS_TTL",
3121 .priv = PRIV_ACTION(OF_DEC_MPLS_TTL, 0),
3122 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3125 [ACTION_OF_SET_NW_TTL] = {
3126 .name = "of_set_nw_ttl",
3127 .help = "OpenFlow's OFPAT_SET_NW_TTL",
3130 sizeof(struct rte_flow_action_of_set_nw_ttl)),
3131 .next = NEXT(action_of_set_nw_ttl),
3134 [ACTION_OF_SET_NW_TTL_NW_TTL] = {
3137 .next = NEXT(action_of_set_nw_ttl, NEXT_ENTRY(UNSIGNED)),
3138 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_of_set_nw_ttl,
3140 .call = parse_vc_conf,
3142 [ACTION_OF_DEC_NW_TTL] = {
3143 .name = "of_dec_nw_ttl",
3144 .help = "OpenFlow's OFPAT_DEC_NW_TTL",
3145 .priv = PRIV_ACTION(OF_DEC_NW_TTL, 0),
3146 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3149 [ACTION_OF_COPY_TTL_OUT] = {
3150 .name = "of_copy_ttl_out",
3151 .help = "OpenFlow's OFPAT_COPY_TTL_OUT",
3152 .priv = PRIV_ACTION(OF_COPY_TTL_OUT, 0),
3153 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3156 [ACTION_OF_COPY_TTL_IN] = {
3157 .name = "of_copy_ttl_in",
3158 .help = "OpenFlow's OFPAT_COPY_TTL_IN",
3159 .priv = PRIV_ACTION(OF_COPY_TTL_IN, 0),
3160 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3163 [ACTION_OF_POP_VLAN] = {
3164 .name = "of_pop_vlan",
3165 .help = "OpenFlow's OFPAT_POP_VLAN",
3166 .priv = PRIV_ACTION(OF_POP_VLAN, 0),
3167 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3170 [ACTION_OF_PUSH_VLAN] = {
3171 .name = "of_push_vlan",
3172 .help = "OpenFlow's OFPAT_PUSH_VLAN",
3175 sizeof(struct rte_flow_action_of_push_vlan)),
3176 .next = NEXT(action_of_push_vlan),
3179 [ACTION_OF_PUSH_VLAN_ETHERTYPE] = {
3180 .name = "ethertype",
3181 .help = "EtherType",
3182 .next = NEXT(action_of_push_vlan, NEXT_ENTRY(UNSIGNED)),
3183 .args = ARGS(ARGS_ENTRY_HTON
3184 (struct rte_flow_action_of_push_vlan,
3186 .call = parse_vc_conf,
3188 [ACTION_OF_SET_VLAN_VID] = {
3189 .name = "of_set_vlan_vid",
3190 .help = "OpenFlow's OFPAT_SET_VLAN_VID",
3193 sizeof(struct rte_flow_action_of_set_vlan_vid)),
3194 .next = NEXT(action_of_set_vlan_vid),
3197 [ACTION_OF_SET_VLAN_VID_VLAN_VID] = {
3200 .next = NEXT(action_of_set_vlan_vid, NEXT_ENTRY(UNSIGNED)),
3201 .args = ARGS(ARGS_ENTRY_HTON
3202 (struct rte_flow_action_of_set_vlan_vid,
3204 .call = parse_vc_conf,
3206 [ACTION_OF_SET_VLAN_PCP] = {
3207 .name = "of_set_vlan_pcp",
3208 .help = "OpenFlow's OFPAT_SET_VLAN_PCP",
3211 sizeof(struct rte_flow_action_of_set_vlan_pcp)),
3212 .next = NEXT(action_of_set_vlan_pcp),
3215 [ACTION_OF_SET_VLAN_PCP_VLAN_PCP] = {
3217 .help = "VLAN priority",
3218 .next = NEXT(action_of_set_vlan_pcp, NEXT_ENTRY(UNSIGNED)),
3219 .args = ARGS(ARGS_ENTRY_HTON
3220 (struct rte_flow_action_of_set_vlan_pcp,
3222 .call = parse_vc_conf,
3224 [ACTION_OF_POP_MPLS] = {
3225 .name = "of_pop_mpls",
3226 .help = "OpenFlow's OFPAT_POP_MPLS",
3227 .priv = PRIV_ACTION(OF_POP_MPLS,
3228 sizeof(struct rte_flow_action_of_pop_mpls)),
3229 .next = NEXT(action_of_pop_mpls),
3232 [ACTION_OF_POP_MPLS_ETHERTYPE] = {
3233 .name = "ethertype",
3234 .help = "EtherType",
3235 .next = NEXT(action_of_pop_mpls, NEXT_ENTRY(UNSIGNED)),
3236 .args = ARGS(ARGS_ENTRY_HTON
3237 (struct rte_flow_action_of_pop_mpls,
3239 .call = parse_vc_conf,
3241 [ACTION_OF_PUSH_MPLS] = {
3242 .name = "of_push_mpls",
3243 .help = "OpenFlow's OFPAT_PUSH_MPLS",
3246 sizeof(struct rte_flow_action_of_push_mpls)),
3247 .next = NEXT(action_of_push_mpls),
3250 [ACTION_OF_PUSH_MPLS_ETHERTYPE] = {
3251 .name = "ethertype",
3252 .help = "EtherType",
3253 .next = NEXT(action_of_push_mpls, NEXT_ENTRY(UNSIGNED)),
3254 .args = ARGS(ARGS_ENTRY_HTON
3255 (struct rte_flow_action_of_push_mpls,
3257 .call = parse_vc_conf,
3259 [ACTION_VXLAN_ENCAP] = {
3260 .name = "vxlan_encap",
3261 .help = "VXLAN encapsulation, uses configuration set by \"set"
3263 .priv = PRIV_ACTION(VXLAN_ENCAP,
3264 sizeof(struct action_vxlan_encap_data)),
3265 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3266 .call = parse_vc_action_vxlan_encap,
3268 [ACTION_VXLAN_DECAP] = {
3269 .name = "vxlan_decap",
3270 .help = "Performs a decapsulation action by stripping all"
3271 " headers of the VXLAN tunnel network overlay from the"
3273 .priv = PRIV_ACTION(VXLAN_DECAP, 0),
3274 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3277 [ACTION_NVGRE_ENCAP] = {
3278 .name = "nvgre_encap",
3279 .help = "NVGRE encapsulation, uses configuration set by \"set"
3281 .priv = PRIV_ACTION(NVGRE_ENCAP,
3282 sizeof(struct action_nvgre_encap_data)),
3283 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3284 .call = parse_vc_action_nvgre_encap,
3286 [ACTION_NVGRE_DECAP] = {
3287 .name = "nvgre_decap",
3288 .help = "Performs a decapsulation action by stripping all"
3289 " headers of the NVGRE tunnel network overlay from the"
3291 .priv = PRIV_ACTION(NVGRE_DECAP, 0),
3292 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3295 [ACTION_L2_ENCAP] = {
3297 .help = "l2 encap, uses configuration set by"
3298 " \"set l2_encap\"",
3299 .priv = PRIV_ACTION(RAW_ENCAP,
3300 sizeof(struct action_raw_encap_data)),
3301 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3302 .call = parse_vc_action_l2_encap,
3304 [ACTION_L2_DECAP] = {
3306 .help = "l2 decap, uses configuration set by"
3307 " \"set l2_decap\"",
3308 .priv = PRIV_ACTION(RAW_DECAP,
3309 sizeof(struct action_raw_decap_data)),
3310 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3311 .call = parse_vc_action_l2_decap,
3313 [ACTION_MPLSOGRE_ENCAP] = {
3314 .name = "mplsogre_encap",
3315 .help = "mplsogre encapsulation, uses configuration set by"
3316 " \"set mplsogre_encap\"",
3317 .priv = PRIV_ACTION(RAW_ENCAP,
3318 sizeof(struct action_raw_encap_data)),
3319 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3320 .call = parse_vc_action_mplsogre_encap,
3322 [ACTION_MPLSOGRE_DECAP] = {
3323 .name = "mplsogre_decap",
3324 .help = "mplsogre decapsulation, uses configuration set by"
3325 " \"set mplsogre_decap\"",
3326 .priv = PRIV_ACTION(RAW_DECAP,
3327 sizeof(struct action_raw_decap_data)),
3328 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3329 .call = parse_vc_action_mplsogre_decap,
3331 [ACTION_MPLSOUDP_ENCAP] = {
3332 .name = "mplsoudp_encap",
3333 .help = "mplsoudp encapsulation, uses configuration set by"
3334 " \"set mplsoudp_encap\"",
3335 .priv = PRIV_ACTION(RAW_ENCAP,
3336 sizeof(struct action_raw_encap_data)),
3337 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3338 .call = parse_vc_action_mplsoudp_encap,
3340 [ACTION_MPLSOUDP_DECAP] = {
3341 .name = "mplsoudp_decap",
3342 .help = "mplsoudp decapsulation, uses configuration set by"
3343 " \"set mplsoudp_decap\"",
3344 .priv = PRIV_ACTION(RAW_DECAP,
3345 sizeof(struct action_raw_decap_data)),
3346 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3347 .call = parse_vc_action_mplsoudp_decap,
3349 [ACTION_SET_IPV4_SRC] = {
3350 .name = "set_ipv4_src",
3351 .help = "Set a new IPv4 source address in the outermost"
3353 .priv = PRIV_ACTION(SET_IPV4_SRC,
3354 sizeof(struct rte_flow_action_set_ipv4)),
3355 .next = NEXT(action_set_ipv4_src),
3358 [ACTION_SET_IPV4_SRC_IPV4_SRC] = {
3359 .name = "ipv4_addr",
3360 .help = "new IPv4 source address to set",
3361 .next = NEXT(action_set_ipv4_src, NEXT_ENTRY(IPV4_ADDR)),
3362 .args = ARGS(ARGS_ENTRY_HTON
3363 (struct rte_flow_action_set_ipv4, ipv4_addr)),
3364 .call = parse_vc_conf,
3366 [ACTION_SET_IPV4_DST] = {
3367 .name = "set_ipv4_dst",
3368 .help = "Set a new IPv4 destination address in the outermost"
3370 .priv = PRIV_ACTION(SET_IPV4_DST,
3371 sizeof(struct rte_flow_action_set_ipv4)),
3372 .next = NEXT(action_set_ipv4_dst),
3375 [ACTION_SET_IPV4_DST_IPV4_DST] = {
3376 .name = "ipv4_addr",
3377 .help = "new IPv4 destination address to set",
3378 .next = NEXT(action_set_ipv4_dst, NEXT_ENTRY(IPV4_ADDR)),
3379 .args = ARGS(ARGS_ENTRY_HTON
3380 (struct rte_flow_action_set_ipv4, ipv4_addr)),
3381 .call = parse_vc_conf,
3383 [ACTION_SET_IPV6_SRC] = {
3384 .name = "set_ipv6_src",
3385 .help = "Set a new IPv6 source address in the outermost"
3387 .priv = PRIV_ACTION(SET_IPV6_SRC,
3388 sizeof(struct rte_flow_action_set_ipv6)),
3389 .next = NEXT(action_set_ipv6_src),
3392 [ACTION_SET_IPV6_SRC_IPV6_SRC] = {
3393 .name = "ipv6_addr",
3394 .help = "new IPv6 source address to set",
3395 .next = NEXT(action_set_ipv6_src, NEXT_ENTRY(IPV6_ADDR)),
3396 .args = ARGS(ARGS_ENTRY_HTON
3397 (struct rte_flow_action_set_ipv6, ipv6_addr)),
3398 .call = parse_vc_conf,
3400 [ACTION_SET_IPV6_DST] = {
3401 .name = "set_ipv6_dst",
3402 .help = "Set a new IPv6 destination address in the outermost"
3404 .priv = PRIV_ACTION(SET_IPV6_DST,
3405 sizeof(struct rte_flow_action_set_ipv6)),
3406 .next = NEXT(action_set_ipv6_dst),
3409 [ACTION_SET_IPV6_DST_IPV6_DST] = {
3410 .name = "ipv6_addr",
3411 .help = "new IPv6 destination address to set",
3412 .next = NEXT(action_set_ipv6_dst, NEXT_ENTRY(IPV6_ADDR)),
3413 .args = ARGS(ARGS_ENTRY_HTON
3414 (struct rte_flow_action_set_ipv6, ipv6_addr)),
3415 .call = parse_vc_conf,
3417 [ACTION_SET_TP_SRC] = {
3418 .name = "set_tp_src",
3419 .help = "set a new source port number in the outermost"
3421 .priv = PRIV_ACTION(SET_TP_SRC,
3422 sizeof(struct rte_flow_action_set_tp)),
3423 .next = NEXT(action_set_tp_src),
3426 [ACTION_SET_TP_SRC_TP_SRC] = {
3428 .help = "new source port number to set",
3429 .next = NEXT(action_set_tp_src, NEXT_ENTRY(UNSIGNED)),
3430 .args = ARGS(ARGS_ENTRY_HTON
3431 (struct rte_flow_action_set_tp, port)),
3432 .call = parse_vc_conf,
3434 [ACTION_SET_TP_DST] = {
3435 .name = "set_tp_dst",
3436 .help = "set a new destination port number in the outermost"
3438 .priv = PRIV_ACTION(SET_TP_DST,
3439 sizeof(struct rte_flow_action_set_tp)),
3440 .next = NEXT(action_set_tp_dst),
3443 [ACTION_SET_TP_DST_TP_DST] = {
3445 .help = "new destination port number to set",
3446 .next = NEXT(action_set_tp_dst, NEXT_ENTRY(UNSIGNED)),
3447 .args = ARGS(ARGS_ENTRY_HTON
3448 (struct rte_flow_action_set_tp, port)),
3449 .call = parse_vc_conf,
3451 [ACTION_MAC_SWAP] = {
3453 .help = "Swap the source and destination MAC addresses"
3454 " in the outermost Ethernet header",
3455 .priv = PRIV_ACTION(MAC_SWAP, 0),
3456 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3459 [ACTION_DEC_TTL] = {
3461 .help = "decrease network TTL if available",
3462 .priv = PRIV_ACTION(DEC_TTL, 0),
3463 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3466 [ACTION_SET_TTL] = {
3468 .help = "set ttl value",
3469 .priv = PRIV_ACTION(SET_TTL,
3470 sizeof(struct rte_flow_action_set_ttl)),
3471 .next = NEXT(action_set_ttl),
3474 [ACTION_SET_TTL_TTL] = {
3475 .name = "ttl_value",
3476 .help = "new ttl value to set",
3477 .next = NEXT(action_set_ttl, NEXT_ENTRY(UNSIGNED)),
3478 .args = ARGS(ARGS_ENTRY_HTON
3479 (struct rte_flow_action_set_ttl, ttl_value)),
3480 .call = parse_vc_conf,
3482 [ACTION_SET_MAC_SRC] = {
3483 .name = "set_mac_src",
3484 .help = "set source mac address",
3485 .priv = PRIV_ACTION(SET_MAC_SRC,
3486 sizeof(struct rte_flow_action_set_mac)),
3487 .next = NEXT(action_set_mac_src),
3490 [ACTION_SET_MAC_SRC_MAC_SRC] = {
3492 .help = "new source mac address",
3493 .next = NEXT(action_set_mac_src, NEXT_ENTRY(MAC_ADDR)),
3494 .args = ARGS(ARGS_ENTRY_HTON
3495 (struct rte_flow_action_set_mac, mac_addr)),
3496 .call = parse_vc_conf,
3498 [ACTION_SET_MAC_DST] = {
3499 .name = "set_mac_dst",
3500 .help = "set destination mac address",
3501 .priv = PRIV_ACTION(SET_MAC_DST,
3502 sizeof(struct rte_flow_action_set_mac)),
3503 .next = NEXT(action_set_mac_dst),
3506 [ACTION_SET_MAC_DST_MAC_DST] = {
3508 .help = "new destination mac address to set",
3509 .next = NEXT(action_set_mac_dst, NEXT_ENTRY(MAC_ADDR)),
3510 .args = ARGS(ARGS_ENTRY_HTON
3511 (struct rte_flow_action_set_mac, mac_addr)),
3512 .call = parse_vc_conf,
3514 [ACTION_INC_TCP_SEQ] = {
3515 .name = "inc_tcp_seq",
3516 .help = "increase TCP sequence number",
3517 .priv = PRIV_ACTION(INC_TCP_SEQ, sizeof(rte_be32_t)),
3518 .next = NEXT(action_inc_tcp_seq),
3521 [ACTION_INC_TCP_SEQ_VALUE] = {
3523 .help = "the value to increase TCP sequence number by",
3524 .next = NEXT(action_inc_tcp_seq, NEXT_ENTRY(UNSIGNED)),
3525 .args = ARGS(ARG_ENTRY_HTON(rte_be32_t)),
3526 .call = parse_vc_conf,
3528 [ACTION_DEC_TCP_SEQ] = {
3529 .name = "dec_tcp_seq",
3530 .help = "decrease TCP sequence number",
3531 .priv = PRIV_ACTION(DEC_TCP_SEQ, sizeof(rte_be32_t)),
3532 .next = NEXT(action_dec_tcp_seq),
3535 [ACTION_DEC_TCP_SEQ_VALUE] = {
3537 .help = "the value to decrease TCP sequence number by",
3538 .next = NEXT(action_dec_tcp_seq, NEXT_ENTRY(UNSIGNED)),
3539 .args = ARGS(ARG_ENTRY_HTON(rte_be32_t)),
3540 .call = parse_vc_conf,
3542 [ACTION_INC_TCP_ACK] = {
3543 .name = "inc_tcp_ack",
3544 .help = "increase TCP acknowledgment number",
3545 .priv = PRIV_ACTION(INC_TCP_ACK, sizeof(rte_be32_t)),
3546 .next = NEXT(action_inc_tcp_ack),
3549 [ACTION_INC_TCP_ACK_VALUE] = {
3551 .help = "the value to increase TCP acknowledgment number by",
3552 .next = NEXT(action_inc_tcp_ack, NEXT_ENTRY(UNSIGNED)),
3553 .args = ARGS(ARG_ENTRY_HTON(rte_be32_t)),
3554 .call = parse_vc_conf,
3556 [ACTION_DEC_TCP_ACK] = {
3557 .name = "dec_tcp_ack",
3558 .help = "decrease TCP acknowledgment number",
3559 .priv = PRIV_ACTION(DEC_TCP_ACK, sizeof(rte_be32_t)),
3560 .next = NEXT(action_dec_tcp_ack),
3563 [ACTION_DEC_TCP_ACK_VALUE] = {
3565 .help = "the value to decrease TCP acknowledgment number by",
3566 .next = NEXT(action_dec_tcp_ack, NEXT_ENTRY(UNSIGNED)),
3567 .args = ARGS(ARG_ENTRY_HTON(rte_be32_t)),
3568 .call = parse_vc_conf,
3570 [ACTION_RAW_ENCAP] = {
3571 .name = "raw_encap",
3572 .help = "encapsulation data, defined by set raw_encap",
3573 .priv = PRIV_ACTION(RAW_ENCAP,
3574 sizeof(struct action_raw_encap_data)),
3575 .next = NEXT(action_raw_encap),
3576 .call = parse_vc_action_raw_encap,
3578 [ACTION_RAW_ENCAP_INDEX] = {
3580 .help = "the index of raw_encap_confs",
3581 .next = NEXT(NEXT_ENTRY(ACTION_RAW_ENCAP_INDEX_VALUE)),
3583 [ACTION_RAW_ENCAP_INDEX_VALUE] = {
3586 .help = "unsigned integer value",
3587 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3588 .call = parse_vc_action_raw_encap_index,
3589 .comp = comp_set_raw_index,
3591 [ACTION_RAW_DECAP] = {
3592 .name = "raw_decap",
3593 .help = "decapsulation data, defined by set raw_encap",
3594 .priv = PRIV_ACTION(RAW_DECAP,
3595 sizeof(struct action_raw_decap_data)),
3596 .next = NEXT(action_raw_decap),
3597 .call = parse_vc_action_raw_decap,
3599 [ACTION_RAW_DECAP_INDEX] = {
3601 .help = "the index of raw_encap_confs",
3602 .next = NEXT(NEXT_ENTRY(ACTION_RAW_DECAP_INDEX_VALUE)),
3604 [ACTION_RAW_DECAP_INDEX_VALUE] = {
3607 .help = "unsigned integer value",
3608 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3609 .call = parse_vc_action_raw_decap_index,
3610 .comp = comp_set_raw_index,
3612 /* Top level command. */
3615 .help = "set raw encap/decap data",
3616 .type = "set raw_encap|raw_decap <index> <pattern>",
3617 .next = NEXT(NEXT_ENTRY
3620 .call = parse_set_init,
3622 /* Sub-level commands. */
3624 .name = "raw_encap",
3625 .help = "set raw encap data",
3626 .next = NEXT(next_set_raw),
3627 .args = ARGS(ARGS_ENTRY_ARB_BOUNDED
3628 (offsetof(struct buffer, port),
3629 sizeof(((struct buffer *)0)->port),
3630 0, RAW_ENCAP_CONFS_MAX_NUM - 1)),
3631 .call = parse_set_raw_encap_decap,
3634 .name = "raw_decap",
3635 .help = "set raw decap data",
3636 .next = NEXT(next_set_raw),
3637 .args = ARGS(ARGS_ENTRY_ARB_BOUNDED
3638 (offsetof(struct buffer, port),
3639 sizeof(((struct buffer *)0)->port),
3640 0, RAW_ENCAP_CONFS_MAX_NUM - 1)),
3641 .call = parse_set_raw_encap_decap,
3646 .help = "index of raw_encap/raw_decap data",
3647 .next = NEXT(next_item),
3650 [ACTION_SET_TAG] = {
3653 .priv = PRIV_ACTION(SET_TAG,
3654 sizeof(struct rte_flow_action_set_tag)),
3655 .next = NEXT(action_set_tag),
3658 [ACTION_SET_TAG_INDEX] = {
3660 .help = "index of tag array",
3661 .next = NEXT(action_set_tag, NEXT_ENTRY(UNSIGNED)),
3662 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_set_tag, index)),
3663 .call = parse_vc_conf,
3665 [ACTION_SET_TAG_DATA] = {
3667 .help = "tag value",
3668 .next = NEXT(action_set_tag, NEXT_ENTRY(UNSIGNED)),
3669 .args = ARGS(ARGS_ENTRY
3670 (struct rte_flow_action_set_tag, data)),
3671 .call = parse_vc_conf,
3673 [ACTION_SET_TAG_MASK] = {
3675 .help = "mask for tag value",
3676 .next = NEXT(action_set_tag, NEXT_ENTRY(UNSIGNED)),
3677 .args = ARGS(ARGS_ENTRY
3678 (struct rte_flow_action_set_tag, mask)),
3679 .call = parse_vc_conf,
3681 [ACTION_SET_META] = {
3683 .help = "set metadata",
3684 .priv = PRIV_ACTION(SET_META,
3685 sizeof(struct rte_flow_action_set_meta)),
3686 .next = NEXT(action_set_meta),
3687 .call = parse_vc_action_set_meta,
3689 [ACTION_SET_META_DATA] = {
3691 .help = "metadata value",
3692 .next = NEXT(action_set_meta, NEXT_ENTRY(UNSIGNED)),
3693 .args = ARGS(ARGS_ENTRY
3694 (struct rte_flow_action_set_meta, data)),
3695 .call = parse_vc_conf,
3697 [ACTION_SET_META_MASK] = {
3699 .help = "mask for metadata value",
3700 .next = NEXT(action_set_meta, NEXT_ENTRY(UNSIGNED)),
3701 .args = ARGS(ARGS_ENTRY
3702 (struct rte_flow_action_set_meta, mask)),
3703 .call = parse_vc_conf,
3705 [ACTION_SET_IPV4_DSCP] = {
3706 .name = "set_ipv4_dscp",
3707 .help = "set DSCP value",
3708 .priv = PRIV_ACTION(SET_IPV4_DSCP,
3709 sizeof(struct rte_flow_action_set_dscp)),
3710 .next = NEXT(action_set_ipv4_dscp),
3713 [ACTION_SET_IPV4_DSCP_VALUE] = {
3714 .name = "dscp_value",
3715 .help = "new IPv4 DSCP value to set",
3716 .next = NEXT(action_set_ipv4_dscp, NEXT_ENTRY(UNSIGNED)),
3717 .args = ARGS(ARGS_ENTRY
3718 (struct rte_flow_action_set_dscp, dscp)),
3719 .call = parse_vc_conf,
3721 [ACTION_SET_IPV6_DSCP] = {
3722 .name = "set_ipv6_dscp",
3723 .help = "set DSCP value",
3724 .priv = PRIV_ACTION(SET_IPV6_DSCP,
3725 sizeof(struct rte_flow_action_set_dscp)),
3726 .next = NEXT(action_set_ipv6_dscp),
3729 [ACTION_SET_IPV6_DSCP_VALUE] = {
3730 .name = "dscp_value",
3731 .help = "new IPv6 DSCP value to set",
3732 .next = NEXT(action_set_ipv6_dscp, NEXT_ENTRY(UNSIGNED)),
3733 .args = ARGS(ARGS_ENTRY
3734 (struct rte_flow_action_set_dscp, dscp)),
3735 .call = parse_vc_conf,
3739 .help = "set a specific metadata header",
3740 .next = NEXT(action_age),
3741 .priv = PRIV_ACTION(AGE,
3742 sizeof(struct rte_flow_action_age)),
3745 [ACTION_AGE_TIMEOUT] = {
3747 .help = "flow age timeout value",
3748 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_age,
3750 .next = NEXT(action_age, NEXT_ENTRY(UNSIGNED)),
3751 .call = parse_vc_conf,
3755 /** Remove and return last entry from argument stack. */
3756 static const struct arg *
3757 pop_args(struct context *ctx)
3759 return ctx->args_num ? ctx->args[--ctx->args_num] : NULL;
3762 /** Add entry on top of the argument stack. */
3764 push_args(struct context *ctx, const struct arg *arg)
3766 if (ctx->args_num == CTX_STACK_SIZE)
3768 ctx->args[ctx->args_num++] = arg;
3772 /** Spread value into buffer according to bit-mask. */
3774 arg_entry_bf_fill(void *dst, uintmax_t val, const struct arg *arg)
3776 uint32_t i = arg->size;
3784 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
3793 unsigned int shift = 0;
3794 uint8_t *buf = (uint8_t *)dst + arg->offset + (i -= sub);
3796 for (shift = 0; arg->mask[i] >> shift; ++shift) {
3797 if (!(arg->mask[i] & (1 << shift)))
3802 *buf &= ~(1 << shift);
3803 *buf |= (val & 1) << shift;
3811 /** Compare a string with a partial one of a given length. */
3813 strcmp_partial(const char *full, const char *partial, size_t partial_len)
3815 int r = strncmp(full, partial, partial_len);
3819 if (strlen(full) <= partial_len)
3821 return full[partial_len];
3825 * Parse a prefix length and generate a bit-mask.
3827 * Last argument (ctx->args) is retrieved to determine mask size, storage
3828 * location and whether the result must use network byte ordering.
3831 parse_prefix(struct context *ctx, const struct token *token,
3832 const char *str, unsigned int len,
3833 void *buf, unsigned int size)
3835 const struct arg *arg = pop_args(ctx);
3836 static const uint8_t conv[] = "\x00\x80\xc0\xe0\xf0\xf8\xfc\xfe\xff";
3843 /* Argument is expected. */
3847 u = strtoumax(str, &end, 0);
3848 if (errno || (size_t)(end - str) != len)
3853 extra = arg_entry_bf_fill(NULL, 0, arg);
3862 if (!arg_entry_bf_fill(ctx->object, v, arg) ||
3863 !arg_entry_bf_fill(ctx->objmask, -1, arg))
3870 if (bytes > size || bytes + !!extra > size)
3874 buf = (uint8_t *)ctx->object + arg->offset;
3875 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
3877 memset((uint8_t *)buf + size - bytes, 0xff, bytes);
3878 memset(buf, 0x00, size - bytes);
3880 ((uint8_t *)buf)[size - bytes - 1] = conv[extra];
3884 memset(buf, 0xff, bytes);
3885 memset((uint8_t *)buf + bytes, 0x00, size - bytes);
3887 ((uint8_t *)buf)[bytes] = conv[extra];
3890 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
3893 push_args(ctx, arg);
3897 /** Default parsing function for token name matching. */
3899 parse_default(struct context *ctx, const struct token *token,
3900 const char *str, unsigned int len,
3901 void *buf, unsigned int size)
3906 if (strcmp_partial(token->name, str, len))
3911 /** Parse flow command, initialize output buffer for subsequent tokens. */
3913 parse_init(struct context *ctx, const struct token *token,
3914 const char *str, unsigned int len,
3915 void *buf, unsigned int size)
3917 struct buffer *out = buf;
3919 /* Token name must match. */
3920 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
3922 /* Nothing else to do if there is no buffer. */
3925 /* Make sure buffer is large enough. */
3926 if (size < sizeof(*out))
3928 /* Initialize buffer. */
3929 memset(out, 0x00, sizeof(*out));
3930 memset((uint8_t *)out + sizeof(*out), 0x22, size - sizeof(*out));
3933 ctx->objmask = NULL;
3937 /** Parse tokens for validate/create commands. */
3939 parse_vc(struct context *ctx, const struct token *token,
3940 const char *str, unsigned int len,
3941 void *buf, unsigned int size)
3943 struct buffer *out = buf;
3947 /* Token name must match. */
3948 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
3950 /* Nothing else to do if there is no buffer. */
3953 if (!out->command) {
3954 if (ctx->curr != VALIDATE && ctx->curr != CREATE)
3956 if (sizeof(*out) > size)
3958 out->command = ctx->curr;
3961 ctx->objmask = NULL;
3962 out->args.vc.data = (uint8_t *)out + size;
3966 ctx->object = &out->args.vc.attr;
3967 ctx->objmask = NULL;
3968 switch (ctx->curr) {
3973 out->args.vc.attr.ingress = 1;
3976 out->args.vc.attr.egress = 1;
3979 out->args.vc.attr.transfer = 1;
3982 out->args.vc.pattern =
3983 (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
3985 ctx->object = out->args.vc.pattern;
3986 ctx->objmask = NULL;
3989 out->args.vc.actions =
3990 (void *)RTE_ALIGN_CEIL((uintptr_t)
3991 (out->args.vc.pattern +
3992 out->args.vc.pattern_n),
3994 ctx->object = out->args.vc.actions;
3995 ctx->objmask = NULL;
4002 if (!out->args.vc.actions) {
4003 const struct parse_item_priv *priv = token->priv;
4004 struct rte_flow_item *item =
4005 out->args.vc.pattern + out->args.vc.pattern_n;
4007 data_size = priv->size * 3; /* spec, last, mask */
4008 data = (void *)RTE_ALIGN_FLOOR((uintptr_t)
4009 (out->args.vc.data - data_size),
4011 if ((uint8_t *)item + sizeof(*item) > data)
4013 *item = (struct rte_flow_item){
4016 ++out->args.vc.pattern_n;
4018 ctx->objmask = NULL;
4020 const struct parse_action_priv *priv = token->priv;
4021 struct rte_flow_action *action =
4022 out->args.vc.actions + out->args.vc.actions_n;
4024 data_size = priv->size; /* configuration */
4025 data = (void *)RTE_ALIGN_FLOOR((uintptr_t)
4026 (out->args.vc.data - data_size),
4028 if ((uint8_t *)action + sizeof(*action) > data)
4030 *action = (struct rte_flow_action){
4032 .conf = data_size ? data : NULL,
4034 ++out->args.vc.actions_n;
4035 ctx->object = action;
4036 ctx->objmask = NULL;
4038 memset(data, 0, data_size);
4039 out->args.vc.data = data;
4040 ctx->objdata = data_size;
4044 /** Parse pattern item parameter type. */
4046 parse_vc_spec(struct context *ctx, const struct token *token,
4047 const char *str, unsigned int len,
4048 void *buf, unsigned int size)
4050 struct buffer *out = buf;
4051 struct rte_flow_item *item;
4057 /* Token name must match. */
4058 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
4060 /* Parse parameter types. */
4061 switch (ctx->curr) {
4062 static const enum index prefix[] = NEXT_ENTRY(PREFIX);
4068 case ITEM_PARAM_SPEC:
4071 case ITEM_PARAM_LAST:
4074 case ITEM_PARAM_PREFIX:
4075 /* Modify next token to expect a prefix. */
4076 if (ctx->next_num < 2)
4078 ctx->next[ctx->next_num - 2] = prefix;
4080 case ITEM_PARAM_MASK:
4086 /* Nothing else to do if there is no buffer. */
4089 if (!out->args.vc.pattern_n)
4091 item = &out->args.vc.pattern[out->args.vc.pattern_n - 1];
4092 data_size = ctx->objdata / 3; /* spec, last, mask */
4093 /* Point to selected object. */
4094 ctx->object = out->args.vc.data + (data_size * index);
4096 ctx->objmask = out->args.vc.data + (data_size * 2); /* mask */
4097 item->mask = ctx->objmask;
4099 ctx->objmask = NULL;
4100 /* Update relevant item pointer. */
4101 *((const void **[]){ &item->spec, &item->last, &item->mask })[index] =
4106 /** Parse action configuration field. */
4108 parse_vc_conf(struct context *ctx, const struct token *token,
4109 const char *str, unsigned int len,
4110 void *buf, unsigned int size)
4112 struct buffer *out = buf;
4115 /* Token name must match. */
4116 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
4118 /* Nothing else to do if there is no buffer. */
4121 /* Point to selected object. */
4122 ctx->object = out->args.vc.data;
4123 ctx->objmask = NULL;
4127 /** Parse RSS action. */
4129 parse_vc_action_rss(struct context *ctx, const struct token *token,
4130 const char *str, unsigned int len,
4131 void *buf, unsigned int size)
4133 struct buffer *out = buf;
4134 struct rte_flow_action *action;
4135 struct action_rss_data *action_rss_data;
4139 ret = parse_vc(ctx, token, str, len, buf, size);
4142 /* Nothing else to do if there is no buffer. */
4145 if (!out->args.vc.actions_n)
4147 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4148 /* Point to selected object. */
4149 ctx->object = out->args.vc.data;
4150 ctx->objmask = NULL;
4151 /* Set up default configuration. */
4152 action_rss_data = ctx->object;
4153 *action_rss_data = (struct action_rss_data){
4154 .conf = (struct rte_flow_action_rss){
4155 .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
4158 .key_len = sizeof(action_rss_data->key),
4159 .queue_num = RTE_MIN(nb_rxq, ACTION_RSS_QUEUE_NUM),
4160 .key = action_rss_data->key,
4161 .queue = action_rss_data->queue,
4163 .key = "testpmd's default RSS hash key, "
4164 "override it for better balancing",
4167 for (i = 0; i < action_rss_data->conf.queue_num; ++i)
4168 action_rss_data->queue[i] = i;
4169 if (!port_id_is_invalid(ctx->port, DISABLED_WARN) &&
4170 ctx->port != (portid_t)RTE_PORT_ALL) {
4171 struct rte_eth_dev_info info;
4174 ret2 = rte_eth_dev_info_get(ctx->port, &info);
4178 action_rss_data->conf.key_len =
4179 RTE_MIN(sizeof(action_rss_data->key),
4180 info.hash_key_size);
4182 action->conf = &action_rss_data->conf;
4187 * Parse func field for RSS action.
4189 * The RTE_ETH_HASH_FUNCTION_* value to assign is derived from the
4190 * ACTION_RSS_FUNC_* index that called this function.
4193 parse_vc_action_rss_func(struct context *ctx, const struct token *token,
4194 const char *str, unsigned int len,
4195 void *buf, unsigned int size)
4197 struct action_rss_data *action_rss_data;
4198 enum rte_eth_hash_function func;
4202 /* Token name must match. */
4203 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
4205 switch (ctx->curr) {
4206 case ACTION_RSS_FUNC_DEFAULT:
4207 func = RTE_ETH_HASH_FUNCTION_DEFAULT;
4209 case ACTION_RSS_FUNC_TOEPLITZ:
4210 func = RTE_ETH_HASH_FUNCTION_TOEPLITZ;
4212 case ACTION_RSS_FUNC_SIMPLE_XOR:
4213 func = RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
4215 case ACTION_RSS_FUNC_SYMMETRIC_TOEPLITZ:
4216 func = RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ;
4223 action_rss_data = ctx->object;
4224 action_rss_data->conf.func = func;
4229 * Parse type field for RSS action.
4231 * Valid tokens are type field names and the "end" token.
4234 parse_vc_action_rss_type(struct context *ctx, const struct token *token,
4235 const char *str, unsigned int len,
4236 void *buf, unsigned int size)
4238 static const enum index next[] = NEXT_ENTRY(ACTION_RSS_TYPE);
4239 struct action_rss_data *action_rss_data;
4245 if (ctx->curr != ACTION_RSS_TYPE)
4247 if (!(ctx->objdata >> 16) && ctx->object) {
4248 action_rss_data = ctx->object;
4249 action_rss_data->conf.types = 0;
4251 if (!strcmp_partial("end", str, len)) {
4252 ctx->objdata &= 0xffff;
4255 for (i = 0; rss_type_table[i].str; ++i)
4256 if (!strcmp_partial(rss_type_table[i].str, str, len))
4258 if (!rss_type_table[i].str)
4260 ctx->objdata = 1 << 16 | (ctx->objdata & 0xffff);
4262 if (ctx->next_num == RTE_DIM(ctx->next))
4264 ctx->next[ctx->next_num++] = next;
4267 action_rss_data = ctx->object;
4268 action_rss_data->conf.types |= rss_type_table[i].rss_type;
4273 * Parse queue field for RSS action.
4275 * Valid tokens are queue indices and the "end" token.
4278 parse_vc_action_rss_queue(struct context *ctx, const struct token *token,
4279 const char *str, unsigned int len,
4280 void *buf, unsigned int size)
4282 static const enum index next[] = NEXT_ENTRY(ACTION_RSS_QUEUE);
4283 struct action_rss_data *action_rss_data;
4284 const struct arg *arg;
4291 if (ctx->curr != ACTION_RSS_QUEUE)
4293 i = ctx->objdata >> 16;
4294 if (!strcmp_partial("end", str, len)) {
4295 ctx->objdata &= 0xffff;
4298 if (i >= ACTION_RSS_QUEUE_NUM)
4300 arg = ARGS_ENTRY_ARB(offsetof(struct action_rss_data, queue) +
4301 i * sizeof(action_rss_data->queue[i]),
4302 sizeof(action_rss_data->queue[i]));
4303 if (push_args(ctx, arg))
4305 ret = parse_int(ctx, token, str, len, NULL, 0);
4311 ctx->objdata = i << 16 | (ctx->objdata & 0xffff);
4313 if (ctx->next_num == RTE_DIM(ctx->next))
4315 ctx->next[ctx->next_num++] = next;
4319 action_rss_data = ctx->object;
4320 action_rss_data->conf.queue_num = i;
4321 action_rss_data->conf.queue = i ? action_rss_data->queue : NULL;
4325 /** Parse VXLAN encap action. */
4327 parse_vc_action_vxlan_encap(struct context *ctx, const struct token *token,
4328 const char *str, unsigned int len,
4329 void *buf, unsigned int size)
4331 struct buffer *out = buf;
4332 struct rte_flow_action *action;
4333 struct action_vxlan_encap_data *action_vxlan_encap_data;
4336 ret = parse_vc(ctx, token, str, len, buf, size);
4339 /* Nothing else to do if there is no buffer. */
4342 if (!out->args.vc.actions_n)
4344 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4345 /* Point to selected object. */
4346 ctx->object = out->args.vc.data;
4347 ctx->objmask = NULL;
4348 /* Set up default configuration. */
4349 action_vxlan_encap_data = ctx->object;
4350 *action_vxlan_encap_data = (struct action_vxlan_encap_data){
4351 .conf = (struct rte_flow_action_vxlan_encap){
4352 .definition = action_vxlan_encap_data->items,
4356 .type = RTE_FLOW_ITEM_TYPE_ETH,
4357 .spec = &action_vxlan_encap_data->item_eth,
4358 .mask = &rte_flow_item_eth_mask,
4361 .type = RTE_FLOW_ITEM_TYPE_VLAN,
4362 .spec = &action_vxlan_encap_data->item_vlan,
4363 .mask = &rte_flow_item_vlan_mask,
4366 .type = RTE_FLOW_ITEM_TYPE_IPV4,
4367 .spec = &action_vxlan_encap_data->item_ipv4,
4368 .mask = &rte_flow_item_ipv4_mask,
4371 .type = RTE_FLOW_ITEM_TYPE_UDP,
4372 .spec = &action_vxlan_encap_data->item_udp,
4373 .mask = &rte_flow_item_udp_mask,
4376 .type = RTE_FLOW_ITEM_TYPE_VXLAN,
4377 .spec = &action_vxlan_encap_data->item_vxlan,
4378 .mask = &rte_flow_item_vxlan_mask,
4381 .type = RTE_FLOW_ITEM_TYPE_END,
4386 .tci = vxlan_encap_conf.vlan_tci,
4390 .src_addr = vxlan_encap_conf.ipv4_src,
4391 .dst_addr = vxlan_encap_conf.ipv4_dst,
4394 .src_port = vxlan_encap_conf.udp_src,
4395 .dst_port = vxlan_encap_conf.udp_dst,
4397 .item_vxlan.flags = 0,
4399 memcpy(action_vxlan_encap_data->item_eth.dst.addr_bytes,
4400 vxlan_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
4401 memcpy(action_vxlan_encap_data->item_eth.src.addr_bytes,
4402 vxlan_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
4403 if (!vxlan_encap_conf.select_ipv4) {
4404 memcpy(&action_vxlan_encap_data->item_ipv6.hdr.src_addr,
4405 &vxlan_encap_conf.ipv6_src,
4406 sizeof(vxlan_encap_conf.ipv6_src));
4407 memcpy(&action_vxlan_encap_data->item_ipv6.hdr.dst_addr,
4408 &vxlan_encap_conf.ipv6_dst,
4409 sizeof(vxlan_encap_conf.ipv6_dst));
4410 action_vxlan_encap_data->items[2] = (struct rte_flow_item){
4411 .type = RTE_FLOW_ITEM_TYPE_IPV6,
4412 .spec = &action_vxlan_encap_data->item_ipv6,
4413 .mask = &rte_flow_item_ipv6_mask,
4416 if (!vxlan_encap_conf.select_vlan)
4417 action_vxlan_encap_data->items[1].type =
4418 RTE_FLOW_ITEM_TYPE_VOID;
4419 if (vxlan_encap_conf.select_tos_ttl) {
4420 if (vxlan_encap_conf.select_ipv4) {
4421 static struct rte_flow_item_ipv4 ipv4_mask_tos;
4423 memcpy(&ipv4_mask_tos, &rte_flow_item_ipv4_mask,
4424 sizeof(ipv4_mask_tos));
4425 ipv4_mask_tos.hdr.type_of_service = 0xff;
4426 ipv4_mask_tos.hdr.time_to_live = 0xff;
4427 action_vxlan_encap_data->item_ipv4.hdr.type_of_service =
4428 vxlan_encap_conf.ip_tos;
4429 action_vxlan_encap_data->item_ipv4.hdr.time_to_live =
4430 vxlan_encap_conf.ip_ttl;
4431 action_vxlan_encap_data->items[2].mask =
4434 static struct rte_flow_item_ipv6 ipv6_mask_tos;
4436 memcpy(&ipv6_mask_tos, &rte_flow_item_ipv6_mask,
4437 sizeof(ipv6_mask_tos));
4438 ipv6_mask_tos.hdr.vtc_flow |=
4439 RTE_BE32(0xfful << RTE_IPV6_HDR_TC_SHIFT);
4440 ipv6_mask_tos.hdr.hop_limits = 0xff;
4441 action_vxlan_encap_data->item_ipv6.hdr.vtc_flow |=
4443 ((uint32_t)vxlan_encap_conf.ip_tos <<
4444 RTE_IPV6_HDR_TC_SHIFT);
4445 action_vxlan_encap_data->item_ipv6.hdr.hop_limits =
4446 vxlan_encap_conf.ip_ttl;
4447 action_vxlan_encap_data->items[2].mask =
4451 memcpy(action_vxlan_encap_data->item_vxlan.vni, vxlan_encap_conf.vni,
4452 RTE_DIM(vxlan_encap_conf.vni));
4453 action->conf = &action_vxlan_encap_data->conf;
4457 /** Parse NVGRE encap action. */
4459 parse_vc_action_nvgre_encap(struct context *ctx, const struct token *token,
4460 const char *str, unsigned int len,
4461 void *buf, unsigned int size)
4463 struct buffer *out = buf;
4464 struct rte_flow_action *action;
4465 struct action_nvgre_encap_data *action_nvgre_encap_data;
4468 ret = parse_vc(ctx, token, str, len, buf, size);
4471 /* Nothing else to do if there is no buffer. */
4474 if (!out->args.vc.actions_n)
4476 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4477 /* Point to selected object. */
4478 ctx->object = out->args.vc.data;
4479 ctx->objmask = NULL;
4480 /* Set up default configuration. */
4481 action_nvgre_encap_data = ctx->object;
4482 *action_nvgre_encap_data = (struct action_nvgre_encap_data){
4483 .conf = (struct rte_flow_action_nvgre_encap){
4484 .definition = action_nvgre_encap_data->items,
4488 .type = RTE_FLOW_ITEM_TYPE_ETH,
4489 .spec = &action_nvgre_encap_data->item_eth,
4490 .mask = &rte_flow_item_eth_mask,
4493 .type = RTE_FLOW_ITEM_TYPE_VLAN,
4494 .spec = &action_nvgre_encap_data->item_vlan,
4495 .mask = &rte_flow_item_vlan_mask,
4498 .type = RTE_FLOW_ITEM_TYPE_IPV4,
4499 .spec = &action_nvgre_encap_data->item_ipv4,
4500 .mask = &rte_flow_item_ipv4_mask,
4503 .type = RTE_FLOW_ITEM_TYPE_NVGRE,
4504 .spec = &action_nvgre_encap_data->item_nvgre,
4505 .mask = &rte_flow_item_nvgre_mask,
4508 .type = RTE_FLOW_ITEM_TYPE_END,
4513 .tci = nvgre_encap_conf.vlan_tci,
4517 .src_addr = nvgre_encap_conf.ipv4_src,
4518 .dst_addr = nvgre_encap_conf.ipv4_dst,
4520 .item_nvgre.flow_id = 0,
4522 memcpy(action_nvgre_encap_data->item_eth.dst.addr_bytes,
4523 nvgre_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
4524 memcpy(action_nvgre_encap_data->item_eth.src.addr_bytes,
4525 nvgre_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
4526 if (!nvgre_encap_conf.select_ipv4) {
4527 memcpy(&action_nvgre_encap_data->item_ipv6.hdr.src_addr,
4528 &nvgre_encap_conf.ipv6_src,
4529 sizeof(nvgre_encap_conf.ipv6_src));
4530 memcpy(&action_nvgre_encap_data->item_ipv6.hdr.dst_addr,
4531 &nvgre_encap_conf.ipv6_dst,
4532 sizeof(nvgre_encap_conf.ipv6_dst));
4533 action_nvgre_encap_data->items[2] = (struct rte_flow_item){
4534 .type = RTE_FLOW_ITEM_TYPE_IPV6,
4535 .spec = &action_nvgre_encap_data->item_ipv6,
4536 .mask = &rte_flow_item_ipv6_mask,
4539 if (!nvgre_encap_conf.select_vlan)
4540 action_nvgre_encap_data->items[1].type =
4541 RTE_FLOW_ITEM_TYPE_VOID;
4542 memcpy(action_nvgre_encap_data->item_nvgre.tni, nvgre_encap_conf.tni,
4543 RTE_DIM(nvgre_encap_conf.tni));
4544 action->conf = &action_nvgre_encap_data->conf;
4548 /** Parse l2 encap action. */
4550 parse_vc_action_l2_encap(struct context *ctx, const struct token *token,
4551 const char *str, unsigned int len,
4552 void *buf, unsigned int size)
4554 struct buffer *out = buf;
4555 struct rte_flow_action *action;
4556 struct action_raw_encap_data *action_encap_data;
4557 struct rte_flow_item_eth eth = { .type = 0, };
4558 struct rte_flow_item_vlan vlan = {
4559 .tci = mplsoudp_encap_conf.vlan_tci,
4565 ret = parse_vc(ctx, token, str, len, buf, size);
4568 /* Nothing else to do if there is no buffer. */
4571 if (!out->args.vc.actions_n)
4573 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4574 /* Point to selected object. */
4575 ctx->object = out->args.vc.data;
4576 ctx->objmask = NULL;
4577 /* Copy the headers to the buffer. */
4578 action_encap_data = ctx->object;
4579 *action_encap_data = (struct action_raw_encap_data) {
4580 .conf = (struct rte_flow_action_raw_encap){
4581 .data = action_encap_data->data,
4585 header = action_encap_data->data;
4586 if (l2_encap_conf.select_vlan)
4587 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
4588 else if (l2_encap_conf.select_ipv4)
4589 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4591 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4592 memcpy(eth.dst.addr_bytes,
4593 l2_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
4594 memcpy(eth.src.addr_bytes,
4595 l2_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
4596 memcpy(header, ð, sizeof(eth));
4597 header += sizeof(eth);
4598 if (l2_encap_conf.select_vlan) {
4599 if (l2_encap_conf.select_ipv4)
4600 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4602 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4603 memcpy(header, &vlan, sizeof(vlan));
4604 header += sizeof(vlan);
4606 action_encap_data->conf.size = header -
4607 action_encap_data->data;
4608 action->conf = &action_encap_data->conf;
4612 /** Parse l2 decap action. */
4614 parse_vc_action_l2_decap(struct context *ctx, const struct token *token,
4615 const char *str, unsigned int len,
4616 void *buf, unsigned int size)
4618 struct buffer *out = buf;
4619 struct rte_flow_action *action;
4620 struct action_raw_decap_data *action_decap_data;
4621 struct rte_flow_item_eth eth = { .type = 0, };
4622 struct rte_flow_item_vlan vlan = {
4623 .tci = mplsoudp_encap_conf.vlan_tci,
4629 ret = parse_vc(ctx, token, str, len, buf, size);
4632 /* Nothing else to do if there is no buffer. */
4635 if (!out->args.vc.actions_n)
4637 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4638 /* Point to selected object. */
4639 ctx->object = out->args.vc.data;
4640 ctx->objmask = NULL;
4641 /* Copy the headers to the buffer. */
4642 action_decap_data = ctx->object;
4643 *action_decap_data = (struct action_raw_decap_data) {
4644 .conf = (struct rte_flow_action_raw_decap){
4645 .data = action_decap_data->data,
4649 header = action_decap_data->data;
4650 if (l2_decap_conf.select_vlan)
4651 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
4652 memcpy(header, ð, sizeof(eth));
4653 header += sizeof(eth);
4654 if (l2_decap_conf.select_vlan) {
4655 memcpy(header, &vlan, sizeof(vlan));
4656 header += sizeof(vlan);
4658 action_decap_data->conf.size = header -
4659 action_decap_data->data;
4660 action->conf = &action_decap_data->conf;
4664 #define ETHER_TYPE_MPLS_UNICAST 0x8847
4666 /** Parse MPLSOGRE encap action. */
4668 parse_vc_action_mplsogre_encap(struct context *ctx, const struct token *token,
4669 const char *str, unsigned int len,
4670 void *buf, unsigned int size)
4672 struct buffer *out = buf;
4673 struct rte_flow_action *action;
4674 struct action_raw_encap_data *action_encap_data;
4675 struct rte_flow_item_eth eth = { .type = 0, };
4676 struct rte_flow_item_vlan vlan = {
4677 .tci = mplsogre_encap_conf.vlan_tci,
4680 struct rte_flow_item_ipv4 ipv4 = {
4682 .src_addr = mplsogre_encap_conf.ipv4_src,
4683 .dst_addr = mplsogre_encap_conf.ipv4_dst,
4684 .next_proto_id = IPPROTO_GRE,
4685 .version_ihl = RTE_IPV4_VHL_DEF,
4686 .time_to_live = IPDEFTTL,
4689 struct rte_flow_item_ipv6 ipv6 = {
4691 .proto = IPPROTO_GRE,
4692 .hop_limits = IPDEFTTL,
4695 struct rte_flow_item_gre gre = {
4696 .protocol = rte_cpu_to_be_16(ETHER_TYPE_MPLS_UNICAST),
4698 struct rte_flow_item_mpls mpls = {
4704 ret = parse_vc(ctx, token, str, len, buf, size);
4707 /* Nothing else to do if there is no buffer. */
4710 if (!out->args.vc.actions_n)
4712 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4713 /* Point to selected object. */
4714 ctx->object = out->args.vc.data;
4715 ctx->objmask = NULL;
4716 /* Copy the headers to the buffer. */
4717 action_encap_data = ctx->object;
4718 *action_encap_data = (struct action_raw_encap_data) {
4719 .conf = (struct rte_flow_action_raw_encap){
4720 .data = action_encap_data->data,
4725 header = action_encap_data->data;
4726 if (mplsogre_encap_conf.select_vlan)
4727 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
4728 else if (mplsogre_encap_conf.select_ipv4)
4729 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4731 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4732 memcpy(eth.dst.addr_bytes,
4733 mplsogre_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
4734 memcpy(eth.src.addr_bytes,
4735 mplsogre_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
4736 memcpy(header, ð, sizeof(eth));
4737 header += sizeof(eth);
4738 if (mplsogre_encap_conf.select_vlan) {
4739 if (mplsogre_encap_conf.select_ipv4)
4740 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4742 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4743 memcpy(header, &vlan, sizeof(vlan));
4744 header += sizeof(vlan);
4746 if (mplsogre_encap_conf.select_ipv4) {
4747 memcpy(header, &ipv4, sizeof(ipv4));
4748 header += sizeof(ipv4);
4750 memcpy(&ipv6.hdr.src_addr,
4751 &mplsogre_encap_conf.ipv6_src,
4752 sizeof(mplsogre_encap_conf.ipv6_src));
4753 memcpy(&ipv6.hdr.dst_addr,
4754 &mplsogre_encap_conf.ipv6_dst,
4755 sizeof(mplsogre_encap_conf.ipv6_dst));
4756 memcpy(header, &ipv6, sizeof(ipv6));
4757 header += sizeof(ipv6);
4759 memcpy(header, &gre, sizeof(gre));
4760 header += sizeof(gre);
4761 memcpy(mpls.label_tc_s, mplsogre_encap_conf.label,
4762 RTE_DIM(mplsogre_encap_conf.label));
4763 mpls.label_tc_s[2] |= 0x1;
4764 memcpy(header, &mpls, sizeof(mpls));
4765 header += sizeof(mpls);
4766 action_encap_data->conf.size = header -
4767 action_encap_data->data;
4768 action->conf = &action_encap_data->conf;
4772 /** Parse MPLSOGRE decap action. */
4774 parse_vc_action_mplsogre_decap(struct context *ctx, const struct token *token,
4775 const char *str, unsigned int len,
4776 void *buf, unsigned int size)
4778 struct buffer *out = buf;
4779 struct rte_flow_action *action;
4780 struct action_raw_decap_data *action_decap_data;
4781 struct rte_flow_item_eth eth = { .type = 0, };
4782 struct rte_flow_item_vlan vlan = {.tci = 0};
4783 struct rte_flow_item_ipv4 ipv4 = {
4785 .next_proto_id = IPPROTO_GRE,
4788 struct rte_flow_item_ipv6 ipv6 = {
4790 .proto = IPPROTO_GRE,
4793 struct rte_flow_item_gre gre = {
4794 .protocol = rte_cpu_to_be_16(ETHER_TYPE_MPLS_UNICAST),
4796 struct rte_flow_item_mpls mpls;
4800 ret = parse_vc(ctx, token, str, len, buf, size);
4803 /* Nothing else to do if there is no buffer. */
4806 if (!out->args.vc.actions_n)
4808 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4809 /* Point to selected object. */
4810 ctx->object = out->args.vc.data;
4811 ctx->objmask = NULL;
4812 /* Copy the headers to the buffer. */
4813 action_decap_data = ctx->object;
4814 *action_decap_data = (struct action_raw_decap_data) {
4815 .conf = (struct rte_flow_action_raw_decap){
4816 .data = action_decap_data->data,
4820 header = action_decap_data->data;
4821 if (mplsogre_decap_conf.select_vlan)
4822 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
4823 else if (mplsogre_encap_conf.select_ipv4)
4824 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4826 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4827 memcpy(eth.dst.addr_bytes,
4828 mplsogre_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
4829 memcpy(eth.src.addr_bytes,
4830 mplsogre_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
4831 memcpy(header, ð, sizeof(eth));
4832 header += sizeof(eth);
4833 if (mplsogre_encap_conf.select_vlan) {
4834 if (mplsogre_encap_conf.select_ipv4)
4835 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4837 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4838 memcpy(header, &vlan, sizeof(vlan));
4839 header += sizeof(vlan);
4841 if (mplsogre_encap_conf.select_ipv4) {
4842 memcpy(header, &ipv4, sizeof(ipv4));
4843 header += sizeof(ipv4);
4845 memcpy(header, &ipv6, sizeof(ipv6));
4846 header += sizeof(ipv6);
4848 memcpy(header, &gre, sizeof(gre));
4849 header += sizeof(gre);
4850 memset(&mpls, 0, sizeof(mpls));
4851 memcpy(header, &mpls, sizeof(mpls));
4852 header += sizeof(mpls);
4853 action_decap_data->conf.size = header -
4854 action_decap_data->data;
4855 action->conf = &action_decap_data->conf;
4859 /** Parse MPLSOUDP encap action. */
4861 parse_vc_action_mplsoudp_encap(struct context *ctx, const struct token *token,
4862 const char *str, unsigned int len,
4863 void *buf, unsigned int size)
4865 struct buffer *out = buf;
4866 struct rte_flow_action *action;
4867 struct action_raw_encap_data *action_encap_data;
4868 struct rte_flow_item_eth eth = { .type = 0, };
4869 struct rte_flow_item_vlan vlan = {
4870 .tci = mplsoudp_encap_conf.vlan_tci,
4873 struct rte_flow_item_ipv4 ipv4 = {
4875 .src_addr = mplsoudp_encap_conf.ipv4_src,
4876 .dst_addr = mplsoudp_encap_conf.ipv4_dst,
4877 .next_proto_id = IPPROTO_UDP,
4878 .version_ihl = RTE_IPV4_VHL_DEF,
4879 .time_to_live = IPDEFTTL,
4882 struct rte_flow_item_ipv6 ipv6 = {
4884 .proto = IPPROTO_UDP,
4885 .hop_limits = IPDEFTTL,
4888 struct rte_flow_item_udp udp = {
4890 .src_port = mplsoudp_encap_conf.udp_src,
4891 .dst_port = mplsoudp_encap_conf.udp_dst,
4894 struct rte_flow_item_mpls mpls;
4898 ret = parse_vc(ctx, token, str, len, buf, size);
4901 /* Nothing else to do if there is no buffer. */
4904 if (!out->args.vc.actions_n)
4906 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4907 /* Point to selected object. */
4908 ctx->object = out->args.vc.data;
4909 ctx->objmask = NULL;
4910 /* Copy the headers to the buffer. */
4911 action_encap_data = ctx->object;
4912 *action_encap_data = (struct action_raw_encap_data) {
4913 .conf = (struct rte_flow_action_raw_encap){
4914 .data = action_encap_data->data,
4919 header = action_encap_data->data;
4920 if (mplsoudp_encap_conf.select_vlan)
4921 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
4922 else if (mplsoudp_encap_conf.select_ipv4)
4923 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4925 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4926 memcpy(eth.dst.addr_bytes,
4927 mplsoudp_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
4928 memcpy(eth.src.addr_bytes,
4929 mplsoudp_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
4930 memcpy(header, ð, sizeof(eth));
4931 header += sizeof(eth);
4932 if (mplsoudp_encap_conf.select_vlan) {
4933 if (mplsoudp_encap_conf.select_ipv4)
4934 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4936 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4937 memcpy(header, &vlan, sizeof(vlan));
4938 header += sizeof(vlan);
4940 if (mplsoudp_encap_conf.select_ipv4) {
4941 memcpy(header, &ipv4, sizeof(ipv4));
4942 header += sizeof(ipv4);
4944 memcpy(&ipv6.hdr.src_addr,
4945 &mplsoudp_encap_conf.ipv6_src,
4946 sizeof(mplsoudp_encap_conf.ipv6_src));
4947 memcpy(&ipv6.hdr.dst_addr,
4948 &mplsoudp_encap_conf.ipv6_dst,
4949 sizeof(mplsoudp_encap_conf.ipv6_dst));
4950 memcpy(header, &ipv6, sizeof(ipv6));
4951 header += sizeof(ipv6);
4953 memcpy(header, &udp, sizeof(udp));
4954 header += sizeof(udp);
4955 memcpy(mpls.label_tc_s, mplsoudp_encap_conf.label,
4956 RTE_DIM(mplsoudp_encap_conf.label));
4957 mpls.label_tc_s[2] |= 0x1;
4958 memcpy(header, &mpls, sizeof(mpls));
4959 header += sizeof(mpls);
4960 action_encap_data->conf.size = header -
4961 action_encap_data->data;
4962 action->conf = &action_encap_data->conf;
4966 /** Parse MPLSOUDP decap action. */
4968 parse_vc_action_mplsoudp_decap(struct context *ctx, const struct token *token,
4969 const char *str, unsigned int len,
4970 void *buf, unsigned int size)
4972 struct buffer *out = buf;
4973 struct rte_flow_action *action;
4974 struct action_raw_decap_data *action_decap_data;
4975 struct rte_flow_item_eth eth = { .type = 0, };
4976 struct rte_flow_item_vlan vlan = {.tci = 0};
4977 struct rte_flow_item_ipv4 ipv4 = {
4979 .next_proto_id = IPPROTO_UDP,
4982 struct rte_flow_item_ipv6 ipv6 = {
4984 .proto = IPPROTO_UDP,
4987 struct rte_flow_item_udp udp = {
4989 .dst_port = rte_cpu_to_be_16(6635),
4992 struct rte_flow_item_mpls mpls;
4996 ret = parse_vc(ctx, token, str, len, buf, size);
4999 /* Nothing else to do if there is no buffer. */
5002 if (!out->args.vc.actions_n)
5004 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
5005 /* Point to selected object. */
5006 ctx->object = out->args.vc.data;
5007 ctx->objmask = NULL;
5008 /* Copy the headers to the buffer. */
5009 action_decap_data = ctx->object;
5010 *action_decap_data = (struct action_raw_decap_data) {
5011 .conf = (struct rte_flow_action_raw_decap){
5012 .data = action_decap_data->data,
5016 header = action_decap_data->data;
5017 if (mplsoudp_decap_conf.select_vlan)
5018 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
5019 else if (mplsoudp_encap_conf.select_ipv4)
5020 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
5022 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
5023 memcpy(eth.dst.addr_bytes,
5024 mplsoudp_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
5025 memcpy(eth.src.addr_bytes,
5026 mplsoudp_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
5027 memcpy(header, ð, sizeof(eth));
5028 header += sizeof(eth);
5029 if (mplsoudp_encap_conf.select_vlan) {
5030 if (mplsoudp_encap_conf.select_ipv4)
5031 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
5033 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
5034 memcpy(header, &vlan, sizeof(vlan));
5035 header += sizeof(vlan);
5037 if (mplsoudp_encap_conf.select_ipv4) {
5038 memcpy(header, &ipv4, sizeof(ipv4));
5039 header += sizeof(ipv4);
5041 memcpy(header, &ipv6, sizeof(ipv6));
5042 header += sizeof(ipv6);
5044 memcpy(header, &udp, sizeof(udp));
5045 header += sizeof(udp);
5046 memset(&mpls, 0, sizeof(mpls));
5047 memcpy(header, &mpls, sizeof(mpls));
5048 header += sizeof(mpls);
5049 action_decap_data->conf.size = header -
5050 action_decap_data->data;
5051 action->conf = &action_decap_data->conf;
5056 parse_vc_action_raw_decap_index(struct context *ctx, const struct token *token,
5057 const char *str, unsigned int len, void *buf,
5060 struct action_raw_decap_data *action_raw_decap_data;
5061 struct rte_flow_action *action;
5062 const struct arg *arg;
5063 struct buffer *out = buf;
5067 RTE_SET_USED(token);
5070 arg = ARGS_ENTRY_ARB_BOUNDED
5071 (offsetof(struct action_raw_decap_data, idx),
5072 sizeof(((struct action_raw_decap_data *)0)->idx),
5073 0, RAW_ENCAP_CONFS_MAX_NUM - 1);
5074 if (push_args(ctx, arg))
5076 ret = parse_int(ctx, token, str, len, NULL, 0);
5083 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
5084 action_raw_decap_data = ctx->object;
5085 idx = action_raw_decap_data->idx;
5086 action_raw_decap_data->conf.data = raw_decap_confs[idx].data;
5087 action_raw_decap_data->conf.size = raw_decap_confs[idx].size;
5088 action->conf = &action_raw_decap_data->conf;
5094 parse_vc_action_raw_encap_index(struct context *ctx, const struct token *token,
5095 const char *str, unsigned int len, void *buf,
5098 struct action_raw_encap_data *action_raw_encap_data;
5099 struct rte_flow_action *action;
5100 const struct arg *arg;
5101 struct buffer *out = buf;
5105 RTE_SET_USED(token);
5108 if (ctx->curr != ACTION_RAW_ENCAP_INDEX_VALUE)
5110 arg = ARGS_ENTRY_ARB_BOUNDED
5111 (offsetof(struct action_raw_encap_data, idx),
5112 sizeof(((struct action_raw_encap_data *)0)->idx),
5113 0, RAW_ENCAP_CONFS_MAX_NUM - 1);
5114 if (push_args(ctx, arg))
5116 ret = parse_int(ctx, token, str, len, NULL, 0);
5123 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
5124 action_raw_encap_data = ctx->object;
5125 idx = action_raw_encap_data->idx;
5126 action_raw_encap_data->conf.data = raw_encap_confs[idx].data;
5127 action_raw_encap_data->conf.size = raw_encap_confs[idx].size;
5128 action_raw_encap_data->conf.preserve = NULL;
5129 action->conf = &action_raw_encap_data->conf;
5134 parse_vc_action_raw_encap(struct context *ctx, const struct token *token,
5135 const char *str, unsigned int len, void *buf,
5138 struct buffer *out = buf;
5139 struct rte_flow_action *action;
5140 struct action_raw_encap_data *action_raw_encap_data = NULL;
5143 ret = parse_vc(ctx, token, str, len, buf, size);
5146 /* Nothing else to do if there is no buffer. */
5149 if (!out->args.vc.actions_n)
5151 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
5152 /* Point to selected object. */
5153 ctx->object = out->args.vc.data;
5154 ctx->objmask = NULL;
5155 /* Copy the headers to the buffer. */
5156 action_raw_encap_data = ctx->object;
5157 action_raw_encap_data->conf.data = raw_encap_confs[0].data;
5158 action_raw_encap_data->conf.preserve = NULL;
5159 action_raw_encap_data->conf.size = raw_encap_confs[0].size;
5160 action->conf = &action_raw_encap_data->conf;
5165 parse_vc_action_raw_decap(struct context *ctx, const struct token *token,
5166 const char *str, unsigned int len, void *buf,
5169 struct buffer *out = buf;
5170 struct rte_flow_action *action;
5171 struct action_raw_decap_data *action_raw_decap_data = NULL;
5174 ret = parse_vc(ctx, token, str, len, buf, size);
5177 /* Nothing else to do if there is no buffer. */
5180 if (!out->args.vc.actions_n)
5182 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
5183 /* Point to selected object. */
5184 ctx->object = out->args.vc.data;
5185 ctx->objmask = NULL;
5186 /* Copy the headers to the buffer. */
5187 action_raw_decap_data = ctx->object;
5188 action_raw_decap_data->conf.data = raw_decap_confs[0].data;
5189 action_raw_decap_data->conf.size = raw_decap_confs[0].size;
5190 action->conf = &action_raw_decap_data->conf;
5195 parse_vc_action_set_meta(struct context *ctx, const struct token *token,
5196 const char *str, unsigned int len, void *buf,
5201 ret = parse_vc(ctx, token, str, len, buf, size);
5204 ret = rte_flow_dynf_metadata_register();
5210 /** Parse tokens for destroy command. */
5212 parse_destroy(struct context *ctx, const struct token *token,
5213 const char *str, unsigned int len,
5214 void *buf, unsigned int size)
5216 struct buffer *out = buf;
5218 /* Token name must match. */
5219 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5221 /* Nothing else to do if there is no buffer. */
5224 if (!out->command) {
5225 if (ctx->curr != DESTROY)
5227 if (sizeof(*out) > size)
5229 out->command = ctx->curr;
5232 ctx->objmask = NULL;
5233 out->args.destroy.rule =
5234 (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
5238 if (((uint8_t *)(out->args.destroy.rule + out->args.destroy.rule_n) +
5239 sizeof(*out->args.destroy.rule)) > (uint8_t *)out + size)
5242 ctx->object = out->args.destroy.rule + out->args.destroy.rule_n++;
5243 ctx->objmask = NULL;
5247 /** Parse tokens for flush command. */
5249 parse_flush(struct context *ctx, const struct token *token,
5250 const char *str, unsigned int len,
5251 void *buf, unsigned int size)
5253 struct buffer *out = buf;
5255 /* Token name must match. */
5256 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5258 /* Nothing else to do if there is no buffer. */
5261 if (!out->command) {
5262 if (ctx->curr != FLUSH)
5264 if (sizeof(*out) > size)
5266 out->command = ctx->curr;
5269 ctx->objmask = NULL;
5274 /** Parse tokens for dump command. */
5276 parse_dump(struct context *ctx, const struct token *token,
5277 const char *str, unsigned int len,
5278 void *buf, unsigned int size)
5280 struct buffer *out = buf;
5282 /* Token name must match. */
5283 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5285 /* Nothing else to do if there is no buffer. */
5288 if (!out->command) {
5289 if (ctx->curr != DUMP)
5291 if (sizeof(*out) > size)
5293 out->command = ctx->curr;
5296 ctx->objmask = NULL;
5301 /** Parse tokens for query command. */
5303 parse_query(struct context *ctx, const struct token *token,
5304 const char *str, unsigned int len,
5305 void *buf, unsigned int size)
5307 struct buffer *out = buf;
5309 /* Token name must match. */
5310 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5312 /* Nothing else to do if there is no buffer. */
5315 if (!out->command) {
5316 if (ctx->curr != QUERY)
5318 if (sizeof(*out) > size)
5320 out->command = ctx->curr;
5323 ctx->objmask = NULL;
5328 /** Parse action names. */
5330 parse_action(struct context *ctx, const struct token *token,
5331 const char *str, unsigned int len,
5332 void *buf, unsigned int size)
5334 struct buffer *out = buf;
5335 const struct arg *arg = pop_args(ctx);
5339 /* Argument is expected. */
5342 /* Parse action name. */
5343 for (i = 0; next_action[i]; ++i) {
5344 const struct parse_action_priv *priv;
5346 token = &token_list[next_action[i]];
5347 if (strcmp_partial(token->name, str, len))
5353 memcpy((uint8_t *)ctx->object + arg->offset,
5359 push_args(ctx, arg);
5363 /** Parse tokens for list command. */
5365 parse_list(struct context *ctx, const struct token *token,
5366 const char *str, unsigned int len,
5367 void *buf, unsigned int size)
5369 struct buffer *out = buf;
5371 /* Token name must match. */
5372 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5374 /* Nothing else to do if there is no buffer. */
5377 if (!out->command) {
5378 if (ctx->curr != LIST)
5380 if (sizeof(*out) > size)
5382 out->command = ctx->curr;
5385 ctx->objmask = NULL;
5386 out->args.list.group =
5387 (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
5391 if (((uint8_t *)(out->args.list.group + out->args.list.group_n) +
5392 sizeof(*out->args.list.group)) > (uint8_t *)out + size)
5395 ctx->object = out->args.list.group + out->args.list.group_n++;
5396 ctx->objmask = NULL;
5400 /** Parse tokens for list all aged flows command. */
5402 parse_aged(struct context *ctx, const struct token *token,
5403 const char *str, unsigned int len,
5404 void *buf, unsigned int size)
5406 struct buffer *out = buf;
5408 /* Token name must match. */
5409 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5411 /* Nothing else to do if there is no buffer. */
5414 if (!out->command) {
5415 if (ctx->curr != AGED)
5417 if (sizeof(*out) > size)
5419 out->command = ctx->curr;
5422 ctx->objmask = NULL;
5424 if (ctx->curr == AGED_DESTROY)
5425 out->args.aged.destroy = 1;
5429 /** Parse tokens for isolate command. */
5431 parse_isolate(struct context *ctx, const struct token *token,
5432 const char *str, unsigned int len,
5433 void *buf, unsigned int size)
5435 struct buffer *out = buf;
5437 /* Token name must match. */
5438 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5440 /* Nothing else to do if there is no buffer. */
5443 if (!out->command) {
5444 if (ctx->curr != ISOLATE)
5446 if (sizeof(*out) > size)
5448 out->command = ctx->curr;
5451 ctx->objmask = NULL;
5457 * Parse signed/unsigned integers 8 to 64-bit long.
5459 * Last argument (ctx->args) is retrieved to determine integer type and
5463 parse_int(struct context *ctx, const struct token *token,
5464 const char *str, unsigned int len,
5465 void *buf, unsigned int size)
5467 const struct arg *arg = pop_args(ctx);
5472 /* Argument is expected. */
5477 (uintmax_t)strtoimax(str, &end, 0) :
5478 strtoumax(str, &end, 0);
5479 if (errno || (size_t)(end - str) != len)
5482 ((arg->sign && ((intmax_t)u < (intmax_t)arg->min ||
5483 (intmax_t)u > (intmax_t)arg->max)) ||
5484 (!arg->sign && (u < arg->min || u > arg->max))))
5489 if (!arg_entry_bf_fill(ctx->object, u, arg) ||
5490 !arg_entry_bf_fill(ctx->objmask, -1, arg))
5494 buf = (uint8_t *)ctx->object + arg->offset;
5496 if (u > RTE_LEN2MASK(size * CHAR_BIT, uint64_t))
5500 case sizeof(uint8_t):
5501 *(uint8_t *)buf = u;
5503 case sizeof(uint16_t):
5504 *(uint16_t *)buf = arg->hton ? rte_cpu_to_be_16(u) : u;
5506 case sizeof(uint8_t [3]):
5507 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
5509 ((uint8_t *)buf)[0] = u;
5510 ((uint8_t *)buf)[1] = u >> 8;
5511 ((uint8_t *)buf)[2] = u >> 16;
5515 ((uint8_t *)buf)[0] = u >> 16;
5516 ((uint8_t *)buf)[1] = u >> 8;
5517 ((uint8_t *)buf)[2] = u;
5519 case sizeof(uint32_t):
5520 *(uint32_t *)buf = arg->hton ? rte_cpu_to_be_32(u) : u;
5522 case sizeof(uint64_t):
5523 *(uint64_t *)buf = arg->hton ? rte_cpu_to_be_64(u) : u;
5528 if (ctx->objmask && buf != (uint8_t *)ctx->objmask + arg->offset) {
5530 buf = (uint8_t *)ctx->objmask + arg->offset;
5535 push_args(ctx, arg);
5542 * Three arguments (ctx->args) are retrieved from the stack to store data,
5543 * its actual length and address (in that order).
5546 parse_string(struct context *ctx, const struct token *token,
5547 const char *str, unsigned int len,
5548 void *buf, unsigned int size)
5550 const struct arg *arg_data = pop_args(ctx);
5551 const struct arg *arg_len = pop_args(ctx);
5552 const struct arg *arg_addr = pop_args(ctx);
5553 char tmp[16]; /* Ought to be enough. */
5556 /* Arguments are expected. */
5560 push_args(ctx, arg_data);
5564 push_args(ctx, arg_len);
5565 push_args(ctx, arg_data);
5568 size = arg_data->size;
5569 /* Bit-mask fill is not supported. */
5570 if (arg_data->mask || size < len)
5574 /* Let parse_int() fill length information first. */
5575 ret = snprintf(tmp, sizeof(tmp), "%u", len);
5578 push_args(ctx, arg_len);
5579 ret = parse_int(ctx, token, tmp, ret, NULL, 0);
5584 buf = (uint8_t *)ctx->object + arg_data->offset;
5585 /* Output buffer is not necessarily NUL-terminated. */
5586 memcpy(buf, str, len);
5587 memset((uint8_t *)buf + len, 0x00, size - len);
5589 memset((uint8_t *)ctx->objmask + arg_data->offset, 0xff, len);
5590 /* Save address if requested. */
5591 if (arg_addr->size) {
5592 memcpy((uint8_t *)ctx->object + arg_addr->offset,
5594 (uint8_t *)ctx->object + arg_data->offset
5598 memcpy((uint8_t *)ctx->objmask + arg_addr->offset,
5600 (uint8_t *)ctx->objmask + arg_data->offset
5606 push_args(ctx, arg_addr);
5607 push_args(ctx, arg_len);
5608 push_args(ctx, arg_data);
5613 parse_hex_string(const char *src, uint8_t *dst, uint32_t *size)
5619 /* Check input parameters */
5620 if ((src == NULL) ||
5626 /* Convert chars to bytes */
5627 for (i = 0, len = 0; i < *size; i += 2) {
5628 snprintf(tmp, 3, "%s", src + i);
5629 dst[len++] = strtoul(tmp, &c, 16);
5644 parse_hex(struct context *ctx, const struct token *token,
5645 const char *str, unsigned int len,
5646 void *buf, unsigned int size)
5648 const struct arg *arg_data = pop_args(ctx);
5649 const struct arg *arg_len = pop_args(ctx);
5650 const struct arg *arg_addr = pop_args(ctx);
5651 char tmp[16]; /* Ought to be enough. */
5653 unsigned int hexlen = len;
5654 unsigned int length = 256;
5655 uint8_t hex_tmp[length];
5657 /* Arguments are expected. */
5661 push_args(ctx, arg_data);
5665 push_args(ctx, arg_len);
5666 push_args(ctx, arg_data);
5669 size = arg_data->size;
5670 /* Bit-mask fill is not supported. */
5676 /* translate bytes string to array. */
5677 if (str[0] == '0' && ((str[1] == 'x') ||
5682 if (hexlen > length)
5684 ret = parse_hex_string(str, hex_tmp, &hexlen);
5687 /* Let parse_int() fill length information first. */
5688 ret = snprintf(tmp, sizeof(tmp), "%u", hexlen);
5691 push_args(ctx, arg_len);
5692 ret = parse_int(ctx, token, tmp, ret, NULL, 0);
5697 buf = (uint8_t *)ctx->object + arg_data->offset;
5698 /* Output buffer is not necessarily NUL-terminated. */
5699 memcpy(buf, hex_tmp, hexlen);
5700 memset((uint8_t *)buf + hexlen, 0x00, size - hexlen);
5702 memset((uint8_t *)ctx->objmask + arg_data->offset,
5704 /* Save address if requested. */
5705 if (arg_addr->size) {
5706 memcpy((uint8_t *)ctx->object + arg_addr->offset,
5708 (uint8_t *)ctx->object + arg_data->offset
5712 memcpy((uint8_t *)ctx->objmask + arg_addr->offset,
5714 (uint8_t *)ctx->objmask + arg_data->offset
5720 push_args(ctx, arg_addr);
5721 push_args(ctx, arg_len);
5722 push_args(ctx, arg_data);
5728 * Parse a zero-ended string.
5731 parse_string0(struct context *ctx, const struct token *token __rte_unused,
5732 const char *str, unsigned int len,
5733 void *buf, unsigned int size)
5735 const struct arg *arg_data = pop_args(ctx);
5737 /* Arguments are expected. */
5740 size = arg_data->size;
5741 /* Bit-mask fill is not supported. */
5742 if (arg_data->mask || size < len + 1)
5746 buf = (uint8_t *)ctx->object + arg_data->offset;
5747 strncpy(buf, str, len);
5749 memset((uint8_t *)ctx->objmask + arg_data->offset, 0xff, len);
5752 push_args(ctx, arg_data);
5757 * Parse a MAC address.
5759 * Last argument (ctx->args) is retrieved to determine storage size and
5763 parse_mac_addr(struct context *ctx, const struct token *token,
5764 const char *str, unsigned int len,
5765 void *buf, unsigned int size)
5767 const struct arg *arg = pop_args(ctx);
5768 struct rte_ether_addr tmp;
5772 /* Argument is expected. */
5776 /* Bit-mask fill is not supported. */
5777 if (arg->mask || size != sizeof(tmp))
5779 /* Only network endian is supported. */
5782 ret = cmdline_parse_etheraddr(NULL, str, &tmp, size);
5783 if (ret < 0 || (unsigned int)ret != len)
5787 buf = (uint8_t *)ctx->object + arg->offset;
5788 memcpy(buf, &tmp, size);
5790 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
5793 push_args(ctx, arg);
5798 * Parse an IPv4 address.
5800 * Last argument (ctx->args) is retrieved to determine storage size and
5804 parse_ipv4_addr(struct context *ctx, const struct token *token,
5805 const char *str, unsigned int len,
5806 void *buf, unsigned int size)
5808 const struct arg *arg = pop_args(ctx);
5813 /* Argument is expected. */
5817 /* Bit-mask fill is not supported. */
5818 if (arg->mask || size != sizeof(tmp))
5820 /* Only network endian is supported. */
5823 memcpy(str2, str, len);
5825 ret = inet_pton(AF_INET, str2, &tmp);
5827 /* Attempt integer parsing. */
5828 push_args(ctx, arg);
5829 return parse_int(ctx, token, str, len, buf, size);
5833 buf = (uint8_t *)ctx->object + arg->offset;
5834 memcpy(buf, &tmp, size);
5836 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
5839 push_args(ctx, arg);
5844 * Parse an IPv6 address.
5846 * Last argument (ctx->args) is retrieved to determine storage size and
5850 parse_ipv6_addr(struct context *ctx, const struct token *token,
5851 const char *str, unsigned int len,
5852 void *buf, unsigned int size)
5854 const struct arg *arg = pop_args(ctx);
5856 struct in6_addr tmp;
5860 /* Argument is expected. */
5864 /* Bit-mask fill is not supported. */
5865 if (arg->mask || size != sizeof(tmp))
5867 /* Only network endian is supported. */
5870 memcpy(str2, str, len);
5872 ret = inet_pton(AF_INET6, str2, &tmp);
5877 buf = (uint8_t *)ctx->object + arg->offset;
5878 memcpy(buf, &tmp, size);
5880 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
5883 push_args(ctx, arg);
5887 /** Boolean values (even indices stand for false). */
5888 static const char *const boolean_name[] = {
5898 * Parse a boolean value.
5900 * Last argument (ctx->args) is retrieved to determine storage size and
5904 parse_boolean(struct context *ctx, const struct token *token,
5905 const char *str, unsigned int len,
5906 void *buf, unsigned int size)
5908 const struct arg *arg = pop_args(ctx);
5912 /* Argument is expected. */
5915 for (i = 0; boolean_name[i]; ++i)
5916 if (!strcmp_partial(boolean_name[i], str, len))
5918 /* Process token as integer. */
5919 if (boolean_name[i])
5920 str = i & 1 ? "1" : "0";
5921 push_args(ctx, arg);
5922 ret = parse_int(ctx, token, str, strlen(str), buf, size);
5923 return ret > 0 ? (int)len : ret;
5926 /** Parse port and update context. */
5928 parse_port(struct context *ctx, const struct token *token,
5929 const char *str, unsigned int len,
5930 void *buf, unsigned int size)
5932 struct buffer *out = &(struct buffer){ .port = 0 };
5940 ctx->objmask = NULL;
5941 size = sizeof(*out);
5943 ret = parse_int(ctx, token, str, len, out, size);
5945 ctx->port = out->port;
5951 /** Parse set command, initialize output buffer for subsequent tokens. */
5953 parse_set_raw_encap_decap(struct context *ctx, const struct token *token,
5954 const char *str, unsigned int len,
5955 void *buf, unsigned int size)
5957 struct buffer *out = buf;
5959 /* Token name must match. */
5960 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5962 /* Nothing else to do if there is no buffer. */
5965 /* Make sure buffer is large enough. */
5966 if (size < sizeof(*out))
5969 ctx->objmask = NULL;
5973 out->command = ctx->curr;
5978 * Parse set raw_encap/raw_decap command,
5979 * initialize output buffer for subsequent tokens.
5982 parse_set_init(struct context *ctx, const struct token *token,
5983 const char *str, unsigned int len,
5984 void *buf, unsigned int size)
5986 struct buffer *out = buf;
5988 /* Token name must match. */
5989 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5991 /* Nothing else to do if there is no buffer. */
5994 /* Make sure buffer is large enough. */
5995 if (size < sizeof(*out))
5997 /* Initialize buffer. */
5998 memset(out, 0x00, sizeof(*out));
5999 memset((uint8_t *)out + sizeof(*out), 0x22, size - sizeof(*out));
6002 ctx->objmask = NULL;
6003 if (!out->command) {
6004 if (ctx->curr != SET)
6006 if (sizeof(*out) > size)
6008 out->command = ctx->curr;
6009 out->args.vc.data = (uint8_t *)out + size;
6010 /* All we need is pattern */
6011 out->args.vc.pattern =
6012 (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
6014 ctx->object = out->args.vc.pattern;
6019 /** No completion. */
6021 comp_none(struct context *ctx, const struct token *token,
6022 unsigned int ent, char *buf, unsigned int size)
6032 /** Complete boolean values. */
6034 comp_boolean(struct context *ctx, const struct token *token,
6035 unsigned int ent, char *buf, unsigned int size)
6041 for (i = 0; boolean_name[i]; ++i)
6042 if (buf && i == ent)
6043 return strlcpy(buf, boolean_name[i], size);
6049 /** Complete action names. */
6051 comp_action(struct context *ctx, const struct token *token,
6052 unsigned int ent, char *buf, unsigned int size)
6058 for (i = 0; next_action[i]; ++i)
6059 if (buf && i == ent)
6060 return strlcpy(buf, token_list[next_action[i]].name,
6067 /** Complete available ports. */
6069 comp_port(struct context *ctx, const struct token *token,
6070 unsigned int ent, char *buf, unsigned int size)
6077 RTE_ETH_FOREACH_DEV(p) {
6078 if (buf && i == ent)
6079 return snprintf(buf, size, "%u", p);
6087 /** Complete available rule IDs. */
6089 comp_rule_id(struct context *ctx, const struct token *token,
6090 unsigned int ent, char *buf, unsigned int size)
6093 struct rte_port *port;
6094 struct port_flow *pf;
6097 if (port_id_is_invalid(ctx->port, DISABLED_WARN) ||
6098 ctx->port == (portid_t)RTE_PORT_ALL)
6100 port = &ports[ctx->port];
6101 for (pf = port->flow_list; pf != NULL; pf = pf->next) {
6102 if (buf && i == ent)
6103 return snprintf(buf, size, "%u", pf->id);
6111 /** Complete type field for RSS action. */
6113 comp_vc_action_rss_type(struct context *ctx, const struct token *token,
6114 unsigned int ent, char *buf, unsigned int size)
6120 for (i = 0; rss_type_table[i].str; ++i)
6125 return strlcpy(buf, rss_type_table[ent].str, size);
6127 return snprintf(buf, size, "end");
6131 /** Complete queue field for RSS action. */
6133 comp_vc_action_rss_queue(struct context *ctx, const struct token *token,
6134 unsigned int ent, char *buf, unsigned int size)
6141 return snprintf(buf, size, "%u", ent);
6143 return snprintf(buf, size, "end");
6147 /** Complete index number for set raw_encap/raw_decap commands. */
6149 comp_set_raw_index(struct context *ctx, const struct token *token,
6150 unsigned int ent, char *buf, unsigned int size)
6156 RTE_SET_USED(token);
6157 for (idx = 0; idx < RAW_ENCAP_CONFS_MAX_NUM; ++idx) {
6158 if (buf && idx == ent)
6159 return snprintf(buf, size, "%u", idx);
6165 /** Internal context. */
6166 static struct context cmd_flow_context;
6168 /** Global parser instance (cmdline API). */
6169 cmdline_parse_inst_t cmd_flow;
6170 cmdline_parse_inst_t cmd_set_raw;
6172 /** Initialize context. */
6174 cmd_flow_context_init(struct context *ctx)
6176 /* A full memset() is not necessary. */
6186 ctx->objmask = NULL;
6189 /** Parse a token (cmdline API). */
6191 cmd_flow_parse(cmdline_parse_token_hdr_t *hdr, const char *src, void *result,
6194 struct context *ctx = &cmd_flow_context;
6195 const struct token *token;
6196 const enum index *list;
6201 token = &token_list[ctx->curr];
6202 /* Check argument length. */
6205 for (len = 0; src[len]; ++len)
6206 if (src[len] == '#' || isspace(src[len]))
6210 /* Last argument and EOL detection. */
6211 for (i = len; src[i]; ++i)
6212 if (src[i] == '#' || src[i] == '\r' || src[i] == '\n')
6214 else if (!isspace(src[i])) {
6219 if (src[i] == '\r' || src[i] == '\n') {
6223 /* Initialize context if necessary. */
6224 if (!ctx->next_num) {
6227 ctx->next[ctx->next_num++] = token->next[0];
6229 /* Process argument through candidates. */
6230 ctx->prev = ctx->curr;
6231 list = ctx->next[ctx->next_num - 1];
6232 for (i = 0; list[i]; ++i) {
6233 const struct token *next = &token_list[list[i]];
6236 ctx->curr = list[i];
6238 tmp = next->call(ctx, next, src, len, result, size);
6240 tmp = parse_default(ctx, next, src, len, result, size);
6241 if (tmp == -1 || tmp != len)
6249 /* Push subsequent tokens if any. */
6251 for (i = 0; token->next[i]; ++i) {
6252 if (ctx->next_num == RTE_DIM(ctx->next))
6254 ctx->next[ctx->next_num++] = token->next[i];
6256 /* Push arguments if any. */
6258 for (i = 0; token->args[i]; ++i) {
6259 if (ctx->args_num == RTE_DIM(ctx->args))
6261 ctx->args[ctx->args_num++] = token->args[i];
6266 /** Return number of completion entries (cmdline API). */
6268 cmd_flow_complete_get_nb(cmdline_parse_token_hdr_t *hdr)
6270 struct context *ctx = &cmd_flow_context;
6271 const struct token *token = &token_list[ctx->curr];
6272 const enum index *list;
6276 /* Count number of tokens in current list. */
6278 list = ctx->next[ctx->next_num - 1];
6280 list = token->next[0];
6281 for (i = 0; list[i]; ++i)
6286 * If there is a single token, use its completion callback, otherwise
6287 * return the number of entries.
6289 token = &token_list[list[0]];
6290 if (i == 1 && token->comp) {
6291 /* Save index for cmd_flow_get_help(). */
6292 ctx->prev = list[0];
6293 return token->comp(ctx, token, 0, NULL, 0);
6298 /** Return a completion entry (cmdline API). */
6300 cmd_flow_complete_get_elt(cmdline_parse_token_hdr_t *hdr, int index,
6301 char *dst, unsigned int size)
6303 struct context *ctx = &cmd_flow_context;
6304 const struct token *token = &token_list[ctx->curr];
6305 const enum index *list;
6309 /* Count number of tokens in current list. */
6311 list = ctx->next[ctx->next_num - 1];
6313 list = token->next[0];
6314 for (i = 0; list[i]; ++i)
6318 /* If there is a single token, use its completion callback. */
6319 token = &token_list[list[0]];
6320 if (i == 1 && token->comp) {
6321 /* Save index for cmd_flow_get_help(). */
6322 ctx->prev = list[0];
6323 return token->comp(ctx, token, index, dst, size) < 0 ? -1 : 0;
6325 /* Otherwise make sure the index is valid and use defaults. */
6328 token = &token_list[list[index]];
6329 strlcpy(dst, token->name, size);
6330 /* Save index for cmd_flow_get_help(). */
6331 ctx->prev = list[index];
6335 /** Populate help strings for current token (cmdline API). */
6337 cmd_flow_get_help(cmdline_parse_token_hdr_t *hdr, char *dst, unsigned int size)
6339 struct context *ctx = &cmd_flow_context;
6340 const struct token *token = &token_list[ctx->prev];
6345 /* Set token type and update global help with details. */
6346 strlcpy(dst, (token->type ? token->type : "TOKEN"), size);
6348 cmd_flow.help_str = token->help;
6350 cmd_flow.help_str = token->name;
6354 /** Token definition template (cmdline API). */
6355 static struct cmdline_token_hdr cmd_flow_token_hdr = {
6356 .ops = &(struct cmdline_token_ops){
6357 .parse = cmd_flow_parse,
6358 .complete_get_nb = cmd_flow_complete_get_nb,
6359 .complete_get_elt = cmd_flow_complete_get_elt,
6360 .get_help = cmd_flow_get_help,
6365 /** Populate the next dynamic token. */
6367 cmd_flow_tok(cmdline_parse_token_hdr_t **hdr,
6368 cmdline_parse_token_hdr_t **hdr_inst)
6370 struct context *ctx = &cmd_flow_context;
6372 /* Always reinitialize context before requesting the first token. */
6373 if (!(hdr_inst - cmd_flow.tokens))
6374 cmd_flow_context_init(ctx);
6375 /* Return NULL when no more tokens are expected. */
6376 if (!ctx->next_num && ctx->curr) {
6380 /* Determine if command should end here. */
6381 if (ctx->eol && ctx->last && ctx->next_num) {
6382 const enum index *list = ctx->next[ctx->next_num - 1];
6385 for (i = 0; list[i]; ++i) {
6392 *hdr = &cmd_flow_token_hdr;
6395 /** Dispatch parsed buffer to function calls. */
6397 cmd_flow_parsed(const struct buffer *in)
6399 switch (in->command) {
6401 port_flow_validate(in->port, &in->args.vc.attr,
6402 in->args.vc.pattern, in->args.vc.actions);
6405 port_flow_create(in->port, &in->args.vc.attr,
6406 in->args.vc.pattern, in->args.vc.actions);
6409 port_flow_destroy(in->port, in->args.destroy.rule_n,
6410 in->args.destroy.rule);
6413 port_flow_flush(in->port);
6416 port_flow_dump(in->port, in->args.dump.file);
6419 port_flow_query(in->port, in->args.query.rule,
6420 &in->args.query.action);
6423 port_flow_list(in->port, in->args.list.group_n,
6424 in->args.list.group);
6427 port_flow_isolate(in->port, in->args.isolate.set);
6430 port_flow_aged(in->port, in->args.aged.destroy);
6437 /** Token generator and output processing callback (cmdline API). */
6439 cmd_flow_cb(void *arg0, struct cmdline *cl, void *arg2)
6442 cmd_flow_tok(arg0, arg2);
6444 cmd_flow_parsed(arg0);
6447 /** Global parser instance (cmdline API). */
6448 cmdline_parse_inst_t cmd_flow = {
6450 .data = NULL, /**< Unused. */
6451 .help_str = NULL, /**< Updated by cmd_flow_get_help(). */
6454 }, /**< Tokens are returned by cmd_flow_tok(). */
6457 /** set cmd facility. Reuse cmd flow's infrastructure as much as possible. */
6460 update_fields(uint8_t *buf, struct rte_flow_item *item, uint16_t next_proto)
6462 struct rte_flow_item_ipv4 *ipv4;
6463 struct rte_flow_item_eth *eth;
6464 struct rte_flow_item_ipv6 *ipv6;
6465 struct rte_flow_item_vxlan *vxlan;
6466 struct rte_flow_item_vxlan_gpe *gpe;
6467 struct rte_flow_item_nvgre *nvgre;
6468 uint32_t ipv6_vtc_flow;
6470 switch (item->type) {
6471 case RTE_FLOW_ITEM_TYPE_ETH:
6472 eth = (struct rte_flow_item_eth *)buf;
6474 eth->type = rte_cpu_to_be_16(next_proto);
6476 case RTE_FLOW_ITEM_TYPE_IPV4:
6477 ipv4 = (struct rte_flow_item_ipv4 *)buf;
6478 ipv4->hdr.version_ihl = 0x45;
6479 if (next_proto && ipv4->hdr.next_proto_id == 0)
6480 ipv4->hdr.next_proto_id = (uint8_t)next_proto;
6482 case RTE_FLOW_ITEM_TYPE_IPV6:
6483 ipv6 = (struct rte_flow_item_ipv6 *)buf;
6484 if (next_proto && ipv6->hdr.proto == 0)
6485 ipv6->hdr.proto = (uint8_t)next_proto;
6486 ipv6_vtc_flow = rte_be_to_cpu_32(ipv6->hdr.vtc_flow);
6487 ipv6_vtc_flow &= 0x0FFFFFFF; /*< reset version bits. */
6488 ipv6_vtc_flow |= 0x60000000; /*< set ipv6 version. */
6489 ipv6->hdr.vtc_flow = rte_cpu_to_be_32(ipv6_vtc_flow);
6491 case RTE_FLOW_ITEM_TYPE_VXLAN:
6492 vxlan = (struct rte_flow_item_vxlan *)buf;
6493 vxlan->flags = 0x08;
6495 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
6496 gpe = (struct rte_flow_item_vxlan_gpe *)buf;
6499 case RTE_FLOW_ITEM_TYPE_NVGRE:
6500 nvgre = (struct rte_flow_item_nvgre *)buf;
6501 nvgre->protocol = rte_cpu_to_be_16(0x6558);
6502 nvgre->c_k_s_rsvd0_ver = rte_cpu_to_be_16(0x2000);
6509 /** Helper of get item's default mask. */
6511 flow_item_default_mask(const struct rte_flow_item *item)
6513 const void *mask = NULL;
6514 static rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
6516 switch (item->type) {
6517 case RTE_FLOW_ITEM_TYPE_ANY:
6518 mask = &rte_flow_item_any_mask;
6520 case RTE_FLOW_ITEM_TYPE_VF:
6521 mask = &rte_flow_item_vf_mask;
6523 case RTE_FLOW_ITEM_TYPE_PORT_ID:
6524 mask = &rte_flow_item_port_id_mask;
6526 case RTE_FLOW_ITEM_TYPE_RAW:
6527 mask = &rte_flow_item_raw_mask;
6529 case RTE_FLOW_ITEM_TYPE_ETH:
6530 mask = &rte_flow_item_eth_mask;
6532 case RTE_FLOW_ITEM_TYPE_VLAN:
6533 mask = &rte_flow_item_vlan_mask;
6535 case RTE_FLOW_ITEM_TYPE_IPV4:
6536 mask = &rte_flow_item_ipv4_mask;
6538 case RTE_FLOW_ITEM_TYPE_IPV6:
6539 mask = &rte_flow_item_ipv6_mask;
6541 case RTE_FLOW_ITEM_TYPE_ICMP:
6542 mask = &rte_flow_item_icmp_mask;
6544 case RTE_FLOW_ITEM_TYPE_UDP:
6545 mask = &rte_flow_item_udp_mask;
6547 case RTE_FLOW_ITEM_TYPE_TCP:
6548 mask = &rte_flow_item_tcp_mask;
6550 case RTE_FLOW_ITEM_TYPE_SCTP:
6551 mask = &rte_flow_item_sctp_mask;
6553 case RTE_FLOW_ITEM_TYPE_VXLAN:
6554 mask = &rte_flow_item_vxlan_mask;
6556 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
6557 mask = &rte_flow_item_vxlan_gpe_mask;
6559 case RTE_FLOW_ITEM_TYPE_E_TAG:
6560 mask = &rte_flow_item_e_tag_mask;
6562 case RTE_FLOW_ITEM_TYPE_NVGRE:
6563 mask = &rte_flow_item_nvgre_mask;
6565 case RTE_FLOW_ITEM_TYPE_MPLS:
6566 mask = &rte_flow_item_mpls_mask;
6568 case RTE_FLOW_ITEM_TYPE_GRE:
6569 mask = &rte_flow_item_gre_mask;
6571 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
6572 mask = &gre_key_default_mask;
6574 case RTE_FLOW_ITEM_TYPE_META:
6575 mask = &rte_flow_item_meta_mask;
6577 case RTE_FLOW_ITEM_TYPE_FUZZY:
6578 mask = &rte_flow_item_fuzzy_mask;
6580 case RTE_FLOW_ITEM_TYPE_GTP:
6581 mask = &rte_flow_item_gtp_mask;
6583 case RTE_FLOW_ITEM_TYPE_GTP_PSC:
6584 mask = &rte_flow_item_gtp_psc_mask;
6586 case RTE_FLOW_ITEM_TYPE_GENEVE:
6587 mask = &rte_flow_item_geneve_mask;
6589 case RTE_FLOW_ITEM_TYPE_PPPOE_PROTO_ID:
6590 mask = &rte_flow_item_pppoe_proto_id_mask;
6592 case RTE_FLOW_ITEM_TYPE_L2TPV3OIP:
6593 mask = &rte_flow_item_l2tpv3oip_mask;
6595 case RTE_FLOW_ITEM_TYPE_ESP:
6596 mask = &rte_flow_item_esp_mask;
6598 case RTE_FLOW_ITEM_TYPE_AH:
6599 mask = &rte_flow_item_ah_mask;
6601 case RTE_FLOW_ITEM_TYPE_PFCP:
6602 mask = &rte_flow_item_pfcp_mask;
6612 /** Dispatch parsed buffer to function calls. */
6614 cmd_set_raw_parsed(const struct buffer *in)
6616 uint32_t n = in->args.vc.pattern_n;
6618 struct rte_flow_item *item = NULL;
6620 uint8_t *data = NULL;
6621 uint8_t *data_tail = NULL;
6622 size_t *total_size = NULL;
6623 uint16_t upper_layer = 0;
6625 uint16_t idx = in->port; /* We borrow port field as index */
6627 RTE_ASSERT(in->command == SET_RAW_ENCAP ||
6628 in->command == SET_RAW_DECAP);
6629 if (in->command == SET_RAW_ENCAP) {
6630 total_size = &raw_encap_confs[idx].size;
6631 data = (uint8_t *)&raw_encap_confs[idx].data;
6633 total_size = &raw_decap_confs[idx].size;
6634 data = (uint8_t *)&raw_decap_confs[idx].data;
6637 memset(data, 0x00, ACTION_RAW_ENCAP_MAX_DATA);
6638 /* process hdr from upper layer to low layer (L3/L4 -> L2). */
6639 data_tail = data + ACTION_RAW_ENCAP_MAX_DATA;
6640 for (i = n - 1 ; i >= 0; --i) {
6641 item = in->args.vc.pattern + i;
6642 if (item->spec == NULL)
6643 item->spec = flow_item_default_mask(item);
6644 switch (item->type) {
6645 case RTE_FLOW_ITEM_TYPE_ETH:
6646 size = sizeof(struct rte_flow_item_eth);
6648 case RTE_FLOW_ITEM_TYPE_VLAN:
6649 size = sizeof(struct rte_flow_item_vlan);
6650 proto = RTE_ETHER_TYPE_VLAN;
6652 case RTE_FLOW_ITEM_TYPE_IPV4:
6653 size = sizeof(struct rte_flow_item_ipv4);
6654 proto = RTE_ETHER_TYPE_IPV4;
6656 case RTE_FLOW_ITEM_TYPE_IPV6:
6657 size = sizeof(struct rte_flow_item_ipv6);
6658 proto = RTE_ETHER_TYPE_IPV6;
6660 case RTE_FLOW_ITEM_TYPE_UDP:
6661 size = sizeof(struct rte_flow_item_udp);
6664 case RTE_FLOW_ITEM_TYPE_TCP:
6665 size = sizeof(struct rte_flow_item_tcp);
6668 case RTE_FLOW_ITEM_TYPE_VXLAN:
6669 size = sizeof(struct rte_flow_item_vxlan);
6671 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
6672 size = sizeof(struct rte_flow_item_vxlan_gpe);
6674 case RTE_FLOW_ITEM_TYPE_GRE:
6675 size = sizeof(struct rte_flow_item_gre);
6678 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
6679 size = sizeof(rte_be32_t);
6682 case RTE_FLOW_ITEM_TYPE_MPLS:
6683 size = sizeof(struct rte_flow_item_mpls);
6686 case RTE_FLOW_ITEM_TYPE_NVGRE:
6687 size = sizeof(struct rte_flow_item_nvgre);
6690 case RTE_FLOW_ITEM_TYPE_GENEVE:
6691 size = sizeof(struct rte_flow_item_geneve);
6693 case RTE_FLOW_ITEM_TYPE_L2TPV3OIP:
6694 size = sizeof(struct rte_flow_item_l2tpv3oip);
6697 case RTE_FLOW_ITEM_TYPE_ESP:
6698 size = sizeof(struct rte_flow_item_esp);
6701 case RTE_FLOW_ITEM_TYPE_AH:
6702 size = sizeof(struct rte_flow_item_ah);
6705 case RTE_FLOW_ITEM_TYPE_GTP:
6706 size = sizeof(struct rte_flow_item_gtp);
6708 case RTE_FLOW_ITEM_TYPE_PFCP:
6709 size = sizeof(struct rte_flow_item_pfcp);
6712 printf("Error - Not supported item\n");
6714 memset(data, 0x00, ACTION_RAW_ENCAP_MAX_DATA);
6717 *total_size += size;
6718 rte_memcpy(data_tail - (*total_size), item->spec, size);
6719 /* update some fields which cannot be set by cmdline */
6720 update_fields((data_tail - (*total_size)), item,
6722 upper_layer = proto;
6724 if (verbose_level & 0x1)
6725 printf("total data size is %zu\n", (*total_size));
6726 RTE_ASSERT((*total_size) <= ACTION_RAW_ENCAP_MAX_DATA);
6727 memmove(data, (data_tail - (*total_size)), *total_size);
6730 /** Populate help strings for current token (cmdline API). */
6732 cmd_set_raw_get_help(cmdline_parse_token_hdr_t *hdr, char *dst,
6735 struct context *ctx = &cmd_flow_context;
6736 const struct token *token = &token_list[ctx->prev];
6741 /* Set token type and update global help with details. */
6742 snprintf(dst, size, "%s", (token->type ? token->type : "TOKEN"));
6744 cmd_set_raw.help_str = token->help;
6746 cmd_set_raw.help_str = token->name;
6750 /** Token definition template (cmdline API). */
6751 static struct cmdline_token_hdr cmd_set_raw_token_hdr = {
6752 .ops = &(struct cmdline_token_ops){
6753 .parse = cmd_flow_parse,
6754 .complete_get_nb = cmd_flow_complete_get_nb,
6755 .complete_get_elt = cmd_flow_complete_get_elt,
6756 .get_help = cmd_set_raw_get_help,
6761 /** Populate the next dynamic token. */
6763 cmd_set_raw_tok(cmdline_parse_token_hdr_t **hdr,
6764 cmdline_parse_token_hdr_t **hdr_inst)
6766 struct context *ctx = &cmd_flow_context;
6768 /* Always reinitialize context before requesting the first token. */
6769 if (!(hdr_inst - cmd_set_raw.tokens)) {
6770 cmd_flow_context_init(ctx);
6771 ctx->curr = START_SET;
6773 /* Return NULL when no more tokens are expected. */
6774 if (!ctx->next_num && (ctx->curr != START_SET)) {
6778 /* Determine if command should end here. */
6779 if (ctx->eol && ctx->last && ctx->next_num) {
6780 const enum index *list = ctx->next[ctx->next_num - 1];
6783 for (i = 0; list[i]; ++i) {
6790 *hdr = &cmd_set_raw_token_hdr;
6793 /** Token generator and output processing callback (cmdline API). */
6795 cmd_set_raw_cb(void *arg0, struct cmdline *cl, void *arg2)
6798 cmd_set_raw_tok(arg0, arg2);
6800 cmd_set_raw_parsed(arg0);
6803 /** Global parser instance (cmdline API). */
6804 cmdline_parse_inst_t cmd_set_raw = {
6805 .f = cmd_set_raw_cb,
6806 .data = NULL, /**< Unused. */
6807 .help_str = NULL, /**< Updated by cmd_flow_get_help(). */
6810 }, /**< Tokens are returned by cmd_flow_tok(). */
6813 /* *** display raw_encap/raw_decap buf */
6814 struct cmd_show_set_raw_result {
6815 cmdline_fixed_string_t cmd_show;
6816 cmdline_fixed_string_t cmd_what;
6817 cmdline_fixed_string_t cmd_all;
6822 cmd_show_set_raw_parsed(void *parsed_result, struct cmdline *cl, void *data)
6824 struct cmd_show_set_raw_result *res = parsed_result;
6825 uint16_t index = res->cmd_index;
6827 uint8_t *raw_data = NULL;
6828 size_t raw_size = 0;
6829 char title[16] = {0};
6833 if (!strcmp(res->cmd_all, "all")) {
6836 } else if (index >= RAW_ENCAP_CONFS_MAX_NUM) {
6837 printf("index should be 0-%u\n", RAW_ENCAP_CONFS_MAX_NUM - 1);
6841 if (!strcmp(res->cmd_what, "raw_encap")) {
6842 raw_data = (uint8_t *)&raw_encap_confs[index].data;
6843 raw_size = raw_encap_confs[index].size;
6844 snprintf(title, 16, "\nindex: %u", index);
6845 rte_hexdump(stdout, title, raw_data, raw_size);
6847 raw_data = (uint8_t *)&raw_decap_confs[index].data;
6848 raw_size = raw_decap_confs[index].size;
6849 snprintf(title, 16, "\nindex: %u", index);
6850 rte_hexdump(stdout, title, raw_data, raw_size);
6852 } while (all && ++index < RAW_ENCAP_CONFS_MAX_NUM);
6855 cmdline_parse_token_string_t cmd_show_set_raw_cmd_show =
6856 TOKEN_STRING_INITIALIZER(struct cmd_show_set_raw_result,
6858 cmdline_parse_token_string_t cmd_show_set_raw_cmd_what =
6859 TOKEN_STRING_INITIALIZER(struct cmd_show_set_raw_result,
6860 cmd_what, "raw_encap#raw_decap");
6861 cmdline_parse_token_num_t cmd_show_set_raw_cmd_index =
6862 TOKEN_NUM_INITIALIZER(struct cmd_show_set_raw_result,
6864 cmdline_parse_token_string_t cmd_show_set_raw_cmd_all =
6865 TOKEN_STRING_INITIALIZER(struct cmd_show_set_raw_result,
6867 cmdline_parse_inst_t cmd_show_set_raw = {
6868 .f = cmd_show_set_raw_parsed,
6870 .help_str = "show <raw_encap|raw_decap> <index>",
6872 (void *)&cmd_show_set_raw_cmd_show,
6873 (void *)&cmd_show_set_raw_cmd_what,
6874 (void *)&cmd_show_set_raw_cmd_index,
6878 cmdline_parse_inst_t cmd_show_set_raw_all = {
6879 .f = cmd_show_set_raw_parsed,
6881 .help_str = "show <raw_encap|raw_decap> all",
6883 (void *)&cmd_show_set_raw_cmd_show,
6884 (void *)&cmd_show_set_raw_cmd_what,
6885 (void *)&cmd_show_set_raw_cmd_all,