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. */
196 ACTION_RSS_FUNC_DEFAULT,
197 ACTION_RSS_FUNC_TOEPLITZ,
198 ACTION_RSS_FUNC_SIMPLE_XOR,
210 ACTION_PHY_PORT_ORIGINAL,
211 ACTION_PHY_PORT_INDEX,
213 ACTION_PORT_ID_ORIGINAL,
217 ACTION_OF_SET_MPLS_TTL,
218 ACTION_OF_SET_MPLS_TTL_MPLS_TTL,
219 ACTION_OF_DEC_MPLS_TTL,
220 ACTION_OF_SET_NW_TTL,
221 ACTION_OF_SET_NW_TTL_NW_TTL,
222 ACTION_OF_DEC_NW_TTL,
223 ACTION_OF_COPY_TTL_OUT,
224 ACTION_OF_COPY_TTL_IN,
227 /** Maximum size for pattern in struct rte_flow_item_raw. */
228 #define ITEM_RAW_PATTERN_SIZE 40
230 /** Storage size for struct rte_flow_item_raw including pattern. */
231 #define ITEM_RAW_SIZE \
232 (sizeof(struct rte_flow_item_raw) + ITEM_RAW_PATTERN_SIZE)
234 /** Maximum number of queue indices in struct rte_flow_action_rss. */
235 #define ACTION_RSS_QUEUE_NUM 32
237 /** Storage for struct rte_flow_action_rss including external data. */
238 struct action_rss_data {
239 struct rte_flow_action_rss conf;
240 uint8_t key[RSS_HASH_KEY_LENGTH];
241 uint16_t queue[ACTION_RSS_QUEUE_NUM];
244 /** Maximum number of subsequent tokens and arguments on the stack. */
245 #define CTX_STACK_SIZE 16
247 /** Parser context. */
249 /** Stack of subsequent token lists to process. */
250 const enum index *next[CTX_STACK_SIZE];
251 /** Arguments for stacked tokens. */
252 const void *args[CTX_STACK_SIZE];
253 enum index curr; /**< Current token index. */
254 enum index prev; /**< Index of the last token seen. */
255 int next_num; /**< Number of entries in next[]. */
256 int args_num; /**< Number of entries in args[]. */
257 uint32_t eol:1; /**< EOL has been detected. */
258 uint32_t last:1; /**< No more arguments. */
259 portid_t port; /**< Current port ID (for completions). */
260 uint32_t objdata; /**< Object-specific data. */
261 void *object; /**< Address of current object for relative offsets. */
262 void *objmask; /**< Object a full mask must be written to. */
265 /** Token argument. */
267 uint32_t hton:1; /**< Use network byte ordering. */
268 uint32_t sign:1; /**< Value is signed. */
269 uint32_t bounded:1; /**< Value is bounded. */
270 uintmax_t min; /**< Minimum value if bounded. */
271 uintmax_t max; /**< Maximum value if bounded. */
272 uint32_t offset; /**< Relative offset from ctx->object. */
273 uint32_t size; /**< Field size. */
274 const uint8_t *mask; /**< Bit-mask to use instead of offset/size. */
277 /** Parser token definition. */
279 /** Type displayed during completion (defaults to "TOKEN"). */
281 /** Help displayed during completion (defaults to token name). */
283 /** Private data used by parser functions. */
286 * Lists of subsequent tokens to push on the stack. Each call to the
287 * parser consumes the last entry of that stack.
289 const enum index *const *next;
290 /** Arguments stack for subsequent tokens that need them. */
291 const struct arg *const *args;
293 * Token-processing callback, returns -1 in case of error, the
294 * length of the matched string otherwise. If NULL, attempts to
295 * match the token name.
297 * If buf is not NULL, the result should be stored in it according
298 * to context. An error is returned if not large enough.
300 int (*call)(struct context *ctx, const struct token *token,
301 const char *str, unsigned int len,
302 void *buf, unsigned int size);
304 * Callback that provides possible values for this token, used for
305 * completion. Returns -1 in case of error, the number of possible
306 * values otherwise. If NULL, the token name is used.
308 * If buf is not NULL, entry index ent is written to buf and the
309 * full length of the entry is returned (same behavior as
312 int (*comp)(struct context *ctx, const struct token *token,
313 unsigned int ent, char *buf, unsigned int size);
314 /** Mandatory token name, no default value. */
318 /** Static initializer for the next field. */
319 #define NEXT(...) (const enum index *const []){ __VA_ARGS__, NULL, }
321 /** Static initializer for a NEXT() entry. */
322 #define NEXT_ENTRY(...) (const enum index []){ __VA_ARGS__, ZERO, }
324 /** Static initializer for the args field. */
325 #define ARGS(...) (const struct arg *const []){ __VA_ARGS__, NULL, }
327 /** Static initializer for ARGS() to target a field. */
328 #define ARGS_ENTRY(s, f) \
329 (&(const struct arg){ \
330 .offset = offsetof(s, f), \
331 .size = sizeof(((s *)0)->f), \
334 /** Static initializer for ARGS() to target a bit-field. */
335 #define ARGS_ENTRY_BF(s, f, b) \
336 (&(const struct arg){ \
338 .mask = (const void *)&(const s){ .f = (1 << (b)) - 1 }, \
341 /** Static initializer for ARGS() to target an arbitrary bit-mask. */
342 #define ARGS_ENTRY_MASK(s, f, m) \
343 (&(const struct arg){ \
344 .offset = offsetof(s, f), \
345 .size = sizeof(((s *)0)->f), \
346 .mask = (const void *)(m), \
349 /** Same as ARGS_ENTRY_MASK() using network byte ordering for the value. */
350 #define ARGS_ENTRY_MASK_HTON(s, f, m) \
351 (&(const struct arg){ \
353 .offset = offsetof(s, f), \
354 .size = sizeof(((s *)0)->f), \
355 .mask = (const void *)(m), \
358 /** Static initializer for ARGS() to target a pointer. */
359 #define ARGS_ENTRY_PTR(s, f) \
360 (&(const struct arg){ \
361 .size = sizeof(*((s *)0)->f), \
364 /** Static initializer for ARGS() with arbitrary offset and size. */
365 #define ARGS_ENTRY_ARB(o, s) \
366 (&(const struct arg){ \
371 /** Same as ARGS_ENTRY_ARB() with bounded values. */
372 #define ARGS_ENTRY_ARB_BOUNDED(o, s, i, a) \
373 (&(const struct arg){ \
381 /** Same as ARGS_ENTRY() using network byte ordering. */
382 #define ARGS_ENTRY_HTON(s, f) \
383 (&(const struct arg){ \
385 .offset = offsetof(s, f), \
386 .size = sizeof(((s *)0)->f), \
389 /** Parser output buffer layout expected by cmd_flow_parsed(). */
391 enum index command; /**< Flow command. */
392 portid_t port; /**< Affected port ID. */
395 struct rte_flow_attr attr;
396 struct rte_flow_item *pattern;
397 struct rte_flow_action *actions;
401 } vc; /**< Validate/create arguments. */
405 } destroy; /**< Destroy arguments. */
408 enum rte_flow_action_type action;
409 } query; /**< Query arguments. */
413 } list; /**< List arguments. */
416 } isolate; /**< Isolated mode arguments. */
417 } args; /**< Command arguments. */
420 /** Private data for pattern items. */
421 struct parse_item_priv {
422 enum rte_flow_item_type type; /**< Item type. */
423 uint32_t size; /**< Size of item specification structure. */
426 #define PRIV_ITEM(t, s) \
427 (&(const struct parse_item_priv){ \
428 .type = RTE_FLOW_ITEM_TYPE_ ## t, \
432 /** Private data for actions. */
433 struct parse_action_priv {
434 enum rte_flow_action_type type; /**< Action type. */
435 uint32_t size; /**< Size of action configuration structure. */
438 #define PRIV_ACTION(t, s) \
439 (&(const struct parse_action_priv){ \
440 .type = RTE_FLOW_ACTION_TYPE_ ## t, \
444 static const enum index next_vc_attr[] = {
454 static const enum index next_destroy_attr[] = {
460 static const enum index next_list_attr[] = {
466 static const enum index item_param[] = {
475 static const enum index next_item[] = {
510 ITEM_ICMP6_ND_OPT_SLA_ETH,
511 ITEM_ICMP6_ND_OPT_TLA_ETH,
515 static const enum index item_fuzzy[] = {
521 static const enum index item_any[] = {
527 static const enum index item_vf[] = {
533 static const enum index item_phy_port[] = {
539 static const enum index item_port_id[] = {
545 static const enum index item_raw[] = {
555 static const enum index item_eth[] = {
563 static const enum index item_vlan[] = {
568 ITEM_VLAN_INNER_TYPE,
573 static const enum index item_ipv4[] = {
583 static const enum index item_ipv6[] = {
594 static const enum index item_icmp[] = {
601 static const enum index item_udp[] = {
608 static const enum index item_tcp[] = {
616 static const enum index item_sctp[] = {
625 static const enum index item_vxlan[] = {
631 static const enum index item_e_tag[] = {
632 ITEM_E_TAG_GRP_ECID_B,
637 static const enum index item_nvgre[] = {
643 static const enum index item_mpls[] = {
649 static const enum index item_gre[] = {
655 static const enum index item_gtp[] = {
661 static const enum index item_geneve[] = {
668 static const enum index item_vxlan_gpe[] = {
674 static const enum index item_arp_eth_ipv4[] = {
675 ITEM_ARP_ETH_IPV4_SHA,
676 ITEM_ARP_ETH_IPV4_SPA,
677 ITEM_ARP_ETH_IPV4_THA,
678 ITEM_ARP_ETH_IPV4_TPA,
683 static const enum index item_ipv6_ext[] = {
684 ITEM_IPV6_EXT_NEXT_HDR,
689 static const enum index item_icmp6[] = {
696 static const enum index item_icmp6_nd_ns[] = {
697 ITEM_ICMP6_ND_NS_TARGET_ADDR,
702 static const enum index item_icmp6_nd_na[] = {
703 ITEM_ICMP6_ND_NA_TARGET_ADDR,
708 static const enum index item_icmp6_nd_opt[] = {
709 ITEM_ICMP6_ND_OPT_TYPE,
714 static const enum index item_icmp6_nd_opt_sla_eth[] = {
715 ITEM_ICMP6_ND_OPT_SLA_ETH_SLA,
720 static const enum index item_icmp6_nd_opt_tla_eth[] = {
721 ITEM_ICMP6_ND_OPT_TLA_ETH_TLA,
726 static const enum index next_action[] = {
741 ACTION_OF_SET_MPLS_TTL,
742 ACTION_OF_DEC_MPLS_TTL,
743 ACTION_OF_SET_NW_TTL,
744 ACTION_OF_DEC_NW_TTL,
745 ACTION_OF_COPY_TTL_OUT,
746 ACTION_OF_COPY_TTL_IN,
750 static const enum index action_mark[] = {
756 static const enum index action_queue[] = {
762 static const enum index action_rss[] = {
773 static const enum index action_vf[] = {
780 static const enum index action_phy_port[] = {
781 ACTION_PHY_PORT_ORIGINAL,
782 ACTION_PHY_PORT_INDEX,
787 static const enum index action_port_id[] = {
788 ACTION_PORT_ID_ORIGINAL,
794 static const enum index action_meter[] = {
800 static const enum index action_of_set_mpls_ttl[] = {
801 ACTION_OF_SET_MPLS_TTL_MPLS_TTL,
806 static const enum index action_of_set_nw_ttl[] = {
807 ACTION_OF_SET_NW_TTL_NW_TTL,
812 static int parse_init(struct context *, const struct token *,
813 const char *, unsigned int,
814 void *, unsigned int);
815 static int parse_vc(struct context *, const struct token *,
816 const char *, unsigned int,
817 void *, unsigned int);
818 static int parse_vc_spec(struct context *, const struct token *,
819 const char *, unsigned int, void *, unsigned int);
820 static int parse_vc_conf(struct context *, const struct token *,
821 const char *, unsigned int, void *, unsigned int);
822 static int parse_vc_action_rss(struct context *, const struct token *,
823 const char *, unsigned int, void *,
825 static int parse_vc_action_rss_func(struct context *, const struct token *,
826 const char *, unsigned int, void *,
828 static int parse_vc_action_rss_type(struct context *, const struct token *,
829 const char *, unsigned int, void *,
831 static int parse_vc_action_rss_queue(struct context *, const struct token *,
832 const char *, unsigned int, void *,
834 static int parse_destroy(struct context *, const struct token *,
835 const char *, unsigned int,
836 void *, unsigned int);
837 static int parse_flush(struct context *, const struct token *,
838 const char *, unsigned int,
839 void *, unsigned int);
840 static int parse_query(struct context *, const struct token *,
841 const char *, unsigned int,
842 void *, unsigned int);
843 static int parse_action(struct context *, const struct token *,
844 const char *, unsigned int,
845 void *, unsigned int);
846 static int parse_list(struct context *, const struct token *,
847 const char *, unsigned int,
848 void *, unsigned int);
849 static int parse_isolate(struct context *, const struct token *,
850 const char *, unsigned int,
851 void *, unsigned int);
852 static int parse_int(struct context *, const struct token *,
853 const char *, unsigned int,
854 void *, unsigned int);
855 static int parse_prefix(struct context *, const struct token *,
856 const char *, unsigned int,
857 void *, unsigned int);
858 static int parse_boolean(struct context *, const struct token *,
859 const char *, unsigned int,
860 void *, unsigned int);
861 static int parse_string(struct context *, const struct token *,
862 const char *, unsigned int,
863 void *, unsigned int);
864 static int parse_mac_addr(struct context *, const struct token *,
865 const char *, unsigned int,
866 void *, unsigned int);
867 static int parse_ipv4_addr(struct context *, const struct token *,
868 const char *, unsigned int,
869 void *, unsigned int);
870 static int parse_ipv6_addr(struct context *, const struct token *,
871 const char *, unsigned int,
872 void *, unsigned int);
873 static int parse_port(struct context *, const struct token *,
874 const char *, unsigned int,
875 void *, unsigned int);
876 static int comp_none(struct context *, const struct token *,
877 unsigned int, char *, unsigned int);
878 static int comp_boolean(struct context *, const struct token *,
879 unsigned int, char *, unsigned int);
880 static int comp_action(struct context *, const struct token *,
881 unsigned int, char *, unsigned int);
882 static int comp_port(struct context *, const struct token *,
883 unsigned int, char *, unsigned int);
884 static int comp_rule_id(struct context *, const struct token *,
885 unsigned int, char *, unsigned int);
886 static int comp_vc_action_rss_type(struct context *, const struct token *,
887 unsigned int, char *, unsigned int);
888 static int comp_vc_action_rss_queue(struct context *, const struct token *,
889 unsigned int, char *, unsigned int);
891 /** Token definitions. */
892 static const struct token token_list[] = {
893 /* Special tokens. */
896 .help = "null entry, abused as the entry point",
897 .next = NEXT(NEXT_ENTRY(FLOW)),
902 .help = "command may end here",
908 .help = "integer value",
913 .name = "{unsigned}",
915 .help = "unsigned integer value",
922 .help = "prefix length for bit-mask",
923 .call = parse_prefix,
929 .help = "any boolean value",
930 .call = parse_boolean,
931 .comp = comp_boolean,
936 .help = "fixed string",
937 .call = parse_string,
941 .name = "{MAC address}",
943 .help = "standard MAC address notation",
944 .call = parse_mac_addr,
948 .name = "{IPv4 address}",
949 .type = "IPV4 ADDRESS",
950 .help = "standard IPv4 address notation",
951 .call = parse_ipv4_addr,
955 .name = "{IPv6 address}",
956 .type = "IPV6 ADDRESS",
957 .help = "standard IPv6 address notation",
958 .call = parse_ipv6_addr,
964 .help = "rule identifier",
966 .comp = comp_rule_id,
971 .help = "port identifier",
976 .name = "{group_id}",
978 .help = "group identifier",
985 .help = "priority level",
989 /* Top-level command. */
992 .type = "{command} {port_id} [{arg} [...]]",
993 .help = "manage ingress/egress flow rules",
994 .next = NEXT(NEXT_ENTRY
1004 /* Sub-level commands. */
1007 .help = "check whether a flow rule can be created",
1008 .next = NEXT(next_vc_attr, NEXT_ENTRY(PORT_ID)),
1009 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1014 .help = "create a flow rule",
1015 .next = NEXT(next_vc_attr, NEXT_ENTRY(PORT_ID)),
1016 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1021 .help = "destroy specific flow rules",
1022 .next = NEXT(NEXT_ENTRY(DESTROY_RULE), NEXT_ENTRY(PORT_ID)),
1023 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1024 .call = parse_destroy,
1028 .help = "destroy all flow rules",
1029 .next = NEXT(NEXT_ENTRY(PORT_ID)),
1030 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1031 .call = parse_flush,
1035 .help = "query an existing flow rule",
1036 .next = NEXT(NEXT_ENTRY(QUERY_ACTION),
1037 NEXT_ENTRY(RULE_ID),
1038 NEXT_ENTRY(PORT_ID)),
1039 .args = ARGS(ARGS_ENTRY(struct buffer, args.query.action),
1040 ARGS_ENTRY(struct buffer, args.query.rule),
1041 ARGS_ENTRY(struct buffer, port)),
1042 .call = parse_query,
1046 .help = "list existing flow rules",
1047 .next = NEXT(next_list_attr, NEXT_ENTRY(PORT_ID)),
1048 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
1053 .help = "restrict ingress traffic to the defined flow rules",
1054 .next = NEXT(NEXT_ENTRY(BOOLEAN),
1055 NEXT_ENTRY(PORT_ID)),
1056 .args = ARGS(ARGS_ENTRY(struct buffer, args.isolate.set),
1057 ARGS_ENTRY(struct buffer, port)),
1058 .call = parse_isolate,
1060 /* Destroy arguments. */
1063 .help = "specify a rule identifier",
1064 .next = NEXT(next_destroy_attr, NEXT_ENTRY(RULE_ID)),
1065 .args = ARGS(ARGS_ENTRY_PTR(struct buffer, args.destroy.rule)),
1066 .call = parse_destroy,
1068 /* Query arguments. */
1072 .help = "action to query, must be part of the rule",
1073 .call = parse_action,
1074 .comp = comp_action,
1076 /* List arguments. */
1079 .help = "specify a group",
1080 .next = NEXT(next_list_attr, NEXT_ENTRY(GROUP_ID)),
1081 .args = ARGS(ARGS_ENTRY_PTR(struct buffer, args.list.group)),
1084 /* Validate/create attributes. */
1087 .help = "specify a group",
1088 .next = NEXT(next_vc_attr, NEXT_ENTRY(GROUP_ID)),
1089 .args = ARGS(ARGS_ENTRY(struct rte_flow_attr, group)),
1094 .help = "specify a priority level",
1095 .next = NEXT(next_vc_attr, NEXT_ENTRY(PRIORITY_LEVEL)),
1096 .args = ARGS(ARGS_ENTRY(struct rte_flow_attr, priority)),
1101 .help = "affect rule to ingress",
1102 .next = NEXT(next_vc_attr),
1107 .help = "affect rule to egress",
1108 .next = NEXT(next_vc_attr),
1113 .help = "apply rule directly to endpoints found in pattern",
1114 .next = NEXT(next_vc_attr),
1117 /* Validate/create pattern. */
1120 .help = "submit a list of pattern items",
1121 .next = NEXT(next_item),
1126 .help = "match value perfectly (with full bit-mask)",
1127 .call = parse_vc_spec,
1129 [ITEM_PARAM_SPEC] = {
1131 .help = "match value according to configured bit-mask",
1132 .call = parse_vc_spec,
1134 [ITEM_PARAM_LAST] = {
1136 .help = "specify upper bound to establish a range",
1137 .call = parse_vc_spec,
1139 [ITEM_PARAM_MASK] = {
1141 .help = "specify bit-mask with relevant bits set to one",
1142 .call = parse_vc_spec,
1144 [ITEM_PARAM_PREFIX] = {
1146 .help = "generate bit-mask from a prefix length",
1147 .call = parse_vc_spec,
1151 .help = "specify next pattern item",
1152 .next = NEXT(next_item),
1156 .help = "end list of pattern items",
1157 .priv = PRIV_ITEM(END, 0),
1158 .next = NEXT(NEXT_ENTRY(ACTIONS)),
1163 .help = "no-op pattern item",
1164 .priv = PRIV_ITEM(VOID, 0),
1165 .next = NEXT(NEXT_ENTRY(ITEM_NEXT)),
1170 .help = "perform actions when pattern does not match",
1171 .priv = PRIV_ITEM(INVERT, 0),
1172 .next = NEXT(NEXT_ENTRY(ITEM_NEXT)),
1177 .help = "match any protocol for the current layer",
1178 .priv = PRIV_ITEM(ANY, sizeof(struct rte_flow_item_any)),
1179 .next = NEXT(item_any),
1184 .help = "number of layers covered",
1185 .next = NEXT(item_any, NEXT_ENTRY(UNSIGNED), item_param),
1186 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_any, num)),
1190 .help = "match traffic from/to the physical function",
1191 .priv = PRIV_ITEM(PF, 0),
1192 .next = NEXT(NEXT_ENTRY(ITEM_NEXT)),
1197 .help = "match traffic from/to a virtual function ID",
1198 .priv = PRIV_ITEM(VF, sizeof(struct rte_flow_item_vf)),
1199 .next = NEXT(item_vf),
1205 .next = NEXT(item_vf, NEXT_ENTRY(UNSIGNED), item_param),
1206 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_vf, id)),
1210 .help = "match traffic from/to a specific physical port",
1211 .priv = PRIV_ITEM(PHY_PORT,
1212 sizeof(struct rte_flow_item_phy_port)),
1213 .next = NEXT(item_phy_port),
1216 [ITEM_PHY_PORT_INDEX] = {
1218 .help = "physical port index",
1219 .next = NEXT(item_phy_port, NEXT_ENTRY(UNSIGNED), item_param),
1220 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_phy_port, index)),
1224 .help = "match traffic from/to a given DPDK port ID",
1225 .priv = PRIV_ITEM(PORT_ID,
1226 sizeof(struct rte_flow_item_port_id)),
1227 .next = NEXT(item_port_id),
1230 [ITEM_PORT_ID_ID] = {
1232 .help = "DPDK port ID",
1233 .next = NEXT(item_port_id, NEXT_ENTRY(UNSIGNED), item_param),
1234 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_port_id, id)),
1238 .help = "match an arbitrary byte string",
1239 .priv = PRIV_ITEM(RAW, ITEM_RAW_SIZE),
1240 .next = NEXT(item_raw),
1243 [ITEM_RAW_RELATIVE] = {
1245 .help = "look for pattern after the previous item",
1246 .next = NEXT(item_raw, NEXT_ENTRY(BOOLEAN), item_param),
1247 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_item_raw,
1250 [ITEM_RAW_SEARCH] = {
1252 .help = "search pattern from offset (see also limit)",
1253 .next = NEXT(item_raw, NEXT_ENTRY(BOOLEAN), item_param),
1254 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_item_raw,
1257 [ITEM_RAW_OFFSET] = {
1259 .help = "absolute or relative offset for pattern",
1260 .next = NEXT(item_raw, NEXT_ENTRY(INTEGER), item_param),
1261 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_raw, offset)),
1263 [ITEM_RAW_LIMIT] = {
1265 .help = "search area limit for start of pattern",
1266 .next = NEXT(item_raw, NEXT_ENTRY(UNSIGNED), item_param),
1267 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_raw, limit)),
1269 [ITEM_RAW_PATTERN] = {
1271 .help = "byte string to look for",
1272 .next = NEXT(item_raw,
1274 NEXT_ENTRY(ITEM_PARAM_IS,
1277 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_raw, pattern),
1278 ARGS_ENTRY(struct rte_flow_item_raw, length),
1279 ARGS_ENTRY_ARB(sizeof(struct rte_flow_item_raw),
1280 ITEM_RAW_PATTERN_SIZE)),
1284 .help = "match Ethernet header",
1285 .priv = PRIV_ITEM(ETH, sizeof(struct rte_flow_item_eth)),
1286 .next = NEXT(item_eth),
1291 .help = "destination MAC",
1292 .next = NEXT(item_eth, NEXT_ENTRY(MAC_ADDR), item_param),
1293 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_eth, dst)),
1297 .help = "source MAC",
1298 .next = NEXT(item_eth, NEXT_ENTRY(MAC_ADDR), item_param),
1299 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_eth, src)),
1303 .help = "EtherType",
1304 .next = NEXT(item_eth, NEXT_ENTRY(UNSIGNED), item_param),
1305 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_eth, type)),
1309 .help = "match 802.1Q/ad VLAN tag",
1310 .priv = PRIV_ITEM(VLAN, sizeof(struct rte_flow_item_vlan)),
1311 .next = NEXT(item_vlan),
1316 .help = "tag control information",
1317 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1318 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vlan, tci)),
1322 .help = "priority code point",
1323 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1324 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_vlan,
1329 .help = "drop eligible indicator",
1330 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1331 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_vlan,
1336 .help = "VLAN identifier",
1337 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1338 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_vlan,
1341 [ITEM_VLAN_INNER_TYPE] = {
1342 .name = "inner_type",
1343 .help = "inner EtherType",
1344 .next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1345 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vlan,
1350 .help = "match IPv4 header",
1351 .priv = PRIV_ITEM(IPV4, sizeof(struct rte_flow_item_ipv4)),
1352 .next = NEXT(item_ipv4),
1357 .help = "type of service",
1358 .next = NEXT(item_ipv4, NEXT_ENTRY(UNSIGNED), item_param),
1359 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
1360 hdr.type_of_service)),
1364 .help = "time to live",
1365 .next = NEXT(item_ipv4, NEXT_ENTRY(UNSIGNED), item_param),
1366 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
1369 [ITEM_IPV4_PROTO] = {
1371 .help = "next protocol ID",
1372 .next = NEXT(item_ipv4, NEXT_ENTRY(UNSIGNED), item_param),
1373 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
1374 hdr.next_proto_id)),
1378 .help = "source address",
1379 .next = NEXT(item_ipv4, NEXT_ENTRY(IPV4_ADDR), item_param),
1380 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
1385 .help = "destination address",
1386 .next = NEXT(item_ipv4, NEXT_ENTRY(IPV4_ADDR), item_param),
1387 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
1392 .help = "match IPv6 header",
1393 .priv = PRIV_ITEM(IPV6, sizeof(struct rte_flow_item_ipv6)),
1394 .next = NEXT(item_ipv6),
1399 .help = "traffic class",
1400 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
1401 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_ipv6,
1403 "\x0f\xf0\x00\x00")),
1405 [ITEM_IPV6_FLOW] = {
1407 .help = "flow label",
1408 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
1409 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_ipv6,
1411 "\x00\x0f\xff\xff")),
1413 [ITEM_IPV6_PROTO] = {
1415 .help = "protocol (next header)",
1416 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
1417 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
1422 .help = "hop limit",
1423 .next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
1424 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
1429 .help = "source address",
1430 .next = NEXT(item_ipv6, NEXT_ENTRY(IPV6_ADDR), item_param),
1431 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
1436 .help = "destination address",
1437 .next = NEXT(item_ipv6, NEXT_ENTRY(IPV6_ADDR), item_param),
1438 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
1443 .help = "match ICMP header",
1444 .priv = PRIV_ITEM(ICMP, sizeof(struct rte_flow_item_icmp)),
1445 .next = NEXT(item_icmp),
1448 [ITEM_ICMP_TYPE] = {
1450 .help = "ICMP packet type",
1451 .next = NEXT(item_icmp, NEXT_ENTRY(UNSIGNED), item_param),
1452 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp,
1455 [ITEM_ICMP_CODE] = {
1457 .help = "ICMP packet code",
1458 .next = NEXT(item_icmp, NEXT_ENTRY(UNSIGNED), item_param),
1459 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp,
1464 .help = "match UDP header",
1465 .priv = PRIV_ITEM(UDP, sizeof(struct rte_flow_item_udp)),
1466 .next = NEXT(item_udp),
1471 .help = "UDP source port",
1472 .next = NEXT(item_udp, NEXT_ENTRY(UNSIGNED), item_param),
1473 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_udp,
1478 .help = "UDP destination port",
1479 .next = NEXT(item_udp, NEXT_ENTRY(UNSIGNED), item_param),
1480 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_udp,
1485 .help = "match TCP header",
1486 .priv = PRIV_ITEM(TCP, sizeof(struct rte_flow_item_tcp)),
1487 .next = NEXT(item_tcp),
1492 .help = "TCP source port",
1493 .next = NEXT(item_tcp, NEXT_ENTRY(UNSIGNED), item_param),
1494 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_tcp,
1499 .help = "TCP destination port",
1500 .next = NEXT(item_tcp, NEXT_ENTRY(UNSIGNED), item_param),
1501 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_tcp,
1504 [ITEM_TCP_FLAGS] = {
1506 .help = "TCP flags",
1507 .next = NEXT(item_tcp, NEXT_ENTRY(UNSIGNED), item_param),
1508 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_tcp,
1513 .help = "match SCTP header",
1514 .priv = PRIV_ITEM(SCTP, sizeof(struct rte_flow_item_sctp)),
1515 .next = NEXT(item_sctp),
1520 .help = "SCTP source port",
1521 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
1522 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
1527 .help = "SCTP destination port",
1528 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
1529 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
1534 .help = "validation tag",
1535 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
1536 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
1539 [ITEM_SCTP_CKSUM] = {
1542 .next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
1543 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
1548 .help = "match VXLAN header",
1549 .priv = PRIV_ITEM(VXLAN, sizeof(struct rte_flow_item_vxlan)),
1550 .next = NEXT(item_vxlan),
1553 [ITEM_VXLAN_VNI] = {
1555 .help = "VXLAN identifier",
1556 .next = NEXT(item_vxlan, NEXT_ENTRY(UNSIGNED), item_param),
1557 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vxlan, vni)),
1561 .help = "match E-Tag header",
1562 .priv = PRIV_ITEM(E_TAG, sizeof(struct rte_flow_item_e_tag)),
1563 .next = NEXT(item_e_tag),
1566 [ITEM_E_TAG_GRP_ECID_B] = {
1567 .name = "grp_ecid_b",
1568 .help = "GRP and E-CID base",
1569 .next = NEXT(item_e_tag, NEXT_ENTRY(UNSIGNED), item_param),
1570 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_e_tag,
1576 .help = "match NVGRE header",
1577 .priv = PRIV_ITEM(NVGRE, sizeof(struct rte_flow_item_nvgre)),
1578 .next = NEXT(item_nvgre),
1581 [ITEM_NVGRE_TNI] = {
1583 .help = "virtual subnet ID",
1584 .next = NEXT(item_nvgre, NEXT_ENTRY(UNSIGNED), item_param),
1585 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_nvgre, tni)),
1589 .help = "match MPLS header",
1590 .priv = PRIV_ITEM(MPLS, sizeof(struct rte_flow_item_mpls)),
1591 .next = NEXT(item_mpls),
1594 [ITEM_MPLS_LABEL] = {
1596 .help = "MPLS label",
1597 .next = NEXT(item_mpls, NEXT_ENTRY(UNSIGNED), item_param),
1598 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_mpls,
1604 .help = "match GRE header",
1605 .priv = PRIV_ITEM(GRE, sizeof(struct rte_flow_item_gre)),
1606 .next = NEXT(item_gre),
1609 [ITEM_GRE_PROTO] = {
1611 .help = "GRE protocol type",
1612 .next = NEXT(item_gre, NEXT_ENTRY(UNSIGNED), item_param),
1613 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gre,
1618 .help = "fuzzy pattern match, expect faster than default",
1619 .priv = PRIV_ITEM(FUZZY,
1620 sizeof(struct rte_flow_item_fuzzy)),
1621 .next = NEXT(item_fuzzy),
1624 [ITEM_FUZZY_THRESH] = {
1626 .help = "match accuracy threshold",
1627 .next = NEXT(item_fuzzy, NEXT_ENTRY(UNSIGNED), item_param),
1628 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_fuzzy,
1633 .help = "match GTP header",
1634 .priv = PRIV_ITEM(GTP, sizeof(struct rte_flow_item_gtp)),
1635 .next = NEXT(item_gtp),
1640 .help = "tunnel endpoint identifier",
1641 .next = NEXT(item_gtp, NEXT_ENTRY(UNSIGNED), item_param),
1642 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gtp, teid)),
1646 .help = "match GTP header",
1647 .priv = PRIV_ITEM(GTPC, sizeof(struct rte_flow_item_gtp)),
1648 .next = NEXT(item_gtp),
1653 .help = "match GTP header",
1654 .priv = PRIV_ITEM(GTPU, sizeof(struct rte_flow_item_gtp)),
1655 .next = NEXT(item_gtp),
1660 .help = "match GENEVE header",
1661 .priv = PRIV_ITEM(GENEVE, sizeof(struct rte_flow_item_geneve)),
1662 .next = NEXT(item_geneve),
1665 [ITEM_GENEVE_VNI] = {
1667 .help = "virtual network identifier",
1668 .next = NEXT(item_geneve, NEXT_ENTRY(UNSIGNED), item_param),
1669 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_geneve, vni)),
1671 [ITEM_GENEVE_PROTO] = {
1673 .help = "GENEVE protocol type",
1674 .next = NEXT(item_geneve, NEXT_ENTRY(UNSIGNED), item_param),
1675 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_geneve,
1678 [ITEM_VXLAN_GPE] = {
1679 .name = "vxlan-gpe",
1680 .help = "match VXLAN-GPE header",
1681 .priv = PRIV_ITEM(VXLAN_GPE,
1682 sizeof(struct rte_flow_item_vxlan_gpe)),
1683 .next = NEXT(item_vxlan_gpe),
1686 [ITEM_VXLAN_GPE_VNI] = {
1688 .help = "VXLAN-GPE identifier",
1689 .next = NEXT(item_vxlan_gpe, NEXT_ENTRY(UNSIGNED), item_param),
1690 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vxlan_gpe,
1693 [ITEM_ARP_ETH_IPV4] = {
1694 .name = "arp_eth_ipv4",
1695 .help = "match ARP header for Ethernet/IPv4",
1696 .priv = PRIV_ITEM(ARP_ETH_IPV4,
1697 sizeof(struct rte_flow_item_arp_eth_ipv4)),
1698 .next = NEXT(item_arp_eth_ipv4),
1701 [ITEM_ARP_ETH_IPV4_SHA] = {
1703 .help = "sender hardware address",
1704 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(MAC_ADDR),
1706 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
1709 [ITEM_ARP_ETH_IPV4_SPA] = {
1711 .help = "sender IPv4 address",
1712 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(IPV4_ADDR),
1714 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
1717 [ITEM_ARP_ETH_IPV4_THA] = {
1719 .help = "target hardware address",
1720 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(MAC_ADDR),
1722 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
1725 [ITEM_ARP_ETH_IPV4_TPA] = {
1727 .help = "target IPv4 address",
1728 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(IPV4_ADDR),
1730 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
1735 .help = "match presence of any IPv6 extension header",
1736 .priv = PRIV_ITEM(IPV6_EXT,
1737 sizeof(struct rte_flow_item_ipv6_ext)),
1738 .next = NEXT(item_ipv6_ext),
1741 [ITEM_IPV6_EXT_NEXT_HDR] = {
1743 .help = "next header",
1744 .next = NEXT(item_ipv6_ext, NEXT_ENTRY(UNSIGNED), item_param),
1745 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6_ext,
1750 .help = "match any ICMPv6 header",
1751 .priv = PRIV_ITEM(ICMP6, sizeof(struct rte_flow_item_icmp6)),
1752 .next = NEXT(item_icmp6),
1755 [ITEM_ICMP6_TYPE] = {
1757 .help = "ICMPv6 type",
1758 .next = NEXT(item_icmp6, NEXT_ENTRY(UNSIGNED), item_param),
1759 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6,
1762 [ITEM_ICMP6_CODE] = {
1764 .help = "ICMPv6 code",
1765 .next = NEXT(item_icmp6, NEXT_ENTRY(UNSIGNED), item_param),
1766 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6,
1769 [ITEM_ICMP6_ND_NS] = {
1770 .name = "icmp6_nd_ns",
1771 .help = "match ICMPv6 neighbor discovery solicitation",
1772 .priv = PRIV_ITEM(ICMP6_ND_NS,
1773 sizeof(struct rte_flow_item_icmp6_nd_ns)),
1774 .next = NEXT(item_icmp6_nd_ns),
1777 [ITEM_ICMP6_ND_NS_TARGET_ADDR] = {
1778 .name = "target_addr",
1779 .help = "target address",
1780 .next = NEXT(item_icmp6_nd_ns, NEXT_ENTRY(IPV6_ADDR),
1782 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6_nd_ns,
1785 [ITEM_ICMP6_ND_NA] = {
1786 .name = "icmp6_nd_na",
1787 .help = "match ICMPv6 neighbor discovery advertisement",
1788 .priv = PRIV_ITEM(ICMP6_ND_NA,
1789 sizeof(struct rte_flow_item_icmp6_nd_na)),
1790 .next = NEXT(item_icmp6_nd_na),
1793 [ITEM_ICMP6_ND_NA_TARGET_ADDR] = {
1794 .name = "target_addr",
1795 .help = "target address",
1796 .next = NEXT(item_icmp6_nd_na, NEXT_ENTRY(IPV6_ADDR),
1798 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6_nd_na,
1801 [ITEM_ICMP6_ND_OPT] = {
1802 .name = "icmp6_nd_opt",
1803 .help = "match presence of any ICMPv6 neighbor discovery"
1805 .priv = PRIV_ITEM(ICMP6_ND_OPT,
1806 sizeof(struct rte_flow_item_icmp6_nd_opt)),
1807 .next = NEXT(item_icmp6_nd_opt),
1810 [ITEM_ICMP6_ND_OPT_TYPE] = {
1812 .help = "ND option type",
1813 .next = NEXT(item_icmp6_nd_opt, NEXT_ENTRY(UNSIGNED),
1815 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6_nd_opt,
1818 [ITEM_ICMP6_ND_OPT_SLA_ETH] = {
1819 .name = "icmp6_nd_opt_sla_eth",
1820 .help = "match ICMPv6 neighbor discovery source Ethernet"
1821 " link-layer address option",
1823 (ICMP6_ND_OPT_SLA_ETH,
1824 sizeof(struct rte_flow_item_icmp6_nd_opt_sla_eth)),
1825 .next = NEXT(item_icmp6_nd_opt_sla_eth),
1828 [ITEM_ICMP6_ND_OPT_SLA_ETH_SLA] = {
1830 .help = "source Ethernet LLA",
1831 .next = NEXT(item_icmp6_nd_opt_sla_eth, NEXT_ENTRY(MAC_ADDR),
1833 .args = ARGS(ARGS_ENTRY_HTON
1834 (struct rte_flow_item_icmp6_nd_opt_sla_eth, sla)),
1836 [ITEM_ICMP6_ND_OPT_TLA_ETH] = {
1837 .name = "icmp6_nd_opt_tla_eth",
1838 .help = "match ICMPv6 neighbor discovery target Ethernet"
1839 " link-layer address option",
1841 (ICMP6_ND_OPT_TLA_ETH,
1842 sizeof(struct rte_flow_item_icmp6_nd_opt_tla_eth)),
1843 .next = NEXT(item_icmp6_nd_opt_tla_eth),
1846 [ITEM_ICMP6_ND_OPT_TLA_ETH_TLA] = {
1848 .help = "target Ethernet LLA",
1849 .next = NEXT(item_icmp6_nd_opt_tla_eth, NEXT_ENTRY(MAC_ADDR),
1851 .args = ARGS(ARGS_ENTRY_HTON
1852 (struct rte_flow_item_icmp6_nd_opt_tla_eth, tla)),
1855 /* Validate/create actions. */
1858 .help = "submit a list of associated actions",
1859 .next = NEXT(next_action),
1864 .help = "specify next action",
1865 .next = NEXT(next_action),
1869 .help = "end list of actions",
1870 .priv = PRIV_ACTION(END, 0),
1875 .help = "no-op action",
1876 .priv = PRIV_ACTION(VOID, 0),
1877 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
1880 [ACTION_PASSTHRU] = {
1882 .help = "let subsequent rule process matched packets",
1883 .priv = PRIV_ACTION(PASSTHRU, 0),
1884 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
1889 .help = "attach 32 bit value to packets",
1890 .priv = PRIV_ACTION(MARK, sizeof(struct rte_flow_action_mark)),
1891 .next = NEXT(action_mark),
1894 [ACTION_MARK_ID] = {
1896 .help = "32 bit value to return with packets",
1897 .next = NEXT(action_mark, NEXT_ENTRY(UNSIGNED)),
1898 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_mark, id)),
1899 .call = parse_vc_conf,
1903 .help = "flag packets",
1904 .priv = PRIV_ACTION(FLAG, 0),
1905 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
1910 .help = "assign packets to a given queue index",
1911 .priv = PRIV_ACTION(QUEUE,
1912 sizeof(struct rte_flow_action_queue)),
1913 .next = NEXT(action_queue),
1916 [ACTION_QUEUE_INDEX] = {
1918 .help = "queue index to use",
1919 .next = NEXT(action_queue, NEXT_ENTRY(UNSIGNED)),
1920 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_queue, index)),
1921 .call = parse_vc_conf,
1925 .help = "drop packets (note: passthru has priority)",
1926 .priv = PRIV_ACTION(DROP, 0),
1927 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
1932 .help = "enable counters for this rule",
1933 .priv = PRIV_ACTION(COUNT, 0),
1934 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
1939 .help = "spread packets among several queues",
1940 .priv = PRIV_ACTION(RSS, sizeof(struct action_rss_data)),
1941 .next = NEXT(action_rss),
1942 .call = parse_vc_action_rss,
1944 [ACTION_RSS_FUNC] = {
1946 .help = "RSS hash function to apply",
1947 .next = NEXT(action_rss,
1948 NEXT_ENTRY(ACTION_RSS_FUNC_DEFAULT,
1949 ACTION_RSS_FUNC_TOEPLITZ,
1950 ACTION_RSS_FUNC_SIMPLE_XOR)),
1952 [ACTION_RSS_FUNC_DEFAULT] = {
1954 .help = "default hash function",
1955 .call = parse_vc_action_rss_func,
1957 [ACTION_RSS_FUNC_TOEPLITZ] = {
1959 .help = "Toeplitz hash function",
1960 .call = parse_vc_action_rss_func,
1962 [ACTION_RSS_FUNC_SIMPLE_XOR] = {
1963 .name = "simple_xor",
1964 .help = "simple XOR hash function",
1965 .call = parse_vc_action_rss_func,
1967 [ACTION_RSS_LEVEL] = {
1969 .help = "encapsulation level for \"types\"",
1970 .next = NEXT(action_rss, NEXT_ENTRY(UNSIGNED)),
1971 .args = ARGS(ARGS_ENTRY_ARB
1972 (offsetof(struct action_rss_data, conf) +
1973 offsetof(struct rte_flow_action_rss, level),
1974 sizeof(((struct rte_flow_action_rss *)0)->
1977 [ACTION_RSS_TYPES] = {
1979 .help = "specific RSS hash types",
1980 .next = NEXT(action_rss, NEXT_ENTRY(ACTION_RSS_TYPE)),
1982 [ACTION_RSS_TYPE] = {
1984 .help = "RSS hash type",
1985 .call = parse_vc_action_rss_type,
1986 .comp = comp_vc_action_rss_type,
1988 [ACTION_RSS_KEY] = {
1990 .help = "RSS hash key",
1991 .next = NEXT(action_rss, NEXT_ENTRY(STRING)),
1992 .args = ARGS(ARGS_ENTRY_ARB(0, 0),
1994 (offsetof(struct action_rss_data, conf) +
1995 offsetof(struct rte_flow_action_rss, key_len),
1996 sizeof(((struct rte_flow_action_rss *)0)->
1998 ARGS_ENTRY(struct action_rss_data, key)),
2000 [ACTION_RSS_KEY_LEN] = {
2002 .help = "RSS hash key length in bytes",
2003 .next = NEXT(action_rss, NEXT_ENTRY(UNSIGNED)),
2004 .args = ARGS(ARGS_ENTRY_ARB_BOUNDED
2005 (offsetof(struct action_rss_data, conf) +
2006 offsetof(struct rte_flow_action_rss, key_len),
2007 sizeof(((struct rte_flow_action_rss *)0)->
2010 RSS_HASH_KEY_LENGTH)),
2012 [ACTION_RSS_QUEUES] = {
2014 .help = "queue indices to use",
2015 .next = NEXT(action_rss, NEXT_ENTRY(ACTION_RSS_QUEUE)),
2016 .call = parse_vc_conf,
2018 [ACTION_RSS_QUEUE] = {
2020 .help = "queue index",
2021 .call = parse_vc_action_rss_queue,
2022 .comp = comp_vc_action_rss_queue,
2026 .help = "direct traffic to physical function",
2027 .priv = PRIV_ACTION(PF, 0),
2028 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2033 .help = "direct traffic to a virtual function ID",
2034 .priv = PRIV_ACTION(VF, sizeof(struct rte_flow_action_vf)),
2035 .next = NEXT(action_vf),
2038 [ACTION_VF_ORIGINAL] = {
2040 .help = "use original VF ID if possible",
2041 .next = NEXT(action_vf, NEXT_ENTRY(BOOLEAN)),
2042 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_vf,
2044 .call = parse_vc_conf,
2049 .next = NEXT(action_vf, NEXT_ENTRY(UNSIGNED)),
2050 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_vf, id)),
2051 .call = parse_vc_conf,
2053 [ACTION_PHY_PORT] = {
2055 .help = "direct packets to physical port index",
2056 .priv = PRIV_ACTION(PHY_PORT,
2057 sizeof(struct rte_flow_action_phy_port)),
2058 .next = NEXT(action_phy_port),
2061 [ACTION_PHY_PORT_ORIGINAL] = {
2063 .help = "use original port index if possible",
2064 .next = NEXT(action_phy_port, NEXT_ENTRY(BOOLEAN)),
2065 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_phy_port,
2067 .call = parse_vc_conf,
2069 [ACTION_PHY_PORT_INDEX] = {
2071 .help = "physical port index",
2072 .next = NEXT(action_phy_port, NEXT_ENTRY(UNSIGNED)),
2073 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_phy_port,
2075 .call = parse_vc_conf,
2077 [ACTION_PORT_ID] = {
2079 .help = "direct matching traffic to a given DPDK port ID",
2080 .priv = PRIV_ACTION(PORT_ID,
2081 sizeof(struct rte_flow_action_port_id)),
2082 .next = NEXT(action_port_id),
2085 [ACTION_PORT_ID_ORIGINAL] = {
2087 .help = "use original DPDK port ID if possible",
2088 .next = NEXT(action_port_id, NEXT_ENTRY(BOOLEAN)),
2089 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_port_id,
2091 .call = parse_vc_conf,
2093 [ACTION_PORT_ID_ID] = {
2095 .help = "DPDK port ID",
2096 .next = NEXT(action_port_id, NEXT_ENTRY(UNSIGNED)),
2097 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_port_id, id)),
2098 .call = parse_vc_conf,
2102 .help = "meter the directed packets at given id",
2103 .priv = PRIV_ACTION(METER,
2104 sizeof(struct rte_flow_action_meter)),
2105 .next = NEXT(action_meter),
2108 [ACTION_METER_ID] = {
2110 .help = "meter id to use",
2111 .next = NEXT(action_meter, NEXT_ENTRY(UNSIGNED)),
2112 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_meter, mtr_id)),
2113 .call = parse_vc_conf,
2115 [ACTION_OF_SET_MPLS_TTL] = {
2116 .name = "of_set_mpls_ttl",
2117 .help = "OpenFlow's OFPAT_SET_MPLS_TTL",
2120 sizeof(struct rte_flow_action_of_set_mpls_ttl)),
2121 .next = NEXT(action_of_set_mpls_ttl),
2124 [ACTION_OF_SET_MPLS_TTL_MPLS_TTL] = {
2127 .next = NEXT(action_of_set_mpls_ttl, NEXT_ENTRY(UNSIGNED)),
2128 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_of_set_mpls_ttl,
2130 .call = parse_vc_conf,
2132 [ACTION_OF_DEC_MPLS_TTL] = {
2133 .name = "of_dec_mpls_ttl",
2134 .help = "OpenFlow's OFPAT_DEC_MPLS_TTL",
2135 .priv = PRIV_ACTION(OF_DEC_MPLS_TTL, 0),
2136 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2139 [ACTION_OF_SET_NW_TTL] = {
2140 .name = "of_set_nw_ttl",
2141 .help = "OpenFlow's OFPAT_SET_NW_TTL",
2144 sizeof(struct rte_flow_action_of_set_nw_ttl)),
2145 .next = NEXT(action_of_set_nw_ttl),
2148 [ACTION_OF_SET_NW_TTL_NW_TTL] = {
2151 .next = NEXT(action_of_set_nw_ttl, NEXT_ENTRY(UNSIGNED)),
2152 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_of_set_nw_ttl,
2154 .call = parse_vc_conf,
2156 [ACTION_OF_DEC_NW_TTL] = {
2157 .name = "of_dec_nw_ttl",
2158 .help = "OpenFlow's OFPAT_DEC_NW_TTL",
2159 .priv = PRIV_ACTION(OF_DEC_NW_TTL, 0),
2160 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2163 [ACTION_OF_COPY_TTL_OUT] = {
2164 .name = "of_copy_ttl_out",
2165 .help = "OpenFlow's OFPAT_COPY_TTL_OUT",
2166 .priv = PRIV_ACTION(OF_COPY_TTL_OUT, 0),
2167 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2170 [ACTION_OF_COPY_TTL_IN] = {
2171 .name = "of_copy_ttl_in",
2172 .help = "OpenFlow's OFPAT_COPY_TTL_IN",
2173 .priv = PRIV_ACTION(OF_COPY_TTL_IN, 0),
2174 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2179 /** Remove and return last entry from argument stack. */
2180 static const struct arg *
2181 pop_args(struct context *ctx)
2183 return ctx->args_num ? ctx->args[--ctx->args_num] : NULL;
2186 /** Add entry on top of the argument stack. */
2188 push_args(struct context *ctx, const struct arg *arg)
2190 if (ctx->args_num == CTX_STACK_SIZE)
2192 ctx->args[ctx->args_num++] = arg;
2196 /** Spread value into buffer according to bit-mask. */
2198 arg_entry_bf_fill(void *dst, uintmax_t val, const struct arg *arg)
2200 uint32_t i = arg->size;
2208 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
2217 unsigned int shift = 0;
2218 uint8_t *buf = (uint8_t *)dst + arg->offset + (i -= sub);
2220 for (shift = 0; arg->mask[i] >> shift; ++shift) {
2221 if (!(arg->mask[i] & (1 << shift)))
2226 *buf &= ~(1 << shift);
2227 *buf |= (val & 1) << shift;
2235 /** Compare a string with a partial one of a given length. */
2237 strcmp_partial(const char *full, const char *partial, size_t partial_len)
2239 int r = strncmp(full, partial, partial_len);
2243 if (strlen(full) <= partial_len)
2245 return full[partial_len];
2249 * Parse a prefix length and generate a bit-mask.
2251 * Last argument (ctx->args) is retrieved to determine mask size, storage
2252 * location and whether the result must use network byte ordering.
2255 parse_prefix(struct context *ctx, const struct token *token,
2256 const char *str, unsigned int len,
2257 void *buf, unsigned int size)
2259 const struct arg *arg = pop_args(ctx);
2260 static const uint8_t conv[] = "\x00\x80\xc0\xe0\xf0\xf8\xfc\xfe\xff";
2267 /* Argument is expected. */
2271 u = strtoumax(str, &end, 0);
2272 if (errno || (size_t)(end - str) != len)
2277 extra = arg_entry_bf_fill(NULL, 0, arg);
2286 if (!arg_entry_bf_fill(ctx->object, v, arg) ||
2287 !arg_entry_bf_fill(ctx->objmask, -1, arg))
2294 if (bytes > size || bytes + !!extra > size)
2298 buf = (uint8_t *)ctx->object + arg->offset;
2299 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
2301 memset((uint8_t *)buf + size - bytes, 0xff, bytes);
2302 memset(buf, 0x00, size - bytes);
2304 ((uint8_t *)buf)[size - bytes - 1] = conv[extra];
2308 memset(buf, 0xff, bytes);
2309 memset((uint8_t *)buf + bytes, 0x00, size - bytes);
2311 ((uint8_t *)buf)[bytes] = conv[extra];
2314 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
2317 push_args(ctx, arg);
2321 /** Default parsing function for token name matching. */
2323 parse_default(struct context *ctx, const struct token *token,
2324 const char *str, unsigned int len,
2325 void *buf, unsigned int size)
2330 if (strcmp_partial(token->name, str, len))
2335 /** Parse flow command, initialize output buffer for subsequent tokens. */
2337 parse_init(struct context *ctx, const struct token *token,
2338 const char *str, unsigned int len,
2339 void *buf, unsigned int size)
2341 struct buffer *out = buf;
2343 /* Token name must match. */
2344 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
2346 /* Nothing else to do if there is no buffer. */
2349 /* Make sure buffer is large enough. */
2350 if (size < sizeof(*out))
2352 /* Initialize buffer. */
2353 memset(out, 0x00, sizeof(*out));
2354 memset((uint8_t *)out + sizeof(*out), 0x22, size - sizeof(*out));
2357 ctx->objmask = NULL;
2361 /** Parse tokens for validate/create commands. */
2363 parse_vc(struct context *ctx, const struct token *token,
2364 const char *str, unsigned int len,
2365 void *buf, unsigned int size)
2367 struct buffer *out = buf;
2371 /* Token name must match. */
2372 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
2374 /* Nothing else to do if there is no buffer. */
2377 if (!out->command) {
2378 if (ctx->curr != VALIDATE && ctx->curr != CREATE)
2380 if (sizeof(*out) > size)
2382 out->command = ctx->curr;
2385 ctx->objmask = NULL;
2386 out->args.vc.data = (uint8_t *)out + size;
2390 ctx->object = &out->args.vc.attr;
2391 ctx->objmask = NULL;
2392 switch (ctx->curr) {
2397 out->args.vc.attr.ingress = 1;
2400 out->args.vc.attr.egress = 1;
2403 out->args.vc.attr.transfer = 1;
2406 out->args.vc.pattern =
2407 (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
2409 ctx->object = out->args.vc.pattern;
2410 ctx->objmask = NULL;
2413 out->args.vc.actions =
2414 (void *)RTE_ALIGN_CEIL((uintptr_t)
2415 (out->args.vc.pattern +
2416 out->args.vc.pattern_n),
2418 ctx->object = out->args.vc.actions;
2419 ctx->objmask = NULL;
2426 if (!out->args.vc.actions) {
2427 const struct parse_item_priv *priv = token->priv;
2428 struct rte_flow_item *item =
2429 out->args.vc.pattern + out->args.vc.pattern_n;
2431 data_size = priv->size * 3; /* spec, last, mask */
2432 data = (void *)RTE_ALIGN_FLOOR((uintptr_t)
2433 (out->args.vc.data - data_size),
2435 if ((uint8_t *)item + sizeof(*item) > data)
2437 *item = (struct rte_flow_item){
2440 ++out->args.vc.pattern_n;
2442 ctx->objmask = NULL;
2444 const struct parse_action_priv *priv = token->priv;
2445 struct rte_flow_action *action =
2446 out->args.vc.actions + out->args.vc.actions_n;
2448 data_size = priv->size; /* configuration */
2449 data = (void *)RTE_ALIGN_FLOOR((uintptr_t)
2450 (out->args.vc.data - data_size),
2452 if ((uint8_t *)action + sizeof(*action) > data)
2454 *action = (struct rte_flow_action){
2456 .conf = data_size ? data : NULL,
2458 ++out->args.vc.actions_n;
2459 ctx->object = action;
2460 ctx->objmask = NULL;
2462 memset(data, 0, data_size);
2463 out->args.vc.data = data;
2464 ctx->objdata = data_size;
2468 /** Parse pattern item parameter type. */
2470 parse_vc_spec(struct context *ctx, const struct token *token,
2471 const char *str, unsigned int len,
2472 void *buf, unsigned int size)
2474 struct buffer *out = buf;
2475 struct rte_flow_item *item;
2481 /* Token name must match. */
2482 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
2484 /* Parse parameter types. */
2485 switch (ctx->curr) {
2486 static const enum index prefix[] = NEXT_ENTRY(PREFIX);
2492 case ITEM_PARAM_SPEC:
2495 case ITEM_PARAM_LAST:
2498 case ITEM_PARAM_PREFIX:
2499 /* Modify next token to expect a prefix. */
2500 if (ctx->next_num < 2)
2502 ctx->next[ctx->next_num - 2] = prefix;
2504 case ITEM_PARAM_MASK:
2510 /* Nothing else to do if there is no buffer. */
2513 if (!out->args.vc.pattern_n)
2515 item = &out->args.vc.pattern[out->args.vc.pattern_n - 1];
2516 data_size = ctx->objdata / 3; /* spec, last, mask */
2517 /* Point to selected object. */
2518 ctx->object = out->args.vc.data + (data_size * index);
2520 ctx->objmask = out->args.vc.data + (data_size * 2); /* mask */
2521 item->mask = ctx->objmask;
2523 ctx->objmask = NULL;
2524 /* Update relevant item pointer. */
2525 *((const void **[]){ &item->spec, &item->last, &item->mask })[index] =
2530 /** Parse action configuration field. */
2532 parse_vc_conf(struct context *ctx, const struct token *token,
2533 const char *str, unsigned int len,
2534 void *buf, unsigned int size)
2536 struct buffer *out = buf;
2539 /* Token name must match. */
2540 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
2542 /* Nothing else to do if there is no buffer. */
2545 /* Point to selected object. */
2546 ctx->object = out->args.vc.data;
2547 ctx->objmask = NULL;
2551 /** Parse RSS action. */
2553 parse_vc_action_rss(struct context *ctx, const struct token *token,
2554 const char *str, unsigned int len,
2555 void *buf, unsigned int size)
2557 struct buffer *out = buf;
2558 struct rte_flow_action *action;
2559 struct action_rss_data *action_rss_data;
2563 ret = parse_vc(ctx, token, str, len, buf, size);
2566 /* Nothing else to do if there is no buffer. */
2569 if (!out->args.vc.actions_n)
2571 action = &out->args.vc.actions[out->args.vc.actions_n - 1];
2572 /* Point to selected object. */
2573 ctx->object = out->args.vc.data;
2574 ctx->objmask = NULL;
2575 /* Set up default configuration. */
2576 action_rss_data = ctx->object;
2577 *action_rss_data = (struct action_rss_data){
2578 .conf = (struct rte_flow_action_rss){
2579 .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
2582 .key_len = sizeof(action_rss_data->key),
2583 .queue_num = RTE_MIN(nb_rxq, ACTION_RSS_QUEUE_NUM),
2584 .key = action_rss_data->key,
2585 .queue = action_rss_data->queue,
2587 .key = "testpmd's default RSS hash key",
2590 for (i = 0; i < action_rss_data->conf.queue_num; ++i)
2591 action_rss_data->queue[i] = i;
2592 if (!port_id_is_invalid(ctx->port, DISABLED_WARN) &&
2593 ctx->port != (portid_t)RTE_PORT_ALL) {
2594 struct rte_eth_dev_info info;
2596 rte_eth_dev_info_get(ctx->port, &info);
2597 action_rss_data->conf.key_len =
2598 RTE_MIN(sizeof(action_rss_data->key),
2599 info.hash_key_size);
2601 action->conf = &action_rss_data->conf;
2606 * Parse func field for RSS action.
2608 * The RTE_ETH_HASH_FUNCTION_* value to assign is derived from the
2609 * ACTION_RSS_FUNC_* index that called this function.
2612 parse_vc_action_rss_func(struct context *ctx, const struct token *token,
2613 const char *str, unsigned int len,
2614 void *buf, unsigned int size)
2616 struct action_rss_data *action_rss_data;
2617 enum rte_eth_hash_function func;
2621 /* Token name must match. */
2622 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
2624 switch (ctx->curr) {
2625 case ACTION_RSS_FUNC_DEFAULT:
2626 func = RTE_ETH_HASH_FUNCTION_DEFAULT;
2628 case ACTION_RSS_FUNC_TOEPLITZ:
2629 func = RTE_ETH_HASH_FUNCTION_TOEPLITZ;
2631 case ACTION_RSS_FUNC_SIMPLE_XOR:
2632 func = RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
2639 action_rss_data = ctx->object;
2640 action_rss_data->conf.func = func;
2645 * Parse type field for RSS action.
2647 * Valid tokens are type field names and the "end" token.
2650 parse_vc_action_rss_type(struct context *ctx, const struct token *token,
2651 const char *str, unsigned int len,
2652 void *buf, unsigned int size)
2654 static const enum index next[] = NEXT_ENTRY(ACTION_RSS_TYPE);
2655 struct action_rss_data *action_rss_data;
2661 if (ctx->curr != ACTION_RSS_TYPE)
2663 if (!(ctx->objdata >> 16) && ctx->object) {
2664 action_rss_data = ctx->object;
2665 action_rss_data->conf.types = 0;
2667 if (!strcmp_partial("end", str, len)) {
2668 ctx->objdata &= 0xffff;
2671 for (i = 0; rss_type_table[i].str; ++i)
2672 if (!strcmp_partial(rss_type_table[i].str, str, len))
2674 if (!rss_type_table[i].str)
2676 ctx->objdata = 1 << 16 | (ctx->objdata & 0xffff);
2678 if (ctx->next_num == RTE_DIM(ctx->next))
2680 ctx->next[ctx->next_num++] = next;
2683 action_rss_data = ctx->object;
2684 action_rss_data->conf.types |= rss_type_table[i].rss_type;
2689 * Parse queue field for RSS action.
2691 * Valid tokens are queue indices and the "end" token.
2694 parse_vc_action_rss_queue(struct context *ctx, const struct token *token,
2695 const char *str, unsigned int len,
2696 void *buf, unsigned int size)
2698 static const enum index next[] = NEXT_ENTRY(ACTION_RSS_QUEUE);
2699 struct action_rss_data *action_rss_data;
2706 if (ctx->curr != ACTION_RSS_QUEUE)
2708 i = ctx->objdata >> 16;
2709 if (!strcmp_partial("end", str, len)) {
2710 ctx->objdata &= 0xffff;
2713 if (i >= ACTION_RSS_QUEUE_NUM)
2716 ARGS_ENTRY_ARB(offsetof(struct action_rss_data, queue) +
2717 i * sizeof(action_rss_data->queue[i]),
2718 sizeof(action_rss_data->queue[i]))))
2720 ret = parse_int(ctx, token, str, len, NULL, 0);
2726 ctx->objdata = i << 16 | (ctx->objdata & 0xffff);
2728 if (ctx->next_num == RTE_DIM(ctx->next))
2730 ctx->next[ctx->next_num++] = next;
2733 action_rss_data = ctx->object;
2734 action_rss_data->conf.queue_num = i;
2735 action_rss_data->conf.queue = i ? action_rss_data->queue : NULL;
2739 /** Parse tokens for destroy command. */
2741 parse_destroy(struct context *ctx, const struct token *token,
2742 const char *str, unsigned int len,
2743 void *buf, unsigned int size)
2745 struct buffer *out = buf;
2747 /* Token name must match. */
2748 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
2750 /* Nothing else to do if there is no buffer. */
2753 if (!out->command) {
2754 if (ctx->curr != DESTROY)
2756 if (sizeof(*out) > size)
2758 out->command = ctx->curr;
2761 ctx->objmask = NULL;
2762 out->args.destroy.rule =
2763 (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
2767 if (((uint8_t *)(out->args.destroy.rule + out->args.destroy.rule_n) +
2768 sizeof(*out->args.destroy.rule)) > (uint8_t *)out + size)
2771 ctx->object = out->args.destroy.rule + out->args.destroy.rule_n++;
2772 ctx->objmask = NULL;
2776 /** Parse tokens for flush command. */
2778 parse_flush(struct context *ctx, const struct token *token,
2779 const char *str, unsigned int len,
2780 void *buf, unsigned int size)
2782 struct buffer *out = buf;
2784 /* Token name must match. */
2785 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
2787 /* Nothing else to do if there is no buffer. */
2790 if (!out->command) {
2791 if (ctx->curr != FLUSH)
2793 if (sizeof(*out) > size)
2795 out->command = ctx->curr;
2798 ctx->objmask = NULL;
2803 /** Parse tokens for query command. */
2805 parse_query(struct context *ctx, const struct token *token,
2806 const char *str, unsigned int len,
2807 void *buf, unsigned int size)
2809 struct buffer *out = buf;
2811 /* Token name must match. */
2812 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
2814 /* Nothing else to do if there is no buffer. */
2817 if (!out->command) {
2818 if (ctx->curr != QUERY)
2820 if (sizeof(*out) > size)
2822 out->command = ctx->curr;
2825 ctx->objmask = NULL;
2830 /** Parse action names. */
2832 parse_action(struct context *ctx, const struct token *token,
2833 const char *str, unsigned int len,
2834 void *buf, unsigned int size)
2836 struct buffer *out = buf;
2837 const struct arg *arg = pop_args(ctx);
2841 /* Argument is expected. */
2844 /* Parse action name. */
2845 for (i = 0; next_action[i]; ++i) {
2846 const struct parse_action_priv *priv;
2848 token = &token_list[next_action[i]];
2849 if (strcmp_partial(token->name, str, len))
2855 memcpy((uint8_t *)ctx->object + arg->offset,
2861 push_args(ctx, arg);
2865 /** Parse tokens for list command. */
2867 parse_list(struct context *ctx, const struct token *token,
2868 const char *str, unsigned int len,
2869 void *buf, unsigned int size)
2871 struct buffer *out = buf;
2873 /* Token name must match. */
2874 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
2876 /* Nothing else to do if there is no buffer. */
2879 if (!out->command) {
2880 if (ctx->curr != LIST)
2882 if (sizeof(*out) > size)
2884 out->command = ctx->curr;
2887 ctx->objmask = NULL;
2888 out->args.list.group =
2889 (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
2893 if (((uint8_t *)(out->args.list.group + out->args.list.group_n) +
2894 sizeof(*out->args.list.group)) > (uint8_t *)out + size)
2897 ctx->object = out->args.list.group + out->args.list.group_n++;
2898 ctx->objmask = NULL;
2902 /** Parse tokens for isolate command. */
2904 parse_isolate(struct context *ctx, const struct token *token,
2905 const char *str, unsigned int len,
2906 void *buf, unsigned int size)
2908 struct buffer *out = buf;
2910 /* Token name must match. */
2911 if (parse_default(ctx, token, str, len, NULL, 0) < 0)
2913 /* Nothing else to do if there is no buffer. */
2916 if (!out->command) {
2917 if (ctx->curr != ISOLATE)
2919 if (sizeof(*out) > size)
2921 out->command = ctx->curr;
2924 ctx->objmask = NULL;
2930 * Parse signed/unsigned integers 8 to 64-bit long.
2932 * Last argument (ctx->args) is retrieved to determine integer type and
2936 parse_int(struct context *ctx, const struct token *token,
2937 const char *str, unsigned int len,
2938 void *buf, unsigned int size)
2940 const struct arg *arg = pop_args(ctx);
2945 /* Argument is expected. */
2950 (uintmax_t)strtoimax(str, &end, 0) :
2951 strtoumax(str, &end, 0);
2952 if (errno || (size_t)(end - str) != len)
2955 ((arg->sign && ((intmax_t)u < (intmax_t)arg->min ||
2956 (intmax_t)u > (intmax_t)arg->max)) ||
2957 (!arg->sign && (u < arg->min || u > arg->max))))
2962 if (!arg_entry_bf_fill(ctx->object, u, arg) ||
2963 !arg_entry_bf_fill(ctx->objmask, -1, arg))
2967 buf = (uint8_t *)ctx->object + arg->offset;
2971 case sizeof(uint8_t):
2972 *(uint8_t *)buf = u;
2974 case sizeof(uint16_t):
2975 *(uint16_t *)buf = arg->hton ? rte_cpu_to_be_16(u) : u;
2977 case sizeof(uint8_t [3]):
2978 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
2980 ((uint8_t *)buf)[0] = u;
2981 ((uint8_t *)buf)[1] = u >> 8;
2982 ((uint8_t *)buf)[2] = u >> 16;
2986 ((uint8_t *)buf)[0] = u >> 16;
2987 ((uint8_t *)buf)[1] = u >> 8;
2988 ((uint8_t *)buf)[2] = u;
2990 case sizeof(uint32_t):
2991 *(uint32_t *)buf = arg->hton ? rte_cpu_to_be_32(u) : u;
2993 case sizeof(uint64_t):
2994 *(uint64_t *)buf = arg->hton ? rte_cpu_to_be_64(u) : u;
2999 if (ctx->objmask && buf != (uint8_t *)ctx->objmask + arg->offset) {
3001 buf = (uint8_t *)ctx->objmask + arg->offset;
3006 push_args(ctx, arg);
3013 * Three arguments (ctx->args) are retrieved from the stack to store data,
3014 * its actual length and address (in that order).
3017 parse_string(struct context *ctx, const struct token *token,
3018 const char *str, unsigned int len,
3019 void *buf, unsigned int size)
3021 const struct arg *arg_data = pop_args(ctx);
3022 const struct arg *arg_len = pop_args(ctx);
3023 const struct arg *arg_addr = pop_args(ctx);
3024 char tmp[16]; /* Ought to be enough. */
3027 /* Arguments are expected. */
3031 push_args(ctx, arg_data);
3035 push_args(ctx, arg_len);
3036 push_args(ctx, arg_data);
3039 size = arg_data->size;
3040 /* Bit-mask fill is not supported. */
3041 if (arg_data->mask || size < len)
3045 /* Let parse_int() fill length information first. */
3046 ret = snprintf(tmp, sizeof(tmp), "%u", len);
3049 push_args(ctx, arg_len);
3050 ret = parse_int(ctx, token, tmp, ret, NULL, 0);
3055 buf = (uint8_t *)ctx->object + arg_data->offset;
3056 /* Output buffer is not necessarily NUL-terminated. */
3057 memcpy(buf, str, len);
3058 memset((uint8_t *)buf + len, 0x00, size - len);
3060 memset((uint8_t *)ctx->objmask + arg_data->offset, 0xff, len);
3061 /* Save address if requested. */
3062 if (arg_addr->size) {
3063 memcpy((uint8_t *)ctx->object + arg_addr->offset,
3065 (uint8_t *)ctx->object + arg_data->offset
3069 memcpy((uint8_t *)ctx->objmask + arg_addr->offset,
3071 (uint8_t *)ctx->objmask + arg_data->offset
3077 push_args(ctx, arg_addr);
3078 push_args(ctx, arg_len);
3079 push_args(ctx, arg_data);
3084 * Parse a MAC address.
3086 * Last argument (ctx->args) is retrieved to determine storage size and
3090 parse_mac_addr(struct context *ctx, const struct token *token,
3091 const char *str, unsigned int len,
3092 void *buf, unsigned int size)
3094 const struct arg *arg = pop_args(ctx);
3095 struct ether_addr tmp;
3099 /* Argument is expected. */
3103 /* Bit-mask fill is not supported. */
3104 if (arg->mask || size != sizeof(tmp))
3106 /* Only network endian is supported. */
3109 ret = cmdline_parse_etheraddr(NULL, str, &tmp, size);
3110 if (ret < 0 || (unsigned int)ret != len)
3114 buf = (uint8_t *)ctx->object + arg->offset;
3115 memcpy(buf, &tmp, size);
3117 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
3120 push_args(ctx, arg);
3125 * Parse an IPv4 address.
3127 * Last argument (ctx->args) is retrieved to determine storage size and
3131 parse_ipv4_addr(struct context *ctx, const struct token *token,
3132 const char *str, unsigned int len,
3133 void *buf, unsigned int size)
3135 const struct arg *arg = pop_args(ctx);
3140 /* Argument is expected. */
3144 /* Bit-mask fill is not supported. */
3145 if (arg->mask || size != sizeof(tmp))
3147 /* Only network endian is supported. */
3150 memcpy(str2, str, len);
3152 ret = inet_pton(AF_INET, str2, &tmp);
3154 /* Attempt integer parsing. */
3155 push_args(ctx, arg);
3156 return parse_int(ctx, token, str, len, buf, size);
3160 buf = (uint8_t *)ctx->object + arg->offset;
3161 memcpy(buf, &tmp, size);
3163 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
3166 push_args(ctx, arg);
3171 * Parse an IPv6 address.
3173 * Last argument (ctx->args) is retrieved to determine storage size and
3177 parse_ipv6_addr(struct context *ctx, const struct token *token,
3178 const char *str, unsigned int len,
3179 void *buf, unsigned int size)
3181 const struct arg *arg = pop_args(ctx);
3183 struct in6_addr tmp;
3187 /* Argument is expected. */
3191 /* Bit-mask fill is not supported. */
3192 if (arg->mask || size != sizeof(tmp))
3194 /* Only network endian is supported. */
3197 memcpy(str2, str, len);
3199 ret = inet_pton(AF_INET6, str2, &tmp);
3204 buf = (uint8_t *)ctx->object + arg->offset;
3205 memcpy(buf, &tmp, size);
3207 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
3210 push_args(ctx, arg);
3214 /** Boolean values (even indices stand for false). */
3215 static const char *const boolean_name[] = {
3225 * Parse a boolean value.
3227 * Last argument (ctx->args) is retrieved to determine storage size and
3231 parse_boolean(struct context *ctx, const struct token *token,
3232 const char *str, unsigned int len,
3233 void *buf, unsigned int size)
3235 const struct arg *arg = pop_args(ctx);
3239 /* Argument is expected. */
3242 for (i = 0; boolean_name[i]; ++i)
3243 if (!strcmp_partial(boolean_name[i], str, len))
3245 /* Process token as integer. */
3246 if (boolean_name[i])
3247 str = i & 1 ? "1" : "0";
3248 push_args(ctx, arg);
3249 ret = parse_int(ctx, token, str, strlen(str), buf, size);
3250 return ret > 0 ? (int)len : ret;
3253 /** Parse port and update context. */
3255 parse_port(struct context *ctx, const struct token *token,
3256 const char *str, unsigned int len,
3257 void *buf, unsigned int size)
3259 struct buffer *out = &(struct buffer){ .port = 0 };
3267 ctx->objmask = NULL;
3268 size = sizeof(*out);
3270 ret = parse_int(ctx, token, str, len, out, size);
3272 ctx->port = out->port;
3278 /** No completion. */
3280 comp_none(struct context *ctx, const struct token *token,
3281 unsigned int ent, char *buf, unsigned int size)
3291 /** Complete boolean values. */
3293 comp_boolean(struct context *ctx, const struct token *token,
3294 unsigned int ent, char *buf, unsigned int size)
3300 for (i = 0; boolean_name[i]; ++i)
3301 if (buf && i == ent)
3302 return snprintf(buf, size, "%s", boolean_name[i]);
3308 /** Complete action names. */
3310 comp_action(struct context *ctx, const struct token *token,
3311 unsigned int ent, char *buf, unsigned int size)
3317 for (i = 0; next_action[i]; ++i)
3318 if (buf && i == ent)
3319 return snprintf(buf, size, "%s",
3320 token_list[next_action[i]].name);
3326 /** Complete available ports. */
3328 comp_port(struct context *ctx, const struct token *token,
3329 unsigned int ent, char *buf, unsigned int size)
3336 RTE_ETH_FOREACH_DEV(p) {
3337 if (buf && i == ent)
3338 return snprintf(buf, size, "%u", p);
3346 /** Complete available rule IDs. */
3348 comp_rule_id(struct context *ctx, const struct token *token,
3349 unsigned int ent, char *buf, unsigned int size)
3352 struct rte_port *port;
3353 struct port_flow *pf;
3356 if (port_id_is_invalid(ctx->port, DISABLED_WARN) ||
3357 ctx->port == (portid_t)RTE_PORT_ALL)
3359 port = &ports[ctx->port];
3360 for (pf = port->flow_list; pf != NULL; pf = pf->next) {
3361 if (buf && i == ent)
3362 return snprintf(buf, size, "%u", pf->id);
3370 /** Complete type field for RSS action. */
3372 comp_vc_action_rss_type(struct context *ctx, const struct token *token,
3373 unsigned int ent, char *buf, unsigned int size)
3379 for (i = 0; rss_type_table[i].str; ++i)
3384 return snprintf(buf, size, "%s", rss_type_table[ent].str);
3386 return snprintf(buf, size, "end");
3390 /** Complete queue field for RSS action. */
3392 comp_vc_action_rss_queue(struct context *ctx, const struct token *token,
3393 unsigned int ent, char *buf, unsigned int size)
3400 return snprintf(buf, size, "%u", ent);
3402 return snprintf(buf, size, "end");
3406 /** Internal context. */
3407 static struct context cmd_flow_context;
3409 /** Global parser instance (cmdline API). */
3410 cmdline_parse_inst_t cmd_flow;
3412 /** Initialize context. */
3414 cmd_flow_context_init(struct context *ctx)
3416 /* A full memset() is not necessary. */
3426 ctx->objmask = NULL;
3429 /** Parse a token (cmdline API). */
3431 cmd_flow_parse(cmdline_parse_token_hdr_t *hdr, const char *src, void *result,
3434 struct context *ctx = &cmd_flow_context;
3435 const struct token *token;
3436 const enum index *list;
3441 token = &token_list[ctx->curr];
3442 /* Check argument length. */
3445 for (len = 0; src[len]; ++len)
3446 if (src[len] == '#' || isspace(src[len]))
3450 /* Last argument and EOL detection. */
3451 for (i = len; src[i]; ++i)
3452 if (src[i] == '#' || src[i] == '\r' || src[i] == '\n')
3454 else if (!isspace(src[i])) {
3459 if (src[i] == '\r' || src[i] == '\n') {
3463 /* Initialize context if necessary. */
3464 if (!ctx->next_num) {
3467 ctx->next[ctx->next_num++] = token->next[0];
3469 /* Process argument through candidates. */
3470 ctx->prev = ctx->curr;
3471 list = ctx->next[ctx->next_num - 1];
3472 for (i = 0; list[i]; ++i) {
3473 const struct token *next = &token_list[list[i]];
3476 ctx->curr = list[i];
3478 tmp = next->call(ctx, next, src, len, result, size);
3480 tmp = parse_default(ctx, next, src, len, result, size);
3481 if (tmp == -1 || tmp != len)
3489 /* Push subsequent tokens if any. */
3491 for (i = 0; token->next[i]; ++i) {
3492 if (ctx->next_num == RTE_DIM(ctx->next))
3494 ctx->next[ctx->next_num++] = token->next[i];
3496 /* Push arguments if any. */
3498 for (i = 0; token->args[i]; ++i) {
3499 if (ctx->args_num == RTE_DIM(ctx->args))
3501 ctx->args[ctx->args_num++] = token->args[i];
3506 /** Return number of completion entries (cmdline API). */
3508 cmd_flow_complete_get_nb(cmdline_parse_token_hdr_t *hdr)
3510 struct context *ctx = &cmd_flow_context;
3511 const struct token *token = &token_list[ctx->curr];
3512 const enum index *list;
3516 /* Count number of tokens in current list. */
3518 list = ctx->next[ctx->next_num - 1];
3520 list = token->next[0];
3521 for (i = 0; list[i]; ++i)
3526 * If there is a single token, use its completion callback, otherwise
3527 * return the number of entries.
3529 token = &token_list[list[0]];
3530 if (i == 1 && token->comp) {
3531 /* Save index for cmd_flow_get_help(). */
3532 ctx->prev = list[0];
3533 return token->comp(ctx, token, 0, NULL, 0);
3538 /** Return a completion entry (cmdline API). */
3540 cmd_flow_complete_get_elt(cmdline_parse_token_hdr_t *hdr, int index,
3541 char *dst, unsigned int size)
3543 struct context *ctx = &cmd_flow_context;
3544 const struct token *token = &token_list[ctx->curr];
3545 const enum index *list;
3549 /* Count number of tokens in current list. */
3551 list = ctx->next[ctx->next_num - 1];
3553 list = token->next[0];
3554 for (i = 0; list[i]; ++i)
3558 /* If there is a single token, use its completion callback. */
3559 token = &token_list[list[0]];
3560 if (i == 1 && token->comp) {
3561 /* Save index for cmd_flow_get_help(). */
3562 ctx->prev = list[0];
3563 return token->comp(ctx, token, index, dst, size) < 0 ? -1 : 0;
3565 /* Otherwise make sure the index is valid and use defaults. */
3568 token = &token_list[list[index]];
3569 snprintf(dst, size, "%s", token->name);
3570 /* Save index for cmd_flow_get_help(). */
3571 ctx->prev = list[index];
3575 /** Populate help strings for current token (cmdline API). */
3577 cmd_flow_get_help(cmdline_parse_token_hdr_t *hdr, char *dst, unsigned int size)
3579 struct context *ctx = &cmd_flow_context;
3580 const struct token *token = &token_list[ctx->prev];
3585 /* Set token type and update global help with details. */
3586 snprintf(dst, size, "%s", (token->type ? token->type : "TOKEN"));
3588 cmd_flow.help_str = token->help;
3590 cmd_flow.help_str = token->name;
3594 /** Token definition template (cmdline API). */
3595 static struct cmdline_token_hdr cmd_flow_token_hdr = {
3596 .ops = &(struct cmdline_token_ops){
3597 .parse = cmd_flow_parse,
3598 .complete_get_nb = cmd_flow_complete_get_nb,
3599 .complete_get_elt = cmd_flow_complete_get_elt,
3600 .get_help = cmd_flow_get_help,
3605 /** Populate the next dynamic token. */
3607 cmd_flow_tok(cmdline_parse_token_hdr_t **hdr,
3608 cmdline_parse_token_hdr_t **hdr_inst)
3610 struct context *ctx = &cmd_flow_context;
3612 /* Always reinitialize context before requesting the first token. */
3613 if (!(hdr_inst - cmd_flow.tokens))
3614 cmd_flow_context_init(ctx);
3615 /* Return NULL when no more tokens are expected. */
3616 if (!ctx->next_num && ctx->curr) {
3620 /* Determine if command should end here. */
3621 if (ctx->eol && ctx->last && ctx->next_num) {
3622 const enum index *list = ctx->next[ctx->next_num - 1];
3625 for (i = 0; list[i]; ++i) {
3632 *hdr = &cmd_flow_token_hdr;
3635 /** Dispatch parsed buffer to function calls. */
3637 cmd_flow_parsed(const struct buffer *in)
3639 switch (in->command) {
3641 port_flow_validate(in->port, &in->args.vc.attr,
3642 in->args.vc.pattern, in->args.vc.actions);
3645 port_flow_create(in->port, &in->args.vc.attr,
3646 in->args.vc.pattern, in->args.vc.actions);
3649 port_flow_destroy(in->port, in->args.destroy.rule_n,
3650 in->args.destroy.rule);
3653 port_flow_flush(in->port);
3656 port_flow_query(in->port, in->args.query.rule,
3657 in->args.query.action);
3660 port_flow_list(in->port, in->args.list.group_n,
3661 in->args.list.group);
3664 port_flow_isolate(in->port, in->args.isolate.set);
3671 /** Token generator and output processing callback (cmdline API). */
3673 cmd_flow_cb(void *arg0, struct cmdline *cl, void *arg2)
3676 cmd_flow_tok(arg0, arg2);
3678 cmd_flow_parsed(arg0);
3681 /** Global parser instance (cmdline API). */
3682 cmdline_parse_inst_t cmd_flow = {
3684 .data = NULL, /**< Unused. */
3685 .help_str = NULL, /**< Updated by cmd_flow_get_help(). */
3688 }, /**< Tokens are returned by cmd_flow_tok(). */