Re: PATCH/Feature request



On 01/25/2012 09:19 PM, Dan Williams wrote:
On Mon, 2012-01-23 at 10:18 +0100, Oncaphillis wrote:
Hi,

Please find attached a patch against the current git
which re-enables DHCP/DNS Name transmission including
domain suffix as an option.

I have a rather dim DSL router with DHCP function
which doesn't accept any domain specific options
but allows for the transmission of a full hostname
via the "send host-name" command. I use the domain name
to distinguish between my VPN connection and the rest
of the world. So I used to add the full hostname
for NetworkManager. Now it chops off the
domain suffix before transmission.

   The attached patch adds a property "dhcp-with-domain"
to NetworkManager  which disables this behaviour when true.

   In addition the ifcfg-rh plugin enables this feature
if it finds the DHCP_WITH_DOMAIN=yes line in the corresponding
ifcfg-xxx file.

Just to clarify, you used to set your persistent system hostname to say
"mycomputer.foobar.org" and NM used to send that entire hostname to the
router, correct?  I know we changed it a while ago to only send the
hostname excluding the domain portion.  However, I think we should only
strip the hostname when we're using the system hostname.  If the user
manually specifies a name in dhclient-<xxx>.conf or in the connection
settings, then I think we should send exactly what the user entered.
That needs a bit of work though; we need to adjust the NMDhcpClient
class to take two hostnames to the client_start() function, one for the
system hostname and one for the hostname from the

 Hows about the attached patch ? It moves the decision to chop off the
domain part into nm_dhcp_manager_start_ip4 where we can decide if the
hostname came from the nm config or the system settings.

NMSettingIP4Config/NMSettingIP6Config.  Then internally
nm-dhcp-dhclient.c would know whether to strip the system hostname (if
the hostname from settings is missing) or to use the configured hostname
verbatim.  The original bug for stripping the hostname is rh#694758.

Dan


diff --git a/src/dhcp-manager/nm-dhcp-dhclient-utils.c b/src/dhcp-manager/nm-dhcp-dhclient-utils.c
index caf90f1..b2f49b4 100644
--- a/src/dhcp-manager/nm-dhcp-dhclient-utils.c
+++ b/src/dhcp-manager/nm-dhcp-dhclient-utils.c
@@ -166,19 +166,8 @@ nm_dhcp_dhclient_create_config (const char *interface,
 		}
 
 		if (hostname) {
-			char *plain_hostname, *dot;
-
-			plain_hostname = g_strdup (hostname);
-			dot = strchr (plain_hostname, '.');
-
-			/* get rid of the domain */
-			if (dot)
-				*dot = '\0';
-
-			g_string_append_printf (new_contents, HOSTNAME_FORMAT "\n", plain_hostname);
+			g_string_append_printf (new_contents, HOSTNAME_FORMAT "\n", hostname);
 			added = TRUE;
-
-			g_free (plain_hostname);
 		}
 
 		if (added)
diff --git a/src/dhcp-manager/nm-dhcp-manager.c b/src/dhcp-manager/nm-dhcp-manager.c
index e65f693..e8ef3ca 100644
--- a/src/dhcp-manager/nm-dhcp-manager.c
+++ b/src/dhcp-manager/nm-dhcp-manager.c
@@ -466,8 +466,9 @@ nm_dhcp_manager_start_ip4 (NMDHCPManager *self,
                            guint8 *dhcp_anycast_addr)
 {
 	NMDHCPManagerPrivate *priv;
-	NMDHCPClient *client = NULL;
-	const char *hostname = NULL;
+	NMDHCPClient *client   = NULL;
+	const char *hostname   = NULL;
+	char *chopped_hostname = NULL;
 
 	g_return_val_if_fail (self, NULL);
 	g_return_val_if_fail (NM_IS_DHCP_MANAGER (self), NULL);
@@ -493,16 +494,32 @@ nm_dhcp_manager_start_ip4 (NMDHCPManager *self,
 			 */
 			if (!hostname && priv->hostname_provider) {
 				hostname = nm_hostname_provider_get_hostname (priv->hostname_provider);
+
 				if (   hostname
 				    && (!strcmp (hostname, "localhost.localdomain") ||
 				        !strcmp (hostname, "localhost6.localdomain6")))
 					hostname = NULL;
+				else
+				{
+					char * dot = NULL; 
+					chopped_hostname = g_strdup (hostname);
+					dot = strchr (chopped_hostname, '.');
+
+					/* get rid of the domain */
+					if (dot)
+						*dot = '\0';
+					hostname = chopped_hostname;
+				}
 			}
 		}
 	}
 
 	client = client_start (self, iface, uuid, FALSE, s_ip4, NULL, timeout, dhcp_anycast_addr, hostname, FALSE);
 
+	if(chopped_hostname)
+	{
+		g_free (chopped_hostname);
+	}
 	return client;
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]