FD.io VPP  v16.06
Vector Packet Processing
parse.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef included_vlib_parse_h
16 #define included_vlib_parse_h
17 
18 #include <vlib/vlib.h>
19 #include <vlib/lex.h>
20 #include <vppinfra/mhash.h>
21 
22 typedef struct {
23  /* Word aligned value. */
24  union {
25  u8 as_u8[32 - 1 * sizeof (u16)];
26  void * as_pointer;
27  uword as_uword;
28  word as_word;
29  u64 as_u64;
30  } value;
31 
32  /* 16 bit type at end so that 30 bytes of value are aligned. */
33  u16 type;
34 } __attribute ((packed)) vlib_parse_value_t;
35 
36 /* Instance of a type. */
37 typedef struct {
39 
41 
43 
44  union {
45  void * as_pointer;
47  } value;
49 
50 typedef struct {
51  /* Index of item for this node. */
53 
54  /* Graph index of peer (sibling) node (linked list of peers). */
56 
57  /* Graph index of deeper (child) node (linked list of children). */
60 
61 #define foreach_parse_match_type \
62  _(MATCH_DONE) \
63  _(MATCH_RULE) \
64  _(MATCH_FAIL) \
65  _(MATCH_FULL) \
66  _(MATCH_VALUE) \
67  _(MATCH_PARTIAL) \
68  _(MATCH_AMBIGUOUS) \
69  _(MATCH_EVAL_FAIL)
70 
71 typedef enum {
72 #define _(a) VLIB_PARSE_##a,
74 #undef _
76 
77 struct vlib_parse_type;
78 struct vlib_parse_main;
79 
81  (struct vlib_parse_main *,
82  struct vlib_parse_type *,
84  vlib_parse_value_t *);
85 typedef void (vlib_parse_value_cleanup_function_t) (vlib_parse_value_t *);
86 
87 typedef struct vlib_parse_type {
88  /* Type name. */
89  char * name;
90 
92 
94 
96 
99 
100 typedef struct {
101  char *initializer;
102  void * eof_match;
105 
106 typedef struct vlib_parse_main {
107  /* (type, origin, help, value) tuples */
110 
111  /* (item, peer, deeper) tuples */
114 
116 
117  /* parser types */
120 
121  /* Vector of MATCH_VALUEs */
122  vlib_parse_value_t * parse_value;
124 
125  /* Parse registrations */
127 
128  /* Token vector */
129  vlib_lex_token_t *tokens;
131 
135 
137 
141  vlib_parse_value_t *);
142 
143 vlib_parse_match_t vlib_parse_eval (u8 * input);
144 
146 
147 /* FIXME need these to be global? */
149 
150 #define _PARSE_REGISTRATION_DATA(x) \
151 VLIB_ELF_SECTION_DATA(x##_registration,parse_registration_t,parse_registrations)
152 
153 #define PARSE_INIT(x, s, e) \
154 static _PARSE_REGISTRATION_DATA(x) = { \
155  .initializer = s, \
156  .eof_match = e, \
157 };
158 
159 #define _PARSE_TYPE_REGISTRATION_DATA(x) \
160 VLIB_ELF_SECTION_DATA(x##_type_registration,vlib_parse_type_t, \
161 parse_type_registrations)
162 
163 #define PARSE_TYPE_INIT(n, m, c, f) \
164 static _PARSE_TYPE_REGISTRATION_DATA(n) = { \
165  .name = #n, \
166  .match_function = m, \
167  .value_cleanup_function = c, \
168  .format_value = f, \
169 };
170 
171 #endif /* included_vlib_parse_h */
struct vlib_parse_main vlib_parse_main_t
char * initializer
Definition: parse.h:101
Definition: mhash.h:46
u8 * register_input
Definition: parse.h:115
void * as_pointer
Definition: parse.h:45
vlib_parse_match_function_t eof_match
Definition: parse.h:148
mhash_t parse_item_hash
Definition: parse.h:109
static void(BVT(clib_bihash)*h, BVT(clib_bihash_value)*v)
bad routing header type(not 4)") sr_error (NO_MORE_SEGMENTS
void * eof_match
Definition: parse.h:102
uword as_uword
Definition: parse.h:46
vlib_parse_main_t vlib_parse_main
Definition: parse.h:136
vlib_parse_graph_t * parse_graph
Definition: parse.h:112
vlib_main_t * vlib_main
Definition: parse.h:133
vlib_lex_main_t * lex_main
Definition: parse.h:132
void( vlib_parse_value_cleanup_function_t)(vlib_parse_value_t *)
Definition: parse.h:85
u32 current_token_index
Definition: parse.h:130
vlib_parse_match_function_t * match_function
Definition: parse.h:91
vlib_parse_value_t * parse_value
Definition: parse.h:122
vlib_parse_type_t * parse_types
Definition: parse.h:118
vlib_parse_item_t * parse_items
Definition: parse.h:108
vlib_parse_match_t vlib_parse_eval(u8 *input)
Definition: parse.c:395
unsigned long u64
Definition: types.h:89
u32 help_index
Definition: parse.h:42
#define foreach_parse_match_type
Definition: parse.h:61
vlib_parse_match_function_t number_match
Definition: parse.h:148
char * name
Definition: parse.h:89
format_function_t format_vlib_parse_value
Definition: parse.h:145
vlib_parse_match_t( vlib_parse_match_function_t)(struct vlib_parse_main *, struct vlib_parse_type *, vlib_lex_token_t *, vlib_parse_value_t *)
Definition: parse.h:81
vlib_parse_match_function_t rule_match
Definition: parse.h:148
vlib_parse_match_function_t word_match
Definition: parse.h:148
vlib_parse_value_cleanup_function_t * value_cleanup_function
Definition: parse.h:93
u32 * match_items
Definition: parse.h:123
unsigned int u32
Definition: types.h:88
struct vlib_parse_type vlib_parse_type_t
parse_registration_t ** parse_registrations
Definition: parse.h:126
u8 *( format_function_t)(u8 *s, va_list *args)
Definition: format.h:48
u64 uword
Definition: types.h:112
format_function_t * format_value
Definition: parse.h:95
uword * parse_type_by_name_hash
Definition: parse.h:119
unsigned short u16
Definition: types.h:57
u32 rule_index
Definition: parse.h:97
i64 word
Definition: types.h:111
unsigned char u8
Definition: types.h:56
vlib_parse_match_t( vlib_parse_eval_function_t)(vlib_parse_main_t *, vlib_parse_item_t *, vlib_parse_value_t *)
Definition: parse.h:139
vlib_lex_token_t * tokens
Definition: parse.h:129
u32 root_index
Definition: parse.h:113
vlib_parse_match_t
Definition: parse.h:71