[BACK]Return to ipx.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / netstat

Annotation of src/usr.bin/netstat/ipx.c, Revision 1.19

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