Esempio n. 1
0
        public bool AddrOnLink(DhcpV4RequestedIpAddressOption requestedIpOption, DhcpLink clientLink)
        {
            bool onLink = true;

            if (requestedIpOption != null)
            {
                IPAddress requestedIp = IPAddress.Parse(requestedIpOption.GetIpAddress());
                if (!clientLink.GetSubnet().Contains(requestedIp))
                {
                    onLink = false;
                }
            }
            return(onLink);
        }
        /**
         * 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);
        }