]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#591,!#313] kea-dhcp6 skips sanity checks for prefix leases
authorThomas Markwalder <tmark@isc.org>
Wed, 1 May 2019 18:05:55 +0000 (14:05 -0400)
committerThomas Markwalder <tmark@isc.org>
Wed, 1 May 2019 18:05:55 +0000 (14:05 -0400)
src/lib/dhcpsrv/sanity_checker.*
    SanityChecker::checkLease(Lease6Ptr& lease, bool current) - now
    simply returns if lease type is TYPE_PD.

src/lib/dhcpsrv/tests/lease_file_loader_unittest.cc
    TEST_F(LeaseFileLoaderTest, sanityChecker6PD) - new test to
    verify PD leases are not sanity checked

ChangeLog -  added proposed entry

ChangeLog
src/lib/dhcpsrv/sanity_checker.cc
src/lib/dhcpsrv/sanity_checker.h
src/lib/dhcpsrv/tests/lease_file_loader_unittest.cc

index c3687fe958c41815385438c65860cb69b9d07f48..6f071ce20108664a389267df1038100756f2c112 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+15xx.  [bug]           tmark
+       kea-dhcp6 now properly skips sanity checking prefix
+       leases.  Prior to this it was incorrectly subjecting
+       them to sanity checks during memfile lease file reloads
+       and then flagging the leases as incorrect.
+       (Gitlab #591,!#313, git TBD)
+
 1567.  [bug]           marcin
        Kea HTTP client now always includes Host header in all HTTP requests.
        The Host header is required in all HTTP/1.1 requests. This corrects
index 1de927c875f8b3e59dfe6325aae93d6d8dd5e9d7..6e512d09ed5ca8cdef60d72e941b9695176a6e99 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2019 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
@@ -26,6 +26,11 @@ void SanityChecker::checkLease(Lease4Ptr& lease, bool current) {
 }
 
 void SanityChecker::checkLease(Lease6Ptr& lease, bool current) {
+    // We only check IA_NAs currently.
+    if (lease->type_ != Lease::TYPE_NA) {
+        return;
+    }
+
     SrvConfigPtr cfg;
     if (current) {
         cfg = CfgMgr::instance().getCurrentCfg();
index c181fd44c5581d73cc19a74b1cd1b3d0c728cfe1..ad0ee24473c62d31be0da7b3856a55b0a5eb90d4 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2019 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
@@ -32,11 +32,12 @@ class SanityChecker {
     ///                config
     void checkLease(Lease4Ptr& lease, bool current = true);
 
-    /// @brief Sanity checks and possibly corrects an IPv4 lease
+    /// @brief Sanity checks and possibly corrects an IPv6 lease
     ///
     /// Depending on the sanity-checks/lease-checks parameter value (see
     /// @ref CfgConsistency for details), this code may print a warning,
-    /// correct subnet-id or discard the lease.
+    /// correct subnet-id or discard the lease.  Note that if the lease
+    /// type is TYPE_PD, it simply returns.
     ///
     /// @param lease Lease to be sanity-checked
     /// @param current specify whether to use current (true) or staging(false)
index ad2569847f12b476162471c72d457e7389776771..b8754cfa4a206d1950b96056b9225be1fbc4a61d 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2015-2018 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2015-2019 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
@@ -235,7 +235,7 @@ public:
         }
     }
 
-    /// @brief Checks if IPv4 lease loaded from file is sanity checked.
+    /// @brief Checks if IPv6 lease loaded from file is sanity checked.
     ///
     /// This method writes a simple lease file with one lease in it,
     /// then sets sanity checks to tested level, then tries to load
@@ -249,10 +249,13 @@ public:
     /// @param sanity level of sanity checks
     /// @param exp_present is the lease expected to be loaded (true = yes)
     /// @param exp_id expected subnet-id of the loaded lease
+    /// @param prefix_len length of the prefix if the lease created should be
+    /// a PD lease. Defaults to 0.
     void sanityChecks6(std::string lease, SubnetID lease_id,
                        std::string subnet_txt, SubnetID subnet_id,
                        CfgConsistency::LeaseSanity sanity,
-                       bool exp_present, SubnetID exp_id) {
+                       bool exp_present, SubnetID exp_id,
+                       unsigned int prefix_len=0) {
 
         // Create the subnet and add it to configuration.
         if (!subnet_txt.empty()) {
@@ -263,8 +266,9 @@ public:
         std::stringstream file_content;
 
         file_content << v6_hdr_ << lease << ",dd:de:ba:0d:1b:2e,"
-                     << "300,300," << static_cast<int>(lease_id)
-                     << ",150,0,8,0,0,0,,,1,\n";
+                     << "300,300," << static_cast<int>(lease_id) << ",150,"
+                     << static_cast<int>(prefix_len > 0 ? Lease::TYPE_PD : Lease::TYPE_NA)
+                     << ",8," << prefix_len << ",0,0,,,1,\n";
 
         ASSERT_NO_THROW(CfgMgr::instance().getStagingCfg()->getConsistency()
                     ->setLeaseSanityCheck(sanity));
@@ -820,4 +824,18 @@ TEST_F(LeaseFileLoaderTest, sanityChecker6Del) {
     sanityChecks6("2001::1", 1, "2001::/16", 2, CfgConsistency::LEASE_CHECK_DEL, false, 1);
 }
 
+// This test checks to make sure PD leases are not sanity checked,
+// and thus not discarded.
+TEST_F(LeaseFileLoaderTest, sanityChecker6PD) {
+    int prefix_len = 64;
+
+    // We check a prefix lease whose subnet-id does not exist and
+    // is clearly outside the only known subnet.
+    sanityChecks6("2001:1::", 2,   // create prefix lease in subnet 2
+                  "3001::/64", 1,  // create subnet 1
+                  CfgConsistency::LEASE_CHECK_DEL,
+                  true, 2,         // lease should still exist with subnet id of 2
+                  prefix_len);
+}
+
 } // end of anonymous namespace