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