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