Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2015 lines
62 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. hr = HrEnsureIpxRouterInterfacesForAdapter (pszwBindName);
  847. }
  848. ReleaseObj (pnccBindingsIpx);
  849. pnccBindingsIpx = NULL;
  850. CoTaskMemFree(pszwBindName);
  851. }
  852. ReleaseObj (pnccAdapter);
  853. pnccAdapter = NULL;
  854. }
  855. // Normalize the HRESULT. (i.e. don't return S_FALSE)
  856. if (S_FALSE == hr)
  857. {
  858. hr = S_OK;
  859. }
  860. TraceResult ("CSteelhead::HrPassToAddInterfaces", hr);
  861. return hr;
  862. }
  863. //+---------------------------------------------------------------------------
  864. //
  865. // Member: CSteelhead::HrPassToRemoveInterfaces
  866. //
  867. // Purpose:
  868. //
  869. // Arguments:
  870. // (none)
  871. //
  872. // Returns:
  873. //
  874. // Author: shaunco 27 Aug 1997
  875. //
  876. // Notes:
  877. //
  878. HRESULT
  879. CSteelhead::HrPassToRemoveInterfaces ()
  880. {
  881. // Enumerate all of the installed router interfaces.
  882. //
  883. MPR_INTERFACE_0* ari0;
  884. DWORD dwEntriesRead;
  885. DWORD dwTotalEntries;
  886. HRESULT hr = HrMprConfigInterfaceEnum (m_hMprConfig, 0,
  887. reinterpret_cast<LPBYTE*>(&ari0),
  888. -1, &dwEntriesRead, &dwTotalEntries, NULL);
  889. if (SUCCEEDED(hr))
  890. {
  891. // By passing -1, we want everything, so we should get everything.
  892. Assert (dwEntriesRead == dwTotalEntries);
  893. // Iterate all of the interfaces.
  894. //
  895. for (MPR_INTERFACE_0* pri0 = ari0; dwEntriesRead--; pri0++)
  896. {
  897. BOOL fDeleteInterface = FALSE;
  898. // If its the internal interface and IP and IPX are no longer
  899. // installed delete the interface.
  900. //
  901. if ((ROUTER_IF_TYPE_INTERNAL == pri0->dwIfType) &&
  902. !PnccIpx() && !PnccIp() &&
  903. (0 == lstrcmpW (pri0->wszInterfaceName, m_swzInternal)))
  904. {
  905. fDeleteInterface = TRUE;
  906. }
  907. else if (ROUTER_IF_TYPE_DEDICATED != pri0->dwIfType)
  908. {
  909. // Skip non-dedicated interfaces.
  910. //
  911. continue;
  912. }
  913. BOOL fSpecialIpxInterface = FALSE;
  914. INetCfgComponent* pnccAdapter = NULL;
  915. // Get the name of the interface and look for a '/' separator.
  916. // If present, it means this is a special IPX interface where
  917. // the first substring is the adapter name, and the second
  918. // substring is the frame type.
  919. //
  920. WCHAR* pchwSep = wcschr (pri0->wszInterfaceName, L'/');
  921. if (!fDeleteInterface && pchwSep)
  922. {
  923. fSpecialIpxInterface = TRUE;
  924. // Point to the frame type string.
  925. //
  926. LPCWSTR pszwFrameType = pchwSep;
  927. // Copy the adapter name into its own buffer.
  928. //
  929. WCHAR szwAdapterName [MAX_INTERFACE_NAME_LEN+1];
  930. lstrcpynW (szwAdapterName, pri0->wszInterfaceName,
  931. (int)(pchwSep - pri0->wszInterfaceName + 1));
  932. // If the frame type is not in use for the adapter, we need
  933. // to delete this interface. This condition happens when
  934. // IPX configuration is changed and the frame type is removed
  935. // from the adapter.
  936. //
  937. if (!FIpxFrameTypeInUseOnAdapter (pszwFrameType,
  938. szwAdapterName))
  939. {
  940. fDeleteInterface = TRUE;
  941. }
  942. }
  943. // Its not a special interface, so just make sure an adapter
  944. // exists with a matching bind name. If not, we will delete
  945. // the interface.
  946. //
  947. else if (!fDeleteInterface)
  948. {
  949. if (!FAdapterExistsWithMatchingBindName (
  950. pri0->wszInterfaceName,
  951. &pnccAdapter))
  952. {
  953. fDeleteInterface = TRUE;
  954. }
  955. }
  956. // Delete the interface if we need to.
  957. //
  958. if (fDeleteInterface)
  959. {
  960. MprConfigInterfaceDelete (m_hMprConfig, pri0->hInterface);
  961. }
  962. // If we don't need to delete the entire interface, check
  963. // for transports on the interface that we may need to delete.
  964. //
  965. else
  966. {
  967. // If its not an IPX special interface, the adapter
  968. // is the interface name. If it is an IPX special
  969. // interface, then we would have already remove the entire
  970. // interfce above if it were invalid.
  971. //
  972. (void) HrPassToRemoveInterfaceTransports (
  973. pri0,
  974. (!fSpecialIpxInterface) ? pri0->wszInterfaceName
  975. : NULL,
  976. pnccAdapter);
  977. }
  978. ReleaseObj (pnccAdapter);
  979. pnccAdapter = NULL;
  980. }
  981. MprConfigBufferFree (ari0);
  982. }
  983. else if (HRESULT_FROM_WIN32(ERROR_NO_MORE_ITEMS) == hr)
  984. {
  985. hr = S_OK;
  986. }
  987. TraceResult ("CSteelhead::HrPassToRemoveInterfaces", hr);
  988. return hr;
  989. }
  990. //+---------------------------------------------------------------------------
  991. //
  992. // Member: CSteelhead::HrPassToRemoveInterfaceTransports
  993. //
  994. // Purpose:
  995. //
  996. // Arguments:
  997. // hInterface []
  998. // pszwAdapterName []
  999. //
  1000. // Returns:
  1001. //
  1002. // Author: shaunco 27 Aug 1997
  1003. //
  1004. // Notes:
  1005. //
  1006. HRESULT
  1007. CSteelhead::HrPassToRemoveInterfaceTransports (
  1008. MPR_INTERFACE_0* pri0,
  1009. LPCWSTR pszwAdapterName,
  1010. INetCfgComponent* pnccAdapter)
  1011. {
  1012. // Assert (FImplies(pnccAdapter, pszwAdapterName));
  1013. // Enumerate all of the transports active on the router interface.
  1014. //
  1015. MPR_IFTRANSPORT_0* arit0;
  1016. DWORD dwEntriesRead;
  1017. DWORD dwTotalEntries;
  1018. HRESULT hr = HrMprConfigInterfaceTransportEnum (m_hMprConfig,
  1019. pri0->hInterface, 0,
  1020. reinterpret_cast<LPBYTE*>(&arit0),
  1021. -1, &dwEntriesRead, &dwTotalEntries, NULL);
  1022. if (SUCCEEDED(hr))
  1023. {
  1024. // By passing -1, we want everything, so we should get everything.
  1025. Assert (dwEntriesRead == dwTotalEntries);
  1026. INetCfgComponentBindings* pnccBindingsIpx = NULL;
  1027. INetCfgComponentBindings* pnccBindingsIp = NULL;
  1028. if (PnccIp())
  1029. {
  1030. hr = PnccIp()->QueryInterface (IID_INetCfgComponentBindings,
  1031. reinterpret_cast<void**>(&pnccBindingsIp));
  1032. }
  1033. if (SUCCEEDED(hr))
  1034. {
  1035. if (PnccIpx())
  1036. {
  1037. hr = PnccIpx()->QueryInterface (IID_INetCfgComponentBindings,
  1038. reinterpret_cast<void**>(&pnccBindingsIpx));
  1039. }
  1040. if (SUCCEEDED(hr))
  1041. {
  1042. // Iterate all of the transports.
  1043. //
  1044. for (MPR_IFTRANSPORT_0* prit0 = arit0; dwEntriesRead--; prit0++)
  1045. {
  1046. BOOL fDeleteInterfaceTransport = FALSE;
  1047. if (prit0->dwTransportId == c_rmiIp.dwTransportId)
  1048. {
  1049. if (!PnccIp())
  1050. {
  1051. fDeleteInterfaceTransport = TRUE;
  1052. }
  1053. else if (pnccAdapter &&
  1054. (S_OK != (hr = pnccBindingsIp->IsBoundTo (pnccAdapter))))
  1055. {
  1056. fDeleteInterfaceTransport = TRUE;
  1057. }
  1058. }
  1059. else if (prit0->dwTransportId == c_rmiIpx.dwTransportId)
  1060. {
  1061. if (!PnccIpx())
  1062. {
  1063. fDeleteInterfaceTransport = TRUE;
  1064. }
  1065. else if (pnccAdapter &&
  1066. (S_OK != (hr = pnccBindingsIpx->IsBoundTo (pnccAdapter))))
  1067. {
  1068. fDeleteInterfaceTransport = TRUE;
  1069. }
  1070. else if (pszwAdapterName)
  1071. {
  1072. Assert (PnccIpx());
  1073. // if frame type is not auto on this adapter, delete
  1074. // the transport
  1075. if (!FIpxFrameTypeInUseOnAdapter (ISN_FRAME_TYPE_AUTO,
  1076. pszwAdapterName))
  1077. {
  1078. fDeleteInterfaceTransport = TRUE;
  1079. }
  1080. }
  1081. }
  1082. if (fDeleteInterfaceTransport)
  1083. {
  1084. MprConfigInterfaceTransportRemove (
  1085. m_hMprConfig,
  1086. pri0->hInterface,
  1087. prit0->hIfTransport);
  1088. }
  1089. }
  1090. MprConfigBufferFree (arit0);
  1091. ReleaseObj (pnccBindingsIpx);
  1092. pnccBindingsIpx = NULL;
  1093. }
  1094. ReleaseObj (pnccBindingsIp);
  1095. pnccBindingsIp = NULL;
  1096. }
  1097. }
  1098. else if (HRESULT_FROM_WIN32(ERROR_NO_MORE_ITEMS) == hr)
  1099. {
  1100. // If there are no transports for this interface, that's okay.
  1101. //
  1102. hr = S_OK;
  1103. }
  1104. TraceResult ("CSteelhead::HrPassToRemoveInterfaceTransports", hr);
  1105. return hr;
  1106. }
  1107. //+---------------------------------------------------------------------------
  1108. //
  1109. // Member: CSteelhead::HrUpdateRouterConfiguration
  1110. //
  1111. // Purpose: Updates the router configuration by ensuring router managers
  1112. // are installed for the protocols present on the system (IP and
  1113. // IPX). Further, router interfaces are created for each
  1114. // physical netcard present on the system.
  1115. //
  1116. // Arguments:
  1117. // (none)
  1118. //
  1119. // Returns: S_OK or an error code.
  1120. //
  1121. // Author: shaunco 28 Jul 1997
  1122. //
  1123. // Notes:
  1124. //
  1125. HRESULT
  1126. CSteelhead::HrUpdateRouterConfiguration ()
  1127. {
  1128. Assert (!m_hMprConfig);
  1129. HRESULT hr = HrMprConfigServerConnect (NULL, &m_hMprConfig);
  1130. if (SUCCEEDED(hr))
  1131. {
  1132. // Ensure router managers are installed for the protocols
  1133. // we know about. Good to do this in case no physical adapters.
  1134. // are found below. We actually do this by ensuring the internal
  1135. // interface exists. This will implicitly ensure the router
  1136. // manger is created.
  1137. //
  1138. if (PnccIp())
  1139. {
  1140. (void) HrEnsureRouterInterfaceForAdapter (
  1141. ROUTER_IF_TYPE_LOOPBACK,
  1142. c_rmiIp.dwPacketType,
  1143. m_swzLoopback,
  1144. m_swzLoopback,
  1145. c_rmiIp);
  1146. (void) HrEnsureRouterInterfaceForAdapter (
  1147. ROUTER_IF_TYPE_INTERNAL,
  1148. c_rmiIp.dwPacketType,
  1149. m_swzInternal,
  1150. m_swzInternal,
  1151. c_rmiIp);
  1152. }
  1153. else
  1154. {
  1155. (void) HrEnsureRouterManagerDeleted (c_rmiIp);
  1156. }
  1157. if (PnccIpx())
  1158. {
  1159. (void) HrEnsureRouterInterfaceForAdapter (
  1160. ROUTER_IF_TYPE_INTERNAL,
  1161. c_rmiIpx.dwPacketType,
  1162. m_swzInternal,
  1163. m_swzInternal,
  1164. c_rmiIpx);
  1165. }
  1166. else
  1167. {
  1168. (void) HrEnsureRouterManagerDeleted (c_rmiIpx);
  1169. }
  1170. (void) HrPassToAddInterfaces ();
  1171. (void) HrPassToRemoveInterfaces ();
  1172. MprConfigServerDisconnect (m_hMprConfig);
  1173. m_hMprConfig = NULL;
  1174. }
  1175. TraceResult ("CSteelhead::HrUpdateRouterConfiguration", hr);
  1176. return hr;
  1177. }
  1178. //+---------------------------------------------------------------------------
  1179. // INetCfgComponentControl
  1180. //
  1181. STDMETHODIMP
  1182. CSteelhead::Initialize (
  1183. INetCfg* pnc)
  1184. {
  1185. // Validate_INetCfgNotify_Initialize (pncc, pnc, fInstalling);
  1186. // Hold on to our the component representing us and our host
  1187. // INetCfg object.
  1188. AddRefObj (m_pnc = pnc);
  1189. return S_OK;
  1190. }
  1191. #define PAD8(_p) (((ULONG_PTR)(_p) + ALIGN_SHIFT) & ALIGN_MASK)
  1192. //+---------------------------------------------------------------------------
  1193. //
  1194. // Function: MakeIpInterfaceInfo
  1195. //
  1196. // Purpose: Create the router interface block for IP.
  1197. //
  1198. // Arguments:
  1199. // pszwAdapterName [in] The adapter name
  1200. // dwPacketType [in] The packet type
  1201. // ppBuff [out] Pointer to the returned info.
  1202. // Free with delete.
  1203. //
  1204. // Returns: nothing
  1205. //
  1206. // Author: shaunco 28 Jul 1997
  1207. //
  1208. // Notes:
  1209. //
  1210. void MakeIpInterfaceInfo (
  1211. LPCWSTR pszwAdapterName,
  1212. DWORD dwPacketType,
  1213. LPBYTE* ppBuff)
  1214. {
  1215. UNREFERENCED_PARAMETER (pszwAdapterName);
  1216. UNREFERENCED_PARAMETER (dwPacketType);
  1217. Assert (ppBuff);
  1218. const int c_cTocEntries = 3;
  1219. // Alocate for minimal global Information.
  1220. //
  1221. DWORD dwSize = sizeof( RTR_INFO_BLOCK_HEADER )
  1222. // header contains one TOC_ENTRY already
  1223. + ((c_cTocEntries - 1) * sizeof( RTR_TOC_ENTRY ))
  1224. + sizeof( INTERFACE_STATUS_INFO )
  1225. + sizeof( RTR_DISC_INFO )
  1226. + (c_cTocEntries * ALIGN_SIZE);
  1227. PRTR_INFO_BLOCK_HEADER pIBH = (PRTR_INFO_BLOCK_HEADER) new BYTE [dwSize];
  1228. *ppBuff = (LPBYTE) pIBH;
  1229. if(pIBH == NULL)
  1230. return;
  1231. ZeroMemory (pIBH, dwSize);
  1232. // Initialize infobase fields.
  1233. //
  1234. pIBH->Version = RTR_INFO_BLOCK_VERSION;
  1235. pIBH->Size = dwSize;
  1236. pIBH->TocEntriesCount = c_cTocEntries;
  1237. LPBYTE pbDataPtr = (LPBYTE) &( pIBH-> TocEntry[ pIBH->TocEntriesCount ] );
  1238. pbDataPtr = (LPBYTE)PAD8(pbDataPtr);
  1239. PRTR_TOC_ENTRY pTocEntry = pIBH->TocEntry;
  1240. // Create empty route info block
  1241. //
  1242. pTocEntry->InfoType = IP_ROUTE_INFO;
  1243. pTocEntry->InfoSize = sizeof( MIB_IPFORWARDROW );
  1244. pTocEntry->Count = 0;
  1245. pTocEntry->Offset = (ULONG)(pbDataPtr - (LPBYTE)pIBH);
  1246. pbDataPtr += pTocEntry->Count * pTocEntry->InfoSize;
  1247. pbDataPtr = (LPBYTE)PAD8(pbDataPtr);
  1248. pTocEntry++;
  1249. // Create interface status block.
  1250. //
  1251. pTocEntry->InfoType = IP_INTERFACE_STATUS_INFO;
  1252. pTocEntry->InfoSize = sizeof( INTERFACE_STATUS_INFO );
  1253. pTocEntry->Count = 1;
  1254. pTocEntry->Offset = (ULONG)(pbDataPtr - (LPBYTE)pIBH);
  1255. PINTERFACE_STATUS_INFO pifStat = (PINTERFACE_STATUS_INFO)pbDataPtr;
  1256. pifStat->dwAdminStatus = MIB_IF_ADMIN_STATUS_UP;
  1257. pbDataPtr += pTocEntry->Count * pTocEntry->InfoSize;
  1258. pbDataPtr = (LPBYTE)PAD8(pbDataPtr);
  1259. pTocEntry++;
  1260. // Create Router Disc. Info.
  1261. //
  1262. pTocEntry->InfoType = IP_ROUTER_DISC_INFO;
  1263. pTocEntry->InfoSize = sizeof( RTR_DISC_INFO );
  1264. pTocEntry->Count = 1;
  1265. pTocEntry->Offset = (ULONG)(pbDataPtr - (LPBYTE)pIBH);
  1266. PRTR_DISC_INFO pRtrDisc = (PRTR_DISC_INFO)pbDataPtr;
  1267. pRtrDisc->bAdvertise = FALSE;
  1268. pRtrDisc->wMaxAdvtInterval = DEFAULT_MAX_ADVT_INTERVAL;
  1269. pRtrDisc->wMinAdvtInterval = (WORD)(DEFAULT_MIN_ADVT_INTERVAL_RATIO * DEFAULT_MAX_ADVT_INTERVAL);
  1270. pRtrDisc->wAdvtLifetime = DEFAULT_ADVT_LIFETIME_RATIO * DEFAULT_MAX_ADVT_INTERVAL;
  1271. pRtrDisc->lPrefLevel = DEFAULT_PREF_LEVEL;
  1272. }
  1273. //+---------------------------------------------------------------------------
  1274. //
  1275. // Function: MakeIpTransportInfo
  1276. //
  1277. // Purpose: Create the router transport blocks for IP. Free with delete.
  1278. //
  1279. // Arguments:
  1280. // ppBuffGlobal [out] Pointer to the returned global block.
  1281. // ppBuffClient [out] Pointer to the returned client block.
  1282. //
  1283. // Returns: nothing
  1284. //
  1285. // Author: shaunco 28 Jul 1997
  1286. //
  1287. // Notes:
  1288. //
  1289. void MakeIpTransportInfo (LPBYTE* ppBuffGlobal, LPBYTE* ppBuffClient)
  1290. {
  1291. Assert (ppBuffGlobal);
  1292. Assert (ppBuffClient);
  1293. *ppBuffClient = NULL;
  1294. const int c_cTocEntries = 2;
  1295. const int c_cProtocols = 7;
  1296. // Alocate for minimal global Information.
  1297. //
  1298. DWORD dwSize = sizeof( RTR_INFO_BLOCK_HEADER )
  1299. // header contains one TOC_ENTRY already
  1300. + ((c_cTocEntries - 1) * sizeof( RTR_TOC_ENTRY ))
  1301. + sizeof(GLOBAL_INFO)
  1302. + SIZEOF_PRIORITY_INFO(c_cProtocols)
  1303. + (c_cTocEntries * ALIGN_SIZE);
  1304. PRTR_INFO_BLOCK_HEADER pIBH = (PRTR_INFO_BLOCK_HEADER) new BYTE [dwSize];
  1305. *ppBuffGlobal = (LPBYTE) pIBH;
  1306. if(pIBH == NULL)
  1307. return;
  1308. ZeroMemory (pIBH, dwSize);
  1309. // Initialize infobase fields.
  1310. //
  1311. pIBH->Version = RTR_INFO_BLOCK_VERSION;
  1312. pIBH->Size = dwSize;
  1313. pIBH->TocEntriesCount = c_cTocEntries;
  1314. LPBYTE pbDataPtr = (LPBYTE) &( pIBH->TocEntry[ pIBH->TocEntriesCount ] );
  1315. pbDataPtr = (LPBYTE)PAD8(pbDataPtr);
  1316. PRTR_TOC_ENTRY pTocEntry = pIBH->TocEntry;
  1317. // Make IP router manager global info.
  1318. //
  1319. pTocEntry->InfoType = IP_GLOBAL_INFO;
  1320. pTocEntry->InfoSize = sizeof(GLOBAL_INFO);
  1321. pTocEntry->Count = 1;
  1322. pTocEntry->Offset = (int)(pbDataPtr - (PBYTE)pIBH);
  1323. PGLOBAL_INFO pGlbInfo = (PGLOBAL_INFO) pbDataPtr;
  1324. pGlbInfo->bFilteringOn = FALSE;
  1325. pGlbInfo->dwLoggingLevel = IPRTR_LOGGING_ERROR;
  1326. pbDataPtr += pTocEntry->Count * pTocEntry-> InfoSize;
  1327. pbDataPtr = (LPBYTE)PAD8(pbDataPtr);
  1328. pTocEntry++;
  1329. // Make IP router manager priority info.
  1330. //
  1331. pTocEntry->InfoType = IP_PROT_PRIORITY_INFO;
  1332. pTocEntry->InfoSize = SIZEOF_PRIORITY_INFO(c_cProtocols);
  1333. pTocEntry->Count = 1;
  1334. pTocEntry->Offset = (int)(pbDataPtr - (PBYTE)pIBH);
  1335. PPRIORITY_INFO pPriorInfo = (PPRIORITY_INFO) pbDataPtr;
  1336. pPriorInfo->dwNumProtocols = c_cProtocols;
  1337. pPriorInfo->ppmProtocolMetric[ 0 ].dwProtocolId = PROTO_IP_LOCAL;
  1338. pPriorInfo->ppmProtocolMetric[ 0 ].dwMetric = 1;
  1339. pPriorInfo->ppmProtocolMetric[ 1 ].dwProtocolId = PROTO_IP_NT_STATIC;
  1340. pPriorInfo->ppmProtocolMetric[ 1 ].dwMetric = 3;
  1341. pPriorInfo->ppmProtocolMetric[ 2 ].dwProtocolId = PROTO_IP_NT_STATIC_NON_DOD;
  1342. pPriorInfo->ppmProtocolMetric[ 2 ].dwMetric = 5;
  1343. pPriorInfo->ppmProtocolMetric[ 3 ].dwProtocolId = PROTO_IP_NT_AUTOSTATIC;
  1344. pPriorInfo->ppmProtocolMetric[ 3 ].dwMetric = 7;
  1345. pPriorInfo->ppmProtocolMetric[ 4 ].dwProtocolId = PROTO_IP_NETMGMT;
  1346. pPriorInfo->ppmProtocolMetric[ 4 ].dwMetric = 10;
  1347. pPriorInfo->ppmProtocolMetric[ 5 ].dwProtocolId = PROTO_IP_OSPF;
  1348. pPriorInfo->ppmProtocolMetric[ 5 ].dwMetric = 110;
  1349. pPriorInfo->ppmProtocolMetric[ 6 ].dwProtocolId = PROTO_IP_RIP;
  1350. pPriorInfo->ppmProtocolMetric[ 6 ].dwMetric = 120;
  1351. }
  1352. //+---------------------------------------------------------------------------
  1353. //
  1354. // Function: MakeIpxInterfaceInfo
  1355. //
  1356. // Purpose: Create the router interface block for IPX.
  1357. //
  1358. // Arguments:
  1359. // pszwAdapterName [in] The adapter name
  1360. // dwPacketType [in] The packet type
  1361. // ppBuff [out] Pointer to the returned info.
  1362. // Free with delete.
  1363. //
  1364. // Returns: nothing
  1365. //
  1366. // Author: shaunco 28 Jul 1997
  1367. //
  1368. // Notes:
  1369. //
  1370. void MakeIpxInterfaceInfo (
  1371. LPCWSTR pszwAdapterName,
  1372. DWORD dwPacketType,
  1373. LPBYTE* ppBuff)
  1374. {
  1375. Assert (ppBuff);
  1376. const BOOL fDialInInterface = (NULL == pszwAdapterName);
  1377. const int c_cTocEntries = 5;
  1378. // Alocate for minimal global Information.
  1379. //
  1380. DWORD dwSize = sizeof( RTR_INFO_BLOCK_HEADER )
  1381. // header contains one TOC_ENTRY already
  1382. + ((c_cTocEntries - 1) * sizeof( RTR_TOC_ENTRY ))
  1383. + sizeof(IPX_IF_INFO)
  1384. + sizeof(IPX_ADAPTER_INFO)
  1385. + sizeof(IPXWAN_IF_INFO)
  1386. + sizeof(RIP_IF_CONFIG)
  1387. + sizeof(SAP_IF_CONFIG)
  1388. + (c_cTocEntries * ALIGN_SIZE);
  1389. PRTR_INFO_BLOCK_HEADER pIBH = (PRTR_INFO_BLOCK_HEADER) new BYTE [dwSize];
  1390. *ppBuff = (LPBYTE) pIBH;
  1391. if(pIBH == NULL)
  1392. return;
  1393. ZeroMemory (pIBH, dwSize);
  1394. // Initialize infobase fields.
  1395. //
  1396. pIBH->Version = RTR_INFO_BLOCK_VERSION;
  1397. pIBH->Size = dwSize;
  1398. pIBH->TocEntriesCount = c_cTocEntries;
  1399. LPBYTE pbDataPtr = (LPBYTE) &( pIBH->TocEntry[ pIBH->TocEntriesCount ] );
  1400. pbDataPtr = (LPBYTE)PAD8(pbDataPtr);
  1401. PRTR_TOC_ENTRY pTocEntry = pIBH->TocEntry;
  1402. // Make IPX router manager interface info.
  1403. //
  1404. pTocEntry->InfoType = IPX_INTERFACE_INFO_TYPE;
  1405. pTocEntry->InfoSize = sizeof(IPX_IF_INFO);
  1406. pTocEntry->Count = 1;
  1407. pTocEntry->Offset = (int)(pbDataPtr - (PBYTE)pIBH);
  1408. PIPX_IF_INFO pIfInfo = (PIPX_IF_INFO) pbDataPtr;
  1409. pIfInfo->AdminState = ADMIN_STATE_ENABLED;
  1410. pIfInfo->NetbiosAccept = ADMIN_STATE_ENABLED;
  1411. pIfInfo->NetbiosDeliver = (fDialInInterface) ? ADMIN_STATE_DISABLED
  1412. : ADMIN_STATE_ENABLED;
  1413. pbDataPtr += pTocEntry->Count * pTocEntry->InfoSize;
  1414. pbDataPtr = (LPBYTE)PAD8(pbDataPtr);
  1415. pTocEntry++;
  1416. // Make adapter info.
  1417. //
  1418. pTocEntry->InfoType = IPX_ADAPTER_INFO_TYPE;
  1419. pTocEntry->InfoSize = sizeof(IPX_ADAPTER_INFO);
  1420. pTocEntry->Count = 1;
  1421. pTocEntry->Offset = (int)(pbDataPtr - (PBYTE)pIBH);
  1422. PIPX_ADAPTER_INFO pAdInfo = (PIPX_ADAPTER_INFO) pbDataPtr;
  1423. if (ISN_FRAME_TYPE_AUTO == dwPacketType)
  1424. {
  1425. dwPacketType = AUTO_DETECT_PACKET_TYPE;
  1426. }
  1427. pAdInfo->PacketType = dwPacketType;
  1428. if (pszwAdapterName)
  1429. {
  1430. AssertSz (lstrlen (pszwAdapterName) < celems (pAdInfo->AdapterName),
  1431. "Bindname too big for pAdInfo->AdapterName buffer.");
  1432. lstrcpy (pAdInfo->AdapterName, pszwAdapterName);
  1433. }
  1434. else
  1435. {
  1436. AssertSz (0 == pAdInfo->AdapterName[0],
  1437. "Who removed the ZeroMemory call above?");
  1438. }
  1439. pbDataPtr += pTocEntry->Count * pTocEntry->InfoSize;
  1440. pbDataPtr = (LPBYTE)PAD8(pbDataPtr);
  1441. pTocEntry++;
  1442. // Make wan info.
  1443. //
  1444. pTocEntry->InfoType = IPXWAN_INTERFACE_INFO_TYPE;
  1445. pTocEntry->InfoSize = sizeof(IPXWAN_IF_INFO);
  1446. pTocEntry->Count = 1;
  1447. pTocEntry->Offset = (int)(pbDataPtr - (PBYTE)pIBH);
  1448. PIPXWAN_IF_INFO pWanInfo = (PIPXWAN_IF_INFO) pbDataPtr;
  1449. pWanInfo->AdminState = ADMIN_STATE_DISABLED;
  1450. pbDataPtr += pTocEntry->Count * pTocEntry->InfoSize;
  1451. pbDataPtr = (LPBYTE)PAD8(pbDataPtr);
  1452. pTocEntry++;
  1453. // Make RIP interface info.
  1454. //
  1455. pTocEntry->InfoType = IPX_PROTOCOL_RIP;
  1456. pTocEntry->InfoSize = sizeof(RIP_IF_CONFIG);
  1457. pTocEntry->Count = 1;
  1458. pTocEntry->Offset = (int)(pbDataPtr - (PBYTE)pIBH);
  1459. PRIP_IF_CONFIG pRipInfo = (PRIP_IF_CONFIG) pbDataPtr;
  1460. pRipInfo->RipIfInfo.AdminState = ADMIN_STATE_ENABLED;
  1461. pRipInfo->RipIfInfo.UpdateMode = (fDialInInterface)
  1462. ? IPX_NO_UPDATE
  1463. : IPX_STANDARD_UPDATE;
  1464. pRipInfo->RipIfInfo.PacketType = IPX_STANDARD_PACKET_TYPE;
  1465. pRipInfo->RipIfInfo.Supply = ADMIN_STATE_ENABLED;
  1466. pRipInfo->RipIfInfo.Listen = ADMIN_STATE_ENABLED;
  1467. pRipInfo->RipIfInfo.PeriodicUpdateInterval = 60;
  1468. pRipInfo->RipIfInfo.AgeIntervalMultiplier = 3;
  1469. pRipInfo->RipIfFilters.SupplyFilterAction = IPX_ROUTE_FILTER_DENY;
  1470. pRipInfo->RipIfFilters.SupplyFilterCount = 0;
  1471. pRipInfo->RipIfFilters.ListenFilterAction = IPX_ROUTE_FILTER_DENY;
  1472. pRipInfo->RipIfFilters.ListenFilterCount = 0;
  1473. pbDataPtr += pTocEntry->Count * pTocEntry->InfoSize;
  1474. pbDataPtr = (LPBYTE)PAD8(pbDataPtr);
  1475. pTocEntry++;
  1476. // Make SAP interface info.
  1477. //
  1478. pTocEntry->InfoType = IPX_PROTOCOL_SAP;
  1479. pTocEntry->InfoSize = sizeof(SAP_IF_CONFIG);
  1480. pTocEntry->Count = 1;
  1481. pTocEntry->Offset = (int)(pbDataPtr - (PBYTE)pIBH);
  1482. PSAP_IF_CONFIG pSapInfo = (PSAP_IF_CONFIG) pbDataPtr;
  1483. pSapInfo->SapIfInfo.AdminState = ADMIN_STATE_ENABLED;
  1484. pSapInfo->SapIfInfo.UpdateMode = (fDialInInterface)
  1485. ? IPX_NO_UPDATE
  1486. : IPX_STANDARD_UPDATE;
  1487. pSapInfo->SapIfInfo.PacketType = IPX_STANDARD_PACKET_TYPE;
  1488. pSapInfo->SapIfInfo.Supply = ADMIN_STATE_ENABLED;
  1489. pSapInfo->SapIfInfo.Listen = ADMIN_STATE_ENABLED;
  1490. pSapInfo->SapIfInfo.GetNearestServerReply = ADMIN_STATE_ENABLED;
  1491. pSapInfo->SapIfInfo.PeriodicUpdateInterval = 60;
  1492. pSapInfo->SapIfInfo.AgeIntervalMultiplier = 3;
  1493. pSapInfo->SapIfFilters.SupplyFilterAction = IPX_SERVICE_FILTER_DENY;
  1494. pSapInfo->SapIfFilters.SupplyFilterCount = 0;
  1495. pSapInfo->SapIfFilters.ListenFilterAction = IPX_SERVICE_FILTER_DENY;
  1496. pSapInfo->SapIfFilters.ListenFilterCount = 0;
  1497. }
  1498. //+---------------------------------------------------------------------------
  1499. //
  1500. // Function: MakeIpxTransportInfo
  1501. //
  1502. // Purpose: Create the router transport blocks for IPX. Free with delete.
  1503. //
  1504. // Arguments:
  1505. // ppBuffGlobal [out] Pointer to the returned global block.
  1506. // ppBuffClient [out] Pointer to the returned client block.
  1507. //
  1508. // Returns: nothing
  1509. //
  1510. // Author: shaunco 28 Jul 1997
  1511. //
  1512. // Notes:
  1513. //
  1514. void MakeIpxTransportInfo (LPBYTE* ppBuffGlobal, LPBYTE* ppBuffClient)
  1515. {
  1516. Assert (ppBuffGlobal);
  1517. Assert (ppBuffClient);
  1518. MakeIpxInterfaceInfo (NULL, ISN_FRAME_TYPE_AUTO, ppBuffClient);
  1519. const int c_cTocEntries = 3;
  1520. // Alocate for minimal global Information.
  1521. //
  1522. DWORD dwSize = sizeof( RTR_INFO_BLOCK_HEADER )
  1523. // header contains one TOC_ENTRY already
  1524. + ((c_cTocEntries - 1) * sizeof( RTR_TOC_ENTRY ))
  1525. + sizeof(IPX_GLOBAL_INFO)
  1526. + sizeof(RIP_GLOBAL_INFO)
  1527. + sizeof(SAP_GLOBAL_INFO)
  1528. + (c_cTocEntries * ALIGN_SIZE);
  1529. PRTR_INFO_BLOCK_HEADER pIBH = (PRTR_INFO_BLOCK_HEADER) new BYTE [dwSize];
  1530. *ppBuffGlobal = (LPBYTE) pIBH;
  1531. if (pIBH == NULL)
  1532. return;
  1533. ZeroMemory (pIBH, dwSize);
  1534. // Initialize infobase fields.
  1535. //
  1536. pIBH->Version = RTR_INFO_BLOCK_VERSION;
  1537. pIBH->Size = dwSize;
  1538. pIBH->TocEntriesCount = c_cTocEntries;
  1539. LPBYTE pbDataPtr = (LPBYTE) &( pIBH->TocEntry[ pIBH->TocEntriesCount ] );
  1540. pbDataPtr = (LPBYTE)PAD8(pbDataPtr);
  1541. PRTR_TOC_ENTRY pTocEntry = pIBH->TocEntry;
  1542. // Make IPX router manager global info.
  1543. //
  1544. pTocEntry->InfoType = IPX_GLOBAL_INFO_TYPE;
  1545. pTocEntry->InfoSize = sizeof(IPX_GLOBAL_INFO);
  1546. pTocEntry->Count = 1;
  1547. pTocEntry->Offset = (int)(pbDataPtr - (PBYTE)pIBH);
  1548. PIPX_GLOBAL_INFO pGlbInfo = (PIPX_GLOBAL_INFO) pbDataPtr;
  1549. pGlbInfo->RoutingTableHashSize = IPX_MEDIUM_ROUTING_TABLE_HASH_SIZE;
  1550. pGlbInfo->EventLogMask = EVENTLOG_ERROR_TYPE;
  1551. pbDataPtr += pTocEntry->Count * pTocEntry->InfoSize;
  1552. pbDataPtr = (LPBYTE)PAD8(pbDataPtr);
  1553. pTocEntry++;
  1554. // Make RIP global info.
  1555. //
  1556. pTocEntry->InfoType = IPX_PROTOCOL_RIP;
  1557. pTocEntry->InfoSize = sizeof(RIP_GLOBAL_INFO);
  1558. pTocEntry->Count = 1;
  1559. pTocEntry->Offset = (int)(pbDataPtr - (PBYTE)pIBH);
  1560. PRIP_GLOBAL_INFO pRipInfo = (PRIP_GLOBAL_INFO) pbDataPtr;
  1561. pRipInfo->EventLogMask = EVENTLOG_ERROR_TYPE;
  1562. pbDataPtr += pTocEntry->Count * pTocEntry->InfoSize;
  1563. pbDataPtr = (LPBYTE)PAD8(pbDataPtr);
  1564. pTocEntry++;
  1565. // Make SAP global info.
  1566. //
  1567. pTocEntry->InfoType = IPX_PROTOCOL_SAP;
  1568. pTocEntry->InfoSize = sizeof(SAP_GLOBAL_INFO);
  1569. pTocEntry->Count = 1;
  1570. pTocEntry->Offset = (int)(pbDataPtr - (PBYTE)pIBH);
  1571. PSAP_GLOBAL_INFO pSapInfo = (PSAP_GLOBAL_INFO) pbDataPtr;
  1572. pSapInfo->EventLogMask = EVENTLOG_ERROR_TYPE;
  1573. }
  1574. //+---------------------------------------------------------------------------
  1575. //
  1576. // mprapi.h wrappers to return HRESULTs and obey rules of COM in regard
  1577. // to output parameters.
  1578. //
  1579. HRESULT
  1580. HrMprConfigServerConnect(
  1581. IN LPWSTR lpwsServerName,
  1582. OUT HANDLE* phMprConfig
  1583. )
  1584. {
  1585. HRESULT hr = S_OK;
  1586. DWORD dw = MprConfigServerConnect (lpwsServerName, phMprConfig);
  1587. if (NO_ERROR != dw)
  1588. {
  1589. hr = HRESULT_FROM_WIN32 (dw);
  1590. *phMprConfig = NULL;
  1591. }
  1592. TraceError ("HrMprConfigServerConnect", hr);
  1593. return hr;
  1594. }
  1595. HRESULT
  1596. HrMprConfigInterfaceCreate(
  1597. IN HANDLE hMprConfig,
  1598. IN DWORD dwLevel,
  1599. IN LPBYTE lpbBuffer,
  1600. OUT HANDLE* phRouterInterface
  1601. )
  1602. {
  1603. HRESULT hr = S_OK;
  1604. DWORD dw = MprConfigInterfaceCreate (hMprConfig, dwLevel, lpbBuffer,
  1605. phRouterInterface);
  1606. if (NO_ERROR != dw)
  1607. {
  1608. hr = HRESULT_FROM_WIN32 (dw);
  1609. *phRouterInterface = NULL;
  1610. }
  1611. TraceErrorOptional ("HrMprConfigInterfaceCreate", hr,
  1612. (HRESULT_FROM_WIN32(ERROR_NO_SUCH_INTERFACE) == hr));
  1613. return hr;
  1614. }
  1615. HRESULT
  1616. HrMprConfigInterfaceEnum(
  1617. IN HANDLE hMprConfig,
  1618. IN DWORD dwLevel,
  1619. IN OUT LPBYTE* lplpBuffer,
  1620. IN DWORD dwPrefMaxLen,
  1621. OUT LPDWORD lpdwEntriesRead,
  1622. OUT LPDWORD lpdwTotalEntries,
  1623. IN OUT LPDWORD lpdwResumeHandle OPTIONAL
  1624. )
  1625. {
  1626. HRESULT hr = S_OK;
  1627. DWORD dw = MprConfigInterfaceEnum (hMprConfig, dwLevel, lplpBuffer,
  1628. dwPrefMaxLen, lpdwEntriesRead,
  1629. lpdwTotalEntries, lpdwResumeHandle);
  1630. if (NO_ERROR != dw)
  1631. {
  1632. hr = HRESULT_FROM_WIN32 (dw);
  1633. *lpdwEntriesRead = 0;
  1634. *lpdwTotalEntries = 0;
  1635. }
  1636. TraceErrorOptional ("HrMprConfigInterfaceCreate", hr,
  1637. (HRESULT_FROM_WIN32(ERROR_NO_MORE_ITEMS) == hr));
  1638. return hr;
  1639. }
  1640. HRESULT
  1641. HrMprConfigInterfaceTransportEnum(
  1642. IN HANDLE hMprConfig,
  1643. IN HANDLE hRouterInterface,
  1644. IN DWORD dwLevel,
  1645. IN OUT LPBYTE* lplpBuffer, // MPR_IFTRANSPORT_0
  1646. IN DWORD dwPrefMaxLen,
  1647. OUT LPDWORD lpdwEntriesRead,
  1648. OUT LPDWORD lpdwTotalEntries,
  1649. IN OUT LPDWORD lpdwResumeHandle OPTIONAL
  1650. )
  1651. {
  1652. HRESULT hr = S_OK;
  1653. DWORD dw = MprConfigInterfaceTransportEnum (hMprConfig, hRouterInterface,
  1654. dwLevel, lplpBuffer,
  1655. dwPrefMaxLen, lpdwEntriesRead,
  1656. lpdwTotalEntries, lpdwResumeHandle);
  1657. if (NO_ERROR != dw)
  1658. {
  1659. hr = HRESULT_FROM_WIN32 (dw);
  1660. *lpdwEntriesRead = 0;
  1661. *lpdwTotalEntries = 0;
  1662. }
  1663. TraceErrorOptional ("HrMprConfigInterfaceTransportEnum", hr,
  1664. (HRESULT_FROM_WIN32(ERROR_NO_MORE_ITEMS) == hr));
  1665. return hr;
  1666. }
  1667. HRESULT
  1668. HrMprConfigInterfaceGetHandle(
  1669. IN HANDLE hMprConfig,
  1670. IN LPWSTR lpwsInterfaceName,
  1671. OUT HANDLE* phRouterInterface
  1672. )
  1673. {
  1674. HRESULT hr = S_OK;
  1675. DWORD dw = MprConfigInterfaceGetHandle (hMprConfig, lpwsInterfaceName,
  1676. phRouterInterface);
  1677. if (NO_ERROR != dw)
  1678. {
  1679. hr = HRESULT_FROM_WIN32 (dw);
  1680. *phRouterInterface = NULL;
  1681. }
  1682. TraceErrorOptional ("HrMprConfigInterfaceGetHandle", hr,
  1683. (HRESULT_FROM_WIN32(ERROR_NO_SUCH_INTERFACE) == hr));
  1684. return hr;
  1685. }
  1686. HRESULT
  1687. HrMprConfigInterfaceTransportAdd(
  1688. IN HANDLE hMprConfig,
  1689. IN HANDLE hRouterInterface,
  1690. IN DWORD dwTransportId,
  1691. IN LPWSTR lpwsTransportName OPTIONAL,
  1692. IN LPBYTE pInterfaceInfo,
  1693. IN DWORD dwInterfaceInfoSize,
  1694. OUT HANDLE* phRouterIfTransport
  1695. )
  1696. {
  1697. HRESULT hr = S_OK;
  1698. DWORD dw = MprConfigInterfaceTransportAdd (hMprConfig, hRouterInterface,
  1699. dwTransportId, lpwsTransportName,
  1700. pInterfaceInfo, dwInterfaceInfoSize,
  1701. phRouterIfTransport);
  1702. if (NO_ERROR != dw)
  1703. {
  1704. hr = HRESULT_FROM_WIN32 (dw);
  1705. *phRouterIfTransport = NULL;
  1706. }
  1707. TraceError ("HrMprConfigInterfaceTransportAdd", hr);
  1708. return hr;
  1709. }
  1710. HRESULT
  1711. HrMprConfigInterfaceTransportGetHandle(
  1712. IN HANDLE hMprConfig,
  1713. IN HANDLE hRouterInterface,
  1714. IN DWORD dwTransportId,
  1715. OUT HANDLE* phRouterIfTransport
  1716. )
  1717. {
  1718. HRESULT hr = S_OK;
  1719. DWORD dw = MprConfigInterfaceTransportGetHandle (hMprConfig,
  1720. hRouterInterface,
  1721. dwTransportId,
  1722. phRouterIfTransport);
  1723. if (NO_ERROR != dw)
  1724. {
  1725. hr = HRESULT_FROM_WIN32 (dw);
  1726. *phRouterIfTransport = NULL;
  1727. }
  1728. TraceErrorOptional ("HrMprConfigInterfaceTransportAdd", hr,
  1729. (HRESULT_FROM_WIN32(ERROR_NO_SUCH_INTERFACE) == hr));
  1730. return hr;
  1731. }
  1732. HRESULT
  1733. HrMprConfigTransportCreate(
  1734. IN HANDLE hMprConfig,
  1735. IN DWORD dwTransportId,
  1736. IN LPWSTR lpwsTransportName OPTIONAL,
  1737. IN LPBYTE pGlobalInfo,
  1738. IN DWORD dwGlobalInfoSize,
  1739. IN LPBYTE pClientInterfaceInfo OPTIONAL,
  1740. IN DWORD dwClientInterfaceInfoSize OPTIONAL,
  1741. IN LPWSTR lpwsDLLPath,
  1742. OUT HANDLE* phRouterTransport
  1743. )
  1744. {
  1745. HRESULT hr = S_OK;
  1746. DWORD dw = MprConfigTransportCreate (hMprConfig, dwTransportId,
  1747. lpwsTransportName, pGlobalInfo, dwGlobalInfoSize,
  1748. pClientInterfaceInfo, dwClientInterfaceInfoSize,
  1749. lpwsDLLPath, phRouterTransport);
  1750. if (NO_ERROR != dw)
  1751. {
  1752. hr = HRESULT_FROM_WIN32 (dw);
  1753. *phRouterTransport = NULL;
  1754. }
  1755. TraceError ("HrMprConfigTransportCreate", hr);
  1756. return hr;
  1757. }
  1758. HRESULT
  1759. HrMprConfigTransportDelete(
  1760. IN HANDLE hMprConfig,
  1761. IN HANDLE hRouterTransport)
  1762. {
  1763. HRESULT hr = S_OK;
  1764. DWORD dw = MprConfigTransportDelete (hMprConfig, hRouterTransport);
  1765. if (NO_ERROR != dw)
  1766. {
  1767. hr = HRESULT_FROM_WIN32 (dw);
  1768. }
  1769. TraceError ("HrMprConfigTransportDelete", hr);
  1770. return hr;
  1771. }
  1772. HRESULT
  1773. HrMprConfigTransportGetHandle(
  1774. IN HANDLE hMprConfig,
  1775. IN DWORD dwTransportId,
  1776. OUT HANDLE* phRouterTransport
  1777. )
  1778. {
  1779. HRESULT hr = S_OK;
  1780. DWORD dw = MprConfigTransportGetHandle (hMprConfig, dwTransportId,
  1781. phRouterTransport);
  1782. if (NO_ERROR != dw)
  1783. {
  1784. hr = HRESULT_FROM_WIN32 (dw);
  1785. *phRouterTransport = NULL;
  1786. }
  1787. TraceError ("HrMprConfigTransportGetHandle",
  1788. (HRESULT_FROM_WIN32 (ERROR_UNKNOWN_PROTOCOL_ID) == hr)
  1789. ? S_OK : hr);
  1790. return hr;
  1791. }
  1792. HRESULT
  1793. HrMprConfigTransportGetInfo(
  1794. IN HANDLE hMprConfig,
  1795. IN HANDLE hRouterTransport,
  1796. IN OUT LPBYTE* ppGlobalInfo OPTIONAL,
  1797. OUT LPDWORD lpdwGlobalInfoSize OPTIONAL,
  1798. IN OUT LPBYTE* ppClientInterfaceInfo OPTIONAL,
  1799. OUT LPDWORD lpdwClientInterfaceInfoSize OPTIONAL,
  1800. IN OUT LPWSTR* lplpwsDLLPath OPTIONAL
  1801. )
  1802. {
  1803. HRESULT hr = S_OK;
  1804. DWORD dw = MprConfigTransportGetInfo (hMprConfig, hRouterTransport,
  1805. ppGlobalInfo, lpdwGlobalInfoSize,
  1806. ppClientInterfaceInfo,
  1807. lpdwClientInterfaceInfoSize,
  1808. lplpwsDLLPath);
  1809. if (NO_ERROR != dw)
  1810. {
  1811. hr = HRESULT_FROM_WIN32 (dw);
  1812. }
  1813. TraceError ("HrMprConfigTransportGetInfo", hr);
  1814. return hr;
  1815. }