mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-10-28 11:55:23 +03:00
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.
This commit is contained in:
parent
444d77fd01
commit
0b58db658b
@ -48,7 +48,7 @@ int manager_add_dns_server_by_string(Manager *m, DnsServerType type, const char
|
||||
* manager_mark_dns_servers() and
|
||||
* manager_flush_marked_dns_servers().
|
||||
*/
|
||||
s->marked = false;
|
||||
dns_server_move_back_and_unmark(s);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
assert_not_reached("Unknown server type");
|
||||
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);
|
||||
|
||||
|
@ -31,6 +31,7 @@ typedef enum DnsServerType {
|
||||
DNS_SERVER_LINK,
|
||||
} DnsServerType;
|
||||
|
||||
#include "resolved-manager.h"
|
||||
#include "resolved-link.h"
|
||||
|
||||
struct DnsServer {
|
||||
@ -39,7 +40,6 @@ struct DnsServer {
|
||||
unsigned n_ref;
|
||||
|
||||
DnsServerType type;
|
||||
|
||||
Link *link;
|
||||
|
||||
int family;
|
||||
@ -57,9 +57,9 @@ struct DnsServer {
|
||||
|
||||
int dns_server_new(
|
||||
Manager *m,
|
||||
DnsServer **s,
|
||||
DnsServer **ret,
|
||||
DnsServerType type,
|
||||
Link *l,
|
||||
Link *link,
|
||||
int family,
|
||||
const union in_addr_union *address);
|
||||
|
||||
@ -67,6 +67,7 @@ DnsServer* dns_server_ref(DnsServer *s);
|
||||
DnsServer* dns_server_unref(DnsServer *s);
|
||||
|
||||
void dns_server_unlink(DnsServer *s);
|
||||
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);
|
||||
|
@ -174,7 +174,7 @@ static int link_update_dns_servers(Link *l) {
|
||||
|
||||
s = link_find_dns_server(l, family, &a);
|
||||
if (s)
|
||||
s->marked = false;
|
||||
dns_server_move_back_and_unmark(s);
|
||||
else {
|
||||
r = dns_server_new(l->manager, NULL, DNS_SERVER_LINK, l, family, &a);
|
||||
if (r < 0)
|
||||
|
Loading…
Reference in New Issue
Block a user