mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-06-11 02:38:31 +02:00
dhcp: support FQDN flags in the nettools backend
Make the nettools backed honor the ipv4.dhcp-hostname-flags property.
This commit is contained in:
parent
316ff68bfa
commit
aa8d5a3e9e
1 changed files with 41 additions and 20 deletions
|
|
@ -71,13 +71,6 @@ G_DEFINE_TYPE (NMDhcpNettools, nm_dhcp_nettools, NM_TYPE_DHCP_CLIENT)
|
||||||
|
|
||||||
#define DHCP_MAX_FQDN_LENGTH 255
|
#define DHCP_MAX_FQDN_LENGTH 255
|
||||||
|
|
||||||
enum {
|
|
||||||
DHCP_FQDN_FLAG_S = (1 << 0),
|
|
||||||
DHCP_FQDN_FLAG_O = (1 << 1),
|
|
||||||
DHCP_FQDN_FLAG_E = (1 << 2),
|
|
||||||
DHCP_FQDN_FLAG_N = (1 << 3),
|
|
||||||
};
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
NM_IN_ADDR_CLASS_A,
|
NM_IN_ADDR_CLASS_A,
|
||||||
NM_IN_ADDR_CLASS_B,
|
NM_IN_ADDR_CLASS_B,
|
||||||
|
|
@ -1220,6 +1213,22 @@ decline (NMDhcpClient *client,
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static guint8
|
||||||
|
fqdn_flags_to_wire (NMDhcpHostnameFlags flags)
|
||||||
|
{
|
||||||
|
guint r = 0;
|
||||||
|
|
||||||
|
/* RFC 4702 section 2.1 */
|
||||||
|
if (flags & NM_DHCP_HOSTNAME_FLAG_FQDN_SERV_UPDATE)
|
||||||
|
r |= (1 << 0);
|
||||||
|
if (flags & NM_DHCP_HOSTNAME_FLAG_FQDN_ENCODED)
|
||||||
|
r |= (1 << 2);
|
||||||
|
if (flags & NM_DHCP_HOSTNAME_FLAG_FQDN_NO_UPDATE)
|
||||||
|
r |= (1 << 3);
|
||||||
|
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
ip4_start (NMDhcpClient *client,
|
ip4_start (NMDhcpClient *client,
|
||||||
const char *dhcp_anycast_addr,
|
const char *dhcp_anycast_addr,
|
||||||
|
|
@ -1289,26 +1298,38 @@ ip4_start (NMDhcpClient *client,
|
||||||
hostname = nm_dhcp_client_get_hostname (client);
|
hostname = nm_dhcp_client_get_hostname (client);
|
||||||
if (hostname) {
|
if (hostname) {
|
||||||
if (nm_dhcp_client_get_use_fqdn (client)) {
|
if (nm_dhcp_client_get_use_fqdn (client)) {
|
||||||
uint8_t buffer[3 + DHCP_MAX_FQDN_LENGTH];
|
uint8_t buffer[255];
|
||||||
|
NMDhcpHostnameFlags flags;
|
||||||
|
size_t fqdn_len;
|
||||||
|
|
||||||
buffer[0] = DHCP_FQDN_FLAG_S | /* Request server to perform A RR DNS updates */
|
flags = nm_dhcp_client_get_hostname_flags (client);
|
||||||
DHCP_FQDN_FLAG_E; /* Canonical wire format */
|
buffer[0] = fqdn_flags_to_wire (flags);
|
||||||
buffer[1] = 0; /* RCODE1 (deprecated) */
|
buffer[1] = 0; /* RCODE1 (deprecated) */
|
||||||
buffer[2] = 0; /* RCODE2 (deprecated) */
|
buffer[2] = 0; /* RCODE2 (deprecated) */
|
||||||
|
|
||||||
r = nm_sd_dns_name_to_wire_format (hostname,
|
if (flags & NM_DHCP_HOSTNAME_FLAG_FQDN_ENCODED) {
|
||||||
buffer + 3,
|
r = nm_sd_dns_name_to_wire_format (hostname,
|
||||||
sizeof (buffer) - 3,
|
buffer + 3,
|
||||||
FALSE);
|
sizeof (buffer) - 3,
|
||||||
if (r < 0) {
|
FALSE);
|
||||||
nm_utils_error_set_errno (error, r, "failed to convert DHCP FQDN: %s");
|
if (r <= 0) {
|
||||||
return FALSE;
|
nm_utils_error_set_errno (error, r, "failed to convert DHCP FQDN: %s");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
fqdn_len = r;
|
||||||
|
} else {
|
||||||
|
fqdn_len = strlen (hostname);
|
||||||
|
if (fqdn_len > sizeof (buffer) - 3) {
|
||||||
|
nm_utils_error_set (error, r, "failed to set DHCP FQDN: name too long");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
memcpy (buffer + 3, hostname, fqdn_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
r = n_dhcp4_client_probe_config_append_option (config,
|
r = n_dhcp4_client_probe_config_append_option (config,
|
||||||
NM_DHCP_OPTION_DHCP4_CLIENT_FQDN,
|
NM_DHCP_OPTION_DHCP4_CLIENT_FQDN,
|
||||||
buffer,
|
buffer,
|
||||||
3 + r);
|
3 + fqdn_len);
|
||||||
if (r) {
|
if (r) {
|
||||||
nm_utils_error_set_errno (error, r, "failed to set DHCP FQDN: %s");
|
nm_utils_error_set_errno (error, r, "failed to set DHCP FQDN: %s");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue