|
20 | 20 | import java.util.Collections; |
21 | 21 | import java.util.Comparator; |
22 | 22 | import java.util.List; |
| 23 | +import java.util.Locale; |
23 | 24 | import java.util.Map; |
24 | 25 | import java.util.Objects; |
25 | 26 |
|
@@ -344,7 +345,7 @@ public NetworkACLItem createNetworkACLItem(CreateNetworkACLCmd createNetworkACLC |
344 | 345 | if (isGlobalAcl(acl.getVpcId()) && !Account.Type.ADMIN.equals(caller.getType())) { |
345 | 346 | throw new PermissionDeniedException("Only Root Admins can create rules for a global ACL."); |
346 | 347 | } |
347 | | - validateNsxConstraints(acl.getVpcId(), icmpType); |
| 348 | + validateNsxConstraints(acl.getVpcId(), protocol, icmpType, icmpCode, sourcePortStart, sourcePortEnd); |
348 | 349 | validateAclRuleNumber(createNetworkACLCmd, acl); |
349 | 350 |
|
350 | 351 | NetworkACLItem.Action ruleAction = validateAndCreateNetworkAclRuleAction(action); |
@@ -435,18 +436,27 @@ protected void validateNetworkAcl(NetworkACL acl) { |
435 | 436 | } |
436 | 437 | } |
437 | 438 |
|
438 | | - private void validateNsxConstraints(Long vpcId, Integer icpmType) { |
| 439 | + private void validateNsxConstraints(long vpcId, String protocol, Integer icmpType, |
| 440 | + Integer icmpCode, Integer sourcePortStart, Integer sourcePortEnd) { |
439 | 441 | VpcVO vpc = _vpcDao.findById(vpcId); |
440 | 442 | final DataCenter dc = _entityMgr.findById(DataCenter.class, vpc.getZoneId()); |
441 | 443 | final NsxProviderVO nsxProvider = nsxProviderDao.findByZoneId(dc.getId()); |
442 | 444 | if (Objects.isNull(nsxProvider)) { |
443 | 445 | return; |
444 | 446 | } |
445 | | - if (icpmType == -1) { |
| 447 | + |
| 448 | + if (NetUtils.ICMP_PROTO.equals(protocol.toLowerCase(Locale.ROOT)) && (icmpType == -1 || icmpCode == -1)) { |
446 | 449 | String errorMsg = "Passing -1 for ICMP type is not supported for NSX enabled zones"; |
447 | 450 | s_logger.error(errorMsg); |
448 | 451 | throw new InvalidParameterValueException(errorMsg); |
449 | 452 | } |
| 453 | + |
| 454 | + if (List.of(NetUtils.TCP_PROTO, NetUtils.UDP_PROTO).contains(protocol.toLowerCase(Locale.ROOT)) && |
| 455 | + (Objects.isNull(sourcePortStart) || Objects.isNull(sourcePortEnd))) { |
| 456 | + String errorMsg = "Source start and end ports are required to be passed"; |
| 457 | + s_logger.error(errorMsg); |
| 458 | + throw new InvalidParameterValueException(errorMsg); |
| 459 | + } |
450 | 460 | } |
451 | 461 |
|
452 | 462 | /** |
@@ -838,7 +848,8 @@ public NetworkACLItem updateNetworkACLItem(UpdateNetworkACLItemCmd updateNetwork |
838 | 848 |
|
839 | 849 | NetworkACL acl = _networkAclMgr.getNetworkACL(networkACLItemVo.getAclId()); |
840 | 850 | validateNetworkAcl(acl); |
841 | | - validateNsxConstraints(acl.getVpcId(), networkACLItemVo.getIcmpType()); |
| 851 | + validateNsxConstraints(acl.getVpcId(), networkACLItemVo.getProtocol(), networkACLItemVo.getIcmpType(), |
| 852 | + networkACLItemVo.getIcmpCode(), networkACLItemVo.getSourcePortStart(), networkACLItemVo.getSourcePortEnd()); |
842 | 853 | Account account = CallContext.current().getCallingAccount(); |
843 | 854 | validateGlobalAclPermissionAndAclAssociatedToVpc(acl, account, "Only Root Admins can update global ACLs."); |
844 | 855 |
|
|
0 commit comments