/// <summary> /// Release an IaAddress. If policy dictates, the address will be deleted, /// otherwise the state will be marked as released instead. In either case, /// a DDNS delete will be issued for the address binding. /// </summary> /// <param name="ia">iaAddr the IaAddress to be released</param> /// <param name="iaAddr">iaAddr the IaAddress to be released</param> public void ReleaseIaAddress(IdentityAssoc ia, IaAddress iaAddr) { try { log.Info("Releasing address: " + iaAddr.GetIpAddress().ToString()); //DdnsDelete(ia, iaAddr); if (DhcpServerPolicies.GlobalPolicyAsBoolean( Property.BINDING_MANAGER_DELETE_OLD_BINDINGS)) { iaMgr.DeleteIaAddr(iaAddr); // free the address only if it is deleted from the db, // otherwise, we will get a unique constraint violation // if another client obtains this released IP address FreeAddress(iaAddr.GetIpAddress()); } else { iaAddr.SetStartTime(DateTime.Now); iaAddr.SetPreferredEndTime(DateTime.Now); iaAddr.SetValidEndTime(DateTime.Now); iaAddr.SetState(IaAddress.RELEASED); iaMgr.UpdateIaAddr(iaAddr); log.Info("Address released: " + iaAddr.ToString()); } } catch (Exception ex) { log.Error("Failed to release address"); } }
/// <summary> /// Decline an IaAddress. This is done when the client declines an address. /// Perform a DDNS delete just in case it was already registered, then mark /// the address as declined (unavailable). /// </summary> /// <param name="ia">iaAddr the declined IaAddress.</param> /// <param name="iaAddr">iaAddr the declined IaAddress.</param> public void DeclineIaAddress(IdentityAssoc ia, IaAddress iaAddr) { try { log.Info("Declining address: " + iaAddr.GetIpAddress().ToString()); //DdnsDelete(ia, iaAddr); iaAddr.SetStartTime(DateTime.Now); iaAddr.SetPreferredEndTime(DateTime.Now); iaAddr.SetValidEndTime(DateTime.Now); iaAddr.SetState(IaAddress.DECLINED); iaMgr.UpdateIaAddr(iaAddr); log.Info("Address declined: " + iaAddr.ToString()); } catch (Exception ex) { log.Error("Failed to decline address"); } }
/// <summary> /// Find an address that can be reused. This method is invoked only /// when no "virgin" leases can be found for a new client request. /// </summary> /// <param name="bp"> binding pool</param> /// <returns>the oldest available address, if any</returns> protected IPAddress ReuseAvailableAddress(BindingPool bp) { Monitor.Enter(_lock); try { if (_log.IsDebugEnabled) { _log.Debug("Finding available addresses in pool: " + bp.ToString()); } List <IaAddress> iaAddrs = iaMgr.FindUnusedIaAddresses(bp.GetStartAddress(), bp.GetEndAddress()); if ((iaAddrs != null) && iaAddrs.Count > 0) { if (_log.IsDebugEnabled) { foreach (IaAddress iaAddre in iaAddrs) { _log.Debug("Found available address: " + iaAddre.ToString()); } } // list is ordered by validendtime // so the first one is the oldest one IaAddress iaAddr = iaAddrs.First(); _log.Info("Deleting oldest available address: " + iaAddr.ToString()); // delete the oldest one and return the IP // allowing that IP to be used again iaMgr.DeleteIaAddr(iaAddr); return(iaAddr.GetIpAddress()); // TODO: should we clear the rest of unused IPs // now, or wait for them to expire or be needed // for (int i=1; i<iaAddrs.size(); i++) { // // } } } finally { Monitor.Exit(_lock); } return(null); }