Kea 2.7.4
isc::dhcp::LeaseFileLoader Class Reference

Utility class to manage bulk of leases in the lease files. More...

#include <lease_file_loader.h>

Static Public Member Functions

template<typename LeaseObjectType , typename LeaseFileType , typename StorageType >
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.
 
template<typename LeaseObjectType , typename LeaseFileType , typename StorageType >
static void write (LeaseFileType &lease_file, const StorageType &storage)
 Write leases from the storage into a lease file.
 

Detailed Description

Utility class to manage bulk of leases in the lease files.

This class exposes methods which allow for bulk loading leases from the lease file and dumping the leases held in memory into the lease file. There are two major use cases for this class:

  • load leases by the DHCP server when the server starts up or reloads configuration,
  • an application performing a lease file cleanup rewrites the whole lease file to remove the redundant lease entries.

In the former case, this class is used by the MemFile_LeaseMgr. In the latter case, this class is used by the standalone application which reads the whole lease file into memory (storage) and then dumps the leases held in the storage to another file.

The methods in this class are templated so as they can be used both with the Lease4Storage and Lease6Storage to process the DHCPv4 and DHCPv6 leases respectively.

Definition at line 40 of file lease_file_loader.h.

Member Function Documentation

◆ load()

template<typename LeaseObjectType , typename LeaseFileType , typename StorageType >
static void isc::dhcp::LeaseFileLoader::load ( LeaseFileType & lease_file,
StorageType & storage,
const uint32_t max_errors = 0,
const bool close_file_on_exit = true )
inlinestatic

Load leases from the lease file into the specified storage.

This method iterates over the entries in the lease file in the CSV format, creates Lease4 or Lease6 objects and inserts them into the storage to which reference is specified as an argument. If there are multiple entries for the particular lease in the lease file the entries further in the lease file override the previous entries.

If the method finds the entry with the valid lifetime of 0 it means that the particular lease was released and the method removes an existing lease from the container.

Parameters
lease_fileA reference to the CSVLeaseFile4 or CSVLeaseFile6 object representing the lease file. The file doesn't need to be open because the method re-opens the file.
storageA reference to the container to which leases should be inserted.
max_errorsMaximum number of corrupted leases in the lease file. The method will skip corrupted leases but after exceeding the specified number of errors it will throw an exception. A value of 0 (default) disables the limit check.
close_file_on_exitA boolean flag which indicates if the file should be closed after it has been successfully parsed. One case when the file is not opened is when the server starts up, reads the leases in the file and then leaves the file open for writing future lease updates.
Template Parameters
LeaseObjectTypeA Lease4 or Lease6.
LeaseFileTypeA CSVLeaseFile4 or CSVLeaseFile6.
StorageTypeA Lease4Storage or Lease6Storage.
Exceptions
isc::util::CSVFileErrorwhen the maximum number of errors has been exceeded.

Definition at line 78 of file lease_file_loader.h.

References isc::dhcp::DHCPSRV_DBG_TRACE_DETAIL_DATA, isc::dhcp::dhcpsrv_logger, isc::dhcp::DHCPSRV_MEMFILE_LEASE_FILE_LOAD, isc::dhcp::DHCPSRV_MEMFILE_LEASE_LOAD, isc::dhcp::DHCPSRV_MEMFILE_LEASE_LOAD_ROW_ERROR, isc::dhcp::DHCPSRV_MEMFILE_NEEDS_DOWNGRADING, isc::dhcp::DHCPSRV_MEMFILE_NEEDS_UPGRADING, isc_throw, isc::dhcp::SanityChecker::leaseCheckingEnabled(), LOG_DEBUG, LOG_ERROR, LOG_INFO, LOG_WARN, and isc::util::VersionedCSVFile::NEEDS_UPGRADE.

+ Here is the call graph for this function:

◆ write()

template<typename LeaseObjectType , typename LeaseFileType , typename StorageType >
static void isc::dhcp::LeaseFileLoader::write ( LeaseFileType & lease_file,
const StorageType & storage )
inlinestatic

Write leases from the storage into a lease file.

This method iterates over the Lease4 or Lease6 object in the storage specified in the arguments and writes them to the file specified in the arguments.

This method writes all entries in the storage to the file, it does not perform any checks for expiration or duplication.

The order in which the entries will be written to the file depends on the first index in the multi-index container. Currently that is the v4 or v6 IP address and they are written from lowest to highest.

Before writing the method will close the file if it is open and reopen it for writing. After completion it will close the file.

Parameters
lease_fileA reference to the CSVLeaseFile4 or CSVLeaseFile6 object representing the lease file. The file doesn't need to be open because the method re-opens the file.
storageA reference to the container from which leases should be written.
Template Parameters
LeaseObjectTypeA Lease4 or Lease6.
LeaseFileTypeA CSVLeaseFile4 or CSVLeaseFile6.
StorageTypeA Lease4Storage or Lease6Storage.

Definition at line 219 of file lease_file_loader.h.


The documentation for this class was generated from the following file: