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,
244 /** Maximum size for pattern in struct rte_flow_item_raw. */
245 #define ITEM_RAW_PATTERN_SIZE 40
247 /** Storage size for struct rte_flow_item_raw including pattern. */
248 #define ITEM_RAW_SIZE \
249 (sizeof(struct rte_flow_item_raw) + ITEM_RAW_PATTERN_SIZE)
251 /** Maximum number of queue indices in struct rte_flow_action_rss. */
252 #define ACTION_RSS_QUEUE_NUM 32
254 /** Storage for struct rte_flow_action_rss including external data. */
255 struct action_rss_data {
256 struct rte_flow_action_rss conf;
257 uint8_t key[RSS_HASH_KEY_LENGTH];
258 uint16_t queue[ACTION_RSS_QUEUE_NUM];
261 /** Maximum number of subsequent tokens and arguments on the stack. */
262 #define CTX_STACK_SIZE 16
264 /** Parser context. */
266 /** Stack of subsequent token lists to process. */
267 const enum index *next[CTX_STACK_SIZE];
268 /** Arguments for stacked tokens. */
269 const void *args[CTX_STACK_SIZE];
270 enum index curr; /**< Current token index. */
271 enum index prev; /**< Index of the last token seen. */
272 int next_num; /**< Number of entries in next[]. */
273 int args_num; /**< Number of entries in args[]. */
274 uint32_t eol:1; /**< EOL has been detected. */
275 uint32_t last:1; /**< No more arguments. */
276 portid_t port; /**< Current port ID (for completions). */
277 uint32_t objdata; /**< Object-specific data. */
278 void *object; /**< Address of current object for relative offsets. */
279 void *objmask; /**< Object a full mask must be written to. */
282 /** Token argument. */
284 uint32_t hton:1; /**< Use network byte ordering. */
285 uint32_t sign:1; /**< Value is signed. */
286 uint32_t bounded:1; /**< Value is bounded. */
287 uintmax_t min; /**< Minimum value if bounded. */
288 uintmax_t max; /**< Maximum value if bounded. */
289 uint32_t offset; /**< Relative offset from ctx->object. */
290 uint32_t size; /**< Field size. */
291 const uint8_t *mask; /**< Bit-mask to use instead of offset/size. */
294 /** Parser token definition. */
296 /** Type displayed during completion (defaults to "TOKEN"). */
298 /** Help displayed during completion (defaults to token name). */
300 /** Private data used by parser functions. */
303 * Lists of subsequent tokens to push on the stack. Each call to the
304 * parser consumes the last entry of that stack.
306 const enum index *const *next;
307 /** Arguments stack for subsequent tokens that need them. */
308 const struct arg *const *args;
310 * Token-processing callback, returns -1 in case of error, the
311 * length of the matched string otherwise. If NULL, attempts to
312 * match the token name.
314 * If buf is not NULL, the result should be stored in it according
315 * to context. An error is returned if not large enough.
317 int (*call)(struct context *ctx, const struct token *token,
318 const char *str, unsigned int len,
319 void *buf, unsigned int size);
321 * Callback that provides possible values for this token, used for
322 * completion. Returns -1 in case of error, the number of possible
323 * values otherwise. If NULL, the token name is used.
325 * If buf is not NULL, entry index ent is written to buf and the
326 * full length of the entry is returned (same behavior as
329 int (*comp)(struct context *ctx, const struct token *token,
330 unsigned int ent, char *buf, unsigned int size);
331 /** Mandatory token name, no default value. */
335 /** Static initializer for the next field. */
336 #define NEXT(...) (const enum index *const []){ __VA_ARGS__, NULL, }
338 /** Static initializer for a NEXT() entry. */
339 #define NEXT_ENTRY(...) (const enum index []){ __VA_ARGS__, ZERO, }
341 /** Static initializer for the args field. */
342 #define ARGS(...) (const struct arg *const []){ __VA_ARGS__, NULL, }
344 /** Static initializer for ARGS() to target a field. */
345 #define ARGS_ENTRY(s, f) \
346 (&(const struct arg){ \
347 .offset = offsetof(s, f), \
348 .size = sizeof(((s *)0)->f), \
351 /** Static initializer for ARGS() to target a bit-field. */
352 #define ARGS_ENTRY_BF(s, f, b) \
353 (&(const struct arg){ \
355 .mask = (const void *)&(const s){ .f = (1 << (b)) - 1 }, \
358 /** Static initializer for ARGS() to target an arbitrary bit-mask. */
359 #define ARGS_ENTRY_MASK(s, f, m) \
360 (&(const struct arg){ \
361 .offset = offsetof(s, f), \
362 .size = sizeof(((s *)0)->f), \
363 .mask = (const void *)(m), \
366 /** Same as ARGS_ENTRY_MASK() using network byte ordering for the value. */
367 #define ARGS_ENTRY_MASK_HTON(s, f, m) \
368 (&(const struct arg){ \
370 .offset = offsetof(s, f), \
371 .size = sizeof(((s *)0)->f), \
372 .mask = (const void *)(m), \
375 /** Static initializer for ARGS() to target a pointer. */
376 #define ARGS_ENTRY_PTR(s, f) \
377 (&(const struct arg){ \
378 .size = sizeof(*((s *)0)->f), \
381 /** Static initializer for ARGS() with arbitrary offset and size. */
382 #define ARGS_ENTRY_ARB(o, s) \
383 (&(const struct arg){ \
388 /** Same as ARGS_ENTRY_ARB() with bounded values. */
389 #define ARGS_ENTRY_ARB_BOUNDED(o, s, i, a) \
390 (&(const struct arg){ \
398 /** Same as ARGS_ENTRY() using network byte ordering. */
399 #define ARGS_ENTRY_HTON(s, f) \
400 (&(const struct arg){ \
402 .offset = offsetof(s, f), \
403 .size = sizeof(((s *)0)->f), \
406 /** Parser output buffer layout expected by cmd_flow_parsed(). */
408 enum index command; /**< Flow command. */
409 portid_t port; /**< Affected port ID. */
412 struct rte_flow_attr attr;
413 struct rte_flow_item *pattern;
414 struct rte_flow_action *actions;
418 } vc; /**< Validate/create arguments. */
422 } destroy; /**< Destroy arguments. */
425 struct rte_flow_action action;
426 } query; /**< Query arguments. */
430 } list; /**< List arguments. */
433 } isolate; /**< Isolated mode arguments. */
434 } args; /**< Command arguments. */
437 /** Private data for pattern items. */
438 struct parse_item_priv {
439 enum rte_flow_item_type type; /**< Item type. */
440 uint32_t size; /**< Size of item specification structure. */
443 #define PRIV_ITEM(t, s) \
444 (&(const struct parse_item_priv){ \
445 .type = RTE_FLOW_ITEM_TYPE_ ## t, \
449 /** Private data for actions. */
450 struct parse_action_priv {
451 enum rte_flow_action_type type; /**< Action type. */
452 uint32_t size; /**< Size of action configuration structure. */
455 #define PRIV_ACTION(t, s) \
456 (&(const struct parse_action_priv){ \
457 .type = RTE_FLOW_ACTION_TYPE_ ## t, \
461 static const enum index next_vc_attr[] = {
471 static const enum index next_destroy_attr[] = {
477 static const enum index next_list_attr[] = {
483 static const enum index item_param[] = {
492 static const enum index next_item[] = {
528 ITEM_ICMP6_ND_OPT_SLA_ETH,
529 ITEM_ICMP6_ND_OPT_TLA_ETH,
533 static const enum index item_fuzzy[] = {
539 static const enum index item_any[] = {
545 static const enum index item_vf[] = {
551 static const enum index item_phy_port[] = {
557 static const enum index item_port_id[] = {
563 static const enum index item_mark[] = {
569 static const enum index item_raw[] = {
579 static const enum index item_eth[] = {
587 static const enum index item_vlan[] = {
592 ITEM_VLAN_INNER_TYPE,
597 static const enum index item_ipv4[] = {
607 static const enum index item_ipv6[] = {
618 static const enum index item_icmp[] = {
625 static const enum index item_udp[] = {
632 static const enum index item_tcp[] = {
640 static const enum index item_sctp[] = {
649 static const enum index item_vxlan[] = {
655 static const enum index item_e_tag[] = {
656 ITEM_E_TAG_GRP_ECID_B,
661 static const enum index item_nvgre[] = {
667 static const enum index item_mpls[] = {
673 static const enum index item_gre[] = {
679 static const enum index item_gtp[] = {
685 static const enum index item_geneve[] = {
692 static const enum index item_vxlan_gpe[] = {
698 static const enum index item_arp_eth_ipv4[] = {
699 ITEM_ARP_ETH_IPV4_SHA,
700 ITEM_ARP_ETH_IPV4_SPA,
701 ITEM_ARP_ETH_IPV4_THA,
702 ITEM_ARP_ETH_IPV4_TPA,
707 static const enum index item_ipv6_ext[] = {
708 ITEM_IPV6_EXT_NEXT_HDR,
713 static const enum index item_icmp6[] = {
720 static const enum index item_icmp6_nd_ns[] = {
721 ITEM_ICMP6_ND_NS_TARGET_ADDR,
726 static const enum index item_icmp6_nd_na[] = {
727 ITEM_ICMP6_ND_NA_TARGET_ADDR,
732 static const enum index item_icmp6_nd_opt[] = {
733 ITEM_ICMP6_ND_OPT_TYPE,
738 static const enum index item_icmp6_nd_opt_sla_eth[] = {
739 ITEM_ICMP6_ND_OPT_SLA_ETH_SLA,
744 static const enum index item_icmp6_nd_opt_tla_eth[] = {
745 ITEM_ICMP6_ND_OPT_TLA_ETH_TLA,
750 static const enum index next_action[] = {
766 ACTION_OF_SET_MPLS_TTL,
767 ACTION_OF_DEC_MPLS_TTL,
768 ACTION_OF_SET_NW_TTL,
769 ACTION_OF_DEC_NW_TTL,
770 ACTION_OF_COPY_TTL_OUT,
771 ACTION_OF_COPY_TTL_IN,
774 ACTION_OF_SET_VLAN_VID,
775 ACTION_OF_SET_VLAN_PCP,
781 static const enum index action_mark[] = {
787 static const enum index action_queue[] = {
793 static const enum index action_count[] = {
800 static const enum index action_rss[] = {
811 static const enum index action_vf[] = {
818 static const enum index action_phy_port[] = {
819 ACTION_PHY_PORT_ORIGINAL,
820 ACTION_PHY_PORT_INDEX,
825 static const enum index action_port_id[] = {
826 ACTION_PORT_ID_ORIGINAL,
832 static const enum index action_meter[] = {
838 static const enum index action_of_set_mpls_ttl[] = {
839 ACTION_OF_SET_MPLS_TTL_MPLS_TTL,
844 static const enum index action_of_set_nw_ttl[] = {
845 ACTION_OF_SET_NW_TTL_NW_TTL,
850 static const enum index action_of_push_vlan[] = {
851 ACTION_OF_PUSH_VLAN_ETHERTYPE,
856 static const enum index action_of_set_vlan_vid[] = {
857 ACTION_OF_SET_VLAN_VID_VLAN_VID,
862 static const enum index action_of_set_vlan_pcp[] = {
863 ACTION_OF_SET_VLAN_PCP_VLAN_PCP,
868 static const enum index action_of_pop_mpls[] = {
869 ACTION_OF_POP_MPLS_ETHERTYPE,
874 static const enum index action_of_push_mpls[] = {
875 ACTION_OF_PUSH_MPLS_ETHERTYPE,
880 static const enum index action_jump[] = {
886 static int parse_init(struct context *, const struct token *,
887 const char *, unsigned int,
888 void *, unsigned int);
889 static int parse_vc(struct context *, const struct token *,
890 const char *, unsigned int,
891 void *, unsigned int);
892 static int parse_vc_spec(struct context *, const struct token *,
893 const char *, unsigned int, void *, unsigned int);
894 static int parse_vc_conf(struct context *, const struct token *,
895 const char *, unsigned int, void *, unsigned int);
896 static int parse_vc_action_rss(struct context *, const struct token *,
897 const char *, unsigned int, void *,
899 static int parse_vc_action_rss_func(struct context *, const struct token *,
900 const char *, unsigned int, void *,
902 static int parse_vc_action_rss_type(struct context *, const struct token *,
903 const char *, unsigned int, void *,
905 static int parse_vc_action_rss_queue(struct context *, const struct token *,
906 const char *, unsigned int, void *,
908 static int parse_destroy(struct context *, const struct token *,
909 const char *, unsigned int,
910 void *, unsigned int);
911 static int parse_flush(struct context *, const struct token *,
912 const char *, unsigned int,
913 void *, unsigned int);
914 static int parse_query(struct context *, const struct token *,
915 const char *, unsigned int,
916 void *, unsigned int);
917 static int parse_action(struct context *, const struct token *,
918 const char *, unsigned int,
919 void *, unsigned int);
920 static int parse_list(struct context *, const struct token *,
921 const char *, unsigned int,
922 void *, unsigned int);
923 static int parse_isolate(struct context *, const struct token *,
924 const char *, unsigned int,
925 void *, unsigned int);
926 static int parse_int(struct context *, const struct token *,
927 const char *, unsigned int,
928 void *, unsigned int);
929 static int parse_prefix(struct context *, const struct token *,
930 const char *, unsigned int,
931 void *, unsigned int);
932 static int parse_boolean(struct context *, const struct token *,
933 const char *, unsigned int,
934 void *, unsigned int);
935 static int parse_string(struct context *, const struct token *,
936 const char *, unsigned int,
937 void *, unsigned int);
938 static int parse_mac_addr(struct context *, const struct token *,
939 const char *, unsigned int,
940 void *, unsigned int);
941 static int parse_ipv4_addr(struct context *, const struct token *,
942 const char *, unsigned int,
943 void *, unsigned int);
944 static int parse_ipv6_addr(struct context *, const struct token *,
945 const char *, unsigned int,
946 void *, unsigned int);
947 static int parse_port(struct context *, const struct token *,
948 const char *, unsigned int,
949 void *, unsigned int);
950 static int comp_none(struct context *, const struct token *,
951 unsigned int, char *, unsigned int);
952 static int comp_boolean(struct context *, const struct token *,
953 unsigned int, char *, unsigned int);
954 static int comp_action(struct context *, const struct token *,
955 unsigned int, char *, unsigned int);
956 static int comp_port(struct context *, const struct token *,
957 unsigned int, char *, unsigned int);
958 static int comp_rule_id(struct context *, const struct token *,
959 unsigned int, char *, unsigned int);
960 static int comp_vc_action_rss_type(struct context *, const struct token *,
961 unsigned int, char *, unsigned int);
962 static int comp_vc_action_rss_queue(struct context *, const struct token *,
963 unsigned int, char *, unsigned int);
965 /** Token definitions. */
966 static const struct token token_list[] = {
967 /* Special tokens. */
970 .help = "null entry, abused as the entry point",
971 .next = NEXT(NEXT_ENTRY(FLOW)),
976 .help = "command may end here",
982 .help = "integer value",
987 .name = "{unsigned}",
989 .help = "unsigned integer value",
996 .help = "prefix length for bit-mask",
997 .call = parse_prefix,
1001 .name = "{boolean}",
1003 .help = "any boolean value",
1004 .call = parse_boolean,
1005 .comp = comp_boolean,
1010 .help = "fixed string",
1011 .call = parse_string,
1015 .name = "{MAC address}",
1017 .help = "standard MAC address notation",
1018 .call = parse_mac_addr,
1022 .name = "{IPv4 address}",
1023 .type = "IPV4 ADDRESS",
1024 .help = "standard IPv4 address notation",
1025 .call = parse_ipv4_addr,
1029 .name = "{IPv6 address}",
1030 .type = "IPV6 ADDRESS",
1031 .help = "standard IPv6 address notation",
1032 .call = parse_ipv6_addr,
1036 .name = "{rule id}",
1038 .help = "rule identifier",
1040 .comp = comp_rule_id,
1043 .name = "{port_id}",
1045 .help = "port identifier",
1050 .name = "{group_id}",
1052 .help = "group identifier",
1056 [PRIORITY_LEVEL] = {
1059 .help = "priority level",
1063 /* Top-level command. */
1066 .type = "{command} {port_id} [{arg} [...]]",
1067 .help = "manage ingress/egress flow rules",
1068 .next = NEXT(NEXT_ENTRY
1078 /* Sub-level commands. */
1081 .help = "check whether a flow rule can be created",
1082 .next = NEXT(next_vc_attr, NEXT_ENTRY(PORT_ID)),
1083 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1088 .help = "create a flow rule",
1089 .next = NEXT(next_vc_attr, NEXT_ENTRY(PORT_ID)),
1090 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1095 .help = "destroy specific flow rules",
1096 .next = NEXT(NEXT_ENTRY(DESTROY_RULE), NEXT_ENTRY(PORT_ID)),
1097 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1098 .call = parse_destroy,
1102 .help = "destroy all flow rules",
1103 .next = NEXT(NEXT_ENTRY(PORT_ID)),
1104 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1105 .call = parse_flush,
1109 .help = "query an existing flow rule",
1110 .next = NEXT(NEXT_ENTRY(QUERY_ACTION),
1111 NEXT_ENTRY(RULE_ID),
1112 NEXT_ENTRY(PORT_ID)),
1113 .args = ARGS(ARGS_ENTRY(struct buffer, args.query.action.type),
1114 ARGS_ENTRY(struct buffer, args.query.rule),
1115 ARGS_ENTRY(struct buffer, port)),
1116 .call = parse_query,
1120 .help = "list existing flow rules",
1121 .next = NEXT(next_list_attr, NEXT_ENTRY(PORT_ID)),
1122 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1127 .help = "restrict ingress traffic to the defined flow rules",
1128 .next = NEXT(NEXT_ENTRY(BOOLEAN),
1129 NEXT_ENTRY(PORT_ID)),
1130 .args = ARGS(ARGS_ENTRY(struct buffer, args.isolate.set),
1131 ARGS_ENTRY(struct buffer, port)),
1132 .call = parse_isolate,
1134 /* Destroy arguments. */
1137 .help = "specify a rule identifier",
1138 .next = NEXT(next_destroy_attr, NEXT_ENTRY(RULE_ID)),
1139 .args = ARGS(ARGS_ENTRY_PTR(struct buffer, args.destroy.rule)),
1140 .call = parse_destroy,
1142 /* Query arguments. */
1146 .help = "action to query, must be part of the rule",
1147 .call = parse_action,
1148 .comp = comp_action,
1150 /* List arguments. */
1153 .help = "specify a group",
1154 .next = NEXT(next_list_attr, NEXT_ENTRY(GROUP_ID)),
1155 .args = ARGS(ARGS_ENTRY_PTR(struct buffer, args.list.group)),
1158 /* Validate/create attributes. */
1161 .help = "specify a group",
1162 .next = NEXT(next_vc_attr, NEXT_ENTRY(GROUP_ID)),
1163 .args = ARGS(ARGS_ENTRY(struct rte_flow_attr, group)),
1168 .help = "specify a priority level",
1169 .next = NEXT(next_vc_attr, NEXT_ENTRY(PRIORITY_LEVEL)),
1170 .args = ARGS(ARGS_ENTRY(struct rte_flow_attr, priority)),
1175 .help = "affect rule to ingress",
1176 .next = NEXT(next_vc_attr),
1181 .help = "affect rule to egress",
1182 .next = NEXT(next_vc_attr),
1187 .help = "apply rule directly to endpoints found in pattern",
1188 .next = NEXT(next_vc_attr),
1191 /* Validate/create pattern. */
1194 .help = "submit a list of pattern items",
1195 .next = NEXT(next_item),
1200 .help = "match value perfectly (with full bit-mask)",
1201 .call = parse_vc_spec,
1203 [ITEM_PARAM_SPEC] = {
1205 .help = "match value according to configured bit-mask",
1206 .call = parse_vc_spec,
1208 [ITEM_PARAM_LAST] = {
1210 .help = "specify upper bound to establish a range",
1211 .call = parse_vc_spec,
1213 [ITEM_PARAM_MASK] = {
1215 .help = "specify bit-mask with relevant bits set to one",
1216 .call = parse_vc_spec,
1218 [ITEM_PARAM_PREFIX] = {
1220 .help = "generate bit-mask from a prefix length",
1221 .call = parse_vc_spec,
1225 .help = "specify next pattern item",
1226 .next = NEXT(next_item),
1230 .help = "end list of pattern items",
1231 .priv = PRIV_ITEM(END, 0),
1232 .next = NEXT(NEXT_ENTRY(ACTIONS)),
1237 .help = "no-op pattern item",
1238 .priv = PRIV_ITEM(VOID, 0),
1239 .next = NEXT(NEXT_ENTRY(ITEM_NEXT)),
1244 .help = "perform actions when pattern does not match",
1245 .priv = PRIV_ITEM(INVERT, 0),
1246 .next = NEXT(NEXT_ENTRY(ITEM_NEXT)),
1251 .help = "match any protocol for the current layer",
1252 .priv = PRIV_ITEM(ANY, sizeof(struct rte_flow_item_any)),
1253 .next = NEXT(item_any),
1258 .help = "number of layers covered",
1259 .next = NEXT(item_any, NEXT_ENTRY(UNSIGNED), item_param),
1260 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_any, num)),
1264 .help = "match traffic from/to the physical function",
1265 .priv = PRIV_ITEM(PF, 0),
1266 .next = NEXT(NEXT_ENTRY(ITEM_NEXT)),
1271 .help = "match traffic from/to a virtual function ID",
1272 .priv = PRIV_ITEM(VF, sizeof(struct rte_flow_item_vf)),
1273 .next = NEXT(item_vf),
1279 .next = NEXT(item_vf, NEXT_ENTRY(UNSIGNED), item_param),
1280 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_vf, id)),
1284 .help = "match traffic from/to a specific physical port",
1285 .priv = PRIV_ITEM(PHY_PORT,
1286 sizeof(struct rte_flow_item_phy_port)),
1287 .next = NEXT(item_phy_port),
1290 [ITEM_PHY_PORT_INDEX] = {
1292 .help = "physical port index",
1293 .next = NEXT(item_phy_port, NEXT_ENTRY(UNSIGNED), item_param),
1294 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_phy_port, index)),
1298 .help = "match traffic from/to a given DPDK port ID",
1299 .priv = PRIV_ITEM(PORT_ID,
1300 sizeof(struct rte_flow_item_port_id)),
1301 .next = NEXT(item_port_id),
1304 [ITEM_PORT_ID_ID] = {
1306 .help = "DPDK port ID",
1307 .next = NEXT(item_port_id, NEXT_ENTRY(UNSIGNED), item_param),
1308 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_port_id, id)),
1312 .help = "match traffic against value set in previously matched rule",
1313 .priv = PRIV_ITEM(MARK, sizeof(struct rte_flow_item_mark)),
1314 .next = NEXT(item_mark),
1319 .help = "Integer value to match against",
1320 .next = NEXT(item_mark, NEXT_ENTRY(UNSIGNED), item_param),
1321 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_mark, id)),
1325 .help = "match an arbitrary byte string",
1326 .priv = PRIV_ITEM(RAW, ITEM_RAW_SIZE),
1327 .next = NEXT(item_raw),
1330 [ITEM_RAW_RELATIVE] = {
1332 .help = "look for pattern after the previous item",
1333 .next = NEXT(item_raw, NEXT_ENTRY(BOOLEAN), item_param),
1334 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_item_raw,
1337 [ITEM_RAW_SEARCH] = {
1339 .help = "search pattern from offset (see also limit)",
1340 .next = NEXT(item_raw, NEXT_ENTRY(BOOLEAN), item_param),
1341 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_item_raw,
1344 [ITEM_RAW_OFFSET] = {
1346 .help = "absolute or relative offset for pattern",
1347 .next = NEXT(item_raw, NEXT_ENTRY(INTEGER), item_param),
1348 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_raw, offset)),
1350 [ITEM_RAW_LIMIT] = {
1352 .help = "search area limit for start of pattern",
1353 .next = NEXT(item_raw, NEXT_ENTRY(UNSIGNED), item_param),
1354 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_raw, limit)),
1356 [ITEM_RAW_PATTERN] = {
1358 .help = "byte string to look for",
1359 .next = NEXT(item_raw,
1361 NEXT_ENTRY(ITEM_PARAM_IS,
1364 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_raw, pattern),
1365 ARGS_ENTRY(struct rte_flow_item_raw, length),
1366 ARGS_ENTRY_ARB(sizeof(struct rte_flow_item_raw),
1367 ITEM_RAW_PATTERN_SIZE)),
1371 .help = "match Ethernet header",
1372 .priv = PRIV_ITEM(ETH, sizeof(struct rte_flow_item_eth)),
1373 .next = NEXT(item_eth),
1378 .help = "destination MAC",
1379 .next = NEXT(item_eth, NEXT_ENTRY(MAC_ADDR), item_param),
1380 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_eth, dst)),
1384 .help = "source MAC",
1385 .next = NEXT(item_eth, NEXT_ENTRY(MAC_ADDR), item_param),
1386 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_eth, src)),
1390 .help = "EtherType",
1391 .next = NEXT(item_eth, NEXT_ENTRY(UNSIGNED), item_param),
1392 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_eth, type)),
1396 .help = "match 802.1Q/ad VLAN tag",
1397 .priv = PRIV_ITEM(VLAN, sizeof(struct rte_flow_item_vlan)),
1398 .next = NEXT(item_vlan),
1403 .help = "tag control information",
1404 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1405 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vlan, tci)),
1409 .help = "priority code point",
1410 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1411 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_vlan,
1416 .help = "drop eligible indicator",
1417 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1418 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_vlan,
1423 .help = "VLAN identifier",
1424 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1425 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_vlan,
1428 [ITEM_VLAN_INNER_TYPE] = {
1429 .name = "inner_type",
1430 .help = "inner EtherType",
1431 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1432 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vlan,
1437 .help = "match IPv4 header",
1438 .priv = PRIV_ITEM(IPV4, sizeof(struct rte_flow_item_ipv4)),
1439 .next = NEXT(item_ipv4),
1444 .help = "type of service",
1445 .next = NEXT(item_ipv4, NEXT_ENTRY(UNSIGNED), item_param),
1446 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
1447 hdr.type_of_service)),
1451 .help = "time to live",
1452 .next = NEXT(item_ipv4, NEXT_ENTRY(UNSIGNED), item_param),
1453 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
1456 [ITEM_IPV4_PROTO] = {
1458 .help = "next protocol ID",
1459 .next = NEXT(item_ipv4, NEXT_ENTRY(UNSIGNED), item_param),
1460 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
1461 hdr.next_proto_id)),
1465 .help = "source address",
1466 .next = NEXT(item_ipv4, NEXT_ENTRY(IPV4_ADDR), item_param),
1467 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
1472 .help = "destination address",
1473 .next = NEXT(item_ipv4, NEXT_ENTRY(IPV4_ADDR), item_param),
1474 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
1479 .help = "match IPv6 header",
1480 .priv = PRIV_ITEM(IPV6, sizeof(struct rte_flow_item_ipv6)),
1481 .next = NEXT(item_ipv6),
1486 .help = "traffic class",
1487 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
1488 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_ipv6,
1490 "\x0f\xf0\x00\x00")),
1492 [ITEM_IPV6_FLOW] = {
1494 .help = "flow label",
1495 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
1496 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_ipv6,
1498 "\x00\x0f\xff\xff")),
1500 [ITEM_IPV6_PROTO] = {
1502 .help = "protocol (next header)",
1503 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
1504 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
1509 .help = "hop limit",
1510 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
1511 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
1516 .help = "source address",
1517 .next = NEXT(item_ipv6, NEXT_ENTRY(IPV6_ADDR), item_param),
1518 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
1523 .help = "destination address",
1524 .next = NEXT(item_ipv6, NEXT_ENTRY(IPV6_ADDR), item_param),
1525 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
1530 .help = "match ICMP header",
1531 .priv = PRIV_ITEM(ICMP, sizeof(struct rte_flow_item_icmp)),
1532 .next = NEXT(item_icmp),
1535 [ITEM_ICMP_TYPE] = {
1537 .help = "ICMP packet type",
1538 .next = NEXT(item_icmp, NEXT_ENTRY(UNSIGNED), item_param),
1539 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp,
1542 [ITEM_ICMP_CODE] = {
1544 .help = "ICMP packet code",
1545 .next = NEXT(item_icmp, NEXT_ENTRY(UNSIGNED), item_param),
1546 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp,
1551 .help = "match UDP header",
1552 .priv = PRIV_ITEM(UDP, sizeof(struct rte_flow_item_udp)),
1553 .next = NEXT(item_udp),
1558 .help = "UDP source port",
1559 .next = NEXT(item_udp, NEXT_ENTRY(UNSIGNED), item_param),
1560 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_udp,
1565 .help = "UDP destination port",
1566 .next = NEXT(item_udp, NEXT_ENTRY(UNSIGNED), item_param),
1567 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_udp,
1572 .help = "match TCP header",
1573 .priv = PRIV_ITEM(TCP, sizeof(struct rte_flow_item_tcp)),
1574 .next = NEXT(item_tcp),
1579 .help = "TCP source port",
1580 .next = NEXT(item_tcp, NEXT_ENTRY(UNSIGNED), item_param),
1581 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_tcp,
1586 .help = "TCP destination port",
1587 .next = NEXT(item_tcp, NEXT_ENTRY(UNSIGNED), item_param),
1588 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_tcp,
1591 [ITEM_TCP_FLAGS] = {
1593 .help = "TCP flags",
1594 .next = NEXT(item_tcp, NEXT_ENTRY(UNSIGNED), item_param),
1595 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_tcp,
1600 .help = "match SCTP header",
1601 .priv = PRIV_ITEM(SCTP, sizeof(struct rte_flow_item_sctp)),
1602 .next = NEXT(item_sctp),
1607 .help = "SCTP source port",
1608 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
1609 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
1614 .help = "SCTP destination port",
1615 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
1616 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
1621 .help = "validation tag",
1622 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
1623 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
1626 [ITEM_SCTP_CKSUM] = {
1629 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
1630 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
1635 .help = "match VXLAN header",
1636 .priv = PRIV_ITEM(VXLAN, sizeof(struct rte_flow_item_vxlan)),
1637 .next = NEXT(item_vxlan),
1640 [ITEM_VXLAN_VNI] = {
1642 .help = "VXLAN identifier",
1643 .next = NEXT(item_vxlan, NEXT_ENTRY(UNSIGNED), item_param),
1644 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vxlan, vni)),
1648 .help = "match E-Tag header",
1649 .priv = PRIV_ITEM(E_TAG, sizeof(struct rte_flow_item_e_tag)),
1650 .next = NEXT(item_e_tag),
1653 [ITEM_E_TAG_GRP_ECID_B] = {
1654 .name = "grp_ecid_b",
1655 .help = "GRP and E-CID base",
1656 .next = NEXT(item_e_tag, NEXT_ENTRY(UNSIGNED), item_param),
1657 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_e_tag,
1663 .help = "match NVGRE header",
1664 .priv = PRIV_ITEM(NVGRE, sizeof(struct rte_flow_item_nvgre)),
1665 .next = NEXT(item_nvgre),
1668 [ITEM_NVGRE_TNI] = {
1670 .help = "virtual subnet ID",
1671 .next = NEXT(item_nvgre, NEXT_ENTRY(UNSIGNED), item_param),
1672 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_nvgre, tni)),
1676 .help = "match MPLS header",
1677 .priv = PRIV_ITEM(MPLS, sizeof(struct rte_flow_item_mpls)),
1678 .next = NEXT(item_mpls),
1681 [ITEM_MPLS_LABEL] = {
1683 .help = "MPLS label",
1684 .next = NEXT(item_mpls, NEXT_ENTRY(UNSIGNED), item_param),
1685 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_mpls,
1691 .help = "match GRE header",
1692 .priv = PRIV_ITEM(GRE, sizeof(struct rte_flow_item_gre)),
1693 .next = NEXT(item_gre),
1696 [ITEM_GRE_PROTO] = {
1698 .help = "GRE protocol type",
1699 .next = NEXT(item_gre, NEXT_ENTRY(UNSIGNED), item_param),
1700 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gre,
1705 .help = "fuzzy pattern match, expect faster than default",
1706 .priv = PRIV_ITEM(FUZZY,
1707 sizeof(struct rte_flow_item_fuzzy)),
1708 .next = NEXT(item_fuzzy),
1711 [ITEM_FUZZY_THRESH] = {
1713 .help = "match accuracy threshold",
1714 .next = NEXT(item_fuzzy, NEXT_ENTRY(UNSIGNED), item_param),
1715 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_fuzzy,
1720 .help = "match GTP header",
1721 .priv = PRIV_ITEM(GTP, sizeof(struct rte_flow_item_gtp)),
1722 .next = NEXT(item_gtp),
1727 .help = "tunnel endpoint identifier",
1728 .next = NEXT(item_gtp, NEXT_ENTRY(UNSIGNED), item_param),
1729 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gtp, teid)),
1733 .help = "match GTP header",
1734 .priv = PRIV_ITEM(GTPC, sizeof(struct rte_flow_item_gtp)),
1735 .next = NEXT(item_gtp),
1740 .help = "match GTP header",
1741 .priv = PRIV_ITEM(GTPU, sizeof(struct rte_flow_item_gtp)),
1742 .next = NEXT(item_gtp),
1747 .help = "match GENEVE header",
1748 .priv = PRIV_ITEM(GENEVE, sizeof(struct rte_flow_item_geneve)),
1749 .next = NEXT(item_geneve),
1752 [ITEM_GENEVE_VNI] = {
1754 .help = "virtual network identifier",
1755 .next = NEXT(item_geneve, NEXT_ENTRY(UNSIGNED), item_param),
1756 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_geneve, vni)),
1758 [ITEM_GENEVE_PROTO] = {
1760 .help = "GENEVE protocol type",
1761 .next = NEXT(item_geneve, NEXT_ENTRY(UNSIGNED), item_param),
1762 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_geneve,
1765 [ITEM_VXLAN_GPE] = {
1766 .name = "vxlan-gpe",
1767 .help = "match VXLAN-GPE header",
1768 .priv = PRIV_ITEM(VXLAN_GPE,
1769 sizeof(struct rte_flow_item_vxlan_gpe)),
1770 .next = NEXT(item_vxlan_gpe),
1773 [ITEM_VXLAN_GPE_VNI] = {
1775 .help = "VXLAN-GPE identifier",
1776 .next = NEXT(item_vxlan_gpe, NEXT_ENTRY(UNSIGNED), item_param),
1777 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vxlan_gpe,
1780 [ITEM_ARP_ETH_IPV4] = {
1781 .name = "arp_eth_ipv4",
1782 .help = "match ARP header for Ethernet/IPv4",
1783 .priv = PRIV_ITEM(ARP_ETH_IPV4,
1784 sizeof(struct rte_flow_item_arp_eth_ipv4)),
1785 .next = NEXT(item_arp_eth_ipv4),
1788 [ITEM_ARP_ETH_IPV4_SHA] = {
1790 .help = "sender hardware address",
1791 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(MAC_ADDR),
1793 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
1796 [ITEM_ARP_ETH_IPV4_SPA] = {
1798 .help = "sender IPv4 address",
1799 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(IPV4_ADDR),
1801 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
1804 [ITEM_ARP_ETH_IPV4_THA] = {
1806 .help = "target hardware address",
1807 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(MAC_ADDR),
1809 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
1812 [ITEM_ARP_ETH_IPV4_TPA] = {
1814 .help = "target IPv4 address",
1815 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(IPV4_ADDR),
1817 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
1822 .help = "match presence of any IPv6 extension header",
1823 .priv = PRIV_ITEM(IPV6_EXT,
1824 sizeof(struct rte_flow_item_ipv6_ext)),
1825 .next = NEXT(item_ipv6_ext),
1828 [ITEM_IPV6_EXT_NEXT_HDR] = {
1830 .help = "next header",
1831 .next = NEXT(item_ipv6_ext, NEXT_ENTRY(UNSIGNED), item_param),
1832 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6_ext,
1837 .help = "match any ICMPv6 header",
1838 .priv = PRIV_ITEM(ICMP6, sizeof(struct rte_flow_item_icmp6)),
1839 .next = NEXT(item_icmp6),
1842 [ITEM_ICMP6_TYPE] = {
1844 .help = "ICMPv6 type",
1845 .next = NEXT(item_icmp6, NEXT_ENTRY(UNSIGNED), item_param),
1846 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6,
1849 [ITEM_ICMP6_CODE] = {
1851 .help = "ICMPv6 code",
1852 .next = NEXT(item_icmp6, NEXT_ENTRY(UNSIGNED), item_param),
1853 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6,
1856 [ITEM_ICMP6_ND_NS] = {
1857 .name = "icmp6_nd_ns",
1858 .help = "match ICMPv6 neighbor discovery solicitation",
1859 .priv = PRIV_ITEM(ICMP6_ND_NS,
1860 sizeof(struct rte_flow_item_icmp6_nd_ns)),
1861 .next = NEXT(item_icmp6_nd_ns),
1864 [ITEM_ICMP6_ND_NS_TARGET_ADDR] = {
1865 .name = "target_addr",
1866 .help = "target address",
1867 .next = NEXT(item_icmp6_nd_ns, NEXT_ENTRY(IPV6_ADDR),
1869 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6_nd_ns,
1872 [ITEM_ICMP6_ND_NA] = {
1873 .name = "icmp6_nd_na",
1874 .help = "match ICMPv6 neighbor discovery advertisement",
1875 .priv = PRIV_ITEM(ICMP6_ND_NA,
1876 sizeof(struct rte_flow_item_icmp6_nd_na)),
1877 .next = NEXT(item_icmp6_nd_na),
1880 [ITEM_ICMP6_ND_NA_TARGET_ADDR] = {
1881 .name = "target_addr",
1882 .help = "target address",
1883 .next = NEXT(item_icmp6_nd_na, NEXT_ENTRY(IPV6_ADDR),
1885 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6_nd_na,
1888 [ITEM_ICMP6_ND_OPT] = {
1889 .name = "icmp6_nd_opt",
1890 .help = "match presence of any ICMPv6 neighbor discovery"
1892 .priv = PRIV_ITEM(ICMP6_ND_OPT,
1893 sizeof(struct rte_flow_item_icmp6_nd_opt)),
1894 .next = NEXT(item_icmp6_nd_opt),
1897 [ITEM_ICMP6_ND_OPT_TYPE] = {
1899 .help = "ND option type",
1900 .next = NEXT(item_icmp6_nd_opt, NEXT_ENTRY(UNSIGNED),
1902 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6_nd_opt,
1905 [ITEM_ICMP6_ND_OPT_SLA_ETH] = {
1906 .name = "icmp6_nd_opt_sla_eth",
1907 .help = "match ICMPv6 neighbor discovery source Ethernet"
1908 " link-layer address option",
1910 (ICMP6_ND_OPT_SLA_ETH,
1911 sizeof(struct rte_flow_item_icmp6_nd_opt_sla_eth)),
1912 .next = NEXT(item_icmp6_nd_opt_sla_eth),
1915 [ITEM_ICMP6_ND_OPT_SLA_ETH_SLA] = {
1917 .help = "source Ethernet LLA",
1918 .next = NEXT(item_icmp6_nd_opt_sla_eth, NEXT_ENTRY(MAC_ADDR),
1920 .args = ARGS(ARGS_ENTRY_HTON
1921 (struct rte_flow_item_icmp6_nd_opt_sla_eth, sla)),
1923 [ITEM_ICMP6_ND_OPT_TLA_ETH] = {
1924 .name = "icmp6_nd_opt_tla_eth",
1925 .help = "match ICMPv6 neighbor discovery target Ethernet"
1926 " link-layer address option",
1928 (ICMP6_ND_OPT_TLA_ETH,
1929 sizeof(struct rte_flow_item_icmp6_nd_opt_tla_eth)),
1930 .next = NEXT(item_icmp6_nd_opt_tla_eth),
1933 [ITEM_ICMP6_ND_OPT_TLA_ETH_TLA] = {
1935 .help = "target Ethernet LLA",
1936 .next = NEXT(item_icmp6_nd_opt_tla_eth, NEXT_ENTRY(MAC_ADDR),
1938 .args = ARGS(ARGS_ENTRY_HTON
1939 (struct rte_flow_item_icmp6_nd_opt_tla_eth, tla)),
1942 /* Validate/create actions. */
1945 .help = "submit a list of associated actions",
1946 .next = NEXT(next_action),
1951 .help = "specify next action",
1952 .next = NEXT(next_action),
1956 .help = "end list of actions",
1957 .priv = PRIV_ACTION(END, 0),
1962 .help = "no-op action",
1963 .priv = PRIV_ACTION(VOID, 0),
1964 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
1967 [ACTION_PASSTHRU] = {
1969 .help = "let subsequent rule process matched packets",
1970 .priv = PRIV_ACTION(PASSTHRU, 0),
1971 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
1976 .help = "redirect traffic to a given group",
1977 .priv = PRIV_ACTION(JUMP, sizeof(struct rte_flow_action_jump)),
1978 .next = NEXT(action_jump),
1981 [ACTION_JUMP_GROUP] = {
1983 .help = "group to redirect traffic to",
1984 .next = NEXT(action_jump, NEXT_ENTRY(UNSIGNED)),
1985 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_jump, group)),
1986 .call = parse_vc_conf,
1990 .help = "attach 32 bit value to packets",
1991 .priv = PRIV_ACTION(MARK, sizeof(struct rte_flow_action_mark)),
1992 .next = NEXT(action_mark),
1995 [ACTION_MARK_ID] = {
1997 .help = "32 bit value to return with packets",
1998 .next = NEXT(action_mark, NEXT_ENTRY(UNSIGNED)),
1999 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_mark, id)),
2000 .call = parse_vc_conf,
2004 .help = "flag packets",
2005 .priv = PRIV_ACTION(FLAG, 0),
2006 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2011 .help = "assign packets to a given queue index",
2012 .priv = PRIV_ACTION(QUEUE,
2013 sizeof(struct rte_flow_action_queue)),
2014 .next = NEXT(action_queue),
2017 [ACTION_QUEUE_INDEX] = {
2019 .help = "queue index to use",
2020 .next = NEXT(action_queue, NEXT_ENTRY(UNSIGNED)),
2021 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_queue, index)),
2022 .call = parse_vc_conf,
2026 .help = "drop packets (note: passthru has priority)",
2027 .priv = PRIV_ACTION(DROP, 0),
2028 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2033 .help = "enable counters for this rule",
2034 .priv = PRIV_ACTION(COUNT,
2035 sizeof(struct rte_flow_action_count)),
2036 .next = NEXT(action_count),
2039 [ACTION_COUNT_ID] = {
2040 .name = "identifier",
2041 .help = "counter identifier to use",
2042 .next = NEXT(action_count, NEXT_ENTRY(UNSIGNED)),
2043 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_count, id)),
2044 .call = parse_vc_conf,
2046 [ACTION_COUNT_SHARED] = {
2048 .help = "shared counter",
2049 .next = NEXT(action_count, NEXT_ENTRY(BOOLEAN)),
2050 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_count,
2052 .call = parse_vc_conf,
2056 .help = "spread packets among several queues",
2057 .priv = PRIV_ACTION(RSS, sizeof(struct action_rss_data)),
2058 .next = NEXT(action_rss),
2059 .call = parse_vc_action_rss,
2061 [ACTION_RSS_FUNC] = {
2063 .help = "RSS hash function to apply",
2064 .next = NEXT(action_rss,
2065 NEXT_ENTRY(ACTION_RSS_FUNC_DEFAULT,
2066 ACTION_RSS_FUNC_TOEPLITZ,
2067 ACTION_RSS_FUNC_SIMPLE_XOR)),
2069 [ACTION_RSS_FUNC_DEFAULT] = {
2071 .help = "default hash function",
2072 .call = parse_vc_action_rss_func,
2074 [ACTION_RSS_FUNC_TOEPLITZ] = {
2076 .help = "Toeplitz hash function",
2077 .call = parse_vc_action_rss_func,
2079 [ACTION_RSS_FUNC_SIMPLE_XOR] = {
2080 .name = "simple_xor",
2081 .help = "simple XOR hash function",
2082 .call = parse_vc_action_rss_func,
2084 [ACTION_RSS_LEVEL] = {
2086 .help = "encapsulation level for \"types\"",
2087 .next = NEXT(action_rss, NEXT_ENTRY(UNSIGNED)),
2088 .args = ARGS(ARGS_ENTRY_ARB
2089 (offsetof(struct action_rss_data, conf) +
2090 offsetof(struct rte_flow_action_rss, level),
2091 sizeof(((struct rte_flow_action_rss *)0)->
2094 [ACTION_RSS_TYPES] = {
2096 .help = "specific RSS hash types",
2097 .next = NEXT(action_rss, NEXT_ENTRY(ACTION_RSS_TYPE)),
2099 [ACTION_RSS_TYPE] = {
2101 .help = "RSS hash type",
2102 .call = parse_vc_action_rss_type,
2103 .comp = comp_vc_action_rss_type,
2105 [ACTION_RSS_KEY] = {
2107 .help = "RSS hash key",
2108 .next = NEXT(action_rss, NEXT_ENTRY(STRING)),
2109 .args = ARGS(ARGS_ENTRY_ARB(0, 0),
2111 (offsetof(struct action_rss_data, conf) +
2112 offsetof(struct rte_flow_action_rss, key_len),
2113 sizeof(((struct rte_flow_action_rss *)0)->
2115 ARGS_ENTRY(struct action_rss_data, key)),
2117 [ACTION_RSS_KEY_LEN] = {
2119 .help = "RSS hash key length in bytes",
2120 .next = NEXT(action_rss, NEXT_ENTRY(UNSIGNED)),
2121 .args = ARGS(ARGS_ENTRY_ARB_BOUNDED
2122 (offsetof(struct action_rss_data, conf) +
2123 offsetof(struct rte_flow_action_rss, key_len),
2124 sizeof(((struct rte_flow_action_rss *)0)->
2127 RSS_HASH_KEY_LENGTH)),
2129 [ACTION_RSS_QUEUES] = {
2131 .help = "queue indices to use",
2132 .next = NEXT(action_rss, NEXT_ENTRY(ACTION_RSS_QUEUE)),
2133 .call = parse_vc_conf,
2135 [ACTION_RSS_QUEUE] = {
2137 .help = "queue index",
2138 .call = parse_vc_action_rss_queue,
2139 .comp = comp_vc_action_rss_queue,
2143 .help = "direct traffic to physical function",
2144 .priv = PRIV_ACTION(PF, 0),
2145 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2150 .help = "direct traffic to a virtual function ID",
2151 .priv = PRIV_ACTION(VF, sizeof(struct rte_flow_action_vf)),
2152 .next = NEXT(action_vf),
2155 [ACTION_VF_ORIGINAL] = {
2157 .help = "use original VF ID if possible",
2158 .next = NEXT(action_vf, NEXT_ENTRY(BOOLEAN)),
2159 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_vf,
2161 .call = parse_vc_conf,
2166 .next = NEXT(action_vf, NEXT_ENTRY(UNSIGNED)),
2167 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_vf, id)),
2168 .call = parse_vc_conf,
2170 [ACTION_PHY_PORT] = {
2172 .help = "direct packets to physical port index",
2173 .priv = PRIV_ACTION(PHY_PORT,
2174 sizeof(struct rte_flow_action_phy_port)),
2175 .next = NEXT(action_phy_port),
2178 [ACTION_PHY_PORT_ORIGINAL] = {
2180 .help = "use original port index if possible",
2181 .next = NEXT(action_phy_port, NEXT_ENTRY(BOOLEAN)),
2182 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_phy_port,
2184 .call = parse_vc_conf,
2186 [ACTION_PHY_PORT_INDEX] = {
2188 .help = "physical port index",
2189 .next = NEXT(action_phy_port, NEXT_ENTRY(UNSIGNED)),
2190 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_phy_port,
2192 .call = parse_vc_conf,
2194 [ACTION_PORT_ID] = {
2196 .help = "direct matching traffic to a given DPDK port ID",
2197 .priv = PRIV_ACTION(PORT_ID,
2198 sizeof(struct rte_flow_action_port_id)),
2199 .next = NEXT(action_port_id),
2202 [ACTION_PORT_ID_ORIGINAL] = {
2204 .help = "use original DPDK port ID if possible",
2205 .next = NEXT(action_port_id, NEXT_ENTRY(BOOLEAN)),
2206 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_port_id,
2208 .call = parse_vc_conf,
2210 [ACTION_PORT_ID_ID] = {
2212 .help = "DPDK port ID",
2213 .next = NEXT(action_port_id, NEXT_ENTRY(UNSIGNED)),
2214 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_port_id, id)),
2215 .call = parse_vc_conf,
2219 .help = "meter the directed packets at given id",
2220 .priv = PRIV_ACTION(METER,
2221 sizeof(struct rte_flow_action_meter)),
2222 .next = NEXT(action_meter),
2225 [ACTION_METER_ID] = {
2227 .help = "meter id to use",
2228 .next = NEXT(action_meter, NEXT_ENTRY(UNSIGNED)),
2229 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_meter, mtr_id)),
2230 .call = parse_vc_conf,
2232 [ACTION_OF_SET_MPLS_TTL] = {
2233 .name = "of_set_mpls_ttl",
2234 .help = "OpenFlow's OFPAT_SET_MPLS_TTL",
2237 sizeof(struct rte_flow_action_of_set_mpls_ttl)),
2238 .next = NEXT(action_of_set_mpls_ttl),
2241 [ACTION_OF_SET_MPLS_TTL_MPLS_TTL] = {
2244 .next = NEXT(action_of_set_mpls_ttl, NEXT_ENTRY(UNSIGNED)),
2245 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_of_set_mpls_ttl,
2247 .call = parse_vc_conf,
2249 [ACTION_OF_DEC_MPLS_TTL] = {
2250 .name = "of_dec_mpls_ttl",
2251 .help = "OpenFlow's OFPAT_DEC_MPLS_TTL",
2252 .priv = PRIV_ACTION(OF_DEC_MPLS_TTL, 0),
2253 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2256 [ACTION_OF_SET_NW_TTL] = {
2257 .name = "of_set_nw_ttl",
2258 .help = "OpenFlow's OFPAT_SET_NW_TTL",
2261 sizeof(struct rte_flow_action_of_set_nw_ttl)),
2262 .next = NEXT(action_of_set_nw_ttl),
2265 [ACTION_OF_SET_NW_TTL_NW_TTL] = {
2268 .next = NEXT(action_of_set_nw_ttl, NEXT_ENTRY(UNSIGNED)),
2269 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_of_set_nw_ttl,
2271 .call = parse_vc_conf,
2273 [ACTION_OF_DEC_NW_TTL] = {
2274 .name = "of_dec_nw_ttl",
2275 .help = "OpenFlow's OFPAT_DEC_NW_TTL",
2276 .priv = PRIV_ACTION(OF_DEC_NW_TTL, 0),
2277 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2280 [ACTION_OF_COPY_TTL_OUT] = {
2281 .name = "of_copy_ttl_out",
2282 .help = "OpenFlow's OFPAT_COPY_TTL_OUT",
2283 .priv = PRIV_ACTION(OF_COPY_TTL_OUT, 0),
2284 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2287 [ACTION_OF_COPY_TTL_IN] = {
2288 .name = "of_copy_ttl_in",
2289 .help = "OpenFlow's OFPAT_COPY_TTL_IN",
2290 .priv = PRIV_ACTION(OF_COPY_TTL_IN, 0),
2291 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2294 [ACTION_OF_POP_VLAN] = {
2295 .name = "of_pop_vlan",
2296 .help = "OpenFlow's OFPAT_POP_VLAN",
2297 .priv = PRIV_ACTION(OF_POP_VLAN, 0),
2298 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2301 [ACTION_OF_PUSH_VLAN] = {
2302 .name = "of_push_vlan",
2303 .help = "OpenFlow's OFPAT_PUSH_VLAN",
2306 sizeof(struct rte_flow_action_of_push_vlan)),
2307 .next = NEXT(action_of_push_vlan),
2310 [ACTION_OF_PUSH_VLAN_ETHERTYPE] = {
2311 .name = "ethertype",
2312 .help = "EtherType",
2313 .next = NEXT(action_of_push_vlan, NEXT_ENTRY(UNSIGNED)),
2314 .args = ARGS(ARGS_ENTRY_HTON
2315 (struct rte_flow_action_of_push_vlan,
2317 .call = parse_vc_conf,
2319 [ACTION_OF_SET_VLAN_VID] = {
2320 .name = "of_set_vlan_vid",
2321 .help = "OpenFlow's OFPAT_SET_VLAN_VID",
2324 sizeof(struct rte_flow_action_of_set_vlan_vid)),
2325 .next = NEXT(action_of_set_vlan_vid),
2328 [ACTION_OF_SET_VLAN_VID_VLAN_VID] = {
2331 .next = NEXT(action_of_set_vlan_vid, NEXT_ENTRY(UNSIGNED)),
2332 .args = ARGS(ARGS_ENTRY_HTON
2333 (struct rte_flow_action_of_set_vlan_vid,
2335 .call = parse_vc_conf,
2337 [ACTION_OF_SET_VLAN_PCP] = {
2338 .name = "of_set_vlan_pcp",
2339 .help = "OpenFlow's OFPAT_SET_VLAN_PCP",
2342 sizeof(struct rte_flow_action_of_set_vlan_pcp)),
2343 .next = NEXT(action_of_set_vlan_pcp),
2346 [ACTION_OF_SET_VLAN_PCP_VLAN_PCP] = {
2348 .help = "VLAN priority",
2349 .next = NEXT(action_of_set_vlan_pcp, NEXT_ENTRY(UNSIGNED)),
2350 .args = ARGS(ARGS_ENTRY_HTON
2351 (struct rte_flow_action_of_set_vlan_pcp,
2353 .call = parse_vc_conf,
2355 [ACTION_OF_POP_MPLS] = {
2356 .name = "of_pop_mpls",
2357 .help = "OpenFlow's OFPAT_POP_MPLS",
2358 .priv = PRIV_ACTION(OF_POP_MPLS,
2359 sizeof(struct rte_flow_action_of_pop_mpls)),
2360 .next = NEXT(action_of_pop_mpls),
2363 [ACTION_OF_POP_MPLS_ETHERTYPE] = {
2364 .name = "ethertype",
2365 .help = "EtherType",
2366 .next = NEXT(action_of_pop_mpls, NEXT_ENTRY(UNSIGNED)),
2367 .args = ARGS(ARGS_ENTRY_HTON
2368 (struct rte_flow_action_of_pop_mpls,
2370 .call = parse_vc_conf,
2372 [ACTION_OF_PUSH_MPLS] = {
2373 .name = "of_push_mpls",
2374 .help = "OpenFlow's OFPAT_PUSH_MPLS",
2377 sizeof(struct rte_flow_action_of_push_mpls)),
2378 .next = NEXT(action_of_push_mpls),
2381 [ACTION_OF_PUSH_MPLS_ETHERTYPE] = {
2382 .name = "ethertype",
2383 .help = "EtherType",
2384 .next = NEXT(action_of_push_mpls, NEXT_ENTRY(UNSIGNED)),
2385 .args = ARGS(ARGS_ENTRY_HTON
2386 (struct rte_flow_action_of_push_mpls,
2388 .call = parse_vc_conf,
2392 /** Remove and return last entry from argument stack. */
2393 static const struct arg *
2394 pop_args(struct context *ctx)
2396 return ctx->args_num ? ctx->args[--ctx->args_num] : NULL;
2399 /** Add entry on top of the argument stack. */
2401 push_args(struct context *ctx, const struct arg *arg)
2403 if (ctx->args_num == CTX_STACK_SIZE)
2405 ctx->args[ctx->args_num++] = arg;
2409 /** Spread value into buffer according to bit-mask. */
2411 arg_entry_bf_fill(void *dst, uintmax_t val, const struct arg *arg)
2413 uint32_t i = arg->size;
2421 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
2430 unsigned int shift = 0;
2431 uint8_t *buf = (uint8_t *)dst + arg->offset + (i -= sub);
2433 for (shift = 0; arg->mask[i] >> shift; ++shift) {
2434 if (!(arg->mask[i] & (1 << shift)))
2439 *buf &= ~(1 << shift);
2440 *buf |= (val & 1) << shift;
2448 /** Compare a string with a partial one of a given length. */
2450 strcmp_partial(const char *full, const char *partial, size_t partial_len)
2452 int r = strncmp(full, partial, partial_len);
2456 if (strlen(full) <= partial_len)
2458 return full[partial_len];
2462 * Parse a prefix length and generate a bit-mask.
2464 * Last argument (ctx->args) is retrieved to determine mask size, storage
2465 * location and whether the result must use network byte ordering.
2468 parse_prefix(struct context *ctx, const struct token *token,
2469 const char *str, unsigned int len,
2470 void *buf, unsigned int size)
2472 const struct arg *arg = pop_args(ctx);
2473 static const uint8_t conv[] = "\x00\x80\xc0\xe0\xf0\xf8\xfc\xfe\xff";
2480 /* Argument is expected. */
2484 u = strtoumax(str, &end, 0);
2485 if (errno || (size_t)(end - str) != len)
2490 extra = arg_entry_bf_fill(NULL, 0, arg);
2499 if (!arg_entry_bf_fill(ctx->object, v, arg) ||
2500 !arg_entry_bf_fill(ctx->objmask, -1, arg))
2507 if (bytes > size || bytes + !!extra > size)
2511 buf = (uint8_t *)ctx->object + arg->offset;
2512 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
2514 memset((uint8_t *)buf + size - bytes, 0xff, bytes);
2515 memset(buf, 0x00, size - bytes);
2517 ((uint8_t *)buf)[size - bytes - 1] = conv[extra];
2521 memset(buf, 0xff, bytes);
2522 memset((uint8_t *)buf + bytes, 0x00, size - bytes);
2524 ((uint8_t *)buf)[bytes] = conv[extra];
2527 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
2530 push_args(ctx, arg);
2534 /** Default parsing function for token name matching. */
2536 parse_default(struct context *ctx, const struct token *token,
2537 const char *str, unsigned int len,
2538 void *buf, unsigned int size)
2543 if (strcmp_partial(token->name, str, len))
2548 /** Parse flow command, initialize output buffer for subsequent tokens. */
2550 parse_init(struct context *ctx, const struct token *token,
2551 const char *str, unsigned int len,
2552 void *buf, unsigned int size)
2554 struct buffer *out = buf;
2556 /* Token name must match. */
2557 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
2559 /* Nothing else to do if there is no buffer. */
2562 /* Make sure buffer is large enough. */
2563 if (size < sizeof(*out))
2565 /* Initialize buffer. */
2566 memset(out, 0x00, sizeof(*out));
2567 memset((uint8_t *)out + sizeof(*out), 0x22, size - sizeof(*out));
2570 ctx->objmask = NULL;
2574 /** Parse tokens for validate/create commands. */
2576 parse_vc(struct context *ctx, const struct token *token,
2577 const char *str, unsigned int len,
2578 void *buf, unsigned int size)
2580 struct buffer *out = buf;
2584 /* Token name must match. */
2585 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
2587 /* Nothing else to do if there is no buffer. */
2590 if (!out->command) {
2591 if (ctx->curr != VALIDATE && ctx->curr != CREATE)
2593 if (sizeof(*out) > size)
2595 out->command = ctx->curr;
2598 ctx->objmask = NULL;
2599 out->args.vc.data = (uint8_t *)out + size;
2603 ctx->object = &out->args.vc.attr;
2604 ctx->objmask = NULL;
2605 switch (ctx->curr) {
2610 out->args.vc.attr.ingress = 1;
2613 out->args.vc.attr.egress = 1;
2616 out->args.vc.attr.transfer = 1;
2619 out->args.vc.pattern =
2620 (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
2622 ctx->object = out->args.vc.pattern;
2623 ctx->objmask = NULL;
2626 out->args.vc.actions =
2627 (void *)RTE_ALIGN_CEIL((uintptr_t)
2628 (out->args.vc.pattern +
2629 out->args.vc.pattern_n),
2631 ctx->object = out->args.vc.actions;
2632 ctx->objmask = NULL;
2639 if (!out->args.vc.actions) {
2640 const struct parse_item_priv *priv = token->priv;
2641 struct rte_flow_item *item =
2642 out->args.vc.pattern + out->args.vc.pattern_n;
2644 data_size = priv->size * 3; /* spec, last, mask */
2645 data = (void *)RTE_ALIGN_FLOOR((uintptr_t)
2646 (out->args.vc.data - data_size),
2648 if ((uint8_t *)item + sizeof(*item) > data)
2650 *item = (struct rte_flow_item){
2653 ++out->args.vc.pattern_n;
2655 ctx->objmask = NULL;
2657 const struct parse_action_priv *priv = token->priv;
2658 struct rte_flow_action *action =
2659 out->args.vc.actions + out->args.vc.actions_n;
2661 data_size = priv->size; /* configuration */
2662 data = (void *)RTE_ALIGN_FLOOR((uintptr_t)
2663 (out->args.vc.data - data_size),
2665 if ((uint8_t *)action + sizeof(*action) > data)
2667 *action = (struct rte_flow_action){
2669 .conf = data_size ? data : NULL,
2671 ++out->args.vc.actions_n;
2672 ctx->object = action;
2673 ctx->objmask = NULL;
2675 memset(data, 0, data_size);
2676 out->args.vc.data = data;
2677 ctx->objdata = data_size;
2681 /** Parse pattern item parameter type. */
2683 parse_vc_spec(struct context *ctx, const struct token *token,
2684 const char *str, unsigned int len,
2685 void *buf, unsigned int size)
2687 struct buffer *out = buf;
2688 struct rte_flow_item *item;
2694 /* Token name must match. */
2695 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
2697 /* Parse parameter types. */
2698 switch (ctx->curr) {
2699 static const enum index prefix[] = NEXT_ENTRY(PREFIX);
2705 case ITEM_PARAM_SPEC:
2708 case ITEM_PARAM_LAST:
2711 case ITEM_PARAM_PREFIX:
2712 /* Modify next token to expect a prefix. */
2713 if (ctx->next_num < 2)
2715 ctx->next[ctx->next_num - 2] = prefix;
2717 case ITEM_PARAM_MASK:
2723 /* Nothing else to do if there is no buffer. */
2726 if (!out->args.vc.pattern_n)
2728 item = &out->args.vc.pattern[out->args.vc.pattern_n - 1];
2729 data_size = ctx->objdata / 3; /* spec, last, mask */
2730 /* Point to selected object. */
2731 ctx->object = out->args.vc.data + (data_size * index);
2733 ctx->objmask = out->args.vc.data + (data_size * 2); /* mask */
2734 item->mask = ctx->objmask;
2736 ctx->objmask = NULL;
2737 /* Update relevant item pointer. */
2738 *((const void **[]){ &item->spec, &item->last, &item->mask })[index] =
2743 /** Parse action configuration field. */
2745 parse_vc_conf(struct context *ctx, const struct token *token,
2746 const char *str, unsigned int len,
2747 void *buf, unsigned int size)
2749 struct buffer *out = buf;
2752 /* Token name must match. */
2753 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
2755 /* Nothing else to do if there is no buffer. */
2758 /* Point to selected object. */
2759 ctx->object = out->args.vc.data;
2760 ctx->objmask = NULL;
2764 /** Parse RSS action. */
2766 parse_vc_action_rss(struct context *ctx, const struct token *token,
2767 const char *str, unsigned int len,
2768 void *buf, unsigned int size)
2770 struct buffer *out = buf;
2771 struct rte_flow_action *action;
2772 struct action_rss_data *action_rss_data;
2776 ret = parse_vc(ctx, token, str, len, buf, size);
2779 /* Nothing else to do if there is no buffer. */
2782 if (!out->args.vc.actions_n)
2784 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
2785 /* Point to selected object. */
2786 ctx->object = out->args.vc.data;
2787 ctx->objmask = NULL;
2788 /* Set up default configuration. */
2789 action_rss_data = ctx->object;
2790 *action_rss_data = (struct action_rss_data){
2791 .conf = (struct rte_flow_action_rss){
2792 .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
2795 .key_len = sizeof(action_rss_data->key),
2796 .queue_num = RTE_MIN(nb_rxq, ACTION_RSS_QUEUE_NUM),
2797 .key = action_rss_data->key,
2798 .queue = action_rss_data->queue,
2800 .key = "testpmd's default RSS hash key, "
2801 "override it for better balancing",
2804 for (i = 0; i < action_rss_data->conf.queue_num; ++i)
2805 action_rss_data->queue[i] = i;
2806 if (!port_id_is_invalid(ctx->port, DISABLED_WARN) &&
2807 ctx->port != (portid_t)RTE_PORT_ALL) {
2808 struct rte_eth_dev_info info;
2810 rte_eth_dev_info_get(ctx->port, &info);
2811 action_rss_data->conf.key_len =
2812 RTE_MIN(sizeof(action_rss_data->key),
2813 info.hash_key_size);
2815 action->conf = &action_rss_data->conf;
2820 * Parse func field for RSS action.
2822 * The RTE_ETH_HASH_FUNCTION_* value to assign is derived from the
2823 * ACTION_RSS_FUNC_* index that called this function.
2826 parse_vc_action_rss_func(struct context *ctx, const struct token *token,
2827 const char *str, unsigned int len,
2828 void *buf, unsigned int size)
2830 struct action_rss_data *action_rss_data;
2831 enum rte_eth_hash_function func;
2835 /* Token name must match. */
2836 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
2838 switch (ctx->curr) {
2839 case ACTION_RSS_FUNC_DEFAULT:
2840 func = RTE_ETH_HASH_FUNCTION_DEFAULT;
2842 case ACTION_RSS_FUNC_TOEPLITZ:
2843 func = RTE_ETH_HASH_FUNCTION_TOEPLITZ;
2845 case ACTION_RSS_FUNC_SIMPLE_XOR:
2846 func = RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
2853 action_rss_data = ctx->object;
2854 action_rss_data->conf.func = func;
2859 * Parse type field for RSS action.
2861 * Valid tokens are type field names and the "end" token.
2864 parse_vc_action_rss_type(struct context *ctx, const struct token *token,
2865 const char *str, unsigned int len,
2866 void *buf, unsigned int size)
2868 static const enum index next[] = NEXT_ENTRY(ACTION_RSS_TYPE);
2869 struct action_rss_data *action_rss_data;
2875 if (ctx->curr != ACTION_RSS_TYPE)
2877 if (!(ctx->objdata >> 16) && ctx->object) {
2878 action_rss_data = ctx->object;
2879 action_rss_data->conf.types = 0;
2881 if (!strcmp_partial("end", str, len)) {
2882 ctx->objdata &= 0xffff;
2885 for (i = 0; rss_type_table[i].str; ++i)
2886 if (!strcmp_partial(rss_type_table[i].str, str, len))
2888 if (!rss_type_table[i].str)
2890 ctx->objdata = 1 << 16 | (ctx->objdata & 0xffff);
2892 if (ctx->next_num == RTE_DIM(ctx->next))
2894 ctx->next[ctx->next_num++] = next;
2897 action_rss_data = ctx->object;
2898 action_rss_data->conf.types |= rss_type_table[i].rss_type;
2903 * Parse queue field for RSS action.
2905 * Valid tokens are queue indices and the "end" token.
2908 parse_vc_action_rss_queue(struct context *ctx, const struct token *token,
2909 const char *str, unsigned int len,
2910 void *buf, unsigned int size)
2912 static const enum index next[] = NEXT_ENTRY(ACTION_RSS_QUEUE);
2913 struct action_rss_data *action_rss_data;
2920 if (ctx->curr != ACTION_RSS_QUEUE)
2922 i = ctx->objdata >> 16;
2923 if (!strcmp_partial("end", str, len)) {
2924 ctx->objdata &= 0xffff;
2927 if (i >= ACTION_RSS_QUEUE_NUM)
2930 ARGS_ENTRY_ARB(offsetof(struct action_rss_data, queue) +
2931 i * sizeof(action_rss_data->queue[i]),
2932 sizeof(action_rss_data->queue[i]))))
2934 ret = parse_int(ctx, token, str, len, NULL, 0);
2940 ctx->objdata = i << 16 | (ctx->objdata & 0xffff);
2942 if (ctx->next_num == RTE_DIM(ctx->next))
2944 ctx->next[ctx->next_num++] = next;
2948 action_rss_data = ctx->object;
2949 action_rss_data->conf.queue_num = i;
2950 action_rss_data->conf.queue = i ? action_rss_data->queue : NULL;
2954 /** Parse tokens for destroy command. */
2956 parse_destroy(struct context *ctx, const struct token *token,
2957 const char *str, unsigned int len,
2958 void *buf, unsigned int size)
2960 struct buffer *out = buf;
2962 /* Token name must match. */
2963 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
2965 /* Nothing else to do if there is no buffer. */
2968 if (!out->command) {
2969 if (ctx->curr != DESTROY)
2971 if (sizeof(*out) > size)
2973 out->command = ctx->curr;
2976 ctx->objmask = NULL;
2977 out->args.destroy.rule =
2978 (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
2982 if (((uint8_t *)(out->args.destroy.rule + out->args.destroy.rule_n) +
2983 sizeof(*out->args.destroy.rule)) > (uint8_t *)out + size)
2986 ctx->object = out->args.destroy.rule + out->args.destroy.rule_n++;
2987 ctx->objmask = NULL;
2991 /** Parse tokens for flush command. */
2993 parse_flush(struct context *ctx, const struct token *token,
2994 const char *str, unsigned int len,
2995 void *buf, unsigned int size)
2997 struct buffer *out = buf;
2999 /* Token name must match. */
3000 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
3002 /* Nothing else to do if there is no buffer. */
3005 if (!out->command) {
3006 if (ctx->curr != FLUSH)
3008 if (sizeof(*out) > size)
3010 out->command = ctx->curr;
3013 ctx->objmask = NULL;
3018 /** Parse tokens for query command. */
3020 parse_query(struct context *ctx, const struct token *token,
3021 const char *str, unsigned int len,
3022 void *buf, unsigned int size)
3024 struct buffer *out = buf;
3026 /* Token name must match. */
3027 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
3029 /* Nothing else to do if there is no buffer. */
3032 if (!out->command) {
3033 if (ctx->curr != QUERY)
3035 if (sizeof(*out) > size)
3037 out->command = ctx->curr;
3040 ctx->objmask = NULL;
3045 /** Parse action names. */
3047 parse_action(struct context *ctx, const struct token *token,
3048 const char *str, unsigned int len,
3049 void *buf, unsigned int size)
3051 struct buffer *out = buf;
3052 const struct arg *arg = pop_args(ctx);
3056 /* Argument is expected. */
3059 /* Parse action name. */
3060 for (i = 0; next_action[i]; ++i) {
3061 const struct parse_action_priv *priv;
3063 token = &token_list[next_action[i]];
3064 if (strcmp_partial(token->name, str, len))
3070 memcpy((uint8_t *)ctx->object + arg->offset,
3076 push_args(ctx, arg);
3080 /** Parse tokens for list command. */
3082 parse_list(struct context *ctx, const struct token *token,
3083 const char *str, unsigned int len,
3084 void *buf, unsigned int size)
3086 struct buffer *out = buf;
3088 /* Token name must match. */
3089 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
3091 /* Nothing else to do if there is no buffer. */
3094 if (!out->command) {
3095 if (ctx->curr != LIST)
3097 if (sizeof(*out) > size)
3099 out->command = ctx->curr;
3102 ctx->objmask = NULL;
3103 out->args.list.group =
3104 (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
3108 if (((uint8_t *)(out->args.list.group + out->args.list.group_n) +
3109 sizeof(*out->args.list.group)) > (uint8_t *)out + size)
3112 ctx->object = out->args.list.group + out->args.list.group_n++;
3113 ctx->objmask = NULL;
3117 /** Parse tokens for isolate command. */
3119 parse_isolate(struct context *ctx, const struct token *token,
3120 const char *str, unsigned int len,
3121 void *buf, unsigned int size)
3123 struct buffer *out = buf;
3125 /* Token name must match. */
3126 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
3128 /* Nothing else to do if there is no buffer. */
3131 if (!out->command) {
3132 if (ctx->curr != ISOLATE)
3134 if (sizeof(*out) > size)
3136 out->command = ctx->curr;
3139 ctx->objmask = NULL;
3145 * Parse signed/unsigned integers 8 to 64-bit long.
3147 * Last argument (ctx->args) is retrieved to determine integer type and
3151 parse_int(struct context *ctx, const struct token *token,
3152 const char *str, unsigned int len,
3153 void *buf, unsigned int size)
3155 const struct arg *arg = pop_args(ctx);
3160 /* Argument is expected. */
3165 (uintmax_t)strtoimax(str, &end, 0) :
3166 strtoumax(str, &end, 0);
3167 if (errno || (size_t)(end - str) != len)
3170 ((arg->sign && ((intmax_t)u < (intmax_t)arg->min ||
3171 (intmax_t)u > (intmax_t)arg->max)) ||
3172 (!arg->sign && (u < arg->min || u > arg->max))))
3177 if (!arg_entry_bf_fill(ctx->object, u, arg) ||
3178 !arg_entry_bf_fill(ctx->objmask, -1, arg))
3182 buf = (uint8_t *)ctx->object + arg->offset;
3186 case sizeof(uint8_t):
3187 *(uint8_t *)buf = u;
3189 case sizeof(uint16_t):
3190 *(uint16_t *)buf = arg->hton ? rte_cpu_to_be_16(u) : u;
3192 case sizeof(uint8_t [3]):
3193 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
3195 ((uint8_t *)buf)[0] = u;
3196 ((uint8_t *)buf)[1] = u >> 8;
3197 ((uint8_t *)buf)[2] = u >> 16;
3201 ((uint8_t *)buf)[0] = u >> 16;
3202 ((uint8_t *)buf)[1] = u >> 8;
3203 ((uint8_t *)buf)[2] = u;
3205 case sizeof(uint32_t):
3206 *(uint32_t *)buf = arg->hton ? rte_cpu_to_be_32(u) : u;
3208 case sizeof(uint64_t):
3209 *(uint64_t *)buf = arg->hton ? rte_cpu_to_be_64(u) : u;
3214 if (ctx->objmask && buf != (uint8_t *)ctx->objmask + arg->offset) {
3216 buf = (uint8_t *)ctx->objmask + arg->offset;
3221 push_args(ctx, arg);
3228 * Three arguments (ctx->args) are retrieved from the stack to store data,
3229 * its actual length and address (in that order).
3232 parse_string(struct context *ctx, const struct token *token,
3233 const char *str, unsigned int len,
3234 void *buf, unsigned int size)
3236 const struct arg *arg_data = pop_args(ctx);
3237 const struct arg *arg_len = pop_args(ctx);
3238 const struct arg *arg_addr = pop_args(ctx);
3239 char tmp[16]; /* Ought to be enough. */
3242 /* Arguments are expected. */
3246 push_args(ctx, arg_data);
3250 push_args(ctx, arg_len);
3251 push_args(ctx, arg_data);
3254 size = arg_data->size;
3255 /* Bit-mask fill is not supported. */
3256 if (arg_data->mask || size < len)
3260 /* Let parse_int() fill length information first. */
3261 ret = snprintf(tmp, sizeof(tmp), "%u", len);
3264 push_args(ctx, arg_len);
3265 ret = parse_int(ctx, token, tmp, ret, NULL, 0);
3270 buf = (uint8_t *)ctx->object + arg_data->offset;
3271 /* Output buffer is not necessarily NUL-terminated. */
3272 memcpy(buf, str, len);
3273 memset((uint8_t *)buf + len, 0x00, size - len);
3275 memset((uint8_t *)ctx->objmask + arg_data->offset, 0xff, len);
3276 /* Save address if requested. */
3277 if (arg_addr->size) {
3278 memcpy((uint8_t *)ctx->object + arg_addr->offset,
3280 (uint8_t *)ctx->object + arg_data->offset
3284 memcpy((uint8_t *)ctx->objmask + arg_addr->offset,
3286 (uint8_t *)ctx->objmask + arg_data->offset
3292 push_args(ctx, arg_addr);
3293 push_args(ctx, arg_len);
3294 push_args(ctx, arg_data);
3299 * Parse a MAC address.
3301 * Last argument (ctx->args) is retrieved to determine storage size and
3305 parse_mac_addr(struct context *ctx, const struct token *token,
3306 const char *str, unsigned int len,
3307 void *buf, unsigned int size)
3309 const struct arg *arg = pop_args(ctx);
3310 struct ether_addr tmp;
3314 /* Argument is expected. */
3318 /* Bit-mask fill is not supported. */
3319 if (arg->mask || size != sizeof(tmp))
3321 /* Only network endian is supported. */
3324 ret = cmdline_parse_etheraddr(NULL, str, &tmp, size);
3325 if (ret < 0 || (unsigned int)ret != len)
3329 buf = (uint8_t *)ctx->object + arg->offset;
3330 memcpy(buf, &tmp, size);
3332 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
3335 push_args(ctx, arg);
3340 * Parse an IPv4 address.
3342 * Last argument (ctx->args) is retrieved to determine storage size and
3346 parse_ipv4_addr(struct context *ctx, const struct token *token,
3347 const char *str, unsigned int len,
3348 void *buf, unsigned int size)
3350 const struct arg *arg = pop_args(ctx);
3355 /* Argument is expected. */
3359 /* Bit-mask fill is not supported. */
3360 if (arg->mask || size != sizeof(tmp))
3362 /* Only network endian is supported. */
3365 memcpy(str2, str, len);
3367 ret = inet_pton(AF_INET, str2, &tmp);
3369 /* Attempt integer parsing. */
3370 push_args(ctx, arg);
3371 return parse_int(ctx, token, str, len, buf, size);
3375 buf = (uint8_t *)ctx->object + arg->offset;
3376 memcpy(buf, &tmp, size);
3378 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
3381 push_args(ctx, arg);
3386 * Parse an IPv6 address.
3388 * Last argument (ctx->args) is retrieved to determine storage size and
3392 parse_ipv6_addr(struct context *ctx, const struct token *token,
3393 const char *str, unsigned int len,
3394 void *buf, unsigned int size)
3396 const struct arg *arg = pop_args(ctx);
3398 struct in6_addr tmp;
3402 /* Argument is expected. */
3406 /* Bit-mask fill is not supported. */
3407 if (arg->mask || size != sizeof(tmp))
3409 /* Only network endian is supported. */
3412 memcpy(str2, str, len);
3414 ret = inet_pton(AF_INET6, str2, &tmp);
3419 buf = (uint8_t *)ctx->object + arg->offset;
3420 memcpy(buf, &tmp, size);
3422 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
3425 push_args(ctx, arg);
3429 /** Boolean values (even indices stand for false). */
3430 static const char *const boolean_name[] = {
3440 * Parse a boolean value.
3442 * Last argument (ctx->args) is retrieved to determine storage size and
3446 parse_boolean(struct context *ctx, const struct token *token,
3447 const char *str, unsigned int len,
3448 void *buf, unsigned int size)
3450 const struct arg *arg = pop_args(ctx);
3454 /* Argument is expected. */
3457 for (i = 0; boolean_name[i]; ++i)
3458 if (!strcmp_partial(boolean_name[i], str, len))
3460 /* Process token as integer. */
3461 if (boolean_name[i])
3462 str = i & 1 ? "1" : "0";
3463 push_args(ctx, arg);
3464 ret = parse_int(ctx, token, str, strlen(str), buf, size);
3465 return ret > 0 ? (int)len : ret;
3468 /** Parse port and update context. */
3470 parse_port(struct context *ctx, const struct token *token,
3471 const char *str, unsigned int len,
3472 void *buf, unsigned int size)
3474 struct buffer *out = &(struct buffer){ .port = 0 };
3482 ctx->objmask = NULL;
3483 size = sizeof(*out);
3485 ret = parse_int(ctx, token, str, len, out, size);
3487 ctx->port = out->port;
3493 /** No completion. */
3495 comp_none(struct context *ctx, const struct token *token,
3496 unsigned int ent, char *buf, unsigned int size)
3506 /** Complete boolean values. */
3508 comp_boolean(struct context *ctx, const struct token *token,
3509 unsigned int ent, char *buf, unsigned int size)
3515 for (i = 0; boolean_name[i]; ++i)
3516 if (buf && i == ent)
3517 return snprintf(buf, size, "%s", boolean_name[i]);
3523 /** Complete action names. */
3525 comp_action(struct context *ctx, const struct token *token,
3526 unsigned int ent, char *buf, unsigned int size)
3532 for (i = 0; next_action[i]; ++i)
3533 if (buf && i == ent)
3534 return snprintf(buf, size, "%s",
3535 token_list[next_action[i]].name);
3541 /** Complete available ports. */
3543 comp_port(struct context *ctx, const struct token *token,
3544 unsigned int ent, char *buf, unsigned int size)
3551 RTE_ETH_FOREACH_DEV(p) {
3552 if (buf && i == ent)
3553 return snprintf(buf, size, "%u", p);
3561 /** Complete available rule IDs. */
3563 comp_rule_id(struct context *ctx, const struct token *token,
3564 unsigned int ent, char *buf, unsigned int size)
3567 struct rte_port *port;
3568 struct port_flow *pf;
3571 if (port_id_is_invalid(ctx->port, DISABLED_WARN) ||
3572 ctx->port == (portid_t)RTE_PORT_ALL)
3574 port = &ports[ctx->port];
3575 for (pf = port->flow_list; pf != NULL; pf = pf->next) {
3576 if (buf && i == ent)
3577 return snprintf(buf, size, "%u", pf->id);
3585 /** Complete type field for RSS action. */
3587 comp_vc_action_rss_type(struct context *ctx, const struct token *token,
3588 unsigned int ent, char *buf, unsigned int size)
3594 for (i = 0; rss_type_table[i].str; ++i)
3599 return snprintf(buf, size, "%s", rss_type_table[ent].str);
3601 return snprintf(buf, size, "end");
3605 /** Complete queue field for RSS action. */
3607 comp_vc_action_rss_queue(struct context *ctx, const struct token *token,
3608 unsigned int ent, char *buf, unsigned int size)
3615 return snprintf(buf, size, "%u", ent);
3617 return snprintf(buf, size, "end");
3621 /** Internal context. */
3622 static struct context cmd_flow_context;
3624 /** Global parser instance (cmdline API). */
3625 cmdline_parse_inst_t cmd_flow;
3627 /** Initialize context. */
3629 cmd_flow_context_init(struct context *ctx)
3631 /* A full memset() is not necessary. */
3641 ctx->objmask = NULL;
3644 /** Parse a token (cmdline API). */
3646 cmd_flow_parse(cmdline_parse_token_hdr_t *hdr, const char *src, void *result,
3649 struct context *ctx = &cmd_flow_context;
3650 const struct token *token;
3651 const enum index *list;
3656 token = &token_list[ctx->curr];
3657 /* Check argument length. */
3660 for (len = 0; src[len]; ++len)
3661 if (src[len] == '#' || isspace(src[len]))
3665 /* Last argument and EOL detection. */
3666 for (i = len; src[i]; ++i)
3667 if (src[i] == '#' || src[i] == '\r' || src[i] == '\n')
3669 else if (!isspace(src[i])) {
3674 if (src[i] == '\r' || src[i] == '\n') {
3678 /* Initialize context if necessary. */
3679 if (!ctx->next_num) {
3682 ctx->next[ctx->next_num++] = token->next[0];
3684 /* Process argument through candidates. */
3685 ctx->prev = ctx->curr;
3686 list = ctx->next[ctx->next_num - 1];
3687 for (i = 0; list[i]; ++i) {
3688 const struct token *next = &token_list[list[i]];
3691 ctx->curr = list[i];
3693 tmp = next->call(ctx, next, src, len, result, size);
3695 tmp = parse_default(ctx, next, src, len, result, size);
3696 if (tmp == -1 || tmp != len)
3704 /* Push subsequent tokens if any. */
3706 for (i = 0; token->next[i]; ++i) {
3707 if (ctx->next_num == RTE_DIM(ctx->next))
3709 ctx->next[ctx->next_num++] = token->next[i];
3711 /* Push arguments if any. */
3713 for (i = 0; token->args[i]; ++i) {
3714 if (ctx->args_num == RTE_DIM(ctx->args))
3716 ctx->args[ctx->args_num++] = token->args[i];
3721 /** Return number of completion entries (cmdline API). */
3723 cmd_flow_complete_get_nb(cmdline_parse_token_hdr_t *hdr)
3725 struct context *ctx = &cmd_flow_context;
3726 const struct token *token = &token_list[ctx->curr];
3727 const enum index *list;
3731 /* Count number of tokens in current list. */
3733 list = ctx->next[ctx->next_num - 1];
3735 list = token->next[0];
3736 for (i = 0; list[i]; ++i)
3741 * If there is a single token, use its completion callback, otherwise
3742 * return the number of entries.
3744 token = &token_list[list[0]];
3745 if (i == 1 && token->comp) {
3746 /* Save index for cmd_flow_get_help(). */
3747 ctx->prev = list[0];
3748 return token->comp(ctx, token, 0, NULL, 0);
3753 /** Return a completion entry (cmdline API). */
3755 cmd_flow_complete_get_elt(cmdline_parse_token_hdr_t *hdr, int index,
3756 char *dst, unsigned int size)
3758 struct context *ctx = &cmd_flow_context;
3759 const struct token *token = &token_list[ctx->curr];
3760 const enum index *list;
3764 /* Count number of tokens in current list. */
3766 list = ctx->next[ctx->next_num - 1];
3768 list = token->next[0];
3769 for (i = 0; list[i]; ++i)
3773 /* If there is a single token, use its completion callback. */
3774 token = &token_list[list[0]];
3775 if (i == 1 && token->comp) {
3776 /* Save index for cmd_flow_get_help(). */
3777 ctx->prev = list[0];
3778 return token->comp(ctx, token, index, dst, size) < 0 ? -1 : 0;
3780 /* Otherwise make sure the index is valid and use defaults. */
3783 token = &token_list[list[index]];
3784 snprintf(dst, size, "%s", token->name);
3785 /* Save index for cmd_flow_get_help(). */
3786 ctx->prev = list[index];
3790 /** Populate help strings for current token (cmdline API). */
3792 cmd_flow_get_help(cmdline_parse_token_hdr_t *hdr, char *dst, unsigned int size)
3794 struct context *ctx = &cmd_flow_context;
3795 const struct token *token = &token_list[ctx->prev];
3800 /* Set token type and update global help with details. */
3801 snprintf(dst, size, "%s", (token->type ? token->type : "TOKEN"));
3803 cmd_flow.help_str = token->help;
3805 cmd_flow.help_str = token->name;
3809 /** Token definition template (cmdline API). */
3810 static struct cmdline_token_hdr cmd_flow_token_hdr = {
3811 .ops = &(struct cmdline_token_ops){
3812 .parse = cmd_flow_parse,
3813 .complete_get_nb = cmd_flow_complete_get_nb,
3814 .complete_get_elt = cmd_flow_complete_get_elt,
3815 .get_help = cmd_flow_get_help,
3820 /** Populate the next dynamic token. */
3822 cmd_flow_tok(cmdline_parse_token_hdr_t **hdr,
3823 cmdline_parse_token_hdr_t **hdr_inst)
3825 struct context *ctx = &cmd_flow_context;
3827 /* Always reinitialize context before requesting the first token. */
3828 if (!(hdr_inst - cmd_flow.tokens))
3829 cmd_flow_context_init(ctx);
3830 /* Return NULL when no more tokens are expected. */
3831 if (!ctx->next_num && ctx->curr) {
3835 /* Determine if command should end here. */
3836 if (ctx->eol && ctx->last && ctx->next_num) {
3837 const enum index *list = ctx->next[ctx->next_num - 1];
3840 for (i = 0; list[i]; ++i) {
3847 *hdr = &cmd_flow_token_hdr;
3850 /** Dispatch parsed buffer to function calls. */
3852 cmd_flow_parsed(const struct buffer *in)
3854 switch (in->command) {
3856 port_flow_validate(in->port, &in->args.vc.attr,
3857 in->args.vc.pattern, in->args.vc.actions);
3860 port_flow_create(in->port, &in->args.vc.attr,
3861 in->args.vc.pattern, in->args.vc.actions);
3864 port_flow_destroy(in->port, in->args.destroy.rule_n,
3865 in->args.destroy.rule);
3868 port_flow_flush(in->port);
3871 port_flow_query(in->port, in->args.query.rule,
3872 &in->args.query.action);
3875 port_flow_list(in->port, in->args.list.group_n,
3876 in->args.list.group);
3879 port_flow_isolate(in->port, in->args.isolate.set);
3886 /** Token generator and output processing callback (cmdline API). */
3888 cmd_flow_cb(void *arg0, struct cmdline *cl, void *arg2)
3891 cmd_flow_tok(arg0, arg2);
3893 cmd_flow_parsed(arg0);
3896 /** Global parser instance (cmdline API). */
3897 cmdline_parse_inst_t cmd_flow = {
3899 .data = NULL, /**< Unused. */
3900 .help_str = NULL, /**< Updated by cmd_flow_get_help(). */
3903 }, /**< Tokens are returned by cmd_flow_tok(). */