/** * Build a BindingPrefix given an IaAddress loaded from the database * and a static binding for the client request. * * @param iaPrefix * @param staticBinding * @return */ private V6BindingPrefix BuildV6BindingPrefixFromIaPrefix(IaPrefix iaPrefix, StaticBinding staticBinding) { V6BindingPrefix bindingPrefix = new V6BindingPrefix(iaPrefix, staticBinding); return(bindingPrefix); }
/** * Build a V6BindingAddress given an IaAddress loaded from the database * and a static binding for the client request. * * @param iaAddr * @param staticBinding * @return */ private V6BindingAddress BuildV6StaticBindingFromIaAddr(IaAddress iaAddr, StaticBinding staticBinding) { V6BindingAddress bindingAddr = new V6BindingAddress(iaAddr, staticBinding); return(bindingAddr); }
/// <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); }
public Binding CreateSolicitBinding(DhcpLink clientLink, DhcpV6ClientIdOption clientIdOption, DhcpV6IaNaOption iaNaOption, DhcpMessage requestMsg, byte state, IPAddress clientV4IPAddress) { byte[] duid = clientIdOption.GetDuid(); long iaid = iaNaOption.GetIaId(); StaticBinding staticBinding = FindStaticBinding(clientLink.GetLink(), duid, IdentityAssoc.NA_TYPE, iaid, requestMsg); if (staticBinding != null) { return(base.CreateStaticBinding(clientLink, duid, IdentityAssoc.NA_TYPE, iaid, staticBinding, requestMsg)); } else { return(base.CreateBinding(clientLink, duid, IdentityAssoc.NA_TYPE, iaid, GetInetAddrs(iaNaOption), requestMsg, state, clientV4IPAddress)); } }
public Binding UpdateBinding(Binding binding, DhcpLink clientLink, byte[] macAddr, DhcpMessage requestMsg, byte state) { StaticBinding staticBinding = FindStaticBinding(clientLink.GetLink(), macAddr, IdentityAssoc.V4_TYPE, 0, requestMsg); if (staticBinding != null) { return(base.UpdateStaticBinding(binding, clientLink, macAddr, IdentityAssoc.V4_TYPE, 0, staticBinding, requestMsg)); } else { return(base.UpdateBinding(binding, clientLink, macAddr, IdentityAssoc.V4_TYPE, 0, GetInetAddrs(requestMsg), requestMsg, state, null)); } }
/** * Create a Binding given an IdentityAssoc loaded from the database. * * @param ia the ia * @param clientLink the client link * @param requestMsg the request msg * * @return the binding */ protected override Binding BuildBindingFromIa(IdentityAssoc ia, DhcpLink clientLink, DhcpMessage requestMsg) { Binding binding = new Binding(ia, clientLink); List <IaAddress> iaAddrs = ia.GetIaAddresses(); if ((iaAddrs != null) && iaAddrs.Count > 0) { List <IaAddress> bindingAddrs = new List <IaAddress>(); foreach (IaAddress iaAddr in iaAddrs) { if (!clientLink.GetSubnet().Contains(iaAddr.GetIpAddress())) { log.Info("Ignoring off-link binding address: " + iaAddr.GetIpAddress().ToString()); continue; } V4BindingAddress bindingAddr = null; StaticBinding staticBinding = FindStaticBinding(clientLink.GetLink(), ia.GetDuid(), ia.GetIatype(), ia.GetIaid(), requestMsg); if (staticBinding != null) { bindingAddr = BuildV4StaticBindingFromIaAddr(iaAddr, staticBinding); } else { bindingAddr = BuildV4BindingAddressFromIaAddr(iaAddr, clientLink.GetLink(), requestMsg); } if (bindingAddr != null) { bindingAddrs.Add(bindingAddr); } } // replace the collection of IaAddresses with BindingAddresses binding.SetIaAddresses(bindingAddrs); } else { log.Warn("IA has no addresses, binding is empty."); } return(binding); }
/** * Create a Binding given an IdentityAssoc loaded from the database. * * @param ia the ia * @param clientLink the client link * @param requestMsg the request msg * * @return the binding */ protected override Binding BuildBindingFromIa(IdentityAssoc ia, DhcpLink clientLink, DhcpMessage requestMsg) { Binding binding = new Binding(ia, clientLink); List <IaAddress> iaPrefs = ia.GetIaAddresses(); if ((iaPrefs != null) && iaPrefs.Count > 0) { List <IaAddress> bindingPrefixes = new List <IaAddress>(); foreach (IaAddress iaAddr in iaPrefs) { // off-link check needed only for v4? // if (!clientLink.getSubnet().contains(iaAddr.getIpAddress())) { // log.info("Ignoring off-link binding address: " + // iaAddr.getIpAddress().getHostAddress()); // continue; // } V6BindingPrefix bindingPrefix = null; StaticBinding staticBinding = FindStaticBinding(clientLink.GetLink(), ia.GetDuid(), ia.GetIatype(), ia.GetIaid(), requestMsg); if (staticBinding != null) { bindingPrefix = BuildV6BindingPrefixFromIaPrefix((IaPrefix)iaAddr, staticBinding); } else { bindingPrefix = BuildBindingAddrFromIaPrefix((IaPrefix)iaAddr, clientLink.GetLink(), requestMsg); } if (bindingPrefix != null) { bindingPrefixes.Add(bindingPrefix); } } // replace the collection of IaPrefixes with BindingPrefixes binding.SetIaAddresses(bindingPrefixes); } else { log.Warn("IA has no prefixes, binding is empty."); } return(binding); }
public Binding CreateDiscoverBinding(DhcpLink clientLink, byte[] macAddr, DhcpMessage requestMsg, byte state) { lock (_lock) { StaticBinding staticBinding = FindStaticBinding(clientLink.GetLink(), macAddr, IdentityAssoc.V4_TYPE, 0, requestMsg); if (staticBinding != null) { return(base.CreateStaticBinding(clientLink, macAddr, IdentityAssoc.V4_TYPE, 0, staticBinding, requestMsg)); } else { return(base.CreateBinding(clientLink, macAddr, IdentityAssoc.V4_TYPE, 0, GetInetAddrs(requestMsg), requestMsg, state, null)); } } }
/** * Perform the DDNS delete processing when a lease is released or expired. * * @param ia the IdentityAssoc of the client * @param iaAddr the released or expired IaAddress */ protected override void DdnsDelete(IdentityAssoc ia, IaAddress iaAddr) { DhcpV6ClientFqdnOption clientFqdnOption = null; try { if ((ia != null) && (iaAddr != null)) { List <DhcpOption> opts = iaAddr.GetDhcpOptions(); if (opts != null) { foreach (DhcpOption opt in opts) { if (opt.GetCode() == DhcpConstants.V6OPTION_CLIENT_FQDN) { clientFqdnOption = new DhcpV6ClientFqdnOption(); //clientFqdnOption.Decode(ByteBuffer.Wrap(opt.GetValue())); break; } } } if (clientFqdnOption != null) { string fqdn = clientFqdnOption.GetDomainName(); if (!String.IsNullOrEmpty(fqdn)) { DhcpLink link = serverConfig.FindLinkForAddress(iaAddr.GetIpAddress()); if (link != null) { V6BindingAddress bindingAddr = null; StaticBinding staticBinding = FindStaticBinding(link.GetLink(), ia.GetDuid(), ia.GetIatype(), ia.GetIaid(), null); if (staticBinding != null) { bindingAddr = BuildV6StaticBindingFromIaAddr(iaAddr, staticBinding); } else { bindingAddr = BuildV6BindingAddressFromIaAddr(iaAddr, link, null); // safe to send null requestMsg } if (bindingAddr != null) { DdnsCallback ddnsComplete = new DhcpV6DdnsComplete(bindingAddr, clientFqdnOption); DhcpConfigObject configObj = bindingAddr.GetConfigObj(); DdnsUpdater ddns = new DdnsUpdater(link.GetLink(), configObj, bindingAddr.GetIpAddress(), fqdn, ia.GetDuid(), configObj.GetValidLifetime(), clientFqdnOption.GetUpdateAaaaBit(), true, ddnsComplete); ddns.ProcessUpdates(); } else { log.Error("Failed to find binding for address: " + iaAddr.GetIpAddress().ToString()); } } else { log.Error("Failed to find link for binding address: " + iaAddr.GetIpAddress().ToString()); } } else { log.Error("FQDN is null or empty. No DDNS deletes performed."); } } else { log.Warn("No Client FQDN option in current binding. No DDNS deletes performed."); } } } catch (Exception ex) { log.Error("Failed to perform DDNS delete"); } }