[net-2.6.26 patch 2/6][NETNS][IPV6] udp - make proc handle the network namespace

Previous thread: [net-2.6.26 patch 1/6][NETNS][IPV6] mcast - fix compilation warning when procfs is not compiled in by Daniel Lezcano on Thursday, March 13, 2008 - 4:46 am. (1 message)

Next thread: [net-2.6.26 patch 3/6][NETNS][IPV6] tcp - assign the netns for timewait sockets by Daniel Lezcano on Thursday, March 13, 2008 - 4:46 am. (1 message)
From: Daniel Lezcano
Date: Thursday, March 13, 2008 - 4:46 am

This patch makes the common udp proc functions to take care
of which socket they should show taking into account the namespace
it belongs.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
---
 include/net/udp.h |    1 +
 net/ipv4/udp.c    |   32 ++++++++++++++++++++++++++++----
 2 files changed, 29 insertions(+), 4 deletions(-)

Index: net-2.6.26/net/ipv4/udp.c
===================================================================
--- net-2.6.26.orig/net/ipv4/udp.c
+++ net-2.6.26/net/ipv4/udp.c
@@ -1512,10 +1512,13 @@ static struct sock *udp_get_first(struct
 {
 	struct sock *sk;
 	struct udp_iter_state *state = seq->private;
+	struct net *net = state->net;
 
 	for (state->bucket = 0; state->bucket < UDP_HTABLE_SIZE; ++state->bucket) {
 		struct hlist_node *node;
 		sk_for_each(sk, node, state->hashtable + state->bucket) {
+			if (sk->sk_net != net)
+				continue;
 			if (sk->sk_family == state->family)
 				goto found;
 		}
@@ -1528,12 +1531,13 @@ found:
 static struct sock *udp_get_next(struct seq_file *seq, struct sock *sk)
 {
 	struct udp_iter_state *state = seq->private;
+	struct net *net = state->net;
 
 	do {
 		sk = sk_next(sk);
 try_again:
 		;
-	} while (sk && sk->sk_family != state->family);
+	} while (sk && sk->sk_net != net && sk->sk_family != state->family);
 
 	if (!sk && ++state->bucket < UDP_HTABLE_SIZE) {
 		sk = sk_head(state->hashtable + state->bucket);
@@ -1582,31 +1586,51 @@ static int udp_seq_open(struct inode *in
 {
 	struct udp_seq_afinfo *afinfo = PDE(inode)->data;
 	struct seq_file *seq;
+	struct net *net;
 	int rc = -ENOMEM;
 	struct udp_iter_state *s = kzalloc(sizeof(*s), GFP_KERNEL);
 
 	if (!s)
 		goto out;
+
+	rc = -ENXIO;
+	net = get_proc_net(inode);
+	if (!net)
+		goto out_kfree;
+
 	s->family		= afinfo->family;
 	s->hashtable		= afinfo->hashtable;
 	s->seq_ops.start	= udp_seq_start;
 	s->seq_ops.next		= udp_seq_next;
 	s->seq_ops.show		= afinfo->seq_show;
 	s->seq_ops.stop		= udp_seq_stop;
+	s->net             ...
Previous thread: [net-2.6.26 patch 1/6][NETNS][IPV6] mcast - fix compilation warning when procfs is not compiled in by Daniel Lezcano on Thursday, March 13, 2008 - 4:46 am. (1 message)

Next thread: [net-2.6.26 patch 3/6][NETNS][IPV6] tcp - assign the netns for timewait sockets by Daniel Lezcano on Thursday, March 13, 2008 - 4:46 am. (1 message)