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. */
109 ITEM_VLAN_INNER_TYPE,
141 ITEM_E_TAG_GRP_ECID_B,
160 ITEM_ARP_ETH_IPV4_SHA,
161 ITEM_ARP_ETH_IPV4_SPA,
162 ITEM_ARP_ETH_IPV4_THA,
163 ITEM_ARP_ETH_IPV4_TPA,
165 ITEM_IPV6_EXT_NEXT_HDR,
170 ITEM_ICMP6_ND_NS_TARGET_ADDR,
172 ITEM_ICMP6_ND_NA_TARGET_ADDR,
174 ITEM_ICMP6_ND_OPT_TYPE,
175 ITEM_ICMP6_ND_OPT_SLA_ETH,
176 ITEM_ICMP6_ND_OPT_SLA_ETH_SLA,
177 ITEM_ICMP6_ND_OPT_TLA_ETH,
178 ITEM_ICMP6_ND_OPT_TLA_ETH_TLA,
180 /* Validate/create actions. */
198 ACTION_RSS_FUNC_DEFAULT,
199 ACTION_RSS_FUNC_TOEPLITZ,
200 ACTION_RSS_FUNC_SIMPLE_XOR,
212 ACTION_PHY_PORT_ORIGINAL,
213 ACTION_PHY_PORT_INDEX,
215 ACTION_PORT_ID_ORIGINAL,
219 ACTION_OF_SET_MPLS_TTL,
220 ACTION_OF_SET_MPLS_TTL_MPLS_TTL,
221 ACTION_OF_DEC_MPLS_TTL,
222 ACTION_OF_SET_NW_TTL,
223 ACTION_OF_SET_NW_TTL_NW_TTL,
224 ACTION_OF_DEC_NW_TTL,
225 ACTION_OF_COPY_TTL_OUT,
226 ACTION_OF_COPY_TTL_IN,
229 ACTION_OF_PUSH_VLAN_ETHERTYPE,
230 ACTION_OF_SET_VLAN_VID,
231 ACTION_OF_SET_VLAN_VID_VLAN_VID,
232 ACTION_OF_SET_VLAN_PCP,
233 ACTION_OF_SET_VLAN_PCP_VLAN_PCP,
235 ACTION_OF_POP_MPLS_ETHERTYPE,
237 ACTION_OF_PUSH_MPLS_ETHERTYPE,
240 /** Maximum size for pattern in struct rte_flow_item_raw. */
241 #define ITEM_RAW_PATTERN_SIZE 40
243 /** Storage size for struct rte_flow_item_raw including pattern. */
244 #define ITEM_RAW_SIZE \
245 (sizeof(struct rte_flow_item_raw) + ITEM_RAW_PATTERN_SIZE)
247 /** Maximum number of queue indices in struct rte_flow_action_rss. */
248 #define ACTION_RSS_QUEUE_NUM 32
250 /** Storage for struct rte_flow_action_rss including external data. */
251 struct action_rss_data {
252 struct rte_flow_action_rss conf;
253 uint8_t key[RSS_HASH_KEY_LENGTH];
254 uint16_t queue[ACTION_RSS_QUEUE_NUM];
257 /** Maximum number of subsequent tokens and arguments on the stack. */
258 #define CTX_STACK_SIZE 16
260 /** Parser context. */
262 /** Stack of subsequent token lists to process. */
263 const enum index *next[CTX_STACK_SIZE];
264 /** Arguments for stacked tokens. */
265 const void *args[CTX_STACK_SIZE];
266 enum index curr; /**< Current token index. */
267 enum index prev; /**< Index of the last token seen. */
268 int next_num; /**< Number of entries in next[]. */
269 int args_num; /**< Number of entries in args[]. */
270 uint32_t eol:1; /**< EOL has been detected. */
271 uint32_t last:1; /**< No more arguments. */
272 portid_t port; /**< Current port ID (for completions). */
273 uint32_t objdata; /**< Object-specific data. */
274 void *object; /**< Address of current object for relative offsets. */
275 void *objmask; /**< Object a full mask must be written to. */
278 /** Token argument. */
280 uint32_t hton:1; /**< Use network byte ordering. */
281 uint32_t sign:1; /**< Value is signed. */
282 uint32_t bounded:1; /**< Value is bounded. */
283 uintmax_t min; /**< Minimum value if bounded. */
284 uintmax_t max; /**< Maximum value if bounded. */
285 uint32_t offset; /**< Relative offset from ctx->object. */
286 uint32_t size; /**< Field size. */
287 const uint8_t *mask; /**< Bit-mask to use instead of offset/size. */
290 /** Parser token definition. */
292 /** Type displayed during completion (defaults to "TOKEN"). */
294 /** Help displayed during completion (defaults to token name). */
296 /** Private data used by parser functions. */
299 * Lists of subsequent tokens to push on the stack. Each call to the
300 * parser consumes the last entry of that stack.
302 const enum index *const *next;
303 /** Arguments stack for subsequent tokens that need them. */
304 const struct arg *const *args;
306 * Token-processing callback, returns -1 in case of error, the
307 * length of the matched string otherwise. If NULL, attempts to
308 * match the token name.
310 * If buf is not NULL, the result should be stored in it according
311 * to context. An error is returned if not large enough.
313 int (*call)(struct context *ctx, const struct token *token,
314 const char *str, unsigned int len,
315 void *buf, unsigned int size);
317 * Callback that provides possible values for this token, used for
318 * completion. Returns -1 in case of error, the number of possible
319 * values otherwise. If NULL, the token name is used.
321 * If buf is not NULL, entry index ent is written to buf and the
322 * full length of the entry is returned (same behavior as
325 int (*comp)(struct context *ctx, const struct token *token,
326 unsigned int ent, char *buf, unsigned int size);
327 /** Mandatory token name, no default value. */
331 /** Static initializer for the next field. */
332 #define NEXT(...) (const enum index *const []){ __VA_ARGS__, NULL, }
334 /** Static initializer for a NEXT() entry. */
335 #define NEXT_ENTRY(...) (const enum index []){ __VA_ARGS__, ZERO, }
337 /** Static initializer for the args field. */
338 #define ARGS(...) (const struct arg *const []){ __VA_ARGS__, NULL, }
340 /** Static initializer for ARGS() to target a field. */
341 #define ARGS_ENTRY(s, f) \
342 (&(const struct arg){ \
343 .offset = offsetof(s, f), \
344 .size = sizeof(((s *)0)->f), \
347 /** Static initializer for ARGS() to target a bit-field. */
348 #define ARGS_ENTRY_BF(s, f, b) \
349 (&(const struct arg){ \
351 .mask = (const void *)&(const s){ .f = (1 << (b)) - 1 }, \
354 /** Static initializer for ARGS() to target an arbitrary bit-mask. */
355 #define ARGS_ENTRY_MASK(s, f, m) \
356 (&(const struct arg){ \
357 .offset = offsetof(s, f), \
358 .size = sizeof(((s *)0)->f), \
359 .mask = (const void *)(m), \
362 /** Same as ARGS_ENTRY_MASK() using network byte ordering for the value. */
363 #define ARGS_ENTRY_MASK_HTON(s, f, m) \
364 (&(const struct arg){ \
366 .offset = offsetof(s, f), \
367 .size = sizeof(((s *)0)->f), \
368 .mask = (const void *)(m), \
371 /** Static initializer for ARGS() to target a pointer. */
372 #define ARGS_ENTRY_PTR(s, f) \
373 (&(const struct arg){ \
374 .size = sizeof(*((s *)0)->f), \
377 /** Static initializer for ARGS() with arbitrary offset and size. */
378 #define ARGS_ENTRY_ARB(o, s) \
379 (&(const struct arg){ \
384 /** Same as ARGS_ENTRY_ARB() with bounded values. */
385 #define ARGS_ENTRY_ARB_BOUNDED(o, s, i, a) \
386 (&(const struct arg){ \
394 /** Same as ARGS_ENTRY() using network byte ordering. */
395 #define ARGS_ENTRY_HTON(s, f) \
396 (&(const struct arg){ \
398 .offset = offsetof(s, f), \
399 .size = sizeof(((s *)0)->f), \
402 /** Parser output buffer layout expected by cmd_flow_parsed(). */
404 enum index command; /**< Flow command. */
405 portid_t port; /**< Affected port ID. */
408 struct rte_flow_attr attr;
409 struct rte_flow_item *pattern;
410 struct rte_flow_action *actions;
414 } vc; /**< Validate/create arguments. */
418 } destroy; /**< Destroy arguments. */
421 enum rte_flow_action_type action;
422 } query; /**< Query arguments. */
426 } list; /**< List arguments. */
429 } isolate; /**< Isolated mode arguments. */
430 } args; /**< Command arguments. */
433 /** Private data for pattern items. */
434 struct parse_item_priv {
435 enum rte_flow_item_type type; /**< Item type. */
436 uint32_t size; /**< Size of item specification structure. */
439 #define PRIV_ITEM(t, s) \
440 (&(const struct parse_item_priv){ \
441 .type = RTE_FLOW_ITEM_TYPE_ ## t, \
445 /** Private data for actions. */
446 struct parse_action_priv {
447 enum rte_flow_action_type type; /**< Action type. */
448 uint32_t size; /**< Size of action configuration structure. */
451 #define PRIV_ACTION(t, s) \
452 (&(const struct parse_action_priv){ \
453 .type = RTE_FLOW_ACTION_TYPE_ ## t, \
457 static const enum index next_vc_attr[] = {
467 static const enum index next_destroy_attr[] = {
473 static const enum index next_list_attr[] = {
479 static const enum index item_param[] = {
488 static const enum index next_item[] = {
523 ITEM_ICMP6_ND_OPT_SLA_ETH,
524 ITEM_ICMP6_ND_OPT_TLA_ETH,
528 static const enum index item_fuzzy[] = {
534 static const enum index item_any[] = {
540 static const enum index item_vf[] = {
546 static const enum index item_phy_port[] = {
552 static const enum index item_port_id[] = {
558 static const enum index item_raw[] = {
568 static const enum index item_eth[] = {
576 static const enum index item_vlan[] = {
581 ITEM_VLAN_INNER_TYPE,
586 static const enum index item_ipv4[] = {
596 static const enum index item_ipv6[] = {
607 static const enum index item_icmp[] = {
614 static const enum index item_udp[] = {
621 static const enum index item_tcp[] = {
629 static const enum index item_sctp[] = {
638 static const enum index item_vxlan[] = {
644 static const enum index item_e_tag[] = {
645 ITEM_E_TAG_GRP_ECID_B,
650 static const enum index item_nvgre[] = {
656 static const enum index item_mpls[] = {
662 static const enum index item_gre[] = {
668 static const enum index item_gtp[] = {
674 static const enum index item_geneve[] = {
681 static const enum index item_vxlan_gpe[] = {
687 static const enum index item_arp_eth_ipv4[] = {
688 ITEM_ARP_ETH_IPV4_SHA,
689 ITEM_ARP_ETH_IPV4_SPA,
690 ITEM_ARP_ETH_IPV4_THA,
691 ITEM_ARP_ETH_IPV4_TPA,
696 static const enum index item_ipv6_ext[] = {
697 ITEM_IPV6_EXT_NEXT_HDR,
702 static const enum index item_icmp6[] = {
709 static const enum index item_icmp6_nd_ns[] = {
710 ITEM_ICMP6_ND_NS_TARGET_ADDR,
715 static const enum index item_icmp6_nd_na[] = {
716 ITEM_ICMP6_ND_NA_TARGET_ADDR,
721 static const enum index item_icmp6_nd_opt[] = {
722 ITEM_ICMP6_ND_OPT_TYPE,
727 static const enum index item_icmp6_nd_opt_sla_eth[] = {
728 ITEM_ICMP6_ND_OPT_SLA_ETH_SLA,
733 static const enum index item_icmp6_nd_opt_tla_eth[] = {
734 ITEM_ICMP6_ND_OPT_TLA_ETH_TLA,
739 static const enum index next_action[] = {
755 ACTION_OF_SET_MPLS_TTL,
756 ACTION_OF_DEC_MPLS_TTL,
757 ACTION_OF_SET_NW_TTL,
758 ACTION_OF_DEC_NW_TTL,
759 ACTION_OF_COPY_TTL_OUT,
760 ACTION_OF_COPY_TTL_IN,
763 ACTION_OF_SET_VLAN_VID,
764 ACTION_OF_SET_VLAN_PCP,
770 static const enum index action_mark[] = {
776 static const enum index action_queue[] = {
782 static const enum index action_rss[] = {
793 static const enum index action_vf[] = {
800 static const enum index action_phy_port[] = {
801 ACTION_PHY_PORT_ORIGINAL,
802 ACTION_PHY_PORT_INDEX,
807 static const enum index action_port_id[] = {
808 ACTION_PORT_ID_ORIGINAL,
814 static const enum index action_meter[] = {
820 static const enum index action_of_set_mpls_ttl[] = {
821 ACTION_OF_SET_MPLS_TTL_MPLS_TTL,
826 static const enum index action_of_set_nw_ttl[] = {
827 ACTION_OF_SET_NW_TTL_NW_TTL,
832 static const enum index action_of_push_vlan[] = {
833 ACTION_OF_PUSH_VLAN_ETHERTYPE,
838 static const enum index action_of_set_vlan_vid[] = {
839 ACTION_OF_SET_VLAN_VID_VLAN_VID,
844 static const enum index action_of_set_vlan_pcp[] = {
845 ACTION_OF_SET_VLAN_PCP_VLAN_PCP,
850 static const enum index action_of_pop_mpls[] = {
851 ACTION_OF_POP_MPLS_ETHERTYPE,
856 static const enum index action_of_push_mpls[] = {
857 ACTION_OF_PUSH_MPLS_ETHERTYPE,
862 static const enum index action_jump[] = {
868 static int parse_init(struct context *, const struct token *,
869 const char *, unsigned int,
870 void *, unsigned int);
871 static int parse_vc(struct context *, const struct token *,
872 const char *, unsigned int,
873 void *, unsigned int);
874 static int parse_vc_spec(struct context *, const struct token *,
875 const char *, unsigned int, void *, unsigned int);
876 static int parse_vc_conf(struct context *, const struct token *,
877 const char *, unsigned int, void *, unsigned int);
878 static int parse_vc_action_rss(struct context *, const struct token *,
879 const char *, unsigned int, void *,
881 static int parse_vc_action_rss_func(struct context *, const struct token *,
882 const char *, unsigned int, void *,
884 static int parse_vc_action_rss_type(struct context *, const struct token *,
885 const char *, unsigned int, void *,
887 static int parse_vc_action_rss_queue(struct context *, const struct token *,
888 const char *, unsigned int, void *,
890 static int parse_destroy(struct context *, const struct token *,
891 const char *, unsigned int,
892 void *, unsigned int);
893 static int parse_flush(struct context *, const struct token *,
894 const char *, unsigned int,
895 void *, unsigned int);
896 static int parse_query(struct context *, const struct token *,
897 const char *, unsigned int,
898 void *, unsigned int);
899 static int parse_action(struct context *, const struct token *,
900 const char *, unsigned int,
901 void *, unsigned int);
902 static int parse_list(struct context *, const struct token *,
903 const char *, unsigned int,
904 void *, unsigned int);
905 static int parse_isolate(struct context *, const struct token *,
906 const char *, unsigned int,
907 void *, unsigned int);
908 static int parse_int(struct context *, const struct token *,
909 const char *, unsigned int,
910 void *, unsigned int);
911 static int parse_prefix(struct context *, const struct token *,
912 const char *, unsigned int,
913 void *, unsigned int);
914 static int parse_boolean(struct context *, const struct token *,
915 const char *, unsigned int,
916 void *, unsigned int);
917 static int parse_string(struct context *, const struct token *,
918 const char *, unsigned int,
919 void *, unsigned int);
920 static int parse_mac_addr(struct context *, const struct token *,
921 const char *, unsigned int,
922 void *, unsigned int);
923 static int parse_ipv4_addr(struct context *, const struct token *,
924 const char *, unsigned int,
925 void *, unsigned int);
926 static int parse_ipv6_addr(struct context *, const struct token *,
927 const char *, unsigned int,
928 void *, unsigned int);
929 static int parse_port(struct context *, const struct token *,
930 const char *, unsigned int,
931 void *, unsigned int);
932 static int comp_none(struct context *, const struct token *,
933 unsigned int, char *, unsigned int);
934 static int comp_boolean(struct context *, const struct token *,
935 unsigned int, char *, unsigned int);
936 static int comp_action(struct context *, const struct token *,
937 unsigned int, char *, unsigned int);
938 static int comp_port(struct context *, const struct token *,
939 unsigned int, char *, unsigned int);
940 static int comp_rule_id(struct context *, const struct token *,
941 unsigned int, char *, unsigned int);
942 static int comp_vc_action_rss_type(struct context *, const struct token *,
943 unsigned int, char *, unsigned int);
944 static int comp_vc_action_rss_queue(struct context *, const struct token *,
945 unsigned int, char *, unsigned int);
947 /** Token definitions. */
948 static const struct token token_list[] = {
949 /* Special tokens. */
952 .help = "null entry, abused as the entry point",
953 .next = NEXT(NEXT_ENTRY(FLOW)),
958 .help = "command may end here",
964 .help = "integer value",
969 .name = "{unsigned}",
971 .help = "unsigned integer value",
978 .help = "prefix length for bit-mask",
979 .call = parse_prefix,
985 .help = "any boolean value",
986 .call = parse_boolean,
987 .comp = comp_boolean,
992 .help = "fixed string",
993 .call = parse_string,
997 .name = "{MAC address}",
999 .help = "standard MAC address notation",
1000 .call = parse_mac_addr,
1004 .name = "{IPv4 address}",
1005 .type = "IPV4 ADDRESS",
1006 .help = "standard IPv4 address notation",
1007 .call = parse_ipv4_addr,
1011 .name = "{IPv6 address}",
1012 .type = "IPV6 ADDRESS",
1013 .help = "standard IPv6 address notation",
1014 .call = parse_ipv6_addr,
1018 .name = "{rule id}",
1020 .help = "rule identifier",
1022 .comp = comp_rule_id,
1025 .name = "{port_id}",
1027 .help = "port identifier",
1032 .name = "{group_id}",
1034 .help = "group identifier",
1038 [PRIORITY_LEVEL] = {
1041 .help = "priority level",
1045 /* Top-level command. */
1048 .type = "{command} {port_id} [{arg} [...]]",
1049 .help = "manage ingress/egress flow rules",
1050 .next = NEXT(NEXT_ENTRY
1060 /* Sub-level commands. */
1063 .help = "check whether a flow rule can be created",
1064 .next = NEXT(next_vc_attr, NEXT_ENTRY(PORT_ID)),
1065 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1070 .help = "create a flow rule",
1071 .next = NEXT(next_vc_attr, NEXT_ENTRY(PORT_ID)),
1072 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1077 .help = "destroy specific flow rules",
1078 .next = NEXT(NEXT_ENTRY(DESTROY_RULE), NEXT_ENTRY(PORT_ID)),
1079 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1080 .call = parse_destroy,
1084 .help = "destroy all flow rules",
1085 .next = NEXT(NEXT_ENTRY(PORT_ID)),
1086 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1087 .call = parse_flush,
1091 .help = "query an existing flow rule",
1092 .next = NEXT(NEXT_ENTRY(QUERY_ACTION),
1093 NEXT_ENTRY(RULE_ID),
1094 NEXT_ENTRY(PORT_ID)),
1095 .args = ARGS(ARGS_ENTRY(struct buffer, args.query.action),
1096 ARGS_ENTRY(struct buffer, args.query.rule),
1097 ARGS_ENTRY(struct buffer, port)),
1098 .call = parse_query,
1102 .help = "list existing flow rules",
1103 .next = NEXT(next_list_attr, NEXT_ENTRY(PORT_ID)),
1104 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1109 .help = "restrict ingress traffic to the defined flow rules",
1110 .next = NEXT(NEXT_ENTRY(BOOLEAN),
1111 NEXT_ENTRY(PORT_ID)),
1112 .args = ARGS(ARGS_ENTRY(struct buffer, args.isolate.set),
1113 ARGS_ENTRY(struct buffer, port)),
1114 .call = parse_isolate,
1116 /* Destroy arguments. */
1119 .help = "specify a rule identifier",
1120 .next = NEXT(next_destroy_attr, NEXT_ENTRY(RULE_ID)),
1121 .args = ARGS(ARGS_ENTRY_PTR(struct buffer, args.destroy.rule)),
1122 .call = parse_destroy,
1124 /* Query arguments. */
1128 .help = "action to query, must be part of the rule",
1129 .call = parse_action,
1130 .comp = comp_action,
1132 /* List arguments. */
1135 .help = "specify a group",
1136 .next = NEXT(next_list_attr, NEXT_ENTRY(GROUP_ID)),
1137 .args = ARGS(ARGS_ENTRY_PTR(struct buffer, args.list.group)),
1140 /* Validate/create attributes. */
1143 .help = "specify a group",
1144 .next = NEXT(next_vc_attr, NEXT_ENTRY(GROUP_ID)),
1145 .args = ARGS(ARGS_ENTRY(struct rte_flow_attr, group)),
1150 .help = "specify a priority level",
1151 .next = NEXT(next_vc_attr, NEXT_ENTRY(PRIORITY_LEVEL)),
1152 .args = ARGS(ARGS_ENTRY(struct rte_flow_attr, priority)),
1157 .help = "affect rule to ingress",
1158 .next = NEXT(next_vc_attr),
1163 .help = "affect rule to egress",
1164 .next = NEXT(next_vc_attr),
1169 .help = "apply rule directly to endpoints found in pattern",
1170 .next = NEXT(next_vc_attr),
1173 /* Validate/create pattern. */
1176 .help = "submit a list of pattern items",
1177 .next = NEXT(next_item),
1182 .help = "match value perfectly (with full bit-mask)",
1183 .call = parse_vc_spec,
1185 [ITEM_PARAM_SPEC] = {
1187 .help = "match value according to configured bit-mask",
1188 .call = parse_vc_spec,
1190 [ITEM_PARAM_LAST] = {
1192 .help = "specify upper bound to establish a range",
1193 .call = parse_vc_spec,
1195 [ITEM_PARAM_MASK] = {
1197 .help = "specify bit-mask with relevant bits set to one",
1198 .call = parse_vc_spec,
1200 [ITEM_PARAM_PREFIX] = {
1202 .help = "generate bit-mask from a prefix length",
1203 .call = parse_vc_spec,
1207 .help = "specify next pattern item",
1208 .next = NEXT(next_item),
1212 .help = "end list of pattern items",
1213 .priv = PRIV_ITEM(END, 0),
1214 .next = NEXT(NEXT_ENTRY(ACTIONS)),
1219 .help = "no-op pattern item",
1220 .priv = PRIV_ITEM(VOID, 0),
1221 .next = NEXT(NEXT_ENTRY(ITEM_NEXT)),
1226 .help = "perform actions when pattern does not match",
1227 .priv = PRIV_ITEM(INVERT, 0),
1228 .next = NEXT(NEXT_ENTRY(ITEM_NEXT)),
1233 .help = "match any protocol for the current layer",
1234 .priv = PRIV_ITEM(ANY, sizeof(struct rte_flow_item_any)),
1235 .next = NEXT(item_any),
1240 .help = "number of layers covered",
1241 .next = NEXT(item_any, NEXT_ENTRY(UNSIGNED), item_param),
1242 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_any, num)),
1246 .help = "match traffic from/to the physical function",
1247 .priv = PRIV_ITEM(PF, 0),
1248 .next = NEXT(NEXT_ENTRY(ITEM_NEXT)),
1253 .help = "match traffic from/to a virtual function ID",
1254 .priv = PRIV_ITEM(VF, sizeof(struct rte_flow_item_vf)),
1255 .next = NEXT(item_vf),
1261 .next = NEXT(item_vf, NEXT_ENTRY(UNSIGNED), item_param),
1262 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_vf, id)),
1266 .help = "match traffic from/to a specific physical port",
1267 .priv = PRIV_ITEM(PHY_PORT,
1268 sizeof(struct rte_flow_item_phy_port)),
1269 .next = NEXT(item_phy_port),
1272 [ITEM_PHY_PORT_INDEX] = {
1274 .help = "physical port index",
1275 .next = NEXT(item_phy_port, NEXT_ENTRY(UNSIGNED), item_param),
1276 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_phy_port, index)),
1280 .help = "match traffic from/to a given DPDK port ID",
1281 .priv = PRIV_ITEM(PORT_ID,
1282 sizeof(struct rte_flow_item_port_id)),
1283 .next = NEXT(item_port_id),
1286 [ITEM_PORT_ID_ID] = {
1288 .help = "DPDK port ID",
1289 .next = NEXT(item_port_id, NEXT_ENTRY(UNSIGNED), item_param),
1290 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_port_id, id)),
1294 .help = "match an arbitrary byte string",
1295 .priv = PRIV_ITEM(RAW, ITEM_RAW_SIZE),
1296 .next = NEXT(item_raw),
1299 [ITEM_RAW_RELATIVE] = {
1301 .help = "look for pattern after the previous item",
1302 .next = NEXT(item_raw, NEXT_ENTRY(BOOLEAN), item_param),
1303 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_item_raw,
1306 [ITEM_RAW_SEARCH] = {
1308 .help = "search pattern from offset (see also limit)",
1309 .next = NEXT(item_raw, NEXT_ENTRY(BOOLEAN), item_param),
1310 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_item_raw,
1313 [ITEM_RAW_OFFSET] = {
1315 .help = "absolute or relative offset for pattern",
1316 .next = NEXT(item_raw, NEXT_ENTRY(INTEGER), item_param),
1317 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_raw, offset)),
1319 [ITEM_RAW_LIMIT] = {
1321 .help = "search area limit for start of pattern",
1322 .next = NEXT(item_raw, NEXT_ENTRY(UNSIGNED), item_param),
1323 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_raw, limit)),
1325 [ITEM_RAW_PATTERN] = {
1327 .help = "byte string to look for",
1328 .next = NEXT(item_raw,
1330 NEXT_ENTRY(ITEM_PARAM_IS,
1333 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_raw, pattern),
1334 ARGS_ENTRY(struct rte_flow_item_raw, length),
1335 ARGS_ENTRY_ARB(sizeof(struct rte_flow_item_raw),
1336 ITEM_RAW_PATTERN_SIZE)),
1340 .help = "match Ethernet header",
1341 .priv = PRIV_ITEM(ETH, sizeof(struct rte_flow_item_eth)),
1342 .next = NEXT(item_eth),
1347 .help = "destination MAC",
1348 .next = NEXT(item_eth, NEXT_ENTRY(MAC_ADDR), item_param),
1349 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_eth, dst)),
1353 .help = "source MAC",
1354 .next = NEXT(item_eth, NEXT_ENTRY(MAC_ADDR), item_param),
1355 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_eth, src)),
1359 .help = "EtherType",
1360 .next = NEXT(item_eth, NEXT_ENTRY(UNSIGNED), item_param),
1361 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_eth, type)),
1365 .help = "match 802.1Q/ad VLAN tag",
1366 .priv = PRIV_ITEM(VLAN, sizeof(struct rte_flow_item_vlan)),
1367 .next = NEXT(item_vlan),
1372 .help = "tag control information",
1373 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1374 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vlan, tci)),
1378 .help = "priority code point",
1379 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1380 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_vlan,
1385 .help = "drop eligible indicator",
1386 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1387 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_vlan,
1392 .help = "VLAN identifier",
1393 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1394 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_vlan,
1397 [ITEM_VLAN_INNER_TYPE] = {
1398 .name = "inner_type",
1399 .help = "inner EtherType",
1400 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1401 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vlan,
1406 .help = "match IPv4 header",
1407 .priv = PRIV_ITEM(IPV4, sizeof(struct rte_flow_item_ipv4)),
1408 .next = NEXT(item_ipv4),
1413 .help = "type of service",
1414 .next = NEXT(item_ipv4, NEXT_ENTRY(UNSIGNED), item_param),
1415 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
1416 hdr.type_of_service)),
1420 .help = "time to live",
1421 .next = NEXT(item_ipv4, NEXT_ENTRY(UNSIGNED), item_param),
1422 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
1425 [ITEM_IPV4_PROTO] = {
1427 .help = "next protocol ID",
1428 .next = NEXT(item_ipv4, NEXT_ENTRY(UNSIGNED), item_param),
1429 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
1430 hdr.next_proto_id)),
1434 .help = "source address",
1435 .next = NEXT(item_ipv4, NEXT_ENTRY(IPV4_ADDR), item_param),
1436 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
1441 .help = "destination address",
1442 .next = NEXT(item_ipv4, NEXT_ENTRY(IPV4_ADDR), item_param),
1443 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
1448 .help = "match IPv6 header",
1449 .priv = PRIV_ITEM(IPV6, sizeof(struct rte_flow_item_ipv6)),
1450 .next = NEXT(item_ipv6),
1455 .help = "traffic class",
1456 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
1457 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_ipv6,
1459 "\x0f\xf0\x00\x00")),
1461 [ITEM_IPV6_FLOW] = {
1463 .help = "flow label",
1464 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
1465 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_ipv6,
1467 "\x00\x0f\xff\xff")),
1469 [ITEM_IPV6_PROTO] = {
1471 .help = "protocol (next header)",
1472 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
1473 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
1478 .help = "hop limit",
1479 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
1480 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
1485 .help = "source address",
1486 .next = NEXT(item_ipv6, NEXT_ENTRY(IPV6_ADDR), item_param),
1487 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
1492 .help = "destination address",
1493 .next = NEXT(item_ipv6, NEXT_ENTRY(IPV6_ADDR), item_param),
1494 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
1499 .help = "match ICMP header",
1500 .priv = PRIV_ITEM(ICMP, sizeof(struct rte_flow_item_icmp)),
1501 .next = NEXT(item_icmp),
1504 [ITEM_ICMP_TYPE] = {
1506 .help = "ICMP packet type",
1507 .next = NEXT(item_icmp, NEXT_ENTRY(UNSIGNED), item_param),
1508 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp,
1511 [ITEM_ICMP_CODE] = {
1513 .help = "ICMP packet code",
1514 .next = NEXT(item_icmp, NEXT_ENTRY(UNSIGNED), item_param),
1515 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp,
1520 .help = "match UDP header",
1521 .priv = PRIV_ITEM(UDP, sizeof(struct rte_flow_item_udp)),
1522 .next = NEXT(item_udp),
1527 .help = "UDP source port",
1528 .next = NEXT(item_udp, NEXT_ENTRY(UNSIGNED), item_param),
1529 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_udp,
1534 .help = "UDP destination port",
1535 .next = NEXT(item_udp, NEXT_ENTRY(UNSIGNED), item_param),
1536 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_udp,
1541 .help = "match TCP header",
1542 .priv = PRIV_ITEM(TCP, sizeof(struct rte_flow_item_tcp)),
1543 .next = NEXT(item_tcp),
1548 .help = "TCP source port",
1549 .next = NEXT(item_tcp, NEXT_ENTRY(UNSIGNED), item_param),
1550 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_tcp,
1555 .help = "TCP destination port",
1556 .next = NEXT(item_tcp, NEXT_ENTRY(UNSIGNED), item_param),
1557 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_tcp,
1560 [ITEM_TCP_FLAGS] = {
1562 .help = "TCP flags",
1563 .next = NEXT(item_tcp, NEXT_ENTRY(UNSIGNED), item_param),
1564 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_tcp,
1569 .help = "match SCTP header",
1570 .priv = PRIV_ITEM(SCTP, sizeof(struct rte_flow_item_sctp)),
1571 .next = NEXT(item_sctp),
1576 .help = "SCTP source port",
1577 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
1578 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
1583 .help = "SCTP destination port",
1584 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
1585 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
1590 .help = "validation tag",
1591 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
1592 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
1595 [ITEM_SCTP_CKSUM] = {
1598 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
1599 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
1604 .help = "match VXLAN header",
1605 .priv = PRIV_ITEM(VXLAN, sizeof(struct rte_flow_item_vxlan)),
1606 .next = NEXT(item_vxlan),
1609 [ITEM_VXLAN_VNI] = {
1611 .help = "VXLAN identifier",
1612 .next = NEXT(item_vxlan, NEXT_ENTRY(UNSIGNED), item_param),
1613 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vxlan, vni)),
1617 .help = "match E-Tag header",
1618 .priv = PRIV_ITEM(E_TAG, sizeof(struct rte_flow_item_e_tag)),
1619 .next = NEXT(item_e_tag),
1622 [ITEM_E_TAG_GRP_ECID_B] = {
1623 .name = "grp_ecid_b",
1624 .help = "GRP and E-CID base",
1625 .next = NEXT(item_e_tag, NEXT_ENTRY(UNSIGNED), item_param),
1626 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_e_tag,
1632 .help = "match NVGRE header",
1633 .priv = PRIV_ITEM(NVGRE, sizeof(struct rte_flow_item_nvgre)),
1634 .next = NEXT(item_nvgre),
1637 [ITEM_NVGRE_TNI] = {
1639 .help = "virtual subnet ID",
1640 .next = NEXT(item_nvgre, NEXT_ENTRY(UNSIGNED), item_param),
1641 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_nvgre, tni)),
1645 .help = "match MPLS header",
1646 .priv = PRIV_ITEM(MPLS, sizeof(struct rte_flow_item_mpls)),
1647 .next = NEXT(item_mpls),
1650 [ITEM_MPLS_LABEL] = {
1652 .help = "MPLS label",
1653 .next = NEXT(item_mpls, NEXT_ENTRY(UNSIGNED), item_param),
1654 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_mpls,
1660 .help = "match GRE header",
1661 .priv = PRIV_ITEM(GRE, sizeof(struct rte_flow_item_gre)),
1662 .next = NEXT(item_gre),
1665 [ITEM_GRE_PROTO] = {
1667 .help = "GRE protocol type",
1668 .next = NEXT(item_gre, NEXT_ENTRY(UNSIGNED), item_param),
1669 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gre,
1674 .help = "fuzzy pattern match, expect faster than default",
1675 .priv = PRIV_ITEM(FUZZY,
1676 sizeof(struct rte_flow_item_fuzzy)),
1677 .next = NEXT(item_fuzzy),
1680 [ITEM_FUZZY_THRESH] = {
1682 .help = "match accuracy threshold",
1683 .next = NEXT(item_fuzzy, NEXT_ENTRY(UNSIGNED), item_param),
1684 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_fuzzy,
1689 .help = "match GTP header",
1690 .priv = PRIV_ITEM(GTP, sizeof(struct rte_flow_item_gtp)),
1691 .next = NEXT(item_gtp),
1696 .help = "tunnel endpoint identifier",
1697 .next = NEXT(item_gtp, NEXT_ENTRY(UNSIGNED), item_param),
1698 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gtp, teid)),
1702 .help = "match GTP header",
1703 .priv = PRIV_ITEM(GTPC, sizeof(struct rte_flow_item_gtp)),
1704 .next = NEXT(item_gtp),
1709 .help = "match GTP header",
1710 .priv = PRIV_ITEM(GTPU, sizeof(struct rte_flow_item_gtp)),
1711 .next = NEXT(item_gtp),
1716 .help = "match GENEVE header",
1717 .priv = PRIV_ITEM(GENEVE, sizeof(struct rte_flow_item_geneve)),
1718 .next = NEXT(item_geneve),
1721 [ITEM_GENEVE_VNI] = {
1723 .help = "virtual network identifier",
1724 .next = NEXT(item_geneve, NEXT_ENTRY(UNSIGNED), item_param),
1725 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_geneve, vni)),
1727 [ITEM_GENEVE_PROTO] = {
1729 .help = "GENEVE protocol type",
1730 .next = NEXT(item_geneve, NEXT_ENTRY(UNSIGNED), item_param),
1731 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_geneve,
1734 [ITEM_VXLAN_GPE] = {
1735 .name = "vxlan-gpe",
1736 .help = "match VXLAN-GPE header",
1737 .priv = PRIV_ITEM(VXLAN_GPE,
1738 sizeof(struct rte_flow_item_vxlan_gpe)),
1739 .next = NEXT(item_vxlan_gpe),
1742 [ITEM_VXLAN_GPE_VNI] = {
1744 .help = "VXLAN-GPE identifier",
1745 .next = NEXT(item_vxlan_gpe, NEXT_ENTRY(UNSIGNED), item_param),
1746 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vxlan_gpe,
1749 [ITEM_ARP_ETH_IPV4] = {
1750 .name = "arp_eth_ipv4",
1751 .help = "match ARP header for Ethernet/IPv4",
1752 .priv = PRIV_ITEM(ARP_ETH_IPV4,
1753 sizeof(struct rte_flow_item_arp_eth_ipv4)),
1754 .next = NEXT(item_arp_eth_ipv4),
1757 [ITEM_ARP_ETH_IPV4_SHA] = {
1759 .help = "sender hardware address",
1760 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(MAC_ADDR),
1762 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
1765 [ITEM_ARP_ETH_IPV4_SPA] = {
1767 .help = "sender IPv4 address",
1768 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(IPV4_ADDR),
1770 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
1773 [ITEM_ARP_ETH_IPV4_THA] = {
1775 .help = "target hardware address",
1776 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(MAC_ADDR),
1778 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
1781 [ITEM_ARP_ETH_IPV4_TPA] = {
1783 .help = "target IPv4 address",
1784 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(IPV4_ADDR),
1786 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
1791 .help = "match presence of any IPv6 extension header",
1792 .priv = PRIV_ITEM(IPV6_EXT,
1793 sizeof(struct rte_flow_item_ipv6_ext)),
1794 .next = NEXT(item_ipv6_ext),
1797 [ITEM_IPV6_EXT_NEXT_HDR] = {
1799 .help = "next header",
1800 .next = NEXT(item_ipv6_ext, NEXT_ENTRY(UNSIGNED), item_param),
1801 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6_ext,
1806 .help = "match any ICMPv6 header",
1807 .priv = PRIV_ITEM(ICMP6, sizeof(struct rte_flow_item_icmp6)),
1808 .next = NEXT(item_icmp6),
1811 [ITEM_ICMP6_TYPE] = {
1813 .help = "ICMPv6 type",
1814 .next = NEXT(item_icmp6, NEXT_ENTRY(UNSIGNED), item_param),
1815 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6,
1818 [ITEM_ICMP6_CODE] = {
1820 .help = "ICMPv6 code",
1821 .next = NEXT(item_icmp6, NEXT_ENTRY(UNSIGNED), item_param),
1822 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6,
1825 [ITEM_ICMP6_ND_NS] = {
1826 .name = "icmp6_nd_ns",
1827 .help = "match ICMPv6 neighbor discovery solicitation",
1828 .priv = PRIV_ITEM(ICMP6_ND_NS,
1829 sizeof(struct rte_flow_item_icmp6_nd_ns)),
1830 .next = NEXT(item_icmp6_nd_ns),
1833 [ITEM_ICMP6_ND_NS_TARGET_ADDR] = {
1834 .name = "target_addr",
1835 .help = "target address",
1836 .next = NEXT(item_icmp6_nd_ns, NEXT_ENTRY(IPV6_ADDR),
1838 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6_nd_ns,
1841 [ITEM_ICMP6_ND_NA] = {
1842 .name = "icmp6_nd_na",
1843 .help = "match ICMPv6 neighbor discovery advertisement",
1844 .priv = PRIV_ITEM(ICMP6_ND_NA,
1845 sizeof(struct rte_flow_item_icmp6_nd_na)),
1846 .next = NEXT(item_icmp6_nd_na),
1849 [ITEM_ICMP6_ND_NA_TARGET_ADDR] = {
1850 .name = "target_addr",
1851 .help = "target address",
1852 .next = NEXT(item_icmp6_nd_na, NEXT_ENTRY(IPV6_ADDR),
1854 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6_nd_na,
1857 [ITEM_ICMP6_ND_OPT] = {
1858 .name = "icmp6_nd_opt",
1859 .help = "match presence of any ICMPv6 neighbor discovery"
1861 .priv = PRIV_ITEM(ICMP6_ND_OPT,
1862 sizeof(struct rte_flow_item_icmp6_nd_opt)),
1863 .next = NEXT(item_icmp6_nd_opt),
1866 [ITEM_ICMP6_ND_OPT_TYPE] = {
1868 .help = "ND option type",
1869 .next = NEXT(item_icmp6_nd_opt, NEXT_ENTRY(UNSIGNED),
1871 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6_nd_opt,
1874 [ITEM_ICMP6_ND_OPT_SLA_ETH] = {
1875 .name = "icmp6_nd_opt_sla_eth",
1876 .help = "match ICMPv6 neighbor discovery source Ethernet"
1877 " link-layer address option",
1879 (ICMP6_ND_OPT_SLA_ETH,
1880 sizeof(struct rte_flow_item_icmp6_nd_opt_sla_eth)),
1881 .next = NEXT(item_icmp6_nd_opt_sla_eth),
1884 [ITEM_ICMP6_ND_OPT_SLA_ETH_SLA] = {
1886 .help = "source Ethernet LLA",
1887 .next = NEXT(item_icmp6_nd_opt_sla_eth, NEXT_ENTRY(MAC_ADDR),
1889 .args = ARGS(ARGS_ENTRY_HTON
1890 (struct rte_flow_item_icmp6_nd_opt_sla_eth, sla)),
1892 [ITEM_ICMP6_ND_OPT_TLA_ETH] = {
1893 .name = "icmp6_nd_opt_tla_eth",
1894 .help = "match ICMPv6 neighbor discovery target Ethernet"
1895 " link-layer address option",
1897 (ICMP6_ND_OPT_TLA_ETH,
1898 sizeof(struct rte_flow_item_icmp6_nd_opt_tla_eth)),
1899 .next = NEXT(item_icmp6_nd_opt_tla_eth),
1902 [ITEM_ICMP6_ND_OPT_TLA_ETH_TLA] = {
1904 .help = "target Ethernet LLA",
1905 .next = NEXT(item_icmp6_nd_opt_tla_eth, NEXT_ENTRY(MAC_ADDR),
1907 .args = ARGS(ARGS_ENTRY_HTON
1908 (struct rte_flow_item_icmp6_nd_opt_tla_eth, tla)),
1911 /* Validate/create actions. */
1914 .help = "submit a list of associated actions",
1915 .next = NEXT(next_action),
1920 .help = "specify next action",
1921 .next = NEXT(next_action),
1925 .help = "end list of actions",
1926 .priv = PRIV_ACTION(END, 0),
1931 .help = "no-op action",
1932 .priv = PRIV_ACTION(VOID, 0),
1933 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
1936 [ACTION_PASSTHRU] = {
1938 .help = "let subsequent rule process matched packets",
1939 .priv = PRIV_ACTION(PASSTHRU, 0),
1940 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
1945 .help = "redirect traffic to a given group",
1946 .priv = PRIV_ACTION(JUMP, sizeof(struct rte_flow_action_jump)),
1947 .next = NEXT(action_jump),
1950 [ACTION_JUMP_GROUP] = {
1952 .help = "group to redirect traffic to",
1953 .next = NEXT(action_jump, NEXT_ENTRY(UNSIGNED)),
1954 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_jump, group)),
1955 .call = parse_vc_conf,
1959 .help = "attach 32 bit value to packets",
1960 .priv = PRIV_ACTION(MARK, sizeof(struct rte_flow_action_mark)),
1961 .next = NEXT(action_mark),
1964 [ACTION_MARK_ID] = {
1966 .help = "32 bit value to return with packets",
1967 .next = NEXT(action_mark, NEXT_ENTRY(UNSIGNED)),
1968 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_mark, id)),
1969 .call = parse_vc_conf,
1973 .help = "flag packets",
1974 .priv = PRIV_ACTION(FLAG, 0),
1975 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
1980 .help = "assign packets to a given queue index",
1981 .priv = PRIV_ACTION(QUEUE,
1982 sizeof(struct rte_flow_action_queue)),
1983 .next = NEXT(action_queue),
1986 [ACTION_QUEUE_INDEX] = {
1988 .help = "queue index to use",
1989 .next = NEXT(action_queue, NEXT_ENTRY(UNSIGNED)),
1990 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_queue, index)),
1991 .call = parse_vc_conf,
1995 .help = "drop packets (note: passthru has priority)",
1996 .priv = PRIV_ACTION(DROP, 0),
1997 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2002 .help = "enable counters for this rule",
2003 .priv = PRIV_ACTION(COUNT, 0),
2004 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2009 .help = "spread packets among several queues",
2010 .priv = PRIV_ACTION(RSS, sizeof(struct action_rss_data)),
2011 .next = NEXT(action_rss),
2012 .call = parse_vc_action_rss,
2014 [ACTION_RSS_FUNC] = {
2016 .help = "RSS hash function to apply",
2017 .next = NEXT(action_rss,
2018 NEXT_ENTRY(ACTION_RSS_FUNC_DEFAULT,
2019 ACTION_RSS_FUNC_TOEPLITZ,
2020 ACTION_RSS_FUNC_SIMPLE_XOR)),
2022 [ACTION_RSS_FUNC_DEFAULT] = {
2024 .help = "default hash function",
2025 .call = parse_vc_action_rss_func,
2027 [ACTION_RSS_FUNC_TOEPLITZ] = {
2029 .help = "Toeplitz hash function",
2030 .call = parse_vc_action_rss_func,
2032 [ACTION_RSS_FUNC_SIMPLE_XOR] = {
2033 .name = "simple_xor",
2034 .help = "simple XOR hash function",
2035 .call = parse_vc_action_rss_func,
2037 [ACTION_RSS_LEVEL] = {
2039 .help = "encapsulation level for \"types\"",
2040 .next = NEXT(action_rss, NEXT_ENTRY(UNSIGNED)),
2041 .args = ARGS(ARGS_ENTRY_ARB
2042 (offsetof(struct action_rss_data, conf) +
2043 offsetof(struct rte_flow_action_rss, level),
2044 sizeof(((struct rte_flow_action_rss *)0)->
2047 [ACTION_RSS_TYPES] = {
2049 .help = "specific RSS hash types",
2050 .next = NEXT(action_rss, NEXT_ENTRY(ACTION_RSS_TYPE)),
2052 [ACTION_RSS_TYPE] = {
2054 .help = "RSS hash type",
2055 .call = parse_vc_action_rss_type,
2056 .comp = comp_vc_action_rss_type,
2058 [ACTION_RSS_KEY] = {
2060 .help = "RSS hash key",
2061 .next = NEXT(action_rss, NEXT_ENTRY(STRING)),
2062 .args = ARGS(ARGS_ENTRY_ARB(0, 0),
2064 (offsetof(struct action_rss_data, conf) +
2065 offsetof(struct rte_flow_action_rss, key_len),
2066 sizeof(((struct rte_flow_action_rss *)0)->
2068 ARGS_ENTRY(struct action_rss_data, key)),
2070 [ACTION_RSS_KEY_LEN] = {
2072 .help = "RSS hash key length in bytes",
2073 .next = NEXT(action_rss, NEXT_ENTRY(UNSIGNED)),
2074 .args = ARGS(ARGS_ENTRY_ARB_BOUNDED
2075 (offsetof(struct action_rss_data, conf) +
2076 offsetof(struct rte_flow_action_rss, key_len),
2077 sizeof(((struct rte_flow_action_rss *)0)->
2080 RSS_HASH_KEY_LENGTH)),
2082 [ACTION_RSS_QUEUES] = {
2084 .help = "queue indices to use",
2085 .next = NEXT(action_rss, NEXT_ENTRY(ACTION_RSS_QUEUE)),
2086 .call = parse_vc_conf,
2088 [ACTION_RSS_QUEUE] = {
2090 .help = "queue index",
2091 .call = parse_vc_action_rss_queue,
2092 .comp = comp_vc_action_rss_queue,
2096 .help = "direct traffic to physical function",
2097 .priv = PRIV_ACTION(PF, 0),
2098 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2103 .help = "direct traffic to a virtual function ID",
2104 .priv = PRIV_ACTION(VF, sizeof(struct rte_flow_action_vf)),
2105 .next = NEXT(action_vf),
2108 [ACTION_VF_ORIGINAL] = {
2110 .help = "use original VF ID if possible",
2111 .next = NEXT(action_vf, NEXT_ENTRY(BOOLEAN)),
2112 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_vf,
2114 .call = parse_vc_conf,
2119 .next = NEXT(action_vf, NEXT_ENTRY(UNSIGNED)),
2120 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_vf, id)),
2121 .call = parse_vc_conf,
2123 [ACTION_PHY_PORT] = {
2125 .help = "direct packets to physical port index",
2126 .priv = PRIV_ACTION(PHY_PORT,
2127 sizeof(struct rte_flow_action_phy_port)),
2128 .next = NEXT(action_phy_port),
2131 [ACTION_PHY_PORT_ORIGINAL] = {
2133 .help = "use original port index if possible",
2134 .next = NEXT(action_phy_port, NEXT_ENTRY(BOOLEAN)),
2135 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_phy_port,
2137 .call = parse_vc_conf,
2139 [ACTION_PHY_PORT_INDEX] = {
2141 .help = "physical port index",
2142 .next = NEXT(action_phy_port, NEXT_ENTRY(UNSIGNED)),
2143 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_phy_port,
2145 .call = parse_vc_conf,
2147 [ACTION_PORT_ID] = {
2149 .help = "direct matching traffic to a given DPDK port ID",
2150 .priv = PRIV_ACTION(PORT_ID,
2151 sizeof(struct rte_flow_action_port_id)),
2152 .next = NEXT(action_port_id),
2155 [ACTION_PORT_ID_ORIGINAL] = {
2157 .help = "use original DPDK port ID if possible",
2158 .next = NEXT(action_port_id, NEXT_ENTRY(BOOLEAN)),
2159 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_port_id,
2161 .call = parse_vc_conf,
2163 [ACTION_PORT_ID_ID] = {
2165 .help = "DPDK port ID",
2166 .next = NEXT(action_port_id, NEXT_ENTRY(UNSIGNED)),
2167 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_port_id, id)),
2168 .call = parse_vc_conf,
2172 .help = "meter the directed packets at given id",
2173 .priv = PRIV_ACTION(METER,
2174 sizeof(struct rte_flow_action_meter)),
2175 .next = NEXT(action_meter),
2178 [ACTION_METER_ID] = {
2180 .help = "meter id to use",
2181 .next = NEXT(action_meter, NEXT_ENTRY(UNSIGNED)),
2182 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_meter, mtr_id)),
2183 .call = parse_vc_conf,
2185 [ACTION_OF_SET_MPLS_TTL] = {
2186 .name = "of_set_mpls_ttl",
2187 .help = "OpenFlow's OFPAT_SET_MPLS_TTL",
2190 sizeof(struct rte_flow_action_of_set_mpls_ttl)),
2191 .next = NEXT(action_of_set_mpls_ttl),
2194 [ACTION_OF_SET_MPLS_TTL_MPLS_TTL] = {
2197 .next = NEXT(action_of_set_mpls_ttl, NEXT_ENTRY(UNSIGNED)),
2198 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_of_set_mpls_ttl,
2200 .call = parse_vc_conf,
2202 [ACTION_OF_DEC_MPLS_TTL] = {
2203 .name = "of_dec_mpls_ttl",
2204 .help = "OpenFlow's OFPAT_DEC_MPLS_TTL",
2205 .priv = PRIV_ACTION(OF_DEC_MPLS_TTL, 0),
2206 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2209 [ACTION_OF_SET_NW_TTL] = {
2210 .name = "of_set_nw_ttl",
2211 .help = "OpenFlow's OFPAT_SET_NW_TTL",
2214 sizeof(struct rte_flow_action_of_set_nw_ttl)),
2215 .next = NEXT(action_of_set_nw_ttl),
2218 [ACTION_OF_SET_NW_TTL_NW_TTL] = {
2221 .next = NEXT(action_of_set_nw_ttl, NEXT_ENTRY(UNSIGNED)),
2222 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_of_set_nw_ttl,
2224 .call = parse_vc_conf,
2226 [ACTION_OF_DEC_NW_TTL] = {
2227 .name = "of_dec_nw_ttl",
2228 .help = "OpenFlow's OFPAT_DEC_NW_TTL",
2229 .priv = PRIV_ACTION(OF_DEC_NW_TTL, 0),
2230 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2233 [ACTION_OF_COPY_TTL_OUT] = {
2234 .name = "of_copy_ttl_out",
2235 .help = "OpenFlow's OFPAT_COPY_TTL_OUT",
2236 .priv = PRIV_ACTION(OF_COPY_TTL_OUT, 0),
2237 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2240 [ACTION_OF_COPY_TTL_IN] = {
2241 .name = "of_copy_ttl_in",
2242 .help = "OpenFlow's OFPAT_COPY_TTL_IN",
2243 .priv = PRIV_ACTION(OF_COPY_TTL_IN, 0),
2244 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2247 [ACTION_OF_POP_VLAN] = {
2248 .name = "of_pop_vlan",
2249 .help = "OpenFlow's OFPAT_POP_VLAN",
2250 .priv = PRIV_ACTION(OF_POP_VLAN, 0),
2251 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2254 [ACTION_OF_PUSH_VLAN] = {
2255 .name = "of_push_vlan",
2256 .help = "OpenFlow's OFPAT_PUSH_VLAN",
2259 sizeof(struct rte_flow_action_of_push_vlan)),
2260 .next = NEXT(action_of_push_vlan),
2263 [ACTION_OF_PUSH_VLAN_ETHERTYPE] = {
2264 .name = "ethertype",
2265 .help = "EtherType",
2266 .next = NEXT(action_of_push_vlan, NEXT_ENTRY(UNSIGNED)),
2267 .args = ARGS(ARGS_ENTRY_HTON
2268 (struct rte_flow_action_of_push_vlan,
2270 .call = parse_vc_conf,
2272 [ACTION_OF_SET_VLAN_VID] = {
2273 .name = "of_set_vlan_vid",
2274 .help = "OpenFlow's OFPAT_SET_VLAN_VID",
2277 sizeof(struct rte_flow_action_of_set_vlan_vid)),
2278 .next = NEXT(action_of_set_vlan_vid),
2281 [ACTION_OF_SET_VLAN_VID_VLAN_VID] = {
2284 .next = NEXT(action_of_set_vlan_vid, NEXT_ENTRY(UNSIGNED)),
2285 .args = ARGS(ARGS_ENTRY_HTON
2286 (struct rte_flow_action_of_set_vlan_vid,
2288 .call = parse_vc_conf,
2290 [ACTION_OF_SET_VLAN_PCP] = {
2291 .name = "of_set_vlan_pcp",
2292 .help = "OpenFlow's OFPAT_SET_VLAN_PCP",
2295 sizeof(struct rte_flow_action_of_set_vlan_pcp)),
2296 .next = NEXT(action_of_set_vlan_pcp),
2299 [ACTION_OF_SET_VLAN_PCP_VLAN_PCP] = {
2301 .help = "VLAN priority",
2302 .next = NEXT(action_of_set_vlan_pcp, NEXT_ENTRY(UNSIGNED)),
2303 .args = ARGS(ARGS_ENTRY_HTON
2304 (struct rte_flow_action_of_set_vlan_pcp,
2306 .call = parse_vc_conf,
2308 [ACTION_OF_POP_MPLS] = {
2309 .name = "of_pop_mpls",
2310 .help = "OpenFlow's OFPAT_POP_MPLS",
2311 .priv = PRIV_ACTION(OF_POP_MPLS,
2312 sizeof(struct rte_flow_action_of_pop_mpls)),
2313 .next = NEXT(action_of_pop_mpls),
2316 [ACTION_OF_POP_MPLS_ETHERTYPE] = {
2317 .name = "ethertype",
2318 .help = "EtherType",
2319 .next = NEXT(action_of_pop_mpls, NEXT_ENTRY(UNSIGNED)),
2320 .args = ARGS(ARGS_ENTRY_HTON
2321 (struct rte_flow_action_of_pop_mpls,
2323 .call = parse_vc_conf,
2325 [ACTION_OF_PUSH_MPLS] = {
2326 .name = "of_push_mpls",
2327 .help = "OpenFlow's OFPAT_PUSH_MPLS",
2330 sizeof(struct rte_flow_action_of_push_mpls)),
2331 .next = NEXT(action_of_push_mpls),
2334 [ACTION_OF_PUSH_MPLS_ETHERTYPE] = {
2335 .name = "ethertype",
2336 .help = "EtherType",
2337 .next = NEXT(action_of_push_mpls, NEXT_ENTRY(UNSIGNED)),
2338 .args = ARGS(ARGS_ENTRY_HTON
2339 (struct rte_flow_action_of_push_mpls,
2341 .call = parse_vc_conf,
2345 /** Remove and return last entry from argument stack. */
2346 static const struct arg *
2347 pop_args(struct context *ctx)
2349 return ctx->args_num ? ctx->args[--ctx->args_num] : NULL;
2352 /** Add entry on top of the argument stack. */
2354 push_args(struct context *ctx, const struct arg *arg)
2356 if (ctx->args_num == CTX_STACK_SIZE)
2358 ctx->args[ctx->args_num++] = arg;
2362 /** Spread value into buffer according to bit-mask. */
2364 arg_entry_bf_fill(void *dst, uintmax_t val, const struct arg *arg)
2366 uint32_t i = arg->size;
2374 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
2383 unsigned int shift = 0;
2384 uint8_t *buf = (uint8_t *)dst + arg->offset + (i -= sub);
2386 for (shift = 0; arg->mask[i] >> shift; ++shift) {
2387 if (!(arg->mask[i] & (1 << shift)))
2392 *buf &= ~(1 << shift);
2393 *buf |= (val & 1) << shift;
2401 /** Compare a string with a partial one of a given length. */
2403 strcmp_partial(const char *full, const char *partial, size_t partial_len)
2405 int r = strncmp(full, partial, partial_len);
2409 if (strlen(full) <= partial_len)
2411 return full[partial_len];
2415 * Parse a prefix length and generate a bit-mask.
2417 * Last argument (ctx->args) is retrieved to determine mask size, storage
2418 * location and whether the result must use network byte ordering.
2421 parse_prefix(struct context *ctx, const struct token *token,
2422 const char *str, unsigned int len,
2423 void *buf, unsigned int size)
2425 const struct arg *arg = pop_args(ctx);
2426 static const uint8_t conv[] = "\x00\x80\xc0\xe0\xf0\xf8\xfc\xfe\xff";
2433 /* Argument is expected. */
2437 u = strtoumax(str, &end, 0);
2438 if (errno || (size_t)(end - str) != len)
2443 extra = arg_entry_bf_fill(NULL, 0, arg);
2452 if (!arg_entry_bf_fill(ctx->object, v, arg) ||
2453 !arg_entry_bf_fill(ctx->objmask, -1, arg))
2460 if (bytes > size || bytes + !!extra > size)
2464 buf = (uint8_t *)ctx->object + arg->offset;
2465 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
2467 memset((uint8_t *)buf + size - bytes, 0xff, bytes);
2468 memset(buf, 0x00, size - bytes);
2470 ((uint8_t *)buf)[size - bytes - 1] = conv[extra];
2474 memset(buf, 0xff, bytes);
2475 memset((uint8_t *)buf + bytes, 0x00, size - bytes);
2477 ((uint8_t *)buf)[bytes] = conv[extra];
2480 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
2483 push_args(ctx, arg);
2487 /** Default parsing function for token name matching. */
2489 parse_default(struct context *ctx, const struct token *token,
2490 const char *str, unsigned int len,
2491 void *buf, unsigned int size)
2496 if (strcmp_partial(token->name, str, len))
2501 /** Parse flow command, initialize output buffer for subsequent tokens. */
2503 parse_init(struct context *ctx, const struct token *token,
2504 const char *str, unsigned int len,
2505 void *buf, unsigned int size)
2507 struct buffer *out = buf;
2509 /* Token name must match. */
2510 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
2512 /* Nothing else to do if there is no buffer. */
2515 /* Make sure buffer is large enough. */
2516 if (size < sizeof(*out))
2518 /* Initialize buffer. */
2519 memset(out, 0x00, sizeof(*out));
2520 memset((uint8_t *)out + sizeof(*out), 0x22, size - sizeof(*out));
2523 ctx->objmask = NULL;
2527 /** Parse tokens for validate/create commands. */
2529 parse_vc(struct context *ctx, const struct token *token,
2530 const char *str, unsigned int len,
2531 void *buf, unsigned int size)
2533 struct buffer *out = buf;
2537 /* Token name must match. */
2538 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
2540 /* Nothing else to do if there is no buffer. */
2543 if (!out->command) {
2544 if (ctx->curr != VALIDATE && ctx->curr != CREATE)
2546 if (sizeof(*out) > size)
2548 out->command = ctx->curr;
2551 ctx->objmask = NULL;
2552 out->args.vc.data = (uint8_t *)out + size;
2556 ctx->object = &out->args.vc.attr;
2557 ctx->objmask = NULL;
2558 switch (ctx->curr) {
2563 out->args.vc.attr.ingress = 1;
2566 out->args.vc.attr.egress = 1;
2569 out->args.vc.attr.transfer = 1;
2572 out->args.vc.pattern =
2573 (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
2575 ctx->object = out->args.vc.pattern;
2576 ctx->objmask = NULL;
2579 out->args.vc.actions =
2580 (void *)RTE_ALIGN_CEIL((uintptr_t)
2581 (out->args.vc.pattern +
2582 out->args.vc.pattern_n),
2584 ctx->object = out->args.vc.actions;
2585 ctx->objmask = NULL;
2592 if (!out->args.vc.actions) {
2593 const struct parse_item_priv *priv = token->priv;
2594 struct rte_flow_item *item =
2595 out->args.vc.pattern + out->args.vc.pattern_n;
2597 data_size = priv->size * 3; /* spec, last, mask */
2598 data = (void *)RTE_ALIGN_FLOOR((uintptr_t)
2599 (out->args.vc.data - data_size),
2601 if ((uint8_t *)item + sizeof(*item) > data)
2603 *item = (struct rte_flow_item){
2606 ++out->args.vc.pattern_n;
2608 ctx->objmask = NULL;
2610 const struct parse_action_priv *priv = token->priv;
2611 struct rte_flow_action *action =
2612 out->args.vc.actions + out->args.vc.actions_n;
2614 data_size = priv->size; /* configuration */
2615 data = (void *)RTE_ALIGN_FLOOR((uintptr_t)
2616 (out->args.vc.data - data_size),
2618 if ((uint8_t *)action + sizeof(*action) > data)
2620 *action = (struct rte_flow_action){
2622 .conf = data_size ? data : NULL,
2624 ++out->args.vc.actions_n;
2625 ctx->object = action;
2626 ctx->objmask = NULL;
2628 memset(data, 0, data_size);
2629 out->args.vc.data = data;
2630 ctx->objdata = data_size;
2634 /** Parse pattern item parameter type. */
2636 parse_vc_spec(struct context *ctx, const struct token *token,
2637 const char *str, unsigned int len,
2638 void *buf, unsigned int size)
2640 struct buffer *out = buf;
2641 struct rte_flow_item *item;
2647 /* Token name must match. */
2648 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
2650 /* Parse parameter types. */
2651 switch (ctx->curr) {
2652 static const enum index prefix[] = NEXT_ENTRY(PREFIX);
2658 case ITEM_PARAM_SPEC:
2661 case ITEM_PARAM_LAST:
2664 case ITEM_PARAM_PREFIX:
2665 /* Modify next token to expect a prefix. */
2666 if (ctx->next_num < 2)
2668 ctx->next[ctx->next_num - 2] = prefix;
2670 case ITEM_PARAM_MASK:
2676 /* Nothing else to do if there is no buffer. */
2679 if (!out->args.vc.pattern_n)
2681 item = &out->args.vc.pattern[out->args.vc.pattern_n - 1];
2682 data_size = ctx->objdata / 3; /* spec, last, mask */
2683 /* Point to selected object. */
2684 ctx->object = out->args.vc.data + (data_size * index);
2686 ctx->objmask = out->args.vc.data + (data_size * 2); /* mask */
2687 item->mask = ctx->objmask;
2689 ctx->objmask = NULL;
2690 /* Update relevant item pointer. */
2691 *((const void **[]){ &item->spec, &item->last, &item->mask })[index] =
2696 /** Parse action configuration field. */
2698 parse_vc_conf(struct context *ctx, const struct token *token,
2699 const char *str, unsigned int len,
2700 void *buf, unsigned int size)
2702 struct buffer *out = buf;
2705 /* Token name must match. */
2706 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
2708 /* Nothing else to do if there is no buffer. */
2711 /* Point to selected object. */
2712 ctx->object = out->args.vc.data;
2713 ctx->objmask = NULL;
2717 /** Parse RSS action. */
2719 parse_vc_action_rss(struct context *ctx, const struct token *token,
2720 const char *str, unsigned int len,
2721 void *buf, unsigned int size)
2723 struct buffer *out = buf;
2724 struct rte_flow_action *action;
2725 struct action_rss_data *action_rss_data;
2729 ret = parse_vc(ctx, token, str, len, buf, size);
2732 /* Nothing else to do if there is no buffer. */
2735 if (!out->args.vc.actions_n)
2737 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
2738 /* Point to selected object. */
2739 ctx->object = out->args.vc.data;
2740 ctx->objmask = NULL;
2741 /* Set up default configuration. */
2742 action_rss_data = ctx->object;
2743 *action_rss_data = (struct action_rss_data){
2744 .conf = (struct rte_flow_action_rss){
2745 .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
2748 .key_len = sizeof(action_rss_data->key),
2749 .queue_num = RTE_MIN(nb_rxq, ACTION_RSS_QUEUE_NUM),
2750 .key = action_rss_data->key,
2751 .queue = action_rss_data->queue,
2753 .key = "testpmd's default RSS hash key",
2756 for (i = 0; i < action_rss_data->conf.queue_num; ++i)
2757 action_rss_data->queue[i] = i;
2758 if (!port_id_is_invalid(ctx->port, DISABLED_WARN) &&
2759 ctx->port != (portid_t)RTE_PORT_ALL) {
2760 struct rte_eth_dev_info info;
2762 rte_eth_dev_info_get(ctx->port, &info);
2763 action_rss_data->conf.key_len =
2764 RTE_MIN(sizeof(action_rss_data->key),
2765 info.hash_key_size);
2767 action->conf = &action_rss_data->conf;
2772 * Parse func field for RSS action.
2774 * The RTE_ETH_HASH_FUNCTION_* value to assign is derived from the
2775 * ACTION_RSS_FUNC_* index that called this function.
2778 parse_vc_action_rss_func(struct context *ctx, const struct token *token,
2779 const char *str, unsigned int len,
2780 void *buf, unsigned int size)
2782 struct action_rss_data *action_rss_data;
2783 enum rte_eth_hash_function func;
2787 /* Token name must match. */
2788 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
2790 switch (ctx->curr) {
2791 case ACTION_RSS_FUNC_DEFAULT:
2792 func = RTE_ETH_HASH_FUNCTION_DEFAULT;
2794 case ACTION_RSS_FUNC_TOEPLITZ:
2795 func = RTE_ETH_HASH_FUNCTION_TOEPLITZ;
2797 case ACTION_RSS_FUNC_SIMPLE_XOR:
2798 func = RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
2805 action_rss_data = ctx->object;
2806 action_rss_data->conf.func = func;
2811 * Parse type field for RSS action.
2813 * Valid tokens are type field names and the "end" token.
2816 parse_vc_action_rss_type(struct context *ctx, const struct token *token,
2817 const char *str, unsigned int len,
2818 void *buf, unsigned int size)
2820 static const enum index next[] = NEXT_ENTRY(ACTION_RSS_TYPE);
2821 struct action_rss_data *action_rss_data;
2827 if (ctx->curr != ACTION_RSS_TYPE)
2829 if (!(ctx->objdata >> 16) && ctx->object) {
2830 action_rss_data = ctx->object;
2831 action_rss_data->conf.types = 0;
2833 if (!strcmp_partial("end", str, len)) {
2834 ctx->objdata &= 0xffff;
2837 for (i = 0; rss_type_table[i].str; ++i)
2838 if (!strcmp_partial(rss_type_table[i].str, str, len))
2840 if (!rss_type_table[i].str)
2842 ctx->objdata = 1 << 16 | (ctx->objdata & 0xffff);
2844 if (ctx->next_num == RTE_DIM(ctx->next))
2846 ctx->next[ctx->next_num++] = next;
2849 action_rss_data = ctx->object;
2850 action_rss_data->conf.types |= rss_type_table[i].rss_type;
2855 * Parse queue field for RSS action.
2857 * Valid tokens are queue indices and the "end" token.
2860 parse_vc_action_rss_queue(struct context *ctx, const struct token *token,
2861 const char *str, unsigned int len,
2862 void *buf, unsigned int size)
2864 static const enum index next[] = NEXT_ENTRY(ACTION_RSS_QUEUE);
2865 struct action_rss_data *action_rss_data;
2872 if (ctx->curr != ACTION_RSS_QUEUE)
2874 i = ctx->objdata >> 16;
2875 if (!strcmp_partial("end", str, len)) {
2876 ctx->objdata &= 0xffff;
2879 if (i >= ACTION_RSS_QUEUE_NUM)
2882 ARGS_ENTRY_ARB(offsetof(struct action_rss_data, queue) +
2883 i * sizeof(action_rss_data->queue[i]),
2884 sizeof(action_rss_data->queue[i]))))
2886 ret = parse_int(ctx, token, str, len, NULL, 0);
2892 ctx->objdata = i << 16 | (ctx->objdata & 0xffff);
2894 if (ctx->next_num == RTE_DIM(ctx->next))
2896 ctx->next[ctx->next_num++] = next;
2899 action_rss_data = ctx->object;
2900 action_rss_data->conf.queue_num = i;
2901 action_rss_data->conf.queue = i ? action_rss_data->queue : NULL;
2905 /** Parse tokens for destroy command. */
2907 parse_destroy(struct context *ctx, const struct token *token,
2908 const char *str, unsigned int len,
2909 void *buf, unsigned int size)
2911 struct buffer *out = buf;
2913 /* Token name must match. */
2914 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
2916 /* Nothing else to do if there is no buffer. */
2919 if (!out->command) {
2920 if (ctx->curr != DESTROY)
2922 if (sizeof(*out) > size)
2924 out->command = ctx->curr;
2927 ctx->objmask = NULL;
2928 out->args.destroy.rule =
2929 (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
2933 if (((uint8_t *)(out->args.destroy.rule + out->args.destroy.rule_n) +
2934 sizeof(*out->args.destroy.rule)) > (uint8_t *)out + size)
2937 ctx->object = out->args.destroy.rule + out->args.destroy.rule_n++;
2938 ctx->objmask = NULL;
2942 /** Parse tokens for flush command. */
2944 parse_flush(struct context *ctx, const struct token *token,
2945 const char *str, unsigned int len,
2946 void *buf, unsigned int size)
2948 struct buffer *out = buf;
2950 /* Token name must match. */
2951 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
2953 /* Nothing else to do if there is no buffer. */
2956 if (!out->command) {
2957 if (ctx->curr != FLUSH)
2959 if (sizeof(*out) > size)
2961 out->command = ctx->curr;
2964 ctx->objmask = NULL;
2969 /** Parse tokens for query command. */
2971 parse_query(struct context *ctx, const struct token *token,
2972 const char *str, unsigned int len,
2973 void *buf, unsigned int size)
2975 struct buffer *out = buf;
2977 /* Token name must match. */
2978 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
2980 /* Nothing else to do if there is no buffer. */
2983 if (!out->command) {
2984 if (ctx->curr != QUERY)
2986 if (sizeof(*out) > size)
2988 out->command = ctx->curr;
2991 ctx->objmask = NULL;
2996 /** Parse action names. */
2998 parse_action(struct context *ctx, const struct token *token,
2999 const char *str, unsigned int len,
3000 void *buf, unsigned int size)
3002 struct buffer *out = buf;
3003 const struct arg *arg = pop_args(ctx);
3007 /* Argument is expected. */
3010 /* Parse action name. */
3011 for (i = 0; next_action[i]; ++i) {
3012 const struct parse_action_priv *priv;
3014 token = &token_list[next_action[i]];
3015 if (strcmp_partial(token->name, str, len))
3021 memcpy((uint8_t *)ctx->object + arg->offset,
3027 push_args(ctx, arg);
3031 /** Parse tokens for list command. */
3033 parse_list(struct context *ctx, const struct token *token,
3034 const char *str, unsigned int len,
3035 void *buf, unsigned int size)
3037 struct buffer *out = buf;
3039 /* Token name must match. */
3040 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
3042 /* Nothing else to do if there is no buffer. */
3045 if (!out->command) {
3046 if (ctx->curr != LIST)
3048 if (sizeof(*out) > size)
3050 out->command = ctx->curr;
3053 ctx->objmask = NULL;
3054 out->args.list.group =
3055 (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
3059 if (((uint8_t *)(out->args.list.group + out->args.list.group_n) +
3060 sizeof(*out->args.list.group)) > (uint8_t *)out + size)
3063 ctx->object = out->args.list.group + out->args.list.group_n++;
3064 ctx->objmask = NULL;
3068 /** Parse tokens for isolate command. */
3070 parse_isolate(struct context *ctx, const struct token *token,
3071 const char *str, unsigned int len,
3072 void *buf, unsigned int size)
3074 struct buffer *out = buf;
3076 /* Token name must match. */
3077 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
3079 /* Nothing else to do if there is no buffer. */
3082 if (!out->command) {
3083 if (ctx->curr != ISOLATE)
3085 if (sizeof(*out) > size)
3087 out->command = ctx->curr;
3090 ctx->objmask = NULL;
3096 * Parse signed/unsigned integers 8 to 64-bit long.
3098 * Last argument (ctx->args) is retrieved to determine integer type and
3102 parse_int(struct context *ctx, const struct token *token,
3103 const char *str, unsigned int len,
3104 void *buf, unsigned int size)
3106 const struct arg *arg = pop_args(ctx);
3111 /* Argument is expected. */
3116 (uintmax_t)strtoimax(str, &end, 0) :
3117 strtoumax(str, &end, 0);
3118 if (errno || (size_t)(end - str) != len)
3121 ((arg->sign && ((intmax_t)u < (intmax_t)arg->min ||
3122 (intmax_t)u > (intmax_t)arg->max)) ||
3123 (!arg->sign && (u < arg->min || u > arg->max))))
3128 if (!arg_entry_bf_fill(ctx->object, u, arg) ||
3129 !arg_entry_bf_fill(ctx->objmask, -1, arg))
3133 buf = (uint8_t *)ctx->object + arg->offset;
3137 case sizeof(uint8_t):
3138 *(uint8_t *)buf = u;
3140 case sizeof(uint16_t):
3141 *(uint16_t *)buf = arg->hton ? rte_cpu_to_be_16(u) : u;
3143 case sizeof(uint8_t [3]):
3144 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
3146 ((uint8_t *)buf)[0] = u;
3147 ((uint8_t *)buf)[1] = u >> 8;
3148 ((uint8_t *)buf)[2] = u >> 16;
3152 ((uint8_t *)buf)[0] = u >> 16;
3153 ((uint8_t *)buf)[1] = u >> 8;
3154 ((uint8_t *)buf)[2] = u;
3156 case sizeof(uint32_t):
3157 *(uint32_t *)buf = arg->hton ? rte_cpu_to_be_32(u) : u;
3159 case sizeof(uint64_t):
3160 *(uint64_t *)buf = arg->hton ? rte_cpu_to_be_64(u) : u;
3165 if (ctx->objmask && buf != (uint8_t *)ctx->objmask + arg->offset) {
3167 buf = (uint8_t *)ctx->objmask + arg->offset;
3172 push_args(ctx, arg);
3179 * Three arguments (ctx->args) are retrieved from the stack to store data,
3180 * its actual length and address (in that order).
3183 parse_string(struct context *ctx, const struct token *token,
3184 const char *str, unsigned int len,
3185 void *buf, unsigned int size)
3187 const struct arg *arg_data = pop_args(ctx);
3188 const struct arg *arg_len = pop_args(ctx);
3189 const struct arg *arg_addr = pop_args(ctx);
3190 char tmp[16]; /* Ought to be enough. */
3193 /* Arguments are expected. */
3197 push_args(ctx, arg_data);
3201 push_args(ctx, arg_len);
3202 push_args(ctx, arg_data);
3205 size = arg_data->size;
3206 /* Bit-mask fill is not supported. */
3207 if (arg_data->mask || size < len)
3211 /* Let parse_int() fill length information first. */
3212 ret = snprintf(tmp, sizeof(tmp), "%u", len);
3215 push_args(ctx, arg_len);
3216 ret = parse_int(ctx, token, tmp, ret, NULL, 0);
3221 buf = (uint8_t *)ctx->object + arg_data->offset;
3222 /* Output buffer is not necessarily NUL-terminated. */
3223 memcpy(buf, str, len);
3224 memset((uint8_t *)buf + len, 0x00, size - len);
3226 memset((uint8_t *)ctx->objmask + arg_data->offset, 0xff, len);
3227 /* Save address if requested. */
3228 if (arg_addr->size) {
3229 memcpy((uint8_t *)ctx->object + arg_addr->offset,
3231 (uint8_t *)ctx->object + arg_data->offset
3235 memcpy((uint8_t *)ctx->objmask + arg_addr->offset,
3237 (uint8_t *)ctx->objmask + arg_data->offset
3243 push_args(ctx, arg_addr);
3244 push_args(ctx, arg_len);
3245 push_args(ctx, arg_data);
3250 * Parse a MAC address.
3252 * Last argument (ctx->args) is retrieved to determine storage size and
3256 parse_mac_addr(struct context *ctx, const struct token *token,
3257 const char *str, unsigned int len,
3258 void *buf, unsigned int size)
3260 const struct arg *arg = pop_args(ctx);
3261 struct ether_addr tmp;
3265 /* Argument is expected. */
3269 /* Bit-mask fill is not supported. */
3270 if (arg->mask || size != sizeof(tmp))
3272 /* Only network endian is supported. */
3275 ret = cmdline_parse_etheraddr(NULL, str, &tmp, size);
3276 if (ret < 0 || (unsigned int)ret != len)
3280 buf = (uint8_t *)ctx->object + arg->offset;
3281 memcpy(buf, &tmp, size);
3283 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
3286 push_args(ctx, arg);
3291 * Parse an IPv4 address.
3293 * Last argument (ctx->args) is retrieved to determine storage size and
3297 parse_ipv4_addr(struct context *ctx, const struct token *token,
3298 const char *str, unsigned int len,
3299 void *buf, unsigned int size)
3301 const struct arg *arg = pop_args(ctx);
3306 /* Argument is expected. */
3310 /* Bit-mask fill is not supported. */
3311 if (arg->mask || size != sizeof(tmp))
3313 /* Only network endian is supported. */
3316 memcpy(str2, str, len);
3318 ret = inet_pton(AF_INET, str2, &tmp);
3320 /* Attempt integer parsing. */
3321 push_args(ctx, arg);
3322 return parse_int(ctx, token, str, len, buf, size);
3326 buf = (uint8_t *)ctx->object + arg->offset;
3327 memcpy(buf, &tmp, size);
3329 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
3332 push_args(ctx, arg);
3337 * Parse an IPv6 address.
3339 * Last argument (ctx->args) is retrieved to determine storage size and
3343 parse_ipv6_addr(struct context *ctx, const struct token *token,
3344 const char *str, unsigned int len,
3345 void *buf, unsigned int size)
3347 const struct arg *arg = pop_args(ctx);
3349 struct in6_addr tmp;
3353 /* Argument is expected. */
3357 /* Bit-mask fill is not supported. */
3358 if (arg->mask || size != sizeof(tmp))
3360 /* Only network endian is supported. */
3363 memcpy(str2, str, len);
3365 ret = inet_pton(AF_INET6, str2, &tmp);
3370 buf = (uint8_t *)ctx->object + arg->offset;
3371 memcpy(buf, &tmp, size);
3373 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
3376 push_args(ctx, arg);
3380 /** Boolean values (even indices stand for false). */
3381 static const char *const boolean_name[] = {
3391 * Parse a boolean value.
3393 * Last argument (ctx->args) is retrieved to determine storage size and
3397 parse_boolean(struct context *ctx, const struct token *token,
3398 const char *str, unsigned int len,
3399 void *buf, unsigned int size)
3401 const struct arg *arg = pop_args(ctx);
3405 /* Argument is expected. */
3408 for (i = 0; boolean_name[i]; ++i)
3409 if (!strcmp_partial(boolean_name[i], str, len))
3411 /* Process token as integer. */
3412 if (boolean_name[i])
3413 str = i & 1 ? "1" : "0";
3414 push_args(ctx, arg);
3415 ret = parse_int(ctx, token, str, strlen(str), buf, size);
3416 return ret > 0 ? (int)len : ret;
3419 /** Parse port and update context. */
3421 parse_port(struct context *ctx, const struct token *token,
3422 const char *str, unsigned int len,
3423 void *buf, unsigned int size)
3425 struct buffer *out = &(struct buffer){ .port = 0 };
3433 ctx->objmask = NULL;
3434 size = sizeof(*out);
3436 ret = parse_int(ctx, token, str, len, out, size);
3438 ctx->port = out->port;
3444 /** No completion. */
3446 comp_none(struct context *ctx, const struct token *token,
3447 unsigned int ent, char *buf, unsigned int size)
3457 /** Complete boolean values. */
3459 comp_boolean(struct context *ctx, const struct token *token,
3460 unsigned int ent, char *buf, unsigned int size)
3466 for (i = 0; boolean_name[i]; ++i)
3467 if (buf && i == ent)
3468 return snprintf(buf, size, "%s", boolean_name[i]);
3474 /** Complete action names. */
3476 comp_action(struct context *ctx, const struct token *token,
3477 unsigned int ent, char *buf, unsigned int size)
3483 for (i = 0; next_action[i]; ++i)
3484 if (buf && i == ent)
3485 return snprintf(buf, size, "%s",
3486 token_list[next_action[i]].name);
3492 /** Complete available ports. */
3494 comp_port(struct context *ctx, const struct token *token,
3495 unsigned int ent, char *buf, unsigned int size)
3502 RTE_ETH_FOREACH_DEV(p) {
3503 if (buf && i == ent)
3504 return snprintf(buf, size, "%u", p);
3512 /** Complete available rule IDs. */
3514 comp_rule_id(struct context *ctx, const struct token *token,
3515 unsigned int ent, char *buf, unsigned int size)
3518 struct rte_port *port;
3519 struct port_flow *pf;
3522 if (port_id_is_invalid(ctx->port, DISABLED_WARN) ||
3523 ctx->port == (portid_t)RTE_PORT_ALL)
3525 port = &ports[ctx->port];
3526 for (pf = port->flow_list; pf != NULL; pf = pf->next) {
3527 if (buf && i == ent)
3528 return snprintf(buf, size, "%u", pf->id);
3536 /** Complete type field for RSS action. */
3538 comp_vc_action_rss_type(struct context *ctx, const struct token *token,
3539 unsigned int ent, char *buf, unsigned int size)
3545 for (i = 0; rss_type_table[i].str; ++i)
3550 return snprintf(buf, size, "%s", rss_type_table[ent].str);
3552 return snprintf(buf, size, "end");
3556 /** Complete queue field for RSS action. */
3558 comp_vc_action_rss_queue(struct context *ctx, const struct token *token,
3559 unsigned int ent, char *buf, unsigned int size)
3566 return snprintf(buf, size, "%u", ent);
3568 return snprintf(buf, size, "end");
3572 /** Internal context. */
3573 static struct context cmd_flow_context;
3575 /** Global parser instance (cmdline API). */
3576 cmdline_parse_inst_t cmd_flow;
3578 /** Initialize context. */
3580 cmd_flow_context_init(struct context *ctx)
3582 /* A full memset() is not necessary. */
3592 ctx->objmask = NULL;
3595 /** Parse a token (cmdline API). */
3597 cmd_flow_parse(cmdline_parse_token_hdr_t *hdr, const char *src, void *result,
3600 struct context *ctx = &cmd_flow_context;
3601 const struct token *token;
3602 const enum index *list;
3607 token = &token_list[ctx->curr];
3608 /* Check argument length. */
3611 for (len = 0; src[len]; ++len)
3612 if (src[len] == '#' || isspace(src[len]))
3616 /* Last argument and EOL detection. */
3617 for (i = len; src[i]; ++i)
3618 if (src[i] == '#' || src[i] == '\r' || src[i] == '\n')
3620 else if (!isspace(src[i])) {
3625 if (src[i] == '\r' || src[i] == '\n') {
3629 /* Initialize context if necessary. */
3630 if (!ctx->next_num) {
3633 ctx->next[ctx->next_num++] = token->next[0];
3635 /* Process argument through candidates. */
3636 ctx->prev = ctx->curr;
3637 list = ctx->next[ctx->next_num - 1];
3638 for (i = 0; list[i]; ++i) {
3639 const struct token *next = &token_list[list[i]];
3642 ctx->curr = list[i];
3644 tmp = next->call(ctx, next, src, len, result, size);
3646 tmp = parse_default(ctx, next, src, len, result, size);
3647 if (tmp == -1 || tmp != len)
3655 /* Push subsequent tokens if any. */
3657 for (i = 0; token->next[i]; ++i) {
3658 if (ctx->next_num == RTE_DIM(ctx->next))
3660 ctx->next[ctx->next_num++] = token->next[i];
3662 /* Push arguments if any. */
3664 for (i = 0; token->args[i]; ++i) {
3665 if (ctx->args_num == RTE_DIM(ctx->args))
3667 ctx->args[ctx->args_num++] = token->args[i];
3672 /** Return number of completion entries (cmdline API). */
3674 cmd_flow_complete_get_nb(cmdline_parse_token_hdr_t *hdr)
3676 struct context *ctx = &cmd_flow_context;
3677 const struct token *token = &token_list[ctx->curr];
3678 const enum index *list;
3682 /* Count number of tokens in current list. */
3684 list = ctx->next[ctx->next_num - 1];
3686 list = token->next[0];
3687 for (i = 0; list[i]; ++i)
3692 * If there is a single token, use its completion callback, otherwise
3693 * return the number of entries.
3695 token = &token_list[list[0]];
3696 if (i == 1 && token->comp) {
3697 /* Save index for cmd_flow_get_help(). */
3698 ctx->prev = list[0];
3699 return token->comp(ctx, token, 0, NULL, 0);
3704 /** Return a completion entry (cmdline API). */
3706 cmd_flow_complete_get_elt(cmdline_parse_token_hdr_t *hdr, int index,
3707 char *dst, unsigned int size)
3709 struct context *ctx = &cmd_flow_context;
3710 const struct token *token = &token_list[ctx->curr];
3711 const enum index *list;
3715 /* Count number of tokens in current list. */
3717 list = ctx->next[ctx->next_num - 1];
3719 list = token->next[0];
3720 for (i = 0; list[i]; ++i)
3724 /* If there is a single token, use its completion callback. */
3725 token = &token_list[list[0]];
3726 if (i == 1 && token->comp) {
3727 /* Save index for cmd_flow_get_help(). */
3728 ctx->prev = list[0];
3729 return token->comp(ctx, token, index, dst, size) < 0 ? -1 : 0;
3731 /* Otherwise make sure the index is valid and use defaults. */
3734 token = &token_list[list[index]];
3735 snprintf(dst, size, "%s", token->name);
3736 /* Save index for cmd_flow_get_help(). */
3737 ctx->prev = list[index];
3741 /** Populate help strings for current token (cmdline API). */
3743 cmd_flow_get_help(cmdline_parse_token_hdr_t *hdr, char *dst, unsigned int size)
3745 struct context *ctx = &cmd_flow_context;
3746 const struct token *token = &token_list[ctx->prev];
3751 /* Set token type and update global help with details. */
3752 snprintf(dst, size, "%s", (token->type ? token->type : "TOKEN"));
3754 cmd_flow.help_str = token->help;
3756 cmd_flow.help_str = token->name;
3760 /** Token definition template (cmdline API). */
3761 static struct cmdline_token_hdr cmd_flow_token_hdr = {
3762 .ops = &(struct cmdline_token_ops){
3763 .parse = cmd_flow_parse,
3764 .complete_get_nb = cmd_flow_complete_get_nb,
3765 .complete_get_elt = cmd_flow_complete_get_elt,
3766 .get_help = cmd_flow_get_help,
3771 /** Populate the next dynamic token. */
3773 cmd_flow_tok(cmdline_parse_token_hdr_t **hdr,
3774 cmdline_parse_token_hdr_t **hdr_inst)
3776 struct context *ctx = &cmd_flow_context;
3778 /* Always reinitialize context before requesting the first token. */
3779 if (!(hdr_inst - cmd_flow.tokens))
3780 cmd_flow_context_init(ctx);
3781 /* Return NULL when no more tokens are expected. */
3782 if (!ctx->next_num && ctx->curr) {
3786 /* Determine if command should end here. */
3787 if (ctx->eol && ctx->last && ctx->next_num) {
3788 const enum index *list = ctx->next[ctx->next_num - 1];
3791 for (i = 0; list[i]; ++i) {
3798 *hdr = &cmd_flow_token_hdr;
3801 /** Dispatch parsed buffer to function calls. */
3803 cmd_flow_parsed(const struct buffer *in)
3805 switch (in->command) {
3807 port_flow_validate(in->port, &in->args.vc.attr,
3808 in->args.vc.pattern, in->args.vc.actions);
3811 port_flow_create(in->port, &in->args.vc.attr,
3812 in->args.vc.pattern, in->args.vc.actions);
3815 port_flow_destroy(in->port, in->args.destroy.rule_n,
3816 in->args.destroy.rule);
3819 port_flow_flush(in->port);
3822 port_flow_query(in->port, in->args.query.rule,
3823 in->args.query.action);
3826 port_flow_list(in->port, in->args.list.group_n,
3827 in->args.list.group);
3830 port_flow_isolate(in->port, in->args.isolate.set);
3837 /** Token generator and output processing callback (cmdline API). */
3839 cmd_flow_cb(void *arg0, struct cmdline *cl, void *arg2)
3842 cmd_flow_tok(arg0, arg2);
3844 cmd_flow_parsed(arg0);
3847 /** Global parser instance (cmdline API). */
3848 cmdline_parse_inst_t cmd_flow = {
3850 .data = NULL, /**< Unused. */
3851 .help_str = NULL, /**< Updated by cmd_flow_get_help(). */
3854 }, /**< Tokens are returned by cmd_flow_tok(). */