Annotation of src/usr.bin/netstat/ipx.c, Revision 1.5
1.5 ! deraadt 1: /* $OpenBSD: ipx.c,v 1.4 1997/06/29 21:46:01 millert 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.5 ! deraadt 41: static char *rcsid = "$OpenBSD: ipx.c,v 1.4 1997/06/29 21:46:01 millert 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:
1.4 millert 67: #include <limits.h>
1.1 mickey 68: #include <nlist.h>
69: #include <errno.h>
70: #include <stdio.h>
71: #include <string.h>
72: #include "netstat.h"
73:
74: struct ipxpcb ipxpcb;
75: struct spxpcb spxpcb;
76: struct socket sockb;
77:
78: static char *ipx_prpr __P((struct ipx_addr *));
79: static void ipx_erputil __P((int, int));
80:
81: static int first = 1;
82:
83: /*
84: * Print a summary of connections related to an IPX
85: * protocol. For SPX, also give state of connection.
86: * Listening processes (aflag) are suppressed unless the
87: * -a (all) flag is specified.
88: */
89:
90: void
91: ipxprotopr(off, name)
92: u_long off;
93: char *name;
94: {
95: struct ipxpcbtable table;
96: register struct ipxpcb *head, *prev, *next;
97: int isspx;
98:
99: if (off == 0)
100: return;
101: isspx = strcmp(name, "spx") == 0;
102: kread(off, (char *)&table, sizeof (table));
103: prev = head = (struct ipxpcb *)
104: &((struct ipxpcbtable *)off)->ipxpt_queue.cqh_first;
105: next = table.ipxpt_queue.cqh_first;
106:
107: while (next != head) {
108: kread((u_long)next, (char *)&ipxpcb, sizeof (ipxpcb));
109: if (ipxpcb.ipxp_queue.cqe_prev != prev) {
110: printf("???\n");
111: break;
112: }
113: prev = next;
114: next = ipxpcb.ipxp_queue.cqe_next;
115:
116: if (!aflag && ipx_nullhost(ipxpcb.ipxp_faddr) )
117: continue;
118:
119: kread((u_long)ipxpcb.ipxp_socket,
120: (char *)&sockb, sizeof (sockb));
121: if (isspx) {
122: kread((u_long)ipxpcb.ipxp_ppcb,
123: (char *)&spxpcb, sizeof (spxpcb));
124: }
125: if (first) {
126: printf("Active Internetwork Packet Exchange connections");
127: if (aflag)
128: printf(" (including servers)");
129: putchar('\n');
1.4 millert 130: if (Aflag)
131: printf("%-*.*s %-5.5s %-6.6s %-6.6s %-*.*s %-*.*s %s\n",
132: PLEN, PLEN, "PCB", "Proto", "Recv-Q",
133: "Send-Q", PLEN, PLEN, "Local Address",
134: PLEN, PLEN, "Foreign Address", "(state)");
135: else
136: printf("%-5.5s %-6.6s %-6.6s %-22.22s %-22.22s %s\n",
137: "Proto", "Recv-Q", "Send-Q",
138: "Local Address", "Foreign Address",
139: "(state)");
1.1 mickey 140: first = 0;
141: }
142: if (Aflag)
1.4 millert 143: printf("%*p ", PLEN, ipxpcb.ipxp_ppcb);
1.2 millert 144: printf("%-5.5s %6ld %6ld ", name, sockb.so_rcv.sb_cc,
1.1 mickey 145: sockb.so_snd.sb_cc);
146: printf(" %-22.22s", ipx_prpr(&ipxpcb.ipxp_laddr));
147: printf(" %-22.22s", ipx_prpr(&ipxpcb.ipxp_faddr));
148: if (isspx) {
149: extern char *tcpstates[];
150: if (spxpcb.s_state >= TCP_NSTATES)
151: printf(" %d", spxpcb.s_state);
152: else
153: printf(" %s", tcpstates[spxpcb.s_state]);
154: }
155: putchar('\n');
156: }
157: }
158: #define ANY(x,y,z) \
1.2 millert 159: ((x) ? printf("\t%ld %s%s%s -- %s\n",x,y,plural(x),z,"x") : 0)
1.1 mickey 160:
161: /*
162: * Dump SPX statistics structure.
163: */
164: void
165: spx_stats(off, name)
166: u_long off;
167: char *name;
168: {
169: struct spx_istat spx_istat;
170: #define spxstat spx_istat.newstats
171:
172: if (off == 0)
173: return;
174: kread(off, (char *)&spx_istat, sizeof (spx_istat));
175: printf("%s:\n", name);
1.2 millert 176: ANY((long)spx_istat.nonucn, "connection", " dropped due to no new sockets ");
177: ANY((long)spx_istat.gonawy, "connection", " terminated due to our end dying");
178: ANY((long)spx_istat.nonucn, "connection",
1.1 mickey 179: " dropped due to inability to connect");
1.2 millert 180: ANY((long)spx_istat.noconn, "connection",
1.1 mickey 181: " dropped due to inability to connect");
1.2 millert 182: ANY((long)spx_istat.notme, "connection",
1.1 mickey 183: " incompleted due to mismatched id's");
1.2 millert 184: ANY((long)spx_istat.wrncon, "connection", " dropped due to mismatched id's");
185: ANY((long)spx_istat.bdreas, "packet", " dropped out of sequence");
186: ANY((long)spx_istat.lstdup, "packet", " duplicating the highest packet");
187: ANY((long)spx_istat.notyet, "packet", " refused as exceeding allocation");
1.1 mickey 188: ANY(spxstat.spxs_connattempt, "connection", " initiated");
189: ANY(spxstat.spxs_accepts, "connection", " accepted");
190: ANY(spxstat.spxs_connects, "connection", " established");
191: ANY(spxstat.spxs_drops, "connection", " dropped");
192: ANY(spxstat.spxs_conndrops, "embryonic connection", " dropped");
193: ANY(spxstat.spxs_closed, "connection", " closed (includes drops)");
194: ANY(spxstat.spxs_segstimed, "packet", " where we tried to get rtt");
195: ANY(spxstat.spxs_rttupdated, "time", " we got rtt");
196: ANY(spxstat.spxs_delack, "delayed ack", " sent");
197: ANY(spxstat.spxs_timeoutdrop, "connection", " dropped in rxmt timeout");
198: ANY(spxstat.spxs_rexmttimeo, "retransmit timeout", "");
199: ANY(spxstat.spxs_persisttimeo, "persist timeout", "");
200: ANY(spxstat.spxs_keeptimeo, "keepalive timeout", "");
201: ANY(spxstat.spxs_keepprobe, "keepalive probe", " sent");
202: ANY(spxstat.spxs_keepdrops, "connection", " dropped in keepalive");
203: ANY(spxstat.spxs_sndtotal, "total packet", " sent");
204: ANY(spxstat.spxs_sndpack, "data packet", " sent");
205: ANY(spxstat.spxs_sndbyte, "data byte", " sent");
206: ANY(spxstat.spxs_sndrexmitpack, "data packet", " retransmitted");
207: ANY(spxstat.spxs_sndrexmitbyte, "data byte", " retransmitted");
208: ANY(spxstat.spxs_sndacks, "ack-only packet", " sent");
209: ANY(spxstat.spxs_sndprobe, "window probe", " sent");
210: ANY(spxstat.spxs_sndurg, "packet", " sent with URG only");
211: ANY(spxstat.spxs_sndwinup, "window update-only packet", " sent");
212: ANY(spxstat.spxs_sndctrl, "control (SYN|FIN|RST) packet", " sent");
213: ANY(spxstat.spxs_sndvoid, "request", " to send a non-existant packet");
214: ANY(spxstat.spxs_rcvtotal, "total packet", " received");
215: ANY(spxstat.spxs_rcvpack, "packet", " received in sequence");
216: ANY(spxstat.spxs_rcvbyte, "byte", " received in sequence");
217: ANY(spxstat.spxs_rcvbadsum, "packet", " received with ccksum errs");
218: ANY(spxstat.spxs_rcvbadoff, "packet", " received with bad offset");
219: ANY(spxstat.spxs_rcvshort, "packet", " received too short");
220: ANY(spxstat.spxs_rcvduppack, "duplicate-only packet", " received");
221: ANY(spxstat.spxs_rcvdupbyte, "duplicate-only byte", " received");
222: ANY(spxstat.spxs_rcvpartduppack, "packet", " with some duplicate data");
223: ANY(spxstat.spxs_rcvpartdupbyte, "dup. byte", " in part-dup. packet");
224: ANY(spxstat.spxs_rcvoopack, "out-of-order packet", " received");
225: ANY(spxstat.spxs_rcvoobyte, "out-of-order byte", " received");
226: ANY(spxstat.spxs_rcvpackafterwin, "packet", " with data after window");
227: ANY(spxstat.spxs_rcvbyteafterwin, "byte", " rcvd after window");
228: ANY(spxstat.spxs_rcvafterclose, "packet", " rcvd after 'close'");
229: ANY(spxstat.spxs_rcvwinprobe, "rcvd window probe packet", "");
230: ANY(spxstat.spxs_rcvdupack, "rcvd duplicate ack", "");
231: ANY(spxstat.spxs_rcvacktoomuch, "rcvd ack", " for unsent data");
232: ANY(spxstat.spxs_rcvackpack, "rcvd ack packet", "");
233: ANY(spxstat.spxs_rcvackbyte, "byte", " acked by rcvd acks");
234: ANY(spxstat.spxs_rcvwinupd, "rcvd window update packet", "");
235: }
236: #undef ANY
237: #define ANY(x,y,z) ((x) ? printf("\t%d %s%s%s\n",x,y,plural(x),z) : 0)
238:
239: /*
240: * Dump IPX statistics structure.
241: */
242: void
243: ipx_stats(off, name)
244: u_long off;
245: char *name;
246: {
247: struct ipxstat ipxstat;
248:
249: if (off == 0)
250: return;
251: kread(off, (char *)&ipxstat, sizeof (ipxstat));
252: printf("%s:\n", name);
253: ANY(ipxstat.ipxs_toosmall, "packet", " smaller than a header");
254: ANY(ipxstat.ipxs_tooshort, "packet", " smaller than advertised");
255: ANY(ipxstat.ipxs_badsum, "packet", " with bad checksums");
256: }
257:
258: static struct {
259: u_short code;
260: char *name;
261: char *where;
262: } ipx_errnames[] = {
263: {0, "Unspecified Error", " at Destination"},
264: {1, "Bad Checksum", " at Destination"},
265: {2, "No Listener", " at Socket"},
266: {3, "Packet", " Refused due to lack of space at Destination"},
267: {01000, "Unspecified Error", " while gatewayed"},
268: {01001, "Bad Checksum", " while gatewayed"},
269: {01002, "Packet", " forwarded too many times"},
270: {01003, "Packet", " too large to be forwarded"},
271: {-1, 0, 0},
272: };
273:
274: /*
275: * Dump IPX Error statistics structure.
276: */
277: /*ARGSUSED*/
278: void
279: ipxerr_stats(off, name)
280: u_long off;
281: char *name;
282: {
283: struct ipx_errstat ipx_errstat;
284: register int j;
285: register int histoprint = 1;
286: int z;
287:
288: if (off == 0)
289: return;
290: kread(off, (char *)&ipx_errstat, sizeof (ipx_errstat));
291: printf("IPX error statistics:\n");
292: ANY(ipx_errstat.ipx_es_error, "call", " to ipx_error");
293: ANY(ipx_errstat.ipx_es_oldshort, "error",
294: " ignored due to insufficient addressing");
295: ANY(ipx_errstat.ipx_es_oldipx_err, "error request",
296: " in response to error packets");
297: ANY(ipx_errstat.ipx_es_tooshort, "error packet",
298: " received incomplete");
299: ANY(ipx_errstat.ipx_es_badcode, "error packet",
300: " received of unknown type");
301: for(j = 0; j < IPX_ERR_MAX; j ++) {
302: z = ipx_errstat.ipx_es_outhist[j];
303: if (z && histoprint) {
304: printf("Output Error Histogram:\n");
305: histoprint = 0;
306: }
307: ipx_erputil(z, ipx_errstat.ipx_es_codes[j]);
308:
309: }
310: histoprint = 1;
311: for(j = 0; j < IPX_ERR_MAX; j ++) {
312: z = ipx_errstat.ipx_es_inhist[j];
313: if (z && histoprint) {
314: printf("Input Error Histogram:\n");
315: histoprint = 0;
316: }
317: ipx_erputil(z, ipx_errstat.ipx_es_codes[j]);
318: }
319: }
320:
321: static void
322: ipx_erputil(z, c)
323: int z, c;
324: {
325: int j;
326: char codebuf[30];
327: char *name, *where;
328:
329: for(j = 0;; j ++) {
330: if ((name = ipx_errnames[j].name) == 0)
331: break;
332: if (ipx_errnames[j].code == c)
333: break;
334: }
335: if (name == 0) {
336: if (c > 01000)
337: where = "in transit";
338: else
339: where = "at destination";
1.5 ! deraadt 340: snprintf(codebuf, sizeof codebuf,
! 341: "Unknown IPX error code 0%o", c);
1.1 mickey 342: name = codebuf;
343: } else
344: where = ipx_errnames[j].where;
345: ANY(z, name, where);
346: }
347:
348: static struct sockaddr_ipx ssipx = {AF_IPX};
349:
350: static char *
351: ipx_prpr(x)
352: struct ipx_addr *x;
353: {
354: struct sockaddr_ipx *sipx = &ssipx;
355:
356: sipx->sipx_addr = *x;
357: return(ipx_print((struct sockaddr *)sipx));
358: }