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