xref: /dpdk/app/test-pmd/cmdline_flow.c (revision 9cd9d3e702fba4700539c1a2eddac13dd14ecf70)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2016 6WIND S.A.
3  * Copyright 2016 Mellanox Technologies, Ltd
4  */
5 
6 #include <stddef.h>
7 #include <stdint.h>
8 #include <stdio.h>
9 #include <inttypes.h>
10 #include <errno.h>
11 #include <ctype.h>
12 #include <string.h>
13 #include <arpa/inet.h>
14 #include <sys/socket.h>
15 
16 #include <rte_string_fns.h>
17 #include <rte_common.h>
18 #include <rte_ethdev.h>
19 #include <rte_byteorder.h>
20 #include <cmdline_parse.h>
21 #include <cmdline_parse_etheraddr.h>
22 #include <cmdline_parse_string.h>
23 #include <cmdline_parse_num.h>
24 #include <rte_flow.h>
25 #include <rte_hexdump.h>
26 
27 #include "testpmd.h"
28 
29 /** Parser token indices. */
30 enum index {
31 	/* Special tokens. */
32 	ZERO = 0,
33 	END,
34 	START_SET,
35 	END_SET,
36 
37 	/* Common tokens. */
38 	INTEGER,
39 	UNSIGNED,
40 	PREFIX,
41 	BOOLEAN,
42 	STRING,
43 	HEX,
44 	FILE_PATH,
45 	MAC_ADDR,
46 	IPV4_ADDR,
47 	IPV6_ADDR,
48 	RULE_ID,
49 	PORT_ID,
50 	GROUP_ID,
51 	PRIORITY_LEVEL,
52 
53 	/* Top-level command. */
54 	SET,
55 	/* Sub-leve commands. */
56 	SET_RAW_ENCAP,
57 	SET_RAW_DECAP,
58 	SET_RAW_INDEX,
59 
60 	/* Top-level command. */
61 	FLOW,
62 	/* Sub-level commands. */
63 	VALIDATE,
64 	CREATE,
65 	DESTROY,
66 	FLUSH,
67 	DUMP,
68 	QUERY,
69 	LIST,
70 	ISOLATE,
71 
72 	/* Destroy arguments. */
73 	DESTROY_RULE,
74 
75 	/* Query arguments. */
76 	QUERY_ACTION,
77 
78 	/* List arguments. */
79 	LIST_GROUP,
80 
81 	/* Validate/create arguments. */
82 	GROUP,
83 	PRIORITY,
84 	INGRESS,
85 	EGRESS,
86 	TRANSFER,
87 
88 	/* Validate/create pattern. */
89 	PATTERN,
90 	ITEM_PARAM_IS,
91 	ITEM_PARAM_SPEC,
92 	ITEM_PARAM_LAST,
93 	ITEM_PARAM_MASK,
94 	ITEM_PARAM_PREFIX,
95 	ITEM_NEXT,
96 	ITEM_END,
97 	ITEM_VOID,
98 	ITEM_INVERT,
99 	ITEM_ANY,
100 	ITEM_ANY_NUM,
101 	ITEM_PF,
102 	ITEM_VF,
103 	ITEM_VF_ID,
104 	ITEM_PHY_PORT,
105 	ITEM_PHY_PORT_INDEX,
106 	ITEM_PORT_ID,
107 	ITEM_PORT_ID_ID,
108 	ITEM_MARK,
109 	ITEM_MARK_ID,
110 	ITEM_RAW,
111 	ITEM_RAW_RELATIVE,
112 	ITEM_RAW_SEARCH,
113 	ITEM_RAW_OFFSET,
114 	ITEM_RAW_LIMIT,
115 	ITEM_RAW_PATTERN,
116 	ITEM_ETH,
117 	ITEM_ETH_DST,
118 	ITEM_ETH_SRC,
119 	ITEM_ETH_TYPE,
120 	ITEM_VLAN,
121 	ITEM_VLAN_TCI,
122 	ITEM_VLAN_PCP,
123 	ITEM_VLAN_DEI,
124 	ITEM_VLAN_VID,
125 	ITEM_VLAN_INNER_TYPE,
126 	ITEM_IPV4,
127 	ITEM_IPV4_TOS,
128 	ITEM_IPV4_TTL,
129 	ITEM_IPV4_PROTO,
130 	ITEM_IPV4_SRC,
131 	ITEM_IPV4_DST,
132 	ITEM_IPV6,
133 	ITEM_IPV6_TC,
134 	ITEM_IPV6_FLOW,
135 	ITEM_IPV6_PROTO,
136 	ITEM_IPV6_HOP,
137 	ITEM_IPV6_SRC,
138 	ITEM_IPV6_DST,
139 	ITEM_ICMP,
140 	ITEM_ICMP_TYPE,
141 	ITEM_ICMP_CODE,
142 	ITEM_UDP,
143 	ITEM_UDP_SRC,
144 	ITEM_UDP_DST,
145 	ITEM_TCP,
146 	ITEM_TCP_SRC,
147 	ITEM_TCP_DST,
148 	ITEM_TCP_FLAGS,
149 	ITEM_SCTP,
150 	ITEM_SCTP_SRC,
151 	ITEM_SCTP_DST,
152 	ITEM_SCTP_TAG,
153 	ITEM_SCTP_CKSUM,
154 	ITEM_VXLAN,
155 	ITEM_VXLAN_VNI,
156 	ITEM_E_TAG,
157 	ITEM_E_TAG_GRP_ECID_B,
158 	ITEM_NVGRE,
159 	ITEM_NVGRE_TNI,
160 	ITEM_MPLS,
161 	ITEM_MPLS_LABEL,
162 	ITEM_MPLS_TC,
163 	ITEM_MPLS_S,
164 	ITEM_GRE,
165 	ITEM_GRE_PROTO,
166 	ITEM_GRE_C_RSVD0_VER,
167 	ITEM_GRE_C_BIT,
168 	ITEM_GRE_K_BIT,
169 	ITEM_GRE_S_BIT,
170 	ITEM_FUZZY,
171 	ITEM_FUZZY_THRESH,
172 	ITEM_GTP,
173 	ITEM_GTP_MSG_TYPE,
174 	ITEM_GTP_TEID,
175 	ITEM_GTPC,
176 	ITEM_GTPU,
177 	ITEM_GENEVE,
178 	ITEM_GENEVE_VNI,
179 	ITEM_GENEVE_PROTO,
180 	ITEM_VXLAN_GPE,
181 	ITEM_VXLAN_GPE_VNI,
182 	ITEM_ARP_ETH_IPV4,
183 	ITEM_ARP_ETH_IPV4_SHA,
184 	ITEM_ARP_ETH_IPV4_SPA,
185 	ITEM_ARP_ETH_IPV4_THA,
186 	ITEM_ARP_ETH_IPV4_TPA,
187 	ITEM_IPV6_EXT,
188 	ITEM_IPV6_EXT_NEXT_HDR,
189 	ITEM_ICMP6,
190 	ITEM_ICMP6_TYPE,
191 	ITEM_ICMP6_CODE,
192 	ITEM_ICMP6_ND_NS,
193 	ITEM_ICMP6_ND_NS_TARGET_ADDR,
194 	ITEM_ICMP6_ND_NA,
195 	ITEM_ICMP6_ND_NA_TARGET_ADDR,
196 	ITEM_ICMP6_ND_OPT,
197 	ITEM_ICMP6_ND_OPT_TYPE,
198 	ITEM_ICMP6_ND_OPT_SLA_ETH,
199 	ITEM_ICMP6_ND_OPT_SLA_ETH_SLA,
200 	ITEM_ICMP6_ND_OPT_TLA_ETH,
201 	ITEM_ICMP6_ND_OPT_TLA_ETH_TLA,
202 	ITEM_META,
203 	ITEM_META_DATA,
204 	ITEM_GRE_KEY,
205 	ITEM_GRE_KEY_VALUE,
206 	ITEM_GTP_PSC,
207 	ITEM_GTP_PSC_QFI,
208 	ITEM_GTP_PSC_PDU_T,
209 	ITEM_PPPOES,
210 	ITEM_PPPOED,
211 	ITEM_PPPOE_SEID,
212 	ITEM_PPPOE_PROTO_ID,
213 	ITEM_HIGIG2,
214 	ITEM_HIGIG2_CLASSIFICATION,
215 	ITEM_HIGIG2_VID,
216 	ITEM_TAG,
217 	ITEM_TAG_DATA,
218 	ITEM_TAG_INDEX,
219 	ITEM_L2TPV3OIP,
220 	ITEM_L2TPV3OIP_SESSION_ID,
221 	ITEM_ESP,
222 	ITEM_ESP_SPI,
223 	ITEM_AH,
224 	ITEM_AH_SPI,
225 	ITEM_PFCP,
226 	ITEM_PFCP_S_FIELD,
227 	ITEM_PFCP_SEID,
228 
229 	/* Validate/create actions. */
230 	ACTIONS,
231 	ACTION_NEXT,
232 	ACTION_END,
233 	ACTION_VOID,
234 	ACTION_PASSTHRU,
235 	ACTION_JUMP,
236 	ACTION_JUMP_GROUP,
237 	ACTION_MARK,
238 	ACTION_MARK_ID,
239 	ACTION_FLAG,
240 	ACTION_QUEUE,
241 	ACTION_QUEUE_INDEX,
242 	ACTION_DROP,
243 	ACTION_COUNT,
244 	ACTION_COUNT_SHARED,
245 	ACTION_COUNT_ID,
246 	ACTION_RSS,
247 	ACTION_RSS_FUNC,
248 	ACTION_RSS_LEVEL,
249 	ACTION_RSS_FUNC_DEFAULT,
250 	ACTION_RSS_FUNC_TOEPLITZ,
251 	ACTION_RSS_FUNC_SIMPLE_XOR,
252 	ACTION_RSS_FUNC_SYMMETRIC_TOEPLITZ,
253 	ACTION_RSS_TYPES,
254 	ACTION_RSS_TYPE,
255 	ACTION_RSS_KEY,
256 	ACTION_RSS_KEY_LEN,
257 	ACTION_RSS_QUEUES,
258 	ACTION_RSS_QUEUE,
259 	ACTION_PF,
260 	ACTION_VF,
261 	ACTION_VF_ORIGINAL,
262 	ACTION_VF_ID,
263 	ACTION_PHY_PORT,
264 	ACTION_PHY_PORT_ORIGINAL,
265 	ACTION_PHY_PORT_INDEX,
266 	ACTION_PORT_ID,
267 	ACTION_PORT_ID_ORIGINAL,
268 	ACTION_PORT_ID_ID,
269 	ACTION_METER,
270 	ACTION_METER_ID,
271 	ACTION_OF_SET_MPLS_TTL,
272 	ACTION_OF_SET_MPLS_TTL_MPLS_TTL,
273 	ACTION_OF_DEC_MPLS_TTL,
274 	ACTION_OF_SET_NW_TTL,
275 	ACTION_OF_SET_NW_TTL_NW_TTL,
276 	ACTION_OF_DEC_NW_TTL,
277 	ACTION_OF_COPY_TTL_OUT,
278 	ACTION_OF_COPY_TTL_IN,
279 	ACTION_OF_POP_VLAN,
280 	ACTION_OF_PUSH_VLAN,
281 	ACTION_OF_PUSH_VLAN_ETHERTYPE,
282 	ACTION_OF_SET_VLAN_VID,
283 	ACTION_OF_SET_VLAN_VID_VLAN_VID,
284 	ACTION_OF_SET_VLAN_PCP,
285 	ACTION_OF_SET_VLAN_PCP_VLAN_PCP,
286 	ACTION_OF_POP_MPLS,
287 	ACTION_OF_POP_MPLS_ETHERTYPE,
288 	ACTION_OF_PUSH_MPLS,
289 	ACTION_OF_PUSH_MPLS_ETHERTYPE,
290 	ACTION_VXLAN_ENCAP,
291 	ACTION_VXLAN_DECAP,
292 	ACTION_NVGRE_ENCAP,
293 	ACTION_NVGRE_DECAP,
294 	ACTION_L2_ENCAP,
295 	ACTION_L2_DECAP,
296 	ACTION_MPLSOGRE_ENCAP,
297 	ACTION_MPLSOGRE_DECAP,
298 	ACTION_MPLSOUDP_ENCAP,
299 	ACTION_MPLSOUDP_DECAP,
300 	ACTION_SET_IPV4_SRC,
301 	ACTION_SET_IPV4_SRC_IPV4_SRC,
302 	ACTION_SET_IPV4_DST,
303 	ACTION_SET_IPV4_DST_IPV4_DST,
304 	ACTION_SET_IPV6_SRC,
305 	ACTION_SET_IPV6_SRC_IPV6_SRC,
306 	ACTION_SET_IPV6_DST,
307 	ACTION_SET_IPV6_DST_IPV6_DST,
308 	ACTION_SET_TP_SRC,
309 	ACTION_SET_TP_SRC_TP_SRC,
310 	ACTION_SET_TP_DST,
311 	ACTION_SET_TP_DST_TP_DST,
312 	ACTION_MAC_SWAP,
313 	ACTION_DEC_TTL,
314 	ACTION_SET_TTL,
315 	ACTION_SET_TTL_TTL,
316 	ACTION_SET_MAC_SRC,
317 	ACTION_SET_MAC_SRC_MAC_SRC,
318 	ACTION_SET_MAC_DST,
319 	ACTION_SET_MAC_DST_MAC_DST,
320 	ACTION_INC_TCP_SEQ,
321 	ACTION_INC_TCP_SEQ_VALUE,
322 	ACTION_DEC_TCP_SEQ,
323 	ACTION_DEC_TCP_SEQ_VALUE,
324 	ACTION_INC_TCP_ACK,
325 	ACTION_INC_TCP_ACK_VALUE,
326 	ACTION_DEC_TCP_ACK,
327 	ACTION_DEC_TCP_ACK_VALUE,
328 	ACTION_RAW_ENCAP,
329 	ACTION_RAW_DECAP,
330 	ACTION_RAW_ENCAP_INDEX,
331 	ACTION_RAW_ENCAP_INDEX_VALUE,
332 	ACTION_RAW_DECAP_INDEX,
333 	ACTION_RAW_DECAP_INDEX_VALUE,
334 	ACTION_SET_TAG,
335 	ACTION_SET_TAG_DATA,
336 	ACTION_SET_TAG_INDEX,
337 	ACTION_SET_TAG_MASK,
338 	ACTION_SET_META,
339 	ACTION_SET_META_DATA,
340 	ACTION_SET_META_MASK,
341 	ACTION_SET_IPV4_DSCP,
342 	ACTION_SET_IPV4_DSCP_VALUE,
343 	ACTION_SET_IPV6_DSCP,
344 	ACTION_SET_IPV6_DSCP_VALUE,
345 };
346 
347 /** Maximum size for pattern in struct rte_flow_item_raw. */
348 #define ITEM_RAW_PATTERN_SIZE 40
349 
350 /** Storage size for struct rte_flow_item_raw including pattern. */
351 #define ITEM_RAW_SIZE \
352 	(sizeof(struct rte_flow_item_raw) + ITEM_RAW_PATTERN_SIZE)
353 
354 /** Maximum number of queue indices in struct rte_flow_action_rss. */
355 #define ACTION_RSS_QUEUE_NUM 128
356 
357 /** Storage for struct rte_flow_action_rss including external data. */
358 struct action_rss_data {
359 	struct rte_flow_action_rss conf;
360 	uint8_t key[RSS_HASH_KEY_LENGTH];
361 	uint16_t queue[ACTION_RSS_QUEUE_NUM];
362 };
363 
364 /** Maximum data size in struct rte_flow_action_raw_encap. */
365 #define ACTION_RAW_ENCAP_MAX_DATA 128
366 #define RAW_ENCAP_CONFS_MAX_NUM 8
367 
368 /** Storage for struct rte_flow_action_raw_encap. */
369 struct raw_encap_conf {
370 	uint8_t data[ACTION_RAW_ENCAP_MAX_DATA];
371 	uint8_t preserve[ACTION_RAW_ENCAP_MAX_DATA];
372 	size_t size;
373 };
374 
375 struct raw_encap_conf raw_encap_confs[RAW_ENCAP_CONFS_MAX_NUM];
376 
377 /** Storage for struct rte_flow_action_raw_encap including external data. */
378 struct action_raw_encap_data {
379 	struct rte_flow_action_raw_encap conf;
380 	uint8_t data[ACTION_RAW_ENCAP_MAX_DATA];
381 	uint8_t preserve[ACTION_RAW_ENCAP_MAX_DATA];
382 	uint16_t idx;
383 };
384 
385 /** Storage for struct rte_flow_action_raw_decap. */
386 struct raw_decap_conf {
387 	uint8_t data[ACTION_RAW_ENCAP_MAX_DATA];
388 	size_t size;
389 };
390 
391 struct raw_decap_conf raw_decap_confs[RAW_ENCAP_CONFS_MAX_NUM];
392 
393 /** Storage for struct rte_flow_action_raw_decap including external data. */
394 struct action_raw_decap_data {
395 	struct rte_flow_action_raw_decap conf;
396 	uint8_t data[ACTION_RAW_ENCAP_MAX_DATA];
397 	uint16_t idx;
398 };
399 
400 struct vxlan_encap_conf vxlan_encap_conf = {
401 	.select_ipv4 = 1,
402 	.select_vlan = 0,
403 	.select_tos_ttl = 0,
404 	.vni = "\x00\x00\x00",
405 	.udp_src = 0,
406 	.udp_dst = RTE_BE16(4789),
407 	.ipv4_src = RTE_IPV4(127, 0, 0, 1),
408 	.ipv4_dst = RTE_IPV4(255, 255, 255, 255),
409 	.ipv6_src = "\x00\x00\x00\x00\x00\x00\x00\x00"
410 		"\x00\x00\x00\x00\x00\x00\x00\x01",
411 	.ipv6_dst = "\x00\x00\x00\x00\x00\x00\x00\x00"
412 		"\x00\x00\x00\x00\x00\x00\x11\x11",
413 	.vlan_tci = 0,
414 	.ip_tos = 0,
415 	.ip_ttl = 255,
416 	.eth_src = "\x00\x00\x00\x00\x00\x00",
417 	.eth_dst = "\xff\xff\xff\xff\xff\xff",
418 };
419 
420 /** Maximum number of items in struct rte_flow_action_vxlan_encap. */
421 #define ACTION_VXLAN_ENCAP_ITEMS_NUM 6
422 
423 /** Storage for struct rte_flow_action_vxlan_encap including external data. */
424 struct action_vxlan_encap_data {
425 	struct rte_flow_action_vxlan_encap conf;
426 	struct rte_flow_item items[ACTION_VXLAN_ENCAP_ITEMS_NUM];
427 	struct rte_flow_item_eth item_eth;
428 	struct rte_flow_item_vlan item_vlan;
429 	union {
430 		struct rte_flow_item_ipv4 item_ipv4;
431 		struct rte_flow_item_ipv6 item_ipv6;
432 	};
433 	struct rte_flow_item_udp item_udp;
434 	struct rte_flow_item_vxlan item_vxlan;
435 };
436 
437 struct nvgre_encap_conf nvgre_encap_conf = {
438 	.select_ipv4 = 1,
439 	.select_vlan = 0,
440 	.tni = "\x00\x00\x00",
441 	.ipv4_src = RTE_IPV4(127, 0, 0, 1),
442 	.ipv4_dst = RTE_IPV4(255, 255, 255, 255),
443 	.ipv6_src = "\x00\x00\x00\x00\x00\x00\x00\x00"
444 		"\x00\x00\x00\x00\x00\x00\x00\x01",
445 	.ipv6_dst = "\x00\x00\x00\x00\x00\x00\x00\x00"
446 		"\x00\x00\x00\x00\x00\x00\x11\x11",
447 	.vlan_tci = 0,
448 	.eth_src = "\x00\x00\x00\x00\x00\x00",
449 	.eth_dst = "\xff\xff\xff\xff\xff\xff",
450 };
451 
452 /** Maximum number of items in struct rte_flow_action_nvgre_encap. */
453 #define ACTION_NVGRE_ENCAP_ITEMS_NUM 5
454 
455 /** Storage for struct rte_flow_action_nvgre_encap including external data. */
456 struct action_nvgre_encap_data {
457 	struct rte_flow_action_nvgre_encap conf;
458 	struct rte_flow_item items[ACTION_NVGRE_ENCAP_ITEMS_NUM];
459 	struct rte_flow_item_eth item_eth;
460 	struct rte_flow_item_vlan item_vlan;
461 	union {
462 		struct rte_flow_item_ipv4 item_ipv4;
463 		struct rte_flow_item_ipv6 item_ipv6;
464 	};
465 	struct rte_flow_item_nvgre item_nvgre;
466 };
467 
468 struct l2_encap_conf l2_encap_conf;
469 
470 struct l2_decap_conf l2_decap_conf;
471 
472 struct mplsogre_encap_conf mplsogre_encap_conf;
473 
474 struct mplsogre_decap_conf mplsogre_decap_conf;
475 
476 struct mplsoudp_encap_conf mplsoudp_encap_conf;
477 
478 struct mplsoudp_decap_conf mplsoudp_decap_conf;
479 
480 /** Maximum number of subsequent tokens and arguments on the stack. */
481 #define CTX_STACK_SIZE 16
482 
483 /** Parser context. */
484 struct context {
485 	/** Stack of subsequent token lists to process. */
486 	const enum index *next[CTX_STACK_SIZE];
487 	/** Arguments for stacked tokens. */
488 	const void *args[CTX_STACK_SIZE];
489 	enum index curr; /**< Current token index. */
490 	enum index prev; /**< Index of the last token seen. */
491 	int next_num; /**< Number of entries in next[]. */
492 	int args_num; /**< Number of entries in args[]. */
493 	uint32_t eol:1; /**< EOL has been detected. */
494 	uint32_t last:1; /**< No more arguments. */
495 	portid_t port; /**< Current port ID (for completions). */
496 	uint32_t objdata; /**< Object-specific data. */
497 	void *object; /**< Address of current object for relative offsets. */
498 	void *objmask; /**< Object a full mask must be written to. */
499 };
500 
501 /** Token argument. */
502 struct arg {
503 	uint32_t hton:1; /**< Use network byte ordering. */
504 	uint32_t sign:1; /**< Value is signed. */
505 	uint32_t bounded:1; /**< Value is bounded. */
506 	uintmax_t min; /**< Minimum value if bounded. */
507 	uintmax_t max; /**< Maximum value if bounded. */
508 	uint32_t offset; /**< Relative offset from ctx->object. */
509 	uint32_t size; /**< Field size. */
510 	const uint8_t *mask; /**< Bit-mask to use instead of offset/size. */
511 };
512 
513 /** Parser token definition. */
514 struct token {
515 	/** Type displayed during completion (defaults to "TOKEN"). */
516 	const char *type;
517 	/** Help displayed during completion (defaults to token name). */
518 	const char *help;
519 	/** Private data used by parser functions. */
520 	const void *priv;
521 	/**
522 	 * Lists of subsequent tokens to push on the stack. Each call to the
523 	 * parser consumes the last entry of that stack.
524 	 */
525 	const enum index *const *next;
526 	/** Arguments stack for subsequent tokens that need them. */
527 	const struct arg *const *args;
528 	/**
529 	 * Token-processing callback, returns -1 in case of error, the
530 	 * length of the matched string otherwise. If NULL, attempts to
531 	 * match the token name.
532 	 *
533 	 * If buf is not NULL, the result should be stored in it according
534 	 * to context. An error is returned if not large enough.
535 	 */
536 	int (*call)(struct context *ctx, const struct token *token,
537 		    const char *str, unsigned int len,
538 		    void *buf, unsigned int size);
539 	/**
540 	 * Callback that provides possible values for this token, used for
541 	 * completion. Returns -1 in case of error, the number of possible
542 	 * values otherwise. If NULL, the token name is used.
543 	 *
544 	 * If buf is not NULL, entry index ent is written to buf and the
545 	 * full length of the entry is returned (same behavior as
546 	 * snprintf()).
547 	 */
548 	int (*comp)(struct context *ctx, const struct token *token,
549 		    unsigned int ent, char *buf, unsigned int size);
550 	/** Mandatory token name, no default value. */
551 	const char *name;
552 };
553 
554 /** Static initializer for the next field. */
555 #define NEXT(...) (const enum index *const []){ __VA_ARGS__, NULL, }
556 
557 /** Static initializer for a NEXT() entry. */
558 #define NEXT_ENTRY(...) (const enum index []){ __VA_ARGS__, ZERO, }
559 
560 /** Static initializer for the args field. */
561 #define ARGS(...) (const struct arg *const []){ __VA_ARGS__, NULL, }
562 
563 /** Static initializer for ARGS() to target a field. */
564 #define ARGS_ENTRY(s, f) \
565 	(&(const struct arg){ \
566 		.offset = offsetof(s, f), \
567 		.size = sizeof(((s *)0)->f), \
568 	})
569 
570 /** Static initializer for ARGS() to target a bit-field. */
571 #define ARGS_ENTRY_BF(s, f, b) \
572 	(&(const struct arg){ \
573 		.size = sizeof(s), \
574 		.mask = (const void *)&(const s){ .f = (1 << (b)) - 1 }, \
575 	})
576 
577 /** Static initializer for ARGS() to target an arbitrary bit-mask. */
578 #define ARGS_ENTRY_MASK(s, f, m) \
579 	(&(const struct arg){ \
580 		.offset = offsetof(s, f), \
581 		.size = sizeof(((s *)0)->f), \
582 		.mask = (const void *)(m), \
583 	})
584 
585 /** Same as ARGS_ENTRY_MASK() using network byte ordering for the value. */
586 #define ARGS_ENTRY_MASK_HTON(s, f, m) \
587 	(&(const struct arg){ \
588 		.hton = 1, \
589 		.offset = offsetof(s, f), \
590 		.size = sizeof(((s *)0)->f), \
591 		.mask = (const void *)(m), \
592 	})
593 
594 /** Static initializer for ARGS() to target a pointer. */
595 #define ARGS_ENTRY_PTR(s, f) \
596 	(&(const struct arg){ \
597 		.size = sizeof(*((s *)0)->f), \
598 	})
599 
600 /** Static initializer for ARGS() with arbitrary offset and size. */
601 #define ARGS_ENTRY_ARB(o, s) \
602 	(&(const struct arg){ \
603 		.offset = (o), \
604 		.size = (s), \
605 	})
606 
607 /** Same as ARGS_ENTRY_ARB() with bounded values. */
608 #define ARGS_ENTRY_ARB_BOUNDED(o, s, i, a) \
609 	(&(const struct arg){ \
610 		.bounded = 1, \
611 		.min = (i), \
612 		.max = (a), \
613 		.offset = (o), \
614 		.size = (s), \
615 	})
616 
617 /** Same as ARGS_ENTRY() using network byte ordering. */
618 #define ARGS_ENTRY_HTON(s, f) \
619 	(&(const struct arg){ \
620 		.hton = 1, \
621 		.offset = offsetof(s, f), \
622 		.size = sizeof(((s *)0)->f), \
623 	})
624 
625 /** Same as ARGS_ENTRY_HTON() for a single argument, without structure. */
626 #define ARG_ENTRY_HTON(s) \
627 	(&(const struct arg){ \
628 		.hton = 1, \
629 		.offset = 0, \
630 		.size = sizeof(s), \
631 	})
632 
633 /** Parser output buffer layout expected by cmd_flow_parsed(). */
634 struct buffer {
635 	enum index command; /**< Flow command. */
636 	portid_t port; /**< Affected port ID. */
637 	union {
638 		struct {
639 			struct rte_flow_attr attr;
640 			struct rte_flow_item *pattern;
641 			struct rte_flow_action *actions;
642 			uint32_t pattern_n;
643 			uint32_t actions_n;
644 			uint8_t *data;
645 		} vc; /**< Validate/create arguments. */
646 		struct {
647 			uint32_t *rule;
648 			uint32_t rule_n;
649 		} destroy; /**< Destroy arguments. */
650 		struct {
651 			char file[128];
652 		} dump; /**< Dump arguments. */
653 		struct {
654 			uint32_t rule;
655 			struct rte_flow_action action;
656 		} query; /**< Query arguments. */
657 		struct {
658 			uint32_t *group;
659 			uint32_t group_n;
660 		} list; /**< List arguments. */
661 		struct {
662 			int set;
663 		} isolate; /**< Isolated mode arguments. */
664 	} args; /**< Command arguments. */
665 };
666 
667 /** Private data for pattern items. */
668 struct parse_item_priv {
669 	enum rte_flow_item_type type; /**< Item type. */
670 	uint32_t size; /**< Size of item specification structure. */
671 };
672 
673 #define PRIV_ITEM(t, s) \
674 	(&(const struct parse_item_priv){ \
675 		.type = RTE_FLOW_ITEM_TYPE_ ## t, \
676 		.size = s, \
677 	})
678 
679 /** Private data for actions. */
680 struct parse_action_priv {
681 	enum rte_flow_action_type type; /**< Action type. */
682 	uint32_t size; /**< Size of action configuration structure. */
683 };
684 
685 #define PRIV_ACTION(t, s) \
686 	(&(const struct parse_action_priv){ \
687 		.type = RTE_FLOW_ACTION_TYPE_ ## t, \
688 		.size = s, \
689 	})
690 
691 static const enum index next_vc_attr[] = {
692 	GROUP,
693 	PRIORITY,
694 	INGRESS,
695 	EGRESS,
696 	TRANSFER,
697 	PATTERN,
698 	ZERO,
699 };
700 
701 static const enum index next_destroy_attr[] = {
702 	DESTROY_RULE,
703 	END,
704 	ZERO,
705 };
706 
707 static const enum index next_dump_attr[] = {
708 	FILE_PATH,
709 	END,
710 	ZERO,
711 };
712 
713 static const enum index next_list_attr[] = {
714 	LIST_GROUP,
715 	END,
716 	ZERO,
717 };
718 
719 static const enum index item_param[] = {
720 	ITEM_PARAM_IS,
721 	ITEM_PARAM_SPEC,
722 	ITEM_PARAM_LAST,
723 	ITEM_PARAM_MASK,
724 	ITEM_PARAM_PREFIX,
725 	ZERO,
726 };
727 
728 static const enum index next_item[] = {
729 	ITEM_END,
730 	ITEM_VOID,
731 	ITEM_INVERT,
732 	ITEM_ANY,
733 	ITEM_PF,
734 	ITEM_VF,
735 	ITEM_PHY_PORT,
736 	ITEM_PORT_ID,
737 	ITEM_MARK,
738 	ITEM_RAW,
739 	ITEM_ETH,
740 	ITEM_VLAN,
741 	ITEM_IPV4,
742 	ITEM_IPV6,
743 	ITEM_ICMP,
744 	ITEM_UDP,
745 	ITEM_TCP,
746 	ITEM_SCTP,
747 	ITEM_VXLAN,
748 	ITEM_E_TAG,
749 	ITEM_NVGRE,
750 	ITEM_MPLS,
751 	ITEM_GRE,
752 	ITEM_FUZZY,
753 	ITEM_GTP,
754 	ITEM_GTPC,
755 	ITEM_GTPU,
756 	ITEM_GENEVE,
757 	ITEM_VXLAN_GPE,
758 	ITEM_ARP_ETH_IPV4,
759 	ITEM_IPV6_EXT,
760 	ITEM_ICMP6,
761 	ITEM_ICMP6_ND_NS,
762 	ITEM_ICMP6_ND_NA,
763 	ITEM_ICMP6_ND_OPT,
764 	ITEM_ICMP6_ND_OPT_SLA_ETH,
765 	ITEM_ICMP6_ND_OPT_TLA_ETH,
766 	ITEM_META,
767 	ITEM_GRE_KEY,
768 	ITEM_GTP_PSC,
769 	ITEM_PPPOES,
770 	ITEM_PPPOED,
771 	ITEM_PPPOE_PROTO_ID,
772 	ITEM_HIGIG2,
773 	ITEM_TAG,
774 	ITEM_L2TPV3OIP,
775 	ITEM_ESP,
776 	ITEM_AH,
777 	ITEM_PFCP,
778 	END_SET,
779 	ZERO,
780 };
781 
782 static const enum index item_fuzzy[] = {
783 	ITEM_FUZZY_THRESH,
784 	ITEM_NEXT,
785 	ZERO,
786 };
787 
788 static const enum index item_any[] = {
789 	ITEM_ANY_NUM,
790 	ITEM_NEXT,
791 	ZERO,
792 };
793 
794 static const enum index item_vf[] = {
795 	ITEM_VF_ID,
796 	ITEM_NEXT,
797 	ZERO,
798 };
799 
800 static const enum index item_phy_port[] = {
801 	ITEM_PHY_PORT_INDEX,
802 	ITEM_NEXT,
803 	ZERO,
804 };
805 
806 static const enum index item_port_id[] = {
807 	ITEM_PORT_ID_ID,
808 	ITEM_NEXT,
809 	ZERO,
810 };
811 
812 static const enum index item_mark[] = {
813 	ITEM_MARK_ID,
814 	ITEM_NEXT,
815 	ZERO,
816 };
817 
818 static const enum index item_raw[] = {
819 	ITEM_RAW_RELATIVE,
820 	ITEM_RAW_SEARCH,
821 	ITEM_RAW_OFFSET,
822 	ITEM_RAW_LIMIT,
823 	ITEM_RAW_PATTERN,
824 	ITEM_NEXT,
825 	ZERO,
826 };
827 
828 static const enum index item_eth[] = {
829 	ITEM_ETH_DST,
830 	ITEM_ETH_SRC,
831 	ITEM_ETH_TYPE,
832 	ITEM_NEXT,
833 	ZERO,
834 };
835 
836 static const enum index item_vlan[] = {
837 	ITEM_VLAN_TCI,
838 	ITEM_VLAN_PCP,
839 	ITEM_VLAN_DEI,
840 	ITEM_VLAN_VID,
841 	ITEM_VLAN_INNER_TYPE,
842 	ITEM_NEXT,
843 	ZERO,
844 };
845 
846 static const enum index item_ipv4[] = {
847 	ITEM_IPV4_TOS,
848 	ITEM_IPV4_TTL,
849 	ITEM_IPV4_PROTO,
850 	ITEM_IPV4_SRC,
851 	ITEM_IPV4_DST,
852 	ITEM_NEXT,
853 	ZERO,
854 };
855 
856 static const enum index item_ipv6[] = {
857 	ITEM_IPV6_TC,
858 	ITEM_IPV6_FLOW,
859 	ITEM_IPV6_PROTO,
860 	ITEM_IPV6_HOP,
861 	ITEM_IPV6_SRC,
862 	ITEM_IPV6_DST,
863 	ITEM_NEXT,
864 	ZERO,
865 };
866 
867 static const enum index item_icmp[] = {
868 	ITEM_ICMP_TYPE,
869 	ITEM_ICMP_CODE,
870 	ITEM_NEXT,
871 	ZERO,
872 };
873 
874 static const enum index item_udp[] = {
875 	ITEM_UDP_SRC,
876 	ITEM_UDP_DST,
877 	ITEM_NEXT,
878 	ZERO,
879 };
880 
881 static const enum index item_tcp[] = {
882 	ITEM_TCP_SRC,
883 	ITEM_TCP_DST,
884 	ITEM_TCP_FLAGS,
885 	ITEM_NEXT,
886 	ZERO,
887 };
888 
889 static const enum index item_sctp[] = {
890 	ITEM_SCTP_SRC,
891 	ITEM_SCTP_DST,
892 	ITEM_SCTP_TAG,
893 	ITEM_SCTP_CKSUM,
894 	ITEM_NEXT,
895 	ZERO,
896 };
897 
898 static const enum index item_vxlan[] = {
899 	ITEM_VXLAN_VNI,
900 	ITEM_NEXT,
901 	ZERO,
902 };
903 
904 static const enum index item_e_tag[] = {
905 	ITEM_E_TAG_GRP_ECID_B,
906 	ITEM_NEXT,
907 	ZERO,
908 };
909 
910 static const enum index item_nvgre[] = {
911 	ITEM_NVGRE_TNI,
912 	ITEM_NEXT,
913 	ZERO,
914 };
915 
916 static const enum index item_mpls[] = {
917 	ITEM_MPLS_LABEL,
918 	ITEM_MPLS_TC,
919 	ITEM_MPLS_S,
920 	ITEM_NEXT,
921 	ZERO,
922 };
923 
924 static const enum index item_gre[] = {
925 	ITEM_GRE_PROTO,
926 	ITEM_GRE_C_RSVD0_VER,
927 	ITEM_GRE_C_BIT,
928 	ITEM_GRE_K_BIT,
929 	ITEM_GRE_S_BIT,
930 	ITEM_NEXT,
931 	ZERO,
932 };
933 
934 static const enum index item_gre_key[] = {
935 	ITEM_GRE_KEY_VALUE,
936 	ITEM_NEXT,
937 	ZERO,
938 };
939 
940 static const enum index item_gtp[] = {
941 	ITEM_GTP_MSG_TYPE,
942 	ITEM_GTP_TEID,
943 	ITEM_NEXT,
944 	ZERO,
945 };
946 
947 static const enum index item_geneve[] = {
948 	ITEM_GENEVE_VNI,
949 	ITEM_GENEVE_PROTO,
950 	ITEM_NEXT,
951 	ZERO,
952 };
953 
954 static const enum index item_vxlan_gpe[] = {
955 	ITEM_VXLAN_GPE_VNI,
956 	ITEM_NEXT,
957 	ZERO,
958 };
959 
960 static const enum index item_arp_eth_ipv4[] = {
961 	ITEM_ARP_ETH_IPV4_SHA,
962 	ITEM_ARP_ETH_IPV4_SPA,
963 	ITEM_ARP_ETH_IPV4_THA,
964 	ITEM_ARP_ETH_IPV4_TPA,
965 	ITEM_NEXT,
966 	ZERO,
967 };
968 
969 static const enum index item_ipv6_ext[] = {
970 	ITEM_IPV6_EXT_NEXT_HDR,
971 	ITEM_NEXT,
972 	ZERO,
973 };
974 
975 static const enum index item_icmp6[] = {
976 	ITEM_ICMP6_TYPE,
977 	ITEM_ICMP6_CODE,
978 	ITEM_NEXT,
979 	ZERO,
980 };
981 
982 static const enum index item_icmp6_nd_ns[] = {
983 	ITEM_ICMP6_ND_NS_TARGET_ADDR,
984 	ITEM_NEXT,
985 	ZERO,
986 };
987 
988 static const enum index item_icmp6_nd_na[] = {
989 	ITEM_ICMP6_ND_NA_TARGET_ADDR,
990 	ITEM_NEXT,
991 	ZERO,
992 };
993 
994 static const enum index item_icmp6_nd_opt[] = {
995 	ITEM_ICMP6_ND_OPT_TYPE,
996 	ITEM_NEXT,
997 	ZERO,
998 };
999 
1000 static const enum index item_icmp6_nd_opt_sla_eth[] = {
1001 	ITEM_ICMP6_ND_OPT_SLA_ETH_SLA,
1002 	ITEM_NEXT,
1003 	ZERO,
1004 };
1005 
1006 static const enum index item_icmp6_nd_opt_tla_eth[] = {
1007 	ITEM_ICMP6_ND_OPT_TLA_ETH_TLA,
1008 	ITEM_NEXT,
1009 	ZERO,
1010 };
1011 
1012 static const enum index item_meta[] = {
1013 	ITEM_META_DATA,
1014 	ITEM_NEXT,
1015 	ZERO,
1016 };
1017 
1018 static const enum index item_gtp_psc[] = {
1019 	ITEM_GTP_PSC_QFI,
1020 	ITEM_GTP_PSC_PDU_T,
1021 	ITEM_NEXT,
1022 	ZERO,
1023 };
1024 
1025 static const enum index item_pppoed[] = {
1026 	ITEM_PPPOE_SEID,
1027 	ITEM_NEXT,
1028 	ZERO,
1029 };
1030 
1031 static const enum index item_pppoes[] = {
1032 	ITEM_PPPOE_SEID,
1033 	ITEM_NEXT,
1034 	ZERO,
1035 };
1036 
1037 static const enum index item_pppoe_proto_id[] = {
1038 	ITEM_PPPOE_PROTO_ID,
1039 	ITEM_NEXT,
1040 	ZERO,
1041 };
1042 
1043 static const enum index item_higig2[] = {
1044 	ITEM_HIGIG2_CLASSIFICATION,
1045 	ITEM_HIGIG2_VID,
1046 	ITEM_NEXT,
1047 	ZERO,
1048 };
1049 
1050 static const enum index item_esp[] = {
1051 	ITEM_ESP_SPI,
1052 	ITEM_NEXT,
1053 	ZERO,
1054 };
1055 
1056 static const enum index item_ah[] = {
1057 	ITEM_AH_SPI,
1058 	ITEM_NEXT,
1059 	ZERO,
1060 };
1061 
1062 static const enum index item_pfcp[] = {
1063 	ITEM_PFCP_S_FIELD,
1064 	ITEM_PFCP_SEID,
1065 	ITEM_NEXT,
1066 	ZERO,
1067 };
1068 
1069 static const enum index next_set_raw[] = {
1070 	SET_RAW_INDEX,
1071 	ITEM_ETH,
1072 	ZERO,
1073 };
1074 
1075 static const enum index item_tag[] = {
1076 	ITEM_TAG_DATA,
1077 	ITEM_TAG_INDEX,
1078 	ITEM_NEXT,
1079 	ZERO,
1080 };
1081 
1082 static const enum index item_l2tpv3oip[] = {
1083 	ITEM_L2TPV3OIP_SESSION_ID,
1084 	ITEM_NEXT,
1085 	ZERO,
1086 };
1087 
1088 static const enum index next_action[] = {
1089 	ACTION_END,
1090 	ACTION_VOID,
1091 	ACTION_PASSTHRU,
1092 	ACTION_JUMP,
1093 	ACTION_MARK,
1094 	ACTION_FLAG,
1095 	ACTION_QUEUE,
1096 	ACTION_DROP,
1097 	ACTION_COUNT,
1098 	ACTION_RSS,
1099 	ACTION_PF,
1100 	ACTION_VF,
1101 	ACTION_PHY_PORT,
1102 	ACTION_PORT_ID,
1103 	ACTION_METER,
1104 	ACTION_OF_SET_MPLS_TTL,
1105 	ACTION_OF_DEC_MPLS_TTL,
1106 	ACTION_OF_SET_NW_TTL,
1107 	ACTION_OF_DEC_NW_TTL,
1108 	ACTION_OF_COPY_TTL_OUT,
1109 	ACTION_OF_COPY_TTL_IN,
1110 	ACTION_OF_POP_VLAN,
1111 	ACTION_OF_PUSH_VLAN,
1112 	ACTION_OF_SET_VLAN_VID,
1113 	ACTION_OF_SET_VLAN_PCP,
1114 	ACTION_OF_POP_MPLS,
1115 	ACTION_OF_PUSH_MPLS,
1116 	ACTION_VXLAN_ENCAP,
1117 	ACTION_VXLAN_DECAP,
1118 	ACTION_NVGRE_ENCAP,
1119 	ACTION_NVGRE_DECAP,
1120 	ACTION_L2_ENCAP,
1121 	ACTION_L2_DECAP,
1122 	ACTION_MPLSOGRE_ENCAP,
1123 	ACTION_MPLSOGRE_DECAP,
1124 	ACTION_MPLSOUDP_ENCAP,
1125 	ACTION_MPLSOUDP_DECAP,
1126 	ACTION_SET_IPV4_SRC,
1127 	ACTION_SET_IPV4_DST,
1128 	ACTION_SET_IPV6_SRC,
1129 	ACTION_SET_IPV6_DST,
1130 	ACTION_SET_TP_SRC,
1131 	ACTION_SET_TP_DST,
1132 	ACTION_MAC_SWAP,
1133 	ACTION_DEC_TTL,
1134 	ACTION_SET_TTL,
1135 	ACTION_SET_MAC_SRC,
1136 	ACTION_SET_MAC_DST,
1137 	ACTION_INC_TCP_SEQ,
1138 	ACTION_DEC_TCP_SEQ,
1139 	ACTION_INC_TCP_ACK,
1140 	ACTION_DEC_TCP_ACK,
1141 	ACTION_RAW_ENCAP,
1142 	ACTION_RAW_DECAP,
1143 	ACTION_SET_TAG,
1144 	ACTION_SET_META,
1145 	ACTION_SET_IPV4_DSCP,
1146 	ACTION_SET_IPV6_DSCP,
1147 	ZERO,
1148 };
1149 
1150 static const enum index action_mark[] = {
1151 	ACTION_MARK_ID,
1152 	ACTION_NEXT,
1153 	ZERO,
1154 };
1155 
1156 static const enum index action_queue[] = {
1157 	ACTION_QUEUE_INDEX,
1158 	ACTION_NEXT,
1159 	ZERO,
1160 };
1161 
1162 static const enum index action_count[] = {
1163 	ACTION_COUNT_ID,
1164 	ACTION_COUNT_SHARED,
1165 	ACTION_NEXT,
1166 	ZERO,
1167 };
1168 
1169 static const enum index action_rss[] = {
1170 	ACTION_RSS_FUNC,
1171 	ACTION_RSS_LEVEL,
1172 	ACTION_RSS_TYPES,
1173 	ACTION_RSS_KEY,
1174 	ACTION_RSS_KEY_LEN,
1175 	ACTION_RSS_QUEUES,
1176 	ACTION_NEXT,
1177 	ZERO,
1178 };
1179 
1180 static const enum index action_vf[] = {
1181 	ACTION_VF_ORIGINAL,
1182 	ACTION_VF_ID,
1183 	ACTION_NEXT,
1184 	ZERO,
1185 };
1186 
1187 static const enum index action_phy_port[] = {
1188 	ACTION_PHY_PORT_ORIGINAL,
1189 	ACTION_PHY_PORT_INDEX,
1190 	ACTION_NEXT,
1191 	ZERO,
1192 };
1193 
1194 static const enum index action_port_id[] = {
1195 	ACTION_PORT_ID_ORIGINAL,
1196 	ACTION_PORT_ID_ID,
1197 	ACTION_NEXT,
1198 	ZERO,
1199 };
1200 
1201 static const enum index action_meter[] = {
1202 	ACTION_METER_ID,
1203 	ACTION_NEXT,
1204 	ZERO,
1205 };
1206 
1207 static const enum index action_of_set_mpls_ttl[] = {
1208 	ACTION_OF_SET_MPLS_TTL_MPLS_TTL,
1209 	ACTION_NEXT,
1210 	ZERO,
1211 };
1212 
1213 static const enum index action_of_set_nw_ttl[] = {
1214 	ACTION_OF_SET_NW_TTL_NW_TTL,
1215 	ACTION_NEXT,
1216 	ZERO,
1217 };
1218 
1219 static const enum index action_of_push_vlan[] = {
1220 	ACTION_OF_PUSH_VLAN_ETHERTYPE,
1221 	ACTION_NEXT,
1222 	ZERO,
1223 };
1224 
1225 static const enum index action_of_set_vlan_vid[] = {
1226 	ACTION_OF_SET_VLAN_VID_VLAN_VID,
1227 	ACTION_NEXT,
1228 	ZERO,
1229 };
1230 
1231 static const enum index action_of_set_vlan_pcp[] = {
1232 	ACTION_OF_SET_VLAN_PCP_VLAN_PCP,
1233 	ACTION_NEXT,
1234 	ZERO,
1235 };
1236 
1237 static const enum index action_of_pop_mpls[] = {
1238 	ACTION_OF_POP_MPLS_ETHERTYPE,
1239 	ACTION_NEXT,
1240 	ZERO,
1241 };
1242 
1243 static const enum index action_of_push_mpls[] = {
1244 	ACTION_OF_PUSH_MPLS_ETHERTYPE,
1245 	ACTION_NEXT,
1246 	ZERO,
1247 };
1248 
1249 static const enum index action_set_ipv4_src[] = {
1250 	ACTION_SET_IPV4_SRC_IPV4_SRC,
1251 	ACTION_NEXT,
1252 	ZERO,
1253 };
1254 
1255 static const enum index action_set_mac_src[] = {
1256 	ACTION_SET_MAC_SRC_MAC_SRC,
1257 	ACTION_NEXT,
1258 	ZERO,
1259 };
1260 
1261 static const enum index action_set_ipv4_dst[] = {
1262 	ACTION_SET_IPV4_DST_IPV4_DST,
1263 	ACTION_NEXT,
1264 	ZERO,
1265 };
1266 
1267 static const enum index action_set_ipv6_src[] = {
1268 	ACTION_SET_IPV6_SRC_IPV6_SRC,
1269 	ACTION_NEXT,
1270 	ZERO,
1271 };
1272 
1273 static const enum index action_set_ipv6_dst[] = {
1274 	ACTION_SET_IPV6_DST_IPV6_DST,
1275 	ACTION_NEXT,
1276 	ZERO,
1277 };
1278 
1279 static const enum index action_set_tp_src[] = {
1280 	ACTION_SET_TP_SRC_TP_SRC,
1281 	ACTION_NEXT,
1282 	ZERO,
1283 };
1284 
1285 static const enum index action_set_tp_dst[] = {
1286 	ACTION_SET_TP_DST_TP_DST,
1287 	ACTION_NEXT,
1288 	ZERO,
1289 };
1290 
1291 static const enum index action_set_ttl[] = {
1292 	ACTION_SET_TTL_TTL,
1293 	ACTION_NEXT,
1294 	ZERO,
1295 };
1296 
1297 static const enum index action_jump[] = {
1298 	ACTION_JUMP_GROUP,
1299 	ACTION_NEXT,
1300 	ZERO,
1301 };
1302 
1303 static const enum index action_set_mac_dst[] = {
1304 	ACTION_SET_MAC_DST_MAC_DST,
1305 	ACTION_NEXT,
1306 	ZERO,
1307 };
1308 
1309 static const enum index action_inc_tcp_seq[] = {
1310 	ACTION_INC_TCP_SEQ_VALUE,
1311 	ACTION_NEXT,
1312 	ZERO,
1313 };
1314 
1315 static const enum index action_dec_tcp_seq[] = {
1316 	ACTION_DEC_TCP_SEQ_VALUE,
1317 	ACTION_NEXT,
1318 	ZERO,
1319 };
1320 
1321 static const enum index action_inc_tcp_ack[] = {
1322 	ACTION_INC_TCP_ACK_VALUE,
1323 	ACTION_NEXT,
1324 	ZERO,
1325 };
1326 
1327 static const enum index action_dec_tcp_ack[] = {
1328 	ACTION_DEC_TCP_ACK_VALUE,
1329 	ACTION_NEXT,
1330 	ZERO,
1331 };
1332 
1333 static const enum index action_raw_encap[] = {
1334 	ACTION_RAW_ENCAP_INDEX,
1335 	ACTION_NEXT,
1336 	ZERO,
1337 };
1338 
1339 static const enum index action_raw_decap[] = {
1340 	ACTION_RAW_DECAP_INDEX,
1341 	ACTION_NEXT,
1342 	ZERO,
1343 };
1344 
1345 static const enum index action_set_tag[] = {
1346 	ACTION_SET_TAG_DATA,
1347 	ACTION_SET_TAG_INDEX,
1348 	ACTION_SET_TAG_MASK,
1349 	ACTION_NEXT,
1350 	ZERO,
1351 };
1352 
1353 static const enum index action_set_meta[] = {
1354 	ACTION_SET_META_DATA,
1355 	ACTION_SET_META_MASK,
1356 	ACTION_NEXT,
1357 	ZERO,
1358 };
1359 
1360 static const enum index action_set_ipv4_dscp[] = {
1361 	ACTION_SET_IPV4_DSCP_VALUE,
1362 	ACTION_NEXT,
1363 	ZERO,
1364 };
1365 
1366 static const enum index action_set_ipv6_dscp[] = {
1367 	ACTION_SET_IPV6_DSCP_VALUE,
1368 	ACTION_NEXT,
1369 	ZERO,
1370 };
1371 
1372 static int parse_set_raw_encap_decap(struct context *, const struct token *,
1373 				     const char *, unsigned int,
1374 				     void *, unsigned int);
1375 static int parse_set_init(struct context *, const struct token *,
1376 			  const char *, unsigned int,
1377 			  void *, unsigned int);
1378 static int parse_init(struct context *, const struct token *,
1379 		      const char *, unsigned int,
1380 		      void *, unsigned int);
1381 static int parse_vc(struct context *, const struct token *,
1382 		    const char *, unsigned int,
1383 		    void *, unsigned int);
1384 static int parse_vc_spec(struct context *, const struct token *,
1385 			 const char *, unsigned int, void *, unsigned int);
1386 static int parse_vc_conf(struct context *, const struct token *,
1387 			 const char *, unsigned int, void *, unsigned int);
1388 static int parse_vc_action_rss(struct context *, const struct token *,
1389 			       const char *, unsigned int, void *,
1390 			       unsigned int);
1391 static int parse_vc_action_rss_func(struct context *, const struct token *,
1392 				    const char *, unsigned int, void *,
1393 				    unsigned int);
1394 static int parse_vc_action_rss_type(struct context *, const struct token *,
1395 				    const char *, unsigned int, void *,
1396 				    unsigned int);
1397 static int parse_vc_action_rss_queue(struct context *, const struct token *,
1398 				     const char *, unsigned int, void *,
1399 				     unsigned int);
1400 static int parse_vc_action_vxlan_encap(struct context *, const struct token *,
1401 				       const char *, unsigned int, void *,
1402 				       unsigned int);
1403 static int parse_vc_action_nvgre_encap(struct context *, const struct token *,
1404 				       const char *, unsigned int, void *,
1405 				       unsigned int);
1406 static int parse_vc_action_l2_encap(struct context *, const struct token *,
1407 				    const char *, unsigned int, void *,
1408 				    unsigned int);
1409 static int parse_vc_action_l2_decap(struct context *, const struct token *,
1410 				    const char *, unsigned int, void *,
1411 				    unsigned int);
1412 static int parse_vc_action_mplsogre_encap(struct context *,
1413 					  const struct token *, const char *,
1414 					  unsigned int, void *, unsigned int);
1415 static int parse_vc_action_mplsogre_decap(struct context *,
1416 					  const struct token *, const char *,
1417 					  unsigned int, void *, unsigned int);
1418 static int parse_vc_action_mplsoudp_encap(struct context *,
1419 					  const struct token *, const char *,
1420 					  unsigned int, void *, unsigned int);
1421 static int parse_vc_action_mplsoudp_decap(struct context *,
1422 					  const struct token *, const char *,
1423 					  unsigned int, void *, unsigned int);
1424 static int parse_vc_action_raw_encap(struct context *,
1425 				     const struct token *, const char *,
1426 				     unsigned int, void *, unsigned int);
1427 static int parse_vc_action_raw_decap(struct context *,
1428 				     const struct token *, const char *,
1429 				     unsigned int, void *, unsigned int);
1430 static int parse_vc_action_raw_encap_index(struct context *,
1431 					   const struct token *, const char *,
1432 					   unsigned int, void *, unsigned int);
1433 static int parse_vc_action_raw_decap_index(struct context *,
1434 					   const struct token *, const char *,
1435 					   unsigned int, void *, unsigned int);
1436 static int parse_vc_action_set_meta(struct context *ctx,
1437 				    const struct token *token, const char *str,
1438 				    unsigned int len, void *buf,
1439 				    unsigned int size);
1440 static int parse_destroy(struct context *, const struct token *,
1441 			 const char *, unsigned int,
1442 			 void *, unsigned int);
1443 static int parse_flush(struct context *, const struct token *,
1444 		       const char *, unsigned int,
1445 		       void *, unsigned int);
1446 static int parse_dump(struct context *, const struct token *,
1447 		      const char *, unsigned int,
1448 		      void *, unsigned int);
1449 static int parse_query(struct context *, const struct token *,
1450 		       const char *, unsigned int,
1451 		       void *, unsigned int);
1452 static int parse_action(struct context *, const struct token *,
1453 			const char *, unsigned int,
1454 			void *, unsigned int);
1455 static int parse_list(struct context *, const struct token *,
1456 		      const char *, unsigned int,
1457 		      void *, unsigned int);
1458 static int parse_isolate(struct context *, const struct token *,
1459 			 const char *, unsigned int,
1460 			 void *, unsigned int);
1461 static int parse_int(struct context *, const struct token *,
1462 		     const char *, unsigned int,
1463 		     void *, unsigned int);
1464 static int parse_prefix(struct context *, const struct token *,
1465 			const char *, unsigned int,
1466 			void *, unsigned int);
1467 static int parse_boolean(struct context *, const struct token *,
1468 			 const char *, unsigned int,
1469 			 void *, unsigned int);
1470 static int parse_string(struct context *, const struct token *,
1471 			const char *, unsigned int,
1472 			void *, unsigned int);
1473 static int parse_hex(struct context *ctx, const struct token *token,
1474 			const char *str, unsigned int len,
1475 			void *buf, unsigned int size);
1476 static int parse_string0(struct context *, const struct token *,
1477 			const char *, unsigned int,
1478 			void *, unsigned int);
1479 static int parse_mac_addr(struct context *, const struct token *,
1480 			  const char *, unsigned int,
1481 			  void *, unsigned int);
1482 static int parse_ipv4_addr(struct context *, const struct token *,
1483 			   const char *, unsigned int,
1484 			   void *, unsigned int);
1485 static int parse_ipv6_addr(struct context *, const struct token *,
1486 			   const char *, unsigned int,
1487 			   void *, unsigned int);
1488 static int parse_port(struct context *, const struct token *,
1489 		      const char *, unsigned int,
1490 		      void *, unsigned int);
1491 static int comp_none(struct context *, const struct token *,
1492 		     unsigned int, char *, unsigned int);
1493 static int comp_boolean(struct context *, const struct token *,
1494 			unsigned int, char *, unsigned int);
1495 static int comp_action(struct context *, const struct token *,
1496 		       unsigned int, char *, unsigned int);
1497 static int comp_port(struct context *, const struct token *,
1498 		     unsigned int, char *, unsigned int);
1499 static int comp_rule_id(struct context *, const struct token *,
1500 			unsigned int, char *, unsigned int);
1501 static int comp_vc_action_rss_type(struct context *, const struct token *,
1502 				   unsigned int, char *, unsigned int);
1503 static int comp_vc_action_rss_queue(struct context *, const struct token *,
1504 				    unsigned int, char *, unsigned int);
1505 static int comp_set_raw_index(struct context *, const struct token *,
1506 			      unsigned int, char *, unsigned int);
1507 
1508 /** Token definitions. */
1509 static const struct token token_list[] = {
1510 	/* Special tokens. */
1511 	[ZERO] = {
1512 		.name = "ZERO",
1513 		.help = "null entry, abused as the entry point",
1514 		.next = NEXT(NEXT_ENTRY(FLOW)),
1515 	},
1516 	[END] = {
1517 		.name = "",
1518 		.type = "RETURN",
1519 		.help = "command may end here",
1520 	},
1521 	[START_SET] = {
1522 		.name = "START_SET",
1523 		.help = "null entry, abused as the entry point for set",
1524 		.next = NEXT(NEXT_ENTRY(SET)),
1525 	},
1526 	[END_SET] = {
1527 		.name = "end_set",
1528 		.type = "RETURN",
1529 		.help = "set command may end here",
1530 	},
1531 	/* Common tokens. */
1532 	[INTEGER] = {
1533 		.name = "{int}",
1534 		.type = "INTEGER",
1535 		.help = "integer value",
1536 		.call = parse_int,
1537 		.comp = comp_none,
1538 	},
1539 	[UNSIGNED] = {
1540 		.name = "{unsigned}",
1541 		.type = "UNSIGNED",
1542 		.help = "unsigned integer value",
1543 		.call = parse_int,
1544 		.comp = comp_none,
1545 	},
1546 	[PREFIX] = {
1547 		.name = "{prefix}",
1548 		.type = "PREFIX",
1549 		.help = "prefix length for bit-mask",
1550 		.call = parse_prefix,
1551 		.comp = comp_none,
1552 	},
1553 	[BOOLEAN] = {
1554 		.name = "{boolean}",
1555 		.type = "BOOLEAN",
1556 		.help = "any boolean value",
1557 		.call = parse_boolean,
1558 		.comp = comp_boolean,
1559 	},
1560 	[STRING] = {
1561 		.name = "{string}",
1562 		.type = "STRING",
1563 		.help = "fixed string",
1564 		.call = parse_string,
1565 		.comp = comp_none,
1566 	},
1567 	[HEX] = {
1568 		.name = "{hex}",
1569 		.type = "HEX",
1570 		.help = "fixed string",
1571 		.call = parse_hex,
1572 	},
1573 	[FILE_PATH] = {
1574 		.name = "{file path}",
1575 		.type = "STRING",
1576 		.help = "file path",
1577 		.call = parse_string0,
1578 		.comp = comp_none,
1579 	},
1580 	[MAC_ADDR] = {
1581 		.name = "{MAC address}",
1582 		.type = "MAC-48",
1583 		.help = "standard MAC address notation",
1584 		.call = parse_mac_addr,
1585 		.comp = comp_none,
1586 	},
1587 	[IPV4_ADDR] = {
1588 		.name = "{IPv4 address}",
1589 		.type = "IPV4 ADDRESS",
1590 		.help = "standard IPv4 address notation",
1591 		.call = parse_ipv4_addr,
1592 		.comp = comp_none,
1593 	},
1594 	[IPV6_ADDR] = {
1595 		.name = "{IPv6 address}",
1596 		.type = "IPV6 ADDRESS",
1597 		.help = "standard IPv6 address notation",
1598 		.call = parse_ipv6_addr,
1599 		.comp = comp_none,
1600 	},
1601 	[RULE_ID] = {
1602 		.name = "{rule id}",
1603 		.type = "RULE ID",
1604 		.help = "rule identifier",
1605 		.call = parse_int,
1606 		.comp = comp_rule_id,
1607 	},
1608 	[PORT_ID] = {
1609 		.name = "{port_id}",
1610 		.type = "PORT ID",
1611 		.help = "port identifier",
1612 		.call = parse_port,
1613 		.comp = comp_port,
1614 	},
1615 	[GROUP_ID] = {
1616 		.name = "{group_id}",
1617 		.type = "GROUP ID",
1618 		.help = "group identifier",
1619 		.call = parse_int,
1620 		.comp = comp_none,
1621 	},
1622 	[PRIORITY_LEVEL] = {
1623 		.name = "{level}",
1624 		.type = "PRIORITY",
1625 		.help = "priority level",
1626 		.call = parse_int,
1627 		.comp = comp_none,
1628 	},
1629 	/* Top-level command. */
1630 	[FLOW] = {
1631 		.name = "flow",
1632 		.type = "{command} {port_id} [{arg} [...]]",
1633 		.help = "manage ingress/egress flow rules",
1634 		.next = NEXT(NEXT_ENTRY
1635 			     (VALIDATE,
1636 			      CREATE,
1637 			      DESTROY,
1638 			      FLUSH,
1639 			      DUMP,
1640 			      LIST,
1641 			      QUERY,
1642 			      ISOLATE)),
1643 		.call = parse_init,
1644 	},
1645 	/* Sub-level commands. */
1646 	[VALIDATE] = {
1647 		.name = "validate",
1648 		.help = "check whether a flow rule can be created",
1649 		.next = NEXT(next_vc_attr, NEXT_ENTRY(PORT_ID)),
1650 		.args = ARGS(ARGS_ENTRY(struct buffer, port)),
1651 		.call = parse_vc,
1652 	},
1653 	[CREATE] = {
1654 		.name = "create",
1655 		.help = "create a flow rule",
1656 		.next = NEXT(next_vc_attr, NEXT_ENTRY(PORT_ID)),
1657 		.args = ARGS(ARGS_ENTRY(struct buffer, port)),
1658 		.call = parse_vc,
1659 	},
1660 	[DESTROY] = {
1661 		.name = "destroy",
1662 		.help = "destroy specific flow rules",
1663 		.next = NEXT(NEXT_ENTRY(DESTROY_RULE), NEXT_ENTRY(PORT_ID)),
1664 		.args = ARGS(ARGS_ENTRY(struct buffer, port)),
1665 		.call = parse_destroy,
1666 	},
1667 	[FLUSH] = {
1668 		.name = "flush",
1669 		.help = "destroy all flow rules",
1670 		.next = NEXT(NEXT_ENTRY(PORT_ID)),
1671 		.args = ARGS(ARGS_ENTRY(struct buffer, port)),
1672 		.call = parse_flush,
1673 	},
1674 	[DUMP] = {
1675 		.name = "dump",
1676 		.help = "dump all flow rules to file",
1677 		.next = NEXT(next_dump_attr, NEXT_ENTRY(PORT_ID)),
1678 		.args = ARGS(ARGS_ENTRY(struct buffer, args.dump.file),
1679 			     ARGS_ENTRY(struct buffer, port)),
1680 		.call = parse_dump,
1681 	},
1682 	[QUERY] = {
1683 		.name = "query",
1684 		.help = "query an existing flow rule",
1685 		.next = NEXT(NEXT_ENTRY(QUERY_ACTION),
1686 			     NEXT_ENTRY(RULE_ID),
1687 			     NEXT_ENTRY(PORT_ID)),
1688 		.args = ARGS(ARGS_ENTRY(struct buffer, args.query.action.type),
1689 			     ARGS_ENTRY(struct buffer, args.query.rule),
1690 			     ARGS_ENTRY(struct buffer, port)),
1691 		.call = parse_query,
1692 	},
1693 	[LIST] = {
1694 		.name = "list",
1695 		.help = "list existing flow rules",
1696 		.next = NEXT(next_list_attr, NEXT_ENTRY(PORT_ID)),
1697 		.args = ARGS(ARGS_ENTRY(struct buffer, port)),
1698 		.call = parse_list,
1699 	},
1700 	[ISOLATE] = {
1701 		.name = "isolate",
1702 		.help = "restrict ingress traffic to the defined flow rules",
1703 		.next = NEXT(NEXT_ENTRY(BOOLEAN),
1704 			     NEXT_ENTRY(PORT_ID)),
1705 		.args = ARGS(ARGS_ENTRY(struct buffer, args.isolate.set),
1706 			     ARGS_ENTRY(struct buffer, port)),
1707 		.call = parse_isolate,
1708 	},
1709 	/* Destroy arguments. */
1710 	[DESTROY_RULE] = {
1711 		.name = "rule",
1712 		.help = "specify a rule identifier",
1713 		.next = NEXT(next_destroy_attr, NEXT_ENTRY(RULE_ID)),
1714 		.args = ARGS(ARGS_ENTRY_PTR(struct buffer, args.destroy.rule)),
1715 		.call = parse_destroy,
1716 	},
1717 	/* Query arguments. */
1718 	[QUERY_ACTION] = {
1719 		.name = "{action}",
1720 		.type = "ACTION",
1721 		.help = "action to query, must be part of the rule",
1722 		.call = parse_action,
1723 		.comp = comp_action,
1724 	},
1725 	/* List arguments. */
1726 	[LIST_GROUP] = {
1727 		.name = "group",
1728 		.help = "specify a group",
1729 		.next = NEXT(next_list_attr, NEXT_ENTRY(GROUP_ID)),
1730 		.args = ARGS(ARGS_ENTRY_PTR(struct buffer, args.list.group)),
1731 		.call = parse_list,
1732 	},
1733 	/* Validate/create attributes. */
1734 	[GROUP] = {
1735 		.name = "group",
1736 		.help = "specify a group",
1737 		.next = NEXT(next_vc_attr, NEXT_ENTRY(GROUP_ID)),
1738 		.args = ARGS(ARGS_ENTRY(struct rte_flow_attr, group)),
1739 		.call = parse_vc,
1740 	},
1741 	[PRIORITY] = {
1742 		.name = "priority",
1743 		.help = "specify a priority level",
1744 		.next = NEXT(next_vc_attr, NEXT_ENTRY(PRIORITY_LEVEL)),
1745 		.args = ARGS(ARGS_ENTRY(struct rte_flow_attr, priority)),
1746 		.call = parse_vc,
1747 	},
1748 	[INGRESS] = {
1749 		.name = "ingress",
1750 		.help = "affect rule to ingress",
1751 		.next = NEXT(next_vc_attr),
1752 		.call = parse_vc,
1753 	},
1754 	[EGRESS] = {
1755 		.name = "egress",
1756 		.help = "affect rule to egress",
1757 		.next = NEXT(next_vc_attr),
1758 		.call = parse_vc,
1759 	},
1760 	[TRANSFER] = {
1761 		.name = "transfer",
1762 		.help = "apply rule directly to endpoints found in pattern",
1763 		.next = NEXT(next_vc_attr),
1764 		.call = parse_vc,
1765 	},
1766 	/* Validate/create pattern. */
1767 	[PATTERN] = {
1768 		.name = "pattern",
1769 		.help = "submit a list of pattern items",
1770 		.next = NEXT(next_item),
1771 		.call = parse_vc,
1772 	},
1773 	[ITEM_PARAM_IS] = {
1774 		.name = "is",
1775 		.help = "match value perfectly (with full bit-mask)",
1776 		.call = parse_vc_spec,
1777 	},
1778 	[ITEM_PARAM_SPEC] = {
1779 		.name = "spec",
1780 		.help = "match value according to configured bit-mask",
1781 		.call = parse_vc_spec,
1782 	},
1783 	[ITEM_PARAM_LAST] = {
1784 		.name = "last",
1785 		.help = "specify upper bound to establish a range",
1786 		.call = parse_vc_spec,
1787 	},
1788 	[ITEM_PARAM_MASK] = {
1789 		.name = "mask",
1790 		.help = "specify bit-mask with relevant bits set to one",
1791 		.call = parse_vc_spec,
1792 	},
1793 	[ITEM_PARAM_PREFIX] = {
1794 		.name = "prefix",
1795 		.help = "generate bit-mask from a prefix length",
1796 		.call = parse_vc_spec,
1797 	},
1798 	[ITEM_NEXT] = {
1799 		.name = "/",
1800 		.help = "specify next pattern item",
1801 		.next = NEXT(next_item),
1802 	},
1803 	[ITEM_END] = {
1804 		.name = "end",
1805 		.help = "end list of pattern items",
1806 		.priv = PRIV_ITEM(END, 0),
1807 		.next = NEXT(NEXT_ENTRY(ACTIONS)),
1808 		.call = parse_vc,
1809 	},
1810 	[ITEM_VOID] = {
1811 		.name = "void",
1812 		.help = "no-op pattern item",
1813 		.priv = PRIV_ITEM(VOID, 0),
1814 		.next = NEXT(NEXT_ENTRY(ITEM_NEXT)),
1815 		.call = parse_vc,
1816 	},
1817 	[ITEM_INVERT] = {
1818 		.name = "invert",
1819 		.help = "perform actions when pattern does not match",
1820 		.priv = PRIV_ITEM(INVERT, 0),
1821 		.next = NEXT(NEXT_ENTRY(ITEM_NEXT)),
1822 		.call = parse_vc,
1823 	},
1824 	[ITEM_ANY] = {
1825 		.name = "any",
1826 		.help = "match any protocol for the current layer",
1827 		.priv = PRIV_ITEM(ANY, sizeof(struct rte_flow_item_any)),
1828 		.next = NEXT(item_any),
1829 		.call = parse_vc,
1830 	},
1831 	[ITEM_ANY_NUM] = {
1832 		.name = "num",
1833 		.help = "number of layers covered",
1834 		.next = NEXT(item_any, NEXT_ENTRY(UNSIGNED), item_param),
1835 		.args = ARGS(ARGS_ENTRY(struct rte_flow_item_any, num)),
1836 	},
1837 	[ITEM_PF] = {
1838 		.name = "pf",
1839 		.help = "match traffic from/to the physical function",
1840 		.priv = PRIV_ITEM(PF, 0),
1841 		.next = NEXT(NEXT_ENTRY(ITEM_NEXT)),
1842 		.call = parse_vc,
1843 	},
1844 	[ITEM_VF] = {
1845 		.name = "vf",
1846 		.help = "match traffic from/to a virtual function ID",
1847 		.priv = PRIV_ITEM(VF, sizeof(struct rte_flow_item_vf)),
1848 		.next = NEXT(item_vf),
1849 		.call = parse_vc,
1850 	},
1851 	[ITEM_VF_ID] = {
1852 		.name = "id",
1853 		.help = "VF ID",
1854 		.next = NEXT(item_vf, NEXT_ENTRY(UNSIGNED), item_param),
1855 		.args = ARGS(ARGS_ENTRY(struct rte_flow_item_vf, id)),
1856 	},
1857 	[ITEM_PHY_PORT] = {
1858 		.name = "phy_port",
1859 		.help = "match traffic from/to a specific physical port",
1860 		.priv = PRIV_ITEM(PHY_PORT,
1861 				  sizeof(struct rte_flow_item_phy_port)),
1862 		.next = NEXT(item_phy_port),
1863 		.call = parse_vc,
1864 	},
1865 	[ITEM_PHY_PORT_INDEX] = {
1866 		.name = "index",
1867 		.help = "physical port index",
1868 		.next = NEXT(item_phy_port, NEXT_ENTRY(UNSIGNED), item_param),
1869 		.args = ARGS(ARGS_ENTRY(struct rte_flow_item_phy_port, index)),
1870 	},
1871 	[ITEM_PORT_ID] = {
1872 		.name = "port_id",
1873 		.help = "match traffic from/to a given DPDK port ID",
1874 		.priv = PRIV_ITEM(PORT_ID,
1875 				  sizeof(struct rte_flow_item_port_id)),
1876 		.next = NEXT(item_port_id),
1877 		.call = parse_vc,
1878 	},
1879 	[ITEM_PORT_ID_ID] = {
1880 		.name = "id",
1881 		.help = "DPDK port ID",
1882 		.next = NEXT(item_port_id, NEXT_ENTRY(UNSIGNED), item_param),
1883 		.args = ARGS(ARGS_ENTRY(struct rte_flow_item_port_id, id)),
1884 	},
1885 	[ITEM_MARK] = {
1886 		.name = "mark",
1887 		.help = "match traffic against value set in previously matched rule",
1888 		.priv = PRIV_ITEM(MARK, sizeof(struct rte_flow_item_mark)),
1889 		.next = NEXT(item_mark),
1890 		.call = parse_vc,
1891 	},
1892 	[ITEM_MARK_ID] = {
1893 		.name = "id",
1894 		.help = "Integer value to match against",
1895 		.next = NEXT(item_mark, NEXT_ENTRY(UNSIGNED), item_param),
1896 		.args = ARGS(ARGS_ENTRY(struct rte_flow_item_mark, id)),
1897 	},
1898 	[ITEM_RAW] = {
1899 		.name = "raw",
1900 		.help = "match an arbitrary byte string",
1901 		.priv = PRIV_ITEM(RAW, ITEM_RAW_SIZE),
1902 		.next = NEXT(item_raw),
1903 		.call = parse_vc,
1904 	},
1905 	[ITEM_RAW_RELATIVE] = {
1906 		.name = "relative",
1907 		.help = "look for pattern after the previous item",
1908 		.next = NEXT(item_raw, NEXT_ENTRY(BOOLEAN), item_param),
1909 		.args = ARGS(ARGS_ENTRY_BF(struct rte_flow_item_raw,
1910 					   relative, 1)),
1911 	},
1912 	[ITEM_RAW_SEARCH] = {
1913 		.name = "search",
1914 		.help = "search pattern from offset (see also limit)",
1915 		.next = NEXT(item_raw, NEXT_ENTRY(BOOLEAN), item_param),
1916 		.args = ARGS(ARGS_ENTRY_BF(struct rte_flow_item_raw,
1917 					   search, 1)),
1918 	},
1919 	[ITEM_RAW_OFFSET] = {
1920 		.name = "offset",
1921 		.help = "absolute or relative offset for pattern",
1922 		.next = NEXT(item_raw, NEXT_ENTRY(INTEGER), item_param),
1923 		.args = ARGS(ARGS_ENTRY(struct rte_flow_item_raw, offset)),
1924 	},
1925 	[ITEM_RAW_LIMIT] = {
1926 		.name = "limit",
1927 		.help = "search area limit for start of pattern",
1928 		.next = NEXT(item_raw, NEXT_ENTRY(UNSIGNED), item_param),
1929 		.args = ARGS(ARGS_ENTRY(struct rte_flow_item_raw, limit)),
1930 	},
1931 	[ITEM_RAW_PATTERN] = {
1932 		.name = "pattern",
1933 		.help = "byte string to look for",
1934 		.next = NEXT(item_raw,
1935 			     NEXT_ENTRY(STRING),
1936 			     NEXT_ENTRY(ITEM_PARAM_IS,
1937 					ITEM_PARAM_SPEC,
1938 					ITEM_PARAM_MASK)),
1939 		.args = ARGS(ARGS_ENTRY(struct rte_flow_item_raw, pattern),
1940 			     ARGS_ENTRY(struct rte_flow_item_raw, length),
1941 			     ARGS_ENTRY_ARB(sizeof(struct rte_flow_item_raw),
1942 					    ITEM_RAW_PATTERN_SIZE)),
1943 	},
1944 	[ITEM_ETH] = {
1945 		.name = "eth",
1946 		.help = "match Ethernet header",
1947 		.priv = PRIV_ITEM(ETH, sizeof(struct rte_flow_item_eth)),
1948 		.next = NEXT(item_eth),
1949 		.call = parse_vc,
1950 	},
1951 	[ITEM_ETH_DST] = {
1952 		.name = "dst",
1953 		.help = "destination MAC",
1954 		.next = NEXT(item_eth, NEXT_ENTRY(MAC_ADDR), item_param),
1955 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_eth, dst)),
1956 	},
1957 	[ITEM_ETH_SRC] = {
1958 		.name = "src",
1959 		.help = "source MAC",
1960 		.next = NEXT(item_eth, NEXT_ENTRY(MAC_ADDR), item_param),
1961 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_eth, src)),
1962 	},
1963 	[ITEM_ETH_TYPE] = {
1964 		.name = "type",
1965 		.help = "EtherType",
1966 		.next = NEXT(item_eth, NEXT_ENTRY(UNSIGNED), item_param),
1967 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_eth, type)),
1968 	},
1969 	[ITEM_VLAN] = {
1970 		.name = "vlan",
1971 		.help = "match 802.1Q/ad VLAN tag",
1972 		.priv = PRIV_ITEM(VLAN, sizeof(struct rte_flow_item_vlan)),
1973 		.next = NEXT(item_vlan),
1974 		.call = parse_vc,
1975 	},
1976 	[ITEM_VLAN_TCI] = {
1977 		.name = "tci",
1978 		.help = "tag control information",
1979 		.next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1980 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vlan, tci)),
1981 	},
1982 	[ITEM_VLAN_PCP] = {
1983 		.name = "pcp",
1984 		.help = "priority code point",
1985 		.next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1986 		.args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_vlan,
1987 						  tci, "\xe0\x00")),
1988 	},
1989 	[ITEM_VLAN_DEI] = {
1990 		.name = "dei",
1991 		.help = "drop eligible indicator",
1992 		.next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
1993 		.args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_vlan,
1994 						  tci, "\x10\x00")),
1995 	},
1996 	[ITEM_VLAN_VID] = {
1997 		.name = "vid",
1998 		.help = "VLAN identifier",
1999 		.next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
2000 		.args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_vlan,
2001 						  tci, "\x0f\xff")),
2002 	},
2003 	[ITEM_VLAN_INNER_TYPE] = {
2004 		.name = "inner_type",
2005 		.help = "inner EtherType",
2006 		.next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
2007 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vlan,
2008 					     inner_type)),
2009 	},
2010 	[ITEM_IPV4] = {
2011 		.name = "ipv4",
2012 		.help = "match IPv4 header",
2013 		.priv = PRIV_ITEM(IPV4, sizeof(struct rte_flow_item_ipv4)),
2014 		.next = NEXT(item_ipv4),
2015 		.call = parse_vc,
2016 	},
2017 	[ITEM_IPV4_TOS] = {
2018 		.name = "tos",
2019 		.help = "type of service",
2020 		.next = NEXT(item_ipv4, NEXT_ENTRY(UNSIGNED), item_param),
2021 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
2022 					     hdr.type_of_service)),
2023 	},
2024 	[ITEM_IPV4_TTL] = {
2025 		.name = "ttl",
2026 		.help = "time to live",
2027 		.next = NEXT(item_ipv4, NEXT_ENTRY(UNSIGNED), item_param),
2028 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
2029 					     hdr.time_to_live)),
2030 	},
2031 	[ITEM_IPV4_PROTO] = {
2032 		.name = "proto",
2033 		.help = "next protocol ID",
2034 		.next = NEXT(item_ipv4, NEXT_ENTRY(UNSIGNED), item_param),
2035 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
2036 					     hdr.next_proto_id)),
2037 	},
2038 	[ITEM_IPV4_SRC] = {
2039 		.name = "src",
2040 		.help = "source address",
2041 		.next = NEXT(item_ipv4, NEXT_ENTRY(IPV4_ADDR), item_param),
2042 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
2043 					     hdr.src_addr)),
2044 	},
2045 	[ITEM_IPV4_DST] = {
2046 		.name = "dst",
2047 		.help = "destination address",
2048 		.next = NEXT(item_ipv4, NEXT_ENTRY(IPV4_ADDR), item_param),
2049 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
2050 					     hdr.dst_addr)),
2051 	},
2052 	[ITEM_IPV6] = {
2053 		.name = "ipv6",
2054 		.help = "match IPv6 header",
2055 		.priv = PRIV_ITEM(IPV6, sizeof(struct rte_flow_item_ipv6)),
2056 		.next = NEXT(item_ipv6),
2057 		.call = parse_vc,
2058 	},
2059 	[ITEM_IPV6_TC] = {
2060 		.name = "tc",
2061 		.help = "traffic class",
2062 		.next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
2063 		.args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_ipv6,
2064 						  hdr.vtc_flow,
2065 						  "\x0f\xf0\x00\x00")),
2066 	},
2067 	[ITEM_IPV6_FLOW] = {
2068 		.name = "flow",
2069 		.help = "flow label",
2070 		.next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
2071 		.args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_ipv6,
2072 						  hdr.vtc_flow,
2073 						  "\x00\x0f\xff\xff")),
2074 	},
2075 	[ITEM_IPV6_PROTO] = {
2076 		.name = "proto",
2077 		.help = "protocol (next header)",
2078 		.next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
2079 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
2080 					     hdr.proto)),
2081 	},
2082 	[ITEM_IPV6_HOP] = {
2083 		.name = "hop",
2084 		.help = "hop limit",
2085 		.next = NEXT(item_ipv6, NEXT_ENTRY(UNSIGNED), item_param),
2086 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
2087 					     hdr.hop_limits)),
2088 	},
2089 	[ITEM_IPV6_SRC] = {
2090 		.name = "src",
2091 		.help = "source address",
2092 		.next = NEXT(item_ipv6, NEXT_ENTRY(IPV6_ADDR), item_param),
2093 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
2094 					     hdr.src_addr)),
2095 	},
2096 	[ITEM_IPV6_DST] = {
2097 		.name = "dst",
2098 		.help = "destination address",
2099 		.next = NEXT(item_ipv6, NEXT_ENTRY(IPV6_ADDR), item_param),
2100 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
2101 					     hdr.dst_addr)),
2102 	},
2103 	[ITEM_ICMP] = {
2104 		.name = "icmp",
2105 		.help = "match ICMP header",
2106 		.priv = PRIV_ITEM(ICMP, sizeof(struct rte_flow_item_icmp)),
2107 		.next = NEXT(item_icmp),
2108 		.call = parse_vc,
2109 	},
2110 	[ITEM_ICMP_TYPE] = {
2111 		.name = "type",
2112 		.help = "ICMP packet type",
2113 		.next = NEXT(item_icmp, NEXT_ENTRY(UNSIGNED), item_param),
2114 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp,
2115 					     hdr.icmp_type)),
2116 	},
2117 	[ITEM_ICMP_CODE] = {
2118 		.name = "code",
2119 		.help = "ICMP packet code",
2120 		.next = NEXT(item_icmp, NEXT_ENTRY(UNSIGNED), item_param),
2121 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp,
2122 					     hdr.icmp_code)),
2123 	},
2124 	[ITEM_UDP] = {
2125 		.name = "udp",
2126 		.help = "match UDP header",
2127 		.priv = PRIV_ITEM(UDP, sizeof(struct rte_flow_item_udp)),
2128 		.next = NEXT(item_udp),
2129 		.call = parse_vc,
2130 	},
2131 	[ITEM_UDP_SRC] = {
2132 		.name = "src",
2133 		.help = "UDP source port",
2134 		.next = NEXT(item_udp, NEXT_ENTRY(UNSIGNED), item_param),
2135 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_udp,
2136 					     hdr.src_port)),
2137 	},
2138 	[ITEM_UDP_DST] = {
2139 		.name = "dst",
2140 		.help = "UDP destination port",
2141 		.next = NEXT(item_udp, NEXT_ENTRY(UNSIGNED), item_param),
2142 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_udp,
2143 					     hdr.dst_port)),
2144 	},
2145 	[ITEM_TCP] = {
2146 		.name = "tcp",
2147 		.help = "match TCP header",
2148 		.priv = PRIV_ITEM(TCP, sizeof(struct rte_flow_item_tcp)),
2149 		.next = NEXT(item_tcp),
2150 		.call = parse_vc,
2151 	},
2152 	[ITEM_TCP_SRC] = {
2153 		.name = "src",
2154 		.help = "TCP source port",
2155 		.next = NEXT(item_tcp, NEXT_ENTRY(UNSIGNED), item_param),
2156 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_tcp,
2157 					     hdr.src_port)),
2158 	},
2159 	[ITEM_TCP_DST] = {
2160 		.name = "dst",
2161 		.help = "TCP destination port",
2162 		.next = NEXT(item_tcp, NEXT_ENTRY(UNSIGNED), item_param),
2163 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_tcp,
2164 					     hdr.dst_port)),
2165 	},
2166 	[ITEM_TCP_FLAGS] = {
2167 		.name = "flags",
2168 		.help = "TCP flags",
2169 		.next = NEXT(item_tcp, NEXT_ENTRY(UNSIGNED), item_param),
2170 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_tcp,
2171 					     hdr.tcp_flags)),
2172 	},
2173 	[ITEM_SCTP] = {
2174 		.name = "sctp",
2175 		.help = "match SCTP header",
2176 		.priv = PRIV_ITEM(SCTP, sizeof(struct rte_flow_item_sctp)),
2177 		.next = NEXT(item_sctp),
2178 		.call = parse_vc,
2179 	},
2180 	[ITEM_SCTP_SRC] = {
2181 		.name = "src",
2182 		.help = "SCTP source port",
2183 		.next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
2184 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
2185 					     hdr.src_port)),
2186 	},
2187 	[ITEM_SCTP_DST] = {
2188 		.name = "dst",
2189 		.help = "SCTP destination port",
2190 		.next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
2191 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
2192 					     hdr.dst_port)),
2193 	},
2194 	[ITEM_SCTP_TAG] = {
2195 		.name = "tag",
2196 		.help = "validation tag",
2197 		.next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
2198 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
2199 					     hdr.tag)),
2200 	},
2201 	[ITEM_SCTP_CKSUM] = {
2202 		.name = "cksum",
2203 		.help = "checksum",
2204 		.next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
2205 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
2206 					     hdr.cksum)),
2207 	},
2208 	[ITEM_VXLAN] = {
2209 		.name = "vxlan",
2210 		.help = "match VXLAN header",
2211 		.priv = PRIV_ITEM(VXLAN, sizeof(struct rte_flow_item_vxlan)),
2212 		.next = NEXT(item_vxlan),
2213 		.call = parse_vc,
2214 	},
2215 	[ITEM_VXLAN_VNI] = {
2216 		.name = "vni",
2217 		.help = "VXLAN identifier",
2218 		.next = NEXT(item_vxlan, NEXT_ENTRY(UNSIGNED), item_param),
2219 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vxlan, vni)),
2220 	},
2221 	[ITEM_E_TAG] = {
2222 		.name = "e_tag",
2223 		.help = "match E-Tag header",
2224 		.priv = PRIV_ITEM(E_TAG, sizeof(struct rte_flow_item_e_tag)),
2225 		.next = NEXT(item_e_tag),
2226 		.call = parse_vc,
2227 	},
2228 	[ITEM_E_TAG_GRP_ECID_B] = {
2229 		.name = "grp_ecid_b",
2230 		.help = "GRP and E-CID base",
2231 		.next = NEXT(item_e_tag, NEXT_ENTRY(UNSIGNED), item_param),
2232 		.args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_e_tag,
2233 						  rsvd_grp_ecid_b,
2234 						  "\x3f\xff")),
2235 	},
2236 	[ITEM_NVGRE] = {
2237 		.name = "nvgre",
2238 		.help = "match NVGRE header",
2239 		.priv = PRIV_ITEM(NVGRE, sizeof(struct rte_flow_item_nvgre)),
2240 		.next = NEXT(item_nvgre),
2241 		.call = parse_vc,
2242 	},
2243 	[ITEM_NVGRE_TNI] = {
2244 		.name = "tni",
2245 		.help = "virtual subnet ID",
2246 		.next = NEXT(item_nvgre, NEXT_ENTRY(UNSIGNED), item_param),
2247 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_nvgre, tni)),
2248 	},
2249 	[ITEM_MPLS] = {
2250 		.name = "mpls",
2251 		.help = "match MPLS header",
2252 		.priv = PRIV_ITEM(MPLS, sizeof(struct rte_flow_item_mpls)),
2253 		.next = NEXT(item_mpls),
2254 		.call = parse_vc,
2255 	},
2256 	[ITEM_MPLS_LABEL] = {
2257 		.name = "label",
2258 		.help = "MPLS label",
2259 		.next = NEXT(item_mpls, NEXT_ENTRY(UNSIGNED), item_param),
2260 		.args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_mpls,
2261 						  label_tc_s,
2262 						  "\xff\xff\xf0")),
2263 	},
2264 	[ITEM_MPLS_TC] = {
2265 		.name = "tc",
2266 		.help = "MPLS Traffic Class",
2267 		.next = NEXT(item_mpls, NEXT_ENTRY(UNSIGNED), item_param),
2268 		.args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_mpls,
2269 						  label_tc_s,
2270 						  "\x00\x00\x0e")),
2271 	},
2272 	[ITEM_MPLS_S] = {
2273 		.name = "s",
2274 		.help = "MPLS Bottom-of-Stack",
2275 		.next = NEXT(item_mpls, NEXT_ENTRY(UNSIGNED), item_param),
2276 		.args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_mpls,
2277 						  label_tc_s,
2278 						  "\x00\x00\x01")),
2279 	},
2280 	[ITEM_GRE] = {
2281 		.name = "gre",
2282 		.help = "match GRE header",
2283 		.priv = PRIV_ITEM(GRE, sizeof(struct rte_flow_item_gre)),
2284 		.next = NEXT(item_gre),
2285 		.call = parse_vc,
2286 	},
2287 	[ITEM_GRE_PROTO] = {
2288 		.name = "protocol",
2289 		.help = "GRE protocol type",
2290 		.next = NEXT(item_gre, NEXT_ENTRY(UNSIGNED), item_param),
2291 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gre,
2292 					     protocol)),
2293 	},
2294 	[ITEM_GRE_C_RSVD0_VER] = {
2295 		.name = "c_rsvd0_ver",
2296 		.help =
2297 			"checksum (1b), undefined (1b), key bit (1b),"
2298 			" sequence number (1b), reserved 0 (9b),"
2299 			" version (3b)",
2300 		.next = NEXT(item_gre, NEXT_ENTRY(UNSIGNED), item_param),
2301 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gre,
2302 					     c_rsvd0_ver)),
2303 	},
2304 	[ITEM_GRE_C_BIT] = {
2305 		.name = "c_bit",
2306 		.help = "checksum bit (C)",
2307 		.next = NEXT(item_gre, NEXT_ENTRY(BOOLEAN), item_param),
2308 		.args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_gre,
2309 						  c_rsvd0_ver,
2310 						  "\x80\x00\x00\x00")),
2311 	},
2312 	[ITEM_GRE_S_BIT] = {
2313 		.name = "s_bit",
2314 		.help = "sequence number bit (S)",
2315 		.next = NEXT(item_gre, NEXT_ENTRY(BOOLEAN), item_param),
2316 		.args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_gre,
2317 						  c_rsvd0_ver,
2318 						  "\x10\x00\x00\x00")),
2319 	},
2320 	[ITEM_GRE_K_BIT] = {
2321 		.name = "k_bit",
2322 		.help = "key bit (K)",
2323 		.next = NEXT(item_gre, NEXT_ENTRY(BOOLEAN), item_param),
2324 		.args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_gre,
2325 						  c_rsvd0_ver,
2326 						  "\x20\x00\x00\x00")),
2327 	},
2328 	[ITEM_FUZZY] = {
2329 		.name = "fuzzy",
2330 		.help = "fuzzy pattern match, expect faster than default",
2331 		.priv = PRIV_ITEM(FUZZY,
2332 				sizeof(struct rte_flow_item_fuzzy)),
2333 		.next = NEXT(item_fuzzy),
2334 		.call = parse_vc,
2335 	},
2336 	[ITEM_FUZZY_THRESH] = {
2337 		.name = "thresh",
2338 		.help = "match accuracy threshold",
2339 		.next = NEXT(item_fuzzy, NEXT_ENTRY(UNSIGNED), item_param),
2340 		.args = ARGS(ARGS_ENTRY(struct rte_flow_item_fuzzy,
2341 					thresh)),
2342 	},
2343 	[ITEM_GTP] = {
2344 		.name = "gtp",
2345 		.help = "match GTP header",
2346 		.priv = PRIV_ITEM(GTP, sizeof(struct rte_flow_item_gtp)),
2347 		.next = NEXT(item_gtp),
2348 		.call = parse_vc,
2349 	},
2350 	[ITEM_GTP_MSG_TYPE] = {
2351 		.name = "msg_type",
2352 		.help = "GTP message type",
2353 		.next = NEXT(item_gtp, NEXT_ENTRY(UNSIGNED), item_param),
2354 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gtp,
2355 					     msg_type)),
2356 	},
2357 	[ITEM_GTP_TEID] = {
2358 		.name = "teid",
2359 		.help = "tunnel endpoint identifier",
2360 		.next = NEXT(item_gtp, NEXT_ENTRY(UNSIGNED), item_param),
2361 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gtp, teid)),
2362 	},
2363 	[ITEM_GTPC] = {
2364 		.name = "gtpc",
2365 		.help = "match GTP header",
2366 		.priv = PRIV_ITEM(GTPC, sizeof(struct rte_flow_item_gtp)),
2367 		.next = NEXT(item_gtp),
2368 		.call = parse_vc,
2369 	},
2370 	[ITEM_GTPU] = {
2371 		.name = "gtpu",
2372 		.help = "match GTP header",
2373 		.priv = PRIV_ITEM(GTPU, sizeof(struct rte_flow_item_gtp)),
2374 		.next = NEXT(item_gtp),
2375 		.call = parse_vc,
2376 	},
2377 	[ITEM_GENEVE] = {
2378 		.name = "geneve",
2379 		.help = "match GENEVE header",
2380 		.priv = PRIV_ITEM(GENEVE, sizeof(struct rte_flow_item_geneve)),
2381 		.next = NEXT(item_geneve),
2382 		.call = parse_vc,
2383 	},
2384 	[ITEM_GENEVE_VNI] = {
2385 		.name = "vni",
2386 		.help = "virtual network identifier",
2387 		.next = NEXT(item_geneve, NEXT_ENTRY(UNSIGNED), item_param),
2388 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_geneve, vni)),
2389 	},
2390 	[ITEM_GENEVE_PROTO] = {
2391 		.name = "protocol",
2392 		.help = "GENEVE protocol type",
2393 		.next = NEXT(item_geneve, NEXT_ENTRY(UNSIGNED), item_param),
2394 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_geneve,
2395 					     protocol)),
2396 	},
2397 	[ITEM_VXLAN_GPE] = {
2398 		.name = "vxlan-gpe",
2399 		.help = "match VXLAN-GPE header",
2400 		.priv = PRIV_ITEM(VXLAN_GPE,
2401 				  sizeof(struct rte_flow_item_vxlan_gpe)),
2402 		.next = NEXT(item_vxlan_gpe),
2403 		.call = parse_vc,
2404 	},
2405 	[ITEM_VXLAN_GPE_VNI] = {
2406 		.name = "vni",
2407 		.help = "VXLAN-GPE identifier",
2408 		.next = NEXT(item_vxlan_gpe, NEXT_ENTRY(UNSIGNED), item_param),
2409 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vxlan_gpe,
2410 					     vni)),
2411 	},
2412 	[ITEM_ARP_ETH_IPV4] = {
2413 		.name = "arp_eth_ipv4",
2414 		.help = "match ARP header for Ethernet/IPv4",
2415 		.priv = PRIV_ITEM(ARP_ETH_IPV4,
2416 				  sizeof(struct rte_flow_item_arp_eth_ipv4)),
2417 		.next = NEXT(item_arp_eth_ipv4),
2418 		.call = parse_vc,
2419 	},
2420 	[ITEM_ARP_ETH_IPV4_SHA] = {
2421 		.name = "sha",
2422 		.help = "sender hardware address",
2423 		.next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(MAC_ADDR),
2424 			     item_param),
2425 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
2426 					     sha)),
2427 	},
2428 	[ITEM_ARP_ETH_IPV4_SPA] = {
2429 		.name = "spa",
2430 		.help = "sender IPv4 address",
2431 		.next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(IPV4_ADDR),
2432 			     item_param),
2433 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
2434 					     spa)),
2435 	},
2436 	[ITEM_ARP_ETH_IPV4_THA] = {
2437 		.name = "tha",
2438 		.help = "target hardware address",
2439 		.next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(MAC_ADDR),
2440 			     item_param),
2441 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
2442 					     tha)),
2443 	},
2444 	[ITEM_ARP_ETH_IPV4_TPA] = {
2445 		.name = "tpa",
2446 		.help = "target IPv4 address",
2447 		.next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(IPV4_ADDR),
2448 			     item_param),
2449 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
2450 					     tpa)),
2451 	},
2452 	[ITEM_IPV6_EXT] = {
2453 		.name = "ipv6_ext",
2454 		.help = "match presence of any IPv6 extension header",
2455 		.priv = PRIV_ITEM(IPV6_EXT,
2456 				  sizeof(struct rte_flow_item_ipv6_ext)),
2457 		.next = NEXT(item_ipv6_ext),
2458 		.call = parse_vc,
2459 	},
2460 	[ITEM_IPV6_EXT_NEXT_HDR] = {
2461 		.name = "next_hdr",
2462 		.help = "next header",
2463 		.next = NEXT(item_ipv6_ext, NEXT_ENTRY(UNSIGNED), item_param),
2464 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6_ext,
2465 					     next_hdr)),
2466 	},
2467 	[ITEM_ICMP6] = {
2468 		.name = "icmp6",
2469 		.help = "match any ICMPv6 header",
2470 		.priv = PRIV_ITEM(ICMP6, sizeof(struct rte_flow_item_icmp6)),
2471 		.next = NEXT(item_icmp6),
2472 		.call = parse_vc,
2473 	},
2474 	[ITEM_ICMP6_TYPE] = {
2475 		.name = "type",
2476 		.help = "ICMPv6 type",
2477 		.next = NEXT(item_icmp6, NEXT_ENTRY(UNSIGNED), item_param),
2478 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6,
2479 					     type)),
2480 	},
2481 	[ITEM_ICMP6_CODE] = {
2482 		.name = "code",
2483 		.help = "ICMPv6 code",
2484 		.next = NEXT(item_icmp6, NEXT_ENTRY(UNSIGNED), item_param),
2485 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6,
2486 					     code)),
2487 	},
2488 	[ITEM_ICMP6_ND_NS] = {
2489 		.name = "icmp6_nd_ns",
2490 		.help = "match ICMPv6 neighbor discovery solicitation",
2491 		.priv = PRIV_ITEM(ICMP6_ND_NS,
2492 				  sizeof(struct rte_flow_item_icmp6_nd_ns)),
2493 		.next = NEXT(item_icmp6_nd_ns),
2494 		.call = parse_vc,
2495 	},
2496 	[ITEM_ICMP6_ND_NS_TARGET_ADDR] = {
2497 		.name = "target_addr",
2498 		.help = "target address",
2499 		.next = NEXT(item_icmp6_nd_ns, NEXT_ENTRY(IPV6_ADDR),
2500 			     item_param),
2501 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6_nd_ns,
2502 					     target_addr)),
2503 	},
2504 	[ITEM_ICMP6_ND_NA] = {
2505 		.name = "icmp6_nd_na",
2506 		.help = "match ICMPv6 neighbor discovery advertisement",
2507 		.priv = PRIV_ITEM(ICMP6_ND_NA,
2508 				  sizeof(struct rte_flow_item_icmp6_nd_na)),
2509 		.next = NEXT(item_icmp6_nd_na),
2510 		.call = parse_vc,
2511 	},
2512 	[ITEM_ICMP6_ND_NA_TARGET_ADDR] = {
2513 		.name = "target_addr",
2514 		.help = "target address",
2515 		.next = NEXT(item_icmp6_nd_na, NEXT_ENTRY(IPV6_ADDR),
2516 			     item_param),
2517 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6_nd_na,
2518 					     target_addr)),
2519 	},
2520 	[ITEM_ICMP6_ND_OPT] = {
2521 		.name = "icmp6_nd_opt",
2522 		.help = "match presence of any ICMPv6 neighbor discovery"
2523 			" option",
2524 		.priv = PRIV_ITEM(ICMP6_ND_OPT,
2525 				  sizeof(struct rte_flow_item_icmp6_nd_opt)),
2526 		.next = NEXT(item_icmp6_nd_opt),
2527 		.call = parse_vc,
2528 	},
2529 	[ITEM_ICMP6_ND_OPT_TYPE] = {
2530 		.name = "type",
2531 		.help = "ND option type",
2532 		.next = NEXT(item_icmp6_nd_opt, NEXT_ENTRY(UNSIGNED),
2533 			     item_param),
2534 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6_nd_opt,
2535 					     type)),
2536 	},
2537 	[ITEM_ICMP6_ND_OPT_SLA_ETH] = {
2538 		.name = "icmp6_nd_opt_sla_eth",
2539 		.help = "match ICMPv6 neighbor discovery source Ethernet"
2540 			" link-layer address option",
2541 		.priv = PRIV_ITEM
2542 			(ICMP6_ND_OPT_SLA_ETH,
2543 			 sizeof(struct rte_flow_item_icmp6_nd_opt_sla_eth)),
2544 		.next = NEXT(item_icmp6_nd_opt_sla_eth),
2545 		.call = parse_vc,
2546 	},
2547 	[ITEM_ICMP6_ND_OPT_SLA_ETH_SLA] = {
2548 		.name = "sla",
2549 		.help = "source Ethernet LLA",
2550 		.next = NEXT(item_icmp6_nd_opt_sla_eth, NEXT_ENTRY(MAC_ADDR),
2551 			     item_param),
2552 		.args = ARGS(ARGS_ENTRY_HTON
2553 			     (struct rte_flow_item_icmp6_nd_opt_sla_eth, sla)),
2554 	},
2555 	[ITEM_ICMP6_ND_OPT_TLA_ETH] = {
2556 		.name = "icmp6_nd_opt_tla_eth",
2557 		.help = "match ICMPv6 neighbor discovery target Ethernet"
2558 			" link-layer address option",
2559 		.priv = PRIV_ITEM
2560 			(ICMP6_ND_OPT_TLA_ETH,
2561 			 sizeof(struct rte_flow_item_icmp6_nd_opt_tla_eth)),
2562 		.next = NEXT(item_icmp6_nd_opt_tla_eth),
2563 		.call = parse_vc,
2564 	},
2565 	[ITEM_ICMP6_ND_OPT_TLA_ETH_TLA] = {
2566 		.name = "tla",
2567 		.help = "target Ethernet LLA",
2568 		.next = NEXT(item_icmp6_nd_opt_tla_eth, NEXT_ENTRY(MAC_ADDR),
2569 			     item_param),
2570 		.args = ARGS(ARGS_ENTRY_HTON
2571 			     (struct rte_flow_item_icmp6_nd_opt_tla_eth, tla)),
2572 	},
2573 	[ITEM_META] = {
2574 		.name = "meta",
2575 		.help = "match metadata header",
2576 		.priv = PRIV_ITEM(META, sizeof(struct rte_flow_item_meta)),
2577 		.next = NEXT(item_meta),
2578 		.call = parse_vc,
2579 	},
2580 	[ITEM_META_DATA] = {
2581 		.name = "data",
2582 		.help = "metadata value",
2583 		.next = NEXT(item_meta, NEXT_ENTRY(UNSIGNED), item_param),
2584 		.args = ARGS(ARGS_ENTRY_MASK(struct rte_flow_item_meta,
2585 					     data, "\xff\xff\xff\xff")),
2586 	},
2587 	[ITEM_GRE_KEY] = {
2588 		.name = "gre_key",
2589 		.help = "match GRE key",
2590 		.priv = PRIV_ITEM(GRE_KEY, sizeof(rte_be32_t)),
2591 		.next = NEXT(item_gre_key),
2592 		.call = parse_vc,
2593 	},
2594 	[ITEM_GRE_KEY_VALUE] = {
2595 		.name = "value",
2596 		.help = "key value",
2597 		.next = NEXT(item_gre_key, NEXT_ENTRY(UNSIGNED), item_param),
2598 		.args = ARGS(ARG_ENTRY_HTON(rte_be32_t)),
2599 	},
2600 	[ITEM_GTP_PSC] = {
2601 		.name = "gtp_psc",
2602 		.help = "match GTP extension header with type 0x85",
2603 		.priv = PRIV_ITEM(GTP_PSC,
2604 				sizeof(struct rte_flow_item_gtp_psc)),
2605 		.next = NEXT(item_gtp_psc),
2606 		.call = parse_vc,
2607 	},
2608 	[ITEM_GTP_PSC_QFI] = {
2609 		.name = "qfi",
2610 		.help = "QoS flow identifier",
2611 		.next = NEXT(item_gtp_psc, NEXT_ENTRY(UNSIGNED), item_param),
2612 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gtp_psc,
2613 					qfi)),
2614 	},
2615 	[ITEM_GTP_PSC_PDU_T] = {
2616 		.name = "pdu_t",
2617 		.help = "PDU type",
2618 		.next = NEXT(item_gtp_psc, NEXT_ENTRY(UNSIGNED), item_param),
2619 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gtp_psc,
2620 					pdu_type)),
2621 	},
2622 	[ITEM_PPPOES] = {
2623 		.name = "pppoes",
2624 		.help = "match PPPoE session header",
2625 		.priv = PRIV_ITEM(PPPOES, sizeof(struct rte_flow_item_pppoe)),
2626 		.next = NEXT(item_pppoes),
2627 		.call = parse_vc,
2628 	},
2629 	[ITEM_PPPOED] = {
2630 		.name = "pppoed",
2631 		.help = "match PPPoE discovery header",
2632 		.priv = PRIV_ITEM(PPPOED, sizeof(struct rte_flow_item_pppoe)),
2633 		.next = NEXT(item_pppoed),
2634 		.call = parse_vc,
2635 	},
2636 	[ITEM_PPPOE_SEID] = {
2637 		.name = "seid",
2638 		.help = "session identifier",
2639 		.next = NEXT(item_pppoes, NEXT_ENTRY(UNSIGNED), item_param),
2640 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_pppoe,
2641 					session_id)),
2642 	},
2643 	[ITEM_PPPOE_PROTO_ID] = {
2644 		.name = "proto_id",
2645 		.help = "match PPPoE session protocol identifier",
2646 		.priv = PRIV_ITEM(PPPOE_PROTO_ID,
2647 				sizeof(struct rte_flow_item_pppoe_proto_id)),
2648 		.next = NEXT(item_pppoe_proto_id),
2649 		.call = parse_vc,
2650 	},
2651 	[ITEM_HIGIG2] = {
2652 		.name = "higig2",
2653 		.help = "matches higig2 header",
2654 		.priv = PRIV_ITEM(HIGIG2,
2655 				sizeof(struct rte_flow_item_higig2_hdr)),
2656 		.next = NEXT(item_higig2),
2657 		.call = parse_vc,
2658 	},
2659 	[ITEM_HIGIG2_CLASSIFICATION] = {
2660 		.name = "classification",
2661 		.help = "matches classification of higig2 header",
2662 		.next = NEXT(item_higig2, NEXT_ENTRY(UNSIGNED), item_param),
2663 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_higig2_hdr,
2664 					hdr.ppt1.classification)),
2665 	},
2666 	[ITEM_HIGIG2_VID] = {
2667 		.name = "vid",
2668 		.help = "matches vid of higig2 header",
2669 		.next = NEXT(item_higig2, NEXT_ENTRY(UNSIGNED), item_param),
2670 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_higig2_hdr,
2671 					hdr.ppt1.vid)),
2672 	},
2673 	[ITEM_TAG] = {
2674 		.name = "tag",
2675 		.help = "match tag value",
2676 		.priv = PRIV_ITEM(TAG, sizeof(struct rte_flow_item_tag)),
2677 		.next = NEXT(item_tag),
2678 		.call = parse_vc,
2679 	},
2680 	[ITEM_TAG_DATA] = {
2681 		.name = "data",
2682 		.help = "tag value to match",
2683 		.next = NEXT(item_tag, NEXT_ENTRY(UNSIGNED), item_param),
2684 		.args = ARGS(ARGS_ENTRY(struct rte_flow_item_tag, data)),
2685 	},
2686 	[ITEM_TAG_INDEX] = {
2687 		.name = "index",
2688 		.help = "index of tag array to match",
2689 		.next = NEXT(item_tag, NEXT_ENTRY(UNSIGNED),
2690 			     NEXT_ENTRY(ITEM_PARAM_IS)),
2691 		.args = ARGS(ARGS_ENTRY(struct rte_flow_item_tag, index)),
2692 	},
2693 	[ITEM_L2TPV3OIP] = {
2694 		.name = "l2tpv3oip",
2695 		.help = "match L2TPv3 over IP header",
2696 		.priv = PRIV_ITEM(L2TPV3OIP,
2697 				  sizeof(struct rte_flow_item_l2tpv3oip)),
2698 		.next = NEXT(item_l2tpv3oip),
2699 		.call = parse_vc,
2700 	},
2701 	[ITEM_L2TPV3OIP_SESSION_ID] = {
2702 		.name = "session_id",
2703 		.help = "session identifier",
2704 		.next = NEXT(item_l2tpv3oip, NEXT_ENTRY(UNSIGNED), item_param),
2705 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_l2tpv3oip,
2706 					     session_id)),
2707 	},
2708 	[ITEM_ESP] = {
2709 		.name = "esp",
2710 		.help = "match ESP header",
2711 		.priv = PRIV_ITEM(ESP, sizeof(struct rte_flow_item_esp)),
2712 		.next = NEXT(item_esp),
2713 		.call = parse_vc,
2714 	},
2715 	[ITEM_ESP_SPI] = {
2716 		.name = "spi",
2717 		.help = "security policy index",
2718 		.next = NEXT(item_esp, NEXT_ENTRY(UNSIGNED), item_param),
2719 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_esp,
2720 				hdr.spi)),
2721 	},
2722 	[ITEM_AH] = {
2723 		.name = "ah",
2724 		.help = "match AH header",
2725 		.priv = PRIV_ITEM(AH, sizeof(struct rte_flow_item_ah)),
2726 		.next = NEXT(item_ah),
2727 		.call = parse_vc,
2728 	},
2729 	[ITEM_AH_SPI] = {
2730 		.name = "spi",
2731 		.help = "security parameters index",
2732 		.next = NEXT(item_ah, NEXT_ENTRY(UNSIGNED), item_param),
2733 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ah, spi)),
2734 	},
2735 	[ITEM_PFCP] = {
2736 		.name = "pfcp",
2737 		.help = "match pfcp header",
2738 		.priv = PRIV_ITEM(PFCP, sizeof(struct rte_flow_item_pfcp)),
2739 		.next = NEXT(item_pfcp),
2740 		.call = parse_vc,
2741 	},
2742 	[ITEM_PFCP_S_FIELD] = {
2743 		.name = "s_field",
2744 		.help = "S field",
2745 		.next = NEXT(item_pfcp, NEXT_ENTRY(UNSIGNED), item_param),
2746 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_pfcp,
2747 				s_field)),
2748 	},
2749 	[ITEM_PFCP_SEID] = {
2750 		.name = "seid",
2751 		.help = "session endpoint identifier",
2752 		.next = NEXT(item_pfcp, NEXT_ENTRY(UNSIGNED), item_param),
2753 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_pfcp, seid)),
2754 	},
2755 	/* Validate/create actions. */
2756 	[ACTIONS] = {
2757 		.name = "actions",
2758 		.help = "submit a list of associated actions",
2759 		.next = NEXT(next_action),
2760 		.call = parse_vc,
2761 	},
2762 	[ACTION_NEXT] = {
2763 		.name = "/",
2764 		.help = "specify next action",
2765 		.next = NEXT(next_action),
2766 	},
2767 	[ACTION_END] = {
2768 		.name = "end",
2769 		.help = "end list of actions",
2770 		.priv = PRIV_ACTION(END, 0),
2771 		.call = parse_vc,
2772 	},
2773 	[ACTION_VOID] = {
2774 		.name = "void",
2775 		.help = "no-op action",
2776 		.priv = PRIV_ACTION(VOID, 0),
2777 		.next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2778 		.call = parse_vc,
2779 	},
2780 	[ACTION_PASSTHRU] = {
2781 		.name = "passthru",
2782 		.help = "let subsequent rule process matched packets",
2783 		.priv = PRIV_ACTION(PASSTHRU, 0),
2784 		.next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2785 		.call = parse_vc,
2786 	},
2787 	[ACTION_JUMP] = {
2788 		.name = "jump",
2789 		.help = "redirect traffic to a given group",
2790 		.priv = PRIV_ACTION(JUMP, sizeof(struct rte_flow_action_jump)),
2791 		.next = NEXT(action_jump),
2792 		.call = parse_vc,
2793 	},
2794 	[ACTION_JUMP_GROUP] = {
2795 		.name = "group",
2796 		.help = "group to redirect traffic to",
2797 		.next = NEXT(action_jump, NEXT_ENTRY(UNSIGNED)),
2798 		.args = ARGS(ARGS_ENTRY(struct rte_flow_action_jump, group)),
2799 		.call = parse_vc_conf,
2800 	},
2801 	[ACTION_MARK] = {
2802 		.name = "mark",
2803 		.help = "attach 32 bit value to packets",
2804 		.priv = PRIV_ACTION(MARK, sizeof(struct rte_flow_action_mark)),
2805 		.next = NEXT(action_mark),
2806 		.call = parse_vc,
2807 	},
2808 	[ACTION_MARK_ID] = {
2809 		.name = "id",
2810 		.help = "32 bit value to return with packets",
2811 		.next = NEXT(action_mark, NEXT_ENTRY(UNSIGNED)),
2812 		.args = ARGS(ARGS_ENTRY(struct rte_flow_action_mark, id)),
2813 		.call = parse_vc_conf,
2814 	},
2815 	[ACTION_FLAG] = {
2816 		.name = "flag",
2817 		.help = "flag packets",
2818 		.priv = PRIV_ACTION(FLAG, 0),
2819 		.next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2820 		.call = parse_vc,
2821 	},
2822 	[ACTION_QUEUE] = {
2823 		.name = "queue",
2824 		.help = "assign packets to a given queue index",
2825 		.priv = PRIV_ACTION(QUEUE,
2826 				    sizeof(struct rte_flow_action_queue)),
2827 		.next = NEXT(action_queue),
2828 		.call = parse_vc,
2829 	},
2830 	[ACTION_QUEUE_INDEX] = {
2831 		.name = "index",
2832 		.help = "queue index to use",
2833 		.next = NEXT(action_queue, NEXT_ENTRY(UNSIGNED)),
2834 		.args = ARGS(ARGS_ENTRY(struct rte_flow_action_queue, index)),
2835 		.call = parse_vc_conf,
2836 	},
2837 	[ACTION_DROP] = {
2838 		.name = "drop",
2839 		.help = "drop packets (note: passthru has priority)",
2840 		.priv = PRIV_ACTION(DROP, 0),
2841 		.next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2842 		.call = parse_vc,
2843 	},
2844 	[ACTION_COUNT] = {
2845 		.name = "count",
2846 		.help = "enable counters for this rule",
2847 		.priv = PRIV_ACTION(COUNT,
2848 				    sizeof(struct rte_flow_action_count)),
2849 		.next = NEXT(action_count),
2850 		.call = parse_vc,
2851 	},
2852 	[ACTION_COUNT_ID] = {
2853 		.name = "identifier",
2854 		.help = "counter identifier to use",
2855 		.next = NEXT(action_count, NEXT_ENTRY(UNSIGNED)),
2856 		.args = ARGS(ARGS_ENTRY(struct rte_flow_action_count, id)),
2857 		.call = parse_vc_conf,
2858 	},
2859 	[ACTION_COUNT_SHARED] = {
2860 		.name = "shared",
2861 		.help = "shared counter",
2862 		.next = NEXT(action_count, NEXT_ENTRY(BOOLEAN)),
2863 		.args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_count,
2864 					   shared, 1)),
2865 		.call = parse_vc_conf,
2866 	},
2867 	[ACTION_RSS] = {
2868 		.name = "rss",
2869 		.help = "spread packets among several queues",
2870 		.priv = PRIV_ACTION(RSS, sizeof(struct action_rss_data)),
2871 		.next = NEXT(action_rss),
2872 		.call = parse_vc_action_rss,
2873 	},
2874 	[ACTION_RSS_FUNC] = {
2875 		.name = "func",
2876 		.help = "RSS hash function to apply",
2877 		.next = NEXT(action_rss,
2878 			     NEXT_ENTRY(ACTION_RSS_FUNC_DEFAULT,
2879 					ACTION_RSS_FUNC_TOEPLITZ,
2880 					ACTION_RSS_FUNC_SIMPLE_XOR,
2881 					ACTION_RSS_FUNC_SYMMETRIC_TOEPLITZ)),
2882 	},
2883 	[ACTION_RSS_FUNC_DEFAULT] = {
2884 		.name = "default",
2885 		.help = "default hash function",
2886 		.call = parse_vc_action_rss_func,
2887 	},
2888 	[ACTION_RSS_FUNC_TOEPLITZ] = {
2889 		.name = "toeplitz",
2890 		.help = "Toeplitz hash function",
2891 		.call = parse_vc_action_rss_func,
2892 	},
2893 	[ACTION_RSS_FUNC_SIMPLE_XOR] = {
2894 		.name = "simple_xor",
2895 		.help = "simple XOR hash function",
2896 		.call = parse_vc_action_rss_func,
2897 	},
2898 	[ACTION_RSS_FUNC_SYMMETRIC_TOEPLITZ] = {
2899 		.name = "symmetric_toeplitz",
2900 		.help = "Symmetric Toeplitz hash function",
2901 		.call = parse_vc_action_rss_func,
2902 	},
2903 	[ACTION_RSS_LEVEL] = {
2904 		.name = "level",
2905 		.help = "encapsulation level for \"types\"",
2906 		.next = NEXT(action_rss, NEXT_ENTRY(UNSIGNED)),
2907 		.args = ARGS(ARGS_ENTRY_ARB
2908 			     (offsetof(struct action_rss_data, conf) +
2909 			      offsetof(struct rte_flow_action_rss, level),
2910 			      sizeof(((struct rte_flow_action_rss *)0)->
2911 				     level))),
2912 	},
2913 	[ACTION_RSS_TYPES] = {
2914 		.name = "types",
2915 		.help = "specific RSS hash types",
2916 		.next = NEXT(action_rss, NEXT_ENTRY(ACTION_RSS_TYPE)),
2917 	},
2918 	[ACTION_RSS_TYPE] = {
2919 		.name = "{type}",
2920 		.help = "RSS hash type",
2921 		.call = parse_vc_action_rss_type,
2922 		.comp = comp_vc_action_rss_type,
2923 	},
2924 	[ACTION_RSS_KEY] = {
2925 		.name = "key",
2926 		.help = "RSS hash key",
2927 		.next = NEXT(action_rss, NEXT_ENTRY(HEX)),
2928 		.args = ARGS(ARGS_ENTRY_ARB(0, 0),
2929 			     ARGS_ENTRY_ARB
2930 			     (offsetof(struct action_rss_data, conf) +
2931 			      offsetof(struct rte_flow_action_rss, key_len),
2932 			      sizeof(((struct rte_flow_action_rss *)0)->
2933 				     key_len)),
2934 			     ARGS_ENTRY(struct action_rss_data, key)),
2935 	},
2936 	[ACTION_RSS_KEY_LEN] = {
2937 		.name = "key_len",
2938 		.help = "RSS hash key length in bytes",
2939 		.next = NEXT(action_rss, NEXT_ENTRY(UNSIGNED)),
2940 		.args = ARGS(ARGS_ENTRY_ARB_BOUNDED
2941 			     (offsetof(struct action_rss_data, conf) +
2942 			      offsetof(struct rte_flow_action_rss, key_len),
2943 			      sizeof(((struct rte_flow_action_rss *)0)->
2944 				     key_len),
2945 			      0,
2946 			      RSS_HASH_KEY_LENGTH)),
2947 	},
2948 	[ACTION_RSS_QUEUES] = {
2949 		.name = "queues",
2950 		.help = "queue indices to use",
2951 		.next = NEXT(action_rss, NEXT_ENTRY(ACTION_RSS_QUEUE)),
2952 		.call = parse_vc_conf,
2953 	},
2954 	[ACTION_RSS_QUEUE] = {
2955 		.name = "{queue}",
2956 		.help = "queue index",
2957 		.call = parse_vc_action_rss_queue,
2958 		.comp = comp_vc_action_rss_queue,
2959 	},
2960 	[ACTION_PF] = {
2961 		.name = "pf",
2962 		.help = "direct traffic to physical function",
2963 		.priv = PRIV_ACTION(PF, 0),
2964 		.next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
2965 		.call = parse_vc,
2966 	},
2967 	[ACTION_VF] = {
2968 		.name = "vf",
2969 		.help = "direct traffic to a virtual function ID",
2970 		.priv = PRIV_ACTION(VF, sizeof(struct rte_flow_action_vf)),
2971 		.next = NEXT(action_vf),
2972 		.call = parse_vc,
2973 	},
2974 	[ACTION_VF_ORIGINAL] = {
2975 		.name = "original",
2976 		.help = "use original VF ID if possible",
2977 		.next = NEXT(action_vf, NEXT_ENTRY(BOOLEAN)),
2978 		.args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_vf,
2979 					   original, 1)),
2980 		.call = parse_vc_conf,
2981 	},
2982 	[ACTION_VF_ID] = {
2983 		.name = "id",
2984 		.help = "VF ID",
2985 		.next = NEXT(action_vf, NEXT_ENTRY(UNSIGNED)),
2986 		.args = ARGS(ARGS_ENTRY(struct rte_flow_action_vf, id)),
2987 		.call = parse_vc_conf,
2988 	},
2989 	[ACTION_PHY_PORT] = {
2990 		.name = "phy_port",
2991 		.help = "direct packets to physical port index",
2992 		.priv = PRIV_ACTION(PHY_PORT,
2993 				    sizeof(struct rte_flow_action_phy_port)),
2994 		.next = NEXT(action_phy_port),
2995 		.call = parse_vc,
2996 	},
2997 	[ACTION_PHY_PORT_ORIGINAL] = {
2998 		.name = "original",
2999 		.help = "use original port index if possible",
3000 		.next = NEXT(action_phy_port, NEXT_ENTRY(BOOLEAN)),
3001 		.args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_phy_port,
3002 					   original, 1)),
3003 		.call = parse_vc_conf,
3004 	},
3005 	[ACTION_PHY_PORT_INDEX] = {
3006 		.name = "index",
3007 		.help = "physical port index",
3008 		.next = NEXT(action_phy_port, NEXT_ENTRY(UNSIGNED)),
3009 		.args = ARGS(ARGS_ENTRY(struct rte_flow_action_phy_port,
3010 					index)),
3011 		.call = parse_vc_conf,
3012 	},
3013 	[ACTION_PORT_ID] = {
3014 		.name = "port_id",
3015 		.help = "direct matching traffic to a given DPDK port ID",
3016 		.priv = PRIV_ACTION(PORT_ID,
3017 				    sizeof(struct rte_flow_action_port_id)),
3018 		.next = NEXT(action_port_id),
3019 		.call = parse_vc,
3020 	},
3021 	[ACTION_PORT_ID_ORIGINAL] = {
3022 		.name = "original",
3023 		.help = "use original DPDK port ID if possible",
3024 		.next = NEXT(action_port_id, NEXT_ENTRY(BOOLEAN)),
3025 		.args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_port_id,
3026 					   original, 1)),
3027 		.call = parse_vc_conf,
3028 	},
3029 	[ACTION_PORT_ID_ID] = {
3030 		.name = "id",
3031 		.help = "DPDK port ID",
3032 		.next = NEXT(action_port_id, NEXT_ENTRY(UNSIGNED)),
3033 		.args = ARGS(ARGS_ENTRY(struct rte_flow_action_port_id, id)),
3034 		.call = parse_vc_conf,
3035 	},
3036 	[ACTION_METER] = {
3037 		.name = "meter",
3038 		.help = "meter the directed packets at given id",
3039 		.priv = PRIV_ACTION(METER,
3040 				    sizeof(struct rte_flow_action_meter)),
3041 		.next = NEXT(action_meter),
3042 		.call = parse_vc,
3043 	},
3044 	[ACTION_METER_ID] = {
3045 		.name = "mtr_id",
3046 		.help = "meter id to use",
3047 		.next = NEXT(action_meter, NEXT_ENTRY(UNSIGNED)),
3048 		.args = ARGS(ARGS_ENTRY(struct rte_flow_action_meter, mtr_id)),
3049 		.call = parse_vc_conf,
3050 	},
3051 	[ACTION_OF_SET_MPLS_TTL] = {
3052 		.name = "of_set_mpls_ttl",
3053 		.help = "OpenFlow's OFPAT_SET_MPLS_TTL",
3054 		.priv = PRIV_ACTION
3055 			(OF_SET_MPLS_TTL,
3056 			 sizeof(struct rte_flow_action_of_set_mpls_ttl)),
3057 		.next = NEXT(action_of_set_mpls_ttl),
3058 		.call = parse_vc,
3059 	},
3060 	[ACTION_OF_SET_MPLS_TTL_MPLS_TTL] = {
3061 		.name = "mpls_ttl",
3062 		.help = "MPLS TTL",
3063 		.next = NEXT(action_of_set_mpls_ttl, NEXT_ENTRY(UNSIGNED)),
3064 		.args = ARGS(ARGS_ENTRY(struct rte_flow_action_of_set_mpls_ttl,
3065 					mpls_ttl)),
3066 		.call = parse_vc_conf,
3067 	},
3068 	[ACTION_OF_DEC_MPLS_TTL] = {
3069 		.name = "of_dec_mpls_ttl",
3070 		.help = "OpenFlow's OFPAT_DEC_MPLS_TTL",
3071 		.priv = PRIV_ACTION(OF_DEC_MPLS_TTL, 0),
3072 		.next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3073 		.call = parse_vc,
3074 	},
3075 	[ACTION_OF_SET_NW_TTL] = {
3076 		.name = "of_set_nw_ttl",
3077 		.help = "OpenFlow's OFPAT_SET_NW_TTL",
3078 		.priv = PRIV_ACTION
3079 			(OF_SET_NW_TTL,
3080 			 sizeof(struct rte_flow_action_of_set_nw_ttl)),
3081 		.next = NEXT(action_of_set_nw_ttl),
3082 		.call = parse_vc,
3083 	},
3084 	[ACTION_OF_SET_NW_TTL_NW_TTL] = {
3085 		.name = "nw_ttl",
3086 		.help = "IP TTL",
3087 		.next = NEXT(action_of_set_nw_ttl, NEXT_ENTRY(UNSIGNED)),
3088 		.args = ARGS(ARGS_ENTRY(struct rte_flow_action_of_set_nw_ttl,
3089 					nw_ttl)),
3090 		.call = parse_vc_conf,
3091 	},
3092 	[ACTION_OF_DEC_NW_TTL] = {
3093 		.name = "of_dec_nw_ttl",
3094 		.help = "OpenFlow's OFPAT_DEC_NW_TTL",
3095 		.priv = PRIV_ACTION(OF_DEC_NW_TTL, 0),
3096 		.next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3097 		.call = parse_vc,
3098 	},
3099 	[ACTION_OF_COPY_TTL_OUT] = {
3100 		.name = "of_copy_ttl_out",
3101 		.help = "OpenFlow's OFPAT_COPY_TTL_OUT",
3102 		.priv = PRIV_ACTION(OF_COPY_TTL_OUT, 0),
3103 		.next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3104 		.call = parse_vc,
3105 	},
3106 	[ACTION_OF_COPY_TTL_IN] = {
3107 		.name = "of_copy_ttl_in",
3108 		.help = "OpenFlow's OFPAT_COPY_TTL_IN",
3109 		.priv = PRIV_ACTION(OF_COPY_TTL_IN, 0),
3110 		.next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3111 		.call = parse_vc,
3112 	},
3113 	[ACTION_OF_POP_VLAN] = {
3114 		.name = "of_pop_vlan",
3115 		.help = "OpenFlow's OFPAT_POP_VLAN",
3116 		.priv = PRIV_ACTION(OF_POP_VLAN, 0),
3117 		.next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3118 		.call = parse_vc,
3119 	},
3120 	[ACTION_OF_PUSH_VLAN] = {
3121 		.name = "of_push_vlan",
3122 		.help = "OpenFlow's OFPAT_PUSH_VLAN",
3123 		.priv = PRIV_ACTION
3124 			(OF_PUSH_VLAN,
3125 			 sizeof(struct rte_flow_action_of_push_vlan)),
3126 		.next = NEXT(action_of_push_vlan),
3127 		.call = parse_vc,
3128 	},
3129 	[ACTION_OF_PUSH_VLAN_ETHERTYPE] = {
3130 		.name = "ethertype",
3131 		.help = "EtherType",
3132 		.next = NEXT(action_of_push_vlan, NEXT_ENTRY(UNSIGNED)),
3133 		.args = ARGS(ARGS_ENTRY_HTON
3134 			     (struct rte_flow_action_of_push_vlan,
3135 			      ethertype)),
3136 		.call = parse_vc_conf,
3137 	},
3138 	[ACTION_OF_SET_VLAN_VID] = {
3139 		.name = "of_set_vlan_vid",
3140 		.help = "OpenFlow's OFPAT_SET_VLAN_VID",
3141 		.priv = PRIV_ACTION
3142 			(OF_SET_VLAN_VID,
3143 			 sizeof(struct rte_flow_action_of_set_vlan_vid)),
3144 		.next = NEXT(action_of_set_vlan_vid),
3145 		.call = parse_vc,
3146 	},
3147 	[ACTION_OF_SET_VLAN_VID_VLAN_VID] = {
3148 		.name = "vlan_vid",
3149 		.help = "VLAN id",
3150 		.next = NEXT(action_of_set_vlan_vid, NEXT_ENTRY(UNSIGNED)),
3151 		.args = ARGS(ARGS_ENTRY_HTON
3152 			     (struct rte_flow_action_of_set_vlan_vid,
3153 			      vlan_vid)),
3154 		.call = parse_vc_conf,
3155 	},
3156 	[ACTION_OF_SET_VLAN_PCP] = {
3157 		.name = "of_set_vlan_pcp",
3158 		.help = "OpenFlow's OFPAT_SET_VLAN_PCP",
3159 		.priv = PRIV_ACTION
3160 			(OF_SET_VLAN_PCP,
3161 			 sizeof(struct rte_flow_action_of_set_vlan_pcp)),
3162 		.next = NEXT(action_of_set_vlan_pcp),
3163 		.call = parse_vc,
3164 	},
3165 	[ACTION_OF_SET_VLAN_PCP_VLAN_PCP] = {
3166 		.name = "vlan_pcp",
3167 		.help = "VLAN priority",
3168 		.next = NEXT(action_of_set_vlan_pcp, NEXT_ENTRY(UNSIGNED)),
3169 		.args = ARGS(ARGS_ENTRY_HTON
3170 			     (struct rte_flow_action_of_set_vlan_pcp,
3171 			      vlan_pcp)),
3172 		.call = parse_vc_conf,
3173 	},
3174 	[ACTION_OF_POP_MPLS] = {
3175 		.name = "of_pop_mpls",
3176 		.help = "OpenFlow's OFPAT_POP_MPLS",
3177 		.priv = PRIV_ACTION(OF_POP_MPLS,
3178 				    sizeof(struct rte_flow_action_of_pop_mpls)),
3179 		.next = NEXT(action_of_pop_mpls),
3180 		.call = parse_vc,
3181 	},
3182 	[ACTION_OF_POP_MPLS_ETHERTYPE] = {
3183 		.name = "ethertype",
3184 		.help = "EtherType",
3185 		.next = NEXT(action_of_pop_mpls, NEXT_ENTRY(UNSIGNED)),
3186 		.args = ARGS(ARGS_ENTRY_HTON
3187 			     (struct rte_flow_action_of_pop_mpls,
3188 			      ethertype)),
3189 		.call = parse_vc_conf,
3190 	},
3191 	[ACTION_OF_PUSH_MPLS] = {
3192 		.name = "of_push_mpls",
3193 		.help = "OpenFlow's OFPAT_PUSH_MPLS",
3194 		.priv = PRIV_ACTION
3195 			(OF_PUSH_MPLS,
3196 			 sizeof(struct rte_flow_action_of_push_mpls)),
3197 		.next = NEXT(action_of_push_mpls),
3198 		.call = parse_vc,
3199 	},
3200 	[ACTION_OF_PUSH_MPLS_ETHERTYPE] = {
3201 		.name = "ethertype",
3202 		.help = "EtherType",
3203 		.next = NEXT(action_of_push_mpls, NEXT_ENTRY(UNSIGNED)),
3204 		.args = ARGS(ARGS_ENTRY_HTON
3205 			     (struct rte_flow_action_of_push_mpls,
3206 			      ethertype)),
3207 		.call = parse_vc_conf,
3208 	},
3209 	[ACTION_VXLAN_ENCAP] = {
3210 		.name = "vxlan_encap",
3211 		.help = "VXLAN encapsulation, uses configuration set by \"set"
3212 			" vxlan\"",
3213 		.priv = PRIV_ACTION(VXLAN_ENCAP,
3214 				    sizeof(struct action_vxlan_encap_data)),
3215 		.next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3216 		.call = parse_vc_action_vxlan_encap,
3217 	},
3218 	[ACTION_VXLAN_DECAP] = {
3219 		.name = "vxlan_decap",
3220 		.help = "Performs a decapsulation action by stripping all"
3221 			" headers of the VXLAN tunnel network overlay from the"
3222 			" matched flow.",
3223 		.priv = PRIV_ACTION(VXLAN_DECAP, 0),
3224 		.next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3225 		.call = parse_vc,
3226 	},
3227 	[ACTION_NVGRE_ENCAP] = {
3228 		.name = "nvgre_encap",
3229 		.help = "NVGRE encapsulation, uses configuration set by \"set"
3230 			" nvgre\"",
3231 		.priv = PRIV_ACTION(NVGRE_ENCAP,
3232 				    sizeof(struct action_nvgre_encap_data)),
3233 		.next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3234 		.call = parse_vc_action_nvgre_encap,
3235 	},
3236 	[ACTION_NVGRE_DECAP] = {
3237 		.name = "nvgre_decap",
3238 		.help = "Performs a decapsulation action by stripping all"
3239 			" headers of the NVGRE tunnel network overlay from the"
3240 			" matched flow.",
3241 		.priv = PRIV_ACTION(NVGRE_DECAP, 0),
3242 		.next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3243 		.call = parse_vc,
3244 	},
3245 	[ACTION_L2_ENCAP] = {
3246 		.name = "l2_encap",
3247 		.help = "l2 encap, uses configuration set by"
3248 			" \"set l2_encap\"",
3249 		.priv = PRIV_ACTION(RAW_ENCAP,
3250 				    sizeof(struct action_raw_encap_data)),
3251 		.next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3252 		.call = parse_vc_action_l2_encap,
3253 	},
3254 	[ACTION_L2_DECAP] = {
3255 		.name = "l2_decap",
3256 		.help = "l2 decap, uses configuration set by"
3257 			" \"set l2_decap\"",
3258 		.priv = PRIV_ACTION(RAW_DECAP,
3259 				    sizeof(struct action_raw_decap_data)),
3260 		.next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3261 		.call = parse_vc_action_l2_decap,
3262 	},
3263 	[ACTION_MPLSOGRE_ENCAP] = {
3264 		.name = "mplsogre_encap",
3265 		.help = "mplsogre encapsulation, uses configuration set by"
3266 			" \"set mplsogre_encap\"",
3267 		.priv = PRIV_ACTION(RAW_ENCAP,
3268 				    sizeof(struct action_raw_encap_data)),
3269 		.next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3270 		.call = parse_vc_action_mplsogre_encap,
3271 	},
3272 	[ACTION_MPLSOGRE_DECAP] = {
3273 		.name = "mplsogre_decap",
3274 		.help = "mplsogre decapsulation, uses configuration set by"
3275 			" \"set mplsogre_decap\"",
3276 		.priv = PRIV_ACTION(RAW_DECAP,
3277 				    sizeof(struct action_raw_decap_data)),
3278 		.next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3279 		.call = parse_vc_action_mplsogre_decap,
3280 	},
3281 	[ACTION_MPLSOUDP_ENCAP] = {
3282 		.name = "mplsoudp_encap",
3283 		.help = "mplsoudp encapsulation, uses configuration set by"
3284 			" \"set mplsoudp_encap\"",
3285 		.priv = PRIV_ACTION(RAW_ENCAP,
3286 				    sizeof(struct action_raw_encap_data)),
3287 		.next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3288 		.call = parse_vc_action_mplsoudp_encap,
3289 	},
3290 	[ACTION_MPLSOUDP_DECAP] = {
3291 		.name = "mplsoudp_decap",
3292 		.help = "mplsoudp decapsulation, uses configuration set by"
3293 			" \"set mplsoudp_decap\"",
3294 		.priv = PRIV_ACTION(RAW_DECAP,
3295 				    sizeof(struct action_raw_decap_data)),
3296 		.next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3297 		.call = parse_vc_action_mplsoudp_decap,
3298 	},
3299 	[ACTION_SET_IPV4_SRC] = {
3300 		.name = "set_ipv4_src",
3301 		.help = "Set a new IPv4 source address in the outermost"
3302 			" IPv4 header",
3303 		.priv = PRIV_ACTION(SET_IPV4_SRC,
3304 			sizeof(struct rte_flow_action_set_ipv4)),
3305 		.next = NEXT(action_set_ipv4_src),
3306 		.call = parse_vc,
3307 	},
3308 	[ACTION_SET_IPV4_SRC_IPV4_SRC] = {
3309 		.name = "ipv4_addr",
3310 		.help = "new IPv4 source address to set",
3311 		.next = NEXT(action_set_ipv4_src, NEXT_ENTRY(IPV4_ADDR)),
3312 		.args = ARGS(ARGS_ENTRY_HTON
3313 			(struct rte_flow_action_set_ipv4, ipv4_addr)),
3314 		.call = parse_vc_conf,
3315 	},
3316 	[ACTION_SET_IPV4_DST] = {
3317 		.name = "set_ipv4_dst",
3318 		.help = "Set a new IPv4 destination address in the outermost"
3319 			" IPv4 header",
3320 		.priv = PRIV_ACTION(SET_IPV4_DST,
3321 			sizeof(struct rte_flow_action_set_ipv4)),
3322 		.next = NEXT(action_set_ipv4_dst),
3323 		.call = parse_vc,
3324 	},
3325 	[ACTION_SET_IPV4_DST_IPV4_DST] = {
3326 		.name = "ipv4_addr",
3327 		.help = "new IPv4 destination address to set",
3328 		.next = NEXT(action_set_ipv4_dst, NEXT_ENTRY(IPV4_ADDR)),
3329 		.args = ARGS(ARGS_ENTRY_HTON
3330 			(struct rte_flow_action_set_ipv4, ipv4_addr)),
3331 		.call = parse_vc_conf,
3332 	},
3333 	[ACTION_SET_IPV6_SRC] = {
3334 		.name = "set_ipv6_src",
3335 		.help = "Set a new IPv6 source address in the outermost"
3336 			" IPv6 header",
3337 		.priv = PRIV_ACTION(SET_IPV6_SRC,
3338 			sizeof(struct rte_flow_action_set_ipv6)),
3339 		.next = NEXT(action_set_ipv6_src),
3340 		.call = parse_vc,
3341 	},
3342 	[ACTION_SET_IPV6_SRC_IPV6_SRC] = {
3343 		.name = "ipv6_addr",
3344 		.help = "new IPv6 source address to set",
3345 		.next = NEXT(action_set_ipv6_src, NEXT_ENTRY(IPV6_ADDR)),
3346 		.args = ARGS(ARGS_ENTRY_HTON
3347 			(struct rte_flow_action_set_ipv6, ipv6_addr)),
3348 		.call = parse_vc_conf,
3349 	},
3350 	[ACTION_SET_IPV6_DST] = {
3351 		.name = "set_ipv6_dst",
3352 		.help = "Set a new IPv6 destination address in the outermost"
3353 			" IPv6 header",
3354 		.priv = PRIV_ACTION(SET_IPV6_DST,
3355 			sizeof(struct rte_flow_action_set_ipv6)),
3356 		.next = NEXT(action_set_ipv6_dst),
3357 		.call = parse_vc,
3358 	},
3359 	[ACTION_SET_IPV6_DST_IPV6_DST] = {
3360 		.name = "ipv6_addr",
3361 		.help = "new IPv6 destination address to set",
3362 		.next = NEXT(action_set_ipv6_dst, NEXT_ENTRY(IPV6_ADDR)),
3363 		.args = ARGS(ARGS_ENTRY_HTON
3364 			(struct rte_flow_action_set_ipv6, ipv6_addr)),
3365 		.call = parse_vc_conf,
3366 	},
3367 	[ACTION_SET_TP_SRC] = {
3368 		.name = "set_tp_src",
3369 		.help = "set a new source port number in the outermost"
3370 			" TCP/UDP header",
3371 		.priv = PRIV_ACTION(SET_TP_SRC,
3372 			sizeof(struct rte_flow_action_set_tp)),
3373 		.next = NEXT(action_set_tp_src),
3374 		.call = parse_vc,
3375 	},
3376 	[ACTION_SET_TP_SRC_TP_SRC] = {
3377 		.name = "port",
3378 		.help = "new source port number to set",
3379 		.next = NEXT(action_set_tp_src, NEXT_ENTRY(UNSIGNED)),
3380 		.args = ARGS(ARGS_ENTRY_HTON
3381 			     (struct rte_flow_action_set_tp, port)),
3382 		.call = parse_vc_conf,
3383 	},
3384 	[ACTION_SET_TP_DST] = {
3385 		.name = "set_tp_dst",
3386 		.help = "set a new destination port number in the outermost"
3387 			" TCP/UDP header",
3388 		.priv = PRIV_ACTION(SET_TP_DST,
3389 			sizeof(struct rte_flow_action_set_tp)),
3390 		.next = NEXT(action_set_tp_dst),
3391 		.call = parse_vc,
3392 	},
3393 	[ACTION_SET_TP_DST_TP_DST] = {
3394 		.name = "port",
3395 		.help = "new destination port number to set",
3396 		.next = NEXT(action_set_tp_dst, NEXT_ENTRY(UNSIGNED)),
3397 		.args = ARGS(ARGS_ENTRY_HTON
3398 			     (struct rte_flow_action_set_tp, port)),
3399 		.call = parse_vc_conf,
3400 	},
3401 	[ACTION_MAC_SWAP] = {
3402 		.name = "mac_swap",
3403 		.help = "Swap the source and destination MAC addresses"
3404 			" in the outermost Ethernet header",
3405 		.priv = PRIV_ACTION(MAC_SWAP, 0),
3406 		.next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3407 		.call = parse_vc,
3408 	},
3409 	[ACTION_DEC_TTL] = {
3410 		.name = "dec_ttl",
3411 		.help = "decrease network TTL if available",
3412 		.priv = PRIV_ACTION(DEC_TTL, 0),
3413 		.next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3414 		.call = parse_vc,
3415 	},
3416 	[ACTION_SET_TTL] = {
3417 		.name = "set_ttl",
3418 		.help = "set ttl value",
3419 		.priv = PRIV_ACTION(SET_TTL,
3420 			sizeof(struct rte_flow_action_set_ttl)),
3421 		.next = NEXT(action_set_ttl),
3422 		.call = parse_vc,
3423 	},
3424 	[ACTION_SET_TTL_TTL] = {
3425 		.name = "ttl_value",
3426 		.help = "new ttl value to set",
3427 		.next = NEXT(action_set_ttl, NEXT_ENTRY(UNSIGNED)),
3428 		.args = ARGS(ARGS_ENTRY_HTON
3429 			     (struct rte_flow_action_set_ttl, ttl_value)),
3430 		.call = parse_vc_conf,
3431 	},
3432 	[ACTION_SET_MAC_SRC] = {
3433 		.name = "set_mac_src",
3434 		.help = "set source mac address",
3435 		.priv = PRIV_ACTION(SET_MAC_SRC,
3436 			sizeof(struct rte_flow_action_set_mac)),
3437 		.next = NEXT(action_set_mac_src),
3438 		.call = parse_vc,
3439 	},
3440 	[ACTION_SET_MAC_SRC_MAC_SRC] = {
3441 		.name = "mac_addr",
3442 		.help = "new source mac address",
3443 		.next = NEXT(action_set_mac_src, NEXT_ENTRY(MAC_ADDR)),
3444 		.args = ARGS(ARGS_ENTRY_HTON
3445 			     (struct rte_flow_action_set_mac, mac_addr)),
3446 		.call = parse_vc_conf,
3447 	},
3448 	[ACTION_SET_MAC_DST] = {
3449 		.name = "set_mac_dst",
3450 		.help = "set destination mac address",
3451 		.priv = PRIV_ACTION(SET_MAC_DST,
3452 			sizeof(struct rte_flow_action_set_mac)),
3453 		.next = NEXT(action_set_mac_dst),
3454 		.call = parse_vc,
3455 	},
3456 	[ACTION_SET_MAC_DST_MAC_DST] = {
3457 		.name = "mac_addr",
3458 		.help = "new destination mac address to set",
3459 		.next = NEXT(action_set_mac_dst, NEXT_ENTRY(MAC_ADDR)),
3460 		.args = ARGS(ARGS_ENTRY_HTON
3461 			     (struct rte_flow_action_set_mac, mac_addr)),
3462 		.call = parse_vc_conf,
3463 	},
3464 	[ACTION_INC_TCP_SEQ] = {
3465 		.name = "inc_tcp_seq",
3466 		.help = "increase TCP sequence number",
3467 		.priv = PRIV_ACTION(INC_TCP_SEQ, sizeof(rte_be32_t)),
3468 		.next = NEXT(action_inc_tcp_seq),
3469 		.call = parse_vc,
3470 	},
3471 	[ACTION_INC_TCP_SEQ_VALUE] = {
3472 		.name = "value",
3473 		.help = "the value to increase TCP sequence number by",
3474 		.next = NEXT(action_inc_tcp_seq, NEXT_ENTRY(UNSIGNED)),
3475 		.args = ARGS(ARG_ENTRY_HTON(rte_be32_t)),
3476 		.call = parse_vc_conf,
3477 	},
3478 	[ACTION_DEC_TCP_SEQ] = {
3479 		.name = "dec_tcp_seq",
3480 		.help = "decrease TCP sequence number",
3481 		.priv = PRIV_ACTION(DEC_TCP_SEQ, sizeof(rte_be32_t)),
3482 		.next = NEXT(action_dec_tcp_seq),
3483 		.call = parse_vc,
3484 	},
3485 	[ACTION_DEC_TCP_SEQ_VALUE] = {
3486 		.name = "value",
3487 		.help = "the value to decrease TCP sequence number by",
3488 		.next = NEXT(action_dec_tcp_seq, NEXT_ENTRY(UNSIGNED)),
3489 		.args = ARGS(ARG_ENTRY_HTON(rte_be32_t)),
3490 		.call = parse_vc_conf,
3491 	},
3492 	[ACTION_INC_TCP_ACK] = {
3493 		.name = "inc_tcp_ack",
3494 		.help = "increase TCP acknowledgment number",
3495 		.priv = PRIV_ACTION(INC_TCP_ACK, sizeof(rte_be32_t)),
3496 		.next = NEXT(action_inc_tcp_ack),
3497 		.call = parse_vc,
3498 	},
3499 	[ACTION_INC_TCP_ACK_VALUE] = {
3500 		.name = "value",
3501 		.help = "the value to increase TCP acknowledgment number by",
3502 		.next = NEXT(action_inc_tcp_ack, NEXT_ENTRY(UNSIGNED)),
3503 		.args = ARGS(ARG_ENTRY_HTON(rte_be32_t)),
3504 		.call = parse_vc_conf,
3505 	},
3506 	[ACTION_DEC_TCP_ACK] = {
3507 		.name = "dec_tcp_ack",
3508 		.help = "decrease TCP acknowledgment number",
3509 		.priv = PRIV_ACTION(DEC_TCP_ACK, sizeof(rte_be32_t)),
3510 		.next = NEXT(action_dec_tcp_ack),
3511 		.call = parse_vc,
3512 	},
3513 	[ACTION_DEC_TCP_ACK_VALUE] = {
3514 		.name = "value",
3515 		.help = "the value to decrease TCP acknowledgment number by",
3516 		.next = NEXT(action_dec_tcp_ack, NEXT_ENTRY(UNSIGNED)),
3517 		.args = ARGS(ARG_ENTRY_HTON(rte_be32_t)),
3518 		.call = parse_vc_conf,
3519 	},
3520 	[ACTION_RAW_ENCAP] = {
3521 		.name = "raw_encap",
3522 		.help = "encapsulation data, defined by set raw_encap",
3523 		.priv = PRIV_ACTION(RAW_ENCAP,
3524 			sizeof(struct action_raw_encap_data)),
3525 		.next = NEXT(action_raw_encap),
3526 		.call = parse_vc_action_raw_encap,
3527 	},
3528 	[ACTION_RAW_ENCAP_INDEX] = {
3529 		.name = "index",
3530 		.help = "the index of raw_encap_confs",
3531 		.next = NEXT(NEXT_ENTRY(ACTION_RAW_ENCAP_INDEX_VALUE)),
3532 	},
3533 	[ACTION_RAW_ENCAP_INDEX_VALUE] = {
3534 		.name = "{index}",
3535 		.type = "UNSIGNED",
3536 		.help = "unsigned integer value",
3537 		.next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3538 		.call = parse_vc_action_raw_encap_index,
3539 		.comp = comp_set_raw_index,
3540 	},
3541 	[ACTION_RAW_DECAP] = {
3542 		.name = "raw_decap",
3543 		.help = "decapsulation data, defined by set raw_encap",
3544 		.priv = PRIV_ACTION(RAW_DECAP,
3545 			sizeof(struct action_raw_decap_data)),
3546 		.next = NEXT(action_raw_decap),
3547 		.call = parse_vc_action_raw_decap,
3548 	},
3549 	[ACTION_RAW_DECAP_INDEX] = {
3550 		.name = "index",
3551 		.help = "the index of raw_encap_confs",
3552 		.next = NEXT(NEXT_ENTRY(ACTION_RAW_DECAP_INDEX_VALUE)),
3553 	},
3554 	[ACTION_RAW_DECAP_INDEX_VALUE] = {
3555 		.name = "{index}",
3556 		.type = "UNSIGNED",
3557 		.help = "unsigned integer value",
3558 		.next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
3559 		.call = parse_vc_action_raw_decap_index,
3560 		.comp = comp_set_raw_index,
3561 	},
3562 	/* Top level command. */
3563 	[SET] = {
3564 		.name = "set",
3565 		.help = "set raw encap/decap data",
3566 		.type = "set raw_encap|raw_decap <index> <pattern>",
3567 		.next = NEXT(NEXT_ENTRY
3568 			     (SET_RAW_ENCAP,
3569 			      SET_RAW_DECAP)),
3570 		.call = parse_set_init,
3571 	},
3572 	/* Sub-level commands. */
3573 	[SET_RAW_ENCAP] = {
3574 		.name = "raw_encap",
3575 		.help = "set raw encap data",
3576 		.next = NEXT(next_set_raw),
3577 		.args = ARGS(ARGS_ENTRY_ARB_BOUNDED
3578 				(offsetof(struct buffer, port),
3579 				 sizeof(((struct buffer *)0)->port),
3580 				 0, RAW_ENCAP_CONFS_MAX_NUM - 1)),
3581 		.call = parse_set_raw_encap_decap,
3582 	},
3583 	[SET_RAW_DECAP] = {
3584 		.name = "raw_decap",
3585 		.help = "set raw decap data",
3586 		.next = NEXT(next_set_raw),
3587 		.args = ARGS(ARGS_ENTRY_ARB_BOUNDED
3588 				(offsetof(struct buffer, port),
3589 				 sizeof(((struct buffer *)0)->port),
3590 				 0, RAW_ENCAP_CONFS_MAX_NUM - 1)),
3591 		.call = parse_set_raw_encap_decap,
3592 	},
3593 	[SET_RAW_INDEX] = {
3594 		.name = "{index}",
3595 		.type = "UNSIGNED",
3596 		.help = "index of raw_encap/raw_decap data",
3597 		.next = NEXT(next_item),
3598 		.call = parse_port,
3599 	},
3600 	[ACTION_SET_TAG] = {
3601 		.name = "set_tag",
3602 		.help = "set tag",
3603 		.priv = PRIV_ACTION(SET_TAG,
3604 			sizeof(struct rte_flow_action_set_tag)),
3605 		.next = NEXT(action_set_tag),
3606 		.call = parse_vc,
3607 	},
3608 	[ACTION_SET_TAG_INDEX] = {
3609 		.name = "index",
3610 		.help = "index of tag array",
3611 		.next = NEXT(action_set_tag, NEXT_ENTRY(UNSIGNED)),
3612 		.args = ARGS(ARGS_ENTRY(struct rte_flow_action_set_tag, index)),
3613 		.call = parse_vc_conf,
3614 	},
3615 	[ACTION_SET_TAG_DATA] = {
3616 		.name = "data",
3617 		.help = "tag value",
3618 		.next = NEXT(action_set_tag, NEXT_ENTRY(UNSIGNED)),
3619 		.args = ARGS(ARGS_ENTRY
3620 			     (struct rte_flow_action_set_tag, data)),
3621 		.call = parse_vc_conf,
3622 	},
3623 	[ACTION_SET_TAG_MASK] = {
3624 		.name = "mask",
3625 		.help = "mask for tag value",
3626 		.next = NEXT(action_set_tag, NEXT_ENTRY(UNSIGNED)),
3627 		.args = ARGS(ARGS_ENTRY
3628 			     (struct rte_flow_action_set_tag, mask)),
3629 		.call = parse_vc_conf,
3630 	},
3631 	[ACTION_SET_META] = {
3632 		.name = "set_meta",
3633 		.help = "set metadata",
3634 		.priv = PRIV_ACTION(SET_META,
3635 			sizeof(struct rte_flow_action_set_meta)),
3636 		.next = NEXT(action_set_meta),
3637 		.call = parse_vc_action_set_meta,
3638 	},
3639 	[ACTION_SET_META_DATA] = {
3640 		.name = "data",
3641 		.help = "metadata value",
3642 		.next = NEXT(action_set_meta, NEXT_ENTRY(UNSIGNED)),
3643 		.args = ARGS(ARGS_ENTRY
3644 			     (struct rte_flow_action_set_meta, data)),
3645 		.call = parse_vc_conf,
3646 	},
3647 	[ACTION_SET_META_MASK] = {
3648 		.name = "mask",
3649 		.help = "mask for metadata value",
3650 		.next = NEXT(action_set_meta, NEXT_ENTRY(UNSIGNED)),
3651 		.args = ARGS(ARGS_ENTRY
3652 			     (struct rte_flow_action_set_meta, mask)),
3653 		.call = parse_vc_conf,
3654 	},
3655 	[ACTION_SET_IPV4_DSCP] = {
3656 		.name = "set_ipv4_dscp",
3657 		.help = "set DSCP value",
3658 		.priv = PRIV_ACTION(SET_IPV4_DSCP,
3659 			sizeof(struct rte_flow_action_set_dscp)),
3660 		.next = NEXT(action_set_ipv4_dscp),
3661 		.call = parse_vc,
3662 	},
3663 	[ACTION_SET_IPV4_DSCP_VALUE] = {
3664 		.name = "dscp_value",
3665 		.help = "new IPv4 DSCP value to set",
3666 		.next = NEXT(action_set_ipv4_dscp, NEXT_ENTRY(UNSIGNED)),
3667 		.args = ARGS(ARGS_ENTRY
3668 			     (struct rte_flow_action_set_dscp, dscp)),
3669 		.call = parse_vc_conf,
3670 	},
3671 	[ACTION_SET_IPV6_DSCP] = {
3672 		.name = "set_ipv6_dscp",
3673 		.help = "set DSCP value",
3674 		.priv = PRIV_ACTION(SET_IPV6_DSCP,
3675 			sizeof(struct rte_flow_action_set_dscp)),
3676 		.next = NEXT(action_set_ipv6_dscp),
3677 		.call = parse_vc,
3678 	},
3679 	[ACTION_SET_IPV6_DSCP_VALUE] = {
3680 		.name = "dscp_value",
3681 		.help = "new IPv6 DSCP value to set",
3682 		.next = NEXT(action_set_ipv6_dscp, NEXT_ENTRY(UNSIGNED)),
3683 		.args = ARGS(ARGS_ENTRY
3684 			     (struct rte_flow_action_set_dscp, dscp)),
3685 		.call = parse_vc_conf,
3686 	},
3687 };
3688 
3689 /** Remove and return last entry from argument stack. */
3690 static const struct arg *
3691 pop_args(struct context *ctx)
3692 {
3693 	return ctx->args_num ? ctx->args[--ctx->args_num] : NULL;
3694 }
3695 
3696 /** Add entry on top of the argument stack. */
3697 static int
3698 push_args(struct context *ctx, const struct arg *arg)
3699 {
3700 	if (ctx->args_num == CTX_STACK_SIZE)
3701 		return -1;
3702 	ctx->args[ctx->args_num++] = arg;
3703 	return 0;
3704 }
3705 
3706 /** Spread value into buffer according to bit-mask. */
3707 static size_t
3708 arg_entry_bf_fill(void *dst, uintmax_t val, const struct arg *arg)
3709 {
3710 	uint32_t i = arg->size;
3711 	uint32_t end = 0;
3712 	int sub = 1;
3713 	int add = 0;
3714 	size_t len = 0;
3715 
3716 	if (!arg->mask)
3717 		return 0;
3718 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
3719 	if (!arg->hton) {
3720 		i = 0;
3721 		end = arg->size;
3722 		sub = 0;
3723 		add = 1;
3724 	}
3725 #endif
3726 	while (i != end) {
3727 		unsigned int shift = 0;
3728 		uint8_t *buf = (uint8_t *)dst + arg->offset + (i -= sub);
3729 
3730 		for (shift = 0; arg->mask[i] >> shift; ++shift) {
3731 			if (!(arg->mask[i] & (1 << shift)))
3732 				continue;
3733 			++len;
3734 			if (!dst)
3735 				continue;
3736 			*buf &= ~(1 << shift);
3737 			*buf |= (val & 1) << shift;
3738 			val >>= 1;
3739 		}
3740 		i += add;
3741 	}
3742 	return len;
3743 }
3744 
3745 /** Compare a string with a partial one of a given length. */
3746 static int
3747 strcmp_partial(const char *full, const char *partial, size_t partial_len)
3748 {
3749 	int r = strncmp(full, partial, partial_len);
3750 
3751 	if (r)
3752 		return r;
3753 	if (strlen(full) <= partial_len)
3754 		return 0;
3755 	return full[partial_len];
3756 }
3757 
3758 /**
3759  * Parse a prefix length and generate a bit-mask.
3760  *
3761  * Last argument (ctx->args) is retrieved to determine mask size, storage
3762  * location and whether the result must use network byte ordering.
3763  */
3764 static int
3765 parse_prefix(struct context *ctx, const struct token *token,
3766 	     const char *str, unsigned int len,
3767 	     void *buf, unsigned int size)
3768 {
3769 	const struct arg *arg = pop_args(ctx);
3770 	static const uint8_t conv[] = "\x00\x80\xc0\xe0\xf0\xf8\xfc\xfe\xff";
3771 	char *end;
3772 	uintmax_t u;
3773 	unsigned int bytes;
3774 	unsigned int extra;
3775 
3776 	(void)token;
3777 	/* Argument is expected. */
3778 	if (!arg)
3779 		return -1;
3780 	errno = 0;
3781 	u = strtoumax(str, &end, 0);
3782 	if (errno || (size_t)(end - str) != len)
3783 		goto error;
3784 	if (arg->mask) {
3785 		uintmax_t v = 0;
3786 
3787 		extra = arg_entry_bf_fill(NULL, 0, arg);
3788 		if (u > extra)
3789 			goto error;
3790 		if (!ctx->object)
3791 			return len;
3792 		extra -= u;
3793 		while (u--)
3794 			(v <<= 1, v |= 1);
3795 		v <<= extra;
3796 		if (!arg_entry_bf_fill(ctx->object, v, arg) ||
3797 		    !arg_entry_bf_fill(ctx->objmask, -1, arg))
3798 			goto error;
3799 		return len;
3800 	}
3801 	bytes = u / 8;
3802 	extra = u % 8;
3803 	size = arg->size;
3804 	if (bytes > size || bytes + !!extra > size)
3805 		goto error;
3806 	if (!ctx->object)
3807 		return len;
3808 	buf = (uint8_t *)ctx->object + arg->offset;
3809 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
3810 	if (!arg->hton) {
3811 		memset((uint8_t *)buf + size - bytes, 0xff, bytes);
3812 		memset(buf, 0x00, size - bytes);
3813 		if (extra)
3814 			((uint8_t *)buf)[size - bytes - 1] = conv[extra];
3815 	} else
3816 #endif
3817 	{
3818 		memset(buf, 0xff, bytes);
3819 		memset((uint8_t *)buf + bytes, 0x00, size - bytes);
3820 		if (extra)
3821 			((uint8_t *)buf)[bytes] = conv[extra];
3822 	}
3823 	if (ctx->objmask)
3824 		memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
3825 	return len;
3826 error:
3827 	push_args(ctx, arg);
3828 	return -1;
3829 }
3830 
3831 /** Default parsing function for token name matching. */
3832 static int
3833 parse_default(struct context *ctx, const struct token *token,
3834 	      const char *str, unsigned int len,
3835 	      void *buf, unsigned int size)
3836 {
3837 	(void)ctx;
3838 	(void)buf;
3839 	(void)size;
3840 	if (strcmp_partial(token->name, str, len))
3841 		return -1;
3842 	return len;
3843 }
3844 
3845 /** Parse flow command, initialize output buffer for subsequent tokens. */
3846 static int
3847 parse_init(struct context *ctx, const struct token *token,
3848 	   const char *str, unsigned int len,
3849 	   void *buf, unsigned int size)
3850 {
3851 	struct buffer *out = buf;
3852 
3853 	/* Token name must match. */
3854 	if (parse_default(ctx, token, str, len, NULL, 0) < 0)
3855 		return -1;
3856 	/* Nothing else to do if there is no buffer. */
3857 	if (!out)
3858 		return len;
3859 	/* Make sure buffer is large enough. */
3860 	if (size < sizeof(*out))
3861 		return -1;
3862 	/* Initialize buffer. */
3863 	memset(out, 0x00, sizeof(*out));
3864 	memset((uint8_t *)out + sizeof(*out), 0x22, size - sizeof(*out));
3865 	ctx->objdata = 0;
3866 	ctx->object = out;
3867 	ctx->objmask = NULL;
3868 	return len;
3869 }
3870 
3871 /** Parse tokens for validate/create commands. */
3872 static int
3873 parse_vc(struct context *ctx, const struct token *token,
3874 	 const char *str, unsigned int len,
3875 	 void *buf, unsigned int size)
3876 {
3877 	struct buffer *out = buf;
3878 	uint8_t *data;
3879 	uint32_t data_size;
3880 
3881 	/* Token name must match. */
3882 	if (parse_default(ctx, token, str, len, NULL, 0) < 0)
3883 		return -1;
3884 	/* Nothing else to do if there is no buffer. */
3885 	if (!out)
3886 		return len;
3887 	if (!out->command) {
3888 		if (ctx->curr != VALIDATE && ctx->curr != CREATE)
3889 			return -1;
3890 		if (sizeof(*out) > size)
3891 			return -1;
3892 		out->command = ctx->curr;
3893 		ctx->objdata = 0;
3894 		ctx->object = out;
3895 		ctx->objmask = NULL;
3896 		out->args.vc.data = (uint8_t *)out + size;
3897 		return len;
3898 	}
3899 	ctx->objdata = 0;
3900 	ctx->object = &out->args.vc.attr;
3901 	ctx->objmask = NULL;
3902 	switch (ctx->curr) {
3903 	case GROUP:
3904 	case PRIORITY:
3905 		return len;
3906 	case INGRESS:
3907 		out->args.vc.attr.ingress = 1;
3908 		return len;
3909 	case EGRESS:
3910 		out->args.vc.attr.egress = 1;
3911 		return len;
3912 	case TRANSFER:
3913 		out->args.vc.attr.transfer = 1;
3914 		return len;
3915 	case PATTERN:
3916 		out->args.vc.pattern =
3917 			(void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
3918 					       sizeof(double));
3919 		ctx->object = out->args.vc.pattern;
3920 		ctx->objmask = NULL;
3921 		return len;
3922 	case ACTIONS:
3923 		out->args.vc.actions =
3924 			(void *)RTE_ALIGN_CEIL((uintptr_t)
3925 					       (out->args.vc.pattern +
3926 						out->args.vc.pattern_n),
3927 					       sizeof(double));
3928 		ctx->object = out->args.vc.actions;
3929 		ctx->objmask = NULL;
3930 		return len;
3931 	default:
3932 		if (!token->priv)
3933 			return -1;
3934 		break;
3935 	}
3936 	if (!out->args.vc.actions) {
3937 		const struct parse_item_priv *priv = token->priv;
3938 		struct rte_flow_item *item =
3939 			out->args.vc.pattern + out->args.vc.pattern_n;
3940 
3941 		data_size = priv->size * 3; /* spec, last, mask */
3942 		data = (void *)RTE_ALIGN_FLOOR((uintptr_t)
3943 					       (out->args.vc.data - data_size),
3944 					       sizeof(double));
3945 		if ((uint8_t *)item + sizeof(*item) > data)
3946 			return -1;
3947 		*item = (struct rte_flow_item){
3948 			.type = priv->type,
3949 		};
3950 		++out->args.vc.pattern_n;
3951 		ctx->object = item;
3952 		ctx->objmask = NULL;
3953 	} else {
3954 		const struct parse_action_priv *priv = token->priv;
3955 		struct rte_flow_action *action =
3956 			out->args.vc.actions + out->args.vc.actions_n;
3957 
3958 		data_size = priv->size; /* configuration */
3959 		data = (void *)RTE_ALIGN_FLOOR((uintptr_t)
3960 					       (out->args.vc.data - data_size),
3961 					       sizeof(double));
3962 		if ((uint8_t *)action + sizeof(*action) > data)
3963 			return -1;
3964 		*action = (struct rte_flow_action){
3965 			.type = priv->type,
3966 			.conf = data_size ? data : NULL,
3967 		};
3968 		++out->args.vc.actions_n;
3969 		ctx->object = action;
3970 		ctx->objmask = NULL;
3971 	}
3972 	memset(data, 0, data_size);
3973 	out->args.vc.data = data;
3974 	ctx->objdata = data_size;
3975 	return len;
3976 }
3977 
3978 /** Parse pattern item parameter type. */
3979 static int
3980 parse_vc_spec(struct context *ctx, const struct token *token,
3981 	      const char *str, unsigned int len,
3982 	      void *buf, unsigned int size)
3983 {
3984 	struct buffer *out = buf;
3985 	struct rte_flow_item *item;
3986 	uint32_t data_size;
3987 	int index;
3988 	int objmask = 0;
3989 
3990 	(void)size;
3991 	/* Token name must match. */
3992 	if (parse_default(ctx, token, str, len, NULL, 0) < 0)
3993 		return -1;
3994 	/* Parse parameter types. */
3995 	switch (ctx->curr) {
3996 		static const enum index prefix[] = NEXT_ENTRY(PREFIX);
3997 
3998 	case ITEM_PARAM_IS:
3999 		index = 0;
4000 		objmask = 1;
4001 		break;
4002 	case ITEM_PARAM_SPEC:
4003 		index = 0;
4004 		break;
4005 	case ITEM_PARAM_LAST:
4006 		index = 1;
4007 		break;
4008 	case ITEM_PARAM_PREFIX:
4009 		/* Modify next token to expect a prefix. */
4010 		if (ctx->next_num < 2)
4011 			return -1;
4012 		ctx->next[ctx->next_num - 2] = prefix;
4013 		/* Fall through. */
4014 	case ITEM_PARAM_MASK:
4015 		index = 2;
4016 		break;
4017 	default:
4018 		return -1;
4019 	}
4020 	/* Nothing else to do if there is no buffer. */
4021 	if (!out)
4022 		return len;
4023 	if (!out->args.vc.pattern_n)
4024 		return -1;
4025 	item = &out->args.vc.pattern[out->args.vc.pattern_n - 1];
4026 	data_size = ctx->objdata / 3; /* spec, last, mask */
4027 	/* Point to selected object. */
4028 	ctx->object = out->args.vc.data + (data_size * index);
4029 	if (objmask) {
4030 		ctx->objmask = out->args.vc.data + (data_size * 2); /* mask */
4031 		item->mask = ctx->objmask;
4032 	} else
4033 		ctx->objmask = NULL;
4034 	/* Update relevant item pointer. */
4035 	*((const void **[]){ &item->spec, &item->last, &item->mask })[index] =
4036 		ctx->object;
4037 	return len;
4038 }
4039 
4040 /** Parse action configuration field. */
4041 static int
4042 parse_vc_conf(struct context *ctx, const struct token *token,
4043 	      const char *str, unsigned int len,
4044 	      void *buf, unsigned int size)
4045 {
4046 	struct buffer *out = buf;
4047 
4048 	(void)size;
4049 	/* Token name must match. */
4050 	if (parse_default(ctx, token, str, len, NULL, 0) < 0)
4051 		return -1;
4052 	/* Nothing else to do if there is no buffer. */
4053 	if (!out)
4054 		return len;
4055 	/* Point to selected object. */
4056 	ctx->object = out->args.vc.data;
4057 	ctx->objmask = NULL;
4058 	return len;
4059 }
4060 
4061 /** Parse RSS action. */
4062 static int
4063 parse_vc_action_rss(struct context *ctx, const struct token *token,
4064 		    const char *str, unsigned int len,
4065 		    void *buf, unsigned int size)
4066 {
4067 	struct buffer *out = buf;
4068 	struct rte_flow_action *action;
4069 	struct action_rss_data *action_rss_data;
4070 	unsigned int i;
4071 	int ret;
4072 
4073 	ret = parse_vc(ctx, token, str, len, buf, size);
4074 	if (ret < 0)
4075 		return ret;
4076 	/* Nothing else to do if there is no buffer. */
4077 	if (!out)
4078 		return ret;
4079 	if (!out->args.vc.actions_n)
4080 		return -1;
4081 	action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4082 	/* Point to selected object. */
4083 	ctx->object = out->args.vc.data;
4084 	ctx->objmask = NULL;
4085 	/* Set up default configuration. */
4086 	action_rss_data = ctx->object;
4087 	*action_rss_data = (struct action_rss_data){
4088 		.conf = (struct rte_flow_action_rss){
4089 			.func = RTE_ETH_HASH_FUNCTION_DEFAULT,
4090 			.level = 0,
4091 			.types = rss_hf,
4092 			.key_len = sizeof(action_rss_data->key),
4093 			.queue_num = RTE_MIN(nb_rxq, ACTION_RSS_QUEUE_NUM),
4094 			.key = action_rss_data->key,
4095 			.queue = action_rss_data->queue,
4096 		},
4097 		.key = "testpmd's default RSS hash key, "
4098 			"override it for better balancing",
4099 		.queue = { 0 },
4100 	};
4101 	for (i = 0; i < action_rss_data->conf.queue_num; ++i)
4102 		action_rss_data->queue[i] = i;
4103 	if (!port_id_is_invalid(ctx->port, DISABLED_WARN) &&
4104 	    ctx->port != (portid_t)RTE_PORT_ALL) {
4105 		struct rte_eth_dev_info info;
4106 		int ret2;
4107 
4108 		ret2 = rte_eth_dev_info_get(ctx->port, &info);
4109 		if (ret2 != 0)
4110 			return ret2;
4111 
4112 		action_rss_data->conf.key_len =
4113 			RTE_MIN(sizeof(action_rss_data->key),
4114 				info.hash_key_size);
4115 	}
4116 	action->conf = &action_rss_data->conf;
4117 	return ret;
4118 }
4119 
4120 /**
4121  * Parse func field for RSS action.
4122  *
4123  * The RTE_ETH_HASH_FUNCTION_* value to assign is derived from the
4124  * ACTION_RSS_FUNC_* index that called this function.
4125  */
4126 static int
4127 parse_vc_action_rss_func(struct context *ctx, const struct token *token,
4128 			 const char *str, unsigned int len,
4129 			 void *buf, unsigned int size)
4130 {
4131 	struct action_rss_data *action_rss_data;
4132 	enum rte_eth_hash_function func;
4133 
4134 	(void)buf;
4135 	(void)size;
4136 	/* Token name must match. */
4137 	if (parse_default(ctx, token, str, len, NULL, 0) < 0)
4138 		return -1;
4139 	switch (ctx->curr) {
4140 	case ACTION_RSS_FUNC_DEFAULT:
4141 		func = RTE_ETH_HASH_FUNCTION_DEFAULT;
4142 		break;
4143 	case ACTION_RSS_FUNC_TOEPLITZ:
4144 		func = RTE_ETH_HASH_FUNCTION_TOEPLITZ;
4145 		break;
4146 	case ACTION_RSS_FUNC_SIMPLE_XOR:
4147 		func = RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
4148 		break;
4149 	case ACTION_RSS_FUNC_SYMMETRIC_TOEPLITZ:
4150 		func = RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ;
4151 		break;
4152 	default:
4153 		return -1;
4154 	}
4155 	if (!ctx->object)
4156 		return len;
4157 	action_rss_data = ctx->object;
4158 	action_rss_data->conf.func = func;
4159 	return len;
4160 }
4161 
4162 /**
4163  * Parse type field for RSS action.
4164  *
4165  * Valid tokens are type field names and the "end" token.
4166  */
4167 static int
4168 parse_vc_action_rss_type(struct context *ctx, const struct token *token,
4169 			  const char *str, unsigned int len,
4170 			  void *buf, unsigned int size)
4171 {
4172 	static const enum index next[] = NEXT_ENTRY(ACTION_RSS_TYPE);
4173 	struct action_rss_data *action_rss_data;
4174 	unsigned int i;
4175 
4176 	(void)token;
4177 	(void)buf;
4178 	(void)size;
4179 	if (ctx->curr != ACTION_RSS_TYPE)
4180 		return -1;
4181 	if (!(ctx->objdata >> 16) && ctx->object) {
4182 		action_rss_data = ctx->object;
4183 		action_rss_data->conf.types = 0;
4184 	}
4185 	if (!strcmp_partial("end", str, len)) {
4186 		ctx->objdata &= 0xffff;
4187 		return len;
4188 	}
4189 	for (i = 0; rss_type_table[i].str; ++i)
4190 		if (!strcmp_partial(rss_type_table[i].str, str, len))
4191 			break;
4192 	if (!rss_type_table[i].str)
4193 		return -1;
4194 	ctx->objdata = 1 << 16 | (ctx->objdata & 0xffff);
4195 	/* Repeat token. */
4196 	if (ctx->next_num == RTE_DIM(ctx->next))
4197 		return -1;
4198 	ctx->next[ctx->next_num++] = next;
4199 	if (!ctx->object)
4200 		return len;
4201 	action_rss_data = ctx->object;
4202 	action_rss_data->conf.types |= rss_type_table[i].rss_type;
4203 	return len;
4204 }
4205 
4206 /**
4207  * Parse queue field for RSS action.
4208  *
4209  * Valid tokens are queue indices and the "end" token.
4210  */
4211 static int
4212 parse_vc_action_rss_queue(struct context *ctx, const struct token *token,
4213 			  const char *str, unsigned int len,
4214 			  void *buf, unsigned int size)
4215 {
4216 	static const enum index next[] = NEXT_ENTRY(ACTION_RSS_QUEUE);
4217 	struct action_rss_data *action_rss_data;
4218 	const struct arg *arg;
4219 	int ret;
4220 	int i;
4221 
4222 	(void)token;
4223 	(void)buf;
4224 	(void)size;
4225 	if (ctx->curr != ACTION_RSS_QUEUE)
4226 		return -1;
4227 	i = ctx->objdata >> 16;
4228 	if (!strcmp_partial("end", str, len)) {
4229 		ctx->objdata &= 0xffff;
4230 		goto end;
4231 	}
4232 	if (i >= ACTION_RSS_QUEUE_NUM)
4233 		return -1;
4234 	arg = ARGS_ENTRY_ARB(offsetof(struct action_rss_data, queue) +
4235 			     i * sizeof(action_rss_data->queue[i]),
4236 			     sizeof(action_rss_data->queue[i]));
4237 	if (push_args(ctx, arg))
4238 		return -1;
4239 	ret = parse_int(ctx, token, str, len, NULL, 0);
4240 	if (ret < 0) {
4241 		pop_args(ctx);
4242 		return -1;
4243 	}
4244 	++i;
4245 	ctx->objdata = i << 16 | (ctx->objdata & 0xffff);
4246 	/* Repeat token. */
4247 	if (ctx->next_num == RTE_DIM(ctx->next))
4248 		return -1;
4249 	ctx->next[ctx->next_num++] = next;
4250 end:
4251 	if (!ctx->object)
4252 		return len;
4253 	action_rss_data = ctx->object;
4254 	action_rss_data->conf.queue_num = i;
4255 	action_rss_data->conf.queue = i ? action_rss_data->queue : NULL;
4256 	return len;
4257 }
4258 
4259 /** Parse VXLAN encap action. */
4260 static int
4261 parse_vc_action_vxlan_encap(struct context *ctx, const struct token *token,
4262 			    const char *str, unsigned int len,
4263 			    void *buf, unsigned int size)
4264 {
4265 	struct buffer *out = buf;
4266 	struct rte_flow_action *action;
4267 	struct action_vxlan_encap_data *action_vxlan_encap_data;
4268 	int ret;
4269 
4270 	ret = parse_vc(ctx, token, str, len, buf, size);
4271 	if (ret < 0)
4272 		return ret;
4273 	/* Nothing else to do if there is no buffer. */
4274 	if (!out)
4275 		return ret;
4276 	if (!out->args.vc.actions_n)
4277 		return -1;
4278 	action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4279 	/* Point to selected object. */
4280 	ctx->object = out->args.vc.data;
4281 	ctx->objmask = NULL;
4282 	/* Set up default configuration. */
4283 	action_vxlan_encap_data = ctx->object;
4284 	*action_vxlan_encap_data = (struct action_vxlan_encap_data){
4285 		.conf = (struct rte_flow_action_vxlan_encap){
4286 			.definition = action_vxlan_encap_data->items,
4287 		},
4288 		.items = {
4289 			{
4290 				.type = RTE_FLOW_ITEM_TYPE_ETH,
4291 				.spec = &action_vxlan_encap_data->item_eth,
4292 				.mask = &rte_flow_item_eth_mask,
4293 			},
4294 			{
4295 				.type = RTE_FLOW_ITEM_TYPE_VLAN,
4296 				.spec = &action_vxlan_encap_data->item_vlan,
4297 				.mask = &rte_flow_item_vlan_mask,
4298 			},
4299 			{
4300 				.type = RTE_FLOW_ITEM_TYPE_IPV4,
4301 				.spec = &action_vxlan_encap_data->item_ipv4,
4302 				.mask = &rte_flow_item_ipv4_mask,
4303 			},
4304 			{
4305 				.type = RTE_FLOW_ITEM_TYPE_UDP,
4306 				.spec = &action_vxlan_encap_data->item_udp,
4307 				.mask = &rte_flow_item_udp_mask,
4308 			},
4309 			{
4310 				.type = RTE_FLOW_ITEM_TYPE_VXLAN,
4311 				.spec = &action_vxlan_encap_data->item_vxlan,
4312 				.mask = &rte_flow_item_vxlan_mask,
4313 			},
4314 			{
4315 				.type = RTE_FLOW_ITEM_TYPE_END,
4316 			},
4317 		},
4318 		.item_eth.type = 0,
4319 		.item_vlan = {
4320 			.tci = vxlan_encap_conf.vlan_tci,
4321 			.inner_type = 0,
4322 		},
4323 		.item_ipv4.hdr = {
4324 			.src_addr = vxlan_encap_conf.ipv4_src,
4325 			.dst_addr = vxlan_encap_conf.ipv4_dst,
4326 		},
4327 		.item_udp.hdr = {
4328 			.src_port = vxlan_encap_conf.udp_src,
4329 			.dst_port = vxlan_encap_conf.udp_dst,
4330 		},
4331 		.item_vxlan.flags = 0,
4332 	};
4333 	memcpy(action_vxlan_encap_data->item_eth.dst.addr_bytes,
4334 	       vxlan_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
4335 	memcpy(action_vxlan_encap_data->item_eth.src.addr_bytes,
4336 	       vxlan_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
4337 	if (!vxlan_encap_conf.select_ipv4) {
4338 		memcpy(&action_vxlan_encap_data->item_ipv6.hdr.src_addr,
4339 		       &vxlan_encap_conf.ipv6_src,
4340 		       sizeof(vxlan_encap_conf.ipv6_src));
4341 		memcpy(&action_vxlan_encap_data->item_ipv6.hdr.dst_addr,
4342 		       &vxlan_encap_conf.ipv6_dst,
4343 		       sizeof(vxlan_encap_conf.ipv6_dst));
4344 		action_vxlan_encap_data->items[2] = (struct rte_flow_item){
4345 			.type = RTE_FLOW_ITEM_TYPE_IPV6,
4346 			.spec = &action_vxlan_encap_data->item_ipv6,
4347 			.mask = &rte_flow_item_ipv6_mask,
4348 		};
4349 	}
4350 	if (!vxlan_encap_conf.select_vlan)
4351 		action_vxlan_encap_data->items[1].type =
4352 			RTE_FLOW_ITEM_TYPE_VOID;
4353 	if (vxlan_encap_conf.select_tos_ttl) {
4354 		if (vxlan_encap_conf.select_ipv4) {
4355 			static struct rte_flow_item_ipv4 ipv4_mask_tos;
4356 
4357 			memcpy(&ipv4_mask_tos, &rte_flow_item_ipv4_mask,
4358 			       sizeof(ipv4_mask_tos));
4359 			ipv4_mask_tos.hdr.type_of_service = 0xff;
4360 			ipv4_mask_tos.hdr.time_to_live = 0xff;
4361 			action_vxlan_encap_data->item_ipv4.hdr.type_of_service =
4362 					vxlan_encap_conf.ip_tos;
4363 			action_vxlan_encap_data->item_ipv4.hdr.time_to_live =
4364 					vxlan_encap_conf.ip_ttl;
4365 			action_vxlan_encap_data->items[2].mask =
4366 							&ipv4_mask_tos;
4367 		} else {
4368 			static struct rte_flow_item_ipv6 ipv6_mask_tos;
4369 
4370 			memcpy(&ipv6_mask_tos, &rte_flow_item_ipv6_mask,
4371 			       sizeof(ipv6_mask_tos));
4372 			ipv6_mask_tos.hdr.vtc_flow |=
4373 				RTE_BE32(0xfful << RTE_IPV6_HDR_TC_SHIFT);
4374 			ipv6_mask_tos.hdr.hop_limits = 0xff;
4375 			action_vxlan_encap_data->item_ipv6.hdr.vtc_flow |=
4376 				rte_cpu_to_be_32
4377 					((uint32_t)vxlan_encap_conf.ip_tos <<
4378 					 RTE_IPV6_HDR_TC_SHIFT);
4379 			action_vxlan_encap_data->item_ipv6.hdr.hop_limits =
4380 					vxlan_encap_conf.ip_ttl;
4381 			action_vxlan_encap_data->items[2].mask =
4382 							&ipv6_mask_tos;
4383 		}
4384 	}
4385 	memcpy(action_vxlan_encap_data->item_vxlan.vni, vxlan_encap_conf.vni,
4386 	       RTE_DIM(vxlan_encap_conf.vni));
4387 	action->conf = &action_vxlan_encap_data->conf;
4388 	return ret;
4389 }
4390 
4391 /** Parse NVGRE encap action. */
4392 static int
4393 parse_vc_action_nvgre_encap(struct context *ctx, const struct token *token,
4394 			    const char *str, unsigned int len,
4395 			    void *buf, unsigned int size)
4396 {
4397 	struct buffer *out = buf;
4398 	struct rte_flow_action *action;
4399 	struct action_nvgre_encap_data *action_nvgre_encap_data;
4400 	int ret;
4401 
4402 	ret = parse_vc(ctx, token, str, len, buf, size);
4403 	if (ret < 0)
4404 		return ret;
4405 	/* Nothing else to do if there is no buffer. */
4406 	if (!out)
4407 		return ret;
4408 	if (!out->args.vc.actions_n)
4409 		return -1;
4410 	action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4411 	/* Point to selected object. */
4412 	ctx->object = out->args.vc.data;
4413 	ctx->objmask = NULL;
4414 	/* Set up default configuration. */
4415 	action_nvgre_encap_data = ctx->object;
4416 	*action_nvgre_encap_data = (struct action_nvgre_encap_data){
4417 		.conf = (struct rte_flow_action_nvgre_encap){
4418 			.definition = action_nvgre_encap_data->items,
4419 		},
4420 		.items = {
4421 			{
4422 				.type = RTE_FLOW_ITEM_TYPE_ETH,
4423 				.spec = &action_nvgre_encap_data->item_eth,
4424 				.mask = &rte_flow_item_eth_mask,
4425 			},
4426 			{
4427 				.type = RTE_FLOW_ITEM_TYPE_VLAN,
4428 				.spec = &action_nvgre_encap_data->item_vlan,
4429 				.mask = &rte_flow_item_vlan_mask,
4430 			},
4431 			{
4432 				.type = RTE_FLOW_ITEM_TYPE_IPV4,
4433 				.spec = &action_nvgre_encap_data->item_ipv4,
4434 				.mask = &rte_flow_item_ipv4_mask,
4435 			},
4436 			{
4437 				.type = RTE_FLOW_ITEM_TYPE_NVGRE,
4438 				.spec = &action_nvgre_encap_data->item_nvgre,
4439 				.mask = &rte_flow_item_nvgre_mask,
4440 			},
4441 			{
4442 				.type = RTE_FLOW_ITEM_TYPE_END,
4443 			},
4444 		},
4445 		.item_eth.type = 0,
4446 		.item_vlan = {
4447 			.tci = nvgre_encap_conf.vlan_tci,
4448 			.inner_type = 0,
4449 		},
4450 		.item_ipv4.hdr = {
4451 		       .src_addr = nvgre_encap_conf.ipv4_src,
4452 		       .dst_addr = nvgre_encap_conf.ipv4_dst,
4453 		},
4454 		.item_nvgre.flow_id = 0,
4455 	};
4456 	memcpy(action_nvgre_encap_data->item_eth.dst.addr_bytes,
4457 	       nvgre_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
4458 	memcpy(action_nvgre_encap_data->item_eth.src.addr_bytes,
4459 	       nvgre_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
4460 	if (!nvgre_encap_conf.select_ipv4) {
4461 		memcpy(&action_nvgre_encap_data->item_ipv6.hdr.src_addr,
4462 		       &nvgre_encap_conf.ipv6_src,
4463 		       sizeof(nvgre_encap_conf.ipv6_src));
4464 		memcpy(&action_nvgre_encap_data->item_ipv6.hdr.dst_addr,
4465 		       &nvgre_encap_conf.ipv6_dst,
4466 		       sizeof(nvgre_encap_conf.ipv6_dst));
4467 		action_nvgre_encap_data->items[2] = (struct rte_flow_item){
4468 			.type = RTE_FLOW_ITEM_TYPE_IPV6,
4469 			.spec = &action_nvgre_encap_data->item_ipv6,
4470 			.mask = &rte_flow_item_ipv6_mask,
4471 		};
4472 	}
4473 	if (!nvgre_encap_conf.select_vlan)
4474 		action_nvgre_encap_data->items[1].type =
4475 			RTE_FLOW_ITEM_TYPE_VOID;
4476 	memcpy(action_nvgre_encap_data->item_nvgre.tni, nvgre_encap_conf.tni,
4477 	       RTE_DIM(nvgre_encap_conf.tni));
4478 	action->conf = &action_nvgre_encap_data->conf;
4479 	return ret;
4480 }
4481 
4482 /** Parse l2 encap action. */
4483 static int
4484 parse_vc_action_l2_encap(struct context *ctx, const struct token *token,
4485 			 const char *str, unsigned int len,
4486 			 void *buf, unsigned int size)
4487 {
4488 	struct buffer *out = buf;
4489 	struct rte_flow_action *action;
4490 	struct action_raw_encap_data *action_encap_data;
4491 	struct rte_flow_item_eth eth = { .type = 0, };
4492 	struct rte_flow_item_vlan vlan = {
4493 		.tci = mplsoudp_encap_conf.vlan_tci,
4494 		.inner_type = 0,
4495 	};
4496 	uint8_t *header;
4497 	int ret;
4498 
4499 	ret = parse_vc(ctx, token, str, len, buf, size);
4500 	if (ret < 0)
4501 		return ret;
4502 	/* Nothing else to do if there is no buffer. */
4503 	if (!out)
4504 		return ret;
4505 	if (!out->args.vc.actions_n)
4506 		return -1;
4507 	action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4508 	/* Point to selected object. */
4509 	ctx->object = out->args.vc.data;
4510 	ctx->objmask = NULL;
4511 	/* Copy the headers to the buffer. */
4512 	action_encap_data = ctx->object;
4513 	*action_encap_data = (struct action_raw_encap_data) {
4514 		.conf = (struct rte_flow_action_raw_encap){
4515 			.data = action_encap_data->data,
4516 		},
4517 		.data = {},
4518 	};
4519 	header = action_encap_data->data;
4520 	if (l2_encap_conf.select_vlan)
4521 		eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
4522 	else if (l2_encap_conf.select_ipv4)
4523 		eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4524 	else
4525 		eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4526 	memcpy(eth.dst.addr_bytes,
4527 	       l2_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
4528 	memcpy(eth.src.addr_bytes,
4529 	       l2_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
4530 	memcpy(header, &eth, sizeof(eth));
4531 	header += sizeof(eth);
4532 	if (l2_encap_conf.select_vlan) {
4533 		if (l2_encap_conf.select_ipv4)
4534 			vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4535 		else
4536 			vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4537 		memcpy(header, &vlan, sizeof(vlan));
4538 		header += sizeof(vlan);
4539 	}
4540 	action_encap_data->conf.size = header -
4541 		action_encap_data->data;
4542 	action->conf = &action_encap_data->conf;
4543 	return ret;
4544 }
4545 
4546 /** Parse l2 decap action. */
4547 static int
4548 parse_vc_action_l2_decap(struct context *ctx, const struct token *token,
4549 			 const char *str, unsigned int len,
4550 			 void *buf, unsigned int size)
4551 {
4552 	struct buffer *out = buf;
4553 	struct rte_flow_action *action;
4554 	struct action_raw_decap_data *action_decap_data;
4555 	struct rte_flow_item_eth eth = { .type = 0, };
4556 	struct rte_flow_item_vlan vlan = {
4557 		.tci = mplsoudp_encap_conf.vlan_tci,
4558 		.inner_type = 0,
4559 	};
4560 	uint8_t *header;
4561 	int ret;
4562 
4563 	ret = parse_vc(ctx, token, str, len, buf, size);
4564 	if (ret < 0)
4565 		return ret;
4566 	/* Nothing else to do if there is no buffer. */
4567 	if (!out)
4568 		return ret;
4569 	if (!out->args.vc.actions_n)
4570 		return -1;
4571 	action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4572 	/* Point to selected object. */
4573 	ctx->object = out->args.vc.data;
4574 	ctx->objmask = NULL;
4575 	/* Copy the headers to the buffer. */
4576 	action_decap_data = ctx->object;
4577 	*action_decap_data = (struct action_raw_decap_data) {
4578 		.conf = (struct rte_flow_action_raw_decap){
4579 			.data = action_decap_data->data,
4580 		},
4581 		.data = {},
4582 	};
4583 	header = action_decap_data->data;
4584 	if (l2_decap_conf.select_vlan)
4585 		eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
4586 	memcpy(header, &eth, sizeof(eth));
4587 	header += sizeof(eth);
4588 	if (l2_decap_conf.select_vlan) {
4589 		memcpy(header, &vlan, sizeof(vlan));
4590 		header += sizeof(vlan);
4591 	}
4592 	action_decap_data->conf.size = header -
4593 		action_decap_data->data;
4594 	action->conf = &action_decap_data->conf;
4595 	return ret;
4596 }
4597 
4598 #define ETHER_TYPE_MPLS_UNICAST 0x8847
4599 
4600 /** Parse MPLSOGRE encap action. */
4601 static int
4602 parse_vc_action_mplsogre_encap(struct context *ctx, const struct token *token,
4603 			       const char *str, unsigned int len,
4604 			       void *buf, unsigned int size)
4605 {
4606 	struct buffer *out = buf;
4607 	struct rte_flow_action *action;
4608 	struct action_raw_encap_data *action_encap_data;
4609 	struct rte_flow_item_eth eth = { .type = 0, };
4610 	struct rte_flow_item_vlan vlan = {
4611 		.tci = mplsogre_encap_conf.vlan_tci,
4612 		.inner_type = 0,
4613 	};
4614 	struct rte_flow_item_ipv4 ipv4 = {
4615 		.hdr =  {
4616 			.src_addr = mplsogre_encap_conf.ipv4_src,
4617 			.dst_addr = mplsogre_encap_conf.ipv4_dst,
4618 			.next_proto_id = IPPROTO_GRE,
4619 			.version_ihl = RTE_IPV4_VHL_DEF,
4620 			.time_to_live = IPDEFTTL,
4621 		},
4622 	};
4623 	struct rte_flow_item_ipv6 ipv6 = {
4624 		.hdr =  {
4625 			.proto = IPPROTO_GRE,
4626 			.hop_limits = IPDEFTTL,
4627 		},
4628 	};
4629 	struct rte_flow_item_gre gre = {
4630 		.protocol = rte_cpu_to_be_16(ETHER_TYPE_MPLS_UNICAST),
4631 	};
4632 	struct rte_flow_item_mpls mpls = {
4633 		.ttl = 0,
4634 	};
4635 	uint8_t *header;
4636 	int ret;
4637 
4638 	ret = parse_vc(ctx, token, str, len, buf, size);
4639 	if (ret < 0)
4640 		return ret;
4641 	/* Nothing else to do if there is no buffer. */
4642 	if (!out)
4643 		return ret;
4644 	if (!out->args.vc.actions_n)
4645 		return -1;
4646 	action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4647 	/* Point to selected object. */
4648 	ctx->object = out->args.vc.data;
4649 	ctx->objmask = NULL;
4650 	/* Copy the headers to the buffer. */
4651 	action_encap_data = ctx->object;
4652 	*action_encap_data = (struct action_raw_encap_data) {
4653 		.conf = (struct rte_flow_action_raw_encap){
4654 			.data = action_encap_data->data,
4655 		},
4656 		.data = {},
4657 		.preserve = {},
4658 	};
4659 	header = action_encap_data->data;
4660 	if (mplsogre_encap_conf.select_vlan)
4661 		eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
4662 	else if (mplsogre_encap_conf.select_ipv4)
4663 		eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4664 	else
4665 		eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4666 	memcpy(eth.dst.addr_bytes,
4667 	       mplsogre_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
4668 	memcpy(eth.src.addr_bytes,
4669 	       mplsogre_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
4670 	memcpy(header, &eth, sizeof(eth));
4671 	header += sizeof(eth);
4672 	if (mplsogre_encap_conf.select_vlan) {
4673 		if (mplsogre_encap_conf.select_ipv4)
4674 			vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4675 		else
4676 			vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4677 		memcpy(header, &vlan, sizeof(vlan));
4678 		header += sizeof(vlan);
4679 	}
4680 	if (mplsogre_encap_conf.select_ipv4) {
4681 		memcpy(header, &ipv4, sizeof(ipv4));
4682 		header += sizeof(ipv4);
4683 	} else {
4684 		memcpy(&ipv6.hdr.src_addr,
4685 		       &mplsogre_encap_conf.ipv6_src,
4686 		       sizeof(mplsogre_encap_conf.ipv6_src));
4687 		memcpy(&ipv6.hdr.dst_addr,
4688 		       &mplsogre_encap_conf.ipv6_dst,
4689 		       sizeof(mplsogre_encap_conf.ipv6_dst));
4690 		memcpy(header, &ipv6, sizeof(ipv6));
4691 		header += sizeof(ipv6);
4692 	}
4693 	memcpy(header, &gre, sizeof(gre));
4694 	header += sizeof(gre);
4695 	memcpy(mpls.label_tc_s, mplsogre_encap_conf.label,
4696 	       RTE_DIM(mplsogre_encap_conf.label));
4697 	mpls.label_tc_s[2] |= 0x1;
4698 	memcpy(header, &mpls, sizeof(mpls));
4699 	header += sizeof(mpls);
4700 	action_encap_data->conf.size = header -
4701 		action_encap_data->data;
4702 	action->conf = &action_encap_data->conf;
4703 	return ret;
4704 }
4705 
4706 /** Parse MPLSOGRE decap action. */
4707 static int
4708 parse_vc_action_mplsogre_decap(struct context *ctx, const struct token *token,
4709 			       const char *str, unsigned int len,
4710 			       void *buf, unsigned int size)
4711 {
4712 	struct buffer *out = buf;
4713 	struct rte_flow_action *action;
4714 	struct action_raw_decap_data *action_decap_data;
4715 	struct rte_flow_item_eth eth = { .type = 0, };
4716 	struct rte_flow_item_vlan vlan = {.tci = 0};
4717 	struct rte_flow_item_ipv4 ipv4 = {
4718 		.hdr =  {
4719 			.next_proto_id = IPPROTO_GRE,
4720 		},
4721 	};
4722 	struct rte_flow_item_ipv6 ipv6 = {
4723 		.hdr =  {
4724 			.proto = IPPROTO_GRE,
4725 		},
4726 	};
4727 	struct rte_flow_item_gre gre = {
4728 		.protocol = rte_cpu_to_be_16(ETHER_TYPE_MPLS_UNICAST),
4729 	};
4730 	struct rte_flow_item_mpls mpls;
4731 	uint8_t *header;
4732 	int ret;
4733 
4734 	ret = parse_vc(ctx, token, str, len, buf, size);
4735 	if (ret < 0)
4736 		return ret;
4737 	/* Nothing else to do if there is no buffer. */
4738 	if (!out)
4739 		return ret;
4740 	if (!out->args.vc.actions_n)
4741 		return -1;
4742 	action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4743 	/* Point to selected object. */
4744 	ctx->object = out->args.vc.data;
4745 	ctx->objmask = NULL;
4746 	/* Copy the headers to the buffer. */
4747 	action_decap_data = ctx->object;
4748 	*action_decap_data = (struct action_raw_decap_data) {
4749 		.conf = (struct rte_flow_action_raw_decap){
4750 			.data = action_decap_data->data,
4751 		},
4752 		.data = {},
4753 	};
4754 	header = action_decap_data->data;
4755 	if (mplsogre_decap_conf.select_vlan)
4756 		eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
4757 	else if (mplsogre_encap_conf.select_ipv4)
4758 		eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4759 	else
4760 		eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4761 	memcpy(eth.dst.addr_bytes,
4762 	       mplsogre_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
4763 	memcpy(eth.src.addr_bytes,
4764 	       mplsogre_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
4765 	memcpy(header, &eth, sizeof(eth));
4766 	header += sizeof(eth);
4767 	if (mplsogre_encap_conf.select_vlan) {
4768 		if (mplsogre_encap_conf.select_ipv4)
4769 			vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4770 		else
4771 			vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4772 		memcpy(header, &vlan, sizeof(vlan));
4773 		header += sizeof(vlan);
4774 	}
4775 	if (mplsogre_encap_conf.select_ipv4) {
4776 		memcpy(header, &ipv4, sizeof(ipv4));
4777 		header += sizeof(ipv4);
4778 	} else {
4779 		memcpy(header, &ipv6, sizeof(ipv6));
4780 		header += sizeof(ipv6);
4781 	}
4782 	memcpy(header, &gre, sizeof(gre));
4783 	header += sizeof(gre);
4784 	memset(&mpls, 0, sizeof(mpls));
4785 	memcpy(header, &mpls, sizeof(mpls));
4786 	header += sizeof(mpls);
4787 	action_decap_data->conf.size = header -
4788 		action_decap_data->data;
4789 	action->conf = &action_decap_data->conf;
4790 	return ret;
4791 }
4792 
4793 /** Parse MPLSOUDP encap action. */
4794 static int
4795 parse_vc_action_mplsoudp_encap(struct context *ctx, const struct token *token,
4796 			       const char *str, unsigned int len,
4797 			       void *buf, unsigned int size)
4798 {
4799 	struct buffer *out = buf;
4800 	struct rte_flow_action *action;
4801 	struct action_raw_encap_data *action_encap_data;
4802 	struct rte_flow_item_eth eth = { .type = 0, };
4803 	struct rte_flow_item_vlan vlan = {
4804 		.tci = mplsoudp_encap_conf.vlan_tci,
4805 		.inner_type = 0,
4806 	};
4807 	struct rte_flow_item_ipv4 ipv4 = {
4808 		.hdr =  {
4809 			.src_addr = mplsoudp_encap_conf.ipv4_src,
4810 			.dst_addr = mplsoudp_encap_conf.ipv4_dst,
4811 			.next_proto_id = IPPROTO_UDP,
4812 			.version_ihl = RTE_IPV4_VHL_DEF,
4813 			.time_to_live = IPDEFTTL,
4814 		},
4815 	};
4816 	struct rte_flow_item_ipv6 ipv6 = {
4817 		.hdr =  {
4818 			.proto = IPPROTO_UDP,
4819 			.hop_limits = IPDEFTTL,
4820 		},
4821 	};
4822 	struct rte_flow_item_udp udp = {
4823 		.hdr = {
4824 			.src_port = mplsoudp_encap_conf.udp_src,
4825 			.dst_port = mplsoudp_encap_conf.udp_dst,
4826 		},
4827 	};
4828 	struct rte_flow_item_mpls mpls;
4829 	uint8_t *header;
4830 	int ret;
4831 
4832 	ret = parse_vc(ctx, token, str, len, buf, size);
4833 	if (ret < 0)
4834 		return ret;
4835 	/* Nothing else to do if there is no buffer. */
4836 	if (!out)
4837 		return ret;
4838 	if (!out->args.vc.actions_n)
4839 		return -1;
4840 	action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4841 	/* Point to selected object. */
4842 	ctx->object = out->args.vc.data;
4843 	ctx->objmask = NULL;
4844 	/* Copy the headers to the buffer. */
4845 	action_encap_data = ctx->object;
4846 	*action_encap_data = (struct action_raw_encap_data) {
4847 		.conf = (struct rte_flow_action_raw_encap){
4848 			.data = action_encap_data->data,
4849 		},
4850 		.data = {},
4851 		.preserve = {},
4852 	};
4853 	header = action_encap_data->data;
4854 	if (mplsoudp_encap_conf.select_vlan)
4855 		eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
4856 	else if (mplsoudp_encap_conf.select_ipv4)
4857 		eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4858 	else
4859 		eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4860 	memcpy(eth.dst.addr_bytes,
4861 	       mplsoudp_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
4862 	memcpy(eth.src.addr_bytes,
4863 	       mplsoudp_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
4864 	memcpy(header, &eth, sizeof(eth));
4865 	header += sizeof(eth);
4866 	if (mplsoudp_encap_conf.select_vlan) {
4867 		if (mplsoudp_encap_conf.select_ipv4)
4868 			vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4869 		else
4870 			vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4871 		memcpy(header, &vlan, sizeof(vlan));
4872 		header += sizeof(vlan);
4873 	}
4874 	if (mplsoudp_encap_conf.select_ipv4) {
4875 		memcpy(header, &ipv4, sizeof(ipv4));
4876 		header += sizeof(ipv4);
4877 	} else {
4878 		memcpy(&ipv6.hdr.src_addr,
4879 		       &mplsoudp_encap_conf.ipv6_src,
4880 		       sizeof(mplsoudp_encap_conf.ipv6_src));
4881 		memcpy(&ipv6.hdr.dst_addr,
4882 		       &mplsoudp_encap_conf.ipv6_dst,
4883 		       sizeof(mplsoudp_encap_conf.ipv6_dst));
4884 		memcpy(header, &ipv6, sizeof(ipv6));
4885 		header += sizeof(ipv6);
4886 	}
4887 	memcpy(header, &udp, sizeof(udp));
4888 	header += sizeof(udp);
4889 	memcpy(mpls.label_tc_s, mplsoudp_encap_conf.label,
4890 	       RTE_DIM(mplsoudp_encap_conf.label));
4891 	mpls.label_tc_s[2] |= 0x1;
4892 	memcpy(header, &mpls, sizeof(mpls));
4893 	header += sizeof(mpls);
4894 	action_encap_data->conf.size = header -
4895 		action_encap_data->data;
4896 	action->conf = &action_encap_data->conf;
4897 	return ret;
4898 }
4899 
4900 /** Parse MPLSOUDP decap action. */
4901 static int
4902 parse_vc_action_mplsoudp_decap(struct context *ctx, const struct token *token,
4903 			       const char *str, unsigned int len,
4904 			       void *buf, unsigned int size)
4905 {
4906 	struct buffer *out = buf;
4907 	struct rte_flow_action *action;
4908 	struct action_raw_decap_data *action_decap_data;
4909 	struct rte_flow_item_eth eth = { .type = 0, };
4910 	struct rte_flow_item_vlan vlan = {.tci = 0};
4911 	struct rte_flow_item_ipv4 ipv4 = {
4912 		.hdr =  {
4913 			.next_proto_id = IPPROTO_UDP,
4914 		},
4915 	};
4916 	struct rte_flow_item_ipv6 ipv6 = {
4917 		.hdr =  {
4918 			.proto = IPPROTO_UDP,
4919 		},
4920 	};
4921 	struct rte_flow_item_udp udp = {
4922 		.hdr = {
4923 			.dst_port = rte_cpu_to_be_16(6635),
4924 		},
4925 	};
4926 	struct rte_flow_item_mpls mpls;
4927 	uint8_t *header;
4928 	int ret;
4929 
4930 	ret = parse_vc(ctx, token, str, len, buf, size);
4931 	if (ret < 0)
4932 		return ret;
4933 	/* Nothing else to do if there is no buffer. */
4934 	if (!out)
4935 		return ret;
4936 	if (!out->args.vc.actions_n)
4937 		return -1;
4938 	action = &out->args.vc.actions[out->args.vc.actions_n - 1];
4939 	/* Point to selected object. */
4940 	ctx->object = out->args.vc.data;
4941 	ctx->objmask = NULL;
4942 	/* Copy the headers to the buffer. */
4943 	action_decap_data = ctx->object;
4944 	*action_decap_data = (struct action_raw_decap_data) {
4945 		.conf = (struct rte_flow_action_raw_decap){
4946 			.data = action_decap_data->data,
4947 		},
4948 		.data = {},
4949 	};
4950 	header = action_decap_data->data;
4951 	if (mplsoudp_decap_conf.select_vlan)
4952 		eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
4953 	else if (mplsoudp_encap_conf.select_ipv4)
4954 		eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4955 	else
4956 		eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4957 	memcpy(eth.dst.addr_bytes,
4958 	       mplsoudp_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
4959 	memcpy(eth.src.addr_bytes,
4960 	       mplsoudp_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
4961 	memcpy(header, &eth, sizeof(eth));
4962 	header += sizeof(eth);
4963 	if (mplsoudp_encap_conf.select_vlan) {
4964 		if (mplsoudp_encap_conf.select_ipv4)
4965 			vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
4966 		else
4967 			vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
4968 		memcpy(header, &vlan, sizeof(vlan));
4969 		header += sizeof(vlan);
4970 	}
4971 	if (mplsoudp_encap_conf.select_ipv4) {
4972 		memcpy(header, &ipv4, sizeof(ipv4));
4973 		header += sizeof(ipv4);
4974 	} else {
4975 		memcpy(header, &ipv6, sizeof(ipv6));
4976 		header += sizeof(ipv6);
4977 	}
4978 	memcpy(header, &udp, sizeof(udp));
4979 	header += sizeof(udp);
4980 	memset(&mpls, 0, sizeof(mpls));
4981 	memcpy(header, &mpls, sizeof(mpls));
4982 	header += sizeof(mpls);
4983 	action_decap_data->conf.size = header -
4984 		action_decap_data->data;
4985 	action->conf = &action_decap_data->conf;
4986 	return ret;
4987 }
4988 
4989 static int
4990 parse_vc_action_raw_decap_index(struct context *ctx, const struct token *token,
4991 				const char *str, unsigned int len, void *buf,
4992 				unsigned int size)
4993 {
4994 	struct action_raw_decap_data *action_raw_decap_data;
4995 	struct rte_flow_action *action;
4996 	const struct arg *arg;
4997 	struct buffer *out = buf;
4998 	int ret;
4999 	uint16_t idx;
5000 
5001 	RTE_SET_USED(token);
5002 	RTE_SET_USED(buf);
5003 	RTE_SET_USED(size);
5004 	arg = ARGS_ENTRY_ARB_BOUNDED
5005 		(offsetof(struct action_raw_decap_data, idx),
5006 		 sizeof(((struct action_raw_decap_data *)0)->idx),
5007 		 0, RAW_ENCAP_CONFS_MAX_NUM - 1);
5008 	if (push_args(ctx, arg))
5009 		return -1;
5010 	ret = parse_int(ctx, token, str, len, NULL, 0);
5011 	if (ret < 0) {
5012 		pop_args(ctx);
5013 		return -1;
5014 	}
5015 	if (!ctx->object)
5016 		return len;
5017 	action = &out->args.vc.actions[out->args.vc.actions_n - 1];
5018 	action_raw_decap_data = ctx->object;
5019 	idx = action_raw_decap_data->idx;
5020 	action_raw_decap_data->conf.data = raw_decap_confs[idx].data;
5021 	action_raw_decap_data->conf.size = raw_decap_confs[idx].size;
5022 	action->conf = &action_raw_decap_data->conf;
5023 	return len;
5024 }
5025 
5026 
5027 static int
5028 parse_vc_action_raw_encap_index(struct context *ctx, const struct token *token,
5029 				const char *str, unsigned int len, void *buf,
5030 				unsigned int size)
5031 {
5032 	struct action_raw_encap_data *action_raw_encap_data;
5033 	struct rte_flow_action *action;
5034 	const struct arg *arg;
5035 	struct buffer *out = buf;
5036 	int ret;
5037 	uint16_t idx;
5038 
5039 	RTE_SET_USED(token);
5040 	RTE_SET_USED(buf);
5041 	RTE_SET_USED(size);
5042 	if (ctx->curr != ACTION_RAW_ENCAP_INDEX_VALUE)
5043 		return -1;
5044 	arg = ARGS_ENTRY_ARB_BOUNDED
5045 		(offsetof(struct action_raw_encap_data, idx),
5046 		 sizeof(((struct action_raw_encap_data *)0)->idx),
5047 		 0, RAW_ENCAP_CONFS_MAX_NUM - 1);
5048 	if (push_args(ctx, arg))
5049 		return -1;
5050 	ret = parse_int(ctx, token, str, len, NULL, 0);
5051 	if (ret < 0) {
5052 		pop_args(ctx);
5053 		return -1;
5054 	}
5055 	if (!ctx->object)
5056 		return len;
5057 	action = &out->args.vc.actions[out->args.vc.actions_n - 1];
5058 	action_raw_encap_data = ctx->object;
5059 	idx = action_raw_encap_data->idx;
5060 	action_raw_encap_data->conf.data = raw_encap_confs[idx].data;
5061 	action_raw_encap_data->conf.size = raw_encap_confs[idx].size;
5062 	action_raw_encap_data->conf.preserve = NULL;
5063 	action->conf = &action_raw_encap_data->conf;
5064 	return len;
5065 }
5066 
5067 static int
5068 parse_vc_action_raw_encap(struct context *ctx, const struct token *token,
5069 			  const char *str, unsigned int len, void *buf,
5070 			  unsigned int size)
5071 {
5072 	struct buffer *out = buf;
5073 	struct rte_flow_action *action;
5074 	struct action_raw_encap_data *action_raw_encap_data = NULL;
5075 	int ret;
5076 
5077 	ret = parse_vc(ctx, token, str, len, buf, size);
5078 	if (ret < 0)
5079 		return ret;
5080 	/* Nothing else to do if there is no buffer. */
5081 	if (!out)
5082 		return ret;
5083 	if (!out->args.vc.actions_n)
5084 		return -1;
5085 	action = &out->args.vc.actions[out->args.vc.actions_n - 1];
5086 	/* Point to selected object. */
5087 	ctx->object = out->args.vc.data;
5088 	ctx->objmask = NULL;
5089 	/* Copy the headers to the buffer. */
5090 	action_raw_encap_data = ctx->object;
5091 	action_raw_encap_data->conf.data = raw_encap_confs[0].data;
5092 	action_raw_encap_data->conf.preserve = NULL;
5093 	action_raw_encap_data->conf.size = raw_encap_confs[0].size;
5094 	action->conf = &action_raw_encap_data->conf;
5095 	return ret;
5096 }
5097 
5098 static int
5099 parse_vc_action_raw_decap(struct context *ctx, const struct token *token,
5100 			  const char *str, unsigned int len, void *buf,
5101 			  unsigned int size)
5102 {
5103 	struct buffer *out = buf;
5104 	struct rte_flow_action *action;
5105 	struct action_raw_decap_data *action_raw_decap_data = NULL;
5106 	int ret;
5107 
5108 	ret = parse_vc(ctx, token, str, len, buf, size);
5109 	if (ret < 0)
5110 		return ret;
5111 	/* Nothing else to do if there is no buffer. */
5112 	if (!out)
5113 		return ret;
5114 	if (!out->args.vc.actions_n)
5115 		return -1;
5116 	action = &out->args.vc.actions[out->args.vc.actions_n - 1];
5117 	/* Point to selected object. */
5118 	ctx->object = out->args.vc.data;
5119 	ctx->objmask = NULL;
5120 	/* Copy the headers to the buffer. */
5121 	action_raw_decap_data = ctx->object;
5122 	action_raw_decap_data->conf.data = raw_decap_confs[0].data;
5123 	action_raw_decap_data->conf.size = raw_decap_confs[0].size;
5124 	action->conf = &action_raw_decap_data->conf;
5125 	return ret;
5126 }
5127 
5128 static int
5129 parse_vc_action_set_meta(struct context *ctx, const struct token *token,
5130 			 const char *str, unsigned int len, void *buf,
5131 			 unsigned int size)
5132 {
5133 	int ret;
5134 
5135 	ret = parse_vc(ctx, token, str, len, buf, size);
5136 	if (ret < 0)
5137 		return ret;
5138 	ret = rte_flow_dynf_metadata_register();
5139 	if (ret < 0)
5140 		return -1;
5141 	return len;
5142 }
5143 
5144 /** Parse tokens for destroy command. */
5145 static int
5146 parse_destroy(struct context *ctx, const struct token *token,
5147 	      const char *str, unsigned int len,
5148 	      void *buf, unsigned int size)
5149 {
5150 	struct buffer *out = buf;
5151 
5152 	/* Token name must match. */
5153 	if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5154 		return -1;
5155 	/* Nothing else to do if there is no buffer. */
5156 	if (!out)
5157 		return len;
5158 	if (!out->command) {
5159 		if (ctx->curr != DESTROY)
5160 			return -1;
5161 		if (sizeof(*out) > size)
5162 			return -1;
5163 		out->command = ctx->curr;
5164 		ctx->objdata = 0;
5165 		ctx->object = out;
5166 		ctx->objmask = NULL;
5167 		out->args.destroy.rule =
5168 			(void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
5169 					       sizeof(double));
5170 		return len;
5171 	}
5172 	if (((uint8_t *)(out->args.destroy.rule + out->args.destroy.rule_n) +
5173 	     sizeof(*out->args.destroy.rule)) > (uint8_t *)out + size)
5174 		return -1;
5175 	ctx->objdata = 0;
5176 	ctx->object = out->args.destroy.rule + out->args.destroy.rule_n++;
5177 	ctx->objmask = NULL;
5178 	return len;
5179 }
5180 
5181 /** Parse tokens for flush command. */
5182 static int
5183 parse_flush(struct context *ctx, const struct token *token,
5184 	    const char *str, unsigned int len,
5185 	    void *buf, unsigned int size)
5186 {
5187 	struct buffer *out = buf;
5188 
5189 	/* Token name must match. */
5190 	if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5191 		return -1;
5192 	/* Nothing else to do if there is no buffer. */
5193 	if (!out)
5194 		return len;
5195 	if (!out->command) {
5196 		if (ctx->curr != FLUSH)
5197 			return -1;
5198 		if (sizeof(*out) > size)
5199 			return -1;
5200 		out->command = ctx->curr;
5201 		ctx->objdata = 0;
5202 		ctx->object = out;
5203 		ctx->objmask = NULL;
5204 	}
5205 	return len;
5206 }
5207 
5208 /** Parse tokens for dump command. */
5209 static int
5210 parse_dump(struct context *ctx, const struct token *token,
5211 	    const char *str, unsigned int len,
5212 	    void *buf, unsigned int size)
5213 {
5214 	struct buffer *out = buf;
5215 
5216 	/* Token name must match. */
5217 	if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5218 		return -1;
5219 	/* Nothing else to do if there is no buffer. */
5220 	if (!out)
5221 		return len;
5222 	if (!out->command) {
5223 		if (ctx->curr != DUMP)
5224 			return -1;
5225 		if (sizeof(*out) > size)
5226 			return -1;
5227 		out->command = ctx->curr;
5228 		ctx->objdata = 0;
5229 		ctx->object = out;
5230 		ctx->objmask = NULL;
5231 	}
5232 	return len;
5233 }
5234 
5235 /** Parse tokens for query command. */
5236 static int
5237 parse_query(struct context *ctx, const struct token *token,
5238 	    const char *str, unsigned int len,
5239 	    void *buf, unsigned int size)
5240 {
5241 	struct buffer *out = buf;
5242 
5243 	/* Token name must match. */
5244 	if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5245 		return -1;
5246 	/* Nothing else to do if there is no buffer. */
5247 	if (!out)
5248 		return len;
5249 	if (!out->command) {
5250 		if (ctx->curr != QUERY)
5251 			return -1;
5252 		if (sizeof(*out) > size)
5253 			return -1;
5254 		out->command = ctx->curr;
5255 		ctx->objdata = 0;
5256 		ctx->object = out;
5257 		ctx->objmask = NULL;
5258 	}
5259 	return len;
5260 }
5261 
5262 /** Parse action names. */
5263 static int
5264 parse_action(struct context *ctx, const struct token *token,
5265 	     const char *str, unsigned int len,
5266 	     void *buf, unsigned int size)
5267 {
5268 	struct buffer *out = buf;
5269 	const struct arg *arg = pop_args(ctx);
5270 	unsigned int i;
5271 
5272 	(void)size;
5273 	/* Argument is expected. */
5274 	if (!arg)
5275 		return -1;
5276 	/* Parse action name. */
5277 	for (i = 0; next_action[i]; ++i) {
5278 		const struct parse_action_priv *priv;
5279 
5280 		token = &token_list[next_action[i]];
5281 		if (strcmp_partial(token->name, str, len))
5282 			continue;
5283 		priv = token->priv;
5284 		if (!priv)
5285 			goto error;
5286 		if (out)
5287 			memcpy((uint8_t *)ctx->object + arg->offset,
5288 			       &priv->type,
5289 			       arg->size);
5290 		return len;
5291 	}
5292 error:
5293 	push_args(ctx, arg);
5294 	return -1;
5295 }
5296 
5297 /** Parse tokens for list command. */
5298 static int
5299 parse_list(struct context *ctx, const struct token *token,
5300 	   const char *str, unsigned int len,
5301 	   void *buf, unsigned int size)
5302 {
5303 	struct buffer *out = buf;
5304 
5305 	/* Token name must match. */
5306 	if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5307 		return -1;
5308 	/* Nothing else to do if there is no buffer. */
5309 	if (!out)
5310 		return len;
5311 	if (!out->command) {
5312 		if (ctx->curr != LIST)
5313 			return -1;
5314 		if (sizeof(*out) > size)
5315 			return -1;
5316 		out->command = ctx->curr;
5317 		ctx->objdata = 0;
5318 		ctx->object = out;
5319 		ctx->objmask = NULL;
5320 		out->args.list.group =
5321 			(void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
5322 					       sizeof(double));
5323 		return len;
5324 	}
5325 	if (((uint8_t *)(out->args.list.group + out->args.list.group_n) +
5326 	     sizeof(*out->args.list.group)) > (uint8_t *)out + size)
5327 		return -1;
5328 	ctx->objdata = 0;
5329 	ctx->object = out->args.list.group + out->args.list.group_n++;
5330 	ctx->objmask = NULL;
5331 	return len;
5332 }
5333 
5334 /** Parse tokens for isolate command. */
5335 static int
5336 parse_isolate(struct context *ctx, const struct token *token,
5337 	      const char *str, unsigned int len,
5338 	      void *buf, unsigned int size)
5339 {
5340 	struct buffer *out = buf;
5341 
5342 	/* Token name must match. */
5343 	if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5344 		return -1;
5345 	/* Nothing else to do if there is no buffer. */
5346 	if (!out)
5347 		return len;
5348 	if (!out->command) {
5349 		if (ctx->curr != ISOLATE)
5350 			return -1;
5351 		if (sizeof(*out) > size)
5352 			return -1;
5353 		out->command = ctx->curr;
5354 		ctx->objdata = 0;
5355 		ctx->object = out;
5356 		ctx->objmask = NULL;
5357 	}
5358 	return len;
5359 }
5360 
5361 /**
5362  * Parse signed/unsigned integers 8 to 64-bit long.
5363  *
5364  * Last argument (ctx->args) is retrieved to determine integer type and
5365  * storage location.
5366  */
5367 static int
5368 parse_int(struct context *ctx, const struct token *token,
5369 	  const char *str, unsigned int len,
5370 	  void *buf, unsigned int size)
5371 {
5372 	const struct arg *arg = pop_args(ctx);
5373 	uintmax_t u;
5374 	char *end;
5375 
5376 	(void)token;
5377 	/* Argument is expected. */
5378 	if (!arg)
5379 		return -1;
5380 	errno = 0;
5381 	u = arg->sign ?
5382 		(uintmax_t)strtoimax(str, &end, 0) :
5383 		strtoumax(str, &end, 0);
5384 	if (errno || (size_t)(end - str) != len)
5385 		goto error;
5386 	if (arg->bounded &&
5387 	    ((arg->sign && ((intmax_t)u < (intmax_t)arg->min ||
5388 			    (intmax_t)u > (intmax_t)arg->max)) ||
5389 	     (!arg->sign && (u < arg->min || u > arg->max))))
5390 		goto error;
5391 	if (!ctx->object)
5392 		return len;
5393 	if (arg->mask) {
5394 		if (!arg_entry_bf_fill(ctx->object, u, arg) ||
5395 		    !arg_entry_bf_fill(ctx->objmask, -1, arg))
5396 			goto error;
5397 		return len;
5398 	}
5399 	buf = (uint8_t *)ctx->object + arg->offset;
5400 	size = arg->size;
5401 	if (u > RTE_LEN2MASK(size * CHAR_BIT, uint64_t))
5402 		return -1;
5403 objmask:
5404 	switch (size) {
5405 	case sizeof(uint8_t):
5406 		*(uint8_t *)buf = u;
5407 		break;
5408 	case sizeof(uint16_t):
5409 		*(uint16_t *)buf = arg->hton ? rte_cpu_to_be_16(u) : u;
5410 		break;
5411 	case sizeof(uint8_t [3]):
5412 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
5413 		if (!arg->hton) {
5414 			((uint8_t *)buf)[0] = u;
5415 			((uint8_t *)buf)[1] = u >> 8;
5416 			((uint8_t *)buf)[2] = u >> 16;
5417 			break;
5418 		}
5419 #endif
5420 		((uint8_t *)buf)[0] = u >> 16;
5421 		((uint8_t *)buf)[1] = u >> 8;
5422 		((uint8_t *)buf)[2] = u;
5423 		break;
5424 	case sizeof(uint32_t):
5425 		*(uint32_t *)buf = arg->hton ? rte_cpu_to_be_32(u) : u;
5426 		break;
5427 	case sizeof(uint64_t):
5428 		*(uint64_t *)buf = arg->hton ? rte_cpu_to_be_64(u) : u;
5429 		break;
5430 	default:
5431 		goto error;
5432 	}
5433 	if (ctx->objmask && buf != (uint8_t *)ctx->objmask + arg->offset) {
5434 		u = -1;
5435 		buf = (uint8_t *)ctx->objmask + arg->offset;
5436 		goto objmask;
5437 	}
5438 	return len;
5439 error:
5440 	push_args(ctx, arg);
5441 	return -1;
5442 }
5443 
5444 /**
5445  * Parse a string.
5446  *
5447  * Three arguments (ctx->args) are retrieved from the stack to store data,
5448  * its actual length and address (in that order).
5449  */
5450 static int
5451 parse_string(struct context *ctx, const struct token *token,
5452 	     const char *str, unsigned int len,
5453 	     void *buf, unsigned int size)
5454 {
5455 	const struct arg *arg_data = pop_args(ctx);
5456 	const struct arg *arg_len = pop_args(ctx);
5457 	const struct arg *arg_addr = pop_args(ctx);
5458 	char tmp[16]; /* Ought to be enough. */
5459 	int ret;
5460 
5461 	/* Arguments are expected. */
5462 	if (!arg_data)
5463 		return -1;
5464 	if (!arg_len) {
5465 		push_args(ctx, arg_data);
5466 		return -1;
5467 	}
5468 	if (!arg_addr) {
5469 		push_args(ctx, arg_len);
5470 		push_args(ctx, arg_data);
5471 		return -1;
5472 	}
5473 	size = arg_data->size;
5474 	/* Bit-mask fill is not supported. */
5475 	if (arg_data->mask || size < len)
5476 		goto error;
5477 	if (!ctx->object)
5478 		return len;
5479 	/* Let parse_int() fill length information first. */
5480 	ret = snprintf(tmp, sizeof(tmp), "%u", len);
5481 	if (ret < 0)
5482 		goto error;
5483 	push_args(ctx, arg_len);
5484 	ret = parse_int(ctx, token, tmp, ret, NULL, 0);
5485 	if (ret < 0) {
5486 		pop_args(ctx);
5487 		goto error;
5488 	}
5489 	buf = (uint8_t *)ctx->object + arg_data->offset;
5490 	/* Output buffer is not necessarily NUL-terminated. */
5491 	memcpy(buf, str, len);
5492 	memset((uint8_t *)buf + len, 0x00, size - len);
5493 	if (ctx->objmask)
5494 		memset((uint8_t *)ctx->objmask + arg_data->offset, 0xff, len);
5495 	/* Save address if requested. */
5496 	if (arg_addr->size) {
5497 		memcpy((uint8_t *)ctx->object + arg_addr->offset,
5498 		       (void *[]){
5499 			(uint8_t *)ctx->object + arg_data->offset
5500 		       },
5501 		       arg_addr->size);
5502 		if (ctx->objmask)
5503 			memcpy((uint8_t *)ctx->objmask + arg_addr->offset,
5504 			       (void *[]){
5505 				(uint8_t *)ctx->objmask + arg_data->offset
5506 			       },
5507 			       arg_addr->size);
5508 	}
5509 	return len;
5510 error:
5511 	push_args(ctx, arg_addr);
5512 	push_args(ctx, arg_len);
5513 	push_args(ctx, arg_data);
5514 	return -1;
5515 }
5516 
5517 static int
5518 parse_hex_string(const char *src, uint8_t *dst, uint32_t *size)
5519 {
5520 	char *c = NULL;
5521 	uint32_t i, len;
5522 	char tmp[3];
5523 
5524 	/* Check input parameters */
5525 	if ((src == NULL) ||
5526 		(dst == NULL) ||
5527 		(size == NULL) ||
5528 		(*size == 0))
5529 		return -1;
5530 
5531 	/* Convert chars to bytes */
5532 	for (i = 0, len = 0; i < *size; i += 2) {
5533 		snprintf(tmp, 3, "%s", src + i);
5534 		dst[len++] = strtoul(tmp, &c, 16);
5535 		if (*c != 0) {
5536 			len--;
5537 			dst[len] = 0;
5538 			*size = len;
5539 			return -1;
5540 		}
5541 	}
5542 	dst[len] = 0;
5543 	*size = len;
5544 
5545 	return 0;
5546 }
5547 
5548 static int
5549 parse_hex(struct context *ctx, const struct token *token,
5550 		const char *str, unsigned int len,
5551 		void *buf, unsigned int size)
5552 {
5553 	const struct arg *arg_data = pop_args(ctx);
5554 	const struct arg *arg_len = pop_args(ctx);
5555 	const struct arg *arg_addr = pop_args(ctx);
5556 	char tmp[16]; /* Ought to be enough. */
5557 	int ret;
5558 	unsigned int hexlen = len;
5559 	unsigned int length = 256;
5560 	uint8_t hex_tmp[length];
5561 
5562 	/* Arguments are expected. */
5563 	if (!arg_data)
5564 		return -1;
5565 	if (!arg_len) {
5566 		push_args(ctx, arg_data);
5567 		return -1;
5568 	}
5569 	if (!arg_addr) {
5570 		push_args(ctx, arg_len);
5571 		push_args(ctx, arg_data);
5572 		return -1;
5573 	}
5574 	size = arg_data->size;
5575 	/* Bit-mask fill is not supported. */
5576 	if (arg_data->mask)
5577 		goto error;
5578 	if (!ctx->object)
5579 		return len;
5580 
5581 	/* translate bytes string to array. */
5582 	if (str[0] == '0' && ((str[1] == 'x') ||
5583 			(str[1] == 'X'))) {
5584 		str += 2;
5585 		hexlen -= 2;
5586 	}
5587 	if (hexlen > length)
5588 		return -1;
5589 	ret = parse_hex_string(str, hex_tmp, &hexlen);
5590 	if (ret < 0)
5591 		goto error;
5592 	/* Let parse_int() fill length information first. */
5593 	ret = snprintf(tmp, sizeof(tmp), "%u", hexlen);
5594 	if (ret < 0)
5595 		goto error;
5596 	push_args(ctx, arg_len);
5597 	ret = parse_int(ctx, token, tmp, ret, NULL, 0);
5598 	if (ret < 0) {
5599 		pop_args(ctx);
5600 		goto error;
5601 	}
5602 	buf = (uint8_t *)ctx->object + arg_data->offset;
5603 	/* Output buffer is not necessarily NUL-terminated. */
5604 	memcpy(buf, hex_tmp, hexlen);
5605 	memset((uint8_t *)buf + hexlen, 0x00, size - hexlen);
5606 	if (ctx->objmask)
5607 		memset((uint8_t *)ctx->objmask + arg_data->offset,
5608 					0xff, hexlen);
5609 	/* Save address if requested. */
5610 	if (arg_addr->size) {
5611 		memcpy((uint8_t *)ctx->object + arg_addr->offset,
5612 		       (void *[]){
5613 			(uint8_t *)ctx->object + arg_data->offset
5614 		       },
5615 		       arg_addr->size);
5616 		if (ctx->objmask)
5617 			memcpy((uint8_t *)ctx->objmask + arg_addr->offset,
5618 			       (void *[]){
5619 				(uint8_t *)ctx->objmask + arg_data->offset
5620 			       },
5621 			       arg_addr->size);
5622 	}
5623 	return len;
5624 error:
5625 	push_args(ctx, arg_addr);
5626 	push_args(ctx, arg_len);
5627 	push_args(ctx, arg_data);
5628 	return -1;
5629 
5630 }
5631 
5632 /**
5633  * Parse a zero-ended string.
5634  */
5635 static int
5636 parse_string0(struct context *ctx, const struct token *token __rte_unused,
5637 	     const char *str, unsigned int len,
5638 	     void *buf, unsigned int size)
5639 {
5640 	const struct arg *arg_data = pop_args(ctx);
5641 
5642 	/* Arguments are expected. */
5643 	if (!arg_data)
5644 		return -1;
5645 	size = arg_data->size;
5646 	/* Bit-mask fill is not supported. */
5647 	if (arg_data->mask || size < len + 1)
5648 		goto error;
5649 	if (!ctx->object)
5650 		return len;
5651 	buf = (uint8_t *)ctx->object + arg_data->offset;
5652 	strncpy(buf, str, len);
5653 	if (ctx->objmask)
5654 		memset((uint8_t *)ctx->objmask + arg_data->offset, 0xff, len);
5655 	return len;
5656 error:
5657 	push_args(ctx, arg_data);
5658 	return -1;
5659 }
5660 
5661 /**
5662  * Parse a MAC address.
5663  *
5664  * Last argument (ctx->args) is retrieved to determine storage size and
5665  * location.
5666  */
5667 static int
5668 parse_mac_addr(struct context *ctx, const struct token *token,
5669 	       const char *str, unsigned int len,
5670 	       void *buf, unsigned int size)
5671 {
5672 	const struct arg *arg = pop_args(ctx);
5673 	struct rte_ether_addr tmp;
5674 	int ret;
5675 
5676 	(void)token;
5677 	/* Argument is expected. */
5678 	if (!arg)
5679 		return -1;
5680 	size = arg->size;
5681 	/* Bit-mask fill is not supported. */
5682 	if (arg->mask || size != sizeof(tmp))
5683 		goto error;
5684 	/* Only network endian is supported. */
5685 	if (!arg->hton)
5686 		goto error;
5687 	ret = cmdline_parse_etheraddr(NULL, str, &tmp, size);
5688 	if (ret < 0 || (unsigned int)ret != len)
5689 		goto error;
5690 	if (!ctx->object)
5691 		return len;
5692 	buf = (uint8_t *)ctx->object + arg->offset;
5693 	memcpy(buf, &tmp, size);
5694 	if (ctx->objmask)
5695 		memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
5696 	return len;
5697 error:
5698 	push_args(ctx, arg);
5699 	return -1;
5700 }
5701 
5702 /**
5703  * Parse an IPv4 address.
5704  *
5705  * Last argument (ctx->args) is retrieved to determine storage size and
5706  * location.
5707  */
5708 static int
5709 parse_ipv4_addr(struct context *ctx, const struct token *token,
5710 		const char *str, unsigned int len,
5711 		void *buf, unsigned int size)
5712 {
5713 	const struct arg *arg = pop_args(ctx);
5714 	char str2[len + 1];
5715 	struct in_addr tmp;
5716 	int ret;
5717 
5718 	/* Argument is expected. */
5719 	if (!arg)
5720 		return -1;
5721 	size = arg->size;
5722 	/* Bit-mask fill is not supported. */
5723 	if (arg->mask || size != sizeof(tmp))
5724 		goto error;
5725 	/* Only network endian is supported. */
5726 	if (!arg->hton)
5727 		goto error;
5728 	memcpy(str2, str, len);
5729 	str2[len] = '\0';
5730 	ret = inet_pton(AF_INET, str2, &tmp);
5731 	if (ret != 1) {
5732 		/* Attempt integer parsing. */
5733 		push_args(ctx, arg);
5734 		return parse_int(ctx, token, str, len, buf, size);
5735 	}
5736 	if (!ctx->object)
5737 		return len;
5738 	buf = (uint8_t *)ctx->object + arg->offset;
5739 	memcpy(buf, &tmp, size);
5740 	if (ctx->objmask)
5741 		memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
5742 	return len;
5743 error:
5744 	push_args(ctx, arg);
5745 	return -1;
5746 }
5747 
5748 /**
5749  * Parse an IPv6 address.
5750  *
5751  * Last argument (ctx->args) is retrieved to determine storage size and
5752  * location.
5753  */
5754 static int
5755 parse_ipv6_addr(struct context *ctx, const struct token *token,
5756 		const char *str, unsigned int len,
5757 		void *buf, unsigned int size)
5758 {
5759 	const struct arg *arg = pop_args(ctx);
5760 	char str2[len + 1];
5761 	struct in6_addr tmp;
5762 	int ret;
5763 
5764 	(void)token;
5765 	/* Argument is expected. */
5766 	if (!arg)
5767 		return -1;
5768 	size = arg->size;
5769 	/* Bit-mask fill is not supported. */
5770 	if (arg->mask || size != sizeof(tmp))
5771 		goto error;
5772 	/* Only network endian is supported. */
5773 	if (!arg->hton)
5774 		goto error;
5775 	memcpy(str2, str, len);
5776 	str2[len] = '\0';
5777 	ret = inet_pton(AF_INET6, str2, &tmp);
5778 	if (ret != 1)
5779 		goto error;
5780 	if (!ctx->object)
5781 		return len;
5782 	buf = (uint8_t *)ctx->object + arg->offset;
5783 	memcpy(buf, &tmp, size);
5784 	if (ctx->objmask)
5785 		memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
5786 	return len;
5787 error:
5788 	push_args(ctx, arg);
5789 	return -1;
5790 }
5791 
5792 /** Boolean values (even indices stand for false). */
5793 static const char *const boolean_name[] = {
5794 	"0", "1",
5795 	"false", "true",
5796 	"no", "yes",
5797 	"N", "Y",
5798 	"off", "on",
5799 	NULL,
5800 };
5801 
5802 /**
5803  * Parse a boolean value.
5804  *
5805  * Last argument (ctx->args) is retrieved to determine storage size and
5806  * location.
5807  */
5808 static int
5809 parse_boolean(struct context *ctx, const struct token *token,
5810 	      const char *str, unsigned int len,
5811 	      void *buf, unsigned int size)
5812 {
5813 	const struct arg *arg = pop_args(ctx);
5814 	unsigned int i;
5815 	int ret;
5816 
5817 	/* Argument is expected. */
5818 	if (!arg)
5819 		return -1;
5820 	for (i = 0; boolean_name[i]; ++i)
5821 		if (!strcmp_partial(boolean_name[i], str, len))
5822 			break;
5823 	/* Process token as integer. */
5824 	if (boolean_name[i])
5825 		str = i & 1 ? "1" : "0";
5826 	push_args(ctx, arg);
5827 	ret = parse_int(ctx, token, str, strlen(str), buf, size);
5828 	return ret > 0 ? (int)len : ret;
5829 }
5830 
5831 /** Parse port and update context. */
5832 static int
5833 parse_port(struct context *ctx, const struct token *token,
5834 	   const char *str, unsigned int len,
5835 	   void *buf, unsigned int size)
5836 {
5837 	struct buffer *out = &(struct buffer){ .port = 0 };
5838 	int ret;
5839 
5840 	if (buf)
5841 		out = buf;
5842 	else {
5843 		ctx->objdata = 0;
5844 		ctx->object = out;
5845 		ctx->objmask = NULL;
5846 		size = sizeof(*out);
5847 	}
5848 	ret = parse_int(ctx, token, str, len, out, size);
5849 	if (ret >= 0)
5850 		ctx->port = out->port;
5851 	if (!buf)
5852 		ctx->object = NULL;
5853 	return ret;
5854 }
5855 
5856 /** Parse set command, initialize output buffer for subsequent tokens. */
5857 static int
5858 parse_set_raw_encap_decap(struct context *ctx, const struct token *token,
5859 			  const char *str, unsigned int len,
5860 			  void *buf, unsigned int size)
5861 {
5862 	struct buffer *out = buf;
5863 
5864 	/* Token name must match. */
5865 	if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5866 		return -1;
5867 	/* Nothing else to do if there is no buffer. */
5868 	if (!out)
5869 		return len;
5870 	/* Make sure buffer is large enough. */
5871 	if (size < sizeof(*out))
5872 		return -1;
5873 	ctx->objdata = 0;
5874 	ctx->objmask = NULL;
5875 	ctx->object = out;
5876 	if (!out->command)
5877 		return -1;
5878 	out->command = ctx->curr;
5879 	return len;
5880 }
5881 
5882 /**
5883  * Parse set raw_encap/raw_decap command,
5884  * initialize output buffer for subsequent tokens.
5885  */
5886 static int
5887 parse_set_init(struct context *ctx, const struct token *token,
5888 	       const char *str, unsigned int len,
5889 	       void *buf, unsigned int size)
5890 {
5891 	struct buffer *out = buf;
5892 
5893 	/* Token name must match. */
5894 	if (parse_default(ctx, token, str, len, NULL, 0) < 0)
5895 		return -1;
5896 	/* Nothing else to do if there is no buffer. */
5897 	if (!out)
5898 		return len;
5899 	/* Make sure buffer is large enough. */
5900 	if (size < sizeof(*out))
5901 		return -1;
5902 	/* Initialize buffer. */
5903 	memset(out, 0x00, sizeof(*out));
5904 	memset((uint8_t *)out + sizeof(*out), 0x22, size - sizeof(*out));
5905 	ctx->objdata = 0;
5906 	ctx->object = out;
5907 	ctx->objmask = NULL;
5908 	if (!out->command) {
5909 		if (ctx->curr != SET)
5910 			return -1;
5911 		if (sizeof(*out) > size)
5912 			return -1;
5913 		out->command = ctx->curr;
5914 		out->args.vc.data = (uint8_t *)out + size;
5915 		/* All we need is pattern */
5916 		out->args.vc.pattern =
5917 			(void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
5918 					       sizeof(double));
5919 		ctx->object = out->args.vc.pattern;
5920 	}
5921 	return len;
5922 }
5923 
5924 /** No completion. */
5925 static int
5926 comp_none(struct context *ctx, const struct token *token,
5927 	  unsigned int ent, char *buf, unsigned int size)
5928 {
5929 	(void)ctx;
5930 	(void)token;
5931 	(void)ent;
5932 	(void)buf;
5933 	(void)size;
5934 	return 0;
5935 }
5936 
5937 /** Complete boolean values. */
5938 static int
5939 comp_boolean(struct context *ctx, const struct token *token,
5940 	     unsigned int ent, char *buf, unsigned int size)
5941 {
5942 	unsigned int i;
5943 
5944 	(void)ctx;
5945 	(void)token;
5946 	for (i = 0; boolean_name[i]; ++i)
5947 		if (buf && i == ent)
5948 			return strlcpy(buf, boolean_name[i], size);
5949 	if (buf)
5950 		return -1;
5951 	return i;
5952 }
5953 
5954 /** Complete action names. */
5955 static int
5956 comp_action(struct context *ctx, const struct token *token,
5957 	    unsigned int ent, char *buf, unsigned int size)
5958 {
5959 	unsigned int i;
5960 
5961 	(void)ctx;
5962 	(void)token;
5963 	for (i = 0; next_action[i]; ++i)
5964 		if (buf && i == ent)
5965 			return strlcpy(buf, token_list[next_action[i]].name,
5966 				       size);
5967 	if (buf)
5968 		return -1;
5969 	return i;
5970 }
5971 
5972 /** Complete available ports. */
5973 static int
5974 comp_port(struct context *ctx, const struct token *token,
5975 	  unsigned int ent, char *buf, unsigned int size)
5976 {
5977 	unsigned int i = 0;
5978 	portid_t p;
5979 
5980 	(void)ctx;
5981 	(void)token;
5982 	RTE_ETH_FOREACH_DEV(p) {
5983 		if (buf && i == ent)
5984 			return snprintf(buf, size, "%u", p);
5985 		++i;
5986 	}
5987 	if (buf)
5988 		return -1;
5989 	return i;
5990 }
5991 
5992 /** Complete available rule IDs. */
5993 static int
5994 comp_rule_id(struct context *ctx, const struct token *token,
5995 	     unsigned int ent, char *buf, unsigned int size)
5996 {
5997 	unsigned int i = 0;
5998 	struct rte_port *port;
5999 	struct port_flow *pf;
6000 
6001 	(void)token;
6002 	if (port_id_is_invalid(ctx->port, DISABLED_WARN) ||
6003 	    ctx->port == (portid_t)RTE_PORT_ALL)
6004 		return -1;
6005 	port = &ports[ctx->port];
6006 	for (pf = port->flow_list; pf != NULL; pf = pf->next) {
6007 		if (buf && i == ent)
6008 			return snprintf(buf, size, "%u", pf->id);
6009 		++i;
6010 	}
6011 	if (buf)
6012 		return -1;
6013 	return i;
6014 }
6015 
6016 /** Complete type field for RSS action. */
6017 static int
6018 comp_vc_action_rss_type(struct context *ctx, const struct token *token,
6019 			unsigned int ent, char *buf, unsigned int size)
6020 {
6021 	unsigned int i;
6022 
6023 	(void)ctx;
6024 	(void)token;
6025 	for (i = 0; rss_type_table[i].str; ++i)
6026 		;
6027 	if (!buf)
6028 		return i + 1;
6029 	if (ent < i)
6030 		return strlcpy(buf, rss_type_table[ent].str, size);
6031 	if (ent == i)
6032 		return snprintf(buf, size, "end");
6033 	return -1;
6034 }
6035 
6036 /** Complete queue field for RSS action. */
6037 static int
6038 comp_vc_action_rss_queue(struct context *ctx, const struct token *token,
6039 			 unsigned int ent, char *buf, unsigned int size)
6040 {
6041 	(void)ctx;
6042 	(void)token;
6043 	if (!buf)
6044 		return nb_rxq + 1;
6045 	if (ent < nb_rxq)
6046 		return snprintf(buf, size, "%u", ent);
6047 	if (ent == nb_rxq)
6048 		return snprintf(buf, size, "end");
6049 	return -1;
6050 }
6051 
6052 /** Complete index number for set raw_encap/raw_decap commands. */
6053 static int
6054 comp_set_raw_index(struct context *ctx, const struct token *token,
6055 		   unsigned int ent, char *buf, unsigned int size)
6056 {
6057 	uint16_t idx = 0;
6058 	uint16_t nb = 0;
6059 
6060 	RTE_SET_USED(ctx);
6061 	RTE_SET_USED(token);
6062 	for (idx = 0; idx < RAW_ENCAP_CONFS_MAX_NUM; ++idx) {
6063 		if (buf && idx == ent)
6064 			return snprintf(buf, size, "%u", idx);
6065 		++nb;
6066 	}
6067 	return nb;
6068 }
6069 
6070 /** Internal context. */
6071 static struct context cmd_flow_context;
6072 
6073 /** Global parser instance (cmdline API). */
6074 cmdline_parse_inst_t cmd_flow;
6075 cmdline_parse_inst_t cmd_set_raw;
6076 
6077 /** Initialize context. */
6078 static void
6079 cmd_flow_context_init(struct context *ctx)
6080 {
6081 	/* A full memset() is not necessary. */
6082 	ctx->curr = ZERO;
6083 	ctx->prev = ZERO;
6084 	ctx->next_num = 0;
6085 	ctx->args_num = 0;
6086 	ctx->eol = 0;
6087 	ctx->last = 0;
6088 	ctx->port = 0;
6089 	ctx->objdata = 0;
6090 	ctx->object = NULL;
6091 	ctx->objmask = NULL;
6092 }
6093 
6094 /** Parse a token (cmdline API). */
6095 static int
6096 cmd_flow_parse(cmdline_parse_token_hdr_t *hdr, const char *src, void *result,
6097 	       unsigned int size)
6098 {
6099 	struct context *ctx = &cmd_flow_context;
6100 	const struct token *token;
6101 	const enum index *list;
6102 	int len;
6103 	int i;
6104 
6105 	(void)hdr;
6106 	token = &token_list[ctx->curr];
6107 	/* Check argument length. */
6108 	ctx->eol = 0;
6109 	ctx->last = 1;
6110 	for (len = 0; src[len]; ++len)
6111 		if (src[len] == '#' || isspace(src[len]))
6112 			break;
6113 	if (!len)
6114 		return -1;
6115 	/* Last argument and EOL detection. */
6116 	for (i = len; src[i]; ++i)
6117 		if (src[i] == '#' || src[i] == '\r' || src[i] == '\n')
6118 			break;
6119 		else if (!isspace(src[i])) {
6120 			ctx->last = 0;
6121 			break;
6122 		}
6123 	for (; src[i]; ++i)
6124 		if (src[i] == '\r' || src[i] == '\n') {
6125 			ctx->eol = 1;
6126 			break;
6127 		}
6128 	/* Initialize context if necessary. */
6129 	if (!ctx->next_num) {
6130 		if (!token->next)
6131 			return 0;
6132 		ctx->next[ctx->next_num++] = token->next[0];
6133 	}
6134 	/* Process argument through candidates. */
6135 	ctx->prev = ctx->curr;
6136 	list = ctx->next[ctx->next_num - 1];
6137 	for (i = 0; list[i]; ++i) {
6138 		const struct token *next = &token_list[list[i]];
6139 		int tmp;
6140 
6141 		ctx->curr = list[i];
6142 		if (next->call)
6143 			tmp = next->call(ctx, next, src, len, result, size);
6144 		else
6145 			tmp = parse_default(ctx, next, src, len, result, size);
6146 		if (tmp == -1 || tmp != len)
6147 			continue;
6148 		token = next;
6149 		break;
6150 	}
6151 	if (!list[i])
6152 		return -1;
6153 	--ctx->next_num;
6154 	/* Push subsequent tokens if any. */
6155 	if (token->next)
6156 		for (i = 0; token->next[i]; ++i) {
6157 			if (ctx->next_num == RTE_DIM(ctx->next))
6158 				return -1;
6159 			ctx->next[ctx->next_num++] = token->next[i];
6160 		}
6161 	/* Push arguments if any. */
6162 	if (token->args)
6163 		for (i = 0; token->args[i]; ++i) {
6164 			if (ctx->args_num == RTE_DIM(ctx->args))
6165 				return -1;
6166 			ctx->args[ctx->args_num++] = token->args[i];
6167 		}
6168 	return len;
6169 }
6170 
6171 /** Return number of completion entries (cmdline API). */
6172 static int
6173 cmd_flow_complete_get_nb(cmdline_parse_token_hdr_t *hdr)
6174 {
6175 	struct context *ctx = &cmd_flow_context;
6176 	const struct token *token = &token_list[ctx->curr];
6177 	const enum index *list;
6178 	int i;
6179 
6180 	(void)hdr;
6181 	/* Count number of tokens in current list. */
6182 	if (ctx->next_num)
6183 		list = ctx->next[ctx->next_num - 1];
6184 	else
6185 		list = token->next[0];
6186 	for (i = 0; list[i]; ++i)
6187 		;
6188 	if (!i)
6189 		return 0;
6190 	/*
6191 	 * If there is a single token, use its completion callback, otherwise
6192 	 * return the number of entries.
6193 	 */
6194 	token = &token_list[list[0]];
6195 	if (i == 1 && token->comp) {
6196 		/* Save index for cmd_flow_get_help(). */
6197 		ctx->prev = list[0];
6198 		return token->comp(ctx, token, 0, NULL, 0);
6199 	}
6200 	return i;
6201 }
6202 
6203 /** Return a completion entry (cmdline API). */
6204 static int
6205 cmd_flow_complete_get_elt(cmdline_parse_token_hdr_t *hdr, int index,
6206 			  char *dst, unsigned int size)
6207 {
6208 	struct context *ctx = &cmd_flow_context;
6209 	const struct token *token = &token_list[ctx->curr];
6210 	const enum index *list;
6211 	int i;
6212 
6213 	(void)hdr;
6214 	/* Count number of tokens in current list. */
6215 	if (ctx->next_num)
6216 		list = ctx->next[ctx->next_num - 1];
6217 	else
6218 		list = token->next[0];
6219 	for (i = 0; list[i]; ++i)
6220 		;
6221 	if (!i)
6222 		return -1;
6223 	/* If there is a single token, use its completion callback. */
6224 	token = &token_list[list[0]];
6225 	if (i == 1 && token->comp) {
6226 		/* Save index for cmd_flow_get_help(). */
6227 		ctx->prev = list[0];
6228 		return token->comp(ctx, token, index, dst, size) < 0 ? -1 : 0;
6229 	}
6230 	/* Otherwise make sure the index is valid and use defaults. */
6231 	if (index >= i)
6232 		return -1;
6233 	token = &token_list[list[index]];
6234 	strlcpy(dst, token->name, size);
6235 	/* Save index for cmd_flow_get_help(). */
6236 	ctx->prev = list[index];
6237 	return 0;
6238 }
6239 
6240 /** Populate help strings for current token (cmdline API). */
6241 static int
6242 cmd_flow_get_help(cmdline_parse_token_hdr_t *hdr, char *dst, unsigned int size)
6243 {
6244 	struct context *ctx = &cmd_flow_context;
6245 	const struct token *token = &token_list[ctx->prev];
6246 
6247 	(void)hdr;
6248 	if (!size)
6249 		return -1;
6250 	/* Set token type and update global help with details. */
6251 	strlcpy(dst, (token->type ? token->type : "TOKEN"), size);
6252 	if (token->help)
6253 		cmd_flow.help_str = token->help;
6254 	else
6255 		cmd_flow.help_str = token->name;
6256 	return 0;
6257 }
6258 
6259 /** Token definition template (cmdline API). */
6260 static struct cmdline_token_hdr cmd_flow_token_hdr = {
6261 	.ops = &(struct cmdline_token_ops){
6262 		.parse = cmd_flow_parse,
6263 		.complete_get_nb = cmd_flow_complete_get_nb,
6264 		.complete_get_elt = cmd_flow_complete_get_elt,
6265 		.get_help = cmd_flow_get_help,
6266 	},
6267 	.offset = 0,
6268 };
6269 
6270 /** Populate the next dynamic token. */
6271 static void
6272 cmd_flow_tok(cmdline_parse_token_hdr_t **hdr,
6273 	     cmdline_parse_token_hdr_t **hdr_inst)
6274 {
6275 	struct context *ctx = &cmd_flow_context;
6276 
6277 	/* Always reinitialize context before requesting the first token. */
6278 	if (!(hdr_inst - cmd_flow.tokens))
6279 		cmd_flow_context_init(ctx);
6280 	/* Return NULL when no more tokens are expected. */
6281 	if (!ctx->next_num && ctx->curr) {
6282 		*hdr = NULL;
6283 		return;
6284 	}
6285 	/* Determine if command should end here. */
6286 	if (ctx->eol && ctx->last && ctx->next_num) {
6287 		const enum index *list = ctx->next[ctx->next_num - 1];
6288 		int i;
6289 
6290 		for (i = 0; list[i]; ++i) {
6291 			if (list[i] != END)
6292 				continue;
6293 			*hdr = NULL;
6294 			return;
6295 		}
6296 	}
6297 	*hdr = &cmd_flow_token_hdr;
6298 }
6299 
6300 /** Dispatch parsed buffer to function calls. */
6301 static void
6302 cmd_flow_parsed(const struct buffer *in)
6303 {
6304 	switch (in->command) {
6305 	case VALIDATE:
6306 		port_flow_validate(in->port, &in->args.vc.attr,
6307 				   in->args.vc.pattern, in->args.vc.actions);
6308 		break;
6309 	case CREATE:
6310 		port_flow_create(in->port, &in->args.vc.attr,
6311 				 in->args.vc.pattern, in->args.vc.actions);
6312 		break;
6313 	case DESTROY:
6314 		port_flow_destroy(in->port, in->args.destroy.rule_n,
6315 				  in->args.destroy.rule);
6316 		break;
6317 	case FLUSH:
6318 		port_flow_flush(in->port);
6319 		break;
6320 	case DUMP:
6321 		port_flow_dump(in->port, in->args.dump.file);
6322 		break;
6323 	case QUERY:
6324 		port_flow_query(in->port, in->args.query.rule,
6325 				&in->args.query.action);
6326 		break;
6327 	case LIST:
6328 		port_flow_list(in->port, in->args.list.group_n,
6329 			       in->args.list.group);
6330 		break;
6331 	case ISOLATE:
6332 		port_flow_isolate(in->port, in->args.isolate.set);
6333 		break;
6334 	default:
6335 		break;
6336 	}
6337 }
6338 
6339 /** Token generator and output processing callback (cmdline API). */
6340 static void
6341 cmd_flow_cb(void *arg0, struct cmdline *cl, void *arg2)
6342 {
6343 	if (cl == NULL)
6344 		cmd_flow_tok(arg0, arg2);
6345 	else
6346 		cmd_flow_parsed(arg0);
6347 }
6348 
6349 /** Global parser instance (cmdline API). */
6350 cmdline_parse_inst_t cmd_flow = {
6351 	.f = cmd_flow_cb,
6352 	.data = NULL, /**< Unused. */
6353 	.help_str = NULL, /**< Updated by cmd_flow_get_help(). */
6354 	.tokens = {
6355 		NULL,
6356 	}, /**< Tokens are returned by cmd_flow_tok(). */
6357 };
6358 
6359 /** set cmd facility. Reuse cmd flow's infrastructure as much as possible. */
6360 
6361 static void
6362 update_fields(uint8_t *buf, struct rte_flow_item *item, uint16_t next_proto)
6363 {
6364 	struct rte_flow_item_ipv4 *ipv4;
6365 	struct rte_flow_item_eth *eth;
6366 	struct rte_flow_item_ipv6 *ipv6;
6367 	struct rte_flow_item_vxlan *vxlan;
6368 	struct rte_flow_item_vxlan_gpe *gpe;
6369 	struct rte_flow_item_nvgre *nvgre;
6370 	uint32_t ipv6_vtc_flow;
6371 
6372 	switch (item->type) {
6373 	case RTE_FLOW_ITEM_TYPE_ETH:
6374 		eth = (struct rte_flow_item_eth *)buf;
6375 		if (next_proto)
6376 			eth->type = rte_cpu_to_be_16(next_proto);
6377 		break;
6378 	case RTE_FLOW_ITEM_TYPE_IPV4:
6379 		ipv4 = (struct rte_flow_item_ipv4 *)buf;
6380 		ipv4->hdr.version_ihl = 0x45;
6381 		if (next_proto && ipv4->hdr.next_proto_id == 0)
6382 			ipv4->hdr.next_proto_id = (uint8_t)next_proto;
6383 		break;
6384 	case RTE_FLOW_ITEM_TYPE_IPV6:
6385 		ipv6 = (struct rte_flow_item_ipv6 *)buf;
6386 		if (next_proto && ipv6->hdr.proto == 0)
6387 			ipv6->hdr.proto = (uint8_t)next_proto;
6388 		ipv6_vtc_flow = rte_be_to_cpu_32(ipv6->hdr.vtc_flow);
6389 		ipv6_vtc_flow &= 0x0FFFFFFF; /*< reset version bits. */
6390 		ipv6_vtc_flow |= 0x60000000; /*< set ipv6 version. */
6391 		ipv6->hdr.vtc_flow = rte_cpu_to_be_32(ipv6_vtc_flow);
6392 		break;
6393 	case RTE_FLOW_ITEM_TYPE_VXLAN:
6394 		vxlan = (struct rte_flow_item_vxlan *)buf;
6395 		vxlan->flags = 0x08;
6396 		break;
6397 	case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
6398 		gpe = (struct rte_flow_item_vxlan_gpe *)buf;
6399 		gpe->flags = 0x0C;
6400 		break;
6401 	case RTE_FLOW_ITEM_TYPE_NVGRE:
6402 		nvgre = (struct rte_flow_item_nvgre *)buf;
6403 		nvgre->protocol = rte_cpu_to_be_16(0x6558);
6404 		nvgre->c_k_s_rsvd0_ver = rte_cpu_to_be_16(0x2000);
6405 		break;
6406 	default:
6407 		break;
6408 	}
6409 }
6410 
6411 /** Helper of get item's default mask. */
6412 static const void *
6413 flow_item_default_mask(const struct rte_flow_item *item)
6414 {
6415 	const void *mask = NULL;
6416 	static rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
6417 
6418 	switch (item->type) {
6419 	case RTE_FLOW_ITEM_TYPE_ANY:
6420 		mask = &rte_flow_item_any_mask;
6421 		break;
6422 	case RTE_FLOW_ITEM_TYPE_VF:
6423 		mask = &rte_flow_item_vf_mask;
6424 		break;
6425 	case RTE_FLOW_ITEM_TYPE_PORT_ID:
6426 		mask = &rte_flow_item_port_id_mask;
6427 		break;
6428 	case RTE_FLOW_ITEM_TYPE_RAW:
6429 		mask = &rte_flow_item_raw_mask;
6430 		break;
6431 	case RTE_FLOW_ITEM_TYPE_ETH:
6432 		mask = &rte_flow_item_eth_mask;
6433 		break;
6434 	case RTE_FLOW_ITEM_TYPE_VLAN:
6435 		mask = &rte_flow_item_vlan_mask;
6436 		break;
6437 	case RTE_FLOW_ITEM_TYPE_IPV4:
6438 		mask = &rte_flow_item_ipv4_mask;
6439 		break;
6440 	case RTE_FLOW_ITEM_TYPE_IPV6:
6441 		mask = &rte_flow_item_ipv6_mask;
6442 		break;
6443 	case RTE_FLOW_ITEM_TYPE_ICMP:
6444 		mask = &rte_flow_item_icmp_mask;
6445 		break;
6446 	case RTE_FLOW_ITEM_TYPE_UDP:
6447 		mask = &rte_flow_item_udp_mask;
6448 		break;
6449 	case RTE_FLOW_ITEM_TYPE_TCP:
6450 		mask = &rte_flow_item_tcp_mask;
6451 		break;
6452 	case RTE_FLOW_ITEM_TYPE_SCTP:
6453 		mask = &rte_flow_item_sctp_mask;
6454 		break;
6455 	case RTE_FLOW_ITEM_TYPE_VXLAN:
6456 		mask = &rte_flow_item_vxlan_mask;
6457 		break;
6458 	case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
6459 		mask = &rte_flow_item_vxlan_gpe_mask;
6460 		break;
6461 	case RTE_FLOW_ITEM_TYPE_E_TAG:
6462 		mask = &rte_flow_item_e_tag_mask;
6463 		break;
6464 	case RTE_FLOW_ITEM_TYPE_NVGRE:
6465 		mask = &rte_flow_item_nvgre_mask;
6466 		break;
6467 	case RTE_FLOW_ITEM_TYPE_MPLS:
6468 		mask = &rte_flow_item_mpls_mask;
6469 		break;
6470 	case RTE_FLOW_ITEM_TYPE_GRE:
6471 		mask = &rte_flow_item_gre_mask;
6472 		break;
6473 	case RTE_FLOW_ITEM_TYPE_GRE_KEY:
6474 		mask = &gre_key_default_mask;
6475 		break;
6476 	case RTE_FLOW_ITEM_TYPE_META:
6477 		mask = &rte_flow_item_meta_mask;
6478 		break;
6479 	case RTE_FLOW_ITEM_TYPE_FUZZY:
6480 		mask = &rte_flow_item_fuzzy_mask;
6481 		break;
6482 	case RTE_FLOW_ITEM_TYPE_GTP:
6483 		mask = &rte_flow_item_gtp_mask;
6484 		break;
6485 	case RTE_FLOW_ITEM_TYPE_GTP_PSC:
6486 		mask = &rte_flow_item_gtp_psc_mask;
6487 		break;
6488 	case RTE_FLOW_ITEM_TYPE_GENEVE:
6489 		mask = &rte_flow_item_geneve_mask;
6490 		break;
6491 	case RTE_FLOW_ITEM_TYPE_PPPOE_PROTO_ID:
6492 		mask = &rte_flow_item_pppoe_proto_id_mask;
6493 		break;
6494 	case RTE_FLOW_ITEM_TYPE_L2TPV3OIP:
6495 		mask = &rte_flow_item_l2tpv3oip_mask;
6496 		break;
6497 	case RTE_FLOW_ITEM_TYPE_ESP:
6498 		mask = &rte_flow_item_esp_mask;
6499 		break;
6500 	case RTE_FLOW_ITEM_TYPE_AH:
6501 		mask = &rte_flow_item_ah_mask;
6502 		break;
6503 	case RTE_FLOW_ITEM_TYPE_PFCP:
6504 		mask = &rte_flow_item_pfcp_mask;
6505 		break;
6506 	default:
6507 		break;
6508 	}
6509 	return mask;
6510 }
6511 
6512 
6513 
6514 /** Dispatch parsed buffer to function calls. */
6515 static void
6516 cmd_set_raw_parsed(const struct buffer *in)
6517 {
6518 	uint32_t n = in->args.vc.pattern_n;
6519 	int i = 0;
6520 	struct rte_flow_item *item = NULL;
6521 	size_t size = 0;
6522 	uint8_t *data = NULL;
6523 	uint8_t *data_tail = NULL;
6524 	size_t *total_size = NULL;
6525 	uint16_t upper_layer = 0;
6526 	uint16_t proto = 0;
6527 	uint16_t idx = in->port; /* We borrow port field as index */
6528 
6529 	RTE_ASSERT(in->command == SET_RAW_ENCAP ||
6530 		   in->command == SET_RAW_DECAP);
6531 	if (in->command == SET_RAW_ENCAP) {
6532 		total_size = &raw_encap_confs[idx].size;
6533 		data = (uint8_t *)&raw_encap_confs[idx].data;
6534 	} else {
6535 		total_size = &raw_decap_confs[idx].size;
6536 		data = (uint8_t *)&raw_decap_confs[idx].data;
6537 	}
6538 	*total_size = 0;
6539 	memset(data, 0x00, ACTION_RAW_ENCAP_MAX_DATA);
6540 	/* process hdr from upper layer to low layer (L3/L4 -> L2). */
6541 	data_tail = data + ACTION_RAW_ENCAP_MAX_DATA;
6542 	for (i = n - 1 ; i >= 0; --i) {
6543 		item = in->args.vc.pattern + i;
6544 		if (item->spec == NULL)
6545 			item->spec = flow_item_default_mask(item);
6546 		switch (item->type) {
6547 		case RTE_FLOW_ITEM_TYPE_ETH:
6548 			size = sizeof(struct rte_flow_item_eth);
6549 			break;
6550 		case RTE_FLOW_ITEM_TYPE_VLAN:
6551 			size = sizeof(struct rte_flow_item_vlan);
6552 			proto = RTE_ETHER_TYPE_VLAN;
6553 			break;
6554 		case RTE_FLOW_ITEM_TYPE_IPV4:
6555 			size = sizeof(struct rte_flow_item_ipv4);
6556 			proto = RTE_ETHER_TYPE_IPV4;
6557 			break;
6558 		case RTE_FLOW_ITEM_TYPE_IPV6:
6559 			size = sizeof(struct rte_flow_item_ipv6);
6560 			proto = RTE_ETHER_TYPE_IPV6;
6561 			break;
6562 		case RTE_FLOW_ITEM_TYPE_UDP:
6563 			size = sizeof(struct rte_flow_item_udp);
6564 			proto = 0x11;
6565 			break;
6566 		case RTE_FLOW_ITEM_TYPE_TCP:
6567 			size = sizeof(struct rte_flow_item_tcp);
6568 			proto = 0x06;
6569 			break;
6570 		case RTE_FLOW_ITEM_TYPE_VXLAN:
6571 			size = sizeof(struct rte_flow_item_vxlan);
6572 			break;
6573 		case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
6574 			size = sizeof(struct rte_flow_item_vxlan_gpe);
6575 			break;
6576 		case RTE_FLOW_ITEM_TYPE_GRE:
6577 			size = sizeof(struct rte_flow_item_gre);
6578 			proto = 0x2F;
6579 			break;
6580 		case RTE_FLOW_ITEM_TYPE_GRE_KEY:
6581 			size = sizeof(rte_be32_t);
6582 			proto = 0x0;
6583 			break;
6584 		case RTE_FLOW_ITEM_TYPE_MPLS:
6585 			size = sizeof(struct rte_flow_item_mpls);
6586 			proto = 0x0;
6587 			break;
6588 		case RTE_FLOW_ITEM_TYPE_NVGRE:
6589 			size = sizeof(struct rte_flow_item_nvgre);
6590 			proto = 0x2F;
6591 			break;
6592 		case RTE_FLOW_ITEM_TYPE_GENEVE:
6593 			size = sizeof(struct rte_flow_item_geneve);
6594 			break;
6595 		case RTE_FLOW_ITEM_TYPE_L2TPV3OIP:
6596 			size = sizeof(struct rte_flow_item_l2tpv3oip);
6597 			proto = 0x73;
6598 			break;
6599 		case RTE_FLOW_ITEM_TYPE_ESP:
6600 			size = sizeof(struct rte_flow_item_esp);
6601 			proto = 0x32;
6602 			break;
6603 		case RTE_FLOW_ITEM_TYPE_AH:
6604 			size = sizeof(struct rte_flow_item_ah);
6605 			proto = 0x33;
6606 			break;
6607 		case RTE_FLOW_ITEM_TYPE_PFCP:
6608 			size = sizeof(struct rte_flow_item_pfcp);
6609 			break;
6610 		default:
6611 			printf("Error - Not supported item\n");
6612 			*total_size = 0;
6613 			memset(data, 0x00, ACTION_RAW_ENCAP_MAX_DATA);
6614 			return;
6615 		}
6616 		*total_size += size;
6617 		rte_memcpy(data_tail - (*total_size), item->spec, size);
6618 		/* update some fields which cannot be set by cmdline */
6619 		update_fields((data_tail - (*total_size)), item,
6620 			      upper_layer);
6621 		upper_layer = proto;
6622 	}
6623 	if (verbose_level & 0x1)
6624 		printf("total data size is %zu\n", (*total_size));
6625 	RTE_ASSERT((*total_size) <= ACTION_RAW_ENCAP_MAX_DATA);
6626 	memmove(data, (data_tail - (*total_size)), *total_size);
6627 }
6628 
6629 /** Populate help strings for current token (cmdline API). */
6630 static int
6631 cmd_set_raw_get_help(cmdline_parse_token_hdr_t *hdr, char *dst,
6632 		     unsigned int size)
6633 {
6634 	struct context *ctx = &cmd_flow_context;
6635 	const struct token *token = &token_list[ctx->prev];
6636 
6637 	(void)hdr;
6638 	if (!size)
6639 		return -1;
6640 	/* Set token type and update global help with details. */
6641 	snprintf(dst, size, "%s", (token->type ? token->type : "TOKEN"));
6642 	if (token->help)
6643 		cmd_set_raw.help_str = token->help;
6644 	else
6645 		cmd_set_raw.help_str = token->name;
6646 	return 0;
6647 }
6648 
6649 /** Token definition template (cmdline API). */
6650 static struct cmdline_token_hdr cmd_set_raw_token_hdr = {
6651 	.ops = &(struct cmdline_token_ops){
6652 		.parse = cmd_flow_parse,
6653 		.complete_get_nb = cmd_flow_complete_get_nb,
6654 		.complete_get_elt = cmd_flow_complete_get_elt,
6655 		.get_help = cmd_set_raw_get_help,
6656 	},
6657 	.offset = 0,
6658 };
6659 
6660 /** Populate the next dynamic token. */
6661 static void
6662 cmd_set_raw_tok(cmdline_parse_token_hdr_t **hdr,
6663 	     cmdline_parse_token_hdr_t **hdr_inst)
6664 {
6665 	struct context *ctx = &cmd_flow_context;
6666 
6667 	/* Always reinitialize context before requesting the first token. */
6668 	if (!(hdr_inst - cmd_set_raw.tokens)) {
6669 		cmd_flow_context_init(ctx);
6670 		ctx->curr = START_SET;
6671 	}
6672 	/* Return NULL when no more tokens are expected. */
6673 	if (!ctx->next_num && (ctx->curr != START_SET)) {
6674 		*hdr = NULL;
6675 		return;
6676 	}
6677 	/* Determine if command should end here. */
6678 	if (ctx->eol && ctx->last && ctx->next_num) {
6679 		const enum index *list = ctx->next[ctx->next_num - 1];
6680 		int i;
6681 
6682 		for (i = 0; list[i]; ++i) {
6683 			if (list[i] != END)
6684 				continue;
6685 			*hdr = NULL;
6686 			return;
6687 		}
6688 	}
6689 	*hdr = &cmd_set_raw_token_hdr;
6690 }
6691 
6692 /** Token generator and output processing callback (cmdline API). */
6693 static void
6694 cmd_set_raw_cb(void *arg0, struct cmdline *cl, void *arg2)
6695 {
6696 	if (cl == NULL)
6697 		cmd_set_raw_tok(arg0, arg2);
6698 	else
6699 		cmd_set_raw_parsed(arg0);
6700 }
6701 
6702 /** Global parser instance (cmdline API). */
6703 cmdline_parse_inst_t cmd_set_raw = {
6704 	.f = cmd_set_raw_cb,
6705 	.data = NULL, /**< Unused. */
6706 	.help_str = NULL, /**< Updated by cmd_flow_get_help(). */
6707 	.tokens = {
6708 		NULL,
6709 	}, /**< Tokens are returned by cmd_flow_tok(). */
6710 };
6711 
6712 /* *** display raw_encap/raw_decap buf */
6713 struct cmd_show_set_raw_result {
6714 	cmdline_fixed_string_t cmd_show;
6715 	cmdline_fixed_string_t cmd_what;
6716 	cmdline_fixed_string_t cmd_all;
6717 	uint16_t cmd_index;
6718 };
6719 
6720 static void
6721 cmd_show_set_raw_parsed(void *parsed_result, struct cmdline *cl, void *data)
6722 {
6723 	struct cmd_show_set_raw_result *res = parsed_result;
6724 	uint16_t index = res->cmd_index;
6725 	uint8_t all = 0;
6726 	uint8_t *raw_data = NULL;
6727 	size_t raw_size = 0;
6728 	char title[16] = {0};
6729 
6730 	RTE_SET_USED(cl);
6731 	RTE_SET_USED(data);
6732 	if (!strcmp(res->cmd_all, "all")) {
6733 		all = 1;
6734 		index = 0;
6735 	} else if (index >= RAW_ENCAP_CONFS_MAX_NUM) {
6736 		printf("index should be 0-%u\n", RAW_ENCAP_CONFS_MAX_NUM - 1);
6737 		return;
6738 	}
6739 	do {
6740 		if (!strcmp(res->cmd_what, "raw_encap")) {
6741 			raw_data = (uint8_t *)&raw_encap_confs[index].data;
6742 			raw_size = raw_encap_confs[index].size;
6743 			snprintf(title, 16, "\nindex: %u", index);
6744 			rte_hexdump(stdout, title, raw_data, raw_size);
6745 		} else {
6746 			raw_data = (uint8_t *)&raw_decap_confs[index].data;
6747 			raw_size = raw_decap_confs[index].size;
6748 			snprintf(title, 16, "\nindex: %u", index);
6749 			rte_hexdump(stdout, title, raw_data, raw_size);
6750 		}
6751 	} while (all && ++index < RAW_ENCAP_CONFS_MAX_NUM);
6752 }
6753 
6754 cmdline_parse_token_string_t cmd_show_set_raw_cmd_show =
6755 	TOKEN_STRING_INITIALIZER(struct cmd_show_set_raw_result,
6756 			cmd_show, "show");
6757 cmdline_parse_token_string_t cmd_show_set_raw_cmd_what =
6758 	TOKEN_STRING_INITIALIZER(struct cmd_show_set_raw_result,
6759 			cmd_what, "raw_encap#raw_decap");
6760 cmdline_parse_token_num_t cmd_show_set_raw_cmd_index =
6761 	TOKEN_NUM_INITIALIZER(struct cmd_show_set_raw_result,
6762 			cmd_index, UINT16);
6763 cmdline_parse_token_string_t cmd_show_set_raw_cmd_all =
6764 	TOKEN_STRING_INITIALIZER(struct cmd_show_set_raw_result,
6765 			cmd_all, "all");
6766 cmdline_parse_inst_t cmd_show_set_raw = {
6767 	.f = cmd_show_set_raw_parsed,
6768 	.data = NULL,
6769 	.help_str = "show <raw_encap|raw_decap> <index>",
6770 	.tokens = {
6771 		(void *)&cmd_show_set_raw_cmd_show,
6772 		(void *)&cmd_show_set_raw_cmd_what,
6773 		(void *)&cmd_show_set_raw_cmd_index,
6774 		NULL,
6775 	},
6776 };
6777 cmdline_parse_inst_t cmd_show_set_raw_all = {
6778 	.f = cmd_show_set_raw_parsed,
6779 	.data = NULL,
6780 	.help_str = "show <raw_encap|raw_decap> all",
6781 	.tokens = {
6782 		(void *)&cmd_show_set_raw_cmd_show,
6783 		(void *)&cmd_show_set_raw_cmd_what,
6784 		(void *)&cmd_show_set_raw_cmd_all,
6785 		NULL,
6786 	},
6787 };
6788