memfile_lease_mgr.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  1. // Copyright (C) 2012-2015 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #ifndef MEMFILE_LEASE_MGR_H
  15. #define MEMFILE_LEASE_MGR_H
  16. #include <asiolink/interval_timer.h>
  17. #include <dhcp/hwaddr.h>
  18. #include <dhcpsrv/csv_lease_file4.h>
  19. #include <dhcpsrv/csv_lease_file6.h>
  20. #include <dhcpsrv/memfile_lease_storage.h>
  21. #include <dhcpsrv/lease_mgr.h>
  22. #include <dhcpsrv/mysql_connection.h>
  23. #include <util/process_spawn.h>
  24. #include <boost/scoped_ptr.hpp>
  25. #include <boost/shared_ptr.hpp>
  26. namespace isc {
  27. namespace dhcp {
  28. class LFCSetup;
  29. /// @brief Concrete implementation of a lease database backend using flat file.
  30. ///
  31. /// This class implements a lease database backend using CSV files to store
  32. /// DHCPv4 and DHCPv6 leases on disk. The format of the files is determined
  33. /// by the @c CSVLeaseFile4 and @c CSVLeaseFile6 classes.
  34. ///
  35. /// In order to obtain good performance, the backend stores leases
  36. /// incrementally, i.e. updates to leases are appended at the end of the lease
  37. /// file. To record the deletion of a lease, the lease record is appended to
  38. /// the lease file with the valid lifetime set to 0. However, this may result
  39. /// in a significant growth of the lease file size over time, because the lease
  40. /// file will contain many entries for each lease. In order to mitigate this
  41. /// problem, the backend implements the Lease File Cleanup mechanism which is
  42. /// described on the Kea wiki: http://kea.isc.org/wiki/LFCDesign.
  43. ///
  44. /// The backend installs an @c asiolink::IntervalTimer to periodically execute
  45. /// the @c Memfile_LeaseMgr::lfcCallback. This callback function controls
  46. /// the startup of the background process which removes redundant information
  47. /// from the lease file(s). Note that the @c asiolink::IntervalTimer uses
  48. /// @c asiolink::IOService to execute the callback. The @c LeaseMgr class
  49. /// creates this object, which can be obtained by the caller using the
  50. /// @c LeaseMgr::getIOService. The caller should later call an appropriate
  51. /// method, @c asio::io_service::poll_one to execute the callback when
  52. /// the timer is ready.
  53. ///
  54. /// When the backend is starting up, it reads leases from the lease file (one
  55. /// by one) and adds them to the in-memory container as follows:
  56. /// - if the lease record being parsed identifies a lease which is not present
  57. /// in the container, and the lease has valid lifetime greater than 0,
  58. /// the lease is added to the container,
  59. /// - if the lease record being parsed identifies a lease which is present in
  60. /// the container, and the valid lifetime of the lease record being parsed is
  61. /// greater than 0, the lease in the container is updated
  62. /// - if the lease record being parsed has valid lifetime equal to 0, and the
  63. /// corresponding lease exists in the container, the lease is removed from
  64. /// the container.
  65. ///
  66. /// After the container holding leases is initialized, each subsequent update,
  67. /// removal or addition of the lease is appended to the lease file
  68. /// synchronously.
  69. ///
  70. /// Originally, the Memfile backend didn't write leases to disk. This was
  71. /// particularly useful for testing server performance in non-disk bound
  72. /// conditions. In order to preserve this capability, the new parameter
  73. /// "persist=true|false" has been introduced in the database access string.
  74. /// For example, database access string: "type=memfile persist=true"
  75. /// enables writes of leases to a disk.
  76. ///
  77. /// The lease file locations can be specified with the "name=[path]"
  78. /// parameter in the database access string. The [path] is the
  79. /// absolute path to the file (including file name). If this parameter
  80. /// is not specified, the default location in the installation
  81. /// directory is used: var/kea/kea-leases4.csv and
  82. /// var/kea/kea-leases6.csv.
  83. class Memfile_LeaseMgr : public LeaseMgr, public MySqlConnection {
  84. public:
  85. /// @defgroup versions Specified memfile backend version.
  86. ///
  87. /// @brief Defines major version of the memfile backend.
  88. ///
  89. /// Version history:
  90. /// 1.0 - initial version (released in Kea 0.9)
  91. /// 2.0 - hwaddr column added (to be released in Kea 0.9.1)
  92. ///
  93. /// @{
  94. static const int MAJOR_VERSION = 2;
  95. /// Defines minor version of the memfile backend.
  96. static const int MINOR_VERSION = 0;
  97. /// @}
  98. /// @brief Specifies universe (V4, V6)
  99. ///
  100. /// This enumeration is used by various functions in Memfile %Lease Manager,
  101. /// to identify the lease type referred to. In particular, it is used by
  102. /// functions operating on the lease files to distinguish between lease
  103. /// files for DHCPv4 and DHCPv6.
  104. enum Universe {
  105. V4,
  106. V6
  107. };
  108. /// @name Methods implementing the API of the lease database backend.
  109. /// The following methods are implementing the API of the
  110. /// @c LeaseMgr to manage leases.
  111. //@{
  112. /// @brief The sole lease manager constructor
  113. ///
  114. /// dbconfig is a generic way of passing parameters. Parameters
  115. /// are passed in the "name=value" format, separated by spaces.
  116. /// Values may be enclosed in double quotes, if needed.
  117. ///
  118. /// @param parameters A data structure relating keywords and values
  119. /// concerned with the database.
  120. Memfile_LeaseMgr(const ParameterMap& parameters);
  121. /// @brief Destructor (closes file)
  122. virtual ~Memfile_LeaseMgr();
  123. /// @brief Local version of getDBVersion() class method
  124. static std::string getDBVersion();
  125. /// @brief Adds an IPv4 lease.
  126. ///
  127. /// @param lease lease to be added
  128. virtual bool addLease(const Lease4Ptr& lease);
  129. /// @brief Adds an IPv6 lease.
  130. ///
  131. /// @param lease lease to be added
  132. virtual bool addLease(const Lease6Ptr& lease);
  133. /// @brief Returns existing IPv4 lease for specified IPv4 address.
  134. ///
  135. /// This function returns a copy of the lease. The modification in the
  136. /// return lease does not affect the instance held in the lease storage.
  137. ///
  138. /// @param addr An address of the searched lease.
  139. ///
  140. /// @return a collection of leases
  141. virtual Lease4Ptr getLease4(const isc::asiolink::IOAddress& addr) const;
  142. /// @brief Returns existing IPv4 leases for specified hardware address.
  143. ///
  144. /// Although in the usual case there will be only one lease, for mobile
  145. /// clients or clients with multiple static/fixed/reserved leases there
  146. /// can be more than one. Thus return type is a container, not a single
  147. /// pointer.
  148. ///
  149. /// @param hwaddr hardware address of the client
  150. ///
  151. /// @return lease collection
  152. virtual Lease4Collection getLease4(const isc::dhcp::HWAddr& hwaddr) const;
  153. /// @brief Returns existing IPv4 lease for specified hardware address
  154. /// and a subnet
  155. ///
  156. /// This function returns a copy of the lease. The modification in the
  157. /// return lease does not affect the instance held in the lease storage.
  158. ///
  159. /// There can be at most one lease for a given HW address in a single
  160. /// pool, so this method with either return a single lease or NULL.
  161. ///
  162. /// @param hwaddr hardware address of the client
  163. /// @param subnet_id identifier of the subnet that lease must belong to
  164. ///
  165. /// @return a pointer to the lease (or NULL if a lease is not found)
  166. virtual Lease4Ptr getLease4(const HWAddr& hwaddr,
  167. SubnetID subnet_id) const;
  168. /// @brief Returns existing IPv4 lease for specified client-id
  169. ///
  170. /// @param client_id client identifier
  171. virtual Lease4Collection getLease4(const ClientId& client_id) const;
  172. /// @brief Returns IPv4 lease for specified client-id/hwaddr/subnet-id tuple
  173. ///
  174. /// There can be at most one lease for a given client-id/hwaddr tuple
  175. /// in a single pool, so this method with either return a single lease
  176. /// or NULL.
  177. ///
  178. /// @param clientid client identifier
  179. /// @param hwaddr hardware address of the client
  180. /// @param subnet_id identifier of the subnet that lease must belong to
  181. ///
  182. /// @return a pointer to the lease (or NULL if a lease is not found)
  183. virtual Lease4Ptr getLease4(const ClientId& clientid,
  184. const HWAddr& hwaddr,
  185. SubnetID subnet_id) const;
  186. /// @brief Returns existing IPv4 lease for specified client-id
  187. ///
  188. /// This function returns a copy of the lease. The modification in the
  189. /// return lease does not affect the instance held in the lease storage.
  190. ///
  191. /// There can be at most one lease for a given HW address in a single
  192. /// pool, so this method with either return a single lease or NULL.
  193. ///
  194. /// @param clientid client identifier
  195. /// @param subnet_id identifier of the subnet that lease must belong to
  196. ///
  197. /// @return a pointer to the lease (or NULL if a lease is not found)
  198. virtual Lease4Ptr getLease4(const ClientId& clientid,
  199. SubnetID subnet_id) const;
  200. /// @brief Returns existing IPv6 lease for a given IPv6 address.
  201. ///
  202. /// This function returns a copy of the lease. The modification in the
  203. /// return lease does not affect the instance held in the lease storage.
  204. ///
  205. /// @param type specifies lease type: (NA, TA or PD)
  206. /// @param addr An address of the searched lease.
  207. ///
  208. /// @return smart pointer to the lease (or NULL if a lease is not found)
  209. virtual Lease6Ptr getLease6(Lease::Type type,
  210. const isc::asiolink::IOAddress& addr) const;
  211. /// @brief Returns existing IPv6 lease for a given DUID + IA + lease type
  212. /// combination
  213. ///
  214. /// @param type specifies lease type: (NA, TA or PD)
  215. /// @param duid client DUID
  216. /// @param iaid IA identifier
  217. ///
  218. /// @return collection of IPv6 leases
  219. virtual Lease6Collection getLeases6(Lease::Type type,
  220. const DUID& duid, uint32_t iaid) const;
  221. /// @brief Returns existing IPv6 lease for a given DUID + IA + subnet-id +
  222. /// lease type combination.
  223. ///
  224. /// This function returns a copy of the lease. The modification in the
  225. /// return lease does not affect the instance held in the lease storage.
  226. ///
  227. /// @param type specifies lease type: (NA, TA or PD)
  228. /// @param duid client DUID
  229. /// @param iaid IA identifier
  230. /// @param subnet_id identifier of the subnet the lease must belong to
  231. ///
  232. /// @return lease collection (may be empty if no lease is found)
  233. virtual Lease6Collection getLeases6(Lease::Type type, const DUID& duid,
  234. uint32_t iaid,
  235. SubnetID subnet_id) const;
  236. /// @brief Updates IPv4 lease.
  237. ///
  238. /// @warning This function does not validate the pointer to the lease.
  239. /// It is caller's responsibility to pass the valid pointer.
  240. ///
  241. /// @param lease4 The lease to be updated.
  242. ///
  243. /// If no such lease is present, an exception will be thrown.
  244. virtual void updateLease4(const Lease4Ptr& lease4);
  245. /// @brief Updates IPv6 lease.
  246. ///
  247. /// @warning This function does not validate the pointer to the lease.
  248. /// It is caller's responsibility to pass the valid pointer.
  249. ///
  250. /// @param lease6 The lease to be updated.
  251. ///
  252. /// If no such lease is present, an exception will be thrown.
  253. virtual void updateLease6(const Lease6Ptr& lease6);
  254. /// @brief Deletes a lease.
  255. ///
  256. /// @param addr Address of the lease to be deleted. (This can be IPv4 or
  257. /// IPv6.)
  258. ///
  259. /// @return true if deletion was successful, false if no such lease exists
  260. virtual bool deleteLease(const isc::asiolink::IOAddress& addr);
  261. /// @brief Return backend type
  262. ///
  263. /// Returns the type of the backend.
  264. ///
  265. /// @return Type of the backend.
  266. virtual std::string getType() const {
  267. return (std::string("memfile"));
  268. }
  269. /// @brief Returns backend name.
  270. ///
  271. /// For now, memfile can only store data in memory.
  272. ///
  273. /// @return Name of the backend.
  274. virtual std::string getName() const {
  275. return ("memory");
  276. }
  277. /// @brief Returns description of the backend.
  278. ///
  279. /// This description may be multiline text that describes the backend.
  280. ///
  281. /// @return Description of the backend.
  282. virtual std::string getDescription() const;
  283. /// @brief Returns backend version.
  284. ///
  285. /// @return Version number as a pair of unsigned integers. "first" is the
  286. /// major version number, "second" the minor number.
  287. virtual std::pair<uint32_t, uint32_t> getVersion() const {
  288. return (std::make_pair(MAJOR_VERSION, MINOR_VERSION));
  289. }
  290. /// @brief Commit Transactions
  291. ///
  292. /// Commits all pending database operations. On databases that don't
  293. /// support transactions, this is a no-op.
  294. virtual void commit();
  295. /// @brief Rollback Transactions
  296. ///
  297. /// Rolls back all pending database operations. On databases that don't
  298. /// support transactions, this is a no-op.
  299. virtual void rollback();
  300. //@}
  301. /// @name Public type and method used to determine file names for LFC.
  302. //@{
  303. /// @brief Types of the lease files used by the %Lease File Cleanup.
  304. ///
  305. /// This enumeration is used by a method which appends the appropriate
  306. /// suffix to the lease file name.
  307. enum LFCFileType {
  308. FILE_CURRENT, ///< %Lease File
  309. FILE_INPUT, ///< %Lease File Copy
  310. FILE_PREVIOUS, ///< Previous %Lease File
  311. FILE_OUTPUT, ///< LFC Output File
  312. FILE_FINISH, ///< LFC Finish File
  313. FILE_PID ///< PID File
  314. };
  315. /// @brief Appends appropriate suffix to the file name.
  316. ///
  317. /// The suffix is selected using the LFC file type specified as a
  318. /// parameter. Each file type uses a unique suffix or no suffix:
  319. /// - Current File: no suffix
  320. /// - %Lease File Copy or Input File: ".1"
  321. /// - Previous File: ".2"
  322. /// - LFC Output File: ".output"
  323. /// - LFC Finish File: ".completed"
  324. /// - LFC PID File: ".pid"
  325. ///
  326. /// See http://kea.isc.org/wiki/LFCDesign for details.
  327. ///
  328. /// @param file_name A base file name to which suffix is appended.
  329. /// @param file_type An LFC file type.
  330. /// @return A lease file name with a suffix appended.
  331. static std::string appendSuffix(const std::string& file_name,
  332. const LFCFileType& file_type);
  333. //@}
  334. /// @name Miscellaneous public convenience methods.
  335. /// The following methods allow for retrieving useful information
  336. /// about the state of the backend.
  337. //@{
  338. /// @brief Returns the interval at which the @c IOService events should
  339. /// be released.
  340. ///
  341. /// The Memfile backend may install a timer to execute the %Lease File
  342. /// Cleanup periodically. If this timer is installed, the method returns
  343. /// the LFC interval in milliseconds.
  344. ///
  345. /// @return A maximum interval (in seconds) at which the @c IOService
  346. /// should be executed. A value of 0 means that no timers are installed
  347. /// and that there is no requirement for the @c IOService to be
  348. /// executed at any specific interval.
  349. virtual uint32_t getIOServiceExecInterval() const;
  350. /// @brief Returns default path to the lease file.
  351. ///
  352. /// @param u Universe (V4 or V6).
  353. std::string getDefaultLeaseFilePath(Universe u) const;
  354. /// @brief Returns an absolute path to the lease file.
  355. ///
  356. /// @param u Universe (V4 or V6).
  357. ///
  358. /// @return Absolute path to the lease file or empty string if no lease
  359. /// file is used.
  360. std::string getLeaseFilePath(Universe u) const;
  361. /// @brief Specifies whether or not leases are written to disk.
  362. ///
  363. /// It is possible that leases for DHCPv4 are written to disk whereas leases
  364. /// for DHCPv6 are not; or vice versa. The argument of the method specifies
  365. /// the type of lease in that respect.
  366. ///
  367. /// @param u Universe (V4 or V6).
  368. ///
  369. /// @return true if leases are written to lease file; if false is
  370. /// returned, leases will be held in memory and will be lost upon
  371. /// server shut down.
  372. bool persistLeases(Universe u) const;
  373. //@}
  374. private:
  375. /// @brief Initialize the location of the lease file.
  376. ///
  377. /// This method uses the parameters passed as a map to the constructor to
  378. /// initialize the location of the lease file. If the lease file is not
  379. /// specified, the method will use the default location for the universe
  380. /// (v4 or v6) selected. If the location is specified in the map as empty
  381. /// or the "persist" parameter is set to "no" it will set the empty
  382. /// location, which implies that leases belonging to the specified universe
  383. /// will not be written to disk.
  384. ///
  385. /// @param u Universe (v4 or v6)
  386. ///
  387. /// @return The location of the lease file that should be assigned to the
  388. /// lease_file4_ or lease_file6_, depending on the universe specified as an
  389. /// argument to this function.
  390. std::string initLeaseFilePath(Universe u);
  391. /// @brief Load leases from the persistent storage.
  392. ///
  393. /// This method loads DHCPv4 or DHCPv6 leases from lease files in the
  394. /// following order:
  395. /// - If the <filename>.completed doesn't exist:
  396. /// - leases from the <filename>.2
  397. /// - leases from the <filename>.1
  398. /// - leases from the <filename>
  399. /// - else
  400. /// - leases from the <filename>.completed
  401. /// - leases from the <filename>
  402. ///
  403. /// If any of the files doesn't exist the method proceeds to reading
  404. /// leases from the subsequent file. If the <filename> doesn't exist
  405. /// it is created.
  406. ///
  407. /// When the method successfully reads leases from the files, it leaves
  408. /// the file <filename> open and its internal pointer is set to the
  409. /// end of file. The server will append lease entries to this file as
  410. /// a result of processing new messages from the clients.
  411. ///
  412. /// The <filename>.2, <filename>.1 and <filename>.completed are the
  413. /// products of the lease file cleanups (LFC).
  414. /// See: http://kea.isc.org/wiki/LFCDesign for details.
  415. ///
  416. /// @note: When the server starts up or is reconfigured it will try to
  417. /// read leases from the lease files using this method. It is possible
  418. /// that the %Lease File Cleanup is performed upon the lease files to
  419. /// be read by this method. This may result in conflicts between the
  420. /// server process and the LFC. To prevent it, the method checks if the
  421. /// instance of the @c kea-lfc is running (using the PID file) before it
  422. /// tries to load leases from the lease files. If it finds that there
  423. /// is an LFC in progress, it throws an exception which will result
  424. /// in the server refuse to start or reconfigure. When the administrator
  425. /// retries starting up or reconfiguring the server it will most likely
  426. /// be successful as the LFC should be complete by that time.
  427. ///
  428. /// @todo Consider implementing delaying the lease files loading when
  429. /// the LFC is in progress by the specified amount of time.
  430. ///
  431. /// @param filename Name of the lease file.
  432. /// @param lease_file An object representing a lease file to which
  433. /// the server will store lease updates.
  434. /// @param storage A storage for leases read from the lease file.
  435. /// @tparam LeaseObjectType @c Lease4 or @c Lease6.
  436. /// @tparam LeaseFileType @c CSVLeaseFile4 or @c CSVLeaseFile6.
  437. /// @tparam StorageType @c Lease4Storage or @c Lease6Storage.
  438. ///
  439. /// @throw CSVFileError when parsing any of the lease files fails.
  440. /// @throw DbOpenError when it is found that the LFC is in progress.
  441. template<typename LeaseObjectType, typename LeaseFileType,
  442. typename StorageType>
  443. void loadLeasesFromFiles(const std::string& filename,
  444. boost::shared_ptr<LeaseFileType>& lease_file,
  445. StorageType& storage);
  446. /// @brief stores IPv4 leases
  447. Lease4Storage storage4_;
  448. /// @brief stores IPv6 leases
  449. Lease6Storage storage6_;
  450. /// @brief Holds the pointer to the DHCPv4 lease file IO.
  451. boost::shared_ptr<CSVLeaseFile4> lease_file4_;
  452. /// @brief Holds the pointer to the DHCPv6 lease file IO.
  453. boost::shared_ptr<CSVLeaseFile6> lease_file6_;
  454. public:
  455. /// @name Public methods to retrieve information about the LFC process state.
  456. /// These methods are meant to be used by unit tests to retrieve the
  457. /// state of the spawned LFC process before validating the result of
  458. /// the lease file cleanup.
  459. //@{
  460. /// @brief Checks if the process performing lease file cleanup is running.
  461. ///
  462. /// @return true if the process performing lease file cleanup is running.
  463. bool isLFCRunning() const;
  464. /// @brief Returns the status code returned by the last executed
  465. /// LFC process.
  466. int getLFCExitStatus() const;
  467. //@}
  468. /// @name Protected methods used for %Lease File Cleanup.
  469. /// The following methods are protected so as they can be accessed and
  470. /// tested by unit tests.
  471. //@{
  472. protected:
  473. /// @brief A callback function triggering %Lease File Cleanup (LFC).
  474. ///
  475. /// This method is executed periodically to start the lease file cleanup.
  476. /// It checks whether the file is a DHCPv4 lease file or DHCPv6 lease file
  477. /// and executes the @c Memfile_LeaseMgr::lfcExecute private method
  478. /// with the appropriate parameters.
  479. ///
  480. /// This method is virtual so as it can be overridden and customized in
  481. /// the unit tests. In particular, the unit test which checks that the
  482. /// callback function has been executed would override this function
  483. /// to increase the execution counter each time it is executed.
  484. virtual void lfcCallback();
  485. //@}
  486. /// @name Private methods and members used for %Lease File Cleanup.
  487. //@{
  488. private:
  489. /// @brief Setup the periodic %Lease File Cleanup.
  490. ///
  491. /// This method checks if the @c lfc-interval configuration parameter
  492. /// is set to a non-zero value and sets up the interval timer to
  493. /// perform the %Lease File Cleanup periodically. It also prepares the
  494. /// path and arguments for the @c kea-lfc application which will be
  495. /// executed to perform the cleanup. By default the backend will use
  496. /// the path to the kea-lfc in the Kea installation directory. If
  497. /// the unit tests need to override this path (with the path in the
  498. /// Kea build directory, the @c KEA_LFC_EXECUTABLE environmental
  499. /// variable should be set to hold an absolute path to the kea-lfc
  500. /// excutable.
  501. void lfcSetup();
  502. /// @brief Performs a lease file cleanup for DHCPv4 or DHCPv6.
  503. ///
  504. /// This method performs all the actions necessary to prepare for the
  505. /// execution of the LFC and if these actions are successful, it executes
  506. /// the @c kea-lfc application as a background process to process (cleanup)
  507. /// the lease files.
  508. ///
  509. /// For the design and the terminology used in this description refer to
  510. /// the http://kea.isc.org/wiki/LFCDesign.
  511. ///
  512. /// If the method finds that the %Lease File Copy exists it simply runs
  513. /// the @c kea-lfc application.
  514. ///
  515. /// If the %Lease File Copy doesn't exist it moves the Current %Lease File
  516. /// to Lease File Copy, and then recreates the Current Lease File without
  517. /// any lease entries. If the file has been successfully moved, it runs
  518. /// the @c kea-lfc application.
  519. ///
  520. /// @param lease_file A pointer to the object representing the Current
  521. /// %Lease File (DHCPv4 or DHCPv6 lease file).
  522. ///
  523. /// @tparam LeaseFileType One of @c CSVLeaseFile4 or @c CSVLeaseFile6.
  524. template<typename LeaseFileType>
  525. void lfcExecute(boost::shared_ptr<LeaseFileType>& lease_file);
  526. /// @brief A pointer to the Lease File Cleanup configuration.
  527. boost::scoped_ptr<LFCSetup> lfc_setup_;
  528. //@}
  529. };
  530. }; // end of isc::dhcp namespace
  531. }; // end of isc namespace
  532. #endif // MEMFILE_LEASE_MGR_H