netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: dlezcano@fr.ibm.com
To: containers@lists.osdl.org
Cc: netdev@vger.kernel.org
Subject: [patch 03/12] net namespace : share network ressources L2 with L3
Date: Fri, 19 Jan 2007 16:47:17 +0100	[thread overview]
Message-ID: <20070119155346.479031252@localhost.localdomain> (raw)
In-Reply-To: 20070119154714.439706567@localhost.localdomain

[-- Attachment #1: net-namespace-l3-use-parent-devlist.patch --]
[-- Type: text/plain, Size: 4265 bytes --]

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

L3 namespace will use routes and devices belonging to its parent, so
the old network namespace structure is copied when allocating a new
one. By this way, hash value, dev list, routes are accessible from the
L3 namespaces. In case of L2 namespace, these values are overwritten
by the newly allocated values.

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

---
 include/linux/net_namespace.h |   14 ++++++++++++++
 net/core/dev.c                |    4 ++--
 net/core/net_namespace.c      |   33 ++++++++++++++++++---------------
 3 files changed, 34 insertions(+), 17 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
@@ -37,7 +37,7 @@
  * Return ERR_PTR on error, new ns otherwise
  */
 static struct net_namespace *clone_net_ns(unsigned int level,
-						struct net_namespace *old_ns)
+					  struct net_namespace *old_ns)
 {
 	struct net_namespace *ns;
 
@@ -45,23 +45,26 @@
 	if (current_net_ns->level == NET_NS_LEVEL3)
 		return ERR_PTR(-EPERM);
 
-	ns = kzalloc(sizeof(struct net_namespace), GFP_KERNEL);
+	ns = kmemdup(old_ns, sizeof(struct net_namespace), GFP_KERNEL);
 	if (!ns)
 		return NULL;
 
 	kref_init(&ns->kref);
-	ns->dev_base_p = NULL;
-	ns->dev_tail_p = &ns->dev_base_p;
-	ns->hash = net_random();
-
 	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;
+		ns->hash = net_random();
+
 #ifdef CONFIG_IP_MULTIPLE_TABLES
 		INIT_LIST_HEAD(&ns->fib_rules_ops_list);
 #endif
 		if (ip_fib_struct_init())
 			goto out_fib4;
+		if (loopback_init())
+			goto out_loopback;
 	}
 
 	if (level == NET_NS_LEVEL3) {
@@ -70,8 +73,6 @@
 	}
 
 	ns->level = level;
-	if (loopback_init())
-		goto out_loopback;
 	pop_net_ns(old_ns);
 	printk(KERN_DEBUG "NET_NS: created new netcontext %p, level %u, "
 		"for %s (pid=%d)\n", ns, (ns->level == NET_NS_LEVEL2) ?
@@ -127,15 +128,17 @@
 	struct net_namespace *ns;
 
 	ns = container_of(kref, struct net_namespace, kref);
-	unregister_netdev(ns->loopback_dev_p);
-	if (ns->dev_base_p != NULL) {
-		printk("NET_NS: BUG: namespace %p has devices! ref %d\n",
-				ns, atomic_read(&ns->kref.refcount));
-		return;
-	}
 
-	if (ns->level == NET_NS_LEVEL2)
+	if (ns->level == NET_NS_LEVEL2) {
 		ip_fib_struct_cleanup(ns);
+		unregister_netdev(ns->loopback_dev_p);
+		if (ns->dev_base_p != NULL) {
+			printk("NET_NS: BUG: namespace %p has devices! ref %d\n",
+			       ns, atomic_read(&ns->kref.refcount));
+			return;
+		}
+	}
+
 	if (ns->level == NET_NS_LEVEL3)
 		put_net_ns(ns->parent);
 
Index: 2.6.20-rc4-mm1/include/linux/net_namespace.h
===================================================================
--- 2.6.20-rc4-mm1.orig/include/linux/net_namespace.h
+++ 2.6.20-rc4-mm1/include/linux/net_namespace.h
@@ -56,6 +56,15 @@
 DECLARE_PER_CPU(struct net_namespace *, exec_net_ns);
 #define current_net_ns		(__get_cpu_var(exec_net_ns))
 
+static inline struct net_namespace *net_ns_l2(void)
+{
+	struct net_namespace *net_ns = current_net_ns;
+
+	if (net_ns->level == NET_NS_LEVEL3)
+		return net_ns->parent;
+	return net_ns;
+}
+
 static inline void init_current_net_ns(int cpu)
 {
 	get_net_ns(&init_net_ns);
@@ -110,6 +119,11 @@
 
 #define current_net_ns			NULL
 
+static inline struct net_namespace *net_ns_l2(void)
+{
+	return NULL;
+}
+
 static inline void init_current_net_ns(int cpu)
 {
 }
Index: 2.6.20-rc4-mm1/net/core/dev.c
===================================================================
--- 2.6.20-rc4-mm1.orig/net/core/dev.c
+++ 2.6.20-rc4-mm1/net/core/dev.c
@@ -485,7 +485,7 @@
 struct net_device *__dev_get_by_name(const char *name)
 {
 	struct hlist_node *p;
-	struct net_namespace *ns = current_net_ns;
+	struct net_namespace *ns = net_ns_l2();
 
 	hlist_for_each(p, dev_name_hash(name, ns)) {
 		struct net_device *dev
@@ -768,7 +768,7 @@
 	if (!err) {
 		hlist_del(&dev->name_hlist);
 		hlist_add_head(&dev->name_hlist, dev_name_hash(dev->name,
-							current_net_ns));
+							       net_ns_l2()));
 		raw_notifier_call_chain(&netdev_chain,
 				NETDEV_CHANGENAME, dev);
 	}

-- 

  parent reply	other threads:[~2007-01-19 16:40 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-01-19 15:47 [patch 00/12] net namespace : L3 namespace - introduction dlezcano
2007-01-19 15:47 ` [patch 01/12] net namespace : initialize init process to level 2 dlezcano
2007-01-19 15:47 ` [patch 02/12] net namespace : store L2 parent namespace dlezcano
2007-01-19 15:47 ` dlezcano [this message]
2007-01-19 15:47 ` [patch 04/12] net namespace : isolate the inet device dlezcano
2007-01-19 15:47 ` [patch 05/12] net namespace : ioctl to push ifa to net namespace l3 dlezcano
2007-01-20  4:52   ` Herbert Poetzl
2007-01-20 11:48     ` Daniel Lezcano
2007-01-19 15:47 ` [patch 06/12] net namespace : check bind address dlezcano
2007-01-19 15:47 ` [patch 07/12] net namespace: set source addresse dlezcano
2007-01-19 15:47 ` [patch 08/12] net namespace : find namespace by addr dlezcano
2007-01-20  4:56   ` Herbert Poetzl
2007-01-19 15:47 ` [patch 09/12] net namespace : make loopback address always visible dlezcano
2007-01-19 15:47 ` [patch 10/12] net namespace : add the loopback isolation dlezcano
2007-01-19 15:47 ` [patch 11/12] net namespace : debugfs - add net_ns debugfs dlezcano
2007-01-19 15:47 ` [patch 12/12] net namespace : Add broadcasting dlezcano
2007-01-20  4:58   ` Herbert Poetzl
2007-01-20 11:54     ` Daniel Lezcano
2007-01-20  4:48 ` [patch 00/12] net namespace : L3 namespace - introduction Herbert Poetzl
2007-01-20 11:42   ` Daniel Lezcano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070119155346.479031252@localhost.localdomain \
    --to=dlezcano@fr.ibm.com \
    --cc=containers@lists.osdl.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).