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