mirror of https://github.com/apache/cloudstack.git
IPv6: Verify if requested IPv4/IPv6 addresses are valid
Also rename NetUtils.isValidIPv6() to NetUtils.isValidIpv6()
This commit is contained in:
parent
249d8e09bb
commit
f5ee570ec3
|
|
@ -2369,7 +2369,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
|||
}
|
||||
|
||||
if (ipv6) {
|
||||
if (!NetUtils.isValidIPv6(vlanGatewayv6)) {
|
||||
if (!NetUtils.isValidIpv6(vlanGatewayv6)) {
|
||||
throw new InvalidParameterValueException("Please specify a valid IPv6 gateway");
|
||||
}
|
||||
if (!NetUtils.isValidIp6Cidr(vlanCidrv6)) {
|
||||
|
|
|
|||
|
|
@ -810,12 +810,12 @@ public class NetworkServiceImpl implements NetworkService, Manager {
|
|||
}
|
||||
|
||||
if (ipv6) {
|
||||
if (!NetUtils.isValidIPv6(startIPv6)) {
|
||||
if (!NetUtils.isValidIpv6(startIPv6)) {
|
||||
throw new InvalidParameterValueException("Invalid format for the startIPv6 parameter");
|
||||
}
|
||||
if (endIPv6 == null) {
|
||||
endIPv6 = startIPv6;
|
||||
} else if (!NetUtils.isValidIPv6(endIPv6)) {
|
||||
} else if (!NetUtils.isValidIpv6(endIPv6)) {
|
||||
throw new InvalidParameterValueException("Invalid format for the endIPv6 parameter");
|
||||
}
|
||||
|
||||
|
|
@ -823,7 +823,7 @@ public class NetworkServiceImpl implements NetworkService, Manager {
|
|||
throw new InvalidParameterValueException("ip6Gateway and ip6Cidr should be defined when startIPv6/endIPv6 are passed in");
|
||||
}
|
||||
|
||||
if (!NetUtils.isValidIPv6(ip6Gateway)) {
|
||||
if (!NetUtils.isValidIpv6(ip6Gateway)) {
|
||||
throw new InvalidParameterValueException("Invalid ip6Gateway");
|
||||
}
|
||||
if (!NetUtils.isValidIp6Cidr(ip6Cidr)) {
|
||||
|
|
|
|||
|
|
@ -2368,6 +2368,8 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
|||
|
||||
if (requestedIpPair == null) {
|
||||
requestedIpPair = new IpAddresses(null, null);
|
||||
} else {
|
||||
checkRequestedIpAddresses(requestedIpPair.getIp4Address(), requestedIpPair.getIp6Address());
|
||||
}
|
||||
|
||||
NicProfile profile = new NicProfile(requestedIpPair.getIp4Address(), requestedIpPair.getIp6Address());
|
||||
|
|
@ -2375,7 +2377,8 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
|||
if (defaultNetworkNumber == 0) {
|
||||
defaultNetworkNumber++;
|
||||
// if user requested specific ip for default network, add it
|
||||
if (defaultIps.getIp4Address() != null || defaultIps.getIp4Address() != null) {
|
||||
if (defaultIps.getIp4Address() != null || defaultIps.getIp6Address() != null) {
|
||||
checkRequestedIpAddresses(defaultIps.getIp4Address(), defaultIps.getIp6Address());
|
||||
profile = new NicProfile(defaultIps.getIp4Address(), defaultIps.getIp6Address());
|
||||
}
|
||||
|
||||
|
|
@ -2513,7 +2516,20 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
|||
return vm;
|
||||
}
|
||||
|
||||
private void validateUserData(String userData) {
|
||||
private void checkRequestedIpAddresses(String ip4, String ip6) throws InvalidParameterValueException {
|
||||
if (ip4 != null) {
|
||||
if (!NetUtils.isValidIp(ip4)) {
|
||||
throw new InvalidParameterValueException("Invalid specified IPv4 address " + ip4);
|
||||
}
|
||||
}
|
||||
if (ip6 != null) {
|
||||
if (!NetUtils.isValidIpv6(ip6)) {
|
||||
throw new InvalidParameterValueException("Invalid specified IPv6 address " + ip6);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void validateUserData(String userData) {
|
||||
byte[] decodedUserData = null;
|
||||
if (userData != null) {
|
||||
if (!Base64.isBase64(userData)) {
|
||||
|
|
|
|||
|
|
@ -1146,7 +1146,7 @@ public class NetUtils {
|
|||
return true;
|
||||
}
|
||||
|
||||
public static boolean isValidIPv6(String ip) {
|
||||
public static boolean isValidIpv6(String ip) {
|
||||
try {
|
||||
IPv6Address address = IPv6Address.fromString(ip);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
|
|
|
|||
|
|
@ -75,10 +75,10 @@ public class NetUtilsTest extends TestCase {
|
|||
}
|
||||
|
||||
public void testIpv6() {
|
||||
assertTrue(NetUtils.isValidIPv6("fc00::1"));
|
||||
assertFalse(NetUtils.isValidIPv6(""));
|
||||
assertFalse(NetUtils.isValidIPv6(null));
|
||||
assertFalse(NetUtils.isValidIPv6("1234:5678::1/64"));
|
||||
assertTrue(NetUtils.isValidIpv6("fc00::1"));
|
||||
assertFalse(NetUtils.isValidIpv6(""));
|
||||
assertFalse(NetUtils.isValidIpv6(null));
|
||||
assertFalse(NetUtils.isValidIpv6("1234:5678::1/64"));
|
||||
assertTrue(NetUtils.isValidIp6Cidr("1234:5678::1/64"));
|
||||
assertFalse(NetUtils.isValidIp6Cidr("1234:5678::1"));
|
||||
assertEquals(NetUtils.getIp6CidrSize("1234:5678::1/32"), 32);
|
||||
|
|
|
|||
Loading…
Reference in New Issue