]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2181] pkt now uses OptionCollectionPtr instead of OptionCollection
authorRazvan Becheriu <razvan@isc.org>
Thu, 24 Feb 2022 14:49:15 +0000 (16:49 +0200)
committerRazvan Becheriu <razvan@isc.org>
Sat, 5 Mar 2022 07:16:37 +0000 (07:16 +0000)
src/bin/dhcp6/dhcp6_srv.cc
src/bin/dhcp6/tests/dhcp6_client.cc
src/bin/perfdhcp/perf_pkt4.cc
src/bin/perfdhcp/perf_pkt6.cc
src/bin/perfdhcp/test_control.cc
src/lib/dhcp/option.h
src/lib/dhcp/pkt.cc
src/lib/dhcp/pkt.h
src/lib/dhcp/pkt4.cc
src/lib/dhcp/pkt4.h
src/lib/dhcp/pkt6.cc

index 555c566713124ea3c15cc68a8ac2a566f384e789..51becc86fd70a76d76f4dc74fb1ccdf5454c6605 100644 (file)
@@ -1080,7 +1080,7 @@ Dhcpv6Srv::processDhcp6Query(Pkt6Ptr& query, Pkt6Ptr& rsp) {
                                        *callout_handle);
         } catch (...) {
             // Make sure we don't orphan a parked packet.
-            HooksManager::drop("leases4_committed", query);
+            HooksManager::drop("leases6_committed", query);
             throw;
         }
 
@@ -1764,13 +1764,12 @@ Dhcpv6Srv::assignLeases(const Pkt6Ptr& question, Pkt6Ptr& answer,
     // 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);
             }
@@ -1779,7 +1778,7 @@ Dhcpv6Srv::assignLeases(const Pkt6Ptr& question, Pkt6Ptr& answer,
         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);
             }
@@ -2657,13 +2656,12 @@ Dhcpv6Srv::extendLeases(const Pkt6Ptr& query, Pkt6Ptr& reply,
     // 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);
             }
@@ -2673,7 +2671,7 @@ Dhcpv6Srv::extendLeases(const Pkt6Ptr& query, Pkt6Ptr& reply,
         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);
             }
@@ -2710,13 +2708,12 @@ Dhcpv6Srv::releaseLeases(const Pkt6Ptr& release, Pkt6Ptr& reply,
     // 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);
@@ -2725,7 +2722,7 @@ Dhcpv6Srv::releaseLeases(const Pkt6Ptr& release, Pkt6Ptr& reply,
         }
         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);
