[systemd-commits] 3 commits - configure.ac Makefile.am src/network

Tom Gundersen tomegun at kemper.freedesktop.org
Fri May 16 10:48:42 PDT 2014


 Makefile.am                    |   33 ++++++++++++-------
 configure.ac                   |    2 -
 src/network/.gitignore         |    2 +
 src/network/networkd-address.c |    8 +++-
 src/network/networkd-manager.c |   68 +++++++++++++++++++++++++++++++++++++++--
 src/network/networkd-network.c |   10 +-----
 src/network/networkd.h         |    8 ++++
 7 files changed, 105 insertions(+), 26 deletions(-)

New commits:
commit 2dcf7ec6ec0c28297311108acba119cd6e055e64
Author: Tom Gundersen <teg at jklm.no>
Date:   Fri May 16 19:44:22 2014 +0200

    networkd: manager - read fallback DNS servers from config file
    
    We will still use the compiled-in defaults if no DNS entry exists in the config file.

diff --git a/Makefile.am b/Makefile.am
index ddfec1b..f6c195b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -4223,7 +4223,8 @@ libsystemd_networkd_core_la_SOURCES = \
 
 nodist_libsystemd_networkd_core_la_SOURCES = \
 	src/network/networkd-network-gperf.c \
-	src/network/networkd-netdev-gperf.c
+	src/network/networkd-netdev-gperf.c \
+	src/network/networkd-gperf.c
 
 libsystemd_networkd_core_la_LIBADD = \
 	libudev-internal.la \
@@ -4232,14 +4233,6 @@ libsystemd_networkd_core_la_LIBADD = \
 	libsystemd-label.la \
 	libsystemd-shared.la
 
-nodist_systemunit_DATA += \
-	units/systemd-networkd.service \
-	units/systemd-networkd-wait-online.service
-
-GENERAL_ALIASES += \
-	$(systemunitdir)/systemd-networkd.service $(pkgsysconfdir)/system/multi-user.target.wants/systemd-networkd.service \
-	$(systemunitdir)/systemd-networkd.service $(pkgsysconfdir)/system/network-online.target.wants/systemd-networkd-wait-online.service
-
 rootlibexec_PROGRAMS += \
 	systemd-networkd-wait-online
 
@@ -4269,15 +4262,30 @@ test_network_LDADD = \
 tests += \
 	test-network
 
+nodist_systemunit_DATA += \
+	units/systemd-networkd.service \
+	units/systemd-networkd-wait-online.service
+
+GENERAL_ALIASES += \
+	$(systemunitdir)/systemd-networkd.service $(pkgsysconfdir)/system/multi-user.target.wants/systemd-networkd.service \
+	$(systemunitdir)/systemd-networkd.service $(pkgsysconfdir)/system/network-online.target.wants/systemd-networkd-wait-online.service
+
+nodist_pkgsysconf_DATA += \
+	src/network/networkd.conf
+
 EXTRA_DIST += \
 	src/network/networkd-network-gperf.gperf \
 	src/network/networkd-netdev-gperf.gperf \
+	src/network/networkd-gperf.gperf \
 	units/systemd-networkd.service.in \
-	units/systemd-networkd-wait-online.service.in
+	units/systemd-networkd-wait-online.service.in \
+	src/network/networkd.conf.in
 
 CLEANFILES += \
 	src/network/networkd-network-gperf.c \
-	src/network/networkd-netdev-gperf.c
+	src/network/networkd-netdev-gperf.c \
+	src/network/networkd-gperf.c \
+	src/network/networkd.conf
 endif
 
 # ------------------------------------------------------------------------------
@@ -4831,7 +4839,8 @@ substitutions = \
        '|RC_LOCAL_SCRIPT_PATH_STOP=$(RC_LOCAL_SCRIPT_PATH_STOP)|' \
        '|PYTHON=$(PYTHON)|' \
        '|PYTHON_BINARY=$(PYTHON_BINARY)|' \
