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.

1207 lines
27 KiB

  1. #include "precomp.h"
  2. DWORD
  3. ValidateMMPolicy(
  4. PIPSEC_MM_POLICY pMMPolicy
  5. )
  6. {
  7. DWORD dwError = 0;
  8. if (!pMMPolicy) {
  9. dwError = ERROR_INVALID_PARAMETER;
  10. BAIL_ON_WIN32_ERROR(dwError);
  11. }
  12. if (!(pMMPolicy->pszPolicyName) || !(*(pMMPolicy->pszPolicyName))) {
  13. dwError = ERROR_INVALID_PARAMETER;
  14. BAIL_ON_WIN32_ERROR(dwError);
  15. }
  16. dwError = ValidateMMOffers(
  17. pMMPolicy->dwOfferCount,
  18. pMMPolicy->pOffers
  19. );
  20. BAIL_ON_WIN32_ERROR(dwError);
  21. error:
  22. return (dwError);
  23. }
  24. DWORD
  25. ValidateMMOffers(
  26. DWORD dwOfferCount,
  27. PIPSEC_MM_OFFER pOffers
  28. )
  29. {
  30. DWORD dwError = 0;
  31. DWORD i = 0;
  32. PIPSEC_MM_OFFER pTemp = NULL;
  33. if (!dwOfferCount || !pOffers || (dwOfferCount > IPSEC_MAX_MM_OFFERS)) {
  34. dwError = ERROR_INVALID_PARAMETER;
  35. BAIL_ON_WIN32_ERROR(dwError);
  36. }
  37. //
  38. // Need to catch the exception when the number of offers
  39. // specified is more than the actual number of offers.
  40. //
  41. pTemp = pOffers;
  42. for (i = 0; i < dwOfferCount; i++) {
  43. if ((pTemp->dwDHGroup != DH_GROUP_1) &&
  44. (pTemp->dwDHGroup != DH_GROUP_2)) {
  45. dwError = ERROR_INVALID_PARAMETER;
  46. BAIL_ON_WIN32_ERROR(dwError);
  47. }
  48. if (pTemp->EncryptionAlgorithm.uAlgoIdentifier >= IPSEC_DOI_ESP_MAX) {
  49. dwError = ERROR_INVALID_PARAMETER;
  50. BAIL_ON_WIN32_ERROR(dwError);
  51. }
  52. if (pTemp->HashingAlgorithm.uAlgoIdentifier >= IPSEC_DOI_AH_MAX) {
  53. dwError = ERROR_INVALID_PARAMETER;
  54. BAIL_ON_WIN32_ERROR(dwError);
  55. }
  56. pTemp++;
  57. }
  58. error:
  59. return (dwError);
  60. }
  61. DWORD
  62. ValidateMMAuthMethods(
  63. PMM_AUTH_METHODS pMMAuthMethods
  64. )
  65. {
  66. DWORD dwError = 0;
  67. DWORD i = 0;
  68. PIPSEC_MM_AUTH_INFO pTemp = NULL;
  69. DWORD dwNumAuthInfos = 0;
  70. PIPSEC_MM_AUTH_INFO pAuthenticationInfo = NULL;
  71. BOOL bSSPI = FALSE;
  72. BOOL bPresharedKey = FALSE;
  73. if (!pMMAuthMethods) {
  74. dwError = ERROR_INVALID_PARAMETER;
  75. BAIL_ON_WIN32_ERROR(dwError);
  76. }
  77. dwNumAuthInfos = pMMAuthMethods->dwNumAuthInfos;
  78. pAuthenticationInfo = pMMAuthMethods->pAuthenticationInfo;
  79. if (!dwNumAuthInfos || !pAuthenticationInfo) {
  80. dwError = ERROR_INVALID_PARAMETER;
  81. BAIL_ON_WIN32_ERROR(dwError);
  82. }
  83. //
  84. // Need to catch the exception when the number of auth infos
  85. // specified is more than the actual number of auth infos.
  86. //
  87. pTemp = pAuthenticationInfo;
  88. for (i = 0; i < dwNumAuthInfos; i++) {
  89. if ((pTemp->AuthMethod != IKE_PRESHARED_KEY) &&
  90. (pTemp->AuthMethod != IKE_RSA_SIGNATURE) &&
  91. (pTemp->AuthMethod != IKE_SSPI)) {
  92. dwError = ERROR_INVALID_PARAMETER;
  93. BAIL_ON_WIN32_ERROR(dwError);
  94. }
  95. if (pTemp->AuthMethod != IKE_SSPI) {
  96. if (!(pTemp->dwAuthInfoSize) || !(pTemp->pAuthInfo)) {
  97. dwError = ERROR_INVALID_PARAMETER;
  98. BAIL_ON_WIN32_ERROR(dwError);
  99. }
  100. }
  101. if (pTemp->AuthMethod == IKE_SSPI) {
  102. if (bSSPI) {
  103. dwError = ERROR_INVALID_PARAMETER;
  104. BAIL_ON_WIN32_ERROR(dwError);
  105. }
  106. bSSPI = TRUE;
  107. }
  108. if (pTemp->AuthMethod == IKE_PRESHARED_KEY) {
  109. if (bPresharedKey) {
  110. dwError = ERROR_INVALID_PARAMETER;
  111. BAIL_ON_WIN32_ERROR(dwError);
  112. }
  113. bPresharedKey = TRUE;
  114. }
  115. pTemp++;
  116. }
  117. error:
  118. return (dwError);
  119. }
  120. DWORD
  121. ValidateQMPolicy(
  122. PIPSEC_QM_POLICY pQMPolicy
  123. )
  124. {
  125. DWORD dwError = 0;
  126. if (!pQMPolicy) {
  127. dwError = ERROR_INVALID_PARAMETER;
  128. BAIL_ON_WIN32_ERROR(dwError);
  129. }
  130. if (!(pQMPolicy->pszPolicyName) || !(*(pQMPolicy->pszPolicyName))) {
  131. dwError = ERROR_INVALID_PARAMETER;
  132. BAIL_ON_WIN32_ERROR(dwError);
  133. }
  134. dwError = ValidateQMOffers(
  135. pQMPolicy->dwOfferCount,
  136. pQMPolicy->pOffers
  137. );
  138. BAIL_ON_WIN32_ERROR(dwError);
  139. error:
  140. return (dwError);
  141. }
  142. DWORD
  143. ValidateQMOffers(
  144. DWORD dwOfferCount,
  145. PIPSEC_QM_OFFER pOffers
  146. )
  147. {
  148. DWORD dwError = 0;
  149. DWORD i = 0;
  150. PIPSEC_QM_OFFER pTemp = NULL;
  151. DWORD j = 0;
  152. BOOL bAH = FALSE;
  153. BOOL bESP = FALSE;
  154. DWORD dwQMGroup = PFS_GROUP_NONE;
  155. if (!dwOfferCount || !pOffers || (dwOfferCount > IPSEC_MAX_QM_OFFERS)) {
  156. dwError = ERROR_INVALID_PARAMETER;
  157. BAIL_ON_WIN32_ERROR(dwError);
  158. }
  159. //
  160. // Need to catch the exception when the number of offers
  161. // specified is more than the actual number of offers.
  162. //
  163. pTemp = pOffers;
  164. if (pTemp->bPFSRequired) {
  165. if ((pTemp->dwPFSGroup != PFS_GROUP_1) &&
  166. (pTemp->dwPFSGroup != PFS_GROUP_2) &&
  167. (pTemp->dwPFSGroup != PFS_GROUP_MM)) {
  168. dwError = ERROR_INVALID_PARAMETER;
  169. BAIL_ON_WIN32_ERROR(dwError);
  170. }
  171. dwQMGroup=pTemp->dwPFSGroup;
  172. }
  173. else {
  174. if (pTemp->dwPFSGroup != PFS_GROUP_NONE) {
  175. dwError = ERROR_INVALID_PARAMETER;
  176. BAIL_ON_WIN32_ERROR(dwError);
  177. }
  178. }
  179. for (i = 0; i < dwOfferCount; i++) {
  180. if (dwQMGroup) {
  181. if ((!pTemp->bPFSRequired) || (pTemp->dwPFSGroup != dwQMGroup)) {
  182. dwError = ERROR_INVALID_PARAMETER;
  183. BAIL_ON_WIN32_ERROR(dwError);
  184. }
  185. } else {
  186. if ((pTemp->bPFSRequired) || (pTemp->dwPFSGroup != PFS_GROUP_NONE)) {
  187. dwError = ERROR_INVALID_PARAMETER;
  188. BAIL_ON_WIN32_ERROR(dwError);
  189. }
  190. }
  191. if (!(pTemp->dwNumAlgos) || (pTemp->dwNumAlgos > QM_MAX_ALGOS)) {
  192. dwError = ERROR_INVALID_PARAMETER;
  193. BAIL_ON_WIN32_ERROR(dwError);
  194. }
  195. bAH = FALSE;
  196. bESP = FALSE;
  197. for (j = 0; j < (pTemp->dwNumAlgos); j++) {
  198. switch (pTemp->Algos[j].Operation) {
  199. case AUTHENTICATION:
  200. if (bAH) {
  201. dwError = ERROR_INVALID_PARAMETER;
  202. BAIL_ON_WIN32_ERROR(dwError);
  203. }
  204. if ((pTemp->Algos[j].uAlgoIdentifier == IPSEC_DOI_AH_NONE) ||
  205. (pTemp->Algos[j].uAlgoIdentifier >= IPSEC_DOI_AH_MAX)) {
  206. dwError = ERROR_INVALID_PARAMETER;
  207. BAIL_ON_WIN32_ERROR(dwError);
  208. }
  209. if (pTemp->Algos[j].uSecAlgoIdentifier != HMAC_AH_NONE) {
  210. dwError = ERROR_INVALID_PARAMETER;
  211. BAIL_ON_WIN32_ERROR(dwError);
  212. }
  213. bAH = TRUE;
  214. break;
  215. case ENCRYPTION:
  216. if (bESP) {
  217. dwError = ERROR_INVALID_PARAMETER;
  218. BAIL_ON_WIN32_ERROR(dwError);
  219. }
  220. if (pTemp->Algos[j].uAlgoIdentifier >= IPSEC_DOI_ESP_MAX) {
  221. dwError = ERROR_INVALID_PARAMETER;
  222. BAIL_ON_WIN32_ERROR(dwError);
  223. }
  224. if (pTemp->Algos[j].uSecAlgoIdentifier >= HMAC_AH_MAX) {
  225. dwError = ERROR_INVALID_PARAMETER;
  226. BAIL_ON_WIN32_ERROR(dwError);
  227. }
  228. if (pTemp->Algos[j].uAlgoIdentifier == IPSEC_DOI_ESP_NONE) {
  229. if (pTemp->Algos[j].uSecAlgoIdentifier == HMAC_AH_NONE) {
  230. dwError = ERROR_INVALID_PARAMETER;
  231. BAIL_ON_WIN32_ERROR(dwError);
  232. }
  233. }
  234. bESP = TRUE;
  235. break;
  236. case NONE:
  237. case COMPRESSION:
  238. default:
  239. dwError = ERROR_INVALID_PARAMETER;
  240. BAIL_ON_WIN32_ERROR(dwError);
  241. break;
  242. }
  243. }
  244. pTemp++;
  245. }
  246. error:
  247. return (dwError);
  248. }
  249. DWORD
  250. ValidateMMFilter(
  251. PMM_FILTER pMMFilter
  252. )
  253. /*++
  254. Routine Description:
  255. This function validates an external generic MM filter.
  256. Arguments:
  257. pMMFilter - Filter to validate.
  258. Return Value:
  259. ERROR_SUCCESS - Success.
  260. Win32 Error - Failure.
  261. --*/
  262. {
  263. DWORD dwError = 0;
  264. BOOL bConflicts = FALSE;
  265. if (!pMMFilter) {
  266. dwError = ERROR_INVALID_PARAMETER;
  267. BAIL_ON_WIN32_ERROR(dwError);
  268. }
  269. dwError = VerifyAddresses(pMMFilter->SrcAddr, TRUE , FALSE);
  270. BAIL_ON_WIN32_ERROR(dwError);
  271. dwError = VerifyAddresses(pMMFilter->DesAddr, TRUE , TRUE);
  272. BAIL_ON_WIN32_ERROR(dwError);
  273. bConflicts = AddressesConflict(
  274. pMMFilter->SrcAddr,
  275. pMMFilter->DesAddr
  276. );
  277. if (bConflicts) {
  278. dwError = ERROR_INVALID_PARAMETER;
  279. BAIL_ON_WIN32_ERROR(dwError);
  280. }
  281. if (!(pMMFilter->pszFilterName) || !(*(pMMFilter->pszFilterName))) {
  282. dwError = ERROR_INVALID_PARAMETER;
  283. BAIL_ON_WIN32_ERROR(dwError);
  284. }
  285. if (pMMFilter->InterfaceType >= INTERFACE_TYPE_MAX) {
  286. dwError = ERROR_INVALID_PARAMETER;
  287. BAIL_ON_WIN32_ERROR(dwError);
  288. }
  289. if (pMMFilter->dwFlags &&
  290. !(pMMFilter->dwFlags & IPSEC_MM_POLICY_DEFAULT_POLICY) &&
  291. !(pMMFilter->dwFlags & IPSEC_MM_AUTH_DEFAULT_AUTH)) {
  292. dwError = ERROR_INVALID_PARAMETER;
  293. BAIL_ON_WIN32_ERROR(dwError);
  294. }
  295. dwError = ApplyMulticastFilterValidation(
  296. pMMFilter->DesAddr,
  297. pMMFilter->bCreateMirror
  298. );
  299. BAIL_ON_WIN32_ERROR(dwError);
  300. error:
  301. return (dwError);
  302. }
  303. DWORD
  304. VerifyAddresses(
  305. ADDR Addr,
  306. BOOL bAcceptMe,
  307. BOOL bIsDesAddr
  308. )
  309. {
  310. DWORD dwError = 0;
  311. BOOL bIsValid = FALSE;
  312. switch (Addr.AddrType) {
  313. case IP_ADDR_UNIQUE:
  314. bIsValid = bIsValidIPAddress(
  315. ntohl(Addr.uIpAddr),
  316. bAcceptMe,
  317. bIsDesAddr
  318. );
  319. if (!bIsValid) {
  320. dwError = ERROR_INVALID_PARAMETER;
  321. BAIL_ON_WIN32_ERROR(dwError);
  322. }
  323. break;
  324. case IP_ADDR_SUBNET:
  325. dwError = VerifySubNetAddress(
  326. ntohl(Addr.uIpAddr),
  327. ntohl(Addr.uSubNetMask),
  328. bIsDesAddr
  329. );
  330. BAIL_ON_WIN32_ERROR(dwError);
  331. break;
  332. case IP_ADDR_INTERFACE:
  333. if (Addr.uIpAddr) {
  334. dwError = ERROR_INVALID_PARAMETER;
  335. BAIL_ON_WIN32_ERROR(dwError);
  336. }
  337. break;
  338. default:
  339. dwError = ERROR_INVALID_PARAMETER;
  340. BAIL_ON_WIN32_ERROR(dwError);
  341. break;
  342. }
  343. error:
  344. return (dwError);
  345. }
  346. DWORD
  347. VerifySubNetAddress(
  348. ULONG uSubNetAddr,
  349. ULONG uSubNetMask,
  350. BOOL bIsDesAddr
  351. )
  352. {
  353. DWORD dwError = 0;
  354. BOOL bIsValid = FALSE;
  355. if (uSubNetAddr == SUBNET_ADDRESS_ANY) {
  356. if (uSubNetMask != SUBNET_MASK_ANY) {
  357. dwError = ERROR_INVALID_PARAMETER;
  358. BAIL_ON_WIN32_ERROR(dwError);
  359. }
  360. }
  361. else {
  362. bIsValid = bIsValidSubnet(
  363. uSubNetAddr,
  364. uSubNetMask,
  365. bIsDesAddr
  366. );
  367. if (!bIsValid) {
  368. dwError = ERROR_INVALID_PARAMETER;
  369. BAIL_ON_WIN32_ERROR(dwError);
  370. }
  371. }
  372. error:
  373. return (dwError);
  374. }
  375. BOOL
  376. bIsValidIPMask(
  377. ULONG uMask
  378. )
  379. {
  380. BOOL bValidMask = FALSE;
  381. ULONG uTestMask = 0;
  382. //
  383. // Mask must be contiguous bits.
  384. //
  385. for (uTestMask = 0xFFFFFFFF; uTestMask; uTestMask <<= 1) {
  386. if (uTestMask == uMask) {
  387. bValidMask = TRUE;
  388. break;
  389. }
  390. }
  391. return (bValidMask);
  392. }
  393. BOOL
  394. bIsValidIPAddress(
  395. ULONG uIpAddr,
  396. BOOL bAcceptMe,
  397. BOOL bIsDesAddr
  398. )
  399. {
  400. ULONG uHostMask = IN_CLASSA_HOST; // Default host mask.
  401. //
  402. // Accept the address if its "me".
  403. //
  404. if (bAcceptMe) {
  405. if (uIpAddr == IP_ADDRESS_ME) {
  406. return TRUE;
  407. }
  408. }
  409. //
  410. // Reject if its a multicast address and is not the
  411. // destination address.
  412. //
  413. if (IN_CLASSD(uIpAddr)) {
  414. if (bIsDesAddr) {
  415. return TRUE;
  416. }
  417. else {
  418. return FALSE;
  419. }
  420. }
  421. //
  422. // Reject if its a Class E address.
  423. //
  424. if (IN_CLASSE(uIpAddr)) {
  425. return FALSE;
  426. }
  427. //
  428. // Reject if the first octet is zero.
  429. //
  430. if (!(IN_CLASSA_NET & uIpAddr)) {
  431. return FALSE;
  432. }
  433. //
  434. // Use default mask based on Class when none is provided.
  435. //
  436. if (IN_CLASSA(uIpAddr)) {
  437. uHostMask = IN_CLASSA_HOST;
  438. }
  439. else if (IN_CLASSB(uIpAddr)) {
  440. uHostMask = IN_CLASSB_HOST;
  441. }
  442. else if (IN_CLASSC(uIpAddr)) {
  443. uHostMask = IN_CLASSC_HOST;
  444. }
  445. //
  446. // Accept address when host portion is non-zero.
  447. //
  448. if (uHostMask & uIpAddr) {
  449. return TRUE;
  450. }
  451. return FALSE;
  452. }
  453. BOOL
  454. bIsValidSubnet(
  455. ULONG uIpAddr,
  456. ULONG uMask,
  457. BOOL bIsDesAddr
  458. )
  459. {
  460. ULONG uHostMask = 0;
  461. //
  462. // Reject if its a multicast address and is not the
  463. // destination address.
  464. //
  465. if (IN_CLASSD(uIpAddr)) {
  466. if (!bIsDesAddr) {
  467. return FALSE;
  468. }
  469. }
  470. //
  471. // Reject if its a Class E address.
  472. //
  473. if (IN_CLASSE(uIpAddr)) {
  474. return FALSE;
  475. }
  476. //
  477. // Reject if the first octet is zero.
  478. //
  479. if (!(IN_CLASSA_NET & uIpAddr)) {
  480. return FALSE;
  481. }
  482. //
  483. // If the mask is invalid then return.
  484. //
  485. if (!bIsValidIPMask(uMask)) {
  486. return FALSE;
  487. }
  488. //
  489. // Use the provided subnet mask to generate the host mask.
  490. //
  491. uHostMask = 0xFFFFFFFF ^ uMask;
  492. //
  493. // Validate the address and the mask.
  494. //
  495. if (IN_CLASSA(uIpAddr)) {
  496. if (IN_CLASSA_NET > uMask) {
  497. return FALSE;
  498. }
  499. }
  500. else if (IN_CLASSB(uIpAddr)) {
  501. if (IN_CLASSB_NET > uMask) {
  502. return FALSE;
  503. }
  504. }
  505. else if (IN_CLASSC(uIpAddr)) {
  506. if (IN_CLASSC_NET > uMask) {
  507. return TRUE;
  508. }
  509. }
  510. //
  511. // Accept address only when the host portion is zero, network
  512. // portion is non-zero and first octet is non-zero.
  513. //
  514. if (!(uHostMask & uIpAddr) &&
  515. (uMask & uIpAddr) &&
  516. (IN_CLASSA_NET & uIpAddr)) {
  517. return TRUE;
  518. }
  519. return FALSE;
  520. }
  521. BOOL
  522. AddressesConflict(
  523. ADDR SrcAddr,
  524. ADDR DesAddr
  525. )
  526. {
  527. if ((SrcAddr.AddrType == IP_ADDR_UNIQUE) &&
  528. (DesAddr.AddrType == IP_ADDR_UNIQUE)) {
  529. if (SrcAddr.uIpAddr == DesAddr.uIpAddr) {
  530. return (TRUE);
  531. }
  532. }
  533. if ((SrcAddr.AddrType == IP_ADDR_INTERFACE) &&
  534. (DesAddr.AddrType == IP_ADDR_INTERFACE)) {
  535. return (TRUE);
  536. }
  537. return (FALSE);
  538. }
  539. DWORD
  540. ValidateTransportFilter(
  541. PTRANSPORT_FILTER pTransportFilter
  542. )
  543. {
  544. DWORD dwError = 0;
  545. BOOL bConflicts = FALSE;
  546. if (!pTransportFilter) {
  547. dwError = ERROR_INVALID_PARAMETER;
  548. BAIL_ON_WIN32_ERROR(dwError);
  549. }
  550. dwError = VerifyAddresses(pTransportFilter->SrcAddr, TRUE, FALSE);
  551. BAIL_ON_WIN32_ERROR(dwError);
  552. dwError = VerifyAddresses(pTransportFilter->DesAddr, TRUE, TRUE);
  553. BAIL_ON_WIN32_ERROR(dwError);
  554. bConflicts = AddressesConflict(
  555. pTransportFilter->SrcAddr,
  556. pTransportFilter->DesAddr
  557. );
  558. if (bConflicts) {
  559. dwError = ERROR_INVALID_PARAMETER;
  560. BAIL_ON_WIN32_ERROR(dwError);
  561. }
  562. dwError = VerifyProtocols(pTransportFilter->Protocol);
  563. BAIL_ON_WIN32_ERROR(dwError);
  564. dwError = VerifyPortsForProtocol(
  565. pTransportFilter->SrcPort,
  566. pTransportFilter->Protocol
  567. );
  568. BAIL_ON_WIN32_ERROR(dwError);
  569. dwError = VerifyPortsForProtocol(
  570. pTransportFilter->DesPort,
  571. pTransportFilter->Protocol
  572. );
  573. BAIL_ON_WIN32_ERROR(dwError);
  574. if (!(pTransportFilter->pszFilterName) || !(*(pTransportFilter->pszFilterName))) {
  575. dwError = ERROR_INVALID_PARAMETER;
  576. BAIL_ON_WIN32_ERROR(dwError);
  577. }
  578. if (pTransportFilter->InterfaceType >= INTERFACE_TYPE_MAX) {
  579. dwError = ERROR_INVALID_PARAMETER;
  580. BAIL_ON_WIN32_ERROR(dwError);
  581. }
  582. if (pTransportFilter->InboundFilterFlag >= FILTER_FLAG_MAX) {
  583. dwError = ERROR_INVALID_PARAMETER;
  584. BAIL_ON_WIN32_ERROR(dwError);
  585. }
  586. if (pTransportFilter->OutboundFilterFlag >= FILTER_FLAG_MAX) {
  587. dwError = ERROR_INVALID_PARAMETER;
  588. BAIL_ON_WIN32_ERROR(dwError);
  589. }
  590. if (pTransportFilter->dwFlags &&
  591. !(pTransportFilter->dwFlags & IPSEC_QM_POLICY_DEFAULT_POLICY)) {
  592. dwError = ERROR_INVALID_PARAMETER;
  593. BAIL_ON_WIN32_ERROR(dwError);
  594. }
  595. dwError = ApplyMulticastFilterValidation(
  596. pTransportFilter->DesAddr,
  597. pTransportFilter->bCreateMirror
  598. );
  599. BAIL_ON_WIN32_ERROR(dwError);
  600. error:
  601. return (dwError);
  602. }
  603. DWORD
  604. ValidateIPSecQMFilter(
  605. PIPSEC_QM_FILTER pQMFilter
  606. )
  607. {
  608. DWORD dwError = 0;
  609. BOOL bConflicts = FALSE;
  610. if (!pQMFilter) {
  611. dwError = ERROR_INVALID_PARAMETER;
  612. BAIL_ON_WIN32_ERROR(dwError);
  613. }
  614. dwError = VerifyAddresses(pQMFilter->SrcAddr, FALSE, FALSE);
  615. BAIL_ON_WIN32_ERROR(dwError);
  616. dwError = VerifyAddresses(pQMFilter->DesAddr, FALSE, TRUE);
  617. BAIL_ON_WIN32_ERROR(dwError);
  618. bConflicts = AddressesConflict(
  619. pQMFilter->SrcAddr,
  620. pQMFilter->DesAddr
  621. );
  622. if (bConflicts) {
  623. dwError = ERROR_INVALID_PARAMETER;
  624. BAIL_ON_WIN32_ERROR(dwError);
  625. }
  626. dwError = VerifyProtocols(pQMFilter->Protocol);
  627. BAIL_ON_WIN32_ERROR(dwError);
  628. dwError = VerifyPortsForProtocol(
  629. pQMFilter->SrcPort,
  630. pQMFilter->Protocol
  631. );
  632. BAIL_ON_WIN32_ERROR(dwError);
  633. dwError = VerifyPortsForProtocol(
  634. pQMFilter->DesPort,
  635. pQMFilter->Protocol
  636. );
  637. BAIL_ON_WIN32_ERROR(dwError);
  638. if (pQMFilter->QMFilterType == QM_TUNNEL_FILTER) {
  639. if (pQMFilter->MyTunnelEndpt.AddrType != IP_ADDR_UNIQUE) {
  640. dwError=ERROR_INVALID_PARAMETER;
  641. BAIL_ON_WIN32_ERROR(dwError);
  642. }
  643. if (pQMFilter->PeerTunnelEndpt.AddrType != IP_ADDR_UNIQUE) {
  644. dwError=ERROR_INVALID_PARAMETER;
  645. BAIL_ON_WIN32_ERROR(dwError);
  646. }
  647. dwError = VerifyAddresses(pQMFilter->MyTunnelEndpt, FALSE, FALSE);
  648. BAIL_ON_WIN32_ERROR(dwError);
  649. dwError = VerifyAddresses(pQMFilter->PeerTunnelEndpt, FALSE, FALSE);
  650. BAIL_ON_WIN32_ERROR(dwError);
  651. }
  652. if (pQMFilter->QMFilterType != QM_TUNNEL_FILTER &&
  653. pQMFilter->QMFilterType != QM_TRANSPORT_FILTER) {
  654. dwError=ERROR_INVALID_PARAMETER;
  655. BAIL_ON_WIN32_ERROR(dwError);
  656. }
  657. error:
  658. return (dwError);
  659. }
  660. DWORD
  661. VerifyProtocols(
  662. PROTOCOL Protocol
  663. )
  664. {
  665. DWORD dwError = 0;
  666. switch (Protocol.ProtocolType) {
  667. case PROTOCOL_UNIQUE:
  668. if (Protocol.dwProtocol > 255) {
  669. dwError = ERROR_INVALID_PARAMETER;
  670. BAIL_ON_WIN32_ERROR(dwError);
  671. }
  672. break;
  673. default:
  674. dwError = ERROR_INVALID_PARAMETER;
  675. BAIL_ON_WIN32_ERROR(dwError);
  676. break;
  677. }
  678. error:
  679. return (dwError);
  680. }
  681. DWORD
  682. VerifyPortsForProtocol(
  683. PORT Port,
  684. PROTOCOL Protocol
  685. )
  686. {
  687. DWORD dwError = 0;
  688. switch (Port.PortType) {
  689. case PORT_UNIQUE:
  690. if (Port.wPort < 0) {
  691. dwError = ERROR_INVALID_PARAMETER;
  692. BAIL_ON_WIN32_ERROR(dwError);
  693. }
  694. switch (Protocol.ProtocolType) {
  695. case PROTOCOL_UNIQUE:
  696. if ((Protocol.dwProtocol != IPPROTO_TCP) &&
  697. (Protocol.dwProtocol != IPPROTO_UDP)) {
  698. if (Port.wPort != 0) {
  699. dwError = ERROR_INVALID_PARAMETER;
  700. BAIL_ON_WIN32_ERROR(dwError);
  701. }
  702. }
  703. break;
  704. default:
  705. dwError = ERROR_INVALID_PARAMETER;
  706. BAIL_ON_WIN32_ERROR(dwError);
  707. break;
  708. }
  709. break;
  710. default:
  711. dwError = ERROR_INVALID_PARAMETER;
  712. BAIL_ON_WIN32_ERROR(dwError);
  713. break;
  714. }
  715. error:
  716. return (dwError);
  717. }
  718. DWORD
  719. ValidateMMFilterTemplate(
  720. PMM_FILTER pMMFilter
  721. )
  722. {
  723. DWORD dwError = 0;
  724. BOOL bConflicts = FALSE;
  725. if (!pMMFilter) {
  726. dwError = ERROR_INVALID_PARAMETER;
  727. BAIL_ON_WIN32_ERROR(dwError);
  728. }
  729. dwError = VerifyAddresses(pMMFilter->SrcAddr, TRUE, FALSE);
  730. BAIL_ON_WIN32_ERROR(dwError);
  731. dwError = VerifyAddresses(pMMFilter->DesAddr, TRUE, TRUE);
  732. BAIL_ON_WIN32_ERROR(dwError);
  733. bConflicts = AddressesConflict(
  734. pMMFilter->SrcAddr,
  735. pMMFilter->DesAddr
  736. );
  737. if (bConflicts) {
  738. dwError = ERROR_INVALID_PARAMETER;
  739. BAIL_ON_WIN32_ERROR(dwError);
  740. }
  741. if (pMMFilter->dwDirection) {
  742. if ((pMMFilter->dwDirection != FILTER_DIRECTION_INBOUND) &&
  743. (pMMFilter->dwDirection != FILTER_DIRECTION_OUTBOUND)) {
  744. dwError = ERROR_INVALID_PARAMETER;
  745. BAIL_ON_WIN32_ERROR(dwError);
  746. }
  747. }
  748. error:
  749. return (dwError);
  750. }
  751. DWORD
  752. ValidateTxFilterTemplate(
  753. PTRANSPORT_FILTER pTxFilter
  754. )
  755. {
  756. DWORD dwError = 0;
  757. BOOL bConflicts = FALSE;
  758. if (!pTxFilter) {
  759. dwError = ERROR_INVALID_PARAMETER;
  760. BAIL_ON_WIN32_ERROR(dwError);
  761. }
  762. dwError = VerifyAddresses(pTxFilter->SrcAddr, TRUE, FALSE);
  763. BAIL_ON_WIN32_ERROR(dwError);
  764. dwError = VerifyAddresses(pTxFilter->DesAddr, TRUE, TRUE);
  765. BAIL_ON_WIN32_ERROR(dwError);
  766. bConflicts = AddressesConflict(
  767. pTxFilter->SrcAddr,
  768. pTxFilter->DesAddr
  769. );
  770. if (bConflicts) {
  771. dwError = ERROR_INVALID_PARAMETER;
  772. BAIL_ON_WIN32_ERROR(dwError);
  773. }
  774. dwError = VerifyProtocols(pTxFilter->Protocol);
  775. BAIL_ON_WIN32_ERROR(dwError);
  776. dwError = VerifyPortsForProtocol(
  777. pTxFilter->SrcPort,
  778. pTxFilter->Protocol
  779. );
  780. BAIL_ON_WIN32_ERROR(dwError);
  781. dwError = VerifyPortsForProtocol(
  782. pTxFilter->DesPort,
  783. pTxFilter->Protocol
  784. );
  785. BAIL_ON_WIN32_ERROR(dwError);
  786. if (pTxFilter->dwDirection) {
  787. if ((pTxFilter->dwDirection != FILTER_DIRECTION_INBOUND) &&
  788. (pTxFilter->dwDirection != FILTER_DIRECTION_OUTBOUND)) {
  789. dwError = ERROR_INVALID_PARAMETER;
  790. BAIL_ON_WIN32_ERROR(dwError);
  791. }
  792. }
  793. error:
  794. return (dwError);
  795. }
  796. DWORD
  797. ValidateTunnelFilter(
  798. PTUNNEL_FILTER pTunnelFilter
  799. )
  800. {
  801. DWORD dwError = 0;
  802. BOOL bConflicts = FALSE;
  803. if (!pTunnelFilter) {
  804. dwError = ERROR_INVALID_PARAMETER;
  805. BAIL_ON_WIN32_ERROR(dwError);
  806. }
  807. dwError = VerifyAddresses(pTunnelFilter->SrcAddr, TRUE, FALSE);
  808. BAIL_ON_WIN32_ERROR(dwError);
  809. dwError = VerifyAddresses(pTunnelFilter->DesAddr, TRUE, TRUE);
  810. BAIL_ON_WIN32_ERROR(dwError);
  811. bConflicts = AddressesConflict(
  812. pTunnelFilter->SrcAddr,
  813. pTunnelFilter->DesAddr
  814. );
  815. if (bConflicts) {
  816. dwError = ERROR_INVALID_PARAMETER;
  817. BAIL_ON_WIN32_ERROR(dwError);
  818. }
  819. dwError = VerifyAddresses(pTunnelFilter->DesTunnelAddr, TRUE, FALSE);
  820. BAIL_ON_WIN32_ERROR(dwError);
  821. dwError = VerifyProtocols(pTunnelFilter->Protocol);
  822. BAIL_ON_WIN32_ERROR(dwError);
  823. dwError = VerifyPortsForProtocol(
  824. pTunnelFilter->SrcPort,
  825. pTunnelFilter->Protocol
  826. );
  827. BAIL_ON_WIN32_ERROR(dwError);
  828. dwError = VerifyPortsForProtocol(
  829. pTunnelFilter->DesPort,
  830. pTunnelFilter->Protocol
  831. );
  832. BAIL_ON_WIN32_ERROR(dwError);
  833. if (!(pTunnelFilter->pszFilterName) || !(*(pTunnelFilter->pszFilterName))) {
  834. dwError = ERROR_INVALID_PARAMETER;
  835. BAIL_ON_WIN32_ERROR(dwError);
  836. }
  837. if (pTunnelFilter->InterfaceType >= INTERFACE_TYPE_MAX) {
  838. dwError = ERROR_INVALID_PARAMETER;
  839. BAIL_ON_WIN32_ERROR(dwError);
  840. }
  841. if (pTunnelFilter->bCreateMirror) {
  842. dwError = ERROR_INVALID_PARAMETER;
  843. BAIL_ON_WIN32_ERROR(dwError);
  844. }
  845. if (pTunnelFilter->InboundFilterFlag >= FILTER_FLAG_MAX) {
  846. dwError = ERROR_INVALID_PARAMETER;
  847. BAIL_ON_WIN32_ERROR(dwError);
  848. }
  849. if (pTunnelFilter->OutboundFilterFlag >= FILTER_FLAG_MAX) {
  850. dwError = ERROR_INVALID_PARAMETER;
  851. BAIL_ON_WIN32_ERROR(dwError);
  852. }
  853. if (pTunnelFilter->dwFlags &&
  854. !(pTunnelFilter->dwFlags & IPSEC_QM_POLICY_DEFAULT_POLICY)) {
  855. dwError = ERROR_INVALID_PARAMETER;
  856. BAIL_ON_WIN32_ERROR(dwError);
  857. }
  858. //
  859. // No need to call ApplyMulticastFilterValidation as bCreateMirror
  860. // is always false for a tunnel filter.
  861. //
  862. error:
  863. return (dwError);
  864. }
  865. DWORD
  866. ValidateTnFilterTemplate(
  867. PTUNNEL_FILTER pTnFilter
  868. )
  869. {
  870. DWORD dwError = 0;
  871. BOOL bConflicts = FALSE;
  872. if (!pTnFilter) {
  873. dwError = ERROR_INVALID_PARAMETER;
  874. BAIL_ON_WIN32_ERROR(dwError);
  875. }
  876. dwError = VerifyAddresses(pTnFilter->SrcAddr, TRUE, FALSE);
  877. BAIL_ON_WIN32_ERROR(dwError);
  878. dwError = VerifyAddresses(pTnFilter->DesAddr, TRUE, TRUE);
  879. BAIL_ON_WIN32_ERROR(dwError);
  880. bConflicts = AddressesConflict(
  881. pTnFilter->SrcAddr,
  882. pTnFilter->DesAddr
  883. );
  884. if (bConflicts) {
  885. dwError = ERROR_INVALID_PARAMETER;
  886. BAIL_ON_WIN32_ERROR(dwError);
  887. }
  888. dwError = VerifyAddresses(pTnFilter->DesTunnelAddr, TRUE, FALSE);
  889. BAIL_ON_WIN32_ERROR(dwError);
  890. dwError = VerifyProtocols(pTnFilter->Protocol);
  891. BAIL_ON_WIN32_ERROR(dwError);
  892. dwError = VerifyPortsForProtocol(
  893. pTnFilter->SrcPort,
  894. pTnFilter->Protocol
  895. );
  896. BAIL_ON_WIN32_ERROR(dwError);
  897. dwError = VerifyPortsForProtocol(
  898. pTnFilter->DesPort,
  899. pTnFilter->Protocol
  900. );
  901. BAIL_ON_WIN32_ERROR(dwError);
  902. if (pTnFilter->dwDirection) {
  903. if ((pTnFilter->dwDirection != FILTER_DIRECTION_INBOUND) &&
  904. (pTnFilter->dwDirection != FILTER_DIRECTION_OUTBOUND)) {
  905. dwError = ERROR_INVALID_PARAMETER;
  906. BAIL_ON_WIN32_ERROR(dwError);
  907. }
  908. }
  909. error:
  910. return (dwError);
  911. }
  912. DWORD
  913. ApplyMulticastFilterValidation(
  914. ADDR Addr,
  915. BOOL bCreateMirror
  916. )
  917. {
  918. DWORD dwError = 0;
  919. if (((Addr.AddrType == IP_ADDR_UNIQUE) ||
  920. (Addr.AddrType == IP_ADDR_SUBNET)) &&
  921. (IN_CLASSD(ntohl(Addr.uIpAddr))) &&
  922. bCreateMirror) {
  923. dwError = ERROR_INVALID_PARAMETER;
  924. BAIL_ON_WIN32_ERROR(dwError);
  925. }
  926. error:
  927. return (dwError);
  928. }