diff options
author | Tom Gundersen <teg@jklm.no> | 2014-07-23 23:03:50 +0200 |
---|---|---|
committer | Tom Gundersen <teg@jklm.no> | 2014-07-23 23:54:52 +0200 |
commit | 6f4dedb250f2d607eceefaa491f338becbeee7c0 (patch) | |
tree | 88ee8549eeb089e853ffce1640f9cb23705a3a5a /src/network | |
parent | 6073b6f26ab9fc6bf335faa7073ec443eef093fd (diff) |
sd-network: expose DNS/NTP servers as strings
This avoids having to distinguish between IPv4 and IPv6, allowing us
to keep their internal orderings. The consumers now has to turn the
strings into addresses.
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/sd-network.c | 67 |
1 files changed, 18 insertions, 49 deletions
diff --git a/src/network/sd-network.c b/src/network/sd-network.c index 91d6275056..bfb8321c87 100644 --- a/src/network/sd-network.c +++ b/src/network/sd-network.c @@ -134,12 +134,13 @@ _public_ int sd_network_get_dhcp_lease(int ifindex, sd_dhcp_lease **ret) { return 0; } -static int network_get_in_addr(const char *key, int ifindex, struct in_addr **addr) { +static int network_get_strv(const char *key, int ifindex, char ***ret) { _cleanup_free_ char *p = NULL, *s = NULL; + _cleanup_strv_free_ char **a = NULL; int r; assert_return(ifindex > 0, -EINVAL); - assert_return(addr, -EINVAL); + assert_return(ret, -EINVAL); if (asprintf(&p, "/run/systemd/netif/links/%d", ifindex) < 0) return -ENOMEM; @@ -147,63 +148,31 @@ static int network_get_in_addr(const char *key, int ifindex, struct in_addr **ad r = parse_env_file(p, NEWLINE, key, &s, NULL); if (r < 0) return r; - else if (!s) - return -EIO; - - return deserialize_in_addrs(addr, s); -} + else if (!s) { + *ret = NULL; -_public_ int sd_network_get_dns(int ifindex, struct in_addr **addr) { - return network_get_in_addr("DNS", ifindex, addr); -} - -static int network_get_in6_addr(const char *key, int ifindex, struct in6_addr **addr) { - _cleanup_free_ char *p = NULL, *s = NULL; - int r; - - assert_return(ifindex > 0, -EINVAL); - assert_return(addr, -EINVAL); + return 0; + } - if (asprintf(&p, "/run/systemd/netif/links/%d", ifindex) < 0) + a = strv_split(s, " "); + if (!a) return -ENOMEM; - r = parse_env_file(p, NEWLINE, key, &s, NULL); - if (r < 0) - return r; - else if (!s) - return -EIO; - - return deserialize_in6_addrs(addr, s); -} - -_public_ int sd_network_get_dns6(int ifindex, struct in6_addr **addr) { - return network_get_in6_addr("DNS", ifindex, addr); -} + strv_uniq(a); + r = strv_length(a); -static int network_get_boolean(const char *key, int ifindex) { - _cleanup_free_ char *p = NULL, *s = NULL; - int r; - - assert_return(ifindex > 0, -EINVAL); - - if (asprintf(&p, "/run/systemd/netif/links/%d", ifindex) < 0) - return -ENOMEM; - - r = parse_env_file(p, NEWLINE, key, &s, NULL); - if (r < 0) - return r; - else if (!s) - return false; + *ret = a; + a = NULL; - return parse_boolean(s); + return r; } -_public_ int sd_network_dhcp_use_dns(int ifindex) { - return network_get_boolean("DHCP_USE_DNS", ifindex); +_public_ int sd_network_get_dns(int ifindex, char ***ret) { + return network_get_strv("DNS", ifindex, ret); } -_public_ int sd_network_dhcp_use_ntp(int ifindex) { - return network_get_boolean("DHCP_USE_NTP", ifindex); +_public_ int sd_network_get_ntp(int ifindex, char ***ret) { + return network_get_strv("NTP", ifindex, ret); } static inline int MONITOR_TO_FD(sd_network_monitor *m) { |