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.

680 lines
14 KiB

  1. /*++
  2. Copyright (c) 1999-2000 Microsoft Corporation
  3. Module Name:
  4. ip.c
  5. Abstract:
  6. Contains IP structure dumps.
  7. Author:
  8. Scott Holden (sholden) 24-Apr-1999
  9. Revision History:
  10. --*/
  11. #include "tcpipxp.h"
  12. #include "tcpipkd.h"
  13. TCPIP_DBGEXT(NetTableEntry, nte);
  14. TCPIP_DBGEXT(IPInfo, ipi);
  15. TCPIP_DBGEXT(PacketContext, pc);
  16. TCPIP_DBGEXT(ARPInterface, ai);
  17. TCPIP_DBGEXT(RouteCacheEntry, rce);
  18. TCPIP_DBGEXT(IPHeader, iph);
  19. TCPIP_DBGEXT(ICMPHeader, icmph);
  20. TCPIP_DBGEXT(ARPHeader, arph);
  21. TCPIP_DBGEXT(ARPIPAddr, aia);
  22. TCPIP_DBGEXT(ARPTableEntry, ate);
  23. TCPIP_DBGEXT(RouteTableEntry, rte);
  24. TCPIP_DBGEXT(LinkEntry, link);
  25. TCPIP_DBGEXT(Interface, interface);
  26. TCPIP_DBGEXT(IPOptInfo, ioi);
  27. TCPIP_DBGEXT(LLIPBindInfo, lip);
  28. // TCPIP_DBGEXT_LIST(LinkEntry, linklist, link_next); Now have srchlink.
  29. //
  30. // Dump IP global parameters.
  31. //
  32. DECLARE_API(gip)
  33. {
  34. dprintf(ENDL);
  35. TCPIPDump_PtrSymbol(ForwardFilterPtr);
  36. TCPIPDump_Queue(ForwardFirewallQ);
  37. TCPIPDump_PtrSymbol(DODCallout;);
  38. TCPIPDump_PtrSymbol(IPSecHandlerPtr);
  39. TCPIPDump_PtrSymbol(IPSecSendCmpltPtr);
  40. TCPIPDump_PtrSymbol(IPSecDeleteIFPtr);
  41. dprintf(ENDL);
  42. //
  43. // init.c
  44. //
  45. TCPIPDump_uint(TotalFreeInterfaces);
  46. TCPIPDump_uint(MaxFreeInterfaces);
  47. TCPIPDump_int(NumNTE);
  48. TCPIPDump_int(NumActiveNTE);
  49. TCPIPDump_ushort(NextNTEContext);
  50. TCPIPDump_uint(NET_TABLE_SIZE);
  51. TCPIPDump_ULONG(NumIF);
  52. TCPIPDump_uint(DHCPActivityCount);
  53. TCPIPDump_uint(IGMPLevel);
  54. TCPIPDump_uint(DefaultTTL);
  55. TCPIPDump_uint(DefaultTOS);
  56. TCPIPDump_uchar(RATimeout);
  57. dprintf(ENDL);
  58. //
  59. // ipxmit.c
  60. //
  61. TCPIPDump_uint(CurrentPacketCount);
  62. TCPIPDumpCfg_uint(MaxPacketCount, 0xfffffff);
  63. TCPIPDumpCfg_uint(MaxFreePacketCount, 10000);
  64. TCPIPDump_uint(FreePackets);
  65. TCPIPDump_uint(CurrentHdrBufCount);
  66. TCPIPDumpCfg_uint(MaxHdrBufCount, 0xffffffff);
  67. TCPIPDump_ULONG(IPID);
  68. dprintf(ENDL);
  69. //
  70. // iproute.c
  71. //
  72. TCPIPDump_uint(MaxFWPackets);
  73. TCPIPDump_uint(CurrentFWPackets);
  74. TCPIPDump_uint(MaxFWBufferSize);
  75. TCPIPDump_uint(CurrentFWBufferSize);
  76. TCPIPDump_uchar(ForwardPackets);
  77. TCPIPDump_uchar(RouterConfigured);
  78. TCPIPDump_uchar(ForwardBcast);
  79. TCPIPDump_uint(DefGWConfigured);
  80. TCPIPDump_uint(DefGWActive);
  81. TCPIPDump_uint(DeadGWDetect);
  82. TCPIPDump_uint(PMTUDiscovery);
  83. TCPIPDumpCfg_uint(DisableIPSourceRouting, TRUE);
  84. dprintf(ENDL);
  85. //
  86. // iprcv.c
  87. //
  88. TCPIPDumpCfg_uint(MaxRH, 100);
  89. TCPIPDump_uint(NumRH);
  90. TCPIPDumpCfg_uint(MaxOverlap, 5);
  91. TCPIPDump_uint(FragmentAttackDrops);
  92. dprintf(ENDL);
  93. //
  94. // ntip.c
  95. //
  96. TCPIPDumpCfg_uint(ArpUseEtherSnap, FALSE);
  97. TCPIPDumpCfg_uint(ArpAlwaysSourceRoute, FALSE);
  98. TCPIPDumpCfg_uint(IPAlwaysSourceRoute, TRUE);
  99. TCPIPDumpCfg_uint(DisableDHCPMediaSense, FALSE);
  100. TCPIPDump_uint(DisableMediaSenseEventLog);
  101. TCPIPDumpCfg_uint(EnableBcastArpReply, TRUE);
  102. TCPIPDumpCfg_uint(DisableTaskOffload, FALSE);
  103. TCPIPDumpCfg_ULONG(DisableUserTOS, TRUE);
  104. dprintf(ENDL);
  105. //
  106. // icmp.c, igmp.c
  107. //
  108. TCPIPDumpCfg_ULONG(DisableUserTOSSetting, TRUE);
  109. TCPIPDumpCfg_ULONG(DefaultTOSValue, 0);
  110. TCPIPDumpCfg_uint(EnableICMPRedirects, 0);
  111. TCPIPDump_uint(IcmpEchoPendingCnt);
  112. TCPIPDump_uint(IcmpErrPendingCnt);
  113. dprintf(ENDL);
  114. //
  115. // arp.c
  116. //
  117. TCPIPDump_uint(ChkSumReset);
  118. TCPIPDump_uint(ChkSumIPFail);
  119. TCPIPDump_uint(ChkSumTCPFail);
  120. TCPIPDump_uint(ChkSumSuccess);
  121. dprintf(ENDL);
  122. TCPIPDumpCfg_uint(ArpCacheLife, DEFAULT_ARP_CACHE_LIFE);
  123. TCPIPDumpCfg_uint(ArpMinValidCacheLife, DEFAULT_ARP_MIN_VALID_CACHE_LIFE);
  124. TCPIPDumpCfg_uint(ArpRetryCount, DEFAULT_ARP_RETRY_COUNT);
  125. TCPIPDump_uint(sArpAlwaysSourceRoute);
  126. TCPIPDump_uint(sIPAlwaysSourceRoute);
  127. dprintf(ENDL);
  128. //
  129. // iploop.c
  130. //
  131. TCPIPDump_uint(LoopIndex);
  132. TCPIPDump_uint(LoopInstance);
  133. dprintf(ENDL);
  134. }
  135. //
  136. // Converts a DWORD into IP address format a.b.c.d.
  137. //
  138. DECLARE_API(ipaddr)
  139. {
  140. ULONG ipaddress;
  141. if (args == 0 || !*args)
  142. {
  143. dprintf("Usage: ipaddr <ip address>" ENDL);
  144. return;
  145. }
  146. ipaddress = GetExpression(args);
  147. dprintf("IP Address: ");
  148. DumpIPAddr(ipaddress);
  149. dprintf(ENDL);
  150. return;
  151. }
  152. //
  153. // Dumps a 6 byte ethernet addr in x-x-x-x-x-x format.
  154. //
  155. DECLARE_API(macaddr)
  156. {
  157. ULONG_PTR MacAddr;
  158. UCHAR Mac[ARP_802_ADDR_LENGTH];
  159. BOOL fStatus;
  160. if (args == 0 || !*args)
  161. {
  162. dprintf("Usage: macaddr <ptr>" ENDL);
  163. return;
  164. }
  165. MacAddr = GetExpression(args);
  166. fStatus = GetData(
  167. Mac,
  168. ARP_802_ADDR_LENGTH,
  169. MacAddr,
  170. "MAC address");
  171. if (fStatus == FALSE)
  172. {
  173. dprintf("Failed to read MAC address @ %x" ENDL, MacAddr);
  174. return;
  175. }
  176. dprintf("MAC Address: %2.2x-%2.2x-%2.2x-%2.2x-%2.2x-%2.2x" ENDL,
  177. Mac[0], Mac[1], Mac[2], Mac[3], Mac[4], Mac[5], Mac[6]);
  178. return;
  179. }
  180. //
  181. // Searches NTE list.
  182. //
  183. DECLARE_API(srchntelist)
  184. {
  185. NetTableEntry **NteList = NULL;
  186. ULONG_PTR NteListAddr;
  187. ULONG NteListSize;
  188. BOOL fStatus;
  189. ULONG i;
  190. ULONG cTotalNtes = 0;
  191. PTCPIP_SRCH pSrch = NULL;
  192. pSrch = ParseSrch(
  193. args,
  194. TCPIP_SRCH_ALL,
  195. TCPIP_SRCH_ALL | TCPIP_SRCH_IPADDR | TCPIP_SRCH_CONTEXT);
  196. if (pSrch == NULL)
  197. {
  198. dprintf("srchntelist: Invalid parameter" ENDL);
  199. goto done;
  200. }
  201. NteListAddr = GetUlongValue("tcpip!NewNetTableList");
  202. NteListSize = GetUlongValue("tcpip!NET_TABLE_SIZE");
  203. NteList = LocalAlloc(LPTR, sizeof(NetTableEntry *) * NteListSize);
  204. if (NteList == NULL)
  205. {
  206. dprintf("Failed to allocate nte list" ENDL);
  207. goto done;
  208. }
  209. fStatus = GetData(
  210. NteList,
  211. sizeof(NetTableEntry *) * NteListSize,
  212. NteListAddr,
  213. "NteList");
  214. if (fStatus == FALSE)
  215. {
  216. dprintf("Failed to read table %x" ENDL, NteListAddr);
  217. goto done;
  218. }
  219. dprintf("NteList %x, size %d" ENDL, NteListAddr, NteListSize);
  220. for (i = 0; i < NteListSize; i++)
  221. {
  222. NetTableEntry Nte;
  223. BOOL fPrint;
  224. NetTableEntry *pNte;
  225. pNte = NteList[i];
  226. while (pNte != NULL)
  227. {
  228. cTotalNtes++;
  229. fStatus = GetData(&Nte, sizeof(NetTableEntry), (ULONG_PTR)pNte, "NTE");
  230. if (fStatus == FALSE)
  231. {
  232. dprintf("Failed to get NTE %x" ENDL, pNte);
  233. goto done;
  234. }
  235. fPrint = FALSE;
  236. switch (pSrch->ulOp)
  237. {
  238. case TCPIP_SRCH_CONTEXT:
  239. if (Nte.nte_context == (ushort)pSrch->context)
  240. {
  241. fPrint = TRUE;
  242. }
  243. break;
  244. case TCPIP_SRCH_IPADDR:
  245. if (Nte.nte_addr == pSrch->ipaddr)
  246. {
  247. fPrint = TRUE;
  248. }
  249. break;
  250. case TCPIP_SRCH_ALL:
  251. fPrint = TRUE;
  252. break;
  253. }
  254. if (fPrint == TRUE)
  255. {
  256. dprintf("[%4d] ", i);
  257. fStatus = DumpNetTableEntry(&Nte, (ULONG_PTR) pNte, g_Verbosity);
  258. if (fStatus == FALSE)
  259. {
  260. dprintf("Failed to dump NTE %x" ENDL, pNte);
  261. }
  262. }
  263. pNte = Nte.nte_next;
  264. if (CheckControlC())
  265. {
  266. goto done;
  267. }
  268. }
  269. }
  270. dprintf("Total NTEs = %d" ENDL, cTotalNtes);
  271. done:
  272. if (NteList)
  273. {
  274. LocalFree(NteList);
  275. }
  276. if (pSrch)
  277. {
  278. LocalFree(pSrch);
  279. }
  280. return;
  281. }
  282. DECLARE_API(srchlink)
  283. {
  284. BOOL fStatus;
  285. LinkEntry Link;
  286. PTCPIP_SRCH pSrch = NULL;
  287. BOOL fPrint;
  288. pSrch = ParseSrch(
  289. args,
  290. TCPIP_SRCH_ALL,
  291. TCPIP_SRCH_PTR_LIST | TCPIP_SRCH_ALL | TCPIP_SRCH_IPADDR);
  292. if (pSrch == NULL)
  293. {
  294. dprintf("!srchlink <ptr> [ipaddr <a.b.c.d>]" ENDL);
  295. goto done;
  296. }
  297. while (pSrch->ListAddr)
  298. {
  299. fStatus = GetData(
  300. &Link,
  301. sizeof(LinkEntry),
  302. pSrch->ListAddr,
  303. "LinkEntry");
  304. if (fStatus == FALSE)
  305. {
  306. dprintf("Failed to get LinkEntry @ %x" ENDL, pSrch->ListAddr);
  307. goto done;
  308. }
  309. fPrint = FALSE;
  310. switch (pSrch->ulOp)
  311. {
  312. case TCPIP_SRCH_IPADDR:
  313. if (Link.link_NextHop == pSrch->ipaddr)
  314. {
  315. fPrint = TRUE;
  316. }
  317. break;
  318. case TCPIP_SRCH_ALL:
  319. fPrint = TRUE;
  320. break;
  321. }
  322. if (fPrint == TRUE)
  323. {
  324. fStatus = DumpLinkEntry(&Link, pSrch->ListAddr, g_Verbosity);
  325. if (fStatus == FALSE)
  326. {
  327. dprintf("Failed to dump LinkEntry @ %x" ENDL, pSrch->ListAddr);
  328. goto done;
  329. }
  330. }
  331. pSrch->ListAddr = (ULONG_PTR) Link.link_next;
  332. if (CheckControlC())
  333. {
  334. goto done;
  335. }
  336. }
  337. done:
  338. if (pSrch != NULL)
  339. {
  340. LocalFree(pSrch);
  341. }
  342. return;
  343. }
  344. //
  345. // Searches Interface list.
  346. //
  347. DECLARE_API(iflist)
  348. {
  349. Interface *pIf = NULL;
  350. Interface interface;
  351. ULONG_PTR IfListAddr;
  352. ULONG IfListSize;
  353. BOOL fStatus;
  354. IfListAddr = GetUlongValue("tcpip!IFList");
  355. IfListSize = GetUlongValue("tcpip!NumIF");
  356. pIf = (Interface *) IfListAddr;
  357. dprintf("IfList %x, size %d" ENDL, IfListAddr, IfListSize);
  358. while (pIf)
  359. {
  360. fStatus = GetData(
  361. &interface,
  362. sizeof(Interface),
  363. (ULONG_PTR) pIf,
  364. "Interface");
  365. if (fStatus == FALSE)
  366. {
  367. dprintf("Failed to read Interface @ %x" ENDL, pIf);
  368. goto done;
  369. }
  370. fStatus = DumpInterface(&interface, (ULONG_PTR) pIf, g_Verbosity);
  371. if (fStatus == FALSE)
  372. {
  373. dprintf("Failed to dump Interface @ %x" ENDL, pIf);
  374. goto done;
  375. }
  376. pIf = interface.if_next;
  377. if (CheckControlC())
  378. {
  379. goto done;
  380. }
  381. }
  382. done:
  383. return;
  384. }
  385. //
  386. // Searches ARPInterface list.
  387. //
  388. DECLARE_API(ailist)
  389. {
  390. ARPInterface *pAi = NULL;
  391. ARPInterface ai;
  392. ULONG_PTR AiListAddr;
  393. BOOL fStatus;
  394. LIST_ENTRY AiList;
  395. PLIST_ENTRY pNext;
  396. AiListAddr = GetExpression("tcpip!ArpInterfaceList");
  397. fStatus = GetData(
  398. &AiList,
  399. sizeof(LIST_ENTRY),
  400. AiListAddr,
  401. "ArpInterfaceList");
  402. if (fStatus == FALSE)
  403. {
  404. dprintf("Failed to get ArpInterfacelist head @ %x" ENDL, AiListAddr);
  405. goto done;
  406. }
  407. dprintf("ArpInterfaceList %x:" ENDL, AiListAddr);
  408. pNext = AiList.Flink;
  409. while (pNext != (PLIST_ENTRY) AiListAddr)
  410. {
  411. pAi = STRUCT_OF(ARPInterface, pNext, ai_linkage);
  412. fStatus = GetData(
  413. &ai,
  414. sizeof(ARPInterface),
  415. (ULONG_PTR) pAi,
  416. "ARPInterface");
  417. if (fStatus == FALSE)
  418. {
  419. dprintf("Failed to read ARPInterface @ %x" ENDL, pAi);
  420. goto done;
  421. }
  422. fStatus = DumpARPInterface(&ai, (ULONG_PTR) pAi, g_Verbosity);
  423. if (fStatus == FALSE)
  424. {
  425. dprintf("Failed to dump ARPInterface @ %x" ENDL, pAi);
  426. goto done;
  427. }
  428. pNext = ai.ai_linkage.Flink;
  429. if (CheckControlC())
  430. {
  431. goto done;
  432. }
  433. }
  434. done:
  435. return;
  436. }
  437. //
  438. // Dumps specified ARPTable (ATEs).
  439. //
  440. DECLARE_API(arptable)
  441. {
  442. ARPTableEntry **ArpTable = NULL;
  443. ULONG_PTR ArpTableAddr;
  444. ULONG ArpTableSize;
  445. ULONG cActiveAtes = 0;
  446. ULONG i;
  447. BOOL fStatus;
  448. if (*args == 0)
  449. {
  450. dprintf("!arptable <ptr>" ENDL);
  451. goto done;
  452. }
  453. ArpTableAddr = GetExpression(args);
  454. ArpTableSize = ARP_TABLE_SIZE;
  455. ArpTable = LocalAlloc(LPTR, ArpTableSize * sizeof(ARPTableEntry *));
  456. if (ArpTable == NULL)
  457. {
  458. dprintf("Failed to allocate ArpTable" ENDL);
  459. goto done;
  460. }
  461. fStatus = GetData(
  462. ArpTable,
  463. sizeof(ARPTableEntry *) * ArpTableSize,
  464. ArpTableAddr,
  465. "ArpTable");
  466. if (fStatus == FALSE)
  467. {
  468. dprintf("Failed to read ArpTable @ %x" ENDL, ArpTableAddr);
  469. goto done;
  470. }
  471. for (i = 0; i < ArpTableSize; i++)
  472. {
  473. ARPTableEntry ate;
  474. ARPTableEntry *pAte;
  475. pAte = ArpTable[i];
  476. while (pAte)
  477. {
  478. cActiveAtes++;
  479. fStatus = GetData(
  480. &ate,
  481. sizeof(ARPTableEntry),
  482. (ULONG_PTR) pAte,
  483. "ARPTableEntry");
  484. if (fStatus == FALSE)
  485. {
  486. dprintf("Failed to read ARPTableEntry @ %x" ENDL, pAte);
  487. goto done;
  488. }
  489. fStatus = DumpARPTableEntry(&ate, (ULONG_PTR) pAte, g_Verbosity);
  490. if (fStatus == FALSE)
  491. {
  492. dprintf("Failed to dump ARPTableEntry @ %x" ENDL, pAte);
  493. goto done;
  494. }
  495. pAte = ate.ate_next;
  496. if (CheckControlC())
  497. {
  498. goto done;
  499. }
  500. }
  501. if (CheckControlC())
  502. {
  503. goto done;
  504. }
  505. }
  506. dprintf("Active ARPTable entries = %d" ENDL, cActiveAtes);
  507. done:
  508. if (ArpTable)
  509. {
  510. LocalFree(ArpTable);
  511. }
  512. return;
  513. }