summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/libsystemd/sd-network/sd-network.c4
-rw-r--r--src/network/networkd-manager.c73
-rw-r--r--src/systemd/sd-network.h7
3 files changed, 53 insertions, 31 deletions
diff --git a/src/libsystemd/sd-network/sd-network.c b/src/libsystemd/sd-network/sd-network.c
index 5d28af0344..3a3f53576f 100644
--- a/src/libsystemd/sd-network/sd-network.c
+++ b/src/libsystemd/sd-network/sd-network.c
@@ -92,6 +92,10 @@ _public_ int sd_network_get_ntp(char ***ret) {
return network_get_strv("NTP", ret);
}
+_public_ int sd_network_get_domains(char ***ret) {
+ return network_get_strv("DOMAINS", ret);
+}
+
_public_ int sd_network_link_get_setup_state(int ifindex, char **state) {
_cleanup_free_ char *s = NULL, *p = NULL;
int r;
diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c
index e3d72edece..f2fe5d5443 100644
--- a/src/network/networkd-manager.c
+++ b/src/network/networkd-manager.c
@@ -450,8 +450,27 @@ static int set_put_in_addrv(Set *s, const struct in_addr *addresses, int n) {
return c;
}
+static void print_string_set(FILE *f, const char *field, Set *s) {
+ bool space = false;
+ Iterator i;
+ char *p;
+
+ if (set_isempty(s))
+ return;
+
+ fputs(field, f);
+
+ SET_FOREACH(p, s, i) {
+ if (space)
+ fputc(' ', f);
+ fputs(p, f);
+ space = true;
+ }
+ fputc('\n', f);
+}
+
int manager_save(Manager *m) {
- _cleanup_set_free_free_ Set *dns = NULL, *ntp = NULL;
+ _cleanup_set_free_free_ Set *dns = NULL, *ntp = NULL, *domains = NULL;
Link *link;
Iterator i;
_cleanup_free_ char *temp_path = NULL;
@@ -472,6 +491,10 @@ int manager_save(Manager *m) {
if (!ntp)
return -ENOMEM;
+ domains = set_new(string_hash_func, string_compare_func);
+ if (!domains)
+ return -ENOMEM;
+
HASHMAP_FOREACH(link, m->links, i) {
if (link->flags & IFF_LOOPBACK)
continue;
@@ -491,6 +514,10 @@ int manager_save(Manager *m) {
if (r < 0)
return r;
+ r = set_put_strdupv(domains, link->network->domains);
+ if (r < 0)
+ return r;
+
if (!link->dhcp_lease)
continue;
@@ -503,7 +530,7 @@ int manager_save(Manager *m) {
r = set_put_in_addrv(dns, addresses, r);
if (r < 0)
return r;
- } else if (r != -ENOENT)
+ } else if (r < 0 && r != -ENOENT)
return r;
}
@@ -515,6 +542,18 @@ int manager_save(Manager *m) {
r = set_put_in_addrv(ntp, addresses, r);
if (r < 0)
return r;
+ } else if (r < 0 && r != -ENOENT)
+ return r;
+ }
+
+ if (link->network->dhcp_domains) {
+ const char *domainname;
+
+ r = sd_dhcp_lease_get_domainname(link->dhcp_lease, &domainname);
+ if (r >= 0) {
+ r = set_put_strdup(domains, domainname);
+ if (r < 0)
+ return r;
} else if (r != -ENOENT)
return r;
}
@@ -533,33 +572,9 @@ int manager_save(Manager *m) {
"# This is private data. Do not parse.\n"
"OPER_STATE=%s\n", operstate_str);
- if (!set_isempty(dns)) {
- bool space = false;
- char *p;
-
- fputs("DNS=", f);
- SET_FOREACH(p, dns, i) {
- if (space)
- fputc(' ', f);
- fputs(p, f);
- space = true;
- }
- fputc('\n', f);
- }
-
- if (!set_isempty(ntp)) {
- bool space = false;
- char *p;
-
- fputs("NTP=", f);
- SET_FOREACH(p, ntp, i) {
- if (space)
- fputc(' ', f);
- fputs(p, f);
- space = true;
- }
- fputc('\n', f);
- }
+ print_string_set(f, "DNS=", dns);
+ print_string_set(f, "NTP=", ntp);
+ print_string_set(f, "DOMAINS=", domains);
r = fflush_and_check(f);
if (r < 0)
diff --git a/src/systemd/sd-network.h b/src/systemd/sd-network.h
index 52e398a08d..b2086c7836 100644
--- a/src/systemd/sd-network.h
+++ b/src/systemd/sd-network.h
@@ -58,11 +58,14 @@ int sd_network_get_operational_state(char **state);
/* Get DNS entries for all links. These are string representations of
* IP addresses */
-int sd_network_get_dns(char ***addr);
+int sd_network_get_dns(char ***dns);
/* Get NTP entries for all links. These are domain names or string
* reperesentations of IP addresses */
-int sd_network_get_ntp(char ***addr);
+int sd_network_get_ntp(char ***ntp);
+
+/* Get the search/routing domains for all links. */
+int sd_network_get_domains(char ***domains);
/* Get setup state from ifindex.
* Possible states: