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.

1841 lines
44 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. routing\monitor2\ip\ipcfg.c
  5. Abstract:
  6. Fns to change configuration at the IP Rtr Mgr level
  7. Revision History:
  8. Anand Mahalingam 7/10/98 Created
  9. --*/
  10. #include "precomp.h"
  11. #pragma hdrstop
  12. DWORD
  13. AddDeleteRoutePrefLevel (
  14. IN PPROTOCOL_METRIC ppm,
  15. IN DWORD dwNumProto,
  16. IN BOOL bAdd
  17. )
  18. /*++
  19. Routine Description:
  20. Adds, deletes route preferences
  21. Arguments:
  22. ppm - array of protocols to be added/deleted
  23. dwNumProto - Number of protocols to be added/deleted
  24. bAdd - To add or not to add
  25. Return Value:
  26. NO_ERROR
  27. --*/
  28. {
  29. DWORD dwRes = (DWORD) -1, dwSize = 0;
  30. PPRIORITY_INFO ppi = NULL, ppiNew = NULL;
  31. DWORD dwBlkSize, dwNewBlkSize, dwCount;
  32. DEBUG("In AddDelRoutePrefLevel");
  33. if (dwNumProto is 0)
  34. {
  35. return NO_ERROR;
  36. }
  37. do
  38. {
  39. dwRes = IpmontrGetInfoBlockFromGlobalInfo(IP_PROT_PRIORITY_INFO,
  40. (PBYTE *) &ppi,
  41. &dwBlkSize,
  42. &dwCount);
  43. if(dwRes != NO_ERROR)
  44. {
  45. break;
  46. }
  47. if(bAdd)
  48. {
  49. dwRes = AddNewRoutePrefToBlock(ppi,
  50. dwBlkSize,
  51. ppm,
  52. dwNumProto,
  53. &ppiNew,
  54. &dwNewBlkSize);
  55. }
  56. else
  57. {
  58. dwRes = DeleteRoutePrefFromBlock(ppi,
  59. dwBlkSize,
  60. ppm,
  61. dwNumProto,
  62. &ppiNew,
  63. &dwNewBlkSize);
  64. }
  65. if(dwRes != NO_ERROR)
  66. {
  67. if(dwRes is ERROR_NO_CHANGE)
  68. {
  69. //
  70. // No Change in config, proceed to change in router
  71. //
  72. dwRes = NO_ERROR;
  73. ppiNew = NULL;
  74. break;
  75. }
  76. }
  77. else
  78. {
  79. if(ppiNew)
  80. {
  81. dwRes = IpmontrSetInfoBlockInGlobalInfo(IP_PROT_PRIORITY_INFO,
  82. (PBYTE) ppiNew,
  83. dwNewBlkSize,
  84. dwCount);
  85. }
  86. }
  87. }while(FALSE);
  88. //
  89. // free allocations
  90. //
  91. if(ppi)
  92. {
  93. FreeInfoBuffer(ppi);
  94. ppi = NULL;
  95. }
  96. if(ppiNew)
  97. {
  98. FREE(ppiNew);
  99. ppiNew = NULL;
  100. }
  101. switch(dwRes)
  102. {
  103. case NO_ERROR:
  104. break;
  105. case ERROR_NOT_FOUND:
  106. DisplayMessage(g_hModule, EMSG_IP_NO_PRIO_INFO, L"Router");
  107. break;
  108. case ERROR_NOT_ENOUGH_MEMORY:
  109. DisplayMessage(g_hModule, MSG_IP_NOT_ENOUGH_MEMORY);
  110. break;
  111. default:
  112. DisplayError(g_hModule, dwRes);
  113. break;
  114. }
  115. return dwRes;
  116. }
  117. DWORD
  118. AddNewRoutePrefToBlock (
  119. IN PPRIORITY_INFO ppi,
  120. IN DWORD dwBlkSize,
  121. IN PPROTOCOL_METRIC ppm,
  122. IN DWORD dwNumProto,
  123. OUT PPRIORITY_INFO *pppi,
  124. OUT PDWORD pdwSize
  125. )
  126. /*++
  127. Routine Description:
  128. creates route preference block
  129. Arguments:
  130. ppi - preference block
  131. dwNumBlkSize - size of block
  132. ppm - protocols to be added
  133. dwNumProto - number of protocols
  134. pppi - new preference block
  135. pdwSize - size of new block
  136. Return Value:
  137. NO_ERROR
  138. --*/
  139. {
  140. PPRIORITY_INFO pPriorInfoOld = NULL, pPriorInfoNew = NULL;
  141. DWORD i = 0, dwNewSize = 0, dwRes = NO_ERROR;
  142. BOOL bFound = FALSE;
  143. PDWORD pdwValid;
  144. DWORD j, dwProtoCount;
  145. //
  146. // Have an array to tell which ones are valid.
  147. //
  148. pdwValid = MALLOC( dwNumProto * sizeof(DWORD));
  149. if (pdwValid is NULL)
  150. {
  151. DisplayMessage(g_hModule, MSG_IP_NOT_ENOUGH_MEMORY);
  152. return ERROR_NOT_ENOUGH_MEMORY;
  153. }
  154. ZeroMemory(pdwValid, dwNumProto * sizeof(DWORD));
  155. //
  156. // find the PrefLevel block
  157. //
  158. pPriorInfoOld = ppi;
  159. if ( pPriorInfoOld == (PPRIORITY_INFO) NULL )
  160. {
  161. DisplayMessage(g_hModule, MSG_IP_CORRUPT_INFO );
  162. FREE(pdwValid);
  163. return ERROR_INVALID_PARAMETER;
  164. }
  165. for ( j = 0, dwNewSize = 0; j < dwNumProto; j++)
  166. {
  167. //
  168. // make sure preference level for the protocol does not already exist.
  169. //
  170. for ( i = 0; i < pPriorInfoOld-> dwNumProtocols; i++ )
  171. {
  172. if (pPriorInfoOld->ppmProtocolMetric[ i ].dwProtocolId
  173. == ppm[j].dwProtocolId)
  174. {
  175. bFound = TRUE;
  176. break;
  177. }
  178. }
  179. if (bFound)
  180. {
  181. pdwValid[j] = 0;
  182. DisplayMessage(g_hModule, MSG_IP_PROTO_PREF_LEVEL_EXISTS,
  183. pPriorInfoOld->ppmProtocolMetric[ i ].dwMetric);
  184. bFound = FALSE;
  185. }
  186. else
  187. {
  188. pdwValid[j] = 1;
  189. dwNewSize += sizeof(PROTOCOL_METRIC);
  190. }
  191. }
  192. //
  193. // allocate new info block
  194. //
  195. if (dwNewSize is 0)
  196. {
  197. //
  198. // All specified protocols already present
  199. //
  200. FREE(pdwValid);
  201. return ERROR_NO_CHANGE;
  202. }
  203. dwProtoCount = dwNewSize / sizeof(PROTOCOL_METRIC);
  204. dwNewSize += dwBlkSize;
  205. pPriorInfoNew = MALLOC(dwNewSize);
  206. if ( pPriorInfoNew == NULL )
  207. {
  208. DisplayMessage(g_hModule, MSG_IP_NOT_ENOUGH_MEMORY );
  209. dwRes = ERROR_NOT_ENOUGH_MEMORY;
  210. return dwRes;
  211. }
  212. do
  213. {
  214. //
  215. // copy the old PrefLevels and set the number of protocols
  216. //
  217. CopyMemory((PBYTE) &pPriorInfoNew-> ppmProtocolMetric,
  218. (PBYTE) &pPriorInfoOld-> ppmProtocolMetric,
  219. sizeof(PROTOCOL_METRIC)*pPriorInfoOld-> dwNumProtocols);
  220. pPriorInfoNew-> dwNumProtocols = pPriorInfoOld-> dwNumProtocols +
  221. dwProtoCount;
  222. //
  223. // add the new PrefLevel and increment count of protocols
  224. // with PrefLevels
  225. //
  226. i = pPriorInfoOld-> dwNumProtocols;
  227. for ( j = 0 ; j < dwNumProto ; j++)
  228. {
  229. if (pdwValid[j])
  230. {
  231. //
  232. // Add the protocol priority
  233. //
  234. pPriorInfoNew-> ppmProtocolMetric[i].dwProtocolId
  235. = ppm[j].dwProtocolId;
  236. pPriorInfoNew-> ppmProtocolMetric[i++].dwMetric
  237. = ppm[j].dwMetric;
  238. }
  239. }
  240. } while (FALSE);
  241. FREE(pdwValid);
  242. if ( dwRes == NO_ERROR )
  243. {
  244. *pppi = pPriorInfoNew;
  245. *pdwSize = dwNewSize;
  246. }
  247. return dwRes;
  248. }
  249. DWORD
  250. DeleteRoutePrefFromBlock (
  251. IN PPRIORITY_INFO ppi,
  252. IN DWORD dwBlkSize,
  253. IN PPROTOCOL_METRIC ppm,
  254. IN DWORD dwNumProto,
  255. OUT PPRIORITY_INFO *pppi,
  256. OUT PDWORD pdwSize
  257. )
  258. /*++
  259. Routine Description:
  260. creates route preference block
  261. Arguments:
  262. ppi - preference block
  263. dwNumBlkSize - size of block
  264. ppm - protocols to be added
  265. dwNumProto - number of protocols
  266. pppi - new preference block
  267. pdwSize - size of new block
  268. Return Value:
  269. NO_ERROR
  270. --*/
  271. {
  272. PPRIORITY_INFO pPriorInfoOld = NULL, pPriorInfoNew = NULL;
  273. DWORD dwInd = 0, dwNewSize = 0, dwRes = NO_ERROR, i, j;
  274. BOOL bFound = FALSE;
  275. PDWORD pdwToDelete;
  276. // find the PrefLevel block
  277. pPriorInfoOld = ppi;
  278. if ( pPriorInfoOld == (PPRIORITY_INFO) NULL )
  279. {
  280. DisplayMessage(g_hModule, MSG_IP_CORRUPT_INFO );
  281. return ERROR_INVALID_PARAMETER;
  282. }
  283. pdwToDelete = MALLOC( pPriorInfoOld-> dwNumProtocols * sizeof(DWORD));
  284. if (pdwToDelete is NULL)
  285. {
  286. return ERROR_NOT_ENOUGH_MEMORY;
  287. }
  288. ZeroMemory(pdwToDelete, pPriorInfoOld-> dwNumProtocols * sizeof(DWORD));
  289. for ( i = 0, dwNewSize = 0; i < dwNumProto; i++)
  290. {
  291. //
  292. // make sure preference level for the protocol already exists.
  293. //
  294. for ( dwInd = 0; dwInd < pPriorInfoOld-> dwNumProtocols; dwInd++ )
  295. {
  296. if (pPriorInfoOld-> ppmProtocolMetric[ dwInd ].dwProtocolId
  297. == ppm[i].dwProtocolId)
  298. {
  299. bFound = TRUE;
  300. break;
  301. }
  302. }
  303. if (!bFound)
  304. {
  305. DisplayMessage(g_hModule, MSG_IP_PROTO_PREF_LEVEL_NOT_FOUND,
  306. ppm[i].dwProtocolId);
  307. }
  308. else
  309. {
  310. bFound = FALSE;
  311. pdwToDelete[dwInd] = 1;
  312. dwNewSize += sizeof(PROTOCOL_METRIC);
  313. }
  314. }
  315. if (dwNewSize is 0)
  316. {
  317. //
  318. // None of the protocols specified were found.
  319. //
  320. FREE(pdwToDelete);
  321. return ERROR_NO_CHANGE;
  322. }
  323. //
  324. // allocate new info block
  325. //
  326. dwNewSize = dwBlkSize - dwNewSize;
  327. pPriorInfoNew = MALLOC(dwNewSize);
  328. if ( pPriorInfoNew == NULL )
  329. {
  330. FREE(pdwToDelete);
  331. dwRes = ERROR_NOT_ENOUGH_MEMORY;
  332. return dwRes;
  333. }
  334. do
  335. {
  336. for ( i = 0, j = 0; i < pPriorInfoOld-> dwNumProtocols; i++)
  337. {
  338. if (pdwToDelete[i])
  339. {
  340. //
  341. // Do not copy this protocol
  342. //
  343. }
  344. else
  345. {
  346. pPriorInfoNew->ppmProtocolMetric[j].dwProtocolId =
  347. pPriorInfoOld->ppmProtocolMetric[i].dwProtocolId;
  348. pPriorInfoNew->ppmProtocolMetric[j++].dwMetric =
  349. pPriorInfoOld->ppmProtocolMetric[i].dwMetric;
  350. }
  351. }
  352. pPriorInfoNew-> dwNumProtocols = j;
  353. } while (FALSE);
  354. FREE(pdwToDelete);
  355. if ( dwRes == NO_ERROR )
  356. {
  357. *pppi = pPriorInfoNew;
  358. *pdwSize = dwNewSize;
  359. }
  360. return dwRes;
  361. }
  362. DWORD
  363. SetRoutePrefLevel (
  364. IN PROTOCOL_METRIC pm
  365. )
  366. /*++
  367. Routine Description:
  368. sets route preference
  369. Arguments:
  370. ppm - preference to set
  371. Return Value:
  372. NO_ERROR
  373. --*/
  374. {
  375. DWORD dwRes = (DWORD) -1, dwSize = 0;
  376. PPRIORITY_INFO ppi = NULL;
  377. DWORD dwBlkSize, dwCount;
  378. DEBUG("In SetRoutePrefLevel");
  379. do
  380. {
  381. //
  382. // get router config, add new router preference level,
  383. // and set the config
  384. //
  385. dwRes = IpmontrGetInfoBlockFromGlobalInfo(IP_PROT_PRIORITY_INFO,
  386. (PBYTE *) &ppi,
  387. &dwBlkSize,
  388. &dwCount);
  389. if (dwRes != NO_ERROR)
  390. {
  391. break;
  392. }
  393. dwRes = UpdateRtrPriority(ppi, pm);
  394. if ( dwRes != NO_ERROR )
  395. {
  396. break;
  397. }
  398. dwRes = IpmontrSetInfoBlockInGlobalInfo(IP_PROT_PRIORITY_INFO,
  399. (PBYTE) ppi,
  400. dwBlkSize,
  401. dwCount);
  402. if ( dwRes != NO_ERROR )
  403. {
  404. break;
  405. }
  406. PRINT(L"Made Changes to Router Config");
  407. if (!IsRouterRunning())
  408. {
  409. break;
  410. }
  411. } while (FALSE);
  412. //
  413. // Free all allocations
  414. //
  415. if ( ppi )
  416. {
  417. FREE(ppi);
  418. }
  419. switch(dwRes)
  420. {
  421. case NO_ERROR:
  422. break;
  423. case ERROR_NOT_FOUND:
  424. DisplayMessage(g_hModule, EMSG_IP_NO_PRIO_INFO, L"Router");
  425. break;
  426. case ERROR_NOT_ENOUGH_MEMORY:
  427. DisplayMessage(g_hModule, MSG_IP_NOT_ENOUGH_MEMORY);
  428. break;
  429. case ERROR_INVALID_PARAMETER:
  430. break;
  431. default:
  432. DisplayError(g_hModule, dwRes);
  433. break;
  434. }
  435. return dwRes;
  436. }
  437. DWORD
  438. UpdateRtrPriority(
  439. IN PPRIORITY_INFO ppi,
  440. IN PROTOCOL_METRIC pm
  441. )
  442. /*++
  443. Routine Description:
  444. sets route preference
  445. Arguments:
  446. ppi - route preference block
  447. ppm - preference to set
  448. Return Value:
  449. NO_ERROR
  450. --*/
  451. {
  452. BOOL bFound = FALSE;
  453. DWORD i = 0;
  454. if ( ppi == (PPRIORITY_INFO) NULL )
  455. {
  456. DisplayMessage(g_hModule, MSG_IP_CORRUPT_INFO );
  457. return ERROR_INVALID_PARAMETER;
  458. }
  459. // search for the protocol
  460. for ( i = 0; i < ppi-> dwNumProtocols; i++ )
  461. {
  462. if (ppi-> ppmProtocolMetric[ i ].dwProtocolId
  463. == pm.dwProtocolId )
  464. {
  465. ppi-> ppmProtocolMetric[ i ].dwMetric = pm.dwMetric;
  466. bFound = TRUE;
  467. break;
  468. }
  469. }
  470. if (!bFound)
  471. {
  472. // preference level for that protocolId does not exist
  473. DisplayMessage(g_hModule, MSG_IP_NO_PREF_FOR_PROTOCOL_ID,
  474. pm.dwProtocolId );
  475. return ERROR_INVALID_PARAMETER;
  476. }
  477. return NO_ERROR;
  478. }
  479. DWORD
  480. SetGlobalConfigInfo(
  481. IN DWORD dwLoggingLevel
  482. )
  483. /*++
  484. Routine Description:
  485. sets global logging level
  486. Arguments:
  487. dwLoggingLevel - Loggging level
  488. Return Value:
  489. NO_ERROR
  490. --*/
  491. {
  492. PGLOBAL_INFO pgi = NULL;
  493. DWORD dwBlkSize, dwCount, dwErr = NO_ERROR;
  494. do
  495. {
  496. //
  497. // Get the IP_GLOBAL_INFO block from router config
  498. //
  499. dwErr = IpmontrGetInfoBlockFromGlobalInfo(IP_GLOBAL_INFO,
  500. (PBYTE *) &pgi,
  501. &dwBlkSize,
  502. &dwCount);
  503. if (dwErr isnot NO_ERROR)
  504. {
  505. break;
  506. }
  507. pgi->dwLoggingLevel = dwLoggingLevel;
  508. //
  509. // Set the IP_GLOBAL_INFO block in router config
  510. //
  511. dwErr = IpmontrSetInfoBlockInGlobalInfo(IP_GLOBAL_INFO,
  512. (PBYTE) pgi,
  513. dwBlkSize,
  514. dwCount);
  515. if (dwErr isnot NO_ERROR)
  516. {
  517. break;
  518. }
  519. FREE(pgi);
  520. pgi = NULL;
  521. DEBUG("Set logging level in router config\n");
  522. }while (FALSE);
  523. if (pgi)
  524. {
  525. FREE(pgi);
  526. }
  527. switch(dwErr)
  528. {
  529. case NO_ERROR:
  530. break;
  531. case ERROR_NOT_FOUND:
  532. DisplayMessage(g_hModule, EMSG_IP_NO_PRIO_INFO, L"Router");
  533. break;
  534. case ERROR_NOT_ENOUGH_MEMORY:
  535. DisplayMessage(g_hModule, MSG_IP_NOT_ENOUGH_MEMORY);
  536. break;
  537. default:
  538. DisplayError(g_hModule, dwErr);
  539. break;
  540. }
  541. return dwErr;
  542. }
  543. DWORD
  544. UpdateInterfaceStatusInfo(
  545. IN DWORD dwAction,
  546. IN LPCWSTR pwszIfName,
  547. IN DWORD dwStatus
  548. )
  549. /*++
  550. Routine Description:
  551. Sets interface discovery information
  552. Arguments:
  553. pwszIfName - interface name
  554. dwStatus - enabled or disabled
  555. Return Value:
  556. NO_ERROR
  557. --*/
  558. {
  559. PINTERFACE_STATUS_INFO pifStat = (PINTERFACE_STATUS_INFO) NULL;
  560. DWORD dwRes = NO_ERROR, dwBlkSize;
  561. DWORD dwCount, dwIfType;
  562. do
  563. {
  564. dwRes = IpmontrGetInfoBlockFromInterfaceInfo(pwszIfName,
  565. IP_INTERFACE_STATUS_INFO,
  566. (PBYTE *) &pifStat,
  567. &dwBlkSize,
  568. &dwCount,
  569. &dwIfType);
  570. if (dwRes is ERROR_NOT_FOUND)
  571. {
  572. //
  573. // No info of this type is currently present
  574. //
  575. dwRes = NO_ERROR;
  576. dwCount = 0;
  577. // Add interface
  578. if (dwAction is ADD_COMMAND) {
  579. pifStat = (PINTERFACE_STATUS_INFO)MALLOC(
  580. sizeof(INTERFACE_STATUS_INFO));
  581. if (pifStat is NULL) {
  582. dwRes = ERROR_NOT_ENOUGH_MEMORY;
  583. break;
  584. }
  585. dwCount++;
  586. }
  587. }
  588. if (dwRes != NO_ERROR)
  589. {
  590. break;
  591. }
  592. if (dwCount is 0)
  593. return ERROR_NOT_FOUND;
  594. if (dwAction is DELETE_COMMAND)
  595. {
  596. dwCount = 0;
  597. }
  598. else
  599. {
  600. pifStat->dwAdminStatus = dwStatus;
  601. }
  602. dwRes = IpmontrSetInfoBlockInInterfaceInfo( pwszIfName,
  603. IP_INTERFACE_STATUS_INFO,
  604. (PBYTE) pifStat,
  605. dwBlkSize,
  606. dwCount);
  607. } while (FALSE);
  608. //
  609. // Free all allocations
  610. //
  611. if ( pifStat )
  612. {
  613. FREE(pifStat);
  614. }
  615. switch(dwRes)
  616. {
  617. case NO_ERROR:
  618. break;
  619. case ERROR_NOT_FOUND:
  620. DisplayMessage(g_hModule, EMSG_IP_NO_IF_STATUS_INFO, L"Router");
  621. break;
  622. case ERROR_NOT_ENOUGH_MEMORY:
  623. DisplayMessage(g_hModule, MSG_IP_NOT_ENOUGH_MEMORY);
  624. break;
  625. default:
  626. DisplayError(g_hModule, dwRes);
  627. break;
  628. }
  629. return dwRes;
  630. }
  631. DWORD
  632. ShowRoutePref(
  633. HANDLE hFile
  634. )
  635. /*++
  636. Routine Description:
  637. Displays the protocol route preferences.
  638. Arguments:
  639. Return Value:
  640. NO_ERROR
  641. --*/
  642. {
  643. PPRIORITY_INFO ppi;
  644. DWORD dwBlkSize, dwCount, dwNumProto, i;
  645. DWORD dwErr;
  646. WCHAR wszBuff[80];
  647. dwErr = IpmontrGetInfoBlockFromGlobalInfo(IP_PROT_PRIORITY_INFO,
  648. (PBYTE *)&ppi,
  649. &dwBlkSize,
  650. &dwCount);
  651. if (dwErr isnot NO_ERROR)
  652. {
  653. DisplayError(g_hModule, dwErr);
  654. return ERROR_SUPPRESS_OUTPUT;
  655. }
  656. dwNumProto = ppi-> dwNumProtocols;
  657. if (dwNumProto &&
  658. (hFile == NULL))
  659. {
  660. DisplayMessage(g_hModule, MSG_RTR_PRIO_INFO_HDR);
  661. }
  662. for (i=0; i < dwNumProto; i++)
  663. {
  664. PTCHAR ptszProto, ptszToken;
  665. switch (ppi-> ppmProtocolMetric[ i ].dwProtocolId)
  666. {
  667. case PROTO_IP_LOCAL:
  668. {
  669. ptszProto = MakeString(g_hModule, STRING_LOCAL );
  670. ptszToken = TOKEN_VALUE_LOCAL;
  671. break;
  672. }
  673. case PROTO_IP_NETMGMT:
  674. {
  675. ptszProto = MakeString(g_hModule, STRING_NETMGMT );
  676. ptszToken = TOKEN_VALUE_NETMGMT;
  677. break;
  678. }
  679. case PROTO_IP_OSPF :
  680. {
  681. ptszProto = MakeString(g_hModule, STRING_OSPF );
  682. ptszToken = TOKEN_VALUE_OSPF;
  683. break;
  684. }
  685. case PROTO_IP_RIP :
  686. {
  687. ptszProto = MakeString(g_hModule, STRING_RIP );
  688. ptszToken = TOKEN_VALUE_RIP;
  689. break;
  690. }
  691. case PROTO_IP_NT_AUTOSTATIC :
  692. {
  693. ptszProto = MakeString(g_hModule, STRING_NT_AUTOSTATIC );
  694. ptszToken = TOKEN_VALUE_AUTOSTATIC;
  695. break;
  696. }
  697. case PROTO_IP_NT_STATIC :
  698. {
  699. ptszProto = MakeString(g_hModule, STRING_STATIC );
  700. ptszToken = TOKEN_VALUE_STATIC;
  701. break;
  702. }
  703. case PROTO_IP_NT_STATIC_NON_DOD :
  704. {
  705. ptszProto = MakeString(g_hModule, STRING_NONDOD );
  706. ptszToken = TOKEN_VALUE_NONDOD;
  707. break;
  708. }
  709. default:
  710. {
  711. ptszProto = NULL;
  712. ptszToken = NULL;
  713. break;
  714. }
  715. }
  716. if ( ptszProto == NULL || ptszToken == NULL )
  717. {
  718. swprintf( wszBuff,
  719. L"%d",
  720. ppi-> ppmProtocolMetric[ i ].dwProtocolId );
  721. }
  722. if(hFile != NULL)
  723. {
  724. DisplayMessageT( DMP_IP_SET_PROTOPREF,
  725. (ptszToken)? ptszToken : wszBuff,
  726. ppi->ppmProtocolMetric[i].dwMetric);
  727. }
  728. else
  729. {
  730. DisplayMessage(g_hModule,
  731. MSG_RTR_PRIO_INFO,
  732. (ptszProto)? ptszProto : wszBuff,
  733. ppi->ppmProtocolMetric[i].dwMetric);
  734. }
  735. if(ptszProto)
  736. {
  737. FreeString(ptszProto);
  738. }
  739. }
  740. FREE(ppi);
  741. return NO_ERROR;
  742. }
  743. DWORD
  744. ShowIpGlobal(
  745. HANDLE hFile
  746. )
  747. /*++
  748. Routine Description:
  749. Displays the logging level for IP
  750. Arguments:
  751. Return Value:
  752. NO_ERROR
  753. --*/
  754. {
  755. PGLOBAL_INFO pgi = NULL;
  756. DWORD dwBlkSize, dwCount;
  757. DWORD dwErr;
  758. PWCHAR ptszLoglevel, ptszLog;
  759. WCHAR wszBuff[80];
  760. dwErr = IpmontrGetInfoBlockFromGlobalInfo(IP_GLOBAL_INFO,
  761. (PBYTE *)&pgi,
  762. &dwBlkSize,
  763. &dwCount);
  764. if (dwErr isnot NO_ERROR)
  765. {
  766. DisplayError(g_hModule, dwErr);
  767. return dwErr;
  768. }
  769. switch (pgi->dwLoggingLevel)
  770. {
  771. case IPRTR_LOGGING_NONE:
  772. {
  773. ptszLoglevel = MakeString(g_hModule, STRING_LOGGING_NONE);
  774. ptszLog = TOKEN_VALUE_NONE;
  775. break;
  776. }
  777. case IPRTR_LOGGING_ERROR:
  778. {
  779. ptszLoglevel = MakeString(g_hModule, STRING_LOGGING_ERROR);
  780. ptszLog = TOKEN_VALUE_ERROR;
  781. break;
  782. }
  783. case IPRTR_LOGGING_WARN:
  784. {
  785. ptszLoglevel = MakeString(g_hModule, STRING_LOGGING_WARN);
  786. ptszLog = TOKEN_VALUE_WARN;
  787. break;
  788. }
  789. case IPRTR_LOGGING_INFO:
  790. {
  791. ptszLoglevel = MakeString(g_hModule, STRING_LOGGING_INFO);
  792. ptszLog = TOKEN_VALUE_INFO;
  793. break;
  794. }
  795. }
  796. if ( ptszLoglevel == NULL || ptszLog == NULL )
  797. {
  798. swprintf( wszBuff,
  799. L"%d",
  800. pgi->dwLoggingLevel);
  801. }
  802. if(hFile)
  803. {
  804. DisplayMessageT( DMP_IP_SET_LOGLEVEL,
  805. (ptszLog) ? ptszLog : wszBuff);
  806. }
  807. else
  808. {
  809. DisplayMessage(g_hModule, MSG_IP_GLOBAL_HDR);
  810. DisplayMessage(g_hModule, MSG_IP_LOG_LEVEL,
  811. (ptszLoglevel) ? ptszLoglevel : wszBuff);
  812. }
  813. if ( ptszLoglevel )
  814. {
  815. FreeString(ptszLoglevel);
  816. }
  817. FREE(pgi);
  818. return NO_ERROR;
  819. }
  820. PWCHAR
  821. GetIfTypeString(
  822. DWORD dwIfType
  823. )
  824. {
  825. PWCHAR pwszStr;
  826. static WCHAR buff[80];
  827. VALUE_STRING ppsList[] = {{ROUTER_IF_TYPE_CLIENT, STRING_CLIENT},
  828. {ROUTER_IF_TYPE_HOME_ROUTER, STRING_HOME_ROUTER},
  829. {ROUTER_IF_TYPE_FULL_ROUTER, STRING_FULL_ROUTER},
  830. {ROUTER_IF_TYPE_DEDICATED, STRING_DEDICATED},
  831. {ROUTER_IF_TYPE_INTERNAL, STRING_INTERNAL},
  832. {ROUTER_IF_TYPE_LOOPBACK, STRING_LOOPBACK},
  833. #ifdef KSL_IPINIP
  834. {ROUTER_IF_TYPE_TUNNEL1, STRING_TUNNEL},
  835. #endif //KSL_IPINIP
  836. };
  837. DWORD dwNum = sizeof(ppsList)/sizeof(VALUE_STRING), i;
  838. DWORD dwMsgId = 0;
  839. for (i=0; i<dwNum; i++)
  840. {
  841. if (dwIfType == ppsList[i].dwValue)
  842. {
  843. dwMsgId = ppsList[i].dwStringId;
  844. break;
  845. }
  846. }
  847. if (dwMsgId)
  848. {
  849. pwszStr = MakeString( g_hModule, dwMsgId);
  850. if ( pwszStr )
  851. {
  852. wcscpy(buff, pwszStr);
  853. FreeString(pwszStr);
  854. }
  855. else
  856. {
  857. wsprintf(buff, L"%d", dwIfType);
  858. }
  859. }
  860. else
  861. {
  862. wsprintf(buff, L"%d", dwIfType);
  863. }
  864. return buff;
  865. }
  866. PWCHAR
  867. GetProtoTypeString(
  868. DWORD dwProtoType
  869. )
  870. {
  871. PWCHAR pwszStr;
  872. static WCHAR buff[80];
  873. VALUE_STRING ppsList[] = {{PROTO_TYPE_UCAST, STRING_UNICAST},
  874. {PROTO_TYPE_MCAST, STRING_MULTICAST},
  875. {PROTO_TYPE_MS1, STRING_GENERAL},
  876. {PROTO_TYPE_MS0, STRING_GENERAL},
  877. };
  878. DWORD dwNum = sizeof(ppsList)/sizeof(VALUE_STRING), i;
  879. DWORD dwMsgId = 0;
  880. for (i=0; i<dwNum; i++)
  881. {
  882. if (dwProtoType == ppsList[i].dwValue)
  883. {
  884. dwMsgId = ppsList[i].dwStringId;
  885. break;
  886. }
  887. }
  888. if (dwMsgId)
  889. {
  890. pwszStr = MakeString( g_hModule, dwMsgId);
  891. if ( pwszStr )
  892. {
  893. wcscpy(buff, pwszStr);
  894. FreeString(pwszStr);
  895. }
  896. else
  897. {
  898. wsprintf(buff, L"%d", dwProtoType);
  899. }
  900. }
  901. else
  902. {
  903. wsprintf(buff, L"%d", dwProtoType);
  904. }
  905. return buff;
  906. }
  907. PWCHAR
  908. GetProtoVendorString(
  909. DWORD dwProtoVendor
  910. )
  911. {
  912. PWCHAR pwszStr;
  913. static WCHAR buff[80];
  914. VALUE_TOKEN ppsList[] = {{PROTO_VENDOR_MS0, TOKEN_MICROSOFT0},
  915. {PROTO_VENDOR_MS1, TOKEN_MICROSOFT1},
  916. {PROTO_VENDOR_MS2, TOKEN_MICROSOFT2},
  917. };
  918. DWORD dwNum = sizeof(ppsList)/sizeof(VALUE_STRING), i;
  919. DWORD dwMsgId = 0;
  920. for (i=0; i<dwNum; i++)
  921. {
  922. if (dwProtoVendor == ppsList[i].dwValue)
  923. {
  924. return (PWCHAR)ppsList[i].pwszToken;
  925. break;
  926. }
  927. }
  928. wsprintf(buff, L"%d", dwProtoVendor);
  929. return buff;
  930. }
  931. PWCHAR
  932. GetProtoProtoString(
  933. DWORD dwProtoType,
  934. DWORD dwProtoVendor,
  935. DWORD dwProtoProto
  936. )
  937. {
  938. PWCHAR pwszStr;
  939. static WCHAR buff[80];
  940. VALUE_STRING ppsUList[] = {{PROTO_IP_RIP, STRING_RIP},
  941. {PROTO_IP_OSPF, STRING_OSPF},
  942. {PROTO_IP_BOOTP, STRING_BOOTP},
  943. {PROTO_IP_NAT, STRING_NAT},
  944. {PROTO_IP_LOCAL, STRING_LOCAL},
  945. {PROTO_IP_OTHER, STRING_OTHER},
  946. {PROTO_IP_NETMGMT,STRING_NETMGMT},
  947. {PROTO_IP_NT_AUTOSTATIC,STRING_NT_AUTOSTATIC},
  948. {PROTO_IP_NT_STATIC, STRING_STATIC},
  949. {PROTO_IP_NT_STATIC_NON_DOD,STRING_NONDOD},
  950. #ifdef MS_IP_BGP
  951. {PROTO_IP_BGP, STRING_BGP},
  952. #endif
  953. };
  954. VALUE_STRING ppsMList[] = {{PROTO_IP_IGMP, STRING_IGMP},
  955. };
  956. VALUE_STRING ppsGList[] = {{IP_IN_FILTER_INFO, STRING_IN_FILTER},
  957. {IP_OUT_FILTER_INFO, STRING_OUT_FILTER},
  958. {IP_GLOBAL_INFO, STRING_GLOBAL_INFO},
  959. {IP_INTERFACE_STATUS_INFO, STRING_IF_STATUS},
  960. {IP_ROUTE_INFO, STRING_ROUTE_INFO},
  961. {IP_PROT_PRIORITY_INFO, STRING_PROT_PRIORITY},
  962. {IP_ROUTER_DISC_INFO, STRING_RTRDISC},
  963. {IP_DEMAND_DIAL_FILTER_INFO, STRING_DD_FILTER},
  964. {IP_MCAST_HEARBEAT_INFO, STRING_MC_HEARTBEAT},
  965. {IP_MCAST_BOUNDARY_INFO, STRING_MC_BOUNDARY},
  966. #ifdef KSL_IPINIP
  967. {IP_IPINIP_CFG_INFO, STRING_IPIP},
  968. #endif //KSL_IPINIP
  969. {IP_IFFILTER_INFO, STRING_IF_FILTER},
  970. {IP_MCAST_LIMIT_INFO, STRING_MC_LIMIT},
  971. };
  972. VALUE_STRING pps2List[] = {{PROTO_IP_DNS_PROXY, STRING_DNS_PROXY},
  973. {PROTO_IP_DHCP_ALLOCATOR,STRING_DHCP_ALLOCATOR},
  974. {PROTO_IP_NAT, STRING_NAT},
  975. {PROTO_IP_DIFFSERV, STRING_DIFFSERV},
  976. {PROTO_IP_VRRP, STRING_VRRP},
  977. };
  978. VALUE_STRING *pVS;
  979. DWORD dwNum, i;
  980. DWORD dwMsgId = 0;
  981. switch (dwProtoType) {
  982. case PROTO_TYPE_UCAST:
  983. pVS = ppsUList;
  984. dwNum = sizeof(ppsUList)/sizeof(VALUE_STRING);
  985. break;
  986. case PROTO_TYPE_MCAST:
  987. pVS = ppsMList;
  988. dwNum = sizeof(ppsMList)/sizeof(VALUE_STRING);
  989. break;
  990. case PROTO_TYPE_MS1:
  991. pVS = ppsGList;
  992. dwNum = sizeof(ppsGList)/sizeof(VALUE_STRING);
  993. break;
  994. case PROTO_TYPE_MS0:
  995. pVS = pps2List;
  996. dwNum = sizeof(pps2List)/sizeof(VALUE_STRING);
  997. break;
  998. default:
  999. dwNum = 0;
  1000. }
  1001. for (i=0; i<dwNum; i++)
  1002. {
  1003. if (dwProtoProto == PROTO_FROM_PROTO_ID(pVS[i].dwValue))
  1004. {
  1005. dwMsgId = pVS[i].dwStringId;
  1006. break;
  1007. }
  1008. }
  1009. if (dwMsgId)
  1010. {
  1011. pwszStr = MakeString( g_hModule, dwMsgId);
  1012. if ( pwszStr )
  1013. {
  1014. wcscpy(buff, pwszStr);
  1015. FreeString(pwszStr);
  1016. }
  1017. else
  1018. {
  1019. wsprintf(buff, L"%d", dwProtoProto);
  1020. }
  1021. }
  1022. else
  1023. {
  1024. wsprintf(buff, L"%d", dwProtoProto);
  1025. }
  1026. return buff;
  1027. }
  1028. DWORD
  1029. ShowIpIfProtocols(
  1030. IN LPCWSTR pwszIfName
  1031. )
  1032. {
  1033. DWORD dwNumProto, dwErr, i;
  1034. PBYTE pby;
  1035. DWORD dwBlkSize, dwCount;
  1036. RTR_INFO_BLOCK_HEADER *pInfoHdr;
  1037. DWORD dwProtoType, dwProtoVendor, dwProtoProto;
  1038. dwErr = ValidateInterfaceInfo(pwszIfName, &pInfoHdr, NULL, NULL);
  1039. if (dwErr isnot NO_ERROR)
  1040. {
  1041. return dwErr;
  1042. }
  1043. // Do this check just to keep the prefix checker happy
  1044. if (!pInfoHdr)
  1045. {
  1046. return ERROR_NOT_ENOUGH_MEMORY;
  1047. }
  1048. DisplayMessage(g_hModule, MSG_RTR_INTERFACE_PROTOCOL_HDR);
  1049. DisplayMessage(g_hModule, MSG_IP_PROTOCOL_HDR);
  1050. // Walk pInfo and output a line for each protocol found
  1051. for (i=0; i<pInfoHdr->TocEntriesCount; i++)
  1052. {
  1053. // Extract type, vendorid, and protocolid
  1054. dwProtoType = TYPE_FROM_PROTO_ID( pInfoHdr->TocEntry[i].InfoType);
  1055. dwProtoVendor = VENDOR_FROM_PROTO_ID(pInfoHdr->TocEntry[i].InfoType);
  1056. dwProtoProto = PROTO_FROM_PROTO_ID( pInfoHdr->TocEntry[i].InfoType);
  1057. DisplayMessageT(L"%1!-11s! %2!-13s! %3!s!\n",
  1058. GetProtoTypeString( dwProtoType),
  1059. GetProtoVendorString(dwProtoVendor),
  1060. GetProtoProtoString( dwProtoType, dwProtoVendor, dwProtoProto));
  1061. }
  1062. if (i is 0)
  1063. {
  1064. DisplayMessage(g_hModule, MSG_IP_NO_PROTOCOL);
  1065. }
  1066. return NO_ERROR;
  1067. }
  1068. DWORD
  1069. ShowIpProtocol(
  1070. VOID
  1071. )
  1072. /*++
  1073. Routine Description:
  1074. Displays all the protocols under IP RTR MGR.
  1075. Arguments:
  1076. Return Value:
  1077. NO_ERROR
  1078. --*/
  1079. {
  1080. DWORD dwNumProto, dwErr, i;
  1081. PBYTE pby;
  1082. DWORD dwBlkSize, dwCount;
  1083. RTR_INFO_BLOCK_HEADER *pInfoHdr;
  1084. DWORD dwProtoType, dwProtoVendor, dwProtoProto;
  1085. dwErr = ValidateGlobalInfo(&pInfoHdr);
  1086. if (dwErr isnot NO_ERROR)
  1087. {
  1088. return dwErr;
  1089. }
  1090. DisplayMessage(g_hModule, MSG_IP_PROTOCOL_HDR);
  1091. // Walk pInfo and output a line for each protocol found
  1092. for (i=0; i<pInfoHdr->TocEntriesCount; i++)
  1093. {
  1094. // Extract type, vendorid, and protocolid
  1095. dwProtoType = TYPE_FROM_PROTO_ID( pInfoHdr->TocEntry[i].InfoType);
  1096. dwProtoVendor = VENDOR_FROM_PROTO_ID(pInfoHdr->TocEntry[i].InfoType);
  1097. dwProtoProto = PROTO_FROM_PROTO_ID( pInfoHdr->TocEntry[i].InfoType);
  1098. DisplayMessageT(L"%1!-11s! %2!-13s! %3!s!\n",
  1099. GetProtoTypeString( dwProtoType),
  1100. GetProtoVendorString(dwProtoVendor),
  1101. GetProtoProtoString( dwProtoType, dwProtoVendor, dwProtoProto));
  1102. }
  1103. if (i is 0)
  1104. {
  1105. DisplayMessage(g_hModule, MSG_IP_NO_PROTOCOL);
  1106. }
  1107. return NO_ERROR;
  1108. }
  1109. DWORD
  1110. ListIpInterface(
  1111. VOID
  1112. )
  1113. /*++
  1114. Routine Description:
  1115. Lists all interfaces under ip
  1116. Arguments:
  1117. Return Value:
  1118. NO_ERROR
  1119. --*/
  1120. {
  1121. DWORD dwErr;
  1122. DWORD dwCount, dwTotal, i, dwNumParsed = 0;
  1123. PMPR_INTERFACE_0 pmi0;
  1124. WCHAR wszIfDesc[MAX_INTERFACE_NAME_LEN + 1];
  1125. HANDLE hIfTransport = (HANDLE) NULL,
  1126. hInterface;
  1127. DisplayMessage(g_hModule, MSG_IP_INTERFACE_HDR);
  1128. //
  1129. // No interface name specified. List all interfaces under IP
  1130. //
  1131. dwErr = IpmontrInterfaceEnum((PBYTE *) &pmi0, &dwCount, &dwTotal);
  1132. if (dwErr isnot NO_ERROR)
  1133. {
  1134. DisplayError(g_hModule, dwErr);
  1135. return dwErr;
  1136. }
  1137. for ( i = 0; i < dwCount; i++)
  1138. {
  1139. // Make sure IP is enabled on this interface
  1140. dwErr = MprConfigInterfaceGetHandle(g_hMprConfig,
  1141. pmi0[i].wszInterfaceName,
  1142. &hInterface);
  1143. dwErr = MprConfigInterfaceTransportGetHandle(g_hMprConfig,
  1144. hInterface,
  1145. PID_IP,
  1146. &hIfTransport);
  1147. if (dwErr isnot NO_ERROR)
  1148. continue;
  1149. dwErr = GetInterfaceDescription(pmi0[i].wszInterfaceName,
  1150. wszIfDesc,
  1151. &dwNumParsed);
  1152. if (!dwNumParsed)
  1153. {
  1154. wcscpy(wszIfDesc, pmi0[i].wszInterfaceName);
  1155. }
  1156. DisplayMessage(g_hModule, MSG_IP_INTERFACE_INFO, wszIfDesc);
  1157. }
  1158. if (dwCount is 0)
  1159. {
  1160. DisplayMessage(g_hModule, MSG_IP_NO_INTERFACE);
  1161. }
  1162. return NO_ERROR;
  1163. }
  1164. #ifdef KSL_IPINIP
  1165. DWORD
  1166. ShowIpInIpInfo(
  1167. IN DWORD dwFormat,
  1168. IN LPCWSTR pwszIfName,
  1169. IN LPCWSTR pwszQuoted
  1170. )
  1171. {
  1172. PIPINIP_CONFIG_INFO pIpIpInfo;
  1173. WCHAR rgwcLocalAddr[ADDR_LENGTH + 1];
  1174. WCHAR rgwcRemAddr[ADDR_LENGTH + 1];
  1175. DWORD dwBlkSize, dwCount, dwIfType, dwErr;
  1176. // IP-in-IP info
  1177. dwErr = IpmontrGetInfoBlockFromInterfaceInfo(pwszIfName,
  1178. IP_IPINIP_CFG_INFO,
  1179. (PBYTE *) &pIpIpInfo,
  1180. &dwBlkSize,
  1181. &dwCount,
  1182. &dwIfType);
  1183. if(dwErr is NO_ERROR)
  1184. {
  1185. ASSERT(dwIfType is ROUTER_IF_TYPE_TUNNEL1);
  1186. IP_TO_WSTR(rgwcLocalAddr, ((PBYTE)&(pIpIpInfo->dwLocalAddress)));
  1187. IP_TO_WSTR(rgwcRemAddr, ((PBYTE)&(pIpIpInfo->dwRemoteAddress)));
  1188. switch (dwFormat)
  1189. {
  1190. case FORMAT_VERBOSE:
  1191. DisplayMessage(g_hModule,
  1192. MSG_RTR_INTERFACE_IPIP_INFO,
  1193. rgwcLocalAddr,
  1194. rgwcRemAddr,
  1195. MAKELONG(MAKEWORD(pIpIpInfo->byTtl, 0x00), 0x0000));
  1196. break;
  1197. // IP-in-IP tunnels need to be added in the interface context in
  1198. // ifmon.dll, not here. But this is how it works for now!!! So
  1199. // we'll just dump the command that works.
  1200. case FORMAT_DUMP:
  1201. DisplayMessageT(DMP_IP_ADD_IPIPTUNNEL,
  1202. pwszQuoted,
  1203. rgwcLocalAddr,
  1204. rgwcRemAddr,
  1205. MAKELONG(MAKEWORD(pIpIpInfo->byTtl,0x00), 0x0000));
  1206. break;
  1207. default:
  1208. break;
  1209. }
  1210. }
  1211. if (pIpIpInfo)
  1212. {
  1213. FREE_BUFFER(pIpIpInfo);
  1214. }
  1215. return dwErr;
  1216. }
  1217. #endif //KSL_IPINIP
  1218. DWORD
  1219. ShowIpInterface(
  1220. IN DWORD dwFormat,
  1221. IN LPCWSTR pwszIfName,
  1222. IN OUT PDWORD pdwNumRows
  1223. )
  1224. /*++
  1225. Routine Description:
  1226. Show the interface info for the interface
  1227. The interface info consists of
  1228. AdminStatus
  1229. Router Discovery Info
  1230. Protocols on the interface
  1231. Other information like filters and routes are should using different
  1232. commands
  1233. Arguments:
  1234. pwszIfName - Interface name
  1235. Return Value:
  1236. NO_ERROR
  1237. --*/
  1238. {
  1239. DWORD dwErr;
  1240. WCHAR wszIfDesc[MAX_INTERFACE_NAME_LEN + 1];
  1241. PVALUE_STRING pps;
  1242. DWORD dwNumProto, dwBlkSize, dwCount, dwNumParsed;
  1243. DWORD dwIfType , i;
  1244. PBYTE pby;
  1245. PWCHAR pwszStatus, pwszQuoted;
  1246. PWCHAR pwszTokenStatus, pwszIfType;
  1247. PINTERFACE_STATUS_INFO pifStat;
  1248. //
  1249. // Interface status info
  1250. //
  1251. dwErr = IpmontrGetInfoBlockFromInterfaceInfo(pwszIfName,
  1252. IP_INTERFACE_STATUS_INFO,
  1253. (PBYTE *) &pifStat,
  1254. &dwBlkSize,
  1255. &dwCount,
  1256. &dwIfType);
  1257. if (dwErr != NO_ERROR)
  1258. {
  1259. // DisplayMessage(g_hModule, EMSG_IP_NO_STATUS_INFO);
  1260. return dwErr;
  1261. }
  1262. if (pifStat->dwAdminStatus is IF_ADMIN_STATUS_UP)
  1263. {
  1264. pwszStatus = MakeString(g_hModule, STRING_ENABLED);
  1265. pwszTokenStatus = TOKEN_VALUE_ENABLE;
  1266. }
  1267. else
  1268. {
  1269. pwszStatus = MakeString(g_hModule, STRING_DISABLED);
  1270. pwszTokenStatus = TOKEN_VALUE_DISABLE;
  1271. }
  1272. FREE_BUFFER(pifStat);
  1273. // Get description
  1274. dwErr = GetInterfaceDescription(pwszIfName,
  1275. wszIfDesc,
  1276. &dwNumParsed);
  1277. if (!dwNumParsed)
  1278. {
  1279. wcscpy(wszIfDesc, pwszIfName);
  1280. }
  1281. if(dwFormat is FORMAT_DUMP)
  1282. {
  1283. pwszQuoted = MakeQuotedString(wszIfDesc);
  1284. }
  1285. else
  1286. {
  1287. pwszQuoted = NULL;
  1288. }
  1289. pwszIfType = GetIfTypeString(dwIfType);
  1290. // Display generic interface info
  1291. switch (dwFormat) {
  1292. case FORMAT_VERBOSE:
  1293. DisplayMessage(g_hModule,
  1294. MSG_RTR_INTERFACE_HDR,
  1295. wszIfDesc);
  1296. DisplayMessage(g_hModule,
  1297. MSG_IP_IF_STATUS,
  1298. pwszStatus);
  1299. ShowIpIfProtocols(pwszIfName);
  1300. break;
  1301. case FORMAT_TABLE:
  1302. if (*pdwNumRows is 0)
  1303. {
  1304. DisplayMessage(g_hModule, MSG_IP_IF_HEADER);
  1305. }
  1306. DisplayMessage(g_hModule, MSG_IP_IF_ENTRY, pwszStatus, pwszIfType,
  1307. wszIfDesc);
  1308. break;
  1309. case FORMAT_DUMP:
  1310. DisplayMessageT(DMP_IP_ADD_IF, pwszQuoted, pwszTokenStatus);
  1311. break;
  1312. }
  1313. (*pdwNumRows)++;
  1314. #ifdef KSL_IPINIP
  1315. ShowIpInIpInfo(dwFormat, pwszIfName, pwszQuoted);
  1316. #endif //KSL_IPINIP
  1317. FreeQuotedString(pwszQuoted);
  1318. FreeString(pwszStatus);
  1319. return NO_ERROR;
  1320. }
  1321. DWORD
  1322. CreateDumpFile(
  1323. IN LPCWSTR pwszName,
  1324. OUT PHANDLE phFile
  1325. )
  1326. {
  1327. HANDLE hFile;
  1328. *phFile = NULL;
  1329. hFile = CreateFileW(pwszName,
  1330. GENERIC_WRITE,
  1331. FILE_SHARE_READ | FILE_SHARE_DELETE,
  1332. NULL,
  1333. OPEN_ALWAYS,
  1334. FILE_ATTRIBUTE_NORMAL,
  1335. NULL);
  1336. if(hFile == INVALID_HANDLE_VALUE)
  1337. return GetLastError();
  1338. *phFile = hFile;
  1339. return NO_ERROR;
  1340. }
  1341. VOID
  1342. DumpIpInformation(
  1343. HANDLE hFile
  1344. )
  1345. /*++
  1346. Routine Description:
  1347. Dumps all the IP Router manager information to the given file
  1348. Arguments:
  1349. hFile Handle of file
  1350. Return Value:
  1351. None
  1352. --*/
  1353. {
  1354. DWORD dwErr, dwCount, dwTotal;
  1355. DWORD dwNumParsed, i;
  1356. PMPR_INTERFACE_0 pmi0;
  1357. WCHAR wszIfDesc[MAX_INTERFACE_NAME_LEN + 1];
  1358. DWORD dwNumRows = 0;
  1359. // Display dump header
  1360. DisplayMessage(g_hModule, DMP_IP_HEADER_COMMENTS);
  1361. DisplayMessageT(DMP_IP_HEADER);
  1362. //
  1363. // First dump the global information
  1364. //
  1365. ShowIpGlobal(hFile);
  1366. ShowRoutePref(hFile);
  1367. ShowScopes(hFile);
  1368. //
  1369. // Dump the per interface info
  1370. //
  1371. dwErr = IpmontrInterfaceEnum((PBYTE *) &pmi0,
  1372. &dwCount,
  1373. &dwTotal);
  1374. if(dwErr != NO_ERROR)
  1375. {
  1376. DisplayError(g_hModule,
  1377. dwErr);
  1378. return;
  1379. }
  1380. for(i = 0; i < dwCount; i++)
  1381. {
  1382. ShowIpInterface(FORMAT_DUMP,
  1383. pmi0[i].wszInterfaceName, &dwNumRows);
  1384. ShowIpIfFilter(hFile,
  1385. FORMAT_DUMP,
  1386. pmi0[i].wszInterfaceName, &dwNumRows);
  1387. ShowIpPersistentRoute(hFile,
  1388. pmi0[i].wszInterfaceName, &dwNumRows);
  1389. ShowBoundaryInfoForInterface(hFile,
  1390. pmi0[i].wszInterfaceName,
  1391. &dwNumRows);
  1392. }
  1393. // Display dump footer
  1394. DisplayMessageT(DMP_POPD);
  1395. DisplayMessage(g_hModule, DMP_IP_FOOTER_COMMENTS);
  1396. }
  1397. DWORD
  1398. UpdateAutoStaticRoutes(
  1399. IN LPCWSTR pwszIfName
  1400. )
  1401. {
  1402. return NO_ERROR;
  1403. }