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