157 UDPDataIndication *ctrl = check_and_cast<UDPDataIndication *>(packet->removeControlInfo());
158 int inputInterfaceId = ctrl->getInterfaceId();
161 EV_WARN <<
"DHCP message arrived on a different interface, dropping\n";
168 int messageType = packet->getOptions().getMessageType();
171 EV_INFO <<
"DHCPDISCOVER arrived. Handling it." << endl;
176 lease =
getAvailableLease(packet->getOptions().getRequestedIp(), packet->getChaddr());
177 if (lease !=
nullptr) {
179 lease->
mac = packet->getChaddr();
180 lease->xid = packet->getXid();
182 lease->leased =
true;
186 EV_ERROR <<
"No lease available. Ignoring discover." << endl;
190 lease->xid = packet->getXid();
196 EV_INFO <<
"DHCPREQUEST arrived. Handling it." << endl;
204 if (lease !=
nullptr) {
205 if (lease->ip != packet->getOptions().getRequestedIp()) {
206 EV_ERROR <<
"The 'requested IP address' must be filled in with the 'yiaddr' value from the chosen DHCPOFFER." << endl;
210 EV_INFO <<
"From now " << lease->ip <<
" is leased to " << lease->mac <<
"." << endl;
211 lease->xid = packet->getXid();
213 lease->leased =
true;
222 EV_ERROR <<
"There is no available lease for " << packet->getChaddr() <<
". Probably, the client missed to send DHCPDISCOVER before DHCPREQUEST." << endl;
227 if (packet->getCiaddr().isUnspecified()) {
229 IPv4Address requestedAddress = packet->getOptions().getRequestedIp();
230 auto it =
leased.find(requestedAddress);
234 EV_WARN <<
"DHCP server has no record of IP " << requestedAddress <<
"." << endl;
237 DHCPLease *lease = &it->second;
238 EV_INFO <<
"Initialization with known IP address (INIT-REBOOT) " << lease->ip <<
" on " << lease->mac <<
" was successful." << endl;
239 lease->xid = packet->getXid();
241 lease->leased =
true;
247 EV_ERROR <<
"The requested IP address is incorrect, or is on the wrong network." << endl;
252 auto it =
leased.find(packet->getCiaddr());
253 DHCPLease *lease = &it->second;
255 EV_INFO <<
"Request for renewal/rebinding IP " << lease->ip <<
" to " << lease->mac <<
"." << endl;
256 lease->xid = packet->getXid();
258 lease->leased =
true;
264 EV_ERROR <<
"Renewal/rebinding process failed: requested IP address " << packet->getCiaddr() <<
" not found in the server's database!" << endl;
271 EV_WARN <<
"BOOTREQUEST arrived, but DHCP message type is unknown. Dropping it." << endl;
274 EV_WARN <<
"Message opcode is unknown. This DHCP server only handles BOOTREQUEST messages. Dropping it." << endl;
277 EV_DEBUG <<
"Deleting " << packet <<
"." << endl;
IPv4InterfaceData * ipv4Data() const
Definition: InterfaceEntry.h:221
static bool maskedAddrAreEqual(const IPv4Address &addr1, const IPv4Address &addr2, const IPv4Address &netmask)
Test if the masked addresses (ie the mask is applied to addr1 and addr2) are equal.
Definition: IPv4Address.cc:260
int getInterfaceId() const
Definition: InterfaceEntry.h:185
virtual DHCPLease * getLeaseByMac(MACAddress mac)
Definition: DHCPServer.cc:442
bool isOperational
Definition: DHCPServer.h:48
virtual DHCPLease * getAvailableLease(IPv4Address requestedAddress, MACAddress &clientMAC)
Definition: DHCPServer.cc:457
Definition: DHCPMessage_m.h:72
int numReceived
Definition: DHCPServer.h:50
virtual void sendNAK(DHCPMessage *msg)
Definition: DHCPServer.cc:283
unsigned int leaseTime
Definition: DHCPServer.h:56
IPv4Address subnetMask
Definition: DHCPServer.h:57
DHCPLeased leased
Definition: DHCPServer.h:46
IPv4Address getIPAddress() const
Definition: IPv4InterfaceData.h:177
Definition: DHCPMessage_m.h:74
Definition: DHCPMessage_m.h:50
virtual void sendACK(DHCPLease *lease, DHCPMessage *packet)
Definition: DHCPServer.cc:311
virtual void sendOffer(DHCPLease *lease, DHCPMessage *packet)
Definition: DHCPServer.cc:376
MACAddress mac
Definition: DHCPLease.h:36
InterfaceEntry * ie
Definition: DHCPServer.h:61