}
int link_drop_dhcp4_config(Link *link, Network *network) {
- int ret = 0;
+ int r, ret = 0;
assert(link);
assert(link->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. */