S2S VPN: CS-15947: Add global config for S2S VPN VPN connection counts limitation

And subnets limitation for each customer gateway
This commit is contained in:
Sheng Yang 2012-08-10 16:11:58 -07:00
parent 029a07fad4
commit 8f8d92ad08
2 changed files with 23 additions and 2 deletions

View File

@ -22,6 +22,7 @@ import com.cloud.ha.HighAvailabilityManager;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.network.NetworkManager;
import com.cloud.network.router.VpcVirtualNetworkApplianceManager;
import com.cloud.network.vpn.Site2SiteVpnManager;
import com.cloud.server.ManagementServer;
import com.cloud.storage.StorageManager;
import com.cloud.storage.allocator.StoragePoolAllocator;
@ -105,6 +106,8 @@ public enum Config {
RemoteAccessVpnPskLength("Network", AgentManager.class, Integer.class, "remote.access.vpn.psk.length", "24", "The length of the ipsec preshared key (minimum 8, maximum 256)", null),
RemoteAccessVpnClientIpRange("Network", AgentManager.class, String.class, "remote.access.vpn.client.iprange", "10.1.2.1-10.1.2.8", "The range of ips to be allocated to remote access vpn clients. The first ip in the range is used by the VPN server", null),
RemoteAccessVpnUserLimit("Network", AgentManager.class, String.class, "remote.access.vpn.user.limit", "8", "The maximum number of VPN users that can be created per account", null),
Site2SiteVpnConnectionPerVpnGatewayLimit("Network", ManagementServer.class, Integer.class, "site2site.vpn.vpngateway.connection.limit", "4", "The maximum number of VPN connection per VPN gateway", null),
Site2SiteVpnSubnetsPerCustomerGatewayLimit("Network", ManagementServer.class, Integer.class, "site2site.vpn.customergateway.subnets.limit", "10", "The maximum number of subnets per customer gateway", null),
// Console Proxy
ConsoleProxyCapacityStandby("Console Proxy", AgentManager.class, String.class, "consoleproxy.capacity.standby", "10", "The minimal number of console proxy viewer sessions that system is able to serve immediately(standby capacity)", null),

View File

@ -20,6 +20,8 @@ import com.cloud.api.commands.ListVpnCustomerGatewaysCmd;
import com.cloud.api.commands.ListVpnGatewaysCmd;
import com.cloud.api.commands.ResetVpnConnectionCmd;
import com.cloud.api.commands.UpdateVpnCustomerGatewayCmd;
import com.cloud.configuration.Config;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.event.ActionEvent;
import com.cloud.event.EventTypes;
import com.cloud.exception.InvalidParameterValueException;
@ -50,7 +52,9 @@ import com.cloud.user.UserStatisticsVO;
import com.cloud.user.dao.AccountDao;
import com.cloud.user.dao.UserStatisticsDao;
import com.cloud.utils.IdentityProxy;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.Ternary;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.component.Inject;
import com.cloud.utils.component.Manager;
import com.cloud.utils.db.DB;
@ -77,10 +81,18 @@ public class Site2SiteVpnManagerImpl implements Site2SiteVpnManager, Manager {
@Inject AccountManager _accountMgr;
@Inject UserStatisticsDao _statsDao = null;
String _name;
int _connLimit;
int _subnetsLimit;
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
_name = name;
ComponentLocator locator = ComponentLocator.getCurrentLocator();
ConfigurationDao configDao = locator.getDao(ConfigurationDao.class);
Map<String, String> configs = configDao.getConfiguration(params);
_connLimit = NumbersUtil.parseInt(configs.get(Config.Site2SiteVpnConnectionPerVpnGatewayLimit.key()), 4);
_subnetsLimit = NumbersUtil.parseInt(configs.get(Config.Site2SiteVpnSubnetsPerCustomerGatewayLimit.key()), 10);
return true;
}
@ -138,8 +150,11 @@ public class Site2SiteVpnManagerImpl implements Site2SiteVpnManager, Manager {
}
protected void checkCustomerGatewayCidrList(String guestCidrList) {
// Remote sub nets cannot overlap themselves
String[] cidrList = guestCidrList.split(",");
if (cidrList.length > _subnetsLimit) {
throw new InvalidParameterValueException("Too many subnets of customer gateway! The limit is " + _subnetsLimit, null);
}
// Remote sub nets cannot overlap themselves
for (int i = 0; i < cidrList.length - 1; i ++) {
for (int j = i + 1; j < cidrList.length; j ++) {
if (NetUtils.isNetworksOverlap(cidrList[i], cidrList[j])) {
@ -274,6 +289,9 @@ public class Site2SiteVpnManagerImpl implements Site2SiteVpnManager, Manager {
// We also need to check if the new connection's remote CIDR is overlapped with existed connections
List<Site2SiteVpnConnectionVO> conns = _vpnConnectionDao.listByVpnGatewayId(vpnGatewayId);
if (conns.size() >= _connLimit) {
throw new InvalidParameterValueException("There are too many VPN connections with current VPN gateway! The limit is " + _connLimit, null);
}
for (Site2SiteVpnConnectionVO vc : conns) {
if (vc == null) {
continue;