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_common.h>
17 #include <rte_eth_ctrl.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. */
46 /* Top-level command. */
49 /* Sub-level commands. */
58 /* Destroy arguments. */
61 /* Query arguments. */
67 /* Validate/create arguments. */
74 /* Validate/create pattern. */
111 ITEM_VLAN_INNER_TYPE,
143 ITEM_E_TAG_GRP_ECID_B,
162 ITEM_ARP_ETH_IPV4_SHA,
163 ITEM_ARP_ETH_IPV4_SPA,
164 ITEM_ARP_ETH_IPV4_THA,
165 ITEM_ARP_ETH_IPV4_TPA,
167 ITEM_IPV6_EXT_NEXT_HDR,
172 ITEM_ICMP6_ND_NS_TARGET_ADDR,
174 ITEM_ICMP6_ND_NA_TARGET_ADDR,
176 ITEM_ICMP6_ND_OPT_TYPE,
177 ITEM_ICMP6_ND_OPT_SLA_ETH,
178 ITEM_ICMP6_ND_OPT_SLA_ETH_SLA,
179 ITEM_ICMP6_ND_OPT_TLA_ETH,
180 ITEM_ICMP6_ND_OPT_TLA_ETH_TLA,
182 /* Validate/create actions. */
202 ACTION_RSS_FUNC_DEFAULT,
203 ACTION_RSS_FUNC_TOEPLITZ,
204 ACTION_RSS_FUNC_SIMPLE_XOR,
216 ACTION_PHY_PORT_ORIGINAL,
217 ACTION_PHY_PORT_INDEX,
219 ACTION_PORT_ID_ORIGINAL,
223 ACTION_OF_SET_MPLS_TTL,
224 ACTION_OF_SET_MPLS_TTL_MPLS_TTL,
225 ACTION_OF_DEC_MPLS_TTL,
226 ACTION_OF_SET_NW_TTL,
227 ACTION_OF_SET_NW_TTL_NW_TTL,
228 ACTION_OF_DEC_NW_TTL,
229 ACTION_OF_COPY_TTL_OUT,
230 ACTION_OF_COPY_TTL_IN,
233 ACTION_OF_PUSH_VLAN_ETHERTYPE,
234 ACTION_OF_SET_VLAN_VID,
235 ACTION_OF_SET_VLAN_VID_VLAN_VID,
236 ACTION_OF_SET_VLAN_PCP,
237 ACTION_OF_SET_VLAN_PCP_VLAN_PCP,
239 ACTION_OF_POP_MPLS_ETHERTYPE,
241 ACTION_OF_PUSH_MPLS_ETHERTYPE,
247 ACTION_SET_IPV4_SRC_IPV4_SRC,
249 ACTION_SET_IPV4_DST_IPV4_DST,
251 ACTION_SET_IPV6_SRC_IPV6_SRC,
253 ACTION_SET_IPV6_DST_IPV6_DST,
256 /** Maximum size for pattern in struct rte_flow_item_raw. */
257 #define ITEM_RAW_PATTERN_SIZE 40
259 /** Storage size for struct rte_flow_item_raw including pattern. */
260 #define ITEM_RAW_SIZE \
261 (sizeof(struct rte_flow_item_raw) + ITEM_RAW_PATTERN_SIZE)
263 /** Maximum number of queue indices in struct rte_flow_action_rss. */
264 #define ACTION_RSS_QUEUE_NUM 32
266 /** Storage for struct rte_flow_action_rss including external data. */
267 struct action_rss_data {
268 struct rte_flow_action_rss conf;
269 uint8_t key[RSS_HASH_KEY_LENGTH];
270 uint16_t queue[ACTION_RSS_QUEUE_NUM];
273 /** Maximum number of items in struct rte_flow_action_vxlan_encap. */
274 #define ACTION_VXLAN_ENCAP_ITEMS_NUM 6
276 /** Storage for struct rte_flow_action_vxlan_encap including external data. */
277 struct action_vxlan_encap_data {
278 struct rte_flow_action_vxlan_encap conf;
279 struct rte_flow_item items[ACTION_VXLAN_ENCAP_ITEMS_NUM];
280 struct rte_flow_item_eth item_eth;
281 struct rte_flow_item_vlan item_vlan;
283 struct rte_flow_item_ipv4 item_ipv4;
284 struct rte_flow_item_ipv6 item_ipv6;
286 struct rte_flow_item_udp item_udp;
287 struct rte_flow_item_vxlan item_vxlan;
290 /** Maximum number of items in struct rte_flow_action_nvgre_encap. */
291 #define ACTION_NVGRE_ENCAP_ITEMS_NUM 5
293 /** Storage for struct rte_flow_action_nvgre_encap including external data. */
294 struct action_nvgre_encap_data {
295 struct rte_flow_action_nvgre_encap conf;
296 struct rte_flow_item items[ACTION_NVGRE_ENCAP_ITEMS_NUM];
297 struct rte_flow_item_eth item_eth;
298 struct rte_flow_item_vlan item_vlan;
300 struct rte_flow_item_ipv4 item_ipv4;
301 struct rte_flow_item_ipv6 item_ipv6;
303 struct rte_flow_item_nvgre item_nvgre;
306 /** Maximum number of subsequent tokens and arguments on the stack. */
307 #define CTX_STACK_SIZE 16
309 /** Parser context. */
311 /** Stack of subsequent token lists to process. */
312 const enum index *next[CTX_STACK_SIZE];
313 /** Arguments for stacked tokens. */
314 const void *args[CTX_STACK_SIZE];
315 enum index curr; /**< Current token index. */
316 enum index prev; /**< Index of the last token seen. */
317 int next_num; /**< Number of entries in next[]. */
318 int args_num; /**< Number of entries in args[]. */
319 uint32_t eol:1; /**< EOL has been detected. */
320 uint32_t last:1; /**< No more arguments. */
321 portid_t port; /**< Current port ID (for completions). */
322 uint32_t objdata; /**< Object-specific data. */
323 void *object; /**< Address of current object for relative offsets. */
324 void *objmask; /**< Object a full mask must be written to. */
327 /** Token argument. */
329 uint32_t hton:1; /**< Use network byte ordering. */
330 uint32_t sign:1; /**< Value is signed. */
331 uint32_t bounded:1; /**< Value is bounded. */
332 uintmax_t min; /**< Minimum value if bounded. */
333 uintmax_t max; /**< Maximum value if bounded. */
334 uint32_t offset; /**< Relative offset from ctx->object. */
335 uint32_t size; /**< Field size. */
336 const uint8_t *mask; /**< Bit-mask to use instead of offset/size. */
339 /** Parser token definition. */
341 /** Type displayed during completion (defaults to "TOKEN"). */
343 /** Help displayed during completion (defaults to token name). */
345 /** Private data used by parser functions. */
348 * Lists of subsequent tokens to push on the stack. Each call to the
349 * parser consumes the last entry of that stack.
351 const enum index *const *next;
352 /** Arguments stack for subsequent tokens that need them. */
353 const struct arg *const *args;
355 * Token-processing callback, returns -1 in case of error, the
356 * length of the matched string otherwise. If NULL, attempts to
357 * match the token name.
359 * If buf is not NULL, the result should be stored in it according
360 * to context. An error is returned if not large enough.
362 int (*call)(struct context *ctx, const struct token *token,
363 const char *str, unsigned int len,
364 void *buf, unsigned int size);
366 * Callback that provides possible values for this token, used for
367 * completion. Returns -1 in case of error, the number of possible
368 * values otherwise. If NULL, the token name is used.
370 * If buf is not NULL, entry index ent is written to buf and the
371 * full length of the entry is returned (same behavior as
374 int (*comp)(struct context *ctx, const struct token *token,
375 unsigned int ent, char *buf, unsigned int size);
376 /** Mandatory token name, no default value. */
380 /** Static initializer for the next field. */
381 #define NEXT(...) (const enum index *const []){ __VA_ARGS__, NULL, }
383 /** Static initializer for a NEXT() entry. */
384 #define NEXT_ENTRY(...) (const enum index []){ __VA_ARGS__, ZERO, }
386 /** Static initializer for the args field. */
387 #define ARGS(...) (const struct arg *const []){ __VA_ARGS__, NULL, }
389 /** Static initializer for ARGS() to target a field. */
390 #define ARGS_ENTRY(s, f) \
391 (&(const struct arg){ \
392 .offset = offsetof(s, f), \
393 .size = sizeof(((s *)0)->f), \
396 /** Static initializer for ARGS() to target a bit-field. */
397 #define ARGS_ENTRY_BF(s, f, b) \
398 (&(const struct arg){ \
400 .mask = (const void *)&(const s){ .f = (1 << (b)) - 1 }, \
403 /** Static initializer for ARGS() to target an arbitrary bit-mask. */
404 #define ARGS_ENTRY_MASK(s, f, m) \
405 (&(const struct arg){ \
406 .offset = offsetof(s, f), \
407 .size = sizeof(((s *)0)->f), \
408 .mask = (const void *)(m), \
411 /** Same as ARGS_ENTRY_MASK() using network byte ordering for the value. */
412 #define ARGS_ENTRY_MASK_HTON(s, f, m) \
413 (&(const struct arg){ \
415 .offset = offsetof(s, f), \
416 .size = sizeof(((s *)0)->f), \
417 .mask = (const void *)(m), \
420 /** Static initializer for ARGS() to target a pointer. */
421 #define ARGS_ENTRY_PTR(s, f) \
422 (&(const struct arg){ \
423 .size = sizeof(*((s *)0)->f), \
426 /** Static initializer for ARGS() with arbitrary offset and size. */
427 #define ARGS_ENTRY_ARB(o, s) \
428 (&(const struct arg){ \
433 /** Same as ARGS_ENTRY_ARB() with bounded values. */
434 #define ARGS_ENTRY_ARB_BOUNDED(o, s, i, a) \
435 (&(const struct arg){ \
443 /** Same as ARGS_ENTRY() using network byte ordering. */
444 #define ARGS_ENTRY_HTON(s, f) \
445 (&(const struct arg){ \
447 .offset = offsetof(s, f), \
448 .size = sizeof(((s *)0)->f), \
451 /** Parser output buffer layout expected by cmd_flow_parsed(). */
453 enum index command; /**< Flow command. */
454 portid_t port; /**< Affected port ID. */
457 struct rte_flow_attr attr;
458 struct rte_flow_item *pattern;
459 struct rte_flow_action *actions;
463 } vc; /**< Validate/create arguments. */
467 } destroy; /**< Destroy arguments. */
470 struct rte_flow_action action;
471 } query; /**< Query arguments. */
475 } list; /**< List arguments. */
478 } isolate; /**< Isolated mode arguments. */
479 } args; /**< Command arguments. */
482 /** Private data for pattern items. */
483 struct parse_item_priv {
484 enum rte_flow_item_type type; /**< Item type. */
485 uint32_t size; /**< Size of item specification structure. */
488 #define PRIV_ITEM(t, s) \
489 (&(const struct parse_item_priv){ \
490 .type = RTE_FLOW_ITEM_TYPE_ ## t, \
494 /** Private data for actions. */
495 struct parse_action_priv {
496 enum rte_flow_action_type type; /**< Action type. */
497 uint32_t size; /**< Size of action configuration structure. */
500 #define PRIV_ACTION(t, s) \
501 (&(const struct parse_action_priv){ \
502 .type = RTE_FLOW_ACTION_TYPE_ ## t, \
506 static const enum index next_vc_attr[] = {
516 static const enum index next_destroy_attr[] = {
522 static const enum index next_list_attr[] = {
528 static const enum index item_param[] = {
537 static const enum index next_item[] = {
573 ITEM_ICMP6_ND_OPT_SLA_ETH,
574 ITEM_ICMP6_ND_OPT_TLA_ETH,
578 static const enum index item_fuzzy[] = {
584 static const enum index item_any[] = {
590 static const enum index item_vf[] = {
596 static const enum index item_phy_port[] = {
602 static const enum index item_port_id[] = {
608 static const enum index item_mark[] = {
614 static const enum index item_raw[] = {
624 static const enum index item_eth[] = {
632 static const enum index item_vlan[] = {
637 ITEM_VLAN_INNER_TYPE,
642 static const enum index item_ipv4[] = {
652 static const enum index item_ipv6[] = {
663 static const enum index item_icmp[] = {
670 static const enum index item_udp[] = {
677 static const enum index item_tcp[] = {
685 static const enum index item_sctp[] = {
694 static const enum index item_vxlan[] = {
700 static const enum index item_e_tag[] = {
701 ITEM_E_TAG_GRP_ECID_B,
706 static const enum index item_nvgre[] = {
712 static const enum index item_mpls[] = {
718 static const enum index item_gre[] = {
724 static const enum index item_gtp[] = {
730 static const enum index item_geneve[] = {
737 static const enum index item_vxlan_gpe[] = {
743 static const enum index item_arp_eth_ipv4[] = {
744 ITEM_ARP_ETH_IPV4_SHA,
745 ITEM_ARP_ETH_IPV4_SPA,
746 ITEM_ARP_ETH_IPV4_THA,
747 ITEM_ARP_ETH_IPV4_TPA,
752 static const enum index item_ipv6_ext[] = {
753 ITEM_IPV6_EXT_NEXT_HDR,
758 static const enum index item_icmp6[] = {
765 static const enum index item_icmp6_nd_ns[] = {
766 ITEM_ICMP6_ND_NS_TARGET_ADDR,
771 static const enum index item_icmp6_nd_na[] = {
772 ITEM_ICMP6_ND_NA_TARGET_ADDR,
777 static const enum index item_icmp6_nd_opt[] = {
778 ITEM_ICMP6_ND_OPT_TYPE,
783 static const enum index item_icmp6_nd_opt_sla_eth[] = {
784 ITEM_ICMP6_ND_OPT_SLA_ETH_SLA,
789 static const enum index item_icmp6_nd_opt_tla_eth[] = {
790 ITEM_ICMP6_ND_OPT_TLA_ETH_TLA,
795 static const enum index next_action[] = {
811 ACTION_OF_SET_MPLS_TTL,
812 ACTION_OF_DEC_MPLS_TTL,
813 ACTION_OF_SET_NW_TTL,
814 ACTION_OF_DEC_NW_TTL,
815 ACTION_OF_COPY_TTL_OUT,
816 ACTION_OF_COPY_TTL_IN,
819 ACTION_OF_SET_VLAN_VID,
820 ACTION_OF_SET_VLAN_PCP,
834 static const enum index action_mark[] = {
840 static const enum index action_queue[] = {
846 static const enum index action_count[] = {
853 static const enum index action_rss[] = {
864 static const enum index action_vf[] = {
871 static const enum index action_phy_port[] = {
872 ACTION_PHY_PORT_ORIGINAL,
873 ACTION_PHY_PORT_INDEX,
878 static const enum index action_port_id[] = {
879 ACTION_PORT_ID_ORIGINAL,
885 static const enum index action_meter[] = {
891 static const enum index action_of_set_mpls_ttl[] = {
892 ACTION_OF_SET_MPLS_TTL_MPLS_TTL,
897 static const enum index action_of_set_nw_ttl[] = {
898 ACTION_OF_SET_NW_TTL_NW_TTL,
903 static const enum index action_of_push_vlan[] = {
904 ACTION_OF_PUSH_VLAN_ETHERTYPE,
909 static const enum index action_of_set_vlan_vid[] = {
910 ACTION_OF_SET_VLAN_VID_VLAN_VID,
915 static const enum index action_of_set_vlan_pcp[] = {
916 ACTION_OF_SET_VLAN_PCP_VLAN_PCP,
921 static const enum index action_of_pop_mpls[] = {
922 ACTION_OF_POP_MPLS_ETHERTYPE,
927 static const enum index action_of_push_mpls[] = {
928 ACTION_OF_PUSH_MPLS_ETHERTYPE,
933 static const enum index action_set_ipv4_src[] = {
934 ACTION_SET_IPV4_SRC_IPV4_SRC,
939 static const enum index action_set_ipv4_dst[] = {
940 ACTION_SET_IPV4_DST_IPV4_DST,
945 static const enum index action_set_ipv6_src[] = {
946 ACTION_SET_IPV6_SRC_IPV6_SRC,
951 static const enum index action_set_ipv6_dst[] = {
952 ACTION_SET_IPV6_DST_IPV6_DST,
957 static const enum index action_jump[] = {
963 static int parse_init(struct context *, const struct token *,
964 const char *, unsigned int,
965 void *, unsigned int);
966 static int parse_vc(struct context *, const struct token *,
967 const char *, unsigned int,
968 void *, unsigned int);
969 static int parse_vc_spec(struct context *, const struct token *,
970 const char *, unsigned int, void *, unsigned int);
971 static int parse_vc_conf(struct context *, const struct token *,
972 const char *, unsigned int, void *, unsigned int);
973 static int parse_vc_action_rss(struct context *, const struct token *,
974 const char *, unsigned int, void *,
976 static int parse_vc_action_rss_func(struct context *, const struct token *,
977 const char *, unsigned int, void *,
979 static int parse_vc_action_rss_type(struct context *, const struct token *,
980 const char *, unsigned int, void *,
982 static int parse_vc_action_rss_queue(struct context *, const struct token *,
983 const char *, unsigned int, void *,
985 static int parse_vc_action_vxlan_encap(struct context *, const struct token *,
986 const char *, unsigned int, void *,
988 static int parse_vc_action_nvgre_encap(struct context *, const struct token *,
989 const char *, unsigned int, void *,
991 static int parse_destroy(struct context *, const struct token *,
992 const char *, unsigned int,
993 void *, unsigned int);
994 static int parse_flush(struct context *, const struct token *,
995 const char *, unsigned int,
996 void *, unsigned int);
997 static int parse_query(struct context *, const struct token *,
998 const char *, unsigned int,
999 void *, unsigned int);
1000 static int parse_action(struct context *, const struct token *,
1001 const char *, unsigned int,
1002 void *, unsigned int);
1003 static int parse_list(struct context *, const struct token *,
1004 const char *, unsigned int,
1005 void *, unsigned int);
1006 static int parse_isolate(struct context *, const struct token *,
1007 const char *, unsigned int,
1008 void *, unsigned int);
1009 static int parse_int(struct context *, const struct token *,
1010 const char *, unsigned int,
1011 void *, unsigned int);
1012 static int parse_prefix(struct context *, const struct token *,
1013 const char *, unsigned int,
1014 void *, unsigned int);
1015 static int parse_boolean(struct context *, const struct token *,
1016 const char *, unsigned int,
1017 void *, unsigned int);
1018 static int parse_string(struct context *, const struct token *,
1019 const char *, unsigned int,
1020 void *, unsigned int);
1021 static int parse_mac_addr(struct context *, const struct token *,
1022 const char *, unsigned int,
1023 void *, unsigned int);
1024 static int parse_ipv4_addr(struct context *, const struct token *,
1025 const char *, unsigned int,
1026 void *, unsigned int);
1027 static int parse_ipv6_addr(struct context *, const struct token *,
1028 const char *, unsigned int,
1029 void *, unsigned int);
1030 static int parse_port(struct context *, const struct token *,
1031 const char *, unsigned int,
1032 void *, unsigned int);
1033 static int comp_none(struct context *, const struct token *,
1034 unsigned int, char *, unsigned int);
1035 static int comp_boolean(struct context *, const struct token *,
1036 unsigned int, char *, unsigned int);
1037 static int comp_action(struct context *, const struct token *,
1038 unsigned int, char *, unsigned int);
1039 static int comp_port(struct context *, const struct token *,
1040 unsigned int, char *, unsigned int);
1041 static int comp_rule_id(struct context *, const struct token *,
1042 unsigned int, char *, unsigned int);
1043 static int comp_vc_action_rss_type(struct context *, const struct token *,
1044 unsigned int, char *, unsigned int);
1045 static int comp_vc_action_rss_queue(struct context *, const struct token *,
1046 unsigned int, char *, unsigned int);
1048 /** Token definitions. */
1049 static const struct token token_list[] = {
1050 /* Special tokens. */
1053 .help = "null entry, abused as the entry point",
1054 .next = NEXT(NEXT_ENTRY(FLOW)),
1059 .help = "command may end here",
1061 /* Common tokens. */
1065 .help = "integer value",
1070 .name = "{unsigned}",
1072 .help = "unsigned integer value",
1079 .help = "prefix length for bit-mask",
1080 .call = parse_prefix,
1084 .name = "{boolean}",
1086 .help = "any boolean value",
1087 .call = parse_boolean,
1088 .comp = comp_boolean,
1093 .help = "fixed string",
1094 .call = parse_string,
1098 .name = "{MAC address}",
1100 .help = "standard MAC address notation",
1101 .call = parse_mac_addr,
1105 .name = "{IPv4 address}",
1106 .type = "IPV4 ADDRESS",
1107 .help = "standard IPv4 address notation",
1108 .call = parse_ipv4_addr,
1112 .name = "{IPv6 address}",
1113 .type = "IPV6 ADDRESS",
1114 .help = "standard IPv6 address notation",
1115 .call = parse_ipv6_addr,
1119 .name = "{rule id}",
1121 .help = "rule identifier",
1123 .comp = comp_rule_id,
1126 .name = "{port_id}",
1128 .help = "port identifier",
1133 .name = "{group_id}",
1135 .help = "group identifier",
1139 [PRIORITY_LEVEL] = {
1142 .help = "priority level",
1146 /* Top-level command. */
1149 .type = "{command} {port_id} [{arg} [...]]",
1150 .help = "manage ingress/egress flow rules",
1151 .next = NEXT(NEXT_ENTRY
1161 /* Sub-level commands. */
1164 .help = "check whether a flow rule can be created",
1165 .next = NEXT(next_vc_attr, NEXT_ENTRY(PORT_ID)),
1166 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1171 .help = "create a flow rule",
1172 .next = NEXT(next_vc_attr, NEXT_ENTRY(PORT_ID)),
1173 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1178 .help = "destroy specific flow rules",
1179 .next = NEXT(NEXT_ENTRY(DESTROY_RULE), NEXT_ENTRY(PORT_ID)),
1180 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1181 .call = parse_destroy,
1185 .help = "destroy all flow rules",
1186 .next = NEXT(NEXT_ENTRY(PORT_ID)),
1187 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1188 .call = parse_flush,
1192 .help = "query an existing flow rule",
1193 .next = NEXT(NEXT_ENTRY(QUERY_ACTION),
1194 NEXT_ENTRY(RULE_ID),
1195 NEXT_ENTRY(PORT_ID)),
1196 .args = ARGS(ARGS_ENTRY(struct buffer, args.query.action.type),
1197 ARGS_ENTRY(struct buffer, args.query.rule),
1198 ARGS_ENTRY(struct buffer, port)),
1199 .call = parse_query,
1203 .help = "list existing flow rules",
1204 .next = NEXT(next_list_attr, NEXT_ENTRY(PORT_ID)),
1205 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1210 .help = "restrict ingress traffic to the defined flow rules",
1211 .next = NEXT(NEXT_ENTRY(BOOLEAN),
1212 NEXT_ENTRY(PORT_ID)),
1213 .args = ARGS(ARGS_ENTRY(struct buffer, args.isolate.set),
1214 ARGS_ENTRY(struct buffer, port)),
1215 .call = parse_isolate,
1217 /* Destroy arguments. */
1220 .help = "specify a rule identifier",
1221 .next = NEXT(next_destroy_attr, NEXT_ENTRY(RULE_ID)),
1222 .args = ARGS(ARGS_ENTRY_PTR(struct buffer, args.destroy.rule)),
1223 .call = parse_destroy,
1225 /* Query arguments. */
1229 .help = "action to query, must be part of the rule",
1230 .call = parse_action,
1231 .comp = comp_action,
1233 /* List arguments. */
1236 .help = "specify a group",
1237 .next = NEXT(next_list_attr, NEXT_ENTRY(GROUP_ID)),
1238 .args = ARGS(ARGS_ENTRY_PTR(struct buffer, args.list.group)),
1241 /* Validate/create attributes. */
1244 .help = "specify a group",
1245 .next = NEXT(next_vc_attr, NEXT_ENTRY(GROUP_ID)),
1246 .args = ARGS(ARGS_ENTRY(struct rte_flow_attr, group)),
1251 .help = "specify a priority level",
1252 .next = NEXT(next_vc_attr, NEXT_ENTRY(PRIORITY_LEVEL)),
1253 .args = ARGS(ARGS_ENTRY(struct rte_flow_attr, priority)),
1258 .help = "affect rule to ingress",
1259 .next = NEXT(next_vc_attr),
1264 .help = "affect rule to egress",
1265 .next = NEXT(next_vc_attr),
1270 .help = "apply rule directly to endpoints found in pattern",
1271 .next = NEXT(next_vc_attr),
1274 /* Validate/create pattern. */
1277 .help = "submit a list of pattern items",
1278 .next = NEXT(next_item),
1283 .help = "match value perfectly (with full bit-mask)",
1284 .call = parse_vc_spec,
1286 [ITEM_PARAM_SPEC] = {
1288 .help = "match value according to configured bit-mask",
1289 .call = parse_vc_spec,
1291 [ITEM_PARAM_LAST] = {
1293 .help = "specify upper bound to establish a range",
1294 .call = parse_vc_spec,
1296 [ITEM_PARAM_MASK] = {
1298 .help = "specify bit-mask with relevant bits set to one",
1299 .call = parse_vc_spec,
1301 [ITEM_PARAM_PREFIX] = {
1303 .help = "generate bit-mask from a prefix length",
1304 .call = parse_vc_spec,
1308 .help = "specify next pattern item",
1309 .next = NEXT(next_item),
1313 .help = "end list of pattern items",
1314 .priv = PRIV_ITEM(END, 0),
1315 .next = NEXT(NEXT_ENTRY(ACTIONS)),
1320 .help = "no-op pattern item",
1321 .priv = PRIV_ITEM(VOID, 0),
1322 .next = NEXT(NEXT_ENTRY(ITEM_NEXT)),
1327 .help = "perform actions when pattern does not match",
1328 .priv = PRIV_ITEM(INVERT, 0),
1329 .next = NEXT(NEXT_ENTRY(ITEM_NEXT)),
1334 .help = "match any protocol for the current layer",
1335 .priv = PRIV_ITEM(ANY, sizeof(struct rte_flow_item_any)),
1336 .next = NEXT(item_any),
1341 .help = "number of layers covered",
1342 .next = NEXT(item_any, NEXT_ENTRY(UNSIGNED), item_param),
1343 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_any, num)),
1347 .help = "match traffic from/to the physical function",
1348 .priv = PRIV_ITEM(PF, 0),
1349 .next = NEXT(NEXT_ENTRY(ITEM_NEXT)),
1354 .help = "match traffic from/to a virtual function ID",
1355 .priv = PRIV_ITEM(VF, sizeof(struct rte_flow_item_vf)),
1356 .next = NEXT(item_vf),
1362 .next = NEXT(item_vf, NEXT_ENTRY(UNSIGNED), item_param),
1363 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_vf, id)),
1367 .help = "match traffic from/to a specific physical port",
1368 .priv = PRIV_ITEM(PHY_PORT,
1369 sizeof(struct rte_flow_item_phy_port)),
1370 .next = NEXT(item_phy_port),
1373 [ITEM_PHY_PORT_INDEX] = {
1375 .help = "physical port index",
1376 .next = NEXT(item_phy_port, NEXT_ENTRY(UNSIGNED), item_param),
1377 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_phy_port, index)),
1381 .help = "match traffic from/to a given DPDK port ID",
1382 .priv = PRIV_ITEM(PORT_ID,
1383 sizeof(struct rte_flow_item_port_id)),
1384 .next = NEXT(item_port_id),
1387 [ITEM_PORT_ID_ID] = {
1389 .help = "DPDK port ID",
1390 .next = NEXT(item_port_id, NEXT_ENTRY(UNSIGNED), item_param),
1391 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_port_id, id)),
1395 .help = "match traffic against value set in previously matched rule",
1396 .priv = PRIV_ITEM(MARK, sizeof(struct rte_flow_item_mark)),
1397 .next = NEXT(item_mark),
1402 .help = "Integer value to match against",
1403 .next = NEXT(item_mark, NEXT_ENTRY(UNSIGNED), item_param),
1404 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_mark, id)),
1408 .help = "match an arbitrary byte string",
1409 .priv = PRIV_ITEM(RAW, ITEM_RAW_SIZE),
1410 .next = NEXT(item_raw),
1413 [ITEM_RAW_RELATIVE] = {
1415 .help = "look for pattern after the previous item",
1416 .next = NEXT(item_raw, NEXT_ENTRY(BOOLEAN), item_param),
1417 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_item_raw,
1420 [ITEM_RAW_SEARCH] = {
1422 .help = "search pattern from offset (see also limit)",
1423 .next = NEXT(item_raw, NEXT_ENTRY(BOOLEAN), item_param),
1424 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_item_raw,
1427 [ITEM_RAW_OFFSET] = {
1429 .help = "absolute or relative offset for pattern",
1430 .next = NEXT(item_raw, NEXT_ENTRY(INTEGER), item_param),
1431 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_raw, offset)),
1433 [ITEM_RAW_LIMIT] = {
1435 .help = "search area limit for start of pattern",
1436 .next = NEXT(item_raw, NEXT_ENTRY(UNSIGNED), item_param),
1437 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_raw, limit)),
1439 [ITEM_RAW_PATTERN] = {
1441 .help = "byte string to look for",
1442 .next = NEXT(item_raw,
1444 NEXT_ENTRY(ITEM_PARAM_IS,
1447 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_raw, pattern),
1448 ARGS_ENTRY(struct rte_flow_item_raw, length),
1449 ARGS_ENTRY_ARB(sizeof(struct rte_flow_item_raw),
1450 ITEM_RAW_PATTERN_SIZE)),
1454 .help = "match Ethernet header",
1455 .priv = PRIV_ITEM(ETH, sizeof(struct rte_flow_item_eth)),
1456 .next = NEXT(item_eth),
1461 .help = "destination MAC",
1462 .next = NEXT(item_eth, NEXT_ENTRY(MAC_ADDR), item_param),
1463 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_eth, dst)),
1467 .help = "source MAC",
1468 .next = NEXT(item_eth, NEXT_ENTRY(MAC_ADDR), item_param),
1469 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_eth, src)),
1473 .help = "EtherType",
1474 .next = NEXT(item_eth, NEXT_ENTRY(UNSIGNED), item_param),
1475 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_eth, type)),
1479 .help = "match 802.1Q/ad VLAN tag",
1480 .priv = PRIV_ITEM(VLAN, sizeof(struct rte_flow_item_vlan)),
1481 .next = NEXT(item_vlan),
1486 .help = "tag control information",
1487 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1488 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vlan, tci)),
1492 .help = "priority code point",
1493 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1494 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_vlan,
1499 .help = "drop eligible indicator",
1500 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1501 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_vlan,
1506 .help = "VLAN identifier",
1507 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1508 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_vlan,
1511 [ITEM_VLAN_INNER_TYPE] = {
1512 .name = "inner_type",
1513 .help = "inner EtherType",
1514 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1515 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vlan,
1520 .help = "match IPv4 header",
1521 .priv = PRIV_ITEM(IPV4, sizeof(struct rte_flow_item_ipv4)),
1522 .next = NEXT(item_ipv4),
1527 .help = "type of service",
1528 .next = NEXT(item_ipv4, NEXT_ENTRY(UNSIGNED), item_param),
1529 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
1530 hdr.type_of_service)),
1534 .help = "time to live",
1535 .next = NEXT(item_ipv4, NEXT_ENTRY(UNSIGNED), item_param),
1536 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
1539 [ITEM_IPV4_PROTO] = {
1541 .help = "next protocol ID",
1542 .next = NEXT(item_ipv4, NEXT_ENTRY(UNSIGNED), item_param),
1543 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
1544 hdr.next_proto_id)),
1548 .help = "source address",
1549 .next = NEXT(item_ipv4, NEXT_ENTRY(IPV4_ADDR), item_param),
1550 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
1555 .help = "destination address",
1556 .next = NEXT(item_ipv4, NEXT_ENTRY(IPV4_ADDR), item_param),
1557 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
1562 .help = "match IPv6 header",
1563 .priv = PRIV_ITEM(IPV6, sizeof(struct rte_flow_item_ipv6)),
1564 .next = NEXT(item_ipv6),
1569 .help = "traffic class",
1570 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
1571 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_ipv6,
1573 "\x0f\xf0\x00\x00")),
1575 [ITEM_IPV6_FLOW] = {
1577 .help = "flow label",
1578 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
1579 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_ipv6,
1581 "\x00\x0f\xff\xff")),
1583 [ITEM_IPV6_PROTO] = {
1585 .help = "protocol (next header)",
1586 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
1587 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
1592 .help = "hop limit",
1593 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
1594 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
1599 .help = "source address",
1600 .next = NEXT(item_ipv6, NEXT_ENTRY(IPV6_ADDR), item_param),
1601 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
1606 .help = "destination address",
1607 .next = NEXT(item_ipv6, NEXT_ENTRY(IPV6_ADDR), item_param),
1608 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
1613 .help = "match ICMP header",
1614 .priv = PRIV_ITEM(ICMP, sizeof(struct rte_flow_item_icmp)),
1615 .next = NEXT(item_icmp),
1618 [ITEM_ICMP_TYPE] = {
1620 .help = "ICMP packet type",
1621 .next = NEXT(item_icmp, NEXT_ENTRY(UNSIGNED), item_param),
1622 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp,
1625 [ITEM_ICMP_CODE] = {
1627 .help = "ICMP packet code",
1628 .next = NEXT(item_icmp, NEXT_ENTRY(UNSIGNED), item_param),
1629 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp,
1634 .help = "match UDP header",
1635 .priv = PRIV_ITEM(UDP, sizeof(struct rte_flow_item_udp)),
1636 .next = NEXT(item_udp),
1641 .help = "UDP source port",
1642 .next = NEXT(item_udp, NEXT_ENTRY(UNSIGNED), item_param),
1643 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_udp,
1648 .help = "UDP destination port",
1649 .next = NEXT(item_udp, NEXT_ENTRY(UNSIGNED), item_param),
1650 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_udp,
1655 .help = "match TCP header",
1656 .priv = PRIV_ITEM(TCP, sizeof(struct rte_flow_item_tcp)),
1657 .next = NEXT(item_tcp),
1662 .help = "TCP source port",
1663 .next = NEXT(item_tcp, NEXT_ENTRY(UNSIGNED), item_param),
1664 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_tcp,
1669 .help = "TCP destination port",
1670 .next = NEXT(item_tcp, NEXT_ENTRY(UNSIGNED), item_param),
1671 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_tcp,
1674 [ITEM_TCP_FLAGS] = {
1676 .help = "TCP flags",
1677 .next = NEXT(item_tcp, NEXT_ENTRY(UNSIGNED), item_param),
1678 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_tcp,
1683 .help = "match SCTP header",
1684 .priv = PRIV_ITEM(SCTP, sizeof(struct rte_flow_item_sctp)),
1685 .next = NEXT(item_sctp),
1690 .help = "SCTP source port",
1691 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
1692 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
1697 .help = "SCTP destination port",
1698 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
1699 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
1704 .help = "validation tag",
1705 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
1706 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
1709 [ITEM_SCTP_CKSUM] = {
1712 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
1713 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
1718 .help = "match VXLAN header",
1719 .priv = PRIV_ITEM(VXLAN, sizeof(struct rte_flow_item_vxlan)),
1720 .next = NEXT(item_vxlan),
1723 [ITEM_VXLAN_VNI] = {
1725 .help = "VXLAN identifier",
1726 .next = NEXT(item_vxlan, NEXT_ENTRY(UNSIGNED), item_param),
1727 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vxlan, vni)),
1731 .help = "match E-Tag header",
1732 .priv = PRIV_ITEM(E_TAG, sizeof(struct rte_flow_item_e_tag)),
1733 .next = NEXT(item_e_tag),
1736 [ITEM_E_TAG_GRP_ECID_B] = {
1737 .name = "grp_ecid_b",
1738 .help = "GRP and E-CID base",
1739 .next = NEXT(item_e_tag, NEXT_ENTRY(UNSIGNED), item_param),
1740 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_e_tag,
1746 .help = "match NVGRE header",
1747 .priv = PRIV_ITEM(NVGRE, sizeof(struct rte_flow_item_nvgre)),
1748 .next = NEXT(item_nvgre),
1751 [ITEM_NVGRE_TNI] = {
1753 .help = "virtual subnet ID",
1754 .next = NEXT(item_nvgre, NEXT_ENTRY(UNSIGNED), item_param),
1755 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_nvgre, tni)),
1759 .help = "match MPLS header",
1760 .priv = PRIV_ITEM(MPLS, sizeof(struct rte_flow_item_mpls)),
1761 .next = NEXT(item_mpls),
1764 [ITEM_MPLS_LABEL] = {
1766 .help = "MPLS label",
1767 .next = NEXT(item_mpls, NEXT_ENTRY(UNSIGNED), item_param),
1768 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_mpls,
1774 .help = "match GRE header",
1775 .priv = PRIV_ITEM(GRE, sizeof(struct rte_flow_item_gre)),
1776 .next = NEXT(item_gre),
1779 [ITEM_GRE_PROTO] = {
1781 .help = "GRE protocol type",
1782 .next = NEXT(item_gre, NEXT_ENTRY(UNSIGNED), item_param),
1783 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gre,
1788 .help = "fuzzy pattern match, expect faster than default",
1789 .priv = PRIV_ITEM(FUZZY,
1790 sizeof(struct rte_flow_item_fuzzy)),
1791 .next = NEXT(item_fuzzy),
1794 [ITEM_FUZZY_THRESH] = {
1796 .help = "match accuracy threshold",
1797 .next = NEXT(item_fuzzy, NEXT_ENTRY(UNSIGNED), item_param),
1798 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_fuzzy,
1803 .help = "match GTP header",
1804 .priv = PRIV_ITEM(GTP, sizeof(struct rte_flow_item_gtp)),
1805 .next = NEXT(item_gtp),
1810 .help = "tunnel endpoint identifier",
1811 .next = NEXT(item_gtp, NEXT_ENTRY(UNSIGNED), item_param),
1812 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gtp, teid)),
1816 .help = "match GTP header",
1817 .priv = PRIV_ITEM(GTPC, sizeof(struct rte_flow_item_gtp)),
1818 .next = NEXT(item_gtp),
1823 .help = "match GTP header",
1824 .priv = PRIV_ITEM(GTPU, sizeof(struct rte_flow_item_gtp)),
1825 .next = NEXT(item_gtp),
1830 .help = "match GENEVE header",
1831 .priv = PRIV_ITEM(GENEVE, sizeof(struct rte_flow_item_geneve)),
1832 .next = NEXT(item_geneve),
1835 [ITEM_GENEVE_VNI] = {
1837 .help = "virtual network identifier",
1838 .next = NEXT(item_geneve, NEXT_ENTRY(UNSIGNED), item_param),
1839 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_geneve, vni)),
1841 [ITEM_GENEVE_PROTO] = {
1843 .help = "GENEVE protocol type",
1844 .next = NEXT(item_geneve, NEXT_ENTRY(UNSIGNED), item_param),
1845 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_geneve,
1848 [ITEM_VXLAN_GPE] = {
1849 .name = "vxlan-gpe",
1850 .help = "match VXLAN-GPE header",
1851 .priv = PRIV_ITEM(VXLAN_GPE,
1852 sizeof(struct rte_flow_item_vxlan_gpe)),
1853 .next = NEXT(item_vxlan_gpe),
1856 [ITEM_VXLAN_GPE_VNI] = {
1858 .help = "VXLAN-GPE identifier",
1859 .next = NEXT(item_vxlan_gpe, NEXT_ENTRY(UNSIGNED), item_param),
1860 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vxlan_gpe,
1863 [ITEM_ARP_ETH_IPV4] = {
1864 .name = "arp_eth_ipv4",
1865 .help = "match ARP header for Ethernet/IPv4",
1866 .priv = PRIV_ITEM(ARP_ETH_IPV4,
1867 sizeof(struct rte_flow_item_arp_eth_ipv4)),
1868 .next = NEXT(item_arp_eth_ipv4),
1871 [ITEM_ARP_ETH_IPV4_SHA] = {
1873 .help = "sender hardware address",
1874 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(MAC_ADDR),
1876 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
1879 [ITEM_ARP_ETH_IPV4_SPA] = {
1881 .help = "sender IPv4 address",
1882 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(IPV4_ADDR),
1884 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
1887 [ITEM_ARP_ETH_IPV4_THA] = {
1889 .help = "target hardware address",
1890 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(MAC_ADDR),
1892 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
1895 [ITEM_ARP_ETH_IPV4_TPA] = {
1897 .help = "target IPv4 address",
1898 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(IPV4_ADDR),
1900 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
1905 .help = "match presence of any IPv6 extension header",
1906 .priv = PRIV_ITEM(IPV6_EXT,
1907 sizeof(struct rte_flow_item_ipv6_ext)),
1908 .next = NEXT(item_ipv6_ext),
1911 [ITEM_IPV6_EXT_NEXT_HDR] = {
1913 .help = "next header",
1914 .next = NEXT(item_ipv6_ext, NEXT_ENTRY(UNSIGNED), item_param),
1915 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6_ext,
1920 .help = "match any ICMPv6 header",
1921 .priv = PRIV_ITEM(ICMP6, sizeof(struct rte_flow_item_icmp6)),
1922 .next = NEXT(item_icmp6),
1925 [ITEM_ICMP6_TYPE] = {
1927 .help = "ICMPv6 type",
1928 .next = NEXT(item_icmp6, NEXT_ENTRY(UNSIGNED), item_param),
1929 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6,
1932 [ITEM_ICMP6_CODE] = {
1934 .help = "ICMPv6 code",
1935 .next = NEXT(item_icmp6, NEXT_ENTRY(UNSIGNED), item_param),
1936 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6,
1939 [ITEM_ICMP6_ND_NS] = {
1940 .name = "icmp6_nd_ns",
1941 .help = "match ICMPv6 neighbor discovery solicitation",
1942 .priv = PRIV_ITEM(ICMP6_ND_NS,
1943 sizeof(struct rte_flow_item_icmp6_nd_ns)),
1944 .next = NEXT(item_icmp6_nd_ns),
1947 [ITEM_ICMP6_ND_NS_TARGET_ADDR] = {
1948 .name = "target_addr",
1949 .help = "target address",
1950 .next = NEXT(item_icmp6_nd_ns, NEXT_ENTRY(IPV6_ADDR),
1952 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6_nd_ns,
1955 [ITEM_ICMP6_ND_NA] = {
1956 .name = "icmp6_nd_na",
1957 .help = "match ICMPv6 neighbor discovery advertisement",
1958 .priv = PRIV_ITEM(ICMP6_ND_NA,
1959 sizeof(struct rte_flow_item_icmp6_nd_na)),
1960 .next = NEXT(item_icmp6_nd_na),
1963 [ITEM_ICMP6_ND_NA_TARGET_ADDR] = {
1964 .name = "target_addr",
1965 .help = "target address",
1966 .next = NEXT(item_icmp6_nd_na, NEXT_ENTRY(IPV6_ADDR),
1968 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6_nd_na,
1971 [ITEM_ICMP6_ND_OPT] = {
1972 .name = "icmp6_nd_opt",
1973 .help = "match presence of any ICMPv6 neighbor discovery"
1975 .priv = PRIV_ITEM(ICMP6_ND_OPT,
1976 sizeof(struct rte_flow_item_icmp6_nd_opt)),
1977 .next = NEXT(item_icmp6_nd_opt),
1980 [ITEM_ICMP6_ND_OPT_TYPE] = {
1982 .help = "ND option type",
1983 .next = NEXT(item_icmp6_nd_opt, NEXT_ENTRY(UNSIGNED),
1985 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6_nd_opt,
1988 [ITEM_ICMP6_ND_OPT_SLA_ETH] = {
1989 .name = "icmp6_nd_opt_sla_eth",
1990 .help = "match ICMPv6 neighbor discovery source Ethernet"
1991 " link-layer address option",
1993 (ICMP6_ND_OPT_SLA_ETH,
1994 sizeof(struct rte_flow_item_icmp6_nd_opt_sla_eth)),
1995 .next = NEXT(item_icmp6_nd_opt_sla_eth),
1998 [ITEM_ICMP6_ND_OPT_SLA_ETH_SLA] = {
2000 .help = "source Ethernet LLA",
2001 .next = NEXT(item_icmp6_nd_opt_sla_eth, NEXT_ENTRY(MAC_ADDR),
2003 .args = ARGS(ARGS_ENTRY_HTON
2004 (struct rte_flow_item_icmp6_nd_opt_sla_eth, sla)),
2006 [ITEM_ICMP6_ND_OPT_TLA_ETH] = {
2007 .name = "icmp6_nd_opt_tla_eth",
2008 .help = "match ICMPv6 neighbor discovery target Ethernet"
2009 " link-layer address option",
2011 (ICMP6_ND_OPT_TLA_ETH,
2012 sizeof(struct rte_flow_item_icmp6_nd_opt_tla_eth)),
2013 .next = NEXT(item_icmp6_nd_opt_tla_eth),
2016 [ITEM_ICMP6_ND_OPT_TLA_ETH_TLA] = {
2018 .help = "target Ethernet LLA",
2019 .next = NEXT(item_icmp6_nd_opt_tla_eth, NEXT_ENTRY(MAC_ADDR),
2021 .args = ARGS(ARGS_ENTRY_HTON
2022 (struct rte_flow_item_icmp6_nd_opt_tla_eth, tla)),
2025 /* Validate/create actions. */
2028 .help = "submit a list of associated actions",
2029 .next = NEXT(next_action),
2034 .help = "specify next action",
2035 .next = NEXT(next_action),
2039 .help = "end list of actions",
2040 .priv = PRIV_ACTION(END, 0),
2045 .help = "no-op action",
2046 .priv = PRIV_ACTION(VOID, 0),
2047 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2050 [ACTION_PASSTHRU] = {
2052 .help = "let subsequent rule process matched packets",
2053 .priv = PRIV_ACTION(PASSTHRU, 0),
2054 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2059 .help = "redirect traffic to a given group",
2060 .priv = PRIV_ACTION(JUMP, sizeof(struct rte_flow_action_jump)),
2061 .next = NEXT(action_jump),
2064 [ACTION_JUMP_GROUP] = {
2066 .help = "group to redirect traffic to",
2067 .next = NEXT(action_jump, NEXT_ENTRY(UNSIGNED)),
2068 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_jump, group)),
2069 .call = parse_vc_conf,
2073 .help = "attach 32 bit value to packets",
2074 .priv = PRIV_ACTION(MARK, sizeof(struct rte_flow_action_mark)),
2075 .next = NEXT(action_mark),
2078 [ACTION_MARK_ID] = {
2080 .help = "32 bit value to return with packets",
2081 .next = NEXT(action_mark, NEXT_ENTRY(UNSIGNED)),
2082 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_mark, id)),
2083 .call = parse_vc_conf,
2087 .help = "flag packets",
2088 .priv = PRIV_ACTION(FLAG, 0),
2089 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2094 .help = "assign packets to a given queue index",
2095 .priv = PRIV_ACTION(QUEUE,
2096 sizeof(struct rte_flow_action_queue)),
2097 .next = NEXT(action_queue),
2100 [ACTION_QUEUE_INDEX] = {
2102 .help = "queue index to use",
2103 .next = NEXT(action_queue, NEXT_ENTRY(UNSIGNED)),
2104 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_queue, index)),
2105 .call = parse_vc_conf,
2109 .help = "drop packets (note: passthru has priority)",
2110 .priv = PRIV_ACTION(DROP, 0),
2111 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2116 .help = "enable counters for this rule",
2117 .priv = PRIV_ACTION(COUNT,
2118 sizeof(struct rte_flow_action_count)),
2119 .next = NEXT(action_count),
2122 [ACTION_COUNT_ID] = {
2123 .name = "identifier",
2124 .help = "counter identifier to use",
2125 .next = NEXT(action_count, NEXT_ENTRY(UNSIGNED)),
2126 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_count, id)),
2127 .call = parse_vc_conf,
2129 [ACTION_COUNT_SHARED] = {
2131 .help = "shared counter",
2132 .next = NEXT(action_count, NEXT_ENTRY(BOOLEAN)),
2133 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_count,
2135 .call = parse_vc_conf,
2139 .help = "spread packets among several queues",
2140 .priv = PRIV_ACTION(RSS, sizeof(struct action_rss_data)),
2141 .next = NEXT(action_rss),
2142 .call = parse_vc_action_rss,
2144 [ACTION_RSS_FUNC] = {
2146 .help = "RSS hash function to apply",
2147 .next = NEXT(action_rss,
2148 NEXT_ENTRY(ACTION_RSS_FUNC_DEFAULT,
2149 ACTION_RSS_FUNC_TOEPLITZ,
2150 ACTION_RSS_FUNC_SIMPLE_XOR)),
2152 [ACTION_RSS_FUNC_DEFAULT] = {
2154 .help = "default hash function",
2155 .call = parse_vc_action_rss_func,
2157 [ACTION_RSS_FUNC_TOEPLITZ] = {
2159 .help = "Toeplitz hash function",
2160 .call = parse_vc_action_rss_func,
2162 [ACTION_RSS_FUNC_SIMPLE_XOR] = {
2163 .name = "simple_xor",
2164 .help = "simple XOR hash function",
2165 .call = parse_vc_action_rss_func,
2167 [ACTION_RSS_LEVEL] = {
2169 .help = "encapsulation level for \"types\"",
2170 .next = NEXT(action_rss, NEXT_ENTRY(UNSIGNED)),
2171 .args = ARGS(ARGS_ENTRY_ARB
2172 (offsetof(struct action_rss_data, conf) +
2173 offsetof(struct rte_flow_action_rss, level),
2174 sizeof(((struct rte_flow_action_rss *)0)->
2177 [ACTION_RSS_TYPES] = {
2179 .help = "specific RSS hash types",
2180 .next = NEXT(action_rss, NEXT_ENTRY(ACTION_RSS_TYPE)),
2182 [ACTION_RSS_TYPE] = {
2184 .help = "RSS hash type",
2185 .call = parse_vc_action_rss_type,
2186 .comp = comp_vc_action_rss_type,
2188 [ACTION_RSS_KEY] = {
2190 .help = "RSS hash key",
2191 .next = NEXT(action_rss, NEXT_ENTRY(STRING)),
2192 .args = ARGS(ARGS_ENTRY_ARB(0, 0),
2194 (offsetof(struct action_rss_data, conf) +
2195 offsetof(struct rte_flow_action_rss, key_len),
2196 sizeof(((struct rte_flow_action_rss *)0)->
2198 ARGS_ENTRY(struct action_rss_data, key)),
2200 [ACTION_RSS_KEY_LEN] = {
2202 .help = "RSS hash key length in bytes",
2203 .next = NEXT(action_rss, NEXT_ENTRY(UNSIGNED)),
2204 .args = ARGS(ARGS_ENTRY_ARB_BOUNDED
2205 (offsetof(struct action_rss_data, conf) +
2206 offsetof(struct rte_flow_action_rss, key_len),
2207 sizeof(((struct rte_flow_action_rss *)0)->
2210 RSS_HASH_KEY_LENGTH)),
2212 [ACTION_RSS_QUEUES] = {
2214 .help = "queue indices to use",
2215 .next = NEXT(action_rss, NEXT_ENTRY(ACTION_RSS_QUEUE)),
2216 .call = parse_vc_conf,
2218 [ACTION_RSS_QUEUE] = {
2220 .help = "queue index",
2221 .call = parse_vc_action_rss_queue,
2222 .comp = comp_vc_action_rss_queue,
2226 .help = "direct traffic to physical function",
2227 .priv = PRIV_ACTION(PF, 0),
2228 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2233 .help = "direct traffic to a virtual function ID",
2234 .priv = PRIV_ACTION(VF, sizeof(struct rte_flow_action_vf)),
2235 .next = NEXT(action_vf),
2238 [ACTION_VF_ORIGINAL] = {
2240 .help = "use original VF ID if possible",
2241 .next = NEXT(action_vf, NEXT_ENTRY(BOOLEAN)),
2242 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_vf,
2244 .call = parse_vc_conf,
2249 .next = NEXT(action_vf, NEXT_ENTRY(UNSIGNED)),
2250 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_vf, id)),
2251 .call = parse_vc_conf,
2253 [ACTION_PHY_PORT] = {
2255 .help = "direct packets to physical port index",
2256 .priv = PRIV_ACTION(PHY_PORT,
2257 sizeof(struct rte_flow_action_phy_port)),
2258 .next = NEXT(action_phy_port),
2261 [ACTION_PHY_PORT_ORIGINAL] = {
2263 .help = "use original port index if possible",
2264 .next = NEXT(action_phy_port, NEXT_ENTRY(BOOLEAN)),
2265 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_phy_port,
2267 .call = parse_vc_conf,
2269 [ACTION_PHY_PORT_INDEX] = {
2271 .help = "physical port index",
2272 .next = NEXT(action_phy_port, NEXT_ENTRY(UNSIGNED)),
2273 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_phy_port,
2275 .call = parse_vc_conf,
2277 [ACTION_PORT_ID] = {
2279 .help = "direct matching traffic to a given DPDK port ID",
2280 .priv = PRIV_ACTION(PORT_ID,
2281 sizeof(struct rte_flow_action_port_id)),
2282 .next = NEXT(action_port_id),
2285 [ACTION_PORT_ID_ORIGINAL] = {
2287 .help = "use original DPDK port ID if possible",
2288 .next = NEXT(action_port_id, NEXT_ENTRY(BOOLEAN)),
2289 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_port_id,
2291 .call = parse_vc_conf,
2293 [ACTION_PORT_ID_ID] = {
2295 .help = "DPDK port ID",
2296 .next = NEXT(action_port_id, NEXT_ENTRY(UNSIGNED)),
2297 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_port_id, id)),
2298 .call = parse_vc_conf,
2302 .help = "meter the directed packets at given id",
2303 .priv = PRIV_ACTION(METER,
2304 sizeof(struct rte_flow_action_meter)),
2305 .next = NEXT(action_meter),
2308 [ACTION_METER_ID] = {
2310 .help = "meter id to use",
2311 .next = NEXT(action_meter, NEXT_ENTRY(UNSIGNED)),
2312 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_meter, mtr_id)),
2313 .call = parse_vc_conf,
2315 [ACTION_OF_SET_MPLS_TTL] = {
2316 .name = "of_set_mpls_ttl",
2317 .help = "OpenFlow's OFPAT_SET_MPLS_TTL",
2320 sizeof(struct rte_flow_action_of_set_mpls_ttl)),
2321 .next = NEXT(action_of_set_mpls_ttl),
2324 [ACTION_OF_SET_MPLS_TTL_MPLS_TTL] = {
2327 .next = NEXT(action_of_set_mpls_ttl, NEXT_ENTRY(UNSIGNED)),
2328 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_of_set_mpls_ttl,
2330 .call = parse_vc_conf,
2332 [ACTION_OF_DEC_MPLS_TTL] = {
2333 .name = "of_dec_mpls_ttl",
2334 .help = "OpenFlow's OFPAT_DEC_MPLS_TTL",
2335 .priv = PRIV_ACTION(OF_DEC_MPLS_TTL, 0),
2336 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2339 [ACTION_OF_SET_NW_TTL] = {
2340 .name = "of_set_nw_ttl",
2341 .help = "OpenFlow's OFPAT_SET_NW_TTL",
2344 sizeof(struct rte_flow_action_of_set_nw_ttl)),
2345 .next = NEXT(action_of_set_nw_ttl),
2348 [ACTION_OF_SET_NW_TTL_NW_TTL] = {
2351 .next = NEXT(action_of_set_nw_ttl, NEXT_ENTRY(UNSIGNED)),
2352 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_of_set_nw_ttl,
2354 .call = parse_vc_conf,
2356 [ACTION_OF_DEC_NW_TTL] = {
2357 .name = "of_dec_nw_ttl",
2358 .help = "OpenFlow's OFPAT_DEC_NW_TTL",
2359 .priv = PRIV_ACTION(OF_DEC_NW_TTL, 0),
2360 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2363 [ACTION_OF_COPY_TTL_OUT] = {
2364 .name = "of_copy_ttl_out",
2365 .help = "OpenFlow's OFPAT_COPY_TTL_OUT",
2366 .priv = PRIV_ACTION(OF_COPY_TTL_OUT, 0),
2367 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2370 [ACTION_OF_COPY_TTL_IN] = {
2371 .name = "of_copy_ttl_in",
2372 .help = "OpenFlow's OFPAT_COPY_TTL_IN",
2373 .priv = PRIV_ACTION(OF_COPY_TTL_IN, 0),
2374 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2377 [ACTION_OF_POP_VLAN] = {
2378 .name = "of_pop_vlan",
2379 .help = "OpenFlow's OFPAT_POP_VLAN",
2380 .priv = PRIV_ACTION(OF_POP_VLAN, 0),
2381 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2384 [ACTION_OF_PUSH_VLAN] = {
2385 .name = "of_push_vlan",
2386 .help = "OpenFlow's OFPAT_PUSH_VLAN",
2389 sizeof(struct rte_flow_action_of_push_vlan)),
2390 .next = NEXT(action_of_push_vlan),
2393 [ACTION_OF_PUSH_VLAN_ETHERTYPE] = {
2394 .name = "ethertype",
2395 .help = "EtherType",
2396 .next = NEXT(action_of_push_vlan, NEXT_ENTRY(UNSIGNED)),
2397 .args = ARGS(ARGS_ENTRY_HTON
2398 (struct rte_flow_action_of_push_vlan,
2400 .call = parse_vc_conf,
2402 [ACTION_OF_SET_VLAN_VID] = {
2403 .name = "of_set_vlan_vid",
2404 .help = "OpenFlow's OFPAT_SET_VLAN_VID",
2407 sizeof(struct rte_flow_action_of_set_vlan_vid)),
2408 .next = NEXT(action_of_set_vlan_vid),
2411 [ACTION_OF_SET_VLAN_VID_VLAN_VID] = {
2414 .next = NEXT(action_of_set_vlan_vid, NEXT_ENTRY(UNSIGNED)),
2415 .args = ARGS(ARGS_ENTRY_HTON
2416 (struct rte_flow_action_of_set_vlan_vid,
2418 .call = parse_vc_conf,
2420 [ACTION_OF_SET_VLAN_PCP] = {
2421 .name = "of_set_vlan_pcp",
2422 .help = "OpenFlow's OFPAT_SET_VLAN_PCP",
2425 sizeof(struct rte_flow_action_of_set_vlan_pcp)),
2426 .next = NEXT(action_of_set_vlan_pcp),
2429 [ACTION_OF_SET_VLAN_PCP_VLAN_PCP] = {
2431 .help = "VLAN priority",
2432 .next = NEXT(action_of_set_vlan_pcp, NEXT_ENTRY(UNSIGNED)),
2433 .args = ARGS(ARGS_ENTRY_HTON
2434 (struct rte_flow_action_of_set_vlan_pcp,
2436 .call = parse_vc_conf,
2438 [ACTION_OF_POP_MPLS] = {
2439 .name = "of_pop_mpls",
2440 .help = "OpenFlow's OFPAT_POP_MPLS",
2441 .priv = PRIV_ACTION(OF_POP_MPLS,
2442 sizeof(struct rte_flow_action_of_pop_mpls)),
2443 .next = NEXT(action_of_pop_mpls),
2446 [ACTION_OF_POP_MPLS_ETHERTYPE] = {
2447 .name = "ethertype",
2448 .help = "EtherType",
2449 .next = NEXT(action_of_pop_mpls, NEXT_ENTRY(UNSIGNED)),
2450 .args = ARGS(ARGS_ENTRY_HTON
2451 (struct rte_flow_action_of_pop_mpls,
2453 .call = parse_vc_conf,
2455 [ACTION_OF_PUSH_MPLS] = {
2456 .name = "of_push_mpls",
2457 .help = "OpenFlow's OFPAT_PUSH_MPLS",
2460 sizeof(struct rte_flow_action_of_push_mpls)),
2461 .next = NEXT(action_of_push_mpls),
2464 [ACTION_OF_PUSH_MPLS_ETHERTYPE] = {
2465 .name = "ethertype",
2466 .help = "EtherType",
2467 .next = NEXT(action_of_push_mpls, NEXT_ENTRY(UNSIGNED)),
2468 .args = ARGS(ARGS_ENTRY_HTON
2469 (struct rte_flow_action_of_push_mpls,
2471 .call = parse_vc_conf,
2473 [ACTION_VXLAN_ENCAP] = {
2474 .name = "vxlan_encap",
2475 .help = "VXLAN encapsulation, uses configuration set by \"set"
2477 .priv = PRIV_ACTION(VXLAN_ENCAP,
2478 sizeof(struct action_vxlan_encap_data)),
2479 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2480 .call = parse_vc_action_vxlan_encap,
2482 [ACTION_VXLAN_DECAP] = {
2483 .name = "vxlan_decap",
2484 .help = "Performs a decapsulation action by stripping all"
2485 " headers of the VXLAN tunnel network overlay from the"
2487 .priv = PRIV_ACTION(VXLAN_DECAP, 0),
2488 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2491 [ACTION_NVGRE_ENCAP] = {
2492 .name = "nvgre_encap",
2493 .help = "NVGRE encapsulation, uses configuration set by \"set"
2495 .priv = PRIV_ACTION(NVGRE_ENCAP,
2496 sizeof(struct action_nvgre_encap_data)),
2497 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2498 .call = parse_vc_action_nvgre_encap,
2500 [ACTION_NVGRE_DECAP] = {
2501 .name = "nvgre_decap",
2502 .help = "Performs a decapsulation action by stripping all"
2503 " headers of the NVGRE tunnel network overlay from the"
2505 .priv = PRIV_ACTION(NVGRE_DECAP, 0),
2506 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2509 [ACTION_SET_IPV4_SRC] = {
2510 .name = "set_ipv4_src",
2511 .help = "Set a new IPv4 source address in the outermost"
2513 .priv = PRIV_ACTION(SET_IPV4_SRC,
2514 sizeof(struct rte_flow_action_set_ipv4)),
2515 .next = NEXT(action_set_ipv4_src),
2518 [ACTION_SET_IPV4_SRC_IPV4_SRC] = {
2519 .name = "ipv4_addr",
2520 .help = "new IPv4 source address to set",
2521 .next = NEXT(action_set_ipv4_src, NEXT_ENTRY(IPV4_ADDR)),
2522 .args = ARGS(ARGS_ENTRY_HTON
2523 (struct rte_flow_action_set_ipv4, ipv4_addr)),
2524 .call = parse_vc_conf,
2526 [ACTION_SET_IPV4_DST] = {
2527 .name = "set_ipv4_dst",
2528 .help = "Set a new IPv4 destination address in the outermost"
2530 .priv = PRIV_ACTION(SET_IPV4_DST,
2531 sizeof(struct rte_flow_action_set_ipv4)),
2532 .next = NEXT(action_set_ipv4_dst),
2535 [ACTION_SET_IPV4_DST_IPV4_DST] = {
2536 .name = "ipv4_addr",
2537 .help = "new IPv4 destination address to set",
2538 .next = NEXT(action_set_ipv4_dst, NEXT_ENTRY(IPV4_ADDR)),
2539 .args = ARGS(ARGS_ENTRY_HTON
2540 (struct rte_flow_action_set_ipv4, ipv4_addr)),
2541 .call = parse_vc_conf,
2543 [ACTION_SET_IPV6_SRC] = {
2544 .name = "set_ipv6_src",
2545 .help = "Set a new IPv6 source address in the outermost"
2547 .priv = PRIV_ACTION(SET_IPV6_SRC,
2548 sizeof(struct rte_flow_action_set_ipv6)),
2549 .next = NEXT(action_set_ipv6_src),
2552 [ACTION_SET_IPV6_SRC_IPV6_SRC] = {
2553 .name = "ipv6_addr",
2554 .help = "new IPv6 source address to set",
2555 .next = NEXT(action_set_ipv6_src, NEXT_ENTRY(IPV6_ADDR)),
2556 .args = ARGS(ARGS_ENTRY_HTON
2557 (struct rte_flow_action_set_ipv6, ipv6_addr)),
2558 .call = parse_vc_conf,
2560 [ACTION_SET_IPV6_DST] = {
2561 .name = "set_ipv6_dst",
2562 .help = "Set a new IPv6 destination address in the outermost"
2564 .priv = PRIV_ACTION(SET_IPV6_DST,
2565 sizeof(struct rte_flow_action_set_ipv6)),
2566 .next = NEXT(action_set_ipv6_dst),
2569 [ACTION_SET_IPV6_DST_IPV6_DST] = {
2570 .name = "ipv6_addr",
2571 .help = "new IPv6 destination address to set",
2572 .next = NEXT(action_set_ipv6_dst, NEXT_ENTRY(IPV6_ADDR)),
2573 .args = ARGS(ARGS_ENTRY_HTON
2574 (struct rte_flow_action_set_ipv6, ipv6_addr)),
2575 .call = parse_vc_conf,
2579 /** Remove and return last entry from argument stack. */
2580 static const struct arg *
2581 pop_args(struct context *ctx)
2583 return ctx->args_num ? ctx->args[--ctx->args_num] : NULL;
2586 /** Add entry on top of the argument stack. */
2588 push_args(struct context *ctx, const struct arg *arg)
2590 if (ctx->args_num == CTX_STACK_SIZE)
2592 ctx->args[ctx->args_num++] = arg;
2596 /** Spread value into buffer according to bit-mask. */
2598 arg_entry_bf_fill(void *dst, uintmax_t val, const struct arg *arg)
2600 uint32_t i = arg->size;
2608 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
2617 unsigned int shift = 0;
2618 uint8_t *buf = (uint8_t *)dst + arg->offset + (i -= sub);
2620 for (shift = 0; arg->mask[i] >> shift; ++shift) {
2621 if (!(arg->mask[i] & (1 << shift)))
2626 *buf &= ~(1 << shift);
2627 *buf |= (val & 1) << shift;
2635 /** Compare a string with a partial one of a given length. */
2637 strcmp_partial(const char *full, const char *partial, size_t partial_len)
2639 int r = strncmp(full, partial, partial_len);
2643 if (strlen(full) <= partial_len)
2645 return full[partial_len];
2649 * Parse a prefix length and generate a bit-mask.
2651 * Last argument (ctx->args) is retrieved to determine mask size, storage
2652 * location and whether the result must use network byte ordering.
2655 parse_prefix(struct context *ctx, const struct token *token,
2656 const char *str, unsigned int len,
2657 void *buf, unsigned int size)
2659 const struct arg *arg = pop_args(ctx);
2660 static const uint8_t conv[] = "\x00\x80\xc0\xe0\xf0\xf8\xfc\xfe\xff";
2667 /* Argument is expected. */
2671 u = strtoumax(str, &end, 0);
2672 if (errno || (size_t)(end - str) != len)
2677 extra = arg_entry_bf_fill(NULL, 0, arg);
2686 if (!arg_entry_bf_fill(ctx->object, v, arg) ||
2687 !arg_entry_bf_fill(ctx->objmask, -1, arg))
2694 if (bytes > size || bytes + !!extra > size)
2698 buf = (uint8_t *)ctx->object + arg->offset;
2699 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
2701 memset((uint8_t *)buf + size - bytes, 0xff, bytes);
2702 memset(buf, 0x00, size - bytes);
2704 ((uint8_t *)buf)[size - bytes - 1] = conv[extra];
2708 memset(buf, 0xff, bytes);
2709 memset((uint8_t *)buf + bytes, 0x00, size - bytes);
2711 ((uint8_t *)buf)[bytes] = conv[extra];
2714 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
2717 push_args(ctx, arg);
2721 /** Default parsing function for token name matching. */
2723 parse_default(struct context *ctx, const struct token *token,
2724 const char *str, unsigned int len,
2725 void *buf, unsigned int size)
2730 if (strcmp_partial(token->name, str, len))
2735 /** Parse flow command, initialize output buffer for subsequent tokens. */
2737 parse_init(struct context *ctx, const struct token *token,
2738 const char *str, unsigned int len,
2739 void *buf, unsigned int size)
2741 struct buffer *out = buf;
2743 /* Token name must match. */
2744 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
2746 /* Nothing else to do if there is no buffer. */
2749 /* Make sure buffer is large enough. */
2750 if (size < sizeof(*out))
2752 /* Initialize buffer. */
2753 memset(out, 0x00, sizeof(*out));
2754 memset((uint8_t *)out + sizeof(*out), 0x22, size - sizeof(*out));
2757 ctx->objmask = NULL;
2761 /** Parse tokens for validate/create commands. */
2763 parse_vc(struct context *ctx, const struct token *token,
2764 const char *str, unsigned int len,
2765 void *buf, unsigned int size)
2767 struct buffer *out = buf;
2771 /* Token name must match. */
2772 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
2774 /* Nothing else to do if there is no buffer. */
2777 if (!out->command) {
2778 if (ctx->curr != VALIDATE && ctx->curr != CREATE)
2780 if (sizeof(*out) > size)
2782 out->command = ctx->curr;
2785 ctx->objmask = NULL;
2786 out->args.vc.data = (uint8_t *)out + size;
2790 ctx->object = &out->args.vc.attr;
2791 ctx->objmask = NULL;
2792 switch (ctx->curr) {
2797 out->args.vc.attr.ingress = 1;
2800 out->args.vc.attr.egress = 1;
2803 out->args.vc.attr.transfer = 1;
2806 out->args.vc.pattern =
2807 (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
2809 ctx->object = out->args.vc.pattern;
2810 ctx->objmask = NULL;
2813 out->args.vc.actions =
2814 (void *)RTE_ALIGN_CEIL((uintptr_t)
2815 (out->args.vc.pattern +
2816 out->args.vc.pattern_n),
2818 ctx->object = out->args.vc.actions;
2819 ctx->objmask = NULL;
2826 if (!out->args.vc.actions) {
2827 const struct parse_item_priv *priv = token->priv;
2828 struct rte_flow_item *item =
2829 out->args.vc.pattern + out->args.vc.pattern_n;
2831 data_size = priv->size * 3; /* spec, last, mask */
2832 data = (void *)RTE_ALIGN_FLOOR((uintptr_t)
2833 (out->args.vc.data - data_size),
2835 if ((uint8_t *)item + sizeof(*item) > data)
2837 *item = (struct rte_flow_item){
2840 ++out->args.vc.pattern_n;
2842 ctx->objmask = NULL;
2844 const struct parse_action_priv *priv = token->priv;
2845 struct rte_flow_action *action =
2846 out->args.vc.actions + out->args.vc.actions_n;
2848 data_size = priv->size; /* configuration */
2849 data = (void *)RTE_ALIGN_FLOOR((uintptr_t)
2850 (out->args.vc.data - data_size),
2852 if ((uint8_t *)action + sizeof(*action) > data)
2854 *action = (struct rte_flow_action){
2856 .conf = data_size ? data : NULL,
2858 ++out->args.vc.actions_n;
2859 ctx->object = action;
2860 ctx->objmask = NULL;
2862 memset(data, 0, data_size);
2863 out->args.vc.data = data;
2864 ctx->objdata = data_size;
2868 /** Parse pattern item parameter type. */
2870 parse_vc_spec(struct context *ctx, const struct token *token,
2871 const char *str, unsigned int len,
2872 void *buf, unsigned int size)
2874 struct buffer *out = buf;
2875 struct rte_flow_item *item;
2881 /* Token name must match. */
2882 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
2884 /* Parse parameter types. */
2885 switch (ctx->curr) {
2886 static const enum index prefix[] = NEXT_ENTRY(PREFIX);
2892 case ITEM_PARAM_SPEC:
2895 case ITEM_PARAM_LAST:
2898 case ITEM_PARAM_PREFIX:
2899 /* Modify next token to expect a prefix. */
2900 if (ctx->next_num < 2)
2902 ctx->next[ctx->next_num - 2] = prefix;
2904 case ITEM_PARAM_MASK:
2910 /* Nothing else to do if there is no buffer. */
2913 if (!out->args.vc.pattern_n)
2915 item = &out->args.vc.pattern[out->args.vc.pattern_n - 1];
2916 data_size = ctx->objdata / 3; /* spec, last, mask */
2917 /* Point to selected object. */
2918 ctx->object = out->args.vc.data + (data_size * index);
2920 ctx->objmask = out->args.vc.data + (data_size * 2); /* mask */
2921 item->mask = ctx->objmask;
2923 ctx->objmask = NULL;
2924 /* Update relevant item pointer. */
2925 *((const void **[]){ &item->spec, &item->last, &item->mask })[index] =
2930 /** Parse action configuration field. */
2932 parse_vc_conf(struct context *ctx, const struct token *token,
2933 const char *str, unsigned int len,
2934 void *buf, unsigned int size)
2936 struct buffer *out = buf;
2939 /* Token name must match. */
2940 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
2942 /* Nothing else to do if there is no buffer. */
2945 /* Point to selected object. */
2946 ctx->object = out->args.vc.data;
2947 ctx->objmask = NULL;
2951 /** Parse RSS action. */
2953 parse_vc_action_rss(struct context *ctx, const struct token *token,
2954 const char *str, unsigned int len,
2955 void *buf, unsigned int size)
2957 struct buffer *out = buf;
2958 struct rte_flow_action *action;
2959 struct action_rss_data *action_rss_data;
2963 ret = parse_vc(ctx, token, str, len, buf, size);
2966 /* Nothing else to do if there is no buffer. */
2969 if (!out->args.vc.actions_n)
2971 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
2972 /* Point to selected object. */
2973 ctx->object = out->args.vc.data;
2974 ctx->objmask = NULL;
2975 /* Set up default configuration. */
2976 action_rss_data = ctx->object;
2977 *action_rss_data = (struct action_rss_data){
2978 .conf = (struct rte_flow_action_rss){
2979 .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
2982 .key_len = sizeof(action_rss_data->key),
2983 .queue_num = RTE_MIN(nb_rxq, ACTION_RSS_QUEUE_NUM),
2984 .key = action_rss_data->key,
2985 .queue = action_rss_data->queue,
2987 .key = "testpmd's default RSS hash key, "
2988 "override it for better balancing",
2991 for (i = 0; i < action_rss_data->conf.queue_num; ++i)
2992 action_rss_data->queue[i] = i;
2993 if (!port_id_is_invalid(ctx->port, DISABLED_WARN) &&
2994 ctx->port != (portid_t)RTE_PORT_ALL) {
2995 struct rte_eth_dev_info info;
2997 rte_eth_dev_info_get(ctx->port, &info);
2998 action_rss_data->conf.key_len =
2999 RTE_MIN(sizeof(action_rss_data->key),
3000 info.hash_key_size);
3002 action->conf = &action_rss_data->conf;
3007 * Parse func field for RSS action.
3009 * The RTE_ETH_HASH_FUNCTION_* value to assign is derived from the
3010 * ACTION_RSS_FUNC_* index that called this function.
3013 parse_vc_action_rss_func(struct context *ctx, const struct token *token,
3014 const char *str, unsigned int len,
3015 void *buf, unsigned int size)
3017 struct action_rss_data *action_rss_data;
3018 enum rte_eth_hash_function func;
3022 /* Token name must match. */
3023 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
3025 switch (ctx->curr) {
3026 case ACTION_RSS_FUNC_DEFAULT:
3027 func = RTE_ETH_HASH_FUNCTION_DEFAULT;
3029 case ACTION_RSS_FUNC_TOEPLITZ:
3030 func = RTE_ETH_HASH_FUNCTION_TOEPLITZ;
3032 case ACTION_RSS_FUNC_SIMPLE_XOR:
3033 func = RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
3040 action_rss_data = ctx->object;
3041 action_rss_data->conf.func = func;
3046 * Parse type field for RSS action.
3048 * Valid tokens are type field names and the "end" token.
3051 parse_vc_action_rss_type(struct context *ctx, const struct token *token,
3052 const char *str, unsigned int len,
3053 void *buf, unsigned int size)
3055 static const enum index next[] = NEXT_ENTRY(ACTION_RSS_TYPE);
3056 struct action_rss_data *action_rss_data;
3062 if (ctx->curr != ACTION_RSS_TYPE)
3064 if (!(ctx->objdata >> 16) && ctx->object) {
3065 action_rss_data = ctx->object;
3066 action_rss_data->conf.types = 0;
3068 if (!strcmp_partial("end", str, len)) {
3069 ctx->objdata &= 0xffff;
3072 for (i = 0; rss_type_table[i].str; ++i)
3073 if (!strcmp_partial(rss_type_table[i].str, str, len))
3075 if (!rss_type_table[i].str)
3077 ctx->objdata = 1 << 16 | (ctx->objdata & 0xffff);
3079 if (ctx->next_num == RTE_DIM(ctx->next))
3081 ctx->next[ctx->next_num++] = next;
3084 action_rss_data = ctx->object;
3085 action_rss_data->conf.types |= rss_type_table[i].rss_type;
3090 * Parse queue field for RSS action.
3092 * Valid tokens are queue indices and the "end" token.
3095 parse_vc_action_rss_queue(struct context *ctx, const struct token *token,
3096 const char *str, unsigned int len,
3097 void *buf, unsigned int size)
3099 static const enum index next[] = NEXT_ENTRY(ACTION_RSS_QUEUE);
3100 struct action_rss_data *action_rss_data;
3107 if (ctx->curr != ACTION_RSS_QUEUE)
3109 i = ctx->objdata >> 16;
3110 if (!strcmp_partial("end", str, len)) {
3111 ctx->objdata &= 0xffff;
3114 if (i >= ACTION_RSS_QUEUE_NUM)
3117 ARGS_ENTRY_ARB(offsetof(struct action_rss_data, queue) +
3118 i * sizeof(action_rss_data->queue[i]),
3119 sizeof(action_rss_data->queue[i]))))
3121 ret = parse_int(ctx, token, str, len, NULL, 0);
3127 ctx->objdata = i << 16 | (ctx->objdata & 0xffff);
3129 if (ctx->next_num == RTE_DIM(ctx->next))
3131 ctx->next[ctx->next_num++] = next;
3135 action_rss_data = ctx->object;
3136 action_rss_data->conf.queue_num = i;
3137 action_rss_data->conf.queue = i ? action_rss_data->queue : NULL;
3141 /** Parse VXLAN encap action. */
3143 parse_vc_action_vxlan_encap(struct context *ctx, const struct token *token,
3144 const char *str, unsigned int len,
3145 void *buf, unsigned int size)
3147 struct buffer *out = buf;
3148 struct rte_flow_action *action;
3149 struct action_vxlan_encap_data *action_vxlan_encap_data;
3152 ret = parse_vc(ctx, token, str, len, buf, size);
3155 /* Nothing else to do if there is no buffer. */
3158 if (!out->args.vc.actions_n)
3160 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
3161 /* Point to selected object. */
3162 ctx->object = out->args.vc.data;
3163 ctx->objmask = NULL;
3164 /* Set up default configuration. */
3165 action_vxlan_encap_data = ctx->object;
3166 *action_vxlan_encap_data = (struct action_vxlan_encap_data){
3167 .conf = (struct rte_flow_action_vxlan_encap){
3168 .definition = action_vxlan_encap_data->items,
3172 .type = RTE_FLOW_ITEM_TYPE_ETH,
3173 .spec = &action_vxlan_encap_data->item_eth,
3174 .mask = &rte_flow_item_eth_mask,
3177 .type = RTE_FLOW_ITEM_TYPE_VLAN,
3178 .spec = &action_vxlan_encap_data->item_vlan,
3179 .mask = &rte_flow_item_vlan_mask,
3182 .type = RTE_FLOW_ITEM_TYPE_IPV4,
3183 .spec = &action_vxlan_encap_data->item_ipv4,
3184 .mask = &rte_flow_item_ipv4_mask,
3187 .type = RTE_FLOW_ITEM_TYPE_UDP,
3188 .spec = &action_vxlan_encap_data->item_udp,
3189 .mask = &rte_flow_item_udp_mask,
3192 .type = RTE_FLOW_ITEM_TYPE_VXLAN,
3193 .spec = &action_vxlan_encap_data->item_vxlan,
3194 .mask = &rte_flow_item_vxlan_mask,
3197 .type = RTE_FLOW_ITEM_TYPE_END,
3202 .tci = vxlan_encap_conf.vlan_tci,
3206 .src_addr = vxlan_encap_conf.ipv4_src,
3207 .dst_addr = vxlan_encap_conf.ipv4_dst,
3210 .src_port = vxlan_encap_conf.udp_src,
3211 .dst_port = vxlan_encap_conf.udp_dst,
3213 .item_vxlan.flags = 0,
3215 memcpy(action_vxlan_encap_data->item_eth.dst.addr_bytes,
3216 vxlan_encap_conf.eth_dst, ETHER_ADDR_LEN);
3217 memcpy(action_vxlan_encap_data->item_eth.src.addr_bytes,
3218 vxlan_encap_conf.eth_src, ETHER_ADDR_LEN);
3219 if (!vxlan_encap_conf.select_ipv4) {
3220 memcpy(&action_vxlan_encap_data->item_ipv6.hdr.src_addr,
3221 &vxlan_encap_conf.ipv6_src,
3222 sizeof(vxlan_encap_conf.ipv6_src));
3223 memcpy(&action_vxlan_encap_data->item_ipv6.hdr.dst_addr,
3224 &vxlan_encap_conf.ipv6_dst,
3225 sizeof(vxlan_encap_conf.ipv6_dst));
3226 action_vxlan_encap_data->items[2] = (struct rte_flow_item){
3227 .type = RTE_FLOW_ITEM_TYPE_IPV6,
3228 .spec = &action_vxlan_encap_data->item_ipv6,
3229 .mask = &rte_flow_item_ipv6_mask,
3232 if (!vxlan_encap_conf.select_vlan)
3233 action_vxlan_encap_data->items[1].type =
3234 RTE_FLOW_ITEM_TYPE_VOID;
3235 memcpy(action_vxlan_encap_data->item_vxlan.vni, vxlan_encap_conf.vni,
3236 RTE_DIM(vxlan_encap_conf.vni));
3237 action->conf = &action_vxlan_encap_data->conf;
3241 /** Parse NVGRE encap action. */
3243 parse_vc_action_nvgre_encap(struct context *ctx, const struct token *token,
3244 const char *str, unsigned int len,
3245 void *buf, unsigned int size)
3247 struct buffer *out = buf;
3248 struct rte_flow_action *action;
3249 struct action_nvgre_encap_data *action_nvgre_encap_data;
3252 ret = parse_vc(ctx, token, str, len, buf, size);
3255 /* Nothing else to do if there is no buffer. */
3258 if (!out->args.vc.actions_n)
3260 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
3261 /* Point to selected object. */
3262 ctx->object = out->args.vc.data;
3263 ctx->objmask = NULL;
3264 /* Set up default configuration. */
3265 action_nvgre_encap_data = ctx->object;
3266 *action_nvgre_encap_data = (struct action_nvgre_encap_data){
3267 .conf = (struct rte_flow_action_nvgre_encap){
3268 .definition = action_nvgre_encap_data->items,
3272 .type = RTE_FLOW_ITEM_TYPE_ETH,
3273 .spec = &action_nvgre_encap_data->item_eth,
3274 .mask = &rte_flow_item_eth_mask,
3277 .type = RTE_FLOW_ITEM_TYPE_VLAN,
3278 .spec = &action_nvgre_encap_data->item_vlan,
3279 .mask = &rte_flow_item_vlan_mask,
3282 .type = RTE_FLOW_ITEM_TYPE_IPV4,
3283 .spec = &action_nvgre_encap_data->item_ipv4,
3284 .mask = &rte_flow_item_ipv4_mask,
3287 .type = RTE_FLOW_ITEM_TYPE_NVGRE,
3288 .spec = &action_nvgre_encap_data->item_nvgre,
3289 .mask = &rte_flow_item_nvgre_mask,
3292 .type = RTE_FLOW_ITEM_TYPE_END,
3297 .tci = nvgre_encap_conf.vlan_tci,
3301 .src_addr = nvgre_encap_conf.ipv4_src,
3302 .dst_addr = nvgre_encap_conf.ipv4_dst,
3304 .item_nvgre.flow_id = 0,
3306 memcpy(action_nvgre_encap_data->item_eth.dst.addr_bytes,
3307 nvgre_encap_conf.eth_dst, ETHER_ADDR_LEN);
3308 memcpy(action_nvgre_encap_data->item_eth.src.addr_bytes,
3309 nvgre_encap_conf.eth_src, ETHER_ADDR_LEN);
3310 if (!nvgre_encap_conf.select_ipv4) {
3311 memcpy(&action_nvgre_encap_data->item_ipv6.hdr.src_addr,
3312 &nvgre_encap_conf.ipv6_src,
3313 sizeof(nvgre_encap_conf.ipv6_src));
3314 memcpy(&action_nvgre_encap_data->item_ipv6.hdr.dst_addr,
3315 &nvgre_encap_conf.ipv6_dst,
3316 sizeof(nvgre_encap_conf.ipv6_dst));
3317 action_nvgre_encap_data->items[2] = (struct rte_flow_item){
3318 .type = RTE_FLOW_ITEM_TYPE_IPV6,
3319 .spec = &action_nvgre_encap_data->item_ipv6,
3320 .mask = &rte_flow_item_ipv6_mask,
3323 if (!nvgre_encap_conf.select_vlan)
3324 action_nvgre_encap_data->items[1].type =
3325 RTE_FLOW_ITEM_TYPE_VOID;
3326 memcpy(action_nvgre_encap_data->item_nvgre.tni, nvgre_encap_conf.tni,
3327 RTE_DIM(nvgre_encap_conf.tni));
3328 action->conf = &action_nvgre_encap_data->conf;
3332 /** Parse tokens for destroy command. */
3334 parse_destroy(struct context *ctx, const struct token *token,
3335 const char *str, unsigned int len,
3336 void *buf, unsigned int size)
3338 struct buffer *out = buf;
3340 /* Token name must match. */
3341 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
3343 /* Nothing else to do if there is no buffer. */
3346 if (!out->command) {
3347 if (ctx->curr != DESTROY)
3349 if (sizeof(*out) > size)
3351 out->command = ctx->curr;
3354 ctx->objmask = NULL;
3355 out->args.destroy.rule =
3356 (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
3360 if (((uint8_t *)(out->args.destroy.rule + out->args.destroy.rule_n) +
3361 sizeof(*out->args.destroy.rule)) > (uint8_t *)out + size)
3364 ctx->object = out->args.destroy.rule + out->args.destroy.rule_n++;
3365 ctx->objmask = NULL;
3369 /** Parse tokens for flush command. */
3371 parse_flush(struct context *ctx, const struct token *token,
3372 const char *str, unsigned int len,
3373 void *buf, unsigned int size)
3375 struct buffer *out = buf;
3377 /* Token name must match. */
3378 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
3380 /* Nothing else to do if there is no buffer. */
3383 if (!out->command) {
3384 if (ctx->curr != FLUSH)
3386 if (sizeof(*out) > size)
3388 out->command = ctx->curr;
3391 ctx->objmask = NULL;
3396 /** Parse tokens for query command. */
3398 parse_query(struct context *ctx, const struct token *token,
3399 const char *str, unsigned int len,
3400 void *buf, unsigned int size)
3402 struct buffer *out = buf;
3404 /* Token name must match. */
3405 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
3407 /* Nothing else to do if there is no buffer. */
3410 if (!out->command) {
3411 if (ctx->curr != QUERY)
3413 if (sizeof(*out) > size)
3415 out->command = ctx->curr;
3418 ctx->objmask = NULL;
3423 /** Parse action names. */
3425 parse_action(struct context *ctx, const struct token *token,
3426 const char *str, unsigned int len,
3427 void *buf, unsigned int size)
3429 struct buffer *out = buf;
3430 const struct arg *arg = pop_args(ctx);
3434 /* Argument is expected. */
3437 /* Parse action name. */
3438 for (i = 0; next_action[i]; ++i) {
3439 const struct parse_action_priv *priv;
3441 token = &token_list[next_action[i]];
3442 if (strcmp_partial(token->name, str, len))
3448 memcpy((uint8_t *)ctx->object + arg->offset,
3454 push_args(ctx, arg);
3458 /** Parse tokens for list command. */
3460 parse_list(struct context *ctx, const struct token *token,
3461 const char *str, unsigned int len,
3462 void *buf, unsigned int size)
3464 struct buffer *out = buf;
3466 /* Token name must match. */
3467 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
3469 /* Nothing else to do if there is no buffer. */
3472 if (!out->command) {
3473 if (ctx->curr != LIST)
3475 if (sizeof(*out) > size)
3477 out->command = ctx->curr;
3480 ctx->objmask = NULL;
3481 out->args.list.group =
3482 (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
3486 if (((uint8_t *)(out->args.list.group + out->args.list.group_n) +
3487 sizeof(*out->args.list.group)) > (uint8_t *)out + size)
3490 ctx->object = out->args.list.group + out->args.list.group_n++;
3491 ctx->objmask = NULL;
3495 /** Parse tokens for isolate command. */
3497 parse_isolate(struct context *ctx, const struct token *token,
3498 const char *str, unsigned int len,
3499 void *buf, unsigned int size)
3501 struct buffer *out = buf;
3503 /* Token name must match. */
3504 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
3506 /* Nothing else to do if there is no buffer. */
3509 if (!out->command) {
3510 if (ctx->curr != ISOLATE)
3512 if (sizeof(*out) > size)
3514 out->command = ctx->curr;
3517 ctx->objmask = NULL;
3523 * Parse signed/unsigned integers 8 to 64-bit long.
3525 * Last argument (ctx->args) is retrieved to determine integer type and
3529 parse_int(struct context *ctx, const struct token *token,
3530 const char *str, unsigned int len,
3531 void *buf, unsigned int size)
3533 const struct arg *arg = pop_args(ctx);
3538 /* Argument is expected. */
3543 (uintmax_t)strtoimax(str, &end, 0) :
3544 strtoumax(str, &end, 0);
3545 if (errno || (size_t)(end - str) != len)
3548 ((arg->sign && ((intmax_t)u < (intmax_t)arg->min ||
3549 (intmax_t)u > (intmax_t)arg->max)) ||
3550 (!arg->sign && (u < arg->min || u > arg->max))))
3555 if (!arg_entry_bf_fill(ctx->object, u, arg) ||
3556 !arg_entry_bf_fill(ctx->objmask, -1, arg))
3560 buf = (uint8_t *)ctx->object + arg->offset;
3564 case sizeof(uint8_t):
3565 *(uint8_t *)buf = u;
3567 case sizeof(uint16_t):
3568 *(uint16_t *)buf = arg->hton ? rte_cpu_to_be_16(u) : u;
3570 case sizeof(uint8_t [3]):
3571 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
3573 ((uint8_t *)buf)[0] = u;
3574 ((uint8_t *)buf)[1] = u >> 8;
3575 ((uint8_t *)buf)[2] = u >> 16;
3579 ((uint8_t *)buf)[0] = u >> 16;
3580 ((uint8_t *)buf)[1] = u >> 8;
3581 ((uint8_t *)buf)[2] = u;
3583 case sizeof(uint32_t):
3584 *(uint32_t *)buf = arg->hton ? rte_cpu_to_be_32(u) : u;
3586 case sizeof(uint64_t):
3587 *(uint64_t *)buf = arg->hton ? rte_cpu_to_be_64(u) : u;
3592 if (ctx->objmask && buf != (uint8_t *)ctx->objmask + arg->offset) {
3594 buf = (uint8_t *)ctx->objmask + arg->offset;
3599 push_args(ctx, arg);
3606 * Three arguments (ctx->args) are retrieved from the stack to store data,
3607 * its actual length and address (in that order).
3610 parse_string(struct context *ctx, const struct token *token,
3611 const char *str, unsigned int len,
3612 void *buf, unsigned int size)
3614 const struct arg *arg_data = pop_args(ctx);
3615 const struct arg *arg_len = pop_args(ctx);
3616 const struct arg *arg_addr = pop_args(ctx);
3617 char tmp[16]; /* Ought to be enough. */
3620 /* Arguments are expected. */
3624 push_args(ctx, arg_data);
3628 push_args(ctx, arg_len);
3629 push_args(ctx, arg_data);
3632 size = arg_data->size;
3633 /* Bit-mask fill is not supported. */
3634 if (arg_data->mask || size < len)
3638 /* Let parse_int() fill length information first. */
3639 ret = snprintf(tmp, sizeof(tmp), "%u", len);
3642 push_args(ctx, arg_len);
3643 ret = parse_int(ctx, token, tmp, ret, NULL, 0);
3648 buf = (uint8_t *)ctx->object + arg_data->offset;
3649 /* Output buffer is not necessarily NUL-terminated. */
3650 memcpy(buf, str, len);
3651 memset((uint8_t *)buf + len, 0x00, size - len);
3653 memset((uint8_t *)ctx->objmask + arg_data->offset, 0xff, len);
3654 /* Save address if requested. */
3655 if (arg_addr->size) {
3656 memcpy((uint8_t *)ctx->object + arg_addr->offset,
3658 (uint8_t *)ctx->object + arg_data->offset
3662 memcpy((uint8_t *)ctx->objmask + arg_addr->offset,
3664 (uint8_t *)ctx->objmask + arg_data->offset
3670 push_args(ctx, arg_addr);
3671 push_args(ctx, arg_len);
3672 push_args(ctx, arg_data);
3677 * Parse a MAC address.
3679 * Last argument (ctx->args) is retrieved to determine storage size and
3683 parse_mac_addr(struct context *ctx, const struct token *token,
3684 const char *str, unsigned int len,
3685 void *buf, unsigned int size)
3687 const struct arg *arg = pop_args(ctx);
3688 struct ether_addr tmp;
3692 /* Argument is expected. */
3696 /* Bit-mask fill is not supported. */
3697 if (arg->mask || size != sizeof(tmp))
3699 /* Only network endian is supported. */
3702 ret = cmdline_parse_etheraddr(NULL, str, &tmp, size);
3703 if (ret < 0 || (unsigned int)ret != len)
3707 buf = (uint8_t *)ctx->object + arg->offset;
3708 memcpy(buf, &tmp, size);
3710 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
3713 push_args(ctx, arg);
3718 * Parse an IPv4 address.
3720 * Last argument (ctx->args) is retrieved to determine storage size and
3724 parse_ipv4_addr(struct context *ctx, const struct token *token,
3725 const char *str, unsigned int len,
3726 void *buf, unsigned int size)
3728 const struct arg *arg = pop_args(ctx);
3733 /* Argument is expected. */
3737 /* Bit-mask fill is not supported. */
3738 if (arg->mask || size != sizeof(tmp))
3740 /* Only network endian is supported. */
3743 memcpy(str2, str, len);
3745 ret = inet_pton(AF_INET, str2, &tmp);
3747 /* Attempt integer parsing. */
3748 push_args(ctx, arg);
3749 return parse_int(ctx, token, str, len, buf, size);
3753 buf = (uint8_t *)ctx->object + arg->offset;
3754 memcpy(buf, &tmp, size);
3756 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
3759 push_args(ctx, arg);
3764 * Parse an IPv6 address.
3766 * Last argument (ctx->args) is retrieved to determine storage size and
3770 parse_ipv6_addr(struct context *ctx, const struct token *token,
3771 const char *str, unsigned int len,
3772 void *buf, unsigned int size)
3774 const struct arg *arg = pop_args(ctx);
3776 struct in6_addr tmp;
3780 /* Argument is expected. */
3784 /* Bit-mask fill is not supported. */
3785 if (arg->mask || size != sizeof(tmp))
3787 /* Only network endian is supported. */
3790 memcpy(str2, str, len);
3792 ret = inet_pton(AF_INET6, str2, &tmp);
3797 buf = (uint8_t *)ctx->object + arg->offset;
3798 memcpy(buf, &tmp, size);
3800 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
3803 push_args(ctx, arg);
3807 /** Boolean values (even indices stand for false). */
3808 static const char *const boolean_name[] = {
3818 * Parse a boolean value.
3820 * Last argument (ctx->args) is retrieved to determine storage size and
3824 parse_boolean(struct context *ctx, const struct token *token,
3825 const char *str, unsigned int len,
3826 void *buf, unsigned int size)
3828 const struct arg *arg = pop_args(ctx);
3832 /* Argument is expected. */
3835 for (i = 0; boolean_name[i]; ++i)
3836 if (!strcmp_partial(boolean_name[i], str, len))
3838 /* Process token as integer. */
3839 if (boolean_name[i])
3840 str = i & 1 ? "1" : "0";
3841 push_args(ctx, arg);
3842 ret = parse_int(ctx, token, str, strlen(str), buf, size);
3843 return ret > 0 ? (int)len : ret;
3846 /** Parse port and update context. */
3848 parse_port(struct context *ctx, const struct token *token,
3849 const char *str, unsigned int len,
3850 void *buf, unsigned int size)
3852 struct buffer *out = &(struct buffer){ .port = 0 };
3860 ctx->objmask = NULL;
3861 size = sizeof(*out);
3863 ret = parse_int(ctx, token, str, len, out, size);
3865 ctx->port = out->port;
3871 /** No completion. */
3873 comp_none(struct context *ctx, const struct token *token,
3874 unsigned int ent, char *buf, unsigned int size)
3884 /** Complete boolean values. */
3886 comp_boolean(struct context *ctx, const struct token *token,
3887 unsigned int ent, char *buf, unsigned int size)
3893 for (i = 0; boolean_name[i]; ++i)
3894 if (buf && i == ent)
3895 return snprintf(buf, size, "%s", boolean_name[i]);
3901 /** Complete action names. */
3903 comp_action(struct context *ctx, const struct token *token,
3904 unsigned int ent, char *buf, unsigned int size)
3910 for (i = 0; next_action[i]; ++i)
3911 if (buf && i == ent)
3912 return snprintf(buf, size, "%s",
3913 token_list[next_action[i]].name);
3919 /** Complete available ports. */
3921 comp_port(struct context *ctx, const struct token *token,
3922 unsigned int ent, char *buf, unsigned int size)
3929 RTE_ETH_FOREACH_DEV(p) {
3930 if (buf && i == ent)
3931 return snprintf(buf, size, "%u", p);
3939 /** Complete available rule IDs. */
3941 comp_rule_id(struct context *ctx, const struct token *token,
3942 unsigned int ent, char *buf, unsigned int size)
3945 struct rte_port *port;
3946 struct port_flow *pf;
3949 if (port_id_is_invalid(ctx->port, DISABLED_WARN) ||
3950 ctx->port == (portid_t)RTE_PORT_ALL)
3952 port = &ports[ctx->port];
3953 for (pf = port->flow_list; pf != NULL; pf = pf->next) {
3954 if (buf && i == ent)
3955 return snprintf(buf, size, "%u", pf->id);
3963 /** Complete type field for RSS action. */
3965 comp_vc_action_rss_type(struct context *ctx, const struct token *token,
3966 unsigned int ent, char *buf, unsigned int size)
3972 for (i = 0; rss_type_table[i].str; ++i)
3977 return snprintf(buf, size, "%s", rss_type_table[ent].str);
3979 return snprintf(buf, size, "end");
3983 /** Complete queue field for RSS action. */
3985 comp_vc_action_rss_queue(struct context *ctx, const struct token *token,
3986 unsigned int ent, char *buf, unsigned int size)
3993 return snprintf(buf, size, "%u", ent);
3995 return snprintf(buf, size, "end");
3999 /** Internal context. */
4000 static struct context cmd_flow_context;
4002 /** Global parser instance (cmdline API). */
4003 cmdline_parse_inst_t cmd_flow;
4005 /** Initialize context. */
4007 cmd_flow_context_init(struct context *ctx)
4009 /* A full memset() is not necessary. */
4019 ctx->objmask = NULL;
4022 /** Parse a token (cmdline API). */
4024 cmd_flow_parse(cmdline_parse_token_hdr_t *hdr, const char *src, void *result,
4027 struct context *ctx = &cmd_flow_context;
4028 const struct token *token;
4029 const enum index *list;
4034 token = &token_list[ctx->curr];
4035 /* Check argument length. */
4038 for (len = 0; src[len]; ++len)
4039 if (src[len] == '#' || isspace(src[len]))
4043 /* Last argument and EOL detection. */
4044 for (i = len; src[i]; ++i)
4045 if (src[i] == '#' || src[i] == '\r' || src[i] == '\n')
4047 else if (!isspace(src[i])) {
4052 if (src[i] == '\r' || src[i] == '\n') {
4056 /* Initialize context if necessary. */
4057 if (!ctx->next_num) {
4060 ctx->next[ctx->next_num++] = token->next[0];
4062 /* Process argument through candidates. */
4063 ctx->prev = ctx->curr;
4064 list = ctx->next[ctx->next_num - 1];
4065 for (i = 0; list[i]; ++i) {
4066 const struct token *next = &token_list[list[i]];
4069 ctx->curr = list[i];
4071 tmp = next->call(ctx, next, src, len, result, size);
4073 tmp = parse_default(ctx, next, src, len, result, size);
4074 if (tmp == -1 || tmp != len)
4082 /* Push subsequent tokens if any. */
4084 for (i = 0; token->next[i]; ++i) {
4085 if (ctx->next_num == RTE_DIM(ctx->next))
4087 ctx->next[ctx->next_num++] = token->next[i];
4089 /* Push arguments if any. */
4091 for (i = 0; token->args[i]; ++i) {
4092 if (ctx->args_num == RTE_DIM(ctx->args))
4094 ctx->args[ctx->args_num++] = token->args[i];
4099 /** Return number of completion entries (cmdline API). */
4101 cmd_flow_complete_get_nb(cmdline_parse_token_hdr_t *hdr)
4103 struct context *ctx = &cmd_flow_context;
4104 const struct token *token = &token_list[ctx->curr];
4105 const enum index *list;
4109 /* Count number of tokens in current list. */
4111 list = ctx->next[ctx->next_num - 1];
4113 list = token->next[0];
4114 for (i = 0; list[i]; ++i)
4119 * If there is a single token, use its completion callback, otherwise
4120 * return the number of entries.
4122 token = &token_list[list[0]];
4123 if (i == 1 && token->comp) {
4124 /* Save index for cmd_flow_get_help(). */
4125 ctx->prev = list[0];
4126 return token->comp(ctx, token, 0, NULL, 0);
4131 /** Return a completion entry (cmdline API). */
4133 cmd_flow_complete_get_elt(cmdline_parse_token_hdr_t *hdr, int index,
4134 char *dst, unsigned int size)
4136 struct context *ctx = &cmd_flow_context;
4137 const struct token *token = &token_list[ctx->curr];
4138 const enum index *list;
4142 /* Count number of tokens in current list. */
4144 list = ctx->next[ctx->next_num - 1];
4146 list = token->next[0];
4147 for (i = 0; list[i]; ++i)
4151 /* If there is a single token, use its completion callback. */
4152 token = &token_list[list[0]];
4153 if (i == 1 && token->comp) {
4154 /* Save index for cmd_flow_get_help(). */
4155 ctx->prev = list[0];
4156 return token->comp(ctx, token, index, dst, size) < 0 ? -1 : 0;
4158 /* Otherwise make sure the index is valid and use defaults. */
4161 token = &token_list[list[index]];
4162 snprintf(dst, size, "%s", token->name);
4163 /* Save index for cmd_flow_get_help(). */
4164 ctx->prev = list[index];
4168 /** Populate help strings for current token (cmdline API). */
4170 cmd_flow_get_help(cmdline_parse_token_hdr_t *hdr, char *dst, unsigned int size)
4172 struct context *ctx = &cmd_flow_context;
4173 const struct token *token = &token_list[ctx->prev];
4178 /* Set token type and update global help with details. */
4179 snprintf(dst, size, "%s", (token->type ? token->type : "TOKEN"));
4181 cmd_flow.help_str = token->help;
4183 cmd_flow.help_str = token->name;
4187 /** Token definition template (cmdline API). */
4188 static struct cmdline_token_hdr cmd_flow_token_hdr = {
4189 .ops = &(struct cmdline_token_ops){
4190 .parse = cmd_flow_parse,
4191 .complete_get_nb = cmd_flow_complete_get_nb,
4192 .complete_get_elt = cmd_flow_complete_get_elt,
4193 .get_help = cmd_flow_get_help,
4198 /** Populate the next dynamic token. */
4200 cmd_flow_tok(cmdline_parse_token_hdr_t **hdr,
4201 cmdline_parse_token_hdr_t **hdr_inst)
4203 struct context *ctx = &cmd_flow_context;
4205 /* Always reinitialize context before requesting the first token. */
4206 if (!(hdr_inst - cmd_flow.tokens))
4207 cmd_flow_context_init(ctx);
4208 /* Return NULL when no more tokens are expected. */
4209 if (!ctx->next_num && ctx->curr) {
4213 /* Determine if command should end here. */
4214 if (ctx->eol && ctx->last && ctx->next_num) {
4215 const enum index *list = ctx->next[ctx->next_num - 1];
4218 for (i = 0; list[i]; ++i) {
4225 *hdr = &cmd_flow_token_hdr;
4228 /** Dispatch parsed buffer to function calls. */
4230 cmd_flow_parsed(const struct buffer *in)
4232 switch (in->command) {
4234 port_flow_validate(in->port, &in->args.vc.attr,
4235 in->args.vc.pattern, in->args.vc.actions);
4238 port_flow_create(in->port, &in->args.vc.attr,
4239 in->args.vc.pattern, in->args.vc.actions);
4242 port_flow_destroy(in->port, in->args.destroy.rule_n,
4243 in->args.destroy.rule);
4246 port_flow_flush(in->port);
4249 port_flow_query(in->port, in->args.query.rule,
4250 &in->args.query.action);
4253 port_flow_list(in->port, in->args.list.group_n,
4254 in->args.list.group);
4257 port_flow_isolate(in->port, in->args.isolate.set);
4264 /** Token generator and output processing callback (cmdline API). */
4266 cmd_flow_cb(void *arg0, struct cmdline *cl, void *arg2)
4269 cmd_flow_tok(arg0, arg2);
4271 cmd_flow_parsed(arg0);
4274 /** Global parser instance (cmdline API). */
4275 cmdline_parse_inst_t cmd_flow = {
4277 .data = NULL, /**< Unused. */
4278 .help_str = NULL, /**< Updated by cmd_flow_get_help(). */
4281 }, /**< Tokens are returned by cmd_flow_tok(). */