]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[5533] Added a negative cache flag (host manager tests to do)
authorFrancis Dupont <fdupont@isc.org>
Wed, 21 Feb 2018 16:48:01 +0000 (17:48 +0100)
committerFrancis Dupont <fdupont@isc.org>
Wed, 21 Feb 2018 16:48:01 +0000 (17:48 +0100)
src/lib/dhcpsrv/host.cc
src/lib/dhcpsrv/host.h
src/lib/dhcpsrv/host_mgr.cc
src/lib/dhcpsrv/tests/host_unittest.cc

index 562bfb4702f68f0ad547ade2096493d284a9fbe3..134c0acc58b06e910e3f282bbf67a62c889690a0 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2017 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-2018 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -92,7 +92,8 @@ Host::Host(const uint8_t* identifier, const size_t identifier_len,
       dhcp6_client_classes_(dhcp6_client_classes),
       next_server_(asiolink::IOAddress::IPV4_ZERO_ADDRESS()),
       server_host_name_(server_host_name), boot_file_name_(boot_file_name),
-      host_id_(0), cfg_option4_(new CfgOption()), cfg_option6_(new CfgOption()) {
+      host_id_(0), cfg_option4_(new CfgOption()),
+      cfg_option6_(new CfgOption()), negative_(false) {
 
     // Initialize host identifier.
     setIdentifier(identifier, identifier_len, identifier_type);
@@ -125,7 +126,8 @@ Host::Host(const std::string& identifier, const std::string& identifier_name,
       dhcp6_client_classes_(dhcp6_client_classes),
       next_server_(asiolink::IOAddress::IPV4_ZERO_ADDRESS()),
       server_host_name_(server_host_name), boot_file_name_(boot_file_name),
-      host_id_(0), cfg_option4_(new CfgOption()), cfg_option6_(new CfgOption()) {
+      host_id_(0), cfg_option4_(new CfgOption()),
+      cfg_option6_(new CfgOption()), negative_(false) {
 
     // Initialize host identifier.
     setIdentifier(identifier, identifier_name);
@@ -589,6 +591,11 @@ Host::toText() const {
           << "=" << *cclass;
     }
 
+    // Add negative cached.
+    if (negative_) {
+        s << " negative cached";
+    }
+
     return (s.str());
 }
 
index cf3466924b920a578a6d10561af51275832a984b..20d8e4e5542dc6850222b549bf8865d0ed0c8307 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2017 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-2018 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -546,6 +546,18 @@ public:
         return (host_id_);
     }
 
+    /// @brief Sets the negative cached flag.
+    ///
+    /// @param negative New valie for negative cache flag.
+    void setNegative(bool negative) {
+        negative_ = negative;
+    }
+
+    /// @brief Return the negative cache flag value.
+    bool getNegative() const {
+        return (negative_);
+    }
+
     /// @brief Unparses (converts to Element representation) IPv4 host
     ///
     /// @return Element representation of the host
@@ -604,6 +616,9 @@ private:
     CfgOptionPtr cfg_option4_;
     /// @brief Pointer to the DHCPv6 option data configuration for this host.
     CfgOptionPtr cfg_option6_;
+
+    /// @brief Negative cached flag.
+    bool negative_;
 };
 
 /// @brief Pointer to the @c Host object.
index 8b62d5423555e08d396aae61c11a78c669c6a98e..5892e480f568ef99662acc94e713a9f2f7d02561 100644 (file)
@@ -133,6 +133,9 @@ HostMgr::get4(const SubnetID& subnet_id, const HWAddrPtr& hwaddr,
             host = (*it)->get4(subnet_id, hwaddr, DuidPtr());
         }
     }
+    if (host && host->getNegative()) {
+        return (ConstHostPtr());
+    }
     return (host);
 }
 
@@ -168,6 +171,9 @@ HostMgr::get4(const SubnetID& subnet_id,
                 .arg((*it)->getType())
                 .arg(host->toText());
                      
+            if (host->getNegative()) {
+                return (ConstHostPtr());
+            }
             return (host);
         }
     }
@@ -194,6 +200,9 @@ HostMgr::get4(const SubnetID& subnet_id,
          !host && it != alternate_sources_.end(); ++it) {
         host = (*it)->get4(subnet_id, address);
     }
