diff options
Diffstat (limited to 'src/resolver.c')
-rw-r--r-- | src/resolver.c | 98 |
1 files changed, 63 insertions, 35 deletions
diff --git a/src/resolver.c b/src/resolver.c index 652f4fd9..75ea5ba6 100644 --- a/src/resolver.c +++ b/src/resolver.c @@ -35,6 +35,9 @@ #include "connman.h" +#define RESOLV_CONF_STATEDIR STATEDIR"/resolv.conf" +#define RESOLV_CONF_ETC "/etc/resolv.conf" + #define RESOLVER_FLAG_PUBLIC (1 << 0) /* @@ -97,9 +100,9 @@ static int resolvfile_export(void) * MAXDNSRCH/MAXNS entries are used. */ - for (count = 0, list = g_list_last(resolvfile_list); + for (count = 0, list = g_list_first(resolvfile_list); list && (count < MAXDNSRCH); - list = g_list_previous(list)) { + list = g_list_next(list)) { struct resolvfile_entry *entry = list->data; if (!entry->domain) @@ -115,9 +118,9 @@ static int resolvfile_export(void) if (count) g_string_append_printf(content, "\n"); - for (count = 0, list = g_list_last(resolvfile_list); + for (count = 0, list = g_list_first(resolvfile_list); list && (count < MAXNS); - list = g_list_previous(list)) { + list = g_list_next(list)) { struct resolvfile_entry *entry = list->data; if (!entry->server) @@ -130,11 +133,19 @@ static int resolvfile_export(void) old_umask = umask(022); - fd = open("/etc/resolv.conf", O_RDWR | O_CREAT | O_CLOEXEC, + fd = open(RESOLV_CONF_STATEDIR, O_RDWR | O_CREAT | O_CLOEXEC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); if (fd < 0) { - err = -errno; - goto done; + connman_warn_once("Cannot create "RESOLV_CONF_STATEDIR" " + "falling back to "RESOLV_CONF_ETC); + + fd = open(RESOLV_CONF_ETC, O_RDWR | O_CREAT | O_CLOEXEC, + S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + + if (fd < 0) { + err = -errno; + goto done; + } } if (ftruncate(fd, 0) < 0) { @@ -207,7 +218,7 @@ int __connman_resolvfile_remove(int index, const char *domain, return resolvfile_export(); } -static void append_fallback_nameservers(void) +void __connman_resolver_append_fallback_nameservers(void) { GSList *list; @@ -283,6 +294,8 @@ static void remove_entries(GSList *entries) } g_slist_free(entries); + + __connman_resolver_append_fallback_nameservers(); } static gboolean resolver_expire_cb(gpointer user_data) @@ -376,18 +389,6 @@ static int append_resolver(int index, const char *domain, entry->timeout = g_timeout_add_seconds(interval, resolver_refresh_cb, entry); - - /* - * We update the service only for those nameservers - * that are automagically added via netlink (lifetime > 0) - */ - if (server && entry->index >= 0) { - struct connman_service *service; - service = __connman_service_lookup_from_index(entry->index); - if (service) - __connman_service_nameserver_append(service, - server, true); - } } if (entry->index >= 0 && entry->server) @@ -400,6 +401,18 @@ static int append_resolver(int index, const char *domain, else __connman_resolvfile_append(entry->index, domain, server); + /* + * We update the service only for those nameservers + * that are automagically added via netlink (lifetime > 0) + */ + if (server && entry->index >= 0 && lifetime) { + struct connman_service *service; + service = __connman_service_lookup_from_index(entry->index); + if (service) + __connman_service_nameserver_append(service, + server, true); + } + return 0; } @@ -562,21 +575,6 @@ int connman_resolver_remove_all(int index) return 0; } -/** - * connman_resolver_flush: - * - * Flush pending resolver requests - */ -void connman_resolver_flush(void) -{ - append_fallback_nameservers(); - - if (dnsproxy_enabled) - __connman_dnsproxy_flush(); - - return; -} - int __connman_resolver_redo_servers(int index) { GSList *list; @@ -613,6 +611,28 @@ int __connman_resolver_redo_servers(int index) entry->server); } + /* + * We want to re-add all search domains back to search + * domain lists as they just got removed for RDNSS IPv6-servers + * (above). + * Removal of search domains is not necessary + * as there can be only one instance of each search domain + * in the each dns-servers search domain list. + */ + + for (list = entry_list; list; list = list->next) { + struct entry_data *entry = list->data; + + if (entry->index != index) + continue; + + if (entry->server) + continue; + + __connman_dnsproxy_append(entry->index, entry->domain, + NULL); + } + return 0; } @@ -639,6 +659,14 @@ int __connman_resolver_init(gboolean dnsproxy) DBG("dnsproxy %d", dnsproxy); + /* get autoip nameservers */ + ns = __connman_inet_get_pnp_nameservers(NULL); + for (i = 0; ns && ns[i]; i += 1) { + DBG("pnp server %s", ns[i]); + append_resolver(i, NULL, ns[i], 86400, 0); + } + g_strfreev(ns); + if (!dnsproxy) return 0; |