summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-11-24 21:27:29 +0100
committerLennart Poettering <lennart@poettering.net>2015-11-25 21:58:38 +0100
commit4b95f1798f22c1bb75295f448188560cb6ec9ece (patch)
treea558209fdb4450717d3d28c4987140ed4f5b33b8
parenta51c10485af349eb15faa4d1a63b9818bcf3e589 (diff)
resolved: unify DnsServer handling code between Link and Manager
This copies concepts we introduced for the DnsSearchDomain stuff, and reworks the operations on lists of dns servers to be reusable and generic for use both with the Link and the Manager object.
-rw-r--r--src/resolve/resolved-conf.c4
-rw-r--r--src/resolve/resolved-dns-server.c82
-rw-r--r--src/resolve/resolved-dns-server.h11
-rw-r--r--src/resolve/resolved-link.c51
-rw-r--r--src/resolve/resolved-link.h7
-rw-r--r--src/resolve/resolved-manager.c5
-rw-r--r--src/resolve/resolved-resolv-conf.c6
7 files changed, 54 insertions, 112 deletions
diff --git a/src/resolve/resolved-conf.c b/src/resolve/resolved-conf.c
index dbac45170f..3fc7d9ae3d 100644
--- a/src/resolve/resolved-conf.c
+++ b/src/resolve/resolved-conf.c
@@ -40,7 +40,7 @@ int manager_add_dns_server_by_string(Manager *m, DnsServerType type, const char
return r;
/* Filter out duplicates */
- s = manager_find_dns_server(m, type, family, &address);
+ s = dns_server_find(manager_get_first_dns_server(m, type), family, &address);
if (s) {
/*
* Drop the marker. This is used to find the servers
@@ -141,7 +141,7 @@ int config_parse_dns_servers(
if (isempty(rvalue))
/* Empty assignment means clear the list */
- manager_flush_dns_servers(m, ltype);
+ dns_server_unlink_all(manager_get_first_dns_server(m, ltype));
else {
/* Otherwise, add to the list */
r = manager_parse_dns_server_string_and_warn(m, ltype, rvalue);
diff --git a/src/resolve/resolved-dns-server.c b/src/resolve/resolved-dns-server.c
index 81301ab800..93b954139b 100644
--- a/src/resolve/resolved-dns-server.c
+++ b/src/resolve/resolved-dns-server.c
@@ -240,74 +240,64 @@ const struct hash_ops dns_server_hash_ops = {
.compare = dns_server_compare_func
};
-DnsServer *manager_get_first_dns_server(Manager *m, DnsServerType t) {
- assert(m);
-
- switch (t) {
+void dns_server_unlink_all(DnsServer *first) {
+ DnsServer *next;
- case DNS_SERVER_SYSTEM:
- return m->dns_servers;
+ if (!first)
+ return;
- case DNS_SERVER_FALLBACK:
- return m->fallback_dns_servers;
+ next = first->servers_next;
+ dns_server_unlink(first);
- default:
- return NULL;
- }
+ dns_server_unlink_all(next);
}
-void manager_flush_dns_servers(Manager *m, DnsServerType type) {
- assert(m);
+void dns_server_unlink_marked(DnsServer *first) {
+ DnsServer *next;
- for (;;) {
- DnsServer *first;
+ if (!first)
+ return;
- first = manager_get_first_dns_server(m, type);
- if (!first)
- break;
+ next = first->servers_next;
+ if (first->marked)
dns_server_unlink(first);
- }
-}
-
-void manager_flush_marked_dns_servers(Manager *m, DnsServerType type) {
- DnsServer *first, *s, *next;
- assert(m);
-
- first = manager_get_first_dns_server(m, type);
+ dns_server_unlink_marked(next);
+}
- LIST_FOREACH_SAFE(servers, s, next, first) {
- if (!s->marked)
- continue;
+void dns_server_mark_all(DnsServer *first) {
+ if (!first)
+ return;
- dns_server_unlink(s);
- }
+ first->marked = true;
+ dns_server_mark_all(first->servers_next);
}
-void manager_mark_dns_servers(Manager *m, DnsServerType type) {
- DnsServer *first, *s;
+DnsServer *dns_server_find(DnsServer *first, int family, const union in_addr_union *in_addr) {
+ DnsServer *s;
- assert(m);
-
- first = manager_get_first_dns_server(m, type);
LIST_FOREACH(servers, s, first)
- s->marked = true;
-}
+ if (s->family == family && in_addr_equal(family, &s->address, in_addr) > 0)
+ return s;
-DnsServer* manager_find_dns_server(Manager *m, DnsServerType type, int family, const union in_addr_union *in_addr) {
- DnsServer *first, *s;
+ return NULL;
+}
+DnsServer *manager_get_first_dns_server(Manager *m, DnsServerType t) {
assert(m);
- assert(in_addr);
- first = manager_get_first_dns_server(m, type);
+ switch (t) {
- LIST_FOREACH(servers, s, first)
- if (s->family == family && in_addr_equal(family, &s->address, in_addr) > 0)
- return s;
+ case DNS_SERVER_SYSTEM:
+ return m->dns_servers;
- return NULL;
+ case DNS_SERVER_FALLBACK:
+ return m->fallback_dns_servers;
+
+ default:
+ return NULL;
+ }
}
DnsServer *manager_set_dns_server(Manager *m, DnsServer *s) {
diff --git a/src/resolve/resolved-dns-server.h b/src/resolve/resolved-dns-server.h
index 0077456cbc..3a78d4a3b5 100644
--- a/src/resolve/resolved-dns-server.h
+++ b/src/resolve/resolved-dns-server.h
@@ -72,14 +72,15 @@ void dns_server_move_back_and_unmark(DnsServer *s);
void dns_server_packet_received(DnsServer *s, usec_t rtt);
void dns_server_packet_lost(DnsServer *s, usec_t usec);
-DnsServer *manager_get_first_dns_server(Manager *m, DnsServerType t);
+DnsServer *dns_server_find(DnsServer *first, int family, const union in_addr_union *in_addr);
+
+void dns_server_unlink_all(DnsServer *first);
+void dns_server_unlink_marked(DnsServer *first);
+void dns_server_mark_all(DnsServer *first);
-void manager_flush_dns_servers(Manager *m, DnsServerType t);
-void manager_flush_marked_dns_servers(Manager *m, DnsServerType type);
-void manager_mark_dns_servers(Manager *m, DnsServerType type);
+DnsServer *manager_get_first_dns_server(Manager *m, DnsServerType t);
DnsServer *manager_set_dns_server(Manager *m, DnsServer *s);
-DnsServer *manager_find_dns_server(Manager *m, DnsServerType t, int family, const union in_addr_union *in_addr);
DnsServer *manager_get_dns_server(Manager *m);
void manager_next_dns_server(Manager *m);
diff --git a/src/resolve/resolved-link.c b/src/resolve/resolved-link.c
index c367160d98..ddd9427dab 100644
--- a/src/resolve/resolved-link.c
+++ b/src/resolve/resolved-link.c
@@ -65,7 +65,7 @@ Link *link_free(Link *l) {
if (!l)
return NULL;
- link_flush_dns_servers(l);
+ dns_server_unlink_marked(l->dns_servers);
dns_search_domain_unlink_all(l->search_domains);
while (l->addresses)
@@ -162,7 +162,7 @@ static int link_update_dns_servers(Link *l) {
if (r < 0)
goto clear;
- link_mark_dns_servers(l);
+ dns_server_mark_all(l->dns_servers);
STRV_FOREACH(nameserver, nameservers) {
union in_addr_union a;
@@ -173,7 +173,7 @@ static int link_update_dns_servers(Link *l) {
if (r < 0)
goto clear;
- s = link_find_dns_server(l, family, &a);
+ s = dns_server_find(l->dns_servers, family, &a);
if (s)
dns_server_move_back_and_unmark(s);
else {
@@ -183,11 +183,11 @@ static int link_update_dns_servers(Link *l) {
}
}
- link_flush_marked_dns_servers(l);
+ dns_server_unlink_marked(l->dns_servers);
return 0;
clear:
- link_flush_dns_servers(l);
+ dns_server_unlink_all(l->dns_servers);
return r;
}
@@ -314,47 +314,6 @@ LinkAddress *link_find_address(Link *l, int family, const union in_addr_union *i
return NULL;
}
-void link_flush_dns_servers(Link *l) {
- assert(l);
-
- while (l->dns_servers)
- dns_server_unlink(l->dns_servers);
-}
-
-void link_flush_marked_dns_servers(Link *l) {
- DnsServer *s, *next;
-
- assert(l);
-
- LIST_FOREACH_SAFE(servers, s, next, l->dns_servers) {
- if (!s->marked)
- continue;
-
- dns_server_unlink(s);
- }
-}
-
-void link_mark_dns_servers(Link *l) {
- DnsServer *s;
-
- assert(l);
-
- LIST_FOREACH(servers, s, l->dns_servers)
- s->marked = true;
-}
-
-DnsServer* link_find_dns_server(Link *l, int family, const union in_addr_union *in_addr) {
- DnsServer *s;
-
- assert(l);
- assert(in_addr);
-
- LIST_FOREACH(servers, s, l->dns_servers)
- if (s->family == family && in_addr_equal(family, &s->address, in_addr))
- return s;
- return NULL;
-}
-
DnsServer* link_set_dns_server(Link *l, DnsServer *s) {
assert(l);
diff --git a/src/resolve/resolved-link.h b/src/resolve/resolved-link.h
index d72461de06..a25715d269 100644
--- a/src/resolve/resolved-link.h
+++ b/src/resolve/resolved-link.h
@@ -79,17 +79,10 @@ bool link_relevant(Link *l, int family);
LinkAddress* link_find_address(Link *l, int family, const union in_addr_union *in_addr);
void link_add_rrs(Link *l, bool force_remove);
-void link_flush_dns_servers(Link *l);
-void link_flush_marked_dns_servers(Link *l);
-void link_mark_dns_servers(Link *l);
-
DnsServer* link_set_dns_server(Link *l, DnsServer *s);
-DnsServer* link_find_dns_server(Link *l, int family, const union in_addr_union *in_addr);
DnsServer* link_get_dns_server(Link *l);
void link_next_dns_server(Link *l);
-void link_flush_search_domains(Link *l);
-
int link_address_new(Link *l, LinkAddress **ret, int family, const union in_addr_union *in_addr);
LinkAddress *link_address_free(LinkAddress *a);
int link_address_update_rtnl(LinkAddress *a, sd_netlink_message *m);
diff --git a/src/resolve/resolved-manager.c b/src/resolve/resolved-manager.c
index 0771ac840f..31f042e066 100644
--- a/src/resolve/resolved-manager.c
+++ b/src/resolve/resolved-manager.c
@@ -533,9 +533,8 @@ Manager *manager_free(Manager *m) {
if (!m)
return NULL;
- manager_flush_dns_servers(m, DNS_SERVER_SYSTEM);
- manager_flush_dns_servers(m, DNS_SERVER_FALLBACK);
-
+ dns_server_unlink_all(m->dns_servers);
+ dns_server_unlink_all(m->fallback_dns_servers);
dns_search_domain_unlink_all(m->search_domains);
while ((l = hashmap_first(m->links)))
diff --git a/src/resolve/resolved-resolv-conf.c b/src/resolve/resolved-resolv-conf.c
index 2ab0008fce..f5cce670f0 100644
--- a/src/resolve/resolved-resolv-conf.c
+++ b/src/resolve/resolved-resolv-conf.c
@@ -85,7 +85,7 @@ int manager_read_resolv_conf(Manager *m) {
goto clear;
}
- manager_mark_dns_servers(m, DNS_SERVER_SYSTEM);
+ dns_server_mark_all(m->dns_servers);
dns_search_domain_mark_all(m->search_domains);
FOREACH_LINE(line, f, r = -errno; goto clear) {
@@ -118,7 +118,7 @@ int manager_read_resolv_conf(Manager *m) {
/* Flush out all servers and search domains that are still
* marked. Those are then ones that didn't appear in the new
* /etc/resolv.conf */
- manager_flush_marked_dns_servers(m, DNS_SERVER_SYSTEM);
+ dns_server_unlink_marked(m->dns_servers);
dns_search_domain_unlink_marked(m->search_domains);
/* Whenever /etc/resolv.conf changes, start using the first
@@ -134,7 +134,7 @@ int manager_read_resolv_conf(Manager *m) {
return 0;
clear:
- manager_flush_dns_servers(m, DNS_SERVER_SYSTEM);
+ dns_server_unlink_all(m->dns_servers);
dns_search_domain_unlink_all(m->search_domains);
return r;
}