incubator-cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From edi...@apache.org
Subject [30/50] [abbrv] git commit: refs/heads/storage_refactor - IPv6: Fix ip address in range check
Date Wed, 06 Feb 2013 02:43:29 GMT
IPv6: Fix ip address in range check


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

Branch: refs/heads/storage_refactor
Commit: 2e236a832235e6642fd58f27a2991efceb3047da
Parents: e5866cf
Author: Sheng Yang <sheng.yang@citrix.com>
Authored: Tue Feb 5 13:04:38 2013 -0800
Committer: Sheng Yang <sheng.yang@citrix.com>
Committed: Tue Feb 5 14:31:06 2013 -0800

----------------------------------------------------------------------
 .../src/com/cloud/network/NetworkServiceImpl.java  |   12 ++++++------
 utils/src/com/cloud/utils/net/NetUtils.java        |   11 +++++++++++
 utils/test/com/cloud/utils/net/NetUtilsTest.java   |    9 +++++++++
 3 files changed, 26 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/2e236a83/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 235762e..d38d1f8 100755
--- a/server/src/com/cloud/network/NetworkServiceImpl.java
+++ b/server/src/com/cloud/network/NetworkServiceImpl.java
@@ -780,14 +780,14 @@ public class NetworkServiceImpl extends ManagerBase implements  NetworkService
{
         	if (!NetUtils.isValidIp6Cidr(ip6Cidr)) {
         		throw new InvalidParameterValueException("Invalid ip6cidr");
         	}
-        	if (!NetUtils.isIp6InRange(startIPv6, ip6Cidr)) {
-        		throw new InvalidParameterValueException("startIPv6 is not in ip6cidr indicated
network range!");
+        	if (!NetUtils.isIp6InNetwork(startIPv6, ip6Cidr)) {
+        		throw new InvalidParameterValueException("startIPv6 is not in ip6cidr indicated
network!");
         	}
-        	if (!NetUtils.isIp6InRange(endIPv6, ip6Cidr)) {
-        		throw new InvalidParameterValueException("endIPv6 is not in ip6cidr indicated network
range!");
+        	if (!NetUtils.isIp6InNetwork(endIPv6, ip6Cidr)) {
+        		throw new InvalidParameterValueException("endIPv6 is not in ip6cidr indicated network!");
         	}
-        	if (!NetUtils.isIp6InRange(ip6Gateway, ip6Cidr)) {
-        		throw new InvalidParameterValueException("ip6Gateway is not in ip6cidr indicated
network range!");
+        	if (!NetUtils.isIp6InNetwork(ip6Gateway, ip6Cidr)) {
+        		throw new InvalidParameterValueException("ip6Gateway is not in ip6cidr indicated
network!");
         	}
         	
         	int cidrSize = NetUtils.getIp6CidrSize(ip6Cidr);

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/2e236a83/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 deb1d05..8d3ff6d 100755
--- a/utils/src/com/cloud/utils/net/NetUtils.java
+++ b/utils/src/com/cloud/utils/net/NetUtils.java
@@ -1211,6 +1211,17 @@ public class NetUtils {
 		return false;
 	}
 	
+	public static boolean isIp6InNetwork(String ip6, String ip6Cidr) {
+		IPv6Network network = null;
+		try {
+			network = IPv6Network.fromString(ip6Cidr);
+		} catch (IllegalArgumentException ex) {
+			return false;
+		}
+    	IPv6Address ip = IPv6Address.fromString(ip6);
+		return network.contains(ip);
+	}
+	
 	public static boolean isIp6RangeOverlap(String ipRange1, String ipRange2) {
 		String[] ips = ipRange1.split("-");
     	String startIp1 = ips[0];

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/2e236a83/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 08b4816..763a798 100644
--- a/utils/test/com/cloud/utils/net/NetUtilsTest.java
+++ b/utils/test/com/cloud/utils/net/NetUtilsTest.java
@@ -102,5 +102,14 @@ public class NetUtilsTest extends TestCase {
     	assertTrue(NetUtils.isIp6RangeOverlap("1234:5678::f-1234:5678::ffff", "1234:5678::2-1234:5678::f"));
     	assertFalse(NetUtils.isIp6RangeOverlap("1234:5678::f-1234:5678::ffff", "1234:5678::2-1234:5678::e"));
     	assertFalse(NetUtils.isIp6RangeOverlap("1234:5678::f-1234:5678::f", "1234:5678::2-1234:5678::e"));
+    	//Test getNextIp6InRange
+    	assertEquals(NetUtils.getNextIp6InRange("1234:5678::8000:0000", range), "1234:5678::1");
+    	assertEquals(NetUtils.getNextIp6InRange("1234:5678::7fff:ffff", range), "1234:5678::8000:0");
+    	assertEquals(NetUtils.getNextIp6InRange("1234:5678::1", range), "1234:5678::2");
+    	//Test isIp6InNetwork
+    	assertFalse(NetUtils.isIp6InNetwork("1234:5678:abcd::1", "1234:5678::/64"));
+    	assertTrue(NetUtils.isIp6InNetwork("1234:5678::1", "1234:5678::/64"));
+    	assertTrue(NetUtils.isIp6InNetwork("1234:5678::ffff:ffff:ffff:ffff", "1234:5678::/64"));
+    	assertTrue(NetUtils.isIp6InNetwork("1234:5678::", "1234:5678::/64"));
     }
 }


Mime
View raw message