*
* Connection Manager
*
- * Copyright (C) 2007-2010 Intel Corporation. All rights reserved.
+ * Copyright (C) 2007-2013 Intel Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
#include <string.h>
#include <sys/stat.h>
#include <resolv.h>
+#include <netdb.h>
#include "connman.h"
+/*
+ * Just to avoid build failure due to missing STATEDIR
+ */
+#if defined TIZEN_EXT
+#ifdef STATEDIR
+#undef STATEDIR
+#endif
+#define STATEDIR "/etc"
+#endif
+
+#define RESOLV_CONF_STATEDIR STATEDIR"/resolv.conf"
+#define RESOLV_CONF_ETC "/etc/resolv.conf"
+
#define RESOLVER_FLAG_PUBLIC (1 << 0)
+/*
+ * Threshold for RDNSS lifetime. Will be used to trigger RS
+ * before RDNSS entries actually expire
+ */
+#define RESOLVER_LIFETIME_REFRESH_THRESHOLD 0.8
+
struct entry_data {
- struct connman_resolver *resolver;
- char *interface;
+ int index;
char *domain;
char *server;
+ int family;
unsigned int flags;
+ unsigned int lifetime;
+ guint timeout;
};
static GSList *entry_list = NULL;
-static GSList *resolver_list = NULL;
+static bool dnsproxy_enabled = false;
-static void remove_entries(GSList *entries)
+struct resolvfile_entry {
+ int index;
+ char *domain;
+ char *server;
+};
+
+static GList *resolvfile_list = NULL;
+
+static void resolvfile_remove_entries(GList *entries)
{
- GSList *list;
+ GList *list;
for (list = entries; list; list = list->next) {
- struct entry_data *entry = list->data;
- struct connman_resolver *resolver = entry->resolver;
-
- entry_list = g_slist_remove(entry_list, entry);
+ struct resolvfile_entry *entry = list->data;
- if (resolver && resolver->remove)
- resolver->remove(entry->interface, entry->domain,
- entry->server);
+ resolvfile_list = g_list_remove(resolvfile_list, entry);
g_free(entry->server);
g_free(entry->domain);
- g_free(entry->interface);
g_free(entry);
}
- g_slist_free(entries);
+ g_list_free(entries);
}
-static gint compare_priority(gconstpointer a, gconstpointer b)
+static int resolvfile_export(void)
{
- const struct connman_resolver *resolver1 = a;
- const struct connman_resolver *resolver2 = b;
+ GList *list;
+ GString *content;
+ int fd, err;
+ unsigned int count;
+ mode_t old_umask;
+
+ content = g_string_new("# Generated by Connection Manager\n");
+
+ /*
+ * 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_first(resolvfile_list);
+ list && (count < MAXDNSRCH);
+ list = g_list_next(list)) {
+ struct resolvfile_entry *entry = list->data;
+
+ if (!entry->domain)
+ continue;
- return resolver2->priority - resolver1->priority;
+ 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_first(resolvfile_list);
+ list && (count < MAXNS);
+ list = g_list_next(list)) {
+ struct resolvfile_entry *entry = list->data;
+
+ if (!entry->server)
+ continue;
+
+ g_string_append_printf(content, "nameserver %s\n",
+ entry->server);
+ count++;
+ }
+
+ old_umask = umask(022);
+
+ fd = open(RESOLV_CONF_STATEDIR, O_RDWR | O_CREAT | O_CLOEXEC,
+ S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+ if (fd < 0) {
+ 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) {
+ err = -errno;
+ goto failed;
+ }
+
+ err = 0;
+
+ if (write(fd, content->str, content->len) < 0)
+ err = -errno;
+
+failed:
+ close(fd);
+
+done:
+ g_string_free(content, TRUE);
+ umask(old_umask);
+
+ return err;
}
-/**
- * connman_resolver_register:
- * @resolver: resolver module
- *
- * Register a new resolver module
- *
- * Returns: %0 on success
- */
-int connman_resolver_register(struct connman_resolver *resolver)
+int __connman_resolvfile_append(int index, const char *domain,
+ const char *server)
{
- GSList *list;
+ struct resolvfile_entry *entry;
- DBG("resolver %p name %s", resolver, resolver->name);
+ DBG("index %d server %s", index, server);
- resolver_list = g_slist_insert_sorted(resolver_list, resolver,
- compare_priority);
+ if (index < 0)
+ return -ENOENT;
- if (resolver->append == NULL)
- return 0;
+ entry = g_try_new0(struct resolvfile_entry, 1);
+ if (!entry)
+ return -ENOMEM;
- for (list = entry_list; list; list = list->next) {
- struct entry_data *entry = list->data;
+ entry->index = index;
+ entry->domain = g_strdup(domain);
+ entry->server = g_strdup(server);
+
+ resolvfile_list = g_list_append(resolvfile_list, entry);
+
+ return resolvfile_export();
+}
+
+int __connman_resolvfile_remove(int index, const char *domain,
+ const char *server)
+{
+ GList *list, *matches = NULL;
+
+ DBG("index %d server %s", index, server);
+
+ for (list = resolvfile_list; list; list = g_list_next(list)) {
+ struct resolvfile_entry *entry = list->data;
+
+ if (index >= 0 && entry->index != index)
+ continue;
+
+ if (domain && g_strcmp0(entry->domain, domain) != 0)
+ continue;
- if (entry->resolver)
+ if (g_strcmp0(entry->server, server) != 0)
continue;
- if (resolver->append(entry->interface, entry->domain,
- entry->server) == 0)
- entry->resolver = resolver;
+ matches = g_list_append(matches, entry);
}
- return 0;
+ resolvfile_remove_entries(matches);
+
+ return resolvfile_export();
}
-/**
- * connman_resolver_unregister:
- * @resolver: resolver module
- *
- * Remove a previously registered resolver module
- */
-void connman_resolver_unregister(struct connman_resolver *resolver)
+void __connman_resolver_append_fallback_nameservers(void)
{
- GSList *list, *matches = NULL;
+ GSList *list;
- DBG("resolver %p name %s", resolver, resolver->name);
+ for (list = entry_list; list; list = list->next) {
+ struct entry_data *entry = list->data;
- resolver_list = g_slist_remove(resolver_list, resolver);
+ if (entry->index >= 0 && entry->server)
+ return;
+ }
for (list = entry_list; list; list = list->next) {
struct entry_data *entry = list->data;
- if (entry->resolver != resolver)
+ if (entry->index != -1 || !entry->server)
continue;
- matches = g_slist_append(matches, entry);
+ DBG("index %d server %s", entry->index, entry->server);
+
+ if (dnsproxy_enabled) {
+ __connman_dnsproxy_append(entry->index, entry->domain,
+ entry->server);
+ } else {
+ __connman_resolvfile_append(entry->index,
+ entry->domain, entry->server);
+ }
}
+}
- remove_entries(matches);
+static void remove_fallback_nameservers(void)
+{
+ GSList *list;
+
+ for (list = entry_list; list; list = list->next) {
+ struct entry_data *entry = list->data;
+
+ if (entry->index >= 0 || !entry->server)
+ continue;
+
+ DBG("index %d server %s", entry->index, entry->server);
+
+ if (dnsproxy_enabled) {
+ __connman_dnsproxy_remove(entry->index, entry->domain,
+ entry->server);
+ } else {
+ __connman_resolvfile_remove(entry->index,
+ entry->domain, entry->server);
+ }
+ }
}
-static int append_resolver(const char *interface, const char *domain,
- const char *server, unsigned int flags)
+static void remove_entries(GSList *entries)
{
- struct entry_data *entry;
GSList *list;
- DBG("interface %s domain %s server %s flags %d",
- interface, domain, server, flags);
+ for (list = entries; list; list = list->next) {
+ struct entry_data *entry = list->data;
+
+ entry_list = g_slist_remove(entry_list, entry);
+
+ if (dnsproxy_enabled) {
+ __connman_dnsproxy_remove(entry->index, entry->domain,
+ entry->server);
+ } else {
+ __connman_resolvfile_remove(entry->index, entry->domain,
+ entry->server);
+ }
+
+ if (entry->timeout)
+ g_source_remove(entry->timeout);
+ g_free(entry->server);
+ g_free(entry->domain);
+ g_free(entry);
+ }
+
+ g_slist_free(entries);
+
+ __connman_resolver_append_fallback_nameservers();
+}
+
+static gboolean resolver_expire_cb(gpointer user_data)
+{
+ struct entry_data *entry = user_data;
+ GSList *list;
+
+ DBG("index %d domain %s server %s",
+ entry->index, entry->domain, entry->server);
+
+ list = g_slist_prepend(NULL, entry);
+
+ if (entry->index >= 0) {
+ struct connman_service *service;
+ service = __connman_service_lookup_from_index(entry->index);
+ if (service)
+#if defined TIZEN_EXT
+ __connman_service_nameserver_remove(service,
+ entry->server, true,
+ CONNMAN_IPCONFIG_TYPE_ALL);
+#else
+ __connman_service_nameserver_remove(service,
+ entry->server, true);
+#endif
+ }
+
+ remove_entries(list);
+
+ return FALSE;
+}
+
+static gboolean resolver_refresh_cb(gpointer user_data)
+{
+ struct entry_data *entry = user_data;
+ unsigned int interval;
+ struct connman_service *service = NULL;
+
+ /* Round up what we have left from lifetime */
+ interval = entry->lifetime *
+ (1 - RESOLVER_LIFETIME_REFRESH_THRESHOLD) + 1.0;
+
+ DBG("RDNSS start index %d domain %s "
+ "server %s remaining lifetime %d",
+ entry->index, entry->domain,
+ entry->server, interval);
+
+ entry->timeout = g_timeout_add_seconds(interval,
+ resolver_expire_cb, entry);
+
+ if (entry->index >= 0) {
+ service = __connman_service_lookup_from_index(entry->index);
+ if (service) {
+ /*
+ * Send Router Solicitation to refresh RDNSS entries
+ * before their lifetime expires
+ */
+ __connman_network_refresh_rs_ipv6(
+ __connman_service_get_network(service),
+ entry->index);
+ }
+ }
+ return FALSE;
+}
+
+static int append_resolver(int index, const char *domain,
+ const char *server, unsigned int lifetime,
+ unsigned int flags)
+{
+ struct entry_data *entry;
+ unsigned int interval;
+
+ DBG("index %d domain %s server %s lifetime %d flags %d",
+ index, domain, server, lifetime, flags);
+
+ if (!server && !domain)
+ return -EINVAL;
- if (server == NULL)
+#ifdef TIZEN_EXT
+ if (g_strcmp0(server, "0.0.0.0") == 0)
return -EINVAL;
+#endif
entry = g_try_new0(struct entry_data, 1);
- if (entry == NULL)
+ if (!entry)
return -ENOMEM;
- entry->interface = g_strdup(interface);
+ entry->index = index;
entry->domain = g_strdup(domain);
entry->server = g_strdup(server);
entry->flags = flags;
+ entry->lifetime = lifetime;
- entry_list = g_slist_append(entry_list, entry);
+ if (server)
+ entry->family = connman_inet_check_ipaddress(server);
- for (list = resolver_list; list; list = list->next) {
- struct connman_resolver *resolver = list->data;
+ if (lifetime) {
+ interval = lifetime * RESOLVER_LIFETIME_REFRESH_THRESHOLD;
- if (resolver->append == NULL)
- continue;
+ DBG("RDNSS start index %d domain %s "
+ "server %s lifetime threshold %d",
+ index, domain, server, interval);
- if (resolver->append(interface, domain, server) == 0) {
- entry->resolver = resolver;
- break;
- }
+ entry->timeout = g_timeout_add_seconds(interval,
+ resolver_refresh_cb, entry);
+ }
+
+ if (entry->index >= 0 && entry->server)
+ remove_fallback_nameservers();
+
+ entry_list = g_slist_append(entry_list, entry);
+
+ if (dnsproxy_enabled)
+ __connman_dnsproxy_append(entry->index, domain, server);
+ 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)
+#if defined TIZEN_EXT
+ __connman_service_nameserver_append(service,
+ server, true,
+ CONNMAN_IPCONFIG_TYPE_ALL);
+#else
+ __connman_service_nameserver_append(service,
+ server, true);
+#endif
}
return 0;
/**
* connman_resolver_append:
- * @interface: network interface
+ * @index: network interface index
* @domain: domain limitation
* @server: server address
*
* Append resolver server address to current list
*/
-int connman_resolver_append(const char *interface, const char *domain,
- const char *server)
+int connman_resolver_append(int index, const char *domain,
+ const char *server)
{
- DBG("interface %s domain %s server %s", interface, domain, server);
+ GSList *list;
+
+ DBG("index %d domain %s server %s", index, domain, server);
- return append_resolver(interface, domain, server, 0);
+ if (!server && !domain)
+ return -EINVAL;
+
+ for (list = entry_list; list; list = list->next) {
+ struct entry_data *entry = list->data;
+
+ if (entry->timeout > 0)
+ continue;
+
+ if (entry->index == index &&
+ g_strcmp0(entry->domain, domain) == 0 &&
+ g_strcmp0(entry->server, server) == 0) {
+ if (dnsproxy_enabled)
+ __connman_dnsproxy_append(entry->index, domain,
+ server);
+
+ return -EEXIST;
+ }
+ }
+
+ return append_resolver(index, domain, server, 0, 0);
}
/**
- * connman_resolver_remove:
- * @interface: network interface
+ * connman_resolver_append_lifetime:
+ * @index: network interface index
* @domain: domain limitation
* @server: server address
+ * @timeout: server lifetime in seconds
*
- * Remover resolver server address from current list
+ * Append resolver server address to current list
*/
-int connman_resolver_remove(const char *interface, const char *domain,
- const char *server)
+int connman_resolver_append_lifetime(int index, const char *domain,
+ const char *server, unsigned int lifetime)
{
- GSList *list, *matches = NULL;
+ GSList *list;
+ unsigned int interval;
- DBG("interface %s domain %s server %s", interface, domain, server);
+ DBG("index %d domain %s server %s lifetime %d",
+ index, domain, server, lifetime);
- if (server == NULL)
+ if (!server && !domain)
return -EINVAL;
for (list = entry_list; list; list = list->next) {
struct entry_data *entry = list->data;
- if (interface != NULL &&
- g_strcmp0(entry->interface, interface) != 0)
+ if (entry->timeout == 0 ||
+ entry->index != index ||
+ g_strcmp0(entry->domain, domain) != 0 ||
+ g_strcmp0(entry->server, server) != 0)
continue;
- if (domain != NULL && g_strcmp0(entry->domain, domain) != 0)
- continue;
+ g_source_remove(entry->timeout);
- if (g_strcmp0(entry->server, server) != 0)
- continue;
+ if (lifetime == 0) {
+ resolver_expire_cb(entry);
+ return 0;
+ }
- matches = g_slist_append(matches, entry);
- }
+ interval = lifetime * RESOLVER_LIFETIME_REFRESH_THRESHOLD;
- if (matches == NULL)
- return -ENOENT;
+ DBG("RDNSS start index %d domain %s "
+ "server %s lifetime threshold %d",
+ index, domain, server, interval);
- remove_entries(matches);
+ entry->timeout = g_timeout_add_seconds(interval,
+ resolver_refresh_cb, entry);
+ return 0;
+ }
- return 0;
+ return append_resolver(index, domain, server, lifetime, 0);
}
/**
- * connman_resolver_remove_all:
- * @interface: network interface
+ * connman_resolver_remove:
+ * @index: network interface index
+ * @domain: domain limitation
+ * @server: server address
*
- * Remove all resolver server address for the specified interface
+ * Remover resolver server address from current list
*/
-int connman_resolver_remove_all(const char *interface)
+int connman_resolver_remove(int index, const char *domain, const char *server)
{
GSList *list, *matches = NULL;
- DBG("interface %s", interface);
-
- if (interface == NULL)
- return -EINVAL;
+ DBG("index %d domain %s server %s", index, domain, server);
for (list = entry_list; list; list = list->next) {
struct entry_data *entry = list->data;
- if (g_strcmp0(entry->interface, interface) != 0)
+ if (entry->index != index)
+ continue;
+
+ if (g_strcmp0(entry->domain, domain) != 0)
continue;
- matches = g_slist_append(matches, entry);
+ if (g_strcmp0(entry->server, server) != 0)
+ continue;
+
+ matches = g_slist_prepend(matches, entry);
+ break;
}
- if (matches == NULL)
+ if (!matches)
return -ENOENT;
remove_entries(matches);
}
/**
- * connman_resolver_append_public_server:
- * @server: server address
- *
- * Append public resolver server address to current list
- */
-int connman_resolver_append_public_server(const char *server)
-{
- DBG("server %s", server);
-
- return append_resolver(NULL, NULL, server, RESOLVER_FLAG_PUBLIC);
-}
-
-/**
- * connman_resolver_remove_public_server:
- * @server: server address
+ * connman_resolver_remove_all:
+ * @index: network interface index
*
- * Remove public resolver server address to current list
+ * Remove all resolver server address for the specified interface index
*/
-int connman_resolver_remove_public_server(const char *server)
+int connman_resolver_remove_all(int index)
{
- DBG("server %s", server);
+ GSList *list, *matches = NULL;
- return connman_resolver_remove(NULL, NULL, server);
-}
+ DBG("index %d", index);
-/**
- * connman_resolver_flush:
- *
- * Flush pending resolver requests
- */
-void connman_resolver_flush(void)
-{
- GSList *list;
+ if (index < 0)
+ return -EINVAL;
- for (list = resolver_list; list; list = list->next) {
- struct connman_resolver *resolver = list->data;
+ for (list = entry_list; list; list = list->next) {
+ struct entry_data *entry = list->data;
- if (resolver->flush == NULL)
+ if (entry->index != index)
continue;
- resolver->flush();
+ matches = g_slist_prepend(matches, entry);
}
- return;
-}
-
-static int selftest_append(const char *interface, const char *domain,
- const char *server)
-{
- DBG("server %s", server);
-
- return 0;
-}
+ if (!matches)
+ return -ENOENT;
-static int selftest_remove(const char *interface, const char *domain,
- const char *server)
-{
- DBG("server %s", server);
+ remove_entries(matches);
return 0;
}
-static struct connman_resolver selftest_resolver = {
- .name = "selftest",
- .priority = CONNMAN_RESOLVER_PRIORITY_HIGH + 42,
- .append = selftest_append,
- .remove = selftest_remove,
-};
-
-int __connman_resolver_selftest(void)
+int __connman_resolver_redo_servers(int index)
{
- connman_resolver_append("wlan0", "lwn.net", "192.168.0.1");
+ GSList *list;
- connman_resolver_register(&selftest_resolver);
+ if (!dnsproxy_enabled)
+ return 0;
- connman_resolver_append("eth0", "connman.net", "192.168.42.1");
- connman_resolver_append("wlan0", "lwn.net", "192.168.0.2");
+ DBG("index %d", index);
- connman_resolver_append_public_server("8.8.8.8");
+ if (index < 0)
+ return -EINVAL;
- connman_resolver_remove_public_server("8.8.8.8");
+ for (list = entry_list; list; list = list->next) {
+ struct entry_data *entry = list->data;
- connman_resolver_remove_all("wlan0");
+ if (entry->timeout == 0 || entry->index != index)
+ continue;
- connman_resolver_unregister(&selftest_resolver);
+ /*
+ * This function must only check IPv6 server addresses so
+ * do not remove IPv4 name servers unnecessarily.
+ */
+ if (entry->family != AF_INET6)
+ continue;
- return 0;
-}
+ /*
+ * We remove the server, and then re-create so that it will
+ * use proper source addresses when sending DNS queries.
+ */
+ __connman_dnsproxy_remove(entry->index, entry->domain,
+ entry->server);
-struct resolvfile_entry {
- char *interface;
- char *domain;
- char *server;
-};
+ __connman_dnsproxy_append(entry->index, entry->domain,
+ entry->server);
+ }
-static GList *resolvfile_list = NULL;
+ /*
+ * 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.
+ */
-static void resolvfile_remove_entries(GList *entries)
-{
- GList *list;
+ for (list = entry_list; list; list = list->next) {
+ struct entry_data *entry = list->data;
- for (list = entries; list; list = list->next) {
- struct resolvfile_entry *entry = list->data;
+ if (entry->index != index)
+ continue;
- resolvfile_list = g_list_remove(resolvfile_list, entry);
+ if (entry->server)
+ continue;
- g_free(entry->server);
- g_free(entry->domain);
- g_free(entry->interface);
- g_free(entry);
+ __connman_dnsproxy_append(entry->index, entry->domain,
+ NULL);
}
- g_list_free(entries);
+ return 0;
}
-static int resolvfile_export(void)
+static void free_entry(gpointer data)
{
- GList *list;
- GString *content;
- int fd, err;
- unsigned int count;
- mode_t old_umask;
-
- 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.
- */
- for (count = 0, list = g_list_last(resolvfile_list);
- list && (count < MAXNS);
- list = g_list_previous(list)) {
- struct resolvfile_entry *entry = list->data;
- g_string_append_printf(content, "nameserver %s\n",
- entry->server);
- count++;
- }
-
- old_umask = umask(022);
-
- fd = open("/etc/resolv.conf", O_RDWR | O_CREAT,
- S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
- if (fd < 0) {
- err = -errno;
- goto done;
- }
-
- if (ftruncate(fd, 0) < 0) {
- err = -errno;
- goto failed;
- }
-
- err = 0;
-
- if (write(fd, content->str, content->len) < 0)
- err = -errno;
-
-failed:
- close(fd);
-
-done:
- g_string_free(content, TRUE);
- umask(old_umask);
-
- return err;
+ struct entry_data *entry = data;
+ g_free(entry->domain);
+ g_free(entry->server);
+ g_free(entry);
}
-static int resolvfile_append(const char *interface, const char *domain,
- const char *server)
+static void free_resolvfile(gpointer data)
{
- struct resolvfile_entry *entry;
-
- DBG("interface %s server %s", interface, server);
-
- if (interface == NULL)
- return -ENOENT;
-
- entry = g_try_new0(struct resolvfile_entry, 1);
- if (entry == NULL)
- return -ENOMEM;
-
- entry->interface = g_strdup(interface);
- entry->domain = g_strdup(domain);
- entry->server = g_strdup(server);
-
- resolvfile_list = g_list_append(resolvfile_list, entry);
-
- return resolvfile_export();
+ struct resolvfile_entry *entry = data;
+ g_free(entry->domain);
+ g_free(entry->server);
+ g_free(entry);
}
-static int resolvfile_remove(const char *interface, const char *domain,
- const char *server)
+int __connman_resolver_set_mdns(int index, bool enabled)
{
- GList *list, *matches = NULL;
-
- DBG("interface %s server %s", interface, server);
-
- for (list = resolvfile_list; list; list = g_list_next(list)) {
- struct resolvfile_entry *entry = list->data;
+ if (!dnsproxy_enabled)
+ return -ENOTSUP;
- if (interface != NULL &&
- g_strcmp0(entry->interface, interface) != 0)
- continue;
+ return __connman_dnsproxy_set_mdns(index, enabled);
+}
- if (domain != NULL && g_strcmp0(entry->domain, domain) != 0)
- continue;
+int __connman_resolver_init(gboolean dnsproxy)
+{
+ int i;
+ char **ns;
- if (g_strcmp0(entry->server, server) != 0)
- continue;
+ DBG("dnsproxy %d", dnsproxy);
- matches = g_list_append(matches, entry);
+ /* 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);
- resolvfile_remove_entries(matches);
+ if (!dnsproxy)
+ return 0;
- return resolvfile_export();
-}
+ if (__connman_dnsproxy_init() < 0) {
+ /* Fall back to resolv.conf */
+ return 0;
+ }
-static struct connman_resolver resolvfile_resolver = {
- .name = "resolvfile",
- .priority = CONNMAN_RESOLVER_PRIORITY_LOW,
- .append = resolvfile_append,
- .remove = resolvfile_remove,
-};
+ dnsproxy_enabled = true;
-int __connman_resolver_init(void)
-{
- DBG("");
+ ns = connman_setting_get_string_list("FallbackNameservers");
+ for (i = 0; ns && ns[i]; i += 1) {
+ DBG("server %s", ns[i]);
+ append_resolver(-1, NULL, ns[i], 0, RESOLVER_FLAG_PUBLIC);
+ }
- return connman_resolver_register(&resolvfile_resolver);
+ return 0;
}
void __connman_resolver_cleanup(void)
{
DBG("");
- connman_resolver_unregister(&resolvfile_resolver);
+ if (dnsproxy_enabled)
+ __connman_dnsproxy_cleanup();
+ else {
+ GList *list;
+ GSList *slist;
+
+ for (list = resolvfile_list; list; list = g_list_next(list))
+ free_resolvfile(list->data);
+ g_list_free(resolvfile_list);
+ resolvfile_list = NULL;
+
+ for (slist = entry_list; slist; slist = g_slist_next(slist))
+ free_entry(slist->data);
+ g_slist_free(entry_list);
+ entry_list = NULL;
+ }
}