summaryrefslogtreecommitdiff
path: root/src/network/networkd-manager.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/network/networkd-manager.c')
-rw-r--r--src/network/networkd-manager.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c
index cc55f9a17a..1b14e9d4f1 100644
--- a/src/network/networkd-manager.c
+++ b/src/network/networkd-manager.c
@@ -25,6 +25,7 @@
#include "path-util.h"
#include "networkd.h"
+#include "network-internal.h"
#include "libudev-private.h"
#include "udev-util.h"
#include "rtnl-util.h"
@@ -74,6 +75,41 @@ static int setup_signals(Manager *m) {
return 0;
}
+static int set_fallback_dns(Manager *m, const char *string) {
+ char *word, *state;
+ size_t length;
+ int r;
+
+ assert(m);
+ assert(string);
+
+ FOREACH_WORD_QUOTED(word, length, string, state) {
+ _cleanup_address_free_ Address *address = NULL;
+ Address *tail;
+ _cleanup_free_ char *addrstr = NULL;
+
+ r = address_new_dynamic(&address);
+ if (r < 0)
+ return r;
+
+ addrstr = strndup(word, length);
+ if (!addrstr)
+ return -ENOMEM;
+
+ r = net_parse_inaddr(addrstr, &address->family, &address->in_addr);
+ if (r < 0) {
+ log_debug("Ignoring invalid DNS address '%s'", addrstr);
+ continue;
+ }
+
+ LIST_FIND_TAIL(addresses, m->fallback_dns, tail);
+ LIST_INSERT_AFTER(addresses, m->fallback_dns, tail, address);
+ address = NULL;
+ }
+
+ return 0;
+}
+
int manager_new(Manager **ret) {
_cleanup_manager_free_ Manager *m = NULL;
int r;
@@ -86,6 +122,10 @@ int manager_new(Manager **ret) {
if (!m->state_file)
return -ENOMEM;
+ r = set_fallback_dns(m, DNS_SERVERS);
+ if (r < 0)
+ return r;
+
r = sd_event_default(&m->event);
if (r < 0)
return r;
@@ -494,6 +534,14 @@ int manager_update_resolv_conf(Manager *m) {
}
}
+ if (!count) {
+ Address *address;
+
+ LIST_FOREACH(addresses, address, m->fallback_dns)
+ append_dns(f, &address->in_addr.in,
+ address->family, &count);
+ }
+
fflush(f);
if (ferror(f) || rename(temp_path, "/run/systemd/network/resolv.conf") < 0) {