summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2019-12-31 13:04:35 +0100
committerThomas Haller <thaller@redhat.com>2020-01-09 10:42:31 +0100
commit62b9d8ee33cba9045daee0ae2d886e64f86eb38f (patch)
tree3b7a063139df97d268052baa41f5cd3a6888a7fa
parent4029f9cd2ec63abb67e48636587c4defc22f5b5e (diff)
downloadNetworkManager-62b9d8ee33cba9045daee0ae2d886e64f86eb38f.tar.gz
platform: implement link_vlan_add via nm_platform_link_add()
-rw-r--r--src/platform/nm-fake-platform.c64
-rw-r--r--src/platform/nm-linux-platform.c66
-rw-r--r--src/platform/nm-platform.c42
-rw-r--r--src/platform/nm-platform.h31
4 files changed, 76 insertions, 127 deletions
diff --git a/src/platform/nm-fake-platform.c b/src/platform/nm-fake-platform.c
index 5a18368e39..224fa05e29 100644
--- a/src/platform/nm-fake-platform.c
+++ b/src/platform/nm-fake-platform.c
@@ -293,10 +293,21 @@ link_add (NMPlatform *platform,
NMPCacheOpsType cache_op;
NMPCacheOpsType cache_op_veth = NMP_CACHE_OPS_UNCHANGED;
const char *veth_peer = NULL;
+ NMPObject *dev_obj;
+ NMPObject *dev_lnk = NULL;
device = link_add_pre (platform, name, type, address, address_len);
- g_assert (parent == 0);
+ 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) == NM_IN_SET (type, NM_LINK_TYPE_VLAN));
switch (type) {
case NM_LINK_TYPE_VETH:
@@ -304,11 +315,22 @@ link_add (NMPlatform *platform,
g_assert (veth_peer);
device_veth = link_add_pre (platform, veth_peer, type, NULL, 0);
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:
g_assert (!extra_data);
break;
}
+ if (dev_lnk)
+ dev_obj->_link.netlink.lnk = dev_lnk;
+
link_add_prepare (platform, device, (NMPObject *) device->obj);
cache_op = nmp_cache_update_netlink (nm_platform_get_cache (platform),
(NMPObject *) device->obj,
@@ -719,45 +741,6 @@ link_release (NMPlatform *platform, int master_idx, int slave_idx)
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
link_vlan_change (NMPlatform *platform,
int ifindex,
@@ -1424,7 +1407,6 @@ nm_fake_platform_class_init (NMFakePlatformClass *klass)
platform_class->link_enslave = link_enslave;
platform_class->link_release = link_release;
- platform_class->vlan_add = vlan_add;
platform_class->link_vlan_change = link_vlan_change;
platform_class->link_vxlan_add = link_vxlan_add;
diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c
index 205e98d06f..3762de362e 100644
--- a/src/platform/nm-linux-platform.c
+++ b/src/platform/nm-linux-platform.c
@@ -3707,6 +3707,26 @@ _nl_msg_new_link_set_linkinfo (struct nl_msg *msg,
NLA_PUT_STRING (msg, IFLA_INFO_KIND, kind);
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: {
const char *veth_peer = extra_data;
const struct ifinfomsg ifi = { };
@@ -3794,6 +3814,11 @@ _nl_msg_new_link_set_linkinfo_vlan (struct nl_msg *msg,
guint i;
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)
nm_assert (msg);
@@ -7213,46 +7238,6 @@ link_get_dev_id (NMPlatform *platform, int ifindex)
}
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
link_ip6tnl_add (NMPlatform *platform,
const char *name,
const NMPlatformLnkIp6Tnl *props,
@@ -9261,7 +9246,6 @@ nm_linux_platform_class_init (NMLinuxPlatformClass *klass)
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_wireguard_change = link_wireguard_change;
platform_class->link_vxlan_add = link_vxlan_add;
diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c
index 28c3353aed..5eca968346 100644
--- a/src/platform/nm-platform.c
+++ b/src/platform/nm-platform.c
@@ -1214,6 +1214,10 @@ nm_platform_link_add (NMPlatform *self,
buf[0] = '\0';
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:
nm_sprintf_buf (buf, ", veth-peer \"%s\"", (const char *) extra_data);
break;
@@ -2316,44 +2320,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:
* @self: platform instance
* @name: New interface name
diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h
index 9c01ba44e1..725e5850b7 100644
--- a/src/platform/nm-platform.h
+++ b/src/platform/nm-platform.h
@@ -1029,7 +1029,6 @@ typedef struct {
guint peers_len,
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,
int ifindex,
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);
}
+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_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 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_egress_map (NMPlatform *self, int ifindex, int from, int to);
gboolean nm_platform_link_vlan_change (NMPlatform *self,