chiark / gitweb /
resolved: unify logic how we flush out DNS servers we learnt
authorLennart Poettering <lennart@poettering.net>
Tue, 12 Aug 2014 17:32:55 +0000 (19:32 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 12 Aug 2014 17:32:55 +0000 (19:32 +0200)
src/resolve/resolved-conf.c
src/resolve/resolved-dns-server.c
src/resolve/resolved-dns-server.h
src/resolve/resolved-manager.c
src/resolve/resolved-manager.h

index ae3773f..63e87f8 100644 (file)
@@ -81,7 +81,6 @@ int config_parse_dnsv(
                 void *userdata) {
 
         Manager *m = userdata;
                 void *userdata) {
 
         Manager *m = userdata;
-        DnsServer **l;
         int r;
 
         assert(filename);
         int r;
 
         assert(filename);
@@ -89,19 +88,10 @@ int config_parse_dnsv(
         assert(rvalue);
         assert(m);
 
         assert(rvalue);
         assert(m);
 
-        if (ltype == DNS_SERVER_FALLBACK)
-                l = &m->fallback_dns_servers;
-        else
-                l = &m->dns_servers;
-
-        if (isempty(rvalue)) {
-
+        if (isempty(rvalue))
                 /* Empty assignment means clear the list */
                 /* Empty assignment means clear the list */
-                while (*l)
-                        dns_server_free(*l);
-
-        } else {
-
+                manager_flush_dns_servers(m, ltype);
+        else {
                 /* Otherwise add to the list */
                 r = manager_parse_dns_server(m, ltype, rvalue);
                 if (r < 0) {
                 /* Otherwise add to the list */
                 r = manager_parse_dns_server(m, ltype, rvalue);
                 if (r < 0) {
index 043f6b6..c99768b 100644 (file)
@@ -64,9 +64,9 @@ int dns_server_new(
          * we used so far was a fallback one? Then let's try to pick
          * the new one */
         if (type != DNS_SERVER_FALLBACK &&
          * we used so far was a fallback one? Then let's try to pick
          * the new one */
         if (type != DNS_SERVER_FALLBACK &&
-            s->manager->current_dns_server &&
-            s->manager->current_dns_server->type == DNS_SERVER_FALLBACK)
-                manager_set_dns_server(s->manager, NULL);
+            m->current_dns_server &&
+            m->current_dns_server->type == DNS_SERVER_FALLBACK)
+                manager_set_dns_server(m, NULL);
 
         if (ret)
                 *ret = s;
 
         if (ret)
                 *ret = s;
@@ -87,14 +87,14 @@ DnsServer* dns_server_free(DnsServer *s)  {
                         LIST_REMOVE(servers, s->manager->fallback_dns_servers, s);
                 else
                         assert_not_reached("Unknown server type");
                         LIST_REMOVE(servers, s->manager->fallback_dns_servers, s);
                 else
                         assert_not_reached("Unknown server type");
+
+                if (s->manager->current_dns_server == s)
+                        manager_set_dns_server(s->manager, NULL);
         }
 
         if (s->link && s->link->current_dns_server == s)
                 link_set_dns_server(s->link, NULL);
 
         }
 
         if (s->link && s->link->current_dns_server == s)
                 link_set_dns_server(s->link, NULL);
 
-        if (s->manager && s->manager->current_dns_server == s)
-                manager_set_dns_server(s->manager, NULL);
-
         free(s);
 
         return NULL;
         free(s);
 
         return NULL;
index 5178a6b..f2361a8 100644 (file)
 typedef struct DnsServer DnsServer;
 typedef enum DnsServerSource DnsServerSource;
 
 typedef struct DnsServer DnsServer;
 typedef enum DnsServerSource DnsServerSource;
 
-#include "resolved-manager.h"
-#include "resolved-link.h"
-
 typedef enum DnsServerType {
         DNS_SERVER_SYSTEM,
         DNS_SERVER_FALLBACK,
         DNS_SERVER_LINK,
 } DnsServerType;
 
 typedef enum DnsServerType {
         DNS_SERVER_SYSTEM,
         DNS_SERVER_FALLBACK,
         DNS_SERVER_LINK,
 } DnsServerType;
 
+#include "resolved-manager.h"
+#include "resolved-link.h"
+
 struct DnsServer {
         Manager *manager;
 
 struct DnsServer {
         Manager *manager;
 
index 6bb0894..a2de2ed 100644 (file)
@@ -536,10 +536,8 @@ Manager *manager_free(Manager *m) {
 
         dns_scope_free(m->unicast_scope);
 
 
         dns_scope_free(m->unicast_scope);
 
-        while (m->dns_servers)
-                dns_server_free(m->dns_servers);
-        while (m->fallback_dns_servers)
-                dns_server_free(m->fallback_dns_servers);
+        manager_flush_dns_servers(m, DNS_SERVER_SYSTEM);
+        manager_flush_dns_servers(m, DNS_SERVER_FALLBACK);
 
         hashmap_free(m->links);
         hashmap_free(m->dns_transactions);
 
         hashmap_free(m->links);
         hashmap_free(m->dns_transactions);
@@ -1771,6 +1769,18 @@ void manager_verify_all(Manager *m) {
                 dns_zone_verify_all(&s->zone);
 }
 
                 dns_zone_verify_all(&s->zone);
 }
 
+void manager_flush_dns_servers(Manager *m, DnsServerType t) {
+        assert(m);
+
+        if (t == DNS_SERVER_SYSTEM)
+                while (m->dns_servers)
+                        dns_server_free(m->dns_servers);
+
+        if (t == DNS_SERVER_FALLBACK)
+                while (m->fallback_dns_servers)
+                        dns_server_free(m->fallback_dns_servers);
+}
+
 static const char* const support_table[_SUPPORT_MAX] = {
         [SUPPORT_NO] = "no",
         [SUPPORT_YES] = "yes",
 static const char* const support_table[_SUPPORT_MAX] = {
         [SUPPORT_NO] = "no",
         [SUPPORT_YES] = "yes",
index f8cb91c..78cbfc0 100644 (file)
@@ -151,6 +151,8 @@ DnsScope* manager_find_scope(Manager *m, DnsPacket *p);
 
 void manager_verify_all(Manager *m);
 
 
 void manager_verify_all(Manager *m);
 
+void manager_flush_dns_servers(Manager *m, DnsServerType t);
+
 DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free);
 
 #define EXTRA_CMSG_SPACE 1024
 DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free);
 
 #define EXTRA_CMSG_SPACE 1024