tcp.c revision 1.11 1 1.11 dsl /* $NetBSD: tcp.c,v 1.11 2005/02/26 22:12:34 dsl Exp $ */
2 1.1 ad
3 1.1 ad /*
4 1.7 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.11 dsl __RCSID("$NetBSD: tcp.c,v 1.11 2005/02/26 22:12:34 dsl 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/sysctl.h>
37 1.1 ad
38 1.1 ad #include <netinet/in.h>
39 1.1 ad #include <netinet/in_systm.h>
40 1.1 ad #include <netinet/ip.h>
41 1.1 ad #include <netinet/ip_var.h>
42 1.1 ad #include <netinet/tcp.h>
43 1.1 ad #include <netinet/tcp_timer.h>
44 1.1 ad #include <netinet/tcp_var.h>
45 1.1 ad
46 1.1 ad #include <string.h>
47 1.3 ad
48 1.1 ad #include "systat.h"
49 1.1 ad #include "extern.h"
50 1.1 ad
51 1.1 ad #define LHD(row, str) mvwprintw(wnd, row, 10, str)
52 1.1 ad #define RHD(row, str) mvwprintw(wnd, row, 45, str)
53 1.7 ad #define SHOW(row, col, stat) \
54 1.7 ad mvwprintw(wnd, row, col, "%9llu", (unsigned long long)curstat.stat)
55 1.1 ad
56 1.7 ad enum update {
57 1.7 ad UPDATE_TIME,
58 1.7 ad UPDATE_BOOT,
59 1.7 ad UPDATE_RUN,
60 1.7 ad };
61 1.7 ad
62 1.7 ad static enum update update = UPDATE_TIME;
63 1.7 ad static struct tcpstat curstat;
64 1.7 ad static struct tcpstat newstat;
65 1.7 ad static struct tcpstat oldstat;
66 1.1 ad
67 1.1 ad static struct nlist namelist[] = {
68 1.1 ad { "_tcpstat" },
69 1.1 ad { "" }
70 1.1 ad };
71 1.1 ad
72 1.1 ad WINDOW *
73 1.1 ad opentcp(void)
74 1.1 ad {
75 1.1 ad
76 1.10 dsl return (subwin(stdscr, -1, 0, 5, 0));
77 1.1 ad }
78 1.1 ad
79 1.1 ad void
80 1.7 ad closetcp(WINDOW *w)
81 1.1 ad {
82 1.1 ad
83 1.1 ad if (w != NULL) {
84 1.1 ad wclear(w);
85 1.1 ad wrefresh(w);
86 1.1 ad delwin(w);
87 1.1 ad }
88 1.1 ad }
89 1.1 ad
90 1.1 ad void
91 1.1 ad labeltcp(void)
92 1.1 ad {
93 1.2 ad
94 1.1 ad wmove(wnd, 0, 0); wclrtoeol(wnd);
95 1.1 ad
96 1.1 ad LHD(0, "connections initiated");
97 1.1 ad LHD(1, "connections accepted");
98 1.1 ad LHD(2, "connections established");
99 1.1 ad
100 1.1 ad LHD(4, "connections dropped");
101 1.1 ad LHD(5, " in embryonic state");
102 1.1 ad LHD(6, " on retransmit timeout");
103 1.1 ad LHD(7, " by keepalive");
104 1.1 ad LHD(8, " by persist");
105 1.1 ad
106 1.1 ad LHD(10, "potential rtt updates");
107 1.1 ad LHD(11, "successful rtt updates");
108 1.1 ad LHD(12, "delayed acks sent");
109 1.1 ad LHD(13, "retransmit timeouts");
110 1.1 ad LHD(14, "persist timeouts");
111 1.1 ad LHD(15, "keepalive probes");
112 1.1 ad LHD(16, "keepalive timeouts");
113 1.1 ad
114 1.1 ad RHD(9, "total TCP packets received");
115 1.1 ad RHD(10, " in sequence");
116 1.1 ad RHD(11, " completely duplicate");
117 1.1 ad RHD(12, " with some duplicate data");
118 1.1 ad RHD(13, " out of order");
119 1.1 ad RHD(14, " duplicate acks");
120 1.1 ad RHD(15, " acks");
121 1.1 ad RHD(16, " window probes");
122 1.1 ad RHD(17, " window updates");
123 1.1 ad
124 1.1 ad RHD(0, "total TCP packets sent");
125 1.1 ad RHD(1, " data");
126 1.1 ad RHD(2, " data (retransmit)");
127 1.1 ad RHD(3, " ack-only");
128 1.1 ad RHD(4, " window probes");
129 1.1 ad RHD(5, " window updates");
130 1.1 ad RHD(6, " urgent data only");
131 1.1 ad RHD(7, " control");
132 1.1 ad }
133 1.1 ad
134 1.1 ad void
135 1.1 ad showtcpsyn(void)
136 1.1 ad {
137 1.1 ad
138 1.1 ad SHOW(0, 0, tcps_sc_added);
139 1.1 ad SHOW(1, 0, tcps_sc_completed);
140 1.1 ad SHOW(2, 0, tcps_sc_timed_out);
141 1.1 ad SHOW(3, 0, tcps_sc_dupesyn);
142 1.1 ad SHOW(4, 0, tcps_sc_collisions);
143 1.1 ad SHOW(5, 0, tcps_sc_retransmitted);
144 1.1 ad SHOW(6, 0, tcps_sc_aborted);
145 1.1 ad SHOW(7, 0, tcps_sc_overflowed);
146 1.1 ad SHOW(8, 0, tcps_sc_reset);
147 1.1 ad SHOW(9, 0, tcps_sc_unreach);
148 1.1 ad SHOW(10, 0, tcps_sc_bucketoverflow);
149 1.1 ad SHOW(11, 0, tcps_sc_dropped);
150 1.1 ad }
151 1.1 ad
152 1.1 ad void
153 1.1 ad labeltcpsyn(void)
154 1.1 ad {
155 1.1 ad
156 1.1 ad wmove(wnd, 0, 0); wclrtoeol(wnd);
157 1.1 ad LHD(0, "entries added");
158 1.1 ad LHD(1, "connections completed");
159 1.1 ad LHD(2, "entries timed out");
160 1.9 wiz LHD(3, "duplicate SYNs received");
161 1.1 ad LHD(4, "hash collisions");
162 1.1 ad LHD(5, "retransmissions");
163 1.1 ad LHD(6, "entries aborted (no memory)");
164 1.1 ad LHD(7, "dropped (overflow)");
165 1.1 ad LHD(8, "dropped (RST)");
166 1.1 ad LHD(9, "dropped (ICMP UNRCH)");
167 1.1 ad LHD(10, "dropped (bucket overflow)");
168 1.1 ad LHD(11, "dropped (unreachable/no memory)");
169 1.1 ad }
170 1.1 ad
171 1.1 ad void
172 1.1 ad showtcp(void)
173 1.1 ad {
174 1.1 ad
175 1.1 ad SHOW(0, 0, tcps_connattempt);
176 1.1 ad SHOW(1, 0, tcps_accepts);
177 1.1 ad SHOW(2, 0, tcps_connects);
178 1.1 ad
179 1.1 ad SHOW(4, 0, tcps_drops);
180 1.1 ad SHOW(5, 0, tcps_conndrops);
181 1.1 ad SHOW(6, 0, tcps_timeoutdrop);
182 1.1 ad SHOW(7, 0, tcps_keepdrops);
183 1.1 ad SHOW(8, 0, tcps_persistdrops);
184 1.1 ad
185 1.1 ad SHOW(10, 0, tcps_segstimed);
186 1.1 ad SHOW(11, 0, tcps_rttupdated);
187 1.1 ad SHOW(12, 0, tcps_delack);
188 1.1 ad SHOW(13, 0, tcps_rexmttimeo);
189 1.1 ad SHOW(14, 0, tcps_persisttimeo);
190 1.1 ad SHOW(15, 0, tcps_keepprobe);
191 1.1 ad SHOW(16, 0, tcps_keeptimeo);
192 1.1 ad
193 1.1 ad SHOW(0, 35, tcps_sndtotal);
194 1.1 ad SHOW(1, 35, tcps_sndpack);
195 1.1 ad SHOW(2, 35, tcps_sndrexmitpack);
196 1.1 ad
197 1.1 ad SHOW(3, 35, tcps_sndacks);
198 1.1 ad SHOW(4, 35, tcps_sndprobe);
199 1.1 ad SHOW(5, 35, tcps_sndwinup);
200 1.1 ad SHOW(6, 35, tcps_sndurg);
201 1.1 ad SHOW(7, 35, tcps_sndctrl);
202 1.1 ad
203 1.1 ad SHOW(9, 35, tcps_rcvtotal);
204 1.1 ad SHOW(10, 35, tcps_rcvpack);
205 1.1 ad SHOW(11, 35, tcps_rcvduppack);
206 1.1 ad SHOW(12, 35, tcps_rcvpartduppack);
207 1.1 ad SHOW(13, 35, tcps_rcvoopack);
208 1.1 ad SHOW(14, 35, tcps_rcvdupack);
209 1.1 ad SHOW(15, 35, tcps_rcvackpack);
210 1.1 ad SHOW(16, 35, tcps_rcvwinprobe);
211 1.1 ad SHOW(17, 35, tcps_rcvwinupd);
212 1.1 ad }
213 1.1 ad
214 1.1 ad int
215 1.1 ad inittcp(void)
216 1.1 ad {
217 1.2 ad
218 1.1 ad if (namelist[0].n_type == 0) {
219 1.1 ad if (kvm_nlist(kd, namelist)) {
220 1.1 ad nlisterr(namelist);
221 1.1 ad return(0);
222 1.1 ad }
223 1.1 ad if (namelist[0].n_type == 0) {
224 1.1 ad error("No namelist");
225 1.1 ad return(0);
226 1.1 ad }
227 1.1 ad }
228 1.1 ad return 1;
229 1.1 ad }
230 1.1 ad
231 1.1 ad void
232 1.1 ad fetchtcp(void)
233 1.1 ad {
234 1.2 ad
235 1.7 ad KREAD((void *)namelist[0].n_value, &newstat, sizeof(newstat));
236 1.7 ad
237 1.7 ad ADJINETCTR(curstat, oldstat, newstat, tcps_connattempt);
238 1.7 ad ADJINETCTR(curstat, oldstat, newstat, tcps_accepts);
239 1.7 ad ADJINETCTR(curstat, oldstat, newstat, tcps_connects);
240 1.7 ad ADJINETCTR(curstat, oldstat, newstat, tcps_drops);
241 1.7 ad ADJINETCTR(curstat, oldstat, newstat, tcps_conndrops);
242 1.7 ad ADJINETCTR(curstat, oldstat, newstat, tcps_timeoutdrop);
243 1.7 ad ADJINETCTR(curstat, oldstat, newstat, tcps_keepdrops);
244 1.7 ad ADJINETCTR(curstat, oldstat, newstat, tcps_persistdrops);
245 1.7 ad ADJINETCTR(curstat, oldstat, newstat, tcps_segstimed);
246 1.7 ad ADJINETCTR(curstat, oldstat, newstat, tcps_rttupdated);
247 1.7 ad ADJINETCTR(curstat, oldstat, newstat, tcps_delack);
248 1.7 ad ADJINETCTR(curstat, oldstat, newstat, tcps_rexmttimeo);
249 1.7 ad ADJINETCTR(curstat, oldstat, newstat, tcps_persisttimeo);
250 1.7 ad ADJINETCTR(curstat, oldstat, newstat, tcps_keepprobe);
251 1.7 ad ADJINETCTR(curstat, oldstat, newstat, tcps_keeptimeo);
252 1.7 ad ADJINETCTR(curstat, oldstat, newstat, tcps_sndtotal);
253 1.7 ad ADJINETCTR(curstat, oldstat, newstat, tcps_sndpack);
254 1.7 ad ADJINETCTR(curstat, oldstat, newstat, tcps_sndrexmitpack);
255 1.7 ad ADJINETCTR(curstat, oldstat, newstat, tcps_sndacks);
256 1.7 ad ADJINETCTR(curstat, oldstat, newstat, tcps_sndprobe);
257 1.7 ad ADJINETCTR(curstat, oldstat, newstat, tcps_sndwinup);
258 1.7 ad ADJINETCTR(curstat, oldstat, newstat, tcps_sndurg);
259 1.7 ad ADJINETCTR(curstat, oldstat, newstat, tcps_sndctrl);
260 1.7 ad ADJINETCTR(curstat, oldstat, newstat, tcps_rcvtotal);
261 1.7 ad ADJINETCTR(curstat, oldstat, newstat, tcps_rcvpack);
262 1.7 ad ADJINETCTR(curstat, oldstat, newstat, tcps_rcvduppack);
263 1.7 ad ADJINETCTR(curstat, oldstat, newstat, tcps_rcvpartduppack);
264 1.7 ad ADJINETCTR(curstat, oldstat, newstat, tcps_rcvoopack);
265 1.7 ad ADJINETCTR(curstat, oldstat, newstat, tcps_rcvdupack);
266 1.7 ad ADJINETCTR(curstat, oldstat, newstat, tcps_rcvackpack);
267 1.7 ad ADJINETCTR(curstat, oldstat, newstat, tcps_rcvwinprobe);
268 1.7 ad ADJINETCTR(curstat, oldstat, newstat, tcps_rcvwinupd);
269 1.7 ad
270 1.7 ad if (update == UPDATE_TIME)
271 1.7 ad memcpy(&oldstat, &newstat, sizeof(oldstat));
272 1.7 ad }
273 1.7 ad
274 1.7 ad void
275 1.7 ad tcp_boot(char *args)
276 1.7 ad {
277 1.7 ad
278 1.7 ad memset(&oldstat, 0, sizeof(oldstat));
279 1.7 ad update = UPDATE_BOOT;
280 1.7 ad }
281 1.7 ad
282 1.7 ad void
283 1.7 ad tcp_run(char *args)
284 1.7 ad {
285 1.7 ad
286 1.7 ad if (update != UPDATE_RUN) {
287 1.7 ad memcpy(&oldstat, &newstat, sizeof(oldstat));
288 1.7 ad update = UPDATE_RUN;
289 1.7 ad }
290 1.7 ad }
291 1.7 ad
292 1.7 ad void
293 1.7 ad tcp_time(char *args)
294 1.7 ad {
295 1.7 ad
296 1.7 ad if (update != UPDATE_TIME) {
297 1.7 ad memcpy(&oldstat, &newstat, sizeof(oldstat));
298 1.7 ad update = UPDATE_TIME;
299 1.7 ad }
300 1.7 ad }
301 1.7 ad
302 1.7 ad void
303 1.7 ad tcp_zero(char *args)
304 1.7 ad {
305 1.7 ad
306 1.7 ad if (update == UPDATE_RUN)
307 1.7 ad memcpy(&oldstat, &newstat, sizeof(oldstat));
308 1.1 ad }
309