Browse Source

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

Marcin Siodelski 10 years ago
parent
commit
07a3335970
3 changed files with 18 additions and 3 deletions
  1. 9 0
      src/lib/dhcpsrv/host.cc
  2. 4 3
      src/lib/dhcpsrv/host.h
  3. 5 0
      src/lib/dhcpsrv/tests/host_unittest.cc

+ 9 - 0
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_ &&

+ 4 - 3
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 {

+ 5 - 0
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) {