tcp.c revision 1.5 1 /* $NetBSD: tcp.c,v 1.5 2000/04/29 04:36:16 matt Exp $ */
2
3 /*
4 * Copyright (c) 1999 Andy Doran <ad (at) NetBSD.org>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 *
28 */
29
30 #include <sys/cdefs.h>
31 #ifndef lint
32 __RCSID("$NetBSD: tcp.c,v 1.5 2000/04/29 04:36:16 matt Exp $");
33 #endif /* not lint */
34
35 #include <sys/param.h>
36 #include <sys/types.h>
37 #include <sys/socket.h>
38 #include <sys/sysctl.h>
39
40 #include <netinet/in.h>
41 #include <netinet/in_systm.h>
42 #include <netinet/ip.h>
43 #include <netinet/ip_var.h>
44 #include <netinet/tcp.h>
45 #include <netinet/tcp_seq.h>
46 #include <netinet/tcp_fsm.h>
47 #include <netinet/tcp_timer.h>
48 #include <netinet/tcp_var.h>
49
50 #include <stdlib.h>
51 #include <string.h>
52 #include <paths.h>
53 #include <nlist.h>
54 #include <kvm.h>
55
56 #include "systat.h"
57 #include "extern.h"
58
59 #define LHD(row, str) mvwprintw(wnd, row, 10, str)
60 #define RHD(row, str) mvwprintw(wnd, row, 45, str)
61 #define SHOW(row, col, stat) mvwprintw(wnd, row, col, "%9llu", (unsigned long long) curstat.stat)
62
63 static struct tcpstat curstat, oldstat;
64
65 static struct nlist namelist[] = {
66 { "_tcpstat" },
67 { "" }
68 };
69
70 WINDOW *
71 opentcp(void)
72 {
73
74 return (subwin(stdscr, LINES-5-1, 0, 5, 0));
75 }
76
77 void
78 closetcp(w)
79 WINDOW *w;
80 {
81
82 if (w != NULL) {
83 wclear(w);
84 wrefresh(w);
85 delwin(w);
86 }
87 }
88
89 void
90 labeltcp(void)
91 {
92
93 wmove(wnd, 0, 0); wclrtoeol(wnd);
94
95 LHD(0, "connections initiated");
96 LHD(1, "connections accepted");
97 LHD(2, "connections established");
98
99 LHD(4, "connections dropped");
100 LHD(5, " in embryonic state");
101 LHD(6, " on retransmit timeout");
102 LHD(7, " by keepalive");
103 LHD(8, " by persist");
104
105 LHD(10, "potential rtt updates");
106 LHD(11, "successful rtt updates");
107 LHD(12, "delayed acks sent");
108 LHD(13, "retransmit timeouts");
109 LHD(14, "persist timeouts");
110 LHD(15, "keepalive probes");
111 LHD(16, "keepalive timeouts");
112
113 RHD(9, "total TCP packets received");
114 RHD(10, " in sequence");
115 RHD(11, " completely duplicate");
116 RHD(12, " with some duplicate data");
117 RHD(13, " out of order");
118 RHD(14, " duplicate acks");
119 RHD(15, " acks");
120 RHD(16, " window probes");
121 RHD(17, " window updates");
122
123 RHD(0, "total TCP packets sent");
124 RHD(1, " data");
125 RHD(2, " data (retransmit)");
126 RHD(3, " ack-only");
127 RHD(4, " window probes");
128 RHD(5, " window updates");
129 RHD(6, " urgent data only");
130 RHD(7, " control");
131 }
132
133 void
134 showtcpsyn(void)
135 {
136
137 SHOW(0, 0, tcps_sc_added);
138 SHOW(1, 0, tcps_sc_completed);
139 SHOW(2, 0, tcps_sc_timed_out);
140 SHOW(3, 0, tcps_sc_dupesyn);
141 SHOW(4, 0, tcps_sc_collisions);
142 SHOW(5, 0, tcps_sc_retransmitted);
143 SHOW(6, 0, tcps_sc_aborted);
144 SHOW(7, 0, tcps_sc_overflowed);
145 SHOW(8, 0, tcps_sc_reset);
146 SHOW(9, 0, tcps_sc_unreach);
147 SHOW(10, 0, tcps_sc_bucketoverflow);
148 SHOW(11, 0, tcps_sc_dropped);
149 }
150
151 void
152 labeltcpsyn(void)
153 {
154
155 wmove(wnd, 0, 0); wclrtoeol(wnd);
156 LHD(0, "entries added");
157 LHD(1, "connections completed");
158 LHD(2, "entries timed out");
159 LHD(3, "duplicate SYNs recieved");
160 LHD(4, "hash collisions");
161 LHD(5, "retransmissions");
162 LHD(6, "entries aborted (no memory)");
163 LHD(7, "dropped (overflow)");
164 LHD(8, "dropped (RST)");
165 LHD(9, "dropped (ICMP UNRCH)");
166 LHD(10, "dropped (bucket overflow)");
167 LHD(11, "dropped (unreachable/no memory)");
168 }
169
170 void
171 showtcp(void)
172 {
173
174 SHOW(0, 0, tcps_connattempt);
175 SHOW(1, 0, tcps_accepts);
176 SHOW(2, 0, tcps_connects);
177
178 SHOW(4, 0, tcps_drops);
179 SHOW(5, 0, tcps_conndrops);
180 SHOW(6, 0, tcps_timeoutdrop);
181 SHOW(7, 0, tcps_keepdrops);
182 SHOW(8, 0, tcps_persistdrops);
183
184 SHOW(10, 0, tcps_segstimed);
185 SHOW(11, 0, tcps_rttupdated);
186 SHOW(12, 0, tcps_delack);
187 SHOW(13, 0, tcps_rexmttimeo);
188 SHOW(14, 0, tcps_persisttimeo);
189 SHOW(15, 0, tcps_keepprobe);
190 SHOW(16, 0, tcps_keeptimeo);
191
192 SHOW(0, 35, tcps_sndtotal);
193 SHOW(1, 35, tcps_sndpack);
194 SHOW(2, 35, tcps_sndrexmitpack);
195
196 SHOW(3, 35, tcps_sndacks);
197 SHOW(4, 35, tcps_sndprobe);
198 SHOW(5, 35, tcps_sndwinup);
199 SHOW(6, 35, tcps_sndurg);
200 SHOW(7, 35, tcps_sndctrl);
201
202 SHOW(9, 35, tcps_rcvtotal);
203 SHOW(10, 35, tcps_rcvpack);
204 SHOW(11, 35, tcps_rcvduppack);
205 SHOW(12, 35, tcps_rcvpartduppack);
206 SHOW(13, 35, tcps_rcvoopack);
207 SHOW(14, 35, tcps_rcvdupack);
208 SHOW(15, 35, tcps_rcvackpack);
209 SHOW(16, 35, tcps_rcvwinprobe);
210 SHOW(17, 35, tcps_rcvwinupd);
211 }
212
213 int
214 inittcp(void)
215 {
216
217 if (namelist[0].n_type == 0) {
218 if (kvm_nlist(kd, namelist)) {
219 nlisterr(namelist);
220 return(0);
221 }
222 if (namelist[0].n_type == 0) {
223 error("No namelist");
224 return(0);
225 }
226 }
227 return 1;
228 }
229
230 void
231 fetchtcp(void)
232 {
233
234 oldstat = curstat;
235 KREAD((void *)namelist[0].n_value, &curstat, sizeof(curstat));
236 }
237