IPv6 support v1.0

Server:
Added IPv6 support for all DNS Providers, but only tested ISC BIND & MS DNS

Enterprise Server:
Added support for IPv6. Hyper-V not tested, and probably doesn't work.
When using IPv6 with Hyper-V it assigns "/CIDR" to the subnet mask, and I don't
know if this is the correct implementation.

Portal:
Modified all IP input masks to accept and validate IPv6.
IP Ranges support IP/CIDR format.
This commit is contained in:
Administrator 2012-08-18 04:53:29 +02:00
parent 90219f284f
commit c4a1b5f4d6
44 changed files with 3221 additions and 247 deletions

View file

@ -3019,14 +3019,16 @@ namespace WebsitePanel.EnterpriseServer
{
// custom format
nic.NetworkFormat = settings["PrivateIPAddress"];
nic.SubnetMask = GetPrivateNetworkSubnetMask(settings["PrivateSubnetMask"]);
var v6 = IPAddress.Parse(nic.NetworkFormat).V6;
nic.SubnetMask = GetPrivateNetworkSubnetMask(settings["PrivateSubnetMask"], v6);
}
else
{
// standard format
string[] formatPair = settings["PrivateNetworkFormat"].Split('/');
nic.NetworkFormat = formatPair[0];
nic.SubnetMask = GetPrivateNetworkSubnetMask(formatPair[1]);
var v6 = IPAddress.Parse(nic.NetworkFormat).V6;
nic.SubnetMask = GetPrivateNetworkSubnetMask(formatPair[1], v6);
}
nic.SubnetMaskCidr = GetSubnetMaskCidr(nic.SubnetMask);
@ -3088,7 +3090,7 @@ namespace WebsitePanel.EnterpriseServer
List<PrivateIPAddress> ips = GetPackagePrivateIPAddresses(vm.PackageId);
// sort them
SortedList<long, string> sortedIps = GetSortedNormalizedIPAddresses(ips, nic.SubnetMask);
SortedList<IPAddress, string> sortedIps = GetSortedNormalizedIPAddresses(ips, nic.SubnetMask);
if (selectRandom)
{
@ -3259,14 +3261,14 @@ namespace WebsitePanel.EnterpriseServer
return res;
}
private static string GenerateNextAvailablePrivateIP(SortedList<long, string> ips, string subnetMask, string startIPAddress)
private static string GenerateNextAvailablePrivateIP(SortedList<IPAddress, string> ips, string subnetMask, string startIPAddress)
{
// start IP address
long startIp = ServerController.ConvertIPToLong(startIPAddress);
long mask = ServerController.ConvertIPToLong(subnetMask);
var startIp = IPAddress.Parse(startIPAddress);
var mask = IPAddress.Parse(subnetMask);
long lastAddress = (startIp & ~mask) - 1;
foreach (long addr in ips.Keys)
var lastAddress = (startIp & ~mask) - 1;
foreach (var addr in ips.Keys)
{
if ((addr - lastAddress) > 1)
{
@ -3279,11 +3281,11 @@ namespace WebsitePanel.EnterpriseServer
}
}
long genAddr = lastAddress + 1;
var genAddr = lastAddress + 1;
// convert to IP address
long ip = startIp & mask | (uint)genAddr;
string genIP = ServerController.ConvertLongToIP(ip);
var ip = startIp & mask | genAddr;
string genIP = ip.ToString();
// store in cache
ips.Add(genAddr, genIP);
@ -3291,46 +3293,45 @@ namespace WebsitePanel.EnterpriseServer
return genIP;
}
private static SortedList<long, string> GetSortedNormalizedIPAddresses(List<PrivateIPAddress> ips, string subnetMask)
private static SortedList<IPAddress, string> GetSortedNormalizedIPAddresses(List<PrivateIPAddress> ips, string subnetMask)
{
long mask = ServerController.ConvertIPToLong(subnetMask);
SortedList<long, string> sortedIps = new SortedList<long, string>();
var mask = IPAddress.Parse(subnetMask);
SortedList<IPAddress, string> sortedIps = new SortedList<IPAddress, string>();
foreach (PrivateIPAddress ip in ips)
{
long addr = ~mask & ServerController.ConvertIPToLong(ip.IPAddress);
var addr = ~mask & IPAddress.Parse(ip.IPAddress);
sortedIps.Add(addr, ip.IPAddress);
}
return sortedIps;
}
private static string GetPrivateNetworkSubnetMask(string cidr)
private static string GetPrivateNetworkSubnetMask(string cidr, bool v6)
{
int digits = 32 - Utils.ParseInt(cidr, 0);
long mask = 0xFFFFFFFF;
mask = mask << digits;
return ServerController.ConvertLongToIP(mask);
if (v6) return "/" + cidr;
else return IPAddress.Parse("/" + cidr).ToV4MaskString();
}
private static string GetSubnetMaskCidr(string subnetMask)
{
if (String.IsNullOrEmpty(subnetMask))
return subnetMask;
int cidr = 32;
long mask = ServerController.ConvertIPToLong(subnetMask);
while ((mask & 1) == 0 && cidr > 0)
{
mask >>= 1;
cidr -= 1;
}
return cidr.ToString();
}
private static string GetSubnetMaskCidr(string subnetMask) {
if (String.IsNullOrEmpty(subnetMask))
return subnetMask;
var ip = IPAddress.Parse(subnetMask);
if (ip.V4) {
int cidr = 32;
long mask = (long)ip.Address;
while ((mask & 1) == 0 && cidr > 0) {
mask >>= 1;
cidr -= 1;
}
return cidr.ToString();
} else {
return ip.Cidr.ToString();
}
}
private static bool CheckPrivateIPAddress(string subnetMask, string ipAddress)
{
long mask = ServerController.ConvertIPToLong(subnetMask);
long ip = ServerController.ConvertIPToLong(ipAddress);
var mask = IPAddress.Parse(subnetMask);
var ip = IPAddress.Parse(ipAddress);
return ((mask & ip) == mask);
}