From: Marcin Siodelski Date: Fri, 9 Jan 2015 18:48:32 +0000 (+0100) Subject: [3671] Created a function to read leases from multiple files. X-Git-Tag: trac3504_base~1^2~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=22ca0b54c141d037721bdf786321a4b743a38858;p=thirdparty%2Fkea.git [3671] Created a function to read leases from multiple files. --- diff --git a/src/lib/dhcpsrv/memfile_lease_mgr.cc b/src/lib/dhcpsrv/memfile_lease_mgr.cc index 43115323dd..a2a7956145 100644 --- a/src/lib/dhcpsrv/memfile_lease_mgr.cc +++ b/src/lib/dhcpsrv/memfile_lease_mgr.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2012-2014 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2012-2015 Internet Systems Consortium, Inc. ("ISC") // // Permission to use, copy, modify, and/or distribute this software for any // purpose with or without fee is hereby granted, provided that the above @@ -36,20 +36,14 @@ Memfile_LeaseMgr::Memfile_LeaseMgr(const ParameterMap& parameters) if (universe == "4") { std::string file4 = initLeaseFilePath(V4); if (!file4.empty()) { - lease_file4_.reset(new CSVLeaseFile4(file4)); - lease_file4_->open(); - storage4_.clear(); - LeaseFileLoader::load(*lease_file4_, storage4_, - MAX_LEASE_ERRORS); + loadLeasesFromFiles(file4, lease_file4_, + storage4_); } } else { std::string file6 = initLeaseFilePath(V6); if (!file6.empty()) { - lease_file6_.reset(new CSVLeaseFile6(file6)); - lease_file6_->open(); - storage6_.clear(); - LeaseFileLoader::load(*lease_file6_, storage6_, - MAX_LEASE_ERRORS); + loadLeasesFromFiles(file6, lease_file6_, + storage6_); } } @@ -480,3 +474,13 @@ Memfile_LeaseMgr::initLeaseFilePath(Universe u) { return (lease_file); } +template +void Memfile_LeaseMgr:: +loadLeasesFromFiles(const std::string& filename, + boost::shared_ptr& lease_file, + StorageType& storage) { + lease_file.reset(new LeaseFileType(filename)); + lease_file->open(); + storage.clear(); + LeaseFileLoader::load(*lease_file, storage, MAX_LEASE_ERRORS); +} diff --git a/src/lib/dhcpsrv/memfile_lease_mgr.h b/src/lib/dhcpsrv/memfile_lease_mgr.h index 8542ae87fe..76b4cc89a1 100644 --- a/src/lib/dhcpsrv/memfile_lease_mgr.h +++ b/src/lib/dhcpsrv/memfile_lease_mgr.h @@ -21,6 +21,8 @@ #include #include +#include + namespace isc { namespace dhcp { @@ -328,7 +330,7 @@ public: /// server shut down. bool persistLeases(Universe u) const; -protected: +private: /// @brief Initialize the location of the lease file. /// @@ -347,6 +349,42 @@ protected: /// argument to this function. std::string initLeaseFilePath(Universe u); + /// @brief Load leases from the persistent storage. + /// + /// This method loads DHCPv4 or DHCPv6 leases from lease files in the + /// following order: + /// - leases from the .2 + /// - leases from the .1 + /// - leases from the + /// + /// If any of the files doesn't exist the method proceeds to reading + /// leases from the subsequent file. If the doesn't exist + /// it is created. + /// + /// When the method successfully reads leases from the files, it leaves + /// the file open and its internal pointer is set to the + /// end of file. The server will append lease entries to this file as + /// a result of processing new messages from the clients. + /// + /// The .2 and .1 are the products of the lease + /// file cleanups (LFC). See: http://kea.isc.org/wiki/LFCDesign for + /// details. + /// + /// @param filename Name of the lease file. + /// @param lease_file An object representing a lease file to which + /// the server will store lease updates. + /// @param storage A storage for leases read from the lease file. + /// @tparam LeaseObjectType @c Lease4 or @c Lease6. + /// @tparam LeaseFileType @c CSVLeaseFile4 or @c CSVLeaseFile6. + /// @tparam StorageType @c Lease4Storage or @c Lease6Storage. + /// + /// @throw CSVFileError when parsing any of the lease files fails. + template + void loadLeasesFromFiles(const std::string& filename, + boost::shared_ptr& lease_file, + StorageType& storage); + /// @brief stores IPv4 leases Lease4Storage storage4_; @@ -364,4 +402,4 @@ protected: }; // end of isc::dhcp namespace }; // end of isc namespace -#endif // MEMFILE_LEASE_MGR +#endif // MEMFILE_LEASE_MGR_H