diff options
author | Tom Gundersen <teg@jklm.no> | 2014-08-14 22:18:22 +0200 |
---|---|---|
committer | Tom Gundersen <teg@jklm.no> | 2014-08-14 23:38:38 +0200 |
commit | bda2c408f8a739c19161818bcc842107f60652a2 (patch) | |
tree | 7bb4b74f35847ac121f62b4290591bd80c895172 /src/resolve | |
parent | 9b4d1882ca46d5b2ae7d028ec2b5d0d0c3a46a76 (diff) |
resolved: pull in domain names from sd-network
Diffstat (limited to 'src/resolve')
-rw-r--r-- | src/resolve/resolved-link.c | 18 | ||||
-rw-r--r-- | src/resolve/resolved-manager.c | 62 |
2 files changed, 75 insertions, 5 deletions
diff --git a/src/resolve/resolved-link.c b/src/resolve/resolved-link.c index 8ec180d3a4..f47017ced8 100644 --- a/src/resolve/resolved-link.c +++ b/src/resolve/resolved-link.c @@ -223,12 +223,30 @@ clear: return r; } +static int link_update_domains(Link *l) { + int r; + + if (!l->unicast_scope) + return 0; + + strv_free(l->unicast_scope->domains); + l->unicast_scope->domains = NULL; + + r = sd_network_link_get_domains(l->ifindex, + &l->unicast_scope->domains); + if (r < 0) + return r; + + return 0; +} + int link_update_monitor(Link *l) { assert(l); link_update_dns_servers(l); link_update_llmnr_support(l); link_allocate_scopes(l); + link_update_domains(l); link_add_rrs(l, false); return 0; diff --git a/src/resolve/resolved-manager.c b/src/resolve/resolved-manager.c index 84dad92c53..bfbdc7d55b 100644 --- a/src/resolve/resolved-manager.c +++ b/src/resolve/resolved-manager.c @@ -677,7 +677,7 @@ clear: return r; } -static void write_resolve_conf_server(DnsServer *s, FILE *f, unsigned *count) { +static void write_resolv_conf_server(DnsServer *s, FILE *f, unsigned *count) { _cleanup_free_ char *t = NULL; int r; @@ -698,11 +698,33 @@ static void write_resolve_conf_server(DnsServer *s, FILE *f, unsigned *count) { (*count) ++; } +static void write_resolv_conf_search(const char *domain, FILE *f, + unsigned *length, unsigned *count) { + assert(domain); + assert(f); + assert(length); + + if (*count >= MAXDNSRCH || + *length + strlen(domain) > 256) { + if (*count == MAXDNSRCH) + fputs(" # Too many search domains configured, remaining ones ignored.", f); + if (*length <= 256) + fputs(" # Total length of all search domains is too long, remaining ones ignored.", f); + + return; + } + + fprintf(f, " %s", domain); + + (*length) += strlen(domain); + (*count) ++; +} + int manager_write_resolv_conf(Manager *m) { static const char path[] = "/run/systemd/resolve/resolv.conf"; _cleanup_free_ char *temp_path = NULL; _cleanup_fclose_ FILE *f = NULL; - _cleanup_set_free_ Set *dns = NULL; + _cleanup_set_free_ Set *dns = NULL, *domains = NULL; unsigned count = 0; DnsServer *s; Iterator i; @@ -719,6 +741,10 @@ int manager_write_resolv_conf(Manager *m) { if (!dns) return -ENOMEM; + domains = set_new(dns_name_hash_func, dns_name_compare_func); + if (!domains) + return -ENOMEM; + /* First add the system-wide servers */ LIST_FOREACH(servers, s, m->dns_servers) { r = set_put(dns, s); @@ -728,8 +754,10 @@ int manager_write_resolv_conf(Manager *m) { return r; } - /* Then, add the per-link servers */ - HASHMAP_FOREACH(l, m->links, i) + /* Then, add the per-link servers and domains */ + HASHMAP_FOREACH(l, m->links, i) { + char **domain; + LIST_FOREACH(servers, s, l->dns_servers) { r = set_put(dns, s); if (r == -EEXIST) @@ -738,6 +766,18 @@ int manager_write_resolv_conf(Manager *m) { return r; } + if (!l->unicast_scope) + continue; + + STRV_FOREACH(domain, l->unicast_scope->domains) { + r = set_put(domains, *domain); + if (r == -EEXIST) + continue; + if (r < 0) + return r; + } + } + /* If we found nothing, add the fallback servers */ if (set_isempty(dns)) { LIST_FOREACH(servers, s, m->fallback_dns_servers) { @@ -765,7 +805,19 @@ int manager_write_resolv_conf(Manager *m) { fputs("# No DNS servers known.\n", f); else { SET_FOREACH(s, dns, i) - write_resolve_conf_server(s, f, &count); + write_resolv_conf_server(s, f, &count); + } + + if (!set_isempty(domains)) { + unsigned length = 0; + char *domain; + + count = 0; + + fputs("search", f); + SET_FOREACH(domain, domains, i) + write_resolv_conf_search(domain, f, &count, &length); + fputs("\n", f); } r = fflush_and_check(f); |