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.

432 lines
13 KiB

  1. /*++
  2. Copyright (c) 1998-1999 Microsoft Corporation
  3. Module Name:
  4. kdutil.c
  5. Abstract:
  6. Packet scheduler KD extension utilities.
  7. Author:
  8. Rajesh Sundaram (1st Aug, 1998)
  9. Revision History:
  10. --*/
  11. #include "precomp.h"
  12. EXT_API_VERSION ApiVersion = { 3, 5, EXT_API_VERSION_NUMBER, 0 };
  13. WINDBG_EXTENSION_APIS ExtensionApis;
  14. USHORT SavedMajorVersion;
  15. USHORT SavedMinorVersion;
  16. ULONG GpcClientVcTag = '1CSP';
  17. PCHAR ClientVCState[] = {
  18. "",
  19. "CL_VC_INITIALIZED",
  20. "CL_CALL_PENDING",
  21. "CL_INTERNAL_CALL_COMPLETE",
  22. "CL_CALL_COMPLETE",
  23. "CL_MODIFY_PENDING",
  24. "CL_GPC_CLOSE_PENDING",
  25. "CL_INTERNAL_CLOSE_PENDING"
  26. };
  27. PCHAR ServiceTypeLabels[] = {
  28. "No Traffic",
  29. "Best Effort",
  30. "Controlled Load",
  31. "Guaranteed",
  32. "Network Unavailable",
  33. "General Information",
  34. "No Change",
  35. "",
  36. "",
  37. "Non Conforming",
  38. "Network Control",
  39. "Custom1",
  40. "Custom2",
  41. "Custom3"
  42. };
  43. PCHAR SDMode[]= {
  44. "Borrow",
  45. "Shape",
  46. "Discard",
  47. "Borrow Plus"};
  48. ushort
  49. IPHeaderXsum(void *Buffer, int Size)
  50. {
  51. ushort UNALIGNED *Buffer1 = (ushort UNALIGNED *)Buffer; // Buffer expres
  52. ulong csum = 0;
  53. while (Size > 1) {
  54. csum += *Buffer1++;
  55. Size -= sizeof(ushort);
  56. }
  57. if (Size)
  58. csum += *(uchar *)Buffer1; // For odd buffers, add in la
  59. csum = (csum >> 16) + (csum & 0xffff);
  60. csum += (csum >> 16);
  61. return (ushort)~csum;
  62. }
  63. VOID
  64. CheckVersion(
  65. VOID
  66. )
  67. {
  68. #if 0
  69. #if DBG
  70. if ((SavedMajorVersion != 0x0c) || (SavedMinorVersion != VER_PRODUCTBUILD)) {
  71. dprintf("\r\n*** Extension DLL(%d Checked) does not match target "
  72. "system(%d %s)\r\n\r\n", VER_PRODUCTBUILD, SavedMinorVersion,
  73. (SavedMajorVersion==0x0f) ? "Free" : "Checked" );
  74. }
  75. #else
  76. if ((SavedMajorVersion != 0x0f) || (SavedMinorVersion != VER_PRODUCTBUILD)) {
  77. dprintf("\r\n*** Extension DLL(%d Free) does not match target "
  78. "system(%d %s)\r\n\r\n",
  79. VER_PRODUCTBUILD, SavedMinorVersion,
  80. (SavedMajorVersion==0x0f) ? "Free" : "Checked" );
  81. }
  82. #endif
  83. #endif
  84. }
  85. LPEXT_API_VERSION
  86. ExtensionApiVersion(
  87. VOID
  88. )
  89. {
  90. return &ApiVersion;
  91. }
  92. VOID
  93. WinDbgExtensionDllInit(
  94. PWINDBG_EXTENSION_APIS lpExtensionApis,
  95. USHORT MajorVersion,
  96. USHORT MinorVersion
  97. )
  98. {
  99. ExtensionApis = *lpExtensionApis;
  100. SavedMajorVersion = MajorVersion;
  101. SavedMinorVersion = MinorVersion;
  102. return;
  103. }
  104. DECLARE_API( version )
  105. {
  106. #if DBG
  107. PCHAR DebuggerType = "Checked";
  108. #else
  109. PCHAR DebuggerType = "Free";
  110. #endif
  111. dprintf("%s Extension dll for Build %d debugging %s kernel for Build %d\n",
  112. DebuggerType,
  113. VER_PRODUCTBUILD,
  114. SavedMajorVersion == 0x0c ? "Checked" : "Free",
  115. SavedMinorVersion
  116. );
  117. }
  118. VOID
  119. DumpGpcClientVc(PCHAR indent, PGPC_CLIENT_VC TargetClientVC, PGPC_CLIENT_VC LocalClientVC)
  120. {
  121. PWSTR Name;
  122. ULONG bytes;
  123. #if DBG
  124. if ( LocalClientVC->LLTag != GpcClientVcTag ) {
  125. dprintf( "%s ClientVC @ %08X has the wrong type \n", indent, TargetClientVC );
  126. return;
  127. }
  128. #endif
  129. dprintf( "%s ClientVC @ %08X\n\n", indent, TargetClientVC );
  130. dprintf( "%s Refcount = %d \n", indent, LocalClientVC->RefCount);
  131. dprintf( "%s VC State = %s\n", indent, ClientVCState[ LocalClientVC->ClVcState ]);
  132. dprintf( "%s Adapter = 0x%x \n", indent, LocalClientVC->Adapter);
  133. dprintf( "%s Flags = 0x%x \n", indent, LocalClientVC->Flags);
  134. dprintf( "%s Lock @ %08X \n", indent, &TargetClientVC->Lock);
  135. if(LocalClientVC->InstanceName.Length) {
  136. bytes = LocalClientVC->InstanceName.Length;
  137. Name = (PWSTR)malloc( bytes );
  138. if ( Name != NULL ) {
  139. KD_READ_MEMORY((LocalClientVC->InstanceName.Buffer), Name, bytes);
  140. }
  141. }
  142. else {
  143. Name = 0;
  144. }
  145. dprintf( "%s Instance Name = %ws \n", indent, Name);
  146. dprintf( "%s CfInfo Handle = %08X \n", indent, LocalClientVC->CfInfoHandle);
  147. dprintf( "%s CfType = %d \n", indent, LocalClientVC->CfType);
  148. dprintf( "%s TOS non conforming = %X \n", indent, LocalClientVC->IPPrecedenceNonConforming);
  149. dprintf( "%s 802.1p conforming = %X \n", indent, LocalClientVC->UserPriorityConforming);
  150. dprintf( "%s 802.1p non conforming = %X \n", indent, LocalClientVC->UserPriorityNonConforming);
  151. dprintf( "%s Flow Context = %x \n", indent, LocalClientVC->PsFlowContext);
  152. dprintf( "%s TokenRateChange = %x \n", indent, LocalClientVC->TokenRateChange);
  153. //
  154. // Control by a flag later on.... to much junk otherwize
  155. //
  156. if(LocalClientVC->CallParameters) {
  157. dprintf("%s Call Parameters \n", indent);
  158. DumpCallParameters(LocalClientVC, " ");
  159. }
  160. if(Name)
  161. free(Name);
  162. return;
  163. }
  164. VOID
  165. DumpFlowSpec(
  166. PFLOWSPEC Flow,
  167. PCHAR Indent
  168. )
  169. {
  170. dprintf( "%sTokenRate = %u (%08X)\n", Indent, Flow->TokenRate, Flow->TokenRate );
  171. dprintf( "%sTokenBucketSize = %u (%08X)\n", Indent, Flow->TokenBucketSize, Flow->TokenBucketSize );
  172. dprintf( "%sPeakBandwidth = %u (%08X)\n", Indent, Flow->PeakBandwidth, Flow->PeakBandwidth );
  173. dprintf( "%sLatency = %u (%08X)\n", Indent, Flow->Latency, Flow->Latency );
  174. dprintf( "%sDelayVariation = %u (%08X)\n", Indent, Flow->DelayVariation, Flow->DelayVariation );
  175. if ( (LONG)(Flow->ServiceType) != -1 ) {
  176. dprintf( "%sServiceType = %s\n", Indent, ServiceTypeLabels[ Flow->ServiceType ] );
  177. } else {
  178. dprintf( "%sServiceType = Unspecified\n", Indent );
  179. }
  180. dprintf( "%sMaxSduSize = %u (%08X)\n", Indent, Flow->MaxSduSize, Flow->MaxSduSize );
  181. dprintf( "%sMinimumPolicedSize = %u (%08X)\n", Indent, Flow->MinimumPolicedSize, Flow->MinimumPolicedSize );
  182. }
  183. VOID
  184. DumpSpecific(
  185. ULONG Length,
  186. PCO_CALL_MANAGER_PARAMETERS TargetCMParams,
  187. PCHAR Indent
  188. )
  189. {
  190. LONG ParamsLength;
  191. LPQOS_OBJECT_HDR lQoSObject = malloc(Length);
  192. CO_CALL_MANAGER_PARAMETERS CM;
  193. ULONG Address;
  194. if(!lQoSObject)
  195. return;
  196. Address = (ULONG)TargetCMParams + FIELD_OFFSET(CO_CALL_MANAGER_PARAMETERS, CallMgrSpecific) +
  197. FIELD_OFFSET(CO_SPECIFIC_PARAMETERS, Parameters);
  198. KD_READ_MEMORY(Address,
  199. lQoSObject,
  200. Length);
  201. ParamsLength = Length;
  202. while(ParamsLength > 0) {
  203. switch(lQoSObject->ObjectType) {
  204. case QOS_OBJECT_SHAPING_RATE:
  205. {
  206. LPQOS_SHAPING_RATE pShapingRate = (LPQOS_SHAPING_RATE)(lQoSObject);
  207. dprintf("%s QOS_OBJECT_SHAPING_RATE (Shaping Rate = %d (0x%x) \n", Indent,
  208. pShapingRate->ShapingRate, pShapingRate->ShapingRate);
  209. break;
  210. }
  211. case QOS_OBJECT_DS_CLASS:
  212. {
  213. LPQOS_DS_CLASS pDClass = (LPQOS_DS_CLASS)(lQoSObject);
  214. dprintf("%s QOS_OBJECT_DS_CLASS (DSCP = %d (0x%x) \n", Indent,
  215. pDClass->DSField, pDClass->DSField);
  216. break;
  217. }
  218. case QOS_OBJECT_TRAFFIC_CLASS:
  219. {
  220. LPQOS_TRAFFIC_CLASS pDClass = (LPQOS_TRAFFIC_CLASS)(lQoSObject);
  221. dprintf("%s QOS_OBJECT_TRAFFIC_CLASS (DSCP = %d (0x%x) \n", Indent,
  222. pDClass->TrafficClass, pDClass->TrafficClass);
  223. break;
  224. }
  225. case QOS_OBJECT_PRIORITY:
  226. {
  227. LPQOS_PRIORITY pPri = (LPQOS_PRIORITY)(lQoSObject);
  228. dprintf("%s QOS_OBJECT_PRIORITY \n", Indent);
  229. dprintf("%s%s SendPriority = %d \n", Indent, Indent, pPri->SendPriority);
  230. dprintf("%s%s RecvPriority = %d \n", Indent, Indent, pPri->ReceivePriority);
  231. dprintf("%s%s SendFlags = %d \n", Indent, Indent, pPri->SendFlags);
  232. break;
  233. }
  234. case QOS_OBJECT_SD_MODE:
  235. {
  236. LPQOS_SD_MODE pSDMode = (LPQOS_SD_MODE)(lQoSObject);
  237. dprintf("%s QOS_OBJECT_SD_MODE (SD mode = %s) \n",
  238. Indent,
  239. SDMode[pSDMode->ShapeDiscardMode]);
  240. break;
  241. }
  242. case QOS_OBJECT_DIFFSERV:
  243. {
  244. LPQOS_DIFFSERV qD = (LPQOS_DIFFSERV)(lQoSObject);
  245. ULONG DSFieldCount = qD->DSFieldCount;
  246. LPQOS_DIFFSERV_RULE pDiffServRule = (LPQOS_DIFFSERV_RULE) qD->DiffservRule;
  247. ULONG i;
  248. dprintf("%s QOS_OBJECT_DIFFSERV \n\n", Indent);
  249. for(i=0; i<DSFieldCount; i++, pDiffServRule++) {
  250. dprintf("%s%sInboundDSField = %3d (0x%x) \n", Indent, Indent,
  251. pDiffServRule->InboundDSField,
  252. pDiffServRule->InboundDSField);
  253. dprintf("%s%sConforming DS = %3d (0x%x) \n", Indent, Indent,
  254. pDiffServRule->ConformingOutboundDSField,
  255. pDiffServRule->ConformingOutboundDSField);
  256. dprintf("%s%sNon Conforming DS = %3d (0x%x) \n", Indent, Indent,
  257. pDiffServRule->NonConformingOutboundDSField,
  258. pDiffServRule->NonConformingOutboundDSField);
  259. dprintf("%s%sConforming 802.1p = %3d (0x%x) \n", Indent, Indent,
  260. pDiffServRule->ConformingUserPriority,
  261. pDiffServRule->ConformingUserPriority);
  262. dprintf("%s%sNon Conforming 802.1p = %3d (0x%x) \n", Indent, Indent,
  263. pDiffServRule->NonConformingUserPriority,
  264. pDiffServRule->NonConformingUserPriority);
  265. dprintf("\n");
  266. }
  267. break;
  268. }
  269. }
  270. if(
  271. ((LONG)lQoSObject->ObjectLength <= 0) ||
  272. ((LONG)lQoSObject->ObjectLength > ParamsLength)
  273. ){
  274. return;
  275. }
  276. ParamsLength -= lQoSObject->ObjectLength;
  277. lQoSObject = (LPQOS_OBJECT_HDR)((UINT_PTR)lQoSObject +
  278. lQoSObject->ObjectLength);
  279. }
  280. if(lQoSObject) {
  281. free(lQoSObject);
  282. }
  283. }
  284. VOID
  285. DumpCallParameters(
  286. PGPC_CLIENT_VC Vc,
  287. PCHAR Indent
  288. )
  289. {
  290. PCO_CALL_PARAMETERS tCp = Vc->CallParameters;
  291. CO_CALL_PARAMETERS lCp;
  292. LONG bytes = sizeof( CO_CALL_MANAGER_PARAMETERS );
  293. LONG IndentLen;
  294. PCHAR NewIndent;
  295. IndentLen = strlen( Indent );
  296. NewIndent = malloc( IndentLen + 8 );
  297. if(!NewIndent)
  298. return;
  299. strcpy( NewIndent, Indent );
  300. strcat( NewIndent, " " );
  301. //
  302. // Read CallParameters out of memory
  303. //
  304. KD_READ_MEMORY(tCp, &lCp, sizeof(CO_CALL_PARAMETERS));
  305. //
  306. // Dump it
  307. //
  308. dprintf("%sFlags 0x%x \n", Indent, lCp.Flags);
  309. dprintf("%sCallManager Parameters \n", Indent);
  310. {
  311. //
  312. // read CMParams struct out of target's memory
  313. //
  314. CO_CALL_MANAGER_PARAMETERS LocalCMParams;
  315. PCO_CALL_MANAGER_PARAMETERS TargetCMParams;
  316. TargetCMParams = lCp.CallMgrParameters;
  317. KD_READ_MEMORY((ULONG)TargetCMParams, &LocalCMParams,sizeof( CO_CALL_MANAGER_PARAMETERS));
  318. dprintf( "%s Transmit\n", Indent );
  319. DumpFlowSpec( &LocalCMParams.Transmit, NewIndent );
  320. dprintf( "%s Receive\n", Indent );
  321. DumpFlowSpec( &LocalCMParams.Receive, NewIndent );
  322. dprintf( "%s Specific\n", Indent );
  323. DumpSpecific( LocalCMParams.CallMgrSpecific.Length,
  324. TargetCMParams,
  325. NewIndent );
  326. }
  327. dprintf("%sMediaParameters \n", Indent);
  328. {
  329. CO_MEDIA_PARAMETERS lM;
  330. PCO_MEDIA_PARAMETERS pM;
  331. pM = lCp.MediaParameters;
  332. KD_READ_MEMORY((ULONG)pM, &lM,sizeof(CO_MEDIA_PARAMETERS));
  333. dprintf( "%s Flags %x \n", Indent, lM.Flags);
  334. dprintf( "%s ReceivePriority %x \n", Indent, lM.ReceivePriority );
  335. dprintf( "%s ReceiveSizeHint %x \n", Indent, lM.ReceiveSizeHint );
  336. dprintf( "%s Specific\n", Indent );
  337. //DumpSpecific( &lM.MediaSpecific, NewIndent );
  338. }
  339. free( NewIndent );
  340. }