1/* dhcpd.h
2
3   Definitions for dhcpd... */
4
5/*
6 * Copyright (c) 2004-2005 by Internet Systems Consortium, Inc. ("ISC")
7 * Copyright (c) 1996-2003 by Internet Software Consortium
8 *
9 * Permission to use, copy, modify, and distribute this software for any
10 * purpose with or without fee is hereby granted, provided that the above
11 * copyright notice and this permission notice appear in all copies.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
14 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15 * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR
16 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
19 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 *
21 *   Internet Systems Consortium, Inc.
22 *   950 Charter Street
23 *   Redwood City, CA 94063
24 *   <info@isc.org>
25 *   http://www.isc.org/
26 *
27 * This software has been written for Internet Systems Consortium
28 * by Ted Lemon in cooperation with Vixie Enterprises and Nominum, Inc.
29 * To learn more about Internet Systems Consortium, see
30 * ``http://www.isc.org/''.  To learn more about Vixie Enterprises,
31 * see ``http://www.vix.com''.   To learn more about Nominum, Inc., see
32 * ``http://www.nominum.com''.
33 */
34
35#ifndef __CYGWIN32__
36#include <sys/types.h>
37#include <netinet/in.h>
38#ifndef SMALL
39#include <netipsec/ipsec.h>
40#endif
41#include <sys/socket.h>
42#include <sys/un.h>
43#include <arpa/inet.h>
44
45#include <netdb.h>
46#else
47#define fd_set cygwin_fd_set
48#include <sys/types.h>
49#endif
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 "cdefs.h"
60#include "osdep.h"
61
62#include "arpa/nameser.h"
63#if defined (NSUPDATE)
64# include "minires/minires.h"
65#endif
66
67struct hash_table;
68typedef struct hash_table group_hash_t;
69typedef struct hash_table universe_hash_t;
70typedef struct hash_table option_hash_t;
71typedef struct hash_table dns_zone_hash_t;
72typedef struct hash_table lease_hash_t;
73typedef struct hash_table host_hash_t;
74typedef struct hash_table class_hash_t;
75
76#include "dhcp.h"
77#include "statement.h"
78#include "tree.h"
79#include "inet.h"
80#include "dhctoken.h"
81
82#include <isc-dhcp/result.h>
83#include <omapip/omapip_p.h>
84
85#if !defined (OPTION_HASH_SIZE)
86# define OPTION_HASH_SIZE 17
87# define OPTION_HASH_PTWO 32	/* Next power of two above option hash. */
88# define OPTION_HASH_EXP 5	/* The exponent for that power of two. */
89#endif
90
91#define compute_option_hash(x) \
92	(((x) & (OPTION_HASH_PTWO - 1)) + \
93	 (((x) >> OPTION_HASH_EXP) & \
94	  (OPTION_HASH_PTWO - 1))) % OPTION_HASH_SIZE;
95
96enum dhcp_shutdown_state {
97	shutdown_listeners,
98	shutdown_omapi_connections,
99	shutdown_drop_omapi_connections,
100	shutdown_dhcp,
101	shutdown_done
102};
103
104/* Client FQDN option, failover FQDN option, etc. */
105typedef struct {
106	u_int8_t codes [2];
107	unsigned length;
108	u_int8_t *data;
109} ddns_fqdn_t;
110
111#include "failover.h"
112
113/* A parsing context. */
114
115struct parse {
116	int lexline;
117	int lexchar;
118	char *token_line;
119	char *prev_line;
120	char *cur_line;
121	const char *tlname;
122	int eol_token;
123
124	char line1 [81];
125	char line2 [81];
126	int lpos;
127	int line;
128	int tlpos;
129	int tline;
130	enum dhcp_token token;
131	int ugflag;
132	char *tval;
133	int tlen;
134	char tokbuf [1500];
135
136#ifdef OLD_LEXER
137	char comments [4096];
138	int comment_index;
139#endif
140	int warnings_occurred;
141	int file;
142	char *inbuf;
143	unsigned bufix, buflen;
144	unsigned bufsiz;
145};
146
147/* Variable-length array of data. */
148
149struct string_list {
150	struct string_list *next;
151	char string [1];
152};
153
154/* A name server, from /etc/resolv.conf. */
155struct name_server {
156	struct name_server *next;
157	struct sockaddr_in addr;
158	TIME rcdate;
159};
160
161/* A domain search list element. */
162struct domain_search_list {
163	struct domain_search_list *next;
164	char *domain;
165	TIME rcdate;
166};
167
168/* Option tag structures are used to build chains of option tags, for
169   when we're sure we're not going to have enough of them to justify
170   maintaining an array. */
171
172struct option_tag {
173	struct option_tag *next;
174	u_int8_t data [1];
175};
176
177/* An agent option structure.   We need a special structure for the
178   Relay Agent Information option because if more than one appears in
179   a message, we have to keep them seperate. */
180
181struct agent_options {
182	struct agent_options *next;
183	int length;
184	struct option_tag *first;
185};
186
187struct option_cache {
188	int refcnt;
189	struct option_cache *next;
190	struct expression *expression;
191	struct option *option;
192	struct data_string data;
193};
194
195struct option_state {
196	int refcnt;
197	int universe_count;
198	int site_universe;
199	int site_code_min;
200	VOIDPTR universes [1];
201};
202
203/* A dhcp packet and the pointers to its option values. */
204struct packet {
205	struct dhcp_packet *raw;
206	int refcnt;
207	unsigned packet_length;
208	int packet_type;
209	int options_valid;
210	int client_port;
211	struct iaddr client_addr;
212	struct interface_info *interface;	/* Interface on which packet
213						   was received. */
214	struct hardware *haddr;		/* Physical link address
215					   of local sender (maybe gateway). */
216
217	/* Information for relay agent options (see
218	   draft-ietf-dhc-agent-options-xx.txt). */
219	u_int8_t *circuit_id;		/* Circuit ID of client connection. */
220	int circuit_id_len;
221	u_int8_t *remote_id;		/* Remote ID of client. */
222	int remote_id_len;
223
224	int got_requested_address;	/* True if client sent the
225					   dhcp-requested-address option. */
226
227	struct shared_network *shared_network;
228	struct option_state *options;
229
230#if !defined (PACKET_MAX_CLASSES)
231# define PACKET_MAX_CLASSES 5
232#endif
233	int class_count;
234	struct class *classes [PACKET_MAX_CLASSES];
235
236	int known;
237	int authenticated;
238};
239
240/* A network interface's MAC address. */
241
242struct hardware {
243	u_int8_t hlen;
244	u_int8_t hbuf [17];
245};
246
247typedef enum {
248	server_startup = 0,
249	server_running = 1,
250	server_shutdown = 2,
251	server_hibernate = 3,
252	server_awaken = 4
253} control_object_state_t;
254
255typedef struct {
256	OMAPI_OBJECT_PREAMBLE;
257	control_object_state_t state;
258} dhcp_control_object_t;
259
260/* Lease states: */
261#define	FTS_FREE	1
262#define	FTS_ACTIVE	2
263#define	FTS_EXPIRED	3
264#define	FTS_RELEASED	4
265#define	FTS_ABANDONED	5
266#define	FTS_RESET	6
267#define	FTS_BACKUP	7
268typedef u_int8_t binding_state_t;
269
270/* FTS_LAST is the highest value that is valid for a lease binding state. */
271#define FTS_LAST FTS_BACKUP
272
273/* A dhcp lease declaration structure. */
274struct lease {
275	OMAPI_OBJECT_PREAMBLE;
276	struct lease *next;
277	struct lease *n_uid, *n_hw;
278
279	struct iaddr ip_addr;
280	TIME starts, ends, timestamp, sort_time;
281	char *client_hostname;
282	struct binding_scope *scope;
283	struct host_decl *host;
284	struct subnet *subnet;
285	struct pool *pool;
286	struct class *billing_class;
287	struct option_chain_head *agent_options;
288
289	struct executable_statement *on_expiry;
290	struct executable_statement *on_commit;
291	struct executable_statement *on_release;
292
293	unsigned char *uid;
294	unsigned short uid_len;
295	unsigned short uid_max;
296	unsigned char uid_buf [7];
297	struct hardware hardware_addr;
298
299	u_int8_t flags;
300#       define STATIC_LEASE		1
301#	define BOOTP_LEASE		2
302#	define PERSISTENT_FLAGS		(ON_ACK_QUEUE | ON_UPDATE_QUEUE)
303#	define MS_NULL_TERMINATION	8
304#	define ON_UPDATE_QUEUE		16
305#	define ON_ACK_QUEUE		32
306#	define UNICAST_BROADCAST_HACK	64
307#	define ON_DEFERRED_QUEUE	128
308#	define EPHEMERAL_FLAGS		(MS_NULL_TERMINATION | \
309					 UNICAST_BROADCAST_HACK)
310
311	binding_state_t binding_state;
312	binding_state_t next_binding_state;
313	binding_state_t desired_binding_state;
314
315	struct lease_state *state;
316
317	TIME tstp;	/* Time sent to partner. */
318	TIME tsfp;	/* Time sent from partner. */
319	TIME cltt;	/* Client last transaction time. */
320	struct lease *next_pending;
321};
322
323struct lease_state {
324	struct lease_state *next;
325
326	struct interface_info *ip;
327
328	struct packet *packet;	/* The incoming packet. */
329
330	TIME offered_expiry;
331
332	struct option_state *options;
333	struct data_string parameter_request_list;
334	int max_message_size;
335	u_int32_t expiry, renewal, rebind;
336	struct data_string filename, server_name;
337	int got_requested_address;
338	int got_server_identifier;
339	struct shared_network *shared_network;	/* Shared network of interface
340						   on which request arrived. */
341
342	u_int32_t xid;
343	u_int16_t secs;
344	u_int16_t bootp_flags;
345	struct in_addr ciaddr;
346	struct in_addr siaddr;
347	struct in_addr giaddr;
348	u_int8_t hops;
349	u_int8_t offer;
350	struct iaddr from;
351};
352
353#define	ROOT_GROUP	0
354#define HOST_DECL	1
355#define SHARED_NET_DECL	2
356#define SUBNET_DECL	3
357#define CLASS_DECL	4
358#define	GROUP_DECL	5
359#define POOL_DECL	6
360
361/* Possible modes in which discover_interfaces can run. */
362
363#define DISCOVER_RUNNING	0
364#define DISCOVER_SERVER		1
365#define DISCOVER_UNCONFIGURED	2
366#define DISCOVER_RELAY		3
367#define DISCOVER_REQUESTED	4
368
369/* Server option names. */
370
371#define SV_DEFAULT_LEASE_TIME		1
372#define SV_MAX_LEASE_TIME		2
373#define SV_MIN_LEASE_TIME		3
374#define SV_BOOTP_LEASE_CUTOFF		4
375#define SV_BOOTP_LEASE_LENGTH		5
376#define SV_BOOT_UNKNOWN_CLIENTS		6
377#define SV_DYNAMIC_BOOTP		7
378#define	SV_ALLOW_BOOTP			8
379#define	SV_ALLOW_BOOTING		9
380#define	SV_ONE_LEASE_PER_CLIENT		10
381#define	SV_GET_LEASE_HOSTNAMES		11
382#define	SV_USE_HOST_DECL_NAMES		12
383#define	SV_USE_LEASE_ADDR_FOR_DEFAULT_ROUTE	13
384#define	SV_MIN_SECS			14
385#define	SV_FILENAME			15
386#define SV_SERVER_NAME			16
387#define	SV_NEXT_SERVER			17
388#define SV_AUTHORITATIVE		18
389#define SV_VENDOR_OPTION_SPACE		19
390#define SV_ALWAYS_REPLY_RFC1048		20
391#define SV_SITE_OPTION_SPACE		21
392#define SV_ALWAYS_BROADCAST		22
393#define SV_DDNS_DOMAIN_NAME		23
394#define SV_DDNS_HOST_NAME		24
395#define SV_DDNS_REV_DOMAIN_NAME		25
396#define SV_LEASE_FILE_NAME		26
397#define SV_PID_FILE_NAME		27
398#define SV_DUPLICATES			28
399#define SV_DECLINES			29
400#define SV_DDNS_UPDATES			30
401#define SV_OMAPI_PORT			31
402#define SV_LOCAL_PORT			32
403#define SV_LIMITED_BROADCAST_ADDRESS	33
404#define SV_REMOTE_PORT			34
405#define SV_LOCAL_ADDRESS		35
406#define SV_OMAPI_KEY			36
407#define SV_STASH_AGENT_OPTIONS		37
408#define SV_DDNS_TTL			38
409#define SV_DDNS_UPDATE_STYLE		39
410#define SV_CLIENT_UPDATES		40
411#define SV_UPDATE_OPTIMIZATION		41
412#define SV_PING_CHECKS			42
413#define SV_UPDATE_STATIC_LEASES		43
414#define SV_LOG_FACILITY			44
415#define SV_DO_FORWARD_UPDATES		45
416#define SV_PING_TIMEOUT         46
417
418#if !defined (DEFAULT_PING_TIMEOUT)
419# define DEFAULT_PING_TIMEOUT 1
420#endif
421
422#if !defined (DEFAULT_DEFAULT_LEASE_TIME)
423# define DEFAULT_DEFAULT_LEASE_TIME 43200
424#endif
425
426#if !defined (DEFAULT_MIN_LEASE_TIME)
427# define DEFAULT_MIN_LEASE_TIME 0
428#endif
429
430#if !defined (DEFAULT_MAX_LEASE_TIME)
431# define DEFAULT_MAX_LEASE_TIME 86400
432#endif
433
434#if !defined (DEFAULT_DDNS_TTL)
435# define DEFAULT_DDNS_TTL 3600
436#endif
437
438/* Client option names */
439
440#define	CL_TIMEOUT		1
441#define	CL_SELECT_INTERVAL	2
442#define CL_REBOOT_TIMEOUT	3
443#define CL_RETRY_INTERVAL	4
444#define CL_BACKOFF_CUTOFF	5
445#define CL_INITIAL_INTERVAL	6
446#define CL_BOOTP_POLICY		7
447#define	CL_SCRIPT_NAME		8
448#define CL_REQUESTED_OPTIONS	9
449#define CL_REQUESTED_LEASE_TIME	10
450#define CL_SEND_OPTIONS		11
451#define CL_MEDIA		12
452#define	CL_REJECT_LIST		13
453
454#ifndef CL_DEFAULT_TIMEOUT
455# define CL_DEFAULT_TIMEOUT	60
456#endif
457
458#ifndef CL_DEFAULT_SELECT_INTERVAL
459# define CL_DEFAULT_SELECT_INTERVAL 0
460#endif
461
462#ifndef CL_DEFAULT_REBOOT_TIMEOUT
463# define CL_DEFAULT_REBOOT_TIMEOUT 10
464#endif
465
466#ifndef CL_DEFAULT_RETRY_INTERVAL
467# define CL_DEFAULT_RETRY_INTERVAL 300
468#endif
469
470#ifndef CL_DEFAULT_BACKOFF_CUTOFF
471# define CL_DEFAULT_BACKOFF_CUTOFF 120
472#endif
473
474#ifndef CL_DEFAULT_INITIAL_INTERVAL
475# define CL_DEFAULT_INITIAL_INTERVAL 10
476#endif
477
478#ifndef CL_DEFAULT_BOOTP_POLICY
479# define CL_DEFAULT_BOOTP_POLICY P_ACCEPT
480#endif
481
482#ifndef CL_DEFAULT_REQUESTED_OPTIONS
483# define CL_DEFAULT_REQUESTED_OPTIONS \
484	{ DHO_SUBNET_MASK, \
485	  DHO_BROADCAST_ADDRESS, \
486	  DHO_TIME_OFFSET, \
487	  DHO_ROUTERS, \
488	  DHO_DOMAIN_NAME, \
489	  DHO_DOMAIN_NAME_SERVERS, \
490	  DHO_HOST_NAME }
491#endif
492
493struct group_object {
494	OMAPI_OBJECT_PREAMBLE;
495
496	struct group_object *n_dynamic;
497	struct group *group;
498	char *name;
499	int flags;
500#define GROUP_OBJECT_DELETED	1
501#define GROUP_OBJECT_DYNAMIC	2
502#define GROUP_OBJECT_STATIC	4
503};
504
505/* Group of declarations that share common parameters. */
506struct group {
507	struct group *next;
508
509	int refcnt;
510	struct group_object *object;
511	struct subnet *subnet;
512	struct shared_network *shared_network;
513	int authoritative;
514	struct executable_statement *statements;
515};
516
517/* A dhcp host declaration structure. */
518struct host_decl {
519	OMAPI_OBJECT_PREAMBLE;
520	struct host_decl *n_ipaddr;
521	struct host_decl *n_dynamic;
522	char *name;
523	struct hardware interface;
524	struct data_string client_identifier;
525	struct option_cache *fixed_addr;
526	struct group *group;
527	struct group_object *named_group;
528	struct data_string auth_key_id;
529	int flags;
530#define HOST_DECL_DELETED	1
531#define HOST_DECL_DYNAMIC	2
532#define HOST_DECL_STATIC	4
533};
534
535struct permit {
536	struct permit *next;
537	enum {
538		permit_unknown_clients,
539		permit_known_clients,
540		permit_authenticated_clients,
541		permit_unauthenticated_clients,
542		permit_all_clients,
543		permit_dynamic_bootp_clients,
544		permit_class
545	} type;
546	struct class *class;
547};
548
549struct pool {
550	OMAPI_OBJECT_PREAMBLE;
551	struct pool *next;
552	struct group *group;
553	struct shared_network *shared_network;
554	struct permit *permit_list;
555	struct permit *prohibit_list;
556	struct lease *active;
557	struct lease *expired;
558	struct lease *free;
559	struct lease *backup;
560	struct lease *abandoned;
561	TIME next_event_time;
562	int lease_count;
563	int free_leases;
564	int backup_leases;
565	int index;
566#if defined (FAILOVER_PROTOCOL)
567	dhcp_failover_state_t *failover_peer;
568#endif
569};
570
571struct shared_network {
572	OMAPI_OBJECT_PREAMBLE;
573	struct shared_network *next;
574	char *name;
575	struct subnet *subnets;
576	struct interface_info *interface;
577	struct pool *pools;
578	struct group *group;
579#if defined (FAILOVER_PROTOCOL)
580	dhcp_failover_state_t *failover_peer;
581#endif
582};
583
584struct subnet {
585	OMAPI_OBJECT_PREAMBLE;
586	struct subnet *next_subnet;
587	struct subnet *next_sibling;
588	struct shared_network *shared_network;
589	struct interface_info *interface;
590	struct iaddr interface_address;
591	struct iaddr net;
592	struct iaddr netmask;
593
594	struct group *group;
595};
596
597struct collection {
598	struct collection *next;
599
600	const char *name;
601	struct class *classes;
602};
603
604/* XXX classes must be reference-counted. */
605struct class {
606	OMAPI_OBJECT_PREAMBLE;
607	struct class *nic;		/* Next in collection. */
608	struct class *superclass;	/* Set for spawned classes only. */
609	char *name;			/* Not set for spawned classes. */
610
611	/* A class may be configured to permit a limited number of leases. */
612	int lease_limit;
613	int leases_consumed;
614	struct lease **billed_leases;
615
616	/* If nonzero, class has not been saved since it was last
617	   modified. */
618	int dirty;
619
620	/* Hash table containing subclasses. */
621	class_hash_t *hash;
622	struct data_string hash_string;
623
624	/* Expression used to match class. */
625	struct expression *expr;
626
627	/* Expression used to compute subclass identifiers for spawning
628	   and to do subclass matching. */
629	struct expression *submatch;
630	int spawning;
631
632	struct group *group;
633
634	/* Statements to execute if class matches. */
635	struct executable_statement *statements;
636};
637
638/* DHCP client lease structure... */
639struct client_lease {
640	struct client_lease *next;		      /* Next lease in list. */
641	TIME expiry, renewal, rebind;			  /* Lease timeouts. */
642	struct iaddr address;			    /* Address being leased. */
643	char *server_name;			     /* Name of boot server. */
644	char *filename;		     /* Name of file we're supposed to boot. */
645	struct string_list *medium;			  /* Network medium. */
646	struct auth_key *key;      /* Key used in basic DHCP authentication. */
647
648	unsigned int is_static : 1;    /* If set, lease is from config file. */
649	unsigned int is_bootp: 1;  /* If set, lease was acquired with BOOTP. */
650
651	struct option_state *options;	     /* Options supplied with lease. */
652};
653
654/* Possible states in which the client can be. */
655enum dhcp_state {
656	S_REBOOTING = 1,
657	S_INIT = 2,
658	S_SELECTING = 3,
659	S_REQUESTING = 4,
660	S_BOUND = 5,
661	S_RENEWING = 6,
662	S_REBINDING = 7,
663	S_STOPPED = 8
664};
665
666/* Authentication and BOOTP policy possibilities (not all values work
667   for each). */
668enum policy { P_IGNORE, P_ACCEPT, P_PREFER, P_REQUIRE, P_DONT };
669
670/* Configuration information from the config file... */
671struct client_config {
672	/*
673	 * When a message has been received, run these statements
674	 * over it.
675	 */
676	struct group *on_receipt;
677
678	/*
679	 * When a message is sent, run these statements.
680	 */
681	struct group *on_transmission;
682
683	u_int32_t *required_options; /* Options server must supply. */
684	u_int32_t *requested_options; /* Options to request from server. */
685
686	TIME timeout;			/* Start to panic if we don't get a
687					   lease in this time period when
688					   SELECTING. */
689	TIME initial_interval;		/* All exponential backoff intervals
690					   start here. */
691	TIME retry_interval;		/* If the protocol failed to produce
692					   an address before the timeout,
693					   try the protocol again after this
694					   many seconds. */
695	TIME select_interval;		/* Wait this many seconds from the
696					   first DHCPDISCOVER before
697					   picking an offered lease. */
698	TIME reboot_timeout;		/* When in INIT-REBOOT, wait this
699					   long before giving up and going
700					   to INIT. */
701	TIME backoff_cutoff;		/* When doing exponential backoff,
702					   never back off to an interval
703					   longer than this amount. */
704	u_int32_t requested_lease;	/* Requested lease time, if user
705					   doesn't configure one. */
706	struct string_list *media;	/* Possible network media values. */
707	char *script_name;		/* Name of config script. */
708	char *vendor_space_name;	/* Name of config script. */
709	enum policy bootp_policy;
710					/* Ignore, accept or prefer BOOTP
711					   responses. */
712	enum policy auth_policy;
713					/* Require authentication, prefer
714					   authentication, or don't try to
715					   authenticate. */
716	struct string_list *medium;	/* Current network medium. */
717
718	struct iaddrlist *reject_list;	/* Servers to reject. */
719
720	int do_forward_update;		/* If nonzero, and if we have the
721					   information we need, update the
722					   A record for the address we get. */
723
724	omapi_auth_key_t *omapi_key;	/* Key to use for authenticating
725					   OMAPI connections. */
726	int omapi_port;			/* Port on which to listen for OMAPI
727					   connections. */
728
729};
730
731/* Per-interface state used in the dhcp client... */
732struct client_state {
733	struct client_state *next;
734	struct interface_info *interface;
735	char *name;
736
737	struct client_lease *active;		  /* Currently active lease. */
738	struct client_lease *new;			       /* New lease. */
739	struct client_lease *offered_leases;	    /* Leases offered to us. */
740	struct client_lease *leases;		/* Leases we currently hold. */
741	struct client_lease *alias;			     /* Alias lease. */
742
743	enum dhcp_state state;		/* Current state for this interface. */
744	struct iaddr destination;		    /* Where to send packet. */
745	u_int32_t xid;					  /* Transaction ID. */
746	u_int16_t secs;			    /* secs value from DHCPDISCOVER. */
747	TIME first_sending;			/* When was first copy sent? */
748	TIME interval;		      /* What's the current resend interval? */
749	int dns_update_timeout;		 /* Last timeout set for DNS update. */
750	struct string_list *medium;		   /* Last media type tried. */
751	struct dhcp_packet packet;		    /* Outgoing DHCP packet. */
752	unsigned packet_length;	       /* Actual length of generated packet. */
753
754	struct iaddr requested_address;	    /* Address we would like to get. */
755
756	struct client_config *config;		    /* Client configuration. */
757	struct string_list *env;	       /* Client script environment. */
758	int envc;			/* Number of entries in environment. */
759
760	struct option_state *sent_options;	/* Options we sent. */
761};
762
763/* Information about each network interface. */
764
765struct interface_info {
766	OMAPI_OBJECT_PREAMBLE;
767	struct interface_info *next;	/* Next interface in list... */
768	struct shared_network *shared_network;
769				/* Networks connected to this interface. */
770	struct hardware hw_address;	/* Its physical address. */
771	struct in_addr primary_address;	/* Primary interface address. */
772
773	u_int8_t *circuit_id;		/* Circuit ID associated with this
774					   interface. */
775	unsigned circuit_id_len;	/* Length of Circuit ID, if there
776					   is one. */
777	u_int8_t *remote_id;		/* Remote ID associated with this
778					   interface (if any). */
779	unsigned remote_id_len;		/* Length of Remote ID. */
780
781	char name [IFNAMSIZ];		/* Its name... */
782	int index;			/* Its index. */
783	int rfdesc;			/* Its read file descriptor. */
784	int wfdesc;			/* Its write file descriptor, if
785					   different. */
786	unsigned char *rbuf;		/* Read buffer, if required. */
787	unsigned int rbuf_max;		/* Size of read buffer. */
788	size_t rbuf_offset;		/* Current offset into buffer. */
789	size_t rbuf_len;		/* Length of data in buffer. */
790
791	struct ifreq *ifp;		/* Pointer to ifreq struct. */
792	u_int32_t flags;		/* Control flags... */
793#define INTERFACE_REQUESTED 1
794#define INTERFACE_AUTOMATIC 2
795#define INTERFACE_RUNNING 4
796
797	/* Only used by DHCP client code. */
798	struct client_state *client;
799# if defined (USE_DLPI_SEND) || defined (USE_DLPI_RECEIVE)
800	int dlpi_sap_length;
801	struct hardware dlpi_broadcast_addr;
802# endif /* DLPI_SEND || DLPI_RECEIVE */
803};
804
805struct hardware_link {
806	struct hardware_link *next;
807	char name [IFNAMSIZ];
808	struct hardware address;
809};
810
811typedef void (*tvref_t)(void *, void *, const char *, int);
812typedef void (*tvunref_t)(void *, const char *, int);
813struct timeout {
814	struct timeout *next;
815	TIME when;
816	void (*func) PROTO ((void *));
817	void *what;
818	tvref_t ref;
819	tvunref_t unref;
820};
821
822struct protocol {
823	struct protocol *next;
824	int fd;
825	void (*handler) PROTO ((struct protocol *));
826	void *local;
827};
828
829struct dns_query; /* forward */
830
831struct dns_wakeup {
832	struct dns_wakeup *next;	/* Next wakeup in chain. */
833	void (*func) PROTO ((struct dns_query *));
834};
835
836struct dns_question {
837	u_int16_t type;			/* Type of query. */
838	u_int16_t class;		/* Class of query. */
839	unsigned char data [1];		/* Query data. */
840};
841
842struct dns_answer {
843	u_int16_t type;			/* Type of answer. */
844	u_int16_t class;		/* Class of answer. */
845	int count;			/* Number of answers. */
846	unsigned char *answers[1];	/* Pointers to answers. */
847};
848
849struct dns_query {
850	struct dns_query *next;		/* Next query in hash bucket. */
851	u_int32_t hash;			/* Hash bucket index. */
852	TIME expiry;			/* Query expiry time (zero if not yet
853					   answered. */
854	u_int16_t id;			/* Query ID (also hash table index) */
855	caddr_t waiters;		/* Pointer to list of things waiting
856					   on this query. */
857
858	struct dns_question *question;	/* Question, internal format. */
859	struct dns_answer *answer;	/* Answer, internal format. */
860
861	unsigned char *query;		/* Query formatted for DNS server. */
862	unsigned len;			/* Length of entire query. */
863	int sent;			/* The query has been sent. */
864	struct dns_wakeup *wakeups;	/* Wakeups to call if this query is
865					   answered. */
866	struct name_server *next_server;	/* Next server to try. */
867	int backoff;			/* Current backoff, in seconds. */
868};
869
870struct dns_zone {
871	int refcnt;
872	TIME timeout;
873	char *name;
874	struct option_cache *primary;
875	struct option_cache *secondary;
876	struct auth_key *key;
877};
878
879struct icmp_state {
880	OMAPI_OBJECT_PREAMBLE;
881	int socket;
882	void (*icmp_handler) PROTO ((struct iaddr, u_int8_t *, int));
883};
884
885#include "ctrace.h"
886
887/* Bitmask of dhcp option codes. */
888typedef unsigned char option_mask [16];
889
890/* DHCP Option mask manipulation macros... */
891#define OPTION_ZERO(mask)	(memset (mask, 0, 16))
892#define OPTION_SET(mask, bit)	(mask [bit >> 8] |= (1 << (bit & 7)))
893#define OPTION_CLR(mask, bit)	(mask [bit >> 8] &= ~(1 << (bit & 7)))
894#define OPTION_ISSET(mask, bit)	(mask [bit >> 8] & (1 << (bit & 7)))
895#define OPTION_ISCLR(mask, bit)	(!OPTION_ISSET (mask, bit))
896
897/* An option occupies its length plus two header bytes (code and
898    length) for every 255 bytes that must be stored. */
899#define OPTION_SPACE(x)		((x) + 2 * ((x) / 255 + 1))
900
901/* Default path to dhcpd config file. */
902#ifdef DEBUG
903#undef _PATH_DHCPD_CONF
904#define _PATH_DHCPD_CONF	"dhcpd.conf"
905#undef _PATH_DHCPD_DB
906#define _PATH_DHCPD_DB		"dhcpd.leases"
907#undef _PATH_DHCPD_PID
908#define _PATH_DHCPD_PID		"dhcpd.pid"
909#else
910#ifndef _PATH_DHCPD_CONF
911#define _PATH_DHCPD_CONF	"/etc/dhcpd.conf"
912#endif
913
914#ifndef _PATH_DHCPD_DB
915#define _PATH_DHCPD_DB		"/etc/dhcpd.leases"
916#endif
917
918#ifndef _PATH_DHCPD_PID
919#define _PATH_DHCPD_PID		"/var/run/dhcpd.pid"
920#endif
921#endif
922
923#ifndef _PATH_DHCLIENT_CONF
924#define _PATH_DHCLIENT_CONF	"/etc/dhclient.conf"
925#endif
926
927#ifndef _PATH_DHCLIENT_SCRIPT
928#define _PATH_DHCLIENT_SCRIPT	"/sbin/dhclient-script"
929#endif
930
931#ifndef _PATH_DHCLIENT_PID
932#define _PATH_DHCLIENT_PID	"/var/run/dhclient.pid"
933#endif
934
935#ifndef _PATH_DHCLIENT_DB
936#define _PATH_DHCLIENT_DB	"/etc/dhclient.leases"
937#endif
938
939#ifndef _PATH_RESOLV_CONF
940#define _PATH_RESOLV_CONF	"/etc/resolv.conf"
941#endif
942
943#ifndef _PATH_DHCRELAY_PID
944#define _PATH_DHCRELAY_PID	"/var/run/dhcrelay.pid"
945#endif
946
947#ifndef DHCPD_LOG_FACILITY
948#define DHCPD_LOG_FACILITY	LOG_DAEMON
949#endif
950
951#define MAX_TIME 0x7fffffff
952#define MIN_TIME 0
953
954/* External definitions... */
955
956HASH_FUNCTIONS_DECL (group, const char *, struct group_object, group_hash_t)
957HASH_FUNCTIONS_DECL (universe, const char *, struct universe, universe_hash_t)
958HASH_FUNCTIONS_DECL (option, const char *, struct option, option_hash_t)
959HASH_FUNCTIONS_DECL (dns_zone, const char *, struct dns_zone, dns_zone_hash_t)
960HASH_FUNCTIONS_DECL (lease, const unsigned char *, struct lease, lease_hash_t)
961HASH_FUNCTIONS_DECL (host, const unsigned char *, struct host_decl, host_hash_t)
962HASH_FUNCTIONS_DECL (class, const char *, struct class, class_hash_t)
963
964/* options.c */
965
966extern struct option *vendor_cfg_option;
967int parse_options PROTO ((struct packet *));
968int parse_option_buffer PROTO ((struct option_state *, const unsigned char *,
969				unsigned, struct universe *));
970struct universe *find_option_universe (struct option *, const char *);
971int parse_encapsulated_suboptions (struct option_state *, struct option *,
972				   const unsigned char *, unsigned,
973				   struct universe *, const char *);
974int cons_options PROTO ((struct packet *, struct dhcp_packet *, struct lease *,
975			 struct client_state *,
976			 int, struct option_state *, struct option_state *,
977			 struct binding_scope **,
978			 int, int, int, struct data_string *, const char *));
979int fqdn_universe_decode (struct option_state *,
980			  const unsigned char *, unsigned, struct universe *);
981int store_options PROTO ((int *, unsigned char *, unsigned, struct packet *,
982			  struct lease *, struct client_state *,
983			  struct option_state *,
984			  struct option_state *, struct binding_scope **,
985			  unsigned *, int, unsigned, unsigned,
986			  int, const char *));
987const char *pretty_print_option PROTO ((struct option *, const unsigned char *,
988					unsigned, int, int));
989int get_option (struct data_string *, struct universe *,
990		struct packet *, struct lease *, struct client_state *,
991		struct option_state *, struct option_state *,
992		struct option_state *, struct binding_scope **, unsigned,
993		const char *, int);
994void set_option (struct universe *, struct option_state *,
995		 struct option_cache *, enum statement_op);
996struct option_cache *lookup_option PROTO ((struct universe *,
997					   struct option_state *, unsigned));
998struct option_cache *lookup_hashed_option PROTO ((struct universe *,
999						  struct option_state *,
1000						  unsigned));
1001int save_option_buffer (struct universe *, struct option_state *,
1002			struct buffer *, unsigned char *, unsigned,
1003			struct option *, int);
1004void save_option PROTO ((struct universe *,
1005			 struct option_state *, struct option_cache *));
1006void save_hashed_option PROTO ((struct universe *,
1007				struct option_state *, struct option_cache *));
1008void delete_option PROTO ((struct universe *, struct option_state *, int));
1009void delete_hashed_option PROTO ((struct universe *,
1010				  struct option_state *, int));
1011int option_cache_dereference PROTO ((struct option_cache **,
1012				     const char *, int));
1013int hashed_option_state_dereference PROTO ((struct universe *,
1014					    struct option_state *,
1015					    const char *, int));
1016int store_option PROTO ((struct data_string *,
1017			 struct universe *, struct packet *, struct lease *,
1018			 struct client_state *,
1019			 struct option_state *, struct option_state *,
1020			 struct binding_scope **, struct option_cache *));
1021int option_space_encapsulate PROTO ((struct data_string *,
1022				     struct packet *, struct lease *,
1023				     struct client_state *,
1024				     struct option_state *,
1025				     struct option_state *,
1026				     struct binding_scope **,
1027				     struct data_string *));
1028int hashed_option_space_encapsulate PROTO ((struct data_string *,
1029					    struct packet *, struct lease *,
1030					    struct client_state *,
1031					    struct option_state *,
1032					    struct option_state *,
1033					    struct binding_scope **,
1034					    struct universe *));
1035int nwip_option_space_encapsulate PROTO ((struct data_string *,
1036					  struct packet *, struct lease *,
1037					  struct client_state *,
1038					  struct option_state *,
1039					  struct option_state *,
1040					  struct binding_scope **,
1041					  struct universe *));
1042int fqdn_option_space_encapsulate (struct data_string *,
1043				   struct packet *, struct lease *,
1044				   struct client_state *,
1045				   struct option_state *,
1046				   struct option_state *,
1047				   struct binding_scope **,
1048				   struct universe *);
1049void suboption_foreach (struct packet *, struct lease *, struct client_state *,
1050			struct option_state *, struct option_state *,
1051			struct binding_scope **, struct universe *, void *,
1052			void (*) (struct option_cache *, struct packet *,
1053				  struct lease *, struct client_state *,
1054				  struct option_state *, struct option_state *,
1055				  struct binding_scope **,
1056				  struct universe *, void *),
1057			struct option_cache *, const char *);
1058void option_space_foreach (struct packet *, struct lease *,
1059			   struct client_state *,
1060			   struct option_state *,
1061			   struct option_state *,
1062			   struct binding_scope **,
1063			   struct universe *, void *,
1064			   void (*) (struct option_cache *,
1065				     struct packet *,
1066				     struct lease *, struct client_state *,
1067				     struct option_state *,
1068				     struct option_state *,
1069				     struct binding_scope **,
1070				     struct universe *, void *));
1071void hashed_option_space_foreach (struct packet *, struct lease *,
1072				  struct client_state *,
1073				  struct option_state *,
1074				  struct option_state *,
1075				  struct binding_scope **,
1076				  struct universe *, void *,
1077				  void (*) (struct option_cache *,
1078					    struct packet *,
1079					    struct lease *,
1080					    struct client_state *,
1081					    struct option_state *,
1082					    struct option_state *,
1083					    struct binding_scope **,
1084					    struct universe *, void *));
1085int linked_option_get PROTO ((struct data_string *, struct universe *,
1086			      struct packet *, struct lease *,
1087			      struct client_state *,
1088			      struct option_state *, struct option_state *,
1089			      struct option_state *, struct binding_scope **,
1090			      unsigned));
1091int linked_option_state_dereference PROTO ((struct universe *,
1092					    struct option_state *,
1093					    const char *, int));
1094void save_linked_option (struct universe *, struct option_state *,
1095			 struct option_cache *);
1096void linked_option_space_foreach (struct packet *, struct lease *,
1097				  struct client_state *,
1098				  struct option_state *,
1099				  struct option_state *,
1100				  struct binding_scope **,
1101				  struct universe *, void *,
1102				  void (*) (struct option_cache *,
1103					    struct packet *,
1104					    struct lease *,
1105					    struct client_state *,
1106					    struct option_state *,
1107					    struct option_state *,
1108					    struct binding_scope **,
1109					    struct universe *, void *));
1110int linked_option_space_encapsulate (struct data_string *, struct packet *,
1111				     struct lease *, struct client_state *,
1112				     struct option_state *,
1113				     struct option_state *,
1114				     struct binding_scope **,
1115				     struct universe *);
1116void delete_linked_option (struct universe *, struct option_state *, int);
1117struct option_cache *lookup_linked_option (struct universe *,
1118					   struct option_state *, unsigned);
1119void do_packet PROTO ((struct interface_info *,
1120		       struct dhcp_packet *, unsigned,
1121		       unsigned int, struct iaddr, struct hardware *));
1122
1123/* dhcpd.c */
1124extern TIME cur_time;
1125
1126int ddns_update_style;
1127
1128extern const char *path_dhcpd_conf;
1129extern const char *path_dhcpd_db;
1130extern const char *path_dhcpd_pid;
1131
1132extern int dhcp_max_agent_option_packet_length;
1133
1134int main PROTO ((int, char **, char **));
1135void postconf_initialization (int);
1136void postdb_startup (void);
1137void cleanup PROTO ((void));
1138void lease_pinged PROTO ((struct iaddr, u_int8_t *, int));
1139void lease_ping_timeout PROTO ((void *));
1140int dhcpd_interface_setup_hook (struct interface_info *ip, struct iaddr *ia);
1141enum dhcp_shutdown_state shutdown_state;
1142isc_result_t dhcp_io_shutdown (omapi_object_t *, void *);
1143isc_result_t dhcp_set_control_state (control_object_state_t oldstate,
1144				     control_object_state_t newstate);
1145
1146/* conflex.c */
1147isc_result_t new_parse PROTO ((struct parse **, int,
1148			       char *, unsigned, const char *, int));
1149isc_result_t end_parse PROTO ((struct parse **));
1150enum dhcp_token next_token PROTO ((const char **, unsigned *, struct parse *));
1151enum dhcp_token peek_token PROTO ((const char **, unsigned *, struct parse *));
1152
1153/* confpars.c */
1154void parse_trace_setup (void);
1155isc_result_t readconf PROTO ((void));
1156isc_result_t read_conf_file (const char *, struct group *, int, int);
1157#if defined (TRACING)
1158void trace_conf_input (trace_type_t *, unsigned, char *);
1159void trace_conf_stop (trace_type_t *ttype);
1160#endif
1161isc_result_t conf_file_subparse (struct parse *, struct group *, int);
1162isc_result_t lease_file_subparse (struct parse *);
1163int parse_statement PROTO ((struct parse *,
1164			    struct group *, int, struct host_decl *, int));
1165#if defined (FAILOVER_PROTOCOL)
1166void parse_failover_peer PROTO ((struct parse *, struct group *, int));
1167void parse_failover_state_declaration (struct parse *,
1168				       dhcp_failover_state_t *);
1169void parse_failover_state PROTO ((struct parse *,
1170				  enum failover_state *, TIME *));
1171#endif
1172int permit_list_match (struct permit *, struct permit *);
1173void parse_pool_statement PROTO ((struct parse *, struct group *, int));
1174int parse_boolean PROTO ((struct parse *));
1175int parse_lbrace PROTO ((struct parse *));
1176void parse_host_declaration PROTO ((struct parse *, struct group *));
1177int parse_class_declaration PROTO ((struct class **, struct parse *,
1178				    struct group *, int));
1179void parse_shared_net_declaration PROTO ((struct parse *, struct group *));
1180void parse_subnet_declaration PROTO ((struct parse *,
1181				      struct shared_network *));
1182void parse_group_declaration PROTO ((struct parse *, struct group *));
1183int parse_fixed_addr_param PROTO ((struct option_cache **, struct parse *));
1184TIME parse_timestamp PROTO ((struct parse *));
1185int parse_lease_declaration PROTO ((struct lease **, struct parse *));
1186void parse_address_range PROTO ((struct parse *, struct group *, int,
1187				 struct pool *, struct lease **));
1188
1189/* ddns.c */
1190int ddns_updates PROTO ((struct packet *, struct lease *, struct lease *,
1191			 struct lease_state *));
1192int ddns_removals PROTO ((struct lease *));
1193
1194/* parse.c */
1195void add_enumeration (struct enumeration *);
1196struct enumeration *find_enumeration (const char *, int);
1197struct enumeration_value *find_enumeration_value (const char *, int,
1198						  const char *);
1199void skip_to_semi PROTO ((struct parse *));
1200void skip_to_rbrace PROTO ((struct parse *, int));
1201int parse_semi PROTO ((struct parse *));
1202int parse_string PROTO ((struct parse *, char **, unsigned *));
1203char *parse_host_name PROTO ((struct parse *));
1204int parse_ip_addr_or_hostname PROTO ((struct expression **,
1205				      struct parse *, int));
1206void parse_hardware_param PROTO ((struct parse *, struct hardware *));
1207void parse_lease_time PROTO ((struct parse *, TIME *));
1208unsigned char *parse_numeric_aggregate PROTO ((struct parse *,
1209					       unsigned char *, unsigned *,
1210					       int, int, unsigned));
1211void convert_num PROTO ((struct parse *, unsigned char *, const char *,
1212			 int, unsigned));
1213TIME parse_date PROTO ((struct parse *));
1214struct option *parse_option_name PROTO ((struct parse *, int, int *));
1215void parse_option_space_decl PROTO ((struct parse *));
1216int parse_option_code_definition PROTO ((struct parse *, struct option *));
1217int parse_base64 (struct data_string *, struct parse *);
1218int parse_cshl PROTO ((struct data_string *, struct parse *));
1219int parse_executable_statement PROTO ((struct executable_statement **,
1220				       struct parse *, int *,
1221				       enum expression_context));
1222int parse_executable_statements PROTO ((struct executable_statement **,
1223					struct parse *, int *,
1224					enum expression_context));
1225int parse_zone (struct dns_zone *, struct parse *);
1226int parse_key (struct parse *);
1227int parse_on_statement PROTO ((struct executable_statement **,
1228			       struct parse *, int *));
1229int parse_switch_statement PROTO ((struct executable_statement **,
1230				   struct parse *, int *));
1231int parse_case_statement PROTO ((struct executable_statement **,
1232				 struct parse *, int *,
1233				 enum expression_context));
1234int parse_if_statement PROTO ((struct executable_statement **,
1235			       struct parse *, int *));
1236int parse_boolean_expression PROTO ((struct expression **,
1237				     struct parse *, int *));
1238int parse_data_expression PROTO ((struct expression **,
1239				  struct parse *, int *));
1240int parse_numeric_expression PROTO ((struct expression **,
1241				     struct parse *, int *));
1242int parse_dns_expression PROTO ((struct expression **, struct parse *, int *));
1243int parse_non_binary PROTO ((struct expression **, struct parse *, int *,
1244			     enum expression_context));
1245int parse_expression PROTO ((struct expression **, struct parse *, int *,
1246			     enum expression_context,
1247			     struct expression **, enum expr_op));
1248int parse_option_statement PROTO ((struct executable_statement **,
1249				   struct parse *, int,
1250				   struct option *, enum statement_op));
1251int parse_option_token PROTO ((struct expression **, struct parse *,
1252			       const char **, struct expression *, int, int));
1253int parse_allow_deny PROTO ((struct option_cache **, struct parse *, int));
1254int parse_auth_key PROTO ((struct data_string *, struct parse *));
1255int parse_warn (struct parse *, const char *, ...)
1256	__attribute__((__format__(__printf__,2,3)));
1257
1258/* tree.c */
1259#if defined (NSUPDATE)
1260extern struct __res_state resolver_state;
1261extern int resolver_inited;
1262#endif
1263
1264extern struct binding_scope *global_scope;
1265pair cons PROTO ((caddr_t, pair));
1266int make_const_option_cache PROTO ((struct option_cache **, struct buffer **,
1267				    u_int8_t *, unsigned, struct option *,
1268				    const char *, int));
1269int make_host_lookup PROTO ((struct expression **, const char *));
1270int enter_dns_host PROTO ((struct dns_host_entry **, const char *));
1271int make_const_data (struct expression **,
1272		     const unsigned char *, unsigned, int, int,
1273		     const char *, int);
1274int make_const_int PROTO ((struct expression **, unsigned long));
1275int make_concat PROTO ((struct expression **,
1276			struct expression *, struct expression *));
1277int make_encapsulation PROTO ((struct expression **, struct data_string *));
1278int make_substring PROTO ((struct expression **, struct expression *,
1279			   struct expression *, struct expression *));
1280int make_limit PROTO ((struct expression **, struct expression *, int));
1281int make_let PROTO ((struct executable_statement **, const char *));
1282int option_cache PROTO ((struct option_cache **, struct data_string *,
1283			 struct expression *, struct option *,
1284			 const char *, int));
1285int evaluate_expression (struct binding_value **, struct packet *,
1286			 struct lease *, struct client_state *,
1287			 struct option_state *, struct option_state *,
1288			 struct binding_scope **, struct expression *,
1289			 const char *, int);
1290int binding_value_dereference (struct binding_value **, const char *, int);
1291#if defined (NSUPDATE)
1292int evaluate_dns_expression PROTO ((ns_updrec **, struct packet *,
1293				    struct lease *,
1294				    struct client_state *,
1295				    struct option_state *,
1296				    struct option_state *,
1297				    struct binding_scope **,
1298				    struct expression *));
1299#endif
1300int evaluate_boolean_expression PROTO ((int *,
1301					struct packet *,  struct lease *,
1302					struct client_state *,
1303					struct option_state *,
1304					struct option_state *,
1305					struct binding_scope **,
1306					struct expression *));
1307int evaluate_data_expression PROTO ((struct data_string *,
1308				     struct packet *, struct lease *,
1309				     struct client_state *,
1310				     struct option_state *,
1311				     struct option_state *,
1312				     struct binding_scope **,
1313				     struct expression *, const char *, int));
1314int evaluate_numeric_expression (unsigned long *, struct packet *,
1315				 struct lease *, struct client_state *,
1316				 struct option_state *, struct option_state *,
1317				 struct binding_scope **,
1318				 struct expression *);
1319int evaluate_option_cache PROTO ((struct data_string *,
1320				  struct packet *, struct lease *,
1321				  struct client_state *,
1322				  struct option_state *, struct option_state *,
1323				  struct binding_scope **,
1324				  struct option_cache *,
1325				  const char *, int));
1326int evaluate_boolean_option_cache PROTO ((int *,
1327					  struct packet *, struct lease *,
1328					  struct client_state *,
1329					  struct option_state *,
1330					  struct option_state *,
1331					  struct binding_scope **,
1332					  struct option_cache *,
1333					  const char *, int));
1334int evaluate_boolean_expression_result PROTO ((int *,
1335					       struct packet *, struct lease *,
1336					       struct client_state *,
1337					       struct option_state *,
1338					       struct option_state *,
1339					       struct binding_scope **,
1340					       struct expression *));
1341void expression_dereference PROTO ((struct expression **, const char *, int));
1342int is_dns_expression PROTO ((struct expression *));
1343int is_boolean_expression PROTO ((struct expression *));
1344int is_data_expression PROTO ((struct expression *));
1345int is_numeric_expression PROTO ((struct expression *));
1346int is_compound_expression PROTO ((struct expression *));
1347int op_precedence PROTO ((enum expr_op, enum expr_op));
1348enum expression_context expression_context (struct expression *);
1349enum expression_context op_context PROTO ((enum expr_op));
1350int write_expression PROTO ((FILE *, struct expression *, int, int, int));
1351struct binding *find_binding PROTO ((struct binding_scope *, const char *));
1352int free_bindings PROTO ((struct binding_scope *, const char *, int));
1353int binding_scope_dereference PROTO ((struct binding_scope **,
1354				      const char *, int));
1355int fundef_dereference (struct fundef **, const char *, int);
1356int data_subexpression_length (int *, struct expression *);
1357int expr_valid_for_context (struct expression *, enum expression_context);
1358struct binding *create_binding (struct binding_scope **, const char *);
1359int bind_ds_value (struct binding_scope **,
1360		   const char *, struct data_string *);
1361int find_bound_string (struct data_string *,
1362		       struct binding_scope *, const char *);
1363int unset (struct binding_scope *, const char *);
1364
1365/* dhcp.c */
1366extern int outstanding_pings;
1367
1368void dhcp PROTO ((struct packet *));
1369void dhcpdiscover PROTO ((struct packet *, int));
1370void dhcprequest PROTO ((struct packet *, int, struct lease *));
1371void dhcprelease PROTO ((struct packet *, int));
1372void dhcpdecline PROTO ((struct packet *, int));
1373void dhcpinform PROTO ((struct packet *, int));
1374void nak_lease PROTO ((struct packet *, struct iaddr *cip));
1375void ack_lease PROTO ((struct packet *, struct lease *,
1376		       unsigned int, TIME, char *, int, struct host_decl *));
1377void dhcp_reply PROTO ((struct lease *));
1378int find_lease PROTO ((struct lease **, struct packet *,
1379		       struct shared_network *, int *, int *, struct lease *,
1380		       const char *, int));
1381int mockup_lease PROTO ((struct lease **, struct packet *,
1382			 struct shared_network *,
1383			 struct host_decl *));
1384void static_lease_dereference PROTO ((struct lease *, const char *, int));
1385
1386int allocate_lease PROTO ((struct lease **, struct packet *,
1387			   struct pool *, int *));
1388int permitted PROTO ((struct packet *, struct permit *));
1389int locate_network PROTO ((struct packet *));
1390int parse_agent_information_option PROTO ((struct packet *, int, u_int8_t *));
1391unsigned cons_agent_information_options PROTO ((struct option_state *,
1392						struct dhcp_packet *,
1393						unsigned, unsigned));
1394
1395/* bootp.c */
1396void bootp PROTO ((struct packet *));
1397
1398/* memory.c */
1399int (*group_write_hook) (struct group_object *);
1400extern struct group *root_group;
1401extern group_hash_t *group_name_hash;
1402isc_result_t delete_group (struct group_object *, int);
1403isc_result_t supersede_group (struct group_object *, int);
1404int clone_group (struct group **, struct group *, const char *, int);
1405int write_group PROTO ((struct group_object *));
1406
1407/* salloc.c */
1408void relinquish_lease_hunks (void);
1409struct lease *new_leases PROTO ((unsigned, const char *, int));
1410#if defined (DEBUG_MEMORY_LEAKAGE) || \
1411		defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
1412void relinquish_free_lease_states (void);
1413#endif
1414OMAPI_OBJECT_ALLOC_DECL (lease, struct lease, dhcp_type_lease)
1415OMAPI_OBJECT_ALLOC_DECL (class, struct class, dhcp_type_class)
1416OMAPI_OBJECT_ALLOC_DECL (pool, struct pool, dhcp_type_pool)
1417OMAPI_OBJECT_ALLOC_DECL (host, struct host_decl, dhcp_type_host)
1418
1419/* alloc.c */
1420OMAPI_OBJECT_ALLOC_DECL (subnet, struct subnet, dhcp_type_subnet)
1421OMAPI_OBJECT_ALLOC_DECL (shared_network, struct shared_network,
1422			 dhcp_type_shared_network)
1423OMAPI_OBJECT_ALLOC_DECL (group_object, struct group_object, dhcp_type_group)
1424OMAPI_OBJECT_ALLOC_DECL (dhcp_control,
1425			 dhcp_control_object_t, dhcp_type_control)
1426
1427#if defined (DEBUG_MEMORY_LEAKAGE) || \
1428		defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
1429void relinquish_free_pairs (void);
1430void relinquish_free_expressions (void);
1431void relinquish_free_binding_values (void);
1432void relinquish_free_option_caches (void);
1433void relinquish_free_packets (void);
1434#endif
1435
1436int option_chain_head_allocate (struct option_chain_head **,
1437				const char *, int);
1438int option_chain_head_reference (struct option_chain_head **,
1439				 struct option_chain_head *,
1440				 const char *, int);
1441int option_chain_head_dereference (struct option_chain_head **,
1442				   const char *, int);
1443int group_allocate (struct group **, const char *, int);
1444int group_reference (struct group **, struct group *, const char *, int);
1445int group_dereference (struct group **, const char *, int);
1446struct dhcp_packet *new_dhcp_packet PROTO ((const char *, int));
1447struct protocol *new_protocol PROTO ((const char *, int));
1448struct lease_state *new_lease_state PROTO ((const char *, int));
1449struct domain_search_list *new_domain_search_list PROTO ((const char *, int));
1450struct name_server *new_name_server PROTO ((const char *, int));
1451void free_name_server PROTO ((struct name_server *, const char *, int));
1452struct option *new_option PROTO ((const char *, int));
1453int group_allocate (struct group **, const char *, int);
1454int group_reference (struct group **, struct group *, const char *, int);
1455int group_dereference (struct group **, const char *, int);
1456void free_option PROTO ((struct option *, const char *, int));
1457struct universe *new_universe PROTO ((const char *, int));
1458void free_universe PROTO ((struct universe *, const char *, int));
1459void free_domain_search_list PROTO ((struct domain_search_list *,
1460				     const char *, int));
1461void free_lease_state PROTO ((struct lease_state *, const char *, int));
1462void free_protocol PROTO ((struct protocol *, const char *, int));
1463void free_dhcp_packet PROTO ((struct dhcp_packet *, const char *, int));
1464struct client_lease *new_client_lease PROTO ((const char *, int));
1465void free_client_lease PROTO ((struct client_lease *, const char *, int));
1466struct permit *new_permit PROTO ((const char *, int));
1467void free_permit PROTO ((struct permit *, const char *, int));
1468pair new_pair PROTO ((const char *, int));
1469void free_pair PROTO ((pair, const char *, int));
1470int expression_allocate PROTO ((struct expression **, const char *, int));
1471int expression_reference PROTO ((struct expression **,
1472				 struct expression *, const char *, int));
1473void free_expression PROTO ((struct expression *, const char *, int));
1474int binding_value_allocate PROTO ((struct binding_value **,
1475				   const char *, int));
1476int binding_value_reference PROTO ((struct binding_value **,
1477				    struct binding_value *,
1478				    const char *, int));
1479void free_binding_value PROTO ((struct binding_value *, const char *, int));
1480int fundef_allocate PROTO ((struct fundef **, const char *, int));
1481int fundef_reference PROTO ((struct fundef **,
1482			     struct fundef *, const char *, int));
1483int option_cache_allocate PROTO ((struct option_cache **, const char *, int));
1484int option_cache_reference PROTO ((struct option_cache **,
1485				   struct option_cache *, const char *, int));
1486int buffer_allocate PROTO ((struct buffer **, unsigned, const char *, int));
1487int buffer_reference PROTO ((struct buffer **, struct buffer *,
1488			     const char *, int));
1489int buffer_dereference PROTO ((struct buffer **, const char *, int));
1490int dns_host_entry_allocate PROTO ((struct dns_host_entry **,
1491				    const char *, const char *, int));
1492int dns_host_entry_reference PROTO ((struct dns_host_entry **,
1493				     struct dns_host_entry *,
1494				     const char *, int));
1495int dns_host_entry_dereference PROTO ((struct dns_host_entry **,
1496				       const char *, int));
1497int option_state_allocate PROTO ((struct option_state **, const char *, int));
1498int option_state_reference PROTO ((struct option_state **,
1499				   struct option_state *, const char *, int));
1500int option_state_dereference PROTO ((struct option_state **,
1501				     const char *, int));
1502void data_string_copy PROTO ((struct data_string *,
1503			      struct data_string *, const char *, int));
1504void data_string_forget PROTO ((struct data_string *, const char *, int));
1505void data_string_truncate PROTO ((struct data_string *, int));
1506int executable_statement_allocate PROTO ((struct executable_statement **,
1507					  const char *, int));
1508int executable_statement_reference PROTO ((struct executable_statement **,
1509					   struct executable_statement *,
1510					   const char *, int));
1511int packet_allocate PROTO ((struct packet **, const char *, int));
1512int packet_reference PROTO ((struct packet **,
1513			     struct packet *, const char *, int));
1514int packet_dereference PROTO ((struct packet **, const char *, int));
1515int binding_scope_allocate PROTO ((struct binding_scope **,
1516				   const char *, int));
1517int binding_scope_reference PROTO ((struct binding_scope **,
1518				    struct binding_scope *,
1519				    const char *, int));
1520int dns_zone_allocate PROTO ((struct dns_zone **, const char *, int));
1521int dns_zone_reference PROTO ((struct dns_zone **,
1522			       struct dns_zone *, const char *, int));
1523
1524/* print.c */
1525char *quotify_string (const char *, const char *, int);
1526char *quotify_buf (const unsigned char *, unsigned, const char *, int);
1527char *print_base64 (const unsigned char *, unsigned, const char *, int);
1528char *print_hw_addr PROTO ((int, int, unsigned char *));
1529void print_lease PROTO ((struct lease *));
1530void dump_raw PROTO ((const unsigned char *, unsigned));
1531void dump_packet_option (struct option_cache *, struct packet *,
1532			 struct lease *, struct client_state *,
1533			 struct option_state *, struct option_state *,
1534			 struct binding_scope **, struct universe *, void *);
1535void dump_packet PROTO ((struct packet *));
1536void hash_dump PROTO ((struct hash_table *));
1537char *print_hex_1 PROTO ((unsigned, const u_int8_t *, unsigned));
1538char *print_hex_2 PROTO ((unsigned, const u_int8_t *, unsigned));
1539char *print_hex_3 PROTO ((unsigned, const u_int8_t *, unsigned));
1540char *print_dotted_quads PROTO ((unsigned, const u_int8_t *));
1541char *print_dec_1 PROTO ((unsigned long));
1542char *print_dec_2 PROTO ((unsigned long));
1543void print_expression PROTO ((const char *, struct expression *));
1544int token_print_indent_concat (FILE *, int, int,
1545			       const char *, const char *, ...);
1546int token_indent_data_string (FILE *, int, int, const char *, const char *,
1547			      struct data_string *);
1548int token_print_indent (FILE *, int, int,
1549			const char *, const char *, const char *);
1550void indent_spaces (FILE *, int);
1551#if defined (NSUPDATE)
1552void print_dns_status (int, ns_updque *);
1553#endif
1554
1555/* socket.c */
1556#if defined (USE_SOCKET_SEND) || defined (USE_SOCKET_RECEIVE) \
1557	|| defined (USE_SOCKET_FALLBACK)
1558int if_register_socket PROTO ((struct interface_info *));
1559#endif
1560
1561#if defined (USE_SOCKET_FALLBACK) && !defined (USE_SOCKET_SEND)
1562void if_reinitialize_fallback PROTO ((struct interface_info *));
1563void if_register_fallback PROTO ((struct interface_info *));
1564ssize_t send_fallback PROTO ((struct interface_info *,
1565			      struct packet *, struct dhcp_packet *, size_t,
1566			      struct in_addr,
1567			      struct sockaddr_in *, struct hardware *));
1568#endif
1569
1570#ifdef USE_SOCKET_SEND
1571void if_reinitialize_send PROTO ((struct interface_info *));
1572void if_register_send PROTO ((struct interface_info *));
1573void if_deregister_send PROTO ((struct interface_info *));
1574ssize_t send_packet PROTO ((struct interface_info *,
1575			    struct packet *, struct dhcp_packet *, size_t,
1576			    struct in_addr,
1577			    struct sockaddr_in *, struct hardware *));
1578#endif
1579#ifdef USE_SOCKET_RECEIVE
1580void if_reinitialize_receive PROTO ((struct interface_info *));
1581void if_register_receive PROTO ((struct interface_info *));
1582void if_deregister_receive PROTO ((struct interface_info *));
1583ssize_t receive_packet PROTO ((struct interface_info *,
1584			       unsigned char *, size_t,
1585			       struct sockaddr_in *, struct hardware *));
1586#endif
1587
1588#if defined (USE_SOCKET_FALLBACK)
1589isc_result_t fallback_discard PROTO ((omapi_object_t *));
1590#endif
1591
1592#if defined (USE_SOCKET_SEND)
1593int can_unicast_without_arp PROTO ((struct interface_info *));
1594int can_receive_unicast_unconfigured PROTO ((struct interface_info *));
1595int supports_multiple_interfaces (struct interface_info *);
1596void maybe_setup_fallback PROTO ((void));
1597#endif
1598
1599/* bpf.c */
1600#if defined (USE_BPF_SEND) || defined (USE_BPF_RECEIVE)
1601int if_register_bpf PROTO ( (struct interface_info *));
1602#endif
1603#ifdef USE_BPF_SEND
1604void if_reinitialize_send PROTO ((struct interface_info *));
1605void if_register_send PROTO ((struct interface_info *));
1606void if_deregister_send PROTO ((struct interface_info *));
1607ssize_t send_packet PROTO ((struct interface_info *,
1608			    struct packet *, struct dhcp_packet *, size_t,
1609			    struct in_addr,
1610			    struct sockaddr_in *, struct hardware *));
1611#endif
1612#ifdef USE_BPF_RECEIVE
1613void if_reinitialize_receive PROTO ((struct interface_info *));
1614void if_register_receive PROTO ((struct interface_info *));
1615void if_deregister_receive PROTO ((struct interface_info *));
1616ssize_t receive_packet PROTO ((struct interface_info *,
1617			       unsigned char *, size_t,
1618			       struct sockaddr_in *, struct hardware *));
1619#endif
1620#if defined (USE_BPF_SEND)
1621int can_unicast_without_arp PROTO ((struct interface_info *));
1622int can_receive_unicast_unconfigured PROTO ((struct interface_info *));
1623int supports_multiple_interfaces (struct interface_info *);
1624void maybe_setup_fallback PROTO ((void));
1625#endif
1626
1627/* lpf.c */
1628#if defined (USE_LPF_SEND) || defined (USE_LPF_RECEIVE)
1629int if_register_lpf PROTO ( (struct interface_info *));
1630#endif
1631#ifdef USE_LPF_SEND
1632void if_reinitialize_send PROTO ((struct interface_info *));
1633void if_register_send PROTO ((struct interface_info *));
1634void if_deregister_send PROTO ((struct interface_info *));
1635ssize_t send_packet PROTO ((struct interface_info *,
1636			    struct packet *, struct dhcp_packet *, size_t,
1637			    struct in_addr,
1638			    struct sockaddr_in *, struct hardware *));
1639#endif
1640#ifdef USE_LPF_RECEIVE
1641void if_reinitialize_receive PROTO ((struct interface_info *));
1642void if_register_receive PROTO ((struct interface_info *));
1643void if_deregister_receive PROTO ((struct interface_info *));
1644ssize_t receive_packet PROTO ((struct interface_info *,
1645			       unsigned char *, size_t,
1646			       struct sockaddr_in *, struct hardware *));
1647#endif
1648#if defined (USE_LPF_SEND)
1649int can_unicast_without_arp PROTO ((struct interface_info *));
1650int can_receive_unicast_unconfigured PROTO ((struct interface_info *));
1651int supports_multiple_interfaces (struct interface_info *);
1652void maybe_setup_fallback PROTO ((void));
1653#endif
1654
1655/* nit.c */
1656#if defined (USE_NIT_SEND) || defined (USE_NIT_RECEIVE)
1657int if_register_nit PROTO ( (struct interface_info *));
1658#endif
1659
1660#ifdef USE_NIT_SEND
1661void if_reinitialize_send PROTO ((struct interface_info *));
1662void if_register_send PROTO ((struct interface_info *));
1663void if_deregister_send PROTO ((struct interface_info *));
1664ssize_t send_packet PROTO ((struct interface_info *,
1665			    struct packet *, struct dhcp_packet *, size_t,
1666			    struct in_addr,
1667			    struct sockaddr_in *, struct hardware *));
1668#endif
1669#ifdef USE_NIT_RECEIVE
1670void if_reinitialize_receive PROTO ((struct interface_info *));
1671void if_register_receive PROTO ((struct interface_info *));
1672void if_deregister_receive PROTO ((struct interface_info *));
1673ssize_t receive_packet PROTO ((struct interface_info *,
1674			       unsigned char *, size_t,
1675			       struct sockaddr_in *, struct hardware *));
1676#endif
1677#if defined (USE_NIT_SEND)
1678int can_unicast_without_arp PROTO ((struct interface_info *));
1679int can_receive_unicast_unconfigured PROTO ((struct interface_info *));
1680int supports_multiple_interfaces (struct interface_info *);
1681void maybe_setup_fallback PROTO ((void));
1682#endif
1683
1684/* dlpi.c */
1685#if defined (USE_DLPI_SEND) || defined (USE_DLPI_RECEIVE)
1686int if_register_dlpi PROTO ( (struct interface_info *));
1687#endif
1688
1689#ifdef USE_DLPI_SEND
1690void if_reinitialize_send PROTO ((struct interface_info *));
1691void if_register_send PROTO ((struct interface_info *));
1692void if_deregister_send PROTO ((struct interface_info *));
1693ssize_t send_packet PROTO ((struct interface_info *,
1694			    struct packet *, struct dhcp_packet *, size_t,
1695			    struct in_addr,
1696			    struct sockaddr_in *, struct hardware *));
1697#endif
1698#ifdef USE_DLPI_RECEIVE
1699void if_reinitialize_receive PROTO ((struct interface_info *));
1700void if_register_receive PROTO ((struct interface_info *));
1701void if_deregister_receive PROTO ((struct interface_info *));
1702ssize_t receive_packet PROTO ((struct interface_info *,
1703			       unsigned char *, size_t,
1704			       struct sockaddr_in *, struct hardware *));
1705#endif
1706
1707
1708/* raw.c */
1709#ifdef USE_RAW_SEND
1710void if_reinitialize_send PROTO ((struct interface_info *));
1711void if_register_send PROTO ((struct interface_info *));
1712void if_deregister_send PROTO ((struct interface_info *));
1713ssize_t send_packet PROTO ((struct interface_info *,
1714			    struct packet *, struct dhcp_packet *, size_t,
1715			    struct in_addr,
1716			    struct sockaddr_in *, struct hardware *));
1717int can_unicast_without_arp PROTO ((struct interface_info *));
1718int can_receive_unicast_unconfigured PROTO ((struct interface_info *));
1719int supports_multiple_interfaces (struct interface_info *);
1720void maybe_setup_fallback PROTO ((void));
1721#endif
1722
1723/* discover.c */
1724extern struct interface_info *interfaces,
1725	*dummy_interfaces, *fallback_interface;
1726extern struct protocol *protocols;
1727extern int quiet_interface_discovery;
1728isc_result_t interface_setup (void);
1729void interface_trace_setup (void);
1730
1731extern struct in_addr limited_broadcast;
1732extern struct in_addr local_address;
1733
1734extern u_int16_t local_port;
1735extern u_int16_t remote_port;
1736extern int (*dhcp_interface_setup_hook) (struct interface_info *,
1737					 struct iaddr *);
1738extern int (*dhcp_interface_discovery_hook) (struct interface_info *);
1739isc_result_t (*dhcp_interface_startup_hook) (struct interface_info *);
1740
1741extern void (*bootp_packet_handler) PROTO ((struct interface_info *,
1742					    struct dhcp_packet *, unsigned,
1743					    unsigned int,
1744					    struct iaddr, struct hardware *));
1745extern struct timeout *timeouts;
1746extern omapi_object_type_t *dhcp_type_interface;
1747#if defined (TRACING)
1748trace_type_t *interface_trace;
1749trace_type_t *inpacket_trace;
1750trace_type_t *outpacket_trace;
1751#endif
1752extern struct interface_info **interface_vector;
1753extern int interface_count;
1754extern int interface_max;
1755isc_result_t interface_initialize (omapi_object_t *, const char *, int);
1756void discover_interfaces PROTO ((int));
1757int setup_fallback (struct interface_info **, const char *, int);
1758int if_readsocket PROTO ((omapi_object_t *));
1759void reinitialize_interfaces PROTO ((void));
1760
1761/* dispatch.c */
1762void set_time (u_int32_t);
1763struct timeval *process_outstanding_timeouts (struct timeval *);
1764void dispatch PROTO ((void));
1765isc_result_t got_one PROTO ((omapi_object_t *));
1766isc_result_t interface_set_value (omapi_object_t *, omapi_object_t *,
1767				  omapi_data_string_t *, omapi_typed_data_t *);
1768isc_result_t interface_get_value (omapi_object_t *, omapi_object_t *,
1769				  omapi_data_string_t *, omapi_value_t **);
1770isc_result_t interface_destroy (omapi_object_t *, const char *, int);
1771isc_result_t interface_signal_handler (omapi_object_t *,
1772				       const char *, va_list);
1773isc_result_t interface_stuff_values (omapi_object_t *,
1774				     omapi_object_t *,
1775				     omapi_object_t *);
1776
1777void add_timeout PROTO ((TIME, void (*) PROTO ((void *)), void *,
1778			 tvref_t, tvunref_t));
1779void cancel_timeout PROTO ((void (*) PROTO ((void *)), void *));
1780void cancel_all_timeouts (void);
1781void relinquish_timeouts (void);
1782#if 0
1783struct protocol *add_protocol PROTO ((const char *, int,
1784				      void (*) PROTO ((struct protocol *)),
1785				      void *));
1786
1787void remove_protocol PROTO ((struct protocol *));
1788#endif
1789OMAPI_OBJECT_ALLOC_DECL (interface,
1790			 struct interface_info, dhcp_type_interface)
1791
1792/* tables.c */
1793extern struct universe dhcp_universe;
1794extern struct option dhcp_options [256];
1795extern struct universe nwip_universe;
1796extern struct option nwip_options [256];
1797extern struct universe fqdn_universe;
1798extern struct option fqdn_options [256];
1799extern int dhcp_option_default_priority_list [];
1800extern int dhcp_option_default_priority_list_count;
1801extern const char *hardware_types [256];
1802int universe_count, universe_max;
1803struct universe **universes;
1804extern universe_hash_t *universe_hash;
1805void initialize_common_option_spaces PROTO ((void));
1806struct universe *config_universe;
1807
1808/* stables.c */
1809#if defined (FAILOVER_PROTOCOL)
1810extern failover_option_t null_failover_option;
1811extern failover_option_t skip_failover_option;
1812extern struct failover_option_info ft_options [];
1813extern u_int32_t fto_allowed [];
1814extern int ft_sizes [];
1815extern const char *dhcp_flink_state_names [];
1816#endif
1817extern const char *binding_state_names [];
1818
1819extern struct universe agent_universe;
1820extern struct option agent_options [256];
1821extern struct universe server_universe;
1822extern struct option server_options [256];
1823
1824extern struct enumeration ddns_styles;
1825extern struct enumeration syslog_enum;
1826void initialize_server_option_spaces PROTO ((void));
1827
1828/* inet.c */
1829struct iaddr subnet_number PROTO ((struct iaddr, struct iaddr));
1830struct iaddr ip_addr PROTO ((struct iaddr, struct iaddr, u_int32_t));
1831struct iaddr broadcast_addr PROTO ((struct iaddr, struct iaddr));
1832u_int32_t host_addr PROTO ((struct iaddr, struct iaddr));
1833int addr_eq PROTO ((struct iaddr, struct iaddr));
1834char *piaddr PROTO ((struct iaddr));
1835char *piaddrmask (struct iaddr, struct iaddr, const char *, int);
1836
1837/* dhclient.c */
1838extern const char *path_dhclient_conf;
1839extern const char *path_dhclient_db;
1840extern const char *path_dhclient_pid;
1841extern char *path_dhclient_script;
1842extern int interfaces_requested;
1843
1844extern struct client_config top_level_config;
1845
1846void dhcpoffer PROTO ((struct packet *));
1847void dhcpack PROTO ((struct packet *));
1848void dhcpnak PROTO ((struct packet *));
1849
1850void send_discover PROTO ((void *));
1851void send_request PROTO ((void *));
1852void send_release PROTO ((void *));
1853void send_decline PROTO ((void *));
1854
1855void state_reboot PROTO ((void *));
1856void state_init PROTO ((void *));
1857void state_selecting PROTO ((void *));
1858void state_requesting PROTO ((void *));
1859void state_bound PROTO ((void *));
1860void state_stop PROTO ((void *));
1861void state_panic PROTO ((void *));
1862
1863void bind_lease PROTO ((struct client_state *));
1864
1865void make_client_options PROTO ((struct client_state *,
1866				 struct client_lease *, u_int8_t *,
1867				 struct option_cache *, struct iaddr *,
1868				 u_int32_t *, struct option_state **));
1869void make_discover PROTO ((struct client_state *, struct client_lease *));
1870void make_request PROTO ((struct client_state *, struct client_lease *));
1871void make_decline PROTO ((struct client_state *, struct client_lease *));
1872void make_release PROTO ((struct client_state *, struct client_lease *));
1873
1874void destroy_client_lease PROTO ((struct client_lease *));
1875void rewrite_client_leases PROTO ((void));
1876void write_lease_option (struct option_cache *, struct packet *,
1877			 struct lease *, struct client_state *,
1878			 struct option_state *, struct option_state *,
1879			 struct binding_scope **, struct universe *, void *);
1880int write_client_lease PROTO ((struct client_state *,
1881			       struct client_lease *, int, int));
1882int dhcp_option_ev_name (char *, size_t, struct option *);
1883
1884void script_init PROTO ((struct client_state *, const char *,
1885			 struct string_list *));
1886void client_option_envadd (struct option_cache *, struct packet *,
1887			   struct lease *, struct client_state *,
1888			   struct option_state *, struct option_state *,
1889			   struct binding_scope **, struct universe *, void *);
1890void script_write_params PROTO ((struct client_state *,
1891				 const char *, struct client_lease *));
1892int script_go PROTO ((struct client_state *));
1893void client_envadd (struct client_state *,
1894		    const char *, const char *, const char *, ...)
1895	__attribute__((__format__(__printf__,4,5)));
1896
1897struct client_lease *packet_to_lease (struct packet *, struct client_state *);
1898void go_daemon PROTO ((void));
1899void write_client_pid_file PROTO ((void));
1900void client_location_changed PROTO ((void));
1901void do_release PROTO ((struct client_state *));
1902int dhclient_interface_shutdown_hook (struct interface_info *);
1903int dhclient_interface_discovery_hook (struct interface_info *);
1904isc_result_t dhclient_interface_startup_hook (struct interface_info *);
1905void client_dns_update_timeout (void *cp);
1906isc_result_t client_dns_update (struct client_state *client, int, int);
1907
1908/* db.c */
1909int write_lease PROTO ((struct lease *));
1910int write_host PROTO ((struct host_decl *));
1911#if defined (FAILOVER_PROTOCOL)
1912int write_failover_state (dhcp_failover_state_t *);
1913#endif
1914int db_printable PROTO ((const char *));
1915int db_printable_len PROTO ((const unsigned char *, unsigned));
1916void write_named_billing_class (const char *, unsigned, struct class *);
1917void write_billing_classes (void);
1918int write_billing_class PROTO ((struct class *));
1919void commit_leases_timeout PROTO ((void *));
1920int commit_leases PROTO ((void));
1921void db_startup PROTO ((int));
1922int new_lease_file PROTO ((void));
1923int group_writer (struct group_object *);
1924
1925/* packet.c */
1926u_int32_t checksum PROTO ((unsigned char *, unsigned, u_int32_t));
1927u_int32_t wrapsum PROTO ((u_int32_t));
1928void assemble_hw_header PROTO ((struct interface_info *, unsigned char *,
1929				unsigned *, struct hardware *));
1930void assemble_udp_ip_header PROTO ((struct interface_info *, unsigned char *,
1931				    unsigned *, u_int32_t, u_int32_t,
1932				    u_int32_t, unsigned char *, unsigned));
1933ssize_t decode_hw_header PROTO ((struct interface_info *, unsigned char *,
1934				 unsigned, struct hardware *));
1935ssize_t decode_udp_ip_header PROTO ((struct interface_info *, unsigned char *,
1936				     unsigned, struct sockaddr_in *,
1937				     unsigned, unsigned *));
1938
1939/* ethernet.c */
1940void assemble_ethernet_header PROTO ((struct interface_info *, unsigned char *,
1941				      unsigned *, struct hardware *));
1942ssize_t decode_ethernet_header PROTO ((struct interface_info *,
1943				       unsigned char *,
1944				       unsigned, struct hardware *));
1945
1946/* tr.c */
1947void assemble_tr_header PROTO ((struct interface_info *, unsigned char *,
1948				unsigned *, struct hardware *));
1949ssize_t decode_tr_header PROTO ((struct interface_info *,
1950				 unsigned char *,
1951				 unsigned, struct hardware *));
1952
1953/* dhxpxlt.c */
1954void convert_statement PROTO ((struct parse *));
1955void convert_host_statement PROTO ((struct parse *, jrefproto));
1956void convert_host_name PROTO ((struct parse *, jrefproto));
1957void convert_class_statement PROTO ((struct parse *, jrefproto, int));
1958void convert_class_decl PROTO ((struct parse *, jrefproto));
1959void convert_lease_time PROTO ((struct parse *, jrefproto, char *));
1960void convert_shared_net_statement PROTO ((struct parse *, jrefproto));
1961void convert_subnet_statement PROTO ((struct parse *, jrefproto));
1962void convert_subnet_decl PROTO ((struct parse *, jrefproto));
1963void convert_host_decl PROTO ((struct parse *, jrefproto));
1964void convert_hardware_decl PROTO ((struct parse *, jrefproto));
1965void convert_hardware_addr PROTO ((struct parse *, jrefproto));
1966void convert_filename_decl PROTO ((struct parse *, jrefproto));
1967void convert_servername_decl PROTO ((struct parse *, jrefproto));
1968void convert_ip_addr_or_hostname PROTO ((struct parse *, jrefproto, int));
1969void convert_fixed_addr_decl PROTO ((struct parse *, jrefproto));
1970void convert_option_decl PROTO ((struct parse *, jrefproto));
1971void convert_timestamp PROTO ((struct parse *, jrefproto));
1972void convert_lease_statement PROTO ((struct parse *, jrefproto));
1973void convert_address_range PROTO ((struct parse *, jrefproto));
1974void convert_date PROTO ((struct parse *, jrefproto, char *));
1975void convert_numeric_aggregate PROTO ((struct parse *, jrefproto, int, int, int, int));
1976void indent PROTO ((int));
1977
1978/* route.c */
1979void add_route_direct PROTO ((struct interface_info *, struct in_addr));
1980void add_route_net PROTO ((struct interface_info *, struct in_addr,
1981			   struct in_addr));
1982void add_route_default_gateway PROTO ((struct interface_info *,
1983				       struct in_addr));
1984void remove_routes PROTO ((struct in_addr));
1985void remove_if_route PROTO ((struct interface_info *, struct in_addr));
1986void remove_all_if_routes PROTO ((struct interface_info *));
1987void set_netmask PROTO ((struct interface_info *, struct in_addr));
1988void set_broadcast_addr PROTO ((struct interface_info *, struct in_addr));
1989void set_ip_address PROTO ((struct interface_info *, struct in_addr));
1990
1991/* clparse.c */
1992isc_result_t read_client_conf PROTO ((void));
1993int read_client_conf_file (const char *,
1994			   struct interface_info *, struct client_config *);
1995void read_client_leases PROTO ((void));
1996void parse_client_statement PROTO ((struct parse *, struct interface_info *,
1997				    struct client_config *));
1998int parse_X PROTO ((struct parse *, u_int8_t *, unsigned));
1999void parse_option_list PROTO ((struct parse *, u_int32_t **));
2000void parse_interface_declaration PROTO ((struct parse *,
2001					 struct client_config *, char *));
2002int interface_or_dummy PROTO ((struct interface_info **, const char *));
2003void make_client_state PROTO ((struct client_state **));
2004void make_client_config PROTO ((struct client_state *,
2005				struct client_config *));
2006void parse_client_lease_statement PROTO ((struct parse *, int));
2007void parse_client_lease_declaration PROTO ((struct parse *,
2008					    struct client_lease *,
2009					    struct interface_info **,
2010					    struct client_state **));
2011int parse_option_decl PROTO ((struct option_cache **, struct parse *));
2012void parse_string_list PROTO ((struct parse *, struct string_list **, int));
2013int parse_ip_addr PROTO ((struct parse *, struct iaddr *));
2014void parse_reject_statement PROTO ((struct parse *, struct client_config *));
2015
2016/* dhcrelay.c */
2017void relay PROTO ((struct interface_info *, struct dhcp_packet *, unsigned,
2018		   unsigned int, struct iaddr, struct hardware *));
2019int strip_relay_agent_options PROTO ((struct interface_info *,
2020				      struct interface_info **,
2021				      struct dhcp_packet *, unsigned));
2022int find_interface_by_agent_option PROTO ((struct dhcp_packet *,
2023					   struct interface_info **,
2024					   u_int8_t *, int));
2025int add_relay_agent_options PROTO ((struct interface_info *,
2026				    struct dhcp_packet *,
2027				    unsigned, struct in_addr));
2028
2029/* icmp.c */
2030OMAPI_OBJECT_ALLOC_DECL (icmp_state, struct icmp_state, dhcp_type_icmp)
2031extern struct icmp_state *icmp_state;
2032void icmp_startup PROTO ((int, void (*) PROTO ((struct iaddr,
2033						u_int8_t *, int))));
2034int icmp_readsocket PROTO ((omapi_object_t *));
2035int icmp_echorequest PROTO ((struct iaddr *));
2036isc_result_t icmp_echoreply PROTO ((omapi_object_t *));
2037
2038/* fddi.c */
2039#if defined (PACKET_ASSEMBLY) || defined (PACKET_DECODING)
2040void assemble_fddi_header (struct interface_info *,
2041	unsigned char *, unsigned *, struct hardware *);
2042ssize_t decode_fddi_header (struct interface_info *,
2043     unsigned char *, unsigned, struct hardware *);
2044#endif /* PACKET_ASSEMBLY || PACKET_DECODING */
2045
2046/* dns.c */
2047#if defined (NSUPDATE)
2048isc_result_t find_tsig_key (ns_tsig_key **, const char *, struct dns_zone *);
2049void tkey_free (ns_tsig_key **);
2050#endif
2051isc_result_t enter_dns_zone (struct dns_zone *);
2052isc_result_t dns_zone_lookup (struct dns_zone **, const char *);
2053int dns_zone_dereference PROTO ((struct dns_zone **, const char *, int));
2054#if defined (NSUPDATE)
2055isc_result_t find_cached_zone (const char *, ns_class, char *,
2056			       size_t, struct in_addr *, int, int *,
2057			       struct dns_zone **);
2058void forget_zone (struct dns_zone **);
2059void repudiate_zone (struct dns_zone **);
2060void cache_found_zone (ns_class, char *, struct in_addr *, int);
2061int get_dhcid (struct data_string *, int, const u_int8_t *, unsigned);
2062isc_result_t ddns_update_a (struct data_string *, struct iaddr,
2063			    struct data_string *, unsigned long, int);
2064isc_result_t ddns_remove_a (struct data_string *,
2065			    struct iaddr, struct data_string *);
2066#endif /* NSUPDATE */
2067
2068/* resolv.c */
2069extern char path_resolv_conf [];
2070struct name_server *name_servers;
2071struct domain_search_list *domains;
2072
2073void read_resolv_conf PROTO ((TIME));
2074struct name_server *first_name_server PROTO ((void));
2075
2076/* inet_addr.c */
2077#ifdef NEED_INET_ATON
2078int inet_aton PROTO ((const char *, struct in_addr *));
2079#endif
2080
2081/* class.c */
2082extern int have_billing_classes;
2083struct class unknown_class;
2084struct class known_class;
2085struct collection default_collection;
2086struct collection *collections;
2087struct executable_statement *default_classification_rules;
2088
2089void classification_setup PROTO ((void));
2090void classify_client PROTO ((struct packet *));
2091int check_collection PROTO ((struct packet *, struct lease *,
2092			     struct collection *));
2093void classify PROTO ((struct packet *, struct class *));
2094isc_result_t find_class PROTO ((struct class **, const char *,
2095				const char *, int));
2096int unbill_class PROTO ((struct lease *, struct class *));
2097int bill_class PROTO ((struct lease *, struct class *));
2098
2099/* execute.c */
2100int execute_statements PROTO ((struct binding_value **result,
2101			       struct packet *, struct lease *,
2102			       struct client_state *,
2103			       struct option_state *, struct option_state *,
2104			       struct binding_scope **,
2105			       struct executable_statement *));
2106void execute_statements_in_scope PROTO ((struct binding_value **result,
2107					 struct packet *, struct lease *,
2108					 struct client_state *,
2109					 struct option_state *,
2110					 struct option_state *,
2111					 struct binding_scope **,
2112					 struct group *, struct group *));
2113int executable_statement_dereference PROTO ((struct executable_statement **,
2114					     const char *, int));
2115void write_statements (FILE *, struct executable_statement *, int);
2116int find_matching_case (struct executable_statement **,
2117			struct packet *, struct lease *, struct client_state *,
2118			struct option_state *, struct option_state *,
2119			struct binding_scope **,
2120			struct expression *, struct executable_statement *);
2121int executable_statement_foreach (struct executable_statement *,
2122				  int (*) (struct executable_statement *,
2123					   void *, int), void *, int);
2124
2125/* comapi.c */
2126extern omapi_object_type_t *dhcp_type_interface;
2127extern omapi_object_type_t *dhcp_type_group;
2128extern omapi_object_type_t *dhcp_type_shared_network;
2129extern omapi_object_type_t *dhcp_type_subnet;
2130extern omapi_object_type_t *dhcp_type_control;
2131extern dhcp_control_object_t *dhcp_control_object;
2132
2133void dhcp_common_objects_setup (void);
2134
2135isc_result_t dhcp_group_set_value  (omapi_object_t *, omapi_object_t *,
2136				    omapi_data_string_t *,
2137				    omapi_typed_data_t *);
2138isc_result_t dhcp_group_get_value (omapi_object_t *, omapi_object_t *,
2139				   omapi_data_string_t *,
2140				   omapi_value_t **);
2141isc_result_t dhcp_group_destroy (omapi_object_t *, const char *, int);
2142isc_result_t dhcp_group_signal_handler (omapi_object_t *,
2143					const char *, va_list);
2144isc_result_t dhcp_group_stuff_values (omapi_object_t *,
2145				      omapi_object_t *,
2146				      omapi_object_t *);
2147isc_result_t dhcp_group_lookup (omapi_object_t **,
2148				omapi_object_t *, omapi_object_t *);
2149isc_result_t dhcp_group_create (omapi_object_t **,
2150				omapi_object_t *);
2151isc_result_t dhcp_group_remove (omapi_object_t *,
2152				omapi_object_t *);
2153
2154isc_result_t dhcp_control_set_value  (omapi_object_t *, omapi_object_t *,
2155				      omapi_data_string_t *,
2156				      omapi_typed_data_t *);
2157isc_result_t dhcp_control_get_value (omapi_object_t *, omapi_object_t *,
2158				     omapi_data_string_t *,
2159				     omapi_value_t **);
2160isc_result_t dhcp_control_destroy (omapi_object_t *, const char *, int);
2161isc_result_t dhcp_control_signal_handler (omapi_object_t *,
2162					  const char *, va_list);
2163isc_result_t dhcp_control_stuff_values (omapi_object_t *,
2164					omapi_object_t *,
2165					omapi_object_t *);
2166isc_result_t dhcp_control_lookup (omapi_object_t **,
2167				  omapi_object_t *, omapi_object_t *);
2168isc_result_t dhcp_control_create (omapi_object_t **,
2169				  omapi_object_t *);
2170isc_result_t dhcp_control_remove (omapi_object_t *,
2171				  omapi_object_t *);
2172
2173isc_result_t dhcp_subnet_set_value  (omapi_object_t *, omapi_object_t *,
2174				     omapi_data_string_t *,
2175				     omapi_typed_data_t *);
2176isc_result_t dhcp_subnet_get_value (omapi_object_t *, omapi_object_t *,
2177				    omapi_data_string_t *,
2178				    omapi_value_t **);
2179isc_result_t dhcp_subnet_destroy (omapi_object_t *, const char *, int);
2180isc_result_t dhcp_subnet_signal_handler (omapi_object_t *,
2181					 const char *, va_list);
2182isc_result_t dhcp_subnet_stuff_values (omapi_object_t *,
2183				       omapi_object_t *,
2184				       omapi_object_t *);
2185isc_result_t dhcp_subnet_lookup (omapi_object_t **,
2186				 omapi_object_t *, omapi_object_t *);
2187isc_result_t dhcp_subnet_create (omapi_object_t **,
2188				 omapi_object_t *);
2189isc_result_t dhcp_subnet_remove (omapi_object_t *,
2190				 omapi_object_t *);
2191
2192isc_result_t dhcp_shared_network_set_value  (omapi_object_t *,
2193					     omapi_object_t *,
2194					     omapi_data_string_t *,
2195					     omapi_typed_data_t *);
2196isc_result_t dhcp_shared_network_get_value (omapi_object_t *,
2197					    omapi_object_t *,
2198					    omapi_data_string_t *,
2199					    omapi_value_t **);
2200isc_result_t dhcp_shared_network_destroy (omapi_object_t *, const char *, int);
2201isc_result_t dhcp_shared_network_signal_handler (omapi_object_t *,
2202						 const char *, va_list);
2203isc_result_t dhcp_shared_network_stuff_values (omapi_object_t *,
2204					       omapi_object_t *,
2205					       omapi_object_t *);
2206isc_result_t dhcp_shared_network_lookup (omapi_object_t **,
2207					 omapi_object_t *, omapi_object_t *);
2208isc_result_t dhcp_shared_network_create (omapi_object_t **,
2209					 omapi_object_t *);
2210isc_result_t dhcp_shared_network_remove (omapi_object_t *,
2211					 omapi_object_t *);
2212
2213/* omapi.c */
2214extern int (*dhcp_interface_shutdown_hook) (struct interface_info *);
2215
2216extern omapi_object_type_t *dhcp_type_lease;
2217extern omapi_object_type_t *dhcp_type_pool;
2218extern omapi_object_type_t *dhcp_type_class;
2219
2220#if defined (FAILOVER_PROTOCOL)
2221extern omapi_object_type_t *dhcp_type_failover_state;
2222extern omapi_object_type_t *dhcp_type_failover_link;
2223extern omapi_object_type_t *dhcp_type_failover_listener;
2224#endif
2225
2226void dhcp_db_objects_setup (void);
2227
2228isc_result_t dhcp_lease_set_value  (omapi_object_t *, omapi_object_t *,
2229				    omapi_data_string_t *,
2230				    omapi_typed_data_t *);
2231isc_result_t dhcp_lease_get_value (omapi_object_t *, omapi_object_t *,
2232				   omapi_data_string_t *,
2233				   omapi_value_t **);
2234isc_result_t dhcp_lease_destroy (omapi_object_t *, const char *, int);
2235isc_result_t dhcp_lease_signal_handler (omapi_object_t *,
2236					const char *, va_list);
2237isc_result_t dhcp_lease_stuff_values (omapi_object_t *,
2238				      omapi_object_t *,
2239				      omapi_object_t *);
2240isc_result_t dhcp_lease_lookup (omapi_object_t **,
2241				omapi_object_t *, omapi_object_t *);
2242isc_result_t dhcp_lease_create (omapi_object_t **,
2243				omapi_object_t *);
2244isc_result_t dhcp_lease_remove (omapi_object_t *,
2245				omapi_object_t *);
2246isc_result_t dhcp_group_set_value  (omapi_object_t *, omapi_object_t *,
2247				    omapi_data_string_t *,
2248				    omapi_typed_data_t *);
2249isc_result_t dhcp_group_get_value (omapi_object_t *, omapi_object_t *,
2250				   omapi_data_string_t *,
2251				   omapi_value_t **);
2252isc_result_t dhcp_group_destroy (omapi_object_t *, const char *, int);
2253isc_result_t dhcp_group_signal_handler (omapi_object_t *,
2254					const char *, va_list);
2255isc_result_t dhcp_group_stuff_values (omapi_object_t *,
2256				      omapi_object_t *,
2257				      omapi_object_t *);
2258isc_result_t dhcp_group_lookup (omapi_object_t **,
2259				omapi_object_t *, omapi_object_t *);
2260isc_result_t dhcp_group_create (omapi_object_t **,
2261				omapi_object_t *);
2262isc_result_t dhcp_group_remove (omapi_object_t *,
2263				omapi_object_t *);
2264isc_result_t dhcp_host_set_value  (omapi_object_t *, omapi_object_t *,
2265				   omapi_data_string_t *,
2266				   omapi_typed_data_t *);
2267isc_result_t dhcp_host_get_value (omapi_object_t *, omapi_object_t *,
2268				  omapi_data_string_t *,
2269				  omapi_value_t **);
2270isc_result_t dhcp_host_destroy (omapi_object_t *, const char *, int);
2271isc_result_t dhcp_host_signal_handler (omapi_object_t *,
2272				       const char *, va_list);
2273isc_result_t dhcp_host_stuff_values (omapi_object_t *,
2274				     omapi_object_t *,
2275				     omapi_object_t *);
2276isc_result_t dhcp_host_lookup (omapi_object_t **,
2277			       omapi_object_t *, omapi_object_t *);
2278isc_result_t dhcp_host_create (omapi_object_t **,
2279			       omapi_object_t *);
2280isc_result_t dhcp_host_remove (omapi_object_t *,
2281			       omapi_object_t *);
2282isc_result_t dhcp_pool_set_value  (omapi_object_t *, omapi_object_t *,
2283				   omapi_data_string_t *,
2284				   omapi_typed_data_t *);
2285isc_result_t dhcp_pool_get_value (omapi_object_t *, omapi_object_t *,
2286				  omapi_data_string_t *,
2287				  omapi_value_t **);
2288isc_result_t dhcp_pool_destroy (omapi_object_t *, const char *, int);
2289isc_result_t dhcp_pool_signal_handler (omapi_object_t *,
2290				       const char *, va_list);
2291isc_result_t dhcp_pool_stuff_values (omapi_object_t *,
2292				     omapi_object_t *,
2293				     omapi_object_t *);
2294isc_result_t dhcp_pool_lookup (omapi_object_t **,
2295			       omapi_object_t *, omapi_object_t *);
2296isc_result_t dhcp_pool_create (omapi_object_t **,
2297			       omapi_object_t *);
2298isc_result_t dhcp_pool_remove (omapi_object_t *,
2299			       omapi_object_t *);
2300isc_result_t dhcp_class_set_value  (omapi_object_t *, omapi_object_t *,
2301				    omapi_data_string_t *,
2302				    omapi_typed_data_t *);
2303isc_result_t dhcp_class_get_value (omapi_object_t *, omapi_object_t *,
2304				   omapi_data_string_t *,
2305				   omapi_value_t **);
2306isc_result_t dhcp_class_destroy (omapi_object_t *, const char *, int);
2307isc_result_t dhcp_class_signal_handler (omapi_object_t *,
2308					const char *, va_list);
2309isc_result_t dhcp_class_stuff_values (omapi_object_t *,
2310				      omapi_object_t *,
2311				      omapi_object_t *);
2312isc_result_t dhcp_class_lookup (omapi_object_t **,
2313				omapi_object_t *, omapi_object_t *);
2314isc_result_t dhcp_class_create (omapi_object_t **,
2315				omapi_object_t *);
2316isc_result_t dhcp_class_remove (omapi_object_t *,
2317				omapi_object_t *);
2318isc_result_t dhcp_subclass_set_value  (omapi_object_t *, omapi_object_t *,
2319				       omapi_data_string_t *,
2320				       omapi_typed_data_t *);
2321isc_result_t dhcp_subclass_get_value (omapi_object_t *, omapi_object_t *,
2322				      omapi_data_string_t *,
2323				      omapi_value_t **);
2324isc_result_t dhcp_subclass_destroy (omapi_object_t *, const char *, int);
2325isc_result_t dhcp_subclass_signal_handler (omapi_object_t *,
2326					   const char *, va_list);
2327isc_result_t dhcp_subclass_stuff_values (omapi_object_t *,
2328					 omapi_object_t *,
2329					 omapi_object_t *);
2330isc_result_t dhcp_subclass_lookup (omapi_object_t **,
2331				   omapi_object_t *, omapi_object_t *);
2332isc_result_t dhcp_subclass_create (omapi_object_t **,
2333				   omapi_object_t *);
2334isc_result_t dhcp_subclass_remove (omapi_object_t *,
2335				   omapi_object_t *);
2336isc_result_t dhcp_shared_network_set_value  (omapi_object_t *,
2337					     omapi_object_t *,
2338					     omapi_data_string_t *,
2339					     omapi_typed_data_t *);
2340isc_result_t dhcp_shared_network_get_value (omapi_object_t *, omapi_object_t *,
2341					    omapi_data_string_t *,
2342					    omapi_value_t **);
2343isc_result_t dhcp_shared_network_destroy (omapi_object_t *, const char *, int);
2344isc_result_t dhcp_shared_network_signal_handler (omapi_object_t *,
2345						 const char *, va_list);
2346isc_result_t dhcp_shared_network_stuff_values (omapi_object_t *,
2347					       omapi_object_t *,
2348					       omapi_object_t *);
2349isc_result_t dhcp_shared_network_lookup (omapi_object_t **,
2350					 omapi_object_t *, omapi_object_t *);
2351isc_result_t dhcp_shared_network_create (omapi_object_t **,
2352					 omapi_object_t *);
2353isc_result_t dhcp_subnet_set_value  (omapi_object_t *, omapi_object_t *,
2354				     omapi_data_string_t *,
2355				     omapi_typed_data_t *);
2356isc_result_t dhcp_subnet_get_value (omapi_object_t *, omapi_object_t *,
2357				    omapi_data_string_t *,
2358				    omapi_value_t **);
2359isc_result_t dhcp_subnet_destroy (omapi_object_t *, const char *, int);
2360isc_result_t dhcp_subnet_signal_handler (omapi_object_t *,
2361					 const char *, va_list);
2362isc_result_t dhcp_subnet_stuff_values (omapi_object_t *,
2363				       omapi_object_t *,
2364				       omapi_object_t *);
2365isc_result_t dhcp_subnet_lookup (omapi_object_t **,
2366				 omapi_object_t *, omapi_object_t *);
2367isc_result_t dhcp_subnet_create (omapi_object_t **,
2368				 omapi_object_t *);
2369isc_result_t dhcp_interface_set_value (omapi_object_t *,
2370				       omapi_object_t *,
2371				       omapi_data_string_t *,
2372				       omapi_typed_data_t *);
2373isc_result_t dhcp_interface_get_value (omapi_object_t *,
2374				       omapi_object_t *,
2375				       omapi_data_string_t *,
2376				       omapi_value_t **);
2377isc_result_t dhcp_interface_destroy (omapi_object_t *,
2378				     const char *, int);
2379isc_result_t dhcp_interface_signal_handler (omapi_object_t *,
2380					    const char *,
2381					    va_list ap);
2382isc_result_t dhcp_interface_stuff_values (omapi_object_t *,
2383					  omapi_object_t *,
2384					  omapi_object_t *);
2385isc_result_t dhcp_interface_lookup (omapi_object_t **,
2386				    omapi_object_t *,
2387				    omapi_object_t *);
2388isc_result_t dhcp_interface_create (omapi_object_t **,
2389				    omapi_object_t *);
2390isc_result_t dhcp_interface_remove (omapi_object_t *,
2391				    omapi_object_t *);
2392void interface_stash (struct interface_info *);
2393void interface_snorf (struct interface_info *, int);
2394
2395isc_result_t binding_scope_set_value (struct binding_scope *, int,
2396				      omapi_data_string_t *,
2397				      omapi_typed_data_t *);
2398isc_result_t binding_scope_get_value (omapi_value_t **,
2399				      struct binding_scope *,
2400				      omapi_data_string_t *);
2401isc_result_t binding_scope_stuff_values (omapi_object_t *,
2402					 struct binding_scope *);
2403
2404/* mdb.c */
2405
2406extern struct subnet *subnets;
2407extern struct shared_network *shared_networks;
2408extern host_hash_t *host_hw_addr_hash;
2409extern host_hash_t *host_uid_hash;
2410extern host_hash_t *host_name_hash;
2411extern lease_hash_t *lease_uid_hash;
2412extern lease_hash_t *lease_ip_addr_hash;
2413extern lease_hash_t *lease_hw_addr_hash;
2414
2415extern omapi_object_type_t *dhcp_type_host;
2416
2417isc_result_t enter_host PROTO ((struct host_decl *, int, int));
2418isc_result_t delete_host PROTO ((struct host_decl *, int));
2419int find_hosts_by_haddr PROTO ((struct host_decl **, int,
2420				const unsigned char *, unsigned,
2421				const char *, int));
2422int find_hosts_by_uid PROTO ((struct host_decl **, const unsigned char *,
2423			      unsigned, const char *, int));
2424int find_host_for_network PROTO ((struct subnet **, struct host_decl **,
2425				  struct iaddr *, struct shared_network *));
2426void new_address_range PROTO ((struct parse *, struct iaddr, struct iaddr,
2427			       struct subnet *, struct pool *,
2428			       struct lease **));
2429isc_result_t dhcp_lease_free (omapi_object_t *, const char *, int);
2430isc_result_t dhcp_lease_get (omapi_object_t **, const char *, int);
2431int find_grouped_subnet PROTO ((struct subnet **, struct shared_network *,
2432				struct iaddr, const char *, int));
2433int find_subnet (struct subnet **, struct iaddr, const char *, int);
2434void enter_shared_network PROTO ((struct shared_network *));
2435void new_shared_network_interface PROTO ((struct parse *,
2436					  struct shared_network *,
2437					  const char *));
2438int subnet_inner_than PROTO ((struct subnet *, struct subnet *, int));
2439void enter_subnet PROTO ((struct subnet *));
2440void enter_lease PROTO ((struct lease *));
2441int supersede_lease PROTO ((struct lease *, struct lease *, int, int, int));
2442void make_binding_state_transition (struct lease *);
2443int lease_copy PROTO ((struct lease **, struct lease *, const char *, int));
2444void release_lease PROTO ((struct lease *, struct packet *));
2445void abandon_lease PROTO ((struct lease *, const char *));
2446void dissociate_lease PROTO ((struct lease *));
2447void pool_timer PROTO ((void *));
2448int find_lease_by_uid PROTO ((struct lease **, const unsigned char *,
2449			      unsigned, const char *, int));
2450int find_lease_by_hw_addr PROTO ((struct lease **, const unsigned char *,
2451				  unsigned, const char *, int));
2452int find_lease_by_ip_addr PROTO ((struct lease **, struct iaddr,
2453				  const char *, int));
2454void uid_hash_add PROTO ((struct lease *));
2455void uid_hash_delete PROTO ((struct lease *));
2456void hw_hash_add PROTO ((struct lease *));
2457void hw_hash_delete PROTO ((struct lease *));
2458int write_leases PROTO ((void));
2459int lease_enqueue (struct lease *);
2460void lease_instantiate (const unsigned char *, unsigned, struct lease *);
2461void expire_all_pools PROTO ((void));
2462void dump_subnets PROTO ((void));
2463#if defined (DEBUG_MEMORY_LEAKAGE) || \
2464		defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
2465void free_everything (void);
2466#endif
2467
2468/* nsupdate.c */
2469char *ddns_rev_name (struct lease *, struct lease_state *, struct packet *);
2470char *ddns_fwd_name (struct lease *, struct lease_state *, struct packet *);
2471int nsupdateA (const char *, const unsigned char *, u_int32_t, int);
2472int nsupdatePTR (const char *, const unsigned char *, u_int32_t, int);
2473void nsupdate (struct lease *, struct lease_state *, struct packet *, int);
2474int updateA (const struct data_string *, const struct data_string *,
2475	     unsigned int, struct lease *);
2476int updatePTR (const struct data_string *, const struct data_string *,
2477	       unsigned int, struct lease *);
2478int deleteA (const struct data_string *, const struct data_string *,
2479	     struct lease *);
2480int deletePTR (const struct data_string *, const struct data_string *,
2481	       struct lease *);
2482
2483/* failover.c */
2484#if defined (FAILOVER_PROTOCOL)
2485extern dhcp_failover_state_t *failover_states;
2486void dhcp_failover_startup PROTO ((void));
2487int dhcp_failover_write_all_states (void);
2488isc_result_t enter_failover_peer PROTO ((dhcp_failover_state_t *));
2489isc_result_t find_failover_peer PROTO ((dhcp_failover_state_t **,
2490					const char *, const char *, int));
2491isc_result_t dhcp_failover_link_initiate PROTO ((omapi_object_t *));
2492isc_result_t dhcp_failover_link_signal PROTO ((omapi_object_t *,
2493					       const char *, va_list));
2494isc_result_t dhcp_failover_link_set_value PROTO ((omapi_object_t *,
2495						  omapi_object_t *,
2496						  omapi_data_string_t *,
2497						  omapi_typed_data_t *));
2498isc_result_t dhcp_failover_link_get_value PROTO ((omapi_object_t *,
2499						  omapi_object_t *,
2500						  omapi_data_string_t *,
2501						  omapi_value_t **));
2502isc_result_t dhcp_failover_link_destroy PROTO ((omapi_object_t *,
2503						const char *, int));
2504isc_result_t dhcp_failover_link_stuff_values PROTO ((omapi_object_t *,
2505						     omapi_object_t *,
2506						     omapi_object_t *));
2507isc_result_t dhcp_failover_listen PROTO ((omapi_object_t *));
2508
2509isc_result_t dhcp_failover_listener_signal PROTO ((omapi_object_t *,
2510						   const char *,
2511						   va_list));
2512isc_result_t dhcp_failover_listener_set_value PROTO ((omapi_object_t *,
2513						      omapi_object_t *,
2514						      omapi_data_string_t *,
2515						      omapi_typed_data_t *));
2516isc_result_t dhcp_failover_listener_get_value PROTO ((omapi_object_t *,
2517						      omapi_object_t *,
2518						      omapi_data_string_t *,
2519						      omapi_value_t **));
2520isc_result_t dhcp_failover_listener_destroy PROTO ((omapi_object_t *,
2521						    const char *, int));
2522isc_result_t dhcp_failover_listener_stuff PROTO ((omapi_object_t *,
2523						  omapi_object_t *,
2524						  omapi_object_t *));
2525isc_result_t dhcp_failover_register PROTO ((omapi_object_t *));
2526isc_result_t dhcp_failover_state_signal PROTO ((omapi_object_t *,
2527						const char *, va_list));
2528isc_result_t dhcp_failover_state_transition (dhcp_failover_state_t *,
2529					     const char *);
2530isc_result_t dhcp_failover_set_service_state (dhcp_failover_state_t *state);
2531isc_result_t dhcp_failover_set_state (dhcp_failover_state_t *,
2532				      enum failover_state);
2533isc_result_t dhcp_failover_peer_state_changed (dhcp_failover_state_t *,
2534					       failover_message_t *);
2535int dhcp_failover_pool_rebalance (dhcp_failover_state_t *);
2536int dhcp_failover_pool_check (struct pool *);
2537int dhcp_failover_state_pool_check (dhcp_failover_state_t *);
2538void dhcp_failover_timeout (void *);
2539void dhcp_failover_send_contact (void *);
2540isc_result_t dhcp_failover_send_state (dhcp_failover_state_t *);
2541isc_result_t dhcp_failover_send_updates (dhcp_failover_state_t *);
2542int dhcp_failover_queue_update (struct lease *, int);
2543int dhcp_failover_send_acks (dhcp_failover_state_t *);
2544void dhcp_failover_toack_queue_timeout (void *);
2545int dhcp_failover_queue_ack (dhcp_failover_state_t *, failover_message_t *msg);
2546void dhcp_failover_ack_queue_remove (dhcp_failover_state_t *, struct lease *);
2547isc_result_t dhcp_failover_state_set_value PROTO ((omapi_object_t *,
2548						   omapi_object_t *,
2549						   omapi_data_string_t *,
2550						   omapi_typed_data_t *));
2551void dhcp_failover_keepalive (void *);
2552void dhcp_failover_reconnect (void *);
2553void dhcp_failover_startup_timeout (void *);
2554void dhcp_failover_link_startup_timeout (void *);
2555void dhcp_failover_listener_restart (void *);
2556isc_result_t dhcp_failover_state_get_value PROTO ((omapi_object_t *,
2557						   omapi_object_t *,
2558						   omapi_data_string_t *,
2559						   omapi_value_t **));
2560isc_result_t dhcp_failover_state_destroy PROTO ((omapi_object_t *,
2561						 const char *, int));
2562isc_result_t dhcp_failover_state_stuff PROTO ((omapi_object_t *,
2563					       omapi_object_t *,
2564					       omapi_object_t *));
2565isc_result_t dhcp_failover_state_lookup PROTO ((omapi_object_t **,
2566						omapi_object_t *,
2567						omapi_object_t *));
2568isc_result_t dhcp_failover_state_create PROTO ((omapi_object_t **,
2569						omapi_object_t *));
2570isc_result_t dhcp_failover_state_remove PROTO ((omapi_object_t *,
2571					       omapi_object_t *));
2572int dhcp_failover_state_match (dhcp_failover_state_t *, u_int8_t *, unsigned);
2573const char *dhcp_failover_reject_reason_print (int);
2574const char *dhcp_failover_state_name_print (enum failover_state);
2575const char *dhcp_failover_message_name (unsigned);
2576const char *dhcp_failover_option_name (unsigned);
2577failover_option_t *dhcp_failover_option_printf (unsigned, char *,
2578						unsigned *,
2579						unsigned,
2580						const char *, ...)
2581	__attribute__((__format__(__printf__,5,6)));
2582failover_option_t *dhcp_failover_make_option (unsigned, char *,
2583					      unsigned *, unsigned, ...);
2584isc_result_t dhcp_failover_put_message (dhcp_failover_link_t *,
2585					omapi_object_t *, int, ...);
2586isc_result_t dhcp_failover_send_connect PROTO ((omapi_object_t *));
2587isc_result_t dhcp_failover_send_connectack PROTO ((omapi_object_t *,
2588						   dhcp_failover_state_t *,
2589						   int, const char *));
2590isc_result_t dhcp_failover_send_disconnect PROTO ((omapi_object_t *,
2591						   int, const char *));
2592isc_result_t dhcp_failover_send_bind_update (dhcp_failover_state_t *,
2593					     struct lease *);
2594isc_result_t dhcp_failover_send_bind_ack (dhcp_failover_state_t *,
2595					  failover_message_t *,
2596					  int, const char *);
2597isc_result_t dhcp_failover_send_poolreq (dhcp_failover_state_t *);
2598isc_result_t dhcp_failover_send_poolresp (dhcp_failover_state_t *, int);
2599isc_result_t dhcp_failover_send_update_request (dhcp_failover_state_t *);
2600isc_result_t dhcp_failover_send_update_request_all (dhcp_failover_state_t *);
2601isc_result_t dhcp_failover_send_update_done (dhcp_failover_state_t *);
2602isc_result_t dhcp_failover_process_bind_update (dhcp_failover_state_t *,
2603						failover_message_t *);
2604isc_result_t dhcp_failover_process_bind_ack (dhcp_failover_state_t *,
2605					     failover_message_t *);
2606isc_result_t dhcp_failover_generate_update_queue (dhcp_failover_state_t *,
2607						  int);
2608isc_result_t dhcp_failover_process_update_request (dhcp_failover_state_t *,
2609						   failover_message_t *);
2610isc_result_t dhcp_failover_process_update_request_all (dhcp_failover_state_t *,
2611						       failover_message_t *);
2612isc_result_t dhcp_failover_process_update_done (dhcp_failover_state_t *,
2613						failover_message_t *);
2614void dhcp_failover_recover_done (void *);
2615void failover_print PROTO ((char *, unsigned *, unsigned, const char *));
2616void update_partner PROTO ((struct lease *));
2617int load_balance_mine (struct packet *, dhcp_failover_state_t *);
2618binding_state_t normal_binding_state_transition_check (struct lease *,
2619						       dhcp_failover_state_t *,
2620						       binding_state_t,
2621						       u_int32_t);
2622binding_state_t
2623conflict_binding_state_transition_check (struct lease *,
2624					 dhcp_failover_state_t *,
2625					 binding_state_t, u_int32_t);
2626int lease_mine_to_reallocate (struct lease *);
2627
2628OMAPI_OBJECT_ALLOC_DECL (dhcp_failover_state, dhcp_failover_state_t,
2629			 dhcp_type_failover_state)
2630OMAPI_OBJECT_ALLOC_DECL (dhcp_failover_listener, dhcp_failover_listener_t,
2631			 dhcp_type_failover_listener)
2632OMAPI_OBJECT_ALLOC_DECL (dhcp_failover_link, dhcp_failover_link_t,
2633			 dhcp_type_failover_link)
2634#endif /* FAILOVER_PROTOCOL */
2635
2636const char *binding_state_print (enum failover_state);
2637