mirror of https://github.com/apache/cloudstack.git
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 <jayapal@apache.org>
This commit is contained in:
parent
ddb2149266
commit
51a4d2677c
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue