cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yas...@apache.org
Subject [1/2] git commit: refs/heads/4.1 - IPv6: Fix ip address in range check
Date Tue, 05 Feb 2013 22:30:49 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/22383d78
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/22383d78
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/22383d78

Branch: refs/heads/4.1
Commit: 22383d78370fed356921f760a4315b45245d43bd
Parents: 6a19da7
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 13:21:41 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/22383d78/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/22383d78/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/22383d78/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