-static void update_static_assignments(struct interface *iface)
-{
- struct dhcpv4_assignment *a, *c;
-
- /* Cleanup static entries not belonging to the network */
- list_for_each_entry_safe(a, c, &iface->dhcpv4_assignments, head) {
- if ((a->flags & OAF_STATIC) &&
- ((a->addr & iface->dhcpv4_mask.s_addr) !=
- (iface->dhcpv4_start.s_addr & iface->dhcpv4_mask.s_addr)))
- free_dhcpv4_assignment(a);
- }
-
- /* Parse static entries */
- struct lease *lease;
- list_for_each_entry(lease, &leases, head) {
- if ((iface->dhcpv4_start_ip.s_addr & iface->dhcpv4_mask.s_addr) !=
- (lease->ipaddr.s_addr & iface->dhcpv4_mask.s_addr)) {
- continue;
- }
-
- a = find_assignment_by_hwaddr(iface, lease->mac.ether_addr_octet);
-
- if (!a) {
- /* Check if there's an assignment with the specified IP address */
- if (find_assignment_by_addr(iface, lease->ipaddr.s_addr))
- continue;
-
- /* Construct entry */
- a = calloc(1, sizeof(*a));
- if (!a) {
- syslog(LOG_ERR, "Calloc failed for static lease on interface %s",
- iface->ifname);
- continue;
- }
- memcpy(a->hwaddr, lease->mac.ether_addr_octet, sizeof(a->hwaddr));
- }
-
- a->leasetime = lease->dhcpv4_leasetime;
-
- a->addr = lease->ipaddr.s_addr;
- /* Static assignment */
- a->flags |= OAF_STATIC;
- /* Infinite valid */
- a->valid_until = 0;
- a->iface = iface;
- if (lease->hostname[0]) {
- free(a->hostname);
- a->hostname = strdup(lease->hostname);
- }
-
- /* Assign to all interfaces */
- list_for_each_entry(c, &iface->dhcpv4_assignments, head) {
- if (ntohl(c->addr) > ntohl(a->addr)) {
- list_add_tail(&a->head, &c->head);
- break;
- }
- }
-
- if (&c->head == &iface->dhcpv4_assignments)
- list_add(&a->head, &iface->dhcpv4_assignments);
- }
-}
-