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