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.

355 lines
9.3 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // File: cluster.cpp
  4. //
  5. // Module: WLBS API
  6. //
  7. // Description: Implement class CWlbsCluster
  8. //
  9. // Copyright (C) Microsoft Corporation. All rights reserved.
  10. //
  11. // Author: Created 3/9/00
  12. //
  13. //+----------------------------------------------------------------------------
  14. #include "precomp.h"
  15. #include <debug.h>
  16. #include "cluster.h"
  17. #include "control.h"
  18. #include "param.h"
  19. #include "cluster.tmh" // For event tracing
  20. CWlbsCluster::CWlbsCluster(DWORD dwConfigIndex)
  21. {
  22. m_reload_required = FALSE;
  23. m_mac_addr_change = FALSE;
  24. m_this_cl_addr = 0;
  25. m_this_host_id = 0;
  26. m_this_ded_addr = 0;
  27. m_dwConfigIndex = dwConfigIndex;
  28. }
  29. //+----------------------------------------------------------------------------
  30. //
  31. // Function: CWlbsCluster::ReadConfig
  32. //
  33. // Description: Read cluster settings from registry
  34. //
  35. // Arguments: PWLBS_REG_PARAMS reg_data -
  36. //
  37. // Returns: DWORD -
  38. //
  39. // History: fengsun Created Header 1/25/00
  40. //
  41. //+----------------------------------------------------------------------------
  42. DWORD CWlbsCluster::ReadConfig(PWLBS_REG_PARAMS reg_data)
  43. {
  44. if (ParamReadReg(m_AdapterGuid, reg_data) == false)
  45. {
  46. return WLBS_REG_ERROR;
  47. }
  48. /* create a copy in the old_params structure. this will be required to
  49. * determine whether a reload is needed or a reboot is needed for commit */
  50. memcpy ( &m_reg_params, reg_data, sizeof (WLBS_REG_PARAMS));
  51. // m_this_cl_addr = IpAddressFromAbcdWsz(m_reg_params.cl_ip_addr);
  52. m_this_ded_addr = IpAddressFromAbcdWsz(m_reg_params.ded_ip_addr);
  53. return WLBS_OK;
  54. }
  55. //+----------------------------------------------------------------------------
  56. //
  57. // Function: CWlbsCluster::GetClusterIpOrIndex
  58. //
  59. // Description: Get the index or IP of the cluster. If the cluster IP is non-zero
  60. // The IP is return.
  61. // If the cluster IP is 0, the index is returned
  62. //
  63. // Arguments: CWlbsControl* pControl -
  64. //
  65. // Returns: DWORD -
  66. //
  67. // History: fengsun Created Header 7/3/00
  68. //
  69. //+----------------------------------------------------------------------------
  70. DWORD CWlbsCluster::GetClusterIpOrIndex(CWlbsControl* pControl)
  71. {
  72. DWORD dwIp = CWlbsCluster::GetClusterIp();
  73. if (dwIp!=0)
  74. {
  75. //
  76. // Return the cluster IP if non 0
  77. //
  78. return dwIp;
  79. }
  80. if (pControl->GetClusterNum() == 1)
  81. {
  82. //
  83. // For backward compatibility, return 0 if only one cluster exists
  84. //
  85. return 0;
  86. }
  87. //
  88. // Ip address is in the reverse order
  89. //
  90. return (CWlbsCluster::m_dwConfigIndex) <<24;
  91. }
  92. //+----------------------------------------------------------------------------
  93. //
  94. // Function: CWlbsCluster::WriteConfig
  95. //
  96. // Description: Write cluster settings to registry
  97. //
  98. // Arguments: WLBS_REG_PARAMS* reg_data -
  99. //
  100. // Returns: DWORD -
  101. //
  102. // History: fengsun Created Header 3/9/00
  103. //
  104. //+----------------------------------------------------------------------------
  105. DWORD CWlbsCluster::WriteConfig(WLBS_REG_PARAMS* reg_data)
  106. {
  107. if (memcmp (&m_reg_params, reg_data, sizeof (WLBS_REG_PARAMS)) == 0)
  108. {
  109. //
  110. // No changes
  111. //
  112. return WLBS_OK;
  113. }
  114. if (ParamWriteReg(m_AdapterGuid, reg_data) == false)
  115. {
  116. return WLBS_REG_ERROR;
  117. }
  118. /* No errors so far, so set the global flags reload_required and reboot_required
  119. * depending on which fields have been changed between reg_data and old_params.
  120. */
  121. m_reload_required = TRUE;
  122. /* Reboot is required if multicast_support option is changed or
  123. * if the user specifies a different mac address
  124. */
  125. /* Reboot required is set to TRUE whenever cl_mac_address changes. Will be modified later ##### */
  126. if (m_reg_params.mcast_support != reg_data->mcast_support || _tcsicmp(m_reg_params.cl_mac_addr, reg_data->cl_mac_addr) != 0) {
  127. m_mac_addr_change = true;
  128. //
  129. // if m_reg_params -> mcast_support then remove mac addr, otherwise write mac addr
  130. //
  131. if (RegChangeNetworkAddress (m_AdapterGuid, reg_data->cl_mac_addr, reg_data->mcast_support) == false) {
  132. LOG_ERROR("CWlbsCluster::WriteConfig failed at RegChangeNetworkAddress");
  133. }
  134. }
  135. /* Write the changes to the structure old_values
  136. * This copying is done only after all the data has been written into the registry
  137. * Otherwise, the structure old_values would retain the previous values.
  138. */
  139. memcpy(&m_reg_params, reg_data, sizeof (WLBS_REG_PARAMS));
  140. return WLBS_OK;
  141. }
  142. //+----------------------------------------------------------------------------
  143. //
  144. // Function: CWlbsCluster::CommitChanges
  145. //
  146. // Description: Notify wlbs driver or nic driver to pick up the changes
  147. //
  148. // Arguments: CWlbsControl* pWlbsControl -
  149. //
  150. // Returns: DWORD -
  151. //
  152. // History: fengsun Created Header 7/6/00
  153. //
  154. //+----------------------------------------------------------------------------
  155. DWORD CWlbsCluster::CommitChanges(CWlbsControl* pWlbsControl)
  156. {
  157. ASSERT(pWlbsControl);
  158. HANDLE hDeviceWlbs = pWlbsControl->GetDriverHandle();
  159. // Read the cluster IP address and the dedicated IP address from the
  160. // registry and update the global variables.
  161. // Always update the cluster IP address and the dedicated IP address
  162. RegReadAdapterIp(m_AdapterGuid, m_this_cl_addr, m_this_ded_addr);
  163. /* Check if the driver requires a reload or not. If not, then simply return */
  164. if (m_reload_required == FALSE)
  165. {
  166. return WLBS_OK;
  167. }
  168. NotifyDriverConfigChanges(hDeviceWlbs, m_AdapterGuid);
  169. LONG status;
  170. IOCTL_CVY_BUF in_buf;
  171. IOCTL_CVY_BUF out_buf;
  172. status = WlbsLocalControl (hDeviceWlbs, m_AdapterGuid, IOCTL_CVY_RELOAD, & in_buf, & out_buf, 0);
  173. if (status == WLBS_IO_ERROR)
  174. {
  175. return status;
  176. }
  177. if (out_buf . ret_code == IOCTL_CVY_BAD_PARAMS)
  178. {
  179. return WLBS_BAD_PARAMS;
  180. }
  181. m_reload_required = FALSE; /* reset the flag */
  182. if (m_mac_addr_change)
  183. {
  184. m_mac_addr_change = false;
  185. /* The NIC card name for the cluster. */
  186. WCHAR driver_name[CVY_STR_SIZE];
  187. ZeroMemory(driver_name, sizeof(driver_name));
  188. /* Get the driver name from the GUID. */
  189. GetDriverNameFromGUID(m_AdapterGuid, driver_name, CVY_STR_SIZE);
  190. /* When the MAC address changes, disable and re-enable the adapter as well as notify
  191. the adapter that the MAC address has changed. There is no need to make sure that
  192. the adapter is initially enabled because disabled adapters are invisible here. */
  193. NotifyAdapterPropertyChange(driver_name, DICS_DISABLE);
  194. NotifyAdapterPropertyChange(driver_name, DICS_PROPCHANGE);
  195. NotifyAdapterPropertyChange(driver_name, DICS_ENABLE);
  196. }
  197. return WLBS_OK;
  198. }
  199. //+----------------------------------------------------------------------------
  200. //
  201. // Function: CWlbsCluster::Initialize
  202. //
  203. // Description: Initialization
  204. //
  205. // Arguments: const GUID& AdapterGuid -
  206. //
  207. // Returns: bool - true if succeeded
  208. //
  209. // History: fengsun Created Header 3/9/00
  210. //
  211. //+----------------------------------------------------------------------------
  212. bool CWlbsCluster::Initialize(const GUID& AdapterGuid)
  213. {
  214. m_AdapterGuid = AdapterGuid;
  215. m_mac_addr_change = false;
  216. m_reload_required = false;
  217. ZeroMemory (& m_reg_params, sizeof (m_reg_params));
  218. ParamReadReg(m_AdapterGuid, &m_reg_params);
  219. m_this_cl_addr = IpAddressFromAbcdWsz(m_reg_params.cl_ip_addr);
  220. m_this_ded_addr = IpAddressFromAbcdWsz(m_reg_params.ded_ip_addr);\
  221. m_this_host_id = m_reg_params.host_priority;
  222. return true;
  223. }
  224. //+----------------------------------------------------------------------------
  225. //
  226. // Function: CWlbsCluster::ReInitialize
  227. //
  228. // Description: Reload settings from registry
  229. //
  230. // Arguments:
  231. //
  232. // Returns: bool - true if succeeded
  233. //
  234. // History: fengsun Created Header 3/9/00
  235. //
  236. //+----------------------------------------------------------------------------
  237. bool CWlbsCluster::ReInitialize()
  238. {
  239. if (ParamReadReg(m_AdapterGuid, &m_reg_params) == false)
  240. {
  241. return false;
  242. }
  243. //
  244. // Do not change the ClusterIP if the changes has not been commited
  245. //
  246. if (!IsCommitPending())
  247. {
  248. m_this_cl_addr = IpAddressFromAbcdWsz(m_reg_params.cl_ip_addr);
  249. m_this_host_id = m_reg_params.host_priority;
  250. }
  251. m_this_ded_addr = IpAddressFromAbcdWsz(m_reg_params.ded_ip_addr);
  252. return true;
  253. }
  254. //+----------------------------------------------------------------------------
  255. //
  256. // Function: CWlbsCluster::GetPassword
  257. //
  258. // Description: Get remote control password for this cluster
  259. //
  260. // Arguments:
  261. //
  262. // Returns: DWORD - password
  263. //
  264. // History: fengsun Created Header 2/3/00
  265. //
  266. //+----------------------------------------------------------------------------
  267. DWORD CWlbsCluster::GetPassword()
  268. {
  269. HKEY key = NULL;
  270. LONG status;
  271. DWORD dwRctPassword = 0;
  272. key = RegOpenWlbsSetting(m_AdapterGuid, true);
  273. DWORD size = sizeof(dwRctPassword);
  274. status = RegQueryValueEx (key, CVY_NAME_RCT_PASSWORD, 0L, NULL,
  275. (LPBYTE) & dwRctPassword, & size);
  276. if (status != ERROR_SUCCESS)
  277. dwRctPassword = CVY_DEF_RCT_PASSWORD;
  278. RegCloseKey(key);
  279. return dwRctPassword;
  280. }