VPC: CS-15580 - don't allow gateway for VPC guest network to be equal to the cidr subnet

This commit is contained in:
Alena Prokharchyk 2012-07-13 17:05:33 -07:00
parent 15664dd37a
commit b145029718
4 changed files with 13 additions and 7 deletions

View File

@ -2825,7 +2825,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,
@ -4654,7 +4654,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) {

View File

@ -71,10 +71,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

View File

@ -898,11 +898,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
@ -958,7 +958,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);
@ -1006,6 +1006,12 @@ public class VpcManagerImpl implements VpcManager, Manager{
throw new InvalidParameterValueException("Network domain of the new network should match network" +
" domain of vpc with specified vpcId", idList);
}
//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());

View File

@ -512,7 +512,6 @@ public class NetUtils {
if (octetString.length() < 1 || octetString.length() > 3) {
return false;
}
}
// IP is good, return true