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.

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