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>
26 /** Parser token indices. */
49 /* Top-level command. */
51 /* Sub-leve commands. */
55 /* Top-level command. */
57 /* Sub-level commands. */
66 /* Destroy arguments. */
69 /* Query arguments. */
75 /* Validate/create arguments. */
82 /* Validate/create pattern. */
119 ITEM_VLAN_INNER_TYPE,
151 ITEM_E_TAG_GRP_ECID_B,
160 ITEM_GRE_C_RSVD0_VER,
176 ITEM_ARP_ETH_IPV4_SHA,
177 ITEM_ARP_ETH_IPV4_SPA,
178 ITEM_ARP_ETH_IPV4_THA,
179 ITEM_ARP_ETH_IPV4_TPA,
181 ITEM_IPV6_EXT_NEXT_HDR,
186 ITEM_ICMP6_ND_NS_TARGET_ADDR,
188 ITEM_ICMP6_ND_NA_TARGET_ADDR,
190 ITEM_ICMP6_ND_OPT_TYPE,
191 ITEM_ICMP6_ND_OPT_SLA_ETH,
192 ITEM_ICMP6_ND_OPT_SLA_ETH_SLA,
193 ITEM_ICMP6_ND_OPT_TLA_ETH,
194 ITEM_ICMP6_ND_OPT_TLA_ETH_TLA,
200 /* Validate/create actions. */
220 ACTION_RSS_FUNC_DEFAULT,
221 ACTION_RSS_FUNC_TOEPLITZ,
222 ACTION_RSS_FUNC_SIMPLE_XOR,
234 ACTION_PHY_PORT_ORIGINAL,
235 ACTION_PHY_PORT_INDEX,
237 ACTION_PORT_ID_ORIGINAL,
241 ACTION_OF_SET_MPLS_TTL,
242 ACTION_OF_SET_MPLS_TTL_MPLS_TTL,
243 ACTION_OF_DEC_MPLS_TTL,
244 ACTION_OF_SET_NW_TTL,
245 ACTION_OF_SET_NW_TTL_NW_TTL,
246 ACTION_OF_DEC_NW_TTL,
247 ACTION_OF_COPY_TTL_OUT,
248 ACTION_OF_COPY_TTL_IN,
251 ACTION_OF_PUSH_VLAN_ETHERTYPE,
252 ACTION_OF_SET_VLAN_VID,
253 ACTION_OF_SET_VLAN_VID_VLAN_VID,
254 ACTION_OF_SET_VLAN_PCP,
255 ACTION_OF_SET_VLAN_PCP_VLAN_PCP,
257 ACTION_OF_POP_MPLS_ETHERTYPE,
259 ACTION_OF_PUSH_MPLS_ETHERTYPE,
266 ACTION_MPLSOGRE_ENCAP,
267 ACTION_MPLSOGRE_DECAP,
268 ACTION_MPLSOUDP_ENCAP,
269 ACTION_MPLSOUDP_DECAP,
271 ACTION_SET_IPV4_SRC_IPV4_SRC,
273 ACTION_SET_IPV4_DST_IPV4_DST,
275 ACTION_SET_IPV6_SRC_IPV6_SRC,
277 ACTION_SET_IPV6_DST_IPV6_DST,
279 ACTION_SET_TP_SRC_TP_SRC,
281 ACTION_SET_TP_DST_TP_DST,
287 ACTION_SET_MAC_SRC_MAC_SRC,
289 ACTION_SET_MAC_DST_MAC_DST,
291 ACTION_INC_TCP_SEQ_VALUE,
293 ACTION_DEC_TCP_SEQ_VALUE,
295 ACTION_INC_TCP_ACK_VALUE,
297 ACTION_DEC_TCP_ACK_VALUE,
302 /** Maximum size for pattern in struct rte_flow_item_raw. */
303 #define ITEM_RAW_PATTERN_SIZE 40
305 /** Storage size for struct rte_flow_item_raw including pattern. */
306 #define ITEM_RAW_SIZE \
307 (sizeof(struct rte_flow_item_raw) + ITEM_RAW_PATTERN_SIZE)
309 /** Maximum number of queue indices in struct rte_flow_action_rss. */
310 #define ACTION_RSS_QUEUE_NUM 32
312 /** Storage for struct rte_flow_action_rss including external data. */
313 struct action_rss_data {
314 struct rte_flow_action_rss conf;
315 uint8_t key[RSS_HASH_KEY_LENGTH];
316 uint16_t queue[ACTION_RSS_QUEUE_NUM];
319 /** Maximum number of items in struct rte_flow_action_vxlan_encap. */
320 #define ACTION_VXLAN_ENCAP_ITEMS_NUM 6
322 #define ACTION_RAW_ENCAP_MAX_DATA 128
324 /** Storage for struct rte_flow_action_raw_encap. */
325 struct raw_encap_conf {
326 uint8_t data[ACTION_RAW_ENCAP_MAX_DATA];
327 uint8_t preserve[ACTION_RAW_ENCAP_MAX_DATA];
331 struct raw_encap_conf raw_encap_conf = {.size = 0};
333 /** Storage for struct rte_flow_action_raw_decap. */
334 struct raw_decap_conf {
335 uint8_t data[ACTION_RAW_ENCAP_MAX_DATA];
339 struct raw_decap_conf raw_decap_conf = {.size = 0};
341 /** Storage for struct rte_flow_action_vxlan_encap including external data. */
342 struct action_vxlan_encap_data {
343 struct rte_flow_action_vxlan_encap conf;
344 struct rte_flow_item items[ACTION_VXLAN_ENCAP_ITEMS_NUM];
345 struct rte_flow_item_eth item_eth;
346 struct rte_flow_item_vlan item_vlan;
348 struct rte_flow_item_ipv4 item_ipv4;
349 struct rte_flow_item_ipv6 item_ipv6;
351 struct rte_flow_item_udp item_udp;
352 struct rte_flow_item_vxlan item_vxlan;
355 /** Maximum number of items in struct rte_flow_action_nvgre_encap. */
356 #define ACTION_NVGRE_ENCAP_ITEMS_NUM 5
358 /** Storage for struct rte_flow_action_nvgre_encap including external data. */
359 struct action_nvgre_encap_data {
360 struct rte_flow_action_nvgre_encap conf;
361 struct rte_flow_item items[ACTION_NVGRE_ENCAP_ITEMS_NUM];
362 struct rte_flow_item_eth item_eth;
363 struct rte_flow_item_vlan item_vlan;
365 struct rte_flow_item_ipv4 item_ipv4;
366 struct rte_flow_item_ipv6 item_ipv6;
368 struct rte_flow_item_nvgre item_nvgre;
371 /** Maximum data size in struct rte_flow_action_raw_encap. */
372 #define ACTION_RAW_ENCAP_MAX_DATA 128
374 /** Storage for struct rte_flow_action_raw_encap including external data. */
375 struct action_raw_encap_data {
376 struct rte_flow_action_raw_encap conf;
377 uint8_t data[ACTION_RAW_ENCAP_MAX_DATA];
378 uint8_t preserve[ACTION_RAW_ENCAP_MAX_DATA];
381 /** Storage for struct rte_flow_action_raw_decap including external data. */
382 struct action_raw_decap_data {
383 struct rte_flow_action_raw_decap conf;
384 uint8_t data[ACTION_RAW_ENCAP_MAX_DATA];
387 /** Maximum number of subsequent tokens and arguments on the stack. */
388 #define CTX_STACK_SIZE 16
390 /** Parser context. */
392 /** Stack of subsequent token lists to process. */
393 const enum index *next[CTX_STACK_SIZE];
394 /** Arguments for stacked tokens. */
395 const void *args[CTX_STACK_SIZE];
396 enum index curr; /**< Current token index. */
397 enum index prev; /**< Index of the last token seen. */
398 int next_num; /**< Number of entries in next[]. */
399 int args_num; /**< Number of entries in args[]. */
400 uint32_t eol:1; /**< EOL has been detected. */
401 uint32_t last:1; /**< No more arguments. */
402 portid_t port; /**< Current port ID (for completions). */
403 uint32_t objdata; /**< Object-specific data. */
404 void *object; /**< Address of current object for relative offsets. */
405 void *objmask; /**< Object a full mask must be written to. */
408 /** Token argument. */
410 uint32_t hton:1; /**< Use network byte ordering. */
411 uint32_t sign:1; /**< Value is signed. */
412 uint32_t bounded:1; /**< Value is bounded. */
413 uintmax_t min; /**< Minimum value if bounded. */
414 uintmax_t max; /**< Maximum value if bounded. */
415 uint32_t offset; /**< Relative offset from ctx->object. */
416 uint32_t size; /**< Field size. */
417 const uint8_t *mask; /**< Bit-mask to use instead of offset/size. */
420 /** Parser token definition. */
422 /** Type displayed during completion (defaults to "TOKEN"). */
424 /** Help displayed during completion (defaults to token name). */
426 /** Private data used by parser functions. */
429 * Lists of subsequent tokens to push on the stack. Each call to the
430 * parser consumes the last entry of that stack.
432 const enum index *const *next;
433 /** Arguments stack for subsequent tokens that need them. */
434 const struct arg *const *args;
436 * Token-processing callback, returns -1 in case of error, the
437 * length of the matched string otherwise. If NULL, attempts to
438 * match the token name.
440 * If buf is not NULL, the result should be stored in it according
441 * to context. An error is returned if not large enough.
443 int (*call)(struct context *ctx, const struct token *token,
444 const char *str, unsigned int len,
445 void *buf, unsigned int size);
447 * Callback that provides possible values for this token, used for
448 * completion. Returns -1 in case of error, the number of possible
449 * values otherwise. If NULL, the token name is used.
451 * If buf is not NULL, entry index ent is written to buf and the
452 * full length of the entry is returned (same behavior as
455 int (*comp)(struct context *ctx, const struct token *token,
456 unsigned int ent, char *buf, unsigned int size);
457 /** Mandatory token name, no default value. */
461 /** Static initializer for the next field. */
462 #define NEXT(...) (const enum index *const []){ __VA_ARGS__, NULL, }
464 /** Static initializer for a NEXT() entry. */
465 #define NEXT_ENTRY(...) (const enum index []){ __VA_ARGS__, ZERO, }
467 /** Static initializer for the args field. */
468 #define ARGS(...) (const struct arg *const []){ __VA_ARGS__, NULL, }
470 /** Static initializer for ARGS() to target a field. */
471 #define ARGS_ENTRY(s, f) \
472 (&(const struct arg){ \
473 .offset = offsetof(s, f), \
474 .size = sizeof(((s *)0)->f), \
477 /** Static initializer for ARGS() to target a bit-field. */
478 #define ARGS_ENTRY_BF(s, f, b) \
479 (&(const struct arg){ \
481 .mask = (const void *)&(const s){ .f = (1 << (b)) - 1 }, \
484 /** Static initializer for ARGS() to target an arbitrary bit-mask. */
485 #define ARGS_ENTRY_MASK(s, f, m) \
486 (&(const struct arg){ \
487 .offset = offsetof(s, f), \
488 .size = sizeof(((s *)0)->f), \
489 .mask = (const void *)(m), \
492 /** Same as ARGS_ENTRY_MASK() using network byte ordering for the value. */
493 #define ARGS_ENTRY_MASK_HTON(s, f, m) \
494 (&(const struct arg){ \
496 .offset = offsetof(s, f), \
497 .size = sizeof(((s *)0)->f), \
498 .mask = (const void *)(m), \
501 /** Static initializer for ARGS() to target a pointer. */
502 #define ARGS_ENTRY_PTR(s, f) \
503 (&(const struct arg){ \
504 .size = sizeof(*((s *)0)->f), \
507 /** Static initializer for ARGS() with arbitrary offset and size. */
508 #define ARGS_ENTRY_ARB(o, s) \
509 (&(const struct arg){ \
514 /** Same as ARGS_ENTRY_ARB() with bounded values. */
515 #define ARGS_ENTRY_ARB_BOUNDED(o, s, i, a) \
516 (&(const struct arg){ \
524 /** Same as ARGS_ENTRY() using network byte ordering. */
525 #define ARGS_ENTRY_HTON(s, f) \
526 (&(const struct arg){ \
528 .offset = offsetof(s, f), \
529 .size = sizeof(((s *)0)->f), \
532 /** Same as ARGS_ENTRY_HTON() for a single argument, without structure. */
533 #define ARG_ENTRY_HTON(s) \
534 (&(const struct arg){ \
540 /** Parser output buffer layout expected by cmd_flow_parsed(). */
542 enum index command; /**< Flow command. */
543 portid_t port; /**< Affected port ID. */
546 struct rte_flow_attr attr;
547 struct rte_flow_item *pattern;
548 struct rte_flow_action *actions;
552 } vc; /**< Validate/create arguments. */
556 } destroy; /**< Destroy arguments. */
559 struct rte_flow_action action;
560 } query; /**< Query arguments. */
564 } list; /**< List arguments. */
567 } isolate; /**< Isolated mode arguments. */
568 } args; /**< Command arguments. */
571 /** Private data for pattern items. */
572 struct parse_item_priv {
573 enum rte_flow_item_type type; /**< Item type. */
574 uint32_t size; /**< Size of item specification structure. */
577 #define PRIV_ITEM(t, s) \
578 (&(const struct parse_item_priv){ \
579 .type = RTE_FLOW_ITEM_TYPE_ ## t, \
583 /** Private data for actions. */
584 struct parse_action_priv {
585 enum rte_flow_action_type type; /**< Action type. */
586 uint32_t size; /**< Size of action configuration structure. */
589 #define PRIV_ACTION(t, s) \
590 (&(const struct parse_action_priv){ \
591 .type = RTE_FLOW_ACTION_TYPE_ ## t, \
595 static const enum index next_vc_attr[] = {
605 static const enum index next_destroy_attr[] = {
611 static const enum index next_list_attr[] = {
617 static const enum index item_param[] = {
626 static const enum index next_item[] = {
662 ITEM_ICMP6_ND_OPT_SLA_ETH,
663 ITEM_ICMP6_ND_OPT_TLA_ETH,
670 static const enum index item_fuzzy[] = {
676 static const enum index item_any[] = {
682 static const enum index item_vf[] = {
688 static const enum index item_phy_port[] = {
694 static const enum index item_port_id[] = {
700 static const enum index item_mark[] = {
706 static const enum index item_raw[] = {
716 static const enum index item_eth[] = {
724 static const enum index item_vlan[] = {
729 ITEM_VLAN_INNER_TYPE,
734 static const enum index item_ipv4[] = {
744 static const enum index item_ipv6[] = {
755 static const enum index item_icmp[] = {
762 static const enum index item_udp[] = {
769 static const enum index item_tcp[] = {
777 static const enum index item_sctp[] = {
786 static const enum index item_vxlan[] = {
792 static const enum index item_e_tag[] = {
793 ITEM_E_TAG_GRP_ECID_B,
798 static const enum index item_nvgre[] = {
804 static const enum index item_mpls[] = {
812 static const enum index item_gre[] = {
814 ITEM_GRE_C_RSVD0_VER,
822 static const enum index item_gre_key[] = {
828 static const enum index item_gtp[] = {
834 static const enum index item_geneve[] = {
841 static const enum index item_vxlan_gpe[] = {
847 static const enum index item_arp_eth_ipv4[] = {
848 ITEM_ARP_ETH_IPV4_SHA,
849 ITEM_ARP_ETH_IPV4_SPA,
850 ITEM_ARP_ETH_IPV4_THA,
851 ITEM_ARP_ETH_IPV4_TPA,
856 static const enum index item_ipv6_ext[] = {
857 ITEM_IPV6_EXT_NEXT_HDR,
862 static const enum index item_icmp6[] = {
869 static const enum index item_icmp6_nd_ns[] = {
870 ITEM_ICMP6_ND_NS_TARGET_ADDR,
875 static const enum index item_icmp6_nd_na[] = {
876 ITEM_ICMP6_ND_NA_TARGET_ADDR,
881 static const enum index item_icmp6_nd_opt[] = {
882 ITEM_ICMP6_ND_OPT_TYPE,
887 static const enum index item_icmp6_nd_opt_sla_eth[] = {
888 ITEM_ICMP6_ND_OPT_SLA_ETH_SLA,
893 static const enum index item_icmp6_nd_opt_tla_eth[] = {
894 ITEM_ICMP6_ND_OPT_TLA_ETH_TLA,
899 static const enum index item_meta[] = {
905 static const enum index next_action[] = {
921 ACTION_OF_SET_MPLS_TTL,
922 ACTION_OF_DEC_MPLS_TTL,
923 ACTION_OF_SET_NW_TTL,
924 ACTION_OF_DEC_NW_TTL,
925 ACTION_OF_COPY_TTL_OUT,
926 ACTION_OF_COPY_TTL_IN,
929 ACTION_OF_SET_VLAN_VID,
930 ACTION_OF_SET_VLAN_PCP,
939 ACTION_MPLSOGRE_ENCAP,
940 ACTION_MPLSOGRE_DECAP,
941 ACTION_MPLSOUDP_ENCAP,
942 ACTION_MPLSOUDP_DECAP,
963 static const enum index action_mark[] = {
969 static const enum index action_queue[] = {
975 static const enum index action_count[] = {
982 static const enum index action_rss[] = {
993 static const enum index action_vf[] = {
1000 static const enum index action_phy_port[] = {
1001 ACTION_PHY_PORT_ORIGINAL,
1002 ACTION_PHY_PORT_INDEX,
1007 static const enum index action_port_id[] = {
1008 ACTION_PORT_ID_ORIGINAL,
1014 static const enum index action_meter[] = {
1020 static const enum index action_of_set_mpls_ttl[] = {
1021 ACTION_OF_SET_MPLS_TTL_MPLS_TTL,
1026 static const enum index action_of_set_nw_ttl[] = {
1027 ACTION_OF_SET_NW_TTL_NW_TTL,
1032 static const enum index action_of_push_vlan[] = {
1033 ACTION_OF_PUSH_VLAN_ETHERTYPE,
1038 static const enum index action_of_set_vlan_vid[] = {
1039 ACTION_OF_SET_VLAN_VID_VLAN_VID,
1044 static const enum index action_of_set_vlan_pcp[] = {
1045 ACTION_OF_SET_VLAN_PCP_VLAN_PCP,
1050 static const enum index action_of_pop_mpls[] = {
1051 ACTION_OF_POP_MPLS_ETHERTYPE,
1056 static const enum index action_of_push_mpls[] = {
1057 ACTION_OF_PUSH_MPLS_ETHERTYPE,
1062 static const enum index action_set_ipv4_src[] = {
1063 ACTION_SET_IPV4_SRC_IPV4_SRC,
1068 static const enum index action_set_mac_src[] = {
1069 ACTION_SET_MAC_SRC_MAC_SRC,
1074 static const enum index action_set_ipv4_dst[] = {
1075 ACTION_SET_IPV4_DST_IPV4_DST,
1080 static const enum index action_set_ipv6_src[] = {
1081 ACTION_SET_IPV6_SRC_IPV6_SRC,
1086 static const enum index action_set_ipv6_dst[] = {
1087 ACTION_SET_IPV6_DST_IPV6_DST,
1092 static const enum index action_set_tp_src[] = {
1093 ACTION_SET_TP_SRC_TP_SRC,
1098 static const enum index action_set_tp_dst[] = {
1099 ACTION_SET_TP_DST_TP_DST,
1104 static const enum index action_set_ttl[] = {
1110 static const enum index action_jump[] = {
1116 static const enum index action_set_mac_dst[] = {
1117 ACTION_SET_MAC_DST_MAC_DST,
1122 static const enum index action_inc_tcp_seq[] = {
1123 ACTION_INC_TCP_SEQ_VALUE,
1128 static const enum index action_dec_tcp_seq[] = {
1129 ACTION_DEC_TCP_SEQ_VALUE,
1134 static const enum index action_inc_tcp_ack[] = {
1135 ACTION_INC_TCP_ACK_VALUE,
1140 static const enum index action_dec_tcp_ack[] = {
1141 ACTION_DEC_TCP_ACK_VALUE,
1146 static int parse_set_raw_encap_decap(struct context *, const struct token *,
1147 const char *, unsigned int,
1148 void *, unsigned int);
1149 static int parse_set_init(struct context *, const struct token *,
1150 const char *, unsigned int,
1151 void *, unsigned int);
1152 static int parse_init(struct context *, const struct token *,
1153 const char *, unsigned int,
1154 void *, unsigned int);
1155 static int parse_vc(struct context *, const struct token *,
1156 const char *, unsigned int,
1157 void *, unsigned int);
1158 static int parse_vc_spec(struct context *, const struct token *,
1159 const char *, unsigned int, void *, unsigned int);
1160 static int parse_vc_conf(struct context *, const struct token *,
1161 const char *, unsigned int, void *, unsigned int);
1162 static int parse_vc_action_rss(struct context *, const struct token *,
1163 const char *, unsigned int, void *,
1165 static int parse_vc_action_rss_func(struct context *, const struct token *,
1166 const char *, unsigned int, void *,
1168 static int parse_vc_action_rss_type(struct context *, const struct token *,
1169 const char *, unsigned int, void *,
1171 static int parse_vc_action_rss_queue(struct context *, const struct token *,
1172 const char *, unsigned int, void *,
1174 static int parse_vc_action_vxlan_encap(struct context *, const struct token *,
1175 const char *, unsigned int, void *,
1177 static int parse_vc_action_nvgre_encap(struct context *, const struct token *,
1178 const char *, unsigned int, void *,
1180 static int parse_vc_action_l2_encap(struct context *, const struct token *,
1181 const char *, unsigned int, void *,
1183 static int parse_vc_action_l2_decap(struct context *, const struct token *,
1184 const char *, unsigned int, void *,
1186 static int parse_vc_action_mplsogre_encap(struct context *,
1187 const struct token *, const char *,
1188 unsigned int, void *, unsigned int);
1189 static int parse_vc_action_mplsogre_decap(struct context *,
1190 const struct token *, const char *,
1191 unsigned int, void *, unsigned int);
1192 static int parse_vc_action_mplsoudp_encap(struct context *,
1193 const struct token *, const char *,
1194 unsigned int, void *, unsigned int);
1195 static int parse_vc_action_mplsoudp_decap(struct context *,
1196 const struct token *, const char *,
1197 unsigned int, void *, unsigned int);
1198 static int parse_vc_action_raw_encap(struct context *,
1199 const struct token *, const char *,
1200 unsigned int, void *, unsigned int);
1201 static int parse_vc_action_raw_decap(struct context *,
1202 const struct token *, const char *,
1203 unsigned int, void *, unsigned int);
1204 static int parse_destroy(struct context *, const struct token *,
1205 const char *, unsigned int,
1206 void *, unsigned int);
1207 static int parse_flush(struct context *, const struct token *,
1208 const char *, unsigned int,
1209 void *, unsigned int);
1210 static int parse_query(struct context *, const struct token *,
1211 const char *, unsigned int,
1212 void *, unsigned int);
1213 static int parse_action(struct context *, const struct token *,
1214 const char *, unsigned int,
1215 void *, unsigned int);
1216 static int parse_list(struct context *, const struct token *,
1217 const char *, unsigned int,
1218 void *, unsigned int);
1219 static int parse_isolate(struct context *, const struct token *,
1220 const char *, unsigned int,
1221 void *, unsigned int);
1222 static int parse_int(struct context *, const struct token *,
1223 const char *, unsigned int,
1224 void *, unsigned int);
1225 static int parse_prefix(struct context *, const struct token *,
1226 const char *, unsigned int,
1227 void *, unsigned int);
1228 static int parse_boolean(struct context *, const struct token *,
1229 const char *, unsigned int,
1230 void *, unsigned int);
1231 static int parse_string(struct context *, const struct token *,
1232 const char *, unsigned int,
1233 void *, unsigned int);
1234 static int parse_hex(struct context *ctx, const struct token *token,
1235 const char *str, unsigned int len,
1236 void *buf, unsigned int size);
1237 static int parse_mac_addr(struct context *, const struct token *,
1238 const char *, unsigned int,
1239 void *, unsigned int);
1240 static int parse_ipv4_addr(struct context *, const struct token *,
1241 const char *, unsigned int,
1242 void *, unsigned int);
1243 static int parse_ipv6_addr(struct context *, const struct token *,
1244 const char *, unsigned int,
1245 void *, unsigned int);
1246 static int parse_port(struct context *, const struct token *,
1247 const char *, unsigned int,
1248 void *, unsigned int);
1249 static int comp_none(struct context *, const struct token *,
1250 unsigned int, char *, unsigned int);
1251 static int comp_boolean(struct context *, const struct token *,
1252 unsigned int, char *, unsigned int);
1253 static int comp_action(struct context *, const struct token *,
1254 unsigned int, char *, unsigned int);
1255 static int comp_port(struct context *, const struct token *,
1256 unsigned int, char *, unsigned int);
1257 static int comp_rule_id(struct context *, const struct token *,
1258 unsigned int, char *, unsigned int);
1259 static int comp_vc_action_rss_type(struct context *, const struct token *,
1260 unsigned int, char *, unsigned int);
1261 static int comp_vc_action_rss_queue(struct context *, const struct token *,
1262 unsigned int, char *, unsigned int);
1264 /** Token definitions. */
1265 static const struct token token_list[] = {
1266 /* Special tokens. */
1269 .help = "null entry, abused as the entry point",
1270 .next = NEXT(NEXT_ENTRY(FLOW)),
1275 .help = "command may end here",
1278 .name = "START_SET",
1279 .help = "null entry, abused as the entry point for set",
1280 .next = NEXT(NEXT_ENTRY(SET)),
1285 .help = "set command may end here",
1287 /* Common tokens. */
1291 .help = "integer value",
1296 .name = "{unsigned}",
1298 .help = "unsigned integer value",
1305 .help = "prefix length for bit-mask",
1306 .call = parse_prefix,
1310 .name = "{boolean}",
1312 .help = "any boolean value",
1313 .call = parse_boolean,
1314 .comp = comp_boolean,
1319 .help = "fixed string",
1320 .call = parse_string,
1326 .help = "fixed string",
1331 .name = "{MAC address}",
1333 .help = "standard MAC address notation",
1334 .call = parse_mac_addr,
1338 .name = "{IPv4 address}",
1339 .type = "IPV4 ADDRESS",
1340 .help = "standard IPv4 address notation",
1341 .call = parse_ipv4_addr,
1345 .name = "{IPv6 address}",
1346 .type = "IPV6 ADDRESS",
1347 .help = "standard IPv6 address notation",
1348 .call = parse_ipv6_addr,
1352 .name = "{rule id}",
1354 .help = "rule identifier",
1356 .comp = comp_rule_id,
1359 .name = "{port_id}",
1361 .help = "port identifier",
1366 .name = "{group_id}",
1368 .help = "group identifier",
1372 [PRIORITY_LEVEL] = {
1375 .help = "priority level",
1379 /* Top-level command. */
1382 .type = "{command} {port_id} [{arg} [...]]",
1383 .help = "manage ingress/egress flow rules",
1384 .next = NEXT(NEXT_ENTRY
1394 /* Sub-level commands. */
1397 .help = "check whether a flow rule can be created",
1398 .next = NEXT(next_vc_attr, NEXT_ENTRY(PORT_ID)),
1399 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1404 .help = "create a flow rule",
1405 .next = NEXT(next_vc_attr, NEXT_ENTRY(PORT_ID)),
1406 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1411 .help = "destroy specific flow rules",
1412 .next = NEXT(NEXT_ENTRY(DESTROY_RULE), NEXT_ENTRY(PORT_ID)),
1413 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1414 .call = parse_destroy,
1418 .help = "destroy all flow rules",
1419 .next = NEXT(NEXT_ENTRY(PORT_ID)),
1420 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1421 .call = parse_flush,
1425 .help = "query an existing flow rule",
1426 .next = NEXT(NEXT_ENTRY(QUERY_ACTION),
1427 NEXT_ENTRY(RULE_ID),
1428 NEXT_ENTRY(PORT_ID)),
1429 .args = ARGS(ARGS_ENTRY(struct buffer, args.query.action.type),
1430 ARGS_ENTRY(struct buffer, args.query.rule),
1431 ARGS_ENTRY(struct buffer, port)),
1432 .call = parse_query,
1436 .help = "list existing flow rules",
1437 .next = NEXT(next_list_attr, NEXT_ENTRY(PORT_ID)),
1438 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1443 .help = "restrict ingress traffic to the defined flow rules",
1444 .next = NEXT(NEXT_ENTRY(BOOLEAN),
1445 NEXT_ENTRY(PORT_ID)),
1446 .args = ARGS(ARGS_ENTRY(struct buffer, args.isolate.set),
1447 ARGS_ENTRY(struct buffer, port)),
1448 .call = parse_isolate,
1450 /* Destroy arguments. */
1453 .help = "specify a rule identifier",
1454 .next = NEXT(next_destroy_attr, NEXT_ENTRY(RULE_ID)),
1455 .args = ARGS(ARGS_ENTRY_PTR(struct buffer, args.destroy.rule)),
1456 .call = parse_destroy,
1458 /* Query arguments. */
1462 .help = "action to query, must be part of the rule",
1463 .call = parse_action,
1464 .comp = comp_action,
1466 /* List arguments. */
1469 .help = "specify a group",
1470 .next = NEXT(next_list_attr, NEXT_ENTRY(GROUP_ID)),
1471 .args = ARGS(ARGS_ENTRY_PTR(struct buffer, args.list.group)),
1474 /* Validate/create attributes. */
1477 .help = "specify a group",
1478 .next = NEXT(next_vc_attr, NEXT_ENTRY(GROUP_ID)),
1479 .args = ARGS(ARGS_ENTRY(struct rte_flow_attr, group)),
1484 .help = "specify a priority level",
1485 .next = NEXT(next_vc_attr, NEXT_ENTRY(PRIORITY_LEVEL)),
1486 .args = ARGS(ARGS_ENTRY(struct rte_flow_attr, priority)),
1491 .help = "affect rule to ingress",
1492 .next = NEXT(next_vc_attr),
1497 .help = "affect rule to egress",
1498 .next = NEXT(next_vc_attr),
1503 .help = "apply rule directly to endpoints found in pattern",
1504 .next = NEXT(next_vc_attr),
1507 /* Validate/create pattern. */
1510 .help = "submit a list of pattern items",
1511 .next = NEXT(next_item),
1516 .help = "match value perfectly (with full bit-mask)",
1517 .call = parse_vc_spec,
1519 [ITEM_PARAM_SPEC] = {
1521 .help = "match value according to configured bit-mask",
1522 .call = parse_vc_spec,
1524 [ITEM_PARAM_LAST] = {
1526 .help = "specify upper bound to establish a range",
1527 .call = parse_vc_spec,
1529 [ITEM_PARAM_MASK] = {
1531 .help = "specify bit-mask with relevant bits set to one",
1532 .call = parse_vc_spec,
1534 [ITEM_PARAM_PREFIX] = {
1536 .help = "generate bit-mask from a prefix length",
1537 .call = parse_vc_spec,
1541 .help = "specify next pattern item",
1542 .next = NEXT(next_item),
1546 .help = "end list of pattern items",
1547 .priv = PRIV_ITEM(END, 0),
1548 .next = NEXT(NEXT_ENTRY(ACTIONS)),
1553 .help = "no-op pattern item",
1554 .priv = PRIV_ITEM(VOID, 0),
1555 .next = NEXT(NEXT_ENTRY(ITEM_NEXT)),
1560 .help = "perform actions when pattern does not match",
1561 .priv = PRIV_ITEM(INVERT, 0),
1562 .next = NEXT(NEXT_ENTRY(ITEM_NEXT)),
1567 .help = "match any protocol for the current layer",
1568 .priv = PRIV_ITEM(ANY, sizeof(struct rte_flow_item_any)),
1569 .next = NEXT(item_any),
1574 .help = "number of layers covered",
1575 .next = NEXT(item_any, NEXT_ENTRY(UNSIGNED), item_param),
1576 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_any, num)),
1580 .help = "match traffic from/to the physical function",
1581 .priv = PRIV_ITEM(PF, 0),
1582 .next = NEXT(NEXT_ENTRY(ITEM_NEXT)),
1587 .help = "match traffic from/to a virtual function ID",
1588 .priv = PRIV_ITEM(VF, sizeof(struct rte_flow_item_vf)),
1589 .next = NEXT(item_vf),
1595 .next = NEXT(item_vf, NEXT_ENTRY(UNSIGNED), item_param),
1596 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_vf, id)),
1600 .help = "match traffic from/to a specific physical port",
1601 .priv = PRIV_ITEM(PHY_PORT,
1602 sizeof(struct rte_flow_item_phy_port)),
1603 .next = NEXT(item_phy_port),
1606 [ITEM_PHY_PORT_INDEX] = {
1608 .help = "physical port index",
1609 .next = NEXT(item_phy_port, NEXT_ENTRY(UNSIGNED), item_param),
1610 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_phy_port, index)),
1614 .help = "match traffic from/to a given DPDK port ID",
1615 .priv = PRIV_ITEM(PORT_ID,
1616 sizeof(struct rte_flow_item_port_id)),
1617 .next = NEXT(item_port_id),
1620 [ITEM_PORT_ID_ID] = {
1622 .help = "DPDK port ID",
1623 .next = NEXT(item_port_id, NEXT_ENTRY(UNSIGNED), item_param),
1624 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_port_id, id)),
1628 .help = "match traffic against value set in previously matched rule",
1629 .priv = PRIV_ITEM(MARK, sizeof(struct rte_flow_item_mark)),
1630 .next = NEXT(item_mark),
1635 .help = "Integer value to match against",
1636 .next = NEXT(item_mark, NEXT_ENTRY(UNSIGNED), item_param),
1637 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_mark, id)),
1641 .help = "match an arbitrary byte string",
1642 .priv = PRIV_ITEM(RAW, ITEM_RAW_SIZE),
1643 .next = NEXT(item_raw),
1646 [ITEM_RAW_RELATIVE] = {
1648 .help = "look for pattern after the previous item",
1649 .next = NEXT(item_raw, NEXT_ENTRY(BOOLEAN), item_param),
1650 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_item_raw,
1653 [ITEM_RAW_SEARCH] = {
1655 .help = "search pattern from offset (see also limit)",
1656 .next = NEXT(item_raw, NEXT_ENTRY(BOOLEAN), item_param),
1657 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_item_raw,
1660 [ITEM_RAW_OFFSET] = {
1662 .help = "absolute or relative offset for pattern",
1663 .next = NEXT(item_raw, NEXT_ENTRY(INTEGER), item_param),
1664 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_raw, offset)),
1666 [ITEM_RAW_LIMIT] = {
1668 .help = "search area limit for start of pattern",
1669 .next = NEXT(item_raw, NEXT_ENTRY(UNSIGNED), item_param),
1670 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_raw, limit)),
1672 [ITEM_RAW_PATTERN] = {
1674 .help = "byte string to look for",
1675 .next = NEXT(item_raw,
1677 NEXT_ENTRY(ITEM_PARAM_IS,
1680 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_raw, pattern),
1681 ARGS_ENTRY(struct rte_flow_item_raw, length),
1682 ARGS_ENTRY_ARB(sizeof(struct rte_flow_item_raw),
1683 ITEM_RAW_PATTERN_SIZE)),
1687 .help = "match Ethernet header",
1688 .priv = PRIV_ITEM(ETH, sizeof(struct rte_flow_item_eth)),
1689 .next = NEXT(item_eth),
1694 .help = "destination MAC",
1695 .next = NEXT(item_eth, NEXT_ENTRY(MAC_ADDR), item_param),
1696 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_eth, dst)),
1700 .help = "source MAC",
1701 .next = NEXT(item_eth, NEXT_ENTRY(MAC_ADDR), item_param),
1702 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_eth, src)),
1706 .help = "EtherType",
1707 .next = NEXT(item_eth, NEXT_ENTRY(UNSIGNED), item_param),
1708 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_eth, type)),
1712 .help = "match 802.1Q/ad VLAN tag",
1713 .priv = PRIV_ITEM(VLAN, sizeof(struct rte_flow_item_vlan)),
1714 .next = NEXT(item_vlan),
1719 .help = "tag control information",
1720 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1721 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vlan, tci)),
1725 .help = "priority code point",
1726 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1727 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_vlan,
1732 .help = "drop eligible indicator",
1733 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1734 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_vlan,
1739 .help = "VLAN identifier",
1740 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1741 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_vlan,
1744 [ITEM_VLAN_INNER_TYPE] = {
1745 .name = "inner_type",
1746 .help = "inner EtherType",
1747 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1748 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vlan,
1753 .help = "match IPv4 header",
1754 .priv = PRIV_ITEM(IPV4, sizeof(struct rte_flow_item_ipv4)),
1755 .next = NEXT(item_ipv4),
1760 .help = "type of service",
1761 .next = NEXT(item_ipv4, NEXT_ENTRY(UNSIGNED), item_param),
1762 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
1763 hdr.type_of_service)),
1767 .help = "time to live",
1768 .next = NEXT(item_ipv4, NEXT_ENTRY(UNSIGNED), item_param),
1769 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
1772 [ITEM_IPV4_PROTO] = {
1774 .help = "next protocol ID",
1775 .next = NEXT(item_ipv4, NEXT_ENTRY(UNSIGNED), item_param),
1776 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
1777 hdr.next_proto_id)),
1781 .help = "source address",
1782 .next = NEXT(item_ipv4, NEXT_ENTRY(IPV4_ADDR), item_param),
1783 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
1788 .help = "destination address",
1789 .next = NEXT(item_ipv4, NEXT_ENTRY(IPV4_ADDR), item_param),
1790 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
1795 .help = "match IPv6 header",
1796 .priv = PRIV_ITEM(IPV6, sizeof(struct rte_flow_item_ipv6)),
1797 .next = NEXT(item_ipv6),
1802 .help = "traffic class",
1803 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
1804 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_ipv6,
1806 "\x0f\xf0\x00\x00")),
1808 [ITEM_IPV6_FLOW] = {
1810 .help = "flow label",
1811 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
1812 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_ipv6,
1814 "\x00\x0f\xff\xff")),
1816 [ITEM_IPV6_PROTO] = {
1818 .help = "protocol (next header)",
1819 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
1820 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
1825 .help = "hop limit",
1826 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
1827 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
1832 .help = "source address",
1833 .next = NEXT(item_ipv6, NEXT_ENTRY(IPV6_ADDR), item_param),
1834 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
1839 .help = "destination address",
1840 .next = NEXT(item_ipv6, NEXT_ENTRY(IPV6_ADDR), item_param),
1841 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
1846 .help = "match ICMP header",
1847 .priv = PRIV_ITEM(ICMP, sizeof(struct rte_flow_item_icmp)),
1848 .next = NEXT(item_icmp),
1851 [ITEM_ICMP_TYPE] = {
1853 .help = "ICMP packet type",
1854 .next = NEXT(item_icmp, NEXT_ENTRY(UNSIGNED), item_param),
1855 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp,
1858 [ITEM_ICMP_CODE] = {
1860 .help = "ICMP packet code",
1861 .next = NEXT(item_icmp, NEXT_ENTRY(UNSIGNED), item_param),
1862 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp,
1867 .help = "match UDP header",
1868 .priv = PRIV_ITEM(UDP, sizeof(struct rte_flow_item_udp)),
1869 .next = NEXT(item_udp),
1874 .help = "UDP source port",
1875 .next = NEXT(item_udp, NEXT_ENTRY(UNSIGNED), item_param),
1876 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_udp,
1881 .help = "UDP destination port",
1882 .next = NEXT(item_udp, NEXT_ENTRY(UNSIGNED), item_param),
1883 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_udp,
1888 .help = "match TCP header",
1889 .priv = PRIV_ITEM(TCP, sizeof(struct rte_flow_item_tcp)),
1890 .next = NEXT(item_tcp),
1895 .help = "TCP source port",
1896 .next = NEXT(item_tcp, NEXT_ENTRY(UNSIGNED), item_param),
1897 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_tcp,
1902 .help = "TCP destination port",
1903 .next = NEXT(item_tcp, NEXT_ENTRY(UNSIGNED), item_param),
1904 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_tcp,
1907 [ITEM_TCP_FLAGS] = {
1909 .help = "TCP flags",
1910 .next = NEXT(item_tcp, NEXT_ENTRY(UNSIGNED), item_param),
1911 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_tcp,
1916 .help = "match SCTP header",
1917 .priv = PRIV_ITEM(SCTP, sizeof(struct rte_flow_item_sctp)),
1918 .next = NEXT(item_sctp),
1923 .help = "SCTP source port",
1924 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
1925 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
1930 .help = "SCTP destination port",
1931 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
1932 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
1937 .help = "validation tag",
1938 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
1939 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
1942 [ITEM_SCTP_CKSUM] = {
1945 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
1946 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
1951 .help = "match VXLAN header",
1952 .priv = PRIV_ITEM(VXLAN, sizeof(struct rte_flow_item_vxlan)),
1953 .next = NEXT(item_vxlan),
1956 [ITEM_VXLAN_VNI] = {
1958 .help = "VXLAN identifier",
1959 .next = NEXT(item_vxlan, NEXT_ENTRY(UNSIGNED), item_param),
1960 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vxlan, vni)),
1964 .help = "match E-Tag header",
1965 .priv = PRIV_ITEM(E_TAG, sizeof(struct rte_flow_item_e_tag)),
1966 .next = NEXT(item_e_tag),
1969 [ITEM_E_TAG_GRP_ECID_B] = {
1970 .name = "grp_ecid_b",
1971 .help = "GRP and E-CID base",
1972 .next = NEXT(item_e_tag, NEXT_ENTRY(UNSIGNED), item_param),
1973 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_e_tag,
1979 .help = "match NVGRE header",
1980 .priv = PRIV_ITEM(NVGRE, sizeof(struct rte_flow_item_nvgre)),
1981 .next = NEXT(item_nvgre),
1984 [ITEM_NVGRE_TNI] = {
1986 .help = "virtual subnet ID",
1987 .next = NEXT(item_nvgre, NEXT_ENTRY(UNSIGNED), item_param),
1988 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_nvgre, tni)),
1992 .help = "match MPLS header",
1993 .priv = PRIV_ITEM(MPLS, sizeof(struct rte_flow_item_mpls)),
1994 .next = NEXT(item_mpls),
1997 [ITEM_MPLS_LABEL] = {
1999 .help = "MPLS label",
2000 .next = NEXT(item_mpls, NEXT_ENTRY(UNSIGNED), item_param),
2001 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_mpls,
2007 .help = "MPLS Traffic Class",
2008 .next = NEXT(item_mpls, NEXT_ENTRY(UNSIGNED), item_param),
2009 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_mpls,
2015 .help = "MPLS Bottom-of-Stack",
2016 .next = NEXT(item_mpls, NEXT_ENTRY(UNSIGNED), item_param),
2017 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_mpls,
2023 .help = "match GRE header",
2024 .priv = PRIV_ITEM(GRE, sizeof(struct rte_flow_item_gre)),
2025 .next = NEXT(item_gre),
2028 [ITEM_GRE_PROTO] = {
2030 .help = "GRE protocol type",
2031 .next = NEXT(item_gre, NEXT_ENTRY(UNSIGNED), item_param),
2032 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gre,
2035 [ITEM_GRE_C_RSVD0_VER] = {
2036 .name = "c_rsvd0_ver",
2038 "checksum (1b), undefined (1b), key bit (1b),"
2039 " sequence number (1b), reserved 0 (9b),"
2041 .next = NEXT(item_gre, NEXT_ENTRY(UNSIGNED), item_param),
2042 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gre,
2045 [ITEM_GRE_C_BIT] = {
2047 .help = "checksum bit (C)",
2048 .next = NEXT(item_gre, NEXT_ENTRY(BOOLEAN), item_param),
2049 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_gre,
2051 "\x80\x00\x00\x00")),
2053 [ITEM_GRE_S_BIT] = {
2055 .help = "sequence number bit (S)",
2056 .next = NEXT(item_gre, NEXT_ENTRY(BOOLEAN), item_param),
2057 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_gre,
2059 "\x10\x00\x00\x00")),
2061 [ITEM_GRE_K_BIT] = {
2063 .help = "key bit (K)",
2064 .next = NEXT(item_gre, NEXT_ENTRY(BOOLEAN), item_param),
2065 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_gre,
2067 "\x20\x00\x00\x00")),
2071 .help = "fuzzy pattern match, expect faster than default",
2072 .priv = PRIV_ITEM(FUZZY,
2073 sizeof(struct rte_flow_item_fuzzy)),
2074 .next = NEXT(item_fuzzy),
2077 [ITEM_FUZZY_THRESH] = {
2079 .help = "match accuracy threshold",
2080 .next = NEXT(item_fuzzy, NEXT_ENTRY(UNSIGNED), item_param),
2081 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_fuzzy,
2086 .help = "match GTP header",
2087 .priv = PRIV_ITEM(GTP, sizeof(struct rte_flow_item_gtp)),
2088 .next = NEXT(item_gtp),
2093 .help = "tunnel endpoint identifier",
2094 .next = NEXT(item_gtp, NEXT_ENTRY(UNSIGNED), item_param),
2095 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gtp, teid)),
2099 .help = "match GTP header",
2100 .priv = PRIV_ITEM(GTPC, sizeof(struct rte_flow_item_gtp)),
2101 .next = NEXT(item_gtp),
2106 .help = "match GTP header",
2107 .priv = PRIV_ITEM(GTPU, sizeof(struct rte_flow_item_gtp)),
2108 .next = NEXT(item_gtp),
2113 .help = "match GENEVE header",
2114 .priv = PRIV_ITEM(GENEVE, sizeof(struct rte_flow_item_geneve)),
2115 .next = NEXT(item_geneve),
2118 [ITEM_GENEVE_VNI] = {
2120 .help = "virtual network identifier",
2121 .next = NEXT(item_geneve, NEXT_ENTRY(UNSIGNED), item_param),
2122 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_geneve, vni)),
2124 [ITEM_GENEVE_PROTO] = {
2126 .help = "GENEVE protocol type",
2127 .next = NEXT(item_geneve, NEXT_ENTRY(UNSIGNED), item_param),
2128 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_geneve,
2131 [ITEM_VXLAN_GPE] = {
2132 .name = "vxlan-gpe",
2133 .help = "match VXLAN-GPE header",
2134 .priv = PRIV_ITEM(VXLAN_GPE,
2135 sizeof(struct rte_flow_item_vxlan_gpe)),
2136 .next = NEXT(item_vxlan_gpe),
2139 [ITEM_VXLAN_GPE_VNI] = {
2141 .help = "VXLAN-GPE identifier",
2142 .next = NEXT(item_vxlan_gpe, NEXT_ENTRY(UNSIGNED), item_param),
2143 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vxlan_gpe,
2146 [ITEM_ARP_ETH_IPV4] = {
2147 .name = "arp_eth_ipv4",
2148 .help = "match ARP header for Ethernet/IPv4",
2149 .priv = PRIV_ITEM(ARP_ETH_IPV4,
2150 sizeof(struct rte_flow_item_arp_eth_ipv4)),
2151 .next = NEXT(item_arp_eth_ipv4),
2154 [ITEM_ARP_ETH_IPV4_SHA] = {
2156 .help = "sender hardware address",
2157 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(MAC_ADDR),
2159 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
2162 [ITEM_ARP_ETH_IPV4_SPA] = {
2164 .help = "sender IPv4 address",
2165 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(IPV4_ADDR),
2167 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
2170 [ITEM_ARP_ETH_IPV4_THA] = {
2172 .help = "target hardware address",
2173 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(MAC_ADDR),
2175 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
2178 [ITEM_ARP_ETH_IPV4_TPA] = {
2180 .help = "target IPv4 address",
2181 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(IPV4_ADDR),
2183 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
2188 .help = "match presence of any IPv6 extension header",
2189 .priv = PRIV_ITEM(IPV6_EXT,
2190 sizeof(struct rte_flow_item_ipv6_ext)),
2191 .next = NEXT(item_ipv6_ext),
2194 [ITEM_IPV6_EXT_NEXT_HDR] = {
2196 .help = "next header",
2197 .next = NEXT(item_ipv6_ext, NEXT_ENTRY(UNSIGNED), item_param),
2198 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6_ext,
2203 .help = "match any ICMPv6 header",
2204 .priv = PRIV_ITEM(ICMP6, sizeof(struct rte_flow_item_icmp6)),
2205 .next = NEXT(item_icmp6),
2208 [ITEM_ICMP6_TYPE] = {
2210 .help = "ICMPv6 type",
2211 .next = NEXT(item_icmp6, NEXT_ENTRY(UNSIGNED), item_param),
2212 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6,
2215 [ITEM_ICMP6_CODE] = {
2217 .help = "ICMPv6 code",
2218 .next = NEXT(item_icmp6, NEXT_ENTRY(UNSIGNED), item_param),
2219 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6,
2222 [ITEM_ICMP6_ND_NS] = {
2223 .name = "icmp6_nd_ns",
2224 .help = "match ICMPv6 neighbor discovery solicitation",
2225 .priv = PRIV_ITEM(ICMP6_ND_NS,
2226 sizeof(struct rte_flow_item_icmp6_nd_ns)),
2227 .next = NEXT(item_icmp6_nd_ns),
2230 [ITEM_ICMP6_ND_NS_TARGET_ADDR] = {
2231 .name = "target_addr",
2232 .help = "target address",
2233 .next = NEXT(item_icmp6_nd_ns, NEXT_ENTRY(IPV6_ADDR),
2235 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6_nd_ns,
2238 [ITEM_ICMP6_ND_NA] = {
2239 .name = "icmp6_nd_na",
2240 .help = "match ICMPv6 neighbor discovery advertisement",
2241 .priv = PRIV_ITEM(ICMP6_ND_NA,
2242 sizeof(struct rte_flow_item_icmp6_nd_na)),
2243 .next = NEXT(item_icmp6_nd_na),
2246 [ITEM_ICMP6_ND_NA_TARGET_ADDR] = {
2247 .name = "target_addr",
2248 .help = "target address",
2249 .next = NEXT(item_icmp6_nd_na, NEXT_ENTRY(IPV6_ADDR),
2251 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6_nd_na,
2254 [ITEM_ICMP6_ND_OPT] = {
2255 .name = "icmp6_nd_opt",
2256 .help = "match presence of any ICMPv6 neighbor discovery"
2258 .priv = PRIV_ITEM(ICMP6_ND_OPT,
2259 sizeof(struct rte_flow_item_icmp6_nd_opt)),
2260 .next = NEXT(item_icmp6_nd_opt),
2263 [ITEM_ICMP6_ND_OPT_TYPE] = {
2265 .help = "ND option type",
2266 .next = NEXT(item_icmp6_nd_opt, NEXT_ENTRY(UNSIGNED),
2268 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6_nd_opt,
2271 [ITEM_ICMP6_ND_OPT_SLA_ETH] = {
2272 .name = "icmp6_nd_opt_sla_eth",
2273 .help = "match ICMPv6 neighbor discovery source Ethernet"
2274 " link-layer address option",
2276 (ICMP6_ND_OPT_SLA_ETH,
2277 sizeof(struct rte_flow_item_icmp6_nd_opt_sla_eth)),
2278 .next = NEXT(item_icmp6_nd_opt_sla_eth),
2281 [ITEM_ICMP6_ND_OPT_SLA_ETH_SLA] = {
2283 .help = "source Ethernet LLA",
2284 .next = NEXT(item_icmp6_nd_opt_sla_eth, NEXT_ENTRY(MAC_ADDR),
2286 .args = ARGS(ARGS_ENTRY_HTON
2287 (struct rte_flow_item_icmp6_nd_opt_sla_eth, sla)),
2289 [ITEM_ICMP6_ND_OPT_TLA_ETH] = {
2290 .name = "icmp6_nd_opt_tla_eth",
2291 .help = "match ICMPv6 neighbor discovery target Ethernet"
2292 " link-layer address option",
2294 (ICMP6_ND_OPT_TLA_ETH,
2295 sizeof(struct rte_flow_item_icmp6_nd_opt_tla_eth)),
2296 .next = NEXT(item_icmp6_nd_opt_tla_eth),
2299 [ITEM_ICMP6_ND_OPT_TLA_ETH_TLA] = {
2301 .help = "target Ethernet LLA",
2302 .next = NEXT(item_icmp6_nd_opt_tla_eth, NEXT_ENTRY(MAC_ADDR),
2304 .args = ARGS(ARGS_ENTRY_HTON
2305 (struct rte_flow_item_icmp6_nd_opt_tla_eth, tla)),
2309 .help = "match metadata header",
2310 .priv = PRIV_ITEM(META, sizeof(struct rte_flow_item_meta)),
2311 .next = NEXT(item_meta),
2314 [ITEM_META_DATA] = {
2316 .help = "metadata value",
2317 .next = NEXT(item_meta, NEXT_ENTRY(UNSIGNED), item_param),
2318 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_meta,
2319 data, "\xff\xff\xff\xff")),
2323 .help = "match GRE key",
2324 .priv = PRIV_ITEM(GRE_KEY, sizeof(rte_be32_t)),
2325 .next = NEXT(item_gre_key),
2328 [ITEM_GRE_KEY_VALUE] = {
2330 .help = "key value",
2331 .next = NEXT(item_gre_key, NEXT_ENTRY(UNSIGNED), item_param),
2332 .args = ARGS(ARG_ENTRY_HTON(rte_be32_t)),
2335 /* Validate/create actions. */
2338 .help = "submit a list of associated actions",
2339 .next = NEXT(next_action),
2344 .help = "specify next action",
2345 .next = NEXT(next_action),
2349 .help = "end list of actions",
2350 .priv = PRIV_ACTION(END, 0),
2355 .help = "no-op action",
2356 .priv = PRIV_ACTION(VOID, 0),
2357 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2360 [ACTION_PASSTHRU] = {
2362 .help = "let subsequent rule process matched packets",
2363 .priv = PRIV_ACTION(PASSTHRU, 0),
2364 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2369 .help = "redirect traffic to a given group",
2370 .priv = PRIV_ACTION(JUMP, sizeof(struct rte_flow_action_jump)),
2371 .next = NEXT(action_jump),
2374 [ACTION_JUMP_GROUP] = {
2376 .help = "group to redirect traffic to",
2377 .next = NEXT(action_jump, NEXT_ENTRY(UNSIGNED)),
2378 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_jump, group)),
2379 .call = parse_vc_conf,
2383 .help = "attach 32 bit value to packets",
2384 .priv = PRIV_ACTION(MARK, sizeof(struct rte_flow_action_mark)),
2385 .next = NEXT(action_mark),
2388 [ACTION_MARK_ID] = {
2390 .help = "32 bit value to return with packets",
2391 .next = NEXT(action_mark, NEXT_ENTRY(UNSIGNED)),
2392 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_mark, id)),
2393 .call = parse_vc_conf,
2397 .help = "flag packets",
2398 .priv = PRIV_ACTION(FLAG, 0),
2399 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2404 .help = "assign packets to a given queue index",
2405 .priv = PRIV_ACTION(QUEUE,
2406 sizeof(struct rte_flow_action_queue)),
2407 .next = NEXT(action_queue),
2410 [ACTION_QUEUE_INDEX] = {
2412 .help = "queue index to use",
2413 .next = NEXT(action_queue, NEXT_ENTRY(UNSIGNED)),
2414 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_queue, index)),
2415 .call = parse_vc_conf,
2419 .help = "drop packets (note: passthru has priority)",
2420 .priv = PRIV_ACTION(DROP, 0),
2421 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2426 .help = "enable counters for this rule",
2427 .priv = PRIV_ACTION(COUNT,
2428 sizeof(struct rte_flow_action_count)),
2429 .next = NEXT(action_count),
2432 [ACTION_COUNT_ID] = {
2433 .name = "identifier",
2434 .help = "counter identifier to use",
2435 .next = NEXT(action_count, NEXT_ENTRY(UNSIGNED)),
2436 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_count, id)),
2437 .call = parse_vc_conf,
2439 [ACTION_COUNT_SHARED] = {
2441 .help = "shared counter",
2442 .next = NEXT(action_count, NEXT_ENTRY(BOOLEAN)),
2443 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_count,
2445 .call = parse_vc_conf,
2449 .help = "spread packets among several queues",
2450 .priv = PRIV_ACTION(RSS, sizeof(struct action_rss_data)),
2451 .next = NEXT(action_rss),
2452 .call = parse_vc_action_rss,
2454 [ACTION_RSS_FUNC] = {
2456 .help = "RSS hash function to apply",
2457 .next = NEXT(action_rss,
2458 NEXT_ENTRY(ACTION_RSS_FUNC_DEFAULT,
2459 ACTION_RSS_FUNC_TOEPLITZ,
2460 ACTION_RSS_FUNC_SIMPLE_XOR)),
2462 [ACTION_RSS_FUNC_DEFAULT] = {
2464 .help = "default hash function",
2465 .call = parse_vc_action_rss_func,
2467 [ACTION_RSS_FUNC_TOEPLITZ] = {
2469 .help = "Toeplitz hash function",
2470 .call = parse_vc_action_rss_func,
2472 [ACTION_RSS_FUNC_SIMPLE_XOR] = {
2473 .name = "simple_xor",
2474 .help = "simple XOR hash function",
2475 .call = parse_vc_action_rss_func,
2477 [ACTION_RSS_LEVEL] = {
2479 .help = "encapsulation level for \"types\"",
2480 .next = NEXT(action_rss, NEXT_ENTRY(UNSIGNED)),
2481 .args = ARGS(ARGS_ENTRY_ARB
2482 (offsetof(struct action_rss_data, conf) +
2483 offsetof(struct rte_flow_action_rss, level),
2484 sizeof(((struct rte_flow_action_rss *)0)->
2487 [ACTION_RSS_TYPES] = {
2489 .help = "specific RSS hash types",
2490 .next = NEXT(action_rss, NEXT_ENTRY(ACTION_RSS_TYPE)),
2492 [ACTION_RSS_TYPE] = {
2494 .help = "RSS hash type",
2495 .call = parse_vc_action_rss_type,
2496 .comp = comp_vc_action_rss_type,
2498 [ACTION_RSS_KEY] = {
2500 .help = "RSS hash key",
2501 .next = NEXT(action_rss, NEXT_ENTRY(HEX)),
2502 .args = ARGS(ARGS_ENTRY_ARB(0, 0),
2504 (offsetof(struct action_rss_data, conf) +
2505 offsetof(struct rte_flow_action_rss, key_len),
2506 sizeof(((struct rte_flow_action_rss *)0)->
2508 ARGS_ENTRY(struct action_rss_data, key)),
2510 [ACTION_RSS_KEY_LEN] = {
2512 .help = "RSS hash key length in bytes",
2513 .next = NEXT(action_rss, NEXT_ENTRY(UNSIGNED)),
2514 .args = ARGS(ARGS_ENTRY_ARB_BOUNDED
2515 (offsetof(struct action_rss_data, conf) +
2516 offsetof(struct rte_flow_action_rss, key_len),
2517 sizeof(((struct rte_flow_action_rss *)0)->
2520 RSS_HASH_KEY_LENGTH)),
2522 [ACTION_RSS_QUEUES] = {
2524 .help = "queue indices to use",
2525 .next = NEXT(action_rss, NEXT_ENTRY(ACTION_RSS_QUEUE)),
2526 .call = parse_vc_conf,
2528 [ACTION_RSS_QUEUE] = {
2530 .help = "queue index",
2531 .call = parse_vc_action_rss_queue,
2532 .comp = comp_vc_action_rss_queue,
2536 .help = "direct traffic to physical function",
2537 .priv = PRIV_ACTION(PF, 0),
2538 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2543 .help = "direct traffic to a virtual function ID",
2544 .priv = PRIV_ACTION(VF, sizeof(struct rte_flow_action_vf)),
2545 .next = NEXT(action_vf),
2548 [ACTION_VF_ORIGINAL] = {
2550 .help = "use original VF ID if possible",
2551 .next = NEXT(action_vf, NEXT_ENTRY(BOOLEAN)),
2552 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_vf,
2554 .call = parse_vc_conf,
2559 .next = NEXT(action_vf, NEXT_ENTRY(UNSIGNED)),
2560 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_vf, id)),
2561 .call = parse_vc_conf,
2563 [ACTION_PHY_PORT] = {
2565 .help = "direct packets to physical port index",
2566 .priv = PRIV_ACTION(PHY_PORT,
2567 sizeof(struct rte_flow_action_phy_port)),
2568 .next = NEXT(action_phy_port),
2571 [ACTION_PHY_PORT_ORIGINAL] = {
2573 .help = "use original port index if possible",
2574 .next = NEXT(action_phy_port, NEXT_ENTRY(BOOLEAN)),
2575 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_phy_port,
2577 .call = parse_vc_conf,
2579 [ACTION_PHY_PORT_INDEX] = {
2581 .help = "physical port index",
2582 .next = NEXT(action_phy_port, NEXT_ENTRY(UNSIGNED)),
2583 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_phy_port,
2585 .call = parse_vc_conf,
2587 [ACTION_PORT_ID] = {
2589 .help = "direct matching traffic to a given DPDK port ID",
2590 .priv = PRIV_ACTION(PORT_ID,
2591 sizeof(struct rte_flow_action_port_id)),
2592 .next = NEXT(action_port_id),
2595 [ACTION_PORT_ID_ORIGINAL] = {
2597 .help = "use original DPDK port ID if possible",
2598 .next = NEXT(action_port_id, NEXT_ENTRY(BOOLEAN)),
2599 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_port_id,
2601 .call = parse_vc_conf,
2603 [ACTION_PORT_ID_ID] = {
2605 .help = "DPDK port ID",
2606 .next = NEXT(action_port_id, NEXT_ENTRY(UNSIGNED)),
2607 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_port_id, id)),
2608 .call = parse_vc_conf,
2612 .help = "meter the directed packets at given id",
2613 .priv = PRIV_ACTION(METER,
2614 sizeof(struct rte_flow_action_meter)),
2615 .next = NEXT(action_meter),
2618 [ACTION_METER_ID] = {
2620 .help = "meter id to use",
2621 .next = NEXT(action_meter, NEXT_ENTRY(UNSIGNED)),
2622 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_meter, mtr_id)),
2623 .call = parse_vc_conf,
2625 [ACTION_OF_SET_MPLS_TTL] = {
2626 .name = "of_set_mpls_ttl",
2627 .help = "OpenFlow's OFPAT_SET_MPLS_TTL",
2630 sizeof(struct rte_flow_action_of_set_mpls_ttl)),
2631 .next = NEXT(action_of_set_mpls_ttl),
2634 [ACTION_OF_SET_MPLS_TTL_MPLS_TTL] = {
2637 .next = NEXT(action_of_set_mpls_ttl, NEXT_ENTRY(UNSIGNED)),
2638 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_of_set_mpls_ttl,
2640 .call = parse_vc_conf,
2642 [ACTION_OF_DEC_MPLS_TTL] = {
2643 .name = "of_dec_mpls_ttl",
2644 .help = "OpenFlow's OFPAT_DEC_MPLS_TTL",
2645 .priv = PRIV_ACTION(OF_DEC_MPLS_TTL, 0),
2646 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2649 [ACTION_OF_SET_NW_TTL] = {
2650 .name = "of_set_nw_ttl",
2651 .help = "OpenFlow's OFPAT_SET_NW_TTL",
2654 sizeof(struct rte_flow_action_of_set_nw_ttl)),
2655 .next = NEXT(action_of_set_nw_ttl),
2658 [ACTION_OF_SET_NW_TTL_NW_TTL] = {
2661 .next = NEXT(action_of_set_nw_ttl, NEXT_ENTRY(UNSIGNED)),
2662 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_of_set_nw_ttl,
2664 .call = parse_vc_conf,
2666 [ACTION_OF_DEC_NW_TTL] = {
2667 .name = "of_dec_nw_ttl",
2668 .help = "OpenFlow's OFPAT_DEC_NW_TTL",
2669 .priv = PRIV_ACTION(OF_DEC_NW_TTL, 0),
2670 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2673 [ACTION_OF_COPY_TTL_OUT] = {
2674 .name = "of_copy_ttl_out",
2675 .help = "OpenFlow's OFPAT_COPY_TTL_OUT",
2676 .priv = PRIV_ACTION(OF_COPY_TTL_OUT, 0),
2677 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2680 [ACTION_OF_COPY_TTL_IN] = {
2681 .name = "of_copy_ttl_in",
2682 .help = "OpenFlow's OFPAT_COPY_TTL_IN",
2683 .priv = PRIV_ACTION(OF_COPY_TTL_IN, 0),
2684 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2687 [ACTION_OF_POP_VLAN] = {
2688 .name = "of_pop_vlan",
2689 .help = "OpenFlow's OFPAT_POP_VLAN",
2690 .priv = PRIV_ACTION(OF_POP_VLAN, 0),
2691 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2694 [ACTION_OF_PUSH_VLAN] = {
2695 .name = "of_push_vlan",
2696 .help = "OpenFlow's OFPAT_PUSH_VLAN",
2699 sizeof(struct rte_flow_action_of_push_vlan)),
2700 .next = NEXT(action_of_push_vlan),
2703 [ACTION_OF_PUSH_VLAN_ETHERTYPE] = {
2704 .name = "ethertype",
2705 .help = "EtherType",
2706 .next = NEXT(action_of_push_vlan, NEXT_ENTRY(UNSIGNED)),
2707 .args = ARGS(ARGS_ENTRY_HTON
2708 (struct rte_flow_action_of_push_vlan,
2710 .call = parse_vc_conf,
2712 [ACTION_OF_SET_VLAN_VID] = {
2713 .name = "of_set_vlan_vid",
2714 .help = "OpenFlow's OFPAT_SET_VLAN_VID",
2717 sizeof(struct rte_flow_action_of_set_vlan_vid)),
2718 .next = NEXT(action_of_set_vlan_vid),
2721 [ACTION_OF_SET_VLAN_VID_VLAN_VID] = {
2724 .next = NEXT(action_of_set_vlan_vid, NEXT_ENTRY(UNSIGNED)),
2725 .args = ARGS(ARGS_ENTRY_HTON
2726 (struct rte_flow_action_of_set_vlan_vid,
2728 .call = parse_vc_conf,
2730 [ACTION_OF_SET_VLAN_PCP] = {
2731 .name = "of_set_vlan_pcp",
2732 .help = "OpenFlow's OFPAT_SET_VLAN_PCP",
2735 sizeof(struct rte_flow_action_of_set_vlan_pcp)),
2736 .next = NEXT(action_of_set_vlan_pcp),
2739 [ACTION_OF_SET_VLAN_PCP_VLAN_PCP] = {
2741 .help = "VLAN priority",
2742 .next = NEXT(action_of_set_vlan_pcp, NEXT_ENTRY(UNSIGNED)),
2743 .args = ARGS(ARGS_ENTRY_HTON
2744 (struct rte_flow_action_of_set_vlan_pcp,
2746 .call = parse_vc_conf,
2748 [ACTION_OF_POP_MPLS] = {
2749 .name = "of_pop_mpls",
2750 .help = "OpenFlow's OFPAT_POP_MPLS",
2751 .priv = PRIV_ACTION(OF_POP_MPLS,
2752 sizeof(struct rte_flow_action_of_pop_mpls)),
2753 .next = NEXT(action_of_pop_mpls),
2756 [ACTION_OF_POP_MPLS_ETHERTYPE] = {
2757 .name = "ethertype",
2758 .help = "EtherType",
2759 .next = NEXT(action_of_pop_mpls, NEXT_ENTRY(UNSIGNED)),
2760 .args = ARGS(ARGS_ENTRY_HTON
2761 (struct rte_flow_action_of_pop_mpls,
2763 .call = parse_vc_conf,
2765 [ACTION_OF_PUSH_MPLS] = {
2766 .name = "of_push_mpls",
2767 .help = "OpenFlow's OFPAT_PUSH_MPLS",
2770 sizeof(struct rte_flow_action_of_push_mpls)),
2771 .next = NEXT(action_of_push_mpls),
2774 [ACTION_OF_PUSH_MPLS_ETHERTYPE] = {
2775 .name = "ethertype",
2776 .help = "EtherType",
2777 .next = NEXT(action_of_push_mpls, NEXT_ENTRY(UNSIGNED)),
2778 .args = ARGS(ARGS_ENTRY_HTON
2779 (struct rte_flow_action_of_push_mpls,
2781 .call = parse_vc_conf,
2783 [ACTION_VXLAN_ENCAP] = {
2784 .name = "vxlan_encap",
2785 .help = "VXLAN encapsulation, uses configuration set by \"set"
2787 .priv = PRIV_ACTION(VXLAN_ENCAP,
2788 sizeof(struct action_vxlan_encap_data)),
2789 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2790 .call = parse_vc_action_vxlan_encap,
2792 [ACTION_VXLAN_DECAP] = {
2793 .name = "vxlan_decap",
2794 .help = "Performs a decapsulation action by stripping all"
2795 " headers of the VXLAN tunnel network overlay from the"
2797 .priv = PRIV_ACTION(VXLAN_DECAP, 0),
2798 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2801 [ACTION_NVGRE_ENCAP] = {
2802 .name = "nvgre_encap",
2803 .help = "NVGRE encapsulation, uses configuration set by \"set"
2805 .priv = PRIV_ACTION(NVGRE_ENCAP,
2806 sizeof(struct action_nvgre_encap_data)),
2807 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2808 .call = parse_vc_action_nvgre_encap,
2810 [ACTION_NVGRE_DECAP] = {
2811 .name = "nvgre_decap",
2812 .help = "Performs a decapsulation action by stripping all"
2813 " headers of the NVGRE tunnel network overlay from the"
2815 .priv = PRIV_ACTION(NVGRE_DECAP, 0),
2816 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2819 [ACTION_L2_ENCAP] = {
2821 .help = "l2 encap, uses configuration set by"
2822 " \"set l2_encap\"",
2823 .priv = PRIV_ACTION(RAW_ENCAP,
2824 sizeof(struct action_raw_encap_data)),
2825 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2826 .call = parse_vc_action_l2_encap,
2828 [ACTION_L2_DECAP] = {
2830 .help = "l2 decap, uses configuration set by"
2831 " \"set l2_decap\"",
2832 .priv = PRIV_ACTION(RAW_DECAP,
2833 sizeof(struct action_raw_decap_data)),
2834 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2835 .call = parse_vc_action_l2_decap,
2837 [ACTION_MPLSOGRE_ENCAP] = {
2838 .name = "mplsogre_encap",
2839 .help = "mplsogre encapsulation, uses configuration set by"
2840 " \"set mplsogre_encap\"",
2841 .priv = PRIV_ACTION(RAW_ENCAP,
2842 sizeof(struct action_raw_encap_data)),
2843 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2844 .call = parse_vc_action_mplsogre_encap,
2846 [ACTION_MPLSOGRE_DECAP] = {
2847 .name = "mplsogre_decap",
2848 .help = "mplsogre decapsulation, uses configuration set by"
2849 " \"set mplsogre_decap\"",
2850 .priv = PRIV_ACTION(RAW_DECAP,
2851 sizeof(struct action_raw_decap_data)),
2852 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2853 .call = parse_vc_action_mplsogre_decap,
2855 [ACTION_MPLSOUDP_ENCAP] = {
2856 .name = "mplsoudp_encap",
2857 .help = "mplsoudp encapsulation, uses configuration set by"
2858 " \"set mplsoudp_encap\"",
2859 .priv = PRIV_ACTION(RAW_ENCAP,
2860 sizeof(struct action_raw_encap_data)),
2861 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2862 .call = parse_vc_action_mplsoudp_encap,
2864 [ACTION_MPLSOUDP_DECAP] = {
2865 .name = "mplsoudp_decap",
2866 .help = "mplsoudp decapsulation, uses configuration set by"
2867 " \"set mplsoudp_decap\"",
2868 .priv = PRIV_ACTION(RAW_DECAP,
2869 sizeof(struct action_raw_decap_data)),
2870 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2871 .call = parse_vc_action_mplsoudp_decap,
2873 [ACTION_SET_IPV4_SRC] = {
2874 .name = "set_ipv4_src",
2875 .help = "Set a new IPv4 source address in the outermost"
2877 .priv = PRIV_ACTION(SET_IPV4_SRC,
2878 sizeof(struct rte_flow_action_set_ipv4)),
2879 .next = NEXT(action_set_ipv4_src),
2882 [ACTION_SET_IPV4_SRC_IPV4_SRC] = {
2883 .name = "ipv4_addr",
2884 .help = "new IPv4 source address to set",
2885 .next = NEXT(action_set_ipv4_src, NEXT_ENTRY(IPV4_ADDR)),
2886 .args = ARGS(ARGS_ENTRY_HTON
2887 (struct rte_flow_action_set_ipv4, ipv4_addr)),
2888 .call = parse_vc_conf,
2890 [ACTION_SET_IPV4_DST] = {
2891 .name = "set_ipv4_dst",
2892 .help = "Set a new IPv4 destination address in the outermost"
2894 .priv = PRIV_ACTION(SET_IPV4_DST,
2895 sizeof(struct rte_flow_action_set_ipv4)),
2896 .next = NEXT(action_set_ipv4_dst),
2899 [ACTION_SET_IPV4_DST_IPV4_DST] = {
2900 .name = "ipv4_addr",
2901 .help = "new IPv4 destination address to set",
2902 .next = NEXT(action_set_ipv4_dst, NEXT_ENTRY(IPV4_ADDR)),
2903 .args = ARGS(ARGS_ENTRY_HTON
2904 (struct rte_flow_action_set_ipv4, ipv4_addr)),
2905 .call = parse_vc_conf,
2907 [ACTION_SET_IPV6_SRC] = {
2908 .name = "set_ipv6_src",
2909 .help = "Set a new IPv6 source address in the outermost"
2911 .priv = PRIV_ACTION(SET_IPV6_SRC,
2912 sizeof(struct rte_flow_action_set_ipv6)),
2913 .next = NEXT(action_set_ipv6_src),
2916 [ACTION_SET_IPV6_SRC_IPV6_SRC] = {
2917 .name = "ipv6_addr",
2918 .help = "new IPv6 source address to set",
2919 .next = NEXT(action_set_ipv6_src, NEXT_ENTRY(IPV6_ADDR)),
2920 .args = ARGS(ARGS_ENTRY_HTON
2921 (struct rte_flow_action_set_ipv6, ipv6_addr)),
2922 .call = parse_vc_conf,
2924 [ACTION_SET_IPV6_DST] = {
2925 .name = "set_ipv6_dst",
2926 .help = "Set a new IPv6 destination address in the outermost"
2928 .priv = PRIV_ACTION(SET_IPV6_DST,
2929 sizeof(struct rte_flow_action_set_ipv6)),
2930 .next = NEXT(action_set_ipv6_dst),
2933 [ACTION_SET_IPV6_DST_IPV6_DST] = {
2934 .name = "ipv6_addr",
2935 .help = "new IPv6 destination address to set",
2936 .next = NEXT(action_set_ipv6_dst, NEXT_ENTRY(IPV6_ADDR)),
2937 .args = ARGS(ARGS_ENTRY_HTON
2938 (struct rte_flow_action_set_ipv6, ipv6_addr)),
2939 .call = parse_vc_conf,
2941 [ACTION_SET_TP_SRC] = {
2942 .name = "set_tp_src",
2943 .help = "set a new source port number in the outermost"
2945 .priv = PRIV_ACTION(SET_TP_SRC,
2946 sizeof(struct rte_flow_action_set_tp)),
2947 .next = NEXT(action_set_tp_src),
2950 [ACTION_SET_TP_SRC_TP_SRC] = {
2952 .help = "new source port number to set",
2953 .next = NEXT(action_set_tp_src, NEXT_ENTRY(UNSIGNED)),
2954 .args = ARGS(ARGS_ENTRY_HTON
2955 (struct rte_flow_action_set_tp, port)),
2956 .call = parse_vc_conf,
2958 [ACTION_SET_TP_DST] = {
2959 .name = "set_tp_dst",
2960 .help = "set a new destination port number in the outermost"
2962 .priv = PRIV_ACTION(SET_TP_DST,
2963 sizeof(struct rte_flow_action_set_tp)),
2964 .next = NEXT(action_set_tp_dst),
2967 [ACTION_SET_TP_DST_TP_DST] = {
2969 .help = "new destination port number to set",
2970 .next = NEXT(action_set_tp_dst, NEXT_ENTRY(UNSIGNED)),
2971 .args = ARGS(ARGS_ENTRY_HTON
2972 (struct rte_flow_action_set_tp, port)),
2973 .call = parse_vc_conf,
2975 [ACTION_MAC_SWAP] = {
2977 .help = "Swap the source and destination MAC addresses"
2978 " in the outermost Ethernet header",
2979 .priv = PRIV_ACTION(MAC_SWAP, 0),
2980 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2983 [ACTION_DEC_TTL] = {
2985 .help = "decrease network TTL if available",
2986 .priv = PRIV_ACTION(DEC_TTL, 0),
2987 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2990 [ACTION_SET_TTL] = {
2992 .help = "set ttl value",
2993 .priv = PRIV_ACTION(SET_TTL,
2994 sizeof(struct rte_flow_action_set_ttl)),
2995 .next = NEXT(action_set_ttl),
2998 [ACTION_SET_TTL_TTL] = {
2999 .name = "ttl_value",
3000 .help = "new ttl value to set",
3001 .next = NEXT(action_set_ttl, NEXT_ENTRY(UNSIGNED)),
3002 .args = ARGS(ARGS_ENTRY_HTON
3003 (struct rte_flow_action_set_ttl, ttl_value)),
3004 .call = parse_vc_conf,
3006 [ACTION_SET_MAC_SRC] = {
3007 .name = "set_mac_src",
3008 .help = "set source mac address",
3009 .priv = PRIV_ACTION(SET_MAC_SRC,
3010 sizeof(struct rte_flow_action_set_mac)),
3011 .next = NEXT(action_set_mac_src),
3014 [ACTION_SET_MAC_SRC_MAC_SRC] = {
3016 .help = "new source mac address",
3017 .next = NEXT(action_set_mac_src, NEXT_ENTRY(MAC_ADDR)),
3018 .args = ARGS(ARGS_ENTRY_HTON
3019 (struct rte_flow_action_set_mac, mac_addr)),
3020 .call = parse_vc_conf,
3022 [ACTION_SET_MAC_DST] = {
3023 .name = "set_mac_dst",
3024 .help = "set destination mac address",
3025 .priv = PRIV_ACTION(SET_MAC_DST,
3026 sizeof(struct rte_flow_action_set_mac)),
3027 .next = NEXT(action_set_mac_dst),
3030 [ACTION_SET_MAC_DST_MAC_DST] = {
3032 .help = "new destination mac address to set",
3033 .next = NEXT(action_set_mac_dst, NEXT_ENTRY(MAC_ADDR)),
3034 .args = ARGS(ARGS_ENTRY_HTON
3035 (struct rte_flow_action_set_mac, mac_addr)),
3036 .call = parse_vc_conf,
3038 [ACTION_INC_TCP_SEQ] = {
3039 .name = "inc_tcp_seq",
3040 .help = "increase TCP sequence number",
3041 .priv = PRIV_ACTION(INC_TCP_SEQ, sizeof(rte_be32_t)),
3042 .next = NEXT(action_inc_tcp_seq),
3045 [ACTION_INC_TCP_SEQ_VALUE] = {
3047 .help = "the value to increase TCP sequence number by",
3048 .next = NEXT(action_inc_tcp_seq, NEXT_ENTRY(UNSIGNED)),
3049 .args = ARGS(ARG_ENTRY_HTON(rte_be32_t)),
3050 .call = parse_vc_conf,
3052 [ACTION_DEC_TCP_SEQ] = {
3053 .name = "dec_tcp_seq",
3054 .help = "decrease TCP sequence number",
3055 .priv = PRIV_ACTION(DEC_TCP_SEQ, sizeof(rte_be32_t)),
3056 .next = NEXT(action_dec_tcp_seq),
3059 [ACTION_DEC_TCP_SEQ_VALUE] = {
3061 .help = "the value to decrease TCP sequence number by",
3062 .next = NEXT(action_dec_tcp_seq, NEXT_ENTRY(UNSIGNED)),
3063 .args = ARGS(ARG_ENTRY_HTON(rte_be32_t)),
3064 .call = parse_vc_conf,
3066 [ACTION_INC_TCP_ACK] = {
3067 .name = "inc_tcp_ack",
3068 .help = "increase TCP acknowledgment number",
3069 .priv = PRIV_ACTION(INC_TCP_ACK, sizeof(rte_be32_t)),
3070 .next = NEXT(action_inc_tcp_ack),
3073 [ACTION_INC_TCP_ACK_VALUE] = {
3075 .help = "the value to increase TCP acknowledgment number by",
3076 .next = NEXT(action_inc_tcp_ack, NEXT_ENTRY(UNSIGNED)),
3077 .args = ARGS(ARG_ENTRY_HTON(rte_be32_t)),
3078 .call = parse_vc_conf,
3080 [ACTION_DEC_TCP_ACK] = {
3081 .name = "dec_tcp_ack",
3082 .help = "decrease TCP acknowledgment number",
3083 .priv = PRIV_ACTION(DEC_TCP_ACK, sizeof(rte_be32_t)),
3084 .next = NEXT(action_dec_tcp_ack),
3087 [ACTION_DEC_TCP_ACK_VALUE] = {
3089 .help = "the value to decrease TCP acknowledgment number by",
3090 .next = NEXT(action_dec_tcp_ack, NEXT_ENTRY(UNSIGNED)),
3091 .args = ARGS(ARG_ENTRY_HTON(rte_be32_t)),
3092 .call = parse_vc_conf,
3094 [ACTION_RAW_ENCAP] = {
3095 .name = "raw_encap",
3096 .help = "encapsulation data, defined by set raw_encap",
3097 .priv = PRIV_ACTION(RAW_ENCAP,
3098 sizeof(struct rte_flow_action_raw_encap)),
3099 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3100 .call = parse_vc_action_raw_encap,
3102 [ACTION_RAW_DECAP] = {
3103 .name = "raw_decap",
3104 .help = "decapsulation data, defined by set raw_encap",
3105 .priv = PRIV_ACTION(RAW_DECAP,
3106 sizeof(struct rte_flow_action_raw_decap)),
3107 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3108 .call = parse_vc_action_raw_decap,
3110 /* Top level command. */
3113 .help = "set raw encap/decap data",
3114 .type = "set raw_encap|raw_decap <pattern>",
3115 .next = NEXT(NEXT_ENTRY
3118 .call = parse_set_init,
3120 /* Sub-level commands. */
3122 .name = "raw_encap",
3123 .help = "set raw encap data",
3124 .next = NEXT(next_item),
3125 .call = parse_set_raw_encap_decap,
3128 .name = "raw_decap",
3129 .help = "set raw decap data",
3130 .next = NEXT(next_item),
3131 .call = parse_set_raw_encap_decap,
3135 /** Remove and return last entry from argument stack. */
3136 static const struct arg *
3137 pop_args(struct context *ctx)
3139 return ctx->args_num ? ctx->args[--ctx->args_num] : NULL;
3142 /** Add entry on top of the argument stack. */
3144 push_args(struct context *ctx, const struct arg *arg)
3146 if (ctx->args_num == CTX_STACK_SIZE)
3148 ctx->args[ctx->args_num++] = arg;
3152 /** Spread value into buffer according to bit-mask. */
3154 arg_entry_bf_fill(void *dst, uintmax_t val, const struct arg *arg)
3156 uint32_t i = arg->size;
3164 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
3173 unsigned int shift = 0;
3174 uint8_t *buf = (uint8_t *)dst + arg->offset + (i -= sub);
3176 for (shift = 0; arg->mask[i] >> shift; ++shift) {
3177 if (!(arg->mask[i] & (1 << shift)))
3182 *buf &= ~(1 << shift);
3183 *buf |= (val & 1) << shift;
3191 /** Compare a string with a partial one of a given length. */
3193 strcmp_partial(const char *full, const char *partial, size_t partial_len)
3195 int r = strncmp(full, partial, partial_len);
3199 if (strlen(full) <= partial_len)
3201 return full[partial_len];
3205 * Parse a prefix length and generate a bit-mask.
3207 * Last argument (ctx->args) is retrieved to determine mask size, storage
3208 * location and whether the result must use network byte ordering.
3211 parse_prefix(struct context *ctx, const struct token *token,
3212 const char *str, unsigned int len,
3213 void *buf, unsigned int size)
3215 const struct arg *arg = pop_args(ctx);
3216 static const uint8_t conv[] = "\x00\x80\xc0\xe0\xf0\xf8\xfc\xfe\xff";
3223 /* Argument is expected. */
3227 u = strtoumax(str, &end, 0);
3228 if (errno || (size_t)(end - str) != len)
3233 extra = arg_entry_bf_fill(NULL, 0, arg);
3242 if (!arg_entry_bf_fill(ctx->object, v, arg) ||
3243 !arg_entry_bf_fill(ctx->objmask, -1, arg))
3250 if (bytes > size || bytes + !!extra > size)
3254 buf = (uint8_t *)ctx->object + arg->offset;
3255 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
3257 memset((uint8_t *)buf + size - bytes, 0xff, bytes);
3258 memset(buf, 0x00, size - bytes);
3260 ((uint8_t *)buf)[size - bytes - 1] = conv[extra];
3264 memset(buf, 0xff, bytes);
3265 memset((uint8_t *)buf + bytes, 0x00, size - bytes);
3267 ((uint8_t *)buf)[bytes] = conv[extra];
3270 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
3273 push_args(ctx, arg);
3277 /** Default parsing function for token name matching. */
3279 parse_default(struct context *ctx, const struct token *token,
3280 const char *str, unsigned int len,
3281 void *buf, unsigned int size)
3286 if (strcmp_partial(token->name, str, len))
3291 /** Parse flow command, initialize output buffer for subsequent tokens. */
3293 parse_init(struct context *ctx, const struct token *token,
3294 const char *str, unsigned int len,
3295 void *buf, unsigned int size)
3297 struct buffer *out = buf;
3299 /* Token name must match. */
3300 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
3302 /* Nothing else to do if there is no buffer. */
3305 /* Make sure buffer is large enough. */
3306 if (size < sizeof(*out))
3308 /* Initialize buffer. */
3309 memset(out, 0x00, sizeof(*out));
3310 memset((uint8_t *)out + sizeof(*out), 0x22, size - sizeof(*out));
3313 ctx->objmask = NULL;
3317 /** Parse tokens for validate/create commands. */
3319 parse_vc(struct context *ctx, const struct token *token,
3320 const char *str, unsigned int len,
3321 void *buf, unsigned int size)
3323 struct buffer *out = buf;
3327 /* Token name must match. */
3328 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
3330 /* Nothing else to do if there is no buffer. */
3333 if (!out->command) {
3334 if (ctx->curr != VALIDATE && ctx->curr != CREATE)
3336 if (sizeof(*out) > size)
3338 out->command = ctx->curr;
3341 ctx->objmask = NULL;
3342 out->args.vc.data = (uint8_t *)out + size;
3346 ctx->object = &out->args.vc.attr;
3347 ctx->objmask = NULL;
3348 switch (ctx->curr) {
3353 out->args.vc.attr.ingress = 1;
3356 out->args.vc.attr.egress = 1;
3359 out->args.vc.attr.transfer = 1;
3362 out->args.vc.pattern =
3363 (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
3365 ctx->object = out->args.vc.pattern;
3366 ctx->objmask = NULL;
3369 out->args.vc.actions =
3370 (void *)RTE_ALIGN_CEIL((uintptr_t)
3371 (out->args.vc.pattern +
3372 out->args.vc.pattern_n),
3374 ctx->object = out->args.vc.actions;
3375 ctx->objmask = NULL;
3382 if (!out->args.vc.actions) {
3383 const struct parse_item_priv *priv = token->priv;
3384 struct rte_flow_item *item =
3385 out->args.vc.pattern + out->args.vc.pattern_n;
3387 data_size = priv->size * 3; /* spec, last, mask */
3388 data = (void *)RTE_ALIGN_FLOOR((uintptr_t)
3389 (out->args.vc.data - data_size),
3391 if ((uint8_t *)item + sizeof(*item) > data)
3393 *item = (struct rte_flow_item){
3396 ++out->args.vc.pattern_n;
3398 ctx->objmask = NULL;
3400 const struct parse_action_priv *priv = token->priv;
3401 struct rte_flow_action *action =
3402 out->args.vc.actions + out->args.vc.actions_n;
3404 data_size = priv->size; /* configuration */
3405 data = (void *)RTE_ALIGN_FLOOR((uintptr_t)
3406 (out->args.vc.data - data_size),
3408 if ((uint8_t *)action + sizeof(*action) > data)
3410 *action = (struct rte_flow_action){
3412 .conf = data_size ? data : NULL,
3414 ++out->args.vc.actions_n;
3415 ctx->object = action;
3416 ctx->objmask = NULL;
3418 memset(data, 0, data_size);
3419 out->args.vc.data = data;
3420 ctx->objdata = data_size;
3424 /** Parse pattern item parameter type. */
3426 parse_vc_spec(struct context *ctx, const struct token *token,
3427 const char *str, unsigned int len,
3428 void *buf, unsigned int size)
3430 struct buffer *out = buf;
3431 struct rte_flow_item *item;
3437 /* Token name must match. */
3438 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
3440 /* Parse parameter types. */
3441 switch (ctx->curr) {
3442 static const enum index prefix[] = NEXT_ENTRY(PREFIX);
3448 case ITEM_PARAM_SPEC:
3451 case ITEM_PARAM_LAST:
3454 case ITEM_PARAM_PREFIX:
3455 /* Modify next token to expect a prefix. */
3456 if (ctx->next_num < 2)
3458 ctx->next[ctx->next_num - 2] = prefix;
3460 case ITEM_PARAM_MASK:
3466 /* Nothing else to do if there is no buffer. */
3469 if (!out->args.vc.pattern_n)
3471 item = &out->args.vc.pattern[out->args.vc.pattern_n - 1];
3472 data_size = ctx->objdata / 3; /* spec, last, mask */
3473 /* Point to selected object. */
3474 ctx->object = out->args.vc.data + (data_size * index);
3476 ctx->objmask = out->args.vc.data + (data_size * 2); /* mask */
3477 item->mask = ctx->objmask;
3479 ctx->objmask = NULL;
3480 /* Update relevant item pointer. */
3481 *((const void **[]){ &item->spec, &item->last, &item->mask })[index] =
3486 /** Parse action configuration field. */
3488 parse_vc_conf(struct context *ctx, const struct token *token,
3489 const char *str, unsigned int len,
3490 void *buf, unsigned int size)
3492 struct buffer *out = buf;
3495 /* Token name must match. */
3496 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
3498 /* Nothing else to do if there is no buffer. */
3501 /* Point to selected object. */
3502 ctx->object = out->args.vc.data;
3503 ctx->objmask = NULL;
3507 /** Parse RSS action. */
3509 parse_vc_action_rss(struct context *ctx, const struct token *token,
3510 const char *str, unsigned int len,
3511 void *buf, unsigned int size)
3513 struct buffer *out = buf;
3514 struct rte_flow_action *action;
3515 struct action_rss_data *action_rss_data;
3519 ret = parse_vc(ctx, token, str, len, buf, size);
3522 /* Nothing else to do if there is no buffer. */
3525 if (!out->args.vc.actions_n)
3527 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
3528 /* Point to selected object. */
3529 ctx->object = out->args.vc.data;
3530 ctx->objmask = NULL;
3531 /* Set up default configuration. */
3532 action_rss_data = ctx->object;
3533 *action_rss_data = (struct action_rss_data){
3534 .conf = (struct rte_flow_action_rss){
3535 .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
3538 .key_len = sizeof(action_rss_data->key),
3539 .queue_num = RTE_MIN(nb_rxq, ACTION_RSS_QUEUE_NUM),
3540 .key = action_rss_data->key,
3541 .queue = action_rss_data->queue,
3543 .key = "testpmd's default RSS hash key, "
3544 "override it for better balancing",
3547 for (i = 0; i < action_rss_data->conf.queue_num; ++i)
3548 action_rss_data->queue[i] = i;
3549 if (!port_id_is_invalid(ctx->port, DISABLED_WARN) &&
3550 ctx->port != (portid_t)RTE_PORT_ALL) {
3551 struct rte_eth_dev_info info;
3553 rte_eth_dev_info_get(ctx->port, &info);
3554 action_rss_data->conf.key_len =
3555 RTE_MIN(sizeof(action_rss_data->key),
3556 info.hash_key_size);
3558 action->conf = &action_rss_data->conf;
3563 * Parse func field for RSS action.
3565 * The RTE_ETH_HASH_FUNCTION_* value to assign is derived from the
3566 * ACTION_RSS_FUNC_* index that called this function.
3569 parse_vc_action_rss_func(struct context *ctx, const struct token *token,
3570 const char *str, unsigned int len,
3571 void *buf, unsigned int size)
3573 struct action_rss_data *action_rss_data;
3574 enum rte_eth_hash_function func;
3578 /* Token name must match. */
3579 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
3581 switch (ctx->curr) {
3582 case ACTION_RSS_FUNC_DEFAULT:
3583 func = RTE_ETH_HASH_FUNCTION_DEFAULT;
3585 case ACTION_RSS_FUNC_TOEPLITZ:
3586 func = RTE_ETH_HASH_FUNCTION_TOEPLITZ;
3588 case ACTION_RSS_FUNC_SIMPLE_XOR:
3589 func = RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
3596 action_rss_data = ctx->object;
3597 action_rss_data->conf.func = func;
3602 * Parse type field for RSS action.
3604 * Valid tokens are type field names and the "end" token.
3607 parse_vc_action_rss_type(struct context *ctx, const struct token *token,
3608 const char *str, unsigned int len,
3609 void *buf, unsigned int size)
3611 static const enum index next[] = NEXT_ENTRY(ACTION_RSS_TYPE);
3612 struct action_rss_data *action_rss_data;
3618 if (ctx->curr != ACTION_RSS_TYPE)
3620 if (!(ctx->objdata >> 16) && ctx->object) {
3621 action_rss_data = ctx->object;
3622 action_rss_data->conf.types = 0;
3624 if (!strcmp_partial("end", str, len)) {
3625 ctx->objdata &= 0xffff;
3628 for (i = 0; rss_type_table[i].str; ++i)
3629 if (!strcmp_partial(rss_type_table[i].str, str, len))
3631 if (!rss_type_table[i].str)
3633 ctx->objdata = 1 << 16 | (ctx->objdata & 0xffff);
3635 if (ctx->next_num == RTE_DIM(ctx->next))
3637 ctx->next[ctx->next_num++] = next;
3640 action_rss_data = ctx->object;
3641 action_rss_data->conf.types |= rss_type_table[i].rss_type;
3646 * Parse queue field for RSS action.
3648 * Valid tokens are queue indices and the "end" token.
3651 parse_vc_action_rss_queue(struct context *ctx, const struct token *token,
3652 const char *str, unsigned int len,
3653 void *buf, unsigned int size)
3655 static const enum index next[] = NEXT_ENTRY(ACTION_RSS_QUEUE);
3656 struct action_rss_data *action_rss_data;
3657 const struct arg *arg;
3664 if (ctx->curr != ACTION_RSS_QUEUE)
3666 i = ctx->objdata >> 16;
3667 if (!strcmp_partial("end", str, len)) {
3668 ctx->objdata &= 0xffff;
3671 if (i >= ACTION_RSS_QUEUE_NUM)
3673 arg = ARGS_ENTRY_ARB(offsetof(struct action_rss_data, queue) +
3674 i * sizeof(action_rss_data->queue[i]),
3675 sizeof(action_rss_data->queue[i]));
3676 if (push_args(ctx, arg))
3678 ret = parse_int(ctx, token, str, len, NULL, 0);
3684 ctx->objdata = i << 16 | (ctx->objdata & 0xffff);
3686 if (ctx->next_num == RTE_DIM(ctx->next))
3688 ctx->next[ctx->next_num++] = next;
3692 action_rss_data = ctx->object;
3693 action_rss_data->conf.queue_num = i;
3694 action_rss_data->conf.queue = i ? action_rss_data->queue : NULL;
3698 /** Parse VXLAN encap action. */
3700 parse_vc_action_vxlan_encap(struct context *ctx, const struct token *token,
3701 const char *str, unsigned int len,
3702 void *buf, unsigned int size)
3704 struct buffer *out = buf;
3705 struct rte_flow_action *action;
3706 struct action_vxlan_encap_data *action_vxlan_encap_data;
3709 ret = parse_vc(ctx, token, str, len, buf, size);
3712 /* Nothing else to do if there is no buffer. */
3715 if (!out->args.vc.actions_n)
3717 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
3718 /* Point to selected object. */
3719 ctx->object = out->args.vc.data;
3720 ctx->objmask = NULL;
3721 /* Set up default configuration. */
3722 action_vxlan_encap_data = ctx->object;
3723 *action_vxlan_encap_data = (struct action_vxlan_encap_data){
3724 .conf = (struct rte_flow_action_vxlan_encap){
3725 .definition = action_vxlan_encap_data->items,
3729 .type = RTE_FLOW_ITEM_TYPE_ETH,
3730 .spec = &action_vxlan_encap_data->item_eth,
3731 .mask = &rte_flow_item_eth_mask,
3734 .type = RTE_FLOW_ITEM_TYPE_VLAN,
3735 .spec = &action_vxlan_encap_data->item_vlan,
3736 .mask = &rte_flow_item_vlan_mask,
3739 .type = RTE_FLOW_ITEM_TYPE_IPV4,
3740 .spec = &action_vxlan_encap_data->item_ipv4,
3741 .mask = &rte_flow_item_ipv4_mask,
3744 .type = RTE_FLOW_ITEM_TYPE_UDP,
3745 .spec = &action_vxlan_encap_data->item_udp,
3746 .mask = &rte_flow_item_udp_mask,
3749 .type = RTE_FLOW_ITEM_TYPE_VXLAN,
3750 .spec = &action_vxlan_encap_data->item_vxlan,
3751 .mask = &rte_flow_item_vxlan_mask,
3754 .type = RTE_FLOW_ITEM_TYPE_END,
3759 .tci = vxlan_encap_conf.vlan_tci,
3763 .src_addr = vxlan_encap_conf.ipv4_src,
3764 .dst_addr = vxlan_encap_conf.ipv4_dst,
3767 .src_port = vxlan_encap_conf.udp_src,
3768 .dst_port = vxlan_encap_conf.udp_dst,
3770 .item_vxlan.flags = 0,
3772 memcpy(action_vxlan_encap_data->item_eth.dst.addr_bytes,
3773 vxlan_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
3774 memcpy(action_vxlan_encap_data->item_eth.src.addr_bytes,
3775 vxlan_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
3776 if (!vxlan_encap_conf.select_ipv4) {
3777 memcpy(&action_vxlan_encap_data->item_ipv6.hdr.src_addr,
3778 &vxlan_encap_conf.ipv6_src,
3779 sizeof(vxlan_encap_conf.ipv6_src));
3780 memcpy(&action_vxlan_encap_data->item_ipv6.hdr.dst_addr,
3781 &vxlan_encap_conf.ipv6_dst,
3782 sizeof(vxlan_encap_conf.ipv6_dst));
3783 action_vxlan_encap_data->items[2] = (struct rte_flow_item){
3784 .type = RTE_FLOW_ITEM_TYPE_IPV6,
3785 .spec = &action_vxlan_encap_data->item_ipv6,
3786 .mask = &rte_flow_item_ipv6_mask,
3789 if (!vxlan_encap_conf.select_vlan)
3790 action_vxlan_encap_data->items[1].type =
3791 RTE_FLOW_ITEM_TYPE_VOID;
3792 if (vxlan_encap_conf.select_tos_ttl) {
3793 if (vxlan_encap_conf.select_ipv4) {
3794 static struct rte_flow_item_ipv4 ipv4_mask_tos;
3796 memcpy(&ipv4_mask_tos, &rte_flow_item_ipv4_mask,
3797 sizeof(ipv4_mask_tos));
3798 ipv4_mask_tos.hdr.type_of_service = 0xff;
3799 ipv4_mask_tos.hdr.time_to_live = 0xff;
3800 action_vxlan_encap_data->item_ipv4.hdr.type_of_service =
3801 vxlan_encap_conf.ip_tos;
3802 action_vxlan_encap_data->item_ipv4.hdr.time_to_live =
3803 vxlan_encap_conf.ip_ttl;
3804 action_vxlan_encap_data->items[2].mask =
3807 static struct rte_flow_item_ipv6 ipv6_mask_tos;
3809 memcpy(&ipv6_mask_tos, &rte_flow_item_ipv6_mask,
3810 sizeof(ipv6_mask_tos));
3811 ipv6_mask_tos.hdr.vtc_flow |=
3812 RTE_BE32(0xfful << RTE_IPV6_HDR_TC_SHIFT);
3813 ipv6_mask_tos.hdr.hop_limits = 0xff;
3814 action_vxlan_encap_data->item_ipv6.hdr.vtc_flow |=
3816 ((uint32_t)vxlan_encap_conf.ip_tos <<
3817 RTE_IPV6_HDR_TC_SHIFT);
3818 action_vxlan_encap_data->item_ipv6.hdr.hop_limits =
3819 vxlan_encap_conf.ip_ttl;
3820 action_vxlan_encap_data->items[2].mask =
3824 memcpy(action_vxlan_encap_data->item_vxlan.vni, vxlan_encap_conf.vni,
3825 RTE_DIM(vxlan_encap_conf.vni));
3826 action->conf = &action_vxlan_encap_data->conf;
3830 /** Parse NVGRE encap action. */
3832 parse_vc_action_nvgre_encap(struct context *ctx, const struct token *token,
3833 const char *str, unsigned int len,
3834 void *buf, unsigned int size)
3836 struct buffer *out = buf;
3837 struct rte_flow_action *action;
3838 struct action_nvgre_encap_data *action_nvgre_encap_data;
3841 ret = parse_vc(ctx, token, str, len, buf, size);
3844 /* Nothing else to do if there is no buffer. */
3847 if (!out->args.vc.actions_n)
3849 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
3850 /* Point to selected object. */
3851 ctx->object = out->args.vc.data;
3852 ctx->objmask = NULL;
3853 /* Set up default configuration. */
3854 action_nvgre_encap_data = ctx->object;
3855 *action_nvgre_encap_data = (struct action_nvgre_encap_data){
3856 .conf = (struct rte_flow_action_nvgre_encap){
3857 .definition = action_nvgre_encap_data->items,
3861 .type = RTE_FLOW_ITEM_TYPE_ETH,
3862 .spec = &action_nvgre_encap_data->item_eth,
3863 .mask = &rte_flow_item_eth_mask,
3866 .type = RTE_FLOW_ITEM_TYPE_VLAN,
3867 .spec = &action_nvgre_encap_data->item_vlan,
3868 .mask = &rte_flow_item_vlan_mask,
3871 .type = RTE_FLOW_ITEM_TYPE_IPV4,
3872 .spec = &action_nvgre_encap_data->item_ipv4,
3873 .mask = &rte_flow_item_ipv4_mask,
3876 .type = RTE_FLOW_ITEM_TYPE_NVGRE,
3877 .spec = &action_nvgre_encap_data->item_nvgre,
3878 .mask = &rte_flow_item_nvgre_mask,
3881 .type = RTE_FLOW_ITEM_TYPE_END,
3886 .tci = nvgre_encap_conf.vlan_tci,
3890 .src_addr = nvgre_encap_conf.ipv4_src,
3891 .dst_addr = nvgre_encap_conf.ipv4_dst,
3893 .item_nvgre.flow_id = 0,
3895 memcpy(action_nvgre_encap_data->item_eth.dst.addr_bytes,
3896 nvgre_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
3897 memcpy(action_nvgre_encap_data->item_eth.src.addr_bytes,
3898 nvgre_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
3899 if (!nvgre_encap_conf.select_ipv4) {
3900 memcpy(&action_nvgre_encap_data->item_ipv6.hdr.src_addr,
3901 &nvgre_encap_conf.ipv6_src,
3902 sizeof(nvgre_encap_conf.ipv6_src));
3903 memcpy(&action_nvgre_encap_data->item_ipv6.hdr.dst_addr,
3904 &nvgre_encap_conf.ipv6_dst,
3905 sizeof(nvgre_encap_conf.ipv6_dst));
3906 action_nvgre_encap_data->items[2] = (struct rte_flow_item){
3907 .type = RTE_FLOW_ITEM_TYPE_IPV6,
3908 .spec = &action_nvgre_encap_data->item_ipv6,
3909 .mask = &rte_flow_item_ipv6_mask,
3912 if (!nvgre_encap_conf.select_vlan)
3913 action_nvgre_encap_data->items[1].type =
3914 RTE_FLOW_ITEM_TYPE_VOID;
3915 memcpy(action_nvgre_encap_data->item_nvgre.tni, nvgre_encap_conf.tni,
3916 RTE_DIM(nvgre_encap_conf.tni));
3917 action->conf = &action_nvgre_encap_data->conf;
3921 /** Parse l2 encap action. */
3923 parse_vc_action_l2_encap(struct context *ctx, const struct token *token,
3924 const char *str, unsigned int len,
3925 void *buf, unsigned int size)
3927 struct buffer *out = buf;
3928 struct rte_flow_action *action;
3929 struct action_raw_encap_data *action_encap_data;
3930 struct rte_flow_item_eth eth = { .type = 0, };
3931 struct rte_flow_item_vlan vlan = {
3932 .tci = mplsoudp_encap_conf.vlan_tci,
3938 ret = parse_vc(ctx, token, str, len, buf, size);
3941 /* Nothing else to do if there is no buffer. */
3944 if (!out->args.vc.actions_n)
3946 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
3947 /* Point to selected object. */
3948 ctx->object = out->args.vc.data;
3949 ctx->objmask = NULL;
3950 /* Copy the headers to the buffer. */
3951 action_encap_data = ctx->object;
3952 *action_encap_data = (struct action_raw_encap_data) {
3953 .conf = (struct rte_flow_action_raw_encap){
3954 .data = action_encap_data->data,
3958 header = action_encap_data->data;
3959 if (l2_encap_conf.select_vlan)
3960 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
3961 else if (l2_encap_conf.select_ipv4)
3962 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
3964 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
3965 memcpy(eth.dst.addr_bytes,
3966 l2_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
3967 memcpy(eth.src.addr_bytes,
3968 l2_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
3969 memcpy(header, ð, sizeof(eth));
3970 header += sizeof(eth);
3971 if (l2_encap_conf.select_vlan) {
3972 if (l2_encap_conf.select_ipv4)
3973 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
3975 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
3976 memcpy(header, &vlan, sizeof(vlan));
3977 header += sizeof(vlan);
3979 action_encap_data->conf.size = header -
3980 action_encap_data->data;
3981 action->conf = &action_encap_data->conf;
3985 /** Parse l2 decap action. */
3987 parse_vc_action_l2_decap(struct context *ctx, const struct token *token,
3988 const char *str, unsigned int len,
3989 void *buf, unsigned int size)
3991 struct buffer *out = buf;
3992 struct rte_flow_action *action;
3993 struct action_raw_decap_data *action_decap_data;
3994 struct rte_flow_item_eth eth = { .type = 0, };
3995 struct rte_flow_item_vlan vlan = {
3996 .tci = mplsoudp_encap_conf.vlan_tci,
4002 ret = parse_vc(ctx, token, str, len, buf, size);
4005 /* Nothing else to do if there is no buffer. */
4008 if (!out->args.vc.actions_n)
4010 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4011 /* Point to selected object. */
4012 ctx->object = out->args.vc.data;
4013 ctx->objmask = NULL;
4014 /* Copy the headers to the buffer. */
4015 action_decap_data = ctx->object;
4016 *action_decap_data = (struct action_raw_decap_data) {
4017 .conf = (struct rte_flow_action_raw_decap){
4018 .data = action_decap_data->data,
4022 header = action_decap_data->data;
4023 if (l2_decap_conf.select_vlan)
4024 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
4025 memcpy(header, ð, sizeof(eth));
4026 header += sizeof(eth);
4027 if (l2_decap_conf.select_vlan) {
4028 memcpy(header, &vlan, sizeof(vlan));
4029 header += sizeof(vlan);
4031 action_decap_data->conf.size = header -
4032 action_decap_data->data;
4033 action->conf = &action_decap_data->conf;
4037 #define ETHER_TYPE_MPLS_UNICAST 0x8847
4039 /** Parse MPLSOGRE encap action. */
4041 parse_vc_action_mplsogre_encap(struct context *ctx, const struct token *token,
4042 const char *str, unsigned int len,
4043 void *buf, unsigned int size)
4045 struct buffer *out = buf;
4046 struct rte_flow_action *action;
4047 struct action_raw_encap_data *action_encap_data;
4048 struct rte_flow_item_eth eth = { .type = 0, };
4049 struct rte_flow_item_vlan vlan = {
4050 .tci = mplsogre_encap_conf.vlan_tci,
4053 struct rte_flow_item_ipv4 ipv4 = {
4055 .src_addr = mplsogre_encap_conf.ipv4_src,
4056 .dst_addr = mplsogre_encap_conf.ipv4_dst,
4057 .next_proto_id = IPPROTO_GRE,
4058 .version_ihl = RTE_IPV4_VHL_DEF,
4059 .time_to_live = IPDEFTTL,
4062 struct rte_flow_item_ipv6 ipv6 = {
4064 .proto = IPPROTO_GRE,
4065 .hop_limits = IPDEFTTL,
4068 struct rte_flow_item_gre gre = {
4069 .protocol = rte_cpu_to_be_16(ETHER_TYPE_MPLS_UNICAST),
4071 struct rte_flow_item_mpls mpls;
4075 ret = parse_vc(ctx, token, str, len, buf, size);
4078 /* Nothing else to do if there is no buffer. */
4081 if (!out->args.vc.actions_n)
4083 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4084 /* Point to selected object. */
4085 ctx->object = out->args.vc.data;
4086 ctx->objmask = NULL;
4087 /* Copy the headers to the buffer. */
4088 action_encap_data = ctx->object;
4089 *action_encap_data = (struct action_raw_encap_data) {
4090 .conf = (struct rte_flow_action_raw_encap){
4091 .data = action_encap_data->data,
4096 header = action_encap_data->data;
4097 if (mplsogre_encap_conf.select_vlan)
4098 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
4099 else if (mplsogre_encap_conf.select_ipv4)
4100 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4102 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4103 memcpy(eth.dst.addr_bytes,
4104 mplsogre_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
4105 memcpy(eth.src.addr_bytes,
4106 mplsogre_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
4107 memcpy(header, ð, sizeof(eth));
4108 header += sizeof(eth);
4109 if (mplsogre_encap_conf.select_vlan) {
4110 if (mplsogre_encap_conf.select_ipv4)
4111 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4113 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4114 memcpy(header, &vlan, sizeof(vlan));
4115 header += sizeof(vlan);
4117 if (mplsogre_encap_conf.select_ipv4) {
4118 memcpy(header, &ipv4, sizeof(ipv4));
4119 header += sizeof(ipv4);
4121 memcpy(&ipv6.hdr.src_addr,
4122 &mplsogre_encap_conf.ipv6_src,
4123 sizeof(mplsogre_encap_conf.ipv6_src));
4124 memcpy(&ipv6.hdr.dst_addr,
4125 &mplsogre_encap_conf.ipv6_dst,
4126 sizeof(mplsogre_encap_conf.ipv6_dst));
4127 memcpy(header, &ipv6, sizeof(ipv6));
4128 header += sizeof(ipv6);
4130 memcpy(header, &gre, sizeof(gre));
4131 header += sizeof(gre);
4132 memcpy(mpls.label_tc_s, mplsogre_encap_conf.label,
4133 RTE_DIM(mplsogre_encap_conf.label));
4134 mpls.label_tc_s[2] |= 0x1;
4135 memcpy(header, &mpls, sizeof(mpls));
4136 header += sizeof(mpls);
4137 action_encap_data->conf.size = header -
4138 action_encap_data->data;
4139 action->conf = &action_encap_data->conf;
4143 /** Parse MPLSOGRE decap action. */
4145 parse_vc_action_mplsogre_decap(struct context *ctx, const struct token *token,
4146 const char *str, unsigned int len,
4147 void *buf, unsigned int size)
4149 struct buffer *out = buf;
4150 struct rte_flow_action *action;
4151 struct action_raw_decap_data *action_decap_data;
4152 struct rte_flow_item_eth eth = { .type = 0, };
4153 struct rte_flow_item_vlan vlan = {.tci = 0};
4154 struct rte_flow_item_ipv4 ipv4 = {
4156 .next_proto_id = IPPROTO_GRE,
4159 struct rte_flow_item_ipv6 ipv6 = {
4161 .proto = IPPROTO_GRE,
4164 struct rte_flow_item_gre gre = {
4165 .protocol = rte_cpu_to_be_16(ETHER_TYPE_MPLS_UNICAST),
4167 struct rte_flow_item_mpls mpls;
4171 ret = parse_vc(ctx, token, str, len, buf, size);
4174 /* Nothing else to do if there is no buffer. */
4177 if (!out->args.vc.actions_n)
4179 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4180 /* Point to selected object. */
4181 ctx->object = out->args.vc.data;
4182 ctx->objmask = NULL;
4183 /* Copy the headers to the buffer. */
4184 action_decap_data = ctx->object;
4185 *action_decap_data = (struct action_raw_decap_data) {
4186 .conf = (struct rte_flow_action_raw_decap){
4187 .data = action_decap_data->data,
4191 header = action_decap_data->data;
4192 if (mplsogre_decap_conf.select_vlan)
4193 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
4194 else if (mplsogre_encap_conf.select_ipv4)
4195 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4197 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4198 memcpy(eth.dst.addr_bytes,
4199 mplsogre_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
4200 memcpy(eth.src.addr_bytes,
4201 mplsogre_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
4202 memcpy(header, ð, sizeof(eth));
4203 header += sizeof(eth);
4204 if (mplsogre_encap_conf.select_vlan) {
4205 if (mplsogre_encap_conf.select_ipv4)
4206 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4208 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4209 memcpy(header, &vlan, sizeof(vlan));
4210 header += sizeof(vlan);
4212 if (mplsogre_encap_conf.select_ipv4) {
4213 memcpy(header, &ipv4, sizeof(ipv4));
4214 header += sizeof(ipv4);
4216 memcpy(header, &ipv6, sizeof(ipv6));
4217 header += sizeof(ipv6);
4219 memcpy(header, &gre, sizeof(gre));
4220 header += sizeof(gre);
4221 memset(&mpls, 0, sizeof(mpls));
4222 memcpy(header, &mpls, sizeof(mpls));
4223 header += sizeof(mpls);
4224 action_decap_data->conf.size = header -
4225 action_decap_data->data;
4226 action->conf = &action_decap_data->conf;
4230 /** Parse MPLSOUDP encap action. */
4232 parse_vc_action_mplsoudp_encap(struct context *ctx, const struct token *token,
4233 const char *str, unsigned int len,
4234 void *buf, unsigned int size)
4236 struct buffer *out = buf;
4237 struct rte_flow_action *action;
4238 struct action_raw_encap_data *action_encap_data;
4239 struct rte_flow_item_eth eth = { .type = 0, };
4240 struct rte_flow_item_vlan vlan = {
4241 .tci = mplsoudp_encap_conf.vlan_tci,
4244 struct rte_flow_item_ipv4 ipv4 = {
4246 .src_addr = mplsoudp_encap_conf.ipv4_src,
4247 .dst_addr = mplsoudp_encap_conf.ipv4_dst,
4248 .next_proto_id = IPPROTO_UDP,
4249 .version_ihl = RTE_IPV4_VHL_DEF,
4250 .time_to_live = IPDEFTTL,
4253 struct rte_flow_item_ipv6 ipv6 = {
4255 .proto = IPPROTO_UDP,
4256 .hop_limits = IPDEFTTL,
4259 struct rte_flow_item_udp udp = {
4261 .src_port = mplsoudp_encap_conf.udp_src,
4262 .dst_port = mplsoudp_encap_conf.udp_dst,
4265 struct rte_flow_item_mpls mpls;
4269 ret = parse_vc(ctx, token, str, len, buf, size);
4272 /* Nothing else to do if there is no buffer. */
4275 if (!out->args.vc.actions_n)
4277 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4278 /* Point to selected object. */
4279 ctx->object = out->args.vc.data;
4280 ctx->objmask = NULL;
4281 /* Copy the headers to the buffer. */
4282 action_encap_data = ctx->object;
4283 *action_encap_data = (struct action_raw_encap_data) {
4284 .conf = (struct rte_flow_action_raw_encap){
4285 .data = action_encap_data->data,
4290 header = action_encap_data->data;
4291 if (mplsoudp_encap_conf.select_vlan)
4292 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
4293 else if (mplsoudp_encap_conf.select_ipv4)
4294 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4296 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4297 memcpy(eth.dst.addr_bytes,
4298 mplsoudp_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
4299 memcpy(eth.src.addr_bytes,
4300 mplsoudp_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
4301 memcpy(header, ð, sizeof(eth));
4302 header += sizeof(eth);
4303 if (mplsoudp_encap_conf.select_vlan) {
4304 if (mplsoudp_encap_conf.select_ipv4)
4305 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4307 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4308 memcpy(header, &vlan, sizeof(vlan));
4309 header += sizeof(vlan);
4311 if (mplsoudp_encap_conf.select_ipv4) {
4312 memcpy(header, &ipv4, sizeof(ipv4));
4313 header += sizeof(ipv4);
4315 memcpy(&ipv6.hdr.src_addr,
4316 &mplsoudp_encap_conf.ipv6_src,
4317 sizeof(mplsoudp_encap_conf.ipv6_src));
4318 memcpy(&ipv6.hdr.dst_addr,
4319 &mplsoudp_encap_conf.ipv6_dst,
4320 sizeof(mplsoudp_encap_conf.ipv6_dst));
4321 memcpy(header, &ipv6, sizeof(ipv6));
4322 header += sizeof(ipv6);
4324 memcpy(header, &udp, sizeof(udp));
4325 header += sizeof(udp);
4326 memcpy(mpls.label_tc_s, mplsoudp_encap_conf.label,
4327 RTE_DIM(mplsoudp_encap_conf.label));
4328 mpls.label_tc_s[2] |= 0x1;
4329 memcpy(header, &mpls, sizeof(mpls));
4330 header += sizeof(mpls);
4331 action_encap_data->conf.size = header -
4332 action_encap_data->data;
4333 action->conf = &action_encap_data->conf;
4337 /** Parse MPLSOUDP decap action. */
4339 parse_vc_action_mplsoudp_decap(struct context *ctx, const struct token *token,
4340 const char *str, unsigned int len,
4341 void *buf, unsigned int size)
4343 struct buffer *out = buf;
4344 struct rte_flow_action *action;
4345 struct action_raw_decap_data *action_decap_data;
4346 struct rte_flow_item_eth eth = { .type = 0, };
4347 struct rte_flow_item_vlan vlan = {.tci = 0};
4348 struct rte_flow_item_ipv4 ipv4 = {
4350 .next_proto_id = IPPROTO_UDP,
4353 struct rte_flow_item_ipv6 ipv6 = {
4355 .proto = IPPROTO_UDP,
4358 struct rte_flow_item_udp udp = {
4360 .dst_port = rte_cpu_to_be_16(6635),
4363 struct rte_flow_item_mpls mpls;
4367 ret = parse_vc(ctx, token, str, len, buf, size);
4370 /* Nothing else to do if there is no buffer. */
4373 if (!out->args.vc.actions_n)
4375 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4376 /* Point to selected object. */
4377 ctx->object = out->args.vc.data;
4378 ctx->objmask = NULL;
4379 /* Copy the headers to the buffer. */
4380 action_decap_data = ctx->object;
4381 *action_decap_data = (struct action_raw_decap_data) {
4382 .conf = (struct rte_flow_action_raw_decap){
4383 .data = action_decap_data->data,
4387 header = action_decap_data->data;
4388 if (mplsoudp_decap_conf.select_vlan)
4389 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
4390 else if (mplsoudp_encap_conf.select_ipv4)
4391 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4393 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4394 memcpy(eth.dst.addr_bytes,
4395 mplsoudp_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
4396 memcpy(eth.src.addr_bytes,
4397 mplsoudp_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
4398 memcpy(header, ð, sizeof(eth));
4399 header += sizeof(eth);
4400 if (mplsoudp_encap_conf.select_vlan) {
4401 if (mplsoudp_encap_conf.select_ipv4)
4402 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4404 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4405 memcpy(header, &vlan, sizeof(vlan));
4406 header += sizeof(vlan);
4408 if (mplsoudp_encap_conf.select_ipv4) {
4409 memcpy(header, &ipv4, sizeof(ipv4));
4410 header += sizeof(ipv4);
4412 memcpy(header, &ipv6, sizeof(ipv6));
4413 header += sizeof(ipv6);
4415 memcpy(header, &udp, sizeof(udp));
4416 header += sizeof(udp);
4417 memset(&mpls, 0, sizeof(mpls));
4418 memcpy(header, &mpls, sizeof(mpls));
4419 header += sizeof(mpls);
4420 action_decap_data->conf.size = header -
4421 action_decap_data->data;
4422 action->conf = &action_decap_data->conf;
4427 parse_vc_action_raw_encap(struct context *ctx, const struct token *token,
4428 const char *str, unsigned int len, void *buf,
4431 struct buffer *out = buf;
4432 struct rte_flow_action *action;
4433 struct rte_flow_action_raw_encap *action_raw_encap_conf = NULL;
4434 uint8_t *data = NULL;
4437 ret = parse_vc(ctx, token, str, len, buf, size);
4440 /* Nothing else to do if there is no buffer. */
4443 if (!out->args.vc.actions_n)
4445 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4446 /* Point to selected object. */
4447 ctx->object = out->args.vc.data;
4448 ctx->objmask = NULL;
4449 /* Copy the headers to the buffer. */
4450 action_raw_encap_conf = ctx->object;
4451 /* data stored from tail of data buffer */
4452 data = (uint8_t *)&(raw_encap_conf.data) +
4453 ACTION_RAW_ENCAP_MAX_DATA - raw_encap_conf.size;
4454 action_raw_encap_conf->data = data;
4455 action_raw_encap_conf->preserve = NULL;
4456 action_raw_encap_conf->size = raw_encap_conf.size;
4457 action->conf = action_raw_encap_conf;
4462 parse_vc_action_raw_decap(struct context *ctx, const struct token *token,
4463 const char *str, unsigned int len, void *buf,
4466 struct buffer *out = buf;
4467 struct rte_flow_action *action;
4468 struct rte_flow_action_raw_decap *action_raw_decap_conf = NULL;
4469 uint8_t *data = NULL;
4472 ret = parse_vc(ctx, token, str, len, buf, size);
4475 /* Nothing else to do if there is no buffer. */
4478 if (!out->args.vc.actions_n)
4480 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4481 /* Point to selected object. */
4482 ctx->object = out->args.vc.data;
4483 ctx->objmask = NULL;
4484 /* Copy the headers to the buffer. */
4485 action_raw_decap_conf = ctx->object;
4486 /* data stored from tail of data buffer */
4487 data = (uint8_t *)&(raw_decap_conf.data) +
4488 ACTION_RAW_ENCAP_MAX_DATA - raw_decap_conf.size;
4489 action_raw_decap_conf->data = data;
4490 action_raw_decap_conf->size = raw_decap_conf.size;
4491 action->conf = action_raw_decap_conf;
4495 /** Parse tokens for destroy command. */
4497 parse_destroy(struct context *ctx, const struct token *token,
4498 const char *str, unsigned int len,
4499 void *buf, unsigned int size)
4501 struct buffer *out = buf;
4503 /* Token name must match. */
4504 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
4506 /* Nothing else to do if there is no buffer. */
4509 if (!out->command) {
4510 if (ctx->curr != DESTROY)
4512 if (sizeof(*out) > size)
4514 out->command = ctx->curr;
4517 ctx->objmask = NULL;
4518 out->args.destroy.rule =
4519 (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
4523 if (((uint8_t *)(out->args.destroy.rule + out->args.destroy.rule_n) +
4524 sizeof(*out->args.destroy.rule)) > (uint8_t *)out + size)
4527 ctx->object = out->args.destroy.rule + out->args.destroy.rule_n++;
4528 ctx->objmask = NULL;
4532 /** Parse tokens for flush command. */
4534 parse_flush(struct context *ctx, const struct token *token,
4535 const char *str, unsigned int len,
4536 void *buf, unsigned int size)
4538 struct buffer *out = buf;
4540 /* Token name must match. */
4541 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
4543 /* Nothing else to do if there is no buffer. */
4546 if (!out->command) {
4547 if (ctx->curr != FLUSH)
4549 if (sizeof(*out) > size)
4551 out->command = ctx->curr;
4554 ctx->objmask = NULL;
4559 /** Parse tokens for query command. */
4561 parse_query(struct context *ctx, const struct token *token,
4562 const char *str, unsigned int len,
4563 void *buf, unsigned int size)
4565 struct buffer *out = buf;
4567 /* Token name must match. */
4568 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
4570 /* Nothing else to do if there is no buffer. */
4573 if (!out->command) {
4574 if (ctx->curr != QUERY)
4576 if (sizeof(*out) > size)
4578 out->command = ctx->curr;
4581 ctx->objmask = NULL;
4586 /** Parse action names. */
4588 parse_action(struct context *ctx, const struct token *token,
4589 const char *str, unsigned int len,
4590 void *buf, unsigned int size)
4592 struct buffer *out = buf;
4593 const struct arg *arg = pop_args(ctx);
4597 /* Argument is expected. */
4600 /* Parse action name. */
4601 for (i = 0; next_action[i]; ++i) {
4602 const struct parse_action_priv *priv;
4604 token = &token_list[next_action[i]];
4605 if (strcmp_partial(token->name, str, len))
4611 memcpy((uint8_t *)ctx->object + arg->offset,
4617 push_args(ctx, arg);
4621 /** Parse tokens for list command. */
4623 parse_list(struct context *ctx, const struct token *token,
4624 const char *str, unsigned int len,
4625 void *buf, unsigned int size)
4627 struct buffer *out = buf;
4629 /* Token name must match. */
4630 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
4632 /* Nothing else to do if there is no buffer. */
4635 if (!out->command) {
4636 if (ctx->curr != LIST)
4638 if (sizeof(*out) > size)
4640 out->command = ctx->curr;
4643 ctx->objmask = NULL;
4644 out->args.list.group =
4645 (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
4649 if (((uint8_t *)(out->args.list.group + out->args.list.group_n) +
4650 sizeof(*out->args.list.group)) > (uint8_t *)out + size)
4653 ctx->object = out->args.list.group + out->args.list.group_n++;
4654 ctx->objmask = NULL;
4658 /** Parse tokens for isolate command. */
4660 parse_isolate(struct context *ctx, const struct token *token,
4661 const char *str, unsigned int len,
4662 void *buf, unsigned int size)
4664 struct buffer *out = buf;
4666 /* Token name must match. */
4667 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
4669 /* Nothing else to do if there is no buffer. */
4672 if (!out->command) {
4673 if (ctx->curr != ISOLATE)
4675 if (sizeof(*out) > size)
4677 out->command = ctx->curr;
4680 ctx->objmask = NULL;
4686 * Parse signed/unsigned integers 8 to 64-bit long.
4688 * Last argument (ctx->args) is retrieved to determine integer type and
4692 parse_int(struct context *ctx, const struct token *token,
4693 const char *str, unsigned int len,
4694 void *buf, unsigned int size)
4696 const struct arg *arg = pop_args(ctx);
4701 /* Argument is expected. */
4706 (uintmax_t)strtoimax(str, &end, 0) :
4707 strtoumax(str, &end, 0);
4708 if (errno || (size_t)(end - str) != len)
4711 ((arg->sign && ((intmax_t)u < (intmax_t)arg->min ||
4712 (intmax_t)u > (intmax_t)arg->max)) ||
4713 (!arg->sign && (u < arg->min || u > arg->max))))
4718 if (!arg_entry_bf_fill(ctx->object, u, arg) ||
4719 !arg_entry_bf_fill(ctx->objmask, -1, arg))
4723 buf = (uint8_t *)ctx->object + arg->offset;
4725 if (u > RTE_LEN2MASK(size * CHAR_BIT, uint64_t))
4729 case sizeof(uint8_t):
4730 *(uint8_t *)buf = u;
4732 case sizeof(uint16_t):
4733 *(uint16_t *)buf = arg->hton ? rte_cpu_to_be_16(u) : u;
4735 case sizeof(uint8_t [3]):
4736 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
4738 ((uint8_t *)buf)[0] = u;
4739 ((uint8_t *)buf)[1] = u >> 8;
4740 ((uint8_t *)buf)[2] = u >> 16;
4744 ((uint8_t *)buf)[0] = u >> 16;
4745 ((uint8_t *)buf)[1] = u >> 8;
4746 ((uint8_t *)buf)[2] = u;
4748 case sizeof(uint32_t):
4749 *(uint32_t *)buf = arg->hton ? rte_cpu_to_be_32(u) : u;
4751 case sizeof(uint64_t):
4752 *(uint64_t *)buf = arg->hton ? rte_cpu_to_be_64(u) : u;
4757 if (ctx->objmask && buf != (uint8_t *)ctx->objmask + arg->offset) {
4759 buf = (uint8_t *)ctx->objmask + arg->offset;
4764 push_args(ctx, arg);
4771 * Three arguments (ctx->args) are retrieved from the stack to store data,
4772 * its actual length and address (in that order).
4775 parse_string(struct context *ctx, const struct token *token,
4776 const char *str, unsigned int len,
4777 void *buf, unsigned int size)
4779 const struct arg *arg_data = pop_args(ctx);
4780 const struct arg *arg_len = pop_args(ctx);
4781 const struct arg *arg_addr = pop_args(ctx);
4782 char tmp[16]; /* Ought to be enough. */
4785 /* Arguments are expected. */
4789 push_args(ctx, arg_data);
4793 push_args(ctx, arg_len);
4794 push_args(ctx, arg_data);
4797 size = arg_data->size;
4798 /* Bit-mask fill is not supported. */
4799 if (arg_data->mask || size < len)
4803 /* Let parse_int() fill length information first. */
4804 ret = snprintf(tmp, sizeof(tmp), "%u", len);
4807 push_args(ctx, arg_len);
4808 ret = parse_int(ctx, token, tmp, ret, NULL, 0);
4813 buf = (uint8_t *)ctx->object + arg_data->offset;
4814 /* Output buffer is not necessarily NUL-terminated. */
4815 memcpy(buf, str, len);
4816 memset((uint8_t *)buf + len, 0x00, size - len);
4818 memset((uint8_t *)ctx->objmask + arg_data->offset, 0xff, len);
4819 /* Save address if requested. */
4820 if (arg_addr->size) {
4821 memcpy((uint8_t *)ctx->object + arg_addr->offset,
4823 (uint8_t *)ctx->object + arg_data->offset
4827 memcpy((uint8_t *)ctx->objmask + arg_addr->offset,
4829 (uint8_t *)ctx->objmask + arg_data->offset
4835 push_args(ctx, arg_addr);
4836 push_args(ctx, arg_len);
4837 push_args(ctx, arg_data);
4842 parse_hex_string(const char *src, uint8_t *dst, uint32_t *size)
4848 /* Check input parameters */
4849 if ((src == NULL) ||
4855 /* Convert chars to bytes */
4856 for (i = 0, len = 0; i < *size; i += 2) {
4857 snprintf(tmp, 3, "%s", src + i);
4858 dst[len++] = strtoul(tmp, &c, 16);
4873 parse_hex(struct context *ctx, const struct token *token,
4874 const char *str, unsigned int len,
4875 void *buf, unsigned int size)
4877 const struct arg *arg_data = pop_args(ctx);
4878 const struct arg *arg_len = pop_args(ctx);
4879 const struct arg *arg_addr = pop_args(ctx);
4880 char tmp[16]; /* Ought to be enough. */
4882 unsigned int hexlen = len;
4883 unsigned int length = 256;
4884 uint8_t hex_tmp[length];
4886 /* Arguments are expected. */
4890 push_args(ctx, arg_data);
4894 push_args(ctx, arg_len);
4895 push_args(ctx, arg_data);
4898 size = arg_data->size;
4899 /* Bit-mask fill is not supported. */
4905 /* translate bytes string to array. */
4906 if (str[0] == '0' && ((str[1] == 'x') ||
4911 if (hexlen > length)
4913 ret = parse_hex_string(str, hex_tmp, &hexlen);
4916 /* Let parse_int() fill length information first. */
4917 ret = snprintf(tmp, sizeof(tmp), "%u", hexlen);
4920 push_args(ctx, arg_len);
4921 ret = parse_int(ctx, token, tmp, ret, NULL, 0);
4926 buf = (uint8_t *)ctx->object + arg_data->offset;
4927 /* Output buffer is not necessarily NUL-terminated. */
4928 memcpy(buf, hex_tmp, hexlen);
4929 memset((uint8_t *)buf + hexlen, 0x00, size - hexlen);
4931 memset((uint8_t *)ctx->objmask + arg_data->offset,
4933 /* Save address if requested. */
4934 if (arg_addr->size) {
4935 memcpy((uint8_t *)ctx->object + arg_addr->offset,
4937 (uint8_t *)ctx->object + arg_data->offset
4941 memcpy((uint8_t *)ctx->objmask + arg_addr->offset,
4943 (uint8_t *)ctx->objmask + arg_data->offset
4949 push_args(ctx, arg_addr);
4950 push_args(ctx, arg_len);
4951 push_args(ctx, arg_data);
4957 * Parse a MAC address.
4959 * Last argument (ctx->args) is retrieved to determine storage size and
4963 parse_mac_addr(struct context *ctx, const struct token *token,
4964 const char *str, unsigned int len,
4965 void *buf, unsigned int size)
4967 const struct arg *arg = pop_args(ctx);
4968 struct rte_ether_addr tmp;
4972 /* Argument is expected. */
4976 /* Bit-mask fill is not supported. */
4977 if (arg->mask || size != sizeof(tmp))
4979 /* Only network endian is supported. */
4982 ret = cmdline_parse_etheraddr(NULL, str, &tmp, size);
4983 if (ret < 0 || (unsigned int)ret != len)
4987 buf = (uint8_t *)ctx->object + arg->offset;
4988 memcpy(buf, &tmp, size);
4990 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
4993 push_args(ctx, arg);
4998 * Parse an IPv4 address.
5000 * Last argument (ctx->args) is retrieved to determine storage size and
5004 parse_ipv4_addr(struct context *ctx, const struct token *token,
5005 const char *str, unsigned int len,
5006 void *buf, unsigned int size)
5008 const struct arg *arg = pop_args(ctx);
5013 /* Argument is expected. */
5017 /* Bit-mask fill is not supported. */
5018 if (arg->mask || size != sizeof(tmp))
5020 /* Only network endian is supported. */
5023 memcpy(str2, str, len);
5025 ret = inet_pton(AF_INET, str2, &tmp);
5027 /* Attempt integer parsing. */
5028 push_args(ctx, arg);
5029 return parse_int(ctx, token, str, len, buf, size);
5033 buf = (uint8_t *)ctx->object + arg->offset;
5034 memcpy(buf, &tmp, size);
5036 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
5039 push_args(ctx, arg);
5044 * Parse an IPv6 address.
5046 * Last argument (ctx->args) is retrieved to determine storage size and
5050 parse_ipv6_addr(struct context *ctx, const struct token *token,
5051 const char *str, unsigned int len,
5052 void *buf, unsigned int size)
5054 const struct arg *arg = pop_args(ctx);
5056 struct in6_addr tmp;
5060 /* Argument is expected. */
5064 /* Bit-mask fill is not supported. */
5065 if (arg->mask || size != sizeof(tmp))
5067 /* Only network endian is supported. */
5070 memcpy(str2, str, len);
5072 ret = inet_pton(AF_INET6, str2, &tmp);
5077 buf = (uint8_t *)ctx->object + arg->offset;
5078 memcpy(buf, &tmp, size);
5080 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
5083 push_args(ctx, arg);
5087 /** Boolean values (even indices stand for false). */
5088 static const char *const boolean_name[] = {
5098 * Parse a boolean value.
5100 * Last argument (ctx->args) is retrieved to determine storage size and
5104 parse_boolean(struct context *ctx, const struct token *token,
5105 const char *str, unsigned int len,
5106 void *buf, unsigned int size)
5108 const struct arg *arg = pop_args(ctx);
5112 /* Argument is expected. */
5115 for (i = 0; boolean_name[i]; ++i)
5116 if (!strcmp_partial(boolean_name[i], str, len))
5118 /* Process token as integer. */
5119 if (boolean_name[i])
5120 str = i & 1 ? "1" : "0";
5121 push_args(ctx, arg);
5122 ret = parse_int(ctx, token, str, strlen(str), buf, size);
5123 return ret > 0 ? (int)len : ret;
5126 /** Parse port and update context. */
5128 parse_port(struct context *ctx, const struct token *token,
5129 const char *str, unsigned int len,
5130 void *buf, unsigned int size)
5132 struct buffer *out = &(struct buffer){ .port = 0 };
5140 ctx->objmask = NULL;
5141 size = sizeof(*out);
5143 ret = parse_int(ctx, token, str, len, out, size);
5145 ctx->port = out->port;
5151 /** Parse set command, initialize output buffer for subsequent tokens. */
5153 parse_set_raw_encap_decap(struct context *ctx, const struct token *token,
5154 const char *str, unsigned int len,
5155 void *buf, unsigned int size)
5157 struct buffer *out = buf;
5159 /* Token name must match. */
5160 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5162 /* Nothing else to do if there is no buffer. */
5165 /* Make sure buffer is large enough. */
5166 if (size < sizeof(*out))
5169 ctx->objmask = NULL;
5172 out->command = ctx->curr;
5177 * Parse set raw_encap/raw_decap command,
5178 * initialize output buffer for subsequent tokens.
5181 parse_set_init(struct context *ctx, const struct token *token,
5182 const char *str, unsigned int len,
5183 void *buf, unsigned int size)
5185 struct buffer *out = buf;
5187 /* Token name must match. */
5188 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5190 /* Nothing else to do if there is no buffer. */
5193 /* Make sure buffer is large enough. */
5194 if (size < sizeof(*out))
5196 /* Initialize buffer. */
5197 memset(out, 0x00, sizeof(*out));
5198 memset((uint8_t *)out + sizeof(*out), 0x22, size - sizeof(*out));
5201 ctx->objmask = NULL;
5202 if (!out->command) {
5203 if (ctx->curr != SET)
5205 if (sizeof(*out) > size)
5207 out->command = ctx->curr;
5208 out->args.vc.data = (uint8_t *)out + size;
5209 /* All we need is pattern */
5210 out->args.vc.pattern =
5211 (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
5213 ctx->object = out->args.vc.pattern;
5218 /** No completion. */
5220 comp_none(struct context *ctx, const struct token *token,
5221 unsigned int ent, char *buf, unsigned int size)
5231 /** Complete boolean values. */
5233 comp_boolean(struct context *ctx, const struct token *token,
5234 unsigned int ent, char *buf, unsigned int size)
5240 for (i = 0; boolean_name[i]; ++i)
5241 if (buf && i == ent)
5242 return strlcpy(buf, boolean_name[i], size);
5248 /** Complete action names. */
5250 comp_action(struct context *ctx, const struct token *token,
5251 unsigned int ent, char *buf, unsigned int size)
5257 for (i = 0; next_action[i]; ++i)
5258 if (buf && i == ent)
5259 return strlcpy(buf, token_list[next_action[i]].name,
5266 /** Complete available ports. */
5268 comp_port(struct context *ctx, const struct token *token,
5269 unsigned int ent, char *buf, unsigned int size)
5276 RTE_ETH_FOREACH_DEV(p) {
5277 if (buf && i == ent)
5278 return snprintf(buf, size, "%u", p);
5286 /** Complete available rule IDs. */
5288 comp_rule_id(struct context *ctx, const struct token *token,
5289 unsigned int ent, char *buf, unsigned int size)
5292 struct rte_port *port;
5293 struct port_flow *pf;
5296 if (port_id_is_invalid(ctx->port, DISABLED_WARN) ||
5297 ctx->port == (portid_t)RTE_PORT_ALL)
5299 port = &ports[ctx->port];
5300 for (pf = port->flow_list; pf != NULL; pf = pf->next) {
5301 if (buf && i == ent)
5302 return snprintf(buf, size, "%u", pf->id);
5310 /** Complete type field for RSS action. */
5312 comp_vc_action_rss_type(struct context *ctx, const struct token *token,
5313 unsigned int ent, char *buf, unsigned int size)
5319 for (i = 0; rss_type_table[i].str; ++i)
5324 return strlcpy(buf, rss_type_table[ent].str, size);
5326 return snprintf(buf, size, "end");
5330 /** Complete queue field for RSS action. */
5332 comp_vc_action_rss_queue(struct context *ctx, const struct token *token,
5333 unsigned int ent, char *buf, unsigned int size)
5340 return snprintf(buf, size, "%u", ent);
5342 return snprintf(buf, size, "end");
5346 /** Internal context. */
5347 static struct context cmd_flow_context;
5349 /** Global parser instance (cmdline API). */
5350 cmdline_parse_inst_t cmd_flow;
5351 cmdline_parse_inst_t cmd_set_raw;
5353 /** Initialize context. */
5355 cmd_flow_context_init(struct context *ctx)
5357 /* A full memset() is not necessary. */
5367 ctx->objmask = NULL;
5370 /** Parse a token (cmdline API). */
5372 cmd_flow_parse(cmdline_parse_token_hdr_t *hdr, const char *src, void *result,
5375 struct context *ctx = &cmd_flow_context;
5376 const struct token *token;
5377 const enum index *list;
5382 token = &token_list[ctx->curr];
5383 /* Check argument length. */
5386 for (len = 0; src[len]; ++len)
5387 if (src[len] == '#' || isspace(src[len]))
5391 /* Last argument and EOL detection. */
5392 for (i = len; src[i]; ++i)
5393 if (src[i] == '#' || src[i] == '\r' || src[i] == '\n')
5395 else if (!isspace(src[i])) {
5400 if (src[i] == '\r' || src[i] == '\n') {
5404 /* Initialize context if necessary. */
5405 if (!ctx->next_num) {
5408 ctx->next[ctx->next_num++] = token->next[0];
5410 /* Process argument through candidates. */
5411 ctx->prev = ctx->curr;
5412 list = ctx->next[ctx->next_num - 1];
5413 for (i = 0; list[i]; ++i) {
5414 const struct token *next = &token_list[list[i]];
5417 ctx->curr = list[i];
5419 tmp = next->call(ctx, next, src, len, result, size);
5421 tmp = parse_default(ctx, next, src, len, result, size);
5422 if (tmp == -1 || tmp != len)
5430 /* Push subsequent tokens if any. */
5432 for (i = 0; token->next[i]; ++i) {
5433 if (ctx->next_num == RTE_DIM(ctx->next))
5435 ctx->next[ctx->next_num++] = token->next[i];
5437 /* Push arguments if any. */
5439 for (i = 0; token->args[i]; ++i) {
5440 if (ctx->args_num == RTE_DIM(ctx->args))
5442 ctx->args[ctx->args_num++] = token->args[i];
5447 /** Return number of completion entries (cmdline API). */
5449 cmd_flow_complete_get_nb(cmdline_parse_token_hdr_t *hdr)
5451 struct context *ctx = &cmd_flow_context;
5452 const struct token *token = &token_list[ctx->curr];
5453 const enum index *list;
5457 /* Count number of tokens in current list. */
5459 list = ctx->next[ctx->next_num - 1];
5461 list = token->next[0];
5462 for (i = 0; list[i]; ++i)
5467 * If there is a single token, use its completion callback, otherwise
5468 * return the number of entries.
5470 token = &token_list[list[0]];
5471 if (i == 1 && token->comp) {
5472 /* Save index for cmd_flow_get_help(). */
5473 ctx->prev = list[0];
5474 return token->comp(ctx, token, 0, NULL, 0);
5479 /** Return a completion entry (cmdline API). */
5481 cmd_flow_complete_get_elt(cmdline_parse_token_hdr_t *hdr, int index,
5482 char *dst, unsigned int size)
5484 struct context *ctx = &cmd_flow_context;
5485 const struct token *token = &token_list[ctx->curr];
5486 const enum index *list;
5490 /* Count number of tokens in current list. */
5492 list = ctx->next[ctx->next_num - 1];
5494 list = token->next[0];
5495 for (i = 0; list[i]; ++i)
5499 /* If there is a single token, use its completion callback. */
5500 token = &token_list[list[0]];
5501 if (i == 1 && token->comp) {
5502 /* Save index for cmd_flow_get_help(). */
5503 ctx->prev = list[0];
5504 return token->comp(ctx, token, index, dst, size) < 0 ? -1 : 0;
5506 /* Otherwise make sure the index is valid and use defaults. */
5509 token = &token_list[list[index]];
5510 strlcpy(dst, token->name, size);
5511 /* Save index for cmd_flow_get_help(). */
5512 ctx->prev = list[index];
5516 /** Populate help strings for current token (cmdline API). */
5518 cmd_flow_get_help(cmdline_parse_token_hdr_t *hdr, char *dst, unsigned int size)
5520 struct context *ctx = &cmd_flow_context;
5521 const struct token *token = &token_list[ctx->prev];
5526 /* Set token type and update global help with details. */
5527 strlcpy(dst, (token->type ? token->type : "TOKEN"), size);
5529 cmd_flow.help_str = token->help;
5531 cmd_flow.help_str = token->name;
5535 /** Token definition template (cmdline API). */
5536 static struct cmdline_token_hdr cmd_flow_token_hdr = {
5537 .ops = &(struct cmdline_token_ops){
5538 .parse = cmd_flow_parse,
5539 .complete_get_nb = cmd_flow_complete_get_nb,
5540 .complete_get_elt = cmd_flow_complete_get_elt,
5541 .get_help = cmd_flow_get_help,
5546 /** Populate the next dynamic token. */
5548 cmd_flow_tok(cmdline_parse_token_hdr_t **hdr,
5549 cmdline_parse_token_hdr_t **hdr_inst)
5551 struct context *ctx = &cmd_flow_context;
5553 /* Always reinitialize context before requesting the first token. */
5554 if (!(hdr_inst - cmd_flow.tokens))
5555 cmd_flow_context_init(ctx);
5556 /* Return NULL when no more tokens are expected. */
5557 if (!ctx->next_num && ctx->curr) {
5561 /* Determine if command should end here. */
5562 if (ctx->eol && ctx->last && ctx->next_num) {
5563 const enum index *list = ctx->next[ctx->next_num - 1];
5566 for (i = 0; list[i]; ++i) {
5573 *hdr = &cmd_flow_token_hdr;
5576 /** Dispatch parsed buffer to function calls. */
5578 cmd_flow_parsed(const struct buffer *in)
5580 switch (in->command) {
5582 port_flow_validate(in->port, &in->args.vc.attr,
5583 in->args.vc.pattern, in->args.vc.actions);
5586 port_flow_create(in->port, &in->args.vc.attr,
5587 in->args.vc.pattern, in->args.vc.actions);
5590 port_flow_destroy(in->port, in->args.destroy.rule_n,
5591 in->args.destroy.rule);
5594 port_flow_flush(in->port);
5597 port_flow_query(in->port, in->args.query.rule,
5598 &in->args.query.action);
5601 port_flow_list(in->port, in->args.list.group_n,
5602 in->args.list.group);
5605 port_flow_isolate(in->port, in->args.isolate.set);
5612 /** Token generator and output processing callback (cmdline API). */
5614 cmd_flow_cb(void *arg0, struct cmdline *cl, void *arg2)
5617 cmd_flow_tok(arg0, arg2);
5619 cmd_flow_parsed(arg0);
5622 /** Global parser instance (cmdline API). */
5623 cmdline_parse_inst_t cmd_flow = {
5625 .data = NULL, /**< Unused. */
5626 .help_str = NULL, /**< Updated by cmd_flow_get_help(). */
5629 }, /**< Tokens are returned by cmd_flow_tok(). */
5632 /** set cmd facility. Reuse cmd flow's infrastructure as much as possible. */
5635 update_fields(uint8_t *buf, struct rte_flow_item *item, uint16_t next_proto)
5637 struct rte_flow_item_ipv4 *ipv4;
5638 struct rte_flow_item_eth *eth;
5639 struct rte_flow_item_ipv6 *ipv6;
5640 struct rte_flow_item_vxlan *vxlan;
5641 struct rte_flow_item_vxlan_gpe *gpe;
5642 struct rte_flow_item_nvgre *nvgre;
5643 uint32_t ipv6_vtc_flow;
5645 switch (item->type) {
5646 case RTE_FLOW_ITEM_TYPE_ETH:
5647 eth = (struct rte_flow_item_eth *)buf;
5649 eth->type = rte_cpu_to_be_16(next_proto);
5651 case RTE_FLOW_ITEM_TYPE_IPV4:
5652 ipv4 = (struct rte_flow_item_ipv4 *)buf;
5653 ipv4->hdr.version_ihl = 0x45;
5654 ipv4->hdr.next_proto_id = (uint8_t)next_proto;
5656 case RTE_FLOW_ITEM_TYPE_IPV6:
5657 ipv6 = (struct rte_flow_item_ipv6 *)buf;
5658 ipv6->hdr.proto = (uint8_t)next_proto;
5659 ipv6_vtc_flow = rte_be_to_cpu_32(ipv6->hdr.vtc_flow);
5660 ipv6_vtc_flow &= 0x0FFFFFFF; /*< reset version bits. */
5661 ipv6_vtc_flow |= 0x60000000; /*< set ipv6 version. */
5662 ipv6->hdr.vtc_flow = rte_cpu_to_be_32(ipv6_vtc_flow);
5664 case RTE_FLOW_ITEM_TYPE_VXLAN:
5665 vxlan = (struct rte_flow_item_vxlan *)buf;
5666 vxlan->flags = 0x08;
5668 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
5669 gpe = (struct rte_flow_item_vxlan_gpe *)buf;
5672 case RTE_FLOW_ITEM_TYPE_NVGRE:
5673 nvgre = (struct rte_flow_item_nvgre *)buf;
5674 nvgre->protocol = rte_cpu_to_be_16(0x6558);
5675 nvgre->c_k_s_rsvd0_ver = rte_cpu_to_be_16(0x2000);
5682 /** Helper of get item's default mask. */
5684 flow_item_default_mask(const struct rte_flow_item *item)
5686 const void *mask = NULL;
5687 static rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
5689 switch (item->type) {
5690 case RTE_FLOW_ITEM_TYPE_ANY:
5691 mask = &rte_flow_item_any_mask;
5693 case RTE_FLOW_ITEM_TYPE_VF:
5694 mask = &rte_flow_item_vf_mask;
5696 case RTE_FLOW_ITEM_TYPE_PORT_ID:
5697 mask = &rte_flow_item_port_id_mask;
5699 case RTE_FLOW_ITEM_TYPE_RAW:
5700 mask = &rte_flow_item_raw_mask;
5702 case RTE_FLOW_ITEM_TYPE_ETH:
5703 mask = &rte_flow_item_eth_mask;
5705 case RTE_FLOW_ITEM_TYPE_VLAN:
5706 mask = &rte_flow_item_vlan_mask;
5708 case RTE_FLOW_ITEM_TYPE_IPV4:
5709 mask = &rte_flow_item_ipv4_mask;
5711 case RTE_FLOW_ITEM_TYPE_IPV6:
5712 mask = &rte_flow_item_ipv6_mask;
5714 case RTE_FLOW_ITEM_TYPE_ICMP:
5715 mask = &rte_flow_item_icmp_mask;
5717 case RTE_FLOW_ITEM_TYPE_UDP:
5718 mask = &rte_flow_item_udp_mask;
5720 case RTE_FLOW_ITEM_TYPE_TCP:
5721 mask = &rte_flow_item_tcp_mask;
5723 case RTE_FLOW_ITEM_TYPE_SCTP:
5724 mask = &rte_flow_item_sctp_mask;
5726 case RTE_FLOW_ITEM_TYPE_VXLAN:
5727 mask = &rte_flow_item_vxlan_mask;
5729 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
5730 mask = &rte_flow_item_vxlan_gpe_mask;
5732 case RTE_FLOW_ITEM_TYPE_E_TAG:
5733 mask = &rte_flow_item_e_tag_mask;
5735 case RTE_FLOW_ITEM_TYPE_NVGRE:
5736 mask = &rte_flow_item_nvgre_mask;
5738 case RTE_FLOW_ITEM_TYPE_MPLS:
5739 mask = &rte_flow_item_mpls_mask;
5741 case RTE_FLOW_ITEM_TYPE_GRE:
5742 mask = &rte_flow_item_gre_mask;
5744 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
5745 mask = &gre_key_default_mask;
5747 case RTE_FLOW_ITEM_TYPE_META:
5748 mask = &rte_flow_item_meta_mask;
5750 case RTE_FLOW_ITEM_TYPE_FUZZY:
5751 mask = &rte_flow_item_fuzzy_mask;
5753 case RTE_FLOW_ITEM_TYPE_GTP:
5754 mask = &rte_flow_item_gtp_mask;
5756 case RTE_FLOW_ITEM_TYPE_ESP:
5757 mask = &rte_flow_item_esp_mask;
5767 /** Dispatch parsed buffer to function calls. */
5769 cmd_set_raw_parsed(const struct buffer *in)
5771 uint32_t n = in->args.vc.pattern_n;
5773 struct rte_flow_item *item = NULL;
5775 uint8_t *data = NULL;
5776 uint8_t *data_tail = NULL;
5777 size_t *total_size = NULL;
5778 uint16_t upper_layer = 0;
5781 RTE_ASSERT(in->command == SET_RAW_ENCAP ||
5782 in->command == SET_RAW_DECAP);
5783 if (in->command == SET_RAW_ENCAP) {
5784 total_size = &raw_encap_conf.size;
5785 data = (uint8_t *)&raw_encap_conf.data;
5787 total_size = &raw_decap_conf.size;
5788 data = (uint8_t *)&raw_decap_conf.data;
5791 memset(data, 0x00, ACTION_RAW_ENCAP_MAX_DATA);
5792 /* process hdr from upper layer to low layer (L3/L4 -> L2). */
5793 data_tail = data + ACTION_RAW_ENCAP_MAX_DATA;
5794 for (i = n - 1 ; i >= 0; --i) {
5795 item = in->args.vc.pattern + i;
5796 if (item->spec == NULL)
5797 item->spec = flow_item_default_mask(item);
5798 switch (item->type) {
5799 case RTE_FLOW_ITEM_TYPE_ETH:
5800 size = sizeof(struct rte_flow_item_eth);
5802 case RTE_FLOW_ITEM_TYPE_VLAN:
5803 size = sizeof(struct rte_flow_item_vlan);
5804 proto = RTE_ETHER_TYPE_VLAN;
5806 case RTE_FLOW_ITEM_TYPE_IPV4:
5807 size = sizeof(struct rte_flow_item_ipv4);
5808 proto = RTE_ETHER_TYPE_IPV4;
5810 case RTE_FLOW_ITEM_TYPE_IPV6:
5811 size = sizeof(struct rte_flow_item_ipv6);
5812 proto = RTE_ETHER_TYPE_IPV6;
5814 case RTE_FLOW_ITEM_TYPE_UDP:
5815 size = sizeof(struct rte_flow_item_udp);
5818 case RTE_FLOW_ITEM_TYPE_TCP:
5819 size = sizeof(struct rte_flow_item_tcp);
5822 case RTE_FLOW_ITEM_TYPE_VXLAN:
5823 size = sizeof(struct rte_flow_item_vxlan);
5825 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
5826 size = sizeof(struct rte_flow_item_vxlan_gpe);
5828 case RTE_FLOW_ITEM_TYPE_GRE:
5829 size = sizeof(struct rte_flow_item_gre);
5832 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
5833 size = sizeof(rte_be32_t);
5835 case RTE_FLOW_ITEM_TYPE_MPLS:
5836 size = sizeof(struct rte_flow_item_mpls);
5838 case RTE_FLOW_ITEM_TYPE_NVGRE:
5839 size = sizeof(struct rte_flow_item_nvgre);
5843 printf("Error - Not supported item\n");
5845 memset(data, 0x00, ACTION_RAW_ENCAP_MAX_DATA);
5848 *total_size += size;
5849 rte_memcpy(data_tail - (*total_size), item->spec, size);
5850 /* update some fields which cannot be set by cmdline */
5851 update_fields((data_tail - (*total_size)), item,
5853 upper_layer = proto;
5855 if (verbose_level & 0x1)
5856 printf("total data size is %zu\n", (*total_size));
5857 RTE_ASSERT((*total_size) <= ACTION_RAW_ENCAP_MAX_DATA);
5860 /** Populate help strings for current token (cmdline API). */
5862 cmd_set_raw_get_help(cmdline_parse_token_hdr_t *hdr, char *dst,
5865 struct context *ctx = &cmd_flow_context;
5866 const struct token *token = &token_list[ctx->prev];
5871 /* Set token type and update global help with details. */
5872 snprintf(dst, size, "%s", (token->type ? token->type : "TOKEN"));
5874 cmd_set_raw.help_str = token->help;
5876 cmd_set_raw.help_str = token->name;
5880 /** Token definition template (cmdline API). */
5881 static struct cmdline_token_hdr cmd_set_raw_token_hdr = {
5882 .ops = &(struct cmdline_token_ops){
5883 .parse = cmd_flow_parse,
5884 .complete_get_nb = cmd_flow_complete_get_nb,
5885 .complete_get_elt = cmd_flow_complete_get_elt,
5886 .get_help = cmd_set_raw_get_help,
5891 /** Populate the next dynamic token. */
5893 cmd_set_raw_tok(cmdline_parse_token_hdr_t **hdr,
5894 cmdline_parse_token_hdr_t **hdr_inst)
5896 struct context *ctx = &cmd_flow_context;
5898 /* Always reinitialize context before requesting the first token. */
5899 if (!(hdr_inst - cmd_set_raw.tokens)) {
5900 cmd_flow_context_init(ctx);
5901 ctx->curr = START_SET;
5903 /* Return NULL when no more tokens are expected. */
5904 if (!ctx->next_num && (ctx->curr != START_SET)) {
5908 /* Determine if command should end here. */
5909 if (ctx->eol && ctx->last && ctx->next_num) {
5910 const enum index *list = ctx->next[ctx->next_num - 1];
5913 for (i = 0; list[i]; ++i) {
5920 *hdr = &cmd_set_raw_token_hdr;
5923 /** Token generator and output processing callback (cmdline API). */
5925 cmd_set_raw_cb(void *arg0, struct cmdline *cl, void *arg2)
5928 cmd_set_raw_tok(arg0, arg2);
5930 cmd_set_raw_parsed(arg0);
5933 /** Global parser instance (cmdline API). */
5934 cmdline_parse_inst_t cmd_set_raw = {
5935 .f = cmd_set_raw_cb,
5936 .data = NULL, /**< Unused. */
5937 .help_str = NULL, /**< Updated by cmd_flow_get_help(). */
5940 }, /**< Tokens are returned by cmd_flow_tok(). */