netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [Patch net-next 1/2] netpoll: use ipv6_addr_equal() to compare ipv6 addr
@ 2013-01-23  9:02 Cong Wang
  2013-01-23  9:02 ` [Patch net-next 2/2] netpoll: use the net namespace of current process instead of init_net Cong Wang
  0 siblings, 1 reply; 5+ messages in thread
From: Cong Wang @ 2013-01-23  9:02 UTC (permalink / raw)
  To: netdev; +Cc: David S. Miller, Cong Wang

From: Cong Wang <amwang@redhat.com>

ipv6_addr_equal() is faster.

Cc: David S. Miller <davem@davemloft.net>
Signed-off-by: Cong Wang <amwang@redhat.com>
---
 net/core/netpoll.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/net/core/netpoll.c b/net/core/netpoll.c
index e2f79a1..a6f39b6 100644
--- a/net/core/netpoll.c
+++ b/net/core/netpoll.c
@@ -635,7 +635,7 @@ static void netpoll_neigh_reply(struct sk_buff *skb, struct netpoll_info *npinfo
 
 		spin_lock_irqsave(&npinfo->rx_lock, flags);
 		list_for_each_entry_safe(np, tmp, &npinfo->rx_np, rx) {
-			if (memcmp(daddr, &np->local_ip, sizeof(*daddr)))
+			if (!ipv6_addr_equal(daddr, &np->local_ip.in6))
 				continue;
 
 			hlen = LL_RESERVED_SPACE(np->dev);
@@ -828,9 +828,9 @@ int __netpoll_rx(struct sk_buff *skb, struct netpoll_info *npinfo)
 		if (udp6_csum_init(skb, uh, IPPROTO_UDP))
 			goto out;
 		list_for_each_entry_safe(np, tmp, &npinfo->rx_np, rx) {
-			if (memcmp(&np->local_ip.in6, &ip6h->daddr, sizeof(struct in6_addr)) != 0)
+			if (!ipv6_addr_equal(&np->local_ip.in6, &ip6h->daddr))
 				continue;
-			if (memcmp(&np->remote_ip.in6, &ip6h->saddr, sizeof(struct in6_addr)) != 0)
+			if (!ipv6_addr_equal(&np->remote_ip.in6, &ip6h->saddr))
 				continue;
 			if (np->local_port && np->local_port != ntohs(uh->dest))
 				continue;
-- 
1.7.7.6

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [Patch net-next 2/2] netpoll: use the net namespace of current process instead of init_net
  2013-01-23  9:02 [Patch net-next 1/2] netpoll: use ipv6_addr_equal() to compare ipv6 addr Cong Wang
@ 2013-01-23  9:02 ` Cong Wang
  2013-01-26 10:00   ` Cong Wang
  0 siblings, 1 reply; 5+ messages in thread
From: Cong Wang @ 2013-01-23  9:02 UTC (permalink / raw)
  To: netdev; +Cc: Eric W. Biederman, David S. Miller, Cong Wang

From: Cong Wang <amwang@redhat.com>

This will allow us to setup netconsole in a different namespace
rather than where init_net is.

Cc: Eric W. Biederman <ebiederm@xmission.com>
Cc: David S. Miller <davem@davemloft.net>
Signed-off-by: Cong Wang <amwang@redhat.com>
---
 net/core/netpoll.c |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/net/core/netpoll.c b/net/core/netpoll.c
index a6f39b6..c3b2589 100644
--- a/net/core/netpoll.c
+++ b/net/core/netpoll.c
@@ -1046,11 +1046,16 @@ int netpoll_setup(struct netpoll *np)
 {
 	struct net_device *ndev = NULL;
 	struct in_device *in_dev;
+	struct net *net = &init_net;
+	struct nsproxy *ns = task_nsproxy(current);
 	int err;
 
 	rtnl_lock();
-	if (np->dev_name)
-		ndev = __dev_get_by_name(&init_net, np->dev_name);
+	if (np->dev_name) {
+		if (ns != NULL)
+			net = get_net(ns->net_ns);
+		ndev = __dev_get_by_name(net, np->dev_name);
+	}
 	if (!ndev) {
 		np_err(np, "%s doesn't exist, aborting\n", np->dev_name);
 		err = -ENODEV;
@@ -1159,6 +1164,8 @@ int netpoll_setup(struct netpoll *np)
 put:
 	dev_put(ndev);
 unlock:
+	if (net != &init_net)
+		put_net(net);
 	rtnl_unlock();
 	return err;
 }
-- 
1.7.7.6

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Patch net-next 2/2] netpoll: use the net namespace of current process instead of init_net
  2013-01-23  9:02 ` [Patch net-next 2/2] netpoll: use the net namespace of current process instead of init_net Cong Wang
