Annotation of previous/src/slirp/slirpdebug.c, revision 1.1.1.2

1.1       root        1: /*
                      2:  * Copyright (c) 1995 Danny Gasparovski.
                      3:  * Portions copyright (c) 2000 Kelly Price.
                      4:  * 
                      5:  * Please read the file COPYRIGHT for the 
                      6:  * terms and conditions of the copyright.
                      7:  */
                      8: 
                      9: #include <slirp.h>
                     10: 
                     11: FILE *dfd = NULL;
                     12: #ifdef DEBUG
                     13: int dostats = 1;
                     14: #else
                     15: int dostats = 0;
                     16: #endif
                     17: int slirp_debug = 0;
                     18: 
                     19: /* Carry over one item from main.c so that the tty's restored. 
                     20:  * Only done when the tty being used is /dev/tty --RedWolf */
                     21: extern struct termios slirp_tty_settings;
                     22: extern int slirp_tty_restore;
                     23: 
                     24: 
                     25: void
                     26: debug_init(file, dbg)
                     27:        char *file;
                     28:        int dbg;
                     29: {
                     30:        /* Close the old debugging file */
                     31:        if (dfd)
                     32:           fclose(dfd);
                     33:        
                     34:        dfd = fopen(file,"w");
                     35:        if (dfd != NULL) {
                     36: #if 0
                     37:                fprintf(dfd,"Slirp %s - Debugging Started.\n", SLIRP_VERSION);
                     38: #endif
                     39:                fprintf(dfd,"Debugging Started level %i.\r\n",dbg);
                     40:                fflush(dfd);
                     41:                slirp_debug = dbg;
                     42:        } else {
                     43:                lprint("Error: Debugging file \"%s\" could not be opened: %s\r\n",
                     44:                        file, strerror(errno));
                     45:        }
                     46: }
                     47: 
                     48: /*
                     49:  * Dump a packet in the same format as tcpdump -x
                     50:  */
                     51: #ifdef DEBUG
                     52: void
                     53: dump_packet(dat, n)
                     54:        void *dat;
                     55:        int n;
                     56: {
                     57:        u_char *pptr = (u_char *)dat;
                     58:        int j,k;
                     59:        
                     60:        n /= 16;
                     61:        n++;
                     62:        DEBUG_MISC((dfd, "PACKET DUMPED: \n"));
                     63:        for(j = 0; j < n; j++) {
                     64:                for(k = 0; k < 6; k++)
                     65:                        DEBUG_MISC((dfd, "%02x ", *pptr++));
                     66:                DEBUG_MISC((dfd, "\n"));
                     67:                fflush(dfd);
                     68:        }
                     69: }
                     70: #endif
                     71: 
                     72: #if 0
                     73: /*
                     74:  * Statistic routines
                     75:  * 
                     76:  * These will print statistics to the screen, the debug file (dfd), or
                     77:  * a buffer, depending on "type", so that the stats can be sent over
                     78:  * the link as well.
                     79:  */
                     80: 
                     81: void
                     82: ttystats(ttyp)
                     83:        struct ttys *ttyp;
                     84: {
                     85:        struct slirp_ifstats *is = &ttyp->ifstats;
                     86:        char buff[512];
                     87:        
                     88:        lprint(" \r\n");
                     89:        
                     90:        if (if_comp & IF_COMPRESS)
                     91:           strcpy(buff, "on");
                     92:        else if (if_comp & IF_NOCOMPRESS)
                     93:           strcpy(buff, "off");
                     94:        else
                     95:           strcpy(buff, "off (for now)");
                     96:        lprint("Unit %d:\r\n", ttyp->unit);
                     97:        lprint("  using %s encapsulation (VJ compression is %s)\r\n", (
                     98: #ifdef USE_PPP
                     99:               ttyp->proto==PROTO_PPP?"PPP":
                    100: #endif
                    101:               "SLIP"), buff);
                    102:        lprint("  %d baudrate\r\n", ttyp->baud);
                    103:        lprint("  interface is %s\r\n", ttyp->up?"up":"down");
                    104:        lprint("  using fd %d, guardian pid is %d\r\n", ttyp->fd, ttyp->pid);
                    105: #ifndef FULL_BOLT
                    106:        lprint("  towrite is %d bytes\r\n", ttyp->towrite);
                    107: #endif
                    108:        if (ttyp->zeros)
                    109:           lprint("  %d zeros have been typed\r\n", ttyp->zeros);
                    110:        else if (ttyp->ones)
                    111:           lprint("  %d ones have been typed\r\n", ttyp->ones);
                    112:        lprint("Interface stats:\r\n");
                    113:        lprint("  %6d output packets sent (%d bytes)\r\n", is->out_pkts, is->out_bytes);
                    114:        lprint("  %6d output packets dropped (%d bytes)\r\n", is->out_errpkts, is->out_errbytes);
                    115:        lprint("  %6d input packets received (%d bytes)\r\n", is->in_pkts, is->in_bytes);
                    116:        lprint("  %6d input packets dropped (%d bytes)\r\n", is->in_errpkts, is->in_errbytes);
                    117:        lprint("  %6d bad input packets\r\n", is->in_mbad);
                    118: }
                    119: 
                    120: void
                    121: allttystats()
                    122: {
                    123:        struct ttys *ttyp;
                    124:        
                    125:        for (ttyp = ttys; ttyp; ttyp = ttyp->next)
                    126:           ttystats(ttyp);
                    127: }
                    128: #endif
                    129: 
                    130: void
                    131: ipstats()
                    132: {
                    133:        lprint(" \r\n");        
                    134: 
                    135:        lprint("IP stats:\r\n");
                    136:        lprint("  %6d total packets received (%d were unaligned)\r\n",
                    137:                        ipstat.ips_total, ipstat.ips_unaligned);
                    138:        lprint("  %6d with incorrect version\r\n", ipstat.ips_badvers);
                    139:        lprint("  %6d with bad header checksum\r\n", ipstat.ips_badsum);
                    140:        lprint("  %6d with length too short (len < sizeof(iphdr))\r\n", ipstat.ips_tooshort);
                    141:        lprint("  %6d with length too small (len < ip->len)\r\n", ipstat.ips_toosmall);
                    142:        lprint("  %6d with bad header length\r\n", ipstat.ips_badhlen);
                    143:        lprint("  %6d with bad packet length\r\n", ipstat.ips_badlen);
                    144:        lprint("  %6d fragments received\r\n", ipstat.ips_fragments);
                    145:        lprint("  %6d fragments dropped\r\n", ipstat.ips_fragdropped);
                    146:        lprint("  %6d fragments timed out\r\n", ipstat.ips_fragtimeout);
                    147:        lprint("  %6d packets reassembled ok\r\n", ipstat.ips_reassembled);
                    148:        lprint("  %6d outgoing packets fragmented\r\n", ipstat.ips_fragmented);
                    149:        lprint("  %6d total outgoing fragments\r\n", ipstat.ips_ofragments);
                    150:        lprint("  %6d with bad protocol field\r\n", ipstat.ips_noproto);
                    151:        lprint("  %6d total packets delivered\r\n", ipstat.ips_delivered);
                    152: }
                    153: 
                    154: #if 0
                    155: void
                    156: vjstats()
                    157: {
                    158:        lprint(" \r\n");
                    159:        
                    160:        lprint("VJ compression stats:\r\n");
                    161:        
                    162:        lprint("  %6d outbound packets (%d compressed)\r\n",
                    163:               comp_s.sls_packets, comp_s.sls_compressed);
                    164:        lprint("  %6d searches for connection stats (%d misses)\r\n",
                    165:               comp_s.sls_searches, comp_s.sls_misses);
                    166:        lprint("  %6d inbound uncompressed packets\r\n", comp_s.sls_uncompressedin);
                    167:        lprint("  %6d inbound compressed packets\r\n", comp_s.sls_compressedin);
                    168:        lprint("  %6d inbound unknown type packets\r\n", comp_s.sls_errorin);
                    169:        lprint("  %6d inbound packets tossed due to error\r\n", comp_s.sls_tossed);
                    170: }
                    171: #endif
                    172: 
                    173: void
                    174: tcpstats()
                    175: {
                    176:        lprint(" \r\n");
                    177: 
                    178:        lprint("TCP stats:\r\n");
                    179:        
                    180:        lprint("  %6d packets sent\r\n", tcpstat.tcps_sndtotal);
                    181:        lprint("          %6d data packets (%d bytes)\r\n",
                    182:                        tcpstat.tcps_sndpack, tcpstat.tcps_sndbyte);
                    183:        lprint("          %6d data packets retransmitted (%d bytes)\r\n",
                    184:                        tcpstat.tcps_sndrexmitpack, tcpstat.tcps_sndrexmitbyte);
                    185:        lprint("          %6d ack-only packets (%d delayed)\r\n",
                    186:                        tcpstat.tcps_sndacks, tcpstat.tcps_delack);
                    187:        lprint("          %6d URG only packets\r\n", tcpstat.tcps_sndurg);
                    188:        lprint("          %6d window probe packets\r\n", tcpstat.tcps_sndprobe);
                    189:        lprint("          %6d window update packets\r\n", tcpstat.tcps_sndwinup);
                    190:        lprint("          %6d control (SYN/FIN/RST) packets\r\n", tcpstat.tcps_sndctrl);
                    191:        lprint("          %6d times tcp_output did nothing\r\n", tcpstat.tcps_didnuttin);
                    192:        
                    193:        lprint("  %6d packets received\r\n", tcpstat.tcps_rcvtotal);       
                    194:        lprint("          %6d acks (for %d bytes)\r\n",
                    195:                        tcpstat.tcps_rcvackpack, tcpstat.tcps_rcvackbyte);
                    196:        lprint("          %6d duplicate acks\r\n", tcpstat.tcps_rcvdupack);
                    197:        lprint("          %6d acks for unsent data\r\n", tcpstat.tcps_rcvacktoomuch);
                    198:        lprint("          %6d packets received in sequence (%d bytes)\r\n",
                    199:                        tcpstat.tcps_rcvpack, tcpstat.tcps_rcvbyte);
                    200:         lprint("          %6d completely duplicate packets (%d bytes)\r\n",
                    201:                        tcpstat.tcps_rcvduppack, tcpstat.tcps_rcvdupbyte);
                    202:        
                    203:        lprint("          %6d packets with some duplicate data (%d bytes duped)\r\n",
                    204:                        tcpstat.tcps_rcvpartduppack, tcpstat.tcps_rcvpartdupbyte);
                    205:        lprint("          %6d out-of-order packets (%d bytes)\r\n",
                    206:                        tcpstat.tcps_rcvoopack, tcpstat.tcps_rcvoobyte);
                    207:        lprint("          %6d packets of data after window (%d bytes)\r\n",
                    208:                        tcpstat.tcps_rcvpackafterwin, tcpstat.tcps_rcvbyteafterwin);
                    209:        lprint("          %6d window probes\r\n", tcpstat.tcps_rcvwinprobe);
                    210:        lprint("          %6d window update packets\r\n", tcpstat.tcps_rcvwinupd);
                    211:        lprint("          %6d packets received after close\r\n", tcpstat.tcps_rcvafterclose);
                    212:        lprint("          %6d discarded for bad checksums\r\n", tcpstat.tcps_rcvbadsum);
                    213:        lprint("          %6d discarded for bad header offset fields\r\n",
                    214:                        tcpstat.tcps_rcvbadoff);
                    215:        
                    216:        lprint("  %6d connection requests\r\n", tcpstat.tcps_connattempt);
                    217:        lprint("  %6d connection accepts\r\n", tcpstat.tcps_accepts);
                    218:        lprint("  %6d connections established (including accepts)\r\n", tcpstat.tcps_connects);
                    219:        lprint("  %6d connections closed (including %d drop)\r\n",
                    220:                        tcpstat.tcps_closed, tcpstat.tcps_drops);
                    221:        lprint("  %6d embryonic connections dropped\r\n", tcpstat.tcps_conndrops);
                    222:        lprint("  %6d segments we tried to get rtt (%d succeeded)\r\n",
                    223:                        tcpstat.tcps_segstimed, tcpstat.tcps_rttupdated);
                    224:        lprint("  %6d retransmit timeouts\r\n", tcpstat.tcps_rexmttimeo);
                    225:        lprint("          %6d connections dropped by rxmt timeout\r\n",
                    226:                        tcpstat.tcps_timeoutdrop);
                    227:        lprint("  %6d persist timeouts\r\n", tcpstat.tcps_persisttimeo);
                    228:        lprint("  %6d keepalive timeouts\r\n", tcpstat.tcps_keeptimeo);
                    229:        lprint("          %6d keepalive probes sent\r\n", tcpstat.tcps_keepprobe);
                    230:        lprint("          %6d connections dropped by keepalive\r\n", tcpstat.tcps_keepdrops);
                    231:        lprint("  %6d correct ACK header predictions\r\n", tcpstat.tcps_predack);
                    232:        lprint("  %6d correct data packet header predictions\n", tcpstat.tcps_preddat);
                    233:        lprint("  %6d TCP cache misses\r\n", tcpstat.tcps_socachemiss);
                    234:        
                    235:        
                    236: /*     lprint("    Packets received too short:         %d\r\n", tcpstat.tcps_rcvshort); */
                    237: /*     lprint("    Segments dropped due to PAWS:       %d\r\n", tcpstat.tcps_pawsdrop); */
                    238: 
                    239: }
                    240: 
                    241: void
                    242: udpstats()
                    243: {
                    244:         lprint(" \r\n");
                    245: 
                    246:        lprint("UDP stats:\r\n");
                    247:        lprint("  %6d datagrams received\r\n", udpstat.udps_ipackets);
                    248:        lprint("  %6d with packets shorter than header\r\n", udpstat.udps_hdrops);
                    249:        lprint("  %6d with bad checksums\r\n", udpstat.udps_badsum);
                    250:        lprint("  %6d with data length larger than packet\r\n", udpstat.udps_badlen);
                    251:        lprint("  %6d UDP socket cache misses\r\n", udpstat.udpps_pcbcachemiss);
                    252:        lprint("  %6d datagrams sent\r\n", udpstat.udps_opackets);
                    253: }
                    254: 
                    255: void
                    256: icmpstats()
                    257: {
                    258:        lprint(" \r\n");
                    259:        lprint("ICMP stats:\r\n");
                    260:        lprint("  %6d ICMP packets received\r\n", icmpstat.icps_received);
                    261:        lprint("  %6d were too short\r\n", icmpstat.icps_tooshort);
                    262:        lprint("  %6d with bad checksums\r\n", icmpstat.icps_checksum);
                    263:        lprint("  %6d with type not supported\r\n", icmpstat.icps_notsupp);
                    264:        lprint("  %6d with bad type feilds\r\n", icmpstat.icps_badtype);
                    265:        lprint("  %6d ICMP packets sent in reply\r\n", icmpstat.icps_reflect);
                    266: }
                    267: 
                    268: void
                    269: mbufstats()
                    270: {
                    271:        struct mbuf *m;
                    272:        int i;
                    273:        
                    274:         lprint(" \r\n");
                    275:        
                    276:        lprint("Mbuf stats:\r\n");
                    277: 
                    278:        lprint("  %6d mbufs allocated (%d max)\r\n", mbuf_alloced, mbuf_max);
                    279:        
                    280:        i = 0;
                    281:        for (m = m_freelist.m_next; m != &m_freelist; m = m->m_next)
                    282:                i++;
                    283:        lprint("  %6d mbufs on free list\r\n",  i);
                    284:        
                    285:        i = 0;
                    286:        for (m = m_usedlist.m_next; m != &m_usedlist; m = m->m_next)
                    287:                i++;
                    288:        lprint("  %6d mbufs on used list\r\n",  i);
                    289:         lprint("  %6d mbufs queued as packets\r\n\r\n", if_queued);
                    290: }
                    291: 
                    292: void
                    293: sockstats()
                    294: {
1.1.1.2 ! root      295:        char addr[INET_ADDRSTRLEN];
1.1       root      296:        char buff[256];
                    297:        int n;
                    298:        struct socket *so;
                    299: 
                    300:         lprint(" \r\n");
                    301:        
                    302:        lprint(
                    303:           "Proto[state]     Sock     Local Address, Port  Remote Address, Port RecvQ SendQ\r\n");
                    304:                        
                    305:        for (so = tcb.so_next; so != &tcb; so = so->so_next) {
                    306:                
                    307:                n = sprintf(buff, "tcp[%s]", so->so_tcpcb?tcpstates[so->so_tcpcb->t_state]:"NONE");
                    308:                while (n < 17)
                    309:                   buff[n++] = ' ';
                    310:                buff[17] = 0;
                    311:                lprint("%s %3d   %15s %5d ",
                    312:                                buff, so->s,
1.1.1.2 ! root      313:                                inet_ntop(AF_INET, &so->so_laddr, addr, sizeof(addr)),
        !           314:                                ntohs(so->so_lport));
1.1       root      315:                lprint("%15s %5d %5d %5d\r\n",
1.1.1.2 ! root      316:                                inet_ntop(AF_INET, &so->so_faddr, addr, sizeof(addr)),
        !           317:                                ntohs(so->so_fport),
1.1       root      318:                                so->so_rcv.sb_cc, so->so_snd.sb_cc);
                    319:        }
                    320:                   
                    321:        for (so = udb.so_next; so != &udb; so = so->so_next) {
                    322:                
                    323:                n = sprintf(buff, "udp[%d sec]", (so->so_expire - curtime) / 1000);
                    324:                while (n < 17)
                    325:                   buff[n++] = ' ';
                    326:                buff[17] = 0;
                    327:                lprint("%s %3d  %15s %5d  ",
                    328:                                buff, so->s,
1.1.1.2 ! root      329:                                inet_ntop(AF_INET, &so->so_laddr, addr, sizeof(addr)),
        !           330:                                ntohs(so->so_lport));
1.1       root      331:                lprint("%15s %5d %5d %5d\r\n",
1.1.1.2 ! root      332:                                inet_ntop(AF_INET, &so->so_faddr, addr, sizeof(addr)),
        !           333:                                ntohs(so->so_fport),
1.1       root      334:                                so->so_rcv.sb_cc, so->so_snd.sb_cc);
                    335:        }
                    336: }
                    337: 
                    338: #if 0
                    339: void
                    340: slirp_exit(exit_status)
                    341:        int exit_status;
                    342: {
                    343:        struct ttys *ttyp;
                    344:        
                    345:        DEBUG_CALL("slirp_exit");
                    346:        DEBUG_ARG("exit_status = %d", exit_status);
                    347: 
                    348:        if (dostats) {
                    349:                lprint_print = (int (*) _P((void *, const char *, va_list)))vfprintf;
                    350:                if (!dfd)
                    351:                   debug_init("slirp_stats", 0xf);
                    352:                lprint_arg = (char **)&dfd;
                    353:                
                    354:                ipstats();
                    355:                tcpstats();
                    356:                udpstats();
                    357:                icmpstats();
                    358:                mbufstats();
                    359:                sockstats();
                    360:                allttystats();
                    361:                vjstats();
                    362:        }
                    363:        
                    364:        for (ttyp = ttys; ttyp; ttyp = ttyp->next)
                    365:           tty_detached(ttyp, 1);
                    366:        
                    367:        if (slirp_forked) {
                    368:                /* Menendez time */
                    369:                if (kill(getppid(), SIGQUIT) < 0)
                    370:                        lprint("Couldn't kill parent process %ld!\n",
                    371:                            (long) getppid());
                    372:        }
                    373:        
                    374:        /* Restore the terminal if we gotta */
                    375:        if(slirp_tty_restore)
                    376:          tcsetattr(0,TCSANOW, &slirp_tty_settings);  /* NOW DAMMIT! */
                    377:        exit(exit_status);
                    378: }
                    379: #endif

unix.superglobalmegacorp.com

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