mirror of https://github.com/apache/cloudstack.git
VPC: CS-15580 - don't allow gateway for VPC guest network to be equal to the cidr subnet
Conflicts: server/src/com/cloud/network/NetworkManagerImpl.java server/src/com/cloud/network/vpc/VpcManagerImpl.java
This commit is contained in:
parent
a1acfd3bfa
commit
4a7149e6b5
|
|
@ -22,7 +22,6 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
|
||||
import com.cloud.acl.ControlledEntity.ACLType;
|
||||
import com.cloud.agent.api.to.NicTO;
|
||||
import com.cloud.dc.DataCenter;
|
||||
import com.cloud.dc.Vlan;
|
||||
import com.cloud.dc.Vlan.VlanType;
|
||||
|
|
@ -55,7 +54,6 @@ import com.cloud.user.Account;
|
|||
import com.cloud.utils.Pair;
|
||||
import com.cloud.vm.Nic;
|
||||
import com.cloud.vm.NicProfile;
|
||||
import com.cloud.vm.NicVO;
|
||||
import com.cloud.vm.ReservationContext;
|
||||
import com.cloud.vm.VMInstanceVO;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
|
|
|
|||
|
|
@ -2852,8 +2852,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
networkDomain = vpc.getNetworkDomain();
|
||||
}
|
||||
//1) Validate if network can be created for VPC
|
||||
_vpcMgr.validateGuestNtkwForVpc(_configMgr.getNetworkOffering(ntwkOffId), cidr, networkDomain, owner, vpc, null);
|
||||
|
||||
_vpcMgr.validateGuestNtkwForVpc(_configMgr.getNetworkOffering(ntwkOffId), cidr, networkDomain, owner, vpc, null, gateway);
|
||||
//2) Create network
|
||||
Network guestNetwork = createGuestNetwork(ntwkOffId, name, displayText, gateway, cidr, vlanId,
|
||||
networkDomain, owner, domainId, pNtwk, zoneId, aclType, subdomainAccess, vpcId);
|
||||
|
|
@ -4677,7 +4676,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
//perform below validation if the network is vpc network
|
||||
if (network.getVpcId() != null) {
|
||||
Vpc vpc = _vpcMgr.getVpc(network.getVpcId());
|
||||
_vpcMgr.validateGuestNtkwForVpc(networkOffering, null, null, null,vpc, networkId);
|
||||
_vpcMgr.validateGuestNtkwForVpc(networkOffering, null, null, null,vpc, networkId, null);
|
||||
}
|
||||
|
||||
if (networkOfferingId != oldNetworkOfferingId) {
|
||||
|
|
|
|||
|
|
@ -68,10 +68,11 @@ public interface VpcManager extends VpcService{
|
|||
* @param networkOwner
|
||||
* @param vpc TODO
|
||||
* @param networkId TODO
|
||||
* @param gateway TODO
|
||||
* @return
|
||||
*/
|
||||
void validateGuestNtkwForVpc(NetworkOffering guestNtwkOff, String cidr, String networkDomain, Account networkOwner,
|
||||
Vpc vpc, Long networkId);
|
||||
Vpc vpc, Long networkId, String gateway);
|
||||
|
||||
/**
|
||||
* @return
|
||||
|
|
|
|||
|
|
@ -858,11 +858,11 @@ public class VpcManagerImpl implements VpcManager, Manager{
|
|||
@Override
|
||||
@DB
|
||||
public void validateGuestNtkwForVpc(NetworkOffering guestNtwkOff, String cidr, String networkDomain,
|
||||
Account networkOwner, Vpc vpc, Long networkId) {
|
||||
|
||||
Account networkOwner, Vpc vpc, Long networkId, String gateway) {
|
||||
|
||||
if (networkId == null) {
|
||||
//1) Validate attributes that has to be passed in when create new guest network
|
||||
validateNewVpcGuestNetwork(cidr, networkOwner, vpc, networkDomain);
|
||||
validateNewVpcGuestNetwork(cidr, gateway, networkOwner, vpc, networkDomain);
|
||||
}
|
||||
|
||||
//2) Only Isolated networks with Source nat service enabled can be added to vpc
|
||||
|
|
@ -914,7 +914,7 @@ public class VpcManagerImpl implements VpcManager, Manager{
|
|||
|
||||
}
|
||||
|
||||
protected void validateNewVpcGuestNetwork(String cidr, Account networkOwner, Vpc vpc, String networkDomain) {
|
||||
protected void validateNewVpcGuestNetwork(String cidr, String gateway, Account networkOwner, Vpc vpc, String networkDomain) {
|
||||
Vpc locked = _vpcDao.acquireInLockTable(vpc.getId());
|
||||
if (locked == null) {
|
||||
throw new CloudRuntimeException("Unable to acquire lock on " + vpc);
|
||||
|
|
@ -954,6 +954,12 @@ public class VpcManagerImpl implements VpcManager, Manager{
|
|||
throw new InvalidParameterValueException("Network domain of the new network should match network" +
|
||||
" domain of vpc " + vpc);
|
||||
}
|
||||
|
||||
//6) gateway should never be equal to the cidr subnet
|
||||
if (NetUtils.getCidrSubNet(cidr).equalsIgnoreCase(gateway)) {
|
||||
throw new InvalidParameterValueException("Invalid gateway specified. It should never be equal to the cidr subnet value");
|
||||
}
|
||||
|
||||
} finally {
|
||||
s_logger.debug("Releasing lock for " + locked);
|
||||
_vpcDao.releaseFromLockTable(locked.getId());
|
||||
|
|
|
|||
|
|
@ -516,7 +516,6 @@ public class NetUtils {
|
|||
if (octetString.length() < 1 || octetString.length() > 3) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// IP is good, return true
|
||||
|
|
|
|||
Loading…
Reference in New Issue