Updated Branches: refs/heads/4.2 c1294fdfa -> 51a4d2677
CLOUDSTACK-4811:Fixed zone creation wizard is allowing to accept wrong sub net mask which is cauing wrong cidr value for a given ip range Signed-off-by: Jayapal <jaya...@apache.org> Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/51a4d267 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/51a4d267 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/51a4d267 Branch: refs/heads/4.2 Commit: 51a4d2677cdc5964916378c568fd7da18d0aaa5f Parents: ddb2149 Author: Damodar Reddy <damoder.re...@citrix.com> Authored: Fri Oct 18 15:09:21 2013 +0530 Committer: Jayapal <jaya...@apache.org> Committed: Fri Oct 18 15:51:13 2013 +0530 ---------------------------------------------------------------------- .../cloud/configuration/ConfigurationManagerImpl.java | 7 ++++++- utils/pom.xml | 5 +++++ utils/src/com/cloud/utils/net/NetUtils.java | 12 ++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/51a4d267/server/src/com/cloud/configuration/ConfigurationManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index e77e1d1..4df12e2 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -3062,7 +3062,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati } // Make sure the netmask is valid - if (!NetUtils.isValidIp(vlanNetmask)) { + if (!NetUtils.isValidNetmask(vlanNetmask)) { throw new InvalidParameterValueException("Please specify a valid netmask"); } } @@ -3079,6 +3079,11 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati if (ipv4) { String newCidr = NetUtils.getCidrFromGatewayAndNetmask(vlanGateway, vlanNetmask); + //Make sure start and end ips are with in the range of cidr calculated for this gateway and netmask { + if(!NetUtils.isIpWithtInCidrRange(vlanGateway, newCidr) || !NetUtils.isIpWithtInCidrRange(startIP, newCidr) || !NetUtils.isIpWithtInCidrRange(endIP, newCidr)) { + throw new InvalidParameterValueException("Please specify a valid IP range or valid netmask or valid gateway"); + } + // Check if the new VLAN's subnet conflicts with the guest network // in // the specified zone (guestCidr is null for basic zone) http://git-wip-us.apache.org/repos/asf/cloudstack/blob/51a4d267/utils/pom.xml ---------------------------------------------------------------------- diff --git a/utils/pom.xml b/utils/pom.xml old mode 100644 new mode 100755 index efe931f..ab3419a --- a/utils/pom.xml +++ b/utils/pom.xml @@ -163,6 +163,11 @@ <artifactId>esapi</artifactId> <version>2.0.1</version> </dependency> + <dependency> + <groupId>commons-net</groupId> + <artifactId>commons-net</artifactId> + <version>3.3</version> + </dependency> </dependencies> <build> <defaultGoal>install</defaultGoal> http://git-wip-us.apache.org/repos/asf/cloudstack/blob/51a4d267/utils/src/com/cloud/utils/net/NetUtils.java ---------------------------------------------------------------------- diff --git a/utils/src/com/cloud/utils/net/NetUtils.java b/utils/src/com/cloud/utils/net/NetUtils.java index ba24c95..14a6c70 100755 --- a/utils/src/com/cloud/utils/net/NetUtils.java +++ b/utils/src/com/cloud/utils/net/NetUtils.java @@ -38,6 +38,7 @@ import com.googlecode.ipv6.IPv6Network; import com.cloud.utils.IteratorUtil; import com.cloud.utils.Pair; +import org.apache.commons.net.util.SubnetUtils; import com.cloud.utils.script.Script; import org.apache.commons.lang.SystemUtils; @@ -1412,4 +1413,15 @@ public class NetUtils { mac = mac & 0x06FFFFFFFFFFl; return long2Mac(mac); } + + public static boolean isIpWithtInCidrRange(String ipAddress, String cidr) { + if (!isValidIp(ipAddress)) { + return false; + } + if (!isValidCIDR(cidr)) { + return false; + } + SubnetUtils subnetUtils = new SubnetUtils(cidr); + return subnetUtils.getInfo().isInRange(ipAddress); + } }