From patchwork Thu May 20 18:10:39 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: gregkh@suse.de X-Patchwork-Id: 53100 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 6814CB7D2D for ; Fri, 21 May 2010 04:11:10 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757017Ab0ETSK5 (ORCPT ); Thu, 20 May 2010 14:10:57 -0400 Received: from kroah.org ([198.145.64.141]:43252 "EHLO coco.kroah.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757004Ab0ETSKy (ORCPT ); Thu, 20 May 2010 14:10:54 -0400 Received: from localhost (c-24-16-163-131.hsd1.wa.comcast.net [24.16.163.131]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by coco.kroah.org (Postfix) with ESMTPSA id 36E69484ED; Thu, 20 May 2010 11:10:54 -0700 (PDT) Subject: patch netns-teach-network-device-kobjects-which-namespace-they-are-in.patch added to gregkh-2.6 tree To: ebiederm@xmission.com, bcrl@lhnet.ca, cornelia.huck@de.ibm.com, davem@davemloft.net, eric.dumazet@gmail.com, gregkh@suse.de, kay.sievers@vrfy.org, netdev@vger.kernel.org, serue@us.ibm.com, tj@kernel.org From: Date: Thu, 20 May 2010 11:10:39 -0700 In-Reply-To: <1273019809-16472-2-git-send-email-ebiederm@xmission.com> Message-ID: <12743790391416@kroah.org> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This is a note to let you know that I've just added the patch titled Subject: [PATCH 2/6] netns: Teach network device kobjects which namespace they are in. to my gregkh-2.6 tree. Its filename is netns-teach-network-device-kobjects-which-namespace-they-are-in.patch This tree can be found at http://www.kernel.org/pub/linux/kernel/people/gregkh/gregkh-2.6/patches/ From ebiederm@xmission.com Thu May 20 10:41:04 2010 From: "Eric W. Biederman" Date: Tue, 4 May 2010 17:36:45 -0700 Subject: [PATCH 2/6] netns: Teach network device kobjects which namespace they are in. To: Greg Kroah-Hartman Cc: Kay Sievers , linux-kernel@vger.kernel.org, Tejun Heo , Cornelia Huck , Eric Dumazet , Benjamin LaHaise , Serge Hallyn , , David Miller , "Eric W. Biederman" Message-ID: <1273019809-16472-2-git-send-email-ebiederm@xmission.com> From: Eric W. Biederman The problem. Network devices show up in sysfs and with the network namespace active multiple devices with the same name can show up in the same directory, ouch! To avoid that problem and allow existing applications in network namespaces to see the same interface that is currently presented in sysfs, this patch enables the tagging directory support in sysfs. By using the network namespace pointers as tags to separate out the the sysfs directory entries we ensure that we don't have conflicts in the directories and applications only see a limited set of the network devices. Signed-off-by: Eric W. Biederman Acked-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- include/linux/kobject.h | 1 + net/Kconfig | 8 ++++++++ net/core/net-sysfs.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html --- a/include/linux/kobject.h +++ b/include/linux/kobject.h @@ -142,6 +142,7 @@ extern const struct sysfs_ops kobj_sysfs */ enum kobj_ns_type { KOBJ_NS_TYPE_NONE = 0, + KOBJ_NS_TYPE_NET, KOBJ_NS_TYPES }; --- a/net/Kconfig +++ b/net/Kconfig @@ -45,6 +45,14 @@ config COMPAT_NETLINK_MESSAGES menu "Networking options" +config NET_NS + bool "Network namespace support" + default n + depends on EXPERIMENTAL && NAMESPACES + help + Allow user space to create what appear to be multiple instances + of the network stack. + source "net/packet/Kconfig" source "net/unix/Kconfig" source "net/xfrm/Kconfig" --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c @@ -14,7 +14,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -467,6 +469,37 @@ static struct attribute_group wireless_g }; #endif +static const void *net_current_ns(void) +{ + return current->nsproxy->net_ns; +} + +static const void *net_initial_ns(void) +{ + return &init_net; +} + +static const void *net_netlink_ns(struct sock *sk) +{ + return sock_net(sk); +} + +static struct kobj_ns_type_operations net_ns_type_operations = { + .type = KOBJ_NS_TYPE_NET, + .current_ns = net_current_ns, + .netlink_ns = net_netlink_ns, + .initial_ns = net_initial_ns, +}; + +static void net_kobj_ns_exit(struct net *net) +{ + kobj_ns_exit(KOBJ_NS_TYPE_NET, net); +} + +static struct pernet_operations sysfs_net_ops = { + .exit = net_kobj_ns_exit, +}; + #endif /* CONFIG_SYSFS */ #ifdef CONFIG_HOTPLUG @@ -507,6 +540,13 @@ static void netdev_release(struct device kfree((char *)dev - dev->padded); } +static const void *net_namespace(struct device *d) +{ + struct net_device *dev; + dev = container_of(d, struct net_device, dev); + return dev_net(dev); +} + static struct class net_class = { .name = "net", .dev_release = netdev_release, @@ -516,6 +556,8 @@ static struct class net_class = { #ifdef CONFIG_HOTPLUG .dev_uevent = netdev_uevent, #endif + .ns_type = &net_ns_type_operations, + .namespace = net_namespace, }; /* Delete sysfs entries but hold kobject reference until after all @@ -588,5 +630,9 @@ void netdev_initialize_kobject(struct ne int netdev_kobject_init(void) { + kobj_ns_type_register(&net_ns_type_operations); +#ifdef CONFIG_SYSFS + register_pernet_subsys(&sysfs_net_ops); +#endif return class_register(&net_class); }