Skip to content

Commit 767c16c

Browse files
committed
NSX: Add appropriate error message when icmp type is set to -1 for NSX
1 parent 2b05dd9 commit 767c16c

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

server/src/main/java/com/cloud/network/vpc/NetworkACLServiceImpl.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,14 @@
2121
import java.util.Comparator;
2222
import java.util.List;
2323
import java.util.Map;
24+
import java.util.Objects;
2425

2526
import javax.inject.Inject;
2627

28+
import com.cloud.dc.DataCenter;
2729
import com.cloud.exception.PermissionDeniedException;
30+
import com.cloud.network.dao.NsxProviderDao;
31+
import com.cloud.network.element.NsxProviderVO;
2832
import org.apache.cloudstack.api.ApiErrorCode;
2933
import org.apache.cloudstack.api.ServerApiException;
3034
import org.apache.cloudstack.api.command.user.network.CreateNetworkACLCmd;
@@ -99,6 +103,10 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ
99103
private VpcDao _vpcDao;
100104
@Inject
101105
private VpcService _vpcSvc;
106+
@Inject
107+
private NsxProviderDao nsxProviderDao;
108+
@Inject
109+
private NetworkACLDao networkACLDao;
102110

103111
private String supportedProtocolsForAclRules = "tcp,udp,icmp,all";
104112

@@ -338,6 +346,7 @@ public NetworkACLItem createNetworkACLItem(CreateNetworkACLCmd createNetworkACLC
338346
if (isGlobalAcl(acl.getVpcId()) && !Account.Type.ADMIN.equals(caller.getType())) {
339347
throw new PermissionDeniedException("Only Root Admins can create rules for a global ACL.");
340348
}
349+
validateNsxConstraints(acl.getVpcId(), icmpType);
341350
validateAclRuleNumber(createNetworkACLCmd, acl);
342351

343352
NetworkACLItem.Action ruleAction = validateAndCreateNetworkAclRuleAction(action);
@@ -428,6 +437,18 @@ protected void validateNetworkAcl(NetworkACL acl) {
428437
}
429438
}
430439

440+
private void validateNsxConstraints(Long vpcId, Integer icpmType) {
441+
VpcVO vpc = _vpcDao.findById(vpcId);
442+
final DataCenter dc = _entityMgr.findById(DataCenter.class, vpc.getZoneId());
443+
final NsxProviderVO nsxProvider = nsxProviderDao.findByZoneId(dc.getId());
444+
if (Objects.isNull(nsxProvider)) {
445+
return;
446+
}
447+
if (icpmType == -1) {
448+
throw new InvalidParameterValueException("Passing -1 for ICMP type is not supported for NSX enabled zones");
449+
}
450+
}
451+
431452
/**
432453
* This methods will simply return the ACL rule list ID if it has been provided by the parameter 'createNetworkACLCmd'.
433454
* If no ACL rule List ID has been provided the method behave as follows:
@@ -817,7 +838,7 @@ public NetworkACLItem updateNetworkACLItem(UpdateNetworkACLItemCmd updateNetwork
817838

818839
NetworkACL acl = _networkAclMgr.getNetworkACL(networkACLItemVo.getAclId());
819840
validateNetworkAcl(acl);
820-
841+
validateNsxConstraints(acl.getVpcId(), networkACLItemVo.getIcmpType());
821842
Account account = CallContext.current().getCallingAccount();
822843
validateGlobalAclPermissionAndAclAssociatedToVpc(acl, account, "Only Root Admins can update global ACLs.");
823844

ui/public/locales/en.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
"error.release.dedicate.zone": "Failed to release dedicated zone.",
1616
"error.unable.to.proceed": "Unable to proceed. Please contact your administrator.",
1717
"firewall.close": "Firewall",
18-
"icmp.code.desc": "Please specify -1 if you want to allow all ICMP codes.",
19-
"icmp.type.desc": "Please specify -1 if you want to allow all ICMP types.",
18+
"icmp.code.desc": "Please specify -1 if you want to allow all ICMP codes for non-NSX zones.",
19+
"icmp.type.desc": "Please specify -1 if you want to allow all ICMP types for non-NSX zones.",
2020
"inline": "Inline",
2121
"label.about": "About",
2222
"label.about.app": "About CloudStack",

0 commit comments

Comments
 (0)