]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2236] split memfile version into v4 and v6
authorAndrei Pavel <andrei@isc.org>
Mon, 13 Dec 2021 18:22:21 +0000 (20:22 +0200)
committerAndrei Pavel <andrei@isc.org>
Sat, 8 Jan 2022 09:05:52 +0000 (11:05 +0200)
src/bin/dhcp4/dhcp4_srv.cc
src/bin/dhcp6/dhcp6_srv.cc
src/bin/lfc/lfc_controller.cc
src/lib/dhcpsrv/memfile_lease_mgr.cc
src/lib/dhcpsrv/memfile_lease_mgr.h

index ed3b56baa47cf8d690d9cb464599da164ae19292..7b765b457214eac89bc99e97c8e39a73a8c49006 100644 (file)
@@ -4033,7 +4033,7 @@ Dhcpv4Srv::getVersion(bool extended) {
 #ifdef HAVE_CQL
         tmp << CqlLeaseMgr::getDBVersion() << endl;
 #endif
-        tmp << Memfile_LeaseMgr::getDBVersion();
+        tmp << Memfile_LeaseMgr::getDBVersion(Memfile_LeaseMgr::V4);
 
         // @todo: more details about database runtime
     }
index b0c16d346cd29d2608c3f865fedcc64eac4549f8..dd4d785f104606acd5701f3357065991673c6633 100644 (file)
@@ -4102,7 +4102,7 @@ Dhcpv6Srv::getVersion(bool extended) {
 #ifdef HAVE_CQL
         tmp << CqlLeaseMgr::getDBVersion() << endl;
 #endif
-        tmp << Memfile_LeaseMgr::getDBVersion();
+        tmp << Memfile_LeaseMgr::getDBVersion(Memfile_LeaseMgr::V6);
 
         // @todo: more details about database runtime
     }
