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