Lines Matching refs:lease
28 struct dhcp_lease *lease; in lease_init() local
91 if (!(lease = lease_allocate(addr))) in lease_init()
96 lease->expires = (time_t)ei + now; in lease_init()
98 lease->expires = (time_t)0; in lease_init()
99 lease->length = ei; in lease_init()
103 lease->expires = (time_t)ei; in lease_init()
106 …lease_set_hwaddr(lease, (unsigned char *)daemon->dhcp_buff2, (unsigned char *)daemon->packet, hw_l… in lease_init()
109 lease_set_hostname(lease, daemon->dhcp_buff, 0); in lease_init()
113 lease->new = lease->changed = 0; in lease_init()
149 struct dhcp_lease *lease; in lease_update_from_configs() local
153 for (lease = leases; lease; lease = lease->next) in lease_update_from_configs()
154 if ((config = find_config(daemon->dhcp_conf, NULL, lease->clid, lease->clid_len, in lease_update_from_configs()
155 lease->hwaddr, lease->hwaddr_len, lease->hwaddr_type, NULL)) && in lease_update_from_configs()
157 (!(config->flags & CONFIG_ADDR) || config->addr.s_addr == lease->addr.s_addr)) in lease_update_from_configs()
158 lease_set_hostname(lease, config->hostname, 1); in lease_update_from_configs()
159 else if ((name = host_from_dns(lease->addr))) in lease_update_from_configs()
160 lease_set_hostname(lease, name, 1); /* updates auth flag only */ in lease_update_from_configs()
175 struct dhcp_lease *lease; in lease_update_file() local
186 for (lease = leases; lease; lease = lease->next) in lease_update_file()
189 ourprintf(&err, "%u ", lease->length); in lease_update_file()
191 ourprintf(&err, "%lu ", (unsigned long)lease->expires); in lease_update_file()
193 if (lease->hwaddr_type != ARPHRD_ETHER || lease->hwaddr_len == 0) in lease_update_file()
194 ourprintf(&err, "%.2x-", lease->hwaddr_type); in lease_update_file()
195 for (i = 0; i < lease->hwaddr_len; i++) in lease_update_file()
197 ourprintf(&err, "%.2x", lease->hwaddr[i]); in lease_update_file()
198 if (i != lease->hwaddr_len - 1) in lease_update_file()
202 ourprintf(&err, " %s ", inet_ntoa(lease->addr)); in lease_update_file()
203 ourprintf(&err, "%s ", lease->hostname ? lease->hostname : "*"); in lease_update_file()
205 if (lease->clid && lease->clid_len != 0) in lease_update_file()
207 for (i = 0; i < lease->clid_len - 1; i++) in lease_update_file()
208 ourprintf(&err, "%.2x:", lease->clid[i]); in lease_update_file()
209 ourprintf(&err, "%.2x\n", lease->clid[i]); in lease_update_file()
224 for (next_event = 0, lease = leases; lease; lease = lease->next) in lease_update_file()
225 if (lease->expires != 0 && in lease_update_file()
226 (next_event == 0 || difftime(next_event, lease->expires + 10) > 0.0)) in lease_update_file()
227 next_event = lease->expires + 10; in lease_update_file()
245 struct dhcp_lease *lease; in lease_update_dns() local
251 for (lease = leases; lease; lease = lease->next) in lease_update_dns()
253 if (lease->fqdn) in lease_update_dns()
254 cache_add_dhcp_entry(lease->fqdn, &lease->addr, lease->expires); in lease_update_dns()
256 if (!(daemon->options & OPT_DHCP_FQDN) && lease->hostname) in lease_update_dns()
257 cache_add_dhcp_entry(lease->hostname, &lease->addr, lease->expires); in lease_update_dns()
266 struct dhcp_lease *lease, *tmp, **up; in lease_prune() local
268 for (lease = leases, up = &leases; lease; lease = tmp) in lease_prune()
270 tmp = lease->next; in lease_prune()
271 if ((lease->expires != 0 && difftime(now, lease->expires) > 0) || lease == target) in lease_prune()
274 if (lease->hostname) in lease_prune()
277 *up = lease->next; /* unlink */ in lease_prune()
281 lease->next = old_leases; in lease_prune()
282 old_leases = lease; in lease_prune()
287 up = &lease->next; in lease_prune()
295 struct dhcp_lease *lease; in lease_find_by_client() local
298 for (lease = leases; lease; lease = lease->next) in lease_find_by_client()
299 if (lease->clid && clid_len == lease->clid_len && in lease_find_by_client()
300 memcmp(clid, lease->clid, clid_len) == 0) in lease_find_by_client()
301 return lease; in lease_find_by_client()
303 for (lease = leases; lease; lease = lease->next) in lease_find_by_client()
304 if ((!lease->clid || !clid) && in lease_find_by_client()
306 lease->hwaddr_len == hw_len && in lease_find_by_client()
307 lease->hwaddr_type == hw_type && in lease_find_by_client()
308 memcmp(hwaddr, lease->hwaddr, hw_len) == 0) in lease_find_by_client()
309 return lease; in lease_find_by_client()
316 struct dhcp_lease *lease; in lease_find_by_addr() local
318 for (lease = leases; lease; lease = lease->next) in lease_find_by_addr()
319 if (lease->addr.s_addr == addr.s_addr) in lease_find_by_addr()
320 return lease; in lease_find_by_addr()
328 struct dhcp_lease *lease; in lease_allocate() local
329 if (!leases_left || !(lease = whine_malloc(sizeof(struct dhcp_lease)))) in lease_allocate()
332 memset(lease, 0, sizeof(struct dhcp_lease)); in lease_allocate()
333 lease->new = 1; in lease_allocate()
334 lease->addr = addr; in lease_allocate()
335 lease->hwaddr_len = 256; /* illegal value */ in lease_allocate()
336 lease->expires = 1; in lease_allocate()
338 lease->length = 0xffffffff; /* illegal value */ in lease_allocate()
340 lease->next = leases; in lease_allocate()
341 leases = lease; in lease_allocate()
346 return lease; in lease_allocate()
349 void lease_set_expires(struct dhcp_lease *lease, unsigned int len, time_t now) in lease_set_expires() argument
359 if (exp != lease->expires) in lease_set_expires()
362 lease->expires = exp; in lease_set_expires()
364 lease->aux_changed = file_dirty = 1; in lease_set_expires()
369 if (len != lease->length) in lease_set_expires()
371 lease->length = len; in lease_set_expires()
372 lease->aux_changed = file_dirty = 1; in lease_set_expires()
377 void lease_set_hwaddr(struct dhcp_lease *lease, unsigned char *hwaddr, in lease_set_hwaddr() argument
380 if (hw_len != lease->hwaddr_len || in lease_set_hwaddr()
381 hw_type != lease->hwaddr_type || in lease_set_hwaddr()
382 (hw_len != 0 && memcmp(lease->hwaddr, hwaddr, hw_len) != 0)) in lease_set_hwaddr()
384 memcpy(lease->hwaddr, hwaddr, hw_len); in lease_set_hwaddr()
385 lease->hwaddr_len = hw_len; in lease_set_hwaddr()
386 lease->hwaddr_type = hw_type; in lease_set_hwaddr()
387 lease->changed = file_dirty = 1; /* run script on change */ in lease_set_hwaddr()
395 if (!lease->clid) in lease_set_hwaddr()
396 lease->clid_len = 0; in lease_set_hwaddr()
398 if (lease->clid_len != clid_len) in lease_set_hwaddr()
400 lease->aux_changed = file_dirty = 1; in lease_set_hwaddr()
401 free(lease->clid); in lease_set_hwaddr()
402 if (!(lease->clid = whine_malloc(clid_len))) in lease_set_hwaddr()
405 else if (memcmp(lease->clid, clid, clid_len) != 0) in lease_set_hwaddr()
406 lease->aux_changed = file_dirty = 1; in lease_set_hwaddr()
408 lease->clid_len = clid_len; in lease_set_hwaddr()
409 memcpy(lease->clid, clid, clid_len); in lease_set_hwaddr()
414 static void kill_name(struct dhcp_lease *lease) in kill_name() argument
420 free(lease->old_hostname); in kill_name()
425 if (lease->fqdn) in kill_name()
427 lease->old_hostname = lease->fqdn; in kill_name()
428 free(lease->hostname); in kill_name()
431 lease->old_hostname = lease->hostname; in kill_name()
433 lease->hostname = lease->fqdn = NULL; in kill_name()
436 void lease_set_hostname(struct dhcp_lease *lease, char *name, int auth) in lease_set_hostname() argument
441 if (lease->hostname && name && hostname_isequal(lease->hostname, name)) in lease_set_hostname()
443 lease->auth_name = auth; in lease_set_hostname()
447 if (!name && !lease->hostname) in lease_set_hostname()
459 char *suffix = get_domain(lease->addr); in lease_set_hostname()
495 if (lease->hostname) in lease_set_hostname()
496 kill_name(lease); in lease_set_hostname()
498 lease->hostname = new_name; in lease_set_hostname()
499 lease->fqdn = new_fqdn; in lease_set_hostname()
500 lease->auth_name = auth; in lease_set_hostname()
504 lease->changed = 1; /* run script on change */ in lease_set_hostname()
507 void lease_set_interface(struct dhcp_lease *lease, int interface) in lease_set_interface() argument
509 if (lease->last_interface == interface) in lease_set_interface()
512 lease->last_interface = interface; in lease_set_interface()
513 lease->changed = 1; in lease_set_interface()
518 struct dhcp_lease *lease; in rerun_scripts() local
520 for (lease = leases; lease; lease = lease->next) in rerun_scripts()
521 lease->changed = 1; in rerun_scripts()
531 struct dhcp_lease *lease; in do_script_run() local
542 lease = old_leases; in do_script_run()
545 if (lease->old_hostname) in do_script_run()
548 queue_script(ACTION_OLD_HOSTNAME, lease, lease->old_hostname, now); in do_script_run()
550 free(lease->old_hostname); in do_script_run()
551 lease->old_hostname = NULL; in do_script_run()
556 kill_name(lease); in do_script_run()
558 queue_script(ACTION_DEL, lease, lease->old_hostname, now); in do_script_run()
561 emit_dbus_signal(ACTION_DEL, lease, lease->old_hostname); in do_script_run()
563 old_leases = lease->next; in do_script_run()
565 free(lease->old_hostname); in do_script_run()
566 free(lease->clid); in do_script_run()
567 free(lease->vendorclass); in do_script_run()
568 free(lease->userclass); in do_script_run()
569 free(lease->supplied_hostname); in do_script_run()
570 free(lease); in do_script_run()
577 for (lease = leases; lease; lease = lease->next) in do_script_run()
578 if (lease->old_hostname) in do_script_run()
581 queue_script(ACTION_OLD_HOSTNAME, lease, lease->old_hostname, now); in do_script_run()
583 free(lease->old_hostname); in do_script_run()
584 lease->old_hostname = NULL; in do_script_run()
588 for (lease = leases; lease; lease = lease->next) in do_script_run()
589 if (lease->new || lease->changed || in do_script_run()
590 (lease->aux_changed && (daemon->options & OPT_LEASE_RO))) in do_script_run()
593 queue_script(lease->new ? ACTION_ADD : ACTION_OLD, lease, in do_script_run()
594 lease->fqdn ? lease->fqdn : lease->hostname, now); in do_script_run()
597 emit_dbus_signal(lease->new ? ACTION_ADD : ACTION_OLD, lease, in do_script_run()
598 lease->fqdn ? lease->fqdn : lease->hostname); in do_script_run()
600 lease->new = lease->changed = lease->aux_changed = 0; in do_script_run()
603 free(lease->vendorclass); in do_script_run()
604 lease->vendorclass = NULL; in do_script_run()
606 free(lease->userclass); in do_script_run()
607 lease->userclass = NULL; in do_script_run()
609 free(lease->supplied_hostname); in do_script_run()
610 lease->supplied_hostname = NULL; in do_script_run()