Пример #1
0
        //Populate v4 options.
        //@param link the link
        //@param configObj the config object or null if none
        protected void PopulateV4Reply(DhcpLink dhcpLink, DhcpV4OptionConfigObject configObj)
        {
            string sname = DhcpServerPolicies.EffectivePolicy(_requestMsg, configObj,
                                                              dhcpLink.GetLink(), Property.V4_HEADER_SNAME);

            if (!String.IsNullOrEmpty(sname))
            {
                _replyMsg.SetsName(sname);
            }

            string filename = DhcpServerPolicies.EffectivePolicy(_requestMsg, configObj,
                                                                 dhcpLink.GetLink(), Property.V4_HEADER_FILENAME);

            if (!String.IsNullOrEmpty(filename))
            {
                _replyMsg.SetFile(filename);
            }

            Dictionary <int, DhcpOption> optionMap =
                _dhcpServerConfig.EffectiveV4AddrOptions(_requestMsg, dhcpLink, configObj);

            if (DhcpServerPolicies.EffectivePolicyAsBoolean(configObj,
                                                            dhcpLink.GetLink(), Property.SEND_REQUESTED_OPTIONS_ONLY))
            {
                optionMap = RequestedOptions(optionMap, _requestMsg);
            }
            _replyMsg.PutAllDhcpOptions(optionMap);

            // copy the relay agent info option from request to reply
            // in order to echo option back to router as required
            if (_requestMsg.HasOption(DhcpConstants.V4OPTION_RELAY_INFO))
            {
                _requestMsg.PutDhcpOption(_requestMsg.GetDhcpOption(DhcpConstants.V4OPTION_RELAY_INFO));
            }
        }
Пример #2
0
        /**
         * Adds the v4 binding to reply.
         *
         * @param clientLink the client link
         * @param binding the binding
         */
        protected void AddBindingToReply(DhcpLink clientLink, Binding binding)
        {
            HashSet <BindingObject> bindingObjs = binding.GetBindingObjects();

            if ((bindingObjs != null) && bindingObjs.Count > 0)
            {
                if (bindingObjs.Count == 1)
                {
                    BindingObject bindingObj = bindingObjs.First();
                    IPAddress     inetAddr   = bindingObj.GetIpAddress();
                    if (inetAddr != null)
                    {
                        _replyMsg.SetYiAddr(inetAddr);
                        // must be an DhcpV4OptionConfigObject for v4 binding
                        DhcpV4OptionConfigObject configObj =
                            (DhcpV4OptionConfigObject)bindingObj.GetConfigObj();
                        if (configObj != null)
                        {
                            long preferred = configObj.GetPreferredLifetime();
                            DhcpV4LeaseTimeOption dhcpV4LeaseTimeOption = new DhcpV4LeaseTimeOption();
                            dhcpV4LeaseTimeOption.SetUnsignedInt(preferred);
                            _replyMsg.PutDhcpOption(dhcpV4LeaseTimeOption);
                            PopulateV4Reply(clientLink, configObj);
                            //TODO when do actually start the timer?  currently, two get
                            //     created - one during advertise, one during reply
                            //     policy to allow real-time expiration?
                            //					bp.startExpireTimerTask(bindingAddr, iaAddrOption.getValidLifetime());
                        }
                        else
                        {
                            log.Error("Null binding pool in binding: " + binding.ToString());
                        }
                    }
                    else
                    {
                        log.Error("Null address in binding: " + binding.ToString());
                    }
                }
                else
                {
                    log.Error("Expected only one bindingObject in v4 Binding, but found " +
                              bindingObjs.Count + "bindingObjects");
                }
            }
            else
            {
                log.Error("No V4 bindings in binding object!");
            }
        }