BIND 10 trac2312, updated. 0a5970240b9e8ae08e4a06b67a0678a19b5def45 [2312] Return option length.
BIND 10 source code commits
bind10-changes at lists.isc.org
Tue Nov 27 10:48:32 UTC 2012
The branch, trac2312 has been updated
via 0a5970240b9e8ae08e4a06b67a0678a19b5def45 (commit)
via c12d1b3b6e90a0918e498282b2374ac294258cdf (commit)
from a6c3266fe1acdfa5393f1cd2aa2a502615800943 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 0a5970240b9e8ae08e4a06b67a0678a19b5def45
Author: Marcin Siodelski <marcin at isc.org>
Date: Tue Nov 27 11:48:25 2012 +0100
[2312] Return option length.
commit c12d1b3b6e90a0918e498282b2374ac294258cdf
Author: Marcin Siodelski <marcin at isc.org>
Date: Tue Nov 27 11:48:06 2012 +0100
[2312] Updated doxygen comments in option_custom.h
-----------------------------------------------------------------------
Summary of changes:
src/lib/dhcp/option_custom.cc | 22 +++++++-----
src/lib/dhcp/option_custom.h | 76 +++++++++++++++++++++++++++++------------
2 files changed, 69 insertions(+), 29 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/dhcp/option_custom.cc b/src/lib/dhcp/option_custom.cc
index a6747f2..cdaa305 100644
--- a/src/lib/dhcp/option_custom.cc
+++ b/src/lib/dhcp/option_custom.cc
@@ -134,6 +134,10 @@ OptionCustom::pack6(isc::util::OutputBuffer& buf) {
void
OptionCustom::readAddress(const uint32_t index, asiolink::IOAddress& address) const {
checkIndex(index);
+
+ // The address being read can be either IPv4 or IPv6. The decision
+ // is made based on the buffer length. If it holds 4 bytes it is IPv4
+ // address, if it holds 16 bytes it is IPv6.
if (buffers_[index].size() == asiolink::V4ADDRESS_LEN) {
OptionDataTypeUtil::readAddress(buffers_[index], AF_INET, address);
} else if (buffers_[index].size() == asiolink::V6ADDRESS_LEN) {
@@ -170,22 +174,22 @@ OptionCustom::unpack(OptionBufferConstIter begin,
uint16_t
OptionCustom::len() {
- // Returns length of the complete option (data length + DHCPv4/DHCPv6
- // option header)
+ // The length of the option is a sum of option header ...
+ int length = getHeaderLen();
- // length of the whole option is header and data stored in this option...
- int length = getHeaderLen() + data_.size();
+ // ... lengths of all buffers that hold option data ...
+ for (std::vector<OptionBuffer>::const_iterator buf = buffers_.begin();
+ buf != buffers_.end(); ++buf) {
+ length += buf.size();
+ }
- // ... and sum of lengths of all suboptions
+ // ... and lengths of all suboptions
for (OptionCustom::OptionCollection::iterator it = options_.begin();
it != options_.end();
++it) {
length += (*it).second->len();
}
- // note that this is not equal to lenght field. This value denotes
- // number of bytes required to store this option. length option should
- // contain (len()-getHeaderLen()) value.
return (length);
}
@@ -225,6 +229,8 @@ void OptionCustom::setData(const OptionBufferConstIter first,
data_.resize(std::distance(first, last));
std::copy(first, last, data_.begin());
+ // Chop the data_ buffer into set of buffers that represent
+ // option fields data.
createBuffers();
}
diff --git a/src/lib/dhcp/option_custom.h b/src/lib/dhcp/option_custom.h
index d0c9a4d..ecf7167 100644
--- a/src/lib/dhcp/option_custom.h
+++ b/src/lib/dhcp/option_custom.h
@@ -38,66 +38,87 @@ namespace dhcp {
class OptionCustom : public Option {
public:
- class OptionFieldBuffer {
- public:
- OptionFieldBuffer(OptionDataType type,
- const OptionBuffer& buf)
- : type_(type), buf_(buf) {
- }
-
- const OptionBuffer& getBuffer() const {
- return (buf_);
- }
-
- OptionDataType getType() const {
- return (type_);
- }
-
- private:
- OptionDataType type_;
- OptionBuffer buf_;
- };
-
/// @brief Constructor, used for options to be sent.
///
+ /// @param def option definition.
/// @param u specifies universe (V4 or V6).
/// @param def option definition.
/// @param data content of the option.
+ ///
+ /// @throw OutOfRange if option buffer is truncated.
+ ///
+ /// @todo list all exceptions thrown by ctor.
OptionCustom(const OptionDefinition& def, Universe u, const OptionBuffer& data);
/// @brief Constructor, used for received options.
///
- /// @param u specifies universe (V4 or V6).
/// @param def option definition.
+ /// @param u specifies universe (V4 or V6).
/// @param first iterator to the first element that should be copied.
/// @param last iterator to the next element after the last one
/// to be copied.
+ ///
+ /// @throw OutOfRange if option buffer is truncated.
+ ///
+ /// @todo list all exceptions thrown by ctor.
OptionCustom(const OptionDefinition& def, Universe u,
OptionBufferConstIter first, OptionBufferConstIter last);
+ /// @brief Read a buffer as IP address.
+ ///
+ /// @param index buffer index.
+ /// @param [out] address read IP address.
+ ///
+ /// @throw isc::OutOfRange if index is out of range.
void readAddress(const uint32_t index, asiolink::IOAddress& address) const;
+ /// @brief Read a buffer as binary data.
+ ///
+ /// @param index buffer index.
+ ///
+ /// @throw isc::OutOfRange if index is out of range.
+ /// @return read buffer holding binary data.
const OptionBuffer& readBinary(const uint32_t index) const;
+ /// @brief Read a buffer as boolean value.
+ ///
+ /// @param index buffer index.
+ ///
+ /// @throw isc::OutOfRange if index is out of range.
+ /// @return read boolean value.
bool readBoolean(const uint32_t index) const;
+ /// @brief Read a buffer as integer value.
+ ///
+ /// @param index buffer index.
+ ///
+ /// @throw isc::OutOfRange if index is out of range.
+ /// @return read integer value.
template<typename T>
T readInteger(const uint32_t index) const {
checkIndex(index);
+ // Check that the requested return type is a supported integer.
if (!OptionDataTypeTraits<T>::integer_type) {
isc_throw(isc::dhcp::InvalidDataType, "specified data type to be returned"
" by readInteger is not supported integer type");
}
+ // Get the option definition type.
OptionDataType data_type = definition_.getType();
+ //
if (data_type == OPT_RECORD_TYPE) {
const OptionDefinition::RecordFieldsCollection& record_fields =
definition_.getRecordFields();
+ // When we initialized buffers we have already checked that
+ // the number of these buffers is equal to number of option
+ // fields in the record so the condition below should be met.
assert(index < record_fields.size());
+ // Get the data type to be returned.
data_type = record_fields[index];
}
+ // Requested data type must match the data type in a record.
if (OptionDataTypeTraits<T>::type != data_type) {
isc_throw(isc::dhcp::InvalidDataType,
"unable to read option field with index " << index
@@ -105,10 +126,19 @@ public:
<< data_type << " does not match the integer type"
<< "returned by the readInteger function.");
}
+ // When we created the buffer we have checked that it has a
+ // valid size so this condition here should be always fulfiled.
assert(buffers_[index].size() == OptionDataTypeTraits<T>::len);
+ // Read an integer value.
return (OptionDataTypeUtil::readInt<T>(buffers_[index]));
}
+ /// @brief Read a buffer as string value.
+ ///
+ /// @param index buffer index.
+ /// @param [out] value read string value.
+ ///
+ /// @throw isc::OutOfRange if index is out of range.
void readString(const uint32_t index, std::string& value) const;
/// @brief Parses received buffer.
@@ -173,8 +203,12 @@ private:
/// @brief Create collection of buffers representing data field values.
void createBuffers();
+ /// Option definition used to create an option.
OptionDefinition definition_;
+ /// The collection of buffers holding data for option fields.
+ /// The order of buffers corresponds to the order of option
+ /// fields.
std::vector<OptionBuffer> buffers_;
};
More information about the bind10-changes
mailing list