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.

495 lines
11 KiB

  1. #include "tcpipxp.h"
  2. #pragma hdrstop
  3. #include "routeext.h"
  4. //
  5. // Exported Functions
  6. //
  7. DECLARE_API( rtetable )
  8. /*++
  9. Routine Description:
  10. Print the route table @ tcpip!RouteTable
  11. Arguments:
  12. args - Detail of debug information
  13. [ SUMMARY is the default ]
  14. Return Value:
  15. None
  16. --*/
  17. {
  18. Trie trie;
  19. PVOID pTrie;
  20. ULONG proxyPtr;
  21. ULONG bytesRead;
  22. ULONG printFlags;
  23. // Get the detail of debug information needed
  24. printFlags = STRIE_INFO | FTRIE_INFO;
  25. if (*args)
  26. {
  27. sscanf(args, "%lu", &printFlags);
  28. }
  29. // Get the address corresponding to symbol
  30. proxyPtr = GetLocation("tcpip!RouteTable");
  31. // Get the pointer at this address
  32. if (!ReadMemory(proxyPtr, &pTrie, sizeof(PVOID), &bytesRead))
  33. {
  34. dprintf("%s @ %08x: Could not read pointer\n",
  35. "tcpip!RouteTable", proxyPtr);
  36. return;
  37. }
  38. proxyPtr = (ULONG) pTrie;
  39. // Read the trie wrapper structure
  40. if (ReadTrie(&trie, proxyPtr) == 0)
  41. {
  42. // KdPrint the trie wrapper structure
  43. KdPrintTrie(&trie, proxyPtr, printFlags);
  44. }
  45. }
  46. DECLARE_API( rtes )
  47. /*++
  48. Routine Description:
  49. Print the routes in the table @ tcpip!RouteTable
  50. Arguments:
  51. args - Detail of debug information
  52. [ SUMMARY is the default ]
  53. Return Value:
  54. None
  55. --*/
  56. {
  57. Trie trie;
  58. PVOID pTrie;
  59. ULONG proxyPtr;
  60. ULONG bytesRead;
  61. ULONG printFlags;
  62. // Get the detail of debug information needed
  63. printFlags = ROUTE_INFO;
  64. if (*args)
  65. {
  66. sscanf(args, "%lu", &printFlags);
  67. }
  68. // Get the address corresponding to symbol
  69. proxyPtr = GetLocation("tcpip!RouteTable");
  70. // Get the pointer at this address
  71. if (!ReadMemory(proxyPtr, &pTrie, sizeof(PVOID), &bytesRead))
  72. {
  73. dprintf("%s @ %08x: Could not read pointer\n",
  74. "tcpip!RouteTable", proxyPtr);
  75. return;
  76. }
  77. proxyPtr = (ULONG) pTrie;
  78. // Read the trie wrapper structure
  79. if (ReadTrie(&trie, proxyPtr) == 0)
  80. {
  81. // KdPrint the trie wrapper structure
  82. KdPrintTrie(&trie, proxyPtr, printFlags);
  83. }
  84. }
  85. //
  86. // Trie Print Routines
  87. //
  88. UINT
  89. ReadTrie(Trie *pTrie, ULONG proxyPtr)
  90. {
  91. ULONG bytesRead;
  92. // Read the trie wrapper structure
  93. if (!ReadMemory(proxyPtr, pTrie, sizeof(Trie), &bytesRead))
  94. {
  95. dprintf("%s @ %08x: Could not read structure\n",
  96. "Trie in RouteTable", proxyPtr);
  97. return -1;
  98. }
  99. return 0;
  100. }
  101. UINT
  102. KdPrintTrie(Trie *pTrie, ULONG proxyPtr, ULONG printFlags)
  103. {
  104. UINT retval;
  105. if (printFlags == ROUTE_INFO)
  106. {
  107. KdPrintSTrie(NULL, (ULONG) pTrie->sTrie, ROUTE_INFO);
  108. return 0;
  109. }
  110. if (pTrie->flags & TFLAG_FAST_TRIE_ENABLED)
  111. dprintf("Fast Trie Enabled\n");
  112. else
  113. dprintf("Slow Trie Only\n");
  114. if (printFlags & STRIE_INFO)
  115. {
  116. dprintf("STrie:\n");
  117. retval = KdPrintSTrie(NULL, (ULONG) pTrie->sTrie, printFlags & STRIE_INFO);
  118. if (retval == -1)
  119. {
  120. return -1;
  121. }
  122. }
  123. if (printFlags & FTRIE_INFO)
  124. {
  125. if (pTrie->flags & TFLAG_FAST_TRIE_ENABLED)
  126. {
  127. dprintf("FTrie:\n");
  128. KdPrintFTrie(NULL, (ULONG) pTrie->fTrie, printFlags & FTRIE_INFO);
  129. }
  130. }
  131. return 0;
  132. }
  133. //
  134. // STrie Print Routines
  135. //
  136. UINT
  137. KdPrintSTrie(STrie *pSTrie, ULONG proxyPtr, ULONG printFlags)
  138. {
  139. STrie strie;
  140. ULONG bytesRead;
  141. UINT retval;
  142. if (proxyPtr == 0)
  143. return -1;
  144. if (pSTrie == NULL)
  145. {
  146. pSTrie = &strie;
  147. // Read the strie structure at this address
  148. if (!ReadMemory(proxyPtr, pSTrie, sizeof(STrie), &bytesRead))
  149. {
  150. dprintf("%s @ %08x: Could not read structure\n",
  151. "STrie in RouteTable", proxyPtr);
  152. return -1;
  153. }
  154. }
  155. if (printFlags == STRIE_INFO)
  156. {
  157. dprintf("\n\n/***Slow-Trie------------------------------------------------");
  158. dprintf("\n/***---------------------------------------------------------\n");
  159. dprintf("Available Memory: %10lu\n\n", pSTrie->availMemory);
  160. dprintf("Statistics:\n\n");
  161. dprintf("Total Number of Dests : %d\n", pSTrie->numDests);
  162. dprintf("Total Number of Routes: %d\n", pSTrie->numRoutes);
  163. dprintf("Total Number of Nodes : %d\n", pSTrie->numNodes);
  164. }
  165. if (pSTrie->trieRoot == NULL)
  166. {
  167. dprintf("\nEmpty STrie\n");
  168. }
  169. else
  170. {
  171. retval = KdPrintSTrieNode(NULL, (ULONG) pSTrie->trieRoot, printFlags);
  172. if (retval == -1)
  173. {
  174. return (-1);
  175. }
  176. }
  177. if (printFlags == STRIE_INFO)
  178. {
  179. dprintf("\n---------------------------------------------------------***/\n");
  180. dprintf("---------------------------------------------------------***/\n\n");
  181. }
  182. return 0;
  183. }
  184. UINT
  185. KdPrintSTrieNode(STrieNode *pSTrieNode, ULONG proxyPtr, ULONG printFlags)
  186. {
  187. ULONG bytesRead;
  188. STrieNode stNode;
  189. if (proxyPtr == 0)
  190. return -1;
  191. if (pSTrieNode == NULL)
  192. {
  193. pSTrieNode = &stNode;
  194. // Read the trie wrapper structure
  195. if (!ReadMemory(proxyPtr, pSTrieNode, sizeof(STrieNode), &bytesRead))
  196. {
  197. dprintf("%s @ %08x: Could not read structure\n",
  198. "STrieNode", proxyPtr);
  199. return -1;
  200. }
  201. }
  202. if (CheckControlC())
  203. {
  204. return (-1);
  205. }
  206. if (printFlags == STRIE_INFO)
  207. {
  208. dprintf("\n--------------------------------------------------------\n");
  209. dprintf("Child @ %08x", proxyPtr);
  210. dprintf("\n--------------------------------------------------------\n");
  211. dprintf("Key: Num of Bits : %8d, Value of Bits: %08x\n",
  212. pSTrieNode->numBits,
  213. pSTrieNode->keyBits);
  214. }
  215. KdPrintDest(NULL, (ULONG) pSTrieNode->dest, printFlags);
  216. if (printFlags == STRIE_INFO)
  217. {
  218. dprintf("Children: On the left %08x, On the right %08x\n",
  219. pSTrieNode->child[0],
  220. pSTrieNode->child[1]);
  221. dprintf("\n--------------------------------------------------------\n");
  222. dprintf("\n\n");
  223. }
  224. KdPrintSTrieNode(NULL, (ULONG) pSTrieNode->child[0], printFlags);
  225. KdPrintSTrieNode(NULL, (ULONG) pSTrieNode->child[1], printFlags);
  226. return 0;
  227. }
  228. //
  229. // FTrie Print Routines
  230. //
  231. UINT
  232. KdPrintFTrie(FTrie *pFTrie, ULONG proxyPtr, ULONG printFlags)
  233. {
  234. FTrieNode *pCurrNode;
  235. FTrie ftrie;
  236. ULONG bytesRead;
  237. UINT i;
  238. if (proxyPtr == 0)
  239. return -1;
  240. if (pFTrie == NULL)
  241. {
  242. pFTrie = &ftrie;
  243. // Read the ftrie structure at this address
  244. if (!ReadMemory(proxyPtr, pFTrie, sizeof(FTrie), &bytesRead))
  245. {
  246. dprintf("%s @ %08x: Could not read structure\n",
  247. "FTrie in RouteTable", proxyPtr);
  248. return -1;
  249. }
  250. }
  251. dprintf("\n\n/***Fast-Trie------------------------------------------------");
  252. dprintf("\n/***---------------------------------------------------------\n");
  253. dprintf("Available Memory: %10lu\n\n", pFTrie->availMemory);
  254. dprintf("\n---------------------------------------------------------***/\n");
  255. dprintf("---------------------------------------------------------***/\n\n");
  256. return 0;
  257. }
  258. UINT
  259. KdPrintFTrieNode(FTrieNode *pFTrieNode, ULONG proxyPtr, ULONG printFlags)
  260. {
  261. return 0;
  262. }
  263. //
  264. // Dest Routines
  265. //
  266. UINT
  267. KdPrintDest(Dest *pDest, ULONG proxyPtr, ULONG printFlags)
  268. {
  269. ULONG bytesRead;
  270. ULONG numBytes;
  271. UINT i;
  272. Dest dest;
  273. Route **pRoutes;
  274. if (proxyPtr == 0)
  275. return -1;
  276. if (pDest == NULL)
  277. {
  278. pDest = &dest;
  279. }
  280. // Read the first RTE - for (dest, mask)
  281. if (!ReadMemory(proxyPtr, pDest, sizeof(Dest), &bytesRead))
  282. {
  283. dprintf("%s @ %08x: Could not read structure\n",
  284. "Dest", proxyPtr);
  285. return -1;
  286. }
  287. if (pDest->numBestRoutes > 1)
  288. {
  289. dprintf("\nBest Routes: Max = %d, Num = %d\n",
  290. pDest->maxBestRoutes,
  291. pDest->numBestRoutes);
  292. // Read the cache of equal cost routes
  293. proxyPtr += FIELD_OFFSET(Dest, bestRoutes);
  294. numBytes = pDest->numBestRoutes * sizeof(Route *);
  295. pRoutes = (Route **) _alloca(numBytes);
  296. if (!ReadMemory(proxyPtr, pRoutes, numBytes, &bytesRead))
  297. {
  298. dprintf("%s @ %08x: Could not read structure\n",
  299. "Dest", proxyPtr);
  300. return -1;
  301. }
  302. for (i = 0; i < pDest->numBestRoutes; i++)
  303. {
  304. dprintf("Best Route %d: %08x\n", i, pRoutes[i]);
  305. }
  306. }
  307. // Get the first route on the destination
  308. KdPrintRoute(NULL, (ULONG) pDest->firstRoute, printFlags);
  309. if (pDest->numBestRoutes > 1)
  310. {
  311. dprintf("\n");
  312. }
  313. return 0;
  314. }
  315. //
  316. // Route Routines
  317. //
  318. UINT
  319. KdPrintRoute(Route *pRoute, ULONG proxyPtr, ULONG printFlags)
  320. {
  321. ULONG bytesRead;
  322. Route route;
  323. if (proxyPtr == 0)
  324. return -1;
  325. if (pRoute == NULL)
  326. {
  327. pRoute = &route;
  328. }
  329. // Read the first RTE - for (dest, mask)
  330. if (!ReadMemory(proxyPtr, pRoute, sizeof(Route), &bytesRead))
  331. {
  332. dprintf("%s @ %08x: Could not read structure\n",
  333. "Route", proxyPtr);
  334. return -1;
  335. }
  336. dprintf("(");
  337. KdPrintIPAddr(&DEST(pRoute));
  338. dprintf(" ");
  339. KdPrintIPAddr(&MASK(pRoute));
  340. dprintf(")");
  341. while (proxyPtr != 0)
  342. {
  343. dprintf(" -> %08x", proxyPtr);
  344. // Read the Route/RTE structure
  345. if (!ReadMemory(proxyPtr, pRoute, sizeof(Route), &bytesRead))
  346. {
  347. dprintf("%s @ %08x: Could not read structure\n",
  348. "Route", proxyPtr);
  349. return -1;
  350. }
  351. proxyPtr = (ULONG) NEXT(pRoute);
  352. }
  353. dprintf("\n");
  354. return 0;
  355. }
  356. //
  357. // Misc Helper Routines
  358. //
  359. ULONG
  360. GetLocation (char *String)
  361. {
  362. ULONG Location;
  363. Location = GetExpression( String );
  364. if (!Location)
  365. {
  366. dprintf("Unable to get %s\n", String);
  367. return 0;
  368. }
  369. return Location;
  370. }
  371. VOID
  372. KdPrintIPAddr (IN ULONG *addr)
  373. {
  374. UCHAR *addrBytes = (UCHAR *) addr;
  375. UINT i;
  376. if (addrBytes)
  377. {
  378. dprintf("%3d.", addrBytes[0]);
  379. dprintf("%3d.", addrBytes[1]);
  380. dprintf("%3d.", addrBytes[2]);
  381. dprintf("%3d ", addrBytes[3]);
  382. }
  383. else
  384. {
  385. dprintf("NULL Addr ");
  386. }
  387. }