1630fa006SGarrett Wollman /*- 2630fa006SGarrett Wollman * Copyright (c) 1980, 1992, 1993 3630fa006SGarrett Wollman * The Regents of the University of California. All rights reserved. 4630fa006SGarrett Wollman * 5630fa006SGarrett Wollman * Redistribution and use in source and binary forms, with or without 6630fa006SGarrett Wollman * modification, are permitted provided that the following conditions 7630fa006SGarrett Wollman * are met: 8630fa006SGarrett Wollman * 1. Redistributions of source code must retain the above copyright 9630fa006SGarrett Wollman * notice, this list of conditions and the following disclaimer. 10630fa006SGarrett Wollman * 2. Redistributions in binary form must reproduce the above copyright 11630fa006SGarrett Wollman * notice, this list of conditions and the following disclaimer in the 12630fa006SGarrett Wollman * documentation and/or other materials provided with the distribution. 13*fbbd9655SWarner Losh * 3. Neither the name of the University nor the names of its contributors 14630fa006SGarrett Wollman * may be used to endorse or promote products derived from this software 15630fa006SGarrett Wollman * without specific prior written permission. 16630fa006SGarrett Wollman * 17630fa006SGarrett Wollman * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18630fa006SGarrett Wollman * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19630fa006SGarrett Wollman * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20630fa006SGarrett Wollman * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21630fa006SGarrett Wollman * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22630fa006SGarrett Wollman * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23630fa006SGarrett Wollman * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24630fa006SGarrett Wollman * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25630fa006SGarrett Wollman * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26630fa006SGarrett Wollman * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27630fa006SGarrett Wollman * SUCH DAMAGE. 28630fa006SGarrett Wollman */ 29630fa006SGarrett Wollman 307501cdc8SBruce Evans #if 0 317501cdc8SBruce Evans #ifndef lint 327501cdc8SBruce Evans /* From: */ 337501cdc8SBruce Evans static char sccsid[] = "@(#)mbufs.c 8.1 (Berkeley) 6/6/93"; 347501cdc8SBruce Evans static const char rcsid[] = 357501cdc8SBruce Evans "Id: mbufs.c,v 1.5 1997/02/24 20:59:03 wollman Exp"; 367501cdc8SBruce Evans #endif /* not lint */ 377501cdc8SBruce Evans #endif 387501cdc8SBruce Evans 399ff712b0SMark Murray #include <sys/cdefs.h> 409ff712b0SMark Murray __FBSDID("$FreeBSD$"); 419ff712b0SMark Murray 42630fa006SGarrett Wollman #include <sys/param.h> 43630fa006SGarrett Wollman #include <sys/types.h> 44630fa006SGarrett Wollman #include <sys/socket.h> 45630fa006SGarrett Wollman #include <sys/sysctl.h> 46630fa006SGarrett Wollman 47630fa006SGarrett Wollman #include <netinet/in.h> 48630fa006SGarrett Wollman #include <netinet/in_systm.h> 49630fa006SGarrett Wollman #include <netinet/ip.h> 50630fa006SGarrett Wollman #include <netinet/tcp.h> 51630fa006SGarrett Wollman #include <netinet/tcp_seq.h> 52630fa006SGarrett Wollman #include <netinet/tcp_fsm.h> 53630fa006SGarrett Wollman #include <netinet/tcp_timer.h> 54630fa006SGarrett Wollman #include <netinet/tcp_var.h> 55630fa006SGarrett Wollman 56821df508SXin LI #include <stdlib.h> 57630fa006SGarrett Wollman #include <string.h> 58821df508SXin LI #include <paths.h> 599ff712b0SMark Murray 60630fa006SGarrett Wollman #include "systat.h" 61630fa006SGarrett Wollman #include "extern.h" 62630fa006SGarrett Wollman #include "mode.h" 63630fa006SGarrett Wollman 64630fa006SGarrett Wollman static struct tcpstat curstat, initstat, oldstat; 65630fa006SGarrett Wollman 66630fa006SGarrett Wollman /*- 67630fa006SGarrett Wollman --0 1 2 3 4 5 6 7 68630fa006SGarrett Wollman --0123456789012345678901234567890123456789012345678901234567890123456789012345 698aa22952SBruce Evans 00 TCP Connections TCP Packets 7059003696SJohn Baldwin 01999999999999 connections initiated 999999999999 total packets sent 7159003696SJohn Baldwin 02999999999999 connections accepted 999999999999 - data 7259003696SJohn Baldwin 03999999999999 connections established 999999999999 - data (retransmit by dupack) 7359003696SJohn Baldwin 04999999999999 connections dropped 999999999999 - data (retransmit by sack) 7459003696SJohn Baldwin 05999999999999 - in embryonic state 999999999999 - ack-only 7559003696SJohn Baldwin 06999999999999 - on retransmit timeout 999999999999 - window probes 7659003696SJohn Baldwin 07999999999999 - by keepalive 999999999999 - window updates 7759003696SJohn Baldwin 08999999999999 - from listen queue 999999999999 - urgent data only 7859003696SJohn Baldwin 09 999999999999 - control 7959003696SJohn Baldwin 10 999999999999 - resends by PMTU discovery 8059003696SJohn Baldwin 11 TCP Timers 999999999999 total packets received 8159003696SJohn Baldwin 12999999999999 potential rtt updates 999999999999 - in sequence 8259003696SJohn Baldwin 13999999999999 - successful 999999999999 - completely duplicate 8359003696SJohn Baldwin 14999999999999 delayed acks sent 999999999999 - with some duplicate data 8459003696SJohn Baldwin 15999999999999 retransmit timeouts 999999999999 - out-of-order 8559003696SJohn Baldwin 16999999999999 persist timeouts 999999999999 - duplicate acks 8659003696SJohn Baldwin 17999999999999 keepalive probes 999999999999 - acks 8759003696SJohn Baldwin 18999999999999 - timeouts 999999999999 - window probes 8859003696SJohn Baldwin 19 999999999999 - window updates 8959003696SJohn Baldwin 20 999999999999 - bad checksum 90630fa006SGarrett Wollman --0123456789012345678901234567890123456789012345678901234567890123456789012345 91630fa006SGarrett Wollman --0 1 2 3 4 5 6 7 92630fa006SGarrett Wollman */ 93630fa006SGarrett Wollman 94630fa006SGarrett Wollman WINDOW * 95630fa006SGarrett Wollman opentcp(void) 96630fa006SGarrett Wollman { 978aa22952SBruce Evans return (subwin(stdscr, LINES-3-1, 0, MAINWIN_ROW, 0)); 98630fa006SGarrett Wollman } 99630fa006SGarrett Wollman 100630fa006SGarrett Wollman void 10193b9f504SXin LI closetcp(WINDOW *w) 102630fa006SGarrett Wollman { 103630fa006SGarrett Wollman if (w == NULL) 104630fa006SGarrett Wollman return; 105630fa006SGarrett Wollman wclear(w); 106630fa006SGarrett Wollman wrefresh(w); 1078aa22952SBruce Evans delwin(w); 108630fa006SGarrett Wollman } 109630fa006SGarrett Wollman 110630fa006SGarrett Wollman void 111630fa006SGarrett Wollman labeltcp(void) 112630fa006SGarrett Wollman { 113630fa006SGarrett Wollman wmove(wnd, 0, 0); wclrtoeol(wnd); 11459003696SJohn Baldwin #define L(row, str) mvwprintw(wnd, row, 13, str) 11559003696SJohn Baldwin #define R(row, str) mvwprintw(wnd, row, 51, str); 1168aa22952SBruce Evans L(0, "TCP Connections"); R(0, "TCP Packets"); 1178aa22952SBruce Evans L(1, "connections initiated"); R(1, "total packets sent"); 1188aa22952SBruce Evans L(2, "connections accepted"); R(2, "- data"); 11902a50a14SJohn Baldwin L(3, "connections established"); R(3, "- data (retransmit by dupack)"); 12002a50a14SJohn Baldwin L(4, "connections dropped"); R(4, "- data (retransmit by sack)"); 12102a50a14SJohn Baldwin L(5, "- in embryonic state"); R(5, "- ack-only"); 12202a50a14SJohn Baldwin L(6, "- on retransmit timeout"); R(6, "- window probes"); 12302a50a14SJohn Baldwin L(7, "- by keepalive"); R(7, "- window updates"); 12402a50a14SJohn Baldwin L(8, "- from listen queue"); R(8, "- urgent data only"); 12502a50a14SJohn Baldwin R(9, "- control"); 12602a50a14SJohn Baldwin R(10, "- resends by PMTU discovery"); 12702a50a14SJohn Baldwin L(11, "TCP Timers"); R(11, "total packets received"); 12802a50a14SJohn Baldwin L(12, "potential rtt updates"); R(12, "- in sequence"); 12902a50a14SJohn Baldwin L(13, "- successful"); R(13, "- completely duplicate"); 13002a50a14SJohn Baldwin L(14, "delayed acks sent"); R(14, "- with some duplicate data"); 13102a50a14SJohn Baldwin L(15, "retransmit timeouts"); R(15, "- out-of-order"); 13202a50a14SJohn Baldwin L(16, "persist timeouts"); R(16, "- duplicate acks"); 13302a50a14SJohn Baldwin L(17, "keepalive probes"); R(17, "- acks"); 13402a50a14SJohn Baldwin L(18, "- timeouts"); R(18, "- window probes"); 13502a50a14SJohn Baldwin R(19, "- window updates"); 13602a50a14SJohn Baldwin R(20, "- bad checksum"); 137630fa006SGarrett Wollman #undef L 138630fa006SGarrett Wollman #undef R 139630fa006SGarrett Wollman } 140630fa006SGarrett Wollman 141630fa006SGarrett Wollman static void 142630fa006SGarrett Wollman domode(struct tcpstat *ret) 143630fa006SGarrett Wollman { 144630fa006SGarrett Wollman const struct tcpstat *sub; 145d22889b8SDavid E. O'Brien int divisor = 1; 146630fa006SGarrett Wollman 147630fa006SGarrett Wollman switch(currentmode) { 148630fa006SGarrett Wollman case display_RATE: 149630fa006SGarrett Wollman sub = &oldstat; 1508b3daf89SAlexander V. Chernikov divisor = (delay > 1000000) ? delay / 1000000 : 1; 151630fa006SGarrett Wollman break; 152630fa006SGarrett Wollman case display_DELTA: 153630fa006SGarrett Wollman sub = &oldstat; 154630fa006SGarrett Wollman break; 155630fa006SGarrett Wollman case display_SINCE: 156630fa006SGarrett Wollman sub = &initstat; 157630fa006SGarrett Wollman break; 158630fa006SGarrett Wollman default: 159630fa006SGarrett Wollman *ret = curstat; 160630fa006SGarrett Wollman return; 161630fa006SGarrett Wollman } 162630fa006SGarrett Wollman #define DO(stat) ret->stat = (curstat.stat - sub->stat) / divisor 163630fa006SGarrett Wollman DO(tcps_connattempt); 164630fa006SGarrett Wollman DO(tcps_accepts); 165630fa006SGarrett Wollman DO(tcps_connects); 166630fa006SGarrett Wollman DO(tcps_drops); 167630fa006SGarrett Wollman DO(tcps_conndrops); 168630fa006SGarrett Wollman DO(tcps_closed); 169630fa006SGarrett Wollman DO(tcps_segstimed); 170630fa006SGarrett Wollman DO(tcps_rttupdated); 171630fa006SGarrett Wollman DO(tcps_delack); 172630fa006SGarrett Wollman DO(tcps_timeoutdrop); 173630fa006SGarrett Wollman DO(tcps_rexmttimeo); 174630fa006SGarrett Wollman DO(tcps_persisttimeo); 175630fa006SGarrett Wollman DO(tcps_keeptimeo); 176630fa006SGarrett Wollman DO(tcps_keepprobe); 177630fa006SGarrett Wollman DO(tcps_keepdrops); 178630fa006SGarrett Wollman 179630fa006SGarrett Wollman DO(tcps_sndtotal); 180630fa006SGarrett Wollman DO(tcps_sndpack); 181630fa006SGarrett Wollman DO(tcps_sndbyte); 182630fa006SGarrett Wollman DO(tcps_sndrexmitpack); 18302a50a14SJohn Baldwin DO(tcps_sack_rexmits); 184630fa006SGarrett Wollman DO(tcps_sndacks); 185630fa006SGarrett Wollman DO(tcps_sndprobe); 186630fa006SGarrett Wollman DO(tcps_sndurg); 187630fa006SGarrett Wollman DO(tcps_sndwinup); 188630fa006SGarrett Wollman DO(tcps_sndctrl); 189630fa006SGarrett Wollman 190630fa006SGarrett Wollman DO(tcps_rcvtotal); 191630fa006SGarrett Wollman DO(tcps_rcvpack); 192630fa006SGarrett Wollman DO(tcps_rcvbyte); 193630fa006SGarrett Wollman DO(tcps_rcvbadsum); 194630fa006SGarrett Wollman DO(tcps_rcvbadoff); 195630fa006SGarrett Wollman DO(tcps_rcvshort); 196630fa006SGarrett Wollman DO(tcps_rcvduppack); 197630fa006SGarrett Wollman DO(tcps_rcvdupbyte); 198630fa006SGarrett Wollman DO(tcps_rcvpartduppack); 199630fa006SGarrett Wollman DO(tcps_rcvpartdupbyte); 200630fa006SGarrett Wollman DO(tcps_rcvoopack); 201630fa006SGarrett Wollman DO(tcps_rcvoobyte); 202630fa006SGarrett Wollman DO(tcps_rcvpackafterwin); 203630fa006SGarrett Wollman DO(tcps_rcvbyteafterwin); 204630fa006SGarrett Wollman DO(tcps_rcvafterclose); 205630fa006SGarrett Wollman DO(tcps_rcvwinprobe); 206630fa006SGarrett Wollman DO(tcps_rcvdupack); 207630fa006SGarrett Wollman DO(tcps_rcvacktoomuch); 208630fa006SGarrett Wollman DO(tcps_rcvackpack); 209630fa006SGarrett Wollman DO(tcps_rcvackbyte); 210630fa006SGarrett Wollman DO(tcps_rcvwinupd); 211630fa006SGarrett Wollman DO(tcps_pawsdrop); 212630fa006SGarrett Wollman DO(tcps_predack); 213630fa006SGarrett Wollman DO(tcps_preddat); 214630fa006SGarrett Wollman DO(tcps_pcbcachemiss); 215630fa006SGarrett Wollman DO(tcps_cachedrtt); 216630fa006SGarrett Wollman DO(tcps_cachedrttvar); 217630fa006SGarrett Wollman DO(tcps_cachedssthresh); 218630fa006SGarrett Wollman DO(tcps_usedrtt); 219630fa006SGarrett Wollman DO(tcps_usedrttvar); 220630fa006SGarrett Wollman DO(tcps_usedssthresh); 221630fa006SGarrett Wollman DO(tcps_persistdrop); 222630fa006SGarrett Wollman DO(tcps_badsyn); 223630fa006SGarrett Wollman DO(tcps_mturesent); 224630fa006SGarrett Wollman DO(tcps_listendrop); 225630fa006SGarrett Wollman #undef DO 226630fa006SGarrett Wollman } 227630fa006SGarrett Wollman 228630fa006SGarrett Wollman void 229630fa006SGarrett Wollman showtcp(void) 230630fa006SGarrett Wollman { 231630fa006SGarrett Wollman struct tcpstat stats; 232630fa006SGarrett Wollman 233630fa006SGarrett Wollman memset(&stats, 0, sizeof stats); 234630fa006SGarrett Wollman domode(&stats); 235630fa006SGarrett Wollman 236630fa006SGarrett Wollman #define DO(stat, row, col) \ 23759003696SJohn Baldwin mvwprintw(wnd, row, col, "%12lu", stats.stat) 238630fa006SGarrett Wollman #define L(row, stat) DO(stat, row, 0) 23959003696SJohn Baldwin #define R(row, stat) DO(stat, row, 38) 2408aa22952SBruce Evans L(1, tcps_connattempt); R(1, tcps_sndtotal); 2418aa22952SBruce Evans L(2, tcps_accepts); R(2, tcps_sndpack); 2428aa22952SBruce Evans L(3, tcps_connects); R(3, tcps_sndrexmitpack); 24302a50a14SJohn Baldwin L(4, tcps_drops); R(4, tcps_sack_rexmits); 24402a50a14SJohn Baldwin L(5, tcps_conndrops); R(5, tcps_sndacks); 24502a50a14SJohn Baldwin L(6, tcps_timeoutdrop); R(6, tcps_sndprobe); 24602a50a14SJohn Baldwin L(7, tcps_keepdrops); R(7, tcps_sndwinup); 24702a50a14SJohn Baldwin L(8, tcps_listendrop); R(8, tcps_sndurg); 24802a50a14SJohn Baldwin R(9, tcps_sndctrl); 24902a50a14SJohn Baldwin R(10, tcps_mturesent); 25002a50a14SJohn Baldwin R(11, tcps_rcvtotal); 25102a50a14SJohn Baldwin L(12, tcps_segstimed); R(12, tcps_rcvpack); 25202a50a14SJohn Baldwin L(13, tcps_rttupdated); R(13, tcps_rcvduppack); 25302a50a14SJohn Baldwin L(14, tcps_delack); R(14, tcps_rcvpartduppack); 25402a50a14SJohn Baldwin L(15, tcps_rexmttimeo); R(15, tcps_rcvoopack); 25502a50a14SJohn Baldwin L(16, tcps_persisttimeo); R(16, tcps_rcvdupack); 25602a50a14SJohn Baldwin L(17, tcps_keepprobe); R(17, tcps_rcvackpack); 25702a50a14SJohn Baldwin L(18, tcps_keeptimeo); R(18, tcps_rcvwinprobe); 25802a50a14SJohn Baldwin R(19, tcps_rcvwinupd); 25902a50a14SJohn Baldwin R(20, tcps_rcvbadsum); 260630fa006SGarrett Wollman #undef DO 261630fa006SGarrett Wollman #undef L 262630fa006SGarrett Wollman #undef R 263630fa006SGarrett Wollman } 264630fa006SGarrett Wollman 265630fa006SGarrett Wollman int 266630fa006SGarrett Wollman inittcp(void) 267630fa006SGarrett Wollman { 268630fa006SGarrett Wollman size_t len; 269630fa006SGarrett Wollman int name[4]; 270630fa006SGarrett Wollman 271630fa006SGarrett Wollman name[0] = CTL_NET; 272630fa006SGarrett Wollman name[1] = PF_INET; 273630fa006SGarrett Wollman name[2] = IPPROTO_TCP; 274630fa006SGarrett Wollman name[3] = TCPCTL_STATS; 275630fa006SGarrett Wollman 276630fa006SGarrett Wollman len = 0; 277630fa006SGarrett Wollman if (sysctl(name, 4, 0, &len, 0, 0) < 0) { 278630fa006SGarrett Wollman error("sysctl getting tcpstat size failed"); 279630fa006SGarrett Wollman return 0; 280630fa006SGarrett Wollman } 281630fa006SGarrett Wollman if (len > sizeof curstat) { 282630fa006SGarrett Wollman error("tcpstat structure has grown--recompile systat!"); 283630fa006SGarrett Wollman return 0; 284630fa006SGarrett Wollman } 285630fa006SGarrett Wollman if (sysctl(name, 4, &initstat, &len, 0, 0) < 0) { 286630fa006SGarrett Wollman error("sysctl getting tcpstat failed"); 287630fa006SGarrett Wollman return 0; 288630fa006SGarrett Wollman } 289630fa006SGarrett Wollman oldstat = initstat; 290630fa006SGarrett Wollman return 1; 291630fa006SGarrett Wollman } 292630fa006SGarrett Wollman 293630fa006SGarrett Wollman void 294630fa006SGarrett Wollman resettcp(void) 295630fa006SGarrett Wollman { 296630fa006SGarrett Wollman size_t len; 297630fa006SGarrett Wollman int name[4]; 298630fa006SGarrett Wollman 299630fa006SGarrett Wollman name[0] = CTL_NET; 300630fa006SGarrett Wollman name[1] = PF_INET; 301630fa006SGarrett Wollman name[2] = IPPROTO_TCP; 302630fa006SGarrett Wollman name[3] = TCPCTL_STATS; 303630fa006SGarrett Wollman 304630fa006SGarrett Wollman len = sizeof initstat; 305630fa006SGarrett Wollman if (sysctl(name, 4, &initstat, &len, 0, 0) < 0) { 306630fa006SGarrett Wollman error("sysctl getting tcpstat failed"); 307630fa006SGarrett Wollman } 308630fa006SGarrett Wollman oldstat = initstat; 309630fa006SGarrett Wollman } 310630fa006SGarrett Wollman 311630fa006SGarrett Wollman void 312630fa006SGarrett Wollman fetchtcp(void) 313630fa006SGarrett Wollman { 314630fa006SGarrett Wollman int name[4]; 315630fa006SGarrett Wollman size_t len; 316630fa006SGarrett Wollman 317630fa006SGarrett Wollman oldstat = curstat; 318630fa006SGarrett Wollman name[0] = CTL_NET; 319630fa006SGarrett Wollman name[1] = PF_INET; 320630fa006SGarrett Wollman name[2] = IPPROTO_TCP; 321630fa006SGarrett Wollman name[3] = TCPCTL_STATS; 322630fa006SGarrett Wollman len = sizeof curstat; 323630fa006SGarrett Wollman 324630fa006SGarrett Wollman if (sysctl(name, 4, &curstat, &len, 0, 0) < 0) 325630fa006SGarrett Wollman return; 326630fa006SGarrett Wollman } 327