summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/network/sd-network.c67
-rw-r--r--src/resolve/resolved-link.c42
-rw-r--r--src/systemd/sd-network.h16
3 files changed, 37 insertions, 88 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) {
diff --git a/src/resolve/resolved-link.c b/src/resolve/resolved-link.c
index 16f41a2604..3c6c757722 100644
--- a/src/resolve/resolved-link.c
+++ b/src/resolve/resolved-link.c
@@ -133,49 +133,33 @@ int link_update_rtnl(Link *l, sd_rtnl_message *m) {
}
static int link_update_dns_servers(Link *l) {
- _cleanup_free_ struct in_addr *nameservers = NULL;
- _cleanup_free_ struct in6_addr *nameservers6 = NULL;
+ _cleanup_strv_free_ char **nameservers = NULL;
+ char **nameserver;
DnsServer *s, *nx;
- int r, n, i;
+ int r;
assert(l);
LIST_FOREACH(servers, s, l->dns_servers)
s->marked = true;
- n = sd_network_get_dns(l->ifindex, &nameservers);
- if (n < 0) {
- r = n;
+ r = sd_network_get_dns(l->ifindex, &nameservers);
+ if (r < 0)
goto clear;
- }
-
- for (i = 0; i < n; i++) {
- union in_addr_union a = { .in = nameservers[i] };
-
- s = link_find_dns_server(l, AF_INET, &a);
- if (s)
- s->marked = false;
- else {
- r = dns_server_new(l->manager, NULL, l, AF_INET, &a);
- if (r < 0)
- goto clear;
- }
- }
- n = sd_network_get_dns6(l->ifindex, &nameservers6);
- if (n < 0) {
- r = n;
- goto clear;
- }
+ STRV_FOREACH(nameserver, nameservers) {
+ union in_addr_union a;
+ int family;
- for (i = 0; i < n; i++) {
- union in_addr_union a = { .in6 = nameservers6[i] };
+ r = in_addr_from_string_auto(*nameserver, &family, &a);
+ if (r < 0)
+ goto clear;
- s = link_find_dns_server(l, AF_INET6, &a);
+ s = link_find_dns_server(l, family, &a);
if (s)
s->marked = false;
else {
- r = dns_server_new(l->manager, NULL, l, AF_INET6, &a);
+ r = dns_server_new(l->manager, NULL, l, family, &a);
if (r < 0)
goto clear;
}
diff --git a/src/systemd/sd-network.h b/src/systemd/sd-network.h
index e4547057f1..ec01e07e85 100644
--- a/src/systemd/sd-network.h
+++ b/src/systemd/sd-network.h
@@ -76,17 +76,13 @@ int sd_network_get_operational_state(char **state);
/* Get DHCPv4 lease from ifindex. */
int sd_network_get_dhcp_lease(int ifindex, sd_dhcp_lease **ret);
-/* Returns true if link is configured to respect DNS entries received by DHCP */
-int sd_network_dhcp_use_dns(int ifindex);
+/* Get DNS entries for a given link. These are string representations of
+ * IP addresses */
+int sd_network_get_dns(int ifindex, char ***addr);
-/* Returns true if link is configured to respect NTP entries received by DHCP */
-int sd_network_dhcp_use_ntp(int ifindex);
-
-/* Get IPv4 DNS entries statically configured for the link */
-int sd_network_get_dns(int ifindex, struct in_addr **addr);
-
-/* Get IPv6 DNS entries statically configured for the link */
-int sd_network_get_dns6(int ifindex, struct in6_addr **addr);
+/* Get NTP entries for a given link. These are domain names or string
+ * reperesentations of IP addresses */
+int sd_network_get_ntp(int ifindex, char ***addr);
/* Monitor object */
typedef struct sd_network_monitor sd_network_monitor;