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.

1060 lines
36 KiB

  1. #include <crtdbg.h>
  2. #include <comdef.h>
  3. #include <iostream>
  4. #include <memory>
  5. #include <string>
  6. #include <wbemprov.h>
  7. #include <genlex.h> //for wmi object path parser
  8. #include <objbase.h>
  9. #include <wlbsconfig.h>
  10. #include <ntrkcomm.h>
  11. using namespace std;
  12. #include "objpath.h"
  13. #include "debug.h"
  14. #include "wlbsiocl.h"
  15. #include "controlwrapper.h"
  16. #include "clusterwrapper.h"
  17. #include "utils.h"
  18. #include "wlbsparm.h"
  19. #include "cluster.h"
  20. #include "wlbsutil.h"
  21. #include "clusterwrapper.tmh"
  22. ////////////////////////////////////////////////////////////////////////////////
  23. //
  24. // CWlbsClusterWrapper::GetClusterConfig
  25. //
  26. // Purpose: This is used to obtain the current
  27. // cluster configuration.
  28. //
  29. ////////////////////////////////////////////////////////////////////////////////
  30. void CWlbsClusterWrapper::GetClusterConfig( CClusterConfiguration& a_WlbsConfig )
  31. {
  32. WLBS_REG_PARAMS WlbsParam;
  33. TRACE_VERB("->%!FUNC!");
  34. DWORD dwWlbsRegRes = CWlbsCluster::ReadConfig(&WlbsParam );
  35. if( dwWlbsRegRes != WLBS_OK )
  36. {
  37. TRACE_CRIT("%!FUNC! CWlbsCluster::ReadConfig returned : 0x%x, Throwing Wlbs error exception",dwWlbsRegRes);
  38. TRACE_VERB("<-%!FUNC!");
  39. throw CErrorWlbsControl( dwWlbsRegRes, CmdWlbsReadReg );
  40. }
  41. a_WlbsConfig.szClusterName = WlbsParam.domain_name;
  42. a_WlbsConfig.szClusterIPAddress = WlbsParam.cl_ip_addr;
  43. a_WlbsConfig.szClusterNetworkMask = WlbsParam.cl_net_mask;
  44. a_WlbsConfig.szClusterMACAddress = WlbsParam.cl_mac_addr;
  45. a_WlbsConfig.bMulticastSupportEnable = ( WlbsParam.mcast_support != 0);
  46. a_WlbsConfig.bRemoteControlEnabled = ( WlbsParam.rct_enabled != 0 );
  47. a_WlbsConfig.nMaxNodes = WLBS_MAX_HOSTS;
  48. a_WlbsConfig.bIgmpSupport = (WlbsParam.fIGMPSupport != FALSE);
  49. a_WlbsConfig.bClusterIPToMulticastIP = (WlbsParam.fIpToMCastIp != FALSE);
  50. a_WlbsConfig.szMulticastIPAddress = WlbsParam.szMCastIpAddress;
  51. a_WlbsConfig.bBDATeamActive = (WlbsParam.bda_teaming.active != 0);
  52. if (a_WlbsConfig.bBDATeamActive)
  53. {
  54. a_WlbsConfig.szBDATeamId = WlbsParam.bda_teaming.team_id;
  55. a_WlbsConfig.bBDATeamMaster = (WlbsParam.bda_teaming.master != 0);
  56. a_WlbsConfig.bBDAReverseHash = (WlbsParam.bda_teaming.reverse_hash != 0);
  57. }
  58. a_WlbsConfig.bIdentityHeartbeatEnabled = ( WlbsParam.identity_enabled != 0 );
  59. TRACE_VERB("<-%!FUNC!");
  60. }
  61. ////////////////////////////////////////////////////////////////////////////////
  62. //
  63. // CWlbsClusterWrapper::GetNodeConfig
  64. //
  65. // Purpose: This function retrieves the current WLBS configuration and selects
  66. // only NodeSetting pertinent information. The information is passed
  67. // back in a CNodeConfiguration class instance.
  68. //
  69. ////////////////////////////////////////////////////////////////////////////////
  70. void CWlbsClusterWrapper::GetNodeConfig( CNodeConfiguration& a_WlbsConfig )
  71. {
  72. WLBS_REG_PARAMS WlbsParam;
  73. TRACE_VERB("->%!FUNC!");
  74. DWORD dwWlbsRegRes = CWlbsCluster::ReadConfig(&WlbsParam );
  75. if( dwWlbsRegRes != WLBS_OK )
  76. {
  77. TRACE_CRIT("%!FUNC! CWlbsCluster::ReadConfig returned : 0x%x, Throwing Wlbs error exception",dwWlbsRegRes);
  78. TRACE_VERB("<-%!FUNC!");
  79. throw CErrorWlbsControl( dwWlbsRegRes, CmdWlbsReadReg );
  80. }
  81. a_WlbsConfig.szDedicatedIPAddress = WlbsParam.ded_ip_addr;
  82. a_WlbsConfig.szDedicatedNetworkMask = WlbsParam.ded_net_mask;
  83. a_WlbsConfig.bClusterModeOnStart = ( WlbsParam.cluster_mode == CVY_HOST_STATE_STARTED );
  84. a_WlbsConfig.bClusterModeSuspendOnStart = ( WlbsParam.cluster_mode == CVY_HOST_STATE_SUSPENDED );
  85. a_WlbsConfig.bPersistSuspendOnReboot = (( WlbsParam.persisted_states & CVY_PERSIST_STATE_SUSPENDED ) != 0);
  86. //a_WlbsConfig.bNBTSupportEnable = ( WlbsParam.nbt_support != 0 );
  87. a_WlbsConfig.bMaskSourceMAC = ( WlbsParam.mask_src_mac != 0 );
  88. a_WlbsConfig.dwNumberOfRules = WlbsGetNumPortRules(&WlbsParam);
  89. a_WlbsConfig.dwCurrentVersion = WlbsParam.alive_period;
  90. a_WlbsConfig.dwHostPriority = WlbsParam.host_priority;
  91. a_WlbsConfig.dwAliveMsgPeriod = WlbsParam.alive_period;
  92. a_WlbsConfig.dwAliveMsgTolerance = WlbsParam.alive_tolerance;
  93. a_WlbsConfig.dwRemoteControlUDPPort = WlbsParam.rct_port;
  94. a_WlbsConfig.dwDescriptorsPerAlloc = WlbsParam.dscr_per_alloc;
  95. a_WlbsConfig.dwMaxDescriptorAllocs = WlbsParam.max_dscr_allocs;
  96. a_WlbsConfig.dwFilterIcmp = WlbsParam.filter_icmp;
  97. a_WlbsConfig.dwTcpDescriptorTimeout = WlbsParam.tcp_dscr_timeout;
  98. a_WlbsConfig.dwIpSecDescriptorTimeout = WlbsParam.ipsec_dscr_timeout;
  99. a_WlbsConfig.dwNumActions = WlbsParam.num_actions;
  100. a_WlbsConfig.dwNumPackets = WlbsParam.num_packets;
  101. a_WlbsConfig.dwNumAliveMsgs = WlbsParam.num_send_msgs;
  102. a_WlbsConfig.szDedicatedIPAddress = WlbsParam.ded_ip_addr;
  103. a_WlbsConfig.dwEffectiveVersion = WlbsGetEffectiveVersion(&WlbsParam);
  104. TRACE_VERB("<-%!FUNC!");
  105. }
  106. ////////////////////////////////////////////////////////////////////////////////
  107. //
  108. // CWlbsClusterWrapper::SetClusterConfig
  109. //
  110. // Purpose: This is used to update the registry with values that originate from
  111. // the MOF ClusterSetting class.
  112. //
  113. ////////////////////////////////////////////////////////////////////////////////
  114. void CWlbsClusterWrapper::PutClusterConfig( const CClusterConfiguration &a_WlbsConfig )
  115. {
  116. WLBS_REG_PARAMS NlbRegData;
  117. TRACE_VERB("->%!FUNC!");
  118. DWORD dwWlbsRegRes = CWlbsCluster::ReadConfig(&NlbRegData );
  119. if( dwWlbsRegRes != WLBS_OK )
  120. {
  121. TRACE_CRIT("%!FUNC! CWlbsCluster::ReadConfig returned : 0x%x, Throwing Wlbs error exception",dwWlbsRegRes);
  122. TRACE_VERB("<-%!FUNC!");
  123. throw CErrorWlbsControl( dwWlbsRegRes, CmdWlbsReadReg );
  124. }
  125. wcsncpy
  126. (
  127. NlbRegData.domain_name,
  128. a_WlbsConfig.szClusterName.c_str(),
  129. WLBS_MAX_DOMAIN_NAME
  130. );
  131. wcsncpy
  132. (
  133. NlbRegData.cl_net_mask,
  134. a_WlbsConfig.szClusterNetworkMask.c_str(),
  135. WLBS_MAX_CL_NET_MASK
  136. );
  137. wcsncpy
  138. (
  139. NlbRegData.cl_ip_addr ,
  140. a_WlbsConfig.szClusterIPAddress.c_str(),
  141. WLBS_MAX_CL_IP_ADDR
  142. );
  143. NlbRegData.mcast_support = a_WlbsConfig.bMulticastSupportEnable;
  144. NlbRegData.rct_enabled = a_WlbsConfig.bRemoteControlEnabled;
  145. NlbRegData.fIGMPSupport = a_WlbsConfig.bIgmpSupport;
  146. NlbRegData.fIpToMCastIp = a_WlbsConfig.bClusterIPToMulticastIP;
  147. wcsncpy
  148. (
  149. NlbRegData.szMCastIpAddress ,
  150. a_WlbsConfig.szMulticastIPAddress.c_str(),
  151. WLBS_MAX_CL_IP_ADDR
  152. );
  153. // Fill in BDA information, if active
  154. NlbRegData.bda_teaming.active = a_WlbsConfig.bBDATeamActive;
  155. if (NlbRegData.bda_teaming.active)
  156. {
  157. wcsncpy
  158. (
  159. NlbRegData.bda_teaming.team_id,
  160. a_WlbsConfig.szBDATeamId.c_str(),
  161. WLBS_MAX_BDA_TEAM_ID
  162. );
  163. NlbRegData.bda_teaming.master = a_WlbsConfig.bBDATeamMaster;
  164. NlbRegData.bda_teaming.reverse_hash = a_WlbsConfig.bBDAReverseHash;
  165. }
  166. NlbRegData.identity_enabled = a_WlbsConfig.bIdentityHeartbeatEnabled;
  167. dwWlbsRegRes = CWlbsCluster::WriteConfig(&NlbRegData );
  168. if( dwWlbsRegRes != WLBS_OK )
  169. {
  170. TRACE_CRIT("%!FUNC! CWlbsCluster::WriteConfig returned : 0x%x, Throwing Wlbs error exception",dwWlbsRegRes);
  171. TRACE_VERB("<-%!FUNC!");
  172. throw CErrorWlbsControl( dwWlbsRegRes, CmdWlbsWriteReg );
  173. }
  174. TRACE_VERB("<-%!FUNC!");
  175. }
  176. ////////////////////////////////////////////////////////////////////////////////
  177. //
  178. // CWlbsClusterWrapper::PutNodeConfig
  179. //
  180. // Purpose:This is used to update the registry with values that originate from
  181. // the MOF NodeSetting class.
  182. //
  183. ////////////////////////////////////////////////////////////////////////////////
  184. void CWlbsClusterWrapper::PutNodeConfig( const CNodeConfiguration& a_WlbsConfig )
  185. {
  186. WLBS_REG_PARAMS NlbRegData;
  187. TRACE_VERB("->%!FUNC!");
  188. DWORD dwWlbsRegRes = CWlbsCluster::ReadConfig(&NlbRegData);
  189. if( dwWlbsRegRes != WLBS_OK )
  190. {
  191. TRACE_CRIT("%!FUNC! CWlbsCluster::ReadConfig returned : 0x%x, Throwing Wlbs error exception",dwWlbsRegRes);
  192. TRACE_VERB("<-%!FUNC!");
  193. throw CErrorWlbsControl( dwWlbsRegRes, CmdWlbsReadReg );
  194. }
  195. NlbRegData.host_priority = a_WlbsConfig.dwHostPriority;
  196. NlbRegData.alive_period = a_WlbsConfig.dwAliveMsgPeriod;
  197. NlbRegData.alive_tolerance = a_WlbsConfig.dwAliveMsgTolerance;
  198. /* Here, we need to convert the two boolean WMI properties to a single enumerated
  199. type describing the initial default state of the host. Valid states include
  200. started, stopped and suspended. The default initial host state is the state
  201. that will be assumed by the driver if the last known state has not been configured
  202. as a persisted state. That is, when the driver loads, it reads the last known
  203. state of the host from this registry - this is the state that the host was in
  204. when NLB was unbound from the adapter. If that state is supposed to be persisted,
  205. as configured by a user (see bPersistSuspendOnReboot below), then the driver will
  206. assume that state. If the last known state was not configured to be persisted,
  207. then the driver will ignore the last known state and assume the default initial
  208. state configured by the user - this is the legacy NLB behavior and should continue
  209. to be the most common behavior. */
  210. if (a_WlbsConfig.bClusterModeOnStart)
  211. {
  212. /* If the user has set the bClusterModeOnStart property, that indicates that the
  213. preferred intitial state of the cluster should be started. However, if they
  214. have also set the bClusterModeSuspendOnStart property, we have to choose
  215. whether to start or suspend - we cannot do both. In this case, we give
  216. precedence to the legacy property (bClusterModeOnStart) and start the host. */
  217. NlbRegData.cluster_mode = CVY_HOST_STATE_STARTED;
  218. if (a_WlbsConfig.bClusterModeSuspendOnStart)
  219. {
  220. TRACE_INFO("%!FUNC! Invalid setting : Both bClusterModeOnStart & bClusterModeSuspendOnStart are set to TRUE, Ignoring bClusterModeSuspendOnStart");
  221. }
  222. }
  223. else if (a_WlbsConfig.bClusterModeSuspendOnStart)
  224. {
  225. /* Otherwise, if the bClusterMode on start property was not set, but the
  226. bClusterModeSuspendOnStart flag is set, this indicates a perferred intial
  227. state of suspended. */
  228. NlbRegData.cluster_mode = CVY_HOST_STATE_SUSPENDED;
  229. }
  230. else
  231. {
  232. /* Otherwise, if both properties are reset, we stop the host. */
  233. NlbRegData.cluster_mode = CVY_HOST_STATE_STOPPED;
  234. }
  235. /* Persisted states are independent of default initial host states. Persisted
  236. states are those which the user is requesting that the driver "remember" after
  237. a reboot, while the default initial host state is the state that will be
  238. assumed in all cases where the driver elects not to persist a state. For
  239. instance, it makes perfect sense for an administrator to set the default
  240. initial host state to started, yet ask NLB to persist suspended states. In
  241. that case, if the host was stopped or started when a reboot occurred, the
  242. driver would re-start the host. However, if the host was suspended at the
  243. time the reboot occurred, the driver would remember that and keep the host
  244. suspend after the reboot. At this time, we only allow users to persist
  245. suspended states, which is sort of a maintenance state. The driver can persist
  246. all three states, but we expose only one option to users at this time. */
  247. if (a_WlbsConfig.bPersistSuspendOnReboot)
  248. {
  249. /* Each state to be persisted has its own bit in the persisted states flag register -
  250. Set the bit for persisting suspended states, but leave the other bits unaltered.
  251. Setting this bit tells the driver to remember if the host was suspended. */
  252. NlbRegData.persisted_states |= CVY_PERSIST_STATE_SUSPENDED;
  253. }
  254. else
  255. {
  256. /* Each state to be persisted has its own bit in the persisted states flag register -
  257. Reset the bit for persisting suspended states, but leave the other bits unaltered.
  258. Turning this bit off tells the driver to use the default initial host state if
  259. the last known state was suspended. */
  260. NlbRegData.persisted_states &= ~CVY_PERSIST_STATE_SUSPENDED;
  261. }
  262. // NlbRegData.nbt_support = a_WlbsConfig.bNBTSupportEnable;
  263. NlbRegData.rct_port = a_WlbsConfig.dwRemoteControlUDPPort;
  264. NlbRegData.mask_src_mac = a_WlbsConfig.bMaskSourceMAC;
  265. NlbRegData.dscr_per_alloc = a_WlbsConfig.dwDescriptorsPerAlloc;
  266. NlbRegData.max_dscr_allocs = a_WlbsConfig.dwMaxDescriptorAllocs;
  267. NlbRegData.filter_icmp = a_WlbsConfig.dwFilterIcmp;
  268. NlbRegData.tcp_dscr_timeout = a_WlbsConfig.dwTcpDescriptorTimeout;
  269. NlbRegData.ipsec_dscr_timeout = a_WlbsConfig.dwIpSecDescriptorTimeout;
  270. NlbRegData.num_actions = a_WlbsConfig.dwNumActions;
  271. NlbRegData.num_packets = a_WlbsConfig.dwNumPackets;
  272. NlbRegData.num_send_msgs = a_WlbsConfig.dwNumAliveMsgs;
  273. //set dedicated IP
  274. wcsncpy
  275. (
  276. NlbRegData.ded_ip_addr,
  277. a_WlbsConfig.szDedicatedIPAddress.c_str(),
  278. WLBS_MAX_DED_IP_ADDR
  279. );
  280. //set dedicated mask
  281. wcsncpy
  282. (
  283. NlbRegData.ded_net_mask,
  284. a_WlbsConfig.szDedicatedNetworkMask.c_str(),
  285. WLBS_MAX_DED_NET_MASK
  286. );
  287. dwWlbsRegRes = CWlbsCluster::WriteConfig(&NlbRegData);
  288. if( dwWlbsRegRes != WLBS_OK )
  289. {
  290. TRACE_CRIT("%!FUNC! CWlbsCluster::WriteConfig returned : 0x%x, Throwing Wlbs error exception",dwWlbsRegRes);
  291. TRACE_VERB("<-%!FUNC!");
  292. throw CErrorWlbsControl( dwWlbsRegRes, CmdWlbsWriteReg );
  293. }
  294. TRACE_VERB("<-%!FUNC!");
  295. }
  296. ////////////////////////////////////////////////////////////////////////////////
  297. //
  298. // CWlbsClusterWrapper::Commit
  299. //
  300. // Purpose: This function invokes WlbsCommitChanges, which causes the driver to
  301. // load the current registry parameters.
  302. //
  303. // Return: This function returns either WLBS_OK or WLBS_REBOOT. All other
  304. // Wlbs return values cause this function to throw WBEM_E_FAILED.
  305. //
  306. // Note: The wlbs API currently caches the cluster and dedicated IP addreses.
  307. // As a result, if a user changes these values via a source external
  308. // to this provider, the cached values will fall out of sync. To
  309. // prevent this, a WlbsWriteReg is invoked to force the cache to
  310. // update.
  311. //
  312. ////////////////////////////////////////////////////////////////////////////////
  313. DWORD CWlbsClusterWrapper::Commit(CWlbsControlWrapper* pControl)
  314. {
  315. WLBS_REG_PARAMS WlbsRegData;
  316. DWORD dwExtRes;
  317. TRACE_VERB("->%!FUNC!");
  318. dwExtRes = CWlbsCluster::CommitChanges(&pControl->m_WlbsControl);
  319. if( dwExtRes != WLBS_OK && dwExtRes != WLBS_REBOOT )
  320. {
  321. TRACE_CRIT("%!FUNC! CommitChanges returned error = 0x%x, Throwing Wlbs error exception",dwExtRes);
  322. TRACE_VERB("<-%!FUNC!");
  323. throw CErrorWlbsControl( dwExtRes, CmdWlbsCommitChanges );
  324. }
  325. TRACE_VERB("<-%!FUNC! return = 0x%x",dwExtRes);
  326. return dwExtRes;
  327. }
  328. ////////////////////////////////////////////////////////////////////////////////
  329. //
  330. // CWlbsClusterWrapper::SetPassword
  331. //
  332. // Purpose: This function encodes the WLBS remote control password and saves
  333. // it in the registry.
  334. //
  335. ////////////////////////////////////////////////////////////////////////////////
  336. void CWlbsClusterWrapper::SetPassword( LPWSTR a_szPassword )
  337. {
  338. WLBS_REG_PARAMS RegData;
  339. TRACE_VERB("->%!FUNC!");
  340. DWORD dwRes = CWlbsCluster::ReadConfig(&RegData );
  341. if( dwRes != WLBS_OK )
  342. {
  343. TRACE_CRIT("%!FUNC! ReadConfig returned error = 0x%x, Throwing Wlbs error exception",dwRes);
  344. TRACE_VERB("<-%!FUNC!");
  345. throw CErrorWlbsControl( dwRes, CmdWlbsReadReg );
  346. }
  347. dwRes = WlbsSetRemotePassword( &RegData, a_szPassword );
  348. if( dwRes != WLBS_OK )
  349. {
  350. TRACE_CRIT("%!FUNC! WlbsSetRemotePassword returned error = 0x%x, Throwing Wlbs error exception",dwRes);
  351. TRACE_VERB("<-%!FUNC!");
  352. throw CErrorWlbsControl( dwRes, CmdWlbsSetRemotePassword );
  353. }
  354. dwRes = CWlbsCluster::WriteConfig( &RegData );
  355. if( dwRes != WLBS_OK )
  356. {
  357. TRACE_CRIT("%!FUNC! WriteConfig returned error = 0x%x, Throwing Wlbs error exception",dwRes);
  358. TRACE_VERB("<-%!FUNC!");
  359. throw CErrorWlbsControl( dwRes, CmdWlbsWriteReg );
  360. }
  361. TRACE_VERB("<-%!FUNC!");
  362. }
  363. ////////////////////////////////////////////////////////////////////////////////
  364. //
  365. // CWlbsClusterWrapper::GetPortRule
  366. //
  367. // Purpose: This function retrieves the port rule that encompasses the requested
  368. // port.
  369. //
  370. ////////////////////////////////////////////////////////////////////////////////
  371. void CWlbsClusterWrapper::GetPortRule( DWORD a_dwVip, DWORD a_dwPort, PWLBS_PORT_RULE a_pPortRule )
  372. {
  373. WLBS_REG_PARAMS WlbsParam;
  374. TRACE_VERB("->%!FUNC!");
  375. DWORD dwWlbsRegRes = CWlbsCluster::ReadConfig(&WlbsParam );
  376. if( dwWlbsRegRes != WLBS_OK )
  377. {
  378. TRACE_CRIT("%!FUNC! ReadConfig returned error = 0x%x, Throwing Wlbs error exception",dwWlbsRegRes);
  379. TRACE_VERB("<-%!FUNC!");
  380. throw CErrorWlbsControl( dwWlbsRegRes, CmdWlbsReadReg );
  381. }
  382. DWORD dwRes = WlbsGetPortRule( &WlbsParam, a_dwVip, a_dwPort, a_pPortRule );
  383. if( dwRes == WLBS_NOT_FOUND )
  384. {
  385. TRACE_CRIT("%!FUNC! WlbsGetPortRule returned WLBS_NOT_FOUND, Throwing com_error WBEM_E_NOT_FOUND exception");
  386. TRACE_VERB("<-%!FUNC!");
  387. throw _com_error( WBEM_E_NOT_FOUND );
  388. }
  389. if( dwRes != WLBS_OK )
  390. {
  391. TRACE_CRIT("%!FUNC! WlbsGetPortRule returned error = 0x%x, Throwing Wlbs error exception",dwRes);
  392. TRACE_VERB("<-%!FUNC!");
  393. throw CErrorWlbsControl( dwRes, CmdWlbsGetPortRule );
  394. }
  395. TRACE_VERB("<-%!FUNC!");
  396. }
  397. ////////////////////////////////////////////////////////////////////////////////
  398. //
  399. // CWlbsClusterWrapper::EnumPortRules
  400. //
  401. // Purpose: This function retrieves all of the port rules of a given type. The
  402. // function allocates memory for the received port rules. It is up
  403. // to the caller to free the memory. The number of rules retrieved is
  404. // placed in the a_dwNumRules parameter.
  405. //
  406. // Note: Setting a_FilteringMode = 0 instructs function to retrieve all the
  407. // port rules.
  408. //
  409. ////////////////////////////////////////////////////////////////////////////////
  410. void CWlbsClusterWrapper::EnumPortRules
  411. (
  412. WLBS_PORT_RULE** a_ppPortRule,
  413. LPDWORD a_pdwNumRules,
  414. DWORD a_FilteringMode
  415. )
  416. {
  417. WLBS_PORT_RULE AllPortRules[WLBS_MAX_RULES];
  418. DWORD dwTotalNumRules = WLBS_MAX_RULES;
  419. TRACE_VERB("->%!FUNC!");
  420. ASSERT( a_ppPortRule );
  421. WLBS_REG_PARAMS WlbsParam;
  422. DWORD dwRes = CWlbsCluster::ReadConfig(&WlbsParam );
  423. if( dwRes != WLBS_OK )
  424. {
  425. TRACE_CRIT("%!FUNC! ReadConfig returned error = 0x%x, Throwing Wlbs error exception",dwRes);
  426. TRACE_VERB("<-%!FUNC!");
  427. throw CErrorWlbsControl( dwRes, CmdWlbsReadReg );
  428. }
  429. dwRes = WlbsEnumPortRules( &WlbsParam, AllPortRules, &dwTotalNumRules );
  430. if( dwRes != WLBS_OK )
  431. {
  432. TRACE_CRIT("%!FUNC! WlbsEnumPortRules returned error = 0x%x, Throwing Wlbs error exception",dwRes);
  433. TRACE_VERB("<-%!FUNC!");
  434. throw CErrorWlbsControl( dwRes, CmdWlbsEnumPortRules );
  435. }
  436. if( dwTotalNumRules == 0 ) {
  437. a_pdwNumRules = 0;
  438. TRACE_CRIT("%!FUNC! WlbsEnumPortRules returned zero port rules");
  439. TRACE_VERB("<-%!FUNC!");
  440. return;
  441. }
  442. long nMaxSelRuleIndex = -1;
  443. DWORD dwSelectedPortRules[WLBS_MAX_RULES];
  444. //loop through all of the port rules
  445. for( DWORD i = 0; i < dwTotalNumRules; i++) {
  446. if( a_FilteringMode == 0 || AllPortRules[i].mode == a_FilteringMode )
  447. dwSelectedPortRules[++nMaxSelRuleIndex] = i;
  448. }
  449. //if rule counter is less than zero, then return not found
  450. if( nMaxSelRuleIndex < 0 ) {
  451. a_pdwNumRules = 0;
  452. TRACE_CRIT("%!FUNC! Rule counter is less than zero");
  453. TRACE_VERB("<-%!FUNC!");
  454. return;
  455. }
  456. *a_ppPortRule = new WLBS_PORT_RULE[nMaxSelRuleIndex+1];
  457. if( !*a_ppPortRule )
  458. {
  459. TRACE_CRIT("%!FUNC! new failed, Throwing com error WBEM_E_OUT_OF_MEMORY exception");
  460. TRACE_VERB("<-%!FUNC!");
  461. throw _com_error( WBEM_E_OUT_OF_MEMORY );
  462. }
  463. PWLBS_PORT_RULE pRule = *a_ppPortRule;
  464. for( i = 0; i <= (DWORD)nMaxSelRuleIndex; i++ ) {
  465. CopyMemory( pRule++,
  466. &AllPortRules[dwSelectedPortRules[i]],
  467. sizeof( WLBS_PORT_RULE ) );
  468. }
  469. *a_pdwNumRules = nMaxSelRuleIndex + 1;
  470. TRACE_VERB("<-%!FUNC!");
  471. return;
  472. }
  473. ////////////////////////////////////////////////////////////////////////////////
  474. //
  475. // CWlbsClusterWrapper::RuleExists
  476. //
  477. // Purpose: This function checks for the existence of a rule that has start
  478. // and end ports that match the input values.
  479. //
  480. ////////////////////////////////////////////////////////////////////////////////
  481. bool CWlbsClusterWrapper::RuleExists(DWORD a_dwVip, DWORD a_dwStartPort )
  482. {
  483. WLBS_REG_PARAMS WlbsParam;
  484. TRACE_VERB("->%!FUNC!");
  485. DWORD dwRes = CWlbsCluster::ReadConfig(&WlbsParam );
  486. if( dwRes != WLBS_OK )
  487. {
  488. TRACE_CRIT("%!FUNC! ReadConfig returned error = 0x%x, Throwing Wlbs error exception",dwRes);
  489. TRACE_VERB("<-%!FUNC!");
  490. throw CErrorWlbsControl( dwRes, CmdWlbsReadReg );
  491. }
  492. WLBS_PORT_RULE PortRule;
  493. dwRes = WlbsGetPortRule( &WlbsParam, a_dwVip, a_dwStartPort, &PortRule );
  494. if( dwRes == WLBS_NOT_FOUND )
  495. {
  496. TRACE_VERB("<-%!FUNC! return = false");
  497. return false;
  498. }
  499. if( dwRes != WLBS_OK )
  500. {
  501. TRACE_CRIT("%!FUNC! WlbsGetPortRule returned error = 0x%x, Throwing Wlbs error exception",dwRes);
  502. TRACE_VERB("<-%!FUNC!");
  503. throw CErrorWlbsControl( dwRes, CmdWlbsGetPortRule );
  504. }
  505. if( PortRule.start_port == a_dwStartPort )
  506. {
  507. TRACE_VERB("<-%!FUNC! return = true");
  508. return true;
  509. }
  510. TRACE_VERB("<-%!FUNC! return = false");
  511. return false;
  512. }
  513. ////////////////////////////////////////////////////////////////////////////////
  514. //
  515. // CWlbsClusterWrapper::DeletePortRule
  516. //
  517. // Purpose: This function deletes the rule that contains the input port.
  518. //
  519. ////////////////////////////////////////////////////////////////////////////////
  520. void CWlbsClusterWrapper::DeletePortRule(DWORD a_dwVip, DWORD a_dwPort )
  521. {
  522. WLBS_REG_PARAMS WlbsParam;
  523. TRACE_VERB("->%!FUNC!");
  524. DWORD dwRes = CWlbsCluster::ReadConfig(&WlbsParam );
  525. if( dwRes != WLBS_OK )
  526. {
  527. TRACE_CRIT("%!FUNC! CWlbsCluster::ReadConfig returned error = 0x%x, Throwing Wlbs error exception",dwRes);
  528. TRACE_VERB("<-%!FUNC!");
  529. throw CErrorWlbsControl( dwRes, CmdWlbsReadReg );
  530. }
  531. dwRes = WlbsDeletePortRule( &WlbsParam, a_dwVip, a_dwPort );
  532. if( dwRes == WBEM_E_NOT_FOUND )
  533. {
  534. TRACE_CRIT("%!FUNC! WlbsDeletePortRule returned WBEM_E_NOT_FOUND, Throwing com_error WBEM_E_NOT_FOUND exception");
  535. TRACE_VERB("<-%!FUNC!");
  536. throw _com_error( WBEM_E_NOT_FOUND );
  537. }
  538. if( dwRes != WLBS_OK )
  539. {
  540. TRACE_CRIT("%!FUNC! WlbsDeletePortRule returned error = 0x%x, Throwing Wlbs error exception",dwRes);
  541. TRACE_VERB("<-%!FUNC!");
  542. throw CErrorWlbsControl( dwRes, CmdWlbsDeletePortRule );
  543. }
  544. dwRes = CWlbsCluster::WriteConfig(&WlbsParam );
  545. if( dwRes != WLBS_OK )
  546. {
  547. TRACE_CRIT("%!FUNC! CWlbsCluster::WriteConfig returned error : 0x%x, Throwing Wlbs error exception",dwRes);
  548. TRACE_VERB("<-%!FUNC!");
  549. throw CErrorWlbsControl( dwRes, CmdWlbsWriteReg );
  550. }
  551. TRACE_VERB("<-%!FUNC!");
  552. }
  553. ////////////////////////////////////////////////////////////////////////////////
  554. //
  555. // CWlbsClusterWrapper::PutPortRule
  556. //
  557. // Purpose: This function adds a rule.
  558. //
  559. ////////////////////////////////////////////////////////////////////////////////
  560. void CWlbsClusterWrapper::PutPortRule(const PWLBS_PORT_RULE a_pPortRule)
  561. {
  562. WLBS_REG_PARAMS WlbsParam;
  563. TRACE_VERB("->%!FUNC!");
  564. DWORD dwRes = CWlbsCluster::ReadConfig(&WlbsParam );
  565. if( dwRes != WLBS_OK )
  566. {
  567. TRACE_CRIT("%!FUNC! CWlbsCluster::ReadConfig returned error = 0x%x, Throwing Wlbs error exception",dwRes);
  568. TRACE_VERB("<-%!FUNC!");
  569. throw CErrorWlbsControl( dwRes, CmdWlbsReadReg );
  570. }
  571. dwRes = WlbsAddPortRule( &WlbsParam, a_pPortRule );
  572. if( dwRes != WLBS_OK )
  573. {
  574. TRACE_CRIT("%!FUNC! WlbsAddPortRule returned error : 0x%x, Throwing Wlbs error exception",dwRes);
  575. TRACE_VERB("<-%!FUNC!");
  576. throw CErrorWlbsControl( dwRes, CmdWlbsAddPortRule );
  577. }
  578. dwRes = CWlbsCluster::WriteConfig(&WlbsParam );
  579. if( dwRes != WLBS_OK )
  580. {
  581. TRACE_CRIT("%!FUNC! CWlbsCluster::WriteConfig returned error : 0x%x, Throwing Wlbs error exception",dwRes);
  582. TRACE_VERB("<-%!FUNC!");
  583. throw CErrorWlbsControl( dwRes, CmdWlbsWriteReg );
  584. }
  585. TRACE_VERB("<-%!FUNC!");
  586. return;
  587. }
  588. DWORD CWlbsClusterWrapper::GetClusterIpOrIndex(CWlbsControlWrapper* pControl)
  589. {
  590. return CWlbsCluster::GetClusterIpOrIndex(&pControl->m_WlbsControl);
  591. }
  592. ////////////////////////////////////////////////////////////////////////////////
  593. //
  594. // CWlbsClusterWrapper::GetHostID
  595. //
  596. // Purpose: Obtain ID of the local host.
  597. //
  598. ////////////////////////////////////////////////////////////////////////////////
  599. DWORD CWlbsClusterWrapper::GetHostID()
  600. {
  601. return CWlbsCluster::GetHostID();
  602. /*
  603. WLBS_RESPONSE WlbsResponse;
  604. DWORD dwResSize = 1;
  605. //get the cluster and HostID
  606. DWORD dwRes = WlbsQuery( CWlbsCluster::GetClusterIp(),
  607. WLBS_LOCAL_HOST,
  608. &WlbsResponse,
  609. &dwResSize,
  610. NULL,
  611. NULL );
  612. //analyze query results for errors
  613. switch( dwRes ) {
  614. case WLBS_OK:
  615. case WLBS_STOPPED:
  616. case WLBS_CONVERGING:
  617. case WLBS_CONVERGED:
  618. case WLBS_DEFAULT:
  619. case WLBS_DRAINING:
  620. case WLBS_SUSPENDED:
  621. break;
  622. default:
  623. throw CErrorWlbsControl( dwRes, CmdWlbsQuery );
  624. }
  625. return WlbsResponse.id;
  626. */
  627. }
  628. ////////////////////////////////////////////////////////////////////////////////
  629. //
  630. // CWlbsClusterWrapper::SetNodeDefaults
  631. //
  632. // Purpose: This routine obtains the default configuration and sets the node
  633. // setting properties to their defaults without affecting the other
  634. // values.
  635. //
  636. ////////////////////////////////////////////////////////////////////////////////
  637. void CWlbsClusterWrapper::SetNodeDefaults()
  638. {
  639. WLBS_REG_PARAMS WlbsConfiguration;
  640. WLBS_REG_PARAMS WlbsDefaultConfiguration;
  641. TRACE_VERB("->%!FUNC!");
  642. //get current configuration
  643. DWORD dwRes = CWlbsCluster::ReadConfig(&WlbsConfiguration );
  644. if( dwRes != WLBS_OK )
  645. {
  646. TRACE_CRIT("%!FUNC! CWlbsCluster::ReadConfig returned error = 0x%x, Throwing Wlbs error exception",dwRes);
  647. TRACE_VERB("<-%!FUNC!");
  648. throw CErrorWlbsControl( dwRes, CmdWlbsReadReg );
  649. }
  650. //get the default configuration
  651. dwRes = WlbsSetDefaults(&WlbsDefaultConfiguration );
  652. if( dwRes != WLBS_OK )
  653. {
  654. TRACE_CRIT("%!FUNC! WlbsSetDefaults returned error = 0x%x, Throwing Wlbs error exception",dwRes);
  655. TRACE_VERB("<-%!FUNC!");
  656. throw CErrorWlbsControl( dwRes, CmdWlbsSetDefaults );
  657. }
  658. //modify current configuration with
  659. //default configuration
  660. WlbsConfiguration.host_priority = WlbsDefaultConfiguration.host_priority;
  661. WlbsConfiguration.alive_period = WlbsDefaultConfiguration.alive_period;
  662. WlbsConfiguration.alive_tolerance = WlbsDefaultConfiguration.alive_tolerance;
  663. WlbsConfiguration.cluster_mode = WlbsDefaultConfiguration.cluster_mode;
  664. WlbsConfiguration.persisted_states= WlbsDefaultConfiguration.persisted_states;
  665. WlbsConfiguration.rct_port = WlbsDefaultConfiguration.rct_port;
  666. WlbsConfiguration.mask_src_mac = WlbsDefaultConfiguration.mask_src_mac;
  667. WlbsConfiguration.dscr_per_alloc = WlbsDefaultConfiguration.dscr_per_alloc;
  668. WlbsConfiguration.max_dscr_allocs = WlbsDefaultConfiguration.max_dscr_allocs;
  669. WlbsConfiguration.filter_icmp = WlbsDefaultConfiguration.filter_icmp;
  670. WlbsConfiguration.tcp_dscr_timeout= WlbsDefaultConfiguration.tcp_dscr_timeout;
  671. WlbsConfiguration.ipsec_dscr_timeout= WlbsDefaultConfiguration.ipsec_dscr_timeout;
  672. WlbsConfiguration.num_actions = WlbsDefaultConfiguration.num_actions;
  673. WlbsConfiguration.num_packets = WlbsDefaultConfiguration.num_packets;
  674. WlbsConfiguration.num_send_msgs = WlbsDefaultConfiguration.num_send_msgs;
  675. //set dedicated IP
  676. wcsncpy
  677. (
  678. WlbsConfiguration.ded_ip_addr,
  679. WlbsDefaultConfiguration.ded_ip_addr,
  680. WLBS_MAX_DED_IP_ADDR
  681. );
  682. //set dedicated mask
  683. wcsncpy
  684. (
  685. WlbsConfiguration.ded_net_mask,
  686. WlbsDefaultConfiguration.ded_net_mask,
  687. WLBS_MAX_DED_NET_MASK
  688. );
  689. //write the default configuration
  690. dwRes = CWlbsCluster::WriteConfig(&WlbsConfiguration);
  691. if( dwRes != WLBS_OK )
  692. {
  693. TRACE_CRIT("%!FUNC! CWlbsCluster::WriteConfig returned error = 0x%x, Throwing Wlbs error exception",dwRes);
  694. TRACE_VERB("<-%!FUNC!");
  695. throw CErrorWlbsControl( dwRes, CmdWlbsWriteReg );
  696. }
  697. TRACE_VERB("<-%!FUNC!");
  698. }
  699. ////////////////////////////////////////////////////////////////////////////////
  700. //
  701. // CWlbsClusterWrapper::SetClusterDefaults
  702. //
  703. // Purpose: This routine obtains the default configuration and sets the cluster
  704. // setting properties to their defaults without affecting the other
  705. // values.
  706. //
  707. ////////////////////////////////////////////////////////////////////////////////
  708. void CWlbsClusterWrapper::SetClusterDefaults()
  709. {
  710. WLBS_REG_PARAMS WlbsConfiguration;
  711. WLBS_REG_PARAMS WlbsDefaultConfiguration;
  712. TRACE_VERB("->%!FUNC!");
  713. //get current configuration
  714. DWORD dwRes = CWlbsCluster::ReadConfig(&WlbsConfiguration );
  715. if( dwRes != WLBS_OK )
  716. {
  717. TRACE_CRIT("%!FUNC! CWlbsCluster::ReadConfig returned error = 0x%x, Throwing Wlbs error exception",dwRes);
  718. TRACE_VERB("<-%!FUNC!");
  719. throw CErrorWlbsControl( dwRes, CmdWlbsReadReg );
  720. }
  721. //get the default configuration
  722. dwRes = WlbsSetDefaults(&WlbsDefaultConfiguration );
  723. if( dwRes != WLBS_OK )
  724. {
  725. TRACE_CRIT("%!FUNC! WlbsSetDefaults returned error = 0x%x, Throwing Wlbs error exception",dwRes);
  726. TRACE_VERB("<-%!FUNC!");
  727. throw CErrorWlbsControl( dwRes, CmdWlbsSetDefaults );
  728. }
  729. //modify current configuration
  730. wcsncpy
  731. (
  732. WlbsConfiguration.domain_name,
  733. WlbsDefaultConfiguration.domain_name,
  734. WLBS_MAX_DOMAIN_NAME
  735. );
  736. wcsncpy
  737. (
  738. WlbsConfiguration.cl_net_mask,
  739. WlbsDefaultConfiguration.cl_net_mask,
  740. WLBS_MAX_CL_NET_MASK
  741. );
  742. wcsncpy
  743. (
  744. WlbsConfiguration.cl_ip_addr ,
  745. WlbsDefaultConfiguration.cl_ip_addr,
  746. WLBS_MAX_CL_IP_ADDR
  747. );
  748. WlbsConfiguration.mcast_support = WlbsDefaultConfiguration.mcast_support;
  749. WlbsConfiguration.rct_enabled = WlbsDefaultConfiguration.rct_enabled;
  750. WlbsConfiguration.fIGMPSupport = WlbsDefaultConfiguration.fIGMPSupport;
  751. WlbsConfiguration.fIpToMCastIp = WlbsDefaultConfiguration.fIpToMCastIp;
  752. wcsncpy
  753. (
  754. WlbsConfiguration.szMCastIpAddress ,
  755. WlbsDefaultConfiguration.szMCastIpAddress,
  756. WLBS_MAX_CL_IP_ADDR
  757. );
  758. // Copy over BDA values
  759. WlbsConfiguration.bda_teaming.active = WlbsDefaultConfiguration.bda_teaming.active;
  760. if (WlbsConfiguration.bda_teaming.active)
  761. {
  762. wcsncpy
  763. (
  764. WlbsConfiguration.bda_teaming.team_id,
  765. WlbsDefaultConfiguration.bda_teaming.team_id,
  766. WLBS_MAX_BDA_TEAM_ID
  767. );
  768. WlbsConfiguration.bda_teaming.master = WlbsDefaultConfiguration.bda_teaming.master;
  769. WlbsConfiguration.bda_teaming.reverse_hash = WlbsDefaultConfiguration.bda_teaming.reverse_hash;
  770. }
  771. //write the default configuration
  772. dwRes = CWlbsCluster::WriteConfig(&WlbsConfiguration );
  773. if( dwRes != WLBS_OK )
  774. {
  775. TRACE_CRIT("%!FUNC! CWlbsCluster::WriteConfig returned error = 0x%x, Throwing Wlbs error exception",dwRes);
  776. TRACE_VERB("<-%!FUNC!");
  777. throw CErrorWlbsControl( dwRes, CmdWlbsWriteReg );
  778. }
  779. TRACE_VERB("<-%!FUNC!");
  780. }
  781. ////////////////////////////////////////////////////////////////////////////////
  782. //
  783. // CWlbsClusterWrapper::SetPortRuleDefaults
  784. //
  785. // Purpose: This routine obtains the current NLB configuration and the default
  786. // configuration. All of the port rules are removed in the current
  787. // configuration and replaced by the default configuration.
  788. //
  789. // Note: The routine only uses WLBS API calls to replace the current port
  790. // rule configuration with the default configuration. This is not
  791. // the most efficient method, but it avoids making assumptions
  792. // about the underlying data structure.
  793. //
  794. ////////////////////////////////////////////////////////////////////////////////
  795. void CWlbsClusterWrapper::SetPortRuleDefaults()
  796. {
  797. WLBS_REG_PARAMS WlbsConfiguration;
  798. WLBS_REG_PARAMS WlbsDefaultConfiguration;
  799. WLBS_PORT_RULE PortRules[WLBS_MAX_RULES];
  800. DWORD dwNumRules = WLBS_MAX_RULES;
  801. TRACE_VERB("->%!FUNC!");
  802. //get current configuration
  803. DWORD dwRes = CWlbsCluster::ReadConfig(&WlbsConfiguration );
  804. if( dwRes != WLBS_OK )
  805. {
  806. TRACE_CRIT("%!FUNC! CWlbsCluster::ReadConfig returned error = 0x%x, Throwing Wlbs error exception",dwRes);
  807. TRACE_VERB("<-%!FUNC!");
  808. throw CErrorWlbsControl( dwRes, CmdWlbsReadReg );
  809. }
  810. //get the default configuration
  811. dwRes = WlbsSetDefaults(&WlbsDefaultConfiguration );
  812. if( dwRes != WLBS_OK )
  813. {
  814. TRACE_CRIT("%!FUNC! WlbsSetDefaults returned error = 0x%x, Throwing Wlbs error exception",dwRes);
  815. TRACE_VERB("<-%!FUNC!");
  816. throw CErrorWlbsControl( dwRes, CmdWlbsSetDefaults );
  817. }
  818. //get the current port rules
  819. dwRes = WlbsEnumPortRules( &WlbsConfiguration,
  820. PortRules,
  821. &dwNumRules );
  822. if( dwRes != WLBS_OK )
  823. {
  824. TRACE_CRIT("%!FUNC! WlbsEnumPortRules returned error = 0x%x, Throwing Wlbs error exception",dwRes);
  825. TRACE_VERB("<-%!FUNC!");
  826. throw CErrorWlbsControl( dwRes, CmdWlbsEnumPortRules );
  827. }
  828. //remove all of the current port rules
  829. DWORD i = 0;
  830. for( i = 0; i < dwNumRules; i++ )
  831. {
  832. //make sure that this works as expected i.e. the indexes must be valid
  833. dwRes = WlbsDeletePortRule( &WlbsConfiguration, IpAddressFromAbcdWsz(PortRules[i].virtual_ip_addr), PortRules[i].start_port );
  834. if( dwRes != WLBS_OK )
  835. {
  836. TRACE_CRIT("%!FUNC! WlbsDeletePortRule returned error = 0x%x, Throwing Wlbs error exception",dwRes);
  837. TRACE_VERB("<-%!FUNC!");
  838. throw CErrorWlbsControl( dwRes, CmdWlbsDeletePortRule );
  839. }
  840. }
  841. //get the default port rules
  842. dwNumRules = WLBS_MAX_RULES;
  843. dwRes = WlbsEnumPortRules( &WlbsDefaultConfiguration,
  844. PortRules,
  845. &dwNumRules );
  846. if( dwRes != WLBS_OK )
  847. {
  848. TRACE_CRIT("%!FUNC! WlbsEnumPortRules returned error = 0x%x, Throwing Wlbs error exception",dwRes);
  849. TRACE_VERB("<-%!FUNC!");
  850. throw CErrorWlbsControl( dwRes, CmdWlbsEnumPortRules );
  851. }
  852. //add the default port rules
  853. for( i = 0; i < dwNumRules; i++ )
  854. {
  855. dwRes = WlbsAddPortRule( &WlbsConfiguration, &PortRules[i] );
  856. if( dwRes != WLBS_OK )
  857. {
  858. TRACE_CRIT("%!FUNC! WlbsAddPortRule returned error = 0x%x, Throwing Wlbs error exception",dwRes);
  859. TRACE_VERB("<-%!FUNC!");
  860. throw CErrorWlbsControl( dwRes, CmdWlbsAddPortRule );
  861. }
  862. }
  863. dwRes = CWlbsCluster::WriteConfig(&WlbsConfiguration );
  864. if( dwRes != WLBS_OK )
  865. {
  866. TRACE_CRIT("%!FUNC! CWlbsCluster::WriteConfig returned error = 0x%x, Throwing Wlbs error exception",dwRes);
  867. TRACE_VERB("<-%!FUNC!");
  868. throw CErrorWlbsControl( dwRes, CmdWlbsWriteReg );
  869. }
  870. TRACE_VERB("<-%!FUNC!");
  871. return;
  872. }