VirtualBox

source: vbox/trunk/src/VBox/Devices/Network/slirp/debug.c@ 3021

Last change on this file since 3021 was 1076, checked in by vboxsync, 18 years ago

Removed tons of ifdef VBOX conditionals to make slirp readable again

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette