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); }
public override bool PreProcess() { if (!base.PreProcess()) { return(false); } requestedIpAddrOption = (DhcpV4RequestedIpAddressOption)_requestMsg.GetDhcpOption(DhcpConstants.V4OPTION_REQUESTED_IP); if (requestedIpAddrOption == null) { log.Warn("Ignoring Decline message: " + "Requested IP option is null"); return(false); } return(true); }
/** * 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); }
private DhcpV4Message BuildRequestMessage(DhcpV4Message offer) { DhcpV4Message msg = new DhcpV4Message(IPAddress.Parse("0.0.0.0"), new IPEndPoint(serverAddr, serverPort)); msg.SetOp((short)DhcpConstants.V4_OP_REQUEST); msg.SetTransactionId(offer.GetTransactionId()); msg.SetHtype((short)1); // ethernet msg.SetHlen((byte)6); msg.SetChAddr(offer.GetChAddr()); msg.SetGiAddr(clientAddr); // look like a relay to the DHCP server DhcpV4MsgTypeOption msgTypeOption = new DhcpV4MsgTypeOption(); msgTypeOption.SetUnsignedByte((short)DhcpConstants.V4MESSAGE_TYPE_REQUEST); msg.PutDhcpOption(msgTypeOption); DhcpV4RequestedIpAddressOption reqIpOption = new DhcpV4RequestedIpAddressOption(); reqIpOption.SetIpAddress(offer.GetYiAddr().ToString()); msg.PutDhcpOption(reqIpOption); return(msg); }
/* (non-Javadoc) * @see com.jagornet.dhcpv6.server.request.BaseDhcpProcessor#preProcess() */ public override bool PreProcess() { if (!base.PreProcess()) { return(false); } DhcpV4ServerIdOption requestedServerIdOption = _requestMsg.GetDhcpV4ServerIdOption(); requestedIpAddrOption = (DhcpV4RequestedIpAddressOption) _requestMsg.GetDhcpOption(DhcpConstants.V4OPTION_REQUESTED_IP); // first determine what KIND of request we are dealing with if (_requestMsg.GetCiAddr().Equals(DhcpConstants.ZEROADDR_V4)) { // the ciAddr MUST be 0.0.0.0 for Init-Reboot and Selecting if (requestedServerIdOption == null) { // init-reboot MUST NOT have server-id option type = RequestType.Request_InitReboot; } else { // selecting MUST have server-id option type = RequestType.Request_Selecting; } } else { // the ciAddr MUST NOT be 0.0.0.0 for Renew and Rebind if (_requestMsg.IsUnicast()) { // renew is unicast // NOTE: this will not happen if the v4 broadcast interface used at startup, // but handling of DHCPv4 renew/rebind is the same anyway type = RequestType.Request_Renewing; } else { // rebind is broadcast type = RequestType.Request_Rebinding; } } if ((type == RequestType.Request_InitReboot) || (type == RequestType.Request_Selecting)) { if (requestedIpAddrOption == null) { log.Warn("Ignoring " + type + " message: " + "Requested IP option is null"); return(false); } if (type == RequestType.Request_Selecting) { String requestedServerId = requestedServerIdOption.GetIpAddress(); string myServerId = _dhcpV4ServerIdOption.GetIpAddress(); if (!myServerId.Equals(requestedServerId)) { log.Warn("Ignoring " + type + " message: " + "Requested ServerId: " + requestedServerIdOption + " My ServerId: " + _dhcpV4ServerIdOption); return(false); } } } else { // type == Renewing or Rebinding if (requestedIpAddrOption != null) { log.Warn("Ignoring " + type + " message: " + "Requested IP option is not null"); return(false); } } return(true); }