dhcp: ignore hostname when invalid

The hostname used for DHCP can be the one obtained from the hostnamed
service and is not guaranteed to be valid, at least with systemd
239. Instead of sending an invalid DHCP option to the server or
failing due to later checks in clients, ignore the hostname and log a
warning when it is invalid.

https://bugzilla.redhat.com/show_bug.cgi?id=1744427
This commit is contained in:
Beniamino Galvani 2019-10-17 17:40:29 +02:00
parent 38f942e038
commit 2da4d54ac3

View file

@ -17,6 +17,7 @@
#include <stdio.h>
#include "nm-glib-aux/nm-dedup-multi.h"
#include "systemd/nm-sd-utils-shared.h"
#include "nm-config.h"
#include "NetworkManagerUtils.h"
@ -252,6 +253,17 @@ client_start (NMDhcpManager *self,
g_return_val_if_reached (NULL) ;
}
if (hostname) {
if ( (hostname_use_fqdn && !nm_sd_dns_name_is_valid (hostname))
|| (!hostname_use_fqdn && !nm_sd_hostname_is_valid (hostname, FALSE))) {
nm_log_warn (LOGD_DHCP , "dhcp%c: %s '%s' is invalid, will be ignored",
nm_utils_addr_family_to_char (addr_family),
hostname_use_fqdn ? "FQDN" : "hostname",
hostname);
hostname = NULL;
}
}
nm_assert (g_bytes_get_size (hwaddr) == g_bytes_get_size (bcast_hwaddr));
priv = NM_DHCP_MANAGER_GET_PRIVATE (self);