mirror of https://github.com/apache/cloudstack.git
address comments
This commit is contained in:
parent
66f923272c
commit
dccace914e
|
|
@ -2862,7 +2862,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
|
|||
|
||||
// Check if cidr is RFC1918 compliant if the network is Guest Isolated for IPv4
|
||||
if (cidr != null && ntwkOff.getGuestType() == Network.GuestType.Isolated && ntwkOff.getTrafficType() == TrafficType.Guest) {
|
||||
if (!ConfigurationManager.AllowNonRFC1918CompliantIPs.value() && !NetUtils.validateGuestCidr(cidr)) {
|
||||
if (!NetUtils.validateGuestCidr(cidr, !ConfigurationManager.AllowNonRFC1918CompliantIPs.value())) {
|
||||
throw new InvalidParameterValueException("Virtual Guest Cidr " + cidr + " is not RFC 1918 or 6598 compliant");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2648,7 +2648,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
|
|||
zoneName = zone.getName();
|
||||
}
|
||||
|
||||
if (guestCidr != null && !AllowNonRFC1918CompliantIPs.value() && !NetUtils.validateGuestCidr(guestCidr)) {
|
||||
if (guestCidr != null && !NetUtils.validateGuestCidr(guestCidr, !AllowNonRFC1918CompliantIPs.value())) {
|
||||
throw new InvalidParameterValueException("Please enter a valid guest cidr");
|
||||
}
|
||||
|
||||
|
|
@ -2817,7 +2817,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
|
|||
// checking the following params outside checkzoneparams method as we do
|
||||
// not use these params for updatezone
|
||||
// hence the method below is generic to check for common params
|
||||
if (guestCidr != null && !AllowNonRFC1918CompliantIPs.value() && !NetUtils.validateGuestCidr(guestCidr)) {
|
||||
if (guestCidr != null && !NetUtils.validateGuestCidr(guestCidr, !AllowNonRFC1918CompliantIPs.value())) {
|
||||
throw new InvalidParameterValueException("Please enter a valid guest cidr");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3125,7 +3125,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService, C
|
|||
if (!NetUtils.isValidIp4Cidr(guestVmCidr)) {
|
||||
throw new InvalidParameterValueException("Invalid format of Guest VM CIDR.");
|
||||
}
|
||||
if (!ConfigurationManager.AllowNonRFC1918CompliantIPs.value() && !NetUtils.validateGuestCidr(guestVmCidr)) {
|
||||
if (!NetUtils.validateGuestCidr(guestVmCidr, !ConfigurationManager.AllowNonRFC1918CompliantIPs.value())) {
|
||||
throw new InvalidParameterValueException("Invalid format of Guest VM CIDR. Make sure it is RFC1918 compliant. ");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1216,7 +1216,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
|
|||
}
|
||||
|
||||
// cidr has to be RFC 1918 complient
|
||||
if (!ConfigurationManager.AllowNonRFC1918CompliantIPs.value() && !NetUtils.validateGuestCidr(cidr)) {
|
||||
if (!NetUtils.validateGuestCidr(cidr, !ConfigurationManager.AllowNonRFC1918CompliantIPs.value())) {
|
||||
throw new InvalidParameterValueException("Guest Cidr " + cidr + " is not RFC1918 compliant");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1116,7 +1116,7 @@ public class NetUtils {
|
|||
return false;
|
||||
}
|
||||
|
||||
public static boolean validateGuestCidr(final String cidr) {
|
||||
public static boolean validateGuestCidr(final String cidr, boolean checkCompliance) {
|
||||
// RFC 1918 - The Internet Assigned Numbers Authority (IANA) has reserved the
|
||||
// following three blocks of the IP address space for private internets:
|
||||
// 10.0.0.0 - 10.255.255.255 (10/8 prefix)
|
||||
|
|
@ -1133,6 +1133,9 @@ public class NetUtils {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!checkCompliance) {
|
||||
return true;
|
||||
}
|
||||
for (String block: allowedNetBlocks) {
|
||||
if (isNetworkAWithinNetworkB(cidr, block)) {
|
||||
return true;
|
||||
|
|
@ -1235,9 +1238,9 @@ public class NetUtils {
|
|||
return true;
|
||||
}
|
||||
|
||||
public static boolean validateGuestCidrList(final String guestCidrList) {
|
||||
public static boolean validateGuestCidrList(final String guestCidrList, boolean checkCompliance) {
|
||||
for (final String guestCidr : guestCidrList.split(",")) {
|
||||
if (!validateGuestCidr(guestCidr)) {
|
||||
if (!validateGuestCidr(guestCidr, checkCompliance)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -354,10 +354,10 @@ public class NetUtilsTest {
|
|||
final String[] invalidCidrs = {"172.33.1.0/16", "100.128.1.0/10"};
|
||||
|
||||
for (String cidr: validCidrs) {
|
||||
assertTrue(NetUtils.validateGuestCidr(cidr));
|
||||
assertTrue(NetUtils.validateGuestCidr(cidr, true));
|
||||
}
|
||||
for (String cidr: invalidCidrs) {
|
||||
assertFalse(NetUtils.validateGuestCidr(cidr));
|
||||
assertFalse(NetUtils.validateGuestCidr(cidr, true));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue