FD.io VPP  v20.01-48-g3e0dafb74
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 {
24  /* Word aligned value. */
25  union
26  {
27  u8 as_u8[32 - 1 * sizeof (u16)];
28  void *as_pointer;
29  uword as_uword;
30  word as_word;
31  u64 as_u64;
32  } value;
33 
34  /* 16 bit type at end so that 30 bytes of value are aligned. */
35  u16 type;
36 } __attribute ((packed))
37  vlib_parse_value_t;
38 
39 /* Instance of a type. */
40  typedef struct
41  {
42  u32
44 
45  u32
47 
48  u32
50 
51  union
52  {
53  void *
55  uword
57  } value;
58  } vlib_parse_item_t;
59 
60  typedef struct
61  {
62  /* Index of item for this node. */
63  u32
65 
66  /* Graph index of peer (sibling) node (linked list of peers). */
67  u32
69 
70  /* Graph index of deeper (child) node (linked list of children). */
71  u32
74 
75 #define foreach_parse_match_type \
76  _(MATCH_DONE) \
77  _(MATCH_RULE) \
78  _(MATCH_FAIL) \
79  _(MATCH_FULL) \
80  _(MATCH_VALUE) \
81  _(MATCH_PARTIAL) \
82  _(MATCH_AMBIGUOUS) \
83  _(MATCH_EVAL_FAIL)
84 
85  typedef enum
86  {
87 #define _(a) VLIB_PARSE_##a,
89 #undef _
91 
92  struct vlib_parse_type;
93  struct vlib_parse_main;
94 
95  typedef
97  (struct vlib_parse_main *,
98  struct vlib_parse_type *, vlib_lex_token_t *, vlib_parse_value_t *);
99  typedef void (vlib_parse_value_cleanup_function_t) (vlib_parse_value_t
100  *);
101 
102  typedef struct vlib_parse_type
103  {
104  /* Type name. */
105  char *
107 
110 
113 
116 
117  u32
120 
121  typedef struct
122  {
123  char *
125  void *
127  int
130 
131  typedef struct vlib_parse_main
132  {
133  /* (type, origin, help, value) tuples */
134  vlib_parse_item_t *
136  mhash_t
138 
139  /* (item, peer, deeper) tuples */
142  u32
144 
145  u8 *
147 
148  /* parser types */
151  uword *
153 
154  /* Vector of MATCH_VALUEs */
155  vlib_parse_value_t *
157  u32 *
159 
160  /* Parse registrations */
163 
164  /* Token vector */
165  vlib_lex_token_t *
167  u32
169 
172  vlib_main_t *
175 
178 
179  typedef
181  (vlib_parse_main_t *, vlib_parse_item_t *, vlib_parse_value_t *);
182 
183 vlib_parse_match_t
184 vlib_parse_eval (u8 * input);
185 
187 
188 /* FIXME need these to be global? */
190  number_match;
191 
192 #define _PARSE_REGISTRATION_DATA(x) \
193 VLIB_ELF_SECTION_DATA(x##_registration,parse_registration_t,parse_registrations)
194 
195 #define PARSE_INIT(x, s, e) \
196 static _PARSE_REGISTRATION_DATA(x) = { \
197  .initializer = s, \
198  .eof_match = e, \
199 };
200 
201 #define _PARSE_TYPE_REGISTRATION_DATA(x) \
202 VLIB_ELF_SECTION_DATA(x##_type_registration,vlib_parse_type_t, \
203 parse_type_registrations)
204 
205 #define PARSE_TYPE_INIT(n, m, c, f) \
206 static _PARSE_TYPE_REGISTRATION_DATA(n) = { \
207  .name = #n, \
208  .match_function = m, \
209  .value_cleanup_function = c, \
210  .format_value = f, \
211 };
212 
213 #endif /* included_vlib_parse_h */
214 
215 /*
216  * fd.io coding-style-patch-verification: ON
217  *
218  * Local Variables:
219  * eval: (c-set-style "gnu")
220  * End:
221  */
struct vlib_parse_main vlib_parse_main_t
char * initializer
Definition: parse.h:124
Definition: mhash.h:46
u8 * register_input
Definition: parse.h:146
void * as_pointer
Definition: parse.h:54
vlib_parse_match_function_t eof_match
Definition: parse.h:189
mhash_t parse_item_hash
Definition: parse.h:137
void * eof_match
Definition: parse.h:126
uword as_uword
Definition: parse.h:56
u64 as_u64
Definition: bihash_doc.h:63
unsigned long u64
Definition: types.h:89
vlib_parse_main_t vlib_parse_main
Definition: parse.h:177
vlib_parse_graph_t * parse_graph
Definition: parse.h:141
vlib_main_t * vlib_main
Definition: parse.h:173
vlib_lex_main_t * lex_main
Definition: parse.h:171
unsigned char u8
Definition: types.h:56
u32 current_token_index
Definition: parse.h:168
u8 *() format_function_t(u8 *s, va_list *args)
Definition: format.h:48
vlib_parse_match_function_t * match_function
Definition: parse.h:109
vlib_parse_match_t() vlib_parse_eval_function_t(vlib_parse_main_t *, vlib_parse_item_t *, vlib_parse_value_t *)
Definition: parse.h:181
vlib_parse_value_t * parse_value
Definition: parse.h:156
i64 word
Definition: types.h:111
vlib_parse_type_t * parse_types
Definition: parse.h:150
vlib_parse_item_t * parse_items
Definition: parse.h:135
vlib_parse_match_t vlib_parse_eval(u8 *input)
unsigned int u32
Definition: types.h:88
u32 help_index
Definition: parse.h:49
vl_api_fib_path_type_t type
Definition: fib_types.api:123
#define foreach_parse_match_type
Definition: parse.h:75
vlib_parse_match_function_t number_match
Definition: parse.h:189
unsigned short u16
Definition: types.h:57
char * name
Definition: parse.h:106
format_function_t format_vlib_parse_value
Definition: parse.h:186
vlib_parse_match_function_t rule_match
Definition: parse.h:189
void() vlib_parse_value_cleanup_function_t(vlib_parse_value_t *)
Definition: parse.h:99
vlib_parse_match_function_t word_match
Definition: parse.h:189
vlib_parse_value_cleanup_function_t * value_cleanup_function
Definition: parse.h:112
u32 * match_items
Definition: parse.h:158
u8 value
Definition: qos.api:54
struct vlib_parse_type vlib_parse_type_t
parse_registration_t ** parse_registrations
Definition: parse.h:162
format_function_t * format_value
Definition: parse.h:115
uword * parse_type_by_name_hash
Definition: parse.h:152
u32 rule_index
Definition: parse.h:118
u64 uword
Definition: types.h:112
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:97
vlib_lex_token_t * tokens
Definition: parse.h:166
u32 root_index
Definition: parse.h:143
vlib_parse_match_t
Definition: parse.h:85