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
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);
.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) {
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);
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)
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;
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 {
}
}
- 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;
}
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);
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);
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)))
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) {
/* 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
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;
}