Source code of Windows XP (NT5)
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.

355 lines
7.0 KiB

  1. #include "tcpipxp.h"
  2. #pragma hdrstop
  3. #include "routeext.h"
  4. #include "lookup.h"
  5. #if TCPIPKD
  6. //
  7. // Exported Functions
  8. //
  9. extern VOID
  10. Tcpipkd_rtetable(
  11. PVOID args[]
  12. )
  13. /*++
  14. Routine Description:
  15. Print the route table @ tcpip!RouteTable
  16. Arguments:
  17. args - Detail of debug information
  18. [ SUMMARY is the default ]
  19. Return Value:
  20. None
  21. --*/
  22. {
  23. ULONG printFlags;
  24. // Get the detail of debug information needed
  25. printFlags = STRIE_INFO | FTRIE_INFO;
  26. if (*args)
  27. {
  28. printFlags = (ULONG) *args;
  29. }
  30. KdPrintTrie(RouteTable, (ULONG) RouteTable, printFlags);
  31. }
  32. extern VOID
  33. Tcpipkd_rtes(
  34. PVOID args[]
  35. )
  36. /*++
  37. Routine Description:
  38. Print the routes in the table @ tcpip!RouteTable
  39. Arguments:
  40. args - Detail of debug information
  41. [ SUMMARY is the default ]
  42. Return Value:
  43. None
  44. --*/
  45. {
  46. ULONG printFlags;
  47. // Get the detail of debug information needed
  48. printFlags = ROUTE_INFO;
  49. if (*args)
  50. {
  51. printFlags = (ULONG) *args;
  52. }
  53. KdPrintTrie(RouteTable, (ULONG) RouteTable, printFlags);
  54. }
  55. UINT
  56. KdPrintTrie(Trie *pTrie, ULONG proxyPtr, ULONG printFlags)
  57. {
  58. UINT retval;
  59. if (printFlags == ROUTE_INFO)
  60. {
  61. KdPrintSTrie(NULL, (ULONG) pTrie->sTrie, ROUTE_INFO);
  62. return 0;
  63. }
  64. if (pTrie->flags & TFLAG_FAST_TRIE_ENABLED)
  65. dprintf("Fast Trie Enabled\n");
  66. else
  67. dprintf("Slow Trie Only\n");
  68. if (printFlags & STRIE_INFO)
  69. {
  70. dprintf("STrie:\n");
  71. retval = KdPrintSTrie(NULL, (ULONG) pTrie->sTrie, printFlags & STRIE_INFO);
  72. if (retval == -1)
  73. {
  74. return -1;
  75. }
  76. }
  77. if (printFlags & FTRIE_INFO)
  78. {
  79. if (pTrie->flags & TFLAG_FAST_TRIE_ENABLED)
  80. {
  81. dprintf("FTrie:\n");
  82. KdPrintFTrie(NULL, (ULONG) pTrie->fTrie, printFlags & FTRIE_INFO);
  83. }
  84. }
  85. return 0;
  86. }
  87. //
  88. // STrie Print Routines
  89. //
  90. UINT
  91. KdPrintSTrie(STrie *pSTrie, ULONG proxyPtr, ULONG printFlags)
  92. {
  93. UINT retval;
  94. if (proxyPtr == 0)
  95. return -1;
  96. if (pSTrie == NULL)
  97. {
  98. pSTrie = (STrie *) proxyPtr;
  99. }
  100. if (printFlags == STRIE_INFO)
  101. {
  102. dprintf("\n\n/***Slow-Trie------------------------------------------------");
  103. dprintf("\n/***---------------------------------------------------------\n");
  104. dprintf("Available Memory: %10lu\n\n", pSTrie->availMemory);
  105. dprintf("Statistics:\n\n");
  106. dprintf("Total Number of Dests : %d\n", pSTrie->numDests);
  107. dprintf("Total Number of Routes: %d\n", pSTrie->numRoutes);
  108. dprintf("Total Number of Nodes : %d\n", pSTrie->numNodes);
  109. }
  110. if (pSTrie->trieRoot == NULL)
  111. {
  112. dprintf("\nEmpty STrie\n");
  113. }
  114. else
  115. {
  116. retval = KdPrintSTrieNode(NULL, (ULONG) pSTrie->trieRoot, printFlags);
  117. if (retval == -1)
  118. {
  119. return (-1);
  120. }
  121. }
  122. if (printFlags == STRIE_INFO)
  123. {
  124. dprintf("\n---------------------------------------------------------***/\n");
  125. dprintf("---------------------------------------------------------***/\n\n");
  126. }
  127. return 0;
  128. }
  129. UINT
  130. KdPrintSTrieNode(STrieNode *pSTrieNode, ULONG proxyPtr, ULONG printFlags)
  131. {
  132. ULONG bytesRead;
  133. STrieNode stNode;
  134. if (proxyPtr == 0)
  135. return -1;
  136. if (pSTrieNode == NULL)
  137. {
  138. pSTrieNode = (STrieNode *) proxyPtr;
  139. }
  140. if (printFlags == STRIE_INFO)
  141. {
  142. dprintf("\n--------------------------------------------------------\n");
  143. dprintf("Child @ %08x", proxyPtr);
  144. dprintf("\n--------------------------------------------------------\n");
  145. dprintf("Key: Num of Bits : %8d, Value of Bits: %08x\n",
  146. pSTrieNode->numBits,
  147. pSTrieNode->keyBits);
  148. }
  149. KdPrintDest(NULL, (ULONG) pSTrieNode->dest, printFlags);
  150. if (printFlags == STRIE_INFO)
  151. {
  152. dprintf("Children: On the left %08x, On the right %08x\n",
  153. pSTrieNode->child[0],
  154. pSTrieNode->child[1]);
  155. dprintf("\n--------------------------------------------------------\n");
  156. dprintf("\n\n");
  157. }
  158. KdPrintSTrieNode(NULL, (ULONG) pSTrieNode->child[0], printFlags);
  159. KdPrintSTrieNode(NULL, (ULONG) pSTrieNode->child[1], printFlags);
  160. return 0;
  161. }
  162. //
  163. // FTrie Print Routines
  164. //
  165. UINT
  166. KdPrintFTrie(FTrie *pFTrie, ULONG proxyPtr, ULONG printFlags)
  167. {
  168. FTrieNode *pCurrNode;
  169. FTrie ftrie;
  170. ULONG bytesRead;
  171. UINT i;
  172. if (proxyPtr == 0)
  173. return -1;
  174. if (pFTrie == NULL)
  175. {
  176. pFTrie = (FTrie *) proxyPtr;
  177. }
  178. dprintf("\n\n/***Fast-Trie------------------------------------------------");
  179. dprintf("\n/***---------------------------------------------------------\n");
  180. dprintf("Available Memory: %10lu\n\n", pFTrie->availMemory);
  181. dprintf("\n---------------------------------------------------------***/\n");
  182. dprintf("---------------------------------------------------------***/\n\n");
  183. return 0;
  184. }
  185. UINT
  186. KdPrintFTrieNode(FTrieNode *pFTrieNode, ULONG proxyPtr, ULONG printFlags)
  187. {
  188. return 0;
  189. }
  190. //
  191. // Dest Routines
  192. //
  193. UINT
  194. KdPrintDest(Dest *pDest, ULONG proxyPtr, ULONG printFlags)
  195. {
  196. UINT i;
  197. Route **pRoutes;
  198. if (proxyPtr == 0)
  199. return -1;
  200. if (pDest == NULL)
  201. {
  202. pDest = (Dest *) proxyPtr;
  203. }
  204. if (pDest->numBestRoutes > 1)
  205. {
  206. dprintf("\nBest Routes: Max = %d, Num = %d\n",
  207. pDest->maxBestRoutes,
  208. pDest->numBestRoutes);
  209. // Read the cache of equal cost routes
  210. proxyPtr += FIELD_OFFSET(Dest, bestRoutes);
  211. pRoutes = (Route **) proxyPtr;
  212. for (i = 0; i < pDest->numBestRoutes; i++)
  213. {
  214. dprintf("Best Route %d: %08x\n", i, pRoutes[i]);
  215. }
  216. }
  217. // Get the first route on the destination
  218. KdPrintRoute(NULL, (ULONG) pDest->firstRoute, printFlags);
  219. if (pDest->numBestRoutes > 1)
  220. {
  221. dprintf("\n");
  222. }
  223. return 0;
  224. }
  225. //
  226. // Route Routines
  227. //
  228. UINT
  229. KdPrintRoute(Route *pRoute, ULONG proxyPtr, ULONG printFlags)
  230. {
  231. if (proxyPtr == 0)
  232. return -1;
  233. if (pRoute == NULL)
  234. {
  235. pRoute = (Route *) proxyPtr;
  236. }
  237. dprintf("(");
  238. KdPrintIPAddr(&DEST(pRoute));
  239. dprintf(" ");
  240. KdPrintIPAddr(&MASK(pRoute));
  241. dprintf(")");
  242. while (pRoute != 0)
  243. {
  244. dprintf(" -> %08x", pRoute);
  245. pRoute = NEXT(pRoute);
  246. }
  247. dprintf("\n");
  248. return 0;
  249. }
  250. VOID
  251. KdPrintIPAddr (IN ULONG *addr)
  252. {
  253. UCHAR *addrBytes = (UCHAR *) addr;
  254. UINT i;
  255. if (addrBytes)
  256. {
  257. dprintf("%3d.", addrBytes[0]);
  258. dprintf("%3d.", addrBytes[1]);
  259. dprintf("%3d.", addrBytes[2]);
  260. dprintf("%3d ", addrBytes[3]);
  261. }
  262. else
  263. {
  264. dprintf("NULL Addr ");
  265. }
  266. }
  267. #endif // TCPIPKD