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.

259 lines
5.0 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. AlgController.cpp : Implementation of CAlgController
  5. Abstract:
  6. This module contains routines for the ALG Manager module's
  7. private interface to be used only by ICS see rmALG.cpp
  8. Author:
  9. JPDup 10-Nov-2000
  10. Revision History:
  11. --*/
  12. #include "PreComp.h"
  13. #include "AlgController.h"
  14. //
  15. // Globals
  16. //
  17. CAlgController* g_pAlgController=NULL; // This is a singleton created by IPNATHLP/NatALG
  18. //
  19. // IPNATHLP is ready and is asking the ALG manager to do it's magic and load all the ISV ALGs
  20. //
  21. STDMETHODIMP
  22. CAlgController::Start(
  23. INat* pINat
  24. )
  25. {
  26. MYTRACE_ENTER("CAlgController::Start");
  27. if ( !pINat )
  28. {
  29. MYTRACE_ERROR("NULL pINat",0);
  30. return E_INVALIDARG;
  31. }
  32. //
  33. // Cache the INat interface that is given, will be used for the total life time of the ALG manager
  34. //
  35. m_pINat = pINat;
  36. m_pINat->AddRef();
  37. //
  38. // Create the one and only ALG Public interface will be passed to all ALG module that we host
  39. //
  40. HRESULT hr;
  41. CComObject<CApplicationGatewayServices>* pAlgServices;
  42. CComObject<CApplicationGatewayServices>::CreateInstance(&pAlgServices);
  43. hr = pAlgServices->QueryInterface(
  44. IID_IApplicationGatewayServices,
  45. (void**)&m_pIAlgServices
  46. );
  47. if ( FAILED(hr) )
  48. {
  49. MYTRACE_ERROR("CreateInstance(CApplicationGateway)", hr);
  50. return hr;
  51. }
  52. //
  53. // Cache the ApplicationGatewayService, other call like PrimaryControlChannel etc.. will refer to this singleton
  54. //
  55. g_pAlgController = this;
  56. //
  57. // Load all the ALG's will return S_OK even if some ALG had problem loading
  58. //
  59. m_AlgModules.Load();
  60. return S_OK;
  61. }
  62. extern HANDLE g_EventKeepAlive;
  63. //
  64. // CALL by IPNATHLP when the ICS/Firewall SharedAccess service is stoped
  65. //
  66. STDMETHODIMP
  67. CAlgController::Stop()
  68. {
  69. MYTRACE_ENTER("CAlgController::Stop()")
  70. //
  71. // Release all ALG currently loaded
  72. //
  73. m_AlgModules.Unload();
  74. FreeResources();
  75. //
  76. // Let's stop
  77. //
  78. MYTRACE("Next intruction will signale the g_EventKeepAlive");
  79. SetEvent(g_EventKeepAlive); // see ALG.cpp the WinMain is waiting on the event before exiting the process
  80. return S_OK;
  81. }
  82. //
  83. // CComNAT will call this interface when a new adapter is reported
  84. //
  85. STDMETHODIMP
  86. CAlgController::Adapter_Add(
  87. IN ULONG nCookie, // Internal handle to indentify the Adapter being added
  88. IN short nType
  89. )
  90. {
  91. MYTRACE_ENTER("CAlgController::Adapter_Add")
  92. MYTRACE("Adapter Cookie %d Type %d", nCookie, nType);
  93. #if defined(DBG) || defined(_DEBUG)
  94. if ( nType & eALG_PRIVATE )
  95. MYTRACE("eALG_PRIVATE ADAPTER");
  96. if ( nType & eALG_FIREWALLED )
  97. MYTRACE("eALG_FIREWALLED ADAPTER");
  98. if ( nType & eALG_BOUNDARY )
  99. MYTRACE("eALG_BOUNDARY ADAPTER");
  100. #endif
  101. m_CollectionOfAdapters.Add(
  102. nCookie,
  103. nType
  104. );
  105. return S_OK;
  106. }
  107. //
  108. // CComNAT will call this interface when a new adapter is Removed
  109. //
  110. STDMETHODIMP
  111. CAlgController::Adapter_Remove(
  112. IN ULONG nCookie // Internal handle to indentify the Adapter being removed
  113. )
  114. {
  115. MYTRACE_ENTER("CAlgController::Adapter_Remove")
  116. MYTRACE("Adapter nCookie %d", nCookie);
  117. m_CollectionOfAdapters.Remove(
  118. nCookie
  119. );
  120. return S_OK;
  121. }
  122. //
  123. // CComNAT will call this interface when a new adapter is modified
  124. //
  125. STDMETHODIMP
  126. CAlgController::Adapter_Modify(
  127. IN ULONG nCookie // Internal handle to indentify the Adapter being Modified
  128. )
  129. {
  130. MYTRACE_ENTER("CAlgController::Adapter_Modify")
  131. MYTRACE("Adapter nCookie %d", nCookie);
  132. return S_OK;
  133. }
  134. //
  135. // CComNAT will call this interface when a new adapter is modified
  136. //
  137. STDMETHODIMP
  138. CAlgController::Adapter_Bind(
  139. IN ULONG nCookie, // Internal handle to indentify the Adapter being Bind
  140. IN ULONG nAdapterIndex,
  141. IN ULONG nAddressCount,
  142. IN DWORD anAddresses[]
  143. )
  144. {
  145. MYTRACE_ENTER("CAlgController::Adapter_Bind")
  146. MYTRACE("Adapter nCookie(%d)=Index(%d), AddressCount %d Address[0] %s", nCookie, nAdapterIndex, nAddressCount, MYTRACE_IP(anAddresses[0]));
  147. m_CollectionOfAdapters.SetAddresses(
  148. nCookie,
  149. nAdapterIndex,
  150. nAddressCount,
  151. anAddresses
  152. );
  153. return S_OK;
  154. }
  155. //
  156. // CComNat will call this method when a port mapping is modified
  157. //
  158. STDMETHODIMP
  159. CAlgController::Adapter_PortMappingChanged(
  160. IN ULONG nCookie,
  161. IN UCHAR ucProtocol,
  162. IN USHORT usPort
  163. )
  164. {
  165. MYTRACE_ENTER("CAlgController::Adapter_PortMappingChanged");
  166. MYTRACE("Adapter Cookie %d, Protocol %d, Port %d", nCookie, ucProtocol, usPort);
  167. HRESULT hr =
  168. m_ControlChannelsPrimary.AdapterPortMappingChanged(
  169. nCookie,
  170. ucProtocol,
  171. usPort
  172. );
  173. return hr;
  174. }