Dhcpv4Exchange::setHostIdentifiers() {
const ConstCfgHostOperationsPtr cfg =
CfgMgr::instance().getCurrentCfg()->getCfgHostOperations4();
+ // Collect host identifiers. The identifiers are stored in order of preference.
+ // The server will use them in that order to search for host reservations.
BOOST_FOREACH(const Host::IdentifierType& id_type,
cfg->getIdentifierTypes()) {
switch (id_type) {
ctx.duid_ = pkt->getClientId();
ctx.hwaddr_ = getMAC(pkt);
- // Collect host identifiers if host reservations enabled.
+ // Collect host identifiers if host reservations enabled. The identifiers
+ // are stored in order of preference. The server will use them in that
+ // order to search for host reservations.
if (ctx.subnet_ &&
(ctx.subnet_->getHostReservationMode() != Subnet::HR_DISABLED)) {
const ConstCfgHostOperationsPtr cfg =
// Check which host reservation mode is supported in this subnet.
Subnet::HRMode hr_mode = ctx.subnet_->getHostReservationMode();
- // Check if there is a host reseravtion for this client. Attempt to
- // get host information
- if (hr_mode != Subnet::HR_DISABLED) {
- // Iterate over configured identifiers in the order of preference
- // and try to use each of them to search for the reservations.
- BOOST_FOREACH(const IdentifierPair& id_pair, ctx.host_identifiers_) {
- // Attempt to find a host using a specified identifier.
- ctx.host_ = host_get(ctx.subnet_->getID(), id_pair.first,
- &id_pair.second[0], id_pair.second.size());
- // If we found matching host, return.
- if (ctx.host_) {
- return;
- }
+ // Iterate over configured identifiers in the order of preference
+ // and try to use each of them to search for the reservations.
+ BOOST_FOREACH(const IdentifierPair& id_pair, ctx.host_identifiers_) {
+ // Attempt to find a host using a specified identifier.
+ ctx.host_ = host_get(ctx.subnet_->getID(), id_pair.first,
+ &id_pair.second[0], id_pair.second.size());
+ // If we found matching host, return.
+ if (ctx.host_) {
+ return;
}
}
}
EXPECT_TRUE(ctx.host_);
EXPECT_EQ(ctx.host_->getIPv4Reservation(), host->getIPv4Reservation());
- // If the host reservation mode for the subnet is disabled, the
- // host should not be returned, even though it exists in the
- // host database.
+ // Regardless of the host reservation mode, the host should be
+ // always returned when findReservation() is called.
subnet_->setHostReservationMode(Subnet::HR_DISABLED);
ASSERT_NO_THROW(engine.findReservation(ctx));
- EXPECT_FALSE(ctx.host_);
+ EXPECT_TRUE(ctx.host_);
+ EXPECT_EQ(ctx.host_->getIPv4Reservation(), host->getIPv4Reservation());
// Check the third possible reservation mode.
subnet_->setHostReservationMode(Subnet::HR_OUT_OF_POOL);