summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-01-09 10:42:45 +0100
committerThomas Haller <thaller@redhat.com>2020-01-09 10:42:45 +0100
commit5fc1b1a681a1f81461509c868a758af464b1c8ab (patch)
tree4359151a773a17bae674e61f23c05979601de1b2
parent7129e669c0e30aa62a681833506c5e312018128e (diff)
parenta90397b963306d8ef243d0b7b5e399a1cec363e3 (diff)
downloadNetworkManager-5fc1b1a681a1f81461509c868a758af464b1c8ab.tar.gz
platform,device: merge branch 'th/device-ip-tunnel-mac'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/377
-rw-r--r--src/devices/nm-device-bridge.c9
-rw-r--r--src/devices/nm-device-ip-tunnel.c42
-rw-r--r--src/devices/nm-device.c6
-rw-r--r--src/platform/nm-fake-platform.c132
-rw-r--r--src/platform/nm-linux-platform.c750
-rw-r--r--src/platform/nm-platform.c521
-rw-r--r--src/platform/nm-platform.h279
-rw-r--r--src/platform/nmp-object.c2
-rw-r--r--src/platform/tests/test-common.c2
-rw-r--r--src/platform/tests/test-link.c4
10 files changed, 618 insertions, 1129 deletions
diff --git a/src/devices/nm-device-bridge.c b/src/devices/nm-device-bridge.c
index 72a8ce2bb2..164fa0a1e8 100644
--- a/src/devices/nm-device-bridge.c
+++ b/src/devices/nm-device-bridge.c
@@ -736,10 +736,11 @@ create_and_realize (NMDevice *device,
if ( !hwaddr
&& nm_device_hw_addr_get_cloned (device, connection, FALSE,
&hwaddr_cloned, NULL, NULL)) {
- /* The cloned MAC address might by dynamic, for example with stable-id="${RANDOM}".
- * It's a bit odd that we first create the device with one dynamic address,
- * and later on may reset it to another. That is, because we don't cache
- * the dynamic address in @device, like we do during nm_device_hw_addr_set_cloned(). */
+ /* FIXME: we set the MAC address when creating the interface, while the
+ * NMDevice is still unrealized. As we afterwards realize the device, it
+ * forgets the parameters for the cloned MAC address, and in stage 1
+ * it might create a different MAC address. That should be fixed by
+ * better handling device realization. */
hwaddr = hwaddr_cloned;
}
diff --git a/src/devices/nm-device-ip-tunnel.c b/src/devices/nm-device-ip-tunnel.c
index 0becb5e568..87c8c7ba5b 100644
--- a/src/devices/nm-device-ip-tunnel.c
+++ b/src/devices/nm-device-ip-tunnel.c
@@ -657,11 +657,44 @@ create_and_realize (NMDevice *device,
gint64 val;
NMIPTunnelMode mode;
int r;
+ gs_free char *hwaddr = NULL;
+ guint8 mac_address[ETH_ALEN];
+ gboolean mac_address_valid = FALSE;
s_ip_tunnel = nm_connection_get_setting_ip_tunnel (connection);
- g_assert (s_ip_tunnel);
+ nm_assert (NM_IS_SETTING_IP_TUNNEL (s_ip_tunnel));
mode = nm_setting_ip_tunnel_get_mode (s_ip_tunnel);
+
+ if ( nm_device_hw_addr_get_cloned (device,
+ connection,
+ FALSE,
+ &hwaddr,
+ NULL,
+ NULL)
+ && hwaddr) {
+ /* FIXME: we set the MAC address when creating the interface, while the
+ * NMDevice is still unrealized. As we afterwards realize the device, it
+ * forgets the parameters for the cloned MAC address, and in stage 1
+ * it might create a different MAC address. That should be fixed by
+ * better handling device realization. */
+ if (!nm_utils_hwaddr_aton (hwaddr, mac_address, ETH_ALEN)) {
+ g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED,
+ "Invalid hardware address '%s'",
+ hwaddr);
+ g_return_val_if_reached (FALSE);
+ }
+
+ if (NM_IN_SET (mode, NM_IP_TUNNEL_MODE_GRE)) {
+ g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED,
+ "Invalid hardware address '%s' for tunnel type",
+ hwaddr);
+ return FALSE;
+ }
+
+ mac_address_valid = TRUE;
+ }
+
switch (mode) {
case NM_IP_TUNNEL_MODE_GRETAP:
lnk_gre.is_tap = TRUE;
@@ -702,7 +735,12 @@ create_and_realize (NMDevice *device,
lnk_gre.output_flags = NM_GRE_KEY;
}
- r = nm_platform_link_gre_add (nm_device_get_platform (device), iface, &lnk_gre, out_plink);
+ r = nm_platform_link_gre_add (nm_device_get_platform (device),
+ iface,
+ mac_address_valid ? mac_address : NULL,
+ mac_address_valid ? ETH_ALEN : 0,
+ &lnk_gre,
+ out_plink);
if (r < 0) {
g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED,
"Failed to create GRE interface '%s' for '%s': %s",
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
index 56858f859e..3898d1565a 100644
--- a/src/devices/nm-device.c
+++ b/src/devices/nm-device.c
@@ -16265,8 +16265,10 @@ _hw_addr_set (NMDevice *self,
}
if ( priv->hw_addr_len
- && priv->hw_addr_len != addr_len)
- g_return_val_if_reached (FALSE);
+ && priv->hw_addr_len != addr_len) {
+ _LOGT (LOGD_DEVICE, "set-hw-addr: setting MAC address to '%s' (%s, %s) failed because of wrong address length (should be %u bytes)", addr, operation, detail, priv->hw_addr_len);
+ return FALSE;
+ }
_LOGT (LOGD_DEVICE, "set-hw-addr: setting MAC address to '%s' (%s, %s)...", addr, operation, detail);
diff --git a/src/platform/nm-fake-platform.c b/src/platform/nm-fake-platform.c
index 9fa2791fec..124432a73c 100644
--- a/src/platform/nm-fake-platform.c
+++ b/src/platform/nm-fake-platform.c
@@ -276,11 +276,12 @@ link_add_pre (NMPlatform *platform,
static int
link_add (NMPlatform *platform,
- const char *name,
NMLinkType type,
- const char *veth_peer,
+ const char *name,
+ int parent,
const void *address,
size_t address_len,
+ gconstpointer extra_data,
const NMPlatformLink **out_link)
{
NMFakePlatformLink *device;
@@ -291,14 +292,52 @@ link_add (NMPlatform *platform,
nm_auto_nmpobj const NMPObject *obj_new_veth = NULL;
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);
- if (veth_peer) {
- g_assert (type == NM_LINK_TYPE_VETH);
+ 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:
+ veth_peer = extra_data;
+ g_assert (veth_peer);
device_veth = link_add_pre (platform, veth_peer, type, NULL, 0);
- } else
- g_assert (type != NM_LINK_TYPE_VETH);
+ 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;
+ }
+ case NM_LINK_TYPE_VXLAN: {
+ const NMPlatformLnkVxlan *props = extra_data;
+
+ g_assert (props);
+
+ dev_lnk = nmp_object_new (NMP_OBJECT_TYPE_LNK_VXLAN, 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),
@@ -710,45 +749,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,
@@ -764,35 +764,6 @@ link_vlan_change (NMPlatform *platform,
return FALSE;
}
-static void
-_vxlan_add_prepare (NMPlatform *platform,
- NMFakePlatformLink *device,
- gconstpointer user_data)
-{
- const NMPlatformLnkVxlan *props = user_data;
- NMPObject *obj_tmp;
- NMPObject *lnk;
-
- obj_tmp = (NMPObject *) device->obj;
-
- lnk = nmp_object_new (NMP_OBJECT_TYPE_LNK_VXLAN, NULL);
- lnk->lnk_vxlan = *props;
-
- obj_tmp->link.parent = props->parent_ifindex;
- obj_tmp->_link.netlink.lnk = lnk;
-}
-
-static gboolean
-link_vxlan_add (NMPlatform *platform,
- const char *name,
- const NMPlatformLnkVxlan *props,
- const NMPlatformLink **out_link)
-{
- link_add_one (platform, name, NM_LINK_TYPE_VXLAN,
- _vxlan_add_prepare, props, out_link);
- return TRUE;
-}
-
struct infiniband_add_data {
int parent;
int p_key;
@@ -1354,13 +1325,10 @@ nm_fake_platform_setup (void)
nm_platform_setup (platform);
- /* add loopback interface */
- link_add (platform, "lo", NM_LINK_TYPE_LOOPBACK, NULL, NULL, 0, NULL);
-
- /* add some ethernets */
- link_add (platform, "eth0", NM_LINK_TYPE_ETHERNET, NULL, NULL, 0, NULL);
- link_add (platform, "eth1", NM_LINK_TYPE_ETHERNET, NULL, NULL, 0, NULL);
- link_add (platform, "eth2", NM_LINK_TYPE_ETHERNET, NULL, NULL, 0, NULL);
+ link_add (platform, NM_LINK_TYPE_LOOPBACK, "lo", 0, NULL, 0, NULL, NULL);
+ link_add (platform, NM_LINK_TYPE_ETHERNET, "eth0", 0, NULL, 0, NULL, NULL);
+ link_add (platform, NM_LINK_TYPE_ETHERNET, "eth1", 0, NULL, 0, NULL, NULL);
+ link_add (platform, NM_LINK_TYPE_ETHERNET, "eth2", 0, NULL, 0, NULL, NULL);
}
static void
@@ -1418,9 +1386,7 @@ 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;
platform_class->infiniband_partition_add = infiniband_partition_add;
platform_class->infiniband_partition_delete = infiniband_partition_delete;
diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c
index f7a4504100..23ebeaa3ab 100644
--- a/src/platform/nm-linux-platform.c
+++ b/src/platform/nm-linux-platform.c
@@ -3689,13 +3689,13 @@ nla_put_failure:
static gboolean
_nl_msg_new_link_set_linkinfo (struct nl_msg *msg,
NMLinkType link_type,
- const char *veth_peer)
+ gconstpointer extra_data)
{
struct nlattr *info;
+ struct nlattr *data = NULL;
const char *kind;
nm_assert (msg);
- nm_assert (!!veth_peer == (link_type == NM_LINK_TYPE_VETH));
kind = nm_link_type_to_rtnl_type_string (link_type);
if (!kind)
@@ -3706,9 +3706,78 @@ _nl_msg_new_link_set_linkinfo (struct nl_msg *msg,
NLA_PUT_STRING (msg, IFLA_INFO_KIND, kind);
- if (veth_peer) {
+ 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_VXLAN: {
+ const NMPlatformLnkVxlan *props = extra_data;
+
+ nm_assert (extra_data);
+
+ if (!(data = nla_nest_start (msg, IFLA_INFO_DATA)))
+ goto nla_put_failure;
+
+ NLA_PUT_U32 (msg, IFLA_VXLAN_ID, props->id);
+
+ if (props->group)
+ NLA_PUT (msg, IFLA_VXLAN_GROUP, sizeof (props->group), &props->group);
+ else if (memcmp (&props->group6, &in6addr_any, sizeof (in6addr_any)))
+ NLA_PUT (msg, IFLA_VXLAN_GROUP6, sizeof (props->group6), &props->group6);
+
+ if (props->local)
+ NLA_PUT (msg, IFLA_VXLAN_LOCAL, sizeof (props->local), &props->local);
+ else if (memcmp (&props->local6, &in6addr_any, sizeof (in6addr_any)))
+ NLA_PUT (msg, IFLA_VXLAN_LOCAL6, sizeof (props->local6), &props->local6);
+
+ if (props->parent_ifindex >= 0)
+ NLA_PUT_U32 (msg, IFLA_VXLAN_LINK, props->parent_ifindex);
+
+ if ( props->src_port_min
+ || props->src_port_max) {
+ struct nm_ifla_vxlan_port_range port_range = {
+ .low = htons (props->src_port_min),
+ .high = htons (props->src_port_max),
+ };
+
+ NLA_PUT (msg, IFLA_VXLAN_PORT_RANGE, sizeof (port_range), &port_range);
+ }
+
+ NLA_PUT_U16 (msg, IFLA_VXLAN_PORT, htons (props->dst_port));
+ NLA_PUT_U8 (msg, IFLA_VXLAN_TOS, props->tos);
+ NLA_PUT_U8 (msg, IFLA_VXLAN_TTL, props->ttl);
+ NLA_PUT_U32 (msg, IFLA_VXLAN_AGEING, props->ageing);
+ NLA_PUT_U32 (msg, IFLA_VXLAN_LIMIT, props->limit);
+ NLA_PUT_U8 (msg, IFLA_VXLAN_LEARNING, !!props->learning);
+ NLA_PUT_U8 (msg, IFLA_VXLAN_PROXY, !!props->proxy);
+ NLA_PUT_U8 (msg, IFLA_VXLAN_RSC, !!props->rsc);
+ NLA_PUT_U8 (msg, IFLA_VXLAN_L2MISS, !!props->l2miss);
+ NLA_PUT_U8 (msg, IFLA_VXLAN_L3MISS, !!props->l3miss);
+ break;
+ }
+ case NM_LINK_TYPE_VETH: {
+ const char *veth_peer = extra_data;
const struct ifinfomsg ifi = { };
- struct nlattr *data, *info_peer;
+ struct nlattr *info_peer;
+
+ nm_assert (veth_peer);
if (!(data = nla_nest_start (msg, IFLA_INFO_DATA)))
goto nla_put_failure;
@@ -3718,8 +3787,174 @@ _nl_msg_new_link_set_linkinfo (struct nl_msg *msg,
goto nla_put_failure;
NLA_PUT_STRING (msg, IFLA_IFNAME, veth_peer);
nla_nest_end (msg, info_peer);
- nla_nest_end (msg, data);
+ break;
}
+ case NM_LINK_TYPE_GRE:
+ case NM_LINK_TYPE_GRETAP: {
+ const NMPlatformLnkGre *props = extra_data;
+
+ nm_assert (props);
+ nm_assert (props->is_tap == (link_type == NM_LINK_TYPE_GRETAP));
+
+ if (!(data = nla_nest_start (msg, IFLA_INFO_DATA)))
+ goto nla_put_failure;
+
+ if (props->parent_ifindex)
+ NLA_PUT_U32 (msg, IFLA_GRE_LINK, props->parent_ifindex);
+ NLA_PUT_U32 (msg, IFLA_GRE_LOCAL, props->local);
+ NLA_PUT_U32 (msg, IFLA_GRE_REMOTE, props->remote);
+ NLA_PUT_U8 (msg, IFLA_GRE_TTL, props->ttl);
+ NLA_PUT_U8 (msg, IFLA_GRE_TOS, props->tos);
+ NLA_PUT_U8 (msg, IFLA_GRE_PMTUDISC, !!props->path_mtu_discovery);
+ NLA_PUT_U32 (msg, IFLA_GRE_IKEY, htonl (props->input_key));
+ NLA_PUT_U32 (msg, IFLA_GRE_OKEY, htonl (props->output_key));
+ NLA_PUT_U16 (msg, IFLA_GRE_IFLAGS, htons (props->input_flags));
+ NLA_PUT_U16 (msg, IFLA_GRE_OFLAGS, htons (props->output_flags));
+ break;
+ }
+ case NM_LINK_TYPE_SIT: {
+ const NMPlatformLnkSit *props = extra_data;
+
+ nm_assert (props);
+
+ if (!(data = nla_nest_start (msg, IFLA_INFO_DATA)))
+ goto nla_put_failure;
+
+ if (props->parent_ifindex)
+ NLA_PUT_U32 (msg, IFLA_IPTUN_LINK, props->parent_ifindex);
+ NLA_PUT_U32 (msg, IFLA_IPTUN_LOCAL, props->local);
+ NLA_PUT_U32 (msg, IFLA_IPTUN_REMOTE, props->remote);
+ NLA_PUT_U8 (msg, IFLA_IPTUN_TTL, props->ttl);
+ NLA_PUT_U8 (msg, IFLA_IPTUN_TOS, props->tos);
+ NLA_PUT_U8 (msg, IFLA_IPTUN_PMTUDISC, !!props->path_mtu_discovery);
+ break;
+ }
+ case NM_LINK_TYPE_IP6TNL: {
+ const NMPlatformLnkIp6Tnl *props = extra_data;
+ guint32 flowinfo;
+
+ nm_assert (props);
+ nm_assert (!props->is_gre);
+
+ if (!(data = nla_nest_start (msg, IFLA_INFO_DATA)))
+ goto nla_put_failure;
+
+ if (props->parent_ifindex)
+ NLA_PUT_U32 (msg, IFLA_IPTUN_LINK, props->parent_ifindex);
+
+ if (memcmp (&props->local, &in6addr_any, sizeof (in6addr_any)))
+ NLA_PUT (msg, IFLA_IPTUN_LOCAL, sizeof (props->local), &props->local);
+ if (memcmp (&props->remote, &in6addr_any, sizeof (in6addr_any)))
+ NLA_PUT (msg, IFLA_IPTUN_REMOTE, sizeof (props->remote), &props->remote);
+
+ NLA_PUT_U8 (msg, IFLA_IPTUN_TTL, props->ttl);
+ NLA_PUT_U8 (msg, IFLA_IPTUN_ENCAP_LIMIT, props->encap_limit);
+
+ flowinfo = props->flow_label & IP6_FLOWINFO_FLOWLABEL_MASK;
+ flowinfo |= (props->tclass << IP6_FLOWINFO_TCLASS_SHIFT)
+ & IP6_FLOWINFO_TCLASS_MASK;
+ NLA_PUT_U32 (msg, IFLA_IPTUN_FLOWINFO, htonl (flowinfo));
+ NLA_PUT_U8 (msg, IFLA_IPTUN_PROTO, props->proto);
+ NLA_PUT_U32 (msg, IFLA_IPTUN_FLAGS, props->flags);
+ break;
+ }
+ case NM_LINK_TYPE_IP6GRE:
+ case NM_LINK_TYPE_IP6GRETAP: {
+ const NMPlatformLnkIp6Tnl *props = extra_data;
+ guint32 flowinfo;
+
+ nm_assert (props);
+ nm_assert (props->is_gre);
+
+ if (!(data = nla_nest_start (msg, IFLA_INFO_DATA)))
+ goto nla_put_failure;
+
+ if (props->parent_ifindex)
+ NLA_PUT_U32 (msg, IFLA_GRE_LINK, props->parent_ifindex);
+
+ NLA_PUT_U32 (msg, IFLA_GRE_IKEY, htonl (props->input_key));
+ NLA_PUT_U32 (msg, IFLA_GRE_OKEY, htonl (props->output_key));
+ NLA_PUT_U16 (msg, IFLA_GRE_IFLAGS, htons (props->input_flags));
+ NLA_PUT_U16 (msg, IFLA_GRE_OFLAGS, htons (props->output_flags));
+
+ if (memcmp (&props->local, &in6addr_any, sizeof (in6addr_any)))
+ NLA_PUT (msg, IFLA_GRE_LOCAL, sizeof (props->local), &props->local);
+ if (memcmp (&props->remote, &in6addr_any, sizeof (in6addr_any)))
+ NLA_PUT (msg, IFLA_GRE_REMOTE, sizeof (props->remote), &props->remote);
+
+ NLA_PUT_U8 (msg, IFLA_GRE_TTL, props->ttl);
+ NLA_PUT_U8 (msg, IFLA_GRE_ENCAP_LIMIT, props->encap_limit);
+
+ flowinfo = props->flow_label & IP6_FLOWINFO_FLOWLABEL_MASK;
+ flowinfo |= (props->tclass << IP6_FLOWINFO_TCLASS_SHIFT)
+ & IP6_FLOWINFO_TCLASS_MASK;
+ NLA_PUT_U32 (msg, IFLA_GRE_FLOWINFO, htonl (flowinfo));
+ NLA_PUT_U32 (msg, IFLA_GRE_FLAGS, props->flags);
+ break;
+ }
+ case NM_LINK_TYPE_IPIP: {
+ const NMPlatformLnkIpIp *props = extra_data;
+
+ nm_assert (props);
+
+ if (!(data = nla_nest_start (msg, IFLA_INFO_DATA)))
+ goto nla_put_failure;
+
+ if (props->parent_ifindex)
+ NLA_PUT_U32 (msg, IFLA_IPTUN_LINK, props->parent_ifindex);
+ NLA_PUT_U32 (msg, IFLA_IPTUN_LOCAL, props->local);
+ NLA_PUT_U32 (msg, IFLA_IPTUN_REMOTE, props->remote);
+ NLA_PUT_U8 (msg, IFLA_IPTUN_TTL, props->ttl);
+ NLA_PUT_U8 (msg, IFLA_IPTUN_TOS, props->tos);
+ NLA_PUT_U8 (msg, IFLA_IPTUN_PMTUDISC, !!props->path_mtu_discovery);
+ break;
+ }
+ case NM_LINK_TYPE_MACSEC: {
+ const NMPlatformLnkMacsec *props = extra_data;
+
+ nm_assert (props);
+
+ if (!(data = nla_nest_start (msg, IFLA_INFO_DATA)))
+ goto nla_put_failure;
+
+ if (props->icv_length)
+ NLA_PUT_U8 (msg, IFLA_MACSEC_ICV_LEN, 16);
+ if (props->cipher_suite)
+ NLA_PUT_U64 (msg, IFLA_MACSEC_CIPHER_SUITE, props->cipher_suite);
+ if (props->replay_protect)
+ NLA_PUT_U32 (msg, IFLA_MACSEC_WINDOW, props->window);
+
+ NLA_PUT_U64 (msg, IFLA_MACSEC_SCI, htobe64 (props->sci));
+ NLA_PUT_U8 (msg, IFLA_MACSEC_ENCODING_SA, props->encoding_sa);
+ NLA_PUT_U8 (msg, IFLA_MACSEC_ENCRYPT, props->encrypt);
+ NLA_PUT_U8 (msg, IFLA_MACSEC_PROTECT, props->protect);
+ NLA_PUT_U8 (msg, IFLA_MACSEC_INC_SCI, props->include_sci);
+ NLA_PUT_U8 (msg, IFLA_MACSEC_ES, props->es);
+ NLA_PUT_U8 (msg, IFLA_MACSEC_SCB, props->scb);
+ NLA_PUT_U8 (msg, IFLA_MACSEC_REPLAY_PROTECT, props->replay_protect);
+ NLA_PUT_U8 (msg, IFLA_MACSEC_VALIDATION, props->validation);
+ break;
+ };
+ case NM_LINK_TYPE_MACVTAP:
+ case NM_LINK_TYPE_MACVLAN: {
+ const NMPlatformLnkMacvlan *props = extra_data;
+
+ nm_assert (props);
+
+ if (!(data = nla_nest_start (msg, IFLA_INFO_DATA)))
+ goto nla_put_failure;
+
+ NLA_PUT_U32 (msg, IFLA_MACVLAN_MODE, props->mode);
+ NLA_PUT_U16 (msg, IFLA_MACVLAN_FLAGS, props->no_promisc ? MACVLAN_FLAG_NOPROMISC : 0);
+ break;
+ }
+ default:
+ nm_assert (!extra_data);
+ break;
+ }
+
+ if (data)
+ nla_nest_end (msg, data);
nla_nest_end (msg, info);
@@ -3743,6 +3978,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);
@@ -6491,11 +6731,12 @@ out:
static int
link_add (NMPlatform *platform,
- const char *name,
NMLinkType type,
- const char *veth_peer,
+ const char *name,
+ int parent,
const void *address,
size_t address_len,
+ gconstpointer extra_data,
const NMPlatformLink **out_link)
{
nm_auto_nlmsg struct nl_msg *nlmsg = NULL;
@@ -6519,10 +6760,13 @@ link_add (NMPlatform *platform,
if (!nlmsg)
return -NME_UNSPEC;
+ if (parent > 0)
+ NLA_PUT_U32 (nlmsg, IFLA_LINK, parent);
+
if (address && address_len)
NLA_PUT (nlmsg, IFLA_ADDRESS, address_len, address);
- if (!_nl_msg_new_link_set_linkinfo (nlmsg, type, veth_peer))
+ if (!_nl_msg_new_link_set_linkinfo (nlmsg, type, extra_data))
return -NME_UNSPEC;
return do_add_link_with_lookup (platform, type, name, nlmsg, out_link);
@@ -7158,385 +7402,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_gre_add (NMPlatform *platform,
- const char *name,
- const NMPlatformLnkGre *props,
- const NMPlatformLink **out_link)
-{
- nm_auto_nlmsg struct nl_msg *nlmsg = NULL;
- struct nlattr *info;
- struct nlattr *data;
-
- nlmsg = _nl_msg_new_link (RTM_NEWLINK,
- NLM_F_CREATE | NLM_F_EXCL,
- 0,
- name);
- if (!nlmsg)
- return FALSE;
-
- if (!(info = nla_nest_start (nlmsg, IFLA_LINKINFO)))
- goto nla_put_failure;
-
- NLA_PUT_STRING (nlmsg, IFLA_INFO_KIND, props->is_tap ? "gretap" : "gre");
-
- if (!(data = nla_nest_start (nlmsg, IFLA_INFO_DATA)))
- goto nla_put_failure;
-
- if (props->parent_ifindex)
- NLA_PUT_U32 (nlmsg, IFLA_GRE_LINK, props->parent_ifindex);
- NLA_PUT_U32 (nlmsg, IFLA_GRE_LOCAL, props->local);
- NLA_PUT_U32 (nlmsg, IFLA_GRE_REMOTE, props->remote);
- NLA_PUT_U8 (nlmsg, IFLA_GRE_TTL, props->ttl);
- NLA_PUT_U8 (nlmsg, IFLA_GRE_TOS, props->tos);
- NLA_PUT_U8 (nlmsg, IFLA_GRE_PMTUDISC, !!props->path_mtu_discovery);
- NLA_PUT_U32 (nlmsg, IFLA_GRE_IKEY, htonl (props->input_key));
- NLA_PUT_U32 (nlmsg, IFLA_GRE_OKEY, htonl (props->output_key));
- NLA_PUT_U16 (nlmsg, IFLA_GRE_IFLAGS, htons (props->input_flags));
- NLA_PUT_U16 (nlmsg, IFLA_GRE_OFLAGS, htons (props->output_flags));
-
- nla_nest_end (nlmsg, data);
- nla_nest_end (nlmsg, info);
-
- return (do_add_link_with_lookup (platform,
- props->is_tap ? NM_LINK_TYPE_GRETAP : NM_LINK_TYPE_GRE,
- 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,
- const NMPlatformLink **out_link)
-{
- nm_auto_nlmsg struct nl_msg *nlmsg = NULL;
- struct nlattr *info;
- struct nlattr *data;
- guint32 flowinfo;
-
- g_return_val_if_fail (!props->is_gre, FALSE);
-
- nlmsg = _nl_msg_new_link (RTM_NEWLINK,
- NLM_F_CREATE | NLM_F_EXCL,
- 0,
- name);
- if (!nlmsg)
- return FALSE;
-
- if (!(info = nla_nest_start (nlmsg, IFLA_LINKINFO)))
- goto nla_put_failure;
-
- NLA_PUT_STRING (nlmsg, IFLA_INFO_KIND, "ip6tnl");
-
- if (!(data = nla_nest_start (nlmsg, IFLA_INFO_DATA)))
- goto nla_put_failure;
-
- if (props->parent_ifindex)
- NLA_PUT_U32 (nlmsg, IFLA_IPTUN_LINK, props->parent_ifindex);
-
- if (memcmp (&props->local, &in6addr_any, sizeof (in6addr_any)))
- NLA_PUT (nlmsg, IFLA_IPTUN_LOCAL, sizeof (props->local), &props->local);
- if (memcmp (&props->remote, &in6addr_any, sizeof (in6addr_any)))
- NLA_PUT (nlmsg, IFLA_IPTUN_REMOTE, sizeof (props->remote), &props->remote);
-
- NLA_PUT_U8 (nlmsg, IFLA_IPTUN_TTL, props->ttl);
- NLA_PUT_U8 (nlmsg, IFLA_IPTUN_ENCAP_LIMIT, props->encap_limit);
-
- flowinfo = props->flow_label & IP6_FLOWINFO_FLOWLABEL_MASK;
- flowinfo |= (props->tclass << IP6_FLOWINFO_TCLASS_SHIFT)
- & IP6_FLOWINFO_TCLASS_MASK;
- NLA_PUT_U32 (nlmsg, IFLA_IPTUN_FLOWINFO, htonl (flowinfo));
- NLA_PUT_U8 (nlmsg, IFLA_IPTUN_PROTO, props->proto);
- NLA_PUT_U32 (nlmsg, IFLA_IPTUN_FLAGS, props->flags);
-
- nla_nest_end (nlmsg, data);
- nla_nest_end (nlmsg, info);
-
- return (do_add_link_with_lookup (platform, NM_LINK_TYPE_IP6TNL, name, nlmsg, out_link) >= 0);
-nla_put_failure:
- g_return_val_if_reached (FALSE);
-}
-
-static gboolean
-link_ip6gre_add (NMPlatform *platform,
- const char *name,
- const NMPlatformLnkIp6Tnl *props,
- const NMPlatformLink **out_link)
-{
- nm_auto_nlmsg struct nl_msg *nlmsg = NULL;
- struct nlattr *info;
- struct nlattr *data;
- guint32 flowinfo;
-
- g_return_val_if_fail (props->is_gre, FALSE);
-
- nlmsg = _nl_msg_new_link (RTM_NEWLINK,
- NLM_F_CREATE | NLM_F_EXCL,
- 0,
- name);
- if (!nlmsg)
- return FALSE;
-
- if (!(info = nla_nest_start (nlmsg, IFLA_LINKINFO)))
- goto nla_put_failure;
-
- NLA_PUT_STRING (nlmsg, IFLA_INFO_KIND, props->is_tap ? "ip6gretap" : "ip6gre");
-
- if (!(data = nla_nest_start (nlmsg, IFLA_INFO_DATA)))
- goto nla_put_failure;
-
- if (props->parent_ifindex)
- NLA_PUT_U32 (nlmsg, IFLA_GRE_LINK, props->parent_ifindex);
-
- NLA_PUT_U32 (nlmsg, IFLA_GRE_IKEY, htonl (props->input_key));
- NLA_PUT_U32 (nlmsg, IFLA_GRE_OKEY, htonl (props->output_key));
- NLA_PUT_U16 (nlmsg, IFLA_GRE_IFLAGS, htons (props->input_flags));
- NLA_PUT_U16 (nlmsg, IFLA_GRE_OFLAGS, htons (props->output_flags));
-
- if (memcmp (&props->local, &in6addr_any, sizeof (in6addr_any)))
- NLA_PUT (nlmsg, IFLA_GRE_LOCAL, sizeof (props->local), &props->local);
- if (memcmp (&props->remote, &in6addr_any, sizeof (in6addr_any)))
- NLA_PUT (nlmsg, IFLA_GRE_REMOTE, sizeof (props->remote), &props->remote);
-
- NLA_PUT_U8 (nlmsg, IFLA_GRE_TTL, props->ttl);
- NLA_PUT_U8 (nlmsg, IFLA_GRE_ENCAP_LIMIT, props->encap_limit);
-
- flowinfo = props->flow_label & IP6_FLOWINFO_FLOWLABEL_MASK;
- flowinfo |= (props->tclass << IP6_FLOWINFO_TCLASS_SHIFT)
- & IP6_FLOWINFO_TCLASS_MASK;
- NLA_PUT_U32 (nlmsg, IFLA_GRE_FLOWINFO, htonl (flowinfo));
- NLA_PUT_U32 (nlmsg, IFLA_GRE_FLAGS, props->flags);
-
- nla_nest_end (nlmsg, data);
- nla_nest_end (nlmsg, info);
-
- return (do_add_link_with_lookup (platform,
- props->is_tap ? NM_LINK_TYPE_IP6GRETAP : NM_LINK_TYPE_IP6GRE,
- name, nlmsg, out_link) >= 0);
-nla_put_failure:
- g_return_val_if_reached (FALSE);
-}
-
-static gboolean
-link_ipip_add (NMPlatform *platform,
- const char *name,
- const NMPlatformLnkIpIp *props,
- const NMPlatformLink **out_link)
-{
- nm_auto_nlmsg struct nl_msg *nlmsg = NULL;
- struct nlattr *info;
- struct nlattr *data;
-
- nlmsg = _nl_msg_new_link (RTM_NEWLINK,
- NLM_F_CREATE | NLM_F_EXCL,
- 0,
- name);
- if (!nlmsg)
- return FALSE;
-
- if (!(info = nla_nest_start (nlmsg, IFLA_LINKINFO)))
- goto nla_put_failure;
-
- NLA_PUT_STRING (nlmsg, IFLA_INFO_KIND, "ipip");
-
- if (!(data = nla_nest_start (nlmsg, IFLA_INFO_DATA)))
- goto nla_put_failure;
-
- if (props->parent_ifindex)
- NLA_PUT_U32 (nlmsg, IFLA_IPTUN_LINK, props->parent_ifindex);
- NLA_PUT_U32 (nlmsg, IFLA_IPTUN_LOCAL, props->local);
- NLA_PUT_U32 (nlmsg, IFLA_IPTUN_REMOTE, props->remote);
- NLA_PUT_U8 (nlmsg, IFLA_IPTUN_TTL, props->ttl);
- NLA_PUT_U8 (nlmsg, IFLA_IPTUN_TOS, props->tos);
- NLA_PUT_U8 (nlmsg, IFLA_IPTUN_PMTUDISC, !!props->path_mtu_discovery);
-
- nla_nest_end (nlmsg, data);
- nla_nest_end (nlmsg, info);
-
- return (do_add_link_with_lookup (platform, NM_LINK_TYPE_IPIP, name, nlmsg, out_link) >= 0);
-nla_put_failure:
- g_return_val_if_reached (FALSE);
-}
-
-static gboolean
-link_macsec_add (NMPlatform *platform,
- const char *name,
- int parent,
- const NMPlatformLnkMacsec *props,
- const NMPlatformLink **out_link)
-{
- nm_auto_nlmsg struct nl_msg *nlmsg = NULL;
- struct nlattr *info;
- struct nlattr *data;
-
- 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 (!(info = nla_nest_start (nlmsg, IFLA_LINKINFO)))
- goto nla_put_failure;
-
- NLA_PUT_STRING (nlmsg, IFLA_INFO_KIND, "macsec");
-
- if (!(data = nla_nest_start (nlmsg, IFLA_INFO_DATA)))
- goto nla_put_failure;
-
- if (props->icv_length)
- NLA_PUT_U8 (nlmsg, IFLA_MACSEC_ICV_LEN, 16);
- if (props->cipher_suite)
- NLA_PUT_U64 (nlmsg, IFLA_MACSEC_CIPHER_SUITE, props->cipher_suite);
- if (props->replay_protect)
- NLA_PUT_U32 (nlmsg, IFLA_MACSEC_WINDOW, props->window);
-
- NLA_PUT_U64 (nlmsg, IFLA_MACSEC_SCI, htobe64 (props->sci));
- NLA_PUT_U8 (nlmsg, IFLA_MACSEC_ENCODING_SA, props->encoding_sa);
- NLA_PUT_U8 (nlmsg, IFLA_MACSEC_ENCRYPT, props->encrypt);
- NLA_PUT_U8 (nlmsg, IFLA_MACSEC_PROTECT, props->protect);
- NLA_PUT_U8 (nlmsg, IFLA_MACSEC_INC_SCI, props->include_sci);
- NLA_PUT_U8 (nlmsg, IFLA_MACSEC_ES, props->es);
- NLA_PUT_U8 (nlmsg, IFLA_MACSEC_SCB, props->scb);
- NLA_PUT_U8 (nlmsg, IFLA_MACSEC_REPLAY_PROTECT, props->replay_protect);
- NLA_PUT_U8 (nlmsg, IFLA_MACSEC_VALIDATION, props->validation);
-
- nla_nest_end (nlmsg, data);
- nla_nest_end (nlmsg, info);
-
- return (do_add_link_with_lookup (platform,
- NM_LINK_TYPE_MACSEC,
- name, nlmsg, out_link) >= 0);
-nla_put_failure:
- g_return_val_if_reached (FALSE);
-}
-
-static gboolean
-link_macvlan_add (NMPlatform *platform,
- const char *name,
- int parent,
- const NMPlatformLnkMacvlan *props,
- const NMPlatformLink **out_link)
-{
- nm_auto_nlmsg struct nl_msg *nlmsg = NULL;
- struct nlattr *info;
- struct nlattr *data;
-
- 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 (!(info = nla_nest_start (nlmsg, IFLA_LINKINFO)))
- goto nla_put_failure;
-
- NLA_PUT_STRING (nlmsg, IFLA_INFO_KIND, props->tap ? "macvtap" : "macvlan");
-
- if (!(data = nla_nest_start (nlmsg, IFLA_INFO_DATA)))
- goto nla_put_failure;
-
- NLA_PUT_U32 (nlmsg, IFLA_MACVLAN_MODE, props->mode);
- NLA_PUT_U16 (nlmsg, IFLA_MACVLAN_FLAGS, props->no_promisc ? MACVLAN_FLAG_NOPROMISC : 0);
-
- nla_nest_end (nlmsg, data);
- nla_nest_end (nlmsg, info);
-
- return (do_add_link_with_lookup (platform,
- props->tap ? NM_LINK_TYPE_MACVTAP : NM_LINK_TYPE_MACVLAN,
- name, nlmsg, out_link) >= 0);
-nla_put_failure:
- g_return_val_if_reached (FALSE);
-}
-
-static gboolean
-link_sit_add (NMPlatform *platform,
- const char *name,
- const NMPlatformLnkSit *props,
- const NMPlatformLink **out_link)
-{
- nm_auto_nlmsg struct nl_msg *nlmsg = NULL;
- struct nlattr *info;
- struct nlattr *data;
-
- nlmsg = _nl_msg_new_link (RTM_NEWLINK,
- NLM_F_CREATE | NLM_F_EXCL,
- 0,
- name);
- if (!nlmsg)
- return FALSE;
-
- if (!(info = nla_nest_start (nlmsg, IFLA_LINKINFO)))
- goto nla_put_failure;
-
- NLA_PUT_STRING (nlmsg, IFLA_INFO_KIND, "sit");
-
- if (!(data = nla_nest_start (nlmsg, IFLA_INFO_DATA)))
- goto nla_put_failure;
-
- if (props->parent_ifindex)
- NLA_PUT_U32 (nlmsg, IFLA_IPTUN_LINK, props->parent_ifindex);
- NLA_PUT_U32 (nlmsg, IFLA_IPTUN_LOCAL, props->local);
- NLA_PUT_U32 (nlmsg, IFLA_IPTUN_REMOTE, props->remote);
- NLA_PUT_U8 (nlmsg, IFLA_IPTUN_TTL, props->ttl);
- NLA_PUT_U8 (nlmsg, IFLA_IPTUN_TOS, props->tos);
- NLA_PUT_U8 (nlmsg, IFLA_IPTUN_PMTUDISC, !!props->path_mtu_discovery);
-
- nla_nest_end (nlmsg, data);
- nla_nest_end (nlmsg, info);
-
- return (do_add_link_with_lookup (platform, NM_LINK_TYPE_SIT, name, nlmsg, out_link) >= 0);
-nla_put_failure:
- g_return_val_if_reached (FALSE);
-}
-
-static gboolean
link_tun_add (NMPlatform *platform,
const char *name,
const NMPlatformLnkTun *props,
@@ -7592,107 +7457,6 @@ link_tun_add (NMPlatform *platform,
return TRUE;
}
-static gboolean
-link_vxlan_add (NMPlatform *platform,
- const char *name,
- const NMPlatformLnkVxlan *props,
- const NMPlatformLink **out_link)
-{
- nm_auto_nlmsg struct nl_msg *nlmsg = NULL;
- struct nlattr *info;
- struct nlattr *data;
- struct nm_ifla_vxlan_port_range port_range;
-
- g_return_val_if_fail (props, FALSE);
-
- nlmsg = _nl_msg_new_link (RTM_NEWLINK,
- NLM_F_CREATE | NLM_F_EXCL,
- 0,
- name);
- if (!nlmsg)
- return FALSE;
-
- if (!(info = nla_nest_start (nlmsg, IFLA_LINKINFO)))
- goto nla_put_failure;
-
- NLA_PUT_STRING (nlmsg, IFLA_INFO_KIND, "vxlan");
-
- if (!(data = nla_nest_start (nlmsg, IFLA_INFO_DATA)))
- goto nla_put_failure;
-
- NLA_PUT_U32 (nlmsg, IFLA_VXLAN_ID, props->id);
-
- if (props->group)
- NLA_PUT (nlmsg, IFLA_VXLAN_GROUP, sizeof (props->group), &props->group);
- else if (memcmp (&props->group6, &in6addr_any, sizeof (in6addr_any)))
- NLA_PUT (nlmsg, IFLA_VXLAN_GROUP6, sizeof (props->group6), &props->group6);
-
- if (props->local)
- NLA_PUT (nlmsg, IFLA_VXLAN_LOCAL, sizeof (props->local), &props->local);
- else if (memcmp (&props->local6, &in6addr_any, sizeof (in6addr_any)))
- NLA_PUT (nlmsg, IFLA_VXLAN_LOCAL6, sizeof (props->local6), &props->local6);
-
- if (props->parent_ifindex >= 0)
- NLA_PUT_U32 (nlmsg, IFLA_VXLAN_LINK, props->parent_ifindex);
-
- if (props->src_port_min || props->src_port_max) {
- port_range.low = htons (props->src_port_min);
- port_range.high = htons (props->src_port_max);
- NLA_PUT (nlmsg, IFLA_VXLAN_PORT_RANGE, sizeof (port_range), &port_range);
- }
-
- NLA_PUT_U16 (nlmsg, IFLA_VXLAN_PORT, htons (props->dst_port));
- NLA_PUT_U8 (nlmsg, IFLA_VXLAN_TOS, props->tos);
- NLA_PUT_U8 (nlmsg, IFLA_VXLAN_TTL, props->ttl);
- NLA_PUT_U32 (nlmsg, IFLA_VXLAN_AGEING, props->ageing);
- NLA_PUT_U32 (nlmsg, IFLA_VXLAN_LIMIT, props->limit);
- NLA_PUT_U8 (nlmsg, IFLA_VXLAN_LEARNING, !!props->learning);
- NLA_PUT_U8 (nlmsg, IFLA_VXLAN_PROXY, !!props->proxy);
- NLA_PUT_U8 (nlmsg, IFLA_VXLAN_RSC, !!props->rsc);
- NLA_PUT_U8 (nlmsg, IFLA_VXLAN_L2MISS, !!props->l2miss);
- NLA_PUT_U8 (nlmsg, IFLA_VXLAN_L3MISS, !!props->l3miss);
-
- nla_nest_end (nlmsg, data);
- nla_nest_end (nlmsg, info);
-
- return (do_add_link_with_lookup (platform, NM_LINK_TYPE_VXLAN, name, nlmsg, out_link) >= 0);
-nla_put_failure:
- g_return_val_if_reached (FALSE);
-}
-
-static gboolean
-link_6lowpan_add (NMPlatform *platform,
- const char *name,
- int parent,
- const NMPlatformLink **out_link)
-{
- nm_auto_nlmsg struct nl_msg *nlmsg = NULL;
- struct nlattr *info;
-
- 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 (!(info = nla_nest_start (nlmsg, IFLA_LINKINFO)))
- goto nla_put_failure;
-
- NLA_PUT_STRING (nlmsg, IFLA_INFO_KIND, "lowpan");
-
- nla_nest_end (nlmsg, info);
-
- return (do_add_link_with_lookup (platform,
- NM_LINK_TYPE_6LOWPAN,
- name, nlmsg, out_link) >= 0);
-nla_put_failure:
- g_return_val_if_reached (FALSE);
-}
-
-
static void
_vlan_change_vlan_qos_mapping_create (gboolean is_ingress_map,
gboolean reset_all,
@@ -9294,10 +9058,8 @@ 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;
platform_class->infiniband_partition_add = infiniband_partition_add;
platform_class->infiniband_partition_delete = infiniband_partition_delete;
@@ -9325,15 +9087,7 @@ nm_linux_platform_class_init (NMLinuxPlatformClass *klass)
platform_class->wpan_set_short_addr = wpan_set_short_addr;
platform_class->wpan_set_channel = wpan_set_channel;
- platform_class->link_gre_add = link_gre_add;
- platform_class->link_ip6tnl_add = link_ip6tnl_add;
- platform_class->link_ip6gre_add = link_ip6gre_add;
- platform_class->link_macsec_add = link_macsec_add;
- platform_class->link_macvlan_add = link_macvlan_add;
- platform_class->link_ipip_add = link_ipip_add;
- platform_class->link_sit_add = link_sit_add;
platform_class->link_tun_add = link_tun_add;
- platform_class->link_6lowpan_add = link_6lowpan_add;
platform_class->object_delete = object_delete;
platform_class->ip4_address_add = ip4_address_add;
diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c
index 2636df9a08..fbb5e7e2fa 100644
--- a/src/platform/nm-platform.c
+++ b/src/platform/nm-platform.c
@@ -1150,11 +1150,12 @@ _link_add_check_existing (NMPlatform *self, const char *name, NMLinkType type, c
/**
* nm_platform_link_add:
* @self: platform instance
- * @name: Interface name
* @type: Interface type
- * @veth_peer: For veths, the peer name
+ * @name: Interface name
+ * @parent: the IFLA_LINK parameter or 0.
* @address: (allow-none): set the mac address of the link
* @address_len: the length of the @address
+ * @extra_data: depending on @type, additional data.
* @out_link: on success, the link object
*
* Add a software interface. If the interface already exists and is of type
@@ -1167,66 +1168,100 @@ _link_add_check_existing (NMPlatform *self, const char *name, NMLinkType type, c
*
* Returns: the negative nm-error on failure.
*/
-static int
+int
nm_platform_link_add (NMPlatform *self,
- const char *name,
NMLinkType type,
- const char *veth_peer,
+ const char *name,
+ int parent,
const void *address,
size_t address_len,
+ gconstpointer extra_data,
const NMPlatformLink **out_link)
{
int r;
char addr_buf[NM_UTILS_HWADDR_LEN_MAX * 3];
+ char parent_buf[64];
+ char buf[512];
_CHECK_SELF (self, klass, -NME_BUG);
g_return_val_if_fail (name, -NME_BUG);
g_return_val_if_fail ((address != NULL) ^ (address_len == 0) , -NME_BUG);
g_return_val_if_fail (address_len <= NM_UTILS_HWADDR_LEN_MAX, -NME_BUG);
- g_return_val_if_fail ((!!veth_peer) == (type == NM_LINK_TYPE_VETH), -NME_BUG);
+ g_return_val_if_fail (parent >= 0, -NME_BUG);
r = _link_add_check_existing (self, name, type, out_link);
if (r < 0)
return r;
- _LOG2D ("link: adding link: %s (%d)"
- "%s%s" /* address */
- "%s%s" /* veth peer */
+ _LOG2D ("link: adding link: "
+ "%s " /* type */
+ "\"%s\"" /* name */
+ "%s%s" /* parent */
+ "%s%s" /* address */
+ "%s" /* extra_data */
"",
nm_link_type_to_string (type),
- (int) type,
+ name,
+ parent > 0 ? ", parent " : "",
+ parent > 0 ? nm_sprintf_buf (parent_buf, "%d", parent) : "",
address ? ", address: " : "",
address ? nm_utils_hwaddr_ntoa_buf (address, address_len, FALSE, addr_buf, sizeof (addr_buf)) : "",
- veth_peer ? ", veth-peer: " : "",
- veth_peer ?: "");
-
- return klass->link_add (self, name, type, veth_peer, address, address_len, out_link);
-}
-
-int
-nm_platform_link_veth_add (NMPlatform *self,
- const char *name,
- const char *peer,
- const NMPlatformLink **out_link)
-{
- return nm_platform_link_add (self, name, NM_LINK_TYPE_VETH, peer, NULL, 0, out_link);
-}
-
-/**
- * nm_platform_link_dummy_add:
- * @self: platform instance
- * @name: New interface name
- * @out_link: on success, the link object
- *
- * Create a software ethernet-like interface
- */
-int
-nm_platform_link_dummy_add (NMPlatform *self,
- const char *name,
- const NMPlatformLink **out_link)
-{
- return nm_platform_link_add (self, name, NM_LINK_TYPE_DUMMY, NULL, NULL, 0, out_link);
+ ({
+ char *buf_p = buf;
+ gsize buf_len = sizeof (buf);
+
+ 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_VXLAN:
+ nm_utils_strbuf_append_str (&buf_p, &buf_len, ", ");
+ nm_platform_lnk_vxlan_to_string ((const NMPlatformLnkVxlan *) extra_data, buf_p, buf_len);
+ break;
+ case NM_LINK_TYPE_VETH:
+ nm_sprintf_buf (buf, ", veth-peer \"%s\"", (const char *) extra_data);
+ break;
+ case NM_LINK_TYPE_GRE:
+ case NM_LINK_TYPE_GRETAP:
+ nm_utils_strbuf_append_str (&buf_p, &buf_len, ", ");
+ nm_platform_lnk_gre_to_string ((const NMPlatformLnkGre *) extra_data, buf_p, buf_len);
+ break;
+ case NM_LINK_TYPE_SIT:
+ nm_utils_strbuf_append_str (&buf_p, &buf_len, ", ");
+ nm_platform_lnk_sit_to_string ((const NMPlatformLnkSit *) extra_data, buf_p, buf_len);
+ break;
+ case NM_LINK_TYPE_IP6TNL:
+ case NM_LINK_TYPE_IP6GRE:
+ case NM_LINK_TYPE_IP6GRETAP:
+ nm_utils_strbuf_append_str (&buf_p, &buf_len, ", ");
+ nm_platform_lnk_ip6tnl_to_string ((const NMPlatformLnkIp6Tnl *) extra_data, buf_p, buf_len);
+ break;
+ case NM_LINK_TYPE_IPIP:
+ nm_utils_strbuf_append_str (&buf_p, &buf_len, ", ");
+ nm_platform_lnk_ipip_to_string ((const NMPlatformLnkIpIp *) extra_data, buf_p, buf_len);
+ break;
+ case NM_LINK_TYPE_MACSEC:
+ nm_utils_strbuf_append_str (&buf_p, &buf_len, ", ");
+ nm_platform_lnk_macsec_to_string ((const NMPlatformLnkMacsec *) extra_data, buf_p, buf_len);
+ break;
+ case NM_LINK_TYPE_MACVLAN:
+ case NM_LINK_TYPE_MACVTAP:
+ nm_utils_strbuf_append_str (&buf_p, &buf_len, ", ");
+ nm_platform_lnk_macvlan_to_string ((const NMPlatformLnkMacvlan *) extra_data, buf_p, buf_len);
+ break;
+ default:
+ nm_assert (!extra_data);
+ break;
+ }
+
+ buf;
+ }));
+
+ return klass->link_add (self, type, name, parent, address, address_len, extra_data, out_link);
}
/**
@@ -2193,7 +2228,7 @@ nm_platform_link_get_lnk_macvlan (NMPlatform *self, int ifindex, const NMPlatfor
return _link_get_lnk (self, ifindex, NM_LINK_TYPE_MACVLAN, out_link);
}
-const NMPlatformLnkMacvtap *
+const NMPlatformLnkMacvlan *
nm_platform_link_get_lnk_macvtap (NMPlatform *self, int ifindex, const NMPlatformLink **out_link)
{
return _link_get_lnk (self, ifindex, NM_LINK_TYPE_MACVTAP, out_link);
@@ -2250,14 +2285,6 @@ NM_UTILS_FLAGS2STR_DEFINE_STATIC (_wireguard_change_peer_flags_to_string, NMPlat
);
int
-nm_platform_link_wireguard_add (NMPlatform *self,
- const char *name,
- const NMPlatformLink **out_link)
-{
- return nm_platform_link_add (self, name, NM_LINK_TYPE_WIREGUARD, NULL, NULL, 0, out_link);
-}
-
-int
nm_platform_link_wireguard_change (NMPlatform *self,
int ifindex,
const NMPlatformLnkWireGuard *lnk_wireguard,
@@ -2316,128 +2343,6 @@ nm_platform_link_wireguard_change (NMPlatform *self,
/*****************************************************************************/
/**
- * nm_platform_link_bridge_add:
- * @self: platform instance
- * @name: New interface name
- * @address: (allow-none): set the mac address of the new bridge
- * @address_len: the length of the @address
- * @out_link: on success, the link object
- *
- * Create a software bridge.
- */
-int
-nm_platform_link_bridge_add (NMPlatform *self,
- const char *name,
- const void *address,
- size_t address_len,
- const NMPlatformLink **out_link)
-{
- return nm_platform_link_add (self, name, NM_LINK_TYPE_BRIDGE, NULL, address, address_len, out_link);
-}
-
-/**
- * nm_platform_link_bond_add:
- * @self: platform instance
- * @name: New interface name
- * @out_link: on success, the link object
- *
- * Create a software bonding device.
- */
-int
-nm_platform_link_bond_add (NMPlatform *self,
- const char *name,
- const NMPlatformLink **out_link)
-{
- return nm_platform_link_add (self, name, NM_LINK_TYPE_BOND, NULL, NULL, 0, out_link);
-}
-
-/**
- * nm_platform_link_team_add:
- * @self: platform instance
- * @name: New interface name
- * @out_link: on success, the link object
- *
- * Create a software teaming device.
- */
-int
-nm_platform_link_team_add (NMPlatform *self,
- const char *name,
- const NMPlatformLink **out_link)
-{
- return nm_platform_link_add (self, name, NM_LINK_TYPE_TEAM, NULL, NULL, 0, out_link);
-}
-
-/**
- * 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
- * @props: properties of the new link
- * @out_link: on success, the link object
- *
- * Create a VXLAN device.
- */
-int
-nm_platform_link_vxlan_add (NMPlatform *self,
- const char *name,
- const NMPlatformLnkVxlan *props,
- const NMPlatformLink **out_link)
-{
- int r;
-
- _CHECK_SELF (self, klass, -NME_BUG);
-
- g_return_val_if_fail (props, -NME_BUG);
-
- r = _link_add_check_existing (self, name, NM_LINK_TYPE_VXLAN, out_link);
- if (r < 0)
- return r;
-
- _LOG2D ("link: adding link %s", nm_platform_lnk_vxlan_to_string (props, NULL, 0));
-
- if (!klass->link_vxlan_add (self, name, props, out_link))
- return -NME_UNSPEC;
- return 0;
-}
-
-/**
* nm_platform_link_tun_add:
* @self: platform instance
* @name: new interface name
@@ -2489,38 +2394,6 @@ nm_platform_link_tun_add (NMPlatform *self,
return 0;
}
-/**
- * nm_platform_6lowpan_add:
- * @self: platform instance
- * @parent: parent link
- * @name: name of the new interface
- * @out_link: on success, the link object
- *
- * Create a 6LoWPAN interface.
- */
-int
-nm_platform_link_6lowpan_add (NMPlatform *self,
- const char *name,
- int parent,
- const NMPlatformLink **out_link)
-{
- int r;
-
- _CHECK_SELF (self, klass, -NME_BUG);
-
- g_return_val_if_fail (name, -NME_BUG);
-
- r = _link_add_check_existing (self, name, NM_LINK_TYPE_6LOWPAN, out_link);
- if (r < 0)
- return r;
-
- _LOG2D ("adding link 6lowpan parent %u", parent);
-
- if (!klass->link_6lowpan_add (self, name, parent, out_link))
- return -NME_UNSPEC;
- return 0;
-}
-
gboolean
nm_platform_link_6lowpan_get_properties (NMPlatform *self, int ifindex, int *out_parent)
{
@@ -2761,39 +2634,6 @@ nm_platform_link_vlan_set_egress_map (NMPlatform *self, int ifindex, int from, i
return nm_platform_link_vlan_change (self, ifindex, 0, 0, FALSE, NULL, 0, FALSE, &map, 1);
}
-/**
- * nm_platform_link_gre_add:
- * @self: platform instance
- * @name: name of the new interface
- * @props: interface properties
- * @out_link: on success, the link object
- *
- * Create a software GRE device.
- */
-int
-nm_platform_link_gre_add (NMPlatform *self,
- const char *name,
- const NMPlatformLnkGre *props,
- const NMPlatformLink **out_link)
-{
- int r;
-
- _CHECK_SELF (self, klass, -NME_BUG);
-
- g_return_val_if_fail (props, -NME_BUG);
- g_return_val_if_fail (name, -NME_BUG);
-
- r = _link_add_check_existing (self, name, props->is_tap ? NM_LINK_TYPE_GRETAP : NM_LINK_TYPE_GRE, out_link);
- if (r < 0)
- return r;
-
- _LOG2D ("adding link %s", nm_platform_lnk_gre_to_string (props, NULL, 0));
-
- if (!klass->link_gre_add (self, name, props, out_link))
- return -NME_UNSPEC;
- return 0;
-}
-
static int
_infiniband_add_add_or_delete (NMPlatform *self,
int ifindex,
@@ -2918,217 +2758,6 @@ nm_platform_link_infiniband_get_properties (NMPlatform *self,
return TRUE;
}
-/**
- * nm_platform_ip6tnl_add:
- * @self: platform instance
- * @name: name of the new interface
- * @props: interface properties
- * @out_link: on success, the link object
- *
- * Create an IPv6 tunnel.
- */
-int
-nm_platform_link_ip6tnl_add (NMPlatform *self,
- const char *name,
- const NMPlatformLnkIp6Tnl *props,
- const NMPlatformLink **out_link)
-{
- int r;
-
- _CHECK_SELF (self, klass, -NME_BUG);
-
- g_return_val_if_fail (props, -NME_BUG);
- g_return_val_if_fail (name, -NME_BUG);
- g_return_val_if_fail (!props->is_gre, -NME_BUG);
-
- r = _link_add_check_existing (self, name, NM_LINK_TYPE_IP6TNL, out_link);
- if (r < 0)
- return r;
-
- _LOG2D ("adding link %s", nm_platform_lnk_ip6tnl_to_string (props, NULL, 0));
-
- if (!klass->link_ip6tnl_add (self, name, props, out_link))
- return -NME_UNSPEC;
- return 0;
-}
-
-/**
- * nm_platform_ip6gre_add:
- * @self: platform instance
- * @name: name of the new interface
- * @props: interface properties
- * @out_link: on success, the link object
- *
- * Create an IPv6 GRE/GRETAP tunnel.
- */
-int
-nm_platform_link_ip6gre_add (NMPlatform *self,
- const char *name,
- const NMPlatformLnkIp6Tnl *props,
- const NMPlatformLink **out_link)
-{
- int r;
-
- _CHECK_SELF (self, klass, -NME_BUG);
-
- g_return_val_if_fail (props, -NME_BUG);
- g_return_val_if_fail (name, -NME_BUG);
- g_return_val_if_fail (props->is_gre, -NME_BUG);
-
- r = _link_add_check_existing (self,
- name,
- props->is_tap
- ? NM_LINK_TYPE_IP6GRETAP
- : NM_LINK_TYPE_IP6GRE,
- out_link);
- if (r < 0)
- return r;
-
- _LOG2D ("adding link %s", nm_platform_lnk_ip6tnl_to_string (props, NULL, 0));
-
- if (!klass->link_ip6gre_add (self, name, props, out_link))
- return -NME_UNSPEC;
- return 0;
-}
-
-/**
- * nm_platform_ipip_add:
- * @self: platform instance
- * @name: name of the new interface
- * @props: interface properties
- * @out_link: on success, the link object
- *
- * Create an IPIP tunnel.
- */
-int
-nm_platform_link_ipip_add (NMPlatform *self,
- const char *name,
- const NMPlatformLnkIpIp *props,
- const NMPlatformLink **out_link)
-{
- int r;
-
- _CHECK_SELF (self, klass, -NME_BUG);
-
- g_return_val_if_fail (props, -NME_BUG);
- g_return_val_if_fail (name, -NME_BUG);
-
- r = _link_add_check_existing (self, name, NM_LINK_TYPE_IPIP, out_link);
- if (r < 0)
- return r;
-
- _LOG2D ("adding link %s", nm_platform_lnk_ipip_to_string (props, NULL, 0));
-
- if (!klass->link_ipip_add (self, name, props, out_link))
- return -NME_UNSPEC;
- return 0;
-}
-
-/**
- * nm_platform_macsec_add:
- * @self: platform instance
- * @name: name of the new interface
- * @parent: parent link
- * @props: interface properties
- * @out_link: on success, the link object
- *
- * Create a MACsec interface.
- */
-int
-nm_platform_link_macsec_add (NMPlatform *self,
- const char *name,
- int parent,
- const NMPlatformLnkMacsec *props,
- const NMPlatformLink **out_link)
-{
- int r;
-
- _CHECK_SELF (self, klass, -NME_BUG);
-
- g_return_val_if_fail (props, -NME_BUG);
- g_return_val_if_fail (name, -NME_BUG);
-
- r = _link_add_check_existing (self, name, NM_LINK_TYPE_MACSEC, out_link);
- if (r < 0)
- return r;
-
- _LOG2D ("adding link %s", nm_platform_lnk_macsec_to_string (props, NULL, 0));
-
- if (!klass->link_macsec_add (self, name, parent, props, out_link))
- return -NME_UNSPEC;
- return 0;
-}
-
-/**
- * nm_platform_macvlan_add:
- * @self: platform instance
- * @name: name of the new interface
- * @props: interface properties
- * @out_link: on success, the link object
- *
- * Create a MACVLAN or MACVTAP device.
- */
-int
-nm_platform_link_macvlan_add (NMPlatform *self,
- const char *name,
- int parent,
- const NMPlatformLnkMacvlan *props,
- const NMPlatformLink **out_link)
-{
- int r;
- NMLinkType type;
-
- _CHECK_SELF (self, klass, -NME_BUG);
-
- g_return_val_if_fail (props, -NME_BUG);
- g_return_val_if_fail (name, -NME_BUG);
-
- type = props->tap ? NM_LINK_TYPE_MACVTAP : NM_LINK_TYPE_MACVLAN;
-
- r = _link_add_check_existing (self, name, type, out_link);
- if (r < 0)
- return r;
-
- _LOG2D ("adding link %s", nm_platform_lnk_macvlan_to_string (props, NULL, 0));
-
- if (!klass->link_macvlan_add (self, name, parent, props, out_link))
- return -NME_UNSPEC;
- return 0;
-}
-
-/**
- * nm_platform_sit_add:
- * @self: platform instance
- * @name: name of the new interface
- * @props: interface properties
- * @out_link: on success, the link object
- *
- * Create a software SIT device.
- */
-int
-nm_platform_link_sit_add (NMPlatform *self,
- const char *name,
- const NMPlatformLnkSit *props,
- const NMPlatformLink **out_link)
-{
- int r;
-
- _CHECK_SELF (self, klass, -NME_BUG);
-
- g_return_val_if_fail (props, -NME_BUG);
- g_return_val_if_fail (name, -NME_BUG);
-
- r = _link_add_check_existing (self, name, NM_LINK_TYPE_SIT, out_link);
- if (r < 0)
- return r;
-
- _LOG2D ("adding link %s", nm_platform_lnk_sit_to_string (props, NULL, 0));
-
- if (!klass->link_sit_add (self, name, props, out_link))
- return -NME_UNSPEC;
- return 0;
-}
-
gboolean
nm_platform_link_veth_get_properties (NMPlatform *self, int ifindex, int *out_peer_ifindex)
{
diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h
index a31564ed3f..8d1a3d3865 100644
--- a/src/platform/nm-platform.h
+++ b/src/platform/nm-platform.h
@@ -795,8 +795,6 @@ typedef struct {
bool tap:1;
} NMPlatformLnkMacvlan;
-typedef NMPlatformLnkMacvlan NMPlatformLnkMacvtap;
-
typedef struct {
in_addr_t local;
in_addr_t remote;
@@ -965,11 +963,12 @@ typedef struct {
void (*process_events) (NMPlatform *self);
int (*link_add) (NMPlatform *self,
- const char *name,
NMLinkType type,
- const char *veth_peer,
+ const char *name,
+ int parent,
const void *address,
size_t address_len,
+ gconstpointer extra_data,
const NMPlatformLink **out_link);
gboolean (*link_delete) (NMPlatform *self, int ifindex);
gboolean (*link_refresh) (NMPlatform *self, int ifindex);
@@ -1028,7 +1027,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,
@@ -1039,49 +1037,11 @@ typedef struct {
gboolean egress_reset_all,
const NMVlanQosMapping *egress_map,
gsize n_egress_map);
- gboolean (*link_vxlan_add) (NMPlatform *self,
- const char *name,
- const NMPlatformLnkVxlan *props,
- const NMPlatformLink **out_link);
- gboolean (*link_gre_add) (NMPlatform *self,
- const char *name,
- const NMPlatformLnkGre *props,
- const NMPlatformLink **out_link);
- gboolean (*link_ip6tnl_add) (NMPlatform *self,
- const char *name,
- const NMPlatformLnkIp6Tnl *props,
- const NMPlatformLink **out_link);
- gboolean (*link_ip6gre_add) (NMPlatform *self,
- const char *name,
- const NMPlatformLnkIp6Tnl *props,
- const NMPlatformLink **out_link);
- gboolean (*link_ipip_add) (NMPlatform *self,
- const char *name,
- const NMPlatformLnkIpIp *props,
- const NMPlatformLink **out_link);
- gboolean (*link_macsec_add) (NMPlatform *self,
- const char *name,
- int parent,
- const NMPlatformLnkMacsec *props,
- const NMPlatformLink **out_link);
- gboolean (*link_macvlan_add) (NMPlatform *self,
- const char *name,
- int parent,
- const NMPlatformLnkMacvlan *props,
- const NMPlatformLink **out_link);
- gboolean (*link_sit_add) (NMPlatform *self,
- const char *name,
- const NMPlatformLnkSit *props,
- const NMPlatformLink **out_link);
gboolean (*link_tun_add) (NMPlatform *self,
const char *name,
const NMPlatformLnkTun *props,
const NMPlatformLink **out_link,
int *out_fd);
- gboolean (*link_6lowpan_add) (NMPlatform *self,
- const char *name,
- int parent,
- const NMPlatformLink **out_link);
gboolean (*infiniband_partition_add) (NMPlatform *self, int parent, int p_key, const NMPlatformLink **out_link);
gboolean (*infiniband_partition_delete) (NMPlatform *self, int parent, int p_key);
@@ -1363,11 +1323,191 @@ const NMPlatformLink *nm_platform_link_get_by_ifname (NMPlatform *self, const ch
const NMPlatformLink *nm_platform_link_get_by_address (NMPlatform *self, NMLinkType link_type, gconstpointer address, size_t length);
GPtrArray *nm_platform_link_get_all (NMPlatform *self, gboolean sort_by_name);
-int nm_platform_link_dummy_add (NMPlatform *self, const char *name, const NMPlatformLink **out_link);
-int nm_platform_link_bridge_add (NMPlatform *self, const char *name, const void *address, size_t address_len, const NMPlatformLink **out_link);
-int nm_platform_link_bond_add (NMPlatform *self, const char *name, const NMPlatformLink **out_link);
-int nm_platform_link_team_add (NMPlatform *self, const char *name, const NMPlatformLink **out_link);
-int nm_platform_link_veth_add (NMPlatform *self, const char *name, const char *peer, const NMPlatformLink **out_link);
+
+int nm_platform_link_add (NMPlatform *self,
+ NMLinkType type,
+ const char *name,
+ int parent,
+ const void *address,
+ size_t address_len,
+ gconstpointer extra_data,
+ const NMPlatformLink **out_link);
+
+static inline int
+nm_platform_link_veth_add (NMPlatform *self,
+ const char *name,
+ const char *peer,
+ const NMPlatformLink **out_link)
+{
+ return nm_platform_link_add (self, NM_LINK_TYPE_VETH, name, 0, NULL, 0, peer, out_link);
+}
+
+static inline int
+nm_platform_link_dummy_add (NMPlatform *self,
+ const char *name,
+ const NMPlatformLink **out_link)
+{
+ return nm_platform_link_add (self, NM_LINK_TYPE_DUMMY, name, 0, NULL, 0, NULL, out_link);
+}
+
+static inline int
+nm_platform_link_bridge_add (NMPlatform *self,
+ const char *name,
+ const void *address,
+ size_t address_len,
+ const NMPlatformLink **out_link)
+{
+ return nm_platform_link_add (self, NM_LINK_TYPE_BRIDGE, name, 0, address, address_len, NULL, out_link);
+}
+
+static inline int
+nm_platform_link_bond_add (NMPlatform *self,
+ const char *name,
+ const NMPlatformLink **out_link)
+{
+ return nm_platform_link_add (self, NM_LINK_TYPE_BOND, name, 0, NULL, 0, NULL, out_link);
+}
+
+static inline int
+nm_platform_link_team_add (NMPlatform *self,
+ const char *name,
+ const NMPlatformLink **out_link)
+{
+ return nm_platform_link_add (self, NM_LINK_TYPE_TEAM, name, 0, NULL, 0, NULL, out_link);
+}
+
+static inline int
+nm_platform_link_wireguard_add (NMPlatform *self,
+ const char *name,
+ const NMPlatformLink **out_link)
+{
+ return nm_platform_link_add (self, NM_LINK_TYPE_WIREGUARD, name, 0, NULL, 0, NULL, out_link);
+}
+
+static inline int
+nm_platform_link_gre_add (NMPlatform *self,
+ const char *name,
+ const void *address,
+ size_t address_len,
+ const NMPlatformLnkGre *props,
+ const NMPlatformLink **out_link)
+{
+ g_return_val_if_fail (props, -NME_BUG);
+
+ return nm_platform_link_add (self, props->is_tap ? NM_LINK_TYPE_GRETAP : NM_LINK_TYPE_GRE, name, 0, address, address_len, props, out_link);
+}
+
+static inline int
+nm_platform_link_sit_add (NMPlatform *self,
+ const char *name,
+ const NMPlatformLnkSit *props,
+ const NMPlatformLink **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);
+}
+
+static inline int
+nm_platform_link_vxlan_add (NMPlatform *self,
+ const char *name,
+ const NMPlatformLnkVxlan *props,
+ const NMPlatformLink **out_link)
+{
+ return nm_platform_link_add (self, NM_LINK_TYPE_VXLAN, name, 0, NULL, 0, props, out_link);
+}
+
+static inline int
+nm_platform_link_6lowpan_add (NMPlatform *self,
+ const char *name,
+ int parent,
+ const NMPlatformLink **out_link)
+{
+ return nm_platform_link_add (self, NM_LINK_TYPE_6LOWPAN, name, parent, NULL, 0, NULL, out_link);
+}
+
+static inline int
+nm_platform_link_ip6tnl_add (NMPlatform *self,
+ const char *name,
+ const NMPlatformLnkIp6Tnl *props,
+ const NMPlatformLink **out_link)
+{
+ g_return_val_if_fail (props, -NME_BUG);
+ g_return_val_if_fail (!props->is_gre, -NME_BUG);
+
+ return nm_platform_link_add (self, NM_LINK_TYPE_IP6TNL, name, 0, NULL, 0, props, out_link);
+}
+
+static inline int
+nm_platform_link_ip6gre_add (NMPlatform *self,
+ const char *name,
+ const NMPlatformLnkIp6Tnl *props,
+ const NMPlatformLink **out_link)
+{
+ g_return_val_if_fail (props, -NME_BUG);
+ g_return_val_if_fail (props->is_gre, -NME_BUG);
+
+ return nm_platform_link_add (self, props->is_tap ? NM_LINK_TYPE_IP6GRETAP : NM_LINK_TYPE_IP6GRE, name, 0, NULL, 0, props, out_link);
+}
+
+static inline int
+nm_platform_link_ipip_add (NMPlatform *self,
+ const char *name,
+ const NMPlatformLnkIpIp *props,
+ const NMPlatformLink **out_link)
+{
+ g_return_val_if_fail (props, -NME_BUG);
+
+ return nm_platform_link_add (self, NM_LINK_TYPE_IPIP, name, 0, NULL, 0, props, out_link);
+}
+
+static inline int
+nm_platform_link_macsec_add (NMPlatform *self,
+ const char *name,
+ int parent,
+ const NMPlatformLnkMacsec *props,
+ const NMPlatformLink **out_link)
+{
+ g_return_val_if_fail (props, -NME_BUG);
+ g_return_val_if_fail (parent > 0, -NME_BUG);
+
+ return nm_platform_link_add (self, NM_LINK_TYPE_MACSEC, name, parent, NULL, 0, props, out_link);
+}
+
+static inline int
+nm_platform_link_macvlan_add (NMPlatform *self,
+ const char *name,
+ int parent,
+ const NMPlatformLnkMacvlan *props,
+ const NMPlatformLink **out_link)
+{
+ g_return_val_if_fail (props, -NME_BUG);
+ g_return_val_if_fail (parent > 0, -NME_BUG);
+
+ return nm_platform_link_add (self, props->tap ? NM_LINK_TYPE_MACVTAP : NM_LINK_TYPE_MACVLAN, name, parent, NULL, 0, props, out_link);
+}
gboolean nm_platform_link_delete (NMPlatform *self, int ifindex);
@@ -1477,19 +1617,13 @@ const NMPlatformLnkInfiniband *nm_platform_link_get_lnk_infiniband (NMPlatform *
const NMPlatformLnkIpIp *nm_platform_link_get_lnk_ipip (NMPlatform *self, int ifindex, const NMPlatformLink **out_link);
const NMPlatformLnkMacsec *nm_platform_link_get_lnk_macsec (NMPlatform *self, int ifindex, const NMPlatformLink **out_link);
const NMPlatformLnkMacvlan *nm_platform_link_get_lnk_macvlan (NMPlatform *self, int ifindex, const NMPlatformLink **out_link);
-const NMPlatformLnkMacvtap *nm_platform_link_get_lnk_macvtap (NMPlatform *self, int ifindex, const NMPlatformLink **out_link);
+const NMPlatformLnkMacvlan *nm_platform_link_get_lnk_macvtap (NMPlatform *self, int ifindex, const NMPlatformLink **out_link);
const NMPlatformLnkSit *nm_platform_link_get_lnk_sit (NMPlatform *self, int ifindex, const NMPlatformLink **out_link);
const NMPlatformLnkTun *nm_platform_link_get_lnk_tun (NMPlatform *self, int ifindex, const NMPlatformLink **out_link);
const NMPlatformLnkVlan *nm_platform_link_get_lnk_vlan (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);
-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,
@@ -1503,11 +1637,6 @@ gboolean nm_platform_link_vlan_change (NMPlatform *self,
const NMVlanQosMapping *egress_map,
gsize n_egress_map);
-int nm_platform_link_vxlan_add (NMPlatform *self,
- const char *name,
- const NMPlatformLnkVxlan *props,
- const NMPlatformLink **out_link);
-
int nm_platform_link_infiniband_add (NMPlatform *self,
int parent,
int p_key,
@@ -1550,32 +1679,6 @@ const struct in6_addr *nm_platform_ip6_address_get_peer (const NMPlatformIP6Addr
const NMPlatformIP4Address *nm_platform_ip4_address_get (NMPlatform *self, int ifindex, in_addr_t address, guint8 plen, in_addr_t peer_address);
-int nm_platform_link_gre_add (NMPlatform *self,
- const char *name,
- const NMPlatformLnkGre *props,
- const NMPlatformLink **out_link);
-int nm_platform_link_ip6tnl_add (NMPlatform *self,
- const char *name,
- const NMPlatformLnkIp6Tnl *props,
- const NMPlatformLink **out_link);
-int nm_platform_link_ip6gre_add (NMPlatform *self,
- const char *name,
- const NMPlatformLnkIp6Tnl *props,
- const NMPlatformLink **out_link);
-int nm_platform_link_ipip_add (NMPlatform *self,
- const char *name,
- const NMPlatformLnkIpIp *props,
- const NMPlatformLink **out_link);
-int nm_platform_link_macsec_add (NMPlatform *self,
- const char *name,
- int parent,
- const NMPlatformLnkMacsec *props,
- const NMPlatformLink **out_link);
-int nm_platform_link_macvlan_add (NMPlatform *self,
- const char *name,
- int parent,
- const NMPlatformLnkMacvlan *props,
- const NMPlatformLink **out_link);
int nm_platform_link_sit_add (NMPlatform *self,
const char *name,
const NMPlatformLnkSit *props,
@@ -1585,10 +1688,6 @@ int nm_platform_link_tun_add (NMPlatform *self,
const NMPlatformLnkTun *props,
const NMPlatformLink **out_link,
int *out_fd);
-int nm_platform_link_6lowpan_add (NMPlatform *self,
- const char *name,
- int parent,
- const NMPlatformLink **out_link);
gboolean nm_platform_link_6lowpan_get_properties (NMPlatform *self,
int ifindex,
int *out_parent);
diff --git a/src/platform/nmp-object.c b/src/platform/nmp-object.c
index 97aa4f28f5..240c1e7d8a 100644
--- a/src/platform/nmp-object.c
+++ b/src/platform/nmp-object.c
@@ -3291,7 +3291,7 @@ const NMPClass _nmp_classes[NMP_OBJECT_TYPE_MAX] = {
.parent = DEDUP_MULTI_OBJ_CLASS_INIT(),
.obj_type = NMP_OBJECT_TYPE_LNK_MACVTAP,
.sizeof_data = sizeof (NMPObjectLnkMacvtap),
- .sizeof_public = sizeof (NMPlatformLnkMacvtap),
+ .sizeof_public = sizeof (NMPlatformLnkMacvlan),
.obj_type_name = "macvtap",
.lnk_link_type = NM_LINK_TYPE_MACVTAP,
.cmd_plobj_to_string = (const char *(*) (const NMPlatformObject *obj, char *buf, gsize len)) nm_platform_lnk_macvlan_to_string,
diff --git a/src/platform/tests/test-common.c b/src/platform/tests/test-common.c
index 7d31e920b8..906deeada6 100644
--- a/src/platform/tests/test-common.c
+++ b/src/platform/tests/test-common.c
@@ -1265,7 +1265,7 @@ nmtstp_link_gre_add (NMPlatform *platform,
if (success)
pllink = nmtstp_assert_wait_for_link (platform, name, link_type, 100);
} else
- success = NMTST_NM_ERR_SUCCESS (nm_platform_link_gre_add (platform, name, lnk, &pllink));
+ success = NMTST_NM_ERR_SUCCESS (nm_platform_link_gre_add (platform, name, NULL, 0, lnk, &pllink));
_assert_pllink (platform, success, pllink, name, link_type);
diff --git a/src/platform/tests/test-link.c b/src/platform/tests/test-link.c
index 0e166a5f7f..4a54af2a19 100644
--- a/src/platform/tests/test-link.c
+++ b/src/platform/tests/test-link.c
@@ -1144,7 +1144,7 @@ test_software_detect (gconstpointer user_data)
break;
}
case NM_LINK_TYPE_MACVTAP: {
- NMPlatformLnkMacvtap lnk_macvtap = { };
+ NMPlatformLnkMacvlan lnk_macvtap = { };
lnk_macvtap.mode = MACVLAN_MODE_PRIVATE;
lnk_macvtap.no_promisc = FALSE;
@@ -1389,7 +1389,7 @@ test_software_detect (gconstpointer user_data)
break;
}
case NM_LINK_TYPE_MACVTAP: {
- const NMPlatformLnkMacvtap *plnk = &lnk->lnk_macvlan;
+ const NMPlatformLnkMacvlan *plnk = &lnk->lnk_macvlan;
g_assert (plnk == nm_platform_link_get_lnk_macvtap (NM_PLATFORM_GET, ifindex, NULL));
g_assert_cmpint (plnk->no_promisc, ==, FALSE);