From e5b19cbed2032db214eec9a6191866f6f96355ef Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 21 Aug 2024 11:24:14 +0900 Subject: sd-dhcp-client: do not call callback with SD_DHCP_CLIENT_EVENT_STOP if already stopped When an interface enters the failed state, even if the DHCP client is stopped, the acquired DHCP lease is not unreferenced, as the callback dhcp4_handler() do nothing in that case. When the failed interface is being reconfigured after that, the DHCP client is stopped again (though it is already stopped), and SD_DHCP_CLIENT_EVENT_STOP event is triggered and sd_dhcp_client_send_release() is called, and the assertion in the function is triggered. E.g. === systemd-networkd[98588]: wlp59s0: DHCPv4 address 192.168.86.250/24, gateway 192.168.86.1 acquired from 192.168.86.1 systemd-networkd[98588]: wlp59s0: Could not set DHCPv4 route: Nexthop has invalid gateway. Network is unreachable systemd-networkd[98588]: wlp59s0: Failed systemd-networkd[98588]: wlp59s0: State changed: configuring -> failed systemd-networkd[98588]: wlp59s0: The interface entered the failed state frequently, refusing to reconfigure it automatically. systemd-networkd[98588]: wlp59s0: DHCPv4 client: STOPPED systemd-networkd[98588]: wlp59s0: DHCPv4 client: State changed: bound -> stopped systemd-networkd[98588]: Got message type=method_call sender=:1.449 destination=org.freedesktop.network1 path=/org/freedesktop/network1 interface=org.freedesktop.network1.Manager member=ReconfigureLink ... systemd-networkd[98588]: wlp59s0: State changed: failed -> initialized systemd-networkd[98588]: wlp59s0: found matching network '/etc/systemd/network/50-wifi.network'. systemd-networkd[98588]: wlp59s0: Configuring with /etc/systemd/network/50-wifi.network. systemd-networkd[98588]: wlp59s0: DHCPv4 client: STOPPED systemd-networkd[98588]: Assertion 'sd_dhcp_client_is_running(client)' failed at src/libsystemd-network/sd-dhcp-client.c:2197, function sd_dhcp_client_send_release(). Aborting. === --- src/libsystemd-network/sd-dhcp-client.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'src/libsystemd-network') diff --git a/src/libsystemd-network/sd-dhcp-client.c b/src/libsystemd-network/sd-dhcp-client.c index 1eb8509f0f..8b8d0611a2 100644 --- a/src/libsystemd-network/sd-dhcp-client.c +++ b/src/libsystemd-network/sd-dhcp-client.c @@ -683,15 +683,21 @@ static int client_initialize(sd_dhcp_client *client) { static void client_stop(sd_dhcp_client *client, int error) { assert(client); + DHCP_CLIENT_DONT_DESTROY(client); - if (error < 0) - log_dhcp_client_errno(client, error, "STOPPED: %m"); - else if (error == SD_DHCP_CLIENT_EVENT_STOP) - log_dhcp_client(client, "STOPPED"); - else - log_dhcp_client(client, "STOPPED: Unknown event"); - - client_notify(client, error); + if (sd_dhcp_client_is_running(client)) { + if (error < 0) + log_dhcp_client_errno(client, error, "STOPPED: %m"); + else if (error == SD_DHCP_CLIENT_EVENT_STOP) + log_dhcp_client(client, "STOPPED"); + else + log_dhcp_client(client, "STOPPED: Unknown event"); + + client_notify(client, error); + } else if (error < 0) { + log_dhcp_client_errno(client, error, "FAILED: %m"); + client_notify(client, error); + } client_initialize(client); } -- cgit v1.2.3