From bccf03159115fcbdc94d2a96d54f80b1aff7d625 Mon Sep 17 00:00:00 2001 From: Wen Liang Date: Thu, 5 Dec 2024 17:13:22 -0500 Subject: [PATCH] n-dhcp4: do not send the release message in wrong connection state We should not send the DHCP release message when udp socket is still in the PACKET state, this state is typically used during the discovery and offer phases, where the client broadcasts DHCP packets like DHCPDISCOVER and receives responses like DHCPOFFER. At this point, the client has no lease because it has not yet completed the DHCP handshake. --- src/n-dhcp4/src/n-dhcp4-c-probe.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/n-dhcp4/src/n-dhcp4-c-probe.c b/src/n-dhcp4/src/n-dhcp4-c-probe.c index ee3a8886bd..c37f1e207b 100644 --- a/src/n-dhcp4/src/n-dhcp4-c-probe.c +++ b/src/n-dhcp4/src/n-dhcp4-c-probe.c @@ -1332,6 +1332,10 @@ int n_dhcp4_client_probe_release(NDhcp4ClientProbe *probe) { _c_cleanup_(n_dhcp4_outgoing_freep) NDhcp4Outgoing *request_out = NULL; int r; + if (probe->connection.state != N_DHCP4_C_CONNECTION_STATE_DRAINING + && probe->connection.state != N_DHCP4_C_CONNECTION_STATE_UDP) + return -ENOTRECOVERABLE; + r = n_dhcp4_c_connection_release_new(&probe->connection, &request_out, NULL); if (r) return r;