bug 6159: now we can add at most 2 records per public port (one for tcp, one for udp) eg: 1:2:tcp and 1:3:udp; any other combination for this port will result in an error being propagated back to the UI

status 6159: resolved fixed
This commit is contained in:
abhishek 2010-09-13 10:19:02 -07:00
parent 77734721e6
commit 8ad314f471
1 changed files with 47 additions and 41 deletions

View File

@ -3403,47 +3403,53 @@ public class ManagementServerImpl implements ManagementServer {
if (userVm != null)
{
String privateIpPort = mappedPublicPorts.get(publicPort).toString();//eg: 10.1.1.2,30 ; 10.1.1.2,34
if (privateIpPort != null && privateIpPort.length()>0)
{
String publicPortProtocol = publicPortToProtocolMapping.get(publicPort).toString();
String[] privateIpPortPairs = privateIpPort.toString().split(";"); //eg. 10.1.1.2,30
String[] privateIpAndPortStr;
boolean errFlag = false;
for(String pair: privateIpPortPairs)
{
privateIpAndPortStr = pair.split(",");//split into 10.1.1.2 & 30
if (privateIpAndPortStr[0].equals(userVm.getGuestIpAddress()) && privateIpAndPortStr[1].equals(privatePort)) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("skipping the creating of firewall rule " + ipAddress + ":" + publicPort + " to " + userVm.getGuestIpAddress() + ":" + privatePort + "; rule already exists.");
}
return null; // already mapped
}
//at this point protocol string looks like: eg. tcp;udp || tcp || udp || udp;tcp
else if(!publicPortProtocol.contains(protocol))//check if this public port is mapped to the protocol or not
{
//this is the case eg:
//pub:1 pri:2 pro: tcp
//pub 1 pri:3 pro: udp
break; //we break here out of the loop, for the record to be created
}
else
{
errFlag = true;
// throw new NetworkRuleConflictException("An existing port forwarding service rule for " + ipAddress + ":" + publicPort
// + " already exists, found while trying to create mapping to " + userVm.getGuestIpAddress() + ":" + privatePort + ((securityGroupId == null) ? "." : " from port forwarding service "
// + securityGroupId.toString() + "."));
}
}
if(errFlag)
throw new NetworkRuleConflictException("An existing port forwarding service rule for " + ipAddress + ":" + publicPort
+ " already exists, found while trying to create mapping to " + userVm.getGuestIpAddress() + ":" + privatePort + ((securityGroupId == null) ? "." : " from port forwarding service "
+ securityGroupId.toString() + "."));
}
if(mappedPublicPorts.size()>0)
{
StringBuilder privateIpPortIntermediate = mappedPublicPorts.get(publicPort);
String privateIpPort = null;
if(privateIpPortIntermediate != null && privateIpPortIntermediate.length()>0)
privateIpPort = privateIpPortIntermediate.toString();//eg: 10.1.1.2,30 ; 10.1.1.2,34
if (privateIpPort != null && privateIpPort.length()>0)
{
String publicPortProtocol = publicPortToProtocolMapping.get(publicPort).toString();
String[] privateIpPortPairs = privateIpPort.toString().split(";"); //eg. 10.1.1.2,30
String[] privateIpAndPortStr;
boolean errFlag = false;
for(String pair: privateIpPortPairs)
{
privateIpAndPortStr = pair.split(",");//split into 10.1.1.2 & 30
if (privateIpAndPortStr[0].equals(userVm.getGuestIpAddress()) && privateIpAndPortStr[1].equals(privatePort)) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("skipping the creating of firewall rule " + ipAddress + ":" + publicPort + " to " + userVm.getGuestIpAddress() + ":" + privatePort + "; rule already exists.");
}
return null; // already mapped
}
//at this point protocol string looks like: eg. tcp;udp || tcp || udp || udp;tcp
else if(!publicPortProtocol.contains(protocol))//check if this public port is mapped to the protocol or not
{
//this is the case eg:
//pub:1 pri:2 pro: tcp
//pub 1 pri:3 pro: udp
break; //we break here out of the loop, for the record to be created
}
else
{
errFlag = true;
// throw new NetworkRuleConflictException("An existing port forwarding service rule for " + ipAddress + ":" + publicPort
// + " already exists, found while trying to create mapping to " + userVm.getGuestIpAddress() + ":" + privatePort + ((securityGroupId == null) ? "." : " from port forwarding service "
// + securityGroupId.toString() + "."));
}
}
if(errFlag)
throw new NetworkRuleConflictException("An existing port forwarding service rule for " + ipAddress + ":" + publicPort
+ " already exists, found while trying to create mapping to " + userVm.getGuestIpAddress() + ":" + privatePort + ((securityGroupId == null) ? "." : " from port forwarding service "
+ securityGroupId.toString() + "."));
}
}
FirewallRuleVO newFwRule = new FirewallRuleVO();
newFwRule.setEnabled(true);
newFwRule.setForwarding(true);