[PATCH 3/3] dhcp: Store host and domain name in service struct

Patrik Flykt patrik.flykt at linux.intel.com
Fri Sep 13 06:11:07 PDT 2013


Store host and domain name when a lease becomes available in order to
use use them if the service is selected to be the default.

When creating a DHCP request use the value previously obtained. If such
a value does not exist, use the system host name.

For link-local autoconfiguration use the system host name just as
before.
---
 src/dhcp.c |   30 ++++++++++--------------------
 1 file changed, 10 insertions(+), 20 deletions(-)

diff --git a/src/dhcp.c b/src/dhcp.c
index 273f918..ac12ff4 100644
--- a/src/dhcp.c
+++ b/src/dhcp.c
@@ -299,7 +299,6 @@ static void lease_available_cb(GDHCPClient *dhcp_client, gpointer user_data)
 	GList *list, *option = NULL;
 	char *address, *netmask = NULL, *gateway = NULL;
 	const char *c_address, *c_gateway;
-	char *domainname = NULL, *hostname = NULL;
 	char **nameservers, **timeservers, *pac = NULL;
 	int ns_entries;
 	struct connman_ipconfig *ipconfig;
@@ -374,14 +373,11 @@ static void lease_available_cb(GDHCPClient *dhcp_client, gpointer user_data)
 
 	option = g_dhcp_client_get_option(dhcp_client, G_DHCP_DOMAIN_NAME);
 	if (option)
-		domainname = g_strdup(option->data);
+		__connman_service_set_domainname(service, option->data);
 
-	if (connman_setting_get_bool("AllowHostnameUpdates")) {
-		option = g_dhcp_client_get_option(dhcp_client,
-						G_DHCP_HOST_NAME);
-		if (option)
-			hostname = g_strdup(option->data);
-	}
+	option = g_dhcp_client_get_option(dhcp_client, G_DHCP_HOST_NAME);
+	if (option)
+		__connman_service_set_hostname(service, option->data);
 
 	option = g_dhcp_client_get_option(dhcp_client, G_DHCP_NTP_SERVER);
 	ns_entries = g_list_length(option);
@@ -451,14 +447,6 @@ static void lease_available_cb(GDHCPClient *dhcp_client, gpointer user_data)
 		__connman_service_set_pac(service, dhcp->pac);
 	}
 
-	__connman_service_set_domainname(service, domainname);
-
-	if (domainname)
-		__connman_utsname_set_domainname(domainname);
-
-	if (hostname)
-		__connman_utsname_set_hostname(hostname);
-
 	if (ip_change)
 		dhcp_valid(dhcp);
 
@@ -467,8 +455,6 @@ static void lease_available_cb(GDHCPClient *dhcp_client, gpointer user_data)
 	g_free(address);
 	g_free(netmask);
 	g_free(gateway);
-	g_free(domainname);
-	g_free(hostname);
 }
 
 static void ipv4ll_available_cb(GDHCPClient *ipv4ll_client, gpointer user_data)
@@ -531,7 +517,12 @@ static int dhcp_request(struct connman_dhcp *dhcp)
 
 	g_dhcp_client_set_id(dhcp_client);
 
-	hostname = connman_utsname_get_hostname();
+	service = connman_service_lookup_from_network(dhcp->network);
+
+	hostname = __connman_service_get_hostname(service);
+	if (!hostname)
+		hostname = connman_utsname_get_hostname();
+
 	if (hostname)
 		g_dhcp_client_set_send(dhcp_client, G_DHCP_HOST_NAME, hostname);
 
@@ -555,7 +546,6 @@ static int dhcp_request(struct connman_dhcp *dhcp)
 
 	dhcp->dhcp_client = dhcp_client;
 
-	service = connman_service_lookup_from_network(dhcp->network);
 	ipconfig = __connman_service_get_ip4config(service);
 
 	/*
-- 
1.7.10.4




More information about the connman mailing list