Annotation of 43BSDReno/usr.sbin/trsp/trsp.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1985 Regents of the University of California.
                      3:  * All rights reserved.
                      4:  *
                      5:  * Redistribution and use in source and binary forms are permitted provided
                      6:  * that: (1) source distributions retain this entire copyright notice and
                      7:  * comment, and (2) distributions including binaries display the following
                      8:  * acknowledgement:  ``This product includes software developed by the
                      9:  * University of California, Berkeley and its contributors'' in the
                     10:  * documentation or other materials provided with the distribution and in
                     11:  * all advertising materials mentioning features or use of this software.
                     12:  * Neither the name of the University nor the names of its contributors may
                     13:  * be used to endorse or promote products derived from this software without
                     14:  * specific prior written permission.
                     15:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
                     16:  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
                     17:  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
                     18:  */
                     19: 
                     20: #ifndef lint
                     21: char copyright[] =
                     22: "@(#) Copyright (c) 1985 Regents of the University of California.\n\
                     23:  All rights reserved.\n";
                     24: #endif /* not lint */
                     25: 
                     26: #ifndef lint
                     27: static char sccsid[] = "@(#)trsp.c     6.7 (Berkeley) 6/1/90";
                     28: #endif /* not lint */
                     29: 
                     30: #include <sys/param.h>
                     31: #include <sys/socket.h>
                     32: #include <sys/socketvar.h>
                     33: #define PRUREQUESTS
                     34: #include <sys/protosw.h>
                     35: 
                     36: #include <net/route.h>
                     37: #include <net/if.h>
                     38: 
                     39: #define TCPSTATES
                     40: #include <netinet/tcp_fsm.h>
                     41: #define        TCPTIMERS
                     42: #include <netinet/tcp_timer.h>
                     43: 
                     44: #include <netns/ns.h>
                     45: #include <netns/ns_pcb.h>
                     46: #include <netns/idp.h>
                     47: #include <netns/idp_var.h>
                     48: #include <netns/sp.h>
                     49: #include <netns/spidp.h>
                     50: #include <netns/spp_timer.h>
                     51: #include <netns/spp_var.h>
                     52: #define SANAMES
                     53: #include <netns/spp_debug.h>
                     54: 
                     55: #include <stdio.h>
                     56: #include <errno.h>
                     57: #include <nlist.h>
                     58: #include <paths.h>
                     59: 
                     60: unsigned long  ntime;
                     61: int    sflag;
                     62: int    tflag;
                     63: int    jflag;
                     64: int    aflag;
                     65: int    zflag;
                     66: int    numeric();
                     67: struct nlist nl[] = {
                     68:        { "_spp_debug" },
                     69:        { "_spp_debx" },
                     70:        0
                     71: };
                     72: struct spp_debug spp_debug[SPP_NDEBUG];
                     73: caddr_t        spp_pcbs[SPP_NDEBUG];
                     74: int    spp_debx;
                     75: 
                     76: main(argc, argv)
                     77:        int argc;
                     78:        char **argv;
                     79: {
                     80:        int i, mask = 0, npcbs = 0;
                     81:        char *system, *core;
                     82: 
                     83:        system = _PATH_UNIX;
                     84:        core = _PATH_KMEM;
                     85: 
                     86:        argc--, argv++;
                     87: again:
                     88:        if (argc > 0 && !strcmp(*argv, "-a")) {
                     89:                aflag++, argc--, argv++;
                     90:                goto again;
                     91:        }
                     92:        if (argc > 0 && !strcmp(*argv, "-z")) {
                     93:                zflag++, argc--, argv++;
                     94:                goto again;
                     95:        }
                     96:        if (argc > 0 && !strcmp(*argv, "-s")) {
                     97:                sflag++, argc--, argv++;
                     98:                goto again;
                     99:        }
                    100:        if (argc > 0 && !strcmp(*argv, "-t")) {
                    101:                tflag++, argc--, argv++;
                    102:                goto again;
                    103:        }
                    104:        if (argc > 0 && !strcmp(*argv, "-j")) {
                    105:                jflag++, argc--, argv++;
                    106:                goto again;
                    107:        }
                    108:        if (argc > 0 && !strcmp(*argv, "-p")) {
                    109:                argc--, argv++;
                    110:                if (argc < 1) {
                    111:                        fprintf(stderr, "-p: missing sppcb address\n");
                    112:                        exit(1);
                    113:                }
                    114:                if (npcbs >= SPP_NDEBUG) {
                    115:                        fprintf(stderr, "-p: too many pcb's specified\n");
                    116:                        exit(1);
                    117:                }
                    118:                sscanf(*argv, "%x", &spp_pcbs[npcbs++]);
                    119:                argc--, argv++;
                    120:                goto again;
                    121:        }
                    122:        if (argc > 0) {
                    123:                system = *argv;
                    124:                argc--, argv++;
                    125:                mask++;
                    126:        }
                    127:        if (argc > 0) {
                    128:                core = *argv;
                    129:                argc--, argv++;
                    130:                mask++;
                    131:        }
                    132:        (void) nlist(system, nl);
                    133:        if (nl[0].n_value == 0) {
                    134:                fprintf(stderr, "trsp: %s: no namelist\n", system);
                    135:                exit(1);
                    136:        }
                    137:        (void) close(0);
                    138:        if (open(core, 0) < 0) {
                    139:                fprintf(stderr, "trsp: "); perror(core);
                    140:                exit(2);
                    141:        }
                    142:        if (mask) {
                    143:                nl[0].n_value &= 0x7fffffff;
                    144:                nl[1].n_value &= 0x7fffffff;
                    145:        }
                    146:        (void) lseek(0, nl[1].n_value, 0);
                    147:        if (read(0, &spp_debx, sizeof (spp_debx)) != sizeof (spp_debx)) {
                    148:                fprintf(stderr, "trsp: "); perror("spp_debx");
                    149:                exit(3);
                    150:        }
                    151:        printf("spp_debx=%d\n", spp_debx);
                    152:        (void) lseek(0, nl[0].n_value, 0);
                    153:        if (read(0, spp_debug, sizeof (spp_debug)) != sizeof (spp_debug)) {
                    154:                fprintf(stderr, "trsp: "); perror("spp_debug");
                    155:                exit(3);
                    156:        }
                    157:        /*
                    158:         * Here, we just want to clear out the old trace data and start over.
                    159:         */
                    160:        if (zflag) {
                    161:                char *cp = (char *) spp_debug,
                    162:                     *cplim = cp + sizeof(spp_debug);
                    163:                (void) close(0);
                    164:                if (open(core, 2) < 0) {
                    165:                        fprintf(stderr, "trsp: "); perror(core);
                    166:                        exit(2);
                    167:                }
                    168:                while(cp < cplim) *cp++ = 0;
                    169:                (void) lseek(0, nl[0].n_value, 0);
                    170:                if (write(0, spp_debug, sizeof (spp_debug)) != sizeof (spp_debug)) {
                    171:                        fprintf(stderr, "trsp: "); perror("spp_debug");
                    172:                        exit(3);
                    173:                }
                    174:                (void) lseek(0, nl[1].n_value, 0);
                    175:                spp_debx = 0;
                    176:                if (write(0, &spp_debx, sizeof (spp_debx)) != sizeof (spp_debx)) {
                    177:                        fprintf(stderr, "trsp: "); perror("spp_debx");
                    178:                        exit(3);
                    179:                }
                    180:                exit(0);
                    181:        }
                    182:        /*
                    183:         * If no control blocks have been specified, figure
                    184:         * out how many distinct one we have and summarize
                    185:         * them in spp_pcbs for sorting the trace records
                    186:         * below.
                    187:         */
                    188:        if (npcbs == 0) {
                    189:                for (i = 0; i < SPP_NDEBUG; i++) {
                    190:                        register int j;
                    191:                        register struct spp_debug *sd = &spp_debug[i];
                    192: 
                    193:                        if (sd->sd_cb == 0)
                    194:                                continue;
                    195:                        for (j = 0; j < npcbs; j++)
                    196:                                if (spp_pcbs[j] == sd->sd_cb)
                    197:                                        break;
                    198:                        if (j >= npcbs)
                    199:                                spp_pcbs[npcbs++] = sd->sd_cb;
                    200:                }
                    201:        }
                    202:        qsort(spp_pcbs, npcbs, sizeof (caddr_t), numeric);
                    203:        if (jflag) {
                    204:                char *cp = "";
                    205: 
                    206:                for (i = 0; i < npcbs; i++) {
                    207:                        printf("%s%x", cp, spp_pcbs[i]);
                    208:                        cp = ", ";
                    209:                }
                    210:                if (*cp)
                    211:                        putchar('\n');
                    212:                exit(0);
                    213:        }
                    214:        for (i = 0; i < npcbs; i++) {
                    215:                printf("\n%x:\n", spp_pcbs[i]);
                    216:                dotrace(spp_pcbs[i]);
                    217:        }
                    218:        exit(0);
                    219: }
                    220: 
                    221: dotrace(sppcb)
                    222:        register caddr_t sppcb;
                    223: {
                    224:        register int i;
                    225:        register struct spp_debug *sd;
                    226: 
                    227:        for (i = spp_debx % SPP_NDEBUG; i < SPP_NDEBUG; i++) {
                    228:                sd = &spp_debug[i];
                    229:                if (sppcb && sd->sd_cb != sppcb)
                    230:                        continue;
                    231:                ntime = ntohl(sd->sd_time);
                    232:                spp_trace(sd->sd_act, sd->sd_ostate, sd->sd_cb, &sd->sd_sp,
                    233:                    &sd->sd_si, sd->sd_req);
                    234:        }
                    235:        for (i = 0; i < spp_debx % SPP_NDEBUG; i++) {
                    236:                sd = &spp_debug[i];
                    237:                if (sppcb && sd->sd_cb != sppcb)
                    238:                        continue;
                    239:                ntime = ntohl(sd->sd_time);
                    240:                spp_trace(sd->sd_act, sd->sd_ostate, sd->sd_cb, &sd->sd_sp,
                    241:                    &sd->sd_si, sd->sd_req);
                    242:        }
                    243: }
                    244: 
                    245: ptime(ms)
                    246:        int ms;
                    247: {
                    248: 
                    249:        printf("%03d ", (ms/10) % 1000);
                    250: }
                    251: 
                    252: numeric(c1, c2)
                    253:        caddr_t *c1, *c2;
                    254: {
                    255:        
                    256:        return (*c1 - *c2);
                    257: }
                    258: 
                    259: spp_trace(act, ostate, asp, sp, si, req)
                    260:        short act, ostate;
                    261:        struct sppcb *asp, *sp;
                    262:        struct spidp *si;
                    263:        int req;
                    264: {
                    265:        u_short seq, ack, len, alo;
                    266:        int flags, timer;
                    267:        char *cp;
                    268: 
                    269:        if(ostate >= TCP_NSTATES) ostate = 0;
                    270:        if(act > SA_DROP) act = SA_DROP;
                    271:        printf("\n");
                    272:        ptime(ntime);
                    273:        printf("%s:%s", tcpstates[ostate], sanames[act]);
                    274: 
                    275:        if (si != 0) {
                    276:                seq = si->si_seq;
                    277:                ack = si->si_ack;
                    278:                alo = si->si_alo;
                    279:                len = si->si_len;
                    280:                switch (act) {
                    281:                case SA_RESPOND:
                    282:                case SA_OUTPUT:
                    283:                                seq = ntohs(seq);
                    284:                                ack = ntohs(ack);
                    285:                                alo = ntohs(alo);
                    286:                                len = ntohs(len);
                    287:                case SA_INPUT:
                    288:                case SA_DROP:
                    289:                        if (aflag) {
                    290:                                printf("\n\tsna=");
                    291:                                ns_printhost(&si->si_sna);
                    292:                                printf("\tdna=");
                    293:                                ns_printhost(&si->si_dna);
                    294:                        }
                    295:                        printf("\n\t");
                    296: #define p1(f)  { printf("%s = %x, ", "f", f); }
                    297:                        p1(seq); p1(ack); p1(alo); p1(len);
                    298:                        flags = si->si_cc;
                    299:                        printf("flags=%x", flags);
                    300:                        if (flags) {
                    301:                                char *cp = "<";
                    302: #define pf(f) { if (flags&f) { printf("%s%s", cp, "f"); cp = ","; } }
                    303:                                pf(SP_SP); pf(SP_SA); pf(SP_OB); pf(SP_EM);
                    304:                                printf(">");
                    305:                        }
                    306:                        printf(", ");
                    307: #define p2(f)  { printf("%s = %x, ", "f", si->si_/**/f); }
                    308:                        p2(sid);p2(did);p2(dt);
                    309:                        printf("\n\tsna=");
                    310:                        ns_printhost(&si->si_sna);
                    311:                        printf("\tdna=");
                    312:                        ns_printhost(&si->si_dna);
                    313:                }
                    314:        }
                    315:        if(act == SA_USER) {
                    316:                printf("\treq=%s", prurequests[req&0xff]);
                    317:                if ((req & 0xff) == PRU_SLOWTIMO)
                    318:                        printf("<%s>", tcptimers[req>>8]);
                    319:        }
                    320:        printf(" -> %s", tcpstates[sp->s_state]);
                    321: 
                    322:        /* print out internal state of sp !?! */
                    323:        printf("\n");
                    324:        if (sp == 0)
                    325:                return;
                    326: #define p3(f)  { printf("%s = %x, ", "f", sp->s_/**/f); }
                    327:        if(sflag) {
                    328:                printf("\t"); p3(rack); p3(ralo); p3(smax); p3(snxt); p3(flags);
                    329: #undef pf
                    330: #define pf(f) { if (flags&SF_/**/f) { printf("%s%s", cp, "f"); cp = ","; } }
                    331:                flags = sp->s_flags;
                    332:                if (flags || sp->s_oobflags) {
                    333:                        char *cp = "<";
                    334:                        pf(ACKNOW); pf(DELACK); pf(HI); pf(HO);
                    335:                        pf(PI); pf(WIN); pf(RXT); pf(RVD);
                    336:                        flags = sp->s_oobflags;
                    337:                        pf(SOOB); pf(IOOB);
                    338:                        printf(">");
                    339:                }
                    340: 
                    341:        }
                    342:        /* print out timers? */
                    343:        if (tflag) {
                    344:                char *cp = "\t";
                    345:                register int i;
                    346: 
                    347:                printf("\n\tTIMERS: ");
                    348:                p3(idle); p3(force); p3(rtseq);
                    349:                for (i = 0; i < TCPT_NTIMERS; i++) {
                    350:                        if (sp->s_timer[i] == 0)
                    351:                                continue;
                    352:                        printf("%s%s=%d", cp, tcptimers[i], sp->s_timer[i]);
                    353:                        if (i == TCPT_REXMT)
                    354:                                printf(" (s_rxtshft=%d)", sp->s_rxtshift);
                    355:                        cp = ", ";
                    356:                }
                    357:                if (*cp != '\t')
                    358:                        putchar('\n');
                    359:        }
                    360: }
                    361: 
                    362: ns_printhost(p)
                    363: register struct ns_addr *p;
                    364: {
                    365: 
                    366:        printf("<net:%x%x,host:%4.4x%4.4x%4.4x,port:%x>",
                    367:                        p->x_net.s_net[0],
                    368:                        p->x_net.s_net[1],
                    369:                        p->x_host.s_host[0],
                    370:                        p->x_host.s_host[1],
                    371:                        p->x_host.s_host[2],
                    372:                        p->x_port);
                    373: 
                    374: }
                    375: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.