networkd-netdev.c revision b024a9cfb1bee0aa8e143f46db11a4c2a58fb798
/*-*- 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 "networkd-netdev.h"
#include "networkd-link.h"
#include "network-internal.h"
#include "conf-files.h"
#include "conf-parser.h"
#include "list.h"
#include "siphash24.h"
[NETDEV_KIND_BOND] = &bond_vtable,
[NETDEV_KIND_VLAN] = &vlan_vtable,
[NETDEV_KIND_IPIP] = &ipip_vtable,
[NETDEV_KIND_GRE] = &gre_vtable,
[NETDEV_KIND_SIT] = &sit_vtable,
[NETDEV_KIND_VTI] = &vti_vtable,
[NETDEV_KIND_VTI6] = &vti6_vtable,
[NETDEV_KIND_VETH] = &veth_vtable,
[NETDEV_KIND_TUN] = &tun_vtable,
[NETDEV_KIND_TAP] = &tap_vtable,
};
static const char* const netdev_kind_table[_NETDEV_KIND_MAX] = {
[NETDEV_KIND_BRIDGE] = "bridge",
[NETDEV_KIND_BOND] = "bond",
[NETDEV_KIND_VLAN] = "vlan",
[NETDEV_KIND_MACVLAN] = "macvlan",
[NETDEV_KIND_IPVLAN] = "ipvlan",
[NETDEV_KIND_VXLAN] = "vxlan",
[NETDEV_KIND_IPIP] = "ipip",
[NETDEV_KIND_GRE] = "gre",
[NETDEV_KIND_GRETAP] = "gretap",
[NETDEV_KIND_IP6GRE] = "ip6gre",
[NETDEV_KIND_IP6GRETAP] = "ip6gretap",
[NETDEV_KIND_SIT] = "sit",
[NETDEV_KIND_VETH] = "veth",
[NETDEV_KIND_VTI] = "vti",
[NETDEV_KIND_VTI6] = "vti6",
[NETDEV_KIND_DUMMY] = "dummy",
[NETDEV_KIND_TUN] = "tun",
[NETDEV_KIND_TAP] = "tap",
[NETDEV_KIND_IP6TNL] = "ip6tnl",
};
DEFINE_CONFIG_PARSE_ENUM(config_parse_netdev_kind, netdev_kind, NetDevKind, "Failed to parse netdev kind");
if (!netdev)
return;
rtnl_message_new_synthetic_error(-ENODEV, 0, &m);
if (m) {
}
}
}
if (!netdev)
return;
if (NETDEV_VTABLE(netdev) &&
}
return NULL;
}
if (netdev)
return netdev;
}
return;
return;
}
if (!netdev) {
return -ENOENT;
}
return 0;
}
return 0;
}
static int netdev_enslave_ready(NetDev *netdev, Link* link, sd_netlink_message_handler_t callback) {
int r;
if (r < 0)
if (r < 0)
if (r < 0)
return 0;
}
int r;
return 0;
/* enslave the links that were attempted to be enslaved before the
* link was ready */
if (r < 0)
return r;
}
return 0;
}
/* callback for netdev's created without a backing Link */
int r;
r = sd_netlink_message_get_errno(m);
if (r == -EEXIST)
else if (r < 0) {
return 1;
}
return 1;
}
int r;
if (r < 0)
return r;
} else {
/* the netdev is not yet read, save this request for when it is */
if (!cb)
return log_oom();
}
return 0;
}
const char *kind;
const char *received_kind;
const char *received_name;
int r, ifindex;
if (r < 0)
if (type != RTM_NEWLINK) {
return -EINVAL;
}
if (r < 0) {
return r;
} else if (ifindex <= 0) {
return -EINVAL;
}
return -EEXIST;
} else
/* ifindex already set to the same for this netdev */
return 0;
}
if (r < 0)
return r;
}
if (r < 0)
if (r < 0)
if (r < 0)
/* the kernel does not distinguish between tun and tap */
kind = "tun";
else {
if (!kind) {
return -EINVAL;
}
}
"Received newlink with wrong KIND %s, "
return r;
}
return 0;
}
uint8_t *v;
int r;
if (!mac)
return -ENOMEM;
sz = sizeof(sd_id128_t) + l;
/* fetch some persistent data unique to the machine */
r = sd_id128_get_machine((sd_id128_t*) v);
if (r < 0)
return r;
/* combine with some data unique (on this machine) to this
* netdev */
/* Let's hash the host machine ID plus the container name. We
* use a fixed, but originally randomly created hash key here. */
/* see eth_random_addr in the kernel */
return 0;
}
int r;
/* create netdev */
if (r < 0)
return r;
} else {
if (r < 0)
if (r < 0)
if (r < 0)
}
if (r < 0)
}
if (link) {
if (r < 0)
}
if (r < 0)
r = sd_netlink_message_open_container_union(m, IFLA_INFO_DATA, netdev_kind_to_string(netdev->kind));
if (r < 0)
if (r < 0)
return r;
}
if (r < 0)
if (r < 0)
if (link) {
if (r < 0)
} else {
if (r < 0)
}
}
return 0;
}
/* the callback must be called, possibly after a timeout, as otherwise the Link will hang */
int r;
case NETDEV_CREATE_MASTER:
if (r < 0)
return r;
break;
case NETDEV_CREATE_STACKED:
if (r < 0)
return r;
break;
default:
assert_not_reached("Can not join independent netdev");
}
return 0;
}
int r;
if (!file) {
return 0;
else
return -errno;
}
return 0;
}
if (!netdev_raw)
return log_oom();
"Match\0NetDev\0",
true, false, true, netdev_raw);
if (r < 0)
return r;
if (r < 0)
return -errno;
/* skip out early if configuration does not match the environment */
return 0;
if (!NETDEV_VTABLE(netdev_raw)) {
return 0;
}
if (!netdev_raw->ifname) {
return 0;
}
if (!netdev)
return log_oom();
false, false, false, netdev);
if (r < 0)
return r;
/* verify configuration */
if (r < 0)
return 0;
}
return log_oom();
if (r < 0)
}
if (r < 0)
return r;
case NETDEV_CREATE_MASTER:
if (r < 0)
return 0;
break;
default:
break;
}
return 0;
}
char **f;
int r;
if (r < 0)
return log_error_errno(r, "Failed to enumerate netdev files: %m");
STRV_FOREACH_BACKWARDS(f, files) {
r = netdev_load_one(manager, *f);
if (r < 0)
return r;
}
return 0;
}