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 = NULL;
1813 #if defined (NSUPDATE) 1845 lease_dereference(<,
MDL);
1859 void dissociate_lease (
lease)
1862 struct lease *lt = (
struct lease *)0;
1863 #if defined (NSUPDATE) 1870 #if defined (FAILOVER_PROTOCOL) 1871 if (lease ->
pool && lease ->
pool -> failover_peer) {
1883 lt ->
uid = (
unsigned char *)0;
1887 lease_dereference (<,
MDL);
1896 struct lease *
next = NULL;
1897 struct lease *lease = NULL;
1898 struct lease *ltemp = NULL;
1899 #define FREE_LEASES 0 1900 #define ACTIVE_LEASES 1 1901 #define EXPIRED_LEASES 2 1902 #define ABANDONED_LEASES 3 1903 #define BACKUP_LEASES 4 1904 #define RESERVED_LEASES 5 1910 pool = (
struct pool *)vpool;
1924 #if defined (FAILOVER_PROTOCOL) 1925 if (pool->failover_peer &&
1941 (pool->failover_peer->i_am == secondary) &&
1942 (pool->failover_peer->me.state ==
normal))
1957 lease_dereference(&next,
MDL);
1960 lease_reference(&next, ltemp,
MDL);
1977 #if defined(FAILOVER_PROTOCOL) 1978 dhcp_failover_state_t *peer = NULL;
1980 if (lease->
pool != NULL)
1987 ((peer->i_am == primary &&
1990 (peer->i_am == secondary &&
1999 lease_dereference(&lease,
MDL);
2001 lease_reference(&lease, next,
MDL);
2004 lease_dereference(&next,
MDL);
2006 lease_dereference(&lease,
MDL);
2015 ((pool->next_event_time > next_expiry) ||
2016 (pool->next_event_time <=
cur_time))) {
2017 pool->next_event_time = next_expiry;
2018 tv.tv_sec = pool->next_event_time;
2033 return lease_ip_hash_lookup(lp, lease_ip_addr_hash, addr.
iabuf,
2034 addr.
len, file, line);
2038 unsigned len,
const char *
file,
int line)
2042 return lease_id_hash_lookup (lp, lease_uid_hash, uid, len, file, line);
2046 const unsigned char *hwaddr,
unsigned hwlen,
2059 return (lease_id_hash_lookup(lp, lease_hw_addr_hash, hwaddr, hwlen,
2076 static isc_boolean_t
2077 client_lease_preferred(
struct lease *cand,
struct lease *lease)
2114 struct lease *head = NULL;
2115 struct lease *cand = NULL;
2116 struct lease *
prev = NULL;
2117 struct lease *
next = NULL;
2121 lease_id_hash_add(lease_uid_hash, lease->
uid, lease->
uid_len,
2131 lease_reference(&cand, head,
MDL);
2132 while (cand != NULL) {
2133 if (client_lease_preferred(cand, lease))
2137 lease_dereference(&prev,
MDL);
2138 lease_reference(&prev, cand,
MDL);
2140 if (cand->
n_uid != NULL)
2141 lease_reference(&next, cand->
n_uid,
MDL);
2143 lease_dereference(&cand,
MDL);
2146 lease_reference(&cand, next,
MDL);
2147 lease_dereference(&next,
MDL);
2155 lease_reference(&lease->
n_uid, head,
MDL);
2156 lease_id_hash_delete(lease_uid_hash, lease->
uid,
2158 lease_id_hash_add(lease_uid_hash, lease->
uid,
2161 if(prev->
n_uid != NULL) {
2164 lease_dereference(&prev->
n_uid,
MDL);
2166 lease_reference(&prev->
n_uid, lease,
MDL);
2168 lease_dereference(&prev,
MDL);
2172 lease_dereference(&cand,
MDL);
2173 lease_dereference(&head,
MDL);
2180 struct lease *lease;
2182 struct lease *head = (
struct lease *)0;
2188 lease_dereference (&lease ->
n_uid,
MDL);
2195 if (head == lease) {
2196 lease_id_hash_delete(lease_uid_hash, lease->uid,
2197 lease->uid_len,
MDL);
2198 if (lease ->
n_uid) {
2199 lease_id_hash_add(lease_uid_hash, lease->n_uid->uid,
2200 lease->n_uid->uid_len, lease->n_uid,
2202 lease_dereference (&lease ->
n_uid,
MDL);
2208 for (scan = head; scan ->
n_uid; scan = scan ->
n_uid) {
2209 if (scan ->
n_uid == lease) {
2210 lease_dereference (&scan ->
n_uid,
MDL);
2211 if (lease ->
n_uid) {
2212 lease_reference (&scan ->
n_uid,
2214 lease_dereference (&lease ->
n_uid,
2221 lease_dereference (&head,
MDL);
2231 struct lease *head = NULL;
2232 struct lease *cand = NULL;
2233 struct lease *
prev = NULL;
2234 struct lease *
next = NULL;
2247 lease_id_hash_add(lease_hw_addr_hash,
2258 lease_reference(&cand, head,
MDL);
2259 while (cand != NULL) {
2260 if (client_lease_preferred(cand, lease))
2264 lease_dereference(&prev,
MDL);
2265 lease_reference(&prev, cand,
MDL);
2267 if (cand->
n_hw != NULL)
2268 lease_reference(&next, cand->
n_hw,
MDL);
2270 lease_dereference(&cand,
MDL);
2273 lease_reference(&cand, next,
MDL);
2274 lease_dereference(&next,
MDL);
2282 lease_reference(&lease->
n_hw, head,
MDL);
2283 lease_id_hash_delete(lease_hw_addr_hash,
2286 lease_id_hash_add(lease_hw_addr_hash,
2291 if(prev->
n_hw != NULL) {
2292 lease_reference(&lease->
n_hw, prev->
n_hw,
2294 lease_dereference(&prev->
n_hw,
MDL);
2296 lease_reference(&prev->
n_hw, lease,
MDL);
2298 lease_dereference(&prev,
MDL);
2302 lease_dereference(&cand,
MDL);
2303 lease_dereference(&head,
MDL);
2310 struct lease *lease;
2312 struct lease *head = (
struct lease *)0;
2313 struct lease *
next = (
struct lease *)0;
2319 if ((lease->hardware_addr.hlen == 1) &&
2327 lease_dereference (&lease ->
n_hw,
MDL);
2334 if (head == lease) {
2335 lease_id_hash_delete(lease_hw_addr_hash,
2336 lease->hardware_addr.hbuf,
2337 lease->hardware_addr.hlen,
MDL);
2339 lease_id_hash_add(lease_hw_addr_hash,
2340 lease->n_hw->hardware_addr.hbuf,
2341 lease->n_hw->hardware_addr.hlen,
2343 lease_dereference(&lease->n_hw,
MDL);
2349 while (head ->
n_hw) {
2350 if (head ->
n_hw == lease) {
2351 lease_dereference (&head ->
n_hw,
MDL);
2352 if (lease ->
n_hw) {
2353 lease_reference (&head ->
n_hw,
2355 lease_dereference (&lease ->
n_hw,
2360 lease_reference (&next, head ->
n_hw,
MDL);
2361 lease_dereference (&head,
MDL);
2362 lease_reference (&head, next,
MDL);
2363 lease_dereference (&next,
MDL);
2367 lease_dereference (&head,
MDL);
2376 int num_written = 0, i;
2379 for (s = shared_networks; s; s = s->
next) {
2392 #if !defined (DEBUG_DUMP_ALL_LEASES) 2406 log_info (
"Wrote %d leases to leases file.", num_written);
2426 for (cp = colp->
classes ; cp ; cp = cp->
nic) {
2428 (
unsigned char *)cp->
name,
2434 log_info (
"Wrote %d class decls to leases file.",
2444 hb; hb = hb ->
next) {
2455 log_info (
"Wrote %d group decls to leases file.", num_written);
2459 if (host_name_hash) {
2461 for (i = 0; i < host_name_hash -> hash_count; i++) {
2462 for (hb = host_name_hash -> buckets [i];
2463 hb; hb = hb ->
next) {
2473 log_info (
"Wrote %d deleted host decls to leases file.",
2478 if (host_name_hash) {
2480 for (i = 0; i < host_name_hash -> hash_count; i++) {
2481 for (hb = host_name_hash -> buckets [i];
2482 hb; hb = hb ->
next) {
2490 log_info (
"Wrote %d new dynamic host decls to leases file.",
2494 #if defined (FAILOVER_PROTOCOL) 2518 #if !defined (BINARY_LEASES) 2521 struct lease *lp, *ln = NULL;
2534 lease_reference(&lp, *lq,
MDL);
2535 lease_dereference(lq,
MDL);
2540 lease_reference(&ln, lp->
next,
MDL);
2541 lease_dereference(&lp->
next,
MDL);
2545 lease_dereference(&lp,
MDL);
2550 }
while (lp != NULL);
2561 struct lease *
prev, *lp;
2564 for (lp = *lq; lp != NULL; lp = lp->
next) {
2571 log_fatal(
"Lease with binding state %s not on its queue.",
2579 lease_dereference(&prev->
next,
MDL);
2582 lease_dereference (&comp->
next,
MDL);
2585 lease_dereference(lq,
MDL);
2587 lease_reference(lq, comp->
next,
MDL);
2588 lease_dereference(&comp->
next,
MDL);
2599 struct lease *
prev, *lp;
2600 static struct lease **last_lq = NULL;
2601 static struct lease *last_insert_point = NULL;
2608 if ((server_starting &
SS_QFOLLOW) && (lq == last_lq) &&
2609 (comp != last_insert_point) &&
2611 prev = last_insert_point;
2619 for (; lp != NULL ; lp = lp->
next) {
2628 lease_dereference(&prev->
next,
MDL);
2630 lease_reference(&prev->
next, comp,
MDL);
2633 lease_reference (&comp->
next, *lq,
MDL);
2634 lease_dereference(lq,
MDL);
2636 lease_reference(lq, comp,
MDL);
2638 last_insert_point = comp;
2678 lq = &comp ->
pool -> active;
2685 lq = &comp ->
pool -> expired;
2686 #if defined(FAILOVER_PROTOCOL) 2710 lq = &comp ->
pool -> abandoned;
2725 log_error (
"Lease with bogus binding state: %d",
2727 #if defined (BINDING_STATE_DEBUG) 2745 struct lease *lease = object;
2746 struct class *
class;
2750 if (!lease ->
pool) {
2751 lease_ip_hash_delete(lease_ip_addr_hash, lease->
ip_addr.
iabuf,
2753 return ISC_R_SUCCESS;
2756 #if defined (FAILOVER_PROTOCOL) 2779 return ISC_R_SUCCESS;
2787 if (lease -> hardware_addr.hlen) {
2792 if (lease -> billing_class) {
2793 class = (struct class *)0;
2794 class_reference (&
class, lease -> billing_class,
MDL);
2795 class_dereference (&lease -> billing_class,
MDL);
2803 class_dereference (&
class,
MDL);
2805 return ISC_R_SUCCESS;
2824 #if defined (BINARY_LEASES) 2830 for (s = shared_networks; s; s = s ->
next) {
2831 for (p = s ->
pools; p != NULL; p = p ->
next) {
2832 size_t num_f = 100, num_a = 50, num_e = 20;
2859 for (s = shared_networks; s; s = s ->
next) {
2860 for (p = s ->
pools; p; p = p ->
next) {
2863 p -> lease_count = 0;
2864 p -> free_leases = 0;
2865 p -> backup_leases = 0;
2894 #if defined (FAILOVER_PROTOCOL) 2895 if (p -> failover_peer &&
2908 server_starting = 0;
2921 for (n = subnets; n; n = n -> next_subnet) {
2927 for (s = shared_networks; s; s = s ->
next) {
2929 for (p = s ->
pools; p; p = p ->
next) {
2951 lease_reference, lease_dereference,
do_id_hash)
2957 #if defined (DEBUG_MEMORY_LEAKAGE) && \ 2958 defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT) 2971 #if defined (COMPACT_LEASES) 2972 extern struct lease *lease_hunks;
2975 void free_everything(
void)
2980 struct pool *pc = (
struct pool *)0, *pn = (
struct pool *)0;
2981 struct lease *
lc = NULL, *ln = NULL, *ltemp = NULL;
2984 struct class *cc = (
struct class *)0, *cn = (
struct class *)0;
2989 if (host_hw_addr_hash)
2990 host_free_hash_table (&host_hw_addr_hash,
MDL);
2991 host_hw_addr_hash = 0;
2993 host_free_hash_table (&host_uid_hash,
MDL);
2996 lease_id_free_hash_table (&lease_uid_hash,
MDL);
2998 if (lease_ip_addr_hash)
2999 lease_ip_free_hash_table (&lease_ip_addr_hash,
MDL);
3000 lease_ip_addr_hash = 0;
3001 if (lease_hw_addr_hash)
3002 lease_id_free_hash_table (&lease_hw_addr_hash,
MDL);
3003 lease_hw_addr_hash = 0;
3005 host_free_hash_table (&host_name_hash,
MDL);
3008 dns_zone_free_hash_table (&dns_zone_hash,
MDL);
3011 while (host_id_info != NULL) {
3015 tmp = host_id_info->
next;
3021 auth_key_free_hash_table (&auth_key_hash,
MDL);
3033 class_reference (&cc, cn,
MDL);
3034 class_dereference (&cn,
MDL);
3037 class_reference (&cn, cc -> nic,
MDL);
3038 class_dereference (&cc -> nic,
MDL);
3042 class_free_hash_table (&cc -> hash,
MDL);
3045 class_dereference (&cc,
MDL);
3047 class_dereference (&lp -> classes,
MDL);
3051 if (interface_vector) {
3053 if (interface_vector [i])
3054 interface_dereference (&interface_vector [i],
MDL);
3057 interface_vector = 0;
3064 interface_reference (&ic, in,
MDL);
3065 interface_dereference (&in,
MDL);
3068 interface_reference (&in, ic ->
next,
MDL);
3069 interface_dereference (&ic ->
next,
MDL);
3074 interface_dereference
3078 interface_dereference (&ic,
MDL);
3085 subnet_reference (&sn, subnets,
MDL);
3088 subnet_reference (&sc, sn,
MDL);
3089 subnet_dereference (&sn,
MDL);
3091 if (sc -> next_subnet) {
3092 subnet_reference (&sn, sc -> next_subnet,
MDL);
3093 subnet_dereference (&sc -> next_subnet,
MDL);
3095 if (sc -> next_sibling)
3096 subnet_dereference (&sc -> next_sibling,
MDL);
3100 if (sc -> interface)
3101 interface_dereference (&sc -> interface,
MDL);
3102 subnet_dereference (&sc,
MDL);
3104 subnet_dereference (&subnets,
MDL);
3113 if (shared_networks) {
3114 shared_network_dereference (&shared_networks,
MDL);
3117 shared_network_reference (&nn, shared_networks,
MDL);
3120 shared_network_reference (&nc, nn,
MDL);
3121 shared_network_dereference (&nn,
MDL);
3124 shared_network_reference (&nn, nc ->
next,
MDL);
3125 shared_network_dereference (&nc ->
next,
MDL);
3130 pool_reference (&pn, nc ->
pools,
MDL);
3135 pool_reference (&pc, pn,
MDL);
3136 pool_dereference (&pn,
MDL);
3139 pool_reference (&pn, pc ->
next,
MDL);
3140 pool_dereference (&pc ->
next,
MDL);
3156 lease_reference (&lc, ln,
MDL);
3157 lease_dereference (&ln,
MDL);
3161 if (ltemp != NULL) {
3162 lease_reference(&ln, ltemp,
MDL);
3168 if (lc -> billing_class)
3169 class_dereference (&lc -> billing_class,
3175 lease_dereference (&lc -> n_hw,
MDL);
3177 lease_dereference (&lc -> n_uid,
MDL);
3178 lease_dereference (&lc,
MDL);
3187 pool_dereference (&pc,
MDL);
3189 pool_dereference (&nc ->
pools,
MDL);
3194 shared_network_dereference (&nc,
MDL);
3196 shared_network_dereference (&shared_networks,
MDL);
3201 #if defined(DELAYED_ACK) 3202 relinquish_ackqueue();
3217 universe_free_hash_table (&universe_hash,
MDL);
3225 if (universes [i]) {
3226 if (universes[i]->name_hash)
3227 option_name_free_hash_table(
3228 &universes[i]->name_hash,
3230 if (universes[i]->code_hash)
3231 option_code_free_hash_table(
3232 &universes[i]->code_hash,
3235 if (universes [i] -> name > (
char *)&end) {
3236 foo.c = universes [i] -> name;
3239 if (universes [i] > (
struct universe *)&end)
3246 relinquish_free_lease_states ();
3247 relinquish_free_pairs ();
3248 relinquish_free_expressions ();
3249 relinquish_free_binding_values ();
3250 relinquish_free_option_caches ();
3251 relinquish_free_packets ();
3252 #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)
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)
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
void * dmalloc(size_t, const char *, int)
struct interface_info * interfaces
int addr_eq(struct iaddr addr1, struct iaddr addr2)
unsigned do_ip4_hash(const void *, unsigned, unsigned)
int executable_statement_foreach(struct executable_statement *stmt, int(*callback)(struct executable_statement *, void *, int), void *vp, int condp)
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
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)
u_int32_t abandon_lease_time
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)
void trace_free_all(void)
struct packet * dhcpv6_container_packet
isc_result_t enter_host(struct host_decl *hd, int dynamicp, int commit)