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

Tom Gundersen tomegun at kemper.freedesktop.org
Fri Aug 15 06:15:33 PDT 2014


 man/systemd.network.xml                  |   13 ++++++++++-
 src/libsystemd/sd-network/sd-network.c   |   19 +++++++++++++++++
 src/network/networkctl.c                 |    7 ++++++
 src/network/networkd-link.c              |   19 +++++++++++++++--
 src/network/networkd-network-gperf.gperf |    1 
 src/network/networkd-network.c           |   34 +++++++++++++++++++++++++++++++
 src/network/networkd.h                   |   14 +++++++++++-
 src/systemd/sd-network.h                 |    4 +++
 8 files changed, 107 insertions(+), 4 deletions(-)

New commits:
commit 67272d157a35e5cda4e5c904eafdcc23d20541d1
Author: Tom Gundersen <teg at jklm.no>
Date:   Fri Aug 15 14:49:31 2014 +0200

    sd-network: add support for wildcard domains

diff --git a/src/libsystemd/sd-network/sd-network.c b/src/libsystemd/sd-network/sd-network.c
index 4d8b7e7..e30fc3c 100644
--- a/src/libsystemd/sd-network/sd-network.c
+++ b/src/libsystemd/sd-network/sd-network.c
@@ -210,6 +210,25 @@ _public_ int sd_network_link_get_domains(int ifindex, char ***ret) {
         return network_get_link_strv("DOMAINS", ifindex, ret);
 }
 
+_public_ int sd_network_link_get_wildcard_domain(int ifindex) {
+        int r;
+        _cleanup_free_ char *p = NULL, *s = NULL;
+
+        assert_return(ifindex > 0, -EINVAL);
+
+        if (asprintf(&p, "/run/systemd/netif/links/%d", ifindex) < 0)
+                return -ENOMEM;
+
+        r = parse_env_file(p, NEWLINE, "WILDCARD_DOMAIN", &s, NULL);
+        if (r < 0)
+                return r;
+
+        if (!s)
+                return -EIO;
+
+        return parse_boolean(s);
+}
+
 static inline int MONITOR_TO_FD(sd_network_monitor *m) {
         return (int) (unsigned long) m - 1;
 }
