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