[PATCH] Export accept queue len of a TCP listening socket via /proc/net/tcp{6}

Subsystems: networking [general], networking [tcp], the rest

STALE7384d

6 messages, 3 authors, 2006-06-27 · open the first message on its own page

[PATCH] Export accept queue len of a TCP listening socket via /proc/net/tcp{6}

From: Sridhar Samudrala <hidden>
Date: 2006-06-21 23:57:38

While debugging a TCP server hang issue, we noticed that currently there is 
no way for a user to find the acceptq backlog value for a TCP listen socket.

All the standard networking utilities that display socket info like netstat,
ss and /proc/net/tcp have 2 fields called rx_queue and tx_queue. I think these
fields do not mean much for listening sockets and they are always zero. So why
not use one of these fields(rx_queue) to export the accept queue len for listening
sockets?
The attached patch implements this, but it only works with /proc/net/tcp and
/proc/net/tcp6.

In order to support this with netstat/ss that use netlink mechanism to
get the socket info, i think we need to extend tcp_info to add this field.
Can this be done in a backward compatible way?

Anyway, i think it is useful to have this value exported via /proc.

Thanks
Sridhar


Signed-off-by: Sridhar Samudrala <redacted>
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 25ecc6e..4c6ef47 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -1726,7 +1726,8 @@ static void get_tcp4_sock(struct sock *s
 	sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X %02X %08X:%08X %02X:%08lX "
 			"%08X %5d %8d %lu %d %p %u %u %u %u %d",
 		i, src, srcp, dest, destp, sp->sk_state,
-		tp->write_seq - tp->snd_una, tp->rcv_nxt - tp->copied_seq,
+		tp->write_seq - tp->snd_una,
+		(sp->sk_state == TCP_LISTEN) ? sp->sk_ack_backlog : (tp->rcv_nxt - tp->copied_seq),
 		timer_active,
 		jiffies_to_clock_t(timer_expires - jiffies),
 		icsk->icsk_retransmits,
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
index a50eb30..b36d5b2 100644
--- a/net/ipv6/tcp_ipv6.c
+++ b/net/ipv6/tcp_ipv6.c
@@ -1469,7 +1469,8 @@ static void get_tcp6_sock(struct seq_fil
 		   dest->s6_addr32[0], dest->s6_addr32[1],
 		   dest->s6_addr32[2], dest->s6_addr32[3], destp,
 		   sp->sk_state, 
-		   tp->write_seq-tp->snd_una, tp->rcv_nxt-tp->copied_seq,
+		   tp->write_seq-tp->snd_una,
+		   (sp->sk_state == TCP_LISTEN) ? sp->sk_ack_backlog : (tp->rcv_nxt - tp->copied_seq),
 		   timer_active,
 		   jiffies_to_clock_t(timer_expires - jiffies),
 		   icsk->icsk_retransmits,

Re: [PATCH] Export accept queue len of a TCP listening socket via /proc/net/tcp{6}

From: Herbert Xu <herbert@gondor.apana.org.au>
Date: 2006-06-22 00:21:46

Sridhar Samudrala [off-list ref] wrote:
In order to support this with netstat/ss that use netlink mechanism to
get the socket info, i think we need to extend tcp_info to add this field.
Can this be done in a backward compatible way?
What about using the same fields (rqueue/wqueue) as you did for /proc?

Cheers,
-- 
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} [off-list ref]
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

Re: [PATCH] Export accept queue len of a TCP listening socket via /proc/net/tcp{6}

From: Sridhar Samudrala <hidden>
Date: 2006-06-22 00:36:02

On Thu, 2006-06-22 at 10:21 +1000, Herbert Xu wrote:
Sridhar Samudrala [off-list ref] wrote:
quoted
In order to support this with netstat/ss that use netlink mechanism to
get the socket info, i think we need to extend tcp_info to add this field.
Can this be done in a backward compatible way?
What about using the same fields (rqueue/wqueue) as you did for /proc?
I meant extending tcp_info structure to add new fields. I think the user
space also uses this structure.

Thanks
Sridhar

Re: [PATCH] Export accept queue len of a TCP listening socket via /proc/net/tcp{6}

From: Herbert Xu <herbert@gondor.apana.org.au>
Date: 2006-06-22 00:50:58

Sridhar Samudrala [off-list ref] wrote:
quoted
What about using the same fields (rqueue/wqueue) as you did for /proc?
I meant extending tcp_info structure to add new fields. I think the user
space also uses this structure.
What about putting it into inet_idiag_msg.idiag_[rw]queue instead?

Cheers,
-- 
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} [off-list ref]
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

