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