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.

796 lines
15 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. VOID
  18. PrintInterface(PIPX_INTERFACE ifp);
  19. VOID
  20. PrintRipInterface(PRIP_INTERFACE ifp);
  21. typedef struct _RPNAM {
  22. ULONG prot;
  23. PUCHAR namep;
  24. } RPNAM, *PRPNAM;
  25. RPNAM ProtName[] = {
  26. { IPX_PROTOCOL_LOCAL, "LOCAL" },
  27. { IPX_PROTOCOL_STATIC, "STATIC" },
  28. { IPX_PROTOCOL_RIP, "RIP" },
  29. { IPX_PROTOCOL_SAP, "SAP" }
  30. };
  31. #define MAX_IPX_PROTOCOLS sizeof(ProtName)/sizeof(RPNAM)
  32. IPX_INTERFACE IpxIf;
  33. VOID
  34. GetIpxInterface(PDIM_ROUTER_INTERFACE dimifp)
  35. {
  36. ULONG ii;
  37. DWORD rc;
  38. IPX_MIB_GET_INPUT_DATA MibGetInputData;
  39. DWORD IfSize;
  40. IfSize = sizeof(IPX_INTERFACE);
  41. printf("Enter interface index:");
  42. scanf("%d", &ii);
  43. MibGetInputData.TableId = IPX_INTERFACE_TABLE;
  44. MibGetInputData.MibIndex.InterfaceTableIndex.InterfaceIndex = ii;
  45. rc = (*(dimifp->MIBEntryGet))(
  46. IPX_PROTOCOL_BASE,
  47. sizeof(IPX_MIB_GET_INPUT_DATA),
  48. &MibGetInputData,
  49. &IfSize,
  50. &IpxIf);
  51. if(rc != NO_ERROR) {
  52. printf("MibEntryGet: failed rc = %d\n", rc);
  53. return;
  54. }
  55. PrintInterface(&IpxIf);
  56. }
  57. VOID
  58. GetRipInterface(PDIM_ROUTER_INTERFACE dimifp)
  59. {
  60. DWORD rc;
  61. ULONG IfSize;
  62. RIP_MIB_GET_INPUT_DATA RipMibGetInputData;
  63. RIP_INTERFACE RipIf;
  64. printf("Enter interface index:");
  65. scanf("%d", &RipMibGetInputData.InterfaceIndex);
  66. RipMibGetInputData.TableId = RIP_INTERFACE_TABLE;
  67. rc = (*(dimifp->MIBEntryGet))(
  68. IPX_PROTOCOL_RIP,
  69. sizeof(RIP_MIB_GET_INPUT_DATA),
  70. &RipMibGetInputData,
  71. &IfSize,
  72. &RipIf);
  73. if(rc != NO_ERROR) {
  74. printf("MibEntryGet: failed rc = %d\n", rc);
  75. return;
  76. }
  77. PrintRipInterface(&RipIf);
  78. }
  79. VOID
  80. GetRipFilters(PDIM_ROUTER_INTERFACE dimifp)
  81. {
  82. DWORD rc;
  83. ULONG GlobalInfoSize, i;
  84. RIP_MIB_GET_INPUT_DATA RipMibGetInputData;
  85. PRIP_GLOBAL_INFO RipGlobalInfop;
  86. PRIP_ROUTE_FILTER_INFO rfip;
  87. char *action;
  88. RipMibGetInputData.TableId = RIP_GLOBAL_INFO_ENTRY;
  89. rc = (*(dimifp->MIBEntryGet))(
  90. IPX_PROTOCOL_RIP,
  91. sizeof(RIP_MIB_GET_INPUT_DATA),
  92. &RipMibGetInputData,
  93. &GlobalInfoSize,
  94. NULL);
  95. if(rc != ERROR_INSUFFICIENT_BUFFER) {
  96. printf("MibEntryGet: failed rc = %d\n", rc);
  97. return;
  98. }
  99. RipGlobalInfop = GlobalAlloc(GPTR, GlobalInfoSize);
  100. rc = (*(dimifp->MIBEntryGet))(
  101. IPX_PROTOCOL_RIP,
  102. sizeof(RIP_MIB_GET_INPUT_DATA),
  103. &RipMibGetInputData,
  104. &GlobalInfoSize,
  105. RipGlobalInfop);
  106. if(rc != NO_ERROR) {
  107. printf("MibEntryGet: failed rc = %d\n", rc);
  108. return;
  109. }
  110. if(RipGlobalInfop->RouteFiltersCount == 0) {
  111. printf("No Filters\n");
  112. return;
  113. }
  114. if(RipGlobalInfop->RouteFilterAction == IPX_ROUTE_FILTER_ADVERTISE) {
  115. action = "ADVERTISE";
  116. }
  117. else
  118. {
  119. action = "SUPPRESS";
  120. }
  121. printf("There are %d RIP filters configured for %s\n",
  122. RipGlobalInfop->RouteFiltersCount,
  123. action);
  124. for(i=0, rfip=RipGlobalInfop->RouteFilter;
  125. i<RipGlobalInfop->RouteFiltersCount;
  126. i++, rfip++)
  127. {
  128. printf("Route filter # %d Network %.2x%.2x%.2x%.2x\n",
  129. i,
  130. rfip->Network[0],
  131. rfip->Network[1],
  132. rfip->Network[2],
  133. rfip->Network[3]);
  134. }
  135. GlobalFree(RipGlobalInfop);
  136. }
  137. VOID
  138. PrintInterface(PIPX_INTERFACE ifp)
  139. {
  140. char *iftype;
  141. char *admin;
  142. char *oper;
  143. switch(ifp->InterfaceType) {
  144. case IF_TYPE_WAN_WORKSTATION:
  145. iftype ="WAN WORKSTATION";
  146. break;
  147. case IF_TYPE_WAN_ROUTER:
  148. iftype = "WAN ROUTER";
  149. break;
  150. case IF_TYPE_LAN:
  151. iftype = "LAN";
  152. break;
  153. case IF_TYPE_INTERNAL:
  154. iftype = "INTERNAL";
  155. break;
  156. default:
  157. iftype = "UNKNOWN";
  158. break;
  159. }
  160. switch(ifp->AdminState) {
  161. case ADMIN_STATE_ENABLED:
  162. admin = "ENABLED";
  163. break;
  164. case ADMIN_STATE_DISABLED:
  165. admin = "DISABLED";
  166. break;
  167. default:
  168. admin = "UNKNOWN";
  169. break;
  170. }
  171. switch(ifp->IfStats.IfOperState) {
  172. case OPER_STATE_UP:
  173. oper = "UP";
  174. break;
  175. case OPER_STATE_DOWN:
  176. oper = "DOWN";
  177. break;
  178. case OPER_STATE_SLEEPING:
  179. oper = "SLEEPING";
  180. break;
  181. default:
  182. oper = "UNKNOWN";
  183. break;
  184. }
  185. printf("\n");
  186. printf("Interface Index: %d\n", ifp->InterfaceIndex);
  187. printf("Name: %s\n", ifp->InterfaceName);
  188. printf("Type: %s\n", iftype);
  189. printf("Network Number: %.2x%.2x%.2x%.2x\n",
  190. ifp->NetNumber[0],
  191. ifp->NetNumber[1],
  192. ifp->NetNumber[2],
  193. ifp->NetNumber[3]);
  194. printf("Admin State: %s\n", admin);
  195. printf("Oper State: %s\n\n", oper);
  196. }
  197. #define REPORT_RIP_CONFIG_STATE(report, config) \
  198. switch((config)) {\
  199. case ADMIN_STATE_ENABLED:\
  200. (report) = "ENABLED";\
  201. break;\
  202. case ADMIN_STATE_DISABLED:\
  203. (report) = "DISABLED";\
  204. break;\
  205. default:\
  206. (report) = "UNKNOWN";\
  207. break;\
  208. }
  209. VOID
  210. PrintRipInterface(PRIP_INTERFACE ifp)
  211. {
  212. char *admin;
  213. char *oper;
  214. char *filtering;
  215. char *supply;
  216. char *listen;
  217. char *update;
  218. REPORT_RIP_CONFIG_STATE(admin, ifp->RipIfInfo.AdminState);
  219. REPORT_RIP_CONFIG_STATE(supply, ifp->RipIfInfo.Supply);
  220. REPORT_RIP_CONFIG_STATE(listen, ifp->RipIfInfo.Listen);
  221. REPORT_RIP_CONFIG_STATE(filtering, ifp->RipIfInfo.EnableGlobalFiltering);
  222. switch(ifp->RipIfStats.RipIfOperState) {
  223. case OPER_STATE_UP:
  224. oper = "UP";
  225. break;
  226. case OPER_STATE_DOWN:
  227. oper = "DOWN";
  228. break;
  229. case OPER_STATE_SLEEPING:
  230. oper = "SLEEPING";
  231. break;
  232. default:
  233. oper = "UNKNOWN";
  234. break;
  235. }
  236. switch(ifp->RipIfInfo.UpdateMode) {
  237. case IPX_STANDARD_UPDATE:
  238. update = "STANDARD";
  239. break;
  240. case IPX_NO_UPDATE:
  241. update = "NO UPDATE";
  242. break;
  243. case IPX_AUTO_STATIC_UPDATE:
  244. update = "AUTO-STATIC";
  245. break;
  246. default:
  247. break;
  248. }
  249. printf("\n");
  250. printf("Interface Index: %d\n", ifp->InterfaceIndex);
  251. printf("Admin State: %s\n", admin);
  252. printf("Oper State: %s\n", oper);
  253. printf("Supply RIP advertisments: %s\n", supply);
  254. printf("Listen to RIP advertisments: %s\n", listen);
  255. printf("Enable Global RIP Filtering: %s\n", filtering);
  256. printf("Update Mode: %s\n", update);
  257. printf("RIP packets recv: %d\n", ifp->RipIfStats.RipIfInputPackets);
  258. printf("RIP packets sent: %d\n\n", ifp->RipIfStats.RipIfOutputPackets);
  259. }
  260. VOID
  261. EnumerateIpxInterfaces(PDIM_ROUTER_INTERFACE dimifp)
  262. {
  263. DWORD rc;
  264. IPX_MIB_GET_INPUT_DATA MibGetInputData;
  265. DWORD IfSize;
  266. IfSize = sizeof(IPX_INTERFACE);
  267. MibGetInputData.TableId = IPX_INTERFACE_TABLE;
  268. MibGetInputData.MibIndex.InterfaceTableIndex.InterfaceIndex = 0;
  269. rc = (*(dimifp->MIBEntryGetFirst))(
  270. IPX_PROTOCOL_BASE,
  271. sizeof(IPX_MIB_GET_INPUT_DATA),
  272. &MibGetInputData,
  273. &IfSize,
  274. &IpxIf);
  275. if(rc != NO_ERROR) {
  276. printf("MIBEntryGetFirst: failed rc = %d\n", rc);
  277. return;
  278. }
  279. PrintInterface(&IpxIf);
  280. for(;;)
  281. {
  282. MibGetInputData.MibIndex.InterfaceTableIndex.InterfaceIndex = IpxIf.InterfaceIndex;
  283. rc = (*(dimifp->MIBEntryGetNext))(
  284. IPX_PROTOCOL_BASE,
  285. sizeof(IPX_MIB_GET_INPUT_DATA),
  286. &MibGetInputData,
  287. &IfSize,
  288. &IpxIf);
  289. if(rc != NO_ERROR) {
  290. printf("EnumerateIpxInterfaces: MIBEntryGetNext failed rc= 0x%x\n", rc);
  291. return;
  292. }
  293. PrintInterface(&IpxIf);
  294. }
  295. }
  296. IPX_ROUTE Route;
  297. VOID
  298. PrintRoute(VOID);
  299. VOID
  300. EnumerateAllBestRoutes(PDIM_ROUTER_INTERFACE dimifp)
  301. {
  302. DWORD rc;
  303. IPX_MIB_GET_INPUT_DATA MibGetInputData;
  304. DWORD RtSize;
  305. RtSize = sizeof(IPX_ROUTE);
  306. MibGetInputData.TableId = IPX_DEST_TABLE;
  307. memset(MibGetInputData.MibIndex.RoutingTableIndex.Network, 0, 4);
  308. rc = (*(dimifp->MIBEntryGetFirst))(
  309. IPX_PROTOCOL_BASE,
  310. sizeof(IPX_MIB_GET_INPUT_DATA),
  311. &MibGetInputData,
  312. &RtSize,
  313. &Route);
  314. if(rc != NO_ERROR) {
  315. printf("MIBEntryGetFirst: failed rc = %d\n", rc);
  316. return;
  317. }
  318. PrintRoute();
  319. for(;;)
  320. {
  321. memcpy(MibGetInputData.MibIndex.RoutingTableIndex.Network, Route.Network, 4);
  322. rc = (*(dimifp->MIBEntryGetNext))(
  323. IPX_PROTOCOL_BASE,
  324. sizeof(IPX_MIB_GET_INPUT_DATA),
  325. &MibGetInputData,
  326. &RtSize,
  327. &Route);
  328. if(rc != NO_ERROR) {
  329. printf("MIBEntryGetNext failed rc= 0x%x\n", rc);
  330. return;
  331. }
  332. PrintRoute();
  333. }
  334. }
  335. VOID
  336. PrintRoute(VOID)
  337. {
  338. int i;
  339. PUCHAR pn = "BOGUS";
  340. for(i=0; i<MAX_IPX_PROTOCOLS; i++) {
  341. if(ProtName[i].prot == Route.Protocol) {
  342. pn = ProtName[i].namep;
  343. break;
  344. }
  345. }
  346. printf("Route: if # 0x%x, prot %s net %.2x%.2x%.2x%.2x ticks %d hops %d nexthop %.2x%.2x%.2x%.2x%.2x%.2x\n",
  347. Route.InterfaceIndex,
  348. pn,
  349. Route.Network[0],
  350. Route.Network[1],
  351. Route.Network[2],
  352. Route.Network[3],
  353. Route.TickCount,
  354. Route.HopCount,
  355. Route.NextHopMacAddress[0],
  356. Route.NextHopMacAddress[1],
  357. Route.NextHopMacAddress[2],
  358. Route.NextHopMacAddress[3],
  359. Route.NextHopMacAddress[4],
  360. Route.NextHopMacAddress[5]);
  361. }
  362. VOID
  363. EnumerateStaticRoutes(PDIM_ROUTER_INTERFACE dimifp)
  364. {
  365. DWORD rc;
  366. IPX_MIB_GET_INPUT_DATA MibGetInputData;
  367. DWORD RtSize;
  368. RtSize = sizeof(IPX_ROUTE);
  369. MibGetInputData.TableId = IPX_STATIC_ROUTE_TABLE;
  370. MibGetInputData.MibIndex.StaticRoutesTableIndex.InterfaceIndex = 0;
  371. memset(MibGetInputData.MibIndex.StaticRoutesTableIndex.Network, 0, 4);
  372. rc = (*(dimifp->MIBEntryGetFirst))(
  373. IPX_PROTOCOL_BASE,
  374. sizeof(IPX_MIB_GET_INPUT_DATA),
  375. &MibGetInputData,
  376. &RtSize,
  377. &Route);
  378. if(rc != NO_ERROR) {
  379. printf("MIBEntryGetFirst: failed rc = %d\n", rc);
  380. return;
  381. }
  382. PrintRoute();
  383. for(;;)
  384. {
  385. memcpy(MibGetInputData.MibIndex.StaticRoutesTableIndex.Network, Route.Network, 4);
  386. MibGetInputData.MibIndex.StaticRoutesTableIndex.InterfaceIndex = Route.InterfaceIndex;
  387. rc = (*(dimifp->MIBEntryGetNext))(
  388. IPX_PROTOCOL_BASE,
  389. sizeof(IPX_MIB_GET_INPUT_DATA),
  390. &MibGetInputData,
  391. &RtSize,
  392. &Route);
  393. if(rc != NO_ERROR) {
  394. printf("MIBEntryGetNext failed rc= 0x%x\n", rc);
  395. return;
  396. }
  397. PrintRoute();
  398. }
  399. }
  400. IPX_SERVICE Service;
  401. VOID
  402. PrintService(VOID)
  403. {
  404. int i;
  405. PUCHAR pn = "BOGUS";
  406. for(i=0; i<MAX_IPX_PROTOCOLS; i++) {
  407. if(ProtName[i].prot == Service.Protocol) {
  408. pn = ProtName[i].namep;
  409. break;
  410. }
  411. }
  412. printf("Service if # %d prot %s type %d name %s\n",
  413. Service.InterfaceIndex,
  414. pn,
  415. Service.Server.Type,
  416. Service.Server.Name);
  417. }
  418. VOID
  419. EnumerateAllServers(PDIM_ROUTER_INTERFACE dimifp)
  420. {
  421. DWORD rc;
  422. IPX_MIB_GET_INPUT_DATA MibGetInputData;
  423. DWORD SvSize;
  424. SvSize = sizeof(IPX_SERVICE);
  425. MibGetInputData.TableId = IPX_SERV_TABLE;
  426. MibGetInputData.MibIndex.ServicesTableIndex.ServiceType = 0;
  427. memset(MibGetInputData.MibIndex.ServicesTableIndex.ServiceName, 0, 48);
  428. rc = (*(dimifp->MIBEntryGetFirst))(
  429. IPX_PROTOCOL_BASE,
  430. sizeof(IPX_MIB_GET_INPUT_DATA),
  431. &MibGetInputData,
  432. &SvSize,
  433. &Service);
  434. if(rc != NO_ERROR) {
  435. printf("MIBEntryGetFirst: failed rc = %d\n", rc);
  436. return;
  437. }
  438. PrintService();
  439. for(;;)
  440. {
  441. MibGetInputData.MibIndex.ServicesTableIndex.ServiceType = Service.Server.Type;
  442. memcpy(MibGetInputData.MibIndex.ServicesTableIndex.ServiceName, Service.Server.Name, 48);
  443. rc = (*(dimifp->MIBEntryGetNext))(
  444. IPX_PROTOCOL_BASE,
  445. sizeof(IPX_MIB_GET_INPUT_DATA),
  446. &MibGetInputData,
  447. &SvSize,
  448. &Service);
  449. if(rc != NO_ERROR) {
  450. printf("MIBEntryGetNext failed rc= 0x%x\n", rc);
  451. return;
  452. }
  453. PrintService();
  454. }
  455. }
  456. VOID
  457. EnumerateAllServersOfType(PDIM_ROUTER_INTERFACE dimifp,
  458. USHORT Type)
  459. {
  460. DWORD rc;
  461. IPX_MIB_GET_INPUT_DATA MibGetInputData;
  462. DWORD SvSize;
  463. SvSize = sizeof(IPX_SERVICE);
  464. MibGetInputData.TableId = IPX_SERV_TABLE;
  465. MibGetInputData.MibIndex.ServicesTableIndex.ServiceType = Type;
  466. memset(MibGetInputData.MibIndex.ServicesTableIndex.ServiceName, ' ', 40);
  467. for(;;)
  468. {
  469. rc = (*(dimifp->MIBEntryGetNext))(
  470. IPX_PROTOCOL_BASE,
  471. sizeof(IPX_MIB_GET_INPUT_DATA),
  472. &MibGetInputData,
  473. &SvSize,
  474. &Service);
  475. if(rc != NO_ERROR) {
  476. printf("MIBEntryGetNext failed rc= 0x%x\n", rc);
  477. return;
  478. }
  479. if(Service.Server.Type != Type)
  480. {
  481. return;
  482. }
  483. PrintService();
  484. memcpy(MibGetInputData.MibIndex.ServicesTableIndex.ServiceName, Service.Server.Name, 48);
  485. }
  486. }
  487. VOID
  488. EnumerateStaticServers(PDIM_ROUTER_INTERFACE dimifp)
  489. {
  490. DWORD rc;
  491. IPX_MIB_GET_INPUT_DATA MibGetInputData;
  492. DWORD SvSize;
  493. SvSize = sizeof(IPX_SERVICE);
  494. MibGetInputData.TableId = IPX_STATIC_SERV_TABLE;
  495. MibGetInputData.MibIndex.StaticServicesTableIndex.InterfaceIndex = 0;
  496. MibGetInputData.MibIndex.StaticServicesTableIndex.ServiceType = 0;
  497. memset(MibGetInputData.MibIndex.ServicesTableIndex.ServiceName, 0, 48);
  498. rc = (*(dimifp->MIBEntryGetFirst))(
  499. IPX_PROTOCOL_BASE,
  500. sizeof(IPX_MIB_GET_INPUT_DATA),
  501. &MibGetInputData,
  502. &SvSize,
  503. &Service);
  504. if(rc != NO_ERROR) {
  505. printf("MIBEntryGetFirst: failed rc = %d\n", rc);
  506. return;
  507. }
  508. PrintService();
  509. for(;;)
  510. {
  511. MibGetInputData.MibIndex.StaticServicesTableIndex.InterfaceIndex = Service.InterfaceIndex;
  512. MibGetInputData.MibIndex.StaticServicesTableIndex.ServiceType = Service.Server.Type;
  513. memcpy(MibGetInputData.MibIndex.StaticServicesTableIndex.ServiceName, Service.Server.Name, 48);
  514. rc = (*(dimifp->MIBEntryGetNext))(
  515. IPX_PROTOCOL_BASE,
  516. sizeof(IPX_MIB_GET_INPUT_DATA),
  517. &MibGetInputData,
  518. &SvSize,
  519. &Service);
  520. if(rc != NO_ERROR) {
  521. printf("MIBEntryGetNext failed rc= 0x%x\n", rc);
  522. return;
  523. }
  524. PrintService();
  525. }
  526. }
  527. VOID
  528. TestMib(PDIM_ROUTER_INTERFACE dimifp)
  529. {
  530. int i;
  531. int Type;
  532. for(;;) {
  533. printf(" MIB TEST OPTIONS MENU:\n");
  534. printf("1. MIB TEST - Get IPX interface\n");
  535. printf("2. MIB TEST - Enumerate IPX Interfaces\n");
  536. printf("3. MIB TEST - Enumerate all best routes\n");
  537. printf("4. MIB TEST - Enumerate static routes\n");
  538. printf("5. MIB TEST - Enumerate all servers\n");
  539. printf("6. MIB TEST - Enumerate all servers of the specified type\n");
  540. printf("7. MIB TEST - Enumerate all static servers\n");
  541. printf("8. MIB TEST - Get RIP Interface\n");
  542. printf("9. MIB TEST - Get RIP Filters\n");
  543. printf("99. MIB TEST - return to main menu\n");
  544. printf("Enter your option:");
  545. scanf("%d", &i);
  546. switch(i)
  547. {
  548. case 1:
  549. GetIpxInterface(dimifp);
  550. break;
  551. case 2:
  552. EnumerateIpxInterfaces(dimifp);
  553. break;
  554. case 3:
  555. EnumerateAllBestRoutes(dimifp);
  556. break;
  557. case 4:
  558. EnumerateStaticRoutes(dimifp);
  559. break;
  560. case 5:
  561. EnumerateAllServers(dimifp);
  562. break;
  563. case 6:
  564. printf("Enter server type:");
  565. scanf("%d", &Type);
  566. EnumerateAllServersOfType(dimifp, (USHORT)Type);
  567. break;
  568. case 7:
  569. EnumerateStaticServers(dimifp);
  570. break;
  571. case 8:
  572. GetRipInterface(dimifp);
  573. break;
  574. case 9:
  575. GetRipFilters(dimifp);
  576. break;
  577. case 99:
  578. return;
  579. default:
  580. break;
  581. }
  582. }
  583. }