2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-09-01 14:35:29 +00:00

[#2181] pkt now uses OptionCollectionPtr instead of OptionCollection

This commit is contained in:
Razvan Becheriu
2022-02-24 16:49:15 +02:00
parent 4d3b60151a
commit 4d26dae299
11 changed files with 94 additions and 149 deletions

View File

@@ -1080,7 +1080,7 @@ Dhcpv6Srv::processDhcp6Query(Pkt6Ptr& query, Pkt6Ptr& rsp) {
*callout_handle); *callout_handle);
} catch (...) { } catch (...) {
// Make sure we don't orphan a parked packet. // Make sure we don't orphan a parked packet.
HooksManager::drop("leases4_committed", query); HooksManager::drop("leases6_committed", query);
throw; throw;
} }
@@ -1764,13 +1764,12 @@ Dhcpv6Srv::assignLeases(const Pkt6Ptr& question, Pkt6Ptr& answer,
// responses in answer message (ADVERTISE or REPLY). // responses in answer message (ADVERTISE or REPLY).
// //
// @todo: IA_TA once we implement support for temporary addresses. // @todo: IA_TA once we implement support for temporary addresses.
for (OptionCollection::iterator opt = question->options_.begin(); for (const auto& opt : (*question->options_)) {
opt != question->options_.end(); ++opt) { switch (opt.second->getType()) {
switch (opt->second->getType()) {
case D6O_IA_NA: { case D6O_IA_NA: {
OptionPtr answer_opt = assignIA_NA(question, ctx, OptionPtr answer_opt = assignIA_NA(question, ctx,
boost::dynamic_pointer_cast< boost::dynamic_pointer_cast<
Option6IA>(opt->second)); Option6IA>(opt.second));
if (answer_opt) { if (answer_opt) {
answer->addOption(answer_opt); answer->addOption(answer_opt);
} }
@@ -1779,7 +1778,7 @@ Dhcpv6Srv::assignLeases(const Pkt6Ptr& question, Pkt6Ptr& answer,
case D6O_IA_PD: { case D6O_IA_PD: {
OptionPtr answer_opt = assignIA_PD(question, ctx, OptionPtr answer_opt = assignIA_PD(question, ctx,
boost::dynamic_pointer_cast< boost::dynamic_pointer_cast<
Option6IA>(opt->second)); Option6IA>(opt.second));
if (answer_opt) { if (answer_opt) {
answer->addOption(answer_opt); answer->addOption(answer_opt);
} }
@@ -2657,13 +2656,12 @@ Dhcpv6Srv::extendLeases(const Pkt6Ptr& query, Pkt6Ptr& reply,
// Save the originally selected subnet. // Save the originally selected subnet.
Subnet6Ptr orig_subnet = ctx.subnet_; Subnet6Ptr orig_subnet = ctx.subnet_;
for (OptionCollection::iterator opt = query->options_.begin(); for (const auto& opt : (*query->options_)) {
opt != query->options_.end(); ++opt) { switch (opt.second->getType()) {
switch (opt->second->getType()) {
case D6O_IA_NA: { case D6O_IA_NA: {
OptionPtr answer_opt = extendIA_NA(query, ctx, OptionPtr answer_opt = extendIA_NA(query, ctx,
boost::dynamic_pointer_cast< boost::dynamic_pointer_cast<
Option6IA>(opt->second)); Option6IA>(opt.second));
if (answer_opt) { if (answer_opt) {
reply->addOption(answer_opt); reply->addOption(answer_opt);
} }
@@ -2673,7 +2671,7 @@ Dhcpv6Srv::extendLeases(const Pkt6Ptr& query, Pkt6Ptr& reply,
case D6O_IA_PD: { case D6O_IA_PD: {
OptionPtr answer_opt = extendIA_PD(query, ctx, OptionPtr answer_opt = extendIA_PD(query, ctx,
boost::dynamic_pointer_cast< boost::dynamic_pointer_cast<
Option6IA>(opt->second)); Option6IA>(opt.second));
if (answer_opt) { if (answer_opt) {
reply->addOption(answer_opt); reply->addOption(answer_opt);
} }
@@ -2710,13 +2708,12 @@ Dhcpv6Srv::releaseLeases(const Pkt6Ptr& release, Pkt6Ptr& reply,
// handled properly. Therefore the releaseIA_NA and releaseIA_PD options // 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. // may turn the status code to some error, but can't turn it back to success.
int general_status = STATUS_Success; int general_status = STATUS_Success;
for (OptionCollection::iterator opt = release->options_.begin(); for (const auto& opt : (*release->options_)) {
opt != release->options_.end(); ++opt) {
Lease6Ptr old_lease; Lease6Ptr old_lease;
switch (opt->second->getType()) { switch (opt.second->getType()) {
case D6O_IA_NA: { case D6O_IA_NA: {
OptionPtr answer_opt = releaseIA_NA(ctx.duid_, release, general_status, 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); old_lease);
if (answer_opt) { if (answer_opt) {
reply->addOption(answer_opt); reply->addOption(answer_opt);
@@ -2725,7 +2722,7 @@ Dhcpv6Srv::releaseLeases(const Pkt6Ptr& release, Pkt6Ptr& reply,
} }
case D6O_IA_PD: { case D6O_IA_PD: {
OptionPtr answer_opt = releaseIA_PD(ctx.duid_, release, general_status, 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); old_lease);
if (answer_opt) { if (answer_opt) {
reply->addOption(answer_opt); reply->addOption(answer_opt);
@@ -3409,12 +3406,11 @@ Dhcpv6Srv::declineLeases(const Pkt6Ptr& decline, Pkt6Ptr& reply,
// may turn the status code to some error, but can't turn it back to success. // may turn the status code to some error, but can't turn it back to success.
int general_status = STATUS_Success; int general_status = STATUS_Success;
for (OptionCollection::iterator opt = decline->options_.begin(); for (const auto& opt : (*decline->options_)) {
opt != decline->options_.end(); ++opt) { switch (opt.second->getType()) {
switch (opt->second->getType()) {
case D6O_IA_NA: { case D6O_IA_NA: {
OptionPtr answer_opt = declineIA(decline, ctx.duid_, general_status, 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_); ctx.new_leases_);
if (answer_opt) { if (answer_opt) {

View File

@@ -139,26 +139,22 @@ Dhcp6Client::Dhcp6Client(boost::shared_ptr<NakedDhcpv6Srv>& srv) :
void void
Dhcp6Client::applyRcvdConfiguration(const Pkt6Ptr& reply, uint32_t state) { 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 // Let's try to get a MAC
HWAddrPtr hwaddr = reply->getMAC(HWAddr::HWADDR_SOURCE_ANY); HWAddrPtr hwaddr = reply->getMAC(HWAddr::HWADDR_SOURCE_ANY);
for (Opts::const_iterator opt = opts.begin(); opt != opts.end(); ++opt) { // Get all options in the reply message and pick IA_NA, IA_PD and
Option6IAPtr ia = boost::dynamic_pointer_cast<Option6IA>(opt->second); // Status code.
for (const auto& opt : *reply->options_) {
Option6IAPtr ia = boost::dynamic_pointer_cast<Option6IA>(opt.second);
if (!ia) { if (!ia) {
// This is not IA, so let's just store it. // This is not IA, so let's just store it.
config_.options_.insert(*opt); config_.options_.insert(opt);
continue; continue;
} }
const Opts& ia_opts = ia->getOptions(); const auto& ia_opts = ia->getOptions();
for (Opts::const_iterator iter_ia_opt = ia_opts.begin(); for (const auto& iter_ia_opt : ia_opts) {
iter_ia_opt != ia_opts.end(); ++iter_ia_opt) { OptionPtr ia_opt = iter_ia_opt.second;
OptionPtr ia_opt = iter_ia_opt->second;
Lease6 lease; Lease6 lease;
lease.type_ = (ia->getType() == D6O_IA_NA ? Lease::TYPE_NA : Lease::TYPE_PD); lease.type_ = (ia->getType() == D6O_IA_NA ? Lease::TYPE_NA : Lease::TYPE_PD);
lease.iaid_ = ia->getIAID(); lease.iaid_ = ia->getIAID();
@@ -877,10 +873,8 @@ Dhcp6Client::getTeeTimes(const uint32_t iaid, uint32_t& t1, uint32_t& t2) const
} }
// Get all options in the response message and pick IA_NA, IA_PD. // Get all options in the response message and pick IA_NA, IA_PD.
OptionCollection opts = context_.response_->options_; for (const auto& opt : *context_.response_->options_) {
Option6IAPtr ia = boost::dynamic_pointer_cast<Option6IA>(opt.second);
for (auto opt = opts.begin(); opt != opts.end(); ++opt) {
Option6IAPtr ia = boost::dynamic_pointer_cast<Option6IA>(opt->second);
if (!ia) { if (!ia) {
// This is not IA, so let's just skip it. // This is not IA, so let's just skip it.
continue; continue;

View File

@@ -31,7 +31,7 @@ bool
PerfPkt4::rawPack() { PerfPkt4::rawPack() {
return (PktTransform::pack(dhcp::Option::V4, return (PktTransform::pack(dhcp::Option::V4,
data_, data_,
options_, *options_,
getTransidOffset(), getTransidOffset(),
getTransid(), getTransid(),
buffer_out_)); buffer_out_));
@@ -42,7 +42,7 @@ PerfPkt4::rawUnpack() {
uint32_t transid = getTransid(); uint32_t transid = getTransid();
bool res = PktTransform::unpack(dhcp::Option::V4, bool res = PktTransform::unpack(dhcp::Option::V4,
data_, data_,
options_, *options_,
getTransidOffset(), getTransidOffset(),
transid); transid);
if (res) { if (res) {

View File

@@ -35,7 +35,7 @@ bool
PerfPkt6::rawPack() { PerfPkt6::rawPack() {
return (PktTransform::pack(dhcp::Option::V6, return (PktTransform::pack(dhcp::Option::V6,
data_, data_,
options_, *options_,
getTransidOffset(), getTransidOffset(),
getTransid(), getTransid(),
buffer_out_)); buffer_out_));
@@ -46,7 +46,7 @@ PerfPkt6::rawUnpack() {
uint32_t transid = getTransid(); uint32_t transid = getTransid();
bool res = PktTransform::unpack(dhcp::Option::V6, bool res = PktTransform::unpack(dhcp::Option::V6,
data_, data_,
options_, *options_,
getTransidOffset(), getTransidOffset(),
transid); transid);
if (res) { if (res) {

View File

@@ -861,14 +861,13 @@ TestControl::address6Uniqueness(const Pkt6Ptr& pkt6, ExchangeType xchg_type) {
std::set<std::string> current; std::set<std::string> current;
// addresses were already checked in validateIA // addresses were already checked in validateIA
// we can safely assume that those are correct // we can safely assume that those are correct
for (OptionCollection::iterator opt = pkt6->options_.begin(); for (const auto& opt : *pkt6->options_) {
opt != pkt6->options_.end(); ++opt) { switch (opt.second->getType()) {
switch (opt->second->getType()) {
case D6O_IA_PD: { case D6O_IA_PD: {
// add address and check if it has not been already assigned // add address and check if it has not been already assigned
// addresses should be unique cross options of the packet // addresses should be unique cross options of the packet
auto ret = current.emplace(boost::dynamic_pointer_cast< 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) { if (!ret.second) {
stats_mgr_.updateNonUniqueAddrNum(xchg_type); stats_mgr_.updateNonUniqueAddrNum(xchg_type);
} }
@@ -878,7 +877,7 @@ TestControl::address6Uniqueness(const Pkt6Ptr& pkt6, ExchangeType xchg_type) {
// add address and check if it has not been already assigned // add address and check if it has not been already assigned
// addresses should be unique cross options of the packet // addresses should be unique cross options of the packet
auto ret = current.emplace(boost::dynamic_pointer_cast< 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) { if (!ret.second) {
stats_mgr_.updateNonUniqueAddrNum(xchg_type); stats_mgr_.updateNonUniqueAddrNum(xchg_type);
} }

View File

@@ -38,6 +38,7 @@ typedef boost::shared_ptr<Option> OptionPtr;
/// A collection of DHCP (v4 or v6) options /// A collection of DHCP (v4 or v6) options
typedef std::multimap<unsigned int, OptionPtr> OptionCollection; typedef std::multimap<unsigned int, OptionPtr> OptionCollection;
/// A pointer to an OptionCollection /// A pointer to an OptionCollection
typedef boost::shared_ptr<OptionCollection> OptionCollectionPtr; typedef boost::shared_ptr<OptionCollection> OptionCollectionPtr;

View File

@@ -17,32 +17,17 @@ namespace dhcp {
Pkt::Pkt(uint32_t transid, const isc::asiolink::IOAddress& local_addr, Pkt::Pkt(uint32_t transid, const isc::asiolink::IOAddress& local_addr,
const isc::asiolink::IOAddress& remote_addr, uint16_t local_port, const isc::asiolink::IOAddress& remote_addr, uint16_t local_port,
uint16_t remote_port) uint16_t remote_port)
:transid_(transid), : options_(new OptionCollection()), transid_(transid), iface_(""), ifindex_(-1),
iface_(""), local_addr_(local_addr), remote_addr_(remote_addr), local_port_(local_port),
ifindex_(-1), remote_port_(remote_port), buffer_out_(0), copy_retrieved_options_(false) {
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, 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, const isc::asiolink::IOAddress& remote_addr, uint16_t local_port,
uint16_t remote_port) uint16_t remote_port)
:transid_(0), : options_(new OptionCollection()), transid_(0), iface_(""), ifindex_(-1),
iface_(""), local_addr_(local_addr), remote_addr_(remote_addr), local_port_(local_port),
ifindex_(-1), remote_port_(remote_port), buffer_out_(0), copy_retrieved_options_(false) {
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 (len != 0) {
if (buf == NULL) { if (buf == NULL) {
isc_throw(InvalidParameter, "data buffer passed to Pkt is NULL"); isc_throw(InvalidParameter, "data buffer passed to Pkt is NULL");
@@ -54,13 +39,13 @@ Pkt::Pkt(const uint8_t* buf, uint32_t len, const isc::asiolink::IOAddress& local
void void
Pkt::addOption(const OptionPtr& opt) { Pkt::addOption(const OptionPtr& opt) {
options_.insert(std::pair<int, OptionPtr>(opt->getType(), opt)); options_->insert(std::pair<int, OptionPtr>(opt->getType(), opt));
} }
OptionPtr OptionPtr
Pkt::getNonCopiedOption(const uint16_t type) const { Pkt::getNonCopiedOption(const uint16_t type) const {
OptionCollection::const_iterator x = options_.find(type); const auto& x = options_->find(type);
if (x != options_.end()) { if (x != options_->end()) {
return (x->second); return (x->second);
} }
return (OptionPtr()); return (OptionPtr());
@@ -68,8 +53,8 @@ Pkt::getNonCopiedOption(const uint16_t type) const {
OptionPtr OptionPtr
Pkt::getOption(const uint16_t type) { Pkt::getOption(const uint16_t type) {
OptionCollection::iterator x = options_.find(type); const auto& x = options_->find(type);
if (x != options_.end()) { if (x != options_->end()) {
if (copy_retrieved_options_) { if (copy_retrieved_options_) {
OptionPtr option_copy = x->second->clone(); OptionPtr option_copy = x->second->clone();
x->second = option_copy; x->second = option_copy;
@@ -81,10 +66,9 @@ Pkt::getOption(const uint16_t type) {
bool bool
Pkt::delOption(uint16_t type) { Pkt::delOption(uint16_t type) {
const auto& x = options_->find(type);
isc::dhcp::OptionCollection::iterator x = options_.find(type); if (x != options_->end()) {
if (x!=options_.end()) { options_->erase(x);
options_.erase(x);
return (true); // delete successful return (true); // delete successful
} else { } else {
return (false); // can't find option to be deleted return (false); // can't find option to be deleted
@@ -138,7 +122,6 @@ void
Pkt::setHWAddrMember(const uint8_t htype, const uint8_t, Pkt::setHWAddrMember(const uint8_t htype, const uint8_t,
const std::vector<uint8_t>& hw_addr, const std::vector<uint8_t>& hw_addr,
HWAddrPtr& storage) { HWAddrPtr& storage) {
storage.reset(new HWAddr(hw_addr, htype)); storage.reset(new HWAddr(hw_addr, htype));
} }
@@ -282,5 +265,5 @@ Pkt::getMACFromIPv6(const isc::asiolink::IOAddress& addr) {
return (mac); return (mac);
} }
}; } // end of namespace isc::dhcp
}; } // end of namespace isc

View File

@@ -611,7 +611,7 @@ public:
/// behavior must be taken into consideration before making /// behavior must be taken into consideration before making
/// changes to this member such as access scope restriction or /// changes to this member such as access scope restriction or
/// data format change etc. /// data format change etc.
isc::dhcp::OptionCollection options_; isc::dhcp::OptionCollectionPtr options_;
protected: protected:
@@ -796,7 +796,7 @@ private:
/// @brief A pointer to either Pkt4 or Pkt6 packet /// @brief A pointer to either Pkt4 or Pkt6 packet
typedef boost::shared_ptr<isc::dhcp::Pkt> PktPtr; typedef boost::shared_ptr<isc::dhcp::Pkt> PktPtr;
}; // namespace isc::dhcp } // namespace isc::dhcp
}; // namespace isc } // namespace isc
#endif #endif

View File

@@ -30,18 +30,10 @@ namespace isc {
namespace dhcp { namespace dhcp {
Pkt4::Pkt4(uint8_t msg_type, uint32_t transid) Pkt4::Pkt4(uint8_t msg_type, uint32_t transid)
:Pkt(transid, DEFAULT_ADDRESS, DEFAULT_ADDRESS, DHCP4_SERVER_PORT, : Pkt(transid, DEFAULT_ADDRESS, DEFAULT_ADDRESS, DHCP4_SERVER_PORT, DHCP4_CLIENT_PORT),
DHCP4_CLIENT_PORT), op_(DHCPTypeToBootpType(msg_type)), hwaddr_(new HWAddr()), hops_(0), secs_(0), flags_(0),
op_(DHCPTypeToBootpType(msg_type)), ciaddr_(DEFAULT_ADDRESS), yiaddr_(DEFAULT_ADDRESS), siaddr_(DEFAULT_ADDRESS),
hwaddr_(new HWAddr()), giaddr_(DEFAULT_ADDRESS) {
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(sname_, 0, MAX_SNAME_LEN);
memset(file_, 0, MAX_FILE_LEN); memset(file_, 0, MAX_FILE_LEN);
@@ -49,18 +41,10 @@ Pkt4::Pkt4(uint8_t msg_type, uint32_t transid)
} }
Pkt4::Pkt4(const uint8_t* data, size_t len) Pkt4::Pkt4(const uint8_t* data, size_t len)
:Pkt(data, len, DEFAULT_ADDRESS, DEFAULT_ADDRESS, DHCP4_SERVER_PORT, : Pkt(data, len, DEFAULT_ADDRESS, DEFAULT_ADDRESS, DHCP4_SERVER_PORT, DHCP4_CLIENT_PORT),
DHCP4_CLIENT_PORT), op_(BOOTREQUEST), hwaddr_(new HWAddr()), hops_(0), secs_(0), flags_(0),
op_(BOOTREQUEST), ciaddr_(DEFAULT_ADDRESS), yiaddr_(DEFAULT_ADDRESS), siaddr_(DEFAULT_ADDRESS),
hwaddr_(new HWAddr()), giaddr_(DEFAULT_ADDRESS) {
hops_(0),
secs_(0),
flags_(0),
ciaddr_(DEFAULT_ADDRESS),
yiaddr_(DEFAULT_ADDRESS),
siaddr_(DEFAULT_ADDRESS),
giaddr_(DEFAULT_ADDRESS)
{
if (len < DHCPV4_PKT_HDR_LEN) { if (len < DHCPV4_PKT_HDR_LEN) {
isc_throw(OutOfRange, "Truncated DHCPv4 packet (len=" << len isc_throw(OutOfRange, "Truncated DHCPv4 packet (len=" << len
@@ -76,10 +60,8 @@ Pkt4::len() {
size_t length = DHCPV4_PKT_HDR_LEN; // DHCPv4 header size_t length = DHCPV4_PKT_HDR_LEN; // DHCPv4 header
// ... and sum of lengths of all options // ... and sum of lengths of all options
for (OptionCollection::const_iterator it = options_.begin(); for (const auto& it : *options_) {
it != options_.end(); length += it.second->len();
++it) {
length += (*it).second->len();
} }
return (length); return (length);
@@ -137,7 +119,7 @@ Pkt4::pack() {
// Call packOptions4() with parameter,"top", true. This invokes // Call packOptions4() with parameter,"top", true. This invokes
// logic to emit the message type option first. // 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 // add END option that indicates end of options
// (End option is very simple, just a 255 octet) // (End option is very simple, just a 255 octet)
@@ -205,7 +187,7 @@ Pkt4::unpack() {
// a vector as an input. // a vector as an input.
buffer_in.readVector(opts_buffer, opts_len); 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, // If offset is not equal to the size and there is no DHO_END,
// then something is wrong here. We either parsed past input // then something is wrong here. We either parsed past input
@@ -431,12 +413,11 @@ Pkt4::toText() const {
output << ", transid=0x" << hex << transid_ << dec; output << ", transid=0x" << hex << transid_ << dec;
if (!options_.empty()) { if (!options_->empty()) {
output << "," << std::endl << "options:"; output << "," << std::endl << "options:";
for (isc::dhcp::OptionCollection::const_iterator opt = options_.begin(); for (const auto& opt : *options_) {
opt != options_.end(); ++opt) {
try { try {
output << std::endl << opt->second->toText(2); output << std::endl << opt.second->toText(2);
} catch (...) { } catch (...) {
output << "(unknown)" << std::endl; output << "(unknown)" << std::endl;
} }
@@ -597,5 +578,4 @@ Pkt4::isRelayed() const {
} }
} // end of namespace isc::dhcp } // end of namespace isc::dhcp
} // end of namespace isc } // end of namespace isc

View File

@@ -544,7 +544,6 @@ protected:
typedef boost::shared_ptr<Pkt4> Pkt4Ptr; typedef boost::shared_ptr<Pkt4> Pkt4Ptr;
} // isc::dhcp namespace } // isc::dhcp namespace
} // isc namespace } // isc namespace
#endif #endif

View File

@@ -44,15 +44,15 @@ std::string Pkt6::RelayInfo::toText() const {
<< "link-address=" << linkaddr_.toText() << "link-address=" << linkaddr_.toText()
<< ", peer-address=" << peeraddr_.toText() << ", " << ", peer-address=" << peeraddr_.toText() << ", "
<< options_.size() << " option(s)" << endl; << options_.size() << " option(s)" << endl;
for (auto option = options_.cbegin(); option != options_.cend(); ++option) { for (const auto& option : options_) {
tmp << option->second->toText() << endl; tmp << option.second->toText() << endl;
} }
return (tmp.str()); return (tmp.str());
} }
Pkt6::Pkt6(const uint8_t* buf, uint32_t buf_len, DHCPv6Proto proto /* = UDP */) Pkt6::Pkt6(const uint8_t* buf, uint32_t buf_len, DHCPv6Proto proto /* = UDP */)
:Pkt(buf, buf_len, DEFAULT_ADDRESS6, DEFAULT_ADDRESS6, 0, 0), : Pkt(buf, buf_len, DEFAULT_ADDRESS6, DEFAULT_ADDRESS6, 0, 0), proto_(proto),
proto_(proto), msg_type_(0) { msg_type_(0) {
} }
Pkt6::Pkt6(uint8_t msg_type, uint32_t transid, DHCPv6Proto proto /*= UDP*/) Pkt6::Pkt6(uint8_t msg_type, uint32_t transid, DHCPv6Proto proto /*= UDP*/)
@@ -231,9 +231,8 @@ uint16_t Pkt6::getRelayOverhead(const RelayInfo& relay) const {
uint16_t len = DHCPV6_RELAY_HDR_LEN // fixed header uint16_t len = DHCPV6_RELAY_HDR_LEN // fixed header
+ Option::OPTION6_HDR_LEN; // header of the relay-msg option + Option::OPTION6_HDR_LEN; // header of the relay-msg option
for (OptionCollection::const_iterator opt = relay.options_.begin(); for (const auto& opt : relay.options_) {
opt != relay.options_.end(); ++opt) { len += (opt.second)->len();
len += (opt->second)->len();
} }
return (len); return (len);
@@ -254,10 +253,8 @@ uint16_t Pkt6::calculateRelaySizes() {
uint16_t Pkt6::directLen() const { uint16_t Pkt6::directLen() const {
uint16_t length = DHCPV6_PKT_HDR_LEN; // DHCPv6 header uint16_t length = DHCPV6_PKT_HDR_LEN; // DHCPv6 header
for (OptionCollection::const_iterator it = options_.begin(); for (const auto& it : *options_) {
it != options_.end(); length += it.second->len();
++it) {
length += (*it).second->len();
} }
return (length); return (length);
@@ -311,10 +308,8 @@ Pkt6::packUDP() {
// present here as well (vendor-opts for Cable modems, // present here as well (vendor-opts for Cable modems,
// subscriber-id, remote-id, options echoed back from Echo // subscriber-id, remote-id, options echoed back from Echo
// Request Option, etc.) // Request Option, etc.)
for (OptionCollection::const_iterator opt = for (const auto& opt : relay->options_) {
relay->options_.begin(); (opt.second)->pack(buffer_out_);
opt != relay->options_.end(); ++opt) {
(opt->second)->pack(buffer_out_);
} }
// and include header relay-msg option. Its payload will be // and include header relay-msg option. Its payload will be
@@ -335,7 +330,7 @@ Pkt6::packUDP() {
buffer_out_.writeUint8( (transid_) & 0xff ); buffer_out_.writeUint8( (transid_) & 0xff );
// the rest are options // the rest are options
LibDHCP::packOptions6(buffer_out_, options_); LibDHCP::packOptions6(buffer_out_, *options_);
} }
catch (const Exception& e) { catch (const Exception& e) {
// An exception is thrown and message will be written to Logger // An exception is thrown and message will be written to Logger
@@ -417,7 +412,7 @@ Pkt6::unpackMsg(OptionBuffer::const_iterator begin,
// If custom option parsing function has been set, use this function // If custom option parsing function has been set, use this function
// to parse options. Otherwise, use standard function from libdhcp. // 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 // 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 // either parsed past input buffer (bug in our code) or we haven't parsed
@@ -632,18 +627,16 @@ Pkt6::toText() const {
hex << transid_ << dec << endl; hex << transid_ << dec << endl;
// Then print the options // Then print the options
for (isc::dhcp::OptionCollection::const_iterator opt=options_.begin(); for (const auto& opt : *options_) {
opt != options_.end(); tmp << opt.second->toText() << std::endl;
++opt) {
tmp << opt->second->toText() << std::endl;
} }
// Finally, print the relay information (if present) // Finally, print the relay information (if present)
if (!relay_info_.empty()) { if (!relay_info_.empty()) {
tmp << relay_info_.size() << " relay(s):" << endl; tmp << relay_info_.size() << " relay(s):" << endl;
int cnt = 0; int cnt = 0;
for (auto relay = relay_info_.cbegin(); relay != relay_info_.cend(); ++relay) { for (const auto& relay : relay_info_) {
tmp << "relay[" << cnt++ << "]: " << relay->toText(); tmp << "relay[" << cnt++ << "]: " << relay.toText();
} }
} else { } else {
tmp << "No relays traversed." << endl; tmp << "No relays traversed." << endl;
@@ -671,7 +664,7 @@ Pkt6::getClientId() const {
isc::dhcp::OptionCollection isc::dhcp::OptionCollection
Pkt6::getNonCopiedOptions(const uint16_t opt_type) const { Pkt6::getNonCopiedOptions(const uint16_t opt_type) const {
std::pair<OptionCollection::const_iterator, 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)); return (OptionCollection(range.first, range.second));
} }
@@ -680,7 +673,7 @@ Pkt6::getOptions(const uint16_t opt_type) {
OptionCollection options_copy; OptionCollection options_copy;
std::pair<OptionCollection::iterator, 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 // If options should be copied on retrieval, we should now iterate over
// matching options, copy them and replace the original ones with new // matching options, copy them and replace the original ones with new
// instances. // instances.