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