linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* lost socket
@ 2003-08-27 21:27 Ricky Beam
  2003-08-27 23:58 ` /proc/net/* read drops data (was: lost socket) Ricky Beam
  0 siblings, 1 reply; 8+ messages in thread
From: Ricky Beam @ 2003-08-27 21:27 UTC (permalink / raw)
  To: Linux Kernel Mail List

It would appear the kernel is not properly reporting all the active sockets.
I noticed this in 2.5.70 while checking netflow collection... udp port 9800
is bound and actively receiving traffic, however, nothing reports it's
existance.  2.6.0-test4 still has this bug.

This smells like a simple "off by one" bug, but I've been too busy to go
look at the code.

--Ricky



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

* /proc/net/* read drops data (was: lost socket)
  2003-08-27 21:27 lost socket Ricky Beam
@ 2003-08-27 23:58 ` Ricky Beam
  2003-08-28  0:34   ` /proc/net/* read drops data YOSHIFUJI Hideaki / 吉藤英明
  2003-09-03  7:07   ` YOSHIFUJI Hideaki / 吉藤英明
  0 siblings, 2 replies; 8+ messages in thread
From: Ricky Beam @ 2003-08-27 23:58 UTC (permalink / raw)
  To: Linux Kernel Mail List

On Wed, 27 Aug 2003, Ricky Beam wrote:
>This smells like a simple "off by one" bug, but I've been too busy to go
>look at the code.

Ah hah!  it's a block size problem... netstat reads 1024 at a time.

Using dd...

[root:pts/5{9}]gir:~/[7:55pm]:dd if=/proc/net/udp bs=1024 | wc
2+1 records in
2+1 records out
     18     216    2304
[root:pts/5{9}]gir:~/[7:56pm]:dd if=/proc/net/udp bs=2048 | wc
1+1 records in
1+1 records out
     19     228    2432
[root:pts/5{9}]gir:~/[7:56pm]:dd if=/proc/net/udp bs=4096 | wc
0+1 records in
0+1 records out
     20     240    2560
[root:pts/5{9}]gir:~/[7:56pm]:dd if=/proc/net/udp bs=8192 | wc
0+1 records in
0+1 records out
     20     240    2560
[root:pts/5{9}]gir:~/[7:56pm]:dd if=/proc/net/udp bs=32768 | wc
0+1 records in
0+1 records out
     20     240    2560
[root:pts/5{9}]gir:~/[7:56pm]:dd if=/proc/net/udp bs=1 | wc
2432+0 records in
2432+0 records out
     19     228    2432

--Ricky



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

* Re: /proc/net/* read drops data
  2003-08-27 23:58 ` /proc/net/* read drops data (was: lost socket) Ricky Beam
@ 2003-08-28  0:34   ` YOSHIFUJI Hideaki / 吉藤英明
  2003-09-03  7:07   ` YOSHIFUJI Hideaki / 吉藤英明
  1 sibling, 0 replies; 8+ messages in thread
From: YOSHIFUJI Hideaki / 吉藤英明 @ 2003-08-28  0:34 UTC (permalink / raw)
  To: jfbeam; +Cc: linux-kernel, netdev

In article <Pine.GSO.4.33.0308271935550.7750-100000@sweetums.bluetronic.net> (at Wed, 27 Aug 2003 19:58:17 -0400 (EDT)), Ricky Beam <jfbeam@bluetronic.net> says:

> On Wed, 27 Aug 2003, Ricky Beam wrote:
> >This smells like a simple "off by one" bug, but I've been too busy to go
> >look at the code.
> 
> Ah hah!  it's a block size problem... netstat reads 1024 at a time.
> 
> Using dd...
> 
> [root:pts/5{9}]gir:~/[7:55pm]:dd if=/proc/net/udp bs=1024 | wc
> 2+1 records in
> 2+1 records out
>      18     216    2304

Good idea. I'll chase this bug.

--yoshfuji

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

* Re: /proc/net/* read drops data
  2003-08-27 23:58 ` /proc/net/* read drops data (was: lost socket) Ricky Beam
  2003-08-28  0:34   ` /proc/net/* read drops data YOSHIFUJI Hideaki / 吉藤英明
@ 2003-09-03  7:07   ` YOSHIFUJI Hideaki / 吉藤英明
  2003-09-04  7:46     ` David S. Miller
  1 sibling, 1 reply; 8+ messages in thread
From: YOSHIFUJI Hideaki / 吉藤英明 @ 2003-09-03  7:07 UTC (permalink / raw)
  To: Ricky Beam, jfbeam; +Cc: linux-kernel, netdev, yoshfuji, davem

Hello.

In article <Pine.GSO.4.33.0308271935550.7750-100000@sweetums.bluetronic.net> (at Wed, 27 Aug 2003 19:58:17 -0400 (EDT)), Ricky Beam <jfbeam@bluetronic.net> says:

> On Wed, 27 Aug 2003, Ricky Beam wrote:
> >This smells like a simple "off by one" bug, but I've been too busy to go
> >look at the code.
> 
> Ah hah!  it's a block size problem... netstat reads 1024 at a time.
> 
> Using dd...
> 
> [root:pts/5{9}]gir:~/[7:55pm]:dd if=/proc/net/udp bs=1024 | wc
> 2+1 records in
> 2+1 records out
>      18     216    2304
> [root:pts/5{9}]gir:~/[7:56pm]:dd if=/proc/net/udp bs=2048 | wc
> 1+1 records in
> 1+1 records out
>      19     228    2432
:

Please try this patch.

D: Fixing a bug that reading /proc/net/{udp,udp6} may drop some data

Index: linux-2.6/net/ipv4/udp.c
===================================================================
RCS file: /home/cvs/linux-2.5/net/ipv4/udp.c,v
retrieving revision 1.38
diff -u -r1.38 udp.c
--- linux-2.6/net/ipv4/udp.c	14 Aug 2003 06:00:04 -0000	1.38
+++ linux-2.6/net/ipv4/udp.c	3 Sep 2003 05:30:52 -0000
@@ -1349,64 +1349,65 @@
 /* ------------------------------------------------------------------------ */
 #ifdef CONFIG_PROC_FS
 
