Merge "Remove libbpf code from connMan" into tizen
[platform/upstream/connman.git] / src / resolver.c
old mode 100644 (file)
new mode 100755 (executable)
index 10121aa..8bfea3c
 
 #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"
 
@@ -83,9 +93,22 @@ static void resolvfile_remove_entries(GList *entries)
        g_list_free(entries);
 }
 
-static int resolvfile_export(void)
+static bool already_exported(GList *export_list, const char *str)
 {
        GList *list;
+
+       for (list = export_list; list; list = g_list_next(list)) {
+               const char *str0 = list->data;
+               if (g_strcmp0(str0, str) == 0)
+                       return true;
+       }
+
+       return false;
+}
+
+static int resolvfile_export(void)
+{
+       GList *list, *export_list;
        GString *content;
        int fd, err;
        unsigned int count;
@@ -99,6 +122,7 @@ static int resolvfile_export(void)
         * MAXDNSRCH/MAXNS entries are used.
         */
 
+       export_list = NULL;
        for (count = 0, list = g_list_first(resolvfile_list);
                                                list && (count < MAXDNSRCH);
                                                list = g_list_next(list)) {
@@ -107,16 +131,25 @@ static int resolvfile_export(void)
                if (!entry->domain)
                        continue;
 
+               if (already_exported(export_list, entry->domain))
+                       continue;
+
                if (count == 0)
                        g_string_append_printf(content, "search ");
 
                g_string_append_printf(content, "%s ", entry->domain);
+
+               export_list = g_list_append(export_list, entry->domain);
+
                count++;
        }
+       g_list_free(export_list);
+
 
        if (count)
                g_string_append_printf(content, "\n");
 
+       export_list = NULL;
        for (count = 0, list = g_list_first(resolvfile_list);
                                                list && (count < MAXNS);
                                                list = g_list_next(list)) {
@@ -125,10 +158,16 @@ static int resolvfile_export(void)
                if (!entry->server)
                        continue;
 
-               g_string_append_printf(content, "nameserver %s\n",
-                                                               entry->server);
+               if (already_exported(export_list, entry->server))
+                       continue;
+
+               g_string_append_printf(content, "nameserver %s\n", entry->server);
+
+               export_list = g_list_append(export_list, entry->server);
+
                count++;
        }
+       g_list_free(export_list);
 
        old_umask = umask(022);
 
@@ -172,7 +211,7 @@ int __connman_resolvfile_append(int index, const char *domain,
 {
        struct resolvfile_entry *entry;
 
-       DBG("index %d server %s", index, server);
+       DBG("index %d domain %s server %s", index, domain, server);
 
        if (index < 0)
                return -ENOENT;
@@ -195,7 +234,7 @@ int __connman_resolvfile_remove(int index, const char *domain,
 {
        GList *list, *matches = NULL;
 
-       DBG("index %d server %s", index, server);
+       DBG("index %d domain %s server %s", index, domain, server);
 
        for (list = resolvfile_list; list; list = g_list_next(list)) {
                struct resolvfile_entry *entry = list->data;
@@ -311,8 +350,14 @@ static gboolean resolver_expire_cb(gpointer user_data)
                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);
@@ -366,6 +411,11 @@ static int append_resolver(int index, const char *domain,
        if (!server && !domain)
                return -EINVAL;
 
+#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)
                return -ENOMEM;
@@ -408,8 +458,14 @@ static int append_resolver(int index, const char *domain,
                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;