network/dhcp4: release previously acquired DHCP lease when BOOTP will be enabled

This commit is contained in:
Yu Watanabe
2025-06-13 07:24:04 +09:00
parent 0dbb5139a7
commit 1f87275736

View 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. */