VirtualBox

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

Last change on this file since 51329 was 51329, checked in by vboxsync, 11 years ago

NAT: Dump info for %R[natsock] even is socket is invalid or closed.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 22.3 KB
Line 
1/* $Id: debug.c 51329 2014-05-21 18:41:59Z vboxsync $ */
2/** @file
3 * NAT - debug helpers.
4 */
5
6/*
7 * Copyright (C) 2006-2012 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18
19/*
20 * This code is based on:
21 *
22 * Copyright (c) 1995 Danny Gasparovski.
23 * Portions copyright (c) 2000 Kelly Price.
24 *
25 * Please read the file COPYRIGHT for the
26 * terms and conditions of the copyright.
27 */
28
29#include <slirp.h>
30#include <iprt/string.h>
31#include <iprt/stream.h>
32#include <iprt/critsect.h>
33#include "zone.h"
34
35#ifdef DEBUG
36void dump_packet(void *, int);
37#endif
38
39#ifndef STRINGIFY
40# define STRINGIFY(x) #x
41#endif
42
43static char *g_apszTcpStates[TCP_NSTATES] =
44{
45 STRINGIFY(TCPS_CLOSED),
46 STRINGIFY(TCPS_LISTEN),
47 STRINGIFY(TCPS_SYN_SENT),
48 STRINGIFY(TCPS_SYN_RECEIVED),
49 STRINGIFY(TCPS_ESTABLISHED),
50 STRINGIFY(TCPS_CLOSE_WAIT),
51 STRINGIFY(TCPS_FIN_WAIT_1),
52 STRINGIFY(TCPS_CLOSING),
53 STRINGIFY(TCPS_LAST_ACK),
54 STRINGIFY(TCPS_FIN_WAIT_2),
55 STRINGIFY(TCPS_TIME_WAIT)
56};
57
58typedef struct DEBUGSTRSOCKETSTATE
59{
60 uint32_t u32SocketState;
61 const char *pcszSocketStateName;
62} DEBUGSTRSOCKETSTATE;
63
64#define DEBUGSTRSOCKETSTATE_HELPER(x) {(x), #x}
65
66static DEBUGSTRSOCKETSTATE g_apszSocketStates[8] =
67{
68 DEBUGSTRSOCKETSTATE_HELPER(SS_NOFDREF),
69 DEBUGSTRSOCKETSTATE_HELPER(SS_ISFCONNECTING),
70 DEBUGSTRSOCKETSTATE_HELPER(SS_ISFCONNECTED),
71 DEBUGSTRSOCKETSTATE_HELPER(SS_FCANTRCVMORE),
72 DEBUGSTRSOCKETSTATE_HELPER(SS_FCANTSENDMORE),
73 DEBUGSTRSOCKETSTATE_HELPER(SS_FWDRAIN),
74 DEBUGSTRSOCKETSTATE_HELPER(SS_FACCEPTCONN),
75 DEBUGSTRSOCKETSTATE_HELPER(SS_FACCEPTONCE),
76};
77
78static DEBUGSTRSOCKETSTATE g_aTcpFlags[] =
79{
80 DEBUGSTRSOCKETSTATE_HELPER(TH_FIN),
81 DEBUGSTRSOCKETSTATE_HELPER(TH_SYN),
82 DEBUGSTRSOCKETSTATE_HELPER(TH_RST),
83 DEBUGSTRSOCKETSTATE_HELPER(TH_PUSH),
84 DEBUGSTRSOCKETSTATE_HELPER(TH_ACK),
85 DEBUGSTRSOCKETSTATE_HELPER(TH_URG),
86};
87
88/*
89 * Dump a packet in the same format as tcpdump -x
90 */
91#ifdef DEBUG
92void
93dump_packet(void *dat, int n)
94{
95 Log(("nat: PACKET DUMPED:\n%.*Rhxd\n", n, dat));
96}
97#endif
98
99#ifdef LOG_ENABLED
100static void
101lprint(const char *pszFormat, ...)
102{
103 va_list args;
104 va_start(args, pszFormat);
105 RTLogPrintfV(pszFormat, args);
106 va_end(args);
107}
108
109void
110ipstats(PNATState pData)
111{
112 lprint("\n");
113
114 lprint("IP stats:\n");
115 lprint(" %6d total packets received (%d were unaligned)\n",
116 ipstat.ips_total, ipstat.ips_unaligned);
117 lprint(" %6d with incorrect version\n", ipstat.ips_badvers);
118 lprint(" %6d with bad header checksum\n", ipstat.ips_badsum);
119 lprint(" %6d with length too short (len < sizeof(iphdr))\n", ipstat.ips_tooshort);
120 lprint(" %6d with length too small (len < ip->len)\n", ipstat.ips_toosmall);
121 lprint(" %6d with bad header length\n", ipstat.ips_badhlen);
122 lprint(" %6d with bad packet length\n", ipstat.ips_badlen);
123 lprint(" %6d fragments received\n", ipstat.ips_fragments);
124 lprint(" %6d fragments dropped\n", ipstat.ips_fragdropped);
125 lprint(" %6d fragments timed out\n", ipstat.ips_fragtimeout);
126 lprint(" %6d packets reassembled ok\n", ipstat.ips_reassembled);
127 lprint(" %6d outgoing packets fragmented\n", ipstat.ips_fragmented);
128 lprint(" %6d total outgoing fragments\n", ipstat.ips_ofragments);
129 lprint(" %6d with bad protocol field\n", ipstat.ips_noproto);
130 lprint(" %6d total packets delivered\n", ipstat.ips_delivered);
131}
132
133void
134tcpstats(PNATState pData)
135{
136 lprint("\n");
137
138 lprint("TCP stats:\n");
139
140 lprint(" %6d packets sent\n", tcpstat.tcps_sndtotal);
141 lprint(" %6d data packets (%d bytes)\n",
142 tcpstat.tcps_sndpack, tcpstat.tcps_sndbyte);
143 lprint(" %6d data packets retransmitted (%d bytes)\n",
144 tcpstat.tcps_sndrexmitpack, tcpstat.tcps_sndrexmitbyte);
145 lprint(" %6d ack-only packets (%d delayed)\n",
146 tcpstat.tcps_sndacks, tcpstat.tcps_delack);
147 lprint(" %6d URG only packets\n", tcpstat.tcps_sndurg);
148 lprint(" %6d window probe packets\n", tcpstat.tcps_sndprobe);
149 lprint(" %6d window update packets\n", tcpstat.tcps_sndwinup);
150 lprint(" %6d control (SYN/FIN/RST) packets\n", tcpstat.tcps_sndctrl);
151 lprint(" %6d times tcp_output did nothing\n", tcpstat.tcps_didnuttin);
152
153 lprint(" %6d packets received\n", tcpstat.tcps_rcvtotal);
154 lprint(" %6d acks (for %d bytes)\n",
155 tcpstat.tcps_rcvackpack, tcpstat.tcps_rcvackbyte);
156 lprint(" %6d duplicate acks\n", tcpstat.tcps_rcvdupack);
157 lprint(" %6d acks for unsent data\n", tcpstat.tcps_rcvacktoomuch);
158 lprint(" %6d packets received in sequence (%d bytes)\n",
159 tcpstat.tcps_rcvpack, tcpstat.tcps_rcvbyte);
160 lprint(" %6d completely duplicate packets (%d bytes)\n",
161 tcpstat.tcps_rcvduppack, tcpstat.tcps_rcvdupbyte);
162
163 lprint(" %6d packets with some duplicate data (%d bytes duped)\n",
164 tcpstat.tcps_rcvpartduppack, tcpstat.tcps_rcvpartdupbyte);
165 lprint(" %6d out-of-order packets (%d bytes)\n",
166 tcpstat.tcps_rcvoopack, tcpstat.tcps_rcvoobyte);
167 lprint(" %6d packets of data after window (%d bytes)\n",
168 tcpstat.tcps_rcvpackafterwin, tcpstat.tcps_rcvbyteafterwin);
169 lprint(" %6d window probes\n", tcpstat.tcps_rcvwinprobe);
170 lprint(" %6d window update packets\n", tcpstat.tcps_rcvwinupd);
171 lprint(" %6d packets received after close\n", tcpstat.tcps_rcvafterclose);
172 lprint(" %6d discarded for bad checksums\n", tcpstat.tcps_rcvbadsum);
173 lprint(" %6d discarded for bad header offset fields\n",
174 tcpstat.tcps_rcvbadoff);
175
176 lprint(" %6d connection requests\n", tcpstat.tcps_connattempt);
177 lprint(" %6d connection accepts\n", tcpstat.tcps_accepts);
178 lprint(" %6d connections established (including accepts)\n", tcpstat.tcps_connects);
179 lprint(" %6d connections closed (including %d drop)\n",
180 tcpstat.tcps_closed, tcpstat.tcps_drops);
181 lprint(" %6d embryonic connections dropped\n", tcpstat.tcps_conndrops);
182 lprint(" %6d segments we tried to get rtt (%d succeeded)\n",
183 tcpstat.tcps_segstimed, tcpstat.tcps_rttupdated);
184 lprint(" %6d retransmit timeouts\n", tcpstat.tcps_rexmttimeo);
185 lprint(" %6d connections dropped by rxmt timeout\n",
186 tcpstat.tcps_timeoutdrop);
187 lprint(" %6d persist timeouts\n", tcpstat.tcps_persisttimeo);
188 lprint(" %6d keepalive timeouts\n", tcpstat.tcps_keeptimeo);
189 lprint(" %6d keepalive probes sent\n", tcpstat.tcps_keepprobe);
190 lprint(" %6d connections dropped by keepalive\n", tcpstat.tcps_keepdrops);
191 lprint(" %6d correct ACK header predictions\n", tcpstat.tcps_predack);
192 lprint(" %6d correct data packet header predictions\n", tcpstat.tcps_preddat);
193 lprint(" %6d TCP cache misses\n", tcpstat.tcps_socachemiss);
194
195/* lprint(" Packets received too short: %d\n", tcpstat.tcps_rcvshort); */
196/* lprint(" Segments dropped due to PAWS: %d\n", tcpstat.tcps_pawsdrop); */
197
198}
199
200void
201udpstats(PNATState pData)
202{
203 lprint("\n");
204
205 lprint("UDP stats:\n");
206 lprint(" %6d datagrams received\n", udpstat.udps_ipackets);
207 lprint(" %6d with packets shorter than header\n", udpstat.udps_hdrops);
208 lprint(" %6d with bad checksums\n", udpstat.udps_badsum);
209 lprint(" %6d with data length larger than packet\n", udpstat.udps_badlen);
210 lprint(" %6d UDP socket cache misses\n", udpstat.udpps_pcbcachemiss);
211 lprint(" %6d datagrams sent\n", udpstat.udps_opackets);
212}
213
214void
215icmpstats(PNATState pData)
216{
217 lprint("\n");
218 lprint("ICMP stats:\n");
219 lprint(" %6d ICMP packets received\n", icmpstat.icps_received);
220 lprint(" %6d were too short\n", icmpstat.icps_tooshort);
221 lprint(" %6d with bad checksums\n", icmpstat.icps_checksum);
222 lprint(" %6d with type not supported\n", icmpstat.icps_notsupp);
223 lprint(" %6d with bad type feilds\n", icmpstat.icps_badtype);
224 lprint(" %6d ICMP packets sent in reply\n", icmpstat.icps_reflect);
225}
226
227void
228mbufstats(PNATState pData)
229{
230 /*
231 * (vvl) this static code can't work with mbuf zone anymore
232 * @todo: make statistic correct
233 */
234 NOREF(pData);
235}
236
237void
238sockstats(PNATState pData)
239{
240 char buff[256];
241 size_t n;
242 struct socket *so, *so_next;
243
244 lprint("\n");
245
246 lprint(
247 "Proto[state] Sock Local Address, Port Remote Address, Port RecvQ SendQ\n");
248
249 QSOCKET_FOREACH(so, so_next, tcp)
250 /* { */
251 n = RTStrPrintf(buff, sizeof(buff), "tcp[%s]", so->so_tcpcb?tcpstates[so->so_tcpcb->t_state]:"NONE");
252 while (n < 17)
253 buff[n++] = ' ';
254 buff[17] = 0;
255 lprint("%s %3d %15s %5d ",
256 buff, so->s, inet_ntoa(so->so_laddr), RT_N2H_U16(so->so_lport));
257 lprint("%15s %5d %5d %5d\n",
258 inet_ntoa(so->so_faddr), RT_N2H_U16(so->so_fport),
259 SBUF_LEN(&so->so_rcv), SBUF_LEN(&so->so_snd));
260 LOOP_LABEL(tcp, so, so_next);
261 }
262
263 QSOCKET_FOREACH(so, so_next, udp)
264 /* { */
265 n = RTStrPrintf(buff, sizeof(buff), "udp[%d sec]", (so->so_expire - curtime) / 1000);
266 while (n < 17)
267 buff[n++] = ' ';
268 buff[17] = 0;
269 lprint("%s %3d %15s %5d ",
270 buff, so->s, inet_ntoa(so->so_laddr), RT_N2H_U16(so->so_lport));
271 lprint("%15s %5d %5d %5d\n",
272 inet_ntoa(so->so_faddr), RT_N2H_U16(so->so_fport),
273 SBUF_LEN(&so->so_rcv), SBUF_LEN(&so->so_snd));
274 LOOP_LABEL(udp, so, so_next);
275 }
276}
277#endif
278
279static DECLCALLBACK(size_t)
280printSocket(PFNRTSTROUTPUT pfnOutput, void *pvArgOutput,
281 const char *pszType, void const *pvValue,
282 int cchWidth, int cchPrecision, unsigned fFlags,
283 void *pvUser)
284{
285 struct socket *so = (struct socket*)pvValue;
286 PNATState pData = (PNATState)pvUser;
287 size_t cb = 0;
288
289 NOREF(cchWidth);
290 NOREF(cchPrecision);
291 NOREF(fFlags);
292 Assert(pData);
293
294 AssertReturn(strcmp(pszType, "natsock") == 0, 0);
295
296 if (so == NULL)
297 return RTStrFormat(pfnOutput, pvArgOutput, NULL, 0,
298 "socket is null");
299 if (so->s == -1)
300 return RTStrFormat(pfnOutput, pvArgOutput, NULL, 0,
301 "socket(%d)", so->s);
302
303 cb += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0,
304 "socket %d:(proto:%u) exp. in %d "
305 " state=%R[natsockstate]"
306 " fUnderPolling:%RTbool"
307 " fShouldBeRemoved:%RTbool"
308 " f_(addr:port)=%RTnaipv4:%d"
309 " l_(addr:port)=%RTnaipv4:%d",
310 so->s, so->so_type,
311 so->so_expire ? so->so_expire - curtime : 0,
312 so->so_state,
313 so->fUnderPolling,
314 so->fShouldBeRemoved,
315 so->so_faddr.s_addr,
316 RT_N2H_U16(so->so_fport),
317 so->so_laddr.s_addr,
318 RT_N2H_U16(so->so_lport));
319
320 if (so->s != -1)
321 {
322 struct sockaddr addr;
323 socklen_t socklen;
324 int status;
325
326 socklen = sizeof(addr);
327 status = getsockname(so->s, &addr, &socklen);
328
329 if (status != 0)
330 {
331 cb += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0,
332 " (getsockname failed)");
333 }
334 else if (addr.sa_family != AF_INET)
335 {
336 cb += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0,
337 " (unexpected address family %d)",
338 addr.sa_family);
339 }
340 else
341 {
342 struct sockaddr_in *in_addr = (struct sockaddr_in *)&addr;
343 cb += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0,
344 " name=%RTnaipv4:%d",
345 in_addr->sin_addr.s_addr,
346 RT_N2H_U16(in_addr->sin_port));
347 }
348 }
349 return cb;
350}
351
352static DECLCALLBACK(size_t)
353printNATSocketState(PFNRTSTROUTPUT pfnOutput, void *pvArgOutput,
354 const char *pszType, void const *pvValue,
355 int cchWidth, int cchPrecision, unsigned fFlags,
356 void *pvUser)
357{
358 uint32_t u32SocketState = (uint32_t)(uintptr_t)pvValue;
359 int idxNATState = 0;
360 bool fFirst = true;
361 size_t cbReturn = 0;
362 NOREF(cchWidth);
363 NOREF(cchPrecision);
364 NOREF(fFlags);
365 NOREF(pvUser);
366 AssertReturn(strcmp(pszType, "natsockstate") == 0, 0);
367
368 for (idxNATState = 0; idxNATState < RT_ELEMENTS(g_apszSocketStates); ++idxNATState)
369 {
370 if (u32SocketState & g_apszSocketStates[idxNATState].u32SocketState)
371 {
372 if (fFirst)
373 {
374 cbReturn += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, g_apszSocketStates[idxNATState].pcszSocketStateName);
375 fFirst = false;
376 }
377 else
378 cbReturn += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, "|%s", g_apszSocketStates[idxNATState].pcszSocketStateName);
379 }
380 }
381
382 if (!cbReturn)
383 return RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, "[unknown state %RX32]", u32SocketState);
384
385 return cbReturn;
386}
387
388/**
389 * Print callback dumping TCP Control Block in terms of RFC 793.
390 */
391static DECLCALLBACK(size_t)
392printTcpcbRfc793(PFNRTSTROUTPUT pfnOutput, void *pvArgOutput,
393 const char *pszType, void const *pvValue,
394 int cchWidth, int cchPrecision, unsigned fFlags,
395 void *pvUser)
396{
397 size_t cb = 0;
398 const struct tcpcb *tp = (const struct tcpcb *)pvValue;
399 NOREF(cchWidth);
400 NOREF(cchPrecision);
401 NOREF(fFlags);
402 NOREF(pvUser);
403 AssertReturn(RTStrCmp(pszType, "tcpcb793") == 0, 0);
404 if (tp)
405 {
406 cb += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, "TCB793[ state:%R[tcpstate] SND(UNA: %x, NXT: %x, UP: %x, WND: %x, WL1:%x, WL2:%x, ISS:%x), ",
407 tp->t_state, tp->snd_una, tp->snd_nxt, tp->snd_up, tp->snd_wnd, tp->snd_wl1, tp->snd_wl2, tp->iss);
408 cb += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, "RCV(WND: %x, NXT: %x, UP: %x, IRS:%x)]", tp->rcv_wnd, tp->rcv_nxt, tp->rcv_up, tp->irs);
409 }
410 else
411 {
412 cb += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, "TCB793[ NULL ]");
413 }
414 return cb;
415}
416/*
417 * Prints TCP segment in terms of RFC 793.
418 */
419static DECLCALLBACK(size_t)
420printTcpSegmentRfc793(PFNRTSTROUTPUT pfnOutput, void *pvArgOutput,
421 const char *pszType, void const *pvValue,
422 int cchWidth, int cchPrecision, unsigned fFlags,
423 void *pvUser)
424{
425 size_t cb = 0;
426 const struct tcpiphdr *ti = (const struct tcpiphdr *)pvValue;
427 NOREF(cchWidth);
428 NOREF(cchPrecision);
429 NOREF(fFlags);
430 NOREF(pvUser);
431 AssertReturn(RTStrCmp(pszType, "tcpseg793") == 0 && ti, 0);
432 cb += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, "SEG[ACK: %x, SEQ: %x, LEN: %x, WND: %x, UP: %x]",
433 ti->ti_ack, ti->ti_seq, ti->ti_len, ti->ti_win, ti->ti_urp);
434 return cb;
435}
436
437/*
438 * Prints TCP state
439 */
440static DECLCALLBACK(size_t)
441printTcpState(PFNRTSTROUTPUT pfnOutput, void *pvArgOutput,
442 const char *pszType, void const *pvValue,
443 int cchWidth, int cchPrecision, unsigned fFlags,
444 void *pvUser)
445{
446 size_t cb = 0;
447 const int idxTcpState = (int)(uintptr_t)pvValue;
448 char *pszTcpStateName = (idxTcpState >= 0 && idxTcpState < TCP_NSTATES) ? g_apszTcpStates[idxTcpState] : "TCPS_INVALIDE_STATE";
449 NOREF(cchWidth);
450 NOREF(cchPrecision);
451 NOREF(fFlags);
452 NOREF(pvUser);
453 AssertReturn(RTStrCmp(pszType, "tcpstate") == 0, 0);
454 cb += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, "%s", pszTcpStateName);
455 return cb;
456}
457
458/*
459 * Prints TCP flags
460 */
461static DECLCALLBACK(size_t)
462printTcpFlags(PFNRTSTROUTPUT pfnOutput, void *pvArgOutput,
463 const char *pszType, void const *pvValue,
464 int cchWidth, int cchPrecision, unsigned fFlags,
465 void *pvUser)
466{
467 size_t cbPrint = 0;
468 uint32_t u32TcpFlags = (uint32_t)(uintptr_t)pvValue;
469 bool fSingleValue = true;
470 int idxTcpFlags = 0;
471 NOREF(cchWidth);
472 NOREF(cchPrecision);
473 NOREF(fFlags);
474 NOREF(pvUser);
475 AssertReturn(RTStrCmp(pszType, "tcpflags") == 0, 0);
476 cbPrint += RTStrFormat(pfnOutput,
477 pvArgOutput,
478 NULL,
479 0,
480 "tcpflags: %RX8 [", (uint8_t)u32TcpFlags);
481 for (idxTcpFlags = 0; idxTcpFlags < RT_ELEMENTS(g_aTcpFlags); ++idxTcpFlags)
482 {
483 if (u32TcpFlags & g_aTcpFlags[idxTcpFlags].u32SocketState)
484 {
485 cbPrint += RTStrFormat(pfnOutput,
486 pvArgOutput,
487 NULL,
488 0,
489 fSingleValue ? "%s(%RX8)" : "|%s(%RX8)",
490 g_aTcpFlags[idxTcpFlags].pcszSocketStateName,
491 (uint8_t)g_aTcpFlags[idxTcpFlags].u32SocketState);
492 fSingleValue = false;
493 }
494 }
495 cbPrint += RTStrFormat(pfnOutput,
496 pvArgOutput,
497 NULL,
498 0,
499 "]");
500 return cbPrint;
501}
502
503/*
504 * Prints sbuf state
505 */
506static DECLCALLBACK(size_t)
507printSbuf(PFNRTSTROUTPUT pfnOutput, void *pvArgOutput,
508 const char *pszType, void const *pvValue,
509 int cchWidth, int cchPrecision, unsigned fFlags,
510 void *pvUser)
511{
512 size_t cb = 0;
513 const struct sbuf *sb = (struct sbuf *)pvValue;
514 NOREF(cchWidth);
515 NOREF(cchPrecision);
516 NOREF(fFlags);
517 NOREF(pvUser);
518 AssertReturn(RTStrCmp(pszType, "sbuf") == 0, 0);
519 cb += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, "[sbuf:%p cc:%d, datalen:%d, wprt:%p, rptr:%p data:%p]",
520 sb, sb->sb_cc, sb->sb_datalen, sb->sb_wptr, sb->sb_rptr, sb->sb_data);
521 return cb;
522}
523
524/*
525 * Prints zone state
526 */
527static DECLCALLBACK(size_t)
528printMbufZone(PFNRTSTROUTPUT pfnOutput, void *pvArgOutput,
529 const char *pszType, void const *pvValue,
530 int cchWidth, int cchPrecision, unsigned fFlags,
531 void *pvUser)
532{
533 size_t cb = 0;
534 const uma_zone_t zone = (const uma_zone_t)pvValue;
535 NOREF(cchWidth);
536 NOREF(cchPrecision);
537 NOREF(fFlags);
538 NOREF(pvUser);
539 AssertReturn(RTStrCmp(pszType, "mzone") == 0, 0);
540 if (!zone)
541 cb += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, "[zone:NULL]");
542 else
543 cb += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, "[zone:%p name:%s, master_zone:%R[mzone]]",
544 zone, zone->name, zone->master_zone);
545 return cb;
546}
547
548/*
549 * Prints zone's item state
550 */
551static DECLCALLBACK(size_t)
552printMbufZoneItem(PFNRTSTROUTPUT pfnOutput, void *pvArgOutput,
553 const char *pszType, void const *pvValue,
554 int cchWidth, int cchPrecision, unsigned fFlags,
555 void *pvUser)
556{
557 size_t cb = 0;
558 const struct item *it = (const struct item *)pvValue;
559 NOREF(cchWidth);
560 NOREF(cchPrecision);
561 NOREF(fFlags);
562 NOREF(pvUser);
563 AssertReturn(RTStrCmp(pszType, "mzoneitem") == 0, 0);
564 if (!it)
565 cb += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, "[item:NULL]");
566 else
567 cb += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, "[iptem:%p ref_count:%d, zone:%R[mzone]]",
568 it, it->ref_count, it->zone);
569 return cb;
570}
571
572static DECLCALLBACK(size_t)
573print_networkevents(PFNRTSTROUTPUT pfnOutput, void *pvArgOutput,
574 const char *pszType, void const *pvValue,
575 int cchWidth, int cchPrecision, unsigned fFlags,
576 void *pvUser)
577{
578 size_t cb = 0;
579#ifdef RT_OS_WINDOWS
580 WSANETWORKEVENTS *pNetworkEvents = (WSANETWORKEVENTS*)pvValue;
581 bool fDelim = false;
582#endif
583
584 NOREF(cchWidth);
585 NOREF(cchPrecision);
586 NOREF(fFlags);
587 NOREF(pvUser);
588
589#ifdef RT_OS_WINDOWS
590 AssertReturn(strcmp(pszType, "natwinnetevents") == 0, 0);
591
592 cb += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, "events=%02x (",
593 pNetworkEvents->lNetworkEvents);
594# define DO_BIT(bit) \
595 if (pNetworkEvents->lNetworkEvents & FD_ ## bit) \
596 { \
597 cb += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, \
598 "%s" #bit "(%d)", fDelim ? "," : "", \
599 pNetworkEvents->iErrorCode[FD_ ## bit ## _BIT]); \
600 fDelim = true; \
601 }
602 DO_BIT(READ);
603 DO_BIT(WRITE);
604 DO_BIT(OOB);
605 DO_BIT(ACCEPT);
606 DO_BIT(CONNECT);
607 DO_BIT(CLOSE);
608 DO_BIT(QOS);
609# undef DO_BIT
610 cb += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, ")");
611#else
612 NOREF(pfnOutput);
613 NOREF(pvArgOutput);
614 NOREF(pszType);
615 NOREF(pvValue);
616#endif
617 return cb;
618}
619
620#if 0
621/*
622 * Debugging
623 */
624int errno_func(const char *file, int line)
625{
626 int err = WSAGetLastError();
627 LogRel(("errno=%d (%s:%d)\n", err, file, line));
628 return err;
629}
630#endif
631
632int
633debug_init(PNATState pData)
634{
635 int rc = VINF_SUCCESS;
636
637 static int g_fFormatRegistered;
638
639 if (!g_fFormatRegistered)
640 {
641
642 rc = RTStrFormatTypeRegister("natsock", printSocket, pData); AssertRC(rc);
643 rc = RTStrFormatTypeRegister("natsockstate", printNATSocketState, NULL); AssertRC(rc);
644 rc = RTStrFormatTypeRegister("natwinnetevents",
645 print_networkevents, NULL); AssertRC(rc);
646 rc = RTStrFormatTypeRegister("tcpcb793", printTcpcbRfc793, NULL); AssertRC(rc);
647 rc = RTStrFormatTypeRegister("tcpseg793", printTcpSegmentRfc793, NULL); AssertRC(rc);
648 rc = RTStrFormatTypeRegister("tcpstate", printTcpState, NULL); AssertRC(rc);
649 rc = RTStrFormatTypeRegister("tcpflags", printTcpFlags, NULL); AssertRC(rc);
650 rc = RTStrFormatTypeRegister("sbuf", printSbuf, NULL); AssertRC(rc);
651 rc = RTStrFormatTypeRegister("mzone", printMbufZone, NULL); AssertRC(rc);
652 rc = RTStrFormatTypeRegister("mzoneitem", printMbufZoneItem, NULL); AssertRC(rc);
653 g_fFormatRegistered = 1;
654 }
655
656 return rc;
657}
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