1 /*	$MirOS: src/usr.sbin/dhcpd/dhcpd.h,v 1.2 2013/10/31 20:07:19 tg Exp $ */
2 /*	$OpenBSD: dhcpd.h,v 1.21 2006/06/14 14:58:52 ckuethe Exp $ */
3 
4 /*
5  * Copyright © 2013
6  *	Thorsten “mirabilos” Glaser <tg@mirbsd.org>
7  * Copyright (c) 1995, 1996, 1997, 1998, 1999
8  * The Internet Software Consortium.    All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  *
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 3. Neither the name of The Internet Software Consortium nor the names
20  *    of its contributors may be used to endorse or promote products derived
21  *    from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE INTERNET SOFTWARE CONSORTIUM AND
24  * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
25  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27  * DISCLAIMED.  IN NO EVENT SHALL THE INTERNET SOFTWARE CONSORTIUM OR
28  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
31  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
32  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
33  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
34  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35  * SUCH DAMAGE.
36  *
37  * This software has been written for the Internet Software Consortium
38  * by Ted Lemon <mellon@fugue.com> in cooperation with Vixie
39  * Enterprises.  To learn more about the Internet Software Consortium,
40  * see ``http://www.vix.com/isc''.  To learn more about Vixie
41  * Enterprises, see ``http://www.vix.com''.
42  */
43 
44 #include <sys/types.h>
45 #include <netinet/in.h>
46 #include <sys/socket.h>
47 #include <sys/un.h>
48 #include <arpa/inet.h>
49 #include <netdb.h>
50 #include <fcntl.h>
51 #include <stdio.h>
52 #include <unistd.h>
53 #include <string.h>
54 #include <stdlib.h>
55 #include <sys/stat.h>
56 #include <ctype.h>
57 #include <time.h>
58 
59 #include <syslog.h>
60 #include <sys/types.h>
61 #include <string.h>
62 #include <paths.h>
63 #include <errno.h>
64 #include <stdlib.h>
65 #include <unistd.h>
66 #include <setjmp.h>
67 #include <limits.h>
68 
69 #include <sys/wait.h>
70 #include <signal.h>
71 
72 extern int h_errno;
73 
74 #include <net/if.h>
75 #include <net/if_dl.h>
76 #include <net/route.h>
77 #include <sys/sockio.h>
78 
79 #define ifr_netmask ifr_addr
80 
81 #include <stdarg.h>
82 
83 #ifndef _PATH_DHCPD_PID
84 #define _PATH_DHCPD_PID	"/var/run/dhcpd.pid"
85 #endif
86 #ifndef _PATH_DHCPD_DB
87 #define _PATH_DHCPD_DB "/var/db/dhcpd.leases"
88 #endif
89 
90 #ifndef _PATH_DEV_PF
91 #define _PATH_DEV_PF "/dev/pf"
92 #endif
93 
94 /* Time stuff... */
95 #include <sys/time.h>
96 
97 #define HAVE_SA_LEN
98 #define HAVE_MKSTEMP
99 
100 #include "dhcp.h"
101 #include "tree.h"
102 
103 #define SERVER_PORT	67
104 #define CLIENT_PORT	68
105 
106 struct iaddr {
107 	int len;
108 	unsigned char iabuf [16];
109 };
110 
111 struct iaddrlist {
112 	struct iaddrlist *next;
113 	struct iaddr addr;
114 };
115 
116 #define DEFAULT_HASH_SIZE	97
117 
118 struct hash_bucket {
119 	struct hash_bucket *next;
120 	unsigned char *name;
121 	int len;
122 	unsigned char *value;
123 };
124 
125 struct hash_table {
126 	int hash_count;
127 	struct hash_bucket *buckets [DEFAULT_HASH_SIZE];
128 };
129 
130 struct option_data {
131 	int len;
132 	u_int8_t *data;
133 };
134 
135 struct string_list {
136 	struct string_list *next;
137 	char *string;
138 };
139 
140 /* A name server, from /etc/resolv.conf. */
141 struct name_server {
142 	struct name_server *next;
143 	struct sockaddr_in addr;
144 	time_t rcdate;
145 };
146 
147 /* A domain search list element. */
148 struct domain_search_list {
149 	struct domain_search_list *next;
150 	char *domain;
151 	time_t rcdate;
152 };
153 
154 /* A dhcp packet and the pointers to its option values. */
155 struct packet {
156 	struct dhcp_packet *raw;
157 	int packet_length;
158 	int packet_type;
159 	int options_valid;
160 	int client_port;
161 	struct iaddr client_addr;
162 	struct interface_info *interface;	/* Interface on which packet
163 						   was received. */
164 	struct hardware *haddr;		/* Physical link address
165 					   of local sender (maybe gateway). */
166 	struct shared_network *shared_network;
167 	struct option_data options [256];
168 	int got_requested_address;	/* True if client sent the
169 					   dhcp-requested-address option. */
170 };
171 
172 struct hardware {
173 	u_int8_t htype;
174 	u_int8_t hlen;
175 	u_int8_t haddr [16];
176 };
177 
178 /* A dhcp lease declaration structure. */
179 struct lease {
180 	struct lease *next;
181 	struct lease *prev;
182 	struct lease *n_uid, *n_hw;
183 	struct lease *waitq_next;
184 
185 	struct iaddr ip_addr;
186 	time_t starts, ends, timestamp;
187 	unsigned char *uid;
188 	int uid_len;
189 	int uid_max;
190 	unsigned char uid_buf [32];
191 	char *hostname;
192 	char *client_hostname;
193 	struct host_decl *host;
194 	struct subnet *subnet;
195 	struct shared_network *shared_network;
196 	struct hardware hardware_addr;
197 
198 	int flags;
199 #define STATIC_LEASE		1
200 #define BOOTP_LEASE		2
201 #define DYNAMIC_BOOTP_OK	4
202 #define PERSISTENT_FLAGS	(DYNAMIC_BOOTP_OK)
203 #define EPHEMERAL_FLAGS		(BOOTP_LEASE)
204 #define MS_NULL_TERMINATION	8
205 #define ABANDONED_LEASE		16
206 
207 	struct lease_state *state;
208 	u_int8_t releasing;
209 };
210 
211 struct lease_state {
212 	struct lease_state *next;
213 
214 	struct interface_info *ip;
215 
216 	time_t offered_expiry;
217 
218 	struct tree_cache *options [256];
219 	u_int32_t expiry, renewal, rebind;
220 	char filename [DHCP_FILE_LEN];
221 	char *server_name;
222 
223 	struct iaddr from;
224 
225 	int max_message_size;
226 	u_int8_t *prl;
227 	int prl_len;
228 	int got_requested_address;	/* True if client sent the
229 					   dhcp-requested-address option. */
230 	int got_server_identifier;	/* True if client sent the
231 					   dhcp-server-identifier option. */
232 	struct shared_network *shared_network;	/* Shared network of interface
233 						   on which request arrived. */
234 
235 	u_int32_t xid;
236 	u_int16_t secs;
237 	u_int16_t bootp_flags;
238 	struct in_addr ciaddr;
239 	struct in_addr giaddr;
240 	u_int8_t hops;
241 	u_int8_t offer;
242 	struct hardware haddr;
243 };
244 
245 #define	ROOT_GROUP	0
246 #define HOST_DECL	1
247 #define SHARED_NET_DECL	2
248 #define SUBNET_DECL	3
249 #define CLASS_DECL	4
250 #define	GROUP_DECL	5
251 
252 /* Group of declarations that share common parameters. */
253 struct group {
254 	struct group *next;
255 
256 	struct subnet *subnet;
257 	struct shared_network *shared_network;
258 
259 	time_t default_lease_time;
260 	time_t max_lease_time;
261 	time_t bootp_lease_cutoff;
262 	time_t bootp_lease_length;
263 
264 	char *filename;
265 	char *server_name;
266 	struct iaddr next_server;
267 
268 	int boot_unknown_clients;
269 	int dynamic_bootp;
270 	int allow_bootp;
271 	int allow_booting;
272 	int one_lease_per_client;
273 	int get_lease_hostnames;
274 	int use_host_decl_names;
275 	int use_lease_addr_for_default_route;
276 	int authoritative;
277 	int always_reply_rfc1048;
278 
279 	struct tree_cache *options [256];
280 };
281 
282 /* A dhcp host declaration structure. */
283 struct host_decl {
284 	struct host_decl *n_ipaddr;
285 	char *name;
286 	struct hardware interface;
287 	struct tree_cache *fixed_addr;
288 	struct group *group;
289 };
290 
291 struct shared_network {
292 	struct shared_network *next;
293 	char *name;
294 	struct subnet *subnets;
295 	struct interface_info *interface;
296 	struct lease *leases;
297 	struct lease *insertion_point;
298 	struct lease *last_lease;
299 
300 	struct group *group;
301 };
302 
303 struct subnet {
304 	struct subnet *next_subnet;
305 	struct subnet *next_sibling;
306 	struct shared_network *shared_network;
307 	struct interface_info *interface;
308 	struct iaddr interface_address;
309 	struct iaddr net;
310 	struct iaddr netmask;
311 
312 	struct group *group;
313 };
314 
315 struct class {
316 	char *name;
317 
318 	struct group *group;
319 };
320 
321 /* DHCP client lease structure... */
322 struct client_lease {
323 	struct client_lease *next;		/* Next lease in list. */
324 	time_t expiry, renewal, rebind;		/* Lease timeouts. */
325 	struct iaddr address;			/* Address being leased. */
326 	char *server_name;			/* Name of boot server. */
327 	char *filename;				/* File to boot. */
328 	struct string_list *medium;		/* Network medium. */
329 
330 	unsigned int is_static : 1;	/* If set, lease is from config file. */
331 	unsigned int is_bootp: 1;	/* If set, lease was aquired with BOOTP. */
332 
333 	struct option_data options [256];	/* Options supplied with lease. */
334 };
335 
336 /* privsep message. fixed length for easy parsing */
337 struct pf_cmd{
338 	struct in_addr ip;
339 	u_int32_t type;
340 };
341 
342 /* Possible states in which the client can be. */
343 enum dhcp_state {
344 	S_REBOOTING,
345 	S_INIT,
346 	S_SELECTING,
347 	S_REQUESTING,
348 	S_BOUND,
349 	S_RENEWING,
350 	S_REBINDING
351 };
352 
353 /* Configuration information from the config file... */
354 struct client_config {
355 	struct option_data defaults [256]; /* Default values for options. */
356 	enum {
357 		ACTION_DEFAULT,		/* Use server value if present,
358 					   otherwise default. */
359 		ACTION_SUPERSEDE,	/* Always use default. */
360 		ACTION_PREPEND,		/* Prepend default to server. */
361 		ACTION_APPEND		/* Append default to server. */
362 	} default_actions [256];
363 
364 	struct option_data send_options [256]; /* Send these to server. */
365 	u_int8_t required_options [256]; /* Options server must supply. */
366 	u_int8_t requested_options [256]; /* Options to request from server. */
367 	int requested_option_count;	/* Number of requested options. */
368 	time_t timeout;			/* Start to panic if we don't get a
369 					   lease in this time period when
370 					   SELECTING. */
371 	time_t initial_interval;	/* All exponential backoff intervals
372 					   start here. */
373 	time_t retry_interval;		/* If the protocol failed to produce
374 					   an address before the timeout,
375 					   try the protocol again after this
376 					   many seconds. */
377 	time_t select_interval;		/* Wait this many seconds from the
378 					   first DHCPDISCOVER before
379 					   picking an offered lease. */
380 	time_t reboot_timeout;		/* When in INIT-REBOOT, wait this
381 					   long before giving up and going
382 					   to INIT. */
383 	time_t backoff_cutoff;		/* When doing exponential backoff,
384 					   never back off to an interval
385 					   longer than this amount. */
386 	struct string_list *media;	/* Possible network media values. */
387 	char *script_name;		/* Name of config script. */
388 	enum { IGNORE, ACCEPT, PREFER } bootp_policy;
389 					/* Ignore, accept or prefer BOOTP
390 					   responses. */
391 	struct string_list *medium;	/* Current network medium. */
392 
393 	struct iaddrlist *reject_list;	/* Servers to reject. */
394 };
395 
396 /* Per-interface state used in the dhcp client... */
397 struct client_state {
398 	struct client_lease *active;		  /* Currently active lease. */
399 	struct client_lease *new;			       /* New lease. */
400 	struct client_lease *offered_leases;	    /* Leases offered to us. */
401 	struct client_lease *leases;		/* Leases we currently hold. */
402 	struct client_lease *alias;			     /* Alias lease. */
403 
404 	enum dhcp_state state;		/* Current state for this interface. */
405 	struct iaddr destination;		    /* Where to send packet. */
406 	u_int32_t xid;					  /* Transaction ID. */
407 	u_int16_t secs;			    /* secs value from DHCPDISCOVER. */
408 	time_t first_sending;			/* When was first copy sent? */
409 	time_t interval;	      /* What's the current resend interval? */
410 	struct string_list *medium;		   /* Last media type tried. */
411 
412 	struct dhcp_packet packet;		    /* Outgoing DHCP packet. */
413 	int packet_length;	       /* Actual length of generated packet. */
414 
415 	struct iaddr requested_address;	    /* Address we would like to get. */
416 
417 	struct client_config *config;	    /* Information from config file. */
418 
419 	char **scriptEnv;  /* Client script env */
420 	int scriptEnvsize; /* size of the env table */
421 
422 	struct string_list *env;	       /* Client script environment. */
423 	int envc;			/* Number of entries in environment. */
424 };
425 
426 /* Information about each network interface. */
427 
428 struct interface_info {
429 	struct interface_info *next;	/* Next interface in list... */
430 	struct shared_network *shared_network;
431 				/* Networks connected to this interface. */
432 	struct hardware hw_address;	/* Its physical address. */
433 	struct in_addr primary_address;	/* Primary interface address. */
434 	char name [IFNAMSIZ];		/* Its name... */
435 	int rfdesc;			/* Its read file descriptor. */
436 	int wfdesc;			/* Its write file descriptor, if
437 					   different. */
438 	unsigned char *rbuf;		/* Read buffer, if required. */
439 	size_t rbuf_max;		/* Size of read buffer. */
440 	size_t rbuf_offset;		/* Current offset into buffer. */
441 	size_t rbuf_len;		/* Length of data in buffer. */
442 
443 	struct ifreq *ifp;		/* Pointer to ifreq struct. */
444 
445 	/* Only used by DHCP client code. */
446 	struct client_state *client;
447 	int noifmedia;
448 	int errors;
449 	int dead;
450 	u_int16_t	index;
451 };
452 
453 struct hardware_link {
454 	struct hardware_link *next;
455 	char name [IFNAMSIZ];
456 	struct hardware address;
457 };
458 
459 struct dhcpd_timeout {
460 	struct dhcpd_timeout *next;
461 	time_t when;
462 	void (*func)(void *);
463 	void *what;
464 };
465 
466 struct protocol {
467 	struct protocol *next;
468 	int fd;
469 	void (*handler)(struct protocol *);
470 	void *local;
471 };
472 
473 /* Bitmask of dhcp option codes. */
474 typedef unsigned char option_mask [16];
475 
476 /* DHCP Option mask manipulation macros... */
477 #define OPTION_ZERO(mask)	(memset (mask, 0, 16))
478 #define OPTION_SET(mask, bit)	(mask [bit >> 8] |= (1 << (bit & 7)))
479 #define OPTION_CLR(mask, bit)	(mask [bit >> 8] &= ~(1 << (bit & 7)))
480 #define OPTION_ISSET(mask, bit)	(mask [bit >> 8] & (1 << (bit & 7)))
481 #define OPTION_ISCLR(mask, bit)	(!OPTION_ISSET (mask, bit))
482 
483 /* An option occupies its length plus two header bytes (code and
484     length) for every 255 bytes that must be stored. */
485 #define OPTION_SPACE(x)		((x) + 2 * ((x) / 255 + 1))
486 
487 /* Default path to dhcpd config file. */
488 #ifdef DEBUG
489 #undef _PATH_DHCPD_CONF
490 #define _PATH_DHCPD_CONF	"dhcpd.conf"
491 #undef _PATH_DHCPD_DB
492 #define _PATH_DHCPD_DB		"dhcpd.leases"
493 #else
494 #ifndef _PATH_DHCPD_CONF
495 #define _PATH_DHCPD_CONF	"/etc/dhcpd.conf"
496 #endif
497 
498 #ifndef _PATH_DHCPD_DB
499 #define _PATH_DHCPD_DB		"/etc/dhcpd.leases"
500 #endif
501 
502 #ifndef _PATH_DHCPD_PID
503 #define _PATH_DHCPD_PID		"/var/run/dhcpd.pid"
504 #endif
505 #endif
506 
507 #ifndef _PATH_DHCLIENT_CONF
508 #define _PATH_DHCLIENT_CONF	"/etc/dhclient.conf"
509 #endif
510 
511 #ifndef _PATH_DHCLIENT_PID
512 #define _PATH_DHCLIENT_PID	"/var/run/dhclient.pid"
513 #endif
514 
515 #ifndef _PATH_DHCLIENT_DB
516 #define _PATH_DHCLIENT_DB	"/etc/dhclient.leases"
517 #endif
518 
519 #ifndef _PATH_RESOLV_CONF
520 #define _PATH_RESOLV_CONF	"/etc/resolv.conf"
521 #endif
522 
523 #ifndef _PATH_DHCRELAY_PID
524 #define _PATH_DHCRELAY_PID	"/var/run/dhcrelay.pid"
525 #endif
526 
527 #ifndef DHCPD_LOG_FACILITY
528 #define DHCPD_LOG_FACILITY	LOG_DAEMON
529 #endif
530 
531 #define MAX_TIME 0x7fffffff
532 #define MIN_TIME 0
533 
534 /* External definitions... */
535 
536 /* options.c */
537 void	 parse_options(struct packet *);
538 void	 parse_option_buffer(struct packet *, unsigned char *, int);
539 int	 cons_options(struct packet *, struct dhcp_packet *, int,
540 	    struct tree_cache **, int, int, int, u_int8_t *, int);
541 int	 store_options(unsigned char *, int, struct tree_cache **,
542 	    unsigned char *, int, int, int, int);
543 char	*pretty_print_option(unsigned int, unsigned char *, int, int, int);
544 void	 do_packet(struct interface_info *, struct dhcp_packet *, int,
545 	    unsigned int, struct iaddr, struct hardware *);
546 
547 /* errwarn.c */
548 extern int warnings_occurred;
549 void	error(char *, ...) __attribute__((__format__(__printf__, 1, 2)));
550 int	warning(char *, ...) __attribute__((__format__(__printf__, 1, 2)));
551 int	note(char *, ...) __attribute__((__format__(__printf__, 1, 2)));
552 int	debug(char *, ...) __attribute__((__format__(__printf__, 1, 2)));
553 int	parse_warn(char *, ...) __attribute__((__format__(__printf__, 1, 2)));
554 
555 /* dhcpd.c */
556 extern time_t		cur_time;
557 extern struct group	root_group;
558 
559 extern u_int16_t	server_port;
560 extern u_int16_t	client_port;
561 extern int		log_priority;
562 extern int		log_perror;
563 
564 extern char		*path_dhcpd_conf;
565 extern char		*path_dhcpd_db;
566 extern char		*path_dhcpd_pid;
567 
568 int	main(int, char *[]);
569 void	cleanup(void);
570 void	lease_pinged(struct iaddr, u_int8_t *, int);
571 void	lease_ping_timeout(void *);
572 void	periodic_scan(void *);
573 
574 /* conflex.c */
575 extern int	 lexline, lexchar;
576 extern char	*token_line, *tlname;
577 extern char	 comments [4096];
578 extern int	 comment_index;
579 extern int	 eol_token;
580 
581 void	new_parse(char *);
582 int	next_token(char **, FILE *);
583 int	peek_token(char **, FILE *);
584 
585 /* confpars.c */
586 int	 readconf(void);
587 void	 read_leases(void);
588 int	 parse_statement(FILE *, struct group *, int, struct host_decl *, int);
589 void	 parse_allow_deny(FILE *, struct group *, int);
590 void	 skip_to_semi(FILE *);
591 int	 parse_boolean(FILE *);
592 int	 parse_semi(FILE *);
593 int	 parse_lbrace(FILE *);
594 void	 parse_host_declaration(FILE *, struct group *);
595 char	*parse_host_name(FILE *);
596 void	 parse_class_declaration(FILE *, struct group *, int);
597 void	 parse_lease_time(FILE *, time_t *);
598 void	 parse_shared_net_declaration(FILE *, struct group *);
599 void	 parse_subnet_declaration(FILE *, struct shared_network *);
600 void	 parse_group_declaration(FILE *, struct group *);
601 void	 parse_hardware_param(FILE *, struct hardware *);
602 char	*parse_string(FILE *);
603 
604 struct tree		*parse_ip_addr_or_hostname(FILE *, int);
605 struct tree_cache	*parse_fixed_addr_param(FILE *);
606 void			 parse_option_param(FILE *, struct group *);
607 time_t			 parse_timestamp(FILE *);
608 struct lease		*parse_lease_declaration(FILE *);
609 void			 parse_address_range(FILE *, struct subnet *);
610 time_t			 parse_date(FILE *);
611 unsigned char		*parse_numeric_aggregate(FILE *, unsigned char *, int *,
612 			    int, int, int);
613 void			 convert_num(unsigned char *, char *, int, int);
614 
615 /* tree.c */
616 pair			 cons(caddr_t, pair);
617 struct tree_cache	*tree_cache(struct tree *);
618 struct tree		*tree_host_lookup(char *);
619 struct dns_host_entry	*enter_dns_host(char *);
620 struct tree		*tree_const(unsigned char *, int);
621 struct tree		*tree_concat(struct tree *, struct tree *);
622 struct tree		*tree_limit(struct tree *, int);
623 int			 tree_evaluate(struct tree_cache *);
624 
625 /* dhcp.c */
626 extern int	outstanding_pings;
627 
628 void dhcp(struct packet *);
629 void dhcpdiscover(struct packet *);
630 void dhcprequest(struct packet *);
631 void dhcprelease(struct packet *);
632 void dhcpdecline(struct packet *);
633 void dhcpinform(struct packet *);
634 void nak_lease(struct packet *, struct iaddr *cip);
635 void ack_lease(struct packet *, struct lease *, unsigned int, time_t);
636 void dhcp_reply(struct lease *);
637 struct lease *find_lease(struct packet *, struct shared_network *, int *);
638 struct lease *mockup_lease(struct packet *, struct shared_network *,
639     struct host_decl *);
640 
641 /* bootp.c */
642 void bootp(struct packet *);
643 
644 /* memory.c */
645 void enter_host(struct host_decl *);
646 struct host_decl *find_hosts_by_haddr(int, unsigned char *, int);
647 struct host_decl *find_hosts_by_uid(unsigned char *, int);
648 struct subnet *find_host_for_network(struct host_decl **, struct iaddr *,
649     struct shared_network *);
650 void new_address_range(struct iaddr, struct iaddr, struct subnet *, int);
651 extern struct subnet *find_grouped_subnet(struct shared_network *,
652     struct iaddr);
653 extern struct subnet *find_subnet(struct iaddr);
654 void enter_shared_network(struct shared_network *);
655 int subnet_inner_than(struct subnet *, struct subnet *, int);
656 void enter_subnet(struct subnet *);
657 void enter_lease(struct lease *);
658 int supersede_lease(struct lease *, struct lease *, int);
659 void release_lease(struct lease *);
660 void abandon_lease(struct lease *, char *);
661 struct lease *find_lease_by_uid(unsigned char *, int);
662 struct lease *find_lease_by_hw_addr(unsigned char *, int);
663 struct lease *find_lease_by_ip_addr(struct iaddr);
664 void uid_hash_add(struct lease *);
665 void uid_hash_delete(struct lease *);
666 void hw_hash_add(struct lease *);
667 void hw_hash_delete(struct lease *);
668 struct class *add_class(int, char *);
669 struct class *find_class(int, unsigned char *, int);
670 struct group *clone_group(struct group *, char *);
671 void write_leases(void);
672 
673 /* alloc.c */
674 void * dmalloc(int, char *);
675 void dfree(void *, char *);
676 struct packet *new_packet(char *);
677 struct dhcp_packet *new_dhcp_packet(char *);
678 struct tree *new_tree(char *);
679 struct tree_cache *new_tree_cache(char *);
680 struct hash_table *new_hash_table(int, char *);
681 struct hash_bucket *new_hash_bucket(char *);
682 struct lease *new_lease(char *);
683 struct lease *new_leases(int, char *);
684 struct subnet *new_subnet(char *);
685 struct class *new_class(char *);
686 struct shared_network *new_shared_network(char *);
687 struct group *new_group(char *);
688 struct protocol *new_protocol(char *);
689 struct lease_state *new_lease_state(char *);
690 struct domain_search_list *new_domain_search_list(char *);
691 struct name_server *new_name_server(char *);
692 void free_name_server(struct name_server *, char *);
693 void free_domain_search_list(struct domain_search_list *, char *);
694 void free_lease_state(struct lease_state *, char *);
695 void free_protocol(struct protocol *, char *);
696 void free_group(struct group *, char *);
697 void free_shared_network(struct shared_network *, char *);
698 void free_class(struct class *, char *);
699 void free_subnet(struct subnet *, char *);
700 void free_lease(struct lease *, char *);
701 void free_hash_bucket(struct hash_bucket *, char *);
702 void free_tree_cache(struct tree_cache *);
703 void free_tree(struct tree *, char *);
704 
705 /* print.c */
706 char *print_hw_addr(int, int, unsigned char *);
707 void dump_raw(unsigned char *, int);
708 
709 /* bpf.c */
710 int if_register_bpf(struct interface_info *);
711 void if_reinitialize_send(struct interface_info *);
712 void if_register_send(struct interface_info *);
713 ssize_t send_packet(struct interface_info *, struct dhcp_packet *, size_t,
714     struct in_addr, struct sockaddr_in *, struct hardware *);
715 void if_reinitialize_receive(struct interface_info *);
716 void if_register_receive(struct interface_info *);
717 ssize_t receive_packet(struct interface_info *, unsigned char *, size_t,
718     struct sockaddr_in *, struct hardware *);
719 int can_unicast_without_arp(void);
720 int can_receive_unicast_unconfigured(struct interface_info *);
721 void maybe_setup_fallback(void);
722 
723 /* dispatch.c */
724 extern struct interface_info *interfaces;
725 extern struct protocol *protocols;
726 extern void (*bootp_packet_handler)(struct interface_info *,
727     struct dhcp_packet *, int, unsigned int, struct iaddr, struct hardware *);
728 extern struct dhcpd_timeout *timeouts;
729 void discover_interfaces(void);
730 void dispatch(void);
731 int locate_network(struct packet *);
732 void got_one(struct protocol *);
733 void add_timeout(time_t, void (*)(void *), void *);
734 void cancel_timeout(void (*)(void *), void *);
735 void add_protocol (char *, int, void (*)(struct protocol *), void *);
736 void remove_protocol(struct protocol *);
737 
738 /* hash.c */
739 struct hash_table *new_hash(void);
740 void add_hash(struct hash_table *, unsigned char *, int, unsigned char *);
741 void delete_hash_entry(struct hash_table *, unsigned char *, int);
742 unsigned char *hash_lookup(struct hash_table *, unsigned char *, int);
743 
744 /* tables.c */
745 extern struct option dhcp_options [256];
746 extern unsigned char dhcp_option_default_priority_list [];
747 extern int sizeof_dhcp_option_default_priority_list;
748 extern char *hardware_types [256];
749 extern struct hash_table universe_hash;
750 extern struct universe dhcp_universe;
751 void initialize_universes(void);
752 
753 /* convert.c */
754 u_int32_t getULong(unsigned char *);
755 int32_t getLong(unsigned char *);
756 u_int16_t getUShort(unsigned char *);
757 int16_t getShort(unsigned char *);
758 void putULong(unsigned char *, u_int32_t);
759 void putLong(unsigned char *, int32_t);
760 void putUShort(unsigned char *, unsigned int);
761 void putShort(unsigned char *, int);
762 
763 /* inet.c */
764 struct iaddr subnet_number(struct iaddr, struct iaddr);
765 struct iaddr ip_addr(struct iaddr, struct iaddr, u_int32_t);
766 u_int32_t host_addr(struct iaddr, struct iaddr);
767 int addr_eq(struct iaddr, struct iaddr);
768 char *piaddr(struct iaddr);
769 
770 /* db.c */
771 int write_lease(struct lease *);
772 int commit_leases(void);
773 void db_startup(void);
774 void new_lease_file(void);
775 
776 /* packet.c */
777 void assemble_hw_header(struct interface_info *, unsigned char *,
778     int *, struct hardware *);
779 void assemble_udp_ip_header(struct interface_info *, unsigned char *,
780     int *, u_int32_t, u_int32_t, unsigned int, unsigned char *, int);
781 ssize_t decode_hw_header(struct interface_info *, unsigned char *,
782     int, struct hardware *);
783 ssize_t decode_udp_ip_header(struct interface_info *, unsigned char *,
784     int, struct sockaddr_in *, unsigned char *, int);
785 u_int32_t	checksum(unsigned char *, unsigned, u_int32_t);
786 u_int32_t	wrapsum(u_int32_t);
787 
788 /* icmp.c */
789 void icmp_startup(int, void (*)(struct iaddr, u_int8_t *, int));
790 int icmp_echorequest(struct iaddr *);
791 void icmp_echoreply(struct protocol *);
792 
793 /* pfutils.c */
794 __dead void pftable_handler(void);
795 void pf_change_table(int , int , struct in_addr , char *);
796 void pf_kill_state(int , struct in_addr );
797 size_t atomicio(ssize_t (*)(int, void *, size_t), int, void *, size_t);
798 #define vwrite (ssize_t (*)(int, void *, size_t))write
799 void pfmsg(char, struct lease *);
800