tcp.c revision 29881
129881Swollman/*- 229881Swollman * Copyright (c) 1980, 1992, 1993 329881Swollman * The Regents of the University of California. All rights reserved. 429881Swollman * 529881Swollman * Redistribution and use in source and binary forms, with or without 629881Swollman * modification, are permitted provided that the following conditions 729881Swollman * are met: 829881Swollman * 1. Redistributions of source code must retain the above copyright 929881Swollman * notice, this list of conditions and the following disclaimer. 1029881Swollman * 2. Redistributions in binary form must reproduce the above copyright 1129881Swollman * notice, this list of conditions and the following disclaimer in the 1229881Swollman * documentation and/or other materials provided with the distribution. 1329881Swollman * 3. All advertising materials mentioning features or use of this software 1429881Swollman * must display the following acknowledgement: 1529881Swollman * This product includes software developed by the University of 1629881Swollman * California, Berkeley and its contributors. 1729881Swollman * 4. Neither the name of the University nor the names of its contributors 1829881Swollman * may be used to endorse or promote products derived from this software 1929881Swollman * without specific prior written permission. 2029881Swollman * 2129881Swollman * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2229881Swollman * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2329881Swollman * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2429881Swollman * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2529881Swollman * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2629881Swollman * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2729881Swollman * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2829881Swollman * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2929881Swollman * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3029881Swollman * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3129881Swollman * SUCH DAMAGE. 3229881Swollman */ 3329881Swollman 3429881Swollman#ifndef lint 3529881Swollman/* From: 3629881Swollmanstatic char sccsid[] = "@(#)mbufs.c 8.1 (Berkeley) 6/6/93"; 3729881Swollmanstatic const char rcsid[] = 3829881Swollman "Id: mbufs.c,v 1.5 1997/02/24 20:59:03 wollman Exp"; 3929881Swollman*/ 4029881Swollmanstatic const char rcsid[] = 4129881Swollman "$Id: icmp.c,v 1.1 1997/09/24 02:43:39 wollman Exp $"; 4229881Swollman#endif /* not lint */ 4329881Swollman 4429881Swollman#include <sys/param.h> 4529881Swollman#include <sys/types.h> 4629881Swollman#include <sys/socket.h> 4729881Swollman#include <sys/sysctl.h> 4829881Swollman 4929881Swollman#include <netinet/in.h> 5029881Swollman#include <netinet/in_systm.h> 5129881Swollman#include <netinet/ip.h> 5229881Swollman#include <netinet/tcp.h> 5329881Swollman#include <netinet/tcp_seq.h> 5429881Swollman#include <netinet/tcp_fsm.h> 5529881Swollman#include <netinet/tcp_timer.h> 5629881Swollman#include <netinet/tcp_var.h> 5729881Swollman 5829881Swollman#include <stdlib.h> 5929881Swollman#include <string.h> 6029881Swollman#include <paths.h> 6129881Swollman#include "systat.h" 6229881Swollman#include "extern.h" 6329881Swollman#include "mode.h" 6429881Swollman 6529881Swollmanstatic struct tcpstat curstat, initstat, oldstat; 6629881Swollman 6729881Swollman/*- 6829881Swollman--0 1 2 3 4 5 6 7 6929881Swollman--0123456789012345678901234567890123456789012345678901234567890123456789012345 7029881Swollman01 TCP Connections TCP Packets 7129881Swollman02999999999 connections initiated 999999999 total packets sent 7229881Swollman03999999999 connections accepted 999999999 - data 7329881Swollman04999999999 connections established 999999999 - data (retransmit) 7429881Swollman05999999999 connections dropped 999999999 - ack-only 7529881Swollman06999999999 - in embryonic state 999999999 - window probes 7629881Swollman07999999999 - on retransmit timeout 999999999 - window updates 7729881Swollman08999999999 - by keepalive 999999999 - urgent data only 7829881Swollman09999999999 - from listen queue 999999999 - control 7929881Swollman10 999999999 - resends by PMTU discovery 8029881Swollman11 TCP Timers 999999999 total packets received 8129881Swollman12999999999 potential rtt updates 999999999 - in sequence 8229881Swollman13999999999 - successful 999999999 - completely duplicate 8329881Swollman14999999999 delayed acks sent 999999999 - with some duplicate data 8429881Swollman15999999999 retransmit timeouts 999999999 - out-of-order 8529881Swollman16999999999 persist timeouts 999999999 - duplicate acks 8629881Swollman17999999999 keepalive probes 999999999 - acks 8729881Swollman18999999999 - timeouts 999999999 - window probes 8829881Swollman19 999999999 - window updates 8929881Swollman--0123456789012345678901234567890123456789012345678901234567890123456789012345 9029881Swollman--0 1 2 3 4 5 6 7 9129881Swollman*/ 9229881Swollman 9329881SwollmanWINDOW * 9429881Swollmanopentcp(void) 9529881Swollman{ 9629881Swollman return (subwin(stdscr, LINES-5-1, 0, 5, 0)); 9729881Swollman} 9829881Swollman 9929881Swollmanvoid 10029881Swollmanclosetcp(w) 10129881Swollman WINDOW *w; 10229881Swollman{ 10329881Swollman if (w == NULL) 10429881Swollman return; 10529881Swollman wclear(w); 10629881Swollman wrefresh(w); 10729881Swollman delwin(w); 10829881Swollman} 10929881Swollman 11029881Swollmanvoid 11129881Swollmanlabeltcp(void) 11229881Swollman{ 11329881Swollman wmove(wnd, 0, 0); wclrtoeol(wnd); 11429881Swollman#define L(row, str) mvwprintw(wnd, row, 10, str) 11529881Swollman#define R(row, str) mvwprintw(wnd, row, 45, str); 11629881Swollman L(1, "TCP Connections"); R(1, "TCP Packets"); 11729881Swollman L(2, "connections initiated"); R(2, "total packets sent"); 11829881Swollman L(3, "connections accepted"); R(3, "- data"); 11929881Swollman L(4, "connections established"); R(4, "- data (retransmit)"); 12029881Swollman L(5, "connections dropped"); R(5, "- ack-only"); 12129881Swollman L(6, "- in embryonic state"); R(6, "- window probes"); 12229881Swollman L(7, "- on retransmit timeout"); R(7, "- window updates"); 12329881Swollman L(8, "- by keepalive"); R(8, "- urgent data only"); 12429881Swollman L(9, "- from listen queue"); R(9, "- control"); 12529881Swollman R(10, "- resends by PMTU discovery"); 12629881Swollman L(11, "TCP Timers"); R(11, "total packets received"); 12729881Swollman L(12, "potential rtt updates"); R(12, "- in sequence"); 12829881Swollman L(13, "- successful"); R(13, "- completely duplicate"); 12929881Swollman L(14, "delayed acks sent"); R(14, "- with some duplicate data"); 13029881Swollman L(15, "retransmit timeouts"); R(15, "- out-of-order"); 13129881Swollman L(16, "persist timeouts"); R(16, "- duplicate acks"); 13229881Swollman L(17, "keepalive probes"); R(17, "- acks"); 13329881Swollman L(18, "- timeouts"); R(18, "- window probes"); 13429881Swollman R(19, "- window updates"); 13529881Swollman#undef L 13629881Swollman#undef R 13729881Swollman} 13829881Swollman 13929881Swollmanstatic void 14029881Swollmandomode(struct tcpstat *ret) 14129881Swollman{ 14229881Swollman const struct tcpstat *sub; 14329881Swollman int i, divisor = 1; 14429881Swollman 14529881Swollman switch(currentmode) { 14629881Swollman case display_RATE: 14729881Swollman sub = &oldstat; 14829881Swollman divisor = naptime; 14929881Swollman break; 15029881Swollman case display_DELTA: 15129881Swollman sub = &oldstat; 15229881Swollman break; 15329881Swollman case display_SINCE: 15429881Swollman sub = &initstat; 15529881Swollman break; 15629881Swollman default: 15729881Swollman *ret = curstat; 15829881Swollman return; 15929881Swollman } 16029881Swollman#define DO(stat) ret->stat = (curstat.stat - sub->stat) / divisor 16129881Swollman DO(tcps_connattempt); 16229881Swollman DO(tcps_accepts); 16329881Swollman DO(tcps_connects); 16429881Swollman DO(tcps_drops); 16529881Swollman DO(tcps_conndrops); 16629881Swollman DO(tcps_closed); 16729881Swollman DO(tcps_segstimed); 16829881Swollman DO(tcps_rttupdated); 16929881Swollman DO(tcps_delack); 17029881Swollman DO(tcps_timeoutdrop); 17129881Swollman DO(tcps_rexmttimeo); 17229881Swollman DO(tcps_persisttimeo); 17329881Swollman DO(tcps_keeptimeo); 17429881Swollman DO(tcps_keepprobe); 17529881Swollman DO(tcps_keepdrops); 17629881Swollman 17729881Swollman DO(tcps_sndtotal); 17829881Swollman DO(tcps_sndpack); 17929881Swollman DO(tcps_sndbyte); 18029881Swollman DO(tcps_sndrexmitpack); 18129881Swollman DO(tcps_sndrexmitbyte); 18229881Swollman DO(tcps_sndacks); 18329881Swollman DO(tcps_sndprobe); 18429881Swollman DO(tcps_sndurg); 18529881Swollman DO(tcps_sndwinup); 18629881Swollman DO(tcps_sndctrl); 18729881Swollman 18829881Swollman DO(tcps_rcvtotal); 18929881Swollman DO(tcps_rcvpack); 19029881Swollman DO(tcps_rcvbyte); 19129881Swollman DO(tcps_rcvbadsum); 19229881Swollman DO(tcps_rcvbadoff); 19329881Swollman DO(tcps_rcvshort); 19429881Swollman DO(tcps_rcvduppack); 19529881Swollman DO(tcps_rcvdupbyte); 19629881Swollman DO(tcps_rcvpartduppack); 19729881Swollman DO(tcps_rcvpartdupbyte); 19829881Swollman DO(tcps_rcvoopack); 19929881Swollman DO(tcps_rcvoobyte); 20029881Swollman DO(tcps_rcvpackafterwin); 20129881Swollman DO(tcps_rcvbyteafterwin); 20229881Swollman DO(tcps_rcvafterclose); 20329881Swollman DO(tcps_rcvwinprobe); 20429881Swollman DO(tcps_rcvdupack); 20529881Swollman DO(tcps_rcvacktoomuch); 20629881Swollman DO(tcps_rcvackpack); 20729881Swollman DO(tcps_rcvackbyte); 20829881Swollman DO(tcps_rcvwinupd); 20929881Swollman DO(tcps_pawsdrop); 21029881Swollman DO(tcps_predack); 21129881Swollman DO(tcps_preddat); 21229881Swollman DO(tcps_pcbcachemiss); 21329881Swollman DO(tcps_cachedrtt); 21429881Swollman DO(tcps_cachedrttvar); 21529881Swollman DO(tcps_cachedssthresh); 21629881Swollman DO(tcps_usedrtt); 21729881Swollman DO(tcps_usedrttvar); 21829881Swollman DO(tcps_usedssthresh); 21929881Swollman DO(tcps_persistdrop); 22029881Swollman DO(tcps_badsyn); 22129881Swollman DO(tcps_mturesent); 22229881Swollman DO(tcps_listendrop); 22329881Swollman#undef DO 22429881Swollman} 22529881Swollman 22629881Swollmanvoid 22729881Swollmanshowtcp(void) 22829881Swollman{ 22929881Swollman struct tcpstat stats; 23029881Swollman 23129881Swollman memset(&stats, 0, sizeof stats); 23229881Swollman domode(&stats); 23329881Swollman 23429881Swollman#define DO(stat, row, col) \ 23529881Swollman mvwprintw(wnd, row, col, "%9lu", stats.stat) 23629881Swollman#define L(row, stat) DO(stat, row, 0) 23729881Swollman#define R(row, stat) DO(stat, row, 35) 23829881Swollman L(2, tcps_connattempt); R(2, tcps_sndtotal); 23929881Swollman L(3, tcps_accepts); R(3, tcps_sndpack); 24029881Swollman L(4, tcps_connects); R(4, tcps_sndrexmitpack); 24129881Swollman L(5, tcps_drops); R(5, tcps_sndacks); 24229881Swollman L(6, tcps_conndrops); R(6, tcps_sndprobe); 24329881Swollman L(7, tcps_timeoutdrop); R(7, tcps_sndwinup); 24429881Swollman L(8, tcps_keepdrops); R(8, tcps_sndurg); 24529881Swollman L(9, tcps_listendrop); R(9, tcps_sndctrl); 24629881Swollman R(10, tcps_mturesent); 24729881Swollman R(11, tcps_rcvtotal); 24829881Swollman L(12, tcps_segstimed); R(12, tcps_rcvpack); 24929881Swollman L(13, tcps_rttupdated); R(13, tcps_rcvduppack); 25029881Swollman L(14, tcps_delack); R(14, tcps_rcvpartduppack); 25129881Swollman L(15, tcps_rexmttimeo); R(15, tcps_rcvoopack); 25229881Swollman L(16, tcps_persisttimeo); R(16, tcps_rcvdupack); 25329881Swollman L(17, tcps_keepprobe); R(17, tcps_rcvackpack); 25429881Swollman L(18, tcps_keeptimeo); R(18, tcps_rcvwinprobe); 25529881Swollman R(19, tcps_rcvwinupd); 25629881Swollman#undef DO 25729881Swollman#undef L 25829881Swollman#undef R 25929881Swollman} 26029881Swollman 26129881Swollmanint 26229881Swollmaninittcp(void) 26329881Swollman{ 26429881Swollman size_t len; 26529881Swollman int name[4]; 26629881Swollman 26729881Swollman name[0] = CTL_NET; 26829881Swollman name[1] = PF_INET; 26929881Swollman name[2] = IPPROTO_TCP; 27029881Swollman name[3] = TCPCTL_STATS; 27129881Swollman 27229881Swollman len = 0; 27329881Swollman if (sysctl(name, 4, 0, &len, 0, 0) < 0) { 27429881Swollman error("sysctl getting tcpstat size failed"); 27529881Swollman return 0; 27629881Swollman } 27729881Swollman if (len > sizeof curstat) { 27829881Swollman error("tcpstat structure has grown--recompile systat!"); 27929881Swollman return 0; 28029881Swollman } 28129881Swollman if (sysctl(name, 4, &initstat, &len, 0, 0) < 0) { 28229881Swollman error("sysctl getting tcpstat failed"); 28329881Swollman return 0; 28429881Swollman } 28529881Swollman oldstat = initstat; 28629881Swollman return 1; 28729881Swollman} 28829881Swollman 28929881Swollmanvoid 29029881Swollmanresettcp(void) 29129881Swollman{ 29229881Swollman size_t len; 29329881Swollman int name[4]; 29429881Swollman 29529881Swollman name[0] = CTL_NET; 29629881Swollman name[1] = PF_INET; 29729881Swollman name[2] = IPPROTO_TCP; 29829881Swollman name[3] = TCPCTL_STATS; 29929881Swollman 30029881Swollman len = sizeof initstat; 30129881Swollman if (sysctl(name, 4, &initstat, &len, 0, 0) < 0) { 30229881Swollman error("sysctl getting tcpstat failed"); 30329881Swollman } 30429881Swollman oldstat = initstat; 30529881Swollman} 30629881Swollman 30729881Swollmanvoid 30829881Swollmanfetchtcp(void) 30929881Swollman{ 31029881Swollman int name[4]; 31129881Swollman size_t len; 31229881Swollman 31329881Swollman oldstat = curstat; 31429881Swollman name[0] = CTL_NET; 31529881Swollman name[1] = PF_INET; 31629881Swollman name[2] = IPPROTO_TCP; 31729881Swollman name[3] = TCPCTL_STATS; 31829881Swollman len = sizeof curstat; 31929881Swollman 32029881Swollman if (sysctl(name, 4, &curstat, &len, 0, 0) < 0) 32129881Swollman return; 32229881Swollman} 32329881Swollman 324