VirtualBox

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

最後變更 在這個檔案從11820是 5715,由 vboxsync 提交於 17 年 前

Get rid of K&R C code.

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

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