networkd-manager.c revision 091a364c802e34a58f3260c9cb5db9b75c62215c
/*-*- 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 <libkmod.h>
#include "conf-parser.h"
#include "path-util.h"
#include "networkd.h"
#include "network-internal.h"
#include "libudev-private.h"
#include "udev-util.h"
#include "rtnl-util.h"
#include "mkdir.h"
#include "virt.h"
#include "sd-rtnl.h"
const char* const network_dirs[] = {
#ifdef HAVE_SPLIT_USR
#endif
NULL};
static int dispatch_sigterm(sd_event_source *es, const struct signalfd_siginfo *si, void *userdata) {
assert(m);
sd_event_exit(m->event, 0);
return 0;
}
static int setup_signals(Manager *m) {
int r;
assert(m);
if (r < 0)
return r;
if (r < 0)
return r;
return 0;
}
int r;
if (!m)
return -ENOMEM;
if (!m->state_file)
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;
r = setup_signals(m);
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 (!m->udev)
return -ENOMEM;
if (!m->udev_monitor)
return -ENOMEM;
}
if (!m->kmod_ctx)
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;
free(m->state_file);
kmod_unref(m->kmod_ctx);
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, ifindex;
assert(m);
return 0;
if (ifindex <= 0) {
log_debug("ignoring udev ADD event for device with invalid ifindex");
return 0;
}
if (r == -ENODEV)
return 0;
else if (r < 0)
return r;
if (r < 0)
return r;
return 0;
}
char *name;
int r, ifindex;
assert(m);
if (r < 0) {
log_warning("rtnl: could not get message type");
return 0;
}
if (r < 0 || ifindex <= 0) {
log_warning("rtnl: received link message without valid ifindex");
return 0;
} else
if (r < 0 || !name) {
log_warning("rtnl: received link message without valid ifname");
return 0;
} else
switch (type) {
case RTM_NEWLINK:
if (!link) {
/* link is new, so add it */
if (r < 0) {
log_debug("could not add new link");
return 0;
}
}
if (netdev) {
/* netdev exists, so make sure the ifindex matches */
if (r < 0) {
log_debug("could not set ifindex on netdev");
return 0;
}
}
if (r < 0)
return 0;
break;
case RTM_DELLINK:
break;
default:
assert_not_reached("Received invalid RTNL message type.");
}
return 1;
}
int manager_rtnl_enumerate_links(Manager *m) {
int r, k;
assert(m);
if (r < 0)
return r;
r = sd_rtnl_message_request_dump(req, true);
if (r < 0)
return r;
if (r < 0)
return r;
if (k < 0)
return k;
if (type != RTM_NEWLINK)
continue;
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 (detect_container(NULL) > 0)
return 0;
assert(m->udev_monitor);
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;
}
int manager_rtnl_listen(Manager *m) {
int r;
if (r < 0)
return r;
if (r < 0)
return r;
if (r < 0)
return 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;
}
int manager_save(Manager *m) {
Iterator i;
const char *oper_state = "unknown";
int r;
assert(m);
assert(m->state_file);
continue;
carrier = true;
dormant = true;
}
if (carrier)
oper_state = "carrier";
else if (dormant)
oper_state = "dormant";
if (r < 0)
goto finish;
fprintf(f,
"# This is private data. Do not parse.\n"
"OPER_STATE=%s\n", oper_state);
fflush(f);
r = -errno;
unlink(m->state_file);
}
if (r < 0)
return r;
}