summaryrefslogtreecommitdiff
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
parent332bc31992acffc6f32e194c0122e01607bd0e27 (diff)
networkd: hardcode a set of default dns servers
Similarly to NTP servers, this can be set at compile-time.
-rw-r--r--configure.ac11
-rw-r--r--src/network/networkd-manager.c48
-rw-r--r--src/network/networkd.h1
3 files changed, 60 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac
index 0a4e901d75..0ceaf51719 100644
--- a/configure.ac
+++ b/configure.ac
@@ -877,6 +877,7 @@ fi
AM_CONDITIONAL(ENABLE_POLKIT, [test "x$have_polkit" = "xyes"])
# ------------------------------------------------------------------------------
+have_networkd=no
AC_ARG_ENABLE(networkd, AS_HELP_STRING([--disable-networkd], [disable networkd]))
if test "x$enable_networkd" != "xno"; then
AC_DEFINE(ENABLE_NETWORKD, 1, [Define if networkd support is to be enabled])
@@ -886,6 +887,15 @@ AS_IF([test "x$have_networkd" = "xyes" -a "x$have_kmod" != "xyes"],
[AC_MSG_ERROR([networkd requires kmod])])
AM_CONDITIONAL(ENABLE_NETWORKD, [test "x$have_networkd" = "xyes"])
+AC_ARG_WITH(dns-servers,
+ AS_HELP_STRING([--with-dns-servers=DNSSERVERS],
+ [Space-separated list of default DNS servers]),
+ [DNS_SERVERS="$withval"],
+ [DNS_SERVERS="8.8.8.8 8.8.4.4"])
+
+AC_DEFINE_UNQUOTED(DNS_SERVERS, ["$DNS_SERVERS"], [Default DNS Servers])
+AC_SUBST(DNS_SERVERS)
+
# ------------------------------------------------------------------------------
have_efi=no
AC_ARG_ENABLE(efi, AS_HELP_STRING([--disable-efi], [disable EFI support]))
@@ -1189,6 +1199,7 @@ AC_MSG_RESULT([
time epoch: ${TIME_EPOCH}
localed: ${have_localed}
networkd: ${have_networkd}
+ default DNS servers: ${DNS_SERVERS}
coredump: ${have_coredump}
polkit: ${have_polkit}
efi: ${have_efi}
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;