Exemplo n.º 1
0
        public ExclusionChanges(NetworkPrefix network, IPRanges before, IPRanges after)
        {
            Network = network;

            BeforeRanges = before.Clone();
            AfterRanges  = after.Clone();
        }
Exemplo n.º 2
0
        public void AddIpRange()
        {
            var ipRange = new IPRange()
            {
                Id = _nextIrId
            };

            IPRanges.Add(ipRange);
            _nextIrId++;
        }
Exemplo n.º 3
0
        // Delete the IPRange and its subnets
        public void DeleteIpRange(IPRange ipRange)
        {
            if (ipRange == null)
            {
                return;
            }

            Subnets.RemoveAll(s => s.IPRangeId == ipRange.Id);
            IPRanges.Remove(ipRange);
            NotifySubnetChange();
        }
Exemplo n.º 4
0
        private void WideIpRange(int ipRangeId, bool notify = true)
        {
            var ipRange = IPRanges.Where(ir => ir.Id == ipRangeId).FirstOrDefault();

            if (ipRange != null)
            {
                var subnets = Subnets.Where(s => s.IPRangeId == ipRangeId).ToList();
                ipRange.WideSubnet(subnets);
                if (notify)
                {
                    NotifySubnetChange();
                }
            }
        }
Exemplo n.º 5
0
        public void SetVnetStartIp(int irId, string ip)
        {
            if (string.IsNullOrEmpty(ip))
            {
                return;
            }

            var ipRange = IPRanges.Where(ir => ir.Id == irId).FirstOrDefault();

            if ((ipRange?.StartIP ?? null) != ip)
            {
                ipRange.StartIP = ip;
                NotifyVnetStartIpChange();
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// Determines whether the specified IP is a valid IP.
 /// </summary>
 /// <param name="ip">The IP.</param>
 /// <param name="invalidRange">The invalid range.</param>
 /// <returns>
 ///     <c>true</c> if the specified IP is a valid IP; otherwise, <c>false</c>.
 /// </returns>
 public static bool IsValidIP(IPAddress ip, IPRanges invalidRange)
 {
     return((GetIPRange(ip) & invalidRange) == IPRanges.None);
 }
Exemplo n.º 7
0
        public void ModifyPool(
            NetworkPrefix network,
            List <IPAddress> gateways,
            IPRanges exclusions,
            string domainName,
            string bootFile,
            List <IPAddress> dnsServers,
            IPAddress tftpServer
            )
        {
            lock (this)
            {
                var addressPool = AddressPools.Where(x => x.Pool.Network.Equals(network)).FirstOrDefault();

                if (addressPool == null)
                {
                    var dhcpPool = GetPoolByPrefix(network);
                    if (dhcpPool == null)
                    {
                        return;
                    }

                    addressPool = new DhcpAddressPool(dhcpPool);
                    AddressPools.Add(addressPool);
                }

                var pool = addressPool.Pool;
                pool.DefaultGateways = gateways
                                       .Select(x =>
                                               x
                                               )
                                       .ToList();

                var exclusionChanges = new ExclusionChanges(pool.Network, pool.Exclusions, exclusions);

                var leasesToKill = Leases
                                   .Where(x =>
                                          exclusionChanges.ToExclude.Contains(x.Address)
                                          )
                                   .ToList();

                foreach (var leaseToKill in leasesToKill)
                {
                    addressPool.SetAvailable(leaseToKill.Address);
                    Leases.Remove(leaseToKill);
                }

                var toExclude = exclusionChanges.ToExclude.Clone();
                toExclude.Remove(pool.Network.BaseNetwork.Network);
                toExclude.Remove(pool.Network.Broadcast);
                addressPool.UnsetAvailable(toExclude);

                var toUnexclude = exclusionChanges.ToUnexclude.Clone();
                toUnexclude.Remove(pool.Network.BaseNetwork.Network);
                toUnexclude.Remove(pool.Network.Broadcast);
                addressPool.SetAvailable(toUnexclude);

                pool.Exclusions              = exclusions.Clone();
                pool.PoolOptions.DomainName  = domainName;
                pool.PoolOptions.BootFile    = bootFile;
                pool.PoolOptions.TFTPServers = new List <string> {
                    tftpServer.ToString()
                };
                pool.PoolOptions.DNSServers = dnsServers
                                              .Select(x =>
                                                      x
                                                      )
                                              .ToList();
            }
        }
Exemplo n.º 8
0
 /// <summary>
 /// Determines whether the specified IP is a valid IP.
 /// </summary>
 /// <param name="ip">The IP.</param>
 /// <param name="invalidRange">The invalid range.</param>
 /// <returns>
 /// 	<c>true</c> if the specified IP is a valid IP; otherwise, <c>false</c>.
 /// </returns>
 public static bool IsValidIP(IPAddress ip, IPRanges invalidRange)
 {
     return (GetIPRange(ip) & invalidRange) == IPRanges.None;
 }
Exemplo n.º 9
0
 public void UnsetAvailable(IPRanges ranges)
 {
     AvailableAddresses.Reserve(ranges);
 }
Exemplo n.º 10
0
 public void SetAvailable(IPRanges ranges)
 {
     AvailableAddresses.Unreserve(ranges);
 }