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