summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwollman <wollman@FreeBSD.org>1997-09-27 00:44:55 +0000
committerwollman <wollman@FreeBSD.org>1997-09-27 00:44:55 +0000
commitb26754caaa6ecf592abaff08257fcfe77670329d (patch)
treee75d4eea856de989b620638e2e31349f3843d4d7
parent8a0c7c5ebea846771a4563a1dcee351b84d37803 (diff)
downloadFreeBSD-src-b26754caaa6ecf592abaff08257fcfe77670329d.zip
FreeBSD-src-b26754caaa6ecf592abaff08257fcfe77670329d.tar.gz
Having done ICMP, UDP, and IP, could a TCP display be far behind?
-rw-r--r--usr.bin/systat/Makefile2
-rw-r--r--usr.bin/systat/cmdtab.c5
-rw-r--r--usr.bin/systat/extern.h7
-rw-r--r--usr.bin/systat/systat.152
-rw-r--r--usr.bin/systat/tcp.c323
5 files changed, 375 insertions, 14 deletions
diff --git a/usr.bin/systat/Makefile b/usr.bin/systat/Makefile
index 4664fd5..d45e526 100644
--- a/usr.bin/systat/Makefile
+++ b/usr.bin/systat/Makefile
@@ -3,7 +3,7 @@
PROG= systat
CFLAGS+=-I${.CURDIR}/../../sys -I${.CURDIR}/../vmstat
SRCS= cmds.c cmdtab.c disks.c fetch.c iostat.c keyboard.c vmstat.c main.c \
- mbufs.c netcmds.c netstat.c pigs.c swap.c icmp.c mode.c ip.c
+ mbufs.c netcmds.c netstat.c pigs.c swap.c icmp.c mode.c ip.c tcp.c
DPADD= ${LIBCURSES} ${LIBTERMCAP} ${LIBM} ${LIBKVM}
LDADD= -lcurses -ltermcap -lm -lkvm
BINGRP= kmem
diff --git a/usr.bin/systat/cmdtab.c b/usr.bin/systat/cmdtab.c
index d2a2884..83b5b02 100644
--- a/usr.bin/systat/cmdtab.c
+++ b/usr.bin/systat/cmdtab.c
@@ -36,7 +36,7 @@
static char sccsid[] = "@(#)cmdtab.c 8.1 (Berkeley) 6/6/93";
*/
static const char rcsid[] =
- "$Id: cmdtab.c,v 1.2 1997/09/24 02:43:37 wollman Exp $";
+ "$Id: cmdtab.c,v 1.3 1997/09/25 00:37:31 wollman Exp $";
#endif /* not lint */
#include "systat.h"
@@ -68,6 +68,9 @@ struct cmdtab cmdtab[] = {
{ "ip", showip, fetchip, labelip,
initip, openip, closeip, cmdmode,
resetip, CF_LOADAV },
+ { "tcp", showtcp, fetchtcp, labeltcp,
+ inittcp, opentcp, closetcp, cmdmode,
+ resettcp, CF_LOADAV },
{ 0 }
};
struct cmdtab *curcmd = &cmdtab[0];
diff --git a/usr.bin/systat/extern.h b/usr.bin/systat/extern.h
index 0deeeb1..c6d5812 100644
--- a/usr.bin/systat/extern.h
+++ b/usr.bin/systat/extern.h
@@ -70,6 +70,7 @@ void closembufs __P((WINDOW *));
void closenetstat __P((WINDOW *));
void closepigs __P((WINDOW *));
void closeswap __P((WINDOW *));
+void closetcp __P((WINDOW *));
int cmdiostat __P((char *, char *));
int cmdkre __P((char *, char *));
int cmdnetstat __P((char *, char *));
@@ -88,6 +89,7 @@ void fetchmbufs __P((void));
void fetchnetstat __P((void));
void fetchpigs __P((void));
void fetchswap __P((void));
+void fetchtcp __P((void));
int initicmp __P((void));
int initip __P((void));
int initiostat __P((void));
@@ -96,6 +98,7 @@ int initmbufs __P((void));
int initnetstat __P((void));
int initpigs __P((void));
int initswap __P((void));
+int inittcp __P((void));
int keyboard __P((void));
int kvm_ckread __P((void *, void *, int));
void labelicmp __P((void));
@@ -107,6 +110,7 @@ void labelnetstat __P((void));
void labelpigs __P((void));
void labels __P((void));
void labelswap __P((void));
+void labeltcp __P((void));
void load __P((void));
int netcmd __P((char *, char *));
void nlisterr __P((struct nlist []));
@@ -118,9 +122,11 @@ WINDOW *openmbufs __P((void));
WINDOW *opennetstat __P((void));
WINDOW *openpigs __P((void));
WINDOW *openswap __P((void));
+WINDOW *opentcp __P((void));
int prefix __P((char *, char *));
void reseticmp __P((void));
void resetip __P((void));
+void resettcp __P((void));
void showicmp __P((void));
void showip __P((void));
void showiostat __P((void));
@@ -129,5 +135,6 @@ void showmbufs __P((void));
void shownetstat __P((void));
void showpigs __P((void));
void showswap __P((void));
+void showtcp __P((void));
void status __P((void));
void suspend __P((int));
diff --git a/usr.bin/systat/systat.1 b/usr.bin/systat/systat.1
index a54e7f8..1ae87cd 100644
--- a/usr.bin/systat/systat.1
+++ b/usr.bin/systat/systat.1
@@ -66,7 +66,7 @@ statistics (a la
virtual memory statistics (a la
.Xr vmstat 8 ) ,
network ``mbuf'' utilization,
-.Tn ICMP
+.Tn TCP/IP
statistics,
and network connections (a la
.Xr netstat 1 ) .
@@ -85,14 +85,16 @@ The
flag expects
.Ar display
to be one of:
-.Ic pigs ,
.Ic icmp ,
.Ic iostat ,
-.Ic swap ,
+.Ic ip ,
.Ic mbufs ,
-.Ic vmstat
+.Ic netstat ,
+.Ic pigs ,
+.Ic swap ,
+.Ic tcp ,
or
-.Ic netstat .
+.Ic vmstat .
These displays can also be requested interactively (without the
.Dq Fl )
and are described in
@@ -194,6 +196,20 @@ mode. The
.Ic mode
command with no argument will display the current mode in the command
line.
+.It Ic ip
+Otherwise identical to the
+.Ic icmp
+display, except that it displays
+.Tn IP
+and
+.Tn UDP
+statistics.
+.It Ic tcp
+Like
+.Ic icmp ,
+but with
+.Tn TCP
+statistics.
.It Ic iostat
Display, in the lower window, statistics about processor use
and disk throughput. Statistics on processor use appear as
@@ -288,8 +304,10 @@ of kilobyte blocks transferred per second averaged over the
refresh period of the display (by default, five seconds).
For some disks it also reports the average milliseconds per seek.
Note that the system only keeps statistics on at most eight disks
-(this is controlled by the constant DK_NDRIVE in
-.Pa /usr/include/sys/dkstat.h
+(this is controlled by the constant
+.Dv DK_NDRIVE
+in
+.Aq Pa sys/dkstat.h
as a kernel compile-time constant).
.Pp
Under the date in the upper right hand quadrant are statistics
@@ -440,10 +458,13 @@ Display information about the drives indicated. Multiple drives
may be specified, separated by spaces.
.El
.Sh SEE ALSO
+.Xr icmp 4 ,
.Xr iostat 1 ,
+.Xr ip 4 ,
.Xr netstat 1 ,
-.Xr vmstat 1 ,
-.Xr icmp 4
+.Xr tcp 4 ,
+.Xr udp 4 ,
+.Xr vmstat 1
.Sh FILES
.Bl -tag -width /etc/networks -compact
.It Pa /kernel
@@ -465,11 +486,18 @@ The
program appeared in
.Bx 4.3 .
The
-.Ic icmp
-display appeared in
+.Ic icmp ,
+.Ic ip ,
+and
+.Ic tcp
+displays appeared in
.Fx 3.0 ;
the notion of having different display modes for the
-.Tn ICMP
+.Tn ICMP ,
+.Tn IP
+.Tn TCP ,
+and
+.Tn UDP
statistics was stolen from the
.Fl C
option to
diff --git a/usr.bin/systat/tcp.c b/usr.bin/systat/tcp.c
new file mode 100644
index 0000000..9a9bbcc
--- /dev/null
+++ b/usr.bin/systat/tcp.c
@@ -0,0 +1,323 @@
+/*-
+ * Copyright (c) 1980, 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+/* From:
+static char sccsid[] = "@(#)mbufs.c 8.1 (Berkeley) 6/6/93";
+static const char rcsid[] =
+ "Id: mbufs.c,v 1.5 1997/02/24 20:59:03 wollman Exp";
+*/
+static const char rcsid[] =
+ "$Id: icmp.c,v 1.1 1997/09/24 02:43:39 wollman Exp $";
+#endif /* not lint */
+
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/sysctl.h>
+
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
+#include <netinet/ip.h>
+#include <netinet/tcp.h>
+#include <netinet/tcp_seq.h>
+#include <netinet/tcp_fsm.h>
+#include <netinet/tcp_timer.h>
+#include <netinet/tcp_var.h>
+
+#include <stdlib.h>
+#include <string.h>
+#include <paths.h>
+#include "systat.h"
+#include "extern.h"
+#include "mode.h"
+
+static struct tcpstat curstat, initstat, oldstat;
+
+/*-
+--0 1 2 3 4 5 6 7
+--0123456789012345678901234567890123456789012345678901234567890123456789012345
+01 TCP Connections TCP Packets
+02999999999 connections initiated 999999999 total packets sent
+03999999999 connections accepted 999999999 - data
+04999999999 connections established 999999999 - data (retransmit)
+05999999999 connections dropped 999999999 - ack-only
+06999999999 - in embryonic state 999999999 - window probes
+07999999999 - on retransmit timeout 999999999 - window updates
+08999999999 - by keepalive 999999999 - urgent data only
+09999999999 - from listen queue 999999999 - control
+10 999999999 - resends by PMTU discovery
+11 TCP Timers 999999999 total packets received
+12999999999 potential rtt updates 999999999 - in sequence
+13999999999 - successful 999999999 - completely duplicate
+14999999999 delayed acks sent 999999999 - with some duplicate data
+15999999999 retransmit timeouts 999999999 - out-of-order
+16999999999 persist timeouts 999999999 - duplicate acks
+17999999999 keepalive probes 999999999 - acks
+18999999999 - timeouts 999999999 - window probes
+19 999999999 - window updates
+--0123456789012345678901234567890123456789012345678901234567890123456789012345
+--0 1 2 3 4 5 6 7
+*/
+
+WINDOW *
+opentcp(void)
+{
+ return (subwin(stdscr, LINES-5-1, 0, 5, 0));
+}
+
+void
+closetcp(w)
+ WINDOW *w;
+{
+ if (w == NULL)
+ return;
+ wclear(w);
+ wrefresh(w);
+ delwin(w);
+}
+
+void
+labeltcp(void)
+{
+ wmove(wnd, 0, 0); wclrtoeol(wnd);
+#define L(row, str) mvwprintw(wnd, row, 10, str)
+#define R(row, str) mvwprintw(wnd, row, 45, str);
+ L(1, "TCP Connections"); R(1, "TCP Packets");
+ L(2, "connections initiated"); R(2, "total packets sent");
+ L(3, "connections accepted"); R(3, "- data");
+ L(4, "connections established"); R(4, "- data (retransmit)");
+ L(5, "connections dropped"); R(5, "- ack-only");
+ L(6, "- in embryonic state"); R(6, "- window probes");
+ L(7, "- on retransmit timeout"); R(7, "- window updates");
+ L(8, "- by keepalive"); R(8, "- urgent data only");
+ L(9, "- from listen queue"); R(9, "- control");
+ R(10, "- resends by PMTU discovery");
+ L(11, "TCP Timers"); R(11, "total packets received");
+ L(12, "potential rtt updates"); R(12, "- in sequence");
+ L(13, "- successful"); R(13, "- completely duplicate");
+ L(14, "delayed acks sent"); R(14, "- with some duplicate data");
+ L(15, "retransmit timeouts"); R(15, "- out-of-order");
+ L(16, "persist timeouts"); R(16, "- duplicate acks");
+ L(17, "keepalive probes"); R(17, "- acks");
+ L(18, "- timeouts"); R(18, "- window probes");
+ R(19, "- window updates");
+#undef L
+#undef R
+}
+
+static void
+domode(struct tcpstat *ret)
+{
+ const struct tcpstat *sub;
+ int i, divisor = 1;
+
+ switch(currentmode) {
+ case display_RATE:
+ sub = &oldstat;
+ divisor = naptime;
+ break;
+ case display_DELTA:
+ sub = &oldstat;
+ break;
+ case display_SINCE:
+ sub = &initstat;
+ break;
+ default:
+ *ret = curstat;
+ return;
+ }
+#define DO(stat) ret->stat = (curstat.stat - sub->stat) / divisor
+ DO(tcps_connattempt);
+ DO(tcps_accepts);
+ DO(tcps_connects);
+ DO(tcps_drops);
+ DO(tcps_conndrops);
+ DO(tcps_closed);
+ DO(tcps_segstimed);
+ DO(tcps_rttupdated);
+ DO(tcps_delack);
+ DO(tcps_timeoutdrop);
+ DO(tcps_rexmttimeo);
+ DO(tcps_persisttimeo);
+ DO(tcps_keeptimeo);
+ DO(tcps_keepprobe);
+ DO(tcps_keepdrops);
+
+ DO(tcps_sndtotal);
+ DO(tcps_sndpack);
+ DO(tcps_sndbyte);
+ DO(tcps_sndrexmitpack);
+ DO(tcps_sndrexmitbyte);
+ DO(tcps_sndacks);
+ DO(tcps_sndprobe);
+ DO(tcps_sndurg);
+ DO(tcps_sndwinup);
+ DO(tcps_sndctrl);
+
+ DO(tcps_rcvtotal);
+ DO(tcps_rcvpack);
+ DO(tcps_rcvbyte);
+ DO(tcps_rcvbadsum);
+ DO(tcps_rcvbadoff);
+ DO(tcps_rcvshort);
+ DO(tcps_rcvduppack);
+ DO(tcps_rcvdupbyte);
+ DO(tcps_rcvpartduppack);
+ DO(tcps_rcvpartdupbyte);
+ DO(tcps_rcvoopack);
+ DO(tcps_rcvoobyte);
+ DO(tcps_rcvpackafterwin);
+ DO(tcps_rcvbyteafterwin);
+ DO(tcps_rcvafterclose);
+ DO(tcps_rcvwinprobe);
+ DO(tcps_rcvdupack);
+ DO(tcps_rcvacktoomuch);
+ DO(tcps_rcvackpack);
+ DO(tcps_rcvackbyte);
+ DO(tcps_rcvwinupd);
+ DO(tcps_pawsdrop);
+ DO(tcps_predack);
+ DO(tcps_preddat);
+ DO(tcps_pcbcachemiss);
+ DO(tcps_cachedrtt);
+ DO(tcps_cachedrttvar);
+ DO(tcps_cachedssthresh);
+ DO(tcps_usedrtt);
+ DO(tcps_usedrttvar);
+ DO(tcps_usedssthresh);
+ DO(tcps_persistdrop);
+ DO(tcps_badsyn);
+ DO(tcps_mturesent);
+ DO(tcps_listendrop);
+#undef DO
+}
+
+void
+showtcp(void)
+{
+ struct tcpstat stats;
+
+ memset(&stats, 0, sizeof stats);
+ domode(&stats);
+
+#define DO(stat, row, col) \
+ mvwprintw(wnd, row, col, "%9lu", stats.stat)
+#define L(row, stat) DO(stat, row, 0)
+#define R(row, stat) DO(stat, row, 35)
+ L(2, tcps_connattempt); R(2, tcps_sndtotal);
+ L(3, tcps_accepts); R(3, tcps_sndpack);
+ L(4, tcps_connects); R(4, tcps_sndrexmitpack);
+ L(5, tcps_drops); R(5, tcps_sndacks);
+ L(6, tcps_conndrops); R(6, tcps_sndprobe);
+ L(7, tcps_timeoutdrop); R(7, tcps_sndwinup);
+ L(8, tcps_keepdrops); R(8, tcps_sndurg);
+ L(9, tcps_listendrop); R(9, tcps_sndctrl);
+ R(10, tcps_mturesent);
+ R(11, tcps_rcvtotal);
+ L(12, tcps_segstimed); R(12, tcps_rcvpack);
+ L(13, tcps_rttupdated); R(13, tcps_rcvduppack);
+ L(14, tcps_delack); R(14, tcps_rcvpartduppack);
+ L(15, tcps_rexmttimeo); R(15, tcps_rcvoopack);
+ L(16, tcps_persisttimeo); R(16, tcps_rcvdupack);
+ L(17, tcps_keepprobe); R(17, tcps_rcvackpack);
+ L(18, tcps_keeptimeo); R(18, tcps_rcvwinprobe);
+ R(19, tcps_rcvwinupd);
+#undef DO
+#undef L
+#undef R
+}
+
+int
+inittcp(void)
+{
+ size_t len;
+ int name[4];
+
+ name[0] = CTL_NET;
+ name[1] = PF_INET;
+ name[2] = IPPROTO_TCP;
+ name[3] = TCPCTL_STATS;
+
+ len = 0;
+ if (sysctl(name, 4, 0, &len, 0, 0) < 0) {
+ error("sysctl getting tcpstat size failed");
+ return 0;
+ }
+ if (len > sizeof curstat) {
+ error("tcpstat structure has grown--recompile systat!");
+ return 0;
+ }
+ if (sysctl(name, 4, &initstat, &len, 0, 0) < 0) {
+ error("sysctl getting tcpstat failed");
+ return 0;
+ }
+ oldstat = initstat;
+ return 1;
+}
+
+void
+resettcp(void)
+{
+ size_t len;
+ int name[4];
+
+ name[0] = CTL_NET;
+ name[1] = PF_INET;
+ name[2] = IPPROTO_TCP;
+ name[3] = TCPCTL_STATS;
+
+ len = sizeof initstat;
+ if (sysctl(name, 4, &initstat, &len, 0, 0) < 0) {
+ error("sysctl getting tcpstat failed");
+ }
+ oldstat = initstat;
+}
+
+void
+fetchtcp(void)
+{
+ int name[4];
+ size_t len;
+
+ oldstat = curstat;
+ name[0] = CTL_NET;
+ name[1] = PF_INET;
+ name[2] = IPPROTO_TCP;
+ name[3] = TCPCTL_STATS;
+ len = sizeof curstat;
+
+ if (sysctl(name, 4, &curstat, &len, 0, 0) < 0)
+ return;
+}
+
OpenPOWER on IntegriCloud