mirror of
https://github.com/apache/cloudstack.git
synced 2025-12-17 02:53:18 +01:00
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
aaa99cd9de
commit
a92095a4a6
@ -2890,7 +2890,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Make sure the netmask is valid
|
// Make sure the netmask is valid
|
||||||
if (!NetUtils.isValidIp(vlanNetmask)) {
|
if (!NetUtils.isValidNetmask(vlanNetmask)) {
|
||||||
throw new InvalidParameterValueException("Please specify a valid netmask");
|
throw new InvalidParameterValueException("Please specify a valid netmask");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2907,6 +2907,11 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
|
|||||||
if (ipv4) {
|
if (ipv4) {
|
||||||
String newCidr = NetUtils.getCidrFromGatewayAndNetmask(vlanGateway, vlanNetmask);
|
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
|
// Check if the new VLAN's subnet conflicts with the guest network
|
||||||
// in
|
// in
|
||||||
// the specified zone (guestCidr is null for basic zone)
|
// the specified zone (guestCidr is null for basic zone)
|
||||||
|
|||||||
5
utils/pom.xml
Normal file → Executable file
5
utils/pom.xml
Normal file → Executable file
@ -112,6 +112,11 @@
|
|||||||
<groupId>org.owasp.esapi</groupId>
|
<groupId>org.owasp.esapi</groupId>
|
||||||
<artifactId>esapi</artifactId>
|
<artifactId>esapi</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-net</groupId>
|
||||||
|
<artifactId>commons-net</artifactId>
|
||||||
|
<version>3.3</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
|||||||
@ -46,6 +46,7 @@ import com.googlecode.ipv6.IPv6Network;
|
|||||||
|
|
||||||
import com.cloud.utils.IteratorUtil;
|
import com.cloud.utils.IteratorUtil;
|
||||||
import com.cloud.utils.Pair;
|
import com.cloud.utils.Pair;
|
||||||
|
import org.apache.commons.net.util.SubnetUtils;
|
||||||
import com.cloud.utils.script.Script;
|
import com.cloud.utils.script.Script;
|
||||||
|
|
||||||
public class NetUtils {
|
public class NetUtils {
|
||||||
@ -1420,4 +1421,15 @@ public class NetUtils {
|
|||||||
mac = mac & 0x06FFFFFFFFFFl;
|
mac = mac & 0x06FFFFFFFFFFl;
|
||||||
return long2Mac(mac);
|
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…
x
Reference in New Issue
Block a user