cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject [1/2] git commit: updated refs/heads/master to 66d7f41
Date Sat, 12 Dec 2015 08:37:25 GMT
Repository: cloudstack
Updated Branches:
  refs/heads/master 879b6da4e -> 66d7f413e


CLOUDSTACK-9086: ACS allows to create isolated networks with invalide gateway IP address -
Fixed and Test cases added


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

Branch: refs/heads/master
Commit: c7c389d61c55c26d7be3c684269613c6fef9cdd5
Parents: e08294a
Author: Kshitij Kansal <kansal.k@gmail.com>
Authored: Tue Dec 8 13:01:39 2015 +0530
Committer: Kshitij Kansal <kansal.k@gmail.com>
Committed: Tue Dec 8 15:27:51 2015 +0530

----------------------------------------------------------------------
 .../src/com/cloud/network/NetworkServiceImpl.java |  7 +++++++
 .../main/java/com/cloud/utils/net/NetUtils.java   |  8 ++++++++
 .../java/com/cloud/utils/net/NetUtilsTest.java    | 18 ++++++++++++++++++
 3 files changed, 33 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c7c389d6/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 3494999..b6dac87 100644
--- a/server/src/com/cloud/network/NetworkServiceImpl.java
+++ b/server/src/com/cloud/network/NetworkServiceImpl.java
@@ -1197,6 +1197,13 @@ public class NetworkServiceImpl extends ManagerBase implements  NetworkService
{
             }
 
             if (gateway != null && netmask != null) {
+                if(NetUtils.isNetworkorBroadcastIP(gateway,netmask)) {
+                    if (s_logger.isDebugEnabled()) {
+                        s_logger.debug("The gateway IP provided is " + gateway + " and netmask
is " + netmask + ". The IP is either broadcast or network IP.");
+                    }
+                    throw new InvalidParameterValueException("Invalid gateway IP provided.
Either the IP is broadcast or network IP.");
+                }
+
                 if (!NetUtils.isValidIp(gateway)) {
                     throw new InvalidParameterValueException("Invalid gateway");
                 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c7c389d6/utils/src/main/java/com/cloud/utils/net/NetUtils.java
----------------------------------------------------------------------
diff --git a/utils/src/main/java/com/cloud/utils/net/NetUtils.java b/utils/src/main/java/com/cloud/utils/net/NetUtils.java
index 90a43fa..a73813c 100644
--- a/utils/src/main/java/com/cloud/utils/net/NetUtils.java
+++ b/utils/src/main/java/com/cloud/utils/net/NetUtils.java
@@ -1570,5 +1570,13 @@ public class NetUtils {
         }
         return false;
     }
+    public static boolean isNetworkorBroadcastIP(String ip, String netmask){
+        String cidr = getCidrFromGatewayAndNetmask(ip,netmask);
+        final SubnetUtils subnetUtils = new SubnetUtils(cidr);
+        subnetUtils.setInclusiveHostCount(false);
+        final boolean isInRange = subnetUtils.getInfo().isInRange(ip);
+        return !isInRange;
+    }
+
 
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c7c389d6/utils/src/test/java/com/cloud/utils/net/NetUtilsTest.java
----------------------------------------------------------------------
diff --git a/utils/src/test/java/com/cloud/utils/net/NetUtilsTest.java b/utils/src/test/java/com/cloud/utils/net/NetUtilsTest.java
index bf686c2..490d0df 100644
--- a/utils/src/test/java/com/cloud/utils/net/NetUtilsTest.java
+++ b/utils/src/test/java/com/cloud/utils/net/NetUtilsTest.java
@@ -508,4 +508,22 @@ public class NetUtilsTest {
     public void testIsNetworksOverlapWithEmptyValues() {
         assertEquals(false, NetUtils.isNetworksOverlap("", null));
     }
+    @Test
+    public void testisNetworkorBroadCastIP(){
+         //Checking the True conditions
+        assertTrue(NetUtils.isNetworkorBroadcastIP("192.168.0.0","255.255.255.0"));
+        assertTrue(NetUtils.isNetworkorBroadcastIP("192.168.0.255","255.255.255.0"));
+        assertTrue(NetUtils.isNetworkorBroadcastIP("192.168.0.127","255.255.255.128"));
+        assertTrue(NetUtils.isNetworkorBroadcastIP("192.168.0.63","255.255.255.192"));
+
+        //Checking the False conditions
+        assertFalse(NetUtils.isNetworkorBroadcastIP("192.168.0.1","255.255.255.0"));
+        assertFalse(NetUtils.isNetworkorBroadcastIP("192.168.0.127","255.255.255.0"));
+        assertFalse(NetUtils.isNetworkorBroadcastIP("192.168.0.126","255.255.255.128"));
+        assertFalse(NetUtils.isNetworkorBroadcastIP("192.168.0.62","255.255.255.192"));
+
+        assertTrue(NetUtils.isNetworkorBroadcastIP("192.168.0.63","255.255.255.192"));
+        assertFalse(NetUtils.isNetworkorBroadcastIP("192.168.0.63","255.255.255.128"));
+    }
+
 }


Mime
View raw message