n-dhcp4: add an accessor for the file name in the lease

The name of the boot file can be either in option 67 or in a field of
the DHCP header. Add an accessor for the one from the DHCP header.

(cherry picked from commit 6a1349c5fb)
This commit is contained in:
Beniamino Galvani 2021-07-14 11:57:59 +02:00
parent a4acfef3aa
commit 50e65f8ce4
3 changed files with 38 additions and 0 deletions

View file

@ -37,6 +37,7 @@ global:
n_dhcp4_client_lease_get_siaddr;
n_dhcp4_client_lease_get_lifetime;
n_dhcp4_client_lease_get_server_identifier;
n_dhcp4_client_lease_get_file;
n_dhcp4_client_lease_query;
n_dhcp4_client_lease_select;
n_dhcp4_client_lease_accept;

View file

@ -269,6 +269,42 @@ _c_public_ int n_dhcp4_client_lease_get_server_identifier(NDhcp4ClientLease *lea
return 0;
}
/**
* n_dhcp4_client_lease_get_file() - query the lease for the boot file name
* @lease: the lease to operate on
* @file: return argument for the file name
*
* Query the lease for the boot file name from the DHCP header. The file name
* is returned as a NULL-terminated string.
*
* Return: 0 on success,
* N_DHCP4_E_UNSET if the lease does not contain a file name, or
* N_DCHP4_E_INTERNAL if the file name is invalid.
*/
_c_public_ int n_dhcp4_client_lease_get_file(NDhcp4ClientLease *lease, const char **file) {
NDhcp4Message *message;
if (lease->message->options[N_DHCP4_OPTION_OVERLOAD].size > 0
&& ((*lease->message->options[N_DHCP4_OPTION_OVERLOAD].value) & N_DHCP4_OVERLOAD_FILE)) {
/* The field is overloaded to contain other options */
return N_DHCP4_E_UNSET;
}
message = &lease->message->message;
if (message->file[0] == '\0')
return N_DHCP4_E_UNSET;
if (!memchr(message->file, '\0', sizeof(message->file))) {
/* The field is NULL-terminated (RFC 2131 section 2) */
return N_DHCP4_E_INTERNAL;
}
*file = (const char *) message->file;
return 0;
}
/**
* n_dhcp4_client_lease_query() - query the lease for an option
* @lease: the lease to operate on

View file

@ -172,6 +172,7 @@ void n_dhcp4_client_lease_get_basetime(NDhcp4ClientLease *lease, uint64_t *ns_ba
void n_dhcp4_client_lease_get_lifetime(NDhcp4ClientLease *lease, uint64_t *ns_lifetimep);
int n_dhcp4_client_lease_query(NDhcp4ClientLease *lease, uint8_t option, uint8_t **datap, size_t *n_datap);
int n_dhcp4_client_lease_get_server_identifier(NDhcp4ClientLease *lease, struct in_addr *addr);
int n_dhcp4_client_lease_get_file(NDhcp4ClientLease *lease, const char **file);
int n_dhcp4_client_lease_select(NDhcp4ClientLease *lease);
int n_dhcp4_client_lease_accept(NDhcp4ClientLease *lease);