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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
15 #ifndef included_vlib_parse_h
16 #define included_vlib_parse_h
18 #include <vlib/vlib.h>
20 #include <vppinfra/mhash.h>
24 /* Word aligned value. */
27 u8 as_u8[32 - 1 * sizeof (u16)];
34 /* 16 bit type at end so that 30 bytes of value are aligned. */
36 } __attribute ((packed))
39 /* Instance of a type. */
62 /* Index of item for this node. */
66 /* Graph index of peer (sibling) node (linked list of peers). */
70 /* Graph index of deeper (child) node (linked list of children). */
75 #define foreach_parse_match_type \
87 #define _(a) VLIB_PARSE_##a,
88 foreach_parse_match_type
92 struct vlib_parse_type;
93 struct vlib_parse_main;
96 vlib_parse_match_t (vlib_parse_match_function_t)
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
102 typedef struct vlib_parse_type
108 vlib_parse_match_function_t *
111 vlib_parse_value_cleanup_function_t *
112 value_cleanup_function;
129 } parse_registration_t;
131 typedef struct vlib_parse_main
133 /* (type, origin, help, value) tuples */
139 /* (item, peer, deeper) tuples */
152 parse_type_by_name_hash;
154 /* Vector of MATCH_VALUEs */
160 /* Parse registrations */
161 parse_registration_t **
180 vlib_parse_match_t (vlib_parse_eval_function_t)
181 (vlib_parse_main_t *, vlib_parse_item_t *, vlib_parse_value_t *);
184 vlib_parse_eval (u8 * input);
186 format_function_t format_vlib_parse_value;
188 /* FIXME need these to be global? */
189 vlib_parse_match_function_t rule_match, eof_match, word_match,
192 #define _PARSE_REGISTRATION_DATA(x) \
193 VLIB_ELF_SECTION_DATA(x##_registration,parse_registration_t,parse_registrations)
195 #define PARSE_INIT(x, s, e) \
196 static _PARSE_REGISTRATION_DATA(x) = { \
201 #define _PARSE_TYPE_REGISTRATION_DATA(x) \
202 VLIB_ELF_SECTION_DATA(x##_type_registration,vlib_parse_type_t, \
203 parse_type_registrations)
205 #define PARSE_TYPE_INIT(n, m, c, f) \
206 static _PARSE_TYPE_REGISTRATION_DATA(n) = { \
208 .match_function = m, \
209 .value_cleanup_function = c, \
213 #endif /* included_vlib_parse_h */
216 * fd.io coding-style-patch-verification: ON
219 * eval: (c-set-style "gnu")