summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2014-05-16 19:44:22 +0200
committerTom Gundersen <teg@jklm.no>2014-05-16 19:48:25 +0200
commit2dcf7ec6ec0c28297311108acba119cd6e055e64 (patch)
tree1af3869990bd995f5826e7387887bfc73d54fd5e /src
parentd4920165fe753751aaa274fdc568927d26284eea (diff)
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.
Diffstat (limited to 'src')
-rw-r--r--src/network/.gitignore2
-rw-r--r--src/network/networkd-manager.c65
-rw-r--r--src/network/networkd.h6
3 files changed, 73 insertions, 0 deletions
diff --git a/src/network/.gitignore b/src/network/.gitignore
index 8858596489..04bce2e8b4 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 013b1dc975..ad36553f2b 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 ebb3075534..eaaf2593f9 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);