diff options
Diffstat (limited to 'src/dhcp/nm-dhcp-manager.c')
| -rw-r--r-- | src/dhcp/nm-dhcp-manager.c | 54 |
1 files changed, 36 insertions, 18 deletions
diff --git a/src/dhcp/nm-dhcp-manager.c b/src/dhcp/nm-dhcp-manager.c index 9c1fbb38..fff9f9ec 100644 --- a/src/dhcp/nm-dhcp-manager.c +++ b/src/dhcp/nm-dhcp-manager.c @@ -163,7 +163,7 @@ client_start (NMDhcpManager *self, guint32 timeout, const char *dhcp_anycast_addr, const char *hostname, - const char *fqdn, + gboolean hostname_use_fqdn, gboolean info_only, NMSettingIP6ConfigPrivacy privacy, const char *last_ip4_address, @@ -209,7 +209,7 @@ client_start (NMDhcpManager *self, if (ipv6) success = nm_dhcp_client_start_ip6 (client, dhcp_anycast_addr, ipv6_ll_addr, hostname, info_only, privacy, needed_prefixes); else - success = nm_dhcp_client_start_ip4 (client, dhcp_client_id, dhcp_anycast_addr, hostname, fqdn, last_ip4_address); + success = nm_dhcp_client_start_ip4 (client, dhcp_client_id, dhcp_anycast_addr, hostname, hostname_use_fqdn, last_ip4_address); if (!success) { remove_client (self, client); @@ -219,15 +219,6 @@ client_start (NMDhcpManager *self, 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 */ NMDhcpClient * nm_dhcp_manager_start_ip4 (NMDhcpManager *self, @@ -244,18 +235,41 @@ nm_dhcp_manager_start_ip4 (NMDhcpManager *self, const char *dhcp_anycast_addr, const char *last_ip_address) { + NMDhcpManagerPrivate *priv; const char *hostname = NULL; - const char *fqdn = NULL; + gs_free char *hostname_tmp = NULL; + gboolean use_fqdn = FALSE; + char *dot; g_return_val_if_fail (NM_IS_DHCP_MANAGER (self), NULL); + priv = NM_DHCP_MANAGER_GET_PRIVATE (self); if (send_hostname) { - hostname = get_send_hostname (self, dhcp_hostname); - fqdn = dhcp_fqdn; + /* Use, in order of preference: + * 1. FQDN from configuration + * 2. hostname from configuration + * 3. system hostname (only host part) + */ + if (dhcp_fqdn) { + hostname = dhcp_fqdn; + use_fqdn = TRUE; + } else if (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, dhcp_client_id, timeout, dhcp_anycast_addr, hostname, - fqdn, FALSE, 0, last_ip_address, 0); + use_fqdn, FALSE, 0, last_ip_address, 0); } /* Caller owns a reference to the NMDhcpClient on return */ @@ -275,14 +289,18 @@ nm_dhcp_manager_start_ip6 (NMDhcpManager *self, NMSettingIP6ConfigPrivacy privacy, guint needed_prefixes) { + NMDhcpManagerPrivate *priv; const char *hostname = NULL; g_return_val_if_fail (NM_IS_DHCP_MANAGER (self), NULL); + priv = NM_DHCP_MANAGER_GET_PRIVATE (self); - if (send_hostname) - hostname = get_send_hostname (self, dhcp_hostname); + if (send_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, - ll_addr, NULL, timeout, dhcp_anycast_addr, hostname, NULL, info_only, + ll_addr, NULL, timeout, dhcp_anycast_addr, hostname, TRUE, info_only, privacy, NULL, needed_prefixes); } |