[systemd-commits] configure.ac src/network

Tom Gundersen tomegun at kemper.freedesktop.org
Fri May 16 08:21:02 PDT 2014


 configure.ac                   |   11 +++++++++
 src/network/networkd-manager.c |   48 +++++++++++++++++++++++++++++++++++++++++
 src/network/networkd.h         |    1 
 3 files changed, 60 insertions(+)

New commits:
commit e16cb2e4efaba83f47da8355adc65fd83bbe8327
Author: Tom Gundersen <teg at jklm.no>
Date:   Fri May 16 15:24:09 2014 +0200

    networkd: hardcode a set of default dns servers
    
    Similarly to NTP servers, this can be set at compile-time.

diff --git a/configure.ac b/configure.ac
index 0a4e901..0ceaf51 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 cc55f9a..1b14e9d 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 e2e15b5..3b29842 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;



More information about the systemd-commits mailing list