[Devel] [patch 1/2] net namespace : assign IP address to specified nsproxy child

dlezcano at fr.ibm.com dlezcano at fr.ibm.com
Fri Jan 26 01:52:49 PST 2007


From: Daniel Lezcano <dlezcano at fr.ibm.com>

All IP configuration is done into the L2 namespace. The L3 namespace gains visibility to an IP address when this one is assigned from the L2 parent's namespace to the L3 child.
In order to be able to find a L3 child, the namespace identifier should be used to retrieve the namespace.

Signed-off-by: Daniel Lezcano <dlezcano at fr.ibm.com>

---
 net/core/net_namespace.c |   24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

Index: 2.6.20-rc4-mm1/net/core/net_namespace.c
===================================================================
--- 2.6.20-rc4-mm1.orig/net/core/net_namespace.c
+++ 2.6.20-rc4-mm1/net/core/net_namespace.c
@@ -15,6 +15,7 @@
 #include <linux/inetdevice.h>
 #include <linux/skbuff.h>
 #include <linux/ip.h>
+#include <linux/capability.h>
 
 #include <net/ip_fib.h>
 #include <net/sock.h>
@@ -57,8 +58,8 @@
 
 	kref_init(&ns->kref);
 	if ((push_net_ns(ns)) != old_ns)
-
 		BUG();
+
 	if (level ==  NET_NS_LEVEL2) {
 		ns->dev_base_p = NULL;
 		ns->dev_tail_p = &ns->dev_base_p;
@@ -200,25 +201,36 @@
 {
 	struct ifreq ifr;
 	struct sockaddr_in *sin = (struct sockaddr_in *)&ifr.ifr_addr;
-	struct net_namespace *net_ns = current_net_ns;
+	struct net_namespace *net_ns;
+	struct nsproxy *nsproxy;
 	struct net_device *dev;
 	struct in_device *in_dev;
 	struct in_ifaddr **ifap = NULL;
 	struct in_ifaddr *ifa = NULL;
 	char *colon;
-	int err;
+	int err, id = 0;
 
 	if (!capable(CAP_NET_ADMIN))
 		return -EPERM;
 
-	if (net_ns->level != NET_NS_LEVEL3)
-		return -EPERM;
-
 	if (copy_from_user(&ifr, arg, sizeof(struct ifreq)))
 		return -EFAULT;
 
 	ifr.ifr_name[IFNAMSIZ - 1] = 0;
+	id = sin->sin_port;
 
+	nsproxy = find_nsproxy_by_id(id);
+	if (!nsproxy)
+		return -ESRCH;
+
+	net_ns = nsproxy->net_ns;
+	put_nsproxy(nsproxy);
+
+	if (net_ns->parent != current_net_ns)
+		return -EPERM;
+
+	if (net_ns->level != NET_NS_LEVEL3)
+		return -EINVAL;
 
 	colon = strchr(ifr.ifr_name, ':');
 	if (colon)

-- 
_______________________________________________
Containers mailing list
Containers at lists.osdl.org
https://lists.osdl.org/mailman/listinfo/containers




More information about the Devel mailing list