Esempio n. 1
0
        /**
         * Build a BindingAddress for the given InetAddress and DhcpLink.
         *
         * @param inetAddr the inet addr
         * @param clientLink the client link
         * @param requestMsg the request msg
         *
         * @return the binding address
         */
        protected override BindingObject BuildBindingObject(IPAddress inetAddr,
                                                            DhcpLink clientLink, DhcpMessage requestMsg)
        {
            V6AddressBindingPool bp =
                (V6AddressBindingPool)FindBindingPool(clientLink.GetLink(), inetAddr, requestMsg);

            if (bp != null)
            {
                bp.SetUsed(inetAddr);   // TODO check if this is necessary
                IaAddress iaAddr = new IaAddress();
                iaAddr.SetIpAddress(inetAddr);
                V6BindingAddress bindingAddr = new V6BindingAddress(iaAddr, bp);
                SetBindingObjectTimes(bindingAddr,
                                      bp.GetPreferredLifetimeMs(), bp.GetPreferredLifetimeMs());
                // TODO store the configured options in the persisted binding?
                // bindingAddr.setDhcpOptions(bp.getDhcpOptions());
                return(bindingAddr);
            }
            else
            {
                log.Error("Failed to create BindingAddress: No BindingPool found for IP=" +
                          inetAddr.ToString());
            }
            // MUST have a BindingPool, otherwise something's broke
            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);
        }
        /// <summary>
        /// Build a BindingObject from a static binding.  Because the StaticBinding
        /// implements the DhcpConfigObject interface, it can be used directly in
        /// creating the BindingObject, unlike buildBindingObject above which is
        /// abstract because each implementation must lookup the object in that
        /// binding manager's map of binding pools.
        /// </summary>
        /// <param name="inetAddr">IP address for this binding object</param>
        /// <param name="staticBinding">static binding</param>
        /// <returns>binding object</returns>
        protected BindingObject BuildStaticBindingObject(IPAddress inetAddr,
                                                         PIXIS.DHCP.Request.Bind.StaticBinding staticBinding)
        {
            IaAddress iaAddr = new IaAddress();

            iaAddr.SetIpAddress(inetAddr);
            V6BindingAddress bindingAddr = new V6BindingAddress(iaAddr, staticBinding);

            SetBindingObjectTimes(bindingAddr,
                                  staticBinding.GetPreferredLifetimeMs(),
                                  staticBinding.GetPreferredLifetimeMs());
            return(bindingAddr);
        }