]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
minor changes
authorAndrei Pavel <andrei.pavel@qualitance.com>
Wed, 13 Jul 2016 11:15:28 +0000 (14:15 +0300)
committerAndrei Pavel <andrei.pavel@qualitance.com>
Wed, 13 Jul 2016 11:15:28 +0000 (14:15 +0300)
src/bin/dhcp4/dhcp4.dox
src/bin/dhcp6/dhcp6.dox
src/lib/dhcp/libdhcp++.cc
src/lib/dhcp/libdhcp++.h
src/lib/dhcp/option.cc
src/lib/dhcp/pkt4.cc
src/lib/dhcp/pkt6.cc
src/lib/dhcp/tests/libdhcp++_unittest.cc
src/lib/dhcp/tests/option6_pdexclude_unittest.cc

index 6afd997a4b67c8184f52933e78acea42bbc4cc0d..1663d5da8c13f9175803eca6b345f86cc451e06d 100644 (file)
@@ -115,14 +115,14 @@ be stored in libdhcp++. Such option formats are stored in the
 of options which may be encapsulated by other options up to any level of
 encapsulation, but these functions are unaware of the option formats defined
 in the @ref isc::dhcp::CfgMgr because they belong to a different library.
-Therefore, the generic function @ref isc::dhcp::LibDHCP::unpackOptions is only
-useful to parse standard
+Therefore, the generic functions @ref isc::dhcp::LibDHCP::unpackOptions4 and
+@ref isc::dhcp::LibDHCP::unpackOptions6 are only useful to parse standard
 options whose definitions are provided in the libdhcp++. In order to overcome
 this problem a callback mechanism has been implemented in @c Option and @c Pkt4
 classes. By installing a callback function on an instance of @c Pkt4, the
 server may provide a custom implementation of the options parsing algorithm.
-This callback function will take precedence over the @c LibDHCP::unpackOptions
-function. With this approach, the callback is
+This callback function will take precedence over the @c LibDHCP::unpackOptions4
+and @c LibDHCP::unpackOptions6 functions. With this approach, the callback is
 implemented within the context of the server and it has access to all objects
 which define its configuration (including dynamically created option
 definitions).
index 05c172cd47d863a4e238b74b1be0798e779076f5..559206348ec4f5a11a5689f7d607bc1c9cfb0c49 100644 (file)
@@ -192,14 +192,14 @@ be stored in libdhcp++. Such option formats are stored in the
 of options which may be encapsulated by other options up to the any level of
 encapsulation but these functions are unaware of the option formats defined
 in the @ref isc::dhcp::CfgMgr because they belong to a different library.
-Therefore, the generic function @ref isc::dhcp::LibDHCP::unpackOptions is only
-useful to parse standard
+Therefore, the generic functions @ref isc::dhcp::LibDHCP::unpackOptions4 and
+@ref isc::dhcp::LibDHCP::unpackOptions6 are only useful to parse standard
 options whose definitions are provided in the libdhcp++. In order to overcome
 this problem a callback mechanism has been implemented in @c Option and @c Pkt6
 classes. By installing a callback function on the instance of the @c Pkt6 the
 server may provide a custom implementation of the options parsing algorithm.
-This callback function will take precedence over the @c LibDHCP::unpackOptions
- functions. With this approach, the callback is
+This callback function will take precedence over the @c LibDHCP::unpackOptions6
+and @c LibDHCP::unpackOptions4 functions. With this approach, the callback is
 implemented within the context of the server and it has access to all objects
 which define its configuration (including dynamically created option
 definitions).
index e7574a61f32b3f00ec920528f5b160a467013b05..27b9986e7ee470be6dd29d4404654af84a08618d 100644 (file)
@@ -132,7 +132,7 @@ LibDHCP::getVendorOptionDefs(const Option::Universe u, const uint32_t vendor_id)
             return getOptionDefs( Option::V6, ISC_V6_OPTION_SPACE );
         }
     }
-    isc_throw(isc::BadValue, "invalid universe " << u );
+    return OptionDefContainerPtr();
 }
 
 OptionDefinitionPtr
