dhcp: allow FQDNs in ipv4.dhcp-hostname
If users wrote a FQDN in ipv4.dhcp-hostname presumably it's because they really want to send the full value, not only the host part, so let's send it as-is. This obviously is a change in behavior, but only for users that have a FQDN in ipv4.dhcp-hostname, where it's not clear if they really want the domain to be stripped. When the property is unset, we keep sending only the host part of the system hostname to maintain backwards compatibility. This commit aligns NM behavior to initscripts.
This commit is contained in:
@@ -95,24 +95,14 @@ grab_request_options (GPtrArray *store, const char* line)
|
|||||||
static void
|
static void
|
||||||
add_hostname4 (GString *str, const char *hostname, gboolean use_fqdn)
|
add_hostname4 (GString *str, const char *hostname, gboolean use_fqdn)
|
||||||
{
|
{
|
||||||
char *plain_hostname, *dot;
|
|
||||||
|
|
||||||
if (hostname) {
|
if (hostname) {
|
||||||
if (use_fqdn) {
|
if (use_fqdn) {
|
||||||
g_string_append_printf (str, FQDN_FORMAT "\n", hostname);
|
g_string_append_printf (str, FQDN_FORMAT "\n", hostname);
|
||||||
g_string_append (str,
|
g_string_append (str,
|
||||||
"send fqdn.encoded on;\n"
|
"send fqdn.encoded on;\n"
|
||||||
"send fqdn.server-update on;\n");
|
"send fqdn.server-update on;\n");
|
||||||
} else {
|
} else
|
||||||
plain_hostname = g_strdup (hostname);
|
g_string_append_printf (str, HOSTNAME4_FORMAT "\n", hostname);
|
||||||
dot = strchr (plain_hostname, '.');
|
|
||||||
/* get rid of the domain */
|
|
||||||
if (dot)
|
|
||||||
*dot = '\0';
|
|
||||||
|
|
||||||
g_string_append_printf (str, HOSTNAME4_FORMAT "\n", plain_hostname);
|
|
||||||
g_free (plain_hostname);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -88,9 +88,8 @@ ip4_start (NMDhcpClient *client, const char *dhcp_anycast_addr, const char *last
|
|||||||
GPtrArray *argv = NULL;
|
GPtrArray *argv = NULL;
|
||||||
pid_t pid = -1;
|
pid_t pid = -1;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
char *pid_contents = NULL, *binary_name, *cmd_str, *dot;
|
char *pid_contents = NULL, *binary_name, *cmd_str;
|
||||||
const char *iface, *dhcpcd_path, *hostname;
|
const char *iface, *dhcpcd_path, *hostname;
|
||||||
gs_free char *prefix = NULL;
|
|
||||||
|
|
||||||
g_return_val_if_fail (priv->pid_file == NULL, FALSE);
|
g_return_val_if_fail (priv->pid_file == NULL, FALSE);
|
||||||
|
|
||||||
@@ -146,14 +145,8 @@ ip4_start (NMDhcpClient *client, const char *dhcp_anycast_addr, const char *last
|
|||||||
g_ptr_array_add (argv, (gpointer) "-F");
|
g_ptr_array_add (argv, (gpointer) "-F");
|
||||||
g_ptr_array_add (argv, (gpointer) "both");
|
g_ptr_array_add (argv, (gpointer) "both");
|
||||||
} else {
|
} else {
|
||||||
prefix = strdup (hostname);
|
g_ptr_array_add (argv, (gpointer) "-h");
|
||||||
dot = strchr (prefix, '.');
|
g_ptr_array_add (argv, (gpointer) hostname);
|
||||||
/* get rid of the domain */
|
|
||||||
if (dot)
|
|
||||||
*dot = '\0';
|
|
||||||
|
|
||||||
g_ptr_array_add (argv, (gpointer) "-h"); /* Send hostname to DHCP server */
|
|
||||||
g_ptr_array_add (argv, (gpointer) prefix);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -219,15 +219,6 @@ client_start (NMDhcpManager *self,
|
|||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *
|
|
||||||
get_send_hostname (NMDhcpManager *self, const char *setting_hostname)
|
|
||||||
{
|
|
||||||
NMDhcpManagerPrivate *priv = NM_DHCP_MANAGER_GET_PRIVATE (self);
|
|
||||||
|
|
||||||
/* Always prefer the explicit dhcp-send-hostname if given */
|
|
||||||
return setting_hostname ? setting_hostname : priv->default_hostname;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Caller owns a reference to the NMDhcpClient on return */
|
/* Caller owns a reference to the NMDhcpClient on return */
|
||||||
NMDhcpClient *
|
NMDhcpClient *
|
||||||
nm_dhcp_manager_start_ip4 (NMDhcpManager *self,
|
nm_dhcp_manager_start_ip4 (NMDhcpManager *self,
|
||||||
@@ -244,17 +235,36 @@ nm_dhcp_manager_start_ip4 (NMDhcpManager *self,
|
|||||||
const char *dhcp_anycast_addr,
|
const char *dhcp_anycast_addr,
|
||||||
const char *last_ip_address)
|
const char *last_ip_address)
|
||||||
{
|
{
|
||||||
|
NMDhcpManagerPrivate *priv;
|
||||||
const char *hostname = NULL;
|
const char *hostname = NULL;
|
||||||
|
gs_free char *hostname_tmp = NULL;
|
||||||
gboolean use_fqdn = FALSE;
|
gboolean use_fqdn = FALSE;
|
||||||
|
char *dot;
|
||||||
|
|
||||||
g_return_val_if_fail (NM_IS_DHCP_MANAGER (self), NULL);
|
g_return_val_if_fail (NM_IS_DHCP_MANAGER (self), NULL);
|
||||||
|
priv = NM_DHCP_MANAGER_GET_PRIVATE (self);
|
||||||
|
|
||||||
if (send_hostname) {
|
if (send_hostname) {
|
||||||
|
/* Use, in order of preference:
|
||||||
|
* 1. FQDN from configuration
|
||||||
|
* 2. hostname from configuration
|
||||||
|
* 3. system hostname (only host part)
|
||||||
|
*/
|
||||||
if (dhcp_fqdn) {
|
if (dhcp_fqdn) {
|
||||||
hostname = dhcp_fqdn;
|
hostname = dhcp_fqdn;
|
||||||
use_fqdn = TRUE;
|
use_fqdn = TRUE;
|
||||||
} else
|
} else if (dhcp_hostname)
|
||||||
hostname = get_send_hostname (self, dhcp_hostname);
|
hostname = dhcp_hostname;
|
||||||
|
else {
|
||||||
|
hostname = priv->default_hostname;
|
||||||
|
if (hostname) {
|
||||||
|
hostname_tmp = g_strdup (hostname);
|
||||||
|
dot = strchr (hostname_tmp, '.');
|
||||||
|
if (dot)
|
||||||
|
*dot = '\0';
|
||||||
|
hostname = hostname_tmp;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return client_start (self, iface, ifindex, hwaddr, uuid, priority, FALSE, NULL,
|
return client_start (self, iface, ifindex, hwaddr, uuid, priority, FALSE, NULL,
|
||||||
@@ -279,12 +289,16 @@ nm_dhcp_manager_start_ip6 (NMDhcpManager *self,
|
|||||||
NMSettingIP6ConfigPrivacy privacy,
|
NMSettingIP6ConfigPrivacy privacy,
|
||||||
guint needed_prefixes)
|
guint needed_prefixes)
|
||||||
{
|
{
|
||||||
|
NMDhcpManagerPrivate *priv;
|
||||||
const char *hostname = NULL;
|
const char *hostname = NULL;
|
||||||
|
|
||||||
g_return_val_if_fail (NM_IS_DHCP_MANAGER (self), NULL);
|
g_return_val_if_fail (NM_IS_DHCP_MANAGER (self), NULL);
|
||||||
|
priv = NM_DHCP_MANAGER_GET_PRIVATE (self);
|
||||||
|
|
||||||
if (send_hostname)
|
if (send_hostname) {
|
||||||
hostname = get_send_hostname (self, dhcp_hostname);
|
/* Always prefer the explicit dhcp-hostname if given */
|
||||||
|
hostname = dhcp_hostname ? dhcp_hostname : priv->default_hostname;
|
||||||
|
}
|
||||||
return client_start (self, iface, ifindex, hwaddr, uuid, priority, TRUE,
|
return client_start (self, iface, ifindex, hwaddr, uuid, priority, TRUE,
|
||||||
ll_addr, NULL, timeout, dhcp_anycast_addr, hostname, TRUE, info_only,
|
ll_addr, NULL, timeout, dhcp_anycast_addr, hostname, TRUE, info_only,
|
||||||
privacy, NULL, needed_prefixes);
|
privacy, NULL, needed_prefixes);
|
||||||
|
@@ -687,28 +687,14 @@ ip4_start (NMDhcpClient *client, const char *dhcp_anycast_addr, const char *last
|
|||||||
|
|
||||||
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)) {
|
/* FIXME: sd-dhcp decides which hostname/FQDN option to send (12 or 81)
|
||||||
r = sd_dhcp_client_set_hostname (priv->client4, hostname);
|
* only based on whether the hostname has a domain part or not. At the
|
||||||
if (r < 0) {
|
* moment there is no way to force one or another.
|
||||||
_LOGW ("failed to set DHCP FQDN (%d)", r);
|
*/
|
||||||
goto error;
|
r = sd_dhcp_client_set_hostname (priv->client4, hostname);
|
||||||
}
|
if (r < 0) {
|
||||||
} else {
|
_LOGW ("failed to set DHCP hostname to '%s' (%d)", hostname, r);
|
||||||
char *prefix, *dot;
|
goto error;
|
||||||
|
|
||||||
prefix = strdup (hostname);
|
|
||||||
dot = strchr (prefix, '.');
|
|
||||||
/* get rid of the domain */
|
|
||||||
if (dot)
|
|
||||||
*dot = '\0';
|
|
||||||
|
|
||||||
r = sd_dhcp_client_set_hostname (priv->client4, prefix);
|
|
||||||
free (prefix);
|
|
||||||
|
|
||||||
if (r < 0) {
|
|
||||||
_LOGW ("failed to set DHCP hostname (%d)", r);
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user