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.

163 lines
3.9 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // CSecondaryControlChannel
  4. //
  5. // SecondaryControlChannel.cpp : Implementation of CSecondaryControlChannel
  6. //
  7. #include "PreComp.h"
  8. #include "AlgController.h"
  9. #include "SecondaryControlChannel.h"
  10. //
  11. // Cancel the redirect when it was created we stored the original demanded addresses & ports
  12. // now we need to reverse(Cancel) them
  13. //
  14. STDMETHODIMP
  15. CSecondaryControlChannel::Cancel()
  16. {
  17. //
  18. // By removing this Channel from the collection of SecondaryChannel
  19. // the Redirect associated with this channel will be cancel(release)
  20. // and ref count decrement.
  21. return g_pAlgController->m_ControlChannelsSecondary.Remove(this);
  22. }
  23. STDMETHODIMP
  24. CSecondaryControlChannel::GetChannelProperties(
  25. ALG_SECONDARY_CHANNEL_PROPERTIES** ppProperties
  26. )
  27. {
  28. HRESULT hr = S_OK;
  29. if (NULL != ppProperties)
  30. {
  31. *ppProperties = reinterpret_cast<ALG_SECONDARY_CHANNEL_PROPERTIES*>(
  32. CoTaskMemAlloc(sizeof(ALG_SECONDARY_CHANNEL_PROPERTIES))
  33. );
  34. if (NULL != *ppProperties)
  35. {
  36. CopyMemory(*ppProperties, &m_Properties, sizeof(ALG_SECONDARY_CHANNEL_PROPERTIES));
  37. }
  38. else
  39. {
  40. hr = E_OUTOFMEMORY;
  41. }
  42. }
  43. else
  44. {
  45. hr = E_POINTER;
  46. }
  47. return hr;
  48. }
  49. //
  50. //
  51. //
  52. STDMETHODIMP
  53. CSecondaryControlChannel::GetOriginalDestinationInformation(
  54. IN ULONG ulSourceAddress,
  55. IN USHORT usSourcePort,
  56. OUT ULONG* pulOriginalDestinationAddress,
  57. OUT USHORT* pusOriginalDestinationPort,
  58. OUT OPTIONAL IAdapterInfo** ppReceiveAdapter
  59. )
  60. {
  61. MYTRACE_ENTER("CSecondaryControlChannel::GetOriginalDestinationInformation");
  62. if ( pulOriginalDestinationAddress==NULL ||
  63. pusOriginalDestinationPort== NULL
  64. )
  65. {
  66. MYTRACE_ERROR("Invalid argument pass pulOriginalDestinationAddress or pulOriginalDestinationPort", E_INVALIDARG);
  67. return E_INVALIDARG;
  68. }
  69. ULONG nAdapterCookie;
  70. HRESULT hr = g_pAlgController->GetNat()->GetOriginalDestinationInformation(
  71. m_Properties.eProtocol,
  72. m_ulNewDestinationAddress,
  73. m_usNewDestinationPort,
  74. ulSourceAddress,
  75. usSourcePort,
  76. pulOriginalDestinationAddress,
  77. pusOriginalDestinationPort,
  78. &nAdapterCookie
  79. );
  80. if ( FAILED(hr) )
  81. {
  82. MYTRACE_ERROR("GetNat()->GetOriginalDestinationInformation", hr);
  83. return hr;
  84. }
  85. if ( ppReceiveAdapter )
  86. {
  87. hr = g_pAlgController->m_CollectionOfAdapters.GetAdapterInfo(
  88. nAdapterCookie,
  89. ppReceiveAdapter
  90. );
  91. }
  92. return hr;
  93. }
  94. //
  95. // Public method
  96. //
  97. // release associated Redirects
  98. //
  99. HRESULT
  100. CSecondaryControlChannel::CancelRedirects()
  101. {
  102. HRESULT hr;
  103. if ( m_HandleDynamicRedirect )
  104. {
  105. //
  106. // We have a handle to a dynamic redirect so we cancel it using this handle
  107. //
  108. hr = g_pAlgController->GetNat()->CancelDynamicRedirect(m_HandleDynamicRedirect);
  109. }
  110. else
  111. {
  112. //
  113. // Normal redirect cancel using original argument pass to CreateRedirect
  114. //
  115. hr = g_pAlgController->GetNat()->CancelRedirect(
  116. (UCHAR)m_Properties.eProtocol,
  117. m_ulDestinationAddress,
  118. m_usDestinationPort,
  119. m_ulSourceAddress,
  120. m_usSourcePort,
  121. m_ulNewDestinationAddress,
  122. m_usNewDestinationPort,
  123. m_ulNewSourceAddress,
  124. m_usNewSourcePort
  125. );
  126. }
  127. return hr;
  128. }