From: Marcin Siodelski Date: Wed, 17 Oct 2012 20:41:48 +0000 (+0200) Subject: [2304] Applied changes suggested in the second code review. X-Git-Tag: trac2402_base~5^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b617d1a26e4e4fd536b37848b1dd39ff40f5213b;p=thirdparty%2Fkea.git [2304] Applied changes suggested in the second code review. --- diff --git a/src/lib/dhcp/option6_int.h b/src/lib/dhcp/option6_int.h index cdc625ecb4..02df9ab17b 100644 --- a/src/lib/dhcp/option6_int.h +++ b/src/lib/dhcp/option6_int.h @@ -44,6 +44,9 @@ public: /// /// @param type option type. /// @param value option value. + /// + /// @throw isc::dhcp::InvalidDataType if data field type provided + /// as template parameter is not a supported integer type. Option6Int(uint16_t type, T value) : Option(Option::V6, type), value_(value) { if (!OptionDataTypes::valid) { @@ -62,6 +65,8 @@ public: /// @param end iterator to end of option data (first byte after option end). /// /// @throw isc::OutOfRange if provided buffer is shorter than data size. + /// @throw isc::dhcp::InvalidDataType if data field type provided + /// as template parameter is not a supported integer type. Option6Int(uint16_t type, OptionBufferConstIter begin, OptionBufferConstIter end) : Option(Option::V6, type) { @@ -76,7 +81,9 @@ public: /// /// @param [out] buf buffer (option will be stored here) /// - /// @throw isc::BadValue if invalid option type has been provided. + /// @throw isc::dhcp::InvalidDataType if size of a data field type is not + /// equal to 1, 2 or 4 bytes. The data type is not checked in this function + /// because it is checked in a constructor. void pack(isc::util::OutputBuffer& buf) { buf.writeUint16(type_); buf.writeUint16(len() - OPTION6_HDR_LEN); @@ -110,6 +117,9 @@ public: /// @param end iterator to end of option data (first byte after option end) /// /// @throw isc::OutOfRange if provided buffer is shorter than data size. + /// @throw isc::dhcp::InvalidDataType if size of a data field type is not + /// equal to 1, 2 or 4 bytes. The data type is not checked in this function + /// because it is checked in a constructor. virtual void unpack(OptionBufferConstIter begin, OptionBufferConstIter end) { if (distance(begin, end) < sizeof(T)) { isc_throw(OutOfRange, "Option " << getType() << " truncated"); diff --git a/src/lib/dhcp/option6_int_array.h b/src/lib/dhcp/option6_int_array.h index a88e5392d1..b6b2369391 100644 --- a/src/lib/dhcp/option6_int_array.h +++ b/src/lib/dhcp/option6_int_array.h @@ -53,6 +53,9 @@ public: /// Creates option with empty values vector. /// /// @param type option type. + /// + /// @throw isc::dhcp::InvalidDataType if data field type provided + /// as template parameter is not a supported integer type. Option6IntArray(uint16_t type) : Option(Option::V6, type), values_(0) { @@ -68,6 +71,8 @@ public: /// /// @throw isc::OutOfRange if provided buffer is empty or its length /// is not multiple of size of the data type in bytes. + /// @throw isc::dhcp::InvalidDataType if data field type provided + /// as template parameter is not a supported integer type. Option6IntArray(uint16_t type, const OptionBuffer& buf) : Option(Option::V6, type) { if (!OptionDataTypes::valid) { @@ -88,6 +93,8 @@ public: /// /// @throw isc::OutOfRange if provided buffer is empty or its length /// is not multiple of size of the data type in bytes. + /// @throw isc::dhcp::InvalidDataType if data field type provided + /// as template parameter is not a supported integer type. Option6IntArray(uint16_t type, OptionBufferConstIter begin, OptionBufferConstIter end) : Option(Option::V6, type) { @@ -102,7 +109,9 @@ public: /// /// @param [out] buf buffer (option will be stored here) /// - /// @throw isc::BadValue if invalid option type has been provided. + /// @throw isc::dhcp::InvalidDataType if size of a data fields type is not + /// equal to 1, 2 or 4 bytes. The data type is not checked in this function + /// because it is checked in a constructor. void pack(isc::util::OutputBuffer& buf) { buf.writeUint16(type_); buf.writeUint16(len() - OPTION6_HDR_LEN); @@ -138,6 +147,10 @@ public: /// /// @param begin iterator to first byte of option data /// @param end iterator to end of option data (first byte after option end) + /// + /// @throw isc::dhcp::InvalidDataType if size of a data fields type is not + /// equal to 1, 2 or 4 bytes. The data type is not checked in this function + /// because it is checked in a constructor. virtual void unpack(OptionBufferConstIter begin, OptionBufferConstIter end) { if (distance(begin, end) == 0) { isc_throw(OutOfRange, "option " << getType() << " empty"); diff --git a/src/lib/dhcp/option_definition.cc b/src/lib/dhcp/option_definition.cc index a4d3405b68..f562316a0a 100644 --- a/src/lib/dhcp/option_definition.cc +++ b/src/lib/dhcp/option_definition.cc @@ -165,12 +165,6 @@ OptionDefinition::validate() const { bool OptionDefinition::haveIAx6Format(OptionDefinition::DataType first_type) const { - // Expect that IA_NA option format is defined as record. - // Although it consists of 3 elements of the same (uint32) - // type it can't be defined as array of uint32 elements because - // arrays do not impose limitations on number of elements in - // the array while this limitation is needed for IA_NA - need - // exactly 3 elements. return (haveType(RECORD_TYPE) && record_fields_.size() == 3 && record_fields_[0] == first_type && @@ -180,6 +174,12 @@ OptionDefinition::haveIAx6Format(OptionDefinition::DataType first_type) const { bool OptionDefinition::haveIA6Format() const { + // Expect that IA_NA option format is defined as record. + // Although it consists of 3 elements of the same (uint32) + // type it can't be defined as array of uint32 elements because + // arrays do not impose limitations on number of elements in + // the array while this limitation is needed for IA_NA - need + // exactly 3 elements. return (haveIAx6Format(UINT32_TYPE)); }