void *userdata) {
Manager *m = userdata;
- DnsServer **l;
int r;
assert(filename);
assert(rvalue);
assert(m);
- if (ltype == DNS_SERVER_FALLBACK)
- l = &m->fallback_dns_servers;
- else
- l = &m->dns_servers;
-
- if (isempty(rvalue)) {
-
+ if (isempty(rvalue))
/* Empty assignment means clear the list */
- while (*l)
- dns_server_free(*l);
-
- } else {
-
+ manager_flush_dns_servers(m, ltype);
+ else {
/* Otherwise add to the list */
r = manager_parse_dns_server(m, ltype, rvalue);
if (r < 0) {
* we used so far was a fallback one? Then let's try to pick
* the new one */
if (type != DNS_SERVER_FALLBACK &&
- s->manager->current_dns_server &&
- s->manager->current_dns_server->type == DNS_SERVER_FALLBACK)
- manager_set_dns_server(s->manager, NULL);
+ m->current_dns_server &&
+ m->current_dns_server->type == DNS_SERVER_FALLBACK)
+ manager_set_dns_server(m, NULL);
if (ret)
*ret = s;
LIST_REMOVE(servers, s->manager->fallback_dns_servers, s);
else
assert_not_reached("Unknown server type");
+
+ if (s->manager->current_dns_server == s)
+ manager_set_dns_server(s->manager, NULL);
}
if (s->link && s->link->current_dns_server == s)
link_set_dns_server(s->link, NULL);
- if (s->manager && s->manager->current_dns_server == s)
- manager_set_dns_server(s->manager, NULL);
-
free(s);
return NULL;
typedef struct DnsServer DnsServer;
typedef enum DnsServerSource DnsServerSource;
-#include "resolved-manager.h"
-#include "resolved-link.h"
-
typedef enum DnsServerType {
DNS_SERVER_SYSTEM,
DNS_SERVER_FALLBACK,
DNS_SERVER_LINK,
} DnsServerType;
+#include "resolved-manager.h"
+#include "resolved-link.h"
+
struct DnsServer {
Manager *manager;
dns_scope_free(m->unicast_scope);
- while (m->dns_servers)
- dns_server_free(m->dns_servers);
- while (m->fallback_dns_servers)
- dns_server_free(m->fallback_dns_servers);
+ manager_flush_dns_servers(m, DNS_SERVER_SYSTEM);
+ manager_flush_dns_servers(m, DNS_SERVER_FALLBACK);
hashmap_free(m->links);
hashmap_free(m->dns_transactions);
dns_zone_verify_all(&s->zone);
}
+void manager_flush_dns_servers(Manager *m, DnsServerType t) {
+ assert(m);
+
+ if (t == DNS_SERVER_SYSTEM)
+ while (m->dns_servers)
+ dns_server_free(m->dns_servers);
+
+ if (t == DNS_SERVER_FALLBACK)
+ while (m->fallback_dns_servers)
+ dns_server_free(m->fallback_dns_servers);
+}
+
static const char* const support_table[_SUPPORT_MAX] = {
[SUPPORT_NO] = "no",
[SUPPORT_YES] = "yes",
void manager_verify_all(Manager *m);
+void manager_flush_dns_servers(Manager *m, DnsServerType t);
+
DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free);
#define EXTRA_CMSG_SPACE 1024