From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dmitry Mishin Subject: [PATCH 2/12] L2 network namespace (v3): network devices virtualization Date: Wed, 17 Jan 2007 18:59:17 +0300 Message-ID: <200701171859.18339.dim@openvz.org> References: <200701171851.14734.dim@openvz.org> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Cc: alexey@sw.ru, saw@sw.ru, Andrew Morton , netdev@vger.kernel.org Return-path: Received: from mailhub.sw.ru ([195.214.233.200]:18089 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751443AbXAQQBX (ORCPT ); Wed, 17 Jan 2007 11:01:23 -0500 To: containers@lists.osdl.org In-Reply-To: <200701171851.14734.dim@openvz.org> Content-Disposition: inline Sender: netdev-owner@vger.kernel.org List-Id: netdev.vger.kernel.org Added ability to have per-namespace network devices. Signed-off-by: Dmitry Mishin --- include/linux/net_namespace.h | 8 +++- include/linux/netdevice.h | 8 ++++ net/core/dev.c | 77 +++++++++++++++++++++++++++++++++++------- net/core/net-sysfs.c | 23 ++++++++++++ net/core/net_namespace.c | 11 ++++++ 5 files changed, 114 insertions(+), 13 deletions(-) --- linux-2.6.20-rc4-mm1.net_ns.orig/include/linux/net_namespace.h +++ linux-2.6.20-rc4-mm1.net_ns/include/linux/net_namespace.h @@ -7,7 +7,9 @@ #include struct net_namespace { - struct kref kref; + struct kref kref; + struct net_device *dev_base_p, **dev_tail_p; + unsigned int hash; }; extern struct net_namespace init_net_ns; @@ -60,6 +62,8 @@ static inline void pop_net_ns(struct net #define net_ns_match(target, ns) ((target) == (ns)) +#define net_ns_hash(ns) ((ns)->hash) + #else /* CONFIG_NET_NS */ #define INIT_NET_NS(net_ns) @@ -103,6 +107,8 @@ static inline void pop_net_ns(struct net #define net_ns_match(target, ns) ((void)(ns), 1) +#define net_ns_hash(ns) (0) + #endif /* !CONFIG_NET_NS */ #endif /* _LINUX_NET_NAMESPACE_H */ --- linux-2.6.20-rc4-mm1.net_ns.orig/include/linux/netdevice.h +++ linux-2.6.20-rc4-mm1.net_ns/include/linux/netdevice.h @@ -389,6 +389,7 @@ struct net_device int promiscuity; int allmulti; + struct net_namespace *net_ns; /* Protocol specific pointers */ @@ -567,9 +568,16 @@ struct packet_type { #include #include +#include extern struct net_device loopback_dev; /* The loopback */ +#ifndef CONFIG_NET_NS extern struct net_device *dev_base; /* All devices */ +#define dev_base_ns(dev) dev_base +#else +#define dev_base (current_net_ns->dev_base_p) +#define dev_base_ns(dev) (dev->net_ns->dev_base_p) +#endif extern rwlock_t dev_base_lock; /* Device list lock */ extern int netdev_boot_setup_check(struct net_device *dev); --- linux-2.6.20-rc4-mm1.net_ns.orig/net/core/dev.c +++ linux-2.6.20-rc4-mm1.net_ns/net/core/dev.c @@ -90,6 +90,7 @@ #include #include #include +#include #include #include #include @@ -174,20 +175,27 @@ static spinlock_t net_dma_event_lock; * unregister_netdevice(), which must be called with the rtnl * semaphore held. */ +#ifndef CONFIG_NET_NS struct net_device *dev_base; static struct net_device **dev_tail = &dev_base; -DEFINE_RWLOCK(dev_base_lock); - +#define dev_tail_ns(dev) dev_tail EXPORT_SYMBOL(dev_base); +#else +#define dev_tail_ns(dev) (dev->net_ns->dev_tail_p) +#endif + +DEFINE_RWLOCK(dev_base_lock); EXPORT_SYMBOL(dev_base_lock); #define NETDEV_HASHBITS 8 static struct hlist_head dev_name_head[1<kref.refcount)); + return; + } kfree(ns); }