diff --git a/src/network/networkctl.c b/src/network/networkctl.c
index 33fe8bf..bf95aa2 100644
--- a/src/network/networkctl.c
+++ b/src/network/networkctl.c
@@ -366,6 +366,13 @@ static int link_status_one(sd_rtnl *rtnl, struct udev *udev, const char *name) {
         sd_network_link_get_dns(ifindex, &dns);
         sd_network_link_get_ntp(ifindex, &ntp);
         sd_network_link_get_domains(ifindex, &domains);
+        r = sd_network_link_get_wildcard_domain(ifindex);
+        if (r > 0) {
+                char *wildcard;
+
+                wildcard = strdup("*");
+                strv_push(&domains, wildcard);
+        }
 
         sprintf(devid, "n%i", ifindex);
         d = udev_device_new_from_device_id(udev, devid);
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index d25343b..76e6427 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -1784,6 +1784,9 @@ int link_save(Link *link) {
 
                 fputs("\n", f);
 
+                fprintf(f, "WILDCARD_DOMAIN=%s\n",
+                        yes_no(link->network->wildcard_domain));
+
                 fprintf(f, "LLMNR=%s\n",
                         llmnr_support_to_string(link->network->llmnr));
         }
diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c
index bbc5d27..f3b2c68 100644
--- a/src/network/networkd-network.c
+++ b/src/network/networkd-network.c
@@ -351,6 +351,7 @@ int config_parse_domains(const char *unit,
                          const char *rvalue,
                          void *data,
                          void *userdata) {
+        Network *network = userdata;
         char ***domains = data;
         char **domain;
         int r;
@@ -362,6 +363,11 @@ int config_parse_domains(const char *unit,
 
         strv_uniq(*domains);
 
+        if (strv_isempty(*domains))
+                network->wildcard_domain = false;
+        else if (strv_find(*domains, "*"))
+                network->wildcard_domain = true;
+
         STRV_FOREACH(domain, *domains)
                 if (is_localhost(*domain) || !hostname_is_valid(*domain))
                         strv_remove(*domains, *domain);
diff --git a/src/network/networkd.h b/src/network/networkd.h
index a9867d9..c8d89d2 100644
--- a/src/network/networkd.h
+++ b/src/network/networkd.h
@@ -111,6 +111,7 @@ struct Network {
         Hashmap *addresses_by_section;
         Hashmap *routes_by_section;
 
+        bool wildcard_domain;
         char **domains, **dns, **ntp;
 
         LLMNRSupport llmnr;
diff --git a/src/systemd/sd-network.h b/src/systemd/sd-network.h
index db78507..52e398a 100644
--- a/src/systemd/sd-network.h
+++ b/src/systemd/sd-network.h
@@ -107,6 +107,10 @@ int sd_network_link_get_llmnr(int ifindex, char **llmnr);
 /* Get the DNS domain names for a given link. */
 int sd_network_link_get_domains(int ifindex, char ***domains);
 
+/* Returns whether or not domains that don't match any link should be resolved
+ * on this link. 1 for yes, 0 for no and negative value for error */
+int sd_network_link_get_wildcard_domain(int ifindex);
+
 /* Monitor object */
 typedef struct sd_network_monitor sd_network_monitor;
 

commit 6192b846ca0d15602e94ddb5da4420b7c60d64a5
Author: Tom Gundersen <teg at jklm.no>
Date:   Fri Aug 15 14:21:08 2014 +0200

    networkd: add support for Domains= to .network files
    
    This allows the search/routing domanis to be specified per link/network and be passed
    on to resolved.

diff --git a/man/systemd.network.xml b/man/systemd.network.xml
index 290aa6e..0245099 100644
--- a/man/systemd.network.xml
+++ b/man/systemd.network.xml
@@ -301,7 +301,18 @@
                                                 This option may be specified more than once.</para>
                                         </listitem>
                                 </varlistentry>
-<!-- TODO: document NTP= option when it is actually used somewhere -->
+                                <varlistentry>
+                                        <term><varname>Domains=</varname></term>
+                                        <listitem>
+                                                <para>The domains used for DNS resolution over this link.</para>
+                                        </listitem>
+                                </varlistentry>
+                                <varlistentry>
+                                        <term><varname>NTP=</varname></term>
+                                        <listitem>
+                                                <para>An NTP server address. This option may be specified more than once.</para>
+                                        </listitem>
+                                </varlistentry>
                                 <varlistentry>
                                         <term><varname>Bridge=</varname></term>
                                         <listitem>
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index 9eb2e89..d25343b 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -1722,6 +1722,7 @@ int link_save(Link *link) {
 
         if (link->network) {
                 char **address;
+                char **domain;
 
                 fputs("DNS=", f);
 
@@ -1763,15 +1764,26 @@ int link_save(Link *link) {
 
                 fputs("\n", f);
 
+                fprintf(f, "DOMAINS=");
+
                 if (link->network->dhcp_domains &&
                     link->dhcp_lease) {
                         const char *domainname;
 
                         r = sd_dhcp_lease_get_domainname(link->dhcp_lease, &domainname);
-                        if (r >= 0)
-                                fprintf(f, "DOMAINS=%s\n", domainname);
+                        if (r >= 0) {
+                                fputs(domainname, f);
+                                if (link->network->domains)
+                                        fputs(" ", f);
+                        }
                 }
 
+                STRV_FOREACH(domain, link->network->domains)
+                        fprintf(f, "%s%s", *domain,
+                                (domain + 1 ? " " : ""));
+
+                fputs("\n", f);
+
                 fprintf(f, "LLMNR=%s\n",
                         llmnr_support_to_string(link->network->llmnr));
         }
diff --git a/src/network/networkd-network-gperf.gperf b/src/network/networkd-network-gperf.gperf
index 9cd7a4a..c5b9614 100644
--- a/src/network/networkd-network-gperf.gperf
+++ b/src/network/networkd-network-gperf.gperf
@@ -37,6 +37,7 @@ Network.IPv4LL,              config_parse_bool,                  0,
 Network.IPv4LLRoute,         config_parse_bool,                  0,                             offsetof(Network, ipv4ll_route)
 Network.Address,             config_parse_address,               0,                             0
 Network.Gateway,             config_parse_gateway,               0,                             0
+Network.Domains,             config_parse_domains,               0,                             offsetof(Network, domains)
 Network.DNS,                 config_parse_strv,                  0,                             offsetof(Network, dns)
 Network.LLMNR,               config_parse_llmnr,                 0,                             offsetof(Network, llmnr)
 Network.NTP,                 config_parse_strv,                  0,                             offsetof(Network, ntp)
diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c
index e13e4a0..bbc5d27 100644
--- a/src/network/networkd-network.c
+++ b/src/network/networkd-network.c
@@ -341,6 +341,34 @@ int config_parse_netdev(const char *unit,
         return 0;
 }
 
+int config_parse_domains(const char *unit,
+                         const char *filename,
+                         unsigned line,
+                         const char *section,
+                         unsigned section_line,
+                         const char *lvalue,
+                         int ltype,
+                         const char *rvalue,
+                         void *data,
+                         void *userdata) {
+        char ***domains = data;
+        char **domain;
+        int r;
+
+        r = config_parse_strv(unit, filename, line, section, section_line,
+                              lvalue, ltype, rvalue, domains, userdata);
+        if (r < 0)
+                return r;
+
+        strv_uniq(*domains);
+
+        STRV_FOREACH(domain, *domains)
+                if (is_localhost(*domain) || !hostname_is_valid(*domain))
+                        strv_remove(*domains, *domain);
+
+        return 0;
+}
+
 int config_parse_tunnel(const char *unit,
                         const char *filename,
                         unsigned line,
diff --git a/src/network/networkd.h b/src/network/networkd.h
index 90e798d..a9867d9 100644
--- a/src/network/networkd.h
+++ b/src/network/networkd.h
@@ -111,7 +111,7 @@ struct Network {
         Hashmap *addresses_by_section;
         Hashmap *routes_by_section;
 
-        char **dns, **ntp;
+        char **domains, **dns, **ntp;
 
         LLMNRSupport llmnr;
 
@@ -224,6 +224,17 @@ int config_parse_netdev(const char *unit, const char *filename, unsigned line,
                         const char *section, unsigned section_line, const char *lvalue,
                         int ltype, const char *rvalue, void *data, void *userdata);
 
+int config_parse_domains(const char *unit,
+                         const char *filename,
+                         unsigned line,
+                         const char *section,
+                         unsigned section_line,
+                         const char *lvalue,
+                         int ltype,
+                         const char *rvalue,
+                         void *data,
+                         void *userdata);
+
 int config_parse_tunnel(const char *unit,
                         const char *filename,
                         unsigned line,



More information about the systemd-commits mailing list