summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2014-05-18 22:10:48 +0200
committerTom Gundersen <teg@jklm.no>2014-05-19 18:14:56 +0200
commit091a364c802e34a58f3260c9cb5db9b75c62215c (patch)
tree35b22463dde65c3fcaec38653fe757ae30152b15 /src/network
parent7dbf94a9c4dcdf9b56384e66eb2652fb61da5063 (diff)
resolved: add daemon to manage resolv.conf
Also remove the equivalent functionality from networkd.
Diffstat (limited to 'src/network')
-rw-r--r--src/network/.gitignore2
-rw-r--r--src/network/networkd-gperf.gperf17
-rw-r--r--src/network/networkd-link.c11
-rw-r--r--src/network/networkd-manager.c201
-rw-r--r--src/network/networkd-network.c2
-rw-r--r--src/network/networkd.c8
-rw-r--r--src/network/networkd.conf.in11
-rw-r--r--src/network/networkd.h8
8 files changed, 2 insertions, 258 deletions
diff --git a/src/network/.gitignore b/src/network/.gitignore
index 04bce2e8b4..8858596489 100644
--- a/src/network/.gitignore
+++ b/src/network/.gitignore
@@ -1,4 +1,2 @@
/networkd-network-gperf.c
/networkd-netdev-gperf.c
-/networkd-gperf.c
-/networkd.conf
diff --git a/src/network/networkd-gperf.gperf b/src/network/networkd-gperf.gperf
deleted file mode 100644
index a5dfc400ea..0000000000
--- a/src/network/networkd-gperf.gperf
+++ /dev/null
@@ -1,17 +0,0 @@
-%{
-#include <stddef.h>
-#include "conf-parser.h"
-#include "networkd.h"
-%}
-struct ConfigPerfItem;
-%null_strings
-%language=ANSI-C
-%define slot-name section_and_lvalue
-%define hash-function-name networkd_gperf_hash
-%define lookup-function-name networkd_gperf_lookup
-%readonly-tables
-%omit-struct-type
-%struct-type
-%includes
-%%
-Network.DNS, config_parse_dnsv, 0, offsetof(Manager, fallback_dns)
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index 8ce2dbd39c..5a7472ba24 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -854,8 +854,6 @@ static int dhcp_lease_acquired(sd_dhcp_client *client, Link *link) {
struct in_addr netmask;
struct in_addr gateway;
unsigned prefixlen;
- struct in_addr *nameservers;
- size_t nameservers_size;
int r;
assert(client);
@@ -920,15 +918,6 @@ static int dhcp_lease_acquired(sd_dhcp_client *client, Link *link) {
link->dhcp_lease = lease;
- if (link->network->dhcp_dns) {
- r = sd_dhcp_lease_get_dns(lease, &nameservers, &nameservers_size);
- if (r >= 0) {
- r = manager_update_resolv_conf(link->manager);
- if (r < 0)
- log_error_link(link, "Failed to update resolv.conf");
- }
- }
-
if (link->network->dhcp_mtu) {
uint16_t mtu;
diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c
index ad36553f2b..2e3b4bb885 100644
--- a/src/network/networkd-manager.c
+++ b/src/network/networkd-manager.c
@@ -19,7 +19,7 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
-#include <resolv.h>
+#include <sys/socket.h>
#include <linux/if.h>
#include <libkmod.h>
@@ -76,95 +76,6 @@ 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 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;
@@ -177,14 +88,6 @@ int manager_new(Manager **ret) {
if (!m->state_file)
return -ENOMEM;
- r = set_fallback_dns(m, DNS_SERVERS);
- 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;
@@ -241,7 +144,6 @@ void manager_free(Manager *m) {
Network *network;
NetDev *netdev;
Link *link;
- Address *address;
if (!m)
return;
@@ -257,11 +159,6 @@ 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);
@@ -522,102 +419,6 @@ int manager_bus_listen(Manager *m) {
return 0;
}
-static void append_dns(FILE *f, struct in_addr *dns, unsigned char family, unsigned *count) {
- char buf[INET6_ADDRSTRLEN];
- const char *address;
-
- address = inet_ntop(family, dns, buf, INET6_ADDRSTRLEN);
- if (!address) {
- log_warning("Invalid DNS address. Ignoring.");
- return;
- }
-
- if (*count == MAXNS)
- fputs("# Too many DNS servers configured, the following entries "
- "will be ignored\n", f);
-
- fprintf(f, "nameserver %s\n", address);
-
- (*count) ++;
-}
-
-int manager_update_resolv_conf(Manager *m) {
- _cleanup_free_ char *temp_path = NULL;
- _cleanup_fclose_ FILE *f = NULL;
- Link *link;
- Iterator i;
- unsigned count = 0;
- const char *domainname = NULL;
- int r;
-
- assert(m);
-
- r = fopen_temporary("/run/systemd/network/resolv.conf", &f, &temp_path);
- if (r < 0)
- return r;
-
- fchmod(fileno(f), 0644);
-
- fputs("# This file is managed by systemd-networkd(8). Do not edit.\n#\n"
- "# Third party programs must not access this file directly, but\n"
- "# only through the symlink at /etc/resolv.conf. To manage\n"
- "# resolv.conf(5) in a different way, replace the symlink by a\n"
- "# static file or a different symlink.\n\n", f);
-
- HASHMAP_FOREACH(link, m->links, i) {
- if (link->dhcp_lease) {
- struct in_addr *nameservers;
- size_t nameservers_size;
-
- if (link->network->dhcp_dns) {
- r = sd_dhcp_lease_get_dns(link->dhcp_lease, &nameservers, &nameservers_size);
- if (r >= 0) {
- unsigned j;
-
- for (j = 0; j < nameservers_size; j++)
- append_dns(f, &nameservers[j], AF_INET, &count);
- }
- }
-
- if (link->network->dhcp_domainname && !domainname) {
- r = sd_dhcp_lease_get_domainname(link->dhcp_lease, &domainname);
- if (r >= 0)
- fprintf(f, "domain %s\n", domainname);
- }
- }
- }
-
- HASHMAP_FOREACH(link, m->links, i) {
- if (link->network && link->network->dns) {
- Address *address;
-
- LIST_FOREACH(addresses, address, link->network->dns) {
- append_dns(f, &address->in_addr.in,
- address->family, &count);
- }
- }
- }
-
- 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) {
- r = -errno;
- unlink("/run/systemd/network/resolv.conf");
- unlink(temp_path);
- return r;
- }
-
- return 0;
-}
-
int manager_save(Manager *m) {
Link *link;
Iterator i;
diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c
index 12107c9406..1b8856afeb 100644
--- a/src/network/networkd-network.c
+++ b/src/network/networkd-network.c
@@ -235,7 +235,7 @@ int network_apply(Manager *manager, Network *network, Link *link) {
link->network = network;
if (network->dns) {
- r = manager_update_resolv_conf(manager);
+ r = link_save(link);
if (r < 0)
return r;
}
diff --git a/src/network/networkd.c b/src/network/networkd.c
index 6b3bf12a4c..6985dcaa4a 100644
--- a/src/network/networkd.c
+++ b/src/network/networkd.c
@@ -93,14 +93,6 @@ int main(int argc, char *argv[]) {
goto out;
}
- /* write out empty resolv.conf to avoid a
- * dangling symlink */
- r = manager_update_resolv_conf(m);
- if (r < 0) {
- log_error("Could not create resolv.conf: %s", strerror(-r));
- goto out;
- }
-
sd_notify(false,
"READY=1\n"
"STATUS=Processing requests...");
diff --git a/src/network/networkd.conf.in b/src/network/networkd.conf.in
deleted file mode 100644
index efe889a442..0000000000
--- a/src/network/networkd.conf.in
+++ /dev/null
@@ -1,11 +0,0 @@
-# This file is part of systemd.
-#
-# systemd is free software; you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published by
-# the Free Software Foundation; either version 2.1 of the License, or
-# (at your option) any later version.
-#
-# See networkd.conf(5) for details
-
-[Network]
-#DNS=@DNS_SERVERS@
diff --git a/src/network/networkd.h b/src/network/networkd.h
index 30a29c7b67..3e4e1f2ba6 100644
--- a/src/network/networkd.h
+++ b/src/network/networkd.h
@@ -256,7 +256,6 @@ 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;
@@ -278,18 +277,11 @@ int manager_rtnl_listen(Manager *m);
int manager_udev_listen(Manager *m);
int manager_bus_listen(Manager *m);
-int manager_update_resolv_conf(Manager *m);
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);