]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-dhcp-server: explicitly refuse when conflicting address is requested
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 27 Jan 2022 18:50:57 +0000 (03:50 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 1 Feb 2022 02:56:22 +0000 (11:56 +0900)
src/libsystemd-network/sd-dhcp-server.c

index ddcd6910e90f2e88afe7c655f181b989474bb8ad..2f429020bbced9f1be65c7894eeb1cdc107bc48a 100644 (file)
@@ -1140,14 +1140,17 @@ int dhcp_server_handle_message(sd_dhcp_server *server, DHCPMessage *message, siz
                         return DHCP_ACK;
                 }
 
-                DHCPLease *existing_lease_by_address = hashmap_get(server->bound_leases_by_address, UINT32_TO_PTR(address));
-                if (address_is_in_pool(server, address) && existing_lease_by_address == existing_lease) {
+                if (address_is_in_pool(server, address)) {
+                        /* The requested address is in the pool. */
+
+                        if (existing_lease && existing_lease->address != address)
+                                /* We previously assigned an address, but the client requested another one. Refuse. */
+                                return server_send_nak_or_ignore(server, init_reboot, req);
+
                         _cleanup_(dhcp_lease_freep) DHCPLease *new_lease = NULL;
                         usec_t time_now, expiration;
                         DHCPLease *lease;
 
-                        /* Note that in the above condition we accept the case that both leases are NULL. */
-
                         r = sd_event_now(server->event, clock_boottime_or_monotonic(), &time_now);
                         if (r < 0)
                                 return r;