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.
This commit is contained in:
Wen Liang 2024-12-05 17:13:22 -05:00
parent 96ff17fd48
commit bccf031591

View file

@ -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;