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.

766 lines
23 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. ////////////////////////////////////////////////////////////////////////////////
  22. //
  23. // CWlbsClusterWrapper::GetClusterConfig
  24. //
  25. // Purpose: This is used to obtain the current
  26. // cluster configuration.
  27. //
  28. ////////////////////////////////////////////////////////////////////////////////
  29. void CWlbsClusterWrapper::GetClusterConfig( CClusterConfiguration& a_WlbsConfig )
  30. {
  31. WLBS_REG_PARAMS WlbsParam;
  32. DWORD dwWlbsRegRes = CWlbsCluster::ReadConfig(&WlbsParam );
  33. if( dwWlbsRegRes != WLBS_OK )
  34. throw CErrorWlbsControl( dwWlbsRegRes, CmdWlbsReadReg );
  35. a_WlbsConfig.szClusterName = WlbsParam.domain_name;
  36. a_WlbsConfig.szClusterIPAddress = WlbsParam.cl_ip_addr;
  37. a_WlbsConfig.szClusterNetworkMask = WlbsParam.cl_net_mask;
  38. a_WlbsConfig.szClusterMACAddress = WlbsParam.cl_mac_addr;
  39. a_WlbsConfig.bMulticastSupportEnable = ( WlbsParam.mcast_support != 0);
  40. a_WlbsConfig.bRemoteControlEnabled = ( WlbsParam.rct_enabled != 0 );
  41. a_WlbsConfig.nMaxNodes = WLBS_MAX_HOSTS;
  42. a_WlbsConfig.bIgmpSupport = (WlbsParam.fIGMPSupport != FALSE);
  43. a_WlbsConfig.bClusterIPToMulticastIP = (WlbsParam.fIpToMCastIp != FALSE);
  44. a_WlbsConfig.szMulticastIPAddress = WlbsParam.szMCastIpAddress;
  45. a_WlbsConfig.bBDATeamActive = (WlbsParam.bda_teaming.active != 0);
  46. if (a_WlbsConfig.bBDATeamActive)
  47. {
  48. a_WlbsConfig.szBDATeamId = WlbsParam.bda_teaming.team_id;
  49. a_WlbsConfig.bBDATeamMaster = (WlbsParam.bda_teaming.master != 0);
  50. a_WlbsConfig.bBDAReverseHash = (WlbsParam.bda_teaming.reverse_hash != 0);
  51. }
  52. }
  53. ////////////////////////////////////////////////////////////////////////////////
  54. //
  55. // CWlbsClusterWrapper::GetNodeConfig
  56. //
  57. // Purpose: This function retrieves the current WLBS configuration and selects
  58. // only NodeSetting pertinent information. The information is passed
  59. // back in a CNodeConfiguration class instance.
  60. //
  61. ////////////////////////////////////////////////////////////////////////////////
  62. void CWlbsClusterWrapper::GetNodeConfig( CNodeConfiguration& a_WlbsConfig )
  63. {
  64. WLBS_REG_PARAMS WlbsParam;
  65. DWORD dwWlbsRegRes = CWlbsCluster::ReadConfig(&WlbsParam );
  66. if( dwWlbsRegRes != WLBS_OK )
  67. throw CErrorWlbsControl( dwWlbsRegRes, CmdWlbsReadReg );
  68. a_WlbsConfig.szDedicatedIPAddress = WlbsParam.ded_ip_addr;
  69. a_WlbsConfig.szDedicatedNetworkMask = WlbsParam.ded_net_mask;
  70. a_WlbsConfig.bClusterModeOnStart = ( WlbsParam.cluster_mode != 0 );
  71. //a_WlbsConfig.bNBTSupportEnable = ( WlbsParam.nbt_support != 0 );
  72. a_WlbsConfig.bMaskSourceMAC = ( WlbsParam.mask_src_mac != 0 );
  73. a_WlbsConfig.dwNumberOfRules = WlbsGetNumPortRules(&WlbsParam);
  74. a_WlbsConfig.dwCurrentVersion = WlbsParam.alive_period;
  75. a_WlbsConfig.dwHostPriority = WlbsParam.host_priority;
  76. a_WlbsConfig.dwAliveMsgPeriod = WlbsParam.alive_period;
  77. a_WlbsConfig.dwAliveMsgTolerance = WlbsParam.alive_tolerance;
  78. a_WlbsConfig.dwRemoteControlUDPPort = WlbsParam.rct_port;
  79. a_WlbsConfig.dwDescriptorsPerAlloc = WlbsParam.dscr_per_alloc;
  80. a_WlbsConfig.dwMaxDescriptorAllocs = WlbsParam.max_dscr_allocs;
  81. a_WlbsConfig.dwNumActions = WlbsParam.num_actions;
  82. a_WlbsConfig.dwNumPackets = WlbsParam.num_packets;
  83. a_WlbsConfig.dwNumAliveMsgs = WlbsParam.num_send_msgs;
  84. a_WlbsConfig.szDedicatedIPAddress = WlbsParam.ded_ip_addr;
  85. a_WlbsConfig.dwEffectiveVersion = WlbsGetEffectiveVersion(&WlbsParam);
  86. }
  87. ////////////////////////////////////////////////////////////////////////////////
  88. //
  89. // CWlbsClusterWrapper::SetClusterConfig
  90. //
  91. // Purpose: This is used to update the registry with values that originate from
  92. // the MOF ClusterSetting class.
  93. //
  94. ////////////////////////////////////////////////////////////////////////////////
  95. void CWlbsClusterWrapper::PutClusterConfig( const CClusterConfiguration &a_WlbsConfig )
  96. {
  97. WLBS_REG_PARAMS NlbRegData;
  98. DWORD dwWlbsRegRes = CWlbsCluster::ReadConfig(&NlbRegData );
  99. if( dwWlbsRegRes != WLBS_OK )
  100. throw CErrorWlbsControl( dwWlbsRegRes, CmdWlbsReadReg );
  101. wcsncpy
  102. (
  103. NlbRegData.domain_name,
  104. a_WlbsConfig.szClusterName.c_str(),
  105. WLBS_MAX_DOMAIN_NAME
  106. );
  107. wcsncpy
  108. (
  109. NlbRegData.cl_net_mask,
  110. a_WlbsConfig.szClusterNetworkMask.c_str(),
  111. WLBS_MAX_CL_NET_MASK
  112. );
  113. wcsncpy
  114. (
  115. NlbRegData.cl_ip_addr ,
  116. a_WlbsConfig.szClusterIPAddress.c_str(),
  117. WLBS_MAX_CL_IP_ADDR
  118. );
  119. NlbRegData.mcast_support = a_WlbsConfig.bMulticastSupportEnable;
  120. NlbRegData.rct_enabled = a_WlbsConfig.bRemoteControlEnabled;
  121. NlbRegData.fIGMPSupport = a_WlbsConfig.bIgmpSupport;
  122. NlbRegData.fIpToMCastIp = a_WlbsConfig.bClusterIPToMulticastIP;
  123. wcsncpy
  124. (
  125. NlbRegData.szMCastIpAddress ,
  126. a_WlbsConfig.szMulticastIPAddress.c_str(),
  127. WLBS_MAX_CL_IP_ADDR
  128. );
  129. // Fill in BDA information, if active
  130. NlbRegData.bda_teaming.active = a_WlbsConfig.bBDATeamActive;
  131. if (NlbRegData.bda_teaming.active)
  132. {
  133. wcsncpy
  134. (
  135. NlbRegData.bda_teaming.team_id,
  136. a_WlbsConfig.szBDATeamId.c_str(),
  137. WLBS_MAX_BDA_TEAM_ID
  138. );
  139. NlbRegData.bda_teaming.master = a_WlbsConfig.bBDATeamMaster;
  140. NlbRegData.bda_teaming.reverse_hash = a_WlbsConfig.bBDAReverseHash;
  141. }
  142. dwWlbsRegRes = CWlbsCluster::WriteConfig(&NlbRegData );
  143. if( dwWlbsRegRes != WLBS_OK )
  144. throw CErrorWlbsControl( dwWlbsRegRes, CmdWlbsWriteReg );
  145. }
  146. ////////////////////////////////////////////////////////////////////////////////
  147. //
  148. // CWlbsClusterWrapper::PutNodeConfig
  149. //
  150. // Purpose:This is used to update the registry with values that originate from
  151. // the MOF NodeSetting class.
  152. //
  153. ////////////////////////////////////////////////////////////////////////////////
  154. void CWlbsClusterWrapper::PutNodeConfig( const CNodeConfiguration& a_WlbsConfig )
  155. {
  156. WLBS_REG_PARAMS NlbRegData;
  157. DWORD dwWlbsRegRes = CWlbsCluster::ReadConfig(&NlbRegData);
  158. if( dwWlbsRegRes != WLBS_OK )
  159. throw CErrorWlbsControl( dwWlbsRegRes, CmdWlbsReadReg );
  160. NlbRegData.host_priority = a_WlbsConfig.dwHostPriority;
  161. NlbRegData.alive_period = a_WlbsConfig.dwAliveMsgPeriod;
  162. NlbRegData.alive_tolerance = a_WlbsConfig.dwAliveMsgTolerance;
  163. NlbRegData.cluster_mode = a_WlbsConfig.bClusterModeOnStart;
  164. // NlbRegData.nbt_support = a_WlbsConfig.bNBTSupportEnable;
  165. NlbRegData.rct_port = a_WlbsConfig.dwRemoteControlUDPPort;
  166. NlbRegData.mask_src_mac = a_WlbsConfig.bMaskSourceMAC;
  167. NlbRegData.dscr_per_alloc = a_WlbsConfig.dwDescriptorsPerAlloc;
  168. NlbRegData.max_dscr_allocs = a_WlbsConfig.dwMaxDescriptorAllocs;
  169. NlbRegData.num_actions = a_WlbsConfig.dwNumActions;
  170. NlbRegData.num_packets = a_WlbsConfig.dwNumPackets;
  171. NlbRegData.num_send_msgs = a_WlbsConfig.dwNumAliveMsgs;
  172. //set dedicated IP
  173. wcsncpy
  174. (
  175. NlbRegData.ded_ip_addr,
  176. a_WlbsConfig.szDedicatedIPAddress.c_str(),
  177. WLBS_MAX_DED_IP_ADDR
  178. );
  179. //set dedicated mask
  180. wcsncpy
  181. (
  182. NlbRegData.ded_net_mask,
  183. a_WlbsConfig.szDedicatedNetworkMask.c_str(),
  184. WLBS_MAX_DED_NET_MASK
  185. );
  186. dwWlbsRegRes = CWlbsCluster::WriteConfig(&NlbRegData);
  187. if( dwWlbsRegRes != WLBS_OK )
  188. throw CErrorWlbsControl( dwWlbsRegRes, CmdWlbsWriteReg );
  189. }
  190. ////////////////////////////////////////////////////////////////////////////////
  191. //
  192. // CWlbsClusterWrapper::Commit
  193. //
  194. // Purpose: This function invokes WlbsCommitChanges, which causes the driver to
  195. // load the current registry parameters.
  196. //
  197. // Return: This function returns either WLBS_OK or WLBS_REBOOT. All other
  198. // Wlbs return values cause this function to throw WBEM_E_FAILED.
  199. //
  200. // Note: The wlbs API currently caches the cluster and dedicated IP addreses.
  201. // As a result, if a user changes these values via a source external
  202. // to this provider, the cached values will fall out of sync. To
  203. // prevent this, a WlbsWriteReg is invoked to force the cache to
  204. // update.
  205. //
  206. ////////////////////////////////////////////////////////////////////////////////
  207. DWORD CWlbsClusterWrapper::Commit(CWlbsControlWrapper* pControl)
  208. {
  209. WLBS_REG_PARAMS WlbsRegData;
  210. DWORD dwExtRes;
  211. dwExtRes = CWlbsCluster::CommitChanges(&pControl->m_WlbsControl);
  212. if( !(dwExtRes != WLBS_OK || dwExtRes != WLBS_REBOOT) )
  213. throw CErrorWlbsControl( dwExtRes, CmdWlbsCommitChanges );
  214. return dwExtRes;
  215. }
  216. ////////////////////////////////////////////////////////////////////////////////
  217. //
  218. // CWlbsClusterWrapper::SetPassword
  219. //
  220. // Purpose: This function encodes the WLBS remote control password and saves
  221. // it in the registry.
  222. //
  223. ////////////////////////////////////////////////////////////////////////////////
  224. void CWlbsClusterWrapper::SetPassword( LPWSTR a_szPassword )
  225. {
  226. WLBS_REG_PARAMS RegData;
  227. DWORD dwRes = CWlbsCluster::ReadConfig(&RegData );
  228. if( dwRes != WLBS_OK )
  229. throw CErrorWlbsControl( dwRes, CmdWlbsReadReg );
  230. dwRes = WlbsSetRemotePassword( &RegData, a_szPassword );
  231. if( dwRes != WLBS_OK )
  232. throw CErrorWlbsControl( dwRes, CmdWlbsSetRemotePassword );
  233. dwRes = CWlbsCluster::WriteConfig( &RegData );
  234. if( dwRes != WLBS_OK )
  235. throw CErrorWlbsControl( dwRes, CmdWlbsWriteReg );
  236. }
  237. ////////////////////////////////////////////////////////////////////////////////
  238. //
  239. // CWlbsClusterWrapper::GetPortRule
  240. //
  241. // Purpose: This function retrieves the port rule that encompasses the requested
  242. // port.
  243. //
  244. ////////////////////////////////////////////////////////////////////////////////
  245. void CWlbsClusterWrapper::GetPortRule( DWORD a_dwVip, DWORD a_dwPort, PWLBS_PORT_RULE a_pPortRule )
  246. {
  247. WLBS_REG_PARAMS WlbsParam;
  248. DWORD dwWlbsRegRes = CWlbsCluster::ReadConfig(&WlbsParam );
  249. if( dwWlbsRegRes != WLBS_OK )
  250. throw CErrorWlbsControl( dwWlbsRegRes, CmdWlbsReadReg );
  251. DWORD dwRes = WlbsGetPortRule( &WlbsParam, a_dwVip, a_dwPort, a_pPortRule );
  252. if( dwRes == WLBS_NOT_FOUND )
  253. throw _com_error( WBEM_E_NOT_FOUND );
  254. if( dwRes != WLBS_OK )
  255. throw CErrorWlbsControl( dwRes, CmdWlbsGetPortRule );
  256. }
  257. ////////////////////////////////////////////////////////////////////////////////
  258. //
  259. // CWlbsClusterWrapper::EnumPortRules
  260. //
  261. // Purpose: This function retrieves all of the port rules of a given type. The
  262. // function allocates memory for the received port rules. It is up
  263. // to the caller to free the memory. The number of rules retrieved is
  264. // placed in the a_dwNumRules parameter.
  265. //
  266. // Note: Setting a_FilteringMode = 0 instructs function to retrieve all the
  267. // port rules.
  268. //
  269. ////////////////////////////////////////////////////////////////////////////////
  270. void CWlbsClusterWrapper::EnumPortRules
  271. (
  272. WLBS_PORT_RULE** a_ppPortRule,
  273. LPDWORD a_pdwNumRules,
  274. DWORD a_FilteringMode
  275. )
  276. {
  277. WLBS_PORT_RULE AllPortRules[WLBS_MAX_RULES];
  278. DWORD dwTotalNumRules = WLBS_MAX_RULES;
  279. ASSERT( a_ppPortRule );
  280. WLBS_REG_PARAMS WlbsParam;
  281. DWORD dwRes = CWlbsCluster::ReadConfig(&WlbsParam );
  282. if( dwRes != WLBS_OK )
  283. throw CErrorWlbsControl( dwRes, CmdWlbsReadReg );
  284. dwRes = WlbsEnumPortRules( &WlbsParam, AllPortRules, &dwTotalNumRules );
  285. if( dwRes != WLBS_OK )
  286. throw CErrorWlbsControl( dwRes, CmdWlbsEnumPortRules );
  287. if( dwTotalNumRules == 0 ) {
  288. a_pdwNumRules = 0;
  289. return;
  290. }
  291. long nMaxSelRuleIndex = -1;
  292. DWORD dwSelectedPortRules[WLBS_MAX_RULES];
  293. //loop through all of the port rules
  294. for( DWORD i = 0; i < dwTotalNumRules; i++) {
  295. if( a_FilteringMode == 0 || AllPortRules[i].mode == a_FilteringMode )
  296. dwSelectedPortRules[++nMaxSelRuleIndex] = i;
  297. }
  298. //if rule counter is less than zero, then return not found
  299. if( nMaxSelRuleIndex < 0 ) {
  300. a_pdwNumRules = 0;
  301. return;
  302. }
  303. *a_ppPortRule = new WLBS_PORT_RULE[nMaxSelRuleIndex+1];
  304. if( !*a_ppPortRule )
  305. throw _com_error( WBEM_E_OUT_OF_MEMORY );
  306. PWLBS_PORT_RULE pRule = *a_ppPortRule;
  307. for( i = 0; i <= (DWORD)nMaxSelRuleIndex; i++ ) {
  308. CopyMemory( pRule++,
  309. &AllPortRules[dwSelectedPortRules[i]],
  310. sizeof( WLBS_PORT_RULE ) );
  311. }
  312. *a_pdwNumRules = nMaxSelRuleIndex + 1;
  313. return;
  314. }
  315. ////////////////////////////////////////////////////////////////////////////////
  316. //
  317. // CWlbsClusterWrapper::RuleExists
  318. //
  319. // Purpose: This function checks for the existence of a rule that has start
  320. // and end ports that match the input values.
  321. //
  322. ////////////////////////////////////////////////////////////////////////////////
  323. bool CWlbsClusterWrapper::RuleExists(DWORD a_dwVip, DWORD a_dwStartPort )
  324. {
  325. WLBS_REG_PARAMS WlbsParam;
  326. DWORD dwRes = CWlbsCluster::ReadConfig(&WlbsParam );
  327. if( dwRes != WLBS_OK )
  328. throw CErrorWlbsControl( dwRes, CmdWlbsReadReg );
  329. WLBS_PORT_RULE PortRule;
  330. dwRes = WlbsGetPortRule( &WlbsParam, a_dwVip, a_dwStartPort, &PortRule );
  331. if( dwRes == WLBS_NOT_FOUND )
  332. return false;
  333. if( dwRes != WLBS_OK )
  334. throw CErrorWlbsControl( dwRes, CmdWlbsGetPortRule );
  335. if( PortRule.start_port == a_dwStartPort )
  336. return true;
  337. return false;
  338. }
  339. ////////////////////////////////////////////////////////////////////////////////
  340. //
  341. // CWlbsClusterWrapper::DeletePortRule
  342. //
  343. // Purpose: This function deletes the rule that contains the input port.
  344. //
  345. ////////////////////////////////////////////////////////////////////////////////
  346. void CWlbsClusterWrapper::DeletePortRule(DWORD a_dwVip, DWORD a_dwPort )
  347. {
  348. WLBS_REG_PARAMS WlbsParam;
  349. DWORD dwRes = CWlbsCluster::ReadConfig(&WlbsParam );
  350. if( dwRes != WLBS_OK )
  351. throw CErrorWlbsControl( dwRes, CmdWlbsReadReg );
  352. dwRes = WlbsDeletePortRule( &WlbsParam, a_dwVip, a_dwPort );
  353. if( dwRes == WBEM_E_NOT_FOUND )
  354. throw _com_error( WBEM_E_NOT_FOUND );
  355. if( dwRes != WLBS_OK )
  356. throw CErrorWlbsControl( dwRes, CmdWlbsDeletePortRule );
  357. dwRes = CWlbsCluster::WriteConfig(&WlbsParam );
  358. if( dwRes != WLBS_OK )
  359. throw CErrorWlbsControl( dwRes, CmdWlbsWriteReg );
  360. }
  361. ////////////////////////////////////////////////////////////////////////////////
  362. //
  363. // CWlbsClusterWrapper::PutPortRule
  364. //
  365. // Purpose: This function adds a rule.
  366. //
  367. ////////////////////////////////////////////////////////////////////////////////
  368. void CWlbsClusterWrapper::PutPortRule(const PWLBS_PORT_RULE a_pPortRule)
  369. {
  370. WLBS_REG_PARAMS WlbsParam;
  371. DWORD dwRes = CWlbsCluster::ReadConfig(&WlbsParam );
  372. if( dwRes != WLBS_OK )
  373. throw CErrorWlbsControl( dwRes, CmdWlbsReadReg );
  374. dwRes = WlbsAddPortRule( &WlbsParam, a_pPortRule );
  375. if( dwRes != WLBS_OK )
  376. throw CErrorWlbsControl( dwRes, CmdWlbsAddPortRule );
  377. dwRes = CWlbsCluster::WriteConfig(&WlbsParam );
  378. if( dwRes != WLBS_OK )
  379. throw CErrorWlbsControl( dwRes, CmdWlbsWriteReg );
  380. return;
  381. }
  382. DWORD CWlbsClusterWrapper::GetClusterIpOrIndex(CWlbsControlWrapper* pControl)
  383. {
  384. return CWlbsCluster::GetClusterIpOrIndex(&pControl->m_WlbsControl);
  385. }
  386. ////////////////////////////////////////////////////////////////////////////////
  387. //
  388. // CWlbsClusterWrapper::GetHostID
  389. //
  390. // Purpose: Obtain ID of the local host.
  391. //
  392. ////////////////////////////////////////////////////////////////////////////////
  393. DWORD CWlbsClusterWrapper::GetHostID()
  394. {
  395. return CWlbsCluster::GetHostID();
  396. /*
  397. WLBS_RESPONSE WlbsResponse;
  398. DWORD dwResSize = 1;
  399. //get the cluster and HostID
  400. DWORD dwRes = WlbsQuery( CWlbsCluster::GetClusterIp(),
  401. WLBS_LOCAL_HOST,
  402. &WlbsResponse,
  403. &dwResSize,
  404. NULL,
  405. NULL );
  406. //analyze query results for errors
  407. switch( dwRes ) {
  408. case WLBS_OK:
  409. case WLBS_STOPPED:
  410. case WLBS_CONVERGING:
  411. case WLBS_CONVERGED:
  412. case WLBS_DEFAULT:
  413. case WLBS_DRAINING:
  414. case WLBS_SUSPENDED:
  415. break;
  416. default:
  417. throw CErrorWlbsControl( dwRes, CmdWlbsQuery );
  418. }
  419. return WlbsResponse.id;
  420. */
  421. }
  422. ////////////////////////////////////////////////////////////////////////////////
  423. //
  424. // CWlbsClusterWrapper::SetNodeDefaults
  425. //
  426. // Purpose: This routine obtains the default configuration and sets the node
  427. // setting properties to their defaults without affecting the other
  428. // values.
  429. //
  430. ////////////////////////////////////////////////////////////////////////////////
  431. void CWlbsClusterWrapper::SetNodeDefaults()
  432. {
  433. WLBS_REG_PARAMS WlbsConfiguration;
  434. WLBS_REG_PARAMS WlbsDefaultConfiguration;
  435. //get current configuration
  436. DWORD dwRes = CWlbsCluster::ReadConfig(&WlbsConfiguration );
  437. if( dwRes != WLBS_OK )
  438. throw CErrorWlbsControl( dwRes, CmdWlbsReadReg );
  439. //get the default configuration
  440. dwRes = WlbsSetDefaults(&WlbsDefaultConfiguration );
  441. if( dwRes != WLBS_OK )
  442. throw CErrorWlbsControl( dwRes, CmdWlbsSetDefaults );
  443. //modify current configuration with
  444. //default configuration
  445. WlbsConfiguration.host_priority = WlbsDefaultConfiguration.host_priority;
  446. WlbsConfiguration.alive_period = WlbsDefaultConfiguration.alive_period;
  447. WlbsConfiguration.alive_tolerance = WlbsDefaultConfiguration.alive_tolerance;
  448. WlbsConfiguration.cluster_mode = WlbsDefaultConfiguration.cluster_mode;
  449. WlbsConfiguration.rct_port = WlbsDefaultConfiguration.rct_port;
  450. WlbsConfiguration.mask_src_mac = WlbsDefaultConfiguration.mask_src_mac;
  451. WlbsConfiguration.dscr_per_alloc = WlbsDefaultConfiguration.dscr_per_alloc;
  452. WlbsConfiguration.max_dscr_allocs = WlbsDefaultConfiguration.max_dscr_allocs;
  453. WlbsConfiguration.num_actions = WlbsDefaultConfiguration.num_actions;
  454. WlbsConfiguration.num_packets = WlbsDefaultConfiguration.num_packets;
  455. WlbsConfiguration.num_send_msgs = WlbsDefaultConfiguration.num_send_msgs;
  456. //set dedicated IP
  457. wcsncpy
  458. (
  459. WlbsConfiguration.ded_ip_addr,
  460. WlbsDefaultConfiguration.ded_ip_addr,
  461. WLBS_MAX_DED_IP_ADDR
  462. );
  463. //set dedicated mask
  464. wcsncpy
  465. (
  466. WlbsConfiguration.ded_net_mask,
  467. WlbsDefaultConfiguration.ded_net_mask,
  468. WLBS_MAX_DED_NET_MASK
  469. );
  470. //write the default configuration
  471. dwRes = CWlbsCluster::WriteConfig(&WlbsConfiguration);
  472. if( dwRes != WLBS_OK )
  473. throw CErrorWlbsControl( dwRes, CmdWlbsWriteReg );
  474. }
  475. ////////////////////////////////////////////////////////////////////////////////
  476. //
  477. // CWlbsClusterWrapper::SetClusterDefaults
  478. //
  479. // Purpose: This routine obtains the default configuration and sets the cluster
  480. // setting properties to their defaults without affecting the other
  481. // values.
  482. //
  483. ////////////////////////////////////////////////////////////////////////////////
  484. void CWlbsClusterWrapper::SetClusterDefaults()
  485. {
  486. WLBS_REG_PARAMS WlbsConfiguration;
  487. WLBS_REG_PARAMS WlbsDefaultConfiguration;
  488. //get current configuration
  489. DWORD dwRes = CWlbsCluster::ReadConfig(&WlbsConfiguration );
  490. if( dwRes != WLBS_OK )
  491. throw CErrorWlbsControl( dwRes, CmdWlbsReadReg );
  492. //get the default configuration
  493. dwRes = WlbsSetDefaults(&WlbsDefaultConfiguration );
  494. if( dwRes != WLBS_OK )
  495. throw CErrorWlbsControl( dwRes, CmdWlbsSetDefaults );
  496. //modify current configuration
  497. wcsncpy
  498. (
  499. WlbsConfiguration.domain_name,
  500. WlbsDefaultConfiguration.domain_name,
  501. WLBS_MAX_DOMAIN_NAME
  502. );
  503. wcsncpy
  504. (
  505. WlbsConfiguration.cl_net_mask,
  506. WlbsDefaultConfiguration.cl_net_mask,
  507. WLBS_MAX_CL_NET_MASK
  508. );
  509. wcsncpy
  510. (
  511. WlbsConfiguration.cl_ip_addr ,
  512. WlbsDefaultConfiguration.cl_ip_addr,
  513. WLBS_MAX_CL_IP_ADDR
  514. );
  515. WlbsConfiguration.mcast_support = WlbsDefaultConfiguration.mcast_support;
  516. WlbsConfiguration.rct_enabled = WlbsDefaultConfiguration.rct_enabled;
  517. WlbsConfiguration.fIGMPSupport = WlbsDefaultConfiguration.fIGMPSupport;
  518. WlbsConfiguration.fIpToMCastIp = WlbsDefaultConfiguration.fIpToMCastIp;
  519. wcsncpy
  520. (
  521. WlbsConfiguration.szMCastIpAddress ,
  522. WlbsDefaultConfiguration.szMCastIpAddress,
  523. WLBS_MAX_CL_IP_ADDR
  524. );
  525. // Copy over BDA values
  526. WlbsConfiguration.bda_teaming.active = WlbsDefaultConfiguration.bda_teaming.active;
  527. if (WlbsConfiguration.bda_teaming.active)
  528. {
  529. wcsncpy
  530. (
  531. WlbsConfiguration.bda_teaming.team_id,
  532. WlbsDefaultConfiguration.bda_teaming.team_id,
  533. WLBS_MAX_BDA_TEAM_ID
  534. );
  535. WlbsConfiguration.bda_teaming.master = WlbsDefaultConfiguration.bda_teaming.master;
  536. WlbsConfiguration.bda_teaming.reverse_hash = WlbsDefaultConfiguration.bda_teaming.reverse_hash;
  537. }
  538. //write the default configuration
  539. dwRes = CWlbsCluster::WriteConfig(&WlbsConfiguration );
  540. if( dwRes != WLBS_OK )
  541. throw CErrorWlbsControl( dwRes, CmdWlbsWriteReg );
  542. }
  543. ////////////////////////////////////////////////////////////////////////////////
  544. //
  545. // CWlbsClusterWrapper::SetPortRuleDefaults
  546. //
  547. // Purpose: This routine obtains the current NLB configuration and the default
  548. // configuration. All of the port rules are removed in the current
  549. // configuration and replaced by the default configuration.
  550. //
  551. // Note: The routine only uses WLBS API calls to replace the current port
  552. // rule configuration with the default configuration. This is not
  553. // the most efficient method, but it avoids making assumptions
  554. // about the underlying data structure.
  555. //
  556. ////////////////////////////////////////////////////////////////////////////////
  557. void CWlbsClusterWrapper::SetPortRuleDefaults()
  558. {
  559. WLBS_REG_PARAMS WlbsConfiguration;
  560. WLBS_REG_PARAMS WlbsDefaultConfiguration;
  561. WLBS_PORT_RULE PortRules[WLBS_MAX_RULES];
  562. DWORD dwNumRules = WLBS_MAX_RULES;
  563. //get current configuration
  564. DWORD dwRes = CWlbsCluster::ReadConfig(&WlbsConfiguration );
  565. if( dwRes != WLBS_OK )
  566. throw CErrorWlbsControl( dwRes, CmdWlbsReadReg );
  567. //get the default configuration
  568. dwRes = WlbsSetDefaults(&WlbsDefaultConfiguration );
  569. if( dwRes != WLBS_OK )
  570. throw CErrorWlbsControl( dwRes, CmdWlbsSetDefaults );
  571. //get the current port rules
  572. dwRes = WlbsEnumPortRules( &WlbsConfiguration,
  573. PortRules,
  574. &dwNumRules );
  575. if( dwRes != WLBS_OK )
  576. throw CErrorWlbsControl( dwRes, CmdWlbsEnumPortRules );
  577. //remove all of the current port rules
  578. DWORD i = 0;
  579. for( i = 0; i < dwNumRules; i++ )
  580. {
  581. //make sure that this works as expected i.e. the indexes must be valid
  582. dwRes = WlbsDeletePortRule( &WlbsConfiguration, IpAddressFromAbcdWsz(PortRules[i].virtual_ip_addr), PortRules[i].start_port );
  583. if( dwRes != WLBS_OK )
  584. throw CErrorWlbsControl( dwRes, CmdWlbsDeletePortRule );
  585. }
  586. //get the default port rules
  587. dwNumRules = WLBS_MAX_RULES;
  588. dwRes = WlbsEnumPortRules( &WlbsDefaultConfiguration,
  589. PortRules,
  590. &dwNumRules );
  591. if( dwRes != WLBS_OK )
  592. throw CErrorWlbsControl( dwRes, CmdWlbsEnumPortRules );
  593. //add the default port rules
  594. for( i = 0; i < dwNumRules; i++ )
  595. {
  596. dwRes = WlbsAddPortRule( &WlbsConfiguration, &PortRules[i] );
  597. if( dwRes != WLBS_OK )
  598. throw CErrorWlbsControl( dwRes, CmdWlbsAddPortRule );
  599. }
  600. dwRes = CWlbsCluster::WriteConfig(&WlbsConfiguration );
  601. if( dwRes != WLBS_OK )
  602. throw CErrorWlbsControl( dwRes, CmdWlbsWriteReg );
  603. return;
  604. }