summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2014-05-16 15:24:09 +0200
committerTom Gundersen <teg@jklm.no>2014-05-16 17:19:04 +0200
commite16cb2e4efaba83f47da8355adc65fd83bbe8327 (patch)
treeda2d956901276b76f543d62c47b3cf185ad45361 /src
parent332bc31992acffc6f32e194c0122e01607bd0e27 (diff)
networkd: hardcode a set of default dns servers
Similarly to NTP servers, this can be set at compile-time.
Diffstat (limited to 'src')
-rw-r--r--src/network/networkd-manager.c48
-rw-r--r--src/network/networkd.h1
2 files changed, 49 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) {
diff --git a/src/network/networkd.h b/src/network/networkd.h
index e2e15b56bb..3b29842f19 100644
--- a/src/network/networkd.h
+++ b/src/network/networkd.h
@@ -254,6 +254,7 @@ struct Manager {
Hashmap *links;
Hashmap *netdevs;
LIST_HEAD(Network, networks);
+ LIST_HEAD(Address, fallback_dns);
usec_t network_dirs_ts_usec;
struct kmod_ctx *kmod_ctx;