protected override BindingObject BuildBindingObject(IPAddress inetAddr, DhcpLink clientLink, DhcpMessage requestMsg) { V4AddressBindingPool bp = (V4AddressBindingPool)FindBindingPool(clientLink.GetLink(), inetAddr, requestMsg); if (bp != null) { bp.SetUsed(inetAddr); // TODO check if this is necessary IaAddress iaAddr = new IaAddress(); iaAddr.SetIpAddress(inetAddr); V4BindingAddress bindingAddr = new V4BindingAddress(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 V4BindingAddress: No V4BindingPool found for IP=" + inetAddr.ToString()); } // MUST have a BindingPool, otherwise something's broke return(null); }
/** * Builds a binding pool from an V4AddressPool using the given link and filter. * * @param pool the V4AddressPool to wrap as an V4AddressBindingPool * @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 V4AddressBindingPool BuildV4BindingPool(v4AddressPool pool, link link, linkFilter linkFilter) { V4AddressBindingPool bp = new V4AddressBindingPool(pool); long leasetime = DhcpServerPolicies.EffectivePolicyAsLong(bp, link, Property.V4_DEFAULT_LEASETIME); bp.SetLeasetime(leasetime); 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 v4 address binding pool: " + bp.GetStartAddress().ToString() + "-" + bp.GetEndAddress().ToString() + " size=" + bp.GetSize()); return(bp); }