From patchwork Thu Jun 18 11:56:39 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Berg X-Patchwork-Id: 28861 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@bilbo.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from ozlabs.org (ozlabs.org [203.10.76.45]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "mx.ozlabs.org", Issuer "CA Cert Signing Authority" (verified OK)) by bilbo.ozlabs.org (Postfix) with ESMTPS id A3792B722B for ; Thu, 18 Jun 2009 21:57:24 +1000 (EST) Received: by ozlabs.org (Postfix) id 9457EDDDA1; Thu, 18 Jun 2009 21:57:24 +1000 (EST) Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by ozlabs.org (Postfix) with ESMTP id 1EF36DDDA0 for ; Thu, 18 Jun 2009 21:57:24 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756233AbZFRL5Q (ORCPT ); Thu, 18 Jun 2009 07:57:16 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754646AbZFRL5O (ORCPT ); Thu, 18 Jun 2009 07:57:14 -0400 Received: from xc.sipsolutions.net ([83.246.72.84]:55447 "EHLO sipsolutions.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754177AbZFRL5O (ORCPT ); Thu, 18 Jun 2009 07:57:14 -0400 Received: by sipsolutions.net with esmtpsa (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1MHGF1-0004Cl-J8; Thu, 18 Jun 2009 13:57:15 +0200 Subject: [PATCH] net: move and export get_net_ns_by_pid From: Johannes Berg To: Netdev Cc: "Eric W. Biederman" Date: Thu, 18 Jun 2009 13:56:39 +0200 Message-Id: <1245326201.13790.10.camel@johannes.local> Mime-Version: 1.0 X-Mailer: Evolution 2.26.2 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The function get_net_ns_by_pid(), to get a network namespace from a pid_t, will be required in cfg80211 as well. Therefore, let's move it to net_namespace.c and export it. Signed-off-by: Johannes Berg --- I first thought we could make it a static inline when !CONFIG_NET_NS, but we need to return -ESRCH for invalid PIDs so that isn't possible. include/net/net_namespace.h | 2 ++ net/core/net_namespace.c | 21 +++++++++++++++++++++ net/core/rtnetlink.c | 21 +-------------------- 3 files changed, 24 insertions(+), 20 deletions(-) -- 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 --- wireless-testing.orig/include/net/net_namespace.h 2009-06-18 13:45:57.000000000 +0200 +++ wireless-testing/include/net/net_namespace.h 2009-06-18 13:51:57.000000000 +0200 @@ -111,6 +111,8 @@ static inline struct net *copy_net_ns(un extern struct list_head net_namespace_list; +extern struct net *get_net_ns_by_pid(pid_t pid); + #ifdef CONFIG_NET_NS extern void __put_net(struct net *net); --- wireless-testing.orig/net/core/net_namespace.c 2009-06-18 13:45:57.000000000 +0200 +++ wireless-testing/net/core/net_namespace.c 2009-06-18 13:52:22.000000000 +0200 @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -204,6 +205,26 @@ struct net *copy_net_ns(unsigned long fl } #endif +struct net *get_net_ns_by_pid(pid_t pid) +{ + struct task_struct *tsk; + struct net *net; + + /* Lookup the network namespace */ + net = ERR_PTR(-ESRCH); + rcu_read_lock(); + tsk = find_task_by_vpid(pid); + if (tsk) { + struct nsproxy *nsproxy; + nsproxy = task_nsproxy(tsk); + if (nsproxy) + net = get_net(nsproxy->net_ns); + } + rcu_read_unlock(); + return net; +} +EXPORT_SYMBOL_GPL(get_net_ns_by_pid); + static int __init net_ns_init(void) { struct net_generic *ng; --- wireless-testing.orig/net/core/rtnetlink.c 2009-06-18 13:45:42.000000000 +0200 +++ wireless-testing/net/core/rtnetlink.c 2009-06-18 13:50:05.000000000 +0200 @@ -35,7 +35,6 @@ #include #include #include -#include #include #include @@ -52,6 +51,7 @@ #include #include #include +#include struct rtnl_link { @@ -725,25 +725,6 @@ static const struct nla_policy ifla_info [IFLA_INFO_DATA] = { .type = NLA_NESTED }, }; -static struct net *get_net_ns_by_pid(pid_t pid) -{ - struct task_struct *tsk; - struct net *net; - - /* Lookup the network namespace */ - net = ERR_PTR(-ESRCH); - rcu_read_lock(); - tsk = find_task_by_vpid(pid); - if (tsk) { - struct nsproxy *nsproxy; - nsproxy = task_nsproxy(tsk); - if (nsproxy) - net = get_net(nsproxy->net_ns); - } - rcu_read_unlock(); - return net; -} - static int validate_linkmsg(struct net_device *dev, struct nlattr *tb[]) { if (dev) {