Option6IAPrefix::Option6IAPrefix(uint16_t type, const isc::asiolink::IOAddress& prefix,
uint8_t prefix_len, uint32_t pref, uint32_t valid)
:Option6IAAddr(type, prefix, pref, valid), prefix_len_(prefix_len) {
+ // Option6IAAddr will check if prefix is IPv6 and will throw if it is not
+ if (prefix_len > 128) {
+ isc_throw(BadValue, prefix_len << " is not a valid prefix length. "
+ << "Allowed range is 0..128");
+ }
}
Option6IAPrefix::Option6IAPrefix(uint32_t type, OptionBuffer::const_iterator begin,
void Option6IAPrefix::pack(isc::util::OutputBuffer& buf) {
if (!addr_.isV6()) {
- isc_throw(isc::BadValue, addr_.toText()
- << " is not an IPv6 address");
+ isc_throw(isc::BadValue, addr_.toText() << " is not an IPv6 address");
}
buf.writeUint16(type_);
for (OptionCollection::const_iterator opt=options_.begin();
opt!=options_.end();
++opt) {
- tmp << (*opt).second->toText(indent+2);
+ tmp << (*opt).second->toText(indent + 2);
}
return tmp.str();
}
uint16_t length = OPTION6_HDR_LEN + OPTION6_IAPREFIX_LEN;
// length of all suboptions
- for (Option::OptionCollection::iterator it = options_.begin();
+ for (Option::OptionCollection::const_iterator it = options_.begin();
it != options_.end(); ++it) {
length += (*it).second->len();
}
/// @brief Class that represents IAPREFIX option in DHCPv6
///
-/// It is based on a similar class that handles addresses.
-/// The major differences are fields order and prefix has also
+/// It is based on a similar class that handles addresses. There are major
+/// differences, though. The fields are in different order. There is also
/// additional prefix length field.
///
-/// It should be noted that to get a full prefix (2 values: base address, and
+/// It should be noted that to get a full prefix (2 values: base prefix, and
/// a prefix length) 2 methods are used: getAddress() and getLength(). Although
-/// using getAddress() to obtain base address is somewhat counter-intuitive at
+/// using getAddress() to obtain base prefix is somewhat counter-intuitive at
/// first, it becomes obvious when one realizes that an address is a special
-/// case of a prefix with /128. It make everyone's like much easier, because
-/// the base address doubles as a regular address in many cases, e.g. when
+/// case of a prefix with /128. It makes everyone's like much easier, because
+/// the base prefix doubles as a regular address in many cases, e.g. when
/// searching for a lease.
class Option6IAPrefix : public Option6IAAddr {
/// length of the fixed part of the IAPREFIX option
static const size_t OPTION6_IAPREFIX_LEN = 25;
- /// @brief Ctor, used for options constructed (during transmission).
+ /// @brief Constructor, used for options constructed (during transmission).
///
/// @param type option type
/// @param addr reference to an address
Option6IAPrefix(uint16_t type, const isc::asiolink::IOAddress& addr,
uint8_t prefix_length, uint32_t preferred, uint32_t valid);
- /// @brief ctor, used for received options.
+ /// @brief Constructor, used for received options.
+ ///
+ /// @throw OutOfRange if buffer is too short
///
/// @param type option type
/// @param begin iterator to first byte of option data
/// Writes option in wire-format to buf, returns pointer to first unused
/// byte after stored option.
///
+ /// @throw BadValue if the address is not IPv6
+ ///
/// @param buf pointer to a buffer
void pack(isc::util::OutputBuffer& buf);
/// @brief Parses received buffer.
///
+ /// @throw OutOfRange when buffer is shorter than 25 bytes
+ ///
/// @param begin iterator to first byte of option data
/// @param end iterator to end of option data (first byte after option end)
virtual void unpack(OptionBufferConstIter begin,
/// @param indent number of spaces before printing text
///
/// @return string with text representation.
- virtual std::string
- toText(int indent = 0);
+ virtual std::string toText(int indent = 0);
/// sets address in this option.
///