

Signed-off-by: Dave Hansen <haveblue@us.ibm.com>
---

 lxc-dave/include/linux/net_ns.h |   15 +++------
 lxc-dave/net/Kconfig            |    1 
 lxc-dave/net/Makefile           |    2 -
 lxc-dave/net/net_ns.c           |   64 ++++++++++++++++------------------------
 4 files changed, 32 insertions(+), 50 deletions(-)

diff -puN include/linux/net_ns.h~A1.1-netns-cleanups include/linux/net_ns.h
--- lxc/include/linux/net_ns.h~A1.1-netns-cleanups	2006-05-31 12:48:42.000000000 -0700
+++ lxc-dave/include/linux/net_ns.h	2006-05-31 12:48:42.000000000 -0700
@@ -57,11 +57,10 @@ static inline void put_net_ns(struct net
 static inline void exit_network(struct task_struct *p)
 {
 	struct net_namespace *net_ns = p->nsproxy->net_ns;
-	if (net_ns) {
+	if (net_ns)
 		put_net_ns(net_ns);
-	}
 }
-#else
+#else /* !CONFIG_NET_NS */
 
 static inline int unshare_network(unsigned long unshare_flags,
 				  struct net_namespace **new_net)
@@ -72,13 +71,9 @@ static inline int copy_network(int flags
 {
 	return 0;
 }
-static inline void put_net_ns(struct net_namespace *ns)
-{
-}
-static inline void exit_network(struct task_struct *p)
-{
-}
-#endif
+static inline void put_net_ns(struct net_namespace *ns) {}
+static inline void exit_network(struct task_struct *p) {}
+#endif /* CONFIG_NET_NS */
 static inline struct net_namespace *net_ns(void)
 {
 	return current->nsproxy->net_ns;
diff -puN net/Kconfig~A1.1-netns-cleanups net/Kconfig
--- lxc/net/Kconfig~A1.1-netns-cleanups	2006-05-31 12:48:42.000000000 -0700
+++ lxc-dave/net/Kconfig	2006-05-31 12:48:42.000000000 -0700
@@ -63,6 +63,7 @@ config INET
 config NET_NS
 	bool "Network namespaces"
 	default n
+	depends on NET
 	---help---
 	  Support for network namespaces.  This allows containers, i.e.
 	  vservers, to use network namespaces to provide isolated
diff -puN net/Makefile~A1.1-netns-cleanups net/Makefile
--- lxc/net/Makefile~A1.1-netns-cleanups	2006-05-31 12:48:42.000000000 -0700
+++ lxc-dave/net/Makefile	2006-05-31 12:48:42.000000000 -0700
@@ -50,6 +50,4 @@ obj-$(CONFIG_TIPC)		+= tipc/
 ifeq ($(CONFIG_NET),y)
 obj-$(CONFIG_SYSCTL)		+= sysctl_net.o
 endif
-ifeq ($(CONFIG_NET),y)
 obj-$(CONFIG_NET_NS)	+= net_ns.o
-endif
diff -puN net/net_ns.c~A1.1-netns-cleanups net/net_ns.c
--- lxc/net/net_ns.c~A1.1-netns-cleanups	2006-05-31 12:48:42.000000000 -0700
+++ lxc-dave/net/net_ns.c	2006-05-31 12:48:42.000000000 -0700
@@ -25,8 +25,6 @@ struct net_namespace init_net_ns = {
 	 },
 };
 
-#ifdef CONFIG_NET_NS
-
 /*
  * Remove a device to the namespace network devices list
  * when registered from a namespace
@@ -34,27 +32,25 @@ struct net_namespace init_net_ns = {
  * @dev_list: network namespace devices
  * Return ENODEV if the device does not exist,
  */
-extern int net_ns_unregister_dev(struct net_device* dev,
-				 struct net_ns_dev_list *devlist)
+int net_ns_unregister_dev(struct net_device* dev,
+			  struct net_ns_dev_list *devlist)
 {
 	struct net_ns_dev *db;
 	struct list_head *l;
-	int ret = 0;
+	int ret = -ENODEV;
 
 	write_lock(&devlist->lock);
-
 	list_for_each(l, &devlist->list) {
-
 		db = list_entry(l, struct net_ns_dev, list);
-		if (dev == db->dev) {
-			list_del(&db->list);
-			dev_put(dev);
-			kfree(db);
-			goto out;
-		}
+		if (dev != db->dev)
+			continue;
+
+		list_del(&db->list);
+		dev_put(dev);
+		kfree(db);
+		ret = 0;
+		break;
 	}
-	ret = -ENODEV;
-out:
 	write_unlock(&devlist->lock);
 	return ret;
 }
@@ -150,7 +146,6 @@ extern int net_ns_remove_dev(const char*
 	write_lock(&devlist->lock);
 
 	list_for_each(l, &devlist->list) {
-
 		db = list_entry(l, struct net_ns_dev, list);
 		dev = db->dev;
 
@@ -161,9 +156,7 @@ extern int net_ns_remove_dev(const char*
 			goto out;
 		}
 	}
-
 	ret = -ENODEV;
-
 out:
 	write_unlock(&devlist->lock);
 	return ret;
@@ -187,7 +180,6 @@ extern  struct net_device *net_ns_find_d
 	read_lock(&devlist->lock);
 
 	list_for_each(l, &devlist->list) {
-
 		db = list_entry(l, struct net_ns_dev, list);
 		dev = db->dev;
 
@@ -196,7 +188,6 @@ extern  struct net_device *net_ns_find_d
 			goto out;
 		}
 	}
-
 	dev = NULL;
 out:
 	read_unlock(&devlist->lock);
@@ -217,13 +208,13 @@ extern struct net_namespace *clone_net_n
 	struct net_ns_dev_list* new_dev_list;
 
 	new_ns = kmalloc(sizeof(*new_ns), GFP_KERNEL);
-	if (new_ns) {
-		kref_init(&new_ns->kref);
-		new_dev_list = &new_ns->dev_list;
-		INIT_LIST_HEAD(&new_dev_list->list);
-		new_dev_list->lock = RW_LOCK_UNLOCKED;
-	}
+	if (!new_ns)
+		return NULL;
 
+	kref_init(&new_ns->kref);
+	new_dev_list = &new_ns->dev_list;
+	INIT_LIST_HEAD(&new_dev_list->list);
+	new_dev_list->lock = RW_LOCK_UNLOCKED;
 	return new_ns;
 }
 
@@ -234,14 +225,15 @@ extern struct net_namespace *clone_net_n
 int unshare_network(unsigned long unshare_flags,
 		    struct net_namespace **new_net)
 {
-	if (unshare_flags & CLONE_NEWNET) {
-		if (!capable(CAP_SYS_ADMIN))
-			return -EPERM;
-
-		*new_net = clone_net_ns(current->nsproxy->net_ns);
-		if (!*new_net)
-			return -ENOMEM;
-	}
+	if (!(unshare_flags & CLONE_NEWNET))
+		return 0;
+
+	if (!capable(CAP_SYS_ADMIN))
+		return -EPERM;
+
+	*new_net = clone_net_ns(current->nsproxy->net_ns);
+	if (!*new_net)
+		return -ENOMEM;
 
 	return 0;
 }
@@ -293,7 +285,6 @@ static int free_net_ns_dev(struct net_ns
 	struct net_device *dev;
 
 	write_lock(&devlist->lock);
-
 	list_for_each_safe(l, next, &devlist->list) {
 		db = list_entry(l, struct net_ns_dev, list);
 		dev = db->dev;
@@ -301,7 +292,6 @@ static int free_net_ns_dev(struct net_ns
 		dev_put(dev);
 		kfree(db);
 	}
-
 	write_unlock(&devlist->lock);
 
 	return 0;
@@ -315,5 +305,3 @@ extern void free_net_ns(struct kref *kre
 	free_net_ns_dev(&ns->dev_list);
 	kfree(ns);
 }
-
-#endif
_
