cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alena1...@apache.org
Subject git commit: updated refs/heads/4.2 to 418f8cb
Date Wed, 08 Jan 2014 17:32:43 GMT
Updated Branches:
  refs/heads/4.2 5e615f74b -> 418f8cb60


CLOUDSTACK-5826: do netmask/gateway validation before calculating the POD cidr

Conflicts:
	server/src/com/cloud/configuration/ConfigurationManagerImpl.java
	utils/src/com/cloud/utils/net/NetUtils.java


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

Branch: refs/heads/4.2
Commit: 418f8cb60e48da0d716edaf67c6e750b016672f0
Parents: 5e615f7
Author: Alena Prokharchyk <alena.prokharchyk@citrix.com>
Authored: Tue Jan 7 15:01:04 2014 -0800
Committer: Alena Prokharchyk <alena.prokharchyk@citrix.com>
Committed: Wed Jan 8 09:32:56 2014 -0800

----------------------------------------------------------------------
 .../configuration/ConfigurationManagerImpl.java | 10 +++++++
 utils/src/com/cloud/utils/net/NetUtils.java     | 28 +++++++++++++++-----
 2 files changed, 31 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/418f8cb6/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 1d55886..27b93ff 100755
--- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
+++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
@@ -1207,6 +1207,16 @@ public class ConfigurationManagerImpl extends ManagerBase implements
Configurati
     @Override
     public Pod createPod(long zoneId, String name, String startIp, String endIp, String gateway,
String netmask,
             String allocationState) {
+
+        // Check if the gateway is a valid IP address
+        if (!NetUtils.isValidIp(gateway)) {
+            throw new InvalidParameterValueException("The gateway is invalid");
+        }
+
+        if (!NetUtils.isValidNetmask(netmask)) {
+            throw new InvalidParameterValueException("The netmask is invalid");
+        }
+
         String cidr = NetUtils.ipAndNetMaskToCidr(gateway, netmask);
         Long userId = UserContext.current().getCallerUserId();
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/418f8cb6/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 14a6c70..35e7bc5 100755
--- a/utils/src/com/cloud/utils/net/NetUtils.java
+++ b/utils/src/com/cloud/utils/net/NetUtils.java
@@ -26,21 +26,27 @@ import java.net.NetworkInterface;
 import java.net.SocketException;
 import java.net.URI;
 import java.net.UnknownHostException;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Formatter;
+import java.util.List;
+import java.util.Random;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.StringTokenizer;
+import java.util.TreeSet;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import org.apache.commons.lang.SystemUtils;
+import org.apache.commons.net.util.SubnetUtils;
 import org.apache.log4j.Logger;
 
-import com.googlecode.ipv6.IPv6Address;
-import com.googlecode.ipv6.IPv6AddressRange;
-import com.googlecode.ipv6.IPv6Network;
-
 import com.cloud.utils.IteratorUtil;
 import com.cloud.utils.Pair;
-import org.apache.commons.net.util.SubnetUtils;
 import com.cloud.utils.script.Script;
-import org.apache.commons.lang.SystemUtils;
+import com.googlecode.ipv6.IPv6Address;
+import com.googlecode.ipv6.IPv6AddressRange;
+import com.googlecode.ipv6.IPv6Network;
 
 public class NetUtils {
     protected final static Logger s_logger = Logger.getLogger(NetUtils.class);
@@ -763,6 +769,14 @@ public class NetUtils {
     }
 
     public static String ipAndNetMaskToCidr(String ip, String netmask) {
+
+        if (!isValidIp(ip)) {
+            return null;
+        }
+
+        if (!isValidNetmask(netmask)) {
+            return null;
+        }
         long ipAddr = ip2Long(ip);
         long subnet = ip2Long(netmask);
         long result = ipAddr & subnet;


Mime
View raw message