18b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project/* 28b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project * Copyright (c) 1995 Danny Gasparovski. 38b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project * Portions copyright (c) 2000 Kelly Price. 45d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner * 55d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner * Please read the file COPYRIGHT for the 68b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project * terms and conditions of the copyright. 78b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project */ 88b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project 98b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#include <slirp.h> 108b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project 118b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source ProjectFILE *dfd = NULL; 128b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#ifdef DEBUG 138b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Projectint dostats = 1; 148b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#else 158b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Projectint dostats = 0; 168b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#endif 178b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Projectint slirp_debug = 0; 188b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project 195d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner/* Carry over one item from main.c so that the tty's restored. 208b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project * Only done when the tty being used is /dev/tty --RedWolf */ 215d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner#ifndef CONFIG_QEMU 228b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Projectextern struct termios slirp_tty_settings; 238b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Projectextern int slirp_tty_restore; 248b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project 258b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project 268b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Projectvoid 278b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Projectdebug_init(file, dbg) 288b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project char *file; 298b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project int dbg; 308b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project{ 318b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project /* Close the old debugging file */ 328b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project if (dfd) 338b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project fclose(dfd); 345d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner 358b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project dfd = fopen(file,"w"); 368b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project if (dfd != NULL) { 378b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#if 0 388b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project fprintf(dfd,"Slirp %s - Debugging Started.\n", SLIRP_VERSION); 398b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#endif 408b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project fprintf(dfd,"Debugging Started level %i.\r\n",dbg); 418b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project fflush(dfd); 428b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project slirp_debug = dbg; 438b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project } else { 445d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner lprint("Error: Debugging file \"%s\" could not be opened: %s\r\n", 458b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project file, strerror(errno)); 468b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project } 478b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project} 488b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project 498b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project/* 508b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project * Dump a packet in the same format as tcpdump -x 518b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project */ 528b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#ifdef DEBUG 538b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Projectvoid 548b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Projectdump_packet(dat, n) 558b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project void *dat; 568b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project int n; 578b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project{ 588b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project u_char *pptr = (u_char *)dat; 598b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project int j,k; 605d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner 618b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project n /= 16; 628b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project n++; 638b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project DEBUG_MISC((dfd, "PACKET DUMPED: \n")); 648b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project for(j = 0; j < n; j++) { 658b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project for(k = 0; k < 6; k++) 668b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project DEBUG_MISC((dfd, "%02x ", *pptr++)); 678b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project DEBUG_MISC((dfd, "\n")); 688b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project fflush(dfd); 698b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project } 708b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project} 718b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#endif 725d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner#endif 738b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project 745d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner#ifdef LOG_ENABLED 758b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#if 0 768b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project/* 778b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project * Statistic routines 785d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner * 798b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project * These will print statistics to the screen, the debug file (dfd), or 808b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project * a buffer, depending on "type", so that the stats can be sent over 818b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project * the link as well. 828b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project */ 838b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project 845d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turnerstatic void 858b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Projectttystats(ttyp) 868b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project struct ttys *ttyp; 878b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project{ 888b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project struct slirp_ifstats *is = &ttyp->ifstats; 898b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project char buff[512]; 905d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner 918b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" \r\n"); 925d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner 935d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner if (IF_COMP & IF_COMPRESS) 948b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project strcpy(buff, "on"); 955d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner else if (IF_COMP & IF_NOCOMPRESS) 968b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project strcpy(buff, "off"); 978b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project else 988b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project strcpy(buff, "off (for now)"); 998b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint("Unit %d:\r\n", ttyp->unit); 1008b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" using %s encapsulation (VJ compression is %s)\r\n", ( 1018b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#ifdef USE_PPP 1028b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project ttyp->proto==PROTO_PPP?"PPP": 1038b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#endif 1048b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project "SLIP"), buff); 1058b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %d baudrate\r\n", ttyp->baud); 1068b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" interface is %s\r\n", ttyp->up?"up":"down"); 1078b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" using fd %d, guardian pid is %d\r\n", ttyp->fd, ttyp->pid); 1088b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#ifndef FULL_BOLT 1098b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" towrite is %d bytes\r\n", ttyp->towrite); 1108b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#endif 1118b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project if (ttyp->zeros) 1128b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %d zeros have been typed\r\n", ttyp->zeros); 1138b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project else if (ttyp->ones) 1148b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %d ones have been typed\r\n", ttyp->ones); 1158b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint("Interface stats:\r\n"); 1168b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d output packets sent (%d bytes)\r\n", is->out_pkts, is->out_bytes); 1178b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d output packets dropped (%d bytes)\r\n", is->out_errpkts, is->out_errbytes); 1188b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d input packets received (%d bytes)\r\n", is->in_pkts, is->in_bytes); 1198b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d input packets dropped (%d bytes)\r\n", is->in_errpkts, is->in_errbytes); 1208b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d bad input packets\r\n", is->in_mbad); 1218b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project} 1228b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project 1235d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turnerstatic void 1245d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turnerallttystats(void) 1258b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project{ 1268b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project struct ttys *ttyp; 1275d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner 1288b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project for (ttyp = ttys; ttyp; ttyp = ttyp->next) 1298b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project ttystats(ttyp); 1308b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project} 1318b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#endif 1328b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project 1335d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turnerstatic void 1345d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turneripstats(void) 1358b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project{ 1365d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner lprint(" \r\n"); 1378b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project 1388b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint("IP stats:\r\n"); 1398b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d total packets received (%d were unaligned)\r\n", 1408b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project ipstat.ips_total, ipstat.ips_unaligned); 1418b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d with incorrect version\r\n", ipstat.ips_badvers); 1428b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d with bad header checksum\r\n", ipstat.ips_badsum); 1438b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d with length too short (len < sizeof(iphdr))\r\n", ipstat.ips_tooshort); 1448b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d with length too small (len < ip->len)\r\n", ipstat.ips_toosmall); 1458b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d with bad header length\r\n", ipstat.ips_badhlen); 1468b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d with bad packet length\r\n", ipstat.ips_badlen); 1478b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d fragments received\r\n", ipstat.ips_fragments); 1488b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d fragments dropped\r\n", ipstat.ips_fragdropped); 1498b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d fragments timed out\r\n", ipstat.ips_fragtimeout); 1508b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d packets reassembled ok\r\n", ipstat.ips_reassembled); 1518b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d outgoing packets fragmented\r\n", ipstat.ips_fragmented); 1528b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d total outgoing fragments\r\n", ipstat.ips_ofragments); 1538b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d with bad protocol field\r\n", ipstat.ips_noproto); 1548b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d total packets delivered\r\n", ipstat.ips_delivered); 1558b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project} 1568b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project 1575d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner#ifndef CONFIG_QEMU 1585d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turnerstatic void 1595d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turnervjstats(void) 1608b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project{ 1618b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" \r\n"); 1625d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner 1638b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint("VJ compression stats:\r\n"); 1645d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner 1658b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d outbound packets (%d compressed)\r\n", 1668b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project comp_s.sls_packets, comp_s.sls_compressed); 1678b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d searches for connection stats (%d misses)\r\n", 1688b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project comp_s.sls_searches, comp_s.sls_misses); 1698b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d inbound uncompressed packets\r\n", comp_s.sls_uncompressedin); 1708b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d inbound compressed packets\r\n", comp_s.sls_compressedin); 1718b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d inbound unknown type packets\r\n", comp_s.sls_errorin); 1728b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d inbound packets tossed due to error\r\n", comp_s.sls_tossed); 1738b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project} 1748b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#endif 1758b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project 1765d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turnerstatic void 1775d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turnertcpstats(void) 1788b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project{ 1798b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" \r\n"); 1808b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project 1818b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint("TCP stats:\r\n"); 1825d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner 1838b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d packets sent\r\n", tcpstat.tcps_sndtotal); 1848b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d data packets (%d bytes)\r\n", 1858b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project tcpstat.tcps_sndpack, tcpstat.tcps_sndbyte); 1868b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d data packets retransmitted (%d bytes)\r\n", 1878b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project tcpstat.tcps_sndrexmitpack, tcpstat.tcps_sndrexmitbyte); 1888b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d ack-only packets (%d delayed)\r\n", 1898b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project tcpstat.tcps_sndacks, tcpstat.tcps_delack); 1908b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d URG only packets\r\n", tcpstat.tcps_sndurg); 1918b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d window probe packets\r\n", tcpstat.tcps_sndprobe); 1928b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d window update packets\r\n", tcpstat.tcps_sndwinup); 1938b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d control (SYN/FIN/RST) packets\r\n", tcpstat.tcps_sndctrl); 1948b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d times tcp_output did nothing\r\n", tcpstat.tcps_didnuttin); 1955d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner 1965d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner lprint(" %6d packets received\r\n", tcpstat.tcps_rcvtotal); 1978b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d acks (for %d bytes)\r\n", 1988b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project tcpstat.tcps_rcvackpack, tcpstat.tcps_rcvackbyte); 1998b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d duplicate acks\r\n", tcpstat.tcps_rcvdupack); 2008b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d acks for unsent data\r\n", tcpstat.tcps_rcvacktoomuch); 2018b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d packets received in sequence (%d bytes)\r\n", 2028b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project tcpstat.tcps_rcvpack, tcpstat.tcps_rcvbyte); 2038b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d completely duplicate packets (%d bytes)\r\n", 2048b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project tcpstat.tcps_rcvduppack, tcpstat.tcps_rcvdupbyte); 2055d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner 2068b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d packets with some duplicate data (%d bytes duped)\r\n", 2078b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project tcpstat.tcps_rcvpartduppack, tcpstat.tcps_rcvpartdupbyte); 2088b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d out-of-order packets (%d bytes)\r\n", 2098b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project tcpstat.tcps_rcvoopack, tcpstat.tcps_rcvoobyte); 2108b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d packets of data after window (%d bytes)\r\n", 2118b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project tcpstat.tcps_rcvpackafterwin, tcpstat.tcps_rcvbyteafterwin); 2128b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d window probes\r\n", tcpstat.tcps_rcvwinprobe); 2138b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d window update packets\r\n", tcpstat.tcps_rcvwinupd); 2148b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d packets received after close\r\n", tcpstat.tcps_rcvafterclose); 2158b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d discarded for bad checksums\r\n", tcpstat.tcps_rcvbadsum); 2168b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d discarded for bad header offset fields\r\n", 2178b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project tcpstat.tcps_rcvbadoff); 2185d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner 2198b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d connection requests\r\n", tcpstat.tcps_connattempt); 2208b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d connection accepts\r\n", tcpstat.tcps_accepts); 2218b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d connections established (including accepts)\r\n", tcpstat.tcps_connects); 2228b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d connections closed (including %d drop)\r\n", 2238b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project tcpstat.tcps_closed, tcpstat.tcps_drops); 2248b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d embryonic connections dropped\r\n", tcpstat.tcps_conndrops); 2258b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d segments we tried to get rtt (%d succeeded)\r\n", 2268b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project tcpstat.tcps_segstimed, tcpstat.tcps_rttupdated); 2278b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d retransmit timeouts\r\n", tcpstat.tcps_rexmttimeo); 2288b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d connections dropped by rxmt timeout\r\n", 2298b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project tcpstat.tcps_timeoutdrop); 2308b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d persist timeouts\r\n", tcpstat.tcps_persisttimeo); 2318b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d keepalive timeouts\r\n", tcpstat.tcps_keeptimeo); 2328b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d keepalive probes sent\r\n", tcpstat.tcps_keepprobe); 2338b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d connections dropped by keepalive\r\n", tcpstat.tcps_keepdrops); 2348b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d correct ACK header predictions\r\n", tcpstat.tcps_predack); 2358b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d correct data packet header predictions\n", tcpstat.tcps_preddat); 2368b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d TCP cache misses\r\n", tcpstat.tcps_socachemiss); 2375d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner 2385d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner 2398b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project/* lprint(" Packets received too short: %d\r\n", tcpstat.tcps_rcvshort); */ 2408b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project/* lprint(" Segments dropped due to PAWS: %d\r\n", tcpstat.tcps_pawsdrop); */ 2418b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project 2428b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project} 2438b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project 2445d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turnerstatic void 2455d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turnerudpstats(void) 2468b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project{ 2478b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" \r\n"); 2488b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project 2498b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint("UDP stats:\r\n"); 2508b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d datagrams received\r\n", udpstat.udps_ipackets); 2518b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d with packets shorter than header\r\n", udpstat.udps_hdrops); 2528b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d with bad checksums\r\n", udpstat.udps_badsum); 2538b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d with data length larger than packet\r\n", udpstat.udps_badlen); 2548b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d UDP socket cache misses\r\n", udpstat.udpps_pcbcachemiss); 2558b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d datagrams sent\r\n", udpstat.udps_opackets); 2568b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project} 2578b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project 2585d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turnerstatic void 2595d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turnericmpstats(void) 2608b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project{ 2618b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" \r\n"); 2628b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint("ICMP stats:\r\n"); 2638b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d ICMP packets received\r\n", icmpstat.icps_received); 2648b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d were too short\r\n", icmpstat.icps_tooshort); 2658b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d with bad checksums\r\n", icmpstat.icps_checksum); 2668b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d with type not supported\r\n", icmpstat.icps_notsupp); 2678b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d with bad type feilds\r\n", icmpstat.icps_badtype); 2688b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" %6d ICMP packets sent in reply\r\n", icmpstat.icps_reflect); 2698b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project} 2708b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project 2715d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turnerstatic void 2725d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turnermbufstats(void) 2735d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner{ 2745d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner struct mbuf *m; 2755d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner int i; 2765d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner 2775d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner lprint(" \r\n"); 2785d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner 2795d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner lprint("Mbuf stats:\r\n"); 2805d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner 2815d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner lprint(" %6d mbufs allocated (%d max)\r\n", mbuf_alloced, mbuf_max); 2825d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner 2835d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner i = 0; 2845d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner for (m = m_freelist.m_next; m != &m_freelist; m = m->m_next) 2855d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner i++; 2865d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner lprint(" %6d mbufs on free list\r\n", i); 2875d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner 2885d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner i = 0; 2895d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner for (m = m_usedlist.m_next; m != &m_usedlist; m = m->m_next) 2905d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner i++; 2915d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner lprint(" %6d mbufs on used list\r\n", i); 2925d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner lprint(" %6d mbufs queued as packets\r\n\r\n", if_queued); 2935d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner} 2945d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner 2955d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turnerstatic void 2965d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turnersockstats(void) 2978b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project{ 2988b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project char buff[256]; 2998b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project int n; 3008b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project struct socket *so; 3018b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project 3028b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint(" \r\n"); 3035d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner 3048b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint( 3058b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project "Proto[state] Sock Local Address, Port Remote Address, Port RecvQ SendQ\r\n"); 3065d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner 3078b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project for (so = tcb.so_next; so != &tcb; so = so->so_next) { 3085d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner 3098b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project n = sprintf(buff, "tcp[%s]", so->so_tcpcb?tcpstates[so->so_tcpcb->t_state]:"NONE"); 3108b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project while (n < 17) 3118b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project buff[n++] = ' '; 3128b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project buff[17] = 0; 3138b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint("%s %3d %15s %5d ", 3148b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project buff, so->s, 3155d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner inet_ntoa(so->so_laddr), ntohs(so->so_lport)); 3168b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint("%15s %5d %5d %5d\r\n", 3175d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner inet_ntoa(so->so_faddr), ntohs(so->so_fport), 3188b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project so->so_rcv.sb_cc, so->so_snd.sb_cc); 3198b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project } 3205d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner 3218b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project for (so = udb.so_next; so != &udb; so = so->so_next) { 3225d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner 3238b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project n = sprintf(buff, "udp[%d sec]", (so->so_expire - curtime) / 1000); 3248b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project while (n < 17) 3258b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project buff[n++] = ' '; 3268b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project buff[17] = 0; 3278b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint("%s %3d %15s %5d ", 3288b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project buff, so->s, 3295d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner inet_ntoa(so->so_laddr), ntohs(so->so_lport)); 3308b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint("%15s %5d %5d %5d\r\n", 3315d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner inet_ntoa(so->so_faddr), ntohs(so->so_fport), 3328b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project so->so_rcv.sb_cc, so->so_snd.sb_cc); 3338b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project } 3348b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project} 3355d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner#endif 3368b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project 3375d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner#ifndef CONFIG_QEMU 3388b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Projectvoid 3398b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Projectslirp_exit(exit_status) 3408b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project int exit_status; 3418b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project{ 3428b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project struct ttys *ttyp; 3435d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner 3448b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project DEBUG_CALL("slirp_exit"); 3458b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project DEBUG_ARG("exit_status = %d", exit_status); 3468b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project 3478b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project if (dostats) { 3488b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint_print = (int (*) _P((void *, const char *, va_list)))vfprintf; 3498b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project if (!dfd) 3508b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project debug_init("slirp_stats", 0xf); 3518b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint_arg = (char **)&dfd; 3525d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner 3538b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project ipstats(); 3548b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project tcpstats(); 3558b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project udpstats(); 3568b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project icmpstats(); 3578b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project mbufstats(); 3588b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project sockstats(); 3598b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project allttystats(); 3608b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project vjstats(); 3618b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project } 3625d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner 3638b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project for (ttyp = ttys; ttyp; ttyp = ttyp->next) 3648b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project tty_detached(ttyp, 1); 3655d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner 3668b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project if (slirp_forked) { 3678b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project /* Menendez time */ 3688b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project if (kill(getppid(), SIGQUIT) < 0) 3698b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project lprint("Couldn't kill parent process %ld!\n", 3708b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project (long) getppid()); 3718b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project } 3725d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner 3738b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project /* Restore the terminal if we gotta */ 3748b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project if(slirp_tty_restore) 3758b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project tcsetattr(0,TCSANOW, &slirp_tty_settings); /* NOW DAMMIT! */ 3768b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project exit(exit_status); 3778b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project} 3788b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#endif 3795d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner 3805d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turnervoid 3815d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turnerslirp_stats(void) 3825d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner{ 3835d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner#ifdef LOG_ENABLED 3845d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner ipstats(); 3855d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner tcpstats(); 3865d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner udpstats(); 3875d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner icmpstats(); 3885d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner mbufstats(); 3895d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner sockstats(); 3905d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner#else 3915d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner lprint("SLIRP statistics code not compiled.\n"); 3925d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner#endif 3935d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner} 394