From: Marcin Siodelski Date: Tue, 14 Oct 2014 10:15:55 +0000 (+0200) Subject: [3560] Disallow IPv4 and IPv6 multicast addresses for IPv6 reservations. X-Git-Tag: trac3162a_base~3^2~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=07a333597044527df59e4a0e4ef996c5eeb165d7;p=thirdparty%2Fkea.git [3560] Disallow IPv4 and IPv6 multicast addresses for IPv6 reservations. --- diff --git a/src/lib/dhcpsrv/host.cc b/src/lib/dhcpsrv/host.cc index 49cafea0ae..0a5054c53a 100644 --- a/src/lib/dhcpsrv/host.cc +++ b/src/lib/dhcpsrv/host.cc @@ -19,6 +19,15 @@ namespace isc { namespace dhcp { +IPv6Resrv::IPv6Resrv(const asiolink::IOAddress& prefix, + const uint8_t prefix_len) + : prefix_(prefix), prefix_len_(prefix_len) { + if (!prefix.isV6() || prefix.isV6Multicast()) { + isc_throw(isc::BadValue, "invalid prefix '" << prefix + << " for new IPv6 reservation"); + } +} + bool IPv6Resrv::operator==(const IPv6Resrv& other) const { return (prefix_ == other.prefix_ && diff --git a/src/lib/dhcpsrv/host.h b/src/lib/dhcpsrv/host.h index ebff21c071..8eed26529f 100644 --- a/src/lib/dhcpsrv/host.h +++ b/src/lib/dhcpsrv/host.h @@ -56,10 +56,11 @@ public: /// /// @param prefix Address or prefix to be reserved. /// @param prefix_len Prefix length. + /// + /// @throw isc::BadValue if address is not IPv6 address or is a + /// multicast address. IPv6Resrv(const asiolink::IOAddress& prefix, - const uint8_t prefix_len = 128) - : prefix_(prefix), prefix_len_(prefix_len) { - } + const uint8_t prefix_len = 128); /// @brief Returns prefix for the reservation. const asiolink::IOAddress& getPrefix() const { diff --git a/src/lib/dhcpsrv/tests/host_unittest.cc b/src/lib/dhcpsrv/tests/host_unittest.cc index eee372a076..f0db9c1753 100644 --- a/src/lib/dhcpsrv/tests/host_unittest.cc +++ b/src/lib/dhcpsrv/tests/host_unittest.cc @@ -42,6 +42,11 @@ TEST(IPv6ResrvTest, constructorPrefix) { EXPECT_EQ(IPv6Resrv::TYPE_PD, resrv.getType()); } +TEST(IPv6ResrvTest, constructorInvalidPrefix) { + EXPECT_THROW(IPv6Resrv(IOAddress("10.0.0.1"), 128), isc::BadValue); + EXPECT_THROW(IPv6Resrv(IOAddress("ff02:1::2"), 128), isc::BadValue); +} + // This test verifies that it is possible to modify prefix and its // length in an existing reservation. TEST(IPv6ResrvTest, setPrefix) {