+    if (host && host->getNegative()) {
+        return (ConstHostPtr());
+    }
     return (host);
 }
 
@@ -220,6 +229,9 @@ HostMgr::get6(const SubnetID& subnet_id, const DuidPtr& duid,
             host = (*it)->get6(subnet_id, DuidPtr(), hwaddr);
         }
     }
+    if (host && host->getNegative()) {
+        return (ConstHostPtr());
+    }
     return (host);
 }
 
@@ -237,6 +249,9 @@ HostMgr::get6(const IOAddress& prefix, const uint8_t prefix_len) const {
          !host && it != alternate_sources_.end(); ++it) {
         host = (*it)->get6(prefix, prefix_len);
     }
+    if (host && host->getNegative()) {
+        return (ConstHostPtr());
+    }
     return (host);
 }
 
@@ -272,6 +287,10 @@ HostMgr::get6(const SubnetID& subnet_id,
                                                    identifier_len))
                     .arg((*it)->getType())
                     .arg(host->toText());
+
+                if (host->getNegative()) {
+                    return (ConstHostPtr());
+                }
                 return (host);
         }
     }
@@ -300,6 +319,9 @@ HostMgr::get6(const SubnetID& subnet_id,
          !host && it != alternate_sources_.end(); ++it) {
         host = (*it)->get6(subnet_id, addr);
     }
+    if (host && host->getNegative()) {
+        return (ConstHostPtr());
+    }
     return (host);
 }
 
index d3603fbae7197b9a9f391f3b60d2ecdcefaac96e..88216ed548c7f44e4baee73b4cf3606bcc5096fc 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2017 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-2018 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -669,6 +669,7 @@ TEST_F(HostTest, setValues) {
     ASSERT_EQ("192.0.2.3", host->getIPv4Reservation().toText());
     ASSERT_EQ("some-host.example.org", host->getHostname());
     ASSERT_FALSE(host->getContext());
+    ASSERT_FALSE(host->getNegative());
 
     host->setIPv4SubnetID(SubnetID(123));
     host->setIPv6SubnetID(SubnetID(234));
@@ -679,6 +680,7 @@ TEST_F(HostTest, setValues) {
     host->setBootFileName("bootfile.efi");
     std::string user_context = "{ \"foo\": \"bar\" }";
     host->setContext(Element::fromJSON(user_context));
+    host->setNegative(true);
 
     EXPECT_EQ(123, host->getIPv4SubnetID());
     EXPECT_EQ(234, host->getIPv6SubnetID());
@@ -689,6 +691,7 @@ TEST_F(HostTest, setValues) {
     EXPECT_EQ("bootfile.efi", host->getBootFileName());
     ASSERT_TRUE(host->getContext());
     EXPECT_EQ(user_context, host->getContext()->str());
+    EXPECT_TRUE(host->getNegative());
 
     // Remove IPv4 reservation.
     host->removeIPv4Reservation();
@@ -981,6 +984,7 @@ TEST_F(HostTest, toText) {
     host->setHostname("");
     host->removeIPv4Reservation();
     host->setIPv4SubnetID(0);
+    host->setNegative(true);
 
     EXPECT_EQ("hwaddr=010203040506 ipv6_subnet_id=2"
               " hostname=(empty) ipv4_reservation=(no)"
@@ -990,7 +994,8 @@ TEST_F(HostTest, toText) {
               " ipv6_reservation0=2001:db8:1::cafe"
               " ipv6_reservation1=2001:db8:1::1"
               " ipv6_reservation2=2001:db8:1:1::/64"
-              " ipv6_reservation3=2001:db8:1:2::/64",
+              " ipv6_reservation3=2001:db8:1:2::/64"
+              " negative cached",
               host->toText());
 
     // Create host identified by DUID, instead of HWADDR, with a very
@@ -1139,6 +1144,8 @@ TEST_F(HostTest, unparse) {
     // Add some classes.
     host->addClientClass4("modem");
     host->addClientClass4("router");
+    // Set invisible negative cache.
+    host->setNegative(true);
 
     EXPECT_EQ("{ "
               "\"boot-file-name\": \"\", "