-       '|NTP_SERVERS=$(NTP_SERVERS)|'
+       '|NTP_SERVERS=$(NTP_SERVERS)|' \
+       '|DNS_SERVERS=$(DNS_SERVERS)|'
 
 SED_PROCESS = \
 	$(AM_V_GEN)$(MKDIR_P) $(dir $@) && \
diff --git a/src/network/.gitignore b/src/network/.gitignore
index 8858596..04bce2e 100644
--- a/src/network/.gitignore
+++ b/src/network/.gitignore
@@ -1,2 +1,4 @@
 /networkd-network-gperf.c
 /networkd-netdev-gperf.c
+/networkd-gperf.c
+/networkd.conf
diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c
index 013b1dc..ad36553 100644
--- a/src/network/networkd-manager.c
+++ b/src/network/networkd-manager.c
@@ -23,6 +23,7 @@
 #include <linux/if.h>
 #include <libkmod.h>
 
+#include "conf-parser.h"
 #include "path-util.h"
 #include "networkd.h"
 #include "network-internal.h"
@@ -110,6 +111,60 @@ static int set_fallback_dns(Manager *m, const char *string) {
         return 0;
 }
 
+int config_parse_dnsv(
+                const char *unit,
+                const char *filename,
+                unsigned line,
+                const char *section,
+                unsigned section_line,
+                const char *lvalue,
+                int ltype,
+                const char *rvalue,
+                void *data,
+                void *userdata) {
+
+        Manager *m = userdata;
+        Address *address;
+
+        assert(filename);
+        assert(lvalue);
+        assert(rvalue);
+        assert(m);
+
+        while ((address = m->fallback_dns)) {
+                LIST_REMOVE(addresses, m->fallback_dns, address);
+                address_free(address);
+        }
+
+        set_fallback_dns(m, rvalue);
+
+        return 0;
+}
+
+static int manager_parse_config_file(Manager *m) {
+        static const char fn[] = "/etc/systemd/networkd.conf";
+        _cleanup_fclose_ FILE *f = NULL;
+        int r;
+
+        assert(m);
+
+        f = fopen(fn, "re");
+        if (!f) {
+                if (errno == ENOENT)
+                        return 0;
+
+                log_warning("Failed to open configuration file %s: %m", fn);
+                return -errno;
+        }
+
+        r = config_parse(NULL, fn, f, "Network\0", config_item_perf_lookup,
+                         (void*) networkd_gperf_lookup, false, false, m);
+        if (r < 0)
+                log_warning("Failed to parse configuration file: %s", strerror(-r));
+
+        return r;
+}
+
 int manager_new(Manager **ret) {
         _cleanup_manager_free_ Manager *m = NULL;
         int r;
@@ -126,6 +181,10 @@ int manager_new(Manager **ret) {
         if (r < 0)
                 return r;
 
+        r = manager_parse_config_file(m);
+        if (r < 0)
+                return r;
+
         r = sd_event_default(&m->event);
         if (r < 0)
                 return r;
@@ -182,6 +241,7 @@ void manager_free(Manager *m) {
         Network *network;
         NetDev *netdev;
         Link *link;
+        Address *address;
 
         if (!m)
                 return;
@@ -197,6 +257,11 @@ void manager_free(Manager *m) {
         sd_event_source_unref(m->sigint_event_source);
         sd_event_unref(m->event);
 
+        while ((address = m->fallback_dns)) {
+                LIST_REMOVE(addresses, m->fallback_dns, address);
+                address_free(address);
+        }
+
         while ((link = hashmap_first(m->links)))
                 link_unref(link);
         hashmap_free(m->links);
diff --git a/src/network/networkd.h b/src/network/networkd.h
index ebb3075..eaaf259 100644
--- a/src/network/networkd.h
+++ b/src/network/networkd.h
@@ -282,6 +282,12 @@ int manager_save(Manager *m);
 DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free);
 #define _cleanup_manager_free_ _cleanup_(manager_freep)
 
+const struct ConfigPerfItem* networkd_gperf_lookup(const char *key, unsigned length);
+
+int config_parse_dnsv(const char *unit, const char *filename, unsigned line,
+                     const char *section, unsigned section_line, const char *lvalue,
+                     int ltype, const char *rvalue, void *data, void *userdata);
+
 /* NetDev */
 
 int netdev_load(Manager *manager);

commit d4920165fe753751aaa274fdc568927d26284eea
Author: Tom Gundersen <teg at jklm.no>
Date:   Fri May 16 19:43:12 2014 +0200

    networkd: network - store DNS servers in List rather than Set
    
    This way we preserve the order of preference.

diff --git a/src/network/networkd-address.c b/src/network/networkd-address.c
index e6e3f8f..6977fe7 100644
--- a/src/network/networkd-address.c
+++ b/src/network/networkd-address.c
@@ -313,7 +313,8 @@ int config_parse_dns(const char *unit,
                 const char *rvalue,
                 void *data,
                 void *userdata) {
-        Set **dns = data;
+        Network *network = userdata;
+        Address *tail;
         _cleanup_address_free_ Address *n = NULL;
         int r;
 
@@ -321,7 +322,7 @@ int config_parse_dns(const char *unit,
         assert(section);
         assert(lvalue);
         assert(rvalue);
-        assert(data);
+        assert(network);
 
         r = address_new_dynamic(&n);
         if (r < 0)
@@ -334,7 +335,8 @@ int config_parse_dns(const char *unit,
                 return 0;
         }
 
-        set_put(*dns, n);
+        LIST_FIND_TAIL(addresses, network->dns, tail);
+        LIST_INSERT_AFTER(addresses, network->dns, tail, n);
         n = NULL;
 
         return 0;
diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c
index 1b14e9d..013b1dc 100644
--- a/src/network/networkd-manager.c
+++ b/src/network/networkd-manager.c
@@ -525,9 +525,8 @@ int manager_update_resolv_conf(Manager *m) {
         HASHMAP_FOREACH(link, m->links, i) {
                 if (link->network && link->network->dns) {
                         Address *address;
-                        Iterator j;
 
-                        SET_FOREACH(address, link->network->dns, j) {
+                        LIST_FOREACH(addresses, address, link->network->dns) {
                                 append_dns(f, &address->in_addr.in,
                                            address->family, &count);
                         }
diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c
index 2a68d3e..12107c9 100644
--- a/src/network/networkd-network.c
+++ b/src/network/networkd-network.c
@@ -77,10 +77,6 @@ static int network_load_one(Manager *manager, const char *filename) {
         if (!network->routes_by_section)
                 return log_oom();
 
-        network->dns = set_new(NULL, NULL);
-        if (!network->dns)
-                return log_oom();
-
         network->filename = strdup(filename);
         if (!network->filename)
                 return log_oom();
@@ -164,10 +160,10 @@ void network_free(Network *network) {
 
         free(network->description);
 
-        SET_FOREACH(address, network->dns, i)
+        while ((address = network->dns)) {
+                LIST_REMOVE(addresses, network->dns, address);
                 address_free(address);
-
-        set_free(network->dns);
+        }
 
         netdev_unref(network->bridge);
 
diff --git a/src/network/networkd.h b/src/network/networkd.h
index 3b29842..ebb3075 100644
--- a/src/network/networkd.h
+++ b/src/network/networkd.h
@@ -150,7 +150,7 @@ struct Network {
         Hashmap *addresses_by_section;
         Hashmap *routes_by_section;
 
-        Set *dns;
+        LIST_HEAD(Address, dns);
 
         LIST_FIELDS(Network, networks);
 };

commit 7b4d79683998a78d6e123dd034b1e06b74d8030b
Author: Tom Gundersen <teg at jklm.no>
Date:   Fri May 16 17:34:43 2014 +0200

    networkd: also add IPv6 DNS servers by default

diff --git a/configure.ac b/configure.ac
index 0ceaf51..30ef33d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -891,7 +891,7 @@ 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"])
+        [DNS_SERVERS="8.8.8.8 8.8.4.4 2001:4860:4860::8888 2001:4860:4860::8844"])
 
 AC_DEFINE_UNQUOTED(DNS_SERVERS, ["$DNS_SERVERS"], [Default DNS Servers])
 AC_SUBST(DNS_SERVERS)



More information about the systemd-commits mailing list