Parcourir la source

[master] Merge branch 'trac2365'

Marcin Siodelski il y a 12 ans
Parent
commit
d3c5e8d90a

+ 30 - 2
src/lib/dhcp/option.cc

@@ -114,7 +114,7 @@ Option::pack4(isc::util::OutputBuffer& buf) {
             buf.writeData(&data_[0], data_.size());
         }
 
-        LibDHCP::packOptions(buf, options_);
+        packOptions(buf);
 
     } else {
         isc_throw(BadValue, "Invalid universe type " << universe_);
@@ -131,18 +131,46 @@ void Option::pack6(isc::util::OutputBuffer& buf) {
             buf.writeData(&data_[0], data_.size());
         }
 
-        LibDHCP::packOptions6(buf, options_);
+        packOptions(buf);
     } else {
         isc_throw(BadValue, "Invalid universe type " << universe_);
     }
     return;
 }
 
+void
+Option::packOptions(isc::util::OutputBuffer& buf) {
+    switch (universe_) {
+    case V4:
+        LibDHCP::packOptions(buf, options_);
+        return;
+    case V6:
+        LibDHCP::packOptions6(buf, options_);
+        return;
+    default:
+        isc_throw(isc::BadValue, "Invalid universe type " << universe_);
+    }
+}
+
 void Option::unpack(OptionBufferConstIter begin,
                     OptionBufferConstIter end) {
     data_ = OptionBuffer(begin, end);
 }
 
+void
+Option::unpackOptions(const OptionBuffer& buf) {
+    switch (universe_) {
+    case V4:
+        LibDHCP::unpackOptions4(buf, options_);
+        return;
+    case V6:
+        LibDHCP::unpackOptions6(buf, options_);
+        return;
+    default:
+        isc_throw(isc::BadValue, "Invalid universe type " << universe_);
+    }
+}
+
 uint16_t Option::len() {
     // Returns length of the complete option (data length + DHCPv4/DHCPv6
     // option header)

+ 29 - 0
src/lib/dhcp/option.h

@@ -312,6 +312,35 @@ protected:
     /// @throw BadValue Universe is not V6.
     virtual void pack6(isc::util::OutputBuffer& buf);
 
+    /// @brief Store sub options in a buffer.
+    ///
+    /// This method stores all sub-options defined for a particular
+    /// option in a on-wire format in output buffer provided.
+    /// This function is called by pack function in this class or
+    /// derived classes that override pack.
+    ///
+    /// @param [out] buf output buffer.
+    ///
+    /// @todo The set of exceptions thrown by this function depend on
+    /// exceptions thrown by pack methods invoked on objects
+    /// representing sub options. We should consider whether to aggregate
+    /// those into one exception which can be documented here.
+    void packOptions(isc::util::OutputBuffer& buf);
+
+    /// @brief Builds a collection of sub options from the buffer.
+    ///
+    /// This method parses the provided buffer and builds a collection
+    /// of objects representing sub options. This function may throw
+    /// different exceptions when option assembly fails.
+    ///
+    /// @param buf buffer to be parsed.
+    ///
+    /// @todo The set of exceptions thrown by this function depend on
+    /// exceptions thrown by unpack methods invoked on objects
+    /// representing sub options. We should consider whether to aggregate
+    /// those into one exception which can be documented here.
+    void unpackOptions(const OptionBuffer& buf);
+
     /// @brief A private method used for option correctness.
     ///
     /// It is used in constructors. In there are any problems detected

+ 2 - 2
src/lib/dhcp/option6_ia.cc

@@ -44,7 +44,7 @@ void Option6IA::pack(isc::util::OutputBuffer& buf) {
     buf.writeUint32(t1_);
     buf.writeUint32(t2_);
 
-    LibDHCP::packOptions6(buf, options_);
+    packOptions(buf);
 }
 
 void Option6IA::unpack(OptionBufferConstIter begin,
@@ -62,7 +62,7 @@ void Option6IA::unpack(OptionBufferConstIter begin,
     t2_ = readUint32( &(*begin) );
     begin += sizeof(uint32_t);
 
-    LibDHCP::unpackOptions6(OptionBuffer(begin, end), options_);
+    unpackOptions(OptionBuffer(begin, end));
 }
 
 std::string Option6IA::toText(int indent /* = 0*/) {

+ 3 - 2
src/lib/dhcp/option6_iaaddr.cc

@@ -59,7 +59,7 @@ void Option6IAAddr::pack(isc::util::OutputBuffer& buf) {
     buf.writeUint32(valid_);
 
     // parse suboption (there shouldn't be any for IAADDR)
-    LibDHCP::packOptions6(buf, options_);
+    packOptions(buf);
 }
 
 void Option6IAAddr::unpack(OptionBuffer::const_iterator begin,
@@ -77,7 +77,8 @@ void Option6IAAddr::unpack(OptionBuffer::const_iterator begin,
 
     valid_ = readUint32( &(*begin) );
     begin += sizeof(uint32_t);
-    LibDHCP::unpackOptions6(OptionBuffer(begin, end), options_);
+
+    unpackOptions(OptionBuffer(begin, end));
 }
 
 std::string Option6IAAddr::toText(int indent /* =0 */) {

+ 2 - 2
src/lib/dhcp/option6_int.h

@@ -104,7 +104,7 @@ public:
         default:
             isc_throw(dhcp::InvalidDataType, "non-integer type");
         }
-        LibDHCP::packOptions6(buf, options_);
+        packOptions(buf);
     }
 
     /// @brief Parses received buffer
@@ -149,7 +149,7 @@ public:
         // of clang complain about unresolved reference to
         // OptionDataTypeTraits structure during linking.
         begin += data_size_len;
-        LibDHCP::unpackOptions6(OptionBuffer(begin, end), options_);
+        unpackOptions(OptionBuffer(begin, end));
     }
 
     /// @brief Set option value.