From b0e4ecb3afd653067c707bd018f4d80cda15dec2 Mon Sep 17 00:00:00 2001 From: alena Date: Wed, 16 Feb 2011 11:01:57 -0800 Subject: [PATCH] bug 7901: Prevent using the same cidr for POD and zone's virtual network status 7901: resolved fixed --- .../configuration/ConfigurationManagerImpl.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index 4b814ec6cc9..939bf3ff5f6 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -468,7 +468,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura if (NetUtils.ipRangesOverlap(startIp, endIp, gateway, gateway)) { throw new InvalidParameterValueException("The gateway shouldn't overlap start/end ip addresses"); } - + String checkPodCIDRs = _configDao.getValue("check.pod.cidrs"); if (checkPodCIDRs == null || checkPodCIDRs.trim().isEmpty() || Boolean.parseBoolean(checkPodCIDRs)) { // Check if the CIDR conflicts with the Guest Network or other pods @@ -478,6 +478,21 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura newCidrPair.add(1, new Long(cidrSize)); currentPodCidrSubnets.put(new Long(-1), newCidrPair); checkPodCidrSubnets(zoneId, currentPodCidrSubnets); + + //Prevent using the same CIDR for POD and virtual networking + List vlans = _vlanDao.listByZoneAndType(zoneId, VlanType.VirtualNetwork); + for (VlanVO vlan : vlans) { + String vlanCidr = NetUtils.ipAndNetMaskToCidr(vlan.getVlanGateway(), vlan.getVlanNetmask()); + String[] cidrPairVlan = vlanCidr.split("\\/"); + String[] vlanIpRange = NetUtils.getIpRangeFromCidr(cidrPairVlan[0], Long.valueOf(cidrPairVlan[1])); + + String[] cidrPairPod = cidr.split("\\/"); + String[] podIpRange = NetUtils.getIpRangeFromCidr(cidrPairPod[0], Long.valueOf(cidrPairPod[1])); + + if (NetUtils.ipRangesOverlap(vlanIpRange[0], vlanIpRange[1], podIpRange[0], podIpRange[1])) { + throw new InvalidParameterValueException("Pod's cidr conflicts with cidr of virtual network in zone id=" + zoneId); + } + } } }