Commit | Line | Data |
---|---|---|
a1f8d2f2 | 1 | /* |
2839532b KB |
2 | * Copyright (c) 1983, 1988, 1993 |
3 | * The Regents of the University of California. All rights reserved. | |
ee3f90a5 | 4 | * |
87198c0c | 5 | * %sccs.include.redist.c% |
a1f8d2f2 KS |
6 | */ |
7 | ||
a1f8d2f2 | 8 | #ifndef lint |
2839532b | 9 | static char sccsid[] = "@(#)ns.c 8.1 (Berkeley) %G%"; |
b36fc510 | 10 | #endif /* not lint */ |
a1f8d2f2 | 11 | |
37fca8b1 | 12 | #include <sys/param.h> |
a1f8d2f2 KS |
13 | #include <sys/socket.h> |
14 | #include <sys/socketvar.h> | |
15 | #include <sys/mbuf.h> | |
16 | #include <sys/protosw.h> | |
17 | ||
18 | #include <net/route.h> | |
19 | #include <net/if.h> | |
20 | ||
21 | #include <netinet/tcp_fsm.h> | |
a1f8d2f2 KS |
22 | |
23 | #include <netns/ns.h> | |
24 | #include <netns/ns_pcb.h> | |
25 | #include <netns/idp.h> | |
26 | #include <netns/idp_var.h> | |
27 | #include <netns/ns_error.h> | |
28 | #include <netns/sp.h> | |
29 | #include <netns/spidp.h> | |
cacc72f7 | 30 | #include <netns/spp_timer.h> |
a1f8d2f2 KS |
31 | #include <netns/spp_var.h> |
32 | #define SANAMES | |
33 | #include <netns/spp_debug.h> | |
34 | ||
bc0c28c1 KB |
35 | #include <nlist.h> |
36 | #include <errno.h> | |
37 | #include <stdio.h> | |
38 | #include <string.h> | |
6e549c8f | 39 | #include "netstat.h" |
a1f8d2f2 KS |
40 | |
41 | struct nspcb nspcb; | |
42 | struct sppcb sppcb; | |
43 | struct socket sockb; | |
6e549c8f KS |
44 | |
45 | static char *ns_prpr __P((struct ns_addr *)); | |
27788811 | 46 | static void ns_erputil __P((int, int)); |
a1f8d2f2 KS |
47 | |
48 | static int first = 1; | |
49 | ||
50 | /* | |
51 | * Print a summary of connections related to a Network Systems | |
52 | * protocol. For SPP, also give state of connection. | |
53 | * Listening processes (aflag) are suppressed unless the | |
54 | * -a (all) flag is specified. | |
55 | */ | |
56 | ||
6e549c8f | 57 | void |
a1f8d2f2 | 58 | nsprotopr(off, name) |
d1cfb820 | 59 | u_long off; |
a1f8d2f2 KS |
60 | char *name; |
61 | { | |
62 | struct nspcb cb; | |
63 | register struct nspcb *prev, *next; | |
64 | int isspp; | |
65 | ||
4a920942 | 66 | if (off == 0) |
a1f8d2f2 | 67 | return; |
a1f8d2f2 | 68 | isspp = strcmp(name, "spp") == 0; |
6e549c8f | 69 | kread(off, (char *)&cb, sizeof (struct nspcb)); |
a1f8d2f2 KS |
70 | nspcb = cb; |
71 | prev = (struct nspcb *)off; | |
4a920942 MK |
72 | if (nspcb.nsp_next == (struct nspcb *)off) |
73 | return; | |
a1f8d2f2 | 74 | for (;nspcb.nsp_next != (struct nspcb *)off; prev = next) { |
d1cfb820 | 75 | u_long ppcb; |
a1f8d2f2 KS |
76 | |
77 | next = nspcb.nsp_next; | |
d1cfb820 | 78 | kread((u_long)next, (char *)&nspcb, sizeof (nspcb)); |
a1f8d2f2 KS |
79 | if (nspcb.nsp_prev != prev) { |
80 | printf("???\n"); | |
81 | break; | |
82 | } | |
83 | if (!aflag && ns_nullhost(nspcb.nsp_faddr) ) { | |
84 | continue; | |
85 | } | |
d1cfb820 | 86 | kread((u_long)nspcb.nsp_socket, |
c34ecf77 | 87 | (char *)&sockb, sizeof (sockb)); |
d1cfb820 | 88 | ppcb = (u_long) nspcb.nsp_pcb; |
a1f8d2f2 KS |
89 | if (ppcb) { |
90 | if (isspp) { | |
6e549c8f | 91 | kread(ppcb, (char *)&sppcb, sizeof (sppcb)); |
a1f8d2f2 KS |
92 | } else continue; |
93 | } else | |
94 | if (isspp) continue; | |
26ebe146 MK |
95 | if (first) { |
96 | printf("Active NS connections"); | |
97 | if (aflag) | |
98 | printf(" (including servers)"); | |
99 | putchar('\n'); | |
100 | if (Aflag) | |
101 | printf("%-8.8s ", "PCB"); | |
102 | printf(Aflag ? | |
103 | "%-5.5s %-6.6s %-6.6s %-18.18s %-18.18s %s\n" : | |
104 | "%-5.5s %-6.6s %-6.6s %-22.22s %-22.22s %s\n", | |
105 | "Proto", "Recv-Q", "Send-Q", | |
106 | "Local Address", "Foreign Address", "(state)"); | |
107 | first = 0; | |
108 | } | |
a1f8d2f2 KS |
109 | if (Aflag) |
110 | printf("%8x ", ppcb); | |
111 | printf("%-5.5s %6d %6d ", name, sockb.so_rcv.sb_cc, | |
112 | sockb.so_snd.sb_cc); | |
113 | printf(" %-22.22s", ns_prpr(&nspcb.nsp_laddr)); | |
114 | printf(" %-22.22s", ns_prpr(&nspcb.nsp_faddr)); | |
115 | if (isspp) { | |
116 | extern char *tcpstates[]; | |
f7c99b06 | 117 | if (sppcb.s_state >= TCP_NSTATES) |
a1f8d2f2 KS |
118 | printf(" %d", sppcb.s_state); |
119 | else | |
120 | printf(" %s", tcpstates[sppcb.s_state]); | |
121 | } | |
122 | putchar('\n'); | |
123 | prev = next; | |
124 | } | |
125 | } | |
bc0c28c1 KB |
126 | #define ANY(x,y,z) \ |
127 | ((x) ? printf("\t%d %s%s%s -- %s\n",x,y,plural(x),z,"x") : 0) | |
a1f8d2f2 KS |
128 | |
129 | /* | |
130 | * Dump SPP statistics structure. | |
131 | */ | |
6e549c8f | 132 | void |
a1f8d2f2 | 133 | spp_stats(off, name) |
d1cfb820 | 134 | u_long off; |
a1f8d2f2 KS |
135 | char *name; |
136 | { | |
137 | struct spp_istat spp_istat; | |
42e83ef1 | 138 | #define sppstat spp_istat.newstats |
a1f8d2f2 | 139 | |
4a920942 | 140 | if (off == 0) |
a1f8d2f2 | 141 | return; |
6e549c8f | 142 | kread(off, (char *)&spp_istat, sizeof (spp_istat)); |
a1f8d2f2 KS |
143 | printf("%s:\n", name); |
144 | ANY(spp_istat.nonucn, "connection", " dropped due to no new sockets "); | |
145 | ANY(spp_istat.gonawy, "connection", " terminated due to our end dying"); | |
bc0c28c1 KB |
146 | ANY(spp_istat.nonucn, "connection", |
147 | " dropped due to inability to connect"); | |
148 | ANY(spp_istat.noconn, "connection", | |
149 | " dropped due to inability to connect"); | |
150 | ANY(spp_istat.notme, "connection", | |
151 | " incompleted due to mismatched id's"); | |
a1f8d2f2 KS |
152 | ANY(spp_istat.wrncon, "connection", " dropped due to mismatched id's"); |
153 | ANY(spp_istat.bdreas, "packet", " dropped out of sequence"); | |
154 | ANY(spp_istat.lstdup, "packet", " duplicating the highest packet"); | |
155 | ANY(spp_istat.notyet, "packet", " refused as exceeding allocation"); | |
42e83ef1 KS |
156 | ANY(sppstat.spps_connattempt, "connection", " initiated"); |
157 | ANY(sppstat.spps_accepts, "connection", " accepted"); | |
158 | ANY(sppstat.spps_connects, "connection", " established"); | |
159 | ANY(sppstat.spps_drops, "connection", " dropped"); | |
160 | ANY(sppstat.spps_conndrops, "embryonic connection", " dropped"); | |
161 | ANY(sppstat.spps_closed, "connection", " closed (includes drops)"); | |
162 | ANY(sppstat.spps_segstimed, "packet", " where we tried to get rtt"); | |
163 | ANY(sppstat.spps_rttupdated, "time", " we got rtt"); | |
164 | ANY(sppstat.spps_delack, "delayed ack", " sent"); | |
165 | ANY(sppstat.spps_timeoutdrop, "connection", " dropped in rxmt timeout"); | |
166 | ANY(sppstat.spps_rexmttimeo, "retransmit timeout", ""); | |
167 | ANY(sppstat.spps_persisttimeo, "persist timeout", ""); | |
168 | ANY(sppstat.spps_keeptimeo, "keepalive timeout", ""); | |
169 | ANY(sppstat.spps_keepprobe, "keepalive probe", " sent"); | |
170 | ANY(sppstat.spps_keepdrops, "connection", " dropped in keepalive"); | |
171 | ANY(sppstat.spps_sndtotal, "total packet", " sent"); | |
172 | ANY(sppstat.spps_sndpack, "data packet", " sent"); | |
173 | ANY(sppstat.spps_sndbyte, "data byte", " sent"); | |
174 | ANY(sppstat.spps_sndrexmitpack, "data packet", " retransmitted"); | |
175 | ANY(sppstat.spps_sndrexmitbyte, "data byte", " retransmitted"); | |
176 | ANY(sppstat.spps_sndacks, "ack-only packet", " sent"); | |
177 | ANY(sppstat.spps_sndprobe, "window probe", " sent"); | |
178 | ANY(sppstat.spps_sndurg, "packet", " sent with URG only"); | |
179 | ANY(sppstat.spps_sndwinup, "window update-only packet", " sent"); | |
180 | ANY(sppstat.spps_sndctrl, "control (SYN|FIN|RST) packet", " sent"); | |
181 | ANY(sppstat.spps_sndvoid, "request", " to send a non-existant packet"); | |
182 | ANY(sppstat.spps_rcvtotal, "total packet", " received"); | |
183 | ANY(sppstat.spps_rcvpack, "packet", " received in sequence"); | |
184 | ANY(sppstat.spps_rcvbyte, "byte", " received in sequence"); | |
185 | ANY(sppstat.spps_rcvbadsum, "packet", " received with ccksum errs"); | |
186 | ANY(sppstat.spps_rcvbadoff, "packet", " received with bad offset"); | |
187 | ANY(sppstat.spps_rcvshort, "packet", " received too short"); | |
188 | ANY(sppstat.spps_rcvduppack, "duplicate-only packet", " received"); | |
189 | ANY(sppstat.spps_rcvdupbyte, "duplicate-only byte", " received"); | |
190 | ANY(sppstat.spps_rcvpartduppack, "packet", " with some duplicate data"); | |
191 | ANY(sppstat.spps_rcvpartdupbyte, "dup. byte", " in part-dup. packet"); | |
192 | ANY(sppstat.spps_rcvoopack, "out-of-order packet", " received"); | |
193 | ANY(sppstat.spps_rcvoobyte, "out-of-order byte", " received"); | |
194 | ANY(sppstat.spps_rcvpackafterwin, "packet", " with data after window"); | |
195 | ANY(sppstat.spps_rcvbyteafterwin, "byte", " rcvd after window"); | |
196 | ANY(sppstat.spps_rcvafterclose, "packet", " rcvd after 'close'"); | |
197 | ANY(sppstat.spps_rcvwinprobe, "rcvd window probe packet", ""); | |
198 | ANY(sppstat.spps_rcvdupack, "rcvd duplicate ack", ""); | |
199 | ANY(sppstat.spps_rcvacktoomuch, "rcvd ack", " for unsent data"); | |
200 | ANY(sppstat.spps_rcvackpack, "rcvd ack packet", ""); | |
201 | ANY(sppstat.spps_rcvackbyte, "byte", " acked by rcvd acks"); | |
202 | ANY(sppstat.spps_rcvwinupd, "rcvd window update packet", ""); | |
a1f8d2f2 | 203 | } |
42e83ef1 KS |
204 | #undef ANY |
205 | #define ANY(x,y,z) ((x) ? printf("\t%d %s%s%s\n",x,y,plural(x),z) : 0) | |
a1f8d2f2 KS |
206 | |
207 | /* | |
208 | * Dump IDP statistics structure. | |
209 | */ | |
6e549c8f | 210 | void |
a1f8d2f2 | 211 | idp_stats(off, name) |
d1cfb820 | 212 | u_long off; |
a1f8d2f2 KS |
213 | char *name; |
214 | { | |
215 | struct idpstat idpstat; | |
216 | ||
4a920942 | 217 | if (off == 0) |
a1f8d2f2 | 218 | return; |
6e549c8f | 219 | kread(off, (char *)&idpstat, sizeof (idpstat)); |
f7c99b06 | 220 | printf("%s:\n", name); |
a1f8d2f2 KS |
221 | ANY(idpstat.idps_toosmall, "packet", " smaller than a header"); |
222 | ANY(idpstat.idps_tooshort, "packet", " smaller than advertised"); | |
223 | ANY(idpstat.idps_badsum, "packet", " with bad checksums"); | |
224 | } | |
225 | ||
42e83ef1 KS |
226 | static struct { |
227 | u_short code; | |
228 | char *name; | |
229 | char *where; | |
230 | } ns_errnames[] = { | |
231 | {0, "Unspecified Error", " at Destination"}, | |
232 | {1, "Bad Checksum", " at Destination"}, | |
233 | {2, "No Listener", " at Socket"}, | |
234 | {3, "Packet", " Refused due to lack of space at Destination"}, | |
235 | {01000, "Unspecified Error", " while gatewayed"}, | |
236 | {01001, "Bad Checksum", " while gatewayed"}, | |
237 | {01002, "Packet", " forwarded too many times"}, | |
238 | {01003, "Packet", " too large to be forwarded"}, | |
239 | {-1, 0, 0}, | |
a1f8d2f2 KS |
240 | }; |
241 | ||
242 | /* | |
243 | * Dump NS Error statistics structure. | |
244 | */ | |
f7c99b06 | 245 | /*ARGSUSED*/ |
6e549c8f | 246 | void |
a1f8d2f2 | 247 | nserr_stats(off, name) |
d1cfb820 | 248 | u_long off; |
a1f8d2f2 KS |
249 | char *name; |
250 | { | |
251 | struct ns_errstat ns_errstat; | |
252 | register int j; | |
253 | register int histoprint = 1; | |
254 | int z; | |
255 | ||
4a920942 | 256 | if (off == 0) |
a1f8d2f2 | 257 | return; |
6e549c8f | 258 | kread(off, (char *)&ns_errstat, sizeof (ns_errstat)); |
a1f8d2f2 KS |
259 | printf("NS error statistics:\n"); |
260 | ANY(ns_errstat.ns_es_error, "call", " to ns_error"); | |
261 | ANY(ns_errstat.ns_es_oldshort, "error", | |
262 | " ignored due to insufficient addressing"); | |
263 | ANY(ns_errstat.ns_es_oldns_err, "error request", | |
264 | " in response to error packets"); | |
265 | ANY(ns_errstat.ns_es_tooshort, "error packet", | |
266 | " received incomplete"); | |
267 | ANY(ns_errstat.ns_es_badcode, "error packet", | |
268 | " received of unknown type"); | |
269 | for(j = 0; j < NS_ERR_MAX; j ++) { | |
270 | z = ns_errstat.ns_es_outhist[j]; | |
271 | if (z && histoprint) { | |
272 | printf("Output Error Histogram:\n"); | |
273 | histoprint = 0; | |
274 | } | |
42e83ef1 KS |
275 | ns_erputil(z, ns_errstat.ns_es_codes[j]); |
276 | ||
a1f8d2f2 KS |
277 | } |
278 | histoprint = 1; | |
279 | for(j = 0; j < NS_ERR_MAX; j ++) { | |
280 | z = ns_errstat.ns_es_inhist[j]; | |
281 | if (z && histoprint) { | |
282 | printf("Input Error Histogram:\n"); | |
283 | histoprint = 0; | |
284 | } | |
42e83ef1 KS |
285 | ns_erputil(z, ns_errstat.ns_es_codes[j]); |
286 | } | |
287 | } | |
bc0c28c1 | 288 | |
6e549c8f | 289 | static void |
42e83ef1 | 290 | ns_erputil(z, c) |
6e549c8f | 291 | int z, c; |
42e83ef1 KS |
292 | { |
293 | int j; | |
294 | char codebuf[30]; | |
295 | char *name, *where; | |
bc0c28c1 | 296 | |
42e83ef1 KS |
297 | for(j = 0;; j ++) { |
298 | if ((name = ns_errnames[j].name) == 0) | |
299 | break; | |
300 | if (ns_errnames[j].code == c) | |
301 | break; | |
a1f8d2f2 | 302 | } |
42e83ef1 KS |
303 | if (name == 0) { |
304 | if (c > 01000) | |
305 | where = "in transit"; | |
306 | else | |
307 | where = "at destination"; | |
308 | sprintf(codebuf, "Unknown XNS error code 0%o", c); | |
309 | name = codebuf; | |
6e549c8f | 310 | } else |
42e83ef1 KS |
311 | where = ns_errnames[j].where; |
312 | ANY(z, name, where); | |
a1f8d2f2 | 313 | } |
bc0c28c1 | 314 | |
a1f8d2f2 KS |
315 | static struct sockaddr_ns ssns = {AF_NS}; |
316 | ||
6e549c8f | 317 | static |
a1f8d2f2 | 318 | char *ns_prpr(x) |
bc0c28c1 | 319 | struct ns_addr *x; |
a1f8d2f2 | 320 | { |
a1f8d2f2 | 321 | struct sockaddr_ns *sns = &ssns; |
bc0c28c1 | 322 | |
a1f8d2f2 | 323 | sns->sns_addr = *x; |
6e549c8f | 324 | return(ns_print((struct sockaddr *)sns)); |
a1f8d2f2 | 325 | } |