Skip to content

Commit 3027501

Browse files
authored
NSX: Add appropriate error message when icmp type is set to -1 for NSX (#8504)
* NSX: Add appropriate error message when icmp type is set to -1 for NSX * address comments * update text
1 parent a4f6305 commit 3027501

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,8 @@ public class NetworkACLServiceImpl extends ManagerBase implements NetworkACLServ
99103
private VpcDao _vpcDao;
100104
@Inject
101105
private VpcService _vpcSvc;
106+
@Inject
107+
private NsxProviderDao nsxProviderDao;
102108

103109
private String supportedProtocolsForAclRules = "tcp,udp,icmp,all";
104110

@@ -338,6 +344,7 @@ public NetworkACLItem createNetworkACLItem(CreateNetworkACLCmd createNetworkACLC
338344
if (isGlobalAcl(acl.getVpcId()) && !Account.Type.ADMIN.equals(caller.getType())) {
339345
throw new PermissionDeniedException("Only Root Admins can create rules for a global ACL.");
340346
}
347+
validateNsxConstraints(acl.getVpcId(), icmpType);
341348
validateAclRuleNumber(createNetworkACLCmd, acl);
342349

343350
NetworkACLItem.Action ruleAction = validateAndCreateNetworkAclRuleAction(action);
@@ -428,6 +435,20 @@ protected void validateNetworkAcl(NetworkACL acl) {
428435
}
429436
}
430437

438+
private void validateNsxConstraints(Long vpcId, Integer icpmType) {
439+
VpcVO vpc = _vpcDao.findById(vpcId);
440+
final DataCenter dc = _entityMgr.findById(DataCenter.class, vpc.getZoneId());
441+
final NsxProviderVO nsxProvider = nsxProviderDao.findByZoneId(dc.getId());
442+
if (Objects.isNull(nsxProvider)) {
443+
return;
444+
}
445+
if (icpmType == -1) {
446+
String errorMsg = "Passing -1 for ICMP type is not supported for NSX enabled zones";
447+
s_logger.error(errorMsg);
448+
throw new InvalidParameterValueException(errorMsg);
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 (except NSX zones).",
19+
"icmp.type.desc": "Please specify -1 if you want to allow all ICMP types (except NSX zones).",
2020
"inline": "Inline",
2121
"label.about": "About",
2222
"label.about.app": "About CloudStack",

0 commit comments

Comments
 (0)