From: Tomek Mrugalski Date: Tue, 10 Sep 2013 09:50:59 +0000 (+0200) Subject: [3145] Several clean-ups in IAPREFIX option, prefix-len checked X-Git-Tag: bind10-1.2.0beta1-release~224^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=660f725b6fb6b326668d7c3c4395ec90b018535d;p=thirdparty%2Fkea.git [3145] Several clean-ups in IAPREFIX option, prefix-len checked --- diff --git a/src/lib/dhcp/option6_iaprefix.cc b/src/lib/dhcp/option6_iaprefix.cc index 403b11fc9a..f942405682 100644 --- a/src/lib/dhcp/option6_iaprefix.cc +++ b/src/lib/dhcp/option6_iaprefix.cc @@ -34,6 +34,11 @@ namespace dhcp { 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, @@ -44,8 +49,7 @@ Option6IAPrefix::Option6IAPrefix(uint32_t type, OptionBuffer::const_iterator beg 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_); @@ -99,7 +103,7 @@ std::string Option6IAPrefix::toText(int indent /* =0 */) { 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(); } @@ -109,7 +113,7 @@ uint16_t Option6IAPrefix::len() { 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(); } diff --git a/src/lib/dhcp/option6_iaprefix.h b/src/lib/dhcp/option6_iaprefix.h index dddf55644a..0a790beddc 100644 --- a/src/lib/dhcp/option6_iaprefix.h +++ b/src/lib/dhcp/option6_iaprefix.h @@ -25,16 +25,16 @@ namespace dhcp { /// @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 { @@ -42,7 +42,7 @@ public: /// 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 @@ -52,7 +52,9 @@ public: 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 @@ -65,11 +67,15 @@ public: /// 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, @@ -80,8 +86,7 @@ public: /// @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. ///