Lease4Ptr lease;
Subnet4Ptr original_subnet = subnet;
+ // We used to issue a separate query (two actually: one for client-id
+ // and another one for hw-addr for) each subnet in the shared network.
+ // That was horribly inefficient if the client didn't have any lease
+ // (or there were many subnets and the client happended to be in one
+ // of the last subnets).
+ //
+ // We now issue at most two queries: get all the leases for specific
+ // client-id and then get all leases for specific hw-address.
if (client_id) {
+
+ // Get all the leases for this client-id
Lease4Collection leases_client_id = LeaseMgrFactory::instance().getLease4(*client_id);
if (!leases_client_id.empty()) {
Subnet4Ptr s = original_subnet;
+ // Among those returned try to find a lease that belongs to
+ // current shared network.
while (s) {
for (auto l = leases_client_id.begin(); l != leases_client_id.end(); ++l) {
if ((*l)->subnet_id_ == s->getID()) {
}
}
+ // If we haven't found a lease yet, try again by hardware-address.
+ // The logic is the same.
if (!lease && hwaddr) {
+
+ // Get all leases for this particular hw-address.
Lease4Collection leases_hwaddr = LeaseMgrFactory::instance().getLease4(*hwaddr);
if (!leases_hwaddr.empty()) {
Subnet4Ptr s = original_subnet;
+ // Pick one that belongs to a subnet in this shared network.
while (s) {
for (auto l = leases_hwaddr.begin(); l != leases_hwaddr.end(); ++l) {
if ((*l)->subnet_id_ == s->getID()) {
// cases in the real deployments, but this is just a test that the allocation
// engine skips checking if the reservation exists when it allocates an
// address. In the real deployment the reservation simply wouldn't exist.
-TEST_F(DORATest, reservationModeDisabledAddressHijacking) {
+TEST_F(DORATest, reservationIgnoredInDisabledMode) {
// Client has a reservation.
Dhcp4Client client(Dhcp4Client::SELECTING);
// Set MAC address which doesn't match the reservation configured.
// This test verifies that the in-pool reservation can be assigned to
// the client not owning this reservation when the reservation mode is
// set to "out-of-pool".
-TEST_F(DORATest, reservationModeOutOfPoolAddressHijacking) {
+TEST_F(DORATest, reservationIgnoredInOutOfPoolMode) {
// Create the first client for which we have a reservation out of the
// dynamic pool.
Dhcp4Client client(Dhcp4Client::SELECTING);
(network->getAllSubnets()->size() > ctx.host_identifiers_.size());
if (use_single_query) {
- for (auto id_pair = ctx.host_identifiers_.begin();
- id_pair != ctx.host_identifiers_.end();
- ++id_pair) {
- ConstHostCollection hosts = HostMgr::instance().getAll(id_pair->first,
- &id_pair->second[0],
- id_pair->second.size());
+ for (auto id_pair : ctx.host_identifiers_) {
+ ConstHostCollection hosts = HostMgr::instance().getAll(id_pair.first,
+ &id_pair.second[0],
+ id_pair.second.size());
// Store the hosts in the temporary map, because some hosts may
// belong to subnets outside of the shared network. We'll need
// to eliminate them.
(subnet->getHostReservationMode() != Network::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_) {
+ for (auto id_pair : ctx.host_identifiers_) {
if (use_single_query) {
if (host_map.count(subnet->getID()) > 0) {
ctx.hosts_[subnet->getID()] = host_map[subnet->getID()];
// our shared network.
Lease6Collection leases;
while (subnet) {
- for (auto l = all_leases.begin(); l != all_leases.end(); ++l) {
- if ((*l)->subnet_id_ == subnet->getID()) {
- leases.push_back(*l);
+ for (auto l : all_leases) {
+ if ((l)->subnet_id_ == subnet->getID()) {
+ leases.push_back(l);
}
}
// the entire subnet (or more subnets) to discover that the address
// pools have been exhausted. Using a subnet from which an address
// was assigned most recently is an optimization which increases
- // the likelyhood of starting from the subnet which address pools
+ // the likelihood of starting from the subnet which address pools
// are not exhausted.
SharedNetwork4Ptr network;
ctx.subnet_->getSharedNetwork(network);