2 * Copyright (c) 2017, 2018 by Internet Systems Consortium, Inc. ("ISC")
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.
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.
16 * Internet Systems Consortium, Inc.
18 * Redwood City, CA 94063
20 * https://www.isc.org/
33 /* Resolution of FQDNs into IPv4 addresses */
35 perform
= 0, /* resolve */
36 fatal
, /* raise a fatal error */
37 pass
/* pass the string wth a warning */
40 /* From includes/dhcp.h */
43 #define HTYPE_IEEE802 6
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
51 /* From includes/dhcp6.h */
52 #define D6O_VENDOR_OPTS 17
53 #define MAX_V6RELAY_HOPS 32
55 /* From includes/dhcpd.h */
57 extern int local_family
;
59 /* A parsing context. */
61 TAILQ_HEAD(parses
, parse
) parses
;
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.
77 * We need to keep track of two lines, because we can look
78 * ahead, via the "peek" function, to the next line sometimes.
80 * The "line1" and "line2" variables act as buffers for this
81 * information. The "lpos" variable tells us where we are in the
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.
95 enum dhcp_token token
;
101 int warnings_occurred
;
104 size_t bufix
, buflen
;
108 * Additions for the Kea Migration Assistant.
110 struct element
**stack
;
113 size_t issue_counter
;
115 /* don't save below this */
116 struct comments comments
;
118 /* TAILQ_NEXT(self) is the saved state */
119 TAILQ_ENTRY(parse
) next
;
127 #define SHARED_NET_DECL 4
128 #define SUBNET_DECL 5
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
139 #define CLASS_DECL_DELETED 1
140 #define CLASS_DECL_DYNAMIC 2
141 #define CLASS_DECL_STATIC 4
142 #define CLASS_DECL_SUBCLASS 8
144 /* Hardware buffer size */
145 #define HARDWARE_ADDR_LEN 20
147 /* Expression context */
149 enum expression_context
{
150 context_any
, /* indefinite */
155 context_data_or_numeric
, /* indefinite */
167 default_option_statement
,
168 supersede_option_statement
,
169 append_option_statement
,
170 prepend_option_statement
,
171 send_option_statement
,
172 statements_statement
,
187 /* Expression tree structure. */
203 expr_hw_type
, /* derived from expr_hardware */
204 expr_hw_address
, /* derived from expr_hardware */
219 expr_binary_to_ascii
,
222 expr_pick_first_value
,
224 expr_dns_transaction
,
232 expr_variable_exists
,
233 expr_variable_reference
,
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 */
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 */
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 */
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 */
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 */
299 /* Kea parse tools */
300 void stackPush(struct parse
*cfile
, struct element
*elem
);
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
;
307 /* From common/parse.c */
308 void parse_error(struct parse
*, const char *, ...)
309 __attribute__((__format__(__printf__
,2,3)))
310 __attribute__((noreturn
));
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
*);
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.
325 #define skip_token(a,b,c) ((void) next_token((a),(b),(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
*);
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 *,
372 void convert_num(struct parse
*, unsigned char *, const char *,
374 struct option
*parse_option_name(struct parse
*, 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
,
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
*,
394 isc_boolean_t
parse_switch_statement(struct element
*, struct parse
*,
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
*,
400 isc_boolean_t
parse_boolean_expression(struct element
*, struct parse
*,
402 /* currently unused */
403 isc_boolean_t
parse_boolean(struct parse
*);
404 isc_boolean_t
parse_data_expression(struct element
*, struct parse
*,
406 isc_boolean_t
numeric_expression(struct element
*, struct parse
*,
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
*,
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
*,
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
*,
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
*);
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
);
451 struct element
*json_parse(struct parse
*);
452 struct element
*json_list_parse(struct parse
*);
453 struct element
*json_map_parse(struct parse
*);
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
*);
462 struct element
*reduce_boolean_expression(struct element
*);
463 struct element
*reduce_data_expression(struct element
*);
464 struct element
*reduce_numeric_expression(struct element
*);
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
*);