"command": "version-get"
}
+.. isccmd:: kea-lfc-start
+.. _command-kea-lfc-start:
+
+The ``kea-lfc-start`` Command
+-----------------------------
+
+The isccmd:`kea-lfc-start` command starts the ``kea-lfc`` process which
+cleans up the lease file (see :ref:`kea-lfc`). It takes no argument and
+returns an error when the lease backend is not the ``memfile`` or when
+the ``persist`` parameter of the ``lease-database`` was configured to
+``false`` (but not when ``lfc-interval`` is ``0``).
+
Commands Supported by the DHCPv4 Server
=======================================
backend. This service is written to run as a standalone process.
While :iscman:`kea-lfc` can be started externally, there is usually no need to
-do so. :iscman:`kea-lfc` is run on a periodic basis by the Kea DHCP servers.
+do so. :iscman:`kea-lfc` is run on a periodic basis by the Kea DHCP servers,
+and since Kea 3.1.2 can be started using the ``kea-lfc-start`` command.
The process operates on a set of files, using them to receive input and
output of the lease entries and to indicate what stage the process is
return (answer);
}
+ConstElementPtr
+ControlledDhcpv4Srv::commandLfcStartHandler(const string&, ConstElementPtr) {
+ if (LeaseMgrFactory::haveInstance()) {
+ return (LeaseMgrFactory::instance().lfcStartHandler());
+ }
+ return (createAnswer(CONTROL_RESULT_COMMAND_UNSUPPORTED,
+ "no lease backend"));
+}
+
isc::data::ConstElementPtr
ControlledDhcpv4Srv::processConfig(isc::data::ConstElementPtr config) {
ControlledDhcpv4Srv* srv = ControlledDhcpv4Srv::getInstance();
CommandMgr::instance().registerCommand("dhcp-disable",
std::bind(&ControlledDhcpv4Srv::commandDhcpDisableHandler, this, ph::_1, ph::_2));
+ CommandMgr::instance().registerCommand("kea-lfc-start",
+ std::bind(&ControlledDhcpv4Srv::commandLfcStartHandler, this, ph::_1, ph::_2));
+
CommandMgr::instance().registerCommand("leases-reclaim",
std::bind(&ControlledDhcpv4Srv::commandLeasesReclaimHandler, this, ph::_1, ph::_2));
CommandMgr::instance().deregisterCommand("config-write");
CommandMgr::instance().deregisterCommand("dhcp-disable");
CommandMgr::instance().deregisterCommand("dhcp-enable");
+ CommandMgr::instance().deregisterCommand("kea-lfc-start");
CommandMgr::instance().deregisterCommand("leases-reclaim");
CommandMgr::instance().deregisterCommand("subnet4-select-test");
CommandMgr::instance().deregisterCommand("subnet4o6-select-test");
#include <cc/data.h>
#include <cc/command_interpreter.h>
#include <util/reconnect_ctl.h>
+#include <dhcpsrv/lease_mgr.h>
#include <dhcpsrv/timer_mgr.h>
#include <dhcp4/dhcp4_srv.h>
commandStatisticSetMaxSampleAgeAllHandler(const std::string& command,
isc::data::ConstElementPtr args);
+ /// @brief handler for processing 'kea-lfc-start' command
+ ///
+ /// This handler processes kea-lfc-start command, which cleans up
+ /// the lease file (the backup file of the memfile lease backend).
+ /// @ref isc::dhcp::LeaseMgr::lfcStartHandler
+ ///
+ /// @param command (ignored)
+ /// @param args (ignored)
+ /// @return process information wrapped in a response
+ isc::data::ConstElementPtr
+ commandLfcStartHandler(const std::string& command,
+ isc::data::ConstElementPtr args);
+
/// @brief Reclaims expired IPv4 leases and reschedules timer.
///
/// This is a wrapper method for @c AllocEngine::reclaimExpiredLeases4.
return (answer);
}
+ConstElementPtr
+ControlledDhcpv6Srv::commandLfcStartHandler(const string&, ConstElementPtr) {
+ if (LeaseMgrFactory::haveInstance()) {
+ return (LeaseMgrFactory::instance().lfcStartHandler());
+ }
+ return (createAnswer(CONTROL_RESULT_COMMAND_UNSUPPORTED,
+ "no lease backend"));
+}
+
isc::data::ConstElementPtr
ControlledDhcpv6Srv::processConfig(isc::data::ConstElementPtr config) {
ControlledDhcpv6Srv* srv = ControlledDhcpv6Srv::getInstance();
CommandMgr::instance().registerCommand("dhcp-disable",
std::bind(&ControlledDhcpv6Srv::commandDhcpDisableHandler, this, ph::_1, ph::_2));
+ CommandMgr::instance().registerCommand("kea-lfc-start",
+ std::bind(&ControlledDhcpv6Srv::commandLfcStartHandler, this, ph::_1, ph::_2));
+
CommandMgr::instance().registerCommand("leases-reclaim",
std::bind(&ControlledDhcpv6Srv::commandLeasesReclaimHandler, this, ph::_1, ph::_2));
CommandMgr::instance().deregisterCommand("config-write");
CommandMgr::instance().deregisterCommand("dhcp-disable");
CommandMgr::instance().deregisterCommand("dhcp-enable");
+ CommandMgr::instance().deregisterCommand("kea-lfc-start");
CommandMgr::instance().deregisterCommand("leases-reclaim");
CommandMgr::instance().deregisterCommand("subnet6-select-test");
CommandMgr::instance().deregisterCommand("server-tag-get");
#include <cc/data.h>
#include <cc/command_interpreter.h>
#include <util/reconnect_ctl.h>
+#include <dhcpsrv/lease_mgr.h>
#include <dhcpsrv/timer_mgr.h>
#include <dhcp6/dhcp6_srv.h>
commandStatisticSetMaxSampleAgeAllHandler(const std::string& command,
isc::data::ConstElementPtr args);
+ /// @brief handler for processing 'kea-lfc-start' command
+ ///
+ /// This handler processes kea-lfc-start command, which cleans up
+ /// the lease file (the backup file of the memfile lease backend).
+ /// @ref isc::dhcp::LeaseMgr::lfcStartHandler
+ ///
+ /// @param command (ignored)
+ /// @param args (ignored)
+ /// @return process information wrapped in a response
+ isc::data::ConstElementPtr
+ commandLfcStartHandler(const std::string& command,
+ isc::data::ConstElementPtr args);
+
/// @brief Reclaims expired IPv6 leases and reschedules timer.
///
/// This is a wrapper method for @c AllocEngine::reclaimExpiredLeases6.
extern const isc::log::MessageID DHCPSRV_MEMFILE_LFC_EXECUTE = "DHCPSRV_MEMFILE_LFC_EXECUTE";
extern const isc::log::MessageID DHCPSRV_MEMFILE_LFC_LEASE_FILE_RENAME_FAIL = "DHCPSRV_MEMFILE_LFC_LEASE_FILE_RENAME_FAIL";
extern const isc::log::MessageID DHCPSRV_MEMFILE_LFC_LEASE_FILE_REOPEN_FAIL = "DHCPSRV_MEMFILE_LFC_LEASE_FILE_REOPEN_FAIL";
+extern const isc::log::MessageID DHCPSRV_MEMFILE_LFC_RESCHEDULED = "DHCPSRV_MEMFILE_LFC_RESCHEDULED";
extern const isc::log::MessageID DHCPSRV_MEMFILE_LFC_SETUP = "DHCPSRV_MEMFILE_LFC_SETUP";
extern const isc::log::MessageID DHCPSRV_MEMFILE_LFC_SPAWN_FAIL = "DHCPSRV_MEMFILE_LFC_SPAWN_FAIL";
extern const isc::log::MessageID DHCPSRV_MEMFILE_LFC_START = "DHCPSRV_MEMFILE_LFC_START";
"DHCPSRV_MEMFILE_LFC_EXECUTE", "executing Lease File Cleanup using: %1",
"DHCPSRV_MEMFILE_LFC_LEASE_FILE_RENAME_FAIL", "failed to rename the current lease file %1 to %2, reason: %3",
"DHCPSRV_MEMFILE_LFC_LEASE_FILE_REOPEN_FAIL", "failed to reopen lease file %1 after preparing input file for lease file cleanup, reason: %2, new leases will not persist!",
+ "DHCPSRV_MEMFILE_LFC_RESCHEDULED", "rescheduled Lease File Cleanup",
"DHCPSRV_MEMFILE_LFC_SETUP", "setting up the Lease File Cleanup interval to %1 sec",
"DHCPSRV_MEMFILE_LFC_SPAWN_FAIL", "lease file cleanup failed to run because kea-lfc process couldn't be spawned",
"DHCPSRV_MEMFILE_LFC_START", "starting Lease File Cleanup",
extern const isc::log::MessageID DHCPSRV_MEMFILE_LFC_EXECUTE;
extern const isc::log::MessageID DHCPSRV_MEMFILE_LFC_LEASE_FILE_RENAME_FAIL;
extern const isc::log::MessageID DHCPSRV_MEMFILE_LFC_LEASE_FILE_REOPEN_FAIL;
+extern const isc::log::MessageID DHCPSRV_MEMFILE_LFC_RESCHEDULED;
extern const isc::log::MessageID DHCPSRV_MEMFILE_LFC_SETUP;
extern const isc::log::MessageID DHCPSRV_MEMFILE_LFC_SPAWN_FAIL;
extern const isc::log::MessageID DHCPSRV_MEMFILE_LFC_START;
lease file for lease file cleanup. The server continues to
operate but leases do not persist to disk.
+% DHCPSRV_MEMFILE_LFC_RESCHEDULED rescheduled Lease File Cleanup
+An informational message issued when the memfile lease database backend
+rescheduled the periodic Lease File Cleanup at the reception of a
+"kea-lfc-start" command.
+
% DHCPSRV_MEMFILE_LFC_SETUP setting up the Lease File Cleanup interval to %1 sec
An informational message logged when the memfile lease database backend
configures the LFC to be executed periodically. The argument holds the
#include <config.h>
+#include <cc/command_interpreter.h>
#include <dhcp/libdhcp++.h>
#include <dhcp/option_custom.h>
#include <dhcpsrv/cfgmgr.h>
#include <time.h>
using namespace isc::asiolink;
+using namespace isc::config;
using namespace isc::data;
using namespace isc::db;
using namespace isc::dhcp;
return (0);
}
+ConstElementPtr
+LeaseMgr::lfcStartHandler() {
+ ostringstream msg;
+ msg << "lease backend `" << getName() << "' is not 'memfile'";
+ return (createAnswer(CONTROL_RESULT_COMMAND_UNSUPPORTED, msg.str()));
+}
+
} // namespace isc::dhcp
} // namespace isc
/// @return Always 0.
virtual size_t byRemoteId6size() const;
+ /// @brief Handler for kea-lfc-start command.
+ ///
+ /// Derived by the memfile backend.
+ ///
+ /// @returns By default an error saying the backend is not the memfile one.
+ virtual isc::data::ConstElementPtr lfcStartHandler();
+
protected:
/// Extended information / Bulk Lease Query shared interface.
#include <config.h>
#include <asiolink/addr_utilities.h>
+#include <cc/command_interpreter.h>
#include <dhcpsrv/cfg_consistency.h>
#include <dhcpsrv/cfgmgr.h>
#include <dhcpsrv/dhcpsrv_exceptions.h>
} // namespace
using namespace isc::asiolink;
+using namespace isc::config;
using namespace isc::data;
using namespace isc::db;
using namespace isc::util;
void
Memfile_LeaseMgr::lfcCallback() {
- LOG_INFO(dhcpsrv_logger, DHCPSRV_MEMFILE_LFC_START);
-
// Check if we're in the v4 or v6 space and use the appropriate file.
if (lease_file4_) {
MultiThreadingCriticalSection cs;
<< lfc_interval_str << " specified");
}
- if (lfc_interval > 0 || conversion_needed) {
- lfc_setup_.reset(new LFCSetup(std::bind(&Memfile_LeaseMgr::lfcCallback, this)));
- lfc_setup_->setup(lfc_interval, lease_file4_, lease_file6_, conversion_needed);
- }
+ lfc_setup_.reset(new LFCSetup(std::bind(&Memfile_LeaseMgr::lfcCallback, this)));
+ lfc_setup_->setup(lfc_interval, lease_file4_, lease_file6_, conversion_needed);
}
template<typename LeaseFileType>
void
Memfile_LeaseMgr::lfcExecute(boost::shared_ptr<LeaseFileType>& lease_file) {
+ LOG_INFO(dhcpsrv_logger, DHCPSRV_MEMFILE_LFC_START);
+
bool do_lfc = true;
// Check the status of the LFC instance.
}
}
+ConstElementPtr
+Memfile_LeaseMgr::lfcStartHandler() {
+ if (!persistLeases(V4) && !persistLeases(V6)) {
+ std::ostringstream msg;
+ msg << "'persist` parameter of `memfile` lease backend "
+ << "was configured to `false`";
+ return (createAnswer(CONTROL_RESULT_COMMAND_UNSUPPORTED, msg.str()));
+ }
+ MultiThreadingCriticalSection cs;
+ // Reschedule the periodic lfc run.
+ if (TimerMgr::instance()->isTimerRegistered("memfile-lfc")) {
+ TimerMgr::instance()->cancel("memfile-lfc");
+ TimerMgr::instance()->setup("memfile-lfc");
+ LOG_INFO(dhcpsrv_logger, DHCPSRV_MEMFILE_LFC_RESCHEDULED);
+ }
+ if (lease_file4_) {
+ lfcExecute(lease_file4_);
+ } else if (lease_file6_) {
+ lfcExecute(lease_file6_);
+ }
+ return (createAnswer(CONTROL_RESULT_SUCCESS, "kea-lfc started"));
+}
+
LeaseStatsQueryPtr
Memfile_LeaseMgr::startLeaseStatsQuery4() {
LeaseStatsQueryPtr query(new MemfileLeaseStatsQuery4(storage4_));
/// @return Always return 0 as this function is a noop for not SQL backends.
virtual size_t upgradeExtendedInfo4(const LeasePageSize& page_size) override;
+ /// @brief Handler for kea-lfc-start command.
+ ///
+ /// @returns Status of command.
+ virtual isc::data::ConstElementPtr lfcStartHandler() override;
+
protected:
/// Extended information / Bulk Lease Query shared interface.
--- /dev/null
+{
+ "access": "write",
+ "avail": "3.1.2",
+ "brief": [
+ "This command starts the kea-lfc process which cleas nup the lease file. ",
+ "This command does not take any parameters."
+ ],
+ "cmd-syntax": [
+ "{",
+ " \"command\": \"kea-lfc-start\"",
+ "}"
+ ],
+ "description": "See <xref linkend=\"command-kea-lfc-start\"/>",
+ "name": "kea-lfc-start",
+ "support": [
+ "kea-dhcp4",
+ "kea-dhcp6"
+ ]
+}