Skip to content

Commit a92095a

Browse files
Damodar ReddyJayapal
authored andcommitted
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>
1 parent aaa99cd commit a92095a

3 files changed

Lines changed: 23 additions & 1 deletion

File tree

‎server/src/com/cloud/configuration/ConfigurationManagerImpl.java‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2890,7 +2890,7 @@ public Vlan createVlanAndPublicIpRange(long zoneId, long networkId, long physica
28902890
}
28912891

28922892
// Make sure the netmask is valid
2893-
if (!NetUtils.isValidIp(vlanNetmask)) {
2893+
if (!NetUtils.isValidNetmask(vlanNetmask)) {
28942894
throw new InvalidParameterValueException("Please specify a valid netmask");
28952895
}
28962896
}
@@ -2907,6 +2907,11 @@ public Vlan createVlanAndPublicIpRange(long zoneId, long networkId, long physica
29072907
if (ipv4) {
29082908
String newCidr = NetUtils.getCidrFromGatewayAndNetmask(vlanGateway, vlanNetmask);
29092909

2910+
//Make sure start and end ips are with in the range of cidr calculated for this gateway and netmask {
2911+
if(!NetUtils.isIpWithtInCidrRange(vlanGateway, newCidr) || !NetUtils.isIpWithtInCidrRange(startIP, newCidr) || !NetUtils.isIpWithtInCidrRange(endIP, newCidr)) {
2912+
throw new InvalidParameterValueException("Please specify a valid IP range or valid netmask or valid gateway");
2913+
}
2914+
29102915
// Check if the new VLAN's subnet conflicts with the guest network
29112916
// in
29122917
// the specified zone (guestCidr is null for basic zone)

‎utils/pom.xml‎

100644100755
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@
112112
<groupId>org.owasp.esapi</groupId>
113113
<artifactId>esapi</artifactId>
114114
</dependency>
115+
<dependency>
116+
<groupId>commons-net</groupId>
117+
<artifactId>commons-net</artifactId>
118+
<version>3.3</version>
119+
</dependency>
115120
</dependencies>
116121
<build>
117122
<plugins>

‎utils/src/com/cloud/utils/net/NetUtils.java‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646

4747
import com.cloud.utils.IteratorUtil;
4848
import com.cloud.utils.Pair;
49+
import org.apache.commons.net.util.SubnetUtils;
4950
import com.cloud.utils.script.Script;
5051

5152
public class NetUtils {
@@ -1420,4 +1421,15 @@ public static String generateMacOnIncrease(String baseMac, long l) {
14201421
mac = mac & 0x06FFFFFFFFFFl;
14211422
return long2Mac(mac);
14221423
}
1424+
1425+
public static boolean isIpWithtInCidrRange(String ipAddress, String cidr) {
1426+
if (!isValidIp(ipAddress)) {
1427+
return false;
1428+
}
1429+
if (!isValidCIDR(cidr)) {
1430+
return false;
1431+
}
1432+
SubnetUtils subnetUtils = new SubnetUtils(cidr);
1433+
return subnetUtils.getInfo().isInRange(ipAddress);
1434+
}
14231435
}

0 commit comments

Comments
 (0)