Commit aec8c636 authored by Marcin Siodelski's avatar Marcin Siodelski

[4303] Address second round of review comments.

- No additional check for HR mode in findReservations
- Additional commentary in the loop collecting host ids.
parent e7bf3666
...@@ -245,6 +245,8 @@ void ...@@ -245,6 +245,8 @@ void
Dhcpv4Exchange::setHostIdentifiers() { Dhcpv4Exchange::setHostIdentifiers() {
const ConstCfgHostOperationsPtr cfg = const ConstCfgHostOperationsPtr cfg =
CfgMgr::instance().getCurrentCfg()->getCfgHostOperations4(); 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, BOOST_FOREACH(const Host::IdentifierType& id_type,
cfg->getIdentifierTypes()) { cfg->getIdentifierTypes()) {
switch (id_type) { switch (id_type) {
......
...@@ -281,7 +281,9 @@ Dhcpv6Srv::createContext(const Pkt6Ptr& pkt) { ...@@ -281,7 +281,9 @@ Dhcpv6Srv::createContext(const Pkt6Ptr& pkt) {
ctx.duid_ = pkt->getClientId(); ctx.duid_ = pkt->getClientId();
ctx.hwaddr_ = getMAC(pkt); 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_ && if (ctx.subnet_ &&
(ctx.subnet_->getHostReservationMode() != Subnet::HR_DISABLED)) { (ctx.subnet_->getHostReservationMode() != Subnet::HR_DISABLED)) {
const ConstCfgHostOperationsPtr cfg = const ConstCfgHostOperationsPtr cfg =
......
...@@ -314,19 +314,15 @@ AllocEngine::findReservationInternal(ContextType& ctx, ...@@ -314,19 +314,15 @@ AllocEngine::findReservationInternal(ContextType& ctx,
// Check which host reservation mode is supported in this subnet. // Check which host reservation mode is supported in this subnet.
Subnet::HRMode hr_mode = ctx.subnet_->getHostReservationMode(); Subnet::HRMode hr_mode = ctx.subnet_->getHostReservationMode();
// Check if there is a host reseravtion for this client. Attempt to // Iterate over configured identifiers in the order of preference
// get host information // and try to use each of them to search for the reservations.
if (hr_mode != Subnet::HR_DISABLED) { BOOST_FOREACH(const IdentifierPair& id_pair, ctx.host_identifiers_) {
// Iterate over configured identifiers in the order of preference // Attempt to find a host using a specified identifier.
// and try to use each of them to search for the reservations. ctx.host_ = host_get(ctx.subnet_->getID(), id_pair.first,
BOOST_FOREACH(const IdentifierPair& id_pair, ctx.host_identifiers_) { &id_pair.second[0], id_pair.second.size());
// Attempt to find a host using a specified identifier. // If we found matching host, return.
ctx.host_ = host_get(ctx.subnet_->getID(), id_pair.first, if (ctx.host_) {
&id_pair.second[0], id_pair.second.size()); return;
// If we found matching host, return.
if (ctx.host_) {
return;
}
} }
} }
} }
......
...@@ -1669,12 +1669,12 @@ TEST_F(AllocEngine4Test, findReservation) { ...@@ -1669,12 +1669,12 @@ TEST_F(AllocEngine4Test, findReservation) {
EXPECT_TRUE(ctx.host_); EXPECT_TRUE(ctx.host_);
EXPECT_EQ(ctx.host_->getIPv4Reservation(), host->getIPv4Reservation()); EXPECT_EQ(ctx.host_->getIPv4Reservation(), host->getIPv4Reservation());
// If the host reservation mode for the subnet is disabled, the // Regardless of the host reservation mode, the host should be
// host should not be returned, even though it exists in the // always returned when findReservation() is called.
// host database.
subnet_->setHostReservationMode(Subnet::HR_DISABLED); subnet_->setHostReservationMode(Subnet::HR_DISABLED);
ASSERT_NO_THROW(engine.findReservation(ctx)); 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. // Check the third possible reservation mode.
subnet_->setHostReservationMode(Subnet::HR_OUT_OF_POOL); subnet_->setHostReservationMode(Subnet::HR_OUT_OF_POOL);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment