return NULL;
if (lease->server) {
- DHCPLease *e;
-
- e = hashmap_get(lease->server->bound_leases_by_client_id, &lease->client_id);
- if (e == lease) {
- hashmap_remove(lease->server->bound_leases_by_address, UINT32_TO_PTR(lease->address));
- hashmap_remove(lease->server->bound_leases_by_client_id, &lease->client_id);
- }
-
- e = hashmap_get(lease->server->static_leases_by_client_id, &lease->client_id);
- if (e == lease) {
- hashmap_remove(lease->server->static_leases_by_address, UINT32_TO_PTR(lease->address));
- hashmap_remove(lease->server->static_leases_by_client_id, &lease->client_id);
- }
+ hashmap_remove_value(lease->server->bound_leases_by_address, UINT32_TO_PTR(lease->address), lease);
+ hashmap_remove_value(lease->server->bound_leases_by_client_id, &lease->client_id, lease);
+ hashmap_remove_value(lease->server->static_leases_by_address, UINT32_TO_PTR(lease->address), lease);
+ hashmap_remove_value(lease->server->static_leases_by_client_id, &lease->client_id, lease);
}
free(lease->client_id.data);
log_dhcp_server(server, "ACK (0x%x)", be32toh(req->message->xid));
- dhcp_lease_free(hashmap_remove(server->bound_leases_by_client_id, &lease->client_id));
+ dhcp_lease_free(hashmap_get(server->bound_leases_by_client_id, &lease->client_id));
+
+ lease->server = server; /* This must be set just before hashmap_put(). */
+
r = hashmap_ensure_put(&server->bound_leases_by_client_id, &dhcp_lease_hash_ops, &lease->client_id, lease);
if (r < 0)
return log_dhcp_server_errno(server, r, "Could not save lease: %m");
if (r < 0)
return log_dhcp_server_errno(server, r, "Could not save lease: %m");
- lease->server = server;
TAKE_PTR(lease);
if (server->callback)
log_dhcp_server(server, "ACK (0x%x)", be32toh(req->message->xid));
+ lease->server = server; /* This must be set just before hashmap_put(). */
+
r = hashmap_ensure_put(&server->bound_leases_by_client_id, &dhcp_lease_hash_ops, &lease->client_id, lease);
if (r < 0)
return log_dhcp_server_errno(server, r, "Could not save lease: %m");
if (r < 0)
return log_dhcp_server_errno(server, r, "Could not save lease: %m");
- lease->server = server;
TAKE_PTR(new_lease);
if (server->callback)
.data = client_id,
};
- dhcp_lease_free(hashmap_remove(server->static_leases_by_client_id, &c));
+ dhcp_lease_free(hashmap_get(server->static_leases_by_client_id, &c));
return 0;
}
- if (hashmap_contains(server->static_leases_by_address, UINT32_TO_PTR(address->s_addr)))
- return -EEXIST;
-
lease = new(DHCPLease, 1);
if (!lease)
return -ENOMEM;
if (!lease->client_id.data)
return -ENOMEM;
+ lease->server = server; /* This must be set just before hashmap_put(). */
+
r = hashmap_ensure_put(&server->static_leases_by_client_id, &dhcp_lease_hash_ops, &lease->client_id, lease);
if (r < 0)
return r;
if (r < 0)
return r;
- lease->server = server;
TAKE_PTR(lease);
return 0;
}