Commit | Line | Data |
---|---|---|
a1f8d2f2 | 1 | /* |
b36fc510 | 2 | * Copyright (c) 1985, 1988 Regents of the University of California. |
ee3f90a5 MK |
3 | * All rights reserved. |
4 | * | |
87198c0c | 5 | * %sccs.include.redist.c% |
a1f8d2f2 KS |
6 | */ |
7 | ||
a1f8d2f2 | 8 | #ifndef lint |
bc0c28c1 | 9 | static char sccsid[] = "@(#)ns.c 5.13 (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> | |
a1f8d2f2 KS |
39 | |
40 | struct nspcb nspcb; | |
41 | struct sppcb sppcb; | |
42 | struct socket sockb; | |
a1f8d2f2 KS |
43 | extern int Aflag; |
44 | extern int aflag; | |
45 | extern int nflag; | |
f7c99b06 | 46 | extern char *plural(); |
a1f8d2f2 KS |
47 | char *ns_prpr(); |
48 | ||
49 | static int first = 1; | |
50 | ||
51 | /* | |
52 | * Print a summary of connections related to a Network Systems | |
53 | * protocol. For SPP, also give state of connection. | |
54 | * Listening processes (aflag) are suppressed unless the | |
55 | * -a (all) flag is specified. | |
56 | */ | |
57 | ||
58 | nsprotopr(off, name) | |
59 | off_t off; | |
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; |
c34ecf77 | 69 | kvm_read(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) { |
a1f8d2f2 KS |
75 | off_t ppcb; |
76 | ||
77 | next = nspcb.nsp_next; | |
c34ecf77 | 78 | kvm_read((off_t)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 | } | |
c34ecf77 KS |
86 | kvm_read((off_t)nspcb.nsp_socket, |
87 | (char *)&sockb, sizeof (sockb)); | |
a1f8d2f2 KS |
88 | ppcb = (off_t) nspcb.nsp_pcb; |
89 | if (ppcb) { | |
90 | if (isspp) { | |
c34ecf77 | 91 | kvm_read(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 | */ | |
132 | spp_stats(off, name) | |
133 | off_t off; | |
134 | char *name; | |
135 | { | |
136 | struct spp_istat spp_istat; | |
42e83ef1 | 137 | #define sppstat spp_istat.newstats |
a1f8d2f2 | 138 | |
4a920942 | 139 | if (off == 0) |
a1f8d2f2 | 140 | return; |
c34ecf77 | 141 | kvm_read(off, (char *)&spp_istat, sizeof (spp_istat)); |
a1f8d2f2 KS |
142 | printf("%s:\n", name); |
143 | ANY(spp_istat.nonucn, "connection", " dropped due to no new sockets "); | |
144 | ANY(spp_istat.gonawy, "connection", " terminated due to our end dying"); | |
bc0c28c1 KB |
145 | ANY(spp_istat.nonucn, "connection", |
146 | " dropped due to inability to connect"); | |
147 | ANY(spp_istat.noconn, "connection", | |
148 | " dropped due to inability to connect"); | |
149 | ANY(spp_istat.notme, "connection", | |
150 | " incompleted due to mismatched id's"); | |
a1f8d2f2 KS |
151 | ANY(spp_istat.wrncon, "connection", " dropped due to mismatched id's"); |
152 | ANY(spp_istat.bdreas, "packet", " dropped out of sequence"); | |
153 | ANY(spp_istat.lstdup, "packet", " duplicating the highest packet"); | |
154 | ANY(spp_istat.notyet, "packet", " refused as exceeding allocation"); | |
42e83ef1 KS |
155 | ANY(sppstat.spps_connattempt, "connection", " initiated"); |
156 | ANY(sppstat.spps_accepts, "connection", " accepted"); | |
157 | ANY(sppstat.spps_connects, "connection", " established"); | |
158 | ANY(sppstat.spps_drops, "connection", " dropped"); | |
159 | ANY(sppstat.spps_conndrops, "embryonic connection", " dropped"); | |
160 | ANY(sppstat.spps_closed, "connection", " closed (includes drops)"); | |
161 | ANY(sppstat.spps_segstimed, "packet", " where we tried to get rtt"); | |
162 | ANY(sppstat.spps_rttupdated, "time", " we got rtt"); | |
163 | ANY(sppstat.spps_delack, "delayed ack", " sent"); | |
164 | ANY(sppstat.spps_timeoutdrop, "connection", " dropped in rxmt timeout"); | |
165 | ANY(sppstat.spps_rexmttimeo, "retransmit timeout", ""); | |
166 | ANY(sppstat.spps_persisttimeo, "persist timeout", ""); | |
167 | ANY(sppstat.spps_keeptimeo, "keepalive timeout", ""); | |
168 | ANY(sppstat.spps_keepprobe, "keepalive probe", " sent"); | |
169 | ANY(sppstat.spps_keepdrops, "connection", " dropped in keepalive"); | |
170 | ANY(sppstat.spps_sndtotal, "total packet", " sent"); | |
171 | ANY(sppstat.spps_sndpack, "data packet", " sent"); | |
172 | ANY(sppstat.spps_sndbyte, "data byte", " sent"); | |
173 | ANY(sppstat.spps_sndrexmitpack, "data packet", " retransmitted"); | |
174 | ANY(sppstat.spps_sndrexmitbyte, "data byte", " retransmitted"); | |
175 | ANY(sppstat.spps_sndacks, "ack-only packet", " sent"); | |
176 | ANY(sppstat.spps_sndprobe, "window probe", " sent"); | |
177 | ANY(sppstat.spps_sndurg, "packet", " sent with URG only"); | |
178 | ANY(sppstat.spps_sndwinup, "window update-only packet", " sent"); | |
179 | ANY(sppstat.spps_sndctrl, "control (SYN|FIN|RST) packet", " sent"); | |
180 | ANY(sppstat.spps_sndvoid, "request", " to send a non-existant packet"); | |
181 | ANY(sppstat.spps_rcvtotal, "total packet", " received"); | |
182 | ANY(sppstat.spps_rcvpack, "packet", " received in sequence"); | |
183 | ANY(sppstat.spps_rcvbyte, "byte", " received in sequence"); | |
184 | ANY(sppstat.spps_rcvbadsum, "packet", " received with ccksum errs"); | |
185 | ANY(sppstat.spps_rcvbadoff, "packet", " received with bad offset"); | |
186 | ANY(sppstat.spps_rcvshort, "packet", " received too short"); | |
187 | ANY(sppstat.spps_rcvduppack, "duplicate-only packet", " received"); | |
188 | ANY(sppstat.spps_rcvdupbyte, "duplicate-only byte", " received"); | |
189 | ANY(sppstat.spps_rcvpartduppack, "packet", " with some duplicate data"); | |
190 | ANY(sppstat.spps_rcvpartdupbyte, "dup. byte", " in part-dup. packet"); | |
191 | ANY(sppstat.spps_rcvoopack, "out-of-order packet", " received"); | |
192 | ANY(sppstat.spps_rcvoobyte, "out-of-order byte", " received"); | |
193 | ANY(sppstat.spps_rcvpackafterwin, "packet", " with data after window"); | |
194 | ANY(sppstat.spps_rcvbyteafterwin, "byte", " rcvd after window"); | |
195 | ANY(sppstat.spps_rcvafterclose, "packet", " rcvd after 'close'"); | |
196 | ANY(sppstat.spps_rcvwinprobe, "rcvd window probe packet", ""); | |
197 | ANY(sppstat.spps_rcvdupack, "rcvd duplicate ack", ""); | |
198 | ANY(sppstat.spps_rcvacktoomuch, "rcvd ack", " for unsent data"); | |
199 | ANY(sppstat.spps_rcvackpack, "rcvd ack packet", ""); | |
200 | ANY(sppstat.spps_rcvackbyte, "byte", " acked by rcvd acks"); | |
201 | ANY(sppstat.spps_rcvwinupd, "rcvd window update packet", ""); | |
a1f8d2f2 | 202 | } |
42e83ef1 KS |
203 | #undef ANY |
204 | #define ANY(x,y,z) ((x) ? printf("\t%d %s%s%s\n",x,y,plural(x),z) : 0) | |
a1f8d2f2 KS |
205 | |
206 | /* | |
207 | * Dump IDP statistics structure. | |
208 | */ | |
209 | idp_stats(off, name) | |
210 | off_t off; | |
211 | char *name; | |
212 | { | |
213 | struct idpstat idpstat; | |
214 | ||
4a920942 | 215 | if (off == 0) |
a1f8d2f2 | 216 | return; |
c34ecf77 | 217 | kvm_read(off, (char *)&idpstat, sizeof (idpstat)); |
f7c99b06 | 218 | printf("%s:\n", name); |
a1f8d2f2 KS |
219 | ANY(idpstat.idps_toosmall, "packet", " smaller than a header"); |
220 | ANY(idpstat.idps_tooshort, "packet", " smaller than advertised"); | |
221 | ANY(idpstat.idps_badsum, "packet", " with bad checksums"); | |
222 | } | |
223 | ||
42e83ef1 KS |
224 | static struct { |
225 | u_short code; | |
226 | char *name; | |
227 | char *where; | |
228 | } ns_errnames[] = { | |
229 | {0, "Unspecified Error", " at Destination"}, | |
230 | {1, "Bad Checksum", " at Destination"}, | |
231 | {2, "No Listener", " at Socket"}, | |
232 | {3, "Packet", " Refused due to lack of space at Destination"}, | |
233 | {01000, "Unspecified Error", " while gatewayed"}, | |
234 | {01001, "Bad Checksum", " while gatewayed"}, | |
235 | {01002, "Packet", " forwarded too many times"}, | |
236 | {01003, "Packet", " too large to be forwarded"}, | |
237 | {-1, 0, 0}, | |
a1f8d2f2 KS |
238 | }; |
239 | ||
240 | /* | |
241 | * Dump NS Error statistics structure. | |
242 | */ | |
f7c99b06 | 243 | /*ARGSUSED*/ |
a1f8d2f2 KS |
244 | nserr_stats(off, name) |
245 | off_t off; | |
246 | char *name; | |
247 | { | |
248 | struct ns_errstat ns_errstat; | |
249 | register int j; | |
250 | register int histoprint = 1; | |
251 | int z; | |
252 | ||
4a920942 | 253 | if (off == 0) |
a1f8d2f2 | 254 | return; |
c34ecf77 | 255 | kvm_read(off, (char *)&ns_errstat, sizeof (ns_errstat)); |
a1f8d2f2 KS |
256 | printf("NS error statistics:\n"); |
257 | ANY(ns_errstat.ns_es_error, "call", " to ns_error"); | |
258 | ANY(ns_errstat.ns_es_oldshort, "error", | |
259 | " ignored due to insufficient addressing"); | |
260 | ANY(ns_errstat.ns_es_oldns_err, "error request", | |
261 | " in response to error packets"); | |
262 | ANY(ns_errstat.ns_es_tooshort, "error packet", | |
263 | " received incomplete"); | |
264 | ANY(ns_errstat.ns_es_badcode, "error packet", | |
265 | " received of unknown type"); | |
266 | for(j = 0; j < NS_ERR_MAX; j ++) { | |
267 | z = ns_errstat.ns_es_outhist[j]; | |
268 | if (z && histoprint) { | |
269 | printf("Output Error Histogram:\n"); | |
270 | histoprint = 0; | |
271 | } | |
42e83ef1 KS |
272 | ns_erputil(z, ns_errstat.ns_es_codes[j]); |
273 | ||
a1f8d2f2 KS |
274 | } |
275 | histoprint = 1; | |
276 | for(j = 0; j < NS_ERR_MAX; j ++) { | |
277 | z = ns_errstat.ns_es_inhist[j]; | |
278 | if (z && histoprint) { | |
279 | printf("Input Error Histogram:\n"); | |
280 | histoprint = 0; | |
281 | } | |
42e83ef1 KS |
282 | ns_erputil(z, ns_errstat.ns_es_codes[j]); |
283 | } | |
284 | } | |
bc0c28c1 | 285 | |
42e83ef1 KS |
286 | ns_erputil(z, c) |
287 | { | |
288 | int j; | |
289 | char codebuf[30]; | |
290 | char *name, *where; | |
bc0c28c1 | 291 | |
42e83ef1 KS |
292 | for(j = 0;; j ++) { |
293 | if ((name = ns_errnames[j].name) == 0) | |
294 | break; | |
295 | if (ns_errnames[j].code == c) | |
296 | break; | |
a1f8d2f2 | 297 | } |
42e83ef1 KS |
298 | if (name == 0) { |
299 | if (c > 01000) | |
300 | where = "in transit"; | |
301 | else | |
302 | where = "at destination"; | |
303 | sprintf(codebuf, "Unknown XNS error code 0%o", c); | |
304 | name = codebuf; | |
305 | } else | |
306 | where = ns_errnames[j].where; | |
307 | ANY(z, name, where); | |
a1f8d2f2 | 308 | } |
bc0c28c1 | 309 | |
a1f8d2f2 KS |
310 | static struct sockaddr_ns ssns = {AF_NS}; |
311 | ||
312 | char *ns_prpr(x) | |
bc0c28c1 | 313 | struct ns_addr *x; |
a1f8d2f2 | 314 | { |
a1f8d2f2 | 315 | struct sockaddr_ns *sns = &ssns; |
bc0c28c1 KB |
316 | extern char *ns_print(); |
317 | ||
a1f8d2f2 KS |
318 | sns->sns_addr = *x; |
319 | return(ns_print(sns)); | |
320 | } |