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