sd-network: add support for wildcard domains
authorTom Gundersen <teg@jklm.no>
Fri, 15 Aug 2014 12:49:31 +0000 (14:49 +0200)
committerTom Gundersen <teg@jklm.no>
Fri, 15 Aug 2014 13:15:24 +0000 (15:15 +0200)
src/libsystemd/sd-network/sd-network.c
src/network/networkctl.c
src/network/networkd-link.c
src/network/networkd-network.c
src/network/networkd.h
src/systemd/sd-network.h

index 4d8b7e7..e30fc3c 100644 (file)
@@ -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;
 }
index 33fe8bf..bf95aa2 100644 (file)
@@ -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);
index d25343b..76e6427 100644 (file)
@@ -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));
         }
index bbc5d27..f3b2c68 100644 (file)
@@ -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);
index a9867d9..c8d89d2 100644 (file)
@@ -111,6 +111,7 @@ struct Network {
         Hashmap *addresses_by_section;
         Hashmap *routes_by_section;
 
+        bool wildcard_domain;
         char **domains, **dns, **ntp;
 
         LLMNRSupport llmnr;
index db78507..52e398a 100644 (file)
@@ -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;