netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] common code for generating tcp_info
@ 2004-06-04 22:37 Stephen Hemminger
  2004-06-05  3:57 ` David S. Miller
  2004-06-07 14:48 ` [PATCH] common code for generating tcp_info Joe Perches
  0 siblings, 2 replies; 6+ messages in thread
From: Stephen Hemminger @ 2004-06-04 22:37 UTC (permalink / raw)
  To: David S. Miller; +Cc: netdev

There are two places tcp_diag (netlink) and getsockopt, both with almost
the same code to generate tcp_info from the current socket state.

Patch agains 2.6.7-rc2

Signed-off-by: Stephen Hemminger <shemminger@osdl.org>


diff -Nru a/net/ipv4/tcp.c b/net/ipv4/tcp.c
--- a/net/ipv4/tcp.c	2004-06-04 15:35:55 -07:00
+++ b/net/ipv4/tcp.c	2004-06-04 15:35:55 -07:00
@@ -2498,56 +2498,11 @@
 		break;
 	case TCP_INFO: {
 		struct tcp_info info;
-		u32 now = tcp_time_stamp;
 
 		if (get_user(len, optlen))
 			return -EFAULT;
-		info.tcpi_state = sk->sk_state;
-		info.tcpi_ca_state = tp->ca_state;
-		info.tcpi_retransmits = tp->retransmits;
-		info.tcpi_probes = tp->probes_out;
-		info.tcpi_backoff = tp->backoff;
-		info.tcpi_options = 0;
-		if (tp->tstamp_ok)
-			info.tcpi_options |= TCPI_OPT_TIMESTAMPS;
-		if (tp->sack_ok)
-			info.tcpi_options |= TCPI_OPT_SACK;
-		if (tp->wscale_ok) {
-			info.tcpi_options |= TCPI_OPT_WSCALE;
-			info.tcpi_snd_wscale = tp->snd_wscale;
-			info.tcpi_rcv_wscale = tp->rcv_wscale;
-		} else {
-			info.tcpi_snd_wscale = 0;
-			info.tcpi_rcv_wscale = 0;
-		}
-		if (tp->ecn_flags & TCP_ECN_OK)
-			info.tcpi_options |= TCPI_OPT_ECN;
 
-		info.tcpi_rto = (1000000 * tp->rto) / HZ;
-		info.tcpi_ato = (1000000 * tp->ack.ato) / HZ;
-		info.tcpi_snd_mss = tp->mss_cache_std;
-		info.tcpi_rcv_mss = tp->ack.rcv_mss;
-
-		info.tcpi_unacked = tp->packets_out;
-		info.tcpi_sacked = tp->sacked_out;
-		info.tcpi_lost = tp->lost_out;
-		info.tcpi_retrans = tp->retrans_out;
-		info.tcpi_fackets = tp->fackets_out;
-
-		info.tcpi_last_data_sent = ((now - tp->lsndtime) * 1000) / HZ;
-		info.tcpi_last_ack_sent = 0;
-		info.tcpi_last_data_recv = ((now -
-					     tp->ack.lrcvtime) * 1000) / HZ;
-		info.tcpi_last_ack_recv = ((now - tp->rcv_tstamp) * 1000) / HZ;
-
-		info.tcpi_pmtu = tp->pmtu_cookie;
-		info.tcpi_rcv_ssthresh = tp->rcv_ssthresh;
-		info.tcpi_rtt = ((1000000 * tp->srtt) / HZ) >> 3;
-		info.tcpi_rttvar = ((1000000 * tp->mdev) / HZ) >> 2;
-		info.tcpi_snd_ssthresh = tp->snd_ssthresh;
-		info.tcpi_snd_cwnd = tp->snd_cwnd;
-		info.tcpi_advmss = tp->advmss;
-		info.tcpi_reordering = tp->reordering;
+		tcp_get_info(sk, &info);
 
 		len = min_t(unsigned int, len, sizeof(info));
 		if (put_user(len, optlen))
diff -Nru a/net/ipv4/tcp_diag.c b/net/ipv4/tcp_diag.c
--- a/net/ipv4/tcp_diag.c	2004-06-04 15:35:55 -07:00
+++ b/net/ipv4/tcp_diag.c	2004-06-04 15:35:55 -07:00
@@ -41,6 +41,58 @@
    rta->rta_len = rtalen;                   \
    RTA_DATA(rta); })
 
