platform: add macvlan link creation support
This commit is contained in:
@@ -4355,6 +4355,52 @@ nla_put_failure:
|
||||
g_return_val_if_reached (FALSE);
|
||||
}
|
||||
|
||||
static int
|
||||
link_macvlan_add (NMPlatform *platform,
|
||||
const char *name,
|
||||
int parent,
|
||||
NMPlatformLnkMacvlan *props,
|
||||
NMPlatformLink *out_link)
|
||||
{
|
||||
nm_auto_nlmsg struct nl_msg *nlmsg = NULL;
|
||||
struct nlattr *info;
|
||||
struct nlattr *data;
|
||||
|
||||
_LOGD ("adding macvlan '%s' parent %u mode %u",
|
||||
name,
|
||||
parent,
|
||||
props->mode);
|
||||
|
||||
nlmsg = _nl_msg_new_link (RTM_NEWLINK,
|
||||
NLM_F_CREATE,
|
||||
0,
|
||||
name,
|
||||
0,
|
||||
0);
|
||||
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, "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, NM_LINK_TYPE_MACVLAN, name, nlmsg, out_link);
|
||||
nla_put_failure:
|
||||
g_return_val_if_reached (FALSE);
|
||||
}
|
||||
|
||||
static int
|
||||
link_sit_add (NMPlatform *platform,
|
||||
const char *name,
|
||||
@@ -5861,6 +5907,7 @@ nm_linux_platform_class_init (NMLinuxPlatformClass *klass)
|
||||
|
||||
platform_class->link_gre_add = link_gre_add;
|
||||
platform_class->link_ip6tnl_add = link_ip6tnl_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;
|
||||
|
||||
|
@@ -1943,6 +1943,43 @@ nm_platform_link_ipip_add (NMPlatform *self,
|
||||
return NM_PLATFORM_ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 device.
|
||||
*/
|
||||
NMPlatformError
|
||||
nm_platform_link_macvlan_add (NMPlatform *self,
|
||||
const char *name,
|
||||
int parent,
|
||||
NMPlatformLnkMacvlan *props,
|
||||
NMPlatformLink *out_link)
|
||||
{
|
||||
NMPlatformError plerr;
|
||||
|
||||
_CHECK_SELF (self, klass, NM_PLATFORM_ERROR_BUG);
|
||||
|
||||
g_return_val_if_fail (props, NM_PLATFORM_ERROR_BUG);
|
||||
g_return_val_if_fail (name, NM_PLATFORM_ERROR_BUG);
|
||||
|
||||
plerr = _link_add_check_existing (self, name, NM_LINK_TYPE_MACVLAN, out_link);
|
||||
if (plerr != NM_PLATFORM_ERROR_SUCCESS)
|
||||
return plerr;
|
||||
|
||||
_LOGD ("adding macvlan '%s' parent %u mode %u",
|
||||
name,
|
||||
parent,
|
||||
props->mode);
|
||||
|
||||
if (!klass->link_macvlan_add (self, name, parent, props, out_link))
|
||||
return NM_PLATFORM_ERROR_UNSPECIFIED;
|
||||
return NM_PLATFORM_ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_platform_sit_add:
|
||||
* @self: platform instance
|
||||
|
@@ -565,6 +565,8 @@ typedef struct {
|
||||
NMPlatformLink *out_link);
|
||||
gboolean (*link_ipip_add) (NMPlatform *, const char *name, NMPlatformLnkIpIp *props,
|
||||
NMPlatformLink *out_link);
|
||||
gboolean (*link_macvlan_add) (NMPlatform *, const char *name, int parent, NMPlatformLnkMacvlan *props,
|
||||
NMPlatformLink *out_link);
|
||||
gboolean (*link_sit_add) (NMPlatform *, const char *name, NMPlatformLnkSit *props,
|
||||
NMPlatformLink *out_link);
|
||||
|
||||
@@ -817,6 +819,8 @@ NMPlatformError nm_platform_link_ip6tnl_add (NMPlatform *self, const char *name,
|
||||
NMPlatformLink *out_link);
|
||||
NMPlatformError nm_platform_link_ipip_add (NMPlatform *self, const char *name, NMPlatformLnkIpIp *props,
|
||||
NMPlatformLink *out_link);
|
||||
NMPlatformError nm_platform_link_macvlan_add (NMPlatform *self, const char *name, int parent, NMPlatformLnkMacvlan *props,
|
||||
NMPlatformLink *out_link);
|
||||
NMPlatformError nm_platform_link_sit_add (NMPlatform *self, const char *name, NMPlatformLnkSit *props,
|
||||
NMPlatformLink *out_link);
|
||||
|
||||
|
Reference in New Issue
Block a user