Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 4 Jan 2011 16:51:24 +0000 (UTC)
From:      "George V. Neville-Neil" <gnn@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org
Subject:   svn commit: r216964 - stable/8/usr.bin/netstat
Message-ID:  <201101041651.p04GpO15046054@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: gnn
Date: Tue Jan  4 16:51:24 2011
New Revision: 216964
URL: http://svn.freebsd.org/changeset/base/216964

Log:
  MFC: 215434, 215724
  
  Add new, per connection, statistics for TCP, including:
  Retransmitted Packets
  Zero Window Advertisements
  Out of Order Receives
  
  These statistics are available via the -T argument to
  netstat(1).

Modified:
  stable/8/usr.bin/netstat/inet.c
  stable/8/usr.bin/netstat/main.c
  stable/8/usr.bin/netstat/netstat.1
  stable/8/usr.bin/netstat/netstat.h

Modified: stable/8/usr.bin/netstat/inet.c
==============================================================================
--- stable/8/usr.bin/netstat/inet.c	Tue Jan  4 16:29:07 2011	(r216963)
+++ stable/8/usr.bin/netstat/inet.c	Tue Jan  4 16:51:24 2011	(r216964)
@@ -408,21 +408,29 @@ protopr(u_long off, const char *name, in
 			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\n",
+				       "rexmt", "persist", "keep",
+				       "2msl", "delack", "rcvtime");
+			}
+			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 %s\n",
-					       	"R-MBUF", "S-MBUF", "R-CLUS", 
-						"S-CLUS", "R-HIWA", "S-HIWA", 
-						"R-LOWA", "S-LOWA", "R-BCNT", 
-						"S-BCNT", "R-BMAX", "S-BMAX",
-					       "(state)");
-				else
-					printf("(state)\n");
+				printf("(state)\n");
 			}
 			first = 0;
 		}
@@ -449,6 +457,10 @@ protopr(u_long off, const char *name, in
 			snprintf(buf1, 15, "%d/%d/%d", so->so_qlen,
 			    so->so_incqlen, so->so_qlimit);
 			printf("%-14.14s ", buf1);
+		} else if (Tflag) {
+			if (istcp)
+				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);
 		}
@@ -525,7 +537,7 @@ protopr(u_long off, const char *name, in
 				       so->so_rcv.sb_mbcnt, so->so_snd.sb_mbcnt,
 				       so->so_rcv.sb_mbmax, so->so_snd.sb_mbmax);
 		}
-		if (istcp && !Lflag) {
+		if (istcp && !Lflag && !xflag && !Tflag) {
 			if (tp->t_state < 0 || tp->t_state >= TCP_NSTATES)
 				printf("%d", tp->t_state);
 			else {

Modified: stable/8/usr.bin/netstat/main.c
==============================================================================
--- stable/8/usr.bin/netstat/main.c	Tue Jan  4 16:29:07 2011	(r216963)
+++ stable/8/usr.bin/netstat/main.c	Tue Jan  4 16:51:24 2011	(r216964)
@@ -340,6 +340,7 @@ int	rflag;		/* show routing tables (or r
 int	sflag;		/* show protocol statistics */
 int	tflag;		/* show i/f watchdog timers */
 int	Wflag;		/* wide display */
+int	Tflag;		/* TCP Information */
 int	xflag;		/* extra information, includes all socket buffer info */
 int	zflag;		/* zero stats */
 
@@ -359,7 +360,8 @@ main(int argc, char *argv[])
 
 	af = AF_UNSPEC;
 
-	while ((ch = getopt(argc, argv, "AaBbdf:ghI:iLlM:mN:np:q:rSstuWw:xz")) != -1)
+	while ((ch = getopt(argc, argv, "AaBbdf:ghI:iLlM:mN:np:Qq:rSTstuWw:xz"))
+	    != -1)
 		switch(ch) {
 		case 'A':
 			Aflag = 1;
@@ -473,6 +475,9 @@ main(int argc, char *argv[])
 			interval = atoi(optarg);
 			iflag = 1;
 			break;
+		case 'T':
+			Tflag = 1;
+			break;
 		case 'x':
 			xflag = 1;
 			break;
@@ -512,6 +517,9 @@ main(int argc, char *argv[])
 	if (!live)
 		setgid(getgid());
 
+	if (xflag && Tflag) 
+		errx(1, "-x and -T are incompatible, pick one.");
+
 	if (Bflag) {
 		if (!live)
 			usage();
@@ -782,7 +790,7 @@ static void
 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",
-"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 [-abdhntW] [-f address_family]\n"
 "               [-M core] [-N system]",

Modified: stable/8/usr.bin/netstat/netstat.1
==============================================================================
--- stable/8/usr.bin/netstat/netstat.1	Tue Jan  4 16:29:07 2011	(r216963)
+++ stable/8/usr.bin/netstat/netstat.1	Tue Jan  4 16:51:24 2011	(r216964)
@@ -49,7 +49,7 @@ depending on the options for the informa
 .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 @@ but show ports symbolically.
 If
 .Fl x
 is present display full socket buffer 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

Modified: stable/8/usr.bin/netstat/netstat.h
==============================================================================
--- stable/8/usr.bin/netstat/netstat.h	Tue Jan  4 16:29:07 2011	(r216963)
+++ stable/8/usr.bin/netstat/netstat.h	Tue Jan  4 16:51:24 2011	(r216964)
@@ -51,6 +51,7 @@ extern int	numeric_port;	/* show ports n
 extern int	rflag;	/* show routing tables (or routing stats) */
 extern int	sflag;	/* show protocol statistics */
 extern int	tflag;	/* show i/f watchdog timers */
+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 */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201101041651.p04GpO15046054>