app/testpmd: add flow queue push operation
[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
14 #include <rte_string_fns.h>
15 #include <rte_common.h>
16 #include <rte_ethdev.h>
17 #include <rte_byteorder.h>
18 #include <cmdline_parse.h>
19 #include <cmdline_parse_etheraddr.h>
20 #include <cmdline_parse_string.h>
21 #include <cmdline_parse_num.h>
22 #include <rte_flow.h>
23 #include <rte_hexdump.h>
24 #include <rte_vxlan.h>
25 #include <rte_gre.h>
26 #include <rte_mpls.h>
27 #include <rte_gtp.h>
28 #include <rte_geneve.h>
29
30 #include "testpmd.h"
31
32 /** Parser token indices. */
33 enum index {
34         /* Special tokens. */
35         ZERO = 0,
36         END,
37         START_SET,
38         END_SET,
39
40         /* Common tokens. */
41         COMMON_INTEGER,
42         COMMON_UNSIGNED,
43         COMMON_PREFIX,
44         COMMON_BOOLEAN,
45         COMMON_STRING,
46         COMMON_HEX,
47         COMMON_FILE_PATH,
48         COMMON_MAC_ADDR,
49         COMMON_IPV4_ADDR,
50         COMMON_IPV6_ADDR,
51         COMMON_RULE_ID,
52         COMMON_PORT_ID,
53         COMMON_GROUP_ID,
54         COMMON_PRIORITY_LEVEL,
55         COMMON_INDIRECT_ACTION_ID,
56         COMMON_POLICY_ID,
57         COMMON_FLEX_HANDLE,
58         COMMON_FLEX_TOKEN,
59         COMMON_PATTERN_TEMPLATE_ID,
60         COMMON_ACTIONS_TEMPLATE_ID,
61         COMMON_TABLE_ID,
62         COMMON_QUEUE_ID,
63
64         /* TOP-level command. */
65         ADD,
66
67         /* Top-level command. */
68         SET,
69         /* Sub-leve commands. */
70         SET_RAW_ENCAP,
71         SET_RAW_DECAP,
72         SET_RAW_INDEX,
73         SET_SAMPLE_ACTIONS,
74         SET_SAMPLE_INDEX,
75
76         /* Top-level command. */
77         FLOW,
78         /* Sub-level commands. */
79         INFO,
80         CONFIGURE,
81         PATTERN_TEMPLATE,
82         ACTIONS_TEMPLATE,
83         TABLE,
84         INDIRECT_ACTION,
85         VALIDATE,
86         CREATE,
87         DESTROY,
88         FLUSH,
89         DUMP,
90         QUERY,
91         LIST,
92         AGED,
93         ISOLATE,
94         TUNNEL,
95         FLEX,
96         QUEUE,
97         PUSH,
98
99         /* Flex arguments */
100         FLEX_ITEM_INIT,
101         FLEX_ITEM_CREATE,
102         FLEX_ITEM_DESTROY,
103
104         /* Pattern template arguments. */
105         PATTERN_TEMPLATE_CREATE,
106         PATTERN_TEMPLATE_DESTROY,
107         PATTERN_TEMPLATE_CREATE_ID,
108         PATTERN_TEMPLATE_DESTROY_ID,
109         PATTERN_TEMPLATE_RELAXED_MATCHING,
110         PATTERN_TEMPLATE_INGRESS,
111         PATTERN_TEMPLATE_EGRESS,
112         PATTERN_TEMPLATE_TRANSFER,
113         PATTERN_TEMPLATE_SPEC,
114
115         /* Actions template arguments. */
116         ACTIONS_TEMPLATE_CREATE,
117         ACTIONS_TEMPLATE_DESTROY,
118         ACTIONS_TEMPLATE_CREATE_ID,
119         ACTIONS_TEMPLATE_DESTROY_ID,
120         ACTIONS_TEMPLATE_INGRESS,
121         ACTIONS_TEMPLATE_EGRESS,
122         ACTIONS_TEMPLATE_TRANSFER,
123         ACTIONS_TEMPLATE_SPEC,
124         ACTIONS_TEMPLATE_MASK,
125
126         /* Queue arguments. */
127         QUEUE_CREATE,
128         QUEUE_DESTROY,
129
130         /* Queue create arguments. */
131         QUEUE_CREATE_ID,
132         QUEUE_CREATE_POSTPONE,
133         QUEUE_TEMPLATE_TABLE,
134         QUEUE_PATTERN_TEMPLATE,
135         QUEUE_ACTIONS_TEMPLATE,
136         QUEUE_SPEC,
137
138         /* Queue destroy arguments. */
139         QUEUE_DESTROY_ID,
140         QUEUE_DESTROY_POSTPONE,
141
142         /* Push arguments. */
143         PUSH_QUEUE,
144
145         /* Table arguments. */
146         TABLE_CREATE,
147         TABLE_DESTROY,
148         TABLE_CREATE_ID,
149         TABLE_DESTROY_ID,
150         TABLE_GROUP,
151         TABLE_PRIORITY,
152         TABLE_INGRESS,
153         TABLE_EGRESS,
154         TABLE_TRANSFER,
155         TABLE_RULES_NUMBER,
156         TABLE_PATTERN_TEMPLATE,
157         TABLE_ACTIONS_TEMPLATE,
158
159         /* Tunnel arguments. */
160         TUNNEL_CREATE,
161         TUNNEL_CREATE_TYPE,
162         TUNNEL_LIST,
163         TUNNEL_DESTROY,
164         TUNNEL_DESTROY_ID,
165
166         /* Destroy arguments. */
167         DESTROY_RULE,
168
169         /* Query arguments. */
170         QUERY_ACTION,
171
172         /* List arguments. */
173         LIST_GROUP,
174
175         /* Destroy aged flow arguments. */
176         AGED_DESTROY,
177
178         /* Validate/create arguments. */
179         VC_GROUP,
180         VC_PRIORITY,
181         VC_INGRESS,
182         VC_EGRESS,
183         VC_TRANSFER,
184         VC_TUNNEL_SET,
185         VC_TUNNEL_MATCH,
186
187         /* Dump arguments */
188         DUMP_ALL,
189         DUMP_ONE,
190
191         /* Configure arguments */
192         CONFIG_QUEUES_NUMBER,
193         CONFIG_QUEUES_SIZE,
194         CONFIG_COUNTERS_NUMBER,
195         CONFIG_AGING_OBJECTS_NUMBER,
196         CONFIG_METERS_NUMBER,
197
198         /* Indirect action arguments */
199         INDIRECT_ACTION_CREATE,
200         INDIRECT_ACTION_UPDATE,
201         INDIRECT_ACTION_DESTROY,
202         INDIRECT_ACTION_QUERY,
203
204         /* Indirect action create arguments */
205         INDIRECT_ACTION_CREATE_ID,
206         INDIRECT_ACTION_INGRESS,
207         INDIRECT_ACTION_EGRESS,
208         INDIRECT_ACTION_TRANSFER,
209         INDIRECT_ACTION_SPEC,
210
211         /* Indirect action destroy arguments */
212         INDIRECT_ACTION_DESTROY_ID,
213
214         /* Validate/create pattern. */
215         ITEM_PATTERN,
216         ITEM_PARAM_IS,
217         ITEM_PARAM_SPEC,
218         ITEM_PARAM_LAST,
219         ITEM_PARAM_MASK,
220         ITEM_PARAM_PREFIX,
221         ITEM_NEXT,
222         ITEM_END,
223         ITEM_VOID,
224         ITEM_INVERT,
225         ITEM_ANY,
226         ITEM_ANY_NUM,
227         ITEM_PF,
228         ITEM_VF,
229         ITEM_VF_ID,
230         ITEM_PHY_PORT,
231         ITEM_PHY_PORT_INDEX,
232         ITEM_PORT_ID,
233         ITEM_PORT_ID_ID,
234         ITEM_MARK,
235         ITEM_MARK_ID,
236         ITEM_RAW,
237         ITEM_RAW_RELATIVE,
238         ITEM_RAW_SEARCH,
239         ITEM_RAW_OFFSET,
240         ITEM_RAW_LIMIT,
241         ITEM_RAW_PATTERN,
242         ITEM_RAW_PATTERN_HEX,
243         ITEM_ETH,
244         ITEM_ETH_DST,
245         ITEM_ETH_SRC,
246         ITEM_ETH_TYPE,
247         ITEM_ETH_HAS_VLAN,
248         ITEM_VLAN,
249         ITEM_VLAN_TCI,
250         ITEM_VLAN_PCP,
251         ITEM_VLAN_DEI,
252         ITEM_VLAN_VID,
253         ITEM_VLAN_INNER_TYPE,
254         ITEM_VLAN_HAS_MORE_VLAN,
255         ITEM_IPV4,
256         ITEM_IPV4_VER_IHL,
257         ITEM_IPV4_TOS,
258         ITEM_IPV4_ID,
259         ITEM_IPV4_FRAGMENT_OFFSET,
260         ITEM_IPV4_TTL,
261         ITEM_IPV4_PROTO,
262         ITEM_IPV4_SRC,
263         ITEM_IPV4_DST,
264         ITEM_IPV6,
265         ITEM_IPV6_TC,
266         ITEM_IPV6_FLOW,
267         ITEM_IPV6_PROTO,
268         ITEM_IPV6_HOP,
269         ITEM_IPV6_SRC,
270         ITEM_IPV6_DST,
271         ITEM_IPV6_HAS_FRAG_EXT,
272         ITEM_ICMP,
273         ITEM_ICMP_TYPE,
274         ITEM_ICMP_CODE,
275         ITEM_ICMP_IDENT,
276         ITEM_ICMP_SEQ,
277         ITEM_UDP,
278         ITEM_UDP_SRC,
279         ITEM_UDP_DST,
280         ITEM_TCP,
281         ITEM_TCP_SRC,
282         ITEM_TCP_DST,
283         ITEM_TCP_FLAGS,
284         ITEM_SCTP,
285         ITEM_SCTP_SRC,
286         ITEM_SCTP_DST,
287         ITEM_SCTP_TAG,
288         ITEM_SCTP_CKSUM,
289         ITEM_VXLAN,
290         ITEM_VXLAN_VNI,
291         ITEM_VXLAN_LAST_RSVD,
292         ITEM_E_TAG,
293         ITEM_E_TAG_GRP_ECID_B,
294         ITEM_NVGRE,
295         ITEM_NVGRE_TNI,
296         ITEM_MPLS,
297         ITEM_MPLS_LABEL,
298         ITEM_MPLS_TC,
299         ITEM_MPLS_S,
300         ITEM_GRE,
301         ITEM_GRE_PROTO,
302         ITEM_GRE_C_RSVD0_VER,
303         ITEM_GRE_C_BIT,
304         ITEM_GRE_K_BIT,
305         ITEM_GRE_S_BIT,
306         ITEM_FUZZY,
307         ITEM_FUZZY_THRESH,
308         ITEM_GTP,
309         ITEM_GTP_FLAGS,
310         ITEM_GTP_MSG_TYPE,
311         ITEM_GTP_TEID,
312         ITEM_GTPC,
313         ITEM_GTPU,
314         ITEM_GENEVE,
315         ITEM_GENEVE_VNI,
316         ITEM_GENEVE_PROTO,
317         ITEM_GENEVE_OPTLEN,
318         ITEM_VXLAN_GPE,
319         ITEM_VXLAN_GPE_VNI,
320         ITEM_ARP_ETH_IPV4,
321         ITEM_ARP_ETH_IPV4_SHA,
322         ITEM_ARP_ETH_IPV4_SPA,
323         ITEM_ARP_ETH_IPV4_THA,
324         ITEM_ARP_ETH_IPV4_TPA,
325         ITEM_IPV6_EXT,
326         ITEM_IPV6_EXT_NEXT_HDR,
327         ITEM_IPV6_FRAG_EXT,
328         ITEM_IPV6_FRAG_EXT_NEXT_HDR,
329         ITEM_IPV6_FRAG_EXT_FRAG_DATA,
330         ITEM_IPV6_FRAG_EXT_ID,
331         ITEM_ICMP6,
332         ITEM_ICMP6_TYPE,
333         ITEM_ICMP6_CODE,
334         ITEM_ICMP6_ND_NS,
335         ITEM_ICMP6_ND_NS_TARGET_ADDR,
336         ITEM_ICMP6_ND_NA,
337         ITEM_ICMP6_ND_NA_TARGET_ADDR,
338         ITEM_ICMP6_ND_OPT,
339         ITEM_ICMP6_ND_OPT_TYPE,
340         ITEM_ICMP6_ND_OPT_SLA_ETH,
341         ITEM_ICMP6_ND_OPT_SLA_ETH_SLA,
342         ITEM_ICMP6_ND_OPT_TLA_ETH,
343         ITEM_ICMP6_ND_OPT_TLA_ETH_TLA,
344         ITEM_META,
345         ITEM_META_DATA,
346         ITEM_GRE_KEY,
347         ITEM_GRE_KEY_VALUE,
348         ITEM_GRE_OPTION,
349         ITEM_GRE_OPTION_CHECKSUM,
350         ITEM_GRE_OPTION_KEY,
351         ITEM_GRE_OPTION_SEQUENCE,
352         ITEM_GTP_PSC,
353         ITEM_GTP_PSC_QFI,
354         ITEM_GTP_PSC_PDU_T,
355         ITEM_PPPOES,
356         ITEM_PPPOED,
357         ITEM_PPPOE_SEID,
358         ITEM_PPPOE_PROTO_ID,
359         ITEM_HIGIG2,
360         ITEM_HIGIG2_CLASSIFICATION,
361         ITEM_HIGIG2_VID,
362         ITEM_TAG,
363         ITEM_TAG_DATA,
364         ITEM_TAG_INDEX,
365         ITEM_L2TPV3OIP,
366         ITEM_L2TPV3OIP_SESSION_ID,
367         ITEM_ESP,
368         ITEM_ESP_SPI,
369         ITEM_AH,
370         ITEM_AH_SPI,
371         ITEM_PFCP,
372         ITEM_PFCP_S_FIELD,
373         ITEM_PFCP_SEID,
374         ITEM_ECPRI,
375         ITEM_ECPRI_COMMON,
376         ITEM_ECPRI_COMMON_TYPE,
377         ITEM_ECPRI_COMMON_TYPE_IQ_DATA,
378         ITEM_ECPRI_COMMON_TYPE_RTC_CTRL,
379         ITEM_ECPRI_COMMON_TYPE_DLY_MSR,
380         ITEM_ECPRI_MSG_IQ_DATA_PCID,
381         ITEM_ECPRI_MSG_RTC_CTRL_RTCID,
382         ITEM_ECPRI_MSG_DLY_MSR_MSRID,
383         ITEM_GENEVE_OPT,
384         ITEM_GENEVE_OPT_CLASS,
385         ITEM_GENEVE_OPT_TYPE,
386         ITEM_GENEVE_OPT_LENGTH,
387         ITEM_GENEVE_OPT_DATA,
388         ITEM_INTEGRITY,
389         ITEM_INTEGRITY_LEVEL,
390         ITEM_INTEGRITY_VALUE,
391         ITEM_CONNTRACK,
392         ITEM_POL_PORT,
393         ITEM_POL_METER,
394         ITEM_POL_POLICY,
395         ITEM_PORT_REPRESENTOR,
396         ITEM_PORT_REPRESENTOR_PORT_ID,
397         ITEM_REPRESENTED_PORT,
398         ITEM_REPRESENTED_PORT_ETHDEV_PORT_ID,
399         ITEM_FLEX,
400         ITEM_FLEX_ITEM_HANDLE,
401         ITEM_FLEX_PATTERN_HANDLE,
402         ITEM_L2TPV2,
403         ITEM_L2TPV2_TYPE,
404         ITEM_L2TPV2_TYPE_DATA,
405         ITEM_L2TPV2_TYPE_DATA_L,
406         ITEM_L2TPV2_TYPE_DATA_S,
407         ITEM_L2TPV2_TYPE_DATA_O,
408         ITEM_L2TPV2_TYPE_DATA_L_S,
409         ITEM_L2TPV2_TYPE_CTRL,
410         ITEM_L2TPV2_MSG_DATA_TUNNEL_ID,
411         ITEM_L2TPV2_MSG_DATA_SESSION_ID,
412         ITEM_L2TPV2_MSG_DATA_L_LENGTH,
413         ITEM_L2TPV2_MSG_DATA_L_TUNNEL_ID,
414         ITEM_L2TPV2_MSG_DATA_L_SESSION_ID,
415         ITEM_L2TPV2_MSG_DATA_S_TUNNEL_ID,
416         ITEM_L2TPV2_MSG_DATA_S_SESSION_ID,
417         ITEM_L2TPV2_MSG_DATA_S_NS,
418         ITEM_L2TPV2_MSG_DATA_S_NR,
419         ITEM_L2TPV2_MSG_DATA_O_TUNNEL_ID,
420         ITEM_L2TPV2_MSG_DATA_O_SESSION_ID,
421         ITEM_L2TPV2_MSG_DATA_O_OFFSET,
422         ITEM_L2TPV2_MSG_DATA_L_S_LENGTH,
423         ITEM_L2TPV2_MSG_DATA_L_S_TUNNEL_ID,
424         ITEM_L2TPV2_MSG_DATA_L_S_SESSION_ID,
425         ITEM_L2TPV2_MSG_DATA_L_S_NS,
426         ITEM_L2TPV2_MSG_DATA_L_S_NR,
427         ITEM_L2TPV2_MSG_CTRL_LENGTH,
428         ITEM_L2TPV2_MSG_CTRL_TUNNEL_ID,
429         ITEM_L2TPV2_MSG_CTRL_SESSION_ID,
430         ITEM_L2TPV2_MSG_CTRL_NS,
431         ITEM_L2TPV2_MSG_CTRL_NR,
432         ITEM_PPP,
433         ITEM_PPP_ADDR,
434         ITEM_PPP_CTRL,
435         ITEM_PPP_PROTO_ID,
436
437         /* Validate/create actions. */
438         ACTIONS,
439         ACTION_NEXT,
440         ACTION_END,
441         ACTION_VOID,
442         ACTION_PASSTHRU,
443         ACTION_JUMP,
444         ACTION_JUMP_GROUP,
445         ACTION_MARK,
446         ACTION_MARK_ID,
447         ACTION_FLAG,
448         ACTION_QUEUE,
449         ACTION_QUEUE_INDEX,
450         ACTION_DROP,
451         ACTION_COUNT,
452         ACTION_COUNT_ID,
453         ACTION_RSS,
454         ACTION_RSS_FUNC,
455         ACTION_RSS_LEVEL,
456         ACTION_RSS_FUNC_DEFAULT,
457         ACTION_RSS_FUNC_TOEPLITZ,
458         ACTION_RSS_FUNC_SIMPLE_XOR,
459         ACTION_RSS_FUNC_SYMMETRIC_TOEPLITZ,
460         ACTION_RSS_TYPES,
461         ACTION_RSS_TYPE,
462         ACTION_RSS_KEY,
463         ACTION_RSS_KEY_LEN,
464         ACTION_RSS_QUEUES,
465         ACTION_RSS_QUEUE,
466         ACTION_PF,
467         ACTION_VF,
468         ACTION_VF_ORIGINAL,
469         ACTION_VF_ID,
470         ACTION_PHY_PORT,
471         ACTION_PHY_PORT_ORIGINAL,
472         ACTION_PHY_PORT_INDEX,
473         ACTION_PORT_ID,
474         ACTION_PORT_ID_ORIGINAL,
475         ACTION_PORT_ID_ID,
476         ACTION_METER,
477         ACTION_METER_COLOR,
478         ACTION_METER_COLOR_TYPE,
479         ACTION_METER_COLOR_GREEN,
480         ACTION_METER_COLOR_YELLOW,
481         ACTION_METER_COLOR_RED,
482         ACTION_METER_ID,
483         ACTION_OF_SET_MPLS_TTL,
484         ACTION_OF_SET_MPLS_TTL_MPLS_TTL,
485         ACTION_OF_DEC_MPLS_TTL,
486         ACTION_OF_SET_NW_TTL,
487         ACTION_OF_SET_NW_TTL_NW_TTL,
488         ACTION_OF_DEC_NW_TTL,
489         ACTION_OF_COPY_TTL_OUT,
490         ACTION_OF_COPY_TTL_IN,
491         ACTION_OF_POP_VLAN,
492         ACTION_OF_PUSH_VLAN,
493         ACTION_OF_PUSH_VLAN_ETHERTYPE,
494         ACTION_OF_SET_VLAN_VID,
495         ACTION_OF_SET_VLAN_VID_VLAN_VID,
496         ACTION_OF_SET_VLAN_PCP,
497         ACTION_OF_SET_VLAN_PCP_VLAN_PCP,
498         ACTION_OF_POP_MPLS,
499         ACTION_OF_POP_MPLS_ETHERTYPE,
500         ACTION_OF_PUSH_MPLS,
501         ACTION_OF_PUSH_MPLS_ETHERTYPE,
502         ACTION_VXLAN_ENCAP,
503         ACTION_VXLAN_DECAP,
504         ACTION_NVGRE_ENCAP,
505         ACTION_NVGRE_DECAP,
506         ACTION_L2_ENCAP,
507         ACTION_L2_DECAP,
508         ACTION_MPLSOGRE_ENCAP,
509         ACTION_MPLSOGRE_DECAP,
510         ACTION_MPLSOUDP_ENCAP,
511         ACTION_MPLSOUDP_DECAP,
512         ACTION_SET_IPV4_SRC,
513         ACTION_SET_IPV4_SRC_IPV4_SRC,
514         ACTION_SET_IPV4_DST,
515         ACTION_SET_IPV4_DST_IPV4_DST,
516         ACTION_SET_IPV6_SRC,
517         ACTION_SET_IPV6_SRC_IPV6_SRC,
518         ACTION_SET_IPV6_DST,
519         ACTION_SET_IPV6_DST_IPV6_DST,
520         ACTION_SET_TP_SRC,
521         ACTION_SET_TP_SRC_TP_SRC,
522         ACTION_SET_TP_DST,
523         ACTION_SET_TP_DST_TP_DST,
524         ACTION_MAC_SWAP,
525         ACTION_DEC_TTL,
526         ACTION_SET_TTL,
527         ACTION_SET_TTL_TTL,
528         ACTION_SET_MAC_SRC,
529         ACTION_SET_MAC_SRC_MAC_SRC,
530         ACTION_SET_MAC_DST,
531         ACTION_SET_MAC_DST_MAC_DST,
532         ACTION_INC_TCP_SEQ,
533         ACTION_INC_TCP_SEQ_VALUE,
534         ACTION_DEC_TCP_SEQ,
535         ACTION_DEC_TCP_SEQ_VALUE,
536         ACTION_INC_TCP_ACK,
537         ACTION_INC_TCP_ACK_VALUE,
538         ACTION_DEC_TCP_ACK,
539         ACTION_DEC_TCP_ACK_VALUE,
540         ACTION_RAW_ENCAP,
541         ACTION_RAW_DECAP,
542         ACTION_RAW_ENCAP_INDEX,
543         ACTION_RAW_ENCAP_INDEX_VALUE,
544         ACTION_RAW_DECAP_INDEX,
545         ACTION_RAW_DECAP_INDEX_VALUE,
546         ACTION_SET_TAG,
547         ACTION_SET_TAG_DATA,
548         ACTION_SET_TAG_INDEX,
549         ACTION_SET_TAG_MASK,
550         ACTION_SET_META,
551         ACTION_SET_META_DATA,
552         ACTION_SET_META_MASK,
553         ACTION_SET_IPV4_DSCP,
554         ACTION_SET_IPV4_DSCP_VALUE,
555         ACTION_SET_IPV6_DSCP,
556         ACTION_SET_IPV6_DSCP_VALUE,
557         ACTION_AGE,
558         ACTION_AGE_TIMEOUT,
559         ACTION_SAMPLE,
560         ACTION_SAMPLE_RATIO,
561         ACTION_SAMPLE_INDEX,
562         ACTION_SAMPLE_INDEX_VALUE,
563         ACTION_INDIRECT,
564         INDIRECT_ACTION_ID2PTR,
565         ACTION_MODIFY_FIELD,
566         ACTION_MODIFY_FIELD_OP,
567         ACTION_MODIFY_FIELD_OP_VALUE,
568         ACTION_MODIFY_FIELD_DST_TYPE,
569         ACTION_MODIFY_FIELD_DST_TYPE_VALUE,
570         ACTION_MODIFY_FIELD_DST_LEVEL,
571         ACTION_MODIFY_FIELD_DST_OFFSET,
572         ACTION_MODIFY_FIELD_SRC_TYPE,
573         ACTION_MODIFY_FIELD_SRC_TYPE_VALUE,
574         ACTION_MODIFY_FIELD_SRC_LEVEL,
575         ACTION_MODIFY_FIELD_SRC_OFFSET,
576         ACTION_MODIFY_FIELD_SRC_VALUE,
577         ACTION_MODIFY_FIELD_SRC_POINTER,
578         ACTION_MODIFY_FIELD_WIDTH,
579         ACTION_CONNTRACK,
580         ACTION_CONNTRACK_UPDATE,
581         ACTION_CONNTRACK_UPDATE_DIR,
582         ACTION_CONNTRACK_UPDATE_CTX,
583         ACTION_POL_G,
584         ACTION_POL_Y,
585         ACTION_POL_R,
586         ACTION_PORT_REPRESENTOR,
587         ACTION_PORT_REPRESENTOR_PORT_ID,
588         ACTION_REPRESENTED_PORT,
589         ACTION_REPRESENTED_PORT_ETHDEV_PORT_ID,
590 };
591
592 /** Maximum size for pattern in struct rte_flow_item_raw. */
593 #define ITEM_RAW_PATTERN_SIZE 512
594
595 /** Maximum size for GENEVE option data pattern in bytes. */
596 #define ITEM_GENEVE_OPT_DATA_SIZE 124
597
598 /** Storage size for struct rte_flow_item_raw including pattern. */
599 #define ITEM_RAW_SIZE \
600         (sizeof(struct rte_flow_item_raw) + ITEM_RAW_PATTERN_SIZE)
601
602 /** Maximum size for external pattern in struct rte_flow_action_modify_data. */
603 #define ACTION_MODIFY_PATTERN_SIZE 32
604
605 /** Storage size for struct rte_flow_action_modify_field including pattern. */
606 #define ACTION_MODIFY_SIZE \
607         (sizeof(struct rte_flow_action_modify_field) + \
608         ACTION_MODIFY_PATTERN_SIZE)
609
610 /** Maximum number of queue indices in struct rte_flow_action_rss. */
611 #define ACTION_RSS_QUEUE_NUM 128
612
613 /** Storage for struct rte_flow_action_rss including external data. */
614 struct action_rss_data {
615         struct rte_flow_action_rss conf;
616         uint8_t key[RSS_HASH_KEY_LENGTH];
617         uint16_t queue[ACTION_RSS_QUEUE_NUM];
618 };
619
620 /** Maximum data size in struct rte_flow_action_raw_encap. */
621 #define ACTION_RAW_ENCAP_MAX_DATA 512
622 #define RAW_ENCAP_CONFS_MAX_NUM 8
623
624 /** Storage for struct rte_flow_action_raw_encap. */
625 struct raw_encap_conf {
626         uint8_t data[ACTION_RAW_ENCAP_MAX_DATA];
627         uint8_t preserve[ACTION_RAW_ENCAP_MAX_DATA];
628         size_t size;
629 };
630
631 struct raw_encap_conf raw_encap_confs[RAW_ENCAP_CONFS_MAX_NUM];
632
633 /** Storage for struct rte_flow_action_raw_encap including external data. */
634 struct action_raw_encap_data {
635         struct rte_flow_action_raw_encap conf;
636         uint8_t data[ACTION_RAW_ENCAP_MAX_DATA];
637         uint8_t preserve[ACTION_RAW_ENCAP_MAX_DATA];
638         uint16_t idx;
639 };
640
641 /** Storage for struct rte_flow_action_raw_decap. */
642 struct raw_decap_conf {
643         uint8_t data[ACTION_RAW_ENCAP_MAX_DATA];
644         size_t size;
645 };
646
647 struct raw_decap_conf raw_decap_confs[RAW_ENCAP_CONFS_MAX_NUM];
648
649 /** Storage for struct rte_flow_action_raw_decap including external data. */
650 struct action_raw_decap_data {
651         struct rte_flow_action_raw_decap conf;
652         uint8_t data[ACTION_RAW_ENCAP_MAX_DATA];
653         uint16_t idx;
654 };
655
656 struct vxlan_encap_conf vxlan_encap_conf = {
657         .select_ipv4 = 1,
658         .select_vlan = 0,
659         .select_tos_ttl = 0,
660         .vni = "\x00\x00\x00",
661         .udp_src = 0,
662         .udp_dst = RTE_BE16(RTE_VXLAN_DEFAULT_PORT),
663         .ipv4_src = RTE_IPV4(127, 0, 0, 1),
664         .ipv4_dst = RTE_IPV4(255, 255, 255, 255),
665         .ipv6_src = "\x00\x00\x00\x00\x00\x00\x00\x00"
666                 "\x00\x00\x00\x00\x00\x00\x00\x01",
667         .ipv6_dst = "\x00\x00\x00\x00\x00\x00\x00\x00"
668                 "\x00\x00\x00\x00\x00\x00\x11\x11",
669         .vlan_tci = 0,
670         .ip_tos = 0,
671         .ip_ttl = 255,
672         .eth_src = "\x00\x00\x00\x00\x00\x00",
673         .eth_dst = "\xff\xff\xff\xff\xff\xff",
674 };
675
676 /** Maximum number of items in struct rte_flow_action_vxlan_encap. */
677 #define ACTION_VXLAN_ENCAP_ITEMS_NUM 6
678
679 /** Storage for struct rte_flow_action_vxlan_encap including external data. */
680 struct action_vxlan_encap_data {
681         struct rte_flow_action_vxlan_encap conf;
682         struct rte_flow_item items[ACTION_VXLAN_ENCAP_ITEMS_NUM];
683         struct rte_flow_item_eth item_eth;
684         struct rte_flow_item_vlan item_vlan;
685         union {
686                 struct rte_flow_item_ipv4 item_ipv4;
687                 struct rte_flow_item_ipv6 item_ipv6;
688         };
689         struct rte_flow_item_udp item_udp;
690         struct rte_flow_item_vxlan item_vxlan;
691 };
692
693 struct nvgre_encap_conf nvgre_encap_conf = {
694         .select_ipv4 = 1,
695         .select_vlan = 0,
696         .tni = "\x00\x00\x00",
697         .ipv4_src = RTE_IPV4(127, 0, 0, 1),
698         .ipv4_dst = RTE_IPV4(255, 255, 255, 255),
699         .ipv6_src = "\x00\x00\x00\x00\x00\x00\x00\x00"
700                 "\x00\x00\x00\x00\x00\x00\x00\x01",
701         .ipv6_dst = "\x00\x00\x00\x00\x00\x00\x00\x00"
702                 "\x00\x00\x00\x00\x00\x00\x11\x11",
703         .vlan_tci = 0,
704         .eth_src = "\x00\x00\x00\x00\x00\x00",
705         .eth_dst = "\xff\xff\xff\xff\xff\xff",
706 };
707
708 /** Maximum number of items in struct rte_flow_action_nvgre_encap. */
709 #define ACTION_NVGRE_ENCAP_ITEMS_NUM 5
710
711 /** Storage for struct rte_flow_action_nvgre_encap including external data. */
712 struct action_nvgre_encap_data {
713         struct rte_flow_action_nvgre_encap conf;
714         struct rte_flow_item items[ACTION_NVGRE_ENCAP_ITEMS_NUM];
715         struct rte_flow_item_eth item_eth;
716         struct rte_flow_item_vlan item_vlan;
717         union {
718                 struct rte_flow_item_ipv4 item_ipv4;
719                 struct rte_flow_item_ipv6 item_ipv6;
720         };
721         struct rte_flow_item_nvgre item_nvgre;
722 };
723
724 struct l2_encap_conf l2_encap_conf;
725
726 struct l2_decap_conf l2_decap_conf;
727
728 struct mplsogre_encap_conf mplsogre_encap_conf;
729
730 struct mplsogre_decap_conf mplsogre_decap_conf;
731
732 struct mplsoudp_encap_conf mplsoudp_encap_conf;
733
734 struct mplsoudp_decap_conf mplsoudp_decap_conf;
735
736 struct rte_flow_action_conntrack conntrack_context;
737
738 #define ACTION_SAMPLE_ACTIONS_NUM 10
739 #define RAW_SAMPLE_CONFS_MAX_NUM 8
740 /** Storage for struct rte_flow_action_sample including external data. */
741 struct action_sample_data {
742         struct rte_flow_action_sample conf;
743         uint32_t idx;
744 };
745 /** Storage for struct rte_flow_action_sample. */
746 struct raw_sample_conf {
747         struct rte_flow_action data[ACTION_SAMPLE_ACTIONS_NUM];
748 };
749 struct raw_sample_conf raw_sample_confs[RAW_SAMPLE_CONFS_MAX_NUM];
750 struct rte_flow_action_mark sample_mark[RAW_SAMPLE_CONFS_MAX_NUM];
751 struct rte_flow_action_queue sample_queue[RAW_SAMPLE_CONFS_MAX_NUM];
752 struct rte_flow_action_count sample_count[RAW_SAMPLE_CONFS_MAX_NUM];
753 struct rte_flow_action_port_id sample_port_id[RAW_SAMPLE_CONFS_MAX_NUM];
754 struct rte_flow_action_raw_encap sample_encap[RAW_SAMPLE_CONFS_MAX_NUM];
755 struct action_vxlan_encap_data sample_vxlan_encap[RAW_SAMPLE_CONFS_MAX_NUM];
756 struct action_nvgre_encap_data sample_nvgre_encap[RAW_SAMPLE_CONFS_MAX_NUM];
757 struct action_rss_data sample_rss_data[RAW_SAMPLE_CONFS_MAX_NUM];
758 struct rte_flow_action_vf sample_vf[RAW_SAMPLE_CONFS_MAX_NUM];
759
760 static const char *const modify_field_ops[] = {
761         "set", "add", "sub", NULL
762 };
763
764 static const char *const modify_field_ids[] = {
765         "start", "mac_dst", "mac_src",
766         "vlan_type", "vlan_id", "mac_type",
767         "ipv4_dscp", "ipv4_ttl", "ipv4_src", "ipv4_dst",
768         "ipv6_dscp", "ipv6_hoplimit", "ipv6_src", "ipv6_dst",
769         "tcp_port_src", "tcp_port_dst",
770         "tcp_seq_num", "tcp_ack_num", "tcp_flags",
771         "udp_port_src", "udp_port_dst",
772         "vxlan_vni", "geneve_vni", "gtp_teid",
773         "tag", "mark", "meta", "pointer", "value", NULL
774 };
775
776 /** Maximum number of subsequent tokens and arguments on the stack. */
777 #define CTX_STACK_SIZE 16
778
779 /** Parser context. */
780 struct context {
781         /** Stack of subsequent token lists to process. */
782         const enum index *next[CTX_STACK_SIZE];
783         /** Arguments for stacked tokens. */
784         const void *args[CTX_STACK_SIZE];
785         enum index curr; /**< Current token index. */
786         enum index prev; /**< Index of the last token seen. */
787         int next_num; /**< Number of entries in next[]. */
788         int args_num; /**< Number of entries in args[]. */
789         uint32_t eol:1; /**< EOL has been detected. */
790         uint32_t last:1; /**< No more arguments. */
791         portid_t port; /**< Current port ID (for completions). */
792         uint32_t objdata; /**< Object-specific data. */
793         void *object; /**< Address of current object for relative offsets. */
794         void *objmask; /**< Object a full mask must be written to. */
795 };
796
797 /** Token argument. */
798 struct arg {
799         uint32_t hton:1; /**< Use network byte ordering. */
800         uint32_t sign:1; /**< Value is signed. */
801         uint32_t bounded:1; /**< Value is bounded. */
802         uintmax_t min; /**< Minimum value if bounded. */
803         uintmax_t max; /**< Maximum value if bounded. */
804         uint32_t offset; /**< Relative offset from ctx->object. */
805         uint32_t size; /**< Field size. */
806         const uint8_t *mask; /**< Bit-mask to use instead of offset/size. */
807 };
808
809 /** Parser token definition. */
810 struct token {
811         /** Type displayed during completion (defaults to "TOKEN"). */
812         const char *type;
813         /** Help displayed during completion (defaults to token name). */
814         const char *help;
815         /** Private data used by parser functions. */
816         const void *priv;
817         /**
818          * Lists of subsequent tokens to push on the stack. Each call to the
819          * parser consumes the last entry of that stack.
820          */
821         const enum index *const *next;
822         /** Arguments stack for subsequent tokens that need them. */
823         const struct arg *const *args;
824         /**
825          * Token-processing callback, returns -1 in case of error, the
826          * length of the matched string otherwise. If NULL, attempts to
827          * match the token name.
828          *
829          * If buf is not NULL, the result should be stored in it according
830          * to context. An error is returned if not large enough.
831          */
832         int (*call)(struct context *ctx, const struct token *token,
833                     const char *str, unsigned int len,
834                     void *buf, unsigned int size);
835         /**
836          * Callback that provides possible values for this token, used for
837          * completion. Returns -1 in case of error, the number of possible
838          * values otherwise. If NULL, the token name is used.
839          *
840          * If buf is not NULL, entry index ent is written to buf and the
841          * full length of the entry is returned (same behavior as
842          * snprintf()).
843          */
844         int (*comp)(struct context *ctx, const struct token *token,
845                     unsigned int ent, char *buf, unsigned int size);
846         /** Mandatory token name, no default value. */
847         const char *name;
848 };
849
850 /** Static initializer for the next field. */
851 #define NEXT(...) (const enum index *const []){ __VA_ARGS__, NULL, }
852
853 /** Static initializer for a NEXT() entry. */
854 #define NEXT_ENTRY(...) (const enum index []){ __VA_ARGS__, ZERO, }
855
856 /** Static initializer for the args field. */
857 #define ARGS(...) (const struct arg *const []){ __VA_ARGS__, NULL, }
858
859 /** Static initializer for ARGS() to target a field. */
860 #define ARGS_ENTRY(s, f) \
861         (&(const struct arg){ \
862                 .offset = offsetof(s, f), \
863                 .size = sizeof(((s *)0)->f), \
864         })
865
866 /** Static initializer for ARGS() to target a bit-field. */
867 #define ARGS_ENTRY_BF(s, f, b) \
868         (&(const struct arg){ \
869                 .size = sizeof(s), \
870                 .mask = (const void *)&(const s){ .f = (1 << (b)) - 1 }, \
871         })
872
873 /** Static initializer for ARGS() to target a field with limits. */
874 #define ARGS_ENTRY_BOUNDED(s, f, i, a) \
875         (&(const struct arg){ \
876                 .bounded = 1, \
877                 .min = (i), \
878                 .max = (a), \
879                 .offset = offsetof(s, f), \
880                 .size = sizeof(((s *)0)->f), \
881         })
882
883 /** Static initializer for ARGS() to target an arbitrary bit-mask. */
884 #define ARGS_ENTRY_MASK(s, f, m) \
885         (&(const struct arg){ \
886                 .offset = offsetof(s, f), \
887                 .size = sizeof(((s *)0)->f), \
888                 .mask = (const void *)(m), \
889         })
890
891 /** Same as ARGS_ENTRY_MASK() using network byte ordering for the value. */
892 #define ARGS_ENTRY_MASK_HTON(s, f, m) \
893         (&(const struct arg){ \
894                 .hton = 1, \
895                 .offset = offsetof(s, f), \
896                 .size = sizeof(((s *)0)->f), \
897                 .mask = (const void *)(m), \
898         })
899
900 /** Static initializer for ARGS() to target a pointer. */
901 #define ARGS_ENTRY_PTR(s, f) \
902         (&(const struct arg){ \
903                 .size = sizeof(*((s *)0)->f), \
904         })
905
906 /** Static initializer for ARGS() with arbitrary offset and size. */
907 #define ARGS_ENTRY_ARB(o, s) \
908         (&(const struct arg){ \
909                 .offset = (o), \
910                 .size = (s), \
911         })
912
913 /** Same as ARGS_ENTRY_ARB() with bounded values. */
914 #define ARGS_ENTRY_ARB_BOUNDED(o, s, i, a) \
915         (&(const struct arg){ \
916                 .bounded = 1, \
917                 .min = (i), \
918                 .max = (a), \
919                 .offset = (o), \
920                 .size = (s), \
921         })
922
923 /** Same as ARGS_ENTRY() using network byte ordering. */
924 #define ARGS_ENTRY_HTON(s, f) \
925         (&(const struct arg){ \
926                 .hton = 1, \
927                 .offset = offsetof(s, f), \
928                 .size = sizeof(((s *)0)->f), \
929         })
930
931 /** Same as ARGS_ENTRY_HTON() for a single argument, without structure. */
932 #define ARG_ENTRY_HTON(s) \
933         (&(const struct arg){ \
934                 .hton = 1, \
935                 .offset = 0, \
936                 .size = sizeof(s), \
937         })
938
939 /** Parser output buffer layout expected by cmd_flow_parsed(). */
940 struct buffer {
941         enum index command; /**< Flow command. */
942         portid_t port; /**< Affected port ID. */
943         queueid_t queue; /** Async queue ID. */
944         bool postpone; /** Postpone async operation */
945         union {
946                 struct {
947                         struct rte_flow_port_attr port_attr;
948                         uint32_t nb_queue;
949                         struct rte_flow_queue_attr queue_attr;
950                 } configure; /**< Configuration arguments. */
951                 struct {
952                         uint32_t *template_id;
953                         uint32_t template_id_n;
954                 } templ_destroy; /**< Template destroy arguments. */
955                 struct {
956                         uint32_t id;
957                         struct rte_flow_template_table_attr attr;
958                         uint32_t *pat_templ_id;
959                         uint32_t pat_templ_id_n;
960                         uint32_t *act_templ_id;
961                         uint32_t act_templ_id_n;
962                 } table; /**< Table arguments. */
963                 struct {
964                         uint32_t *table_id;
965                         uint32_t table_id_n;
966                 } table_destroy; /**< Template destroy arguments. */
967                 struct {
968                         uint32_t *action_id;
969                         uint32_t action_id_n;
970                 } ia_destroy; /**< Indirect action destroy arguments. */
971                 struct {
972                         uint32_t action_id;
973                 } ia; /* Indirect action query arguments */
974                 struct {
975                         uint32_t table_id;
976                         uint32_t pat_templ_id;
977                         uint32_t act_templ_id;
978                         struct rte_flow_attr attr;
979                         struct tunnel_ops tunnel_ops;
980                         struct rte_flow_item *pattern;
981                         struct rte_flow_action *actions;
982                         struct rte_flow_action *masks;
983                         uint32_t pattern_n;
984                         uint32_t actions_n;
985                         uint8_t *data;
986                 } vc; /**< Validate/create arguments. */
987                 struct {
988                         uint32_t *rule;
989                         uint32_t rule_n;
990                 } destroy; /**< Destroy arguments. */
991                 struct {
992                         char file[128];
993                         bool mode;
994                         uint32_t rule;
995                 } dump; /**< Dump arguments. */
996                 struct {
997                         uint32_t rule;
998                         struct rte_flow_action action;
999                 } query; /**< Query arguments. */
1000                 struct {
1001                         uint32_t *group;
1002                         uint32_t group_n;
1003                 } list; /**< List arguments. */
1004                 struct {
1005                         int set;
1006                 } isolate; /**< Isolated mode arguments. */
1007                 struct {
1008                         int destroy;
1009                 } aged; /**< Aged arguments. */
1010                 struct {
1011                         uint32_t policy_id;
1012                 } policy;/**< Policy arguments. */
1013                 struct {
1014                         uint16_t token;
1015                         uintptr_t uintptr;
1016                         char filename[128];
1017                 } flex; /**< Flex arguments*/
1018         } args; /**< Command arguments. */
1019 };
1020
1021 /** Private data for pattern items. */
1022 struct parse_item_priv {
1023         enum rte_flow_item_type type; /**< Item type. */
1024         uint32_t size; /**< Size of item specification structure. */
1025 };
1026
1027 #define PRIV_ITEM(t, s) \
1028         (&(const struct parse_item_priv){ \
1029                 .type = RTE_FLOW_ITEM_TYPE_ ## t, \
1030                 .size = s, \
1031         })
1032
1033 /** Private data for actions. */
1034 struct parse_action_priv {
1035         enum rte_flow_action_type type; /**< Action type. */
1036         uint32_t size; /**< Size of action configuration structure. */
1037 };
1038
1039 #define PRIV_ACTION(t, s) \
1040         (&(const struct parse_action_priv){ \
1041                 .type = RTE_FLOW_ACTION_TYPE_ ## t, \
1042                 .size = s, \
1043         })
1044
1045 static const enum index next_flex_item[] = {
1046         FLEX_ITEM_INIT,
1047         FLEX_ITEM_CREATE,
1048         FLEX_ITEM_DESTROY,
1049         ZERO,
1050 };
1051
1052 static const enum index next_config_attr[] = {
1053         CONFIG_QUEUES_NUMBER,
1054         CONFIG_QUEUES_SIZE,
1055         CONFIG_COUNTERS_NUMBER,
1056         CONFIG_AGING_OBJECTS_NUMBER,
1057         CONFIG_METERS_NUMBER,
1058         END,
1059         ZERO,
1060 };
1061
1062 static const enum index next_pt_subcmd[] = {
1063         PATTERN_TEMPLATE_CREATE,
1064         PATTERN_TEMPLATE_DESTROY,
1065         ZERO,
1066 };
1067
1068 static const enum index next_pt_attr[] = {
1069         PATTERN_TEMPLATE_CREATE_ID,
1070         PATTERN_TEMPLATE_RELAXED_MATCHING,
1071         PATTERN_TEMPLATE_INGRESS,
1072         PATTERN_TEMPLATE_EGRESS,
1073         PATTERN_TEMPLATE_TRANSFER,
1074         PATTERN_TEMPLATE_SPEC,
1075         ZERO,
1076 };
1077
1078 static const enum index next_pt_destroy_attr[] = {
1079         PATTERN_TEMPLATE_DESTROY_ID,
1080         END,
1081         ZERO,
1082 };
1083
1084 static const enum index next_at_subcmd[] = {
1085         ACTIONS_TEMPLATE_CREATE,
1086         ACTIONS_TEMPLATE_DESTROY,
1087         ZERO,
1088 };
1089
1090 static const enum index next_at_attr[] = {
1091         ACTIONS_TEMPLATE_CREATE_ID,
1092         ACTIONS_TEMPLATE_INGRESS,
1093         ACTIONS_TEMPLATE_EGRESS,
1094         ACTIONS_TEMPLATE_TRANSFER,
1095         ACTIONS_TEMPLATE_SPEC,
1096         ZERO,
1097 };
1098
1099 static const enum index next_at_destroy_attr[] = {
1100         ACTIONS_TEMPLATE_DESTROY_ID,
1101         END,
1102         ZERO,
1103 };
1104
1105 static const enum index next_table_subcmd[] = {
1106         TABLE_CREATE,
1107         TABLE_DESTROY,
1108         ZERO,
1109 };
1110
1111 static const enum index next_table_attr[] = {
1112         TABLE_CREATE_ID,
1113         TABLE_GROUP,
1114         TABLE_PRIORITY,
1115         TABLE_INGRESS,
1116         TABLE_EGRESS,
1117         TABLE_TRANSFER,
1118         TABLE_RULES_NUMBER,
1119         TABLE_PATTERN_TEMPLATE,
1120         TABLE_ACTIONS_TEMPLATE,
1121         END,
1122         ZERO,
1123 };
1124
1125 static const enum index next_table_destroy_attr[] = {
1126         TABLE_DESTROY_ID,
1127         END,
1128         ZERO,
1129 };
1130
1131 static const enum index next_queue_subcmd[] = {
1132         QUEUE_CREATE,
1133         QUEUE_DESTROY,
1134         ZERO,
1135 };
1136
1137 static const enum index next_queue_destroy_attr[] = {
1138         QUEUE_DESTROY_ID,
1139         END,
1140         ZERO,
1141 };
1142
1143 static const enum index next_ia_create_attr[] = {
1144         INDIRECT_ACTION_CREATE_ID,
1145         INDIRECT_ACTION_INGRESS,
1146         INDIRECT_ACTION_EGRESS,
1147         INDIRECT_ACTION_TRANSFER,
1148         INDIRECT_ACTION_SPEC,
1149         ZERO,
1150 };
1151
1152 static const enum index next_dump_subcmd[] = {
1153         DUMP_ALL,
1154         DUMP_ONE,
1155         ZERO,
1156 };
1157
1158 static const enum index next_ia_subcmd[] = {
1159         INDIRECT_ACTION_CREATE,
1160         INDIRECT_ACTION_UPDATE,
1161         INDIRECT_ACTION_DESTROY,
1162         INDIRECT_ACTION_QUERY,
1163         ZERO,
1164 };
1165
1166 static const enum index next_vc_attr[] = {
1167         VC_GROUP,
1168         VC_PRIORITY,
1169         VC_INGRESS,
1170         VC_EGRESS,
1171         VC_TRANSFER,
1172         VC_TUNNEL_SET,
1173         VC_TUNNEL_MATCH,
1174         ITEM_PATTERN,
1175         ZERO,
1176 };
1177
1178 static const enum index next_destroy_attr[] = {
1179         DESTROY_RULE,
1180         END,
1181         ZERO,
1182 };
1183
1184 static const enum index next_dump_attr[] = {
1185         COMMON_FILE_PATH,
1186         END,
1187         ZERO,
1188 };
1189
1190 static const enum index next_list_attr[] = {
1191         LIST_GROUP,
1192         END,
1193         ZERO,
1194 };
1195
1196 static const enum index next_aged_attr[] = {
1197         AGED_DESTROY,
1198         END,
1199         ZERO,
1200 };
1201
1202 static const enum index next_ia_destroy_attr[] = {
1203         INDIRECT_ACTION_DESTROY_ID,
1204         END,
1205         ZERO,
1206 };
1207
1208 static const enum index item_param[] = {
1209         ITEM_PARAM_IS,
1210         ITEM_PARAM_SPEC,
1211         ITEM_PARAM_LAST,
1212         ITEM_PARAM_MASK,
1213         ITEM_PARAM_PREFIX,
1214         ZERO,
1215 };
1216
1217 static const enum index next_item[] = {
1218         ITEM_END,
1219         ITEM_VOID,
1220         ITEM_INVERT,
1221         ITEM_ANY,
1222         ITEM_PF,
1223         ITEM_VF,
1224         ITEM_PHY_PORT,
1225         ITEM_PORT_ID,
1226         ITEM_MARK,
1227         ITEM_RAW,
1228         ITEM_ETH,
1229         ITEM_VLAN,
1230         ITEM_IPV4,
1231         ITEM_IPV6,
1232         ITEM_ICMP,
1233         ITEM_UDP,
1234         ITEM_TCP,
1235         ITEM_SCTP,
1236         ITEM_VXLAN,
1237         ITEM_E_TAG,
1238         ITEM_NVGRE,
1239         ITEM_MPLS,
1240         ITEM_GRE,
1241         ITEM_FUZZY,
1242         ITEM_GTP,
1243         ITEM_GTPC,
1244         ITEM_GTPU,
1245         ITEM_GENEVE,
1246         ITEM_VXLAN_GPE,
1247         ITEM_ARP_ETH_IPV4,
1248         ITEM_IPV6_EXT,
1249         ITEM_IPV6_FRAG_EXT,
1250         ITEM_ICMP6,
1251         ITEM_ICMP6_ND_NS,
1252         ITEM_ICMP6_ND_NA,
1253         ITEM_ICMP6_ND_OPT,
1254         ITEM_ICMP6_ND_OPT_SLA_ETH,
1255         ITEM_ICMP6_ND_OPT_TLA_ETH,
1256         ITEM_META,
1257         ITEM_GRE_KEY,
1258         ITEM_GRE_OPTION,
1259         ITEM_GTP_PSC,
1260         ITEM_PPPOES,
1261         ITEM_PPPOED,
1262         ITEM_PPPOE_PROTO_ID,
1263         ITEM_HIGIG2,
1264         ITEM_TAG,
1265         ITEM_L2TPV3OIP,
1266         ITEM_ESP,
1267         ITEM_AH,
1268         ITEM_PFCP,
1269         ITEM_ECPRI,
1270         ITEM_GENEVE_OPT,
1271         ITEM_INTEGRITY,
1272         ITEM_CONNTRACK,
1273         ITEM_PORT_REPRESENTOR,
1274         ITEM_REPRESENTED_PORT,
1275         ITEM_FLEX,
1276         ITEM_L2TPV2,
1277         ITEM_PPP,
1278         END_SET,
1279         ZERO,
1280 };
1281
1282 static const enum index item_fuzzy[] = {
1283         ITEM_FUZZY_THRESH,
1284         ITEM_NEXT,
1285         ZERO,
1286 };
1287
1288 static const enum index item_any[] = {
1289         ITEM_ANY_NUM,
1290         ITEM_NEXT,
1291         ZERO,
1292 };
1293
1294 static const enum index item_vf[] = {
1295         ITEM_VF_ID,
1296         ITEM_NEXT,
1297         ZERO,
1298 };
1299
1300 static const enum index item_phy_port[] = {
1301         ITEM_PHY_PORT_INDEX,
1302         ITEM_NEXT,
1303         ZERO,
1304 };
1305
1306 static const enum index item_port_id[] = {
1307         ITEM_PORT_ID_ID,
1308         ITEM_NEXT,
1309         ZERO,
1310 };
1311
1312 static const enum index item_mark[] = {
1313         ITEM_MARK_ID,
1314         ITEM_NEXT,
1315         ZERO,
1316 };
1317
1318 static const enum index item_raw[] = {
1319         ITEM_RAW_RELATIVE,
1320         ITEM_RAW_SEARCH,
1321         ITEM_RAW_OFFSET,
1322         ITEM_RAW_LIMIT,
1323         ITEM_RAW_PATTERN,
1324         ITEM_RAW_PATTERN_HEX,
1325         ITEM_NEXT,
1326         ZERO,
1327 };
1328
1329 static const enum index item_eth[] = {
1330         ITEM_ETH_DST,
1331         ITEM_ETH_SRC,
1332         ITEM_ETH_TYPE,
1333         ITEM_ETH_HAS_VLAN,
1334         ITEM_NEXT,
1335         ZERO,
1336 };
1337
1338 static const enum index item_vlan[] = {
1339         ITEM_VLAN_TCI,
1340         ITEM_VLAN_PCP,
1341         ITEM_VLAN_DEI,
1342         ITEM_VLAN_VID,
1343         ITEM_VLAN_INNER_TYPE,
1344         ITEM_VLAN_HAS_MORE_VLAN,
1345         ITEM_NEXT,
1346         ZERO,
1347 };
1348
1349 static const enum index item_ipv4[] = {
1350         ITEM_IPV4_VER_IHL,
1351         ITEM_IPV4_TOS,
1352         ITEM_IPV4_ID,
1353         ITEM_IPV4_FRAGMENT_OFFSET,
1354         ITEM_IPV4_TTL,
1355         ITEM_IPV4_PROTO,
1356         ITEM_IPV4_SRC,
1357         ITEM_IPV4_DST,
1358         ITEM_NEXT,
1359         ZERO,
1360 };
1361
1362 static const enum index item_ipv6[] = {
1363         ITEM_IPV6_TC,
1364         ITEM_IPV6_FLOW,
1365         ITEM_IPV6_PROTO,
1366         ITEM_IPV6_HOP,
1367         ITEM_IPV6_SRC,
1368         ITEM_IPV6_DST,
1369         ITEM_IPV6_HAS_FRAG_EXT,
1370         ITEM_NEXT,
1371         ZERO,
1372 };
1373
1374 static const enum index item_icmp[] = {
1375         ITEM_ICMP_TYPE,
1376         ITEM_ICMP_CODE,
1377         ITEM_ICMP_IDENT,
1378         ITEM_ICMP_SEQ,
1379         ITEM_NEXT,
1380         ZERO,
1381 };
1382
1383 static const enum index item_udp[] = {
1384         ITEM_UDP_SRC,
1385         ITEM_UDP_DST,
1386         ITEM_NEXT,
1387         ZERO,
1388 };
1389
1390 static const enum index item_tcp[] = {
1391         ITEM_TCP_SRC,
1392         ITEM_TCP_DST,
1393         ITEM_TCP_FLAGS,
1394         ITEM_NEXT,
1395         ZERO,
1396 };
1397
1398 static const enum index item_sctp[] = {
1399         ITEM_SCTP_SRC,
1400         ITEM_SCTP_DST,
1401         ITEM_SCTP_TAG,
1402         ITEM_SCTP_CKSUM,
1403         ITEM_NEXT,
1404         ZERO,
1405 };
1406
1407 static const enum index item_vxlan[] = {
1408         ITEM_VXLAN_VNI,
1409         ITEM_VXLAN_LAST_RSVD,
1410         ITEM_NEXT,
1411         ZERO,
1412 };
1413
1414 static const enum index item_e_tag[] = {
1415         ITEM_E_TAG_GRP_ECID_B,
1416         ITEM_NEXT,
1417         ZERO,
1418 };
1419
1420 static const enum index item_nvgre[] = {
1421         ITEM_NVGRE_TNI,
1422         ITEM_NEXT,
1423         ZERO,
1424 };
1425
1426 static const enum index item_mpls[] = {
1427         ITEM_MPLS_LABEL,
1428         ITEM_MPLS_TC,
1429         ITEM_MPLS_S,
1430         ITEM_NEXT,
1431         ZERO,
1432 };
1433
1434 static const enum index item_gre[] = {
1435         ITEM_GRE_PROTO,
1436         ITEM_GRE_C_RSVD0_VER,
1437         ITEM_GRE_C_BIT,
1438         ITEM_GRE_K_BIT,
1439         ITEM_GRE_S_BIT,
1440         ITEM_NEXT,
1441         ZERO,
1442 };
1443
1444 static const enum index item_gre_key[] = {
1445         ITEM_GRE_KEY_VALUE,
1446         ITEM_NEXT,
1447         ZERO,
1448 };
1449
1450 static const enum index item_gre_option[] = {
1451         ITEM_GRE_OPTION_CHECKSUM,
1452         ITEM_GRE_OPTION_KEY,
1453         ITEM_GRE_OPTION_SEQUENCE,
1454         ITEM_NEXT,
1455         ZERO,
1456 };
1457
1458 static const enum index item_gtp[] = {
1459         ITEM_GTP_FLAGS,
1460         ITEM_GTP_MSG_TYPE,
1461         ITEM_GTP_TEID,
1462         ITEM_NEXT,
1463         ZERO,
1464 };
1465
1466 static const enum index item_geneve[] = {
1467         ITEM_GENEVE_VNI,
1468         ITEM_GENEVE_PROTO,
1469         ITEM_GENEVE_OPTLEN,
1470         ITEM_NEXT,
1471         ZERO,
1472 };
1473
1474 static const enum index item_vxlan_gpe[] = {
1475         ITEM_VXLAN_GPE_VNI,
1476         ITEM_NEXT,
1477         ZERO,
1478 };
1479
1480 static const enum index item_arp_eth_ipv4[] = {
1481         ITEM_ARP_ETH_IPV4_SHA,
1482         ITEM_ARP_ETH_IPV4_SPA,
1483         ITEM_ARP_ETH_IPV4_THA,
1484         ITEM_ARP_ETH_IPV4_TPA,
1485         ITEM_NEXT,
1486         ZERO,
1487 };
1488
1489 static const enum index item_ipv6_ext[] = {
1490         ITEM_IPV6_EXT_NEXT_HDR,
1491         ITEM_NEXT,
1492         ZERO,
1493 };
1494
1495 static const enum index item_ipv6_frag_ext[] = {
1496         ITEM_IPV6_FRAG_EXT_NEXT_HDR,
1497         ITEM_IPV6_FRAG_EXT_FRAG_DATA,
1498         ITEM_IPV6_FRAG_EXT_ID,
1499         ITEM_NEXT,
1500         ZERO,
1501 };
1502
1503 static const enum index item_icmp6[] = {
1504         ITEM_ICMP6_TYPE,
1505         ITEM_ICMP6_CODE,
1506         ITEM_NEXT,
1507         ZERO,
1508 };
1509
1510 static const enum index item_icmp6_nd_ns[] = {
1511         ITEM_ICMP6_ND_NS_TARGET_ADDR,
1512         ITEM_NEXT,
1513         ZERO,
1514 };
1515
1516 static const enum index item_icmp6_nd_na[] = {
1517         ITEM_ICMP6_ND_NA_TARGET_ADDR,
1518         ITEM_NEXT,
1519         ZERO,
1520 };
1521
1522 static const enum index item_icmp6_nd_opt[] = {
1523         ITEM_ICMP6_ND_OPT_TYPE,
1524         ITEM_NEXT,
1525         ZERO,
1526 };
1527
1528 static const enum index item_icmp6_nd_opt_sla_eth[] = {
1529         ITEM_ICMP6_ND_OPT_SLA_ETH_SLA,
1530         ITEM_NEXT,
1531         ZERO,
1532 };
1533
1534 static const enum index item_icmp6_nd_opt_tla_eth[] = {
1535         ITEM_ICMP6_ND_OPT_TLA_ETH_TLA,
1536         ITEM_NEXT,
1537         ZERO,
1538 };
1539
1540 static const enum index item_meta[] = {
1541         ITEM_META_DATA,
1542         ITEM_NEXT,
1543         ZERO,
1544 };
1545
1546 static const enum index item_gtp_psc[] = {
1547         ITEM_GTP_PSC_QFI,
1548         ITEM_GTP_PSC_PDU_T,
1549         ITEM_NEXT,
1550         ZERO,
1551 };
1552
1553 static const enum index item_pppoed[] = {
1554         ITEM_PPPOE_SEID,
1555         ITEM_NEXT,
1556         ZERO,
1557 };
1558
1559 static const enum index item_pppoes[] = {
1560         ITEM_PPPOE_SEID,
1561         ITEM_NEXT,
1562         ZERO,
1563 };
1564
1565 static const enum index item_pppoe_proto_id[] = {
1566         ITEM_NEXT,
1567         ZERO,
1568 };
1569
1570 static const enum index item_higig2[] = {
1571         ITEM_HIGIG2_CLASSIFICATION,
1572         ITEM_HIGIG2_VID,
1573         ITEM_NEXT,
1574         ZERO,
1575 };
1576
1577 static const enum index item_esp[] = {
1578         ITEM_ESP_SPI,
1579         ITEM_NEXT,
1580         ZERO,
1581 };
1582
1583 static const enum index item_ah[] = {
1584         ITEM_AH_SPI,
1585         ITEM_NEXT,
1586         ZERO,
1587 };
1588
1589 static const enum index item_pfcp[] = {
1590         ITEM_PFCP_S_FIELD,
1591         ITEM_PFCP_SEID,
1592         ITEM_NEXT,
1593         ZERO,
1594 };
1595
1596 static const enum index next_set_raw[] = {
1597         SET_RAW_INDEX,
1598         ITEM_ETH,
1599         ZERO,
1600 };
1601
1602 static const enum index item_tag[] = {
1603         ITEM_TAG_DATA,
1604         ITEM_TAG_INDEX,
1605         ITEM_NEXT,
1606         ZERO,
1607 };
1608
1609 static const enum index item_l2tpv3oip[] = {
1610         ITEM_L2TPV3OIP_SESSION_ID,
1611         ITEM_NEXT,
1612         ZERO,
1613 };
1614
1615 static const enum index item_ecpri[] = {
1616         ITEM_ECPRI_COMMON,
1617         ITEM_NEXT,
1618         ZERO,
1619 };
1620
1621 static const enum index item_ecpri_common[] = {
1622         ITEM_ECPRI_COMMON_TYPE,
1623         ZERO,
1624 };
1625
1626 static const enum index item_ecpri_common_type[] = {
1627         ITEM_ECPRI_COMMON_TYPE_IQ_DATA,
1628         ITEM_ECPRI_COMMON_TYPE_RTC_CTRL,
1629         ITEM_ECPRI_COMMON_TYPE_DLY_MSR,
1630         ZERO,
1631 };
1632
1633 static const enum index item_geneve_opt[] = {
1634         ITEM_GENEVE_OPT_CLASS,
1635         ITEM_GENEVE_OPT_TYPE,
1636         ITEM_GENEVE_OPT_LENGTH,
1637         ITEM_GENEVE_OPT_DATA,
1638         ITEM_NEXT,
1639         ZERO,
1640 };
1641
1642 static const enum index item_integrity[] = {
1643         ITEM_INTEGRITY_LEVEL,
1644         ITEM_INTEGRITY_VALUE,
1645         ZERO,
1646 };
1647
1648 static const enum index item_integrity_lv[] = {
1649         ITEM_INTEGRITY_LEVEL,
1650         ITEM_INTEGRITY_VALUE,
1651         ITEM_NEXT,
1652         ZERO,
1653 };
1654
1655 static const enum index item_port_representor[] = {
1656         ITEM_PORT_REPRESENTOR_PORT_ID,
1657         ITEM_NEXT,
1658         ZERO,
1659 };
1660
1661 static const enum index item_represented_port[] = {
1662         ITEM_REPRESENTED_PORT_ETHDEV_PORT_ID,
1663         ITEM_NEXT,
1664         ZERO,
1665 };
1666
1667 static const enum index item_flex[] = {
1668         ITEM_FLEX_PATTERN_HANDLE,
1669         ITEM_FLEX_ITEM_HANDLE,
1670         ITEM_NEXT,
1671         ZERO,
1672 };
1673
1674 static const enum index item_l2tpv2[] = {
1675         ITEM_L2TPV2_TYPE,
1676         ITEM_NEXT,
1677         ZERO,
1678 };
1679
1680 static const enum index item_l2tpv2_type[] = {
1681         ITEM_L2TPV2_TYPE_DATA,
1682         ITEM_L2TPV2_TYPE_DATA_L,
1683         ITEM_L2TPV2_TYPE_DATA_S,
1684         ITEM_L2TPV2_TYPE_DATA_O,
1685         ITEM_L2TPV2_TYPE_DATA_L_S,
1686         ITEM_L2TPV2_TYPE_CTRL,
1687         ZERO,
1688 };
1689
1690 static const enum index item_l2tpv2_type_data[] = {
1691         ITEM_L2TPV2_MSG_DATA_TUNNEL_ID,
1692         ITEM_L2TPV2_MSG_DATA_SESSION_ID,
1693         ITEM_NEXT,
1694         ZERO,
1695 };
1696
1697 static const enum index item_l2tpv2_type_data_l[] = {
1698         ITEM_L2TPV2_MSG_DATA_L_LENGTH,
1699         ITEM_L2TPV2_MSG_DATA_L_TUNNEL_ID,
1700         ITEM_L2TPV2_MSG_DATA_L_SESSION_ID,
1701         ITEM_NEXT,
1702         ZERO,
1703 };
1704
1705 static const enum index item_l2tpv2_type_data_s[] = {
1706         ITEM_L2TPV2_MSG_DATA_S_TUNNEL_ID,
1707         ITEM_L2TPV2_MSG_DATA_S_SESSION_ID,
1708         ITEM_L2TPV2_MSG_DATA_S_NS,
1709         ITEM_L2TPV2_MSG_DATA_S_NR,
1710         ITEM_NEXT,
1711         ZERO,
1712 };
1713
1714 static const enum index item_l2tpv2_type_data_o[] = {
1715         ITEM_L2TPV2_MSG_DATA_O_TUNNEL_ID,
1716         ITEM_L2TPV2_MSG_DATA_O_SESSION_ID,
1717         ITEM_L2TPV2_MSG_DATA_O_OFFSET,
1718         ITEM_NEXT,
1719         ZERO,
1720 };
1721
1722 static const enum index item_l2tpv2_type_data_l_s[] = {
1723         ITEM_L2TPV2_MSG_DATA_L_S_LENGTH,
1724         ITEM_L2TPV2_MSG_DATA_L_S_TUNNEL_ID,
1725         ITEM_L2TPV2_MSG_DATA_L_S_SESSION_ID,
1726         ITEM_L2TPV2_MSG_DATA_L_S_NS,
1727         ITEM_L2TPV2_MSG_DATA_L_S_NR,
1728         ITEM_NEXT,
1729         ZERO,
1730 };
1731
1732 static const enum index item_l2tpv2_type_ctrl[] = {
1733         ITEM_L2TPV2_MSG_CTRL_LENGTH,
1734         ITEM_L2TPV2_MSG_CTRL_TUNNEL_ID,
1735         ITEM_L2TPV2_MSG_CTRL_SESSION_ID,
1736         ITEM_L2TPV2_MSG_CTRL_NS,
1737         ITEM_L2TPV2_MSG_CTRL_NR,
1738         ITEM_NEXT,
1739         ZERO,
1740 };
1741
1742 static const enum index item_ppp[] = {
1743         ITEM_PPP_ADDR,
1744         ITEM_PPP_CTRL,
1745         ITEM_PPP_PROTO_ID,
1746         ITEM_NEXT,
1747         ZERO,
1748 };
1749
1750 static const enum index next_action[] = {
1751         ACTION_END,
1752         ACTION_VOID,
1753         ACTION_PASSTHRU,
1754         ACTION_JUMP,
1755         ACTION_MARK,
1756         ACTION_FLAG,
1757         ACTION_QUEUE,
1758         ACTION_DROP,
1759         ACTION_COUNT,
1760         ACTION_RSS,
1761         ACTION_PF,
1762         ACTION_VF,
1763         ACTION_PHY_PORT,
1764         ACTION_PORT_ID,
1765         ACTION_METER,
1766         ACTION_METER_COLOR,
1767         ACTION_OF_SET_MPLS_TTL,
1768         ACTION_OF_DEC_MPLS_TTL,
1769         ACTION_OF_SET_NW_TTL,
1770         ACTION_OF_DEC_NW_TTL,
1771         ACTION_OF_COPY_TTL_OUT,
1772         ACTION_OF_COPY_TTL_IN,
1773         ACTION_OF_POP_VLAN,
1774         ACTION_OF_PUSH_VLAN,
1775         ACTION_OF_SET_VLAN_VID,
1776         ACTION_OF_SET_VLAN_PCP,
1777         ACTION_OF_POP_MPLS,
1778         ACTION_OF_PUSH_MPLS,
1779         ACTION_VXLAN_ENCAP,
1780         ACTION_VXLAN_DECAP,
1781         ACTION_NVGRE_ENCAP,
1782         ACTION_NVGRE_DECAP,
1783         ACTION_L2_ENCAP,
1784         ACTION_L2_DECAP,
1785         ACTION_MPLSOGRE_ENCAP,
1786         ACTION_MPLSOGRE_DECAP,
1787         ACTION_MPLSOUDP_ENCAP,
1788         ACTION_MPLSOUDP_DECAP,
1789         ACTION_SET_IPV4_SRC,
1790         ACTION_SET_IPV4_DST,
1791         ACTION_SET_IPV6_SRC,
1792         ACTION_SET_IPV6_DST,
1793         ACTION_SET_TP_SRC,
1794         ACTION_SET_TP_DST,
1795         ACTION_MAC_SWAP,
1796         ACTION_DEC_TTL,
1797         ACTION_SET_TTL,
1798         ACTION_SET_MAC_SRC,
1799         ACTION_SET_MAC_DST,
1800         ACTION_INC_TCP_SEQ,
1801         ACTION_DEC_TCP_SEQ,
1802         ACTION_INC_TCP_ACK,
1803         ACTION_DEC_TCP_ACK,
1804         ACTION_RAW_ENCAP,
1805         ACTION_RAW_DECAP,
1806         ACTION_SET_TAG,
1807         ACTION_SET_META,
1808         ACTION_SET_IPV4_DSCP,
1809         ACTION_SET_IPV6_DSCP,
1810         ACTION_AGE,
1811         ACTION_SAMPLE,
1812         ACTION_INDIRECT,
1813         ACTION_MODIFY_FIELD,
1814         ACTION_CONNTRACK,
1815         ACTION_CONNTRACK_UPDATE,
1816         ACTION_PORT_REPRESENTOR,
1817         ACTION_REPRESENTED_PORT,
1818         ZERO,
1819 };
1820
1821 static const enum index action_mark[] = {
1822         ACTION_MARK_ID,
1823         ACTION_NEXT,
1824         ZERO,
1825 };
1826
1827 static const enum index action_queue[] = {
1828         ACTION_QUEUE_INDEX,
1829         ACTION_NEXT,
1830         ZERO,
1831 };
1832
1833 static const enum index action_count[] = {
1834         ACTION_COUNT_ID,
1835         ACTION_NEXT,
1836         ZERO,
1837 };
1838
1839 static const enum index action_rss[] = {
1840         ACTION_RSS_FUNC,
1841         ACTION_RSS_LEVEL,
1842         ACTION_RSS_TYPES,
1843         ACTION_RSS_KEY,
1844         ACTION_RSS_KEY_LEN,
1845         ACTION_RSS_QUEUES,
1846         ACTION_NEXT,
1847         ZERO,
1848 };
1849
1850 static const enum index action_vf[] = {
1851         ACTION_VF_ORIGINAL,
1852         ACTION_VF_ID,
1853         ACTION_NEXT,
1854         ZERO,
1855 };
1856
1857 static const enum index action_phy_port[] = {
1858         ACTION_PHY_PORT_ORIGINAL,
1859         ACTION_PHY_PORT_INDEX,
1860         ACTION_NEXT,
1861         ZERO,
1862 };
1863
1864 static const enum index action_port_id[] = {
1865         ACTION_PORT_ID_ORIGINAL,
1866         ACTION_PORT_ID_ID,
1867         ACTION_NEXT,
1868         ZERO,
1869 };
1870
1871 static const enum index action_meter[] = {
1872         ACTION_METER_ID,
1873         ACTION_NEXT,
1874         ZERO,
1875 };
1876
1877 static const enum index action_meter_color[] = {
1878         ACTION_METER_COLOR_TYPE,
1879         ACTION_NEXT,
1880         ZERO,
1881 };
1882
1883 static const enum index action_of_set_mpls_ttl[] = {
1884         ACTION_OF_SET_MPLS_TTL_MPLS_TTL,
1885         ACTION_NEXT,
1886         ZERO,
1887 };
1888
1889 static const enum index action_of_set_nw_ttl[] = {
1890         ACTION_OF_SET_NW_TTL_NW_TTL,
1891         ACTION_NEXT,
1892         ZERO,
1893 };
1894
1895 static const enum index action_of_push_vlan[] = {
1896         ACTION_OF_PUSH_VLAN_ETHERTYPE,
1897         ACTION_NEXT,
1898         ZERO,
1899 };
1900
1901 static const enum index action_of_set_vlan_vid[] = {
1902         ACTION_OF_SET_VLAN_VID_VLAN_VID,
1903         ACTION_NEXT,
1904         ZERO,
1905 };
1906
1907 static const enum index action_of_set_vlan_pcp[] = {
1908         ACTION_OF_SET_VLAN_PCP_VLAN_PCP,
1909         ACTION_NEXT,
1910         ZERO,
1911 };
1912
1913 static const enum index action_of_pop_mpls[] = {
1914         ACTION_OF_POP_MPLS_ETHERTYPE,
1915         ACTION_NEXT,
1916         ZERO,
1917 };
1918
1919 static const enum index action_of_push_mpls[] = {
1920         ACTION_OF_PUSH_MPLS_ETHERTYPE,
1921         ACTION_NEXT,
1922         ZERO,
1923 };
1924
1925 static const enum index action_set_ipv4_src[] = {
1926         ACTION_SET_IPV4_SRC_IPV4_SRC,
1927         ACTION_NEXT,
1928         ZERO,
1929 };
1930
1931 static const enum index action_set_mac_src[] = {
1932         ACTION_SET_MAC_SRC_MAC_SRC,
1933         ACTION_NEXT,
1934         ZERO,
1935 };
1936
1937 static const enum index action_set_ipv4_dst[] = {
1938         ACTION_SET_IPV4_DST_IPV4_DST,
1939         ACTION_NEXT,
1940         ZERO,
1941 };
1942
1943 static const enum index action_set_ipv6_src[] = {
1944         ACTION_SET_IPV6_SRC_IPV6_SRC,
1945         ACTION_NEXT,
1946         ZERO,
1947 };
1948
1949 static const enum index action_set_ipv6_dst[] = {
1950         ACTION_SET_IPV6_DST_IPV6_DST,
1951         ACTION_NEXT,
1952         ZERO,
1953 };
1954
1955 static const enum index action_set_tp_src[] = {
1956         ACTION_SET_TP_SRC_TP_SRC,
1957         ACTION_NEXT,
1958         ZERO,
1959 };
1960
1961 static const enum index action_set_tp_dst[] = {
1962         ACTION_SET_TP_DST_TP_DST,
1963         ACTION_NEXT,
1964         ZERO,
1965 };
1966
1967 static const enum index action_set_ttl[] = {
1968         ACTION_SET_TTL_TTL,
1969         ACTION_NEXT,
1970         ZERO,
1971 };
1972
1973 static const enum index action_jump[] = {
1974         ACTION_JUMP_GROUP,
1975         ACTION_NEXT,
1976         ZERO,
1977 };
1978
1979 static const enum index action_set_mac_dst[] = {
1980         ACTION_SET_MAC_DST_MAC_DST,
1981         ACTION_NEXT,
1982         ZERO,
1983 };
1984
1985 static const enum index action_inc_tcp_seq[] = {
1986         ACTION_INC_TCP_SEQ_VALUE,
1987         ACTION_NEXT,
1988         ZERO,
1989 };
1990
1991 static const enum index action_dec_tcp_seq[] = {
1992         ACTION_DEC_TCP_SEQ_VALUE,
1993         ACTION_NEXT,
1994         ZERO,
1995 };
1996
1997 static const enum index action_inc_tcp_ack[] = {
1998         ACTION_INC_TCP_ACK_VALUE,
1999         ACTION_NEXT,
2000         ZERO,
2001 };
2002
2003 static const enum index action_dec_tcp_ack[] = {
2004         ACTION_DEC_TCP_ACK_VALUE,
2005         ACTION_NEXT,
2006         ZERO,
2007 };
2008
2009 static const enum index action_raw_encap[] = {
2010         ACTION_RAW_ENCAP_INDEX,
2011         ACTION_NEXT,
2012         ZERO,
2013 };
2014
2015 static const enum index action_raw_decap[] = {
2016         ACTION_RAW_DECAP_INDEX,
2017         ACTION_NEXT,
2018         ZERO,
2019 };
2020
2021 static const enum index action_set_tag[] = {
2022         ACTION_SET_TAG_DATA,
2023         ACTION_SET_TAG_INDEX,
2024         ACTION_SET_TAG_MASK,
2025         ACTION_NEXT,
2026         ZERO,
2027 };
2028
2029 static const enum index action_set_meta[] = {
2030         ACTION_SET_META_DATA,
2031         ACTION_SET_META_MASK,
2032         ACTION_NEXT,
2033         ZERO,
2034 };
2035
2036 static const enum index action_set_ipv4_dscp[] = {
2037         ACTION_SET_IPV4_DSCP_VALUE,
2038         ACTION_NEXT,
2039         ZERO,
2040 };
2041
2042 static const enum index action_set_ipv6_dscp[] = {
2043         ACTION_SET_IPV6_DSCP_VALUE,
2044         ACTION_NEXT,
2045         ZERO,
2046 };
2047
2048 static const enum index action_age[] = {
2049         ACTION_AGE,
2050         ACTION_AGE_TIMEOUT,
2051         ACTION_NEXT,
2052         ZERO,
2053 };
2054
2055 static const enum index action_sample[] = {
2056         ACTION_SAMPLE,
2057         ACTION_SAMPLE_RATIO,
2058         ACTION_SAMPLE_INDEX,
2059         ACTION_NEXT,
2060         ZERO,
2061 };
2062
2063 static const enum index next_action_sample[] = {
2064         ACTION_QUEUE,
2065         ACTION_RSS,
2066         ACTION_MARK,
2067         ACTION_COUNT,
2068         ACTION_PORT_ID,
2069         ACTION_RAW_ENCAP,
2070         ACTION_VXLAN_ENCAP,
2071         ACTION_NVGRE_ENCAP,
2072         ACTION_NEXT,
2073         ZERO,
2074 };
2075
2076 static const enum index action_modify_field_dst[] = {
2077         ACTION_MODIFY_FIELD_DST_LEVEL,
2078         ACTION_MODIFY_FIELD_DST_OFFSET,
2079         ACTION_MODIFY_FIELD_SRC_TYPE,
2080         ZERO,
2081 };
2082
2083 static const enum index action_modify_field_src[] = {
2084         ACTION_MODIFY_FIELD_SRC_LEVEL,
2085         ACTION_MODIFY_FIELD_SRC_OFFSET,
2086         ACTION_MODIFY_FIELD_SRC_VALUE,
2087         ACTION_MODIFY_FIELD_SRC_POINTER,
2088         ACTION_MODIFY_FIELD_WIDTH,
2089         ZERO,
2090 };
2091
2092 static const enum index action_update_conntrack[] = {
2093         ACTION_CONNTRACK_UPDATE_DIR,
2094         ACTION_CONNTRACK_UPDATE_CTX,
2095         ACTION_NEXT,
2096         ZERO,
2097 };
2098
2099 static const enum index action_port_representor[] = {
2100         ACTION_PORT_REPRESENTOR_PORT_ID,
2101         ACTION_NEXT,
2102         ZERO,
2103 };
2104
2105 static const enum index action_represented_port[] = {
2106         ACTION_REPRESENTED_PORT_ETHDEV_PORT_ID,
2107         ACTION_NEXT,
2108         ZERO,
2109 };
2110
2111 static int parse_set_raw_encap_decap(struct context *, const struct token *,
2112                                      const char *, unsigned int,
2113                                      void *, unsigned int);
2114 static int parse_set_sample_action(struct context *, const struct token *,
2115                                    const char *, unsigned int,
2116                                    void *, unsigned int);
2117 static int parse_set_init(struct context *, const struct token *,
2118                           const char *, unsigned int,
2119                           void *, unsigned int);
2120 static int
2121 parse_flex_handle(struct context *, const struct token *,
2122                   const char *, unsigned int, void *, unsigned int);
2123 static int parse_init(struct context *, const struct token *,
2124                       const char *, unsigned int,
2125                       void *, unsigned int);
2126 static int parse_vc(struct context *, const struct token *,
2127                     const char *, unsigned int,
2128                     void *, unsigned int);
2129 static int parse_vc_spec(struct context *, const struct token *,
2130                          const char *, unsigned int, void *, unsigned int);
2131 static int parse_vc_conf(struct context *, const struct token *,
2132                          const char *, unsigned int, void *, unsigned int);
2133 static int parse_vc_item_ecpri_type(struct context *, const struct token *,
2134                                     const char *, unsigned int,
2135                                     void *, unsigned int);
2136 static int parse_vc_item_l2tpv2_type(struct context *, const struct token *,
2137                                     const char *, unsigned int,
2138                                     void *, unsigned int);
2139 static int parse_vc_action_meter_color_type(struct context *,
2140                                         const struct token *,
2141                                         const char *, unsigned int, void *,
2142                                         unsigned int);
2143 static int parse_vc_action_rss(struct context *, const struct token *,
2144                                const char *, unsigned int, void *,
2145                                unsigned int);
2146 static int parse_vc_action_rss_func(struct context *, const struct token *,
2147                                     const char *, unsigned int, void *,
2148                                     unsigned int);
2149 static int parse_vc_action_rss_type(struct context *, const struct token *,
2150                                     const char *, unsigned int, void *,
2151                                     unsigned int);
2152 static int parse_vc_action_rss_queue(struct context *, const struct token *,
2153                                      const char *, unsigned int, void *,
2154                                      unsigned int);
2155 static int parse_vc_action_vxlan_encap(struct context *, const struct token *,
2156                                        const char *, unsigned int, void *,
2157                                        unsigned int);
2158 static int parse_vc_action_nvgre_encap(struct context *, const struct token *,
2159                                        const char *, unsigned int, void *,
2160                                        unsigned int);
2161 static int parse_vc_action_l2_encap(struct context *, const struct token *,
2162                                     const char *, unsigned int, void *,
2163                                     unsigned int);
2164 static int parse_vc_action_l2_decap(struct context *, const struct token *,
2165                                     const char *, unsigned int, void *,
2166                                     unsigned int);
2167 static int parse_vc_action_mplsogre_encap(struct context *,
2168                                           const struct token *, const char *,
2169                                           unsigned int, void *, unsigned int);
2170 static int parse_vc_action_mplsogre_decap(struct context *,
2171                                           const struct token *, const char *,
2172                                           unsigned int, void *, unsigned int);
2173 static int parse_vc_action_mplsoudp_encap(struct context *,
2174                                           const struct token *, const char *,
2175                                           unsigned int, void *, unsigned int);
2176 static int parse_vc_action_mplsoudp_decap(struct context *,
2177                                           const struct token *, const char *,
2178                                           unsigned int, void *, unsigned int);
2179 static int parse_vc_action_raw_encap(struct context *,
2180                                      const struct token *, const char *,
2181                                      unsigned int, void *, unsigned int);
2182 static int parse_vc_action_raw_decap(struct context *,
2183                                      const struct token *, const char *,
2184                                      unsigned int, void *, unsigned int);
2185 static int parse_vc_action_raw_encap_index(struct context *,
2186                                            const struct token *, const char *,
2187                                            unsigned int, void *, unsigned int);
2188 static int parse_vc_action_raw_decap_index(struct context *,
2189                                            const struct token *, const char *,
2190                                            unsigned int, void *, unsigned int);
2191 static int parse_vc_action_set_meta(struct context *ctx,
2192                                     const struct token *token, const char *str,
2193                                     unsigned int len, void *buf,
2194                                         unsigned int size);
2195 static int parse_vc_action_sample(struct context *ctx,
2196                                     const struct token *token, const char *str,
2197                                     unsigned int len, void *buf,
2198                                     unsigned int size);
2199 static int
2200 parse_vc_action_sample_index(struct context *ctx, const struct token *token,
2201                                 const char *str, unsigned int len, void *buf,
2202                                 unsigned int size);
2203 static int
2204 parse_vc_modify_field_op(struct context *ctx, const struct token *token,
2205                                 const char *str, unsigned int len, void *buf,
2206                                 unsigned int size);
2207 static int
2208 parse_vc_modify_field_id(struct context *ctx, const struct token *token,
2209                                 const char *str, unsigned int len, void *buf,
2210                                 unsigned int size);
2211 static int
2212 parse_vc_action_conntrack_update(struct context *ctx, const struct token *token,
2213                          const char *str, unsigned int len, void *buf,
2214                          unsigned int size);
2215 static int parse_destroy(struct context *, const struct token *,
2216                          const char *, unsigned int,
2217                          void *, unsigned int);
2218 static int parse_flush(struct context *, const struct token *,
2219                        const char *, unsigned int,
2220                        void *, unsigned int);
2221 static int parse_dump(struct context *, const struct token *,
2222                       const char *, unsigned int,
2223                       void *, unsigned int);
2224 static int parse_query(struct context *, const struct token *,
2225                        const char *, unsigned int,
2226                        void *, unsigned int);
2227 static int parse_action(struct context *, const struct token *,
2228                         const char *, unsigned int,
2229                         void *, unsigned int);
2230 static int parse_list(struct context *, const struct token *,
2231                       const char *, unsigned int,
2232                       void *, unsigned int);
2233 static int parse_aged(struct context *, const struct token *,
2234                       const char *, unsigned int,
2235                       void *, unsigned int);
2236 static int parse_isolate(struct context *, const struct token *,
2237                          const char *, unsigned int,
2238                          void *, unsigned int);
2239 static int parse_configure(struct context *, const struct token *,
2240                            const char *, unsigned int,
2241                            void *, unsigned int);
2242 static int parse_template(struct context *, const struct token *,
2243                           const char *, unsigned int,
2244                           void *, unsigned int);
2245 static int parse_template_destroy(struct context *, const struct token *,
2246                                   const char *, unsigned int,
2247                                   void *, unsigned int);
2248 static int parse_table(struct context *, const struct token *,
2249                        const char *, unsigned int, void *, unsigned int);
2250 static int parse_table_destroy(struct context *, const struct token *,
2251                                const char *, unsigned int,
2252                                void *, unsigned int);
2253 static int parse_qo(struct context *, const struct token *,
2254                     const char *, unsigned int,
2255                     void *, unsigned int);
2256 static int parse_qo_destroy(struct context *, const struct token *,
2257                             const char *, unsigned int,
2258                             void *, unsigned int);
2259 static int parse_push(struct context *, const struct token *,
2260                       const char *, unsigned int,
2261                       void *, unsigned int);
2262 static int parse_tunnel(struct context *, const struct token *,
2263                         const char *, unsigned int,
2264                         void *, unsigned int);
2265 static int parse_flex(struct context *, const struct token *,
2266                       const char *, unsigned int, void *, unsigned int);
2267 static int parse_int(struct context *, const struct token *,
2268                      const char *, unsigned int,
2269                      void *, unsigned int);
2270 static int parse_prefix(struct context *, const struct token *,
2271                         const char *, unsigned int,
2272                         void *, unsigned int);
2273 static int parse_boolean(struct context *, const struct token *,
2274                          const char *, unsigned int,
2275                          void *, unsigned int);
2276 static int parse_string(struct context *, const struct token *,
2277                         const char *, unsigned int,
2278                         void *, unsigned int);
2279 static int parse_hex(struct context *ctx, const struct token *token,
2280                         const char *str, unsigned int len,
2281                         void *buf, unsigned int size);
2282 static int parse_string0(struct context *, const struct token *,
2283                         const char *, unsigned int,
2284                         void *, unsigned int);
2285 static int parse_mac_addr(struct context *, const struct token *,
2286                           const char *, unsigned int,
2287                           void *, unsigned int);
2288 static int parse_ipv4_addr(struct context *, const struct token *,
2289                            const char *, unsigned int,
2290                            void *, unsigned int);
2291 static int parse_ipv6_addr(struct context *, const struct token *,
2292                            const char *, unsigned int,
2293                            void *, unsigned int);
2294 static int parse_port(struct context *, const struct token *,
2295                       const char *, unsigned int,
2296                       void *, unsigned int);
2297 static int parse_ia(struct context *, const struct token *,
2298                     const char *, unsigned int,
2299                     void *, unsigned int);
2300 static int parse_ia_destroy(struct context *ctx, const struct token *token,
2301                             const char *str, unsigned int len,
2302                             void *buf, unsigned int size);
2303 static int parse_ia_id2ptr(struct context *ctx, const struct token *token,
2304                            const char *str, unsigned int len, void *buf,
2305                            unsigned int size);
2306 static int parse_mp(struct context *, const struct token *,
2307                     const char *, unsigned int,
2308                     void *, unsigned int);
2309 static int comp_none(struct context *, const struct token *,
2310                      unsigned int, char *, unsigned int);
2311 static int comp_boolean(struct context *, const struct token *,
2312                         unsigned int, char *, unsigned int);
2313 static int comp_action(struct context *, const struct token *,
2314                        unsigned int, char *, unsigned int);
2315 static int comp_port(struct context *, const struct token *,
2316                      unsigned int, char *, unsigned int);
2317 static int comp_rule_id(struct context *, const struct token *,
2318                         unsigned int, char *, unsigned int);
2319 static int comp_vc_action_rss_type(struct context *, const struct token *,
2320                                    unsigned int, char *, unsigned int);
2321 static int comp_vc_action_rss_queue(struct context *, const struct token *,
2322                                     unsigned int, char *, unsigned int);
2323 static int comp_set_raw_index(struct context *, const struct token *,
2324                               unsigned int, char *, unsigned int);
2325 static int comp_set_sample_index(struct context *, const struct token *,
2326                               unsigned int, char *, unsigned int);
2327 static int comp_set_modify_field_op(struct context *, const struct token *,
2328                               unsigned int, char *, unsigned int);
2329 static int comp_set_modify_field_id(struct context *, const struct token *,
2330                               unsigned int, char *, unsigned int);
2331 static int comp_pattern_template_id(struct context *, const struct token *,
2332                                     unsigned int, char *, unsigned int);
2333 static int comp_actions_template_id(struct context *, const struct token *,
2334                                     unsigned int, char *, unsigned int);
2335 static int comp_table_id(struct context *, const struct token *,
2336                          unsigned int, char *, unsigned int);
2337 static int comp_queue_id(struct context *, const struct token *,
2338                          unsigned int, char *, unsigned int);
2339
2340 /** Token definitions. */
2341 static const struct token token_list[] = {
2342         /* Special tokens. */
2343         [ZERO] = {
2344                 .name = "ZERO",
2345                 .help = "null entry, abused as the entry point",
2346                 .next = NEXT(NEXT_ENTRY(FLOW, ADD)),
2347         },
2348         [END] = {
2349                 .name = "",
2350                 .type = "RETURN",
2351                 .help = "command may end here",
2352         },
2353         [START_SET] = {
2354                 .name = "START_SET",
2355                 .help = "null entry, abused as the entry point for set",
2356                 .next = NEXT(NEXT_ENTRY(SET)),
2357         },
2358         [END_SET] = {
2359                 .name = "end_set",
2360                 .type = "RETURN",
2361                 .help = "set command may end here",
2362         },
2363         /* Common tokens. */
2364         [COMMON_INTEGER] = {
2365                 .name = "{int}",
2366                 .type = "INTEGER",
2367                 .help = "integer value",
2368                 .call = parse_int,
2369                 .comp = comp_none,
2370         },
2371         [COMMON_UNSIGNED] = {
2372                 .name = "{unsigned}",
2373                 .type = "UNSIGNED",
2374                 .help = "unsigned integer value",
2375                 .call = parse_int,
2376                 .comp = comp_none,
2377         },
2378         [COMMON_PREFIX] = {
2379                 .name = "{prefix}",
2380                 .type = "PREFIX",
2381                 .help = "prefix length for bit-mask",
2382                 .call = parse_prefix,
2383                 .comp = comp_none,
2384         },
2385         [COMMON_BOOLEAN] = {
2386                 .name = "{boolean}",
2387                 .type = "BOOLEAN",
2388                 .help = "any boolean value",
2389                 .call = parse_boolean,
2390                 .comp = comp_boolean,
2391         },
2392         [COMMON_STRING] = {
2393                 .name = "{string}",
2394                 .type = "STRING",
2395                 .help = "fixed string",
2396                 .call = parse_string,
2397                 .comp = comp_none,
2398         },
2399         [COMMON_HEX] = {
2400                 .name = "{hex}",
2401                 .type = "HEX",
2402                 .help = "fixed string",
2403                 .call = parse_hex,
2404         },
2405         [COMMON_FILE_PATH] = {
2406                 .name = "{file path}",
2407                 .type = "STRING",
2408                 .help = "file path",
2409                 .call = parse_string0,
2410                 .comp = comp_none,
2411         },
2412         [COMMON_MAC_ADDR] = {
2413                 .name = "{MAC address}",
2414                 .type = "MAC-48",
2415                 .help = "standard MAC address notation",
2416                 .call = parse_mac_addr,
2417                 .comp = comp_none,
2418         },
2419         [COMMON_IPV4_ADDR] = {
2420                 .name = "{IPv4 address}",
2421                 .type = "IPV4 ADDRESS",
2422                 .help = "standard IPv4 address notation",
2423                 .call = parse_ipv4_addr,
2424                 .comp = comp_none,
2425         },
2426         [COMMON_IPV6_ADDR] = {
2427                 .name = "{IPv6 address}",
2428                 .type = "IPV6 ADDRESS",
2429                 .help = "standard IPv6 address notation",
2430                 .call = parse_ipv6_addr,
2431                 .comp = comp_none,
2432         },
2433         [COMMON_RULE_ID] = {
2434                 .name = "{rule id}",
2435                 .type = "RULE ID",
2436                 .help = "rule identifier",
2437                 .call = parse_int,
2438                 .comp = comp_rule_id,
2439         },
2440         [COMMON_PORT_ID] = {
2441                 .name = "{port_id}",
2442                 .type = "PORT ID",
2443                 .help = "port identifier",
2444                 .call = parse_port,
2445                 .comp = comp_port,
2446         },
2447         [COMMON_GROUP_ID] = {
2448                 .name = "{group_id}",
2449                 .type = "GROUP ID",
2450                 .help = "group identifier",
2451                 .call = parse_int,
2452                 .comp = comp_none,
2453         },
2454         [COMMON_PRIORITY_LEVEL] = {
2455                 .name = "{level}",
2456                 .type = "PRIORITY",
2457                 .help = "priority level",
2458                 .call = parse_int,
2459                 .comp = comp_none,
2460         },
2461         [COMMON_INDIRECT_ACTION_ID] = {
2462                 .name = "{indirect_action_id}",
2463                 .type = "INDIRECT_ACTION_ID",
2464                 .help = "indirect action id",
2465                 .call = parse_int,
2466                 .comp = comp_none,
2467         },
2468         [COMMON_POLICY_ID] = {
2469                 .name = "{policy_id}",
2470                 .type = "POLICY_ID",
2471                 .help = "policy id",
2472                 .call = parse_int,
2473                 .comp = comp_none,
2474         },
2475         [COMMON_FLEX_TOKEN] = {
2476                 .name = "{flex token}",
2477                 .type = "flex token",
2478                 .help = "flex token",
2479                 .call = parse_int,
2480                 .comp = comp_none,
2481         },
2482         [COMMON_FLEX_HANDLE] = {
2483                 .name = "{flex handle}",
2484                 .type = "FLEX HANDLE",
2485                 .help = "fill flex item data",
2486                 .call = parse_flex_handle,
2487                 .comp = comp_none,
2488         },
2489         [COMMON_PATTERN_TEMPLATE_ID] = {
2490                 .name = "{pattern_template_id}",
2491                 .type = "PATTERN_TEMPLATE_ID",
2492                 .help = "pattern template id",
2493                 .call = parse_int,
2494                 .comp = comp_pattern_template_id,
2495         },
2496         [COMMON_ACTIONS_TEMPLATE_ID] = {
2497                 .name = "{actions_template_id}",
2498                 .type = "ACTIONS_TEMPLATE_ID",
2499                 .help = "actions template id",
2500                 .call = parse_int,
2501                 .comp = comp_actions_template_id,
2502         },
2503         [COMMON_TABLE_ID] = {
2504                 .name = "{table_id}",
2505                 .type = "TABLE_ID",
2506                 .help = "table id",
2507                 .call = parse_int,
2508                 .comp = comp_table_id,
2509         },
2510         [COMMON_QUEUE_ID] = {
2511                 .name = "{queue_id}",
2512                 .type = "QUEUE_ID",
2513                 .help = "queue id",
2514                 .call = parse_int,
2515                 .comp = comp_queue_id,
2516         },
2517         /* Top-level command. */
2518         [FLOW] = {
2519                 .name = "flow",
2520                 .type = "{command} {port_id} [{arg} [...]]",
2521                 .help = "manage ingress/egress flow rules",
2522                 .next = NEXT(NEXT_ENTRY
2523                              (INFO,
2524                               CONFIGURE,
2525                               PATTERN_TEMPLATE,
2526                               ACTIONS_TEMPLATE,
2527                               TABLE,
2528                               INDIRECT_ACTION,
2529                               VALIDATE,
2530                               CREATE,
2531                               DESTROY,
2532                               FLUSH,
2533                               DUMP,
2534                               LIST,
2535                               AGED,
2536                               QUERY,
2537                               ISOLATE,
2538                               TUNNEL,
2539                               FLEX,
2540                               QUEUE,
2541                               PUSH)),
2542                 .call = parse_init,
2543         },
2544         /* Top-level command. */
2545         [INFO] = {
2546                 .name = "info",
2547                 .help = "get information about flow engine",
2548                 .next = NEXT(NEXT_ENTRY(END),
2549                              NEXT_ENTRY(COMMON_PORT_ID)),
2550                 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
2551                 .call = parse_configure,
2552         },
2553         /* Top-level command. */
2554         [CONFIGURE] = {
2555                 .name = "configure",
2556                 .help = "configure flow engine",
2557                 .next = NEXT(next_config_attr,
2558                              NEXT_ENTRY(COMMON_PORT_ID)),
2559                 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
2560                 .call = parse_configure,
2561         },
2562         /* Configure arguments. */
2563         [CONFIG_QUEUES_NUMBER] = {
2564                 .name = "queues_number",
2565                 .help = "number of queues",
2566                 .next = NEXT(next_config_attr,
2567                              NEXT_ENTRY(COMMON_UNSIGNED)),
2568                 .args = ARGS(ARGS_ENTRY(struct buffer,
2569                                         args.configure.nb_queue)),
2570         },
2571         [CONFIG_QUEUES_SIZE] = {
2572                 .name = "queues_size",
2573                 .help = "number of elements in queues",
2574                 .next = NEXT(next_config_attr,
2575                              NEXT_ENTRY(COMMON_UNSIGNED)),
2576                 .args = ARGS(ARGS_ENTRY(struct buffer,
2577                                         args.configure.queue_attr.size)),
2578         },
2579         [CONFIG_COUNTERS_NUMBER] = {
2580                 .name = "counters_number",
2581                 .help = "number of counters",
2582                 .next = NEXT(next_config_attr,
2583                              NEXT_ENTRY(COMMON_UNSIGNED)),
2584                 .args = ARGS(ARGS_ENTRY(struct buffer,
2585                                         args.configure.port_attr.nb_counters)),
2586         },
2587         [CONFIG_AGING_OBJECTS_NUMBER] = {
2588                 .name = "aging_counters_number",
2589                 .help = "number of aging objects",
2590                 .next = NEXT(next_config_attr,
2591                              NEXT_ENTRY(COMMON_UNSIGNED)),
2592                 .args = ARGS(ARGS_ENTRY(struct buffer,
2593                                         args.configure.port_attr.nb_aging_objects)),
2594         },
2595         [CONFIG_METERS_NUMBER] = {
2596                 .name = "meters_number",
2597                 .help = "number of meters",
2598                 .next = NEXT(next_config_attr,
2599                              NEXT_ENTRY(COMMON_UNSIGNED)),
2600                 .args = ARGS(ARGS_ENTRY(struct buffer,
2601                                         args.configure.port_attr.nb_meters)),
2602         },
2603         /* Top-level command. */
2604         [PATTERN_TEMPLATE] = {
2605                 .name = "pattern_template",
2606                 .type = "{command} {port_id} [{arg} [...]]",
2607                 .help = "manage pattern templates",
2608                 .next = NEXT(next_pt_subcmd, NEXT_ENTRY(COMMON_PORT_ID)),
2609                 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
2610                 .call = parse_template,
2611         },
2612         /* Sub-level commands. */
2613         [PATTERN_TEMPLATE_CREATE] = {
2614                 .name = "create",
2615                 .help = "create pattern template",
2616                 .next = NEXT(next_pt_attr),
2617                 .call = parse_template,
2618         },
2619         [PATTERN_TEMPLATE_DESTROY] = {
2620                 .name = "destroy",
2621                 .help = "destroy pattern template",
2622                 .next = NEXT(NEXT_ENTRY(PATTERN_TEMPLATE_DESTROY_ID)),
2623                 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
2624                 .call = parse_template_destroy,
2625         },
2626         /* Pattern template arguments. */
2627         [PATTERN_TEMPLATE_CREATE_ID] = {
2628                 .name = "pattern_template_id",
2629                 .help = "specify a pattern template id to create",
2630                 .next = NEXT(next_pt_attr,
2631                              NEXT_ENTRY(COMMON_PATTERN_TEMPLATE_ID)),
2632                 .args = ARGS(ARGS_ENTRY(struct buffer, args.vc.pat_templ_id)),
2633         },
2634         [PATTERN_TEMPLATE_DESTROY_ID] = {
2635                 .name = "pattern_template",
2636                 .help = "specify a pattern template id to destroy",
2637                 .next = NEXT(next_pt_destroy_attr,
2638                              NEXT_ENTRY(COMMON_PATTERN_TEMPLATE_ID)),
2639                 .args = ARGS(ARGS_ENTRY_PTR(struct buffer,
2640                                             args.templ_destroy.template_id)),
2641                 .call = parse_template_destroy,
2642         },
2643         [PATTERN_TEMPLATE_RELAXED_MATCHING] = {
2644                 .name = "relaxed",
2645                 .help = "is matching relaxed",
2646                 .next = NEXT(next_pt_attr,
2647                              NEXT_ENTRY(COMMON_BOOLEAN)),
2648                 .args = ARGS(ARGS_ENTRY_BF(struct buffer,
2649                              args.vc.attr.reserved, 1)),
2650         },
2651         [PATTERN_TEMPLATE_INGRESS] = {
2652                 .name = "ingress",
2653                 .help = "attribute pattern to ingress",
2654                 .next = NEXT(next_pt_attr),
2655                 .call = parse_template,
2656         },
2657         [PATTERN_TEMPLATE_EGRESS] = {
2658                 .name = "egress",
2659                 .help = "attribute pattern to egress",
2660                 .next = NEXT(next_pt_attr),
2661                 .call = parse_template,
2662         },
2663         [PATTERN_TEMPLATE_TRANSFER] = {
2664                 .name = "transfer",
2665                 .help = "attribute pattern to transfer",
2666                 .next = NEXT(next_pt_attr),
2667                 .call = parse_template,
2668         },
2669         [PATTERN_TEMPLATE_SPEC] = {
2670                 .name = "template",
2671                 .help = "specify item to create pattern template",
2672                 .next = NEXT(next_item),
2673         },
2674         /* Top-level command. */
2675         [ACTIONS_TEMPLATE] = {
2676                 .name = "actions_template",
2677                 .type = "{command} {port_id} [{arg} [...]]",
2678                 .help = "manage actions templates",
2679                 .next = NEXT(next_at_subcmd, NEXT_ENTRY(COMMON_PORT_ID)),
2680                 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
2681                 .call = parse_template,
2682         },
2683         /* Sub-level commands. */
2684         [ACTIONS_TEMPLATE_CREATE] = {
2685                 .name = "create",
2686                 .help = "create actions template",
2687                 .next = NEXT(next_at_attr),
2688                 .call = parse_template,
2689         },
2690         [ACTIONS_TEMPLATE_DESTROY] = {
2691                 .name = "destroy",
2692                 .help = "destroy actions template",
2693                 .next = NEXT(NEXT_ENTRY(ACTIONS_TEMPLATE_DESTROY_ID)),
2694                 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
2695                 .call = parse_template_destroy,
2696         },
2697         /* Actions template arguments. */
2698         [ACTIONS_TEMPLATE_CREATE_ID] = {
2699                 .name = "actions_template_id",
2700                 .help = "specify an actions template id to create",
2701                 .next = NEXT(NEXT_ENTRY(ACTIONS_TEMPLATE_MASK),
2702                              NEXT_ENTRY(ACTIONS_TEMPLATE_SPEC),
2703                              NEXT_ENTRY(COMMON_ACTIONS_TEMPLATE_ID)),
2704                 .args = ARGS(ARGS_ENTRY(struct buffer, args.vc.act_templ_id)),
2705         },
2706         [ACTIONS_TEMPLATE_DESTROY_ID] = {
2707                 .name = "actions_template",
2708                 .help = "specify an actions template id to destroy",
2709                 .next = NEXT(next_at_destroy_attr,
2710                              NEXT_ENTRY(COMMON_ACTIONS_TEMPLATE_ID)),
2711                 .args = ARGS(ARGS_ENTRY_PTR(struct buffer,
2712                                             args.templ_destroy.template_id)),
2713                 .call = parse_template_destroy,
2714         },
2715         [ACTIONS_TEMPLATE_INGRESS] = {
2716                 .name = "ingress",
2717                 .help = "attribute actions to ingress",
2718                 .next = NEXT(next_at_attr),
2719                 .call = parse_template,
2720         },
2721         [ACTIONS_TEMPLATE_EGRESS] = {
2722                 .name = "egress",
2723                 .help = "attribute actions to egress",
2724                 .next = NEXT(next_at_attr),
2725                 .call = parse_template,
2726         },
2727         [ACTIONS_TEMPLATE_TRANSFER] = {
2728                 .name = "transfer",
2729                 .help = "attribute actions to transfer",
2730                 .next = NEXT(next_at_attr),
2731                 .call = parse_template,
2732         },
2733         [ACTIONS_TEMPLATE_SPEC] = {
2734                 .name = "template",
2735                 .help = "specify action to create actions template",
2736                 .next = NEXT(next_action),
2737                 .call = parse_template,
2738         },
2739         [ACTIONS_TEMPLATE_MASK] = {
2740                 .name = "mask",
2741                 .help = "specify action mask to create actions template",
2742                 .next = NEXT(next_action),
2743                 .call = parse_template,
2744         },
2745         /* Top-level command. */
2746         [TABLE] = {
2747                 .name = "template_table",
2748                 .type = "{command} {port_id} [{arg} [...]]",
2749                 .help = "manage template tables",
2750                 .next = NEXT(next_table_subcmd, NEXT_ENTRY(COMMON_PORT_ID)),
2751                 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
2752                 .call = parse_table,
2753         },
2754         /* Sub-level commands. */
2755         [TABLE_CREATE] = {
2756                 .name = "create",
2757                 .help = "create template table",
2758                 .next = NEXT(next_table_attr),
2759                 .call = parse_table,
2760         },
2761         [TABLE_DESTROY] = {
2762                 .name = "destroy",
2763                 .help = "destroy template table",
2764                 .next = NEXT(NEXT_ENTRY(TABLE_DESTROY_ID)),
2765                 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
2766                 .call = parse_table_destroy,
2767         },
2768         /* Table  arguments. */
2769         [TABLE_CREATE_ID] = {
2770                 .name = "table_id",
2771                 .help = "specify table id to create",
2772                 .next = NEXT(next_table_attr,
2773                              NEXT_ENTRY(COMMON_TABLE_ID)),
2774                 .args = ARGS(ARGS_ENTRY(struct buffer, args.table.id)),
2775         },
2776         [TABLE_DESTROY_ID] = {
2777                 .name = "table",
2778                 .help = "specify table id to destroy",
2779                 .next = NEXT(next_table_destroy_attr,
2780                              NEXT_ENTRY(COMMON_TABLE_ID)),
2781                 .args = ARGS(ARGS_ENTRY_PTR(struct buffer,
2782                                             args.table_destroy.table_id)),
2783                 .call = parse_table_destroy,
2784         },
2785         [TABLE_GROUP] = {
2786                 .name = "group",
2787                 .help = "specify a group",
2788                 .next = NEXT(next_table_attr, NEXT_ENTRY(COMMON_GROUP_ID)),
2789                 .args = ARGS(ARGS_ENTRY(struct buffer,
2790                                         args.table.attr.flow_attr.group)),
2791         },
2792         [TABLE_PRIORITY] = {
2793                 .name = "priority",
2794                 .help = "specify a priority level",
2795                 .next = NEXT(next_table_attr, NEXT_ENTRY(COMMON_PRIORITY_LEVEL)),
2796                 .args = ARGS(ARGS_ENTRY(struct buffer,
2797                                         args.table.attr.flow_attr.priority)),
2798         },
2799         [TABLE_EGRESS] = {
2800                 .name = "egress",
2801                 .help = "affect rule to egress",
2802                 .next = NEXT(next_table_attr),
2803                 .call = parse_table,
2804         },
2805         [TABLE_INGRESS] = {
2806                 .name = "ingress",
2807                 .help = "affect rule to ingress",
2808                 .next = NEXT(next_table_attr),
2809                 .call = parse_table,
2810         },
2811         [TABLE_TRANSFER] = {
2812                 .name = "transfer",
2813                 .help = "affect rule to transfer",
2814                 .next = NEXT(next_table_attr),
2815                 .call = parse_table,
2816         },
2817         [TABLE_RULES_NUMBER] = {
2818                 .name = "rules_number",
2819                 .help = "number of rules in table",
2820                 .next = NEXT(next_table_attr,
2821                              NEXT_ENTRY(COMMON_UNSIGNED)),
2822                 .args = ARGS(ARGS_ENTRY(struct buffer,
2823                                         args.table.attr.nb_flows)),
2824         },
2825         [TABLE_PATTERN_TEMPLATE] = {
2826                 .name = "pattern_template",
2827                 .help = "specify pattern template id",
2828                 .next = NEXT(next_table_attr,
2829                              NEXT_ENTRY(COMMON_PATTERN_TEMPLATE_ID)),
2830                 .args = ARGS(ARGS_ENTRY_PTR(struct buffer,
2831                                             args.table.pat_templ_id)),
2832                 .call = parse_table,
2833         },
2834         [TABLE_ACTIONS_TEMPLATE] = {
2835                 .name = "actions_template",
2836                 .help = "specify actions template id",
2837                 .next = NEXT(next_table_attr,
2838                              NEXT_ENTRY(COMMON_ACTIONS_TEMPLATE_ID)),
2839                 .args = ARGS(ARGS_ENTRY_PTR(struct buffer,
2840                                             args.table.act_templ_id)),
2841                 .call = parse_table,
2842         },
2843         /* Top-level command. */
2844         [QUEUE] = {
2845                 .name = "queue",
2846                 .help = "queue a flow rule operation",
2847                 .next = NEXT(next_queue_subcmd, NEXT_ENTRY(COMMON_PORT_ID)),
2848                 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
2849                 .call = parse_qo,
2850         },
2851         /* Sub-level commands. */
2852         [QUEUE_CREATE] = {
2853                 .name = "create",
2854                 .help = "create a flow rule",
2855                 .next = NEXT(NEXT_ENTRY(QUEUE_TEMPLATE_TABLE),
2856                              NEXT_ENTRY(COMMON_QUEUE_ID)),
2857                 .args = ARGS(ARGS_ENTRY(struct buffer, queue)),
2858                 .call = parse_qo,
2859         },
2860         [QUEUE_DESTROY] = {
2861                 .name = "destroy",
2862                 .help = "destroy a flow rule",
2863                 .next = NEXT(NEXT_ENTRY(QUEUE_DESTROY_ID),
2864                              NEXT_ENTRY(COMMON_QUEUE_ID)),
2865                 .args = ARGS(ARGS_ENTRY(struct buffer, queue)),
2866                 .call = parse_qo_destroy,
2867         },
2868         /* Queue  arguments. */
2869         [QUEUE_TEMPLATE_TABLE] = {
2870                 .name = "template table",
2871                 .help = "specify table id",
2872                 .next = NEXT(NEXT_ENTRY(QUEUE_PATTERN_TEMPLATE),
2873                              NEXT_ENTRY(COMMON_TABLE_ID)),
2874                 .args = ARGS(ARGS_ENTRY(struct buffer,
2875                                         args.vc.table_id)),
2876                 .call = parse_qo,
2877         },
2878         [QUEUE_PATTERN_TEMPLATE] = {
2879                 .name = "pattern_template",
2880                 .help = "specify pattern template index",
2881                 .next = NEXT(NEXT_ENTRY(QUEUE_ACTIONS_TEMPLATE),
2882                              NEXT_ENTRY(COMMON_UNSIGNED)),
2883                 .args = ARGS(ARGS_ENTRY(struct buffer,
2884                                         args.vc.pat_templ_id)),
2885                 .call = parse_qo,
2886         },
2887         [QUEUE_ACTIONS_TEMPLATE] = {
2888                 .name = "actions_template",
2889                 .help = "specify actions template index",
2890                 .next = NEXT(NEXT_ENTRY(QUEUE_CREATE_POSTPONE),
2891                              NEXT_ENTRY(COMMON_UNSIGNED)),
2892                 .args = ARGS(ARGS_ENTRY(struct buffer,
2893                                         args.vc.act_templ_id)),
2894                 .call = parse_qo,
2895         },
2896         [QUEUE_CREATE_POSTPONE] = {
2897                 .name = "postpone",
2898                 .help = "postpone create operation",
2899                 .next = NEXT(NEXT_ENTRY(ITEM_PATTERN),
2900                              NEXT_ENTRY(COMMON_BOOLEAN)),
2901                 .args = ARGS(ARGS_ENTRY(struct buffer, postpone)),
2902                 .call = parse_qo,
2903         },
2904         [QUEUE_DESTROY_POSTPONE] = {
2905                 .name = "postpone",
2906                 .help = "postpone destroy operation",
2907                 .next = NEXT(NEXT_ENTRY(QUEUE_DESTROY_ID),
2908                              NEXT_ENTRY(COMMON_BOOLEAN)),
2909                 .args = ARGS(ARGS_ENTRY(struct buffer, postpone)),
2910                 .call = parse_qo_destroy,
2911         },
2912         [QUEUE_DESTROY_ID] = {
2913                 .name = "rule",
2914                 .help = "specify rule id to destroy",
2915                 .next = NEXT(next_queue_destroy_attr,
2916                         NEXT_ENTRY(COMMON_UNSIGNED)),
2917                 .args = ARGS(ARGS_ENTRY_PTR(struct buffer,
2918                                             args.destroy.rule)),
2919                 .call = parse_qo_destroy,
2920         },
2921         /* Top-level command. */
2922         [PUSH] = {
2923                 .name = "push",
2924                 .help = "push enqueued operations",
2925                 .next = NEXT(NEXT_ENTRY(PUSH_QUEUE), NEXT_ENTRY(COMMON_PORT_ID)),
2926                 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
2927                 .call = parse_push,
2928         },
2929         /* Sub-level commands. */
2930         [PUSH_QUEUE] = {
2931                 .name = "queue",
2932                 .help = "specify queue id",
2933                 .next = NEXT(NEXT_ENTRY(END), NEXT_ENTRY(COMMON_QUEUE_ID)),
2934                 .args = ARGS(ARGS_ENTRY(struct buffer, queue)),
2935         },
2936         /* Top-level command. */
2937         [INDIRECT_ACTION] = {
2938                 .name = "indirect_action",
2939                 .type = "{command} {port_id} [{arg} [...]]",
2940                 .help = "manage indirect actions",
2941                 .next = NEXT(next_ia_subcmd, NEXT_ENTRY(COMMON_PORT_ID)),
2942                 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
2943                 .call = parse_ia,
2944         },
2945         /* Sub-level commands. */
2946         [INDIRECT_ACTION_CREATE] = {
2947                 .name = "create",
2948                 .help = "create indirect action",
2949                 .next = NEXT(next_ia_create_attr),
2950                 .call = parse_ia,
2951         },
2952         [INDIRECT_ACTION_UPDATE] = {
2953                 .name = "update",
2954                 .help = "update indirect action",
2955                 .next = NEXT(NEXT_ENTRY(INDIRECT_ACTION_SPEC),
2956                              NEXT_ENTRY(COMMON_INDIRECT_ACTION_ID)),
2957                 .args = ARGS(ARGS_ENTRY(struct buffer, args.vc.attr.group)),
2958                 .call = parse_ia,
2959         },
2960         [INDIRECT_ACTION_DESTROY] = {
2961                 .name = "destroy",
2962                 .help = "destroy indirect action",
2963                 .next = NEXT(NEXT_ENTRY(INDIRECT_ACTION_DESTROY_ID)),
2964                 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
2965                 .call = parse_ia_destroy,
2966         },
2967         [INDIRECT_ACTION_QUERY] = {
2968                 .name = "query",
2969                 .help = "query indirect action",
2970                 .next = NEXT(NEXT_ENTRY(END),
2971                              NEXT_ENTRY(COMMON_INDIRECT_ACTION_ID)),
2972                 .args = ARGS(ARGS_ENTRY(struct buffer, args.ia.action_id)),
2973                 .call = parse_ia,
2974         },
2975         [VALIDATE] = {
2976                 .name = "validate",
2977                 .help = "check whether a flow rule can be created",
2978                 .next = NEXT(next_vc_attr, NEXT_ENTRY(COMMON_PORT_ID)),
2979                 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
2980                 .call = parse_vc,
2981         },
2982         [CREATE] = {
2983                 .name = "create",
2984                 .help = "create a flow rule",
2985                 .next = NEXT(next_vc_attr, NEXT_ENTRY(COMMON_PORT_ID)),
2986                 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
2987                 .call = parse_vc,
2988         },
2989         [DESTROY] = {
2990                 .name = "destroy",
2991                 .help = "destroy specific flow rules",
2992                 .next = NEXT(NEXT_ENTRY(DESTROY_RULE),
2993                              NEXT_ENTRY(COMMON_PORT_ID)),
2994                 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
2995                 .call = parse_destroy,
2996         },
2997         [FLUSH] = {
2998                 .name = "flush",
2999                 .help = "destroy all flow rules",
3000                 .next = NEXT(NEXT_ENTRY(COMMON_PORT_ID)),
3001                 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
3002                 .call = parse_flush,
3003         },
3004         [DUMP] = {
3005                 .name = "dump",
3006                 .help = "dump single/all flow rules to file",
3007                 .next = NEXT(next_dump_subcmd, NEXT_ENTRY(COMMON_PORT_ID)),
3008                 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
3009                 .call = parse_dump,
3010         },
3011         [QUERY] = {
3012                 .name = "query",
3013                 .help = "query an existing flow rule",
3014                 .next = NEXT(NEXT_ENTRY(QUERY_ACTION),
3015                              NEXT_ENTRY(COMMON_RULE_ID),
3016                              NEXT_ENTRY(COMMON_PORT_ID)),
3017                 .args = ARGS(ARGS_ENTRY(struct buffer, args.query.action.type),
3018                              ARGS_ENTRY(struct buffer, args.query.rule),
3019                              ARGS_ENTRY(struct buffer, port)),
3020                 .call = parse_query,
3021         },
3022         [LIST] = {
3023                 .name = "list",
3024                 .help = "list existing flow rules",
3025                 .next = NEXT(next_list_attr, NEXT_ENTRY(COMMON_PORT_ID)),
3026                 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
3027                 .call = parse_list,
3028         },
3029         [AGED] = {
3030                 .name = "aged",
3031                 .help = "list and destroy aged flows",
3032                 .next = NEXT(next_aged_attr, NEXT_ENTRY(COMMON_PORT_ID)),
3033                 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
3034                 .call = parse_aged,
3035         },
3036         [ISOLATE] = {
3037                 .name = "isolate",
3038                 .help = "restrict ingress traffic to the defined flow rules",
3039                 .next = NEXT(NEXT_ENTRY(COMMON_BOOLEAN),
3040                              NEXT_ENTRY(COMMON_PORT_ID)),
3041                 .args = ARGS(ARGS_ENTRY(struct buffer, args.isolate.set),
3042                              ARGS_ENTRY(struct buffer, port)),
3043                 .call = parse_isolate,
3044         },
3045         [FLEX] = {
3046                 .name = "flex_item",
3047                 .help = "flex item API",
3048                 .next = NEXT(next_flex_item),
3049                 .call = parse_flex,
3050         },
3051         [FLEX_ITEM_INIT] = {
3052                 .name = "init",
3053                 .help = "flex item init",
3054                 .args = ARGS(ARGS_ENTRY(struct buffer, args.flex.token),
3055                              ARGS_ENTRY(struct buffer, port)),
3056                 .next = NEXT(NEXT_ENTRY(COMMON_FLEX_TOKEN),
3057                              NEXT_ENTRY(COMMON_PORT_ID)),
3058                 .call = parse_flex
3059         },
3060         [FLEX_ITEM_CREATE] = {
3061                 .name = "create",
3062                 .help = "flex item create",
3063                 .args = ARGS(ARGS_ENTRY(struct buffer, args.flex.filename),
3064                              ARGS_ENTRY(struct buffer, args.flex.token),
3065                              ARGS_ENTRY(struct buffer, port)),
3066                 .next = NEXT(NEXT_ENTRY(COMMON_FILE_PATH),
3067                              NEXT_ENTRY(COMMON_FLEX_TOKEN),
3068                              NEXT_ENTRY(COMMON_PORT_ID)),
3069                 .call = parse_flex
3070         },
3071         [FLEX_ITEM_DESTROY] = {
3072                 .name = "destroy",
3073                 .help = "flex item destroy",
3074                 .args = ARGS(ARGS_ENTRY(struct buffer, args.flex.token),
3075                              ARGS_ENTRY(struct buffer, port)),
3076                 .next = NEXT(NEXT_ENTRY(COMMON_FLEX_TOKEN),
3077                              NEXT_ENTRY(COMMON_PORT_ID)),
3078                 .call = parse_flex
3079         },
3080         [TUNNEL] = {
3081                 .name = "tunnel",
3082                 .help = "new tunnel API",
3083                 .next = NEXT(NEXT_ENTRY
3084                              (TUNNEL_CREATE, TUNNEL_LIST, TUNNEL_DESTROY)),
3085                 .call = parse_tunnel,
3086         },
3087         /* Tunnel arguments. */
3088         [TUNNEL_CREATE] = {
3089                 .name = "create",
3090                 .help = "create new tunnel object",
3091                 .next = NEXT(NEXT_ENTRY(TUNNEL_CREATE_TYPE),
3092                              NEXT_ENTRY(COMMON_PORT_ID)),
3093                 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
3094                 .call = parse_tunnel,
3095         },
3096         [TUNNEL_CREATE_TYPE] = {
3097                 .name = "type",
3098                 .help = "create new tunnel",
3099                 .next = NEXT(NEXT_ENTRY(COMMON_FILE_PATH)),
3100                 .args = ARGS(ARGS_ENTRY(struct tunnel_ops, type)),
3101                 .call = parse_tunnel,
3102         },
3103         [TUNNEL_DESTROY] = {
3104                 .name = "destroy",
3105                 .help = "destroy tunnel",
3106                 .next = NEXT(NEXT_ENTRY(TUNNEL_DESTROY_ID),
3107                              NEXT_ENTRY(COMMON_PORT_ID)),
3108                 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
3109                 .call = parse_tunnel,
3110         },
3111         [TUNNEL_DESTROY_ID] = {
3112                 .name = "id",
3113                 .help = "tunnel identifier to destroy",
3114                 .next = NEXT(NEXT_ENTRY(COMMON_UNSIGNED)),
3115                 .args = ARGS(ARGS_ENTRY(struct tunnel_ops, id)),
3116                 .call = parse_tunnel,
3117         },
3118         [TUNNEL_LIST] = {
3119                 .name = "list",
3120                 .help = "list existing tunnels",
3121                 .next = NEXT(NEXT_ENTRY(COMMON_PORT_ID)),
3122                 .args = ARGS(ARGS_ENTRY(struct buffer, port)),
3123                 .call = parse_tunnel,
3124         },
3125         /* Destroy arguments. */
3126         [DESTROY_RULE] = {
3127                 .name = "rule",
3128                 .help = "specify a rule identifier",
3129                 .next = NEXT(next_destroy_attr, NEXT_ENTRY(COMMON_RULE_ID)),
3130                 .args = ARGS(ARGS_ENTRY_PTR(struct buffer, args.destroy.rule)),
3131                 .call = parse_destroy,
3132         },
3133         /* Dump arguments. */
3134         [DUMP_ALL] = {
3135                 .name = "all",
3136                 .help = "dump all",
3137                 .next = NEXT(next_dump_attr),
3138                 .args = ARGS(ARGS_ENTRY(struct buffer, args.dump.file)),
3139                 .call = parse_dump,
3140         },
3141         [DUMP_ONE] = {
3142                 .name = "rule",
3143                 .help = "dump one rule",
3144                 .next = NEXT(next_dump_attr, NEXT_ENTRY(COMMON_RULE_ID)),
3145                 .args = ARGS(ARGS_ENTRY(struct buffer, args.dump.file),
3146                                 ARGS_ENTRY(struct buffer, args.dump.rule)),
3147                 .call = parse_dump,
3148         },
3149         /* Query arguments. */
3150         [QUERY_ACTION] = {
3151                 .name = "{action}",
3152                 .type = "ACTION",
3153                 .help = "action to query, must be part of the rule",
3154                 .call = parse_action,
3155                 .comp = comp_action,
3156         },
3157         /* List arguments. */
3158         [LIST_GROUP] = {
3159                 .name = "group",
3160                 .help = "specify a group",
3161                 .next = NEXT(next_list_attr, NEXT_ENTRY(COMMON_GROUP_ID)),
3162                 .args = ARGS(ARGS_ENTRY_PTR(struct buffer, args.list.group)),
3163                 .call = parse_list,
3164         },
3165         [AGED_DESTROY] = {
3166                 .name = "destroy",
3167                 .help = "specify aged flows need be destroyed",
3168                 .call = parse_aged,
3169                 .comp = comp_none,
3170         },
3171         /* Validate/create attributes. */
3172         [VC_GROUP] = {
3173                 .name = "group",
3174                 .help = "specify a group",
3175                 .next = NEXT(next_vc_attr, NEXT_ENTRY(COMMON_GROUP_ID)),
3176                 .args = ARGS(ARGS_ENTRY(struct rte_flow_attr, group)),
3177                 .call = parse_vc,
3178         },
3179         [VC_PRIORITY] = {
3180                 .name = "priority",
3181                 .help = "specify a priority level",
3182                 .next = NEXT(next_vc_attr, NEXT_ENTRY(COMMON_PRIORITY_LEVEL)),
3183                 .args = ARGS(ARGS_ENTRY(struct rte_flow_attr, priority)),
3184                 .call = parse_vc,
3185         },
3186         [VC_INGRESS] = {
3187                 .name = "ingress",
3188                 .help = "affect rule to ingress",
3189                 .next = NEXT(next_vc_attr),
3190                 .call = parse_vc,
3191         },
3192         [VC_EGRESS] = {
3193                 .name = "egress",
3194                 .help = "affect rule to egress",
3195                 .next = NEXT(next_vc_attr),
3196                 .call = parse_vc,
3197         },
3198         [VC_TRANSFER] = {
3199                 .name = "transfer",
3200                 .help = "apply rule directly to endpoints found in pattern",
3201                 .next = NEXT(next_vc_attr),
3202                 .call = parse_vc,
3203         },
3204         [VC_TUNNEL_SET] = {
3205                 .name = "tunnel_set",
3206                 .help = "tunnel steer rule",
3207                 .next = NEXT(next_vc_attr, NEXT_ENTRY(COMMON_UNSIGNED)),
3208                 .args = ARGS(ARGS_ENTRY(struct tunnel_ops, id)),
3209                 .call = parse_vc,
3210         },
3211         [VC_TUNNEL_MATCH] = {
3212                 .name = "tunnel_match",
3213                 .help = "tunnel match rule",
3214                 .next = NEXT(next_vc_attr, NEXT_ENTRY(COMMON_UNSIGNED)),
3215                 .args = ARGS(ARGS_ENTRY(struct tunnel_ops, id)),
3216                 .call = parse_vc,
3217         },
3218         /* Validate/create pattern. */
3219         [ITEM_PATTERN] = {
3220                 .name = "pattern",
3221                 .help = "submit a list of pattern items",
3222                 .next = NEXT(next_item),
3223                 .call = parse_vc,
3224         },
3225         [ITEM_PARAM_IS] = {
3226                 .name = "is",
3227                 .help = "match value perfectly (with full bit-mask)",
3228                 .call = parse_vc_spec,
3229         },
3230         [ITEM_PARAM_SPEC] = {
3231                 .name = "spec",
3232                 .help = "match value according to configured bit-mask",
3233                 .call = parse_vc_spec,
3234         },
3235         [ITEM_PARAM_LAST] = {
3236                 .name = "last",
3237                 .help = "specify upper bound to establish a range",
3238                 .call = parse_vc_spec,
3239         },
3240         [ITEM_PARAM_MASK] = {
3241                 .name = "mask",
3242                 .help = "specify bit-mask with relevant bits set to one",
3243                 .call = parse_vc_spec,
3244         },
3245         [ITEM_PARAM_PREFIX] = {
3246                 .name = "prefix",
3247                 .help = "generate bit-mask from a prefix length",
3248                 .call = parse_vc_spec,
3249         },
3250         [ITEM_NEXT] = {
3251                 .name = "/",
3252                 .help = "specify next pattern item",
3253                 .next = NEXT(next_item),
3254         },
3255         [ITEM_END] = {
3256                 .name = "end",
3257                 .help = "end list of pattern items",
3258                 .priv = PRIV_ITEM(END, 0),
3259                 .next = NEXT(NEXT_ENTRY(ACTIONS, END)),
3260                 .call = parse_vc,
3261         },
3262         [ITEM_VOID] = {
3263                 .name = "void",
3264                 .help = "no-op pattern item",
3265                 .priv = PRIV_ITEM(VOID, 0),
3266                 .next = NEXT(NEXT_ENTRY(ITEM_NEXT)),
3267                 .call = parse_vc,
3268         },
3269         [ITEM_INVERT] = {
3270                 .name = "invert",
3271                 .help = "perform actions when pattern does not match",
3272                 .priv = PRIV_ITEM(INVERT, 0),
3273                 .next = NEXT(NEXT_ENTRY(ITEM_NEXT)),
3274                 .call = parse_vc,
3275         },
3276         [ITEM_ANY] = {
3277                 .name = "any",
3278                 .help = "match any protocol for the current layer",
3279                 .priv = PRIV_ITEM(ANY, sizeof(struct rte_flow_item_any)),
3280                 .next = NEXT(item_any),
3281                 .call = parse_vc,
3282         },
3283         [ITEM_ANY_NUM] = {
3284                 .name = "num",
3285                 .help = "number of layers covered",
3286                 .next = NEXT(item_any, NEXT_ENTRY(COMMON_UNSIGNED), item_param),
3287                 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_any, num)),
3288         },
3289         [ITEM_PF] = {
3290                 .name = "pf",
3291                 .help = "match traffic from/to the physical function",
3292                 .priv = PRIV_ITEM(PF, 0),
3293                 .next = NEXT(NEXT_ENTRY(ITEM_NEXT)),
3294                 .call = parse_vc,
3295         },
3296         [ITEM_VF] = {
3297                 .name = "vf",
3298                 .help = "match traffic from/to a virtual function ID",
3299                 .priv = PRIV_ITEM(VF, sizeof(struct rte_flow_item_vf)),
3300                 .next = NEXT(item_vf),
3301                 .call = parse_vc,
3302         },
3303         [ITEM_VF_ID] = {
3304                 .name = "id",
3305                 .help = "VF ID",
3306                 .next = NEXT(item_vf, NEXT_ENTRY(COMMON_UNSIGNED), item_param),
3307                 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_vf, id)),
3308         },
3309         [ITEM_PHY_PORT] = {
3310                 .name = "phy_port",
3311                 .help = "match traffic from/to a specific physical port",
3312                 .priv = PRIV_ITEM(PHY_PORT,
3313                                   sizeof(struct rte_flow_item_phy_port)),
3314                 .next = NEXT(item_phy_port),
3315                 .call = parse_vc,
3316         },
3317         [ITEM_PHY_PORT_INDEX] = {
3318                 .name = "index",
3319                 .help = "physical port index",
3320                 .next = NEXT(item_phy_port, NEXT_ENTRY(COMMON_UNSIGNED),
3321                              item_param),
3322                 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_phy_port, index)),
3323         },
3324         [ITEM_PORT_ID] = {
3325                 .name = "port_id",
3326                 .help = "match traffic from/to a given DPDK port ID",
3327                 .priv = PRIV_ITEM(PORT_ID,
3328                                   sizeof(struct rte_flow_item_port_id)),
3329                 .next = NEXT(item_port_id),
3330                 .call = parse_vc,
3331         },
3332         [ITEM_PORT_ID_ID] = {
3333                 .name = "id",
3334                 .help = "DPDK port ID",
3335                 .next = NEXT(item_port_id, NEXT_ENTRY(COMMON_UNSIGNED),
3336                              item_param),
3337                 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_port_id, id)),
3338         },
3339         [ITEM_MARK] = {
3340                 .name = "mark",
3341                 .help = "match traffic against value set in previously matched rule",
3342                 .priv = PRIV_ITEM(MARK, sizeof(struct rte_flow_item_mark)),
3343                 .next = NEXT(item_mark),
3344                 .call = parse_vc,
3345         },
3346         [ITEM_MARK_ID] = {
3347                 .name = "id",
3348                 .help = "Integer value to match against",
3349                 .next = NEXT(item_mark, NEXT_ENTRY(COMMON_UNSIGNED),
3350                              item_param),
3351                 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_mark, id)),
3352         },
3353         [ITEM_RAW] = {
3354                 .name = "raw",
3355                 .help = "match an arbitrary byte string",
3356                 .priv = PRIV_ITEM(RAW, ITEM_RAW_SIZE),
3357                 .next = NEXT(item_raw),
3358                 .call = parse_vc,
3359         },
3360         [ITEM_RAW_RELATIVE] = {
3361                 .name = "relative",
3362                 .help = "look for pattern after the previous item",
3363                 .next = NEXT(item_raw, NEXT_ENTRY(COMMON_BOOLEAN), item_param),
3364                 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_item_raw,
3365                                            relative, 1)),
3366         },
3367         [ITEM_RAW_SEARCH] = {
3368                 .name = "search",
3369                 .help = "search pattern from offset (see also limit)",
3370                 .next = NEXT(item_raw, NEXT_ENTRY(COMMON_BOOLEAN), item_param),
3371                 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_item_raw,
3372                                            search, 1)),
3373         },
3374         [ITEM_RAW_OFFSET] = {
3375                 .name = "offset",
3376                 .help = "absolute or relative offset for pattern",
3377                 .next = NEXT(item_raw, NEXT_ENTRY(COMMON_INTEGER), item_param),
3378                 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_raw, offset)),
3379         },
3380         [ITEM_RAW_LIMIT] = {
3381                 .name = "limit",
3382                 .help = "search area limit for start of pattern",
3383                 .next = NEXT(item_raw, NEXT_ENTRY(COMMON_UNSIGNED), item_param),
3384                 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_raw, limit)),
3385         },
3386         [ITEM_RAW_PATTERN] = {
3387                 .name = "pattern",
3388                 .help = "byte string to look for",
3389                 .next = NEXT(item_raw,
3390                              NEXT_ENTRY(COMMON_STRING),
3391                              NEXT_ENTRY(ITEM_PARAM_IS,
3392                                         ITEM_PARAM_SPEC,
3393                                         ITEM_PARAM_MASK)),
3394                 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_raw, pattern),
3395                              ARGS_ENTRY(struct rte_flow_item_raw, length),
3396                              ARGS_ENTRY_ARB(sizeof(struct rte_flow_item_raw),
3397                                             ITEM_RAW_PATTERN_SIZE)),
3398         },
3399         [ITEM_RAW_PATTERN_HEX] = {
3400                 .name = "pattern_hex",
3401                 .help = "hex string to look for",
3402                 .next = NEXT(item_raw,
3403                              NEXT_ENTRY(COMMON_HEX),
3404                              NEXT_ENTRY(ITEM_PARAM_IS,
3405                                         ITEM_PARAM_SPEC,
3406                                         ITEM_PARAM_MASK)),
3407                 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_raw, pattern),
3408                              ARGS_ENTRY(struct rte_flow_item_raw, length),
3409                              ARGS_ENTRY_ARB(sizeof(struct rte_flow_item_raw),
3410                                             ITEM_RAW_PATTERN_SIZE)),
3411         },
3412         [ITEM_ETH] = {
3413                 .name = "eth",
3414                 .help = "match Ethernet header",
3415                 .priv = PRIV_ITEM(ETH, sizeof(struct rte_flow_item_eth)),
3416                 .next = NEXT(item_eth),
3417                 .call = parse_vc,
3418         },
3419         [ITEM_ETH_DST] = {
3420                 .name = "dst",
3421                 .help = "destination MAC",
3422                 .next = NEXT(item_eth, NEXT_ENTRY(COMMON_MAC_ADDR), item_param),
3423                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_eth, dst)),
3424         },
3425         [ITEM_ETH_SRC] = {
3426                 .name = "src",
3427                 .help = "source MAC",
3428                 .next = NEXT(item_eth, NEXT_ENTRY(COMMON_MAC_ADDR), item_param),
3429                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_eth, src)),
3430         },
3431         [ITEM_ETH_TYPE] = {
3432                 .name = "type",
3433                 .help = "EtherType",
3434                 .next = NEXT(item_eth, NEXT_ENTRY(COMMON_UNSIGNED), item_param),
3435                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_eth, type)),
3436         },
3437         [ITEM_ETH_HAS_VLAN] = {
3438                 .name = "has_vlan",
3439                 .help = "packet header contains VLAN",
3440                 .next = NEXT(item_eth, NEXT_ENTRY(COMMON_UNSIGNED), item_param),
3441                 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_item_eth,
3442                                            has_vlan, 1)),
3443         },
3444         [ITEM_VLAN] = {
3445                 .name = "vlan",
3446                 .help = "match 802.1Q/ad VLAN tag",
3447                 .priv = PRIV_ITEM(VLAN, sizeof(struct rte_flow_item_vlan)),
3448                 .next = NEXT(item_vlan),
3449                 .call = parse_vc,
3450         },
3451         [ITEM_VLAN_TCI] = {
3452                 .name = "tci",
3453                 .help = "tag control information",
3454                 .next = NEXT(item_vlan, NEXT_ENTRY(COMMON_UNSIGNED),
3455                              item_param),
3456                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vlan, tci)),
3457         },
3458         [ITEM_VLAN_PCP] = {
3459                 .name = "pcp",
3460                 .help = "priority code point",
3461                 .next = NEXT(item_vlan, NEXT_ENTRY(COMMON_UNSIGNED),
3462                              item_param),
3463                 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_vlan,
3464                                                   tci, "\xe0\x00")),
3465         },
3466         [ITEM_VLAN_DEI] = {
3467                 .name = "dei",
3468                 .help = "drop eligible indicator",
3469                 .next = NEXT(item_vlan, NEXT_ENTRY(COMMON_UNSIGNED),
3470                              item_param),
3471                 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_vlan,
3472                                                   tci, "\x10\x00")),
3473         },
3474         [ITEM_VLAN_VID] = {
3475                 .name = "vid",
3476                 .help = "VLAN identifier",
3477                 .next = NEXT(item_vlan, NEXT_ENTRY(COMMON_UNSIGNED),
3478                              item_param),
3479                 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_vlan,
3480                                                   tci, "\x0f\xff")),
3481         },
3482         [ITEM_VLAN_INNER_TYPE] = {
3483                 .name = "inner_type",
3484                 .help = "inner EtherType",
3485                 .next = NEXT(item_vlan, NEXT_ENTRY(COMMON_UNSIGNED),
3486                              item_param),
3487                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vlan,
3488                                              inner_type)),
3489         },
3490         [ITEM_VLAN_HAS_MORE_VLAN] = {
3491                 .name = "has_more_vlan",
3492                 .help = "packet header contains another VLAN",
3493                 .next = NEXT(item_vlan, NEXT_ENTRY(COMMON_UNSIGNED),
3494                              item_param),
3495                 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_item_vlan,
3496                                            has_more_vlan, 1)),
3497         },
3498         [ITEM_IPV4] = {
3499                 .name = "ipv4",
3500                 .help = "match IPv4 header",
3501                 .priv = PRIV_ITEM(IPV4, sizeof(struct rte_flow_item_ipv4)),
3502                 .next = NEXT(item_ipv4),
3503                 .call = parse_vc,
3504         },
3505         [ITEM_IPV4_VER_IHL] = {
3506                 .name = "version_ihl",
3507                 .help = "match header length",
3508                 .next = NEXT(item_ipv4, NEXT_ENTRY(COMMON_UNSIGNED),
3509                              item_param),
3510                 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_ipv4,
3511                                      hdr.version_ihl)),
3512         },
3513         [ITEM_IPV4_TOS] = {
3514                 .name = "tos",
3515                 .help = "type of service",
3516                 .next = NEXT(item_ipv4, NEXT_ENTRY(COMMON_UNSIGNED),
3517                              item_param),
3518                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
3519                                              hdr.type_of_service)),
3520         },
3521         [ITEM_IPV4_ID] = {
3522                 .name = "packet_id",
3523                 .help = "fragment packet id",
3524                 .next = NEXT(item_ipv4, NEXT_ENTRY(COMMON_UNSIGNED),
3525                              item_param),
3526                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
3527                                              hdr.packet_id)),
3528         },
3529         [ITEM_IPV4_FRAGMENT_OFFSET] = {
3530                 .name = "fragment_offset",
3531                 .help = "fragmentation flags and fragment offset",
3532                 .next = NEXT(item_ipv4, NEXT_ENTRY(COMMON_UNSIGNED),
3533                              item_param),
3534                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
3535                                              hdr.fragment_offset)),
3536         },
3537         [ITEM_IPV4_TTL] = {
3538                 .name = "ttl",
3539                 .help = "time to live",
3540                 .next = NEXT(item_ipv4, NEXT_ENTRY(COMMON_UNSIGNED),
3541                              item_param),
3542                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
3543                                              hdr.time_to_live)),
3544         },
3545         [ITEM_IPV4_PROTO] = {
3546                 .name = "proto",
3547                 .help = "next protocol ID",
3548                 .next = NEXT(item_ipv4, NEXT_ENTRY(COMMON_UNSIGNED),
3549                              item_param),
3550                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
3551                                              hdr.next_proto_id)),
3552         },
3553         [ITEM_IPV4_SRC] = {
3554                 .name = "src",
3555                 .help = "source address",
3556                 .next = NEXT(item_ipv4, NEXT_ENTRY(COMMON_IPV4_ADDR),
3557                              item_param),
3558                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
3559                                              hdr.src_addr)),
3560         },
3561         [ITEM_IPV4_DST] = {
3562                 .name = "dst",
3563                 .help = "destination address",
3564                 .next = NEXT(item_ipv4, NEXT_ENTRY(COMMON_IPV4_ADDR),
3565                              item_param),
3566                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
3567                                              hdr.dst_addr)),
3568         },
3569         [ITEM_IPV6] = {
3570                 .name = "ipv6",
3571                 .help = "match IPv6 header",
3572                 .priv = PRIV_ITEM(IPV6, sizeof(struct rte_flow_item_ipv6)),
3573                 .next = NEXT(item_ipv6),
3574                 .call = parse_vc,
3575         },
3576         [ITEM_IPV6_TC] = {
3577                 .name = "tc",
3578                 .help = "traffic class",
3579                 .next = NEXT(item_ipv6, NEXT_ENTRY(COMMON_UNSIGNED),
3580                              item_param),
3581                 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_ipv6,
3582                                                   hdr.vtc_flow,
3583                                                   "\x0f\xf0\x00\x00")),
3584         },
3585         [ITEM_IPV6_FLOW] = {
3586                 .name = "flow",
3587                 .help = "flow label",
3588                 .next = NEXT(item_ipv6, NEXT_ENTRY(COMMON_UNSIGNED),
3589                              item_param),
3590                 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_ipv6,
3591                                                   hdr.vtc_flow,
3592                                                   "\x00\x0f\xff\xff")),
3593         },
3594         [ITEM_IPV6_PROTO] = {
3595                 .name = "proto",
3596                 .help = "protocol (next header)",
3597                 .next = NEXT(item_ipv6, NEXT_ENTRY(COMMON_UNSIGNED),
3598                              item_param),
3599                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
3600                                              hdr.proto)),
3601         },
3602         [ITEM_IPV6_HOP] = {
3603                 .name = "hop",
3604                 .help = "hop limit",
3605                 .next = NEXT(item_ipv6, NEXT_ENTRY(COMMON_UNSIGNED),
3606                              item_param),
3607                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
3608                                              hdr.hop_limits)),
3609         },
3610         [ITEM_IPV6_SRC] = {
3611                 .name = "src",
3612                 .help = "source address",
3613                 .next = NEXT(item_ipv6, NEXT_ENTRY(COMMON_IPV6_ADDR),
3614                              item_param),
3615                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
3616                                              hdr.src_addr)),
3617         },
3618         [ITEM_IPV6_DST] = {
3619                 .name = "dst",
3620                 .help = "destination address",
3621                 .next = NEXT(item_ipv6, NEXT_ENTRY(COMMON_IPV6_ADDR),
3622                              item_param),
3623                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
3624                                              hdr.dst_addr)),
3625         },
3626         [ITEM_IPV6_HAS_FRAG_EXT] = {
3627                 .name = "has_frag_ext",
3628                 .help = "fragment packet attribute",
3629                 .next = NEXT(item_ipv6, NEXT_ENTRY(COMMON_UNSIGNED),
3630                              item_param),
3631                 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_item_ipv6,
3632                                            has_frag_ext, 1)),
3633         },
3634         [ITEM_ICMP] = {
3635                 .name = "icmp",
3636                 .help = "match ICMP header",
3637                 .priv = PRIV_ITEM(ICMP, sizeof(struct rte_flow_item_icmp)),
3638                 .next = NEXT(item_icmp),
3639                 .call = parse_vc,
3640         },
3641         [ITEM_ICMP_TYPE] = {
3642                 .name = "type",
3643                 .help = "ICMP packet type",
3644                 .next = NEXT(item_icmp, NEXT_ENTRY(COMMON_UNSIGNED),
3645                              item_param),
3646                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp,
3647                                              hdr.icmp_type)),
3648         },
3649         [ITEM_ICMP_CODE] = {
3650                 .name = "code",
3651                 .help = "ICMP packet code",
3652                 .next = NEXT(item_icmp, NEXT_ENTRY(COMMON_UNSIGNED),
3653                              item_param),
3654                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp,
3655                                              hdr.icmp_code)),
3656         },
3657         [ITEM_ICMP_IDENT] = {
3658                 .name = "ident",
3659                 .help = "ICMP packet identifier",
3660                 .next = NEXT(item_icmp, NEXT_ENTRY(COMMON_UNSIGNED),
3661                              item_param),
3662                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp,
3663                                              hdr.icmp_ident)),
3664         },
3665         [ITEM_ICMP_SEQ] = {
3666                 .name = "seq",
3667                 .help = "ICMP packet sequence number",
3668                 .next = NEXT(item_icmp, NEXT_ENTRY(COMMON_UNSIGNED),
3669                              item_param),
3670                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp,
3671                                              hdr.icmp_seq_nb)),
3672         },
3673         [ITEM_UDP] = {
3674                 .name = "udp",
3675                 .help = "match UDP header",
3676                 .priv = PRIV_ITEM(UDP, sizeof(struct rte_flow_item_udp)),
3677                 .next = NEXT(item_udp),
3678                 .call = parse_vc,
3679         },
3680         [ITEM_UDP_SRC] = {
3681                 .name = "src",
3682                 .help = "UDP source port",
3683                 .next = NEXT(item_udp, NEXT_ENTRY(COMMON_UNSIGNED),
3684                              item_param),
3685                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_udp,
3686                                              hdr.src_port)),
3687         },
3688         [ITEM_UDP_DST] = {
3689                 .name = "dst",
3690                 .help = "UDP destination port",
3691                 .next = NEXT(item_udp, NEXT_ENTRY(COMMON_UNSIGNED), item_param),
3692                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_udp,
3693                                              hdr.dst_port)),
3694         },
3695         [ITEM_TCP] = {
3696                 .name = "tcp",
3697                 .help = "match TCP header",
3698                 .priv = PRIV_ITEM(TCP, sizeof(struct rte_flow_item_tcp)),
3699                 .next = NEXT(item_tcp),
3700                 .call = parse_vc,
3701         },
3702         [ITEM_TCP_SRC] = {
3703                 .name = "src",
3704                 .help = "TCP source port",
3705                 .next = NEXT(item_tcp, NEXT_ENTRY(COMMON_UNSIGNED), item_param),
3706                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_tcp,
3707                                              hdr.src_port)),
3708         },
3709         [ITEM_TCP_DST] = {
3710                 .name = "dst",
3711                 .help = "TCP destination port",
3712                 .next = NEXT(item_tcp, NEXT_ENTRY(COMMON_UNSIGNED), item_param),
3713                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_tcp,
3714                                              hdr.dst_port)),
3715         },
3716         [ITEM_TCP_FLAGS] = {
3717                 .name = "flags",
3718                 .help = "TCP flags",
3719                 .next = NEXT(item_tcp, NEXT_ENTRY(COMMON_UNSIGNED), item_param),
3720                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_tcp,
3721                                              hdr.tcp_flags)),
3722         },
3723         [ITEM_SCTP] = {
3724                 .name = "sctp",
3725                 .help = "match SCTP header",
3726                 .priv = PRIV_ITEM(SCTP, sizeof(struct rte_flow_item_sctp)),
3727                 .next = NEXT(item_sctp),
3728                 .call = parse_vc,
3729         },
3730         [ITEM_SCTP_SRC] = {
3731                 .name = "src",
3732                 .help = "SCTP source port",
3733                 .next = NEXT(item_sctp, NEXT_ENTRY(COMMON_UNSIGNED),
3734                              item_param),
3735                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
3736                                              hdr.src_port)),
3737         },
3738         [ITEM_SCTP_DST] = {
3739                 .name = "dst",
3740                 .help = "SCTP destination port",
3741                 .next = NEXT(item_sctp, NEXT_ENTRY(COMMON_UNSIGNED),
3742                              item_param),
3743                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
3744                                              hdr.dst_port)),
3745         },
3746         [ITEM_SCTP_TAG] = {
3747                 .name = "tag",
3748                 .help = "validation tag",
3749                 .next = NEXT(item_sctp, NEXT_ENTRY(COMMON_UNSIGNED),
3750                              item_param),
3751                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
3752                                              hdr.tag)),
3753         },
3754         [ITEM_SCTP_CKSUM] = {
3755                 .name = "cksum",
3756                 .help = "checksum",
3757                 .next = NEXT(item_sctp, NEXT_ENTRY(COMMON_UNSIGNED),
3758                              item_param),
3759                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
3760                                              hdr.cksum)),
3761         },
3762         [ITEM_VXLAN] = {
3763                 .name = "vxlan",
3764                 .help = "match VXLAN header",
3765                 .priv = PRIV_ITEM(VXLAN, sizeof(struct rte_flow_item_vxlan)),
3766                 .next = NEXT(item_vxlan),
3767                 .call = parse_vc,
3768         },
3769         [ITEM_VXLAN_VNI] = {
3770                 .name = "vni",
3771                 .help = "VXLAN identifier",
3772                 .next = NEXT(item_vxlan, NEXT_ENTRY(COMMON_UNSIGNED),
3773                              item_param),
3774                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vxlan, vni)),
3775         },
3776         [ITEM_VXLAN_LAST_RSVD] = {
3777                 .name = "last_rsvd",
3778                 .help = "VXLAN last reserved bits",
3779                 .next = NEXT(item_vxlan, NEXT_ENTRY(COMMON_UNSIGNED),
3780                              item_param),
3781                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vxlan,
3782                                              rsvd1)),
3783         },
3784         [ITEM_E_TAG] = {
3785                 .name = "e_tag",
3786                 .help = "match E-Tag header",
3787                 .priv = PRIV_ITEM(E_TAG, sizeof(struct rte_flow_item_e_tag)),
3788                 .next = NEXT(item_e_tag),
3789                 .call = parse_vc,
3790         },
3791         [ITEM_E_TAG_GRP_ECID_B] = {
3792                 .name = "grp_ecid_b",
3793                 .help = "GRP and E-CID base",
3794                 .next = NEXT(item_e_tag, NEXT_ENTRY(COMMON_UNSIGNED),
3795                              item_param),
3796                 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_e_tag,
3797                                                   rsvd_grp_ecid_b,
3798                                                   "\x3f\xff")),
3799         },
3800         [ITEM_NVGRE] = {
3801                 .name = "nvgre",
3802                 .help = "match NVGRE header",
3803                 .priv = PRIV_ITEM(NVGRE, sizeof(struct rte_flow_item_nvgre)),
3804                 .next = NEXT(item_nvgre),
3805                 .call = parse_vc,
3806         },
3807         [ITEM_NVGRE_TNI] = {
3808                 .name = "tni",
3809                 .help = "virtual subnet ID",
3810                 .next = NEXT(item_nvgre, NEXT_ENTRY(COMMON_UNSIGNED),
3811                              item_param),
3812                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_nvgre, tni)),
3813         },
3814         [ITEM_MPLS] = {
3815                 .name = "mpls",
3816                 .help = "match MPLS header",
3817                 .priv = PRIV_ITEM(MPLS, sizeof(struct rte_flow_item_mpls)),
3818                 .next = NEXT(item_mpls),
3819                 .call = parse_vc,
3820         },
3821         [ITEM_MPLS_LABEL] = {
3822                 .name = "label",
3823                 .help = "MPLS label",
3824                 .next = NEXT(item_mpls, NEXT_ENTRY(COMMON_UNSIGNED),
3825                              item_param),
3826                 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_mpls,
3827                                                   label_tc_s,
3828                                                   "\xff\xff\xf0")),
3829         },
3830         [ITEM_MPLS_TC] = {
3831                 .name = "tc",
3832                 .help = "MPLS Traffic Class",
3833                 .next = NEXT(item_mpls, NEXT_ENTRY(COMMON_UNSIGNED),
3834                              item_param),
3835                 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_mpls,
3836                                                   label_tc_s,
3837                                                   "\x00\x00\x0e")),
3838         },
3839         [ITEM_MPLS_S] = {
3840                 .name = "s",
3841                 .help = "MPLS Bottom-of-Stack",
3842                 .next = NEXT(item_mpls, NEXT_ENTRY(COMMON_UNSIGNED),
3843                              item_param),
3844                 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_mpls,
3845                                                   label_tc_s,
3846                                                   "\x00\x00\x01")),
3847         },
3848         [ITEM_GRE] = {
3849                 .name = "gre",
3850                 .help = "match GRE header",
3851                 .priv = PRIV_ITEM(GRE, sizeof(struct rte_flow_item_gre)),
3852                 .next = NEXT(item_gre),
3853                 .call = parse_vc,
3854         },
3855         [ITEM_GRE_PROTO] = {
3856                 .name = "protocol",
3857                 .help = "GRE protocol type",
3858                 .next = NEXT(item_gre, NEXT_ENTRY(COMMON_UNSIGNED),
3859                              item_param),
3860                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gre,
3861                                              protocol)),
3862         },
3863         [ITEM_GRE_C_RSVD0_VER] = {
3864                 .name = "c_rsvd0_ver",
3865                 .help =
3866                         "checksum (1b), undefined (1b), key bit (1b),"
3867                         " sequence number (1b), reserved 0 (9b),"
3868                         " version (3b)",
3869                 .next = NEXT(item_gre, NEXT_ENTRY(COMMON_UNSIGNED),
3870                              item_param),
3871                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gre,
3872                                              c_rsvd0_ver)),
3873         },
3874         [ITEM_GRE_C_BIT] = {
3875                 .name = "c_bit",
3876                 .help = "checksum bit (C)",
3877                 .next = NEXT(item_gre, NEXT_ENTRY(COMMON_BOOLEAN),
3878                              item_param),
3879                 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_gre,
3880                                                   c_rsvd0_ver,
3881                                                   "\x80\x00\x00\x00")),
3882         },
3883         [ITEM_GRE_S_BIT] = {
3884                 .name = "s_bit",
3885                 .help = "sequence number bit (S)",
3886                 .next = NEXT(item_gre, NEXT_ENTRY(COMMON_BOOLEAN), item_param),
3887                 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_gre,
3888                                                   c_rsvd0_ver,
3889                                                   "\x10\x00\x00\x00")),
3890         },
3891         [ITEM_GRE_K_BIT] = {
3892                 .name = "k_bit",
3893                 .help = "key bit (K)",
3894                 .next = NEXT(item_gre, NEXT_ENTRY(COMMON_BOOLEAN), item_param),
3895                 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_gre,
3896                                                   c_rsvd0_ver,
3897                                                   "\x20\x00\x00\x00")),
3898         },
3899         [ITEM_FUZZY] = {
3900                 .name = "fuzzy",
3901                 .help = "fuzzy pattern match, expect faster than default",
3902                 .priv = PRIV_ITEM(FUZZY,
3903                                 sizeof(struct rte_flow_item_fuzzy)),
3904                 .next = NEXT(item_fuzzy),
3905                 .call = parse_vc,
3906         },
3907         [ITEM_FUZZY_THRESH] = {
3908                 .name = "thresh",
3909                 .help = "match accuracy threshold",
3910                 .next = NEXT(item_fuzzy, NEXT_ENTRY(COMMON_UNSIGNED),
3911                              item_param),
3912                 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_fuzzy,
3913                                         thresh)),
3914         },
3915         [ITEM_GTP] = {
3916                 .name = "gtp",
3917                 .help = "match GTP header",
3918                 .priv = PRIV_ITEM(GTP, sizeof(struct rte_flow_item_gtp)),
3919                 .next = NEXT(item_gtp),
3920                 .call = parse_vc,
3921         },
3922         [ITEM_GTP_FLAGS] = {
3923                 .name = "v_pt_rsv_flags",
3924                 .help = "GTP flags",
3925                 .next = NEXT(item_gtp, NEXT_ENTRY(COMMON_UNSIGNED), item_param),
3926                 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_gtp,
3927                                         v_pt_rsv_flags)),
3928         },
3929         [ITEM_GTP_MSG_TYPE] = {
3930                 .name = "msg_type",
3931                 .help = "GTP message type",
3932                 .next = NEXT(item_gtp, NEXT_ENTRY(COMMON_UNSIGNED), item_param),
3933                 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_gtp, msg_type)),
3934         },
3935         [ITEM_GTP_TEID] = {
3936                 .name = "teid",
3937                 .help = "tunnel endpoint identifier",
3938                 .next = NEXT(item_gtp, NEXT_ENTRY(COMMON_UNSIGNED), item_param),
3939                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gtp, teid)),
3940         },
3941         [ITEM_GTPC] = {
3942                 .name = "gtpc",
3943                 .help = "match GTP header",
3944                 .priv = PRIV_ITEM(GTPC, sizeof(struct rte_flow_item_gtp)),
3945                 .next = NEXT(item_gtp),
3946                 .call = parse_vc,
3947         },
3948         [ITEM_GTPU] = {
3949                 .name = "gtpu",
3950                 .help = "match GTP header",
3951                 .priv = PRIV_ITEM(GTPU, sizeof(struct rte_flow_item_gtp)),
3952                 .next = NEXT(item_gtp),
3953                 .call = parse_vc,
3954         },
3955         [ITEM_GENEVE] = {
3956                 .name = "geneve",
3957                 .help = "match GENEVE header",
3958                 .priv = PRIV_ITEM(GENEVE, sizeof(struct rte_flow_item_geneve)),
3959                 .next = NEXT(item_geneve),
3960                 .call = parse_vc,
3961         },
3962         [ITEM_GENEVE_VNI] = {
3963                 .name = "vni",
3964                 .help = "virtual network identifier",
3965                 .next = NEXT(item_geneve, NEXT_ENTRY(COMMON_UNSIGNED),
3966                              item_param),
3967                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_geneve, vni)),
3968         },
3969         [ITEM_GENEVE_PROTO] = {
3970                 .name = "protocol",
3971                 .help = "GENEVE protocol type",
3972                 .next = NEXT(item_geneve, NEXT_ENTRY(COMMON_UNSIGNED),
3973                              item_param),
3974                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_geneve,
3975                                              protocol)),
3976         },
3977         [ITEM_GENEVE_OPTLEN] = {
3978                 .name = "optlen",
3979                 .help = "GENEVE options length in dwords",
3980                 .next = NEXT(item_geneve, NEXT_ENTRY(COMMON_UNSIGNED),
3981                              item_param),
3982                 .args = ARGS(ARGS_ENTRY_MASK_HTON(struct rte_flow_item_geneve,
3983                                                   ver_opt_len_o_c_rsvd0,
3984                                                   "\x3f\x00")),
3985         },
3986         [ITEM_VXLAN_GPE] = {
3987                 .name = "vxlan-gpe",
3988                 .help = "match VXLAN-GPE header",
3989                 .priv = PRIV_ITEM(VXLAN_GPE,
3990                                   sizeof(struct rte_flow_item_vxlan_gpe)),
3991                 .next = NEXT(item_vxlan_gpe),
3992                 .call = parse_vc,
3993         },
3994         [ITEM_VXLAN_GPE_VNI] = {
3995                 .name = "vni",
3996                 .help = "VXLAN-GPE identifier",
3997                 .next = NEXT(item_vxlan_gpe, NEXT_ENTRY(COMMON_UNSIGNED),
3998                              item_param),
3999                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vxlan_gpe,
4000                                              vni)),
4001         },
4002         [ITEM_ARP_ETH_IPV4] = {
4003                 .name = "arp_eth_ipv4",
4004                 .help = "match ARP header for Ethernet/IPv4",
4005                 .priv = PRIV_ITEM(ARP_ETH_IPV4,
4006                                   sizeof(struct rte_flow_item_arp_eth_ipv4)),
4007                 .next = NEXT(item_arp_eth_ipv4),
4008                 .call = parse_vc,
4009         },
4010         [ITEM_ARP_ETH_IPV4_SHA] = {
4011                 .name = "sha",
4012                 .help = "sender hardware address",
4013                 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(COMMON_MAC_ADDR),
4014                              item_param),
4015                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
4016                                              sha)),
4017         },
4018         [ITEM_ARP_ETH_IPV4_SPA] = {
4019                 .name = "spa",
4020                 .help = "sender IPv4 address",
4021                 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(COMMON_IPV4_ADDR),
4022                              item_param),
4023                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
4024                                              spa)),
4025         },
4026         [ITEM_ARP_ETH_IPV4_THA] = {
4027                 .name = "tha",
4028                 .help = "target hardware address",
4029                 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(COMMON_MAC_ADDR),
4030                              item_param),
4031                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
4032                                              tha)),
4033         },
4034         [ITEM_ARP_ETH_IPV4_TPA] = {
4035                 .name = "tpa",
4036                 .help = "target IPv4 address",
4037                 .next = NEXT(item_arp_eth_ipv4, NEXT_ENTRY(COMMON_IPV4_ADDR),
4038                              item_param),
4039                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_arp_eth_ipv4,
4040                                              tpa)),
4041         },
4042         [ITEM_IPV6_EXT] = {
4043                 .name = "ipv6_ext",
4044                 .help = "match presence of any IPv6 extension header",
4045                 .priv = PRIV_ITEM(IPV6_EXT,
4046                                   sizeof(struct rte_flow_item_ipv6_ext)),
4047                 .next = NEXT(item_ipv6_ext),
4048                 .call = parse_vc,
4049         },
4050         [ITEM_IPV6_EXT_NEXT_HDR] = {
4051                 .name = "next_hdr",
4052                 .help = "next header",
4053                 .next = NEXT(item_ipv6_ext, NEXT_ENTRY(COMMON_UNSIGNED),
4054                              item_param),
4055                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6_ext,
4056                                              next_hdr)),
4057         },
4058         [ITEM_IPV6_FRAG_EXT] = {
4059                 .name = "ipv6_frag_ext",
4060                 .help = "match presence of IPv6 fragment extension header",
4061                 .priv = PRIV_ITEM(IPV6_FRAG_EXT,
4062                                 sizeof(struct rte_flow_item_ipv6_frag_ext)),
4063                 .next = NEXT(item_ipv6_frag_ext),
4064                 .call = parse_vc,
4065         },
4066         [ITEM_IPV6_FRAG_EXT_NEXT_HDR] = {
4067                 .name = "next_hdr",
4068                 .help = "next header",
4069                 .next = NEXT(item_ipv6_frag_ext, NEXT_ENTRY(COMMON_UNSIGNED),
4070                              item_param),
4071                 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_ipv6_frag_ext,
4072                                         hdr.next_header)),
4073         },
4074         [ITEM_IPV6_FRAG_EXT_FRAG_DATA] = {
4075                 .name = "frag_data",
4076                 .help = "fragment flags and offset",
4077                 .next = NEXT(item_ipv6_frag_ext, NEXT_ENTRY(COMMON_UNSIGNED),
4078                              item_param),
4079                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6_frag_ext,
4080                                              hdr.frag_data)),
4081         },
4082         [ITEM_IPV6_FRAG_EXT_ID] = {
4083                 .name = "packet_id",
4084                 .help = "fragment packet id",
4085                 .next = NEXT(item_ipv6_frag_ext, NEXT_ENTRY(COMMON_UNSIGNED),
4086                              item_param),
4087                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6_frag_ext,
4088                                              hdr.id)),
4089         },
4090         [ITEM_ICMP6] = {
4091                 .name = "icmp6",
4092                 .help = "match any ICMPv6 header",
4093                 .priv = PRIV_ITEM(ICMP6, sizeof(struct rte_flow_item_icmp6)),
4094                 .next = NEXT(item_icmp6),
4095                 .call = parse_vc,
4096         },
4097         [ITEM_ICMP6_TYPE] = {
4098                 .name = "type",
4099                 .help = "ICMPv6 type",
4100                 .next = NEXT(item_icmp6, NEXT_ENTRY(COMMON_UNSIGNED),
4101                              item_param),
4102                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6,
4103                                              type)),
4104         },
4105         [ITEM_ICMP6_CODE] = {
4106                 .name = "code",
4107                 .help = "ICMPv6 code",
4108                 .next = NEXT(item_icmp6, NEXT_ENTRY(COMMON_UNSIGNED),
4109                              item_param),
4110                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6,
4111                                              code)),
4112         },
4113         [ITEM_ICMP6_ND_NS] = {
4114                 .name = "icmp6_nd_ns",
4115                 .help = "match ICMPv6 neighbor discovery solicitation",
4116                 .priv = PRIV_ITEM(ICMP6_ND_NS,
4117                                   sizeof(struct rte_flow_item_icmp6_nd_ns)),
4118                 .next = NEXT(item_icmp6_nd_ns),
4119                 .call = parse_vc,
4120         },
4121         [ITEM_ICMP6_ND_NS_TARGET_ADDR] = {
4122                 .name = "target_addr",
4123                 .help = "target address",
4124                 .next = NEXT(item_icmp6_nd_ns, NEXT_ENTRY(COMMON_IPV6_ADDR),
4125                              item_param),
4126                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6_nd_ns,
4127                                              target_addr)),
4128         },
4129         [ITEM_ICMP6_ND_NA] = {
4130                 .name = "icmp6_nd_na",
4131                 .help = "match ICMPv6 neighbor discovery advertisement",
4132                 .priv = PRIV_ITEM(ICMP6_ND_NA,
4133                                   sizeof(struct rte_flow_item_icmp6_nd_na)),
4134                 .next = NEXT(item_icmp6_nd_na),
4135                 .call = parse_vc,
4136         },
4137         [ITEM_ICMP6_ND_NA_TARGET_ADDR] = {
4138                 .name = "target_addr",
4139                 .help = "target address",
4140                 .next = NEXT(item_icmp6_nd_na, NEXT_ENTRY(COMMON_IPV6_ADDR),
4141                              item_param),
4142                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6_nd_na,
4143                                              target_addr)),
4144         },
4145         [ITEM_ICMP6_ND_OPT] = {
4146                 .name = "icmp6_nd_opt",
4147                 .help = "match presence of any ICMPv6 neighbor discovery"
4148                         " option",
4149                 .priv = PRIV_ITEM(ICMP6_ND_OPT,
4150                                   sizeof(struct rte_flow_item_icmp6_nd_opt)),
4151                 .next = NEXT(item_icmp6_nd_opt),
4152                 .call = parse_vc,
4153         },
4154         [ITEM_ICMP6_ND_OPT_TYPE] = {
4155                 .name = "type",
4156                 .help = "ND option type",
4157                 .next = NEXT(item_icmp6_nd_opt, NEXT_ENTRY(COMMON_UNSIGNED),
4158                              item_param),
4159                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp6_nd_opt,
4160                                              type)),
4161         },
4162         [ITEM_ICMP6_ND_OPT_SLA_ETH] = {
4163                 .name = "icmp6_nd_opt_sla_eth",
4164                 .help = "match ICMPv6 neighbor discovery source Ethernet"
4165                         " link-layer address option",
4166                 .priv = PRIV_ITEM
4167                         (ICMP6_ND_OPT_SLA_ETH,
4168                          sizeof(struct rte_flow_item_icmp6_nd_opt_sla_eth)),
4169                 .next = NEXT(item_icmp6_nd_opt_sla_eth),
4170                 .call = parse_vc,
4171         },
4172         [ITEM_ICMP6_ND_OPT_SLA_ETH_SLA] = {
4173                 .name = "sla",
4174                 .help = "source Ethernet LLA",
4175                 .next = NEXT(item_icmp6_nd_opt_sla_eth,
4176                              NEXT_ENTRY(COMMON_MAC_ADDR), item_param),
4177                 .args = ARGS(ARGS_ENTRY_HTON
4178                              (struct rte_flow_item_icmp6_nd_opt_sla_eth, sla)),
4179         },
4180         [ITEM_ICMP6_ND_OPT_TLA_ETH] = {
4181                 .name = "icmp6_nd_opt_tla_eth",
4182                 .help = "match ICMPv6 neighbor discovery target Ethernet"
4183                         " link-layer address option",
4184                 .priv = PRIV_ITEM
4185                         (ICMP6_ND_OPT_TLA_ETH,
4186                          sizeof(struct rte_flow_item_icmp6_nd_opt_tla_eth)),
4187                 .next = NEXT(item_icmp6_nd_opt_tla_eth),
4188                 .call = parse_vc,
4189         },
4190         [ITEM_ICMP6_ND_OPT_TLA_ETH_TLA] = {
4191                 .name = "tla",
4192                 .help = "target Ethernet LLA",
4193                 .next = NEXT(item_icmp6_nd_opt_tla_eth,
4194                              NEXT_ENTRY(COMMON_MAC_ADDR), item_param),
4195                 .args = ARGS(ARGS_ENTRY_HTON
4196                              (struct rte_flow_item_icmp6_nd_opt_tla_eth, tla)),
4197         },
4198         [ITEM_META] = {
4199                 .name = "meta",
4200                 .help = "match metadata header",
4201                 .priv = PRIV_ITEM(META, sizeof(struct rte_flow_item_meta)),
4202                 .next = NEXT(item_meta),
4203                 .call = parse_vc,
4204         },
4205         [ITEM_META_DATA] = {
4206                 .name = "data",
4207                 .help = "metadata value",
4208                 .next = NEXT(item_meta, NEXT_ENTRY(COMMON_UNSIGNED),
4209                              item_param),
4210                 .args = ARGS(ARGS_ENTRY_MASK(struct rte_flow_item_meta,
4211                                              data, "\xff\xff\xff\xff")),
4212         },
4213         [ITEM_GRE_KEY] = {
4214                 .name = "gre_key",
4215                 .help = "match GRE key",
4216                 .priv = PRIV_ITEM(GRE_KEY, sizeof(rte_be32_t)),
4217                 .next = NEXT(item_gre_key),
4218                 .call = parse_vc,
4219         },
4220         [ITEM_GRE_KEY_VALUE] = {
4221                 .name = "value",
4222                 .help = "key value",
4223                 .next = NEXT(item_gre_key, NEXT_ENTRY(COMMON_UNSIGNED),
4224                              item_param),
4225                 .args = ARGS(ARG_ENTRY_HTON(rte_be32_t)),
4226         },
4227         [ITEM_GRE_OPTION] = {
4228                 .name = "gre_option",
4229                 .help = "match GRE optional fields",
4230                 .priv = PRIV_ITEM(GRE_OPTION,
4231                                   sizeof(struct rte_flow_item_gre_opt)),
4232                 .next = NEXT(item_gre_option),
4233                 .call = parse_vc,
4234         },
4235         [ITEM_GRE_OPTION_CHECKSUM] = {
4236                 .name = "checksum",
4237                 .help = "match GRE checksum",
4238                 .next = NEXT(item_gre_option, NEXT_ENTRY(COMMON_UNSIGNED),
4239                              item_param),
4240                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gre_opt,
4241                                              checksum_rsvd.checksum)),
4242         },
4243         [ITEM_GRE_OPTION_KEY] = {
4244                 .name = "key",
4245                 .help = "match GRE key",
4246                 .next = NEXT(item_gre_option, NEXT_ENTRY(COMMON_UNSIGNED),
4247                              item_param),
4248                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gre_opt,
4249                                              key.key)),
4250         },
4251         [ITEM_GRE_OPTION_SEQUENCE] = {
4252                 .name = "sequence",
4253                 .help = "match GRE sequence",
4254                 .next = NEXT(item_gre_option, NEXT_ENTRY(COMMON_UNSIGNED),
4255                              item_param),
4256                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gre_opt,
4257                                              sequence.sequence)),
4258         },
4259         [ITEM_GTP_PSC] = {
4260                 .name = "gtp_psc",
4261                 .help = "match GTP extension header with type 0x85",
4262                 .priv = PRIV_ITEM(GTP_PSC,
4263                                 sizeof(struct rte_flow_item_gtp_psc)),
4264                 .next = NEXT(item_gtp_psc),
4265                 .call = parse_vc,
4266         },
4267         [ITEM_GTP_PSC_QFI] = {
4268                 .name = "qfi",
4269                 .help = "QoS flow identifier",
4270                 .next = NEXT(item_gtp_psc, NEXT_ENTRY(COMMON_UNSIGNED),
4271                              item_param),
4272                 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_item_gtp_psc,
4273                                         hdr.qfi, 6)),
4274         },
4275         [ITEM_GTP_PSC_PDU_T] = {
4276                 .name = "pdu_t",
4277                 .help = "PDU type",
4278                 .next = NEXT(item_gtp_psc, NEXT_ENTRY(COMMON_UNSIGNED),
4279                              item_param),
4280                 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_item_gtp_psc,
4281                                         hdr.type, 4)),
4282         },
4283         [ITEM_PPPOES] = {
4284                 .name = "pppoes",
4285                 .help = "match PPPoE session header",
4286                 .priv = PRIV_ITEM(PPPOES, sizeof(struct rte_flow_item_pppoe)),
4287                 .next = NEXT(item_pppoes),
4288                 .call = parse_vc,
4289         },
4290         [ITEM_PPPOED] = {
4291                 .name = "pppoed",
4292                 .help = "match PPPoE discovery header",
4293                 .priv = PRIV_ITEM(PPPOED, sizeof(struct rte_flow_item_pppoe)),
4294                 .next = NEXT(item_pppoed),
4295                 .call = parse_vc,
4296         },
4297         [ITEM_PPPOE_SEID] = {
4298                 .name = "seid",
4299                 .help = "session identifier",
4300                 .next = NEXT(item_pppoes, NEXT_ENTRY(COMMON_UNSIGNED),
4301                              item_param),
4302                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_pppoe,
4303                                         session_id)),
4304         },
4305         [ITEM_PPPOE_PROTO_ID] = {
4306                 .name = "pppoe_proto_id",
4307                 .help = "match PPPoE session protocol identifier",
4308                 .priv = PRIV_ITEM(PPPOE_PROTO_ID,
4309                                 sizeof(struct rte_flow_item_pppoe_proto_id)),
4310                 .next = NEXT(item_pppoe_proto_id, NEXT_ENTRY(COMMON_UNSIGNED),
4311                              item_param),
4312                 .args = ARGS(ARGS_ENTRY_HTON
4313                              (struct rte_flow_item_pppoe_proto_id, proto_id)),
4314                 .call = parse_vc,
4315         },
4316         [ITEM_HIGIG2] = {
4317                 .name = "higig2",
4318                 .help = "matches higig2 header",
4319                 .priv = PRIV_ITEM(HIGIG2,
4320                                 sizeof(struct rte_flow_item_higig2_hdr)),
4321                 .next = NEXT(item_higig2),
4322                 .call = parse_vc,
4323         },
4324         [ITEM_HIGIG2_CLASSIFICATION] = {
4325                 .name = "classification",
4326                 .help = "matches classification of higig2 header",
4327                 .next = NEXT(item_higig2, NEXT_ENTRY(COMMON_UNSIGNED),
4328                              item_param),
4329                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_higig2_hdr,
4330                                         hdr.ppt1.classification)),
4331         },
4332         [ITEM_HIGIG2_VID] = {
4333                 .name = "vid",
4334                 .help = "matches vid of higig2 header",
4335                 .next = NEXT(item_higig2, NEXT_ENTRY(COMMON_UNSIGNED),
4336                              item_param),
4337                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_higig2_hdr,
4338                                         hdr.ppt1.vid)),
4339         },
4340         [ITEM_TAG] = {
4341                 .name = "tag",
4342                 .help = "match tag value",
4343                 .priv = PRIV_ITEM(TAG, sizeof(struct rte_flow_item_tag)),
4344                 .next = NEXT(item_tag),
4345                 .call = parse_vc,
4346         },
4347         [ITEM_TAG_DATA] = {
4348                 .name = "data",
4349                 .help = "tag value to match",
4350                 .next = NEXT(item_tag, NEXT_ENTRY(COMMON_UNSIGNED), item_param),
4351                 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_tag, data)),
4352         },
4353         [ITEM_TAG_INDEX] = {
4354                 .name = "index",
4355                 .help = "index of tag array to match",
4356                 .next = NEXT(item_tag, NEXT_ENTRY(COMMON_UNSIGNED),
4357                              NEXT_ENTRY(ITEM_PARAM_IS)),
4358                 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_tag, index)),
4359         },
4360         [ITEM_L2TPV3OIP] = {
4361                 .name = "l2tpv3oip",
4362                 .help = "match L2TPv3 over IP header",
4363                 .priv = PRIV_ITEM(L2TPV3OIP,
4364                                   sizeof(struct rte_flow_item_l2tpv3oip)),
4365                 .next = NEXT(item_l2tpv3oip),
4366                 .call = parse_vc,
4367         },
4368         [ITEM_L2TPV3OIP_SESSION_ID] = {
4369                 .name = "session_id",
4370                 .help = "session identifier",
4371                 .next = NEXT(item_l2tpv3oip, NEXT_ENTRY(COMMON_UNSIGNED),
4372                              item_param),
4373                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_l2tpv3oip,
4374                                              session_id)),
4375         },
4376         [ITEM_ESP] = {
4377                 .name = "esp",
4378                 .help = "match ESP header",
4379                 .priv = PRIV_ITEM(ESP, sizeof(struct rte_flow_item_esp)),
4380                 .next = NEXT(item_esp),
4381                 .call = parse_vc,
4382         },
4383         [ITEM_ESP_SPI] = {
4384                 .name = "spi",
4385                 .help = "security policy index",
4386                 .next = NEXT(item_esp, NEXT_ENTRY(COMMON_UNSIGNED), item_param),
4387                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_esp,
4388                                 hdr.spi)),
4389         },
4390         [ITEM_AH] = {
4391                 .name = "ah",
4392                 .help = "match AH header",
4393                 .priv = PRIV_ITEM(AH, sizeof(struct rte_flow_item_ah)),
4394                 .next = NEXT(item_ah),
4395                 .call = parse_vc,
4396         },
4397         [ITEM_AH_SPI] = {
4398                 .name = "spi",
4399                 .help = "security parameters index",
4400                 .next = NEXT(item_ah, NEXT_ENTRY(COMMON_UNSIGNED), item_param),
4401                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ah, spi)),
4402         },
4403         [ITEM_PFCP] = {
4404                 .name = "pfcp",
4405                 .help = "match pfcp header",
4406                 .priv = PRIV_ITEM(PFCP, sizeof(struct rte_flow_item_pfcp)),
4407                 .next = NEXT(item_pfcp),
4408                 .call = parse_vc,
4409         },
4410         [ITEM_PFCP_S_FIELD] = {
4411                 .name = "s_field",
4412                 .help = "S field",
4413                 .next = NEXT(item_pfcp, NEXT_ENTRY(COMMON_UNSIGNED),
4414                              item_param),
4415                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_pfcp,
4416                                 s_field)),
4417         },
4418         [ITEM_PFCP_SEID] = {
4419                 .name = "seid",
4420                 .help = "session endpoint identifier",
4421                 .next = NEXT(item_pfcp, NEXT_ENTRY(COMMON_UNSIGNED),
4422                              item_param),
4423                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_pfcp, seid)),
4424         },
4425         [ITEM_ECPRI] = {
4426                 .name = "ecpri",
4427                 .help = "match eCPRI header",
4428                 .priv = PRIV_ITEM(ECPRI, sizeof(struct rte_flow_item_ecpri)),
4429                 .next = NEXT(item_ecpri),
4430                 .call = parse_vc,
4431         },
4432         [ITEM_ECPRI_COMMON] = {
4433                 .name = "common",
4434                 .help = "eCPRI common header",
4435                 .next = NEXT(item_ecpri_common),
4436         },
4437         [ITEM_ECPRI_COMMON_TYPE] = {
4438                 .name = "type",
4439                 .help = "type of common header",
4440                 .next = NEXT(item_ecpri_common_type),
4441                 .args = ARGS(ARG_ENTRY_HTON(struct rte_flow_item_ecpri)),
4442         },
4443         [ITEM_ECPRI_COMMON_TYPE_IQ_DATA] = {
4444                 .name = "iq_data",
4445                 .help = "Type #0: IQ Data",
4446                 .next = NEXT(NEXT_ENTRY(ITEM_ECPRI_MSG_IQ_DATA_PCID,
4447                                         ITEM_NEXT)),
4448                 .call = parse_vc_item_ecpri_type,
4449         },
4450         [ITEM_ECPRI_MSG_IQ_DATA_PCID] = {
4451                 .name = "pc_id",
4452                 .help = "Physical Channel ID",
4453                 .next = NEXT(NEXT_ENTRY(ITEM_ECPRI_MSG_IQ_DATA_PCID,
4454                                 ITEM_ECPRI_COMMON, ITEM_NEXT),
4455                                 NEXT_ENTRY(COMMON_UNSIGNED), item_param),
4456                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ecpri,
4457                                 hdr.type0.pc_id)),
4458         },
4459         [ITEM_ECPRI_COMMON_TYPE_RTC_CTRL] = {
4460                 .name = "rtc_ctrl",
4461                 .help = "Type #2: Real-Time Control Data",
4462                 .next = NEXT(NEXT_ENTRY(ITEM_ECPRI_MSG_RTC_CTRL_RTCID,
4463                                         ITEM_NEXT)),
4464                 .call = parse_vc_item_ecpri_type,
4465         },
4466         [ITEM_ECPRI_MSG_RTC_CTRL_RTCID] = {
4467                 .name = "rtc_id",
4468                 .help = "Real-Time Control Data ID",
4469                 .next = NEXT(NEXT_ENTRY(ITEM_ECPRI_MSG_RTC_CTRL_RTCID,
4470                                 ITEM_ECPRI_COMMON, ITEM_NEXT),
4471                                 NEXT_ENTRY(COMMON_UNSIGNED), item_param),
4472                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ecpri,
4473                                 hdr.type2.rtc_id)),
4474         },
4475         [ITEM_ECPRI_COMMON_TYPE_DLY_MSR] = {
4476                 .name = "delay_measure",
4477                 .help = "Type #5: One-Way Delay Measurement",
4478                 .next = NEXT(NEXT_ENTRY(ITEM_ECPRI_MSG_DLY_MSR_MSRID,
4479                                         ITEM_NEXT)),
4480                 .call = parse_vc_item_ecpri_type,
4481         },
4482         [ITEM_ECPRI_MSG_DLY_MSR_MSRID] = {
4483                 .name = "msr_id",
4484                 .help = "Measurement ID",
4485                 .next = NEXT(NEXT_ENTRY(ITEM_ECPRI_MSG_DLY_MSR_MSRID,
4486                                 ITEM_ECPRI_COMMON, ITEM_NEXT),
4487                                 NEXT_ENTRY(COMMON_UNSIGNED), item_param),
4488                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ecpri,
4489                                 hdr.type5.msr_id)),
4490         },
4491         [ITEM_GENEVE_OPT] = {
4492                 .name = "geneve-opt",
4493                 .help = "GENEVE header option",
4494                 .priv = PRIV_ITEM(GENEVE_OPT,
4495                                   sizeof(struct rte_flow_item_geneve_opt) +
4496                                   ITEM_GENEVE_OPT_DATA_SIZE),
4497                 .next = NEXT(item_geneve_opt),
4498                 .call = parse_vc,
4499         },
4500         [ITEM_GENEVE_OPT_CLASS] = {
4501                 .name = "class",
4502                 .help = "GENEVE option class",
4503                 .next = NEXT(item_geneve_opt, NEXT_ENTRY(COMMON_UNSIGNED),
4504                              item_param),
4505                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_geneve_opt,
4506                                              option_class)),
4507         },
4508         [ITEM_GENEVE_OPT_TYPE] = {
4509                 .name = "type",
4510                 .help = "GENEVE option type",
4511                 .next = NEXT(item_geneve_opt, NEXT_ENTRY(COMMON_UNSIGNED),
4512                              item_param),
4513                 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_geneve_opt,
4514                                         option_type)),
4515         },
4516         [ITEM_GENEVE_OPT_LENGTH] = {
4517                 .name = "length",
4518                 .help = "GENEVE option data length (in 32b words)",
4519                 .next = NEXT(item_geneve_opt, NEXT_ENTRY(COMMON_UNSIGNED),
4520                              item_param),
4521                 .args = ARGS(ARGS_ENTRY_BOUNDED(
4522                                 struct rte_flow_item_geneve_opt, option_len,
4523                                 0, 31)),
4524         },
4525         [ITEM_GENEVE_OPT_DATA] = {
4526                 .name = "data",
4527                 .help = "GENEVE option data pattern",
4528                 .next = NEXT(item_geneve_opt, NEXT_ENTRY(COMMON_HEX),
4529                              item_param),
4530                 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_geneve_opt, data),
4531                              ARGS_ENTRY_ARB(0, 0),
4532                              ARGS_ENTRY_ARB
4533                                 (sizeof(struct rte_flow_item_geneve_opt),
4534                                 ITEM_GENEVE_OPT_DATA_SIZE)),
4535         },
4536         [ITEM_INTEGRITY] = {
4537                 .name = "integrity",
4538                 .help = "match packet integrity",
4539                 .priv = PRIV_ITEM(INTEGRITY,
4540                                   sizeof(struct rte_flow_item_integrity)),
4541                 .next = NEXT(item_integrity),
4542                 .call = parse_vc,
4543         },
4544         [ITEM_INTEGRITY_LEVEL] = {
4545                 .name = "level",
4546                 .help = "integrity level",
4547                 .next = NEXT(item_integrity_lv, NEXT_ENTRY(COMMON_UNSIGNED),
4548                              item_param),
4549                 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_integrity, level)),
4550         },
4551         [ITEM_INTEGRITY_VALUE] = {
4552                 .name = "value",
4553                 .help = "integrity value",
4554                 .next = NEXT(item_integrity_lv, NEXT_ENTRY(COMMON_UNSIGNED),
4555                              item_param),
4556                 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_integrity, value)),
4557         },
4558         [ITEM_CONNTRACK] = {
4559                 .name = "conntrack",
4560                 .help = "conntrack state",
4561                 .next = NEXT(NEXT_ENTRY(ITEM_NEXT), NEXT_ENTRY(COMMON_UNSIGNED),
4562                              item_param),
4563                 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_conntrack, flags)),
4564         },
4565         [ITEM_PORT_REPRESENTOR] = {
4566                 .name = "port_representor",
4567                 .help = "match traffic entering the embedded switch from the given ethdev",
4568                 .priv = PRIV_ITEM(PORT_REPRESENTOR,
4569                                   sizeof(struct rte_flow_item_ethdev)),
4570                 .next = NEXT(item_port_representor),
4571                 .call = parse_vc,
4572         },
4573         [ITEM_PORT_REPRESENTOR_PORT_ID] = {
4574                 .name = "port_id",
4575                 .help = "ethdev port ID",
4576                 .next = NEXT(item_port_representor, NEXT_ENTRY(COMMON_UNSIGNED),
4577                              item_param),
4578                 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_ethdev, port_id)),
4579         },
4580         [ITEM_REPRESENTED_PORT] = {
4581                 .name = "represented_port",
4582                 .help = "match traffic entering the embedded switch from the entity represented by the given ethdev",
4583                 .priv = PRIV_ITEM(REPRESENTED_PORT,
4584                                   sizeof(struct rte_flow_item_ethdev)),
4585                 .next = NEXT(item_represented_port),
4586                 .call = parse_vc,
4587         },
4588         [ITEM_REPRESENTED_PORT_ETHDEV_PORT_ID] = {
4589                 .name = "ethdev_port_id",
4590                 .help = "ethdev port ID",
4591                 .next = NEXT(item_represented_port, NEXT_ENTRY(COMMON_UNSIGNED),
4592                              item_param),
4593                 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_ethdev, port_id)),
4594         },
4595         [ITEM_FLEX] = {
4596                 .name = "flex",
4597                 .help = "match flex header",
4598                 .priv = PRIV_ITEM(FLEX, sizeof(struct rte_flow_item_flex)),
4599                 .next = NEXT(item_flex),
4600                 .call = parse_vc,
4601         },
4602         [ITEM_FLEX_ITEM_HANDLE] = {
4603                 .name = "item",
4604                 .help = "flex item handle",
4605                 .next = NEXT(item_flex, NEXT_ENTRY(COMMON_FLEX_HANDLE),
4606                              NEXT_ENTRY(ITEM_PARAM_IS)),
4607                 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_flex, handle)),
4608         },
4609         [ITEM_FLEX_PATTERN_HANDLE] = {
4610                 .name = "pattern",
4611                 .help = "flex pattern handle",
4612                 .next = NEXT(item_flex, NEXT_ENTRY(COMMON_FLEX_HANDLE),
4613                              NEXT_ENTRY(ITEM_PARAM_IS)),
4614                 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_flex, pattern)),
4615         },
4616         [ITEM_L2TPV2] = {
4617                 .name = "l2tpv2",
4618                 .help = "match L2TPv2 header",
4619                 .priv = PRIV_ITEM(L2TPV2, sizeof(struct rte_flow_item_l2tpv2)),
4620                 .next = NEXT(item_l2tpv2),
4621                 .call = parse_vc,
4622         },
4623         [ITEM_L2TPV2_TYPE] = {
4624                 .name = "type",
4625                 .help = "type of l2tpv2",
4626                 .next = NEXT(item_l2tpv2_type),
4627                 .args = ARGS(ARG_ENTRY_HTON(struct rte_flow_item_l2tpv2)),
4628         },
4629         [ITEM_L2TPV2_TYPE_DATA] = {
4630                 .name = "data",
4631                 .help = "Type #7: data message without any options",
4632                 .next = NEXT(item_l2tpv2_type_data),
4633                 .call = parse_vc_item_l2tpv2_type,
4634         },
4635         [ITEM_L2TPV2_MSG_DATA_TUNNEL_ID] = {
4636                 .name = "tunnel_id",
4637                 .help = "tunnel identifier",
4638                 .next = NEXT(item_l2tpv2_type_data,
4639                              NEXT_ENTRY(COMMON_UNSIGNED),
4640                              item_param),
4641                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_l2tpv2,
4642                                              hdr.type7.tunnel_id)),
4643         },
4644         [ITEM_L2TPV2_MSG_DATA_SESSION_ID] = {
4645                 .name = "session_id",
4646                 .help = "session identifier",
4647                 .next = NEXT(item_l2tpv2_type_data,
4648                              NEXT_ENTRY(COMMON_UNSIGNED),
4649                              item_param),
4650                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_l2tpv2,
4651                                              hdr.type7.session_id)),
4652         },
4653         [ITEM_L2TPV2_TYPE_DATA_L] = {
4654                 .name = "data_l",
4655                 .help = "Type #6: data message with length option",
4656                 .next = NEXT(item_l2tpv2_type_data_l),
4657                 .call = parse_vc_item_l2tpv2_type,
4658         },
4659         [ITEM_L2TPV2_MSG_DATA_L_LENGTH] = {
4660                 .name = "length",
4661                 .help = "message length",
4662                 .next = NEXT(item_l2tpv2_type_data_l,
4663                              NEXT_ENTRY(COMMON_UNSIGNED),
4664                              item_param),
4665                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_l2tpv2,
4666                                              hdr.type6.length)),
4667         },
4668         [ITEM_L2TPV2_MSG_DATA_L_TUNNEL_ID] = {
4669                 .name = "tunnel_id",
4670                 .help = "tunnel identifier",
4671                 .next = NEXT(item_l2tpv2_type_data_l,
4672                              NEXT_ENTRY(COMMON_UNSIGNED),
4673                              item_param),
4674                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_l2tpv2,
4675                                              hdr.type6.tunnel_id)),
4676         },
4677         [ITEM_L2TPV2_MSG_DATA_L_SESSION_ID] = {
4678                 .name = "session_id",
4679                 .help = "session identifier",
4680                 .next = NEXT(item_l2tpv2_type_data_l,
4681                              NEXT_ENTRY(COMMON_UNSIGNED),
4682                              item_param),
4683                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_l2tpv2,
4684                                              hdr.type6.session_id)),
4685         },
4686         [ITEM_L2TPV2_TYPE_DATA_S] = {
4687                 .name = "data_s",
4688                 .help = "Type #5: data message with ns, nr option",
4689                 .next = NEXT(item_l2tpv2_type_data_s),
4690                 .call = parse_vc_item_l2tpv2_type,
4691         },
4692         [ITEM_L2TPV2_MSG_DATA_S_TUNNEL_ID] = {
4693                 .name = "tunnel_id",
4694                 .help = "tunnel identifier",
4695                 .next = NEXT(item_l2tpv2_type_data_s,
4696                              NEXT_ENTRY(COMMON_UNSIGNED),
4697                              item_param),
4698                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_l2tpv2,
4699                                              hdr.type5.tunnel_id)),
4700         },
4701         [ITEM_L2TPV2_MSG_DATA_S_SESSION_ID] = {
4702                 .name = "session_id",
4703                 .help = "session identifier",
4704                 .next = NEXT(item_l2tpv2_type_data_s,
4705                              NEXT_ENTRY(COMMON_UNSIGNED),
4706                              item_param),
4707                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_l2tpv2,
4708                                              hdr.type5.session_id)),
4709         },
4710         [ITEM_L2TPV2_MSG_DATA_S_NS] = {
4711                 .name = "ns",
4712                 .help = "sequence number for message",
4713                 .next = NEXT(item_l2tpv2_type_data_s,
4714                              NEXT_ENTRY(COMMON_UNSIGNED),
4715                              item_param),
4716                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_l2tpv2,
4717                                              hdr.type5.ns)),
4718         },
4719         [ITEM_L2TPV2_MSG_DATA_S_NR] = {
4720                 .name = "nr",
4721                 .help = "sequence number for next receive message",
4722                 .next = NEXT(item_l2tpv2_type_data_s,
4723                              NEXT_ENTRY(COMMON_UNSIGNED),
4724                              item_param),
4725                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_l2tpv2,
4726                                              hdr.type5.nr)),
4727         },
4728         [ITEM_L2TPV2_TYPE_DATA_O] = {
4729                 .name = "data_o",
4730                 .help = "Type #4: data message with offset option",
4731                 .next = NEXT(item_l2tpv2_type_data_o),
4732                 .call = parse_vc_item_l2tpv2_type,
4733         },
4734         [ITEM_L2TPV2_MSG_DATA_O_TUNNEL_ID] = {
4735                 .name = "tunnel_id",
4736                 .help = "tunnel identifier",
4737                 .next = NEXT(item_l2tpv2_type_data_o,
4738                              NEXT_ENTRY(COMMON_UNSIGNED),
4739                              item_param),
4740                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_l2tpv2,
4741                                              hdr.type4.tunnel_id)),
4742         },
4743         [ITEM_L2TPV2_MSG_DATA_O_SESSION_ID] = {
4744                 .name = "session_id",
4745                 .help = "session identifier",
4746                 .next = NEXT(item_l2tpv2_type_data_o,
4747                              NEXT_ENTRY(COMMON_UNSIGNED),
4748                              item_param),
4749                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_l2tpv2,
4750                                              hdr.type5.session_id)),
4751         },
4752         [ITEM_L2TPV2_MSG_DATA_O_OFFSET] = {
4753                 .name = "offset_size",
4754                 .help = "the size of offset padding",
4755                 .next = NEXT(item_l2tpv2_type_data_o,
4756                              NEXT_ENTRY(COMMON_UNSIGNED),
4757                              item_param),
4758                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_l2tpv2,
4759                                              hdr.type4.offset_size)),
4760         },
4761         [ITEM_L2TPV2_TYPE_DATA_L_S] = {
4762                 .name = "data_l_s",
4763                 .help = "Type #3: data message contains length, ns, nr "
4764                         "options",
4765                 .next = NEXT(item_l2tpv2_type_data_l_s),
4766                 .call = parse_vc_item_l2tpv2_type,
4767         },
4768         [ITEM_L2TPV2_MSG_DATA_L_S_LENGTH] = {
4769                 .name = "length",
4770                 .help = "message length",
4771                 .next = NEXT(item_l2tpv2_type_data_l_s,
4772                              NEXT_ENTRY(COMMON_UNSIGNED),
4773                              item_param),
4774                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_l2tpv2,
4775                                              hdr.type3.length)),
4776         },
4777         [ITEM_L2TPV2_MSG_DATA_L_S_TUNNEL_ID] = {
4778                 .name = "tunnel_id",
4779                 .help = "tunnel identifier",
4780                 .next = NEXT(item_l2tpv2_type_data_l_s,
4781                              NEXT_ENTRY(COMMON_UNSIGNED),
4782                              item_param),
4783                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_l2tpv2,
4784                                              hdr.type3.tunnel_id)),
4785         },
4786         [ITEM_L2TPV2_MSG_DATA_L_S_SESSION_ID] = {
4787                 .name = "session_id",
4788                 .help = "session identifier",
4789                 .next = NEXT(item_l2tpv2_type_data_l_s,
4790                              NEXT_ENTRY(COMMON_UNSIGNED),
4791                              item_param),
4792                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_l2tpv2,
4793                                              hdr.type3.session_id)),
4794         },
4795         [ITEM_L2TPV2_MSG_DATA_L_S_NS] = {
4796                 .name = "ns",
4797                 .help = "sequence number for message",
4798                 .next = NEXT(item_l2tpv2_type_data_l_s,
4799                              NEXT_ENTRY(COMMON_UNSIGNED),
4800                              item_param),
4801                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_l2tpv2,
4802                                              hdr.type3.ns)),
4803         },
4804         [ITEM_L2TPV2_MSG_DATA_L_S_NR] = {
4805                 .name = "nr",
4806                 .help = "sequence number for next receive message",
4807                 .next = NEXT(item_l2tpv2_type_data_l_s,
4808                              NEXT_ENTRY(COMMON_UNSIGNED),
4809                              item_param),
4810                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_l2tpv2,
4811                                              hdr.type3.nr)),
4812         },
4813         [ITEM_L2TPV2_TYPE_CTRL] = {
4814                 .name = "control",
4815                 .help = "Type #3: conrtol message contains length, ns, nr "
4816                         "options",
4817                 .next = NEXT(item_l2tpv2_type_ctrl),
4818                 .call = parse_vc_item_l2tpv2_type,
4819         },
4820         [ITEM_L2TPV2_MSG_CTRL_LENGTH] = {
4821                 .name = "length",
4822                 .help = "message length",
4823                 .next = NEXT(item_l2tpv2_type_ctrl,
4824                              NEXT_ENTRY(COMMON_UNSIGNED),
4825                              item_param),
4826                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_l2tpv2,
4827                                              hdr.type3.length)),
4828         },
4829         [ITEM_L2TPV2_MSG_CTRL_TUNNEL_ID] = {
4830                 .name = "tunnel_id",
4831                 .help = "tunnel identifier",
4832                 .next = NEXT(item_l2tpv2_type_ctrl,
4833                              NEXT_ENTRY(COMMON_UNSIGNED),
4834                              item_param),
4835                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_l2tpv2,
4836                                              hdr.type3.tunnel_id)),
4837         },
4838         [ITEM_L2TPV2_MSG_CTRL_SESSION_ID] = {
4839                 .name = "session_id",
4840                 .help = "session identifier",
4841                 .next = NEXT(item_l2tpv2_type_ctrl,
4842                              NEXT_ENTRY(COMMON_UNSIGNED),
4843                              item_param),
4844                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_l2tpv2,
4845                                              hdr.type3.session_id)),
4846         },
4847         [ITEM_L2TPV2_MSG_CTRL_NS] = {
4848                 .name = "ns",
4849                 .help = "sequence number for message",
4850                 .next = NEXT(item_l2tpv2_type_ctrl,
4851                              NEXT_ENTRY(COMMON_UNSIGNED),
4852                              item_param),
4853                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_l2tpv2,
4854                                              hdr.type3.ns)),
4855         },
4856         [ITEM_L2TPV2_MSG_CTRL_NR] = {
4857                 .name = "nr",
4858                 .help = "sequence number for next receive message",
4859                 .next = NEXT(item_l2tpv2_type_ctrl,
4860                              NEXT_ENTRY(COMMON_UNSIGNED),
4861                              item_param),
4862                 .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_l2tpv2,
4863                                              hdr.type3.nr)),
4864         },
4865         [ITEM_PPP] = {
4866                 .name = "ppp",
4867                 .help = "match PPP header",
4868                 .priv = PRIV_ITEM(PPP, sizeof(struct rte_flow_item_ppp)),
4869                 .next = NEXT(item_ppp),
4870                 .call = parse_vc,
4871         },
4872         [ITEM_PPP_ADDR] = {
4873                 .name = "addr",
4874                 .help = "PPP address",
4875                 .next = NEXT(item_ppp, NEXT_ENTRY(COMMON_UNSIGNED),
4876                              item_param),
4877                 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_ppp, hdr.addr)),
4878         },
4879         [ITEM_PPP_CTRL] = {
4880                 .name = "ctrl",
4881                 .help = "PPP control",
4882                 .next = NEXT(item_ppp, NEXT_ENTRY(COMMON_UNSIGNED),
4883                              item_param),
4884                 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_ppp, hdr.ctrl)),
4885         },
4886         [ITEM_PPP_PROTO_ID] = {
4887                 .name = "proto_id",
4888                 .help = "PPP protocol identifier",
4889                 .next = NEXT(item_ppp, NEXT_ENTRY(COMMON_UNSIGNED),
4890                              item_param),
4891                 .args = ARGS(ARGS_ENTRY(struct rte_flow_item_ppp,
4892                                         hdr.proto_id)),
4893         },
4894         /* Validate/create actions. */
4895         [ACTIONS] = {
4896                 .name = "actions",
4897                 .help = "submit a list of associated actions",
4898                 .next = NEXT(next_action),
4899                 .call = parse_vc,
4900         },
4901         [ACTION_NEXT] = {
4902                 .name = "/",
4903                 .help = "specify next action",
4904                 .next = NEXT(next_action),
4905         },
4906         [ACTION_END] = {
4907                 .name = "end",
4908                 .help = "end list of actions",
4909                 .priv = PRIV_ACTION(END, 0),
4910                 .call = parse_vc,
4911         },
4912         [ACTION_VOID] = {
4913                 .name = "void",
4914                 .help = "no-op action",
4915                 .priv = PRIV_ACTION(VOID, 0),
4916                 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
4917                 .call = parse_vc,
4918         },
4919         [ACTION_PASSTHRU] = {
4920                 .name = "passthru",
4921                 .help = "let subsequent rule process matched packets",
4922                 .priv = PRIV_ACTION(PASSTHRU, 0),
4923                 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
4924                 .call = parse_vc,
4925         },
4926         [ACTION_JUMP] = {
4927                 .name = "jump",
4928                 .help = "redirect traffic to a given group",
4929                 .priv = PRIV_ACTION(JUMP, sizeof(struct rte_flow_action_jump)),
4930                 .next = NEXT(action_jump),
4931                 .call = parse_vc,
4932         },
4933         [ACTION_JUMP_GROUP] = {
4934                 .name = "group",
4935                 .help = "group to redirect traffic to",
4936                 .next = NEXT(action_jump, NEXT_ENTRY(COMMON_UNSIGNED)),
4937                 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_jump, group)),
4938                 .call = parse_vc_conf,
4939         },
4940         [ACTION_MARK] = {
4941                 .name = "mark",
4942                 .help = "attach 32 bit value to packets",
4943                 .priv = PRIV_ACTION(MARK, sizeof(struct rte_flow_action_mark)),
4944                 .next = NEXT(action_mark),
4945                 .call = parse_vc,
4946         },
4947         [ACTION_MARK_ID] = {
4948                 .name = "id",
4949                 .help = "32 bit value to return with packets",
4950                 .next = NEXT(action_mark, NEXT_ENTRY(COMMON_UNSIGNED)),
4951                 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_mark, id)),
4952                 .call = parse_vc_conf,
4953         },
4954         [ACTION_FLAG] = {
4955                 .name = "flag",
4956                 .help = "flag packets",
4957                 .priv = PRIV_ACTION(FLAG, 0),
4958                 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
4959                 .call = parse_vc,
4960         },
4961         [ACTION_QUEUE] = {
4962                 .name = "queue",
4963                 .help = "assign packets to a given queue index",
4964                 .priv = PRIV_ACTION(QUEUE,
4965                                     sizeof(struct rte_flow_action_queue)),
4966                 .next = NEXT(action_queue),
4967                 .call = parse_vc,
4968         },
4969         [ACTION_QUEUE_INDEX] = {
4970                 .name = "index",
4971                 .help = "queue index to use",
4972                 .next = NEXT(action_queue, NEXT_ENTRY(COMMON_UNSIGNED)),
4973                 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_queue, index)),
4974                 .call = parse_vc_conf,
4975         },
4976         [ACTION_DROP] = {
4977                 .name = "drop",
4978                 .help = "drop packets (note: passthru has priority)",
4979                 .priv = PRIV_ACTION(DROP, 0),
4980                 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
4981                 .call = parse_vc,
4982         },
4983         [ACTION_COUNT] = {
4984                 .name = "count",
4985                 .help = "enable counters for this rule",
4986                 .priv = PRIV_ACTION(COUNT,
4987                                     sizeof(struct rte_flow_action_count)),
4988                 .next = NEXT(action_count),
4989                 .call = parse_vc,
4990         },
4991         [ACTION_COUNT_ID] = {
4992                 .name = "identifier",
4993                 .help = "counter identifier to use",
4994                 .next = NEXT(action_count, NEXT_ENTRY(COMMON_UNSIGNED)),
4995                 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_count, id)),
4996                 .call = parse_vc_conf,
4997         },
4998         [ACTION_RSS] = {
4999                 .name = "rss",
5000                 .help = "spread packets among several queues",
5001                 .priv = PRIV_ACTION(RSS, sizeof(struct action_rss_data)),
5002                 .next = NEXT(action_rss),
5003                 .call = parse_vc_action_rss,
5004         },
5005         [ACTION_RSS_FUNC] = {
5006                 .name = "func",
5007                 .help = "RSS hash function to apply",
5008                 .next = NEXT(action_rss,
5009                              NEXT_ENTRY(ACTION_RSS_FUNC_DEFAULT,
5010                                         ACTION_RSS_FUNC_TOEPLITZ,
5011                                         ACTION_RSS_FUNC_SIMPLE_XOR,
5012                                         ACTION_RSS_FUNC_SYMMETRIC_TOEPLITZ)),
5013         },
5014         [ACTION_RSS_FUNC_DEFAULT] = {
5015                 .name = "default",
5016                 .help = "default hash function",
5017                 .call = parse_vc_action_rss_func,
5018         },
5019         [ACTION_RSS_FUNC_TOEPLITZ] = {
5020                 .name = "toeplitz",
5021                 .help = "Toeplitz hash function",
5022                 .call = parse_vc_action_rss_func,
5023         },
5024         [ACTION_RSS_FUNC_SIMPLE_XOR] = {
5025                 .name = "simple_xor",
5026                 .help = "simple XOR hash function",
5027                 .call = parse_vc_action_rss_func,
5028         },
5029         [ACTION_RSS_FUNC_SYMMETRIC_TOEPLITZ] = {
5030                 .name = "symmetric_toeplitz",
5031                 .help = "Symmetric Toeplitz hash function",
5032                 .call = parse_vc_action_rss_func,
5033         },
5034         [ACTION_RSS_LEVEL] = {
5035                 .name = "level",
5036                 .help = "encapsulation level for \"types\"",
5037                 .next = NEXT(action_rss, NEXT_ENTRY(COMMON_UNSIGNED)),
5038                 .args = ARGS(ARGS_ENTRY_ARB
5039                              (offsetof(struct action_rss_data, conf) +
5040                               offsetof(struct rte_flow_action_rss, level),
5041                               sizeof(((struct rte_flow_action_rss *)0)->
5042                                      level))),
5043         },
5044         [ACTION_RSS_TYPES] = {
5045                 .name = "types",
5046                 .help = "specific RSS hash types",
5047                 .next = NEXT(action_rss, NEXT_ENTRY(ACTION_RSS_TYPE)),
5048         },
5049         [ACTION_RSS_TYPE] = {
5050                 .name = "{type}",
5051                 .help = "RSS hash type",
5052                 .call = parse_vc_action_rss_type,
5053                 .comp = comp_vc_action_rss_type,
5054         },
5055         [ACTION_RSS_KEY] = {
5056                 .name = "key",
5057                 .help = "RSS hash key",
5058                 .next = NEXT(action_rss, NEXT_ENTRY(COMMON_HEX)),
5059                 .args = ARGS(ARGS_ENTRY_ARB
5060                              (offsetof(struct action_rss_data, conf) +
5061                               offsetof(struct rte_flow_action_rss, key),
5062                               sizeof(((struct rte_flow_action_rss *)0)->key)),
5063                              ARGS_ENTRY_ARB
5064                              (offsetof(struct action_rss_data, conf) +
5065                               offsetof(struct rte_flow_action_rss, key_len),
5066                               sizeof(((struct rte_flow_action_rss *)0)->
5067                                      key_len)),
5068                              ARGS_ENTRY(struct action_rss_data, key)),
5069         },
5070         [ACTION_RSS_KEY_LEN] = {
5071                 .name = "key_len",
5072                 .help = "RSS hash key length in bytes",
5073                 .next = NEXT(action_rss, NEXT_ENTRY(COMMON_UNSIGNED)),
5074                 .args = ARGS(ARGS_ENTRY_ARB_BOUNDED
5075                              (offsetof(struct action_rss_data, conf) +
5076                               offsetof(struct rte_flow_action_rss, key_len),
5077                               sizeof(((struct rte_flow_action_rss *)0)->
5078                                      key_len),
5079                               0,
5080                               RSS_HASH_KEY_LENGTH)),
5081         },
5082         [ACTION_RSS_QUEUES] = {
5083                 .name = "queues",
5084                 .help = "queue indices to use",
5085                 .next = NEXT(action_rss, NEXT_ENTRY(ACTION_RSS_QUEUE)),
5086                 .call = parse_vc_conf,
5087         },
5088         [ACTION_RSS_QUEUE] = {
5089                 .name = "{queue}",
5090                 .help = "queue index",
5091                 .call = parse_vc_action_rss_queue,
5092                 .comp = comp_vc_action_rss_queue,
5093         },
5094         [ACTION_PF] = {
5095                 .name = "pf",
5096                 .help = "direct traffic to physical function",
5097                 .priv = PRIV_ACTION(PF, 0),
5098                 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
5099                 .call = parse_vc,
5100         },
5101         [ACTION_VF] = {
5102                 .name = "vf",
5103                 .help = "direct traffic to a virtual function ID",
5104                 .priv = PRIV_ACTION(VF, sizeof(struct rte_flow_action_vf)),
5105                 .next = NEXT(action_vf),
5106                 .call = parse_vc,
5107         },
5108         [ACTION_VF_ORIGINAL] = {
5109                 .name = "original",
5110                 .help = "use original VF ID if possible",
5111                 .next = NEXT(action_vf, NEXT_ENTRY(COMMON_BOOLEAN)),
5112                 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_vf,
5113                                            original, 1)),
5114                 .call = parse_vc_conf,
5115         },
5116         [ACTION_VF_ID] = {
5117                 .name = "id",
5118                 .help = "VF ID",
5119                 .next = NEXT(action_vf, NEXT_ENTRY(COMMON_UNSIGNED)),
5120                 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_vf, id)),
5121                 .call = parse_vc_conf,
5122         },
5123         [ACTION_PHY_PORT] = {
5124                 .name = "phy_port",
5125                 .help = "direct packets to physical port index",
5126                 .priv = PRIV_ACTION(PHY_PORT,
5127                                     sizeof(struct rte_flow_action_phy_port)),
5128                 .next = NEXT(action_phy_port),
5129                 .call = parse_vc,
5130         },
5131         [ACTION_PHY_PORT_ORIGINAL] = {
5132                 .name = "original",
5133                 .help = "use original port index if possible",
5134                 .next = NEXT(action_phy_port, NEXT_ENTRY(COMMON_BOOLEAN)),
5135                 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_phy_port,
5136                                            original, 1)),
5137                 .call = parse_vc_conf,
5138         },
5139         [ACTION_PHY_PORT_INDEX] = {
5140                 .name = "index",
5141                 .help = "physical port index",
5142                 .next = NEXT(action_phy_port, NEXT_ENTRY(COMMON_UNSIGNED)),
5143                 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_phy_port,
5144                                         index)),
5145                 .call = parse_vc_conf,
5146         },
5147         [ACTION_PORT_ID] = {
5148                 .name = "port_id",
5149                 .help = "direct matching traffic to a given DPDK port ID",
5150                 .priv = PRIV_ACTION(PORT_ID,
5151                                     sizeof(struct rte_flow_action_port_id)),
5152                 .next = NEXT(action_port_id),
5153                 .call = parse_vc,
5154         },
5155         [ACTION_PORT_ID_ORIGINAL] = {
5156                 .name = "original",
5157                 .help = "use original DPDK port ID if possible",
5158                 .next = NEXT(action_port_id, NEXT_ENTRY(COMMON_BOOLEAN)),
5159                 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_port_id,
5160                                            original, 1)),
5161                 .call = parse_vc_conf,
5162         },
5163         [ACTION_PORT_ID_ID] = {
5164                 .name = "id",
5165                 .help = "DPDK port ID",
5166                 .next = NEXT(action_port_id, NEXT_ENTRY(COMMON_UNSIGNED)),
5167                 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_port_id, id)),
5168                 .call = parse_vc_conf,
5169         },
5170         [ACTION_METER] = {
5171                 .name = "meter",
5172                 .help = "meter the directed packets at given id",
5173                 .priv = PRIV_ACTION(METER,
5174                                     sizeof(struct rte_flow_action_meter)),
5175                 .next = NEXT(action_meter),
5176                 .call = parse_vc,
5177         },
5178         [ACTION_METER_COLOR] = {
5179                 .name = "color",
5180                 .help = "meter color for the packets",
5181                 .priv = PRIV_ACTION(METER_COLOR,
5182                                 sizeof(struct rte_flow_action_meter_color)),
5183                 .next = NEXT(action_meter_color),
5184                 .call = parse_vc,
5185         },
5186         [ACTION_METER_COLOR_TYPE] = {
5187                 .name = "type",
5188                 .help = "specific meter color",
5189                 .next = NEXT(NEXT_ENTRY(ACTION_NEXT),
5190                                 NEXT_ENTRY(ACTION_METER_COLOR_GREEN,
5191                                         ACTION_METER_COLOR_YELLOW,
5192                                         ACTION_METER_COLOR_RED)),
5193         },
5194         [ACTION_METER_COLOR_GREEN] = {
5195                 .name = "green",
5196                 .help = "meter color green",
5197                 .call = parse_vc_action_meter_color_type,
5198         },
5199         [ACTION_METER_COLOR_YELLOW] = {
5200                 .name = "yellow",
5201                 .help = "meter color yellow",
5202                 .call = parse_vc_action_meter_color_type,
5203         },
5204         [ACTION_METER_COLOR_RED] = {
5205                 .name = "red",
5206                 .help = "meter color red",
5207                 .call = parse_vc_action_meter_color_type,
5208         },
5209         [ACTION_METER_ID] = {
5210                 .name = "mtr_id",
5211                 .help = "meter id to use",
5212                 .next = NEXT(action_meter, NEXT_ENTRY(COMMON_UNSIGNED)),
5213                 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_meter, mtr_id)),
5214                 .call = parse_vc_conf,
5215         },
5216         [ACTION_OF_SET_MPLS_TTL] = {
5217                 .name = "of_set_mpls_ttl",
5218                 .help = "OpenFlow's OFPAT_SET_MPLS_TTL",
5219                 .priv = PRIV_ACTION
5220                         (OF_SET_MPLS_TTL,
5221                          sizeof(struct rte_flow_action_of_set_mpls_ttl)),
5222                 .next = NEXT(action_of_set_mpls_ttl),
5223                 .call = parse_vc,
5224         },
5225         [ACTION_OF_SET_MPLS_TTL_MPLS_TTL] = {
5226                 .name = "mpls_ttl",
5227                 .help = "MPLS TTL",
5228                 .next = NEXT(action_of_set_mpls_ttl,
5229                              NEXT_ENTRY(COMMON_UNSIGNED)),
5230                 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_of_set_mpls_ttl,
5231                                         mpls_ttl)),
5232                 .call = parse_vc_conf,
5233         },
5234         [ACTION_OF_DEC_MPLS_TTL] = {
5235                 .name = "of_dec_mpls_ttl",
5236                 .help = "OpenFlow's OFPAT_DEC_MPLS_TTL",
5237                 .priv = PRIV_ACTION(OF_DEC_MPLS_TTL, 0),
5238                 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
5239                 .call = parse_vc,
5240         },
5241         [ACTION_OF_SET_NW_TTL] = {
5242                 .name = "of_set_nw_ttl",
5243                 .help = "OpenFlow's OFPAT_SET_NW_TTL",
5244                 .priv = PRIV_ACTION
5245                         (OF_SET_NW_TTL,
5246                          sizeof(struct rte_flow_action_of_set_nw_ttl)),
5247                 .next = NEXT(action_of_set_nw_ttl),
5248                 .call = parse_vc,
5249         },
5250         [ACTION_OF_SET_NW_TTL_NW_TTL] = {
5251                 .name = "nw_ttl",
5252                 .help = "IP TTL",
5253                 .next = NEXT(action_of_set_nw_ttl, NEXT_ENTRY(COMMON_UNSIGNED)),
5254                 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_of_set_nw_ttl,
5255                                         nw_ttl)),
5256                 .call = parse_vc_conf,
5257         },
5258         [ACTION_OF_DEC_NW_TTL] = {
5259                 .name = "of_dec_nw_ttl",
5260                 .help = "OpenFlow's OFPAT_DEC_NW_TTL",
5261                 .priv = PRIV_ACTION(OF_DEC_NW_TTL, 0),
5262                 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
5263                 .call = parse_vc,
5264         },
5265         [ACTION_OF_COPY_TTL_OUT] = {
5266                 .name = "of_copy_ttl_out",
5267                 .help = "OpenFlow's OFPAT_COPY_TTL_OUT",
5268                 .priv = PRIV_ACTION(OF_COPY_TTL_OUT, 0),
5269                 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
5270                 .call = parse_vc,
5271         },
5272         [ACTION_OF_COPY_TTL_IN] = {
5273                 .name = "of_copy_ttl_in",
5274                 .help = "OpenFlow's OFPAT_COPY_TTL_IN",
5275                 .priv = PRIV_ACTION(OF_COPY_TTL_IN, 0),
5276                 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
5277                 .call = parse_vc,
5278         },
5279         [ACTION_OF_POP_VLAN] = {
5280                 .name = "of_pop_vlan",
5281                 .help = "OpenFlow's OFPAT_POP_VLAN",
5282                 .priv = PRIV_ACTION(OF_POP_VLAN, 0),
5283                 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
5284                 .call = parse_vc,
5285         },
5286         [ACTION_OF_PUSH_VLAN] = {
5287                 .name = "of_push_vlan",
5288                 .help = "OpenFlow's OFPAT_PUSH_VLAN",
5289                 .priv = PRIV_ACTION
5290                         (OF_PUSH_VLAN,
5291                          sizeof(struct rte_flow_action_of_push_vlan)),
5292                 .next = NEXT(action_of_push_vlan),
5293                 .call = parse_vc,
5294         },
5295         [ACTION_OF_PUSH_VLAN_ETHERTYPE] = {
5296                 .name = "ethertype",
5297                 .help = "EtherType",
5298                 .next = NEXT(action_of_push_vlan, NEXT_ENTRY(COMMON_UNSIGNED)),
5299                 .args = ARGS(ARGS_ENTRY_HTON
5300                              (struct rte_flow_action_of_push_vlan,
5301                               ethertype)),
5302                 .call = parse_vc_conf,
5303         },
5304         [ACTION_OF_SET_VLAN_VID] = {
5305                 .name = "of_set_vlan_vid",
5306                 .help = "OpenFlow's OFPAT_SET_VLAN_VID",
5307                 .priv = PRIV_ACTION
5308                         (OF_SET_VLAN_VID,
5309                          sizeof(struct rte_flow_action_of_set_vlan_vid)),
5310                 .next = NEXT(action_of_set_vlan_vid),
5311                 .call = parse_vc,
5312         },
5313         [ACTION_OF_SET_VLAN_VID_VLAN_VID] = {
5314                 .name = "vlan_vid",
5315                 .help = "VLAN id",
5316                 .next = NEXT(action_of_set_vlan_vid,
5317                              NEXT_ENTRY(COMMON_UNSIGNED)),
5318                 .args = ARGS(ARGS_ENTRY_HTON
5319                              (struct rte_flow_action_of_set_vlan_vid,
5320                               vlan_vid)),
5321                 .call = parse_vc_conf,
5322         },
5323         [ACTION_OF_SET_VLAN_PCP] = {
5324                 .name = "of_set_vlan_pcp",
5325                 .help = "OpenFlow's OFPAT_SET_VLAN_PCP",
5326                 .priv = PRIV_ACTION
5327                         (OF_SET_VLAN_PCP,
5328                          sizeof(struct rte_flow_action_of_set_vlan_pcp)),
5329                 .next = NEXT(action_of_set_vlan_pcp),
5330                 .call = parse_vc,
5331         },
5332         [ACTION_OF_SET_VLAN_PCP_VLAN_PCP] = {
5333                 .name = "vlan_pcp",
5334                 .help = "VLAN priority",
5335                 .next = NEXT(action_of_set_vlan_pcp,
5336                              NEXT_ENTRY(COMMON_UNSIGNED)),
5337                 .args = ARGS(ARGS_ENTRY_HTON
5338                              (struct rte_flow_action_of_set_vlan_pcp,
5339                               vlan_pcp)),
5340                 .call = parse_vc_conf,
5341         },
5342         [ACTION_OF_POP_MPLS] = {
5343                 .name = "of_pop_mpls",
5344                 .help = "OpenFlow's OFPAT_POP_MPLS",
5345                 .priv = PRIV_ACTION(OF_POP_MPLS,
5346                                     sizeof(struct rte_flow_action_of_pop_mpls)),
5347                 .next = NEXT(action_of_pop_mpls),
5348                 .call = parse_vc,
5349         },
5350         [ACTION_OF_POP_MPLS_ETHERTYPE] = {
5351                 .name = "ethertype",
5352                 .help = "EtherType",
5353                 .next = NEXT(action_of_pop_mpls, NEXT_ENTRY(COMMON_UNSIGNED)),
5354                 .args = ARGS(ARGS_ENTRY_HTON
5355                              (struct rte_flow_action_of_pop_mpls,
5356                               ethertype)),
5357                 .call = parse_vc_conf,
5358         },
5359         [ACTION_OF_PUSH_MPLS] = {
5360                 .name = "of_push_mpls",
5361                 .help = "OpenFlow's OFPAT_PUSH_MPLS",
5362                 .priv = PRIV_ACTION
5363                         (OF_PUSH_MPLS,
5364                          sizeof(struct rte_flow_action_of_push_mpls)),
5365                 .next = NEXT(action_of_push_mpls),
5366                 .call = parse_vc,
5367         },
5368         [ACTION_OF_PUSH_MPLS_ETHERTYPE] = {
5369                 .name = "ethertype",
5370                 .help = "EtherType",
5371                 .next = NEXT(action_of_push_mpls, NEXT_ENTRY(COMMON_UNSIGNED)),
5372                 .args = ARGS(ARGS_ENTRY_HTON
5373                              (struct rte_flow_action_of_push_mpls,
5374                               ethertype)),
5375                 .call = parse_vc_conf,
5376         },
5377         [ACTION_VXLAN_ENCAP] = {
5378                 .name = "vxlan_encap",
5379                 .help = "VXLAN encapsulation, uses configuration set by \"set"
5380                         " vxlan\"",
5381                 .priv = PRIV_ACTION(VXLAN_ENCAP,
5382                                     sizeof(struct action_vxlan_encap_data)),
5383                 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
5384                 .call = parse_vc_action_vxlan_encap,
5385         },
5386         [ACTION_VXLAN_DECAP] = {
5387                 .name = "vxlan_decap",
5388                 .help = "Performs a decapsulation action by stripping all"
5389                         " headers of the VXLAN tunnel network overlay from the"
5390                         " matched flow.",
5391                 .priv = PRIV_ACTION(VXLAN_DECAP, 0),
5392                 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
5393                 .call = parse_vc,
5394         },
5395         [ACTION_NVGRE_ENCAP] = {
5396                 .name = "nvgre_encap",
5397                 .help = "NVGRE encapsulation, uses configuration set by \"set"
5398                         " nvgre\"",
5399                 .priv = PRIV_ACTION(NVGRE_ENCAP,
5400                                     sizeof(struct action_nvgre_encap_data)),
5401                 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
5402                 .call = parse_vc_action_nvgre_encap,
5403         },
5404         [ACTION_NVGRE_DECAP] = {
5405                 .name = "nvgre_decap",
5406                 .help = "Performs a decapsulation action by stripping all"
5407                         " headers of the NVGRE tunnel network overlay from the"
5408                         " matched flow.",
5409                 .priv = PRIV_ACTION(NVGRE_DECAP, 0),
5410                 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
5411                 .call = parse_vc,
5412         },
5413         [ACTION_L2_ENCAP] = {
5414                 .name = "l2_encap",
5415                 .help = "l2 encap, uses configuration set by"
5416                         " \"set l2_encap\"",
5417                 .priv = PRIV_ACTION(RAW_ENCAP,
5418                                     sizeof(struct action_raw_encap_data)),
5419                 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
5420                 .call = parse_vc_action_l2_encap,
5421         },
5422         [ACTION_L2_DECAP] = {
5423                 .name = "l2_decap",
5424                 .help = "l2 decap, uses configuration set by"
5425                         " \"set l2_decap\"",
5426                 .priv = PRIV_ACTION(RAW_DECAP,
5427                                     sizeof(struct action_raw_decap_data)),
5428                 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
5429                 .call = parse_vc_action_l2_decap,
5430         },
5431         [ACTION_MPLSOGRE_ENCAP] = {
5432                 .name = "mplsogre_encap",
5433                 .help = "mplsogre encapsulation, uses configuration set by"
5434                         " \"set mplsogre_encap\"",
5435                 .priv = PRIV_ACTION(RAW_ENCAP,
5436                                     sizeof(struct action_raw_encap_data)),
5437                 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
5438                 .call = parse_vc_action_mplsogre_encap,
5439         },
5440         [ACTION_MPLSOGRE_DECAP] = {
5441                 .name = "mplsogre_decap",
5442                 .help = "mplsogre decapsulation, uses configuration set by"
5443                         " \"set mplsogre_decap\"",
5444                 .priv = PRIV_ACTION(RAW_DECAP,
5445                                     sizeof(struct action_raw_decap_data)),
5446                 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
5447                 .call = parse_vc_action_mplsogre_decap,
5448         },
5449         [ACTION_MPLSOUDP_ENCAP] = {
5450                 .name = "mplsoudp_encap",
5451                 .help = "mplsoudp encapsulation, uses configuration set by"
5452                         " \"set mplsoudp_encap\"",
5453                 .priv = PRIV_ACTION(RAW_ENCAP,
5454                                     sizeof(struct action_raw_encap_data)),
5455                 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
5456                 .call = parse_vc_action_mplsoudp_encap,
5457         },
5458         [ACTION_MPLSOUDP_DECAP] = {
5459                 .name = "mplsoudp_decap",
5460                 .help = "mplsoudp decapsulation, uses configuration set by"
5461                         " \"set mplsoudp_decap\"",
5462                 .priv = PRIV_ACTION(RAW_DECAP,
5463                                     sizeof(struct action_raw_decap_data)),
5464                 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
5465                 .call = parse_vc_action_mplsoudp_decap,
5466         },
5467         [ACTION_SET_IPV4_SRC] = {
5468                 .name = "set_ipv4_src",
5469                 .help = "Set a new IPv4 source address in the outermost"
5470                         " IPv4 header",
5471                 .priv = PRIV_ACTION(SET_IPV4_SRC,
5472                         sizeof(struct rte_flow_action_set_ipv4)),
5473                 .next = NEXT(action_set_ipv4_src),
5474                 .call = parse_vc,
5475         },
5476         [ACTION_SET_IPV4_SRC_IPV4_SRC] = {
5477                 .name = "ipv4_addr",
5478                 .help = "new IPv4 source address to set",
5479                 .next = NEXT(action_set_ipv4_src, NEXT_ENTRY(COMMON_IPV4_ADDR)),
5480                 .args = ARGS(ARGS_ENTRY_HTON
5481                         (struct rte_flow_action_set_ipv4, ipv4_addr)),
5482                 .call = parse_vc_conf,
5483         },
5484         [ACTION_SET_IPV4_DST] = {
5485                 .name = "set_ipv4_dst",
5486                 .help = "Set a new IPv4 destination address in the outermost"
5487                         " IPv4 header",
5488                 .priv = PRIV_ACTION(SET_IPV4_DST,
5489                         sizeof(struct rte_flow_action_set_ipv4)),
5490                 .next = NEXT(action_set_ipv4_dst),
5491                 .call = parse_vc,
5492         },
5493         [ACTION_SET_IPV4_DST_IPV4_DST] = {
5494                 .name = "ipv4_addr",
5495                 .help = "new IPv4 destination address to set",
5496                 .next = NEXT(action_set_ipv4_dst, NEXT_ENTRY(COMMON_IPV4_ADDR)),
5497                 .args = ARGS(ARGS_ENTRY_HTON
5498                         (struct rte_flow_action_set_ipv4, ipv4_addr)),
5499                 .call = parse_vc_conf,
5500         },
5501         [ACTION_SET_IPV6_SRC] = {
5502                 .name = "set_ipv6_src",
5503                 .help = "Set a new IPv6 source address in the outermost"
5504                         " IPv6 header",
5505                 .priv = PRIV_ACTION(SET_IPV6_SRC,
5506                         sizeof(struct rte_flow_action_set_ipv6)),
5507                 .next = NEXT(action_set_ipv6_src),
5508                 .call = parse_vc,
5509         },
5510         [ACTION_SET_IPV6_SRC_IPV6_SRC] = {
5511                 .name = "ipv6_addr",
5512                 .help = "new IPv6 source address to set",
5513                 .next = NEXT(action_set_ipv6_src, NEXT_ENTRY(COMMON_IPV6_ADDR)),
5514                 .args = ARGS(ARGS_ENTRY_HTON
5515                         (struct rte_flow_action_set_ipv6, ipv6_addr)),
5516                 .call = parse_vc_conf,
5517         },
5518         [ACTION_SET_IPV6_DST] = {
5519                 .name = "set_ipv6_dst",
5520                 .help = "Set a new IPv6 destination address in the outermost"
5521                         " IPv6 header",
5522                 .priv = PRIV_ACTION(SET_IPV6_DST,
5523                         sizeof(struct rte_flow_action_set_ipv6)),
5524                 .next = NEXT(action_set_ipv6_dst),
5525                 .call = parse_vc,
5526         },
5527         [ACTION_SET_IPV6_DST_IPV6_DST] = {
5528                 .name = "ipv6_addr",
5529                 .help = "new IPv6 destination address to set",
5530                 .next = NEXT(action_set_ipv6_dst, NEXT_ENTRY(COMMON_IPV6_ADDR)),
5531                 .args = ARGS(ARGS_ENTRY_HTON
5532                         (struct rte_flow_action_set_ipv6, ipv6_addr)),
5533                 .call = parse_vc_conf,
5534         },
5535         [ACTION_SET_TP_SRC] = {
5536                 .name = "set_tp_src",
5537                 .help = "set a new source port number in the outermost"
5538                         " TCP/UDP header",
5539                 .priv = PRIV_ACTION(SET_TP_SRC,
5540                         sizeof(struct rte_flow_action_set_tp)),
5541                 .next = NEXT(action_set_tp_src),
5542                 .call = parse_vc,
5543         },
5544         [ACTION_SET_TP_SRC_TP_SRC] = {
5545                 .name = "port",
5546                 .help = "new source port number to set",
5547                 .next = NEXT(action_set_tp_src, NEXT_ENTRY(COMMON_UNSIGNED)),
5548                 .args = ARGS(ARGS_ENTRY_HTON
5549                              (struct rte_flow_action_set_tp, port)),
5550                 .call = parse_vc_conf,
5551         },
5552         [ACTION_SET_TP_DST] = {
5553                 .name = "set_tp_dst",
5554                 .help = "set a new destination port number in the outermost"
5555                         " TCP/UDP header",
5556                 .priv = PRIV_ACTION(SET_TP_DST,
5557                         sizeof(struct rte_flow_action_set_tp)),
5558                 .next = NEXT(action_set_tp_dst),
5559                 .call = parse_vc,
5560         },
5561         [ACTION_SET_TP_DST_TP_DST] = {
5562                 .name = "port",
5563                 .help = "new destination port number to set",
5564                 .next = NEXT(action_set_tp_dst, NEXT_ENTRY(COMMON_UNSIGNED)),
5565                 .args = ARGS(ARGS_ENTRY_HTON
5566                              (struct rte_flow_action_set_tp, port)),
5567                 .call = parse_vc_conf,
5568         },
5569         [ACTION_MAC_SWAP] = {
5570                 .name = "mac_swap",
5571                 .help = "Swap the source and destination MAC addresses"
5572                         " in the outermost Ethernet header",
5573                 .priv = PRIV_ACTION(MAC_SWAP, 0),
5574                 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
5575                 .call = parse_vc,
5576         },
5577         [ACTION_DEC_TTL] = {
5578                 .name = "dec_ttl",
5579                 .help = "decrease network TTL if available",
5580                 .priv = PRIV_ACTION(DEC_TTL, 0),
5581                 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
5582                 .call = parse_vc,
5583         },
5584         [ACTION_SET_TTL] = {
5585                 .name = "set_ttl",
5586                 .help = "set ttl value",
5587                 .priv = PRIV_ACTION(SET_TTL,
5588                         sizeof(struct rte_flow_action_set_ttl)),
5589                 .next = NEXT(action_set_ttl),
5590                 .call = parse_vc,
5591         },
5592         [ACTION_SET_TTL_TTL] = {
5593                 .name = "ttl_value",
5594                 .help = "new ttl value to set",
5595                 .next = NEXT(action_set_ttl, NEXT_ENTRY(COMMON_UNSIGNED)),
5596                 .args = ARGS(ARGS_ENTRY_HTON
5597                              (struct rte_flow_action_set_ttl, ttl_value)),
5598                 .call = parse_vc_conf,
5599         },
5600         [ACTION_SET_MAC_SRC] = {
5601                 .name = "set_mac_src",
5602                 .help = "set source mac address",
5603                 .priv = PRIV_ACTION(SET_MAC_SRC,
5604                         sizeof(struct rte_flow_action_set_mac)),
5605                 .next = NEXT(action_set_mac_src),
5606                 .call = parse_vc,
5607         },
5608         [ACTION_SET_MAC_SRC_MAC_SRC] = {
5609                 .name = "mac_addr",
5610                 .help = "new source mac address",
5611                 .next = NEXT(action_set_mac_src, NEXT_ENTRY(COMMON_MAC_ADDR)),
5612                 .args = ARGS(ARGS_ENTRY_HTON
5613                              (struct rte_flow_action_set_mac, mac_addr)),
5614                 .call = parse_vc_conf,
5615         },
5616         [ACTION_SET_MAC_DST] = {
5617                 .name = "set_mac_dst",
5618                 .help = "set destination mac address",
5619                 .priv = PRIV_ACTION(SET_MAC_DST,
5620                         sizeof(struct rte_flow_action_set_mac)),
5621                 .next = NEXT(action_set_mac_dst),
5622                 .call = parse_vc,
5623         },
5624         [ACTION_SET_MAC_DST_MAC_DST] = {
5625                 .name = "mac_addr",
5626                 .help = "new destination mac address to set",
5627                 .next = NEXT(action_set_mac_dst, NEXT_ENTRY(COMMON_MAC_ADDR)),
5628                 .args = ARGS(ARGS_ENTRY_HTON
5629                              (struct rte_flow_action_set_mac, mac_addr)),
5630                 .call = parse_vc_conf,
5631         },
5632         [ACTION_INC_TCP_SEQ] = {
5633                 .name = "inc_tcp_seq",
5634                 .help = "increase TCP sequence number",
5635                 .priv = PRIV_ACTION(INC_TCP_SEQ, sizeof(rte_be32_t)),
5636                 .next = NEXT(action_inc_tcp_seq),
5637                 .call = parse_vc,
5638         },
5639         [ACTION_INC_TCP_SEQ_VALUE] = {
5640                 .name = "value",
5641                 .help = "the value to increase TCP sequence number by",
5642                 .next = NEXT(action_inc_tcp_seq, NEXT_ENTRY(COMMON_UNSIGNED)),
5643                 .args = ARGS(ARG_ENTRY_HTON(rte_be32_t)),
5644                 .call = parse_vc_conf,
5645         },
5646         [ACTION_DEC_TCP_SEQ] = {
5647                 .name = "dec_tcp_seq",
5648                 .help = "decrease TCP sequence number",
5649                 .priv = PRIV_ACTION(DEC_TCP_SEQ, sizeof(rte_be32_t)),
5650                 .next = NEXT(action_dec_tcp_seq),
5651                 .call = parse_vc,
5652         },
5653         [ACTION_DEC_TCP_SEQ_VALUE] = {
5654                 .name = "value",
5655                 .help = "the value to decrease TCP sequence number by",
5656                 .next = NEXT(action_dec_tcp_seq, NEXT_ENTRY(COMMON_UNSIGNED)),
5657                 .args = ARGS(ARG_ENTRY_HTON(rte_be32_t)),
5658                 .call = parse_vc_conf,
5659         },
5660         [ACTION_INC_TCP_ACK] = {
5661                 .name = "inc_tcp_ack",
5662                 .help = "increase TCP acknowledgment number",
5663                 .priv = PRIV_ACTION(INC_TCP_ACK, sizeof(rte_be32_t)),
5664                 .next = NEXT(action_inc_tcp_ack),
5665                 .call = parse_vc,
5666         },
5667         [ACTION_INC_TCP_ACK_VALUE] = {
5668                 .name = "value",
5669                 .help = "the value to increase TCP acknowledgment number by",
5670                 .next = NEXT(action_inc_tcp_ack, NEXT_ENTRY(COMMON_UNSIGNED)),
5671                 .args = ARGS(ARG_ENTRY_HTON(rte_be32_t)),
5672                 .call = parse_vc_conf,
5673         },
5674         [ACTION_DEC_TCP_ACK] = {
5675                 .name = "dec_tcp_ack",
5676                 .help = "decrease TCP acknowledgment number",
5677                 .priv = PRIV_ACTION(DEC_TCP_ACK, sizeof(rte_be32_t)),
5678                 .next = NEXT(action_dec_tcp_ack),
5679                 .call = parse_vc,
5680         },
5681         [ACTION_DEC_TCP_ACK_VALUE] = {
5682                 .name = "value",
5683                 .help = "the value to decrease TCP acknowledgment number by",
5684                 .next = NEXT(action_dec_tcp_ack, NEXT_ENTRY(COMMON_UNSIGNED)),
5685                 .args = ARGS(ARG_ENTRY_HTON(rte_be32_t)),
5686                 .call = parse_vc_conf,
5687         },
5688         [ACTION_RAW_ENCAP] = {
5689                 .name = "raw_encap",
5690                 .help = "encapsulation data, defined by set raw_encap",
5691                 .priv = PRIV_ACTION(RAW_ENCAP,
5692                         sizeof(struct action_raw_encap_data)),
5693                 .next = NEXT(action_raw_encap),
5694                 .call = parse_vc_action_raw_encap,
5695         },
5696         [ACTION_RAW_ENCAP_INDEX] = {
5697                 .name = "index",
5698                 .help = "the index of raw_encap_confs",
5699                 .next = NEXT(NEXT_ENTRY(ACTION_RAW_ENCAP_INDEX_VALUE)),
5700         },
5701         [ACTION_RAW_ENCAP_INDEX_VALUE] = {
5702                 .name = "{index}",
5703                 .type = "UNSIGNED",
5704                 .help = "unsigned integer value",
5705                 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
5706                 .call = parse_vc_action_raw_encap_index,
5707                 .comp = comp_set_raw_index,
5708         },
5709         [ACTION_RAW_DECAP] = {
5710                 .name = "raw_decap",
5711                 .help = "decapsulation data, defined by set raw_encap",
5712                 .priv = PRIV_ACTION(RAW_DECAP,
5713                         sizeof(struct action_raw_decap_data)),
5714                 .next = NEXT(action_raw_decap),
5715                 .call = parse_vc_action_raw_decap,
5716         },
5717         [ACTION_RAW_DECAP_INDEX] = {
5718                 .name = "index",
5719                 .help = "the index of raw_encap_confs",
5720                 .next = NEXT(NEXT_ENTRY(ACTION_RAW_DECAP_INDEX_VALUE)),
5721         },
5722         [ACTION_RAW_DECAP_INDEX_VALUE] = {
5723                 .name = "{index}",
5724                 .type = "UNSIGNED",
5725                 .help = "unsigned integer value",
5726                 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
5727                 .call = parse_vc_action_raw_decap_index,
5728                 .comp = comp_set_raw_index,
5729         },
5730         [ACTION_MODIFY_FIELD] = {
5731                 .name = "modify_field",
5732                 .help = "modify destination field with data from source field",
5733                 .priv = PRIV_ACTION(MODIFY_FIELD, ACTION_MODIFY_SIZE),
5734                 .next = NEXT(NEXT_ENTRY(ACTION_MODIFY_FIELD_OP)),
5735                 .call = parse_vc,
5736         },
5737         [ACTION_MODIFY_FIELD_OP] = {
5738                 .name = "op",
5739                 .help = "operation type",
5740                 .next = NEXT(NEXT_ENTRY(ACTION_MODIFY_FIELD_DST_TYPE),
5741                         NEXT_ENTRY(ACTION_MODIFY_FIELD_OP_VALUE)),
5742                 .call = parse_vc_conf,
5743         },
5744         [ACTION_MODIFY_FIELD_OP_VALUE] = {
5745                 .name = "{operation}",
5746                 .help = "operation type value",
5747                 .call = parse_vc_modify_field_op,
5748                 .comp = comp_set_modify_field_op,
5749         },
5750         [ACTION_MODIFY_FIELD_DST_TYPE] = {
5751                 .name = "dst_type",
5752                 .help = "destination field type",
5753                 .next = NEXT(action_modify_field_dst,
5754                         NEXT_ENTRY(ACTION_MODIFY_FIELD_DST_TYPE_VALUE)),
5755                 .call = parse_vc_conf,
5756         },
5757         [ACTION_MODIFY_FIELD_DST_TYPE_VALUE] = {
5758                 .name = "{dst_type}",
5759                 .help = "destination field type value",
5760                 .call = parse_vc_modify_field_id,
5761                 .comp = comp_set_modify_field_id,
5762         },
5763         [ACTION_MODIFY_FIELD_DST_LEVEL] = {
5764                 .name = "dst_level",
5765                 .help = "destination field level",
5766                 .next = NEXT(action_modify_field_dst,
5767                              NEXT_ENTRY(COMMON_UNSIGNED)),
5768                 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_modify_field,
5769                                         dst.level)),
5770                 .call = parse_vc_conf,
5771         },
5772         [ACTION_MODIFY_FIELD_DST_OFFSET] = {
5773                 .name = "dst_offset",
5774                 .help = "destination field bit offset",
5775                 .next = NEXT(action_modify_field_dst,
5776                              NEXT_ENTRY(COMMON_UNSIGNED)),
5777                 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_modify_field,
5778                                         dst.offset)),
5779                 .call = parse_vc_conf,
5780         },
5781         [ACTION_MODIFY_FIELD_SRC_TYPE] = {
5782                 .name = "src_type",
5783                 .help = "source field type",
5784                 .next = NEXT(action_modify_field_src,
5785                         NEXT_ENTRY(ACTION_MODIFY_FIELD_SRC_TYPE_VALUE)),
5786                 .call = parse_vc_conf,
5787         },
5788         [ACTION_MODIFY_FIELD_SRC_TYPE_VALUE] = {
5789                 .name = "{src_type}",
5790                 .help = "source field type value",
5791                 .call = parse_vc_modify_field_id,
5792                 .comp = comp_set_modify_field_id,
5793         },
5794         [ACTION_MODIFY_FIELD_SRC_LEVEL] = {
5795                 .name = "src_level",
5796                 .help = "source field level",
5797                 .next = NEXT(action_modify_field_src,
5798                              NEXT_ENTRY(COMMON_UNSIGNED)),
5799                 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_modify_field,
5800                                         src.level)),
5801                 .call = parse_vc_conf,
5802         },
5803         [ACTION_MODIFY_FIELD_SRC_OFFSET] = {
5804                 .name = "src_offset",
5805                 .help = "source field bit offset",
5806                 .next = NEXT(action_modify_field_src,
5807                              NEXT_ENTRY(COMMON_UNSIGNED)),
5808                 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_modify_field,
5809                                         src.offset)),
5810                 .call = parse_vc_conf,
5811         },
5812         [ACTION_MODIFY_FIELD_SRC_VALUE] = {
5813                 .name = "src_value",
5814                 .help = "source immediate value",
5815                 .next = NEXT(NEXT_ENTRY(ACTION_MODIFY_FIELD_WIDTH),
5816                              NEXT_ENTRY(COMMON_HEX)),
5817                 .args = ARGS(ARGS_ENTRY_ARB(0, 0),
5818                              ARGS_ENTRY_ARB(0, 0),
5819                              ARGS_ENTRY(struct rte_flow_action_modify_field,
5820                                         src.value)),
5821                 .call = parse_vc_conf,
5822         },
5823         [ACTION_MODIFY_FIELD_SRC_POINTER] = {
5824                 .name = "src_ptr",
5825                 .help = "pointer to source immediate value",
5826                 .next = NEXT(NEXT_ENTRY(ACTION_MODIFY_FIELD_WIDTH),
5827                              NEXT_ENTRY(COMMON_HEX)),
5828                 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_modify_field,
5829                                         src.pvalue),
5830                              ARGS_ENTRY_ARB(0, 0),
5831                              ARGS_ENTRY_ARB
5832                                 (sizeof(struct rte_flow_action_modify_field),
5833                                  ACTION_MODIFY_PATTERN_SIZE)),
5834                 .call = parse_vc_conf,
5835         },
5836         [ACTION_MODIFY_FIELD_WIDTH] = {
5837                 .name = "width",
5838                 .help = "number of bits to copy",
5839                 .next = NEXT(NEXT_ENTRY(ACTION_NEXT),
5840                         NEXT_ENTRY(COMMON_UNSIGNED)),
5841                 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_modify_field,
5842                                         width)),
5843                 .call = parse_vc_conf,
5844         },
5845         /* Top level command. */
5846         [SET] = {
5847                 .name = "set",
5848                 .help = "set raw encap/decap/sample data",
5849                 .type = "set raw_encap|raw_decap <index> <pattern>"
5850                                 " or set sample_actions <index> <action>",
5851                 .next = NEXT(NEXT_ENTRY
5852                              (SET_RAW_ENCAP,
5853                               SET_RAW_DECAP,
5854                               SET_SAMPLE_ACTIONS)),
5855                 .call = parse_set_init,
5856         },
5857         /* Sub-level commands. */
5858         [SET_RAW_ENCAP] = {
5859                 .name = "raw_encap",
5860                 .help = "set raw encap data",
5861                 .next = NEXT(next_set_raw),
5862                 .args = ARGS(ARGS_ENTRY_ARB_BOUNDED
5863                                 (offsetof(struct buffer, port),
5864                                  sizeof(((struct buffer *)0)->port),
5865                                  0, RAW_ENCAP_CONFS_MAX_NUM - 1)),
5866                 .call = parse_set_raw_encap_decap,
5867         },
5868         [SET_RAW_DECAP] = {
5869                 .name = "raw_decap",
5870                 .help = "set raw decap data",
5871                 .next = NEXT(next_set_raw),
5872                 .args = ARGS(ARGS_ENTRY_ARB_BOUNDED
5873                                 (offsetof(struct buffer, port),
5874                                  sizeof(((struct buffer *)0)->port),
5875                                  0, RAW_ENCAP_CONFS_MAX_NUM - 1)),
5876                 .call = parse_set_raw_encap_decap,
5877         },
5878         [SET_RAW_INDEX] = {
5879                 .name = "{index}",
5880                 .type = "COMMON_UNSIGNED",
5881                 .help = "index of raw_encap/raw_decap data",
5882                 .next = NEXT(next_item),
5883                 .call = parse_port,
5884         },
5885         [SET_SAMPLE_INDEX] = {
5886                 .name = "{index}",
5887                 .type = "UNSIGNED",
5888                 .help = "index of sample actions",
5889                 .next = NEXT(next_action_sample),
5890                 .call = parse_port,
5891         },
5892         [SET_SAMPLE_ACTIONS] = {
5893                 .name = "sample_actions",
5894                 .help = "set sample actions list",
5895                 .next = NEXT(NEXT_ENTRY(SET_SAMPLE_INDEX)),
5896                 .args = ARGS(ARGS_ENTRY_ARB_BOUNDED
5897                                 (offsetof(struct buffer, port),
5898                                  sizeof(((struct buffer *)0)->port),
5899                                  0, RAW_SAMPLE_CONFS_MAX_NUM - 1)),
5900                 .call = parse_set_sample_action,
5901         },
5902         [ACTION_SET_TAG] = {
5903                 .name = "set_tag",
5904                 .help = "set tag",
5905                 .priv = PRIV_ACTION(SET_TAG,
5906                         sizeof(struct rte_flow_action_set_tag)),
5907                 .next = NEXT(action_set_tag),
5908                 .call = parse_vc,
5909         },
5910         [ACTION_SET_TAG_INDEX] = {
5911                 .name = "index",
5912                 .help = "index of tag array",
5913                 .next = NEXT(action_set_tag, NEXT_ENTRY(COMMON_UNSIGNED)),
5914                 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_set_tag, index)),
5915                 .call = parse_vc_conf,
5916         },
5917         [ACTION_SET_TAG_DATA] = {
5918                 .name = "data",
5919                 .help = "tag value",
5920                 .next = NEXT(action_set_tag, NEXT_ENTRY(COMMON_UNSIGNED)),
5921                 .args = ARGS(ARGS_ENTRY
5922                              (struct rte_flow_action_set_tag, data)),
5923                 .call = parse_vc_conf,
5924         },
5925         [ACTION_SET_TAG_MASK] = {
5926                 .name = "mask",
5927                 .help = "mask for tag value",
5928                 .next = NEXT(action_set_tag, NEXT_ENTRY(COMMON_UNSIGNED)),
5929                 .args = ARGS(ARGS_ENTRY
5930                              (struct rte_flow_action_set_tag, mask)),
5931                 .call = parse_vc_conf,
5932         },
5933         [ACTION_SET_META] = {
5934                 .name = "set_meta",
5935                 .help = "set metadata",
5936                 .priv = PRIV_ACTION(SET_META,
5937                         sizeof(struct rte_flow_action_set_meta)),
5938                 .next = NEXT(action_set_meta),
5939                 .call = parse_vc_action_set_meta,
5940         },
5941         [ACTION_SET_META_DATA] = {
5942                 .name = "data",
5943                 .help = "metadata value",
5944                 .next = NEXT(action_set_meta, NEXT_ENTRY(COMMON_UNSIGNED)),
5945                 .args = ARGS(ARGS_ENTRY
5946                              (struct rte_flow_action_set_meta, data)),
5947                 .call = parse_vc_conf,
5948         },
5949         [ACTION_SET_META_MASK] = {
5950                 .name = "mask",
5951                 .help = "mask for metadata value",
5952                 .next = NEXT(action_set_meta, NEXT_ENTRY(COMMON_UNSIGNED)),
5953                 .args = ARGS(ARGS_ENTRY
5954                              (struct rte_flow_action_set_meta, mask)),
5955                 .call = parse_vc_conf,
5956         },
5957         [ACTION_SET_IPV4_DSCP] = {
5958                 .name = "set_ipv4_dscp",
5959                 .help = "set DSCP value",
5960                 .priv = PRIV_ACTION(SET_IPV4_DSCP,
5961                         sizeof(struct rte_flow_action_set_dscp)),
5962                 .next = NEXT(action_set_ipv4_dscp),
5963                 .call = parse_vc,
5964         },
5965         [ACTION_SET_IPV4_DSCP_VALUE] = {
5966                 .name = "dscp_value",
5967                 .help = "new IPv4 DSCP value to set",
5968                 .next = NEXT(action_set_ipv4_dscp, NEXT_ENTRY(COMMON_UNSIGNED)),
5969                 .args = ARGS(ARGS_ENTRY
5970                              (struct rte_flow_action_set_dscp, dscp)),
5971                 .call = parse_vc_conf,
5972         },
5973         [ACTION_SET_IPV6_DSCP] = {
5974                 .name = "set_ipv6_dscp",
5975                 .help = "set DSCP value",
5976                 .priv = PRIV_ACTION(SET_IPV6_DSCP,
5977                         sizeof(struct rte_flow_action_set_dscp)),
5978                 .next = NEXT(action_set_ipv6_dscp),
5979                 .call = parse_vc,
5980         },
5981         [ACTION_SET_IPV6_DSCP_VALUE] = {
5982                 .name = "dscp_value",
5983                 .help = "new IPv6 DSCP value to set",
5984                 .next = NEXT(action_set_ipv6_dscp, NEXT_ENTRY(COMMON_UNSIGNED)),
5985                 .args = ARGS(ARGS_ENTRY
5986                              (struct rte_flow_action_set_dscp, dscp)),
5987                 .call = parse_vc_conf,
5988         },
5989         [ACTION_AGE] = {
5990                 .name = "age",
5991                 .help = "set a specific metadata header",
5992                 .next = NEXT(action_age),
5993                 .priv = PRIV_ACTION(AGE,
5994                         sizeof(struct rte_flow_action_age)),
5995                 .call = parse_vc,
5996         },
5997         [ACTION_AGE_TIMEOUT] = {
5998                 .name = "timeout",
5999                 .help = "flow age timeout value",
6000                 .args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_age,
6001                                            timeout, 24)),
6002                 .next = NEXT(action_age, NEXT_ENTRY(COMMON_UNSIGNED)),
6003                 .call = parse_vc_conf,
6004         },
6005         [ACTION_SAMPLE] = {
6006                 .name = "sample",
6007                 .help = "set a sample action",
6008                 .next = NEXT(action_sample),
6009                 .priv = PRIV_ACTION(SAMPLE,
6010                         sizeof(struct action_sample_data)),
6011                 .call = parse_vc_action_sample,
6012         },
6013         [ACTION_SAMPLE_RATIO] = {
6014                 .name = "ratio",
6015                 .help = "flow sample ratio value",
6016                 .next = NEXT(action_sample, NEXT_ENTRY(COMMON_UNSIGNED)),
6017                 .args = ARGS(ARGS_ENTRY_ARB
6018                              (offsetof(struct action_sample_data, conf) +
6019                               offsetof(struct rte_flow_action_sample, ratio),
6020                               sizeof(((struct rte_flow_action_sample *)0)->
6021                                      ratio))),
6022         },
6023         [ACTION_SAMPLE_INDEX] = {
6024                 .name = "index",
6025                 .help = "the index of sample actions list",
6026                 .next = NEXT(NEXT_ENTRY(ACTION_SAMPLE_INDEX_VALUE)),
6027         },
6028         [ACTION_SAMPLE_INDEX_VALUE] = {
6029                 .name = "{index}",
6030                 .type = "COMMON_UNSIGNED",
6031                 .help = "unsigned integer value",
6032                 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
6033                 .call = parse_vc_action_sample_index,
6034                 .comp = comp_set_sample_index,
6035         },
6036         [ACTION_CONNTRACK] = {
6037                 .name = "conntrack",
6038                 .help = "create a conntrack object",
6039                 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
6040                 .priv = PRIV_ACTION(CONNTRACK,
6041                                     sizeof(struct rte_flow_action_conntrack)),
6042                 .call = parse_vc,
6043         },
6044         [ACTION_CONNTRACK_UPDATE] = {
6045                 .name = "conntrack_update",
6046                 .help = "update a conntrack object",
6047                 .next = NEXT(action_update_conntrack),
6048                 .priv = PRIV_ACTION(CONNTRACK,
6049                                     sizeof(struct rte_flow_modify_conntrack)),
6050                 .call = parse_vc,
6051         },
6052         [ACTION_CONNTRACK_UPDATE_DIR] = {
6053                 .name = "dir",
6054                 .help = "update a conntrack object direction",
6055                 .next = NEXT(action_update_conntrack),
6056                 .call = parse_vc_action_conntrack_update,
6057         },
6058         [ACTION_CONNTRACK_UPDATE_CTX] = {
6059                 .name = "ctx",
6060                 .help = "update a conntrack object context",
6061                 .next = NEXT(action_update_conntrack),
6062                 .call = parse_vc_action_conntrack_update,
6063         },
6064         [ACTION_PORT_REPRESENTOR] = {
6065                 .name = "port_representor",
6066                 .help = "at embedded switch level, send matching traffic to the given ethdev",
6067                 .priv = PRIV_ACTION(PORT_REPRESENTOR,
6068                                     sizeof(struct rte_flow_action_ethdev)),
6069                 .next = NEXT(action_port_representor),
6070                 .call = parse_vc,
6071         },
6072         [ACTION_PORT_REPRESENTOR_PORT_ID] = {
6073                 .name = "port_id",
6074                 .help = "ethdev port ID",
6075                 .next = NEXT(action_port_representor,
6076                              NEXT_ENTRY(COMMON_UNSIGNED)),
6077                 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_ethdev,
6078                                         port_id)),
6079                 .call = parse_vc_conf,
6080         },
6081         [ACTION_REPRESENTED_PORT] = {
6082                 .name = "represented_port",
6083                 .help = "at embedded switch level, send matching traffic to the entity represented by the given ethdev",
6084                 .priv = PRIV_ACTION(REPRESENTED_PORT,
6085                                 sizeof(struct rte_flow_action_ethdev)),
6086                 .next = NEXT(action_represented_port),
6087                 .call = parse_vc,
6088         },
6089         [ACTION_REPRESENTED_PORT_ETHDEV_PORT_ID] = {
6090                 .name = "ethdev_port_id",
6091                 .help = "ethdev port ID",
6092                 .next = NEXT(action_represented_port,
6093                              NEXT_ENTRY(COMMON_UNSIGNED)),
6094                 .args = ARGS(ARGS_ENTRY(struct rte_flow_action_ethdev,
6095                                         port_id)),
6096                 .call = parse_vc_conf,
6097         },
6098         /* Indirect action destroy arguments. */
6099         [INDIRECT_ACTION_DESTROY_ID] = {
6100                 .name = "action_id",
6101                 .help = "specify a indirect action id to destroy",
6102                 .next = NEXT(next_ia_destroy_attr,
6103                              NEXT_ENTRY(COMMON_INDIRECT_ACTION_ID)),
6104                 .args = ARGS(ARGS_ENTRY_PTR(struct buffer,
6105                                             args.ia_destroy.action_id)),
6106                 .call = parse_ia_destroy,
6107         },
6108         /* Indirect action create arguments. */
6109         [INDIRECT_ACTION_CREATE_ID] = {
6110                 .name = "action_id",
6111                 .help = "specify a indirect action id to create",
6112                 .next = NEXT(next_ia_create_attr,
6113                              NEXT_ENTRY(COMMON_INDIRECT_ACTION_ID)),
6114                 .args = ARGS(ARGS_ENTRY(struct buffer, args.vc.attr.group)),
6115         },
6116         [ACTION_INDIRECT] = {
6117                 .name = "indirect",
6118                 .help = "apply indirect action by id",
6119                 .priv = PRIV_ACTION(INDIRECT, 0),
6120                 .next = NEXT(NEXT_ENTRY(INDIRECT_ACTION_ID2PTR)),
6121                 .args = ARGS(ARGS_ENTRY_ARB(0, sizeof(uint32_t))),
6122                 .call = parse_vc,
6123         },
6124         [INDIRECT_ACTION_ID2PTR] = {
6125                 .name = "{action_id}",
6126                 .type = "INDIRECT_ACTION_ID",
6127                 .help = "indirect action id",
6128                 .next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
6129                 .call = parse_ia_id2ptr,
6130                 .comp = comp_none,
6131         },
6132         [INDIRECT_ACTION_INGRESS] = {
6133                 .name = "ingress",
6134                 .help = "affect rule to ingress",
6135                 .next = NEXT(next_ia_create_attr),
6136                 .call = parse_ia,
6137         },
6138         [INDIRECT_ACTION_EGRESS] = {
6139                 .name = "egress",
6140                 .help = "affect rule to egress",
6141                 .next = NEXT(next_ia_create_attr),
6142                 .call = parse_ia,
6143         },
6144         [INDIRECT_ACTION_TRANSFER] = {
6145                 .name = "transfer",
6146                 .help = "affect rule to transfer",
6147                 .next = NEXT(next_ia_create_attr),
6148                 .call = parse_ia,
6149         },
6150         [INDIRECT_ACTION_SPEC] = {
6151                 .name = "action",
6152                 .help = "specify action to create indirect handle",
6153                 .next = NEXT(next_action),
6154         },
6155         [ACTION_POL_G] = {
6156                 .name = "g_actions",
6157                 .help = "submit a list of associated actions for green",
6158                 .next = NEXT(next_action),
6159                 .call = parse_mp,
6160         },
6161         [ACTION_POL_Y] = {
6162                 .name = "y_actions",
6163                 .help = "submit a list of associated actions for yellow",
6164                 .next = NEXT(next_action),
6165         },
6166         [ACTION_POL_R] = {
6167                 .name = "r_actions",
6168                 .help = "submit a list of associated actions for red",
6169                 .next = NEXT(next_action),
6170         },
6171
6172         /* Top-level command. */
6173         [ADD] = {
6174                 .name = "add",
6175                 .type = "port meter policy {port_id} {arg}",
6176                 .help = "add port meter policy",
6177                 .next = NEXT(NEXT_ENTRY(ITEM_POL_PORT)),
6178                 .call = parse_init,
6179         },
6180         /* Sub-level commands. */
6181         [ITEM_POL_PORT] = {
6182                 .name = "port",
6183                 .help = "add port meter policy",
6184                 .next = NEXT(NEXT_ENTRY(ITEM_POL_METER)),
6185         },
6186         [ITEM_POL_METER] = {
6187                 .name = "meter",
6188                 .help = "add port meter policy",
6189                 .next = NEXT(NEXT_ENTRY(ITEM_POL_POLICY)),
6190         },
6191         [ITEM_POL_POLICY] = {
6192                 .name = "policy",
6193                 .help = "add port meter policy",
6194                 .next = NEXT(NEXT_ENTRY(ACTION_POL_R),
6195                                 NEXT_ENTRY(ACTION_POL_Y),
6196                                 NEXT_ENTRY(ACTION_POL_G),
6197                                 NEXT_ENTRY(COMMON_POLICY_ID),
6198                                 NEXT_ENTRY(COMMON_PORT_ID)),
6199                 .args = ARGS(ARGS_ENTRY(struct buffer, args.policy.policy_id),
6200                                 ARGS_ENTRY(struct buffer, port)),
6201                 .call = parse_mp,
6202         },
6203 };
6204
6205 /** Remove and return last entry from argument stack. */
6206 static const struct arg *
6207 pop_args(struct context *ctx)
6208 {
6209         return ctx->args_num ? ctx->args[--ctx->args_num] : NULL;
6210 }
6211
6212 /** Add entry on top of the argument stack. */
6213 static int
6214 push_args(struct context *ctx, const struct arg *arg)
6215 {
6216         if (ctx->args_num == CTX_STACK_SIZE)
6217                 return -1;
6218         ctx->args[ctx->args_num++] = arg;
6219         return 0;
6220 }
6221
6222 /** Spread value into buffer according to bit-mask. */
6223 static size_t
6224 arg_entry_bf_fill(void *dst, uintmax_t val, const struct arg *arg)
6225 {
6226         uint32_t i = arg->size;
6227         uint32_t end = 0;
6228         int sub = 1;
6229         int add = 0;
6230         size_t len = 0;
6231
6232         if (!arg->mask)
6233                 return 0;
6234 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
6235         if (!arg->hton) {
6236                 i = 0;
6237                 end = arg->size;
6238                 sub = 0;
6239                 add = 1;
6240         }
6241 #endif
6242         while (i != end) {
6243                 unsigned int shift = 0;
6244                 uint8_t *buf = (uint8_t *)dst + arg->offset + (i -= sub);
6245
6246                 for (shift = 0; arg->mask[i] >> shift; ++shift) {
6247                         if (!(arg->mask[i] & (1 << shift)))
6248                                 continue;
6249                         ++len;
6250                         if (!dst)
6251                                 continue;
6252                         *buf &= ~(1 << shift);
6253                         *buf |= (val & 1) << shift;
6254                         val >>= 1;
6255                 }
6256                 i += add;
6257         }
6258         return len;
6259 }
6260
6261 /** Compare a string with a partial one of a given length. */
6262 static int
6263 strcmp_partial(const char *full, const char *partial, size_t partial_len)
6264 {
6265         int r = strncmp(full, partial, partial_len);
6266
6267         if (r)
6268                 return r;
6269         if (strlen(full) <= partial_len)
6270                 return 0;
6271         return full[partial_len];
6272 }
6273
6274 /**
6275  * Parse a prefix length and generate a bit-mask.
6276  *
6277  * Last argument (ctx->args) is retrieved to determine mask size, storage
6278  * location and whether the result must use network byte ordering.
6279  */
6280 static int
6281 parse_prefix(struct context *ctx, const struct token *token,
6282              const char *str, unsigned int len,
6283              void *buf, unsigned int size)
6284 {
6285         const struct arg *arg = pop_args(ctx);
6286         static const uint8_t conv[] = "\x00\x80\xc0\xe0\xf0\xf8\xfc\xfe\xff";
6287         char *end;
6288         uintmax_t u;
6289         unsigned int bytes;
6290         unsigned int extra;
6291
6292         (void)token;
6293         /* Argument is expected. */
6294         if (!arg)
6295                 return -1;
6296         errno = 0;
6297         u = strtoumax(str, &end, 0);
6298         if (errno || (size_t)(end - str) != len)
6299                 goto error;
6300         if (arg->mask) {
6301                 uintmax_t v = 0;
6302
6303                 extra = arg_entry_bf_fill(NULL, 0, arg);
6304                 if (u > extra)
6305                         goto error;
6306                 if (!ctx->object)
6307                         return len;
6308                 extra -= u;
6309                 while (u--)
6310                         (v <<= 1, v |= 1);
6311                 v <<= extra;
6312                 if (!arg_entry_bf_fill(ctx->object, v, arg) ||
6313                     !arg_entry_bf_fill(ctx->objmask, -1, arg))
6314                         goto error;
6315                 return len;
6316         }
6317         bytes = u / 8;
6318         extra = u % 8;
6319         size = arg->size;
6320         if (bytes > size || bytes + !!extra > size)
6321                 goto error;
6322         if (!ctx->object)
6323                 return len;
6324         buf = (uint8_t *)ctx->object + arg->offset;
6325 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
6326         if (!arg->hton) {
6327                 memset((uint8_t *)buf + size - bytes, 0xff, bytes);
6328                 memset(buf, 0x00, size - bytes);
6329                 if (extra)
6330                         ((uint8_t *)buf)[size - bytes - 1] = conv[extra];
6331         } else
6332 #endif
6333         {
6334                 memset(buf, 0xff, bytes);
6335                 memset((uint8_t *)buf + bytes, 0x00, size - bytes);
6336                 if (extra)
6337                         ((uint8_t *)buf)[bytes] = conv[extra];
6338         }
6339         if (ctx->objmask)
6340                 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
6341         return len;
6342 error:
6343         push_args(ctx, arg);
6344         return -1;
6345 }
6346
6347 /** Default parsing function for token name matching. */
6348 static int
6349 parse_default(struct context *ctx, const struct token *token,
6350               const char *str, unsigned int len,
6351               void *buf, unsigned int size)
6352 {
6353         (void)ctx;
6354         (void)buf;
6355         (void)size;
6356         if (strcmp_partial(token->name, str, len))
6357                 return -1;
6358         return len;
6359 }
6360
6361 /** Parse flow command, initialize output buffer for subsequent tokens. */
6362 static int
6363 parse_init(struct context *ctx, const struct token *token,
6364            const char *str, unsigned int len,
6365            void *buf, unsigned int size)
6366 {
6367         struct buffer *out = buf;
6368
6369         /* Token name must match. */
6370         if (parse_default(ctx, token, str, len, NULL, 0) < 0)
6371                 return -1;
6372         /* Nothing else to do if there is no buffer. */
6373         if (!out)
6374                 return len;
6375         /* Make sure buffer is large enough. */
6376         if (size < sizeof(*out))
6377                 return -1;
6378         /* Initialize buffer. */
6379         memset(out, 0x00, sizeof(*out));
6380         memset((uint8_t *)out + sizeof(*out), 0x22, size - sizeof(*out));
6381         ctx->objdata = 0;
6382         ctx->object = out;
6383         ctx->objmask = NULL;
6384         return len;
6385 }
6386
6387 /** Parse tokens for indirect action commands. */
6388 static int
6389 parse_ia(struct context *ctx, const struct token *token,
6390          const char *str, unsigned int len,
6391          void *buf, unsigned int size)
6392 {
6393         struct buffer *out = buf;
6394
6395         /* Token name must match. */
6396         if (parse_default(ctx, token, str, len, NULL, 0) < 0)
6397                 return -1;
6398         /* Nothing else to do if there is no buffer. */
6399         if (!out)
6400                 return len;
6401         if (!out->command) {
6402                 if (ctx->curr != INDIRECT_ACTION)
6403                         return -1;
6404                 if (sizeof(*out) > size)
6405                         return -1;
6406                 out->command = ctx->curr;
6407                 ctx->objdata = 0;
6408                 ctx->object = out;
6409                 ctx->objmask = NULL;
6410                 out->args.vc.data = (uint8_t *)out + size;
6411                 return len;
6412         }
6413         switch (ctx->curr) {
6414         case INDIRECT_ACTION_CREATE:
6415         case INDIRECT_ACTION_UPDATE:
6416                 out->args.vc.actions =
6417                         (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
6418                                                sizeof(double));
6419                 out->args.vc.attr.group = UINT32_MAX;
6420                 /* fallthrough */
6421         case INDIRECT_ACTION_QUERY:
6422                 out->command = ctx->curr;
6423                 ctx->objdata = 0;
6424                 ctx->object = out;
6425                 ctx->objmask = NULL;
6426                 return len;
6427         case INDIRECT_ACTION_EGRESS:
6428                 out->args.vc.attr.egress = 1;
6429                 return len;
6430         case INDIRECT_ACTION_INGRESS:
6431                 out->args.vc.attr.ingress = 1;
6432                 return len;
6433         case INDIRECT_ACTION_TRANSFER:
6434                 out->args.vc.attr.transfer = 1;
6435                 return len;
6436         default:
6437                 return -1;
6438         }
6439 }
6440
6441
6442 /** Parse tokens for indirect action destroy command. */
6443 static int
6444 parse_ia_destroy(struct context *ctx, const struct token *token,
6445                  const char *str, unsigned int len,
6446                  void *buf, unsigned int size)
6447 {
6448         struct buffer *out = buf;
6449         uint32_t *action_id;
6450
6451         /* Token name must match. */
6452         if (parse_default(ctx, token, str, len, NULL, 0) < 0)
6453                 return -1;
6454         /* Nothing else to do if there is no buffer. */
6455         if (!out)
6456                 return len;
6457         if (!out->command || out->command == INDIRECT_ACTION) {
6458                 if (ctx->curr != INDIRECT_ACTION_DESTROY)
6459                         return -1;
6460                 if (sizeof(*out) > size)
6461                         return -1;
6462                 out->command = ctx->curr;
6463                 ctx->objdata = 0;
6464                 ctx->object = out;
6465                 ctx->objmask = NULL;
6466                 out->args.ia_destroy.action_id =
6467                         (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
6468                                                sizeof(double));
6469                 return len;
6470         }
6471         action_id = out->args.ia_destroy.action_id
6472                     + out->args.ia_destroy.action_id_n++;
6473         if ((uint8_t *)action_id > (uint8_t *)out + size)
6474                 return -1;
6475         ctx->objdata = 0;
6476         ctx->object = action_id;
6477         ctx->objmask = NULL;
6478         return len;
6479 }
6480
6481 /** Parse tokens for meter policy action commands. */
6482 static int
6483 parse_mp(struct context *ctx, const struct token *token,
6484         const char *str, unsigned int len,
6485         void *buf, unsigned int size)
6486 {
6487         struct buffer *out = buf;
6488
6489         /* Token name must match. */
6490         if (parse_default(ctx, token, str, len, NULL, 0) < 0)
6491                 return -1;
6492         /* Nothing else to do if there is no buffer. */
6493         if (!out)
6494                 return len;
6495         if (!out->command) {
6496                 if (ctx->curr != ITEM_POL_POLICY)
6497                         return -1;
6498                 if (sizeof(*out) > size)
6499                         return -1;
6500                 out->command = ctx->curr;
6501                 ctx->objdata = 0;
6502                 ctx->object = out;
6503                 ctx->objmask = NULL;
6504                 out->args.vc.data = (uint8_t *)out + size;
6505                 return len;
6506         }
6507         switch (ctx->curr) {
6508         case ACTION_POL_G:
6509                 out->args.vc.actions =
6510                         (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
6511                                         sizeof(double));
6512                 out->command = ctx->curr;
6513                 ctx->objdata = 0;
6514                 ctx->object = out;
6515                 ctx->objmask = NULL;
6516                 return len;
6517         default:
6518                 return -1;
6519         }
6520 }
6521
6522 /** Parse tokens for validate/create commands. */
6523 static int
6524 parse_vc(struct context *ctx, const struct token *token,
6525          const char *str, unsigned int len,
6526          void *buf, unsigned int size)
6527 {
6528         struct buffer *out = buf;
6529         uint8_t *data;
6530         uint32_t data_size;
6531
6532         /* Token name must match. */
6533         if (parse_default(ctx, token, str, len, NULL, 0) < 0)
6534                 return -1;
6535         /* Nothing else to do if there is no buffer. */
6536         if (!out)
6537                 return len;
6538         if (!out->command) {
6539                 if (ctx->curr != VALIDATE && ctx->curr != CREATE &&
6540                     ctx->curr != PATTERN_TEMPLATE_CREATE &&
6541                     ctx->curr != ACTIONS_TEMPLATE_CREATE)
6542                         return -1;
6543                 if (sizeof(*out) > size)
6544                         return -1;
6545                 out->command = ctx->curr;
6546                 ctx->objdata = 0;
6547                 ctx->object = out;
6548                 ctx->objmask = NULL;
6549                 out->args.vc.data = (uint8_t *)out + size;
6550                 return len;
6551         }
6552         ctx->objdata = 0;
6553         switch (ctx->curr) {
6554         default:
6555                 ctx->object = &out->args.vc.attr;
6556                 break;
6557         case VC_TUNNEL_SET:
6558         case VC_TUNNEL_MATCH:
6559                 ctx->object = &out->args.vc.tunnel_ops;
6560                 break;
6561         }
6562         ctx->objmask = NULL;
6563         switch (ctx->curr) {
6564         case VC_GROUP:
6565         case VC_PRIORITY:
6566                 return len;
6567         case VC_TUNNEL_SET:
6568                 out->args.vc.tunnel_ops.enabled = 1;
6569                 out->args.vc.tunnel_ops.actions = 1;
6570                 return len;
6571         case VC_TUNNEL_MATCH:
6572                 out->args.vc.tunnel_ops.enabled = 1;
6573                 out->args.vc.tunnel_ops.items = 1;
6574                 return len;
6575         case VC_INGRESS:
6576                 out->args.vc.attr.ingress = 1;
6577                 return len;
6578         case VC_EGRESS:
6579                 out->args.vc.attr.egress = 1;
6580                 return len;
6581         case VC_TRANSFER:
6582                 out->args.vc.attr.transfer = 1;
6583                 return len;
6584         case ITEM_PATTERN:
6585                 out->args.vc.pattern =
6586                         (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
6587                                                sizeof(double));
6588                 ctx->object = out->args.vc.pattern;
6589                 ctx->objmask = NULL;
6590                 return len;
6591         case ACTIONS:
6592                 out->args.vc.actions =
6593                         (void *)RTE_ALIGN_CEIL((uintptr_t)
6594                                                (out->args.vc.pattern +
6595                                                 out->args.vc.pattern_n),
6596                                                sizeof(double));
6597                 ctx->object = out->args.vc.actions;
6598                 ctx->objmask = NULL;
6599                 return len;
6600         default:
6601                 if (!token->priv)
6602                         return -1;
6603                 break;
6604         }
6605         if (!out->args.vc.actions) {
6606                 const struct parse_item_priv *priv = token->priv;
6607                 struct rte_flow_item *item =
6608                         out->args.vc.pattern + out->args.vc.pattern_n;
6609
6610                 data_size = priv->size * 3; /* spec, last, mask */
6611                 data = (void *)RTE_ALIGN_FLOOR((uintptr_t)
6612                                                (out->args.vc.data - data_size),
6613                                                sizeof(double));
6614                 if ((uint8_t *)item + sizeof(*item) > data)
6615                         return -1;
6616                 *item = (struct rte_flow_item){
6617                         .type = priv->type,
6618                 };
6619                 ++out->args.vc.pattern_n;
6620                 ctx->object = item;
6621                 ctx->objmask = NULL;
6622         } else {
6623                 const struct parse_action_priv *priv = token->priv;
6624                 struct rte_flow_action *action =
6625                         out->args.vc.actions + out->args.vc.actions_n;
6626
6627                 data_size = priv->size; /* configuration */
6628                 data = (void *)RTE_ALIGN_FLOOR((uintptr_t)
6629                                                (out->args.vc.data - data_size),
6630                                                sizeof(double));
6631                 if ((uint8_t *)action + sizeof(*action) > data)
6632                         return -1;
6633                 *action = (struct rte_flow_action){
6634                         .type = priv->type,
6635                         .conf = data_size ? data : NULL,
6636                 };
6637                 ++out->args.vc.actions_n;
6638                 ctx->object = action;
6639                 ctx->objmask = NULL;
6640         }
6641         memset(data, 0, data_size);
6642         out->args.vc.data = data;
6643         ctx->objdata = data_size;
6644         return len;
6645 }
6646
6647 /** Parse pattern item parameter type. */
6648 static int
6649 parse_vc_spec(struct context *ctx, const struct token *token,
6650               const char *str, unsigned int len,
6651               void *buf, unsigned int size)
6652 {
6653         struct buffer *out = buf;
6654         struct rte_flow_item *item;
6655         uint32_t data_size;
6656         int index;
6657         int objmask = 0;
6658
6659         (void)size;
6660         /* Token name must match. */
6661         if (parse_default(ctx, token, str, len, NULL, 0) < 0)
6662                 return -1;
6663         /* Parse parameter types. */
6664         switch (ctx->curr) {
6665                 static const enum index prefix[] = NEXT_ENTRY(COMMON_PREFIX);
6666
6667         case ITEM_PARAM_IS:
6668                 index = 0;
6669                 objmask = 1;
6670                 break;
6671         case ITEM_PARAM_SPEC:
6672                 index = 0;
6673                 break;
6674         case ITEM_PARAM_LAST:
6675                 index = 1;
6676                 break;
6677         case ITEM_PARAM_PREFIX:
6678                 /* Modify next token to expect a prefix. */
6679                 if (ctx->next_num < 2)
6680                         return -1;
6681                 ctx->next[ctx->next_num - 2] = prefix;
6682                 /* Fall through. */
6683         case ITEM_PARAM_MASK:
6684                 index = 2;
6685                 break;
6686         default:
6687                 return -1;
6688         }
6689         /* Nothing else to do if there is no buffer. */
6690         if (!out)
6691                 return len;
6692         if (!out->args.vc.pattern_n)
6693                 return -1;
6694         item = &out->args.vc.pattern[out->args.vc.pattern_n - 1];
6695         data_size = ctx->objdata / 3; /* spec, last, mask */
6696         /* Point to selected object. */
6697         ctx->object = out->args.vc.data + (data_size * index);
6698         if (objmask) {
6699                 ctx->objmask = out->args.vc.data + (data_size * 2); /* mask */
6700                 item->mask = ctx->objmask;
6701         } else
6702                 ctx->objmask = NULL;
6703         /* Update relevant item pointer. */
6704         *((const void **[]){ &item->spec, &item->last, &item->mask })[index] =
6705                 ctx->object;
6706         return len;
6707 }
6708
6709 /** Parse action configuration field. */
6710 static int
6711 parse_vc_conf(struct context *ctx, const struct token *token,
6712               const char *str, unsigned int len,
6713               void *buf, unsigned int size)
6714 {
6715         struct buffer *out = buf;
6716
6717         (void)size;
6718         /* Token name must match. */
6719         if (parse_default(ctx, token, str, len, NULL, 0) < 0)
6720                 return -1;
6721         /* Nothing else to do if there is no buffer. */
6722         if (!out)
6723                 return len;
6724         /* Point to selected object. */
6725         ctx->object = out->args.vc.data;
6726         ctx->objmask = NULL;
6727         return len;
6728 }
6729
6730 /** Parse eCPRI common header type field. */
6731 static int
6732 parse_vc_item_ecpri_type(struct context *ctx, const struct token *token,
6733                          const char *str, unsigned int len,
6734                          void *buf, unsigned int size)
6735 {
6736         struct rte_flow_item_ecpri *ecpri;
6737         struct rte_flow_item_ecpri *ecpri_mask;
6738         struct rte_flow_item *item;
6739         uint32_t data_size;
6740         uint8_t msg_type;
6741         struct buffer *out = buf;
6742         const struct arg *arg;
6743
6744         (void)size;
6745         /* Token name must match. */
6746         if (parse_default(ctx, token, str, len, NULL, 0) < 0)
6747                 return -1;
6748         switch (ctx->curr) {
6749         case ITEM_ECPRI_COMMON_TYPE_IQ_DATA:
6750                 msg_type = RTE_ECPRI_MSG_TYPE_IQ_DATA;
6751                 break;
6752         case ITEM_ECPRI_COMMON_TYPE_RTC_CTRL:
6753                 msg_type = RTE_ECPRI_MSG_TYPE_RTC_CTRL;
6754                 break;
6755         case ITEM_ECPRI_COMMON_TYPE_DLY_MSR:
6756                 msg_type = RTE_ECPRI_MSG_TYPE_DLY_MSR;
6757                 break;
6758         default:
6759                 return -1;
6760         }
6761         if (!ctx->object)
6762                 return len;
6763         arg = pop_args(ctx);
6764         if (!arg)
6765                 return -1;
6766         ecpri = (struct rte_flow_item_ecpri *)out->args.vc.data;
6767         ecpri->hdr.common.type = msg_type;
6768         data_size = ctx->objdata / 3; /* spec, last, mask */
6769         ecpri_mask = (struct rte_flow_item_ecpri *)(out->args.vc.data +
6770                                                     (data_size * 2));
6771         ecpri_mask->hdr.common.type = 0xFF;
6772         if (arg->hton) {
6773                 ecpri->hdr.common.u32 = rte_cpu_to_be_32(ecpri->hdr.common.u32);
6774                 ecpri_mask->hdr.common.u32 =
6775                                 rte_cpu_to_be_32(ecpri_mask->hdr.common.u32);
6776         }
6777         item = &out->args.vc.pattern[out->args.vc.pattern_n - 1];
6778         item->spec = ecpri;
6779         item->mask = ecpri_mask;
6780         return len;
6781 }
6782
6783 /** Parse L2TPv2 common header type field. */
6784 static int
6785 parse_vc_item_l2tpv2_type(struct context *ctx, const struct token *token,
6786                          const char *str, unsigned int len,
6787                          void *buf, unsigned int size)
6788 {
6789         struct rte_flow_item_l2tpv2 *l2tpv2;
6790         struct rte_flow_item_l2tpv2 *l2tpv2_mask;
6791         struct rte_flow_item *item;
6792         uint32_t data_size;
6793         uint16_t msg_type = 0;
6794         struct buffer *out = buf;
6795         const struct arg *arg;
6796
6797         (void)size;
6798         /* Token name must match. */
6799         if (parse_default(ctx, token, str, len, NULL, 0) < 0)
6800                 return -1;
6801         switch (ctx->curr) {
6802         case ITEM_L2TPV2_TYPE_DATA:
6803                 msg_type |= RTE_L2TPV2_MSG_TYPE_DATA;
6804                 break;
6805         case ITEM_L2TPV2_TYPE_DATA_L:
6806                 msg_type |= RTE_L2TPV2_MSG_TYPE_DATA_L;
6807                 break;
6808         case ITEM_L2TPV2_TYPE_DATA_S:
6809                 msg_type |= RTE_L2TPV2_MSG_TYPE_DATA_S;
6810                 break;
6811         case ITEM_L2TPV2_TYPE_DATA_O:
6812                 msg_type |= RTE_L2TPV2_MSG_TYPE_DATA_O;
6813                 break;
6814         case ITEM_L2TPV2_TYPE_DATA_L_S:
6815                 msg_type |= RTE_L2TPV2_MSG_TYPE_DATA_L_S;
6816                 break;
6817         case ITEM_L2TPV2_TYPE_CTRL:
6818                 msg_type |= RTE_L2TPV2_MSG_TYPE_CONTROL;
6819                 break;
6820         default:
6821                 return -1;
6822         }
6823         if (!ctx->object)
6824                 return len;
6825         arg = pop_args(ctx);
6826         if (!arg)
6827                 return -1;
6828         l2tpv2 = (struct rte_flow_item_l2tpv2 *)out->args.vc.data;
6829         l2tpv2->hdr.common.flags_version |= msg_type;
6830         data_size = ctx->objdata / 3; /* spec, last, mask */
6831         l2tpv2_mask = (struct rte_flow_item_l2tpv2 *)(out->args.vc.data +
6832                                                     (data_size * 2));
6833         l2tpv2_mask->hdr.common.flags_version = 0xFFFF;
6834         if (arg->hton) {
6835                 l2tpv2->hdr.common.flags_version =
6836                         rte_cpu_to_be_16(l2tpv2->hdr.common.flags_version);
6837                 l2tpv2_mask->hdr.common.flags_version =
6838                     rte_cpu_to_be_16(l2tpv2_mask->hdr.common.flags_version);
6839         }
6840         item = &out->args.vc.pattern[out->args.vc.pattern_n - 1];
6841         item->spec = l2tpv2;
6842         item->mask = l2tpv2_mask;
6843         return len;
6844 }
6845
6846 /** Parse meter color action type. */
6847 static int
6848 parse_vc_action_meter_color_type(struct context *ctx, const struct token *token,
6849                                 const char *str, unsigned int len,
6850                                 void *buf, unsigned int size)
6851 {
6852         struct rte_flow_action *action_data;
6853         struct rte_flow_action_meter_color *conf;
6854         enum rte_color color;
6855
6856         (void)buf;
6857         (void)size;
6858         /* Token name must match. */
6859         if (parse_default(ctx, token, str, len, NULL, 0) < 0)
6860                 return -1;
6861         switch (ctx->curr) {
6862         case ACTION_METER_COLOR_GREEN:
6863                 color = RTE_COLOR_GREEN;
6864         break;
6865         case ACTION_METER_COLOR_YELLOW:
6866                 color = RTE_COLOR_YELLOW;
6867         break;
6868         case ACTION_METER_COLOR_RED:
6869                 color = RTE_COLOR_RED;
6870         break;
6871         default:
6872                 return -1;
6873         }
6874
6875         if (!ctx->object)
6876                 return len;
6877         action_data = ctx->object;
6878         conf = (struct rte_flow_action_meter_color *)
6879                                         (uintptr_t)(action_data->conf);
6880         conf->color = color;
6881         return len;
6882 }
6883
6884 /** Parse RSS action. */
6885 static int
6886 parse_vc_action_rss(struct context *ctx, const struct token *token,
6887                     const char *str, unsigned int len,
6888                     void *buf, unsigned int size)
6889 {
6890         struct buffer *out = buf;
6891         struct rte_flow_action *action;
6892         struct action_rss_data *action_rss_data;
6893         unsigned int i;
6894         int ret;
6895
6896         ret = parse_vc(ctx, token, str, len, buf, size);
6897         if (ret < 0)
6898                 return ret;
6899         /* Nothing else to do if there is no buffer. */
6900         if (!out)
6901                 return ret;
6902         if (!out->args.vc.actions_n)
6903                 return -1;
6904         action = &out->args.vc.actions[out->args.vc.actions_n - 1];
6905         /* Point to selected object. */
6906         ctx->object = out->args.vc.data;
6907         ctx->objmask = NULL;
6908         /* Set up default configuration. */
6909         action_rss_data = ctx->object;
6910         *action_rss_data = (struct action_rss_data){
6911                 .conf = (struct rte_flow_action_rss){
6912                         .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
6913                         .level = 0,
6914                         .types = rss_hf,
6915                         .key_len = 0,
6916                         .queue_num = RTE_MIN(nb_rxq, ACTION_RSS_QUEUE_NUM),
6917                         .key = NULL,
6918                         .queue = action_rss_data->queue,
6919                 },
6920                 .queue = { 0 },
6921         };
6922         for (i = 0; i < action_rss_data->conf.queue_num; ++i)
6923                 action_rss_data->queue[i] = i;
6924         action->conf = &action_rss_data->conf;
6925         return ret;
6926 }
6927
6928 /**
6929  * Parse func field for RSS action.
6930  *
6931  * The RTE_ETH_HASH_FUNCTION_* value to assign is derived from the
6932  * ACTION_RSS_FUNC_* index that called this function.
6933  */
6934 static int
6935 parse_vc_action_rss_func(struct context *ctx, const struct token *token,
6936                          const char *str, unsigned int len,
6937                          void *buf, unsigned int size)
6938 {
6939         struct action_rss_data *action_rss_data;
6940         enum rte_eth_hash_function func;
6941
6942         (void)buf;
6943         (void)size;
6944         /* Token name must match. */
6945         if (parse_default(ctx, token, str, len, NULL, 0) < 0)
6946                 return -1;
6947         switch (ctx->curr) {
6948         case ACTION_RSS_FUNC_DEFAULT:
6949                 func = RTE_ETH_HASH_FUNCTION_DEFAULT;
6950                 break;
6951         case ACTION_RSS_FUNC_TOEPLITZ:
6952                 func = RTE_ETH_HASH_FUNCTION_TOEPLITZ;
6953                 break;
6954         case ACTION_RSS_FUNC_SIMPLE_XOR:
6955                 func = RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
6956                 break;
6957         case ACTION_RSS_FUNC_SYMMETRIC_TOEPLITZ:
6958                 func = RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ;
6959                 break;
6960         default:
6961                 return -1;
6962         }
6963         if (!ctx->object)
6964                 return len;
6965         action_rss_data = ctx->object;
6966         action_rss_data->conf.func = func;
6967         return len;
6968 }
6969
6970 /**
6971  * Parse type field for RSS action.
6972  *
6973  * Valid tokens are type field names and the "end" token.
6974  */
6975 static int
6976 parse_vc_action_rss_type(struct context *ctx, const struct token *token,
6977                           const char *str, unsigned int len,
6978                           void *buf, unsigned int size)
6979 {
6980         static const enum index next[] = NEXT_ENTRY(ACTION_RSS_TYPE);
6981         struct action_rss_data *action_rss_data;
6982         unsigned int i;
6983
6984         (void)token;
6985         (void)buf;
6986         (void)size;
6987         if (ctx->curr != ACTION_RSS_TYPE)
6988                 return -1;
6989         if (!(ctx->objdata >> 16) && ctx->object) {
6990                 action_rss_data = ctx->object;
6991                 action_rss_data->conf.types = 0;
6992         }
6993         if (!strcmp_partial("end", str, len)) {
6994                 ctx->objdata &= 0xffff;
6995                 return len;
6996         }
6997         for (i = 0; rss_type_table[i].str; ++i)
6998                 if (!strcmp_partial(rss_type_table[i].str, str, len))
6999                         break;
7000         if (!rss_type_table[i].str)
7001                 return -1;
7002         ctx->objdata = 1 << 16 | (ctx->objdata & 0xffff);
7003         /* Repeat token. */
7004         if (ctx->next_num == RTE_DIM(ctx->next))
7005                 return -1;
7006         ctx->next[ctx->next_num++] = next;
7007         if (!ctx->object)
7008                 return len;
7009         action_rss_data = ctx->object;
7010         action_rss_data->conf.types |= rss_type_table[i].rss_type;
7011         return len;
7012 }
7013
7014 /**
7015  * Parse queue field for RSS action.
7016  *
7017  * Valid tokens are queue indices and the "end" token.
7018  */
7019 static int
7020 parse_vc_action_rss_queue(struct context *ctx, const struct token *token,
7021                           const char *str, unsigned int len,
7022                           void *buf, unsigned int size)
7023 {
7024         static const enum index next[] = NEXT_ENTRY(ACTION_RSS_QUEUE);
7025         struct action_rss_data *action_rss_data;
7026         const struct arg *arg;
7027         int ret;
7028         int i;
7029
7030         (void)token;
7031         (void)buf;
7032         (void)size;
7033         if (ctx->curr != ACTION_RSS_QUEUE)
7034                 return -1;
7035         i = ctx->objdata >> 16;
7036         if (!strcmp_partial("end", str, len)) {
7037                 ctx->objdata &= 0xffff;
7038                 goto end;
7039         }
7040         if (i >= ACTION_RSS_QUEUE_NUM)
7041                 return -1;
7042         arg = ARGS_ENTRY_ARB(offsetof(struct action_rss_data, queue) +
7043                              i * sizeof(action_rss_data->queue[i]),
7044                              sizeof(action_rss_data->queue[i]));
7045         if (push_args(ctx, arg))
7046                 return -1;
7047         ret = parse_int(ctx, token, str, len, NULL, 0);
7048         if (ret < 0) {
7049                 pop_args(ctx);
7050                 return -1;
7051         }
7052         ++i;
7053         ctx->objdata = i << 16 | (ctx->objdata & 0xffff);
7054         /* Repeat token. */
7055         if (ctx->next_num == RTE_DIM(ctx->next))
7056                 return -1;
7057         ctx->next[ctx->next_num++] = next;
7058 end:
7059         if (!ctx->object)
7060                 return len;
7061         action_rss_data = ctx->object;
7062         action_rss_data->conf.queue_num = i;
7063         action_rss_data->conf.queue = i ? action_rss_data->queue : NULL;
7064         return len;
7065 }
7066
7067 /** Setup VXLAN encap configuration. */
7068 static int
7069 parse_setup_vxlan_encap_data(struct action_vxlan_encap_data *action_vxlan_encap_data)
7070 {
7071         /* Set up default configuration. */
7072         *action_vxlan_encap_data = (struct action_vxlan_encap_data){
7073                 .conf = (struct rte_flow_action_vxlan_encap){
7074                         .definition = action_vxlan_encap_data->items,
7075                 },
7076                 .items = {
7077                         {
7078                                 .type = RTE_FLOW_ITEM_TYPE_ETH,
7079                                 .spec = &action_vxlan_encap_data->item_eth,
7080                                 .mask = &rte_flow_item_eth_mask,
7081                         },
7082                         {
7083                                 .type = RTE_FLOW_ITEM_TYPE_VLAN,
7084                                 .spec = &action_vxlan_encap_data->item_vlan,
7085                                 .mask = &rte_flow_item_vlan_mask,
7086                         },
7087                         {
7088                                 .type = RTE_FLOW_ITEM_TYPE_IPV4,
7089                                 .spec = &action_vxlan_encap_data->item_ipv4,
7090                                 .mask = &rte_flow_item_ipv4_mask,
7091                         },
7092                         {
7093                                 .type = RTE_FLOW_ITEM_TYPE_UDP,
7094                                 .spec = &action_vxlan_encap_data->item_udp,
7095                                 .mask = &rte_flow_item_udp_mask,
7096                         },
7097                         {
7098                                 .type = RTE_FLOW_ITEM_TYPE_VXLAN,
7099                                 .spec = &action_vxlan_encap_data->item_vxlan,
7100                                 .mask = &rte_flow_item_vxlan_mask,
7101                         },
7102                         {
7103                                 .type = RTE_FLOW_ITEM_TYPE_END,
7104                         },
7105                 },
7106                 .item_eth.type = 0,
7107                 .item_vlan = {
7108                         .tci = vxlan_encap_conf.vlan_tci,
7109                         .inner_type = 0,
7110                 },
7111                 .item_ipv4.hdr = {
7112                         .src_addr = vxlan_encap_conf.ipv4_src,
7113                         .dst_addr = vxlan_encap_conf.ipv4_dst,
7114                 },
7115                 .item_udp.hdr = {
7116                         .src_port = vxlan_encap_conf.udp_src,
7117                         .dst_port = vxlan_encap_conf.udp_dst,
7118                 },
7119                 .item_vxlan.flags = 0,
7120         };
7121         memcpy(action_vxlan_encap_data->item_eth.dst.addr_bytes,
7122                vxlan_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
7123         memcpy(action_vxlan_encap_data->item_eth.src.addr_bytes,
7124                vxlan_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
7125         if (!vxlan_encap_conf.select_ipv4) {
7126                 memcpy(&action_vxlan_encap_data->item_ipv6.hdr.src_addr,
7127                        &vxlan_encap_conf.ipv6_src,
7128                        sizeof(vxlan_encap_conf.ipv6_src));
7129                 memcpy(&action_vxlan_encap_data->item_ipv6.hdr.dst_addr,
7130                        &vxlan_encap_conf.ipv6_dst,
7131                        sizeof(vxlan_encap_conf.ipv6_dst));
7132                 action_vxlan_encap_data->items[2] = (struct rte_flow_item){
7133                         .type = RTE_FLOW_ITEM_TYPE_IPV6,
7134                         .spec = &action_vxlan_encap_data->item_ipv6,
7135                         .mask = &rte_flow_item_ipv6_mask,
7136                 };
7137         }
7138         if (!vxlan_encap_conf.select_vlan)
7139                 action_vxlan_encap_data->items[1].type =
7140                         RTE_FLOW_ITEM_TYPE_VOID;
7141         if (vxlan_encap_conf.select_tos_ttl) {
7142                 if (vxlan_encap_conf.select_ipv4) {
7143                         static struct rte_flow_item_ipv4 ipv4_mask_tos;
7144
7145                         memcpy(&ipv4_mask_tos, &rte_flow_item_ipv4_mask,
7146                                sizeof(ipv4_mask_tos));
7147                         ipv4_mask_tos.hdr.type_of_service = 0xff;
7148                         ipv4_mask_tos.hdr.time_to_live = 0xff;
7149                         action_vxlan_encap_data->item_ipv4.hdr.type_of_service =
7150                                         vxlan_encap_conf.ip_tos;
7151                         action_vxlan_encap_data->item_ipv4.hdr.time_to_live =
7152                                         vxlan_encap_conf.ip_ttl;
7153                         action_vxlan_encap_data->items[2].mask =
7154                                                         &ipv4_mask_tos;
7155                 } else {
7156                         static struct rte_flow_item_ipv6 ipv6_mask_tos;
7157
7158                         memcpy(&ipv6_mask_tos, &rte_flow_item_ipv6_mask,
7159                                sizeof(ipv6_mask_tos));
7160                         ipv6_mask_tos.hdr.vtc_flow |=
7161                                 RTE_BE32(0xfful << RTE_IPV6_HDR_TC_SHIFT);
7162                         ipv6_mask_tos.hdr.hop_limits = 0xff;
7163                         action_vxlan_encap_data->item_ipv6.hdr.vtc_flow |=
7164                                 rte_cpu_to_be_32
7165                                         ((uint32_t)vxlan_encap_conf.ip_tos <<
7166                                          RTE_IPV6_HDR_TC_SHIFT);
7167                         action_vxlan_encap_data->item_ipv6.hdr.hop_limits =
7168                                         vxlan_encap_conf.ip_ttl;
7169                         action_vxlan_encap_data->items[2].mask =
7170                                                         &ipv6_mask_tos;
7171                 }
7172         }
7173         memcpy(action_vxlan_encap_data->item_vxlan.vni, vxlan_encap_conf.vni,
7174                RTE_DIM(vxlan_encap_conf.vni));
7175         return 0;
7176 }
7177
7178 /** Parse VXLAN encap action. */
7179 static int
7180 parse_vc_action_vxlan_encap(struct context *ctx, const struct token *token,
7181                             const char *str, unsigned int len,
7182                             void *buf, unsigned int size)
7183 {
7184         struct buffer *out = buf;
7185         struct rte_flow_action *action;
7186         struct action_vxlan_encap_data *action_vxlan_encap_data;
7187         int ret;
7188
7189         ret = parse_vc(ctx, token, str, len, buf, size);
7190         if (ret < 0)
7191                 return ret;
7192         /* Nothing else to do if there is no buffer. */
7193         if (!out)
7194                 return ret;
7195         if (!out->args.vc.actions_n)
7196                 return -1;
7197         action = &out->args.vc.actions[out->args.vc.actions_n - 1];
7198         /* Point to selected object. */
7199         ctx->object = out->args.vc.data;
7200         ctx->objmask = NULL;
7201         action_vxlan_encap_data = ctx->object;
7202         parse_setup_vxlan_encap_data(action_vxlan_encap_data);
7203         action->conf = &action_vxlan_encap_data->conf;
7204         return ret;
7205 }
7206
7207 /** Setup NVGRE encap configuration. */
7208 static int
7209 parse_setup_nvgre_encap_data(struct action_nvgre_encap_data *action_nvgre_encap_data)
7210 {
7211         /* Set up default configuration. */
7212         *action_nvgre_encap_data = (struct action_nvgre_encap_data){
7213                 .conf = (struct rte_flow_action_nvgre_encap){
7214                         .definition = action_nvgre_encap_data->items,
7215                 },
7216                 .items = {
7217                         {
7218                                 .type = RTE_FLOW_ITEM_TYPE_ETH,
7219                                 .spec = &action_nvgre_encap_data->item_eth,
7220                                 .mask = &rte_flow_item_eth_mask,
7221                         },
7222                         {
7223                                 .type = RTE_FLOW_ITEM_TYPE_VLAN,
7224                                 .spec = &action_nvgre_encap_data->item_vlan,
7225                                 .mask = &rte_flow_item_vlan_mask,
7226                         },
7227                         {
7228                                 .type = RTE_FLOW_ITEM_TYPE_IPV4,
7229                                 .spec = &action_nvgre_encap_data->item_ipv4,
7230                                 .mask = &rte_flow_item_ipv4_mask,
7231                         },
7232                         {
7233                                 .type = RTE_FLOW_ITEM_TYPE_NVGRE,
7234                                 .spec = &action_nvgre_encap_data->item_nvgre,
7235                                 .mask = &rte_flow_item_nvgre_mask,
7236                         },
7237                         {
7238                                 .type = RTE_FLOW_ITEM_TYPE_END,
7239                         },
7240                 },
7241                 .item_eth.type = 0,
7242                 .item_vlan = {
7243                         .tci = nvgre_encap_conf.vlan_tci,
7244                         .inner_type = 0,
7245                 },
7246                 .item_ipv4.hdr = {
7247                        .src_addr = nvgre_encap_conf.ipv4_src,
7248                        .dst_addr = nvgre_encap_conf.ipv4_dst,
7249                 },
7250                 .item_nvgre.c_k_s_rsvd0_ver = RTE_BE16(0x2000),
7251                 .item_nvgre.protocol = RTE_BE16(RTE_ETHER_TYPE_TEB),
7252                 .item_nvgre.flow_id = 0,
7253         };
7254         memcpy(action_nvgre_encap_data->item_eth.dst.addr_bytes,
7255                nvgre_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
7256         memcpy(action_nvgre_encap_data->item_eth.src.addr_bytes,
7257                nvgre_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
7258         if (!nvgre_encap_conf.select_ipv4) {
7259                 memcpy(&action_nvgre_encap_data->item_ipv6.hdr.src_addr,
7260                        &nvgre_encap_conf.ipv6_src,
7261                        sizeof(nvgre_encap_conf.ipv6_src));
7262                 memcpy(&action_nvgre_encap_data->item_ipv6.hdr.dst_addr,
7263                        &nvgre_encap_conf.ipv6_dst,
7264                        sizeof(nvgre_encap_conf.ipv6_dst));
7265                 action_nvgre_encap_data->items[2] = (struct rte_flow_item){
7266                         .type = RTE_FLOW_ITEM_TYPE_IPV6,
7267                         .spec = &action_nvgre_encap_data->item_ipv6,
7268                         .mask = &rte_flow_item_ipv6_mask,
7269                 };
7270         }
7271         if (!nvgre_encap_conf.select_vlan)
7272                 action_nvgre_encap_data->items[1].type =
7273                         RTE_FLOW_ITEM_TYPE_VOID;
7274         memcpy(action_nvgre_encap_data->item_nvgre.tni, nvgre_encap_conf.tni,
7275                RTE_DIM(nvgre_encap_conf.tni));
7276         return 0;
7277 }
7278
7279 /** Parse NVGRE encap action. */
7280 static int
7281 parse_vc_action_nvgre_encap(struct context *ctx, const struct token *token,
7282                             const char *str, unsigned int len,
7283                             void *buf, unsigned int size)
7284 {
7285         struct buffer *out = buf;
7286         struct rte_flow_action *action;
7287         struct action_nvgre_encap_data *action_nvgre_encap_data;
7288         int ret;
7289
7290         ret = parse_vc(ctx, token, str, len, buf, size);
7291         if (ret < 0)
7292                 return ret;
7293         /* Nothing else to do if there is no buffer. */
7294         if (!out)
7295                 return ret;
7296         if (!out->args.vc.actions_n)
7297                 return -1;
7298         action = &out->args.vc.actions[out->args.vc.actions_n - 1];
7299         /* Point to selected object. */
7300         ctx->object = out->args.vc.data;
7301         ctx->objmask = NULL;
7302         action_nvgre_encap_data = ctx->object;
7303         parse_setup_nvgre_encap_data(action_nvgre_encap_data);
7304         action->conf = &action_nvgre_encap_data->conf;
7305         return ret;
7306 }
7307
7308 /** Parse l2 encap action. */
7309 static int
7310 parse_vc_action_l2_encap(struct context *ctx, const struct token *token,
7311                          const char *str, unsigned int len,
7312                          void *buf, unsigned int size)
7313 {
7314         struct buffer *out = buf;
7315         struct rte_flow_action *action;
7316         struct action_raw_encap_data *action_encap_data;
7317         struct rte_flow_item_eth eth = { .type = 0, };
7318         struct rte_flow_item_vlan vlan = {
7319                 .tci = mplsoudp_encap_conf.vlan_tci,
7320                 .inner_type = 0,
7321         };
7322         uint8_t *header;
7323         int ret;
7324
7325         ret = parse_vc(ctx, token, str, len, buf, size);
7326         if (ret < 0)
7327                 return ret;
7328         /* Nothing else to do if there is no buffer. */
7329         if (!out)
7330                 return ret;
7331         if (!out->args.vc.actions_n)
7332                 return -1;
7333         action = &out->args.vc.actions[out->args.vc.actions_n - 1];
7334         /* Point to selected object. */
7335         ctx->object = out->args.vc.data;
7336         ctx->objmask = NULL;
7337         /* Copy the headers to the buffer. */
7338         action_encap_data = ctx->object;
7339         *action_encap_data = (struct action_raw_encap_data) {
7340                 .conf = (struct rte_flow_action_raw_encap){
7341                         .data = action_encap_data->data,
7342                 },
7343                 .data = {},
7344         };
7345         header = action_encap_data->data;
7346         if (l2_encap_conf.select_vlan)
7347                 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
7348         else if (l2_encap_conf.select_ipv4)
7349                 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
7350         else
7351                 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
7352         memcpy(eth.dst.addr_bytes,
7353                l2_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
7354         memcpy(eth.src.addr_bytes,
7355                l2_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
7356         memcpy(header, &eth, sizeof(eth));
7357         header += sizeof(eth);
7358         if (l2_encap_conf.select_vlan) {
7359                 if (l2_encap_conf.select_ipv4)
7360                         vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
7361                 else
7362                         vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
7363                 memcpy(header, &vlan, sizeof(vlan));
7364                 header += sizeof(vlan);
7365         }
7366         action_encap_data->conf.size = header -
7367                 action_encap_data->data;
7368         action->conf = &action_encap_data->conf;
7369         return ret;
7370 }
7371
7372 /** Parse l2 decap action. */
7373 static int
7374 parse_vc_action_l2_decap(struct context *ctx, const struct token *token,
7375                          const char *str, unsigned int len,
7376                          void *buf, unsigned int size)
7377 {
7378         struct buffer *out = buf;
7379         struct rte_flow_action *action;
7380         struct action_raw_decap_data *action_decap_data;
7381         struct rte_flow_item_eth eth = { .type = 0, };
7382         struct rte_flow_item_vlan vlan = {
7383                 .tci = mplsoudp_encap_conf.vlan_tci,
7384                 .inner_type = 0,
7385         };
7386         uint8_t *header;
7387         int ret;
7388
7389         ret = parse_vc(ctx, token, str, len, buf, size);
7390         if (ret < 0)
7391                 return ret;
7392         /* Nothing else to do if there is no buffer. */
7393         if (!out)
7394                 return ret;
7395         if (!out->args.vc.actions_n)
7396                 return -1;
7397         action = &out->args.vc.actions[out->args.vc.actions_n - 1];
7398         /* Point to selected object. */
7399         ctx->object = out->args.vc.data;
7400         ctx->objmask = NULL;
7401         /* Copy the headers to the buffer. */
7402         action_decap_data = ctx->object;
7403         *action_decap_data = (struct action_raw_decap_data) {
7404                 .conf = (struct rte_flow_action_raw_decap){
7405                         .data = action_decap_data->data,
7406                 },
7407                 .data = {},
7408         };
7409         header = action_decap_data->data;
7410         if (l2_decap_conf.select_vlan)
7411                 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
7412         memcpy(header, &eth, sizeof(eth));
7413         header += sizeof(eth);
7414         if (l2_decap_conf.select_vlan) {
7415                 memcpy(header, &vlan, sizeof(vlan));
7416                 header += sizeof(vlan);
7417         }
7418         action_decap_data->conf.size = header -
7419                 action_decap_data->data;
7420         action->conf = &action_decap_data->conf;
7421         return ret;
7422 }
7423
7424 #define ETHER_TYPE_MPLS_UNICAST 0x8847
7425
7426 /** Parse MPLSOGRE encap action. */
7427 static int
7428 parse_vc_action_mplsogre_encap(struct context *ctx, const struct token *token,
7429                                const char *str, unsigned int len,
7430                                void *buf, unsigned int size)
7431 {
7432         struct buffer *out = buf;
7433         struct rte_flow_action *action;
7434         struct action_raw_encap_data *action_encap_data;
7435         struct rte_flow_item_eth eth = { .type = 0, };
7436         struct rte_flow_item_vlan vlan = {
7437                 .tci = mplsogre_encap_conf.vlan_tci,
7438                 .inner_type = 0,
7439         };
7440         struct rte_flow_item_ipv4 ipv4 = {
7441                 .hdr =  {
7442                         .src_addr = mplsogre_encap_conf.ipv4_src,
7443                         .dst_addr = mplsogre_encap_conf.ipv4_dst,
7444                         .next_proto_id = IPPROTO_GRE,
7445                         .version_ihl = RTE_IPV4_VHL_DEF,
7446                         .time_to_live = IPDEFTTL,
7447                 },
7448         };
7449         struct rte_flow_item_ipv6 ipv6 = {
7450                 .hdr =  {
7451                         .proto = IPPROTO_GRE,
7452                         .hop_limits = IPDEFTTL,
7453                 },
7454         };
7455         struct rte_flow_item_gre gre = {
7456                 .protocol = rte_cpu_to_be_16(ETHER_TYPE_MPLS_UNICAST),
7457         };
7458         struct rte_flow_item_mpls mpls = {
7459                 .ttl = 0,
7460         };
7461         uint8_t *header;
7462         int ret;
7463
7464         ret = parse_vc(ctx, token, str, len, buf, size);
7465         if (ret < 0)
7466                 return ret;
7467         /* Nothing else to do if there is no buffer. */
7468         if (!out)
7469                 return ret;
7470         if (!out->args.vc.actions_n)
7471                 return -1;
7472         action = &out->args.vc.actions[out->args.vc.actions_n - 1];
7473         /* Point to selected object. */
7474         ctx->object = out->args.vc.data;
7475         ctx->objmask = NULL;
7476         /* Copy the headers to the buffer. */
7477         action_encap_data = ctx->object;
7478         *action_encap_data = (struct action_raw_encap_data) {
7479                 .conf = (struct rte_flow_action_raw_encap){
7480                         .data = action_encap_data->data,
7481                 },
7482                 .data = {},
7483                 .preserve = {},
7484         };
7485         header = action_encap_data->data;
7486         if (mplsogre_encap_conf.select_vlan)
7487                 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
7488         else if (mplsogre_encap_conf.select_ipv4)
7489                 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
7490         else
7491                 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
7492         memcpy(eth.dst.addr_bytes,
7493                mplsogre_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
7494         memcpy(eth.src.addr_bytes,
7495                mplsogre_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
7496         memcpy(header, &eth, sizeof(eth));
7497         header += sizeof(eth);
7498         if (mplsogre_encap_conf.select_vlan) {
7499                 if (mplsogre_encap_conf.select_ipv4)
7500                         vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
7501                 else
7502                         vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
7503                 memcpy(header, &vlan, sizeof(vlan));
7504                 header += sizeof(vlan);
7505         }
7506         if (mplsogre_encap_conf.select_ipv4) {
7507                 memcpy(header, &ipv4, sizeof(ipv4));
7508                 header += sizeof(ipv4);
7509         } else {
7510                 memcpy(&ipv6.hdr.src_addr,
7511                        &mplsogre_encap_conf.ipv6_src,
7512                        sizeof(mplsogre_encap_conf.ipv6_src));
7513                 memcpy(&ipv6.hdr.dst_addr,
7514                        &mplsogre_encap_conf.ipv6_dst,
7515                        sizeof(mplsogre_encap_conf.ipv6_dst));
7516                 memcpy(header, &ipv6, sizeof(ipv6));
7517                 header += sizeof(ipv6);
7518         }
7519         memcpy(header, &gre, sizeof(gre));
7520         header += sizeof(gre);
7521         memcpy(mpls.label_tc_s, mplsogre_encap_conf.label,
7522                RTE_DIM(mplsogre_encap_conf.label));
7523         mpls.label_tc_s[2] |= 0x1;
7524         memcpy(header, &mpls, sizeof(mpls));
7525         header += sizeof(mpls);
7526         action_encap_data->conf.size = header -
7527                 action_encap_data->data;
7528         action->conf = &action_encap_data->conf;
7529         return ret;
7530 }
7531
7532 /** Parse MPLSOGRE decap action. */
7533 static int
7534 parse_vc_action_mplsogre_decap(struct context *ctx, const struct token *token,
7535                                const char *str, unsigned int len,
7536                                void *buf, unsigned int size)
7537 {
7538         struct buffer *out = buf;
7539         struct rte_flow_action *action;
7540         struct action_raw_decap_data *action_decap_data;
7541         struct rte_flow_item_eth eth = { .type = 0, };
7542         struct rte_flow_item_vlan vlan = {.tci = 0};
7543         struct rte_flow_item_ipv4 ipv4 = {
7544                 .hdr =  {
7545                         .next_proto_id = IPPROTO_GRE,
7546                 },
7547         };
7548         struct rte_flow_item_ipv6 ipv6 = {
7549                 .hdr =  {
7550                         .proto = IPPROTO_GRE,
7551                 },
7552         };
7553         struct rte_flow_item_gre gre = {
7554                 .protocol = rte_cpu_to_be_16(ETHER_TYPE_MPLS_UNICAST),
7555         };
7556         struct rte_flow_item_mpls mpls;
7557         uint8_t *header;
7558         int ret;
7559
7560         ret = parse_vc(ctx, token, str, len, buf, size);
7561         if (ret < 0)
7562                 return ret;
7563         /* Nothing else to do if there is no buffer. */
7564         if (!out)
7565                 return ret;
7566         if (!out->args.vc.actions_n)
7567                 return -1;
7568         action = &out->args.vc.actions[out->args.vc.actions_n - 1];
7569         /* Point to selected object. */
7570         ctx->object = out->args.vc.data;
7571         ctx->objmask = NULL;
7572         /* Copy the headers to the buffer. */
7573         action_decap_data = ctx->object;
7574         *action_decap_data = (struct action_raw_decap_data) {
7575                 .conf = (struct rte_flow_action_raw_decap){
7576                         .data = action_decap_data->data,
7577                 },
7578                 .data = {},
7579         };
7580         header = action_decap_data->data;
7581         if (mplsogre_decap_conf.select_vlan)
7582                 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
7583         else if (mplsogre_encap_conf.select_ipv4)
7584                 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
7585         else
7586                 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
7587         memcpy(eth.dst.addr_bytes,
7588                mplsogre_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
7589         memcpy(eth.src.addr_bytes,
7590                mplsogre_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
7591         memcpy(header, &eth, sizeof(eth));
7592         header += sizeof(eth);
7593         if (mplsogre_encap_conf.select_vlan) {
7594                 if (mplsogre_encap_conf.select_ipv4)
7595                         vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
7596                 else
7597                         vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
7598                 memcpy(header, &vlan, sizeof(vlan));
7599                 header += sizeof(vlan);
7600         }
7601         if (mplsogre_encap_conf.select_ipv4) {
7602                 memcpy(header, &ipv4, sizeof(ipv4));
7603                 header += sizeof(ipv4);
7604         } else {
7605                 memcpy(header, &ipv6, sizeof(ipv6));
7606                 header += sizeof(ipv6);
7607         }
7608         memcpy(header, &gre, sizeof(gre));
7609         header += sizeof(gre);
7610         memset(&mpls, 0, sizeof(mpls));
7611         memcpy(header, &mpls, sizeof(mpls));
7612         header += sizeof(mpls);
7613         action_decap_data->conf.size = header -
7614                 action_decap_data->data;
7615         action->conf = &action_decap_data->conf;
7616         return ret;
7617 }
7618
7619 /** Parse MPLSOUDP encap action. */
7620 static int
7621 parse_vc_action_mplsoudp_encap(struct context *ctx, const struct token *token,
7622                                const char *str, unsigned int len,
7623                                void *buf, unsigned int size)
7624 {
7625         struct buffer *out = buf;
7626         struct rte_flow_action *action;
7627         struct action_raw_encap_data *action_encap_data;
7628         struct rte_flow_item_eth eth = { .type = 0, };
7629         struct rte_flow_item_vlan vlan = {
7630                 .tci = mplsoudp_encap_conf.vlan_tci,
7631                 .inner_type = 0,
7632         };
7633         struct rte_flow_item_ipv4 ipv4 = {
7634                 .hdr =  {
7635                         .src_addr = mplsoudp_encap_conf.ipv4_src,
7636                         .dst_addr = mplsoudp_encap_conf.ipv4_dst,
7637                         .next_proto_id = IPPROTO_UDP,
7638                         .version_ihl = RTE_IPV4_VHL_DEF,
7639                         .time_to_live = IPDEFTTL,
7640                 },
7641         };
7642         struct rte_flow_item_ipv6 ipv6 = {
7643                 .hdr =  {
7644                         .proto = IPPROTO_UDP,
7645                         .hop_limits = IPDEFTTL,
7646                 },
7647         };
7648         struct rte_flow_item_udp udp = {
7649                 .hdr = {
7650                         .src_port = mplsoudp_encap_conf.udp_src,
7651                         .dst_port = mplsoudp_encap_conf.udp_dst,
7652                 },
7653         };
7654         struct rte_flow_item_mpls mpls;
7655         uint8_t *header;
7656         int ret;
7657
7658         ret = parse_vc(ctx, token, str, len, buf, size);
7659         if (ret < 0)
7660                 return ret;
7661         /* Nothing else to do if there is no buffer. */
7662         if (!out)
7663                 return ret;
7664         if (!out->args.vc.actions_n)
7665                 return -1;
7666         action = &out->args.vc.actions[out->args.vc.actions_n - 1];
7667         /* Point to selected object. */
7668         ctx->object = out->args.vc.data;
7669         ctx->objmask = NULL;
7670         /* Copy the headers to the buffer. */
7671         action_encap_data = ctx->object;
7672         *action_encap_data = (struct action_raw_encap_data) {
7673                 .conf = (struct rte_flow_action_raw_encap){
7674                         .data = action_encap_data->data,
7675                 },
7676                 .data = {},
7677                 .preserve = {},
7678         };
7679         header = action_encap_data->data;
7680         if (mplsoudp_encap_conf.select_vlan)
7681                 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
7682         else if (mplsoudp_encap_conf.select_ipv4)
7683                 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
7684         else
7685                 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
7686         memcpy(eth.dst.addr_bytes,
7687                mplsoudp_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
7688         memcpy(eth.src.addr_bytes,
7689                mplsoudp_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
7690         memcpy(header, &eth, sizeof(eth));
7691         header += sizeof(eth);
7692         if (mplsoudp_encap_conf.select_vlan) {
7693                 if (mplsoudp_encap_conf.select_ipv4)
7694                         vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
7695                 else
7696                         vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
7697                 memcpy(header, &vlan, sizeof(vlan));
7698                 header += sizeof(vlan);
7699         }
7700         if (mplsoudp_encap_conf.select_ipv4) {
7701                 memcpy(header, &ipv4, sizeof(ipv4));
7702                 header += sizeof(ipv4);
7703         } else {
7704                 memcpy(&ipv6.hdr.src_addr,
7705                        &mplsoudp_encap_conf.ipv6_src,
7706                        sizeof(mplsoudp_encap_conf.ipv6_src));
7707                 memcpy(&ipv6.hdr.dst_addr,
7708                        &mplsoudp_encap_conf.ipv6_dst,
7709                        sizeof(mplsoudp_encap_conf.ipv6_dst));
7710                 memcpy(header, &ipv6, sizeof(ipv6));
7711                 header += sizeof(ipv6);
7712         }
7713         memcpy(header, &udp, sizeof(udp));
7714         header += sizeof(udp);
7715         memcpy(mpls.label_tc_s, mplsoudp_encap_conf.label,
7716                RTE_DIM(mplsoudp_encap_conf.label));
7717         mpls.label_tc_s[2] |= 0x1;
7718         memcpy(header, &mpls, sizeof(mpls));
7719         header += sizeof(mpls);
7720         action_encap_data->conf.size = header -
7721                 action_encap_data->data;
7722         action->conf = &action_encap_data->conf;
7723         return ret;
7724 }
7725
7726 /** Parse MPLSOUDP decap action. */
7727 static int
7728 parse_vc_action_mplsoudp_decap(struct context *ctx, const struct token *token,
7729                                const char *str, unsigned int len,
7730                                void *buf, unsigned int size)
7731 {
7732         struct buffer *out = buf;
7733         struct rte_flow_action *action;
7734         struct action_raw_decap_data *action_decap_data;
7735         struct rte_flow_item_eth eth = { .type = 0, };
7736         struct rte_flow_item_vlan vlan = {.tci = 0};
7737         struct rte_flow_item_ipv4 ipv4 = {
7738                 .hdr =  {
7739                         .next_proto_id = IPPROTO_UDP,
7740                 },
7741         };
7742         struct rte_flow_item_ipv6 ipv6 = {
7743                 .hdr =  {
7744                         .proto = IPPROTO_UDP,
7745                 },
7746         };
7747         struct rte_flow_item_udp udp = {
7748                 .hdr = {
7749                         .dst_port = rte_cpu_to_be_16(6635),
7750                 },
7751         };
7752         struct rte_flow_item_mpls mpls;
7753         uint8_t *header;
7754         int ret;
7755
7756         ret = parse_vc(ctx, token, str, len, buf, size);
7757         if (ret < 0)
7758                 return ret;
7759         /* Nothing else to do if there is no buffer. */
7760         if (!out)
7761                 return ret;
7762         if (!out->args.vc.actions_n)
7763                 return -1;
7764         action = &out->args.vc.actions[out->args.vc.actions_n - 1];
7765         /* Point to selected object. */
7766         ctx->object = out->args.vc.data;
7767         ctx->objmask = NULL;
7768         /* Copy the headers to the buffer. */
7769         action_decap_data = ctx->object;
7770         *action_decap_data = (struct action_raw_decap_data) {
7771                 .conf = (struct rte_flow_action_raw_decap){
7772                         .data = action_decap_data->data,
7773                 },
7774                 .data = {},
7775         };
7776         header = action_decap_data->data;
7777         if (mplsoudp_decap_conf.select_vlan)
7778                 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
7779         else if (mplsoudp_encap_conf.select_ipv4)
7780                 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
7781         else
7782                 eth.type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
7783         memcpy(eth.dst.addr_bytes,
7784                mplsoudp_encap_conf.eth_dst, RTE_ETHER_ADDR_LEN);
7785         memcpy(eth.src.addr_bytes,
7786                mplsoudp_encap_conf.eth_src, RTE_ETHER_ADDR_LEN);
7787         memcpy(header, &eth, sizeof(eth));
7788         header += sizeof(eth);
7789         if (mplsoudp_encap_conf.select_vlan) {
7790                 if (mplsoudp_encap_conf.select_ipv4)
7791                         vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
7792                 else
7793                         vlan.inner_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV6);
7794                 memcpy(header, &vlan, sizeof(vlan));
7795                 header += sizeof(vlan);
7796         }
7797         if (mplsoudp_encap_conf.select_ipv4) {
7798                 memcpy(header, &ipv4, sizeof(ipv4));
7799                 header += sizeof(ipv4);
7800         } else {
7801                 memcpy(header, &ipv6, sizeof(ipv6));
7802                 header += sizeof(ipv6);
7803         }
7804         memcpy(header, &udp, sizeof(udp));
7805         header += sizeof(udp);
7806         memset(&mpls, 0, sizeof(mpls));
7807         memcpy(header, &mpls, sizeof(mpls));
7808         header += sizeof(mpls);
7809         action_decap_data->conf.size = header -
7810                 action_decap_data->data;
7811         action->conf = &action_decap_data->conf;
7812         return ret;
7813 }
7814
7815 static int
7816 parse_vc_action_raw_decap_index(struct context *ctx, const struct token *token,
7817                                 const char *str, unsigned int len, void *buf,
7818                                 unsigned int size)
7819 {
7820         struct action_raw_decap_data *action_raw_decap_data;
7821         struct rte_flow_action *action;
7822         const struct arg *arg;
7823         struct buffer *out = buf;
7824         int ret;
7825         uint16_t idx;
7826
7827         RTE_SET_USED(token);
7828         RTE_SET_USED(buf);
7829         RTE_SET_USED(size);
7830         arg = ARGS_ENTRY_ARB_BOUNDED
7831                 (offsetof(struct action_raw_decap_data, idx),
7832                  sizeof(((struct action_raw_decap_data *)0)->idx),
7833                  0, RAW_ENCAP_CONFS_MAX_NUM - 1);
7834         if (push_args(ctx, arg))
7835                 return -1;
7836         ret = parse_int(ctx, token, str, len, NULL, 0);
7837         if (ret < 0) {
7838                 pop_args(ctx);
7839                 return -1;
7840         }
7841         if (!ctx->object)
7842                 return len;
7843         action = &out->args.vc.actions[out->args.vc.actions_n - 1];
7844         action_raw_decap_data = ctx->object;
7845         idx = action_raw_decap_data->idx;
7846         action_raw_decap_data->conf.data = raw_decap_confs[idx].data;
7847         action_raw_decap_data->conf.size = raw_decap_confs[idx].size;
7848         action->conf = &action_raw_decap_data->conf;
7849         return len;
7850 }
7851
7852
7853 static int
7854 parse_vc_action_raw_encap_index(struct context *ctx, const struct token *token,
7855                                 const char *str, unsigned int len, void *buf,
7856                                 unsigned int size)
7857 {
7858         struct action_raw_encap_data *action_raw_encap_data;
7859         struct rte_flow_action *action;
7860         const struct arg *arg;
7861         struct buffer *out = buf;
7862         int ret;
7863         uint16_t idx;
7864
7865         RTE_SET_USED(token);
7866         RTE_SET_USED(buf);
7867         RTE_SET_USED(size);
7868         if (ctx->curr != ACTION_RAW_ENCAP_INDEX_VALUE)
7869                 return -1;
7870         arg = ARGS_ENTRY_ARB_BOUNDED
7871                 (offsetof(struct action_raw_encap_data, idx),
7872                  sizeof(((struct action_raw_encap_data *)0)->idx),
7873                  0, RAW_ENCAP_CONFS_MAX_NUM - 1);
7874         if (push_args(ctx, arg))
7875                 return -1;
7876         ret = parse_int(ctx, token, str, len, NULL, 0);
7877         if (ret < 0) {
7878                 pop_args(ctx);
7879                 return -1;
7880         }
7881         if (!ctx->object)
7882                 return len;
7883         action = &out->args.vc.actions[out->args.vc.actions_n - 1];
7884         action_raw_encap_data = ctx->object;
7885         idx = action_raw_encap_data->idx;
7886         action_raw_encap_data->conf.data = raw_encap_confs[idx].data;
7887         action_raw_encap_data->conf.size = raw_encap_confs[idx].size;
7888         action_raw_encap_data->conf.preserve = NULL;
7889         action->conf = &action_raw_encap_data->conf;
7890         return len;
7891 }
7892
7893 static int
7894 parse_vc_action_raw_encap(struct context *ctx, const struct token *token,
7895                           const char *str, unsigned int len, void *buf,
7896                           unsigned int size)
7897 {
7898         struct buffer *out = buf;
7899         struct rte_flow_action *action;
7900         struct action_raw_encap_data *action_raw_encap_data = NULL;
7901         int ret;
7902
7903         ret = parse_vc(ctx, token, str, len, buf, size);
7904         if (ret < 0)
7905                 return ret;
7906         /* Nothing else to do if there is no buffer. */
7907         if (!out)
7908                 return ret;
7909         if (!out->args.vc.actions_n)
7910                 return -1;
7911         action = &out->args.vc.actions[out->args.vc.actions_n - 1];
7912         /* Point to selected object. */
7913         ctx->object = out->args.vc.data;
7914         ctx->objmask = NULL;
7915         /* Copy the headers to the buffer. */
7916         action_raw_encap_data = ctx->object;
7917         action_raw_encap_data->conf.data = raw_encap_confs[0].data;
7918         action_raw_encap_data->conf.preserve = NULL;
7919         action_raw_encap_data->conf.size = raw_encap_confs[0].size;
7920         action->conf = &action_raw_encap_data->conf;
7921         return ret;
7922 }
7923
7924 static int
7925 parse_vc_action_raw_decap(struct context *ctx, const struct token *token,
7926                           const char *str, unsigned int len, void *buf,
7927                           unsigned int size)
7928 {
7929         struct buffer *out = buf;
7930         struct rte_flow_action *action;
7931         struct action_raw_decap_data *action_raw_decap_data = NULL;
7932         int ret;
7933
7934         ret = parse_vc(ctx, token, str, len, buf, size);
7935         if (ret < 0)
7936                 return ret;
7937         /* Nothing else to do if there is no buffer. */
7938         if (!out)
7939                 return ret;
7940         if (!out->args.vc.actions_n)
7941                 return -1;
7942         action = &out->args.vc.actions[out->args.vc.actions_n - 1];
7943         /* Point to selected object. */
7944         ctx->object = out->args.vc.data;
7945         ctx->objmask = NULL;
7946         /* Copy the headers to the buffer. */
7947         action_raw_decap_data = ctx->object;
7948         action_raw_decap_data->conf.data = raw_decap_confs[0].data;
7949         action_raw_decap_data->conf.size = raw_decap_confs[0].size;
7950         action->conf = &action_raw_decap_data->conf;
7951         return ret;
7952 }
7953
7954 static int
7955 parse_vc_action_set_meta(struct context *ctx, const struct token *token,
7956                          const char *str, unsigned int len, void *buf,
7957                          unsigned int size)
7958 {
7959         int ret;
7960
7961         ret = parse_vc(ctx, token, str, len, buf, size);
7962         if (ret < 0)
7963                 return ret;
7964         ret = rte_flow_dynf_metadata_register();
7965         if (ret < 0)
7966                 return -1;
7967         return len;
7968 }
7969
7970 static int
7971 parse_vc_action_sample(struct context *ctx, const struct token *token,
7972                          const char *str, unsigned int len, void *buf,
7973                          unsigned int size)
7974 {
7975         struct buffer *out = buf;
7976         struct rte_flow_action *action;
7977         struct action_sample_data *action_sample_data = NULL;
7978         static struct rte_flow_action end_action = {
7979                 RTE_FLOW_ACTION_TYPE_END, 0
7980         };
7981         int ret;
7982
7983         ret = parse_vc(ctx, token, str, len, buf, size);
7984         if (ret < 0)
7985                 return ret;
7986         /* Nothing else to do if there is no buffer. */
7987         if (!out)
7988                 return ret;
7989         if (!out->args.vc.actions_n)
7990                 return -1;
7991         action = &out->args.vc.actions[out->args.vc.actions_n - 1];
7992         /* Point to selected object. */
7993         ctx->object = out->args.vc.data;
7994         ctx->objmask = NULL;
7995         /* Copy the headers to the buffer. */
7996         action_sample_data = ctx->object;
7997         action_sample_data->conf.actions = &end_action;
7998         action->conf = &action_sample_data->conf;
7999         return ret;
8000 }
8001
8002 static int
8003 parse_vc_action_sample_index(struct context *ctx, const struct token *token,
8004                                 const char *str, unsigned int len, void *buf,
8005                                 unsigned int size)
8006 {
8007         struct action_sample_data *action_sample_data;
8008         struct rte_flow_action *action;
8009         const struct arg *arg;
8010         struct buffer *out = buf;
8011         int ret;
8012         uint16_t idx;
8013
8014         RTE_SET_USED(token);
8015         RTE_SET_USED(buf);
8016         RTE_SET_USED(size);
8017         if (ctx->curr != ACTION_SAMPLE_INDEX_VALUE)
8018                 return -1;
8019         arg = ARGS_ENTRY_ARB_BOUNDED
8020                 (offsetof(struct action_sample_data, idx),
8021                  sizeof(((struct action_sample_data *)0)->idx),
8022                  0, RAW_SAMPLE_CONFS_MAX_NUM - 1);
8023         if (push_args(ctx, arg))
8024                 return -1;
8025         ret = parse_int(ctx, token, str, len, NULL, 0);
8026         if (ret < 0) {
8027                 pop_args(ctx);
8028                 return -1;
8029         }
8030         if (!ctx->object)
8031                 return len;
8032         action = &out->args.vc.actions[out->args.vc.actions_n - 1];
8033         action_sample_data = ctx->object;
8034         idx = action_sample_data->idx;
8035         action_sample_data->conf.actions = raw_sample_confs[idx].data;
8036         action->conf = &action_sample_data->conf;
8037         return len;
8038 }
8039
8040 /** Parse operation for modify_field command. */
8041 static int
8042 parse_vc_modify_field_op(struct context *ctx, const struct token *token,
8043                          const char *str, unsigned int len, void *buf,
8044                          unsigned int size)
8045 {
8046         struct rte_flow_action_modify_field *action_modify_field;
8047         unsigned int i;
8048
8049         (void)token;
8050         (void)buf;
8051         (void)size;
8052         if (ctx->curr != ACTION_MODIFY_FIELD_OP_VALUE)
8053                 return -1;
8054         for (i = 0; modify_field_ops[i]; ++i)
8055                 if (!strcmp_partial(modify_field_ops[i], str, len))
8056                         break;
8057         if (!modify_field_ops[i])
8058                 return -1;
8059         if (!ctx->object)
8060                 return len;
8061         action_modify_field = ctx->object;
8062         action_modify_field->operation = (enum rte_flow_modify_op)i;
8063         return len;
8064 }
8065
8066 /** Parse id for modify_field command. */
8067 static int
8068 parse_vc_modify_field_id(struct context *ctx, const struct token *token,
8069                          const char *str, unsigned int len, void *buf,
8070                          unsigned int size)
8071 {
8072         struct rte_flow_action_modify_field *action_modify_field;
8073         unsigned int i;
8074
8075         (void)token;
8076         (void)buf;
8077         (void)size;
8078         if (ctx->curr != ACTION_MODIFY_FIELD_DST_TYPE_VALUE &&
8079                 ctx->curr != ACTION_MODIFY_FIELD_SRC_TYPE_VALUE)
8080                 return -1;
8081         for (i = 0; modify_field_ids[i]; ++i)
8082                 if (!strcmp_partial(modify_field_ids[i], str, len))
8083                         break;
8084         if (!modify_field_ids[i])
8085                 return -1;
8086         if (!ctx->object)
8087                 return len;
8088         action_modify_field = ctx->object;
8089         if (ctx->curr == ACTION_MODIFY_FIELD_DST_TYPE_VALUE)
8090                 action_modify_field->dst.field = (enum rte_flow_field_id)i;
8091         else
8092                 action_modify_field->src.field = (enum rte_flow_field_id)i;
8093         return len;
8094 }
8095
8096 /** Parse the conntrack update, not a rte_flow_action. */
8097 static int
8098 parse_vc_action_conntrack_update(struct context *ctx, const struct token *token,
8099                          const char *str, unsigned int len, void *buf,
8100                          unsigned int size)
8101 {
8102         struct buffer *out = buf;
8103         struct rte_flow_modify_conntrack *ct_modify = NULL;
8104
8105         (void)size;
8106         if (ctx->curr != ACTION_CONNTRACK_UPDATE_CTX &&
8107             ctx->curr != ACTION_CONNTRACK_UPDATE_DIR)
8108                 return -1;
8109         /* Token name must match. */
8110         if (parse_default(ctx, token, str, len, NULL, 0) < 0)
8111                 return -1;
8112         /* Nothing else to do if there is no buffer. */
8113         if (!out)
8114                 return len;
8115         ct_modify = (struct rte_flow_modify_conntrack *)out->args.vc.data;
8116         if (ctx->curr == ACTION_CONNTRACK_UPDATE_DIR) {
8117                 ct_modify->new_ct.is_original_dir =
8118                                 conntrack_context.is_original_dir;
8119                 ct_modify->direction = 1;
8120         } else {
8121                 uint32_t old_dir;
8122
8123                 old_dir = ct_modify->new_ct.is_original_dir;
8124                 memcpy(&ct_modify->new_ct, &conntrack_context,
8125                        sizeof(conntrack_context));
8126                 ct_modify->new_ct.is_original_dir = old_dir;
8127                 ct_modify->state = 1;
8128         }
8129         return len;
8130 }
8131
8132 /** Parse tokens for destroy command. */
8133 static int
8134 parse_destroy(struct context *ctx, const struct token *token,
8135               const char *str, unsigned int len,
8136               void *buf, unsigned int size)
8137 {
8138         struct buffer *out = buf;
8139
8140         /* Token name must match. */
8141         if (parse_default(ctx, token, str, len, NULL, 0) < 0)
8142                 return -1;
8143         /* Nothing else to do if there is no buffer. */
8144         if (!out)
8145                 return len;
8146         if (!out->command) {
8147                 if (ctx->curr != DESTROY)
8148                         return -1;
8149                 if (sizeof(*out) > size)
8150                         return -1;
8151                 out->command = ctx->curr;
8152                 ctx->objdata = 0;
8153                 ctx->object = out;
8154                 ctx->objmask = NULL;
8155                 out->args.destroy.rule =
8156                         (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
8157                                                sizeof(double));
8158                 return len;
8159         }
8160         if (((uint8_t *)(out->args.destroy.rule + out->args.destroy.rule_n) +
8161              sizeof(*out->args.destroy.rule)) > (uint8_t *)out + size)
8162                 return -1;
8163         ctx->objdata = 0;
8164         ctx->object = out->args.destroy.rule + out->args.destroy.rule_n++;
8165         ctx->objmask = NULL;
8166         return len;
8167 }
8168
8169 /** Parse tokens for flush command. */
8170 static int
8171 parse_flush(struct context *ctx, const struct token *token,
8172             const char *str, unsigned int len,
8173             void *buf, unsigned int size)
8174 {
8175         struct buffer *out = buf;
8176
8177         /* Token name must match. */
8178         if (parse_default(ctx, token, str, len, NULL, 0) < 0)
8179                 return -1;
8180         /* Nothing else to do if there is no buffer. */
8181         if (!out)
8182                 return len;
8183         if (!out->command) {
8184                 if (ctx->curr != FLUSH)
8185                         return -1;
8186                 if (sizeof(*out) > size)
8187                         return -1;
8188                 out->command = ctx->curr;
8189                 ctx->objdata = 0;
8190                 ctx->object = out;
8191                 ctx->objmask = NULL;
8192         }
8193         return len;
8194 }
8195
8196 /** Parse tokens for dump command. */
8197 static int
8198 parse_dump(struct context *ctx, const struct token *token,
8199             const char *str, unsigned int len,
8200             void *buf, unsigned int size)
8201 {
8202         struct buffer *out = buf;
8203
8204         /* Token name must match. */
8205         if (parse_default(ctx, token, str, len, NULL, 0) < 0)
8206                 return -1;
8207         /* Nothing else to do if there is no buffer. */
8208         if (!out)
8209                 return len;
8210         if (!out->command) {
8211                 if (ctx->curr != DUMP)
8212                         return -1;
8213                 if (sizeof(*out) > size)
8214                         return -1;
8215                 out->command = ctx->curr;
8216                 ctx->objdata = 0;
8217                 ctx->object = out;
8218                 ctx->objmask = NULL;
8219                 return len;
8220         }
8221         switch (ctx->curr) {
8222         case DUMP_ALL:
8223         case DUMP_ONE:
8224                 out->args.dump.mode = (ctx->curr == DUMP_ALL) ? true : false;
8225                 out->command = ctx->curr;
8226                 ctx->objdata = 0;
8227                 ctx->object = out;
8228                 ctx->objmask = NULL;
8229                 return len;
8230         default:
8231                 return -1;
8232         }
8233 }
8234
8235 /** Parse tokens for query command. */
8236 static int
8237 parse_query(struct context *ctx, const struct token *token,
8238             const char *str, unsigned int len,
8239             void *buf, unsigned int size)
8240 {
8241         struct buffer *out = buf;
8242
8243         /* Token name must match. */
8244         if (parse_default(ctx, token, str, len, NULL, 0) < 0)
8245                 return -1;
8246         /* Nothing else to do if there is no buffer. */
8247         if (!out)
8248                 return len;
8249         if (!out->command) {
8250                 if (ctx->curr != QUERY)
8251                         return -1;
8252                 if (sizeof(*out) > size)
8253                         return -1;
8254                 out->command = ctx->curr;
8255                 ctx->objdata = 0;
8256                 ctx->object = out;
8257                 ctx->objmask = NULL;
8258         }
8259         return len;
8260 }
8261
8262 /** Parse action names. */
8263 static int
8264 parse_action(struct context *ctx, const struct token *token,
8265              const char *str, unsigned int len,
8266              void *buf, unsigned int size)
8267 {
8268         struct buffer *out = buf;
8269         const struct arg *arg = pop_args(ctx);
8270         unsigned int i;
8271
8272         (void)size;
8273         /* Argument is expected. */
8274         if (!arg)
8275                 return -1;
8276         /* Parse action name. */
8277         for (i = 0; next_action[i]; ++i) {
8278                 const struct parse_action_priv *priv;
8279
8280                 token = &token_list[next_action[i]];
8281                 if (strcmp_partial(token->name, str, len))
8282                         continue;
8283                 priv = token->priv;
8284                 if (!priv)
8285                         goto error;
8286                 if (out)
8287                         memcpy((uint8_t *)ctx->object + arg->offset,
8288                                &priv->type,
8289                                arg->size);
8290                 return len;
8291         }
8292 error:
8293         push_args(ctx, arg);
8294         return -1;
8295 }
8296
8297 /** Parse tokens for list command. */
8298 static int
8299 parse_list(struct context *ctx, const struct token *token,
8300            const char *str, unsigned int len,
8301            void *buf, unsigned int size)
8302 {
8303         struct buffer *out = buf;
8304
8305         /* Token name must match. */
8306         if (parse_default(ctx, token, str, len, NULL, 0) < 0)
8307                 return -1;
8308         /* Nothing else to do if there is no buffer. */
8309         if (!out)
8310                 return len;
8311         if (!out->command) {
8312                 if (ctx->curr != LIST)
8313                         return -1;
8314                 if (sizeof(*out) > size)
8315                         return -1;
8316                 out->command = ctx->curr;
8317                 ctx->objdata = 0;
8318                 ctx->object = out;
8319                 ctx->objmask = NULL;
8320                 out->args.list.group =
8321                         (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
8322                                                sizeof(double));
8323                 return len;
8324         }
8325         if (((uint8_t *)(out->args.list.group + out->args.list.group_n) +
8326              sizeof(*out->args.list.group)) > (uint8_t *)out + size)
8327                 return -1;
8328         ctx->objdata = 0;
8329         ctx->object = out->args.list.group + out->args.list.group_n++;
8330         ctx->objmask = NULL;
8331         return len;
8332 }
8333
8334 /** Parse tokens for list all aged flows command. */
8335 static int
8336 parse_aged(struct context *ctx, const struct token *token,
8337            const char *str, unsigned int len,
8338            void *buf, unsigned int size)
8339 {
8340         struct buffer *out = buf;
8341
8342         /* Token name must match. */
8343         if (parse_default(ctx, token, str, len, NULL, 0) < 0)
8344                 return -1;
8345         /* Nothing else to do if there is no buffer. */
8346         if (!out)
8347                 return len;
8348         if (!out->command) {
8349                 if (ctx->curr != AGED)
8350                         return -1;
8351                 if (sizeof(*out) > size)
8352                         return -1;
8353                 out->command = ctx->curr;
8354                 ctx->objdata = 0;
8355                 ctx->object = out;
8356                 ctx->objmask = NULL;
8357         }
8358         if (ctx->curr == AGED_DESTROY)
8359                 out->args.aged.destroy = 1;
8360         return len;
8361 }
8362
8363 /** Parse tokens for isolate command. */
8364 static int
8365 parse_isolate(struct context *ctx, const struct token *token,
8366               const char *str, unsigned int len,
8367               void *buf, unsigned int size)
8368 {
8369         struct buffer *out = buf;
8370
8371         /* Token name must match. */
8372         if (parse_default(ctx, token, str, len, NULL, 0) < 0)
8373                 return -1;
8374         /* Nothing else to do if there is no buffer. */
8375         if (!out)
8376                 return len;
8377         if (!out->command) {
8378                 if (ctx->curr != ISOLATE)
8379                         return -1;
8380                 if (sizeof(*out) > size)
8381                         return -1;
8382                 out->command = ctx->curr;
8383                 ctx->objdata = 0;
8384                 ctx->object = out;
8385                 ctx->objmask = NULL;
8386         }
8387         return len;
8388 }
8389
8390 /** Parse tokens for info/configure command. */
8391 static int
8392 parse_configure(struct context *ctx, const struct token *token,
8393                 const char *str, unsigned int len,
8394                 void *buf, unsigned int size)
8395 {
8396         struct buffer *out = buf;
8397
8398         /* Token name must match. */
8399         if (parse_default(ctx, token, str, len, NULL, 0) < 0)
8400                 return -1;
8401         /* Nothing else to do if there is no buffer. */
8402         if (!out)
8403                 return len;
8404         if (!out->command) {
8405                 if (ctx->curr != INFO && ctx->curr != CONFIGURE)
8406                         return -1;
8407                 if (sizeof(*out) > size)
8408                         return -1;
8409                 out->command = ctx->curr;
8410                 ctx->objdata = 0;
8411                 ctx->object = out;
8412                 ctx->objmask = NULL;
8413         }
8414         return len;
8415 }
8416
8417 /** Parse tokens for template create command. */
8418 static int
8419 parse_template(struct context *ctx, const struct token *token,
8420                const char *str, unsigned int len,
8421                void *buf, unsigned int size)
8422 {
8423         struct buffer *out = buf;
8424
8425         /* Token name must match. */
8426         if (parse_default(ctx, token, str, len, NULL, 0) < 0)
8427                 return -1;
8428         /* Nothing else to do if there is no buffer. */
8429         if (!out)
8430                 return len;
8431         if (!out->command) {
8432                 if (ctx->curr != PATTERN_TEMPLATE &&
8433                     ctx->curr != ACTIONS_TEMPLATE)
8434                         return -1;
8435                 if (sizeof(*out) > size)
8436                         return -1;
8437                 out->command = ctx->curr;
8438                 ctx->objdata = 0;
8439                 ctx->object = out;
8440                 ctx->objmask = NULL;
8441                 out->args.vc.data = (uint8_t *)out + size;
8442                 return len;
8443         }
8444         switch (ctx->curr) {
8445         case PATTERN_TEMPLATE_CREATE:
8446                 out->args.vc.pattern =
8447                         (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
8448                                                sizeof(double));
8449                 out->args.vc.pat_templ_id = UINT32_MAX;
8450                 out->command = ctx->curr;
8451                 ctx->objdata = 0;
8452                 ctx->object = out;
8453                 ctx->objmask = NULL;
8454                 return len;
8455         case PATTERN_TEMPLATE_EGRESS:
8456                 out->args.vc.attr.egress = 1;
8457                 return len;
8458         case PATTERN_TEMPLATE_INGRESS:
8459                 out->args.vc.attr.ingress = 1;
8460                 return len;
8461         case PATTERN_TEMPLATE_TRANSFER:
8462                 out->args.vc.attr.transfer = 1;
8463                 return len;
8464         case ACTIONS_TEMPLATE_CREATE:
8465                 out->args.vc.act_templ_id = UINT32_MAX;
8466                 out->command = ctx->curr;
8467                 ctx->objdata = 0;
8468                 ctx->object = out;
8469                 ctx->objmask = NULL;
8470                 return len;
8471         case ACTIONS_TEMPLATE_SPEC:
8472                 out->args.vc.actions =
8473                         (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
8474                                                sizeof(double));
8475                 ctx->object = out->args.vc.actions;
8476                 ctx->objmask = NULL;
8477                 return len;
8478         case ACTIONS_TEMPLATE_MASK:
8479                 out->args.vc.masks =
8480                         (void *)RTE_ALIGN_CEIL((uintptr_t)
8481                                                (out->args.vc.actions +
8482                                                 out->args.vc.actions_n),
8483                                                sizeof(double));
8484                 ctx->object = out->args.vc.masks;
8485                 ctx->objmask = NULL;
8486                 return len;
8487         case ACTIONS_TEMPLATE_EGRESS:
8488                 out->args.vc.attr.egress = 1;
8489                 return len;
8490         case ACTIONS_TEMPLATE_INGRESS:
8491                 out->args.vc.attr.ingress = 1;
8492                 return len;
8493         case ACTIONS_TEMPLATE_TRANSFER:
8494                 out->args.vc.attr.transfer = 1;
8495                 return len;
8496         default:
8497                 return -1;
8498         }
8499 }
8500
8501 /** Parse tokens for template destroy command. */
8502 static int
8503 parse_template_destroy(struct context *ctx, const struct token *token,
8504                        const char *str, unsigned int len,
8505                        void *buf, unsigned int size)
8506 {
8507         struct buffer *out = buf;
8508         uint32_t *template_id;
8509
8510         /* Token name must match. */
8511         if (parse_default(ctx, token, str, len, NULL, 0) < 0)
8512                 return -1;
8513         /* Nothing else to do if there is no buffer. */
8514         if (!out)
8515                 return len;
8516         if (!out->command ||
8517                 out->command == PATTERN_TEMPLATE ||
8518                 out->command == ACTIONS_TEMPLATE) {
8519                 if (ctx->curr != PATTERN_TEMPLATE_DESTROY &&
8520                         ctx->curr != ACTIONS_TEMPLATE_DESTROY)
8521                         return -1;
8522                 if (sizeof(*out) > size)
8523                         return -1;
8524                 out->command = ctx->curr;
8525                 ctx->objdata = 0;
8526                 ctx->object = out;
8527                 ctx->objmask = NULL;
8528                 out->args.templ_destroy.template_id =
8529                         (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
8530                                                sizeof(double));
8531                 return len;
8532         }
8533         template_id = out->args.templ_destroy.template_id
8534                     + out->args.templ_destroy.template_id_n++;
8535         if ((uint8_t *)template_id > (uint8_t *)out + size)
8536                 return -1;
8537         ctx->objdata = 0;
8538         ctx->object = template_id;
8539         ctx->objmask = NULL;
8540         return len;
8541 }
8542
8543 /** Parse tokens for table create command. */
8544 static int
8545 parse_table(struct context *ctx, const struct token *token,
8546             const char *str, unsigned int len,
8547             void *buf, unsigned int size)
8548 {
8549         struct buffer *out = buf;
8550         uint32_t *template_id;
8551
8552         /* Token name must match. */
8553         if (parse_default(ctx, token, str, len, NULL, 0) < 0)
8554                 return -1;
8555         /* Nothing else to do if there is no buffer. */
8556         if (!out)
8557                 return len;
8558         if (!out->command) {
8559                 if (ctx->curr != TABLE)
8560                         return -1;
8561                 if (sizeof(*out) > size)
8562                         return -1;
8563                 out->command = ctx->curr;
8564                 ctx->objdata = 0;
8565                 ctx->object = out;
8566                 ctx->objmask = NULL;
8567                 return len;
8568         }
8569         switch (ctx->curr) {
8570         case TABLE_CREATE:
8571                 out->command = ctx->curr;
8572                 ctx->objdata = 0;
8573                 ctx->object = out;
8574                 ctx->objmask = NULL;
8575                 out->args.table.id = UINT32_MAX;
8576                 return len;
8577         case TABLE_PATTERN_TEMPLATE:
8578                 out->args.table.pat_templ_id =
8579                         (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
8580                                                sizeof(double));
8581                 template_id = out->args.table.pat_templ_id
8582                                 + out->args.table.pat_templ_id_n++;
8583                 if ((uint8_t *)template_id > (uint8_t *)out + size)
8584                         return -1;
8585                 ctx->objdata = 0;
8586                 ctx->object = template_id;
8587                 ctx->objmask = NULL;
8588                 return len;
8589         case TABLE_ACTIONS_TEMPLATE:
8590                 out->args.table.act_templ_id =
8591                         (void *)RTE_ALIGN_CEIL((uintptr_t)
8592                                                (out->args.table.pat_templ_id +
8593                                                 out->args.table.pat_templ_id_n),
8594                                                sizeof(double));
8595                 template_id = out->args.table.act_templ_id
8596                                 + out->args.table.act_templ_id_n++;
8597                 if ((uint8_t *)template_id > (uint8_t *)out + size)
8598                         return -1;
8599                 ctx->objdata = 0;
8600                 ctx->object = template_id;
8601                 ctx->objmask = NULL;
8602                 return len;
8603         case TABLE_INGRESS:
8604                 out->args.table.attr.flow_attr.ingress = 1;
8605                 return len;
8606         case TABLE_EGRESS:
8607                 out->args.table.attr.flow_attr.egress = 1;
8608                 return len;
8609         case TABLE_TRANSFER:
8610                 out->args.table.attr.flow_attr.transfer = 1;
8611                 return len;
8612         default:
8613                 return -1;
8614         }
8615 }
8616
8617 /** Parse tokens for table destroy command. */
8618 static int
8619 parse_table_destroy(struct context *ctx, const struct token *token,
8620                     const char *str, unsigned int len,
8621                     void *buf, unsigned int size)
8622 {
8623         struct buffer *out = buf;
8624         uint32_t *table_id;
8625
8626         /* Token name must match. */
8627         if (parse_default(ctx, token, str, len, NULL, 0) < 0)
8628                 return -1;
8629         /* Nothing else to do if there is no buffer. */
8630         if (!out)
8631                 return len;
8632         if (!out->command || out->command == TABLE) {
8633                 if (ctx->curr != TABLE_DESTROY)
8634                         return -1;
8635                 if (sizeof(*out) > size)
8636                         return -1;
8637                 out->command = ctx->curr;
8638                 ctx->objdata = 0;
8639                 ctx->object = out;
8640                 ctx->objmask = NULL;
8641                 out->args.table_destroy.table_id =
8642                         (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
8643                                                sizeof(double));
8644                 return len;
8645         }
8646         table_id = out->args.table_destroy.table_id
8647                     + out->args.table_destroy.table_id_n++;
8648         if ((uint8_t *)table_id > (uint8_t *)out + size)
8649                 return -1;
8650         ctx->objdata = 0;
8651         ctx->object = table_id;
8652         ctx->objmask = NULL;
8653         return len;
8654 }
8655
8656 /** Parse tokens for queue create commands. */
8657 static int
8658 parse_qo(struct context *ctx, const struct token *token,
8659          const char *str, unsigned int len,
8660          void *buf, unsigned int size)
8661 {
8662         struct buffer *out = buf;
8663
8664         /* Token name must match. */
8665         if (parse_default(ctx, token, str, len, NULL, 0) < 0)
8666                 return -1;
8667         /* Nothing else to do if there is no buffer. */
8668         if (!out)
8669                 return len;
8670         if (!out->command) {
8671                 if (ctx->curr != QUEUE)
8672                         return -1;
8673                 if (sizeof(*out) > size)
8674                         return -1;
8675                 out->command = ctx->curr;
8676                 ctx->objdata = 0;
8677                 ctx->object = out;
8678                 ctx->objmask = NULL;
8679                 out->args.vc.data = (uint8_t *)out + size;
8680                 return len;
8681         }
8682         switch (ctx->curr) {
8683         case QUEUE_CREATE:
8684                 out->command = ctx->curr;
8685                 ctx->objdata = 0;
8686                 ctx->object = out;
8687                 ctx->objmask = NULL;
8688                 return len;
8689         case QUEUE_TEMPLATE_TABLE:
8690         case QUEUE_PATTERN_TEMPLATE:
8691         case QUEUE_ACTIONS_TEMPLATE:
8692         case QUEUE_CREATE_POSTPONE:
8693                 return len;
8694         case ITEM_PATTERN:
8695                 out->args.vc.pattern =
8696                         (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
8697                                                sizeof(double));
8698                 ctx->object = out->args.vc.pattern;
8699                 ctx->objmask = NULL;
8700                 return len;
8701         case ACTIONS:
8702                 out->args.vc.actions =
8703                         (void *)RTE_ALIGN_CEIL((uintptr_t)
8704                                                (out->args.vc.pattern +
8705                                                 out->args.vc.pattern_n),
8706                                                sizeof(double));
8707                 ctx->object = out->args.vc.actions;
8708                 ctx->objmask = NULL;
8709                 return len;
8710         default:
8711                 return -1;
8712         }
8713 }
8714
8715 /** Parse tokens for queue destroy command. */
8716 static int
8717 parse_qo_destroy(struct context *ctx, const struct token *token,
8718                  const char *str, unsigned int len,
8719                  void *buf, unsigned int size)
8720 {
8721         struct buffer *out = buf;
8722         uint32_t *flow_id;
8723
8724         /* Token name must match. */
8725         if (parse_default(ctx, token, str, len, NULL, 0) < 0)
8726                 return -1;
8727         /* Nothing else to do if there is no buffer. */
8728         if (!out)
8729                 return len;
8730         if (!out->command || out->command == QUEUE) {
8731                 if (ctx->curr != QUEUE_DESTROY)
8732                         return -1;
8733                 if (sizeof(*out) > size)
8734                         return -1;
8735                 out->command = ctx->curr;
8736                 ctx->objdata = 0;
8737                 ctx->object = out;
8738                 ctx->objmask = NULL;
8739                 out->args.destroy.rule =
8740                         (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
8741                                                sizeof(double));
8742                 return len;
8743         }
8744         switch (ctx->curr) {
8745         case QUEUE_DESTROY_ID:
8746                 flow_id = out->args.destroy.rule
8747                                 + out->args.destroy.rule_n++;
8748                 if ((uint8_t *)flow_id > (uint8_t *)out + size)
8749                         return -1;
8750                 ctx->objdata = 0;
8751                 ctx->object = flow_id;
8752                 ctx->objmask = NULL;
8753                 return len;
8754         case QUEUE_DESTROY_POSTPONE:
8755                 return len;
8756         default:
8757                 return -1;
8758         }
8759 }
8760
8761 /** Parse tokens for push queue command. */
8762 static int
8763 parse_push(struct context *ctx, const struct token *token,
8764            const char *str, unsigned int len,
8765            void *buf, unsigned int size)
8766 {
8767         struct buffer *out = buf;
8768
8769         /* Token name must match. */
8770         if (parse_default(ctx, token, str, len, NULL, 0) < 0)
8771                 return -1;
8772         /* Nothing else to do if there is no buffer. */
8773         if (!out)
8774                 return len;
8775         if (!out->command) {
8776                 if (ctx->curr != PUSH)
8777                         return -1;
8778                 if (sizeof(*out) > size)
8779                         return -1;
8780                 out->command = ctx->curr;
8781                 ctx->objdata = 0;
8782                 ctx->object = out;
8783                 ctx->objmask = NULL;
8784                 out->args.vc.data = (uint8_t *)out + size;
8785         }
8786         return len;
8787 }
8788
8789 static int
8790 parse_flex(struct context *ctx, const struct token *token,
8791              const char *str, unsigned int len,
8792              void *buf, unsigned int size)
8793 {
8794         struct buffer *out = buf;
8795
8796         /* Token name must match. */
8797         if (parse_default(ctx, token, str, len, NULL, 0) < 0)
8798                 return -1;
8799         /* Nothing else to do if there is no buffer. */
8800         if (!out)
8801                 return len;
8802         if (out->command == ZERO) {
8803                 if (ctx->curr != FLEX)
8804                         return -1;
8805                 if (sizeof(*out) > size)
8806                         return -1;
8807                 out->command = ctx->curr;
8808                 ctx->objdata = 0;
8809                 ctx->object = out;
8810                 ctx->objmask = NULL;
8811         } else {
8812                 switch (ctx->curr) {
8813                 default:
8814                         break;
8815                 case FLEX_ITEM_INIT:
8816                 case FLEX_ITEM_CREATE:
8817                 case FLEX_ITEM_DESTROY:
8818                         out->command = ctx->curr;
8819                         break;
8820                 }
8821         }
8822
8823         return len;
8824 }
8825
8826 static int
8827 parse_tunnel(struct context *ctx, const struct token *token,
8828              const char *str, unsigned int len,
8829              void *buf, unsigned int size)
8830 {
8831         struct buffer *out = buf;
8832
8833         /* Token name must match. */
8834         if (parse_default(ctx, token, str, len, NULL, 0) < 0)
8835                 return -1;
8836         /* Nothing else to do if there is no buffer. */
8837         if (!out)
8838                 return len;
8839         if (!out->command) {
8840                 if (ctx->curr != TUNNEL)
8841                         return -1;
8842                 if (sizeof(*out) > size)
8843                         return -1;
8844                 out->command = ctx->curr;
8845                 ctx->objdata = 0;
8846                 ctx->object = out;
8847                 ctx->objmask = NULL;
8848         } else {
8849                 switch (ctx->curr) {
8850                 default:
8851                         break;
8852                 case TUNNEL_CREATE:
8853                 case TUNNEL_DESTROY:
8854                 case TUNNEL_LIST:
8855                         out->command = ctx->curr;
8856                         break;
8857                 case TUNNEL_CREATE_TYPE:
8858                 case TUNNEL_DESTROY_ID:
8859                         ctx->object = &out->args.vc.tunnel_ops;
8860                         break;
8861                 }
8862         }
8863
8864         return len;
8865 }
8866
8867 /**
8868  * Parse signed/unsigned integers 8 to 64-bit long.
8869  *
8870  * Last argument (ctx->args) is retrieved to determine integer type and
8871  * storage location.
8872  */
8873 static int
8874 parse_int(struct context *ctx, const struct token *token,
8875           const char *str, unsigned int len,
8876           void *buf, unsigned int size)
8877 {
8878         const struct arg *arg = pop_args(ctx);
8879         uintmax_t u;
8880         char *end;
8881
8882         (void)token;
8883         /* Argument is expected. */
8884         if (!arg)
8885                 return -1;
8886         errno = 0;
8887         u = arg->sign ?
8888                 (uintmax_t)strtoimax(str, &end, 0) :
8889                 strtoumax(str, &end, 0);
8890         if (errno || (size_t)(end - str) != len)
8891                 goto error;
8892         if (arg->bounded &&
8893             ((arg->sign && ((intmax_t)u < (intmax_t)arg->min ||
8894                             (intmax_t)u > (intmax_t)arg->max)) ||
8895              (!arg->sign && (u < arg->min || u > arg->max))))
8896                 goto error;
8897         if (!ctx->object)
8898                 return len;
8899         if (arg->mask) {
8900                 if (!arg_entry_bf_fill(ctx->object, u, arg) ||
8901                     !arg_entry_bf_fill(ctx->objmask, -1, arg))
8902                         goto error;
8903                 return len;
8904         }
8905         buf = (uint8_t *)ctx->object + arg->offset;
8906         size = arg->size;
8907         if (u > RTE_LEN2MASK(size * CHAR_BIT, uint64_t))
8908                 return -1;
8909 objmask:
8910         switch (size) {
8911         case sizeof(uint8_t):
8912                 *(uint8_t *)buf = u;
8913                 break;
8914         case sizeof(uint16_t):
8915                 *(uint16_t *)buf = arg->hton ? rte_cpu_to_be_16(u) : u;
8916                 break;
8917         case sizeof(uint8_t [3]):
8918 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
8919                 if (!arg->hton) {
8920                         ((uint8_t *)buf)[0] = u;
8921                         ((uint8_t *)buf)[1] = u >> 8;
8922                         ((uint8_t *)buf)[2] = u >> 16;
8923                         break;
8924                 }
8925 #endif
8926                 ((uint8_t *)buf)[0] = u >> 16;
8927                 ((uint8_t *)buf)[1] = u >> 8;
8928                 ((uint8_t *)buf)[2] = u;
8929                 break;
8930         case sizeof(uint32_t):
8931                 *(uint32_t *)buf = arg->hton ? rte_cpu_to_be_32(u) : u;
8932                 break;
8933         case sizeof(uint64_t):
8934                 *(uint64_t *)buf = arg->hton ? rte_cpu_to_be_64(u) : u;
8935                 break;
8936         default:
8937                 goto error;
8938         }
8939         if (ctx->objmask && buf != (uint8_t *)ctx->objmask + arg->offset) {
8940                 u = -1;
8941                 buf = (uint8_t *)ctx->objmask + arg->offset;
8942                 goto objmask;
8943         }
8944         return len;
8945 error:
8946         push_args(ctx, arg);
8947         return -1;
8948 }
8949
8950 /**
8951  * Parse a string.
8952  *
8953  * Three arguments (ctx->args) are retrieved from the stack to store data,
8954  * its actual length and address (in that order).
8955  */
8956 static int
8957 parse_string(struct context *ctx, const struct token *token,
8958              const char *str, unsigned int len,
8959              void *buf, unsigned int size)
8960 {
8961         const struct arg *arg_data = pop_args(ctx);
8962         const struct arg *arg_len = pop_args(ctx);
8963         const struct arg *arg_addr = pop_args(ctx);
8964         char tmp[16]; /* Ought to be enough. */
8965         int ret;
8966
8967         /* Arguments are expected. */
8968         if (!arg_data)
8969                 return -1;
8970         if (!arg_len) {
8971                 push_args(ctx, arg_data);
8972                 return -1;
8973         }
8974         if (!arg_addr) {
8975                 push_args(ctx, arg_len);
8976                 push_args(ctx, arg_data);
8977                 return -1;
8978         }
8979         size = arg_data->size;
8980         /* Bit-mask fill is not supported. */
8981         if (arg_data->mask || size < len)
8982                 goto error;
8983         if (!ctx->object)
8984                 return len;
8985         /* Let parse_int() fill length information first. */
8986         ret = snprintf(tmp, sizeof(tmp), "%u", len);
8987         if (ret < 0)
8988                 goto error;
8989         push_args(ctx, arg_len);
8990         ret = parse_int(ctx, token, tmp, ret, NULL, 0);
8991         if (ret < 0) {
8992                 pop_args(ctx);
8993                 goto error;
8994         }
8995         buf = (uint8_t *)ctx->object + arg_data->offset;
8996         /* Output buffer is not necessarily NUL-terminated. */
8997         memcpy(buf, str, len);
8998         memset((uint8_t *)buf + len, 0x00, size - len);
8999         if (ctx->objmask)
9000                 memset((uint8_t *)ctx->objmask + arg_data->offset, 0xff, len);
9001         /* Save address if requested. */
9002         if (arg_addr->size) {
9003                 memcpy((uint8_t *)ctx->object + arg_addr->offset,
9004                        (void *[]){
9005                         (uint8_t *)ctx->object + arg_data->offset
9006                        },
9007                        arg_addr->size);
9008                 if (ctx->objmask)
9009                         memcpy((uint8_t *)ctx->objmask + arg_addr->offset,
9010                                (void *[]){
9011                                 (uint8_t *)ctx->objmask + arg_data->offset
9012                                },
9013                                arg_addr->size);
9014         }
9015         return len;
9016 error:
9017         push_args(ctx, arg_addr);
9018         push_args(ctx, arg_len);
9019         push_args(ctx, arg_data);
9020         return -1;
9021 }
9022
9023 static int
9024 parse_hex_string(const char *src, uint8_t *dst, uint32_t *size)
9025 {
9026         const uint8_t *head = dst;
9027         uint32_t left;
9028
9029         /* Check input parameters */
9030         if ((src == NULL) ||
9031                 (dst == NULL) ||
9032                 (size == NULL) ||
9033                 (*size == 0))
9034                 return -1;
9035
9036         left = *size;
9037
9038         /* Convert chars to bytes */
9039         while (left) {
9040                 char tmp[3], *end = tmp;
9041                 uint32_t read_lim = left & 1 ? 1 : 2;
9042
9043                 snprintf(tmp, read_lim + 1, "%s", src);
9044                 *dst = strtoul(tmp, &end, 16);
9045                 if (*end) {
9046                         *dst = 0;
9047                         *size = (uint32_t)(dst - head);
9048                         return -1;
9049                 }
9050                 left -= read_lim;
9051                 src += read_lim;
9052                 dst++;
9053         }
9054         *dst = 0;
9055         *size = (uint32_t)(dst - head);
9056         return 0;
9057 }
9058
9059 static int
9060 parse_hex(struct context *ctx, const struct token *token,
9061                 const char *str, unsigned int len,
9062                 void *buf, unsigned int size)
9063 {
9064         const struct arg *arg_data = pop_args(ctx);
9065         const struct arg *arg_len = pop_args(ctx);
9066         const struct arg *arg_addr = pop_args(ctx);
9067         char tmp[16]; /* Ought to be enough. */
9068         int ret;
9069         unsigned int hexlen = len;
9070         unsigned int length = 256;
9071         uint8_t hex_tmp[length];
9072
9073         /* Arguments are expected. */
9074         if (!arg_data)
9075                 return -1;
9076         if (!arg_len) {
9077                 push_args(ctx, arg_data);
9078                 return -1;
9079         }
9080         if (!arg_addr) {
9081                 push_args(ctx, arg_len);
9082                 push_args(ctx, arg_data);
9083                 return -1;
9084         }
9085         size = arg_data->size;
9086         /* Bit-mask fill is not supported. */
9087         if (arg_data->mask)
9088                 goto error;
9089         if (!ctx->object)
9090                 return len;
9091
9092         /* translate bytes string to array. */
9093         if (str[0] == '0' && ((str[1] == 'x') ||
9094                         (str[1] == 'X'))) {
9095                 str += 2;
9096                 hexlen -= 2;
9097         }
9098         if (hexlen > length)
9099                 goto error;
9100         ret = parse_hex_string(str, hex_tmp, &hexlen);
9101         if (ret < 0)
9102                 goto error;
9103         /* Check the converted binary fits into data buffer. */
9104         if (hexlen > size)
9105                 goto error;
9106         /* Let parse_int() fill length information first. */
9107         ret = snprintf(tmp, sizeof(tmp), "%u", hexlen);
9108         if (ret < 0)
9109                 goto error;
9110         /* Save length if requested. */
9111         if (arg_len->size) {
9112                 push_args(ctx, arg_len);
9113                 ret = parse_int(ctx, token, tmp, ret, NULL, 0);
9114                 if (ret < 0) {
9115                         pop_args(ctx);
9116                         goto error;
9117                 }
9118         }
9119         buf = (uint8_t *)ctx->object + arg_data->offset;
9120         /* Output buffer is not necessarily NUL-terminated. */
9121         memcpy(buf, hex_tmp, hexlen);
9122         memset((uint8_t *)buf + hexlen, 0x00, size - hexlen);
9123         if (ctx->objmask)
9124                 memset((uint8_t *)ctx->objmask + arg_data->offset,
9125                                         0xff, hexlen);
9126         /* Save address if requested. */
9127         if (arg_addr->size) {
9128                 memcpy((uint8_t *)ctx->object + arg_addr->offset,
9129                        (void *[]){
9130                         (uint8_t *)ctx->object + arg_data->offset
9131                        },
9132                        arg_addr->size);
9133                 if (ctx->objmask)
9134                         memcpy((uint8_t *)ctx->objmask + arg_addr->offset,
9135                                (void *[]){
9136                                 (uint8_t *)ctx->objmask + arg_data->offset
9137                                },
9138                                arg_addr->size);
9139         }
9140         return len;
9141 error:
9142         push_args(ctx, arg_addr);
9143         push_args(ctx, arg_len);
9144         push_args(ctx, arg_data);
9145         return -1;
9146
9147 }
9148
9149 /**
9150  * Parse a zero-ended string.
9151  */
9152 static int
9153 parse_string0(struct context *ctx, const struct token *token __rte_unused,
9154              const char *str, unsigned int len,
9155              void *buf, unsigned int size)
9156 {
9157         const struct arg *arg_data = pop_args(ctx);
9158
9159         /* Arguments are expected. */
9160         if (!arg_data)
9161                 return -1;
9162         size = arg_data->size;
9163         /* Bit-mask fill is not supported. */
9164         if (arg_data->mask || size < len + 1)
9165                 goto error;
9166         if (!ctx->object)
9167                 return len;
9168         buf = (uint8_t *)ctx->object + arg_data->offset;
9169         strncpy(buf, str, len);
9170         if (ctx->objmask)
9171                 memset((uint8_t *)ctx->objmask + arg_data->offset, 0xff, len);
9172         return len;
9173 error:
9174         push_args(ctx, arg_data);
9175         return -1;
9176 }
9177
9178 /**
9179  * Parse a MAC address.
9180  *
9181  * Last argument (ctx->args) is retrieved to determine storage size and
9182  * location.
9183  */
9184 static int
9185 parse_mac_addr(struct context *ctx, const struct token *token,
9186                const char *str, unsigned int len,
9187                void *buf, unsigned int size)
9188 {
9189         const struct arg *arg = pop_args(ctx);
9190         struct rte_ether_addr tmp;
9191         int ret;
9192
9193         (void)token;
9194         /* Argument is expected. */
9195         if (!arg)
9196                 return -1;
9197         size = arg->size;
9198         /* Bit-mask fill is not supported. */
9199         if (arg->mask || size != sizeof(tmp))
9200                 goto error;
9201         /* Only network endian is supported. */
9202         if (!arg->hton)
9203                 goto error;
9204         ret = cmdline_parse_etheraddr(NULL, str, &tmp, size);
9205         if (ret < 0 || (unsigned int)ret != len)
9206                 goto error;
9207         if (!ctx->object)
9208                 return len;
9209         buf = (uint8_t *)ctx->object + arg->offset;
9210         memcpy(buf, &tmp, size);
9211         if (ctx->objmask)
9212                 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
9213         return len;
9214 error:
9215         push_args(ctx, arg);
9216         return -1;
9217 }
9218
9219 /**
9220  * Parse an IPv4 address.
9221  *
9222  * Last argument (ctx->args) is retrieved to determine storage size and
9223  * location.
9224  */
9225 static int
9226 parse_ipv4_addr(struct context *ctx, const struct token *token,
9227                 const char *str, unsigned int len,
9228                 void *buf, unsigned int size)
9229 {
9230         const struct arg *arg = pop_args(ctx);
9231         char str2[len + 1];
9232         struct in_addr tmp;
9233         int ret;
9234
9235         /* Argument is expected. */
9236         if (!arg)
9237                 return -1;
9238         size = arg->size;
9239         /* Bit-mask fill is not supported. */
9240         if (arg->mask || size != sizeof(tmp))
9241                 goto error;
9242         /* Only network endian is supported. */
9243         if (!arg->hton)
9244                 goto error;
9245         memcpy(str2, str, len);
9246         str2[len] = '\0';
9247         ret = inet_pton(AF_INET, str2, &tmp);
9248         if (ret != 1) {
9249                 /* Attempt integer parsing. */
9250                 push_args(ctx, arg);
9251                 return parse_int(ctx, token, str, len, buf, size);
9252         }
9253         if (!ctx->object)
9254                 return len;
9255         buf = (uint8_t *)ctx->object + arg->offset;
9256         memcpy(buf, &tmp, size);
9257         if (ctx->objmask)
9258                 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
9259         return len;
9260 error:
9261         push_args(ctx, arg);
9262         return -1;
9263 }
9264
9265 /**
9266  * Parse an IPv6 address.
9267  *
9268  * Last argument (ctx->args) is retrieved to determine storage size and
9269  * location.
9270  */
9271 static int
9272 parse_ipv6_addr(struct context *ctx, const struct token *token,
9273                 const char *str, unsigned int len,
9274                 void *buf, unsigned int size)
9275 {
9276         const struct arg *arg = pop_args(ctx);
9277         char str2[len + 1];
9278         struct in6_addr tmp;
9279         int ret;
9280
9281         (void)token;
9282         /* Argument is expected. */
9283         if (!arg)
9284                 return -1;
9285         size = arg->size;
9286         /* Bit-mask fill is not supported. */
9287         if (arg->mask || size != sizeof(tmp))
9288                 goto error;
9289         /* Only network endian is supported. */
9290         if (!arg->hton)
9291                 goto error;
9292         memcpy(str2, str, len);
9293         str2[len] = '\0';
9294         ret = inet_pton(AF_INET6, str2, &tmp);
9295         if (ret != 1)
9296                 goto error;
9297         if (!ctx->object)
9298                 return len;
9299         buf = (uint8_t *)ctx->object + arg->offset;
9300         memcpy(buf, &tmp, size);
9301         if (ctx->objmask)
9302                 memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
9303         return len;
9304 error:
9305         push_args(ctx, arg);
9306         return -1;
9307 }
9308
9309 /** Boolean values (even indices stand for false). */
9310 static const char *const boolean_name[] = {
9311         "0", "1",
9312         "false", "true",
9313         "no", "yes",
9314         "N", "Y",
9315         "off", "on",
9316         NULL,
9317 };
9318
9319 /**
9320  * Parse a boolean value.
9321  *
9322  * Last argument (ctx->args) is retrieved to determine storage size and
9323  * location.
9324  */
9325 static int
9326 parse_boolean(struct context *ctx, const struct token *token,
9327               const char *str, unsigned int len,
9328               void *buf, unsigned int size)
9329 {
9330         const struct arg *arg = pop_args(ctx);
9331         unsigned int i;
9332         int ret;
9333
9334         /* Argument is expected. */
9335         if (!arg)
9336                 return -1;
9337         for (i = 0; boolean_name[i]; ++i)
9338                 if (!strcmp_partial(boolean_name[i], str, len))
9339                         break;
9340         /* Process token as integer. */
9341         if (boolean_name[i])
9342                 str = i & 1 ? "1" : "0";
9343         push_args(ctx, arg);
9344         ret = parse_int(ctx, token, str, strlen(str), buf, size);
9345         return ret > 0 ? (int)len : ret;
9346 }
9347
9348 /** Parse port and update context. */
9349 static int
9350 parse_port(struct context *ctx, const struct token *token,
9351            const char *str, unsigned int len,
9352            void *buf, unsigned int size)
9353 {
9354         struct buffer *out = &(struct buffer){ .port = 0 };
9355         int ret;
9356
9357         if (buf)
9358                 out = buf;
9359         else {
9360                 ctx->objdata = 0;
9361                 ctx->object = out;
9362                 ctx->objmask = NULL;
9363                 size = sizeof(*out);
9364         }
9365         ret = parse_int(ctx, token, str, len, out, size);
9366         if (ret >= 0)
9367                 ctx->port = out->port;
9368         if (!buf)
9369                 ctx->object = NULL;
9370         return ret;
9371 }
9372
9373 static int
9374 parse_ia_id2ptr(struct context *ctx, const struct token *token,
9375                 const char *str, unsigned int len,
9376                 void *buf, unsigned int size)
9377 {
9378         struct rte_flow_action *action = ctx->object;
9379         uint32_t id;
9380         int ret;
9381
9382         (void)buf;
9383         (void)size;
9384         ctx->objdata = 0;
9385         ctx->object = &id;
9386         ctx->objmask = NULL;
9387         ret = parse_int(ctx, token, str, len, ctx->object, sizeof(id));
9388         ctx->object = action;
9389         if (ret != (int)len)
9390                 return ret;
9391         /* set indirect action */
9392         if (action) {
9393                 action->conf = port_action_handle_get_by_id(ctx->port, id);
9394                 ret = (action->conf) ? ret : -1;
9395         }
9396         return ret;
9397 }
9398
9399 /** Parse set command, initialize output buffer for subsequent tokens. */
9400 static int
9401 parse_set_raw_encap_decap(struct context *ctx, const struct token *token,
9402                           const char *str, unsigned int len,
9403                           void *buf, unsigned int size)
9404 {
9405         struct buffer *out = buf;
9406
9407         /* Token name must match. */
9408         if (parse_default(ctx, token, str, len, NULL, 0) < 0)
9409                 return -1;
9410         /* Nothing else to do if there is no buffer. */
9411         if (!out)
9412                 return len;
9413         /* Make sure buffer is large enough. */
9414         if (size < sizeof(*out))
9415                 return -1;
9416         ctx->objdata = 0;
9417         ctx->objmask = NULL;
9418         ctx->object = out;
9419         if (!out->command)
9420                 return -1;
9421         out->command = ctx->curr;
9422         /* For encap/decap we need is pattern */
9423         out->args.vc.pattern = (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
9424                                                        sizeof(double));
9425         return len;
9426 }
9427
9428 /** Parse set command, initialize output buffer for subsequent tokens. */
9429 static int
9430 parse_set_sample_action(struct context *ctx, const struct token *token,
9431                           const char *str, unsigned int len,
9432                           void *buf, unsigned int size)
9433 {
9434         struct buffer *out = buf;
9435
9436         /* Token name must match. */
9437         if (parse_default(ctx, token, str, len, NULL, 0) < 0)
9438                 return -1;
9439         /* Nothing else to do if there is no buffer. */
9440         if (!out)
9441                 return len;
9442         /* Make sure buffer is large enough. */
9443         if (size < sizeof(*out))
9444                 return -1;
9445         ctx->objdata = 0;
9446         ctx->objmask = NULL;
9447         ctx->object = out;
9448         if (!out->command)
9449                 return -1;
9450         out->command = ctx->curr;
9451         /* For sampler we need is actions */
9452         out->args.vc.actions = (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
9453                                                        sizeof(double));
9454         return len;
9455 }
9456
9457 /**
9458  * Parse set raw_encap/raw_decap command,
9459  * initialize output buffer for subsequent tokens.
9460  */
9461 static int
9462 parse_set_init(struct context *ctx, const struct token *token,
9463                const char *str, unsigned int len,
9464                void *buf, unsigned int size)
9465 {
9466         struct buffer *out = buf;
9467
9468         /* Token name must match. */
9469         if (parse_default(ctx, token, str, len, NULL, 0) < 0)
9470                 return -1;
9471         /* Nothing else to do if there is no buffer. */
9472         if (!out)
9473                 return len;
9474         /* Make sure buffer is large enough. */
9475         if (size < sizeof(*out))
9476                 return -1;
9477         /* Initialize buffer. */
9478         memset(out, 0x00, sizeof(*out));
9479         memset((uint8_t *)out + sizeof(*out), 0x22, size - sizeof(*out));
9480         ctx->objdata = 0;
9481         ctx->object = out;
9482         ctx->objmask = NULL;
9483         if (!out->command) {
9484                 if (ctx->curr != SET)
9485                         return -1;
9486                 if (sizeof(*out) > size)
9487                         return -1;
9488                 out->command = ctx->curr;
9489                 out->args.vc.data = (uint8_t *)out + size;
9490                 ctx->object  = (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
9491                                                        sizeof(double));
9492         }
9493         return len;
9494 }
9495
9496 /*
9497  * Replace testpmd handles in a flex flow item with real values.
9498  */
9499 static int
9500 parse_flex_handle(struct context *ctx, const struct token *token,
9501                   const char *str, unsigned int len,
9502                   void *buf, unsigned int size)
9503 {
9504         struct rte_flow_item_flex *spec, *mask;
9505         const struct rte_flow_item_flex *src_spec, *src_mask;
9506         const struct arg *arg = pop_args(ctx);
9507         uint32_t offset;
9508         uint16_t handle;
9509         int ret;
9510
9511         if (!arg) {
9512                 printf("Bad environment\n");
9513                 return -1;
9514         }
9515         offset = arg->offset;
9516         push_args(ctx, arg);
9517         ret = parse_int(ctx, token, str, len, buf, size);
9518         if (ret <= 0 || !ctx->object)
9519                 return ret;
9520         if (ctx->port >= RTE_MAX_ETHPORTS) {
9521                 printf("Bad port\n");
9522                 return -1;
9523         }
9524         if (offset == offsetof(struct rte_flow_item_flex, handle)) {
9525                 const struct flex_item *fp;
9526                 struct rte_flow_item_flex *item_flex = ctx->object;
9527                 handle = (uint16_t)(uintptr_t)item_flex->handle;
9528                 if (handle >= FLEX_MAX_PARSERS_NUM) {
9529                         printf("Bad flex item handle\n");
9530                         return -1;
9531                 }
9532                 fp = flex_items[ctx->port][handle];
9533                 if (!fp) {
9534                         printf("Bad flex item handle\n");
9535                         return -1;
9536                 }
9537                 item_flex->handle = fp->flex_handle;
9538         } else if (offset == offsetof(struct rte_flow_item_flex, pattern)) {
9539                 handle = (uint16_t)(uintptr_t)
9540                         ((struct rte_flow_item_flex *)ctx->object)->pattern;
9541                 if (handle >= FLEX_MAX_PATTERNS_NUM) {
9542                         printf("Bad pattern handle\n");
9543                         return -1;
9544                 }
9545                 src_spec = &flex_patterns[handle].spec;
9546                 src_mask = &flex_patterns[handle].mask;
9547                 spec = ctx->object;
9548                 mask = spec + 2; /* spec, last, mask */
9549                 /* fill flow rule spec and mask parameters */
9550                 spec->length = src_spec->length;
9551                 spec->pattern = src_spec->pattern;
9552                 mask->length = src_mask->length;
9553                 mask->pattern = src_mask->pattern;
9554         } else {
9555                 printf("Bad arguments - unknown flex item offset\n");
9556                 return -1;
9557         }
9558         return ret;
9559 }
9560
9561 /** No completion. */
9562 static int
9563 comp_none(struct context *ctx, const struct token *token,
9564           unsigned int ent, char *buf, unsigned int size)
9565 {
9566         (void)ctx;
9567         (void)token;
9568         (void)ent;
9569         (void)buf;
9570         (void)size;
9571         return 0;
9572 }
9573
9574 /** Complete boolean values. */
9575 static int
9576 comp_boolean(struct context *ctx, const struct token *token,
9577              unsigned int ent, char *buf, unsigned int size)
9578 {
9579         unsigned int i;
9580
9581         (void)ctx;
9582         (void)token;
9583         for (i = 0; boolean_name[i]; ++i)
9584                 if (buf && i == ent)
9585                         return strlcpy(buf, boolean_name[i], size);
9586         if (buf)
9587                 return -1;
9588         return i;
9589 }
9590
9591 /** Complete action names. */
9592 static int
9593 comp_action(struct context *ctx, const struct token *token,
9594             unsigned int ent, char *buf, unsigned int size)
9595 {
9596         unsigned int i;
9597
9598         (void)ctx;
9599         (void)token;
9600         for (i = 0; next_action[i]; ++i)
9601                 if (buf && i == ent)
9602                         return strlcpy(buf, token_list[next_action[i]].name,
9603                                        size);
9604         if (buf)
9605                 return -1;
9606         return i;
9607 }
9608
9609 /** Complete available ports. */
9610 static int
9611 comp_port(struct context *ctx, const struct token *token,
9612           unsigned int ent, char *buf, unsigned int size)
9613 {
9614         unsigned int i = 0;
9615         portid_t p;
9616
9617         (void)ctx;
9618         (void)token;
9619         RTE_ETH_FOREACH_DEV(p) {
9620                 if (buf && i == ent)
9621                         return snprintf(buf, size, "%u", p);
9622                 ++i;
9623         }
9624         if (buf)
9625                 return -1;
9626         return i;
9627 }
9628
9629 /** Complete available rule IDs. */
9630 static int
9631 comp_rule_id(struct context *ctx, const struct token *token,
9632              unsigned int ent, char *buf, unsigned int size)
9633 {
9634         unsigned int i = 0;
9635         struct rte_port *port;
9636         struct port_flow *pf;
9637
9638         (void)token;
9639         if (port_id_is_invalid(ctx->port, DISABLED_WARN) ||
9640             ctx->port == (portid_t)RTE_PORT_ALL)
9641                 return -1;
9642         port = &ports[ctx->port];
9643         for (pf = port->flow_list; pf != NULL; pf = pf->next) {
9644                 if (buf && i == ent)
9645                         return snprintf(buf, size, "%u", pf->id);
9646                 ++i;
9647         }
9648         if (buf)
9649                 return -1;
9650         return i;
9651 }
9652
9653 /** Complete type field for RSS action. */
9654 static int
9655 comp_vc_action_rss_type(struct context *ctx, const struct token *token,
9656                         unsigned int ent, char *buf, unsigned int size)
9657 {
9658         unsigned int i;
9659
9660         (void)ctx;
9661         (void)token;
9662         for (i = 0; rss_type_table[i].str; ++i)
9663                 ;
9664         if (!buf)
9665                 return i + 1;
9666         if (ent < i)
9667                 return strlcpy(buf, rss_type_table[ent].str, size);
9668         if (ent == i)
9669                 return snprintf(buf, size, "end");
9670         return -1;
9671 }
9672
9673 /** Complete queue field for RSS action. */
9674 static int
9675 comp_vc_action_rss_queue(struct context *ctx, const struct token *token,
9676                          unsigned int ent, char *buf, unsigned int size)
9677 {
9678         (void)ctx;
9679         (void)token;
9680         if (!buf)
9681                 return nb_rxq + 1;
9682         if (ent < nb_rxq)
9683                 return snprintf(buf, size, "%u", ent);
9684         if (ent == nb_rxq)
9685                 return snprintf(buf, size, "end");
9686         return -1;
9687 }
9688
9689 /** Complete index number for set raw_encap/raw_decap commands. */
9690 static int
9691 comp_set_raw_index(struct context *ctx, const struct token *token,
9692                    unsigned int ent, char *buf, unsigned int size)
9693 {
9694         uint16_t idx = 0;
9695         uint16_t nb = 0;
9696
9697         RTE_SET_USED(ctx);
9698         RTE_SET_USED(token);
9699         for (idx = 0; idx < RAW_ENCAP_CONFS_MAX_NUM; ++idx) {
9700                 if (buf && idx == ent)
9701                         return snprintf(buf, size, "%u", idx);
9702                 ++nb;
9703         }
9704         return nb;
9705 }
9706
9707 /** Complete index number for set raw_encap/raw_decap commands. */
9708 static int
9709 comp_set_sample_index(struct context *ctx, const struct token *token,
9710                    unsigned int ent, char *buf, unsigned int size)
9711 {
9712         uint16_t idx = 0;
9713         uint16_t nb = 0;
9714
9715         RTE_SET_USED(ctx);
9716         RTE_SET_USED(token);
9717         for (idx = 0; idx < RAW_SAMPLE_CONFS_MAX_NUM; ++idx) {
9718                 if (buf && idx == ent)
9719                         return snprintf(buf, size, "%u", idx);
9720                 ++nb;
9721         }
9722         return nb;
9723 }
9724
9725 /** Complete operation for modify_field command. */
9726 static int
9727 comp_set_modify_field_op(struct context *ctx, const struct token *token,
9728                    unsigned int ent, char *buf, unsigned int size)
9729 {
9730         RTE_SET_USED(ctx);
9731         RTE_SET_USED(token);
9732         if (!buf)
9733                 return RTE_DIM(modify_field_ops);
9734         if (ent < RTE_DIM(modify_field_ops) - 1)
9735                 return strlcpy(buf, modify_field_ops[ent], size);
9736         return -1;
9737 }
9738
9739 /** Complete field id for modify_field command. */
9740 static int
9741 comp_set_modify_field_id(struct context *ctx, const struct token *token,
9742                    unsigned int ent, char *buf, unsigned int size)
9743 {
9744         const char *name;
9745
9746         RTE_SET_USED(token);
9747         if (!buf)
9748                 return RTE_DIM(modify_field_ids);
9749         if (ent >= RTE_DIM(modify_field_ids) - 1)
9750                 return -1;
9751         name = modify_field_ids[ent];
9752         if (ctx->curr == ACTION_MODIFY_FIELD_SRC_TYPE ||
9753             (strcmp(name, "pointer") && strcmp(name, "value")))
9754                 return strlcpy(buf, name, size);
9755         return -1;
9756 }
9757
9758 /** Complete available pattern template IDs. */
9759 static int
9760 comp_pattern_template_id(struct context *ctx, const struct token *token,
9761                          unsigned int ent, char *buf, unsigned int size)
9762 {
9763         unsigned int i = 0;
9764         struct rte_port *port;
9765         struct port_template *pt;
9766
9767         (void)token;
9768         if (port_id_is_invalid(ctx->port, DISABLED_WARN) ||
9769             ctx->port == (portid_t)RTE_PORT_ALL)
9770                 return -1;
9771         port = &ports[ctx->port];
9772         for (pt = port->pattern_templ_list; pt != NULL; pt = pt->next) {
9773                 if (buf && i == ent)
9774                         return snprintf(buf, size, "%u", pt->id);
9775                 ++i;
9776         }
9777         if (buf)
9778                 return -1;
9779         return i;
9780 }
9781
9782 /** Complete available actions template IDs. */
9783 static int
9784 comp_actions_template_id(struct context *ctx, const struct token *token,
9785                          unsigned int ent, char *buf, unsigned int size)
9786 {
9787         unsigned int i = 0;
9788         struct rte_port *port;
9789         struct port_template *pt;
9790
9791         (void)token;
9792         if (port_id_is_invalid(ctx->port, DISABLED_WARN) ||
9793             ctx->port == (portid_t)RTE_PORT_ALL)
9794                 return -1;
9795         port = &ports[ctx->port];
9796         for (pt = port->actions_templ_list; pt != NULL; pt = pt->next) {
9797                 if (buf && i == ent)
9798                         return snprintf(buf, size, "%u", pt->id);
9799                 ++i;
9800         }
9801         if (buf)
9802                 return -1;
9803         return i;
9804 }
9805
9806 /** Complete available table IDs. */
9807 static int
9808 comp_table_id(struct context *ctx, const struct token *token,
9809               unsigned int ent, char *buf, unsigned int size)
9810 {
9811         unsigned int i = 0;
9812         struct rte_port *port;
9813         struct port_table *pt;
9814
9815         (void)token;
9816         if (port_id_is_invalid(ctx->port, DISABLED_WARN) ||
9817             ctx->port == (portid_t)RTE_PORT_ALL)
9818                 return -1;
9819         port = &ports[ctx->port];
9820         for (pt = port->table_list; pt != NULL; pt = pt->next) {
9821                 if (buf && i == ent)
9822                         return snprintf(buf, size, "%u", pt->id);
9823                 ++i;
9824         }
9825         if (buf)
9826                 return -1;
9827         return i;
9828 }
9829
9830 /** Complete available queue IDs. */
9831 static int
9832 comp_queue_id(struct context *ctx, const struct token *token,
9833               unsigned int ent, char *buf, unsigned int size)
9834 {
9835         unsigned int i = 0;
9836         struct rte_port *port;
9837
9838         (void)token;
9839         if (port_id_is_invalid(ctx->port, DISABLED_WARN) ||
9840             ctx->port == (portid_t)RTE_PORT_ALL)
9841                 return -1;
9842         port = &ports[ctx->port];
9843         for (i = 0; i < port->queue_nb; i++) {
9844                 if (buf && i == ent)
9845                         return snprintf(buf, size, "%u", i);
9846         }
9847         if (buf)
9848                 return -1;
9849         return i;
9850 }
9851
9852 /** Internal context. */
9853 static struct context cmd_flow_context;
9854
9855 /** Global parser instance (cmdline API). */
9856 cmdline_parse_inst_t cmd_flow;
9857 cmdline_parse_inst_t cmd_set_raw;
9858
9859 /** Initialize context. */
9860 static void
9861 cmd_flow_context_init(struct context *ctx)
9862 {
9863         /* A full memset() is not necessary. */
9864         ctx->curr = ZERO;
9865         ctx->prev = ZERO;
9866         ctx->next_num = 0;
9867         ctx->args_num = 0;
9868         ctx->eol = 0;
9869         ctx->last = 0;
9870         ctx->port = 0;
9871         ctx->objdata = 0;
9872         ctx->object = NULL;
9873         ctx->objmask = NULL;
9874 }
9875
9876 /** Parse a token (cmdline API). */
9877 static int
9878 cmd_flow_parse(cmdline_parse_token_hdr_t *hdr, const char *src, void *result,
9879                unsigned int size)
9880 {
9881         struct context *ctx = &cmd_flow_context;
9882         const struct token *token;
9883         const enum index *list;
9884         int len;
9885         int i;
9886
9887         (void)hdr;
9888         token = &token_list[ctx->curr];
9889         /* Check argument length. */
9890         ctx->eol = 0;
9891         ctx->last = 1;
9892         for (len = 0; src[len]; ++len)
9893                 if (src[len] == '#' || isspace(src[len]))
9894                         break;
9895         if (!len)
9896                 return -1;
9897         /* Last argument and EOL detection. */
9898         for (i = len; src[i]; ++i)
9899                 if (src[i] == '#' || src[i] == '\r' || src[i] == '\n')
9900                         break;
9901                 else if (!isspace(src[i])) {
9902                         ctx->last = 0;
9903                         break;
9904                 }
9905         for (; src[i]; ++i)
9906                 if (src[i] == '\r' || src[i] == '\n') {
9907                         ctx->eol = 1;
9908                         break;
9909                 }
9910         /* Initialize context if necessary. */
9911         if (!ctx->next_num) {
9912                 if (!token->next)
9913                         return 0;
9914                 ctx->next[ctx->next_num++] = token->next[0];
9915         }
9916         /* Process argument through candidates. */
9917         ctx->prev = ctx->curr;
9918         list = ctx->next[ctx->next_num - 1];
9919         for (i = 0; list[i]; ++i) {
9920                 const struct token *next = &token_list[list[i]];
9921                 int tmp;
9922
9923                 ctx->curr = list[i];
9924                 if (next->call)
9925                         tmp = next->call(ctx, next, src, len, result, size);
9926                 else
9927                         tmp = parse_default(ctx, next, src, len, result, size);
9928                 if (tmp == -1 || tmp != len)
9929                         continue;
9930                 token = next;
9931                 break;
9932         }
9933         if (!list[i])
9934                 return -1;
9935         --ctx->next_num;
9936         /* Push subsequent tokens if any. */
9937         if (token->next)
9938                 for (i = 0; token->next[i]; ++i) {
9939                         if (ctx->next_num == RTE_DIM(ctx->next))
9940                                 return -1;
9941                         ctx->next[ctx->next_num++] = token->next[i];
9942                 }
9943         /* Push arguments if any. */
9944         if (token->args)
9945                 for (i = 0; token->args[i]; ++i) {
9946                         if (ctx->args_num == RTE_DIM(ctx->args))
9947                                 return -1;
9948                         ctx->args[ctx->args_num++] = token->args[i];
9949                 }
9950         return len;
9951 }
9952
9953 int
9954 flow_parse(const char *src, void *result, unsigned int size,
9955            struct rte_flow_attr **attr,
9956            struct rte_flow_item **pattern, struct rte_flow_action **actions)
9957 {
9958         int ret;
9959         struct context saved_flow_ctx = cmd_flow_context;
9960
9961         cmd_flow_context_init(&cmd_flow_context);
9962         do {
9963                 ret = cmd_flow_parse(NULL, src, result, size);
9964                 if (ret > 0) {
9965                         src += ret;
9966                         while (isspace(*src))
9967                                 src++;
9968                 }
9969         } while (ret > 0 && strlen(src));
9970         cmd_flow_context = saved_flow_ctx;
9971         *attr = &((struct buffer *)result)->args.vc.attr;
9972         *pattern = ((struct buffer *)result)->args.vc.pattern;
9973         *actions = ((struct buffer *)result)->args.vc.actions;
9974         return (ret >= 0 && !strlen(src)) ? 0 : -1;
9975 }
9976
9977 /** Return number of completion entries (cmdline API). */
9978 static int
9979 cmd_flow_complete_get_nb(cmdline_parse_token_hdr_t *hdr)
9980 {
9981         struct context *ctx = &cmd_flow_context;
9982         const struct token *token = &token_list[ctx->curr];
9983         const enum index *list;
9984         int i;
9985
9986         (void)hdr;
9987         /* Count number of tokens in current list. */
9988         if (ctx->next_num)
9989                 list = ctx->next[ctx->next_num - 1];
9990         else
9991                 list = token->next[0];
9992         for (i = 0; list[i]; ++i)
9993                 ;
9994         if (!i)
9995                 return 0;
9996         /*
9997          * If there is a single token, use its completion callback, otherwise
9998          * return the number of entries.
9999          */
10000         token = &token_list[list[0]];
10001         if (i == 1 && token->comp) {
10002                 /* Save index for cmd_flow_get_help(). */
10003                 ctx->prev = list[0];
10004                 return token->comp(ctx, token, 0, NULL, 0);
10005         }
10006         return i;
10007 }
10008
10009 /** Return a completion entry (cmdline API). */
10010 static int
10011 cmd_flow_complete_get_elt(cmdline_parse_token_hdr_t *hdr, int index,
10012                           char *dst, unsigned int size)
10013 {
10014         struct context *ctx = &cmd_flow_context;
10015         const struct token *token = &token_list[ctx->curr];
10016         const enum index *list;
10017         int i;
10018
10019         (void)hdr;
10020         /* Count number of tokens in current list. */
10021         if (ctx->next_num)
10022                 list = ctx->next[ctx->next_num - 1];
10023         else
10024                 list = token->next[0];
10025         for (i = 0; list[i]; ++i)
10026                 ;
10027         if (!i)
10028                 return -1;
10029         /* If there is a single token, use its completion callback. */
10030         token = &token_list[list[0]];
10031         if (i == 1 && token->comp) {
10032                 /* Save index for cmd_flow_get_help(). */
10033                 ctx->prev = list[0];
10034                 return token->comp(ctx, token, index, dst, size) < 0 ? -1 : 0;
10035         }
10036         /* Otherwise make sure the index is valid and use defaults. */
10037         if (index >= i)
10038                 return -1;
10039         token = &token_list[list[index]];
10040         strlcpy(dst, token->name, size);
10041         /* Save index for cmd_flow_get_help(). */
10042         ctx->prev = list[index];
10043         return 0;
10044 }
10045
10046 /** Populate help strings for current token (cmdline API). */
10047 static int
10048 cmd_flow_get_help(cmdline_parse_token_hdr_t *hdr, char *dst, unsigned int size)
10049 {
10050         struct context *ctx = &cmd_flow_context;
10051         const struct token *token = &token_list[ctx->prev];
10052
10053         (void)hdr;
10054         if (!size)
10055                 return -1;
10056         /* Set token type and update global help with details. */
10057         strlcpy(dst, (token->type ? token->type : "TOKEN"), size);
10058         if (token->help)
10059                 cmd_flow.help_str = token->help;
10060         else
10061                 cmd_flow.help_str = token->name;
10062         return 0;
10063 }
10064
10065 /** Token definition template (cmdline API). */
10066 static struct cmdline_token_hdr cmd_flow_token_hdr = {
10067         .ops = &(struct cmdline_token_ops){
10068                 .parse = cmd_flow_parse,
10069                 .complete_get_nb = cmd_flow_complete_get_nb,
10070                 .complete_get_elt = cmd_flow_complete_get_elt,
10071                 .get_help = cmd_flow_get_help,
10072         },
10073         .offset = 0,
10074 };
10075
10076 /** Populate the next dynamic token. */
10077 static void
10078 cmd_flow_tok(cmdline_parse_token_hdr_t **hdr,
10079              cmdline_parse_token_hdr_t **hdr_inst)
10080 {
10081         struct context *ctx = &cmd_flow_context;
10082
10083         /* Always reinitialize context before requesting the first token. */
10084         if (!(hdr_inst - cmd_flow.tokens))
10085                 cmd_flow_context_init(ctx);
10086         /* Return NULL when no more tokens are expected. */
10087         if (!ctx->next_num && ctx->curr) {
10088                 *hdr = NULL;
10089                 return;
10090         }
10091         /* Determine if command should end here. */
10092         if (ctx->eol && ctx->last && ctx->next_num) {
10093                 const enum index *list = ctx->next[ctx->next_num - 1];
10094                 int i;
10095
10096                 for (i = 0; list[i]; ++i) {
10097                         if (list[i] != END)
10098                                 continue;
10099                         *hdr = NULL;
10100                         return;
10101                 }
10102         }
10103         *hdr = &cmd_flow_token_hdr;
10104 }
10105
10106 /** Dispatch parsed buffer to function calls. */
10107 static void
10108 cmd_flow_parsed(const struct buffer *in)
10109 {
10110         switch (in->command) {
10111         case INFO:
10112                 port_flow_get_info(in->port);
10113                 break;
10114         case CONFIGURE:
10115                 port_flow_configure(in->port,
10116                                     &in->args.configure.port_attr,
10117                                     in->args.configure.nb_queue,
10118                                     &in->args.configure.queue_attr);
10119                 break;
10120         case PATTERN_TEMPLATE_CREATE:
10121                 port_flow_pattern_template_create(in->port,
10122                                 in->args.vc.pat_templ_id,
10123                                 &((const struct rte_flow_pattern_template_attr) {
10124                                         .relaxed_matching = in->args.vc.attr.reserved,
10125                                         .ingress = in->args.vc.attr.ingress,
10126                                         .egress = in->args.vc.attr.egress,
10127                                         .transfer = in->args.vc.attr.transfer,
10128                                 }),
10129                                 in->args.vc.pattern);
10130                 break;
10131         case PATTERN_TEMPLATE_DESTROY:
10132                 port_flow_pattern_template_destroy(in->port,
10133                                 in->args.templ_destroy.template_id_n,
10134                                 in->args.templ_destroy.template_id);
10135                 break;
10136         case ACTIONS_TEMPLATE_CREATE:
10137                 port_flow_actions_template_create(in->port,
10138                                 in->args.vc.act_templ_id,
10139                                 &((const struct rte_flow_actions_template_attr) {
10140                                         .ingress = in->args.vc.attr.ingress,
10141                                         .egress = in->args.vc.attr.egress,
10142                                         .transfer = in->args.vc.attr.transfer,
10143                                 }),
10144                                 in->args.vc.actions,
10145                                 in->args.vc.masks);
10146                 break;
10147         case ACTIONS_TEMPLATE_DESTROY:
10148                 port_flow_actions_template_destroy(in->port,
10149                                 in->args.templ_destroy.template_id_n,
10150                                 in->args.templ_destroy.template_id);
10151                 break;
10152         case TABLE_CREATE:
10153                 port_flow_template_table_create(in->port, in->args.table.id,
10154                         &in->args.table.attr, in->args.table.pat_templ_id_n,
10155                         in->args.table.pat_templ_id, in->args.table.act_templ_id_n,
10156                         in->args.table.act_templ_id);
10157                 break;
10158         case TABLE_DESTROY:
10159                 port_flow_template_table_destroy(in->port,
10160                                         in->args.table_destroy.table_id_n,
10161                                         in->args.table_destroy.table_id);
10162                 break;
10163         case QUEUE_CREATE:
10164                 port_queue_flow_create(in->port, in->queue, in->postpone,
10165                                        in->args.vc.table_id, in->args.vc.pat_templ_id,
10166                                        in->args.vc.act_templ_id, in->args.vc.pattern,
10167                                        in->args.vc.actions);
10168                 break;
10169         case QUEUE_DESTROY:
10170                 port_queue_flow_destroy(in->port, in->queue, in->postpone,
10171                                         in->args.destroy.rule_n,
10172                                         in->args.destroy.rule);
10173                 break;
10174         case PUSH:
10175                 port_queue_flow_push(in->port, in->queue);
10176                 break;
10177         case INDIRECT_ACTION_CREATE:
10178                 port_action_handle_create(
10179                                 in->port, in->args.vc.attr.group,
10180                                 &((const struct rte_flow_indir_action_conf) {
10181                                         .ingress = in->args.vc.attr.ingress,
10182                                         .egress = in->args.vc.attr.egress,
10183                                         .transfer = in->args.vc.attr.transfer,
10184                                 }),
10185                                 in->args.vc.actions);
10186                 break;
10187         case INDIRECT_ACTION_DESTROY:
10188                 port_action_handle_destroy(in->port,
10189                                            in->args.ia_destroy.action_id_n,
10190                                            in->args.ia_destroy.action_id);
10191                 break;
10192         case INDIRECT_ACTION_UPDATE:
10193                 port_action_handle_update(in->port, in->args.vc.attr.group,
10194                                           in->args.vc.actions);
10195                 break;
10196         case INDIRECT_ACTION_QUERY:
10197                 port_action_handle_query(in->port, in->args.ia.action_id);
10198                 break;
10199         case VALIDATE:
10200                 port_flow_validate(in->port, &in->args.vc.attr,
10201                                    in->args.vc.pattern, in->args.vc.actions,
10202                                    &in->args.vc.tunnel_ops);
10203                 break;
10204         case CREATE:
10205                 port_flow_create(in->port, &in->args.vc.attr,
10206                                  in->args.vc.pattern, in->args.vc.actions,
10207                                  &in->args.vc.tunnel_ops);
10208                 break;
10209         case DESTROY:
10210                 port_flow_destroy(in->port, in->args.destroy.rule_n,
10211                                   in->args.destroy.rule);
10212                 break;
10213         case FLUSH:
10214                 port_flow_flush(in->port);
10215                 break;
10216         case DUMP_ONE:
10217         case DUMP_ALL:
10218                 port_flow_dump(in->port, in->args.dump.mode,
10219                                 in->args.dump.rule, in->args.dump.file);
10220                 break;
10221         case QUERY:
10222                 port_flow_query(in->port, in->args.query.rule,
10223                                 &in->args.query.action);
10224                 break;
10225         case LIST:
10226                 port_flow_list(in->port, in->args.list.group_n,
10227                                in->args.list.group);
10228                 break;
10229         case ISOLATE:
10230                 port_flow_isolate(in->port, in->args.isolate.set);
10231                 break;
10232         case AGED:
10233                 port_flow_aged(in->port, in->args.aged.destroy);
10234                 break;
10235         case TUNNEL_CREATE:
10236                 port_flow_tunnel_create(in->port, &in->args.vc.tunnel_ops);
10237                 break;
10238         case TUNNEL_DESTROY:
10239                 port_flow_tunnel_destroy(in->port, in->args.vc.tunnel_ops.id);
10240                 break;
10241         case TUNNEL_LIST:
10242                 port_flow_tunnel_list(in->port);
10243                 break;
10244         case ACTION_POL_G:
10245                 port_meter_policy_add(in->port, in->args.policy.policy_id,
10246                                         in->args.vc.actions);
10247                 break;
10248         case FLEX_ITEM_CREATE:
10249                 flex_item_create(in->port, in->args.flex.token,
10250                                  in->args.flex.filename);
10251                 break;
10252         case FLEX_ITEM_DESTROY:
10253                 flex_item_destroy(in->port, in->args.flex.token);
10254                 break;
10255         default:
10256                 break;
10257         }
10258 }
10259
10260 /** Token generator and output processing callback (cmdline API). */
10261 static void
10262 cmd_flow_cb(void *arg0, struct cmdline *cl, void *arg2)
10263 {
10264         if (cl == NULL)
10265                 cmd_flow_tok(arg0, arg2);
10266         else
10267                 cmd_flow_parsed(arg0);
10268 }
10269
10270 /** Global parser instance (cmdline API). */
10271 cmdline_parse_inst_t cmd_flow = {
10272         .f = cmd_flow_cb,
10273         .data = NULL, /**< Unused. */
10274         .help_str = NULL, /**< Updated by cmd_flow_get_help(). */
10275         .tokens = {
10276                 NULL,
10277         }, /**< Tokens are returned by cmd_flow_tok(). */
10278 };
10279
10280 /** set cmd facility. Reuse cmd flow's infrastructure as much as possible. */
10281
10282 static void
10283 update_fields(uint8_t *buf, struct rte_flow_item *item, uint16_t next_proto)
10284 {
10285         struct rte_ipv4_hdr *ipv4;
10286         struct rte_ether_hdr *eth;
10287         struct rte_ipv6_hdr *ipv6;
10288         struct rte_vxlan_hdr *vxlan;
10289         struct rte_vxlan_gpe_hdr *gpe;
10290         struct rte_flow_item_nvgre *nvgre;
10291         uint32_t ipv6_vtc_flow;
10292
10293         switch (item->type) {
10294         case RTE_FLOW_ITEM_TYPE_ETH:
10295                 eth = (struct rte_ether_hdr *)buf;
10296                 if (next_proto)
10297                         eth->ether_type = rte_cpu_to_be_16(next_proto);
10298                 break;
10299         case RTE_FLOW_ITEM_TYPE_IPV4:
10300                 ipv4 = (struct rte_ipv4_hdr *)buf;
10301                 if (!ipv4->version_ihl)
10302                         ipv4->version_ihl = RTE_IPV4_VHL_DEF;
10303                 if (next_proto && ipv4->next_proto_id == 0)
10304                         ipv4->next_proto_id = (uint8_t)next_proto;
10305                 break;
10306         case RTE_FLOW_ITEM_TYPE_IPV6:
10307                 ipv6 = (struct rte_ipv6_hdr *)buf;
10308                 if (next_proto && ipv6->proto == 0)
10309                         ipv6->proto = (uint8_t)next_proto;
10310                 ipv6_vtc_flow = rte_be_to_cpu_32(ipv6->vtc_flow);
10311                 ipv6_vtc_flow &= 0x0FFFFFFF; /*< reset version bits. */
10312                 ipv6_vtc_flow |= 0x60000000; /*< set ipv6 version. */
10313                 ipv6->vtc_flow = rte_cpu_to_be_32(ipv6_vtc_flow);
10314                 break;
10315         case RTE_FLOW_ITEM_TYPE_VXLAN:
10316                 vxlan = (struct rte_vxlan_hdr *)buf;
10317                 vxlan->vx_flags = 0x08;
10318                 break;
10319         case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
10320                 gpe = (struct rte_vxlan_gpe_hdr *)buf;
10321                 gpe->vx_flags = 0x0C;
10322                 break;
10323         case RTE_FLOW_ITEM_TYPE_NVGRE:
10324                 nvgre = (struct rte_flow_item_nvgre *)buf;
10325                 nvgre->protocol = rte_cpu_to_be_16(0x6558);
10326                 nvgre->c_k_s_rsvd0_ver = rte_cpu_to_be_16(0x2000);
10327                 break;
10328         default:
10329                 break;
10330         }
10331 }
10332
10333 /** Helper of get item's default mask. */
10334 static const void *
10335 flow_item_default_mask(const struct rte_flow_item *item)
10336 {
10337         const void *mask = NULL;
10338         static rte_be32_t gre_key_default_mask = RTE_BE32(UINT32_MAX);
10339
10340         switch (item->type) {
10341         case RTE_FLOW_ITEM_TYPE_ANY:
10342                 mask = &rte_flow_item_any_mask;
10343                 break;
10344         case RTE_FLOW_ITEM_TYPE_VF:
10345                 mask = &rte_flow_item_vf_mask;
10346                 break;
10347         case RTE_FLOW_ITEM_TYPE_PORT_ID:
10348                 mask = &rte_flow_item_port_id_mask;
10349                 break;
10350         case RTE_FLOW_ITEM_TYPE_RAW:
10351                 mask = &rte_flow_item_raw_mask;
10352                 break;
10353         case RTE_FLOW_ITEM_TYPE_ETH:
10354                 mask = &rte_flow_item_eth_mask;
10355                 break;
10356         case RTE_FLOW_ITEM_TYPE_VLAN:
10357                 mask = &rte_flow_item_vlan_mask;
10358                 break;
10359         case RTE_FLOW_ITEM_TYPE_IPV4:
10360                 mask = &rte_flow_item_ipv4_mask;
10361                 break;
10362         case RTE_FLOW_ITEM_TYPE_IPV6:
10363                 mask = &rte_flow_item_ipv6_mask;
10364                 break;
10365         case RTE_FLOW_ITEM_TYPE_ICMP:
10366                 mask = &rte_flow_item_icmp_mask;
10367                 break;
10368         case RTE_FLOW_ITEM_TYPE_UDP:
10369                 mask = &rte_flow_item_udp_mask;
10370                 break;
10371         case RTE_FLOW_ITEM_TYPE_TCP:
10372                 mask = &rte_flow_item_tcp_mask;
10373                 break;
10374         case RTE_FLOW_ITEM_TYPE_SCTP:
10375                 mask = &rte_flow_item_sctp_mask;
10376                 break;
10377         case RTE_FLOW_ITEM_TYPE_VXLAN:
10378                 mask = &rte_flow_item_vxlan_mask;
10379                 break;
10380         case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
10381                 mask = &rte_flow_item_vxlan_gpe_mask;
10382                 break;
10383         case RTE_FLOW_ITEM_TYPE_E_TAG:
10384                 mask = &rte_flow_item_e_tag_mask;
10385                 break;
10386         case RTE_FLOW_ITEM_TYPE_NVGRE:
10387                 mask = &rte_flow_item_nvgre_mask;
10388                 break;
10389         case RTE_FLOW_ITEM_TYPE_MPLS:
10390                 mask = &rte_flow_item_mpls_mask;
10391                 break;
10392         case RTE_FLOW_ITEM_TYPE_GRE:
10393                 mask = &rte_flow_item_gre_mask;
10394                 break;
10395         case RTE_FLOW_ITEM_TYPE_GRE_KEY:
10396                 mask = &gre_key_default_mask;
10397                 break;
10398         case RTE_FLOW_ITEM_TYPE_META:
10399                 mask = &rte_flow_item_meta_mask;
10400                 break;
10401         case RTE_FLOW_ITEM_TYPE_FUZZY:
10402                 mask = &rte_flow_item_fuzzy_mask;
10403                 break;
10404         case RTE_FLOW_ITEM_TYPE_GTP:
10405                 mask = &rte_flow_item_gtp_mask;
10406                 break;
10407         case RTE_FLOW_ITEM_TYPE_GTP_PSC:
10408                 mask = &rte_flow_item_gtp_psc_mask;
10409                 break;
10410         case RTE_FLOW_ITEM_TYPE_GENEVE:
10411                 mask = &rte_flow_item_geneve_mask;
10412                 break;
10413         case RTE_FLOW_ITEM_TYPE_GENEVE_OPT:
10414                 mask = &rte_flow_item_geneve_opt_mask;
10415                 break;
10416         case RTE_FLOW_ITEM_TYPE_PPPOE_PROTO_ID:
10417                 mask = &rte_flow_item_pppoe_proto_id_mask;
10418                 break;
10419         case RTE_FLOW_ITEM_TYPE_L2TPV3OIP:
10420                 mask = &rte_flow_item_l2tpv3oip_mask;
10421                 break;
10422         case RTE_FLOW_ITEM_TYPE_ESP:
10423                 mask = &rte_flow_item_esp_mask;
10424                 break;
10425         case RTE_FLOW_ITEM_TYPE_AH:
10426                 mask = &rte_flow_item_ah_mask;
10427                 break;
10428         case RTE_FLOW_ITEM_TYPE_PFCP:
10429                 mask = &rte_flow_item_pfcp_mask;
10430                 break;
10431         case RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR:
10432         case RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT:
10433                 mask = &rte_flow_item_ethdev_mask;
10434                 break;
10435         case RTE_FLOW_ITEM_TYPE_L2TPV2:
10436                 mask = &rte_flow_item_l2tpv2_mask;
10437                 break;
10438         case RTE_FLOW_ITEM_TYPE_PPP:
10439                 mask = &rte_flow_item_ppp_mask;
10440                 break;
10441         default:
10442                 break;
10443         }
10444         return mask;
10445 }
10446
10447 /** Dispatch parsed buffer to function calls. */
10448 static void
10449 cmd_set_raw_parsed_sample(const struct buffer *in)
10450 {
10451         uint32_t n = in->args.vc.actions_n;
10452         uint32_t i = 0;
10453         struct rte_flow_action *action = NULL;
10454         struct rte_flow_action *data = NULL;
10455         const struct rte_flow_action_rss *rss = NULL;
10456         size_t size = 0;
10457         uint16_t idx = in->port; /* We borrow port field as index */
10458         uint32_t max_size = sizeof(struct rte_flow_action) *
10459                                                 ACTION_SAMPLE_ACTIONS_NUM;
10460
10461         RTE_ASSERT(in->command == SET_SAMPLE_ACTIONS);
10462         data = (struct rte_flow_action *)&raw_sample_confs[idx].data;
10463         memset(data, 0x00, max_size);
10464         for (; i <= n - 1; i++) {
10465                 action = in->args.vc.actions + i;
10466                 if (action->type == RTE_FLOW_ACTION_TYPE_END)
10467                         break;
10468                 switch (action->type) {
10469                 case RTE_FLOW_ACTION_TYPE_MARK:
10470                         size = sizeof(struct rte_flow_action_mark);
10471                         rte_memcpy(&sample_mark[idx],
10472                                 (const void *)action->conf, size);
10473                         action->conf = &sample_mark[idx];
10474                         break;
10475                 case RTE_FLOW_ACTION_TYPE_COUNT:
10476                         size = sizeof(struct rte_flow_action_count);
10477                         rte_memcpy(&sample_count[idx],
10478                                 (const void *)action->conf, size);
10479                         action->conf = &sample_count[idx];
10480                         break;
10481                 case RTE_FLOW_ACTION_TYPE_QUEUE:
10482                         size = sizeof(struct rte_flow_action_queue);
10483                         rte_memcpy(&sample_queue[idx],
10484                                 (const void *)action->conf, size);
10485                         action->conf = &sample_queue[idx];
10486                         break;
10487                 case RTE_FLOW_ACTION_TYPE_RSS:
10488                         size = sizeof(struct rte_flow_action_rss);
10489                         rss = action->conf;
10490                         rte_memcpy(&sample_rss_data[idx].conf,
10491                                    (const void *)rss, size);
10492                         if (rss->key_len && rss->key) {
10493                                 sample_rss_data[idx].conf.key =
10494                                                 sample_rss_data[idx].key;
10495                                 rte_memcpy((void *)((uintptr_t)
10496                                            sample_rss_data[idx].conf.key),
10497                                            (const void *)rss->key,
10498                                            sizeof(uint8_t) * rss->key_len);
10499                         }
10500                         if (rss->queue_num && rss->queue) {
10501                                 sample_rss_data[idx].conf.queue =
10502                                                 sample_rss_data[idx].queue;
10503                                 rte_memcpy((void *)((uintptr_t)
10504                                            sample_rss_data[idx].conf.queue),
10505                                            (const void *)rss->queue,
10506                                            sizeof(uint16_t) * rss->queue_num);
10507                         }
10508                         action->conf = &sample_rss_data[idx].conf;
10509                         break;
10510                 case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
10511                         size = sizeof(struct rte_flow_action_raw_encap);
10512                         rte_memcpy(&sample_encap[idx],
10513                                 (const void *)action->conf, size);
10514                         action->conf = &sample_encap[idx];
10515                         break;
10516                 case RTE_FLOW_ACTION_TYPE_PORT_ID:
10517                         size = sizeof(struct rte_flow_action_port_id);
10518                         rte_memcpy(&sample_port_id[idx],
10519                                 (const void *)action->conf, size);
10520                         action->conf = &sample_port_id[idx];
10521                         break;
10522                 case RTE_FLOW_ACTION_TYPE_PF:
10523                         break;
10524                 case RTE_FLOW_ACTION_TYPE_VF:
10525                         size = sizeof(struct rte_flow_action_vf);
10526                         rte_memcpy(&sample_vf[idx],
10527                                         (const void *)action->conf, size);
10528                         action->conf = &sample_vf[idx];
10529                         break;
10530                 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
10531                         size = sizeof(struct rte_flow_action_vxlan_encap);
10532                         parse_setup_vxlan_encap_data(&sample_vxlan_encap[idx]);
10533                         action->conf = &sample_vxlan_encap[idx].conf;
10534                         break;
10535                 case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
10536                         size = sizeof(struct rte_flow_action_nvgre_encap);
10537                         parse_setup_nvgre_encap_data(&sample_nvgre_encap[idx]);
10538                         action->conf = &sample_nvgre_encap[idx];
10539                         break;
10540                 default:
10541                         fprintf(stderr, "Error - Not supported action\n");
10542                         return;
10543                 }
10544                 rte_memcpy(data, action, sizeof(struct rte_flow_action));
10545                 data++;
10546         }
10547 }
10548
10549 /** Dispatch parsed buffer to function calls. */
10550 static void
10551 cmd_set_raw_parsed(const struct buffer *in)
10552 {
10553         uint32_t n = in->args.vc.pattern_n;
10554         int i = 0;
10555         struct rte_flow_item *item = NULL;
10556         size_t size = 0;
10557         uint8_t *data = NULL;
10558         uint8_t *data_tail = NULL;
10559         size_t *total_size = NULL;
10560         uint16_t upper_layer = 0;
10561         uint16_t proto = 0;
10562         uint16_t idx = in->port; /* We borrow port field as index */
10563         int gtp_psc = -1; /* GTP PSC option index. */
10564
10565         if (in->command == SET_SAMPLE_ACTIONS)
10566                 return cmd_set_raw_parsed_sample(in);
10567         RTE_ASSERT(in->command == SET_RAW_ENCAP ||
10568                    in->command == SET_RAW_DECAP);
10569         if (in->command == SET_RAW_ENCAP) {
10570                 total_size = &raw_encap_confs[idx].size;
10571                 data = (uint8_t *)&raw_encap_confs[idx].data;
10572         } else {
10573                 total_size = &raw_decap_confs[idx].size;
10574                 data = (uint8_t *)&raw_decap_confs[idx].data;
10575         }
10576         *total_size = 0;
10577         memset(data, 0x00, ACTION_RAW_ENCAP_MAX_DATA);
10578         /* process hdr from upper layer to low layer (L3/L4 -> L2). */
10579         data_tail = data + ACTION_RAW_ENCAP_MAX_DATA;
10580         for (i = n - 1 ; i >= 0; --i) {
10581                 const struct rte_flow_item_gtp *gtp;
10582                 const struct rte_flow_item_geneve_opt *opt;
10583
10584                 item = in->args.vc.pattern + i;
10585                 if (item->spec == NULL)
10586                         item->spec = flow_item_default_mask(item);
10587                 switch (item->type) {
10588                 case RTE_FLOW_ITEM_TYPE_ETH:
10589                         size = sizeof(struct rte_ether_hdr);
10590                         break;
10591                 case RTE_FLOW_ITEM_TYPE_VLAN:
10592                         size = sizeof(struct rte_vlan_hdr);
10593                         proto = RTE_ETHER_TYPE_VLAN;
10594                         break;
10595                 case RTE_FLOW_ITEM_TYPE_IPV4:
10596                         size = sizeof(struct rte_ipv4_hdr);
10597                         proto = RTE_ETHER_TYPE_IPV4;
10598                         break;
10599                 case RTE_FLOW_ITEM_TYPE_IPV6:
10600                         size = sizeof(struct rte_ipv6_hdr);
10601                         proto = RTE_ETHER_TYPE_IPV6;
10602                         break;
10603                 case RTE_FLOW_ITEM_TYPE_UDP:
10604                         size = sizeof(struct rte_udp_hdr);
10605                         proto = 0x11;
10606                         break;
10607                 case RTE_FLOW_ITEM_TYPE_TCP:
10608                         size = sizeof(struct rte_tcp_hdr);
10609                         proto = 0x06;
10610                         break;
10611                 case RTE_FLOW_ITEM_TYPE_VXLAN:
10612                         size = sizeof(struct rte_vxlan_hdr);
10613                         break;
10614                 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
10615                         size = sizeof(struct rte_vxlan_gpe_hdr);
10616                         break;
10617                 case RTE_FLOW_ITEM_TYPE_GRE:
10618                         size = sizeof(struct rte_gre_hdr);
10619                         proto = 0x2F;
10620                         break;
10621                 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
10622                         size = sizeof(rte_be32_t);
10623                         proto = 0x0;
10624                         break;
10625                 case RTE_FLOW_ITEM_TYPE_MPLS:
10626                         size = sizeof(struct rte_mpls_hdr);
10627                         proto = 0x0;
10628                         break;
10629                 case RTE_FLOW_ITEM_TYPE_NVGRE:
10630                         size = sizeof(struct rte_flow_item_nvgre);
10631                         proto = 0x2F;
10632                         break;
10633                 case RTE_FLOW_ITEM_TYPE_GENEVE:
10634                         size = sizeof(struct rte_geneve_hdr);
10635                         break;
10636                 case RTE_FLOW_ITEM_TYPE_GENEVE_OPT:
10637                         opt = (const struct rte_flow_item_geneve_opt *)
10638                                                                 item->spec;
10639                         size = offsetof(struct rte_flow_item_geneve_opt, data);
10640                         if (opt->option_len && opt->data) {
10641                                 *total_size += opt->option_len *
10642                                                sizeof(uint32_t);
10643                                 rte_memcpy(data_tail - (*total_size),
10644                                            opt->data,
10645                                            opt->option_len * sizeof(uint32_t));
10646                         }
10647                         break;
10648                 case RTE_FLOW_ITEM_TYPE_L2TPV3OIP:
10649                         size = sizeof(rte_be32_t);
10650                         proto = 0x73;
10651                         break;
10652                 case RTE_FLOW_ITEM_TYPE_ESP:
10653                         size = sizeof(struct rte_esp_hdr);
10654                         proto = 0x32;
10655                         break;
10656                 case RTE_FLOW_ITEM_TYPE_AH:
10657                         size = sizeof(struct rte_flow_item_ah);
10658                         proto = 0x33;
10659                         break;
10660                 case RTE_FLOW_ITEM_TYPE_GTP:
10661                         if (gtp_psc < 0) {
10662                                 size = sizeof(struct rte_gtp_hdr);
10663                                 break;
10664                         }
10665                         if (gtp_psc != i + 1) {
10666                                 fprintf(stderr,
10667                                         "Error - GTP PSC does not follow GTP\n");
10668                                 goto error;
10669                         }
10670                         gtp = item->spec;
10671                         if ((gtp->v_pt_rsv_flags & 0x07) != 0x04) {
10672                                 /* Only E flag should be set. */
10673                                 fprintf(stderr,
10674                                         "Error - GTP unsupported flags\n");
10675                                 goto error;
10676                         } else {
10677                                 struct rte_gtp_hdr_ext_word ext_word = {
10678                                         .next_ext = 0x85
10679                                 };
10680
10681                                 /* We have to add GTP header extra word. */
10682                                 *total_size += sizeof(ext_word);
10683                                 rte_memcpy(data_tail - (*total_size),
10684                                            &ext_word, sizeof(ext_word));
10685                         }
10686                         size = sizeof(struct rte_gtp_hdr);
10687                         break;
10688                 case RTE_FLOW_ITEM_TYPE_GTP_PSC:
10689                         if (gtp_psc >= 0) {
10690                                 fprintf(stderr,
10691                                         "Error - Multiple GTP PSC items\n");
10692                                 goto error;
10693                         } else {
10694                                 const struct rte_flow_item_gtp_psc
10695                                         *opt = item->spec;
10696                                 struct {
10697                                         uint8_t len;
10698                                         uint8_t pdu_type:4;
10699                                         uint8_t qfi:6;
10700                                         uint8_t next;
10701                                 } psc;
10702                                 psc.len = sizeof(psc) / 4;
10703                                 psc.pdu_type = opt->hdr.type;
10704                                 psc.qfi = opt->hdr.qfi;
10705                                 psc.next = 0;
10706                                 *total_size += sizeof(psc);
10707                                 rte_memcpy(data_tail - (*total_size),
10708                                            &psc, sizeof(psc));
10709                                 gtp_psc = i;
10710                                 size = 0;
10711                         }
10712                         break;
10713                 case RTE_FLOW_ITEM_TYPE_PFCP:
10714                         size = sizeof(struct rte_flow_item_pfcp);
10715                         break;
10716                 case RTE_FLOW_ITEM_TYPE_FLEX:
10717                         size = item->spec ?
10718                                 ((const struct rte_flow_item_flex *)
10719                                 item->spec)->length : 0;
10720                         break;
10721                 case RTE_FLOW_ITEM_TYPE_GRE_OPTION:
10722                         size = 0;
10723                         if (item->spec) {
10724                                 const struct rte_flow_item_gre_opt
10725                                         *opt = item->spec;
10726                                 if (opt->checksum_rsvd.checksum) {
10727                                         *total_size +=
10728                                                 sizeof(opt->checksum_rsvd);
10729                                         rte_memcpy(data_tail - (*total_size),
10730                                                    &opt->checksum_rsvd,
10731                                                    sizeof(opt->checksum_rsvd));
10732                                 }
10733                                 if (opt->key.key) {
10734                                         *total_size += sizeof(opt->key.key);
10735                                         rte_memcpy(data_tail - (*total_size),
10736                                                    &opt->key.key,
10737                                                    sizeof(opt->key.key));
10738                                 }
10739                                 if (opt->sequence.sequence) {
10740                                         *total_size += sizeof(opt->sequence.sequence);
10741                                         rte_memcpy(data_tail - (*total_size),
10742                                                    &opt->sequence.sequence,
10743                                                    sizeof(opt->sequence.sequence));
10744                                 }
10745                         }
10746                         proto = 0x2F;
10747                         break;
10748                 default:
10749                         fprintf(stderr, "Error - Not supported item\n");
10750                         goto error;
10751                 }
10752                 *total_size += size;
10753                 rte_memcpy(data_tail - (*total_size), item->spec, size);
10754                 /* update some fields which cannot be set by cmdline */
10755                 update_fields((data_tail - (*total_size)), item,
10756                               upper_layer);
10757                 upper_layer = proto;
10758         }
10759         if (verbose_level & 0x1)
10760                 printf("total data size is %zu\n", (*total_size));
10761         RTE_ASSERT((*total_size) <= ACTION_RAW_ENCAP_MAX_DATA);
10762         memmove(data, (data_tail - (*total_size)), *total_size);
10763         return;
10764
10765 error:
10766         *total_size = 0;
10767         memset(data, 0x00, ACTION_RAW_ENCAP_MAX_DATA);
10768 }
10769
10770 /** Populate help strings for current token (cmdline API). */
10771 static int
10772 cmd_set_raw_get_help(cmdline_parse_token_hdr_t *hdr, char *dst,
10773                      unsigned int size)
10774 {
10775         struct context *ctx = &cmd_flow_context;
10776         const struct token *token = &token_list[ctx->prev];
10777
10778         (void)hdr;
10779         if (!size)
10780                 return -1;
10781         /* Set token type and update global help with details. */
10782         snprintf(dst, size, "%s", (token->type ? token->type : "TOKEN"));
10783         if (token->help)
10784                 cmd_set_raw.help_str = token->help;
10785         else
10786                 cmd_set_raw.help_str = token->name;
10787         return 0;
10788 }
10789
10790 /** Token definition template (cmdline API). */
10791 static struct cmdline_token_hdr cmd_set_raw_token_hdr = {
10792         .ops = &(struct cmdline_token_ops){
10793                 .parse = cmd_flow_parse,
10794                 .complete_get_nb = cmd_flow_complete_get_nb,
10795                 .complete_get_elt = cmd_flow_complete_get_elt,
10796                 .get_help = cmd_set_raw_get_help,
10797         },
10798         .offset = 0,
10799 };
10800
10801 /** Populate the next dynamic token. */
10802 static void
10803 cmd_set_raw_tok(cmdline_parse_token_hdr_t **hdr,
10804              cmdline_parse_token_hdr_t **hdr_inst)
10805 {
10806         struct context *ctx = &cmd_flow_context;
10807
10808         /* Always reinitialize context before requesting the first token. */
10809         if (!(hdr_inst - cmd_set_raw.tokens)) {
10810                 cmd_flow_context_init(ctx);
10811                 ctx->curr = START_SET;
10812         }
10813         /* Return NULL when no more tokens are expected. */
10814         if (!ctx->next_num && (ctx->curr != START_SET)) {
10815                 *hdr = NULL;
10816                 return;
10817         }
10818         /* Determine if command should end here. */
10819         if (ctx->eol && ctx->last && ctx->next_num) {
10820                 const enum index *list = ctx->next[ctx->next_num - 1];
10821                 int i;
10822
10823                 for (i = 0; list[i]; ++i) {
10824                         if (list[i] != END)
10825                                 continue;
10826                         *hdr = NULL;
10827                         return;
10828                 }
10829         }
10830         *hdr = &cmd_set_raw_token_hdr;
10831 }
10832
10833 /** Token generator and output processing callback (cmdline API). */
10834 static void
10835 cmd_set_raw_cb(void *arg0, struct cmdline *cl, void *arg2)
10836 {
10837         if (cl == NULL)
10838                 cmd_set_raw_tok(arg0, arg2);
10839         else
10840                 cmd_set_raw_parsed(arg0);
10841 }
10842
10843 /** Global parser instance (cmdline API). */
10844 cmdline_parse_inst_t cmd_set_raw = {
10845         .f = cmd_set_raw_cb,
10846         .data = NULL, /**< Unused. */
10847         .help_str = NULL, /**< Updated by cmd_flow_get_help(). */
10848         .tokens = {
10849                 NULL,
10850         }, /**< Tokens are returned by cmd_flow_tok(). */
10851 };
10852
10853 /* *** display raw_encap/raw_decap buf */
10854 struct cmd_show_set_raw_result {
10855         cmdline_fixed_string_t cmd_show;
10856         cmdline_fixed_string_t cmd_what;
10857         cmdline_fixed_string_t cmd_all;
10858         uint16_t cmd_index;
10859 };
10860
10861 static void
10862 cmd_show_set_raw_parsed(void *parsed_result, struct cmdline *cl, void *data)
10863 {
10864         struct cmd_show_set_raw_result *res = parsed_result;
10865         uint16_t index = res->cmd_index;
10866         uint8_t all = 0;
10867         uint8_t *raw_data = NULL;
10868         size_t raw_size = 0;
10869         char title[16] = {0};
10870
10871         RTE_SET_USED(cl);
10872         RTE_SET_USED(data);
10873         if (!strcmp(res->cmd_all, "all")) {
10874                 all = 1;
10875                 index = 0;
10876         } else if (index >= RAW_ENCAP_CONFS_MAX_NUM) {
10877                 fprintf(stderr, "index should be 0-%u\n",
10878                         RAW_ENCAP_CONFS_MAX_NUM - 1);
10879                 return;
10880         }
10881         do {
10882                 if (!strcmp(res->cmd_what, "raw_encap")) {
10883                         raw_data = (uint8_t *)&raw_encap_confs[index].data;
10884                         raw_size = raw_encap_confs[index].size;
10885                         snprintf(title, 16, "\nindex: %u", index);
10886                         rte_hexdump(stdout, title, raw_data, raw_size);
10887                 } else {
10888                         raw_data = (uint8_t *)&raw_decap_confs[index].data;
10889                         raw_size = raw_decap_confs[index].size;
10890                         snprintf(title, 16, "\nindex: %u", index);
10891                         rte_hexdump(stdout, title, raw_data, raw_size);
10892                 }
10893         } while (all && ++index < RAW_ENCAP_CONFS_MAX_NUM);
10894 }
10895
10896 cmdline_parse_token_string_t cmd_show_set_raw_cmd_show =
10897         TOKEN_STRING_INITIALIZER(struct cmd_show_set_raw_result,
10898                         cmd_show, "show");
10899 cmdline_parse_token_string_t cmd_show_set_raw_cmd_what =
10900         TOKEN_STRING_INITIALIZER(struct cmd_show_set_raw_result,
10901                         cmd_what, "raw_encap#raw_decap");
10902 cmdline_parse_token_num_t cmd_show_set_raw_cmd_index =
10903         TOKEN_NUM_INITIALIZER(struct cmd_show_set_raw_result,
10904                         cmd_index, RTE_UINT16);
10905 cmdline_parse_token_string_t cmd_show_set_raw_cmd_all =
10906         TOKEN_STRING_INITIALIZER(struct cmd_show_set_raw_result,
10907                         cmd_all, "all");
10908 cmdline_parse_inst_t cmd_show_set_raw = {
10909         .f = cmd_show_set_raw_parsed,
10910         .data = NULL,
10911         .help_str = "show <raw_encap|raw_decap> <index>",
10912         .tokens = {
10913                 (void *)&cmd_show_set_raw_cmd_show,
10914                 (void *)&cmd_show_set_raw_cmd_what,
10915                 (void *)&cmd_show_set_raw_cmd_index,
10916                 NULL,
10917         },
10918 };
10919 cmdline_parse_inst_t cmd_show_set_raw_all = {
10920         .f = cmd_show_set_raw_parsed,
10921         .data = NULL,
10922         .help_str = "show <raw_encap|raw_decap> all",
10923         .tokens = {
10924                 (void *)&cmd_show_set_raw_cmd_show,
10925                 (void *)&cmd_show_set_raw_cmd_what,
10926                 (void *)&cmd_show_set_raw_cmd_all,
10927                 NULL,
10928         },
10929 };