incubator-cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yas...@apache.org
Subject [14/28] git commit: refs/heads/master - IPv6: Verify if requested IPv4/IPv6 addresses are valid
Date Thu, 31 Jan 2013 23:08:02 GMT
IPv6: Verify if requested IPv4/IPv6 addresses are valid

Also rename NetUtils.isValidIPv6() to NetUtils.isValidIpv6()


Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/0b62fc4c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/0b62fc4c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/0b62fc4c

Branch: refs/heads/master
Commit: 0b62fc4c1743bb3f1d61d854d3bca368d146865c
Parents: cb9f2d0
Author: Sheng Yang <sheng.yang@citrix.com>
Authored: Tue Jan 29 18:42:04 2013 -0800
Committer: Sheng Yang <sheng.yang@citrix.com>
Committed: Tue Jan 29 19:08:09 2013 -0800

----------------------------------------------------------------------
 .../configuration/ConfigurationManagerImpl.java    |    2 +-
 .../src/com/cloud/network/NetworkServiceImpl.java  |    6 ++--
 server/src/com/cloud/vm/UserVmManagerImpl.java     |   20 +++++++++++++-
 utils/src/com/cloud/utils/net/NetUtils.java        |    2 +-
 utils/test/com/cloud/utils/net/NetUtilsTest.java   |    8 +++---
 5 files changed, 27 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/0b62fc4c/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
index 7154dc8..aee3234 100755
--- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
+++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
@@ -2372,7 +2372,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)) {

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/0b62fc4c/server/src/com/cloud/network/NetworkServiceImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/NetworkServiceImpl.java b/server/src/com/cloud/network/NetworkServiceImpl.java
index df44ce0..98d9342 100755
--- a/server/src/com/cloud/network/NetworkServiceImpl.java
+++ b/server/src/com/cloud/network/NetworkServiceImpl.java
@@ -783,12 +783,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");
         	}
         	
@@ -796,7 +796,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)) {

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/0b62fc4c/server/src/com/cloud/vm/UserVmManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java
index 491f8a2..1bc7edb 100644
--- a/server/src/com/cloud/vm/UserVmManagerImpl.java
+++ b/server/src/com/cloud/vm/UserVmManagerImpl.java
@@ -2376,6 +2376,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());
@@ -2383,7 +2385,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());
                 }
 
@@ -2521,7 +2524,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)) {

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/0b62fc4c/utils/src/com/cloud/utils/net/NetUtils.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/net/NetUtils.java b/utils/src/com/cloud/utils/net/NetUtils.java
index e3bf707..d121ff0 100755
--- a/utils/src/com/cloud/utils/net/NetUtils.java
+++ b/utils/src/com/cloud/utils/net/NetUtils.java
@@ -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) {

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/0b62fc4c/utils/test/com/cloud/utils/net/NetUtilsTest.java
----------------------------------------------------------------------
diff --git a/utils/test/com/cloud/utils/net/NetUtilsTest.java b/utils/test/com/cloud/utils/net/NetUtilsTest.java
index 9beb6ca..c256d6d 100644
--- a/utils/test/com/cloud/utils/net/NetUtilsTest.java
+++ b/utils/test/com/cloud/utils/net/NetUtilsTest.java
@@ -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);


Mime
View raw message