summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStjepan Gros <stjepan.gros@gmail.com>2016-03-08 13:02:58 +0100
committerThomas Haller <thaller@redhat.com>2016-03-15 12:56:58 +0100
commit99956991169a55590a9750d2c1ae2e26e22ce38a (patch)
tree8f81f7c5b7169221008c65720829cc8a722dfd17
parent30fe52c76629f771401afde37a7d809347372840 (diff)
downloadNetworkManager-99956991169a55590a9750d2c1ae2e26e22ce38a.tar.gz
platform: add nm_platform_link_set_netns() function
[thaller@redhat.com: cherry-picked original patch and modified slightly]
-rw-r--r--src/platform/nm-linux-platform.c27
-rw-r--r--src/platform/nm-platform.c26
-rw-r--r--src/platform/nm-platform.h5
3 files changed, 58 insertions, 0 deletions
diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c
index 3536fd468b..e2ff1f61af 100644
--- a/src/platform/nm-linux-platform.c
+++ b/src/platform/nm-linux-platform.c
@@ -4051,6 +4051,31 @@ link_refresh (NMPlatform *platform, int ifindex)
return !!cache_lookup_link (platform, ifindex);
}
+static gboolean
+link_set_netns (NMPlatform *platform,
+ int ifindex,
+ int netns_fd)
+{
+ nm_auto_nlmsg struct nl_msg *nlmsg = NULL;
+
+ _LOGD ("link: move link %d to network namespace with fd %d", ifindex, netns_fd);
+
+ nlmsg = _nl_msg_new_link (RTM_NEWLINK,
+ 0,
+ ifindex,
+ NULL,
+ 0,
+ 0);
+ if (!nlmsg)
+ return FALSE;
+
+ NLA_PUT (nlmsg, IFLA_NET_NS_FD, 4, &netns_fd);
+ return do_change_link (platform, ifindex, nlmsg) == NM_PLATFORM_ERROR_SUCCESS;
+
+nla_put_failure:
+ g_return_val_if_reached (FALSE);
+}
+
static NMPlatformError
link_change_flags (NMPlatform *platform,
int ifindex,
@@ -6164,6 +6189,8 @@ nm_linux_platform_class_init (NMLinuxPlatformClass *klass)
platform_class->link_refresh = link_refresh;
+ platform_class->link_set_netns = link_set_netns;
+
platform_class->link_set_up = link_set_up;
platform_class->link_set_down = link_set_down;
platform_class->link_set_arp = link_set_arp;
diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c
index 8659cff517..89f385ec96 100644
--- a/src/platform/nm-platform.c
+++ b/src/platform/nm-platform.c
@@ -668,6 +668,32 @@ nm_platform_link_delete (NMPlatform *self, int ifindex)
}
/**
+ * nm_platform_link_set_netns:
+ * @self: platform instance
+ * @ifindex: Interface index
+ * @netns_fd: the file descriptor for the new netns.
+ *
+ * Returns: %TRUE on success.
+ */
+gboolean
+nm_platform_link_set_netns (NMPlatform *self, int ifindex, int netns_fd)
+{
+ const NMPlatformLink *pllink;
+
+ _CHECK_SELF (self, klass, FALSE);
+
+ g_return_val_if_fail (ifindex > 0, FALSE);
+ g_return_val_if_fail (netns_fd > 0, FALSE);
+
+ pllink = nm_platform_link_get (self, ifindex);
+ if (!pllink)
+ return FALSE;
+
+ _LOGD ("link: ifindex %d changing network namespace to %d", ifindex, netns_fd);
+ return klass->link_set_netns (self, ifindex, netns_fd);
+}
+
+/**
* nm_platform_link_get_index:
* @self: platform instance
* @name: Interface name
diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h
index 1f4f3739fa..8c97f7668a 100644
--- a/src/platform/nm-platform.h
+++ b/src/platform/nm-platform.h
@@ -491,6 +491,9 @@ typedef struct {
gboolean (*link_get_unmanaged) (NMPlatform *, int ifindex, gboolean *unmanaged);
gboolean (*link_refresh) (NMPlatform *, int ifindex);
+
+ gboolean (*link_set_netns) (NMPlatform *, int ifindex, int netns_fd);
+
void (*process_events) (NMPlatform *self);
gboolean (*link_set_up) (NMPlatform *, int ifindex, gboolean *out_no_firmware);
@@ -698,6 +701,8 @@ NMPlatformError nm_platform_link_bond_add (NMPlatform *self, const char *name, c
NMPlatformError nm_platform_link_team_add (NMPlatform *self, const char *name, const NMPlatformLink **out_link);
gboolean nm_platform_link_delete (NMPlatform *self, int ifindex);
+gboolean nm_platform_link_set_netns (NMPlatform *self, int ifindex, int netns_fd);
+
/* convienience methods to lookup the link and access fields of NMPlatformLink. */
int nm_platform_link_get_ifindex (NMPlatform *self, const char *name);
const char *nm_platform_link_get_name (NMPlatform *self, int ifindex);