Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

557 lines
14 KiB

  1. /*++
  2. Copyright (c) 1999-2000 Microsoft Corporation
  3. Module Name:
  4. util.c
  5. Abstract:
  6. Utility dumping functions.
  7. Author:
  8. Scott Holden (sholden) 24-Apr-1999
  9. Revision History:
  10. --*/
  11. #include "tcpipxp.h"
  12. int _Indent = 0;
  13. char IndentBuf[80];
  14. FLAG_INFO FlagsMDL[] =
  15. {
  16. { MDL_MAPPED_TO_SYSTEM_VA, "MAPPED_TO_SYSTEM_VA" },
  17. { MDL_PAGES_LOCKED, "PAGES_LOCKED" },
  18. { MDL_SOURCE_IS_NONPAGED_POOL, "SOURCE_IS_NONPAGED_POOL" },
  19. { MDL_ALLOCATED_FIXED_SIZE, "ALLOCATED_FIXED_SIZE" },
  20. { MDL_PARTIAL, "PARTIAL" },
  21. { MDL_PARTIAL_HAS_BEEN_MAPPED, "PARTIAL_HAS_BEEN_MAPPED" },
  22. { MDL_IO_PAGE_READ, "IO_PAGE_READ" },
  23. { MDL_WRITE_OPERATION, "WRITE_OPERATION" },
  24. { MDL_PARENT_MAPPED_SYSTEM_VA, "PARENT_MAPPED_SYSTEM_VA" },
  25. { MDL_IO_SPACE, "IO_SPACE" },
  26. { MDL_NETWORK_HEADER, "NETWORK_HEADER" },
  27. { MDL_MAPPING_CAN_FAIL, "MAPPING_CAN_FAIL" },
  28. { MDL_ALLOCATED_MUST_SUCCEED, "ALLOCATED_MUST_SUCCEED" },
  29. { 0, NULL }
  30. };
  31. FLAG_INFO FlagsTCPConn[] =
  32. {
  33. { CONN_CLOSING, "CONN_CLOSING" },
  34. { CONN_DISACC, "CONN_DISACC" },
  35. { CONN_WINSET, "CONN_WINSET" },
  36. { CONN_INVALID, "CONN_INVALID" },
  37. { 0, NULL }
  38. };
  39. FLAG_INFO FlagsLLIPBindInfo[] =
  40. {
  41. { LIP_COPY_FLAG, "LIP_COPY_FLAG" },
  42. { LIP_P2P_FLAG, "LIP_P2P_FLAG" },
  43. { LIP_NOIPADDR_FLAG, "LIP_NOIPADDR_FLAG" },
  44. { LIP_P2MP_FLAG, "LIP_P2MP_FLAG" },
  45. { LIP_NOLINKBCST_FLAG, "LIP_NOLINKBCST_FLAG" },
  46. { 0, NULL }
  47. };
  48. FLAG_INFO FlagsTsr[] =
  49. {
  50. { TSR_FLAG_URG, "TSR_FLAG_URG" },
  51. { TSR_FLAG_SEND_AND_DISC, "TSR_FLAG_SEND_AND_DISC" },
  52. { 0, NULL }
  53. };
  54. FLAG_INFO FlagsNTE[] =
  55. {
  56. { NTE_VALID, "NTE_Valid" },
  57. { NTE_COPY, "NTE_Copy" },
  58. { NTE_PRIMARY, "NTE_Primary" },
  59. { NTE_ACTIVE, "NTE_Active" },
  60. { NTE_DYNAMIC, "NTE_Dynamic" },
  61. { NTE_DHCP, "NTE_DHCP" },
  62. { NTE_DISCONNECTED, "NTE_Disconnected" },
  63. { NTE_TIMER_STARTED, "NTE_TimerStarted" },
  64. { NTE_IF_DELETING, "NTE_IF_Deleting" },
  65. { 0, NULL }
  66. };
  67. FLAG_INFO FlagsIF[] =
  68. {
  69. { IF_FLAGS_P2P, "IF_P2P" },
  70. { IF_FLAGS_DELETING, "IF_DELETING" },
  71. { IF_FLAGS_NOIPADDR, "IF_NOIPADDR" },
  72. { IF_FLAGS_P2MP, "IF_P2MP" },
  73. { IF_FLAGS_REMOVING_POWER, "IF_REMOVING_POWER" },
  74. { IF_FLAGS_POWER_DOWN, "IF_POWER_DOWN" },
  75. { IF_FLAGS_REMOVING_DEVICE, "IF_REMOVING_DEVICE" },
  76. { IF_FLAGS_NOLINKBCST, "IF_NOLINKBCST" },
  77. { IF_FLAGS_UNI, "IF_UNI" },
  78. { IF_FLAGS_MEDIASENSE, "IF_MEDIASENSE" },
  79. { 0, NULL }
  80. };
  81. FLAG_INFO FlagsRCE[] =
  82. {
  83. { RCE_VALID, "RCE_Valid" },
  84. { RCE_CONNECTED, "RCE_Connected" },
  85. { RCE_REFERENCED, "RCE_Referenced" },
  86. { RCE_DEADGW, "RCE_Deadgw" },
  87. { 0, NULL }
  88. };
  89. FLAG_INFO FlagsRTE[] =
  90. {
  91. { RTE_VALID, "RTE_Valid" },
  92. { RTE_INCREASE, "RTE_Increase" },
  93. { RTE_IF_VALID, "RTE_If_Valid" },
  94. { RTE_DEADGW, "RTE_DeadGW" },
  95. { RTE_NEW, "RTE_New" },
  96. { 0, NULL }
  97. };
  98. FLAG_INFO FlagsTcb[] =
  99. {
  100. { WINDOW_SET, "Window_Set" },
  101. { CLIENT_OPTIONS, "Client_Options" },
  102. { CONN_ACCEPTED, "Connection_Accepted" },
  103. { ACTIVE_OPEN, "Active_Open" },
  104. { DISC_NOTIFIED, "Disc_Notified" },
  105. { IN_DELAY_Q, "In_Delay_Q" },
  106. { RCV_CMPLTING, "Receives_Completing" },
  107. { IN_RCV_IND, "In_Receive_Indication" },
  108. { NEED_RCV_CMPLT, "Need_To_Have_Rcvs_Completed" },
  109. { NEED_ACK, "Need_To_Send_Ack" },
  110. { NEED_OUTPUT, "Need_To_Output" },
  111. { ACK_DELAYED, "Delayed_Ack" },
  112. { PMTU_BH_PROBE, "PMTU_BH_Probe" },
  113. { BSD_URGENT, "BSD_Urgent" },
  114. { IN_DELIV_URG, "In_Deliver_Urgent" },
  115. { URG_VALID, "Urgent_Valid" },
  116. { FIN_NEEDED, "Fin_Needed" },
  117. { NAGLING, "Nagling" },
  118. { IN_TCP_SEND, "In_Tcp_Send" },
  119. { FLOW_CNTLD, "Flow_Controlled" },
  120. { DISC_PENDING, "Disconnect_Pending" },
  121. { TW_PENDING, "Timed_Wait_Pending" },
  122. { FORCE_OUTPUT, "Force_Output" },
  123. { SEND_AFTER_RCV, "Send_After_Receive" },
  124. { GC_PENDING, "Graceful_Close_Pending" },
  125. { KEEPALIVE, "KeepAlive" },
  126. { URG_INLINE, "Urgent_Inline" },
  127. { FIN_OUTSTANDING, "Fin_Outstanding" },
  128. { FIN_SENT, "Fin_Sent" },
  129. { NEED_RST, "Need_Rst" },
  130. { IN_TCB_TABLE, "In_Tcb_Table" },
  131. { IN_TWTCB_TABLE, "IN_TWTCB_TABLE" },
  132. { IN_TWQUEUE, "IN_TWQUEUE" },
  133. { 0, NULL }
  134. };
  135. FLAG_INFO FlagsTCPHeader[] =
  136. {
  137. { TCP_FLAG_FIN, "FIN" },
  138. { TCP_FLAG_SYN, "SYN" },
  139. { TCP_FLAG_RST, "RST" },
  140. { TCP_FLAG_PUSH, "PSH" },
  141. { TCP_FLAG_ACK, "ACK" },
  142. { TCP_FLAG_URG, "URG" },
  143. { 0, NULL }
  144. };
  145. FLAG_INFO FlagsFastChk[] =
  146. {
  147. { TCP_FLAG_SLOW, "Need_Slow_Path" },
  148. { TCP_FLAG_IN_RCV, "In_Receive_Path" },
  149. { TCP_FLAG_FASTREC, "FastXmit_In_Progress" },
  150. { 0, NULL }
  151. };
  152. FLAG_INFO FlagsAO[] =
  153. {
  154. { AO_RAW_FLAG, "Raw" },
  155. { AO_DHCP_FLAG, "DHCP" },
  156. { AO_VALID_FLAG, "Valid" },
  157. { AO_BUSY_FLAG, "Busy" },
  158. { AO_OOR_FLAG, "Out_of_Resources" },
  159. { AO_QUEUED_FLAG, "On_PendingQ" },
  160. { AO_XSUM_FLAG, "Use_Xsums" },
  161. { AO_SEND_FLAG, "Send_Pending" },
  162. { AO_OPTIONS_FLAG, "Option_Set_Pending" },
  163. { AO_DELETE_FLAG, "Delete_Pending" },
  164. { AO_BROADCAST_FLAG,"BCast_Enabled" },
  165. { AO_CONNUDP_FLAG, "Connected_UDP" },
  166. { 0, NULL }
  167. };
  168. ENUM_INFO StateTcb[] =
  169. {
  170. { TCB_CLOSED, "Closed" },
  171. { TCB_LISTEN, "Listening" },
  172. { TCB_SYN_SENT, "Syn_Sent" },
  173. { TCB_SYN_RCVD, "Syn_Received" },
  174. { TCB_ESTAB, "Established" },
  175. { TCB_FIN_WAIT1, "Fin_Wait_1" },
  176. { TCB_FIN_WAIT2, "Fin_Wait_2" },
  177. { TCB_CLOSE_WAIT, "Close_Wait" },
  178. { TCB_CLOSING, "Closing" },
  179. { TCB_LAST_ACK, "Last_Ack" },
  180. { TCB_TIME_WAIT, "Time_Wait" },
  181. { 0, NULL }
  182. };
  183. ENUM_INFO CloseReason[] =
  184. {
  185. { TCB_CLOSE_RST, "RST_Received" },
  186. { TCB_CLOSE_ABORTED, "Local_Abort" },
  187. { TCB_CLOSE_TIMEOUT, "Timed_Out" },
  188. { TCB_CLOSE_REFUSED, "Refused" },
  189. { TCB_CLOSE_UNREACH, "Dest_Unreachable" },
  190. { TCB_CLOSE_SUCCESS, "Sucessful_Close" },
  191. { 0, NULL }
  192. };
  193. ENUM_INFO FsContext2[] =
  194. {
  195. { TDI_TRANSPORT_ADDRESS_FILE, "Transport_Address" },
  196. { TDI_CONNECTION_FILE, "Connection" },
  197. { TDI_CONTROL_CHANNEL_FILE, "Control_Channel" },
  198. { 0, NULL }
  199. };
  200. ENUM_INFO Prot[] =
  201. {
  202. { PROTOCOL_UDP, "Udp" },
  203. { PROTOCOL_TCP, "Tcp" },
  204. { PROTOCOL_RAW, "Raw" },
  205. { 0, NULL }
  206. };
  207. ENUM_INFO NdisMediumsEnum[] =
  208. {
  209. { NdisMedium802_3, "802.3" },
  210. { NdisMedium802_5, "802.5" },
  211. { NdisMediumFddi, "Fddi" },
  212. { NdisMediumWan, "Wan" },
  213. { NdisMediumLocalTalk, "LocalTalk" },
  214. { NdisMediumDix, "Dix" },
  215. { NdisMediumArcnetRaw, "ArcnetRaw" },
  216. { NdisMediumArcnet878_2, "Arcnet878_2" },
  217. { NdisMediumAtm, "Atm" },
  218. { NdisMediumWirelessWan, "WirelessWan" },
  219. { NdisMediumIrda, "Irda" },
  220. { NdisMediumBpc, "Bpc" },
  221. { NdisMediumCoWan, "CoWan" },
  222. { NdisMedium1394, "1394" },
  223. { NdisMediumMax, "???" },
  224. { 0, NULL }
  225. };
  226. ENUM_INFO AteState[] =
  227. {
  228. { ARP_RESOLVING_LOCAL, "ARP_RESOLVING_LOCAL"},
  229. { ARP_RESOLVING_GLOBAL, "ARP_RESOLVING_GLOBAL"},
  230. { ARP_GOOD, "ARP_GOOD"},
  231. { ARP_BAD, "ARP_BAD"},
  232. { 0, NULL }
  233. };
  234. VOID
  235. DumpIPAddr(
  236. IPAddr Address
  237. )
  238. {
  239. uchar IPAddrBuffer[(sizeof(IPAddr) * 4)];
  240. uint i;
  241. uint IPAddrCharCount;
  242. //
  243. // Convert the IP address into a string.
  244. //
  245. IPAddrCharCount = 0;
  246. for (i = 0; i < sizeof(IPAddr); i++) {
  247. uint CurrentByte;
  248. CurrentByte = Address & 0xff;
  249. if (CurrentByte > 99) {
  250. IPAddrBuffer[IPAddrCharCount++] = (CurrentByte / 100) + '0';
  251. CurrentByte %= 100;
  252. IPAddrBuffer[IPAddrCharCount++] = (CurrentByte / 10) + '0';
  253. CurrentByte %= 10;
  254. } else if (CurrentByte > 9) {
  255. IPAddrBuffer[IPAddrCharCount++] = (CurrentByte / 10) + '0';
  256. CurrentByte %= 10;
  257. }
  258. IPAddrBuffer[IPAddrCharCount++] = CurrentByte + '0';
  259. if (i != (sizeof(IPAddr) - 1))
  260. IPAddrBuffer[IPAddrCharCount++] = '.';
  261. Address >>= 8;
  262. }
  263. IPAddrBuffer[IPAddrCharCount] = '\0';
  264. printx("%-15s", IPAddrBuffer);
  265. }
  266. VOID
  267. DumpPtrSymbol(
  268. PVOID pvSymbol
  269. )
  270. {
  271. UCHAR SymbolName[ 80 ];
  272. ULONG Displacement = 0;
  273. printx("%-10lx", pvSymbol );
  274. #if !MILLENKD
  275. GetSymbol(pvSymbol, SymbolName, &Displacement);
  276. #endif // !MILLENKD
  277. if (Displacement == 0)
  278. {
  279. #if MILLENKD
  280. printx(" (%pS + 0x%pX)", pvSymbol, pvSymbol);
  281. #else // MILLENKD
  282. printx(" (%s)", SymbolName);
  283. #endif // !MILLENKD
  284. }
  285. else
  286. {
  287. printx(" (%s + 0x%X)", SymbolName, Displacement);
  288. }
  289. }
  290. VOID
  291. DumpFlags(
  292. ULONG flags,
  293. PFLAG_INFO pFlagInfo
  294. )
  295. {
  296. BOOL fFound = FALSE;
  297. while (pFlagInfo->pszDescription != NULL)
  298. {
  299. if (pFlagInfo->Value & flags)
  300. {
  301. if (fFound)
  302. {
  303. printx(" | ");
  304. }
  305. fFound = TRUE;
  306. dprintf("%.20s", pFlagInfo->pszDescription);
  307. }
  308. pFlagInfo++;
  309. }
  310. return;
  311. }
  312. VOID
  313. DumpEnum(
  314. ULONG Value,
  315. PENUM_INFO pEnumInfo
  316. )
  317. {
  318. while (pEnumInfo->pszDescription != NULL)
  319. {
  320. if (pEnumInfo->Value == Value)
  321. {
  322. dprintf("%.40s", pEnumInfo->pszDescription);
  323. return;
  324. }
  325. pEnumInfo++;
  326. }
  327. dprintf( "Unknown enumeration value." );
  328. return;
  329. }
  330. BOOL
  331. DumpCTEEvent(
  332. CTEEvent *pCe
  333. )
  334. {
  335. PrintStartStruct();
  336. Print_uint(pCe, ce_scheduled);
  337. Print_CTELock(pCe, ce_lock);
  338. Print_PtrSymbol(pCe, ce_handler);
  339. Print_ptr(pCe, ce_arg);
  340. Print_WORK_QUEUE_ITEM(pCe, ce_workitem);
  341. PrintEndStruct();
  342. return (TRUE);
  343. }
  344. BOOL
  345. DumpKEVENT(
  346. KEVENT *pKe
  347. )
  348. {
  349. PrintStartStruct();
  350. Print_uchar(pKe, Header.Type);
  351. Print_uchar(pKe, Header.Absolute);
  352. Print_uchar(pKe, Header.Size);
  353. Print_uchar(pKe, Header.Inserted);
  354. Print_ULONGhex(pKe, Header.SignalState);
  355. Print_LL(pKe, Header.WaitListHead);
  356. PrintEndStruct();
  357. return (TRUE);
  358. }
  359. BOOL
  360. DumpWORK_QUEUE_ITEM(
  361. WORK_QUEUE_ITEM *pWqi
  362. )
  363. {
  364. PrintStartStruct();
  365. Print_LL(pWqi, List);
  366. Print_PtrSymbol(pWqi, WorkerRoutine);
  367. Print_ptr(pWqi, Parameter);
  368. PrintEndStruct();
  369. return (TRUE);
  370. }
  371. BOOL
  372. DumpSHARE_ACCESS(
  373. SHARE_ACCESS *pSa
  374. )
  375. {
  376. PrintStartStruct();
  377. Print_ULONG(pSa, OpenCount);
  378. Print_ULONG(pSa, Readers);
  379. Print_ULONG(pSa, Writers);
  380. Print_ULONG(pSa, Deleters);
  381. Print_ULONG(pSa, SharedRead);
  382. Print_ULONG(pSa, SharedWrite);
  383. Print_ULONG(pSa, SharedDelete);
  384. PrintEndStruct();
  385. return (TRUE);
  386. }
  387. BOOL
  388. DumpCTETimer(
  389. CTETimer *pCt
  390. )
  391. {
  392. PrintStartStruct();
  393. Print_uint(pCt, t_running);
  394. Print_Lock(pCt, t_lock);
  395. Print_PtrSymbol(pCt, t_handler);
  396. Print_ptr(pCt, t_arg);
  397. PrintEndStruct();
  398. return (TRUE);
  399. }
  400. BOOL
  401. DumpNDIS_STRING(
  402. NDIS_STRING *pNs
  403. )
  404. {
  405. PrintStartStruct();
  406. Print_ushort(pNs, Length);
  407. Print_ushort(pNs, MaximumLength);
  408. Print_ptr(pNs, Buffer);
  409. PrintEndStruct();
  410. return (TRUE);
  411. }
  412. BOOL
  413. DumpMDL(
  414. MDL *pMdl,
  415. ULONG_PTR MdlAddr,
  416. VERB verb
  417. )
  418. {
  419. if (verb == VERB_MAX)
  420. {
  421. PrintStartNamedStruct(MDL, MdlAddr);
  422. Print_ptr(pMdl, Next);
  423. Print_short(pMdl, Size);
  424. //Print_ushorthex(pMdl, MdlFlags);
  425. Print_flags(pMdl, MdlFlags, FlagsMDL);
  426. Print_ptr(pMdl, Process);
  427. Print_ptr(pMdl, MappedSystemVa);
  428. Print_ptr(pMdl, StartVa);
  429. Print_ULONG(pMdl, ByteCount);
  430. Print_ULONG(pMdl, ByteOffset);
  431. PrintEndStruct();
  432. }
  433. else if (verb == VERB_MED)
  434. {
  435. printx("MDL %x va %x cb %d (",
  436. MdlAddr, pMdl->MappedSystemVa, pMdl->ByteCount);
  437. DumpFlags(pMdl->MdlFlags, FlagsMDL);
  438. printx(")" ENDL);
  439. }
  440. else
  441. {
  442. printx("MDL %x va %x cb %d" ENDL,
  443. MdlAddr, pMdl->MappedSystemVa, pMdl->ByteCount);
  444. }
  445. return (TRUE);
  446. }
  447. BOOL
  448. DumpNPAGED_LOOKASIDE_LIST(
  449. PNPAGED_LOOKASIDE_LIST pPpl,
  450. ULONG_PTR PplAddr,
  451. VERB verb
  452. )
  453. {
  454. PrintStartNamedStruct(PPL, PplAddr);
  455. Print_ptr(pPpl, L.ListHead.Next.Next);
  456. Print_USHORT(pPpl, L.ListHead.Depth);
  457. Print_USHORT(pPpl, L.ListHead.Sequence);
  458. Print_USHORT(pPpl, L.Depth);
  459. Print_USHORT(pPpl, L.MaximumDepth);
  460. Print_ULONG(pPpl, L.TotalAllocates);
  461. Print_ULONG(pPpl, L.AllocateMisses);
  462. Print_ULONG(pPpl, L.TotalFrees);
  463. Print_ULONG(pPpl, L.FreeMisses);
  464. Print_ULONG(pPpl, L.Type);
  465. Print_Tag(pPpl, L.Tag);
  466. Print_ULONG(pPpl, L.Size);
  467. Print_PtrSymbol(pPpl, L.Allocate);
  468. Print_PtrSymbol(pPpl, L.Free);
  469. Print_LL(pPpl, L.ListEntry);
  470. Print_ULONG(pPpl, L.LastTotalAllocates);
  471. Print_ULONG(pPpl, L.LastAllocateMisses);
  472. PrintEndStruct();
  473. return (TRUE);
  474. }