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 |
|
---|
12 | /* Carry over one item from main.c so that the tty's restored.
|
---|
13 | * Only done when the tty being used is /dev/tty --RedWolf */
|
---|
14 | extern struct termios slirp_tty_settings;
|
---|
15 | extern int slirp_tty_restore;
|
---|
16 | #ifdef DEBUG
|
---|
17 | void dump_packet(void *, int);
|
---|
18 | #endif
|
---|
19 |
|
---|
20 |
|
---|
21 | /*
|
---|
22 | * Dump a packet in the same format as tcpdump -x
|
---|
23 | */
|
---|
24 | #ifdef DEBUG
|
---|
25 | void
|
---|
26 | dump_packet(void *dat, int n)
|
---|
27 | {
|
---|
28 | Log(("nat: PACKET DUMPED:\n%.*Vhxd\n", n, dat));
|
---|
29 | }
|
---|
30 | #endif
|
---|
31 |
|
---|
32 |
|
---|
33 | void
|
---|
34 | ipstats(PNATState pData)
|
---|
35 | {
|
---|
36 | lprint(" \r\n");
|
---|
37 |
|
---|
38 | lprint("IP stats:\r\n");
|
---|
39 | lprint(" %6d total packets received (%d were unaligned)\r\n",
|
---|
40 | ipstat.ips_total, ipstat.ips_unaligned);
|
---|
41 | lprint(" %6d with incorrect version\r\n", ipstat.ips_badvers);
|
---|
42 | lprint(" %6d with bad header checksum\r\n", ipstat.ips_badsum);
|
---|
43 | lprint(" %6d with length too short (len < sizeof(iphdr))\r\n", ipstat.ips_tooshort);
|
---|
44 | lprint(" %6d with length too small (len < ip->len)\r\n", ipstat.ips_toosmall);
|
---|
45 | lprint(" %6d with bad header length\r\n", ipstat.ips_badhlen);
|
---|
46 | lprint(" %6d with bad packet length\r\n", ipstat.ips_badlen);
|
---|
47 | lprint(" %6d fragments received\r\n", ipstat.ips_fragments);
|
---|
48 | lprint(" %6d fragments dropped\r\n", ipstat.ips_fragdropped);
|
---|
49 | lprint(" %6d fragments timed out\r\n", ipstat.ips_fragtimeout);
|
---|
50 | lprint(" %6d packets reassembled ok\r\n", ipstat.ips_reassembled);
|
---|
51 | lprint(" %6d outgoing packets fragmented\r\n", ipstat.ips_fragmented);
|
---|
52 | lprint(" %6d total outgoing fragments\r\n", ipstat.ips_ofragments);
|
---|
53 | lprint(" %6d with bad protocol field\r\n", ipstat.ips_noproto);
|
---|
54 | lprint(" %6d total packets delivered\r\n", ipstat.ips_delivered);
|
---|
55 | }
|
---|
56 |
|
---|
57 |
|
---|
58 | void
|
---|
59 | tcpstats(PNATState pData)
|
---|
60 | {
|
---|
61 | lprint(" \r\n");
|
---|
62 |
|
---|
63 | lprint("TCP stats:\r\n");
|
---|
64 |
|
---|
65 | lprint(" %6d packets sent\r\n", tcpstat.tcps_sndtotal);
|
---|
66 | lprint(" %6d data packets (%d bytes)\r\n",
|
---|
67 | tcpstat.tcps_sndpack, tcpstat.tcps_sndbyte);
|
---|
68 | lprint(" %6d data packets retransmitted (%d bytes)\r\n",
|
---|
69 | tcpstat.tcps_sndrexmitpack, tcpstat.tcps_sndrexmitbyte);
|
---|
70 | lprint(" %6d ack-only packets (%d delayed)\r\n",
|
---|
71 | tcpstat.tcps_sndacks, tcpstat.tcps_delack);
|
---|
72 | lprint(" %6d URG only packets\r\n", tcpstat.tcps_sndurg);
|
---|
73 | lprint(" %6d window probe packets\r\n", tcpstat.tcps_sndprobe);
|
---|
74 | lprint(" %6d window update packets\r\n", tcpstat.tcps_sndwinup);
|
---|
75 | lprint(" %6d control (SYN/FIN/RST) packets\r\n", tcpstat.tcps_sndctrl);
|
---|
76 | lprint(" %6d times tcp_output did nothing\r\n", tcpstat.tcps_didnuttin);
|
---|
77 |
|
---|
78 | lprint(" %6d packets received\r\n", tcpstat.tcps_rcvtotal);
|
---|
79 | lprint(" %6d acks (for %d bytes)\r\n",
|
---|
80 | tcpstat.tcps_rcvackpack, tcpstat.tcps_rcvackbyte);
|
---|
81 | lprint(" %6d duplicate acks\r\n", tcpstat.tcps_rcvdupack);
|
---|
82 | lprint(" %6d acks for unsent data\r\n", tcpstat.tcps_rcvacktoomuch);
|
---|
83 | lprint(" %6d packets received in sequence (%d bytes)\r\n",
|
---|
84 | tcpstat.tcps_rcvpack, tcpstat.tcps_rcvbyte);
|
---|
85 | lprint(" %6d completely duplicate packets (%d bytes)\r\n",
|
---|
86 | tcpstat.tcps_rcvduppack, tcpstat.tcps_rcvdupbyte);
|
---|
87 |
|
---|
88 | lprint(" %6d packets with some duplicate data (%d bytes duped)\r\n",
|
---|
89 | tcpstat.tcps_rcvpartduppack, tcpstat.tcps_rcvpartdupbyte);
|
---|
90 | lprint(" %6d out-of-order packets (%d bytes)\r\n",
|
---|
91 | tcpstat.tcps_rcvoopack, tcpstat.tcps_rcvoobyte);
|
---|
92 | lprint(" %6d packets of data after window (%d bytes)\r\n",
|
---|
93 | tcpstat.tcps_rcvpackafterwin, tcpstat.tcps_rcvbyteafterwin);
|
---|
94 | lprint(" %6d window probes\r\n", tcpstat.tcps_rcvwinprobe);
|
---|
95 | lprint(" %6d window update packets\r\n", tcpstat.tcps_rcvwinupd);
|
---|
96 | lprint(" %6d packets received after close\r\n", tcpstat.tcps_rcvafterclose);
|
---|
97 | lprint(" %6d discarded for bad checksums\r\n", tcpstat.tcps_rcvbadsum);
|
---|
98 | lprint(" %6d discarded for bad header offset fields\r\n",
|
---|
99 | tcpstat.tcps_rcvbadoff);
|
---|
100 |
|
---|
101 | lprint(" %6d connection requests\r\n", tcpstat.tcps_connattempt);
|
---|
102 | lprint(" %6d connection accepts\r\n", tcpstat.tcps_accepts);
|
---|
103 | lprint(" %6d connections established (including accepts)\r\n", tcpstat.tcps_connects);
|
---|
104 | lprint(" %6d connections closed (including %d drop)\r\n",
|
---|
105 | tcpstat.tcps_closed, tcpstat.tcps_drops);
|
---|
106 | lprint(" %6d embryonic connections dropped\r\n", tcpstat.tcps_conndrops);
|
---|
107 | lprint(" %6d segments we tried to get rtt (%d succeeded)\r\n",
|
---|
108 | tcpstat.tcps_segstimed, tcpstat.tcps_rttupdated);
|
---|
109 | lprint(" %6d retransmit timeouts\r\n", tcpstat.tcps_rexmttimeo);
|
---|
110 | lprint(" %6d connections dropped by rxmt timeout\r\n",
|
---|
111 | tcpstat.tcps_timeoutdrop);
|
---|
112 | lprint(" %6d persist timeouts\r\n", tcpstat.tcps_persisttimeo);
|
---|
113 | lprint(" %6d keepalive timeouts\r\n", tcpstat.tcps_keeptimeo);
|
---|
114 | lprint(" %6d keepalive probes sent\r\n", tcpstat.tcps_keepprobe);
|
---|
115 | lprint(" %6d connections dropped by keepalive\r\n", tcpstat.tcps_keepdrops);
|
---|
116 | lprint(" %6d correct ACK header predictions\r\n", tcpstat.tcps_predack);
|
---|
117 | lprint(" %6d correct data packet header predictions\n", tcpstat.tcps_preddat);
|
---|
118 | lprint(" %6d TCP cache misses\r\n", tcpstat.tcps_socachemiss);
|
---|
119 |
|
---|
120 |
|
---|
121 | /* lprint(" Packets received too short: %d\r\n", tcpstat.tcps_rcvshort); */
|
---|
122 | /* lprint(" Segments dropped due to PAWS: %d\r\n", tcpstat.tcps_pawsdrop); */
|
---|
123 |
|
---|
124 | }
|
---|
125 |
|
---|
126 | void
|
---|
127 | udpstats(PNATState pData)
|
---|
128 | {
|
---|
129 | lprint(" \r\n");
|
---|
130 |
|
---|
131 | lprint("UDP stats:\r\n");
|
---|
132 | lprint(" %6d datagrams received\r\n", udpstat.udps_ipackets);
|
---|
133 | lprint(" %6d with packets shorter than header\r\n", udpstat.udps_hdrops);
|
---|
134 | lprint(" %6d with bad checksums\r\n", udpstat.udps_badsum);
|
---|
135 | lprint(" %6d with data length larger than packet\r\n", udpstat.udps_badlen);
|
---|
136 | lprint(" %6d UDP socket cache misses\r\n", udpstat.udpps_pcbcachemiss);
|
---|
137 | lprint(" %6d datagrams sent\r\n", udpstat.udps_opackets);
|
---|
138 | }
|
---|
139 |
|
---|
140 | void
|
---|
141 | icmpstats(PNATState pData)
|
---|
142 | {
|
---|
143 | lprint(" \r\n");
|
---|
144 | lprint("ICMP stats:\r\n");
|
---|
145 | lprint(" %6d ICMP packets received\r\n", icmpstat.icps_received);
|
---|
146 | lprint(" %6d were too short\r\n", icmpstat.icps_tooshort);
|
---|
147 | lprint(" %6d with bad checksums\r\n", icmpstat.icps_checksum);
|
---|
148 | lprint(" %6d with type not supported\r\n", icmpstat.icps_notsupp);
|
---|
149 | lprint(" %6d with bad type feilds\r\n", icmpstat.icps_badtype);
|
---|
150 | lprint(" %6d ICMP packets sent in reply\r\n", icmpstat.icps_reflect);
|
---|
151 | }
|
---|
152 |
|
---|
153 | void
|
---|
154 | mbufstats(PNATState pData)
|
---|
155 | {
|
---|
156 | struct mbuf *m;
|
---|
157 | int i;
|
---|
158 |
|
---|
159 | lprint(" \r\n");
|
---|
160 |
|
---|
161 | lprint("Mbuf stats:\r\n");
|
---|
162 |
|
---|
163 | lprint(" %6d mbufs allocated (%d max)\r\n", mbuf_alloced, mbuf_max);
|
---|
164 |
|
---|
165 | i = 0;
|
---|
166 | for (m = m_freelist.m_next; m != &m_freelist; m = m->m_next)
|
---|
167 | i++;
|
---|
168 | lprint(" %6d mbufs on free list\r\n", i);
|
---|
169 |
|
---|
170 | i = 0;
|
---|
171 | for (m = m_usedlist.m_next; m != &m_usedlist; m = m->m_next)
|
---|
172 | i++;
|
---|
173 | lprint(" %6d mbufs on used list\r\n", i);
|
---|
174 | lprint(" %6d mbufs queued as packets\r\n\r\n", if_queued);
|
---|
175 | }
|
---|
176 |
|
---|
177 | void
|
---|
178 | sockstats(PNATState pData)
|
---|
179 | {
|
---|
180 | char buff[256];
|
---|
181 | int n;
|
---|
182 | struct socket *so;
|
---|
183 |
|
---|
184 | lprint(" \r\n");
|
---|
185 |
|
---|
186 | lprint(
|
---|
187 | "Proto[state] Sock Local Address, Port Remote Address, Port RecvQ SendQ\r\n");
|
---|
188 |
|
---|
189 | for (so = tcb.so_next; so != &tcb; so = so->so_next) {
|
---|
190 |
|
---|
191 | n = sprintf(buff, "tcp[%s]", so->so_tcpcb?tcpstates[so->so_tcpcb->t_state]:"NONE");
|
---|
192 | while (n < 17)
|
---|
193 | buff[n++] = ' ';
|
---|
194 | buff[17] = 0;
|
---|
195 | lprint("%s %3d %15s %5d ",
|
---|
196 | buff, so->s,
|
---|
197 | inet_ntoa(so->so_laddr), ntohs(so->so_lport));
|
---|
198 | lprint("%15s %5d %5d %5d\r\n",
|
---|
199 | inet_ntoa(so->so_faddr), ntohs(so->so_fport),
|
---|
200 | so->so_rcv.sb_cc, so->so_snd.sb_cc);
|
---|
201 | }
|
---|
202 |
|
---|
203 | for (so = udb.so_next; so != &udb; so = so->so_next) {
|
---|
204 |
|
---|
205 | n = sprintf(buff, "udp[%d sec]", (so->so_expire - curtime) / 1000);
|
---|
206 | while (n < 17)
|
---|
207 | buff[n++] = ' ';
|
---|
208 | buff[17] = 0;
|
---|
209 | lprint("%s %3d %15s %5d ",
|
---|
210 | buff, so->s,
|
---|
211 | inet_ntoa(so->so_laddr), ntohs(so->so_lport));
|
---|
212 | lprint("%15s %5d %5d %5d\r\n",
|
---|
213 | inet_ntoa(so->so_faddr), ntohs(so->so_fport),
|
---|
214 | so->so_rcv.sb_cc, so->so_snd.sb_cc);
|
---|
215 | }
|
---|
216 | }
|
---|
217 |
|
---|