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