Linux Container Development
 help / color / mirror / Atom feed
From: Vivien Chappelier <vivien.chappelier-L+G57L1VLRbR7s880joybQ@public.gmane.org>
To: containers-qjLDD68F18O7TbgM5vRIOg@public.gmane.org
Subject: [PATCH 6/6] netns: configurable number of initial network namespaces
Date: Thu, 30 Oct 2008 14:11:11 +0100	[thread overview]
Message-ID: <20081030131111.GF17665@thomson.net> (raw)

This allows the creation of more than one network namespace at boot time.
---
 net/Kconfig              |    7 +++++++
 net/core/net_namespace.c |   19 ++++++++++++++++++-
 2 files changed, 25 insertions(+), 1 deletions(-)

diff --git a/net/Kconfig b/net/Kconfig
index 8c3d97c..c896bdf 100644
--- a/net/Kconfig
+++ b/net/Kconfig
@@ -32,6 +32,13 @@ config NET_NS
 	  Allow user space to create what appear to be multiple instances
 	  of the network stack.
 
+config NET_NS_NR
+	int "Initial number of network namespaces"
+	default 1
+	depends on NET_NS
+	help
+	  Number of network stacks to create at start-up.
+
 source "net/packet/Kconfig"
 source "net/unix/Kconfig"
 source "net/xfrm/Kconfig"
diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
index 596cb83..1cafa31 100644
--- a/net/core/net_namespace.c
+++ b/net/core/net_namespace.c
@@ -297,8 +297,25 @@ static int __init net_ns_init(void)
 	rtnl_unlock();
 
 	mutex_unlock(&net_mutex);
+
+#if defined(CONFIG_NET_NS) && CONFIG_NET_NS_NR > 1
+	/* Create additional initial namespaces */
+	{
+		struct net *net;
+		int i;
+
+		for (i = 1; i < CONFIG_NET_NS_NR; i++) {
+			net = copy_net_ns(CLONE_NEWNET, &init_net);
+			if (IS_ERR(net)) {
+				err = PTR_ERR(net);
+				break;
+			}
+		}
+	}
+#endif
+
 	if (err)
-		panic("Could not setup the initial network namespace");
+		panic("Could not setup the initial network namespace(s)");
 
 	return 0;
 }
-- 
1.5.4.4

                 reply	other threads:[~2008-10-30 13:11 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20081030131111.GF17665@thomson.net \
    --to=vivien.chappelier-l+g57l1vlrbr7s880joybq@public.gmane.org \
    --cc=containers-qjLDD68F18O7TbgM5vRIOg@public.gmane.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