mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrey Savochkin <saw@swsoft.com>
To: dlezcano@fr.ibm.com
Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
	serue@us.ibm.com, haveblue@us.ibm.com, clg@fr.ibm.com,
	Andrew Morton <akpm@osdl.org>,
	dev@sw.ru, herbert@13thfloor.at, devel@openvz.org,
	sam@vilain.net, ebiederm@xmission.com, viro@ftp.linux.org.uk
Subject: [patch 4/4] Network namespaces: playing and debugging
Date: Mon, 26 Jun 2006 13:55:37 +0400	[thread overview]
Message-ID: <20060626135537.D28942@castle.nmd.msu.ru> (raw)
In-Reply-To: <20060626135427.C28942@castle.nmd.msu.ru>; from "Andrey Savochkin" on Mon, Jun 26, 2006 at 01:54:27PM

Temporary code to play with network namespaces in the simplest way.
Do
	exec 7< /proc/net/net_ns
in your bash shell and you'll get a brand new network namespace.
There you can, for example, do
	ip link set lo up
	ip addr list
	ip addr add 1.2.3.4 dev lo
	ping -n 1.2.3.4

Signed-off-by: Andrey Savochkin <saw@swsoft.com>
---
 dev.c |   27 ++++++++++++++++++++++++++-
 1 files changed, 26 insertions, 1 deletion

--- ./net/core/dev.c.vensdbg	Fri Jun 23 11:50:16 2006
+++ ./net/core/dev.c	Fri Jun 23 11:50:40 2006
@@ -3444,6 +3444,8 @@ int net_ns_start(void)
 	if (err)
 		goto out_register;
 	put_net_ns(orig_ns);
+	printk(KERN_DEBUG "NET_NS: created new netcontext %p for %s (pid=%d)\n",
+			ns, task->comm, task->tgid);
 	return 0;
 
 out_register:
@@ -3461,6 +3463,7 @@ EXPORT_SYMBOL(net_ns_start);
 
 void net_ns_free(struct net_namespace *ns)
 {
+	printk(KERN_DEBUG "NET_NS: netcontext %p freed\n", ns);
 	kfree(ns);
 }
 EXPORT_SYMBOL(net_ns_free);
@@ -3473,8 +3476,13 @@ static void net_ns_destroy(void *data)
 	ns = data;
 	push_net_ns(ns, orig_ns);
 	unregister_netdev(ns->loopback);
+	if (!list_empty(&ns->dev_base)) {
+		printk("NET_NS: BUG: context %p has devices! ref %d\n",
+				ns, atomic_read(&ns->active_ref));
+		pop_net_ns(orig_ns);
+		return;
+	}
 	ip_fib_struct_fini();
-	BUG_ON(!list_empty(&ns->dev_base));
 	pop_net_ns(orig_ns);
 
 	/* drop (hopefully) final reference */
@@ -3483,9 +3491,23 @@ static void net_ns_destroy(void *data)
 
 void net_ns_stop(struct net_namespace *ns)
 {
+	printk(KERN_DEBUG "NET_NS: netcontext %p scheduled for stop\n", ns);
 	execute_in_process_context(net_ns_destroy, ns, &ns->destroy_work);
 }
 EXPORT_SYMBOL(net_ns_stop);
