*callout_handle);
} catch (...) {
// Make sure we don't orphan a parked packet.
- HooksManager::drop("leases4_committed", query);
+ HooksManager::drop("leases6_committed", query);
throw;
}
// responses in answer message (ADVERTISE or REPLY).
//
// @todo: IA_TA once we implement support for temporary addresses.
- for (OptionCollection::iterator opt = question->options_.begin();
- opt != question->options_.end(); ++opt) {
- switch (opt->second->getType()) {
+ for (const auto& opt : (*question->options_)) {
+ switch (opt.second->getType()) {
case D6O_IA_NA: {
OptionPtr answer_opt = assignIA_NA(question, ctx,
boost::dynamic_pointer_cast<
- Option6IA>(opt->second));
+ Option6IA>(opt.second));
if (answer_opt) {
answer->addOption(answer_opt);
}
case D6O_IA_PD: {
OptionPtr answer_opt = assignIA_PD(question, ctx,
boost::dynamic_pointer_cast<
- Option6IA>(opt->second));
+ Option6IA>(opt.second));
if (answer_opt) {
answer->addOption(answer_opt);
}
// Save the originally selected subnet.
Subnet6Ptr orig_subnet = ctx.subnet_;
- for (OptionCollection::iterator opt = query->options_.begin();
- opt != query->options_.end(); ++opt) {
- switch (opt->second->getType()) {
+ for (const auto& opt : (*query->options_)) {
+ switch (opt.second->getType()) {
case D6O_IA_NA: {
OptionPtr answer_opt = extendIA_NA(query, ctx,
boost::dynamic_pointer_cast<
- Option6IA>(opt->second));
+ Option6IA>(opt.second));
if (answer_opt) {
reply->addOption(answer_opt);
}
case D6O_IA_PD: {
OptionPtr answer_opt = extendIA_PD(query, ctx,
boost::dynamic_pointer_cast<
- Option6IA>(opt->second));
+ Option6IA>(opt.second));
if (answer_opt) {
reply->addOption(answer_opt);
}
// handled properly. Therefore the releaseIA_NA and releaseIA_PD options
// may turn the status code to some error, but can't turn it back to success.
int general_status = STATUS_Success;
- for (OptionCollection::iterator opt = release->options_.begin();
- opt != release->options_.end(); ++opt) {
+ for (const auto& opt : (*release->options_)) {
Lease6Ptr old_lease;
- switch (opt->second->getType()) {
+ switch (opt.second->getType()) {
case D6O_IA_NA: {
OptionPtr answer_opt = releaseIA_NA(ctx.duid_, release, general_status,
- boost::dynamic_pointer_cast<Option6IA>(opt->second),
+ boost::dynamic_pointer_cast<Option6IA>(opt.second),
old_lease);
if (answer_opt) {
reply->addOption(answer_opt);
}
case D6O_IA_PD: {
OptionPtr answer_opt = releaseIA_PD(ctx.duid_, release, general_status,
- boost::dynamic_pointer_cast<Option6IA>(opt->second),
+ boost::dynamic_pointer_cast<Option6IA>(opt.second),
old_lease);
if (answer_opt) {
reply->addOption(answer_opt);
// may turn the status code to some error, but can't turn it back to success.
int general_status = STATUS_Success;
- for (OptionCollection::iterator opt = decline->options_.begin();
- opt != decline->options_.end(); ++opt) {
- switch (opt->second->getType()) {
+ for (const auto& opt : (*decline->options_)) {
+ switch (opt.second->getType()) {
case D6O_IA_NA: {
OptionPtr answer_opt = declineIA(decline, ctx.duid_, general_status,
- boost::dynamic_pointer_cast<Option6IA>(opt->second),
+ boost::dynamic_pointer_cast<Option6IA>(opt.second),
ctx.new_leases_);
if (answer_opt) {
void
Dhcp6Client::applyRcvdConfiguration(const Pkt6Ptr& reply, uint32_t state) {
- typedef OptionCollection Opts;
- // Get all options in the reply message and pick IA_NA, IA_PD and
- // Status code.
- Opts opts = reply->options_;
-
// Let's try to get a MAC
HWAddrPtr hwaddr = reply->getMAC(HWAddr::HWADDR_SOURCE_ANY);
- for (Opts::const_iterator opt = opts.begin(); opt != opts.end(); ++opt) {
- Option6IAPtr ia = boost::dynamic_pointer_cast<Option6IA>(opt->second);
+ // Get all options in the reply message and pick IA_NA, IA_PD and
+ // Status code.
+ for (const auto& opt : *reply->options_) {
+ Option6IAPtr ia = boost::dynamic_pointer_cast<Option6IA>(opt.second);
if (!ia) {
// This is not IA, so let's just store it.
- config_.options_.insert(*opt);
+ config_.options_.insert(opt);
continue;
}
- const Opts& ia_opts = ia->getOptions();
- for (Opts::const_iterator iter_ia_opt = ia_opts.begin();
- iter_ia_opt != ia_opts.end(); ++iter_ia_opt) {
- OptionPtr ia_opt = iter_ia_opt->second;
+ const auto& ia_opts = ia->getOptions();
+ for (const auto& iter_ia_opt : ia_opts) {
+ OptionPtr ia_opt = iter_ia_opt.second;
Lease6 lease;
lease.type_ = (ia->getType() == D6O_IA_NA ? Lease::TYPE_NA : Lease::TYPE_PD);
lease.iaid_ = ia->getIAID();
}
// Get all options in the response message and pick IA_NA, IA_PD.
- OptionCollection opts = context_.response_->options_;
-
- for (auto opt = opts.begin(); opt != opts.end(); ++opt) {
- Option6IAPtr ia = boost::dynamic_pointer_cast<Option6IA>(opt->second);
+ for (const auto& opt : *context_.response_->options_) {
+ Option6IAPtr ia = boost::dynamic_pointer_cast<Option6IA>(opt.second);
if (!ia) {
// This is not IA, so let's just skip it.
continue;
PerfPkt4::rawPack() {
return (PktTransform::pack(dhcp::Option::V4,
data_,
- options_,
+ *options_,
getTransidOffset(),
getTransid(),
buffer_out_));
uint32_t transid = getTransid();
bool res = PktTransform::unpack(dhcp::Option::V4,
data_,
- options_,
+ *options_,
getTransidOffset(),
transid);
if (res) {
PerfPkt6::rawPack() {
return (PktTransform::pack(dhcp::Option::V6,
data_,
- options_,
+ *options_,
getTransidOffset(),
getTransid(),
buffer_out_));
uint32_t transid = getTransid();
bool res = PktTransform::unpack(dhcp::Option::V6,
data_,
- options_,
+ *options_,
getTransidOffset(),
transid);
if (res) {
std::cout <<"***Malformed Packets***" << std::endl
<< "Malformed packets: " << ExchangeStats::malformed_pkts_
- << std::endl;
+ << std::endl;
}
void
std::set<std::string> current;
// addresses were already checked in validateIA
// we can safely assume that those are correct
- for (OptionCollection::iterator opt = pkt6->options_.begin();
- opt != pkt6->options_.end(); ++opt) {
- switch (opt->second->getType()) {
+ for (const auto& opt : *pkt6->options_) {
+ switch (opt.second->getType()) {
case D6O_IA_PD: {
// add address and check if it has not been already assigned
// addresses should be unique cross options of the packet
auto ret = current.emplace(boost::dynamic_pointer_cast<
- Option6IAPrefix>(opt->second->getOption(D6O_IAPREFIX))->getAddress().toText());
+ Option6IAPrefix>(opt.second->getOption(D6O_IAPREFIX))->getAddress().toText());
if (!ret.second) {
stats_mgr_.updateNonUniqueAddrNum(xchg_type);
}
break;
- }
- case D6O_IA_NA: {
+ }
+ case D6O_IA_NA: {
// add address and check if it has not been already assigned
// addresses should be unique cross options of the packet
auto ret = current.emplace(boost::dynamic_pointer_cast<
- Option6IAAddr>(opt->second->getOption(D6O_IAADDR))->getAddress().toText());
+ Option6IAAddr>(opt.second->getOption(D6O_IAADDR))->getAddress().toText());
if (!ret.second) {
stats_mgr_.updateNonUniqueAddrNum(xchg_type);
}
/// A collection of DHCP (v4 or v6) options
typedef std::multimap<unsigned int, OptionPtr> OptionCollection;
+
/// A pointer to an OptionCollection
typedef boost::shared_ptr<OptionCollection> OptionCollectionPtr;
Pkt::Pkt(uint32_t transid, const isc::asiolink::IOAddress& local_addr,
const isc::asiolink::IOAddress& remote_addr, uint16_t local_port,
uint16_t remote_port)
- :transid_(transid),
- iface_(""),
- ifindex_(-1),
- local_addr_(local_addr),
- remote_addr_(remote_addr),
- local_port_(local_port),
- remote_port_(remote_port),
- buffer_out_(0),
- copy_retrieved_options_(false)
-{
+ : options_(new OptionCollection()), transid_(transid), iface_(""), ifindex_(-1),
+ local_addr_(local_addr), remote_addr_(remote_addr), local_port_(local_port),
+ remote_port_(remote_port), buffer_out_(0), copy_retrieved_options_(false) {
}
Pkt::Pkt(const uint8_t* buf, uint32_t len, const isc::asiolink::IOAddress& local_addr,
const isc::asiolink::IOAddress& remote_addr, uint16_t local_port,
uint16_t remote_port)
- :transid_(0),
- iface_(""),
- ifindex_(-1),
- local_addr_(local_addr),
- remote_addr_(remote_addr),
- local_port_(local_port),
- remote_port_(remote_port),
- buffer_out_(0),
- copy_retrieved_options_(false)
-{
-
+ : options_(new OptionCollection()), transid_(0), iface_(""), ifindex_(-1),
+ local_addr_(local_addr), remote_addr_(remote_addr), local_port_(local_port),
+ remote_port_(remote_port), buffer_out_(0), copy_retrieved_options_(false) {
if (len != 0) {
if (buf == NULL) {
isc_throw(InvalidParameter, "data buffer passed to Pkt is NULL");
void
Pkt::addOption(const OptionPtr& opt) {
- options_.insert(std::pair<int, OptionPtr>(opt->getType(), opt));
+ options_->insert(std::pair<int, OptionPtr>(opt->getType(), opt));
}
OptionPtr
Pkt::getNonCopiedOption(const uint16_t type) const {
- OptionCollection::const_iterator x = options_.find(type);
- if (x != options_.end()) {
+ const auto& x = options_->find(type);
+ if (x != options_->end()) {
return (x->second);
}
return (OptionPtr());
OptionPtr
Pkt::getOption(const uint16_t type) {
- OptionCollection::iterator x = options_.find(type);
- if (x != options_.end()) {
+ const auto& x = options_->find(type);
+ if (x != options_->end()) {
if (copy_retrieved_options_) {
OptionPtr option_copy = x->second->clone();
x->second = option_copy;
bool
Pkt::delOption(uint16_t type) {
-
- isc::dhcp::OptionCollection::iterator x = options_.find(type);
- if (x!=options_.end()) {
- options_.erase(x);
+ const auto& x = options_->find(type);
+ if (x != options_->end()) {
+ options_->erase(x);
return (true); // delete successful
} else {
return (false); // can't find option to be deleted
Pkt::setHWAddrMember(const uint8_t htype, const uint8_t,
const std::vector<uint8_t>& hw_addr,
HWAddrPtr& storage) {
-
storage.reset(new HWAddr(hw_addr, htype));
}
return (mac);
}
-};
-};
+} // end of namespace isc::dhcp
+} // end of namespace isc
/// behavior must be taken into consideration before making
/// changes to this member such as access scope restriction or
/// data format change etc.
- isc::dhcp::OptionCollection options_;
+ isc::dhcp::OptionCollectionPtr options_;
protected:
/// @brief A pointer to either Pkt4 or Pkt6 packet
typedef boost::shared_ptr<isc::dhcp::Pkt> PktPtr;
-}; // namespace isc::dhcp
-}; // namespace isc
+} // namespace isc::dhcp
+} // namespace isc
#endif
namespace dhcp {
Pkt4::Pkt4(uint8_t msg_type, uint32_t transid)
- :Pkt(transid, DEFAULT_ADDRESS, DEFAULT_ADDRESS, DHCP4_SERVER_PORT,
- DHCP4_CLIENT_PORT),
- op_(DHCPTypeToBootpType(msg_type)),
- hwaddr_(new HWAddr()),
- hops_(0),
- secs_(0),
- flags_(0),
- ciaddr_(DEFAULT_ADDRESS),
- yiaddr_(DEFAULT_ADDRESS),
- siaddr_(DEFAULT_ADDRESS),
- giaddr_(DEFAULT_ADDRESS)
-{
+ : Pkt(transid, DEFAULT_ADDRESS, DEFAULT_ADDRESS, DHCP4_SERVER_PORT, DHCP4_CLIENT_PORT),
+ op_(DHCPTypeToBootpType(msg_type)), hwaddr_(new HWAddr()), hops_(0), secs_(0), flags_(0),
+ ciaddr_(DEFAULT_ADDRESS), yiaddr_(DEFAULT_ADDRESS), siaddr_(DEFAULT_ADDRESS),
+ giaddr_(DEFAULT_ADDRESS) {
memset(sname_, 0, MAX_SNAME_LEN);
memset(file_, 0, MAX_FILE_LEN);
}
Pkt4::Pkt4(const uint8_t* data, size_t len)
- :Pkt(data, len, DEFAULT_ADDRESS, DEFAULT_ADDRESS, DHCP4_SERVER_PORT,
- DHCP4_CLIENT_PORT),
- op_(BOOTREQUEST),
- hwaddr_(new HWAddr()),
- hops_(0),
- secs_(0),
- flags_(0),
- ciaddr_(DEFAULT_ADDRESS),
- yiaddr_(DEFAULT_ADDRESS),
- siaddr_(DEFAULT_ADDRESS),
- giaddr_(DEFAULT_ADDRESS)
-{
+ : Pkt(data, len, DEFAULT_ADDRESS, DEFAULT_ADDRESS, DHCP4_SERVER_PORT, DHCP4_CLIENT_PORT),
+ op_(BOOTREQUEST), hwaddr_(new HWAddr()), hops_(0), secs_(0), flags_(0),
+ ciaddr_(DEFAULT_ADDRESS), yiaddr_(DEFAULT_ADDRESS), siaddr_(DEFAULT_ADDRESS),
+ giaddr_(DEFAULT_ADDRESS) {
if (len < DHCPV4_PKT_HDR_LEN) {
isc_throw(OutOfRange, "Truncated DHCPv4 packet (len=" << len
size_t length = DHCPV4_PKT_HDR_LEN; // DHCPv4 header
// ... and sum of lengths of all options
- for (OptionCollection::const_iterator it = options_.begin();
- it != options_.end();
- ++it) {
- length += (*it).second->len();
+ for (const auto& it : *options_) {
+ length += it.second->len();
}
return (length);
// Call packOptions4() with parameter,"top", true. This invokes
// logic to emit the message type option first.
- LibDHCP::packOptions4(buffer_out_, options_, true);
+ LibDHCP::packOptions4(buffer_out_, *options_, true);
// add END option that indicates end of options
// (End option is very simple, just a 255 octet)
// a vector as an input.
buffer_in.readVector(opts_buffer, opts_len);
- size_t offset = LibDHCP::unpackOptions4(opts_buffer, DHCP4_OPTION_SPACE, options_, deferred_options_, false);
+ size_t offset = LibDHCP::unpackOptions4(opts_buffer, DHCP4_OPTION_SPACE, *options_, deferred_options_, false);
// If offset is not equal to the size and there is no DHO_END,
// then something is wrong here. We either parsed past input
output << ", transid=0x" << hex << transid_ << dec;
- if (!options_.empty()) {
+ if (!options_->empty()) {
output << "," << std::endl << "options:";
- for (isc::dhcp::OptionCollection::const_iterator opt = options_.begin();
- opt != options_.end(); ++opt) {
+ for (const auto& opt : *options_) {
try {
- output << std::endl << opt->second->toText(2);
+ output << std::endl << opt.second->toText(2);
} catch (...) {
output << "(unknown)" << std::endl;
}
}
} // end of namespace isc::dhcp
-
} // end of namespace isc
typedef boost::shared_ptr<Pkt4> Pkt4Ptr;
} // isc::dhcp namespace
-
} // isc namespace
#endif
namespace dhcp {
Pkt6::RelayInfo::RelayInfo()
- :msg_type_(0), hop_count_(0), linkaddr_(DEFAULT_ADDRESS6),
- peeraddr_(DEFAULT_ADDRESS6), relay_msg_len_(0) {
+ : msg_type_(0), hop_count_(0), linkaddr_(DEFAULT_ADDRESS6),
+ peeraddr_(DEFAULT_ADDRESS6), relay_msg_len_(0) {
}
std::string Pkt6::RelayInfo::toText() const {
<< "link-address=" << linkaddr_.toText()
<< ", peer-address=" << peeraddr_.toText() << ", "
<< options_.size() << " option(s)" << endl;
- for (auto option = options_.cbegin(); option != options_.cend(); ++option) {
- tmp << option->second->toText() << endl;
+ for (const auto& option : options_) {
+ tmp << option.second->toText() << endl;
}
return (tmp.str());
}
Pkt6::Pkt6(const uint8_t* buf, uint32_t buf_len, DHCPv6Proto proto /* = UDP */)
- :Pkt(buf, buf_len, DEFAULT_ADDRESS6, DEFAULT_ADDRESS6, 0, 0),
- proto_(proto), msg_type_(0) {
+ : Pkt(buf, buf_len, DEFAULT_ADDRESS6, DEFAULT_ADDRESS6, 0, 0), proto_(proto),
+ msg_type_(0) {
}
Pkt6::Pkt6(uint8_t msg_type, uint32_t transid, DHCPv6Proto proto /*= UDP*/)
-:Pkt(transid, DEFAULT_ADDRESS6, DEFAULT_ADDRESS6, 0, 0), proto_(proto),
- msg_type_(msg_type) {
+ : Pkt(transid, DEFAULT_ADDRESS6, DEFAULT_ADDRESS6, 0, 0), proto_(proto),
+ msg_type_(msg_type) {
}
size_t Pkt6::len() {
uint16_t len = DHCPV6_RELAY_HDR_LEN // fixed header
+ Option::OPTION6_HDR_LEN; // header of the relay-msg option
- for (OptionCollection::const_iterator opt = relay.options_.begin();
- opt != relay.options_.end(); ++opt) {
- len += (opt->second)->len();
+ for (const auto& opt : relay.options_) {
+ len += (opt.second)->len();
}
return (len);
uint16_t Pkt6::directLen() const {
uint16_t length = DHCPV6_PKT_HDR_LEN; // DHCPv6 header
- for (OptionCollection::const_iterator it = options_.begin();
- it != options_.end();
- ++it) {
- length += (*it).second->len();
+ for (const auto& it : *options_) {
+ length += it.second->len();
}
return (length);
// present here as well (vendor-opts for Cable modems,
// subscriber-id, remote-id, options echoed back from Echo
// Request Option, etc.)
- for (OptionCollection::const_iterator opt =
- relay->options_.begin();
- opt != relay->options_.end(); ++opt) {
- (opt->second)->pack(buffer_out_);
+ for (const auto& opt : relay->options_) {
+ (opt.second)->pack(buffer_out_);
}
// and include header relay-msg option. Its payload will be
buffer_out_.writeUint8( (transid_) & 0xff );
// the rest are options
- LibDHCP::packOptions6(buffer_out_, options_);
+ LibDHCP::packOptions6(buffer_out_, *options_);
}
catch (const Exception& e) {
// An exception is thrown and message will be written to Logger
// If custom option parsing function has been set, use this function
// to parse options. Otherwise, use standard function from libdhcp.
- size_t offset = LibDHCP::unpackOptions6(opt_buffer, DHCP6_OPTION_SPACE, options_);
+ size_t offset = LibDHCP::unpackOptions6(opt_buffer, DHCP6_OPTION_SPACE, *options_);
// If offset is not equal to the size, then something is wrong here. We
// either parsed past input buffer (bug in our code) or we haven't parsed
hex << transid_ << dec << endl;
// Then print the options
- for (isc::dhcp::OptionCollection::const_iterator opt=options_.begin();
- opt != options_.end();
- ++opt) {
- tmp << opt->second->toText() << std::endl;
+ for (const auto& opt : *options_) {
+ tmp << opt.second->toText() << std::endl;
}
// Finally, print the relay information (if present)
if (!relay_info_.empty()) {
tmp << relay_info_.size() << " relay(s):" << endl;
int cnt = 0;
- for (auto relay = relay_info_.cbegin(); relay != relay_info_.cend(); ++relay) {
- tmp << "relay[" << cnt++ << "]: " << relay->toText();
+ for (const auto& relay : relay_info_) {
+ tmp << "relay[" << cnt++ << "]: " << relay.toText();
}
} else {
tmp << "No relays traversed." << endl;
isc::dhcp::OptionCollection
Pkt6::getNonCopiedOptions(const uint16_t opt_type) const {
std::pair<OptionCollection::const_iterator,
- OptionCollection::const_iterator> range = options_.equal_range(opt_type);
+ OptionCollection::const_iterator> range = options_->equal_range(opt_type);
return (OptionCollection(range.first, range.second));
}
OptionCollection options_copy;
std::pair<OptionCollection::iterator,
- OptionCollection::iterator> range = options_.equal_range(opt_type);
+ OptionCollection::iterator> range = options_->equal_range(opt_type);
// If options should be copied on retrieval, we should now iterate over
// matching options, copy them and replace the original ones with new
// instances.