Skip to content

Commit c1294fd

Browse files
committed
CLOUDSTACK-4596: CloudStack is currently allowing same ip range to be
defined in different VLANs across public and portable ranges added checks to restric same ip range to be configure as both public ip range and portable ip range
1 parent 2b6b99f commit c1294fd

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

‎server/src/com/cloud/configuration/ConfigurationManagerImpl.java‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3094,6 +3094,12 @@ public Vlan createVlanAndPublicIpRange(long zoneId, long networkId, long physica
30943094
// Check if there are any errors with the IP range
30953095
checkPublicIpRangeErrors(zoneId, vlanId, vlanGateway, vlanNetmask, startIP, endIP);
30963096

3097+
// check and throw exception if there is portable IP range that overlaps with ip range being configure
3098+
if (checkOverlapPortableIpRange(_regionDao.getRegionId(), startIP, endIP)) {
3099+
throw new InvalidParameterValueException("Ip range: " + startIP + "-" + endIP
3100+
+ " overlaps with a portable" + " IP range already configured in the region " + _regionDao.getRegionId());
3101+
}
3102+
30973103
// Throw an exception if this subnet overlaps with subnet on other VLAN,
30983104
// if this is ip range extension, gateway, network mask should be same and ip range should not overlap
30993105

@@ -5091,17 +5097,18 @@ public PortableIpRange createPortableIpRange(CreatePortableIpRangeCmd cmd) throw
50915097
throw new InvalidParameterValueException("Invalid vlan id " + vlanId);
50925098
}
50935099

5094-
// check if there is zone vlan with same id
50955100
List<DataCenterVO> zones= _zoneDao.listAllZones();
50965101
if (zones != null && !zones.isEmpty()) {
50975102
for (DataCenterVO zone: zones) {
5103+
// check if there is zone vlan with same id
50985104
if (_vlanDao.findByZoneAndVlanId(zone.getId(), vlanId) != null) {
50995105
throw new InvalidParameterValueException("Found a VLAN id " + vlanId + " already existing in"
51005106
+ " zone " + zone.getUuid() + " that conflicts with VLAN id of the portable ip range being configured");
51015107
}
5108+
//check if there is a public ip range that overlaps with portable ip range being created
5109+
checkOverlapPublicIpRange(zone.getId(), startIP, endIP);
51025110
}
51035111
}
5104-
51055112
}
51065113
GlobalLock portableIpLock = GlobalLock.getInternLock("PortablePublicIpRange");
51075114
portableIpLock.lock(5);
@@ -5204,6 +5211,11 @@ private boolean checkOverlapPortableIpRange(int regionId, String newStartIpStr,
52045211
long newEndIp = NetUtils.ip2Long(newEndIpStr);
52055212

52065213
List<PortableIpRangeVO> existingPortableIPRanges = _portableIpRangeDao.listByRegionId(regionId);
5214+
5215+
if (existingPortableIPRanges == null || existingPortableIPRanges.isEmpty()) {
5216+
return false;
5217+
}
5218+
52075219
for (PortableIpRangeVO portableIpRange : existingPortableIPRanges) {
52085220
String ipRangeStr = portableIpRange.getIpRange();
52095221
String[] range = ipRangeStr.split("-");

0 commit comments

Comments
 (0)