]> git.ipfire.org Git - thirdparty/dhcp.git/blame - includes/dhcpd.h
[master] Fixed memory leask in omapi dereferencing
[thirdparty/dhcp.git] / includes / dhcpd.h
CommitLineData
d7837182
TL
1/* dhcpd.h
2
3 Definitions for dhcpd... */
4
5/*
fb98e02e 6 * Copyright (c) 2004-2015 by Internet Systems Consortium, Inc. ("ISC")
98311e4b 7 * Copyright (c) 1996-2003 by Internet Software Consortium
d7837182 8 *
98311e4b
DH
9 * Permission to use, copy, modify, and distribute this software for any
10 * purpose with or without fee is hereby granted, provided that the above
11 * copyright notice and this permission notice appear in all copies.
d7837182 12 *
98311e4b
DH
13 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
14 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
16 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
19 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
d7837182 20 *
98311e4b
DH
21 * Internet Systems Consortium, Inc.
22 * 950 Charter Street
23 * Redwood City, CA 94063
24 * <info@isc.org>
2c85ac9b 25 * https://www.isc.org/
49733f31 26 *
d7837182
TL
27 */
28
01fa619f
SR
29/*! \file includes/dhcpd.h */
30
fe5b0fdd 31#include "config.h"
98bd7ca0 32
0c7802b1 33#ifndef __CYGWIN32__
d7837182 34#include <sys/types.h>
d7837182
TL
35#include <netinet/in.h>
36#include <sys/socket.h>
5a526cf8 37#include <sys/un.h>
d7837182 38#include <arpa/inet.h>
59112e84 39#include <errno.h>
972ab2aa 40
d7837182 41#include <netdb.h>
0c7802b1
TL
42#else
43#define fd_set cygwin_fd_set
44#include <sys/types.h>
45#endif
176c2a7d 46#include <stddef.h>
d7837182
TL
47#include <fcntl.h>
48#include <stdio.h>
089fb364 49#include <unistd.h>
8fdfeffe 50#include <string.h>
089fb364
TL
51#include <stdlib.h>
52#include <sys/stat.h>
66eaae18 53#include <sys/mman.h>
089fb364 54#include <ctype.h>
97ca1699 55#include <time.h>
089fb364 56
fe5b0fdd 57#include <net/if.h>
b8c0eda0 58#undef FDDI
fe5b0fdd
DH
59#include <net/route.h>
60#include <net/if_arp.h>
627ad6d6 61#if HAVE_NET_IF_DL_H
6dd7efa2
DH
62# include <net/if_dl.h>
63#endif
fe5b0fdd
DH
64
65#include <setjmp.h>
66
2f620dce 67#include "cdefs.h"
a8b53b42 68#include "osdep.h"
e55017af
TL
69
70#include "arpa/nameser.h"
98bf1607
SR
71
72#include "minires.h"
e55017af 73
98311e4b
DH
74struct hash_table;
75typedef struct hash_table group_hash_t;
76typedef struct hash_table universe_hash_t;
f7fdb216
DH
77typedef struct hash_table option_name_hash_t;
78typedef struct hash_table option_code_hash_t;
98311e4b 79typedef struct hash_table dns_zone_hash_t;
6708d944
DH
80typedef struct hash_table lease_ip_hash_t;
81typedef struct hash_table lease_id_hash_t;
98311e4b
DH
82typedef struct hash_table host_hash_t;
83typedef struct hash_table class_hash_t;
84
fe5b0fdd
DH
85typedef time_t TIME;
86
87#ifndef EOL
88#define EOL '\n'
89#endif
90
98bf1607
SR
91#include <omapip/isclib.h>
92#include <omapip/result.h>
93
d7837182 94#include "dhcp.h"
98bd7ca0 95#include "dhcp6.h"
2b9b6ff7 96#include "statement.h"
d7837182 97#include "tree.h"
089fb364 98#include "inet.h"
fde86d2d 99#include "dhctoken.h"
d7837182 100
400c0b19 101#include <omapip/omapip_p.h>
4fe74d72 102
33692791
DH
103#if defined(LDAP_CONFIGURATION)
104# include <ldap.h>
105# include <sys/utsname.h> /* for uname() */
106#endif
107
f7fdb216 108#if !defined (BYTE_NAME_HASH_SIZE)
20ae1aff 109# define BYTE_NAME_HASH_SIZE 401 /* Default would be ridiculous. */
f7fdb216
DH
110#endif
111#if !defined (BYTE_CODE_HASH_SIZE)
20ae1aff 112# define BYTE_CODE_HASH_SIZE 254 /* Default would be ridiculous. */
f7fdb216
DH
113#endif
114
6708d944
DH
115/* Although it is highly improbable that a 16-bit option space might
116 * actually use 2^16 actual defined options, it is the worst case
117 * scenario we must prepare for. Having 4 options per bucket in this
118 * case is pretty reasonable.
119 */
f7fdb216 120#if !defined (WORD_NAME_HASH_SIZE)
6708d944 121# define WORD_NAME_HASH_SIZE 20479
f7fdb216
DH
122#endif
123#if !defined (WORD_CODE_HASH_SIZE)
6708d944 124# define WORD_CODE_HASH_SIZE 16384
f7fdb216
DH
125#endif
126
6708d944 127/* Not only is it improbable that the 32-bit spaces might actually use 2^32
20ae1aff 128 * defined options, it is infeasible. It would be best for this kind of
6708d944
DH
129 * space to be dynamically sized. Instead we size it at the word hash's
130 * level.
131 */
f7fdb216
DH
132#if !defined (QUAD_NAME_HASH_SIZE)
133# define QUAD_NAME_HASH_SIZE WORD_NAME_HASH_SIZE
134#endif
135#if !defined (QUAD_CODE_HASH_SIZE)
136# define QUAD_CODE_HASH_SIZE WORD_CODE_HASH_SIZE
137#endif
138
139#if !defined (DNS_HASH_SIZE)
140# define DNS_HASH_SIZE 0 /* Default. */
141#endif
142
143/* Default size to use for name/code hashes on user-defined option spaces. */
144#if !defined (DEFAULT_SPACE_HASH_SIZE)
145# define DEFAULT_SPACE_HASH_SIZE 11
146#endif
147
148#if !defined (NWIP_HASH_SIZE)
6708d944 149# define NWIP_HASH_SIZE 17 /* A really small table. */
f7fdb216
DH
150#endif
151
152#if !defined (FQDN_HASH_SIZE)
20ae1aff 153# define FQDN_HASH_SIZE 13 /* A ridiculously small table. */
f7fdb216
DH
154#endif
155
6708d944
DH
156/* I really doubt a given installation is going to have more than a few
157 * hundred vendors involved.
158 */
f7fdb216 159#if !defined (VIVCO_HASH_SIZE)
6708d944 160# define VIVCO_HASH_SIZE 127
f7fdb216
DH
161#endif
162
163#if !defined (VIVSO_HASH_SIZE)
164# define VIVSO_HASH_SIZE VIVCO_HASH_SIZE
165#endif
166
98bd7ca0
DH
167#if !defined (VSIO_HASH_SIZE)
168# define VSIO_HASH_SIZE VIVCO_HASH_SIZE
169#endif
170
f7fdb216
DH
171#if !defined (VIV_ISC_HASH_SIZE)
172# define VIV_ISC_HASH_SIZE 3 /* An incredulously small table. */
173#endif
174
175#if !defined (UNIVERSE_HASH_SIZE)
6708d944 176# define UNIVERSE_HASH_SIZE 13 /* A really small table. */
f7fdb216
DH
177#endif
178
179#if !defined (GROUP_HASH_SIZE)
180# define GROUP_HASH_SIZE 0 /* Default. */
181#endif
182
6708d944
DH
183/* At least one person has indicated they use ~20k host records.
184 */
f7fdb216 185#if !defined (HOST_HASH_SIZE)
6708d944 186# define HOST_HASH_SIZE 22501
f7fdb216
DH
187#endif
188
6708d944
DH
189/* We have user reports of use of ISC DHCP numbering leases in the 200k's.
190 *
191 * We also have reports of folks using 10.0/8 as a dynamic range. The
192 * following is something of a compromise between the two. At the ~2-3
193 * hundred thousand leases, there's ~2-3 leases to search in each bucket.
194 */
f7fdb216 195#if !defined (LEASE_HASH_SIZE)
6708d944 196# define LEASE_HASH_SIZE 100003
f7fdb216
DH
197#endif
198
6708d944
DH
199/* It is not known what the worst case subclass hash size is. We estimate
200 * high, I think.
201 */
f7fdb216 202#if !defined (SCLASS_HASH_SIZE)
6708d944 203# define SCLASS_HASH_SIZE 12007
f7fdb216
DH
204#endif
205
206#if !defined (AGENT_HASH_SIZE)
207# define AGENT_HASH_SIZE 11 /* A really small table. */
208#endif
209
6708d944
DH
210/* The server hash size is used for both names and codes. There aren't
211 * many (roughly 50 at the moment), so we use a smaller table. If we
212 * use a 1:1 table size, then we get name collisions due to poor name
213 * hashing. So we use double the space we need, which drastically
214 * reduces collisions.
215 */
f7fdb216 216#if !defined (SERVER_HASH_SIZE)
6708d944 217# define SERVER_HASH_SIZE (2*(sizeof(server_options) / sizeof(struct option)))
f7fdb216
DH
218#endif
219
220
6708d944 221/* How many options are likely to appear in a single packet? */
27fe61a7
TL
222#if !defined (OPTION_HASH_SIZE)
223# define OPTION_HASH_SIZE 17
0dbb132f
TL
224# define OPTION_HASH_PTWO 32 /* Next power of two above option hash. */
225# define OPTION_HASH_EXP 5 /* The exponent for that power of two. */
27fe61a7
TL
226#endif
227
0dbb132f
TL
228#define compute_option_hash(x) \
229 (((x) & (OPTION_HASH_PTWO - 1)) + \
230 (((x) >> OPTION_HASH_EXP) & \
231 (OPTION_HASH_PTWO - 1))) % OPTION_HASH_SIZE;
232
3933e2aa
SR
233/* Lease queue information. We have two ways of storing leases.
234 * The original is a linear linked list which is slower but uses
235 * less memory while the other adds a binary array on top of that
236 * list to make insertions faster. We define several macros
237 * based on which is in use to allow the code to be cleaner by
238 * avoiding #ifdefs.
239 *
240 * POOL_DESTROYP is used for debugging purposes
241 */
242
243#if !defined (BINARY_LEASES)
244#define LEASE_STRUCT struct lease *
245#define LEASE_STRUCT_PTR struct lease **
246#define LEASE_GET_FIRST(LQ) LQ
247#define LEASE_GET_FIRSTP(LQ) *(LQ)
248#define LEASE_GET_NEXT(LQ, LEASE) LEASE->next
249#define LEASE_GET_NEXTP(LQ, LEASE) LEASE->next
250#define LEASE_INSERTP(LQ, LEASE) lease_insert(LQ, LEASE)
251#define LEASE_REMOVEP(LQ, LEASE) lease_remove(LQ, LEASE)
252#define LEASE_NOT_EMPTY(LQ) LQ
253#define LEASE_NOT_EMPTYP(LQ) *LQ
254#define POOL_DESTROYP(LQ) lease_remove_all(LQ)
255#else
256#define LEASE_STRUCT struct leasechain
257#define LEASE_STRUCT_PTR struct leasechain *
258#define LEASE_GET_FIRST(LQ) lc_get_first_lease(&LQ)
259#define LEASE_GET_FIRSTP(LQ) lc_get_first_lease(LQ)
260#define LEASE_GET_NEXT(LQ, LEASE) lc_get_next(&LQ, LEASE)
261#define LEASE_GET_NEXTP(LQ, LEASE) lc_get_next(LQ, LEASE)
262#define LEASE_INSERTP(LQ, LEASE) lc_add_sorted_lease(LQ, LEASE)
263#define LEASE_REMOVEP(LQ, LEASE) lc_unlink_lease(LQ, LEASE)
264#define LEASE_NOT_EMPTY(LQ) lc_not_empty(&LQ)
265#define LEASE_NOT_EMPTYP(LQ) lc_not_empty(LQ)
266#define POOL_DESTROYP(LQ) lc_delete_all(LQ)
267#endif
268
d758ad8c
TL
269enum dhcp_shutdown_state {
270 shutdown_listeners,
271 shutdown_omapi_connections,
272 shutdown_drop_omapi_connections,
273 shutdown_dhcp,
274 shutdown_done
275};
276
35e0fdf8
TL
277/* Client FQDN option, failover FQDN option, etc. */
278typedef struct {
279 u_int8_t codes [2];
280 unsigned length;
281 u_int8_t *data;
282} ddns_fqdn_t;
283
de1863a1 284#include "failover.h"
35e0fdf8 285
fde86d2d
TL
286/* A parsing context. */
287
288struct parse {
289 int lexline;
290 int lexchar;
291 char *token_line;
292 char *prev_line;
293 char *cur_line;
b1b7b521 294 const char *tlname;
fde86d2d
TL
295 int eol_token;
296
d19e816e 297 /*
a34feb7d 298 * In order to give nice output when we have a parsing error
d19e816e
SK
299 * in our file, we keep track of where we are in the line so
300 * that we can show the user.
301 *
a34feb7d 302 * We need to keep track of two lines, because we can look
d19e816e
SK
303 * ahead, via the "peek" function, to the next line sometimes.
304 *
a34feb7d 305 * The "line1" and "line2" variables act as buffers for this
d19e816e
SK
306 * information. The "lpos" variable tells us where we are in the
307 * line.
308 *
309 * When we "put back" a character from the parsing context, we
310 * do not want to have the character appear twice in the error
311 * output. So, we set a flag, the "ugflag", which the
312 * get_char() function uses to check for this condition.
313 */
fde86d2d
TL
314 char line1 [81];
315 char line2 [81];
316 int lpos;
317 int line;
318 int tlpos;
319 int tline;
320 enum dhcp_token token;
321 int ugflag;
322 char *tval;
b3519f23 323 int tlen;
fde86d2d
TL
324 char tokbuf [1500];
325
fde86d2d
TL
326 int warnings_occurred;
327 int file;
328 char *inbuf;
66eaae18
SK
329 size_t bufix, buflen;
330 size_t bufsiz;
bda33169
SK
331
332 struct parse *saved_state;
33692791
DH
333
334#if defined(LDAP_CONFIGURATION)
335 /*
336 * LDAP configuration uses a call-back to iteratively read config
337 * off of the LDAP repository.
338 * XXX: The token stream can not be rewound reliably, so this must
339 * be addressed for DHCPv6 support.
340 */
341 int (*read_function)(struct parse *);
342#endif
fde86d2d
TL
343};
344
74f45f96 345/* Variable-length array of data. */
74f45f96 346
6b3b97e1
TL
347struct string_list {
348 struct string_list *next;
349 char string [1];
350};
351
0c7802b1
TL
352/* A name server, from /etc/resolv.conf. */
353struct name_server {
354 struct name_server *next;
355 struct sockaddr_in addr;
356 TIME rcdate;
357};
358
359/* A domain search list element. */
360struct domain_search_list {
361 struct domain_search_list *next;
362 char *domain;
363 TIME rcdate;
364};
365
5142937c
TL
366/* Option tag structures are used to build chains of option tags, for
367 when we're sure we're not going to have enough of them to justify
368 maintaining an array. */
369
370struct option_tag {
371 struct option_tag *next;
372 u_int8_t data [1];
373};
374
375/* An agent option structure. We need a special structure for the
376 Relay Agent Information option because if more than one appears in
c57db45c 377 a message, we have to keep them separate. */
5142937c
TL
378
379struct agent_options {
380 struct agent_options *next;
381 int length;
382 struct option_tag *first;
383};
384
27fe61a7
TL
385struct option_cache {
386 int refcnt;
387 struct option_cache *next;
388 struct expression *expression;
389 struct option *option;
390 struct data_string data;
88cd8aca
DH
391
392 #define OPTION_HAD_NULLS 0x00000001
393 u_int32_t flags;
27fe61a7 394};
5142937c 395
27fe61a7 396struct option_state {
a340de95 397 int refcnt;
4f58da18 398 int universe_count;
53ac6c6f
TL
399 int site_universe;
400 int site_code_min;
fe5b0fdd 401 void *universes [1];
5142937c
TL
402};
403
d7837182
TL
404/* A dhcp packet and the pointers to its option values. */
405struct packet {
406 struct dhcp_packet *raw;
f3e8ea32 407 int refcnt;
b1b7b521 408 unsigned packet_length;
d7837182 409 int packet_type;
98bd7ca0
DH
410
411 unsigned char dhcpv6_msg_type; /* DHCPv6 message type */
412
413 /* DHCPv6 transaction ID */
414 unsigned char dhcpv6_transaction_id[3];
415
416 /* DHCPv6 relay information */
417 unsigned char dhcpv6_hop_count;
418 struct in6_addr dhcpv6_link_address;
419 struct in6_addr dhcpv6_peer_address;
420
421 /* DHCPv6 packet containing this one, or NULL if none */
422 struct packet *dhcpv6_container_packet;
423
d7837182 424 int options_valid;
089fb364
TL
425 int client_port;
426 struct iaddr client_addr;
17b95f41
TL
427 struct interface_info *interface; /* Interface on which packet
428 was received. */
429 struct hardware *haddr; /* Physical link address
430 of local sender (maybe gateway). */
c4763f5f
TL
431
432 /* Information for relay agent options (see
433 draft-ietf-dhc-agent-options-xx.txt). */
434 u_int8_t *circuit_id; /* Circuit ID of client connection. */
435 int circuit_id_len;
436 u_int8_t *remote_id; /* Remote ID of client. */
437 int remote_id_len;
438
f67530be
TL
439 int got_requested_address; /* True if client sent the
440 dhcp-requested-address option. */
441
c626ae69 442 struct shared_network *shared_network;
4f58da18 443 struct option_state *options;
102ee7e9
TL
444
445#if !defined (PACKET_MAX_CLASSES)
446# define PACKET_MAX_CLASSES 5
447#endif
448 int class_count;
449 struct class *classes [PACKET_MAX_CLASSES];
734d2258
TL
450
451 int known;
452 int authenticated;
9aa3f3a5
DH
453
454 /* If we stash agent options onto the packet option state, to pretend
455 * options we got in a previous exchange were still there, we need
456 * to signal this in a reliable way.
457 */
458 isc_boolean_t agent_options_stashed;
98bd7ca0 459
a34feb7d
TM
460 /*
461 * ISC_TRUE if packet received unicast (as opposed to multicast).
98bd7ca0
DH
462 * Only used in DHCPv6.
463 */
464 isc_boolean_t unicast;
e046c826
TM
465
466 /* Propogates server value SV_ECHO_CLIENT_ID so it is available
467 * in cons_options() */
468 int sv_echo_client_id;
d7837182
TL
469};
470
e563ec2e
SR
471/*
472 * A network interface's MAC address.
473 * 20 bytes for the hardware address
474 * and 1 byte for the type tag
475 */
476
477#define HARDWARE_ADDR_LEN 20
5142937c 478
d7837182 479struct hardware {
d7837182 480 u_int8_t hlen;
e563ec2e 481 u_int8_t hbuf[HARDWARE_ADDR_LEN + 1];
d7837182
TL
482};
483
33692791
DH
484#if defined(LDAP_CONFIGURATION)
485# define LDAP_BUFFER_SIZE 8192
486# define LDAP_METHOD_STATIC 0
487# define LDAP_METHOD_DYNAMIC 1
488#if defined (LDAP_USE_SSL)
489# define LDAP_SSL_OFF 0
490# define LDAP_SSL_ON 1
491# define LDAP_SSL_TLS 2
492# define LDAP_SSL_LDAPS 3
493#endif
494
495/* This is a tree of the current configuration we are building from LDAP */
496struct ldap_config_stack {
497 LDAPMessage * res; /* Pointer returned from ldap_search */
498 LDAPMessage * ldent; /* Current item in LDAP that we're processing.
499 in res */
500 int close_brace; /* Put a closing } after we're through with
501 this item */
502 int processed; /* We set this flag if this base item has been
503 processed. After this base item is processed,
504 we can start processing the children */
505 struct ldap_config_stack *children;
506 struct ldap_config_stack *next;
507};
508#endif
509
d758ad8c
TL
510typedef enum {
511 server_startup = 0,
512 server_running = 1,
513 server_shutdown = 2,
514 server_hibernate = 3,
515 server_awaken = 4
516} control_object_state_t;
517
518typedef struct {
519 OMAPI_OBJECT_PREAMBLE;
520 control_object_state_t state;
521} dhcp_control_object_t;
522
7ea8b207 523/* Lease states: */
98311e4b
DH
524#define FTS_FREE 1
525#define FTS_ACTIVE 2
526#define FTS_EXPIRED 3
527#define FTS_RELEASED 4
528#define FTS_ABANDONED 5
529#define FTS_RESET 6
530#define FTS_BACKUP 7
98311e4b
DH
531typedef u_int8_t binding_state_t;
532
533/* FTS_LAST is the highest value that is valid for a lease binding state. */
a55ccdd0 534#define FTS_LAST FTS_BACKUP
7ea8b207 535
a7341359
SR
536/*
537 * A block for the on statements so we can share the structure
538 * between v4 and v6
539 */
540struct on_star {
541 struct executable_statement *on_expiry;
542 struct executable_statement *on_commit;
543 struct executable_statement *on_release;
544};
545
d7837182
TL
546/* A dhcp lease declaration structure. */
547struct lease {
4fe74d72 548 OMAPI_OBJECT_PREAMBLE;
d7837182 549 struct lease *next;
3933e2aa
SR
550#if defined (BINARY_LEASES)
551 struct lease *prev;
552 struct leasechain *lc;
553#endif
ab370123 554 struct lease *n_uid, *n_hw;
fc2df23a 555
089fb364 556 struct iaddr ip_addr;
6d103865 557 TIME starts, ends, sort_time;
3933e2aa
SR
558#if defined (BINARY_LEASES)
559 long int sort_tiebreaker;
560#endif
0c7802b1 561 char *client_hostname;
6ceb9118 562 struct binding_scope *scope;
d7837182 563 struct host_decl *host;
c626ae69 564 struct subnet *subnet;
734d2258 565 struct pool *pool;
112a6c2c 566 struct class *billing_class;
625f7cee 567 struct option_chain_head *agent_options;
fc2df23a 568
a7341359
SR
569 /* insert the structure directly */
570 struct on_star on_star;
79a65726 571
f3aad410
TL
572 unsigned char *uid;
573 unsigned short uid_len;
574 unsigned short uid_max;
575 unsigned char uid_buf [7];
576 struct hardware hardware_addr;
577
578 u_int8_t flags;
c626ae69 579# define STATIC_LEASE 1
98311e4b 580# define BOOTP_LEASE 2
a55ccdd0 581# define RESERVED_LEASE 4
fc2df23a 582# define MS_NULL_TERMINATION 8
007e3ee4
TL
583# define ON_UPDATE_QUEUE 16
584# define ON_ACK_QUEUE 32
4c7ffd58 585# define ON_QUEUE (ON_UPDATE_QUEUE | ON_ACK_QUEUE)
bca94423 586# define UNICAST_BROADCAST_HACK 64
98311e4b 587# define ON_DEFERRED_QUEUE 128
a55ccdd0
DH
588
589/* Persistent flags are to be preserved on a given lease structure. */
590# define PERSISTENT_FLAGS (ON_ACK_QUEUE | ON_UPDATE_QUEUE)
591/* Ephemeral flags are to be preserved on a given lease (copied etc). */
bca94423 592# define EPHEMERAL_FLAGS (MS_NULL_TERMINATION | \
a55ccdd0
DH
593 UNICAST_BROADCAST_HACK | \
594 RESERVED_LEASE | \
595 BOOTP_LEASE)
2aac4312 596
fdfebedf
DH
597 /*
598 * The lease's binding state is its current state. The next binding
599 * state is the next state this lease will move into by expiration,
600 * or timers in general. The desired binding state is used on lease
601 * updates; the caller is attempting to move the lease to the desired
602 * binding state (and this may either succeed or fail, so the binding
603 * state must be preserved).
604 *
605 * The 'rewind' binding state is used in failover processing. It
606 * is used for an optimization when out of communications; it allows
607 * the server to "rewind" a lease to the previous state acknowledged
608 * by the peer, and progress forward from that point.
609 */
98311e4b
DH
610 binding_state_t binding_state;
611 binding_state_t next_binding_state;
612 binding_state_t desired_binding_state;
fdfebedf
DH
613 binding_state_t rewind_binding_state;
614
6e5ed8bf 615 struct lease_state *state;
5b7f941d 616
fdfebedf
DH
617 /*
618 * 'tsfp' is more of an 'effective' tsfp. It may be calculated from
88cd8aca
DH
619 * stos+mclt for example if it's an expired lease and the server is
620 * in partner-down state. 'atsfp' is zeroed whenever a lease is
621 * updated - and only set when the peer acknowledges it. This
622 * ensures every state change is transmitted.
623 */
5b7f941d
TL
624 TIME tstp; /* Time sent to partner. */
625 TIME tsfp; /* Time sent from partner. */
88cd8aca 626 TIME atsfp; /* Actual time sent from partner. */
5b7f941d 627 TIME cltt; /* Client last transaction time. */
a55ccdd0 628 u_int32_t last_xid; /* XID we sent in this lease's BNDUPD */
aa8579c0 629 struct lease *next_pending;
98bf1607
SR
630
631 /*
632 * A pointer to the state of the ddns update for this lease.
633 * It should be set while the update is in progress and cleared
634 * when the update finishes. It can be used to cancel the
635 * update if we want to do a different update.
636 */
637 struct dhcp_ddns_cb *ddns_cb;
f3a44c10
TM
638
639 /* Set when a lease has been disqualified for cache-threshold reuse */
640 unsigned short cannot_reuse;
6e5ed8bf
TL
641};
642
643struct lease_state {
644 struct lease_state *next;
645
646 struct interface_info *ip;
647
f3e8ea32
TL
648 struct packet *packet; /* The incoming packet. */
649
6e5ed8bf
TL
650 TIME offered_expiry;
651
4f58da18 652 struct option_state *options;
15151db6 653 struct data_string parameter_request_list;
5142937c 654 int max_message_size;
dcc557db 655 unsigned char expiry[4], renewal[4], rebind[4];
2b9b6ff7 656 struct data_string filename, server_name;
f67530be
TL
657 int got_requested_address;
658 int got_server_identifier;
659 struct shared_network *shared_network; /* Shared network of interface
660 on which request arrived. */
fc2df23a
TL
661
662 u_int32_t xid;
663 u_int16_t secs;
664 u_int16_t bootp_flags;
665 struct in_addr ciaddr;
c783f799 666 struct in_addr siaddr;
fc2df23a
TL
667 struct in_addr giaddr;
668 u_int8_t hops;
669 u_int8_t offer;
27fe61a7 670 struct iaddr from;
c626ae69
TL
671};
672
ab370123 673#define ROOT_GROUP 0
750d0800
TL
674#define HOST_DECL 1
675#define SHARED_NET_DECL 2
676#define SUBNET_DECL 3
677#define CLASS_DECL 4
678#define GROUP_DECL 5
74f45f96 679#define POOL_DECL 6
ab370123 680
cc26de46
TL
681/* Possible modes in which discover_interfaces can run. */
682
683#define DISCOVER_RUNNING 0
684#define DISCOVER_SERVER 1
685#define DISCOVER_UNCONFIGURED 2
f79e49f3 686#define DISCOVER_RELAY 3
5a526cf8 687#define DISCOVER_REQUESTED 4
cc26de46 688
98bd7ca0
DH
689/* DDNS_UPDATE_STYLE enumerations. */
690#define DDNS_UPDATE_STYLE_NONE 0
691#define DDNS_UPDATE_STYLE_AD_HOC 1
692#define DDNS_UPDATE_STYLE_INTERIM 2
d7d9c0c7 693#define DDNS_UPDATE_STYLE_STANDARD 3
98bd7ca0 694
2b9b6ff7
TL
695/* Server option names. */
696
697#define SV_DEFAULT_LEASE_TIME 1
698#define SV_MAX_LEASE_TIME 2
699#define SV_MIN_LEASE_TIME 3
700#define SV_BOOTP_LEASE_CUTOFF 4
701#define SV_BOOTP_LEASE_LENGTH 5
702#define SV_BOOT_UNKNOWN_CLIENTS 6
703#define SV_DYNAMIC_BOOTP 7
704#define SV_ALLOW_BOOTP 8
705#define SV_ALLOW_BOOTING 9
706#define SV_ONE_LEASE_PER_CLIENT 10
707#define SV_GET_LEASE_HOSTNAMES 11
708#define SV_USE_HOST_DECL_NAMES 12
709#define SV_USE_LEASE_ADDR_FOR_DEFAULT_ROUTE 13
710#define SV_MIN_SECS 14
711#define SV_FILENAME 15
712#define SV_SERVER_NAME 16
713#define SV_NEXT_SERVER 17
d1f2c520 714#define SV_AUTHORITATIVE 18
4f58da18 715#define SV_VENDOR_OPTION_SPACE 19
4b7f8736 716#define SV_ALWAYS_REPLY_RFC1048 20
53ac6c6f 717#define SV_SITE_OPTION_SPACE 21
f7b9d823 718#define SV_ALWAYS_BROADCAST 22
972ab2aa
TL
719#define SV_DDNS_DOMAIN_NAME 23
720#define SV_DDNS_HOST_NAME 24
721#define SV_DDNS_REV_DOMAIN_NAME 25
94bf482e
TL
722#define SV_LEASE_FILE_NAME 26
723#define SV_PID_FILE_NAME 27
4c026751
TL
724#define SV_DUPLICATES 28
725#define SV_DECLINES 29
7f6ad5ac 726#define SV_DDNS_UPDATES 30
aa8579c0
TL
727#define SV_OMAPI_PORT 31
728#define SV_LOCAL_PORT 32
729#define SV_LIMITED_BROADCAST_ADDRESS 33
730#define SV_REMOTE_PORT 34
731#define SV_LOCAL_ADDRESS 35
49146f3c 732#define SV_OMAPI_KEY 36
159bcce3 733#define SV_STASH_AGENT_OPTIONS 37
b992d7e2 734#define SV_DDNS_TTL 38
dbcc689e 735#define SV_DDNS_UPDATE_STYLE 39
afc0ca25
TL
736#define SV_CLIENT_UPDATES 40
737#define SV_UPDATE_OPTIMIZATION 41
cc4473a0
TL
738#define SV_PING_CHECKS 42
739#define SV_UPDATE_STATIC_LEASES 43
625f7cee 740#define SV_LOG_FACILITY 44
98311e4b 741#define SV_DO_FORWARD_UPDATES 45
a55ccdd0
DH
742#define SV_PING_TIMEOUT 46
743#define SV_RESERVE_INFINITE 47
3004bebf 744#define SV_DDNS_CONFLICT_DETECT 48
6d103865 745#define SV_LEASEQUERY 49
b22de500 746#define SV_ADAPTIVE_LEASE_TIME_THRESHOLD 50
4d2eaafb 747#define SV_DO_REVERSE_UPDATES 51
1ba87b37 748#define SV_FQDN_REPLY 52
98bd7ca0 749#define SV_PREFER_LIFETIME 53
75135a3f
EH
750#define SV_DHCPV6_LEASE_FILE_NAME 54
751#define SV_DHCPV6_PID_FILE_NAME 55
b024480e 752#define SV_LIMIT_ADDRS_PER_IA 56
80c9fdb0
FD
753#define SV_LIMIT_PREFS_PER_IA 57
754#define SV_DELAYED_ACK 58
f8cbf390 755#define SV_MAX_ACK_DELAY 59
929a2364
TM
756#if defined(LDAP_CONFIGURATION)
757# define SV_LDAP_SERVER 60
758# define SV_LDAP_PORT 61
759# define SV_LDAP_USERNAME 62
760# define SV_LDAP_PASSWORD 63
761# define SV_LDAP_BASE_DN 64
762# define SV_LDAP_METHOD 65
763# define SV_LDAP_DEBUG_FILE 66
764# define SV_LDAP_DHCP_SERVER_CN 67
765# define SV_LDAP_REFERRALS 68
766#if defined (LDAP_USE_SSL)
767# define SV_LDAP_SSL 69
768# define SV_LDAP_TLS_REQCERT 70
769# define SV_LDAP_TLS_CA_FILE 71
770# define SV_LDAP_TLS_CA_DIR 72
771# define SV_LDAP_TLS_CERT 73
772# define SV_LDAP_TLS_KEY 74
773# define SV_LDAP_TLS_CRLCHECK 75
774# define SV_LDAP_TLS_CIPHERS 76
775# define SV_LDAP_TLS_RANDFILE 77
776#endif
743d6937
TM
777# define SV_LDAP_INIT_RETRY 178
778#if defined (LDAP_USE_GSSAPI)
779# define SV_LDAP_GSSAPI_KEYTAB 179
780# define SV_LDAP_GSSAPI_PRINCIPAL 180
781#endif
929a2364
TM
782#endif
783#define SV_CACHE_THRESHOLD 78
cde11a4c 784#define SV_DONT_USE_FSYNC 79
61ef216b
SR
785#define SV_DDNS_LOCAL_ADDRESS4 80
786#define SV_DDNS_LOCAL_ADDRESS6 81
38ee81bd 787#define SV_IGNORE_CLIENT_UIDS 82
250f7134
SR
788#define SV_LOG_THRESHOLD_LOW 83
789#define SV_LOG_THRESHOLD_HIGH 84
e046c826 790#define SV_ECHO_CLIENT_ID 85
7116a34f 791#define SV_SERVER_ID_CHECK 86
1a006ff6 792#define SV_PREFIX_LEN_MODE 87
98311e4b
DH
793
794#if !defined (DEFAULT_PING_TIMEOUT)
795# define DEFAULT_PING_TIMEOUT 1
796#endif
2b9b6ff7 797
6368a1bd
DH
798#if !defined (DEFAULT_DELAYED_ACK)
799# define DEFAULT_DELAYED_ACK 28 /* default SO_SNDBUF size / 576 bytes */
800#endif
801
f8cbf390
DH
802#if !defined (DEFAULT_ACK_DELAY_SECS)
803# define DEFAULT_ACK_DELAY_SECS 0
804#endif
805
806#if !defined (DEFAULT_ACK_DELAY_USECS)
807# define DEFAULT_ACK_DELAY_USECS 250000 /* 1/4 of a second */
808#endif
809
0585235c
SR
810#if !defined (DEFAULT_MIN_ACK_DELAY_USECS)
811# define DEFAULT_MIN_ACK_DELAY_USECS 10000 /* 1/100 second */
812#endif
813
929a2364
TM
814#if !defined (DEFAULT_CACHE_THRESHOLD)
815# define DEFAULT_CACHE_THRESHOLD 25
33692791
DH
816#endif
817
2b9b6ff7
TL
818#if !defined (DEFAULT_DEFAULT_LEASE_TIME)
819# define DEFAULT_DEFAULT_LEASE_TIME 43200
820#endif
821
822#if !defined (DEFAULT_MIN_LEASE_TIME)
3a16098f 823# define DEFAULT_MIN_LEASE_TIME 300
2b9b6ff7
TL
824#endif
825
826#if !defined (DEFAULT_MAX_LEASE_TIME)
827# define DEFAULT_MAX_LEASE_TIME 86400
828#endif
829
b992d7e2
DN
830#if !defined (DEFAULT_DDNS_TTL)
831# define DEFAULT_DDNS_TTL 3600
832#endif
2b58b865
SR
833#if !defined (MAX_DEFAULT_DDNS_TTL)
834# define MAX_DEFAULT_DDNS_TTL 3600
835#endif
b992d7e2 836
5d082abd
TM
837#if !defined (MIN_LEASE_WRITE)
838# define MIN_LEASE_WRITE 15
839#endif
840
1a006ff6
TM
841#define PLM_IGNORE 0
842#define PLM_PREFER 1
843#define PLM_EXACT 2
844#define PLM_MINIMUM 3
845#define PLM_MAXIMUM 4
846
27fe61a7
TL
847/* Client option names */
848
849#define CL_TIMEOUT 1
850#define CL_SELECT_INTERVAL 2
851#define CL_REBOOT_TIMEOUT 3
852#define CL_RETRY_INTERVAL 4
853#define CL_BACKOFF_CUTOFF 5
854#define CL_INITIAL_INTERVAL 6
855#define CL_BOOTP_POLICY 7
856#define CL_SCRIPT_NAME 8
857#define CL_REQUESTED_OPTIONS 9
858#define CL_REQUESTED_LEASE_TIME 10
859#define CL_SEND_OPTIONS 11
860#define CL_MEDIA 12
861#define CL_REJECT_LIST 13
862
863#ifndef CL_DEFAULT_TIMEOUT
864# define CL_DEFAULT_TIMEOUT 60
865#endif
866
867#ifndef CL_DEFAULT_SELECT_INTERVAL
868# define CL_DEFAULT_SELECT_INTERVAL 0
869#endif
870
871#ifndef CL_DEFAULT_REBOOT_TIMEOUT
872# define CL_DEFAULT_REBOOT_TIMEOUT 10
873#endif
874
875#ifndef CL_DEFAULT_RETRY_INTERVAL
876# define CL_DEFAULT_RETRY_INTERVAL 300
877#endif
878
879#ifndef CL_DEFAULT_BACKOFF_CUTOFF
880# define CL_DEFAULT_BACKOFF_CUTOFF 120
881#endif
882
883#ifndef CL_DEFAULT_INITIAL_INTERVAL
884# define CL_DEFAULT_INITIAL_INTERVAL 10
885#endif
886
887#ifndef CL_DEFAULT_BOOTP_POLICY
c5b0f529 888# define CL_DEFAULT_BOOTP_POLICY P_ACCEPT
27fe61a7
TL
889#endif
890
27fe61a7
TL
891#ifndef CL_DEFAULT_REQUESTED_OPTIONS
892# define CL_DEFAULT_REQUESTED_OPTIONS \
893 { DHO_SUBNET_MASK, \
894 DHO_BROADCAST_ADDRESS, \
895 DHO_TIME_OFFSET, \
896 DHO_ROUTERS, \
897 DHO_DOMAIN_NAME, \
898 DHO_DOMAIN_NAME_SERVERS, \
899 DHO_HOST_NAME }
900#endif
901
940ea8ab
TL
902struct group_object {
903 OMAPI_OBJECT_PREAMBLE;
904
905 struct group_object *n_dynamic;
906 struct group *group;
907 char *name;
908 int flags;
909#define GROUP_OBJECT_DELETED 1
910#define GROUP_OBJECT_DYNAMIC 2
911#define GROUP_OBJECT_STATIC 4
912};
913
750d0800 914/* Group of declarations that share common parameters. */
ab370123
TL
915struct group {
916 struct group *next;
917
20916cae 918 int refcnt;
940ea8ab 919 struct group_object *object;
ab370123
TL
920 struct subnet *subnet;
921 struct shared_network *shared_network;
d1f2c520 922 int authoritative;
2b9b6ff7 923 struct executable_statement *statements;
ab370123
TL
924};
925
926/* A dhcp host declaration structure. */
927struct host_decl {
4fe74d72 928 OMAPI_OBJECT_PREAMBLE;
ab370123 929 struct host_decl *n_ipaddr;
4fe74d72 930 struct host_decl *n_dynamic;
ab370123
TL
931 char *name;
932 struct hardware interface;
2b9b6ff7 933 struct data_string client_identifier;
98bd7ca0
DH
934 struct option *host_id_option;
935 struct data_string host_id;
936 /* XXXSK: fixed_addr should be an array of iaddr values,
937 not an option_cache, but it's referenced in a lot of
938 places, so we'll leave it for now. */
2b9b6ff7 939 struct option_cache *fixed_addr;
80c9fdb0 940 struct iaddrcidrnetlist *fixed_prefix;
ab370123 941 struct group *group;
940ea8ab 942 struct group_object *named_group;
74f45f96 943 struct data_string auth_key_id;
4fe74d72 944 int flags;
3c48d369
TL
945#define HOST_DECL_DELETED 1
946#define HOST_DECL_DYNAMIC 2
940ea8ab 947#define HOST_DECL_STATIC 4
619304cd
SR
948 /* For v6 the host-identifer option can specify which relay
949 to use when trying to look up an option. We store the
950 value here. */
951 int relays;
ab370123
TL
952};
953
734d2258
TL
954struct permit {
955 struct permit *next;
956 enum {
957 permit_unknown_clients,
958 permit_known_clients,
959 permit_authenticated_clients,
960 permit_unauthenticated_clients,
961 permit_all_clients,
962 permit_dynamic_bootp_clients,
b1d3778c
DH
963 permit_class,
964 permit_after
734d2258
TL
965 } type;
966 struct class *class;
b1d3778c 967 TIME after; /* date after which this clause applies */
734d2258
TL
968};
969
3933e2aa
SR
970#if defined (BINARY_LEASES)
971struct leasechain {
972 struct lease **list; /* lease list */
973 size_t total; /* max number of elements in this list,
974 * including free pointers at the end if any */
975 size_t nelem; /* the number of elements, also the next index to use */
976 size_t growth; /* the growth factor to use when increase an array
977 * this is set after parsing the pools and before
978 * creatin an array. */
979};
980#endif
981
734d2258 982struct pool {
4fe74d72 983 OMAPI_OBJECT_PREAMBLE;
734d2258 984 struct pool *next;
74f45f96 985 struct group *group;
734d2258
TL
986 struct shared_network *shared_network;
987 struct permit *permit_list;
988 struct permit *prohibit_list;
3933e2aa
SR
989 LEASE_STRUCT active;
990 LEASE_STRUCT expired;
991 LEASE_STRUCT free;
992 LEASE_STRUCT backup;
993 LEASE_STRUCT abandoned;
994 LEASE_STRUCT reserved;
007e3ee4 995 TIME next_event_time;
5b7f941d 996 int lease_count;
007e3ee4
TL
997 int free_leases;
998 int backup_leases;
d758ad8c 999 int index;
b1d3778c
DH
1000 TIME valid_from; /* deny pool use before this date */
1001 TIME valid_until; /* deny pool use after this date */
1002
7ea8b207 1003#if defined (FAILOVER_PROTOCOL)
5b7f941d
TL
1004 dhcp_failover_state_t *failover_peer;
1005#endif
250f7134
SR
1006 int logged; /* already logged a message */
1007 int low_threshold; /* low threshold to restart logging */
d1f2c520 1008};
d1f2c520 1009
c626ae69 1010struct shared_network {
4fe74d72 1011 OMAPI_OBJECT_PREAMBLE;
c626ae69 1012 struct shared_network *next;
20916cae 1013 char *name;
7d6180be
DH
1014
1015#define SHARED_IMPLICIT 1 /* This network was synthesized. */
1016 int flags;
1017
c626ae69
TL
1018 struct subnet *subnets;
1019 struct interface_info *interface;
734d2258 1020 struct pool *pools;
01fa619f 1021 struct ipv6_pond *ipv6_pond;
5b7f941d 1022 struct group *group;
d1f2c520 1023#if defined (FAILOVER_PROTOCOL)
5b7f941d 1024 dhcp_failover_state_t *failover_peer;
d1f2c520 1025#endif
d7837182
TL
1026};
1027
1028struct subnet {
4fe74d72 1029 OMAPI_OBJECT_PREAMBLE;
c626ae69
TL
1030 struct subnet *next_subnet;
1031 struct subnet *next_sibling;
1032 struct shared_network *shared_network;
1033 struct interface_info *interface;
1034 struct iaddr interface_address;
089fb364
TL
1035 struct iaddr net;
1036 struct iaddr netmask;
98bd7ca0 1037 int prefix_len; /* XXX: currently for IPv6 only */
ab370123 1038 struct group *group;
d7837182
TL
1039};
1040
102ee7e9
TL
1041struct collection {
1042 struct collection *next;
a34feb7d 1043
b1b7b521 1044 const char *name;
102ee7e9
TL
1045 struct class *classes;
1046};
1047
06e77c34
DH
1048/* Used as an argument to parse_clasS_decl() */
1049#define CLASS_TYPE_VENDOR 0
1050#define CLASS_TYPE_USER 1
1051#define CLASS_TYPE_CLASS 2
1052#define CLASS_TYPE_SUBCLASS 3
1053
112a6c2c 1054/* XXX classes must be reference-counted. */
102ee7e9 1055struct class {
4fe74d72 1056 OMAPI_OBJECT_PREAMBLE;
a609e69b 1057 struct class *nic; /* Next in collection. */
112a6c2c 1058 struct class *superclass; /* Set for spawned classes only. */
a609e69b 1059 char *name; /* Not set for spawned classes. */
734d2258
TL
1060
1061 /* A class may be configured to permit a limited number of leases. */
1062 int lease_limit;
112a6c2c
TL
1063 int leases_consumed;
1064 struct lease **billed_leases;
1065
1066 /* If nonzero, class has not been saved since it was last
1067 modified. */
1068 int dirty;
ab370123 1069
112a6c2c 1070 /* Hash table containing subclasses. */
98311e4b 1071 class_hash_t *hash;
112a6c2c
TL
1072 struct data_string hash_string;
1073
1074 /* Expression used to match class. */
2b9b6ff7 1075 struct expression *expr;
112a6c2c
TL
1076
1077 /* Expression used to compute subclass identifiers for spawning
58bfaaa7
TL
1078 and to do subclass matching. */
1079 struct expression *submatch;
1080 int spawning;
a34feb7d 1081
ab370123 1082 struct group *group;
2b9b6ff7
TL
1083
1084 /* Statements to execute if class matches. */
1085 struct executable_statement *statements;
899d754f
JB
1086
1087#define CLASS_DECL_DELETED 1
1088#define CLASS_DECL_DYNAMIC 2
1089#define CLASS_DECL_STATIC 4
1090#define CLASS_DECL_SUBCLASS 8
a34feb7d 1091
899d754f 1092 int flags;
709f15cc
TL
1093};
1094
cc26de46
TL
1095/* DHCP client lease structure... */
1096struct client_lease {
41fb155b
TL
1097 struct client_lease *next; /* Next lease in list. */
1098 TIME expiry, renewal, rebind; /* Lease timeouts. */
1099 struct iaddr address; /* Address being leased. */
1100 char *server_name; /* Name of boot server. */
1101 char *filename; /* Name of file we're supposed to boot. */
6b3b97e1 1102 struct string_list *medium; /* Network medium. */
49146f3c 1103 struct auth_key *key; /* Key used in basic DHCP authentication. */
cc26de46 1104
0c7802b1 1105 unsigned int is_static : 1; /* If set, lease is from config file. */
98311e4b 1106 unsigned int is_bootp: 1; /* If set, lease was acquired with BOOTP. */
41fb155b 1107
4f58da18 1108 struct option_state *options; /* Options supplied with lease. */
02b0bdc3 1109 struct iaddr next_srv_addr; /* Address of the next server to use */
cc26de46
TL
1110};
1111
98bd7ca0
DH
1112/* DHCPv6 lease structures */
1113struct dhc6_addr {
1114 struct dhc6_addr *next;
1115 struct iaddr address;
1d9774ab 1116 u_int8_t plen;
98bd7ca0
DH
1117
1118 /* Address state flags. */
1119 #define DHC6_ADDR_DEPREFFED 0x01
1120 #define DHC6_ADDR_EXPIRED 0x02
1121 u_int8_t flags;
1122
1123 TIME starts;
1124 u_int32_t preferred_life;
1125 u_int32_t max_life;
1126
1127 struct option_state *options;
1128};
1129
1130struct dhc6_ia {
1131 struct dhc6_ia *next;
1132 unsigned char iaid[4];
1d9774ab 1133 u_int16_t ia_type;
98bd7ca0
DH
1134
1135 TIME starts;
1136 u_int32_t renew;
1137 u_int32_t rebind;
1138 struct dhc6_addr *addrs;
1139
1140 struct option_state *options;
1141};
1142
1143struct dhc6_lease {
1144 struct dhc6_lease *next;
1145 struct data_string server_id;
1146
cabdb9b1 1147 isc_boolean_t released;
98bd7ca0
DH
1148 int score;
1149 u_int8_t pref;
1150
1151 unsigned char dhcpv6_transaction_id[3];
1152 struct dhc6_ia *bindings;
1153
1154 struct option_state *options;
1155};
1156
41fb155b 1157/* Possible states in which the client can be. */
cc26de46 1158enum dhcp_state {
159bcce3
TL
1159 S_REBOOTING = 1,
1160 S_INIT = 2,
1161 S_SELECTING = 3,
a34feb7d 1162 S_REQUESTING = 4,
159bcce3
TL
1163 S_BOUND = 5,
1164 S_RENEWING = 6,
c1f22aef
TL
1165 S_REBINDING = 7,
1166 S_STOPPED = 8
cc26de46
TL
1167};
1168
08512bce
TL
1169/* Authentication and BOOTP policy possibilities (not all values work
1170 for each). */
1171enum policy { P_IGNORE, P_ACCEPT, P_PREFER, P_REQUIRE, P_DONT };
1172
cc26de46
TL
1173/* Configuration information from the config file... */
1174struct client_config {
27fe61a7
TL
1175 /*
1176 * When a message has been received, run these statements
1177 * over it.
1178 */
112a6c2c 1179 struct group *on_receipt;
27fe61a7
TL
1180
1181 /*
1182 * When a message is sent, run these statements.
1183 */
112a6c2c 1184 struct group *on_transmission;
27fe61a7 1185
0c20eab3
DH
1186 struct option **required_options; /* Options that MUST be present. */
1187 struct option **requested_options; /* Options to request (ORO/PRL). */
27fe61a7 1188
cc26de46
TL
1189 TIME timeout; /* Start to panic if we don't get a
1190 lease in this time period when
1191 SELECTING. */
a34feb7d
TM
1192 TIME initial_delay; /* Set initial delay before first
1193 transmission. */
83c1b012
TL
1194 TIME initial_interval; /* All exponential backoff intervals
1195 start here. */
cc26de46
TL
1196 TIME retry_interval; /* If the protocol failed to produce
1197 an address before the timeout,
1198 try the protocol again after this
1199 many seconds. */
1200 TIME select_interval; /* Wait this many seconds from the
1201 first DHCPDISCOVER before
1202 picking an offered lease. */
fc2df23a
TL
1203 TIME reboot_timeout; /* When in INIT-REBOOT, wait this
1204 long before giving up and going
1205 to INIT. */
83c1b012
TL
1206 TIME backoff_cutoff; /* When doing exponential backoff,
1207 never back off to an interval
1208 longer than this amount. */
27fe61a7
TL
1209 u_int32_t requested_lease; /* Requested lease time, if user
1210 doesn't configure one. */
6b3b97e1 1211 struct string_list *media; /* Possible network media values. */
32a47563 1212 char *script_name; /* Name of config script. */
432604c3 1213 char *vendor_space_name; /* Name of config script. */
08512bce 1214 enum policy bootp_policy;
cc26de46
TL
1215 /* Ignore, accept or prefer BOOTP
1216 responses. */
08512bce
TL
1217 enum policy auth_policy;
1218 /* Require authentication, prefer
1219 authentication, or don't try to
1220 authenticate. */
6b3b97e1 1221 struct string_list *medium; /* Current network medium. */
0c7802b1 1222
febbd402 1223 struct iaddrmatchlist *reject_list; /* Servers to reject. */
27fe61a7 1224
626ca6a2
TL
1225 int omapi_port; /* port on which to accept OMAPI
1226 connections, or -1 for no
1227 listener. */
98311e4b
DH
1228 int do_forward_update; /* If nonzero, and if we have the
1229 information we need, update the
1230 A record for the address we get. */
cc26de46
TL
1231};
1232
1233/* Per-interface state used in the dhcp client... */
98bd7ca0 1234/* XXX: consider union {}'ing this for v4/v6. */
cc26de46 1235struct client_state {
734d2258
TL
1236 struct client_state *next;
1237 struct interface_info *interface;
1238 char *name;
1239
98bd7ca0
DH
1240 /* Common values. */
1241 struct client_config *config; /* Client configuration. */
1242 struct string_list *env; /* Client script environment. */
a34feb7d 1243 int envc; /* Number of entries in environment. */
98bd7ca0
DH
1244 struct option_state *sent_options; /* Options we sent. */
1245 enum dhcp_state state; /* Current state for this interface. */
5d082abd 1246 TIME last_write; /* Last time this state was written. */
98bd7ca0
DH
1247
1248 /* DHCPv4 values. */
cc26de46
TL
1249 struct client_lease *active; /* Currently active lease. */
1250 struct client_lease *new; /* New lease. */
1251 struct client_lease *offered_leases; /* Leases offered to us. */
1252 struct client_lease *leases; /* Leases we currently hold. */
f79e49f3 1253 struct client_lease *alias; /* Alias lease. */
cc26de46 1254
cc26de46
TL
1255 struct iaddr destination; /* Where to send packet. */
1256 u_int32_t xid; /* Transaction ID. */
64826b61 1257 u_int16_t secs; /* secs value from DHCPDISCOVER. */
cc26de46 1258 TIME first_sending; /* When was first copy sent? */
6b3b97e1
TL
1259 TIME interval; /* What's the current resend interval? */
1260 struct string_list *medium; /* Last media type tried. */
cc26de46 1261 struct dhcp_packet packet; /* Outgoing DHCP packet. */
b1b7b521 1262 unsigned packet_length; /* Actual length of generated packet. */
cc26de46 1263
41fb155b
TL
1264 struct iaddr requested_address; /* Address we would like to get. */
1265
98bd7ca0
DH
1266 /* DHCPv6 values. */
1267 unsigned char dhcpv6_transaction_id[3];
1268 u_int8_t refresh_type;
1269
1270 struct dhc6_lease *active_lease;
1271 struct dhc6_lease *old_lease;
1272 struct dhc6_lease *advertised_leases;
1273 struct dhc6_lease *selected_lease;
1274 struct dhc6_lease *held_leases;
1275
be62cf06 1276 struct timeval start_time;
98bd7ca0
DH
1277 u_int16_t elapsed;
1278 int txcount;
1279
1280 /* See RFC3315 section 14. */
be62cf06
FD
1281 TIME RT; /* In hundredths of seconds. */
1282 TIME IRT; /* In hundredths of seconds. */
1283 TIME MRC; /* Count. */
1284 TIME MRT; /* In hundredths of seconds. */
1285 TIME MRD; /* In seconds, relative. */
1286 TIME next_MRD; /* In seconds, absolute. */
98bd7ca0
DH
1287
1288 /* Rather than a state, we use a function that shifts around
1289 * depending what stage of life the v6 state machine is in.
1290 * This is where incoming packets are dispatched to (sometimes
1291 * a no-op).
1292 */
1293 void (*v6_handler)(struct packet *, struct client_state *);
98bf1607
SR
1294
1295 /*
1296 * A pointer to the state of the ddns update for this lease.
1297 * It should be set while the update is in progress and cleared
1298 * when the update finishes. It can be used to cancel the
1299 * update if we want to do a different update.
1300 */
1301 struct dhcp_ddns_cb *ddns_cb;
98bd7ca0 1302};
d758ad8c 1303
98bd7ca0
DH
1304struct envadd_state {
1305 struct client_state *client;
1306 const char *prefix;
1307};
1308
1309struct dns_update_state {
1310 struct client_state *client;
1311 struct iaddr address;
1312 int dns_update_timeout;
cc26de46
TL
1313};
1314
17b95f41
TL
1315/* Information about each network interface. */
1316
1317struct interface_info {
4fe74d72 1318 OMAPI_OBJECT_PREAMBLE;
17b95f41 1319 struct interface_info *next; /* Next interface in list... */
c626ae69
TL
1320 struct shared_network *shared_network;
1321 /* Networks connected to this interface. */
17b95f41 1322 struct hardware hw_address; /* Its physical address. */
98bd7ca0
DH
1323 struct in_addr *addresses; /* Addresses associated with this
1324 * interface.
1325 */
1326 int address_count; /* Number of addresses stored. */
1327 int address_max; /* Size of addresses buffer. */
a34feb7d 1328 struct in6_addr *v6addresses; /* IPv6 addresses associated with
98bd7ca0
DH
1329 this interface. */
1330 int v6address_count; /* Number of IPv6 addresses associated
1331 with this interface. */
1332 int v6address_max; /* Maximum number of IPv6 addresses
1333 we can store in current buffer. */
c4763f5f
TL
1334
1335 u_int8_t *circuit_id; /* Circuit ID associated with this
1336 interface. */
b1b7b521 1337 unsigned circuit_id_len; /* Length of Circuit ID, if there
c4763f5f
TL
1338 is one. */
1339 u_int8_t *remote_id; /* Remote ID associated with this
1340 interface (if any). */
b1b7b521 1341 unsigned remote_id_len; /* Length of Remote ID. */
c4763f5f 1342
17b95f41 1343 char name [IFNAMSIZ]; /* Its name... */
ecddae64 1344 int index; /* Its if_nametoindex(). */
17b95f41
TL
1345 int rfdesc; /* Its read file descriptor. */
1346 int wfdesc; /* Its write file descriptor, if
1347 different. */
1348 unsigned char *rbuf; /* Read buffer, if required. */
98311e4b 1349 unsigned int rbuf_max; /* Size of read buffer. */
17b95f41
TL
1350 size_t rbuf_offset; /* Current offset into buffer. */
1351 size_t rbuf_len; /* Length of data in buffer. */
c626ae69 1352
41fb155b 1353 struct ifreq *ifp; /* Pointer to ifreq struct. */
98bd7ca0
DH
1354 int configured; /* If set to 1, interface has at least
1355 * one valid IP address.
1356 */
7f91dcfb
TL
1357 u_int32_t flags; /* Control flags... */
1358#define INTERFACE_REQUESTED 1
5a526cf8 1359#define INTERFACE_AUTOMATIC 2
347de8bd 1360#define INTERFACE_RUNNING 4
7de20a95
EH
1361#define INTERFACE_DOWNSTREAM 8
1362#define INTERFACE_UPSTREAM 16
1363#define INTERFACE_STREAMS (INTERFACE_DOWNSTREAM | INTERFACE_UPSTREAM)
cc26de46
TL
1364
1365 /* Only used by DHCP client code. */
1366 struct client_state *client;
a57df74a
DH
1367# if defined(USE_DLPI_SEND) || defined(USE_DLPI_RECEIVE) || \
1368 defined(USE_DLPI_HWADDR)
3d2aa1bf
BC
1369 int dlpi_sap_length;
1370 struct hardware dlpi_broadcast_addr;
1371# endif /* DLPI_SEND || DLPI_RECEIVE */
0829d595 1372 struct hardware anycast_mac_addr;
17b95f41
TL
1373};
1374
1375struct hardware_link {
1376 struct hardware_link *next;
1377 char name [IFNAMSIZ];
1378 struct hardware address;
1379};
1380
6368a1bd
DH
1381struct leasequeue {
1382 struct leasequeue *prev;
1383 struct leasequeue *next;
1384 struct lease *lease;
1385};
1386
76d5bd36
TL
1387typedef void (*tvref_t)(void *, void *, const char *, int);
1388typedef void (*tvunref_t)(void *, const char *, int);
cc26de46
TL
1389struct timeout {
1390 struct timeout *next;
be62cf06 1391 struct timeval when;
a34feb7d 1392 void (*func) (void *);
6e5ed8bf 1393 void *what;
76d5bd36
TL
1394 tvref_t ref;
1395 tvunref_t unref;
a34feb7d 1396 isc_timer_t *isc_timeout;
6e5ed8bf
TL
1397};
1398
6368a1bd
DH
1399struct eventqueue {
1400 struct eventqueue *next;
1401 void (*handler)(void *);
1402};
1403
6e5ed8bf
TL
1404struct protocol {
1405 struct protocol *next;
1406 int fd;
a34feb7d 1407 void (*handler) (struct protocol *);
6e5ed8bf 1408 void *local;
cc26de46
TL
1409};
1410
94f08824
TL
1411struct dns_query; /* forward */
1412
1413struct dns_wakeup {
1414 struct dns_wakeup *next; /* Next wakeup in chain. */
a34feb7d 1415 void (*func) (struct dns_query *);
94f08824
TL
1416};
1417
5142937c
TL
1418struct dns_question {
1419 u_int16_t type; /* Type of query. */
1420 u_int16_t class; /* Class of query. */
1421 unsigned char data [1]; /* Query data. */
1422};
1423
1424struct dns_answer {
1425 u_int16_t type; /* Type of answer. */
1426 u_int16_t class; /* Class of answer. */
1427 int count; /* Number of answers. */
1428 unsigned char *answers[1]; /* Pointers to answers. */
1429};
1430
94f08824
TL
1431struct dns_query {
1432 struct dns_query *next; /* Next query in hash bucket. */
5142937c 1433 u_int32_t hash; /* Hash bucket index. */
94f08824
TL
1434 TIME expiry; /* Query expiry time (zero if not yet
1435 answered. */
1436 u_int16_t id; /* Query ID (also hash table index) */
1437 caddr_t waiters; /* Pointer to list of things waiting
1438 on this query. */
5142937c
TL
1439
1440 struct dns_question *question; /* Question, internal format. */
1441 struct dns_answer *answer; /* Answer, internal format. */
1442
1443 unsigned char *query; /* Query formatted for DNS server. */
b1b7b521 1444 unsigned len; /* Length of entire query. */
94f08824
TL
1445 int sent; /* The query has been sent. */
1446 struct dns_wakeup *wakeups; /* Wakeups to call if this query is
1447 answered. */
1448 struct name_server *next_server; /* Next server to try. */
1449 int backoff; /* Current backoff, in seconds. */
1450};
1451
e54ff84f
SR
1452#define DNS_ZONE_ACTIVE 0
1453#define DNS_ZONE_INACTIVE 1
3f09cb5a
TL
1454struct dns_zone {
1455 int refcnt;
1456 TIME timeout;
1457 char *name;
1458 struct option_cache *primary;
1459 struct option_cache *secondary;
d424157d
SR
1460 struct option_cache *primary6;
1461 struct option_cache *secondary6;
49146f3c 1462 struct auth_key *key;
e54ff84f 1463 u_int16_t flags;
3f09cb5a
TL
1464};
1465
d758ad8c
TL
1466struct icmp_state {
1467 OMAPI_OBJECT_PREAMBLE;
1468 int socket;
a34feb7d 1469 void (*icmp_handler) (struct iaddr, u_int8_t *, int);
d758ad8c
TL
1470};
1471
f3aad410
TL
1472#include "ctrace.h"
1473
d7837182
TL
1474/* Bitmask of dhcp option codes. */
1475typedef unsigned char option_mask [16];
1476
1477/* DHCP Option mask manipulation macros... */
1478#define OPTION_ZERO(mask) (memset (mask, 0, 16))
1479#define OPTION_SET(mask, bit) (mask [bit >> 8] |= (1 << (bit & 7)))
1480#define OPTION_CLR(mask, bit) (mask [bit >> 8] &= ~(1 << (bit & 7)))
1481#define OPTION_ISSET(mask, bit) (mask [bit >> 8] & (1 << (bit & 7)))
1482#define OPTION_ISCLR(mask, bit) (!OPTION_ISSET (mask, bit))
1483
1484/* An option occupies its length plus two header bytes (code and
1485 length) for every 255 bytes that must be stored. */
1486#define OPTION_SPACE(x) ((x) + 2 * ((x) / 255 + 1))
1487
1488/* Default path to dhcpd config file. */
d7837182 1489#ifdef DEBUG
80ba033e 1490#undef _PATH_DHCPD_CONF
d7837182 1491#define _PATH_DHCPD_CONF "dhcpd.conf"
80ba033e 1492#undef _PATH_DHCPD_DB
1358b874 1493#define _PATH_DHCPD_DB "dhcpd.leases"
75135a3f
EH
1494#undef _PATH_DHCPD6_DB
1495#define _PATH_DHCPD6_DB "dhcpd6.leases"
98311e4b
DH
1496#undef _PATH_DHCPD_PID
1497#define _PATH_DHCPD_PID "dhcpd.pid"
75135a3f
EH
1498#undef _PATH_DHCPD6_PID
1499#define _PATH_DHCPD6_PID "dhcpd6.pid"
fe5b0fdd 1500#else /* !DEBUG */
75135a3f 1501
a8b53b42 1502#ifndef _PATH_DHCPD_CONF
d7837182 1503#define _PATH_DHCPD_CONF "/etc/dhcpd.conf"
fe5b0fdd 1504#endif /* DEBUG */
a8b53b42
TL
1505
1506#ifndef _PATH_DHCPD_DB
fe5b0fdd 1507#define _PATH_DHCPD_DB LOCALSTATEDIR"/db/dhcpd.leases"
d7837182 1508#endif
a8b53b42 1509
75135a3f
EH
1510#ifndef _PATH_DHCPD6_DB
1511#define _PATH_DHCPD6_DB LOCALSTATEDIR"/db/dhcpd6.leases"
1512#endif
1513
a8b53b42 1514#ifndef _PATH_DHCPD_PID
fe5b0fdd 1515#define _PATH_DHCPD_PID LOCALSTATEDIR"/run/dhcpd.pid"
a8b53b42 1516#endif
75135a3f
EH
1517
1518#ifndef _PATH_DHCPD6_PID
1519#define _PATH_DHCPD6_PID LOCALSTATEDIR"/run/dhcpd6.pid"
d7837182
TL
1520#endif
1521
75135a3f
EH
1522#endif /* DEBUG */
1523
cc26de46
TL
1524#ifndef _PATH_DHCLIENT_CONF
1525#define _PATH_DHCLIENT_CONF "/etc/dhclient.conf"
1526#endif
1527
e47988bf
TL
1528#ifndef _PATH_DHCLIENT_SCRIPT
1529#define _PATH_DHCLIENT_SCRIPT "/sbin/dhclient-script"
1530#endif
1531
cc26de46 1532#ifndef _PATH_DHCLIENT_PID
fe5b0fdd 1533#define _PATH_DHCLIENT_PID LOCALSTATEDIR"/run/dhclient.pid"
cc26de46
TL
1534#endif
1535
98bd7ca0 1536#ifndef _PATH_DHCLIENT6_PID
fe5b0fdd 1537#define _PATH_DHCLIENT6_PID LOCALSTATEDIR"/run/dhclient6.pid"
98bd7ca0
DH
1538#endif
1539
cc26de46 1540#ifndef _PATH_DHCLIENT_DB
fe5b0fdd 1541#define _PATH_DHCLIENT_DB LOCALSTATEDIR"/db/dhclient.leases"
cc26de46
TL
1542#endif
1543
98bd7ca0 1544#ifndef _PATH_DHCLIENT6_DB
fe5b0fdd 1545#define _PATH_DHCLIENT6_DB LOCALSTATEDIR"/db/dhclient6.leases"
98bd7ca0
DH
1546#endif
1547
0c7802b1
TL
1548#ifndef _PATH_RESOLV_CONF
1549#define _PATH_RESOLV_CONF "/etc/resolv.conf"
1550#endif
cc26de46 1551
8afb9ae0 1552#ifndef _PATH_DHCRELAY_PID
fe5b0fdd 1553#define _PATH_DHCRELAY_PID LOCALSTATEDIR"/run/dhcrelay.pid"
8afb9ae0
TL
1554#endif
1555
7de20a95
EH
1556#ifndef _PATH_DHCRELAY6_PID
1557#define _PATH_DHCRELAY6_PID LOCALSTATEDIR"/run/dhcrelay6.pid"
1558#endif
1559
ab370123
TL
1560#ifndef DHCPD_LOG_FACILITY
1561#define DHCPD_LOG_FACILITY LOG_DAEMON
1562#endif
1563
d7837182
TL
1564#define MAX_TIME 0x7fffffff
1565#define MIN_TIME 0
1566
00e9af8e
SR
1567#ifdef USE_LOG_PID
1568/* include the pid in the syslog messages */
1569#define DHCP_LOG_OPTIONS LOG_NDELAY | LOG_PID
1570#else
1571#define DHCP_LOG_OPTIONS LOG_NDELAY
1572#endif
d9b43370 1573 /* these are referenced */
9322442f 1574typedef struct hash_table ia_hash_t;
1d17db44 1575typedef struct hash_table iasubopt_hash_t;
98bd7ca0 1576
1d17db44 1577 /* IAADDR/IAPREFIX lease */
9322442f 1578
1d17db44 1579struct iasubopt {
98bd7ca0 1580 int refcnt; /* reference count */
9322442f
FD
1581 struct in6_addr addr; /* IPv6 address/prefix */
1582 u_int8_t plen; /* iaprefix prefix length */
98bd7ca0
DH
1583 binding_state_t state; /* state */
1584 struct binding_scope *scope; /* "set var = value;" */
5d89d60f
FD
1585 time_t hard_lifetime_end_time; /* time address expires */
1586 time_t soft_lifetime_end_time; /* time ephemeral expires */
1acab09f
FD
1587 u_int32_t prefer; /* cached preferred lifetime */
1588 u_int32_t valid; /* cached valid lifetime */
9322442f
FD
1589 struct ia_xx *ia; /* IA for this lease */
1590 struct ipv6_pool *ipv6_pool; /* pool for this lease */
d9b43370 1591/*
5d89d60f 1592 * For now, just pick an arbitrary time to keep old hard leases
d9b43370
SK
1593 * around (value in seconds).
1594 */
1595#define EXPIRED_IPV6_CLEANUP_TIME (60*60)
1596
a34feb7d 1597 int heap_index; /* index into heap, or -1
98bd7ca0 1598 (internal use only) */
98bf1607
SR
1599
1600 /*
1601 * A pointer to the state of the ddns update for this lease.
1602 * It should be set while the update is in progress and cleared
1603 * when the update finishes. It can be used to cancel the
1604 * update if we want to do a different update.
1605 */
1606 struct dhcp_ddns_cb *ddns_cb;
1607
a7341359
SR
1608 /* space for the on * executable statements */
1609 struct on_star on_star;
98bd7ca0
DH
1610};
1611
9322442f 1612struct ia_xx {
98bd7ca0
DH
1613 int refcnt; /* reference count */
1614 struct data_string iaid_duid; /* from the client */
9322442f 1615 u_int16_t ia_type; /* IA_XX */
1d17db44
FD
1616 int num_iasubopt; /* number of IAADDR/PREFIX */
1617 int max_iasubopt; /* space available for IAADDR/PREFIX */
1acab09f 1618 time_t cltt; /* client last transaction time */
1d17db44 1619 struct iasubopt **iasubopt; /* pointers to the IAADDR/IAPREFIXs */
98bd7ca0
DH
1620};
1621
9322442f
FD
1622extern ia_hash_t *ia_na_active;
1623extern ia_hash_t *ia_ta_active;
1624extern ia_hash_t *ia_pd_active;
98bd7ca0 1625
01fa619f
SR
1626/*!
1627 *
1628 * \brief ipv6_pool structure
1629 *
1630 * This structure is part of a range of addresses or prefixes.
1631 * A range6 or prefix6 statement will map to one or more of these
1632 * with each pool being a simple block of the form xxxx/yyy and
1633 * all the pools adding up to comprise the entire range. When
1634 * choosing an address or prefix the code will walk through the
1635 * pools until it finds one that is available.
1636 *
1637 * The naming for this structure is unfortunate as there is also
1638 * a v4 pool structure and the two are not equivalent. The v4
1639 * pool matches the ipv6_pond structure. I considered changing the
1640 * name of this structure but concluded that doing so would be worse
1641 * than leaving it as is. Changing it adds some risk and makes for
1642 * larger differences between the 4.1 & 4.2 code and the 4.3 code.
1643 *
1644 */
1645
98bd7ca0
DH
1646struct ipv6_pool {
1647 int refcnt; /* reference count */
9322442f 1648 u_int16_t pool_type; /* IA_xx */
98bd7ca0
DH
1649 struct in6_addr start_addr; /* first IPv6 address */
1650 int bits; /* number of bits, CIDR style */
9322442f 1651 int units; /* allocation unit in bits */
1d17db44 1652 iasubopt_hash_t *leases; /* non-free leases */
fb98e02e
TM
1653 isc_uint64_t num_active; /* count of active leases */
1654 isc_uint64_t num_abandoned; /* count of abandoned leases */
98bd7ca0 1655 isc_heap_t *active_timeouts; /* timeouts for active leases */
1d17db44 1656 int num_inactive; /* count of inactive leases */
a34feb7d 1657 isc_heap_t *inactive_timeouts; /* timeouts for expired or
98bd7ca0 1658 released leases */
a34feb7d 1659 struct shared_network *shared_network; /* shared_network for
98bd7ca0 1660 this pool */
7d6180be 1661 struct subnet *subnet; /* subnet for this pool */
01fa619f
SR
1662 struct ipv6_pond *ipv6_pond; /* pond for this pool */
1663};
1664
1665/*!
1666 *
1667 * \brief ipv6_pond structure
1668 *
1669 * This structure is the ipv6 version of the v4 pool structure.
1670 * It contains the address and prefix information via the pointers
1671 * to the ipv6_pools and the allowability of this pool for a given
1672 * client via the permit lists and the valid TIMEs.
1673 *
1674 */
1675
1676struct ipv6_pond {
1677 int refcnt;
1678 struct ipv6_pond *next;
1679 struct group *group;
1680 struct shared_network *shared_network; /* backpointer to the enclosing
1681 shared network */
1682 struct permit *permit_list; /* allow clients from this list */
1683 struct permit *prohibit_list; /* deny clients from this list */
1684 TIME valid_from; /* deny pool use before this date */
1685 TIME valid_until; /* deny pool use after this date */
1686
1687 struct ipv6_pool **ipv6_pools; /* NULL-terminated array */
1688 int last_ipv6_pool; /* offset of last IPv6 pool
1689 used to issue a lease */
fb98e02e
TM
1690 isc_uint64_t num_total; /* Total number of elements in the pond */
1691 isc_uint64_t num_active; /* Number of elements in the pond in use */
1692 isc_uint64_t num_abandoned; /* count of abandoned leases */
250f7134 1693 int logged; /* already logged a message */
fb98e02e
TM
1694 isc_uint64_t low_threshold; /* low threshold to restart logging */
1695 int jumbo_range;
98bd7ca0
DH
1696};
1697
fb98e02e
TM
1698/*
1699 * Max addresses in a pond that can be supported by log threshold
1700 * Currently based on max value supported by isc_uint64_t.
1701*/
7e35d5b1 1702#define POND_TRACK_MAX ISC_UINT64_MAX
fb98e02e 1703
98bf1607
SR
1704/* Flags and state for dhcp_ddns_cb_t */
1705#define DDNS_UPDATE_ADDR 0x01
1706#define DDNS_UPDATE_PTR 0x02
1707#define DDNS_INCLUDE_RRSET 0x04
1708#define DDNS_CONFLICT_OVERRIDE 0x08
1709#define DDNS_CLIENT_DID_UPDATE 0x10
1710#define DDNS_EXECUTE_NEXT 0x20
1711#define DDNS_ABORT 0x40
3221151b 1712#define DDNS_STATIC_LEASE 0x80
0ef9a46e 1713#define DDNS_ACTIVE_LEASE 0x100
98bf1607
SR
1714/*
1715 * The following two groups are separate and we could reuse
1716 * values but not reusing them may be useful in the future.
1717 */
1718#define DDNS_STATE_CLEANUP 0 // The previous step failed, cleanup
1719
1720#define DDNS_STATE_ADD_FW_NXDOMAIN 1
1721#define DDNS_STATE_ADD_FW_YXDHCID 2
1722#define DDNS_STATE_ADD_PTR 3
1723
1724#define DDNS_STATE_REM_FW_YXDHCID 17
1725#define DDNS_STATE_REM_FW_NXRR 18
1726#define DDNS_STATE_REM_PTR 19
1727
590298e7
SR
1728/*
1729 * Flags for the dns print function
1730 */
1731#define DDNS_PRINT_INBOUND 1
1732#define DDNS_PRINT_OUTBOUND 0
1733
98bf1607
SR
1734struct dhcp_ddns_cb;
1735
1736typedef void (*ddns_action_t)(struct dhcp_ddns_cb *ddns_cb,
1737 isc_result_t result);
1738
1739typedef struct dhcp_ddns_cb {
1740 struct data_string fwd_name;
1741 struct data_string rev_name;
1742 struct data_string dhcid;
1743 struct iaddr address;
1744 int address_type;
1745
1746 unsigned long ttl;
1747
1748 unsigned char zone_name[DHCP_MAXDNS_WIRE];
1749 isc_sockaddrlist_t zone_server_list;
1750 isc_sockaddr_t zone_addrs[DHCP_MAXNS];
1751 int zone_addr_count;
1752 struct dns_zone *zone;
1753
0ef9a46e 1754 u_int16_t flags;
98bf1607
SR
1755 TIME timeout;
1756 int state;
1757 ddns_action_t cur_func;
1758
1759 struct dhcp_ddns_cb * next_op;
1760
1761 /* Lease or client state that triggered the ddns operation */
1762 void *lease;
1763 struct binding_scope **scope;
a34feb7d 1764
98bf1607
SR
1765 void *transaction;
1766 void *dataspace;
d7d9c0c7
SR
1767
1768 dns_rdataclass_t dhcid_class;
1769 char *lease_tag;
98bf1607
SR
1770} dhcp_ddns_cb_t;
1771
98bd7ca0
DH
1772extern struct ipv6_pool **pools;
1773extern int num_pools;
1774
d7837182
TL
1775/* External definitions... */
1776
98311e4b
DH
1777HASH_FUNCTIONS_DECL (group, const char *, struct group_object, group_hash_t)
1778HASH_FUNCTIONS_DECL (universe, const char *, struct universe, universe_hash_t)
f7fdb216
DH
1779HASH_FUNCTIONS_DECL (option_name, const char *, struct option,
1780 option_name_hash_t)
1781HASH_FUNCTIONS_DECL (option_code, const unsigned *, struct option,
1782 option_code_hash_t)
98311e4b 1783HASH_FUNCTIONS_DECL (dns_zone, const char *, struct dns_zone, dns_zone_hash_t)
6708d944
DH
1784HASH_FUNCTIONS_DECL(lease_ip, const unsigned char *, struct lease,
1785 lease_ip_hash_t)
1786HASH_FUNCTIONS_DECL(lease_id, const unsigned char *, struct lease,
1787 lease_id_hash_t)
98311e4b
DH
1788HASH_FUNCTIONS_DECL (host, const unsigned char *, struct host_decl, host_hash_t)
1789HASH_FUNCTIONS_DECL (class, const char *, struct class, class_hash_t)
1790
d7837182
TL
1791/* options.c */
1792
432604c3 1793extern struct option *vendor_cfg_option;
a34feb7d
TM
1794int parse_options (struct packet *);
1795int parse_option_buffer (struct option_state *, const unsigned char *,
1796 unsigned, struct universe *);
6f56b7e2 1797struct universe *find_option_universe (struct option *, const char *);
432604c3 1798int parse_encapsulated_suboptions (struct option_state *, struct option *,
6f56b7e2
TL
1799 const unsigned char *, unsigned,
1800 struct universe *, const char *);
a34feb7d
TM
1801int cons_options (struct packet *, struct dhcp_packet *, struct lease *,
1802 struct client_state *,
1803 int, struct option_state *, struct option_state *,
1804 struct binding_scope **,
1805 int, int, int, struct data_string *, const char *);
432604c3 1806int fqdn_universe_decode (struct option_state *,
6f56b7e2 1807 const unsigned char *, unsigned, struct universe *);
98bd7ca0
DH
1808struct option_cache *
1809lookup_fqdn6_option(struct universe *universe, struct option_state *options,
1810 unsigned code);
1811void
1812save_fqdn6_option(struct universe *universe, struct option_state *options,
bead14ea 1813 struct option_cache *oc, isc_boolean_t appendp);
98bd7ca0
DH
1814void
1815delete_fqdn6_option(struct universe *universe, struct option_state *options,
1816 int code);
1817void
1818fqdn6_option_space_foreach(struct packet *packet, struct lease *lease,
1819 struct client_state *client_state,
1820 struct option_state *in_options,
1821 struct option_state *cfg_options,
1822 struct binding_scope **scope,
1823 struct universe *u, void *stuff,
1824 void (*func)(struct option_cache *,
1825 struct packet *,
1826 struct lease *,
1827 struct client_state *,
1828 struct option_state *,
1829 struct option_state *,
1830 struct binding_scope **,
1831 struct universe *, void *));
1832int
1833fqdn6_option_space_encapsulate(struct data_string *result,
1834 struct packet *packet, struct lease *lease,
1835 struct client_state *client_state,
1836 struct option_state *in_options,
1837 struct option_state *cfg_options,
1838 struct binding_scope **scope,
1839 struct universe *universe);
1840int
1841fqdn6_universe_decode(struct option_state *options,
1842 const unsigned char *buffer, unsigned length,
1843 struct universe *u);
1844int append_option(struct data_string *dst, struct universe *universe,
1845 struct option *option, struct data_string *src);
e2624b82
EH
1846int
1847store_options(int *ocount,
1848 unsigned char *buffer, unsigned buflen, unsigned index,
1849 struct packet *packet, struct lease *lease,
1850 struct client_state *client_state,
1851 struct option_state *in_options,
1852 struct option_state *cfg_options,
1853 struct binding_scope **scope,
1854 unsigned *priority_list, int priority_len,
1855 unsigned first_cutoff, int second_cutoff, int terminate,
1856 const char *vuname);
98bd7ca0
DH
1857int store_options6(char *, int, struct option_state *, struct packet *,
1858 const int *, struct data_string *);
88cd8aca
DH
1859int format_has_text(const char *);
1860int format_min_length(const char *, struct option_cache *);
a34feb7d
TM
1861const char *pretty_print_option (struct option *, const unsigned char *,
1862 unsigned, int, int);
b543fea9
DH
1863int pretty_escape(char **, char *, const unsigned char **,
1864 const unsigned char *);
432604c3 1865int get_option (struct data_string *, struct universe *,
159bcce3 1866 struct packet *, struct lease *, struct client_state *,
432604c3 1867 struct option_state *, struct option_state *,
d758ad8c
TL
1868 struct option_state *, struct binding_scope **, unsigned,
1869 const char *, int);
250f7134
SR
1870int get_option_int (int *, struct universe *,
1871 struct packet *, struct lease *, struct client_state *,
1872 struct option_state *, struct option_state *,
1873 struct option_state *, struct binding_scope **, unsigned,
1874 const char *, int);
432604c3
TL
1875void set_option (struct universe *, struct option_state *,
1876 struct option_cache *, enum statement_op);
a34feb7d
TM
1877struct option_cache *lookup_option (struct universe *,
1878 struct option_state *, unsigned);
1879struct option_cache *lookup_hashed_option (struct universe *,
1880 struct option_state *,
1881 unsigned);
98bd7ca0 1882struct option_cache *next_hashed_option(struct universe *,
a34feb7d 1883 struct option_state *,
98bd7ca0 1884 struct option_cache *);
432604c3
TL
1885int save_option_buffer (struct universe *, struct option_state *,
1886 struct buffer *, unsigned char *, unsigned,
f7fdb216 1887 unsigned, int);
bead14ea
DH
1888int append_option_buffer(struct universe *, struct option_state *,
1889 struct buffer *, unsigned char *, unsigned,
1890 unsigned, int);
a34feb7d 1891void build_server_oro(struct data_string *, struct option_state *,
98bd7ca0 1892 const char *, int);
bead14ea
DH
1893void save_option(struct universe *, struct option_state *,
1894 struct option_cache *);
1895void also_save_option(struct universe *, struct option_state *,
1896 struct option_cache *);
1897void save_hashed_option(struct universe *, struct option_state *,
1898 struct option_cache *, isc_boolean_t appendp);
a34feb7d
TM
1899void delete_option (struct universe *, struct option_state *, int);
1900void delete_hashed_option (struct universe *,
1901 struct option_state *, int);
1902int option_cache_dereference (struct option_cache **,
1903 const char *, int);
1904int hashed_option_state_dereference (struct universe *,
1905 struct option_state *,
1906 const char *, int);
1907int store_option (struct data_string *,
1908 struct universe *, struct packet *, struct lease *,
1909 struct client_state *,
1910 struct option_state *, struct option_state *,
1911 struct binding_scope **, struct option_cache *);
1912int option_space_encapsulate (struct data_string *,
1913 struct packet *, struct lease *,
1914 struct client_state *,
1915 struct option_state *,
1916 struct option_state *,
1917 struct binding_scope **,
1918 struct data_string *);
1919int hashed_option_space_encapsulate (struct data_string *,
f3e8ea32 1920 struct packet *, struct lease *,
159bcce3 1921 struct client_state *,
f3e8ea32 1922 struct option_state *,
4f58da18 1923 struct option_state *,
6ceb9118 1924 struct binding_scope **,
a34feb7d
TM
1925 struct universe *);
1926int nwip_option_space_encapsulate (struct data_string *,
1927 struct packet *, struct lease *,
1928 struct client_state *,
1929 struct option_state *,
1930 struct option_state *,
1931 struct binding_scope **,
1932 struct universe *);
432604c3
TL
1933int fqdn_option_space_encapsulate (struct data_string *,
1934 struct packet *, struct lease *,
159bcce3 1935 struct client_state *,
432604c3
TL
1936 struct option_state *,
1937 struct option_state *,
1938 struct binding_scope **,
1939 struct universe *);
159bcce3
TL
1940void suboption_foreach (struct packet *, struct lease *, struct client_state *,
1941 struct option_state *, struct option_state *,
1942 struct binding_scope **, struct universe *, void *,
1943 void (*) (struct option_cache *, struct packet *,
1944 struct lease *, struct client_state *,
1945 struct option_state *, struct option_state *,
6f56b7e2
TL
1946 struct binding_scope **,
1947 struct universe *, void *),
1948 struct option_cache *, const char *);
432604c3 1949void option_space_foreach (struct packet *, struct lease *,
159bcce3 1950 struct client_state *,
432604c3
TL
1951 struct option_state *,
1952 struct option_state *,
1953 struct binding_scope **,
1954 struct universe *, void *,
1955 void (*) (struct option_cache *,
1956 struct packet *,
159bcce3
TL
1957 struct lease *, struct client_state *,
1958 struct option_state *,
432604c3
TL
1959 struct option_state *,
1960 struct binding_scope **,
1961 struct universe *, void *));
1962void hashed_option_space_foreach (struct packet *, struct lease *,
159bcce3 1963 struct client_state *,
432604c3
TL
1964 struct option_state *,
1965 struct option_state *,
1966 struct binding_scope **,
1967 struct universe *, void *,
1968 void (*) (struct option_cache *,
1969 struct packet *,
1970 struct lease *,
159bcce3 1971 struct client_state *,
432604c3
TL
1972 struct option_state *,
1973 struct option_state *,
1974 struct binding_scope **,
1975 struct universe *, void *));
a34feb7d
TM
1976int linked_option_get (struct data_string *, struct universe *,
1977 struct packet *, struct lease *,
1978 struct client_state *,
1979 struct option_state *, struct option_state *,
1980 struct option_state *, struct binding_scope **,
1981 unsigned);
1982int linked_option_state_dereference (struct universe *,
1983 struct option_state *,
1984 const char *, int);
bead14ea
DH
1985void save_linked_option(struct universe *, struct option_state *,
1986 struct option_cache *, isc_boolean_t appendp);
432604c3 1987void linked_option_space_foreach (struct packet *, struct lease *,
159bcce3 1988 struct client_state *,
432604c3
TL
1989 struct option_state *,
1990 struct option_state *,
1991 struct binding_scope **,
1992 struct universe *, void *,
1993 void (*) (struct option_cache *,
1994 struct packet *,
1995 struct lease *,
159bcce3 1996 struct client_state *,
432604c3
TL
1997 struct option_state *,
1998 struct option_state *,
1999 struct binding_scope **,
2000 struct universe *, void *));
2001int linked_option_space_encapsulate (struct data_string *, struct packet *,
159bcce3
TL
2002 struct lease *, struct client_state *,
2003 struct option_state *,
432604c3
TL
2004 struct option_state *,
2005 struct binding_scope **,
2006 struct universe *);
2007void delete_linked_option (struct universe *, struct option_state *, int);
2008struct option_cache *lookup_linked_option (struct universe *,
2009 struct option_state *, unsigned);
a34feb7d
TM
2010void do_packet (struct interface_info *,
2011 struct dhcp_packet *, unsigned,
2012 unsigned int, struct iaddr, struct hardware *);
2013void do_packet6(struct interface_info *, const char *,
98bd7ca0
DH
2014 int, int, const struct iaddr *, isc_boolean_t);
2015int packet6_len_okay(const char *, int);
2016
de87ffe3
SR
2017int validate_packet(struct packet *);
2018
98bd7ca0
DH
2019int add_option(struct option_state *options,
2020 unsigned int option_num,
a34feb7d
TM
2021 void *data,
2022 unsigned int data_len);
d7837182 2023
45c332f0
SR
2024void parse_vendor_option(struct packet *packet,
2025 struct lease *lease,
2026 struct client_state *client_state,
2027 struct option_state *in_options,
2028 struct option_state *out_options,
2029 struct binding_scope **scope);
2030
d7837182 2031/* dhcpd.c */
be62cf06
FD
2032extern struct timeval cur_tv;
2033#define cur_time cur_tv.tv_sec
685963dc 2034
06eb8bab 2035extern int ddns_update_style;
cde11a4c 2036extern int dont_use_fsync;
7116a34f 2037extern int server_id_check;
dbcc689e 2038
1a006ff6 2039extern int prefix_length_mode;
347d4962 2040extern int authoring_byte_order;
1a006ff6 2041
b1b7b521
TL
2042extern const char *path_dhcpd_conf;
2043extern const char *path_dhcpd_db;
2044extern const char *path_dhcpd_pid;
e2ac5814 2045
5142937c 2046extern int dhcp_max_agent_option_packet_length;
6368a1bd 2047extern struct eventqueue *rw_queue_empty;
5142937c 2048
7a6c9368
SR
2049#if defined (PARANOIA)
2050extern uid_t set_uid;
2051extern gid_t set_gid;
2052#endif
2053
98bd7ca0
DH
2054int main(int, char **);
2055void postconf_initialization(int);
2056void postdb_startup(void);
a34feb7d
TM
2057void cleanup (void);
2058void lease_pinged (struct iaddr, u_int8_t *, int);
2059void lease_ping_timeout (void *);
20916cae 2060int dhcpd_interface_setup_hook (struct interface_info *ip, struct iaddr *ia);
06eb8bab 2061extern enum dhcp_shutdown_state shutdown_state;
d758ad8c
TL
2062isc_result_t dhcp_io_shutdown (omapi_object_t *, void *);
2063isc_result_t dhcp_set_control_state (control_object_state_t oldstate,
2064 control_object_state_t newstate);
95fd7038
DH
2065#if defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
2066void relinquish_ackqueue(void);
2067#endif
d7837182
TL
2068
2069/* conflex.c */
a34feb7d
TM
2070isc_result_t new_parse (struct parse **, int,
2071 char *, unsigned, const char *, int);
2072isc_result_t end_parse (struct parse **);
bda33169
SK
2073isc_result_t save_parse_state(struct parse *cfile);
2074isc_result_t restore_parse_state(struct parse *cfile);
a34feb7d
TM
2075enum dhcp_token next_token (const char **, unsigned *, struct parse *);
2076enum dhcp_token peek_token (const char **, unsigned *, struct parse *);
2077enum dhcp_token next_raw_token(const char **rval, unsigned *rlen,
bda33169 2078 struct parse *cfile);
a34feb7d 2079enum dhcp_token peek_raw_token(const char **rval, unsigned *rlen,
bda33169 2080 struct parse *cfile);
dc9d7b08
MA
2081/*
2082 * Use skip_token when we are skipping a token we have previously
2083 * used peek_token on as we know what the result will be in this case.
2084 */
2085#define skip_token(a,b,c) ((void) next_token((a),(b),(c)))
2086
d7837182
TL
2087
2088/* confpars.c */
f3aad410 2089void parse_trace_setup (void);
a34feb7d 2090isc_result_t readconf (void);
f3aad410
TL
2091isc_result_t read_conf_file (const char *, struct group *, int, int);
2092#if defined (TRACING)
2093void trace_conf_input (trace_type_t *, unsigned, char *);
2094void trace_conf_stop (trace_type_t *ttype);
2095#endif
2096isc_result_t conf_file_subparse (struct parse *, struct group *, int);
2097isc_result_t lease_file_subparse (struct parse *);
a34feb7d
TM
2098int parse_statement (struct parse *, struct group *, int,
2099 struct host_decl *, int);
a7982987 2100#if defined (FAILOVER_PROTOCOL)
a34feb7d 2101void parse_failover_peer (struct parse *, struct group *, int);
a7982987
TL
2102void parse_failover_state_declaration (struct parse *,
2103 dhcp_failover_state_t *);
a34feb7d
TM
2104void parse_failover_state (struct parse *,
2105 enum failover_state *, TIME *);
a7982987 2106#endif
98311e4b 2107int permit_list_match (struct permit *, struct permit *);
a34feb7d 2108void parse_pool_statement (struct parse *, struct group *, int);
a34feb7d
TM
2109int parse_lbrace (struct parse *);
2110void parse_host_declaration (struct parse *, struct group *);
2111int parse_class_declaration (struct class **, struct parse *,
2112 struct group *, int);
2113void parse_shared_net_declaration (struct parse *, struct group *);
2114void parse_subnet_declaration (struct parse *,
2115 struct shared_network *);
2116void parse_subnet6_declaration (struct parse *,
2117 struct shared_network *);
2118void parse_group_declaration (struct parse *, struct group *);
2119int parse_fixed_addr_param (struct option_cache **,
2120 struct parse *, enum dhcp_token);
2121int parse_lease_declaration (struct lease **, struct parse *);
6705543f
DH
2122int parse_ip6_addr(struct parse *, struct iaddr *);
2123int parse_ip6_addr_expr(struct expression **, struct parse *);
1d9774ab 2124int parse_ip6_prefix(struct parse *, struct iaddr *, u_int8_t *);
a34feb7d
TM
2125void parse_address_range (struct parse *, struct group *, int,
2126 struct pool *, struct lease **);
01fa619f
SR
2127void parse_address_range6(struct parse *cfile, struct group *group,
2128 struct ipv6_pond *);
2129void parse_prefix6(struct parse *cfile, struct group *group,
2130 struct ipv6_pond *);
80c9fdb0 2131void parse_fixed_prefix6(struct parse *cfile, struct host_decl *host_decl);
98bd7ca0 2132void parse_ia_na_declaration(struct parse *);
1d9774ab
FD
2133void parse_ia_ta_declaration(struct parse *);
2134void parse_ia_pd_declaration(struct parse *);
98bd7ca0
DH
2135void parse_server_duid(struct parse *cfile);
2136void parse_server_duid_conf(struct parse *cfile);
01fa619f 2137void parse_pool6_statement (struct parse *, struct group *, int);
347d4962 2138uint32_t parse_byte_order_uint32(const void *source);
8bdd4d02 2139
b992d7e2 2140/* ddns.c */
98bd7ca0 2141int ddns_updates(struct packet *, struct lease *, struct lease *,
1d17db44 2142 struct iasubopt *, struct iasubopt *, struct option_state *);
d13db163
SR
2143isc_result_t ddns_removals(struct lease *, struct iasubopt *,
2144 struct dhcp_ddns_cb *, isc_boolean_t);
7aa153b8
SR
2145#if defined (TRACING)
2146void trace_ddns_init(void);
2147#endif
b992d7e2 2148
8bdd4d02 2149/* parse.c */
dbcc689e
TL
2150void add_enumeration (struct enumeration *);
2151struct enumeration *find_enumeration (const char *, int);
2152struct enumeration_value *find_enumeration_value (const char *, int,
c54db708 2153 unsigned *,
dbcc689e 2154 const char *);
a34feb7d
TM
2155void skip_to_semi (struct parse *);
2156void skip_to_rbrace (struct parse *, int);
2157int parse_semi (struct parse *);
2158int parse_string (struct parse *, char **, unsigned *);
2159char *parse_host_name (struct parse *);
2160int parse_ip_addr_or_hostname (struct expression **,
2161 struct parse *, int);
2162void parse_hardware_param (struct parse *, struct hardware *);
2163void parse_lease_time (struct parse *, TIME *);
2164unsigned char *parse_numeric_aggregate (struct parse *,
2165 unsigned char *, unsigned *,
2166 int, int, unsigned);
2167void convert_num (struct parse *, unsigned char *, const char *,
2168 int, unsigned);
2169TIME parse_date (struct parse *);
b1d3778c 2170TIME parse_date_core(struct parse *);
a34feb7d
TM
2171isc_result_t parse_option_name (struct parse *, int, int *,
2172 struct option **);
2173void parse_option_space_decl (struct parse *);
2174int parse_option_code_definition (struct parse *, struct option *);
a59ea078 2175int parse_base64 (struct data_string *, struct parse *);
a34feb7d
TM
2176int parse_cshl (struct data_string *, struct parse *);
2177int parse_executable_statement (struct executable_statement **,
2178 struct parse *, int *,
2179 enum expression_context);
2180int parse_executable_statements (struct executable_statement **,
2181 struct parse *, int *,
2182 enum expression_context);
3f09cb5a 2183int parse_zone (struct dns_zone *, struct parse *);
a59ea078 2184int parse_key (struct parse *);
a34feb7d
TM
2185int parse_on_statement (struct executable_statement **,
2186 struct parse *, int *);
2187int parse_switch_statement (struct executable_statement **,
2188 struct parse *, int *);
2189int parse_case_statement (struct executable_statement **,
2190 struct parse *, int *,
2191 enum expression_context);
2192int parse_if_statement (struct executable_statement **,
2193 struct parse *, int *);
2194int parse_boolean_expression (struct expression **,
2195 struct parse *, int *);
d15aa964 2196int parse_boolean (struct parse *);
a34feb7d
TM
2197int parse_data_expression (struct expression **,
2198 struct parse *, int *);
2199int parse_numeric_expression (struct expression **,
2200 struct parse *, int *);
2201int parse_dns_expression (struct expression **, struct parse *, int *);
2202int parse_non_binary (struct expression **, struct parse *, int *,
2203 enum expression_context);
2204int parse_expression (struct expression **, struct parse *, int *,
2205 enum expression_context,
2206 struct expression **, enum expr_op);
28868515
SK
2207int parse_option_data(struct expression **expr, struct parse *cfile,
2208 int lookups, struct option *option);
a34feb7d
TM
2209int parse_option_statement (struct executable_statement **,
2210 struct parse *, int,
2211 struct option *, enum statement_op);
2212int parse_option_token (struct expression **, struct parse *,
2213 const char **, struct expression *, int, int);
2214int parse_allow_deny (struct option_cache **, struct parse *, int);
2215int parse_auth_key (struct data_string *, struct parse *);
cfdfb9f1 2216int parse_warn (struct parse *, const char *, ...)
4bd8800e 2217 __attribute__((__format__(__printf__,2,3)));
98bd7ca0 2218struct expression *parse_domain_list(struct parse *cfile, int);
dba5803b 2219
d7837182
TL
2220
2221/* tree.c */
6ceb9118 2222extern struct binding_scope *global_scope;
a34feb7d
TM
2223pair cons (caddr_t, pair);
2224int make_const_option_cache (struct option_cache **, struct buffer **,
2225 u_int8_t *, unsigned, struct option *,
2226 const char *, int);
2227int make_host_lookup (struct expression **, const char *);
2228int enter_dns_host (struct dns_host_entry **, const char *);
d758ad8c
TL
2229int make_const_data (struct expression **,
2230 const unsigned char *, unsigned, int, int,
2231 const char *, int);
a34feb7d
TM
2232int make_const_int (struct expression **, unsigned long);
2233int make_concat (struct expression **,
2234 struct expression *, struct expression *);
2235int make_encapsulation (struct expression **, struct data_string *);
2236int make_substring (struct expression **, struct expression *,
2237 struct expression *, struct expression *);
2238int make_limit (struct expression **, struct expression *, int);
2239int make_let (struct executable_statement **, const char *);
2240int option_cache (struct option_cache **, struct data_string *,
2241 struct expression *, struct option *,
2242 const char *, int);
17a10efe 2243int evaluate_expression (struct binding_value **, struct packet *,
159bcce3
TL
2244 struct lease *, struct client_state *,
2245 struct option_state *, struct option_state *,
d758ad8c
TL
2246 struct binding_scope **, struct expression *,
2247 const char *, int);
17a10efe 2248int binding_value_dereference (struct binding_value **, const char *, int);
a34feb7d
TM
2249int evaluate_boolean_expression (int *,
2250 struct packet *, struct lease *,
2251 struct client_state *,
2252 struct option_state *,
2253 struct option_state *,
2254 struct binding_scope **,
2255 struct expression *);
2256int evaluate_data_expression (struct data_string *,
2257 struct packet *, struct lease *,
2258 struct client_state *,
2259 struct option_state *,
2260 struct option_state *,
2261 struct binding_scope **,
a7341359
SR
2262 struct expression *,
2263 const char *, int);
159bcce3
TL
2264int evaluate_numeric_expression (unsigned long *, struct packet *,
2265 struct lease *, struct client_state *,
2266 struct option_state *, struct option_state *,
2267 struct binding_scope **,
2268 struct expression *);
a34feb7d
TM
2269int evaluate_option_cache (struct data_string *,
2270 struct packet *, struct lease *,
2271 struct client_state *,
2272 struct option_state *, struct option_state *,
2273 struct binding_scope **,
2274 struct option_cache *,
2275 const char *, int);
2276int evaluate_boolean_option_cache (int *,
2277 struct packet *, struct lease *,
2278 struct client_state *,
2279 struct option_state *,
2280 struct option_state *,
2281 struct binding_scope **,
2282 struct option_cache *,
2283 const char *, int);
2284int evaluate_boolean_expression_result (int *,
2285 struct packet *, struct lease *,
2286 struct client_state *,
2287 struct option_state *,
2288 struct option_state *,
2289 struct binding_scope **,
2290 struct expression *);
2291void expression_dereference (struct expression **, const char *, int);
2292int is_dns_expression (struct expression *);
2293int is_boolean_expression (struct expression *);
2294int is_data_expression (struct expression *);
2295int is_numeric_expression (struct expression *);
2296int is_compound_expression (struct expression *);
2297int op_precedence (enum expr_op, enum expr_op);
cc4473a0 2298enum expression_context expression_context (struct expression *);
a34feb7d
TM
2299enum expression_context op_context (enum expr_op);
2300int write_expression (FILE *, struct expression *, int, int, int);
2301struct binding *find_binding (struct binding_scope *, const char *);
2302int free_bindings (struct binding_scope *, const char *, int);
2303int binding_scope_dereference (struct binding_scope **,
2304 const char *, int);
432604c3
TL
2305int fundef_dereference (struct fundef **, const char *, int);
2306int data_subexpression_length (int *, struct expression *);
2307int expr_valid_for_context (struct expression *, enum expression_context);
2f7ca092
TL
2308struct binding *create_binding (struct binding_scope **, const char *);
2309int bind_ds_value (struct binding_scope **,
2310 const char *, struct data_string *);
2311int find_bound_string (struct data_string *,
2312 struct binding_scope *, const char *);
2313int unset (struct binding_scope *, const char *);
98bd7ca0 2314int data_string_sprintfa(struct data_string *ds, const char *fmt, ...);
04daf4fe
TM
2315int concat_dclists (struct data_string *, struct data_string *,
2316 struct data_string *);
d7837182
TL
2317
2318/* dhcp.c */
e5078937 2319extern int outstanding_pings;
6368a1bd 2320extern int max_outstanding_acks;
f8cbf390
DH
2321extern int max_ack_delay_secs;
2322extern int max_ack_delay_usecs;
e5078937 2323
a34feb7d
TM
2324void dhcp (struct packet *);
2325void dhcpdiscover (struct packet *, int);
2326void dhcprequest (struct packet *, int, struct lease *);
2327void dhcprelease (struct packet *, int);
2328void dhcpdecline (struct packet *, int);
2329void dhcpinform (struct packet *, int);
e046c826 2330void nak_lease (struct packet *, struct iaddr *cip, struct group*);
a34feb7d
TM
2331void ack_lease (struct packet *, struct lease *,
2332 unsigned int, TIME, char *, int, struct host_decl *);
e046c826
TM
2333void echo_client_id(struct packet*, struct lease*, struct option_state*,
2334 struct option_state*);
e422b8c7 2335
a34feb7d
TM
2336void dhcp_reply (struct lease *);
2337int find_lease (struct lease **, struct packet *,
2338 struct shared_network *, int *, int *, struct lease *,
2339 const char *, int);
2340int mockup_lease (struct lease **, struct packet *,
2341 struct shared_network *,
2342 struct host_decl *);
2343void static_lease_dereference (struct lease *, const char *, int);
2344
2345int allocate_lease (struct lease **, struct packet *,
2346 struct pool *, int *);
2347int permitted (struct packet *, struct permit *);
2348int locate_network (struct packet *);
2349int parse_agent_information_option (struct packet *, int, u_int8_t *);
2350unsigned cons_agent_information_options (struct option_state *,
2351 struct dhcp_packet *,
2352 unsigned, unsigned);
6d103865
SK
2353void get_server_source_address(struct in_addr *from,
2354 struct option_state *options,
f8380d3f 2355 struct option_state *out_options,
6d103865 2356 struct packet *packet);
e046c826
TM
2357
2358void eval_network_statements(struct option_state **options,
2359 struct packet *packet,
2360 struct group *network_group);
734d2258 2361
37ec5845 2362/* dhcpleasequery.c */
a34feb7d
TM
2363void dhcpleasequery (struct packet *, int);
2364void dhcpv6_leasequery (struct data_string *, struct packet *);
37ec5845 2365
98bd7ca0
DH
2366/* dhcpv6.c */
2367isc_boolean_t server_duid_isset(void);
2368void copy_server_duid(struct data_string *ds, const char *file, int line);
2369void set_server_duid(struct data_string *new_duid);
2370isc_result_t set_server_duid_from_option(void);
6705543f 2371void set_server_duid_type(int type);
98bd7ca0 2372isc_result_t generate_new_server_duid(void);
37ec5845 2373isc_result_t get_client_id(struct packet *, struct data_string *);
98bd7ca0
DH
2374void dhcpv6(struct packet *);
2375
d7837182 2376/* bootp.c */
0a7e1a8a
TM
2377void bootp(struct packet *);
2378void use_host_decl_name(struct packet *, struct lease* , struct option_state *);
d7837182
TL
2379
2380/* memory.c */
06eb8bab 2381extern int (*group_write_hook) (struct group_object *);
20916cae 2382extern struct group *root_group;
98311e4b 2383extern group_hash_t *group_name_hash;
20916cae
TL
2384isc_result_t delete_group (struct group_object *, int);
2385isc_result_t supersede_group (struct group_object *, int);
2386int clone_group (struct group **, struct group *, const char *, int);
a34feb7d 2387int write_group (struct group_object *);
20916cae
TL
2388
2389/* salloc.c */
d758ad8c 2390void relinquish_lease_hunks (void);
a34feb7d 2391struct lease *new_leases (unsigned, const char *, int);
d758ad8c
TL
2392#if defined (DEBUG_MEMORY_LEAKAGE) || \
2393 defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
2394void relinquish_free_lease_states (void);
2395#endif
20916cae
TL
2396OMAPI_OBJECT_ALLOC_DECL (lease, struct lease, dhcp_type_lease)
2397OMAPI_OBJECT_ALLOC_DECL (class, struct class, dhcp_type_class)
899d754f 2398OMAPI_OBJECT_ALLOC_DECL (subclass, struct class, dhcp_type_subclass)
20916cae 2399OMAPI_OBJECT_ALLOC_DECL (pool, struct pool, dhcp_type_pool)
165bce70 2400OMAPI_OBJECT_ALLOC_DECL (host, struct host_decl, dhcp_type_host)
d7837182
TL
2401
2402/* alloc.c */
20916cae
TL
2403OMAPI_OBJECT_ALLOC_DECL (subnet, struct subnet, dhcp_type_subnet)
2404OMAPI_OBJECT_ALLOC_DECL (shared_network, struct shared_network,
2405 dhcp_type_shared_network)
2406OMAPI_OBJECT_ALLOC_DECL (group_object, struct group_object, dhcp_type_group)
d758ad8c
TL
2407OMAPI_OBJECT_ALLOC_DECL (dhcp_control,
2408 dhcp_control_object_t, dhcp_type_control)
2409
2410#if defined (DEBUG_MEMORY_LEAKAGE) || \
2411 defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
2412void relinquish_free_pairs (void);
2413void relinquish_free_expressions (void);
2414void relinquish_free_binding_values (void);
2415void relinquish_free_option_caches (void);
2416void relinquish_free_packets (void);
2417#endif
20916cae 2418
625f7cee
TL
2419int option_chain_head_allocate (struct option_chain_head **,
2420 const char *, int);
2421int option_chain_head_reference (struct option_chain_head **,
2422 struct option_chain_head *,
2423 const char *, int);
2424int option_chain_head_dereference (struct option_chain_head **,
2425 const char *, int);
20916cae
TL
2426int group_allocate (struct group **, const char *, int);
2427int group_reference (struct group **, struct group *, const char *, int);
2428int group_dereference (struct group **, const char *, int);
a34feb7d
TM
2429struct dhcp_packet *new_dhcp_packet (const char *, int);
2430struct protocol *new_protocol (const char *, int);
2431struct lease_state *new_lease_state (const char *, int);
2432struct domain_search_list *new_domain_search_list (const char *, int);
2433struct name_server *new_name_server (const char *, int);
2434void free_name_server (struct name_server *, const char *, int);
2435struct option *new_option (const char *, const char *, int);
f7fdb216
DH
2436int option_reference(struct option **dest, struct option *src,
2437 const char * file, int line);
2438int option_dereference(struct option **dest, const char *file, int line);
a34feb7d
TM
2439struct universe *new_universe (const char *, int);
2440void free_universe (struct universe *, const char *, int);
2441void free_domain_search_list (struct domain_search_list *,
2442 const char *, int);
2443void free_lease_state (struct lease_state *, const char *, int);
2444void free_protocol (struct protocol *, const char *, int);
2445void free_dhcp_packet (struct dhcp_packet *, const char *, int);
2446struct client_lease *new_client_lease (const char *, int);
2447void free_client_lease (struct client_lease *, const char *, int);
2448struct permit *new_permit (const char *, int);
2449void free_permit (struct permit *, const char *, int);
2450pair new_pair (const char *, int);
2451void free_pair (pair, const char *, int);
2452int expression_allocate (struct expression **, const char *, int);
2453int expression_reference (struct expression **,
2454 struct expression *, const char *, int);
2455void free_expression (struct expression *, const char *, int);
2456int binding_value_allocate (struct binding_value **,
2457 const char *, int);
2458int binding_value_reference (struct binding_value **,
2459 struct binding_value *,
2460 const char *, int);
2461void free_binding_value (struct binding_value *, const char *, int);
2462int fundef_allocate (struct fundef **, const char *, int);
2463int fundef_reference (struct fundef **,
2464 struct fundef *, const char *, int);
2465int option_cache_allocate (struct option_cache **, const char *, int);
2466int option_cache_reference (struct option_cache **,
2467 struct option_cache *, const char *, int);
2468int buffer_allocate (struct buffer **, unsigned, const char *, int);
2469int buffer_reference (struct buffer **, struct buffer *,
2470 const char *, int);
2471int buffer_dereference (struct buffer **, const char *, int);
2472int dns_host_entry_allocate (struct dns_host_entry **,
2473 const char *, const char *, int);
2474int dns_host_entry_reference (struct dns_host_entry **,
2475 struct dns_host_entry *,
2476 const char *, int);
2477int dns_host_entry_dereference (struct dns_host_entry **,
2478 const char *, int);
2479int option_state_allocate (struct option_state **, const char *, int);
2480int option_state_reference (struct option_state **,
2481 struct option_state *, const char *, int);
2482int option_state_dereference (struct option_state **,
2483 const char *, int);
d9b2a590
TM
2484int data_string_new(struct data_string *, const char *, unsigned int,
2485 const char *, int);
5279b8f3
DH
2486void data_string_copy(struct data_string *, const struct data_string *,
2487 const char *, int);
a34feb7d
TM
2488void data_string_forget (struct data_string *, const char *, int);
2489void data_string_truncate (struct data_string *, int);
2490int executable_statement_allocate (struct executable_statement **,
2491 const char *, int);
2492int executable_statement_reference (struct executable_statement **,
2493 struct executable_statement *,
2494 const char *, int);
2495int packet_allocate (struct packet **, const char *, int);
2496int packet_reference (struct packet **,
2497 struct packet *, const char *, int);
2498int packet_dereference (struct packet **, const char *, int);
2499int binding_scope_allocate (struct binding_scope **,
2500 const char *, int);
2501int binding_scope_reference (struct binding_scope **,
2502 struct binding_scope *,
2503 const char *, int);
2504int dns_zone_allocate (struct dns_zone **, const char *, int);
2505int dns_zone_reference (struct dns_zone **,
2506 struct dns_zone *, const char *, int);
d7837182
TL
2507
2508/* print.c */
5e864416
DH
2509#define DEFAULT_TIME_FORMAT 0
2510#define LOCAL_TIME_FORMAT 1
2511extern int db_time_format;
d73c2404
TL
2512char *quotify_string (const char *, const char *, int);
2513char *quotify_buf (const unsigned char *, unsigned, const char *, int);
d758ad8c 2514char *print_base64 (const unsigned char *, unsigned, const char *, int);
a34feb7d
TM
2515char *print_hw_addr (const int, const int, const unsigned char *);
2516void print_lease (struct lease *);
2517void dump_raw (const unsigned char *, unsigned);
b2398d97 2518void dump_packet_option (struct option_cache *, struct packet *,
159bcce3
TL
2519 struct lease *, struct client_state *,
2520 struct option_state *, struct option_state *,
2521 struct binding_scope **, struct universe *, void *);
a34feb7d
TM
2522void dump_packet (struct packet *);
2523void hash_dump (struct hash_table *);
2524char *print_hex (unsigned, const u_int8_t *, unsigned, unsigned);
2525void print_hex_only (unsigned, const u_int8_t *, unsigned, char *);
2526void print_hex_or_string (unsigned, const u_int8_t *, unsigned, char *);
6aaaf6a4
SR
2527#define print_hex_1(len, data, limit) print_hex(len, data, limit, 0)
2528#define print_hex_2(len, data, limit) print_hex(len, data, limit, 1)
2529#define print_hex_3(len, data, limit) print_hex(len, data, limit, 2)
a34feb7d
TM
2530char *print_dotted_quads (unsigned, const u_int8_t *);
2531char *print_dec_1 (unsigned long);
2532char *print_dec_2 (unsigned long);
2533void print_expression (const char *, struct expression *);
b1b7b521
TL
2534int token_print_indent_concat (FILE *, int, int,
2535 const char *, const char *, ...);
2536int token_indent_data_string (FILE *, int, int, const char *, const char *,
fa098be8 2537 struct data_string *);
b1b7b521
TL
2538int token_print_indent (FILE *, int, int,
2539 const char *, const char *, const char *);
fa098be8 2540void indent_spaces (FILE *, int);
69bb758c 2541#if defined (NSUPDATE)
590298e7 2542void print_dns_status (int, struct dhcp_ddns_cb *, isc_result_t);
98bf1607 2543#endif
5e864416 2544const char *print_time(TIME);
d7837182 2545
98bd7ca0
DH
2546void get_hw_addr(const char *name, struct hardware *hw);
2547
d7837182 2548/* socket.c */
c626ae69
TL
2549#if defined (USE_SOCKET_SEND) || defined (USE_SOCKET_RECEIVE) \
2550 || defined (USE_SOCKET_FALLBACK)
4b8251a0 2551int if_register_socket(struct interface_info *, int, int *, struct in6_addr *);
c2b5b5e8
TM
2552
2553void set_multicast_hop_limit(struct interface_info* info, int hop_limit);
17b95f41
TL
2554#endif
2555
5d4afdbc 2556#if defined (USE_SOCKET_FALLBACK) && !defined (USE_SOCKET_SEND)
a34feb7d
TM
2557void if_reinitialize_fallback (struct interface_info *);
2558void if_register_fallback (struct interface_info *);
2559ssize_t send_fallback (struct interface_info *,
2560 struct packet *, struct dhcp_packet *, size_t,
2561 struct in_addr,
2562 struct sockaddr_in *, struct hardware *);
2563ssize_t send_fallback6(struct interface_info *, struct packet *,
4b8251a0 2564 struct dhcp_packet *, size_t, struct in6_addr *,
98bd7ca0 2565 struct sockaddr_in6 *, struct hardware *);
c626ae69
TL
2566#endif
2567
6f10b1a4 2568#ifdef USE_SOCKET_SEND
a34feb7d
TM
2569void if_reinitialize_send (struct interface_info *);
2570void if_register_send (struct interface_info *);
2571void if_deregister_send (struct interface_info *);
2572ssize_t send_packet (struct interface_info *,
2573 struct packet *, struct dhcp_packet *, size_t,
2574 struct in_addr,
2575 struct sockaddr_in *, struct hardware *);
6f10b1a4 2576#endif
6705543f
DH
2577ssize_t send_packet6(struct interface_info *, const unsigned char *, size_t,
2578 struct sockaddr_in6 *);
6f10b1a4 2579#ifdef USE_SOCKET_RECEIVE
a34feb7d
TM
2580void if_reinitialize_receive (struct interface_info *);
2581void if_register_receive (struct interface_info *);
2582void if_deregister_receive (struct interface_info *);
2583ssize_t receive_packet (struct interface_info *,
2584 unsigned char *, size_t,
2585 struct sockaddr_in *, struct hardware *);
6f10b1a4 2586#endif
b5c11cbe 2587
5d4afdbc 2588#if defined (USE_SOCKET_FALLBACK)
a34feb7d 2589isc_result_t fallback_discard (omapi_object_t *);
b5c11cbe
TL
2590#endif
2591
5d4afdbc 2592#if defined (USE_SOCKET_SEND)
a34feb7d
TM
2593int can_unicast_without_arp (struct interface_info *);
2594int can_receive_unicast_unconfigured (struct interface_info *);
af380050 2595int supports_multiple_interfaces (struct interface_info *);
a34feb7d 2596void maybe_setup_fallback (void);
469cf3a4 2597#endif
6f10b1a4 2598
99fe695e 2599void if_register6(struct interface_info *info, int do_multicast);
4b8251a0 2600void if_register_linklocal6(struct interface_info *info);
99fe695e
SK
2601ssize_t receive_packet6(struct interface_info *interface,
2602 unsigned char *buf, size_t len,
ecddae64
DH
2603 struct sockaddr_in6 *from, struct in6_addr *to_addr,
2604 unsigned int *if_index);
99fe695e
SK
2605void if_deregister6(struct interface_info *info);
2606
2607
6f10b1a4 2608/* bpf.c */
17b95f41 2609#if defined (USE_BPF_SEND) || defined (USE_BPF_RECEIVE)
a34feb7d 2610int if_register_bpf (struct interface_info *);
17b95f41 2611#endif
6f10b1a4 2612#ifdef USE_BPF_SEND
a34feb7d
TM
2613void if_reinitialize_send (struct interface_info *);
2614void if_register_send (struct interface_info *);
2615void if_deregister_send (struct interface_info *);
2616ssize_t send_packet (struct interface_info *,
2617 struct packet *, struct dhcp_packet *, size_t,
2618 struct in_addr,
2619 struct sockaddr_in *, struct hardware *);
6f10b1a4
TL
2620#endif
2621#ifdef USE_BPF_RECEIVE
a34feb7d
TM
2622void if_reinitialize_receive (struct interface_info *);
2623void if_register_receive (struct interface_info *);
2624void if_deregister_receive (struct interface_info *);
2625ssize_t receive_packet (struct interface_info *,
2626 unsigned char *, size_t,
2627 struct sockaddr_in *, struct hardware *);
6f10b1a4 2628#endif
469cf3a4 2629#if defined (USE_BPF_SEND)
a34feb7d
TM
2630int can_unicast_without_arp (struct interface_info *);
2631int can_receive_unicast_unconfigured (struct interface_info *);
af380050 2632int supports_multiple_interfaces (struct interface_info *);
a34feb7d 2633void maybe_setup_fallback (void);
d1f2c520
TL
2634#endif
2635
2636/* lpf.c */
2637#if defined (USE_LPF_SEND) || defined (USE_LPF_RECEIVE)
a34feb7d 2638int if_register_lpf (struct interface_info *);
d1f2c520
TL
2639#endif
2640#ifdef USE_LPF_SEND
a34feb7d
TM
2641void if_reinitialize_send (struct interface_info *);
2642void if_register_send (struct interface_info *);
2643void if_deregister_send (struct interface_info *);
2644ssize_t send_packet (struct interface_info *,
2645 struct packet *, struct dhcp_packet *, size_t,
2646 struct in_addr,
2647 struct sockaddr_in *, struct hardware *);
d1f2c520
TL
2648#endif
2649#ifdef USE_LPF_RECEIVE
a34feb7d
TM
2650void if_reinitialize_receive (struct interface_info *);
2651void if_register_receive (struct interface_info *);
2652void if_deregister_receive (struct interface_info *);
2653ssize_t receive_packet (struct interface_info *,
2654 unsigned char *, size_t,
2655 struct sockaddr_in *, struct hardware *);
d1f2c520
TL
2656#endif
2657#if defined (USE_LPF_SEND)
a34feb7d
TM
2658int can_unicast_without_arp (struct interface_info *);
2659int can_receive_unicast_unconfigured (struct interface_info *);
af380050 2660int supports_multiple_interfaces (struct interface_info *);
a34feb7d 2661void maybe_setup_fallback (void);
469cf3a4 2662#endif
6f10b1a4
TL
2663
2664/* nit.c */
41fb155b 2665#if defined (USE_NIT_SEND) || defined (USE_NIT_RECEIVE)
a34feb7d 2666int if_register_nit (struct interface_info *);
41fb155b
TL
2667#endif
2668
6f10b1a4 2669#ifdef USE_NIT_SEND
a34feb7d
TM
2670void if_reinitialize_send (struct interface_info *);
2671void if_register_send (struct interface_info *);
2672void if_deregister_send (struct interface_info *);
2673ssize_t send_packet (struct interface_info *,
2674 struct packet *, struct dhcp_packet *, size_t,
2675 struct in_addr,
2676 struct sockaddr_in *, struct hardware *);
6f10b1a4
TL
2677#endif
2678#ifdef USE_NIT_RECEIVE
a34feb7d
TM
2679void if_reinitialize_receive (struct interface_info *);
2680void if_register_receive (struct interface_info *);
2681void if_deregister_receive (struct interface_info *);
2682ssize_t receive_packet (struct interface_info *,
2683 unsigned char *, size_t,
2684 struct sockaddr_in *, struct hardware *);
6f10b1a4 2685#endif
94f08824 2686#if defined (USE_NIT_SEND)
a34feb7d
TM
2687int can_unicast_without_arp (struct interface_info *);
2688int can_receive_unicast_unconfigured (struct interface_info *);
af380050 2689int supports_multiple_interfaces (struct interface_info *);
a34feb7d 2690void maybe_setup_fallback (void);
469cf3a4 2691#endif
6f10b1a4 2692
94f08824 2693/* dlpi.c */
5142937c 2694#if defined (USE_DLPI_SEND) || defined (USE_DLPI_RECEIVE)
a34feb7d 2695int if_register_dlpi (struct interface_info *);
5142937c
TL
2696#endif
2697
94f08824 2698#ifdef USE_DLPI_SEND
a34feb7d
TM
2699int can_unicast_without_arp (struct interface_info *);
2700int can_receive_unicast_unconfigured (struct interface_info *);
2701void if_reinitialize_send (struct interface_info *);
2702void if_register_send (struct interface_info *);
2703void if_deregister_send (struct interface_info *);
2704ssize_t send_packet (struct interface_info *,
2705 struct packet *, struct dhcp_packet *, size_t,
2706 struct in_addr,
2707 struct sockaddr_in *, struct hardware *);
109e00db 2708int supports_multiple_interfaces (struct interface_info *);
a34feb7d 2709void maybe_setup_fallback (void);
94f08824
TL
2710#endif
2711#ifdef USE_DLPI_RECEIVE
a34feb7d
TM
2712void if_reinitialize_receive (struct interface_info *);
2713void if_register_receive (struct interface_info *);
2714void if_deregister_receive (struct interface_info *);
2715ssize_t receive_packet (struct interface_info *,
2716 unsigned char *, size_t,
2717 struct sockaddr_in *, struct hardware *);
94f08824
TL
2718#endif
2719
2720
6f10b1a4
TL
2721/* raw.c */
2722#ifdef USE_RAW_SEND
a34feb7d
TM
2723void if_reinitialize_send (struct interface_info *);
2724void if_register_send (struct interface_info *);
2725void if_deregister_send (struct interface_info *);
2726ssize_t send_packet (struct interface_info *, struct packet *,
2727 struct dhcp_packet *, size_t, struct in_addr,
2728 struct sockaddr_in *, struct hardware *);
2729int can_unicast_without_arp (struct interface_info *);
2730int can_receive_unicast_unconfigured (struct interface_info *);
af380050 2731int supports_multiple_interfaces (struct interface_info *);
a34feb7d 2732void maybe_setup_fallback (void);
6f10b1a4
TL
2733#endif
2734
f3aad410 2735/* discover.c */
d1f2c520 2736extern struct interface_info *interfaces,
339b0231 2737 *dummy_interfaces, *fallback_interface;
6e5ed8bf 2738extern struct protocol *protocols;
d032a71e 2739extern int quiet_interface_discovery;
8bed305d 2740isc_result_t interface_setup (void);
f3aad410 2741void interface_trace_setup (void);
aa8579c0
TL
2742
2743extern struct in_addr limited_broadcast;
98bd7ca0 2744extern int local_family;
aa8579c0
TL
2745extern struct in_addr local_address;
2746
2747extern u_int16_t local_port;
2748extern u_int16_t remote_port;
20916cae
TL
2749extern int (*dhcp_interface_setup_hook) (struct interface_info *,
2750 struct iaddr *);
2751extern int (*dhcp_interface_discovery_hook) (struct interface_info *);
06eb8bab 2752extern isc_result_t (*dhcp_interface_startup_hook) (struct interface_info *);
aa8579c0 2753
a34feb7d
TM
2754extern void (*bootp_packet_handler) (struct interface_info *,
2755 struct dhcp_packet *, unsigned,
2756 unsigned int,
2757 struct iaddr, struct hardware *);
98bd7ca0
DH
2758extern void (*dhcpv6_packet_handler)(struct interface_info *,
2759 const char *, int,
2760 int, const struct iaddr *, isc_boolean_t);
cc26de46 2761extern struct timeout *timeouts;
4fe74d72 2762extern omapi_object_type_t *dhcp_type_interface;
f3aad410 2763#if defined (TRACING)
06eb8bab
SK
2764extern trace_type_t *interface_trace;
2765extern trace_type_t *inpacket_trace;
2766extern trace_type_t *outpacket_trace;
f3aad410
TL
2767#endif
2768extern struct interface_info **interface_vector;
2769extern int interface_count;
2770extern int interface_max;
98bd7ca0
DH
2771isc_result_t interface_initialize(omapi_object_t *, const char *, int);
2772void discover_interfaces(int);
20916cae 2773int setup_fallback (struct interface_info **, const char *, int);
a34feb7d
TM
2774int if_readsocket (omapi_object_t *);
2775void reinitialize_interfaces (void);
f3aad410
TL
2776
2777/* dispatch.c */
88cd8aca 2778void set_time(TIME);
f3aad410 2779struct timeval *process_outstanding_timeouts (struct timeval *);
a34feb7d 2780void dispatch (void);
98bd7ca0
DH
2781isc_result_t got_one(omapi_object_t *);
2782isc_result_t got_one_v6(omapi_object_t *);
4fe74d72
TL
2783isc_result_t interface_set_value (omapi_object_t *, omapi_object_t *,
2784 omapi_data_string_t *, omapi_typed_data_t *);
2785isc_result_t interface_get_value (omapi_object_t *, omapi_object_t *,
a34feb7d 2786 omapi_data_string_t *, omapi_value_t **);
4bd8800e 2787isc_result_t interface_destroy (omapi_object_t *, const char *, int);
b1b7b521
TL
2788isc_result_t interface_signal_handler (omapi_object_t *,
2789 const char *, va_list);
4fe74d72
TL
2790isc_result_t interface_stuff_values (omapi_object_t *,
2791 omapi_object_t *,
2792 omapi_object_t *);
2793
a34feb7d
TM
2794void add_timeout (struct timeval *, void (*) (void *), void *,
2795 tvref_t, tvunref_t);
2796void cancel_timeout (void (*) (void *), void *);
d758ad8c
TL
2797void cancel_all_timeouts (void);
2798void relinquish_timeouts (void);
d7837182 2799
20916cae 2800OMAPI_OBJECT_ALLOC_DECL (interface,
165bce70 2801 struct interface_info, dhcp_type_interface)
5a526cf8 2802
d7837182 2803/* tables.c */
f7fdb216 2804extern char *default_option_format;
102ee7e9 2805extern struct universe dhcp_universe;
98bd7ca0 2806extern struct universe dhcpv6_universe;
432604c3 2807extern struct universe nwip_universe;
432604c3 2808extern struct universe fqdn_universe;
98bd7ca0 2809extern struct universe vsio_universe;
27fe61a7
TL
2810extern int dhcp_option_default_priority_list [];
2811extern int dhcp_option_default_priority_list_count;
b1b7b521 2812extern const char *hardware_types [256];
06eb8bab
SK
2813extern int universe_count, universe_max;
2814extern struct universe **universes;
98311e4b 2815extern universe_hash_t *universe_hash;
a34feb7d 2816void initialize_common_option_spaces (void);
06eb8bab 2817extern struct universe *config_universe;
516cf43a
TL
2818
2819/* stables.c */
d9eefc5d 2820#if defined (FAILOVER_PROTOCOL)
76d5bd36
TL
2821extern failover_option_t null_failover_option;
2822extern failover_option_t skip_failover_option;
2823extern struct failover_option_info ft_options [];
2824extern u_int32_t fto_allowed [];
2825extern int ft_sizes [];
2826extern const char *dhcp_flink_state_names [];
d9eefc5d 2827#endif
007e3ee4
TL
2828extern const char *binding_state_names [];
2829
516cf43a 2830extern struct universe agent_universe;
516cf43a 2831extern struct universe server_universe;
dbcc689e
TL
2832
2833extern struct enumeration ddns_styles;
625f7cee 2834extern struct enumeration syslog_enum;
a34feb7d 2835void initialize_server_option_spaces (void);
d7837182 2836
1a006ff6
TM
2837extern struct enumeration prefix_length_modes;
2838
089fb364 2839/* inet.c */
a34feb7d
TM
2840struct iaddr subnet_number (struct iaddr, struct iaddr);
2841struct iaddr ip_addr (struct iaddr, struct iaddr, u_int32_t);
2842struct iaddr broadcast_addr (struct iaddr, struct iaddr);
2843u_int32_t host_addr (struct iaddr, struct iaddr);
2844int addr_eq (struct iaddr, struct iaddr);
febbd402 2845int addr_match(struct iaddr *, struct iaddrmatch *);
98bd7ca0 2846int addr_cmp(const struct iaddr *a1, const struct iaddr *a2);
a34feb7d 2847int addr_or(struct iaddr *result,
98bd7ca0 2848 const struct iaddr *a1, const struct iaddr *a2);
a34feb7d 2849int addr_and(struct iaddr *result,
98bd7ca0 2850 const struct iaddr *a1, const struct iaddr *a2);
9b21e73e 2851isc_boolean_t is_cidr_mask_valid(const struct iaddr *addr, int bits);
98bd7ca0
DH
2852isc_result_t range2cidr(struct iaddrcidrnetlist **result,
2853 const struct iaddr *lo, const struct iaddr *hi);
2854isc_result_t free_iaddrcidrnetlist(struct iaddrcidrnetlist **result);
a34feb7d 2855const char *piaddr (struct iaddr);
98bd7ca0
DH
2856char *piaddrmask(struct iaddr *, struct iaddr *);
2857char *piaddrcidr(const struct iaddr *, unsigned int);
59112e84 2858u_int16_t validate_port(char *);
95821729
TL
2859
2860/* dhclient.c */
8ea19a71
DH
2861extern int nowait;
2862
420d8b3f
FD
2863extern int wanted_ia_na;
2864extern int wanted_ia_ta;
2865extern int wanted_ia_pd;
2866
b1b7b521
TL
2867extern const char *path_dhclient_conf;
2868extern const char *path_dhclient_db;
2869extern const char *path_dhclient_pid;
e47988bf 2870extern char *path_dhclient_script;
5a526cf8 2871extern int interfaces_requested;
98bd7ca0 2872extern struct data_string default_duid;
a41d7a25 2873extern int duid_type;
79818c93 2874extern const char *path_dhclient_duid;
cc26de46
TL
2875
2876extern struct client_config top_level_config;
2877
a34feb7d
TM
2878void dhcpoffer (struct packet *);
2879void dhcpack (struct packet *);
2880void dhcpnak (struct packet *);
2881
2882void send_discover (void *);
2883void send_request (void *);
2884void send_release (void *);
2885void send_decline (void *);
2886
2887void state_reboot (void *);
2888void state_init (void *);
2889void state_selecting (void *);
2890void state_requesting (void *);
2891void state_bound (void *);
2892void state_stop (void *);
2893void state_panic (void *);
2894
2895void bind_lease (struct client_state *);
2896
2897void make_client_options (struct client_state *,
2898 struct client_lease *, u_int8_t *,
2899 struct option_cache *, struct iaddr *,
2900 struct option **, struct option_state **);
2901void make_discover (struct client_state *, struct client_lease *);
2902void make_request (struct client_state *, struct client_lease *);
2903void make_decline (struct client_state *, struct client_lease *);
2904void make_release (struct client_state *, struct client_lease *);
2905
2906void destroy_client_lease (struct client_lease *);
2907void rewrite_client_leases (void);
432604c3 2908void write_lease_option (struct option_cache *, struct packet *,
159bcce3
TL
2909 struct lease *, struct client_state *,
2910 struct option_state *, struct option_state *,
2911 struct binding_scope **, struct universe *, void *);
a34feb7d 2912int write_client_lease (struct client_state *, struct client_lease *, int, int);
98bd7ca0
DH
2913isc_result_t write_client6_lease(struct client_state *client,
2914 struct dhc6_lease *lease,
2915 int rewrite, int sync);
32a47563 2916int dhcp_option_ev_name (char *, size_t, struct option *);
cc26de46 2917
a34feb7d
TM
2918void script_init (struct client_state *, const char *,
2919 struct string_list *);
432604c3 2920void client_option_envadd (struct option_cache *, struct packet *,
159bcce3
TL
2921 struct lease *, struct client_state *,
2922 struct option_state *, struct option_state *,
2923 struct binding_scope **, struct universe *, void *);
a34feb7d
TM
2924void script_write_params (struct client_state *, const char *,
2925 struct client_lease *);
10613724 2926void script_write_requested (struct client_state *);
a34feb7d 2927int script_go (struct client_state *);
32a47563
TL
2928void client_envadd (struct client_state *,
2929 const char *, const char *, const char *, ...)
2930 __attribute__((__format__(__printf__,4,5)));
cc26de46 2931
6ceb9118 2932struct client_lease *packet_to_lease (struct packet *, struct client_state *);
a34feb7d
TM
2933void go_daemon (void);
2934void write_client_pid_file (void);
2935void client_location_changed (void);
2936void do_release (struct client_state *);
20916cae
TL
2937int dhclient_interface_shutdown_hook (struct interface_info *);
2938int dhclient_interface_discovery_hook (struct interface_info *);
c1f22aef 2939isc_result_t dhclient_interface_startup_hook (struct interface_info *);
98bd7ca0
DH
2940void dhclient_schedule_updates(struct client_state *client,
2941 struct iaddr *addr, int offset);
98311e4b 2942void client_dns_update_timeout (void *cp);
98bf1607
SR
2943isc_result_t client_dns_update(struct client_state *client,
2944 dhcp_ddns_cb_t *ddns_cb);
2945void client_dns_remove(struct client_state *client, struct iaddr *addr);
98bd7ca0
DH
2946
2947void dhcpv4_client_assignments(void);
2948void dhcpv6_client_assignments(void);
d7d9c0c7 2949void form_duid(struct data_string *duid, const char *file, int line);
98bd7ca0
DH
2950
2951/* dhc6.c */
e32529a5 2952void dhc6_lease_destroy(struct dhc6_lease **src, const char *file, int line);
98bd7ca0 2953void start_init6(struct client_state *client);
3dbe2246 2954void start_info_request6(struct client_state *client);
98bd7ca0 2955void start_confirm6(struct client_state *client);
af5fa176 2956void start_release6(struct client_state *client);
98bd7ca0 2957void start_selecting6(struct client_state *client);
af5fa176 2958void unconfigure6(struct client_state *client, const char *reason);
95821729 2959
1358b874 2960/* db.c */
a34feb7d
TM
2961int write_lease (struct lease *);
2962int write_host (struct host_decl *);
6705543f 2963int write_server_duid(void);
a7982987
TL
2964#if defined (FAILOVER_PROTOCOL)
2965int write_failover_state (dhcp_failover_state_t *);
2966#endif
a34feb7d
TM
2967int db_printable (const unsigned char *);
2968int db_printable_len (const unsigned char *, unsigned);
f7fdb216 2969isc_result_t write_named_billing_class(const void *, unsigned, void *);
875d2b66 2970void write_billing_classes (void);
a34feb7d
TM
2971int write_billing_class (struct class *);
2972void commit_leases_timeout (void *);
a34feb7d 2973int commit_leases (void);
cbbd2714 2974int commit_leases_timed (void);
a34feb7d
TM
2975void db_startup (int);
2976int new_lease_file (void);
20916cae 2977int group_writer (struct group_object *);
9322442f 2978int write_ia(const struct ia_xx *);
17b95f41
TL
2979
2980/* packet.c */
a34feb7d
TM
2981u_int32_t checksum (unsigned char *, unsigned, u_int32_t);
2982u_int32_t wrapsum (u_int32_t);
2983void assemble_hw_header (struct interface_info *, unsigned char *,
2984 unsigned *, struct hardware *);
2985void assemble_udp_ip_header (struct interface_info *, unsigned char *,
2986 unsigned *, u_int32_t, u_int32_t,
2987 u_int32_t, unsigned char *, unsigned);
2988ssize_t decode_hw_header (struct interface_info *, unsigned char *,
2989 unsigned, struct hardware *);
2990ssize_t decode_udp_ip_header (struct interface_info *, unsigned char *,
2991 unsigned, struct sockaddr_in *,
7ff6ae5a 2992 unsigned, unsigned *, int);
ab370123 2993
7d29d66d 2994/* ethernet.c */
a34feb7d
TM
2995void assemble_ethernet_header (struct interface_info *, unsigned char *,
2996 unsigned *, struct hardware *);
2997ssize_t decode_ethernet_header (struct interface_info *,
2998 unsigned char *,
2999 unsigned, struct hardware *);
7d29d66d
TL
3000
3001/* tr.c */
a34feb7d
TM
3002void assemble_tr_header (struct interface_info *, unsigned char *,
3003 unsigned *, struct hardware *);
3004ssize_t decode_tr_header (struct interface_info *,
3005 unsigned char *,
3006 unsigned, struct hardware *);
7d29d66d 3007
ab370123 3008/* dhxpxlt.c */
a34feb7d
TM
3009void convert_statement (struct parse *);
3010void convert_host_statement (struct parse *, jrefproto);
3011void convert_host_name (struct parse *, jrefproto);
3012void convert_class_statement (struct parse *, jrefproto, int);
3013void convert_class_decl (struct parse *, jrefproto);
3014void convert_lease_time (struct parse *, jrefproto, char *);
3015void convert_shared_net_statement (struct parse *, jrefproto);
3016void convert_subnet_statement (struct parse *, jrefproto);
3017void convert_subnet_decl (struct parse *, jrefproto);
3018void convert_host_decl (struct parse *, jrefproto);
3019void convert_hardware_decl (struct parse *, jrefproto);
3020void convert_hardware_addr (struct parse *, jrefproto);
3021void convert_filename_decl (struct parse *, jrefproto);
3022void convert_servername_decl (struct parse *, jrefproto);
3023void convert_ip_addr_or_hostname (struct parse *, jrefproto, int);
3024void convert_fixed_addr_decl (struct parse *, jrefproto);
3025void convert_option_decl (struct parse *, jrefproto);
3026void convert_lease_statement (struct parse *, jrefproto);
3027void convert_address_range (struct parse *, jrefproto);
3028void convert_date (struct parse *, jrefproto, char *);
3029void convert_numeric_aggregate (struct parse *, jrefproto, int, int, int, int);
3030void indent (int);
469cf3a4
TL
3031
3032/* route.c */
a34feb7d
TM
3033void add_route_direct (struct interface_info *, struct in_addr);
3034void add_route_net (struct interface_info *, struct in_addr, struct in_addr);
3035void add_route_default_gateway (struct interface_info *, struct in_addr);
3036void remove_routes (struct in_addr);
3037void remove_if_route (struct interface_info *, struct in_addr);
3038void remove_all_if_routes (struct interface_info *);
3039void set_netmask (struct interface_info *, struct in_addr);
3040void set_broadcast_addr (struct interface_info *, struct in_addr);
3041void set_ip_address (struct interface_info *, struct in_addr);
cc26de46
TL
3042
3043/* clparse.c */
a34feb7d 3044isc_result_t read_client_conf (void);
d758ad8c
TL
3045int read_client_conf_file (const char *,
3046 struct interface_info *, struct client_config *);
a34feb7d 3047void read_client_leases (void);
79818c93 3048void read_client_duid (void);
a34feb7d
TM
3049void parse_client_statement (struct parse *, struct interface_info *,
3050 struct client_config *);
3051int parse_X (struct parse *, u_int8_t *, unsigned);
3052int parse_option_list (struct parse *, struct option ***);
3053void parse_interface_declaration (struct parse *,
3054 struct client_config *, char *);
3055int interface_or_dummy (struct interface_info **, const char *);
3056void make_client_state (struct client_state **);
3057void make_client_config (struct client_state *, struct client_config *);
3058void parse_client_lease_statement (struct parse *, int);
3059void parse_client_lease_declaration (struct parse *,
3060 struct client_lease *,
3061 struct interface_info **,
3062 struct client_state **);
3063int parse_option_decl (struct option_cache **, struct parse *);
3064void parse_string_list (struct parse *, struct string_list **, int);
3065int parse_ip_addr (struct parse *, struct iaddr *);
d19e2cf7 3066int parse_ip_addr_with_subnet(struct parse *, struct iaddrmatch *);
a34feb7d 3067void parse_reject_statement (struct parse *, struct client_config *);
6b3b97e1 3068
6e5ed8bf 3069/* icmp.c */
d758ad8c
TL
3070OMAPI_OBJECT_ALLOC_DECL (icmp_state, struct icmp_state, dhcp_type_icmp)
3071extern struct icmp_state *icmp_state;
a34feb7d
TM
3072void icmp_startup (int, void (*) (struct iaddr, u_int8_t *, int));
3073int icmp_readsocket (omapi_object_t *);
3074int icmp_echorequest (struct iaddr *);
3075isc_result_t icmp_echoreply (omapi_object_t *);
83c1b012
TL
3076
3077/* dns.c */
3f09cb5a
TL
3078isc_result_t enter_dns_zone (struct dns_zone *);
3079isc_result_t dns_zone_lookup (struct dns_zone **, const char *);
a34feb7d 3080int dns_zone_dereference (struct dns_zone **, const char *, int);
29a026db 3081#if defined (NSUPDATE)
98bf1607
SR
3082#define FIND_FORWARD 0
3083#define FIND_REVERSE 1
d7d9c0c7
SR
3084isc_result_t find_tsig_key (ns_tsig_key **, const char *, struct dns_zone *);
3085void tkey_free (ns_tsig_key **);
98bf1607 3086isc_result_t find_cached_zone (dhcp_ddns_cb_t *, int);
aa8579c0
TL
3087void forget_zone (struct dns_zone **);
3088void repudiate_zone (struct dns_zone **);
d7d9c0c7 3089int get_dhcid (dhcp_ddns_cb_t *, int, const u_int8_t *, unsigned);
98bf1607
SR
3090void dhcid_tolease (struct data_string *, struct data_string *);
3091isc_result_t dhcid_fromlease (struct data_string *, struct data_string *);
98bd7ca0
DH
3092isc_result_t ddns_update_fwd(struct data_string *, struct iaddr,
3093 struct data_string *, unsigned long, unsigned,
3094 unsigned);
a34feb7d 3095isc_result_t ddns_remove_fwd(struct data_string *,
98bd7ca0 3096 struct iaddr, struct data_string *);
29a026db 3097#endif /* NSUPDATE */
0c7802b1 3098
d7d9c0c7
SR
3099dhcp_ddns_cb_t *ddns_cb_alloc(const char *file, int line);
3100void ddns_cb_free (dhcp_ddns_cb_t *ddns_cb, const char *file, int line);
3101void ddns_cb_forget_zone (dhcp_ddns_cb_t *ddns_cb);
3102isc_result_t
3103ddns_modify_fwd(dhcp_ddns_cb_t *ddns_cb, const char *file, int line);
3104isc_result_t
3105ddns_modify_ptr(dhcp_ddns_cb_t *ddns_cb, const char *file, int line);
3106void
3107ddns_cancel(dhcp_ddns_cb_t *ddns_cb, const char *file, int line);
3108
0c7802b1
TL
3109/* resolv.c */
3110extern char path_resolv_conf [];
06eb8bab
SK
3111extern struct name_server *name_servers;
3112extern struct domain_search_list *domains;
0c7802b1 3113
a34feb7d
TM
3114void read_resolv_conf (TIME);
3115struct name_server *first_name_server (void);
2b60cc68
TL
3116
3117/* inet_addr.c */
3118#ifdef NEED_INET_ATON
a34feb7d 3119int inet_aton (const char *, struct in_addr *);
2b60cc68 3120#endif
5a526cf8 3121
102ee7e9 3122/* class.c */
112a6c2c 3123extern int have_billing_classes;
102ee7e9
TL
3124struct class unknown_class;
3125struct class known_class;
3126struct collection default_collection;
8bdd4d02 3127struct collection *collections;
06eb8bab 3128extern struct executable_statement *default_classification_rules;
102ee7e9 3129
a34feb7d
TM
3130void classification_setup (void);
3131void classify_client (struct packet *);
3132int check_collection (struct packet *, struct lease *, struct collection *);
3133void classify (struct packet *, struct class *);
3134isc_result_t unlink_class (struct class **class);
3135isc_result_t find_class (struct class **, const char *,
3136 const char *, int);
6a39bcf0 3137void unbill_class (struct lease *);
a34feb7d 3138int bill_class (struct lease *, struct class *);
2b9b6ff7
TL
3139
3140/* execute.c */
a34feb7d
TM
3141int execute_statements (struct binding_value **result,
3142 struct packet *, struct lease *,
3143 struct client_state *,
3144 struct option_state *, struct option_state *,
3145 struct binding_scope **,
a7341359
SR
3146 struct executable_statement *,
3147 struct on_star *);
a34feb7d
TM
3148void execute_statements_in_scope (struct binding_value **result,
3149 struct packet *, struct lease *,
3150 struct client_state *,
3151 struct option_state *,
3152 struct option_state *,
3153 struct binding_scope **,
a7341359
SR
3154 struct group *, struct group *,
3155 struct on_star *);
a34feb7d
TM
3156int executable_statement_dereference (struct executable_statement **,
3157 const char *, int);
7f6ad5ac 3158void write_statements (FILE *, struct executable_statement *, int);
932d739c 3159int find_matching_case (struct executable_statement **,
159bcce3 3160 struct packet *, struct lease *, struct client_state *,
932d739c 3161 struct option_state *, struct option_state *,
6ceb9118 3162 struct binding_scope **,
932d739c 3163 struct expression *, struct executable_statement *);
d758ad8c
TL
3164int executable_statement_foreach (struct executable_statement *,
3165 int (*) (struct executable_statement *,
3166 void *, int), void *, int);
74f45f96 3167
20916cae 3168/* comapi.c */
4fe74d72 3169extern omapi_object_type_t *dhcp_type_group;
4fe74d72
TL
3170extern omapi_object_type_t *dhcp_type_shared_network;
3171extern omapi_object_type_t *dhcp_type_subnet;
d758ad8c
TL
3172extern omapi_object_type_t *dhcp_type_control;
3173extern dhcp_control_object_t *dhcp_control_object;
20916cae
TL
3174
3175void dhcp_common_objects_setup (void);
3176
3177isc_result_t dhcp_group_set_value (omapi_object_t *, omapi_object_t *,
3178 omapi_data_string_t *,
3179 omapi_typed_data_t *);
3180isc_result_t dhcp_group_get_value (omapi_object_t *, omapi_object_t *,
3181 omapi_data_string_t *,
a34feb7d 3182 omapi_value_t **);
20916cae
TL
3183isc_result_t dhcp_group_destroy (omapi_object_t *, const char *, int);
3184isc_result_t dhcp_group_signal_handler (omapi_object_t *,
3185 const char *, va_list);
3186isc_result_t dhcp_group_stuff_values (omapi_object_t *,
3187 omapi_object_t *,
3188 omapi_object_t *);
3189isc_result_t dhcp_group_lookup (omapi_object_t **,
3190 omapi_object_t *, omapi_object_t *);
3191isc_result_t dhcp_group_create (omapi_object_t **,
3192 omapi_object_t *);
3193isc_result_t dhcp_group_remove (omapi_object_t *,
3194 omapi_object_t *);
3195
d758ad8c
TL
3196isc_result_t dhcp_control_set_value (omapi_object_t *, omapi_object_t *,
3197 omapi_data_string_t *,
3198 omapi_typed_data_t *);
3199isc_result_t dhcp_control_get_value (omapi_object_t *, omapi_object_t *,
3200 omapi_data_string_t *,
a34feb7d 3201 omapi_value_t **);
d758ad8c
TL
3202isc_result_t dhcp_control_destroy (omapi_object_t *, const char *, int);
3203isc_result_t dhcp_control_signal_handler (omapi_object_t *,
3204 const char *, va_list);
3205isc_result_t dhcp_control_stuff_values (omapi_object_t *,
3206 omapi_object_t *,
3207 omapi_object_t *);
3208isc_result_t dhcp_control_lookup (omapi_object_t **,
3209 omapi_object_t *, omapi_object_t *);
3210isc_result_t dhcp_control_create (omapi_object_t **,
3211 omapi_object_t *);
3212isc_result_t dhcp_control_remove (omapi_object_t *,
3213 omapi_object_t *);
3214
20916cae
TL
3215isc_result_t dhcp_subnet_set_value (omapi_object_t *, omapi_object_t *,
3216 omapi_data_string_t *,
3217 omapi_typed_data_t *);
3218isc_result_t dhcp_subnet_get_value (omapi_object_t *, omapi_object_t *,
3219 omapi_data_string_t *,
a34feb7d 3220 omapi_value_t **);
20916cae
TL
3221isc_result_t dhcp_subnet_destroy (omapi_object_t *, const char *, int);
3222isc_result_t dhcp_subnet_signal_handler (omapi_object_t *,
3223 const char *, va_list);
3224isc_result_t dhcp_subnet_stuff_values (omapi_object_t *,
3225 omapi_object_t *,
3226 omapi_object_t *);
3227isc_result_t dhcp_subnet_lookup (omapi_object_t **,
3228 omapi_object_t *, omapi_object_t *);
3229isc_result_t dhcp_subnet_create (omapi_object_t **,
3230 omapi_object_t *);
3231isc_result_t dhcp_subnet_remove (omapi_object_t *,
3232 omapi_object_t *);
3233
3234isc_result_t dhcp_shared_network_set_value (omapi_object_t *,
3235 omapi_object_t *,
3236 omapi_data_string_t *,
3237 omapi_typed_data_t *);
3238isc_result_t dhcp_shared_network_get_value (omapi_object_t *,
3239 omapi_object_t *,
3240 omapi_data_string_t *,
a34feb7d 3241 omapi_value_t **);
20916cae
TL
3242isc_result_t dhcp_shared_network_destroy (omapi_object_t *, const char *, int);
3243isc_result_t dhcp_shared_network_signal_handler (omapi_object_t *,
3244 const char *, va_list);
3245isc_result_t dhcp_shared_network_stuff_values (omapi_object_t *,
3246 omapi_object_t *,
3247 omapi_object_t *);
3248isc_result_t dhcp_shared_network_lookup (omapi_object_t **,
3249 omapi_object_t *, omapi_object_t *);
3250isc_result_t dhcp_shared_network_create (omapi_object_t **,
3251 omapi_object_t *);
3252isc_result_t dhcp_shared_network_remove (omapi_object_t *,
3253 omapi_object_t *);
3254
3255/* omapi.c */
3256extern int (*dhcp_interface_shutdown_hook) (struct interface_info *);
3257
3258extern omapi_object_type_t *dhcp_type_lease;
3259extern omapi_object_type_t *dhcp_type_pool;
4fe74d72 3260extern omapi_object_type_t *dhcp_type_class;
899d754f 3261extern omapi_object_type_t *dhcp_type_subclass;
bdcaf7b9 3262
d9eefc5d
TL
3263#if defined (FAILOVER_PROTOCOL)
3264extern omapi_object_type_t *dhcp_type_failover_state;
3265extern omapi_object_type_t *dhcp_type_failover_link;
3266extern omapi_object_type_t *dhcp_type_failover_listener;
3267#endif
4fe74d72
TL
3268
3269void dhcp_db_objects_setup (void);
3270
3271isc_result_t dhcp_lease_set_value (omapi_object_t *, omapi_object_t *,
3272 omapi_data_string_t *,
3273 omapi_typed_data_t *);
3274isc_result_t dhcp_lease_get_value (omapi_object_t *, omapi_object_t *,
3275 omapi_data_string_t *,
a34feb7d 3276 omapi_value_t **);
4bd8800e 3277isc_result_t dhcp_lease_destroy (omapi_object_t *, const char *, int);
b1b7b521
TL
3278isc_result_t dhcp_lease_signal_handler (omapi_object_t *,
3279 const char *, va_list);
4fe74d72
TL
3280isc_result_t dhcp_lease_stuff_values (omapi_object_t *,
3281 omapi_object_t *,
3282 omapi_object_t *);
3283isc_result_t dhcp_lease_lookup (omapi_object_t **,
3284 omapi_object_t *, omapi_object_t *);
3285isc_result_t dhcp_lease_create (omapi_object_t **,
3286 omapi_object_t *);
ccce1cc6 3287isc_result_t dhcp_lease_remove (omapi_object_t *,
3c48d369 3288 omapi_object_t *);
4fe74d72
TL
3289isc_result_t dhcp_host_set_value (omapi_object_t *, omapi_object_t *,
3290 omapi_data_string_t *,
3291 omapi_typed_data_t *);
3292isc_result_t dhcp_host_get_value (omapi_object_t *, omapi_object_t *,
3293 omapi_data_string_t *,
a34feb7d 3294 omapi_value_t **);
4bd8800e 3295isc_result_t dhcp_host_destroy (omapi_object_t *, const char *, int);
b1b7b521
TL
3296isc_result_t dhcp_host_signal_handler (omapi_object_t *,
3297 const char *, va_list);
4fe74d72
TL
3298isc_result_t dhcp_host_stuff_values (omapi_object_t *,
3299 omapi_object_t *,
3300 omapi_object_t *);
3301isc_result_t dhcp_host_lookup (omapi_object_t **,
3302 omapi_object_t *, omapi_object_t *);
3303isc_result_t dhcp_host_create (omapi_object_t **,
3304 omapi_object_t *);
ccce1cc6 3305isc_result_t dhcp_host_remove (omapi_object_t *,
3c48d369 3306 omapi_object_t *);
4fe74d72
TL
3307isc_result_t dhcp_pool_set_value (omapi_object_t *, omapi_object_t *,
3308 omapi_data_string_t *,
3309 omapi_typed_data_t *);
3310isc_result_t dhcp_pool_get_value (omapi_object_t *, omapi_object_t *,
3311 omapi_data_string_t *,
a34feb7d 3312 omapi_value_t **);
4bd8800e 3313isc_result_t dhcp_pool_destroy (omapi_object_t *, const char *, int);
b1b7b521
TL
3314isc_result_t dhcp_pool_signal_handler (omapi_object_t *,
3315 const char *, va_list);
4fe74d72
TL
3316isc_result_t dhcp_pool_stuff_values (omapi_object_t *,
3317 omapi_object_t *,
3318 omapi_object_t *);
3319isc_result_t dhcp_pool_lookup (omapi_object_t **,
3320 omapi_object_t *, omapi_object_t *);
3321isc_result_t dhcp_pool_create (omapi_object_t **,
3322 omapi_object_t *);
ccce1cc6 3323isc_result_t dhcp_pool_remove (omapi_object_t *,
3c48d369 3324 omapi_object_t *);
20916cae
TL
3325isc_result_t dhcp_class_set_value (omapi_object_t *, omapi_object_t *,
3326 omapi_data_string_t *,
3327 omapi_typed_data_t *);
3328isc_result_t dhcp_class_get_value (omapi_object_t *, omapi_object_t *,
3329 omapi_data_string_t *,
a34feb7d 3330 omapi_value_t **);
20916cae
TL
3331isc_result_t dhcp_class_destroy (omapi_object_t *, const char *, int);
3332isc_result_t dhcp_class_signal_handler (omapi_object_t *,
3333 const char *, va_list);
3334isc_result_t dhcp_class_stuff_values (omapi_object_t *,
3335 omapi_object_t *,
3336 omapi_object_t *);
3337isc_result_t dhcp_class_lookup (omapi_object_t **,
3338 omapi_object_t *, omapi_object_t *);
3339isc_result_t dhcp_class_create (omapi_object_t **,
3340 omapi_object_t *);
3341isc_result_t dhcp_class_remove (omapi_object_t *,
3342 omapi_object_t *);
c1f22aef
TL
3343isc_result_t dhcp_subclass_set_value (omapi_object_t *, omapi_object_t *,
3344 omapi_data_string_t *,
3345 omapi_typed_data_t *);
3346isc_result_t dhcp_subclass_get_value (omapi_object_t *, omapi_object_t *,
3347 omapi_data_string_t *,
a34feb7d 3348 omapi_value_t **);
c1f22aef
TL
3349isc_result_t dhcp_subclass_destroy (omapi_object_t *, const char *, int);
3350isc_result_t dhcp_subclass_signal_handler (omapi_object_t *,
3351 const char *, va_list);
3352isc_result_t dhcp_subclass_stuff_values (omapi_object_t *,
3353 omapi_object_t *,
3354 omapi_object_t *);
3355isc_result_t dhcp_subclass_lookup (omapi_object_t **,
3356 omapi_object_t *, omapi_object_t *);
3357isc_result_t dhcp_subclass_create (omapi_object_t **,
3358 omapi_object_t *);
3359isc_result_t dhcp_subclass_remove (omapi_object_t *,
3360 omapi_object_t *);
20916cae
TL
3361isc_result_t dhcp_interface_set_value (omapi_object_t *,
3362 omapi_object_t *,
3363 omapi_data_string_t *,
3364 omapi_typed_data_t *);
3365isc_result_t dhcp_interface_get_value (omapi_object_t *,
3366 omapi_object_t *,
3367 omapi_data_string_t *,
3368 omapi_value_t **);
3369isc_result_t dhcp_interface_destroy (omapi_object_t *,
3370 const char *, int);
3371isc_result_t dhcp_interface_signal_handler (omapi_object_t *,
3372 const char *,
3373 va_list ap);
3374isc_result_t dhcp_interface_stuff_values (omapi_object_t *,
3375 omapi_object_t *,
3376 omapi_object_t *);
3377isc_result_t dhcp_interface_lookup (omapi_object_t **,
3378 omapi_object_t *,
3379 omapi_object_t *);
3380isc_result_t dhcp_interface_create (omapi_object_t **,
3381 omapi_object_t *);
3382isc_result_t dhcp_interface_remove (omapi_object_t *,
3383 omapi_object_t *);
f3aad410
TL
3384void interface_stash (struct interface_info *);
3385void interface_snorf (struct interface_info *, int);
4fe74d72 3386
d758ad8c
TL
3387isc_result_t binding_scope_set_value (struct binding_scope *, int,
3388 omapi_data_string_t *,
3389 omapi_typed_data_t *);
3390isc_result_t binding_scope_get_value (omapi_value_t **,
3391 struct binding_scope *,
3392 omapi_data_string_t *);
3393isc_result_t binding_scope_stuff_values (omapi_object_t *,
3394 struct binding_scope *);
3395
6368a1bd
DH
3396void register_eventhandler(struct eventqueue **, void (*handler)(void *));
3397void unregister_eventhandler(struct eventqueue **, void (*handler)(void *));
a34feb7d 3398void trigger_event(struct eventqueue **);
6368a1bd 3399
940ea8ab
TL
3400/* mdb.c */
3401
8c8e27c5
TL
3402extern struct subnet *subnets;
3403extern struct shared_network *shared_networks;
98311e4b
DH
3404extern host_hash_t *host_hw_addr_hash;
3405extern host_hash_t *host_uid_hash;
3406extern host_hash_t *host_name_hash;
6708d944
DH
3407extern lease_id_hash_t *lease_uid_hash;
3408extern lease_ip_hash_t *lease_ip_addr_hash;
3409extern lease_id_hash_t *lease_hw_addr_hash;
940ea8ab
TL
3410
3411extern omapi_object_type_t *dhcp_type_host;
3412
f3fe382d
JB
3413extern int numclasseswritten;
3414
3415
a34feb7d
TM
3416isc_result_t enter_class (struct class *, int, int);
3417isc_result_t delete_class (struct class *, int);
3418isc_result_t enter_host (struct host_decl *, int, int);
3419isc_result_t delete_host (struct host_decl *, int);
98bd7ca0 3420void change_host_uid(struct host_decl *host, const char *data, int len);
a34feb7d
TM
3421int find_hosts_by_haddr (struct host_decl **, int,
3422 const unsigned char *, unsigned,
3423 const char *, int);
3424int find_hosts_by_uid (struct host_decl **, const unsigned char *,
3425 unsigned, const char *, int);
3426int find_hosts_by_option(struct host_decl **, struct packet *,
98bd7ca0 3427 struct option_state *, const char *, int);
a34feb7d
TM
3428int find_host_for_network (struct subnet **, struct host_decl **,
3429 struct iaddr *, struct shared_network *);
3430void new_address_range (struct parse *, struct iaddr, struct iaddr,
3431 struct subnet *, struct pool *,
3432 struct lease **);
20916cae 3433isc_result_t dhcp_lease_free (omapi_object_t *, const char *, int);
932d739c 3434isc_result_t dhcp_lease_get (omapi_object_t **, const char *, int);
a34feb7d
TM
3435int find_grouped_subnet (struct subnet **, struct shared_network *,
3436 struct iaddr, const char *, int);
98bd7ca0 3437int find_subnet(struct subnet **, struct iaddr, const char *, int);
a34feb7d
TM
3438void enter_shared_network (struct shared_network *);
3439void new_shared_network_interface (struct parse *,
3440 struct shared_network *,
3441 const char *);
98bd7ca0 3442int subnet_inner_than(const struct subnet *, const struct subnet *, int);
a34feb7d
TM
3443void enter_subnet (struct subnet *);
3444void enter_lease (struct lease *);
491bf4a2 3445int supersede_lease (struct lease *, struct lease *, int, int, int, int);
e540864e 3446void make_binding_state_transition (struct lease *);
a34feb7d
TM
3447int lease_copy (struct lease **, struct lease *, const char *, int);
3448void release_lease (struct lease *, struct packet *);
3449void abandon_lease (struct lease *, const char *);
d13db163
SR
3450#if 0
3451/* this appears to be unused and I plan to remove it SAR */
a34feb7d 3452void dissociate_lease (struct lease *);
d13db163 3453#endif
a34feb7d
TM
3454void pool_timer (void *);
3455int find_lease_by_uid (struct lease **, const unsigned char *,
3456 unsigned, const char *, int);
3457int find_lease_by_hw_addr (struct lease **, const unsigned char *,
3458 unsigned, const char *, int);
3459int find_lease_by_ip_addr (struct lease **, struct iaddr,
3460 const char *, int);
3461void uid_hash_add (struct lease *);
3462void uid_hash_delete (struct lease *);
3463void hw_hash_add (struct lease *);
3464void hw_hash_delete (struct lease *);
3465int write_leases (void);
98bd7ca0 3466int write_leases6(void);
3933e2aa
SR
3467#if !defined(BINARY_LEASES)
3468void lease_insert(struct lease **, struct lease *);
3469void lease_remove(struct lease **, struct lease *);
3933e2aa
SR
3470void lease_remove_all(struct lease **);
3471#endif
d0411fbd 3472int lease_enqueue (struct lease *);
f7fdb216 3473isc_result_t lease_instantiate(const void *, unsigned, void *);
a34feb7d
TM
3474void expire_all_pools (void);
3475void dump_subnets (void);
d758ad8c
TL
3476#if defined (DEBUG_MEMORY_LEAKAGE) || \
3477 defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
3478void free_everything (void);
3479#endif
9ba7cdec 3480
d9eefc5d
TL
3481/* failover.c */
3482#if defined (FAILOVER_PROTOCOL)
d758ad8c 3483extern dhcp_failover_state_t *failover_states;
a34feb7d 3484void dhcp_failover_startup (void);
d758ad8c 3485int dhcp_failover_write_all_states (void);
a34feb7d
TM
3486isc_result_t enter_failover_peer (dhcp_failover_state_t *);
3487isc_result_t find_failover_peer (dhcp_failover_state_t **,
3488 const char *, const char *, int);
3489isc_result_t dhcp_failover_link_initiate (omapi_object_t *);
3490isc_result_t dhcp_failover_link_signal (omapi_object_t *,
3491 const char *, va_list);
3492isc_result_t dhcp_failover_link_set_value (omapi_object_t *,
3493 omapi_object_t *,
3494 omapi_data_string_t *,
3495 omapi_typed_data_t *);
3496isc_result_t dhcp_failover_link_get_value (omapi_object_t *,
3497 omapi_object_t *,
3498 omapi_data_string_t *,
3499 omapi_value_t **);
3500isc_result_t dhcp_failover_link_destroy (omapi_object_t *,
3501 const char *, int);
3502isc_result_t dhcp_failover_link_stuff_values (omapi_object_t *,
3503 omapi_object_t *,
3504 omapi_object_t *);
3505isc_result_t dhcp_failover_listen (omapi_object_t *);
3506
3507isc_result_t dhcp_failover_listener_signal (omapi_object_t *,
3508 const char *,
3509 va_list);
3510isc_result_t dhcp_failover_listener_set_value (omapi_object_t *,
3511 omapi_object_t *,
3512 omapi_data_string_t *,
3513 omapi_typed_data_t *);
3514isc_result_t dhcp_failover_listener_get_value (omapi_object_t *,
3515 omapi_object_t *,
3516 omapi_data_string_t *,
3517 omapi_value_t **);
3518isc_result_t dhcp_failover_listener_destroy (omapi_object_t *,
3519 const char *, int);
3520isc_result_t dhcp_failover_listener_stuff (omapi_object_t *,
3521 omapi_object_t *,
3522 omapi_object_t *);
3523isc_result_t dhcp_failover_register (omapi_object_t *);
3524isc_result_t dhcp_failover_state_signal (omapi_object_t *,
3525 const char *, va_list);
aa8579c0
TL
3526isc_result_t dhcp_failover_state_transition (dhcp_failover_state_t *,
3527 const char *);
c489f075 3528isc_result_t dhcp_failover_set_service_state (dhcp_failover_state_t *state);
21d30347 3529void dhcp_failover_rescind_updates (dhcp_failover_state_t *);
aa8579c0
TL
3530isc_result_t dhcp_failover_set_state (dhcp_failover_state_t *,
3531 enum failover_state);
c489f075
TL
3532isc_result_t dhcp_failover_peer_state_changed (dhcp_failover_state_t *,
3533 failover_message_t *);
2426234f
DH
3534void dhcp_failover_pool_rebalance (void *);
3535void dhcp_failover_pool_check (struct pool *);
8c8e27c5 3536int dhcp_failover_state_pool_check (dhcp_failover_state_t *);
d0411fbd
TL
3537void dhcp_failover_timeout (void *);
3538void dhcp_failover_send_contact (void *);
8d3aec71 3539isc_result_t dhcp_failover_send_state (dhcp_failover_state_t *);
a7982987 3540isc_result_t dhcp_failover_send_updates (dhcp_failover_state_t *);
007e3ee4 3541int dhcp_failover_queue_update (struct lease *, int);
988c1ca7 3542int dhcp_failover_send_acks (dhcp_failover_state_t *);
af5ad6df 3543void dhcp_failover_toack_queue_timeout (void *);
988c1ca7 3544int dhcp_failover_queue_ack (dhcp_failover_state_t *, failover_message_t *msg);
f9d43a9a 3545void dhcp_failover_ack_queue_remove (dhcp_failover_state_t *, struct lease *);
a34feb7d
TM
3546isc_result_t dhcp_failover_state_set_value (omapi_object_t *,
3547 omapi_object_t *,
3548 omapi_data_string_t *,
3549 omapi_typed_data_t *);
aa8579c0 3550void dhcp_failover_keepalive (void *);
a7982987 3551void dhcp_failover_reconnect (void *);
c489f075 3552void dhcp_failover_startup_timeout (void *);
8d3aec71 3553void dhcp_failover_link_startup_timeout (void *);
a7982987 3554void dhcp_failover_listener_restart (void *);
9e3eb22a 3555void dhcp_failover_auto_partner_down(void *vs);
a34feb7d
TM
3556isc_result_t dhcp_failover_state_get_value (omapi_object_t *,
3557 omapi_object_t *,
3558 omapi_data_string_t *,
3559 omapi_value_t **);
3560isc_result_t dhcp_failover_state_destroy (omapi_object_t *,
3561 const char *, int);
3562isc_result_t dhcp_failover_state_stuff (omapi_object_t *,
3563 omapi_object_t *,
3564 omapi_object_t *);
3565isc_result_t dhcp_failover_state_lookup (omapi_object_t **,
3566 omapi_object_t *,
3567 omapi_object_t *);
3568isc_result_t dhcp_failover_state_create (omapi_object_t **,
3569 omapi_object_t *);
3570isc_result_t dhcp_failover_state_remove (omapi_object_t *,
3571 omapi_object_t *);
a7982987 3572int dhcp_failover_state_match (dhcp_failover_state_t *, u_int8_t *, unsigned);
a55ccdd0 3573int dhcp_failover_state_match_by_name(dhcp_failover_state_t *,
a34feb7d 3574 failover_option_t *);
a7982987
TL
3575const char *dhcp_failover_reject_reason_print (int);
3576const char *dhcp_failover_state_name_print (enum failover_state);
af380050
TL
3577const char *dhcp_failover_message_name (unsigned);
3578const char *dhcp_failover_option_name (unsigned);
165bce70
TL
3579failover_option_t *dhcp_failover_option_printf (unsigned, char *,
3580 unsigned *,
a34feb7d 3581 unsigned,
72896e9f
TL
3582 const char *, ...)
3583 __attribute__((__format__(__printf__,5,6)));
3584failover_option_t *dhcp_failover_make_option (unsigned, char *,
3585 unsigned *, unsigned, ...);
165bce70 3586isc_result_t dhcp_failover_put_message (dhcp_failover_link_t *,
a55ccdd0 3587 omapi_object_t *, int, u_int32_t, ...);
a34feb7d
TM
3588isc_result_t dhcp_failover_send_connect (omapi_object_t *);
3589isc_result_t dhcp_failover_send_connectack (omapi_object_t *,
3590 dhcp_failover_state_t *,
3591 int, const char *);
3592isc_result_t dhcp_failover_send_disconnect (omapi_object_t *,
3593 int, const char *);
a7982987
TL
3594isc_result_t dhcp_failover_send_bind_update (dhcp_failover_state_t *,
3595 struct lease *);
8c8e27c5 3596isc_result_t dhcp_failover_send_bind_ack (dhcp_failover_state_t *,
988c1ca7 3597 failover_message_t *,
8c8e27c5
TL
3598 int, const char *);
3599isc_result_t dhcp_failover_send_poolreq (dhcp_failover_state_t *);
3600isc_result_t dhcp_failover_send_poolresp (dhcp_failover_state_t *, int);
c489f075
TL
3601isc_result_t dhcp_failover_send_update_request (dhcp_failover_state_t *);
3602isc_result_t dhcp_failover_send_update_request_all (dhcp_failover_state_t *);
3603isc_result_t dhcp_failover_send_update_done (dhcp_failover_state_t *);
8c8e27c5
TL
3604isc_result_t dhcp_failover_process_bind_update (dhcp_failover_state_t *,
3605 failover_message_t *);
3606isc_result_t dhcp_failover_process_bind_ack (dhcp_failover_state_t *,
3607 failover_message_t *);
c489f075
TL
3608isc_result_t dhcp_failover_generate_update_queue (dhcp_failover_state_t *,
3609 int);
3610isc_result_t dhcp_failover_process_update_request (dhcp_failover_state_t *,
3611 failover_message_t *);
3612isc_result_t dhcp_failover_process_update_request_all (dhcp_failover_state_t *,
3613 failover_message_t *);
3614isc_result_t dhcp_failover_process_update_done (dhcp_failover_state_t *,
3615 failover_message_t *);
1d17db44 3616void ia_remove_all_lease(struct ia_xx *ia, const char *file, int line);
c489f075 3617void dhcp_failover_recover_done (void *);
a34feb7d
TM
3618void failover_print (char *, unsigned *, unsigned, const char *);
3619void update_partner (struct lease *);
aa8579c0 3620int load_balance_mine (struct packet *, dhcp_failover_state_t *);
2426234f 3621int peer_wants_lease (struct lease *);
e540864e
TL
3622binding_state_t normal_binding_state_transition_check (struct lease *,
3623 dhcp_failover_state_t *,
31bbee78
TL
3624 binding_state_t,
3625 u_int32_t);
e540864e
TL
3626binding_state_t
3627conflict_binding_state_transition_check (struct lease *,
3628 dhcp_failover_state_t *,
31bbee78 3629 binding_state_t, u_int32_t);
c489f075 3630int lease_mine_to_reallocate (struct lease *);
007e3ee4 3631
20916cae
TL
3632OMAPI_OBJECT_ALLOC_DECL (dhcp_failover_state, dhcp_failover_state_t,
3633 dhcp_type_failover_state)
3634OMAPI_OBJECT_ALLOC_DECL (dhcp_failover_listener, dhcp_failover_listener_t,
3635 dhcp_type_failover_listener)
3636OMAPI_OBJECT_ALLOC_DECL (dhcp_failover_link, dhcp_failover_link_t,
57c8fdd7 3637 dhcp_type_failover_link)
d9eefc5d 3638#endif /* FAILOVER_PROTOCOL */
e540864e
TL
3639
3640const char *binding_state_print (enum failover_state);
98bd7ca0 3641
33692791
DH
3642/* ldap.c */
3643#if defined(LDAP_CONFIGURATION)
3644extern struct enumeration ldap_methods;
3645#if defined (LDAP_USE_SSL)
3646extern struct enumeration ldap_ssl_usage_enum;
3647extern struct enumeration ldap_tls_reqcert_enum;
3648extern struct enumeration ldap_tls_crlcheck_enum;
3649#endif
3650isc_result_t ldap_read_config (void);
3651int find_haddr_in_ldap (struct host_decl **, int, unsigned,
a34feb7d 3652 const unsigned char *, const char *, int);
33692791 3653int find_subclass_in_ldap (struct class *, struct class **,
a34feb7d 3654 struct data_string *);
743d6937
TM
3655int find_client_in_ldap (struct host_decl **, struct packet*,
3656 struct option_state *, const char *, int);
33692791 3657#endif
98bd7ca0
DH
3658
3659/* mdb6.c */
e91b6f3c 3660HASH_FUNCTIONS_DECL(ia, unsigned char *, struct ia_xx, ia_hash_t)
1d17db44 3661HASH_FUNCTIONS_DECL(iasubopt, struct in6_addr *, struct iasubopt,
e91b6f3c 3662 iasubopt_hash_t)
98bd7ca0 3663
1d17db44
FD
3664isc_result_t iasubopt_allocate(struct iasubopt **iasubopt,
3665 const char *file, int line);
3666isc_result_t iasubopt_reference(struct iasubopt **iasubopt,
3667 struct iasubopt *src,
98bd7ca0 3668 const char *file, int line);
1d17db44
FD
3669isc_result_t iasubopt_dereference(struct iasubopt **iasubopt,
3670 const char *file, int line);
98bd7ca0 3671
1d9774ab
FD
3672isc_result_t ia_make_key(struct data_string *key, u_int32_t iaid,
3673 const char *duid, unsigned int duid_len,
3674 const char *file, int line);
9322442f
FD
3675isc_result_t ia_allocate(struct ia_xx **ia, u_int32_t iaid,
3676 const char *duid, unsigned int duid_len,
98bd7ca0 3677 const char *file, int line);
9322442f
FD
3678isc_result_t ia_reference(struct ia_xx **ia, struct ia_xx *src,
3679 const char *file, int line);
3680isc_result_t ia_dereference(struct ia_xx **ia,
1d9774ab 3681 const char *file, int line);
1d17db44
FD
3682isc_result_t ia_add_iasubopt(struct ia_xx *ia, struct iasubopt *iasubopt,
3683 const char *file, int line);
3684void ia_remove_iasubopt(struct ia_xx *ia, struct iasubopt *iasubopt,
3685 const char *file, int line);
9322442f 3686isc_boolean_t ia_equal(const struct ia_xx *a, const struct ia_xx *b);
1d9774ab 3687
9322442f
FD
3688isc_result_t ipv6_pool_allocate(struct ipv6_pool **pool, u_int16_t type,
3689 const struct in6_addr *start_addr,
3690 int bits, int units,
98bd7ca0
DH
3691 const char *file, int line);
3692isc_result_t ipv6_pool_reference(struct ipv6_pool **pool,
3693 struct ipv6_pool *src,
3694 const char *file, int line);
3695isc_result_t ipv6_pool_dereference(struct ipv6_pool **pool,
3696 const char *file, int line);
5d89d60f 3697isc_result_t create_lease6(struct ipv6_pool *pool,
1d17db44 3698 struct iasubopt **addr,
5d89d60f
FD
3699 unsigned int *attempts,
3700 const struct data_string *uid,
3701 time_t soft_lifetime_end_time);
98bd7ca0 3702isc_result_t add_lease6(struct ipv6_pool *pool,
1d17db44 3703 struct iasubopt *lease,
98bd7ca0 3704 time_t valid_lifetime_end_time);
1d17db44
FD
3705isc_result_t renew_lease6(struct ipv6_pool *pool, struct iasubopt *lease);
3706isc_result_t expire_lease6(struct iasubopt **leasep,
98bd7ca0 3707 struct ipv6_pool *pool, time_t now);
1d17db44
FD
3708isc_result_t release_lease6(struct ipv6_pool *pool, struct iasubopt *lease);
3709isc_result_t decline_lease6(struct ipv6_pool *pool, struct iasubopt *lease);
a34feb7d 3710isc_boolean_t lease6_exists(const struct ipv6_pool *pool,
98bd7ca0 3711 const struct in6_addr *addr);
bc7f8b8e
SR
3712isc_boolean_t lease6_usable(struct iasubopt *lease);
3713isc_result_t cleanup_lease6(ia_hash_t *ia_table,
3714 struct ipv6_pool *pool,
3715 struct iasubopt *lease,
3716 struct ia_xx *ia);
9322442f
FD
3717isc_result_t mark_lease_unavailble(struct ipv6_pool *pool,
3718 const struct in6_addr *addr);
9322442f 3719isc_result_t create_prefix6(struct ipv6_pool *pool,
1d17db44 3720 struct iasubopt **pref,
5d89d60f
FD
3721 unsigned int *attempts,
3722 const struct data_string *uid,
3723 time_t soft_lifetime_end_time);
a34feb7d 3724isc_boolean_t prefix6_exists(const struct ipv6_pool *pool,
1d9774ab
FD
3725 const struct in6_addr *pref, u_int8_t plen);
3726
98bd7ca0 3727isc_result_t add_ipv6_pool(struct ipv6_pool *pool);
9322442f 3728isc_result_t find_ipv6_pool(struct ipv6_pool **pool, u_int16_t type,
98bd7ca0 3729 const struct in6_addr *addr);
a34feb7d 3730isc_boolean_t ipv6_in_pool(const struct in6_addr *addr,
9322442f 3731 const struct ipv6_pool *pool);
01fa619f
SR
3732isc_result_t ipv6_pond_allocate(struct ipv6_pond **pond,
3733 const char *file, int line);
3734isc_result_t ipv6_pond_reference(struct ipv6_pond **pond,
3735 struct ipv6_pond *src,
3736 const char *file, int line);
3737isc_result_t ipv6_pond_dereference(struct ipv6_pond **pond,
3738 const char *file, int line);
9322442f
FD
3739
3740isc_result_t renew_leases(struct ia_xx *ia);
3741isc_result_t release_leases(struct ia_xx *ia);
3742isc_result_t decline_leases(struct ia_xx *ia);
d9b43370
SK
3743void schedule_lease_timeout(struct ipv6_pool *pool);
3744void schedule_all_ipv6_lease_timeouts();
98bd7ca0
DH
3745
3746void mark_hosts_unavailable(void);
80c9fdb0 3747void mark_phosts_unavailable(void);
98bd7ca0 3748void mark_interfaces_unavailable(void);
fb98e02e 3749void report_jumbo_ranges();
98bd7ca0 3750
3933e2aa
SR
3751#if defined (BINARY_LEASES)
3752/* leasechain.c */
3753int lc_not_empty(struct leasechain *lc);
3754void lc_add_sorted_lease(struct leasechain *lc, struct lease *lp);
3755void lc_unlink_lease(struct leasechain *lc, struct lease *lp);
3756struct lease *lc_get_first_lease(struct leasechain *lc);
3757struct lease *lc_get_next(struct leasechain *lc, struct lease *lp);
3758void lc_init_growth(struct leasechain *lc, size_t growth);
3759#if defined (DEBUG_MEMORY_LEAKAGE) || \
3760 defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
3761void lc_delete_all(struct leasechain *lc);
3762#endif
3763#endif /* BINARY_LEASES */
3764
beaed73f
SR
3765#define MAX_ADDRESS_STRING_LEN \
3766 (sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"))
250f7134
SR
3767
3768/* Find the percentage of count. We need to try two different
3769 * ways to avoid rounding mistakes.
3770 */
3771#define FIND_PERCENT(count, percent) \
3772 ((count) > (INT_MAX / 100) ? \
3773 ((count) / 100) * (percent) : ((count) * (percent)) / 100)
3774
fb98e02e
TM
3775#define FIND_POND6_PERCENT(count, percent) \
3776 ((count) > (POND_TRACK_MAX / 100) ? \
3777 ((count) / 100) * (percent) : ((count) * (percent)) / 100)
3778