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