]> git.ipfire.org Git - thirdparty/dhcp.git/blob - keama/keama.h
[#64,!35] Restored work
[thirdparty/dhcp.git] / keama / keama.h
1 /*
2 * Copyright (c) 2017, 2018 by Internet Systems Consortium, Inc. ("ISC")
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
14 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 *
16 * Internet Systems Consortium, Inc.
17 * 950 Charter Street
18 * Redwood City, CA 94063
19 * <info@isc.org>
20 * https://www.isc.org/
21 *
22 */
23
24 #ifndef EOL
25 #define EOL '\n'
26 #endif
27
28 #include "data.h"
29 #include "dhctoken.h"
30
31 #include <time.h>
32
33 /* Resolution of FQDNs into IPv4 addresses */
34 enum resolve {
35 perform = 0, /* resolve */
36 fatal, /* raise a fatal error */
37 pass /* pass the string wth a warning */
38 } resolve;
39
40 /* From includes/dhcp.h */
41
42 #define HTYPE_ETHER 1
43 #define HTYPE_IEEE802 6
44 #define HTYPE_FDDI 8
45
46 #define DHO_DHCP_SERVER_IDENTIFIER 54
47 #define DHO_VENDOR_CLASS_IDENTIFIER 60
48 #define DHO_USER_CLASS 77
49 #define DHO_VIVSO_SUBOPTIONS 125
50
51 /* From includes/dhcp6.h */
52 #define D6O_VENDOR_OPTS 17
53 #define MAX_V6RELAY_HOPS 32
54
55 /* From includes/dhcpd.h */
56
57 extern int local_family;
58
59 /* A parsing context. */
60
61 TAILQ_HEAD(parses, parse) parses;
62
63 struct parse {
64 int lexline;
65 int lexchar;
66 char *token_line;
67 char *prev_line;
68 char *cur_line;
69 const char *tlname;
70 int eol_token;
71
72 /*
73 * In order to give nice output when we have a parsing error
74 * in our file, we keep track of where we are in the line so
75 * that we can show the user.
76 *
77 * We need to keep track of two lines, because we can look
78 * ahead, via the "peek" function, to the next line sometimes.
79 *
80 * The "line1" and "line2" variables act as buffers for this
81 * information. The "lpos" variable tells us where we are in the
82 * line.
83 *
84 * When we "put back" a character from the parsing context, we
85 * do not want to have the character appear twice in the error
86 * output. So, we set a flag, the "ugflag", which the
87 * get_char() function uses to check for this condition.
88 */
89 char line1[81];
90 char line2[81];
91 int lpos;
92 int line;
93 int tlpos;
94 int tline;
95 enum dhcp_token token;
96 int ugflag;
97 char *tval;
98 int tlen;
99 char tokbuf[1500];
100
101 int warnings_occurred;
102 int file;
103 char *inbuf;
104 size_t bufix, buflen;
105 size_t bufsiz;
106
107 /*
108 * Additions for the Kea Migration Assistant.
109 */
110 struct element **stack;
111 size_t stack_size;
112 size_t stack_top;
113 size_t issue_counter;
114
115 /* don't save below this */
116 struct comments comments;
117
118 /* TAILQ_NEXT(self) is the saved state */
119 TAILQ_ENTRY(parse) next;
120
121 };
122
123 #define PARAMETER 0
124 #define TOPLEVEL 1
125 #define ROOT_GROUP 2
126 #define HOST_DECL 3
127 #define SHARED_NET_DECL 4
128 #define SUBNET_DECL 5
129 #define CLASS_DECL 6
130 #define GROUP_DECL 7
131 #define POOL_DECL 8
132
133 /* Used as an argument to parse_class_decl() */
134 #define CLASS_TYPE_VENDOR 0
135 #define CLASS_TYPE_USER 1
136 #define CLASS_TYPE_CLASS 2
137 #define CLASS_TYPE_SUBCLASS 3
138
139 #define CLASS_DECL_DELETED 1
140 #define CLASS_DECL_DYNAMIC 2
141 #define CLASS_DECL_STATIC 4
142 #define CLASS_DECL_SUBCLASS 8
143
144 /* Hardware buffer size */
145 #define HARDWARE_ADDR_LEN 20
146
147 /* Expression context */
148
149 enum expression_context {
150 context_any, /* indefinite */
151 context_boolean,
152 context_data,
153 context_numeric,
154 context_dns,
155 context_data_or_numeric, /* indefinite */
156 context_function
157 };
158
159 /* Statements */
160
161 enum statement_op {
162 null_statement,
163 if_statement,
164 add_statement,
165 eval_statement,
166 break_statement,
167 default_option_statement,
168 supersede_option_statement,
169 append_option_statement,
170 prepend_option_statement,
171 send_option_statement,
172 statements_statement,
173 on_statement,
174 switch_statement,
175 case_statement,
176 default_statement,
177 set_statement,
178 unset_statement,
179 let_statement,
180 define_statement,
181 log_statement,
182 return_statement,
183 execute_statement,
184 vendor_opt_statement
185 };
186
187 /* Expression tree structure. */
188
189 enum expr_op {
190 expr_none,
191 expr_match,
192 expr_check,
193 expr_equal,
194 expr_substring,
195 expr_suffix,
196 expr_concat,
197 expr_host_lookup,
198 expr_and,
199 expr_or,
200 expr_not,
201 expr_option,
202 expr_hardware,
203 expr_hw_type, /* derived from expr_hardware */
204 expr_hw_address, /* derived from expr_hardware */
205 expr_packet,
206 expr_const_data,
207 expr_extract_int8,
208 expr_extract_int16,
209 expr_extract_int32,
210 expr_encode_int8,
211 expr_encode_int16,
212 expr_encode_int32,
213 expr_const_int,
214 expr_exists,
215 expr_encapsulate,
216 expr_known,
217 expr_reverse,
218 expr_leased_address,
219 expr_binary_to_ascii,
220 expr_config_option,
221 expr_host_decl_name,
222 expr_pick_first_value,
223 expr_lease_time,
224 expr_dns_transaction,
225 expr_static,
226 expr_ns_add,
227 expr_ns_delete,
228 expr_ns_exists,
229 expr_ns_not_exists,
230 expr_not_equal,
231 expr_null,
232 expr_variable_exists,
233 expr_variable_reference,
234 expr_filename,
235 expr_sname,
236 expr_arg,
237 expr_funcall,
238 expr_function,
239 expr_add,
240 expr_subtract,
241 expr_multiply,
242 expr_divide,
243 expr_remainder,
244 expr_binary_and,
245 expr_binary_or,
246 expr_binary_xor,
247 expr_client_state,
248 expr_ucase,
249 expr_lcase,
250 expr_regex_match,
251 expr_iregex_match,
252 expr_gethostname,
253 expr_v6relay,
254 expr_concat_dclist
255 };
256
257 /* options */
258
259 enum option_status {
260 kea_unknown = 0, /* known only by ISC DHCP */
261 isc_dhcp_unknown = 1, /* known only by Kea */
262 known = 2, /* known by both ISC DHCP and Kea */
263 special = 3, /* requires special processing */
264 dynamic = 4 /* dynamic entry */
265 };
266
267 struct option_def { /* ISC DHCP option definition */
268 const char *name; /* option name */
269 const char *format; /* format string */
270 const char *space; /* space (aka universe) */
271 unsigned code; /* code point */
272 enum option_status status; /* status */
273 };
274
275 struct space_def { /* ISC DHCP space definition */
276 const char *old; /* ISC DHCP space name */
277 const char *name; /* Kea space name */
278 enum option_status status; /* status */
279 };
280
281 struct space {
282 const char *old; /* ISC DHCP space name */
283 const char *name; /* Kea space name */
284 enum option_status status; /* status */
285 struct element *vendor; /* vendor option */
286 TAILQ_ENTRY(space) next; /* next space */
287 };
288
289 struct option {
290 const char *old; /* ISC DHCP option name */
291 const char *name; /* Kea option name */
292 const char *format; /* ISC DHCP format string */
293 const struct space *space; /* space (aka universe) */
294 unsigned code; /* code point */
295 enum option_status status; /* status */
296 TAILQ_ENTRY(option) next; /* next option */
297 };
298
299 /* Kea parse tools */
300 void stackPush(struct parse *cfile, struct element *elem);
301
302 /* From command line */
303 extern char *hook_library_path;
304 extern isc_boolean_t use_isc_lifetimes;
305 extern isc_boolean_t global_hr;
306
307 /* From common/parse.c */
308 void parse_error(struct parse *, const char *, ...)
309 __attribute__((__format__(__printf__,2,3)))
310 __attribute__((noreturn));
311
312 /* conflex.c */
313 struct parse *new_parse(int, char *, size_t, const char *, int);
314 void end_parse(struct parse *);
315 void save_parse_state(struct parse *);
316 void restore_parse_state(struct parse *);
317 enum dhcp_token next_token(const char **, unsigned *, struct parse *);
318 enum dhcp_token peek_token(const char **, unsigned *, struct parse *);
319 enum dhcp_token next_raw_token(const char **, unsigned *, struct parse *);
320 enum dhcp_token peek_raw_token(const char **, unsigned *, struct parse *);
321 /*
322 * Use skip_token when we are skipping a token we have previously
323 * used peek_token on as we know what the result will be in this case.
324 */
325 #define skip_token(a,b,c) ((void) next_token((a),(b),(c)))
326
327 /* confparse.c */
328 size_t conf_file_parse(struct parse *);
329 void read_conf_file(struct parse *, const char *, int);
330 size_t conf_file_subparse(struct parse *, int);
331 isc_boolean_t parse_statement(struct parse *, int, isc_boolean_t);
332 void get_permit(struct parse *, struct element *);
333 void parse_pool_statement(struct parse *, int);
334 void parse_lbrace(struct parse *);
335 void parse_host_declaration(struct parse *);
336 void parse_class_declaration(struct parse *, int);
337 void parse_shared_net_declaration(struct parse *);
338 void parse_subnet_declaration(struct parse *);
339 void parse_subnet6_declaration(struct parse *);
340 void parse_group_declaration(struct parse *);
341 void close_group(struct parse *, struct element *);
342 struct element *parse_fixed_addr_param(struct parse *, enum dhcp_token);
343 void parse_address_range(struct parse *, int, size_t);
344 void parse_address_range6(struct parse *, int, size_t);
345 void parse_prefix6(struct parse *, int, size_t);
346 void parse_fixed_prefix6(struct parse *, size_t);
347 void parse_pool6_statement(struct parse *, int);
348 struct element *parse_allow_deny(struct parse *, int);
349 void parse_server_duid_conf(struct parse *);
350 void parse_directive(struct parse *);
351 void parse_option_space_dir(struct parse *);
352 void parse_option_code_dir(struct parse *, struct option *);
353 void parse_option_status_dir(struct parse *, struct option *, enum dhcp_token);
354 void parse_option_local_dir(struct parse *, struct option *);
355 void parse_option_define_dir(struct parse *, struct option *);
356
357 /* parse.c */
358 void skip_to_semi(struct parse *);
359 void skip_to_rbrace(struct parse *, int);
360 void parse_semi(struct parse *);
361 void parse_string(struct parse *, char **, unsigned *);
362 struct string *parse_host_name(struct parse *);
363 struct string *parse_ip_addr_or_hostname(struct parse *, isc_boolean_t);
364 struct string *parse_ip_addr(struct parse *);
365 struct string *parse_ip6_addr(struct parse *);
366 struct string *parse_ip6_addr_txt(struct parse *);
367 struct element *parse_hardware_param(struct parse *);
368 void parse_lease_time(struct parse *, time_t *);
369 struct string *parse_numeric_aggregate(struct parse *,
370 unsigned char *, unsigned *,
371 int, int, unsigned);
372 void convert_num(struct parse *, unsigned char *, const char *,
373 int, unsigned);
374 struct option *parse_option_name(struct parse *, isc_boolean_t,
375 isc_boolean_t *);
376 void parse_option_space_decl(struct parse *);
377 void parse_option_code_definition(struct parse *, struct option *);
378 void parse_vendor_code_definition(struct parse *, struct option *);
379 struct string *convert_format(const char *, isc_boolean_t *, isc_boolean_t *);
380 struct string *parse_base64(struct parse *);
381 struct string *parse_cshl(struct parse *);
382 struct string *parse_hexa(struct parse *);
383 isc_boolean_t parse_executable_statements(struct element *,
384 struct parse *, isc_boolean_t *,
385 enum expression_context);
386 isc_boolean_t parse_executable_statement(struct element *,
387 struct parse *, isc_boolean_t *,
388 enum expression_context,
389 isc_boolean_t);
390 isc_boolean_t parse_zone(struct element *, struct parse *);
391 isc_boolean_t parse_key(struct element *, struct parse *);
392 isc_boolean_t parse_on_statement(struct element *, struct parse *,
393 isc_boolean_t *);
394 isc_boolean_t parse_switch_statement(struct element *, struct parse *,
395 isc_boolean_t *);
396 isc_boolean_t parse_case_statement(struct element *, struct parse *,
397 isc_boolean_t *, enum expression_context);
398 isc_boolean_t parse_if_statement(struct element *, struct parse *,
399 isc_boolean_t *);
400 isc_boolean_t parse_boolean_expression(struct element *, struct parse *,
401 isc_boolean_t *);
402 /* currently unused */
403 isc_boolean_t parse_boolean(struct parse *);
404 isc_boolean_t parse_data_expression(struct element *, struct parse *,
405 isc_boolean_t *);
406 isc_boolean_t numeric_expression(struct element *, struct parse *,
407 isc_boolean_t *);
408 isc_boolean_t parse_non_binary(struct element *, struct parse *,
409 isc_boolean_t *, enum expression_context);
410 isc_boolean_t parse_expression(struct element *, struct parse *,
411 isc_boolean_t *, enum expression_context,
412 struct element *, enum expr_op);
413 struct string *escape_option_string(unsigned, const char *,
414 isc_boolean_t *, isc_boolean_t *);
415 isc_boolean_t parse_option_data(struct element *, struct parse *,
416 struct option *);
417 isc_boolean_t parse_option_binary(struct element *, struct parse *,
418 struct option *, isc_boolean_t);
419 struct string * parse_option_textbin(struct parse *, struct option *);
420 isc_boolean_t parse_option_statement(struct element *, struct parse *,
421 struct option *, enum statement_op);
422 isc_boolean_t parse_config_data(struct element *, struct parse *,
423 struct option *);
424 isc_boolean_t parse_config_statement(struct element *, struct parse *,
425 struct option *, enum statement_op);
426 struct string *parse_option_token(struct parse *, const char *,
427 isc_boolean_t *, isc_boolean_t *,
428 isc_boolean_t *);
429 struct string *parse_option_token_binary(struct parse *, const char *);
430 struct string *parse_domain_list(struct parse *, isc_boolean_t);
431 isc_boolean_t is_boolean_expression(struct element *);
432 isc_boolean_t is_data_expression(struct element *);
433 isc_boolean_t is_numeric_expression(struct element *);
434 int expr_precedence(enum expr_op, struct element *);
435
436 /* options.c */
437 void spaces_init(void);
438 void options_init(void);
439 struct space *space_lookup(const char *);
440 struct option *option_lookup_name(const char *, const char *);
441 struct option *kea_lookup_name(const char *, const char *);
442 struct option *option_lookup_code(const char *, unsigned);
443 void push_space(struct space *);
444 void push_option(struct option *);
445 void add_option_data(struct element *, struct element *);
446 void merge_option_data(struct element *, struct element *);
447 struct comments *get_config_comments(unsigned);
448 const char *display_status(enum option_status);
449
450 /* json.c */
451 struct element *json_parse(struct parse *);
452 struct element *json_list_parse(struct parse *);
453 struct element *json_map_parse(struct parse *);
454
455 /* print.c */
456 const char *print_expression(struct element *, isc_boolean_t *);
457 const char *print_boolean_expression(struct element *, isc_boolean_t *);
458 const char *print_data_expression(struct element *, isc_boolean_t *);
459 const char *print_numeric_expression(struct element *, isc_boolean_t *);
460
461 /* reduce.c */
462 struct element *reduce_boolean_expression(struct element *);
463 struct element *reduce_data_expression(struct element *);
464 struct element *reduce_numeric_expression(struct element *);
465
466 /* eval */
467 struct element *eval_expression(struct element *, isc_boolean_t *);
468 struct element *eval_boolean_expression(struct element *, isc_boolean_t *);
469 struct element *eval_data_expression(struct element *, isc_boolean_t *);
470 struct element *eval_numeric_expression(struct element *, isc_boolean_t *);