OptionCustomPtr opt_serverid = boost::dynamic_pointer_cast<
OptionCustom>(question->getOption(DHO_DHCP_SERVER_IDENTIFIER));
- // Try to get the Requested IP Address option and use the address as a hint
- // for the allocation engine. If the server doesn't already have a lease
- // for this client it will try to allocate the one requested.
+ // Check if the client has sent a requested IP address option or
+ // ciaddr.
OptionCustomPtr opt_requested_address = boost::dynamic_pointer_cast<
OptionCustom>(question->getOption(DHO_DHCP_REQUESTED_ADDRESS));
IOAddress hint("0.0.0.0");
if (opt_requested_address) {
hint = opt_requested_address->readAddress();
+
+ } else if (question->getCiaddr() != IOAddress("0.0.0.0")) {
+ hint = question->getCiaddr();
+
}
HWAddrPtr hwaddr = question->getHWAddr();
}
}
-void Dhcpv4SrvTest::checkResponse(const Pkt4Ptr& rsp, uint8_t expected_message_type,
+void Dhcpv4SrvTest::checkResponse(const Pkt4Ptr& rsp, int expected_message_type,
uint32_t expected_transid) {
ASSERT_TRUE(rsp);
- EXPECT_EQ(expected_message_type, rsp->getType());
+ EXPECT_EQ(expected_message_type,
+ static_cast<int>(rsp->getType()));
EXPECT_EQ(expected_transid, rsp->getTransid());
}
/// @param rsp response packet to be validated
/// @param expected_message_type expected message type
/// @param expected_transid expected transaction-id
- void checkResponse(const Pkt4Ptr& rsp, uint8_t expected_message_type,
+ void checkResponse(const Pkt4Ptr& rsp, int expected_message_type,
uint32_t expected_transid);
/// @brief Checks if the lease sent to client is present in the database
// Save the old lease, before renewal.
ctx.old_lease_.reset(new Lease4(*lease));
+ /// The client's address will need to be modified in case if:
+ /// - There is a reservation for the client (likely new one) and
+ /// the currently used address is different.
+ /// - Client requested some IP address and the requested address
+ /// is different than the currently used one. Note that if this
+ /// is a DHCPDISCOVER the requested IP address is ignored when
+ /// it doesn't match the one in use.
if ((ctx.host_ && (ctx.host_->getIPv4Reservation() != lease->addr_)) ||
- (lease->addr_ != ctx.requested_address_)) {
+ (!ctx.fake_allocation_ &&
+ (ctx.requested_address_ != IOAddress("0.0.0.0")) &&
+ (lease->addr_ != ctx.requested_address_))) {
lease = replaceClientLease(lease, ctx);
return (lease);