resolver: Add support for multiple search domains
authorHenri Bragge <henri.bragge@ixonos.com>
Tue, 7 Dec 2010 08:49:38 +0000 (10:49 +0200)
committerSamuel Ortiz <sameo@linux.intel.com>
Tue, 7 Dec 2010 18:04:42 +0000 (19:04 +0100)
Domains are appended to entry list just like nameservers, and finally exported
to /etc/resolv.conf. Domains are written to resolv.conf in reverse order so
that the most recently appended domain will have the highest priority.

Search domains should only be useful for resolvfile_resolver and should be
ignored by dnsproxy_resolver.

src/resolver.c
src/service.c

index cbb628e..6ee4d48 100644 (file)
@@ -164,7 +164,7 @@ static int append_resolver(const char *interface, const char *domain,
        DBG("interface %s domain %s server %s lifetime %d flags %d",
            interface, domain, server, lifetime, flags);
 
-       if (server == NULL)
+       if (server == NULL && domain == NULL)
                return -EINVAL;
 
        entry = g_try_new0(struct entry_data, 1);
@@ -409,14 +409,37 @@ static int resolvfile_export(void)
        content = g_string_new("# Generated by Connection Manager\n");
 
        /*
-        * Nameservers are added in reverse so that the most recently
-        * appended entry is the primary nameserver. No more than MAXNS
-        * nameservers are used.
+        * Domains and nameservers are added in reverse so that the most
+        * recently appended entry is the primary one. No more than
+        * MAXDNSRCH/MAXNS entries are used.
         */
+
+       for (count = 0, list = g_list_last(resolvfile_list);
+                                               list && (count < MAXDNSRCH);
+                                               list = g_list_previous(list)) {
+               struct resolvfile_entry *entry = list->data;
+
+               if (!entry->domain)
+                       continue;
+
+               if (count == 0)
+                       g_string_append_printf(content, "search ");
+
+               g_string_append_printf(content, "%s ", entry->domain);
+               count++;
+       }
+
+       if (count)
+               g_string_append_printf(content, "\n");
+
        for (count = 0, list = g_list_last(resolvfile_list);
                                                list && (count < MAXNS);
                                                list = g_list_previous(list)) {
                struct resolvfile_entry *entry = list->data;
+
+               if (!entry->server)
+                       continue;
+
                g_string_append_printf(content, "nameserver %s\n",
                                                                entry->server);
                count++;
index c49cb00..aecbe9a 100644 (file)
@@ -368,6 +368,15 @@ static void update_nameservers(struct connman_service *service)
        } else if (service->nameserver != NULL)
                connman_resolver_append(ifname, NULL, service->nameserver);
 
+       if (service->domains != NULL) {
+               int i;
+
+               for (i = 0; service->domains[i]; i++)
+                       connman_resolver_append(ifname, service->domains[i],
+                                               NULL);
+       } else if (service->domainname != NULL)
+               connman_resolver_append(ifname, service->domainname, NULL);
+
        connman_resolver_flush();
 }
 
@@ -1516,7 +1525,10 @@ const char *connman_service_get_domainname(struct connman_service *service)
        if (service == NULL)
                return NULL;
 
-       return service->domainname;
+       if (service->domains != NULL)
+               return service->domains[0];
+       else
+               return service->domainname;
 }
 
 const char *connman_service_get_nameserver(struct connman_service *service)
@@ -1986,7 +1998,7 @@ static DBusMessage *set_property(DBusConnection *conn,
 
                g_string_free(str, TRUE);
 
-               //update_domains(service);
+               update_nameservers(service);
                domain_configuration_changed(service);
 
                __connman_storage_save_service(service);
@@ -3030,6 +3042,7 @@ int __connman_service_indicate_state(struct connman_service *service,
 
                update_nameservers(service);
                dns_changed(service);
+               domain_changed(service);
 
                __connman_wpad_start(service);
 
@@ -3045,6 +3058,7 @@ int __connman_service_indicate_state(struct connman_service *service,
 
                update_nameservers(service);
                dns_changed(service);
+               domain_changed(service);
 
                __connman_notifier_disconnect(service->type);
        }