[systemd-commits] 3 commits - src/libsystemd src/network src/systemd

Lennart Poettering lennart at kemper.freedesktop.org
Fri Aug 15 07:02:55 PDT 2014


 src/libsystemd/sd-network/sd-network.c |    4 +
 src/network/networkctl.c               |    8 ++-
 src/network/networkd-manager.c         |   73 +++++++++++++++++++--------------
 src/network/networkd-network.c         |    1 
 src/systemd/sd-network.h               |    7 ++-
 5 files changed, 60 insertions(+), 33 deletions(-)

New commits:
commit 486d1a81489da2341454ede4624342aad8334443
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Aug 15 16:02:42 2014 +0200

    networkd: fix minor memory leak

diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c
index 6f0d1a1..6538abe 100644
--- a/src/network/networkd-network.c
+++ b/src/network/networkd-network.c
@@ -166,6 +166,7 @@ void network_free(Network *network) {
 
         strv_free(network->ntp);
         strv_free(network->dns);
+        strv_free(network->domains);
 
         netdev_unref(network->bridge);
 

commit c627729fc49d59ffcecc09555a34d9dd139927ce
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Aug 15 16:02:29 2014 +0200

    networkctl: show acquired system domains

diff --git a/src/network/networkctl.c b/src/network/networkctl.c
index 8f2c1b3..6253cbf 100644
--- a/src/network/networkctl.c
+++ b/src/network/networkctl.c
@@ -427,7 +427,7 @@ static int link_status_one(sd_rtnl *rtnl, struct udev *udev, const char *name) {
         if (!strv_isempty(dns))
                 dump_list("         DNS: ", dns);
         if (!strv_isempty(domains))
-                dump_list("     Domains: ", domains);
+                dump_list("      Domain: ", domains);
         if (!strv_isempty(ntp))
                 dump_list("         NTP: ", ntp);
 
@@ -454,7 +454,7 @@ static int link_status(char **args, unsigned n) {
 
         if (n <= 1 && !arg_all) {
                 _cleanup_free_ char *operational_state = NULL;
-                _cleanup_strv_free_ char **dns = NULL, **ntp = NULL;
+                _cleanup_strv_free_ char **dns = NULL, **ntp = NULL, **domains = NULL;
                 _cleanup_free_ struct local_address *addresses = NULL;
                 const char *on_color_operational, *off_color_operational;
                 int i, c;
@@ -480,6 +480,10 @@ static int link_status(char **args, unsigned n) {
                 if (!strv_isempty(dns))
                         dump_list("         DNS: ", dns);
 
+                sd_network_get_domains(&domains);
+                if (!strv_isempty(domains))
+                        dump_list("      Domain: ", domains);
+
                 sd_network_get_dns(&ntp);
                 if (!strv_isempty(ntp))
                         dump_list("         NTP: ", ntp);

commit 8612e9365333d35773a08509b1d80a98911acb44
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Aug 15 16:02:14 2014 +0200

    sd-network: add system-wide sd_network_get_domains() API

diff --git a/src/libsystemd/sd-network/sd-network.c b/src/libsystemd/sd-network/sd-network.c
index 5d28af0..3a3f535 100644
--- a/src/libsystemd/sd-network/sd-network.c
+++ b/src/libsystemd/sd-network/sd-network.c
@@ -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;
diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c
index e3d72ed..f2fe5d5 100644
--- a/src/network/networkd-manager.c
+++ b/src/network/networkd-manager.c
@@ -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)
diff --git a/src/systemd/sd-network.h b/src/systemd/sd-network.h
index 52e398a..b2086c7 100644
--- a/src/systemd/sd-network.h
+++ b/src/systemd/sd-network.h
@@ -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:



More information about the systemd-commits mailing list