chiark / gitweb /
sd-network: add system-wide sd_network_get_domains() API
authorLennart Poettering <lennart@poettering.net>
Fri, 15 Aug 2014 14:02:14 +0000 (16:02 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 15 Aug 2014 14:02:14 +0000 (16:02 +0200)
src/libsystemd/sd-network/sd-network.c
src/network/networkd-manager.c
src/systemd/sd-network.h

index 5d28af0..3a3f535 100644 (file)
@@ -92,6 +92,10 @@ _public_ int sd_network_get_ntp(char ***ret) {
         return network_get_strv("NTP", ret);
 }
 
+_public_ int sd_network_get_domains(char ***ret) {
+        return network_get_strv("DOMAINS", ret);
+}
+
 _public_ int sd_network_link_get_setup_state(int ifindex, char **state) {
         _cleanup_free_ char *s = NULL, *p = NULL;
         int r;
index e3d72ed..f2fe5d5 100644 (file)
@@ -450,8 +450,27 @@ static int set_put_in_addrv(Set *s, const struct in_addr *addresses, int n) {
         return c;
 }
 
+static void print_string_set(FILE *f, const char *field, Set *s) {
+        bool space = false;
+        Iterator i;
+        char *p;
+
+        if (set_isempty(s))
+                return;
+
+        fputs(field, f);
+
+        SET_FOREACH(p, s, i) {
+                if (space)
+                        fputc(' ', f);
+                fputs(p, f);
+                space = true;
+        }
+        fputc('\n', f);
+}
+
 int manager_save(Manager *m) {
-        _cleanup_set_free_free_ Set *dns = NULL, *ntp = NULL;
+        _cleanup_set_free_free_ Set *dns = NULL, *ntp = NULL, *domains = NULL;
         Link *link;
         Iterator i;
         _cleanup_free_ char *temp_path = NULL;
@@ -472,6 +491,10 @@ int manager_save(Manager *m) {
         if (!ntp)
                 return -ENOMEM;
 
+        domains = set_new(string_hash_func, string_compare_func);
+        if (!domains)
+                return -ENOMEM;
+
         HASHMAP_FOREACH(link, m->links, i) {
                 if (link->flags & IFF_LOOPBACK)
                         continue;
@@ -491,6 +514,10 @@ int manager_save(Manager *m) {
                 if (r < 0)
                         return r;
 
+                r = set_put_strdupv(domains, link->network->domains);
+                if (r < 0)
+                        return r;
+
                 if (!link->dhcp_lease)
                         continue;
 
@@ -503,7 +530,7 @@ int manager_save(Manager *m) {
                                 r = set_put_in_addrv(dns, addresses, r);
                                 if (r < 0)
                                         return r;
-                        } else if (r != -ENOENT)
+                        } else if (r < 0 && r != -ENOENT)
                                 return r;
                 }
 
@@ -515,6 +542,18 @@ int manager_save(Manager *m) {
                                 r = set_put_in_addrv(ntp, addresses, r);
                                 if (r < 0)
                                         return r;
+                        } else if (r < 0 && r != -ENOENT)
+                                return r;
+                }
+
+                if (link->network->dhcp_domains) {
+                        const char *domainname;
+
+                        r = sd_dhcp_lease_get_domainname(link->dhcp_lease, &domainname);
+                        if (r >= 0) {
+                                r = set_put_strdup(domains, domainname);
+                                if (r < 0)
+                                        return r;
                         } else if (r != -ENOENT)
                                 return r;
                 }
@@ -533,33 +572,9 @@ int manager_save(Manager *m) {
                 "# This is private data. Do not parse.\n"
                 "OPER_STATE=%s\n", operstate_str);
 
-        if (!set_isempty(dns)) {
-                bool space = false;
-                char *p;
-
-                fputs("DNS=", f);
-                SET_FOREACH(p, dns, i) {
-                        if (space)
-                                fputc(' ', f);
-                        fputs(p, f);
-                        space = true;
-                }
-                fputc('\n', f);
-        }
-
-        if (!set_isempty(ntp)) {
-                bool space = false;
-                char *p;
-
-                fputs("NTP=", f);
-                SET_FOREACH(p, ntp, i) {
-                        if (space)
-                                fputc(' ', f);
-                        fputs(p, f);
-                        space = true;
-                }
-                fputc('\n', f);
-        }
+        print_string_set(f, "DNS=", dns);
+        print_string_set(f, "NTP=", ntp);
+        print_string_set(f, "DOMAINS=", domains);
 
         r = fflush_and_check(f);
         if (r < 0)
index 52e398a..b2086c7 100644 (file)
@@ -58,11 +58,14 @@ int sd_network_get_operational_state(char **state);
 
 /* Get DNS entries for all links. These are string representations of
  * IP addresses */
-int sd_network_get_dns(char ***addr);
+int sd_network_get_dns(char ***dns);
 
 /* Get NTP entries for all links. These are domain names or string
  * reperesentations of IP addresses */
-int sd_network_get_ntp(char ***addr);
+int sd_network_get_ntp(char ***ntp);
+
+/* Get the search/routing domains for all links. */
+int sd_network_get_domains(char ***domains);
 
 /* Get setup state from ifindex.
  * Possible states: