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.

555 lines
11 KiB

  1. /*
  2. * Filename: NLB_PortRule.cpp
  3. * Description:
  4. * Author: shouse, 04.10.01
  5. */
  6. #include <stdio.h>
  7. #include "NLB_PortRule.h"
  8. /*
  9. * Method:
  10. * Description:
  11. * Author: Created by shouse, 4.26.01
  12. * Notes:
  13. */
  14. NLB_PortRule::NLB_PortRule () {
  15. PriorityList.clear();
  16. LoadWeightList.clear();
  17. }
  18. /*
  19. * Method:
  20. * Description:
  21. * Author: Created by shouse, 4.26.01
  22. * Notes:
  23. */
  24. NLB_PortRule::~NLB_PortRule () {
  25. }
  26. /*
  27. * Method:
  28. * Description:
  29. * Author: Created by shouse, 4.26.01
  30. * Notes:
  31. */
  32. bool NLB_PortRule::IsValid () {
  33. if (!Name.IsValid())
  34. return false;
  35. if (!Range.IsValid())
  36. return false;
  37. if (!FilteringMode.IsValid())
  38. return false;
  39. return true;
  40. }
  41. /*
  42. * Method:
  43. * Description:
  44. * Author: Created by shouse, 4.26.01
  45. * Notes:
  46. */
  47. void NLB_PortRule::Clear () {
  48. Name.Clear();
  49. Label.Clear();
  50. State.Clear();
  51. VirtualIPAddress.Clear();
  52. Range.Clear();
  53. Protocol.Clear();
  54. FilteringMode.Clear();
  55. Affinity.Clear();
  56. PriorityList.clear();
  57. LoadWeightList.clear();
  58. }
  59. /*
  60. * Method:
  61. * Description:
  62. * Author: Created by shouse, 4.26.01
  63. * Notes:
  64. */
  65. bool NLB_PortRule::SetName (PWCHAR pName) {
  66. NLB_ASSERT(pName);
  67. return Name.SetName(pName);
  68. }
  69. /*
  70. * Method:
  71. * Description:
  72. * Author: Created by shouse, 4.26.01
  73. * Notes:
  74. */
  75. bool NLB_PortRule::GetName (PWCHAR pName, ULONG length) {
  76. NLB_ASSERT(pName);
  77. return Name.GetName(pName, length);
  78. }
  79. /*
  80. * Method:
  81. * Description:
  82. * Author: Created by shouse, 4.26.01
  83. * Notes:
  84. */
  85. bool NLB_PortRule::SetLabel (PWCHAR pLabel) {
  86. NLB_ASSERT(pLabel);
  87. return Label.SetText(pLabel);
  88. }
  89. /*
  90. * Method:
  91. * Description:
  92. * Author: Created by shouse, 4.26.01
  93. * Notes:
  94. */
  95. bool NLB_PortRule::GetLabel (PWCHAR pLabel, ULONG length) {
  96. NLB_ASSERT(pLabel);
  97. return Label.GetText(pLabel, length);
  98. }
  99. /*
  100. * Method:
  101. * Description:
  102. * Author: Created by shouse, 4.26.01
  103. * Notes:
  104. */
  105. bool NLB_PortRule::SetPortRange (ULONG start, ULONG end) {
  106. return Range.SetPortRange(start, end);
  107. }
  108. /*
  109. * Method:
  110. * Description:
  111. * Author: Created by shouse, 4.26.01
  112. * Notes:
  113. */
  114. bool NLB_PortRule::GetPortRange (ULONG & start, ULONG & end) {
  115. return Range.GetPortRange(start, end);
  116. }
  117. /*
  118. * Method:
  119. * Description:
  120. * Author: Created by shouse, 4.26.01
  121. * Notes:
  122. */
  123. bool NLB_PortRule::SetVirtualIPAddress (NLB_IPAddress address) {
  124. NLB_IPAddress::NLB_IPAddressType Type;
  125. if (!address.IsValid())
  126. return false;
  127. if (!address.GetIPAddressType(Type))
  128. return false;
  129. if (Type != NLB_IPAddress::Virtual)
  130. return false;
  131. VirtualIPAddress = address;
  132. return true;
  133. }
  134. /*
  135. * Method:
  136. * Description:
  137. * Author: Created by shouse, 4.26.01
  138. * Notes:
  139. */
  140. bool NLB_PortRule::GetVirtualIPAddress (NLB_IPAddress & address) {
  141. address = VirtualIPAddress;
  142. return VirtualIPAddress.IsValid();
  143. }
  144. /*
  145. * Method:
  146. * Description:
  147. * Author: Created by shouse, 4.26.01
  148. * Notes:
  149. */
  150. bool NLB_PortRule::SetState (NLB_PortRuleState::NLB_PortRuleStateType eState) {
  151. return State.SetState(eState);
  152. }
  153. /*
  154. * Method:
  155. * Description:
  156. * Author: Created by shouse, 4.26.01
  157. * Notes:
  158. */
  159. bool NLB_PortRule::GetState (NLB_PortRuleState::NLB_PortRuleStateType & eState) {
  160. return State.GetState(eState);
  161. }
  162. /*
  163. * Method:
  164. * Description:
  165. * Author: Created by shouse, 4.26.01
  166. * Notes:
  167. */
  168. bool NLB_PortRule::SetProtocol (NLB_PortRuleProtocol::NLB_PortRuleProtocolType eProtocol) {
  169. return Protocol.SetProtocol(eProtocol);
  170. }
  171. /*
  172. * Method:
  173. * Description:
  174. * Author: Created by shouse, 4.26.01
  175. * Notes:
  176. */
  177. bool NLB_PortRule::GetProtocol (NLB_PortRuleProtocol::NLB_PortRuleProtocolType & eProtocol) {
  178. return Protocol.GetProtocol(eProtocol);
  179. }
  180. /*
  181. * Method:
  182. * Description:
  183. * Author: Created by shouse, 4.26.01
  184. * Notes:
  185. */
  186. bool NLB_PortRule::SetFilteringMode (NLB_PortRuleFilteringMode::NLB_PortRuleFilteringModeType eMode) {
  187. return FilteringMode.SetMode(eMode);
  188. }
  189. /*
  190. * Method:
  191. * Description:
  192. * Author: Created by shouse, 4.26.01
  193. * Notes:
  194. */
  195. bool NLB_PortRule::GetFilteringMode (NLB_PortRuleFilteringMode::NLB_PortRuleFilteringModeType & eMode) {
  196. return FilteringMode.GetMode(eMode);
  197. }
  198. /*
  199. * Method:
  200. * Description:
  201. * Author: Created by shouse, 4.26.01
  202. * Notes:
  203. */
  204. bool NLB_PortRule::SetAffinity (NLB_PortRuleAffinity::NLB_PortRuleAffinityType eAffinity) {
  205. return Affinity.SetAffinity(eAffinity);
  206. }
  207. /*
  208. * Method:
  209. * Description:
  210. * Author: Created by shouse, 4.26.01
  211. * Notes:
  212. */
  213. bool NLB_PortRule::GetAffinity (NLB_PortRuleAffinity::NLB_PortRuleAffinityType & eAffinity) {
  214. return Affinity.GetAffinity(eAffinity);
  215. }
  216. /*
  217. * Method:
  218. * Description:
  219. * Author: Created by shouse, 4.26.01
  220. * Notes:
  221. */
  222. bool NLB_PortRule::AddSingleHostFilteringPriority (PWCHAR pHost, ULONG priority) {
  223. NLB_SingleHostFilteringPriorityList::iterator iHost;
  224. NLB_PortRulePriority Priority;
  225. if (!Priority.SetHost(pHost))
  226. return false;
  227. if (!Priority.SetPriority(priority))
  228. return false;
  229. iHost = PriorityList.find(pHost);
  230. if (iHost != PriorityList.end())
  231. return false;
  232. PriorityList.insert(NLB_SingleHostFilteringPriorityList::value_type(pHost, Priority));
  233. return true;
  234. }
  235. /*
  236. * Method:
  237. * Description:
  238. * Author: Created by shouse, 4.26.01
  239. * Notes:
  240. */
  241. bool NLB_PortRule::ChangeSingleHostFilteringPriority (PWCHAR pHost, ULONG priority) {
  242. if (!RemoveSingleHostFilteringPriority(pHost))
  243. return false;
  244. if (!AddSingleHostFilteringPriority(pHost, priority))
  245. return false;
  246. return true;
  247. }
  248. /*
  249. * Method:
  250. * Description:
  251. * Author: Created by shouse, 4.26.01
  252. * Notes:
  253. */
  254. bool NLB_PortRule::GetSingleHostFilteringPriority (PWCHAR pHost, ULONG & priority) {
  255. NLB_SingleHostFilteringPriorityList::iterator iHost;
  256. NLB_PortRulePriority Priority;
  257. iHost = PriorityList.find(pHost);
  258. if (iHost == PriorityList.end())
  259. return false;
  260. Priority = (*iHost).second;
  261. return Priority.GetPriority(priority);
  262. }
  263. /*
  264. * Method:
  265. * Description:
  266. * Author: Created by shouse, 4.26.01
  267. * Notes:
  268. */
  269. bool NLB_PortRule::RemoveSingleHostFilteringPriority (PWCHAR pHost) {
  270. NLB_SingleHostFilteringPriorityList::iterator iHost;
  271. iHost = PriorityList.find(pHost);
  272. if (iHost == PriorityList.end())
  273. return false;
  274. PriorityList.erase(pHost);
  275. return true;
  276. }
  277. /*
  278. * Method:
  279. * Description:
  280. * Author: Created by shouse, 4.26.01
  281. * Notes:
  282. */
  283. ULONG NLB_PortRule::SetSingleHostFilteringPriorityList (vector<NLB_PortRulePriority> pList) {
  284. vector<NLB_PortRulePriority>::iterator iPriority;
  285. ULONG num = 0;
  286. PriorityList.clear();
  287. for (iPriority = pList.begin(); iPriority != pList.end(); iPriority++) {
  288. NLB_PortRulePriority * pPriority = iPriority;
  289. WCHAR wszString[MAX_PATH];
  290. ULONG value;
  291. if (!pPriority->IsValid())
  292. continue;
  293. if (!pPriority->GetHost(wszString, MAX_PATH))
  294. continue;
  295. if (!pPriority->GetPriority(value))
  296. continue;
  297. if (!AddSingleHostFilteringPriority(wszString, value))
  298. continue;
  299. num++;
  300. }
  301. return num;
  302. }
  303. /*
  304. * Method:
  305. * Description:
  306. * Author: Created by shouse, 4.26.01
  307. * Notes:
  308. */
  309. ULONG NLB_PortRule::GetSingleHostFilteringPriorityList (vector<NLB_PortRulePriority> * pList) {
  310. NLB_SingleHostFilteringPriorityList::iterator iPriority;
  311. ULONG num = 0;
  312. NLB_ASSERT(pList);
  313. pList->clear();
  314. for (iPriority = PriorityList.begin(); iPriority != PriorityList.end(); iPriority++) {
  315. NLB_PortRulePriority Priority = (*iPriority).second;
  316. pList->push_back(Priority);
  317. num++;
  318. }
  319. return num;
  320. }
  321. /*
  322. * Method:
  323. * Description:
  324. * Author: Created by shouse, 4.26.01
  325. * Notes:
  326. */
  327. bool NLB_PortRule::AddMultipleHostFilteringLoadWeight (PWCHAR pHost, ULONG weight) {
  328. NLB_MultipleHostFilteringLoadWeightList::iterator iHost;
  329. NLB_PortRuleLoadWeight Weight;
  330. if (!Weight.SetHost(pHost))
  331. return false;
  332. if (!Weight.SetWeight(weight))
  333. return false;
  334. iHost = LoadWeightList.find(pHost);
  335. if (iHost != LoadWeightList.end())
  336. return false;
  337. LoadWeightList.insert(NLB_MultipleHostFilteringLoadWeightList::value_type(pHost, Weight));
  338. return true;
  339. }
  340. /*
  341. * Method:
  342. * Description:
  343. * Author: Created by shouse, 4.26.01
  344. * Notes:
  345. */
  346. bool NLB_PortRule::ChangeMultipleHostFilteringLoadWeight (PWCHAR pHost, ULONG weight) {
  347. if (!RemoveMultipleHostFilteringLoadWeight(pHost))
  348. return false;
  349. if (!AddMultipleHostFilteringLoadWeight(pHost, weight))
  350. return false;
  351. return true;
  352. }
  353. /*
  354. * Method:
  355. * Description:
  356. * Author: Created by shouse, 4.26.01
  357. * Notes:
  358. */
  359. bool NLB_PortRule::GetMultipleHostFilteringLoadWeight (PWCHAR pHost, ULONG & weight) {
  360. NLB_MultipleHostFilteringLoadWeightList::iterator iHost;
  361. NLB_PortRuleLoadWeight Weight;
  362. iHost = LoadWeightList.find(pHost);
  363. if (iHost == LoadWeightList.end())
  364. return false;
  365. Weight = (*iHost).second;
  366. return Weight.GetWeight(weight);
  367. }
  368. /*
  369. * Method:
  370. * Description:
  371. * Author: Created by shouse, 4.26.01
  372. * Notes:
  373. */
  374. bool NLB_PortRule::RemoveMultipleHostFilteringLoadWeight (PWCHAR pHost) {
  375. NLB_MultipleHostFilteringLoadWeightList::iterator iHost;
  376. iHost = LoadWeightList.find(pHost);
  377. if (iHost == LoadWeightList.end())
  378. return false;
  379. LoadWeightList.erase(pHost);
  380. return true;
  381. }
  382. /*
  383. * Method:
  384. * Description:
  385. * Author: Created by shouse, 4.26.01
  386. * Notes:
  387. */
  388. ULONG NLB_PortRule::SetMultipleHostFilteringLoadWeightList (vector<NLB_PortRuleLoadWeight> pList) {
  389. vector<NLB_PortRuleLoadWeight>::iterator iLoadWeight;
  390. ULONG num = 0;
  391. LoadWeightList.clear();
  392. for (iLoadWeight = pList.begin(); iLoadWeight != pList.end(); iLoadWeight++) {
  393. NLB_PortRuleLoadWeight * pLoadWeight = iLoadWeight;
  394. WCHAR wszString[MAX_PATH];
  395. ULONG value;
  396. if (!pLoadWeight->IsValid())
  397. continue;
  398. if (!pLoadWeight->GetHost(wszString, MAX_PATH))
  399. continue;
  400. if (!pLoadWeight->GetWeight(value))
  401. continue;
  402. if (!AddMultipleHostFilteringLoadWeight(wszString, value))
  403. continue;
  404. num++;
  405. }
  406. return num;
  407. }
  408. /*
  409. * Method:
  410. * Description:
  411. * Author: Created by shouse, 4.26.01
  412. * Notes:
  413. */
  414. ULONG NLB_PortRule::GetMultipleHostFilteringLoadWeightList (vector<NLB_PortRuleLoadWeight> * pList) {
  415. NLB_MultipleHostFilteringLoadWeightList::iterator iLoadWeight;
  416. ULONG num = 0;
  417. NLB_ASSERT(pList);
  418. pList->clear();
  419. for (iLoadWeight = LoadWeightList.begin(); iLoadWeight != LoadWeightList.end(); iLoadWeight++) {
  420. NLB_PortRuleLoadWeight LoadWeight = (*iLoadWeight).second;
  421. pList->push_back(LoadWeight);
  422. num++;
  423. }
  424. return num;
  425. }