Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 15 Nov 2010 16:53:57 -0500
From:      George Neville-Neil <gnn@freebsd.org>
To:        net@freebsd.org
Cc:        John Baldwin <jhb@FreeBSD.org>
Subject:   Proposed new information from netstat
Message-ID:  <68C8A8D9-E592-4561-973F-02873227DF3D@freebsd.org>

next in thread | raw e-mail | index | archive | help

--Apple-Mail-3-165708523
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
	charset=us-ascii

Howdy,

Please review this patch which adds the -T flag to netstat so that you =
can get TCP information, per socket,
including retransmits, out-of-order receives, and zero window =
advertisements.

Best,
George


--Apple-Mail-3-165708523
Content-Disposition: attachment;
	filename=head-tcpinfo.diff
Content-Type: application/octet-stream; x-unix-mode=0664;
	name="head-tcpinfo.diff"
Content-Transfer-Encoding: 7bit

Index: usr.bin/netstat/inet.c
===================================================================
--- usr.bin/netstat/inet.c	(revision 215339)
+++ usr.bin/netstat/inet.c	(working copy)
@@ -411,25 +411,30 @@
 			if (Lflag)
 				printf("%-5.5s %-14.14s %-22.22s\n",
 				    "Proto", "Listen", "Local Address");
-			else {
+			if (Tflag) 
+				printf((Aflag && !Wflag) ?
+			    "%-5.5s %-6.6s %-6.6s %-6.6s %-18.18s %s\n" :
+			    "%-5.5s %-6.6s %-6.6s %-6.6s %-22.22s %s\n",
+				    "Proto", "Rexmit", "OOORcv", "0-win",
+				    "Local Address", "Foreign Address");
+			if (xflag) {
+				printf("%-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s ",
+				       "R-MBUF", "S-MBUF", "R-CLUS", 
+				       "S-CLUS", "R-HIWA", "S-HIWA", 
+				       "R-LOWA", "S-LOWA", "R-BCNT", 
+				       "S-BCNT", "R-BMAX", "S-BMAX");
+				printf("%7.7s %7.7s %7.7s %7.7s %7.7s %7.7s %s\n",
+				       "rexmt", "persist", "keep",
+				       "2msl", "delack", "rcvtime",
+				       "(state)");
+			}
+			if (!xflag && !Tflag) 
 				printf((Aflag && !Wflag) ? 
 				       "%-5.5s %-6.6s %-6.6s  %-18.18s %-18.18s" :
 				       "%-5.5s %-6.6s %-6.6s  %-22.22s %-22.22s",
 				       "Proto", "Recv-Q", "Send-Q",
 				       "Local Address", "Foreign Address");
-				if (xflag) {
-					printf("%-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s ",
-					       	"R-MBUF", "S-MBUF", "R-CLUS", 
-						"S-CLUS", "R-HIWA", "S-HIWA", 
-						"R-LOWA", "S-LOWA", "R-BCNT", 
-						"S-BCNT", "R-BMAX", "S-BMAX");
-					printf("%7.7s %7.7s %7.7s %7.7s %7.7s %7.7s %s\n",
-						"rexmt", "persist", "keep",
-						"2msl", "delack", "rcvtime",
-						"(state)");
-				} else
-					printf("(state)\n");
-			}
+
 			first = 0;
 		}
 		if (Lflag && so->so_qlimit == 0)
@@ -455,6 +460,9 @@
 			snprintf(buf1, 15, "%d/%d/%d", so->so_qlen,
 			    so->so_incqlen, so->so_qlimit);
 			printf("%-14.14s ", buf1);
+		} else if (Tflag) {
+			printf("%6u %6u %6u ", tp->t_sndrexmitpack,
+			    tp->t_rcvoopack, tp->t_sndzerowin);
 		} else {
 			printf("%6u %6u ", so->so_rcv.sb_cc, so->so_snd.sb_cc);
 		}
@@ -540,7 +548,7 @@
 					    timer->t_rcvtime / 1000, (timer->t_rcvtime % 1000) / 10);
 			}
 		}
