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,
263 ACTION_SET_MAC_SRC_MAC_SRC,
265 ACTION_SET_MAC_DST_MAC_DST,
268 /** Maximum size for pattern in struct rte_flow_item_raw. */
269 #define ITEM_RAW_PATTERN_SIZE 40
271 /** Storage size for struct rte_flow_item_raw including pattern. */
272 #define ITEM_RAW_SIZE \
273 (sizeof(struct rte_flow_item_raw) + ITEM_RAW_PATTERN_SIZE)
275 /** Maximum number of queue indices in struct rte_flow_action_rss. */
276 #define ACTION_RSS_QUEUE_NUM 32
278 /** Storage for struct rte_flow_action_rss including external data. */
279 struct action_rss_data {
280 struct rte_flow_action_rss conf;
281 uint8_t key[RSS_HASH_KEY_LENGTH];
282 uint16_t queue[ACTION_RSS_QUEUE_NUM];
285 /** Maximum number of items in struct rte_flow_action_vxlan_encap. */
286 #define ACTION_VXLAN_ENCAP_ITEMS_NUM 6
288 /** Storage for struct rte_flow_action_vxlan_encap including external data. */
289 struct action_vxlan_encap_data {
290 struct rte_flow_action_vxlan_encap conf;
291 struct rte_flow_item items[ACTION_VXLAN_ENCAP_ITEMS_NUM];
292 struct rte_flow_item_eth item_eth;
293 struct rte_flow_item_vlan item_vlan;
295 struct rte_flow_item_ipv4 item_ipv4;
296 struct rte_flow_item_ipv6 item_ipv6;
298 struct rte_flow_item_udp item_udp;
299 struct rte_flow_item_vxlan item_vxlan;
302 /** Maximum number of items in struct rte_flow_action_nvgre_encap. */
303 #define ACTION_NVGRE_ENCAP_ITEMS_NUM 5
305 /** Storage for struct rte_flow_action_nvgre_encap including external data. */
306 struct action_nvgre_encap_data {
307 struct rte_flow_action_nvgre_encap conf;
308 struct rte_flow_item items[ACTION_NVGRE_ENCAP_ITEMS_NUM];
309 struct rte_flow_item_eth item_eth;
310 struct rte_flow_item_vlan item_vlan;
312 struct rte_flow_item_ipv4 item_ipv4;
313 struct rte_flow_item_ipv6 item_ipv6;
315 struct rte_flow_item_nvgre item_nvgre;
318 /** Maximum number of subsequent tokens and arguments on the stack. */
319 #define CTX_STACK_SIZE 16
321 /** Parser context. */
323 /** Stack of subsequent token lists to process. */
324 const enum index *next[CTX_STACK_SIZE];
325 /** Arguments for stacked tokens. */
326 const void *args[CTX_STACK_SIZE];
327 enum index curr; /**< Current token index. */
328 enum index prev; /**< Index of the last token seen. */
329 int next_num; /**< Number of entries in next[]. */
330 int args_num; /**< Number of entries in args[]. */
331 uint32_t eol:1; /**< EOL has been detected. */
332 uint32_t last:1; /**< No more arguments. */
333 portid_t port; /**< Current port ID (for completions). */
334 uint32_t objdata; /**< Object-specific data. */
335 void *object; /**< Address of current object for relative offsets. */
336 void *objmask; /**< Object a full mask must be written to. */
339 /** Token argument. */
341 uint32_t hton:1; /**< Use network byte ordering. */
342 uint32_t sign:1; /**< Value is signed. */
343 uint32_t bounded:1; /**< Value is bounded. */
344 uintmax_t min; /**< Minimum value if bounded. */
345 uintmax_t max; /**< Maximum value if bounded. */
346 uint32_t offset; /**< Relative offset from ctx->object. */
347 uint32_t size; /**< Field size. */
348 const uint8_t *mask; /**< Bit-mask to use instead of offset/size. */
351 /** Parser token definition. */
353 /** Type displayed during completion (defaults to "TOKEN"). */
355 /** Help displayed during completion (defaults to token name). */
357 /** Private data used by parser functions. */
360 * Lists of subsequent tokens to push on the stack. Each call to the
361 * parser consumes the last entry of that stack.
363 const enum index *const *next;
364 /** Arguments stack for subsequent tokens that need them. */
365 const struct arg *const *args;
367 * Token-processing callback, returns -1 in case of error, the
368 * length of the matched string otherwise. If NULL, attempts to
369 * match the token name.
371 * If buf is not NULL, the result should be stored in it according
372 * to context. An error is returned if not large enough.
374 int (*call)(struct context *ctx, const struct token *token,
375 const char *str, unsigned int len,
376 void *buf, unsigned int size);
378 * Callback that provides possible values for this token, used for
379 * completion. Returns -1 in case of error, the number of possible
380 * values otherwise. If NULL, the token name is used.
382 * If buf is not NULL, entry index ent is written to buf and the
383 * full length of the entry is returned (same behavior as
386 int (*comp)(struct context *ctx, const struct token *token,
387 unsigned int ent, char *buf, unsigned int size);
388 /** Mandatory token name, no default value. */
392 /** Static initializer for the next field. */
393 #define NEXT(...) (const enum index *const []){ __VA_ARGS__, NULL, }
395 /** Static initializer for a NEXT() entry. */
396 #define NEXT_ENTRY(...) (const enum index []){ __VA_ARGS__, ZERO, }
398 /** Static initializer for the args field. */
399 #define ARGS(...) (const struct arg *const []){ __VA_ARGS__, NULL, }
401 /** Static initializer for ARGS() to target a field. */
402 #define ARGS_ENTRY(s, f) \
403 (&(const struct arg){ \
404 .offset = offsetof(s, f), \
405 .size = sizeof(((s *)0)->f), \
408 /** Static initializer for ARGS() to target a bit-field. */
409 #define ARGS_ENTRY_BF(s, f, b) \
410 (&(const struct arg){ \
412 .mask = (const void *)&(const s){ .f = (1 << (b)) - 1 }, \
415 /** Static initializer for ARGS() to target an arbitrary bit-mask. */
416 #define ARGS_ENTRY_MASK(s, f, m) \
417 (&(const struct arg){ \
418 .offset = offsetof(s, f), \
419 .size = sizeof(((s *)0)->f), \
420 .mask = (const void *)(m), \
423 /** Same as ARGS_ENTRY_MASK() using network byte ordering for the value. */
424 #define ARGS_ENTRY_MASK_HTON(s, f, m) \
425 (&(const struct arg){ \
427 .offset = offsetof(s, f), \
428 .size = sizeof(((s *)0)->f), \
429 .mask = (const void *)(m), \
432 /** Static initializer for ARGS() to target a pointer. */
433 #define ARGS_ENTRY_PTR(s, f) \
434 (&(const struct arg){ \
435 .size = sizeof(*((s *)0)->f), \
438 /** Static initializer for ARGS() with arbitrary offset and size. */
439 #define ARGS_ENTRY_ARB(o, s) \
440 (&(const struct arg){ \
445 /** Same as ARGS_ENTRY_ARB() with bounded values. */
446 #define ARGS_ENTRY_ARB_BOUNDED(o, s, i, a) \
447 (&(const struct arg){ \
455 /** Same as ARGS_ENTRY() using network byte ordering. */
456 #define ARGS_ENTRY_HTON(s, f) \
457 (&(const struct arg){ \
459 .offset = offsetof(s, f), \
460 .size = sizeof(((s *)0)->f), \
463 /** Parser output buffer layout expected by cmd_flow_parsed(). */
465 enum index command; /**< Flow command. */
466 portid_t port; /**< Affected port ID. */
469 struct rte_flow_attr attr;
470 struct rte_flow_item *pattern;
471 struct rte_flow_action *actions;
475 } vc; /**< Validate/create arguments. */
479 } destroy; /**< Destroy arguments. */
482 struct rte_flow_action action;
483 } query; /**< Query arguments. */
487 } list; /**< List arguments. */
490 } isolate; /**< Isolated mode arguments. */
491 } args; /**< Command arguments. */
494 /** Private data for pattern items. */
495 struct parse_item_priv {
496 enum rte_flow_item_type type; /**< Item type. */
497 uint32_t size; /**< Size of item specification structure. */
500 #define PRIV_ITEM(t, s) \
501 (&(const struct parse_item_priv){ \
502 .type = RTE_FLOW_ITEM_TYPE_ ## t, \
506 /** Private data for actions. */
507 struct parse_action_priv {
508 enum rte_flow_action_type type; /**< Action type. */
509 uint32_t size; /**< Size of action configuration structure. */
512 #define PRIV_ACTION(t, s) \
513 (&(const struct parse_action_priv){ \
514 .type = RTE_FLOW_ACTION_TYPE_ ## t, \
518 static const enum index next_vc_attr[] = {
528 static const enum index next_destroy_attr[] = {
534 static const enum index next_list_attr[] = {
540 static const enum index item_param[] = {
549 static const enum index next_item[] = {
585 ITEM_ICMP6_ND_OPT_SLA_ETH,
586 ITEM_ICMP6_ND_OPT_TLA_ETH,
590 static const enum index item_fuzzy[] = {
596 static const enum index item_any[] = {
602 static const enum index item_vf[] = {
608 static const enum index item_phy_port[] = {
614 static const enum index item_port_id[] = {
620 static const enum index item_mark[] = {
626 static const enum index item_raw[] = {
636 static const enum index item_eth[] = {
644 static const enum index item_vlan[] = {
649 ITEM_VLAN_INNER_TYPE,
654 static const enum index item_ipv4[] = {
664 static const enum index item_ipv6[] = {
675 static const enum index item_icmp[] = {
682 static const enum index item_udp[] = {
689 static const enum index item_tcp[] = {
697 static const enum index item_sctp[] = {
706 static const enum index item_vxlan[] = {
712 static const enum index item_e_tag[] = {
713 ITEM_E_TAG_GRP_ECID_B,
718 static const enum index item_nvgre[] = {
724 static const enum index item_mpls[] = {
730 static const enum index item_gre[] = {
736 static const enum index item_gtp[] = {
742 static const enum index item_geneve[] = {
749 static const enum index item_vxlan_gpe[] = {
755 static const enum index item_arp_eth_ipv4[] = {
756 ITEM_ARP_ETH_IPV4_SHA,
757 ITEM_ARP_ETH_IPV4_SPA,
758 ITEM_ARP_ETH_IPV4_THA,
759 ITEM_ARP_ETH_IPV4_TPA,
764 static const enum index item_ipv6_ext[] = {
765 ITEM_IPV6_EXT_NEXT_HDR,
770 static const enum index item_icmp6[] = {
777 static const enum index item_icmp6_nd_ns[] = {
778 ITEM_ICMP6_ND_NS_TARGET_ADDR,
783 static const enum index item_icmp6_nd_na[] = {
784 ITEM_ICMP6_ND_NA_TARGET_ADDR,
789 static const enum index item_icmp6_nd_opt[] = {
790 ITEM_ICMP6_ND_OPT_TYPE,
795 static const enum index item_icmp6_nd_opt_sla_eth[] = {
796 ITEM_ICMP6_ND_OPT_SLA_ETH_SLA,
801 static const enum index item_icmp6_nd_opt_tla_eth[] = {
802 ITEM_ICMP6_ND_OPT_TLA_ETH_TLA,
807 static const enum index next_action[] = {
823 ACTION_OF_SET_MPLS_TTL,
824 ACTION_OF_DEC_MPLS_TTL,
825 ACTION_OF_SET_NW_TTL,
826 ACTION_OF_DEC_NW_TTL,
827 ACTION_OF_COPY_TTL_OUT,
828 ACTION_OF_COPY_TTL_IN,
831 ACTION_OF_SET_VLAN_VID,
832 ACTION_OF_SET_VLAN_PCP,
853 static const enum index action_mark[] = {
859 static const enum index action_queue[] = {
865 static const enum index action_count[] = {
872 static const enum index action_rss[] = {
883 static const enum index action_vf[] = {
890 static const enum index action_phy_port[] = {
891 ACTION_PHY_PORT_ORIGINAL,
892 ACTION_PHY_PORT_INDEX,
897 static const enum index action_port_id[] = {
898 ACTION_PORT_ID_ORIGINAL,
904 static const enum index action_meter[] = {
910 static const enum index action_of_set_mpls_ttl[] = {
911 ACTION_OF_SET_MPLS_TTL_MPLS_TTL,
916 static const enum index action_of_set_nw_ttl[] = {
917 ACTION_OF_SET_NW_TTL_NW_TTL,
922 static const enum index action_of_push_vlan[] = {
923 ACTION_OF_PUSH_VLAN_ETHERTYPE,
928 static const enum index action_of_set_vlan_vid[] = {
929 ACTION_OF_SET_VLAN_VID_VLAN_VID,
934 static const enum index action_of_set_vlan_pcp[] = {
935 ACTION_OF_SET_VLAN_PCP_VLAN_PCP,
940 static const enum index action_of_pop_mpls[] = {
941 ACTION_OF_POP_MPLS_ETHERTYPE,
946 static const enum index action_of_push_mpls[] = {
947 ACTION_OF_PUSH_MPLS_ETHERTYPE,
952 static const enum index action_set_ipv4_src[] = {
953 ACTION_SET_IPV4_SRC_IPV4_SRC,
958 static const enum index action_set_mac_src[] = {
959 ACTION_SET_MAC_SRC_MAC_SRC,
964 static const enum index action_set_ipv4_dst[] = {
965 ACTION_SET_IPV4_DST_IPV4_DST,
970 static const enum index action_set_ipv6_src[] = {
971 ACTION_SET_IPV6_SRC_IPV6_SRC,
976 static const enum index action_set_ipv6_dst[] = {
977 ACTION_SET_IPV6_DST_IPV6_DST,
982 static const enum index action_set_tp_src[] = {
983 ACTION_SET_TP_SRC_TP_SRC,
988 static const enum index action_set_tp_dst[] = {
989 ACTION_SET_TP_DST_TP_DST,
994 static const enum index action_set_ttl[] = {
1000 static const enum index action_jump[] = {
1006 static const enum index action_set_mac_dst[] = {
1007 ACTION_SET_MAC_DST_MAC_DST,
1012 static int parse_init(struct context *, const struct token *,
1013 const char *, unsigned int,
1014 void *, unsigned int);
1015 static int parse_vc(struct context *, const struct token *,
1016 const char *, unsigned int,
1017 void *, unsigned int);
1018 static int parse_vc_spec(struct context *, const struct token *,
1019 const char *, unsigned int, void *, unsigned int);
1020 static int parse_vc_conf(struct context *, const struct token *,
1021 const char *, unsigned int, void *, unsigned int);
1022 static int parse_vc_action_rss(struct context *, const struct token *,
1023 const char *, unsigned int, void *,
1025 static int parse_vc_action_rss_func(struct context *, const struct token *,
1026 const char *, unsigned int, void *,
1028 static int parse_vc_action_rss_type(struct context *, const struct token *,
1029 const char *, unsigned int, void *,
1031 static int parse_vc_action_rss_queue(struct context *, const struct token *,
1032 const char *, unsigned int, void *,
1034 static int parse_vc_action_vxlan_encap(struct context *, const struct token *,
1035 const char *, unsigned int, void *,
1037 static int parse_vc_action_nvgre_encap(struct context *, const struct token *,
1038 const char *, unsigned int, void *,
1040 static int parse_destroy(struct context *, const struct token *,
1041 const char *, unsigned int,
1042 void *, unsigned int);
1043 static int parse_flush(struct context *, const struct token *,
1044 const char *, unsigned int,
1045 void *, unsigned int);
1046 static int parse_query(struct context *, const struct token *,
1047 const char *, unsigned int,
1048 void *, unsigned int);
1049 static int parse_action(struct context *, const struct token *,
1050 const char *, unsigned int,
1051 void *, unsigned int);
1052 static int parse_list(struct context *, const struct token *,
1053 const char *, unsigned int,
1054 void *, unsigned int);
1055 static int parse_isolate(struct context *, const struct token *,
1056 const char *, unsigned int,
1057 void *, unsigned int);
1058 static int parse_int(struct context *, const struct token *,
1059 const char *, unsigned int,
1060 void *, unsigned int);
1061 static int parse_prefix(struct context *, const struct token *,
1062 const char *, unsigned int,
1063 void *, unsigned int);
1064 static int parse_boolean(struct context *, const struct token *,
1065 const char *, unsigned int,
1066 void *, unsigned int);
1067 static int parse_string(struct context *, const struct token *,
1068 const char *, unsigned int,
1069 void *, unsigned int);
1070 static int parse_mac_addr(struct context *, const struct token *,
1071 const char *, unsigned int,
1072 void *, unsigned int);
1073 static int parse_ipv4_addr(struct context *, const struct token *,
1074 const char *, unsigned int,
1075 void *, unsigned int);
1076 static int parse_ipv6_addr(struct context *, const struct token *,
1077 const char *, unsigned int,
1078 void *, unsigned int);
1079 static int parse_port(struct context *, const struct token *,
1080 const char *, unsigned int,
1081 void *, unsigned int);
1082 static int comp_none(struct context *, const struct token *,
1083 unsigned int, char *, unsigned int);
1084 static int comp_boolean(struct context *, const struct token *,
1085 unsigned int, char *, unsigned int);
1086 static int comp_action(struct context *, const struct token *,
1087 unsigned int, char *, unsigned int);
1088 static int comp_port(struct context *, const struct token *,
1089 unsigned int, char *, unsigned int);
1090 static int comp_rule_id(struct context *, const struct token *,
1091 unsigned int, char *, unsigned int);
1092 static int comp_vc_action_rss_type(struct context *, const struct token *,
1093 unsigned int, char *, unsigned int);
1094 static int comp_vc_action_rss_queue(struct context *, const struct token *,
1095 unsigned int, char *, unsigned int);
1097 /** Token definitions. */
1098 static const struct token token_list[] = {
1099 /* Special tokens. */
1102 .help = "null entry, abused as the entry point",
1103 .next = NEXT(NEXT_ENTRY(FLOW)),
1108 .help = "command may end here",
1110 /* Common tokens. */
1114 .help = "integer value",
1119 .name = "{unsigned}",
1121 .help = "unsigned integer value",
1128 .help = "prefix length for bit-mask",
1129 .call = parse_prefix,
1133 .name = "{boolean}",
1135 .help = "any boolean value",
1136 .call = parse_boolean,
1137 .comp = comp_boolean,
1142 .help = "fixed string",
1143 .call = parse_string,
1147 .name = "{MAC address}",
1149 .help = "standard MAC address notation",
1150 .call = parse_mac_addr,
1154 .name = "{IPv4 address}",
1155 .type = "IPV4 ADDRESS",
1156 .help = "standard IPv4 address notation",
1157 .call = parse_ipv4_addr,
1161 .name = "{IPv6 address}",
1162 .type = "IPV6 ADDRESS",
1163 .help = "standard IPv6 address notation",
1164 .call = parse_ipv6_addr,
1168 .name = "{rule id}",
1170 .help = "rule identifier",
1172 .comp = comp_rule_id,
1175 .name = "{port_id}",
1177 .help = "port identifier",
1182 .name = "{group_id}",
1184 .help = "group identifier",
1188 [PRIORITY_LEVEL] = {
1191 .help = "priority level",
1195 /* Top-level command. */
1198 .type = "{command} {port_id} [{arg} [...]]",
1199 .help = "manage ingress/egress flow rules",
1200 .next = NEXT(NEXT_ENTRY
1210 /* Sub-level commands. */
1213 .help = "check whether a flow rule can be created",
1214 .next = NEXT(next_vc_attr, NEXT_ENTRY(PORT_ID)),
1215 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1220 .help = "create a flow rule",
1221 .next = NEXT(next_vc_attr, NEXT_ENTRY(PORT_ID)),
1222 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1227 .help = "destroy specific flow rules",
1228 .next = NEXT(NEXT_ENTRY(DESTROY_RULE), NEXT_ENTRY(PORT_ID)),
1229 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1230 .call = parse_destroy,
1234 .help = "destroy all flow rules",
1235 .next = NEXT(NEXT_ENTRY(PORT_ID)),
1236 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1237 .call = parse_flush,
1241 .help = "query an existing flow rule",
1242 .next = NEXT(NEXT_ENTRY(QUERY_ACTION),
1243 NEXT_ENTRY(RULE_ID),
1244 NEXT_ENTRY(PORT_ID)),
1245 .args = ARGS(ARGS_ENTRY(struct buffer, args.query.action.type),
1246 ARGS_ENTRY(struct buffer, args.query.rule),
1247 ARGS_ENTRY(struct buffer, port)),
1248 .call = parse_query,
1252 .help = "list existing flow rules",
1253 .next = NEXT(next_list_attr, NEXT_ENTRY(PORT_ID)),
1254 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1259 .help = "restrict ingress traffic to the defined flow rules",
1260 .next = NEXT(NEXT_ENTRY(BOOLEAN),
1261 NEXT_ENTRY(PORT_ID)),
1262 .args = ARGS(ARGS_ENTRY(struct buffer, args.isolate.set),
1263 ARGS_ENTRY(struct buffer, port)),
1264 .call = parse_isolate,
1266 /* Destroy arguments. */
1269 .help = "specify a rule identifier",
1270 .next = NEXT(next_destroy_attr, NEXT_ENTRY(RULE_ID)),
1271 .args = ARGS(ARGS_ENTRY_PTR(struct buffer, args.destroy.rule)),
1272 .call = parse_destroy,
1274 /* Query arguments. */
1278 .help = "action to query, must be part of the rule",
1279 .call = parse_action,
1280 .comp = comp_action,
1282 /* List arguments. */
1285 .help = "specify a group",
1286 .next = NEXT(next_list_attr, NEXT_ENTRY(GROUP_ID)),
1287 .args = ARGS(ARGS_ENTRY_PTR(struct buffer, args.list.group)),
1290 /* Validate/create attributes. */
1293 .help = "specify a group",
1294 .next = NEXT(next_vc_attr, NEXT_ENTRY(GROUP_ID)),
1295 .args = ARGS(ARGS_ENTRY(struct rte_flow_attr, group)),
1300 .help = "specify a priority level",
1301 .next = NEXT(next_vc_attr, NEXT_ENTRY(PRIORITY_LEVEL)),
1302 .args = ARGS(ARGS_ENTRY(struct rte_flow_attr, priority)),
1307 .help = "affect rule to ingress",
1308 .next = NEXT(next_vc_attr),
1313 .help = "affect rule to egress",
1314 .next = NEXT(next_vc_attr),
1319 .help = "apply rule directly to endpoints found in pattern",
1320 .next = NEXT(next_vc_attr),
1323 /* Validate/create pattern. */
1326 .help = "submit a list of pattern items",
1327 .next = NEXT(next_item),
1332 .help = "match value perfectly (with full bit-mask)",
1333 .call = parse_vc_spec,
1335 [ITEM_PARAM_SPEC] = {
1337 .help = "match value according to configured bit-mask",
1338 .call = parse_vc_spec,
1340 [ITEM_PARAM_LAST] = {
1342 .help = "specify upper bound to establish a range",
1343 .call = parse_vc_spec,
1345 [ITEM_PARAM_MASK] = {
1347 .help = "specify bit-mask with relevant bits set to one",
1348 .call = parse_vc_spec,
1350 [ITEM_PARAM_PREFIX] = {
1352 .help = "generate bit-mask from a prefix length",
1353 .call = parse_vc_spec,
1357 .help = "specify next pattern item",
1358 .next = NEXT(next_item),
1362 .help = "end list of pattern items",
1363 .priv = PRIV_ITEM(END, 0),
1364 .next = NEXT(NEXT_ENTRY(ACTIONS)),
1369 .help = "no-op pattern item",
1370 .priv = PRIV_ITEM(VOID, 0),
1371 .next = NEXT(NEXT_ENTRY(ITEM_NEXT)),
1376 .help = "perform actions when pattern does not match",
1377 .priv = PRIV_ITEM(INVERT, 0),
1378 .next = NEXT(NEXT_ENTRY(ITEM_NEXT)),
1383 .help = "match any protocol for the current layer",
1384 .priv = PRIV_ITEM(ANY, sizeof(struct rte_flow_item_any)),
1385 .next = NEXT(item_any),
1390 .help = "number of layers covered",
1391 .next = NEXT(item_any, NEXT_ENTRY(UNSIGNED), item_param),
1392 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_any, num)),
1396 .help = "match traffic from/to the physical function",
1397 .priv = PRIV_ITEM(PF, 0),
1398 .next = NEXT(NEXT_ENTRY(ITEM_NEXT)),
1403 .help = "match traffic from/to a virtual function ID",
1404 .priv = PRIV_ITEM(VF, sizeof(struct rte_flow_item_vf)),
1405 .next = NEXT(item_vf),
1411 .next = NEXT(item_vf, NEXT_ENTRY(UNSIGNED), item_param),
1412 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_vf, id)),
1416 .help = "match traffic from/to a specific physical port",
1417 .priv = PRIV_ITEM(PHY_PORT,
1418 sizeof(struct rte_flow_item_phy_port)),
1419 .next = NEXT(item_phy_port),
1422 [ITEM_PHY_PORT_INDEX] = {
1424 .help = "physical port index",
1425 .next = NEXT(item_phy_port, NEXT_ENTRY(UNSIGNED), item_param),
1426 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_phy_port, index)),
1430 .help = "match traffic from/to a given DPDK port ID",
1431 .priv = PRIV_ITEM(PORT_ID,
1432 sizeof(struct rte_flow_item_port_id)),
1433 .next = NEXT(item_port_id),
1436 [ITEM_PORT_ID_ID] = {
1438 .help = "DPDK port ID",
1439 .next = NEXT(item_port_id, NEXT_ENTRY(UNSIGNED), item_param),
1440 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_port_id, id)),
1444 .help = "match traffic against value set in previously matched rule",
1445 .priv = PRIV_ITEM(MARK, sizeof(struct rte_flow_item_mark)),
1446 .next = NEXT(item_mark),
1451 .help = "Integer value to match against",
1452 .next = NEXT(item_mark, NEXT_ENTRY(UNSIGNED), item_param),
1453 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_mark, id)),
1457 .help = "match an arbitrary byte string",
1458 .priv = PRIV_ITEM(RAW, ITEM_RAW_SIZE),
1459 .next = NEXT(item_raw),
1462 [ITEM_RAW_RELATIVE] = {
1464 .help = "look for pattern after the previous item",
1465 .next = NEXT(item_raw, NEXT_ENTRY(BOOLEAN), item_param),
1466 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_item_raw,
1469 [ITEM_RAW_SEARCH] = {
1471 .help = "search pattern from offset (see also limit)",
1472 .next = NEXT(item_raw, NEXT_ENTRY(BOOLEAN), item_param),
1473 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_item_raw,
1476 [ITEM_RAW_OFFSET] = {
1478 .help = "absolute or relative offset for pattern",
1479 .next = NEXT(item_raw, NEXT_ENTRY(INTEGER), item_param),
1480 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_raw, offset)),
1482 [ITEM_RAW_LIMIT] = {
1484 .help = "search area limit for start of pattern",
1485 .next = NEXT(item_raw, NEXT_ENTRY(UNSIGNED), item_param),
1486 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_raw, limit)),
1488 [ITEM_RAW_PATTERN] = {
1490 .help = "byte string to look for",
1491 .next = NEXT(item_raw,
1493 NEXT_ENTRY(ITEM_PARAM_IS,
1496 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_raw, pattern),
1497 ARGS_ENTRY(struct rte_flow_item_raw, length),
1498 ARGS_ENTRY_ARB(sizeof(struct rte_flow_item_raw),
1499 ITEM_RAW_PATTERN_SIZE)),
1503 .help = "match Ethernet header",
1504 .priv = PRIV_ITEM(ETH, sizeof(struct rte_flow_item_eth)),
1505 .next = NEXT(item_eth),
1510 .help = "destination MAC",
1511 .next = NEXT(item_eth, NEXT_ENTRY(MAC_ADDR), item_param),
1512 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_eth, dst)),
1516 .help = "source MAC",
1517 .next = NEXT(item_eth, NEXT_ENTRY(MAC_ADDR), item_param),
1518 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_eth, src)),
1522 .help = "EtherType",
1523 .next = NEXT(item_eth, NEXT_ENTRY(UNSIGNED), item_param),
1524 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_eth, type)),
1528 .help = "match 802.1Q/ad VLAN tag",
1529 .priv = PRIV_ITEM(VLAN, sizeof(struct rte_flow_item_vlan)),
1530 .next = NEXT(item_vlan),
1535 .help = "tag control information",
1536 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1537 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vlan, tci)),
1541 .help = "priority code point",
1542 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1543 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_vlan,
1548 .help = "drop eligible indicator",
1549 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1550 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_vlan,
1555 .help = "VLAN identifier",
1556 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1557 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_vlan,
1560 [ITEM_VLAN_INNER_TYPE] = {
1561 .name = "inner_type",
1562 .help = "inner EtherType",
1563 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1564 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vlan,
1569 .help = "match IPv4 header",
1570 .priv = PRIV_ITEM(IPV4, sizeof(struct rte_flow_item_ipv4)),
1571 .next = NEXT(item_ipv4),
1576 .help = "type of service",
1577 .next = NEXT(item_ipv4, NEXT_ENTRY(UNSIGNED), item_param),
1578 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
1579 hdr.type_of_service)),
1583 .help = "time to live",
1584 .next = NEXT(item_ipv4, NEXT_ENTRY(UNSIGNED), item_param),
1585 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
1588 [ITEM_IPV4_PROTO] = {
1590 .help = "next protocol ID",
1591 .next = NEXT(item_ipv4, NEXT_ENTRY(UNSIGNED), item_param),
1592 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
1593 hdr.next_proto_id)),
1597 .help = "source address",
1598 .next = NEXT(item_ipv4, NEXT_ENTRY(IPV4_ADDR), item_param),
1599 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
1604 .help = "destination address",
1605 .next = NEXT(item_ipv4, NEXT_ENTRY(IPV4_ADDR), item_param),
1606 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
1611 .help = "match IPv6 header",
1612 .priv = PRIV_ITEM(IPV6, sizeof(struct rte_flow_item_ipv6)),
1613 .next = NEXT(item_ipv6),
1618 .help = "traffic class",
1619 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
1620 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_ipv6,
1622 "\x0f\xf0\x00\x00")),
1624 [ITEM_IPV6_FLOW] = {
1626 .help = "flow label",
1627 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
1628 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_ipv6,
1630 "\x00\x0f\xff\xff")),
1632 [ITEM_IPV6_PROTO] = {
1634 .help = "protocol (next header)",
1635 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
1636 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
1641 .help = "hop limit",
1642 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
1643 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
1648 .help = "source address",
1649 .next = NEXT(item_ipv6, NEXT_ENTRY(IPV6_ADDR), item_param),
1650 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
1655 .help = "destination address",
1656 .next = NEXT(item_ipv6, NEXT_ENTRY(IPV6_ADDR), item_param),
1657 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
1662 .help = "match ICMP header",
1663 .priv = PRIV_ITEM(ICMP, sizeof(struct rte_flow_item_icmp)),
1664 .next = NEXT(item_icmp),
1667 [ITEM_ICMP_TYPE] = {
1669 .help = "ICMP packet type",
1670 .next = NEXT(item_icmp, NEXT_ENTRY(UNSIGNED), item_param),
1671 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp,
1674 [ITEM_ICMP_CODE] = {
1676 .help = "ICMP packet code",
1677 .next = NEXT(item_icmp, NEXT_ENTRY(UNSIGNED), item_param),
1678 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp,
1683 .help = "match UDP header",
1684 .priv = PRIV_ITEM(UDP, sizeof(struct rte_flow_item_udp)),
1685 .next = NEXT(item_udp),
1690 .help = "UDP source port",
1691 .next = NEXT(item_udp, NEXT_ENTRY(UNSIGNED), item_param),
1692 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_udp,
1697 .help = "UDP destination port",
1698 .next = NEXT(item_udp, NEXT_ENTRY(UNSIGNED), item_param),
1699 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_udp,
1704 .help = "match TCP header",
1705 .priv = PRIV_ITEM(TCP, sizeof(struct rte_flow_item_tcp)),
1706 .next = NEXT(item_tcp),
1711 .help = "TCP source port",
1712 .next = NEXT(item_tcp, NEXT_ENTRY(UNSIGNED), item_param),
1713 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_tcp,
1718 .help = "TCP destination port",
1719 .next = NEXT(item_tcp, NEXT_ENTRY(UNSIGNED), item_param),
1720 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_tcp,
1723 [ITEM_TCP_FLAGS] = {
1725 .help = "TCP flags",
1726 .next = NEXT(item_tcp, NEXT_ENTRY(UNSIGNED), item_param),
1727 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_tcp,
1732 .help = "match SCTP header",
1733 .priv = PRIV_ITEM(SCTP, sizeof(struct rte_flow_item_sctp)),
1734 .next = NEXT(item_sctp),
1739 .help = "SCTP source port",
1740 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
1741 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
1746 .help = "SCTP destination port",
1747 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
1748 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
1753 .help = "validation tag",
1754 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
1755 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
1758 [ITEM_SCTP_CKSUM] = {
1761 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
1762 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
1767 .help = "match VXLAN header",
1768 .priv = PRIV_ITEM(VXLAN, sizeof(struct rte_flow_item_vxlan)),
1769 .next = NEXT(item_vxlan),
1772 [ITEM_VXLAN_VNI] = {
1774 .help = "VXLAN identifier",
1775 .next = NEXT(item_vxlan, NEXT_ENTRY(UNSIGNED), item_param),
1776 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vxlan, vni)),
1780 .help = "match E-Tag header",
1781 .priv = PRIV_ITEM(E_TAG, sizeof(struct rte_flow_item_e_tag)),
1782 .next = NEXT(item_e_tag),
1785 [ITEM_E_TAG_GRP_ECID_B] = {
1786 .name = "grp_ecid_b",
1787 .help = "GRP and E-CID base",
1788 .next = NEXT(item_e_tag, NEXT_ENTRY(UNSIGNED), item_param),
1789 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_e_tag,
1795 .help = "match NVGRE header",
1796 .priv = PRIV_ITEM(NVGRE, sizeof(struct rte_flow_item_nvgre)),
1797 .next = NEXT(item_nvgre),
1800 [ITEM_NVGRE_TNI] = {
1802 .help = "virtual subnet ID",
1803 .next = NEXT(item_nvgre, NEXT_ENTRY(UNSIGNED), item_param),
1804 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_nvgre, tni)),
1808 .help = "match MPLS header",
1809 .priv = PRIV_ITEM(MPLS, sizeof(struct rte_flow_item_mpls)),
1810 .next = NEXT(item_mpls),
1813 [ITEM_MPLS_LABEL] = {
1815 .help = "MPLS label",
1816 .next = NEXT(item_mpls, NEXT_ENTRY(UNSIGNED), item_param),
1817 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_mpls,
1823 .help = "match GRE header",
1824 .priv = PRIV_ITEM(GRE, sizeof(struct rte_flow_item_gre)),
1825 .next = NEXT(item_gre),
1828 [ITEM_GRE_PROTO] = {
1830 .help = "GRE protocol type",
1831 .next = NEXT(item_gre, NEXT_ENTRY(UNSIGNED), item_param),
1832 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gre,
1837 .help = "fuzzy pattern match, expect faster than default",
1838 .priv = PRIV_ITEM(FUZZY,
1839 sizeof(struct rte_flow_item_fuzzy)),
1840 .next = NEXT(item_fuzzy),
1843 [ITEM_FUZZY_THRESH] = {
1845 .help = "match accuracy threshold",
1846 .next = NEXT(item_fuzzy, NEXT_ENTRY(UNSIGNED), item_param),
1847 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_fuzzy,
1852 .help = "match GTP header",
1853 .priv = PRIV_ITEM(GTP, sizeof(struct rte_flow_item_gtp)),
1854 .next = NEXT(item_gtp),
1859 .help = "tunnel endpoint identifier",
1860 .next = NEXT(item_gtp, NEXT_ENTRY(UNSIGNED), item_param),
1861 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gtp, teid)),
1865 .help = "match GTP header",
1866 .priv = PRIV_ITEM(GTPC, sizeof(struct rte_flow_item_gtp)),
1867 .next = NEXT(item_gtp),
1872 .help = "match GTP header",
1873 .priv = PRIV_ITEM(GTPU, sizeof(struct rte_flow_item_gtp)),
1874 .next = NEXT(item_gtp),
1879 .help = "match GENEVE header",
1880 .priv = PRIV_ITEM(GENEVE, sizeof(struct rte_flow_item_geneve)),
1881 .next = NEXT(item_geneve),
1884 [ITEM_GENEVE_VNI] = {
1886 .help = "virtual network identifier",
1887 .next = NEXT(item_geneve, NEXT_ENTRY(UNSIGNED), item_param),
1888 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_geneve, vni)),
1890 [ITEM_GENEVE_PROTO] = {
1892 .help = "GENEVE protocol type",
1893 .next = NEXT(item_geneve, NEXT_ENTRY(UNSIGNED), item_param),
1894 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_geneve,
1897 [ITEM_VXLAN_GPE] = {
1898 .name = "vxlan-gpe",
1899 .help = "match VXLAN-GPE header",
1900 .priv = PRIV_ITEM(VXLAN_GPE,
1901 sizeof(struct rte_flow_item_vxlan_gpe)),
1902 .next = NEXT(item_vxlan_gpe),
1905 [ITEM_VXLAN_GPE_VNI] = {
1907 .help = "VXLAN-GPE identifier",
1908 .next = NEXT(item_vxlan_gpe, NEXT_ENTRY(UNSIGNED), item_param),
1909 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vxlan_gpe,
1912 [ITEM_ARP_ETH_IPV4] = {
1913 .name = "arp_eth_ipv4",
1914 .help = "match ARP header for Ethernet/IPv4",
1915 .priv = PRIV_ITEM(ARP_ETH_IPV4,
1916 sizeof(struct rte_flow_item_arp_eth_ipv4)),
1917 .next = NEXT(item_arp_eth_ipv4),
1920 [ITEM_ARP_ETH_IPV4_SHA] = {
1922 .help = "sender hardware address",
1923 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(MAC_ADDR),
1925 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
1928 [ITEM_ARP_ETH_IPV4_SPA] = {
1930 .help = "sender IPv4 address",
1931 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(IPV4_ADDR),
1933 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
1936 [ITEM_ARP_ETH_IPV4_THA] = {
1938 .help = "target hardware address",
1939 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(MAC_ADDR),
1941 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
1944 [ITEM_ARP_ETH_IPV4_TPA] = {
1946 .help = "target IPv4 address",
1947 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(IPV4_ADDR),
1949 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
1954 .help = "match presence of any IPv6 extension header",
1955 .priv = PRIV_ITEM(IPV6_EXT,
1956 sizeof(struct rte_flow_item_ipv6_ext)),
1957 .next = NEXT(item_ipv6_ext),
1960 [ITEM_IPV6_EXT_NEXT_HDR] = {
1962 .help = "next header",
1963 .next = NEXT(item_ipv6_ext, NEXT_ENTRY(UNSIGNED), item_param),
1964 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6_ext,
1969 .help = "match any ICMPv6 header",
1970 .priv = PRIV_ITEM(ICMP6, sizeof(struct rte_flow_item_icmp6)),
1971 .next = NEXT(item_icmp6),
1974 [ITEM_ICMP6_TYPE] = {
1976 .help = "ICMPv6 type",
1977 .next = NEXT(item_icmp6, NEXT_ENTRY(UNSIGNED), item_param),
1978 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6,
1981 [ITEM_ICMP6_CODE] = {
1983 .help = "ICMPv6 code",
1984 .next = NEXT(item_icmp6, NEXT_ENTRY(UNSIGNED), item_param),
1985 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6,
1988 [ITEM_ICMP6_ND_NS] = {
1989 .name = "icmp6_nd_ns",
1990 .help = "match ICMPv6 neighbor discovery solicitation",
1991 .priv = PRIV_ITEM(ICMP6_ND_NS,
1992 sizeof(struct rte_flow_item_icmp6_nd_ns)),
1993 .next = NEXT(item_icmp6_nd_ns),
1996 [ITEM_ICMP6_ND_NS_TARGET_ADDR] = {
1997 .name = "target_addr",
1998 .help = "target address",
1999 .next = NEXT(item_icmp6_nd_ns, NEXT_ENTRY(IPV6_ADDR),
2001 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6_nd_ns,
2004 [ITEM_ICMP6_ND_NA] = {
2005 .name = "icmp6_nd_na",
2006 .help = "match ICMPv6 neighbor discovery advertisement",
2007 .priv = PRIV_ITEM(ICMP6_ND_NA,
2008 sizeof(struct rte_flow_item_icmp6_nd_na)),
2009 .next = NEXT(item_icmp6_nd_na),
2012 [ITEM_ICMP6_ND_NA_TARGET_ADDR] = {
2013 .name = "target_addr",
2014 .help = "target address",
2015 .next = NEXT(item_icmp6_nd_na, NEXT_ENTRY(IPV6_ADDR),
2017 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6_nd_na,
2020 [ITEM_ICMP6_ND_OPT] = {
2021 .name = "icmp6_nd_opt",
2022 .help = "match presence of any ICMPv6 neighbor discovery"
2024 .priv = PRIV_ITEM(ICMP6_ND_OPT,
2025 sizeof(struct rte_flow_item_icmp6_nd_opt)),
2026 .next = NEXT(item_icmp6_nd_opt),
2029 [ITEM_ICMP6_ND_OPT_TYPE] = {
2031 .help = "ND option type",
2032 .next = NEXT(item_icmp6_nd_opt, NEXT_ENTRY(UNSIGNED),
2034 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6_nd_opt,
2037 [ITEM_ICMP6_ND_OPT_SLA_ETH] = {
2038 .name = "icmp6_nd_opt_sla_eth",
2039 .help = "match ICMPv6 neighbor discovery source Ethernet"
2040 " link-layer address option",
2042 (ICMP6_ND_OPT_SLA_ETH,
2043 sizeof(struct rte_flow_item_icmp6_nd_opt_sla_eth)),
2044 .next = NEXT(item_icmp6_nd_opt_sla_eth),
2047 [ITEM_ICMP6_ND_OPT_SLA_ETH_SLA] = {
2049 .help = "source Ethernet LLA",
2050 .next = NEXT(item_icmp6_nd_opt_sla_eth, NEXT_ENTRY(MAC_ADDR),
2052 .args = ARGS(ARGS_ENTRY_HTON
2053 (struct rte_flow_item_icmp6_nd_opt_sla_eth, sla)),
2055 [ITEM_ICMP6_ND_OPT_TLA_ETH] = {
2056 .name = "icmp6_nd_opt_tla_eth",
2057 .help = "match ICMPv6 neighbor discovery target Ethernet"
2058 " link-layer address option",
2060 (ICMP6_ND_OPT_TLA_ETH,
2061 sizeof(struct rte_flow_item_icmp6_nd_opt_tla_eth)),
2062 .next = NEXT(item_icmp6_nd_opt_tla_eth),
2065 [ITEM_ICMP6_ND_OPT_TLA_ETH_TLA] = {
2067 .help = "target Ethernet LLA",
2068 .next = NEXT(item_icmp6_nd_opt_tla_eth, NEXT_ENTRY(MAC_ADDR),
2070 .args = ARGS(ARGS_ENTRY_HTON
2071 (struct rte_flow_item_icmp6_nd_opt_tla_eth, tla)),
2074 /* Validate/create actions. */
2077 .help = "submit a list of associated actions",
2078 .next = NEXT(next_action),
2083 .help = "specify next action",
2084 .next = NEXT(next_action),
2088 .help = "end list of actions",
2089 .priv = PRIV_ACTION(END, 0),
2094 .help = "no-op action",
2095 .priv = PRIV_ACTION(VOID, 0),
2096 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2099 [ACTION_PASSTHRU] = {
2101 .help = "let subsequent rule process matched packets",
2102 .priv = PRIV_ACTION(PASSTHRU, 0),
2103 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2108 .help = "redirect traffic to a given group",
2109 .priv = PRIV_ACTION(JUMP, sizeof(struct rte_flow_action_jump)),
2110 .next = NEXT(action_jump),
2113 [ACTION_JUMP_GROUP] = {
2115 .help = "group to redirect traffic to",
2116 .next = NEXT(action_jump, NEXT_ENTRY(UNSIGNED)),
2117 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_jump, group)),
2118 .call = parse_vc_conf,
2122 .help = "attach 32 bit value to packets",
2123 .priv = PRIV_ACTION(MARK, sizeof(struct rte_flow_action_mark)),
2124 .next = NEXT(action_mark),
2127 [ACTION_MARK_ID] = {
2129 .help = "32 bit value to return with packets",
2130 .next = NEXT(action_mark, NEXT_ENTRY(UNSIGNED)),
2131 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_mark, id)),
2132 .call = parse_vc_conf,
2136 .help = "flag packets",
2137 .priv = PRIV_ACTION(FLAG, 0),
2138 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2143 .help = "assign packets to a given queue index",
2144 .priv = PRIV_ACTION(QUEUE,
2145 sizeof(struct rte_flow_action_queue)),
2146 .next = NEXT(action_queue),
2149 [ACTION_QUEUE_INDEX] = {
2151 .help = "queue index to use",
2152 .next = NEXT(action_queue, NEXT_ENTRY(UNSIGNED)),
2153 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_queue, index)),
2154 .call = parse_vc_conf,
2158 .help = "drop packets (note: passthru has priority)",
2159 .priv = PRIV_ACTION(DROP, 0),
2160 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2165 .help = "enable counters for this rule",
2166 .priv = PRIV_ACTION(COUNT,
2167 sizeof(struct rte_flow_action_count)),
2168 .next = NEXT(action_count),
2171 [ACTION_COUNT_ID] = {
2172 .name = "identifier",
2173 .help = "counter identifier to use",
2174 .next = NEXT(action_count, NEXT_ENTRY(UNSIGNED)),
2175 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_count, id)),
2176 .call = parse_vc_conf,
2178 [ACTION_COUNT_SHARED] = {
2180 .help = "shared counter",
2181 .next = NEXT(action_count, NEXT_ENTRY(BOOLEAN)),
2182 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_count,
2184 .call = parse_vc_conf,
2188 .help = "spread packets among several queues",
2189 .priv = PRIV_ACTION(RSS, sizeof(struct action_rss_data)),
2190 .next = NEXT(action_rss),
2191 .call = parse_vc_action_rss,
2193 [ACTION_RSS_FUNC] = {
2195 .help = "RSS hash function to apply",
2196 .next = NEXT(action_rss,
2197 NEXT_ENTRY(ACTION_RSS_FUNC_DEFAULT,
2198 ACTION_RSS_FUNC_TOEPLITZ,
2199 ACTION_RSS_FUNC_SIMPLE_XOR)),
2201 [ACTION_RSS_FUNC_DEFAULT] = {
2203 .help = "default hash function",
2204 .call = parse_vc_action_rss_func,
2206 [ACTION_RSS_FUNC_TOEPLITZ] = {
2208 .help = "Toeplitz hash function",
2209 .call = parse_vc_action_rss_func,
2211 [ACTION_RSS_FUNC_SIMPLE_XOR] = {
2212 .name = "simple_xor",
2213 .help = "simple XOR hash function",
2214 .call = parse_vc_action_rss_func,
2216 [ACTION_RSS_LEVEL] = {
2218 .help = "encapsulation level for \"types\"",
2219 .next = NEXT(action_rss, NEXT_ENTRY(UNSIGNED)),
2220 .args = ARGS(ARGS_ENTRY_ARB
2221 (offsetof(struct action_rss_data, conf) +
2222 offsetof(struct rte_flow_action_rss, level),
2223 sizeof(((struct rte_flow_action_rss *)0)->
2226 [ACTION_RSS_TYPES] = {
2228 .help = "specific RSS hash types",
2229 .next = NEXT(action_rss, NEXT_ENTRY(ACTION_RSS_TYPE)),
2231 [ACTION_RSS_TYPE] = {
2233 .help = "RSS hash type",
2234 .call = parse_vc_action_rss_type,
2235 .comp = comp_vc_action_rss_type,
2237 [ACTION_RSS_KEY] = {
2239 .help = "RSS hash key",
2240 .next = NEXT(action_rss, NEXT_ENTRY(STRING)),
2241 .args = ARGS(ARGS_ENTRY_ARB(0, 0),
2243 (offsetof(struct action_rss_data, conf) +
2244 offsetof(struct rte_flow_action_rss, key_len),
2245 sizeof(((struct rte_flow_action_rss *)0)->
2247 ARGS_ENTRY(struct action_rss_data, key)),
2249 [ACTION_RSS_KEY_LEN] = {
2251 .help = "RSS hash key length in bytes",
2252 .next = NEXT(action_rss, NEXT_ENTRY(UNSIGNED)),
2253 .args = ARGS(ARGS_ENTRY_ARB_BOUNDED
2254 (offsetof(struct action_rss_data, conf) +
2255 offsetof(struct rte_flow_action_rss, key_len),
2256 sizeof(((struct rte_flow_action_rss *)0)->
2259 RSS_HASH_KEY_LENGTH)),
2261 [ACTION_RSS_QUEUES] = {
2263 .help = "queue indices to use",
2264 .next = NEXT(action_rss, NEXT_ENTRY(ACTION_RSS_QUEUE)),
2265 .call = parse_vc_conf,
2267 [ACTION_RSS_QUEUE] = {
2269 .help = "queue index",
2270 .call = parse_vc_action_rss_queue,
2271 .comp = comp_vc_action_rss_queue,
2275 .help = "direct traffic to physical function",
2276 .priv = PRIV_ACTION(PF, 0),
2277 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2282 .help = "direct traffic to a virtual function ID",
2283 .priv = PRIV_ACTION(VF, sizeof(struct rte_flow_action_vf)),
2284 .next = NEXT(action_vf),
2287 [ACTION_VF_ORIGINAL] = {
2289 .help = "use original VF ID if possible",
2290 .next = NEXT(action_vf, NEXT_ENTRY(BOOLEAN)),
2291 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_vf,
2293 .call = parse_vc_conf,
2298 .next = NEXT(action_vf, NEXT_ENTRY(UNSIGNED)),
2299 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_vf, id)),
2300 .call = parse_vc_conf,
2302 [ACTION_PHY_PORT] = {
2304 .help = "direct packets to physical port index",
2305 .priv = PRIV_ACTION(PHY_PORT,
2306 sizeof(struct rte_flow_action_phy_port)),
2307 .next = NEXT(action_phy_port),
2310 [ACTION_PHY_PORT_ORIGINAL] = {
2312 .help = "use original port index if possible",
2313 .next = NEXT(action_phy_port, NEXT_ENTRY(BOOLEAN)),
2314 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_phy_port,
2316 .call = parse_vc_conf,
2318 [ACTION_PHY_PORT_INDEX] = {
2320 .help = "physical port index",
2321 .next = NEXT(action_phy_port, NEXT_ENTRY(UNSIGNED)),
2322 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_phy_port,
2324 .call = parse_vc_conf,
2326 [ACTION_PORT_ID] = {
2328 .help = "direct matching traffic to a given DPDK port ID",
2329 .priv = PRIV_ACTION(PORT_ID,
2330 sizeof(struct rte_flow_action_port_id)),
2331 .next = NEXT(action_port_id),
2334 [ACTION_PORT_ID_ORIGINAL] = {
2336 .help = "use original DPDK port ID if possible",
2337 .next = NEXT(action_port_id, NEXT_ENTRY(BOOLEAN)),
2338 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_port_id,
2340 .call = parse_vc_conf,
2342 [ACTION_PORT_ID_ID] = {
2344 .help = "DPDK port ID",
2345 .next = NEXT(action_port_id, NEXT_ENTRY(UNSIGNED)),
2346 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_port_id, id)),
2347 .call = parse_vc_conf,
2351 .help = "meter the directed packets at given id",
2352 .priv = PRIV_ACTION(METER,
2353 sizeof(struct rte_flow_action_meter)),
2354 .next = NEXT(action_meter),
2357 [ACTION_METER_ID] = {
2359 .help = "meter id to use",
2360 .next = NEXT(action_meter, NEXT_ENTRY(UNSIGNED)),
2361 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_meter, mtr_id)),
2362 .call = parse_vc_conf,
2364 [ACTION_OF_SET_MPLS_TTL] = {
2365 .name = "of_set_mpls_ttl",
2366 .help = "OpenFlow's OFPAT_SET_MPLS_TTL",
2369 sizeof(struct rte_flow_action_of_set_mpls_ttl)),
2370 .next = NEXT(action_of_set_mpls_ttl),
2373 [ACTION_OF_SET_MPLS_TTL_MPLS_TTL] = {
2376 .next = NEXT(action_of_set_mpls_ttl, NEXT_ENTRY(UNSIGNED)),
2377 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_of_set_mpls_ttl,
2379 .call = parse_vc_conf,
2381 [ACTION_OF_DEC_MPLS_TTL] = {
2382 .name = "of_dec_mpls_ttl",
2383 .help = "OpenFlow's OFPAT_DEC_MPLS_TTL",
2384 .priv = PRIV_ACTION(OF_DEC_MPLS_TTL, 0),
2385 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2388 [ACTION_OF_SET_NW_TTL] = {
2389 .name = "of_set_nw_ttl",
2390 .help = "OpenFlow's OFPAT_SET_NW_TTL",
2393 sizeof(struct rte_flow_action_of_set_nw_ttl)),
2394 .next = NEXT(action_of_set_nw_ttl),
2397 [ACTION_OF_SET_NW_TTL_NW_TTL] = {
2400 .next = NEXT(action_of_set_nw_ttl, NEXT_ENTRY(UNSIGNED)),
2401 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_of_set_nw_ttl,
2403 .call = parse_vc_conf,
2405 [ACTION_OF_DEC_NW_TTL] = {
2406 .name = "of_dec_nw_ttl",
2407 .help = "OpenFlow's OFPAT_DEC_NW_TTL",
2408 .priv = PRIV_ACTION(OF_DEC_NW_TTL, 0),
2409 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2412 [ACTION_OF_COPY_TTL_OUT] = {
2413 .name = "of_copy_ttl_out",
2414 .help = "OpenFlow's OFPAT_COPY_TTL_OUT",
2415 .priv = PRIV_ACTION(OF_COPY_TTL_OUT, 0),
2416 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2419 [ACTION_OF_COPY_TTL_IN] = {
2420 .name = "of_copy_ttl_in",
2421 .help = "OpenFlow's OFPAT_COPY_TTL_IN",
2422 .priv = PRIV_ACTION(OF_COPY_TTL_IN, 0),
2423 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2426 [ACTION_OF_POP_VLAN] = {
2427 .name = "of_pop_vlan",
2428 .help = "OpenFlow's OFPAT_POP_VLAN",
2429 .priv = PRIV_ACTION(OF_POP_VLAN, 0),
2430 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2433 [ACTION_OF_PUSH_VLAN] = {
2434 .name = "of_push_vlan",
2435 .help = "OpenFlow's OFPAT_PUSH_VLAN",
2438 sizeof(struct rte_flow_action_of_push_vlan)),
2439 .next = NEXT(action_of_push_vlan),
2442 [ACTION_OF_PUSH_VLAN_ETHERTYPE] = {
2443 .name = "ethertype",
2444 .help = "EtherType",
2445 .next = NEXT(action_of_push_vlan, NEXT_ENTRY(UNSIGNED)),
2446 .args = ARGS(ARGS_ENTRY_HTON
2447 (struct rte_flow_action_of_push_vlan,
2449 .call = parse_vc_conf,
2451 [ACTION_OF_SET_VLAN_VID] = {
2452 .name = "of_set_vlan_vid",
2453 .help = "OpenFlow's OFPAT_SET_VLAN_VID",
2456 sizeof(struct rte_flow_action_of_set_vlan_vid)),
2457 .next = NEXT(action_of_set_vlan_vid),
2460 [ACTION_OF_SET_VLAN_VID_VLAN_VID] = {
2463 .next = NEXT(action_of_set_vlan_vid, NEXT_ENTRY(UNSIGNED)),
2464 .args = ARGS(ARGS_ENTRY_HTON
2465 (struct rte_flow_action_of_set_vlan_vid,
2467 .call = parse_vc_conf,
2469 [ACTION_OF_SET_VLAN_PCP] = {
2470 .name = "of_set_vlan_pcp",
2471 .help = "OpenFlow's OFPAT_SET_VLAN_PCP",
2474 sizeof(struct rte_flow_action_of_set_vlan_pcp)),
2475 .next = NEXT(action_of_set_vlan_pcp),
2478 [ACTION_OF_SET_VLAN_PCP_VLAN_PCP] = {
2480 .help = "VLAN priority",
2481 .next = NEXT(action_of_set_vlan_pcp, NEXT_ENTRY(UNSIGNED)),
2482 .args = ARGS(ARGS_ENTRY_HTON
2483 (struct rte_flow_action_of_set_vlan_pcp,
2485 .call = parse_vc_conf,
2487 [ACTION_OF_POP_MPLS] = {
2488 .name = "of_pop_mpls",
2489 .help = "OpenFlow's OFPAT_POP_MPLS",
2490 .priv = PRIV_ACTION(OF_POP_MPLS,
2491 sizeof(struct rte_flow_action_of_pop_mpls)),
2492 .next = NEXT(action_of_pop_mpls),
2495 [ACTION_OF_POP_MPLS_ETHERTYPE] = {
2496 .name = "ethertype",
2497 .help = "EtherType",
2498 .next = NEXT(action_of_pop_mpls, NEXT_ENTRY(UNSIGNED)),
2499 .args = ARGS(ARGS_ENTRY_HTON
2500 (struct rte_flow_action_of_pop_mpls,
2502 .call = parse_vc_conf,
2504 [ACTION_OF_PUSH_MPLS] = {
2505 .name = "of_push_mpls",
2506 .help = "OpenFlow's OFPAT_PUSH_MPLS",
2509 sizeof(struct rte_flow_action_of_push_mpls)),
2510 .next = NEXT(action_of_push_mpls),
2513 [ACTION_OF_PUSH_MPLS_ETHERTYPE] = {
2514 .name = "ethertype",
2515 .help = "EtherType",
2516 .next = NEXT(action_of_push_mpls, NEXT_ENTRY(UNSIGNED)),
2517 .args = ARGS(ARGS_ENTRY_HTON
2518 (struct rte_flow_action_of_push_mpls,
2520 .call = parse_vc_conf,
2522 [ACTION_VXLAN_ENCAP] = {
2523 .name = "vxlan_encap",
2524 .help = "VXLAN encapsulation, uses configuration set by \"set"
2526 .priv = PRIV_ACTION(VXLAN_ENCAP,
2527 sizeof(struct action_vxlan_encap_data)),
2528 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2529 .call = parse_vc_action_vxlan_encap,
2531 [ACTION_VXLAN_DECAP] = {
2532 .name = "vxlan_decap",
2533 .help = "Performs a decapsulation action by stripping all"
2534 " headers of the VXLAN tunnel network overlay from the"
2536 .priv = PRIV_ACTION(VXLAN_DECAP, 0),
2537 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2540 [ACTION_NVGRE_ENCAP] = {
2541 .name = "nvgre_encap",
2542 .help = "NVGRE encapsulation, uses configuration set by \"set"
2544 .priv = PRIV_ACTION(NVGRE_ENCAP,
2545 sizeof(struct action_nvgre_encap_data)),
2546 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2547 .call = parse_vc_action_nvgre_encap,
2549 [ACTION_NVGRE_DECAP] = {
2550 .name = "nvgre_decap",
2551 .help = "Performs a decapsulation action by stripping all"
2552 " headers of the NVGRE tunnel network overlay from the"
2554 .priv = PRIV_ACTION(NVGRE_DECAP, 0),
2555 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2558 [ACTION_SET_IPV4_SRC] = {
2559 .name = "set_ipv4_src",
2560 .help = "Set a new IPv4 source address in the outermost"
2562 .priv = PRIV_ACTION(SET_IPV4_SRC,
2563 sizeof(struct rte_flow_action_set_ipv4)),
2564 .next = NEXT(action_set_ipv4_src),
2567 [ACTION_SET_IPV4_SRC_IPV4_SRC] = {
2568 .name = "ipv4_addr",
2569 .help = "new IPv4 source address to set",
2570 .next = NEXT(action_set_ipv4_src, NEXT_ENTRY(IPV4_ADDR)),
2571 .args = ARGS(ARGS_ENTRY_HTON
2572 (struct rte_flow_action_set_ipv4, ipv4_addr)),
2573 .call = parse_vc_conf,
2575 [ACTION_SET_IPV4_DST] = {
2576 .name = "set_ipv4_dst",
2577 .help = "Set a new IPv4 destination address in the outermost"
2579 .priv = PRIV_ACTION(SET_IPV4_DST,
2580 sizeof(struct rte_flow_action_set_ipv4)),
2581 .next = NEXT(action_set_ipv4_dst),
2584 [ACTION_SET_IPV4_DST_IPV4_DST] = {
2585 .name = "ipv4_addr",
2586 .help = "new IPv4 destination address to set",
2587 .next = NEXT(action_set_ipv4_dst, NEXT_ENTRY(IPV4_ADDR)),
2588 .args = ARGS(ARGS_ENTRY_HTON
2589 (struct rte_flow_action_set_ipv4, ipv4_addr)),
2590 .call = parse_vc_conf,
2592 [ACTION_SET_IPV6_SRC] = {
2593 .name = "set_ipv6_src",
2594 .help = "Set a new IPv6 source address in the outermost"
2596 .priv = PRIV_ACTION(SET_IPV6_SRC,
2597 sizeof(struct rte_flow_action_set_ipv6)),
2598 .next = NEXT(action_set_ipv6_src),
2601 [ACTION_SET_IPV6_SRC_IPV6_SRC] = {
2602 .name = "ipv6_addr",
2603 .help = "new IPv6 source address to set",
2604 .next = NEXT(action_set_ipv6_src, NEXT_ENTRY(IPV6_ADDR)),
2605 .args = ARGS(ARGS_ENTRY_HTON
2606 (struct rte_flow_action_set_ipv6, ipv6_addr)),
2607 .call = parse_vc_conf,
2609 [ACTION_SET_IPV6_DST] = {
2610 .name = "set_ipv6_dst",
2611 .help = "Set a new IPv6 destination address in the outermost"
2613 .priv = PRIV_ACTION(SET_IPV6_DST,
2614 sizeof(struct rte_flow_action_set_ipv6)),
2615 .next = NEXT(action_set_ipv6_dst),
2618 [ACTION_SET_IPV6_DST_IPV6_DST] = {
2619 .name = "ipv6_addr",
2620 .help = "new IPv6 destination address to set",
2621 .next = NEXT(action_set_ipv6_dst, NEXT_ENTRY(IPV6_ADDR)),
2622 .args = ARGS(ARGS_ENTRY_HTON
2623 (struct rte_flow_action_set_ipv6, ipv6_addr)),
2624 .call = parse_vc_conf,
2626 [ACTION_SET_TP_SRC] = {
2627 .name = "set_tp_src",
2628 .help = "set a new source port number in the outermost"
2630 .priv = PRIV_ACTION(SET_TP_SRC,
2631 sizeof(struct rte_flow_action_set_tp)),
2632 .next = NEXT(action_set_tp_src),
2635 [ACTION_SET_TP_SRC_TP_SRC] = {
2637 .help = "new source port number to set",
2638 .next = NEXT(action_set_tp_src, NEXT_ENTRY(UNSIGNED)),
2639 .args = ARGS(ARGS_ENTRY_HTON
2640 (struct rte_flow_action_set_tp, port)),
2641 .call = parse_vc_conf,
2643 [ACTION_SET_TP_DST] = {
2644 .name = "set_tp_dst",
2645 .help = "set a new destination port number in the outermost"
2647 .priv = PRIV_ACTION(SET_TP_DST,
2648 sizeof(struct rte_flow_action_set_tp)),
2649 .next = NEXT(action_set_tp_dst),
2652 [ACTION_SET_TP_DST_TP_DST] = {
2654 .help = "new destination port number to set",
2655 .next = NEXT(action_set_tp_dst, NEXT_ENTRY(UNSIGNED)),
2656 .args = ARGS(ARGS_ENTRY_HTON
2657 (struct rte_flow_action_set_tp, port)),
2658 .call = parse_vc_conf,
2660 [ACTION_MAC_SWAP] = {
2662 .help = "Swap the source and destination MAC addresses"
2663 " in the outermost Ethernet header",
2664 .priv = PRIV_ACTION(MAC_SWAP, 0),
2665 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2668 [ACTION_DEC_TTL] = {
2670 .help = "decrease network TTL if available",
2671 .priv = PRIV_ACTION(DEC_TTL, 0),
2672 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2675 [ACTION_SET_TTL] = {
2677 .help = "set ttl value",
2678 .priv = PRIV_ACTION(SET_TTL,
2679 sizeof(struct rte_flow_action_set_ttl)),
2680 .next = NEXT(action_set_ttl),
2683 [ACTION_SET_TTL_TTL] = {
2684 .name = "ttl_value",
2685 .help = "new ttl value to set",
2686 .next = NEXT(action_set_ttl, NEXT_ENTRY(UNSIGNED)),
2687 .args = ARGS(ARGS_ENTRY_HTON
2688 (struct rte_flow_action_set_ttl, ttl_value)),
2689 .call = parse_vc_conf,
2691 [ACTION_SET_MAC_SRC] = {
2692 .name = "set_mac_src",
2693 .help = "set source mac address",
2694 .priv = PRIV_ACTION(SET_MAC_SRC,
2695 sizeof(struct rte_flow_action_set_mac)),
2696 .next = NEXT(action_set_mac_src),
2699 [ACTION_SET_MAC_SRC_MAC_SRC] = {
2701 .help = "new source mac address",
2702 .next = NEXT(action_set_mac_src, NEXT_ENTRY(MAC_ADDR)),
2703 .args = ARGS(ARGS_ENTRY_HTON
2704 (struct rte_flow_action_set_mac, mac_addr)),
2705 .call = parse_vc_conf,
2707 [ACTION_SET_MAC_DST] = {
2708 .name = "set_mac_dst",
2709 .help = "set destination mac address",
2710 .priv = PRIV_ACTION(SET_MAC_DST,
2711 sizeof(struct rte_flow_action_set_mac)),
2712 .next = NEXT(action_set_mac_dst),
2715 [ACTION_SET_MAC_DST_MAC_DST] = {
2717 .help = "new destination mac address to set",
2718 .next = NEXT(action_set_mac_dst, NEXT_ENTRY(MAC_ADDR)),
2719 .args = ARGS(ARGS_ENTRY_HTON
2720 (struct rte_flow_action_set_mac, mac_addr)),
2721 .call = parse_vc_conf,
2725 /** Remove and return last entry from argument stack. */
2726 static const struct arg *
2727 pop_args(struct context *ctx)
2729 return ctx->args_num ? ctx->args[--ctx->args_num] : NULL;
2732 /** Add entry on top of the argument stack. */
2734 push_args(struct context *ctx, const struct arg *arg)
2736 if (ctx->args_num == CTX_STACK_SIZE)
2738 ctx->args[ctx->args_num++] = arg;
2742 /** Spread value into buffer according to bit-mask. */
2744 arg_entry_bf_fill(void *dst, uintmax_t val, const struct arg *arg)
2746 uint32_t i = arg->size;
2754 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
2763 unsigned int shift = 0;
2764 uint8_t *buf = (uint8_t *)dst + arg->offset + (i -= sub);
2766 for (shift = 0; arg->mask[i] >> shift; ++shift) {
2767 if (!(arg->mask[i] & (1 << shift)))
2772 *buf &= ~(1 << shift);
2773 *buf |= (val & 1) << shift;
2781 /** Compare a string with a partial one of a given length. */
2783 strcmp_partial(const char *full, const char *partial, size_t partial_len)
2785 int r = strncmp(full, partial, partial_len);
2789 if (strlen(full) <= partial_len)
2791 return full[partial_len];
2795 * Parse a prefix length and generate a bit-mask.
2797 * Last argument (ctx->args) is retrieved to determine mask size, storage
2798 * location and whether the result must use network byte ordering.
2801 parse_prefix(struct context *ctx, const struct token *token,
2802 const char *str, unsigned int len,
2803 void *buf, unsigned int size)
2805 const struct arg *arg = pop_args(ctx);
2806 static const uint8_t conv[] = "\x00\x80\xc0\xe0\xf0\xf8\xfc\xfe\xff";
2813 /* Argument is expected. */
2817 u = strtoumax(str, &end, 0);
2818 if (errno || (size_t)(end - str) != len)
2823 extra = arg_entry_bf_fill(NULL, 0, arg);
2832 if (!arg_entry_bf_fill(ctx->object, v, arg) ||
2833 !arg_entry_bf_fill(ctx->objmask, -1, arg))
2840 if (bytes > size || bytes + !!extra > size)
2844 buf = (uint8_t *)ctx->object + arg->offset;
2845 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
2847 memset((uint8_t *)buf + size - bytes, 0xff, bytes);
2848 memset(buf, 0x00, size - bytes);
2850 ((uint8_t *)buf)[size - bytes - 1] = conv[extra];
2854 memset(buf, 0xff, bytes);
2855 memset((uint8_t *)buf + bytes, 0x00, size - bytes);
2857 ((uint8_t *)buf)[bytes] = conv[extra];
2860 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
2863 push_args(ctx, arg);
2867 /** Default parsing function for token name matching. */
2869 parse_default(struct context *ctx, const struct token *token,
2870 const char *str, unsigned int len,
2871 void *buf, unsigned int size)
2876 if (strcmp_partial(token->name, str, len))
2881 /** Parse flow command, initialize output buffer for subsequent tokens. */
2883 parse_init(struct context *ctx, const struct token *token,
2884 const char *str, unsigned int len,
2885 void *buf, unsigned int size)
2887 struct buffer *out = buf;
2889 /* Token name must match. */
2890 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
2892 /* Nothing else to do if there is no buffer. */
2895 /* Make sure buffer is large enough. */
2896 if (size < sizeof(*out))
2898 /* Initialize buffer. */
2899 memset(out, 0x00, sizeof(*out));
2900 memset((uint8_t *)out + sizeof(*out), 0x22, size - sizeof(*out));
2903 ctx->objmask = NULL;
2907 /** Parse tokens for validate/create commands. */
2909 parse_vc(struct context *ctx, const struct token *token,
2910 const char *str, unsigned int len,
2911 void *buf, unsigned int size)
2913 struct buffer *out = buf;
2917 /* Token name must match. */
2918 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
2920 /* Nothing else to do if there is no buffer. */
2923 if (!out->command) {
2924 if (ctx->curr != VALIDATE && ctx->curr != CREATE)
2926 if (sizeof(*out) > size)
2928 out->command = ctx->curr;
2931 ctx->objmask = NULL;
2932 out->args.vc.data = (uint8_t *)out + size;
2936 ctx->object = &out->args.vc.attr;
2937 ctx->objmask = NULL;
2938 switch (ctx->curr) {
2943 out->args.vc.attr.ingress = 1;
2946 out->args.vc.attr.egress = 1;
2949 out->args.vc.attr.transfer = 1;
2952 out->args.vc.pattern =
2953 (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
2955 ctx->object = out->args.vc.pattern;
2956 ctx->objmask = NULL;
2959 out->args.vc.actions =
2960 (void *)RTE_ALIGN_CEIL((uintptr_t)
2961 (out->args.vc.pattern +
2962 out->args.vc.pattern_n),
2964 ctx->object = out->args.vc.actions;
2965 ctx->objmask = NULL;
2972 if (!out->args.vc.actions) {
2973 const struct parse_item_priv *priv = token->priv;
2974 struct rte_flow_item *item =
2975 out->args.vc.pattern + out->args.vc.pattern_n;
2977 data_size = priv->size * 3; /* spec, last, mask */
2978 data = (void *)RTE_ALIGN_FLOOR((uintptr_t)
2979 (out->args.vc.data - data_size),
2981 if ((uint8_t *)item + sizeof(*item) > data)
2983 *item = (struct rte_flow_item){
2986 ++out->args.vc.pattern_n;
2988 ctx->objmask = NULL;
2990 const struct parse_action_priv *priv = token->priv;
2991 struct rte_flow_action *action =
2992 out->args.vc.actions + out->args.vc.actions_n;
2994 data_size = priv->size; /* configuration */
2995 data = (void *)RTE_ALIGN_FLOOR((uintptr_t)
2996 (out->args.vc.data - data_size),
2998 if ((uint8_t *)action + sizeof(*action) > data)
3000 *action = (struct rte_flow_action){
3002 .conf = data_size ? data : NULL,
3004 ++out->args.vc.actions_n;
3005 ctx->object = action;
3006 ctx->objmask = NULL;
3008 memset(data, 0, data_size);
3009 out->args.vc.data = data;
3010 ctx->objdata = data_size;
3014 /** Parse pattern item parameter type. */
3016 parse_vc_spec(struct context *ctx, const struct token *token,
3017 const char *str, unsigned int len,
3018 void *buf, unsigned int size)
3020 struct buffer *out = buf;
3021 struct rte_flow_item *item;
3027 /* Token name must match. */
3028 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
3030 /* Parse parameter types. */
3031 switch (ctx->curr) {
3032 static const enum index prefix[] = NEXT_ENTRY(PREFIX);
3038 case ITEM_PARAM_SPEC:
3041 case ITEM_PARAM_LAST:
3044 case ITEM_PARAM_PREFIX:
3045 /* Modify next token to expect a prefix. */
3046 if (ctx->next_num < 2)
3048 ctx->next[ctx->next_num - 2] = prefix;
3050 case ITEM_PARAM_MASK:
3056 /* Nothing else to do if there is no buffer. */
3059 if (!out->args.vc.pattern_n)
3061 item = &out->args.vc.pattern[out->args.vc.pattern_n - 1];
3062 data_size = ctx->objdata / 3; /* spec, last, mask */
3063 /* Point to selected object. */
3064 ctx->object = out->args.vc.data + (data_size * index);
3066 ctx->objmask = out->args.vc.data + (data_size * 2); /* mask */
3067 item->mask = ctx->objmask;
3069 ctx->objmask = NULL;
3070 /* Update relevant item pointer. */
3071 *((const void **[]){ &item->spec, &item->last, &item->mask })[index] =
3076 /** Parse action configuration field. */
3078 parse_vc_conf(struct context *ctx, const struct token *token,
3079 const char *str, unsigned int len,
3080 void *buf, unsigned int size)
3082 struct buffer *out = buf;
3085 /* Token name must match. */
3086 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
3088 /* Nothing else to do if there is no buffer. */
3091 /* Point to selected object. */
3092 ctx->object = out->args.vc.data;
3093 ctx->objmask = NULL;
3097 /** Parse RSS action. */
3099 parse_vc_action_rss(struct context *ctx, const struct token *token,
3100 const char *str, unsigned int len,
3101 void *buf, unsigned int size)
3103 struct buffer *out = buf;
3104 struct rte_flow_action *action;
3105 struct action_rss_data *action_rss_data;
3109 ret = parse_vc(ctx, token, str, len, buf, size);
3112 /* Nothing else to do if there is no buffer. */
3115 if (!out->args.vc.actions_n)
3117 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
3118 /* Point to selected object. */
3119 ctx->object = out->args.vc.data;
3120 ctx->objmask = NULL;
3121 /* Set up default configuration. */
3122 action_rss_data = ctx->object;
3123 *action_rss_data = (struct action_rss_data){
3124 .conf = (struct rte_flow_action_rss){
3125 .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
3128 .key_len = sizeof(action_rss_data->key),
3129 .queue_num = RTE_MIN(nb_rxq, ACTION_RSS_QUEUE_NUM),
3130 .key = action_rss_data->key,
3131 .queue = action_rss_data->queue,
3133 .key = "testpmd's default RSS hash key, "
3134 "override it for better balancing",
3137 for (i = 0; i < action_rss_data->conf.queue_num; ++i)
3138 action_rss_data->queue[i] = i;
3139 if (!port_id_is_invalid(ctx->port, DISABLED_WARN) &&
3140 ctx->port != (portid_t)RTE_PORT_ALL) {
3141 struct rte_eth_dev_info info;
3143 rte_eth_dev_info_get(ctx->port, &info);
3144 action_rss_data->conf.key_len =
3145 RTE_MIN(sizeof(action_rss_data->key),
3146 info.hash_key_size);
3148 action->conf = &action_rss_data->conf;
3153 * Parse func field for RSS action.
3155 * The RTE_ETH_HASH_FUNCTION_* value to assign is derived from the
3156 * ACTION_RSS_FUNC_* index that called this function.
3159 parse_vc_action_rss_func(struct context *ctx, const struct token *token,
3160 const char *str, unsigned int len,
3161 void *buf, unsigned int size)
3163 struct action_rss_data *action_rss_data;
3164 enum rte_eth_hash_function func;
3168 /* Token name must match. */
3169 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
3171 switch (ctx->curr) {
3172 case ACTION_RSS_FUNC_DEFAULT:
3173 func = RTE_ETH_HASH_FUNCTION_DEFAULT;
3175 case ACTION_RSS_FUNC_TOEPLITZ:
3176 func = RTE_ETH_HASH_FUNCTION_TOEPLITZ;
3178 case ACTION_RSS_FUNC_SIMPLE_XOR:
3179 func = RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
3186 action_rss_data = ctx->object;
3187 action_rss_data->conf.func = func;
3192 * Parse type field for RSS action.
3194 * Valid tokens are type field names and the "end" token.
3197 parse_vc_action_rss_type(struct context *ctx, const struct token *token,
3198 const char *str, unsigned int len,
3199 void *buf, unsigned int size)
3201 static const enum index next[] = NEXT_ENTRY(ACTION_RSS_TYPE);
3202 struct action_rss_data *action_rss_data;
3208 if (ctx->curr != ACTION_RSS_TYPE)
3210 if (!(ctx->objdata >> 16) && ctx->object) {
3211 action_rss_data = ctx->object;
3212 action_rss_data->conf.types = 0;
3214 if (!strcmp_partial("end", str, len)) {
3215 ctx->objdata &= 0xffff;
3218 for (i = 0; rss_type_table[i].str; ++i)
3219 if (!strcmp_partial(rss_type_table[i].str, str, len))
3221 if (!rss_type_table[i].str)
3223 ctx->objdata = 1 << 16 | (ctx->objdata & 0xffff);
3225 if (ctx->next_num == RTE_DIM(ctx->next))
3227 ctx->next[ctx->next_num++] = next;
3230 action_rss_data = ctx->object;
3231 action_rss_data->conf.types |= rss_type_table[i].rss_type;
3236 * Parse queue field for RSS action.
3238 * Valid tokens are queue indices and the "end" token.
3241 parse_vc_action_rss_queue(struct context *ctx, const struct token *token,
3242 const char *str, unsigned int len,
3243 void *buf, unsigned int size)
3245 static const enum index next[] = NEXT_ENTRY(ACTION_RSS_QUEUE);
3246 struct action_rss_data *action_rss_data;
3253 if (ctx->curr != ACTION_RSS_QUEUE)
3255 i = ctx->objdata >> 16;
3256 if (!strcmp_partial("end", str, len)) {
3257 ctx->objdata &= 0xffff;
3260 if (i >= ACTION_RSS_QUEUE_NUM)
3263 ARGS_ENTRY_ARB(offsetof(struct action_rss_data, queue) +
3264 i * sizeof(action_rss_data->queue[i]),
3265 sizeof(action_rss_data->queue[i]))))
3267 ret = parse_int(ctx, token, str, len, NULL, 0);
3273 ctx->objdata = i << 16 | (ctx->objdata & 0xffff);
3275 if (ctx->next_num == RTE_DIM(ctx->next))
3277 ctx->next[ctx->next_num++] = next;
3281 action_rss_data = ctx->object;
3282 action_rss_data->conf.queue_num = i;
3283 action_rss_data->conf.queue = i ? action_rss_data->queue : NULL;
3287 /** Parse VXLAN encap action. */
3289 parse_vc_action_vxlan_encap(struct context *ctx, const struct token *token,
3290 const char *str, unsigned int len,
3291 void *buf, unsigned int size)
3293 struct buffer *out = buf;
3294 struct rte_flow_action *action;
3295 struct action_vxlan_encap_data *action_vxlan_encap_data;
3298 ret = parse_vc(ctx, token, str, len, buf, size);
3301 /* Nothing else to do if there is no buffer. */
3304 if (!out->args.vc.actions_n)
3306 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
3307 /* Point to selected object. */
3308 ctx->object = out->args.vc.data;
3309 ctx->objmask = NULL;
3310 /* Set up default configuration. */
3311 action_vxlan_encap_data = ctx->object;
3312 *action_vxlan_encap_data = (struct action_vxlan_encap_data){
3313 .conf = (struct rte_flow_action_vxlan_encap){
3314 .definition = action_vxlan_encap_data->items,
3318 .type = RTE_FLOW_ITEM_TYPE_ETH,
3319 .spec = &action_vxlan_encap_data->item_eth,
3320 .mask = &rte_flow_item_eth_mask,
3323 .type = RTE_FLOW_ITEM_TYPE_VLAN,
3324 .spec = &action_vxlan_encap_data->item_vlan,
3325 .mask = &rte_flow_item_vlan_mask,
3328 .type = RTE_FLOW_ITEM_TYPE_IPV4,
3329 .spec = &action_vxlan_encap_data->item_ipv4,
3330 .mask = &rte_flow_item_ipv4_mask,
3333 .type = RTE_FLOW_ITEM_TYPE_UDP,
3334 .spec = &action_vxlan_encap_data->item_udp,
3335 .mask = &rte_flow_item_udp_mask,
3338 .type = RTE_FLOW_ITEM_TYPE_VXLAN,
3339 .spec = &action_vxlan_encap_data->item_vxlan,
3340 .mask = &rte_flow_item_vxlan_mask,
3343 .type = RTE_FLOW_ITEM_TYPE_END,
3348 .tci = vxlan_encap_conf.vlan_tci,
3352 .src_addr = vxlan_encap_conf.ipv4_src,
3353 .dst_addr = vxlan_encap_conf.ipv4_dst,
3356 .src_port = vxlan_encap_conf.udp_src,
3357 .dst_port = vxlan_encap_conf.udp_dst,
3359 .item_vxlan.flags = 0,
3361 memcpy(action_vxlan_encap_data->item_eth.dst.addr_bytes,
3362 vxlan_encap_conf.eth_dst, ETHER_ADDR_LEN);
3363 memcpy(action_vxlan_encap_data->item_eth.src.addr_bytes,
3364 vxlan_encap_conf.eth_src, ETHER_ADDR_LEN);
3365 if (!vxlan_encap_conf.select_ipv4) {
3366 memcpy(&action_vxlan_encap_data->item_ipv6.hdr.src_addr,
3367 &vxlan_encap_conf.ipv6_src,
3368 sizeof(vxlan_encap_conf.ipv6_src));
3369 memcpy(&action_vxlan_encap_data->item_ipv6.hdr.dst_addr,
3370 &vxlan_encap_conf.ipv6_dst,
3371 sizeof(vxlan_encap_conf.ipv6_dst));
3372 action_vxlan_encap_data->items[2] = (struct rte_flow_item){
3373 .type = RTE_FLOW_ITEM_TYPE_IPV6,
3374 .spec = &action_vxlan_encap_data->item_ipv6,
3375 .mask = &rte_flow_item_ipv6_mask,
3378 if (!vxlan_encap_conf.select_vlan)
3379 action_vxlan_encap_data->items[1].type =
3380 RTE_FLOW_ITEM_TYPE_VOID;
3381 memcpy(action_vxlan_encap_data->item_vxlan.vni, vxlan_encap_conf.vni,
3382 RTE_DIM(vxlan_encap_conf.vni));
3383 action->conf = &action_vxlan_encap_data->conf;
3387 /** Parse NVGRE encap action. */
3389 parse_vc_action_nvgre_encap(struct context *ctx, const struct token *token,
3390 const char *str, unsigned int len,
3391 void *buf, unsigned int size)
3393 struct buffer *out = buf;
3394 struct rte_flow_action *action;
3395 struct action_nvgre_encap_data *action_nvgre_encap_data;
3398 ret = parse_vc(ctx, token, str, len, buf, size);
3401 /* Nothing else to do if there is no buffer. */
3404 if (!out->args.vc.actions_n)
3406 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
3407 /* Point to selected object. */
3408 ctx->object = out->args.vc.data;
3409 ctx->objmask = NULL;
3410 /* Set up default configuration. */
3411 action_nvgre_encap_data = ctx->object;
3412 *action_nvgre_encap_data = (struct action_nvgre_encap_data){
3413 .conf = (struct rte_flow_action_nvgre_encap){
3414 .definition = action_nvgre_encap_data->items,
3418 .type = RTE_FLOW_ITEM_TYPE_ETH,
3419 .spec = &action_nvgre_encap_data->item_eth,
3420 .mask = &rte_flow_item_eth_mask,
3423 .type = RTE_FLOW_ITEM_TYPE_VLAN,
3424 .spec = &action_nvgre_encap_data->item_vlan,
3425 .mask = &rte_flow_item_vlan_mask,
3428 .type = RTE_FLOW_ITEM_TYPE_IPV4,
3429 .spec = &action_nvgre_encap_data->item_ipv4,
3430 .mask = &rte_flow_item_ipv4_mask,
3433 .type = RTE_FLOW_ITEM_TYPE_NVGRE,
3434 .spec = &action_nvgre_encap_data->item_nvgre,
3435 .mask = &rte_flow_item_nvgre_mask,
3438 .type = RTE_FLOW_ITEM_TYPE_END,
3443 .tci = nvgre_encap_conf.vlan_tci,
3447 .src_addr = nvgre_encap_conf.ipv4_src,
3448 .dst_addr = nvgre_encap_conf.ipv4_dst,
3450 .item_nvgre.flow_id = 0,
3452 memcpy(action_nvgre_encap_data->item_eth.dst.addr_bytes,
3453 nvgre_encap_conf.eth_dst, ETHER_ADDR_LEN);
3454 memcpy(action_nvgre_encap_data->item_eth.src.addr_bytes,
3455 nvgre_encap_conf.eth_src, ETHER_ADDR_LEN);
3456 if (!nvgre_encap_conf.select_ipv4) {
3457 memcpy(&action_nvgre_encap_data->item_ipv6.hdr.src_addr,
3458 &nvgre_encap_conf.ipv6_src,
3459 sizeof(nvgre_encap_conf.ipv6_src));
3460 memcpy(&action_nvgre_encap_data->item_ipv6.hdr.dst_addr,
3461 &nvgre_encap_conf.ipv6_dst,
3462 sizeof(nvgre_encap_conf.ipv6_dst));
3463 action_nvgre_encap_data->items[2] = (struct rte_flow_item){
3464 .type = RTE_FLOW_ITEM_TYPE_IPV6,
3465 .spec = &action_nvgre_encap_data->item_ipv6,
3466 .mask = &rte_flow_item_ipv6_mask,
3469 if (!nvgre_encap_conf.select_vlan)
3470 action_nvgre_encap_data->items[1].type =
3471 RTE_FLOW_ITEM_TYPE_VOID;
3472 memcpy(action_nvgre_encap_data->item_nvgre.tni, nvgre_encap_conf.tni,
3473 RTE_DIM(nvgre_encap_conf.tni));
3474 action->conf = &action_nvgre_encap_data->conf;
3478 /** Parse tokens for destroy command. */
3480 parse_destroy(struct context *ctx, const struct token *token,
3481 const char *str, unsigned int len,
3482 void *buf, unsigned int size)
3484 struct buffer *out = buf;
3486 /* Token name must match. */
3487 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
3489 /* Nothing else to do if there is no buffer. */
3492 if (!out->command) {
3493 if (ctx->curr != DESTROY)
3495 if (sizeof(*out) > size)
3497 out->command = ctx->curr;
3500 ctx->objmask = NULL;
3501 out->args.destroy.rule =
3502 (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
3506 if (((uint8_t *)(out->args.destroy.rule + out->args.destroy.rule_n) +
3507 sizeof(*out->args.destroy.rule)) > (uint8_t *)out + size)
3510 ctx->object = out->args.destroy.rule + out->args.destroy.rule_n++;
3511 ctx->objmask = NULL;
3515 /** Parse tokens for flush command. */
3517 parse_flush(struct context *ctx, const struct token *token,
3518 const char *str, unsigned int len,
3519 void *buf, unsigned int size)
3521 struct buffer *out = buf;
3523 /* Token name must match. */
3524 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
3526 /* Nothing else to do if there is no buffer. */
3529 if (!out->command) {
3530 if (ctx->curr != FLUSH)
3532 if (sizeof(*out) > size)
3534 out->command = ctx->curr;
3537 ctx->objmask = NULL;
3542 /** Parse tokens for query command. */
3544 parse_query(struct context *ctx, const struct token *token,
3545 const char *str, unsigned int len,
3546 void *buf, unsigned int size)
3548 struct buffer *out = buf;
3550 /* Token name must match. */
3551 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
3553 /* Nothing else to do if there is no buffer. */
3556 if (!out->command) {
3557 if (ctx->curr != QUERY)
3559 if (sizeof(*out) > size)
3561 out->command = ctx->curr;
3564 ctx->objmask = NULL;
3569 /** Parse action names. */
3571 parse_action(struct context *ctx, const struct token *token,
3572 const char *str, unsigned int len,
3573 void *buf, unsigned int size)
3575 struct buffer *out = buf;
3576 const struct arg *arg = pop_args(ctx);
3580 /* Argument is expected. */
3583 /* Parse action name. */
3584 for (i = 0; next_action[i]; ++i) {
3585 const struct parse_action_priv *priv;
3587 token = &token_list[next_action[i]];
3588 if (strcmp_partial(token->name, str, len))
3594 memcpy((uint8_t *)ctx->object + arg->offset,
3600 push_args(ctx, arg);
3604 /** Parse tokens for list command. */
3606 parse_list(struct context *ctx, const struct token *token,
3607 const char *str, unsigned int len,
3608 void *buf, unsigned int size)
3610 struct buffer *out = buf;
3612 /* Token name must match. */
3613 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
3615 /* Nothing else to do if there is no buffer. */
3618 if (!out->command) {
3619 if (ctx->curr != LIST)
3621 if (sizeof(*out) > size)
3623 out->command = ctx->curr;
3626 ctx->objmask = NULL;
3627 out->args.list.group =
3628 (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
3632 if (((uint8_t *)(out->args.list.group + out->args.list.group_n) +
3633 sizeof(*out->args.list.group)) > (uint8_t *)out + size)
3636 ctx->object = out->args.list.group + out->args.list.group_n++;
3637 ctx->objmask = NULL;
3641 /** Parse tokens for isolate command. */
3643 parse_isolate(struct context *ctx, const struct token *token,
3644 const char *str, unsigned int len,
3645 void *buf, unsigned int size)
3647 struct buffer *out = buf;
3649 /* Token name must match. */
3650 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
3652 /* Nothing else to do if there is no buffer. */
3655 if (!out->command) {
3656 if (ctx->curr != ISOLATE)
3658 if (sizeof(*out) > size)
3660 out->command = ctx->curr;
3663 ctx->objmask = NULL;
3669 * Parse signed/unsigned integers 8 to 64-bit long.
3671 * Last argument (ctx->args) is retrieved to determine integer type and
3675 parse_int(struct context *ctx, const struct token *token,
3676 const char *str, unsigned int len,
3677 void *buf, unsigned int size)
3679 const struct arg *arg = pop_args(ctx);
3684 /* Argument is expected. */
3689 (uintmax_t)strtoimax(str, &end, 0) :
3690 strtoumax(str, &end, 0);
3691 if (errno || (size_t)(end - str) != len)
3694 ((arg->sign && ((intmax_t)u < (intmax_t)arg->min ||
3695 (intmax_t)u > (intmax_t)arg->max)) ||
3696 (!arg->sign && (u < arg->min || u > arg->max))))
3701 if (!arg_entry_bf_fill(ctx->object, u, arg) ||
3702 !arg_entry_bf_fill(ctx->objmask, -1, arg))
3706 buf = (uint8_t *)ctx->object + arg->offset;
3710 case sizeof(uint8_t):
3711 *(uint8_t *)buf = u;
3713 case sizeof(uint16_t):
3714 *(uint16_t *)buf = arg->hton ? rte_cpu_to_be_16(u) : u;
3716 case sizeof(uint8_t [3]):
3717 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
3719 ((uint8_t *)buf)[0] = u;
3720 ((uint8_t *)buf)[1] = u >> 8;
3721 ((uint8_t *)buf)[2] = u >> 16;
3725 ((uint8_t *)buf)[0] = u >> 16;
3726 ((uint8_t *)buf)[1] = u >> 8;
3727 ((uint8_t *)buf)[2] = u;
3729 case sizeof(uint32_t):
3730 *(uint32_t *)buf = arg->hton ? rte_cpu_to_be_32(u) : u;
3732 case sizeof(uint64_t):
3733 *(uint64_t *)buf = arg->hton ? rte_cpu_to_be_64(u) : u;
3738 if (ctx->objmask && buf != (uint8_t *)ctx->objmask + arg->offset) {
3740 buf = (uint8_t *)ctx->objmask + arg->offset;
3745 push_args(ctx, arg);
3752 * Three arguments (ctx->args) are retrieved from the stack to store data,
3753 * its actual length and address (in that order).
3756 parse_string(struct context *ctx, const struct token *token,
3757 const char *str, unsigned int len,
3758 void *buf, unsigned int size)
3760 const struct arg *arg_data = pop_args(ctx);
3761 const struct arg *arg_len = pop_args(ctx);
3762 const struct arg *arg_addr = pop_args(ctx);
3763 char tmp[16]; /* Ought to be enough. */
3766 /* Arguments are expected. */
3770 push_args(ctx, arg_data);
3774 push_args(ctx, arg_len);
3775 push_args(ctx, arg_data);
3778 size = arg_data->size;
3779 /* Bit-mask fill is not supported. */
3780 if (arg_data->mask || size < len)
3784 /* Let parse_int() fill length information first. */
3785 ret = snprintf(tmp, sizeof(tmp), "%u", len);
3788 push_args(ctx, arg_len);
3789 ret = parse_int(ctx, token, tmp, ret, NULL, 0);
3794 buf = (uint8_t *)ctx->object + arg_data->offset;
3795 /* Output buffer is not necessarily NUL-terminated. */
3796 memcpy(buf, str, len);
3797 memset((uint8_t *)buf + len, 0x00, size - len);
3799 memset((uint8_t *)ctx->objmask + arg_data->offset, 0xff, len);
3800 /* Save address if requested. */
3801 if (arg_addr->size) {
3802 memcpy((uint8_t *)ctx->object + arg_addr->offset,
3804 (uint8_t *)ctx->object + arg_data->offset
3808 memcpy((uint8_t *)ctx->objmask + arg_addr->offset,
3810 (uint8_t *)ctx->objmask + arg_data->offset
3816 push_args(ctx, arg_addr);
3817 push_args(ctx, arg_len);
3818 push_args(ctx, arg_data);
3823 * Parse a MAC address.
3825 * Last argument (ctx->args) is retrieved to determine storage size and
3829 parse_mac_addr(struct context *ctx, const struct token *token,
3830 const char *str, unsigned int len,
3831 void *buf, unsigned int size)
3833 const struct arg *arg = pop_args(ctx);
3834 struct ether_addr tmp;
3838 /* Argument is expected. */
3842 /* Bit-mask fill is not supported. */
3843 if (arg->mask || size != sizeof(tmp))
3845 /* Only network endian is supported. */
3848 ret = cmdline_parse_etheraddr(NULL, str, &tmp, size);
3849 if (ret < 0 || (unsigned int)ret != len)
3853 buf = (uint8_t *)ctx->object + arg->offset;
3854 memcpy(buf, &tmp, size);
3856 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
3859 push_args(ctx, arg);
3864 * Parse an IPv4 address.
3866 * Last argument (ctx->args) is retrieved to determine storage size and
3870 parse_ipv4_addr(struct context *ctx, const struct token *token,
3871 const char *str, unsigned int len,
3872 void *buf, unsigned int size)
3874 const struct arg *arg = pop_args(ctx);
3879 /* Argument is expected. */
3883 /* Bit-mask fill is not supported. */
3884 if (arg->mask || size != sizeof(tmp))
3886 /* Only network endian is supported. */
3889 memcpy(str2, str, len);
3891 ret = inet_pton(AF_INET, str2, &tmp);
3893 /* Attempt integer parsing. */
3894 push_args(ctx, arg);
3895 return parse_int(ctx, token, str, len, buf, size);
3899 buf = (uint8_t *)ctx->object + arg->offset;
3900 memcpy(buf, &tmp, size);
3902 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
3905 push_args(ctx, arg);
3910 * Parse an IPv6 address.
3912 * Last argument (ctx->args) is retrieved to determine storage size and
3916 parse_ipv6_addr(struct context *ctx, const struct token *token,
3917 const char *str, unsigned int len,
3918 void *buf, unsigned int size)
3920 const struct arg *arg = pop_args(ctx);
3922 struct in6_addr tmp;
3926 /* Argument is expected. */
3930 /* Bit-mask fill is not supported. */
3931 if (arg->mask || size != sizeof(tmp))
3933 /* Only network endian is supported. */
3936 memcpy(str2, str, len);
3938 ret = inet_pton(AF_INET6, str2, &tmp);
3943 buf = (uint8_t *)ctx->object + arg->offset;
3944 memcpy(buf, &tmp, size);
3946 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
3949 push_args(ctx, arg);
3953 /** Boolean values (even indices stand for false). */
3954 static const char *const boolean_name[] = {
3964 * Parse a boolean value.
3966 * Last argument (ctx->args) is retrieved to determine storage size and
3970 parse_boolean(struct context *ctx, const struct token *token,
3971 const char *str, unsigned int len,
3972 void *buf, unsigned int size)
3974 const struct arg *arg = pop_args(ctx);
3978 /* Argument is expected. */
3981 for (i = 0; boolean_name[i]; ++i)
3982 if (!strcmp_partial(boolean_name[i], str, len))
3984 /* Process token as integer. */
3985 if (boolean_name[i])
3986 str = i & 1 ? "1" : "0";
3987 push_args(ctx, arg);
3988 ret = parse_int(ctx, token, str, strlen(str), buf, size);
3989 return ret > 0 ? (int)len : ret;
3992 /** Parse port and update context. */
3994 parse_port(struct context *ctx, const struct token *token,
3995 const char *str, unsigned int len,
3996 void *buf, unsigned int size)
3998 struct buffer *out = &(struct buffer){ .port = 0 };
4006 ctx->objmask = NULL;
4007 size = sizeof(*out);
4009 ret = parse_int(ctx, token, str, len, out, size);
4011 ctx->port = out->port;
4017 /** No completion. */
4019 comp_none(struct context *ctx, const struct token *token,
4020 unsigned int ent, char *buf, unsigned int size)
4030 /** Complete boolean values. */
4032 comp_boolean(struct context *ctx, const struct token *token,
4033 unsigned int ent, char *buf, unsigned int size)
4039 for (i = 0; boolean_name[i]; ++i)
4040 if (buf && i == ent)
4041 return snprintf(buf, size, "%s", boolean_name[i]);
4047 /** Complete action names. */
4049 comp_action(struct context *ctx, const struct token *token,
4050 unsigned int ent, char *buf, unsigned int size)
4056 for (i = 0; next_action[i]; ++i)
4057 if (buf && i == ent)
4058 return snprintf(buf, size, "%s",
4059 token_list[next_action[i]].name);
4065 /** Complete available ports. */
4067 comp_port(struct context *ctx, const struct token *token,
4068 unsigned int ent, char *buf, unsigned int size)
4075 RTE_ETH_FOREACH_DEV(p) {
4076 if (buf && i == ent)
4077 return snprintf(buf, size, "%u", p);
4085 /** Complete available rule IDs. */
4087 comp_rule_id(struct context *ctx, const struct token *token,
4088 unsigned int ent, char *buf, unsigned int size)
4091 struct rte_port *port;
4092 struct port_flow *pf;
4095 if (port_id_is_invalid(ctx->port, DISABLED_WARN) ||
4096 ctx->port == (portid_t)RTE_PORT_ALL)
4098 port = &ports[ctx->port];
4099 for (pf = port->flow_list; pf != NULL; pf = pf->next) {
4100 if (buf && i == ent)
4101 return snprintf(buf, size, "%u", pf->id);
4109 /** Complete type field for RSS action. */
4111 comp_vc_action_rss_type(struct context *ctx, const struct token *token,
4112 unsigned int ent, char *buf, unsigned int size)
4118 for (i = 0; rss_type_table[i].str; ++i)
4123 return snprintf(buf, size, "%s", rss_type_table[ent].str);
4125 return snprintf(buf, size, "end");
4129 /** Complete queue field for RSS action. */
4131 comp_vc_action_rss_queue(struct context *ctx, const struct token *token,
4132 unsigned int ent, char *buf, unsigned int size)
4139 return snprintf(buf, size, "%u", ent);
4141 return snprintf(buf, size, "end");
4145 /** Internal context. */
4146 static struct context cmd_flow_context;
4148 /** Global parser instance (cmdline API). */
4149 cmdline_parse_inst_t cmd_flow;
4151 /** Initialize context. */
4153 cmd_flow_context_init(struct context *ctx)
4155 /* A full memset() is not necessary. */
4165 ctx->objmask = NULL;
4168 /** Parse a token (cmdline API). */
4170 cmd_flow_parse(cmdline_parse_token_hdr_t *hdr, const char *src, void *result,
4173 struct context *ctx = &cmd_flow_context;
4174 const struct token *token;
4175 const enum index *list;
4180 token = &token_list[ctx->curr];
4181 /* Check argument length. */
4184 for (len = 0; src[len]; ++len)
4185 if (src[len] == '#' || isspace(src[len]))
4189 /* Last argument and EOL detection. */
4190 for (i = len; src[i]; ++i)
4191 if (src[i] == '#' || src[i] == '\r' || src[i] == '\n')
4193 else if (!isspace(src[i])) {
4198 if (src[i] == '\r' || src[i] == '\n') {
4202 /* Initialize context if necessary. */
4203 if (!ctx->next_num) {
4206 ctx->next[ctx->next_num++] = token->next[0];
4208 /* Process argument through candidates. */
4209 ctx->prev = ctx->curr;
4210 list = ctx->next[ctx->next_num - 1];
4211 for (i = 0; list[i]; ++i) {
4212 const struct token *next = &token_list[list[i]];
4215 ctx->curr = list[i];
4217 tmp = next->call(ctx, next, src, len, result, size);
4219 tmp = parse_default(ctx, next, src, len, result, size);
4220 if (tmp == -1 || tmp != len)
4228 /* Push subsequent tokens if any. */
4230 for (i = 0; token->next[i]; ++i) {
4231 if (ctx->next_num == RTE_DIM(ctx->next))
4233 ctx->next[ctx->next_num++] = token->next[i];
4235 /* Push arguments if any. */
4237 for (i = 0; token->args[i]; ++i) {
4238 if (ctx->args_num == RTE_DIM(ctx->args))
4240 ctx->args[ctx->args_num++] = token->args[i];
4245 /** Return number of completion entries (cmdline API). */
4247 cmd_flow_complete_get_nb(cmdline_parse_token_hdr_t *hdr)
4249 struct context *ctx = &cmd_flow_context;
4250 const struct token *token = &token_list[ctx->curr];
4251 const enum index *list;
4255 /* Count number of tokens in current list. */
4257 list = ctx->next[ctx->next_num - 1];
4259 list = token->next[0];
4260 for (i = 0; list[i]; ++i)
4265 * If there is a single token, use its completion callback, otherwise
4266 * return the number of entries.
4268 token = &token_list[list[0]];
4269 if (i == 1 && token->comp) {
4270 /* Save index for cmd_flow_get_help(). */
4271 ctx->prev = list[0];
4272 return token->comp(ctx, token, 0, NULL, 0);
4277 /** Return a completion entry (cmdline API). */
4279 cmd_flow_complete_get_elt(cmdline_parse_token_hdr_t *hdr, int index,
4280 char *dst, unsigned int size)
4282 struct context *ctx = &cmd_flow_context;
4283 const struct token *token = &token_list[ctx->curr];
4284 const enum index *list;
4288 /* Count number of tokens in current list. */
4290 list = ctx->next[ctx->next_num - 1];
4292 list = token->next[0];
4293 for (i = 0; list[i]; ++i)
4297 /* If there is a single token, use its completion callback. */
4298 token = &token_list[list[0]];
4299 if (i == 1 && token->comp) {
4300 /* Save index for cmd_flow_get_help(). */
4301 ctx->prev = list[0];
4302 return token->comp(ctx, token, index, dst, size) < 0 ? -1 : 0;
4304 /* Otherwise make sure the index is valid and use defaults. */
4307 token = &token_list[list[index]];
4308 snprintf(dst, size, "%s", token->name);
4309 /* Save index for cmd_flow_get_help(). */
4310 ctx->prev = list[index];
4314 /** Populate help strings for current token (cmdline API). */
4316 cmd_flow_get_help(cmdline_parse_token_hdr_t *hdr, char *dst, unsigned int size)
4318 struct context *ctx = &cmd_flow_context;
4319 const struct token *token = &token_list[ctx->prev];
4324 /* Set token type and update global help with details. */
4325 snprintf(dst, size, "%s", (token->type ? token->type : "TOKEN"));
4327 cmd_flow.help_str = token->help;
4329 cmd_flow.help_str = token->name;
4333 /** Token definition template (cmdline API). */
4334 static struct cmdline_token_hdr cmd_flow_token_hdr = {
4335 .ops = &(struct cmdline_token_ops){
4336 .parse = cmd_flow_parse,
4337 .complete_get_nb = cmd_flow_complete_get_nb,
4338 .complete_get_elt = cmd_flow_complete_get_elt,
4339 .get_help = cmd_flow_get_help,
4344 /** Populate the next dynamic token. */
4346 cmd_flow_tok(cmdline_parse_token_hdr_t **hdr,
4347 cmdline_parse_token_hdr_t **hdr_inst)
4349 struct context *ctx = &cmd_flow_context;
4351 /* Always reinitialize context before requesting the first token. */
4352 if (!(hdr_inst - cmd_flow.tokens))
4353 cmd_flow_context_init(ctx);
4354 /* Return NULL when no more tokens are expected. */
4355 if (!ctx->next_num && ctx->curr) {
4359 /* Determine if command should end here. */
4360 if (ctx->eol && ctx->last && ctx->next_num) {
4361 const enum index *list = ctx->next[ctx->next_num - 1];
4364 for (i = 0; list[i]; ++i) {
4371 *hdr = &cmd_flow_token_hdr;
4374 /** Dispatch parsed buffer to function calls. */
4376 cmd_flow_parsed(const struct buffer *in)
4378 switch (in->command) {
4380 port_flow_validate(in->port, &in->args.vc.attr,
4381 in->args.vc.pattern, in->args.vc.actions);
4384 port_flow_create(in->port, &in->args.vc.attr,
4385 in->args.vc.pattern, in->args.vc.actions);
4388 port_flow_destroy(in->port, in->args.destroy.rule_n,
4389 in->args.destroy.rule);
4392 port_flow_flush(in->port);
4395 port_flow_query(in->port, in->args.query.rule,
4396 &in->args.query.action);
4399 port_flow_list(in->port, in->args.list.group_n,
4400 in->args.list.group);
4403 port_flow_isolate(in->port, in->args.isolate.set);
4410 /** Token generator and output processing callback (cmdline API). */
4412 cmd_flow_cb(void *arg0, struct cmdline *cl, void *arg2)
4415 cmd_flow_tok(arg0, arg2);
4417 cmd_flow_parsed(arg0);
4420 /** Global parser instance (cmdline API). */
4421 cmdline_parse_inst_t cmd_flow = {
4423 .data = NULL, /**< Unused. */
4424 .help_str = NULL, /**< Updated by cmd_flow_get_help(). */
4427 }, /**< Tokens are returned by cmd_flow_tok(). */