Commit 07a33359 authored by Marcin Siodelski's avatar Marcin Siodelski
Browse files

[3560] Disallow IPv4 and IPv6 multicast addresses for IPv6 reservations.

parent da9288ba
......@@ -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_ &&
......
......@@ -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 {
......
......@@ -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) {
......
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