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. */
47 /* Top-level command. */
50 /* Sub-level commands. */
59 /* Destroy arguments. */
62 /* Query arguments. */
68 /* Validate/create arguments. */
75 /* Validate/create pattern. */
112 ITEM_VLAN_INNER_TYPE,
144 ITEM_E_TAG_GRP_ECID_B,
151 ITEM_GRE_C_RSVD0_VER,
167 ITEM_ARP_ETH_IPV4_SHA,
168 ITEM_ARP_ETH_IPV4_SPA,
169 ITEM_ARP_ETH_IPV4_THA,
170 ITEM_ARP_ETH_IPV4_TPA,
172 ITEM_IPV6_EXT_NEXT_HDR,
177 ITEM_ICMP6_ND_NS_TARGET_ADDR,
179 ITEM_ICMP6_ND_NA_TARGET_ADDR,
181 ITEM_ICMP6_ND_OPT_TYPE,
182 ITEM_ICMP6_ND_OPT_SLA_ETH,
183 ITEM_ICMP6_ND_OPT_SLA_ETH_SLA,
184 ITEM_ICMP6_ND_OPT_TLA_ETH,
185 ITEM_ICMP6_ND_OPT_TLA_ETH_TLA,
191 /* Validate/create actions. */
211 ACTION_RSS_FUNC_DEFAULT,
212 ACTION_RSS_FUNC_TOEPLITZ,
213 ACTION_RSS_FUNC_SIMPLE_XOR,
225 ACTION_PHY_PORT_ORIGINAL,
226 ACTION_PHY_PORT_INDEX,
228 ACTION_PORT_ID_ORIGINAL,
232 ACTION_OF_SET_MPLS_TTL,
233 ACTION_OF_SET_MPLS_TTL_MPLS_TTL,
234 ACTION_OF_DEC_MPLS_TTL,
235 ACTION_OF_SET_NW_TTL,
236 ACTION_OF_SET_NW_TTL_NW_TTL,
237 ACTION_OF_DEC_NW_TTL,
238 ACTION_OF_COPY_TTL_OUT,
239 ACTION_OF_COPY_TTL_IN,
242 ACTION_OF_PUSH_VLAN_ETHERTYPE,
243 ACTION_OF_SET_VLAN_VID,
244 ACTION_OF_SET_VLAN_VID_VLAN_VID,
245 ACTION_OF_SET_VLAN_PCP,
246 ACTION_OF_SET_VLAN_PCP_VLAN_PCP,
248 ACTION_OF_POP_MPLS_ETHERTYPE,
250 ACTION_OF_PUSH_MPLS_ETHERTYPE,
257 ACTION_MPLSOGRE_ENCAP,
258 ACTION_MPLSOGRE_DECAP,
259 ACTION_MPLSOUDP_ENCAP,
260 ACTION_MPLSOUDP_DECAP,
262 ACTION_SET_IPV4_SRC_IPV4_SRC,
264 ACTION_SET_IPV4_DST_IPV4_DST,
266 ACTION_SET_IPV6_SRC_IPV6_SRC,
268 ACTION_SET_IPV6_DST_IPV6_DST,
270 ACTION_SET_TP_SRC_TP_SRC,
272 ACTION_SET_TP_DST_TP_DST,
278 ACTION_SET_MAC_SRC_MAC_SRC,
280 ACTION_SET_MAC_DST_MAC_DST,
282 ACTION_INC_TCP_SEQ_VALUE,
284 ACTION_DEC_TCP_SEQ_VALUE,
286 ACTION_INC_TCP_ACK_VALUE,
288 ACTION_DEC_TCP_ACK_VALUE,
291 /** Maximum size for pattern in struct rte_flow_item_raw. */
292 #define ITEM_RAW_PATTERN_SIZE 40
294 /** Storage size for struct rte_flow_item_raw including pattern. */
295 #define ITEM_RAW_SIZE \
296 (sizeof(struct rte_flow_item_raw) + ITEM_RAW_PATTERN_SIZE)
298 /** Maximum number of queue indices in struct rte_flow_action_rss. */
299 #define ACTION_RSS_QUEUE_NUM 32
301 /** Storage for struct rte_flow_action_rss including external data. */
302 struct action_rss_data {
303 struct rte_flow_action_rss conf;
304 uint8_t key[RSS_HASH_KEY_LENGTH];
305 uint16_t queue[ACTION_RSS_QUEUE_NUM];
308 /** Maximum number of items in struct rte_flow_action_vxlan_encap. */
309 #define ACTION_VXLAN_ENCAP_ITEMS_NUM 6
311 /** Storage for struct rte_flow_action_vxlan_encap including external data. */
312 struct action_vxlan_encap_data {
313 struct rte_flow_action_vxlan_encap conf;
314 struct rte_flow_item items[ACTION_VXLAN_ENCAP_ITEMS_NUM];
315 struct rte_flow_item_eth item_eth;
316 struct rte_flow_item_vlan item_vlan;
318 struct rte_flow_item_ipv4 item_ipv4;
319 struct rte_flow_item_ipv6 item_ipv6;
321 struct rte_flow_item_udp item_udp;
322 struct rte_flow_item_vxlan item_vxlan;
325 /** Maximum number of items in struct rte_flow_action_nvgre_encap. */
326 #define ACTION_NVGRE_ENCAP_ITEMS_NUM 5
328 /** Storage for struct rte_flow_action_nvgre_encap including external data. */
329 struct action_nvgre_encap_data {
330 struct rte_flow_action_nvgre_encap conf;
331 struct rte_flow_item items[ACTION_NVGRE_ENCAP_ITEMS_NUM];
332 struct rte_flow_item_eth item_eth;
333 struct rte_flow_item_vlan item_vlan;
335 struct rte_flow_item_ipv4 item_ipv4;
336 struct rte_flow_item_ipv6 item_ipv6;
338 struct rte_flow_item_nvgre item_nvgre;
341 /** Maximum data size in struct rte_flow_action_raw_encap. */
342 #define ACTION_RAW_ENCAP_MAX_DATA 128
344 /** Storage for struct rte_flow_action_raw_encap including external data. */
345 struct action_raw_encap_data {
346 struct rte_flow_action_raw_encap conf;
347 uint8_t data[ACTION_RAW_ENCAP_MAX_DATA];
348 uint8_t preserve[ACTION_RAW_ENCAP_MAX_DATA];
351 /** Storage for struct rte_flow_action_raw_decap including external data. */
352 struct action_raw_decap_data {
353 struct rte_flow_action_raw_decap conf;
354 uint8_t data[ACTION_RAW_ENCAP_MAX_DATA];
357 /** Maximum number of subsequent tokens and arguments on the stack. */
358 #define CTX_STACK_SIZE 16
360 /** Parser context. */
362 /** Stack of subsequent token lists to process. */
363 const enum index *next[CTX_STACK_SIZE];
364 /** Arguments for stacked tokens. */
365 const void *args[CTX_STACK_SIZE];
366 enum index curr; /**< Current token index. */
367 enum index prev; /**< Index of the last token seen. */
368 int next_num; /**< Number of entries in next[]. */
369 int args_num; /**< Number of entries in args[]. */
370 uint32_t eol:1; /**< EOL has been detected. */
371 uint32_t last:1; /**< No more arguments. */
372 portid_t port; /**< Current port ID (for completions). */
373 uint32_t objdata; /**< Object-specific data. */
374 void *object; /**< Address of current object for relative offsets. */
375 void *objmask; /**< Object a full mask must be written to. */
378 /** Token argument. */
380 uint32_t hton:1; /**< Use network byte ordering. */
381 uint32_t sign:1; /**< Value is signed. */
382 uint32_t bounded:1; /**< Value is bounded. */
383 uintmax_t min; /**< Minimum value if bounded. */
384 uintmax_t max; /**< Maximum value if bounded. */
385 uint32_t offset; /**< Relative offset from ctx->object. */
386 uint32_t size; /**< Field size. */
387 const uint8_t *mask; /**< Bit-mask to use instead of offset/size. */
390 /** Parser token definition. */
392 /** Type displayed during completion (defaults to "TOKEN"). */
394 /** Help displayed during completion (defaults to token name). */
396 /** Private data used by parser functions. */
399 * Lists of subsequent tokens to push on the stack. Each call to the
400 * parser consumes the last entry of that stack.
402 const enum index *const *next;
403 /** Arguments stack for subsequent tokens that need them. */
404 const struct arg *const *args;
406 * Token-processing callback, returns -1 in case of error, the
407 * length of the matched string otherwise. If NULL, attempts to
408 * match the token name.
410 * If buf is not NULL, the result should be stored in it according
411 * to context. An error is returned if not large enough.
413 int (*call)(struct context *ctx, const struct token *token,
414 const char *str, unsigned int len,
415 void *buf, unsigned int size);
417 * Callback that provides possible values for this token, used for
418 * completion. Returns -1 in case of error, the number of possible
419 * values otherwise. If NULL, the token name is used.
421 * If buf is not NULL, entry index ent is written to buf and the
422 * full length of the entry is returned (same behavior as
425 int (*comp)(struct context *ctx, const struct token *token,
426 unsigned int ent, char *buf, unsigned int size);
427 /** Mandatory token name, no default value. */
431 /** Static initializer for the next field. */
432 #define NEXT(...) (const enum index *const []){ __VA_ARGS__, NULL, }
434 /** Static initializer for a NEXT() entry. */
435 #define NEXT_ENTRY(...) (const enum index []){ __VA_ARGS__, ZERO, }
437 /** Static initializer for the args field. */
438 #define ARGS(...) (const struct arg *const []){ __VA_ARGS__, NULL, }
440 /** Static initializer for ARGS() to target a field. */
441 #define ARGS_ENTRY(s, f) \
442 (&(const struct arg){ \
443 .offset = offsetof(s, f), \
444 .size = sizeof(((s *)0)->f), \
447 /** Static initializer for ARGS() to target a bit-field. */
448 #define ARGS_ENTRY_BF(s, f, b) \
449 (&(const struct arg){ \
451 .mask = (const void *)&(const s){ .f = (1 << (b)) - 1 }, \
454 /** Static initializer for ARGS() to target an arbitrary bit-mask. */
455 #define ARGS_ENTRY_MASK(s, f, m) \
456 (&(const struct arg){ \
457 .offset = offsetof(s, f), \
458 .size = sizeof(((s *)0)->f), \
459 .mask = (const void *)(m), \
462 /** Same as ARGS_ENTRY_MASK() using network byte ordering for the value. */
463 #define ARGS_ENTRY_MASK_HTON(s, f, m) \
464 (&(const struct arg){ \
466 .offset = offsetof(s, f), \
467 .size = sizeof(((s *)0)->f), \
468 .mask = (const void *)(m), \
471 /** Static initializer for ARGS() to target a pointer. */
472 #define ARGS_ENTRY_PTR(s, f) \
473 (&(const struct arg){ \
474 .size = sizeof(*((s *)0)->f), \
477 /** Static initializer for ARGS() with arbitrary offset and size. */
478 #define ARGS_ENTRY_ARB(o, s) \
479 (&(const struct arg){ \
484 /** Same as ARGS_ENTRY_ARB() with bounded values. */
485 #define ARGS_ENTRY_ARB_BOUNDED(o, s, i, a) \
486 (&(const struct arg){ \
494 /** Same as ARGS_ENTRY() using network byte ordering. */
495 #define ARGS_ENTRY_HTON(s, f) \
496 (&(const struct arg){ \
498 .offset = offsetof(s, f), \
499 .size = sizeof(((s *)0)->f), \
502 /** Same as ARGS_ENTRY_HTON() for a single argument, without structure. */
503 #define ARG_ENTRY_HTON(s) \
504 (&(const struct arg){ \
510 /** Parser output buffer layout expected by cmd_flow_parsed(). */
512 enum index command; /**< Flow command. */
513 portid_t port; /**< Affected port ID. */
516 struct rte_flow_attr attr;
517 struct rte_flow_item *pattern;
518 struct rte_flow_action *actions;
522 } vc; /**< Validate/create arguments. */
526 } destroy; /**< Destroy arguments. */
529 struct rte_flow_action action;
530 } query; /**< Query arguments. */
534 } list; /**< List arguments. */
537 } isolate; /**< Isolated mode arguments. */
538 } args; /**< Command arguments. */
541 /** Private data for pattern items. */
542 struct parse_item_priv {
543 enum rte_flow_item_type type; /**< Item type. */
544 uint32_t size; /**< Size of item specification structure. */
547 #define PRIV_ITEM(t, s) \
548 (&(const struct parse_item_priv){ \
549 .type = RTE_FLOW_ITEM_TYPE_ ## t, \
553 /** Private data for actions. */
554 struct parse_action_priv {
555 enum rte_flow_action_type type; /**< Action type. */
556 uint32_t size; /**< Size of action configuration structure. */
559 #define PRIV_ACTION(t, s) \
560 (&(const struct parse_action_priv){ \
561 .type = RTE_FLOW_ACTION_TYPE_ ## t, \
565 static const enum index next_vc_attr[] = {
575 static const enum index next_destroy_attr[] = {
581 static const enum index next_list_attr[] = {
587 static const enum index item_param[] = {
596 static const enum index next_item[] = {
632 ITEM_ICMP6_ND_OPT_SLA_ETH,
633 ITEM_ICMP6_ND_OPT_TLA_ETH,
639 static const enum index item_fuzzy[] = {
645 static const enum index item_any[] = {
651 static const enum index item_vf[] = {
657 static const enum index item_phy_port[] = {
663 static const enum index item_port_id[] = {
669 static const enum index item_mark[] = {
675 static const enum index item_raw[] = {
685 static const enum index item_eth[] = {
693 static const enum index item_vlan[] = {
698 ITEM_VLAN_INNER_TYPE,
703 static const enum index item_ipv4[] = {
713 static const enum index item_ipv6[] = {
724 static const enum index item_icmp[] = {
731 static const enum index item_udp[] = {
738 static const enum index item_tcp[] = {
746 static const enum index item_sctp[] = {
755 static const enum index item_vxlan[] = {
761 static const enum index item_e_tag[] = {
762 ITEM_E_TAG_GRP_ECID_B,
767 static const enum index item_nvgre[] = {
773 static const enum index item_mpls[] = {
779 static const enum index item_gre[] = {
781 ITEM_GRE_C_RSVD0_VER,
789 static const enum index item_gre_key[] = {
795 static const enum index item_gtp[] = {
801 static const enum index item_geneve[] = {
808 static const enum index item_vxlan_gpe[] = {
814 static const enum index item_arp_eth_ipv4[] = {
815 ITEM_ARP_ETH_IPV4_SHA,
816 ITEM_ARP_ETH_IPV4_SPA,
817 ITEM_ARP_ETH_IPV4_THA,
818 ITEM_ARP_ETH_IPV4_TPA,
823 static const enum index item_ipv6_ext[] = {
824 ITEM_IPV6_EXT_NEXT_HDR,
829 static const enum index item_icmp6[] = {
836 static const enum index item_icmp6_nd_ns[] = {
837 ITEM_ICMP6_ND_NS_TARGET_ADDR,
842 static const enum index item_icmp6_nd_na[] = {
843 ITEM_ICMP6_ND_NA_TARGET_ADDR,
848 static const enum index item_icmp6_nd_opt[] = {
849 ITEM_ICMP6_ND_OPT_TYPE,
854 static const enum index item_icmp6_nd_opt_sla_eth[] = {
855 ITEM_ICMP6_ND_OPT_SLA_ETH_SLA,
860 static const enum index item_icmp6_nd_opt_tla_eth[] = {
861 ITEM_ICMP6_ND_OPT_TLA_ETH_TLA,
866 static const enum index item_meta[] = {
872 static const enum index next_action[] = {
888 ACTION_OF_SET_MPLS_TTL,
889 ACTION_OF_DEC_MPLS_TTL,
890 ACTION_OF_SET_NW_TTL,
891 ACTION_OF_DEC_NW_TTL,
892 ACTION_OF_COPY_TTL_OUT,
893 ACTION_OF_COPY_TTL_IN,
896 ACTION_OF_SET_VLAN_VID,
897 ACTION_OF_SET_VLAN_PCP,
906 ACTION_MPLSOGRE_ENCAP,
907 ACTION_MPLSOGRE_DECAP,
908 ACTION_MPLSOUDP_ENCAP,
909 ACTION_MPLSOUDP_DECAP,
928 static const enum index action_mark[] = {
934 static const enum index action_queue[] = {
940 static const enum index action_count[] = {
947 static const enum index action_rss[] = {
958 static const enum index action_vf[] = {
965 static const enum index action_phy_port[] = {
966 ACTION_PHY_PORT_ORIGINAL,
967 ACTION_PHY_PORT_INDEX,
972 static const enum index action_port_id[] = {
973 ACTION_PORT_ID_ORIGINAL,
979 static const enum index action_meter[] = {
985 static const enum index action_of_set_mpls_ttl[] = {
986 ACTION_OF_SET_MPLS_TTL_MPLS_TTL,
991 static const enum index action_of_set_nw_ttl[] = {
992 ACTION_OF_SET_NW_TTL_NW_TTL,
997 static const enum index action_of_push_vlan[] = {
998 ACTION_OF_PUSH_VLAN_ETHERTYPE,
1003 static const enum index action_of_set_vlan_vid[] = {
1004 ACTION_OF_SET_VLAN_VID_VLAN_VID,
1009 static const enum index action_of_set_vlan_pcp[] = {
1010 ACTION_OF_SET_VLAN_PCP_VLAN_PCP,
1015 static const enum index action_of_pop_mpls[] = {
1016 ACTION_OF_POP_MPLS_ETHERTYPE,
1021 static const enum index action_of_push_mpls[] = {
1022 ACTION_OF_PUSH_MPLS_ETHERTYPE,
1027 static const enum index action_set_ipv4_src[] = {
1028 ACTION_SET_IPV4_SRC_IPV4_SRC,
1033 static const enum index action_set_mac_src[] = {
1034 ACTION_SET_MAC_SRC_MAC_SRC,
1039 static const enum index action_set_ipv4_dst[] = {
1040 ACTION_SET_IPV4_DST_IPV4_DST,
1045 static const enum index action_set_ipv6_src[] = {
1046 ACTION_SET_IPV6_SRC_IPV6_SRC,
1051 static const enum index action_set_ipv6_dst[] = {
1052 ACTION_SET_IPV6_DST_IPV6_DST,
1057 static const enum index action_set_tp_src[] = {
1058 ACTION_SET_TP_SRC_TP_SRC,
1063 static const enum index action_set_tp_dst[] = {
1064 ACTION_SET_TP_DST_TP_DST,
1069 static const enum index action_set_ttl[] = {
1075 static const enum index action_jump[] = {
1081 static const enum index action_set_mac_dst[] = {
1082 ACTION_SET_MAC_DST_MAC_DST,
1087 static const enum index action_inc_tcp_seq[] = {
1088 ACTION_INC_TCP_SEQ_VALUE,
1093 static const enum index action_dec_tcp_seq[] = {
1094 ACTION_DEC_TCP_SEQ_VALUE,
1099 static const enum index action_inc_tcp_ack[] = {
1100 ACTION_INC_TCP_ACK_VALUE,
1105 static const enum index action_dec_tcp_ack[] = {
1106 ACTION_DEC_TCP_ACK_VALUE,
1111 static int parse_init(struct context *, const struct token *,
1112 const char *, unsigned int,
1113 void *, unsigned int);
1114 static int parse_vc(struct context *, const struct token *,
1115 const char *, unsigned int,
1116 void *, unsigned int);
1117 static int parse_vc_spec(struct context *, const struct token *,
1118 const char *, unsigned int, void *, unsigned int);
1119 static int parse_vc_conf(struct context *, const struct token *,
1120 const char *, unsigned int, void *, unsigned int);
1121 static int parse_vc_action_rss(struct context *, const struct token *,
1122 const char *, unsigned int, void *,
1124 static int parse_vc_action_rss_func(struct context *, const struct token *,
1125 const char *, unsigned int, void *,
1127 static int parse_vc_action_rss_type(struct context *, const struct token *,
1128 const char *, unsigned int, void *,
1130 static int parse_vc_action_rss_queue(struct context *, const struct token *,
1131 const char *, unsigned int, void *,
1133 static int parse_vc_action_vxlan_encap(struct context *, const struct token *,
1134 const char *, unsigned int, void *,
1136 static int parse_vc_action_nvgre_encap(struct context *, const struct token *,
1137 const char *, unsigned int, void *,
1139 static int parse_vc_action_l2_encap(struct context *, const struct token *,
1140 const char *, unsigned int, void *,
1142 static int parse_vc_action_l2_decap(struct context *, const struct token *,
1143 const char *, unsigned int, void *,
1145 static int parse_vc_action_mplsogre_encap(struct context *,
1146 const struct token *, const char *,
1147 unsigned int, void *, unsigned int);
1148 static int parse_vc_action_mplsogre_decap(struct context *,
1149 const struct token *, const char *,
1150 unsigned int, void *, unsigned int);
1151 static int parse_vc_action_mplsoudp_encap(struct context *,
1152 const struct token *, const char *,
1153 unsigned int, void *, unsigned int);
1154 static int parse_vc_action_mplsoudp_decap(struct context *,
1155 const struct token *, const char *,
1156 unsigned int, void *, unsigned int);
1157 static int parse_destroy(struct context *, const struct token *,
1158 const char *, unsigned int,
1159 void *, unsigned int);
1160 static int parse_flush(struct context *, const struct token *,
1161 const char *, unsigned int,
1162 void *, unsigned int);
1163 static int parse_query(struct context *, const struct token *,
1164 const char *, unsigned int,
1165 void *, unsigned int);
1166 static int parse_action(struct context *, const struct token *,
1167 const char *, unsigned int,
1168 void *, unsigned int);
1169 static int parse_list(struct context *, const struct token *,
1170 const char *, unsigned int,
1171 void *, unsigned int);
1172 static int parse_isolate(struct context *, const struct token *,
1173 const char *, unsigned int,
1174 void *, unsigned int);
1175 static int parse_int(struct context *, const struct token *,
1176 const char *, unsigned int,
1177 void *, unsigned int);
1178 static int parse_prefix(struct context *, const struct token *,
1179 const char *, unsigned int,
1180 void *, unsigned int);
1181 static int parse_boolean(struct context *, const struct token *,
1182 const char *, unsigned int,
1183 void *, unsigned int);
1184 static int parse_string(struct context *, const struct token *,
1185 const char *, unsigned int,
1186 void *, unsigned int);
1187 static int parse_hex(struct context *ctx, const struct token *token,
1188 const char *str, unsigned int len,
1189 void *buf, unsigned int size);
1190 static int parse_mac_addr(struct context *, const struct token *,
1191 const char *, unsigned int,
1192 void *, unsigned int);
1193 static int parse_ipv4_addr(struct context *, const struct token *,
1194 const char *, unsigned int,
1195 void *, unsigned int);
1196 static int parse_ipv6_addr(struct context *, const struct token *,
1197 const char *, unsigned int,
1198 void *, unsigned int);
1199 static int parse_port(struct context *, const struct token *,
1200 const char *, unsigned int,
1201 void *, unsigned int);
1202 static int comp_none(struct context *, const struct token *,
1203 unsigned int, char *, unsigned int);
1204 static int comp_boolean(struct context *, const struct token *,
1205 unsigned int, char *, unsigned int);
1206 static int comp_action(struct context *, const struct token *,
1207 unsigned int, char *, unsigned int);
1208 static int comp_port(struct context *, const struct token *,
1209 unsigned int, char *, unsigned int);
1210 static int comp_rule_id(struct context *, const struct token *,
1211 unsigned int, char *, unsigned int);
1212 static int comp_vc_action_rss_type(struct context *, const struct token *,
1213 unsigned int, char *, unsigned int);
1214 static int comp_vc_action_rss_queue(struct context *, const struct token *,
1215 unsigned int, char *, unsigned int);
1217 /** Token definitions. */
1218 static const struct token token_list[] = {
1219 /* Special tokens. */
1222 .help = "null entry, abused as the entry point",
1223 .next = NEXT(NEXT_ENTRY(FLOW)),
1228 .help = "command may end here",
1230 /* Common tokens. */
1234 .help = "integer value",
1239 .name = "{unsigned}",
1241 .help = "unsigned integer value",
1248 .help = "prefix length for bit-mask",
1249 .call = parse_prefix,
1253 .name = "{boolean}",
1255 .help = "any boolean value",
1256 .call = parse_boolean,
1257 .comp = comp_boolean,
1262 .help = "fixed string",
1263 .call = parse_string,
1269 .help = "fixed string",
1274 .name = "{MAC address}",
1276 .help = "standard MAC address notation",
1277 .call = parse_mac_addr,
1281 .name = "{IPv4 address}",
1282 .type = "IPV4 ADDRESS",
1283 .help = "standard IPv4 address notation",
1284 .call = parse_ipv4_addr,
1288 .name = "{IPv6 address}",
1289 .type = "IPV6 ADDRESS",
1290 .help = "standard IPv6 address notation",
1291 .call = parse_ipv6_addr,
1295 .name = "{rule id}",
1297 .help = "rule identifier",
1299 .comp = comp_rule_id,
1302 .name = "{port_id}",
1304 .help = "port identifier",
1309 .name = "{group_id}",
1311 .help = "group identifier",
1315 [PRIORITY_LEVEL] = {
1318 .help = "priority level",
1322 /* Top-level command. */
1325 .type = "{command} {port_id} [{arg} [...]]",
1326 .help = "manage ingress/egress flow rules",
1327 .next = NEXT(NEXT_ENTRY
1337 /* Sub-level commands. */
1340 .help = "check whether a flow rule can be created",
1341 .next = NEXT(next_vc_attr, NEXT_ENTRY(PORT_ID)),
1342 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1347 .help = "create a flow rule",
1348 .next = NEXT(next_vc_attr, NEXT_ENTRY(PORT_ID)),
1349 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1354 .help = "destroy specific flow rules",
1355 .next = NEXT(NEXT_ENTRY(DESTROY_RULE), NEXT_ENTRY(PORT_ID)),
1356 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1357 .call = parse_destroy,
1361 .help = "destroy all flow rules",
1362 .next = NEXT(NEXT_ENTRY(PORT_ID)),
1363 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1364 .call = parse_flush,
1368 .help = "query an existing flow rule",
1369 .next = NEXT(NEXT_ENTRY(QUERY_ACTION),
1370 NEXT_ENTRY(RULE_ID),
1371 NEXT_ENTRY(PORT_ID)),
1372 .args = ARGS(ARGS_ENTRY(struct buffer, args.query.action.type),
1373 ARGS_ENTRY(struct buffer, args.query.rule),
1374 ARGS_ENTRY(struct buffer, port)),
1375 .call = parse_query,
1379 .help = "list existing flow rules",
1380 .next = NEXT(next_list_attr, NEXT_ENTRY(PORT_ID)),
1381 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1386 .help = "restrict ingress traffic to the defined flow rules",
1387 .next = NEXT(NEXT_ENTRY(BOOLEAN),
1388 NEXT_ENTRY(PORT_ID)),
1389 .args = ARGS(ARGS_ENTRY(struct buffer, args.isolate.set),
1390 ARGS_ENTRY(struct buffer, port)),
1391 .call = parse_isolate,
1393 /* Destroy arguments. */
1396 .help = "specify a rule identifier",
1397 .next = NEXT(next_destroy_attr, NEXT_ENTRY(RULE_ID)),
1398 .args = ARGS(ARGS_ENTRY_PTR(struct buffer, args.destroy.rule)),
1399 .call = parse_destroy,
1401 /* Query arguments. */
1405 .help = "action to query, must be part of the rule",
1406 .call = parse_action,
1407 .comp = comp_action,
1409 /* List arguments. */
1412 .help = "specify a group",
1413 .next = NEXT(next_list_attr, NEXT_ENTRY(GROUP_ID)),
1414 .args = ARGS(ARGS_ENTRY_PTR(struct buffer, args.list.group)),
1417 /* Validate/create attributes. */
1420 .help = "specify a group",
1421 .next = NEXT(next_vc_attr, NEXT_ENTRY(GROUP_ID)),
1422 .args = ARGS(ARGS_ENTRY(struct rte_flow_attr, group)),
1427 .help = "specify a priority level",
1428 .next = NEXT(next_vc_attr, NEXT_ENTRY(PRIORITY_LEVEL)),
1429 .args = ARGS(ARGS_ENTRY(struct rte_flow_attr, priority)),
1434 .help = "affect rule to ingress",
1435 .next = NEXT(next_vc_attr),
1440 .help = "affect rule to egress",
1441 .next = NEXT(next_vc_attr),
1446 .help = "apply rule directly to endpoints found in pattern",
1447 .next = NEXT(next_vc_attr),
1450 /* Validate/create pattern. */
1453 .help = "submit a list of pattern items",
1454 .next = NEXT(next_item),
1459 .help = "match value perfectly (with full bit-mask)",
1460 .call = parse_vc_spec,
1462 [ITEM_PARAM_SPEC] = {
1464 .help = "match value according to configured bit-mask",
1465 .call = parse_vc_spec,
1467 [ITEM_PARAM_LAST] = {
1469 .help = "specify upper bound to establish a range",
1470 .call = parse_vc_spec,
1472 [ITEM_PARAM_MASK] = {
1474 .help = "specify bit-mask with relevant bits set to one",
1475 .call = parse_vc_spec,
1477 [ITEM_PARAM_PREFIX] = {
1479 .help = "generate bit-mask from a prefix length",
1480 .call = parse_vc_spec,
1484 .help = "specify next pattern item",
1485 .next = NEXT(next_item),
1489 .help = "end list of pattern items",
1490 .priv = PRIV_ITEM(END, 0),
1491 .next = NEXT(NEXT_ENTRY(ACTIONS)),
1496 .help = "no-op pattern item",
1497 .priv = PRIV_ITEM(VOID, 0),
1498 .next = NEXT(NEXT_ENTRY(ITEM_NEXT)),
1503 .help = "perform actions when pattern does not match",
1504 .priv = PRIV_ITEM(INVERT, 0),
1505 .next = NEXT(NEXT_ENTRY(ITEM_NEXT)),
1510 .help = "match any protocol for the current layer",
1511 .priv = PRIV_ITEM(ANY, sizeof(struct rte_flow_item_any)),
1512 .next = NEXT(item_any),
1517 .help = "number of layers covered",
1518 .next = NEXT(item_any, NEXT_ENTRY(UNSIGNED), item_param),
1519 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_any, num)),
1523 .help = "match traffic from/to the physical function",
1524 .priv = PRIV_ITEM(PF, 0),
1525 .next = NEXT(NEXT_ENTRY(ITEM_NEXT)),
1530 .help = "match traffic from/to a virtual function ID",
1531 .priv = PRIV_ITEM(VF, sizeof(struct rte_flow_item_vf)),
1532 .next = NEXT(item_vf),
1538 .next = NEXT(item_vf, NEXT_ENTRY(UNSIGNED), item_param),
1539 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_vf, id)),
1543 .help = "match traffic from/to a specific physical port",
1544 .priv = PRIV_ITEM(PHY_PORT,
1545 sizeof(struct rte_flow_item_phy_port)),
1546 .next = NEXT(item_phy_port),
1549 [ITEM_PHY_PORT_INDEX] = {
1551 .help = "physical port index",
1552 .next = NEXT(item_phy_port, NEXT_ENTRY(UNSIGNED), item_param),
1553 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_phy_port, index)),
1557 .help = "match traffic from/to a given DPDK port ID",
1558 .priv = PRIV_ITEM(PORT_ID,
1559 sizeof(struct rte_flow_item_port_id)),
1560 .next = NEXT(item_port_id),
1563 [ITEM_PORT_ID_ID] = {
1565 .help = "DPDK port ID",
1566 .next = NEXT(item_port_id, NEXT_ENTRY(UNSIGNED), item_param),
1567 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_port_id, id)),
1571 .help = "match traffic against value set in previously matched rule",
1572 .priv = PRIV_ITEM(MARK, sizeof(struct rte_flow_item_mark)),
1573 .next = NEXT(item_mark),
1578 .help = "Integer value to match against",
1579 .next = NEXT(item_mark, NEXT_ENTRY(UNSIGNED), item_param),
1580 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_mark, id)),
1584 .help = "match an arbitrary byte string",
1585 .priv = PRIV_ITEM(RAW, ITEM_RAW_SIZE),
1586 .next = NEXT(item_raw),
1589 [ITEM_RAW_RELATIVE] = {
1591 .help = "look for pattern after the previous item",
1592 .next = NEXT(item_raw, NEXT_ENTRY(BOOLEAN), item_param),
1593 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_item_raw,
1596 [ITEM_RAW_SEARCH] = {
1598 .help = "search pattern from offset (see also limit)",
1599 .next = NEXT(item_raw, NEXT_ENTRY(BOOLEAN), item_param),
1600 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_item_raw,
1603 [ITEM_RAW_OFFSET] = {
1605 .help = "absolute or relative offset for pattern",
1606 .next = NEXT(item_raw, NEXT_ENTRY(INTEGER), item_param),
1607 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_raw, offset)),
1609 [ITEM_RAW_LIMIT] = {
1611 .help = "search area limit for start of pattern",
1612 .next = NEXT(item_raw, NEXT_ENTRY(UNSIGNED), item_param),
1613 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_raw, limit)),
1615 [ITEM_RAW_PATTERN] = {
1617 .help = "byte string to look for",
1618 .next = NEXT(item_raw,
1620 NEXT_ENTRY(ITEM_PARAM_IS,
1623 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_raw, pattern),
1624 ARGS_ENTRY(struct rte_flow_item_raw, length),
1625 ARGS_ENTRY_ARB(sizeof(struct rte_flow_item_raw),
1626 ITEM_RAW_PATTERN_SIZE)),
1630 .help = "match Ethernet header",
1631 .priv = PRIV_ITEM(ETH, sizeof(struct rte_flow_item_eth)),
1632 .next = NEXT(item_eth),
1637 .help = "destination MAC",
1638 .next = NEXT(item_eth, NEXT_ENTRY(MAC_ADDR), item_param),
1639 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_eth, dst)),
1643 .help = "source MAC",
1644 .next = NEXT(item_eth, NEXT_ENTRY(MAC_ADDR), item_param),
1645 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_eth, src)),
1649 .help = "EtherType",
1650 .next = NEXT(item_eth, NEXT_ENTRY(UNSIGNED), item_param),
1651 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_eth, type)),
1655 .help = "match 802.1Q/ad VLAN tag",
1656 .priv = PRIV_ITEM(VLAN, sizeof(struct rte_flow_item_vlan)),
1657 .next = NEXT(item_vlan),
1662 .help = "tag control information",
1663 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1664 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vlan, tci)),
1668 .help = "priority code point",
1669 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1670 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_vlan,
1675 .help = "drop eligible indicator",
1676 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1677 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_vlan,
1682 .help = "VLAN identifier",
1683 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1684 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_vlan,
1687 [ITEM_VLAN_INNER_TYPE] = {
1688 .name = "inner_type",
1689 .help = "inner EtherType",
1690 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1691 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vlan,
1696 .help = "match IPv4 header",
1697 .priv = PRIV_ITEM(IPV4, sizeof(struct rte_flow_item_ipv4)),
1698 .next = NEXT(item_ipv4),
1703 .help = "type of service",
1704 .next = NEXT(item_ipv4, NEXT_ENTRY(UNSIGNED), item_param),
1705 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
1706 hdr.type_of_service)),
1710 .help = "time to live",
1711 .next = NEXT(item_ipv4, NEXT_ENTRY(UNSIGNED), item_param),
1712 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
1715 [ITEM_IPV4_PROTO] = {
1717 .help = "next protocol ID",
1718 .next = NEXT(item_ipv4, NEXT_ENTRY(UNSIGNED), item_param),
1719 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
1720 hdr.next_proto_id)),
1724 .help = "source address",
1725 .next = NEXT(item_ipv4, NEXT_ENTRY(IPV4_ADDR), item_param),
1726 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
1731 .help = "destination address",
1732 .next = NEXT(item_ipv4, NEXT_ENTRY(IPV4_ADDR), item_param),
1733 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
1738 .help = "match IPv6 header",
1739 .priv = PRIV_ITEM(IPV6, sizeof(struct rte_flow_item_ipv6)),
1740 .next = NEXT(item_ipv6),
1745 .help = "traffic class",
1746 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
1747 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_ipv6,
1749 "\x0f\xf0\x00\x00")),
1751 [ITEM_IPV6_FLOW] = {
1753 .help = "flow label",
1754 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
1755 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_ipv6,
1757 "\x00\x0f\xff\xff")),
1759 [ITEM_IPV6_PROTO] = {
1761 .help = "protocol (next header)",
1762 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
1763 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
1768 .help = "hop limit",
1769 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
1770 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
1775 .help = "source address",
1776 .next = NEXT(item_ipv6, NEXT_ENTRY(IPV6_ADDR), item_param),
1777 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
1782 .help = "destination address",
1783 .next = NEXT(item_ipv6, NEXT_ENTRY(IPV6_ADDR), item_param),
1784 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
1789 .help = "match ICMP header",
1790 .priv = PRIV_ITEM(ICMP, sizeof(struct rte_flow_item_icmp)),
1791 .next = NEXT(item_icmp),
1794 [ITEM_ICMP_TYPE] = {
1796 .help = "ICMP packet type",
1797 .next = NEXT(item_icmp, NEXT_ENTRY(UNSIGNED), item_param),
1798 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp,
1801 [ITEM_ICMP_CODE] = {
1803 .help = "ICMP packet code",
1804 .next = NEXT(item_icmp, NEXT_ENTRY(UNSIGNED), item_param),
1805 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp,
1810 .help = "match UDP header",
1811 .priv = PRIV_ITEM(UDP, sizeof(struct rte_flow_item_udp)),
1812 .next = NEXT(item_udp),
1817 .help = "UDP source port",
1818 .next = NEXT(item_udp, NEXT_ENTRY(UNSIGNED), item_param),
1819 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_udp,
1824 .help = "UDP destination port",
1825 .next = NEXT(item_udp, NEXT_ENTRY(UNSIGNED), item_param),
1826 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_udp,
1831 .help = "match TCP header",
1832 .priv = PRIV_ITEM(TCP, sizeof(struct rte_flow_item_tcp)),
1833 .next = NEXT(item_tcp),
1838 .help = "TCP source port",
1839 .next = NEXT(item_tcp, NEXT_ENTRY(UNSIGNED), item_param),
1840 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_tcp,
1845 .help = "TCP destination port",
1846 .next = NEXT(item_tcp, NEXT_ENTRY(UNSIGNED), item_param),
1847 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_tcp,
1850 [ITEM_TCP_FLAGS] = {
1852 .help = "TCP flags",
1853 .next = NEXT(item_tcp, NEXT_ENTRY(UNSIGNED), item_param),
1854 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_tcp,
1859 .help = "match SCTP header",
1860 .priv = PRIV_ITEM(SCTP, sizeof(struct rte_flow_item_sctp)),
1861 .next = NEXT(item_sctp),
1866 .help = "SCTP source port",
1867 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
1868 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
1873 .help = "SCTP destination port",
1874 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
1875 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
1880 .help = "validation tag",
1881 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
1882 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
1885 [ITEM_SCTP_CKSUM] = {
1888 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
1889 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
1894 .help = "match VXLAN header",
1895 .priv = PRIV_ITEM(VXLAN, sizeof(struct rte_flow_item_vxlan)),
1896 .next = NEXT(item_vxlan),
1899 [ITEM_VXLAN_VNI] = {
1901 .help = "VXLAN identifier",
1902 .next = NEXT(item_vxlan, NEXT_ENTRY(UNSIGNED), item_param),
1903 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vxlan, vni)),
1907 .help = "match E-Tag header",
1908 .priv = PRIV_ITEM(E_TAG, sizeof(struct rte_flow_item_e_tag)),
1909 .next = NEXT(item_e_tag),
1912 [ITEM_E_TAG_GRP_ECID_B] = {
1913 .name = "grp_ecid_b",
1914 .help = "GRP and E-CID base",
1915 .next = NEXT(item_e_tag, NEXT_ENTRY(UNSIGNED), item_param),
1916 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_e_tag,
1922 .help = "match NVGRE header",
1923 .priv = PRIV_ITEM(NVGRE, sizeof(struct rte_flow_item_nvgre)),
1924 .next = NEXT(item_nvgre),
1927 [ITEM_NVGRE_TNI] = {
1929 .help = "virtual subnet ID",
1930 .next = NEXT(item_nvgre, NEXT_ENTRY(UNSIGNED), item_param),
1931 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_nvgre, tni)),
1935 .help = "match MPLS header",
1936 .priv = PRIV_ITEM(MPLS, sizeof(struct rte_flow_item_mpls)),
1937 .next = NEXT(item_mpls),
1940 [ITEM_MPLS_LABEL] = {
1942 .help = "MPLS label",
1943 .next = NEXT(item_mpls, NEXT_ENTRY(UNSIGNED), item_param),
1944 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_mpls,
1950 .help = "match GRE header",
1951 .priv = PRIV_ITEM(GRE, sizeof(struct rte_flow_item_gre)),
1952 .next = NEXT(item_gre),
1955 [ITEM_GRE_PROTO] = {
1957 .help = "GRE protocol type",
1958 .next = NEXT(item_gre, NEXT_ENTRY(UNSIGNED), item_param),
1959 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gre,
1962 [ITEM_GRE_C_RSVD0_VER] = {
1963 .name = "c_rsvd0_ver",
1965 "checksum (1b), undefined (1b), key bit (1b),"
1966 " sequence number (1b), reserved 0 (9b),"
1968 .next = NEXT(item_gre, NEXT_ENTRY(UNSIGNED), item_param),
1969 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gre,
1972 [ITEM_GRE_C_BIT] = {
1974 .help = "checksum bit (C)",
1975 .next = NEXT(item_gre, NEXT_ENTRY(BOOLEAN), item_param),
1976 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_gre,
1978 "\x80\x00\x00\x00")),
1980 [ITEM_GRE_S_BIT] = {
1982 .help = "sequence number bit (S)",
1983 .next = NEXT(item_gre, NEXT_ENTRY(BOOLEAN), item_param),
1984 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_gre,
1986 "\x10\x00\x00\x00")),
1988 [ITEM_GRE_K_BIT] = {
1990 .help = "key bit (K)",
1991 .next = NEXT(item_gre, NEXT_ENTRY(BOOLEAN), item_param),
1992 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_gre,
1994 "\x20\x00\x00\x00")),
1998 .help = "fuzzy pattern match, expect faster than default",
1999 .priv = PRIV_ITEM(FUZZY,
2000 sizeof(struct rte_flow_item_fuzzy)),
2001 .next = NEXT(item_fuzzy),
2004 [ITEM_FUZZY_THRESH] = {
2006 .help = "match accuracy threshold",
2007 .next = NEXT(item_fuzzy, NEXT_ENTRY(UNSIGNED), item_param),
2008 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_fuzzy,
2013 .help = "match GTP header",
2014 .priv = PRIV_ITEM(GTP, sizeof(struct rte_flow_item_gtp)),
2015 .next = NEXT(item_gtp),
2020 .help = "tunnel endpoint identifier",
2021 .next = NEXT(item_gtp, NEXT_ENTRY(UNSIGNED), item_param),
2022 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gtp, teid)),
2026 .help = "match GTP header",
2027 .priv = PRIV_ITEM(GTPC, sizeof(struct rte_flow_item_gtp)),
2028 .next = NEXT(item_gtp),
2033 .help = "match GTP header",
2034 .priv = PRIV_ITEM(GTPU, sizeof(struct rte_flow_item_gtp)),
2035 .next = NEXT(item_gtp),
2040 .help = "match GENEVE header",
2041 .priv = PRIV_ITEM(GENEVE, sizeof(struct rte_flow_item_geneve)),
2042 .next = NEXT(item_geneve),
2045 [ITEM_GENEVE_VNI] = {
2047 .help = "virtual network identifier",
2048 .next = NEXT(item_geneve, NEXT_ENTRY(UNSIGNED), item_param),
2049 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_geneve, vni)),
2051 [ITEM_GENEVE_PROTO] = {
2053 .help = "GENEVE protocol type",
2054 .next = NEXT(item_geneve, NEXT_ENTRY(UNSIGNED), item_param),
2055 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_geneve,
2058 [ITEM_VXLAN_GPE] = {
2059 .name = "vxlan-gpe",
2060 .help = "match VXLAN-GPE header",
2061 .priv = PRIV_ITEM(VXLAN_GPE,
2062 sizeof(struct rte_flow_item_vxlan_gpe)),
2063 .next = NEXT(item_vxlan_gpe),
2066 [ITEM_VXLAN_GPE_VNI] = {
2068 .help = "VXLAN-GPE identifier",
2069 .next = NEXT(item_vxlan_gpe, NEXT_ENTRY(UNSIGNED), item_param),
2070 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vxlan_gpe,
2073 [ITEM_ARP_ETH_IPV4] = {
2074 .name = "arp_eth_ipv4",
2075 .help = "match ARP header for Ethernet/IPv4",
2076 .priv = PRIV_ITEM(ARP_ETH_IPV4,
2077 sizeof(struct rte_flow_item_arp_eth_ipv4)),
2078 .next = NEXT(item_arp_eth_ipv4),
2081 [ITEM_ARP_ETH_IPV4_SHA] = {
2083 .help = "sender hardware address",
2084 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(MAC_ADDR),
2086 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
2089 [ITEM_ARP_ETH_IPV4_SPA] = {
2091 .help = "sender IPv4 address",
2092 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(IPV4_ADDR),
2094 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
2097 [ITEM_ARP_ETH_IPV4_THA] = {
2099 .help = "target hardware address",
2100 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(MAC_ADDR),
2102 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
2105 [ITEM_ARP_ETH_IPV4_TPA] = {
2107 .help = "target IPv4 address",
2108 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(IPV4_ADDR),
2110 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
2115 .help = "match presence of any IPv6 extension header",
2116 .priv = PRIV_ITEM(IPV6_EXT,
2117 sizeof(struct rte_flow_item_ipv6_ext)),
2118 .next = NEXT(item_ipv6_ext),
2121 [ITEM_IPV6_EXT_NEXT_HDR] = {
2123 .help = "next header",
2124 .next = NEXT(item_ipv6_ext, NEXT_ENTRY(UNSIGNED), item_param),
2125 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6_ext,
2130 .help = "match any ICMPv6 header",
2131 .priv = PRIV_ITEM(ICMP6, sizeof(struct rte_flow_item_icmp6)),
2132 .next = NEXT(item_icmp6),
2135 [ITEM_ICMP6_TYPE] = {
2137 .help = "ICMPv6 type",
2138 .next = NEXT(item_icmp6, NEXT_ENTRY(UNSIGNED), item_param),
2139 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6,
2142 [ITEM_ICMP6_CODE] = {
2144 .help = "ICMPv6 code",
2145 .next = NEXT(item_icmp6, NEXT_ENTRY(UNSIGNED), item_param),
2146 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6,
2149 [ITEM_ICMP6_ND_NS] = {
2150 .name = "icmp6_nd_ns",
2151 .help = "match ICMPv6 neighbor discovery solicitation",
2152 .priv = PRIV_ITEM(ICMP6_ND_NS,
2153 sizeof(struct rte_flow_item_icmp6_nd_ns)),
2154 .next = NEXT(item_icmp6_nd_ns),
2157 [ITEM_ICMP6_ND_NS_TARGET_ADDR] = {
2158 .name = "target_addr",
2159 .help = "target address",
2160 .next = NEXT(item_icmp6_nd_ns, NEXT_ENTRY(IPV6_ADDR),
2162 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6_nd_ns,
2165 [ITEM_ICMP6_ND_NA] = {
2166 .name = "icmp6_nd_na",
2167 .help = "match ICMPv6 neighbor discovery advertisement",
2168 .priv = PRIV_ITEM(ICMP6_ND_NA,
2169 sizeof(struct rte_flow_item_icmp6_nd_na)),
2170 .next = NEXT(item_icmp6_nd_na),
2173 [ITEM_ICMP6_ND_NA_TARGET_ADDR] = {
2174 .name = "target_addr",
2175 .help = "target address",
2176 .next = NEXT(item_icmp6_nd_na, NEXT_ENTRY(IPV6_ADDR),
2178 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6_nd_na,
2181 [ITEM_ICMP6_ND_OPT] = {
2182 .name = "icmp6_nd_opt",
2183 .help = "match presence of any ICMPv6 neighbor discovery"
2185 .priv = PRIV_ITEM(ICMP6_ND_OPT,
2186 sizeof(struct rte_flow_item_icmp6_nd_opt)),
2187 .next = NEXT(item_icmp6_nd_opt),
2190 [ITEM_ICMP6_ND_OPT_TYPE] = {
2192 .help = "ND option type",
2193 .next = NEXT(item_icmp6_nd_opt, NEXT_ENTRY(UNSIGNED),
2195 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6_nd_opt,
2198 [ITEM_ICMP6_ND_OPT_SLA_ETH] = {
2199 .name = "icmp6_nd_opt_sla_eth",
2200 .help = "match ICMPv6 neighbor discovery source Ethernet"
2201 " link-layer address option",
2203 (ICMP6_ND_OPT_SLA_ETH,
2204 sizeof(struct rte_flow_item_icmp6_nd_opt_sla_eth)),
2205 .next = NEXT(item_icmp6_nd_opt_sla_eth),
2208 [ITEM_ICMP6_ND_OPT_SLA_ETH_SLA] = {
2210 .help = "source Ethernet LLA",
2211 .next = NEXT(item_icmp6_nd_opt_sla_eth, NEXT_ENTRY(MAC_ADDR),
2213 .args = ARGS(ARGS_ENTRY_HTON
2214 (struct rte_flow_item_icmp6_nd_opt_sla_eth, sla)),
2216 [ITEM_ICMP6_ND_OPT_TLA_ETH] = {
2217 .name = "icmp6_nd_opt_tla_eth",
2218 .help = "match ICMPv6 neighbor discovery target Ethernet"
2219 " link-layer address option",
2221 (ICMP6_ND_OPT_TLA_ETH,
2222 sizeof(struct rte_flow_item_icmp6_nd_opt_tla_eth)),
2223 .next = NEXT(item_icmp6_nd_opt_tla_eth),
2226 [ITEM_ICMP6_ND_OPT_TLA_ETH_TLA] = {
2228 .help = "target Ethernet LLA",
2229 .next = NEXT(item_icmp6_nd_opt_tla_eth, NEXT_ENTRY(MAC_ADDR),
2231 .args = ARGS(ARGS_ENTRY_HTON
2232 (struct rte_flow_item_icmp6_nd_opt_tla_eth, tla)),
2236 .help = "match metadata header",
2237 .priv = PRIV_ITEM(META, sizeof(struct rte_flow_item_meta)),
2238 .next = NEXT(item_meta),
2241 [ITEM_META_DATA] = {
2243 .help = "metadata value",
2244 .next = NEXT(item_meta, NEXT_ENTRY(UNSIGNED), item_param),
2245 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_meta,
2246 data, "\xff\xff\xff\xff")),
2250 .help = "match GRE key",
2251 .priv = PRIV_ITEM(GRE_KEY, sizeof(rte_be32_t)),
2252 .next = NEXT(item_gre_key),
2255 [ITEM_GRE_KEY_VALUE] = {
2257 .help = "key value",
2258 .next = NEXT(item_gre_key, NEXT_ENTRY(UNSIGNED), item_param),
2259 .args = ARGS(ARG_ENTRY_HTON(rte_be32_t)),
2262 /* Validate/create actions. */
2265 .help = "submit a list of associated actions",
2266 .next = NEXT(next_action),
2271 .help = "specify next action",
2272 .next = NEXT(next_action),
2276 .help = "end list of actions",
2277 .priv = PRIV_ACTION(END, 0),
2282 .help = "no-op action",
2283 .priv = PRIV_ACTION(VOID, 0),
2284 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2287 [ACTION_PASSTHRU] = {
2289 .help = "let subsequent rule process matched packets",
2290 .priv = PRIV_ACTION(PASSTHRU, 0),
2291 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2296 .help = "redirect traffic to a given group",
2297 .priv = PRIV_ACTION(JUMP, sizeof(struct rte_flow_action_jump)),
2298 .next = NEXT(action_jump),
2301 [ACTION_JUMP_GROUP] = {
2303 .help = "group to redirect traffic to",
2304 .next = NEXT(action_jump, NEXT_ENTRY(UNSIGNED)),
2305 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_jump, group)),
2306 .call = parse_vc_conf,
2310 .help = "attach 32 bit value to packets",
2311 .priv = PRIV_ACTION(MARK, sizeof(struct rte_flow_action_mark)),
2312 .next = NEXT(action_mark),
2315 [ACTION_MARK_ID] = {
2317 .help = "32 bit value to return with packets",
2318 .next = NEXT(action_mark, NEXT_ENTRY(UNSIGNED)),
2319 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_mark, id)),
2320 .call = parse_vc_conf,
2324 .help = "flag packets",
2325 .priv = PRIV_ACTION(FLAG, 0),
2326 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2331 .help = "assign packets to a given queue index",
2332 .priv = PRIV_ACTION(QUEUE,
2333 sizeof(struct rte_flow_action_queue)),
2334 .next = NEXT(action_queue),
2337 [ACTION_QUEUE_INDEX] = {
2339 .help = "queue index to use",
2340 .next = NEXT(action_queue, NEXT_ENTRY(UNSIGNED)),
2341 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_queue, index)),
2342 .call = parse_vc_conf,
2346 .help = "drop packets (note: passthru has priority)",
2347 .priv = PRIV_ACTION(DROP, 0),
2348 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2353 .help = "enable counters for this rule",
2354 .priv = PRIV_ACTION(COUNT,
2355 sizeof(struct rte_flow_action_count)),
2356 .next = NEXT(action_count),
2359 [ACTION_COUNT_ID] = {
2360 .name = "identifier",
2361 .help = "counter identifier to use",
2362 .next = NEXT(action_count, NEXT_ENTRY(UNSIGNED)),
2363 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_count, id)),
2364 .call = parse_vc_conf,
2366 [ACTION_COUNT_SHARED] = {
2368 .help = "shared counter",
2369 .next = NEXT(action_count, NEXT_ENTRY(BOOLEAN)),
2370 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_count,
2372 .call = parse_vc_conf,
2376 .help = "spread packets among several queues",
2377 .priv = PRIV_ACTION(RSS, sizeof(struct action_rss_data)),
2378 .next = NEXT(action_rss),
2379 .call = parse_vc_action_rss,
2381 [ACTION_RSS_FUNC] = {
2383 .help = "RSS hash function to apply",
2384 .next = NEXT(action_rss,
2385 NEXT_ENTRY(ACTION_RSS_FUNC_DEFAULT,
2386 ACTION_RSS_FUNC_TOEPLITZ,
2387 ACTION_RSS_FUNC_SIMPLE_XOR)),
2389 [ACTION_RSS_FUNC_DEFAULT] = {
2391 .help = "default hash function",
2392 .call = parse_vc_action_rss_func,
2394 [ACTION_RSS_FUNC_TOEPLITZ] = {
2396 .help = "Toeplitz hash function",
2397 .call = parse_vc_action_rss_func,
2399 [ACTION_RSS_FUNC_SIMPLE_XOR] = {
2400 .name = "simple_xor",
2401 .help = "simple XOR hash function",
2402 .call = parse_vc_action_rss_func,
2404 [ACTION_RSS_LEVEL] = {
2406 .help = "encapsulation level for \"types\"",
2407 .next = NEXT(action_rss, NEXT_ENTRY(UNSIGNED)),
2408 .args = ARGS(ARGS_ENTRY_ARB
2409 (offsetof(struct action_rss_data, conf) +
2410 offsetof(struct rte_flow_action_rss, level),
2411 sizeof(((struct rte_flow_action_rss *)0)->
2414 [ACTION_RSS_TYPES] = {
2416 .help = "specific RSS hash types",
2417 .next = NEXT(action_rss, NEXT_ENTRY(ACTION_RSS_TYPE)),
2419 [ACTION_RSS_TYPE] = {
2421 .help = "RSS hash type",
2422 .call = parse_vc_action_rss_type,
2423 .comp = comp_vc_action_rss_type,
2425 [ACTION_RSS_KEY] = {
2427 .help = "RSS hash key",
2428 .next = NEXT(action_rss, NEXT_ENTRY(HEX)),
2429 .args = ARGS(ARGS_ENTRY_ARB(0, 0),
2431 (offsetof(struct action_rss_data, conf) +
2432 offsetof(struct rte_flow_action_rss, key_len),
2433 sizeof(((struct rte_flow_action_rss *)0)->
2435 ARGS_ENTRY(struct action_rss_data, key)),
2437 [ACTION_RSS_KEY_LEN] = {
2439 .help = "RSS hash key length in bytes",
2440 .next = NEXT(action_rss, NEXT_ENTRY(UNSIGNED)),
2441 .args = ARGS(ARGS_ENTRY_ARB_BOUNDED
2442 (offsetof(struct action_rss_data, conf) +
2443 offsetof(struct rte_flow_action_rss, key_len),
2444 sizeof(((struct rte_flow_action_rss *)0)->
2447 RSS_HASH_KEY_LENGTH)),
2449 [ACTION_RSS_QUEUES] = {
2451 .help = "queue indices to use",
2452 .next = NEXT(action_rss, NEXT_ENTRY(ACTION_RSS_QUEUE)),
2453 .call = parse_vc_conf,
2455 [ACTION_RSS_QUEUE] = {
2457 .help = "queue index",
2458 .call = parse_vc_action_rss_queue,
2459 .comp = comp_vc_action_rss_queue,
2463 .help = "direct traffic to physical function",
2464 .priv = PRIV_ACTION(PF, 0),
2465 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2470 .help = "direct traffic to a virtual function ID",
2471 .priv = PRIV_ACTION(VF, sizeof(struct rte_flow_action_vf)),
2472 .next = NEXT(action_vf),
2475 [ACTION_VF_ORIGINAL] = {
2477 .help = "use original VF ID if possible",
2478 .next = NEXT(action_vf, NEXT_ENTRY(BOOLEAN)),
2479 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_vf,
2481 .call = parse_vc_conf,
2486 .next = NEXT(action_vf, NEXT_ENTRY(UNSIGNED)),
2487 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_vf, id)),
2488 .call = parse_vc_conf,
2490 [ACTION_PHY_PORT] = {
2492 .help = "direct packets to physical port index",
2493 .priv = PRIV_ACTION(PHY_PORT,
2494 sizeof(struct rte_flow_action_phy_port)),
2495 .next = NEXT(action_phy_port),
2498 [ACTION_PHY_PORT_ORIGINAL] = {
2500 .help = "use original port index if possible",
2501 .next = NEXT(action_phy_port, NEXT_ENTRY(BOOLEAN)),
2502 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_phy_port,
2504 .call = parse_vc_conf,
2506 [ACTION_PHY_PORT_INDEX] = {
2508 .help = "physical port index",
2509 .next = NEXT(action_phy_port, NEXT_ENTRY(UNSIGNED)),
2510 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_phy_port,
2512 .call = parse_vc_conf,
2514 [ACTION_PORT_ID] = {
2516 .help = "direct matching traffic to a given DPDK port ID",
2517 .priv = PRIV_ACTION(PORT_ID,
2518 sizeof(struct rte_flow_action_port_id)),
2519 .next = NEXT(action_port_id),
2522 [ACTION_PORT_ID_ORIGINAL] = {
2524 .help = "use original DPDK port ID if possible",
2525 .next = NEXT(action_port_id, NEXT_ENTRY(BOOLEAN)),
2526 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_port_id,
2528 .call = parse_vc_conf,
2530 [ACTION_PORT_ID_ID] = {
2532 .help = "DPDK port ID",
2533 .next = NEXT(action_port_id, NEXT_ENTRY(UNSIGNED)),
2534 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_port_id, id)),
2535 .call = parse_vc_conf,
2539 .help = "meter the directed packets at given id",
2540 .priv = PRIV_ACTION(METER,
2541 sizeof(struct rte_flow_action_meter)),
2542 .next = NEXT(action_meter),
2545 [ACTION_METER_ID] = {
2547 .help = "meter id to use",
2548 .next = NEXT(action_meter, NEXT_ENTRY(UNSIGNED)),
2549 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_meter, mtr_id)),
2550 .call = parse_vc_conf,
2552 [ACTION_OF_SET_MPLS_TTL] = {
2553 .name = "of_set_mpls_ttl",
2554 .help = "OpenFlow's OFPAT_SET_MPLS_TTL",
2557 sizeof(struct rte_flow_action_of_set_mpls_ttl)),
2558 .next = NEXT(action_of_set_mpls_ttl),
2561 [ACTION_OF_SET_MPLS_TTL_MPLS_TTL] = {
2564 .next = NEXT(action_of_set_mpls_ttl, NEXT_ENTRY(UNSIGNED)),
2565 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_of_set_mpls_ttl,
2567 .call = parse_vc_conf,
2569 [ACTION_OF_DEC_MPLS_TTL] = {
2570 .name = "of_dec_mpls_ttl",
2571 .help = "OpenFlow's OFPAT_DEC_MPLS_TTL",
2572 .priv = PRIV_ACTION(OF_DEC_MPLS_TTL, 0),
2573 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2576 [ACTION_OF_SET_NW_TTL] = {
2577 .name = "of_set_nw_ttl",
2578 .help = "OpenFlow's OFPAT_SET_NW_TTL",
2581 sizeof(struct rte_flow_action_of_set_nw_ttl)),
2582 .next = NEXT(action_of_set_nw_ttl),
2585 [ACTION_OF_SET_NW_TTL_NW_TTL] = {
2588 .next = NEXT(action_of_set_nw_ttl, NEXT_ENTRY(UNSIGNED)),
2589 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_of_set_nw_ttl,
2591 .call = parse_vc_conf,
2593 [ACTION_OF_DEC_NW_TTL] = {
2594 .name = "of_dec_nw_ttl",
2595 .help = "OpenFlow's OFPAT_DEC_NW_TTL",
2596 .priv = PRIV_ACTION(OF_DEC_NW_TTL, 0),
2597 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2600 [ACTION_OF_COPY_TTL_OUT] = {
2601 .name = "of_copy_ttl_out",
2602 .help = "OpenFlow's OFPAT_COPY_TTL_OUT",
2603 .priv = PRIV_ACTION(OF_COPY_TTL_OUT, 0),
2604 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2607 [ACTION_OF_COPY_TTL_IN] = {
2608 .name = "of_copy_ttl_in",
2609 .help = "OpenFlow's OFPAT_COPY_TTL_IN",
2610 .priv = PRIV_ACTION(OF_COPY_TTL_IN, 0),
2611 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2614 [ACTION_OF_POP_VLAN] = {
2615 .name = "of_pop_vlan",
2616 .help = "OpenFlow's OFPAT_POP_VLAN",
2617 .priv = PRIV_ACTION(OF_POP_VLAN, 0),
2618 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2621 [ACTION_OF_PUSH_VLAN] = {
2622 .name = "of_push_vlan",
2623 .help = "OpenFlow's OFPAT_PUSH_VLAN",
2626 sizeof(struct rte_flow_action_of_push_vlan)),
2627 .next = NEXT(action_of_push_vlan),
2630 [ACTION_OF_PUSH_VLAN_ETHERTYPE] = {
2631 .name = "ethertype",
2632 .help = "EtherType",
2633 .next = NEXT(action_of_push_vlan, NEXT_ENTRY(UNSIGNED)),
2634 .args = ARGS(ARGS_ENTRY_HTON
2635 (struct rte_flow_action_of_push_vlan,
2637 .call = parse_vc_conf,
2639 [ACTION_OF_SET_VLAN_VID] = {
2640 .name = "of_set_vlan_vid",
2641 .help = "OpenFlow's OFPAT_SET_VLAN_VID",
2644 sizeof(struct rte_flow_action_of_set_vlan_vid)),
2645 .next = NEXT(action_of_set_vlan_vid),
2648 [ACTION_OF_SET_VLAN_VID_VLAN_VID] = {
2651 .next = NEXT(action_of_set_vlan_vid, NEXT_ENTRY(UNSIGNED)),
2652 .args = ARGS(ARGS_ENTRY_HTON
2653 (struct rte_flow_action_of_set_vlan_vid,
2655 .call = parse_vc_conf,
2657 [ACTION_OF_SET_VLAN_PCP] = {
2658 .name = "of_set_vlan_pcp",
2659 .help = "OpenFlow's OFPAT_SET_VLAN_PCP",
2662 sizeof(struct rte_flow_action_of_set_vlan_pcp)),
2663 .next = NEXT(action_of_set_vlan_pcp),
2666 [ACTION_OF_SET_VLAN_PCP_VLAN_PCP] = {
2668 .help = "VLAN priority",
2669 .next = NEXT(action_of_set_vlan_pcp, NEXT_ENTRY(UNSIGNED)),
2670 .args = ARGS(ARGS_ENTRY_HTON
2671 (struct rte_flow_action_of_set_vlan_pcp,
2673 .call = parse_vc_conf,
2675 [ACTION_OF_POP_MPLS] = {
2676 .name = "of_pop_mpls",
2677 .help = "OpenFlow's OFPAT_POP_MPLS",
2678 .priv = PRIV_ACTION(OF_POP_MPLS,
2679 sizeof(struct rte_flow_action_of_pop_mpls)),
2680 .next = NEXT(action_of_pop_mpls),
2683 [ACTION_OF_POP_MPLS_ETHERTYPE] = {
2684 .name = "ethertype",
2685 .help = "EtherType",
2686 .next = NEXT(action_of_pop_mpls, NEXT_ENTRY(UNSIGNED)),
2687 .args = ARGS(ARGS_ENTRY_HTON
2688 (struct rte_flow_action_of_pop_mpls,
2690 .call = parse_vc_conf,
2692 [ACTION_OF_PUSH_MPLS] = {
2693 .name = "of_push_mpls",
2694 .help = "OpenFlow's OFPAT_PUSH_MPLS",
2697 sizeof(struct rte_flow_action_of_push_mpls)),
2698 .next = NEXT(action_of_push_mpls),
2701 [ACTION_OF_PUSH_MPLS_ETHERTYPE] = {
2702 .name = "ethertype",
2703 .help = "EtherType",
2704 .next = NEXT(action_of_push_mpls, NEXT_ENTRY(UNSIGNED)),
2705 .args = ARGS(ARGS_ENTRY_HTON
2706 (struct rte_flow_action_of_push_mpls,
2708 .call = parse_vc_conf,
2710 [ACTION_VXLAN_ENCAP] = {
2711 .name = "vxlan_encap",
2712 .help = "VXLAN encapsulation, uses configuration set by \"set"
2714 .priv = PRIV_ACTION(VXLAN_ENCAP,
2715 sizeof(struct action_vxlan_encap_data)),
2716 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2717 .call = parse_vc_action_vxlan_encap,
2719 [ACTION_VXLAN_DECAP] = {
2720 .name = "vxlan_decap",
2721 .help = "Performs a decapsulation action by stripping all"
2722 " headers of the VXLAN tunnel network overlay from the"
2724 .priv = PRIV_ACTION(VXLAN_DECAP, 0),
2725 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2728 [ACTION_NVGRE_ENCAP] = {
2729 .name = "nvgre_encap",
2730 .help = "NVGRE encapsulation, uses configuration set by \"set"
2732 .priv = PRIV_ACTION(NVGRE_ENCAP,
2733 sizeof(struct action_nvgre_encap_data)),
2734 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2735 .call = parse_vc_action_nvgre_encap,
2737 [ACTION_NVGRE_DECAP] = {
2738 .name = "nvgre_decap",
2739 .help = "Performs a decapsulation action by stripping all"
2740 " headers of the NVGRE tunnel network overlay from the"
2742 .priv = PRIV_ACTION(NVGRE_DECAP, 0),
2743 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2746 [ACTION_L2_ENCAP] = {
2748 .help = "l2 encap, uses configuration set by"
2749 " \"set l2_encap\"",
2750 .priv = PRIV_ACTION(RAW_ENCAP,
2751 sizeof(struct action_raw_encap_data)),
2752 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2753 .call = parse_vc_action_l2_encap,
2755 [ACTION_L2_DECAP] = {
2757 .help = "l2 decap, uses configuration set by"
2758 " \"set l2_decap\"",
2759 .priv = PRIV_ACTION(RAW_DECAP,
2760 sizeof(struct action_raw_decap_data)),
2761 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2762 .call = parse_vc_action_l2_decap,
2764 [ACTION_MPLSOGRE_ENCAP] = {
2765 .name = "mplsogre_encap",
2766 .help = "mplsogre encapsulation, uses configuration set by"
2767 " \"set mplsogre_encap\"",
2768 .priv = PRIV_ACTION(RAW_ENCAP,
2769 sizeof(struct action_raw_encap_data)),
2770 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2771 .call = parse_vc_action_mplsogre_encap,
2773 [ACTION_MPLSOGRE_DECAP] = {
2774 .name = "mplsogre_decap",
2775 .help = "mplsogre decapsulation, uses configuration set by"
2776 " \"set mplsogre_decap\"",
2777 .priv = PRIV_ACTION(RAW_DECAP,
2778 sizeof(struct action_raw_decap_data)),
2779 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2780 .call = parse_vc_action_mplsogre_decap,
2782 [ACTION_MPLSOUDP_ENCAP] = {
2783 .name = "mplsoudp_encap",
2784 .help = "mplsoudp encapsulation, uses configuration set by"
2785 " \"set mplsoudp_encap\"",
2786 .priv = PRIV_ACTION(RAW_ENCAP,
2787 sizeof(struct action_raw_encap_data)),
2788 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2789 .call = parse_vc_action_mplsoudp_encap,
2791 [ACTION_MPLSOUDP_DECAP] = {
2792 .name = "mplsoudp_decap",
2793 .help = "mplsoudp decapsulation, uses configuration set by"
2794 " \"set mplsoudp_decap\"",
2795 .priv = PRIV_ACTION(RAW_DECAP,
2796 sizeof(struct action_raw_decap_data)),
2797 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2798 .call = parse_vc_action_mplsoudp_decap,
2800 [ACTION_SET_IPV4_SRC] = {
2801 .name = "set_ipv4_src",
2802 .help = "Set a new IPv4 source address in the outermost"
2804 .priv = PRIV_ACTION(SET_IPV4_SRC,
2805 sizeof(struct rte_flow_action_set_ipv4)),
2806 .next = NEXT(action_set_ipv4_src),
2809 [ACTION_SET_IPV4_SRC_IPV4_SRC] = {
2810 .name = "ipv4_addr",
2811 .help = "new IPv4 source address to set",
2812 .next = NEXT(action_set_ipv4_src, NEXT_ENTRY(IPV4_ADDR)),
2813 .args = ARGS(ARGS_ENTRY_HTON
2814 (struct rte_flow_action_set_ipv4, ipv4_addr)),
2815 .call = parse_vc_conf,
2817 [ACTION_SET_IPV4_DST] = {
2818 .name = "set_ipv4_dst",
2819 .help = "Set a new IPv4 destination address in the outermost"
2821 .priv = PRIV_ACTION(SET_IPV4_DST,
2822 sizeof(struct rte_flow_action_set_ipv4)),
2823 .next = NEXT(action_set_ipv4_dst),
2826 [ACTION_SET_IPV4_DST_IPV4_DST] = {
2827 .name = "ipv4_addr",
2828 .help = "new IPv4 destination address to set",
2829 .next = NEXT(action_set_ipv4_dst, NEXT_ENTRY(IPV4_ADDR)),
2830 .args = ARGS(ARGS_ENTRY_HTON
2831 (struct rte_flow_action_set_ipv4, ipv4_addr)),
2832 .call = parse_vc_conf,
2834 [ACTION_SET_IPV6_SRC] = {
2835 .name = "set_ipv6_src",
2836 .help = "Set a new IPv6 source address in the outermost"
2838 .priv = PRIV_ACTION(SET_IPV6_SRC,
2839 sizeof(struct rte_flow_action_set_ipv6)),
2840 .next = NEXT(action_set_ipv6_src),
2843 [ACTION_SET_IPV6_SRC_IPV6_SRC] = {
2844 .name = "ipv6_addr",
2845 .help = "new IPv6 source address to set",
2846 .next = NEXT(action_set_ipv6_src, NEXT_ENTRY(IPV6_ADDR)),
2847 .args = ARGS(ARGS_ENTRY_HTON
2848 (struct rte_flow_action_set_ipv6, ipv6_addr)),
2849 .call = parse_vc_conf,
2851 [ACTION_SET_IPV6_DST] = {
2852 .name = "set_ipv6_dst",
2853 .help = "Set a new IPv6 destination address in the outermost"
2855 .priv = PRIV_ACTION(SET_IPV6_DST,
2856 sizeof(struct rte_flow_action_set_ipv6)),
2857 .next = NEXT(action_set_ipv6_dst),
2860 [ACTION_SET_IPV6_DST_IPV6_DST] = {
2861 .name = "ipv6_addr",
2862 .help = "new IPv6 destination address to set",
2863 .next = NEXT(action_set_ipv6_dst, NEXT_ENTRY(IPV6_ADDR)),
2864 .args = ARGS(ARGS_ENTRY_HTON
2865 (struct rte_flow_action_set_ipv6, ipv6_addr)),
2866 .call = parse_vc_conf,
2868 [ACTION_SET_TP_SRC] = {
2869 .name = "set_tp_src",
2870 .help = "set a new source port number in the outermost"
2872 .priv = PRIV_ACTION(SET_TP_SRC,
2873 sizeof(struct rte_flow_action_set_tp)),
2874 .next = NEXT(action_set_tp_src),
2877 [ACTION_SET_TP_SRC_TP_SRC] = {
2879 .help = "new source port number to set",
2880 .next = NEXT(action_set_tp_src, NEXT_ENTRY(UNSIGNED)),
2881 .args = ARGS(ARGS_ENTRY_HTON
2882 (struct rte_flow_action_set_tp, port)),
2883 .call = parse_vc_conf,
2885 [ACTION_SET_TP_DST] = {
2886 .name = "set_tp_dst",
2887 .help = "set a new destination port number in the outermost"
2889 .priv = PRIV_ACTION(SET_TP_DST,
2890 sizeof(struct rte_flow_action_set_tp)),
2891 .next = NEXT(action_set_tp_dst),
2894 [ACTION_SET_TP_DST_TP_DST] = {
2896 .help = "new destination port number to set",
2897 .next = NEXT(action_set_tp_dst, NEXT_ENTRY(UNSIGNED)),
2898 .args = ARGS(ARGS_ENTRY_HTON
2899 (struct rte_flow_action_set_tp, port)),
2900 .call = parse_vc_conf,
2902 [ACTION_MAC_SWAP] = {
2904 .help = "Swap the source and destination MAC addresses"
2905 " in the outermost Ethernet header",
2906 .priv = PRIV_ACTION(MAC_SWAP, 0),
2907 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2910 [ACTION_DEC_TTL] = {
2912 .help = "decrease network TTL if available",
2913 .priv = PRIV_ACTION(DEC_TTL, 0),
2914 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2917 [ACTION_SET_TTL] = {
2919 .help = "set ttl value",
2920 .priv = PRIV_ACTION(SET_TTL,
2921 sizeof(struct rte_flow_action_set_ttl)),
2922 .next = NEXT(action_set_ttl),
2925 [ACTION_SET_TTL_TTL] = {
2926 .name = "ttl_value",
2927 .help = "new ttl value to set",
2928 .next = NEXT(action_set_ttl, NEXT_ENTRY(UNSIGNED)),
2929 .args = ARGS(ARGS_ENTRY_HTON
2930 (struct rte_flow_action_set_ttl, ttl_value)),
2931 .call = parse_vc_conf,
2933 [ACTION_SET_MAC_SRC] = {
2934 .name = "set_mac_src",
2935 .help = "set source mac address",
2936 .priv = PRIV_ACTION(SET_MAC_SRC,
2937 sizeof(struct rte_flow_action_set_mac)),
2938 .next = NEXT(action_set_mac_src),
2941 [ACTION_SET_MAC_SRC_MAC_SRC] = {
2943 .help = "new source mac address",
2944 .next = NEXT(action_set_mac_src, NEXT_ENTRY(MAC_ADDR)),
2945 .args = ARGS(ARGS_ENTRY_HTON
2946 (struct rte_flow_action_set_mac, mac_addr)),
2947 .call = parse_vc_conf,
2949 [ACTION_SET_MAC_DST] = {
2950 .name = "set_mac_dst",
2951 .help = "set destination mac address",
2952 .priv = PRIV_ACTION(SET_MAC_DST,
2953 sizeof(struct rte_flow_action_set_mac)),
2954 .next = NEXT(action_set_mac_dst),
2957 [ACTION_SET_MAC_DST_MAC_DST] = {
2959 .help = "new destination mac address to set",
2960 .next = NEXT(action_set_mac_dst, NEXT_ENTRY(MAC_ADDR)),
2961 .args = ARGS(ARGS_ENTRY_HTON
2962 (struct rte_flow_action_set_mac, mac_addr)),
2963 .call = parse_vc_conf,
2965 [ACTION_INC_TCP_SEQ] = {
2966 .name = "inc_tcp_seq",
2967 .help = "increase TCP sequence number",
2968 .priv = PRIV_ACTION(INC_TCP_SEQ, sizeof(rte_be32_t)),
2969 .next = NEXT(action_inc_tcp_seq),
2972 [ACTION_INC_TCP_SEQ_VALUE] = {
2974 .help = "the value to increase TCP sequence number by",
2975 .next = NEXT(action_inc_tcp_seq, NEXT_ENTRY(UNSIGNED)),
2976 .args = ARGS(ARG_ENTRY_HTON(rte_be32_t)),
2977 .call = parse_vc_conf,
2979 [ACTION_DEC_TCP_SEQ] = {
2980 .name = "dec_tcp_seq",
2981 .help = "decrease TCP sequence number",
2982 .priv = PRIV_ACTION(DEC_TCP_SEQ, sizeof(rte_be32_t)),
2983 .next = NEXT(action_dec_tcp_seq),
2986 [ACTION_DEC_TCP_SEQ_VALUE] = {
2988 .help = "the value to decrease TCP sequence number by",
2989 .next = NEXT(action_dec_tcp_seq, NEXT_ENTRY(UNSIGNED)),
2990 .args = ARGS(ARG_ENTRY_HTON(rte_be32_t)),
2991 .call = parse_vc_conf,
2993 [ACTION_INC_TCP_ACK] = {
2994 .name = "inc_tcp_ack",
2995 .help = "increase TCP acknowledgment number",
2996 .priv = PRIV_ACTION(INC_TCP_ACK, sizeof(rte_be32_t)),
2997 .next = NEXT(action_inc_tcp_ack),
3000 [ACTION_INC_TCP_ACK_VALUE] = {
3002 .help = "the value to increase TCP acknowledgment number by",
3003 .next = NEXT(action_inc_tcp_ack, NEXT_ENTRY(UNSIGNED)),
3004 .args = ARGS(ARG_ENTRY_HTON(rte_be32_t)),
3005 .call = parse_vc_conf,
3007 [ACTION_DEC_TCP_ACK] = {
3008 .name = "dec_tcp_ack",
3009 .help = "decrease TCP acknowledgment number",
3010 .priv = PRIV_ACTION(DEC_TCP_ACK, sizeof(rte_be32_t)),
3011 .next = NEXT(action_dec_tcp_ack),
3014 [ACTION_DEC_TCP_ACK_VALUE] = {
3016 .help = "the value to decrease TCP acknowledgment number by",
3017 .next = NEXT(action_dec_tcp_ack, NEXT_ENTRY(UNSIGNED)),
3018 .args = ARGS(ARG_ENTRY_HTON(rte_be32_t)),
3019 .call = parse_vc_conf,
3023 /** Remove and return last entry from argument stack. */
3024 static const struct arg *
3025 pop_args(struct context *ctx)
3027 return ctx->args_num ? ctx->args[--ctx->args_num] : NULL;
3030 /** Add entry on top of the argument stack. */
3032 push_args(struct context *ctx, const struct arg *arg)
3034 if (ctx->args_num == CTX_STACK_SIZE)
3036 ctx->args[ctx->args_num++] = arg;
3040 /** Spread value into buffer according to bit-mask. */
3042 arg_entry_bf_fill(void *dst, uintmax_t val, const struct arg *arg)
3044 uint32_t i = arg->size;
3052 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
3061 unsigned int shift = 0;
3062 uint8_t *buf = (uint8_t *)dst + arg->offset + (i -= sub);
3064 for (shift = 0; arg->mask[i] >> shift; ++shift) {
3065 if (!(arg->mask[i] & (1 << shift)))
3070 *buf &= ~(1 << shift);
3071 *buf |= (val & 1) << shift;
3079 /** Compare a string with a partial one of a given length. */
3081 strcmp_partial(const char *full, const char *partial, size_t partial_len)
3083 int r = strncmp(full, partial, partial_len);
3087 if (strlen(full) <= partial_len)
3089 return full[partial_len];
3093 * Parse a prefix length and generate a bit-mask.
3095 * Last argument (ctx->args) is retrieved to determine mask size, storage
3096 * location and whether the result must use network byte ordering.
3099 parse_prefix(struct context *ctx, const struct token *token,
3100 const char *str, unsigned int len,
3101 void *buf, unsigned int size)
3103 const struct arg *arg = pop_args(ctx);
3104 static const uint8_t conv[] = "\x00\x80\xc0\xe0\xf0\xf8\xfc\xfe\xff";
3111 /* Argument is expected. */
3115 u = strtoumax(str, &end, 0);
3116 if (errno || (size_t)(end - str) != len)
3121 extra = arg_entry_bf_fill(NULL, 0, arg);
3130 if (!arg_entry_bf_fill(ctx->object, v, arg) ||
3131 !arg_entry_bf_fill(ctx->objmask, -1, arg))
3138 if (bytes > size || bytes + !!extra > size)
3142 buf = (uint8_t *)ctx->object + arg->offset;
3143 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
3145 memset((uint8_t *)buf + size - bytes, 0xff, bytes);
3146 memset(buf, 0x00, size - bytes);
3148 ((uint8_t *)buf)[size - bytes - 1] = conv[extra];
3152 memset(buf, 0xff, bytes);
3153 memset((uint8_t *)buf + bytes, 0x00, size - bytes);
3155 ((uint8_t *)buf)[bytes] = conv[extra];
3158 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
3161 push_args(ctx, arg);
3165 /** Default parsing function for token name matching. */
3167 parse_default(struct context *ctx, const struct token *token,
3168 const char *str, unsigned int len,
3169 void *buf, unsigned int size)
3174 if (strcmp_partial(token->name, str, len))
3179 /** Parse flow command, initialize output buffer for subsequent tokens. */
3181 parse_init(struct context *ctx, const struct token *token,
3182 const char *str, unsigned int len,
3183 void *buf, unsigned int size)
3185 struct buffer *out = buf;
3187 /* Token name must match. */
3188 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
3190 /* Nothing else to do if there is no buffer. */
3193 /* Make sure buffer is large enough. */
3194 if (size < sizeof(*out))
3196 /* Initialize buffer. */
3197 memset(out, 0x00, sizeof(*out));
3198 memset((uint8_t *)out + sizeof(*out), 0x22, size - sizeof(*out));
3201 ctx->objmask = NULL;
3205 /** Parse tokens for validate/create commands. */
3207 parse_vc(struct context *ctx, const struct token *token,
3208 const char *str, unsigned int len,
3209 void *buf, unsigned int size)
3211 struct buffer *out = buf;
3215 /* Token name must match. */
3216 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
3218 /* Nothing else to do if there is no buffer. */
3221 if (!out->command) {
3222 if (ctx->curr != VALIDATE && ctx->curr != CREATE)
3224 if (sizeof(*out) > size)
3226 out->command = ctx->curr;
3229 ctx->objmask = NULL;
3230 out->args.vc.data = (uint8_t *)out + size;
3234 ctx->object = &out->args.vc.attr;
3235 ctx->objmask = NULL;
3236 switch (ctx->curr) {
3241 out->args.vc.attr.ingress = 1;
3244 out->args.vc.attr.egress = 1;
3247 out->args.vc.attr.transfer = 1;
3250 out->args.vc.pattern =
3251 (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
3253 ctx->object = out->args.vc.pattern;
3254 ctx->objmask = NULL;
3257 out->args.vc.actions =
3258 (void *)RTE_ALIGN_CEIL((uintptr_t)
3259 (out->args.vc.pattern +
3260 out->args.vc.pattern_n),
3262 ctx->object = out->args.vc.actions;
3263 ctx->objmask = NULL;
3270 if (!out->args.vc.actions) {
3271 const struct parse_item_priv *priv = token->priv;
3272 struct rte_flow_item *item =
3273 out->args.vc.pattern + out->args.vc.pattern_n;
3275 data_size = priv->size * 3; /* spec, last, mask */
3276 data = (void *)RTE_ALIGN_FLOOR((uintptr_t)
3277 (out->args.vc.data - data_size),
3279 if ((uint8_t *)item + sizeof(*item) > data)
3281 *item = (struct rte_flow_item){
3284 ++out->args.vc.pattern_n;
3286 ctx->objmask = NULL;
3288 const struct parse_action_priv *priv = token->priv;
3289 struct rte_flow_action *action =
3290 out->args.vc.actions + out->args.vc.actions_n;
3292 data_size = priv->size; /* configuration */
3293 data = (void *)RTE_ALIGN_FLOOR((uintptr_t)
3294 (out->args.vc.data - data_size),
3296 if ((uint8_t *)action + sizeof(*action) > data)
3298 *action = (struct rte_flow_action){
3300 .conf = data_size ? data : NULL,
3302 ++out->args.vc.actions_n;
3303 ctx->object = action;
3304 ctx->objmask = NULL;
3306 memset(data, 0, data_size);
3307 out->args.vc.data = data;
3308 ctx->objdata = data_size;
3312 /** Parse pattern item parameter type. */
3314 parse_vc_spec(struct context *ctx, const struct token *token,
3315 const char *str, unsigned int len,
3316 void *buf, unsigned int size)
3318 struct buffer *out = buf;
3319 struct rte_flow_item *item;
3325 /* Token name must match. */
3326 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
3328 /* Parse parameter types. */
3329 switch (ctx->curr) {
3330 static const enum index prefix[] = NEXT_ENTRY(PREFIX);
3336 case ITEM_PARAM_SPEC:
3339 case ITEM_PARAM_LAST:
3342 case ITEM_PARAM_PREFIX:
3343 /* Modify next token to expect a prefix. */
3344 if (ctx->next_num < 2)
3346 ctx->next[ctx->next_num - 2] = prefix;
3348 case ITEM_PARAM_MASK:
3354 /* Nothing else to do if there is no buffer. */
3357 if (!out->args.vc.pattern_n)
3359 item = &out->args.vc.pattern[out->args.vc.pattern_n - 1];
3360 data_size = ctx->objdata / 3; /* spec, last, mask */
3361 /* Point to selected object. */
3362 ctx->object = out->args.vc.data + (data_size * index);
3364 ctx->objmask = out->args.vc.data + (data_size * 2); /* mask */
3365 item->mask = ctx->objmask;
3367 ctx->objmask = NULL;
3368 /* Update relevant item pointer. */
3369 *((const void **[]){ &item->spec, &item->last, &item->mask })[index] =
3374 /** Parse action configuration field. */
3376 parse_vc_conf(struct context *ctx, const struct token *token,
3377 const char *str, unsigned int len,
3378 void *buf, unsigned int size)
3380 struct buffer *out = buf;
3383 /* Token name must match. */
3384 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
3386 /* Nothing else to do if there is no buffer. */
3389 /* Point to selected object. */
3390 ctx->object = out->args.vc.data;
3391 ctx->objmask = NULL;
3395 /** Parse RSS action. */
3397 parse_vc_action_rss(struct context *ctx, const struct token *token,
3398 const char *str, unsigned int len,
3399 void *buf, unsigned int size)
3401 struct buffer *out = buf;
3402 struct rte_flow_action *action;
3403 struct action_rss_data *action_rss_data;
3407 ret = parse_vc(ctx, token, str, len, buf, size);
3410 /* Nothing else to do if there is no buffer. */
3413 if (!out->args.vc.actions_n)
3415 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
3416 /* Point to selected object. */
3417 ctx->object = out->args.vc.data;
3418 ctx->objmask = NULL;
3419 /* Set up default configuration. */
3420 action_rss_data = ctx->object;
3421 *action_rss_data = (struct action_rss_data){
3422 .conf = (struct rte_flow_action_rss){
3423 .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
3426 .key_len = sizeof(action_rss_data->key),
3427 .queue_num = RTE_MIN(nb_rxq, ACTION_RSS_QUEUE_NUM),
3428 .key = action_rss_data->key,
3429 .queue = action_rss_data->queue,
3431 .key = "testpmd's default RSS hash key, "
3432 "override it for better balancing",
3435 for (i = 0; i < action_rss_data->conf.queue_num; ++i)
3436 action_rss_data->queue[i] = i;
3437 if (!port_id_is_invalid(ctx->port, DISABLED_WARN) &&
3438 ctx->port != (portid_t)RTE_PORT_ALL) {
3439 struct rte_eth_dev_info info;
3441 rte_eth_dev_info_get(ctx->port, &info);
3442 action_rss_data->conf.key_len =
3443 RTE_MIN(sizeof(action_rss_data->key),
3444 info.hash_key_size);
3446 action->conf = &action_rss_data->conf;
3451 * Parse func field for RSS action.
3453 * The RTE_ETH_HASH_FUNCTION_* value to assign is derived from the
3454 * ACTION_RSS_FUNC_* index that called this function.
3457 parse_vc_action_rss_func(struct context *ctx, const struct token *token,
3458 const char *str, unsigned int len,
3459 void *buf, unsigned int size)
3461 struct action_rss_data *action_rss_data;
3462 enum rte_eth_hash_function func;
3466 /* Token name must match. */
3467 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
3469 switch (ctx->curr) {
3470 case ACTION_RSS_FUNC_DEFAULT:
3471 func = RTE_ETH_HASH_FUNCTION_DEFAULT;
3473 case ACTION_RSS_FUNC_TOEPLITZ:
3474 func = RTE_ETH_HASH_FUNCTION_TOEPLITZ;
3476 case ACTION_RSS_FUNC_SIMPLE_XOR:
3477 func = RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
3484 action_rss_data = ctx->object;
3485 action_rss_data->conf.func = func;
3490 * Parse type field for RSS action.
3492 * Valid tokens are type field names and the "end" token.
3495 parse_vc_action_rss_type(struct context *ctx, const struct token *token,
3496 const char *str, unsigned int len,
3497 void *buf, unsigned int size)
3499 static const enum index next[] = NEXT_ENTRY(ACTION_RSS_TYPE);
3500 struct action_rss_data *action_rss_data;
3506 if (ctx->curr != ACTION_RSS_TYPE)
3508 if (!(ctx->objdata >> 16) && ctx->object) {
3509 action_rss_data = ctx->object;
3510 action_rss_data->conf.types = 0;
3512 if (!strcmp_partial("end", str, len)) {
3513 ctx->objdata &= 0xffff;
3516 for (i = 0; rss_type_table[i].str; ++i)
3517 if (!strcmp_partial(rss_type_table[i].str, str, len))
3519 if (!rss_type_table[i].str)
3521 ctx->objdata = 1 << 16 | (ctx->objdata & 0xffff);
3523 if (ctx->next_num == RTE_DIM(ctx->next))
3525 ctx->next[ctx->next_num++] = next;
3528 action_rss_data = ctx->object;
3529 action_rss_data->conf.types |= rss_type_table[i].rss_type;
3534 * Parse queue field for RSS action.
3536 * Valid tokens are queue indices and the "end" token.
3539 parse_vc_action_rss_queue(struct context *ctx, const struct token *token,
3540 const char *str, unsigned int len,
3541 void *buf, unsigned int size)
3543 static const enum index next[] = NEXT_ENTRY(ACTION_RSS_QUEUE);
3544 struct action_rss_data *action_rss_data;
3545 const struct arg *arg;
3552 if (ctx->curr != ACTION_RSS_QUEUE)
3554 i = ctx->objdata >> 16;
3555 if (!strcmp_partial("end", str, len)) {
3556 ctx->objdata &= 0xffff;
3559 if (i >= ACTION_RSS_QUEUE_NUM)
3561 arg = ARGS_ENTRY_ARB(offsetof(struct action_rss_data, queue) +
3562 i * sizeof(action_rss_data->queue[i]),
3563 sizeof(action_rss_data->queue[i]));
3564 if (push_args(ctx, arg))
3566 ret = parse_int(ctx, token, str, len, NULL, 0);
3572 ctx->objdata = i << 16 | (ctx->objdata & 0xffff);
3574 if (ctx->next_num == RTE_DIM(ctx->next))
3576 ctx->next[ctx->next_num++] = next;
3580 action_rss_data = ctx->object;
3581 action_rss_data->conf.queue_num = i;
3582 action_rss_data->conf.queue = i ? action_rss_data->queue : NULL;
3586 /** Parse VXLAN encap action. */
3588 parse_vc_action_vxlan_encap(struct context *ctx, const struct token *token,
3589 const char *str, unsigned int len,
3590 void *buf, unsigned int size)
3592 struct buffer *out = buf;
3593 struct rte_flow_action *action;
3594 struct action_vxlan_encap_data *action_vxlan_encap_data;
3597 ret = parse_vc(ctx, token, str, len, buf, size);
3600 /* Nothing else to do if there is no buffer. */
3603 if (!out->args.vc.actions_n)
3605 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
3606 /* Point to selected object. */
3607 ctx->object = out->args.vc.data;
3608 ctx->objmask = NULL;
3609 /* Set up default configuration. */
3610 action_vxlan_encap_data = ctx->object;
3611 *action_vxlan_encap_data = (struct action_vxlan_encap_data){
3612 .conf = (struct rte_flow_action_vxlan_encap){
3613 .definition = action_vxlan_encap_data->items,
3617 .type = RTE_FLOW_ITEM_TYPE_ETH,
3618 .spec = &action_vxlan_encap_data->item_eth,
3619 .mask = &rte_flow_item_eth_mask,
3622 .type = RTE_FLOW_ITEM_TYPE_VLAN,
3623 .spec = &action_vxlan_encap_data->item_vlan,
3624 .mask = &rte_flow_item_vlan_mask,
3627 .type = RTE_FLOW_ITEM_TYPE_IPV4,
3628 .spec = &action_vxlan_encap_data->item_ipv4,
3629 .mask = &rte_flow_item_ipv4_mask,
3632 .type = RTE_FLOW_ITEM_TYPE_UDP,
3633 .spec = &action_vxlan_encap_data->item_udp,
3634 .mask = &rte_flow_item_udp_mask,
3637 .type = RTE_FLOW_ITEM_TYPE_VXLAN,
3638 .spec = &action_vxlan_encap_data->item_vxlan,
3639 .mask = &rte_flow_item_vxlan_mask,
3642 .type = RTE_FLOW_ITEM_TYPE_END,
3647 .tci = vxlan_encap_conf.vlan_tci,
3651 .src_addr = vxlan_encap_conf.ipv4_src,
3652 .dst_addr = vxlan_encap_conf.ipv4_dst,
3655 .src_port = vxlan_encap_conf.udp_src,
3656 .dst_port = vxlan_encap_conf.udp_dst,
3658 .item_vxlan.flags = 0,
3660 memcpy(action_vxlan_encap_data->item_eth.dst.addr_bytes,
3661 vxlan_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
3662 memcpy(action_vxlan_encap_data->item_eth.src.addr_bytes,
3663 vxlan_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
3664 if (!vxlan_encap_conf.select_ipv4) {
3665 memcpy(&action_vxlan_encap_data->item_ipv6.hdr.src_addr,
3666 &vxlan_encap_conf.ipv6_src,
3667 sizeof(vxlan_encap_conf.ipv6_src));
3668 memcpy(&action_vxlan_encap_data->item_ipv6.hdr.dst_addr,
3669 &vxlan_encap_conf.ipv6_dst,
3670 sizeof(vxlan_encap_conf.ipv6_dst));
3671 action_vxlan_encap_data->items[2] = (struct rte_flow_item){
3672 .type = RTE_FLOW_ITEM_TYPE_IPV6,
3673 .spec = &action_vxlan_encap_data->item_ipv6,
3674 .mask = &rte_flow_item_ipv6_mask,
3677 if (!vxlan_encap_conf.select_vlan)
3678 action_vxlan_encap_data->items[1].type =
3679 RTE_FLOW_ITEM_TYPE_VOID;
3680 if (vxlan_encap_conf.select_tos_ttl) {
3681 if (vxlan_encap_conf.select_ipv4) {
3682 static struct rte_flow_item_ipv4 ipv4_mask_tos;
3684 memcpy(&ipv4_mask_tos, &rte_flow_item_ipv4_mask,
3685 sizeof(ipv4_mask_tos));
3686 ipv4_mask_tos.hdr.type_of_service = 0xff;
3687 ipv4_mask_tos.hdr.time_to_live = 0xff;
3688 action_vxlan_encap_data->item_ipv4.hdr.type_of_service =
3689 vxlan_encap_conf.ip_tos;
3690 action_vxlan_encap_data->item_ipv4.hdr.time_to_live =
3691 vxlan_encap_conf.ip_ttl;
3692 action_vxlan_encap_data->items[2].mask =
3695 static struct rte_flow_item_ipv6 ipv6_mask_tos;
3697 memcpy(&ipv6_mask_tos, &rte_flow_item_ipv6_mask,
3698 sizeof(ipv6_mask_tos));
3699 ipv6_mask_tos.hdr.vtc_flow |=
3700 RTE_BE32(0xfful << RTE_IPV6_HDR_TC_SHIFT);
3701 ipv6_mask_tos.hdr.hop_limits = 0xff;
3702 action_vxlan_encap_data->item_ipv6.hdr.vtc_flow |=
3704 ((uint32_t)vxlan_encap_conf.ip_tos <<
3705 RTE_IPV6_HDR_TC_SHIFT);
3706 action_vxlan_encap_data->item_ipv6.hdr.hop_limits =
3707 vxlan_encap_conf.ip_ttl;
3708 action_vxlan_encap_data->items[2].mask =
3712 memcpy(action_vxlan_encap_data->item_vxlan.vni, vxlan_encap_conf.vni,
3713 RTE_DIM(vxlan_encap_conf.vni));
3714 action->conf = &action_vxlan_encap_data->conf;
3718 /** Parse NVGRE encap action. */
3720 parse_vc_action_nvgre_encap(struct context *ctx, const struct token *token,
3721 const char *str, unsigned int len,
3722 void *buf, unsigned int size)
3724 struct buffer *out = buf;
3725 struct rte_flow_action *action;
3726 struct action_nvgre_encap_data *action_nvgre_encap_data;
3729 ret = parse_vc(ctx, token, str, len, buf, size);
3732 /* Nothing else to do if there is no buffer. */
3735 if (!out->args.vc.actions_n)
3737 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
3738 /* Point to selected object. */
3739 ctx->object = out->args.vc.data;
3740 ctx->objmask = NULL;
3741 /* Set up default configuration. */
3742 action_nvgre_encap_data = ctx->object;
3743 *action_nvgre_encap_data = (struct action_nvgre_encap_data){
3744 .conf = (struct rte_flow_action_nvgre_encap){
3745 .definition = action_nvgre_encap_data->items,
3749 .type = RTE_FLOW_ITEM_TYPE_ETH,
3750 .spec = &action_nvgre_encap_data->item_eth,
3751 .mask = &rte_flow_item_eth_mask,
3754 .type = RTE_FLOW_ITEM_TYPE_VLAN,
3755 .spec = &action_nvgre_encap_data->item_vlan,
3756 .mask = &rte_flow_item_vlan_mask,
3759 .type = RTE_FLOW_ITEM_TYPE_IPV4,
3760 .spec = &action_nvgre_encap_data->item_ipv4,
3761 .mask = &rte_flow_item_ipv4_mask,
3764 .type = RTE_FLOW_ITEM_TYPE_NVGRE,
3765 .spec = &action_nvgre_encap_data->item_nvgre,
3766 .mask = &rte_flow_item_nvgre_mask,
3769 .type = RTE_FLOW_ITEM_TYPE_END,
3774 .tci = nvgre_encap_conf.vlan_tci,
3778 .src_addr = nvgre_encap_conf.ipv4_src,
3779 .dst_addr = nvgre_encap_conf.ipv4_dst,
3781 .item_nvgre.flow_id = 0,
3783 memcpy(action_nvgre_encap_data->item_eth.dst.addr_bytes,
3784 nvgre_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
3785 memcpy(action_nvgre_encap_data->item_eth.src.addr_bytes,
3786 nvgre_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
3787 if (!nvgre_encap_conf.select_ipv4) {
3788 memcpy(&action_nvgre_encap_data->item_ipv6.hdr.src_addr,
3789 &nvgre_encap_conf.ipv6_src,
3790 sizeof(nvgre_encap_conf.ipv6_src));
3791 memcpy(&action_nvgre_encap_data->item_ipv6.hdr.dst_addr,
3792 &nvgre_encap_conf.ipv6_dst,
3793 sizeof(nvgre_encap_conf.ipv6_dst));
3794 action_nvgre_encap_data->items[2] = (struct rte_flow_item){
3795 .type = RTE_FLOW_ITEM_TYPE_IPV6,
3796 .spec = &action_nvgre_encap_data->item_ipv6,
3797 .mask = &rte_flow_item_ipv6_mask,
3800 if (!nvgre_encap_conf.select_vlan)
3801 action_nvgre_encap_data->items[1].type =
3802 RTE_FLOW_ITEM_TYPE_VOID;
3803 memcpy(action_nvgre_encap_data->item_nvgre.tni, nvgre_encap_conf.tni,
3804 RTE_DIM(nvgre_encap_conf.tni));
3805 action->conf = &action_nvgre_encap_data->conf;
3809 /** Parse l2 encap action. */
3811 parse_vc_action_l2_encap(struct context *ctx, const struct token *token,
3812 const char *str, unsigned int len,
3813 void *buf, unsigned int size)
3815 struct buffer *out = buf;
3816 struct rte_flow_action *action;
3817 struct action_raw_encap_data *action_encap_data;
3818 struct rte_flow_item_eth eth = { .type = 0, };
3819 struct rte_flow_item_vlan vlan = {
3820 .tci = mplsoudp_encap_conf.vlan_tci,
3826 ret = parse_vc(ctx, token, str, len, buf, size);
3829 /* Nothing else to do if there is no buffer. */
3832 if (!out->args.vc.actions_n)
3834 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
3835 /* Point to selected object. */
3836 ctx->object = out->args.vc.data;
3837 ctx->objmask = NULL;
3838 /* Copy the headers to the buffer. */
3839 action_encap_data = ctx->object;
3840 *action_encap_data = (struct action_raw_encap_data) {
3841 .conf = (struct rte_flow_action_raw_encap){
3842 .data = action_encap_data->data,
3846 header = action_encap_data->data;
3847 if (l2_encap_conf.select_vlan)
3848 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
3849 else if (l2_encap_conf.select_ipv4)
3850 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
3852 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
3853 memcpy(eth.dst.addr_bytes,
3854 l2_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
3855 memcpy(eth.src.addr_bytes,
3856 l2_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
3857 memcpy(header, ð, sizeof(eth));
3858 header += sizeof(eth);
3859 if (l2_encap_conf.select_vlan) {
3860 if (l2_encap_conf.select_ipv4)
3861 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
3863 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
3864 memcpy(header, &vlan, sizeof(vlan));
3865 header += sizeof(vlan);
3867 action_encap_data->conf.size = header -
3868 action_encap_data->data;
3869 action->conf = &action_encap_data->conf;
3873 /** Parse l2 decap action. */
3875 parse_vc_action_l2_decap(struct context *ctx, const struct token *token,
3876 const char *str, unsigned int len,
3877 void *buf, unsigned int size)
3879 struct buffer *out = buf;
3880 struct rte_flow_action *action;
3881 struct action_raw_decap_data *action_decap_data;
3882 struct rte_flow_item_eth eth = { .type = 0, };
3883 struct rte_flow_item_vlan vlan = {
3884 .tci = mplsoudp_encap_conf.vlan_tci,
3890 ret = parse_vc(ctx, token, str, len, buf, size);
3893 /* Nothing else to do if there is no buffer. */
3896 if (!out->args.vc.actions_n)
3898 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
3899 /* Point to selected object. */
3900 ctx->object = out->args.vc.data;
3901 ctx->objmask = NULL;
3902 /* Copy the headers to the buffer. */
3903 action_decap_data = ctx->object;
3904 *action_decap_data = (struct action_raw_decap_data) {
3905 .conf = (struct rte_flow_action_raw_decap){
3906 .data = action_decap_data->data,
3910 header = action_decap_data->data;
3911 if (l2_decap_conf.select_vlan)
3912 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
3913 memcpy(header, ð, sizeof(eth));
3914 header += sizeof(eth);
3915 if (l2_decap_conf.select_vlan) {
3916 memcpy(header, &vlan, sizeof(vlan));
3917 header += sizeof(vlan);
3919 action_decap_data->conf.size = header -
3920 action_decap_data->data;
3921 action->conf = &action_decap_data->conf;
3925 #define ETHER_TYPE_MPLS_UNICAST 0x8847
3927 /** Parse MPLSOGRE encap action. */
3929 parse_vc_action_mplsogre_encap(struct context *ctx, const struct token *token,
3930 const char *str, unsigned int len,
3931 void *buf, unsigned int size)
3933 struct buffer *out = buf;
3934 struct rte_flow_action *action;
3935 struct action_raw_encap_data *action_encap_data;
3936 struct rte_flow_item_eth eth = { .type = 0, };
3937 struct rte_flow_item_vlan vlan = {
3938 .tci = mplsogre_encap_conf.vlan_tci,
3941 struct rte_flow_item_ipv4 ipv4 = {
3943 .src_addr = mplsogre_encap_conf.ipv4_src,
3944 .dst_addr = mplsogre_encap_conf.ipv4_dst,
3945 .next_proto_id = IPPROTO_GRE,
3946 .version_ihl = RTE_IPV4_VHL_DEF,
3947 .time_to_live = IPDEFTTL,
3950 struct rte_flow_item_ipv6 ipv6 = {
3952 .proto = IPPROTO_GRE,
3953 .hop_limits = IPDEFTTL,
3956 struct rte_flow_item_gre gre = {
3957 .protocol = rte_cpu_to_be_16(ETHER_TYPE_MPLS_UNICAST),
3959 struct rte_flow_item_mpls mpls;
3963 ret = parse_vc(ctx, token, str, len, buf, size);
3966 /* Nothing else to do if there is no buffer. */
3969 if (!out->args.vc.actions_n)
3971 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
3972 /* Point to selected object. */
3973 ctx->object = out->args.vc.data;
3974 ctx->objmask = NULL;
3975 /* Copy the headers to the buffer. */
3976 action_encap_data = ctx->object;
3977 *action_encap_data = (struct action_raw_encap_data) {
3978 .conf = (struct rte_flow_action_raw_encap){
3979 .data = action_encap_data->data,
3984 header = action_encap_data->data;
3985 if (mplsogre_encap_conf.select_vlan)
3986 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
3987 else if (mplsogre_encap_conf.select_ipv4)
3988 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
3990 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
3991 memcpy(eth.dst.addr_bytes,
3992 mplsogre_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
3993 memcpy(eth.src.addr_bytes,
3994 mplsogre_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
3995 memcpy(header, ð, sizeof(eth));
3996 header += sizeof(eth);
3997 if (mplsogre_encap_conf.select_vlan) {
3998 if (mplsogre_encap_conf.select_ipv4)
3999 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4001 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4002 memcpy(header, &vlan, sizeof(vlan));
4003 header += sizeof(vlan);
4005 if (mplsogre_encap_conf.select_ipv4) {
4006 memcpy(header, &ipv4, sizeof(ipv4));
4007 header += sizeof(ipv4);
4009 memcpy(&ipv6.hdr.src_addr,
4010 &mplsogre_encap_conf.ipv6_src,
4011 sizeof(mplsogre_encap_conf.ipv6_src));
4012 memcpy(&ipv6.hdr.dst_addr,
4013 &mplsogre_encap_conf.ipv6_dst,
4014 sizeof(mplsogre_encap_conf.ipv6_dst));
4015 memcpy(header, &ipv6, sizeof(ipv6));
4016 header += sizeof(ipv6);
4018 memcpy(header, &gre, sizeof(gre));
4019 header += sizeof(gre);
4020 memcpy(mpls.label_tc_s, mplsogre_encap_conf.label,
4021 RTE_DIM(mplsogre_encap_conf.label));
4022 mpls.label_tc_s[2] |= 0x1;
4023 memcpy(header, &mpls, sizeof(mpls));
4024 header += sizeof(mpls);
4025 action_encap_data->conf.size = header -
4026 action_encap_data->data;
4027 action->conf = &action_encap_data->conf;
4031 /** Parse MPLSOGRE decap action. */
4033 parse_vc_action_mplsogre_decap(struct context *ctx, const struct token *token,
4034 const char *str, unsigned int len,
4035 void *buf, unsigned int size)
4037 struct buffer *out = buf;
4038 struct rte_flow_action *action;
4039 struct action_raw_decap_data *action_decap_data;
4040 struct rte_flow_item_eth eth = { .type = 0, };
4041 struct rte_flow_item_vlan vlan = {.tci = 0};
4042 struct rte_flow_item_ipv4 ipv4 = {
4044 .next_proto_id = IPPROTO_GRE,
4047 struct rte_flow_item_ipv6 ipv6 = {
4049 .proto = IPPROTO_GRE,
4052 struct rte_flow_item_gre gre = {
4053 .protocol = rte_cpu_to_be_16(ETHER_TYPE_MPLS_UNICAST),
4055 struct rte_flow_item_mpls mpls;
4059 ret = parse_vc(ctx, token, str, len, buf, size);
4062 /* Nothing else to do if there is no buffer. */
4065 if (!out->args.vc.actions_n)
4067 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4068 /* Point to selected object. */
4069 ctx->object = out->args.vc.data;
4070 ctx->objmask = NULL;
4071 /* Copy the headers to the buffer. */
4072 action_decap_data = ctx->object;
4073 *action_decap_data = (struct action_raw_decap_data) {
4074 .conf = (struct rte_flow_action_raw_decap){
4075 .data = action_decap_data->data,
4079 header = action_decap_data->data;
4080 if (mplsogre_decap_conf.select_vlan)
4081 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
4082 else if (mplsogre_encap_conf.select_ipv4)
4083 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4085 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4086 memcpy(eth.dst.addr_bytes,
4087 mplsogre_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
4088 memcpy(eth.src.addr_bytes,
4089 mplsogre_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
4090 memcpy(header, ð, sizeof(eth));
4091 header += sizeof(eth);
4092 if (mplsogre_encap_conf.select_vlan) {
4093 if (mplsogre_encap_conf.select_ipv4)
4094 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4096 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4097 memcpy(header, &vlan, sizeof(vlan));
4098 header += sizeof(vlan);
4100 if (mplsogre_encap_conf.select_ipv4) {
4101 memcpy(header, &ipv4, sizeof(ipv4));
4102 header += sizeof(ipv4);
4104 memcpy(header, &ipv6, sizeof(ipv6));
4105 header += sizeof(ipv6);
4107 memcpy(header, &gre, sizeof(gre));
4108 header += sizeof(gre);
4109 memset(&mpls, 0, sizeof(mpls));
4110 memcpy(header, &mpls, sizeof(mpls));
4111 header += sizeof(mpls);
4112 action_decap_data->conf.size = header -
4113 action_decap_data->data;
4114 action->conf = &action_decap_data->conf;
4118 /** Parse MPLSOUDP encap action. */
4120 parse_vc_action_mplsoudp_encap(struct context *ctx, const struct token *token,
4121 const char *str, unsigned int len,
4122 void *buf, unsigned int size)
4124 struct buffer *out = buf;
4125 struct rte_flow_action *action;
4126 struct action_raw_encap_data *action_encap_data;
4127 struct rte_flow_item_eth eth = { .type = 0, };
4128 struct rte_flow_item_vlan vlan = {
4129 .tci = mplsoudp_encap_conf.vlan_tci,
4132 struct rte_flow_item_ipv4 ipv4 = {
4134 .src_addr = mplsoudp_encap_conf.ipv4_src,
4135 .dst_addr = mplsoudp_encap_conf.ipv4_dst,
4136 .next_proto_id = IPPROTO_UDP,
4137 .version_ihl = RTE_IPV4_VHL_DEF,
4138 .time_to_live = IPDEFTTL,
4141 struct rte_flow_item_ipv6 ipv6 = {
4143 .proto = IPPROTO_UDP,
4144 .hop_limits = IPDEFTTL,
4147 struct rte_flow_item_udp udp = {
4149 .src_port = mplsoudp_encap_conf.udp_src,
4150 .dst_port = mplsoudp_encap_conf.udp_dst,
4153 struct rte_flow_item_mpls mpls;
4157 ret = parse_vc(ctx, token, str, len, buf, size);
4160 /* Nothing else to do if there is no buffer. */
4163 if (!out->args.vc.actions_n)
4165 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4166 /* Point to selected object. */
4167 ctx->object = out->args.vc.data;
4168 ctx->objmask = NULL;
4169 /* Copy the headers to the buffer. */
4170 action_encap_data = ctx->object;
4171 *action_encap_data = (struct action_raw_encap_data) {
4172 .conf = (struct rte_flow_action_raw_encap){
4173 .data = action_encap_data->data,
4178 header = action_encap_data->data;
4179 if (mplsoudp_encap_conf.select_vlan)
4180 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
4181 else if (mplsoudp_encap_conf.select_ipv4)
4182 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4184 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4185 memcpy(eth.dst.addr_bytes,
4186 mplsoudp_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
4187 memcpy(eth.src.addr_bytes,
4188 mplsoudp_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
4189 memcpy(header, ð, sizeof(eth));
4190 header += sizeof(eth);
4191 if (mplsoudp_encap_conf.select_vlan) {
4192 if (mplsoudp_encap_conf.select_ipv4)
4193 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4195 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4196 memcpy(header, &vlan, sizeof(vlan));
4197 header += sizeof(vlan);
4199 if (mplsoudp_encap_conf.select_ipv4) {
4200 memcpy(header, &ipv4, sizeof(ipv4));
4201 header += sizeof(ipv4);
4203 memcpy(&ipv6.hdr.src_addr,
4204 &mplsoudp_encap_conf.ipv6_src,
4205 sizeof(mplsoudp_encap_conf.ipv6_src));
4206 memcpy(&ipv6.hdr.dst_addr,
4207 &mplsoudp_encap_conf.ipv6_dst,
4208 sizeof(mplsoudp_encap_conf.ipv6_dst));
4209 memcpy(header, &ipv6, sizeof(ipv6));
4210 header += sizeof(ipv6);
4212 memcpy(header, &udp, sizeof(udp));
4213 header += sizeof(udp);
4214 memcpy(mpls.label_tc_s, mplsoudp_encap_conf.label,
4215 RTE_DIM(mplsoudp_encap_conf.label));
4216 mpls.label_tc_s[2] |= 0x1;
4217 memcpy(header, &mpls, sizeof(mpls));
4218 header += sizeof(mpls);
4219 action_encap_data->conf.size = header -
4220 action_encap_data->data;
4221 action->conf = &action_encap_data->conf;
4225 /** Parse MPLSOUDP decap action. */
4227 parse_vc_action_mplsoudp_decap(struct context *ctx, const struct token *token,
4228 const char *str, unsigned int len,
4229 void *buf, unsigned int size)
4231 struct buffer *out = buf;
4232 struct rte_flow_action *action;
4233 struct action_raw_decap_data *action_decap_data;
4234 struct rte_flow_item_eth eth = { .type = 0, };
4235 struct rte_flow_item_vlan vlan = {.tci = 0};
4236 struct rte_flow_item_ipv4 ipv4 = {
4238 .next_proto_id = IPPROTO_UDP,
4241 struct rte_flow_item_ipv6 ipv6 = {
4243 .proto = IPPROTO_UDP,
4246 struct rte_flow_item_udp udp = {
4248 .dst_port = rte_cpu_to_be_16(6635),
4251 struct rte_flow_item_mpls mpls;
4255 ret = parse_vc(ctx, token, str, len, buf, size);
4258 /* Nothing else to do if there is no buffer. */
4261 if (!out->args.vc.actions_n)
4263 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4264 /* Point to selected object. */
4265 ctx->object = out->args.vc.data;
4266 ctx->objmask = NULL;
4267 /* Copy the headers to the buffer. */
4268 action_decap_data = ctx->object;
4269 *action_decap_data = (struct action_raw_decap_data) {
4270 .conf = (struct rte_flow_action_raw_decap){
4271 .data = action_decap_data->data,
4275 header = action_decap_data->data;
4276 if (mplsoudp_decap_conf.select_vlan)
4277 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
4278 else if (mplsoudp_encap_conf.select_ipv4)
4279 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4281 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4282 memcpy(eth.dst.addr_bytes,
4283 mplsoudp_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
4284 memcpy(eth.src.addr_bytes,
4285 mplsoudp_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
4286 memcpy(header, ð, sizeof(eth));
4287 header += sizeof(eth);
4288 if (mplsoudp_encap_conf.select_vlan) {
4289 if (mplsoudp_encap_conf.select_ipv4)
4290 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4292 vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4293 memcpy(header, &vlan, sizeof(vlan));
4294 header += sizeof(vlan);
4296 if (mplsoudp_encap_conf.select_ipv4) {
4297 memcpy(header, &ipv4, sizeof(ipv4));
4298 header += sizeof(ipv4);
4300 memcpy(header, &ipv6, sizeof(ipv6));
4301 header += sizeof(ipv6);
4303 memcpy(header, &udp, sizeof(udp));
4304 header += sizeof(udp);
4305 memset(&mpls, 0, sizeof(mpls));
4306 memcpy(header, &mpls, sizeof(mpls));
4307 header += sizeof(mpls);
4308 action_decap_data->conf.size = header -
4309 action_decap_data->data;
4310 action->conf = &action_decap_data->conf;
4314 /** Parse tokens for destroy command. */
4316 parse_destroy(struct context *ctx, const struct token *token,
4317 const char *str, unsigned int len,
4318 void *buf, unsigned int size)
4320 struct buffer *out = buf;
4322 /* Token name must match. */
4323 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
4325 /* Nothing else to do if there is no buffer. */
4328 if (!out->command) {
4329 if (ctx->curr != DESTROY)
4331 if (sizeof(*out) > size)
4333 out->command = ctx->curr;
4336 ctx->objmask = NULL;
4337 out->args.destroy.rule =
4338 (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
4342 if (((uint8_t *)(out->args.destroy.rule + out->args.destroy.rule_n) +
4343 sizeof(*out->args.destroy.rule)) > (uint8_t *)out + size)
4346 ctx->object = out->args.destroy.rule + out->args.destroy.rule_n++;
4347 ctx->objmask = NULL;
4351 /** Parse tokens for flush command. */
4353 parse_flush(struct context *ctx, const struct token *token,
4354 const char *str, unsigned int len,
4355 void *buf, unsigned int size)
4357 struct buffer *out = buf;
4359 /* Token name must match. */
4360 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
4362 /* Nothing else to do if there is no buffer. */
4365 if (!out->command) {
4366 if (ctx->curr != FLUSH)
4368 if (sizeof(*out) > size)
4370 out->command = ctx->curr;
4373 ctx->objmask = NULL;
4378 /** Parse tokens for query command. */
4380 parse_query(struct context *ctx, const struct token *token,
4381 const char *str, unsigned int len,
4382 void *buf, unsigned int size)
4384 struct buffer *out = buf;
4386 /* Token name must match. */
4387 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
4389 /* Nothing else to do if there is no buffer. */
4392 if (!out->command) {
4393 if (ctx->curr != QUERY)
4395 if (sizeof(*out) > size)
4397 out->command = ctx->curr;
4400 ctx->objmask = NULL;
4405 /** Parse action names. */
4407 parse_action(struct context *ctx, const struct token *token,
4408 const char *str, unsigned int len,
4409 void *buf, unsigned int size)
4411 struct buffer *out = buf;
4412 const struct arg *arg = pop_args(ctx);
4416 /* Argument is expected. */
4419 /* Parse action name. */
4420 for (i = 0; next_action[i]; ++i) {
4421 const struct parse_action_priv *priv;
4423 token = &token_list[next_action[i]];
4424 if (strcmp_partial(token->name, str, len))
4430 memcpy((uint8_t *)ctx->object + arg->offset,
4436 push_args(ctx, arg);
4440 /** Parse tokens for list command. */
4442 parse_list(struct context *ctx, const struct token *token,
4443 const char *str, unsigned int len,
4444 void *buf, unsigned int size)
4446 struct buffer *out = buf;
4448 /* Token name must match. */
4449 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
4451 /* Nothing else to do if there is no buffer. */
4454 if (!out->command) {
4455 if (ctx->curr != LIST)
4457 if (sizeof(*out) > size)
4459 out->command = ctx->curr;
4462 ctx->objmask = NULL;
4463 out->args.list.group =
4464 (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
4468 if (((uint8_t *)(out->args.list.group + out->args.list.group_n) +
4469 sizeof(*out->args.list.group)) > (uint8_t *)out + size)
4472 ctx->object = out->args.list.group + out->args.list.group_n++;
4473 ctx->objmask = NULL;
4477 /** Parse tokens for isolate command. */
4479 parse_isolate(struct context *ctx, const struct token *token,
4480 const char *str, unsigned int len,
4481 void *buf, unsigned int size)
4483 struct buffer *out = buf;
4485 /* Token name must match. */
4486 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
4488 /* Nothing else to do if there is no buffer. */
4491 if (!out->command) {
4492 if (ctx->curr != ISOLATE)
4494 if (sizeof(*out) > size)
4496 out->command = ctx->curr;
4499 ctx->objmask = NULL;
4505 * Parse signed/unsigned integers 8 to 64-bit long.
4507 * Last argument (ctx->args) is retrieved to determine integer type and
4511 parse_int(struct context *ctx, const struct token *token,
4512 const char *str, unsigned int len,
4513 void *buf, unsigned int size)
4515 const struct arg *arg = pop_args(ctx);
4520 /* Argument is expected. */
4525 (uintmax_t)strtoimax(str, &end, 0) :
4526 strtoumax(str, &end, 0);
4527 if (errno || (size_t)(end - str) != len)
4530 ((arg->sign && ((intmax_t)u < (intmax_t)arg->min ||
4531 (intmax_t)u > (intmax_t)arg->max)) ||
4532 (!arg->sign && (u < arg->min || u > arg->max))))
4537 if (!arg_entry_bf_fill(ctx->object, u, arg) ||
4538 !arg_entry_bf_fill(ctx->objmask, -1, arg))
4542 buf = (uint8_t *)ctx->object + arg->offset;
4544 if (u > RTE_LEN2MASK(size * CHAR_BIT, uint64_t))
4548 case sizeof(uint8_t):
4549 *(uint8_t *)buf = u;
4551 case sizeof(uint16_t):
4552 *(uint16_t *)buf = arg->hton ? rte_cpu_to_be_16(u) : u;
4554 case sizeof(uint8_t [3]):
4555 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
4557 ((uint8_t *)buf)[0] = u;
4558 ((uint8_t *)buf)[1] = u >> 8;
4559 ((uint8_t *)buf)[2] = u >> 16;
4563 ((uint8_t *)buf)[0] = u >> 16;
4564 ((uint8_t *)buf)[1] = u >> 8;
4565 ((uint8_t *)buf)[2] = u;
4567 case sizeof(uint32_t):
4568 *(uint32_t *)buf = arg->hton ? rte_cpu_to_be_32(u) : u;
4570 case sizeof(uint64_t):
4571 *(uint64_t *)buf = arg->hton ? rte_cpu_to_be_64(u) : u;
4576 if (ctx->objmask && buf != (uint8_t *)ctx->objmask + arg->offset) {
4578 buf = (uint8_t *)ctx->objmask + arg->offset;
4583 push_args(ctx, arg);
4590 * Three arguments (ctx->args) are retrieved from the stack to store data,
4591 * its actual length and address (in that order).
4594 parse_string(struct context *ctx, const struct token *token,
4595 const char *str, unsigned int len,
4596 void *buf, unsigned int size)
4598 const struct arg *arg_data = pop_args(ctx);
4599 const struct arg *arg_len = pop_args(ctx);
4600 const struct arg *arg_addr = pop_args(ctx);
4601 char tmp[16]; /* Ought to be enough. */
4604 /* Arguments are expected. */
4608 push_args(ctx, arg_data);
4612 push_args(ctx, arg_len);
4613 push_args(ctx, arg_data);
4616 size = arg_data->size;
4617 /* Bit-mask fill is not supported. */
4618 if (arg_data->mask || size < len)
4622 /* Let parse_int() fill length information first. */
4623 ret = snprintf(tmp, sizeof(tmp), "%u", len);
4626 push_args(ctx, arg_len);
4627 ret = parse_int(ctx, token, tmp, ret, NULL, 0);
4632 buf = (uint8_t *)ctx->object + arg_data->offset;
4633 /* Output buffer is not necessarily NUL-terminated. */
4634 memcpy(buf, str, len);
4635 memset((uint8_t *)buf + len, 0x00, size - len);
4637 memset((uint8_t *)ctx->objmask + arg_data->offset, 0xff, len);
4638 /* Save address if requested. */
4639 if (arg_addr->size) {
4640 memcpy((uint8_t *)ctx->object + arg_addr->offset,
4642 (uint8_t *)ctx->object + arg_data->offset
4646 memcpy((uint8_t *)ctx->objmask + arg_addr->offset,
4648 (uint8_t *)ctx->objmask + arg_data->offset
4654 push_args(ctx, arg_addr);
4655 push_args(ctx, arg_len);
4656 push_args(ctx, arg_data);
4661 parse_hex_string(const char *src, uint8_t *dst, uint32_t *size)
4667 /* Check input parameters */
4668 if ((src == NULL) ||
4674 /* Convert chars to bytes */
4675 for (i = 0, len = 0; i < *size; i += 2) {
4676 snprintf(tmp, 3, "%s", src + i);
4677 dst[len++] = strtoul(tmp, &c, 16);
4692 parse_hex(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_data = pop_args(ctx);
4697 const struct arg *arg_len = pop_args(ctx);
4698 const struct arg *arg_addr = pop_args(ctx);
4699 char tmp[16]; /* Ought to be enough. */
4701 unsigned int hexlen = len;
4702 unsigned int length = 256;
4703 uint8_t hex_tmp[length];
4705 /* Arguments are expected. */
4709 push_args(ctx, arg_data);
4713 push_args(ctx, arg_len);
4714 push_args(ctx, arg_data);
4717 size = arg_data->size;
4718 /* Bit-mask fill is not supported. */
4724 /* translate bytes string to array. */
4725 if (str[0] == '0' && ((str[1] == 'x') ||
4730 if (hexlen > length)
4732 ret = parse_hex_string(str, hex_tmp, &hexlen);
4735 /* Let parse_int() fill length information first. */
4736 ret = snprintf(tmp, sizeof(tmp), "%u", hexlen);
4739 push_args(ctx, arg_len);
4740 ret = parse_int(ctx, token, tmp, ret, NULL, 0);
4745 buf = (uint8_t *)ctx->object + arg_data->offset;
4746 /* Output buffer is not necessarily NUL-terminated. */
4747 memcpy(buf, hex_tmp, hexlen);
4748 memset((uint8_t *)buf + hexlen, 0x00, size - hexlen);
4750 memset((uint8_t *)ctx->objmask + arg_data->offset,
4752 /* Save address if requested. */
4753 if (arg_addr->size) {
4754 memcpy((uint8_t *)ctx->object + arg_addr->offset,
4756 (uint8_t *)ctx->object + arg_data->offset
4760 memcpy((uint8_t *)ctx->objmask + arg_addr->offset,
4762 (uint8_t *)ctx->objmask + arg_data->offset
4768 push_args(ctx, arg_addr);
4769 push_args(ctx, arg_len);
4770 push_args(ctx, arg_data);
4776 * Parse a MAC address.
4778 * Last argument (ctx->args) is retrieved to determine storage size and
4782 parse_mac_addr(struct context *ctx, const struct token *token,
4783 const char *str, unsigned int len,
4784 void *buf, unsigned int size)
4786 const struct arg *arg = pop_args(ctx);
4787 struct rte_ether_addr tmp;
4791 /* Argument is expected. */
4795 /* Bit-mask fill is not supported. */
4796 if (arg->mask || size != sizeof(tmp))
4798 /* Only network endian is supported. */
4801 ret = cmdline_parse_etheraddr(NULL, str, &tmp, size);
4802 if (ret < 0 || (unsigned int)ret != len)
4806 buf = (uint8_t *)ctx->object + arg->offset;
4807 memcpy(buf, &tmp, size);
4809 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
4812 push_args(ctx, arg);
4817 * Parse an IPv4 address.
4819 * Last argument (ctx->args) is retrieved to determine storage size and
4823 parse_ipv4_addr(struct context *ctx, const struct token *token,
4824 const char *str, unsigned int len,
4825 void *buf, unsigned int size)
4827 const struct arg *arg = pop_args(ctx);
4832 /* Argument is expected. */
4836 /* Bit-mask fill is not supported. */
4837 if (arg->mask || size != sizeof(tmp))
4839 /* Only network endian is supported. */
4842 memcpy(str2, str, len);
4844 ret = inet_pton(AF_INET, str2, &tmp);
4846 /* Attempt integer parsing. */
4847 push_args(ctx, arg);
4848 return parse_int(ctx, token, str, len, buf, size);
4852 buf = (uint8_t *)ctx->object + arg->offset;
4853 memcpy(buf, &tmp, size);
4855 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
4858 push_args(ctx, arg);
4863 * Parse an IPv6 address.
4865 * Last argument (ctx->args) is retrieved to determine storage size and
4869 parse_ipv6_addr(struct context *ctx, const struct token *token,
4870 const char *str, unsigned int len,
4871 void *buf, unsigned int size)
4873 const struct arg *arg = pop_args(ctx);
4875 struct in6_addr tmp;
4879 /* Argument is expected. */
4883 /* Bit-mask fill is not supported. */
4884 if (arg->mask || size != sizeof(tmp))
4886 /* Only network endian is supported. */
4889 memcpy(str2, str, len);
4891 ret = inet_pton(AF_INET6, str2, &tmp);
4896 buf = (uint8_t *)ctx->object + arg->offset;
4897 memcpy(buf, &tmp, size);
4899 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
4902 push_args(ctx, arg);
4906 /** Boolean values (even indices stand for false). */
4907 static const char *const boolean_name[] = {
4917 * Parse a boolean value.
4919 * Last argument (ctx->args) is retrieved to determine storage size and
4923 parse_boolean(struct context *ctx, const struct token *token,
4924 const char *str, unsigned int len,
4925 void *buf, unsigned int size)
4927 const struct arg *arg = pop_args(ctx);
4931 /* Argument is expected. */
4934 for (i = 0; boolean_name[i]; ++i)
4935 if (!strcmp_partial(boolean_name[i], str, len))
4937 /* Process token as integer. */
4938 if (boolean_name[i])
4939 str = i & 1 ? "1" : "0";
4940 push_args(ctx, arg);
4941 ret = parse_int(ctx, token, str, strlen(str), buf, size);
4942 return ret > 0 ? (int)len : ret;
4945 /** Parse port and update context. */
4947 parse_port(struct context *ctx, const struct token *token,
4948 const char *str, unsigned int len,
4949 void *buf, unsigned int size)
4951 struct buffer *out = &(struct buffer){ .port = 0 };
4959 ctx->objmask = NULL;
4960 size = sizeof(*out);
4962 ret = parse_int(ctx, token, str, len, out, size);
4964 ctx->port = out->port;
4970 /** No completion. */
4972 comp_none(struct context *ctx, const struct token *token,
4973 unsigned int ent, char *buf, unsigned int size)
4983 /** Complete boolean values. */
4985 comp_boolean(struct context *ctx, const struct token *token,
4986 unsigned int ent, char *buf, unsigned int size)
4992 for (i = 0; boolean_name[i]; ++i)
4993 if (buf && i == ent)
4994 return strlcpy(buf, boolean_name[i], size);
5000 /** Complete action names. */
5002 comp_action(struct context *ctx, const struct token *token,
5003 unsigned int ent, char *buf, unsigned int size)
5009 for (i = 0; next_action[i]; ++i)
5010 if (buf && i == ent)
5011 return strlcpy(buf, token_list[next_action[i]].name,
5018 /** Complete available ports. */
5020 comp_port(struct context *ctx, const struct token *token,
5021 unsigned int ent, char *buf, unsigned int size)
5028 RTE_ETH_FOREACH_DEV(p) {
5029 if (buf && i == ent)
5030 return snprintf(buf, size, "%u", p);
5038 /** Complete available rule IDs. */
5040 comp_rule_id(struct context *ctx, const struct token *token,
5041 unsigned int ent, char *buf, unsigned int size)
5044 struct rte_port *port;
5045 struct port_flow *pf;
5048 if (port_id_is_invalid(ctx->port, DISABLED_WARN) ||
5049 ctx->port == (portid_t)RTE_PORT_ALL)
5051 port = &ports[ctx->port];
5052 for (pf = port->flow_list; pf != NULL; pf = pf->next) {
5053 if (buf && i == ent)
5054 return snprintf(buf, size, "%u", pf->id);
5062 /** Complete type field for RSS action. */
5064 comp_vc_action_rss_type(struct context *ctx, const struct token *token,
5065 unsigned int ent, char *buf, unsigned int size)
5071 for (i = 0; rss_type_table[i].str; ++i)
5076 return strlcpy(buf, rss_type_table[ent].str, size);
5078 return snprintf(buf, size, "end");
5082 /** Complete queue field for RSS action. */
5084 comp_vc_action_rss_queue(struct context *ctx, const struct token *token,
5085 unsigned int ent, char *buf, unsigned int size)
5092 return snprintf(buf, size, "%u", ent);
5094 return snprintf(buf, size, "end");
5098 /** Internal context. */
5099 static struct context cmd_flow_context;
5101 /** Global parser instance (cmdline API). */
5102 cmdline_parse_inst_t cmd_flow;
5104 /** Initialize context. */
5106 cmd_flow_context_init(struct context *ctx)
5108 /* A full memset() is not necessary. */
5118 ctx->objmask = NULL;
5121 /** Parse a token (cmdline API). */
5123 cmd_flow_parse(cmdline_parse_token_hdr_t *hdr, const char *src, void *result,
5126 struct context *ctx = &cmd_flow_context;
5127 const struct token *token;
5128 const enum index *list;
5133 token = &token_list[ctx->curr];
5134 /* Check argument length. */
5137 for (len = 0; src[len]; ++len)
5138 if (src[len] == '#' || isspace(src[len]))
5142 /* Last argument and EOL detection. */
5143 for (i = len; src[i]; ++i)
5144 if (src[i] == '#' || src[i] == '\r' || src[i] == '\n')
5146 else if (!isspace(src[i])) {
5151 if (src[i] == '\r' || src[i] == '\n') {
5155 /* Initialize context if necessary. */
5156 if (!ctx->next_num) {
5159 ctx->next[ctx->next_num++] = token->next[0];
5161 /* Process argument through candidates. */
5162 ctx->prev = ctx->curr;
5163 list = ctx->next[ctx->next_num - 1];
5164 for (i = 0; list[i]; ++i) {
5165 const struct token *next = &token_list[list[i]];
5168 ctx->curr = list[i];
5170 tmp = next->call(ctx, next, src, len, result, size);
5172 tmp = parse_default(ctx, next, src, len, result, size);
5173 if (tmp == -1 || tmp != len)
5181 /* Push subsequent tokens if any. */
5183 for (i = 0; token->next[i]; ++i) {
5184 if (ctx->next_num == RTE_DIM(ctx->next))
5186 ctx->next[ctx->next_num++] = token->next[i];
5188 /* Push arguments if any. */
5190 for (i = 0; token->args[i]; ++i) {
5191 if (ctx->args_num == RTE_DIM(ctx->args))
5193 ctx->args[ctx->args_num++] = token->args[i];
5198 /** Return number of completion entries (cmdline API). */
5200 cmd_flow_complete_get_nb(cmdline_parse_token_hdr_t *hdr)
5202 struct context *ctx = &cmd_flow_context;
5203 const struct token *token = &token_list[ctx->curr];
5204 const enum index *list;
5208 /* Count number of tokens in current list. */
5210 list = ctx->next[ctx->next_num - 1];
5212 list = token->next[0];
5213 for (i = 0; list[i]; ++i)
5218 * If there is a single token, use its completion callback, otherwise
5219 * return the number of entries.
5221 token = &token_list[list[0]];
5222 if (i == 1 && token->comp) {
5223 /* Save index for cmd_flow_get_help(). */
5224 ctx->prev = list[0];
5225 return token->comp(ctx, token, 0, NULL, 0);
5230 /** Return a completion entry (cmdline API). */
5232 cmd_flow_complete_get_elt(cmdline_parse_token_hdr_t *hdr, int index,
5233 char *dst, unsigned int size)
5235 struct context *ctx = &cmd_flow_context;
5236 const struct token *token = &token_list[ctx->curr];
5237 const enum index *list;
5241 /* Count number of tokens in current list. */
5243 list = ctx->next[ctx->next_num - 1];
5245 list = token->next[0];
5246 for (i = 0; list[i]; ++i)
5250 /* If there is a single token, use its completion callback. */
5251 token = &token_list[list[0]];
5252 if (i == 1 && token->comp) {
5253 /* Save index for cmd_flow_get_help(). */
5254 ctx->prev = list[0];
5255 return token->comp(ctx, token, index, dst, size) < 0 ? -1 : 0;
5257 /* Otherwise make sure the index is valid and use defaults. */
5260 token = &token_list[list[index]];
5261 strlcpy(dst, token->name, size);
5262 /* Save index for cmd_flow_get_help(). */
5263 ctx->prev = list[index];
5267 /** Populate help strings for current token (cmdline API). */
5269 cmd_flow_get_help(cmdline_parse_token_hdr_t *hdr, char *dst, unsigned int size)
5271 struct context *ctx = &cmd_flow_context;
5272 const struct token *token = &token_list[ctx->prev];
5277 /* Set token type and update global help with details. */
5278 strlcpy(dst, (token->type ? token->type : "TOKEN"), size);
5280 cmd_flow.help_str = token->help;
5282 cmd_flow.help_str = token->name;
5286 /** Token definition template (cmdline API). */
5287 static struct cmdline_token_hdr cmd_flow_token_hdr = {
5288 .ops = &(struct cmdline_token_ops){
5289 .parse = cmd_flow_parse,
5290 .complete_get_nb = cmd_flow_complete_get_nb,
5291 .complete_get_elt = cmd_flow_complete_get_elt,
5292 .get_help = cmd_flow_get_help,
5297 /** Populate the next dynamic token. */
5299 cmd_flow_tok(cmdline_parse_token_hdr_t **hdr,
5300 cmdline_parse_token_hdr_t **hdr_inst)
5302 struct context *ctx = &cmd_flow_context;
5304 /* Always reinitialize context before requesting the first token. */
5305 if (!(hdr_inst - cmd_flow.tokens))
5306 cmd_flow_context_init(ctx);
5307 /* Return NULL when no more tokens are expected. */
5308 if (!ctx->next_num && ctx->curr) {
5312 /* Determine if command should end here. */
5313 if (ctx->eol && ctx->last && ctx->next_num) {
5314 const enum index *list = ctx->next[ctx->next_num - 1];
5317 for (i = 0; list[i]; ++i) {
5324 *hdr = &cmd_flow_token_hdr;
5327 /** Dispatch parsed buffer to function calls. */
5329 cmd_flow_parsed(const struct buffer *in)
5331 switch (in->command) {
5333 port_flow_validate(in->port, &in->args.vc.attr,
5334 in->args.vc.pattern, in->args.vc.actions);
5337 port_flow_create(in->port, &in->args.vc.attr,
5338 in->args.vc.pattern, in->args.vc.actions);
5341 port_flow_destroy(in->port, in->args.destroy.rule_n,
5342 in->args.destroy.rule);
5345 port_flow_flush(in->port);
5348 port_flow_query(in->port, in->args.query.rule,
5349 &in->args.query.action);
5352 port_flow_list(in->port, in->args.list.group_n,
5353 in->args.list.group);
5356 port_flow_isolate(in->port, in->args.isolate.set);
5363 /** Token generator and output processing callback (cmdline API). */
5365 cmd_flow_cb(void *arg0, struct cmdline *cl, void *arg2)
5368 cmd_flow_tok(arg0, arg2);
5370 cmd_flow_parsed(arg0);
5373 /** Global parser instance (cmdline API). */
5374 cmdline_parse_inst_t cmd_flow = {
5376 .data = NULL, /**< Unused. */
5377 .help_str = NULL, /**< Updated by cmd_flow_get_help(). */
5380 }, /**< Tokens are returned by cmd_flow_tok(). */