+
+static int net_ns_open(struct inode *i, struct file *f)
+{
+	return net_ns_start();
+}
+static struct file_operations net_ns_fops = {
+	.open	= net_ns_open,
+};
+static int net_ns_init(void)
+{
+	return proc_net_fops_create("net_ns", S_IRWXU, &net_ns_fops)
+			? 0 : -ENOMEM;
+}
 #endif
 
 /*
@@ -3550,6 +3572,9 @@ static int __init net_dev_init(void)
 	hotcpu_notifier(dev_cpu_callback, 0);
 	dst_init();
 	dev_mcast_init();
+#ifdef CONFIG_NET_NS
+	net_ns_init();
+#endif
 	rc = 0;
 out:
 	return rc;

  reply	other threads:[~2006-06-26  9:56 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-06-26  9:49 [patch 1/4] Network namespaces: cleanup of dev_base list use Andrey Savochkin
2006-06-26  9:52 ` [patch 2/4] " Andrey Savochkin
2006-06-26  9:54   ` [patch 3/4] Network namespaces: IPv4 FIB/routing in namespaces Andrey Savochkin
2006-06-26  9:55     ` Andrey Savochkin [this message]
2006-06-26 15:04       ` [patch 4/4] Network namespaces: playing and debugging Daniel Lezcano
2006-06-26 15:43         ` Andrey Savochkin
2006-06-26 17:29           ` Daniel Lezcano
2006-06-26 19:34             ` Andrey Savochkin
2006-06-26 14:56     ` [patch 3/4] Network namespaces: IPv4 FIB/routing in namespaces Daniel Lezcano
2006-06-26 15:46       ` Andrey Savochkin
2006-06-26 15:57         ` Daniel Lezcano
2006-06-26 19:39           ` Andrey Savochkin
2006-06-26 20:05       ` Herbert Poetzl
2006-06-27  9:25         ` Andrey Savochkin
2006-06-28 13:51       ` Daniel Lezcano
2006-06-28 14:19         ` Herbert Poetzl
2006-06-28 14:30         ` Andrey Savochkin
2006-06-28 14:34           ` Kirill Korotaev
2006-06-28 16:56             ` Daniel Lezcano
2006-06-28 17:10               ` Ben Greear
2006-06-28 15:05         ` Eric W. Biederman
2006-06-26 15:13 ` [RFC][patch 1/4] Network namespaces: cleanup of dev_base list use Eric W. Biederman
2006-06-26 15:42   ` [patch " Andrey Savochkin
2006-06-26 16:26     ` Eric W. Biederman
2006-06-26 20:14       ` Andrey Savochkin
2006-06-26 21:02         ` Eric W. Biederman
2006-06-27  6:59   ` [RFC][patch " Kirill Korotaev
2006-06-27 11:13     ` Eric W. Biederman
2006-06-27 15:08       ` Kirill Korotaev
2006-06-27 15:26         ` Serge E. Hallyn
2006-06-27 16:54         ` Eric W. Biederman
2006-06-27 17:20 ` [RFC] Network namespaces a path to mergable code Eric W. Biederman
2006-06-27 17:58   ` Andrey Savochkin
2006-06-27 22:20     ` Sam Vilain
2006-06-28  4:33       ` Eric W. Biederman
2006-06-28  5:59         ` Abdallah Chatila
2006-06-28  6:19         ` Sam Vilain
2006-06-28  6:55           ` Eric W. Biederman
2006-06-28  9:54             ` Cedric Le Goater
2006-06-28 14:03               ` Eric W. Biederman
2006-06-28 14:15                 ` Serge E. Hallyn
2006-06-28 14:56                   ` Eric W. Biederman
2006-06-28  4:20     ` Eric W. Biederman
2006-06-28 11:06       ` Andrey Savochkin
2006-06-28 16:51         ` Eric W. Biederman
2006-06-28 17:22           ` Andrey Savochkin
2006-06-28 17:40             ` Herbert Poetzl
2006-06-28 17:50             ` Eric W. Biederman
2006-06-28 18:11             ` Eric W. Biederman
2006-06-28 18:14             ` Eric W. Biederman
2006-06-28 18:51               ` Andrey Savochkin
2006-06-28 21:53         ` Daniel Lezcano
2006-06-28 22:54           ` James Morris
2006-06-29  0:19             ` Eric W. Biederman
2006-06-29  0:25           ` Eric W. Biederman
2006-06-29  9:42             ` Daniel Lezcano
2006-06-28 10:20   ` [RFC] " Cedric Le Goater
2006-06-28 15:20     ` Eric W. Biederman

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=20060626135537.D28942@castle.nmd.msu.ru \
    --to=saw@swsoft.com \
    --cc=akpm@osdl.org \
    --cc=clg@fr.ibm.com \
    --cc=dev@sw.ru \
    --cc=devel@openvz.org \
    --cc=dlezcano@fr.ibm.com \
    --cc=ebiederm@xmission.com \
    --cc=haveblue@us.ibm.com \
    --cc=herbert@13thfloor.at \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=sam@vilain.net \
    --cc=serue@us.ibm.com \
    --cc=viro@ftp.linux.org.uk \
    /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

all inboxes | Powered by JetHome®