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