/// <summary> /// Update an existing static binding. /// </summary> /// <param name="binding">existing client binding</param> /// <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>updated Binding</returns> protected Binding UpdateStaticBinding(Binding binding, DhcpLink clientLink, byte[] duid, byte iatype, long iaid, StaticBinding staticBinding, DhcpMessage requestMsg) { List <IaAddress> addIaAddresses = null; List <IaAddress> updateIaAddresses = null; List <IaAddress> delIaAddresses = null; // not used currently if (staticBinding != null) { _log.Info("Updating static binding: " + binding); HashSet <BindingObject> bindingObjs = binding.GetBindingObjects(); if ((bindingObjs != null) && bindingObjs.Count > 0) { foreach (BindingObject bindingObj in bindingObjs) { if (bindingObj.GetIpAddress().Equals(staticBinding.GetIpAddress())) { SetBindingObjectTimes(bindingObj, staticBinding.GetPreferredLifetimeMs(), staticBinding.GetPreferredLifetimeMs()); break; } //TODO: what about bindingObjs that do NOT match the static binding? } // the existing IaAddress binding objects will be updated updateIaAddresses = binding.GetIaAddresses(); } else { IPAddress inetAddr = staticBinding.GetInetAddress(); if (inetAddr != null) { BindingObject bindingObj = BuildStaticBindingObject(inetAddr, staticBinding); bindingObjs = new HashSet <BindingObject>(); bindingObjs.Add(bindingObj); binding.SetBindingObjects(bindingObjs); // this new IaAddress binding object will be added addIaAddresses = binding.GetIaAddresses(); } } } else { _log.Error("StaticBindingObject is null"); } binding.SetState(IaAddress.STATIC); try { iaMgr.UpdateIA(binding, addIaAddresses, updateIaAddresses, delIaAddresses); return(binding); // if we get here, it worked } catch (Exception ex) { _log.Error("Failed to update binding"); return(null); } }
/// <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); }