VirtualBox

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

Last change on this file since 14882 was 14882, checked in by vboxsync, 16 years ago

registered log formatter prining IPv4 addresses on %R[IP4]

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