summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2009-12-14 04:13:14 +0100
committerMarcel Holtmann <marcel@holtmann.org>2009-12-14 04:13:14 +0100
commita3386210b543e697cda5180e32d1f25cec6f18d8 (patch)
tree31f958dc6a9b7bc50b4f888ed3d008517bbb7658
parent1fab2db6662c9f7097cbc2486a84f36482e83050 (diff)
downloadconnman-a3386210b543e697cda5180e32d1f25cec6f18d8.tar.gz
connman-a3386210b543e697cda5180e32d1f25cec6f18d8.tar.bz2
connman-a3386210b543e697cda5180e32d1f25cec6f18d8.zip
Add support for using public DNS servers
-rw-r--r--include/resolver.h13
-rw-r--r--src/resolver.c80
2 files changed, 88 insertions, 5 deletions
diff --git a/include/resolver.h b/include/resolver.h
index 18c3ab89..1ca2b1d1 100644
--- a/include/resolver.h
+++ b/include/resolver.h
@@ -32,6 +32,15 @@ extern "C" {
* @short_description: Functions for registering resolver modules
*/
+int connman_resolver_append(const char *interface, const char *domain,
+ const char *server);
+int connman_resolver_remove(const char *interface, const char *domain,
+ const char *server);
+int connman_resolver_remove_all(const char *interface);
+
+int connman_resolver_append_public_server(const char *server);
+int connman_resolver_remove_public_server(const char *server);
+
#define CONNMAN_RESOLVER_PRIORITY_LOW -100
#define CONNMAN_RESOLVER_PRIORITY_DEFAULT 0
#define CONNMAN_RESOLVER_PRIORITY_HIGH 100
@@ -48,10 +57,6 @@ struct connman_resolver {
int connman_resolver_register(struct connman_resolver *resolver);
void connman_resolver_unregister(struct connman_resolver *resolver);
-int connman_resolver_append(const char *interface, const char *domain,
- const char *server);
-int connman_resolver_remove_all(const char *interface);
-
#ifdef __cplusplus
}
#endif
diff --git a/src/resolver.c b/src/resolver.c
index 3cf37329..dec13573 100644
--- a/src/resolver.c
+++ b/src/resolver.c
@@ -178,6 +178,48 @@ int connman_resolver_append(const char *interface, const char *domain,
}
/**
+ * connman_resolver_remove:
+ * @interface: network interface
+ * @domain: domain limitation
+ * @server: server address
+ *
+ * Remover resolver server address from current list
+ */
+int connman_resolver_remove(const char *interface, const char *domain,
+ const char *server)
+{
+ GSList *list, *matches = NULL;
+
+ DBG("interface %s domain %s server %s", interface, domain, server);
+
+ if (server == NULL)
+ 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)
+ continue;
+
+ if (domain != NULL && g_strcmp0(entry->domain, domain) != 0)
+ continue;
+
+ if (g_strcmp0(entry->server, server) != 0)
+ continue;
+
+ matches = g_slist_append(matches, entry);
+ }
+
+ if (matches == NULL)
+ return -ENOENT;
+
+ remove_entries(matches);
+
+ return 0;
+}
+
+/**
* connman_resolver_remove_all:
* @interface: network interface
*
@@ -189,20 +231,52 @@ int connman_resolver_remove_all(const char *interface)
DBG("interface %s", interface);
+ if (interface == NULL)
+ return -EINVAL;
+
for (list = entry_list; list; list = list->next) {
struct entry_data *entry = list->data;
- if (g_str_equal(entry->interface, interface) == FALSE)
+ if (g_strcmp0(entry->interface, interface) != 0)
continue;
matches = g_slist_append(matches, entry);
}
+ if (matches == NULL)
+ return -ENOENT;
+
remove_entries(matches);
return 0;
}
+/**
+ * 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 connman_resolver_append(NULL, NULL, server);
+}
+
+/**
+ * connman_resolver_remove_public_server:
+ * @server: server address
+ *
+ * Remove public resolver server address to current list
+ */
+int connman_resolver_remove_public_server(const char *server)
+{
+ DBG("server %s", server);
+
+ return connman_resolver_remove(NULL, NULL, server);
+}
+
static int selftest_append(const char *interface, const char *domain,
const char *server)
{
@@ -235,6 +309,10 @@ int __connman_resolver_selftest(void)
connman_resolver_append("eth0", "moblin.org", "192.168.42.1");
connman_resolver_append("wlan0", "lwn.net", "192.168.0.2");
+ connman_resolver_append_public_server("8.8.8.8");
+
+ connman_resolver_remove_public_server("8.8.8.8");
+
connman_resolver_remove_all("wlan0");
connman_resolver_unregister(&selftest_resolver);