n-dhcp4: add new client probe function to send RELEASE message

The new function uses the client probe connection to send a RELEASE
message. Returns zero if successful otherwise returns non-zero value.
This commit is contained in:
Fernando Fernandez Mancera 2024-01-29 11:26:12 +01:00
parent 0f0f1bbf8a
commit 243cc433fb
2 changed files with 28 additions and 0 deletions

View file

@ -1319,3 +1319,30 @@ int n_dhcp4_client_probe_dispatch_io(NDhcp4ClientProbe *probe, uint32_t events)
int n_dhcp4_client_probe_update_mtu(NDhcp4ClientProbe *probe, uint16_t mtu) {
return 0;
}
/**
* n_dhcp4_client_probe_release() - send a release request
* @probe: probe to operate on
*
* This sends a RELEASE message on the connection used by the probe.
*
* Return: 0 if successful otherwise non-zero value is returned.
*/
int n_dhcp4_client_probe_release(NDhcp4ClientProbe *probe) {
_c_cleanup_(n_dhcp4_outgoing_freep) NDhcp4Outgoing *request_out = NULL;
int r;
r = n_dhcp4_c_connection_release_new(&probe->connection, &request_out, NULL);
if (r)
return r;
r = n_dhcp4_c_connection_start_request(&probe->connection, request_out, 0);
if (r)
return r;
probe->state = N_DHCP4_CLIENT_PROBE_STATE_INIT;
n_dhcp4_client_lease_unlink(probe->current_lease);
request_out = NULL;
return 0;
}

View file

@ -161,6 +161,7 @@ NDhcp4ClientProbe *n_dhcp4_client_probe_free(NDhcp4ClientProbe *probe);
void n_dhcp4_client_probe_set_userdata(NDhcp4ClientProbe *probe, void *userdata);
void n_dhcp4_client_probe_get_userdata(NDhcp4ClientProbe *probe, void **userdatap);
int n_dhcp4_client_probe_release(NDhcp4ClientProbe *probe);
/* client leases */