@@ -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.
     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) {
 
index d41d339c13cb89b1a2c1f7064dc1ea46000654fe..bbb6cd5ed98809db115d9d939a6b6e8c0d49cdfb 100644 (file)
@@ -139,26 +139,22 @@ Dhcp6Client::Dhcp6Client(boost::shared_ptr<NakedDhcpv6Srv>& srv) :
 
 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();
@@ -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.
-    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;
index 0bceb82ba927b8ca26ec30edb3722e4b505d792d..5c5e46bc158e1309805fad855a4fc39c7e55e267 100644 (file)
@@ -31,7 +31,7 @@ bool
 PerfPkt4::rawPack() {
     return (PktTransform::pack(dhcp::Option::V4,
                                data_,
-                               options_,
+                               *options_,
                                getTransidOffset(),
                                getTransid(),
                                buffer_out_));
@@ -42,7 +42,7 @@ PerfPkt4::rawUnpack() {
     uint32_t transid = getTransid();
     bool res = PktTransform::unpack(dhcp::Option::V4,
                                     data_,
-                                    options_,
+                                    *options_,
                                     getTransidOffset(),
                                     transid);
     if (res) {
index 066d8ba516143ce6a5dca33a3e947c3cb9f3d68a..948fbaf2449fed09f819eaf4fe999c4d8bd5b103 100644 (file)
@@ -35,7 +35,7 @@ bool
 PerfPkt6::rawPack() {
     return (PktTransform::pack(dhcp::Option::V6,
                                data_,
-                               options_,
+                               *options_,
                                getTransidOffset(),
                                getTransid(),
                                buffer_out_));
@@ -46,7 +46,7 @@ PerfPkt6::rawUnpack() {
     uint32_t transid = getTransid();
     bool res =  PktTransform::unpack(dhcp::Option::V6,
                                      data_,
-                                     options_,
+                                     *options_,
                                      getTransidOffset(),
                                      transid);
     if (res) {
index 78e4fb2fb7b288c85332d874455e1084437df0e1..51eada4d0583278b27daaf618bdc43abd0d2d16d 100644 (file)
@@ -722,7 +722,7 @@ TestControl::printRate() const {
 
     std::cout <<"***Malformed Packets***" << std::endl
               << "Malformed packets: " << ExchangeStats::malformed_pkts_
-             << std::endl;
+              << std::endl;
 }
 
 void
@@ -861,24 +861,23 @@ TestControl::address6Uniqueness(const Pkt6Ptr& pkt6, ExchangeType xchg_type) {
         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);
                 }
index 720e4fd434348d8c998e6758ec7b1898708069b8..806d1d87116d71d0d5f589e15f5720b118faccbb 100644 (file)
@@ -38,6 +38,7 @@ typedef boost::shared_ptr<Option> OptionPtr;
 
 /// 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;
 
index 907e38d7224f2dbeab0d674bbf0b3844e93d7459..0476adc057bd3a89390ba32a5a292066898a228d 100644 (file)
@@ -17,32 +17,17 @@ namespace dhcp {
 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");
@@ -54,13 +39,13 @@ Pkt::Pkt(const uint8_t* buf, uint32_t len, const isc::asiolink::IOAddress& local
 
 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());
@@ -68,8 +53,8 @@ Pkt::getNonCopiedOption(const uint16_t type) const {
 
 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;
@@ -81,10 +66,9 @@ Pkt::getOption(const uint16_t type) {
 
 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
@@ -138,7 +122,6 @@ void
 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));
 }
 
@@ -282,5 +265,5 @@ Pkt::getMACFromIPv6(const isc::asiolink::IOAddress& addr) {
     return (mac);
 }
 
-};
-};
+} // end of namespace isc::dhcp
+} // end of namespace isc
index 48d03eca1398a26630548c44da0b2684ce6f50d7..4462c3cab2611e230ee74344d7c80ba915d8c81c 100644 (file)
@@ -611,7 +611,7 @@ public:
     /// 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:
 
@@ -796,7 +796,7 @@ private:
 /// @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
index cd634ca3b6e665f05daf1494bb29a78c42d5c5fd..2f3f255c58e1b7f014f32dc959acb45667c68be3 100644 (file)
@@ -30,18 +30,10 @@ namespace isc {
 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);
 
@@ -49,18 +41,10 @@ Pkt4::Pkt4(uint8_t msg_type, uint32_t transid)
 }
 
 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
@@ -76,10 +60,8 @@ Pkt4::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);
@@ -137,7 +119,7 @@ Pkt4::pack() {
 
         // 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)
@@ -205,7 +187,7 @@ Pkt4::unpack() {
     // 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
@@ -431,12 +413,11 @@ Pkt4::toText() const {
 
     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;
             }
@@ -597,5 +578,4 @@ Pkt4::isRelayed() const {
 }
 
 } // end of namespace isc::dhcp
-
 } // end of namespace isc
index d1ee363e2d321686724ecdd4fe06d78879a452bb..f86580292cab0c6cacecc20b86aa93db492f14c1 100644 (file)
@@ -544,7 +544,6 @@ protected:
 typedef boost::shared_ptr<Pkt4> Pkt4Ptr;
 
 } // isc::dhcp namespace
-
 } // isc namespace
 
 #endif
index 3e951e5a997a144e45a673f6d533fdfc853217fa..f46032e4be0bc4c24eb3507ddb4b3e82f0532079 100644 (file)
@@ -33,8 +33,8 @@ namespace isc {
 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 {
@@ -44,20 +44,20 @@ 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() {
@@ -231,9 +231,8 @@ uint16_t Pkt6::getRelayOverhead(const RelayInfo& relay) const {
     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);
@@ -254,10 +253,8 @@ uint16_t Pkt6::calculateRelaySizes() {
 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);
@@ -311,10 +308,8 @@ Pkt6::packUDP() {
                 // 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
@@ -335,7 +330,7 @@ Pkt6::packUDP() {
         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
@@ -417,7 +412,7 @@ Pkt6::unpackMsg(OptionBuffer::const_iterator begin,
 
     // 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
@@ -632,18 +627,16 @@ Pkt6::toText() const {
         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;
@@ -671,7 +664,7 @@ Pkt6::getClientId() const {
 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));
 }
 
@@ -680,7 +673,7 @@ Pkt6::getOptions(const uint16_t opt_type) {
     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.