You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ja...@apache.org on 2013/10/18 12:22:15 UTC
git commit: updated refs/heads/master to a92095a
Updated Branches:
refs/heads/master aaa99cd9d -> a92095a4a
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 <ja...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/a92095a4
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/a92095a4
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/a92095a4
Branch: refs/heads/master
Commit: a92095a4a6ce771387956a7c35fcbf47dbd35eee
Parents: aaa99cd
Author: Damodar Reddy <da...@citrix.com>
Authored: Fri Oct 18 15:09:21 2013 +0530
Committer: Jayapal <ja...@apache.org>
Committed: Fri Oct 18 15:51:51 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/a92095a4/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 b4429cb..a0be496 100755
--- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
+++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
@@ -2890,7 +2890,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");
}
}
@@ -2907,6 +2907,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/a92095a4/utils/pom.xml
----------------------------------------------------------------------
diff --git a/utils/pom.xml b/utils/pom.xml
old mode 100644
new mode 100755
index 35012b2..ec66839
--- a/utils/pom.xml
+++ b/utils/pom.xml
@@ -112,6 +112,11 @@
<groupId>org.owasp.esapi</groupId>
<artifactId>esapi</artifactId>
</dependency>
+ <dependency>
+ <groupId>commons-net</groupId>
+ <artifactId>commons-net</artifactId>
+ <version>3.3</version>
+ </dependency>
</dependencies>
<build>
<plugins>
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a92095a4/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 e64af4c..f590425 100755
--- a/utils/src/com/cloud/utils/net/NetUtils.java
+++ b/utils/src/com/cloud/utils/net/NetUtils.java
@@ -46,6 +46,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;
public class NetUtils {
@@ -1420,4 +1421,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);
+ }
}