diff options
author | Beniamino Galvani <bgalvani@redhat.com> | 2015-12-03 17:09:50 +0100 |
---|---|---|
committer | Beniamino Galvani <bgalvani@redhat.com> | 2015-12-09 14:30:08 +0100 |
commit | 27c0f8def4a9930775a1e4bc8ea6d1732730cb40 (patch) | |
tree | fcd3ee155065cf27687c590e5c9a7d1aa6321690 | |
parent | c3e6e25239ea691cc3eb7ee3d443a29f54d3bdfb (diff) | |
download | NetworkManager-27c0f8def4a9930775a1e4bc8ea6d1732730cb40.tar.gz |
platform: add macvlan link creation support
-rw-r--r-- | src/platform/nm-linux-platform.c | 47 | ||||
-rw-r--r-- | src/platform/nm-platform.c | 37 | ||||
-rw-r--r-- | src/platform/nm-platform.h | 4 |
3 files changed, 88 insertions, 0 deletions
diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index 6434be1a1c..cafed814a6 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -4356,6 +4356,52 @@ nla_put_failure: } 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, NMPlatformLnkSit *props, @@ -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; diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index 5d82f76fd0..e48bc9c24f 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -1944,6 +1944,43 @@ nm_platform_link_ipip_add (NMPlatform *self, } /** + * 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 * @name: name of the new interface diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h index 4866654445..4e3a497744 100644 --- a/src/platform/nm-platform.h +++ b/src/platform/nm-platform.h @@ -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); |