/** * Build a BindingAddress for the given InetAddress and DhcpLink. * * @param inetAddr the inet addr * @param clientLink the client link * @param requestMsg the request msg * * @return the binding address */ protected override BindingObject BuildBindingObject(IPAddress inetAddr, DhcpLink clientLink, DhcpMessage requestMsg) { V6AddressBindingPool bp = (V6AddressBindingPool)FindBindingPool(clientLink.GetLink(), inetAddr, requestMsg); if (bp != null) { bp.SetUsed(inetAddr); // TODO check if this is necessary IaAddress iaAddr = new IaAddress(); iaAddr.SetIpAddress(inetAddr); V6BindingAddress bindingAddr = new V6BindingAddress(iaAddr, bp); SetBindingObjectTimes(bindingAddr, bp.GetPreferredLifetimeMs(), bp.GetPreferredLifetimeMs()); // TODO store the configured options in the persisted binding? // bindingAddr.setDhcpOptions(bp.getDhcpOptions()); return(bindingAddr); } else { log.Error("Failed to create BindingAddress: No BindingPool found for IP=" + inetAddr.ToString()); } // MUST have a BindingPool, otherwise something's broke return(null); }
/** * Builds a binding pool from an AddressPool using the given link. * * @param pool the AddressPool to wrap as an AddressBindingPool * @param link the link * * @return the binding pool * * @throws DhcpServerConfigException if there is a problem parsing the configured range */ private V6AddressBindingPool BuildV6BindingPool(v6AddressPool pool, link link, linkFilter linkFilter) { Debug.Assert(CheckIPIsUsed != null, "V6AddrBindingManager --BuildV6BindingPool-- CheckIPIsUsed = null"); V6AddressBindingPool bp = new V6AddressBindingPool(pool); long pLifetime = long.Parse(Property.PREFERRED_LIFETIME.Value()); // DhcpServerPolicies.EffectivePolicyAsLong(bp, link, Property.PREFERRED_LIFETIME); bp.SetPreferredLifetime(pLifetime); long vLifetime = long.Parse(Property.VALID_LIFETIME.Value()); // DhcpServerPolicies.EffectivePolicyAsLong(bp, link, Property.VALID_LIFETIME); bp.SetValidLifetime(vLifetime); bp.SetLinkFilter(linkFilter); bp.CheckIPIsUsed = CheckIPIsUsed; List <IPAddress> usedIps = null;// 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 address binding pool: " + bp.GetStartAddress().ToString() + "-" + bp.GetEndAddress().ToString()); return(bp); }