networkd-netdev.c revision 505f8da7325591defe5f751f328bd26915267602
/*-*- 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.h"
#include "network-internal.h"
#include "path-util.h"
#include "conf-files.h"
#include "conf-parser.h"
#include "list.h"
#define VLANID_MAX 4094
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",
};
DEFINE_CONFIG_PARSE_ENUM(config_parse_netdev_kind, netdev_kind, NetDevKind, "Failed to parse netdev kind");
static const char* const macvlan_mode_table[_NETDEV_MACVLAN_MODE_MAX] = {
[NETDEV_MACVLAN_MODE_PRIVATE] = "private",
[NETDEV_MACVLAN_MODE_VEPA] = "vepa",
[NETDEV_MACVLAN_MODE_BRIDGE] = "bridge",
[NETDEV_MACVLAN_MODE_PASSTHRU] = "passthru",
};
DEFINE_CONFIG_PARSE_ENUM(config_parse_macvlan_mode, macvlan_mode, MacVlanMode, "Failed to parse macvlan mode");
if (!netdev)
return;
}
}
if (!netdev) {
return -ENOENT;
}
return 0;
}
return 0;
}
int r;
if (r < 0) {
"Could not allocate RTM_SETLINK message: %s",
strerror(-r));
return r;
}
if (r < 0) {
"Could not append IFLA_MASTER attribute: %s",
strerror(-r));
return r;
}
if (r < 0) {
"Could not send rtnetlink message: %s",
strerror(-r));
return r;
}
return 0;
}
return 0;
/* enslave the links that were attempted to be enslaved befor the
* link was ready */
}
return 0;
}
int r;
r = sd_rtnl_message_get_errno(m);
if (r == -EEXIST)
else if (r < 0) {
return 1;
}
return 1;
}
const char *kind;
int r;
if (r < 0) {
"Could not allocate RTM_NEWLINK message: %s",
strerror(-r));
return r;
}
if (link) {
if (r < 0) {
"Could not append IFLA_LINK attribute: %s",
strerror(-r));
return r;
}
}
if (r < 0) {
"Could not append IFLA_IFNAME attribute: %s",
strerror(-r));
return r;
}
if (r < 0) {
"Could not open IFLA_LINKINFO container: %s",
strerror(-r));
return r;
}
if (!kind) {
return -EINVAL;
}
if (r < 0) {
"Could not open IFLA_INFO_DATA container: %s",
strerror(-r));
return r;
}
if (r < 0) {
"Could not append IFLA_VLAN_ID attribute: %s",
strerror(-r));
return r;
}
}
if (r < 0) {
"Could not append IFLA_MACVLAN_MODE attribute: %s",
strerror(-r));
return r;
}
}
if (r < 0) {
"Could not close IFLA_INFO_DATA container %s",
strerror(-r));
return r;
}
if (r < 0) {
"Could not close IFLA_LINKINFO container %s",
strerror(-r));
return r;
}
if (link)
else
if (r < 0) {
"Could not send rtnetlink message: %s", strerror(-r));
return r;
}
return 0;
}
} else {
/* the netdev is not yet read, save this request for when it is*/
if (!cb)
return log_oom();
}
return 0;
}
const char *kind;
char *received_kind;
int r, ifindex;
if (r < 0) {
return r;
}
if (type != RTM_NEWLINK) {
return -EINVAL;
}
if (r < 0) {
return r;
}
if (r < 0) {
return r;
}
if (r < 0) {
return r;
}
if (!kind) {
return -EINVAL;
}
return r;
}
if (r < 0) {
return r;
} else if (ifindex <= 0) {
return r;
}
return -EEXIST;
}
return 0;
}
int r;
if (!file) {
return 0;
else
return -errno;
}
if (!netdev)
return log_oom();
false, false, netdev);
if (r < 0) {
return r;
}
return 0;
}
return 0;
}
return 0;
}
log_warning("VLAN Id configured for a %s in %s. Ignoring",
return 0;
}
log_warning("MACVLAN Mode configured for a %s in %s. Ignoring",
return 0;
}
return log_oom();
return 0;
if (r < 0)
return r;
if (r < 0)
return r;
}
return 0;
}
char **files, **f;
int r;
if (r < 0) {
return r;
}
STRV_FOREACH_BACKWARDS(f, files) {
r = netdev_load_one(manager, *f);
if (r < 0)
return r;
}
return 0;
}