summaryrefslogtreecommitdiff
path: root/src/platform
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2019-12-31 14:09:58 +0100
committerThomas Haller <thaller@redhat.com>2020-01-09 10:42:32 +0100
commitf30ae566087cd3434eb9e32447325142677f33f5 (patch)
tree4caf4cd76936874f4568759836daaee0d387820b /src/platform
parent1ffdca6331f81122045b9397576378617809b9e1 (diff)
downloadNetworkManager-f30ae566087cd3434eb9e32447325142677f33f5.tar.gz
platform: implement link_macvlan_add via nm_platform_link_add()
Diffstat (limited to 'src/platform')
-rw-r--r--src/platform/nm-linux-platform.c55
-rw-r--r--src/platform/nm-platform.c42
-rw-r--r--src/platform/nm-platform.h23
3 files changed, 31 insertions, 89 deletions
diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c
index 6dbef6d7b2..23ebeaa3ab 100644
--- a/src/platform/nm-linux-platform.c
+++ b/src/platform/nm-linux-platform.c
@@ -3935,6 +3935,19 @@ _nl_msg_new_link_set_linkinfo (struct nl_msg *msg,
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;
@@ -7389,47 +7402,6 @@ link_get_dev_id (NMPlatform *platform, int ifindex)
}
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_tun_add (NMPlatform *platform,
const char *name,
const NMPlatformLnkTun *props,
@@ -9115,7 +9087,6 @@ 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_macvlan_add = link_macvlan_add;
platform_class->link_tun_add = link_tun_add;
platform_class->object_delete = object_delete;
diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c
index f152f1b2d4..3d6376b4f7 100644
--- a/src/platform/nm-platform.c
+++ b/src/platform/nm-platform.c
@@ -1248,6 +1248,11 @@ nm_platform_link_add (NMPlatform *self,
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;
@@ -2753,43 +2758,6 @@ nm_platform_link_infiniband_get_properties (NMPlatform *self,
return TRUE;
}
-/**
- * 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;
-}
-
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 03df636f46..b3243bbd9d 100644
--- a/src/platform/nm-platform.h
+++ b/src/platform/nm-platform.h
@@ -1039,11 +1039,6 @@ typedef struct {
gboolean egress_reset_all,
const NMVlanQosMapping *egress_map,
gsize n_egress_map);
- gboolean (*link_macvlan_add) (NMPlatform *self,
- const char *name,
- int parent,
- const NMPlatformLnkMacvlan *props,
- const NMPlatformLink **out_link);
gboolean (*link_tun_add) (NMPlatform *self,
const char *name,
const NMPlatformLnkTun *props,
@@ -1501,6 +1496,19 @@ nm_platform_link_macsec_add (NMPlatform *self,
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);
gboolean nm_platform_link_set_netns (NMPlatform *self, int ifindex, int netns_fd);
@@ -1671,11 +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_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,