summaryrefslogtreecommitdiff
path: root/src/resolve/resolved-resolv-conf.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-11-24 21:12:51 +0100
committerLennart Poettering <lennart@poettering.net>2015-11-25 21:58:38 +0100
commita51c10485af349eb15faa4d1a63b9818bcf3e589 (patch)
tree86134465451ab8044208710c2c5018171100555d /src/resolve/resolved-resolv-conf.c
parent0b58db658b5c3f586ac3a837427f1f7fec2abb2e (diff)
resolved: add a generic DnsSearchDomain concept
With this change, we add a new object to resolved, "DnsSearchDomain=" which wraps a search domain. This is then used to introduce a global search domain list, in addition to the existing per-link search domain list which is reword to make use of this new object too. This is preparation for implement proper unicast DNS search domain support.
Diffstat (limited to 'src/resolve/resolved-resolv-conf.c')
-rw-r--r--src/resolve/resolved-resolv-conf.c35
1 files changed, 26 insertions, 9 deletions
diff --git a/src/resolve/resolved-resolv-conf.c b/src/resolve/resolved-resolv-conf.c
index 98c1720f0f..2ab0008fce 100644
--- a/src/resolve/resolved-resolv-conf.c
+++ b/src/resolve/resolved-resolv-conf.c
@@ -86,13 +86,12 @@ int manager_read_resolv_conf(Manager *m) {
}
manager_mark_dns_servers(m, DNS_SERVER_SYSTEM);
+ dns_search_domain_mark_all(m->search_domains);
FOREACH_LINE(line, f, r = -errno; goto clear) {
const char *a;
char *l;
- truncate_nl(line);
-
l = strstrip(line);
if (*l == '#' || *l == ';')
continue;
@@ -105,9 +104,22 @@ int manager_read_resolv_conf(Manager *m) {
continue;
}
+
+ a = first_word(l, "domain");
+ if (!a) /* We treat "domain" lines, and "search" lines as equivalent, and add both to our list. */
+ a = first_word(l, "search");
+ if (a) {
+ r = manager_parse_search_domains_and_warn(m, a);
+ if (r < 0)
+ log_warning_errno(r, "Failed to parse search domain string '%s', ignoring.", a);
+ }
}
+ /* 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_search_domain_unlink_marked(m->search_domains);
/* Whenever /etc/resolv.conf changes, start using the first
* DNS server of it. This is useful to deal with broken
@@ -123,6 +135,7 @@ int manager_read_resolv_conf(Manager *m) {
clear:
manager_flush_dns_servers(m, DNS_SERVER_SYSTEM);
+ dns_search_domain_unlink_all(m->search_domains);
return r;
}
@@ -211,6 +224,7 @@ int manager_write_resolv_conf(Manager *m) {
_cleanup_free_ char *temp_path = NULL;
_cleanup_fclose_ FILE *f = NULL;
_cleanup_ordered_set_free_ OrderedSet *dns = NULL, *domains = NULL;
+ DnsSearchDomain *d;
DnsServer *s;
Iterator i;
Link *l;
@@ -239,10 +253,16 @@ int manager_write_resolv_conf(Manager *m) {
return r;
}
+ LIST_FOREACH(domains, d, m->search_domains) {
+ r = ordered_set_put(domains, d->name);
+ if (r == -EEXIST)
+ continue;
+ if (r < 0)
+ return r;
+ }
+
/* Then, add the per-link servers and domains */
HASHMAP_FOREACH(l, m->links, i) {
- char **domain;
-
LIST_FOREACH(servers, s, l->dns_servers) {
r = ordered_set_put(dns, s);
if (r == -EEXIST)
@@ -251,11 +271,8 @@ int manager_write_resolv_conf(Manager *m) {
return r;
}
- if (!l->unicast_scope)
- continue;
-
- STRV_FOREACH(domain, l->unicast_scope->domains) {
- r = ordered_set_put(domains, *domain);
+ LIST_FOREACH(domains, d, l->search_domains) {
+ r = ordered_set_put(domains, d->name);
if (r == -EEXIST)
continue;
if (r < 0)