platform: implement link_vlan_add via nm_platform_link_add()
This commit is contained in:
@@ -293,22 +293,44 @@ link_add (NMPlatform *platform,
|
|||||||
NMPCacheOpsType cache_op;
|
NMPCacheOpsType cache_op;
|
||||||
NMPCacheOpsType cache_op_veth = NMP_CACHE_OPS_UNCHANGED;
|
NMPCacheOpsType cache_op_veth = NMP_CACHE_OPS_UNCHANGED;
|
||||||
const char *veth_peer = NULL;
|
const char *veth_peer = NULL;
|
||||||
|
NMPObject *dev_obj;
|
||||||
|
NMPObject *dev_lnk = NULL;
|
||||||
|
|
||||||
device = link_add_pre (platform, name, type, address, address_len);
|
device = link_add_pre (platform, name, type, address, address_len);
|
||||||
|
|
||||||
|
g_assert (device);
|
||||||
|
|
||||||
|
dev_obj = (NMPObject *) device->obj;
|
||||||
|
|
||||||
|
if (parent > 0)
|
||||||
|
dev_obj->link.parent = parent;
|
||||||
|
else
|
||||||
g_assert (parent == 0);
|
g_assert (parent == 0);
|
||||||
|
|
||||||
|
g_assert ((parent != 0) == NM_IN_SET (type, NM_LINK_TYPE_VLAN));
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case NM_LINK_TYPE_VETH:
|
case NM_LINK_TYPE_VETH:
|
||||||
veth_peer = extra_data;
|
veth_peer = extra_data;
|
||||||
g_assert (veth_peer);
|
g_assert (veth_peer);
|
||||||
device_veth = link_add_pre (platform, veth_peer, type, NULL, 0);
|
device_veth = link_add_pre (platform, veth_peer, type, NULL, 0);
|
||||||
break;
|
break;
|
||||||
|
case NM_LINK_TYPE_VLAN: {
|
||||||
|
const NMPlatformLnkVlan *props = extra_data;
|
||||||
|
|
||||||
|
g_assert (props);
|
||||||
|
|
||||||
|
dev_lnk = nmp_object_new (NMP_OBJECT_TYPE_LNK_VLAN, props);
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
g_assert (!extra_data);
|
g_assert (!extra_data);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (dev_lnk)
|
||||||
|
dev_obj->_link.netlink.lnk = dev_lnk;
|
||||||
|
|
||||||
link_add_prepare (platform, device, (NMPObject *) device->obj);
|
link_add_prepare (platform, device, (NMPObject *) device->obj);
|
||||||
cache_op = nmp_cache_update_netlink (nm_platform_get_cache (platform),
|
cache_op = nmp_cache_update_netlink (nm_platform_get_cache (platform),
|
||||||
(NMPObject *) device->obj,
|
(NMPObject *) device->obj,
|
||||||
@@ -719,45 +741,6 @@ link_release (NMPlatform *platform, int master_idx, int slave_idx)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct vlan_add_data {
|
|
||||||
guint32 vlan_flags;
|
|
||||||
int parent;
|
|
||||||
int vlan_id;
|
|
||||||
};
|
|
||||||
|
|
||||||
static void
|
|
||||||
_vlan_add_prepare (NMPlatform *platform,
|
|
||||||
NMFakePlatformLink *device,
|
|
||||||
gconstpointer user_data)
|
|
||||||
{
|
|
||||||
const struct vlan_add_data *d = user_data;
|
|
||||||
NMPObject *obj_tmp;
|
|
||||||
NMPObject *lnk;
|
|
||||||
|
|
||||||
obj_tmp = (NMPObject *) device->obj;
|
|
||||||
|
|
||||||
lnk = nmp_object_new (NMP_OBJECT_TYPE_LNK_VLAN, NULL);
|
|
||||||
lnk->lnk_vlan.id = d->vlan_id;
|
|
||||||
lnk->lnk_vlan.flags = d->vlan_flags;
|
|
||||||
|
|
||||||
obj_tmp->link.parent = d->parent;
|
|
||||||
obj_tmp->_link.netlink.lnk = lnk;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
vlan_add (NMPlatform *platform, const char *name, int parent, int vlan_id, guint32 vlan_flags, const NMPlatformLink **out_link)
|
|
||||||
{
|
|
||||||
const struct vlan_add_data d = {
|
|
||||||
.parent = parent,
|
|
||||||
.vlan_id = vlan_id,
|
|
||||||
.vlan_flags = vlan_flags,
|
|
||||||
};
|
|
||||||
|
|
||||||
link_add_one (platform, name, NM_LINK_TYPE_VLAN,
|
|
||||||
_vlan_add_prepare, &d, out_link);
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
link_vlan_change (NMPlatform *platform,
|
link_vlan_change (NMPlatform *platform,
|
||||||
int ifindex,
|
int ifindex,
|
||||||
@@ -1424,7 +1407,6 @@ nm_fake_platform_class_init (NMFakePlatformClass *klass)
|
|||||||
platform_class->link_enslave = link_enslave;
|
platform_class->link_enslave = link_enslave;
|
||||||
platform_class->link_release = link_release;
|
platform_class->link_release = link_release;
|
||||||
|
|
||||||
platform_class->vlan_add = vlan_add;
|
|
||||||
platform_class->link_vlan_change = link_vlan_change;
|
platform_class->link_vlan_change = link_vlan_change;
|
||||||
platform_class->link_vxlan_add = link_vxlan_add;
|
platform_class->link_vxlan_add = link_vxlan_add;
|
||||||
|
|
||||||
|
@@ -3707,6 +3707,26 @@ _nl_msg_new_link_set_linkinfo (struct nl_msg *msg,
|
|||||||
NLA_PUT_STRING (msg, IFLA_INFO_KIND, kind);
|
NLA_PUT_STRING (msg, IFLA_INFO_KIND, kind);
|
||||||
|
|
||||||
switch (link_type) {
|
switch (link_type) {
|
||||||
|
case NM_LINK_TYPE_VLAN: {
|
||||||
|
const NMPlatformLnkVlan *props = extra_data;
|
||||||
|
|
||||||
|
nm_assert (extra_data);
|
||||||
|
|
||||||
|
if (!(data = nla_nest_start (msg, IFLA_INFO_DATA)))
|
||||||
|
goto nla_put_failure;
|
||||||
|
|
||||||
|
NLA_PUT_U16 (msg, IFLA_VLAN_ID, props->id);
|
||||||
|
|
||||||
|
{
|
||||||
|
struct ifla_vlan_flags flags = {
|
||||||
|
.flags = props->flags & NM_VLAN_FLAGS_ALL,
|
||||||
|
.mask = NM_VLAN_FLAGS_ALL,
|
||||||
|
};
|
||||||
|
|
||||||
|
NLA_PUT (msg, IFLA_VLAN_FLAGS, sizeof (flags), &flags);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
case NM_LINK_TYPE_VETH: {
|
case NM_LINK_TYPE_VETH: {
|
||||||
const char *veth_peer = extra_data;
|
const char *veth_peer = extra_data;
|
||||||
const struct ifinfomsg ifi = { };
|
const struct ifinfomsg ifi = { };
|
||||||
@@ -3794,6 +3814,11 @@ _nl_msg_new_link_set_linkinfo_vlan (struct nl_msg *msg,
|
|||||||
guint i;
|
guint i;
|
||||||
gboolean has_any_vlan_properties = FALSE;
|
gboolean has_any_vlan_properties = FALSE;
|
||||||
|
|
||||||
|
G_STATIC_ASSERT (NM_VLAN_FLAG_REORDER_HEADERS == (guint32) VLAN_FLAG_REORDER_HDR);
|
||||||
|
G_STATIC_ASSERT (NM_VLAN_FLAG_GVRP == (guint32) VLAN_FLAG_GVRP);
|
||||||
|
G_STATIC_ASSERT (NM_VLAN_FLAG_LOOSE_BINDING == (guint32) VLAN_FLAG_LOOSE_BINDING);
|
||||||
|
G_STATIC_ASSERT (NM_VLAN_FLAG_MVRP == (guint32) VLAN_FLAG_MVRP);
|
||||||
|
|
||||||
#define VLAN_XGRESS_PRIO_VALID(from) (((from) & ~(guint32) 0x07) == 0)
|
#define VLAN_XGRESS_PRIO_VALID(from) (((from) & ~(guint32) 0x07) == 0)
|
||||||
|
|
||||||
nm_assert (msg);
|
nm_assert (msg);
|
||||||
@@ -7212,46 +7237,6 @@ link_get_dev_id (NMPlatform *platform, int ifindex)
|
|||||||
16, 0, G_MAXUINT16, 0);
|
16, 0, G_MAXUINT16, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
|
||||||
vlan_add (NMPlatform *platform,
|
|
||||||
const char *name,
|
|
||||||
int parent,
|
|
||||||
int vlan_id,
|
|
||||||
guint32 vlan_flags,
|
|
||||||
const NMPlatformLink **out_link)
|
|
||||||
{
|
|
||||||
nm_auto_nlmsg struct nl_msg *nlmsg = NULL;
|
|
||||||
|
|
||||||
G_STATIC_ASSERT (NM_VLAN_FLAG_REORDER_HEADERS == (guint32) VLAN_FLAG_REORDER_HDR);
|
|
||||||
G_STATIC_ASSERT (NM_VLAN_FLAG_GVRP == (guint32) VLAN_FLAG_GVRP);
|
|
||||||
G_STATIC_ASSERT (NM_VLAN_FLAG_LOOSE_BINDING == (guint32) VLAN_FLAG_LOOSE_BINDING);
|
|
||||||
G_STATIC_ASSERT (NM_VLAN_FLAG_MVRP == (guint32) VLAN_FLAG_MVRP);
|
|
||||||
|
|
||||||
vlan_flags &= (guint32) NM_VLAN_FLAGS_ALL;
|
|
||||||
nlmsg = _nl_msg_new_link (RTM_NEWLINK,
|
|
||||||
NLM_F_CREATE | NLM_F_EXCL,
|
|
||||||
0,
|
|
||||||
name);
|
|
||||||
if (!nlmsg)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
NLA_PUT_U32 (nlmsg, IFLA_LINK, parent);
|
|
||||||
|
|
||||||
if (!_nl_msg_new_link_set_linkinfo_vlan (nlmsg,
|
|
||||||
vlan_id,
|
|
||||||
NM_VLAN_FLAGS_ALL,
|
|
||||||
vlan_flags,
|
|
||||||
NULL,
|
|
||||||
0,
|
|
||||||
NULL,
|
|
||||||
0))
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
return (do_add_link_with_lookup (platform, NM_LINK_TYPE_VLAN, name, nlmsg, out_link) >= 0);
|
|
||||||
nla_put_failure:
|
|
||||||
g_return_val_if_reached (FALSE);
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
link_ip6tnl_add (NMPlatform *platform,
|
link_ip6tnl_add (NMPlatform *platform,
|
||||||
const char *name,
|
const char *name,
|
||||||
@@ -9261,7 +9246,6 @@ nm_linux_platform_class_init (NMLinuxPlatformClass *klass)
|
|||||||
|
|
||||||
platform_class->link_can_assume = link_can_assume;
|
platform_class->link_can_assume = link_can_assume;
|
||||||
|
|
||||||
platform_class->vlan_add = vlan_add;
|
|
||||||
platform_class->link_vlan_change = link_vlan_change;
|
platform_class->link_vlan_change = link_vlan_change;
|
||||||
platform_class->link_wireguard_change = link_wireguard_change;
|
platform_class->link_wireguard_change = link_wireguard_change;
|
||||||
platform_class->link_vxlan_add = link_vxlan_add;
|
platform_class->link_vxlan_add = link_vxlan_add;
|
||||||
|
@@ -1214,6 +1214,10 @@ nm_platform_link_add (NMPlatform *self,
|
|||||||
buf[0] = '\0';
|
buf[0] = '\0';
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
case NM_LINK_TYPE_VLAN:
|
||||||
|
nm_utils_strbuf_append_str (&buf_p, &buf_len, ", ");
|
||||||
|
nm_platform_lnk_vlan_to_string ((const NMPlatformLnkVlan *) extra_data, buf_p, buf_len);
|
||||||
|
break;
|
||||||
case NM_LINK_TYPE_VETH:
|
case NM_LINK_TYPE_VETH:
|
||||||
nm_sprintf_buf (buf, ", veth-peer \"%s\"", (const char *) extra_data);
|
nm_sprintf_buf (buf, ", veth-peer \"%s\"", (const char *) extra_data);
|
||||||
break;
|
break;
|
||||||
@@ -2315,44 +2319,6 @@ nm_platform_link_wireguard_change (NMPlatform *self,
|
|||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
/**
|
|
||||||
* nm_platform_link_vlan_add:
|
|
||||||
* @self: platform instance
|
|
||||||
* @name: New interface name
|
|
||||||
* @vlanid: VLAN identifier
|
|
||||||
* @vlanflags: VLAN flags from libnm
|
|
||||||
* @out_link: on success, the link object
|
|
||||||
*
|
|
||||||
* Create a software VLAN device.
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
nm_platform_link_vlan_add (NMPlatform *self,
|
|
||||||
const char *name,
|
|
||||||
int parent,
|
|
||||||
int vlanid,
|
|
||||||
guint32 vlanflags,
|
|
||||||
const NMPlatformLink **out_link)
|
|
||||||
{
|
|
||||||
int r;
|
|
||||||
|
|
||||||
_CHECK_SELF (self, klass, -NME_BUG);
|
|
||||||
|
|
||||||
g_return_val_if_fail (parent >= 0, -NME_BUG);
|
|
||||||
g_return_val_if_fail (vlanid >= 0, -NME_BUG);
|
|
||||||
g_return_val_if_fail (name, -NME_BUG);
|
|
||||||
|
|
||||||
r = _link_add_check_existing (self, name, NM_LINK_TYPE_VLAN, out_link);
|
|
||||||
if (r < 0)
|
|
||||||
return r;
|
|
||||||
|
|
||||||
_LOG2D ("link: adding link vlan parent %d vlanid %d vlanflags %x",
|
|
||||||
parent, vlanid, vlanflags);
|
|
||||||
|
|
||||||
if (!klass->vlan_add (self, name, parent, vlanid, vlanflags, out_link))
|
|
||||||
return -NME_UNSPEC;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* nm_platform_link_vxlan_add:
|
* nm_platform_link_vxlan_add:
|
||||||
* @self: platform instance
|
* @self: platform instance
|
||||||
|
@@ -1029,7 +1029,6 @@ typedef struct {
|
|||||||
guint peers_len,
|
guint peers_len,
|
||||||
NMPlatformWireGuardChangeFlags change_flags);
|
NMPlatformWireGuardChangeFlags change_flags);
|
||||||
|
|
||||||
gboolean (*vlan_add) (NMPlatform *self, const char *name, int parent, int vlanid, guint32 vlanflags, const NMPlatformLink **out_link);
|
|
||||||
gboolean (*link_vlan_change) (NMPlatform *self,
|
gboolean (*link_vlan_change) (NMPlatform *self,
|
||||||
int ifindex,
|
int ifindex,
|
||||||
NMVlanFlags flags_mask,
|
NMVlanFlags flags_mask,
|
||||||
@@ -1437,6 +1436,30 @@ nm_platform_link_sit_add (NMPlatform *self,
|
|||||||
return nm_platform_link_add (self, NM_LINK_TYPE_SIT, name, 0, NULL, 0, props, out_link);
|
return nm_platform_link_add (self, NM_LINK_TYPE_SIT, name, 0, NULL, 0, props, out_link);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline int
|
||||||
|
nm_platform_link_vlan_add (NMPlatform *self,
|
||||||
|
const char *name,
|
||||||
|
int parent,
|
||||||
|
int vlanid,
|
||||||
|
guint32 vlanflags,
|
||||||
|
const NMPlatformLink **out_link)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (parent >= 0, -NME_BUG);
|
||||||
|
g_return_val_if_fail (vlanid >= 0, -NME_BUG);
|
||||||
|
|
||||||
|
return nm_platform_link_add (self,
|
||||||
|
NM_LINK_TYPE_VLAN,
|
||||||
|
name,
|
||||||
|
parent,
|
||||||
|
NULL,
|
||||||
|
0,
|
||||||
|
&((NMPlatformLnkVlan) {
|
||||||
|
.id = vlanid,
|
||||||
|
.flags = vlanflags,
|
||||||
|
}),
|
||||||
|
out_link);
|
||||||
|
}
|
||||||
|
|
||||||
gboolean nm_platform_link_delete (NMPlatform *self, int ifindex);
|
gboolean nm_platform_link_delete (NMPlatform *self, int ifindex);
|
||||||
|
|
||||||
gboolean nm_platform_link_set_netns (NMPlatform *self, int ifindex, int netns_fd);
|
gboolean nm_platform_link_set_netns (NMPlatform *self, int ifindex, int netns_fd);
|
||||||
@@ -1552,12 +1575,6 @@ const NMPlatformLnkVlan *nm_platform_link_get_lnk_vlan (NMPlatform *self, int if
|
|||||||
const NMPlatformLnkVxlan *nm_platform_link_get_lnk_vxlan (NMPlatform *self, int ifindex, const NMPlatformLink **out_link);
|
const NMPlatformLnkVxlan *nm_platform_link_get_lnk_vxlan (NMPlatform *self, int ifindex, const NMPlatformLink **out_link);
|
||||||
const NMPlatformLnkWireGuard *nm_platform_link_get_lnk_wireguard (NMPlatform *self, int ifindex, const NMPlatformLink **out_link);
|
const NMPlatformLnkWireGuard *nm_platform_link_get_lnk_wireguard (NMPlatform *self, int ifindex, const NMPlatformLink **out_link);
|
||||||
|
|
||||||
int nm_platform_link_vlan_add (NMPlatform *self,
|
|
||||||
const char *name,
|
|
||||||
int parent,
|
|
||||||
int vlanid,
|
|
||||||
guint32 vlanflags,
|
|
||||||
const NMPlatformLink **out_link);
|
|
||||||
gboolean nm_platform_link_vlan_set_ingress_map (NMPlatform *self, int ifindex, int from, int to);
|
gboolean nm_platform_link_vlan_set_ingress_map (NMPlatform *self, int ifindex, int from, int to);
|
||||||
gboolean nm_platform_link_vlan_set_egress_map (NMPlatform *self, int ifindex, int from, int to);
|
gboolean nm_platform_link_vlan_set_egress_map (NMPlatform *self, int ifindex, int from, int to);
|
||||||
gboolean nm_platform_link_vlan_change (NMPlatform *self,
|
gboolean nm_platform_link_vlan_change (NMPlatform *self,
|
||||||
|
Reference in New Issue
Block a user