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