Esempio n. 1
0
        public Binding(IdentityAssoc ia, DhcpLink dhcpLink)
        {
            this.origIa = ia;
            //  save a reference to the original IA
            this.SetDhcpOptions(ia.GetDhcpOptions());
            this.SetDuid(ia.GetDuid());
            this.SetIaAddresses(ia.GetIaAddresses());
            this.SetIaid(ia.GetIaid());
            this.SetIatype(ia.GetIatype());
            this.SetId(ia.GetId());
            this.SetState(ia.GetState());

            this.dhcpLink = dhcpLink;
        }
        /// <summary>
        /// Checks if the duid-iatype-iaid tuple matches the given IA.
        /// </summary>
        /// <param name="duid">DUID</param>
        /// <param name="iatype">IA type</param>
        /// <param name="iaid">IAID</param>
        /// <param name="ia">IA</param>
        /// <returns>true, if is my ia</returns>
        protected bool IsMyIa(byte[] duid, byte iatype, long iaid, IdentityAssoc ia)
        {
            bool rc = false;

            if (duid != null)
            {
                if (Array.Equals(ia.GetDuid(), duid) &&
                    (ia.GetIatype() == iatype) &&
                    (ia.GetIaid() == iaid))
                {
                    rc = true;
                }
            }
            return(rc);
        }
        /**
         * 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);
        }
Esempio n. 4
0
        /**
         * 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");
            }
        }
        /**
         * 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);
        }