Lines Matching refs:lease
28 struct dhcp_lease *lease;
44 lease database. */
66 die(_("cannot open or create lease file %s: %s"), daemon->lease_file, EC_FILE);
91 if (!(lease = lease_allocate(addr)))
96 lease->expires = (time_t)ei + now;
98 lease->expires = (time_t)0;
99 lease->length = ei;
103 lease->expires = (time_t)ei;
106 lease_set_hwaddr(lease, (unsigned char *)daemon->dhcp_buff2, (unsigned char *)daemon->packet, hw_len, hw_type, clid_len);
109 lease_set_hostname(lease, daemon->dhcp_buff, 0);
113 lease->new = lease->changed = 0;
128 die(_("cannot run lease-init script %s: %s"), daemon->lease_change_command, EC_FILE);
134 die(_("lease-init script returned exit code %s"), daemon->dhcp_buff, WEXITSTATUS(rc) + EC_INIT_OFFSET);
149 struct dhcp_lease *lease;
153 for (lease = leases; lease; lease = lease->next)
154 if ((config = find_config(daemon->dhcp_conf, NULL, lease->clid, lease->clid_len,
155 lease->hwaddr, lease->hwaddr_len, lease->hwaddr_type, NULL)) &&
157 (!(config->flags & CONFIG_ADDR) || config->addr.s_addr == lease->addr.s_addr))
158 lease_set_hostname(lease, config->hostname, 1);
159 else if ((name = host_from_dns(lease->addr)))
160 lease_set_hostname(lease, name, 1); /* updates auth flag only */
175 struct dhcp_lease *lease;
186 for (lease = leases; lease; lease = lease->next)
189 ourprintf(&err, "%u ", lease->length);
191 ourprintf(&err, "%lu ", (unsigned long)lease->expires);
193 if (lease->hwaddr_type != ARPHRD_ETHER || lease->hwaddr_len == 0)
194 ourprintf(&err, "%.2x-", lease->hwaddr_type);
195 for (i = 0; i < lease->hwaddr_len; i++)
197 ourprintf(&err, "%.2x", lease->hwaddr[i]);
198 if (i != lease->hwaddr_len - 1)
202 ourprintf(&err, " %s ", inet_ntoa(lease->addr));
203 ourprintf(&err, "%s ", lease->hostname ? lease->hostname : "*");
205 if (lease->clid && lease->clid_len != 0)
207 for (i = 0; i < lease->clid_len - 1; i++)
208 ourprintf(&err, "%.2x:", lease->clid[i]);
209 ourprintf(&err, "%.2x\n", lease->clid[i]);
223 /* Set alarm for when the first lease expires + slop. */
224 for (next_event = 0, lease = leases; lease; lease = lease->next)
225 if (lease->expires != 0 &&
226 (next_event == 0 || difftime(next_event, lease->expires + 10) > 0.0))
227 next_event = lease->expires + 10;
245 struct dhcp_lease *lease;
251 for (lease = leases; lease; lease = lease->next)
253 if (lease->fqdn)
254 cache_add_dhcp_entry(lease->fqdn, &lease->addr, lease->expires);
256 if (!(daemon->options & OPT_DHCP_FQDN) && lease->hostname)
257 cache_add_dhcp_entry(lease->hostname, &lease->addr, lease->expires);
266 struct dhcp_lease *lease, *tmp, **up;
268 for (lease = leases, up = &leases; lease; lease = tmp)
270 tmp = lease->next;
271 if ((lease->expires != 0 && difftime(now, lease->expires) > 0) || lease == target)
274 if (lease->hostname)
277 *up = lease->next; /* unlink */
281 lease->next = old_leases;
282 old_leases = lease;
287 up = &lease->next;
295 struct dhcp_lease *lease;
298 for (lease = leases; lease; lease = lease->next)
299 if (lease->clid && clid_len == lease->clid_len &&
300 memcmp(clid, lease->clid, clid_len) == 0)
301 return lease;
303 for (lease = leases; lease; lease = lease->next)
304 if ((!lease->clid || !clid) &&
306 lease->hwaddr_len == hw_len &&
307 lease->hwaddr_type == hw_type &&
308 memcmp(hwaddr, lease->hwaddr, hw_len) == 0)
309 return lease;
316 struct dhcp_lease *lease;
318 for (lease = leases; lease; lease = lease->next)
319 if (lease->addr.s_addr == addr.s_addr)
320 return lease;
328 struct dhcp_lease *lease;
329 if (!leases_left || !(lease = whine_malloc(sizeof(struct dhcp_lease))))
332 memset(lease, 0, sizeof(struct dhcp_lease));
333 lease->new = 1;
334 lease->addr = addr;
335 lease->hwaddr_len = 256; /* illegal value */
336 lease->expires = 1;
338 lease->length = 0xffffffff; /* illegal value */
340 lease->next = leases;
341 leases = lease;
346 return lease;
349 void lease_set_expires(struct dhcp_lease *lease, unsigned int len, time_t now)
359 if (exp != lease->expires)
362 lease->expires = exp;
364 lease->aux_changed = file_dirty = 1;
369 if (len != lease->length)
371 lease->length = len;
372 lease->aux_changed = file_dirty = 1;
377 void lease_set_hwaddr(struct dhcp_lease *lease, unsigned char *hwaddr,
380 if (hw_len != lease->hwaddr_len ||
381 hw_type != lease->hwaddr_type ||
382 (hw_len != 0 && memcmp(lease->hwaddr, hwaddr, hw_len) != 0))
384 memcpy(lease->hwaddr, hwaddr, hw_len);
385 lease->hwaddr_len = hw_len;
386 lease->hwaddr_type = hw_type;
387 lease->changed = file_dirty = 1; /* run script on change */
391 without a clid removing the record. Lease init uses
395 if (!lease->clid)
396 lease->clid_len = 0;
398 if (lease->clid_len != clid_len)
400 lease->aux_changed = file_dirty = 1;
401 free(lease->clid);
402 if (!(lease->clid = whine_malloc(clid_len)))
405 else if (memcmp(lease->clid, clid, clid_len) != 0)
406 lease->aux_changed = file_dirty = 1;
408 lease->clid_len = clid_len;
409 memcpy(lease->clid, clid, clid_len);
414 static void kill_name(struct dhcp_lease *lease)
420 free(lease->old_hostname);
425 if (lease->fqdn)
427 lease->old_hostname = lease->fqdn;
428 free(lease->hostname);
431 lease->old_hostname = lease->hostname;
433 lease->hostname = lease->fqdn = NULL;
436 void lease_set_hostname(struct dhcp_lease *lease, char *name, int auth)
441 if (lease->hostname && name && hostname_isequal(lease->hostname, name))
443 lease->auth_name = auth;
447 if (!name && !lease->hostname)
450 /* If a machine turns up on a new net without dropping the old lease,
452 the same name. Check for that here and remove the name from the old lease.
459 char *suffix = get_domain(lease->addr);
495 if (lease->hostname)
496 kill_name(lease);
498 lease->hostname = new_name;
499 lease->fqdn = new_fqdn;
500 lease->auth_name = auth;
504 lease->changed = 1; /* run script on change */
507 void lease_set_interface(struct dhcp_lease *lease, int interface)
509 if (lease->last_interface == interface)
512 lease->last_interface = interface;
513 lease->changed = 1;
518 struct dhcp_lease *lease;
520 for (lease = leases; lease; lease = lease->next)
521 lease->changed = 1;
525 remove them here, after calling the lease change
526 script. Also run the lease change script on new/modified leases.
531 struct dhcp_lease *lease;
542 lease = old_leases;
544 /* If the lease still has an old_hostname, do the "old" action on that first */
545 if (lease->old_hostname)
548 queue_script(ACTION_OLD_HOSTNAME, lease, lease->old_hostname, now);
550 free(lease->old_hostname);
551 lease->old_hostname = NULL;
556 kill_name(lease);
558 queue_script(ACTION_DEL, lease, lease->old_hostname, now);
561 emit_dbus_signal(ACTION_DEL, lease, lease->old_hostname);
563 old_leases = lease->next;
565 free(lease->old_hostname);
566 free(lease->clid);
567 free(lease->vendorclass);
568 free(lease->userclass);
569 free(lease->supplied_hostname);
570 free(lease);
577 for (lease = leases; lease; lease = lease->next)
578 if (lease->old_hostname)
581 queue_script(ACTION_OLD_HOSTNAME, lease, lease->old_hostname, now);
583 free(lease->old_hostname);
584 lease->old_hostname = NULL;
588 for (lease = leases; lease; lease = lease->next)
589 if (lease->new || lease->changed ||
590 (lease->aux_changed && (daemon->options & OPT_LEASE_RO)))
593 queue_script(lease->new ? ACTION_ADD : ACTION_OLD, lease,
594 lease->fqdn ? lease->fqdn : lease->hostname, now);
597 emit_dbus_signal(lease->new ? ACTION_ADD : ACTION_OLD, lease,
598 lease->fqdn ? lease->fqdn : lease->hostname);
600 lease->new = lease->changed = lease->aux_changed = 0;
603 free(lease->vendorclass);
604 lease->vendorclass = NULL;
606 free(lease->userclass);
607 lease->userclass = NULL;
609 free(lease->supplied_hostname);
610 lease->supplied_hostname = NULL;