83 }
else if (cd->name != NULL) {
87 class_dereference(&c,
MDL);
95 class_reference (&c ->
nic, cd,
MDL);
98 if (dynamicp && commit) {
99 const char *
name = cd->name;
102 name = cd->superclass->name;
107 return ISC_R_IOERROR;
110 return ISC_R_SUCCESS;
121 static int server_starting = 0;
129 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,
238 host_hash_lookup (&hp, host_name_hash,
239 (
unsigned char *)hd ->
name,
244 host_hash_delete (host_name_hash,
245 (
unsigned char *)hd ->
name,
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,
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,
593 host_hash_delete (host_name_hash,
594 (
unsigned char *)hd ->
name,
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 #if defined(LDAP_CONFIGURATION) 650 if ((found = find_client_in_ldap (hp, packet, opt_state, file, line)))
654 for (p = host_id_info; p != NULL; p = p->
next) {
655 relay_packet = packet;
656 relay_state = opt_state;
676 relay_state = relay_packet->
options;
682 memset(&data, 0,
sizeof(data));
685 NULL, relay_state, NULL,
688 log_error(
"Error evaluating option cache");
718 struct iaddr ip_address;
722 memset (&fixed_addr, 0,
sizeof fixed_addr);
724 for (hp = *host; hp; hp = hp -> n_ipaddr) {
725 if (!hp -> fixed_addr)
733 hp -> fixed_addr,
MDL))
735 for (i = 0; i < fixed_addr.
len; i += 4) {
737 memcpy (ip_address.
iabuf,
738 fixed_addr.
data + i, 4);
747 host_reference (&tmp, *host,
MDL);
748 host_dereference (host,
MDL);
749 host_reference (host, hp,
MDL);
750 host_dereference (&tmp,
MDL);
762 struct
iaddr low, high;
765 struct
lease **lpchain;
767 #if defined(COMPACT_LEASES) 768 struct lease *address_range;
771 unsigned min, max, i, num_addrs;
772 char lowbuf [16], highbuf [16], netbuf [16];
775 #if !defined(COMPACT_LEASES) 781 strcpy (netbuf,
piaddr (subnet -> net));
782 log_fatal (
"No shared network for network %s (%s)",
783 netbuf,
piaddr (subnet -> netmask));
787 if (!lease_uid_hash) {
789 log_fatal (
"Can't allocate lease/uid hash");
791 if (!lease_ip_addr_hash) {
794 log_fatal (
"Can't allocate lease/ip hash");
796 if (!lease_hw_addr_hash) {
799 log_fatal (
"Can't allocate lease/hw hash");
804 strcpy(lowbuf,
piaddr(low));
806 log_fatal(
"bad range, address %s not in subnet %s netmask %s",
811 strcpy(highbuf,
piaddr(high));
813 log_fatal(
"bad range, address %s not in subnet %s netmask %s",
818 max =
host_addr (high, subnet -> netmask);
819 min =
host_addr (low, subnet -> netmask);
824 min =
host_addr (high, subnet -> netmask);
831 num_addrs = max - min + 1;
832 #if defined (BINARY_LEASES) 837 #if defined (COMPACT_LEASES) 838 s = (num_addrs + 1) *
sizeof (
struct lease);
842 if (((s %
sizeof (
struct lease)) != 0) ||
843 ((s /
sizeof (
struct lease)) != (num_addrs + 1))) {
844 strcpy (lowbuf,
piaddr (low));
845 strcpy (highbuf,
piaddr (high));
846 parse_warn (cfile,
"%s-%s is an overly large address range.",
851 if (!address_range) {
852 strcpy (lowbuf,
piaddr (low));
853 strcpy (highbuf,
piaddr (high));
854 log_fatal (
"No memory for address range %s-%s.",
860 for (i = 0; i < num_addrs; i++) {
862 #if defined (COMPACT_LEASES) 866 lease_reference (&lp, &address_range [i],
MDL);
868 status = lease_allocate (&lp,
MDL);
869 if (status != ISC_R_SUCCESS)
874 isc_result_totext (status));
879 subnet_reference(&lp->
subnet, subnet,
MDL);
880 pool_reference(&lp->
pool, pool,
MDL);
890 "lease %s is declared twice!",
893 pool_reference (< -> pool, pool,
MDL);
894 lease_dereference (<,
MDL);
896 lease_ip_hash_add(lease_ip_addr_hash,
902 lease_reference (&lp ->
next, *lpchain,
MDL);
903 lease_dereference (lpchain,
MDL);
905 lease_reference (lpchain, lp,
MDL);
907 lease_dereference (&lp,
MDL);
922 if (subnet_reference (sp, rv,
923 file, line) != ISC_R_SUCCESS)
937 for (rv = share -> subnets; rv; rv = rv ->
next_sibling) {
943 if (subnet_reference (sp, rv,
944 file, line) != ISC_R_SUCCESS)
955 const struct subnet *scan,
963 char n1buf[
sizeof(
"ffff:ffff:ffff:ffff:ffff:ffff:255.255.255")];
965 for (i = 0; i < 128; i++)
969 for (j = 0; j < 128; j++)
975 log_error(
"Warning: subnet %s/%d overlaps subnet %s/%d",
989 struct subnet *scan = (
struct subnet *)0;
990 struct subnet *
next = (
struct subnet *)0;
991 struct subnet *prev = (
struct subnet *)0;
995 subnet_reference (&next, subnets,
MDL);
997 subnet_reference (&scan, next,
MDL);
998 subnet_dereference (&next,
MDL);
1008 subnet_dereference (&prev,
MDL);
1010 subnet_dereference (&subnets,
MDL);
1011 subnet_reference (&subnets, subnet,
MDL);
1014 subnet_dereference (&scan,
MDL);
1017 subnet_reference (&prev, scan,
MDL);
1018 subnet_dereference (&scan,
MDL);
1021 subnet_dereference (&prev,
MDL);
1026 subnet_dereference (&subnets,
MDL);
1028 subnet_reference (&subnets, subnet,
MDL);
1036 if (shared_networks) {
1037 shared_network_reference (&share ->
next,
1038 shared_networks,
MDL);
1039 shared_network_dereference (&shared_networks,
MDL);
1041 shared_network_reference (&shared_networks, share,
MDL);
1045 struct
parse *cfile;
1050 isc_result_t status;
1052 if (share -> interface) {
1054 "A subnet or shared network can't be connected %s",
1055 "to two interfaces.");
1060 if (!strcmp (ip -> name, name))
1063 status = interface_allocate (&ip,
MDL);
1064 if (status != ISC_R_SUCCESS)
1065 log_fatal (
"new_shared_network_interface %s: %s",
1066 name, isc_result_totext (status));
1067 if (strlen (name) >
sizeof ip -> name) {
1068 memcpy (ip -> name, name, (
sizeof ip -> name) - 1);
1069 ip -> name [(
sizeof ip ->
name) - 1] = 0;
1071 strcpy (ip -> name, name);
1080 interface_reference (&share -> interface, ip,
MDL);
1093 struct lease *comp = (
struct lease *)0;
1096 if (!comp ->
pool) {
1097 log_error (
"undeclared lease found in database: %s",
1100 pool_reference (&lease ->
pool, comp ->
pool,
MDL);
1103 subnet_reference (&lease ->
subnet,
1105 lease_ip_hash_delete(lease_ip_addr_hash,
1106 lease->ip_addr.iabuf, lease->ip_addr.len,
1108 lease_dereference (&comp,
MDL);
1124 lease_ip_hash_add(lease_ip_addr_hash, lease->ip_addr.iabuf,
1125 lease->ip_addr.len, lease,
MDL);
1142 #if defined (FAILOVER_PROTOCOL) 1143 int do_pool_check = 0;
1148 if (pimmediate && !commit)
1171 (((comp -> uid && lease -> uid) &&
1172 (comp -> uid_len != lease -> uid_len ||
1173 memcmp (comp -> uid, lease -> uid, comp -> uid_len))) ||
1175 ((comp -> hardware_addr.hlen !=
1176 lease -> hardware_addr.hlen) ||
1177 memcmp (comp -> hardware_addr.hbuf,
1178 lease -> hardware_addr.hbuf,
1179 comp -> hardware_addr.hlen))))) {
1188 if (comp->uid != comp->uid_buf) {
1193 comp -> uid = (
unsigned char *)0;
1199 if (comp->hardware_addr.hlen)
1203 if (comp -> billing_class != lease -> billing_class) {
1204 if (comp->billing_class)
1206 if (lease -> billing_class)
1211 comp -> starts = lease -> starts;
1213 if (lease -> uid_len <=
sizeof (lease -> uid_buf)) {
1214 memcpy (comp -> uid_buf,
1215 lease -> uid, lease -> uid_len);
1216 comp -> uid = &comp -> uid_buf [0];
1217 comp -> uid_max =
sizeof comp -> uid_buf;
1218 comp -> uid_len = lease -> uid_len;
1219 }
else if (lease -> uid != &lease -> uid_buf [0]) {
1220 comp -> uid = lease -> uid;
1221 comp -> uid_max = lease -> uid_max;
1222 lease -> uid = (
unsigned char *)0;
1223 lease -> uid_max = 0;
1224 comp -> uid_len = lease -> uid_len;
1225 lease -> uid_len = 0;
1230 comp -> uid = (
unsigned char *)0;
1231 comp -> uid_len = comp -> uid_max = 0;
1234 host_dereference (&comp -> host,
MDL);
1235 host_reference (&comp -> host, lease -> host,
MDL);
1236 comp -> hardware_addr = lease -> hardware_addr;
1239 if (lease -> scope) {
1249 if (lease -> next_binding_state ==
FTS_ACTIVE ||
1258 if (comp -> client_hostname)
1259 dfree (comp -> client_hostname,
MDL);
1260 comp -> client_hostname = lease -> client_hostname;
1261 lease -> client_hostname = (
char *)0;
1263 if (lease->on_star.on_expiry) {
1264 if (comp->on_star.on_expiry)
1266 (&comp->on_star.on_expiry,
MDL);
1268 lease->on_star.on_expiry,
1271 if (lease->on_star.on_commit) {
1272 if (comp->on_star.on_commit)
1274 (&comp->on_star.on_commit,
MDL);
1276 lease->on_star.on_commit,
1279 if (lease->on_star.on_release) {
1280 if (comp->on_star.on_release)
1282 (&comp->on_star.on_release,
MDL);
1284 lease->on_star.on_release,
1293 if (comp->hardware_addr.hlen)
1296 comp->cltt = lease->cltt;
1297 #if defined (FAILOVER_PROTOCOL) 1298 comp->tstp = lease->tstp;
1299 comp->tsfp = lease->tsfp;
1300 comp->atsfp = lease->atsfp;
1302 comp->ends = lease->ends;
1303 comp->next_binding_state = lease->next_binding_state;
1312 if (lease->ddns_cb != NULL)
1313 comp->ddns_cb = lease->ddns_cb;
1316 #if defined (FAILOVER_PROTOCOL) 1326 if (!comp ->
pool) {
1327 log_error (
"Supersede_lease: lease %s with no pool.",
1333 switch (comp -> binding_state) {
1336 lq = &comp->pool->reserved;
1338 lq = &comp->pool->free;
1339 comp->pool->free_leases--;
1342 #if defined(FAILOVER_PROTOCOL) 1348 lq = &comp ->
pool -> active;
1354 lq = &comp ->
pool -> expired;
1358 lq = &comp ->
pool -> abandoned;
1363 lq = &comp->pool->reserved;
1365 lq = &comp->pool->backup;
1366 comp->pool->backup_leases--;
1369 #if defined(FAILOVER_PROTOCOL) 1375 log_error (
"Lease with bogus binding state: %d",
1376 comp -> binding_state);
1377 #if defined (BINDING_STATE_DEBUG) 1396 if (commit || !pimmediate)
1415 if ((commit || !pimmediate) &&
1418 (comp -> sort_time < comp ->
pool -> next_event_time ||
1420 comp ->
pool -> next_event_time = comp -> sort_time;
1421 tv . tv_sec = comp ->
pool -> next_event_time;
1430 #if defined(FAILOVER_PROTOCOL) 1440 if (propogate && (comp->pool->failover_peer != NULL) &&
1441 ((comp->pool->failover_peer->service_state ==
1443 (comp->pool->failover_peer->service_state ==
1445 comp->rewind_binding_state = comp->binding_state;
1450 if ((server_starting &
SS_NOSYNC) == 0) {
1456 #if defined (FAILOVER_PROTOCOL) 1458 comp -> desired_binding_state = comp -> binding_state;
1462 if (do_pool_check && comp->pool->failover_peer)
1472 if ((from_pool == 0) &&
1473 (commit || !pimmediate) &&
1475 (comp->next_binding_state != comp->binding_state))
1484 #if defined (FAILOVER_PROTOCOL) 1485 dhcp_failover_state_t *peer;
1487 if (lease ->
pool && lease ->
pool -> failover_peer)
1488 peer = lease ->
pool -> failover_peer;
1490 peer = (dhcp_failover_state_t *)0;
1495 if (lease -> next_binding_state != lease -> binding_state &&
1507 #if defined (NSUPDATE) 1532 if (lease -> client_hostname) {
1533 dfree (lease -> client_hostname,
MDL);
1534 lease -> client_hostname = (
char *)0;
1537 host_dereference (&lease -> host,
MDL);
1540 lease -> tstp = lease -> ends;
1545 if (lease -> next_binding_state != lease -> binding_state &&
1550 (lease -> next_binding_state ==
FTS_FREE ||
1551 lease -> next_binding_state ==
FTS_BACKUP)) ||
1556 #if defined (NSUPDATE) 1596 if (lease -> client_hostname) {
1597 dfree (lease -> client_hostname,
MDL);
1598 lease -> client_hostname = (
char *)0;
1601 host_dereference (&lease -> host,
MDL);
1605 lease -> tstp = lease -> ends;
1608 #if defined (DEBUG_LEASE_STATE_TRANSITIONS) 1609 log_debug (
"lease %s moves from %s to %s",
1615 lease -> binding_state = lease -> next_binding_state;
1616 switch (lease -> binding_state) {
1618 #if defined (FAILOVER_PROTOCOL) 1619 if (lease ->
pool && lease ->
pool -> failover_peer)
1623 lease -> next_binding_state =
FTS_FREE;
1631 #if defined(FAILOVER_PROTOCOL) 1636 if ((lease->
pool != NULL) &&
1647 lease -> next_binding_state = lease -> binding_state;
1650 #if defined (DEBUG_LEASE_STATE_TRANSITIONS) 1651 log_debug (
"lease %s: next binding state %s",
1662 struct lease *lt = (
struct lease *)0;
1663 isc_result_t status;
1665 status = lease_allocate (<,
MDL);
1666 if (status != ISC_R_SUCCESS)
1677 }
else if (!lease ->
uid_max) {
1678 lt ->
uid = (
unsigned char *)0;
1682 lease_dereference (<,
MDL);
1691 lease_dereference (<,
MDL);
1701 host_reference (< ->
host, lease ->
host, file, line);
1702 subnet_reference (< ->
subnet, lease ->
subnet, file, line);
1703 pool_reference (< ->
pool, lease ->
pool, file, line);
1727 status = lease_reference(lp, lt, file, line);
1728 lease_dereference(<,
MDL);
1729 return status == ISC_R_SUCCESS;
1739 #if defined (NSUPDATE) 1742 if (lease->on_star.on_release) {
1745 NULL, &lease->scope,
1746 lease->on_star.on_release, NULL);
1747 if (lease->on_star.on_release)
1749 (&lease->on_star.on_release,
MDL);
1755 if (lease->on_star.on_expiry)
1757 (&lease->on_star.on_expiry,
MDL);
1764 if (lease->on_star.on_commit)
1766 (&lease->on_star.on_commit,
MDL);
1779 #if defined (FAILOVER_PROTOCOL) 1780 if (lease ->
pool && lease ->
pool -> failover_peer) {
1781 dhcp_failover_state_t *peer = NULL;
1783 if (lease->pool != NULL)
1784 peer = lease->pool->failover_peer;
1787 (((peer->i_am == primary) &&
1788 (lease->rewind_binding_state ==
FTS_FREE)) ||
1789 ((peer->i_am == secondary) &&
1790 (lease->rewind_binding_state ==
FTS_BACKUP)))) {
1791 lease->next_binding_state =
1792 lease->rewind_binding_state;
1810 const
char *message;
1812 struct lease *lt = (
struct lease *)0;
1813 #if defined (NSUPDATE) 1826 log_error (
"Abandoning IP address %s: %s",
1831 lt ->
uid = (
unsigned char *)0;
1835 lease_dereference (<,
MDL);
1849 void dissociate_lease (
lease)
1852 struct lease *lt = (
struct lease *)0;
1853 #if defined (NSUPDATE) 1860 #if defined (FAILOVER_PROTOCOL) 1861 if (lease ->
pool && lease ->
pool -> failover_peer) {
1873 lt ->
uid = (
unsigned char *)0;
1877 lease_dereference (<,
MDL);
1886 struct lease *
next = NULL;
1887 struct lease *lease = NULL;
1888 struct lease *ltemp = NULL;
1889 #define FREE_LEASES 0 1890 #define ACTIVE_LEASES 1 1891 #define EXPIRED_LEASES 2 1892 #define ABANDONED_LEASES 3 1893 #define BACKUP_LEASES 4 1894 #define RESERVED_LEASES 5 1900 pool = (
struct pool *)vpool;
1914 #if defined (FAILOVER_PROTOCOL) 1915 if (pool->failover_peer &&
1931 (pool->failover_peer->i_am == secondary) &&
1932 (pool->failover_peer->me.state ==
normal))
1947 lease_dereference(&next,
MDL);
1950 lease_reference(&next, ltemp,
MDL);
1967 #if defined(FAILOVER_PROTOCOL) 1968 dhcp_failover_state_t *peer = NULL;
1970 if (lease->
pool != NULL)
1977 ((peer->i_am == primary &&
1980 (peer->i_am == secondary &&
1989 lease_dereference(&lease,
MDL);
1991 lease_reference(&lease, next,
MDL);
1994 lease_dereference(&next,
MDL);
1996 lease_dereference(&lease,
MDL);
2005 ((pool->next_event_time > next_expiry) ||
2006 (pool->next_event_time <=
cur_time))) {
2007 pool->next_event_time = next_expiry;
2008 tv.tv_sec = pool->next_event_time;
2023 return lease_ip_hash_lookup(lp, lease_ip_addr_hash, addr.
iabuf,
2024 addr.
len, file, line);
2028 unsigned len,
const char *
file,
int line)
2032 return lease_id_hash_lookup (lp, lease_uid_hash, uid, len, file, line);
2036 const unsigned char *hwaddr,
unsigned hwlen,
2049 return (lease_id_hash_lookup(lp, lease_hw_addr_hash, hwaddr, hwlen,
2066 static isc_boolean_t
2067 client_lease_preferred(
struct lease *cand,
struct lease *lease)
2104 struct lease *head = NULL;
2105 struct lease *cand = NULL;
2106 struct lease *
prev = NULL;
2107 struct lease *
next = NULL;
2111 lease_id_hash_add(lease_uid_hash, lease->
uid, lease->
uid_len,
2121 lease_reference(&cand, head,
MDL);
2122 while (cand != NULL) {
2123 if (client_lease_preferred(cand, lease))
2127 lease_dereference(&prev,
MDL);
2128 lease_reference(&prev, cand,
MDL);
2130 if (cand->
n_uid != NULL)
2131 lease_reference(&next, cand->
n_uid,
MDL);
2133 lease_dereference(&cand,
MDL);
2136 lease_reference(&cand, next,
MDL);
2137 lease_dereference(&next,
MDL);
2145 lease_reference(&lease->
n_uid, head,
MDL);
2146 lease_id_hash_delete(lease_uid_hash, lease->
uid,
2148 lease_id_hash_add(lease_uid_hash, lease->
uid,
2151 if(prev->
n_uid != NULL) {
2154 lease_dereference(&prev->
n_uid,
MDL);
2156 lease_reference(&prev->
n_uid, lease,
MDL);
2158 lease_dereference(&prev,
MDL);
2162 lease_dereference(&cand,
MDL);
2163 lease_dereference(&head,
MDL);
2170 struct lease *lease;
2172 struct lease *head = (
struct lease *)0;
2178 lease_dereference (&lease ->
n_uid,
MDL);
2185 if (head == lease) {
2186 lease_id_hash_delete(lease_uid_hash, lease->uid,
2187 lease->uid_len,
MDL);
2188 if (lease ->
n_uid) {
2189 lease_id_hash_add(lease_uid_hash, lease->n_uid->uid,
2190 lease->n_uid->uid_len, lease->n_uid,
2192 lease_dereference (&lease ->
n_uid,
MDL);
2198 for (scan = head; scan ->
n_uid; scan = scan ->
n_uid) {
2199 if (scan ->
n_uid == lease) {
2200 lease_dereference (&scan ->
n_uid,
MDL);
2201 if (lease ->
n_uid) {
2202 lease_reference (&scan ->
n_uid,
2204 lease_dereference (&lease ->
n_uid,
2211 lease_dereference (&head,
MDL);
2221 struct lease *head = NULL;
2222 struct lease *cand = NULL;
2223 struct lease *
prev = NULL;
2224 struct lease *
next = NULL;
2237 lease_id_hash_add(lease_hw_addr_hash,
2248 lease_reference(&cand, head,
MDL);
2249 while (cand != NULL) {
2250 if (client_lease_preferred(cand, lease))
2254 lease_dereference(&prev,
MDL);
2255 lease_reference(&prev, cand,
MDL);
2257 if (cand->
n_hw != NULL)
2258 lease_reference(&next, cand->
n_hw,
MDL);
2260 lease_dereference(&cand,
MDL);
2263 lease_reference(&cand, next,
MDL);
2264 lease_dereference(&next,
MDL);
2272 lease_reference(&lease->
n_hw, head,
MDL);
2273 lease_id_hash_delete(lease_hw_addr_hash,
2276 lease_id_hash_add(lease_hw_addr_hash,
2281 if(prev->
n_hw != NULL) {
2282 lease_reference(&lease->
n_hw, prev->
n_hw,
2284 lease_dereference(&prev->
n_hw,
MDL);
2286 lease_reference(&prev->
n_hw, lease,
MDL);
2288 lease_dereference(&prev,
MDL);
2292 lease_dereference(&cand,
MDL);
2293 lease_dereference(&head,
MDL);
2300 struct lease *lease;
2302 struct lease *head = (
struct lease *)0;
2303 struct lease *
next = (
struct lease *)0;
2309 if ((lease->hardware_addr.hlen == 1) &&
2317 lease_dereference (&lease ->
n_hw,
MDL);
2324 if (head == lease) {
2325 lease_id_hash_delete(lease_hw_addr_hash,
2326 lease->hardware_addr.hbuf,
2327 lease->hardware_addr.hlen,
MDL);
2329 lease_id_hash_add(lease_hw_addr_hash,
2330 lease->n_hw->hardware_addr.hbuf,
2331 lease->n_hw->hardware_addr.hlen,
2333 lease_dereference(&lease->n_hw,
MDL);
2339 while (head ->
n_hw) {
2340 if (head ->
n_hw == lease) {
2341 lease_dereference (&head ->
n_hw,
MDL);
2342 if (lease ->
n_hw) {
2343 lease_reference (&head ->
n_hw,
2345 lease_dereference (&lease ->
n_hw,
2350 lease_reference (&next, head ->
n_hw,
MDL);
2351 lease_dereference (&head,
MDL);
2352 lease_reference (&head, next,
MDL);
2353 lease_dereference (&next,
MDL);
2357 lease_dereference (&head,
MDL);
2366 int num_written = 0, i;
2369 for (s = shared_networks; s; s = s->
next) {
2382 #if !defined (DEBUG_DUMP_ALL_LEASES) 2396 log_info (
"Wrote %d leases to leases file.", num_written);
2416 for (cp = colp->
classes ; cp ; cp = cp->
nic) {
2418 (
unsigned char *)cp->
name,
2424 log_info (
"Wrote %d class decls to leases file.",
2434 hb; hb = hb ->
next) {
2445 log_info (
"Wrote %d group decls to leases file.", num_written);
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) {
2463 log_info (
"Wrote %d deleted host decls to leases file.",
2468 if (host_name_hash) {
2470 for (i = 0; i < host_name_hash -> hash_count; i++) {
2471 for (hb = host_name_hash -> buckets [i];
2472 hb; hb = hb ->
next) {
2480 log_info (
"Wrote %d new dynamic host decls to leases file.",
2484 #if defined (FAILOVER_PROTOCOL) 2508 #if !defined (BINARY_LEASES) 2511 struct lease *lp, *ln = NULL;
2524 lease_reference(&lp, *lq,
MDL);
2525 lease_dereference(lq,
MDL);
2530 lease_reference(&ln, lp->
next,
MDL);
2531 lease_dereference(&lp->
next,
MDL);
2535 lease_dereference(&lp,
MDL);
2540 }
while (lp != NULL);
2551 struct lease *
prev, *lp;
2554 for (lp = *lq; lp != NULL; lp = lp->
next) {
2561 log_fatal(
"Lease with binding state %s not on its queue.",
2569 lease_dereference(&prev->
next,
MDL);
2572 lease_dereference (&comp->
next,
MDL);
2575 lease_dereference(lq,
MDL);
2577 lease_reference(lq, comp->
next,
MDL);
2578 lease_dereference(&comp->
next,
MDL);
2589 struct lease *
prev, *lp;
2590 static struct lease **last_lq = NULL;
2591 static struct lease *last_insert_point = NULL;
2598 if ((server_starting &
SS_QFOLLOW) && (lq == last_lq) &&
2599 (comp != last_insert_point) &&
2601 prev = last_insert_point;
2609 for (; lp != NULL ; lp = lp->
next) {
2618 lease_dereference(&prev->
next,
MDL);
2620 lease_reference(&prev->
next, comp,
MDL);
2623 lease_reference (&comp->
next, *lq,
MDL);
2624 lease_dereference(lq,
MDL);
2626 lease_reference(lq, comp,
MDL);
2628 last_insert_point = comp;
2668 lq = &comp ->
pool -> active;
2675 lq = &comp ->
pool -> expired;
2676 #if defined(FAILOVER_PROTOCOL) 2700 lq = &comp ->
pool -> abandoned;
2715 log_error (
"Lease with bogus binding state: %d",
2717 #if defined (BINDING_STATE_DEBUG) 2735 struct lease *lease = object;
2736 struct class *
class;
2740 if (!lease ->
pool) {
2741 lease_ip_hash_delete(lease_ip_addr_hash, lease->
ip_addr.
iabuf,
2743 return ISC_R_SUCCESS;
2746 #if defined (FAILOVER_PROTOCOL) 2769 return ISC_R_SUCCESS;
2777 if (lease -> hardware_addr.hlen) {
2782 if (lease -> billing_class) {
2783 class = (struct class *)0;
2784 class_reference (&
class, lease -> billing_class,
MDL);
2785 class_dereference (&lease -> billing_class,
MDL);
2793 class_dereference (&
class,
MDL);
2795 return ISC_R_SUCCESS;
2814 #if defined (BINARY_LEASES) 2820 for (s = shared_networks; s; s = s ->
next) {
2821 for (p = s ->
pools; p != NULL; p = p ->
next) {
2822 size_t num_f = 100, num_a = 50, num_e = 20;
2849 for (s = shared_networks; s; s = s ->
next) {
2850 for (p = s ->
pools; p; p = p ->
next) {
2853 p -> lease_count = 0;
2854 p -> free_leases = 0;
2855 p -> backup_leases = 0;
2884 #if defined (FAILOVER_PROTOCOL) 2885 if (p -> failover_peer &&
2898 server_starting = 0;
2911 for (n = subnets; n; n = n -> next_subnet) {
2917 for (s = shared_networks; s; s = s ->
next) {
2919 for (p = s ->
pools; p; p = p ->
next) {
2941 lease_reference, lease_dereference,
do_id_hash)
2947 #if defined (DEBUG_MEMORY_LEAKAGE) && \ 2948 defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT) 2961 #if defined (COMPACT_LEASES) 2962 extern struct lease *lease_hunks;
2965 void free_everything(
void)
2970 struct pool *pc = (
struct pool *)0, *pn = (
struct pool *)0;
2971 struct lease *
lc = NULL, *ln = NULL, *ltemp = NULL;
2974 struct class *cc = (
struct class *)0, *cn = (
struct class *)0;
2979 if (host_hw_addr_hash)
2980 host_free_hash_table (&host_hw_addr_hash,
MDL);
2981 host_hw_addr_hash = 0;
2983 host_free_hash_table (&host_uid_hash,
MDL);
2986 lease_id_free_hash_table (&lease_uid_hash,
MDL);
2988 if (lease_ip_addr_hash)
2989 lease_ip_free_hash_table (&lease_ip_addr_hash,
MDL);
2990 lease_ip_addr_hash = 0;
2991 if (lease_hw_addr_hash)
2992 lease_id_free_hash_table (&lease_hw_addr_hash,
MDL);
2993 lease_hw_addr_hash = 0;
2995 host_free_hash_table (&host_name_hash,
MDL);
2998 dns_zone_free_hash_table (&dns_zone_hash,
MDL);
3001 while (host_id_info != NULL) {
3005 tmp = host_id_info->
next;
3011 auth_key_free_hash_table (&auth_key_hash,
MDL);
3023 class_reference (&cc, cn,
MDL);
3024 class_dereference (&cn,
MDL);
3027 class_reference (&cn, cc -> nic,
MDL);
3028 class_dereference (&cc -> nic,
MDL);
3032 class_free_hash_table (&cc -> hash,
MDL);
3035 class_dereference (&cc,
MDL);
3037 class_dereference (&lp -> classes,
MDL);
3041 if (interface_vector) {
3043 if (interface_vector [i])
3044 interface_dereference (&interface_vector [i],
MDL);
3047 interface_vector = 0;
3054 interface_reference (&ic, in,
MDL);
3055 interface_dereference (&in,
MDL);
3058 interface_reference (&in, ic ->
next,
MDL);
3059 interface_dereference (&ic ->
next,
MDL);
3064 interface_dereference
3068 interface_dereference (&ic,
MDL);
3075 subnet_reference (&sn, subnets,
MDL);
3078 subnet_reference (&sc, sn,
MDL);
3079 subnet_dereference (&sn,
MDL);
3081 if (sc -> next_subnet) {
3082 subnet_reference (&sn, sc -> next_subnet,
MDL);
3083 subnet_dereference (&sc -> next_subnet,
MDL);
3085 if (sc -> next_sibling)
3086 subnet_dereference (&sc -> next_sibling,
MDL);
3090 if (sc -> interface)
3091 interface_dereference (&sc -> interface,
MDL);
3092 subnet_dereference (&sc,
MDL);
3094 subnet_dereference (&subnets,
MDL);
3103 if (shared_networks) {
3104 shared_network_dereference (&shared_networks,
MDL);
3107 shared_network_reference (&nn, shared_networks,
MDL);
3110 shared_network_reference (&nc, nn,
MDL);
3111 shared_network_dereference (&nn,
MDL);
3114 shared_network_reference (&nn, nc ->
next,
MDL);
3115 shared_network_dereference (&nc ->
next,
MDL);
3120 pool_reference (&pn, nc ->
pools,
MDL);
3125 pool_reference (&pc, pn,
MDL);
3126 pool_dereference (&pn,
MDL);
3129 pool_reference (&pn, pc ->
next,
MDL);
3130 pool_dereference (&pc ->
next,
MDL);
3146 lease_reference (&lc, ln,
MDL);
3147 lease_dereference (&ln,
MDL);
3151 if (ltemp != NULL) {
3152 lease_reference(&ln, ltemp,
MDL);
3158 if (lc -> billing_class)
3159 class_dereference (&lc -> billing_class,
3165 lease_dereference (&lc -> n_hw,
MDL);
3167 lease_dereference (&lc -> n_uid,
MDL);
3168 lease_dereference (&lc,
MDL);
3177 pool_dereference (&pc,
MDL);
3179 pool_dereference (&nc ->
pools,
MDL);
3184 shared_network_dereference (&nc,
MDL);
3186 shared_network_dereference (&shared_networks,
MDL);
3191 #if defined(DELAYED_ACK) 3192 relinquish_ackqueue();
3207 universe_free_hash_table (&universe_hash,
MDL);
3215 if (universes [i]) {
3216 if (universes[i]->name_hash)
3217 option_name_free_hash_table(
3218 &universes[i]->name_hash,
3220 if (universes[i]->code_hash)
3221 option_code_free_hash_table(
3222 &universes[i]->code_hash,
3225 if (universes [i] -> name > (
char *)&end) {
3226 foo.c = universes [i] -> name;
3229 if (universes [i] > (
struct universe *)&end)
3236 relinquish_free_lease_states ();
3237 relinquish_free_pairs ();
3238 relinquish_free_expressions ();
3239 relinquish_free_binding_values ();
3240 relinquish_free_option_caches ();
3241 relinquish_free_packets ();
3242 #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)
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 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 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 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)
#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)
void lease_remove_all(struct lease **lq)
#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)
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
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 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)
void lease_insert(struct lease **lq, struct lease *comp)
void trace_free_all(void)
struct packet * dhcpv6_container_packet
isc_result_t enter_host(struct host_decl *hd, int dynamicp, int commit)