-static __inline__ struct sock *udp_get_bucket(struct seq_file *seq, loff_t *pos)
+static struct sock *udp_get_first(struct seq_file *seq)
 {
-	int i;
 	struct sock *sk;
-	struct hlist_node *node;
-	loff_t l = *pos;
 	struct udp_iter_state *state = seq->private;
 
-	for (; state->bucket < UDP_HTABLE_SIZE; ++state->bucket) {
-		i = 0;
+	for (state->bucket = 0; state->bucket < UDP_HTABLE_SIZE; ++state->bucket) {
+		struct hlist_node *node;
 		sk_for_each(sk, node, &udp_hash[state->bucket]) {
-			if (sk->sk_family != state->family) {
-				++i;
-				continue;
-			}
-			if (l--) {
-				++i;
-				continue;
-			}
-			*pos = i;
-			goto out;
+			if (sk->sk_family == state->family)
+				goto found;
 		}
 	}
 	sk = NULL;
-out:
+found:
 	return sk;
 }
 
+static struct sock *udp_get_next(struct seq_file *seq, struct sock *sk)
+{
+	struct udp_iter_state *state = seq->private;
+
+	do {
+		sk = sk_next(sk);
+try_again:
+		;
+	} while (sk && sk->sk_family != state->family);
+
+	if (!sk && ++state->bucket < UDP_HTABLE_SIZE) {
+		sk = sk_head(&udp_hash[state->bucket]);
+		goto try_again;
+	}
+	return sk;
+}
+
+static struct sock *udp_get_idx(struct seq_file *seq, loff_t pos)
+{
+	struct sock *sk = udp_get_first(seq);
+
+	if (sk)
+		while(pos && (sk = udp_get_next(seq, sk)) != NULL)
+			--pos;
+	return pos ? NULL : sk;
+}
+
 static void *udp_seq_start(struct seq_file *seq, loff_t *pos)
 {
 	read_lock(&udp_hash_lock);
-	return *pos ? udp_get_bucket(seq, pos) : (void *)1;
+	return *pos ? udp_get_idx(seq, *pos-1) : (void *)1;
 }
 
 static void *udp_seq_next(struct seq_file *seq, void *v, loff_t *pos)
 {
 	struct sock *sk;
-	struct hlist_node *node;
-	struct udp_iter_state *state;
-
-	if (v == (void *)1) {
-		sk = udp_get_bucket(seq, pos);
-		goto out;
-	}
 
-	state = seq->private;
+	if (v == (void *)1)
+		sk = udp_get_idx(seq, 0);
+	else
+		sk = udp_get_next(seq, v);
 
-	sk = v;
-	sk_for_each_continue(sk, node)
-		if (sk->sk_family == state->family)
-			goto out;
-
-	if (++state->bucket >= UDP_HTABLE_SIZE) 
-		goto out;
-
-	*pos = 0;
-	sk = udp_get_bucket(seq, pos);
-out:
 	++*pos;
 	return sk;
 }

-- 
Hideaki YOSHIFUJI @ USAGI Project <yoshfuji@linux-ipv6.org>
GPG FP: 9022 65EB 1ECF 3AD1 0BDF  80D8 4807 F894 E062 0EEA

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

* Re: /proc/net/* read drops data
  2003-09-03  7:07   ` YOSHIFUJI Hideaki / 吉藤英明
@ 2003-09-04  7:46     ` David S. Miller
  2003-09-04 16:21       ` Ricky Beam
  2003-09-04 16:25       ` Ricky Beam
  0 siblings, 2 replies; 8+ messages in thread
From: David S. Miller @ 2003-09-04  7:46 UTC (permalink / raw)
  To: YOSHIFUJI Hideaki / _$B5HF#1QL@; +Cc: jfbeam, linux-kernel, netdev, yoshfuji

On Wed, 03 Sep 2003 16:07:33 +0900 (JST)
YOSHIFUJI Hideaki / _$B5HF#1QL@ <yoshfuji@linux-ipv6.org> wrote:

> D: Fixing a bug that reading /proc/net/{udp,udp6} may drop some data

This fix looks good to me.  Applied.

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

* Re: /proc/net/* read drops data
  2003-09-04  7:46     ` David S. Miller
@ 2003-09-04 16:21       ` Ricky Beam
  2003-09-04 16:25       ` Ricky Beam
  1 sibling, 0 replies; 8+ messages in thread
From: Ricky Beam @ 2003-09-04 16:21 UTC (permalink / raw)
  To: David S. Miller; +Cc: YOSHIFUJI Hideaki / _$B5HF#1QL@, linux-kernel, netdev

On Thu, 4 Sep 2003, David S. Miller wrote:
>> D: Fixing a bug that reading /proc/net/{udp,udp6} may drop some data
>
>This fix looks good to me.  Applied.

That might fix udp, but that's not the only one to be fixed.  I'll compile
a list. (tcp for sure.)

--Ricky



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

* Re: /proc/net/* read drops data
  2003-09-04  7:46     ` David S. Miller
  2003-09-04 16:21       ` Ricky Beam
@ 2003-09-04 16:25       ` Ricky Beam
  2003-09-04 17:13         ` YOSHIFUJI Hideaki / 吉藤英明
  1 sibling, 1 reply; 8+ messages in thread
From: Ricky Beam @ 2003-09-04 16:25 UTC (permalink / raw)
  To: David S. Miller; +Cc: YOSHIFUJI Hideaki / _$B5HF#1QL@, linux-kernel, netdev

On Thu, 4 Sep 2003, David S. Miller wrote:
>> D: Fixing a bug that reading /proc/net/{udp,udp6} may drop some data
>
>This fix looks good to me.  Applied.

The list:
(file)			(bs=1)	(bs=10000)
/proc/net/igmp		122     191
/proc/net/route		128     384
/proc/net/rt_acct	0	4096
/proc/net/rt_cache	384     512
/proc/net/tcp		1800    1950
/proc/net/udp		1024    1152

(I don't have ipv6 enabled)

--Ricky



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

* Re: /proc/net/* read drops data
  2003-09-04 16:25       ` Ricky Beam
@ 2003-09-04 17:13         ` YOSHIFUJI Hideaki / 吉藤英明
  0 siblings, 0 replies; 8+ messages in thread
From: YOSHIFUJI Hideaki / 吉藤英明 @ 2003-09-04 17:13 UTC (permalink / raw)
  To: jfbeam; +Cc: davem, linux-kernel, netdev, yoshfuji

In article <Pine.GSO.4.33.0309041223430.13584-100000@sweetums.bluetronic.net> (at Thu, 4 Sep 2003 12:25:16 -0400 (EDT)), Ricky Beam <jfbeam@bluetronic.net> says:

> The list:
> (file)			(bs=1)	(bs=10000)
> /proc/net/igmp		122     191
> /proc/net/route		128     384
> /proc/net/rt_acct	0	4096
> /proc/net/rt_cache	384     512
> /proc/net/tcp		1800    1950
> /proc/net/udp		1024    1152

Okay, I'll seek the code.
--yoshfuji

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

end of thread, other threads:[~2003-09-04 17:12 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-08-27 21:27 lost socket Ricky Beam
2003-08-27 23:58 ` /proc/net/* read drops data (was: lost socket) Ricky Beam
2003-08-28  0:34   ` /proc/net/* read drops data YOSHIFUJI Hideaki / 吉藤英明
2003-09-03  7:07   ` YOSHIFUJI Hideaki / 吉藤英明
2003-09-04  7:46     ` David S. Miller
2003-09-04 16:21       ` Ricky Beam
2003-09-04 16:25       ` Ricky Beam
2003-09-04 17:13         ` YOSHIFUJI Hideaki / 吉藤英明

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).