Commit 925a6f65 authored by Marcin Siodelski's avatar Marcin Siodelski
Browse files

[3194] Cleanup in the OptionVendor class.

Added consts where applicable and extended comments.
parent 37f108c1
......@@ -18,7 +18,7 @@
using namespace isc::dhcp;
OptionVendor::OptionVendor(Option::Universe u, uint32_t vendor_id)
OptionVendor::OptionVendor(Option::Universe u, const uint32_t vendor_id)
:Option(u, u==Option::V4?DHO_VIVSO_SUBOPTIONS:D6O_VENDOR_OPTS), vendor_id_(vendor_id) {
}
......@@ -37,14 +37,18 @@ void OptionVendor::pack(isc::util::OutputBuffer& buf) {
// The format is slightly different for v4
if (universe_ == Option::V4) {
// Store data-len1 (it's a length of following suboptions
buf.writeUint8(len() - getHeaderLen() - sizeof(uint32_t) - sizeof(uint8_t));
// Calculate and store data-len as follows:
// data-len = total option length - header length
// - enterprise id field length - data-len field size
buf.writeUint8(len() - getHeaderLen() -
sizeof(uint32_t) - sizeof(uint8_t));
}
packOptions(buf);
}
void OptionVendor::unpack(OptionBufferConstIter begin, OptionBufferConstIter end) {
void OptionVendor::unpack(OptionBufferConstIter begin,
OptionBufferConstIter end) {
if (distance(begin, end) < sizeof(uint32_t)) {
isc_throw(OutOfRange, "Truncated vendor-specific information option"
<< ", length=" << distance(begin, end));
......
......@@ -25,16 +25,18 @@
namespace isc {
namespace dhcp {
/// This class represents vendor-specific information option.
/// As defined in RFC3925. The option formatting is slightly
/// @brief This class represents vendor-specific information option.
///
/// As specified in RFC3925, the option formatting is slightly different
/// for DHCPv4 than DHCPv6. The DHCPv4 Option includes additional field
/// holding vendor data length.
class OptionVendor: public Option {
public:
/// @brief Constructor.
///
/// @param u universe (V4 or V6)
/// @param vendor_id vendor enterprise-id (unique 32 bit integer)
OptionVendor(Option::Universe u, uint32_t vendor_id);
OptionVendor(Option::Universe u, const uint32_t vendor_id);
/// @brief Constructor.
///
......@@ -47,17 +49,15 @@ 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.
/// @todo Extend constructor to set encapsulated option space name.
OptionVendor(Option::Universe u, OptionBufferConstIter begin,
OptionBufferConstIter end);
/// Writes option in wire-format to buf, returns pointer to first unused
/// byte after stored option.
/// @brief Writes option in wire-format to buf, returns pointer to first
/// unused byte after stored option.
///
/// @param [out] buf buffer (option will be stored here)
void pack(isc::util::OutputBuffer& buf);
virtual void pack(isc::util::OutputBuffer& buf);
/// @brief Parses received buffer
///
......@@ -73,12 +73,12 @@ public:
/// @brief Sets enterprise identifier
///
/// @param value vendor identifier
void setVendorId(uint32_t vendor_id) { vendor_id_ = vendor_id; }
void setVendorId(const uint32_t vendor_id) { vendor_id_ = vendor_id; }
/// @brief Returns enterprise identifier
///
/// @return enterprise identifier
uint32_t getVendorId() const { return vendor_id_; }
uint32_t getVendorId() const { return (vendor_id_); }
/// @brief returns complete length of option
///
......@@ -89,7 +89,7 @@ public:
private:
uint32_t vendor_id_; ///< Enterprise-id
uint32_t vendor_id_; ///< Enterprise-id
};
/// Pointer to a vendor option
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment