//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)); } }
public static DhcpV4Message HandleMessage(IPAddress localAddress, DhcpV4Message dhcpMessage) { DhcpV4Message replyMessage = null; if (dhcpMessage.GetOp() == DhcpConstants.V4_OP_REQUEST) { IPAddress linkAddress = null; if (dhcpMessage.GetGiAddr().Equals(DhcpConstants.ZEROADDR_V4)) { linkAddress = localAddress; //log.Info("Handling client request on local client link address: " + // linkAddress.ToString()); } else { linkAddress = dhcpMessage.GetGiAddr(); log.Info("Handling client request on remote client link address: " + linkAddress.ToString()); } DhcpV4MsgTypeOption msgTypeOption = (DhcpV4MsgTypeOption) dhcpMessage.GetDhcpOption(DhcpConstants.V4OPTION_MESSAGE_TYPE); if (msgTypeOption != null) { short msgType = msgTypeOption.GetUnsignedByte(); DhcpV4MessageProcessor processor = null; switch (msgType) { case DhcpConstants.V4MESSAGE_TYPE_DISCOVER: processor = new DhcpV4DiscoverProcessor(dhcpMessage, linkAddress); break; case DhcpConstants.V4MESSAGE_TYPE_REQUEST: processor = new DhcpV4RequestProcessor(dhcpMessage, linkAddress); break; case DhcpConstants.V4MESSAGE_TYPE_DECLINE: processor = new DhcpV4DeclineProcessor(dhcpMessage, linkAddress); break; case DhcpConstants.V4MESSAGE_TYPE_RELEASE: processor = new DhcpV4ReleaseProcessor(dhcpMessage, linkAddress); break; case DhcpConstants.V4MESSAGE_TYPE_INFORM: processor = new DhcpV4InformProcessor(dhcpMessage, linkAddress); break; default: log.Error("Unknown message type."); break; } if (processor != null) { return(processor.ProcessMessage(localAddress)); } else { log.Error("No processor found for message type: " + msgType); } } else { log.Error("No message type option found in request."); } return(null); } else { log.Error("Unsupported op code: " + dhcpMessage.GetOp()); } return(replyMessage); }