@@ -323,19 +323,23 @@ size_t LibDHCP::unpackOptions6(const OptionBuffer& buf,
     size_t last_offset = 0;
 
     // Get the list of standard option definitions.
-    const OptionDefContainerPtr& option_defs = LibDHCP::getOptionDefs(Option::V6);
-    // Runtime option definitions for non standard option space and if
-    // the definition doesn't exist within the standard option definitions.
-    const OptionDefContainerPtr& runtime_option_defs = LibDHCP::getRuntimeOptionDefs(option_space);
-
-    // @todo Once we implement other option spaces we should add else clause
-    // here and gather option definitions for them. For now leaving option_defs
-    // empty will imply creation of generic Option.
+    OptionDefContainer option_defs;
+    const OptionDefContainerPtr option_defs_ptr
+        = LibDHCP::getOptionDefs(Option::V6, option_space);
+    OptionDefContainer runtime_option_defs;
+    const OptionDefContainerPtr runtime_option_defs_ptr
+        = LibDHCP::getRuntimeOptionDefs(option_space);
+    if (option_defs_ptr) {
+        option_defs = *option_defs_ptr;
+    }
+    if (runtime_option_defs_ptr) {
+        runtime_option_defs = *runtime_option_defs_ptr;
+    }
 
     // Get the search indexes #1. It allows to search for option definitions
     // using option code.
-    const OptionDefContainerTypeIndex& idx = option_defs->get<1>();
-    const OptionDefContainerTypeIndex& runtime_idx = runtime_option_defs->get<1>();
+    const OptionDefContainerTypeIndex& idx = option_defs.get<1>();
+    const OptionDefContainerTypeIndex& runtime_idx = runtime_option_defs.get<1>();
 
     // The buffer being read comprises a set of options, each starting with
     // a two-byte type code and a two-byte length field.
@@ -459,15 +463,23 @@ size_t LibDHCP::unpackOptions4(const OptionBuffer& buf,
     size_t last_offset = 0;
 
     // Get the list of standard option definitions.
-    const OptionDefContainerPtr& option_defs = LibDHCP::getOptionDefs(Option::V4);
-    // Runtime option definitions for non standard option space and if
-    // the definition doesn't exist within the standard option definitions.
-    const OptionDefContainerPtr& runtime_option_defs = LibDHCP::getRuntimeOptionDefs(option_space);
+    OptionDefContainer option_defs;
+    const OptionDefContainerPtr option_defs_ptr
+        = LibDHCP::getOptionDefs(Option::V4, option_space);
+    OptionDefContainer runtime_option_defs;
+    const OptionDefContainerPtr runtime_option_defs_ptr
+        = LibDHCP::getRuntimeOptionDefs(option_space);
+    if (option_defs_ptr) {
+        option_defs = *option_defs_ptr;
+    }
+    if (runtime_option_defs_ptr) {
+        runtime_option_defs = *runtime_option_defs_ptr;
+    }
 
     // Get the search indexes #1. It allows to search for option definitions
     // using option code.
-    const OptionDefContainerTypeIndex& idx = option_defs->get<1>();
-    const OptionDefContainerTypeIndex& runtime_idx = runtime_option_defs->get<1>();
+    const OptionDefContainerTypeIndex& idx = option_defs.get<1>();
+    const OptionDefContainerTypeIndex& runtime_idx = runtime_option_defs.get<1>();
 
     // The buffer being read comprises a set of options, each starting with
     // a one-byte type code and a one-byte length field.
@@ -564,182 +576,6 @@ size_t LibDHCP::unpackOptions4(const OptionBuffer& buf,
     return (last_offset);
 }
 
-size_t LibDHCP::unpackOptions(const Option::Universe& universe,
-                              const OptionBuffer& buf,
-                              const std::string& option_space,
-                              isc::dhcp::OptionCollection& options,
-                              size_t* relay_msg_offset /* = NULL */,
-                              size_t* relay_msg_len /* = NULL */) {
-    // Sanity check
-    if (universe != Option::V4 || universe != Option::V6) {
-        return 0U; // no options parsed
-    }
-
-    if (universe == Option::V4) {
-        return unpackOptions4(buf, option_space, options);
-    } else if (universe == Option::V6){
-        return unpackOptions6(buf, option_space, options, relay_msg_offset, relay_msg_len);
-    } else {
-        return 0U;
-    }
-    /*
-
-    // Get the list of standard option definitions.
-    OptionDefContainer option_defs;
-    const OptionDefContainerPtr option_defs_ptr
-        = LibDHCP::getOptionDefs(universe, option_space);
-    OptionDefContainer runtime_option_defs;
-    const OptionDefContainerPtr runtime_option_defs_ptr
-        = LibDHCP::getRuntimeOptionDefs(option_space);
-    if (option_defs_ptr) {
-        option_defs = *option_defs_ptr;
-    }
-    if (runtime_option_defs_ptr) {
-        runtime_option_defs = *runtime_option_defs_ptr;
-    }
-
-    // Get the search indexes #1. It allows to search for option definitions
-    // using option code.
-    const OptionDefContainerTypeIndex& idx = option_defs.get<1>();
-    const OptionDefContainerTypeIndex& runtime_idx = runtime_option_defs.get<1>();
-
-    // The buffer being read comprises a set of options, each starting with
-    // a type code and a length field, both holding one byte (DHCPv4) or two
-    // bytes (DHCPv6).
-    const size_t element_size = universe == Option::V4 ? sizeof(uint8_t) : sizeof(uint16_t);
-    const size_t metadata_length = 2U * element_size;
-    const size_t length = buf.size();
-    size_t offset = 0U;
-    uint16_t opt_type = 0U;
-    uint16_t opt_len = 0U;
-    for (offset = 0U; offset < length; offset += metadata_length + opt_len) {
-        size_t useful_data_offset = offset + metadata_length;
-        // Parse the option header
-        if (universe == Option::V4) {
-            opt_type = buf[offset];
-            if (opt_type == DHO_PAD) {
-                // DHO_PAD is just a padding after DHO_END. Let's continue
-                // parsing in case we receive a message without DHO_END.
-                continue;
-            } else if (opt_type == DHO_END) {
-                // Just return. Don't need to add DHO_END option.
-                return offset;
-            } else if (useful_data_offset > length) {
-                // We peeked at the option header of the next option, but
-                // discovered that it would end up beyond buffer end, so
-                // the option is truncated. Hence we can't parse
-                // it. Therefore we revert back (as if we never parsed it).
-                //
-                // @note it is the responsibility of the caller to throw
-                // an exception on partial parsing
-                return offset;
-            }
-            opt_len = buf[offset + element_size];
-            if (useful_data_offset + opt_len > length) {
-                return offset;
-            }
-        } else if (universe == Option::V6) {
-            if (useful_data_offset > length) {
-                // We peeked at the option header of the next option, but
-                // discovered that it would end up beyond buffer end, so
-                // the option is truncated. Hence we can't parse
-                // it. Therefore we revert back (as if we never parsed it).
-                //
-                // @note it is the responsibility of the caller to throw
-                // an exception on partial parsing
-                return offset;
-            }
-            opt_type = isc::util::readUint16(&buf[offset], element_size);
-            opt_len = isc::util::readUint16(&buf[offset + element_size], element_size);
-            if (useful_data_offset + opt_len > length) {
-                // We peeked at the option header of the next option, but
-                // discovered that it would end up beyond buffer end, so
-                // the option is truncated. Hence we can't parse
-                // it. Therefore we revert back (as if we never parsed it).
-                //
-                // @note it is the responsibility of the caller to throw
-                // an exception on partial parsing
-                return offset;
-            }
-            if (opt_type == D6O_RELAY_MSG && relay_msg_offset && relay_msg_len) {
-                // Remember offset of the beginning of the relay-msg option.
-                *relay_msg_offset = useful_data_offset;
-                *relay_msg_len = opt_len;
-
-                // Do not create the relay-msg option.
-                continue;
-            } else if (opt_type == D6O_VENDOR_OPTS) {
-                const size_t ENTERPRISE_ID_LEN = 4U; // duid_factory.cc
-                if (useful_data_offset + ENTERPRISE_ID_LEN > length) {
-                    // Truncated vendor-option. We expect at least
-                    // 4 bytes for the enterprise-id field. Let's roll back
-                    // option code + option length (4 bytes) and return.
-                    return offset;
-                }
-
-                // Parse this as a vendor option.
-                OptionBufferConstIter begin = buf.begin() + useful_data_offset;
-                OptionPtr vendor_opt(new OptionVendor(Option::V6, begin, begin + opt_len));
-                options.insert(std::make_pair(opt_type, vendor_opt));
-                continue;
-            }
-        }
-
-        // Get all definitions with the particular option code. Note
-        // that option code is non-unique within this container
-        // however at this point we expect to get one option
-        // definition with the particular code. If more are returned
-        // we report an error.
-        OptionDefContainerTypeRange range;
-        // Number of option definitions returned.
-        size_t num_defs = 0U;
-        if (option_space == DHCP4_OPTION_SPACE ||
-                option_space == DHCP6_OPTION_SPACE) {
-            range = idx.equal_range(opt_type);
-            num_defs = distance(range.first, range.second);
-        }
-
-        // Standard option definitions do not include the definition for
-        // our option or we're searching for non-standard option. Try to
-        // find the definition among runtime option definitions.
-        if (num_defs == 0U) {
-            range = runtime_idx.equal_range(opt_type);
-            num_defs = distance(range.first, range.second);
-        }
-
-        OptionPtr opt;
-        if (num_defs > 1U) {
-            // Multiple options of the same code are not supported right now!
-            isc_throw(isc::Unexpected, "Internal error: multiple option"
-                      " definitions for option type " << opt_type <<
-                      " returned. Currently it is not supported to initialize"
-                      " multiple option definitions for the same option code."
-                      " This will be supported once support for option spaces"
-                      " is implemented");
-        } else if (num_defs == 0U) {
-            // @todo Don't crash if definition does not exist because
-            // only a few option definitions are initialized right
-            // now. In the future we will initialize definitions for
-            // all options and we will remove this elseif. For now,
-            // return generic option.
-            OptionBufferConstIter begin = buf.begin() + useful_data_offset;
-            opt = OptionPtr(new Option(universe, opt_type, begin, begin + opt_len));
-            //opt->setEncapsulatedSpace(DHCP4_OPTION_SPACE);
-        } else {
-            // The option definition has been found. Use it to create
-            // the option instance from the provided buffer chunk.
-            const OptionDefinitionPtr& def = *(range.first);
-            assert(def);
-            OptionBufferConstIter begin = buf.begin() + useful_data_offset;
-            opt = def->optionFactory(universe, opt_type, begin, begin + opt_len);
-        }
-
-        options.insert(std::make_pair(opt_type, opt));
-    }
-    return offset;
-    */
-}
-
 size_t LibDHCP::unpackVendorOptions6(const uint32_t vendor_id,
                                      const OptionBuffer& buf,
                                      isc::dhcp::OptionCollection& options) {
@@ -773,14 +609,13 @@ size_t LibDHCP::unpackVendorOptions6(const uint32_t vendor_id,
         offset += 2;
 
         if (offset + opt_len > length) {
-            isc_throw(OutOfRange, "Vendor option parse failed. Tried to parse " <<
-                          offset + opt_len << " bytes from " << length <<
-                          "-byte long buffer.");
+            isc_throw(OutOfRange, "Vendor option parse failed. "
+                      "Tried to parse " << offset + opt_len << " bytes from " <<
+                      length << "-byte long buffer.");
         }
 
         OptionPtr opt;
         opt.reset();
-        OptionBufferConstIter begin = buf.begin() + offset;
 
         // If there is a definition for such a vendor option...
         if (idx) {
@@ -809,7 +644,9 @@ size_t LibDHCP::unpackVendorOptions6(const uint32_t vendor_id,
                 // the option instance from the provided buffer chunk.
                 const OptionDefinitionPtr& def = *(range.first);
                 assert(def);
-                opt = def->optionFactory(Option::V6, opt_type, begin, begin + opt_len);
+                OptionBufferConstIter begin = buf.begin() + offset;
+                opt = def->optionFactory(Option::V6, opt_type, begin,
+                                         begin + opt_len);
             }
         }
 
@@ -819,7 +656,9 @@ size_t LibDHCP::unpackVendorOptions6(const uint32_t vendor_id,
         //    not defined
 
         if (!opt) {
-            opt = OptionPtr(new Option(Option::V6, opt_type, begin, begin + opt_len));
+            OptionBufferConstIter begin = buf.begin() + offset;
+            opt = OptionPtr(new Option(Option::V6, opt_type, begin,
+                                       begin + opt_len));
         }
 
         // add option to options
@@ -873,8 +712,8 @@ size_t LibDHCP::unpackVendorOptions4(const uint32_t vendor_id, const OptionBuffe
                 // treated as unsigned char value (a number is
                 // presented in error message).
                 isc_throw(OutOfRange,
-                          "Attempt to parse truncated vendor option "
-                          << static_cast<int>(opt_type));
+                          "Attempt to parse truncated vendor option " <<
+                          static_cast<int>(opt_type));
             }
 
             uint8_t opt_len =  buf[offset++];
@@ -886,7 +725,6 @@ size_t LibDHCP::unpackVendorOptions4(const uint32_t vendor_id, const OptionBuffe
 
             OptionPtr opt;
             opt.reset();
-            OptionBufferConstIter begin = buf.begin() + offset;
 
             if (idx) {
                 // Get all definitions with the particular option
@@ -904,8 +742,8 @@ size_t LibDHCP::unpackVendorOptions4(const uint32_t vendor_id, const OptionBuffe
                     // Multiple options of the same code are not
                     // supported right now!
                     isc_throw(isc::Unexpected, "Internal error: multiple"
-                              " option definitions for option type "
-                              << opt_type << " returned. Currently it is"
+                              " option definitions for option type " <<
+                              opt_type << " returned. Currently it is"
                               " not supported to initialize multiple option"
                               " definitions for the same option code."
                               " This will be supported once support for"
@@ -915,12 +753,16 @@ size_t LibDHCP::unpackVendorOptions4(const uint32_t vendor_id, const OptionBuffe
                     // the option instance from the provided buffer chunk.
                     const OptionDefinitionPtr& def = *(range.first);
                     assert(def);
-                    opt = def->optionFactory(Option::V4, opt_type, begin, begin + opt_len);
+                    OptionBufferConstIter begin = buf.begin() + offset;
+                    opt = def->optionFactory(Option::V4, opt_type, begin,
+                                             begin + opt_len);
                 }
             }
 
             if (!opt) {
-                opt = OptionPtr(new Option(Option::V4, opt_type, begin, begin + opt_len));
+                OptionBufferConstIter begin = buf.begin() + offset;
+                opt = OptionPtr(new Option(Option::V4, opt_type, begin,
+                                           begin + opt_len));
             }
 
             options.insert(std::make_pair(opt_type, opt));
@@ -982,7 +824,7 @@ void LibDHCP::OptionFactoryRegister(Option::Universe u,
     case Option::V6: {
         if (v6factories_.find(opt_type) != v6factories_.end()) {
             isc_throw(BadValue, "There is already DHCPv6 factory registered "
-                     << "for option type "  << opt_type);
+                      "for option type " << opt_type);
         }
         v6factories_[opt_type]=factory;
         return;
@@ -1002,7 +844,7 @@ void LibDHCP::OptionFactoryRegister(Option::Universe u,
         }
         if (v4factories_.find(opt_type)!=v4factories_.end()) {
             isc_throw(BadValue, "There is already DHCPv4 factory registered "
-                     << "for option type "  << opt_type);
+                      "for option type " << opt_type);
         }
         v4factories_[opt_type]=factory;
         return;
@@ -1069,11 +911,11 @@ void initOptionSpace(OptionDefContainerPtr& defs,
         std::string encapsulates(params[i].encapsulates);
         if (!encapsulates.empty() && params[i].array) {
             isc_throw(isc::BadValue, "invalid standard option definition: "
-                      << "option with code '" << params[i].code
-                      << "' may not encapsulate option space '"
-                      << encapsulates << "' because the definition"
-                      << " indicates that this option comprises an array"
-                      << " of values");
+                      "option with code '" << params[i].code <<
+                      "' may not encapsulate option space '" <<
+                      encapsulates << "' because the definition"
+                      " indicates that this option comprises an array"
+                      " of values");
         }
 
         // Depending whether an option encapsulates an option space or not
index 970a7123e99b11ac1915e1bf43ac2fc1de0817bc..d85b846e02307f19b850e91e9bacc4161dcc0fb4 100644 (file)
@@ -200,7 +200,7 @@ public:
     static void packOptions6(isc::util::OutputBuffer& buf,
                              const isc::dhcp::OptionCollection& options);
 
-    /// @brief Parses provided buffer as DHCPV4 or DHCPv6 options and creates
+    /// @brief Parses provided buffer as DHCPv6 options and creates
     /// Option objects.
     ///
     /// Parses provided buffer and stores created Option objects in
@@ -229,20 +229,30 @@ public:
     /// than once, and it calls option building routines which can throw.
     /// Partial parsing does not throw: it is the responsibility of the
     /// caller to handle this condition.
-    static size_t unpackOptions(const Option::Universe& universe,
-                                const OptionBuffer& buf,
-                                const std::string& option_space,
-                                isc::dhcp::OptionCollection& options,
-                                size_t* relay_msg_offset = NULL,
-                                size_t* relay_msg_len = NULL);
-    static size_t unpackOptions4(const OptionBuffer& buf,
-                                 const std::string& option_space,
-                                 isc::dhcp::OptionCollection& options);
     static size_t unpackOptions6(const OptionBuffer& buf,
                                  const std::string& option_space,
                                  isc::dhcp::OptionCollection& options,
-                                 size_t* relay_msg_offset = NULL,
-                                 size_t* relay_msg_len = NULL);
+                                 size_t* relay_msg_offset = 0,
+                                 size_t* relay_msg_len = 0);
+
+    /// @brief Parses provided buffer as DHCPv4 options and creates
+    /// Option objects.
+    ///
+    /// Parses provided buffer and stores created Option objects
+    /// in options container.
+    ///
+    /// @param buf Buffer to be parsed.
+    /// @param option_space A name of the option space which holds definitions
+    ///        to be used to parse options in the packets.
+    /// @param options Reference to option container. Options will be
+    ///        put here.
+    /// @return offset to the first byte after the last successfully
+    /// parsed option or the offset of the DHO_END option type.
+    ///
+    /// The unpackOptions6 note applies too.
+    static size_t unpackOptions4(const OptionBuffer& buf,
+                                 const std::string& option_space,
+                                 isc::dhcp::OptionCollection& options);
 
     /// Registers factory method that produces options of specific option types.
     ///
index bc763a143bd50dd35d929db169af05d820bebdb5..82e3593cfb24aeebe495503728a8853082679e2d 100644 (file)
@@ -155,10 +155,10 @@ void
 Option::unpackOptions(const OptionBuffer& buf) {
     switch (universe_) {
     case V4:
-        LibDHCP::unpackOptions(Option::V4, buf, getEncapsulatedSpace(), options_);
+        LibDHCP::unpackOptions4(buf, getEncapsulatedSpace(), options_);
         return;
     case V6:
-        LibDHCP::unpackOptions(Option::V6, buf, getEncapsulatedSpace(), options_);
+        LibDHCP::unpackOptions6(buf, getEncapsulatedSpace(), options_);
         return;
     default:
         isc_throw(isc::BadValue, "Invalid universe type " << universe_);
index edc639bbfb91463012bba4c677bc7b194870836b..b837277e6acc053452eefea1f73f116e1635c397 100644 (file)
@@ -203,8 +203,7 @@ Pkt4::unpack() {
     // a vector as an input.
     buffer_in.readVector(opts_buffer, opts_len);
 
-    size_t offset = LibDHCP::unpackOptions(Option::V4, opts_buffer,
-        DHCP4_OPTION_SPACE, options_);
+    size_t offset = LibDHCP::unpackOptions4(opts_buffer, DHCP4_OPTION_SPACE, options_);
 
     // If offset is not equal to the size and there is no DHO_END,
     // then something is wrong here. We either parsed past input
index e468525b09c640c0062e7414277f09cef981bbf0..25afd44469b504756a3105d377e8dbb14ec79aec 100644 (file)
@@ -403,8 +403,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::unpackOptions(Option::V6, 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
@@ -454,8 +453,8 @@ Pkt6::unpackRelayMsg() {
 
         // If custom option parsing function has been set, use this function
         // to parse options. Otherwise, use standard function from libdhcp.
-        LibDHCP::unpackOptions(Option::V6, opt_buffer, DHCP6_OPTION_SPACE,
-                               relay.options_, &relay_msg_offset, &relay_msg_len);
+        LibDHCP::unpackOptions6(opt_buffer, DHCP6_OPTION_SPACE, relay.options_,
+                                &relay_msg_offset, &relay_msg_len);
 
         /// @todo: check that each option appears at most once
         //relay.interface_id_ = options->getOption(D6O_INTERFACE_ID);
index ba1ab3b98eb1fc6361e0f06325f850be14ceb13b..5f8ea9eb68ca1c7ac87b0371da5c98d45cacc652 100644 (file)
@@ -420,9 +420,8 @@ TEST_F(LibDhcpTest, unpackOptions6) {
     memcpy(&buf[0], v6packed, sizeof(v6packed));
 
     EXPECT_NO_THROW ({
-        OptionBufferIter begin = buf.begin();
-        LibDHCP::unpackOptions(Option::V6, OptionBuffer(begin,
-            begin + sizeof(v6packed)), DHCP6_OPTION_SPACE, options);
+            LibDHCP::unpackOptions6(OptionBuffer(buf.begin(), buf.begin() + sizeof(v6packed)),
+                                    DHCP6_OPTION_SPACE, options);
     });
 
     EXPECT_EQ(options.size(), 6); // there should be 5 options
@@ -545,8 +544,8 @@ TEST_F(LibDhcpTest, unpackEmptyOption6) {
 
     // Parse options.
     OptionCollection options;
-    ASSERT_NO_THROW(LibDHCP::unpackOptions(Option::V6, buf, DHCP6_OPTION_SPACE,
-                                           options));
+    ASSERT_NO_THROW(LibDHCP::unpackOptions6(buf, DHCP6_OPTION_SPACE,
+                                            options));
 
     // There should be one option.
     ASSERT_EQ(1, options.size());
@@ -602,8 +601,7 @@ TEST_F(LibDhcpTest, unpackSubOptions6) {
 
     // Parse options.
     OptionCollection options;
-    ASSERT_NO_THROW(LibDHCP::unpackOptions(Option::V6, buf, "space-foobar",
-                                           options, 0, 0));
+    ASSERT_NO_THROW(LibDHCP::unpackOptions6(buf, "space-foobar", options, 0, 0));
 
     // There should be one top level option.
     ASSERT_EQ(1, options.size());
@@ -769,8 +767,7 @@ TEST_F(LibDhcpTest, unpackOptions4) {
     isc::dhcp::OptionCollection options; // list of options
 
     ASSERT_NO_THROW(
-        LibDHCP::unpackOptions(Option::V4, v4packed, DHCP4_OPTION_SPACE,
-                               options);
+        LibDHCP::unpackOptions4(v4packed, DHCP4_OPTION_SPACE, options);
     );
 
     isc::dhcp::OptionCollection::const_iterator x = options.find(12);
@@ -861,9 +858,9 @@ TEST_F(LibDhcpTest, unpackOptions4) {
     ASSERT_TRUE(rai);
     // RAI should have 3 sub-options: Circuit ID, Agent Remote ID, Vendor
     // Specific Information option. Note that by parsing these suboptions we
-    // are checking that unpackOptions differentiates between standard option
-    // space called "dhcp4" or "dhcp6" and other option spaces. These sub-options
-    // do not belong to standard option space and should be parsed using different
+    // are checking that unpackOptions4 differentiates between standard option
+    // space called "dhcp4" and other option spaces. These sub-options do not
+    // belong to standard option space and should be parsed using different
     // option definitions.
     // @todo Currently, definitions for option space "dhcp-agent-options-space"
     // are not defined. Therefore all suboptions will be represented here by
@@ -930,8 +927,8 @@ TEST_F(LibDhcpTest, unpackEmptyOption4) {
 
     // Parse options.
     OptionCollection options;
-    ASSERT_NO_THROW(LibDHCP::unpackOptions(Option::V4, buf, DHCP4_OPTION_SPACE,
-                                           options));
+    ASSERT_NO_THROW(LibDHCP::unpackOptions4(buf, DHCP4_OPTION_SPACE,
+                                            options));
 
     // There should be one option.
     ASSERT_EQ(1, options.size());
@@ -990,8 +987,7 @@ TEST_F(LibDhcpTest, unpackSubOptions4) {
 
     // Parse options.
     OptionCollection options;
-    ASSERT_NO_THROW(LibDHCP::unpackOptions(Option::V4, buf, "space-foobar",
-                                           options));
+    ASSERT_NO_THROW(LibDHCP::unpackOptions4(buf, "space-foobar", options));
 
     // There should be one top level option.
     ASSERT_EQ(1, options.size());
@@ -1703,8 +1699,8 @@ TEST_F(LibDhcpTest, vendorClass6) {
     isc::util::encode::decodeHex(vendor_class_hex, bin);
 
     ASSERT_NO_THROW ({
-        LibDHCP::unpackOptions(Option::V4, bin, DHCP6_OPTION_SPACE, options);
-    });
+            LibDHCP::unpackOptions6(bin, DHCP6_OPTION_SPACE, options);
+        });
 
     EXPECT_EQ(options.size(), 1); // There should be 1 option.
 
index eea68a8f25e0da20bb8420b29a70a5d2b8210f6f..5203cbed10f5103c26b53cf33d7eefa2cdeeb7a6 100644 (file)
@@ -25,12 +25,22 @@ const IOAddress cafe("2001:db8:dead:cafe::"); // /48 prefix length
 const IOAddress beef01("2001:db8:dead:beef::01"); // /56 prefix length
 
 // Description
-TEST(Option6PDExcludeTest, testName) {
+TEST(Option6PDExcludeTest, constructor) {
     Option6PDExclude option = Option6PDExclude(beef, 56, beef01, 60);
 
+    EXPECT_EQ(option.getDelegatedAddress(), beef);
+    EXPECT_EQ(option.getDelegatedPrefixLength(), 56);
+    EXPECT_EQ(option.getExcludedAddress(), beef01);
     EXPECT_EQ(option.getExcludedPrefixLength(), 60);
-    /*
+    EXPECT_EQ(option.len(), Option::OPTION6_HDR_LEN +
+        /* excluded_prefix_length_ AKA prefix-len is 1B */ 1 +
+        /* [delegated_prefix_length_ - excluded_prefix_length_](bytes) */ 1);
+}
+
+TEST(Option6PDExcludeTest, packing_and_unpacking) {
+    EXPECT_NO_THROW(isc_throw(Exception, "Not implemented yet."));
 
+    /*
     OptionBuffer data(option.getData());
 
     util::OutputBuffer buf(128);
@@ -47,19 +57,21 @@ TEST(Option6PDExcludeTest, testName) {
     EXPECT_EQ(option.getExcludedAddress(), unpackedOption.getExcludedAddress());
     EXPECT_EQ(option.getExcludedPrefixLength(),
             unpackedOption.getExcludedPrefixLength());
-            */
+    //*/
 }
 
 TEST(Option6PDExcludeTest, pool) {
-    //Pool6Ptr pool6Ptr = Pool6Ptr(new Pool6(Lease::TYPE_PD, beef, cafe));
-    //ASSERT_TRUE(pool6Ptr);
-    //ASSERT_GT(pool6Ptr->getPrefixExcludedLength(), 0);
+    EXPECT_NO_THROW(isc_throw(Exception, "Not implemented yet."));
+
     /*
+    Pool6Ptr pool6Ptr = Pool6Ptr(new Pool6(Lease::TYPE_PD, beef, cafe));
+    ASSERT_TRUE(pool6Ptr);
+    ASSERT_GT(pool6Ptr->getPrefixExcludedLength(), 0);
      OptionPtr opt(
      new Option6PDExclude((*l)->addr_, (*l)->prefixlen_,
      pool->getPrefixExcluded(),
      pool->getPrefixExcludedLength()));
-     */
+    //*/
 }
 
 } // anonymous namespace