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 for (p = host_id_info; p != NULL; p = p->
next) {
651 relay_packet = packet;
652 relay_state = opt_state;
672 relay_state = relay_packet->
options;
678 memset(&data, 0,
sizeof(data));
681 NULL, relay_state, NULL,
684 log_error(
"Error evaluating option cache");
714 struct iaddr ip_address;
718 memset (&fixed_addr, 0,
sizeof fixed_addr);
720 for (hp = *host; hp; hp = hp -> n_ipaddr) {
721 if (!hp -> fixed_addr)
729 hp -> fixed_addr,
MDL))
731 for (i = 0; i < fixed_addr.
len; i += 4) {
733 memcpy (ip_address.
iabuf,
734 fixed_addr.
data + i, 4);
743 host_reference (&tmp, *host,
MDL);
744 host_dereference (host,
MDL);
745 host_reference (host, hp,
MDL);
746 host_dereference (&tmp,
MDL);
758 struct
iaddr low, high;
761 struct
lease **lpchain;
763 #if defined(COMPACT_LEASES)
764 struct lease *address_range;
766 unsigned min, max, i;
767 char lowbuf [16], highbuf [16], netbuf [16];
770 #if !defined(COMPACT_LEASES)
776 strcpy (netbuf,
piaddr (subnet -> net));
777 log_fatal (
"No shared network for network %s (%s)",
778 netbuf,
piaddr (subnet -> netmask));
782 if (!lease_uid_hash) {
784 log_fatal (
"Can't allocate lease/uid hash");
786 if (!lease_ip_addr_hash) {
789 log_fatal (
"Can't allocate lease/ip hash");
791 if (!lease_hw_addr_hash) {
794 log_fatal (
"Can't allocate lease/hw hash");
799 strcpy(lowbuf,
piaddr(low));
801 log_fatal(
"bad range, address %s not in subnet %s netmask %s",
806 strcpy(highbuf,
piaddr(high));
808 log_fatal(
"bad range, address %s not in subnet %s netmask %s",
813 max =
host_addr (high, subnet -> netmask);
814 min =
host_addr (low, subnet -> netmask);
819 min =
host_addr (high, subnet -> netmask);
823 #if defined (COMPACT_LEASES)
825 if (!address_range) {
826 strcpy (lowbuf,
piaddr (low));
827 strcpy (highbuf,
piaddr (high));
828 log_fatal (
"No memory for address range %s-%s.",
834 for (i = 0; i < max - min + 1; i++) {
836 #if defined (COMPACT_LEASES)
840 lease_reference (&lp, &address_range [i],
MDL);
842 status = lease_allocate (&lp,
MDL);
843 if (status != ISC_R_SUCCESS)
848 isc_result_totext (status));
853 subnet_reference(&lp->
subnet, subnet,
MDL);
854 pool_reference(&lp->
pool, pool,
MDL);
864 "lease %s is declared twice!",
867 pool_reference (< -> pool, pool,
MDL);
868 lease_dereference (<,
MDL);
870 lease_ip_hash_add(lease_ip_addr_hash,
876 lease_reference (&lp ->
next, *lpchain,
MDL);
877 lease_dereference (lpchain,
MDL);
879 lease_reference (lpchain, lp,
MDL);
881 lease_dereference (&lp,
MDL);
892 if (subnet_reference (sp, rv,
893 file, line) != ISC_R_SUCCESS)
907 for (rv = share -> subnets; rv; rv = rv ->
next_sibling) {
909 if (subnet_reference (sp, rv,
910 file, line) != ISC_R_SUCCESS)
921 const struct subnet *scan,
925 char n1buf[
sizeof(
"ffff:ffff:ffff:ffff:ffff:ffff:255.255.255")];
927 for (i = 0; i < 128; i++)
931 for (j = 0; j < 128; j++)
937 log_error(
"Warning: subnet %s/%d overlaps subnet %s/%d",
951 struct subnet *scan = (
struct subnet *)0;
952 struct subnet *next = (
struct subnet *)0;
953 struct subnet *prev = (
struct subnet *)0;
957 subnet_reference (&next, subnets,
MDL);
959 subnet_reference (&scan, next,
MDL);
960 subnet_dereference (&next,
MDL);
970 subnet_dereference (&prev,
MDL);
972 subnet_dereference (&subnets,
MDL);
973 subnet_reference (&subnets, subnet,
MDL);
976 subnet_dereference (&scan,
MDL);
979 subnet_reference (&prev, scan,
MDL);
980 subnet_dereference (&scan,
MDL);
983 subnet_dereference (&prev,
MDL);
988 subnet_dereference (&subnets,
MDL);
990 subnet_reference (&subnets, subnet,
MDL);
998 if (shared_networks) {
999 shared_network_reference (&share -> next,
1000 shared_networks,
MDL);
1001 shared_network_dereference (&shared_networks,
MDL);
1003 shared_network_reference (&shared_networks, share,
MDL);
1007 struct
parse *cfile;
1012 isc_result_t status;
1014 if (share -> interface) {
1016 "A subnet or shared network can't be connected %s",
1017 "to two interfaces.");
1022 if (!strcmp (ip -> name, name))
1025 status = interface_allocate (&ip,
MDL);
1026 if (status != ISC_R_SUCCESS)
1027 log_fatal (
"new_shared_network_interface %s: %s",
1028 name, isc_result_totext (status));
1029 if (strlen (name) >
sizeof ip -> name) {
1030 memcpy (ip -> name, name, (
sizeof ip -> name) - 1);
1031 ip -> name [(
sizeof ip ->
name) - 1] = 0;
1033 strcpy (ip -> name, name);
1042 interface_reference (&share -> interface, ip,
MDL);
1055 struct lease *comp = (
struct lease *)0;
1058 if (!comp ->
pool) {
1059 log_error (
"undeclared lease found in database: %s",
1062 pool_reference (&lease ->
pool, comp ->
pool,
MDL);
1065 subnet_reference (&lease ->
subnet,
1067 lease_ip_hash_delete(lease_ip_addr_hash,
1068 lease->ip_addr.iabuf, lease->ip_addr.len,
1070 lease_dereference (&comp,
MDL);
1086 lease_ip_hash_add(lease_ip_addr_hash, lease->ip_addr.iabuf,
1087 lease->ip_addr.len, lease,
MDL);
1102 struct lease *lp, **lq, *prev;
1104 #if defined (FAILOVER_PROTOCOL)
1105 int do_pool_check = 0;
1110 if (pimmediate && !commit)
1134 (((comp -> uid && lease -> uid) &&
1135 (comp -> uid_len != lease -> uid_len ||
1136 memcmp (comp -> uid, lease -> uid, comp -> uid_len))) ||
1138 ((comp -> hardware_addr.hlen !=
1139 lease -> hardware_addr.hlen) ||
1140 memcmp (comp -> hardware_addr.hbuf,
1141 lease -> hardware_addr.hbuf,
1142 comp -> hardware_addr.hlen))))) {
1151 if (comp->uid != comp->uid_buf) {
1156 comp -> uid = (
unsigned char *)0;
1162 if (comp->hardware_addr.hlen)
1166 if (comp -> billing_class != lease -> billing_class) {
1167 if (comp -> billing_class)
1169 if (lease -> billing_class)
1174 comp -> starts = lease -> starts;
1176 if (lease -> uid_len <=
sizeof (lease -> uid_buf)) {
1177 memcpy (comp -> uid_buf,
1178 lease -> uid, lease -> uid_len);
1179 comp -> uid = &comp -> uid_buf [0];
1180 comp -> uid_max =
sizeof comp -> uid_buf;
1181 comp -> uid_len = lease -> uid_len;
1182 }
else if (lease -> uid != &lease -> uid_buf [0]) {
1183 comp -> uid = lease -> uid;
1184 comp -> uid_max = lease -> uid_max;
1185 lease -> uid = (
unsigned char *)0;
1186 lease -> uid_max = 0;
1187 comp -> uid_len = lease -> uid_len;
1188 lease -> uid_len = 0;
1193 comp -> uid = (
unsigned char *)0;
1194 comp -> uid_len = comp -> uid_max = 0;
1197 host_dereference (&comp -> host,
MDL);
1198 host_reference (&comp -> host, lease -> host,
MDL);
1199 comp -> hardware_addr = lease -> hardware_addr;
1204 if (lease -> scope) {
1214 if (lease -> next_binding_state ==
FTS_ACTIVE ||
1223 if (comp -> client_hostname)
1224 dfree (comp -> client_hostname,
MDL);
1225 comp -> client_hostname = lease -> client_hostname;
1226 lease -> client_hostname = (
char *)0;
1228 if (lease->on_star.on_expiry) {
1229 if (comp->on_star.on_expiry)
1231 (&comp->on_star.on_expiry,
MDL);
1233 lease->on_star.on_expiry,
1236 if (lease->on_star.on_commit) {
1237 if (comp->on_star.on_commit)
1239 (&comp->on_star.on_commit,
MDL);
1241 lease->on_star.on_commit,
1244 if (lease->on_star.on_release) {
1245 if (comp->on_star.on_release)
1247 (&comp->on_star.on_release,
MDL);
1249 lease->on_star.on_release,
1258 if (comp->hardware_addr.hlen)
1261 comp->cltt = lease->cltt;
1262 #if defined (FAILOVER_PROTOCOL)
1263 comp->tstp = lease->tstp;
1264 comp->tsfp = lease->tsfp;
1265 comp->atsfp = lease->atsfp;
1267 comp->ends = lease->ends;
1268 comp->next_binding_state = lease->next_binding_state;
1277 if (lease->ddns_cb != NULL)
1278 comp->ddns_cb = lease->ddns_cb;
1281 #if defined (FAILOVER_PROTOCOL)
1291 if (!comp ->
pool) {
1292 log_error (
"Supersede_lease: lease %s with no pool.",
1298 switch (comp -> binding_state) {
1307 #if defined(FAILOVER_PROTOCOL)
1313 lq = &comp ->
pool -> active;
1319 lq = &comp ->
pool -> expired;
1323 lq = &comp ->
pool -> abandoned;
1334 #if defined(FAILOVER_PROTOCOL)
1340 log_error (
"Lease with bogus binding state: %d",
1341 comp -> binding_state);
1342 #if defined (BINDING_STATE_DEBUG)
1351 prev = (
struct lease *)0;
1352 for (lp = *lq; lp; lp = lp ->
next) {
1359 log_fatal(
"Lease with binding state %s not on its queue.",
1360 (comp->binding_state < 1 ||
1367 lease_dereference (&prev ->
next,
MDL);
1369 lease_reference (&prev ->
next, comp ->
next,
MDL);
1370 lease_dereference (&comp ->
next,
MDL);
1373 lease_dereference (lq,
MDL);
1375 lease_reference (lq, comp ->
next,
MDL);
1376 lease_dereference (&comp ->
next,
MDL);
1381 if (commit || !pimmediate)
1400 if ((commit || !pimmediate) &&
1403 (comp -> sort_time < comp ->
pool -> next_event_time ||
1406 tv . tv_sec = comp ->
pool -> next_event_time;
1415 #if defined(FAILOVER_PROTOCOL)
1425 if (propogate && (comp->pool->failover_peer != NULL) &&
1426 ((comp->pool->failover_peer->service_state ==
1428 (comp->pool->failover_peer->service_state ==
1430 comp->rewind_binding_state = comp->binding_state;
1435 if ((server_starting &
SS_NOSYNC) == 0) {
1441 #if defined (FAILOVER_PROTOCOL)
1447 if (do_pool_check && comp->pool->failover_peer)
1457 if ((from_pool == 0) &&
1458 (commit || !pimmediate) &&
1460 (comp->next_binding_state != comp->binding_state))
1469 #if defined (FAILOVER_PROTOCOL)
1470 dhcp_failover_state_t *peer;
1472 if (lease ->
pool && lease ->
pool -> failover_peer)
1473 peer = lease ->
pool -> failover_peer;
1475 peer = (dhcp_failover_state_t *)0;
1492 #if defined (NSUPDATE)
1522 host_dereference (&lease ->
host,
MDL);
1541 #if defined (NSUPDATE)
1586 host_dereference (&lease ->
host,
MDL);
1593 #if defined (DEBUG_LEASE_STATE_TRANSITIONS)
1594 log_debug (
"lease %s moves from %s to %s",
1603 #if defined (FAILOVER_PROTOCOL)
1604 if (lease ->
pool && lease ->
pool -> failover_peer)
1616 #if defined(FAILOVER_PROTOCOL)
1621 if ((lease->
pool != NULL) &&
1635 #if defined (DEBUG_LEASE_STATE_TRANSITIONS)
1636 log_debug (
"lease %s: next binding state %s",
1647 struct lease *lt = (
struct lease *)0;
1648 isc_result_t status;
1650 status = lease_allocate (<,
MDL);
1651 if (status != ISC_R_SUCCESS)
1662 }
else if (!lease ->
uid_max) {
1663 lt ->
uid = (
unsigned char *)0;
1667 lease_dereference (<,
MDL);
1676 lease_dereference (<,
MDL);
1686 host_reference (< ->
host, lease ->
host, file, line);
1687 subnet_reference (< ->
subnet, lease ->
subnet, file, line);
1688 pool_reference (< ->
pool, lease ->
pool, file, line);
1712 status = lease_reference(lp, lt, file, line);
1713 lease_dereference(<,
MDL);
1714 return status == ISC_R_SUCCESS;
1724 #if defined (NSUPDATE)
1727 if (lease->on_star.on_release) {
1730 NULL, &lease->scope,
1731 lease->on_star.on_release, NULL);
1732 if (lease->on_star.on_release)
1734 (&lease->on_star.on_release,
MDL);
1740 if (lease->on_star.on_expiry)
1742 (&lease->on_star.on_expiry,
MDL);
1749 if (lease->on_star.on_commit)
1751 (&lease->on_star.on_commit,
MDL);
1764 #if defined (FAILOVER_PROTOCOL)
1765 if (lease ->
pool && lease ->
pool -> failover_peer) {
1766 dhcp_failover_state_t *peer = NULL;
1768 if (lease->pool != NULL)
1769 peer = lease->pool->failover_peer;
1772 (((peer->i_am == primary) &&
1773 (lease->rewind_binding_state ==
FTS_FREE)) ||
1774 ((peer->i_am == secondary) &&
1775 (lease->rewind_binding_state ==
FTS_BACKUP)))) {
1776 lease->next_binding_state =
1777 lease->rewind_binding_state;
1795 const
char *message;
1797 struct lease *lt = (
struct lease *)0;
1798 #if defined (NSUPDATE)
1811 log_error (
"Abandoning IP address %s: %s",
1816 lt ->
uid = (
unsigned char *)0;
1820 lease_dereference (<,
MDL);
1834 void dissociate_lease (
lease)
1837 struct lease *lt = (
struct lease *)0;
1838 #if defined (NSUPDATE)
1845 #if defined (FAILOVER_PROTOCOL)
1846 if (lease ->
pool && lease ->
pool -> failover_peer) {
1858 lt ->
uid = (
unsigned char *)0;
1862 lease_dereference (<,
MDL);
1871 struct lease *
next = NULL;
1872 struct lease *lease = 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))
1926 lease_reference(&lease, *(lptr [i]),
MDL);
1931 lease_dereference(&next,
MDL);
1933 lease_reference(&next, lease->
next,
MDL);
1950 #if defined(FAILOVER_PROTOCOL)
1951 dhcp_failover_state_t *peer = NULL;
1953 if (lease->
pool != NULL)
1960 ((peer->i_am == primary &&
1963 (peer->i_am == secondary &&
1972 lease_dereference(&lease,
MDL);
1974 lease_reference(&lease, next,
MDL);
1977 lease_dereference(&next,
MDL);
1979 lease_dereference(&lease,
MDL);
1988 ((pool->next_event_time > next_expiry) ||
1989 (pool->next_event_time <=
cur_time))) {
1990 pool->next_event_time = next_expiry;
1991 tv.tv_sec = pool->next_event_time;
2006 return lease_ip_hash_lookup(lp, lease_ip_addr_hash, addr.
iabuf,
2007 addr.
len, file, line);
2011 unsigned len,
const char *
file,
int line)
2015 return lease_id_hash_lookup (lp, lease_uid_hash, uid, len, file, line);
2019 const unsigned char *hwaddr,
unsigned hwlen,
2032 return (lease_id_hash_lookup(lp, lease_hw_addr_hash, hwaddr, hwlen,
2049 static isc_boolean_t
2050 client_lease_preferred(
struct lease *cand,
struct lease *lease)
2087 struct lease *head = NULL;
2088 struct lease *cand = NULL;
2089 struct lease *prev = NULL;
2090 struct lease *
next = NULL;
2094 lease_id_hash_add(lease_uid_hash, lease->
uid, lease->
uid_len,
2104 lease_reference(&cand, head,
MDL);
2105 while (cand != NULL) {
2106 if (client_lease_preferred(cand, lease))
2110 lease_dereference(&prev,
MDL);
2111 lease_reference(&prev, cand,
MDL);
2113 if (cand->
n_uid != NULL)
2114 lease_reference(&next, cand->
n_uid,
MDL);
2116 lease_dereference(&cand,
MDL);
2119 lease_reference(&cand, next,
MDL);
2120 lease_dereference(&next,
MDL);
2128 lease_reference(&lease->
n_uid, head,
MDL);
2129 lease_id_hash_delete(lease_uid_hash, lease->
uid,
2131 lease_id_hash_add(lease_uid_hash, lease->
uid,
2134 if(prev->
n_uid != NULL) {
2137 lease_dereference(&prev->
n_uid,
MDL);
2139 lease_reference(&prev->
n_uid, lease,
MDL);
2141 lease_dereference(&prev,
MDL);
2145 lease_dereference(&cand,
MDL);
2146 lease_dereference(&head,
MDL);
2153 struct lease *lease;
2155 struct lease *head = (
struct lease *)0;
2161 lease_dereference (&lease ->
n_uid,
MDL);
2168 if (head == lease) {
2169 lease_id_hash_delete(lease_uid_hash, lease->uid,
2170 lease->uid_len,
MDL);
2171 if (lease ->
n_uid) {
2172 lease_id_hash_add(lease_uid_hash, lease->n_uid->uid,
2173 lease->n_uid->uid_len, lease->n_uid,
2175 lease_dereference (&lease ->
n_uid,
MDL);
2181 for (scan = head; scan ->
n_uid; scan = scan ->
n_uid) {
2182 if (scan ->
n_uid == lease) {
2183 lease_dereference (&scan ->
n_uid,
MDL);
2184 if (lease ->
n_uid) {
2185 lease_reference (&scan ->
n_uid,
2187 lease_dereference (&lease ->
n_uid,
2194 lease_dereference (&head,
MDL);
2204 struct lease *head = NULL;
2205 struct lease *cand = NULL;
2206 struct lease *prev = NULL;
2207 struct lease *
next = NULL;
2220 lease_id_hash_add(lease_hw_addr_hash,
2231 lease_reference(&cand, head,
MDL);
2232 while (cand != NULL) {
2233 if (client_lease_preferred(cand, lease))
2237 lease_dereference(&prev,
MDL);
2238 lease_reference(&prev, cand,
MDL);
2240 if (cand->
n_hw != NULL)
2241 lease_reference(&next, cand->
n_hw,
MDL);
2243 lease_dereference(&cand,
MDL);
2246 lease_reference(&cand, next,
MDL);
2247 lease_dereference(&next,
MDL);
2255 lease_reference(&lease->
n_hw, head,
MDL);
2256 lease_id_hash_delete(lease_hw_addr_hash,
2259 lease_id_hash_add(lease_hw_addr_hash,
2264 if(prev->
n_hw != NULL) {
2265 lease_reference(&lease->
n_hw, prev->
n_hw,
2267 lease_dereference(&prev->
n_hw,
MDL);
2269 lease_reference(&prev->
n_hw, lease,
MDL);
2271 lease_dereference(&prev,
MDL);
2275 lease_dereference(&cand,
MDL);
2276 lease_dereference(&head,
MDL);
2283 struct lease *lease;
2285 struct lease *head = (
struct lease *)0;
2286 struct lease *
next = (
struct lease *)0;
2292 if ((lease->hardware_addr.hlen == 1) &&
2300 lease_dereference (&lease ->
n_hw,
MDL);
2307 if (head == lease) {
2308 lease_id_hash_delete(lease_hw_addr_hash,
2309 lease->hardware_addr.hbuf,
2310 lease->hardware_addr.hlen,
MDL);
2312 lease_id_hash_add(lease_hw_addr_hash,
2313 lease->n_hw->hardware_addr.hbuf,
2314 lease->n_hw->hardware_addr.hlen,
2316 lease_dereference(&lease->n_hw,
MDL);
2322 while (head ->
n_hw) {
2323 if (head ->
n_hw == lease) {
2324 lease_dereference (&head ->
n_hw,
MDL);
2325 if (lease ->
n_hw) {
2326 lease_reference (&head ->
n_hw,
2328 lease_dereference (&lease ->
n_hw,
2333 lease_reference (&next, head ->
n_hw,
MDL);
2334 lease_dereference (&head,
MDL);
2335 lease_reference (&head, next,
MDL);
2336 lease_dereference (&next,
MDL);
2340 lease_dereference (&head,
MDL);
2349 int num_written = 0, i;
2352 for (s = shared_networks; s; s = s->
next) {
2362 for (l = *(lptr[i]); l; l = l->
next) {
2363 #if !defined (DEBUG_DUMP_ALL_LEASES)
2377 log_info (
"Wrote %d leases to leases file.", num_written);
2397 for (cp = colp->
classes ; cp ; cp = cp->
nic) {
2399 (
unsigned char *)cp->
name,
2405 log_info (
"Wrote %d class decls to leases file.",
2415 hb; hb = hb ->
next) {
2426 log_info (
"Wrote %d group decls to leases file.", num_written);
2430 if (host_name_hash) {
2432 for (i = 0; i < host_name_hash -> hash_count; i++) {
2433 for (hb = host_name_hash -> buckets [i];
2434 hb; hb = hb -> next) {
2444 log_info (
"Wrote %d deleted host decls to leases file.",
2449 if (host_name_hash) {
2451 for (i = 0; i < host_name_hash -> hash_count; i++) {
2452 for (hb = host_name_hash -> buckets [i];
2453 hb; hb = hb -> next) {
2461 log_info (
"Wrote %d new dynamic host decls to leases file.",
2465 #if defined (FAILOVER_PROTOCOL)
2503 struct lease **lq, *prev, *lp;
2504 static struct lease **last_lq = NULL;
2505 static struct lease *last_insert_point = NULL;
2524 lq = &comp ->
pool -> active;
2531 lq = &comp ->
pool -> expired;
2532 #if defined(FAILOVER_PROTOCOL)
2556 lq = &comp ->
pool -> abandoned;
2571 log_error (
"Lease with bogus binding state: %d",
2573 #if defined (BINDING_STATE_DEBUG)
2584 if ((server_starting &
SS_QFOLLOW) && (lq == last_lq) &&
2585 (comp != last_insert_point) &&
2587 prev = last_insert_point;
2595 for (; lp ; lp = lp->
next) {
2603 lease_reference (&comp ->
next, prev ->
next,
MDL);
2604 lease_dereference (&prev ->
next,
MDL);
2606 lease_reference (&prev ->
next, comp,
MDL);
2609 lease_reference (&comp ->
next, *lq,
MDL);
2610 lease_dereference (lq,
MDL);
2612 lease_reference (lq, comp,
MDL);
2614 last_insert_point = comp;
2626 struct lease *lease = object;
2627 struct class *
class;
2631 if (!lease ->
pool) {
2632 lease_ip_hash_delete(lease_ip_addr_hash, lease->
ip_addr.
iabuf,
2634 return ISC_R_SUCCESS;
2637 #if defined (FAILOVER_PROTOCOL)
2660 return ISC_R_SUCCESS;
2668 if (lease -> hardware_addr.hlen) {
2673 if (lease -> billing_class) {
2674 class = (struct class *)0;
2675 class_reference (&
class, lease -> billing_class,
MDL);
2676 class_dereference (&lease -> billing_class,
MDL);
2684 class_dereference (&
class,
MDL);
2686 return ISC_R_SUCCESS;
2716 for (s = shared_networks; s; s = s ->
next) {
2717 for (p = s ->
pools; p; p = p ->
next) {
2720 p -> lease_count = 0;
2721 p -> free_leases = 0;
2722 p -> backup_leases = 0;
2732 for (l = *(lptr [i]); l; l = l ->
next) {
2749 #if defined (FAILOVER_PROTOCOL)
2750 if (p -> failover_peer &&
2763 server_starting = 0;
2776 for (n = subnets; n; n = n -> next_subnet) {
2782 for (s = shared_networks; s; s = s ->
next) {
2784 for (p = s ->
pools; p; p = p ->
next) {
2793 for (l = *(lptr [i]); l; l = l ->
next) {
2804 lease_reference, lease_dereference,
do_id_hash)
2810 #if defined (DEBUG_MEMORY_LEAKAGE) && \
2811 defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
2824 #if defined (COMPACT_LEASES)
2825 extern struct lease *lease_hunks;
2828 void free_everything(
void)
2833 struct pool *pc = (
struct pool *)0, *pn = (
struct pool *)0;
2834 struct lease *lc = (
struct lease *)0, *ln = (
struct lease *)0;
2837 struct class *cc = (
struct class *)0, *cn = (
struct class *)0;
2842 if (host_hw_addr_hash)
2843 host_free_hash_table (&host_hw_addr_hash,
MDL);
2844 host_hw_addr_hash = 0;
2846 host_free_hash_table (&host_uid_hash,
MDL);
2849 lease_id_free_hash_table (&lease_uid_hash,
MDL);
2851 if (lease_ip_addr_hash)
2852 lease_ip_free_hash_table (&lease_ip_addr_hash,
MDL);
2853 lease_ip_addr_hash = 0;
2854 if (lease_hw_addr_hash)
2855 lease_id_free_hash_table (&lease_hw_addr_hash,
MDL);
2856 lease_hw_addr_hash = 0;
2858 host_free_hash_table (&host_name_hash,
MDL);
2861 dns_zone_free_hash_table (&dns_zone_hash,
MDL);
2864 while (host_id_info != NULL) {
2868 tmp = host_id_info->
next;
2874 auth_key_free_hash_table (&auth_key_hash,
MDL);
2886 class_reference (&cc, cn,
MDL);
2887 class_dereference (&cn,
MDL);
2890 class_reference (&cn, cc -> nic,
MDL);
2891 class_dereference (&cc -> nic,
MDL);
2895 class_free_hash_table (&cc -> hash,
MDL);
2898 class_dereference (&cc,
MDL);
2900 class_dereference (&lp -> classes,
MDL);
2904 if (interface_vector) {
2906 if (interface_vector [i])
2907 interface_dereference (&interface_vector [i],
MDL);
2910 interface_vector = 0;
2917 interface_reference (&ic, in,
MDL);
2918 interface_dereference (&in,
MDL);
2921 interface_reference (&in, ic -> next,
MDL);
2922 interface_dereference (&ic -> next,
MDL);
2927 interface_dereference
2931 interface_dereference (&ic,
MDL);
2938 subnet_reference (&sn, subnets,
MDL);
2941 subnet_reference (&sc, sn,
MDL);
2942 subnet_dereference (&sn,
MDL);
2944 if (sc -> next_subnet) {
2945 subnet_reference (&sn, sc -> next_subnet,
MDL);
2946 subnet_dereference (&sc -> next_subnet,
MDL);
2948 if (sc -> next_sibling)
2949 subnet_dereference (&sc -> next_sibling,
MDL);
2953 if (sc -> interface)
2954 interface_dereference (&sc -> interface,
MDL);
2955 subnet_dereference (&sc,
MDL);
2957 subnet_dereference (&subnets,
MDL);
2966 if (shared_networks) {
2967 shared_network_dereference (&shared_networks,
MDL);
2970 shared_network_reference (&nn, shared_networks,
MDL);
2973 shared_network_reference (&nc, nn,
MDL);
2974 shared_network_dereference (&nn,
MDL);
2977 shared_network_reference (&nn, nc -> next,
MDL);
2978 shared_network_dereference (&nc -> next,
MDL);
2983 pool_reference (&pn, nc ->
pools,
MDL);
2988 pool_reference (&pc, pn,
MDL);
2989 pool_dereference (&pn,
MDL);
2992 pool_reference (&pn, pc ->
next,
MDL);
2993 pool_dereference (&pc ->
next,
MDL);
3006 lease_reference (&ln, *lptr [i],
MDL);
3009 lease_reference (&lc, ln,
MDL);
3010 lease_dereference (&ln,
MDL);
3013 lease_reference (&ln, lc ->
next,
MDL);
3014 lease_dereference (&lc ->
next,
MDL);
3023 lease_dereference (&lc -> n_hw,
MDL);
3025 lease_dereference (&lc -> n_uid,
MDL);
3026 lease_dereference (&lc,
MDL);
3028 lease_dereference (lptr [i],
MDL);
3036 pool_dereference (&pc,
MDL);
3038 pool_dereference (&nc ->
pools,
MDL);
3043 shared_network_dereference (&nc,
MDL);
3045 shared_network_dereference (&shared_networks,
MDL);
3050 relinquish_ackqueue();
3064 universe_free_hash_table (&universe_hash,
MDL);
3072 if (universes [i]) {
3073 if (universes[i]->name_hash)
3074 option_name_free_hash_table(
3075 &universes[i]->name_hash,
3077 if (universes[i]->code_hash)
3078 option_code_free_hash_table(
3079 &universes[i]->code_hash,
3082 if (universes [i] -> name > (
char *)&end) {
3083 foo.c = universes [i] -> name;
3086 if (universes [i] > (
struct universe *)&end)
3093 relinquish_free_lease_states ();
3094 relinquish_free_pairs ();
3095 relinquish_free_expressions ();
3096 relinquish_free_binding_values ();
3097 relinquish_free_option_caches ();
3098 relinquish_free_packets ();
3099 #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)
isc_result_t omapi_io_state_foreach(isc_result_t(*func)(omapi_object_t *, void *), void *p)
calls a given function on every object
unsigned do_id_hash(const void *, unsigned, unsigned)
#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)
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 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 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 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 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
int executable_statement_foreach(struct executable_statement *stmt, int(*callback)(struct executable_statement *, void *, int), void *vp, int condp)
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 HASH_FUNCTIONS(name, bufarg, type, hashtype, ref, deref, hasher)
#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)