@ 2013-01-26 10:00   ` Cong Wang
  2013-01-27  5:16     ` Eric W. Biederman
  0 siblings, 1 reply; 5+ messages in thread
From: Cong Wang @ 2013-01-26 10:00 UTC (permalink / raw)
  To: netdev; +Cc: Eric W. Biederman, David S. Miller

On Wed, 2013-01-23 at 17:02 +0800, Cong Wang wrote:
> From: Cong Wang <amwang@redhat.com>
> 
> This will allow us to setup netconsole in a different namespace
> rather than where init_net is.
> 

Hmm, I missed to put the netns in netpoll_cleanup()...

Will send v2.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Patch net-next 2/2] netpoll: use the net namespace of current process instead of init_net
  2013-01-26 10:00   ` Cong Wang
@ 2013-01-27  5:16     ` Eric W. Biederman
  2013-01-28  1:36       ` Cong Wang
  0 siblings, 1 reply; 5+ messages in thread
From: Eric W. Biederman @ 2013-01-27  5:16 UTC (permalink / raw)
  To: Cong Wang; +Cc: netdev, David S. Miller

Cong Wang <amwang@redhat.com> writes:

> On Wed, 2013-01-23 at 17:02 +0800, Cong Wang wrote:
>> From: Cong Wang <amwang@redhat.com>
>> 
>> This will allow us to setup netconsole in a different namespace
>> rather than where init_net is.
>> 
>
> Hmm, I missed to put the netns in netpoll_cleanup()...
>
> Will send v2.

Since you are working on it.  I forgot to mention that it doesn't
look you were working with nsproxy properly.  The code just felt
very different from every other nsproxy reference I have seen.

Looking more closely since you are looking at current you don't need
to test to see if nsproxy is NULL. You can just say.

-	if (np->dev_name)
-		ndev = __dev_get_by_name(&init_net, np->dev_name);
+	if (np->dev_name) {
+		net = current->nsproxy->net_ns;
+		ndev = __dev_get_by_name(net, np->dev_name);
+	}

task_nsproxy and get_net are needed when you are accessing another
tasks nsproxy.  Since you are just accessing current the code
can be much simpler.

Which also means that you shouldn't need to get a reference to
the network namespace or put the reference to the network namespace.
Although you do need to handle things like network device hotplug
in case the network device (or equivalently for most purposes) the
network namespace goes away.

Eric

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Patch net-next 2/2] netpoll: use the net namespace of current process instead of init_net
  2013-01-27  5:16     ` Eric W. Biederman
@ 2013-01-28  1:36       ` Cong Wang
  0 siblings, 0 replies; 5+ messages in thread
From: Cong Wang @ 2013-01-28  1:36 UTC (permalink / raw)
  To: Eric W. Biederman; +Cc: netdev, David S. Miller

On Sat, 2013-01-26 at 21:16 -0800, Eric W. Biederman wrote:
> Cong Wang <amwang@redhat.com> writes:
> 
> > On Wed, 2013-01-23 at 17:02 +0800, Cong Wang wrote:
> >> From: Cong Wang <amwang@redhat.com>
> >> 
> >> This will allow us to setup netconsole in a different namespace
> >> rather than where init_net is.
> >> 
> >
> > Hmm, I missed to put the netns in netpoll_cleanup()...
> >
> > Will send v2.
> 
> Since you are working on it.  I forgot to mention that it doesn't
> look you were working with nsproxy properly.  The code just felt
> very different from every other nsproxy reference I have seen.
> 
> Looking more closely since you are looking at current you don't need
> to test to see if nsproxy is NULL. You can just say.
> 
> -	if (np->dev_name)
> -		ndev = __dev_get_by_name(&init_net, np->dev_name);
> +	if (np->dev_name) {
> +		net = current->nsproxy->net_ns;
> +		ndev = __dev_get_by_name(net, np->dev_name);
> +	}
> 
> task_nsproxy and get_net are needed when you are accessing another
> tasks nsproxy.  Since you are just accessing current the code
> can be much simpler.

Ok.

> 
> Which also means that you shouldn't need to get a reference to
> the network namespace or put the reference to the network namespace.
> Although you do need to handle things like network device hotplug
> in case the network device (or equivalently for most purposes) the
> network namespace goes away.

I believe we already handle NETDEV_UNREGISTER.

Thanks!

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-01-28  1:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-23  9:02 [Patch net-next 1/2] netpoll: use ipv6_addr_equal() to compare ipv6 addr Cong Wang
2013-01-23  9:02 ` [Patch net-next 2/2] netpoll: use the net namespace of current process instead of init_net Cong Wang
2013-01-26 10:00   ` Cong Wang
2013-01-27  5:16     ` Eric W. Biederman
2013-01-28  1:36       ` Cong Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).