84 }
else if (cd->name != NULL) {
88 class_dereference(&c,
MDL);
96 class_reference (&c ->
nic, cd,
MDL);
99 if (dynamicp && commit) {
100 const char *
name = cd->name;
103 name = cd->superclass->name;
108 return ISC_R_IOERROR;
111 return ISC_R_SUCCESS;
122 static int server_starting = 0;
130 esp ->
data.option &&
136 log_error (
"dhcp client identifier may not be %s",
137 "specified conditionally.");
138 }
else if (!(*evp)) {
142 log_error (
"only one dhcp client identifier may be %s",
151 find_host_id_info(
unsigned int option_code,
int relays) {
154 for (p = host_id_info; p != NULL; p = p->
next) {
166 print_host(
const void *
name,
unsigned len,
void *value) {
168 printf(
"--------------\n");
170 printf(
"len:%d\n", len);
172 printf(
"host @%p is '%s'\n", h, h->
name);
173 return ISC_R_SUCCESS;
179 printf(
"--------------\n");
186 if (host_uid_hash == NULL) {
188 log_fatal(
"Can't allocate host/uid hash");
196 host_hash_delete(host_uid_hash,
231 if (!host_name_hash) {
233 log_fatal (
"Can't allocate host name hash");
234 host_hash_add (host_name_hash,
235 (
unsigned char *)hd -> name,
236 strlen (hd -> name), hd,
MDL);
238 host_hash_lookup (&hp, host_name_hash,
239 (
unsigned char *)hd -> name,
240 strlen (hd -> name),
MDL);
244 host_hash_delete (host_name_hash,
245 (
unsigned char *)hd -> name,
246 strlen (hd -> name),
MDL);
252 host_dereference (&hp,
MDL);
257 if (hp && hp == hd) {
258 host_dereference (&hp,
MDL);
261 return ISC_R_IOERROR;
262 hd -> flags &= ~HOST_DECL_DELETED;
268 host_hash_add (host_name_hash,
269 (
unsigned char *)hd -> name,
270 strlen (hd -> name), hd,
MDL);
274 host_dereference (&hp,
MDL);
280 host_dereference (&hd -> n_ipaddr,
MDL);
285 if (hd -> interface.hlen) {
286 if (!host_hw_addr_hash) {
287 if (!host_new_hash(&host_hw_addr_hash,
289 log_fatal (
"Can't allocate host/hw hash");
293 host_hash_lookup (&hp, host_hw_addr_hash,
294 hd -> interface.hbuf,
295 hd -> interface.hlen,
MDL);
298 host_hash_add (host_hw_addr_hash, hd -> interface.hbuf,
299 hd -> interface.hlen, hd,
MDL);
304 for (np = hp; np -> n_ipaddr; np = np -> n_ipaddr)
306 host_reference (&np -> n_ipaddr, hd,
MDL);
307 host_dereference (&hp,
MDL);
316 find_uid_statement, &esp, 0)) {
318 NULL, NULL, NULL, NULL, NULL,
325 if (hd -> client_identifier.len) {
328 if (!host_uid_hash) {
329 if (!host_new_hash(&host_uid_hash,
331 log_fatal (
"Can't allocate host/uid hash");
333 host_hash_add (host_uid_hash,
334 hd -> client_identifier.data,
335 hd -> client_identifier.len,
341 if (host_hash_lookup (&hp, host_uid_hash,
342 hd -> client_identifier.data,
343 hd -> client_identifier.len,
347 for (np = hp; np -> n_ipaddr;
348 np = np -> n_ipaddr) {
353 host_reference (&np -> n_ipaddr,
356 host_dereference (&hp,
MDL);
358 host_hash_add (host_uid_hash,
359 hd -> client_identifier.data,
360 hd -> client_identifier.len,
370 if (hd->host_id_option != NULL) {
375 h_id_info = find_host_id_info(hd->host_id_option->code,
377 if (h_id_info == NULL) {
379 if (h_id_info == NULL) {
380 log_fatal(
"No memory for host-identifier "
381 "option information.");
384 hd->host_id_option,
MDL);
387 log_fatal(
"No memory for host-identifier "
390 h_id_info->
relays = hd->relays;
391 h_id_info->
next = host_id_info;
392 host_id_info = h_id_info;
396 hd->host_id.data, hd->host_id.len,
MDL)) {
416 host_dereference(&hp,
MDL);
425 if (dynamicp && commit) {
427 return ISC_R_IOERROR;
429 return ISC_R_IOERROR;
432 return ISC_R_SUCCESS;
448 return ISC_R_IOERROR;
454 if (cp->superclass) {
455 class_hash_delete(cp->superclass->hash,
456 (
const char *)cp->hash_string.data,
464 return ISC_R_SUCCESS;
475 int hw_head = 0, uid_head = 1;
479 return ISC_R_SUCCESS;
485 if (host_hw_addr_hash) {
486 if (host_hash_lookup (&hp, host_hw_addr_hash,
490 host_hash_delete (host_hw_addr_hash,
497 host_reference (&foo, hp,
MDL);
502 host_dereference (&np,
MDL);
503 host_reference (&np, foo,
MDL);
504 host_dereference (&foo,
MDL);
514 host_dereference (&foo,
MDL);
517 host_dereference (&np,
MDL);
519 host_dereference (&hp,
MDL);
528 if (host_hash_lookup (&hp, host_uid_hash,
532 host_hash_delete (host_uid_hash,
539 host_reference (&foo, hp,
MDL);
544 host_dereference (&np,
MDL);
545 host_reference (&np, foo,
MDL);
546 host_dereference (&foo,
MDL);
556 host_dereference (&foo,
MDL);
559 host_dereference (&np,
MDL);
561 host_dereference (&hp,
MDL);
566 if (hd->host_id_option != NULL) {
580 host_hash_add (host_hw_addr_hash,
588 if (host_name_hash) {
589 if (host_hash_lookup (&hp, host_name_hash,
590 (
unsigned char *)hd -> name,
591 strlen (hd -> name),
MDL)) {
593 host_hash_delete (host_name_hash,
594 (
unsigned char *)hd -> name,
595 strlen (hd -> name),
MDL);
597 host_dereference (&hp,
MDL);
603 return ISC_R_IOERROR;
605 return ISC_R_IOERROR;
607 return ISC_R_SUCCESS;
611 const unsigned char *haddr,
unsigned hlen,
615 #if defined(LDAP_CONFIGURATION)
618 if ((ret = find_haddr_in_ldap (hp, htype, hlen, haddr, file, line)))
624 memcpy (&h.
hbuf [1], haddr, hlen);
626 return host_hash_lookup (hp, host_hw_addr_hash,
631 const unsigned char *data,
unsigned len,
634 return host_hash_lookup (hp, host_uid_hash, data, len, file, line);
646 struct packet *relay_packet;
649 for (p = host_id_info; p != NULL; p = p->
next) {
650 relay_packet = packet;
651 relay_state = opt_state;
671 relay_state = relay_packet->
options;
677 memset(&data, 0,
sizeof(data));
680 NULL, relay_state, NULL,
683 log_error(
"Error evaluating option cache");
713 struct iaddr ip_address;
717 memset (&fixed_addr, 0,
sizeof fixed_addr);
719 for (hp = *host; hp; hp = hp -> n_ipaddr) {
720 if (!hp -> fixed_addr)
728 hp -> fixed_addr,
MDL))
730 for (i = 0; i < fixed_addr.
len; i += 4) {
732 memcpy (ip_address.
iabuf,
733 fixed_addr.
data + i, 4);
742 host_reference (&tmp, *host,
MDL);
743 host_dereference (host,
MDL);
744 host_reference (host, hp,
MDL);
745 host_dereference (&tmp,
MDL);
757 struct
iaddr low, high;
760 struct
lease **lpchain;
762 #if defined(COMPACT_LEASES)
763 struct lease *address_range;
765 unsigned min, max, i;
766 char lowbuf [16], highbuf [16], netbuf [16];
769 #if !defined(COMPACT_LEASES)
775 strcpy (netbuf,
piaddr (subnet -> net));
776 log_fatal (
"No shared network for network %s (%s)",
777 netbuf,
piaddr (subnet -> netmask));
781 if (!lease_uid_hash) {
783 log_fatal (
"Can't allocate lease/uid hash");
785 if (!lease_ip_addr_hash) {
788 log_fatal (
"Can't allocate lease/ip hash");
790 if (!lease_hw_addr_hash) {
793 log_fatal (
"Can't allocate lease/hw hash");
798 strcpy(lowbuf,
piaddr(low));
800 log_fatal(
"bad range, address %s not in subnet %s netmask %s",
805 strcpy(highbuf,
piaddr(high));
807 log_fatal(
"bad range, address %s not in subnet %s netmask %s",
812 max =
host_addr (high, subnet -> netmask);
813 min =
host_addr (low, subnet -> netmask);
818 min =
host_addr (high, subnet -> netmask);
822 #if defined (COMPACT_LEASES)
824 if (!address_range) {
825 strcpy (lowbuf,
piaddr (low));
826 strcpy (highbuf,
piaddr (high));
827 log_fatal (
"No memory for address range %s-%s.",
833 for (i = 0; i < max - min + 1; i++) {
835 #if defined (COMPACT_LEASES)
839 lease_reference (&lp, &address_range [i],
MDL);
841 status = lease_allocate (&lp,
MDL);
842 if (status != ISC_R_SUCCESS)
847 isc_result_totext (status));
852 subnet_reference(&lp->
subnet, subnet,
MDL);
853 pool_reference(&lp->
pool, pool,
MDL);
863 "lease %s is declared twice!",
866 pool_reference (< -> pool, pool,
MDL);
867 lease_dereference (<,
MDL);
869 lease_ip_hash_add(lease_ip_addr_hash,
875 lease_reference (&lp ->
next, *lpchain,
MDL);
876 lease_dereference (lpchain,
MDL);
878 lease_reference (lpchain, lp,
MDL);
880 lease_dereference (&lp,
MDL);
891 if (subnet_reference (sp, rv,
892 file, line) != ISC_R_SUCCESS)
906 for (rv = share -> subnets; rv; rv = rv ->
next_sibling) {
908 if (subnet_reference (sp, rv,
909 file, line) != ISC_R_SUCCESS)
920 const struct subnet *scan,
924 char n1buf[
sizeof(
"ffff:ffff:ffff:ffff:ffff:ffff:255.255.255")];
926 for (i = 0; i < 128; i++)
930 for (j = 0; j < 128; j++)
936 log_error(
"Warning: subnet %s/%d overlaps subnet %s/%d",
950 struct subnet *scan = (
struct subnet *)0;
951 struct subnet *next = (
struct subnet *)0;
952 struct subnet *prev = (
struct subnet *)0;
956 subnet_reference (&next, subnets,
MDL);
958 subnet_reference (&scan, next,
MDL);
959 subnet_dereference (&next,
MDL);
969 subnet_dereference (&prev,
MDL);
971 subnet_dereference (&subnets,
MDL);
972 subnet_reference (&subnets, subnet,
MDL);
975 subnet_dereference (&scan,
MDL);
978 subnet_reference (&prev, scan,
MDL);
979 subnet_dereference (&scan,
MDL);
982 subnet_dereference (&prev,
MDL);
987 subnet_dereference (&subnets,
MDL);
989 subnet_reference (&subnets, subnet,
MDL);
997 if (shared_networks) {
998 shared_network_reference (&share -> next,
999 shared_networks,
MDL);
1000 shared_network_dereference (&shared_networks,
MDL);
1002 shared_network_reference (&shared_networks, share,
MDL);
1006 struct
parse *cfile;
1011 isc_result_t status;
1013 if (share -> interface) {
1015 "A subnet or shared network can't be connected %s",
1016 "to two interfaces.");
1021 if (!strcmp (ip -> name, name))
1024 status = interface_allocate (&ip,
MDL);
1025 if (status != ISC_R_SUCCESS)
1026 log_fatal (
"new_shared_network_interface %s: %s",
1027 name, isc_result_totext (status));
1028 if (strlen (name) >
sizeof ip -> name) {
1029 memcpy (ip -> name, name, (
sizeof ip -> name) - 1);
1030 ip -> name [(
sizeof ip ->
name) - 1] = 0;
1032 strcpy (ip -> name, name);
1041 interface_reference (&share -> interface, ip,
MDL);
1054 struct lease *comp = (
struct lease *)0;
1057 if (!comp ->
pool) {
1058 log_error (
"undeclared lease found in database: %s",
1061 pool_reference (&lease ->
pool, comp ->
pool,
MDL);
1064 subnet_reference (&lease ->
subnet,
1066 lease_ip_hash_delete(lease_ip_addr_hash,
1067 lease->ip_addr.iabuf, lease->ip_addr.len,
1069 lease_dereference (&comp,
MDL);
1085 lease_ip_hash_add(lease_ip_addr_hash, lease->ip_addr.iabuf,
1086 lease->ip_addr.len, lease,
MDL);
1100 struct lease *lp, **lq, *prev;
1102 #if defined (FAILOVER_PROTOCOL)
1103 int do_pool_check = 0;
1108 if (pimmediate && !commit)
1132 (((comp -> uid && lease -> uid) &&
1133 (comp -> uid_len != lease -> uid_len ||
1134 memcmp (comp -> uid, lease -> uid, comp -> uid_len))) ||
1136 ((comp -> hardware_addr.hlen !=
1137 lease -> hardware_addr.hlen) ||
1138 memcmp (comp -> hardware_addr.hbuf,
1139 lease -> hardware_addr.hbuf,
1140 comp -> hardware_addr.hlen))))) {
1149 if (comp->uid != comp->uid_buf) {
1154 comp -> uid = (
unsigned char *)0;
1160 if (comp->hardware_addr.hlen)
1164 if (comp -> billing_class != lease -> billing_class) {
1165 if (comp -> billing_class)
1167 if (lease -> billing_class)
1172 comp -> starts = lease -> starts;
1174 if (lease -> uid_len <=
sizeof (lease -> uid_buf)) {
1175 memcpy (comp -> uid_buf,
1176 lease -> uid, lease -> uid_len);
1177 comp -> uid = &comp -> uid_buf [0];
1178 comp -> uid_max =
sizeof comp -> uid_buf;
1179 comp -> uid_len = lease -> uid_len;
1180 }
else if (lease -> uid != &lease -> uid_buf [0]) {
1181 comp -> uid = lease -> uid;
1182 comp -> uid_max = lease -> uid_max;
1183 lease -> uid = (
unsigned char *)0;
1184 lease -> uid_max = 0;
1185 comp -> uid_len = lease -> uid_len;
1186 lease -> uid_len = 0;
1191 comp -> uid = (
unsigned char *)0;
1192 comp -> uid_len = comp -> uid_max = 0;
1195 host_dereference (&comp -> host,
MDL);
1196 host_reference (&comp -> host, lease -> host,
MDL);
1197 comp -> hardware_addr = lease -> hardware_addr;
1202 if (lease -> scope) {
1212 if (lease -> next_binding_state ==
FTS_ACTIVE ||
1221 if (comp -> client_hostname)
1222 dfree (comp -> client_hostname,
MDL);
1223 comp -> client_hostname = lease -> client_hostname;
1224 lease -> client_hostname = (
char *)0;
1226 if (lease->on_star.on_expiry) {
1227 if (comp->on_star.on_expiry)
1229 (&comp->on_star.on_expiry,
MDL);
1231 lease->on_star.on_expiry,
1234 if (lease->on_star.on_commit) {
1235 if (comp->on_star.on_commit)
1237 (&comp->on_star.on_commit,
MDL);
1239 lease->on_star.on_commit,
1242 if (lease->on_star.on_release) {
1243 if (comp->on_star.on_release)
1245 (&comp->on_star.on_release,
MDL);
1247 lease->on_star.on_release,
1256 if (comp->hardware_addr.hlen)
1259 comp->cltt = lease->cltt;
1260 #if defined (FAILOVER_PROTOCOL)
1261 comp->tstp = lease->tstp;
1262 comp->tsfp = lease->tsfp;
1263 comp->atsfp = lease->atsfp;
1265 comp->ends = lease->ends;
1266 comp->next_binding_state = lease->next_binding_state;
1275 if (lease->ddns_cb != NULL)
1276 comp->ddns_cb = lease->ddns_cb;
1279 #if defined (FAILOVER_PROTOCOL)
1289 if (!comp ->
pool) {
1290 log_error (
"Supersede_lease: lease %s with no pool.",
1296 switch (comp -> binding_state) {
1305 #if defined(FAILOVER_PROTOCOL)
1311 lq = &comp ->
pool -> active;
1317 lq = &comp ->
pool -> expired;
1321 lq = &comp ->
pool -> abandoned;
1332 #if defined(FAILOVER_PROTOCOL)
1338 log_error (
"Lease with bogus binding state: %d",
1339 comp -> binding_state);
1340 #if defined (BINDING_STATE_DEBUG)
1349 prev = (
struct lease *)0;
1350 for (lp = *lq; lp; lp = lp ->
next) {
1357 log_fatal(
"Lease with binding state %s not on its queue.",
1358 (comp->binding_state < 1 ||
1365 lease_dereference (&prev ->
next,
MDL);
1367 lease_reference (&prev ->
next, comp ->
next,
MDL);
1368 lease_dereference (&comp ->
next,
MDL);
1371 lease_dereference (lq,
MDL);
1373 lease_reference (lq, comp ->
next,
MDL);
1374 lease_dereference (&comp ->
next,
MDL);
1379 if (commit || !pimmediate)
1398 if ((commit || !pimmediate) &&
1401 (comp -> sort_time < comp ->
pool -> next_event_time ||
1404 tv . tv_sec = comp ->
pool -> next_event_time;
1413 #if defined(FAILOVER_PROTOCOL)
1423 if (propogate && (comp->pool->failover_peer != NULL) &&
1424 ((comp->pool->failover_peer->service_state ==
1426 (comp->pool->failover_peer->service_state ==
1428 comp->rewind_binding_state = comp->binding_state;
1433 if ((server_starting &
SS_NOSYNC) == 0) {
1439 #if defined (FAILOVER_PROTOCOL)
1445 if (do_pool_check && comp->pool->failover_peer)
1454 if ((commit || !pimmediate) &&
1465 #if defined (FAILOVER_PROTOCOL)
1466 dhcp_failover_state_t *peer;
1468 if (lease ->
pool && lease ->
pool -> failover_peer)
1469 peer = lease ->
pool -> failover_peer;
1471 peer = (dhcp_failover_state_t *)0;
1488 #if defined (NSUPDATE)
1518 host_dereference (&lease ->
host,
MDL);
1537 #if defined (NSUPDATE)
1582 host_dereference (&lease ->
host,
MDL);
1589 #if defined (DEBUG_LEASE_STATE_TRANSITIONS)
1590 log_debug (
"lease %s moves from %s to %s",
1599 #if defined (FAILOVER_PROTOCOL)
1600 if (lease ->
pool && lease ->
pool -> failover_peer)
1612 #if defined(FAILOVER_PROTOCOL)
1617 if ((lease->
pool != NULL) &&
1631 #if defined (DEBUG_LEASE_STATE_TRANSITIONS)
1632 log_debug (
"lease %s: next binding state %s",
1643 struct lease *lt = (
struct lease *)0;
1644 isc_result_t status;
1646 status = lease_allocate (<,
MDL);
1647 if (status != ISC_R_SUCCESS)
1658 }
else if (!lease ->
uid_max) {
1659 lt ->
uid = (
unsigned char *)0;
1663 lease_dereference (<,
MDL);
1672 lease_dereference (<,
MDL);
1682 host_reference (< ->
host, lease ->
host, file, line);
1683 subnet_reference (< ->
subnet, lease ->
subnet, file, line);
1684 pool_reference (< ->
pool, lease ->
pool, file, line);
1708 status = lease_reference(lp, lt, file, line);
1709 lease_dereference(<,
MDL);
1710 return status == ISC_R_SUCCESS;
1720 #if defined (NSUPDATE)
1723 if (lease->on_star.on_release) {
1726 NULL, &lease->scope,
1727 lease->on_star.on_release, NULL);
1728 if (lease->on_star.on_release)
1730 (&lease->on_star.on_release,
MDL);
1736 if (lease->on_star.on_expiry)
1738 (&lease->on_star.on_expiry,
MDL);
1745 if (lease->on_star.on_commit)
1747 (&lease->on_star.on_commit,
MDL);
1760 #if defined (FAILOVER_PROTOCOL)
1761 if (lease ->
pool && lease ->
pool -> failover_peer) {
1762 dhcp_failover_state_t *peer = NULL;
1764 if (lease->pool != NULL)
1765 peer = lease->pool->failover_peer;
1768 (((peer->i_am == primary) &&
1769 (lease->rewind_binding_state ==
FTS_FREE)) ||
1770 ((peer->i_am == secondary) &&
1771 (lease->rewind_binding_state ==
FTS_BACKUP)))) {
1772 lease->next_binding_state =
1773 lease->rewind_binding_state;
1791 const
char *message;
1793 struct lease *lt = (
struct lease *)0;
1794 #if defined (NSUPDATE)
1807 log_error (
"Abandoning IP address %s: %s",
1812 lt ->
uid = (
unsigned char *)0;
1816 lease_dereference (<,
MDL);
1830 void dissociate_lease (
lease)
1833 struct lease *lt = (
struct lease *)0;
1834 #if defined (NSUPDATE)
1841 #if defined (FAILOVER_PROTOCOL)
1842 if (lease ->
pool && lease ->
pool -> failover_peer) {
1854 lt ->
uid = (
unsigned char *)0;
1858 lease_dereference (<,
MDL);
1867 struct lease *
next = (
struct lease *)0;
1868 struct lease *lease = (
struct lease *)0;
1869 #define FREE_LEASES 0
1870 #define ACTIVE_LEASES 1
1871 #define EXPIRED_LEASES 2
1872 #define ABANDONED_LEASES 3
1873 #define BACKUP_LEASES 4
1874 #define RESERVED_LEASES 5
1880 pool = (
struct pool *)vpool;
1894 #if defined (FAILOVER_PROTOCOL)
1895 if (pool->failover_peer &&
1911 (pool->failover_peer->i_am == secondary) &&
1912 (pool->failover_peer->me.state ==
normal))
1922 lease_reference (&lease, *(lptr [i]),
MDL);
1927 lease_dereference (&next,
MDL);
1929 lease_reference (&next, lease -> next,
MDL);
1933 if (lease -> sort_time >
cur_time) {
1934 if (lease -> sort_time < next_expiry)
1935 next_expiry = lease -> sort_time;
1946 #if defined(FAILOVER_PROTOCOL)
1947 dhcp_failover_state_t *peer = NULL;
1949 if (lease->
pool != NULL)
1956 ((peer->i_am == primary &&
1959 (peer->i_am == secondary &&
1968 lease_dereference (&lease,
MDL);
1970 lease_reference (&lease, next,
MDL);
1973 lease_dereference (&next,
MDL);
1975 lease_dereference (&lease,
MDL);
1994 return lease_ip_hash_lookup(lp, lease_ip_addr_hash, addr.
iabuf,
1995 addr.
len, file, line);
1999 unsigned len,
const char *
file,
int line)
2003 return lease_id_hash_lookup (lp, lease_uid_hash, uid, len, file, line);
2007 const unsigned char *hwaddr,
unsigned hwlen,
2020 return (lease_id_hash_lookup(lp, lease_hw_addr_hash, hwaddr, hwlen,
2037 static isc_boolean_t
2038 client_lease_preferred(
struct lease *cand,
struct lease *lease)
2075 struct lease *head = NULL;
2076 struct lease *cand = NULL;
2077 struct lease *prev = NULL;
2078 struct lease *
next = NULL;
2082 lease_id_hash_add(lease_uid_hash, lease->
uid, lease->
uid_len,
2092 lease_reference(&cand, head,
MDL);
2093 while (cand != NULL) {
2094 if (client_lease_preferred(cand, lease))
2098 lease_dereference(&prev,
MDL);
2099 lease_reference(&prev, cand,
MDL);
2101 if (cand->
n_uid != NULL)
2102 lease_reference(&next, cand->
n_uid,
MDL);
2104 lease_dereference(&cand,
MDL);
2107 lease_reference(&cand, next,
MDL);
2108 lease_dereference(&next,
MDL);
2116 lease_reference(&lease->
n_uid, head,
MDL);
2117 lease_id_hash_delete(lease_uid_hash, lease->
uid,
2119 lease_id_hash_add(lease_uid_hash, lease->
uid,
2122 if(prev->
n_uid != NULL) {
2125 lease_dereference(&prev->
n_uid,
MDL);
2127 lease_reference(&prev->
n_uid, lease,
MDL);
2129 lease_dereference(&prev,
MDL);
2133 lease_dereference(&cand,
MDL);
2134 lease_dereference(&head,
MDL);
2141 struct lease *lease;
2143 struct lease *head = (
struct lease *)0;
2149 lease_dereference (&lease ->
n_uid,
MDL);
2156 if (head == lease) {
2157 lease_id_hash_delete(lease_uid_hash, lease->uid,
2158 lease->uid_len,
MDL);
2159 if (lease ->
n_uid) {
2160 lease_id_hash_add(lease_uid_hash, lease->n_uid->uid,
2161 lease->n_uid->uid_len, lease->n_uid,
2163 lease_dereference (&lease ->
n_uid,
MDL);
2169 for (scan = head; scan ->
n_uid; scan = scan ->
n_uid) {
2170 if (scan ->
n_uid == lease) {
2171 lease_dereference (&scan ->
n_uid,
MDL);
2172 if (lease ->
n_uid) {
2173 lease_reference (&scan ->
n_uid,
2175 lease_dereference (&lease ->
n_uid,
2182 lease_dereference (&head,
MDL);
2192 struct lease *head = NULL;
2193 struct lease *cand = NULL;
2194 struct lease *prev = NULL;
2195 struct lease *
next = NULL;
2208 lease_id_hash_add(lease_hw_addr_hash,
2219 lease_reference(&cand, head,
MDL);
2220 while (cand != NULL) {
2221 if (client_lease_preferred(cand, lease))
2225 lease_dereference(&prev,
MDL);
2226 lease_reference(&prev, cand,
MDL);
2228 if (cand->
n_hw != NULL)
2229 lease_reference(&next, cand->
n_hw,
MDL);
2231 lease_dereference(&cand,
MDL);
2234 lease_reference(&cand, next,
MDL);
2235 lease_dereference(&next,
MDL);
2243 lease_reference(&lease->
n_hw, head,
MDL);
2244 lease_id_hash_delete(lease_hw_addr_hash,
2247 lease_id_hash_add(lease_hw_addr_hash,
2252 if(prev->
n_hw != NULL) {
2253 lease_reference(&lease->
n_hw, prev->
n_hw,
2255 lease_dereference(&prev->
n_hw,
MDL);
2257 lease_reference(&prev->
n_hw, lease,
MDL);
2259 lease_dereference(&prev,
MDL);
2263 lease_dereference(&cand,
MDL);
2264 lease_dereference(&head,
MDL);
2271 struct lease *lease;
2273 struct lease *head = (
struct lease *)0;
2274 struct lease *
next = (
struct lease *)0;
2280 if ((lease->hardware_addr.hlen == 1) &&
2288 lease_dereference (&lease ->
n_hw,
MDL);
2295 if (head == lease) {
2296 lease_id_hash_delete(lease_hw_addr_hash,
2297 lease->hardware_addr.hbuf,
2298 lease->hardware_addr.hlen,
MDL);
2300 lease_id_hash_add(lease_hw_addr_hash,
2301 lease->n_hw->hardware_addr.hbuf,
2302 lease->n_hw->hardware_addr.hlen,
2304 lease_dereference(&lease->n_hw,
MDL);
2310 while (head ->
n_hw) {
2311 if (head ->
n_hw == lease) {
2312 lease_dereference (&head ->
n_hw,
MDL);
2313 if (lease ->
n_hw) {
2314 lease_reference (&head ->
n_hw,
2316 lease_dereference (&lease ->
n_hw,
2321 lease_reference (&next, head ->
n_hw,
MDL);
2322 lease_dereference (&head,
MDL);
2323 lease_reference (&head, next,
MDL);
2324 lease_dereference (&next,
MDL);
2328 lease_dereference (&head,
MDL);
2337 int num_written = 0, i;
2340 for (s = shared_networks; s; s = s->
next) {
2350 for (l = *(lptr[i]); l; l = l->
next) {
2351 #if !defined (DEBUG_DUMP_ALL_LEASES)
2365 log_info (
"Wrote %d leases to leases file.", num_written);
2385 for (cp = colp->
classes ; cp ; cp = cp->
nic) {
2387 (
unsigned char *)cp->
name,
2393 log_info (
"Wrote %d class decls to leases file.",
2403 hb; hb = hb ->
next) {
2414 log_info (
"Wrote %d group decls to leases file.", num_written);
2418 if (host_name_hash) {
2420 for (i = 0; i < host_name_hash -> hash_count; i++) {
2421 for (hb = host_name_hash -> buckets [i];
2422 hb; hb = hb -> next) {
2432 log_info (
"Wrote %d deleted host decls to leases file.",
2437 if (host_name_hash) {
2439 for (i = 0; i < host_name_hash -> hash_count; i++) {
2440 for (hb = host_name_hash -> buckets [i];
2441 hb; hb = hb -> next) {
2449 log_info (
"Wrote %d new dynamic host decls to leases file.",
2453 #if defined (FAILOVER_PROTOCOL)
2491 struct lease **lq, *prev, *lp;
2492 static struct lease **last_lq = NULL;
2493 static struct lease *last_insert_point = NULL;
2512 lq = &comp ->
pool -> active;
2519 lq = &comp ->
pool -> expired;
2520 #if defined(FAILOVER_PROTOCOL)
2544 lq = &comp ->
pool -> abandoned;
2559 log_error (
"Lease with bogus binding state: %d",
2561 #if defined (BINDING_STATE_DEBUG)
2572 if ((server_starting &
SS_QFOLLOW) && (lq == last_lq) &&
2573 (comp != last_insert_point) &&
2575 prev = last_insert_point;
2583 for (; lp ; lp = lp->
next) {
2591 lease_reference (&comp ->
next, prev ->
next,
MDL);
2592 lease_dereference (&prev ->
next,
MDL);
2594 lease_reference (&prev ->
next, comp,
MDL);
2597 lease_reference (&comp ->
next, *lq,
MDL);
2598 lease_dereference (lq,
MDL);
2600 lease_reference (lq, comp,
MDL);
2602 last_insert_point = comp;
2614 struct lease *lease = object;
2615 struct class *
class;
2619 if (!lease ->
pool) {
2620 lease_ip_hash_delete(lease_ip_addr_hash, lease->
ip_addr.
iabuf,
2622 return ISC_R_SUCCESS;
2632 return ISC_R_SUCCESS;
2640 if (lease -> hardware_addr.hlen) {
2645 if (lease -> billing_class) {
2646 class = (struct class *)0;
2647 class_reference (&
class, lease -> billing_class,
MDL);
2648 class_dereference (&lease -> billing_class,
MDL);
2656 class_dereference (&
class,
MDL);
2658 return ISC_R_SUCCESS;
2688 for (s = shared_networks; s; s = s ->
next) {
2689 for (p = s ->
pools; p; p = p ->
next) {
2692 p -> lease_count = 0;
2693 p -> free_leases = 0;
2694 p -> backup_leases = 0;
2704 for (l = *(lptr [i]); l; l = l ->
next) {
2721 #if defined (FAILOVER_PROTOCOL)
2722 if (p -> failover_peer &&
2735 server_starting = 0;
2748 for (n = subnets; n; n = n -> next_subnet) {
2754 for (s = shared_networks; s; s = s ->
next) {
2756 for (p = s ->
pools; p; p = p ->
next) {
2765 for (l = *(lptr [i]); l; l = l ->
next) {
2776 lease_reference, lease_dereference,
do_id_hash)
2782 #if defined (DEBUG_MEMORY_LEAKAGE) && \
2783 defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
2796 #if defined (COMPACT_LEASES)
2797 extern struct lease *lease_hunks;
2800 void free_everything(
void)
2805 struct pool *pc = (
struct pool *)0, *pn = (
struct pool *)0;
2806 struct lease *lc = (
struct lease *)0, *ln = (
struct lease *)0;
2809 struct class *cc = (
struct class *)0, *cn = (
struct class *)0;
2814 if (host_hw_addr_hash)
2815 host_free_hash_table (&host_hw_addr_hash,
MDL);
2816 host_hw_addr_hash = 0;
2818 host_free_hash_table (&host_uid_hash,
MDL);
2821 lease_id_free_hash_table (&lease_uid_hash,
MDL);
2823 if (lease_ip_addr_hash)
2824 lease_ip_free_hash_table (&lease_ip_addr_hash,
MDL);
2825 lease_ip_addr_hash = 0;
2826 if (lease_hw_addr_hash)
2827 lease_id_free_hash_table (&lease_hw_addr_hash,
MDL);
2828 lease_hw_addr_hash = 0;
2830 host_free_hash_table (&host_name_hash,
MDL);
2833 dns_zone_free_hash_table (&dns_zone_hash,
MDL);
2836 while (host_id_info != NULL) {
2840 tmp = host_id_info->
next;
2846 auth_key_free_hash_table (&auth_key_hash,
MDL);
2858 class_reference (&cc, cn,
MDL);
2859 class_dereference (&cn,
MDL);
2862 class_reference (&cn, cc -> nic,
MDL);
2863 class_dereference (&cc -> nic,
MDL);
2867 class_free_hash_table (&cc -> hash,
MDL);
2870 class_dereference (&cc,
MDL);
2872 class_dereference (&lp -> classes,
MDL);
2876 if (interface_vector) {
2878 if (interface_vector [i])
2879 interface_dereference (&interface_vector [i],
MDL);
2882 interface_vector = 0;
2889 interface_reference (&ic, in,
MDL);
2890 interface_dereference (&in,
MDL);
2893 interface_reference (&in, ic -> next,
MDL);
2894 interface_dereference (&ic -> next,
MDL);
2899 interface_dereference
2903 interface_dereference (&ic,
MDL);
2910 subnet_reference (&sn, subnets,
MDL);
2913 subnet_reference (&sc, sn,
MDL);
2914 subnet_dereference (&sn,
MDL);
2916 if (sc -> next_subnet) {
2917 subnet_reference (&sn, sc -> next_subnet,
MDL);
2918 subnet_dereference (&sc -> next_subnet,
MDL);
2920 if (sc -> next_sibling)
2921 subnet_dereference (&sc -> next_sibling,
MDL);
2925 if (sc -> interface)
2926 interface_dereference (&sc -> interface,
MDL);
2927 subnet_dereference (&sc,
MDL);
2929 subnet_dereference (&subnets,
MDL);
2938 if (shared_networks) {
2939 shared_network_dereference (&shared_networks,
MDL);
2942 shared_network_reference (&nn, shared_networks,
MDL);
2945 shared_network_reference (&nc, nn,
MDL);
2946 shared_network_dereference (&nn,
MDL);
2949 shared_network_reference (&nn, nc -> next,
MDL);
2950 shared_network_dereference (&nc -> next,
MDL);
2955 pool_reference (&pn, nc ->
pools,
MDL);
2960 pool_reference (&pc, pn,
MDL);
2961 pool_dereference (&pn,
MDL);
2964 pool_reference (&pn, pc ->
next,
MDL);
2965 pool_dereference (&pc ->
next,
MDL);
2978 lease_reference (&ln, *lptr [i],
MDL);
2981 lease_reference (&lc, ln,
MDL);
2982 lease_dereference (&ln,
MDL);
2985 lease_reference (&ln, lc ->
next,
MDL);
2986 lease_dereference (&lc ->
next,
MDL);
2995 lease_dereference (&lc -> n_hw,
MDL);
2997 lease_dereference (&lc -> n_uid,
MDL);
2998 lease_dereference (&lc,
MDL);
3000 lease_dereference (lptr [i],
MDL);
3008 pool_dereference (&pc,
MDL);
3010 pool_dereference (&nc ->
pools,
MDL);
3015 shared_network_dereference (&nc,
MDL);
3017 shared_network_dereference (&shared_networks,
MDL);
3022 relinquish_ackqueue();
3036 universe_free_hash_table (&universe_hash,
MDL);
3044 if (universes [i]) {
3045 if (universes[i]->name_hash)
3046 option_name_free_hash_table(
3047 &universes[i]->name_hash,
3049 if (universes[i]->code_hash)
3050 option_code_free_hash_table(
3051 &universes[i]->code_hash,
3054 if (universes [i] -> name > (
char *)&end) {
3055 foo.c = universes [i] -> name;
3058 if (universes [i] > (
struct universe *)&end)
3065 relinquish_free_lease_states ();
3066 relinquish_free_pairs ();
3067 relinquish_free_expressions ();
3068 relinquish_free_binding_values ();
3069 relinquish_free_option_caches ();
3070 relinquish_free_packets ();
3071 #if defined(COMPACT_LEASES)
#define GROUP_OBJECT_DYNAMIC
int executable_statement_reference(struct executable_statement **ptr, struct executable_statement *bp, const char *file, int line)
void enter_shared_network(struct shared_network *share)
struct lease * new_leases(unsigned, const char *, int)
struct binding_scope * global_scope
lease_ip_hash_t * lease_ip_addr_hash
struct universe * universe
int subnet_inner_than(const struct subnet *subnet, const struct subnet *scan, int warnp)
void uid_hash_add(struct lease *lease)
struct host_id_info host_id_info_t
lease_id_hash_t * lease_hw_addr_hash
int executable_statement_dereference(struct executable_statement **ptr, const char *file, int line)
const char * piaddr(const struct iaddr addr)
unsigned do_id_hash(const void *, unsigned, unsigned)
void release_lease(struct lease *lease, struct packet *packet)
struct executable_statement * default_classification_rules
int find_host_for_network(struct subnet **sp, struct host_decl **host, struct iaddr *addr, struct shared_network *share)
int unbill_class(struct lease *lease, struct class *class)
void abandon_lease(struct lease *lease, const char *message)
void * dmalloc(unsigned, const char *, int)
struct lease_state * state
int executable_statement_foreach(struct executable_statement *stmt, int(*callback)(structexecutable_statement *, void *, int), void *vp, int condp)
int execute_statements(struct binding_value **result, struct packet *packet, struct lease *lease, struct client_state *client_state, struct option_state *in_options, struct option_state *out_options, struct binding_scope **scope, struct executable_statement *statements, struct on_star *on_star)
void dhcp_failover_pool_check(struct pool *)
struct iaddr ip_addr(struct iaddr subnet, struct iaddr mask, u_int32_t host_address)
isc_result_t unlink_class(struct class **class)
#define HOST_DECL_DYNAMIC
#define print_hex_1(len, data, limit)
#define DHCP_R_INVALIDARG
void print_lease(struct lease *lease)
#define HASH_FUNCTIONS(name, bufarg, type, hashtype, ref, deref, hasher)
#define CLASS_DECL_DELETED
int int int log_debug(const char *,...) __attribute__((__format__(__printf__
omapi_object_type_t * dhcp_type_lease
int lease_enqueue(struct lease *comp)
enum executable_statement::statement_op op
void omapi_type_relinquish(void)
struct executable_statement * on_release
void pool_timer(void *vpool)
int option_reference(struct option **dest, struct option *src, const char *file, int line)
struct universe dhcp_universe
int supersede_lease(struct lease *comp, struct lease *lease, int commit, int propogate, int pimmediate)
void data_string_forget(struct data_string *data, const char *file, int line)
struct class * billing_class
struct group * root_group
int find_lease_by_ip_addr(struct lease **lp, struct iaddr addr, const char *file, int line)
int log_error(const char *,...) __attribute__((__format__(__printf__
struct collection * collections
#define HOST_DECL_DELETED
void cancel_all_timeouts(void)
int binding_scope_dereference(struct binding_scope **ptr, const char *file, int line)
void add_timeout(struct timeval *when, void(*)(void *) where, void *what, tvref_t ref, tvunref_t unref)
void relinquish_lease_hunks(void)
dhcp_failover_state_t * failover_peer
struct shared_network * shared_networks
struct data_string client_identifier
const char * binding_state_print(enum failover_state state)
struct option_state * options
void make_binding_state_transition(struct lease *lease)
void log_fatal(const char *,...) __attribute__((__format__(__printf__
isc_result_t omapi_object_initialize(omapi_object_t *, omapi_object_type_t *, size_t, size_t, const char *, int)
isc_result_t omapi_io_state_foreach(isc_result_t(*func)(omapi_object_t *, void *), void *p)
calls a given function on every object
isc_result_t delete_host(struct host_decl *hd, int commit)
void enter_lease(struct lease *lease)
isc_result_t delete_class(struct class *cp, int commit)
void free_lease_state(struct lease_state *, const char *, int)
universe_hash_t * universe_hash
struct hardware hardware_addr
struct iaddr subnet_number(struct iaddr addr, struct iaddr mask)
void relinquish_timeouts(void)
int lease_copy(struct lease **lp, struct lease *lease, const char *file, int line)
#define FAILOVER_PROTOCOL
int find_hosts_by_uid(struct host_decl **hp, const unsigned char *data, unsigned len, const char *file, int line)
void hw_hash_delete(struct lease *lease)
int evaluate_option_cache(struct data_string *result, struct packet *packet, struct lease *lease, struct client_state *client_state, struct option_state *in_options, struct option_state *cfg_options, struct binding_scope **scope, struct option_cache *oc, const char *file, int line)
struct host_id_info * next
int write_host(struct host_decl *host)
int option_chain_head_dereference(struct option_chain_head **ptr, const char *file, int line)
void new_address_range(struct parse *cfile, struct iaddr low, struct iaddr high, struct subnet *subnet, struct pool *pool, struct lease **lpchain)
unsigned do_string_hash(const void *, unsigned, unsigned)
binding_state_t binding_state
int find_grouped_subnet(struct subnet **sp, struct shared_network *share, struct iaddr addr, const char *file, int line)
int buffer_allocate(struct buffer **ptr, unsigned len, const char *file, int line)
struct option_cache * option
int write_lease(struct lease *lease)
int group_dereference(struct group **ptr, const char *file, int line)
void trace_free_all(void)
isc_result_t omapi_object_dereference(omapi_object_t **, const char *, int)
void(* tvref_t)(void *, void *, const char *, int)
void dfree(void *, const char *, int)
int find_lease_by_uid(struct lease **lp, const unsigned char *uid, unsigned len, const char *file, int line)
struct host_decl * n_ipaddr
int option_chain_head_reference(struct option_chain_head **ptr, struct option_chain_head *bp, const char *file, int line)
struct option_cache * lookup_option(struct universe *universe, struct option_state *options, unsigned code)
int int log_info(const char *,...) __attribute__((__format__(__printf__
isc_result_t write_named_billing_class(const void *, unsigned, void *)
#define GROUP_OBJECT_DELETED
struct interface_info * interfaces
int addr_eq(struct iaddr addr1, struct iaddr addr2)
unsigned do_ip4_hash(const void *, unsigned, unsigned)
int write_group(struct group_object *)
omapi_object_type_t * dhcp_type_host
struct subnet * next_subnet
void(* tvunref_t)(void *, const char *, int)
union executable_statement::@7 data
dhcp_control_object_t * dhcp_control_object
isc_result_t enter_class(struct class *cd, int dynamicp, int commit)
struct universe ** universes
host_hash_t * host_hw_addr_hash
u_int32_t host_addr(struct iaddr addr, struct iaddr mask)
isc_result_t ddns_removals(struct lease *, struct iasubopt *, struct dhcp_ddns_cb *, isc_boolean_t)
enum dhcp_shutdown_state shutdown_state
host_hash_t * host_name_hash
int binding_scope_reference(struct binding_scope **ptr, struct binding_scope *bp, const char *file, int line)
int hash_foreach(struct hash_table *, hash_foreach_func)
binding_state_t rewind_binding_state
struct interface_info * next
isc_result_t dhcp_io_shutdown(omapi_object_t *, void *)
void hw_hash_add(struct lease *lease)
host_hash_t * values_hash
int find_subnet(struct subnet **sp, struct iaddr addr, const char *file, int line)
int dhcp_failover_queue_update(struct lease *, int)
isc_result_t find_class(struct class **c, const char *s, const char *file, int line)
isc_result_t omapi_unregister_io_object(omapi_object_t *)
binding_state_t desired_binding_state
void relinquish_hash_bucket_hunks(void)
struct subnet * next_sibling
dns_zone_hash_t * dns_zone_hash
int dhcp_failover_write_all_states(void)
lease_id_hash_t * lease_uid_hash
void change_host_uid(struct host_decl *host, const char *uid, int len)
group_hash_t * group_name_hash
int find_lease_by_hw_addr(struct lease **lp, const unsigned char *hwaddr, unsigned hwlen, const char *file, int line)
int find_hosts_by_option(struct host_decl **hp, struct packet *packet, struct option_state *opt_state, const char *file, int line)
void enter_subnet(struct subnet *subnet)
u_int8_t hbuf[HARDWARE_ADDR_LEN+1]
isc_result_t lease_instantiate(const void *key, unsigned len, void *object)
struct ipv6_pool ** pools
const char * binding_state_names[]
struct executable_statement * on_expiry
struct shared_network * next
host_hash_t * host_uid_hash
int find_hosts_by_haddr(struct host_decl **hp, int htype, const unsigned char *haddr, unsigned hlen, const char *file, int line)
#define DHO_DHCP_CLIENT_IDENTIFIER
int bill_class(struct lease *, struct class *)
struct interface_info ** interface_vector
struct executable_statement * on_commit
const unsigned char * data
struct binding_scope * scope
struct hardware interface
int parse_warn(struct parse *cfile, const char *fmt,...)
void uid_hash_delete(struct lease *lease)
binding_state_t next_binding_state
void new_shared_network_interface(struct parse *cfile, struct shared_network *share, const char *name)
#define GROUP_OBJECT_STATIC
#define INTERFACE_REQUESTED
int option_dereference(struct option **dest, const char *file, int line)
struct packet * dhcpv6_container_packet
isc_result_t enter_host(struct host_decl *hd, int dynamicp, int commit)