2017-11-18 17:09:20 +01:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1+ */
|
2014-07-03 09:38:33 +02:00
|
|
|
|
2018-01-11 00:39:12 +01:00
|
|
|
#include <errno.h>
|
2014-07-03 09:38:33 +02:00
|
|
|
#include <net/if.h>
|
2019-05-09 02:33:45 +02:00
|
|
|
#include <linux/if_vlan.h>
|
2014-07-03 09:38:33 +02:00
|
|
|
|
2016-06-09 18:55:16 +02:00
|
|
|
#include "vlan-util.h"
|
2019-10-30 09:02:15 +01:00
|
|
|
#include "vlan.h"
|
2014-07-03 09:38:33 +02:00
|
|
|
|
2015-06-12 16:31:33 +02:00
|
|
|
static int netdev_vlan_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *req) {
|
2017-04-21 11:01:59 +02:00
|
|
|
struct ifla_vlan_flags flags = {};
|
2015-10-25 05:00:17 +01:00
|
|
|
VLan *v;
|
2014-07-03 09:38:33 +02:00
|
|
|
int r;
|
|
|
|
|
|
|
|
assert(netdev);
|
|
|
|
assert(link);
|
2014-07-06 14:07:34 +02:00
|
|
|
assert(req);
|
2014-07-03 09:38:33 +02:00
|
|
|
|
2015-10-25 05:00:17 +01:00
|
|
|
v = VLAN(netdev);
|
|
|
|
|
|
|
|
assert(v);
|
|
|
|
|
2016-06-09 18:55:16 +02:00
|
|
|
r = sd_netlink_message_append_u16(req, IFLA_VLAN_ID, v->id);
|
|
|
|
if (r < 0)
|
|
|
|
return log_netdev_error_errno(netdev, r, "Could not append IFLA_VLAN_ID attribute: %m");
|
2014-07-03 09:38:33 +02:00
|
|
|
|
2017-04-21 11:01:59 +02:00
|
|
|
if (v->gvrp != -1) {
|
|
|
|
flags.mask |= VLAN_FLAG_GVRP;
|
2017-05-07 13:03:28 +02:00
|
|
|
SET_FLAG(flags.flags, VLAN_FLAG_GVRP, v->gvrp);
|
2017-04-21 11:01:59 +02:00
|
|
|
}
|
|
|
|
|
2017-05-09 20:25:11 +02:00
|
|
|
if (v->mvrp != -1) {
|
|
|
|
flags.mask |= VLAN_FLAG_MVRP;
|
|
|
|
SET_FLAG(flags.flags, VLAN_FLAG_MVRP, v->mvrp);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (v->reorder_hdr != -1) {
|
|
|
|
flags.mask |= VLAN_FLAG_REORDER_HDR;
|
|
|
|
SET_FLAG(flags.flags, VLAN_FLAG_REORDER_HDR, v->reorder_hdr);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (v->loose_binding != -1) {
|
|
|
|
flags.mask |= VLAN_FLAG_LOOSE_BINDING;
|
|
|
|
SET_FLAG(flags.flags, VLAN_FLAG_LOOSE_BINDING, v->loose_binding);
|
|
|
|
}
|
|
|
|
|
2017-04-21 11:01:59 +02:00
|
|
|
r = sd_netlink_message_append_data(req, IFLA_VLAN_FLAGS, &flags, sizeof(struct ifla_vlan_flags));
|
|
|
|
if (r < 0)
|
|
|
|
return log_netdev_error_errno(netdev, r, "Could not append IFLA_VLAN_FLAGS attribute: %m");
|
|
|
|
|
2014-07-06 14:07:34 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2014-07-07 14:18:26 +02:00
|
|
|
|
2014-07-06 14:07:34 +02:00
|
|
|
static int netdev_vlan_verify(NetDev *netdev, const char *filename) {
|
2015-10-25 05:00:17 +01:00
|
|
|
VLan *v;
|
2014-07-16 13:17:10 +02:00
|
|
|
|
2014-07-06 14:07:34 +02:00
|
|
|
assert(netdev);
|
|
|
|
assert(filename);
|
2014-07-03 09:38:33 +02:00
|
|
|
|
2015-10-25 05:00:17 +01:00
|
|
|
v = VLAN(netdev);
|
|
|
|
|
|
|
|
assert(v);
|
|
|
|
|
2016-06-09 18:55:16 +02:00
|
|
|
if (v->id == VLANID_INVALID) {
|
2020-01-07 04:53:19 +01:00
|
|
|
log_netdev_warning(netdev, "VLAN without valid Id (%"PRIu16") configured in %s.", v->id, filename);
|
2014-07-06 14:07:34 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2014-07-03 09:38:33 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2014-07-06 14:07:34 +02:00
|
|
|
|
2014-07-16 13:17:10 +02:00
|
|
|
static void vlan_init(NetDev *netdev) {
|
|
|
|
VLan *v = VLAN(netdev);
|
|
|
|
|
|
|
|
assert(netdev);
|
|
|
|
assert(v);
|
|
|
|
|
2016-06-09 18:55:16 +02:00
|
|
|
v->id = VLANID_INVALID;
|
2017-04-21 11:01:59 +02:00
|
|
|
v->gvrp = -1;
|
2017-05-09 20:25:11 +02:00
|
|
|
v->mvrp = -1;
|
|
|
|
v->loose_binding = -1;
|
|
|
|
v->reorder_hdr = -1;
|
2014-07-16 13:17:10 +02:00
|
|
|
}
|
|
|
|
|
2014-07-06 14:07:34 +02:00
|
|
|
const NetDevVTable vlan_vtable = {
|
2014-07-16 13:17:10 +02:00
|
|
|
.object_size = sizeof(VLan),
|
|
|
|
.init = vlan_init,
|
2019-11-22 11:43:26 +01:00
|
|
|
.sections = NETDEV_COMMON_SECTIONS "VLAN\0",
|
2014-07-16 13:17:10 +02:00
|
|
|
.fill_message_create = netdev_vlan_fill_message_create,
|
|
|
|
.create_type = NETDEV_CREATE_STACKED,
|
2014-07-06 14:07:34 +02:00
|
|
|
.config_verify = netdev_vlan_verify,
|
|
|
|
};
|