diff options
author | Tom Gundersen <teg@jklm.no> | 2014-05-18 22:05:09 +0200 |
---|---|---|
committer | Tom Gundersen <teg@jklm.no> | 2014-05-19 18:14:56 +0200 |
commit | 7dbf94a9c4dcdf9b56384e66eb2652fb61da5063 (patch) | |
tree | 9fbb52f5c4514d533872f752bec3dc7232b25e8f | |
parent | 7374f9d87c710bc1ae3bfdb78a191a31c72d29b9 (diff) |
sd-network: expose DNS information
-rw-r--r-- | src/network/sd-network.c | 59 | ||||
-rw-r--r-- | src/systemd/sd-network.h | 9 |
2 files changed, 68 insertions, 0 deletions
diff --git a/src/network/sd-network.c b/src/network/sd-network.c index 492e97c73f..64e3aaae48 100644 --- a/src/network/sd-network.c +++ b/src/network/sd-network.c @@ -32,6 +32,7 @@ #include "strv.h" #include "fileio.h" #include "sd-network.h" +#include "network-internal.h" #include "dhcp-lease-internal.h" static int link_get_flags(unsigned index, unsigned *flags) { @@ -169,6 +170,64 @@ _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) { + _cleanup_free_ char *p = NULL, *s = NULL; + int r; + + assert_return(index, -EINVAL); + assert_return(addr, -EINVAL); + assert_return(addr_size, -EINVAL); + + if (asprintf(&p, "/run/systemd/network/links/%u", index) < 0) + return -ENOMEM; + + r = parse_env_file(p, NEWLINE, "DNS", &s, NULL); + if (r < 0) + return r; + else if (!s) + return -EIO; + + return deserialize_in_addrs(addr, addr_size, s); +} + +_public_ int sd_network_get_dns6(unsigned index, struct in6_addr **addr, size_t *addr_size) { + _cleanup_free_ char *p = NULL, *s = NULL; + int r; + + assert_return(index, -EINVAL); + assert_return(addr, -EINVAL); + assert_return(addr_size, -EINVAL); + + if (asprintf(&p, "/run/systemd/network/links/%u", index) < 0) + return -ENOMEM; + + r = parse_env_file(p, NEWLINE, "DNS", &s, NULL); + if (r < 0) + return r; + else if (!s) + return -EIO; + + return deserialize_in6_addrs(addr, addr_size, s); +} + +_public_ int sd_network_dhcp_use_dns(unsigned index) { + _cleanup_free_ char *p = NULL, *s = NULL; + int r; + + assert_return(index, -EINVAL); + + if (asprintf(&p, "/run/systemd/network/links/%u", index) < 0) + return -ENOMEM; + + r = parse_env_file(p, NEWLINE, "DHCP_USE_DNS", &s, NULL); + if (r < 0) + return r; + else if (!s) + return -EIO; + + return parse_boolean(s); +} + _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 d0b2ea3576..860325a6ed 100644 --- a/src/systemd/sd-network.h +++ b/src/systemd/sd-network.h @@ -80,6 +80,15 @@ int sd_network_link_is_loopback(unsigned index); /* Get DHCPv4 lease from ifindex. */ 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); + +/* 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 IPv6 DNS entries statically configured for the link */ +int sd_network_get_dns6(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); |