summaryrefslogtreecommitdiff
path: root/src/resolve/resolved-dns-server.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-11-24 20:50:37 +0100
committerLennart Poettering <lennart@poettering.net>2015-11-25 21:58:38 +0100
commit0b58db658b5c3f586ac3a837427f1f7fec2abb2e (patch)
treefdb47d9ceee7a7d07637ba5d5f2682a3d9d2074d /src/resolve/resolved-dns-server.c
parent444d77fd014d86f3b211abf52981bfb34e7e78be (diff)
resolved: make sure order of dns servers is stable
Previously, we'd keep adding new dns servers we discover to the end of our linked list of servers. When we encountered a pre-existing server, we'd just leave it where it was. In essence that meant that old servers ended up at the front, and new servers at the end, but not in an order that would reflect the configuration. With this change we ensure that every pre-existing server we want to add again we move to the back of the linked list, so that the order is stable and in sync with the requested configuration.
Diffstat (limited to 'src/resolve/resolved-dns-server.c')
-rw-r--r--src/resolve/resolved-dns-server.c63
1 files changed, 57 insertions, 6 deletions
diff --git a/src/resolve/resolved-dns-server.c b/src/resolve/resolved-dns-server.c
index 371594c710..81301ab800 100644
--- a/src/resolve/resolved-dns-server.c
+++ b/src/resolve/resolved-dns-server.c
@@ -48,25 +48,34 @@ int dns_server_new(
return -ENOMEM;
s->n_ref = 1;
+ s->manager = m;
s->type = type;
s->family = family;
s->address = *in_addr;
s->resend_timeout = DNS_TIMEOUT_MIN_USEC;
- if (type == DNS_SERVER_LINK) {
+ switch (type) {
+
+ case DNS_SERVER_LINK:
+ s->link = l;
LIST_FIND_TAIL(servers, l->dns_servers, tail);
LIST_INSERT_AFTER(servers, l->dns_servers, tail, s);
- s->link = l;
- } else if (type == DNS_SERVER_SYSTEM) {
+ break;
+
+ case DNS_SERVER_SYSTEM:
LIST_FIND_TAIL(servers, m->dns_servers, tail);
LIST_INSERT_AFTER(servers, m->dns_servers, tail, s);
- } else if (type == DNS_SERVER_FALLBACK) {
+ break;
+
+ case DNS_SERVER_FALLBACK:
LIST_FIND_TAIL(servers, m->fallback_dns_servers, tail);
LIST_INSERT_AFTER(servers, m->fallback_dns_servers, tail, s);
- } else
+ break;
+
+ default:
assert_not_reached("Unknown server type");
+ }
- s->manager = m;
s->linked = true;
/* A new DNS server that isn't fallback is added and the one
@@ -145,6 +154,48 @@ void dns_server_unlink(DnsServer *s) {
dns_server_unref(s);
}
+void dns_server_move_back_and_unmark(DnsServer *s) {
+ DnsServer *tail;
+
+ assert(s);
+
+ if (!s->marked)
+ return;
+
+ s->marked = false;
+
+ if (!s->linked || !s->servers_next)
+ return;
+
+ /* Move us to the end of the list, so that the order is
+ * strictly kept, if we are not at the end anyway. */
+
+ switch (s->type) {
+
+ case DNS_SERVER_LINK:
+ assert(s->link);
+ LIST_FIND_TAIL(servers, s, tail);
+ LIST_REMOVE(servers, s->link->dns_servers, s);
+ LIST_INSERT_AFTER(servers, s->link->dns_servers, tail, s);
+ break;
+
+ case DNS_SERVER_SYSTEM:
+ LIST_FIND_TAIL(servers, s, tail);
+ LIST_REMOVE(servers, s->manager->dns_servers, s);
+ LIST_INSERT_AFTER(servers, s->manager->dns_servers, tail, s);
+ break;
+
+ case DNS_SERVER_FALLBACK:
+ LIST_FIND_TAIL(servers, s, tail);
+ LIST_REMOVE(servers, s->manager->fallback_dns_servers, s);
+ LIST_INSERT_AFTER(servers, s->manager->fallback_dns_servers, tail, s);
+ break;
+
+ default:
+ assert_not_reached("Unknown server type");
+ }
+}
+
void dns_server_packet_received(DnsServer *s, usec_t rtt) {
assert(s);