summaryrefslogtreecommitdiff
path: root/src/resolve/resolved-dns-server.c
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 /src/resolve/resolved-dns-server.c
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.
Diffstat (limited to 'src/resolve/resolved-dns-server.c')
-rw-r--r--src/resolve/resolved-dns-server.c82
1 files changed, 36 insertions, 46 deletions
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) {