networkd-manager.c revision adda1ed94a04742ddacdc76dfa311816e1ed9f68
4819ff0358b6317c195fd4b1768e03d09c871070Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4819ff0358b6317c195fd4b1768e03d09c871070Lennart Poettering This file is part of systemd.
4819ff0358b6317c195fd4b1768e03d09c871070Lennart Poettering Copyright 2013 Tom Gundersen <teg@jklm.no>
4819ff0358b6317c195fd4b1768e03d09c871070Lennart Poettering systemd is free software; you can redistribute it and/or modify it
4819ff0358b6317c195fd4b1768e03d09c871070Lennart Poettering under the terms of the GNU Lesser General Public License as published by
4819ff0358b6317c195fd4b1768e03d09c871070Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
4819ff0358b6317c195fd4b1768e03d09c871070Lennart Poettering (at your option) any later version.
4819ff0358b6317c195fd4b1768e03d09c871070Lennart Poettering systemd is distributed in the hope that it will be useful, but
4819ff0358b6317c195fd4b1768e03d09c871070Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
4819ff0358b6317c195fd4b1768e03d09c871070Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4819ff0358b6317c195fd4b1768e03d09c871070Lennart Poettering Lesser General Public License for more details.
4819ff0358b6317c195fd4b1768e03d09c871070Lennart Poettering You should have received a copy of the GNU Lesser General Public License
4819ff0358b6317c195fd4b1768e03d09c871070Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
4819ff0358b6317c195fd4b1768e03d09c871070Lennart Poettering/* use 8 MB for receive socket kernel queue. */
82659fd7571bda0f3dce9755b89a23c411d53ddaLennart Poetteringconst char* const network_dirs[] = {
4819ff0358b6317c195fd4b1768e03d09c871070Lennart Poetteringstatic int setup_default_address_pool(Manager *m) {
4819ff0358b6317c195fd4b1768e03d09c871070Lennart Poettering /* Add in the well-known private address ranges. */
4819ff0358b6317c195fd4b1768e03d09c871070Lennart Poettering r = address_pool_new_from_string(m, &p, AF_INET6, "fc00::", 7);
ac5e3a505e49c80b56c971a8fc13bacac961640dJan Synacek r = address_pool_new_from_string(m, &p, AF_INET, "192.168.0.0", 16);
4819ff0358b6317c195fd4b1768e03d09c871070Lennart Poettering r = address_pool_new_from_string(m, &p, AF_INET, "172.16.0.0", 12);
assert(s);
assert(m);
Iterator i;
assert(m);
static int match_prepare_for_sleep(sd_bus_message *message, void *userdata, sd_bus_error *ret_error) {
assert(m);
if (r == -ENOENT) {
r = sd_event_add_time(m->event, &m->bus_retry_event_source, CLOCK_MONOTONIC, now(CLOCK_MONOTONIC) + 5*USEC_PER_SEC, 0, on_bus_retry, m);
"path='/org/freedesktop/login1'",
r = sd_bus_add_object_vtable(m->bus, NULL, "/org/freedesktop/network1", "org.freedesktop.network1.Manager", manager_vtable, m);
r = sd_bus_add_fallback_vtable(m->bus, NULL, "/org/freedesktop/network1/link", "org.freedesktop.network1.Link", link_vtable, link_object_find, m);
r = sd_bus_add_node_enumerator(m->bus, NULL, "/org/freedesktop/network1/link", link_node_enumerator, m);
r = sd_bus_add_fallback_vtable(m->bus, NULL, "/org/freedesktop/network1/network", "org.freedesktop.network1.Network", network_vtable, network_object_find, m);
r = sd_bus_add_node_enumerator(m->bus, NULL, "/org/freedesktop/network1/network", network_node_enumerator, m);
int r, ifindex;
assert(m);
if (ifindex <= 0) {
if (r == -ENODEV)
static int manager_dispatch_link_udev(sd_event_source *source, int fd, uint32_t revents, void *userdata) {
if (!device)
return -ENOMEM;
if (detect_container() > 0)
if (!m->udev)
return -ENOMEM;
if (!m->udev_monitor)
return -ENOMEM;
&m->udev_event_source,
unsigned char flags;
int family;
unsigned char prefixlen;
unsigned char scope;
int r, ifindex;
assert(m);
} else if (ifindex <= 0) {
if (r < 0 || !link) {
if (!m->enumerating)
switch (family) {
case AF_INET:
case AF_INET6:
switch (type) {
case RTM_NEWADDR:
if (address)
case RTM_DELADDR:
if (address) {
log_link_warning(link, "Removing non-existent address: %s/%u (valid for %s)", buf, prefixlen, valid_str);
static int manager_rtnl_process_link(sd_netlink *rtnl, sd_netlink_message *message, void *userdata) {
const char *name;
int r, ifindex;
assert(m);
} else if (ifindex <= 0) {
switch (type) {
case RTM_NEWLINK:
if (!link) {
if (netdev) {
case RTM_DELLINK:
static int systemd_netlink_fd(void) {
n = sd_listen_fds(true);
return -EINVAL;
if (rtnl_fd >= 0)
return -EINVAL;
return rtnl_fd;
int fd, r;
assert(m);
if (fd < 0)
return -ENOMEM;
if (!m->state_file)
return -ENOMEM;
r = manager_connect_rtnl(m);
r = manager_connect_udev(m);
if (!m->netdevs)
return -ENOMEM;
r = setup_default_address_pool(m);
*ret = m;
m = NULL;
free(m);
Iterator i;
assert(m);
assert(m);
if (m->bus)
return bus_event_loop_with_idle(
m->event,
m->bus,
r = netdev_load(m);
r = network_load(m);
assert(m);
m->enumerating = true;
m->enumerating = false;
assert(m);
m->enumerating = true;
m->enumerating = false;
assert(s);
r = set_consume(s, p);
if (r == -EEXIST)
assert(s);
bool space = false;
Iterator i;
if (set_isempty(s))
SET_FOREACH(p, s, i) {
if (space)
fputs(p, f);
space = true;
Iterator i;
const char *operstate_str;
assert(m);
if (!dns)
return -ENOMEM;
if (!ntp)
return -ENOMEM;
if (!domains)
return -ENOMEM;
} else if (r < 0 && r != -ENODATA)
} else if (r < 0 && r != -ENODATA)
const char *domainname;
} else if (r != -ENODATA)
fprintf(f,
r = fflush_and_check(f);
goto fail;
r = -errno;
goto fail;
fail:
int manager_address_pool_acquire(Manager *m, int family, unsigned prefixlen, union in_addr_union *found) {
AddressPool *p;
assert(m);
assert(m);
return NULL;
if (!link) {
return link;
return NULL;