Exemple #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);
        }
        /**
         * Get the Requested IP addresses from the client message, if any was provided.
         *
         * @param requestMsg the request msg
         *
         * @return a list of InetAddresses containing the requested IP, or null if none requested or
         *         if the requested IP is bogus
         */
        private List <IPAddress> GetInetAddrs(DhcpMessage requestMsg)
        {
            List <IPAddress> inetAddrs = new List <IPAddress>();
            DhcpV4RequestedIpAddressOption reqIpOption = (DhcpV4RequestedIpAddressOption)
                                                         requestMsg.GetDhcpOption(DhcpConstants.V4OPTION_REQUESTED_IP);

            if (reqIpOption != null)
            {
                IPAddress inetAddr =
                    IPAddress.Parse(reqIpOption.GetIpAddress());
                inetAddrs = new List <IPAddress>();
                inetAddrs.Add(inetAddr);
            }
            return(inetAddrs);
        }
        public override bool Process()
        {
            byte[] chAddr = _requestMsg.GetChAddr();

            V4AddrBindingManager bindingMgr = _dhcpServerConfig.GetV4AddrBindingMgr();

            if (bindingMgr != null)
            {
                log.Info("Processing Decline" + " from chAddr=" + Util.ToHexString(chAddr) + " requestedIp=" + requestedIpAddrOption.GetIpAddress());
                Binding binding = bindingMgr.FindCurrentBinding(_clientLink, chAddr, _requestMsg);
                if (binding != null)
                {
                    HashSet <BindingObject> bindingObjs = binding.GetBindingObjects();
                    if ((bindingObjs != null) && bindingObjs.Count != 0)
                    {
                        V4BindingAddress bindingAddr = (V4BindingAddress)bindingObjs.First();
                        bindingMgr.DeclineIaAddress(binding, bindingAddr);
                    }
                    else
                    {
                        log.Error("No binding addresses in binding for client: " + Util.ToHexString(chAddr));
                    }
                }
                else
                {
                    log.Error("No Binding available for client: " + Util.ToHexString(chAddr));
                }
            }
            else
            {
                log.Error("Unable to process V4 Decline:" + " No V4AddrBindingManager available");
            }

            return(false); // no reply for v4 decline
        }