/// <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> /// Create a binding in from a StaticBinding /// </summary> /// <param name="clientLink">link for the client request message</param> /// <param name="duid">DUID of the client</param> /// <param name="iatype">IA type of the client request</param> /// <param name="iaid">IAID of the client request</param> /// <param name="staticBinding">static binding</param> /// <param name="requestMsg">client request message</param> /// <returns>created Binding</returns> protected Binding CreateStaticBinding(DhcpLink clientLink, byte[] duid, byte iatype, long iaid, StaticBinding staticBinding, DhcpMessage requestMsg) { Binding binding = null; if (staticBinding != null) { binding = BuildBinding(clientLink, duid, iatype, iaid, IaAddress.STATIC); IPAddress inetAddr = staticBinding.GetInetAddress(); if (inetAddr != null) { IaAddress iaAddr = new IaAddress(); iaAddr.SetIpAddress(inetAddr); iaAddr.SetState(IaAddress.STATIC); V6BindingAddress bindingAddr = new V6BindingAddress(iaAddr, staticBinding); SetBindingObjectTimes(bindingAddr, staticBinding.GetPreferredLifetimeMs(), staticBinding.GetPreferredLifetimeMs()); // TODO store the configured options in the persisted binding? // bindingAddr.setDhcpOptions(bp.getDhcpOptions()); HashSet <BindingObject> bindingObjs = new HashSet <BindingObject>(); bindingObjs.Add(bindingAddr); binding.SetBindingObjects(bindingObjs); try { iaMgr.CreateIA(binding); } catch (Exception ex) { _log.Error("Failed to create persistent binding"); return(null); } } else { _log.Error("Failed to build binding object(s)"); return(null); } } else { _log.Error("StaticBinding object is null"); } String bindingType = (iatype == IdentityAssoc.V4_TYPE) ? "discover" : "solicit"; if (binding != null) { _log.Info("Created static " + bindingType + " binding: " + binding.ToString()); } else { _log.Warn("Failed to create static " + bindingType + " binding"); } return(binding); }
/// <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"); } }