From 1f87275736daab5cc3ea06a8fc75fc16abc07c24 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Fri, 13 Jun 2025 07:24:04 +0900 Subject: [PATCH] network/dhcp4: release previously acquired DHCP lease when BOOTP will be enabled --- src/network/networkd-dhcp4.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/network/networkd-dhcp4.c b/src/network/networkd-dhcp4.c index 981b28b7776..4b0263ea72a 100644 --- a/src/network/networkd-dhcp4.c +++ b/src/network/networkd-dhcp4.c @@ -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. */ -- 2.47.3