tcp.c revision 1.1 1 /* $NetBSD: tcp.c,v 1.1 1999/05/30 20:26:21 ad 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.1 1999/05/30 20:26:21 ad 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 #include "systat.h"
56 #include "extern.h"
57
58 #define LHD(row, str) mvwprintw(wnd, row, 10, str)
59 #define RHD(row, str) mvwprintw(wnd, row, 45, str)
60 #define SHOW(row, col, stat) mvwprintw(wnd, row, col, "%9lu", curstat.stat)
61
62 static struct tcpstat curstat, oldstat;
63
64 static struct nlist namelist[] = {
65 { "_tcpstat" },
66 { "" }
67 };
68
69 WINDOW *
70 opentcp(void)
71 {
72
73 return (subwin(stdscr, LINES-5-1, 0, 5, 0));
74 }
75
76 void
77 closetcp(w)
78 WINDOW *w;
79 {
80
81 if (w != NULL) {
82 wclear(w);
83 wrefresh(w);
84 delwin(w);
85 }
86 }
87
88 void
89 labeltcp(void)
90 {
91 wmove(wnd, 0, 0); wclrtoeol(wnd);
92
93 LHD(0, "connections initiated");
94 LHD(1, "connections accepted");
95 LHD(2, "connections established");
96
97 LHD(4, "connections dropped");
98 LHD(5, " in embryonic state");
99 LHD(6, " on retransmit timeout");
100 LHD(7, " by keepalive");
101 LHD(8, " by persist");
102
103 LHD(10, "potential rtt updates");
104 LHD(11, "successful rtt updates");
105 LHD(12, "delayed acks sent");
106 LHD(13, "retransmit timeouts");
107 LHD(14, "persist timeouts");
108 LHD(15, "keepalive probes");
109 LHD(16, "keepalive timeouts");
110
111 RHD(9, "total TCP packets received");
112 RHD(10, " in sequence");
113 RHD(11, " completely duplicate");
114 RHD(12, " with some duplicate data");
115 RHD(13, " out of order");
116 RHD(14, " duplicate acks");
117 RHD(15, " acks");
118 RHD(16, " window probes");
119 RHD(17, " window updates");
120
121 RHD(0, "total TCP packets sent");
122 RHD(1, " data");
123 RHD(2, " data (retransmit)");
124 RHD(3, " ack-only");
125 RHD(4, " window probes");
126 RHD(5, " window updates");
127 RHD(6, " urgent data only");
128 RHD(7, " control");
129 }
130
131 void
132 showtcpsyn(void)
133 {
134
135 SHOW(0, 0, tcps_sc_added);
136 SHOW(1, 0, tcps_sc_completed);
137 SHOW(2, 0, tcps_sc_timed_out);
138 SHOW(3, 0, tcps_sc_dupesyn);
139 SHOW(4, 0, tcps_sc_collisions);
140 SHOW(5, 0, tcps_sc_retransmitted);
141 SHOW(6, 0, tcps_sc_aborted);
142 SHOW(7, 0, tcps_sc_overflowed);
143 SHOW(8, 0, tcps_sc_reset);
144 SHOW(9, 0, tcps_sc_unreach);
145 SHOW(10, 0, tcps_sc_bucketoverflow);
146 SHOW(11, 0, tcps_sc_dropped);
147 }
148
149 void
150 labeltcpsyn(void)
151 {
152
153 wmove(wnd, 0, 0); wclrtoeol(wnd);
154 LHD(0, "entries added");
155 LHD(1, "connections completed");
156 LHD(2, "entries timed out");
157 LHD(3, "duplicate SYNs recieved");
158 LHD(4, "hash collisions");
159 LHD(5, "retransmissions");
160 LHD(6, "entries aborted (no memory)");
161 LHD(7, "dropped (overflow)");
162 LHD(8, "dropped (RST)");
163 LHD(9, "dropped (ICMP UNRCH)");
164 LHD(10, "dropped (bucket overflow)");
165 LHD(11, "dropped (unreachable/no memory)");
166 }
167
168 void
169 showtcp(void)
170 {
171
172 SHOW(0, 0, tcps_connattempt);
173 SHOW(1, 0, tcps_accepts);
174 SHOW(2, 0, tcps_connects);
175
176 SHOW(4, 0, tcps_drops);
177 SHOW(5, 0, tcps_conndrops);
178 SHOW(6, 0, tcps_timeoutdrop);
179 SHOW(7, 0, tcps_keepdrops);
180 SHOW(8, 0, tcps_persistdrops);
181
182 SHOW(10, 0, tcps_segstimed);
183 SHOW(11, 0, tcps_rttupdated);
184 SHOW(12, 0, tcps_delack);
185 SHOW(13, 0, tcps_rexmttimeo);
186 SHOW(14, 0, tcps_persisttimeo);
187 SHOW(15, 0, tcps_keepprobe);
188 SHOW(16, 0, tcps_keeptimeo);
189
190 SHOW(0, 35, tcps_sndtotal);
191 SHOW(1, 35, tcps_sndpack);
192 SHOW(2, 35, tcps_sndrexmitpack);
193
194 SHOW(3, 35, tcps_sndacks);
195 SHOW(4, 35, tcps_sndprobe);
196 SHOW(5, 35, tcps_sndwinup);
197 SHOW(6, 35, tcps_sndurg);
198 SHOW(7, 35, tcps_sndctrl);
199
200 SHOW(9, 35, tcps_rcvtotal);
201 SHOW(10, 35, tcps_rcvpack);
202 SHOW(11, 35, tcps_rcvduppack);
203 SHOW(12, 35, tcps_rcvpartduppack);
204 SHOW(13, 35, tcps_rcvoopack);
205 SHOW(14, 35, tcps_rcvdupack);
206 SHOW(15, 35, tcps_rcvackpack);
207 SHOW(16, 35, tcps_rcvwinprobe);
208 SHOW(17, 35, tcps_rcvwinupd);
209 }
210
211 int
212 inittcp(void)
213 {
214 if (namelist[0].n_type == 0) {
215 if (kvm_nlist(kd, namelist)) {
216 nlisterr(namelist);
217 return(0);
218 }
219 if (namelist[0].n_type == 0) {
220 error("No namelist");
221 return(0);
222 }
223 }
224 return 1;
225 }
226
227 void
228 fetchtcp(void)
229 {
230 oldstat = curstat;
231 KREAD((void *)namelist[0].n_value, &curstat, sizeof(curstat));
232 }
233