summaryrefslogtreecommitdiffstats
path: root/src/bin/dhcp4
diff options
context:
space:
mode:
authorRazvan Becheriu <razvan@isc.org>2024-01-12 15:31:50 +0100
committerRazvan Becheriu <razvan@isc.org>2024-01-22 16:49:59 +0100
commit1b4d7b0293bca6657d1f798e6e4e65ce95d2dca4 (patch)
treefc89d85f5dd097dd85a2921ce1382980e012a423 /src/bin/dhcp4
parent[#3119] replace const auto with auto const (diff)
downloadkea-1b4d7b0293bca6657d1f798e6e4e65ce95d2dca4.tar.xz
kea-1b4d7b0293bca6657d1f798e6e4e65ce95d2dca4.zip
[#3119] use range based for loop or BOOST_FOREACH
Diffstat (limited to 'src/bin/dhcp4')
-rw-r--r--src/bin/dhcp4/dhcp4_srv.cc137
-rw-r--r--src/bin/dhcp4/json_config_parser.cc53
-rw-r--r--src/bin/dhcp4/tests/callout_library_3.cc4
-rw-r--r--src/bin/dhcp4/tests/config_backend_unittest.cc1
-rw-r--r--src/bin/dhcp4/tests/config_parser_unittest.cc26
-rw-r--r--src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc13
-rw-r--r--src/bin/dhcp4/tests/dhcp4_client.cc20
-rw-r--r--src/bin/dhcp4/tests/dhcp4_srv_unittest.cc4
-rw-r--r--src/bin/dhcp4/tests/hooks_unittest.cc2
-rw-r--r--src/bin/dhcp4/tests/shared_network_unittest.cc7
10 files changed, 123 insertions, 144 deletions
diff --git a/src/bin/dhcp4/dhcp4_srv.cc b/src/bin/dhcp4/dhcp4_srv.cc
index 8edef2d542..f9a7ab61ec 100644
--- a/src/bin/dhcp4/dhcp4_srv.cc
+++ b/src/bin/dhcp4/dhcp4_srv.cc
@@ -65,6 +65,7 @@
#include <boost/algorithm/string.hpp>
#include <boost/foreach.hpp>
+#include <boost/range/adaptor/reversed.hpp>
#include <boost/pointer_cast.hpp>
#include <boost/shared_ptr.hpp>
@@ -402,8 +403,7 @@ Dhcpv4Exchange::setHostIdentifiers(AllocEngine::ClientContext4Ptr context) {
// 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()) {
+ for (auto const& id_type : cfg->getIdentifierTypes()) {
switch (id_type) {
case Host::IDENT_HWADDR:
if (context->hwaddr_ && !context->hwaddr_->hwaddr_.empty()) {
@@ -515,9 +515,8 @@ void
Dhcpv4Exchange::setReservedClientClasses(AllocEngine::ClientContext4Ptr context) {
if (context->currentHost() && context->query_) {
const ClientClasses& classes = context->currentHost()->getClientClasses4();
- for (ClientClasses::const_iterator cclass = classes.cbegin();
- cclass != classes.cend(); ++cclass) {
- context->query_->addClass(*cclass);
+ for (auto const& cclass : classes) {
+ context->query_->addClass(cclass);
}
}
}
@@ -587,23 +586,22 @@ void Dhcpv4Exchange::evaluateClasses(const Pkt4Ptr& pkt, bool depend_on_known) {
const ClientClassDictionaryPtr& dict =
CfgMgr::instance().getCurrentCfg()->getClientClassDictionary();
const ClientClassDefListPtr& defs_ptr = dict->getClasses();
- for (ClientClassDefList::const_iterator it = defs_ptr->cbegin();
- it != defs_ptr->cend(); ++it) {
+ for (auto const& it : *defs_ptr) {
// Note second cannot be null
- const ExpressionPtr& expr_ptr = (*it)->getMatchExpr();
+ const ExpressionPtr& expr_ptr = it->getMatchExpr();
// Nothing to do without an expression to evaluate
if (!expr_ptr) {
continue;
}
// Not the right time if only when required
- if ((*it)->getRequired()) {
+ if (it->getRequired()) {
continue;
}
// Not the right pass.
- if ((*it)->getDependOnKnown() != depend_on_known) {
+ if (it->getDependOnKnown() != depend_on_known) {
continue;
}
- (*it)->test(pkt, expr_ptr);
+ it->test(pkt, expr_ptr);
}
}
@@ -664,9 +662,9 @@ void Dhcpv4Srv::setPacketStatisticsDefaults() {
isc::stats::StatsMgr& stats_mgr = isc::stats::StatsMgr::instance();
// Iterate over set of observed statistics
- for (auto it = dhcp4_statistics.begin(); it != dhcp4_statistics.end(); ++it) {
+ for (auto const& it : dhcp4_statistics) {
// Initialize them with default value 0
- stats_mgr.setValue((*it), static_cast<int64_t>(0));
+ stats_mgr.setValue(it, static_cast<int64_t>(0));
}
}
@@ -827,7 +825,7 @@ Dhcpv4Srv::selectSubnet4o6(const Pkt4Ptr& query, bool& drop,
// Initialize fields specific to relayed messages.
if (query6 && !query6->relay_info_.empty()) {
- BOOST_REVERSE_FOREACH(Pkt6::RelayInfo relay, query6->relay_info_) {
+ for (auto const& relay : boost::adaptors::reverse(query6->relay_info_)) {
if (!relay.linkaddr_.isV6Zero() &&
!relay.linkaddr_.isV6LinkLocal()) {
selector.first_relay_linkaddr_ = relay.linkaddr_;
@@ -966,9 +964,8 @@ Dhcpv4Srv::earlyGHRLookup(const Pkt4Ptr& query,
// Add classes from the global reservations.
const ClientClasses& classes = global_host->getClientClasses4();
- for (ClientClasses::const_iterator cclass = classes.cbegin();
- cclass != classes.cend(); ++cclass) {
- query->addClass(*cclass);
+ for (auto const& cclass : classes) {
+ query->addClass(cclass);
}
// Evaluate classes before KNOWN.
@@ -1845,17 +1842,16 @@ Dhcpv4Srv::buildCfgOptionList(Dhcpv4Exchange& ex) {
// Each class in the incoming packet
const ClientClasses& classes = ex.getQuery()->getClasses();
- for (ClientClasses::const_iterator cclass = classes.cbegin();
- cclass != classes.cend(); ++cclass) {
+ for (auto const& cclass : classes) {
// Find the client class definition for this class
const ClientClassDefPtr& ccdef = CfgMgr::instance().getCurrentCfg()->
- getClientClassDictionary()->findClass(*cclass);
+ getClientClassDictionary()->findClass(cclass);
if (!ccdef) {
// Not found: the class is built-in or not configured
- if (!isClientClassBuiltIn(*cclass)) {
+ if (!isClientClassBuiltIn(cclass)) {
LOG_DEBUG(dhcp4_logger, DBG_DHCP4_BASIC, DHCP4_CLASS_UNCONFIGURED)
.arg(ex.getQuery()->getLabel())
- .arg(*cclass);
+ .arg(cclass);
}
// Skip it
continue;
@@ -1922,22 +1918,20 @@ Dhcpv4Srv::appendRequestedOptions(Dhcpv4Exchange& ex) {
// Get persistent options.
const OptionContainerPersistIndex& pidx = opts->get<2>();
const OptionContainerPersistRange& prange = pidx.equal_range(true);
- for (OptionContainerPersistIndex::const_iterator desc = prange.first;
- desc != prange.second; ++desc) {
+ BOOST_FOREACH(auto const& desc, prange) {
// Add the persistent option code to requested options.
- if (desc->option_) {
- uint8_t code = static_cast<uint8_t>(desc->option_->getType());
+ if (desc.option_) {
+ uint8_t code = static_cast<uint8_t>(desc.option_->getType());
static_cast<void>(requested_opts.insert(code));
}
}
// Get cancelled options.
const OptionContainerCancelIndex& cidx = opts->get<5>();
const OptionContainerCancelRange& crange = cidx.equal_range(true);
- for (OptionContainerCancelIndex::const_iterator desc = crange.first;
- desc != crange.second; ++desc) {
+ BOOST_FOREACH(auto const& desc, crange) {
// Add the cancelled option code to cancelled options.
- if (desc->option_) {
- uint8_t code = static_cast<uint8_t>(desc->option_->getType());
+ if (desc.option_) {
+ uint8_t code = static_cast<uint8_t>(desc.option_->getType());
static_cast<void>(cancelled_opts.insert(code));
}
}
@@ -2024,7 +2018,7 @@ Dhcpv4Srv::appendRequestedOptions(Dhcpv4Exchange& ex) {
// Iterate on the configured option list
for (auto const& copts : co_list) {
for (auto const& desc : copts->getList(DHCP4_OPTION_SPACE,
- DHO_VIVSO_SUBOPTIONS)) {
+ DHO_VIVSO_SUBOPTIONS)) {
if (!desc.option_) {
continue;
}
@@ -2153,11 +2147,10 @@ Dhcpv4Srv::appendRequestedVendorOptions(Dhcpv4Exchange& ex) {
// Get persistent options.
const OptionContainerPersistIndex& pidx = opts->get<2>();
const OptionContainerPersistRange& prange = pidx.equal_range(true);
- for (OptionContainerPersistIndex::const_iterator desc = prange.first;
- desc != prange.second; ++desc) {
+ BOOST_FOREACH(auto const& desc, prange) {
// Add the persistent option code to requested options.
- if (desc->option_) {
- uint8_t code = static_cast<uint8_t>(desc->option_->getType());
+ if (desc.option_) {
+ uint8_t code = static_cast<uint8_t>(desc.option_->getType());
static_cast<void>(requested_opts[vendor_id].insert(code));
}
}
@@ -2165,11 +2158,10 @@ Dhcpv4Srv::appendRequestedVendorOptions(Dhcpv4Exchange& ex) {
// Get cancelled options.
const OptionContainerCancelIndex& cidx = opts->get<5>();
const OptionContainerCancelRange& crange = cidx.equal_range(true);
- for (OptionContainerCancelIndex::const_iterator desc = crange.first;
- desc != crange.second; ++desc) {
+ BOOST_FOREACH(auto const& desc, crange) {
// Add the cancelled option code to cancelled options.
- if (desc->option_) {
- uint8_t code = static_cast<uint8_t>(desc->option_->getType());
+ if (desc.option_) {
+ uint8_t code = static_cast<uint8_t>(desc.option_->getType());
static_cast<void>(cancelled_opts.insert(code));
}
}
@@ -2762,9 +2754,9 @@ Dhcpv4Srv::assignLease(Dhcpv4Exchange& ex) {
// 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()) {
- lease = *l;
+ for (auto const& l : leases_client_id) {
+ if (l->subnet_id_ == s->getID()) {
+ lease = l;
break;
}
}
@@ -2790,9 +2782,9 @@ Dhcpv4Srv::assignLease(Dhcpv4Exchange& ex) {
// 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()) {
- lease = *l;
+ for (auto const& l : leases_hwaddr) {
+ if (l->subnet_id_ == s->getID()) {
+ lease = l;
break;
}
}
@@ -3400,10 +3392,13 @@ Dhcpv4Srv::setFixedFields(Dhcpv4Exchange& ex) {
string sname;
string filename;
size_t found_cnt = 0; // How many fields we have found.
- for (ClientClasses::const_iterator name = classes.cbegin();
- name != classes.cend() && found_cnt < 3; ++name) {
+ for (auto const& name : classes) {
+
+ if (found_cnt >= 3) {
+ break;
+ }
- ClientClassDefPtr cl = dict->findClass(*name);
+ ClientClassDefPtr cl = dict->findClass(name);
if (!cl) {
// Let's skip classes that don't have definitions. Currently
// these are automatic classes VENDOR_CLASS_something, but there
@@ -4365,11 +4360,10 @@ Dhcpv4Srv::acceptServerId(const Pkt4Ptr& query) const {
// Check if the server identifier is configured at client class level.
const ClientClasses& classes = query->getClasses();
- for (ClientClasses::const_iterator cclass = classes.cbegin();
- cclass != classes.cend(); ++cclass) {
+ for (auto const& cclass : classes) {
// Find the client class definition for this class
const ClientClassDefPtr& ccdef = CfgMgr::instance().getCurrentCfg()->
- getClientClassDictionary()->findClass(*cclass);
+ getClientClassDictionary()->findClass(cclass);
if (!ccdef) {
continue;
}
@@ -4453,17 +4447,15 @@ void Dhcpv4Srv::requiredClassify(Dhcpv4Exchange& ex) {
subnet->getSharedNetwork(network);
if (network) {
const ClientClasses& to_add = network->getRequiredClasses();
- for (ClientClasses::const_iterator cclass = to_add.cbegin();
- cclass != to_add.cend(); ++cclass) {
- classes.insert(*cclass);
+ for (auto const& cclass : to_add) {
+ classes.insert(cclass);
}
}
// Followed by the subnet
const ClientClasses& to_add = subnet->getRequiredClasses();
- for(ClientClasses::const_iterator cclass = to_add.cbegin();
- cclass != to_add.cend(); ++cclass) {
- classes.insert(*cclass);
+ for (auto const& cclass : to_add) {
+ classes.insert(cclass);
}
// And finish by the pool
@@ -4476,9 +4468,8 @@ void Dhcpv4Srv::requiredClassify(Dhcpv4Exchange& ex) {
PoolPtr pool = subnet->getPool(Lease::TYPE_V4, addr, false);
if (pool) {
const ClientClasses& to_add = pool->getRequiredClasses();
- for (ClientClasses::const_iterator cclass = to_add.cbegin();
- cclass != to_add.cend(); ++cclass) {
- classes.insert(*cclass);
+ for (auto const& cclass : to_add) {
+ classes.insert(cclass);
}
}
}
@@ -4490,19 +4481,18 @@ void Dhcpv4Srv::requiredClassify(Dhcpv4Exchange& ex) {
// Note getClientClassDictionary() cannot be null
const ClientClassDictionaryPtr& dict =
CfgMgr::instance().getCurrentCfg()->getClientClassDictionary();
- for (ClientClasses::const_iterator cclass = classes.cbegin();
- cclass != classes.cend(); ++cclass) {
- const ClientClassDefPtr class_def = dict->findClass(*cclass);
+ for (auto const& cclass : classes) {
+ const ClientClassDefPtr class_def = dict->findClass(cclass);
if (!class_def) {
LOG_DEBUG(dhcp4_logger, DBG_DHCP4_BASIC, DHCP4_CLASS_UNDEFINED)
- .arg(*cclass);
+ .arg(cclass);
continue;
}
const ExpressionPtr& expr_ptr = class_def->getMatchExpr();
// Nothing to do without an expression to evaluate
if (!expr_ptr) {
LOG_DEBUG(dhcp4_logger, DBG_DHCP4_BASIC, DHCP4_CLASS_UNTESTABLE)
- .arg(*cclass);
+ .arg(cclass);
continue;
}
// Evaluate the expression which can return false (no match),
@@ -4511,22 +4501,22 @@ void Dhcpv4Srv::requiredClassify(Dhcpv4Exchange& ex) {
bool status = evaluateBool(*expr_ptr, *query);
if (status) {
LOG_INFO(dhcp4_logger, EVAL_RESULT)
- .arg(*cclass)
+ .arg(cclass)
.arg("true");
// Matching: add the class
- query->addClass(*cclass);
+ query->addClass(cclass);
} else {
LOG_DEBUG(dhcp4_logger, DBG_DHCP4_DETAIL, EVAL_RESULT)
- .arg(*cclass)
+ .arg(cclass)
.arg("false");
}
} catch (const Exception& ex) {
LOG_ERROR(dhcp4_logger, EVAL_RESULT)
- .arg(*cclass)
+ .arg(cclass)
.arg(ex.what());
} catch (...) {
LOG_ERROR(dhcp4_logger, EVAL_RESULT)
- .arg(*cclass)
+ .arg(cclass)
.arg("get exception?");
}
}
@@ -4535,16 +4525,15 @@ void Dhcpv4Srv::requiredClassify(Dhcpv4Exchange& ex) {
void
Dhcpv4Srv::deferredUnpack(Pkt4Ptr& query) {
// Iterate on the list of deferred option codes
- BOOST_FOREACH(const uint16_t& code, query->getDeferredOptions()) {
+ for (auto const& code : query->getDeferredOptions()) {
OptionDefinitionPtr def;
// Iterate on client classes
const ClientClasses& classes = query->getClasses();
- for (ClientClasses::const_iterator cclass = classes.cbegin();
- cclass != classes.cend(); ++cclass) {
+ for (auto const& cclass : classes) {
// Get the client class definition for this class
const ClientClassDefPtr& ccdef =
CfgMgr::instance().getCurrentCfg()->
- getClientClassDictionary()->findClass(*cclass);
+ getClientClassDictionary()->findClass(cclass);
// If not found skip it
if (!ccdef) {
continue;
diff --git a/src/bin/dhcp4/json_config_parser.cc b/src/bin/dhcp4/json_config_parser.cc
index b26cfc4e05..a7bf06954e 100644
--- a/src/bin/dhcp4/json_config_parser.cc
+++ b/src/bin/dhcp4/json_config_parser.cc
@@ -45,7 +45,6 @@
#include <util/strutil.h>
#include <boost/algorithm/string.hpp>
-#include <boost/foreach.hpp>
#include <boost/lexical_cast.hpp>
#include <iomanip>
@@ -157,10 +156,10 @@ public:
}
// Let's go through all the networks one by one
- for (auto net = networks->begin(); net != networks->end(); ++net) {
+ for (auto const& net : *networks) {
// For each network go through all the subnets in it.
- const Subnet4SimpleCollection* subnets = (*net)->getAllSubnets();
+ const Subnet4SimpleCollection* subnets = net->getAllSubnets();
if (!subnets) {
// Shared network without subnets it weird, but we decided to
// accept such configurations.
@@ -168,8 +167,8 @@ public:
}
// For each subnet, add it to a list of regular subnets.
- for (auto subnet = subnets->begin(); subnet != subnets->end(); ++subnet) {
- dest->add(*subnet);
+ for (auto const& subnet : *subnets) {
+ dest->add(subnet);
}
}
}
@@ -216,61 +215,61 @@ public:
std::set<string> names;
// Let's go through all the networks one by one
- for (auto net = networks.begin(); net != networks.end(); ++net) {
+ for (auto const& net : networks) {
string txt;
// Let's check if all subnets have either the same interface
// or don't have the interface specified at all.
- bool authoritative = (*net)->getAuthoritative();
- string iface = (*net)->getIface();
+ bool authoritative = net->getAuthoritative();
+ string iface = net->getIface();
- const Subnet4SimpleCollection* subnets = (*net)->getAllSubnets();
+ const Subnet4SimpleCollection* subnets = net->getAllSubnets();
if (subnets) {
// For each subnet, add it to a list of regular subnets.
- for (auto subnet = subnets->begin(); subnet != subnets->end(); ++subnet) {
- if ((*subnet)->getAuthoritative() != authoritative) {
+ for (auto const& subnet : *subnets) {
+ if (subnet->getAuthoritative() != authoritative) {
isc_throw(DhcpConfigError, "Subnet " << boolalpha
- << (*subnet)->toText()
+ << subnet->toText()
<< " has different authoritative setting "
- << (*subnet)->getAuthoritative()
+ << subnet->getAuthoritative()
<< " than the shared-network itself: "
<< authoritative);
}
if (iface.empty()) {
- iface = (*subnet)->getIface();
+ iface = subnet->getIface();
continue;
}
- if ((*subnet)->getIface().empty()) {
+ if (subnet->getIface().empty()) {
continue;
}
- if ((*subnet)->getIface() != iface) {
- isc_throw(DhcpConfigError, "Subnet " << (*subnet)->toText()
- << " has specified interface " << (*subnet)->getIface()
+ if (subnet->getIface() != iface) {
+ isc_throw(DhcpConfigError, "Subnet " << subnet->toText()
+ << " has specified interface " << subnet->getIface()
<< ", but earlier subnet in the same shared-network"
<< " or the shared-network itself used " << iface);
}
// Let's collect the subnets in case we later find out the
// subnet doesn't have a mandatory name.
- txt += (*subnet)->toText() + " ";
+ txt += subnet->toText() + " ";
}
}
// Next, let's check name of the shared network.
- if ((*net)->getName().empty()) {
+ if (net->getName().empty()) {
isc_throw(DhcpConfigError, "Shared-network with subnets "
<< txt << " is missing mandatory 'name' parameter");
}
// Is it unique?
- if (names.find((*net)->getName()) != names.end()) {
+ if (names.find(net->getName()) != names.end()) {
isc_throw(DhcpConfigError, "A shared-network with "
- "name " << (*net)->getName() << " defined twice.");
+ "name " << net->getName() << " defined twice.");
}
- names.insert((*net)->getName());
+ names.insert(net->getName());
}
}
@@ -563,8 +562,8 @@ processDhcp4Config(isc::data::ConstElementPtr config_set) {
HostCollection hosts;
HostReservationsListParser<HostReservationParser4> parser;
parser.parse(SUBNET_ID_GLOBAL, reservations, hosts);
- for (auto h = hosts.begin(); h != hosts.end(); ++h) {
- srv_config->getCfgHosts()->add(*h);
+ for (auto const& h : hosts) {
+ srv_config->getCfgHosts()->add(h);
}
}
@@ -607,12 +606,10 @@ processDhcp4Config(isc::data::ConstElementPtr config_set) {
}
// Make parsers grouping.
- ConfigPair config_pair;
const std::map<std::string, ConstElementPtr>& values_map =
mutable_cfg->mapValue();
- BOOST_FOREACH(config_pair, values_map) {
-
+ for (auto const& config_pair : values_map) {
parameter_name = config_pair.first;
// These are converted to SimpleParser and are handled already above.
diff --git a/src/bin/dhcp4/tests/callout_library_3.cc b/src/bin/dhcp4/tests/callout_library_3.cc
index 6bd0fa3569..07faf51445 100644
--- a/src/bin/dhcp4/tests/callout_library_3.cc
+++ b/src/bin/dhcp4/tests/callout_library_3.cc
@@ -58,8 +58,8 @@ dhcp4_srv_configured(CalloutHandle& handle) {
// Append argument names.
std::vector<std::string> args = handle.getArgumentNames();
- for (auto arg = args.begin(); arg != args.end(); ++arg) {
- if (appendArgument(SRV_CONFIG_MARKER_FILE, arg->c_str()) != 0) {
+ for (auto const& arg : args) {
+ if (appendArgument(SRV_CONFIG_MARKER_FILE, arg.c_str()) != 0) {
return (1);
}
}
diff --git a/src/bin/dhcp4/tests/config_backend_unittest.cc b/src/bin/dhcp4/tests/config_backend_unittest.cc
index 5010177871..82fe4545f1 100644
--- a/src/bin/dhcp4/tests/config_backend_unittest.cc
+++ b/src/bin/dhcp4/tests/config_backend_unittest.cc
@@ -23,7 +23,6 @@
#include <dhcp4/tests/dhcp4_test_utils.h>
#include <dhcp4/tests/get_config_unittest.h>
-#include <boost/foreach.hpp>
#include <boost/scoped_ptr.hpp>
#include <iostream>
diff --git a/src/bin/dhcp4/tests/config_parser_unittest.cc b/src/bin/dhcp4/tests/config_parser_unittest.cc
index eb78dbbf76..bd5f2b361f 100644
--- a/src/bin/dhcp4/tests/config_parser_unittest.cc
+++ b/src/bin/dhcp4/tests/config_parser_unittest.cc
@@ -42,7 +42,6 @@
#include "dhcp4_test_utils.h"
#include "get_config_unittest.h"
-#include <boost/foreach.hpp>
#include <boost/scoped_ptr.hpp>
#include <iostream>
@@ -438,8 +437,7 @@ public:
" \"subnet\": \"192.0.2.0/24\", "
" \"option-data\": [ {";
bool first = true;
- typedef std::pair<std::string, std::string> ParamPair;
- BOOST_FOREACH(ParamPair param, params) {
+ for (auto const& param : params) {
if (!first) {
stream << ", ";
} else {
@@ -2365,18 +2363,16 @@ TEST_F(Dhcp4ParserTest, badSubnetValues) {
// Iterate over the list of scenarios. Each should fail to parse with
// a specific error message.
- for (auto scenario = scenarios.begin(); scenario != scenarios.end(); ++scenario) {
- {
- SCOPED_TRACE((*scenario).description_);
- ConstElementPtr config;
- ASSERT_NO_THROW(config = parseDHCP4((*scenario).config_json_))
- << "invalid json, broken test";
- ConstElementPtr status;
- EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, config));
- checkResult(status, 1);
- ASSERT_TRUE(comment_);
- EXPECT_EQ(comment_->stringValue(), (*scenario).exp_error_msg_);
- }
+ for (auto const& scenario : scenarios) {
+ SCOPED_TRACE(scenario.description_);
+ ConstElementPtr config;
+ ASSERT_NO_THROW(config = parseDHCP4(scenario.config_json_))
+ << "invalid json, broken test";
+ ConstElementPtr status;
+ EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, config));
+ checkResult(status, 1);
+ ASSERT_TRUE(comment_);
+ EXPECT_EQ(comment_->stringValue(), scenario.exp_error_msg_);
}
}
diff --git a/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc b/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc
index 14ffe8d4ff..12f2c3d1f5 100644
--- a/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc
+++ b/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc
@@ -667,13 +667,16 @@ TEST_F(CtrlChannelDhcpv4SrvTest, controlChannelStats) {
// preparing the schema which check if all statistics are set to zero
std::ostringstream s;
s << "{ \"arguments\": { ";
- for (auto st = initial_stats.begin(); st != initial_stats.end();) {
- s << "\"" << *st << "\": [ [ 0, \"";
- s << isc::util::clockToText(StatsMgr::instance().getObservation(*st)->getInteger().second);
- s << "\" ] ]";
- if (++st != initial_stats.end()) {
+ bool first = true;
+ for (auto const& st : initial_stats) {
+ if (!first) {
s << ", ";
+ } else {
+ first = false;
}
+ s << "\"" << st << "\": [ [ 0, \"";
+ s << isc::util::clockToText(StatsMgr::instance().getObservation(st)->getInteger().second);
+ s << "\" ] ]";
}
s << " }, \"result\": 0 }";
diff --git a/src/bin/dhcp4/tests/dhcp4_client.cc b/src/bin/dhcp4/tests/dhcp4_client.cc
index ae466aa97a..75efdcbe7a 100644
--- a/src/bin/dhcp4/tests/dhcp4_client.cc
+++ b/src/bin/dhcp4/tests/dhcp4_client.cc
@@ -137,9 +137,8 @@ Dhcp4Client::appendPRL() {
// has been specified to be requested.
OptionUint8ArrayPtr prl(new OptionUint8Array(Option::V4,
DHO_DHCP_PARAMETER_REQUEST_LIST));
- for (std::set<uint8_t>::const_iterator opt = requested_options_.begin();
- opt != requested_options_.end(); ++opt) {
- prl->addValue(*opt);
+ for (auto const& opt : requested_options_) {
+ prl->addValue(opt);
}
context_.query_->addOption(prl);
}
@@ -235,20 +234,18 @@ void
Dhcp4Client::appendExtraOptions() {
// If there are any custom options specified, add them all to the message.
if (!extra_options_.empty()) {
- for (OptionCollection::iterator opt = extra_options_.begin();
- opt != extra_options_.end(); ++opt) {
+ for (auto const& opt : extra_options_) {
// Call base class function so that unittests can add multiple
// options with the same code.
- context_.query_->Pkt::addOption(opt->second);
+ context_.query_->Pkt::addOption(opt.second);
}
}
}
void
Dhcp4Client::appendClasses() {
- for (ClientClasses::const_iterator cclass = classes_.cbegin();
- cclass != classes_.cend(); ++cclass) {
- context_.query_->addClass(*cclass);
+ for (auto const& cclass : classes_) {
+ context_.query_->addClass(cclass);
}
}
@@ -556,9 +553,8 @@ Dhcp4Client::sendMsg(const Pkt4Ptr& msg) {
msg_copy->setIndex(iface_index_);
// Copy classes
const ClientClasses& classes = msg->getClasses();
- for (ClientClasses::const_iterator cclass = classes.cbegin();
- cclass != classes.cend(); ++cclass) {
- msg_copy->addClass(*cclass);
+ for (auto const& cclass : classes) {
+ msg_copy->addClass(cclass);
}
srv_->fakeReceive(msg_copy);
diff --git a/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc b/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc
index 28d150b343..78aa950096 100644
--- a/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc
+++ b/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc
@@ -2898,7 +2898,7 @@ Dhcpv4SrvTest::loadConfigFile(const string& path) {
removeTlsParameters(hosts);
hosts = dhcp4->get("hosts-databases");
if (hosts) {
- for (auto& host : hosts->listValue()) {
+ for (auto const& host : hosts->listValue()) {
removeTlsParameters(host);
}
}
@@ -2991,7 +2991,7 @@ Dhcpv4SrvTest::checkConfigFiles() {
"with-ddns.json",
};
vector<string> files;
- for (const string& example : examples) {
+ for (auto const& example : examples) {
string file = path + "/" + example;
files.push_back(file);
}
diff --git a/src/bin/dhcp4/tests/hooks_unittest.cc b/src/bin/dhcp4/tests/hooks_unittest.cc
index 8ee1a8a3dc..b30b7d5682 100644
--- a/src/bin/dhcp4/tests/hooks_unittest.cc
+++ b/src/bin/dhcp4/tests/hooks_unittest.cc
@@ -3371,7 +3371,7 @@ TEST_F(LoadUnloadDhcpv4SrvTest, failLoadIncompatibleLibraries) {
// Checks if callouts installed on the dhcp4_srv_configured ared indeed called
// and all the necessary parameters are passed.
TEST_F(LoadUnloadDhcpv4SrvTest, Dhcpv4SrvConfigured) {
- for (const string& parameters : vector<string>{
+ for (auto const& parameters : vector<string>{
"",
R"(, "parameters": { "mode": "fail-without-error" } )",
R"(, "parameters": { "mode": "fail-with-error" } )"}) {
diff --git a/src/bin/dhcp4/tests/shared_network_unittest.cc b/src/bin/dhcp4/tests/shared_network_unittest.cc
index bf5964dc1e..6cda3aabf2 100644
--- a/src/bin/dhcp4/tests/shared_network_unittest.cc
+++ b/src/bin/dhcp4/tests/shared_network_unittest.cc
@@ -1165,10 +1165,9 @@ public:
Subnet4Ptr getConfiguredSubnet(const IOAddress& address) {
CfgSubnets4Ptr cfg = CfgMgr::instance().getCurrentCfg()->getCfgSubnets4();
const Subnet4Collection* subnets = cfg->getAll();
- for (auto subnet_it = subnets->cbegin(); subnet_it != subnets->cend();
- ++subnet_it) {
- if ((*subnet_it)->inRange(address)) {
- return (*subnet_it);
+ for (auto const& subnet_it : *subnets) {
+ if (subnet_it->inRange(address)) {
+ return (subnet_it);
}
}
return (Subnet4Ptr());