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;
121 static int server_starting = 0;
129 esp ->
data.option &&
135 log_error (
"dhcp client identifier may not be %s",
136 "specified conditionally.");
137 }
else if (!(*evp)) {
141 log_error (
"only one dhcp client identifier may be %s",
150 find_host_id_info(
unsigned int option_code,
int relays) {
153 for (p = host_id_info; p != NULL; p = p->
next) {
165 print_host(
const void *
name,
unsigned len,
void *value) {
167 printf(
"--------------\n");
169 printf(
"len:%d\n", len);
171 printf(
"host @%p is '%s'\n", h, h->
name);
178 printf(
"--------------\n");
185 if (host_uid_hash == NULL) {
187 log_fatal(
"Can't allocate host/uid hash");
195 host_hash_delete(host_uid_hash,
230 if (!host_name_hash) {
232 log_fatal (
"Can't allocate host name hash");
233 host_hash_add (host_name_hash,
234 (
unsigned char *)hd -> name,
235 strlen (hd -> name), hd,
MDL);
237 host_hash_lookup (&hp, host_name_hash,
238 (
unsigned char *)hd -> name,
239 strlen (hd -> name),
MDL);
243 host_hash_delete (host_name_hash,
244 (
unsigned char *)hd -> name,
245 strlen (hd -> name),
MDL);
251 host_dereference (&hp,
MDL);
256 if (hp && hp == hd) {
257 host_dereference (&hp,
MDL);
260 return ISC_R_IOERROR;
261 hd -> flags &= ~HOST_DECL_DELETED;
267 host_hash_add (host_name_hash,
268 (
unsigned char *)hd -> name,
269 strlen (hd -> name), hd,
MDL);
273 host_dereference (&hp,
MDL);
279 host_dereference (&hd -> n_ipaddr,
MDL);
284 if (hd -> interface.hlen) {
285 if (!host_hw_addr_hash) {
286 if (!host_new_hash(&host_hw_addr_hash,
288 log_fatal (
"Can't allocate host/hw hash");
292 host_hash_lookup (&hp, host_hw_addr_hash,
293 hd -> interface.hbuf,
294 hd -> interface.hlen,
MDL);
297 host_hash_add (host_hw_addr_hash, hd -> interface.hbuf,
298 hd -> interface.hlen, hd,
MDL);
303 for (np = hp; np -> n_ipaddr; np = np -> n_ipaddr)
305 host_reference (&np -> n_ipaddr, hd,
MDL);
306 host_dereference (&hp,
MDL);
315 find_uid_statement, &esp, 0)) {
317 NULL, NULL, NULL, NULL, NULL,
324 if (hd -> client_identifier.len) {
327 if (!host_uid_hash) {
328 if (!host_new_hash(&host_uid_hash,
330 log_fatal (
"Can't allocate host/uid hash");
332 host_hash_add (host_uid_hash,
333 hd -> client_identifier.data,
334 hd -> client_identifier.len,
340 if (host_hash_lookup (&hp, host_uid_hash,
341 hd -> client_identifier.data,
342 hd -> client_identifier.len,
346 for (np = hp; np -> n_ipaddr;
347 np = np -> n_ipaddr) {
352 host_reference (&np -> n_ipaddr,
355 host_dereference (&hp,
MDL);
357 host_hash_add (host_uid_hash,
358 hd -> client_identifier.data,
359 hd -> client_identifier.len,
369 if (hd->host_id_option != NULL) {
374 h_id_info = find_host_id_info(hd->host_id_option->code,
376 if (h_id_info == NULL) {
378 if (h_id_info == NULL) {
379 log_fatal(
"No memory for host-identifier "
380 "option information.");
383 hd->host_id_option,
MDL);
386 log_fatal(
"No memory for host-identifier "
389 h_id_info->
relays = hd->relays;
390 h_id_info->
next = host_id_info;
391 host_id_info = h_id_info;
395 hd->host_id.data, hd->host_id.len,
MDL)) {
415 host_dereference(&hp,
MDL);
424 if (dynamicp && commit) {
426 return ISC_R_IOERROR;
428 return ISC_R_IOERROR;
447 return ISC_R_IOERROR;
453 if (cp->superclass) {
454 class_hash_delete(cp->superclass->hash,
455 (
const char *)cp->hash_string.data,
474 int hw_head = 0, uid_head = 1;
484 if (host_hw_addr_hash) {
485 if (host_hash_lookup (&hp, host_hw_addr_hash,
489 host_hash_delete (host_hw_addr_hash,
496 host_reference (&foo, hp,
MDL);
501 host_dereference (&np,
MDL);
502 host_reference (&np, foo,
MDL);
503 host_dereference (&foo,
MDL);
513 host_dereference (&foo,
MDL);
516 host_dereference (&np,
MDL);
518 host_dereference (&hp,
MDL);
527 if (host_hash_lookup (&hp, host_uid_hash,
531 host_hash_delete (host_uid_hash,
538 host_reference (&foo, hp,
MDL);
543 host_dereference (&np,
MDL);
544 host_reference (&np, foo,
MDL);
545 host_dereference (&foo,
MDL);
555 host_dereference (&foo,
MDL);
558 host_dereference (&np,
MDL);
560 host_dereference (&hp,
MDL);
565 if (hd->host_id_option != NULL) {
579 host_hash_add (host_hw_addr_hash,
587 if (host_name_hash) {
588 if (host_hash_lookup (&hp, host_name_hash,
589 (
unsigned char *)hd -> name,
590 strlen (hd -> name),
MDL)) {
592 host_hash_delete (host_name_hash,
593 (
unsigned char *)hd -> name,
594 strlen (hd -> name),
MDL);
596 host_dereference (&hp,
MDL);
602 return ISC_R_IOERROR;
604 return ISC_R_IOERROR;
610 const unsigned char *haddr,
unsigned hlen,
614 #if defined(LDAP_CONFIGURATION)
617 if ((ret = find_haddr_in_ldap (hp, htype, hlen, haddr, file, line)))
623 memcpy (&h.
hbuf [1], haddr, hlen);
625 return host_hash_lookup (hp, host_hw_addr_hash,
630 const unsigned char *data,
unsigned len,
633 return host_hash_lookup (hp, host_uid_hash, data, len, file, line);
645 struct packet *relay_packet;
648 #if defined(LDAP_CONFIGURATION)
649 if ((found = find_client_in_ldap (hp, packet, opt_state, file, line)))
653 for (p = host_id_info; p != NULL; p = p->
next) {
654 relay_packet = packet;
655 relay_state = opt_state;
675 relay_state = relay_packet->
options;
681 memset(&data, 0,
sizeof(data));
684 NULL, relay_state, NULL,
687 log_error(
"Error evaluating option cache");
717 struct iaddr ip_address;
721 memset (&fixed_addr, 0,
sizeof fixed_addr);
723 for (hp = *host; hp; hp = hp -> n_ipaddr) {
724 if (!hp -> fixed_addr)
732 hp -> fixed_addr,
MDL))
734 for (i = 0; i < fixed_addr.
len; i += 4) {
736 memcpy (ip_address.
iabuf,
737 fixed_addr.
data + i, 4);
746 host_reference (&tmp, *host,
MDL);
747 host_dereference (host,
MDL);
748 host_reference (host, hp,
MDL);
749 host_dereference (&tmp,
MDL);
761 struct
iaddr low, high;
764 struct
lease **lpchain;
766 #if defined(COMPACT_LEASES)
767 struct lease *address_range;
770 unsigned min, max, i, num_addrs;
771 char lowbuf [16], highbuf [16], netbuf [16];
774 #if !defined(COMPACT_LEASES)
781 log_fatal (
"No shared network for network %s (%s)",
782 netbuf,
piaddr (subnet -> netmask));
786 if (!lease_uid_hash) {
788 log_fatal (
"Can't allocate lease/uid hash");
790 if (!lease_ip_addr_hash) {
793 log_fatal (
"Can't allocate lease/ip hash");
795 if (!lease_hw_addr_hash) {
798 log_fatal (
"Can't allocate lease/hw hash");
805 log_fatal(
"bad range, address %s not in subnet %s netmask %s",
812 log_fatal(
"bad range, address %s not in subnet %s netmask %s",
817 max =
host_addr (high, subnet -> netmask);
818 min =
host_addr (low, subnet -> netmask);
823 min =
host_addr (high, subnet -> netmask);
830 num_addrs = max - min + 1;
831 #if defined (BINARY_LEASES)
836 #if defined (COMPACT_LEASES)
837 s = (num_addrs + 1) *
sizeof (
struct lease);
841 if (((s %
sizeof (
struct lease)) != 0) ||
842 ((s /
sizeof (
struct lease)) != (num_addrs + 1))) {
845 parse_warn (cfile,
"%s-%s is an overly large address range.",
850 if (!address_range) {
853 log_fatal (
"No memory for address range %s-%s.",
859 for (i = 0; i < num_addrs; i++) {
861 #if defined (COMPACT_LEASES)
865 lease_reference (&lp, &address_range [i],
MDL);
867 status = lease_allocate (&lp,
MDL);
873 isc_result_totext (status));
878 subnet_reference(&lp->
subnet, subnet,
MDL);
879 pool_reference(&lp->
pool, pool,
MDL);
889 "lease %s is declared twice!",
892 pool_reference (< -> pool, pool,
MDL);
893 lease_dereference (<,
MDL);
895 lease_ip_hash_add(lease_ip_addr_hash,
901 lease_reference (&lp ->
next, *lpchain,
MDL);
902 lease_dereference (lpchain,
MDL);
904 lease_reference (lpchain, lp,
MDL);
906 lease_dereference (&lp,
MDL);
921 if (subnet_reference (sp, rv,
936 for (rv = share -> subnets; rv; rv = rv ->
next_sibling) {
942 if (subnet_reference (sp, rv,
954 const struct subnet *scan,
962 char n1buf[
sizeof(
"ffff:ffff:ffff:ffff:ffff:ffff:255.255.255")];
964 for (i = 0; i < 128; i++)
968 for (j = 0; j < 128; j++)
974 log_error(
"Warning: subnet %s/%d overlaps subnet %s/%d",
988 struct subnet *scan = (
struct subnet *)0;
989 struct subnet *next = (
struct subnet *)0;
990 struct subnet *prev = (
struct subnet *)0;
994 subnet_reference (&next, subnets,
MDL);
996 subnet_reference (&scan, next,
MDL);
997 subnet_dereference (&next,
MDL);
1007 subnet_dereference (&prev,
MDL);
1009 subnet_dereference (&subnets,
MDL);
1010 subnet_reference (&subnets, subnet,
MDL);
1013 subnet_dereference (&scan,
MDL);
1016 subnet_reference (&prev, scan,
MDL);
1017 subnet_dereference (&scan,
MDL);
1020 subnet_dereference (&prev,
MDL);
1025 subnet_dereference (&subnets,
MDL);
1027 subnet_reference (&subnets, subnet,
MDL);
1035 if (shared_networks) {
1036 shared_network_reference (&share -> next,
1037 shared_networks,
MDL);
1038 shared_network_dereference (&shared_networks,
MDL);
1040 shared_network_reference (&shared_networks, share,
MDL);
1049 isc_result_t status;
1051 if (share -> interface) {
1053 "A subnet or shared network can't be connected %s",
1054 "to two interfaces.");
1059 if (!strcmp (ip -> name, name))
1062 status = interface_allocate (&ip,
MDL);
1064 log_fatal (
"new_shared_network_interface %s: %s",
1065 name, isc_result_totext (status));
1066 if (strlen (name) >
sizeof ip -> name) {
1067 memcpy (ip -> name, name, (
sizeof ip -> name) - 1);
1068 ip -> name [(
sizeof ip ->
name) - 1] = 0;
1070 strcpy (ip -> name, name);
1079 interface_reference (&share -> interface, ip,
MDL);
1092 struct lease *comp = (
struct lease *)0;
1095 if (!comp ->
pool) {
1096 log_error (
"undeclared lease found in database: %s",
1099 pool_reference (&lease ->
pool, comp ->
pool,
MDL);
1102 subnet_reference (&lease ->
subnet,
1104 lease_ip_hash_delete(lease_ip_addr_hash,
1105 lease->ip_addr.iabuf, lease->ip_addr.len,
1107 lease_dereference (&comp,
MDL);
1123 lease_ip_hash_add(lease_ip_addr_hash, lease->ip_addr.iabuf,
1124 lease->ip_addr.len, lease,
MDL);
1141 #if defined (FAILOVER_PROTOCOL)
1142 int do_pool_check = 0;
1147 if (pimmediate && !commit)
1170 (((comp -> uid && lease -> uid) &&
1171 (comp -> uid_len != lease -> uid_len ||
1172 memcmp (comp -> uid, lease -> uid, comp -> uid_len))) ||
1174 ((comp -> hardware_addr.hlen !=
1175 lease -> hardware_addr.hlen) ||
1176 memcmp (comp -> hardware_addr.hbuf,
1177 lease -> hardware_addr.hbuf,
1178 comp -> hardware_addr.hlen))))) {
1187 if (comp->uid != comp->uid_buf) {
1192 comp -> uid = (
unsigned char *)0;
1198 if (comp->hardware_addr.hlen)
1202 if (comp -> billing_class != lease -> billing_class) {
1203 if (comp->billing_class)
1205 if (lease -> billing_class)
1210 comp -> starts = lease -> starts;
1212 if (lease -> uid_len <=
sizeof (lease -> uid_buf)) {
1213 memcpy (comp -> uid_buf,
1214 lease -> uid, lease -> uid_len);
1215 comp -> uid = &comp -> uid_buf [0];
1216 comp -> uid_max =
sizeof comp -> uid_buf;
1217 comp -> uid_len = lease -> uid_len;
1218 }
else if (lease -> uid != &lease -> uid_buf [0]) {
1219 comp -> uid = lease -> uid;
1220 comp -> uid_max = lease -> uid_max;
1221 lease -> uid = (
unsigned char *)0;
1222 lease -> uid_max = 0;
1223 comp -> uid_len = lease -> uid_len;
1224 lease -> uid_len = 0;
1229 comp -> uid = (
unsigned char *)0;
1230 comp -> uid_len = comp -> uid_max = 0;
1233 host_dereference (&comp -> host,
MDL);
1234 host_reference (&comp -> host, lease -> host,
MDL);
1235 comp -> hardware_addr = lease -> hardware_addr;
1238 if (lease -> scope) {
1248 if (lease -> next_binding_state ==
FTS_ACTIVE ||
1257 if (comp -> client_hostname)
1258 dfree (comp -> client_hostname,
MDL);
1259 comp -> client_hostname = lease -> client_hostname;
1260 lease -> client_hostname = (
char *)0;
1262 if (lease->on_star.on_expiry) {
1263 if (comp->on_star.on_expiry)
1265 (&comp->on_star.on_expiry,
MDL);
1267 lease->on_star.on_expiry,
1270 if (lease->on_star.on_commit) {
1271 if (comp->on_star.on_commit)
1273 (&comp->on_star.on_commit,
MDL);
1275 lease->on_star.on_commit,
1278 if (lease->on_star.on_release) {
1279 if (comp->on_star.on_release)
1281 (&comp->on_star.on_release,
MDL);
1283 lease->on_star.on_release,
1292 if (comp->hardware_addr.hlen)
1295 comp->cltt = lease->cltt;
1296 #if defined (FAILOVER_PROTOCOL)
1297 comp->tstp = lease->tstp;
1298 comp->tsfp = lease->tsfp;
1299 comp->atsfp = lease->atsfp;
1301 comp->ends = lease->ends;
1302 comp->next_binding_state = lease->next_binding_state;
1311 if (lease->ddns_cb != NULL)
1312 comp->ddns_cb = lease->ddns_cb;
1315 #if defined (FAILOVER_PROTOCOL)
1325 if (!comp ->
pool) {
1326 log_error (
"Supersede_lease: lease %s with no pool.",
1332 switch (comp -> binding_state) {
1335 lq = &comp->pool->reserved;
1337 lq = &comp->pool->free;
1338 comp->pool->free_leases--;
1341 #if defined(FAILOVER_PROTOCOL)
1347 lq = &comp ->
pool -> active;
1353 lq = &comp ->
pool -> expired;
1357 lq = &comp ->
pool -> abandoned;
1362 lq = &comp->pool->reserved;
1364 lq = &comp->pool->backup;
1365 comp->pool->backup_leases--;
1368 #if defined(FAILOVER_PROTOCOL)
1374 log_error (
"Lease with bogus binding state: %d",
1375 comp -> binding_state);
1376 #if defined (BINDING_STATE_DEBUG)
1395 if (commit || !pimmediate)
1414 if ((commit || !pimmediate) &&
1417 (comp -> sort_time < comp ->
pool -> next_event_time ||
1419 comp ->
pool -> next_event_time = comp -> sort_time;
1420 tv . tv_sec = comp ->
pool -> next_event_time;
1429 #if defined(FAILOVER_PROTOCOL)
1439 if (propogate && (comp->pool->failover_peer != NULL) &&
1440 ((comp->pool->failover_peer->service_state ==
1442 (comp->pool->failover_peer->service_state ==
1444 comp->rewind_binding_state = comp->binding_state;
1449 if ((server_starting &
SS_NOSYNC) == 0) {
1455 #if defined (FAILOVER_PROTOCOL)
1457 comp -> desired_binding_state = comp -> binding_state;
1461 if (do_pool_check && comp->pool->failover_peer)
1471 if ((from_pool == 0) &&
1472 (commit || !pimmediate) &&
1474 (comp->next_binding_state != comp->binding_state))
1483 #if defined (FAILOVER_PROTOCOL)
1484 dhcp_failover_state_t *peer;
1486 if (lease ->
pool && lease ->
pool -> failover_peer)
1487 peer = lease ->
pool -> failover_peer;
1489 peer = (dhcp_failover_state_t *)0;
1494 if (lease -> next_binding_state != lease -> binding_state &&
1506 #if defined (NSUPDATE)
1531 if (lease -> client_hostname) {
1532 dfree (lease -> client_hostname,
MDL);
1533 lease -> client_hostname = (
char *)0;
1536 host_dereference (&lease -> host,
MDL);
1539 lease -> tstp = lease -> ends;
1544 if (lease -> next_binding_state != lease -> binding_state &&
1549 (lease -> next_binding_state ==
FTS_FREE ||
1550 lease -> next_binding_state ==
FTS_BACKUP)) ||
1555 #if defined (NSUPDATE)
1595 if (lease -> client_hostname) {
1596 dfree (lease -> client_hostname,
MDL);
1597 lease -> client_hostname = (
char *)0;
1600 host_dereference (&lease -> host,
MDL);
1604 lease -> tstp = lease -> ends;
1607 #if defined (DEBUG_LEASE_STATE_TRANSITIONS)
1608 log_debug (
"lease %s moves from %s to %s",
1614 lease -> binding_state = lease -> next_binding_state;
1615 switch (lease -> binding_state) {
1617 #if defined (FAILOVER_PROTOCOL)
1618 if (lease ->
pool && lease ->
pool -> failover_peer)
1622 lease -> next_binding_state =
FTS_FREE;
1630 #if defined(FAILOVER_PROTOCOL)
1635 if ((lease->
pool != NULL) &&
1646 lease -> next_binding_state = lease -> binding_state;
1649 #if defined (DEBUG_LEASE_STATE_TRANSITIONS)
1650 log_debug (
"lease %s: next binding state %s",
1661 struct lease *lt = (
struct lease *)0;
1662 isc_result_t status;
1664 status = lease_allocate (<,
MDL);
1676 }
else if (!lease ->
uid_max) {
1677 lt ->
uid = (
unsigned char *)0;
1681 lease_dereference (<,
MDL);
1690 lease_dereference (<,
MDL);
1700 host_reference (< ->
host, lease ->
host, file, line);
1701 subnet_reference (< ->
subnet, lease ->
subnet, file, line);
1702 pool_reference (< ->
pool, lease ->
pool, file, line);
1726 status = lease_reference(lp, lt, file, line);
1727 lease_dereference(<,
MDL);
1738 #if defined (NSUPDATE)
1741 if (lease->on_star.on_release) {
1744 NULL, &lease->scope,
1745 lease->on_star.on_release, NULL);
1746 if (lease->on_star.on_release)
1748 (&lease->on_star.on_release,
MDL);
1754 if (lease->on_star.on_expiry)
1756 (&lease->on_star.on_expiry,
MDL);
1763 if (lease->on_star.on_commit)
1765 (&lease->on_star.on_commit,
MDL);
1778 #if defined (FAILOVER_PROTOCOL)
1779 if (lease ->
pool && lease ->
pool -> failover_peer) {
1780 dhcp_failover_state_t *peer = NULL;
1782 if (lease->pool != NULL)
1783 peer = lease->pool->failover_peer;
1786 (((peer->i_am == primary) &&
1787 (lease->rewind_binding_state ==
FTS_FREE)) ||
1788 ((peer->i_am == secondary) &&
1789 (lease->rewind_binding_state ==
FTS_BACKUP)))) {
1790 lease->next_binding_state =
1791 lease->rewind_binding_state;
1809 const
char *message;
1811 struct lease *lt = NULL;
1812 #if defined (NSUPDATE)
1844 lease_dereference(<,
MDL);
1858 void dissociate_lease (
lease)
1861 struct lease *lt = (
struct lease *)0;
1862 #if defined (NSUPDATE)
1869 #if defined (FAILOVER_PROTOCOL)
1870 if (lease ->
pool && lease ->
pool -> failover_peer) {
1882 lt ->
uid = (
unsigned char *)0;
1886 lease_dereference (<,
MDL);
1895 struct lease *
next = NULL;
1896 struct lease *lease = NULL;
1897 struct lease *ltemp = NULL;
1898 #define FREE_LEASES 0
1899 #define ACTIVE_LEASES 1
1900 #define EXPIRED_LEASES 2
1901 #define ABANDONED_LEASES 3
1902 #define BACKUP_LEASES 4
1903 #define RESERVED_LEASES 5
1909 pool = (
struct pool *)vpool;
1923 #if defined (FAILOVER_PROTOCOL)
1924 if (pool->failover_peer &&
1940 (pool->failover_peer->i_am == secondary) &&
1941 (pool->failover_peer->me.state ==
normal))
1956 lease_dereference(&next,
MDL);
1959 lease_reference(&next, ltemp,
MDL);
1976 #if defined(FAILOVER_PROTOCOL)
1977 dhcp_failover_state_t *peer = NULL;
1979 if (lease->
pool != NULL)
1986 ((peer->i_am == primary &&
1989 (peer->i_am == secondary &&
1998 lease_dereference(&lease,
MDL);
2000 lease_reference(&lease, next,
MDL);
2003 lease_dereference(&next,
MDL);
2005 lease_dereference(&lease,
MDL);
2014 ((pool->next_event_time > next_expiry) ||
2015 (pool->next_event_time <=
cur_time))) {
2016 pool->next_event_time = next_expiry;
2017 tv.tv_sec = pool->next_event_time;
2032 return lease_ip_hash_lookup(lp, lease_ip_addr_hash, addr.
iabuf,
2033 addr.
len, file, line);
2037 unsigned len,
const char *
file,
int line)
2041 return lease_id_hash_lookup (lp, lease_uid_hash, uid, len, file, line);
2045 const unsigned char *hwaddr,
unsigned hwlen,
2058 return (lease_id_hash_lookup(lp, lease_hw_addr_hash, hwaddr, hwlen,
2075 static isc_boolean_t
2076 client_lease_preferred(
struct lease *cand,
struct lease *lease)
2113 struct lease *head = NULL;
2114 struct lease *cand = NULL;
2115 struct lease *
prev = NULL;
2116 struct lease *
next = NULL;
2120 lease_id_hash_add(lease_uid_hash, lease->
uid, lease->
uid_len,
2130 lease_reference(&cand, head,
MDL);
2131 while (cand != NULL) {
2132 if (client_lease_preferred(cand, lease))
2136 lease_dereference(&prev,
MDL);
2137 lease_reference(&prev, cand,
MDL);
2139 if (cand->
n_uid != NULL)
2140 lease_reference(&next, cand->
n_uid,
MDL);
2142 lease_dereference(&cand,
MDL);
2145 lease_reference(&cand, next,
MDL);
2146 lease_dereference(&next,
MDL);
2154 lease_reference(&lease->
n_uid, head,
MDL);
2155 lease_id_hash_delete(lease_uid_hash, lease->
uid,
2157 lease_id_hash_add(lease_uid_hash, lease->
uid,
2160 if(prev->
n_uid != NULL) {
2163 lease_dereference(&prev->
n_uid,
MDL);
2165 lease_reference(&prev->
n_uid, lease,
MDL);
2167 lease_dereference(&prev,
MDL);
2171 lease_dereference(&cand,
MDL);
2172 lease_dereference(&head,
MDL);
2179 struct lease *lease;
2181 struct lease *head = (
struct lease *)0;
2187 lease_dereference (&lease ->
n_uid,
MDL);
2194 if (head == lease) {
2195 lease_id_hash_delete(lease_uid_hash, lease->uid,
2196 lease->uid_len,
MDL);
2197 if (lease ->
n_uid) {
2198 lease_id_hash_add(lease_uid_hash, lease->n_uid->uid,
2199 lease->n_uid->uid_len, lease->n_uid,
2201 lease_dereference (&lease ->
n_uid,
MDL);
2207 for (scan = head; scan ->
n_uid; scan = scan ->
n_uid) {
2208 if (scan ->
n_uid == lease) {
2209 lease_dereference (&scan ->
n_uid,
MDL);
2210 if (lease ->
n_uid) {
2211 lease_reference (&scan ->
n_uid,
2213 lease_dereference (&lease ->
n_uid,
2220 lease_dereference (&head,
MDL);
2230 struct lease *head = NULL;
2231 struct lease *cand = NULL;
2232 struct lease *
prev = NULL;
2233 struct lease *
next = NULL;
2246 lease_id_hash_add(lease_hw_addr_hash,
2257 lease_reference(&cand, head,
MDL);
2258 while (cand != NULL) {
2259 if (client_lease_preferred(cand, lease))
2263 lease_dereference(&prev,
MDL);
2264 lease_reference(&prev, cand,
MDL);
2266 if (cand->
n_hw != NULL)
2267 lease_reference(&next, cand->
n_hw,
MDL);
2269 lease_dereference(&cand,
MDL);
2272 lease_reference(&cand, next,
MDL);
2273 lease_dereference(&next,
MDL);
2281 lease_reference(&lease->
n_hw, head,
MDL);
2282 lease_id_hash_delete(lease_hw_addr_hash,
2285 lease_id_hash_add(lease_hw_addr_hash,
2290 if(prev->
n_hw != NULL) {
2291 lease_reference(&lease->
n_hw, prev->
n_hw,
2293 lease_dereference(&prev->
n_hw,
MDL);
2295 lease_reference(&prev->
n_hw, lease,
MDL);
2297 lease_dereference(&prev,
MDL);
2301 lease_dereference(&cand,
MDL);
2302 lease_dereference(&head,
MDL);
2309 struct lease *lease;
2311 struct lease *head = (
struct lease *)0;
2312 struct lease *
next = (
struct lease *)0;
2318 if ((lease->hardware_addr.hlen == 1) &&
2326 lease_dereference (&lease ->
n_hw,
MDL);
2333 if (head == lease) {
2334 lease_id_hash_delete(lease_hw_addr_hash,
2335 lease->hardware_addr.hbuf,
2336 lease->hardware_addr.hlen,
MDL);
2338 lease_id_hash_add(lease_hw_addr_hash,
2339 lease->n_hw->hardware_addr.hbuf,
2340 lease->n_hw->hardware_addr.hlen,
2342 lease_dereference(&lease->n_hw,
MDL);
2348 while (head ->
n_hw) {
2349 if (head ->
n_hw == lease) {
2350 lease_dereference (&head ->
n_hw,
MDL);
2351 if (lease ->
n_hw) {
2352 lease_reference (&head ->
n_hw,
2354 lease_dereference (&lease ->
n_hw,
2359 lease_reference (&next, head ->
n_hw,
MDL);
2360 lease_dereference (&head,
MDL);
2361 lease_reference (&head, next,
MDL);
2362 lease_dereference (&next,
MDL);
2366 lease_dereference (&head,
MDL);
2375 int num_written = 0, i;
2378 for (s = shared_networks; s; s = s->
next) {
2391 #if !defined (DEBUG_DUMP_ALL_LEASES)
2405 log_info (
"Wrote %d leases to leases file.", num_written);
2425 for (cp = colp->
classes ; cp ; cp = cp->
nic) {
2427 (
unsigned char *)cp->
name,
2433 log_info (
"Wrote %d class decls to leases file.",
2443 hb; hb = hb ->
next) {
2454 log_info (
"Wrote %d group decls to leases file.", num_written);
2458 if (host_name_hash) {
2460 for (i = 0; i < host_name_hash -> hash_count; i++) {
2461 for (hb = host_name_hash -> buckets [i];
2462 hb; hb = hb -> next) {
2472 log_info (
"Wrote %d deleted host decls to leases file.",
2477 if (host_name_hash) {
2479 for (i = 0; i < host_name_hash -> hash_count; i++) {
2480 for (hb = host_name_hash -> buckets [i];
2481 hb; hb = hb -> next) {
2489 log_info (
"Wrote %d new dynamic host decls to leases file.",
2493 #if defined (FAILOVER_PROTOCOL)
2517 #if !defined (BINARY_LEASES)
2520 struct lease *lp, *ln = NULL;
2533 lease_reference(&lp, *lq,
MDL);
2534 lease_dereference(lq,
MDL);
2539 lease_reference(&ln, lp->
next,
MDL);
2540 lease_dereference(&lp->
next,
MDL);
2544 lease_dereference(&lp,
MDL);
2549 }
while (lp != NULL);
2560 struct lease *
prev, *lp;
2563 for (lp = *lq; lp != NULL; lp = lp->
next) {
2570 log_fatal(
"Lease with binding state %s not on its queue.",
2578 lease_dereference(&prev->
next,
MDL);
2581 lease_dereference (&comp->
next,
MDL);
2584 lease_dereference(lq,
MDL);
2586 lease_reference(lq, comp->
next,
MDL);
2587 lease_dereference(&comp->
next,
MDL);
2598 struct lease *
prev, *lp;
2599 static struct lease **last_lq = NULL;
2600 static struct lease *last_insert_point = NULL;
2607 if ((server_starting &
SS_QFOLLOW) && (lq == last_lq) &&
2608 (comp != last_insert_point) &&
2610 prev = last_insert_point;
2618 for (; lp != NULL ; lp = lp->
next) {
2627 lease_dereference(&prev->
next,
MDL);
2629 lease_reference(&prev->
next, comp,
MDL);
2632 lease_reference (&comp->
next, *lq,
MDL);
2633 lease_dereference(lq,
MDL);
2635 lease_reference(lq, comp,
MDL);
2637 last_insert_point = comp;
2677 lq = &comp ->
pool -> active;
2684 lq = &comp ->
pool -> expired;
2685 #if defined(FAILOVER_PROTOCOL)
2709 lq = &comp ->
pool -> abandoned;
2724 log_error (
"Lease with bogus binding state: %d",
2726 #if defined (BINDING_STATE_DEBUG)
2744 struct lease *lease = object;
2745 struct class *
class;
2749 if (!lease ->
pool) {
2750 lease_ip_hash_delete(lease_ip_addr_hash, lease->
ip_addr.
iabuf,
2755 #if defined (FAILOVER_PROTOCOL)
2786 if (lease -> hardware_addr.hlen) {
2791 if (lease -> billing_class) {
2792 class = (struct class *)0;
2793 class_reference (&
class, lease -> billing_class,
MDL);
2794 class_dereference (&lease -> billing_class,
MDL);
2802 class_dereference (&
class,
MDL);
2823 #if defined (BINARY_LEASES)
2829 for (s = shared_networks; s; s = s ->
next) {
2830 for (p = s ->
pools; p != NULL; p = p ->
next) {
2831 size_t num_f = 100, num_a = 50, num_e = 20;
2858 for (s = shared_networks; s; s = s ->
next) {
2862 p -> lease_count = 0;
2863 p -> free_leases = 0;
2864 p -> backup_leases = 0;
2893 #if defined (FAILOVER_PROTOCOL)
2894 if (p -> failover_peer &&
2907 server_starting = 0;
2920 for (n = subnets; n; n = n -> next_subnet) {
2926 for (s = shared_networks; s; s = s ->
next) {
2950 lease_reference, lease_dereference,
do_id_hash)
2956 #if defined (DEBUG_MEMORY_LEAKAGE) && \
2957 defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
2970 #if defined (COMPACT_LEASES)
2971 extern struct lease *lease_hunks;
2974 void free_everything(
void)
2979 struct pool *pc = (
struct pool *)0, *pn = (
struct pool *)0;
2980 struct lease *
lc = NULL, *ln = NULL, *ltemp = NULL;
2983 struct class *cc = (
struct class *)0, *cn = (
struct class *)0;
2988 if (host_hw_addr_hash)
2989 host_free_hash_table (&host_hw_addr_hash,
MDL);
2990 host_hw_addr_hash = 0;
2992 host_free_hash_table (&host_uid_hash,
MDL);
2995 lease_id_free_hash_table (&lease_uid_hash,
MDL);
2997 if (lease_ip_addr_hash)
2998 lease_ip_free_hash_table (&lease_ip_addr_hash,
MDL);
2999 lease_ip_addr_hash = 0;
3000 if (lease_hw_addr_hash)
3001 lease_id_free_hash_table (&lease_hw_addr_hash,
MDL);
3002 lease_hw_addr_hash = 0;
3004 host_free_hash_table (&host_name_hash,
MDL);
3007 dns_zone_free_hash_table (&dns_zone_hash,
MDL);
3010 while (host_id_info != NULL) {
3014 tmp = host_id_info->
next;
3020 auth_key_free_hash_table (&auth_key_hash,
MDL);
3032 class_reference (&cc, cn,
MDL);
3033 class_dereference (&cn,
MDL);
3036 class_reference (&cn, cc -> nic,
MDL);
3037 class_dereference (&cc -> nic,
MDL);
3041 class_free_hash_table (&cc -> hash,
MDL);
3044 class_dereference (&cc,
MDL);
3046 class_dereference (&lp -> classes,
MDL);
3050 if (interface_vector) {
3052 if (interface_vector [i])
3053 interface_dereference (&interface_vector [i],
MDL);
3056 interface_vector = 0;
3063 interface_reference (&ic, in,
MDL);
3064 interface_dereference (&in,
MDL);
3067 interface_reference (&in, ic -> next,
MDL);
3068 interface_dereference (&ic -> next,
MDL);
3073 interface_dereference
3077 interface_dereference (&ic,
MDL);
3084 subnet_reference (&sn, subnets,
MDL);
3087 subnet_reference (&sc, sn,
MDL);
3088 subnet_dereference (&sn,
MDL);
3090 if (sc -> next_subnet) {
3091 subnet_reference (&sn, sc -> next_subnet,
MDL);
3092 subnet_dereference (&sc -> next_subnet,
MDL);
3094 if (sc -> next_sibling)
3095 subnet_dereference (&sc -> next_sibling,
MDL);
3099 if (sc -> interface)
3100 interface_dereference (&sc -> interface,
MDL);
3101 subnet_dereference (&sc,
MDL);
3103 subnet_dereference (&subnets,
MDL);
3112 if (shared_networks) {
3113 shared_network_dereference (&shared_networks,
MDL);
3116 shared_network_reference (&nn, shared_networks,
MDL);
3119 shared_network_reference (&nc, nn,
MDL);
3120 shared_network_dereference (&nn,
MDL);
3123 shared_network_reference (&nn, nc -> next,
MDL);
3124 shared_network_dereference (&nc -> next,
MDL);
3129 pool_reference (&pn, nc ->
pools,
MDL);
3134 pool_reference (&pc, pn,
MDL);
3135 pool_dereference (&pn,
MDL);
3138 pool_reference (&pn, pc -> next,
MDL);
3139 pool_dereference (&pc -> next,
MDL);
3155 lease_reference (&lc, ln,
MDL);
3156 lease_dereference (&ln,
MDL);
3160 if (ltemp != NULL) {
3161 lease_reference(&ln, ltemp,
MDL);
3167 if (lc -> billing_class)
3168 class_dereference (&lc -> billing_class,
3174 lease_dereference (&lc -> n_hw,
MDL);
3176 lease_dereference (&lc -> n_uid,
MDL);
3177 lease_dereference (&lc,
MDL);
3186 pool_dereference (&pc,
MDL);
3188 pool_dereference (&nc ->
pools,
MDL);
3193 shared_network_dereference (&nc,
MDL);
3195 shared_network_dereference (&shared_networks,
MDL);
3200 #if defined(DELAYED_ACK)
3201 relinquish_ackqueue();
3216 universe_free_hash_table (&universe_hash,
MDL);
3224 if (universes [i]) {
3225 if (universes[i]->name_hash)
3226 option_name_free_hash_table(
3227 &universes[i]->name_hash,
3229 if (universes[i]->code_hash)
3230 option_code_free_hash_table(
3231 &universes[i]->code_hash,
3234 if (universes [i] -> name > (
char *)&end) {
3235 foo.c = universes [i] -> name;
3238 if (universes [i] > (
struct universe *)&end)
3245 relinquish_free_lease_states ();
3246 relinquish_free_pairs ();
3247 relinquish_free_expressions ();
3248 relinquish_free_binding_values ();
3249 relinquish_free_option_caches ();
3250 relinquish_free_packets ();
3251 #if defined(COMPACT_LEASES)
int supersede_lease(struct lease *, struct lease *, int, int, int, int)
#define GROUP_OBJECT_DYNAMIC
int executable_statement_reference(struct executable_statement **ptr, struct executable_statement *bp, const char *file, int line)
int find_grouped_subnet(struct subnet **, struct shared_network *, struct iaddr, const char *, int)
void unbill_class(struct lease *lease)
struct lease * new_leases(unsigned, const char *, int)
lease_id_hash_t * lease_uid_hash
struct binding_scope * global_scope
struct universe * universe
struct host_id_info host_id_info_t
int executable_statement_dereference(struct executable_statement **ptr, const char *file, int line)
int find_host_for_network(struct subnet **, struct host_decl **, struct iaddr *, struct shared_network *)
const char * piaddr(const struct iaddr addr)
struct shared_network * shared_networks
unsigned do_id_hash(const void *, unsigned, unsigned)
#define LEASE_REMOVEP(LQ, LEASE)
void expire_all_pools(void)
struct executable_statement * default_classification_rules
int executable_statement_foreach(struct executable_statement *stmt, int(*callback)(structexecutable_statement *, void *, int), void *vp, int condp)
int execute_statements(struct binding_value **result, struct packet *packet, struct lease *lease, struct client_state *client_state, struct option_state *in_options, struct option_state *out_options, struct binding_scope **scope, struct executable_statement *statements, struct on_star *on_star)
void dhcp_failover_pool_check(struct pool *)
struct iaddr ip_addr(struct iaddr subnet, struct iaddr mask, u_int32_t host_address)
isc_result_t unlink_class(struct class **class)
#define HOST_DECL_DYNAMIC
int find_hosts_by_option(struct host_decl **, struct packet *, struct option_state *, const char *, int)
void lease_remove(struct lease **lq, struct lease *comp)
#define print_hex_1(len, data, limit)
void print_lease(struct lease *lease)
#define HASH_FUNCTIONS(name, bufarg, type, hashtype, ref, deref, hasher)
#define CLASS_DECL_DELETED
host_hash_t * host_uid_hash
int int int log_debug(const char *,...) __attribute__((__format__(__printf__
omapi_object_type_t * dhcp_type_lease
enum executable_statement::statement_op op
void omapi_type_relinquish(void)
struct executable_statement * on_release
void uid_hash_add(struct lease *)
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)
void hw_hash_delete(struct lease *)
struct class * billing_class
struct group * root_group
int log_error(const char *,...) __attribute__((__format__(__printf__
#define HOST_DECL_DELETED
lease_id_hash_t * lease_hw_addr_hash
void cancel_all_timeouts(void)
int binding_scope_dereference(struct binding_scope **ptr, const char *file, int line)
void add_timeout(struct timeval *when, void(*)(void *) where, void *what, tvref_t ref, tvunref_t unref)
void relinquish_lease_hunks(void)
dhcp_failover_state_t * failover_peer
void release_lease(struct lease *, struct packet *)
int find_hosts_by_haddr(struct host_decl **, int, const unsigned char *, unsigned, const char *, int)
parse_warn(cfile,"expecting ip-address or ip-address/prefixlen")
log_fatal("no memory for uname information.")
struct data_string client_identifier
const char * binding_state_print(enum failover_state state)
struct option_state * options
isc_result_t enter_class(struct class *, int, int)
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
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)
int find_subnet(struct subnet **sp, struct iaddr addr, const char *file, int line)
#define LEASE_INSERTP(LQ, LEASE)
void relinquish_timeouts(void)
void change_host_uid(struct host_decl *host, const char *data, int len)
int subnet_inner_than(const struct subnet *, const struct subnet *, int)
#define FAILOVER_PROTOCOL
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)
host_hash_t * host_name_hash
void lease_remove_all(struct lease **lq)
isc_result_t delete_host(struct host_decl *, int)
#define LEASE_NOT_EMPTYP(LQ)
void enter_shared_network(struct shared_network *)
unsigned do_string_hash(const void *, unsigned, unsigned)
void abandon_lease(struct lease *, const char *)
binding_state_t binding_state
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)
if(parse_ip_addr(cfile,&match->addr))
void enter_lease(struct lease *)
isc_result_t omapi_object_dereference(omapi_object_t **, const char *, int)
int find_lease_by_hw_addr(struct lease **, const unsigned char *, unsigned, const char *, int)
host_hash_t * host_hw_addr_hash
void(* tvref_t)(void *, void *, const char *, int)
omapi_object_type_t * dhcp_type_host
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)
void uid_hash_delete(struct lease *)
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)
void new_address_range(struct parse *, struct iaddr, struct iaddr, struct subnet *, struct pool *, struct lease **)
struct interface_info * interfaces
int find_hosts_by_uid(struct host_decl **, const unsigned char *, unsigned, const char *, int)
int addr_eq(struct iaddr addr1, struct iaddr addr2)
unsigned do_ip4_hash(const void *, unsigned, unsigned)
int write_group(struct group_object *)
isc_result_t delete_class(struct class *, int)
struct subnet * next_subnet
void(* tvunref_t)(void *, const char *, int)
union executable_statement::@7 data
dhcp_control_object_t * dhcp_control_object
struct universe ** universes
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
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)
int lease_enqueue(struct lease *)
binding_state_t rewind_binding_state
struct interface_info * next
isc_result_t dhcp_io_shutdown(omapi_object_t *, void *)
host_hash_t * values_hash
void make_binding_state_transition(struct lease *)
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)
int find_lease_by_uid(struct lease **, const unsigned char *, unsigned, const char *, int)
void enter_subnet(struct subnet *)
isc_result_t enter_host(struct host_decl *, int, int)
group_hash_t * group_name_hash
u_int8_t hbuf[HARDWARE_ADDR_LEN+1]
struct ipv6_pool ** pools
struct collection * collections
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
#define DHO_DHCP_CLIENT_IDENTIFIER
void new_shared_network_interface(struct parse *, struct shared_network *, const char *)
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
isc_result_t lease_instantiate(const void *, unsigned, void *)
int find_lease_by_ip_addr(struct lease **, struct iaddr, const char *, int)
u_int32_t abandon_lease_time
binding_state_t next_binding_state
void hw_hash_add(struct lease *)
lease_ip_hash_t * lease_ip_addr_hash
#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)
int lease_copy(struct lease **, struct lease *, const char *, int)
struct packet * dhcpv6_container_packet