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