/** * 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); }
/** * 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); }
protected override List <v6AddressPool> GetV6AddressPools(linkFilter linkFilter) { return(linkFilter.v6NaAddrPools); }
/** * Sets the link filter. * * @param linkFilter the new link filter */ public void SetLinkFilter(linkFilter linkFilter) { this.linkFilter = linkFilter; }
/** * Fetch the V6AddressPoolsType XML object from the given LinkFilter XML object. * The subclasses fetch the address pools for either NA or TA addresses. * * @param linkFilter the link filter * @return the V6AddressPoolsType for this link filter, or null if none */ protected abstract List <v6AddressPool> GetV6AddressPools(linkFilter linkFilter);
/** * 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); }
/// <summary> /// Gets the next free address from the pool(s) configured for the client link. /// </summary> /// <param name="clientLink">client link</param> /// <param name="requestMsg">request message</param> /// <returns></returns> protected IPAddress GetNextFreeAddress(DhcpLink clientLink, DhcpMessage requestMsg, IPAddress clientV4IPAddress) { if (clientLink != null) { List <BindingPool> pools = bindingPoolMap.ContainsKey(clientLink.GetLinkAddress()) ? bindingPoolMap[clientLink.GetLinkAddress()] : null; if ((pools != null) && pools.Count > 0) { foreach (BindingPool bp in pools) { linkFilter filter = bp.GetLinkFilter(); if ((requestMsg != null) && (filter != null)) { if (!DhcpServerConfiguration.MsgMatchesFilter(requestMsg, filter)) { _log.Info("Client request does not match filter, skipping pool: " + bp.ToString()); continue; } } _log.Debug("Getting next available address from pool: " + bp.ToString()); if (clientV4IPAddress != null) { //if (bp.GetV6AssignRule() != AssignDhcpV6Rule.Noen && bp.GetV6AssignRule() != AssignDhcpV6Rule.AssignV6IPAndDNSByV6Pool) //{ // string[] clientV4IPArray = clientV4IPAddress.ToString().Split('.'); // IPAddress clientV6Addr = null; // if (bp.GetV6AssignRule() == AssignDhcpV6Rule.AssignV6IPAndDNSByTransferV4IPLast2) // { // clientV6Addr = bp.GetNextAvailableAddress(clientV4IPArray[2], clientV4IPArray[3]); // } // else // { // clientV6Addr = bp.GetNextAvailableAddress("", clientV4IPArray[3]); // } // if (clientV6Addr != null) // { // return clientV6Addr; // } // // Callback sreach V4 IP Using MAC // // 依照回傳的 IPv4 IP 決定回傳的 IPv6 IP // // Return new IPAddress(clientLink.GetLinkAddress() + "IPv4 尾 1 碼或 2 碼") // // byte[] v4TransferV6 = new byte[] { 32, 1, 176, 48, 17, 40, 1, 96, 0, 0, 0, 0, 0, 97, 1, 151 }; // // return new IPAddress(v4TransferV6); // // 若無 v4 IP 則依照既有的邏輯進行派發,派發的 IP 從::255:255 以後開始派發 //} } IPAddress free = bp.GetNextAvailableAddress(); if (free != null) { _log.Debug("Found next available address: " + free.ToString()); return(free); } else { // warning here, b/c there may be more pools _log.Warn("No free addresses available in pool: " + bp.ToString()); } } // if we get this far, then we did not find any free(virgin) addresses // so we must start searching for any that can be used in the pools foreach (BindingPool bp in pools) { linkFilter filter = bp.GetLinkFilter(); if ((requestMsg != null) && (filter != null)) { if (!DhcpServerConfiguration.MsgMatchesFilter(requestMsg, filter)) { _log.Info("Client request does not match filter, skipping pool: " + bp.ToString()); continue; } } IPAddress reused = ReuseAvailableAddress(bp); if (reused != null) { return(reused); } } } else { _log.Error("No Pools defined in server configuration for Link: " + clientLink.GetLinkAddress()); } } else { throw new Exception("ClientLink is null"); } return(null); }