service: Proper ordering of nameservers and search domains
authorPatrik Flykt <patrik.flykt@linux.intel.com>
Thu, 24 May 2012 13:25:02 +0000 (16:25 +0300)
committerPatrik Flykt <patrik.flykt@linux.intel.com>
Mon, 28 May 2012 14:00:46 +0000 (17:00 +0300)
The primary nameserver or search domain is the first element
in the array. When adding a nameserver or search domain to
the resolver, start from the end of the array since the resolver
functions expect the most important entry to be the last one
appended.

src/service.c

index 7d66a4b..5d73ba7 100644 (file)
@@ -942,16 +942,20 @@ static void update_nameservers(struct connman_service *service)
 
                remove_nameservers(service, ifname, service->nameservers);
 
-               for (i = 0; service->nameservers_config[i] != NULL; i++) {
+               i = g_strv_length(service->nameservers_config);
+               while (i != 0) {
+                       i--;
                        connman_resolver_append(ifname, NULL,
-                                               service->nameservers_config[i]);
+                                       service->nameservers_config[i]);
                }
        } else if (service->nameservers != NULL) {
                int i;
 
-               for (i = 0; service->nameservers[i] != NULL; i++) {
+               i = g_strv_length(service->nameservers);
+               while (i != 0) {
+                       i--;
                        connman_resolver_append(ifname, NULL,
-                                               service->nameservers[i]);
+                                       service->nameservers[i]);
                }
        }
 
@@ -962,9 +966,12 @@ static void update_nameservers(struct connman_service *service)
                searchdomains[0] = service->domainname;
                remove_searchdomains(service, ifname, searchdomains);
 
-               for (i = 0; service->domains[i]; i++)
+               i = g_strv_length(service->domains);
+               while (i != 0) {
+                       i--;
                        connman_resolver_append(ifname, service->domains[i],
                                                NULL);
+               }
        } else if (service->domainname != NULL)
                connman_resolver_append(ifname, service->domainname, NULL);