Skip to contentSkip to conversation

netpoll: use ipv6_addr_equal() to compare ipv6 addr

PATCH Superseded Cong Wang 2 participants 5 messages Jan 23, 2013 – Jan 28, 2013

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Cong Wang

author
#0 lore raw

PATCH 1/2 netpoll: use ipv6_addr_equal() to compare ipv6 addr

From: Cong Wang <[email protected]>

ipv6_addr_equal() is faster.

Cc David S. Miller <[email protected]>
---
 net/core/netpoll.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
net/core/netpoll.c +3 -3
index e2f79a1..a6f39b6 100644
@@ -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;
Signature · 1 line
1.7.7.6
author
#1 lore raw

PATCH 2/2 netpoll: use the net namespace of current process instead of init_net

From: Cong Wang <[email protected]>

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

Cc Eric W. Biederman <[email protected]>
Cc David S. Miller <[email protected]>
---
 net/core/netpoll.c |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)
net/core/netpoll.c +9 -2
index a6f39b6..c3b2589 100644
@@ -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;
 }
Signature · 1 line
1.7.7.6
author
#2 lore raw

Re: [Patch net-next 2/2] netpoll: use the net namespace of current process instead of init_net

Quoted 5 lines · Cong Wang

From: Cong Wang <[email protected]>

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.

#3 lore raw

Re: [Patch net-next 2/2] netpoll: use the net namespace of current process instead of init_net

Quoted 10 lines · Cong Wang
Quoted 5 lines · Cong Wang

From: Cong Wang <[email protected]>

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

author
#4 lore raw

Re: [Patch net-next 2/2] netpoll: use the net namespace of current process instead of init_net

Quoted 27 lines · Eric W. Biederman
Quoted 10 lines · Cong Wang
Quoted 5 lines · Cong Wang

From: Cong Wang <[email protected]>

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.

net/core/netpoll.c +4 -2
-	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);
+	}
Quoted 3 lines

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.

Quoted 6 lines

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!