2 * Copyright (c) 1980, 1992, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * @(#)mbufs.c 8.1 (Berkeley) 6/6/93
30 * $FreeBSD: src/usr.bin/systat/tcp.c,v 1.3 1999/08/28 01:06:06 peter Exp $
31 * $DragonFly: src/usr.bin/systat/tcp.c,v 1.5 2004/04/07 21:40:19 dillon Exp $
34 #include <sys/param.h>
35 #include <sys/types.h>
36 #include <sys/socket.h>
37 #include <sys/sysctl.h>
39 #include <netinet/in.h>
40 #include <netinet/in_systm.h>
41 #include <netinet/ip.h>
42 #include <netinet/tcp.h>
43 #include <netinet/tcp_seq.h>
44 #include <netinet/tcp_fsm.h>
45 #include <netinet/tcp_timer.h>
46 #include <netinet/tcp_var.h>
55 static struct tcp_stats curstat
, initstat
, oldstat
;
59 --0123456789012345678901234567890123456789012345678901234567890123456789012345
60 01 TCP Connections TCP Packets
61 02999999999 connections initiated 999999999 total packets sent
62 03999999999 connections accepted 999999999 - data
63 04999999999 connections established 999999999 - data (retransmit)
64 05999999999 connections dropped 999999999 - ack-only
65 06999999999 - in embryonic state 999999999 - window probes
66 07999999999 - on retransmit timeout 999999999 - window updates
67 08999999999 - by keepalive 999999999 - urgent data only
68 09999999999 - from listen queue 999999999 - control
69 10 999999999 - resends by PMTU discovery
70 11 TCP Timers 999999999 total packets received
71 12999999999 potential rtt updates 999999999 - in sequence
72 13999999999 - successful 999999999 - completely duplicate
73 14999999999 delayed acks sent 999999999 - with some duplicate data
74 15999999999 retransmit timeouts 999999999 - out-of-order
75 16999999999 persist timeouts 999999999 - duplicate acks
76 17999999999 keepalive probes 999999999 - acks
77 18999999999 - timeouts 999999999 - window probes
78 19 999999999 - window updates
79 --0123456789012345678901234567890123456789012345678901234567890123456789012345
86 return (subwin(stdscr
, LINES
-5-1, 0, 5, 0));
102 wmove(wnd
, 0, 0); wclrtoeol(wnd
);
103 #define L(row, str) mvwprintw(wnd, row, 10, str)
104 #define R(row, str) mvwprintw(wnd, row, 45, str);
105 L(1, "TCP Connections"); R(1, "TCP Packets");
106 L(2, "connections initiated"); R(2, "total packets sent");
107 L(3, "connections accepted"); R(3, "- data");
108 L(4, "connections established"); R(4, "- data (retransmit)");
109 L(5, "connections dropped"); R(5, "- ack-only");
110 L(6, "- in embryonic state"); R(6, "- window probes");
111 L(7, "- on retransmit timeout"); R(7, "- window updates");
112 L(8, "- by keepalive"); R(8, "- urgent data only");
113 L(9, "- from listen queue"); R(9, "- control");
114 R(10, "- resends by PMTU discovery");
115 L(11, "TCP Timers"); R(11, "total packets received");
116 L(12, "potential rtt updates"); R(12, "- in sequence");
117 L(13, "- successful"); R(13, "- completely duplicate");
118 L(14, "delayed acks sent"); R(14, "- with some duplicate data");
119 L(15, "retransmit timeouts"); R(15, "- out-of-order");
120 L(16, "persist timeouts"); R(16, "- duplicate acks");
121 L(17, "keepalive probes"); R(17, "- acks");
122 L(18, "- timeouts"); R(18, "- window probes");
123 R(19, "- window updates");
129 domode(struct tcp_stats
*ret
)
131 const struct tcp_stats
*sub
;
132 double divisor
= 1.0;
134 switch(currentmode
) {
149 #define DO(stat) ret->stat = (double)(curstat.stat - sub->stat) / divisor
150 DO(tcps_connattempt
);
159 DO(tcps_timeoutdrop
);
161 DO(tcps_persisttimeo
);
169 DO(tcps_sndrexmitpack
);
170 DO(tcps_sndrexmitbyte
);
185 DO(tcps_rcvpartduppack
);
186 DO(tcps_rcvpartdupbyte
);
189 DO(tcps_rcvpackafterwin
);
190 DO(tcps_rcvbyteafterwin
);
191 DO(tcps_rcvafterclose
);
192 DO(tcps_rcvwinprobe
);
194 DO(tcps_rcvacktoomuch
);
201 DO(tcps_pcbcachemiss
);
203 DO(tcps_cachedrttvar
);
204 DO(tcps_cachedssthresh
);
207 DO(tcps_usedssthresh
);
208 DO(tcps_persistdrop
);
218 struct tcp_stats stats
;
220 memset(&stats
, 0, sizeof stats
);
223 #define DO(stat, row, col) \
224 mvwprintw(wnd, row, col, "%9lu", stats.stat)
225 #define L(row, stat) DO(stat, row, 0)
226 #define R(row, stat) DO(stat, row, 35)
227 L(2, tcps_connattempt
); R(2, tcps_sndtotal
);
228 L(3, tcps_accepts
); R(3, tcps_sndpack
);
229 L(4, tcps_connects
); R(4, tcps_sndrexmitpack
);
230 L(5, tcps_drops
); R(5, tcps_sndacks
);
231 L(6, tcps_conndrops
); R(6, tcps_sndprobe
);
232 L(7, tcps_timeoutdrop
); R(7, tcps_sndwinup
);
233 L(8, tcps_keepdrops
); R(8, tcps_sndurg
);
234 L(9, tcps_listendrop
); R(9, tcps_sndctrl
);
235 R(10, tcps_mturesent
);
236 R(11, tcps_rcvtotal
);
237 L(12, tcps_segstimed
); R(12, tcps_rcvpack
);
238 L(13, tcps_rttupdated
); R(13, tcps_rcvduppack
);
239 L(14, tcps_delack
); R(14, tcps_rcvpartduppack
);
240 L(15, tcps_rexmttimeo
); R(15, tcps_rcvoopack
);
241 L(16, tcps_persisttimeo
); R(16, tcps_rcvdupack
);
242 L(17, tcps_keepprobe
); R(17, tcps_rcvackpack
);
243 L(18, tcps_keeptimeo
); R(18, tcps_rcvwinprobe
);
244 R(19, tcps_rcvwinupd
);
250 #define CPU_STATS_FUNC(proto,type) \
252 proto ##_stats_agg(type *ary, type *ttl, int cpucnt) \
255 siz = sizeof(type); \
264 for (i = 0; i < cpucnt; ++i) { \
265 for (off = 0; off < siz; off += sizeof(u_long)) { \
266 *(u_long *)((char *)(*(&ttl)) + off) += \
267 *(u_long *)((char *)&ary[i] + off); \
272 CPU_STATS_FUNC(tcp
, struct tcp_stats
);
275 fetch_tcpstats(struct tcp_stats
*st
)
277 struct tcp_stats stattmp
[SMP_MAXCPU
];
283 name
[2] = IPPROTO_TCP
;
284 name
[3] = TCPCTL_STATS
;
286 len
= sizeof(struct tcp_stats
) * SMP_MAXCPU
;
287 if (sysctl(name
, 4, stattmp
, &len
, NULL
, 0) < 0) {
288 error("sysctl getting tcp_stats failed");
291 cpucnt
= len
/ sizeof(struct tcp_stats
);
292 tcp_stats_agg(stattmp
, st
, cpucnt
);
300 fetch_tcpstats(&initstat
);
309 fetch_tcpstats(&initstat
);
317 fetch_tcpstats(&curstat
);