merge commit
This commit is contained in:
commit
5caabc42e9
3 changed files with 98 additions and 19 deletions
|
@ -5,7 +5,7 @@ using System.Web;
|
||||||
|
|
||||||
namespace WebsitePanel.EnterpriseServer {
|
namespace WebsitePanel.EnterpriseServer {
|
||||||
|
|
||||||
public struct IPAddress {
|
public struct IPAddress : IComparable {
|
||||||
public Int128 Address;
|
public Int128 Address;
|
||||||
public bool V6 { get; private set; }
|
public bool V6 { get; private set; }
|
||||||
public bool V4 { get { return !V6 || Null; } }
|
public bool V4 { get { return !V6 || Null; } }
|
||||||
|
@ -68,10 +68,19 @@ namespace WebsitePanel.EnterpriseServer {
|
||||||
if (Null)
|
if (Null)
|
||||||
return "";
|
return "";
|
||||||
var s = new System.Text.StringBuilder();
|
var s = new System.Text.StringBuilder();
|
||||||
if (!V6) {
|
if (!V6)
|
||||||
var ipl = Address;
|
{
|
||||||
s.Append(String.Format("{0}.{1}.{2}.{3}", (ipl >> 24) & 0xFFL, (ipl >> 16) & 0xFFL, (ipl >> 8) & 0xFFL, (ipl & 0xFFL)));
|
var ipl = Address;
|
||||||
} else if (!IsMask) {
|
if (IsMask)
|
||||||
|
{
|
||||||
|
int digits = 32 - Cidr;
|
||||||
|
ipl = (Int128.MaxValue << 1) | 0x1; // remove left sign bit
|
||||||
|
ipl = ipl << digits;
|
||||||
|
}
|
||||||
|
s.Append(String.Format("{0}.{1}.{2}.{3}", (ipl >> 24) & 0xFFL, (ipl >> 16) & 0xFFL, (ipl >> 8) & 0xFFL, (ipl & 0xFFL)));
|
||||||
|
}
|
||||||
|
else if (!IsMask)
|
||||||
|
{
|
||||||
|
|
||||||
var vals = new List<int>();
|
var vals = new List<int>();
|
||||||
int i;
|
int i;
|
||||||
|
@ -127,6 +136,30 @@ namespace WebsitePanel.EnterpriseServer {
|
||||||
public static bool operator >(IPAddress a, IPAddress b) { return a.Address > b.Address; }
|
public static bool operator >(IPAddress a, IPAddress b) { return a.Address > b.Address; }
|
||||||
public static bool operator <=(IPAddress a, IPAddress b) { return a.Address <= b.Address; }
|
public static bool operator <=(IPAddress a, IPAddress b) { return a.Address <= b.Address; }
|
||||||
public static bool operator >=(IPAddress a, IPAddress b) { return a.Address >= b.Address; }
|
public static bool operator >=(IPAddress a, IPAddress b) { return a.Address >= b.Address; }
|
||||||
|
|
||||||
|
public override bool Equals(object obj)
|
||||||
|
{
|
||||||
|
if (obj is IPAddress)
|
||||||
|
{
|
||||||
|
var b = (IPAddress)obj;
|
||||||
|
return this.Address == b.Address && this.Null == b.Null && (this.Null || !(this.IsSubnet && b.IsSubnet || this.IsMask && b.IsMask) || this.Cidr == b.Cidr);
|
||||||
|
}
|
||||||
|
else if (obj is long)
|
||||||
|
{
|
||||||
|
var b = (long)obj;
|
||||||
|
return this.Address == b;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
return this.Address.GetHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
public static IPAddress operator +(IPAddress a, IPAddress b) {
|
public static IPAddress operator +(IPAddress a, IPAddress b) {
|
||||||
if (a.IsSubnet || b.IsSubnet || a.V6 != b.V6) throw new ArgumentException("Arithmetic with subnets or mixed v4 & v6 addresses not supported.");
|
if (a.IsSubnet || b.IsSubnet || a.V6 != b.V6) throw new ArgumentException("Arithmetic with subnets or mixed v4 & v6 addresses not supported.");
|
||||||
|
@ -157,7 +190,20 @@ namespace WebsitePanel.EnterpriseServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static implicit operator IPAddress(NullIPAddress a) { return new IPAddress { Null = true, Address = 0, Cidr = -1 }; }
|
public static implicit operator IPAddress(NullIPAddress a) { return new IPAddress { Null = true, Address = 0, Cidr = -1 }; }
|
||||||
}
|
|
||||||
|
public int CompareTo(object obj)
|
||||||
|
{
|
||||||
|
var a = this.Address;
|
||||||
|
var b = ((IPAddress)obj).Address;
|
||||||
|
|
||||||
|
if (a < b)
|
||||||
|
return 1;
|
||||||
|
else if (a > b)
|
||||||
|
return -1;
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public class NullIPAddress { }
|
public class NullIPAddress { }
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,7 @@ using WebsitePanel.Providers;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Net.Mail;
|
using System.Net.Mail;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
namespace WebsitePanel.EnterpriseServer
|
namespace WebsitePanel.EnterpriseServer
|
||||||
{
|
{
|
||||||
|
@ -2991,6 +2992,18 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
|
|
||||||
public static ResultObject AddVirtualMachinePrivateIPAddresses(int itemId, bool selectRandom, int addressesNumber, string[] addresses, bool provisionKvp)
|
public static ResultObject AddVirtualMachinePrivateIPAddresses(int itemId, bool selectRandom, int addressesNumber, string[] addresses, bool provisionKvp)
|
||||||
{
|
{
|
||||||
|
// trace info
|
||||||
|
Trace.TraceInformation("Entering AddVirtualMachinePrivateIPAddresses()");
|
||||||
|
Trace.TraceInformation("Item ID: {0}", itemId);
|
||||||
|
Trace.TraceInformation("SelectRandom: {0}", selectRandom);
|
||||||
|
Trace.TraceInformation("AddressesNumber: {0}", addressesNumber);
|
||||||
|
|
||||||
|
if (addresses != null)
|
||||||
|
{
|
||||||
|
foreach(var address in addresses)
|
||||||
|
Trace.TraceInformation("addresses[n]: {0}", address);
|
||||||
|
}
|
||||||
|
|
||||||
ResultObject res = new ResultObject();
|
ResultObject res = new ResultObject();
|
||||||
|
|
||||||
// load service item
|
// load service item
|
||||||
|
@ -3026,6 +3039,9 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
|
|
||||||
bool wasEmptyList = (nic.IPAddresses.Length == 0);
|
bool wasEmptyList = (nic.IPAddresses.Length == 0);
|
||||||
|
|
||||||
|
if(wasEmptyList)
|
||||||
|
Trace.TraceInformation("NIC IP addresses list is empty");
|
||||||
|
|
||||||
// check IP addresses if they are specified
|
// check IP addresses if they are specified
|
||||||
List<string> checkResults = CheckPrivateIPAddresses(vm.PackageId, addresses);
|
List<string> checkResults = CheckPrivateIPAddresses(vm.PackageId, addresses);
|
||||||
if (checkResults.Count > 0)
|
if (checkResults.Count > 0)
|
||||||
|
@ -3213,51 +3229,68 @@ namespace WebsitePanel.EnterpriseServer
|
||||||
|
|
||||||
private static string GenerateNextAvailablePrivateIP(SortedList<IPAddress, string> ips, string subnetMask, string startIPAddress)
|
private static string GenerateNextAvailablePrivateIP(SortedList<IPAddress, string> ips, string subnetMask, string startIPAddress)
|
||||||
{
|
{
|
||||||
// start IP address
|
Trace.TraceInformation("Entering GenerateNextAvailablePrivateIP()");
|
||||||
var startIp = IPAddress.Parse(startIPAddress);
|
Trace.TraceInformation("Param - number of sorted IPs in the list: {0}", ips.Count);
|
||||||
var mask = IPAddress.Parse(subnetMask);
|
Trace.TraceInformation("Param - startIPAddress: {0}", startIPAddress);
|
||||||
|
Trace.TraceInformation("Param - subnetMask: {0}", subnetMask);
|
||||||
|
|
||||||
var lastAddress = (startIp & ~mask) - 1;
|
// start IP address
|
||||||
|
var ip = IPAddress.Parse(startIPAddress) - 1;
|
||||||
|
|
||||||
|
Trace.TraceInformation("Start looking for next available IP");
|
||||||
foreach (var addr in ips.Keys)
|
foreach (var addr in ips.Keys)
|
||||||
{
|
{
|
||||||
if ((addr - lastAddress) > 1)
|
if ((addr - ip) > 1)
|
||||||
{
|
{
|
||||||
// it is a gap
|
// it is a gap
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
lastAddress = addr;
|
ip = addr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var genAddr = lastAddress + 1;
|
// final IP found
|
||||||
|
ip = ip + 1;
|
||||||
|
|
||||||
// convert to IP address
|
|
||||||
var ip = startIp & mask | genAddr;
|
|
||||||
string genIP = ip.ToString();
|
string genIP = ip.ToString();
|
||||||
|
Trace.TraceInformation("Generated IP: {0}", genIP);
|
||||||
|
|
||||||
// store in cache
|
// store in cache
|
||||||
ips.Add(genAddr, genIP);
|
Trace.TraceInformation("Adding to sorted list");
|
||||||
|
ips.Add(ip, genIP);
|
||||||
|
|
||||||
|
Trace.TraceInformation("Leaving GenerateNextAvailablePrivateIP()");
|
||||||
return genIP;
|
return genIP;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static SortedList<IPAddress, string> GetSortedNormalizedIPAddresses(List<PrivateIPAddress> ips, string subnetMask)
|
private static SortedList<IPAddress, string> GetSortedNormalizedIPAddresses(List<PrivateIPAddress> ips, string subnetMask)
|
||||||
{
|
{
|
||||||
|
Trace.TraceInformation("Entering GetSortedNormalizedIPAddresses()");
|
||||||
|
Trace.TraceInformation("Param - subnetMask: {0}", subnetMask);
|
||||||
|
|
||||||
var mask = IPAddress.Parse(subnetMask);
|
var mask = IPAddress.Parse(subnetMask);
|
||||||
SortedList<IPAddress, string> sortedIps = new SortedList<IPAddress, string>();
|
SortedList<IPAddress, string> sortedIps = new SortedList<IPAddress, string>();
|
||||||
foreach (PrivateIPAddress ip in ips)
|
foreach (PrivateIPAddress ip in ips)
|
||||||
{
|
{
|
||||||
var addr = ~mask & IPAddress.Parse(ip.IPAddress);
|
var addr = ~mask & IPAddress.Parse(ip.IPAddress);
|
||||||
sortedIps.Add(addr, ip.IPAddress);
|
sortedIps.Add(addr, ip.IPAddress);
|
||||||
|
|
||||||
|
Trace.TraceInformation("Added {0} to sorted IPs list with key: {1} ", ip.IPAddress, addr.ToString());
|
||||||
}
|
}
|
||||||
return sortedIps;
|
return sortedIps;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetPrivateNetworkSubnetMask(string cidr, bool v6) {
|
private static string GetPrivateNetworkSubnetMask(string cidr, bool v6) {
|
||||||
if (v6) return "/" + cidr;
|
if (v6)
|
||||||
else return IPAddress.Parse("/" + cidr).ToV4MaskString();
|
{
|
||||||
|
return "/" + cidr;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return IPAddress.Parse("/" + cidr).ToV4MaskString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetSubnetMaskCidr(string subnetMask) {
|
private static string GetSubnetMaskCidr(string subnetMask) {
|
||||||
|
|
|
@ -142,7 +142,7 @@
|
||||||
<value>If you need your web site to be accessible via dedicated IP address or you are planning to enable SSL for your site you should choose "Dedicated IP" option; otherwise leave this settings by default. In order to create IP-based site you need to purchase IP address from your host.</value>
|
<value>If you need your web site to be accessible via dedicated IP address or you are planning to enable SSL for your site you should choose "Dedicated IP" option; otherwise leave this settings by default. In order to create IP-based site you need to purchase IP address from your host.</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="lblIPHelp2.Text" xml:space="preserve">
|
<data name="lblIPHelp2.Text" xml:space="preserve">
|
||||||
<value> </value>
|
<value>Note: A Zone Template is often defined by your host and contains additional Web Site Pointers to create when creating a new Web Site. Static record definitions such as 'www' conflicts when creating an additional Web Site in the same Domain.</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="rbDedicatedIP.Text" xml:space="preserve">
|
<data name="rbDedicatedIP.Text" xml:space="preserve">
|
||||||
<value>Dedicated</value>
|
<value>Dedicated</value>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue