[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.13

1.13    ! deraadt     1: /*     $OpenBSD: ipx.c,v 1.12 2002/06/09 04:07:10 jsyn 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.13    ! deraadt    41: static char *rcsid = "$OpenBSD: ipx.c,v 1.12 2002/06/09 04:07:10 jsyn 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 *);
1.13    ! deraadt    81: #ifdef IPXERRORMSGS
1.10      millert    82: static void ipx_erputil(int, int);
1.13    ! deraadt    83: #endif
1.1       mickey     84:
                     85: static int first = 1;
                     86:
                     87: /*
                     88:  * Print a summary of connections related to an IPX
                     89:  * protocol.  For SPX, also give state of connection.
                     90:  * Listening processes (aflag) are suppressed unless the
                     91:  * -a (all) flag is specified.
                     92:  */
                     93:
                     94: void
1.13    ! deraadt    95: ipxprotopr(u_long off, char *name)
1.1       mickey     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
1.13    ! deraadt   167: spx_stats(u_long off, char *name)
1.1       mickey    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");
1.12      jsyn      223:        ANY(spxstat.spxs_rcvpartdupbyte, "duplicate byte", " in part-duplicate packet");
1.1       mickey    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
1.11      deraadt   237: #define ANY(x,y,z)     ((x) ? printf("\t%ld %s%s%s\n",x,y,plural(x),z) : 0)
1.1       mickey    238:
                    239: /*
                    240:  * Dump IPX statistics structure.
                    241:  */
                    242: void
1.13    ! deraadt   243: ipx_stats(u_long off, char *name)
1.1       mickey    244: {
                    245:        struct ipxstat ipxstat;
                    246:
                    247:        if (off == 0)
                    248:                return;
                    249:        kread(off, (char *)&ipxstat, sizeof (ipxstat));
                    250:        printf("%s:\n", name);
                    251:        ANY(ipxstat.ipxs_toosmall, "packet", " smaller than a header");
                    252:        ANY(ipxstat.ipxs_tooshort, "packet", " smaller than advertised");
                    253:        ANY(ipxstat.ipxs_badsum, "packet", " with bad checksums");
                    254: }
                    255:
1.6       fgsch     256: #ifdef IPXERRORMSGS
1.1       mickey    257: static struct {
                    258:        u_short code;
                    259:        char *name;
                    260:        char *where;
                    261: } ipx_errnames[] = {
1.13    ! deraadt   262:        { 0, "Unspecified Error", " at Destination" },
        !           263:        { 1, "Bad Checksum", " at Destination" },
        !           264:        { 2, "No Listener", " at Socket" },
        !           265:        { 3, "Packet", " Refused due to lack of space at Destination" },
        !           266:        { 01000, "Unspecified Error", " while gatewayed" },
        !           267:        { 01001, "Bad Checksum", " while gatewayed" },
        !           268:        { 01002, "Packet", " forwarded too many times" },
        !           269:        { 01003, "Packet", " too large to be forwarded" },
        !           270:        { -1, 0, 0 },
1.1       mickey    271: };
                    272:
                    273: /*
                    274:  * Dump IPX Error statistics structure.
                    275:  */
                    276: /*ARGSUSED*/
                    277: void
1.13    ! deraadt   278: ipxerr_stats(u_long off, char *name)
1.1       mickey    279: {
                    280:        struct ipx_errstat ipx_errstat;
1.8       mpech     281:        int j;
                    282:        int histoprint = 1;
1.1       mickey    283:        int z;
                    284:
                    285:        if (off == 0)
                    286:                return;
                    287:        kread(off, (char *)&ipx_errstat, sizeof (ipx_errstat));
                    288:        printf("IPX error statistics:\n");
                    289:        ANY(ipx_errstat.ipx_es_error, "call", " to ipx_error");
                    290:        ANY(ipx_errstat.ipx_es_oldshort, "error",
                    291:                " ignored due to insufficient addressing");
                    292:        ANY(ipx_errstat.ipx_es_oldipx_err, "error request",
                    293:                " in response to error packets");
                    294:        ANY(ipx_errstat.ipx_es_tooshort, "error packet",
                    295:                " received incomplete");
                    296:        ANY(ipx_errstat.ipx_es_badcode, "error packet",
                    297:                " received of unknown type");
1.11      deraadt   298:        for (j = 0; j < IPX_ERR_MAX; j ++) {
1.1       mickey    299:                z = ipx_errstat.ipx_es_outhist[j];
                    300:                if (z && histoprint) {
                    301:                        printf("Output Error Histogram:\n");
                    302:                        histoprint = 0;
                    303:                }
                    304:                ipx_erputil(z, ipx_errstat.ipx_es_codes[j]);
                    305:
                    306:        }
                    307:        histoprint = 1;
1.11      deraadt   308:        for (j = 0; j < IPX_ERR_MAX; j ++) {
1.1       mickey    309:                z = ipx_errstat.ipx_es_inhist[j];
                    310:                if (z && histoprint) {
                    311:                        printf("Input Error Histogram:\n");
                    312:                        histoprint = 0;
                    313:                }
                    314:                ipx_erputil(z, ipx_errstat.ipx_es_codes[j]);
                    315:        }
                    316: }
                    317:
                    318: static void
1.13    ! deraadt   319: ipx_erputil(int z, int c)
1.1       mickey    320: {
                    321:        int j;
                    322:        char codebuf[30];
                    323:        char *name, *where;
                    324:
1.11      deraadt   325:        for (j = 0;; j ++) {
1.1       mickey    326:                if ((name = ipx_errnames[j].name) == 0)
                    327:                        break;
                    328:                if (ipx_errnames[j].code == c)
                    329:                        break;
                    330:        }
1.11      deraadt   331:        if (name == 0) {
1.1       mickey    332:                if (c > 01000)
                    333:                        where = "in transit";
                    334:                else
                    335:                        where = "at destination";
1.5       deraadt   336:                snprintf(codebuf, sizeof codebuf,
                    337:                    "Unknown IPX error code 0%o", c);
1.1       mickey    338:                name = codebuf;
                    339:        } else
1.11      deraadt   340:                where = ipx_errnames[j].where;
1.1       mickey    341:        ANY(z, name, where);
                    342: }
1.6       fgsch     343: #endif /* IPXERRORMSGS */
1.1       mickey    344:
1.13    ! deraadt   345: static struct sockaddr_ipx ssipx = { AF_IPX };
1.1       mickey    346:
                    347: static char *
1.13    ! deraadt   348: ipx_prpr(struct ipx_addr *x)
1.1       mickey    349: {
                    350:        struct sockaddr_ipx *sipx = &ssipx;
                    351:
                    352:        sipx->sipx_addr = *x;
                    353:        return(ipx_print((struct sockaddr *)sipx));
                    354: }