index ebd95cf23683e11fcefb99479b293a47ab21d6cf..20f5cbe5465e23466b3af6827cba7a805dfe5e26 100644 (file)
@@ -325,8 +325,18 @@ LFCController::getVersion(const bool extended) const{
 
     version_stream << VERSION;
     if (extended) {
-        version_stream << std::endl << EXTENDED_VERSION << std::endl
-        << "database: " << isc::dhcp::Memfile_LeaseMgr::getDBVersion();
+        std::string db_version;
+        if (protocol_version_ == 4) {
+            db_version = Memfile_LeaseMgr::getDBVersion(Memfile_LeaseMgr::V4);
+        } else if (protocol_version_ == 6) {
+            db_version = Memfile_LeaseMgr::getDBVersion(Memfile_LeaseMgr::V6);
+        }
+        if (!db_version.empty()) {
+            db_version = "database: " + db_version;
+        }
+        version_stream << std::endl
+                       << EXTENDED_VERSION << std::endl
+                       << db_version;
     }
 
     return (version_stream.str());
index da1b31c61b0d04ec923cfed0c5b9acd6fabf7214..78923aa2e7a83d20528b82864896375e55ecebad 100644 (file)
@@ -625,8 +625,10 @@ private:
 
 // Explicit definition of class static constants.  Values are given in the
 // declaration so they're not needed here.
-const int Memfile_LeaseMgr::MAJOR_VERSION;
-const int Memfile_LeaseMgr::MINOR_VERSION;
+const int Memfile_LeaseMgr::MAJOR_VERSION_V4;
+const int Memfile_LeaseMgr::MINOR_VERSION_V4;
+const int Memfile_LeaseMgr::MAJOR_VERSION_V6;
+const int Memfile_LeaseMgr::MINOR_VERSION_V6;
 
 Memfile_LeaseMgr::Memfile_LeaseMgr(const DatabaseConnection::ParameterMap& parameters)
     : LeaseMgr(), lfc_setup_(), conn_(parameters), mutex_(new std::mutex) {
@@ -660,8 +662,9 @@ Memfile_LeaseMgr::Memfile_LeaseMgr(const DatabaseConnection::ParameterMap& param
         LOG_WARN(dhcpsrv_logger, DHCPSRV_MEMFILE_NO_STORAGE);
     } else  {
         if (conversion_needed) {
+            auto const& version(getVersion());
             LOG_WARN(dhcpsrv_logger, DHCPSRV_MEMFILE_CONVERTING_LEASE_FILES)
-                    .arg(MAJOR_VERSION).arg(MINOR_VERSION);
+                    .arg(version.first).arg(version.second);
         }
         lfcSetup(conversion_needed);
     }
@@ -679,11 +682,15 @@ Memfile_LeaseMgr::~Memfile_LeaseMgr() {
 }
 
 std::string
-Memfile_LeaseMgr::getDBVersion() {
+Memfile_LeaseMgr::getDBVersion(Universe const& u) {
     std::stringstream tmp;
-    tmp << "Memfile backend " << MAJOR_VERSION;
-    tmp << "." << MINOR_VERSION;
-    return (tmp.str());
+    tmp << "Memfile backend ";
+    if (u == V4) {
+        tmp << MAJOR_VERSION_V4 << "." << MINOR_VERSION_V4;
+    } else if (u == V6) {
+        tmp << MAJOR_VERSION_V6 << "." << MINOR_VERSION_V6;
+    }
+    return tmp.str();
 }
 
 bool
@@ -1655,6 +1662,17 @@ Memfile_LeaseMgr::getDescription() const {
     return (std::string("In memory database with leases stored in a CSV file."));
 }
 
+std::pair<uint32_t, uint32_t>
+Memfile_LeaseMgr::getVersion() const {
+    std::string const& universe(conn_.getParameter("universe"));
+    if (universe == "4") {
+        return std::make_pair(MAJOR_VERSION_V4, MINOR_VERSION_V4);
+    } else if (universe == "6") {
+        return std::make_pair(MAJOR_VERSION_V6, MINOR_VERSION_V6);
+    }
+    isc_throw(BadValue, "cannot determine version for universe " << universe);
+}
+
 void
 Memfile_LeaseMgr::commit() {
     LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_MEMFILE_COMMIT);
index f1dd01f2158bc7ffd4f5f16b78edd8549f5bf18a..376ae7338c8398a8aa4dfa00904ccae1e13e61e9 100644 (file)
@@ -79,21 +79,36 @@ class LFCSetup;
 class Memfile_LeaseMgr : public LeaseMgr {
 public:
 
-    /// @defgroup versions Specified memfile backend version.
-    ///
-    /// @brief Defines major version of the memfile backend.
+    /// @defgroup v4 memfile backend versions
     ///
     /// Version history:
     /// 1.0 - initial version (released in Kea 0.9)
-    /// 2.0 - hwaddr column added (to be released in Kea 0.9.1)
-    /// 2.1 - user context column add (to be released in Kea 1.5)
+    /// 2.0 - hwaddr column added (released in Kea 0.9.1)
+    /// 2.1 - user context column added (released in Kea 1.4.0)
     ///
     /// @{
-    static const int MAJOR_VERSION = 2;
+    /// @brief the major version of the v4 memfile backend
+    static const int MAJOR_VERSION_V4 = 2;
 
-    /// Defines minor version of the memfile backend.
-    static const int MINOR_VERSION = 1;
+    /// @brief the minor version of the v4 memfile backend
+    static const int MINOR_VERSION_V4 = 1;
+    /// @}
 
+    /// @defgroup v6 memfile backend versions
+    ///
+    /// Version history:
+    /// 1.0 - initial version (released in Kea 0.9)
+    /// 2.0 - hwaddr column added (released in Kea 0.9.1)
+    /// 3.0 - state column added (released in Kea 0.9.2)
+    /// 3.1 - user context column added (released in Kea 1.4.0)
+    /// 4.0 - hwtype,hwaddr_source columns added (released in Kea 2.1.2)
+    ///
+    /// @{
+    /// @brief the major version of the v6 memfile backend
+    static const int MAJOR_VERSION_V6 = 4;
+
+    /// @brief the minor version of the v6 memfile backend
+    static const int MINOR_VERSION_V6 = 0;
     /// @}
 
 
@@ -139,7 +154,7 @@ public:
     virtual ~Memfile_LeaseMgr();
 
     /// @brief Local version of getDBVersion() class method
-    static std::string getDBVersion();
+    static std::string getDBVersion(Universe const& u);
 
     /// @brief Adds an IPv4 lease.
     ///
@@ -821,9 +836,7 @@ public:
     ///
     /// @return Version number as a pair of unsigned integers.  "first" is the
     ///         major version number, "second" the minor number.
-    virtual std::pair<uint32_t, uint32_t> getVersion() const {
-        return (std::make_pair(MAJOR_VERSION, MINOR_VERSION));
-    }
+    virtual std::pair<uint32_t, uint32_t> getVersion() const;
 
     /// @brief Commit Transactions
     ///