-		if (istcp && !Lflag) {
+		if (istcp && !Lflag && !xflag && !Tflag) {
 			if (tp->t_state < 0 || tp->t_state >= TCP_NSTATES)
 				printf("%d", tp->t_state);
 			else {
Index: usr.bin/netstat/netstat.1
===================================================================
--- usr.bin/netstat/netstat.1	(revision 215339)
+++ usr.bin/netstat/netstat.1	(working copy)
@@ -49,7 +49,7 @@
 .It Xo
 .Bk -words
 .Nm
-.Op Fl AaLnSWx
+.Op Fl AaLnSTWx
 .Op Fl f Ar protocol_family | Fl p Ar protocol
 .Op Fl M Ar core
 .Op Fl N Ar system
@@ -88,6 +88,10 @@
 If
 .Fl x
 is present, display socket buffer and tcp timer statistics for each internet socket.
+When
+.Fl T
+is present, display information from the TCP control block, including
+retransmits, out-of-order packets received, and zero-sized windows advertised.
 .It Xo
 .Bk -words
 .Nm
Index: usr.bin/netstat/main.c
===================================================================
--- usr.bin/netstat/main.c	(revision 215339)
+++ usr.bin/netstat/main.c	(working copy)
@@ -342,6 +342,7 @@
 int	rflag;		/* show routing tables (or routing stats) */
 int	sflag;		/* show protocol statistics */
 int	Wflag;		/* wide display */
+int	Tflag;		/* TCP Information */
 int	xflag;		/* extra information, includes all socket buffer info */
 int	zflag;		/* zero stats */
 
@@ -361,7 +362,7 @@
 
 	af = AF_UNSPEC;
 
-	while ((ch = getopt(argc, argv, "AaBbdf:ghI:iLlM:mN:np:Qq:rSsuWw:xz"))
+	while ((ch = getopt(argc, argv, "AaBbdf:ghI:iLlM:mN:np:Qq:rSTsuWw:xz"))
 	    != -1)
 		switch(ch) {
 		case 'A':
@@ -476,6 +477,9 @@
 			interval = atoi(optarg);
 			iflag = 1;
 			break;
+		case 'T':
+			Tflag = 1;
+			break;
 		case 'x':
 			xflag = 1;
 			break;
@@ -515,6 +519,9 @@
 	if (!live)
 		setgid(getgid());
 
+	if (xflag && Tflag) 
+		errx(1, "-x and -T are incompatible, pick one.");
+
 	if (Bflag) {
 		if (!live)
 			usage();
@@ -794,7 +801,7 @@
 usage(void)
 {
 	(void)fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
-"usage: netstat [-AaLnSWx] [-f protocol_family | -p protocol]\n"
+"usage: netstat [-AaLnSTWx] [-f protocol_family | -p protocol]\n"
 "               [-M core] [-N system]",
 "       netstat -i | -I interface [-abdhnW] [-f address_family]\n"
 "               [-M core] [-N system]",
Index: usr.bin/netstat/netstat.h
===================================================================
--- usr.bin/netstat/netstat.h	(revision 215339)
+++ usr.bin/netstat/netstat.h	(working copy)
@@ -50,6 +50,7 @@
 extern int	numeric_port;	/* show ports numerically */
 extern int	rflag;	/* show routing tables (or routing stats) */
 extern int	sflag;	/* show protocol statistics */
+extern int	Tflag;  /* show TCP control block info */
 extern int	Wflag;	/* wide display */
 extern int	xflag;	/* extended display, includes all socket buffer info */
 extern int	zflag;	/* zero stats */
Index: sys/netinet/tcp_reass.c
===================================================================
--- sys/netinet/tcp_reass.c	(revision 215339)
+++ sys/netinet/tcp_reass.c	(working copy)
@@ -266,6 +266,7 @@
 			th->th_seq += i;
 		}
 	}
+ 	tp->t_rcvoopack++;
 	TCPSTAT_INC(tcps_rcvoopack);
 	TCPSTAT_ADD(tcps_rcvoobyte, *tlenp);
 
Index: sys/netinet/tcp_var.h
===================================================================
--- sys/netinet/tcp_var.h	(revision 215339)
+++ sys/netinet/tcp_var.h	(working copy)
@@ -177,6 +177,7 @@
 	u_long	snd_cwnd_prev;		/* cwnd prior to retransmit */
 	u_long	snd_ssthresh_prev;	/* ssthresh prior to retransmit */
 	tcp_seq	snd_recover_prev;	/* snd_recover prior to retransmit */
+	int	t_sndzerowin;		/* zero-window updates sent */
 	u_int	t_badrxtwin;		/* window for retransmit recovery */
 	u_char	snd_limited;		/* segments limited transmitted */
 /* SACK related state */
@@ -193,6 +194,8 @@
 	u_int32_t	rfbuf_ts;	/* recv buffer autoscaling timestamp */
 	int	rfbuf_cnt;		/* recv buffer autoscaling byte count */
 	struct toe_usrreqs *t_tu;	/* offload operations vector */
+	int	t_sndrexmitpack;	/* retransmit packets sent */
+	int	t_rcvoopack;		/* out-of-order packets received */
 	void	*t_toe;			/* TOE pcb pointer */
 	int	t_bytes_acked;		/* # bytes acked during current RTT */
 	struct cc_algo	*cc_algo;	/* congestion control algorithm */
Index: sys/netinet/tcp_output.c
===================================================================
--- sys/netinet/tcp_output.c	(revision 215339)
+++ sys/netinet/tcp_output.c	(working copy)
@@ -803,6 +803,7 @@
 		if ((tp->t_flags & TF_FORCEDATA) && len == 1)
 			TCPSTAT_INC(tcps_sndprobe);
 		else if (SEQ_LT(tp->snd_nxt, tp->snd_max) || sack_rxmit) {
+			tp->t_sndrexmitpack++;
 			TCPSTAT_INC(tcps_sndrexmitpack);
 			TCPSTAT_ADD(tcps_sndrexmitbyte, len);
 		} else {
@@ -1027,9 +1028,10 @@
 	 * to read more data than can be buffered prior to transmitting on
 	 * the connection.
 	 */
-	if (th->th_win == 0)
+	if (th->th_win == 0) {
+		tp->t_sndzerowin++;
 		tp->t_flags |= TF_RXWIN0SENT;
-	else
+	} else
 		tp->t_flags &= ~TF_RXWIN0SENT;
 	if (SEQ_GT(tp->snd_up, tp->snd_nxt)) {
 		th->th_urp = htons((u_short)(tp->snd_up - tp->snd_nxt));
Index: sys/netinet/tcp.h
===================================================================
--- sys/netinet/tcp.h	(revision 215339)
+++ sys/netinet/tcp.h	(working copy)
@@ -225,9 +225,12 @@
 	u_int32_t	tcpi_snd_nxt;		/* Next egress seqno */
 	u_int32_t	tcpi_rcv_nxt;		/* Next ingress seqno */
 	u_int32_t	tcpi_toe_tid;		/* HWTID for TOE endpoints */
+	u_int32_t	tcpi_snd_rexmitpack;	/* Retransmitted packets */
+	u_int32_t	tcpi_rcv_ooopack;	/* Out-of-order packets */
+	u_int32_t	tcpi_snd_zerowin;	/* Zero-sized windows sent */
 	
 	/* Padding to grow without breaking ABI. */
-	u_int32_t	__tcpi_pad[29];		/* Padding. */
+	u_int32_t	__tcpi_pad[26];		/* Padding. */
 };
 #endif
 
Index: sys/netinet/tcp_usrreq.c
===================================================================
--- sys/netinet/tcp_usrreq.c	(revision 215339)
+++ sys/netinet/tcp_usrreq.c	(working copy)
@@ -1218,6 +1218,9 @@
 	ti->tcpi_rcv_mss = tp->t_maxseg;
 	if (tp->t_flags & TF_TOE)
 		ti->tcpi_options |= TCPI_OPT_TOE;
+	ti->tcpi_snd_rexmitpack = tp->t_sndrexmitpack;
+	ti->tcpi_rcv_ooopack = tp->t_rcvoopack;
+	ti->tcpi_snd_zerowin = tp->t_sndzerowin;
 }
 
 /*

--Apple-Mail-3-165708523--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?68C8A8D9-E592-4561-973F-02873227DF3D>