[systemd-commits] src/network src/systemd

Tom Gundersen tomegun at kemper.freedesktop.org
Mon May 19 09:42:26 PDT 2014


 src/network/networkd-address.c           |   14 ++++++++++--
 src/network/networkd-link.c              |   11 ++++++---
 src/network/networkd-network-gperf.gperf |    1 
 src/network/networkd-network.c           |    8 ++++++
 src/network/networkd.h                   |    2 +
 src/network/sd-network.c                 |   36 +++++++++++++++++++++++++------
 src/systemd/sd-network.h                 |    9 +++++++
 7 files changed, 69 insertions(+), 12 deletions(-)

New commits:
commit bcb7a07e0a785bda1eed658e984ff6b4a11cba9a
Author: Tom Gundersen <teg at jklm.no>
Date:   Mon May 19 18:42:14 2014 +0200

    networkd/sd-network: expose statically configured NTP servers

diff --git a/src/network/networkd-address.c b/src/network/networkd-address.c
index 34863b2..afd36a0 100644
--- a/src/network/networkd-address.c
+++ b/src/network/networkd-address.c
@@ -335,8 +335,18 @@ int config_parse_dns(const char *unit,
                 return 0;
         }
 
-        LIST_FIND_TAIL(addresses, network->dns, tail);
-        LIST_INSERT_AFTER(addresses, network->dns, tail, n);
+        if (streq(lvalue, "DNS")) {
+                LIST_FIND_TAIL(addresses, network->dns, tail);
+                LIST_INSERT_AFTER(addresses, network->dns, tail, n);
+        } else if (streq(lvalue, "NTP")) {
+                LIST_FIND_TAIL(addresses, network->ntp, tail);
+                LIST_INSERT_AFTER(addresses, network->ntp, tail, n);
+        } else {
+                log_syntax(unit, LOG_ERR, filename, line, EINVAL,
+                           "Key is invalid, ignoring assignment: %s=%s", lvalue, rvalue);
+                return 0;
+        }
+
         n = NULL;
 
         return 0;
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index a90aff9..3ca8626 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -2027,8 +2027,10 @@ int link_save(Link *link) {
                 "FLAGS=%u\n",
                 admin_state, oper_state, link->flags);
 
-        if (link->network)
+        if (link->network) {
                 serialize_addresses(f, "DNS", link->network->dns);
+                serialize_addresses(f, "NTP", link->network->ntp);
+        }
 
         if (link->dhcp_lease) {
                 r = dhcp_lease_save(link->dhcp_lease, link->lease_file);
@@ -2037,8 +2039,11 @@ int link_save(Link *link) {
 
                 fprintf(f,
                         "DHCP_LEASE=%s\n"
-                        "DHCP_USE_DNS=%s\n",
-                        link->lease_file, yes_no(link->network->dhcp_dns));
+                        "DHCP_USE_DNS=%s\n"
+                        "DHCP_USE_NTP=%s\n",
+                        link->lease_file,
+                        yes_no(link->network->dhcp_dns),
+                        yes_no(link->network->dhcp_ntp));
         } else
                 unlink(link->lease_file);
 
diff --git a/src/network/networkd-network-gperf.gperf b/src/network/networkd-network-gperf.gperf
index 4bb8425..5038cb5 100644
--- a/src/network/networkd-network-gperf.gperf
+++ b/src/network/networkd-network-gperf.gperf
@@ -34,6 +34,7 @@ Network.IPv4LL,              config_parse_bool,                  0,
 Network.Address,             config_parse_address,               0,                             0
 Network.Gateway,             config_parse_gateway,               0,                             0
 Network.DNS,                 config_parse_dns,                   0,                             offsetof(Network, dns)
+Network.NTP,                 config_parse_dns,                   0,                             offsetof(Network, ntp)
 Network.Tunnel,              config_parse_tunnel,                0,                             offsetof(Network, tunnel)
 Address.Address,             config_parse_address,               0,                             0
 Address.Broadcast,           config_parse_broadcast,             0,                             0
diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c
index 1b8856a..a6cbee2 100644
--- a/src/network/networkd-network.c
+++ b/src/network/networkd-network.c
@@ -81,6 +81,7 @@ static int network_load_one(Manager *manager, const char *filename) {
         if (!network->filename)
                 return log_oom();
 
+        network->dhcp_ntp = true;
         network->dhcp_dns = true;
         network->dhcp_hostname = true;
         network->dhcp_domainname = true;
@@ -160,6 +161,11 @@ void network_free(Network *network) {
 
         free(network->description);
 
+        while ((address = network->ntp)) {
+                LIST_REMOVE(addresses, network->ntp, address);
+                address_free(address);
+        }
+
         while ((address = network->dns)) {
                 LIST_REMOVE(addresses, network->dns, address);
                 address_free(address);
@@ -234,7 +240,7 @@ int network_apply(Manager *manager, Network *network, Link *link) {
 
         link->network = network;
 
-        if (network->dns) {
+        if (network->dns || network->ntp) {
                 r = link_save(link);
                 if (r < 0)
                         return r;
diff --git a/src/network/networkd.h b/src/network/networkd.h
index 3e4e1f2..46ed2ac 100644
--- a/src/network/networkd.h
+++ b/src/network/networkd.h
@@ -138,6 +138,7 @@ struct Network {
         Hashmap *macvlans;
         bool dhcp;
         bool dhcp_dns;
+        bool dhcp_ntp;
         bool dhcp_mtu;
         bool dhcp_hostname;
         bool dhcp_domainname;
@@ -151,6 +152,7 @@ struct Network {
         Hashmap *routes_by_section;
 
         LIST_HEAD(Address, dns);
+        LIST_HEAD(Address, ntp);
 
         LIST_FIELDS(Network, networks);
 };
diff --git a/src/network/sd-network.c b/src/network/sd-network.c
index 7ae15ed..e7cda0d 100644
--- a/src/network/sd-network.c
+++ b/src/network/sd-network.c
@@ -168,7 +168,7 @@ _public_ int sd_network_get_dhcp_lease(unsigned index, sd_dhcp_lease **ret) {
         return 0;
 }
 
-_public_ int sd_network_get_dns(unsigned index, struct in_addr **addr, size_t *addr_size) {
+static int network_get_in_addr(const char *key, unsigned index, struct in_addr **addr, size_t *addr_size) {
         _cleanup_free_ char *p = NULL, *s = NULL;
         int r;
 
@@ -179,7 +179,7 @@ _public_ int sd_network_get_dns(unsigned index, struct in_addr **addr, size_t *a
         if (asprintf(&p, "/run/systemd/network/links/%u", index) < 0)
                 return -ENOMEM;
 
-        r = parse_env_file(p, NEWLINE, "DNS", &s, NULL);
+        r = parse_env_file(p, NEWLINE, key, &s, NULL);
         if (r < 0)
                 return r;
         else if (!s)
@@ -188,7 +188,15 @@ _public_ int sd_network_get_dns(unsigned index, struct in_addr **addr, size_t *a
         return deserialize_in_addrs(addr, addr_size, s);
 }
 
-_public_ int sd_network_get_dns6(unsigned index, struct in6_addr **addr, size_t *addr_size) {
+_public_ int sd_network_get_dns(unsigned index, struct in_addr **addr, size_t *addr_size) {
+        return network_get_in_addr("DNS", index, addr, addr_size);
+}
+
+_public_ int sd_network_get_ntp(unsigned index, struct in_addr **addr, size_t *addr_size) {
+        return network_get_in_addr("NTP", index, addr, addr_size);
+}
+
+static int network_get_in6_addr(const char *key, unsigned index, struct in6_addr **addr, size_t *addr_size) {
         _cleanup_free_ char *p = NULL, *s = NULL;
         int r;
 
@@ -199,7 +207,7 @@ _public_ int sd_network_get_dns6(unsigned index, struct in6_addr **addr, size_t
         if (asprintf(&p, "/run/systemd/network/links/%u", index) < 0)
                 return -ENOMEM;
 
-        r = parse_env_file(p, NEWLINE, "DNS", &s, NULL);
+        r = parse_env_file(p, NEWLINE, key, &s, NULL);
         if (r < 0)
                 return r;
         else if (!s)
@@ -208,7 +216,15 @@ _public_ int sd_network_get_dns6(unsigned index, struct in6_addr **addr, size_t
         return deserialize_in6_addrs(addr, addr_size, s);
 }
 
-_public_ int sd_network_dhcp_use_dns(unsigned index) {
+_public_ int sd_network_get_dns6(unsigned index, struct in6_addr **addr, size_t *addr_size) {
+        return network_get_in6_addr("DNS", index, addr, addr_size);
+}
+
+_public_ int sd_network_get_ntp6(unsigned index, struct in6_addr **addr, size_t *addr_size) {
+        return network_get_in6_addr("NTP", index, addr, addr_size);
+}
+
+static int network_get_boolean(const char *key, unsigned index) {
         _cleanup_free_ char *p = NULL, *s = NULL;
         int r;
 
@@ -217,7 +233,7 @@ _public_ int sd_network_dhcp_use_dns(unsigned index) {
         if (asprintf(&p, "/run/systemd/network/links/%u", index) < 0)
                 return -ENOMEM;
 
-        r = parse_env_file(p, NEWLINE, "DHCP_USE_DNS", &s, NULL);
+        r = parse_env_file(p, NEWLINE, key, &s, NULL);
         if (r < 0)
                 return r;
         else if (!s)
@@ -226,6 +242,14 @@ _public_ int sd_network_dhcp_use_dns(unsigned index) {
         return parse_boolean(s);
 }
 
+_public_ int sd_network_dhcp_use_dns(unsigned index) {
+        return network_get_boolean("DHCP_USE_DNS", index);
+}
+
+_public_ int sd_network_dhcp_use_ntp(unsigned index) {
+        return network_get_boolean("DHCP_USE_NTP", index);
+}
+
 _public_ int sd_network_get_ifindices(unsigned **indices) {
         _cleanup_closedir_ DIR *d;
         int r = 0;
diff --git a/src/systemd/sd-network.h b/src/systemd/sd-network.h
index 860325a..e42d106 100644
--- a/src/systemd/sd-network.h
+++ b/src/systemd/sd-network.h
@@ -83,12 +83,21 @@ int sd_network_get_dhcp_lease(unsigned index, sd_dhcp_lease **ret);
 /* Returns true if link is configured to respect DNS entries received by DHCP */
 int sd_network_dhcp_use_dns(unsigned index);
 
+/* Returns true if link is configured to respect NTP entries received by DHCP */
+int sd_network_dhcp_use_ntp(unsigned index);
+
 /* Get IPv4 DNS entries statically configured for the link */
 int sd_network_get_dns(unsigned index, struct in_addr **addr, size_t *addr_size);
 
+/* Get IPv4 NTP entries statically configured for the link */
+int sd_network_get_ntp(unsigned index, struct in_addr **addr, size_t *addr_size);
+
 /* Get IPv6 DNS entries statically configured for the link */
 int sd_network_get_dns6(unsigned index, struct in6_addr **addr, size_t *addr_size);
 
+/* Get IPv6 NTP entries statically configured for the link */
+int sd_network_get_ntp6(unsigned index, struct in6_addr **addr, size_t *addr_size);
+
 /* Get all network interfaces' indices, and store them in *indices. Returns
  * the number of indices. If indices is NULL, only returns the number of indices. */
 int sd_network_get_ifindices(unsigned **indices);



More information about the systemd-commits mailing list