Annotation of src/usr.bin/netstat/ipx.c, Revision 1.2
1.2 ! millert 1: /* $OpenBSD: ipx.c,v 1.1 1996/08/16 09:29:32 mickey Exp $ */
1.1 mickey 2:
3: /*
4: * Copyright (c) 1996 Michael Shalayeff
5: * Copyright (c) 1983, 1988, 1993
6: * The Regents of the University of California. All rights reserved.
7: *
8: * Redistribution and use in source and binary forms, with or without
9: * modification, are permitted provided that the following conditions
10: * are met:
11: * 1. Redistributions of source code must retain the above copyright
12: * notice, this list of conditions and the following disclaimer.
13: * 2. Redistributions in binary form must reproduce the above copyright
14: * notice, this list of conditions and the following disclaimer in the
15: * documentation and/or other materials provided with the distribution.
16: * 3. All advertising materials mentioning features or use of this software
17: * must display the following acknowledgement:
18: * This product includes software developed by the University of
19: * California, Berkeley and its contributors.
20: * 4. Neither the name of the University nor the names of its contributors
21: * may be used to endorse or promote products derived from this software
22: * without specific prior written permission.
23: *
24: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34: * SUCH DAMAGE.
35: */
36:
37: #ifndef lint
38: #if 0
39: static char sccsid[] = "from: @(#)ns.c 8.1 (Berkeley) 6/6/93";
40: #else
1.2 ! millert 41: static char *rcsid = "$OpenBSD: ipx.c,v 1.1 1996/08/16 09:29:32 mickey Exp $";
1.1 mickey 42: #endif
43: #endif /* not lint */
44:
45: #include <sys/param.h>
46: #include <sys/socket.h>
47: #include <sys/socketvar.h>
48: #include <sys/mbuf.h>
49: #include <sys/protosw.h>
50:
51: #include <net/route.h>
52: #include <net/if.h>
53:
54: #include <netinet/tcp_fsm.h>
55:
56: #include <netipx/ipx.h>
57: #include <netipx/ipx_pcb.h>
58: #include <netipx/ipx.h>
59: #include <netipx/ipx_var.h>
60: #include <netipx/ipx_error.h>
61: #include <netipx/spx.h>
62: #include <netipx/spx_timer.h>
63: #include <netipx/spx_var.h>
64: #define SANAMES
65: #include <netipx/spx_debug.h>
66:
67: #include <nlist.h>
68: #include <errno.h>
69: #include <stdio.h>
70: #include <string.h>
71: #include "netstat.h"
72:
73: struct ipxpcb ipxpcb;
74: struct spxpcb spxpcb;
75: struct socket sockb;
76:
77: static char *ipx_prpr __P((struct ipx_addr *));
78: static void ipx_erputil __P((int, int));
79:
80: static int first = 1;
81:
82: /*
83: * Print a summary of connections related to an IPX
84: * protocol. For SPX, also give state of connection.
85: * Listening processes (aflag) are suppressed unless the
86: * -a (all) flag is specified.
87: */
88:
89: void
90: ipxprotopr(off, name)
91: u_long off;
92: char *name;
93: {
94: struct ipxpcbtable table;
95: register struct ipxpcb *head, *prev, *next;
96: int isspx;
97:
98: if (off == 0)
99: return;
100: isspx = strcmp(name, "spx") == 0;
101: kread(off, (char *)&table, sizeof (table));
102: prev = head = (struct ipxpcb *)
103: &((struct ipxpcbtable *)off)->ipxpt_queue.cqh_first;
104: next = table.ipxpt_queue.cqh_first;
105:
106: while (next != head) {
107: kread((u_long)next, (char *)&ipxpcb, sizeof (ipxpcb));
108: if (ipxpcb.ipxp_queue.cqe_prev != prev) {
109: printf("???\n");
110: break;
111: }
112: prev = next;
113: next = ipxpcb.ipxp_queue.cqe_next;
114:
115: if (!aflag && ipx_nullhost(ipxpcb.ipxp_faddr) )
116: continue;
117:
118: kread((u_long)ipxpcb.ipxp_socket,
119: (char *)&sockb, sizeof (sockb));
120: if (isspx) {
121: kread((u_long)ipxpcb.ipxp_ppcb,
122: (char *)&spxpcb, sizeof (spxpcb));
123: }
124: if (first) {
125: printf("Active Internetwork Packet Exchange connections");
126: if (aflag)
127: printf(" (including servers)");
128: putchar('\n');
129: if (Aflag)
130: printf("%-8.8s ", "PCB");
131: printf(Aflag ?
132: "%-5.5s %-6.6s %-6.6s %-18.18s %-18.18s %s\n" :
133: "%-5.5s %-6.6s %-6.6s %-22.22s %-22.22s %s\n",
134: "Proto", "Recv-Q", "Send-Q",
135: "Local Address", "Foreign Address", "(state)");
136: first = 0;
137: }
138: if (Aflag)
1.2 ! millert 139: printf("%8p ", ipxpcb.ipxp_ppcb);
! 140: printf("%-5.5s %6ld %6ld ", name, sockb.so_rcv.sb_cc,
1.1 mickey 141: sockb.so_snd.sb_cc);
142: printf(" %-22.22s", ipx_prpr(&ipxpcb.ipxp_laddr));
143: printf(" %-22.22s", ipx_prpr(&ipxpcb.ipxp_faddr));
144: if (isspx) {
145: extern char *tcpstates[];
146: if (spxpcb.s_state >= TCP_NSTATES)
147: printf(" %d", spxpcb.s_state);
148: else
149: printf(" %s", tcpstates[spxpcb.s_state]);
150: }
151: putchar('\n');
152: }
153: }
154: #define ANY(x,y,z) \
1.2 ! millert 155: ((x) ? printf("\t%ld %s%s%s -- %s\n",x,y,plural(x),z,"x") : 0)
1.1 mickey 156:
157: /*
158: * Dump SPX statistics structure.
159: */
160: void
161: spx_stats(off, name)
162: u_long off;
163: char *name;
164: {
165: struct spx_istat spx_istat;
166: #define spxstat spx_istat.newstats
167:
168: if (off == 0)
169: return;
170: kread(off, (char *)&spx_istat, sizeof (spx_istat));
171: printf("%s:\n", name);
1.2 ! millert 172: ANY((long)spx_istat.nonucn, "connection", " dropped due to no new sockets ");
! 173: ANY((long)spx_istat.gonawy, "connection", " terminated due to our end dying");
! 174: ANY((long)spx_istat.nonucn, "connection",
1.1 mickey 175: " dropped due to inability to connect");
1.2 ! millert 176: ANY((long)spx_istat.noconn, "connection",
1.1 mickey 177: " dropped due to inability to connect");
1.2 ! millert 178: ANY((long)spx_istat.notme, "connection",
1.1 mickey 179: " incompleted due to mismatched id's");
1.2 ! millert 180: ANY((long)spx_istat.wrncon, "connection", " dropped due to mismatched id's");
! 181: ANY((long)spx_istat.bdreas, "packet", " dropped out of sequence");
! 182: ANY((long)spx_istat.lstdup, "packet", " duplicating the highest packet");
! 183: ANY((long)spx_istat.notyet, "packet", " refused as exceeding allocation");
1.1 mickey 184: ANY(spxstat.spxs_connattempt, "connection", " initiated");
185: ANY(spxstat.spxs_accepts, "connection", " accepted");
186: ANY(spxstat.spxs_connects, "connection", " established");
187: ANY(spxstat.spxs_drops, "connection", " dropped");
188: ANY(spxstat.spxs_conndrops, "embryonic connection", " dropped");
189: ANY(spxstat.spxs_closed, "connection", " closed (includes drops)");
190: ANY(spxstat.spxs_segstimed, "packet", " where we tried to get rtt");
191: ANY(spxstat.spxs_rttupdated, "time", " we got rtt");
192: ANY(spxstat.spxs_delack, "delayed ack", " sent");
193: ANY(spxstat.spxs_timeoutdrop, "connection", " dropped in rxmt timeout");
194: ANY(spxstat.spxs_rexmttimeo, "retransmit timeout", "");
195: ANY(spxstat.spxs_persisttimeo, "persist timeout", "");
196: ANY(spxstat.spxs_keeptimeo, "keepalive timeout", "");
197: ANY(spxstat.spxs_keepprobe, "keepalive probe", " sent");
198: ANY(spxstat.spxs_keepdrops, "connection", " dropped in keepalive");
199: ANY(spxstat.spxs_sndtotal, "total packet", " sent");
200: ANY(spxstat.spxs_sndpack, "data packet", " sent");
201: ANY(spxstat.spxs_sndbyte, "data byte", " sent");
202: ANY(spxstat.spxs_sndrexmitpack, "data packet", " retransmitted");
203: ANY(spxstat.spxs_sndrexmitbyte, "data byte", " retransmitted");
204: ANY(spxstat.spxs_sndacks, "ack-only packet", " sent");
205: ANY(spxstat.spxs_sndprobe, "window probe", " sent");
206: ANY(spxstat.spxs_sndurg, "packet", " sent with URG only");
207: ANY(spxstat.spxs_sndwinup, "window update-only packet", " sent");
208: ANY(spxstat.spxs_sndctrl, "control (SYN|FIN|RST) packet", " sent");
209: ANY(spxstat.spxs_sndvoid, "request", " to send a non-existant packet");
210: ANY(spxstat.spxs_rcvtotal, "total packet", " received");
211: ANY(spxstat.spxs_rcvpack, "packet", " received in sequence");
212: ANY(spxstat.spxs_rcvbyte, "byte", " received in sequence");
213: ANY(spxstat.spxs_rcvbadsum, "packet", " received with ccksum errs");
214: ANY(spxstat.spxs_rcvbadoff, "packet", " received with bad offset");
215: ANY(spxstat.spxs_rcvshort, "packet", " received too short");
216: ANY(spxstat.spxs_rcvduppack, "duplicate-only packet", " received");
217: ANY(spxstat.spxs_rcvdupbyte, "duplicate-only byte", " received");
218: ANY(spxstat.spxs_rcvpartduppack, "packet", " with some duplicate data");
219: ANY(spxstat.spxs_rcvpartdupbyte, "dup. byte", " in part-dup. packet");
220: ANY(spxstat.spxs_rcvoopack, "out-of-order packet", " received");
221: ANY(spxstat.spxs_rcvoobyte, "out-of-order byte", " received");
222: ANY(spxstat.spxs_rcvpackafterwin, "packet", " with data after window");
223: ANY(spxstat.spxs_rcvbyteafterwin, "byte", " rcvd after window");
224: ANY(spxstat.spxs_rcvafterclose, "packet", " rcvd after 'close'");
225: ANY(spxstat.spxs_rcvwinprobe, "rcvd window probe packet", "");
226: ANY(spxstat.spxs_rcvdupack, "rcvd duplicate ack", "");
227: ANY(spxstat.spxs_rcvacktoomuch, "rcvd ack", " for unsent data");
228: ANY(spxstat.spxs_rcvackpack, "rcvd ack packet", "");
229: ANY(spxstat.spxs_rcvackbyte, "byte", " acked by rcvd acks");
230: ANY(spxstat.spxs_rcvwinupd, "rcvd window update packet", "");
231: }
232: #undef ANY
233: #define ANY(x,y,z) ((x) ? printf("\t%d %s%s%s\n",x,y,plural(x),z) : 0)
234:
235: /*
236: * Dump IPX statistics structure.
237: */
238: void
239: ipx_stats(off, name)
240: u_long off;
241: char *name;
242: {
243: struct ipxstat ipxstat;
244:
245: if (off == 0)
246: return;
247: kread(off, (char *)&ipxstat, sizeof (ipxstat));
248: printf("%s:\n", name);
249: ANY(ipxstat.ipxs_toosmall, "packet", " smaller than a header");
250: ANY(ipxstat.ipxs_tooshort, "packet", " smaller than advertised");
251: ANY(ipxstat.ipxs_badsum, "packet", " with bad checksums");
252: }
253:
254: static struct {
255: u_short code;
256: char *name;
257: char *where;
258: } ipx_errnames[] = {
259: {0, "Unspecified Error", " at Destination"},
260: {1, "Bad Checksum", " at Destination"},
261: {2, "No Listener", " at Socket"},
262: {3, "Packet", " Refused due to lack of space at Destination"},
263: {01000, "Unspecified Error", " while gatewayed"},
264: {01001, "Bad Checksum", " while gatewayed"},
265: {01002, "Packet", " forwarded too many times"},
266: {01003, "Packet", " too large to be forwarded"},
267: {-1, 0, 0},
268: };
269:
270: /*
271: * Dump IPX Error statistics structure.
272: */
273: /*ARGSUSED*/
274: void
275: ipxerr_stats(off, name)
276: u_long off;
277: char *name;
278: {
279: struct ipx_errstat ipx_errstat;
280: register int j;
281: register int histoprint = 1;
282: int z;
283:
284: if (off == 0)
285: return;
286: kread(off, (char *)&ipx_errstat, sizeof (ipx_errstat));
287: printf("IPX error statistics:\n");
288: ANY(ipx_errstat.ipx_es_error, "call", " to ipx_error");
289: ANY(ipx_errstat.ipx_es_oldshort, "error",
290: " ignored due to insufficient addressing");
291: ANY(ipx_errstat.ipx_es_oldipx_err, "error request",
292: " in response to error packets");
293: ANY(ipx_errstat.ipx_es_tooshort, "error packet",
294: " received incomplete");
295: ANY(ipx_errstat.ipx_es_badcode, "error packet",
296: " received of unknown type");
297: for(j = 0; j < IPX_ERR_MAX; j ++) {
298: z = ipx_errstat.ipx_es_outhist[j];
299: if (z && histoprint) {
300: printf("Output Error Histogram:\n");
301: histoprint = 0;
302: }
303: ipx_erputil(z, ipx_errstat.ipx_es_codes[j]);
304:
305: }
306: histoprint = 1;
307: for(j = 0; j < IPX_ERR_MAX; j ++) {
308: z = ipx_errstat.ipx_es_inhist[j];
309: if (z && histoprint) {
310: printf("Input Error Histogram:\n");
311: histoprint = 0;
312: }
313: ipx_erputil(z, ipx_errstat.ipx_es_codes[j]);
314: }
315: }
316:
317: static void
318: ipx_erputil(z, c)
319: int z, c;
320: {
321: int j;
322: char codebuf[30];
323: char *name, *where;
324:
325: for(j = 0;; j ++) {
326: if ((name = ipx_errnames[j].name) == 0)
327: break;
328: if (ipx_errnames[j].code == c)
329: break;
330: }
331: if (name == 0) {
332: if (c > 01000)
333: where = "in transit";
334: else
335: where = "at destination";
336: sprintf(codebuf, "Unknown IPX error code 0%o", c);
337: name = codebuf;
338: } else
339: where = ipx_errnames[j].where;
340: ANY(z, name, where);
341: }
342:
343: static struct sockaddr_ipx ssipx = {AF_IPX};
344:
345: static char *
346: ipx_prpr(x)
347: struct ipx_addr *x;
348: {
349: struct sockaddr_ipx *sipx = &ssipx;
350:
351: sipx->sipx_addr = *x;
352: return(ipx_print((struct sockaddr *)sipx));
353: }