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.

1231 lines
26 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. routing\monitor2\ip\mprip.c
  5. Abstract:
  6. Functions to modify transport header (global and interface)
  7. This file now contains all the function exported by ipmon.dll to
  8. the helpers
  9. Revision History:
  10. Anand Mahalingam 7/29/98 Created
  11. AmritanR
  12. --*/
  13. #include "precomp.h"
  14. #include <time.h>
  15. #pragma hdrstop
  16. #define MaxIfDisplayLength 1024
  17. #define SetErrorType(pdw) *(pdw) = IsRouterRunning()?ERROR_ADMIN:ERROR_CONFIG
  18. BOOL g_bRouterRunning;
  19. ULONG g_ulNumChecks;
  20. VOID
  21. FreeInfoBuffer(
  22. IN PVOID pvBuffer
  23. )
  24. {
  25. HeapFree(GetProcessHeap(),
  26. 0,
  27. pvBuffer);
  28. }
  29. DWORD
  30. WINAPI
  31. IpmontrSetInfoBlockInGlobalInfo(
  32. IN DWORD dwType,
  33. IN PBYTE pbInfoBlk,
  34. IN DWORD dwSize,
  35. IN DWORD dwCount
  36. )
  37. /*++
  38. Routine Description:
  39. Called to Set or Add an info block to the Global Info
  40. Arguments:
  41. pbInfoBlk - Info block to be added
  42. dwType - Type of the info block
  43. dwSize - Size of each item in the info block
  44. dwCount - Number of items in the info block
  45. Return Value:
  46. NO_ERROR
  47. --*/
  48. {
  49. PRTR_INFO_BLOCK_HEADER pOldInfo, pNewInfo;
  50. DWORD dwErr;
  51. //
  52. // Get/update global info
  53. //
  54. dwErr = ValidateGlobalInfo(&pOldInfo);
  55. if(dwErr isnot NO_ERROR)
  56. {
  57. return dwErr;
  58. }
  59. if(MprInfoBlockExists(pOldInfo,
  60. dwType))
  61. {
  62. //
  63. // The block already exists. So call set to replace it
  64. //
  65. dwErr = MprInfoBlockSet(pOldInfo,
  66. dwType,
  67. dwSize,
  68. dwCount,
  69. pbInfoBlk,
  70. &pNewInfo);
  71. }
  72. else
  73. {
  74. //
  75. // No info currently, add it
  76. //
  77. dwErr = MprInfoBlockAdd(pOldInfo,
  78. dwType,
  79. dwSize,
  80. dwCount,
  81. pbInfoBlk,
  82. &pNewInfo);
  83. }
  84. //
  85. // Dont need the old info
  86. //
  87. FREE_BUFFER(pOldInfo);
  88. if(dwErr isnot NO_ERROR)
  89. {
  90. if(!g_bCommit)
  91. {
  92. g_tiTransport.pibhInfo = NULL;
  93. g_tiTransport.bValid = FALSE;
  94. }
  95. return dwErr;
  96. }
  97. //
  98. // If in commit mode, set it to the router/registry
  99. // Otherwise update the local copy
  100. //
  101. if(g_bCommit)
  102. {
  103. dwErr = SetGlobalInfo(pNewInfo);
  104. FREE_BUFFER(pNewInfo);
  105. }
  106. else
  107. {
  108. ASSERT(g_tiTransport.bValid);
  109. g_tiTransport.pibhInfo = pNewInfo;
  110. dwErr = NO_ERROR;
  111. }
  112. return dwErr;
  113. }
  114. DWORD
  115. WINAPI
  116. IpmontrSetInfoBlockInInterfaceInfo(
  117. IN LPCWSTR pwszIfName,
  118. IN DWORD dwType,
  119. IN PBYTE pbInfoBlk,
  120. IN DWORD dwSize,
  121. IN DWORD dwCount
  122. )
  123. /*++
  124. Routine Description:
  125. Adds or Sets and infoblock in the interface info
  126. Arguments:
  127. pwszIfName - interface name
  128. pbInfoBlk - Info block to be added
  129. dwType - Type of the info block
  130. dwSize - Size of each item in the info block
  131. dwCount - Number of items in the info block
  132. Return Value:
  133. NO_ERROR
  134. --*/
  135. {
  136. PRTR_INFO_BLOCK_HEADER pOldInfo, pNewInfo;
  137. DWORD dwErr;
  138. PINTERFACE_STORE pii;
  139. pii = NULL;
  140. //
  141. // Get/Update the interface info
  142. //
  143. dwErr = ValidateInterfaceInfo(pwszIfName,
  144. &pOldInfo,
  145. NULL,
  146. &pii);
  147. if(dwErr isnot NO_ERROR)
  148. {
  149. return dwErr;
  150. }
  151. if(MprInfoBlockExists(pOldInfo,
  152. dwType))
  153. {
  154. //
  155. // The block already exists call Set to replace
  156. //
  157. dwErr = MprInfoBlockSet(pOldInfo,
  158. dwType,
  159. dwSize,
  160. dwCount,
  161. pbInfoBlk,
  162. &pNewInfo);
  163. }
  164. else
  165. {
  166. dwErr = MprInfoBlockAdd(pOldInfo,
  167. dwType,
  168. dwSize,
  169. dwCount,
  170. pbInfoBlk,
  171. &pNewInfo);
  172. }
  173. FREE_BUFFER(pOldInfo);
  174. if(dwErr isnot NO_ERROR)
  175. {
  176. //
  177. // Some error - invalidate info
  178. //
  179. if(!g_bCommit)
  180. {
  181. ASSERT(pii);
  182. ASSERT(pii->bValid);
  183. pii->pibhInfo = NULL;
  184. pii->bValid = FALSE;
  185. }
  186. return dwErr;
  187. }
  188. if(g_bCommit)
  189. {
  190. //
  191. // Set to router/registry
  192. //
  193. dwErr = SetInterfaceInfo(pNewInfo,
  194. pwszIfName);
  195. FREE_BUFFER(pNewInfo);
  196. }
  197. else
  198. {
  199. //
  200. // Update local copy with new info (old one has been freed)
  201. //
  202. ASSERT(pii);
  203. ASSERT(pii->bValid);
  204. pii->pibhInfo = pNewInfo;
  205. pii->bValid = TRUE;
  206. dwErr = NO_ERROR;
  207. }
  208. return dwErr;
  209. }
  210. DWORD
  211. WINAPI
  212. IpmontrDeleteInfoBlockFromGlobalInfo(
  213. IN DWORD dwType
  214. )
  215. /*++
  216. Routine Description:
  217. Deletes an infoblock from the global info.
  218. The Infoblock is deleted by setting its Size and Count to 0
  219. Arguments:
  220. dwType - Id of Protocol to be added
  221. Return Value:
  222. NO_ERROR
  223. --*/
  224. {
  225. DWORD dwErr = NO_ERROR;
  226. PRTR_INFO_BLOCK_HEADER pOldInfo, pNewInfo;
  227. dwErr = ValidateGlobalInfo(&pOldInfo);
  228. if(dwErr isnot NO_ERROR)
  229. {
  230. return dwErr;
  231. }
  232. if(!MprInfoBlockExists(pOldInfo,
  233. dwType))
  234. {
  235. if(g_bCommit)
  236. {
  237. //
  238. // Arent saving a local copy so free this info
  239. //
  240. FREE_BUFFER(pOldInfo);
  241. }
  242. return NO_ERROR;
  243. }
  244. //
  245. // The router manager will only delete config info if we set
  246. // the size to 0. However, we don't want to write 0-size
  247. // blocks to the registry, so we will strip them out when
  248. // we write to the registry.
  249. //
  250. dwErr = MprInfoBlockSet(pOldInfo,
  251. dwType,
  252. 0,
  253. 0,
  254. NULL,
  255. &pNewInfo);
  256. FREE_BUFFER(pOldInfo);
  257. if(dwErr isnot NO_ERROR)
  258. {
  259. if(!g_bCommit)
  260. {
  261. ASSERT(g_tiTransport.bValid);
  262. g_tiTransport.pibhInfo = NULL;
  263. g_tiTransport.bValid = FALSE;
  264. }
  265. return dwErr;
  266. }
  267. if(g_bCommit)
  268. {
  269. dwErr = SetGlobalInfo(pNewInfo);
  270. FREE_BUFFER(pNewInfo);
  271. }
  272. else
  273. {
  274. ASSERT(g_tiTransport.bValid);
  275. g_tiTransport.pibhInfo = pNewInfo;
  276. dwErr = NO_ERROR;
  277. }
  278. return dwErr;
  279. }
  280. DWORD
  281. WINAPI
  282. IpmontrDeleteInfoBlockFromInterfaceInfo(
  283. IN LPCWSTR pwszIfName,
  284. IN DWORD dwType
  285. )
  286. /*++
  287. Routine Description:
  288. Deletes an info block from the interface info. The info block is
  289. deleted by setting its Size and Count to 0
  290. Arguments:
  291. pwszIfName - Interface on which to add the protocol
  292. dwType - Id of Protocol to be added
  293. Return Value:
  294. NO_ERROR
  295. --*/
  296. {
  297. DWORD dwErr;
  298. PRTR_INFO_BLOCK_HEADER pOldInfo, pNewInfo;
  299. PINTERFACE_STORE pii;
  300. pii = NULL;
  301. dwErr = ValidateInterfaceInfo(pwszIfName,
  302. &pOldInfo,
  303. NULL,
  304. &pii);
  305. if (dwErr isnot NO_ERROR)
  306. {
  307. return dwErr;
  308. }
  309. if(!MprInfoBlockExists(pOldInfo,
  310. dwType))
  311. {
  312. if (g_bCommit)
  313. {
  314. FREE_BUFFER(pOldInfo);
  315. }
  316. return NO_ERROR;
  317. }
  318. //
  319. // If it does exist, remove it
  320. // This creates a new block
  321. // HACKHACK - Again we can interchangeably use info that is allocated
  322. // by GetXxx functions and MprInfoBlock functions since both allocations
  323. // are from ProcessHeap()
  324. //
  325. //
  326. // The router manager will only delete config info if we set
  327. // the size to 0. However, we don't want to write 0-size
  328. // blocks to the registry, so we will strip them out when
  329. // we write to the registry.
  330. //
  331. dwErr = MprInfoBlockSet(pOldInfo,
  332. dwType,
  333. 0,
  334. 0,
  335. NULL,
  336. &pNewInfo);
  337. //
  338. // One way or another, done with the old info
  339. //
  340. FREE_BUFFER(pOldInfo);
  341. if(dwErr isnot NO_ERROR)
  342. {
  343. if(!g_bCommit)
  344. {
  345. ASSERT(pii);
  346. ASSERT(pii->bValid);
  347. pii->pibhInfo = NULL;
  348. pii->bValid = FALSE;
  349. }
  350. return dwErr;
  351. }
  352. if(g_bCommit)
  353. {
  354. dwErr = SetInterfaceInfo(pNewInfo,
  355. pwszIfName);
  356. FREE_BUFFER(pNewInfo);
  357. }
  358. else
  359. {
  360. ASSERT(pii);
  361. ASSERT(pii->bValid);
  362. pii->pibhInfo = pNewInfo;
  363. pii->bValid = TRUE;
  364. dwErr = NO_ERROR;
  365. }
  366. return dwErr;
  367. }
  368. DWORD
  369. WINAPI
  370. IpmontrDeleteProtocol(
  371. IN DWORD dwProtoId
  372. )
  373. /*++
  374. Routine Description:
  375. Deletes Protocol from a transport
  376. Arguments:
  377. dwProtoId - Id of Protocol to be deleted
  378. Return Value:
  379. NO_ERROR
  380. --*/
  381. {
  382. DWORD dwRes;
  383. PMPR_INTERFACE_0 pmi0;
  384. DWORD dwCnt, dwTot, dwInd, dwCount, dwErrType;
  385. SetErrorType(&dwErrType);
  386. do
  387. {
  388. //
  389. // Protocol being deleted globally, so remove from
  390. // all interfaces.
  391. //
  392. dwRes = IpmontrInterfaceEnum((PBYTE *) &pmi0,
  393. &dwCnt,
  394. &dwTot);
  395. if(dwRes != NO_ERROR)
  396. {
  397. DisplayMessage(g_hModule, dwErrType, dwRes);
  398. break;
  399. }
  400. if (pmi0 == NULL)
  401. {
  402. dwCnt = 0;
  403. }
  404. for (dwInd = 0; dwInd < dwCnt; dwInd++)
  405. {
  406. dwRes =
  407. IpmontrDeleteInfoBlockFromInterfaceInfo(pmi0[dwInd].wszInterfaceName,
  408. dwProtoId);
  409. if (dwRes is ERROR_NOT_ENOUGH_MEMORY)
  410. {
  411. break;
  412. }
  413. }
  414. //
  415. // Remove protocol from global info
  416. //
  417. dwRes = IpmontrDeleteInfoBlockFromGlobalInfo(dwProtoId);
  418. if (dwRes != NO_ERROR)
  419. {
  420. break;
  421. }
  422. } while(FALSE);
  423. if (pmi0)
  424. {
  425. HeapFree(GetProcessHeap(), 0, pmi0);
  426. }
  427. return dwRes;
  428. }
  429. DWORD
  430. WINAPI
  431. IpmontrGetInfoBlockFromGlobalInfo(
  432. IN DWORD dwType,
  433. OUT BYTE **ppbInfoBlk, OPTIONAL
  434. OUT PDWORD pdwSize, OPTIONAL
  435. OUT PDWORD pdwCount OPTIONAL
  436. )
  437. /*++
  438. Routine Description:
  439. Gets the info block from global info. If we get a zero sized block
  440. we return ERROR_NOT_FOUND so as to not configure the caller
  441. Arguments:
  442. dwType - Type of the info block
  443. ppbInfoBlk - ptr to info block
  444. pdwSize - size of each item in block
  445. pdwCount - number of items in block
  446. Return Value:
  447. NO_ERROR
  448. ERROR_NOT_FOUND if the block doesnt exist.
  449. --*/
  450. {
  451. PRTR_INFO_BLOCK_HEADER pInfo;
  452. DWORD dwErr;
  453. BOOL *pbValid;
  454. PBYTE pbyTmp = NULL;
  455. DWORD dwSize, dwCnt;
  456. if(ppbInfoBlk)
  457. {
  458. *ppbInfoBlk = NULL;
  459. }
  460. if(pdwSize)
  461. {
  462. *pdwSize = 0;
  463. }
  464. if(pdwCount)
  465. {
  466. *pdwCount = 0;
  467. }
  468. dwErr = ValidateGlobalInfo(&pInfo);
  469. if(dwErr isnot NO_ERROR)
  470. {
  471. return dwErr;
  472. }
  473. dwErr = MprInfoBlockFind(pInfo,
  474. dwType,
  475. &dwSize,
  476. &dwCnt,
  477. &pbyTmp);
  478. if(dwErr is NO_ERROR)
  479. {
  480. if(dwSize is 0)
  481. {
  482. if(g_bCommit)
  483. {
  484. FREE_BUFFER(pInfo);
  485. }
  486. return ERROR_NOT_FOUND;
  487. }
  488. if(ppbInfoBlk)
  489. {
  490. *ppbInfoBlk = HeapAlloc(GetProcessHeap(),
  491. 0,
  492. dwSize * dwCnt);
  493. if(*ppbInfoBlk is NULL)
  494. {
  495. if(g_bCommit)
  496. {
  497. FREE_BUFFER(pInfo);
  498. }
  499. return ERROR_NOT_ENOUGH_MEMORY;
  500. }
  501. CopyMemory(*ppbInfoBlk,
  502. pbyTmp,
  503. dwSize * dwCnt);
  504. }
  505. if(pdwSize)
  506. {
  507. *pdwSize = dwSize;
  508. }
  509. if(pdwCount)
  510. {
  511. *pdwCount = dwCnt;
  512. }
  513. }
  514. if(g_bCommit)
  515. {
  516. FREE_BUFFER(pInfo);
  517. }
  518. return dwErr;
  519. }
  520. DWORD
  521. WINAPI
  522. IpmontrGetInfoBlockFromInterfaceInfo(
  523. IN LPCWSTR pwszIfName,
  524. IN DWORD dwType,
  525. OUT BYTE **ppbInfoBlk, OPTIONAL
  526. OUT PDWORD pdwSize, OPTIONAL
  527. OUT PDWORD pdwCount, OPTIONAL
  528. OUT PDWORD pdwIfType OPTIONAL
  529. )
  530. /*++
  531. Routine Description:
  532. Gets the info block from interface transport header
  533. Arguments:
  534. pwszIfName - Interface Name
  535. dwType - Type of the info block
  536. ppbInfoBlk - ptr to info block
  537. pdwSize - size of each item in block
  538. pdwCount - number of items in block
  539. pdwIfType - interface type
  540. Return Value:
  541. NO_ERROR
  542. ERROR_NOT_FOUND
  543. --*/
  544. {
  545. PRTR_INFO_BLOCK_HEADER pInfo, *ppInfo;
  546. DWORD dwErr;
  547. PBYTE pbTmp, pbyTmp;
  548. DWORD dwSize, dwCount;
  549. if(ppbInfoBlk)
  550. {
  551. *ppbInfoBlk = NULL;
  552. }
  553. if(pdwSize)
  554. {
  555. *pdwSize = 0;
  556. }
  557. if(pdwCount)
  558. {
  559. *pdwCount = 0;
  560. }
  561. //
  562. // If the user doesnt want any info, size or count, then we can optimize
  563. // a bit by passing NULL to validate
  564. //
  565. if(((ULONG_PTR)ppbInfoBlk | (ULONG_PTR)pdwSize | (ULONG_PTR)pdwCount))
  566. {
  567. ppInfo = &pInfo;
  568. }
  569. else
  570. {
  571. ppInfo = NULL;
  572. }
  573. dwErr = ValidateInterfaceInfo(pwszIfName,
  574. ppInfo,
  575. pdwIfType,
  576. NULL);
  577. if((dwErr isnot NO_ERROR) or
  578. (ppInfo is NULL))
  579. {
  580. //
  581. // If the user had an error or only wanted the ifType we are done
  582. //
  583. return dwErr;
  584. }
  585. //
  586. // Return protocol block info.
  587. //
  588. dwErr = MprInfoBlockFind(pInfo,
  589. dwType,
  590. &dwSize,
  591. &dwCount,
  592. &pbyTmp);
  593. if(dwErr is NO_ERROR)
  594. {
  595. if(dwSize is 0)
  596. {
  597. if(g_bCommit)
  598. {
  599. FREE_BUFFER(pInfo);
  600. }
  601. return ERROR_NOT_FOUND;
  602. }
  603. if(ppbInfoBlk)
  604. {
  605. *ppbInfoBlk = HeapAlloc(GetProcessHeap(),
  606. 0,
  607. dwSize * dwCount);
  608. if(*ppbInfoBlk is NULL)
  609. {
  610. if(g_bCommit)
  611. {
  612. FREE_BUFFER(pInfo);
  613. }
  614. return ERROR_NOT_ENOUGH_MEMORY;
  615. }
  616. CopyMemory(*ppbInfoBlk,
  617. pbyTmp,
  618. dwSize * dwCount);
  619. if(pdwSize)
  620. {
  621. *pdwSize = dwSize;
  622. }
  623. if(pdwCount)
  624. {
  625. *pdwCount = dwCount;
  626. }
  627. }
  628. }
  629. if(g_bCommit)
  630. {
  631. FREE_BUFFER(pInfo);
  632. }
  633. return dwErr;
  634. }
  635. DWORD WINAPI
  636. IpmontrGetInterfaceType(
  637. IN LPCWSTR pwszIfName,
  638. OUT PDWORD pdwIfType
  639. )
  640. {
  641. return GetInterfaceInfo(pwszIfName,
  642. NULL,
  643. NULL,
  644. pdwIfType);
  645. }
  646. DWORD
  647. WINAPI
  648. GetInterfaceName(
  649. IN LPCWSTR ptcArgument,
  650. OUT LPWSTR pwszIfName,
  651. IN DWORD dwSizeOfIfName,
  652. OUT PDWORD pdwNumParsed
  653. )
  654. /*++
  655. Description:
  656. Convert a friendly name to an interface name
  657. Arguments:
  658. ptcArgument - Buffer holding the Friendly Name of an interface
  659. pwszIfName - Buffer to hold the Guid Interface Name
  660. dwSizeOfIfName - Size (in Bytes) of the pwszIfName
  661. pdwNumParsed -
  662. --*/
  663. {
  664. DWORD dwErr;
  665. dwErr = IpmontrGetIfNameFromFriendlyName(
  666. ptcArgument,
  667. pwszIfName,
  668. &dwSizeOfIfName );
  669. *pdwNumParsed = (dwErr is NO_ERROR)? 1 : 0;
  670. return dwErr;
  671. }
  672. DWORD
  673. WINAPI
  674. GetInterfaceDescription(
  675. IN LPCWSTR pwszIfName,
  676. OUT LPWSTR pwszIfDesc,
  677. OUT PDWORD pdwNumParsed
  678. )
  679. {
  680. DWORD rc,dwSize;
  681. WCHAR IfNamBuffer[MaxIfDisplayLength];
  682. DWORD dwLen = (DWORD) wcslen(pwszIfName);
  683. if ( !dwLen || dwLen > MAX_INTERFACE_NAME_LEN )
  684. {
  685. *pdwNumParsed = 0;
  686. return ERROR_INVALID_PARAMETER;
  687. }
  688. dwSize = sizeof(IfNamBuffer);
  689. //======================================
  690. // Translate the Interface Name
  691. //======================================
  692. rc = IpmontrGetFriendlyNameFromIfName(pwszIfName, IfNamBuffer, &dwSize);
  693. if (rc == NO_ERROR)
  694. {
  695. wcscpy(pwszIfDesc,IfNamBuffer);
  696. *pdwNumParsed = 1;
  697. }
  698. else
  699. {
  700. *pdwNumParsed = 0;
  701. }
  702. return rc;
  703. }
  704. DWORD
  705. WINAPI
  706. IpmontrInterfaceEnum(
  707. OUT PBYTE *ppb,
  708. OUT PDWORD pdwCount,
  709. OUT PDWORD pdwTotal
  710. )
  711. {
  712. DWORD dwRes;
  713. PMPR_INTERFACE_0 pmi0;
  714. #ifdef READROUTERINFO
  715. if(!IsRouterRunning())
  716. #endif
  717. {
  718. dwRes = MprConfigInterfaceEnum(g_hMprConfig,
  719. 0,
  720. (LPBYTE*) &pmi0,
  721. (DWORD) -1,
  722. pdwCount,
  723. pdwTotal,
  724. NULL);
  725. if(dwRes == NO_ERROR)
  726. {
  727. *ppb = (PBYTE)pmi0;
  728. }
  729. }
  730. #ifdef READROUTERINFO
  731. else
  732. {
  733. dwRes = MprAdminInterfaceEnum(g_hMprAdmin,
  734. 0,
  735. (LPBYTE*) &pmi0,
  736. (DWORD) -1,
  737. pdwCount,
  738. pdwTotal,
  739. NULL);
  740. if(dwRes == NO_ERROR)
  741. {
  742. *ppb = HeapAlloc(GetProcessHeap(),
  743. 0,
  744. sizeof(MPR_INTERFACE_0) * (*pdwCount));
  745. if(*ppb == NULL)
  746. {
  747. DisplayMessage(g_hModule, MSG_IP_NOT_ENOUGH_MEMORY);
  748. return ERROR_NOT_ENOUGH_MEMORY;
  749. }
  750. CopyMemory(*ppb, pmi0, sizeof(MPR_INTERFACE_0) * (*pdwCount));
  751. MprAdminBufferFree(pmi0);
  752. }
  753. }
  754. #endif
  755. return dwRes;
  756. }
  757. DWORD
  758. WINAPI
  759. MatchRoutingProtoTag(
  760. IN LPCWSTR pwszToken
  761. )
  762. /*++
  763. Routine Description:
  764. Gets the protocol ID corresponding to a protocol tag.
  765. Arguments:
  766. pwszArg - protocol token
  767. Return Value:
  768. Protocol Id or (DWORD)-1
  769. --*/
  770. {
  771. DWORD dwRes, dwErr;
  772. TOKEN_VALUE rgEnums[] ={{TOKEN_VALUE_RIP, PROTO_IP_RIP},
  773. {TOKEN_VALUE_OSPF, PROTO_IP_OSPF},
  774. {TOKEN_VALUE_AUTOSTATIC, PROTO_IP_NT_AUTOSTATIC},
  775. {TOKEN_VALUE_STATIC, PROTO_IP_NT_STATIC},
  776. {TOKEN_VALUE_NETMGMT, PROTO_IP_NETMGMT},
  777. {TOKEN_VALUE_LOCAL, PROTO_IP_LOCAL},
  778. {TOKEN_VALUE_NONDOD, PROTO_IP_NT_STATIC_NON_DOD}};
  779. if (iswdigit(pwszToken[0]))
  780. {
  781. return wcstoul(pwszToken, NULL, 10);
  782. }
  783. dwErr = MatchEnumTag(g_hModule,
  784. pwszToken,
  785. sizeof(rgEnums)/sizeof(TOKEN_VALUE),
  786. rgEnums,
  787. &dwRes);
  788. if(dwErr != NO_ERROR)
  789. {
  790. return (DWORD)-1;
  791. }
  792. return dwRes;
  793. }
  794. BOOL
  795. WINAPI
  796. IsRouterRunning(
  797. VOID
  798. )
  799. /*++
  800. Routine Description:
  801. Gets the protocol ID corresponding to a protocol tag.
  802. Arguments:
  803. pwszArg - protocol token
  804. Return Value:
  805. Protocol Id or (DWORD)-1
  806. --*/
  807. {
  808. DWORD dwErr;
  809. //
  810. // Check at most once per second
  811. //
  812. // We don't care about wrapping, we just need a fast way to
  813. // get some identifier of the current "second".
  814. //
  815. static time_t dwPreviousTime = 0;
  816. time_t dwCurrentTime;
  817. time(&dwCurrentTime);
  818. if (dwCurrentTime == dwPreviousTime)
  819. {
  820. return g_bRouterRunning;
  821. }
  822. dwPreviousTime = dwCurrentTime;
  823. if(MprAdminIsServiceRunning(g_pwszRouter))
  824. {
  825. if(g_bRouterRunning)
  826. {
  827. return TRUE;
  828. }
  829. dwErr = MprAdminServerConnect(g_pwszRouter,
  830. &g_hMprAdmin);
  831. if(dwErr isnot NO_ERROR)
  832. {
  833. DisplayError(NULL,
  834. dwErr);
  835. DisplayMessage(g_hModule,
  836. MSG_IP_CAN_NOT_CONNECT_DIM,
  837. dwErr);
  838. return FALSE;
  839. }
  840. dwErr = MprAdminMIBServerConnect(g_pwszRouter,
  841. &g_hMIBServer);
  842. if(dwErr isnot NO_ERROR)
  843. {
  844. DisplayError(NULL,
  845. dwErr);
  846. DisplayMessage(g_hModule,
  847. MSG_IP_CAN_NOT_CONNECT_DIM,
  848. dwErr);
  849. MprAdminServerDisconnect(g_hMprAdmin);
  850. g_hMprAdmin = NULL;
  851. return FALSE;
  852. }
  853. g_bRouterRunning = TRUE;
  854. }
  855. else
  856. {
  857. if(g_bRouterRunning)
  858. {
  859. g_bRouterRunning = FALSE;
  860. g_hMprAdmin = NULL;
  861. g_hMIBServer = NULL;
  862. }
  863. }
  864. return g_bRouterRunning;
  865. }
  866. DWORD
  867. MibGetFirst(
  868. DWORD dwTransportId,
  869. DWORD dwRoutingPid,
  870. LPVOID lpInEntry,
  871. DWORD dwInEntrySize,
  872. LPVOID *lplpOutEntry,
  873. LPDWORD lpdwOutEntrySize
  874. )
  875. {
  876. DWORD dwErr;
  877. dwErr = MprAdminMIBEntryGetFirst( g_hMIBServer,
  878. dwTransportId,
  879. dwRoutingPid,
  880. lpInEntry,
  881. dwInEntrySize,
  882. lplpOutEntry,
  883. lpdwOutEntrySize );
  884. if (dwErr is RPC_S_INVALID_BINDING)
  885. {
  886. g_bRouterRunning = FALSE;
  887. g_hMprAdmin = NULL;
  888. g_hMIBServer = NULL;
  889. }
  890. return dwErr;
  891. }
  892. DWORD
  893. MibGetNext(
  894. DWORD dwTransportId,
  895. DWORD dwRoutingPid,
  896. LPVOID lpInEntry,
  897. DWORD dwInEntrySize,
  898. LPVOID *lplpOutEntry,
  899. LPDWORD lpdwOutEntrySize
  900. )
  901. {
  902. DWORD dwErr;
  903. dwErr = MprAdminMIBEntryGetNext( g_hMIBServer,
  904. dwTransportId,
  905. dwRoutingPid,
  906. lpInEntry,
  907. dwInEntrySize,
  908. lplpOutEntry,
  909. lpdwOutEntrySize );
  910. if (dwErr is RPC_S_INVALID_BINDING)
  911. {
  912. g_bRouterRunning = FALSE;
  913. g_hMprAdmin = NULL;
  914. g_hMIBServer = NULL;
  915. }
  916. return dwErr;
  917. }
  918. DWORD
  919. MibGet(
  920. DWORD dwTransportId,
  921. DWORD dwRoutingPid,
  922. LPVOID lpInEntry,
  923. DWORD dwInEntrySize,
  924. LPVOID *lplpOutEntry,
  925. LPDWORD lpdwOutEntrySize
  926. )
  927. {
  928. DWORD dwErr;
  929. dwErr = MprAdminMIBEntryGet( g_hMIBServer,
  930. dwTransportId,
  931. dwRoutingPid,
  932. lpInEntry,
  933. dwInEntrySize,
  934. lplpOutEntry,
  935. lpdwOutEntrySize );
  936. if (dwErr is RPC_S_INVALID_BINDING)
  937. {
  938. g_bRouterRunning = FALSE;
  939. g_hMprAdmin = NULL;
  940. g_hMIBServer = NULL;
  941. }
  942. return dwErr;
  943. }