You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by al...@apache.org on 2012/08/02 04:57:47 UTC

git commit: VPC: CS-15813 - ICMP type and code validation

Updated Branches:
  refs/heads/vpc ce9f1afa7 -> 8f797afd4


VPC: CS-15813 - ICMP type and code validation

Conflicts:

	server/src/com/cloud/network/vpc/NetworkACLManagerImpl.java
	utils/src/com/cloud/utils/net/NetUtils.java


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

Branch: refs/heads/vpc
Commit: 8f797afd42be02909c22a6daf6cbc24ad3280877
Parents: ce9f1af
Author: Alena Prokharchyk <al...@citrix.com>
Authored: Wed Aug 1 19:39:52 2012 -0700
Committer: Alena Prokharchyk <al...@citrix.com>
Committed: Wed Aug 1 19:55:51 2012 -0700

----------------------------------------------------------------------
 .../cloud/network/vpc/NetworkACLManagerImpl.java   |   13 +++++++++
 utils/src/com/cloud/utils/net/NetUtils.java        |   20 +++++++++++++++
 2 files changed, 33 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8f797afd/server/src/com/cloud/network/vpc/NetworkACLManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/vpc/NetworkACLManagerImpl.java b/server/src/com/cloud/network/vpc/NetworkACLManagerImpl.java
index 951af21..1e09a14 100644
--- a/server/src/com/cloud/network/vpc/NetworkACLManagerImpl.java
+++ b/server/src/com/cloud/network/vpc/NetworkACLManagerImpl.java
@@ -152,6 +152,19 @@ public class NetworkACLManagerImpl implements Manager,NetworkACLManager{
         if (protocol.equalsIgnoreCase(NetUtils.ICMP_PROTO) && (portStart != null || portEnd != null)) {
             throw new InvalidParameterValueException("Can't specify start/end port when protocol is ICMP");
         } 
+        
+        //validate icmp code and type
+        if (icmpType != null) {
+            if (!NetUtils.validateIcmpType(icmpType)) {
+                throw new InvalidParameterValueException("Invalid icmp type; should belong to [0-255] range");
+            }
+            if (icmpCode != null) {
+                if (!NetUtils.validateIcmpCode(icmpCode)) {
+                    throw new InvalidParameterValueException("Invalid icmp code; should belong to [0-15] range and can" +
+                            " be defined when icmpType belongs to [0-40] range");
+                }
+            }
+        }
 
         validateNetworkACL(caller, network, portStart, portEnd, protocol);
 

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8f797afd/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 333e784..7e1d7cb 100755
--- a/utils/src/com/cloud/utils/net/NetUtils.java
+++ b/utils/src/com/cloud/utils/net/NetUtils.java
@@ -1107,4 +1107,24 @@ public class NetUtils {
         }
         return true;
     }
+    
+    public static boolean validateIcmpType(int icmpType) {
+        //Source - http://www.erg.abdn.ac.uk/~gorry/course/inet-pages/icmp-code.html
+        if(!(icmpType >=0 && icmpType <=255)) {
+            s_logger.warn("impcType is not within 0-255 range");
+            return false;
+        }
+        return true;
+    }
+    
+    public static boolean validateIcmpCode(int icmpCode) {
+        
+        //Source - http://www.erg.abdn.ac.uk/~gorry/course/inet-pages/icmp-code.html
+        if(!(icmpCode >=0 && icmpCode <=15)) {
+            s_logger.warn("Icmp code should be within 0-15 range");
+            return false;
+        }
+        
+        return true;
+    }
 }