summaryrefslogtreecommitdiff
path: root/src/network/sd-network.c
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2014-05-19 18:42:14 +0200
committerTom Gundersen <teg@jklm.no>2014-05-19 18:42:14 +0200
commitbcb7a07e0a785bda1eed658e984ff6b4a11cba9a (patch)
treeca7b9498783bac32e153b2059cea24863a6642e4 /src/network/sd-network.c
parentd408b506814a0f99590d946b3bf99b57ba78336b (diff)
networkd/sd-network: expose statically configured NTP servers
Diffstat (limited to 'src/network/sd-network.c')
-rw-r--r--src/network/sd-network.c36
1 files changed, 30 insertions, 6 deletions
diff --git a/src/network/sd-network.c b/src/network/sd-network.c
index 7ae15ed6ae..e7cda0d510 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;