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.

667 lines
14 KiB

  1. #include <nt.h>
  2. #include <ntrtl.h>
  3. #include <nturtl.h>
  4. #include <ntddser.h>
  5. #include <windows.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <memory.h>
  9. #include <malloc.h>
  10. #include <rasman.h>
  11. #include <dim.h>
  12. #include <routprot.h>
  13. #include <ipxrtdef.h>
  14. #include <utils.h>
  15. // [pmay] this will no longer be neccessary when the ipx router
  16. // is converted to use MprInfo api's.
  17. typedef RTR_INFO_BLOCK_HEADER IPX_INFO_BLOCK_HEADER, *PIPX_INFO_BLOCK_HEADER;
  18. DIM_ROUTER_INTERFACE dimif;
  19. LPVOID
  20. GetInfoEntry(PIPX_INFO_BLOCK_HEADER InterfaceInfop,
  21. ULONG InfoEntryType);
  22. VOID
  23. TestMib(PDIM_ROUTER_INTERFACE dimifp);
  24. VOID
  25. SaveConfiguration(PDIM_ROUTER_INTERFACE dimifp);
  26. VOID
  27. RestoreConfiguration(PDIM_ROUTER_INTERFACE dimifp);
  28. VOID
  29. RouterStopped(DWORD protid,
  30. DWORD err)
  31. {
  32. printf("main: RouterStopped: protid 0x%x err 0x%x\n", protid, err);
  33. }
  34. DWORD
  35. SaveInterfaceInfo(
  36. IN HANDLE hDIMInterface,
  37. IN DWORD dwProtocolId,
  38. IN LPVOID pInterfaceInfo,
  39. IN DWORD cbInterfaceInfoSize)
  40. {
  41. printf("Main: SaveInterfaceInfo: entered for Dim if handle %d\n", hDIMInterface);
  42. return NO_ERROR;
  43. }
  44. HANDLE RmEvent;
  45. //*** IPX Router Global Info ***
  46. struct _GlobalInfo {
  47. IPX_INFO_BLOCK_HEADER GI_Header;
  48. IPX_TOC_ENTRY GI_RipTocEntry;
  49. IPX_TOC_ENTRY GI_SapTocEntry;
  50. IPX_GLOBAL_INFO GI_IpxGlobalInfo;
  51. WCHAR SapName[MAX_DLL_NAME];
  52. RIP_GLOBAL_INFO GI_RipGlobalInfo;
  53. RIP_ROUTE_FILTER_INFO GI_RipRouteFilter[15];
  54. SAP_GLOBAL_INFO GI_SapGlobalInfo;
  55. } gi;
  56. struct _GlobalInfo getgi;
  57. PWCHAR IpxRipNamep = L"IPXRIP";
  58. PWCHAR IpxSapNamep = L"IPXSAP";
  59. struct _DBG_IF {
  60. IPX_INFO_BLOCK_HEADER header;
  61. IPX_TOC_ENTRY toc[6];
  62. IPX_IF_INFO ipxifinfo;
  63. RIP_IF_INFO ripifinfo;
  64. SAP_IF_INFO sapifinfo;
  65. IPXWAN_IF_INFO ipxwanifinfo;
  66. IPX_ADAPTER_INFO adapterinfo;
  67. IPX_STATIC_ROUTE_INFO routeinfo[10];
  68. IPX_STATIC_SERVICE_INFO srvinfo[10];
  69. } dbgif;
  70. LPVOID dbgifgetp;
  71. WCHAR MainAdapterName[48];
  72. WCHAR MainInterfaceName[48];
  73. ULONG MainInterfaceType = ROUTER_IF_TYPE_DEDICATED;
  74. HANDLE MainInterfaceHandle;
  75. #define ipxtoc dbgif.header.TocEntry[0]
  76. #define riptoc dbgif.toc[0]
  77. #define saptoc dbgif.toc[1]
  78. #define ipxwantoc dbgif.toc[2]
  79. #define adaptertoc dbgif.toc[3]
  80. #define routetoc dbgif.toc[4]
  81. #define srvtoc dbgif.toc[5]
  82. VOID
  83. MainAddInterface(VOID)
  84. {
  85. PIPX_IF_INFO ipxinfop;
  86. PRIP_IF_INFO ripifinfop;
  87. PSAP_IF_INFO sapifinfop;
  88. PIPXWAN_IF_INFO ipxwaninfop;
  89. PIPX_ADAPTER_INFO adapterinfop;
  90. PIPX_STATIC_ROUTE_INFO routeinfop;
  91. PIPX_STATIC_SERVICE_INFO srvinfop;
  92. int i,j;
  93. BOOL str = FALSE; // static routes info
  94. DWORD rc, update;
  95. memset(&dbgif, 0, sizeof(dbgif));
  96. printf("Enter the interface name:");
  97. scanf("%S", &MainInterfaceName);
  98. printf("Enter the DIM Interface Handle:");
  99. scanf("%d", &i);
  100. printf("Enter interface type (0,1 - wan client, 2- wan router, 3 - lan, 4 - internal):");
  101. scanf("%d", &MainInterfaceType);
  102. switch(MainInterfaceType) {
  103. case 2:
  104. str = TRUE;
  105. break;
  106. case 3:
  107. printf("Enter LAN Adapter name:");
  108. scanf("%S", &MainAdapterName);
  109. break;
  110. default:
  111. break;
  112. }
  113. printf("Enter update mode on this interface: 1-standard, 2-none, 3-autostatic:");
  114. scanf("%d", &update);
  115. dbgif.header.Version = IPX_ROUTER_VERSION_1;
  116. dbgif.header.Size = sizeof(dbgif);
  117. if (str)
  118. dbgif.header.TocEntriesCount = 7;
  119. else
  120. dbgif.header.TocEntriesCount = 6;
  121. ipxtoc.InfoType = IPX_INTERFACE_INFO_TYPE;
  122. ipxtoc.InfoSize = sizeof(IPX_IF_INFO);
  123. ipxtoc.Count = 1;
  124. ipxtoc.Offset = (ULONG)((PUCHAR)&dbgif.ipxifinfo - (PUCHAR)&dbgif);
  125. riptoc.InfoType = IPX_PROTOCOL_RIP;
  126. riptoc.InfoSize = sizeof(RIP_IF_INFO);
  127. riptoc.Count = 1;
  128. riptoc.Offset = ipxtoc.Offset + sizeof(IPX_IF_INFO);
  129. saptoc.InfoType = IPX_PROTOCOL_SAP;
  130. saptoc.InfoSize = sizeof(SAP_IF_INFO);
  131. saptoc.Count = 1;
  132. saptoc.Offset = riptoc.Offset + sizeof(RIP_IF_INFO);
  133. ipxwantoc.InfoType = IPXWAN_INTERFACE_INFO_TYPE;
  134. ipxwantoc.InfoSize = sizeof(IPXWAN_IF_INFO);
  135. ipxwantoc.Count = 1;
  136. ipxwantoc.Offset = saptoc.Offset + sizeof(SAP_IF_INFO);
  137. adaptertoc.InfoType = IPX_ADAPTER_INFO_TYPE;
  138. adaptertoc.InfoSize = sizeof(IPX_ADAPTER_INFO);
  139. adaptertoc.Count = 1;
  140. adaptertoc.Offset = ipxwantoc.Offset + ipxwantoc.InfoSize;
  141. if (str) {
  142. routetoc.InfoType = IPX_STATIC_ROUTE_INFO_TYPE;
  143. routetoc.InfoSize = sizeof(IPX_STATIC_ROUTE_INFO);
  144. routetoc.Count = 3;
  145. routetoc.Offset = adaptertoc.Offset + adaptertoc.InfoSize;
  146. srvtoc.InfoType = IPX_STATIC_SERVICE_INFO_TYPE;
  147. srvtoc.InfoSize = sizeof(IPX_STATIC_SERVICE_INFO);
  148. srvtoc.Count = 3;
  149. srvtoc.Offset = (ULONG)((PUCHAR)&dbgif.srvinfo - (PUCHAR)&dbgif);
  150. }
  151. ipxinfop = (PIPX_IF_INFO)((PUCHAR)&dbgif + ipxtoc.Offset);
  152. ipxinfop->AdminState = ADMIN_STATE_ENABLED;
  153. ipxinfop->NetbiosAccept = ADMIN_STATE_ENABLED;
  154. ipxinfop->NetbiosDeliver = ADMIN_STATE_DISABLED;
  155. adapterinfop = (PIPX_ADAPTER_INFO)((PUCHAR)&dbgif + adaptertoc.Offset);
  156. adapterinfop->PacketType = 2;
  157. wcscpy(adapterinfop->AdapterName, MainAdapterName);
  158. ripifinfop = &dbgif.ripifinfo;
  159. ripifinfop->AdminState = ADMIN_STATE_ENABLED;
  160. ripifinfop->UpdateMode = update;
  161. ripifinfop->PacketType = IPX_STANDARD_PACKET_TYPE;
  162. ripifinfop->Supply = ADMIN_STATE_ENABLED;
  163. ripifinfop->Listen = ADMIN_STATE_ENABLED;
  164. ripifinfop->EnableGlobalFiltering = ADMIN_STATE_DISABLED;
  165. sapifinfop = &dbgif.sapifinfo;
  166. sapifinfop->AdminState = ADMIN_STATE_ENABLED;
  167. sapifinfop->UpdateMode = update;
  168. sapifinfop->PacketType = IPX_STANDARD_PACKET_TYPE;
  169. sapifinfop->Supply = ADMIN_STATE_ENABLED;
  170. sapifinfop->Listen = ADMIN_STATE_ENABLED;
  171. sapifinfop->EnableGlobalFiltering = ADMIN_STATE_DISABLED;
  172. ipxwaninfop = &dbgif.ipxwanifinfo;
  173. ipxwaninfop->AdminState = ADMIN_STATE_ENABLED;
  174. if (str) {
  175. routeinfop = dbgif.routeinfo;
  176. srvinfop = dbgif.srvinfo;
  177. for(j=0; j <3; j++, routeinfop++, srvinfop++)
  178. {
  179. memset(routeinfop->Network, 0, 4);
  180. routeinfop->Network[3] = i * 0x10 + j;
  181. routeinfop->HopCount = 1;
  182. routeinfop->TickCount = 1;
  183. memset(routeinfop->NextHopMacAddress, i * 0x10 + j, 6);
  184. srvinfop->Type = 4;
  185. strcpy(srvinfop->Name, "TEST_STATIC_SERVER00");
  186. srvinfop->Name[strlen(srvinfop->Name) - 2] = i + '0';
  187. srvinfop->Name[strlen(srvinfop->Name) - 1] = j + '0';
  188. memcpy(srvinfop->Network, routeinfop->Network, 4);
  189. memset(srvinfop->Node, i * 0x10 + j, 6);
  190. memset(srvinfop->Socket, j, 2);
  191. srvinfop->HopCount = 2;
  192. }
  193. }
  194. rc = (*dimif.AddInterface)(
  195. MainInterfaceName,
  196. &dbgif,
  197. NULL,
  198. NULL,
  199. MainInterfaceType,
  200. TRUE,
  201. (HANDLE)i,
  202. &MainInterfaceHandle);
  203. printf("main: AddInterface returned %d and IPX Interface Index = %d\n",
  204. rc, MainInterfaceHandle);
  205. }
  206. VOID
  207. MainDeleteInterface(VOID)
  208. {
  209. ULONG ii;
  210. printf("Enter IPX Interface Index:");
  211. scanf("%d", &ii);
  212. (*dimif.DeleteInterface)((HANDLE)ii);
  213. }
  214. VOID
  215. MainGetInterface(VOID)
  216. {
  217. ULONG ii;
  218. DWORD ifinfosize;
  219. DWORD infiltinfosize, outfiltinfosize;
  220. DWORD rc;
  221. printf("Enter IPX Interface Index:");
  222. scanf("%d", &ii);
  223. rc = (*dimif.GetInterfaceInfo)((HANDLE)ii,
  224. NULL,
  225. &ifinfosize,
  226. NULL,
  227. &infiltinfosize,
  228. NULL,
  229. &outfiltinfosize);
  230. if(rc != ERROR_INSUFFICIENT_BUFFER) {
  231. printf("main: GetInterfaceInfo failed with rc=%d\n", rc);
  232. return;
  233. }
  234. dbgifgetp = GlobalAlloc(GPTR, ifinfosize);
  235. rc = (*dimif.GetInterfaceInfo)((HANDLE)ii,
  236. dbgifgetp,
  237. &ifinfosize,
  238. NULL,
  239. &infiltinfosize,
  240. NULL,
  241. &outfiltinfosize);
  242. if(rc != NO_ERROR) {
  243. printf("main: GetInterfaceInfo failed on second call with rc=%d\n", rc);
  244. return;
  245. }
  246. }
  247. VOID
  248. MainSetInterface(VOID)
  249. {
  250. PIPX_IF_INFO ipxinfop;
  251. PRIP_IF_INFO ripinfop;
  252. PSAP_IF_INFO sapinfop;
  253. DWORD rc;
  254. ULONG IfIndex;
  255. ULONG AdminState, RipAdminState, RipFilter, Update;
  256. ULONG ifinfosize, infiltinfosize, outfiltinfosize;
  257. PIPX_INFO_BLOCK_HEADER InterfaceInfop;
  258. printf("Enter IPX Interface Index:");
  259. scanf("%d", &IfIndex);
  260. printf("Enter the new IPX Admin State: 1- ENABLED 2- DISABLED:");
  261. scanf("%d", &AdminState);
  262. printf("Enter the new RIP Admin State: 1- ENABLED 2- DISABLED:");
  263. scanf("%d", &RipAdminState);
  264. printf("Enter Update Mode on this interface: 1- STANDARD, 2- NONE, 3- AUTO-STATIC:");
  265. scanf("%d", &Update);
  266. printf("Enter the RIP global filter action on this if: 1- ENABLED, 2- DISABLED:");
  267. scanf("%d", &RipFilter);
  268. rc = (*dimif.GetInterfaceInfo)((HANDLE)IfIndex,
  269. NULL,
  270. &ifinfosize,
  271. NULL,
  272. &infiltinfosize,
  273. NULL,
  274. &outfiltinfosize);
  275. if(rc != ERROR_INSUFFICIENT_BUFFER) {
  276. printf("main: GetInterfaceInfo failed with rc=%d\n", rc);
  277. return;
  278. }
  279. InterfaceInfop = GlobalAlloc(GPTR, ifinfosize);
  280. rc = (*dimif.GetInterfaceInfo)((HANDLE)IfIndex,
  281. InterfaceInfop,
  282. &ifinfosize,
  283. NULL,
  284. &infiltinfosize,
  285. NULL,
  286. &outfiltinfosize);
  287. if(rc != NO_ERROR) {
  288. printf("main: GetInterfaceInfo failed on second call with rc=%d\n", rc);
  289. return;
  290. }
  291. ipxinfop = GetInfoEntry(InterfaceInfop, IPX_INTERFACE_INFO_TYPE);
  292. ipxinfop->AdminState = AdminState;
  293. ripinfop = GetInfoEntry(InterfaceInfop, IPX_PROTOCOL_RIP);
  294. ripinfop->AdminState = RipAdminState;
  295. ripinfop->UpdateMode = Update;
  296. ripinfop->EnableGlobalFiltering = RipFilter;
  297. sapinfop = GetInfoEntry(InterfaceInfop, IPX_PROTOCOL_SAP);
  298. sapinfop->UpdateMode = Update;
  299. rc = (*dimif.SetInterfaceInfo)(
  300. (HANDLE)IfIndex,
  301. InterfaceInfop,
  302. NULL,
  303. NULL);
  304. printf("main: SetInterfaceInfo returned %d \n", rc);
  305. }
  306. VOID
  307. MainUpdate(VOID)
  308. {
  309. ULONG IfIndex;
  310. DWORD UpdateResult;
  311. DWORD rc;
  312. printf("Enter interface index:");
  313. scanf("%d", &IfIndex);
  314. RmEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
  315. rc = (*dimif.UpdateRoutes)((HANDLE)IfIndex, RmEvent);
  316. if(rc != NO_ERROR) {
  317. printf("UpdateRoutes failed with rc = %d\n", rc);
  318. return;
  319. }
  320. printf("Main: Waiting for the update result ... (for 30 sec)\n");
  321. rc = WaitForSingleObject(RmEvent, 30000);
  322. if(rc == WAIT_TIMEOUT) {
  323. printf("Main: Update wait failed with timeout\n");
  324. return;
  325. }
  326. if((rc = (*dimif.GetUpdateRoutesResult)((HANDLE)IfIndex, &UpdateResult)) != NO_ERROR) {
  327. printf("Cannot get update result rc = %d\n", rc);
  328. }
  329. else
  330. {
  331. printf("UpdateResult = %d\n", UpdateResult);
  332. }
  333. CloseHandle(RmEvent);
  334. }
  335. VOID
  336. SetRipFilters(VOID)
  337. {
  338. ULONG filtcount, i, netnumber, rc;
  339. PRIP_ROUTE_FILTER_INFO rfip;
  340. printf("Enter RIP global filtering action: 1-advertise, 2-suppress:");
  341. scanf("%d", &gi.GI_RipGlobalInfo.RouteFilterAction);
  342. printf("Enter the number of filters (up to 16):");
  343. scanf("%d", &filtcount);
  344. for(i=0, rfip = &gi.GI_RipGlobalInfo.RouteFilter[0];
  345. i<filtcount;
  346. i++, rfip++)
  347. {
  348. printf("Enter net nr for filter # %d:", i);
  349. scanf("%x", &netnumber);
  350. PUTULONG2LONG(rfip->Network, netnumber);
  351. }
  352. gi.GI_RipGlobalInfo.RouteFiltersCount = filtcount;
  353. rc = (*dimif.SetGlobalInfo)(&gi);
  354. printf("SetGlobalInfo returned %d\n", rc);
  355. }
  356. VOID _cdecl
  357. main(
  358. IN WORD argc,
  359. IN LPSTR argv[]
  360. )
  361. {
  362. DWORD rc;
  363. int i;
  364. PIPX_INFO_BLOCK_HEADER ph;
  365. PIPX_TOC_ENTRY tocep;
  366. PIPX_GLOBAL_INFO ipxgp;
  367. dimif.RouterStopped = RouterStopped;
  368. dimif.SaveInterfaceInfo = SaveInterfaceInfo;
  369. ph = &gi.GI_Header;
  370. ph->Version = 1;
  371. ph->Size = sizeof(gi);
  372. ph->TocEntriesCount = 3;
  373. tocep = ph->TocEntry;
  374. tocep->InfoType = IPX_GLOBAL_INFO_TYPE;
  375. tocep->InfoSize = sizeof(IPX_GLOBAL_INFO);
  376. tocep->Count = 1;
  377. tocep->Offset = (ULONG)((PUCHAR)&gi.GI_IpxGlobalInfo - (PUCHAR)&gi);
  378. tocep++;
  379. tocep->InfoType = IPX_PROTOCOL_RIP;
  380. tocep->InfoSize = sizeof(RIP_GLOBAL_INFO);
  381. tocep->Count = 1;
  382. tocep->Offset = (ULONG)((PUCHAR)&gi.GI_RipGlobalInfo - (PUCHAR)&gi);
  383. tocep++;
  384. tocep->InfoType = IPX_PROTOCOL_SAP;
  385. tocep->InfoSize = sizeof(SAP_GLOBAL_INFO);
  386. tocep->Count = 1;
  387. tocep->Offset = (ULONG)((PUCHAR)&gi.GI_SapGlobalInfo - (PUCHAR)&gi);
  388. ipxgp = &gi.GI_IpxGlobalInfo;
  389. ipxgp->NumRoutingProtocols = 2;
  390. wcscpy(ipxgp->DllName, IpxRipNamep);
  391. wcscpy(gi.SapName, IpxSapNamep);
  392. for(;;) {
  393. printf("IPX Router Test Menu:\n");
  394. printf("1. Start Router\n");
  395. printf("2. Stop Router\n");
  396. printf("3. Add Interface\n");
  397. printf("4. Delete Interface\n");
  398. printf("5. Get Interface\n");
  399. printf("6. Set Interface\n");
  400. printf("7. Update\n");
  401. printf("8. Save Configuration\n");
  402. printf("9. Restore Configuration\n");
  403. printf("10. Rip filters test\n");
  404. printf("20. MIB Tests\n");
  405. printf("99. Exit\n");
  406. printf("Enter your option:");
  407. scanf("%d", &i);
  408. switch(i) {
  409. case 1:
  410. rc = StartRouter(&dimif, FALSE, &gi);
  411. printf("main: StartRouter returned rc=%d\n", rc);
  412. break;
  413. case 2:
  414. (*dimif.StopRouter)();
  415. printf("main: StopRouter \n");
  416. break;
  417. case 3:
  418. MainAddInterface();
  419. break;
  420. case 4:
  421. MainDeleteInterface();
  422. break;
  423. case 5:
  424. MainGetInterface();
  425. break;
  426. case 6:
  427. MainSetInterface();
  428. break;
  429. case 7:
  430. MainUpdate();
  431. break;
  432. case 8:
  433. SaveConfiguration(&dimif);
  434. break;
  435. case 9:
  436. RestoreConfiguration(&dimif);
  437. break;
  438. case 10:
  439. SetRipFilters();
  440. break;
  441. case 20:
  442. TestMib(&dimif);
  443. break;
  444. case 99:
  445. printf("exit\n");
  446. goto Exit;
  447. default:
  448. break;
  449. }
  450. }
  451. Exit:
  452. ExitProcess(0);
  453. }
  454. /*++
  455. Function: GetTocEntry
  456. Descr: Returns a pointer to the specified table of contents entry
  457. in the interface info block.
  458. --*/
  459. PIPX_TOC_ENTRY
  460. GetTocEntry(PIPX_INFO_BLOCK_HEADER InterfaceInfop,
  461. ULONG InfoEntryType)
  462. {
  463. PIPX_TOC_ENTRY tocep;
  464. UINT i;
  465. for(i=0, tocep = InterfaceInfop->TocEntry;
  466. i<InterfaceInfop->TocEntriesCount;
  467. i++, tocep++) {
  468. if(tocep->InfoType == InfoEntryType) {
  469. return tocep;
  470. }
  471. }
  472. return NULL;
  473. }
  474. /*++
  475. Function: GetInfoEntry
  476. Descr: Returns a pointer to the specified info entry in the interface
  477. control block. If more then one entries, returns a pointer to
  478. the first one.
  479. --*/
  480. LPVOID
  481. GetInfoEntry(PIPX_INFO_BLOCK_HEADER InterfaceInfop,
  482. ULONG InfoEntryType)
  483. {
  484. PIPX_TOC_ENTRY tocep;
  485. if(tocep = GetTocEntry(InterfaceInfop, InfoEntryType)) {
  486. return((LPVOID)((PUCHAR)InterfaceInfop + tocep->Offset));
  487. }
  488. else
  489. {
  490. return NULL;
  491. }
  492. }