FD.io VPP  v21.06-3-gbb25fbf28
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;
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 */
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 */
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 
184 vlib_parse_eval (u8 * input);
185 
187 
188 /* FIXME need these to be global? */
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  */
vlib_parse_main
vlib_parse_main_t vlib_parse_main
Definition: parse.h:177
vlib.h
vlib_parse_main::parse_graph
vlib_parse_graph_t * parse_graph
Definition: parse.h:141
vlib_parse_main_t
struct vlib_parse_main vlib_parse_main_t
vlib_parse_item_t::help_index
u32 help_index
Definition: parse.h:49
vlib_parse_main
Definition: parse.h:131
number_match
vlib_parse_match_function_t number_match
Definition: parse.h:190
vlib_parse_type
Definition: parse.h:102
mhash.h
vlib_parse_item_t::type
u32 type
Definition: parse.h:43
vlib_parse_main::parse_items
vlib_parse_item_t * parse_items
Definition: parse.h:135
vlib_parse_type::match_function
vlib_parse_match_function_t * match_function
Definition: parse.h:109
vlib_parse_type::value_cleanup_function
vlib_parse_value_cleanup_function_t * value_cleanup_function
Definition: parse.h:112
foreach_parse_match_type
#define foreach_parse_match_type
Definition: parse.h:75
parse_registration_t::initializer
char * initializer
Definition: parse.h:124
vlib_parse_graph_t::peer
u32 peer
Definition: parse.h:68
vlib_parse_type::name
char * name
Definition: parse.h:106
vlib_parse_item_t::as_uword
uword as_uword
Definition: parse.h:56
mhash_t
Definition: mhash.h:46
vlib_parse_main::parse_value
vlib_parse_value_t * parse_value
Definition: parse.h:156
vlib_parse_main::parse_registrations
parse_registration_t ** parse_registrations
Definition: parse.h:162
vlib_parse_main::parse_type_by_name_hash
uword * parse_type_by_name_hash
Definition: parse.h:152
u16
unsigned short u16
Definition: types.h:57
vlib_parse_main::parse_types
vlib_parse_type_t * parse_types
Definition: parse.h:150
vlib_parse_type_t
struct vlib_parse_type vlib_parse_type_t
vlib_parse_main::lex_main
vlib_lex_main_t * lex_main
Definition: parse.h:171
lex.h
rule_match
vlib_parse_match_function_t rule_match
Definition: parse.h:189
vlib_parse_type::rule_index
u32 rule_index
Definition: parse.h:118
vlib_lex_main_t
Definition: lex.h:83
vlib_parse_eval_function_t
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
uword
u64 uword
Definition: types.h:112
vlib_parse_main::parse_item_hash
mhash_t parse_item_hash
Definition: parse.h:137
vlib_parse_match_function_t
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_parse_graph_t::deeper
u32 deeper
Definition: parse.h:72
vlib_parse_main::current_token_index
u32 current_token_index
Definition: parse.h:168
format_function_t
u8 *() format_function_t(u8 *s, va_list *args)
Definition: format.h:48
vlib_parse_main::vlib_main
vlib_main_t * vlib_main
Definition: parse.h:173
u64
unsigned long u64
Definition: types.h:89
vlib_parse_value_cleanup_function_t
void() vlib_parse_value_cleanup_function_t(vlib_parse_value_t *)
Definition: parse.h:99
u32
unsigned int u32
Definition: types.h:88
vlib_parse_type::format_value
format_function_t * format_value
Definition: parse.h:115
parse_registration_t::rule_length
int rule_length
Definition: parse.h:128
vlib_parse_item_t::as_pointer
void * as_pointer
Definition: parse.h:54
as_u64
u64 as_u64
Definition: bihash_doc.h:63
value
u8 value
Definition: qos.api:54
vlib_parse_graph_t::item
u32 item
Definition: parse.h:64
vlib_main_t
Definition: main.h:102
u8
unsigned char u8
Definition: types.h:56
vlib_parse_main::register_input
u8 * register_input
Definition: parse.h:146
vlib_parse_main::tokens
vlib_lex_token_t * tokens
Definition: parse.h:166
vlib_parse_graph_t
Definition: parse.h:60
vlib_parse_match_t
vlib_parse_match_t
Definition: parse.h:85
word
i64 word
Definition: types.h:111
vlib_parse_item_t
Definition: parse.h:40
vlib_parse_main::match_items
u32 * match_items
Definition: parse.h:158
format_vlib_parse_value
format_function_t format_vlib_parse_value
Definition: parse.h:186
vlib_parse_eval
vlib_parse_match_t vlib_parse_eval(u8 *input)
vlib_lex_token_t
Definition: lex.h:71
eof_match
vlib_parse_match_function_t eof_match
Definition: parse.h:189
parse_registration_t::eof_match
void * eof_match
Definition: parse.h:126
vlib_parse_item_t::origin
u32 origin
Definition: parse.h:46
vlib_parse_main::root_index
u32 root_index
Definition: parse.h:143
type
vl_api_fib_path_type_t type
Definition: fib_types.api:123
parse_registration_t
Definition: parse.h:121
word_match
vlib_parse_match_function_t word_match
Definition: parse.h:189