diff options
author | Razvan Becheriu <razvan@isc.org> | 2024-01-12 15:31:50 +0100 |
---|---|---|
committer | Razvan Becheriu <razvan@isc.org> | 2024-01-22 16:49:59 +0100 |
commit | 1b4d7b0293bca6657d1f798e6e4e65ce95d2dca4 (patch) | |
tree | fc89d85f5dd097dd85a2921ce1382980e012a423 /src/bin | |
parent | [#3119] replace const auto with auto const (diff) | |
download | kea-1b4d7b0293bca6657d1f798e6e4e65ce95d2dca4.tar.xz kea-1b4d7b0293bca6657d1f798e6e4e65ce95d2dca4.zip |
[#3119] use range based for loop or BOOST_FOREACH
Diffstat (limited to 'src/bin')
36 files changed, 481 insertions, 575 deletions
diff --git a/src/bin/agent/ca_cfg_mgr.cc b/src/bin/agent/ca_cfg_mgr.cc index f2f8caa92a..cda267f78a 100644 --- a/src/bin/agent/ca_cfg_mgr.cc +++ b/src/bin/agent/ca_cfg_mgr.cc @@ -77,8 +77,8 @@ CtrlAgentCfgMgr::getConfigSummary(const uint32_t /*selection*/) { // Finally, print the hook libraries names const isc::hooks::HookLibsCollection libs = ctx->getHooksConfig().get(); s << ", " << libs.size() << " lib(s):"; - for (auto lib = libs.begin(); lib != libs.end(); ++lib) { - s << lib->first << " "; + for (auto const& lib : libs) { + s << lib.first << " "; } return (s.str()); @@ -163,11 +163,11 @@ CtrlAgentCfgContext::setControlSocketInfo(const ConstElementPtr& control_socket, std::string CtrlAgentCfgContext::getControlSocketInfoSummary() const { std::ostringstream s; - for (auto si = ctrl_sockets_.cbegin(); si != ctrl_sockets_.end(); ++si) { + for (auto const& si : ctrl_sockets_) { if (s.tellp() != 0) { s << " "; } - s << si->first; + s << si.first; } if (s.tellp() == 0) { @@ -200,9 +200,9 @@ CtrlAgentCfgContext::toElement() const { ca->set("hooks-libraries", hooks_config_.toElement()); // Set control-sockets ElementPtr control_sockets = Element::createMap(); - for (auto si = ctrl_sockets_.cbegin(); si != ctrl_sockets_.cend(); ++si) { - ConstElementPtr socket = UserContext::toElement(si->second); - control_sockets->set(si->first, socket); + for (auto const& si : ctrl_sockets_) { + ConstElementPtr socket = UserContext::toElement(si.second); + control_sockets->set(si.first, socket); } ca->set("control-sockets", control_sockets); // Set Control-agent diff --git a/src/bin/agent/ca_process.cc b/src/bin/agent/ca_process.cc index 3a3cebae90..1e42503065 100644 --- a/src/bin/agent/ca_process.cc +++ b/src/bin/agent/ca_process.cc @@ -201,9 +201,7 @@ CtrlAgentProcess::garbageCollectListeners(size_t leaving) { // listeners except the most recently added. if (http_listeners_.size() > leaving) { // Stop no longer used listeners. - for (auto l = http_listeners_.begin(); - l != http_listeners_.end() - leaving; - ++l) { + for (auto l = http_listeners_.begin(); l != http_listeners_.end() - leaving; ++l) { (*l)->stop(); } // We have stopped listeners but there may be some pending handlers @@ -215,7 +213,6 @@ CtrlAgentProcess::garbageCollectListeners(size_t leaving) { } } - CtrlAgentCfgMgrPtr CtrlAgentProcess::getCtrlAgentCfgMgr() { return (boost::dynamic_pointer_cast<CtrlAgentCfgMgr>(getCfgMgr())); diff --git a/src/bin/agent/simple_parser.cc b/src/bin/agent/simple_parser.cc index 9c863656d6..b340d46530 100644 --- a/src/bin/agent/simple_parser.cc +++ b/src/bin/agent/simple_parser.cc @@ -12,7 +12,6 @@ #include <hooks/hooks_manager.h> #include <hooks/hooks_parser.h> #include <http/basic_auth_config.h> -#include <boost/foreach.hpp> using namespace isc::data; @@ -147,8 +146,8 @@ AgentSimpleParser::parse(const CtrlAgentCfgContextPtr& ctx, ConstElementPtr ctrl_sockets = config->get("control-sockets"); if (ctrl_sockets) { auto const& sockets_map = ctrl_sockets->mapValue(); - for (auto cs = sockets_map.cbegin(); cs != sockets_map.cend(); ++cs) { - ctx->setControlSocketInfo(cs->second, cs->first); + for (auto const& cs : sockets_map) { + ctx->setControlSocketInfo(cs.second, cs.first); } } diff --git a/src/bin/agent/tests/ca_command_mgr_unittests.cc b/src/bin/agent/tests/ca_command_mgr_unittests.cc index 939e55f063..6a71a2af81 100644 --- a/src/bin/agent/tests/ca_command_mgr_unittests.cc +++ b/src/bin/agent/tests/ca_command_mgr_unittests.cc @@ -94,14 +94,14 @@ public: std::vector<ElementPtr> answer_list = answer->listValue(); ASSERT_EQ(expected_codes.size(), answer_list.size()); + size_t count = 0; // Check all answers. - for (auto ans = answer_list.cbegin(); ans != answer_list.cend(); - ++ans) { + for (auto const& ans : answer_list) { ConstElementPtr text; - ASSERT_NO_THROW(text = isc::config::parseAnswer(status_code, *ans)); - EXPECT_EQ(expected_codes[std::distance(answer_list.cbegin(), ans)], - status_code) + ASSERT_NO_THROW(text = isc::config::parseAnswer(status_code, ans)); + EXPECT_EQ(expected_codes[count], status_code) << "answer contains text: " << text->stringValue(); + count++; } } diff --git a/src/bin/d2/tests/d2_cfg_mgr_unittests.cc b/src/bin/d2/tests/d2_cfg_mgr_unittests.cc index e00afae840..aad7e09757 100644 --- a/src/bin/d2/tests/d2_cfg_mgr_unittests.cc +++ b/src/bin/d2/tests/d2_cfg_mgr_unittests.cc @@ -17,7 +17,6 @@ #include <test_data_files_config.h> #include <util/encode/base64.h> -#include <boost/foreach.hpp> #include <boost/scoped_ptr.hpp> #include <gtest/gtest.h> @@ -583,8 +582,7 @@ TEST_F(D2CfgMgrTest, fullConfig) { // NOTE that since prior tests have validated server parsing, we are are // assuming that the servers did in fact parse correctly if the correct // number of them are there. - DdnsDomainMapPair domain_pair; - BOOST_FOREACH(domain_pair, (*domains)) { + for (auto const& domain_pair : *domains) { DdnsDomainPtr domain = domain_pair.second; DnsServerInfoStoragePtr servers = domain->getServers(); count = servers->size(); @@ -606,7 +604,7 @@ TEST_F(D2CfgMgrTest, fullConfig) { // NOTE that since prior tests have validated server parsing, we are are // assuming that the servers did in fact parse correctly if the correct // number of them are there. - BOOST_FOREACH(domain_pair, (*domains)) { + for (auto const& domain_pair : *domains) { DdnsDomainPtr domain = domain_pair.second; DnsServerInfoStoragePtr servers = domain->getServers(); count = servers->size(); @@ -933,7 +931,7 @@ TEST_F(D2CfgMgrTest, configPermutations) { // 5. submit JSON for parsing isc::data::ConstElementPtr test; ASSERT_TRUE(tests->get("test-list")); - BOOST_FOREACH(test, tests->get("test-list")->listValue()) { + for (auto const& test : tests->get("test-list")->listValue()) { // Grab the description. std::string description = "<no desc>"; isc::data::ConstElementPtr elem = test->get("description"); diff --git a/src/bin/d2/tests/d2_simple_parser_unittest.cc b/src/bin/d2/tests/d2_simple_parser_unittest.cc index b236469cb9..682908a083 100644 --- a/src/bin/d2/tests/d2_simple_parser_unittest.cc +++ b/src/bin/d2/tests/d2_simple_parser_unittest.cc @@ -277,7 +277,7 @@ TEST_F(D2SimpleParserTest, globalD2Defaults) { EXPECT_EQ(num, 8); // Let's go over all parameters we have defaults for. - BOOST_FOREACH(SimpleDefault deflt, D2SimpleParser::D2_GLOBAL_DEFAULTS) { + for (auto const& deflt : D2SimpleParser::D2_GLOBAL_DEFAULTS) { ConstElementPtr x; ASSERT_NO_THROW(x = empty->get(deflt.name_)); @@ -569,7 +569,7 @@ public: size_t cnt = 0; // We don't use SimpleParser::setListDefaults() as this does // not handle sub-lists or sub-maps - BOOST_FOREACH(ElementPtr domain, config->listValue()) { + for (auto const& domain : config->listValue()) { cnt += D2SimpleParser:: setDdnsDomainDefaults(domain, D2SimpleParser:: DDNS_DOMAIN_DEFAULTS); 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()); diff --git a/src/bin/dhcp6/dhcp6_srv.cc b/src/bin/dhcp6/dhcp6_srv.cc index a7e7379581..b415ed596f 100644 --- a/src/bin/dhcp6/dhcp6_srv.cc +++ b/src/bin/dhcp6/dhcp6_srv.cc @@ -63,8 +63,8 @@ #endif #include <dhcpsrv/memfile_lease_mgr.h> -#include <boost/foreach.hpp> #include <boost/tokenizer.hpp> +#include <boost/foreach.hpp> #include <boost/algorithm/string/erase.hpp> #include <boost/algorithm/string/join.hpp> #include <boost/algorithm/string/split.hpp> @@ -261,9 +261,9 @@ void Dhcpv6Srv::setPacketStatisticsDefaults() { isc::stats::StatsMgr& stats_mgr = isc::stats::StatsMgr::instance(); // Iterate over set of observed statistics - for (auto it = dhcp6_statistics.begin(); it != dhcp6_statistics.end(); ++it) { + for (auto const& it : dhcp6_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)); } } @@ -364,8 +364,7 @@ void Dhcpv6Srv::setHostIdentifiers(AllocEngine::ClientContext6& ctx) { const ConstCfgHostOperationsPtr cfg = CfgMgr::instance().getCurrentCfg()->getCfgHostOperations6(); - BOOST_FOREACH(const Host::IdentifierType& id_type, - cfg->getIdentifierTypes()) { + for (auto const& id_type : cfg->getIdentifierTypes()) { switch (id_type) { case Host::IDENT_DUID: if (ctx.duid_) { @@ -455,9 +454,8 @@ Dhcpv6Srv::earlyGHRLookup(const Pkt6Ptr& query, // Add classes from the global reservations. const ClientClasses& classes = global_host->getClientClasses6(); - 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. @@ -1378,11 +1376,11 @@ Dhcpv6Srv::duidToString(const OptionPtr& opt) { OptionBuffer data = opt->getData(); bool colon = false; - for (OptionBufferConstIter it = data.begin(); it != data.end(); ++it) { + for (auto const& it : data) { if (colon) { tmp << ":"; } - tmp << hex << setw(2) << setfill('0') << static_cast<uint16_t>(*it); + tmp << hex << setw(2) << setfill('0') << static_cast<uint16_t>(it); if (!colon) { colon = true; } @@ -1452,17 +1450,16 @@ Dhcpv6Srv::buildCfgOptionList(const Pkt6Ptr& question, // Each class in the incoming packet const ClientClasses& classes = question->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(dhcp6_logger, DBG_DHCP6_BASIC, DHCP6_CLASS_UNCONFIGURED) .arg(question->getLabel()) - .arg(*cclass); + .arg(cclass); } // Skip it continue; @@ -1516,22 +1513,20 @@ Dhcpv6Srv::appendRequestedOptions(const Pkt6Ptr& question, Pkt6Ptr& answer, // 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_) { - uint16_t code = desc->option_->getType(); + if (desc.option_) { + uint16_t code = 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 the cancelled options. - if (desc->option_) { - uint16_t code = desc->option_->getType(); + if (desc.option_) { + uint16_t code = desc.option_->getType(); static_cast<void>(cancelled_opts.insert(code)); } } @@ -1741,25 +1736,23 @@ Dhcpv6Srv::appendRequestedVendorOptions(const Pkt6Ptr& question, // 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) { - if (!desc->option_) { + BOOST_FOREACH(auto const& desc, prange) { + if (!desc.option_) { continue; } // Add the persistent option code to requested options - uint16_t code = desc->option_->getType(); + uint16_t code = desc.option_->getType(); static_cast<void>(requested_opts[vendor_id].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) { - if (!desc->option_) { + BOOST_FOREACH(auto const& desc, crange) { + if (!desc.option_) { continue; } // Add the cancelled option code to cancelled options - uint16_t code = desc->option_->getType(); + uint16_t code = desc.option_->getType(); static_cast<void>(cancelled_opts[vendor_id].insert(code)); } } @@ -2254,22 +2247,21 @@ Dhcpv6Srv::createNameChangeRequests(const Pkt6Ptr& answer, // to determine if the changes included changes to the FQDN. If so // then we may need to do a CHG_REMOVE. bool extended_only = false; - for (Lease6Collection::const_iterator l = ctx.currentIA().changed_leases_.begin(); - l != ctx.currentIA().changed_leases_.end(); ++l) { + for (auto const& l : ctx.currentIA().changed_leases_) { - if ((*l)->addr_ == iaaddr->getAddress()) { + if (l->addr_ == iaaddr->getAddress()) { // The address is the same so this must be renewal. If we're not // always updating on renew, then we only renew if DNS info has // changed. if (!ctx.getDdnsParams()->getUpdateOnRenew() && - ((*l)->hostname_ == opt_fqdn->getDomainName() && - (*l)->fqdn_fwd_ == do_fwd && (*l)->fqdn_rev_ == do_rev)) { + (l->hostname_ == opt_fqdn->getDomainName() && + l->fqdn_fwd_ == do_fwd && l->fqdn_rev_ == do_rev)) { extended_only = true; } else { // Queue a CHG_REMOVE of the old data. // NCR will only be created if the lease hostname is not // empty and at least one of the direction flags is true - queueNCR(CHG_REMOVE, *l); + queueNCR(CHG_REMOVE, l); } break; @@ -2317,9 +2309,8 @@ Dhcpv6Srv::getMAC(const Pkt6Ptr& pkt) { CfgMACSources mac_sources = CfgMgr::instance().getCurrentCfg()-> getMACSources().get(); HWAddrPtr hwaddr; - for (CfgMACSources::const_iterator it = mac_sources.begin(); - it != mac_sources.end(); ++it) { - hwaddr = pkt->getMAC(*it); + for (auto const& it : mac_sources) { + hwaddr = pkt->getMAC(it); if (hwaddr) { return (hwaddr); } @@ -2537,57 +2528,56 @@ Dhcpv6Srv::assignIA_PD(const Pkt6Ptr& query, uint32_t min_preferred_lft = (*leases.begin())->preferred_lft_; const bool pd_exclude_requested = requestedInORO(query, D6O_PD_EXCLUDE); - for (Lease6Collection::iterator l = leases.begin(); - l != leases.end(); ++l) { + for (auto const& l : leases) { // We have a lease! Let's wrap its content into IA_PD option // with IAADDR suboption. if (ctx.fake_allocation_) { LOG_INFO(lease6_logger, DHCP6_PD_LEASE_ADVERT) .arg(query->getLabel()) - .arg((*l)->addr_.toText()) - .arg(static_cast<int>((*l)->prefixlen_)) + .arg(l->addr_.toText()) + .arg(static_cast<int>(l->prefixlen_)) .arg(ia->getIAID()); - } else if ((*l)->reuseable_valid_lft_ == 0) { + } else if (l->reuseable_valid_lft_ == 0) { LOG_INFO(lease6_logger, DHCP6_PD_LEASE_ALLOC) .arg(query->getLabel()) - .arg((*l)->addr_.toText()) - .arg(static_cast<int>((*l)->prefixlen_)) + .arg(l->addr_.toText()) + .arg(static_cast<int>(l->prefixlen_)) .arg(ia->getIAID()) - .arg(Lease::lifetimeToText((*l)->valid_lft_)); + .arg(Lease::lifetimeToText(l->valid_lft_)); } else { - (*l)->valid_lft_ = (*l)->reuseable_valid_lft_; - (*l)->preferred_lft_ = (*l)->reuseable_preferred_lft_; + l->valid_lft_ = l->reuseable_valid_lft_; + l->preferred_lft_ = l->reuseable_preferred_lft_; LOG_INFO(lease6_logger, DHCP6_PD_LEASE_REUSE) .arg(query->getLabel()) - .arg((*l)->addr_.toText()) - .arg(static_cast<int>((*l)->prefixlen_)) + .arg(l->addr_.toText()) + .arg(static_cast<int>(l->prefixlen_)) .arg(ia->getIAID()) - .arg(Lease::lifetimeToText((*l)->valid_lft_)); + .arg(Lease::lifetimeToText(l->valid_lft_)); // Increment the reuse statistics. StatsMgr::instance().addValue("v6-ia-pd-lease-reuses", int64_t(1)); - StatsMgr::instance().addValue(StatsMgr::generateName("subnet", (*l)->subnet_id_, + StatsMgr::instance().addValue(StatsMgr::generateName("subnet", l->subnet_id_, "v6-ia-pd-lease-reuses"), int64_t(1)); } // Check for new minimum lease time - if (((*l)->preferred_lft_ > 0) && (min_preferred_lft > (*l)->preferred_lft_)) { - min_preferred_lft = (*l)->preferred_lft_; + if ((l->preferred_lft_ > 0) && (min_preferred_lft > l->preferred_lft_)) { + min_preferred_lft = l->preferred_lft_; } boost::shared_ptr<Option6IAPrefix> - addr(new Option6IAPrefix(D6O_IAPREFIX, (*l)->addr_, - (*l)->prefixlen_, (*l)->preferred_lft_, - (*l)->valid_lft_)); + addr(new Option6IAPrefix(D6O_IAPREFIX, l->addr_, + l->prefixlen_, l->preferred_lft_, + l->valid_lft_)); ia_rsp->addOption(addr); if (pd_exclude_requested) { // PD exclude option has been requested via ORO, thus we need to // include it if the pool configuration specifies this option. Pool6Ptr pool = boost::dynamic_pointer_cast< - Pool6>(subnet->getPool(Lease::TYPE_PD, (*l)->addr_)); + Pool6>(subnet->getPool(Lease::TYPE_PD, l->addr_)); if (pool) { Option6PDExcludePtr pd_exclude_option = pool->getPrefixExcludeOption(); if (pd_exclude_option) { @@ -2660,12 +2650,11 @@ Dhcpv6Srv::extendIA_NA(const Pkt6Ptr& query, // Extract the addresses that the client is trying to obtain. OptionCollection addrs = ia->getOptions(); - for (OptionCollection::const_iterator it = addrs.begin(); - it != addrs.end(); ++it) { - if (it->second->getType() != D6O_IAADDR) { + for (auto const& it : addrs) { + if (it.second->getType() != D6O_IAADDR) { continue; } - Option6IAAddrPtr iaaddr = boost::dynamic_pointer_cast<Option6IAAddr>(it->second); + Option6IAAddrPtr iaaddr = boost::dynamic_pointer_cast<Option6IAAddr>(it.second); if (!iaaddr) { // That's weird. Option code was ok, but the object type was not. // This should never happen. The only case would be with badly @@ -2695,82 +2684,80 @@ Dhcpv6Srv::extendIA_NA(const Pkt6Ptr& query, uint32_t min_preferred_lft = std::numeric_limits<uint32_t>::max(); // For all leases we have now, add the IAADDR with non-zero lifetimes. - for (Lease6Collection::iterator l = leases.begin(); l != leases.end(); ++l) { - if ((*l)->reuseable_valid_lft_ == 0) { + for (auto const& l : leases) { + if (l->reuseable_valid_lft_ == 0) { LOG_INFO(lease6_logger, DHCP6_LEASE_RENEW) .arg(query->getLabel()) - .arg((*l)->addr_.toText()) + .arg(l->addr_.toText()) .arg(ia->getIAID()); } else { - (*l)->valid_lft_ = (*l)->reuseable_valid_lft_; - (*l)->preferred_lft_ = (*l)->reuseable_preferred_lft_; + l->valid_lft_ = l->reuseable_valid_lft_; + l->preferred_lft_ = l->reuseable_preferred_lft_; LOG_INFO(lease6_logger, DHCP6_LEASE_REUSE) .arg(query->getLabel()) - .arg((*l)->addr_.toText()) + .arg(l->addr_.toText()) .arg(ia->getIAID()) - .arg(Lease::lifetimeToText((*l)->valid_lft_)); + .arg(Lease::lifetimeToText(l->valid_lft_)); // Increment the reuse statistics. StatsMgr::instance().addValue("v6-ia-na-lease-reuses", int64_t(1)); - StatsMgr::instance().addValue(StatsMgr::generateName("subnet", (*l)->subnet_id_, + StatsMgr::instance().addValue(StatsMgr::generateName("subnet", l->subnet_id_, "v6-ia-na-lease-reuses"), int64_t(1)); } Option6IAAddrPtr iaaddr(new Option6IAAddr(D6O_IAADDR, - (*l)->addr_, (*l)->preferred_lft_, (*l)->valid_lft_)); + l->addr_, l->preferred_lft_, l->valid_lft_)); ia_rsp->addOption(iaaddr); // Check for new minimum lease time - if (((*l)->preferred_lft_ > 0) && (min_preferred_lft > (*l)->preferred_lft_)) { - min_preferred_lft = (*l)->preferred_lft_; + if ((l->preferred_lft_ > 0) && (min_preferred_lft > l->preferred_lft_)) { + min_preferred_lft = l->preferred_lft_; } // Now remove this address from the hints list. - AllocEngine::Resource hint_type((*l)->addr_); + AllocEngine::Resource hint_type(l->addr_); hints.erase(std::remove(hints.begin(), hints.end(), hint_type), hints.end()); } // For the leases that we just retired, send the addresses with 0 lifetimes. - for (Lease6Collection::iterator l = ctx.currentIA().old_leases_.begin(); - l != ctx.currentIA().old_leases_.end(); ++l) { + for (auto const& l : ctx.currentIA().old_leases_) { // Send an address with zero lifetimes only when this lease belonged to // this client. Do not send it when we're reusing an old lease that belonged // to someone else. - if (equalValues(query->getClientId(), (*l)->duid_)) { + if (equalValues(query->getClientId(), l->duid_)) { Option6IAAddrPtr iaaddr(new Option6IAAddr(D6O_IAADDR, - (*l)->addr_, 0, 0)); + l->addr_, 0, 0)); ia_rsp->addOption(iaaddr); } // Now remove this address from the hints list. - AllocEngine::Resource hint_type((*l)->addr_); + AllocEngine::Resource hint_type(l->addr_); hints.erase(std::remove(hints.begin(), hints.end(), hint_type), hints.end()); // If the new FQDN settings have changed for the lease, we need to // delete any existing FQDN records for this lease. - if (((*l)->hostname_ != ctx.hostname_) || ((*l)->fqdn_fwd_ != ctx.fwd_dns_update_) || - ((*l)->fqdn_rev_ != ctx.rev_dns_update_)) { + if ((l->hostname_ != ctx.hostname_) || (l->fqdn_fwd_ != ctx.fwd_dns_update_) || + (l->fqdn_rev_ != ctx.rev_dns_update_)) { LOG_DEBUG(ddns6_logger, DBG_DHCP6_DETAIL, DHCP6_DDNS_REMOVE_OLD_LEASE_FQDN) .arg(query->getLabel()) - .arg((*l)->toText()) + .arg(l->toText()) .arg(ctx.hostname_) .arg(ctx.rev_dns_update_ ? "true" : "false") .arg(ctx.fwd_dns_update_ ? "true" : "false"); - queueNCR(CHG_REMOVE, *l); + queueNCR(CHG_REMOVE, l); } } // Finally, if there are any addresses requested that we haven't dealt with // already, inform the client that he can't have them. - for (AllocEngine::HintContainer::const_iterator hint = hints.begin(); - hint != hints.end(); ++hint) { + for (auto const& hint : hints) { Option6IAAddrPtr iaaddr(new Option6IAAddr(D6O_IAADDR, - hint->getAddress(), 0, 0)); + hint.getAddress(), 0, 0)); ia_rsp->addOption(iaaddr); } @@ -2848,12 +2835,11 @@ Dhcpv6Srv::extendIA_PD(const Pkt6Ptr& query, // Extract prefixes that the client is trying to renew. OptionCollection addrs = ia->getOptions(); - for (OptionCollection::const_iterator it = addrs.begin(); - it != addrs.end(); ++it) { - if (it->second->getType() != D6O_IAPREFIX) { + for (auto const& it : addrs) { + if (it.second->getType() != D6O_IAPREFIX) { continue; } - Option6IAPrefixPtr prf = boost::dynamic_pointer_cast<Option6IAPrefix>(it->second); + Option6IAPrefixPtr prf = boost::dynamic_pointer_cast<Option6IAPrefix>(it.second); if (!prf) { // That's weird. Option code was ok, but the object type was not. // This should never happen. The only case would be with badly @@ -2889,40 +2875,40 @@ Dhcpv6Srv::extendIA_PD(const Pkt6Ptr& query, // for calculating T1 and T2. uint32_t min_preferred_lft = std::numeric_limits<uint32_t>::max(); - for (Lease6Collection::iterator l = leases.begin(); l != leases.end(); ++l) { - if ((*l)->reuseable_valid_lft_ == 0) { + for (auto const& l : leases) { + if (l->reuseable_valid_lft_ == 0) { LOG_INFO(lease6_logger, DHCP6_PD_LEASE_RENEW) .arg(query->getLabel()) - .arg((*l)->addr_.toText()) - .arg(static_cast<int>((*l)->prefixlen_)) + .arg(l->addr_.toText()) + .arg(static_cast<int>(l->prefixlen_)) .arg(ia->getIAID()); } else { - (*l)->valid_lft_ = (*l)->reuseable_valid_lft_; - (*l)->preferred_lft_ = (*l)->reuseable_preferred_lft_; + l->valid_lft_ = l->reuseable_valid_lft_; + l->preferred_lft_ = l->reuseable_preferred_lft_; LOG_INFO(lease6_logger, DHCP6_PD_LEASE_REUSE) .arg(query->getLabel()) - .arg((*l)->addr_.toText()) - .arg(static_cast<int>((*l)->prefixlen_)) + .arg(l->addr_.toText()) + .arg(static_cast<int>(l->prefixlen_)) .arg(ia->getIAID()) - .arg(Lease::lifetimeToText((*l)->valid_lft_)); + .arg(Lease::lifetimeToText(l->valid_lft_)); // Increment the reuse statistics. StatsMgr::instance().addValue("v6-ia-pd-lease-reuses", int64_t(1)); - StatsMgr::instance().addValue(StatsMgr::generateName("subnet", (*l)->subnet_id_, + StatsMgr::instance().addValue(StatsMgr::generateName("subnet", l->subnet_id_, "v6-ia-pd-lease-reuses"), int64_t(1)); } Option6IAPrefixPtr prf(new Option6IAPrefix(D6O_IAPREFIX, - (*l)->addr_, (*l)->prefixlen_, - (*l)->preferred_lft_, (*l)->valid_lft_)); + l->addr_, l->prefixlen_, + l->preferred_lft_, l->valid_lft_)); ia_rsp->addOption(prf); if (pd_exclude_requested) { // PD exclude option has been requested via ORO, thus we need to // include it if the pool configuration specifies this option. Pool6Ptr pool = boost::dynamic_pointer_cast< - Pool6>(subnet->getPool(Lease::TYPE_PD, (*l)->addr_)); + Pool6>(subnet->getPool(Lease::TYPE_PD, l->addr_)); if (pool) { Option6PDExcludePtr pd_exclude_option = pool->getPrefixExcludeOption(); @@ -2933,46 +2919,44 @@ Dhcpv6Srv::extendIA_PD(const Pkt6Ptr& query, } // Check for new minimum lease time - if (((*l)->preferred_lft_ > 0) && ((*l)->preferred_lft_ < min_preferred_lft)) { - min_preferred_lft = (*l)->preferred_lft_; + if ((l->preferred_lft_ > 0) && (l->preferred_lft_ < min_preferred_lft)) { + min_preferred_lft = l->preferred_lft_; } // Now remove this prefix from the hints list. - AllocEngine::Resource hint_type((*l)->addr_, (*l)->prefixlen_); + AllocEngine::Resource hint_type(l->addr_, l->prefixlen_); hints.erase(std::remove(hints.begin(), hints.end(), hint_type), hints.end()); } /// For the leases that we just retired, send the prefixes with 0 lifetimes. - for (Lease6Collection::iterator l = ctx.currentIA().old_leases_.begin(); - l != ctx.currentIA().old_leases_.end(); ++l) { + for (auto const& l : ctx.currentIA().old_leases_) { // Send a prefix with zero lifetimes only when this lease belonged to // this client. Do not send it when we're reusing an old lease that belonged // to someone else. - if (equalValues(query->getClientId(), (*l)->duid_)) { - Option6IAPrefixPtr prefix(new Option6IAPrefix(D6O_IAPREFIX, (*l)->addr_, - (*l)->prefixlen_, 0, 0)); + if (equalValues(query->getClientId(), l->duid_)) { + Option6IAPrefixPtr prefix(new Option6IAPrefix(D6O_IAPREFIX, l->addr_, + l->prefixlen_, 0, 0)); ia_rsp->addOption(prefix); } // Now remove this prefix from the hints list. - AllocEngine::Resource hint_type((*l)->addr_, (*l)->prefixlen_); + AllocEngine::Resource hint_type(l->addr_, l->prefixlen_); hints.erase(std::remove(hints.begin(), hints.end(), hint_type), hints.end()); } // Finally, if there are any prefixes requested that we haven't dealt with // already, inform the client that he can't have them. - for (AllocEngine::HintContainer::const_iterator prefix = hints.begin(); - prefix != hints.end(); ++prefix) { + for (auto const& prefix : hints) { // Send the prefix with the zero lifetimes only if the prefix // contains non-zero value. A zero value indicates that the hint was // for the prefix length. - if (!prefix->getAddress().isV6Zero()) { + if (!prefix.getAddress().isV6Zero()) { OptionPtr prefix_opt(new Option6IAPrefix(D6O_IAPREFIX, - prefix->getAddress(), - prefix->getPrefixLength(), + prefix.getAddress(), + prefix.getPrefixLength(), 0, 0)); ia_rsp->addOption(prefix_opt); } @@ -3741,16 +3725,14 @@ Dhcpv6Srv::processConfirm(AllocEngine::ClientContext6& ctx) { // over the IA_NA options to check if they hold any addresses. If there // are no, the Confirm is discarded. // Check addresses in IA_NA options and make sure they are appropriate. - for (OptionCollection::const_iterator ia = ias.begin(); - ia != ias.end(); ++ia) { - const OptionCollection& opts = ia->second->getOptions(); - for (OptionCollection::const_iterator opt = opts.begin(); - opt != opts.end(); ++opt) { + for (auto const& ia : ias) { + const OptionCollection& opts = ia.second->getOptions(); + for (auto const& opt : opts) { // Ignore options other than IAAddr. - if (opt->second->getType() == D6O_IAADDR) { + if (opt.second->getType() == D6O_IAADDR) { // Check that the address is in range in the subnet selected. Option6IAAddrPtr iaaddr = boost::dynamic_pointer_cast< - Option6IAAddr>(opt->second); + Option6IAAddr>(opt.second); // If there is subnet selected and the address has been included // in IA_NA, mark it verified and verify that it belongs to the // subnet. @@ -3927,16 +3909,15 @@ Dhcpv6Srv::declineIA(const Pkt6Ptr& decline, const DuidPtr& duid, const OptionCollection& opts = ia->getOptions(); int total_addrs = 0; // Let's count the total number of addresses. - for (OptionCollection::const_iterator opt = opts.begin(); opt != opts.end(); - ++opt) { + for (auto const& opt : opts) { // Let's ignore nested options other than IAADDR (there shouldn't be anything // else in IA_NA in Decline message, but let's be on the safe side). - if (opt->second->getType() != D6O_IAADDR) { + if (opt.second->getType() != D6O_IAADDR) { continue; } Option6IAAddrPtr decline_addr = boost::dynamic_pointer_cast<Option6IAAddr> - (opt->second); + (opt.second); if (!decline_addr) { continue; } @@ -4243,23 +4224,22 @@ void Dhcpv6Srv::evaluateClasses(const Pkt6Ptr& 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); } } @@ -4283,9 +4263,8 @@ Dhcpv6Srv::setReservedClientClasses(const Pkt6Ptr& pkt, const AllocEngine::ClientContext6& ctx) { if (ctx.currentHost() && pkt) { const ClientClasses& classes = ctx.currentHost()->getClientClasses6(); - for (ClientClasses::const_iterator cclass = classes.cbegin(); - cclass != classes.cend(); ++cclass) { - pkt->addClass(*cclass); + for (auto const& cclass : classes) { + pkt->addClass(cclass); } } } @@ -4317,17 +4296,15 @@ Dhcpv6Srv::requiredClassify(const Pkt6Ptr& pkt, AllocEngine::ClientContext6& ctx 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 pools @@ -4339,9 +4316,8 @@ Dhcpv6Srv::requiredClassify(const Pkt6Ptr& pkt, AllocEngine::ClientContext6& ctx 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); } } } @@ -4353,19 +4329,18 @@ Dhcpv6Srv::requiredClassify(const Pkt6Ptr& pkt, AllocEngine::ClientContext6& ctx // 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(dhcp6_logger, DBG_DHCP6_BASIC, DHCP6_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(dhcp6_logger, DBG_DHCP6_BASIC, DHCP6_CLASS_UNTESTABLE) - .arg(*cclass); + .arg(cclass); continue; } // Evaluate the expression which can return false (no match), @@ -4374,22 +4349,22 @@ Dhcpv6Srv::requiredClassify(const Pkt6Ptr& pkt, AllocEngine::ClientContext6& ctx bool status = evaluateBool(*expr_ptr, *pkt); if (status) { LOG_INFO(dhcp6_logger, EVAL_RESULT) - .arg(*cclass) + .arg(cclass) .arg("true"); // Matching: add the class - pkt->addClass(*cclass); + pkt->addClass(cclass); } else { LOG_DEBUG(dhcp6_logger, DBG_DHCP6_DETAIL, EVAL_RESULT) - .arg(*cclass) + .arg(cclass) .arg("false"); } } catch (const Exception& ex) { LOG_ERROR(dhcp6_logger, EVAL_RESULT) - .arg(*cclass) + .arg(cclass) .arg(ex.what()); } catch (...) { LOG_ERROR(dhcp6_logger, EVAL_RESULT) - .arg(*cclass) + .arg(cclass) .arg("get exception?"); } } @@ -4593,14 +4568,13 @@ void Dhcpv6Srv::processRSOO(const Pkt6Ptr& query, const Pkt6Ptr& rsp) { // and if it's RSOO-enabled and there's no such option provided yet, // copy it to the server's response const OptionCollection& rsoo = rsoo_container->getOptions(); - for (OptionCollection::const_iterator opt = rsoo.begin(); - opt != rsoo.end(); ++opt) { + for (auto const& opt : rsoo) { // Echo option if it is RSOO enabled option and there is no such // option added yet. - if (cfg_rsoo->enabled(opt->second->getType()) && - !rsp->getOption(opt->second->getType())) { - rsp->addOption(opt->second); + if (cfg_rsoo->enabled(opt.second->getType()) && + !rsp->getOption(opt.second->getType())) { + rsp->addOption(opt.second); } } } @@ -4802,13 +4776,12 @@ Dhcpv6Srv::checkDynamicSubnetChange(const Pkt6Ptr& question, Pkt6Ptr& answer, ((prev_hostname != ctx.hostname_) || (prev_fwd_dns_update != ctx.fwd_dns_update_) || (prev_rev_dns_update != ctx.rev_dns_update_))) { - for (Lease6Collection::const_iterator l = ctx.new_leases_.begin(); - l != ctx.new_leases_.end(); ++l) { - (*l)->hostname_ = ctx.hostname_; - (*l)->fqdn_fwd_ = ctx.fwd_dns_update_; - (*l)->fqdn_rev_ = ctx.rev_dns_update_; - (*l)->reuseable_valid_lft_ = 0; - LeaseMgrFactory::instance().updateLease6(*l); + for (auto const& l : ctx.new_leases_) { + l->hostname_ = ctx.hostname_; + l->fqdn_fwd_ = ctx.fwd_dns_update_; + l->fqdn_rev_ = ctx.rev_dns_update_; + l->reuseable_valid_lft_ = 0; + LeaseMgrFactory::instance().updateLease6(l); } } } diff --git a/src/bin/dhcp6/json_config_parser.cc b/src/bin/dhcp6/json_config_parser.cc index 47a8f3f100..e39163fe6f 100644 --- a/src/bin/dhcp6/json_config_parser.cc +++ b/src/bin/dhcp6/json_config_parser.cc @@ -49,7 +49,6 @@ #include <util/triplet.h> #include <boost/algorithm/string.hpp> -#include <boost/foreach.hpp> #include <boost/lexical_cast.hpp> #include <boost/scoped_ptr.hpp> #include <boost/shared_ptr.hpp> @@ -109,7 +108,7 @@ public: /// @param cfg server configuration (RSOO will be stored here) void parse(const SrvConfigPtr& cfg, const isc::data::ConstElementPtr& value) { try { - BOOST_FOREACH(ConstElementPtr source_elem, value->listValue()) { + for (auto const& source_elem : value->listValue()) { std::string option_str = source_elem->stringValue(); // This option can be either code (integer) or name. Let's try code first int64_t code = 0; @@ -245,10 +244,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 Subnet6SimpleCollection* subnets = (*net)->getAllSubnets(); + const Subnet6SimpleCollection* subnets = net->getAllSubnets(); if (!subnets) { // Shared network without subnets it weird, but we decided to // accept such configurations. @@ -256,8 +255,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); } } } @@ -305,75 +304,74 @@ 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. - string iface = (*net)->getIface(); + string iface = net->getIface(); - const Subnet6SimpleCollection* subnets = (*net)->getAllSubnets(); + const Subnet6SimpleCollection* subnets = net->getAllSubnets(); if (subnets) { bool rapid_commit = false; - // For each subnet, add it to a list of regular subnets. - for (auto subnet = subnets->begin(); subnet != subnets->end(); ++subnet) { + // Rapid commit must either be enabled or disabled in all subnets + // in the shared network. + if (subnets->size()) { + // If this is the first subnet, remember the value. + rapid_commit = (*subnets->begin())->getRapidCommit(); + } - // Rapid commit must either be enabled or disabled in all subnets - // in the shared network. - if (subnet == subnets->begin()) { - // If this is the first subnet, remember the value. - rapid_commit = (*subnet)->getRapidCommit(); - } else { - // Ok, this is the second or following subnets. The value - // must match what was set in the first subnet. - if (rapid_commit != (*subnet)->getRapidCommit()) { - isc_throw(DhcpConfigError, "All subnets in a shared network " - "must have the same rapid-commit value. Subnet " - << (*subnet)->toText() - << " has specified rapid-commit " - << ( (*subnet)->getRapidCommit() ? "true" : "false") - << ", but earlier subnet in the same shared-network" - << " or the shared-network itself used rapid-commit " - << (rapid_commit ? "true" : "false")); - } + // For each subnet, add it to a list of regular subnets. + for (auto const& subnet : *subnets) { + // Ok, this is the second or following subnets. The value + // must match what was set in the first subnet. + if (rapid_commit != subnet->getRapidCommit()) { + isc_throw(DhcpConfigError, "All subnets in a shared network " + "must have the same rapid-commit value. Subnet " + << subnet->toText() + << " has specified rapid-commit " + << (subnet->getRapidCommit() ? "true" : "false") + << ", but earlier subnet in the same shared-network" + << " or the shared-network itself used rapid-commit " + << (rapid_commit ? "true" : "false")); } 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()); } } @@ -689,8 +687,8 @@ processDhcp6Config(isc::data::ConstElementPtr config_set) { HostCollection hosts; HostReservationsListParser<HostReservationParser6> 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); } } @@ -731,12 +729,10 @@ processDhcp6Config(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/dhcp6/tests/callout_library_3.cc b/src/bin/dhcp6/tests/callout_library_3.cc index c8e212eac0..7465809d2b 100644 --- a/src/bin/dhcp6/tests/callout_library_3.cc +++ b/src/bin/dhcp6/tests/callout_library_3.cc @@ -56,8 +56,8 @@ dhcp6_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/dhcp6/tests/config_backend_unittest.cc b/src/bin/dhcp6/tests/config_backend_unittest.cc index f1427ce5f8..52fae459b5 100644 --- a/src/bin/dhcp6/tests/config_backend_unittest.cc +++ b/src/bin/dhcp6/tests/config_backend_unittest.cc @@ -25,7 +25,6 @@ #include <dhcp6/tests/dhcp6_test_utils.h> #include <dhcp6/tests/get_config_unittest.h> -#include <boost/foreach.hpp> #include <boost/scoped_ptr.hpp> #include <iostream> diff --git a/src/bin/dhcp6/tests/config_parser_unittest.cc b/src/bin/dhcp6/tests/config_parser_unittest.cc index ef08dbdd24..6f571d52ab 100644 --- a/src/bin/dhcp6/tests/config_parser_unittest.cc +++ b/src/bin/dhcp6/tests/config_parser_unittest.cc @@ -41,9 +41,9 @@ #include "dhcp6_test_utils.h" #include "get_config_unittest.h" -#include <boost/foreach.hpp> #include <gtest/gtest.h> +#include <boost/foreach.hpp> #include <fstream> #include <iostream> #include <sstream> @@ -595,8 +595,7 @@ public: " \"subnet\": \"2001:db8:1::/64\", " " \"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 { @@ -2092,16 +2091,14 @@ TEST_F(Dhcp6ParserTest, badSubnetValues) { // Iterate over the list of scenarios. Each should fail to parse with // a specific error message. for (auto const& scenario : scenarios) { - { - SCOPED_TRACE(scenario.description_); - ConstElementPtr config; - ASSERT_NO_THROW(config = parseDHCP6(scenario.config_json_)) - << "invalid json, broken test"; - ConstElementPtr status; - EXPECT_NO_THROW(status = Dhcpv6SrvTest::configure(srv_, config)); - checkResult(status, 1); - EXPECT_EQ(comment_->stringValue(), scenario.exp_error_msg_); - } + SCOPED_TRACE(scenario.description_); + ConstElementPtr config; + ASSERT_NO_THROW(config = parseDHCP6(scenario.config_json_)) + << "invalid json, broken test"; + ConstElementPtr status; + EXPECT_NO_THROW(status = Dhcpv6SrvTest::configure(srv_, config)); + checkResult(status, 1); + EXPECT_EQ(comment_->stringValue(), scenario.exp_error_msg_); } } @@ -5424,9 +5421,8 @@ TEST_F(Dhcp6ParserTest, invalidD2ClientConfig) { /// @param range Range of reservations returned by the @c Host object /// in which the reservation will be searched. bool reservationExists(const IPv6Resrv& resrv, const IPv6ResrvRange& range) { - for (IPv6ResrvIterator it = range.first; it != range.second; - ++it) { - if (resrv == it->second) { + BOOST_FOREACH(auto const& it, range) { + if (resrv == it.second) { return (true); } } diff --git a/src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc b/src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc index 421cf13ccf..67c3b192b9 100644 --- a/src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc +++ b/src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc @@ -1426,14 +1426,17 @@ TEST_F(CtrlChannelDhcpv6SrvTest, controlChannelStats) { }; std::ostringstream s; + bool first = true; 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()) { + 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/dhcp6/tests/dhcp6_client.cc b/src/bin/dhcp6/tests/dhcp6_client.cc index a797a9745d..a1d085769d 100644 --- a/src/bin/dhcp6/tests/dhcp6_client.cc +++ b/src/bin/dhcp6/tests/dhcp6_client.cc @@ -22,7 +22,6 @@ #include <dhcp6/tests/dhcp6_client.h> #include <util/buffer.h> #include <util/multi_threading_mgr.h> -#include <boost/foreach.hpp> #include <boost/pointer_cast.hpp> #include <algorithm> #include <cstdlib> @@ -258,13 +257,12 @@ Dhcp6Client::appendFQDN() { void Dhcp6Client::appendRequestedIAs(const Pkt6Ptr& query) const { - BOOST_FOREACH(const ClientIA& ia, client_ias_) { + for (auto const& ia : client_ias_) { OptionCollection options = query->getOptions(ia.type_ == Lease::TYPE_NA ? D6O_IA_NA : D6O_IA_PD); - std::pair<unsigned int, OptionPtr> option_pair; Option6IAPtr existing_ia; - BOOST_FOREACH(option_pair, options) { + for (auto const& option_pair : options) { Option6IAPtr ia_opt = boost::dynamic_pointer_cast<Option6IA>(option_pair.second); // This shouldn't happen. @@ -287,7 +285,7 @@ Dhcp6Client::appendRequestedIAs(const Pkt6Ptr& query) const { if ((ia.type_ == Lease::TYPE_NA) && !ia.prefix_.isV6Zero()) { Option6IAAddrPtr ia_addr(new Option6IAAddr(D6O_IAADDR, ia.prefix_, 0, 0)); - BOOST_FOREACH(option_pair, existing_ia->getOptions()) { + for (auto const& option_pair : existing_ia->getOptions()) { Option6IAAddrPtr existing_addr = boost::dynamic_pointer_cast< Option6IAAddr>(option_pair.second); if (existing_addr && @@ -306,7 +304,7 @@ Dhcp6Client::appendRequestedIAs(const Pkt6Ptr& query) const { ia.prefix_, ia.prefix_len_, 0, 0)); - BOOST_FOREACH(option_pair, existing_ia->getOptions()) { + for (auto const& option_pair : existing_ia->getOptions()) { Option6IAPrefixPtr existing_prefix = boost::dynamic_pointer_cast<Option6IAPrefix>(option_pair.second); if (existing_prefix && @@ -328,19 +326,19 @@ Dhcp6Client::copyIAs(const Pkt6Ptr& source, const Pkt6Ptr& dest) { typedef OptionCollection Opts; // Copy IA_NAs. Opts opts = source->getOptions(D6O_IA_NA); - for (Opts::const_iterator opt = opts.begin(); opt != opts.end(); ++opt) { + for (auto const& opt : opts) { // Only copy the entire IA_NA if there is at lease one IA Address option. - if (opt->second->getOption(D6O_IAADDR)) { - dest->addOption(opt->second); + if (opt.second->getOption(D6O_IAADDR)) { + dest->addOption(opt.second); } } // Copy IA_PDs. opts = source->getOptions(D6O_IA_PD); - for (Opts::const_iterator opt = opts.begin(); opt != opts.end(); ++opt) { + for (auto const& opt : opts) { // Only copy the entire IA_PD if there is at least one IA Prefix option // in it. - if (opt->second->getOption(D6O_IAPREFIX)) { - dest->addOption(opt->second); + if (opt.second->getOption(D6O_IAPREFIX)) { + dest->addOption(opt.second); } } } @@ -350,32 +348,28 @@ Dhcp6Client::copyIAsFromLeases(const Pkt6Ptr& dest) const { // Go over leases and create IA_NA and IA_PD options from them. // Create one IA per lease. std::set<uint32_t> iaids = getIAIDs(); - for (std::set<uint32_t>::const_iterator iaid = iaids.begin(); - iaid != iaids.end(); ++iaid) { - std::vector<Lease6> leases = getLeasesByIAID(*iaid); + for (auto const& iaid : iaids) { + std::vector<Lease6> leases = getLeasesByIAID(iaid); // Only a valid lease should be included. Do not copy a // lease which have been marked by the server as invalid. if (leases[0].valid_lft_ == 0) { continue; } Option6IAPtr opt(new Option6IA(leases[0].type_ == Lease::TYPE_NA ? - D6O_IA_NA : D6O_IA_PD, *iaid)); - for (std::vector<Lease6>::const_iterator lease = leases.begin(); - lease != leases.end(); ++lease) { - if ((lease->preferred_lft_ != 0) && (lease->valid_lft_ != 0)) { - if (lease->type_ == Lease::TYPE_NA) { - opt->addOption(Option6IAAddrPtr(new Option6IAAddr( - D6O_IAADDR, - lease->addr_, - lease->preferred_lft_, - lease->valid_lft_))); - } else if (lease->type_ == Lease::TYPE_PD) { - opt->addOption(Option6IAAddrPtr(new Option6IAPrefix( - D6O_IAPREFIX, - lease->addr_, - lease->prefixlen_, - lease->preferred_lft_, - lease->valid_lft_))); + D6O_IA_NA : D6O_IA_PD, iaid)); + for (auto const& lease : leases) { + if ((lease.preferred_lft_ != 0) && (lease.valid_lft_ != 0)) { + if (lease.type_ == Lease::TYPE_NA) { + opt->addOption(Option6IAAddrPtr(new Option6IAAddr(D6O_IAADDR, + lease.addr_, + lease.preferred_lft_, + lease.valid_lft_))); + } else if (lease.type_ == Lease::TYPE_PD) { + opt->addOption(Option6IAAddrPtr(new Option6IAPrefix(D6O_IAPREFIX, + lease.addr_, + lease.prefixlen_, + lease.preferred_lft_, + lease.valid_lft_))); } } } @@ -414,16 +408,14 @@ Dhcp6Client::createMsg(const uint8_t msg_type) { // 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) { - msg->addOption(opt->second); + for (auto const& opt : extra_options_) { + msg->addOption(opt.second); } } // Add classes. - for (ClientClasses::const_iterator cclass = classes_.cbegin(); - cclass != classes_.cend(); ++cclass) { - msg->addClass(*cclass); + for (auto const& cclass : classes_) { + msg->addClass(cclass); } return (msg); @@ -621,17 +613,18 @@ Dhcp6Client::generateIAFromLeases(const Pkt6Ptr& query, const bool include_address) { /// @todo: add support for IAPREFIX here. - for (std::vector<Lease6>::const_iterator lease = config_.leases_.begin(); - lease != config_.leases_.end(); ++lease) { - if (lease->type_ != Lease::TYPE_NA) { + for (auto const& lease : config_.leases_) { + if (lease.type_ != Lease::TYPE_NA) { continue; } - Option6IAPtr ia(new Option6IA(D6O_IA_NA, lease->iaid_)); + Option6IAPtr ia(new Option6IA(D6O_IA_NA, lease.iaid_)); if (include_address) { ia->addOption(OptionPtr(new Option6IAAddr(D6O_IAADDR, - lease->addr_, lease->preferred_lft_, lease->valid_lft_))); + lease.addr_, + lease.preferred_lft_, + lease.valid_lft_))); } query->addOption(ia); } @@ -681,9 +674,8 @@ Dhcp6Client::getClientId() const { std::set<uint32_t> Dhcp6Client::getIAIDs() const { std::set<uint32_t> iaids; - for (std::vector<Lease6>::const_iterator lease = config_.leases_.begin(); - lease != config_.leases_.end(); ++lease) { - iaids.insert(lease->iaid_); + for (auto const& lease : config_.leases_) { + iaids.insert(lease.iaid_); } return (iaids); } @@ -759,7 +751,7 @@ bool Dhcp6Client::hasLeaseForAddress(const asiolink::IOAddress& address, const IAID& iaid) const { std::vector<Lease6> leases = getLeasesByAddress(address); - BOOST_FOREACH(const Lease6& lease, leases) { + for (auto const& lease : leases) { if (lease.iaid_ == iaid) { return (true); } @@ -777,7 +769,7 @@ Dhcp6Client::hasLeaseForAddressRange(const asiolink::IOAddress& first, bool Dhcp6Client::hasLeaseWithZeroLifetimeForAddress(const asiolink::IOAddress& address) const { std::vector<Lease6> leases = getLeasesByAddress(address); - BOOST_FOREACH(const Lease6& lease, leases) { + for (auto const& lease : leases) { if ((lease.preferred_lft_ == 0) && (lease.valid_lft_ == 0)) { return (true); } @@ -790,7 +782,7 @@ bool Dhcp6Client::hasLeaseForPrefix(const asiolink::IOAddress& prefix, const uint8_t prefix_len) const { std::vector<Lease6> leases = getLeasesByAddress(prefix); - BOOST_FOREACH(const Lease6& lease, leases) { + for (auto const& lease : leases) { if (lease.prefixlen_ == prefix_len) { return (true); } @@ -803,7 +795,7 @@ Dhcp6Client::hasLeaseForPrefix(const asiolink::IOAddress& prefix, const uint8_t prefix_len, const IAID& iaid) const { std::vector<Lease6> leases = getLeasesByAddress(prefix); - BOOST_FOREACH(const Lease6& lease, leases) { + for (auto const& lease : leases) { if ((lease.prefixlen_ == prefix_len) && (lease.iaid_ == iaid)) { return (true); @@ -825,7 +817,7 @@ bool Dhcp6Client::hasLeaseWithZeroLifetimeForPrefix(const asiolink::IOAddress& prefix, const uint8_t prefix_len) const { std::vector<Lease6> leases = getLeasesByAddress(prefix); - BOOST_FOREACH(const Lease6& lease, leases) { + for (auto const& lease : leases) { if ((lease.prefixlen_ == prefix_len) && (lease.preferred_lft_ == 0) && (lease.valid_lft_ == 0)) { return (true); @@ -965,9 +957,8 @@ Dhcp6Client::sendMsg(const Pkt6Ptr& msg) { // 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/dhcp6/tests/dhcp6_srv_unittest.cc b/src/bin/dhcp6/tests/dhcp6_srv_unittest.cc index 656711af22..697e4f07a7 100644 --- a/src/bin/dhcp6/tests/dhcp6_srv_unittest.cc +++ b/src/bin/dhcp6/tests/dhcp6_srv_unittest.cc @@ -267,7 +267,7 @@ Dhcpv6SrvTest::loadConfigFile(const string& path) { removeTlsParameters(hosts); hosts = dhcp6->get("hosts-databases"); if (hosts) { - for (auto& host : hosts->listValue()) { + for (auto const& host : hosts->listValue()) { removeTlsParameters(host); } } @@ -362,7 +362,7 @@ Dhcpv6SrvTest::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); } @@ -3365,15 +3365,14 @@ TEST_F(Dhcpv6SrvTest, rsoo2relays) { int count120 = 0; // Let's count how many times option 120 was echoed back int count130 = 0; // Let's count how many times option 130 was echoed back OptionPtr opt120; - for (OptionCollection::const_iterator it = client.config_.options_.begin(); - it != client.config_.options_.end(); ++it) { - switch (it->second->getType()) { + for (auto const& it : client.config_.options_) { + switch (it.second->getType()) { case 110: count110++; break; case 120: count120++; - opt120 = it->second; + opt120 = it.second; break; case 130: count130++; diff --git a/src/bin/dhcp6/tests/dhcp6_test_utils.cc b/src/bin/dhcp6/tests/dhcp6_test_utils.cc index a2f9acff61..de4dec633c 100644 --- a/src/bin/dhcp6/tests/dhcp6_test_utils.cc +++ b/src/bin/dhcp6/tests/dhcp6_test_utils.cc @@ -1146,14 +1146,13 @@ NakedDhcpv6SrvTest::checkIA_NAStatusCode( // it will return it with zeroed lifetimes. if (check_addr) { dhcp::OptionCollection options = ia->getOptions(); - for (isc::dhcp::OptionCollection::iterator opt = options.begin(); - opt != options.end(); ++opt) { - if (opt->second->getType() != D6O_IAADDR) { + for (auto const& opt : options) { + if (opt.second->getType() != D6O_IAADDR) { continue; } dhcp::Option6IAAddrPtr addr = - boost::dynamic_pointer_cast<isc::dhcp::Option6IAAddr>(opt->second); + boost::dynamic_pointer_cast<isc::dhcp::Option6IAAddr>(opt.second); ASSERT_TRUE(addr); EXPECT_EQ(0, addr->getPreferred()); diff --git a/src/bin/dhcp6/tests/hooks_unittest.cc b/src/bin/dhcp6/tests/hooks_unittest.cc index d87896eab3..0fb81725f3 100644 --- a/src/bin/dhcp6/tests/hooks_unittest.cc +++ b/src/bin/dhcp6/tests/hooks_unittest.cc @@ -5589,7 +5589,7 @@ TEST_F(LoadUnloadDhcpv6SrvTest, failLoadIncompatibleLibraries) { // Checks if callouts installed on the dhcp6_srv_configured ared indeed called // and all the necessary parameters are passed. TEST_F(LoadUnloadDhcpv6SrvTest, Dhcpv6SrvConfigured) { - 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/dhcp6/tests/shared_network_unittest.cc b/src/bin/dhcp6/tests/shared_network_unittest.cc index 02a8283e74..fa9651e4f3 100644 --- a/src/bin/dhcp6/tests/shared_network_unittest.cc +++ b/src/bin/dhcp6/tests/shared_network_unittest.cc @@ -1279,9 +1279,9 @@ public: Subnet6Ptr getConfiguredSubnet(const Lease::Type& type, const IOAddress& resource) const { CfgSubnets6Ptr cfg = CfgMgr::instance().getCurrentCfg()->getCfgSubnets6(); const Subnet6Collection* subnets = cfg->getAll(); - for (auto subnet_it = subnets->cbegin(); subnet_it != subnets->cend(); ++subnet_it) { - if ((*subnet_it)->inPool(type, resource)) { - return (*subnet_it); + for (auto const& subnet_it : *subnets) { + if (subnet_it->inPool(type, resource)) { + return (subnet_it); } } @@ -1380,13 +1380,13 @@ public: bool hasLeaseForAddressRange(Dhcp6Client& client, const IOAddress& first, const IOAddress& last, const LeaseOnServer& lease_on_server = LeaseOnServer::MUST_EXIST) { std::vector<Lease6> leases = client.getLeasesByAddressRange(first, last); - for (auto lease_it = leases.cbegin(); lease_it != leases.cend(); ++lease_it) { + for (auto const& lease_it : leases) { // Take into account only valid leases. - if (lease_it->valid_lft_ == 0) { + if (lease_it.valid_lft_ == 0) { continue; } - Lease6Ptr lease = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, lease_it->addr_); + Lease6Ptr lease = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, lease_it.addr_); if ((lease && (lease_on_server == LeaseOnServer::MUST_NOT_EXIST)) || (!lease && (lease_on_server == LeaseOnServer::MUST_EXIST))) { return (false); @@ -1415,13 +1415,13 @@ public: const LeaseOnServer& lease_on_server = LeaseOnServer::MUST_EXIST) { std::vector<Lease6> leases = client.getLeasesByPrefixPool(prefix, prefix_len, delegated_len); - for (auto lease_it = leases.cbegin(); lease_it != leases.cend(); ++lease_it) { + for (auto const& lease_it : leases) { // Take into account only valid leases. - if (lease_it->valid_lft_ == 0) { + if (lease_it.valid_lft_ == 0) { continue; } - Lease6Ptr lease = LeaseMgrFactory::instance().getLease6(Lease::TYPE_PD, lease_it->addr_); + Lease6Ptr lease = LeaseMgrFactory::instance().getLease6(Lease::TYPE_PD, lease_it.addr_); if ((lease && (lease->prefixlen_ == lease->prefixlen_) && (lease_on_server == LeaseOnServer::MUST_NOT_EXIST)) || (!lease && (lease_on_server == LeaseOnServer::MUST_EXIST))) { diff --git a/src/bin/perfdhcp/pkt_transform.cc b/src/bin/perfdhcp/pkt_transform.cc index 7aaf9c6c41..d189161c5c 100644 --- a/src/bin/perfdhcp/pkt_transform.cc +++ b/src/bin/perfdhcp/pkt_transform.cc @@ -116,11 +116,10 @@ PktTransform::packOptions(const OptionBuffer& in_buffer, // If there are any options on the list, we will use provided // options offsets to override them in the output buffer // with new contents. - for (OptionCollection::const_iterator it = options.begin(); - it != options.end(); ++it) { + for (auto const& it : options) { // Get options with their position (offset). boost::shared_ptr<LocalizedOption> option = - boost::dynamic_pointer_cast<LocalizedOption>(it->second); + boost::dynamic_pointer_cast<LocalizedOption>(it.second); if (option == NULL) { isc_throw(isc::BadValue, "option is null"); } @@ -146,8 +145,7 @@ PktTransform::packOptions(const OptionBuffer& in_buffer, out_buffer.writeUint8At(buf_data[i], offset + i); } } - } - catch (const Exception&) { + } catch (const Exception&) { isc_throw(isc::BadValue, "failed to pack options into buffer."); } } @@ -155,11 +153,10 @@ PktTransform::packOptions(const OptionBuffer& in_buffer, void PktTransform::unpackOptions(const OptionBuffer& in_buffer, const OptionCollection& options) { - for (OptionCollection::const_iterator it = options.begin(); - it != options.end(); ++it) { + for (auto const& it : options) { boost::shared_ptr<LocalizedOption> option = - boost::dynamic_pointer_cast<LocalizedOption>(it->second); + boost::dynamic_pointer_cast<LocalizedOption>(it.second); if (option == NULL) { isc_throw(isc::BadValue, "option is null"); } diff --git a/src/bin/perfdhcp/stats_mgr.cc b/src/bin/perfdhcp/stats_mgr.cc index 1563588f65..1bb655b791 100644 --- a/src/bin/perfdhcp/stats_mgr.cc +++ b/src/bin/perfdhcp/stats_mgr.cc @@ -14,6 +14,7 @@ #include <dhcp/pkt4.h> #include <perfdhcp/stats_mgr.h> #include <perfdhcp/test_control.h> +#include <boost/foreach.hpp> using isc::dhcp::DHO_DHCP_CLIENT_IDENTIFIER; using isc::dhcp::DUID; @@ -313,21 +314,16 @@ ExchangeStats::printTimestamps() { using namespace boost::posix_time; // Iterate through all received packets. - for (PktListIterator it = rcvd_packets_.begin(); - it != rcvd_packets_.end(); - ++it) { - PktPtr rcvd_packet = *it; + for (auto const& it : rcvd_packets_) { + PktPtr rcvd_packet = it; PktListTransidHashIndex& idx = archived_packets_.template get<1>(); std::pair<PktListTransidHashIterator, PktListTransidHashIterator> p = idx.equal_range(hashTransid(rcvd_packet)); - for (PktListTransidHashIterator it_archived = p.first; - it_archived != p.second; - ++it_archived) { - if ((*it_archived)->getTransid() == - rcvd_packet->getTransid()) { - PktPtr sent_packet = *it_archived; + BOOST_FOREACH(auto const& it_archived, p) { + if (it_archived->getTransid() == rcvd_packet->getTransid()) { + PktPtr sent_packet = it_archived; // Get sent and received packet times. ptime sent_time = sent_packet->getTimestamp(); ptime rcvd_time = rcvd_packet->getTimestamp(); diff --git a/src/bin/perfdhcp/stats_mgr.h b/src/bin/perfdhcp/stats_mgr.h index 39718e9b79..e5a3619351 100644 --- a/src/bin/perfdhcp/stats_mgr.h +++ b/src/bin/perfdhcp/stats_mgr.h @@ -209,10 +209,8 @@ public: /// \code /// PktList packets_collection(); /// ... # Add elements to the container - /// for (PktListIterator it = packets_collection.begin(); - /// it != packets_collection.end(); - /// ++it) { - /// boost::shared_ptr<Pkt4> pkt = *it; + /// for (auto const& it : packets_collection) { + /// boost::shared_ptr<Pkt4> pkt = it; /// # Do something with packet; /// } /// \endcode @@ -778,10 +776,8 @@ public: /// // \return true, if packet drops occurred. bool droppedPackets() const { - for (ExchangesMapIterator it = exchanges_.begin(); - it != exchanges_.end(); - ++it) { - if (it->second->getDroppedPacketsNum() > 0) { + for (auto const& it : exchanges_) { + if (it.second->getDroppedPacketsNum() > 0) { return (true); } } @@ -1098,11 +1094,9 @@ public: isc_throw(isc::InvalidOperation, "no exchange type added for tracking"); } - for (ExchangesMapIterator it = exchanges_.begin(); - it != exchanges_.end(); - ++it) { - ExchangeStatsPtr xchg_stats = it->second; - std::cout << "***Statistics for: " << it->first + for (auto const& it : exchanges_) { + ExchangeStatsPtr xchg_stats = it.second; + std::cout << "***Statistics for: " << it.first << "***" << std::endl; xchg_stats->printMainStats(); std::cout << std::endl; @@ -1126,35 +1120,36 @@ public: std::ostringstream stream_drops; std::ostringstream stream_reject; std::string sep(""); - for (ExchangesMapIterator it = exchanges_.begin(); - it != exchanges_.end(); ++it) { - - if (it != exchanges_.begin()) { + bool first = true; + for (auto const& it : exchanges_) { + if (!first) { if (clean_report) { sep = clean_sep; } else { sep = "/"; } + } else { + first = false; } - stream_sent << sep << it->second->getSentPacketsNum(); - stream_rcvd << sep << it->second->getRcvdPacketsNum(); - stream_drops << sep << it->second->getDroppedPacketsNum(); - stream_reject << sep << it->second->getRejLeasesNum(); + stream_sent << sep << it.second->getSentPacketsNum(); + stream_rcvd << sep << it.second->getRcvdPacketsNum(); + stream_drops << sep << it.second->getDroppedPacketsNum(); + stream_reject << sep << it.second->getRejLeasesNum(); } if (clean_report) { - std::cout << stream_sent.str() - << clean_sep << stream_rcvd.str() - << clean_sep << stream_drops.str() - << clean_sep << stream_reject.str() - << std::endl; + std::cout << stream_sent.str() + << clean_sep << stream_rcvd.str() + << clean_sep << stream_drops.str() + << clean_sep << stream_reject.str() + << std::endl; } else { - std::cout << "sent: " << stream_sent.str() - << "; received: " << stream_rcvd.str() - << "; drops: " << stream_drops.str() - << "; rejected: " << stream_reject.str() - << std::endl; + std::cout << "sent: " << stream_sent.str() + << "; received: " << stream_rcvd.str() + << "; drops: " << stream_drops.str() + << "; rejected: " << stream_reject.str() + << std::endl; } } @@ -1174,12 +1169,10 @@ public: isc_throw(isc::InvalidOperation, "no exchange type added for tracking"); } - for (ExchangesMapIterator it = exchanges_.begin(); - it != exchanges_.end(); - ++it) { - ExchangeStatsPtr xchg_stats = it->second; + for (auto const& it : exchanges_) { + ExchangeStatsPtr xchg_stats = it.second; std::cout << "***Timestamps for packets: " - << it->first + << it.first << "***" << std::endl; xchg_stats->printTimestamps(); std::cout << std::endl; @@ -1199,19 +1192,19 @@ public: if (custom_counters_.empty()) { isc_throw(isc::InvalidOperation, "no custom counters specified"); } - for (CustomCountersMapIterator it = custom_counters_.begin(); - it != custom_counters_.end(); - ++it) { - CustomCounterPtr counter = it->second; + for (auto const& it : custom_counters_) { + CustomCounterPtr counter = it.second; std::cout << counter->getName() << ": " << counter->getValue() << std::endl; } } - std::tuple<typename ExchangeStats::PktListIterator, typename ExchangeStats::PktListIterator> getSentPackets(const ExchangeType xchg_type) const { + std::tuple<typename ExchangeStats::PktListIterator, typename ExchangeStats::PktListIterator> + getSentPackets(const ExchangeType xchg_type) const { ExchangeStatsPtr xchg_stats = getExchangeStats(xchg_type); - std::tuple<typename ExchangeStats::PktListIterator, typename ExchangeStats::PktListIterator> sent_packets_its = xchg_stats->getSentPackets(); - return(sent_packets_its); + std::tuple<typename ExchangeStats::PktListIterator, typename ExchangeStats::PktListIterator> sent_packets_its = + xchg_stats->getSentPackets(); + return (sent_packets_its); } private: diff --git a/src/bin/perfdhcp/test_control.cc b/src/bin/perfdhcp/test_control.cc index 29ef5a87f3..9d33be86aa 100644 --- a/src/bin/perfdhcp/test_control.cc +++ b/src/bin/perfdhcp/test_control.cc @@ -549,9 +549,8 @@ TestControl::initPacketTemplates() { template_packets_v6_.clear(); template_buffers_.clear(); std::vector<std::string> template_files = options_.getTemplateFiles(); - for (std::vector<std::string>::const_iterator it = template_files.begin(); - it != template_files.end(); ++it) { - readPacketTemplate(*it); + for (auto const& it : template_files) { + readPacketTemplate(it); } } @@ -750,13 +749,13 @@ std::string TestControl::vector2Hex(const std::vector<uint8_t>& vec, const std::string& separator /* = "" */) { std::ostringstream stream; - for (std::vector<uint8_t>::const_iterator it = vec.begin(); - it != vec.end(); - ++it) { - if (it == vec.begin()) { - stream << byte2Hex(*it); + bool first = true; + for (auto const& it : vec) { + if (first) { + stream << byte2Hex(it); + first = false; } else { - stream << separator << byte2Hex(*it); + stream << separator << byte2Hex(it); } } return (stream.str()); diff --git a/src/bin/perfdhcp/test_control.h b/src/bin/perfdhcp/test_control.h index 17700cebf2..2ec4e44cec 100644 --- a/src/bin/perfdhcp/test_control.h +++ b/src/bin/perfdhcp/test_control.h @@ -615,10 +615,9 @@ protected: void addUniqeAddr(const std::set<std::string>& current, ExchangeType xchg_type) { switch(xchg_type) { case ExchangeType::SA: { - for (auto current_it = current.begin(); - current_it != current.end(); ++current_it) { + for (auto const& current_it : current) { // addresses should be unique cross packets - auto ret = unique_address_.emplace(*current_it); + auto ret = unique_address_.emplace(current_it); if (!ret.second) { stats_mgr_.updateNonUniqueAddrNum(ExchangeType::SA); } @@ -626,10 +625,9 @@ protected: break; } case ExchangeType::RR: { - for (auto current_it = current.begin(); - current_it != current.end(); ++current_it) { + for (auto const& current_it : current) { // addresses should be unique cross packets - auto ret = unique_reply_address_.emplace(*current_it); + auto ret = unique_reply_address_.emplace(current_it); if (!ret.second) { stats_mgr_.updateNonUniqueAddrNum(ExchangeType::RR); } @@ -642,10 +640,9 @@ protected: break; } case ExchangeType::DO: { - for (auto current_it = current.begin(); - current_it != current.end(); ++current_it) { + for (auto const& current_it : current) { // addresses should be unique cross packets - auto ret = unique_address_.emplace(*current_it); + auto ret = unique_address_.emplace(current_it); if (!ret.second) { stats_mgr_.updateNonUniqueAddrNum(ExchangeType::DO); } @@ -653,10 +650,9 @@ protected: break; } case ExchangeType::RA: { - for (auto current_it = current.begin(); - current_it != current.end(); ++current_it) { + for (auto const& current_it : current) { // addresses should be unique cross packets - auto ret = unique_reply_address_.emplace(*current_it); + auto ret = unique_reply_address_.emplace(current_it); if (!ret.second) { stats_mgr_.updateNonUniqueAddrNum(ExchangeType::RA); } @@ -677,13 +673,13 @@ protected: /// /// \param addr holding value of unique address. void removeUniqueAddr(const std::set<std::string>& addr) { - for (auto addr_it = addr.begin(); addr_it != addr.end(); ++addr_it) { - auto it = unique_address_.find(*addr_it); + for (auto const& addr_it : addr) { + auto it = unique_address_.find(addr_it); if (it != unique_address_.end()) { unique_address_.erase(it); } - auto it2 = unique_reply_address_.find(*addr_it); + auto it2 = unique_reply_address_.find(addr_it); if (it2 != unique_reply_address_.end()) { unique_reply_address_.erase(it2); } diff --git a/src/bin/perfdhcp/tests/avalanche_scen_unittest.cc b/src/bin/perfdhcp/tests/avalanche_scen_unittest.cc index d2e119a094..614ca03380 100644 --- a/src/bin/perfdhcp/tests/avalanche_scen_unittest.cc +++ b/src/bin/perfdhcp/tests/avalanche_scen_unittest.cc @@ -18,7 +18,6 @@ #include <dhcp/option6_iaprefix.h> #include <boost/date_time/posix_time/posix_time.hpp> -#include <boost/foreach.hpp> #include <algorithm> #include <cstddef> diff --git a/src/bin/perfdhcp/tests/basic_scen_unittest.cc b/src/bin/perfdhcp/tests/basic_scen_unittest.cc index 5240293339..431e8326fc 100644 --- a/src/bin/perfdhcp/tests/basic_scen_unittest.cc +++ b/src/bin/perfdhcp/tests/basic_scen_unittest.cc @@ -17,7 +17,6 @@ #include <dhcp/option6_iaaddr.h> #include <dhcp/option6_iaprefix.h> #include <boost/date_time/posix_time/posix_time.hpp> -#include <boost/foreach.hpp> #include <algorithm> #include <cstddef> diff --git a/src/bin/perfdhcp/tests/perf_socket_unittest.cc b/src/bin/perfdhcp/tests/perf_socket_unittest.cc index 39a2db99e9..e0d5f1ce2e 100644 --- a/src/bin/perfdhcp/tests/perf_socket_unittest.cc +++ b/src/bin/perfdhcp/tests/perf_socket_unittest.cc @@ -6,8 +6,8 @@ #include <config.h> -#include "command_options_helper.h" -#include "../perf_socket.h" +#include <command_options_helper.h> +#include <perf_socket.h> #include <asiolink/io_address.h> #include <exceptions/exceptions.h> @@ -16,7 +16,6 @@ #include <dhcp/iface_mgr.h> #include <boost/date_time/posix_time/posix_time.hpp> -#include <boost/foreach.hpp> #include <algorithm> #include <cstddef> diff --git a/src/bin/perfdhcp/tests/test_control_unittest.cc b/src/bin/perfdhcp/tests/test_control_unittest.cc index 1838a7b1db..f31f25a844 100644 --- a/src/bin/perfdhcp/tests/test_control_unittest.cc +++ b/src/bin/perfdhcp/tests/test_control_unittest.cc @@ -6,8 +6,8 @@ #include <config.h> -#include "command_options_helper.h" -#include "../test_control.h" +#include <command_options_helper.h> +#include <test_control.h> #include <asiolink/io_address.h> #include <exceptions/exceptions.h> @@ -19,7 +19,6 @@ #include <dhcp/option6_iaprefix.h> #include <boost/date_time/posix_time/posix_time.hpp> -#include <boost/foreach.hpp> #include <boost/format.hpp> #include <algorithm> |