Re: [PATCH] Export accept queue len of a TCP listening socket via rx_queue

From: Sridhar Samudrala <hidden>
Date: 2006-06-22 17:39:13

On Thu, 2006-06-22 at 10:50 +1000, Herbert Xu wrote:
Sridhar Samudrala [off-list ref] wrote:
quoted
quoted
What about using the same fields (rqueue/wqueue) as you did for /proc?
I meant extending tcp_info structure to add new fields. I think the user
space also uses this structure.
What about putting it into inet_idiag_msg.idiag_[rw]queue instead?
OK. I was under the mistaken assumption that [rw]queue fields are exported
via tcp_info. This makes it pretty simple to support netlink users also. 
Here is the updated patch.

Thanks
Sridhar

While debugging a TCP server hang issue, we noticed that currently there is 
no way for a user to get the acceptq backlog value for a TCP listen socket.

All the standard networking utilities that display socket info like netstat,
ss and /proc/net/tcp have 2 fields called rx_queue and tx_queue. These
fields do not mean much for listening sockets. This patch uses one of these
unused fields(rx_queue) to export the accept queue len for listening sockets.

Signed-off-by: Sridhar Samudrala <redacted>
diff --git a/net/ipv4/tcp_diag.c b/net/ipv4/tcp_diag.c
index c148c10..b56399c 100644
--- a/net/ipv4/tcp_diag.c
+++ b/net/ipv4/tcp_diag.c
@@ -26,7 +26,10 @@ static void tcp_diag_get_info(struct soc
 	const struct tcp_sock *tp = tcp_sk(sk);
 	struct tcp_info *info = _info;
 
-	r->idiag_rqueue = tp->rcv_nxt - tp->copied_seq;
+	if (sk->sk_state == TCP_LISTEN)
+		r->idiag_rqueue = sk->sk_ack_backlog;
+	else
+		r->idiag_rqueue = tp->rcv_nxt - tp->copied_seq;
 	r->idiag_wqueue = tp->write_seq - tp->snd_una;
 	if (info != NULL)
 		tcp_get_info(sk, info);
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 25ecc6e..4c6ef47 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -1726,7 +1726,8 @@ static void get_tcp4_sock(struct sock *s
 	sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X %02X %08X:%08X %02X:%08lX "
 			"%08X %5d %8d %lu %d %p %u %u %u %u %d",
 		i, src, srcp, dest, destp, sp->sk_state,
-		tp->write_seq - tp->snd_una, tp->rcv_nxt - tp->copied_seq,
+		tp->write_seq - tp->snd_una,
+		(sp->sk_state == TCP_LISTEN) ? sp->sk_ack_backlog : (tp->rcv_nxt - tp->copied_seq),
 		timer_active,
 		jiffies_to_clock_t(timer_expires - jiffies),
 		icsk->icsk_retransmits,
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
index a50eb30..b36d5b2 100644
--- a/net/ipv6/tcp_ipv6.c
+++ b/net/ipv6/tcp_ipv6.c
@@ -1469,7 +1469,8 @@ static void get_tcp6_sock(struct seq_fil
 		   dest->s6_addr32[0], dest->s6_addr32[1],
 		   dest->s6_addr32[2], dest->s6_addr32[3], destp,
 		   sp->sk_state, 
-		   tp->write_seq-tp->snd_una, tp->rcv_nxt-tp->copied_seq,
+		   tp->write_seq-tp->snd_una,
+		   (sp->sk_state == TCP_LISTEN) ? sp->sk_ack_backlog : (tp->rcv_nxt - tp->copied_seq),
 		   timer_active,
 		   jiffies_to_clock_t(timer_expires - jiffies),
 		   icsk->icsk_retransmits,

Re: [PATCH] Export accept queue len of a TCP listening socket via rx_queue

From: David Miller <davem@davemloft.net>
Date: 2006-06-27 20:29:16

From: Sridhar Samudrala <redacted>
Date: Thu, 22 Jun 2006 10:38:17 -0700
On Thu, 2006-06-22 at 10:50 +1000, Herbert Xu wrote:
quoted
Sridhar Samudrala [off-list ref] wrote:
quoted
quoted
What about using the same fields (rqueue/wqueue) as you did for /proc?
I meant extending tcp_info structure to add new fields. I think the user
space also uses this structure.
What about putting it into inet_idiag_msg.idiag_[rw]queue instead?
OK. I was under the mistaken assumption that [rw]queue fields are exported
via tcp_info. This makes it pretty simple to support netlink users also. 
Here is the updated patch.
This looks fine.  Applied, thanks a lot Sridhar.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help