networkd-manager.c revision 151b9b9662a90455262ce575a8a8ae74bf4ff336
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2013 Tom Gundersen <teg@jklm.no>
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.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <resolv.h>
#include "path-util.h"
#include "networkd.h"
#include "libudev-private.h"
#include "udev-util.h"
#include "rtnl-util.h"
#include "mkdir.h"
#include "virt.h"
const char* const network_dirs[] = {
#ifdef HAVE_SPLIT_USER
#endif
NULL};
int r;
if (!m)
return -ENOMEM;
r = sd_event_default(&m->event);
if (r < 0)
return r;
sd_event_set_watchdog(m->event, true);
if (r < 0)
return r;
r = sd_bus_default_system(&m->bus);
if (r < 0 && r != -ENOENT) /* TODO: drop when we can rely on kdbus */
return r;
if (!m->udev)
return -ENOMEM;
/* udev does not initialize devices inside containers,
* so we rely on them being already initialized before
* entering the container */
if (detect_container(NULL) > 0) {
if (!m->udev_monitor)
return -ENOMEM;
} else {
if (!m->udev_monitor)
return -ENOMEM;
}
if (!m->links)
return -ENOMEM;
if (!m->netdevs)
return -ENOMEM;
LIST_HEAD_INIT(m->networks);
*ret = m;
m = NULL;
return 0;
}
void manager_free(Manager *m) {
if (!m)
return;
udev_unref(m->udev);
sd_bus_unref(m->bus);
sd_event_unref(m->event);
hashmap_free(m->links);
hashmap_free(m->netdevs);
sd_rtnl_unref(m->rtnl);
free(m);
}
int manager_load_config(Manager *m) {
int r;
/* update timestamp */
r = netdev_load(m);
if (r < 0)
return r;
r = network_load(m);
if (r < 0)
return r;
return 0;
}
bool manager_should_reload(Manager *m) {
}
int r;
assert(m);
if (link)
} else {
if (link) {
log_debug("%s: link already exists, ignoring",
return 0;
}
if (r < 0) {
log_error("%s: could not handle link: %s",
strerror(-r));
} else
}
return 0;
}
int manager_udev_enumerate_links(Manager *m) {
int r;
assert(m);
e = udev_enumerate_new(m->udev);
if (!e)
return -ENOMEM;
r = udev_enumerate_add_match_subsystem(e, "net");
if (r < 0)
return r;
/* udev does not initialize devices inside containers,
* so we rely on them being already initialized before
* entering the container */
if (detect_container(NULL) <= 0) {
if (r < 0)
return r;
}
r = udev_enumerate_scan_devices(e);
if (r < 0)
return r;
int k;
if (!d)
return -ENOMEM;
k = manager_process_link(m, d);
if (k < 0)
r = k;
}
return r;
}
static int manager_dispatch_link_udev(sd_event_source *source, int fd, uint32_t revents, void *userdata) {
if (!device)
return -ENOMEM;
return 0;
}
int manager_udev_listen(Manager *m) {
int r;
if (r < 0) {
return r;
}
if (r < 0) {
log_error("Could not enable udev monitor");
return r;
}
r = sd_event_add_io(m->event,
&m->udev_event_source,
m);
if (r < 0)
return r;
return 0;
}
const char *name;
int r, ifindex;
assert(m);
if (r < 0 || ifindex <= 0) {
log_debug("received RTM_NEWLINK message without valid ifindex");
return 0;
}
if (r < 0)
log_debug("received RTM_NEWLINK message without valid IFLA_IFNAME");
else {
if (r >= 0) {
if (r < 0)
log_debug("could not set ifindex of netdev '%s' to %d: %s",
}
}
if (r < 0) {
return 0;
}
/* only track the status of links we want to manage */
if (r < 0)
return 0;
} else
return 1;
}
int manager_rtnl_listen(Manager *m) {
int r;
if (r < 0)
return r;
if (r < 0)
return r;
return 0;
}
int manager_bus_listen(Manager *m) {
int r;
if (!m->bus) /* TODO: drop when we can rely on kdbus */
return 0;
if (r < 0)
return r;
return 0;
}
char buf[INET6_ADDRSTRLEN];
const char *address;
if (!address) {
log_warning("Invalid DNS address. Ignoring.");
return;
}
fputs("# Too many DNS servers configured, the following entries "
"will be ignored\n", f);
(*count) ++;
}
int manager_update_resolv_conf(Manager *m) {
Iterator i;
unsigned count = 0;
const char *domainname = NULL;
int r;
assert(m);
if (r < 0)
return r;
if (r < 0)
return r;
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);
if (link->dhcp_lease) {
struct in_addr *nameservers;
if (r >= 0) {
unsigned j;
for (j = 0; j < nameservers_size; j++)
}
}
if (r >= 0)
}
}
}
fflush(f);
r = -errno;
unlink("/run/systemd/network/resolv.conf");
return r;
}
return 0;
}