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,
255 ACTION_SET_TP_SRC_TP_SRC,
257 ACTION_SET_TP_DST_TP_DST,
264 /** Maximum size for pattern in struct rte_flow_item_raw. */
265 #define ITEM_RAW_PATTERN_SIZE 40
267 /** Storage size for struct rte_flow_item_raw including pattern. */
268 #define ITEM_RAW_SIZE \
269 (sizeof(struct rte_flow_item_raw) + ITEM_RAW_PATTERN_SIZE)
271 /** Maximum number of queue indices in struct rte_flow_action_rss. */
272 #define ACTION_RSS_QUEUE_NUM 32
274 /** Storage for struct rte_flow_action_rss including external data. */
275 struct action_rss_data {
276 struct rte_flow_action_rss conf;
277 uint8_t key[RSS_HASH_KEY_LENGTH];
278 uint16_t queue[ACTION_RSS_QUEUE_NUM];
281 /** Maximum number of items in struct rte_flow_action_vxlan_encap. */
282 #define ACTION_VXLAN_ENCAP_ITEMS_NUM 6
284 /** Storage for struct rte_flow_action_vxlan_encap including external data. */
285 struct action_vxlan_encap_data {
286 struct rte_flow_action_vxlan_encap conf;
287 struct rte_flow_item items[ACTION_VXLAN_ENCAP_ITEMS_NUM];
288 struct rte_flow_item_eth item_eth;
289 struct rte_flow_item_vlan item_vlan;
291 struct rte_flow_item_ipv4 item_ipv4;
292 struct rte_flow_item_ipv6 item_ipv6;
294 struct rte_flow_item_udp item_udp;
295 struct rte_flow_item_vxlan item_vxlan;
298 /** Maximum number of items in struct rte_flow_action_nvgre_encap. */
299 #define ACTION_NVGRE_ENCAP_ITEMS_NUM 5
301 /** Storage for struct rte_flow_action_nvgre_encap including external data. */
302 struct action_nvgre_encap_data {
303 struct rte_flow_action_nvgre_encap conf;
304 struct rte_flow_item items[ACTION_NVGRE_ENCAP_ITEMS_NUM];
305 struct rte_flow_item_eth item_eth;
306 struct rte_flow_item_vlan item_vlan;
308 struct rte_flow_item_ipv4 item_ipv4;
309 struct rte_flow_item_ipv6 item_ipv6;
311 struct rte_flow_item_nvgre item_nvgre;
314 /** Maximum number of subsequent tokens and arguments on the stack. */
315 #define CTX_STACK_SIZE 16
317 /** Parser context. */
319 /** Stack of subsequent token lists to process. */
320 const enum index *next[CTX_STACK_SIZE];
321 /** Arguments for stacked tokens. */
322 const void *args[CTX_STACK_SIZE];
323 enum index curr; /**< Current token index. */
324 enum index prev; /**< Index of the last token seen. */
325 int next_num; /**< Number of entries in next[]. */
326 int args_num; /**< Number of entries in args[]. */
327 uint32_t eol:1; /**< EOL has been detected. */
328 uint32_t last:1; /**< No more arguments. */
329 portid_t port; /**< Current port ID (for completions). */
330 uint32_t objdata; /**< Object-specific data. */
331 void *object; /**< Address of current object for relative offsets. */
332 void *objmask; /**< Object a full mask must be written to. */
335 /** Token argument. */
337 uint32_t hton:1; /**< Use network byte ordering. */
338 uint32_t sign:1; /**< Value is signed. */
339 uint32_t bounded:1; /**< Value is bounded. */
340 uintmax_t min; /**< Minimum value if bounded. */
341 uintmax_t max; /**< Maximum value if bounded. */
342 uint32_t offset; /**< Relative offset from ctx->object. */
343 uint32_t size; /**< Field size. */
344 const uint8_t *mask; /**< Bit-mask to use instead of offset/size. */
347 /** Parser token definition. */
349 /** Type displayed during completion (defaults to "TOKEN"). */
351 /** Help displayed during completion (defaults to token name). */
353 /** Private data used by parser functions. */
356 * Lists of subsequent tokens to push on the stack. Each call to the
357 * parser consumes the last entry of that stack.
359 const enum index *const *next;
360 /** Arguments stack for subsequent tokens that need them. */
361 const struct arg *const *args;
363 * Token-processing callback, returns -1 in case of error, the
364 * length of the matched string otherwise. If NULL, attempts to
365 * match the token name.
367 * If buf is not NULL, the result should be stored in it according
368 * to context. An error is returned if not large enough.
370 int (*call)(struct context *ctx, const struct token *token,
371 const char *str, unsigned int len,
372 void *buf, unsigned int size);
374 * Callback that provides possible values for this token, used for
375 * completion. Returns -1 in case of error, the number of possible
376 * values otherwise. If NULL, the token name is used.
378 * If buf is not NULL, entry index ent is written to buf and the
379 * full length of the entry is returned (same behavior as
382 int (*comp)(struct context *ctx, const struct token *token,
383 unsigned int ent, char *buf, unsigned int size);
384 /** Mandatory token name, no default value. */
388 /** Static initializer for the next field. */
389 #define NEXT(...) (const enum index *const []){ __VA_ARGS__, NULL, }
391 /** Static initializer for a NEXT() entry. */
392 #define NEXT_ENTRY(...) (const enum index []){ __VA_ARGS__, ZERO, }
394 /** Static initializer for the args field. */
395 #define ARGS(...) (const struct arg *const []){ __VA_ARGS__, NULL, }
397 /** Static initializer for ARGS() to target a field. */
398 #define ARGS_ENTRY(s, f) \
399 (&(const struct arg){ \
400 .offset = offsetof(s, f), \
401 .size = sizeof(((s *)0)->f), \
404 /** Static initializer for ARGS() to target a bit-field. */
405 #define ARGS_ENTRY_BF(s, f, b) \
406 (&(const struct arg){ \
408 .mask = (const void *)&(const s){ .f = (1 << (b)) - 1 }, \
411 /** Static initializer for ARGS() to target an arbitrary bit-mask. */
412 #define ARGS_ENTRY_MASK(s, f, m) \
413 (&(const struct arg){ \
414 .offset = offsetof(s, f), \
415 .size = sizeof(((s *)0)->f), \
416 .mask = (const void *)(m), \
419 /** Same as ARGS_ENTRY_MASK() using network byte ordering for the value. */
420 #define ARGS_ENTRY_MASK_HTON(s, f, m) \
421 (&(const struct arg){ \
423 .offset = offsetof(s, f), \
424 .size = sizeof(((s *)0)->f), \
425 .mask = (const void *)(m), \
428 /** Static initializer for ARGS() to target a pointer. */
429 #define ARGS_ENTRY_PTR(s, f) \
430 (&(const struct arg){ \
431 .size = sizeof(*((s *)0)->f), \
434 /** Static initializer for ARGS() with arbitrary offset and size. */
435 #define ARGS_ENTRY_ARB(o, s) \
436 (&(const struct arg){ \
441 /** Same as ARGS_ENTRY_ARB() with bounded values. */
442 #define ARGS_ENTRY_ARB_BOUNDED(o, s, i, a) \
443 (&(const struct arg){ \
451 /** Same as ARGS_ENTRY() using network byte ordering. */
452 #define ARGS_ENTRY_HTON(s, f) \
453 (&(const struct arg){ \
455 .offset = offsetof(s, f), \
456 .size = sizeof(((s *)0)->f), \
459 /** Parser output buffer layout expected by cmd_flow_parsed(). */
461 enum index command; /**< Flow command. */
462 portid_t port; /**< Affected port ID. */
465 struct rte_flow_attr attr;
466 struct rte_flow_item *pattern;
467 struct rte_flow_action *actions;
471 } vc; /**< Validate/create arguments. */
475 } destroy; /**< Destroy arguments. */
478 struct rte_flow_action action;
479 } query; /**< Query arguments. */
483 } list; /**< List arguments. */
486 } isolate; /**< Isolated mode arguments. */
487 } args; /**< Command arguments. */
490 /** Private data for pattern items. */
491 struct parse_item_priv {
492 enum rte_flow_item_type type; /**< Item type. */
493 uint32_t size; /**< Size of item specification structure. */
496 #define PRIV_ITEM(t, s) \
497 (&(const struct parse_item_priv){ \
498 .type = RTE_FLOW_ITEM_TYPE_ ## t, \
502 /** Private data for actions. */
503 struct parse_action_priv {
504 enum rte_flow_action_type type; /**< Action type. */
505 uint32_t size; /**< Size of action configuration structure. */
508 #define PRIV_ACTION(t, s) \
509 (&(const struct parse_action_priv){ \
510 .type = RTE_FLOW_ACTION_TYPE_ ## t, \
514 static const enum index next_vc_attr[] = {
524 static const enum index next_destroy_attr[] = {
530 static const enum index next_list_attr[] = {
536 static const enum index item_param[] = {
545 static const enum index next_item[] = {
581 ITEM_ICMP6_ND_OPT_SLA_ETH,
582 ITEM_ICMP6_ND_OPT_TLA_ETH,
586 static const enum index item_fuzzy[] = {
592 static const enum index item_any[] = {
598 static const enum index item_vf[] = {
604 static const enum index item_phy_port[] = {
610 static const enum index item_port_id[] = {
616 static const enum index item_mark[] = {
622 static const enum index item_raw[] = {
632 static const enum index item_eth[] = {
640 static const enum index item_vlan[] = {
645 ITEM_VLAN_INNER_TYPE,
650 static const enum index item_ipv4[] = {
660 static const enum index item_ipv6[] = {
671 static const enum index item_icmp[] = {
678 static const enum index item_udp[] = {
685 static const enum index item_tcp[] = {
693 static const enum index item_sctp[] = {
702 static const enum index item_vxlan[] = {
708 static const enum index item_e_tag[] = {
709 ITEM_E_TAG_GRP_ECID_B,
714 static const enum index item_nvgre[] = {
720 static const enum index item_mpls[] = {
726 static const enum index item_gre[] = {
732 static const enum index item_gtp[] = {
738 static const enum index item_geneve[] = {
745 static const enum index item_vxlan_gpe[] = {
751 static const enum index item_arp_eth_ipv4[] = {
752 ITEM_ARP_ETH_IPV4_SHA,
753 ITEM_ARP_ETH_IPV4_SPA,
754 ITEM_ARP_ETH_IPV4_THA,
755 ITEM_ARP_ETH_IPV4_TPA,
760 static const enum index item_ipv6_ext[] = {
761 ITEM_IPV6_EXT_NEXT_HDR,
766 static const enum index item_icmp6[] = {
773 static const enum index item_icmp6_nd_ns[] = {
774 ITEM_ICMP6_ND_NS_TARGET_ADDR,
779 static const enum index item_icmp6_nd_na[] = {
780 ITEM_ICMP6_ND_NA_TARGET_ADDR,
785 static const enum index item_icmp6_nd_opt[] = {
786 ITEM_ICMP6_ND_OPT_TYPE,
791 static const enum index item_icmp6_nd_opt_sla_eth[] = {
792 ITEM_ICMP6_ND_OPT_SLA_ETH_SLA,
797 static const enum index item_icmp6_nd_opt_tla_eth[] = {
798 ITEM_ICMP6_ND_OPT_TLA_ETH_TLA,
803 static const enum index next_action[] = {
819 ACTION_OF_SET_MPLS_TTL,
820 ACTION_OF_DEC_MPLS_TTL,
821 ACTION_OF_SET_NW_TTL,
822 ACTION_OF_DEC_NW_TTL,
823 ACTION_OF_COPY_TTL_OUT,
824 ACTION_OF_COPY_TTL_IN,
827 ACTION_OF_SET_VLAN_VID,
828 ACTION_OF_SET_VLAN_PCP,
847 static const enum index action_mark[] = {
853 static const enum index action_queue[] = {
859 static const enum index action_count[] = {
866 static const enum index action_rss[] = {
877 static const enum index action_vf[] = {
884 static const enum index action_phy_port[] = {
885 ACTION_PHY_PORT_ORIGINAL,
886 ACTION_PHY_PORT_INDEX,
891 static const enum index action_port_id[] = {
892 ACTION_PORT_ID_ORIGINAL,
898 static const enum index action_meter[] = {
904 static const enum index action_of_set_mpls_ttl[] = {
905 ACTION_OF_SET_MPLS_TTL_MPLS_TTL,
910 static const enum index action_of_set_nw_ttl[] = {
911 ACTION_OF_SET_NW_TTL_NW_TTL,
916 static const enum index action_of_push_vlan[] = {
917 ACTION_OF_PUSH_VLAN_ETHERTYPE,
922 static const enum index action_of_set_vlan_vid[] = {
923 ACTION_OF_SET_VLAN_VID_VLAN_VID,
928 static const enum index action_of_set_vlan_pcp[] = {
929 ACTION_OF_SET_VLAN_PCP_VLAN_PCP,
934 static const enum index action_of_pop_mpls[] = {
935 ACTION_OF_POP_MPLS_ETHERTYPE,
940 static const enum index action_of_push_mpls[] = {
941 ACTION_OF_PUSH_MPLS_ETHERTYPE,
946 static const enum index action_set_ipv4_src[] = {
947 ACTION_SET_IPV4_SRC_IPV4_SRC,
952 static const enum index action_set_ipv4_dst[] = {
953 ACTION_SET_IPV4_DST_IPV4_DST,
958 static const enum index action_set_ipv6_src[] = {
959 ACTION_SET_IPV6_SRC_IPV6_SRC,
964 static const enum index action_set_ipv6_dst[] = {
965 ACTION_SET_IPV6_DST_IPV6_DST,
970 static const enum index action_set_tp_src[] = {
971 ACTION_SET_TP_SRC_TP_SRC,
976 static const enum index action_set_tp_dst[] = {
977 ACTION_SET_TP_DST_TP_DST,
982 static const enum index action_set_ttl[] = {
988 static const enum index action_jump[] = {
994 static int parse_init(struct context *, const struct token *,
995 const char *, unsigned int,
996 void *, unsigned int);
997 static int parse_vc(struct context *, const struct token *,
998 const char *, unsigned int,
999 void *, unsigned int);
1000 static int parse_vc_spec(struct context *, const struct token *,
1001 const char *, unsigned int, void *, unsigned int);
1002 static int parse_vc_conf(struct context *, const struct token *,
1003 const char *, unsigned int, void *, unsigned int);
1004 static int parse_vc_action_rss(struct context *, const struct token *,
1005 const char *, unsigned int, void *,
1007 static int parse_vc_action_rss_func(struct context *, const struct token *,
1008 const char *, unsigned int, void *,
1010 static int parse_vc_action_rss_type(struct context *, const struct token *,
1011 const char *, unsigned int, void *,
1013 static int parse_vc_action_rss_queue(struct context *, const struct token *,
1014 const char *, unsigned int, void *,
1016 static int parse_vc_action_vxlan_encap(struct context *, const struct token *,
1017 const char *, unsigned int, void *,
1019 static int parse_vc_action_nvgre_encap(struct context *, const struct token *,
1020 const char *, unsigned int, void *,
1022 static int parse_destroy(struct context *, const struct token *,
1023 const char *, unsigned int,
1024 void *, unsigned int);
1025 static int parse_flush(struct context *, const struct token *,
1026 const char *, unsigned int,
1027 void *, unsigned int);
1028 static int parse_query(struct context *, const struct token *,
1029 const char *, unsigned int,
1030 void *, unsigned int);
1031 static int parse_action(struct context *, const struct token *,
1032 const char *, unsigned int,
1033 void *, unsigned int);
1034 static int parse_list(struct context *, const struct token *,
1035 const char *, unsigned int,
1036 void *, unsigned int);
1037 static int parse_isolate(struct context *, const struct token *,
1038 const char *, unsigned int,
1039 void *, unsigned int);
1040 static int parse_int(struct context *, const struct token *,
1041 const char *, unsigned int,
1042 void *, unsigned int);
1043 static int parse_prefix(struct context *, const struct token *,
1044 const char *, unsigned int,
1045 void *, unsigned int);
1046 static int parse_boolean(struct context *, const struct token *,
1047 const char *, unsigned int,
1048 void *, unsigned int);
1049 static int parse_string(struct context *, const struct token *,
1050 const char *, unsigned int,
1051 void *, unsigned int);
1052 static int parse_mac_addr(struct context *, const struct token *,
1053 const char *, unsigned int,
1054 void *, unsigned int);
1055 static int parse_ipv4_addr(struct context *, const struct token *,
1056 const char *, unsigned int,
1057 void *, unsigned int);
1058 static int parse_ipv6_addr(struct context *, const struct token *,
1059 const char *, unsigned int,
1060 void *, unsigned int);
1061 static int parse_port(struct context *, const struct token *,
1062 const char *, unsigned int,
1063 void *, unsigned int);
1064 static int comp_none(struct context *, const struct token *,
1065 unsigned int, char *, unsigned int);
1066 static int comp_boolean(struct context *, const struct token *,
1067 unsigned int, char *, unsigned int);
1068 static int comp_action(struct context *, const struct token *,
1069 unsigned int, char *, unsigned int);
1070 static int comp_port(struct context *, const struct token *,
1071 unsigned int, char *, unsigned int);
1072 static int comp_rule_id(struct context *, const struct token *,
1073 unsigned int, char *, unsigned int);
1074 static int comp_vc_action_rss_type(struct context *, const struct token *,
1075 unsigned int, char *, unsigned int);
1076 static int comp_vc_action_rss_queue(struct context *, const struct token *,
1077 unsigned int, char *, unsigned int);
1079 /** Token definitions. */
1080 static const struct token token_list[] = {
1081 /* Special tokens. */
1084 .help = "null entry, abused as the entry point",
1085 .next = NEXT(NEXT_ENTRY(FLOW)),
1090 .help = "command may end here",
1092 /* Common tokens. */
1096 .help = "integer value",
1101 .name = "{unsigned}",
1103 .help = "unsigned integer value",
1110 .help = "prefix length for bit-mask",
1111 .call = parse_prefix,
1115 .name = "{boolean}",
1117 .help = "any boolean value",
1118 .call = parse_boolean,
1119 .comp = comp_boolean,
1124 .help = "fixed string",
1125 .call = parse_string,
1129 .name = "{MAC address}",
1131 .help = "standard MAC address notation",
1132 .call = parse_mac_addr,
1136 .name = "{IPv4 address}",
1137 .type = "IPV4 ADDRESS",
1138 .help = "standard IPv4 address notation",
1139 .call = parse_ipv4_addr,
1143 .name = "{IPv6 address}",
1144 .type = "IPV6 ADDRESS",
1145 .help = "standard IPv6 address notation",
1146 .call = parse_ipv6_addr,
1150 .name = "{rule id}",
1152 .help = "rule identifier",
1154 .comp = comp_rule_id,
1157 .name = "{port_id}",
1159 .help = "port identifier",
1164 .name = "{group_id}",
1166 .help = "group identifier",
1170 [PRIORITY_LEVEL] = {
1173 .help = "priority level",
1177 /* Top-level command. */
1180 .type = "{command} {port_id} [{arg} [...]]",
1181 .help = "manage ingress/egress flow rules",
1182 .next = NEXT(NEXT_ENTRY
1192 /* Sub-level commands. */
1195 .help = "check whether a flow rule can be created",
1196 .next = NEXT(next_vc_attr, NEXT_ENTRY(PORT_ID)),
1197 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1202 .help = "create a flow rule",
1203 .next = NEXT(next_vc_attr, NEXT_ENTRY(PORT_ID)),
1204 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1209 .help = "destroy specific flow rules",
1210 .next = NEXT(NEXT_ENTRY(DESTROY_RULE), NEXT_ENTRY(PORT_ID)),
1211 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1212 .call = parse_destroy,
1216 .help = "destroy all flow rules",
1217 .next = NEXT(NEXT_ENTRY(PORT_ID)),
1218 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1219 .call = parse_flush,
1223 .help = "query an existing flow rule",
1224 .next = NEXT(NEXT_ENTRY(QUERY_ACTION),
1225 NEXT_ENTRY(RULE_ID),
1226 NEXT_ENTRY(PORT_ID)),
1227 .args = ARGS(ARGS_ENTRY(struct buffer, args.query.action.type),
1228 ARGS_ENTRY(struct buffer, args.query.rule),
1229 ARGS_ENTRY(struct buffer, port)),
1230 .call = parse_query,
1234 .help = "list existing flow rules",
1235 .next = NEXT(next_list_attr, NEXT_ENTRY(PORT_ID)),
1236 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1241 .help = "restrict ingress traffic to the defined flow rules",
1242 .next = NEXT(NEXT_ENTRY(BOOLEAN),
1243 NEXT_ENTRY(PORT_ID)),
1244 .args = ARGS(ARGS_ENTRY(struct buffer, args.isolate.set),
1245 ARGS_ENTRY(struct buffer, port)),
1246 .call = parse_isolate,
1248 /* Destroy arguments. */
1251 .help = "specify a rule identifier",
1252 .next = NEXT(next_destroy_attr, NEXT_ENTRY(RULE_ID)),
1253 .args = ARGS(ARGS_ENTRY_PTR(struct buffer, args.destroy.rule)),
1254 .call = parse_destroy,
1256 /* Query arguments. */
1260 .help = "action to query, must be part of the rule",
1261 .call = parse_action,
1262 .comp = comp_action,
1264 /* List arguments. */
1267 .help = "specify a group",
1268 .next = NEXT(next_list_attr, NEXT_ENTRY(GROUP_ID)),
1269 .args = ARGS(ARGS_ENTRY_PTR(struct buffer, args.list.group)),
1272 /* Validate/create attributes. */
1275 .help = "specify a group",
1276 .next = NEXT(next_vc_attr, NEXT_ENTRY(GROUP_ID)),
1277 .args = ARGS(ARGS_ENTRY(struct rte_flow_attr, group)),
1282 .help = "specify a priority level",
1283 .next = NEXT(next_vc_attr, NEXT_ENTRY(PRIORITY_LEVEL)),
1284 .args = ARGS(ARGS_ENTRY(struct rte_flow_attr, priority)),
1289 .help = "affect rule to ingress",
1290 .next = NEXT(next_vc_attr),
1295 .help = "affect rule to egress",
1296 .next = NEXT(next_vc_attr),
1301 .help = "apply rule directly to endpoints found in pattern",
1302 .next = NEXT(next_vc_attr),
1305 /* Validate/create pattern. */
1308 .help = "submit a list of pattern items",
1309 .next = NEXT(next_item),
1314 .help = "match value perfectly (with full bit-mask)",
1315 .call = parse_vc_spec,
1317 [ITEM_PARAM_SPEC] = {
1319 .help = "match value according to configured bit-mask",
1320 .call = parse_vc_spec,
1322 [ITEM_PARAM_LAST] = {
1324 .help = "specify upper bound to establish a range",
1325 .call = parse_vc_spec,
1327 [ITEM_PARAM_MASK] = {
1329 .help = "specify bit-mask with relevant bits set to one",
1330 .call = parse_vc_spec,
1332 [ITEM_PARAM_PREFIX] = {
1334 .help = "generate bit-mask from a prefix length",
1335 .call = parse_vc_spec,
1339 .help = "specify next pattern item",
1340 .next = NEXT(next_item),
1344 .help = "end list of pattern items",
1345 .priv = PRIV_ITEM(END, 0),
1346 .next = NEXT(NEXT_ENTRY(ACTIONS)),
1351 .help = "no-op pattern item",
1352 .priv = PRIV_ITEM(VOID, 0),
1353 .next = NEXT(NEXT_ENTRY(ITEM_NEXT)),
1358 .help = "perform actions when pattern does not match",
1359 .priv = PRIV_ITEM(INVERT, 0),
1360 .next = NEXT(NEXT_ENTRY(ITEM_NEXT)),
1365 .help = "match any protocol for the current layer",
1366 .priv = PRIV_ITEM(ANY, sizeof(struct rte_flow_item_any)),
1367 .next = NEXT(item_any),
1372 .help = "number of layers covered",
1373 .next = NEXT(item_any, NEXT_ENTRY(UNSIGNED), item_param),
1374 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_any, num)),
1378 .help = "match traffic from/to the physical function",
1379 .priv = PRIV_ITEM(PF, 0),
1380 .next = NEXT(NEXT_ENTRY(ITEM_NEXT)),
1385 .help = "match traffic from/to a virtual function ID",
1386 .priv = PRIV_ITEM(VF, sizeof(struct rte_flow_item_vf)),
1387 .next = NEXT(item_vf),
1393 .next = NEXT(item_vf, NEXT_ENTRY(UNSIGNED), item_param),
1394 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_vf, id)),
1398 .help = "match traffic from/to a specific physical port",
1399 .priv = PRIV_ITEM(PHY_PORT,
1400 sizeof(struct rte_flow_item_phy_port)),
1401 .next = NEXT(item_phy_port),
1404 [ITEM_PHY_PORT_INDEX] = {
1406 .help = "physical port index",
1407 .next = NEXT(item_phy_port, NEXT_ENTRY(UNSIGNED), item_param),
1408 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_phy_port, index)),
1412 .help = "match traffic from/to a given DPDK port ID",
1413 .priv = PRIV_ITEM(PORT_ID,
1414 sizeof(struct rte_flow_item_port_id)),
1415 .next = NEXT(item_port_id),
1418 [ITEM_PORT_ID_ID] = {
1420 .help = "DPDK port ID",
1421 .next = NEXT(item_port_id, NEXT_ENTRY(UNSIGNED), item_param),
1422 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_port_id, id)),
1426 .help = "match traffic against value set in previously matched rule",
1427 .priv = PRIV_ITEM(MARK, sizeof(struct rte_flow_item_mark)),
1428 .next = NEXT(item_mark),
1433 .help = "Integer value to match against",
1434 .next = NEXT(item_mark, NEXT_ENTRY(UNSIGNED), item_param),
1435 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_mark, id)),
1439 .help = "match an arbitrary byte string",
1440 .priv = PRIV_ITEM(RAW, ITEM_RAW_SIZE),
1441 .next = NEXT(item_raw),
1444 [ITEM_RAW_RELATIVE] = {
1446 .help = "look for pattern after the previous item",
1447 .next = NEXT(item_raw, NEXT_ENTRY(BOOLEAN), item_param),
1448 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_item_raw,
1451 [ITEM_RAW_SEARCH] = {
1453 .help = "search pattern from offset (see also limit)",
1454 .next = NEXT(item_raw, NEXT_ENTRY(BOOLEAN), item_param),
1455 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_item_raw,
1458 [ITEM_RAW_OFFSET] = {
1460 .help = "absolute or relative offset for pattern",
1461 .next = NEXT(item_raw, NEXT_ENTRY(INTEGER), item_param),
1462 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_raw, offset)),
1464 [ITEM_RAW_LIMIT] = {
1466 .help = "search area limit for start of pattern",
1467 .next = NEXT(item_raw, NEXT_ENTRY(UNSIGNED), item_param),
1468 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_raw, limit)),
1470 [ITEM_RAW_PATTERN] = {
1472 .help = "byte string to look for",
1473 .next = NEXT(item_raw,
1475 NEXT_ENTRY(ITEM_PARAM_IS,
1478 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_raw, pattern),
1479 ARGS_ENTRY(struct rte_flow_item_raw, length),
1480 ARGS_ENTRY_ARB(sizeof(struct rte_flow_item_raw),
1481 ITEM_RAW_PATTERN_SIZE)),
1485 .help = "match Ethernet header",
1486 .priv = PRIV_ITEM(ETH, sizeof(struct rte_flow_item_eth)),
1487 .next = NEXT(item_eth),
1492 .help = "destination MAC",
1493 .next = NEXT(item_eth, NEXT_ENTRY(MAC_ADDR), item_param),
1494 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_eth, dst)),
1498 .help = "source MAC",
1499 .next = NEXT(item_eth, NEXT_ENTRY(MAC_ADDR), item_param),
1500 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_eth, src)),
1504 .help = "EtherType",
1505 .next = NEXT(item_eth, NEXT_ENTRY(UNSIGNED), item_param),
1506 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_eth, type)),
1510 .help = "match 802.1Q/ad VLAN tag",
1511 .priv = PRIV_ITEM(VLAN, sizeof(struct rte_flow_item_vlan)),
1512 .next = NEXT(item_vlan),
1517 .help = "tag control information",
1518 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1519 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vlan, tci)),
1523 .help = "priority code point",
1524 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1525 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_vlan,
1530 .help = "drop eligible indicator",
1531 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1532 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_vlan,
1537 .help = "VLAN identifier",
1538 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1539 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_vlan,
1542 [ITEM_VLAN_INNER_TYPE] = {
1543 .name = "inner_type",
1544 .help = "inner EtherType",
1545 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1546 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vlan,
1551 .help = "match IPv4 header",
1552 .priv = PRIV_ITEM(IPV4, sizeof(struct rte_flow_item_ipv4)),
1553 .next = NEXT(item_ipv4),
1558 .help = "type of service",
1559 .next = NEXT(item_ipv4, NEXT_ENTRY(UNSIGNED), item_param),
1560 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
1561 hdr.type_of_service)),
1565 .help = "time to live",
1566 .next = NEXT(item_ipv4, NEXT_ENTRY(UNSIGNED), item_param),
1567 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
1570 [ITEM_IPV4_PROTO] = {
1572 .help = "next protocol ID",
1573 .next = NEXT(item_ipv4, NEXT_ENTRY(UNSIGNED), item_param),
1574 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
1575 hdr.next_proto_id)),
1579 .help = "source address",
1580 .next = NEXT(item_ipv4, NEXT_ENTRY(IPV4_ADDR), item_param),
1581 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
1586 .help = "destination address",
1587 .next = NEXT(item_ipv4, NEXT_ENTRY(IPV4_ADDR), item_param),
1588 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
1593 .help = "match IPv6 header",
1594 .priv = PRIV_ITEM(IPV6, sizeof(struct rte_flow_item_ipv6)),
1595 .next = NEXT(item_ipv6),
1600 .help = "traffic class",
1601 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
1602 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_ipv6,
1604 "\x0f\xf0\x00\x00")),
1606 [ITEM_IPV6_FLOW] = {
1608 .help = "flow label",
1609 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
1610 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_ipv6,
1612 "\x00\x0f\xff\xff")),
1614 [ITEM_IPV6_PROTO] = {
1616 .help = "protocol (next header)",
1617 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
1618 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
1623 .help = "hop limit",
1624 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
1625 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
1630 .help = "source address",
1631 .next = NEXT(item_ipv6, NEXT_ENTRY(IPV6_ADDR), item_param),
1632 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
1637 .help = "destination address",
1638 .next = NEXT(item_ipv6, NEXT_ENTRY(IPV6_ADDR), item_param),
1639 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
1644 .help = "match ICMP header",
1645 .priv = PRIV_ITEM(ICMP, sizeof(struct rte_flow_item_icmp)),
1646 .next = NEXT(item_icmp),
1649 [ITEM_ICMP_TYPE] = {
1651 .help = "ICMP packet type",
1652 .next = NEXT(item_icmp, NEXT_ENTRY(UNSIGNED), item_param),
1653 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp,
1656 [ITEM_ICMP_CODE] = {
1658 .help = "ICMP packet code",
1659 .next = NEXT(item_icmp, NEXT_ENTRY(UNSIGNED), item_param),
1660 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp,
1665 .help = "match UDP header",
1666 .priv = PRIV_ITEM(UDP, sizeof(struct rte_flow_item_udp)),
1667 .next = NEXT(item_udp),
1672 .help = "UDP source port",
1673 .next = NEXT(item_udp, NEXT_ENTRY(UNSIGNED), item_param),
1674 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_udp,
1679 .help = "UDP destination port",
1680 .next = NEXT(item_udp, NEXT_ENTRY(UNSIGNED), item_param),
1681 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_udp,
1686 .help = "match TCP header",
1687 .priv = PRIV_ITEM(TCP, sizeof(struct rte_flow_item_tcp)),
1688 .next = NEXT(item_tcp),
1693 .help = "TCP source port",
1694 .next = NEXT(item_tcp, NEXT_ENTRY(UNSIGNED), item_param),
1695 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_tcp,
1700 .help = "TCP destination port",
1701 .next = NEXT(item_tcp, NEXT_ENTRY(UNSIGNED), item_param),
1702 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_tcp,
1705 [ITEM_TCP_FLAGS] = {
1707 .help = "TCP flags",
1708 .next = NEXT(item_tcp, NEXT_ENTRY(UNSIGNED), item_param),
1709 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_tcp,
1714 .help = "match SCTP header",
1715 .priv = PRIV_ITEM(SCTP, sizeof(struct rte_flow_item_sctp)),
1716 .next = NEXT(item_sctp),
1721 .help = "SCTP source port",
1722 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
1723 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
1728 .help = "SCTP destination port",
1729 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
1730 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
1735 .help = "validation tag",
1736 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
1737 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
1740 [ITEM_SCTP_CKSUM] = {
1743 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
1744 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
1749 .help = "match VXLAN header",
1750 .priv = PRIV_ITEM(VXLAN, sizeof(struct rte_flow_item_vxlan)),
1751 .next = NEXT(item_vxlan),
1754 [ITEM_VXLAN_VNI] = {
1756 .help = "VXLAN identifier",
1757 .next = NEXT(item_vxlan, NEXT_ENTRY(UNSIGNED), item_param),
1758 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vxlan, vni)),
1762 .help = "match E-Tag header",
1763 .priv = PRIV_ITEM(E_TAG, sizeof(struct rte_flow_item_e_tag)),
1764 .next = NEXT(item_e_tag),
1767 [ITEM_E_TAG_GRP_ECID_B] = {
1768 .name = "grp_ecid_b",
1769 .help = "GRP and E-CID base",
1770 .next = NEXT(item_e_tag, NEXT_ENTRY(UNSIGNED), item_param),
1771 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_e_tag,
1777 .help = "match NVGRE header",
1778 .priv = PRIV_ITEM(NVGRE, sizeof(struct rte_flow_item_nvgre)),
1779 .next = NEXT(item_nvgre),
1782 [ITEM_NVGRE_TNI] = {
1784 .help = "virtual subnet ID",
1785 .next = NEXT(item_nvgre, NEXT_ENTRY(UNSIGNED), item_param),
1786 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_nvgre, tni)),
1790 .help = "match MPLS header",
1791 .priv = PRIV_ITEM(MPLS, sizeof(struct rte_flow_item_mpls)),
1792 .next = NEXT(item_mpls),
1795 [ITEM_MPLS_LABEL] = {
1797 .help = "MPLS label",
1798 .next = NEXT(item_mpls, NEXT_ENTRY(UNSIGNED), item_param),
1799 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_mpls,
1805 .help = "match GRE header",
1806 .priv = PRIV_ITEM(GRE, sizeof(struct rte_flow_item_gre)),
1807 .next = NEXT(item_gre),
1810 [ITEM_GRE_PROTO] = {
1812 .help = "GRE protocol type",
1813 .next = NEXT(item_gre, NEXT_ENTRY(UNSIGNED), item_param),
1814 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gre,
1819 .help = "fuzzy pattern match, expect faster than default",
1820 .priv = PRIV_ITEM(FUZZY,
1821 sizeof(struct rte_flow_item_fuzzy)),
1822 .next = NEXT(item_fuzzy),
1825 [ITEM_FUZZY_THRESH] = {
1827 .help = "match accuracy threshold",
1828 .next = NEXT(item_fuzzy, NEXT_ENTRY(UNSIGNED), item_param),
1829 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_fuzzy,
1834 .help = "match GTP header",
1835 .priv = PRIV_ITEM(GTP, sizeof(struct rte_flow_item_gtp)),
1836 .next = NEXT(item_gtp),
1841 .help = "tunnel endpoint identifier",
1842 .next = NEXT(item_gtp, NEXT_ENTRY(UNSIGNED), item_param),
1843 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gtp, teid)),
1847 .help = "match GTP header",
1848 .priv = PRIV_ITEM(GTPC, sizeof(struct rte_flow_item_gtp)),
1849 .next = NEXT(item_gtp),
1854 .help = "match GTP header",
1855 .priv = PRIV_ITEM(GTPU, sizeof(struct rte_flow_item_gtp)),
1856 .next = NEXT(item_gtp),
1861 .help = "match GENEVE header",
1862 .priv = PRIV_ITEM(GENEVE, sizeof(struct rte_flow_item_geneve)),
1863 .next = NEXT(item_geneve),
1866 [ITEM_GENEVE_VNI] = {
1868 .help = "virtual network identifier",
1869 .next = NEXT(item_geneve, NEXT_ENTRY(UNSIGNED), item_param),
1870 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_geneve, vni)),
1872 [ITEM_GENEVE_PROTO] = {
1874 .help = "GENEVE protocol type",
1875 .next = NEXT(item_geneve, NEXT_ENTRY(UNSIGNED), item_param),
1876 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_geneve,
1879 [ITEM_VXLAN_GPE] = {
1880 .name = "vxlan-gpe",
1881 .help = "match VXLAN-GPE header",
1882 .priv = PRIV_ITEM(VXLAN_GPE,
1883 sizeof(struct rte_flow_item_vxlan_gpe)),
1884 .next = NEXT(item_vxlan_gpe),
1887 [ITEM_VXLAN_GPE_VNI] = {
1889 .help = "VXLAN-GPE identifier",
1890 .next = NEXT(item_vxlan_gpe, NEXT_ENTRY(UNSIGNED), item_param),
1891 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vxlan_gpe,
1894 [ITEM_ARP_ETH_IPV4] = {
1895 .name = "arp_eth_ipv4",
1896 .help = "match ARP header for Ethernet/IPv4",
1897 .priv = PRIV_ITEM(ARP_ETH_IPV4,
1898 sizeof(struct rte_flow_item_arp_eth_ipv4)),
1899 .next = NEXT(item_arp_eth_ipv4),
1902 [ITEM_ARP_ETH_IPV4_SHA] = {
1904 .help = "sender hardware address",
1905 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(MAC_ADDR),
1907 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
1910 [ITEM_ARP_ETH_IPV4_SPA] = {
1912 .help = "sender IPv4 address",
1913 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(IPV4_ADDR),
1915 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
1918 [ITEM_ARP_ETH_IPV4_THA] = {
1920 .help = "target hardware address",
1921 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(MAC_ADDR),
1923 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
1926 [ITEM_ARP_ETH_IPV4_TPA] = {
1928 .help = "target IPv4 address",
1929 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(IPV4_ADDR),
1931 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
1936 .help = "match presence of any IPv6 extension header",
1937 .priv = PRIV_ITEM(IPV6_EXT,
1938 sizeof(struct rte_flow_item_ipv6_ext)),
1939 .next = NEXT(item_ipv6_ext),
1942 [ITEM_IPV6_EXT_NEXT_HDR] = {
1944 .help = "next header",
1945 .next = NEXT(item_ipv6_ext, NEXT_ENTRY(UNSIGNED), item_param),
1946 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6_ext,
1951 .help = "match any ICMPv6 header",
1952 .priv = PRIV_ITEM(ICMP6, sizeof(struct rte_flow_item_icmp6)),
1953 .next = NEXT(item_icmp6),
1956 [ITEM_ICMP6_TYPE] = {
1958 .help = "ICMPv6 type",
1959 .next = NEXT(item_icmp6, NEXT_ENTRY(UNSIGNED), item_param),
1960 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6,
1963 [ITEM_ICMP6_CODE] = {
1965 .help = "ICMPv6 code",
1966 .next = NEXT(item_icmp6, NEXT_ENTRY(UNSIGNED), item_param),
1967 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6,
1970 [ITEM_ICMP6_ND_NS] = {
1971 .name = "icmp6_nd_ns",
1972 .help = "match ICMPv6 neighbor discovery solicitation",
1973 .priv = PRIV_ITEM(ICMP6_ND_NS,
1974 sizeof(struct rte_flow_item_icmp6_nd_ns)),
1975 .next = NEXT(item_icmp6_nd_ns),
1978 [ITEM_ICMP6_ND_NS_TARGET_ADDR] = {
1979 .name = "target_addr",
1980 .help = "target address",
1981 .next = NEXT(item_icmp6_nd_ns, NEXT_ENTRY(IPV6_ADDR),
1983 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6_nd_ns,
1986 [ITEM_ICMP6_ND_NA] = {
1987 .name = "icmp6_nd_na",
1988 .help = "match ICMPv6 neighbor discovery advertisement",
1989 .priv = PRIV_ITEM(ICMP6_ND_NA,
1990 sizeof(struct rte_flow_item_icmp6_nd_na)),
1991 .next = NEXT(item_icmp6_nd_na),
1994 [ITEM_ICMP6_ND_NA_TARGET_ADDR] = {
1995 .name = "target_addr",
1996 .help = "target address",
1997 .next = NEXT(item_icmp6_nd_na, NEXT_ENTRY(IPV6_ADDR),
1999 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6_nd_na,
2002 [ITEM_ICMP6_ND_OPT] = {
2003 .name = "icmp6_nd_opt",
2004 .help = "match presence of any ICMPv6 neighbor discovery"
2006 .priv = PRIV_ITEM(ICMP6_ND_OPT,
2007 sizeof(struct rte_flow_item_icmp6_nd_opt)),
2008 .next = NEXT(item_icmp6_nd_opt),
2011 [ITEM_ICMP6_ND_OPT_TYPE] = {
2013 .help = "ND option type",
2014 .next = NEXT(item_icmp6_nd_opt, NEXT_ENTRY(UNSIGNED),
2016 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6_nd_opt,
2019 [ITEM_ICMP6_ND_OPT_SLA_ETH] = {
2020 .name = "icmp6_nd_opt_sla_eth",
2021 .help = "match ICMPv6 neighbor discovery source Ethernet"
2022 " link-layer address option",
2024 (ICMP6_ND_OPT_SLA_ETH,
2025 sizeof(struct rte_flow_item_icmp6_nd_opt_sla_eth)),
2026 .next = NEXT(item_icmp6_nd_opt_sla_eth),
2029 [ITEM_ICMP6_ND_OPT_SLA_ETH_SLA] = {
2031 .help = "source Ethernet LLA",
2032 .next = NEXT(item_icmp6_nd_opt_sla_eth, NEXT_ENTRY(MAC_ADDR),
2034 .args = ARGS(ARGS_ENTRY_HTON
2035 (struct rte_flow_item_icmp6_nd_opt_sla_eth, sla)),
2037 [ITEM_ICMP6_ND_OPT_TLA_ETH] = {
2038 .name = "icmp6_nd_opt_tla_eth",
2039 .help = "match ICMPv6 neighbor discovery target Ethernet"
2040 " link-layer address option",
2042 (ICMP6_ND_OPT_TLA_ETH,
2043 sizeof(struct rte_flow_item_icmp6_nd_opt_tla_eth)),
2044 .next = NEXT(item_icmp6_nd_opt_tla_eth),
2047 [ITEM_ICMP6_ND_OPT_TLA_ETH_TLA] = {
2049 .help = "target Ethernet LLA",
2050 .next = NEXT(item_icmp6_nd_opt_tla_eth, NEXT_ENTRY(MAC_ADDR),
2052 .args = ARGS(ARGS_ENTRY_HTON
2053 (struct rte_flow_item_icmp6_nd_opt_tla_eth, tla)),
2056 /* Validate/create actions. */
2059 .help = "submit a list of associated actions",
2060 .next = NEXT(next_action),
2065 .help = "specify next action",
2066 .next = NEXT(next_action),
2070 .help = "end list of actions",
2071 .priv = PRIV_ACTION(END, 0),
2076 .help = "no-op action",
2077 .priv = PRIV_ACTION(VOID, 0),
2078 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2081 [ACTION_PASSTHRU] = {
2083 .help = "let subsequent rule process matched packets",
2084 .priv = PRIV_ACTION(PASSTHRU, 0),
2085 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2090 .help = "redirect traffic to a given group",
2091 .priv = PRIV_ACTION(JUMP, sizeof(struct rte_flow_action_jump)),
2092 .next = NEXT(action_jump),
2095 [ACTION_JUMP_GROUP] = {
2097 .help = "group to redirect traffic to",
2098 .next = NEXT(action_jump, NEXT_ENTRY(UNSIGNED)),
2099 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_jump, group)),
2100 .call = parse_vc_conf,
2104 .help = "attach 32 bit value to packets",
2105 .priv = PRIV_ACTION(MARK, sizeof(struct rte_flow_action_mark)),
2106 .next = NEXT(action_mark),
2109 [ACTION_MARK_ID] = {
2111 .help = "32 bit value to return with packets",
2112 .next = NEXT(action_mark, NEXT_ENTRY(UNSIGNED)),
2113 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_mark, id)),
2114 .call = parse_vc_conf,
2118 .help = "flag packets",
2119 .priv = PRIV_ACTION(FLAG, 0),
2120 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2125 .help = "assign packets to a given queue index",
2126 .priv = PRIV_ACTION(QUEUE,
2127 sizeof(struct rte_flow_action_queue)),
2128 .next = NEXT(action_queue),
2131 [ACTION_QUEUE_INDEX] = {
2133 .help = "queue index to use",
2134 .next = NEXT(action_queue, NEXT_ENTRY(UNSIGNED)),
2135 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_queue, index)),
2136 .call = parse_vc_conf,
2140 .help = "drop packets (note: passthru has priority)",
2141 .priv = PRIV_ACTION(DROP, 0),
2142 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2147 .help = "enable counters for this rule",
2148 .priv = PRIV_ACTION(COUNT,
2149 sizeof(struct rte_flow_action_count)),
2150 .next = NEXT(action_count),
2153 [ACTION_COUNT_ID] = {
2154 .name = "identifier",
2155 .help = "counter identifier to use",
2156 .next = NEXT(action_count, NEXT_ENTRY(UNSIGNED)),
2157 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_count, id)),
2158 .call = parse_vc_conf,
2160 [ACTION_COUNT_SHARED] = {
2162 .help = "shared counter",
2163 .next = NEXT(action_count, NEXT_ENTRY(BOOLEAN)),
2164 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_count,
2166 .call = parse_vc_conf,
2170 .help = "spread packets among several queues",
2171 .priv = PRIV_ACTION(RSS, sizeof(struct action_rss_data)),
2172 .next = NEXT(action_rss),
2173 .call = parse_vc_action_rss,
2175 [ACTION_RSS_FUNC] = {
2177 .help = "RSS hash function to apply",
2178 .next = NEXT(action_rss,
2179 NEXT_ENTRY(ACTION_RSS_FUNC_DEFAULT,
2180 ACTION_RSS_FUNC_TOEPLITZ,
2181 ACTION_RSS_FUNC_SIMPLE_XOR)),
2183 [ACTION_RSS_FUNC_DEFAULT] = {
2185 .help = "default hash function",
2186 .call = parse_vc_action_rss_func,
2188 [ACTION_RSS_FUNC_TOEPLITZ] = {
2190 .help = "Toeplitz hash function",
2191 .call = parse_vc_action_rss_func,
2193 [ACTION_RSS_FUNC_SIMPLE_XOR] = {
2194 .name = "simple_xor",
2195 .help = "simple XOR hash function",
2196 .call = parse_vc_action_rss_func,
2198 [ACTION_RSS_LEVEL] = {
2200 .help = "encapsulation level for \"types\"",
2201 .next = NEXT(action_rss, NEXT_ENTRY(UNSIGNED)),
2202 .args = ARGS(ARGS_ENTRY_ARB
2203 (offsetof(struct action_rss_data, conf) +
2204 offsetof(struct rte_flow_action_rss, level),
2205 sizeof(((struct rte_flow_action_rss *)0)->
2208 [ACTION_RSS_TYPES] = {
2210 .help = "specific RSS hash types",
2211 .next = NEXT(action_rss, NEXT_ENTRY(ACTION_RSS_TYPE)),
2213 [ACTION_RSS_TYPE] = {
2215 .help = "RSS hash type",
2216 .call = parse_vc_action_rss_type,
2217 .comp = comp_vc_action_rss_type,
2219 [ACTION_RSS_KEY] = {
2221 .help = "RSS hash key",
2222 .next = NEXT(action_rss, NEXT_ENTRY(STRING)),
2223 .args = ARGS(ARGS_ENTRY_ARB(0, 0),
2225 (offsetof(struct action_rss_data, conf) +
2226 offsetof(struct rte_flow_action_rss, key_len),
2227 sizeof(((struct rte_flow_action_rss *)0)->
2229 ARGS_ENTRY(struct action_rss_data, key)),
2231 [ACTION_RSS_KEY_LEN] = {
2233 .help = "RSS hash key length in bytes",
2234 .next = NEXT(action_rss, NEXT_ENTRY(UNSIGNED)),
2235 .args = ARGS(ARGS_ENTRY_ARB_BOUNDED
2236 (offsetof(struct action_rss_data, conf) +
2237 offsetof(struct rte_flow_action_rss, key_len),
2238 sizeof(((struct rte_flow_action_rss *)0)->
2241 RSS_HASH_KEY_LENGTH)),
2243 [ACTION_RSS_QUEUES] = {
2245 .help = "queue indices to use",
2246 .next = NEXT(action_rss, NEXT_ENTRY(ACTION_RSS_QUEUE)),
2247 .call = parse_vc_conf,
2249 [ACTION_RSS_QUEUE] = {
2251 .help = "queue index",
2252 .call = parse_vc_action_rss_queue,
2253 .comp = comp_vc_action_rss_queue,
2257 .help = "direct traffic to physical function",
2258 .priv = PRIV_ACTION(PF, 0),
2259 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2264 .help = "direct traffic to a virtual function ID",
2265 .priv = PRIV_ACTION(VF, sizeof(struct rte_flow_action_vf)),
2266 .next = NEXT(action_vf),
2269 [ACTION_VF_ORIGINAL] = {
2271 .help = "use original VF ID if possible",
2272 .next = NEXT(action_vf, NEXT_ENTRY(BOOLEAN)),
2273 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_vf,
2275 .call = parse_vc_conf,
2280 .next = NEXT(action_vf, NEXT_ENTRY(UNSIGNED)),
2281 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_vf, id)),
2282 .call = parse_vc_conf,
2284 [ACTION_PHY_PORT] = {
2286 .help = "direct packets to physical port index",
2287 .priv = PRIV_ACTION(PHY_PORT,
2288 sizeof(struct rte_flow_action_phy_port)),
2289 .next = NEXT(action_phy_port),
2292 [ACTION_PHY_PORT_ORIGINAL] = {
2294 .help = "use original port index if possible",
2295 .next = NEXT(action_phy_port, NEXT_ENTRY(BOOLEAN)),
2296 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_phy_port,
2298 .call = parse_vc_conf,
2300 [ACTION_PHY_PORT_INDEX] = {
2302 .help = "physical port index",
2303 .next = NEXT(action_phy_port, NEXT_ENTRY(UNSIGNED)),
2304 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_phy_port,
2306 .call = parse_vc_conf,
2308 [ACTION_PORT_ID] = {
2310 .help = "direct matching traffic to a given DPDK port ID",
2311 .priv = PRIV_ACTION(PORT_ID,
2312 sizeof(struct rte_flow_action_port_id)),
2313 .next = NEXT(action_port_id),
2316 [ACTION_PORT_ID_ORIGINAL] = {
2318 .help = "use original DPDK port ID if possible",
2319 .next = NEXT(action_port_id, NEXT_ENTRY(BOOLEAN)),
2320 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_port_id,
2322 .call = parse_vc_conf,
2324 [ACTION_PORT_ID_ID] = {
2326 .help = "DPDK port ID",
2327 .next = NEXT(action_port_id, NEXT_ENTRY(UNSIGNED)),
2328 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_port_id, id)),
2329 .call = parse_vc_conf,
2333 .help = "meter the directed packets at given id",
2334 .priv = PRIV_ACTION(METER,
2335 sizeof(struct rte_flow_action_meter)),
2336 .next = NEXT(action_meter),
2339 [ACTION_METER_ID] = {
2341 .help = "meter id to use",
2342 .next = NEXT(action_meter, NEXT_ENTRY(UNSIGNED)),
2343 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_meter, mtr_id)),
2344 .call = parse_vc_conf,
2346 [ACTION_OF_SET_MPLS_TTL] = {
2347 .name = "of_set_mpls_ttl",
2348 .help = "OpenFlow's OFPAT_SET_MPLS_TTL",
2351 sizeof(struct rte_flow_action_of_set_mpls_ttl)),
2352 .next = NEXT(action_of_set_mpls_ttl),
2355 [ACTION_OF_SET_MPLS_TTL_MPLS_TTL] = {
2358 .next = NEXT(action_of_set_mpls_ttl, NEXT_ENTRY(UNSIGNED)),
2359 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_of_set_mpls_ttl,
2361 .call = parse_vc_conf,
2363 [ACTION_OF_DEC_MPLS_TTL] = {
2364 .name = "of_dec_mpls_ttl",
2365 .help = "OpenFlow's OFPAT_DEC_MPLS_TTL",
2366 .priv = PRIV_ACTION(OF_DEC_MPLS_TTL, 0),
2367 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2370 [ACTION_OF_SET_NW_TTL] = {
2371 .name = "of_set_nw_ttl",
2372 .help = "OpenFlow's OFPAT_SET_NW_TTL",
2375 sizeof(struct rte_flow_action_of_set_nw_ttl)),
2376 .next = NEXT(action_of_set_nw_ttl),
2379 [ACTION_OF_SET_NW_TTL_NW_TTL] = {
2382 .next = NEXT(action_of_set_nw_ttl, NEXT_ENTRY(UNSIGNED)),
2383 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_of_set_nw_ttl,
2385 .call = parse_vc_conf,
2387 [ACTION_OF_DEC_NW_TTL] = {
2388 .name = "of_dec_nw_ttl",
2389 .help = "OpenFlow's OFPAT_DEC_NW_TTL",
2390 .priv = PRIV_ACTION(OF_DEC_NW_TTL, 0),
2391 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2394 [ACTION_OF_COPY_TTL_OUT] = {
2395 .name = "of_copy_ttl_out",
2396 .help = "OpenFlow's OFPAT_COPY_TTL_OUT",
2397 .priv = PRIV_ACTION(OF_COPY_TTL_OUT, 0),
2398 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2401 [ACTION_OF_COPY_TTL_IN] = {
2402 .name = "of_copy_ttl_in",
2403 .help = "OpenFlow's OFPAT_COPY_TTL_IN",
2404 .priv = PRIV_ACTION(OF_COPY_TTL_IN, 0),
2405 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2408 [ACTION_OF_POP_VLAN] = {
2409 .name = "of_pop_vlan",
2410 .help = "OpenFlow's OFPAT_POP_VLAN",
2411 .priv = PRIV_ACTION(OF_POP_VLAN, 0),
2412 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2415 [ACTION_OF_PUSH_VLAN] = {
2416 .name = "of_push_vlan",
2417 .help = "OpenFlow's OFPAT_PUSH_VLAN",
2420 sizeof(struct rte_flow_action_of_push_vlan)),
2421 .next = NEXT(action_of_push_vlan),
2424 [ACTION_OF_PUSH_VLAN_ETHERTYPE] = {
2425 .name = "ethertype",
2426 .help = "EtherType",
2427 .next = NEXT(action_of_push_vlan, NEXT_ENTRY(UNSIGNED)),
2428 .args = ARGS(ARGS_ENTRY_HTON
2429 (struct rte_flow_action_of_push_vlan,
2431 .call = parse_vc_conf,
2433 [ACTION_OF_SET_VLAN_VID] = {
2434 .name = "of_set_vlan_vid",
2435 .help = "OpenFlow's OFPAT_SET_VLAN_VID",
2438 sizeof(struct rte_flow_action_of_set_vlan_vid)),
2439 .next = NEXT(action_of_set_vlan_vid),
2442 [ACTION_OF_SET_VLAN_VID_VLAN_VID] = {
2445 .next = NEXT(action_of_set_vlan_vid, NEXT_ENTRY(UNSIGNED)),
2446 .args = ARGS(ARGS_ENTRY_HTON
2447 (struct rte_flow_action_of_set_vlan_vid,
2449 .call = parse_vc_conf,
2451 [ACTION_OF_SET_VLAN_PCP] = {
2452 .name = "of_set_vlan_pcp",
2453 .help = "OpenFlow's OFPAT_SET_VLAN_PCP",
2456 sizeof(struct rte_flow_action_of_set_vlan_pcp)),
2457 .next = NEXT(action_of_set_vlan_pcp),
2460 [ACTION_OF_SET_VLAN_PCP_VLAN_PCP] = {
2462 .help = "VLAN priority",
2463 .next = NEXT(action_of_set_vlan_pcp, NEXT_ENTRY(UNSIGNED)),
2464 .args = ARGS(ARGS_ENTRY_HTON
2465 (struct rte_flow_action_of_set_vlan_pcp,
2467 .call = parse_vc_conf,
2469 [ACTION_OF_POP_MPLS] = {
2470 .name = "of_pop_mpls",
2471 .help = "OpenFlow's OFPAT_POP_MPLS",
2472 .priv = PRIV_ACTION(OF_POP_MPLS,
2473 sizeof(struct rte_flow_action_of_pop_mpls)),
2474 .next = NEXT(action_of_pop_mpls),
2477 [ACTION_OF_POP_MPLS_ETHERTYPE] = {
2478 .name = "ethertype",
2479 .help = "EtherType",
2480 .next = NEXT(action_of_pop_mpls, NEXT_ENTRY(UNSIGNED)),
2481 .args = ARGS(ARGS_ENTRY_HTON
2482 (struct rte_flow_action_of_pop_mpls,
2484 .call = parse_vc_conf,
2486 [ACTION_OF_PUSH_MPLS] = {
2487 .name = "of_push_mpls",
2488 .help = "OpenFlow's OFPAT_PUSH_MPLS",
2491 sizeof(struct rte_flow_action_of_push_mpls)),
2492 .next = NEXT(action_of_push_mpls),
2495 [ACTION_OF_PUSH_MPLS_ETHERTYPE] = {
2496 .name = "ethertype",
2497 .help = "EtherType",
2498 .next = NEXT(action_of_push_mpls, NEXT_ENTRY(UNSIGNED)),
2499 .args = ARGS(ARGS_ENTRY_HTON
2500 (struct rte_flow_action_of_push_mpls,
2502 .call = parse_vc_conf,
2504 [ACTION_VXLAN_ENCAP] = {
2505 .name = "vxlan_encap",
2506 .help = "VXLAN encapsulation, uses configuration set by \"set"
2508 .priv = PRIV_ACTION(VXLAN_ENCAP,
2509 sizeof(struct action_vxlan_encap_data)),
2510 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2511 .call = parse_vc_action_vxlan_encap,
2513 [ACTION_VXLAN_DECAP] = {
2514 .name = "vxlan_decap",
2515 .help = "Performs a decapsulation action by stripping all"
2516 " headers of the VXLAN tunnel network overlay from the"
2518 .priv = PRIV_ACTION(VXLAN_DECAP, 0),
2519 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2522 [ACTION_NVGRE_ENCAP] = {
2523 .name = "nvgre_encap",
2524 .help = "NVGRE encapsulation, uses configuration set by \"set"
2526 .priv = PRIV_ACTION(NVGRE_ENCAP,
2527 sizeof(struct action_nvgre_encap_data)),
2528 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2529 .call = parse_vc_action_nvgre_encap,
2531 [ACTION_NVGRE_DECAP] = {
2532 .name = "nvgre_decap",
2533 .help = "Performs a decapsulation action by stripping all"
2534 " headers of the NVGRE tunnel network overlay from the"
2536 .priv = PRIV_ACTION(NVGRE_DECAP, 0),
2537 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2540 [ACTION_SET_IPV4_SRC] = {
2541 .name = "set_ipv4_src",
2542 .help = "Set a new IPv4 source address in the outermost"
2544 .priv = PRIV_ACTION(SET_IPV4_SRC,
2545 sizeof(struct rte_flow_action_set_ipv4)),
2546 .next = NEXT(action_set_ipv4_src),
2549 [ACTION_SET_IPV4_SRC_IPV4_SRC] = {
2550 .name = "ipv4_addr",
2551 .help = "new IPv4 source address to set",
2552 .next = NEXT(action_set_ipv4_src, NEXT_ENTRY(IPV4_ADDR)),
2553 .args = ARGS(ARGS_ENTRY_HTON
2554 (struct rte_flow_action_set_ipv4, ipv4_addr)),
2555 .call = parse_vc_conf,
2557 [ACTION_SET_IPV4_DST] = {
2558 .name = "set_ipv4_dst",
2559 .help = "Set a new IPv4 destination address in the outermost"
2561 .priv = PRIV_ACTION(SET_IPV4_DST,
2562 sizeof(struct rte_flow_action_set_ipv4)),
2563 .next = NEXT(action_set_ipv4_dst),
2566 [ACTION_SET_IPV4_DST_IPV4_DST] = {
2567 .name = "ipv4_addr",
2568 .help = "new IPv4 destination address to set",
2569 .next = NEXT(action_set_ipv4_dst, NEXT_ENTRY(IPV4_ADDR)),
2570 .args = ARGS(ARGS_ENTRY_HTON
2571 (struct rte_flow_action_set_ipv4, ipv4_addr)),
2572 .call = parse_vc_conf,
2574 [ACTION_SET_IPV6_SRC] = {
2575 .name = "set_ipv6_src",
2576 .help = "Set a new IPv6 source address in the outermost"
2578 .priv = PRIV_ACTION(SET_IPV6_SRC,
2579 sizeof(struct rte_flow_action_set_ipv6)),
2580 .next = NEXT(action_set_ipv6_src),
2583 [ACTION_SET_IPV6_SRC_IPV6_SRC] = {
2584 .name = "ipv6_addr",
2585 .help = "new IPv6 source address to set",
2586 .next = NEXT(action_set_ipv6_src, NEXT_ENTRY(IPV6_ADDR)),
2587 .args = ARGS(ARGS_ENTRY_HTON
2588 (struct rte_flow_action_set_ipv6, ipv6_addr)),
2589 .call = parse_vc_conf,
2591 [ACTION_SET_IPV6_DST] = {
2592 .name = "set_ipv6_dst",
2593 .help = "Set a new IPv6 destination address in the outermost"
2595 .priv = PRIV_ACTION(SET_IPV6_DST,
2596 sizeof(struct rte_flow_action_set_ipv6)),
2597 .next = NEXT(action_set_ipv6_dst),
2600 [ACTION_SET_IPV6_DST_IPV6_DST] = {
2601 .name = "ipv6_addr",
2602 .help = "new IPv6 destination address to set",
2603 .next = NEXT(action_set_ipv6_dst, NEXT_ENTRY(IPV6_ADDR)),
2604 .args = ARGS(ARGS_ENTRY_HTON
2605 (struct rte_flow_action_set_ipv6, ipv6_addr)),
2606 .call = parse_vc_conf,
2608 [ACTION_SET_TP_SRC] = {
2609 .name = "set_tp_src",
2610 .help = "set a new source port number in the outermost"
2612 .priv = PRIV_ACTION(SET_TP_SRC,
2613 sizeof(struct rte_flow_action_set_tp)),
2614 .next = NEXT(action_set_tp_src),
2617 [ACTION_SET_TP_SRC_TP_SRC] = {
2619 .help = "new source port number to set",
2620 .next = NEXT(action_set_tp_src, NEXT_ENTRY(UNSIGNED)),
2621 .args = ARGS(ARGS_ENTRY_HTON
2622 (struct rte_flow_action_set_tp, port)),
2623 .call = parse_vc_conf,
2625 [ACTION_SET_TP_DST] = {
2626 .name = "set_tp_dst",
2627 .help = "set a new destination port number in the outermost"
2629 .priv = PRIV_ACTION(SET_TP_DST,
2630 sizeof(struct rte_flow_action_set_tp)),
2631 .next = NEXT(action_set_tp_dst),
2634 [ACTION_SET_TP_DST_TP_DST] = {
2636 .help = "new destination port number to set",
2637 .next = NEXT(action_set_tp_dst, NEXT_ENTRY(UNSIGNED)),
2638 .args = ARGS(ARGS_ENTRY_HTON
2639 (struct rte_flow_action_set_tp, port)),
2640 .call = parse_vc_conf,
2642 [ACTION_MAC_SWAP] = {
2644 .help = "Swap the source and destination MAC addresses"
2645 " in the outermost Ethernet header",
2646 .priv = PRIV_ACTION(MAC_SWAP, 0),
2647 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2650 [ACTION_DEC_TTL] = {
2652 .help = "decrease network TTL if available",
2653 .priv = PRIV_ACTION(DEC_TTL, 0),
2654 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2657 [ACTION_SET_TTL] = {
2659 .help = "set ttl value",
2660 .priv = PRIV_ACTION(SET_TTL,
2661 sizeof(struct rte_flow_action_set_ttl)),
2662 .next = NEXT(action_set_ttl),
2665 [ACTION_SET_TTL_TTL] = {
2666 .name = "ttl_value",
2667 .help = "new ttl value to set",
2668 .next = NEXT(action_set_ttl, NEXT_ENTRY(UNSIGNED)),
2669 .args = ARGS(ARGS_ENTRY_HTON
2670 (struct rte_flow_action_set_ttl, ttl_value)),
2671 .call = parse_vc_conf,
2675 /** Remove and return last entry from argument stack. */
2676 static const struct arg *
2677 pop_args(struct context *ctx)
2679 return ctx->args_num ? ctx->args[--ctx->args_num] : NULL;
2682 /** Add entry on top of the argument stack. */
2684 push_args(struct context *ctx, const struct arg *arg)
2686 if (ctx->args_num == CTX_STACK_SIZE)
2688 ctx->args[ctx->args_num++] = arg;
2692 /** Spread value into buffer according to bit-mask. */
2694 arg_entry_bf_fill(void *dst, uintmax_t val, const struct arg *arg)
2696 uint32_t i = arg->size;
2704 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
2713 unsigned int shift = 0;
2714 uint8_t *buf = (uint8_t *)dst + arg->offset + (i -= sub);
2716 for (shift = 0; arg->mask[i] >> shift; ++shift) {
2717 if (!(arg->mask[i] & (1 << shift)))
2722 *buf &= ~(1 << shift);
2723 *buf |= (val & 1) << shift;
2731 /** Compare a string with a partial one of a given length. */
2733 strcmp_partial(const char *full, const char *partial, size_t partial_len)
2735 int r = strncmp(full, partial, partial_len);
2739 if (strlen(full) <= partial_len)
2741 return full[partial_len];
2745 * Parse a prefix length and generate a bit-mask.
2747 * Last argument (ctx->args) is retrieved to determine mask size, storage
2748 * location and whether the result must use network byte ordering.
2751 parse_prefix(struct context *ctx, const struct token *token,
2752 const char *str, unsigned int len,
2753 void *buf, unsigned int size)
2755 const struct arg *arg = pop_args(ctx);
2756 static const uint8_t conv[] = "\x00\x80\xc0\xe0\xf0\xf8\xfc\xfe\xff";
2763 /* Argument is expected. */
2767 u = strtoumax(str, &end, 0);
2768 if (errno || (size_t)(end - str) != len)
2773 extra = arg_entry_bf_fill(NULL, 0, arg);
2782 if (!arg_entry_bf_fill(ctx->object, v, arg) ||
2783 !arg_entry_bf_fill(ctx->objmask, -1, arg))
2790 if (bytes > size || bytes + !!extra > size)
2794 buf = (uint8_t *)ctx->object + arg->offset;
2795 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
2797 memset((uint8_t *)buf + size - bytes, 0xff, bytes);
2798 memset(buf, 0x00, size - bytes);
2800 ((uint8_t *)buf)[size - bytes - 1] = conv[extra];
2804 memset(buf, 0xff, bytes);
2805 memset((uint8_t *)buf + bytes, 0x00, size - bytes);
2807 ((uint8_t *)buf)[bytes] = conv[extra];
2810 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
2813 push_args(ctx, arg);
2817 /** Default parsing function for token name matching. */
2819 parse_default(struct context *ctx, const struct token *token,
2820 const char *str, unsigned int len,
2821 void *buf, unsigned int size)
2826 if (strcmp_partial(token->name, str, len))
2831 /** Parse flow command, initialize output buffer for subsequent tokens. */
2833 parse_init(struct context *ctx, const struct token *token,
2834 const char *str, unsigned int len,
2835 void *buf, unsigned int size)
2837 struct buffer *out = buf;
2839 /* Token name must match. */
2840 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
2842 /* Nothing else to do if there is no buffer. */
2845 /* Make sure buffer is large enough. */
2846 if (size < sizeof(*out))
2848 /* Initialize buffer. */
2849 memset(out, 0x00, sizeof(*out));
2850 memset((uint8_t *)out + sizeof(*out), 0x22, size - sizeof(*out));
2853 ctx->objmask = NULL;
2857 /** Parse tokens for validate/create commands. */
2859 parse_vc(struct context *ctx, const struct token *token,
2860 const char *str, unsigned int len,
2861 void *buf, unsigned int size)
2863 struct buffer *out = buf;
2867 /* Token name must match. */
2868 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
2870 /* Nothing else to do if there is no buffer. */
2873 if (!out->command) {
2874 if (ctx->curr != VALIDATE && ctx->curr != CREATE)
2876 if (sizeof(*out) > size)
2878 out->command = ctx->curr;
2881 ctx->objmask = NULL;
2882 out->args.vc.data = (uint8_t *)out + size;
2886 ctx->object = &out->args.vc.attr;
2887 ctx->objmask = NULL;
2888 switch (ctx->curr) {
2893 out->args.vc.attr.ingress = 1;
2896 out->args.vc.attr.egress = 1;
2899 out->args.vc.attr.transfer = 1;
2902 out->args.vc.pattern =
2903 (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
2905 ctx->object = out->args.vc.pattern;
2906 ctx->objmask = NULL;
2909 out->args.vc.actions =
2910 (void *)RTE_ALIGN_CEIL((uintptr_t)
2911 (out->args.vc.pattern +
2912 out->args.vc.pattern_n),
2914 ctx->object = out->args.vc.actions;
2915 ctx->objmask = NULL;
2922 if (!out->args.vc.actions) {
2923 const struct parse_item_priv *priv = token->priv;
2924 struct rte_flow_item *item =
2925 out->args.vc.pattern + out->args.vc.pattern_n;
2927 data_size = priv->size * 3; /* spec, last, mask */
2928 data = (void *)RTE_ALIGN_FLOOR((uintptr_t)
2929 (out->args.vc.data - data_size),
2931 if ((uint8_t *)item + sizeof(*item) > data)
2933 *item = (struct rte_flow_item){
2936 ++out->args.vc.pattern_n;
2938 ctx->objmask = NULL;
2940 const struct parse_action_priv *priv = token->priv;
2941 struct rte_flow_action *action =
2942 out->args.vc.actions + out->args.vc.actions_n;
2944 data_size = priv->size; /* configuration */
2945 data = (void *)RTE_ALIGN_FLOOR((uintptr_t)
2946 (out->args.vc.data - data_size),
2948 if ((uint8_t *)action + sizeof(*action) > data)
2950 *action = (struct rte_flow_action){
2952 .conf = data_size ? data : NULL,
2954 ++out->args.vc.actions_n;
2955 ctx->object = action;
2956 ctx->objmask = NULL;
2958 memset(data, 0, data_size);
2959 out->args.vc.data = data;
2960 ctx->objdata = data_size;
2964 /** Parse pattern item parameter type. */
2966 parse_vc_spec(struct context *ctx, const struct token *token,
2967 const char *str, unsigned int len,
2968 void *buf, unsigned int size)
2970 struct buffer *out = buf;
2971 struct rte_flow_item *item;
2977 /* Token name must match. */
2978 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
2980 /* Parse parameter types. */
2981 switch (ctx->curr) {
2982 static const enum index prefix[] = NEXT_ENTRY(PREFIX);
2988 case ITEM_PARAM_SPEC:
2991 case ITEM_PARAM_LAST:
2994 case ITEM_PARAM_PREFIX:
2995 /* Modify next token to expect a prefix. */
2996 if (ctx->next_num < 2)
2998 ctx->next[ctx->next_num - 2] = prefix;
3000 case ITEM_PARAM_MASK:
3006 /* Nothing else to do if there is no buffer. */
3009 if (!out->args.vc.pattern_n)
3011 item = &out->args.vc.pattern[out->args.vc.pattern_n - 1];
3012 data_size = ctx->objdata / 3; /* spec, last, mask */
3013 /* Point to selected object. */
3014 ctx->object = out->args.vc.data + (data_size * index);
3016 ctx->objmask = out->args.vc.data + (data_size * 2); /* mask */
3017 item->mask = ctx->objmask;
3019 ctx->objmask = NULL;
3020 /* Update relevant item pointer. */
3021 *((const void **[]){ &item->spec, &item->last, &item->mask })[index] =
3026 /** Parse action configuration field. */
3028 parse_vc_conf(struct context *ctx, const struct token *token,
3029 const char *str, unsigned int len,
3030 void *buf, unsigned int size)
3032 struct buffer *out = buf;
3035 /* Token name must match. */
3036 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
3038 /* Nothing else to do if there is no buffer. */
3041 /* Point to selected object. */
3042 ctx->object = out->args.vc.data;
3043 ctx->objmask = NULL;
3047 /** Parse RSS action. */
3049 parse_vc_action_rss(struct context *ctx, const struct token *token,
3050 const char *str, unsigned int len,
3051 void *buf, unsigned int size)
3053 struct buffer *out = buf;
3054 struct rte_flow_action *action;
3055 struct action_rss_data *action_rss_data;
3059 ret = parse_vc(ctx, token, str, len, buf, size);
3062 /* Nothing else to do if there is no buffer. */
3065 if (!out->args.vc.actions_n)
3067 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
3068 /* Point to selected object. */
3069 ctx->object = out->args.vc.data;
3070 ctx->objmask = NULL;
3071 /* Set up default configuration. */
3072 action_rss_data = ctx->object;
3073 *action_rss_data = (struct action_rss_data){
3074 .conf = (struct rte_flow_action_rss){
3075 .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
3078 .key_len = sizeof(action_rss_data->key),
3079 .queue_num = RTE_MIN(nb_rxq, ACTION_RSS_QUEUE_NUM),
3080 .key = action_rss_data->key,
3081 .queue = action_rss_data->queue,
3083 .key = "testpmd's default RSS hash key, "
3084 "override it for better balancing",
3087 for (i = 0; i < action_rss_data->conf.queue_num; ++i)
3088 action_rss_data->queue[i] = i;
3089 if (!port_id_is_invalid(ctx->port, DISABLED_WARN) &&
3090 ctx->port != (portid_t)RTE_PORT_ALL) {
3091 struct rte_eth_dev_info info;
3093 rte_eth_dev_info_get(ctx->port, &info);
3094 action_rss_data->conf.key_len =
3095 RTE_MIN(sizeof(action_rss_data->key),
3096 info.hash_key_size);
3098 action->conf = &action_rss_data->conf;
3103 * Parse func field for RSS action.
3105 * The RTE_ETH_HASH_FUNCTION_* value to assign is derived from the
3106 * ACTION_RSS_FUNC_* index that called this function.
3109 parse_vc_action_rss_func(struct context *ctx, const struct token *token,
3110 const char *str, unsigned int len,
3111 void *buf, unsigned int size)
3113 struct action_rss_data *action_rss_data;
3114 enum rte_eth_hash_function func;
3118 /* Token name must match. */
3119 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
3121 switch (ctx->curr) {
3122 case ACTION_RSS_FUNC_DEFAULT:
3123 func = RTE_ETH_HASH_FUNCTION_DEFAULT;
3125 case ACTION_RSS_FUNC_TOEPLITZ:
3126 func = RTE_ETH_HASH_FUNCTION_TOEPLITZ;
3128 case ACTION_RSS_FUNC_SIMPLE_XOR:
3129 func = RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
3136 action_rss_data = ctx->object;
3137 action_rss_data->conf.func = func;
3142 * Parse type field for RSS action.
3144 * Valid tokens are type field names and the "end" token.
3147 parse_vc_action_rss_type(struct context *ctx, const struct token *token,
3148 const char *str, unsigned int len,
3149 void *buf, unsigned int size)
3151 static const enum index next[] = NEXT_ENTRY(ACTION_RSS_TYPE);
3152 struct action_rss_data *action_rss_data;
3158 if (ctx->curr != ACTION_RSS_TYPE)
3160 if (!(ctx->objdata >> 16) && ctx->object) {
3161 action_rss_data = ctx->object;
3162 action_rss_data->conf.types = 0;
3164 if (!strcmp_partial("end", str, len)) {
3165 ctx->objdata &= 0xffff;
3168 for (i = 0; rss_type_table[i].str; ++i)
3169 if (!strcmp_partial(rss_type_table[i].str, str, len))
3171 if (!rss_type_table[i].str)
3173 ctx->objdata = 1 << 16 | (ctx->objdata & 0xffff);
3175 if (ctx->next_num == RTE_DIM(ctx->next))
3177 ctx->next[ctx->next_num++] = next;
3180 action_rss_data = ctx->object;
3181 action_rss_data->conf.types |= rss_type_table[i].rss_type;
3186 * Parse queue field for RSS action.
3188 * Valid tokens are queue indices and the "end" token.
3191 parse_vc_action_rss_queue(struct context *ctx, const struct token *token,
3192 const char *str, unsigned int len,
3193 void *buf, unsigned int size)
3195 static const enum index next[] = NEXT_ENTRY(ACTION_RSS_QUEUE);
3196 struct action_rss_data *action_rss_data;
3203 if (ctx->curr != ACTION_RSS_QUEUE)
3205 i = ctx->objdata >> 16;
3206 if (!strcmp_partial("end", str, len)) {
3207 ctx->objdata &= 0xffff;
3210 if (i >= ACTION_RSS_QUEUE_NUM)
3213 ARGS_ENTRY_ARB(offsetof(struct action_rss_data, queue) +
3214 i * sizeof(action_rss_data->queue[i]),
3215 sizeof(action_rss_data->queue[i]))))
3217 ret = parse_int(ctx, token, str, len, NULL, 0);
3223 ctx->objdata = i << 16 | (ctx->objdata & 0xffff);
3225 if (ctx->next_num == RTE_DIM(ctx->next))
3227 ctx->next[ctx->next_num++] = next;
3231 action_rss_data = ctx->object;
3232 action_rss_data->conf.queue_num = i;
3233 action_rss_data->conf.queue = i ? action_rss_data->queue : NULL;
3237 /** Parse VXLAN encap action. */
3239 parse_vc_action_vxlan_encap(struct context *ctx, const struct token *token,
3240 const char *str, unsigned int len,
3241 void *buf, unsigned int size)
3243 struct buffer *out = buf;
3244 struct rte_flow_action *action;
3245 struct action_vxlan_encap_data *action_vxlan_encap_data;
3248 ret = parse_vc(ctx, token, str, len, buf, size);
3251 /* Nothing else to do if there is no buffer. */
3254 if (!out->args.vc.actions_n)
3256 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
3257 /* Point to selected object. */
3258 ctx->object = out->args.vc.data;
3259 ctx->objmask = NULL;
3260 /* Set up default configuration. */
3261 action_vxlan_encap_data = ctx->object;
3262 *action_vxlan_encap_data = (struct action_vxlan_encap_data){
3263 .conf = (struct rte_flow_action_vxlan_encap){
3264 .definition = action_vxlan_encap_data->items,
3268 .type = RTE_FLOW_ITEM_TYPE_ETH,
3269 .spec = &action_vxlan_encap_data->item_eth,
3270 .mask = &rte_flow_item_eth_mask,
3273 .type = RTE_FLOW_ITEM_TYPE_VLAN,
3274 .spec = &action_vxlan_encap_data->item_vlan,
3275 .mask = &rte_flow_item_vlan_mask,
3278 .type = RTE_FLOW_ITEM_TYPE_IPV4,
3279 .spec = &action_vxlan_encap_data->item_ipv4,
3280 .mask = &rte_flow_item_ipv4_mask,
3283 .type = RTE_FLOW_ITEM_TYPE_UDP,
3284 .spec = &action_vxlan_encap_data->item_udp,
3285 .mask = &rte_flow_item_udp_mask,
3288 .type = RTE_FLOW_ITEM_TYPE_VXLAN,
3289 .spec = &action_vxlan_encap_data->item_vxlan,
3290 .mask = &rte_flow_item_vxlan_mask,
3293 .type = RTE_FLOW_ITEM_TYPE_END,
3298 .tci = vxlan_encap_conf.vlan_tci,
3302 .src_addr = vxlan_encap_conf.ipv4_src,
3303 .dst_addr = vxlan_encap_conf.ipv4_dst,
3306 .src_port = vxlan_encap_conf.udp_src,
3307 .dst_port = vxlan_encap_conf.udp_dst,
3309 .item_vxlan.flags = 0,
3311 memcpy(action_vxlan_encap_data->item_eth.dst.addr_bytes,
3312 vxlan_encap_conf.eth_dst, ETHER_ADDR_LEN);
3313 memcpy(action_vxlan_encap_data->item_eth.src.addr_bytes,
3314 vxlan_encap_conf.eth_src, ETHER_ADDR_LEN);
3315 if (!vxlan_encap_conf.select_ipv4) {
3316 memcpy(&action_vxlan_encap_data->item_ipv6.hdr.src_addr,
3317 &vxlan_encap_conf.ipv6_src,
3318 sizeof(vxlan_encap_conf.ipv6_src));
3319 memcpy(&action_vxlan_encap_data->item_ipv6.hdr.dst_addr,
3320 &vxlan_encap_conf.ipv6_dst,
3321 sizeof(vxlan_encap_conf.ipv6_dst));
3322 action_vxlan_encap_data->items[2] = (struct rte_flow_item){
3323 .type = RTE_FLOW_ITEM_TYPE_IPV6,
3324 .spec = &action_vxlan_encap_data->item_ipv6,
3325 .mask = &rte_flow_item_ipv6_mask,
3328 if (!vxlan_encap_conf.select_vlan)
3329 action_vxlan_encap_data->items[1].type =
3330 RTE_FLOW_ITEM_TYPE_VOID;
3331 memcpy(action_vxlan_encap_data->item_vxlan.vni, vxlan_encap_conf.vni,
3332 RTE_DIM(vxlan_encap_conf.vni));
3333 action->conf = &action_vxlan_encap_data->conf;
3337 /** Parse NVGRE encap action. */
3339 parse_vc_action_nvgre_encap(struct context *ctx, const struct token *token,
3340 const char *str, unsigned int len,
3341 void *buf, unsigned int size)
3343 struct buffer *out = buf;
3344 struct rte_flow_action *action;
3345 struct action_nvgre_encap_data *action_nvgre_encap_data;
3348 ret = parse_vc(ctx, token, str, len, buf, size);
3351 /* Nothing else to do if there is no buffer. */
3354 if (!out->args.vc.actions_n)
3356 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
3357 /* Point to selected object. */
3358 ctx->object = out->args.vc.data;
3359 ctx->objmask = NULL;
3360 /* Set up default configuration. */
3361 action_nvgre_encap_data = ctx->object;
3362 *action_nvgre_encap_data = (struct action_nvgre_encap_data){
3363 .conf = (struct rte_flow_action_nvgre_encap){
3364 .definition = action_nvgre_encap_data->items,
3368 .type = RTE_FLOW_ITEM_TYPE_ETH,
3369 .spec = &action_nvgre_encap_data->item_eth,
3370 .mask = &rte_flow_item_eth_mask,
3373 .type = RTE_FLOW_ITEM_TYPE_VLAN,
3374 .spec = &action_nvgre_encap_data->item_vlan,
3375 .mask = &rte_flow_item_vlan_mask,
3378 .type = RTE_FLOW_ITEM_TYPE_IPV4,
3379 .spec = &action_nvgre_encap_data->item_ipv4,
3380 .mask = &rte_flow_item_ipv4_mask,
3383 .type = RTE_FLOW_ITEM_TYPE_NVGRE,
3384 .spec = &action_nvgre_encap_data->item_nvgre,
3385 .mask = &rte_flow_item_nvgre_mask,
3388 .type = RTE_FLOW_ITEM_TYPE_END,
3393 .tci = nvgre_encap_conf.vlan_tci,
3397 .src_addr = nvgre_encap_conf.ipv4_src,
3398 .dst_addr = nvgre_encap_conf.ipv4_dst,
3400 .item_nvgre.flow_id = 0,
3402 memcpy(action_nvgre_encap_data->item_eth.dst.addr_bytes,
3403 nvgre_encap_conf.eth_dst, ETHER_ADDR_LEN);
3404 memcpy(action_nvgre_encap_data->item_eth.src.addr_bytes,
3405 nvgre_encap_conf.eth_src, ETHER_ADDR_LEN);
3406 if (!nvgre_encap_conf.select_ipv4) {
3407 memcpy(&action_nvgre_encap_data->item_ipv6.hdr.src_addr,
3408 &nvgre_encap_conf.ipv6_src,
3409 sizeof(nvgre_encap_conf.ipv6_src));
3410 memcpy(&action_nvgre_encap_data->item_ipv6.hdr.dst_addr,
3411 &nvgre_encap_conf.ipv6_dst,
3412 sizeof(nvgre_encap_conf.ipv6_dst));
3413 action_nvgre_encap_data->items[2] = (struct rte_flow_item){
3414 .type = RTE_FLOW_ITEM_TYPE_IPV6,
3415 .spec = &action_nvgre_encap_data->item_ipv6,
3416 .mask = &rte_flow_item_ipv6_mask,
3419 if (!nvgre_encap_conf.select_vlan)
3420 action_nvgre_encap_data->items[1].type =
3421 RTE_FLOW_ITEM_TYPE_VOID;
3422 memcpy(action_nvgre_encap_data->item_nvgre.tni, nvgre_encap_conf.tni,
3423 RTE_DIM(nvgre_encap_conf.tni));
3424 action->conf = &action_nvgre_encap_data->conf;
3428 /** Parse tokens for destroy command. */
3430 parse_destroy(struct context *ctx, const struct token *token,
3431 const char *str, unsigned int len,
3432 void *buf, unsigned int size)
3434 struct buffer *out = buf;
3436 /* Token name must match. */
3437 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
3439 /* Nothing else to do if there is no buffer. */
3442 if (!out->command) {
3443 if (ctx->curr != DESTROY)
3445 if (sizeof(*out) > size)
3447 out->command = ctx->curr;
3450 ctx->objmask = NULL;
3451 out->args.destroy.rule =
3452 (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
3456 if (((uint8_t *)(out->args.destroy.rule + out->args.destroy.rule_n) +
3457 sizeof(*out->args.destroy.rule)) > (uint8_t *)out + size)
3460 ctx->object = out->args.destroy.rule + out->args.destroy.rule_n++;
3461 ctx->objmask = NULL;
3465 /** Parse tokens for flush command. */
3467 parse_flush(struct context *ctx, const struct token *token,
3468 const char *str, unsigned int len,
3469 void *buf, unsigned int size)
3471 struct buffer *out = buf;
3473 /* Token name must match. */
3474 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
3476 /* Nothing else to do if there is no buffer. */
3479 if (!out->command) {
3480 if (ctx->curr != FLUSH)
3482 if (sizeof(*out) > size)
3484 out->command = ctx->curr;
3487 ctx->objmask = NULL;
3492 /** Parse tokens for query command. */
3494 parse_query(struct context *ctx, const struct token *token,
3495 const char *str, unsigned int len,
3496 void *buf, unsigned int size)
3498 struct buffer *out = buf;
3500 /* Token name must match. */
3501 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
3503 /* Nothing else to do if there is no buffer. */
3506 if (!out->command) {
3507 if (ctx->curr != QUERY)
3509 if (sizeof(*out) > size)
3511 out->command = ctx->curr;
3514 ctx->objmask = NULL;
3519 /** Parse action names. */
3521 parse_action(struct context *ctx, const struct token *token,
3522 const char *str, unsigned int len,
3523 void *buf, unsigned int size)
3525 struct buffer *out = buf;
3526 const struct arg *arg = pop_args(ctx);
3530 /* Argument is expected. */
3533 /* Parse action name. */
3534 for (i = 0; next_action[i]; ++i) {
3535 const struct parse_action_priv *priv;
3537 token = &token_list[next_action[i]];
3538 if (strcmp_partial(token->name, str, len))
3544 memcpy((uint8_t *)ctx->object + arg->offset,
3550 push_args(ctx, arg);
3554 /** Parse tokens for list command. */
3556 parse_list(struct context *ctx, const struct token *token,
3557 const char *str, unsigned int len,
3558 void *buf, unsigned int size)
3560 struct buffer *out = buf;
3562 /* Token name must match. */
3563 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
3565 /* Nothing else to do if there is no buffer. */
3568 if (!out->command) {
3569 if (ctx->curr != LIST)
3571 if (sizeof(*out) > size)
3573 out->command = ctx->curr;
3576 ctx->objmask = NULL;
3577 out->args.list.group =
3578 (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
3582 if (((uint8_t *)(out->args.list.group + out->args.list.group_n) +
3583 sizeof(*out->args.list.group)) > (uint8_t *)out + size)
3586 ctx->object = out->args.list.group + out->args.list.group_n++;
3587 ctx->objmask = NULL;
3591 /** Parse tokens for isolate command. */
3593 parse_isolate(struct context *ctx, const struct token *token,
3594 const char *str, unsigned int len,
3595 void *buf, unsigned int size)
3597 struct buffer *out = buf;
3599 /* Token name must match. */
3600 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
3602 /* Nothing else to do if there is no buffer. */
3605 if (!out->command) {
3606 if (ctx->curr != ISOLATE)
3608 if (sizeof(*out) > size)
3610 out->command = ctx->curr;
3613 ctx->objmask = NULL;
3619 * Parse signed/unsigned integers 8 to 64-bit long.
3621 * Last argument (ctx->args) is retrieved to determine integer type and
3625 parse_int(struct context *ctx, const struct token *token,
3626 const char *str, unsigned int len,
3627 void *buf, unsigned int size)
3629 const struct arg *arg = pop_args(ctx);
3634 /* Argument is expected. */
3639 (uintmax_t)strtoimax(str, &end, 0) :
3640 strtoumax(str, &end, 0);
3641 if (errno || (size_t)(end - str) != len)
3644 ((arg->sign && ((intmax_t)u < (intmax_t)arg->min ||
3645 (intmax_t)u > (intmax_t)arg->max)) ||
3646 (!arg->sign && (u < arg->min || u > arg->max))))
3651 if (!arg_entry_bf_fill(ctx->object, u, arg) ||
3652 !arg_entry_bf_fill(ctx->objmask, -1, arg))
3656 buf = (uint8_t *)ctx->object + arg->offset;
3660 case sizeof(uint8_t):
3661 *(uint8_t *)buf = u;
3663 case sizeof(uint16_t):
3664 *(uint16_t *)buf = arg->hton ? rte_cpu_to_be_16(u) : u;
3666 case sizeof(uint8_t [3]):
3667 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
3669 ((uint8_t *)buf)[0] = u;
3670 ((uint8_t *)buf)[1] = u >> 8;
3671 ((uint8_t *)buf)[2] = u >> 16;
3675 ((uint8_t *)buf)[0] = u >> 16;
3676 ((uint8_t *)buf)[1] = u >> 8;
3677 ((uint8_t *)buf)[2] = u;
3679 case sizeof(uint32_t):
3680 *(uint32_t *)buf = arg->hton ? rte_cpu_to_be_32(u) : u;
3682 case sizeof(uint64_t):
3683 *(uint64_t *)buf = arg->hton ? rte_cpu_to_be_64(u) : u;
3688 if (ctx->objmask && buf != (uint8_t *)ctx->objmask + arg->offset) {
3690 buf = (uint8_t *)ctx->objmask + arg->offset;
3695 push_args(ctx, arg);
3702 * Three arguments (ctx->args) are retrieved from the stack to store data,
3703 * its actual length and address (in that order).
3706 parse_string(struct context *ctx, const struct token *token,
3707 const char *str, unsigned int len,
3708 void *buf, unsigned int size)
3710 const struct arg *arg_data = pop_args(ctx);
3711 const struct arg *arg_len = pop_args(ctx);
3712 const struct arg *arg_addr = pop_args(ctx);
3713 char tmp[16]; /* Ought to be enough. */
3716 /* Arguments are expected. */
3720 push_args(ctx, arg_data);
3724 push_args(ctx, arg_len);
3725 push_args(ctx, arg_data);
3728 size = arg_data->size;
3729 /* Bit-mask fill is not supported. */
3730 if (arg_data->mask || size < len)
3734 /* Let parse_int() fill length information first. */
3735 ret = snprintf(tmp, sizeof(tmp), "%u", len);
3738 push_args(ctx, arg_len);
3739 ret = parse_int(ctx, token, tmp, ret, NULL, 0);
3744 buf = (uint8_t *)ctx->object + arg_data->offset;
3745 /* Output buffer is not necessarily NUL-terminated. */
3746 memcpy(buf, str, len);
3747 memset((uint8_t *)buf + len, 0x00, size - len);
3749 memset((uint8_t *)ctx->objmask + arg_data->offset, 0xff, len);
3750 /* Save address if requested. */
3751 if (arg_addr->size) {
3752 memcpy((uint8_t *)ctx->object + arg_addr->offset,
3754 (uint8_t *)ctx->object + arg_data->offset
3758 memcpy((uint8_t *)ctx->objmask + arg_addr->offset,
3760 (uint8_t *)ctx->objmask + arg_data->offset
3766 push_args(ctx, arg_addr);
3767 push_args(ctx, arg_len);
3768 push_args(ctx, arg_data);
3773 * Parse a MAC address.
3775 * Last argument (ctx->args) is retrieved to determine storage size and
3779 parse_mac_addr(struct context *ctx, const struct token *token,
3780 const char *str, unsigned int len,
3781 void *buf, unsigned int size)
3783 const struct arg *arg = pop_args(ctx);
3784 struct ether_addr tmp;
3788 /* Argument is expected. */
3792 /* Bit-mask fill is not supported. */
3793 if (arg->mask || size != sizeof(tmp))
3795 /* Only network endian is supported. */
3798 ret = cmdline_parse_etheraddr(NULL, str, &tmp, size);
3799 if (ret < 0 || (unsigned int)ret != len)
3803 buf = (uint8_t *)ctx->object + arg->offset;
3804 memcpy(buf, &tmp, size);
3806 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
3809 push_args(ctx, arg);
3814 * Parse an IPv4 address.
3816 * Last argument (ctx->args) is retrieved to determine storage size and
3820 parse_ipv4_addr(struct context *ctx, const struct token *token,
3821 const char *str, unsigned int len,
3822 void *buf, unsigned int size)
3824 const struct arg *arg = pop_args(ctx);
3829 /* Argument is expected. */
3833 /* Bit-mask fill is not supported. */
3834 if (arg->mask || size != sizeof(tmp))
3836 /* Only network endian is supported. */
3839 memcpy(str2, str, len);
3841 ret = inet_pton(AF_INET, str2, &tmp);
3843 /* Attempt integer parsing. */
3844 push_args(ctx, arg);
3845 return parse_int(ctx, token, str, len, buf, size);
3849 buf = (uint8_t *)ctx->object + arg->offset;
3850 memcpy(buf, &tmp, size);
3852 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
3855 push_args(ctx, arg);
3860 * Parse an IPv6 address.
3862 * Last argument (ctx->args) is retrieved to determine storage size and
3866 parse_ipv6_addr(struct context *ctx, const struct token *token,
3867 const char *str, unsigned int len,
3868 void *buf, unsigned int size)
3870 const struct arg *arg = pop_args(ctx);
3872 struct in6_addr tmp;
3876 /* Argument is expected. */
3880 /* Bit-mask fill is not supported. */
3881 if (arg->mask || size != sizeof(tmp))
3883 /* Only network endian is supported. */
3886 memcpy(str2, str, len);
3888 ret = inet_pton(AF_INET6, str2, &tmp);
3893 buf = (uint8_t *)ctx->object + arg->offset;
3894 memcpy(buf, &tmp, size);
3896 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
3899 push_args(ctx, arg);
3903 /** Boolean values (even indices stand for false). */
3904 static const char *const boolean_name[] = {
3914 * Parse a boolean value.
3916 * Last argument (ctx->args) is retrieved to determine storage size and
3920 parse_boolean(struct context *ctx, const struct token *token,
3921 const char *str, unsigned int len,
3922 void *buf, unsigned int size)
3924 const struct arg *arg = pop_args(ctx);
3928 /* Argument is expected. */
3931 for (i = 0; boolean_name[i]; ++i)
3932 if (!strcmp_partial(boolean_name[i], str, len))
3934 /* Process token as integer. */
3935 if (boolean_name[i])
3936 str = i & 1 ? "1" : "0";
3937 push_args(ctx, arg);
3938 ret = parse_int(ctx, token, str, strlen(str), buf, size);
3939 return ret > 0 ? (int)len : ret;
3942 /** Parse port and update context. */
3944 parse_port(struct context *ctx, const struct token *token,
3945 const char *str, unsigned int len,
3946 void *buf, unsigned int size)
3948 struct buffer *out = &(struct buffer){ .port = 0 };
3956 ctx->objmask = NULL;
3957 size = sizeof(*out);
3959 ret = parse_int(ctx, token, str, len, out, size);
3961 ctx->port = out->port;
3967 /** No completion. */
3969 comp_none(struct context *ctx, const struct token *token,
3970 unsigned int ent, char *buf, unsigned int size)
3980 /** Complete boolean values. */
3982 comp_boolean(struct context *ctx, const struct token *token,
3983 unsigned int ent, char *buf, unsigned int size)
3989 for (i = 0; boolean_name[i]; ++i)
3990 if (buf && i == ent)
3991 return snprintf(buf, size, "%s", boolean_name[i]);
3997 /** Complete action names. */
3999 comp_action(struct context *ctx, const struct token *token,
4000 unsigned int ent, char *buf, unsigned int size)
4006 for (i = 0; next_action[i]; ++i)
4007 if (buf && i == ent)
4008 return snprintf(buf, size, "%s",
4009 token_list[next_action[i]].name);
4015 /** Complete available ports. */
4017 comp_port(struct context *ctx, const struct token *token,
4018 unsigned int ent, char *buf, unsigned int size)
4025 RTE_ETH_FOREACH_DEV(p) {
4026 if (buf && i == ent)
4027 return snprintf(buf, size, "%u", p);
4035 /** Complete available rule IDs. */
4037 comp_rule_id(struct context *ctx, const struct token *token,
4038 unsigned int ent, char *buf, unsigned int size)
4041 struct rte_port *port;
4042 struct port_flow *pf;
4045 if (port_id_is_invalid(ctx->port, DISABLED_WARN) ||
4046 ctx->port == (portid_t)RTE_PORT_ALL)
4048 port = &ports[ctx->port];
4049 for (pf = port->flow_list; pf != NULL; pf = pf->next) {
4050 if (buf && i == ent)
4051 return snprintf(buf, size, "%u", pf->id);
4059 /** Complete type field for RSS action. */
4061 comp_vc_action_rss_type(struct context *ctx, const struct token *token,
4062 unsigned int ent, char *buf, unsigned int size)
4068 for (i = 0; rss_type_table[i].str; ++i)
4073 return snprintf(buf, size, "%s", rss_type_table[ent].str);
4075 return snprintf(buf, size, "end");
4079 /** Complete queue field for RSS action. */
4081 comp_vc_action_rss_queue(struct context *ctx, const struct token *token,
4082 unsigned int ent, char *buf, unsigned int size)
4089 return snprintf(buf, size, "%u", ent);
4091 return snprintf(buf, size, "end");
4095 /** Internal context. */
4096 static struct context cmd_flow_context;
4098 /** Global parser instance (cmdline API). */
4099 cmdline_parse_inst_t cmd_flow;
4101 /** Initialize context. */
4103 cmd_flow_context_init(struct context *ctx)
4105 /* A full memset() is not necessary. */
4115 ctx->objmask = NULL;
4118 /** Parse a token (cmdline API). */
4120 cmd_flow_parse(cmdline_parse_token_hdr_t *hdr, const char *src, void *result,
4123 struct context *ctx = &cmd_flow_context;
4124 const struct token *token;
4125 const enum index *list;
4130 token = &token_list[ctx->curr];
4131 /* Check argument length. */
4134 for (len = 0; src[len]; ++len)
4135 if (src[len] == '#' || isspace(src[len]))
4139 /* Last argument and EOL detection. */
4140 for (i = len; src[i]; ++i)
4141 if (src[i] == '#' || src[i] == '\r' || src[i] == '\n')
4143 else if (!isspace(src[i])) {
4148 if (src[i] == '\r' || src[i] == '\n') {
4152 /* Initialize context if necessary. */
4153 if (!ctx->next_num) {
4156 ctx->next[ctx->next_num++] = token->next[0];
4158 /* Process argument through candidates. */
4159 ctx->prev = ctx->curr;
4160 list = ctx->next[ctx->next_num - 1];
4161 for (i = 0; list[i]; ++i) {
4162 const struct token *next = &token_list[list[i]];
4165 ctx->curr = list[i];
4167 tmp = next->call(ctx, next, src, len, result, size);
4169 tmp = parse_default(ctx, next, src, len, result, size);
4170 if (tmp == -1 || tmp != len)
4178 /* Push subsequent tokens if any. */
4180 for (i = 0; token->next[i]; ++i) {
4181 if (ctx->next_num == RTE_DIM(ctx->next))
4183 ctx->next[ctx->next_num++] = token->next[i];
4185 /* Push arguments if any. */
4187 for (i = 0; token->args[i]; ++i) {
4188 if (ctx->args_num == RTE_DIM(ctx->args))
4190 ctx->args[ctx->args_num++] = token->args[i];
4195 /** Return number of completion entries (cmdline API). */
4197 cmd_flow_complete_get_nb(cmdline_parse_token_hdr_t *hdr)
4199 struct context *ctx = &cmd_flow_context;
4200 const struct token *token = &token_list[ctx->curr];
4201 const enum index *list;
4205 /* Count number of tokens in current list. */
4207 list = ctx->next[ctx->next_num - 1];
4209 list = token->next[0];
4210 for (i = 0; list[i]; ++i)
4215 * If there is a single token, use its completion callback, otherwise
4216 * return the number of entries.
4218 token = &token_list[list[0]];
4219 if (i == 1 && token->comp) {
4220 /* Save index for cmd_flow_get_help(). */
4221 ctx->prev = list[0];
4222 return token->comp(ctx, token, 0, NULL, 0);
4227 /** Return a completion entry (cmdline API). */
4229 cmd_flow_complete_get_elt(cmdline_parse_token_hdr_t *hdr, int index,
4230 char *dst, unsigned int size)
4232 struct context *ctx = &cmd_flow_context;
4233 const struct token *token = &token_list[ctx->curr];
4234 const enum index *list;
4238 /* Count number of tokens in current list. */
4240 list = ctx->next[ctx->next_num - 1];
4242 list = token->next[0];
4243 for (i = 0; list[i]; ++i)
4247 /* If there is a single token, use its completion callback. */
4248 token = &token_list[list[0]];
4249 if (i == 1 && token->comp) {
4250 /* Save index for cmd_flow_get_help(). */
4251 ctx->prev = list[0];
4252 return token->comp(ctx, token, index, dst, size) < 0 ? -1 : 0;
4254 /* Otherwise make sure the index is valid and use defaults. */
4257 token = &token_list[list[index]];
4258 snprintf(dst, size, "%s", token->name);
4259 /* Save index for cmd_flow_get_help(). */
4260 ctx->prev = list[index];
4264 /** Populate help strings for current token (cmdline API). */
4266 cmd_flow_get_help(cmdline_parse_token_hdr_t *hdr, char *dst, unsigned int size)
4268 struct context *ctx = &cmd_flow_context;
4269 const struct token *token = &token_list[ctx->prev];
4274 /* Set token type and update global help with details. */
4275 snprintf(dst, size, "%s", (token->type ? token->type : "TOKEN"));
4277 cmd_flow.help_str = token->help;
4279 cmd_flow.help_str = token->name;
4283 /** Token definition template (cmdline API). */
4284 static struct cmdline_token_hdr cmd_flow_token_hdr = {
4285 .ops = &(struct cmdline_token_ops){
4286 .parse = cmd_flow_parse,
4287 .complete_get_nb = cmd_flow_complete_get_nb,
4288 .complete_get_elt = cmd_flow_complete_get_elt,
4289 .get_help = cmd_flow_get_help,
4294 /** Populate the next dynamic token. */
4296 cmd_flow_tok(cmdline_parse_token_hdr_t **hdr,
4297 cmdline_parse_token_hdr_t **hdr_inst)
4299 struct context *ctx = &cmd_flow_context;
4301 /* Always reinitialize context before requesting the first token. */
4302 if (!(hdr_inst - cmd_flow.tokens))
4303 cmd_flow_context_init(ctx);
4304 /* Return NULL when no more tokens are expected. */
4305 if (!ctx->next_num && ctx->curr) {
4309 /* Determine if command should end here. */
4310 if (ctx->eol && ctx->last && ctx->next_num) {
4311 const enum index *list = ctx->next[ctx->next_num - 1];
4314 for (i = 0; list[i]; ++i) {
4321 *hdr = &cmd_flow_token_hdr;
4324 /** Dispatch parsed buffer to function calls. */
4326 cmd_flow_parsed(const struct buffer *in)
4328 switch (in->command) {
4330 port_flow_validate(in->port, &in->args.vc.attr,
4331 in->args.vc.pattern, in->args.vc.actions);
4334 port_flow_create(in->port, &in->args.vc.attr,
4335 in->args.vc.pattern, in->args.vc.actions);
4338 port_flow_destroy(in->port, in->args.destroy.rule_n,
4339 in->args.destroy.rule);
4342 port_flow_flush(in->port);
4345 port_flow_query(in->port, in->args.query.rule,
4346 &in->args.query.action);
4349 port_flow_list(in->port, in->args.list.group_n,
4350 in->args.list.group);
4353 port_flow_isolate(in->port, in->args.isolate.set);
4360 /** Token generator and output processing callback (cmdline API). */
4362 cmd_flow_cb(void *arg0, struct cmdline *cl, void *arg2)
4365 cmd_flow_tok(arg0, arg2);
4367 cmd_flow_parsed(arg0);
4370 /** Global parser instance (cmdline API). */
4371 cmdline_parse_inst_t cmd_flow = {
4373 .data = NULL, /**< Unused. */
4374 .help_str = NULL, /**< Updated by cmd_flow_get_help(). */
4377 }, /**< Tokens are returned by cmd_flow_tok(). */