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 &&
137 log_error (
"dhcp client identifier may not be %s",
138 "specified conditionally.");
139 }
else if (!(*evp)) {
143 log_error (
"only one dhcp client identifier may be %s",
152 find_host_id_info(
unsigned int option_code,
int relays) {
155 for (p = host_id_info; p != NULL; p = p->
next) {
167 print_host(
const void *
name,
unsigned len,
void *value) {
169 printf(
"--------------\n");
171 printf(
"len:%d\n", len);
173 printf(
"host @%p is '%s'\n", h, h->
name);
174 return ISC_R_SUCCESS;
180 printf(
"--------------\n");
187 if (host_uid_hash == NULL) {
189 log_fatal(
"Can't allocate host/uid hash");
197 host_hash_delete(host_uid_hash,
232 if (!host_name_hash) {
234 log_fatal (
"Can't allocate host name hash");
235 host_hash_add (host_name_hash,
236 (
unsigned char *)hd -> name,
237 strlen (hd -> name), hd,
MDL);
239 host_hash_lookup (&hp, host_name_hash,
240 (
unsigned char *)hd -> name,
241 strlen (hd -> name),
MDL);
245 host_hash_delete (host_name_hash,
246 (
unsigned char *)hd -> name,
247 strlen (hd -> name),
MDL);
253 host_dereference (&hp,
MDL);
258 if (hp && hp == hd) {
259 host_dereference (&hp,
MDL);
262 return ISC_R_IOERROR;
263 hd -> flags &= ~HOST_DECL_DELETED;
269 host_hash_add (host_name_hash,
270 (
unsigned char *)hd -> name,
271 strlen (hd -> name), hd,
MDL);
275 host_dereference (&hp,
MDL);
281 host_dereference (&hd -> n_ipaddr,
MDL);
286 if (hd -> interface.hlen) {
287 if (!host_hw_addr_hash) {
288 if (!host_new_hash(&host_hw_addr_hash,
290 log_fatal (
"Can't allocate host/hw hash");
294 host_hash_lookup (&hp, host_hw_addr_hash,
295 hd -> interface.hbuf,
296 hd -> interface.hlen,
MDL);
299 host_hash_add (host_hw_addr_hash, hd -> interface.hbuf,
300 hd -> interface.hlen, hd,
MDL);
305 for (np = hp; np -> n_ipaddr; np = np -> n_ipaddr)
307 host_reference (&np -> n_ipaddr, hd,
MDL);
308 host_dereference (&hp,
MDL);
317 find_uid_statement, &esp, 0)) {
319 NULL, NULL, NULL, NULL, NULL,
326 if (hd -> client_identifier.len) {
329 if (!host_uid_hash) {
330 if (!host_new_hash(&host_uid_hash,
332 log_fatal (
"Can't allocate host/uid hash");
334 host_hash_add (host_uid_hash,
335 hd -> client_identifier.data,
336 hd -> client_identifier.len,
342 if (host_hash_lookup (&hp, host_uid_hash,
343 hd -> client_identifier.data,
344 hd -> client_identifier.len,
348 for (np = hp; np -> n_ipaddr;
349 np = np -> n_ipaddr) {
354 host_reference (&np -> n_ipaddr,
357 host_dereference (&hp,
MDL);
359 host_hash_add (host_uid_hash,
360 hd -> client_identifier.data,
361 hd -> client_identifier.len,
371 if (hd->host_id_option != NULL) {
376 h_id_info = find_host_id_info(hd->host_id_option->code,
378 if (h_id_info == NULL) {
380 if (h_id_info == NULL) {
381 log_fatal(
"No memory for host-identifier "
382 "option information.");
385 hd->host_id_option,
MDL);
388 log_fatal(
"No memory for host-identifier "
391 h_id_info->
relays = hd->relays;
392 h_id_info->
next = host_id_info;
393 host_id_info = h_id_info;
397 hd->host_id.data, hd->host_id.len,
MDL)) {
417 host_dereference(&hp,
MDL);
426 if (dynamicp && commit) {
428 return ISC_R_IOERROR;
430 return ISC_R_IOERROR;
433 return ISC_R_SUCCESS;
449 return ISC_R_IOERROR;
455 if (cp->superclass) {
456 class_hash_delete(cp->superclass->hash,
457 (
const char *)cp->hash_string.data,
465 return ISC_R_SUCCESS;
476 int hw_head = 0, uid_head = 1;
480 return ISC_R_SUCCESS;
486 if (host_hw_addr_hash) {
487 if (host_hash_lookup (&hp, host_hw_addr_hash,
491 host_hash_delete (host_hw_addr_hash,
498 host_reference (&foo, hp,
MDL);
503 host_dereference (&np,
MDL);
504 host_reference (&np, foo,
MDL);
505 host_dereference (&foo,
MDL);
515 host_dereference (&foo,
MDL);
518 host_dereference (&np,
MDL);
520 host_dereference (&hp,
MDL);
529 if (host_hash_lookup (&hp, host_uid_hash,
533 host_hash_delete (host_uid_hash,
540 host_reference (&foo, hp,
MDL);
545 host_dereference (&np,
MDL);
546 host_reference (&np, foo,
MDL);
547 host_dereference (&foo,
MDL);
557 host_dereference (&foo,
MDL);
560 host_dereference (&np,
MDL);
562 host_dereference (&hp,
MDL);
567 if (hd->host_id_option != NULL) {
581 host_hash_add (host_hw_addr_hash,
589 if (host_name_hash) {
590 if (host_hash_lookup (&hp, host_name_hash,
591 (
unsigned char *)hd -> name,
592 strlen (hd -> name),
MDL)) {
594 host_hash_delete (host_name_hash,
595 (
unsigned char *)hd -> name,
596 strlen (hd -> name),
MDL);
598 host_dereference (&hp,
MDL);
604 return ISC_R_IOERROR;
606 return ISC_R_IOERROR;
608 return ISC_R_SUCCESS;
612 const unsigned char *haddr,
unsigned hlen,
616 #if defined(LDAP_CONFIGURATION)
619 if ((ret = find_haddr_in_ldap (hp, htype, hlen, haddr, file, line)))
625 memcpy (&h.
hbuf [1], haddr, hlen);
627 return host_hash_lookup (hp, host_hw_addr_hash,
632 const unsigned char *data,
unsigned len,
635 return host_hash_lookup (hp, host_uid_hash, data, len, file, line);
647 struct packet *relay_packet;
650 #if defined(LDAP_CONFIGURATION)
651 if ((found = find_client_in_ldap (hp, packet, opt_state, file, line)))
655 for (p = host_id_info; p != NULL; p = p->
next) {
656 relay_packet = packet;
657 relay_state = opt_state;
677 relay_state = relay_packet->
options;
683 memset(&data, 0,
sizeof(data));
686 NULL, relay_state, NULL,
689 log_error(
"Error evaluating option cache");
719 struct iaddr ip_address;
723 memset (&fixed_addr, 0,
sizeof fixed_addr);
725 for (hp = *host; hp; hp = hp -> n_ipaddr) {
726 if (!hp -> fixed_addr)
734 hp -> fixed_addr,
MDL))
736 for (i = 0; i < fixed_addr.
len; i += 4) {
738 memcpy (ip_address.
iabuf,
739 fixed_addr.
data + i, 4);
748 host_reference (&tmp, *host,
MDL);
749 host_dereference (host,
MDL);
750 host_reference (host, hp,
MDL);
751 host_dereference (&tmp,
MDL);
763 struct
iaddr low, high;
766 struct
lease **lpchain;
768 #if defined(COMPACT_LEASES)
769 struct lease *address_range;
772 unsigned min, max, i, num_addrs;
773 char lowbuf [16], highbuf [16], netbuf [16];
776 #if !defined(COMPACT_LEASES)
782 strcpy (netbuf,
piaddr (subnet -> net));
783 log_fatal (
"No shared network for network %s (%s)",
784 netbuf,
piaddr (subnet -> netmask));
788 if (!lease_uid_hash) {
790 log_fatal (
"Can't allocate lease/uid hash");
792 if (!lease_ip_addr_hash) {
795 log_fatal (
"Can't allocate lease/ip hash");
797 if (!lease_hw_addr_hash) {
800 log_fatal (
"Can't allocate lease/hw hash");
805 strcpy(lowbuf,
piaddr(low));
807 log_fatal(
"bad range, address %s not in subnet %s netmask %s",
812 strcpy(highbuf,
piaddr(high));
814 log_fatal(
"bad range, address %s not in subnet %s netmask %s",
819 max =
host_addr (high, subnet -> netmask);
820 min =
host_addr (low, subnet -> netmask);
825 min =
host_addr (high, subnet -> netmask);
832 num_addrs = max - min + 1;
833 #if defined (BINARY_LEASES)
838 #if defined (COMPACT_LEASES)
839 s = (num_addrs + 1) *
sizeof (
struct lease);
843 if (((s %
sizeof (
struct lease)) != 0) ||
844 ((s /
sizeof (
struct lease)) != (num_addrs + 1))) {
845 strcpy (lowbuf,
piaddr (low));
846 strcpy (highbuf,
piaddr (high));
847 parse_warn (cfile,
"%s-%s is an overly large address range.",
852 if (!address_range) {
853 strcpy (lowbuf,
piaddr (low));
854 strcpy (highbuf,
piaddr (high));
855 log_fatal (
"No memory for address range %s-%s.",
861 for (i = 0; i < num_addrs; i++) {
863 #if defined (COMPACT_LEASES)
867 lease_reference (&lp, &address_range [i],
MDL);
869 status = lease_allocate (&lp,
MDL);
870 if (status != ISC_R_SUCCESS)
875 isc_result_totext (status));
880 subnet_reference(&lp->
subnet, subnet,
MDL);
881 pool_reference(&lp->
pool, pool,
MDL);
891 "lease %s is declared twice!",
894 pool_reference (< -> pool, pool,
MDL);
895 lease_dereference (<,
MDL);
897 lease_ip_hash_add(lease_ip_addr_hash,
903 lease_reference (&lp ->
next, *lpchain,
MDL);
904 lease_dereference (lpchain,
MDL);
906 lease_reference (lpchain, lp,
MDL);
908 lease_dereference (&lp,
MDL);
919 if (subnet_reference (sp, rv,
920 file, line) != ISC_R_SUCCESS)
934 for (rv = share -> subnets; rv; rv = rv ->
next_sibling) {
936 if (subnet_reference (sp, rv,
937 file, line) != ISC_R_SUCCESS)
948 const struct subnet *scan,
952 char n1buf[
sizeof(
"ffff:ffff:ffff:ffff:ffff:ffff:255.255.255")];
954 for (i = 0; i < 128; i++)
958 for (j = 0; j < 128; j++)
964 log_error(
"Warning: subnet %s/%d overlaps subnet %s/%d",
978 struct subnet *scan = (
struct subnet *)0;
979 struct subnet *next = (
struct subnet *)0;
980 struct subnet *prev = (
struct subnet *)0;
984 subnet_reference (&next, subnets,
MDL);
986 subnet_reference (&scan, next,
MDL);
987 subnet_dereference (&next,
MDL);
997 subnet_dereference (&prev,
MDL);
999 subnet_dereference (&subnets,
MDL);
1000 subnet_reference (&subnets, subnet,
MDL);
1003 subnet_dereference (&scan,
MDL);
1006 subnet_reference (&prev, scan,
MDL);
1007 subnet_dereference (&scan,
MDL);
1010 subnet_dereference (&prev,
MDL);
1015 subnet_dereference (&subnets,
MDL);
1017 subnet_reference (&subnets, subnet,
MDL);
1025 if (shared_networks) {
1026 shared_network_reference (&share -> next,
1027 shared_networks,
MDL);
1028 shared_network_dereference (&shared_networks,
MDL);
1030 shared_network_reference (&shared_networks, share,
MDL);
1034 struct
parse *cfile;
1039 isc_result_t status;
1041 if (share -> interface) {
1043 "A subnet or shared network can't be connected %s",
1044 "to two interfaces.");
1049 if (!strcmp (ip -> name, name))
1052 status = interface_allocate (&ip,
MDL);
1053 if (status != ISC_R_SUCCESS)
1054 log_fatal (
"new_shared_network_interface %s: %s",
1055 name, isc_result_totext (status));
1056 if (strlen (name) >
sizeof ip -> name) {
1057 memcpy (ip -> name, name, (
sizeof ip -> name) - 1);
1058 ip -> name [(
sizeof ip ->
name) - 1] = 0;
1060 strcpy (ip -> name, name);
1069 interface_reference (&share -> interface, ip,
MDL);
1082 struct lease *comp = (
struct lease *)0;
1085 if (!comp ->
pool) {
1086 log_error (
"undeclared lease found in database: %s",
1089 pool_reference (&lease ->
pool, comp ->
pool,
MDL);
1092 subnet_reference (&lease ->
subnet,
1094 lease_ip_hash_delete(lease_ip_addr_hash,
1095 lease->ip_addr.iabuf, lease->ip_addr.len,
1097 lease_dereference (&comp,
MDL);
1113 lease_ip_hash_add(lease_ip_addr_hash, lease->ip_addr.iabuf,
1114 lease->ip_addr.len, lease,
MDL);
1131 #if defined (FAILOVER_PROTOCOL)
1132 int do_pool_check = 0;
1137 if (pimmediate && !commit)
1161 (((comp -> uid && lease -> uid) &&
1162 (comp -> uid_len != lease -> uid_len ||
1163 memcmp (comp -> uid, lease -> uid, comp -> uid_len))) ||
1165 ((comp -> hardware_addr.hlen !=
1166 lease -> hardware_addr.hlen) ||
1167 memcmp (comp -> hardware_addr.hbuf,
1168 lease -> hardware_addr.hbuf,
1169 comp -> hardware_addr.hlen))))) {
1178 if (comp->uid != comp->uid_buf) {
1183 comp -> uid = (
unsigned char *)0;
1189 if (comp->hardware_addr.hlen)
1193 if (comp -> billing_class != lease -> billing_class) {
1194 if (comp->billing_class)
1196 if (lease -> billing_class)
1201 comp -> starts = lease -> starts;
1203 if (lease -> uid_len <=
sizeof (lease -> uid_buf)) {
1204 memcpy (comp -> uid_buf,
1205 lease -> uid, lease -> uid_len);
1206 comp -> uid = &comp -> uid_buf [0];
1207 comp -> uid_max =
sizeof comp -> uid_buf;
1208 comp -> uid_len = lease -> uid_len;
1209 }
else if (lease -> uid != &lease -> uid_buf [0]) {
1210 comp -> uid = lease -> uid;
1211 comp -> uid_max = lease -> uid_max;
1212 lease -> uid = (
unsigned char *)0;
1213 lease -> uid_max = 0;
1214 comp -> uid_len = lease -> uid_len;
1215 lease -> uid_len = 0;
1220 comp -> uid = (
unsigned char *)0;
1221 comp -> uid_len = comp -> uid_max = 0;
1224 host_dereference (&comp -> host,
MDL);
1225 host_reference (&comp -> host, lease -> host,
MDL);
1226 comp -> hardware_addr = lease -> hardware_addr;
1231 if (lease -> scope) {
1241 if (lease -> next_binding_state ==
FTS_ACTIVE ||
1250 if (comp -> client_hostname)
1251 dfree (comp -> client_hostname,
MDL);
1252 comp -> client_hostname = lease -> client_hostname;
1253 lease -> client_hostname = (
char *)0;
1255 if (lease->on_star.on_expiry) {
1256 if (comp->on_star.on_expiry)
1258 (&comp->on_star.on_expiry,
MDL);
1260 lease->on_star.on_expiry,
1263 if (lease->on_star.on_commit) {
1264 if (comp->on_star.on_commit)
1266 (&comp->on_star.on_commit,
MDL);
1268 lease->on_star.on_commit,
1271 if (lease->on_star.on_release) {
1272 if (comp->on_star.on_release)
1274 (&comp->on_star.on_release,
MDL);
1276 lease->on_star.on_release,
1285 if (comp->hardware_addr.hlen)
1288 comp->cltt = lease->cltt;
1289 #if defined (FAILOVER_PROTOCOL)
1290 comp->tstp = lease->tstp;
1291 comp->tsfp = lease->tsfp;
1292 comp->atsfp = lease->atsfp;
1294 comp->ends = lease->ends;
1295 comp->next_binding_state = lease->next_binding_state;
1304 if (lease->ddns_cb != NULL)
1305 comp->ddns_cb = lease->ddns_cb;
1308 #if defined (FAILOVER_PROTOCOL)
1318 if (!comp ->
pool) {
1319 log_error (
"Supersede_lease: lease %s with no pool.",
1325 switch (comp -> binding_state) {
1328 lq = &comp->pool->reserved;
1330 lq = &comp->pool->free;
1331 comp->pool->free_leases--;
1334 #if defined(FAILOVER_PROTOCOL)
1340 lq = &comp ->
pool -> active;
1346 lq = &comp ->
pool -> expired;
1350 lq = &comp ->
pool -> abandoned;
1355 lq = &comp->pool->reserved;
1357 lq = &comp->pool->backup;
1358 comp->pool->backup_leases--;
1361 #if defined(FAILOVER_PROTOCOL)
1367 log_error (
"Lease with bogus binding state: %d",
1368 comp -> binding_state);
1369 #if defined (BINDING_STATE_DEBUG)
1380 if (commit || !pimmediate)
1399 if ((commit || !pimmediate) &&
1402 (comp -> sort_time < comp ->
pool -> next_event_time ||
1404 comp ->
pool -> next_event_time = comp -> sort_time;
1405 tv . tv_sec = comp ->
pool -> next_event_time;
1414 #if defined(FAILOVER_PROTOCOL)
1424 if (propogate && (comp->pool->failover_peer != NULL) &&
1425 ((comp->pool->failover_peer->service_state ==
1427 (comp->pool->failover_peer->service_state ==
1429 comp->rewind_binding_state = comp->binding_state;
1434 if ((server_starting &
SS_NOSYNC) == 0) {
1440 #if defined (FAILOVER_PROTOCOL)
1442 comp -> desired_binding_state = comp -> binding_state;
1446 if (do_pool_check && comp->pool->failover_peer)
1456 if ((from_pool == 0) &&
1457 (commit || !pimmediate) &&
1459 (comp->next_binding_state != comp->binding_state))
1468 #if defined (FAILOVER_PROTOCOL)
1469 dhcp_failover_state_t *peer;
1471 if (lease ->
pool && lease ->
pool -> failover_peer)
1472 peer = lease ->
pool -> failover_peer;
1474 peer = (dhcp_failover_state_t *)0;
1479 if (lease -> next_binding_state != lease -> binding_state &&
1491 #if defined (NSUPDATE)
1516 if (lease -> client_hostname) {
1517 dfree (lease -> client_hostname,
MDL);
1518 lease -> client_hostname = (
char *)0;
1521 host_dereference (&lease -> host,
MDL);
1524 lease -> tstp = lease -> ends;
1529 if (lease -> next_binding_state != lease -> binding_state &&
1534 (lease -> next_binding_state ==
FTS_FREE ||
1535 lease -> next_binding_state ==
FTS_BACKUP)) ||
1540 #if defined (NSUPDATE)
1580 if (lease -> client_hostname) {
1581 dfree (lease -> client_hostname,
MDL);
1582 lease -> client_hostname = (
char *)0;
1585 host_dereference (&lease -> host,
MDL);
1589 lease -> tstp = lease -> ends;
1592 #if defined (DEBUG_LEASE_STATE_TRANSITIONS)
1593 log_debug (
"lease %s moves from %s to %s",
1599 lease -> binding_state = lease -> next_binding_state;
1600 switch (lease -> binding_state) {
1602 #if defined (FAILOVER_PROTOCOL)
1603 if (lease ->
pool && lease ->
pool -> failover_peer)
1607 lease -> next_binding_state =
FTS_FREE;
1615 #if defined(FAILOVER_PROTOCOL)
1620 if ((lease->
pool != NULL) &&
1631 lease -> next_binding_state = lease -> binding_state;
1634 #if defined (DEBUG_LEASE_STATE_TRANSITIONS)
1635 log_debug (
"lease %s: next binding state %s",
1646 struct lease *lt = (
struct lease *)0;
1647 isc_result_t status;
1649 status = lease_allocate (<,
MDL);
1650 if (status != ISC_R_SUCCESS)
1661 }
else if (!lease ->
uid_max) {
1662 lt ->
uid = (
unsigned char *)0;
1666 lease_dereference (<,
MDL);
1675 lease_dereference (<,
MDL);
1685 host_reference (< ->
host, lease ->
host, file, line);
1686 subnet_reference (< ->
subnet, lease ->
subnet, file, line);
1687 pool_reference (< ->
pool, lease ->
pool, file, line);
1711 status = lease_reference(lp, lt, file, line);
1712 lease_dereference(<,
MDL);
1713 return status == ISC_R_SUCCESS;
1723 #if defined (NSUPDATE)
1726 if (lease->on_star.on_release) {
1729 NULL, &lease->scope,
1730 lease->on_star.on_release, NULL);
1731 if (lease->on_star.on_release)
1733 (&lease->on_star.on_release,
MDL);
1739 if (lease->on_star.on_expiry)
1741 (&lease->on_star.on_expiry,
MDL);
1748 if (lease->on_star.on_commit)
1750 (&lease->on_star.on_commit,
MDL);
1763 #if defined (FAILOVER_PROTOCOL)
1764 if (lease ->
pool && lease ->
pool -> failover_peer) {
1765 dhcp_failover_state_t *peer = NULL;
1767 if (lease->pool != NULL)
1768 peer = lease->pool->failover_peer;
1771 (((peer->i_am == primary) &&
1772 (lease->rewind_binding_state ==
FTS_FREE)) ||
1773 ((peer->i_am == secondary) &&
1774 (lease->rewind_binding_state ==
FTS_BACKUP)))) {
1775 lease->next_binding_state =
1776 lease->rewind_binding_state;
1794 const
char *message;
1796 struct lease *lt = (
struct lease *)0;
1797 #if defined (NSUPDATE)
1810 log_error (
"Abandoning IP address %s: %s",
1815 lt ->
uid = (
unsigned char *)0;
1819 lease_dereference (<,
MDL);
1833 void dissociate_lease (
lease)
1836 struct lease *lt = (
struct lease *)0;
1837 #if defined (NSUPDATE)
1844 #if defined (FAILOVER_PROTOCOL)
1845 if (lease ->
pool && lease ->
pool -> failover_peer) {
1857 lt ->
uid = (
unsigned char *)0;
1861 lease_dereference (<,
MDL);
1870 struct lease *
next = NULL;
1871 struct lease *lease = NULL;
1872 struct lease *ltemp = NULL;
1873 #define FREE_LEASES 0
1874 #define ACTIVE_LEASES 1
1875 #define EXPIRED_LEASES 2
1876 #define ABANDONED_LEASES 3
1877 #define BACKUP_LEASES 4
1878 #define RESERVED_LEASES 5
1884 pool = (
struct pool *)vpool;
1898 #if defined (FAILOVER_PROTOCOL)
1899 if (pool->failover_peer &&
1915 (pool->failover_peer->i_am == secondary) &&
1916 (pool->failover_peer->me.state ==
normal))
1931 lease_dereference(&next,
MDL);
1934 lease_reference(&next, ltemp,
MDL);
1951 #if defined(FAILOVER_PROTOCOL)
1952 dhcp_failover_state_t *peer = NULL;
1954 if (lease->
pool != NULL)
1961 ((peer->i_am == primary &&
1964 (peer->i_am == secondary &&
1973 lease_dereference(&lease,
MDL);
1975 lease_reference(&lease, next,
MDL);
1978 lease_dereference(&next,
MDL);
1980 lease_dereference(&lease,
MDL);
1989 ((pool->next_event_time > next_expiry) ||
1990 (pool->next_event_time <=
cur_time))) {
1991 pool->next_event_time = next_expiry;
1992 tv.tv_sec = pool->next_event_time;
2007 return lease_ip_hash_lookup(lp, lease_ip_addr_hash, addr.
iabuf,
2008 addr.
len, file, line);
2012 unsigned len,
const char *
file,
int line)
2016 return lease_id_hash_lookup (lp, lease_uid_hash, uid, len, file, line);
2020 const unsigned char *hwaddr,
unsigned hwlen,
2033 return (lease_id_hash_lookup(lp, lease_hw_addr_hash, hwaddr, hwlen,
2050 static isc_boolean_t
2051 client_lease_preferred(
struct lease *cand,
struct lease *lease)
2088 struct lease *head = NULL;
2089 struct lease *cand = NULL;
2090 struct lease *
prev = NULL;
2091 struct lease *
next = NULL;
2095 lease_id_hash_add(lease_uid_hash, lease->
uid, lease->
uid_len,
2105 lease_reference(&cand, head,
MDL);
2106 while (cand != NULL) {
2107 if (client_lease_preferred(cand, lease))
2111 lease_dereference(&prev,
MDL);
2112 lease_reference(&prev, cand,
MDL);
2114 if (cand->
n_uid != NULL)
2115 lease_reference(&next, cand->
n_uid,
MDL);
2117 lease_dereference(&cand,
MDL);
2120 lease_reference(&cand, next,
MDL);
2121 lease_dereference(&next,
MDL);
2129 lease_reference(&lease->
n_uid, head,
MDL);
2130 lease_id_hash_delete(lease_uid_hash, lease->
uid,
2132 lease_id_hash_add(lease_uid_hash, lease->
uid,
2135 if(prev->
n_uid != NULL) {
2138 lease_dereference(&prev->
n_uid,
MDL);
2140 lease_reference(&prev->
n_uid, lease,
MDL);
2142 lease_dereference(&prev,
MDL);
2146 lease_dereference(&cand,
MDL);
2147 lease_dereference(&head,
MDL);
2154 struct lease *lease;
2156 struct lease *head = (
struct lease *)0;
2162 lease_dereference (&lease ->
n_uid,
MDL);
2169 if (head == lease) {
2170 lease_id_hash_delete(lease_uid_hash, lease->uid,
2171 lease->uid_len,
MDL);
2172 if (lease ->
n_uid) {
2173 lease_id_hash_add(lease_uid_hash, lease->n_uid->uid,
2174 lease->n_uid->uid_len, lease->n_uid,
2176 lease_dereference (&lease ->
n_uid,
MDL);
2182 for (scan = head; scan ->
n_uid; scan = scan ->
n_uid) {
2183 if (scan ->
n_uid == lease) {
2184 lease_dereference (&scan ->
n_uid,
MDL);
2185 if (lease ->
n_uid) {
2186 lease_reference (&scan ->
n_uid,
2188 lease_dereference (&lease ->
n_uid,
2195 lease_dereference (&head,
MDL);
2205 struct lease *head = NULL;
2206 struct lease *cand = NULL;
2207 struct lease *
prev = NULL;
2208 struct lease *
next = NULL;
2221 lease_id_hash_add(lease_hw_addr_hash,
2232 lease_reference(&cand, head,
MDL);
2233 while (cand != NULL) {
2234 if (client_lease_preferred(cand, lease))
2238 lease_dereference(&prev,
MDL);
2239 lease_reference(&prev, cand,
MDL);
2241 if (cand->
n_hw != NULL)
2242 lease_reference(&next, cand->
n_hw,
MDL);
2244 lease_dereference(&cand,
MDL);
2247 lease_reference(&cand, next,
MDL);
2248 lease_dereference(&next,
MDL);
2256 lease_reference(&lease->
n_hw, head,
MDL);
2257 lease_id_hash_delete(lease_hw_addr_hash,
2260 lease_id_hash_add(lease_hw_addr_hash,
2265 if(prev->
n_hw != NULL) {
2266 lease_reference(&lease->
n_hw, prev->
n_hw,
2268 lease_dereference(&prev->
n_hw,
MDL);
2270 lease_reference(&prev->
n_hw, lease,
MDL);
2272 lease_dereference(&prev,
MDL);
2276 lease_dereference(&cand,
MDL);
2277 lease_dereference(&head,
MDL);
2284 struct lease *lease;
2286 struct lease *head = (
struct lease *)0;
2287 struct lease *
next = (
struct lease *)0;
2293 if ((lease->hardware_addr.hlen == 1) &&
2301 lease_dereference (&lease ->
n_hw,
MDL);
2308 if (head == lease) {
2309 lease_id_hash_delete(lease_hw_addr_hash,
2310 lease->hardware_addr.hbuf,
2311 lease->hardware_addr.hlen,
MDL);
2313 lease_id_hash_add(lease_hw_addr_hash,
2314 lease->n_hw->hardware_addr.hbuf,
2315 lease->n_hw->hardware_addr.hlen,
2317 lease_dereference(&lease->n_hw,
MDL);
2323 while (head ->
n_hw) {
2324 if (head ->
n_hw == lease) {
2325 lease_dereference (&head ->
n_hw,
MDL);
2326 if (lease ->
n_hw) {
2327 lease_reference (&head ->
n_hw,
2329 lease_dereference (&lease ->
n_hw,
2334 lease_reference (&next, head ->
n_hw,
MDL);
2335 lease_dereference (&head,
MDL);
2336 lease_reference (&head, next,
MDL);
2337 lease_dereference (&next,
MDL);
2341 lease_dereference (&head,
MDL);
2350 int num_written = 0, i;
2353 for (s = shared_networks; s; s = s->
next) {
2366 #if !defined (DEBUG_DUMP_ALL_LEASES)
2380 log_info (
"Wrote %d leases to leases file.", num_written);
2400 for (cp = colp->
classes ; cp ; cp = cp->
nic) {
2402 (
unsigned char *)cp->
name,
2408 log_info (
"Wrote %d class decls to leases file.",
2418 hb; hb = hb ->
next) {
2429 log_info (
"Wrote %d group decls to leases file.", num_written);
2433 if (host_name_hash) {
2435 for (i = 0; i < host_name_hash -> hash_count; i++) {
2436 for (hb = host_name_hash -> buckets [i];
2437 hb; hb = hb -> next) {
2447 log_info (
"Wrote %d deleted host decls to leases file.",
2452 if (host_name_hash) {
2454 for (i = 0; i < host_name_hash -> hash_count; i++) {
2455 for (hb = host_name_hash -> buckets [i];
2456 hb; hb = hb -> next) {
2464 log_info (
"Wrote %d new dynamic host decls to leases file.",
2468 #if defined (FAILOVER_PROTOCOL)
2492 #if !defined (BINARY_LEASES)
2493 #if defined (DEBUG_MEMORY_LEAKAGE) || \
2494 defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
2497 void lease_remove_all(
struct lease **lq) {
2498 struct lease *lp, *ln = NULL;
2511 lease_reference(&lp, *lq,
MDL);
2512 lease_dereference(lq,
MDL);
2517 lease_reference(&ln, lp->
next,
MDL);
2518 lease_dereference(&lp->
next,
MDL);
2522 lease_dereference(&lp,
MDL);
2527 }
while (lp != NULL);
2539 struct lease *
prev, *lp;
2542 for (lp = *lq; lp != NULL; lp = lp->
next) {
2549 log_fatal(
"Lease with binding state %s not on its queue.",
2557 lease_dereference(&prev->
next,
MDL);
2560 lease_dereference (&comp->
next,
MDL);
2563 lease_dereference(lq,
MDL);
2565 lease_reference(lq, comp->
next,
MDL);
2566 lease_dereference(&comp->
next,
MDL);
2577 struct lease *
prev, *lp;
2578 static struct lease **last_lq = NULL;
2579 static struct lease *last_insert_point = NULL;
2586 if ((server_starting &
SS_QFOLLOW) && (lq == last_lq) &&
2587 (comp != last_insert_point) &&
2589 prev = last_insert_point;
2597 for (; lp != NULL ; lp = lp->
next) {
2606 lease_dereference(&prev->
next,
MDL);
2608 lease_reference(&prev->
next, comp,
MDL);
2611 lease_reference (&comp->
next, *lq,
MDL);
2612 lease_dereference(lq,
MDL);
2614 lease_reference(lq, comp,
MDL);
2616 last_insert_point = comp;
2656 lq = &comp ->
pool -> active;
2663 lq = &comp ->
pool -> expired;
2664 #if defined(FAILOVER_PROTOCOL)
2688 lq = &comp ->
pool -> abandoned;
2703 log_error (
"Lease with bogus binding state: %d",
2705 #if defined (BINDING_STATE_DEBUG)
2723 struct lease *lease = object;
2724 struct class *
class;
2728 if (!lease ->
pool) {
2729 lease_ip_hash_delete(lease_ip_addr_hash, lease->
ip_addr.
iabuf,
2731 return ISC_R_SUCCESS;
2734 #if defined (FAILOVER_PROTOCOL)
2757 return ISC_R_SUCCESS;
2765 if (lease -> hardware_addr.hlen) {
2770 if (lease -> billing_class) {
2771 class = (struct class *)0;
2772 class_reference (&
class, lease -> billing_class,
MDL);
2773 class_dereference (&lease -> billing_class,
MDL);
2781 class_dereference (&
class,
MDL);
2783 return ISC_R_SUCCESS;
2802 #if defined (BINARY_LEASES)
2808 for (s = shared_networks; s; s = s ->
next) {
2809 for (p = s ->
pools; p != NULL; p = p ->
next) {
2810 size_t num_f = 100, num_a = 50, num_e = 20;
2837 for (s = shared_networks; s; s = s ->
next) {
2838 for (p = s ->
pools; p; p = p ->
next) {
2841 p -> lease_count = 0;
2842 p -> free_leases = 0;
2843 p -> backup_leases = 0;
2872 #if defined (FAILOVER_PROTOCOL)
2873 if (p -> failover_peer &&
2886 server_starting = 0;
2899 for (n = subnets; n; n = n -> next_subnet) {
2905 for (s = shared_networks; s; s = s ->
next) {
2907 for (p = s ->
pools; p; p = p ->
next) {
2929 lease_reference, lease_dereference,
do_id_hash)
2935 #if defined (DEBUG_MEMORY_LEAKAGE) && \
2936 defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
2949 #if defined (COMPACT_LEASES)
2950 extern struct lease *lease_hunks;
2953 void free_everything(
void)
2958 struct pool *pc = (
struct pool *)0, *pn = (
struct pool *)0;
2959 struct lease *
lc = NULL, *ln = NULL, *ltemp = NULL;
2962 struct class *cc = (
struct class *)0, *cn = (
struct class *)0;
2967 if (host_hw_addr_hash)
2968 host_free_hash_table (&host_hw_addr_hash,
MDL);
2969 host_hw_addr_hash = 0;
2971 host_free_hash_table (&host_uid_hash,
MDL);
2974 lease_id_free_hash_table (&lease_uid_hash,
MDL);
2976 if (lease_ip_addr_hash)
2977 lease_ip_free_hash_table (&lease_ip_addr_hash,
MDL);
2978 lease_ip_addr_hash = 0;
2979 if (lease_hw_addr_hash)
2980 lease_id_free_hash_table (&lease_hw_addr_hash,
MDL);
2981 lease_hw_addr_hash = 0;
2983 host_free_hash_table (&host_name_hash,
MDL);
2986 dns_zone_free_hash_table (&dns_zone_hash,
MDL);
2989 while (host_id_info != NULL) {
2993 tmp = host_id_info->
next;
2999 auth_key_free_hash_table (&auth_key_hash,
MDL);
3011 class_reference (&cc, cn,
MDL);
3012 class_dereference (&cn,
MDL);
3015 class_reference (&cn, cc -> nic,
MDL);
3016 class_dereference (&cc -> nic,
MDL);
3020 class_free_hash_table (&cc -> hash,
MDL);
3023 class_dereference (&cc,
MDL);
3025 class_dereference (&lp -> classes,
MDL);
3029 if (interface_vector) {
3031 if (interface_vector [i])
3032 interface_dereference (&interface_vector [i],
MDL);
3035 interface_vector = 0;
3042 interface_reference (&ic, in,
MDL);
3043 interface_dereference (&in,
MDL);
3046 interface_reference (&in, ic -> next,
MDL);
3047 interface_dereference (&ic -> next,
MDL);
3052 interface_dereference
3056 interface_dereference (&ic,
MDL);
3063 subnet_reference (&sn, subnets,
MDL);
3066 subnet_reference (&sc, sn,
MDL);
3067 subnet_dereference (&sn,
MDL);
3069 if (sc -> next_subnet) {
3070 subnet_reference (&sn, sc -> next_subnet,
MDL);
3071 subnet_dereference (&sc -> next_subnet,
MDL);
3073 if (sc -> next_sibling)
3074 subnet_dereference (&sc -> next_sibling,
MDL);
3078 if (sc -> interface)
3079 interface_dereference (&sc -> interface,
MDL);
3080 subnet_dereference (&sc,
MDL);
3082 subnet_dereference (&subnets,
MDL);
3091 if (shared_networks) {
3092 shared_network_dereference (&shared_networks,
MDL);
3095 shared_network_reference (&nn, shared_networks,
MDL);
3098 shared_network_reference (&nc, nn,
MDL);
3099 shared_network_dereference (&nn,
MDL);
3102 shared_network_reference (&nn, nc -> next,
MDL);
3103 shared_network_dereference (&nc -> next,
MDL);
3108 pool_reference (&pn, nc ->
pools,
MDL);
3113 pool_reference (&pc, pn,
MDL);
3114 pool_dereference (&pn,
MDL);
3117 pool_reference (&pn, pc -> next,
MDL);
3118 pool_dereference (&pc -> next,
MDL);
3134 lease_reference (&lc, ln,
MDL);
3135 lease_dereference (&ln,
MDL);
3139 if (ltemp != NULL) {
3140 lease_reference(&ln, ltemp,
MDL);
3146 if (lc -> billing_class)
3147 class_dereference (&lc -> billing_class,
3153 lease_dereference (&lc -> n_hw,
MDL);
3155 lease_dereference (&lc -> n_uid,
MDL);
3156 lease_dereference (&lc,
MDL);
3165 pool_dereference (&pc,
MDL);
3167 pool_dereference (&nc ->
pools,
MDL);
3172 shared_network_dereference (&nc,
MDL);
3174 shared_network_dereference (&shared_networks,
MDL);
3179 relinquish_ackqueue();
3193 universe_free_hash_table (&universe_hash,
MDL);
3201 if (universes [i]) {
3202 if (universes[i]->name_hash)
3203 option_name_free_hash_table(
3204 &universes[i]->name_hash,
3206 if (universes[i]->code_hash)
3207 option_code_free_hash_table(
3208 &universes[i]->code_hash,
3211 if (universes [i] -> name > (
char *)&end) {
3212 foo.c = universes [i] -> name;
3215 if (universes [i] > (
struct universe *)&end)
3222 relinquish_free_lease_states ();
3223 relinquish_free_pairs ();
3224 relinquish_free_expressions ();
3225 relinquish_free_binding_values ();
3226 relinquish_free_option_caches ();
3227 relinquish_free_packets ();
3228 #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)
void unbill_class(struct lease *lease)
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)
#define LEASE_REMOVEP(LQ, LEASE)
#define DHO_PXE_CLIENT_ID
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)
void abandon_lease(struct lease *lease, const char *message)
void * dmalloc(unsigned, const char *, int)
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
void lease_remove(struct lease **lq, struct lease *comp)
#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
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(* tvunref_t)(void *, const char *, int)
void relinquish_lease_hunks(void)
dhcp_failover_state_t * failover_peer
struct shared_network * shared_networks
struct data_string client_identifier
void(* tvref_t)(void *, void *, const char *, int)
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)
#define LEASE_INSERTP(LQ, LEASE)
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)
#define LEASE_NOT_EMPTYP(LQ)
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 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
union executable_statement::@7 data
int supersede_lease(struct lease *comp, struct lease *lease, int commit, int propogate, int pimmediate, int from_pool)
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
void lc_init_growth(struct leasechain *lc, size_t growth)
#define LEASE_GET_FIRSTP(LQ)
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
#define LEASE_GET_NEXTP(LQ, LEASE)
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)
void lease_insert(struct lease **lq, struct lease *comp)
struct packet * dhcpv6_container_packet
isc_result_t enter_host(struct host_decl *hd, int dynamicp, int commit)