// protected Timer reaper;

        /**
         * Instantiates a new binding pool.
         *
         * @param pool the pool
         *
         * @throws DhcpServerConfigException if the PrefixPool definition is invalid
         */
        public V6PrefixBindingPool(v6PrefixPool pool)
        {
            try
            {
                this.pool      = pool;
                allocPrefixLen = pool.prefixLength;
                string[] cidr = pool.range.Split('/');
                if ((cidr == null) || (cidr.Length != 2))
                {
                    throw new Exception(
                              "Prefix pool must be specified in prefix/len notation");
                }
                subnet = new Subnet(cidr[0], cidr[1]);
                if (allocPrefixLen < subnet.GetPrefixLength())
                {
                    throw new Exception(
                              "Allocation prefix length must be greater or equal to pool prefix length");
                }
                int numPrefixes = (int)Math.Pow(2, (allocPrefixLen - subnet.GetPrefixLength()));
                freeList = new FreeList(new BigInteger(0),
                                        new BigInteger(numPrefixes) - new BigInteger(1));
                //reaper = new Timer(pool.getRange() + "_Reaper");
                dhcpConfigOptions = new DhcpV6ConfigOptions(pool.prefixConfigOptions);
            }
            catch (Exception ex)
            {
                log.Error("Invalid PrefixPool definition");
                throw new Exception("Invalid PrefixPool definition", ex);
            }
        }
        /**
         * Builds a binding pool from an PrefixPool using the given link and filter.
         *
         * @param pool the AddressPool to wrap as an PrefixBindingPool
         * @param link the link
         * @param linkFilter the link filter
         *
         * @return the binding pool
         *
         * @throws DhcpServerConfigException if there is a problem parsing the configured range
         */
        protected V6PrefixBindingPool BuildV6BindingPool(v6PrefixPool pool, link link,
                                                         linkFilter linkFilter)
        {
            V6PrefixBindingPool bp = new V6PrefixBindingPool(pool);
            long pLifetime         =
                DhcpServerPolicies.EffectivePolicyAsLong(bp, link, Property.PREFERRED_LIFETIME);

            bp.SetPreferredLifetime(pLifetime);
            long vLifetime =
                DhcpServerPolicies.EffectivePolicyAsLong(bp, link, Property.VALID_LIFETIME);

            bp.SetValidLifetime(vLifetime);
            bp.SetLinkFilter(linkFilter);

            List <IPAddress> usedIps = iaMgr.FindExistingIPs(bp.GetStartAddress(), bp.GetEndAddress());

            if ((usedIps != null) && usedIps.Count > 0)
            {
                foreach (IPAddress ip in usedIps)
                {
                    //TODO: for the quickest startup?...
                    // set IP as used without checking if the binding has expired
                    // let the reaper thread deal with all binding cleanup activity
                    bp.SetUsed(ip);
                }
            }
            log.Info("Built prefix binding pool: " + bp.GetStartAddress().ToString() + "-" +
                     bp.GetEndAddress().ToString() + ", size=" + bp.GetSize());
            return(bp);
        }
Example #3
0
        protected bool AllIaPrefixesOnLink(DhcpV6IaPdOption dhcpIaPdOption, DhcpLink clientLink)
        {
            bool onLink = true;

            //  assume all IPs are on link
            if ((dhcpIaPdOption != null))
            {
                List <DhcpV6IaPrefixOption> iaPrefixOpts = dhcpIaPdOption.GetIaPrefixOptions();
                if ((iaPrefixOpts != null))
                {
                    foreach (DhcpV6IaPrefixOption iaPrefixOpt in iaPrefixOpts)
                    {
                        if (this.clientLink.GetSubnet().GetSubnetAddress().IsIPv6LinkLocal)
                        {
                            //  if the Link address is link-local, then check if the
                            //  address is within one of the pools configured for this
                            //  local Link, which automatically makes this server
                            //  "authoritative" (in ISC parlance) for this local net
                            v6PrefixPool p = DhcpServerConfiguration.FindPrefixPool(this.clientLink.GetLink(), iaPrefixOpt.GetInetAddress());
                            if ((p == null))
                            {
                                log.Info(("No local prefix pool found for requested IA_PD: "
                                          + (iaPrefixOpt.GetInetAddress().ToString() + " - considered to be off link")));
                                iaPrefixOpt.SetPreferredLifetime(0);
                                iaPrefixOpt.SetValidLifetime(0);
                                onLink = false;
                            }
                        }
                        else if (!this.clientLink.GetSubnet().Contains(iaPrefixOpt.GetInetAddress()))
                        {
                            log.Info(("Setting zero(0) lifetimes for off link prefix: " + iaPrefixOpt.GetInetAddress().ToString()));
                            iaPrefixOpt.SetPreferredLifetime(0);
                            iaPrefixOpt.SetValidLifetime(0);
                            onLink = false;
                        }
                    }
                }
            }

            return(onLink);
        }
 /**
  * Sets the pool.
  *
  * @param pool the new pool
  */
 public void SetV6PrefixPool(v6PrefixPool pool)
 {
     this.pool = pool;
 }
 /**
  * Builds a binding pool from an PrefixPool using the given link.
  *
  * @param pool the PrefixPool to wrap as an PrefixBindingPool
  * @param link the link
  *
  * @return the binding pool
  *
  * @throws DhcpServerConfigException if there is a problem parsing the configured range
  */
 protected V6PrefixBindingPool BuildV6BindingPool(v6PrefixPool pool, link link)
 {
     return(BuildV6BindingPool(pool, link, null));
 }