+/* Return information about state of tcp endpoint in API format. */
+void tcp_get_info(struct sock *sk, struct tcp_info *info)
+{
+	struct tcp_opt *tp = tcp_sk(sk);
+	u32 now = tcp_time_stamp;
+
+	memset(info, 0, sizeof(*info));
+
+	info->tcpi_state = sk->sk_state;
+	info->tcpi_ca_state = tp->ca_state;
+	info->tcpi_retransmits = tp->retransmits;
+	info->tcpi_probes = tp->probes_out;
+	info->tcpi_backoff = tp->backoff;
+
+	if (tp->tstamp_ok)
+		info->tcpi_options |= TCPI_OPT_TIMESTAMPS;
+	if (tp->sack_ok)
+		info->tcpi_options |= TCPI_OPT_SACK;
+	if (tp->wscale_ok) {
+		info->tcpi_options |= TCPI_OPT_WSCALE;
+		info->tcpi_snd_wscale = tp->snd_wscale;
+		info->tcpi_rcv_wscale = tp->rcv_wscale;
+	} 
+
+	if (tp->ecn_flags&TCP_ECN_OK)
+		info->tcpi_options |= TCPI_OPT_ECN;
+
+	info->tcpi_rto = (1000000*tp->rto)/HZ;
+	info->tcpi_ato = (1000000*tp->ack.ato)/HZ;
+	info->tcpi_snd_mss = tp->mss_cache;
+	info->tcpi_rcv_mss = tp->ack.rcv_mss;
+
+	info->tcpi_unacked = tp->packets_out;
+	info->tcpi_sacked = tp->sacked_out;
+	info->tcpi_lost = tp->lost_out;
+	info->tcpi_retrans = tp->retrans_out;
+	info->tcpi_fackets = tp->fackets_out;
+
+	info->tcpi_last_data_sent = ((now - tp->lsndtime)*1000)/HZ;
+	info->tcpi_last_data_recv = ((now - tp->ack.lrcvtime)*1000)/HZ;
+	info->tcpi_last_ack_recv = ((now - tp->rcv_tstamp)*1000)/HZ;
+
+	info->tcpi_pmtu = tp->pmtu_cookie;
+	info->tcpi_rcv_ssthresh = tp->rcv_ssthresh;
+	info->tcpi_rtt = ((1000000*tp->srtt)/HZ)>>3;
+	info->tcpi_rttvar = ((1000000*tp->mdev)/HZ)>>2;
+	info->tcpi_snd_ssthresh = tp->snd_ssthresh;
+	info->tcpi_snd_cwnd = tp->snd_cwnd;
+	info->tcpi_advmss = tp->advmss;
+	info->tcpi_reordering = tp->reordering;
+}
+
 static int tcpdiag_fill(struct sk_buff *skb, struct sock *sk,
 			int ext, u32 pid, u32 seq)
 {
@@ -150,55 +202,8 @@
 		minfo->tcpdiag_tmem = atomic_read(&sk->sk_wmem_alloc);
 	}
 
-	if (info) {
-		u32 now = tcp_time_stamp;
-
-		info->tcpi_state = sk->sk_state;
-		info->tcpi_ca_state = tp->ca_state;
-		info->tcpi_retransmits = tp->retransmits;
-		info->tcpi_probes = tp->probes_out;
-		info->tcpi_backoff = tp->backoff;
-		info->tcpi_options = 0;
-		if (tp->tstamp_ok)
-			info->tcpi_options |= TCPI_OPT_TIMESTAMPS;
-		if (tp->sack_ok)
-			info->tcpi_options |= TCPI_OPT_SACK;
-		if (tp->wscale_ok) {
-			info->tcpi_options |= TCPI_OPT_WSCALE;
-			info->tcpi_snd_wscale = tp->snd_wscale;
-			info->tcpi_rcv_wscale = tp->rcv_wscale;
-		} else {
-			info->tcpi_snd_wscale = 0;
-			info->tcpi_rcv_wscale = 0;
-		}
-		if (tp->ecn_flags&TCP_ECN_OK)
-			info->tcpi_options |= TCPI_OPT_ECN;
-
-		info->tcpi_rto = (1000000*tp->rto)/HZ;
-		info->tcpi_ato = (1000000*tp->ack.ato)/HZ;
-		info->tcpi_snd_mss = tp->mss_cache;
-		info->tcpi_rcv_mss = tp->ack.rcv_mss;
-
-		info->tcpi_unacked = tp->packets_out;
-		info->tcpi_sacked = tp->sacked_out;
-		info->tcpi_lost = tp->lost_out;
-		info->tcpi_retrans = tp->retrans_out;
-		info->tcpi_fackets = tp->fackets_out;
-
-		info->tcpi_last_data_sent = ((now - tp->lsndtime)*1000)/HZ;
-		info->tcpi_last_ack_sent = 0;
-		info->tcpi_last_data_recv = ((now - tp->ack.lrcvtime)*1000)/HZ;
-		info->tcpi_last_ack_recv = ((now - tp->rcv_tstamp)*1000)/HZ;
-
-		info->tcpi_pmtu = tp->pmtu_cookie;
-		info->tcpi_rcv_ssthresh = tp->rcv_ssthresh;
-		info->tcpi_rtt = ((1000000*tp->srtt)/HZ)>>3;
-		info->tcpi_rttvar = ((1000000*tp->mdev)/HZ)>>2;
-		info->tcpi_snd_ssthresh = tp->snd_ssthresh;
-		info->tcpi_snd_cwnd = tp->snd_cwnd;
-		info->tcpi_advmss = tp->advmss;
-		info->tcpi_reordering = tp->reordering;
-	}
+	if (info) 
+		tcp_get_info(sk, info);
 
 	if (vinfo) {
 		vinfo->tcpv_enabled = tp->vegas.doing_vegas_now;

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

* Re: [PATCH] common code for generating tcp_info
  2004-06-04 22:37 [PATCH] common code for generating tcp_info Stephen Hemminger
@ 2004-06-05  3:57 ` David S. Miller
  2004-06-07 17:07   ` [PATCH] add receive DRS info Stephen Hemminger
  2004-06-07 14:48 ` [PATCH] common code for generating tcp_info Joe Perches
  1 sibling, 1 reply; 6+ messages in thread
From: David S. Miller @ 2004-06-05  3:57 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev

On Fri, 4 Jun 2004 15:37:49 -0700
Stephen Hemminger <shemminger@osdl.org> wrote:

> There are two places tcp_diag (netlink) and getsockopt, both with almost
> the same code to generate tcp_info from the current socket state.

Works for me, applied.

Should maybe try to move that tcp_info off the stack at some
point.

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

* Re: [PATCH] common code for generating tcp_info
  2004-06-04 22:37 [PATCH] common code for generating tcp_info Stephen Hemminger
  2004-06-05  3:57 ` David S. Miller
@ 2004-06-07 14:48 ` Joe Perches
  2004-06-07 16:16   ` Stephen Hemminger
  1 sibling, 1 reply; 6+ messages in thread
From: Joe Perches @ 2004-06-07 14:48 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: David S Miller, netdev

On Fri, 2004-06-04 at 15:37, Stephen Hemminger wrote:

> diff -Nru a/net/ipv4/tcp_diag.c b/net/ipv4/tcp_diag.c
> --- a/net/ipv4/tcp_diag.c	2004-06-04 15:35:55 -07:00
> +++ b/net/ipv4/tcp_diag.c	2004-06-04 15:35:55 -07:00
> +void tcp_get_info(struct sock *sk, struct tcp_info *info)

What is the appropriate text to update tcp.h?

	/* The syn_wait_lock is necessary only to avoid tcp_get_info having
	 * to grab the main lock sock while browsing the listening hash
	 * (otherwise it's deadlock prone).
	 * This lock is acquired in read mode only from tcp_get_info() and
	 * it's acquired in write mode _only_ from code that is actively
	 * changing the syn_wait_queue. All readers that are holding
	 * the master sock lock don't need to grab this lock in read mode
	 * too as the syn_wait_queue writes are always protected from
	 * the main sock lock.
	 */

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

* Re: [PATCH] common code for generating tcp_info
  2004-06-07 14:48 ` [PATCH] common code for generating tcp_info Joe Perches
@ 2004-06-07 16:16   ` Stephen Hemminger
  0 siblings, 0 replies; 6+ messages in thread
From: Stephen Hemminger @ 2004-06-07 16:16 UTC (permalink / raw)
  To: Joe Perches, David S Miller; +Cc: netdev

The comment was out of date, keep moving, nothing to see here...

diff -Nru a/include/linux/tcp.h b/include/linux/tcp.h
--- a/include/linux/tcp.h	2004-06-07 09:15:59 -07:00
+++ b/include/linux/tcp.h	2004-06-07 09:15:59 -07:00
@@ -351,11 +351,11 @@
 	__u8	urg_mode;	/* In urgent mode		*/
 	__u32	snd_up;		/* Urgent pointer		*/
 
-	/* The syn_wait_lock is necessary only to avoid tcp_get_info having
+	/* The syn_wait_lock is necessary only to avoid proc interface having
 	 * to grab the main lock sock while browsing the listening hash
 	 * (otherwise it's deadlock prone).
-	 * This lock is acquired in read mode only from tcp_get_info() and
-	 * it's acquired in write mode _only_ from code that is actively
+	 * This lock is acquired in read mode only from listening_get_next()
+	 * and it's acquired in write mode _only_ from code that is actively
 	 * changing the syn_wait_queue. All readers that are holding
 	 * the master sock lock don't need to grab this lock in read mode
 	 * too as the syn_wait_queue writes are always protected from

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

* [PATCH] add receive DRS info
  2004-06-05  3:57 ` David S. Miller
@ 2004-06-07 17:07   ` Stephen Hemminger
  2004-06-07 22:27     ` David S. Miller
  0 siblings, 1 reply; 6+ messages in thread
From: Stephen Hemminger @ 2004-06-07 17:07 UTC (permalink / raw)
  To: David S. Miller; +Cc: netdev

Add receiver feedback information to the tcp_info structure to allow
looking at receive dynamic right sizing with 'ss' command.

This increases the size of the structure, but since both getsockopt() and netlink
interface pass length in request; it retains compatibility with older versions.

diff -Nru a/include/linux/tcp.h b/include/linux/tcp.h
--- a/include/linux/tcp.h	2004-06-07 10:07:25 -07:00
+++ b/include/linux/tcp.h	2004-06-07 10:07:25 -07:00
@@ -183,6 +183,9 @@
 	__u32	tcpi_snd_cwnd;
 	__u32	tcpi_advmss;
 	__u32	tcpi_reordering;
+
+	__u32	tcpi_rcv_rtt;
+	__u32	tcpi_rcv_space;
 };
 
 #ifdef __KERNEL__
diff -Nru a/net/ipv4/tcp_diag.c b/net/ipv4/tcp_diag.c
--- a/net/ipv4/tcp_diag.c	2004-06-07 10:07:25 -07:00
+++ b/net/ipv4/tcp_diag.c	2004-06-07 10:07:25 -07:00
@@ -91,6 +91,9 @@
 	info->tcpi_snd_cwnd = tp->snd_cwnd;
 	info->tcpi_advmss = tp->advmss;
 	info->tcpi_reordering = tp->reordering;
+
+	info->tcpi_rcv_rtt = ((1000000*tp->rcv_rtt_est.rtt)/HZ)>>3;
+	info->tcpi_rcv_space = tp->rcvq_space.space;
 }
 
 static int tcpdiag_fill(struct sk_buff *skb, struct sock *sk,

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

* Re: [PATCH] add receive DRS info
  2004-06-07 17:07   ` [PATCH] add receive DRS info Stephen Hemminger
@ 2004-06-07 22:27     ` David S. Miller
  0 siblings, 0 replies; 6+ messages in thread
From: David S. Miller @ 2004-06-07 22:27 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev

On Mon, 7 Jun 2004 10:07:44 -0700
Stephen Hemminger <shemminger@osdl.org> wrote:

> Add receiver feedback information to the tcp_info structure to allow
> looking at receive dynamic right sizing with 'ss' command.
> 
> This increases the size of the structure, but since both getsockopt() and netlink
> interface pass length in request; it retains compatibility with older versions.

Right, applied.  Thanks Stephen.

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

end of thread, other threads:[~2004-06-07 22:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-06-04 22:37 [PATCH] common code for generating tcp_info Stephen Hemminger
2004-06-05  3:57 ` David S. Miller
2004-06-07 17:07   ` [PATCH] add receive DRS info Stephen Hemminger
2004-06-07 22:27     ` David S. Miller
2004-06-07 14:48 ` [PATCH] common code for generating tcp_info Joe Perches
2004-06-07 16:16   ` Stephen Hemminger

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