]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network/dhcp4: release previously acquired DHCP lease when BOOTP will be enabled
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 12 Jun 2025 22:24:04 +0000 (07:24 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 13 Jun 2025 05:15:04 +0000 (14:15 +0900)
src/network/networkd-dhcp4.c

index 981b28b77763ee659f45e7eb0549727d7739a9ef..4b0263ea72a587f5ff5dfc7238a662059997cf24 100644 (file)
@@ -1860,7 +1860,7 @@ int link_request_dhcp4_client(Link *link) {
 }
 
 int link_drop_dhcp4_config(Link *link, Network *network) {
-        int ret = 0;
+        int r, ret = 0;
 
         assert(link);
         assert(link->network);
@@ -1879,6 +1879,17 @@ int link_drop_dhcp4_config(Link *link, Network *network) {
                 RET_GATHER(ret, dhcp4_remove_address_and_routes(link, /* only_marked = */ false));
         }
 
+        if (link->dhcp_client && link->network->dhcp_use_bootp &&
+            network && !network->dhcp_use_bootp && network->dhcp_send_release) {
+                /* If the client was enabled as a DHCP client, and is now enabled as a BOOTP client, release
+                 * the previous lease. Note, this can be easily fail, e.g. when the interface is down. Hence,
+                 * ignore any failures here. */
+                r = sd_dhcp_client_send_release(link->dhcp_client);
+                if (r < 0)
+                        log_link_full_errno(link, ERRNO_IS_DISCONNECT(r) ? LOG_DEBUG : LOG_WARNING, r,
+                                            "Failed to send DHCP RELEASE, ignoring: %m");
+        }
+
         /* Even if the client is currently enabled and also enabled in the new .network file, detailed
          * settings for the client may be different. Let's unref() the client. But do not unref() the lease.
          * it will be unref()ed later when a new lease is acquired. */