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