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.

2175 lines
68 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997 - 1999
  5. //
  6. // File: S T E E L H E A D . C P P
  7. //
  8. // Contents: Implementation of Steelhead configuration object.
  9. //
  10. // Notes:
  11. //
  12. // Author: shaunco 15 Jun 1997
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "stdafx.h"
  16. #pragma hdrstop
  17. #include <mprerror.h>
  18. #include "assert.h"
  19. //nclude <tdi.h> // must include for isnkrnl.h
  20. //nclude <isnkrnl.h>
  21. #include <rtinfo.h>
  22. #include "update.h"
  23. //nclude "ncreg.h"
  24. //nclude "ncsvc.h"
  25. #include "netcfgp.h"
  26. //nclude "router.h"
  27. #include "netcfgn.h"
  28. #include "netcfgx.h"
  29. #include "iprtrmib.h"
  30. #include "ipxrtdef.h"
  31. #include "routprot.h"
  32. #include "ipinfoid.h"
  33. #include "fltdefs.h"
  34. #include "iprtinfo.h"
  35. #include "ncnetcfg.h"
  36. #include "ncutil.h"
  37. extern const TCHAR c_szBiNdis5[];
  38. extern const TCHAR c_szRegKeyServices[];
  39. extern const TCHAR c_szSvcRemoteAccess[];
  40. extern const TCHAR c_szSvcRouter[];
  41. const GUID GUID_DEVCLASS_NET ={0x4D36E972,0xE325,0x11CE,{0xbf,0xc1,0x08,0x00,0x2b,0xe1,0x03,0x18}};
  42. //nst GUID IID_INetCfgComponentBindings ={0xC0E8AE9E,0x306E,0x11D1,{0xaa,0xcf,0x00,0x80,0x5F,0xC1,0x27,0x0E}};
  43. //+---------------------------------------------------------------------------
  44. // Static data for adding router managers.
  45. //
  46. static const WCHAR c_szwRtrMgrIp [] = L"Ip";
  47. static const WCHAR c_szwRtrMgrDllIp [] = L"%SystemRoot%\\System32\\iprtrmgr.dll";
  48. static const WCHAR c_szwRtrMgrIpx [] = L"Ipx";
  49. static const WCHAR c_szwRtrMgrDllIpx[] = L"%SystemRoot%\\System32\\ipxrtmgr.dll";
  50. static const ROUTER_MANAGER_INFO c_rmiIp =
  51. {
  52. PID_IP,
  53. 0,
  54. c_szwRtrMgrIp,
  55. c_szwRtrMgrDllIp,
  56. MakeIpInterfaceInfo,
  57. MakeIpTransportInfo,
  58. };
  59. static const ROUTER_MANAGER_INFO c_rmiIpx =
  60. {
  61. PID_IPX,
  62. ISN_FRAME_TYPE_AUTO,
  63. c_szwRtrMgrIpx,
  64. c_szwRtrMgrDllIpx ,
  65. MakeIpxInterfaceInfo,
  66. MakeIpxTransportInfo,
  67. };
  68. // For Ipx, the adapter name is the bind name.
  69. // We need to create an interface per frame type.
  70. // The interface name is the adapter name followed
  71. // by these strings.
  72. //
  73. struct MAP_SZW_DWORD
  74. {
  75. LPCWSTR pszwValue;
  76. DWORD dwValue;
  77. };
  78. static const MAP_SZW_DWORD c_mapFrameType [] =
  79. {
  80. L"/EthII", MISN_FRAME_TYPE_ETHERNET_II,
  81. L"/802.3", MISN_FRAME_TYPE_802_3,
  82. L"/802.2", MISN_FRAME_TYPE_802_2,
  83. L"/SNAP", MISN_FRAME_TYPE_SNAP,
  84. };
  85. BOOL
  86. FMapFrameTypeToString (
  87. DWORD dwFrameType,
  88. LPCWSTR* ppszwFrameType)
  89. {
  90. Assert (ppszwFrameType);
  91. for (int i = 0; i < celems (c_mapFrameType); i++)
  92. {
  93. if (dwFrameType == c_mapFrameType[i].dwValue)
  94. {
  95. *ppszwFrameType = c_mapFrameType[i].pszwValue;
  96. return TRUE;
  97. }
  98. }
  99. *ppszwFrameType = NULL;
  100. return FALSE;
  101. }
  102. BOOL
  103. FMapStringToFrameType (
  104. LPCWSTR pszwFrameType,
  105. DWORD* pdwFrameType)
  106. {
  107. Assert (pszwFrameType);
  108. Assert (pdwFrameType);
  109. for (int i = 0; i < celems (c_mapFrameType); i++)
  110. {
  111. if (0 == lstrcmpW (pszwFrameType, c_mapFrameType[i].pszwValue))
  112. {
  113. *pdwFrameType = c_mapFrameType[i].dwValue;
  114. return TRUE;
  115. }
  116. }
  117. *pdwFrameType = NULL;
  118. return FALSE;
  119. }
  120. //+---------------------------------------------------------------------------
  121. //
  122. // Function: HrShouldRouteOverAdapter
  123. //
  124. // Purpose:
  125. //
  126. // Arguments:
  127. // pnccAdapter [in]
  128. // pszwBindName [out]
  129. //
  130. // Returns:
  131. //
  132. // Author: shaunco 27 Aug 1997
  133. //
  134. // Notes:
  135. //
  136. HRESULT
  137. HrShouldRouteOverAdapter (
  138. INetCfgComponent* pnccAdapter,
  139. LPWSTR* ppszwBindName)
  140. {
  141. if (ppszwBindName)
  142. {
  143. *ppszwBindName = NULL;
  144. }
  145. // We should return S_OK if the adapter is physical or it supports
  146. // a binding interface of ndis5. S_FALSE otherwise.
  147. //
  148. DWORD dwCharacter;
  149. HRESULT hr = pnccAdapter->GetCharacteristics (&dwCharacter);
  150. if (SUCCEEDED(hr) && !(dwCharacter & NCF_PHYSICAL))
  151. {
  152. INetCfgComponentBindings* pnccBindings = NULL;
  153. hr = pnccAdapter->QueryInterface (IID_INetCfgComponentBindings,
  154. reinterpret_cast<void**>(&pnccBindings));
  155. if (SUCCEEDED(hr) && pnccBindings)
  156. {
  157. hr = pnccBindings->SupportsBindingInterface (NCF_UPPER, c_szBiNdis5);
  158. ReleaseObj (pnccBindings);
  159. pnccBindings = NULL;
  160. }
  161. }
  162. // SupportsBindingInterface may return S_OK or S_FALSE.
  163. // We only want the bind name if we're going to return S_OK.
  164. //
  165. if ((S_OK == hr) && ppszwBindName)
  166. {
  167. hr = pnccAdapter->GetBindName (ppszwBindName);
  168. }
  169. TraceResult ("HrShouldRouteOverAdapter", (S_FALSE == hr) ? S_OK : hr);
  170. return hr;
  171. }
  172. //+---------------------------------------------------------------------------
  173. //
  174. // Member: CSteelhead::CSteelhead
  175. //
  176. // Purpose: Constructor
  177. //
  178. // Arguments:
  179. // (none)
  180. //
  181. // Returns: Nothing.
  182. //
  183. // Author: shaunco 28 Jul 1997
  184. //
  185. // Notes:
  186. //
  187. CSteelhead::CSteelhead ()
  188. {
  189. m_hMprConfig = NULL;
  190. HMODULE hModule = NULL;
  191. hModule = LoadLibrary ( L"netcfgx.dll" );
  192. if ( NULL != hModule )
  193. {
  194. ::LoadString(hModule,
  195. IDS_RAS_INTERNAL_ADAPTER,
  196. m_swzInternal,
  197. sizeof(m_swzInternal) / sizeof(*m_swzInternal));
  198. ::LoadString(hModule,
  199. IDS_RAS_LOOPBACK_ADAPTER,
  200. m_swzLoopback,
  201. sizeof(m_swzLoopback) / sizeof(*m_swzLoopback));
  202. FreeLibrary ( hModule );
  203. }
  204. else
  205. {
  206. ::LoadString(_Module.GetResourceInstance(),
  207. IDS_INTERNAL_ADAPTER,
  208. m_swzInternal,
  209. sizeof(m_swzInternal) / sizeof(*m_swzInternal));
  210. ::LoadString(_Module.GetResourceInstance(),
  211. IDS_LOOPBACK_ADAPTER,
  212. m_swzLoopback,
  213. sizeof(m_swzLoopback) / sizeof(*m_swzLoopback));
  214. }
  215. }
  216. //+---------------------------------------------------------------------------
  217. //
  218. // Member: CSteelhead::~CSteelhead
  219. //
  220. // Purpose: Destructor
  221. //
  222. // Arguments:
  223. // (none)
  224. //
  225. // Returns: Nothing.
  226. //
  227. // Author: shaunco 28 Jul 1997
  228. //
  229. // Notes:
  230. //
  231. CSteelhead::~CSteelhead ()
  232. {
  233. Assert (!m_hMprConfig);
  234. ReleaseObj(m_pnc);
  235. m_pnc = NULL;
  236. }
  237. //+---------------------------------------------------------------------------
  238. //
  239. // Member: CSteelhead::FAdapterExistsWithMatchingBindName
  240. //
  241. // Purpose:
  242. //
  243. // Arguments:
  244. // pszwAdapterName [in]
  245. // ppnccAdapter [out]
  246. //
  247. // Returns:
  248. //
  249. // Author: shaunco 27 Aug 1997
  250. //
  251. // Notes:
  252. //
  253. BOOL
  254. CSteelhead::FAdapterExistsWithMatchingBindName (
  255. LPCWSTR pszwAdapterName,
  256. INetCfgComponent** ppnccAdapter)
  257. {
  258. Assert (pszwAdapterName);
  259. Assert (ppnccAdapter);
  260. *ppnccAdapter = NULL;
  261. BOOL fFound = FALSE;
  262. // Enumerate physical adapters in the system.
  263. //
  264. HRESULT hr = S_OK;
  265. CIterNetCfgComponent nccIter (m_pnc, &GUID_DEVCLASS_NET);
  266. INetCfgComponent* pnccAdapter = NULL;
  267. while (!fFound && SUCCEEDED(hr) &&
  268. S_OK == (hr = nccIter.HrNext (&pnccAdapter)))
  269. {
  270. // Only consider this adapter if we should router over it.
  271. //
  272. LPWSTR pszwBindName = NULL;
  273. hr = HrShouldRouteOverAdapter (pnccAdapter, &pszwBindName);
  274. if (S_OK == hr)
  275. {
  276. if (0 == lstrcmpW (pszwAdapterName, pszwBindName))
  277. {
  278. fFound = TRUE;
  279. *ppnccAdapter = pnccAdapter;
  280. AddRefObj (pnccAdapter);
  281. }
  282. CoTaskMemFree (pszwBindName);
  283. }
  284. ReleaseObj (pnccAdapter);
  285. pnccAdapter = NULL;
  286. }
  287. return fFound;
  288. }
  289. //+---------------------------------------------------------------------------
  290. //
  291. // Member: CSteelhead::FIpxFrameTypeInUseOnAdapter
  292. //
  293. // Purpose:
  294. //
  295. // Arguments:
  296. // dwFrameType []
  297. // pszwAdapterName []
  298. //
  299. // Returns:
  300. //
  301. // Author: shaunco 27 Aug 1997
  302. //
  303. // Notes:
  304. //
  305. BOOL
  306. CSteelhead::FIpxFrameTypeInUseOnAdapter (
  307. DWORD dwFrameType,
  308. LPCWSTR pszwAdapterName)
  309. {
  310. // Assume its not in use. If PnccIpx() is NULL, it means IPX is not
  311. // installed and the frame type is definately not in use on the adapter.
  312. //
  313. BOOL fRet = FALSE;
  314. if (PnccIpx())
  315. {
  316. // Get the private interface off of the INetCfgComponent for IPX
  317. // then we can query for a notify object interface
  318. //
  319. INetCfgComponentPrivate* pinccp;
  320. HRESULT hr = PnccIpx()->QueryInterface(
  321. IID_INetCfgComponentPrivate,
  322. reinterpret_cast<void**>(&pinccp));
  323. if (SUCCEEDED(hr))
  324. {
  325. IIpxAdapterInfo* pIpxAdapterInfo;
  326. hr = pinccp->QueryNotifyObject(
  327. IID_IIpxAdapterInfo,
  328. reinterpret_cast<void**>(&pIpxAdapterInfo));
  329. if (SUCCEEDED(hr) && pIpxAdapterInfo)
  330. {
  331. // Get the frametypes in use for this adapter.
  332. //
  333. DWORD adwFrameType [MISN_FRAME_TYPE_MAX + 1];
  334. DWORD cdwFrameType;
  335. hr = pIpxAdapterInfo->GetFrameTypesForAdapter (
  336. pszwAdapterName,
  337. celems (adwFrameType),
  338. adwFrameType,
  339. &cdwFrameType);
  340. if (SUCCEEDED(hr))
  341. {
  342. for (DWORD i = 0; i < cdwFrameType; i++)
  343. {
  344. if (dwFrameType == adwFrameType[i])
  345. {
  346. fRet = TRUE;
  347. break;
  348. }
  349. }
  350. }
  351. ReleaseObj (pIpxAdapterInfo);
  352. pIpxAdapterInfo = NULL;
  353. }
  354. ReleaseObj (pinccp);
  355. pinccp = NULL;
  356. }
  357. }
  358. return fRet;
  359. }
  360. //+---------------------------------------------------------------------------
  361. //
  362. // Member: CSteelhead::FIpxFrameTypeInUseOnAdapter
  363. //
  364. // Purpose:
  365. //
  366. // Arguments:
  367. // pszwFrameType []
  368. // pszwAdapterName []
  369. //
  370. // Returns:
  371. //
  372. // Author: shaunco 27 Aug 1997
  373. //
  374. // Notes:
  375. //
  376. BOOL
  377. CSteelhead::FIpxFrameTypeInUseOnAdapter (
  378. LPCWSTR pszwFrameType,
  379. LPCWSTR pszwAdapterName)
  380. {
  381. // Assume its not in use. If PnccIpx() is NULL, it means IPX is not
  382. // installed and the frame type is definately not in use on the adapter.
  383. //
  384. BOOL fRet = FALSE;
  385. DWORD dwFrameType;
  386. if (PnccIpx() && FMapStringToFrameType (pszwFrameType, &dwFrameType))
  387. {
  388. fRet = FIpxFrameTypeInUseOnAdapter (dwFrameType, pszwAdapterName);
  389. }
  390. return fRet;
  391. }
  392. //+---------------------------------------------------------------------------
  393. //
  394. // Member: CSteelhead::HrEnsureRouterInterfaceForAdapter
  395. //
  396. // Purpose: Ensures the router interface block for the specified
  397. // interface (adapter) is present and that the specified router
  398. // manger is configured for that interface.
  399. //
  400. // Arguments:
  401. // dwIfType [in] Interface type
  402. // dwPacketType [in] The packet type (IPX only, ignored othewise)
  403. // pszwAdapterName [in] The adapter name
  404. // pszwInterfaceName [in] The interface name
  405. // rmi [in] The router manager
  406. //
  407. // Returns: S_OK or an error code.
  408. //
  409. // Author: shaunco 28 Jul 1997
  410. //
  411. // Notes:
  412. //
  413. HRESULT
  414. CSteelhead::HrEnsureRouterInterfaceForAdapter (
  415. ROUTER_INTERFACE_TYPE dwIfType,
  416. DWORD dwPacketType,
  417. LPCWSTR pszwAdapterName,
  418. LPCWSTR pszwInterfaceName,
  419. const ROUTER_MANAGER_INFO& rmi)
  420. {
  421. // Make sure the interface is created.
  422. //
  423. HANDLE hInterface;
  424. HRESULT hr = HrEnsureRouterInterface (
  425. dwIfType,
  426. pszwInterfaceName,
  427. &hInterface);
  428. if (SUCCEEDED(hr))
  429. {
  430. // Ensure the router manager is added to the interface.
  431. //
  432. hr = HrEnsureRouterInterfaceTransport (
  433. pszwAdapterName,
  434. dwPacketType,
  435. hInterface,
  436. rmi);
  437. }
  438. TraceResult ("CSteelhead::HrEnsureRouterInterfaceForAdapter", hr);
  439. return hr;
  440. }
  441. //+---------------------------------------------------------------------------
  442. //
  443. // Member: CSteelhead::HrEnsureIpxRouterInterfacesForAdapter
  444. //
  445. // Purpose:
  446. //
  447. // Arguments:
  448. // pszwAdapterName []
  449. //
  450. // Returns:
  451. //
  452. // Author: shaunco 27 Aug 1997
  453. //
  454. // Notes:
  455. //
  456. HRESULT
  457. CSteelhead::HrEnsureIpxRouterInterfacesForAdapter (
  458. LPCWSTR pszwAdapterName)
  459. {
  460. AssertSz (PnccIpx(), "Why is this being called if IPX isn't installed?");
  461. // Get the private interface off of the INetCfgComponent for IPX
  462. // then we can query for a notify object interface
  463. //
  464. INetCfgComponentPrivate* pinccp;
  465. HRESULT hr = PnccIpx()->QueryInterface(
  466. IID_INetCfgComponentPrivate,
  467. reinterpret_cast<void**>(&pinccp));
  468. if (SUCCEEDED(hr))
  469. {
  470. // Get the IIpxAdapterInfo interface from the IPX notify object.
  471. // We'll use it to find out how adapters are configured under IPX.
  472. //
  473. IIpxAdapterInfo* pIpxAdapterInfo = NULL;
  474. hr = pinccp->QueryNotifyObject(
  475. IID_IIpxAdapterInfo,
  476. reinterpret_cast<void**>(&pIpxAdapterInfo));
  477. if (SUCCEEDED(hr) && pIpxAdapterInfo)
  478. {
  479. // Get the frametypes in use for this adapter.
  480. //
  481. DWORD adwFrameType [MISN_FRAME_TYPE_MAX + 1];
  482. DWORD cdwFrameType;
  483. hr = pIpxAdapterInfo->GetFrameTypesForAdapter (
  484. pszwAdapterName,
  485. celems (adwFrameType),
  486. adwFrameType,
  487. &cdwFrameType);
  488. if (SUCCEEDED(hr) && cdwFrameType)
  489. {
  490. // If more than one frame type is in use, or if there is only
  491. // one and it isn't auto, then we'll be creating interfaces
  492. // for those frame types explicitly.
  493. //
  494. if ((cdwFrameType > 1) ||
  495. ((1 == cdwFrameType) &&
  496. (ISN_FRAME_TYPE_AUTO != adwFrameType[0])))
  497. {
  498. for (DWORD i = 0; SUCCEEDED(hr) && (i < cdwFrameType); i++)
  499. {
  500. LPCWSTR pszwFrameType;
  501. if (FMapFrameTypeToString (adwFrameType[i], &pszwFrameType))
  502. {
  503. // Make the interface name by catenating the
  504. // adapter (bind) name with the frame type.
  505. //
  506. WCHAR szwInterfaceName [512];
  507. lstrcpyW (szwInterfaceName, pszwAdapterName);
  508. lstrcatW (szwInterfaceName, pszwFrameType);
  509. hr = HrEnsureRouterInterfaceForAdapter (
  510. ROUTER_IF_TYPE_DEDICATED,
  511. adwFrameType[i],
  512. pszwAdapterName,
  513. szwInterfaceName,
  514. c_rmiIpx);
  515. }
  516. }
  517. }
  518. // Otherwise, we'll create the interface for the auto frame
  519. // type case.
  520. //
  521. else
  522. {
  523. #ifdef DBG
  524. AssertSz (1 == cdwFrameType,
  525. "IPX should report at least one frame type. "
  526. "You may continue without a problem.");
  527. if (1 == cdwFrameType)
  528. {
  529. AssertSz (ISN_FRAME_TYPE_AUTO == adwFrameType[0],
  530. "Frame type should be auto here. "
  531. "You may continue without a problem.");
  532. }
  533. #endif
  534. hr = HrEnsureRouterInterfaceForAdapter (
  535. ROUTER_IF_TYPE_DEDICATED,
  536. ISN_FRAME_TYPE_AUTO,
  537. pszwAdapterName,
  538. pszwAdapterName,
  539. c_rmiIpx);
  540. }
  541. }
  542. ReleaseObj (pIpxAdapterInfo);
  543. pIpxAdapterInfo = NULL;
  544. }
  545. ReleaseObj (pinccp);
  546. pinccp = NULL;
  547. }
  548. TraceResult ("CSteelhead::HrEnsureIpxRouterInterfacesForAdapter", hr);
  549. return hr;
  550. }
  551. //+---------------------------------------------------------------------------
  552. //
  553. // Member: CSteelhead::HrEnsureRouterInterface
  554. //
  555. // Purpose: Ensures the specified router interface is present and
  556. // returns a handle to it.
  557. //
  558. // Arguments:
  559. // pszwInterfaceName [in] The interface (adapter) name
  560. // phInterface [out] Returned handle to the interface
  561. //
  562. // Returns: S_OK or an error code.
  563. //
  564. // Author: shaunco 28 Jul 1997
  565. //
  566. // Notes:
  567. //
  568. HRESULT
  569. CSteelhead::HrEnsureRouterInterface (
  570. ROUTER_INTERFACE_TYPE dwIfType,
  571. LPCWSTR pszwInterfaceName,
  572. HANDLE* phInterface)
  573. {
  574. Assert (pszwInterfaceName);
  575. Assert (phInterface);
  576. HRESULT hr = HrMprConfigInterfaceGetHandle (m_hMprConfig,
  577. const_cast<LPWSTR>(pszwInterfaceName),
  578. phInterface);
  579. if (HRESULT_FROM_WIN32 (ERROR_NO_SUCH_INTERFACE ) == hr)
  580. {
  581. // It's not installed, we'll create it.
  582. //
  583. // The name of the interface will be the adatper instance.
  584. //
  585. MPR_INTERFACE_0 ri0;
  586. ZeroMemory (&ri0, sizeof(ri0));
  587. ri0.hInterface = INVALID_HANDLE_VALUE;
  588. ri0.fEnabled = TRUE; // thanks gibbs
  589. ri0.dwIfType = dwIfType;
  590. // Copy the interface name into the buffer.
  591. //
  592. AssertSz (lstrlen (pszwInterfaceName) < celems (ri0.wszInterfaceName),
  593. "Bindname too big for MPR_INTERFACE_0 buffer.");
  594. lstrcpy (ri0.wszInterfaceName, pszwInterfaceName);
  595. // Create the interface.
  596. //
  597. hr = HrMprConfigInterfaceCreate (m_hMprConfig,
  598. 0, (LPBYTE)&ri0,
  599. phInterface);
  600. }
  601. TraceResult ("CSteelhead::HrEnsureRouterInterface", hr);
  602. return hr;
  603. }
  604. //+---------------------------------------------------------------------------
  605. //
  606. // Member: CSteelhead::HrEnsureRouterInterfaceTransport
  607. //
  608. // Purpose: Ensures the specified router manager is configured over
  609. // the specified interface.
  610. //
  611. // Arguments:
  612. // pszwAdapterName [in] The adapter name
  613. // dwPacketType [in] The packet type (IPX only, ignored otherwise)
  614. // hInterface [in] Handle to the interface
  615. // rmi [in] The router manager
  616. //
  617. // Returns: S_OK or an error code.
  618. //
  619. // Author: shaunco 28 Jul 1997
  620. //
  621. // Notes:
  622. //
  623. HRESULT
  624. CSteelhead::HrEnsureRouterInterfaceTransport (
  625. LPCWSTR pszwAdapterName,
  626. DWORD dwPacketType,
  627. HANDLE hInterface,
  628. const ROUTER_MANAGER_INFO& rmi)
  629. {
  630. HRESULT hr;
  631. Assert (hInterface);
  632. // Ensure the router manager is present
  633. //
  634. hr = HrEnsureRouterManager (rmi);
  635. if (SUCCEEDED(hr))
  636. {
  637. // See if the router manager is present on the interface.
  638. //
  639. HANDLE hIfTransport;
  640. hr = HrMprConfigInterfaceTransportGetHandle (m_hMprConfig,
  641. hInterface,
  642. rmi.dwTransportId,
  643. &hIfTransport);
  644. if (FAILED(hr))
  645. {
  646. // Create the interface info and add the router manager to
  647. // the interface.
  648. //
  649. PRTR_INFO_BLOCK_HEADER pibh;
  650. Assert (rmi.pfnMakeInterfaceInfo);
  651. rmi.pfnMakeInterfaceInfo (pszwAdapterName,
  652. dwPacketType,
  653. (LPBYTE*)&pibh);
  654. hr = HrMprConfigInterfaceTransportAdd (
  655. m_hMprConfig,
  656. hInterface,
  657. rmi.dwTransportId,
  658. const_cast<LPWSTR>(rmi.pszwTransportName),
  659. (LPBYTE)pibh,
  660. pibh->Size,
  661. &hIfTransport);
  662. delete (LPBYTE*)pibh;
  663. }
  664. }
  665. TraceResult ("CSteelhead::HrEnsureRouterInterfaceTransport", hr);
  666. return hr;
  667. }
  668. //+---------------------------------------------------------------------------
  669. //
  670. // Member: CSteelhead::HrEnsureRouterManager
  671. //
  672. // Purpose: Ensures that the specified router manager is installed.
  673. //
  674. // Arguments:
  675. // rmi [in] The router manager.
  676. //
  677. // Returns: S_OK or an error code.
  678. //
  679. // Author: shaunco 28 Jul 1997
  680. //
  681. // Notes:
  682. //
  683. HRESULT
  684. CSteelhead::HrEnsureRouterManager (
  685. const ROUTER_MANAGER_INFO& rmi)
  686. {
  687. PRTR_INFO_BLOCK_HEADER pibhGlobal;
  688. BOOL fCreate = FALSE;
  689. // See if the router manager is installed.
  690. //
  691. HANDLE hTransport;
  692. HRESULT hr = HrMprConfigTransportGetHandle (m_hMprConfig,
  693. rmi.dwTransportId,
  694. &hTransport);
  695. if (HRESULT_FROM_WIN32 (ERROR_UNKNOWN_PROTOCOL_ID) == hr)
  696. {
  697. // It's not installed, we'll create it.
  698. //
  699. fCreate = TRUE;
  700. }
  701. else if (SUCCEEDED(hr))
  702. {
  703. // Its installed, see if its transport info is available.
  704. //
  705. DWORD dwSize;
  706. hr = HrMprConfigTransportGetInfo (m_hMprConfig, hTransport,
  707. (LPBYTE*)&pibhGlobal, &dwSize,
  708. NULL, NULL, NULL);
  709. if (SUCCEEDED(hr))
  710. {
  711. if (!pibhGlobal)
  712. {
  713. // Global info is missing, we'll create it.
  714. //
  715. fCreate = TRUE;
  716. }
  717. else
  718. {
  719. MprConfigBufferFree (pibhGlobal);
  720. }
  721. }
  722. }
  723. if (fCreate)
  724. {
  725. // Install the router manager.
  726. //
  727. Assert (rmi.pfnMakeTransportInfo);
  728. PRTR_INFO_BLOCK_HEADER pibhClient;
  729. rmi.pfnMakeTransportInfo ((LPBYTE*)&pibhGlobal,
  730. (LPBYTE*)&pibhClient);
  731. hr = HrMprConfigTransportCreate (
  732. m_hMprConfig,
  733. rmi.dwTransportId,
  734. const_cast<LPWSTR>(rmi.pszwTransportName),
  735. (LPBYTE)pibhGlobal, (pibhGlobal) ? pibhGlobal->Size : 0,
  736. (LPBYTE)pibhClient, (pibhClient) ? pibhClient->Size : 0,
  737. const_cast<LPWSTR>(rmi.pszwDllPath),
  738. &hTransport);
  739. delete (LPBYTE*)pibhGlobal;
  740. delete (LPBYTE*)pibhClient;
  741. }
  742. TraceResult ("CSteelhead::HrEnsureRouterManager", hr);
  743. return hr;
  744. }
  745. //+---------------------------------------------------------------------------
  746. //
  747. // Member: CSteelhead::HrEnsureRouterManagerDeleted
  748. //
  749. // Purpose: Ensures that the specified router manager is not installed.
  750. //
  751. // Arguments:
  752. // rmi [in] The router manager.
  753. //
  754. // Returns: S_OK or an error code.
  755. //
  756. // Author: shaunco 6 Sep 1997
  757. //
  758. // Notes:
  759. //
  760. HRESULT CSteelhead::HrEnsureRouterManagerDeleted (
  761. const ROUTER_MANAGER_INFO& rmi)
  762. {
  763. // See if the router manager is installed.
  764. //
  765. HANDLE hTransport;
  766. HRESULT hr = HrMprConfigTransportGetHandle (m_hMprConfig,
  767. rmi.dwTransportId,
  768. &hTransport);
  769. if (SUCCEEDED(hr))
  770. {
  771. // It is installed, so we need to delete it.
  772. //
  773. (void) HrMprConfigTransportDelete (m_hMprConfig, hTransport);
  774. }
  775. TraceResult ("CSteelhead::HrEnsureRouterManagerDeleted",
  776. (HRESULT_FROM_WIN32 (ERROR_UNKNOWN_PROTOCOL_ID) == hr)
  777. ? S_OK : hr);
  778. return hr;
  779. }
  780. //+---------------------------------------------------------------------------
  781. //
  782. // Member: CSteelhead::HrPassToAddInterfaces
  783. //
  784. // Purpose:
  785. //
  786. // Arguments:
  787. // (none)
  788. //
  789. // Returns:
  790. //
  791. // Author: shaunco 27 Aug 1997
  792. //
  793. // Notes:
  794. //
  795. HRESULT
  796. CSteelhead::HrPassToAddInterfaces ()
  797. {
  798. HRESULT hr = S_OK;
  799. // Enumerate physical adapters in the system.
  800. //
  801. CIterNetCfgComponent nccIter(m_pnc, &GUID_DEVCLASS_NET);
  802. INetCfgComponent* pnccAdapter;
  803. while (SUCCEEDED(hr) && S_OK == (hr = nccIter.HrNext(&pnccAdapter)))
  804. {
  805. // Only consider this adapter if we should router over it.
  806. //
  807. LPWSTR pszwBindName = NULL;
  808. hr = HrShouldRouteOverAdapter (pnccAdapter, &pszwBindName);
  809. if (S_OK == hr)
  810. {
  811. INetCfgComponentBindings* pnccBindingsIp = NULL;
  812. INetCfgComponentBindings* pnccBindingsIpx = NULL;
  813. // If Ip is bound to the adapter, create and interface
  814. // for it.
  815. //
  816. if (PnccIp())
  817. {
  818. hr = PnccIp()->QueryInterface (IID_INetCfgComponentBindings,
  819. reinterpret_cast<void**>(&pnccBindingsIp) );
  820. }
  821. if (PnccIp() && SUCCEEDED(hr) &&
  822. (S_OK == (hr = pnccBindingsIp->IsBoundTo (pnccAdapter))))
  823. {
  824. // Interface name is the same as the adapter name
  825. // is the same as the bind name.
  826. //
  827. hr = HrEnsureRouterInterfaceForAdapter (
  828. ROUTER_IF_TYPE_DEDICATED,
  829. 0,
  830. pszwBindName,
  831. pszwBindName,
  832. c_rmiIp);
  833. }
  834. ReleaseObj (pnccBindingsIp);
  835. pnccBindingsIp = NULL;
  836. // If Ipx is bound to the adapter, create the interface(s)
  837. // for it.
  838. if (PnccIpx())
  839. {
  840. hr = PnccIpx()->QueryInterface (IID_INetCfgComponentBindings,
  841. reinterpret_cast<void**>(&pnccBindingsIpx));
  842. }
  843. if (PnccIpx() &&
  844. (S_OK == (hr = pnccBindingsIpx->IsBoundTo( pnccAdapter )) ))
  845. {
  846. #if (WINVER < 0x0501)
  847. hr = HrEnsureIpxRouterInterfacesForAdapter (pszwBindName);
  848. #endif
  849. }
  850. ReleaseObj (pnccBindingsIpx);
  851. pnccBindingsIpx = NULL;
  852. CoTaskMemFree(pszwBindName);
  853. }
  854. ReleaseObj (pnccAdapter);
  855. pnccAdapter = NULL;
  856. }
  857. // Normalize the HRESULT. (i.e. don't return S_FALSE)
  858. if (S_FALSE == hr)
  859. {
  860. hr = S_OK;
  861. }
  862. TraceResult ("CSteelhead::HrPassToAddInterfaces", hr);
  863. return hr;
  864. }
  865. //+---------------------------------------------------------------------------
  866. //
  867. // Member: CSteelhead::HrPassToRemoveInterfaces
  868. //
  869. // Purpose:
  870. //
  871. // Arguments:
  872. // (none)
  873. //
  874. // Returns:
  875. //
  876. // Author: shaunco 27 Aug 1997
  877. //
  878. // Notes:
  879. //
  880. HRESULT
  881. CSteelhead::HrPassToRemoveInterfaces ()
  882. {
  883. // Enumerate all of the installed router interfaces.
  884. //
  885. MPR_INTERFACE_0* ari0;
  886. DWORD dwEntriesRead;
  887. DWORD dwTotalEntries;
  888. HRESULT hr = HrMprConfigInterfaceEnum (m_hMprConfig, 0,
  889. reinterpret_cast<LPBYTE*>(&ari0),
  890. -1, &dwEntriesRead, &dwTotalEntries, NULL);
  891. if (SUCCEEDED(hr))
  892. {
  893. // By passing -1, we want everything, so we should get everything.
  894. Assert (dwEntriesRead == dwTotalEntries);
  895. // Iterate all of the interfaces.
  896. //
  897. for (MPR_INTERFACE_0* pri0 = ari0; dwEntriesRead--; pri0++)
  898. {
  899. BOOL fDeleteInterface = FALSE;
  900. // If its the internal interface and IP and IPX are no longer
  901. // installed delete the interface.
  902. //
  903. if ((ROUTER_IF_TYPE_INTERNAL == pri0->dwIfType) &&
  904. !PnccIpx() && !PnccIp() &&
  905. (0 == lstrcmpW (pri0->wszInterfaceName, m_swzInternal)))
  906. {
  907. fDeleteInterface = TRUE;
  908. }
  909. else if (ROUTER_IF_TYPE_DEDICATED != pri0->dwIfType)
  910. {
  911. // Skip non-dedicated interfaces.
  912. //
  913. continue;
  914. }
  915. BOOL fSpecialIpxInterface = FALSE;
  916. INetCfgComponent* pnccAdapter = NULL;
  917. // Get the name of the interface and look for a '/' separator.
  918. // If present, it means this is a special IPX interface where
  919. // the first substring is the adapter name, and the second
  920. // substring is the frame type.
  921. //
  922. WCHAR* pchwSep = wcschr (pri0->wszInterfaceName, L'/');
  923. if (!fDeleteInterface && pchwSep)
  924. {
  925. fSpecialIpxInterface = TRUE;
  926. // Point to the frame type string.
  927. //
  928. LPCWSTR pszwFrameType = pchwSep;
  929. // Copy the adapter name into its own buffer.
  930. //
  931. WCHAR szwAdapterName [MAX_INTERFACE_NAME_LEN+1];
  932. lstrcpynW (szwAdapterName, pri0->wszInterfaceName,
  933. (int)(pchwSep - pri0->wszInterfaceName + 1));
  934. // If the frame type is not in use for the adapter, we need
  935. // to delete this interface. This condition happens when
  936. // IPX configuration is changed and the frame type is removed
  937. // from the adapter.
  938. //
  939. if (!FIpxFrameTypeInUseOnAdapter (pszwFrameType,
  940. szwAdapterName))
  941. {
  942. fDeleteInterface = TRUE;
  943. }
  944. }
  945. // Its not a special interface, so just make sure an adapter
  946. // exists with a matching bind name. If not, we will delete
  947. // the interface.
  948. //
  949. else if (!fDeleteInterface)
  950. {
  951. if (!FAdapterExistsWithMatchingBindName (
  952. pri0->wszInterfaceName,
  953. &pnccAdapter))
  954. {
  955. fDeleteInterface = TRUE;
  956. }
  957. }
  958. // Delete the interface if we need to.
  959. //
  960. if (fDeleteInterface)
  961. {
  962. MprConfigInterfaceDelete (m_hMprConfig, pri0->hInterface);
  963. }
  964. // If we don't need to delete the entire interface, check
  965. // for transports on the interface that we may need to delete.
  966. //
  967. else
  968. {
  969. // If its not an IPX special interface, the adapter
  970. // is the interface name. If it is an IPX special
  971. // interface, then we would have already remove the entire
  972. // interfce above if it were invalid.
  973. //
  974. (void) HrPassToRemoveInterfaceTransports (
  975. pri0,
  976. (!fSpecialIpxInterface) ? pri0->wszInterfaceName
  977. : NULL,
  978. pnccAdapter);
  979. }
  980. ReleaseObj (pnccAdapter);
  981. pnccAdapter = NULL;
  982. }
  983. MprConfigBufferFree (ari0);
  984. }
  985. else if (HRESULT_FROM_WIN32(ERROR_NO_MORE_ITEMS) == hr)
  986. {
  987. hr = S_OK;
  988. }
  989. TraceResult ("CSteelhead::HrPassToRemoveInterfaces", hr);
  990. return hr;
  991. }
  992. //+---------------------------------------------------------------------------
  993. //
  994. // Member: CSteelhead::HrPassToRemoveInterfaceTransports
  995. //
  996. // Purpose:
  997. //
  998. // Arguments:
  999. // hInterface []
  1000. // pszwAdapterName []
  1001. //
  1002. // Returns:
  1003. //
  1004. // Author: shaunco 27 Aug 1997
  1005. //
  1006. // Notes:
  1007. //
  1008. HRESULT
  1009. CSteelhead::HrPassToRemoveInterfaceTransports (
  1010. MPR_INTERFACE_0* pri0,
  1011. LPCWSTR pszwAdapterName,
  1012. INetCfgComponent* pnccAdapter)
  1013. {
  1014. // Assert (FImplies(pnccAdapter, pszwAdapterName));
  1015. // Enumerate all of the transports active on the router interface.
  1016. //
  1017. MPR_IFTRANSPORT_0* arit0;
  1018. DWORD dwEntriesRead;
  1019. DWORD dwTotalEntries;
  1020. HRESULT hr = HrMprConfigInterfaceTransportEnum (m_hMprConfig,
  1021. pri0->hInterface, 0,
  1022. reinterpret_cast<LPBYTE*>(&arit0),
  1023. -1, &dwEntriesRead, &dwTotalEntries, NULL);
  1024. if (SUCCEEDED(hr))
  1025. {
  1026. // By passing -1, we want everything, so we should get everything.
  1027. Assert (dwEntriesRead == dwTotalEntries);
  1028. INetCfgComponentBindings* pnccBindingsIpx = NULL;
  1029. INetCfgComponentBindings* pnccBindingsIp = NULL;
  1030. if (PnccIp())
  1031. {
  1032. hr = PnccIp()->QueryInterface (IID_INetCfgComponentBindings,
  1033. reinterpret_cast<void**>(&pnccBindingsIp));
  1034. }
  1035. if (SUCCEEDED(hr))
  1036. {
  1037. if (PnccIpx())
  1038. {
  1039. hr = PnccIpx()->QueryInterface (IID_INetCfgComponentBindings,
  1040. reinterpret_cast<void**>(&pnccBindingsIpx));
  1041. }
  1042. if (SUCCEEDED(hr))
  1043. {
  1044. // Iterate all of the transports.
  1045. //
  1046. for (MPR_IFTRANSPORT_0* prit0 = arit0; dwEntriesRead--; prit0++)
  1047. {
  1048. BOOL fDeleteInterfaceTransport = FALSE;
  1049. if (prit0->dwTransportId == c_rmiIp.dwTransportId)
  1050. {
  1051. if (!PnccIp())
  1052. {
  1053. fDeleteInterfaceTransport = TRUE;
  1054. }
  1055. else if (pnccAdapter &&
  1056. (S_OK != (hr = pnccBindingsIp->IsBoundTo (pnccAdapter))))
  1057. {
  1058. fDeleteInterfaceTransport = TRUE;
  1059. }
  1060. }
  1061. else if (prit0->dwTransportId == c_rmiIpx.dwTransportId)
  1062. {
  1063. if (!PnccIpx())
  1064. {
  1065. fDeleteInterfaceTransport = TRUE;
  1066. }
  1067. else if (pnccAdapter &&
  1068. (S_OK != (hr = pnccBindingsIpx->IsBoundTo (pnccAdapter))))
  1069. {
  1070. fDeleteInterfaceTransport = TRUE;
  1071. }
  1072. else if (pszwAdapterName)
  1073. {
  1074. Assert (PnccIpx());
  1075. // if frame type is not auto on this adapter, delete
  1076. // the transport
  1077. if (!FIpxFrameTypeInUseOnAdapter (ISN_FRAME_TYPE_AUTO,
  1078. pszwAdapterName))
  1079. {
  1080. fDeleteInterfaceTransport = TRUE;
  1081. }
  1082. }
  1083. }
  1084. if (fDeleteInterfaceTransport)
  1085. {
  1086. MprConfigInterfaceTransportRemove (
  1087. m_hMprConfig,
  1088. pri0->hInterface,
  1089. prit0->hIfTransport);
  1090. }
  1091. }
  1092. MprConfigBufferFree (arit0);
  1093. ReleaseObj (pnccBindingsIpx);
  1094. pnccBindingsIpx = NULL;
  1095. }
  1096. ReleaseObj (pnccBindingsIp);
  1097. pnccBindingsIp = NULL;
  1098. }
  1099. }
  1100. else if (HRESULT_FROM_WIN32(ERROR_NO_MORE_ITEMS) == hr)
  1101. {
  1102. // If there are no transports for this interface, that's okay.
  1103. //
  1104. hr = S_OK;
  1105. }
  1106. TraceResult ("CSteelhead::HrPassToRemoveInterfaceTransports", hr);
  1107. return hr;
  1108. }
  1109. //+---------------------------------------------------------------------------
  1110. //
  1111. // Member: CSteelhead::HrUpdateRouterConfiguration
  1112. //
  1113. // Purpose: Updates the router configuration by ensuring router managers
  1114. // are installed for the protocols present on the system (IP and
  1115. // IPX). Further, router interfaces are created for each
  1116. // physical netcard present on the system.
  1117. //
  1118. // Arguments:
  1119. // (none)
  1120. //
  1121. // Returns: S_OK or an error code.
  1122. //
  1123. // Author: shaunco 28 Jul 1997
  1124. //
  1125. // Notes:
  1126. //
  1127. HRESULT
  1128. CSteelhead::HrUpdateRouterConfiguration ()
  1129. {
  1130. Assert (!m_hMprConfig);
  1131. HRESULT hr = HrMprConfigServerConnect (NULL, &m_hMprConfig);
  1132. if (SUCCEEDED(hr))
  1133. {
  1134. // Ensure router managers are installed for the protocols
  1135. // we know about. Good to do this in case no physical adapters.
  1136. // are found below. We actually do this by ensuring the internal
  1137. // interface exists. This will implicitly ensure the router
  1138. // manger is created.
  1139. //
  1140. if (PnccIp())
  1141. {
  1142. (void) HrEnsureRouterInterfaceForAdapter (
  1143. ROUTER_IF_TYPE_LOOPBACK,
  1144. c_rmiIp.dwPacketType,
  1145. m_swzLoopback,
  1146. m_swzLoopback,
  1147. c_rmiIp);
  1148. (void) HrEnsureRouterInterfaceForAdapter (
  1149. ROUTER_IF_TYPE_INTERNAL,
  1150. c_rmiIp.dwPacketType,
  1151. m_swzInternal,
  1152. m_swzInternal,
  1153. c_rmiIp);
  1154. }
  1155. else
  1156. {
  1157. (void) HrEnsureRouterManagerDeleted (c_rmiIp);
  1158. }
  1159. if (PnccIpx())
  1160. {
  1161. (void) HrEnsureRouterInterfaceForAdapter (
  1162. ROUTER_IF_TYPE_INTERNAL,
  1163. c_rmiIpx.dwPacketType,
  1164. m_swzInternal,
  1165. m_swzInternal,
  1166. c_rmiIpx);
  1167. }
  1168. else
  1169. {
  1170. (void) HrEnsureRouterManagerDeleted (c_rmiIpx);
  1171. }
  1172. (void) HrPassToAddInterfaces ();
  1173. (void) HrPassToRemoveInterfaces ();
  1174. #if (WINVER >= 0x0501)
  1175. (VOID) HrRemoveIPXRouterConfiguration();
  1176. //
  1177. // Remove IPX router Manager configuration
  1178. //
  1179. (VOID) HrEnsureRouterManagerDeleted(c_rmiIpx);
  1180. //
  1181. // Remove IPX keys under HKLM\Software\Microsoft\Router\CurrentVersion
  1182. //
  1183. hr = HrRegOpenKeyEx(
  1184. HKEY_LOCAL_MACHINE,
  1185. L"Software\\Microsoft\\Router\\CurrentVersion\\RouterManagers",
  1186. KEY_ALL_ACCESS,
  1187. &hKey
  1188. );
  1189. if (SUCCEEDED(hr))
  1190. {
  1191. (VOID) SHDeleteKey(hKey, L"Ipx");
  1192. RegCloseKey(hKey);
  1193. hKey = NULL;
  1194. }
  1195. //
  1196. // Remove IPX keys under HKLM\Software\Microsoft\IPXMibAgent
  1197. //
  1198. hr = HrRegOpenKeyEx(
  1199. HKEY_LOCAL_MACHINE,
  1200. L"Software\\Microsoft",
  1201. KEY_ALL_ACCESS,
  1202. &hKey
  1203. );
  1204. if (SUCCEEDED(hr))
  1205. {
  1206. (VOID) SHDeleteKey(hKey, L"IPXMibAgent");
  1207. RegCloseKey(hKey);
  1208. hKey = NULL;
  1209. }
  1210. //
  1211. // Remove keys for NWLNKFWD and NWLNKFLT
  1212. //
  1213. hr = HrRegOpenKeyEx(
  1214. HKEY_LOCAL_MACHINE,
  1215. L"System\\CurrentControlSet\Services",
  1216. KEY_ALL_ACCESS,
  1217. &hKey
  1218. );
  1219. if (SUCCEEDED(hr))
  1220. {
  1221. (VOID) SHDeleteKey(hKey, L"NwlnkFwd");
  1222. (VOID) SHDeleteKey(hKey, L"NwlnkFlt");
  1223. RegCloseKey(hKey);
  1224. hKey = NULL;
  1225. }
  1226. #endif
  1227. MprConfigServerDisconnect (m_hMprConfig);
  1228. m_hMprConfig = NULL;
  1229. }
  1230. TraceResult ("CSteelhead::HrUpdateRouterConfiguration", hr);
  1231. return hr;
  1232. }
  1233. #if (WINVER >= 0x0501)
  1234. //+---------------------------------------------------------------------------
  1235. //
  1236. // Member : CSteelhead::HrRemoveIPXRouterConfiguration
  1237. //
  1238. // Purpose: Updates the router configuration to remove all the IPX related
  1239. // configuration
  1240. //
  1241. // Arguments:
  1242. // fRouter - Remove from running instance of router
  1243. //
  1244. // Returns: S_OK or an error code.
  1245. //
  1246. // Author: vraman 17 April 2002
  1247. //
  1248. // Notes:
  1249. //
  1250. HRESULT
  1251. CSteelhead::HrRemoveIPXRouterConfiguration ()
  1252. {
  1253. HRESULT hr = S_OK;
  1254. MPR_INTERFACE_0 *ari0;
  1255. DWORD dwIfRead, dwIfTotal, dwIfTransRead, dwIfTransTotal;
  1256. HANDLE hIfTransport;
  1257. //
  1258. // Enumerate interfaces
  1259. //
  1260. hr = HrMprConfigInterfaceEnum(
  1261. m_hMprConfig,
  1262. 0,
  1263. reinterpret_cast<LPBYTE*>(&ari0),
  1264. -1,
  1265. &dwIfRead,
  1266. &dwIfTotal,
  1267. NULL
  1268. );
  1269. if (SUCCEEDED(hr))
  1270. {
  1271. for (MPR_INTERFACE_0 *pri0 = ari0; dwIfRead--; pri0++)
  1272. {
  1273. //
  1274. // For each interface, remove RRAS IPX config
  1275. //
  1276. hr = HrMprConfigInterfaceTransportGetHandle(
  1277. m_hMprConfig,
  1278. pri0->hInterface,
  1279. PID_IPX,
  1280. &hIfTransport
  1281. );
  1282. if (SUCCEEDED(hr))
  1283. {
  1284. hr = HrMprConfigInterfaceTransportRemove(
  1285. m_hMprConfig,
  1286. pri0->hInterface,
  1287. hIfTransport
  1288. );
  1289. }
  1290. }
  1291. }
  1292. TraceError ("CSteelhead::HrRemoveIPXRouterConfiguration", hr);
  1293. return hr;
  1294. }
  1295. #endif
  1296. //+---------------------------------------------------------------------------
  1297. // INetCfgComponentControl
  1298. //
  1299. STDMETHODIMP
  1300. CSteelhead::Initialize (
  1301. INetCfg* pnc)
  1302. {
  1303. // Validate_INetCfgNotify_Initialize (pncc, pnc, fInstalling);
  1304. // Hold on to our the component representing us and our host
  1305. // INetCfg object.
  1306. AddRefObj (m_pnc = pnc);
  1307. return S_OK;
  1308. }
  1309. #define PAD8(_p) (((ULONG_PTR)(_p) + ALIGN_SHIFT) & ALIGN_MASK)
  1310. //+---------------------------------------------------------------------------
  1311. //
  1312. // Function: MakeIpInterfaceInfo
  1313. //
  1314. // Purpose: Create the router interface block for IP.
  1315. //
  1316. // Arguments:
  1317. // pszwAdapterName [in] The adapter name
  1318. // dwPacketType [in] The packet type
  1319. // ppBuff [out] Pointer to the returned info.
  1320. // Free with delete.
  1321. //
  1322. // Returns: nothing
  1323. //
  1324. // Author: shaunco 28 Jul 1997
  1325. //
  1326. // Notes:
  1327. //
  1328. void MakeIpInterfaceInfo (
  1329. LPCWSTR pszwAdapterName,
  1330. DWORD dwPacketType,
  1331. LPBYTE* ppBuff)
  1332. {
  1333. UNREFERENCED_PARAMETER (pszwAdapterName);
  1334. UNREFERENCED_PARAMETER (dwPacketType);
  1335. Assert (ppBuff);
  1336. const int c_cTocEntries = 3;
  1337. // Alocate for minimal global Information.
  1338. //
  1339. DWORD dwSize = sizeof( RTR_INFO_BLOCK_HEADER )
  1340. // header contains one TOC_ENTRY already
  1341. + ((c_cTocEntries - 1) * sizeof( RTR_TOC_ENTRY ))
  1342. + sizeof( INTERFACE_STATUS_INFO )
  1343. + sizeof( RTR_DISC_INFO )
  1344. + (c_cTocEntries * ALIGN_SIZE);
  1345. PRTR_INFO_BLOCK_HEADER pIBH = (PRTR_INFO_BLOCK_HEADER) new BYTE [dwSize];
  1346. *ppBuff = (LPBYTE) pIBH;
  1347. if(pIBH == NULL)
  1348. return;
  1349. ZeroMemory (pIBH, dwSize);
  1350. // Initialize infobase fields.
  1351. //
  1352. pIBH->Version = RTR_INFO_BLOCK_VERSION;
  1353. pIBH->Size = dwSize;
  1354. pIBH->TocEntriesCount = c_cTocEntries;
  1355. LPBYTE pbDataPtr = (LPBYTE) &( pIBH-> TocEntry[ pIBH->TocEntriesCount ] );
  1356. pbDataPtr = (LPBYTE)PAD8(pbDataPtr);
  1357. PRTR_TOC_ENTRY pTocEntry = pIBH->TocEntry;
  1358. // Create empty route info block
  1359. //
  1360. pTocEntry->InfoType = IP_ROUTE_INFO;
  1361. pTocEntry->InfoSize = sizeof( MIB_IPFORWARDROW );
  1362. pTocEntry->Count = 0;
  1363. pTocEntry->Offset = (ULONG)(pbDataPtr - (LPBYTE)pIBH);
  1364. pbDataPtr += pTocEntry->Count * pTocEntry->InfoSize;
  1365. pbDataPtr = (LPBYTE)PAD8(pbDataPtr);
  1366. pTocEntry++;
  1367. // Create interface status block.
  1368. //
  1369. pTocEntry->InfoType = IP_INTERFACE_STATUS_INFO;
  1370. pTocEntry->InfoSize = sizeof( INTERFACE_STATUS_INFO );
  1371. pTocEntry->Count = 1;
  1372. pTocEntry->Offset = (ULONG)(pbDataPtr - (LPBYTE)pIBH);
  1373. PINTERFACE_STATUS_INFO pifStat = (PINTERFACE_STATUS_INFO)pbDataPtr;
  1374. pifStat->dwAdminStatus = MIB_IF_ADMIN_STATUS_UP;
  1375. pbDataPtr += pTocEntry->Count * pTocEntry->InfoSize;
  1376. pbDataPtr = (LPBYTE)PAD8(pbDataPtr);
  1377. pTocEntry++;
  1378. // Create Router Disc. Info.
  1379. //
  1380. pTocEntry->InfoType = IP_ROUTER_DISC_INFO;
  1381. pTocEntry->InfoSize = sizeof( RTR_DISC_INFO );
  1382. pTocEntry->Count = 1;
  1383. pTocEntry->Offset = (ULONG)(pbDataPtr - (LPBYTE)pIBH);
  1384. PRTR_DISC_INFO pRtrDisc = (PRTR_DISC_INFO)pbDataPtr;
  1385. pRtrDisc->bAdvertise = FALSE;
  1386. pRtrDisc->wMaxAdvtInterval = DEFAULT_MAX_ADVT_INTERVAL;
  1387. pRtrDisc->wMinAdvtInterval = (WORD)(DEFAULT_MIN_ADVT_INTERVAL_RATIO * DEFAULT_MAX_ADVT_INTERVAL);
  1388. pRtrDisc->wAdvtLifetime = DEFAULT_ADVT_LIFETIME_RATIO * DEFAULT_MAX_ADVT_INTERVAL;
  1389. pRtrDisc->lPrefLevel = DEFAULT_PREF_LEVEL;
  1390. }
  1391. //+---------------------------------------------------------------------------
  1392. //
  1393. // Function: MakeIpTransportInfo
  1394. //
  1395. // Purpose: Create the router transport blocks for IP. Free with delete.
  1396. //
  1397. // Arguments:
  1398. // ppBuffGlobal [out] Pointer to the returned global block.
  1399. // ppBuffClient [out] Pointer to the returned client block.
  1400. //
  1401. // Returns: nothing
  1402. //
  1403. // Author: shaunco 28 Jul 1997
  1404. //
  1405. // Notes:
  1406. //
  1407. void MakeIpTransportInfo (LPBYTE* ppBuffGlobal, LPBYTE* ppBuffClient)
  1408. {
  1409. Assert (ppBuffGlobal);
  1410. Assert (ppBuffClient);
  1411. *ppBuffClient = NULL;
  1412. const int c_cTocEntries = 2;
  1413. const int c_cProtocols = 7;
  1414. // Alocate for minimal global Information.
  1415. //
  1416. DWORD dwSize = sizeof( RTR_INFO_BLOCK_HEADER )
  1417. // header contains one TOC_ENTRY already
  1418. + ((c_cTocEntries - 1) * sizeof( RTR_TOC_ENTRY ))
  1419. + sizeof(GLOBAL_INFO)
  1420. + SIZEOF_PRIORITY_INFO(c_cProtocols)
  1421. + (c_cTocEntries * ALIGN_SIZE);
  1422. PRTR_INFO_BLOCK_HEADER pIBH = (PRTR_INFO_BLOCK_HEADER) new BYTE [dwSize];
  1423. *ppBuffGlobal = (LPBYTE) pIBH;
  1424. if(pIBH == NULL)
  1425. return;
  1426. ZeroMemory (pIBH, dwSize);
  1427. // Initialize infobase fields.
  1428. //
  1429. pIBH->Version = RTR_INFO_BLOCK_VERSION;
  1430. pIBH->Size = dwSize;
  1431. pIBH->TocEntriesCount = c_cTocEntries;
  1432. LPBYTE pbDataPtr = (LPBYTE) &( pIBH->TocEntry[ pIBH->TocEntriesCount ] );
  1433. pbDataPtr = (LPBYTE)PAD8(pbDataPtr);
  1434. PRTR_TOC_ENTRY pTocEntry = pIBH->TocEntry;
  1435. // Make IP router manager global info.
  1436. //
  1437. pTocEntry->InfoType = IP_GLOBAL_INFO;
  1438. pTocEntry->InfoSize = sizeof(GLOBAL_INFO);
  1439. pTocEntry->Count = 1;
  1440. pTocEntry->Offset = (int)(pbDataPtr - (PBYTE)pIBH);
  1441. PGLOBAL_INFO pGlbInfo = (PGLOBAL_INFO) pbDataPtr;
  1442. pGlbInfo->bFilteringOn = FALSE;
  1443. pGlbInfo->dwLoggingLevel = IPRTR_LOGGING_ERROR;
  1444. pbDataPtr += pTocEntry->Count * pTocEntry-> InfoSize;
  1445. pbDataPtr = (LPBYTE)PAD8(pbDataPtr);
  1446. pTocEntry++;
  1447. // Make IP router manager priority info.
  1448. //
  1449. pTocEntry->InfoType = IP_PROT_PRIORITY_INFO;
  1450. pTocEntry->InfoSize = SIZEOF_PRIORITY_INFO(c_cProtocols);
  1451. pTocEntry->Count = 1;
  1452. pTocEntry->Offset = (int)(pbDataPtr - (PBYTE)pIBH);
  1453. PPRIORITY_INFO pPriorInfo = (PPRIORITY_INFO) pbDataPtr;
  1454. pPriorInfo->dwNumProtocols = c_cProtocols;
  1455. pPriorInfo->ppmProtocolMetric[ 0 ].dwProtocolId = PROTO_IP_LOCAL;
  1456. pPriorInfo->ppmProtocolMetric[ 0 ].dwMetric = 1;
  1457. pPriorInfo->ppmProtocolMetric[ 1 ].dwProtocolId = PROTO_IP_NT_STATIC;
  1458. pPriorInfo->ppmProtocolMetric[ 1 ].dwMetric = 3;
  1459. pPriorInfo->ppmProtocolMetric[ 2 ].dwProtocolId = PROTO_IP_NT_STATIC_NON_DOD;
  1460. pPriorInfo->ppmProtocolMetric[ 2 ].dwMetric = 5;
  1461. pPriorInfo->ppmProtocolMetric[ 3 ].dwProtocolId = PROTO_IP_NT_AUTOSTATIC;
  1462. pPriorInfo->ppmProtocolMetric[ 3 ].dwMetric = 7;
  1463. pPriorInfo->ppmProtocolMetric[ 4 ].dwProtocolId = PROTO_IP_NETMGMT;
  1464. pPriorInfo->ppmProtocolMetric[ 4 ].dwMetric = 10;
  1465. pPriorInfo->ppmProtocolMetric[ 5 ].dwProtocolId = PROTO_IP_OSPF;
  1466. pPriorInfo->ppmProtocolMetric[ 5 ].dwMetric = 110;
  1467. pPriorInfo->ppmProtocolMetric[ 6 ].dwProtocolId = PROTO_IP_RIP;
  1468. pPriorInfo->ppmProtocolMetric[ 6 ].dwMetric = 120;
  1469. }
  1470. //+---------------------------------------------------------------------------
  1471. //
  1472. // Function: MakeIpxInterfaceInfo
  1473. //
  1474. // Purpose: Create the router interface block for IPX.
  1475. //
  1476. // Arguments:
  1477. // pszwAdapterName [in] The adapter name
  1478. // dwPacketType [in] The packet type
  1479. // ppBuff [out] Pointer to the returned info.
  1480. // Free with delete.
  1481. //
  1482. // Returns: nothing
  1483. //
  1484. // Author: shaunco 28 Jul 1997
  1485. //
  1486. // Notes:
  1487. //
  1488. void MakeIpxInterfaceInfo (
  1489. LPCWSTR pszwAdapterName,
  1490. DWORD dwPacketType,
  1491. LPBYTE* ppBuff)
  1492. {
  1493. Assert (ppBuff);
  1494. const BOOL fDialInInterface = (NULL == pszwAdapterName);
  1495. const int c_cTocEntries = 5;
  1496. // Alocate for minimal global Information.
  1497. //
  1498. DWORD dwSize = sizeof( RTR_INFO_BLOCK_HEADER )
  1499. // header contains one TOC_ENTRY already
  1500. + ((c_cTocEntries - 1) * sizeof( RTR_TOC_ENTRY ))
  1501. + sizeof(IPX_IF_INFO)
  1502. + sizeof(IPX_ADAPTER_INFO)
  1503. + sizeof(IPXWAN_IF_INFO)
  1504. + sizeof(RIP_IF_CONFIG)
  1505. + sizeof(SAP_IF_CONFIG)
  1506. + (c_cTocEntries * ALIGN_SIZE);
  1507. PRTR_INFO_BLOCK_HEADER pIBH = (PRTR_INFO_BLOCK_HEADER) new BYTE [dwSize];
  1508. *ppBuff = (LPBYTE) pIBH;
  1509. if(pIBH == NULL)
  1510. return;
  1511. ZeroMemory (pIBH, dwSize);
  1512. // Initialize infobase fields.
  1513. //
  1514. pIBH->Version = RTR_INFO_BLOCK_VERSION;
  1515. pIBH->Size = dwSize;
  1516. pIBH->TocEntriesCount = c_cTocEntries;
  1517. LPBYTE pbDataPtr = (LPBYTE) &( pIBH->TocEntry[ pIBH->TocEntriesCount ] );
  1518. pbDataPtr = (LPBYTE)PAD8(pbDataPtr);
  1519. PRTR_TOC_ENTRY pTocEntry = pIBH->TocEntry;
  1520. // Make IPX router manager interface info.
  1521. //
  1522. pTocEntry->InfoType = IPX_INTERFACE_INFO_TYPE;
  1523. pTocEntry->InfoSize = sizeof(IPX_IF_INFO);
  1524. pTocEntry->Count = 1;
  1525. pTocEntry->Offset = (int)(pbDataPtr - (PBYTE)pIBH);
  1526. PIPX_IF_INFO pIfInfo = (PIPX_IF_INFO) pbDataPtr;
  1527. pIfInfo->AdminState = ADMIN_STATE_ENABLED;
  1528. pIfInfo->NetbiosAccept = ADMIN_STATE_ENABLED;
  1529. pIfInfo->NetbiosDeliver = (fDialInInterface) ? ADMIN_STATE_DISABLED
  1530. : ADMIN_STATE_ENABLED;
  1531. pbDataPtr += pTocEntry->Count * pTocEntry->InfoSize;
  1532. pbDataPtr = (LPBYTE)PAD8(pbDataPtr);
  1533. pTocEntry++;
  1534. // Make adapter info.
  1535. //
  1536. pTocEntry->InfoType = IPX_ADAPTER_INFO_TYPE;
  1537. pTocEntry->InfoSize = sizeof(IPX_ADAPTER_INFO);
  1538. pTocEntry->Count = 1;
  1539. pTocEntry->Offset = (int)(pbDataPtr - (PBYTE)pIBH);
  1540. PIPX_ADAPTER_INFO pAdInfo = (PIPX_ADAPTER_INFO) pbDataPtr;
  1541. if (ISN_FRAME_TYPE_AUTO == dwPacketType)
  1542. {
  1543. dwPacketType = AUTO_DETECT_PACKET_TYPE;
  1544. }
  1545. pAdInfo->PacketType = dwPacketType;
  1546. if (pszwAdapterName)
  1547. {
  1548. AssertSz (lstrlen (pszwAdapterName) < celems (pAdInfo->AdapterName),
  1549. "Bindname too big for pAdInfo->AdapterName buffer.");
  1550. lstrcpy (pAdInfo->AdapterName, pszwAdapterName);
  1551. }
  1552. else
  1553. {
  1554. AssertSz (0 == pAdInfo->AdapterName[0],
  1555. "Who removed the ZeroMemory call above?");
  1556. }
  1557. pbDataPtr += pTocEntry->Count * pTocEntry->InfoSize;
  1558. pbDataPtr = (LPBYTE)PAD8(pbDataPtr);
  1559. pTocEntry++;
  1560. // Make wan info.
  1561. //
  1562. pTocEntry->InfoType = IPXWAN_INTERFACE_INFO_TYPE;
  1563. pTocEntry->InfoSize = sizeof(IPXWAN_IF_INFO);
  1564. pTocEntry->Count = 1;
  1565. pTocEntry->Offset = (int)(pbDataPtr - (PBYTE)pIBH);
  1566. PIPXWAN_IF_INFO pWanInfo = (PIPXWAN_IF_INFO) pbDataPtr;
  1567. pWanInfo->AdminState = ADMIN_STATE_DISABLED;
  1568. pbDataPtr += pTocEntry->Count * pTocEntry->InfoSize;
  1569. pbDataPtr = (LPBYTE)PAD8(pbDataPtr);
  1570. pTocEntry++;
  1571. // Make RIP interface info.
  1572. //
  1573. pTocEntry->InfoType = IPX_PROTOCOL_RIP;
  1574. pTocEntry->InfoSize = sizeof(RIP_IF_CONFIG);
  1575. pTocEntry->Count = 1;
  1576. pTocEntry->Offset = (int)(pbDataPtr - (PBYTE)pIBH);
  1577. PRIP_IF_CONFIG pRipInfo = (PRIP_IF_CONFIG) pbDataPtr;
  1578. pRipInfo->RipIfInfo.AdminState = ADMIN_STATE_ENABLED;
  1579. pRipInfo->RipIfInfo.UpdateMode = (fDialInInterface)
  1580. ? IPX_NO_UPDATE
  1581. : IPX_STANDARD_UPDATE;
  1582. pRipInfo->RipIfInfo.PacketType = IPX_STANDARD_PACKET_TYPE;
  1583. pRipInfo->RipIfInfo.Supply = ADMIN_STATE_ENABLED;
  1584. pRipInfo->RipIfInfo.Listen = ADMIN_STATE_ENABLED;
  1585. pRipInfo->RipIfInfo.PeriodicUpdateInterval = 60;
  1586. pRipInfo->RipIfInfo.AgeIntervalMultiplier = 3;
  1587. pRipInfo->RipIfFilters.SupplyFilterAction = IPX_ROUTE_FILTER_DENY;
  1588. pRipInfo->RipIfFilters.SupplyFilterCount = 0;
  1589. pRipInfo->RipIfFilters.ListenFilterAction = IPX_ROUTE_FILTER_DENY;
  1590. pRipInfo->RipIfFilters.ListenFilterCount = 0;
  1591. pbDataPtr += pTocEntry->Count * pTocEntry->InfoSize;
  1592. pbDataPtr = (LPBYTE)PAD8(pbDataPtr);
  1593. pTocEntry++;
  1594. // Make SAP interface info.
  1595. //
  1596. pTocEntry->InfoType = IPX_PROTOCOL_SAP;
  1597. pTocEntry->InfoSize = sizeof(SAP_IF_CONFIG);
  1598. pTocEntry->Count = 1;
  1599. pTocEntry->Offset = (int)(pbDataPtr - (PBYTE)pIBH);
  1600. PSAP_IF_CONFIG pSapInfo = (PSAP_IF_CONFIG) pbDataPtr;
  1601. pSapInfo->SapIfInfo.AdminState = ADMIN_STATE_ENABLED;
  1602. pSapInfo->SapIfInfo.UpdateMode = (fDialInInterface)
  1603. ? IPX_NO_UPDATE
  1604. : IPX_STANDARD_UPDATE;
  1605. pSapInfo->SapIfInfo.PacketType = IPX_STANDARD_PACKET_TYPE;
  1606. pSapInfo->SapIfInfo.Supply = ADMIN_STATE_ENABLED;
  1607. pSapInfo->SapIfInfo.Listen = ADMIN_STATE_ENABLED;
  1608. pSapInfo->SapIfInfo.GetNearestServerReply = ADMIN_STATE_ENABLED;
  1609. pSapInfo->SapIfInfo.PeriodicUpdateInterval = 60;
  1610. pSapInfo->SapIfInfo.AgeIntervalMultiplier = 3;
  1611. pSapInfo->SapIfFilters.SupplyFilterAction = IPX_SERVICE_FILTER_DENY;
  1612. pSapInfo->SapIfFilters.SupplyFilterCount = 0;
  1613. pSapInfo->SapIfFilters.ListenFilterAction = IPX_SERVICE_FILTER_DENY;
  1614. pSapInfo->SapIfFilters.ListenFilterCount = 0;
  1615. }
  1616. //+---------------------------------------------------------------------------
  1617. //
  1618. // Function: MakeIpxTransportInfo
  1619. //
  1620. // Purpose: Create the router transport blocks for IPX. Free with delete.
  1621. //
  1622. // Arguments:
  1623. // ppBuffGlobal [out] Pointer to the returned global block.
  1624. // ppBuffClient [out] Pointer to the returned client block.
  1625. //
  1626. // Returns: nothing
  1627. //
  1628. // Author: shaunco 28 Jul 1997
  1629. //
  1630. // Notes:
  1631. //
  1632. void MakeIpxTransportInfo (LPBYTE* ppBuffGlobal, LPBYTE* ppBuffClient)
  1633. {
  1634. Assert (ppBuffGlobal);
  1635. Assert (ppBuffClient);
  1636. MakeIpxInterfaceInfo (NULL, ISN_FRAME_TYPE_AUTO, ppBuffClient);
  1637. const int c_cTocEntries = 3;
  1638. // Alocate for minimal global Information.
  1639. //
  1640. DWORD dwSize = sizeof( RTR_INFO_BLOCK_HEADER )
  1641. // header contains one TOC_ENTRY already
  1642. + ((c_cTocEntries - 1) * sizeof( RTR_TOC_ENTRY ))
  1643. + sizeof(IPX_GLOBAL_INFO)
  1644. + sizeof(RIP_GLOBAL_INFO)
  1645. + sizeof(SAP_GLOBAL_INFO)
  1646. + (c_cTocEntries * ALIGN_SIZE);
  1647. PRTR_INFO_BLOCK_HEADER pIBH = (PRTR_INFO_BLOCK_HEADER) new BYTE [dwSize];
  1648. *ppBuffGlobal = (LPBYTE) pIBH;
  1649. if (pIBH == NULL)
  1650. return;
  1651. ZeroMemory (pIBH, dwSize);
  1652. // Initialize infobase fields.
  1653. //
  1654. pIBH->Version = RTR_INFO_BLOCK_VERSION;
  1655. pIBH->Size = dwSize;
  1656. pIBH->TocEntriesCount = c_cTocEntries;
  1657. LPBYTE pbDataPtr = (LPBYTE) &( pIBH->TocEntry[ pIBH->TocEntriesCount ] );
  1658. pbDataPtr = (LPBYTE)PAD8(pbDataPtr);
  1659. PRTR_TOC_ENTRY pTocEntry = pIBH->TocEntry;
  1660. // Make IPX router manager global info.
  1661. //
  1662. pTocEntry->InfoType = IPX_GLOBAL_INFO_TYPE;
  1663. pTocEntry->InfoSize = sizeof(IPX_GLOBAL_INFO);
  1664. pTocEntry->Count = 1;
  1665. pTocEntry->Offset = (int)(pbDataPtr - (PBYTE)pIBH);
  1666. PIPX_GLOBAL_INFO pGlbInfo = (PIPX_GLOBAL_INFO) pbDataPtr;
  1667. pGlbInfo->RoutingTableHashSize = IPX_MEDIUM_ROUTING_TABLE_HASH_SIZE;
  1668. pGlbInfo->EventLogMask = EVENTLOG_ERROR_TYPE;
  1669. pbDataPtr += pTocEntry->Count * pTocEntry->InfoSize;
  1670. pbDataPtr = (LPBYTE)PAD8(pbDataPtr);
  1671. pTocEntry++;
  1672. // Make RIP global info.
  1673. //
  1674. pTocEntry->InfoType = IPX_PROTOCOL_RIP;
  1675. pTocEntry->InfoSize = sizeof(RIP_GLOBAL_INFO);
  1676. pTocEntry->Count = 1;
  1677. pTocEntry->Offset = (int)(pbDataPtr - (PBYTE)pIBH);
  1678. PRIP_GLOBAL_INFO pRipInfo = (PRIP_GLOBAL_INFO) pbDataPtr;
  1679. pRipInfo->EventLogMask = EVENTLOG_ERROR_TYPE;
  1680. pbDataPtr += pTocEntry->Count * pTocEntry->InfoSize;
  1681. pbDataPtr = (LPBYTE)PAD8(pbDataPtr);
  1682. pTocEntry++;
  1683. // Make SAP global info.
  1684. //
  1685. pTocEntry->InfoType = IPX_PROTOCOL_SAP;
  1686. pTocEntry->InfoSize = sizeof(SAP_GLOBAL_INFO);
  1687. pTocEntry->Count = 1;
  1688. pTocEntry->Offset = (int)(pbDataPtr - (PBYTE)pIBH);
  1689. PSAP_GLOBAL_INFO pSapInfo = (PSAP_GLOBAL_INFO) pbDataPtr;
  1690. pSapInfo->EventLogMask = EVENTLOG_ERROR_TYPE;
  1691. }
  1692. //+---------------------------------------------------------------------------
  1693. //
  1694. // mprapi.h wrappers to return HRESULTs and obey rules of COM in regard
  1695. // to output parameters.
  1696. //
  1697. HRESULT
  1698. HrMprConfigServerConnect(
  1699. IN LPWSTR lpwsServerName,
  1700. OUT HANDLE* phMprConfig
  1701. )
  1702. {
  1703. HRESULT hr = S_OK;
  1704. DWORD dw = MprConfigServerConnect (lpwsServerName, phMprConfig);
  1705. if (NO_ERROR != dw)
  1706. {
  1707. hr = HRESULT_FROM_WIN32 (dw);
  1708. *phMprConfig = NULL;
  1709. }
  1710. TraceError ("HrMprConfigServerConnect", hr);
  1711. return hr;
  1712. }
  1713. HRESULT
  1714. HrMprConfigInterfaceCreate(
  1715. IN HANDLE hMprConfig,
  1716. IN DWORD dwLevel,
  1717. IN LPBYTE lpbBuffer,
  1718. OUT HANDLE* phRouterInterface
  1719. )
  1720. {
  1721. HRESULT hr = S_OK;
  1722. DWORD dw = MprConfigInterfaceCreate (hMprConfig, dwLevel, lpbBuffer,
  1723. phRouterInterface);
  1724. if (NO_ERROR != dw)
  1725. {
  1726. hr = HRESULT_FROM_WIN32 (dw);
  1727. *phRouterInterface = NULL;
  1728. }
  1729. TraceErrorOptional ("HrMprConfigInterfaceCreate", hr,
  1730. (HRESULT_FROM_WIN32(ERROR_NO_SUCH_INTERFACE) == hr));
  1731. return hr;
  1732. }
  1733. HRESULT
  1734. HrMprConfigInterfaceEnum(
  1735. IN HANDLE hMprConfig,
  1736. IN DWORD dwLevel,
  1737. IN OUT LPBYTE* lplpBuffer,
  1738. IN DWORD dwPrefMaxLen,
  1739. OUT LPDWORD lpdwEntriesRead,
  1740. OUT LPDWORD lpdwTotalEntries,
  1741. IN OUT LPDWORD lpdwResumeHandle OPTIONAL
  1742. )
  1743. {
  1744. HRESULT hr = S_OK;
  1745. DWORD dw = MprConfigInterfaceEnum (hMprConfig, dwLevel, lplpBuffer,
  1746. dwPrefMaxLen, lpdwEntriesRead,
  1747. lpdwTotalEntries, lpdwResumeHandle);
  1748. if (NO_ERROR != dw)
  1749. {
  1750. hr = HRESULT_FROM_WIN32 (dw);
  1751. *lpdwEntriesRead = 0;
  1752. *lpdwTotalEntries = 0;
  1753. }
  1754. TraceErrorOptional ("HrMprConfigInterfaceCreate", hr,
  1755. (HRESULT_FROM_WIN32(ERROR_NO_MORE_ITEMS) == hr));
  1756. return hr;
  1757. }
  1758. HRESULT
  1759. HrMprConfigInterfaceTransportEnum(
  1760. IN HANDLE hMprConfig,
  1761. IN HANDLE hRouterInterface,
  1762. IN DWORD dwLevel,
  1763. IN OUT LPBYTE* lplpBuffer, // MPR_IFTRANSPORT_0
  1764. IN DWORD dwPrefMaxLen,
  1765. OUT LPDWORD lpdwEntriesRead,
  1766. OUT LPDWORD lpdwTotalEntries,
  1767. IN OUT LPDWORD lpdwResumeHandle OPTIONAL
  1768. )
  1769. {
  1770. HRESULT hr = S_OK;
  1771. DWORD dw = MprConfigInterfaceTransportEnum (hMprConfig, hRouterInterface,
  1772. dwLevel, lplpBuffer,
  1773. dwPrefMaxLen, lpdwEntriesRead,
  1774. lpdwTotalEntries, lpdwResumeHandle);
  1775. if (NO_ERROR != dw)
  1776. {
  1777. hr = HRESULT_FROM_WIN32 (dw);
  1778. *lpdwEntriesRead = 0;
  1779. *lpdwTotalEntries = 0;
  1780. }
  1781. TraceErrorOptional ("HrMprConfigInterfaceTransportEnum", hr,
  1782. (HRESULT_FROM_WIN32(ERROR_NO_MORE_ITEMS) == hr));
  1783. return hr;
  1784. }
  1785. HRESULT
  1786. HrMprConfigInterfaceGetHandle(
  1787. IN HANDLE hMprConfig,
  1788. IN LPWSTR lpwsInterfaceName,
  1789. OUT HANDLE* phRouterInterface
  1790. )
  1791. {
  1792. HRESULT hr = S_OK;
  1793. DWORD dw = MprConfigInterfaceGetHandle (hMprConfig, lpwsInterfaceName,
  1794. phRouterInterface);
  1795. if (NO_ERROR != dw)
  1796. {
  1797. hr = HRESULT_FROM_WIN32 (dw);
  1798. *phRouterInterface = NULL;
  1799. }
  1800. TraceErrorOptional ("HrMprConfigInterfaceGetHandle", hr,
  1801. (HRESULT_FROM_WIN32(ERROR_NO_SUCH_INTERFACE) == hr));
  1802. return hr;
  1803. }
  1804. HRESULT
  1805. HrMprConfigInterfaceTransportAdd(
  1806. IN HANDLE hMprConfig,
  1807. IN HANDLE hRouterInterface,
  1808. IN DWORD dwTransportId,
  1809. IN LPWSTR lpwsTransportName OPTIONAL,
  1810. IN LPBYTE pInterfaceInfo,
  1811. IN DWORD dwInterfaceInfoSize,
  1812. OUT HANDLE* phRouterIfTransport
  1813. )
  1814. {
  1815. HRESULT hr = S_OK;
  1816. DWORD dw = MprConfigInterfaceTransportAdd (hMprConfig, hRouterInterface,
  1817. dwTransportId, lpwsTransportName,
  1818. pInterfaceInfo, dwInterfaceInfoSize,
  1819. phRouterIfTransport);
  1820. if (NO_ERROR != dw)
  1821. {
  1822. hr = HRESULT_FROM_WIN32 (dw);
  1823. *phRouterIfTransport = NULL;
  1824. }
  1825. TraceError ("HrMprConfigInterfaceTransportAdd", hr);
  1826. return hr;
  1827. }
  1828. HRESULT
  1829. HrMprConfigInterfaceTransportRemove(
  1830. IN HANDLE hMprConfig,
  1831. IN HANDLE hRouterInterface,
  1832. IN HANDLE hRouterIfTransport
  1833. )
  1834. {
  1835. HRESULT hr = S_OK;
  1836. DWORD dw = MprConfigInterfaceTransportRemove(hMprConfig, hRouterInterface,
  1837. hRouterIfTransport);
  1838. if (dw)
  1839. {
  1840. hr = HRESULT_FROM_WIN32 (dw);
  1841. }
  1842. TraceErrorOptional ("HrMprConfigInterfaceTransportRemove", hr, FALSE);
  1843. return hr;
  1844. }
  1845. HRESULT
  1846. HrMprConfigInterfaceTransportGetHandle(
  1847. IN HANDLE hMprConfig,
  1848. IN HANDLE hRouterInterface,
  1849. IN DWORD dwTransportId,
  1850. OUT HANDLE* phRouterIfTransport
  1851. )
  1852. {
  1853. HRESULT hr = S_OK;
  1854. DWORD dw = MprConfigInterfaceTransportGetHandle (hMprConfig,
  1855. hRouterInterface,
  1856. dwTransportId,
  1857. phRouterIfTransport);
  1858. if (NO_ERROR != dw)
  1859. {
  1860. hr = HRESULT_FROM_WIN32 (dw);
  1861. *phRouterIfTransport = NULL;
  1862. }
  1863. TraceErrorOptional ("HrMprConfigInterfaceTransportAdd", hr,
  1864. (HRESULT_FROM_WIN32(ERROR_NO_SUCH_INTERFACE) == hr));
  1865. return hr;
  1866. }
  1867. HRESULT
  1868. HrMprConfigTransportCreate(
  1869. IN HANDLE hMprConfig,
  1870. IN DWORD dwTransportId,
  1871. IN LPWSTR lpwsTransportName OPTIONAL,
  1872. IN LPBYTE pGlobalInfo,
  1873. IN DWORD dwGlobalInfoSize,
  1874. IN LPBYTE pClientInterfaceInfo OPTIONAL,
  1875. IN DWORD dwClientInterfaceInfoSize OPTIONAL,
  1876. IN LPWSTR lpwsDLLPath,
  1877. OUT HANDLE* phRouterTransport
  1878. )
  1879. {
  1880. HRESULT hr = S_OK;
  1881. DWORD dw = MprConfigTransportCreate (hMprConfig, dwTransportId,
  1882. lpwsTransportName, pGlobalInfo, dwGlobalInfoSize,
  1883. pClientInterfaceInfo, dwClientInterfaceInfoSize,
  1884. lpwsDLLPath, phRouterTransport);
  1885. if (NO_ERROR != dw)
  1886. {
  1887. hr = HRESULT_FROM_WIN32 (dw);
  1888. *phRouterTransport = NULL;
  1889. }
  1890. TraceError ("HrMprConfigTransportCreate", hr);
  1891. return hr;
  1892. }
  1893. HRESULT
  1894. HrMprConfigTransportDelete(
  1895. IN HANDLE hMprConfig,
  1896. IN HANDLE hRouterTransport)
  1897. {
  1898. HRESULT hr = S_OK;
  1899. DWORD dw = MprConfigTransportDelete (hMprConfig, hRouterTransport);
  1900. if (NO_ERROR != dw)
  1901. {
  1902. hr = HRESULT_FROM_WIN32 (dw);
  1903. }
  1904. TraceError ("HrMprConfigTransportDelete", hr);
  1905. return hr;
  1906. }
  1907. HRESULT
  1908. HrMprConfigTransportGetHandle(
  1909. IN HANDLE hMprConfig,
  1910. IN DWORD dwTransportId,
  1911. OUT HANDLE* phRouterTransport
  1912. )
  1913. {
  1914. HRESULT hr = S_OK;
  1915. DWORD dw = MprConfigTransportGetHandle (hMprConfig, dwTransportId,
  1916. phRouterTransport);
  1917. if (NO_ERROR != dw)
  1918. {
  1919. hr = HRESULT_FROM_WIN32 (dw);
  1920. *phRouterTransport = NULL;
  1921. }
  1922. TraceError ("HrMprConfigTransportGetHandle",
  1923. (HRESULT_FROM_WIN32 (ERROR_UNKNOWN_PROTOCOL_ID) == hr)
  1924. ? S_OK : hr);
  1925. return hr;
  1926. }
  1927. HRESULT
  1928. HrMprConfigTransportGetInfo(
  1929. IN HANDLE hMprConfig,
  1930. IN HANDLE hRouterTransport,
  1931. IN OUT LPBYTE* ppGlobalInfo OPTIONAL,
  1932. OUT LPDWORD lpdwGlobalInfoSize OPTIONAL,
  1933. IN OUT LPBYTE* ppClientInterfaceInfo OPTIONAL,
  1934. OUT LPDWORD lpdwClientInterfaceInfoSize OPTIONAL,
  1935. IN OUT LPWSTR* lplpwsDLLPath OPTIONAL
  1936. )
  1937. {
  1938. HRESULT hr = S_OK;
  1939. DWORD dw = MprConfigTransportGetInfo (hMprConfig, hRouterTransport,
  1940. ppGlobalInfo, lpdwGlobalInfoSize,
  1941. ppClientInterfaceInfo,
  1942. lpdwClientInterfaceInfoSize,
  1943. lplpwsDLLPath);
  1944. if (NO_ERROR != dw)
  1945. {
  1946. hr = HRESULT_FROM_WIN32 (dw);
  1947. }
  1948. TraceError ("HrMprConfigTransportGetInfo", hr);
  1949. return hr;
  1950. }