2017-11-18 17:09:20 +01:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1+ */
|
2014-05-21 10:31:04 +02:00
|
|
|
|
2018-01-11 00:39:12 +01:00
|
|
|
#include <errno.h>
|
|
|
|
#include <net/if.h>
|
2019-05-09 02:33:45 +02:00
|
|
|
#include <linux/veth.h>
|
2014-05-21 10:31:04 +02:00
|
|
|
|
2019-10-30 09:02:15 +01:00
|
|
|
#include "veth.h"
|
2014-05-21 10:31:04 +02:00
|
|
|
|
2015-06-12 16:31:33 +02:00
|
|
|
static int netdev_veth_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) {
|
2015-10-25 04:55:16 +01:00
|
|
|
Veth *v;
|
2014-05-21 10:31:04 +02:00
|
|
|
int r;
|
|
|
|
|
|
|
|
assert(netdev);
|
2014-07-16 13:17:10 +02:00
|
|
|
assert(!link);
|
2014-05-21 10:31:04 +02:00
|
|
|
assert(m);
|
|
|
|
|
2015-10-25 04:55:16 +01:00
|
|
|
v = VETH(netdev);
|
|
|
|
|
|
|
|
assert(v);
|
|
|
|
|
2015-06-12 16:31:33 +02:00
|
|
|
r = sd_netlink_message_open_container(m, VETH_INFO_PEER);
|
2015-06-10 08:50:45 +02:00
|
|
|
if (r < 0)
|
|
|
|
return log_netdev_error_errno(netdev, r, "Could not append VETH_INFO_PEER attribute: %m");
|
2014-05-21 10:31:04 +02:00
|
|
|
|
2014-07-16 13:17:10 +02:00
|
|
|
if (v->ifname_peer) {
|
2015-06-12 16:31:33 +02:00
|
|
|
r = sd_netlink_message_append_string(m, IFLA_IFNAME, v->ifname_peer);
|
2014-11-28 18:50:43 +01:00
|
|
|
if (r < 0)
|
2020-01-07 04:53:19 +01:00
|
|
|
return log_netdev_error_errno(netdev, r, "Failed to add netlink interface name: %m");
|
2014-05-21 10:31:04 +02:00
|
|
|
}
|
|
|
|
|
2014-07-16 13:17:10 +02:00
|
|
|
if (v->mac_peer) {
|
2015-06-12 16:31:33 +02:00
|
|
|
r = sd_netlink_message_append_ether_addr(m, IFLA_ADDRESS, v->mac_peer);
|
2015-06-10 08:50:45 +02:00
|
|
|
if (r < 0)
|
|
|
|
return log_netdev_error_errno(netdev, r, "Could not append IFLA_ADDRESS attribute: %m");
|
2014-06-14 15:38:35 +02:00
|
|
|
}
|
|
|
|
|
2015-06-12 16:31:33 +02:00
|
|
|
r = sd_netlink_message_close_container(m);
|
2015-06-10 08:50:45 +02:00
|
|
|
if (r < 0)
|
|
|
|
return log_netdev_error_errno(netdev, r, "Could not append IFLA_INFO_DATA attribute: %m");
|
2014-05-21 10:31:04 +02:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2014-07-06 14:07:34 +02:00
|
|
|
static int netdev_veth_verify(NetDev *netdev, const char *filename) {
|
2015-10-25 04:55:16 +01:00
|
|
|
Veth *v;
|
2014-05-21 10:31:04 +02:00
|
|
|
int r;
|
|
|
|
|
|
|
|
assert(netdev);
|
2014-07-06 14:07:34 +02:00
|
|
|
assert(filename);
|
2014-05-21 10:31:04 +02:00
|
|
|
|
2015-10-25 04:55:16 +01:00
|
|
|
v = VETH(netdev);
|
|
|
|
|
|
|
|
assert(v);
|
|
|
|
|
2014-07-16 13:17:10 +02:00
|
|
|
if (!v->ifname_peer) {
|
2020-01-07 04:53:19 +01:00
|
|
|
log_netdev_warning(netdev, "Veth NetDev without peer name configured in %s. Ignoring",
|
|
|
|
filename);
|
2014-07-06 14:07:34 +02:00
|
|
|
return -EINVAL;
|
2014-05-21 10:31:04 +02:00
|
|
|
}
|
|
|
|
|
2014-07-16 13:17:10 +02:00
|
|
|
if (!v->mac_peer) {
|
|
|
|
r = netdev_get_mac(v->ifname_peer, &v->mac_peer);
|
2014-07-06 14:07:34 +02:00
|
|
|
if (r < 0) {
|
2020-01-07 04:53:19 +01:00
|
|
|
log_netdev_warning(netdev,
|
|
|
|
"Failed to generate predictable MAC address for %s. Ignoring",
|
|
|
|
v->ifname_peer);
|
2014-07-06 14:07:34 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2014-05-21 10:31:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2014-07-06 14:07:34 +02:00
|
|
|
|
2014-07-16 13:17:10 +02:00
|
|
|
static void veth_done(NetDev *n) {
|
2015-10-25 04:55:16 +01:00
|
|
|
Veth *v;
|
2014-07-16 13:17:10 +02:00
|
|
|
|
|
|
|
assert(n);
|
2015-10-25 04:55:16 +01:00
|
|
|
|
|
|
|
v = VETH(n);
|
|
|
|
|
2014-07-16 13:17:10 +02:00
|
|
|
assert(v);
|
|
|
|
|
|
|
|
free(v->ifname_peer);
|
|
|
|
free(v->mac_peer);
|
|
|
|
}
|
|
|
|
|
2014-07-06 14:07:34 +02:00
|
|
|
const NetDevVTable veth_vtable = {
|
2014-07-16 13:17:10 +02:00
|
|
|
.object_size = sizeof(Veth),
|
2019-11-22 11:43:26 +01:00
|
|
|
.sections = NETDEV_COMMON_SECTIONS "Peer\0",
|
2014-07-16 13:17:10 +02:00
|
|
|
.done = veth_done,
|
2014-07-06 14:07:34 +02:00
|
|
|
.fill_message_create = netdev_veth_fill_message_create,
|
2014-07-16 13:17:10 +02:00
|
|
|
.create_type = NETDEV_CREATE_INDEPENDENT,
|
2014-07-06 14:07:34 +02:00
|
|
|
.config_verify = netdev_veth_verify,
|
2019-05-23 04:27:12 +02:00
|
|
|
.generate_mac = true,
|
2014-07-06 14:07:34 +02:00
|
|
|
};
|