[systemd-commits] 3 commits - man/systemd.network.xml src/libsystemd-network src/network src/resolve

Tom Gundersen tomegun at kemper.freedesktop.org
Thu Aug 14 16:09:50 PDT 2014


 man/systemd.network.xml                |    7 +++
 src/libsystemd-network/sd-dhcp-lease.c |   28 ++++++++++++--
 src/network/networkd-network.c         |    1 
 src/resolve/resolved-link.c            |   18 +++++++++
 src/resolve/resolved-manager.c         |   62 ++++++++++++++++++++++++++++++---
 5 files changed, 106 insertions(+), 10 deletions(-)

New commits:
commit 1bd27a45d04639190fc91ad2552b72ea759c0c27
Author: Tom Gundersen <teg at jklm.no>
Date:   Fri Aug 15 01:08:46 2014 +0200

    networkd: don't respect domainname from DHCP by default
    
    Most routers will send garbage, so make this opt-in only.

diff --git a/man/systemd.network.xml b/man/systemd.network.xml
index 9ef69fa..f4ca721 100644
--- a/man/systemd.network.xml
+++ b/man/systemd.network.xml
@@ -447,6 +447,13 @@
                                         </listitem>
                                 </varlistentry>
                                 <varlistentry>
+                                        <term><varname>UseDomainName=</varname></term>
+                                        <listitem>
+                                                <para>When true (not the default), the domain name received from the DHCP server
+                                                will be used for DNS resolution over this link.</para>
+                                        </listitem>
+                                </varlistentry>
+                                <varlistentry>
                                         <term><varname>UseRoutes=</varname></term>
                                         <listitem>
                                                 <para>When true (the default), the static routes will be requested from the DHCP server
diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c
index 11affb9..e13e4a0 100644
--- a/src/network/networkd-network.c
+++ b/src/network/networkd-network.c
@@ -83,7 +83,6 @@ static int network_load_one(Manager *manager, const char *filename) {
         network->dhcp_ntp = true;
         network->dhcp_dns = true;
         network->dhcp_hostname = true;
-        network->dhcp_domainname = true;
         network->dhcp_routes = true;
         network->dhcp_sendhost = true;
 

commit 784d9b9c09aa1ecdc688f251ea423fb47892f498
Author: Tom Gundersen <teg at jklm.no>
Date:   Fri Aug 15 01:04:53 2014 +0200

    sd-dhcp-lease: verify hostname and domainnames we receive

diff --git a/src/libsystemd-network/sd-dhcp-lease.c b/src/libsystemd-network/sd-dhcp-lease.c
index bfd1b0c..e8cfd72 100644
--- a/src/libsystemd-network/sd-dhcp-lease.c
+++ b/src/libsystemd-network/sd-dhcp-lease.c
@@ -513,19 +513,39 @@ int dhcp_lease_parse_options(uint8_t code, uint8_t len, const uint8_t *option,
                 break;
 
         case DHCP_OPTION_DOMAIN_NAME:
-                r = lease_parse_string(option, len, &lease->domainname);
+        {
+                _cleanup_free_ char *domainname = NULL;
+
+                r = lease_parse_string(option, len, &domainname);
                 if (r < 0)
                         return r;
 
-                break;
+                if (!hostname_is_valid(domainname) || is_localhost(domainname))
+                        break;
+
+                free(lease->domainname);
+                lease->domainname = domainname;
+                domainname = NULL;
 
+                break;
+        }
         case DHCP_OPTION_HOST_NAME:
-                r = lease_parse_string(option, len, &lease->hostname);
+        {
+                _cleanup_free_ char *hostname = NULL;
+
+                r = lease_parse_string(option, len, &hostname);
                 if (r < 0)
                         return r;
 
-                break;
+                if (!hostname_is_valid(hostname))
+                        break;
+
+                free(lease->hostname);
+                lease->hostname = hostname;
+                hostname = NULL;
 
+                break;
+        }
         case DHCP_OPTION_ROOT_PATH:
                 r = lease_parse_string(option, len, &lease->root_path);
                 if (r < 0)

commit bda2c408f8a739c19161818bcc842107f60652a2
Author: Tom Gundersen <teg at jklm.no>
Date:   Thu Aug 14 22:18:22 2014 +0200

    resolved: pull in domain names from sd-network

diff --git a/src/resolve/resolved-link.c b/src/resolve/resolved-link.c
index 8ec180d..f47017c 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 84dad92..bfbdc7d 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);



More information about the systemd-commits mailing list