8#include <kea_version.h> 
   37const uint32_t MAX_LEASE_ERRORS = 100;
 
   51    : protocol_version_(0), verbose_(false), config_file_(
""), previous_file_(
""),
 
   52      copy_file_(
""), output_file_(
""), finish_file_(
""), pid_file_(
"") {
 
 
   60    bool do_rotate = 
true;
 
   78    startLogger(test_mode);
 
   86        if (pid_file.
check()) {
 
  103    if (!lf_finish.
exists()) {
 
  110                processLeases<Lease4, CSVLeaseFile4, Lease4Storage>();
 
  112                processLeases<Lease6, CSVLeaseFile6, Lease6Storage>();
 
  114        } 
catch (
const std::exception& proc_ex) {
 
 
  151    while ((ch = getopt(argc, argv, 
":46dhvVWp:x:i:o:c:f:")) != -1) {
 
  155            protocol_version_ = 4;
 
  160            protocol_version_ = 6;
 
  165            std::cout << getVersion(
false) << std::endl;
 
  170            std::cout << getVersion(
true) << std::endl;
 
  185            if (optarg == NULL) {
 
  193            if (optarg == NULL) {
 
  196            previous_file_ = optarg;
 
  201            if (optarg == NULL) {
 
  209            if (optarg == NULL) {
 
  212            output_file_ = optarg;
 
  217            if (optarg == NULL) {
 
  220            finish_file_ = optarg;
 
  225            if (optarg == NULL) {
 
  228            config_file_ = optarg;
 
  256    if (protocol_version_ == 0) {
 
  260    if (pid_file_.empty()) {
 
  264    if (previous_file_.empty()) {
 
  268    if (copy_file_.empty()) {
 
  272    if (output_file_.empty()) {
 
  276    if (finish_file_.empty()) {
 
  280    if (config_file_.empty()) {
 
  286        std::cout << 
"Protocol version:    DHCPv" << protocol_version_ << std::endl
 
  287                  << 
"Previous or ex lease file: " << previous_file_ << std::endl
 
  288                  << 
"Copy lease file:           " << copy_file_ << std::endl
 
  289                  << 
"Output lease file:         " << output_file_ << std::endl
 
  290                  << 
"Finish file:               " << finish_file_ << std::endl
 
  291                  << 
"Config file:               " << config_file_ << std::endl
 
  292                  << 
"PID file:                  " << pid_file_ << std::endl
 
 
  298LFCController::usage(
const std::string& text) {
 
  300        std::cerr << 
"Usage error: " << text << std::endl;
 
  304              << 
" [-4|-6] -p file -x file -i file -o file -f file -c file" << std::endl
 
  305              << 
"   -4 or -6 clean a set of v4 or v6 lease files" << std::endl
 
  306              << 
"   -p <file>: PID file" << std::endl
 
  307              << 
"   -x <file>: previous or ex lease file" << std::endl
 
  308              << 
"   -i <file>: copy of lease file" << std::endl
 
  309              << 
"   -o <file>: output lease file" << std::endl
 
  310              << 
"   -f <file>: finish file" << std::endl
 
  311              << 
"   -c <file>: configuration file" << std::endl
 
  312              << 
"   -v: print version number and exit" << std::endl
 
  313              << 
"   -V: print extended version information and exit" << std::endl
 
  314              << 
"   -d: optional, verbose output " << std::endl
 
  315              << 
"   -h: print this message " << std::endl
 
  320LFCController::getVersion(
const bool extended)
 const{
 
  321    std::stringstream version_stream;
 
  323    version_stream << VERSION;
 
  325        std::string db_version;
 
  326        if (protocol_version_ == 4) {
 
  328        } 
else if (protocol_version_ == 6) {
 
  332        version_stream << 
" (" << EXTENDED_VERSION << 
")";
 
  333        if (!db_version.empty()) {
 
  334            db_version = 
"backend: " + db_version;
 
  335            version_stream << std::endl << db_version;
 
  339    return (version_stream.str());
 
  342template<
typename LeaseObjectType, 
typename LeaseFileType, 
typename StorageType>
 
  344LFCController::processLeases()
 const {
 
  349    if (lf_prev.exists()) {
 
  356    if (lf_copy.exists()) {
 
  367      .arg(lf_prev.getReadLeases() + lf_copy.getReadLeases())
 
  368      .arg(lf_prev.getReads() + lf_copy.getReads())
 
  369      .arg(lf_prev.getReadErrs() + lf_copy.getReadErrs());
 
  372      .arg(lf_output.getWriteLeases())
 
  373      .arg(lf_output.getWrites())
 
  374      .arg(lf_output.getWriteErrs());
 
  378        isc_throw(RunTimeFail, 
"Unable to move output (" << output_file_
 
  379                  << 
") to complete (" << finish_file_
 
  380                  << 
") error: " << strerror(errno));
 
  390                  << previous_file_ << 
"' error: " << strerror(errno));
 
  397                  << copy_file_ << 
"' error: " << strerror(errno));
 
  401    if (rename(finish_file_.c_str(), previous_file_.c_str()) != 0) {
 
  403                  << 
") to previous (" << previous_file_
 
  404                  << 
") error: " << strerror(errno));
 
 
  409LFCController::startLogger(
const bool test_mode)
 const {
 
  435        spec.addOutputOption(option);
 
 
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
static void write(LeaseFileType &lease_file, const StorageType &storage)
Write leases from the storage into a lease file.
static void load(LeaseFileType &lease_file, StorageType &storage, const uint32_t max_errors=0, const bool close_file_on_exit=true)
Load leases from the lease file into the specified storage.
static std::string getDBVersionInternal(Universe const &u)
Local version of getDBVersion() class method.
Exception thrown when the command line is invalid.
void fileRotate() const
Rotate files.
void launch(int argc, char *argv[], const bool test_mode)
Acts as the primary entry point to start execution of the process.
int getProtocolVersion() const
Gets the protocol version of the leases files.
LFCController()
Constructor.
std::string getFinishFile() const
Gets the finish file name.
~LFCController()
Destructor.
std::string getCopyFile() const
Gets the copy file name.
static const char * lfc_bin_name_
Defines the executable name, by convention this should match the executable name.
void parseArgs(int argc, char *argv[])
Process the command line arguments.
static const char * lfc_app_name_
Defines the application name, it may be used to locate configuration data and appears in log statemen...
std::string getPreviousFile() const
Gets the previous file name.
std::string getOutputFile() const
Gets the output file name.
Exceptions thrown when a method is unable to manipulate (remove or rename) a file.
void process(T start, T finish)
Process Specifications.
Provides input/output access to CSV files.
bool exists() const
Checks if the CSV file exists and can be opened for reading.
Exception thrown when an error occurs during PID file processing.
Class to help with processing PID files.
void write(int) const
Write the PID to the file.
void deleteFile() const
Delete the PID file.
int check() const
Read the PID in from the file and check it.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
An abstract API for lease database.
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
#define LOG_FATAL(LOGGER, MESSAGE)
Macro to conveniently test fatal output and log it.
std::string getConfigReport()
const isc::log::MessageID LFC_FAIL_PROCESS
const isc::log::MessageID LFC_START
const isc::log::MessageID LFC_TERMINATE
const isc::log::MessageID LFC_FAIL_PID_DEL
const isc::log::MessageID LFC_FAIL_ROTATE
const isc::log::MessageID LFC_RUNNING
const isc::log::MessageID LFC_WRITE_STATS
const isc::log::MessageID LFC_FAIL_PID_CREATE
isc::log::Logger lfc_logger("DhcpLFC")
Defines the logger used within LFC.
const isc::log::MessageID LFC_PROCESSING
const isc::log::MessageID LFC_ROTATING
const isc::log::MessageID LFC_READ_STATS
const std::string & getRootLoggerName()
Get root logger name.
void initLogger(const string &root, isc::log::Severity severity, int dbglevel, const char *file, bool buffer)
Run-time initialization.
int keaLoggerDbglevel(int defdbglevel)
Obtains logging debug level from KEA_LOGGER_DBGLEVEL.
isc::log::Severity keaLoggerSeverity(isc::log::Severity defseverity)
Obtains logging severity from KEA_LOGGER_SEVERITY.
Defines the logger used by the top-level component of kea-lfc.
Destination destination
Members.