Kea  1.5.0
isc::dhcp::CfgMgr Class Reference

Configuration Manager. More...

#include <cfgmgr.h>

+ Inheritance diagram for isc::dhcp::CfgMgr:

Public Member Functions

bool ddnsEnabled ()
 Convenience method for checking if DHCP-DDNS updates are enabled. More...
 
const D2ClientConfigPtrgetD2ClientConfig () const
 Fetches the DHCP-DDNS configuration pointer. More...
 
D2ClientMgrgetD2ClientMgr ()
 Fetches the DHCP-DDNS manager. More...
 
std::string getDataDir () const
 returns path do the data directory More...
 
void setD2ClientConfig (D2ClientConfigPtr &new_config)
 Updates the DHCP-DDNS client configuration to the given value. More...
 
void setDataDir (const std::string &datadir)
 Sets new data directory. More...
 

Static Public Member Functions

static CfgMgrinstance ()
 returns a single instance of Configuration Manager More...
 

Static Public Attributes

static const size_t CONFIG_LIST_SIZE = 10
 A number of configurations held by CfgMgr. More...
 

Methods managing the collection of configurations.

The following methods manage the process of preparing a configuration without affecting a currently used configuration and then committing the configuration to replace current configuration atomically.

They also allow for keeping a history of previous configurations so as the CfgMgr can revert to the historical configuration when required.

Todo:
Migrate all configuration parameters to use the model supported by these functions.
Todo:
Make the size of the configurations history configurable.
void clear ()
 Removes current, staging and all previous configurations. More...
 
void commit ()
 Commits the staging configuration. More...
 
void rollback ()
 Removes staging configuration. More...
 
void revert (const size_t index)
 Reverts to one of the previous configurations. More...
 
SrvConfigPtr getCurrentCfg ()
 Returns a pointer to the current configuration. More...
 
SrvConfigPtr getStagingCfg ()
 Returns a pointer to the staging configuration. More...
 
void setFamily (uint16_t family)
 Sets address family (AF_INET or AF_INET6) More...
 
uint16_t getFamily () const
 Returns address family. More...
 
 CfgMgr ()
 Protected constructor. More...
 
virtual ~CfgMgr ()
 virtual destructor More...
 

Detailed Description

Configuration Manager.

This singleton class holds the whole configuration for DHCPv4 and DHCPv6 servers.

Below is a sketch of configuration inheritance. Let's investigate the following configuration:

preferred-lifetime 500;
valid-lifetime 1000;
subnet6 2001:db8:1::/48 {
pool6 2001::db8:1::1 - 2001::db8:1::ff;
};
subnet6 2001:db8:2::/48 {
valid-lifetime 2000;
pool6 2001::db8:2::1 - 2001::db8:2::ff;
};

Parameters defined in a global scope are applicable to everything until they are overwritten in a smaller scope, in this case subnet6. In the example above, the first subnet6 has preferred lifetime of 500s and a valid lifetime of 1000s. The second subnet has preferred lifetime of 500s, but valid lifetime of 2000s.

Parameter inheritance is implemented in dedicated classes. See isc::dhcp::SimpleParser4::deriveParameters and isc::dhcp::SimpleParser6::deriveParameters.

Definition at line 69 of file cfgmgr.h.

Constructor & Destructor Documentation

◆ CfgMgr()

isc::dhcp::CfgMgr::CfgMgr ( )
protected

Protected constructor.

This constructor is protected for 2 reasons. First, it forbids any instantiations of this class (CfgMgr is a singleton). Second, it allows derived class to instantiate it. That is useful for testing purposes.

Definition at line 169 of file cfgmgr.cc.

◆ ~CfgMgr()

isc::dhcp::CfgMgr::~CfgMgr ( )
protectedvirtual

virtual destructor

Definition at line 176 of file cfgmgr.cc.

Member Function Documentation

◆ clear()

void isc::dhcp::CfgMgr::clear ( )

Removes current, staging and all previous configurations.

This function removes all configurations, including current and staging configurations. It creates a new current configuration with default settings.

This function is exception safe.

Definition at line 78 of file cfgmgr.cc.

◆ commit()

void isc::dhcp::CfgMgr::commit ( )

Commits the staging configuration.

The staging configuration becomes current configuration when this function is called. It removes the oldest configuration held in the history so as the size of the list of configuration does not exceed the CONFIG_LIST_SIZE.

This function is exception safe.

Definition at line 87 of file cfgmgr.cc.

◆ ddnsEnabled()

bool isc::dhcp::CfgMgr::ddnsEnabled ( )

Convenience method for checking if DHCP-DDNS updates are enabled.

Returns
True if the D2 configuration is enabled.

Definition at line 55 of file cfgmgr.cc.

◆ getCurrentCfg()

SrvConfigPtr isc::dhcp::CfgMgr::getCurrentCfg ( )

Returns a pointer to the current configuration.

This function returns pointer to the current configuration. If the current configuration is not set it will create a default configuration and return it.

In the previous Kea releases this method used to return a const pointer to the current configuration to ensure that it is not accidentally modified while the server is running. This has been changed in Kea 1.3 release and now this function returns a non-const pointer. The reason is that there are certain use cases when current configuration must be modified without going through a full cycle of server reconfiguration, e.g. add a subnet to the current configuration as a result of receiving a command over control API. In such case the performance of processing such command is critical and rebuilding the whole configuration just for this small configuration change is out of question.

Nevertheless, such configuration updates should always be made with caution and one has to make sure that the configuration data integrity is preserved.

Returns
Non-null pointer to the current configuration.

Definition at line 154 of file cfgmgr.cc.

Referenced by isc::dhcp::Dhcpv4Srv::acceptServerId(), isc::dhcp::Dhcpv4Srv::adjustIfaceData(), isc::dhcp::Dhcpv4Srv::buildCfgOptionList(), isc::dhcp::Dhcpv6Srv::buildCfgOptionList(), isc::dhcp::SanityChecker::checkLease(), isc::dhcp::Dhcpv4Srv::deferredUnpack(), isc::dhcp::Dhcpv6Srv::evaluateClasses(), isc::dhcp::Dhcpv4Srv::evaluateClasses(), isc::dhcp::Dhcpv6Srv::getMAC(), isc::dhcp::Dhcpv6Srv::initContext(), isc::lease_cmds::LeaseCmdsImpl::lease4UpdateHandler(), isc::lease_cmds::LeaseCmdsImpl::lease4WipeHandler(), isc::lease_cmds::LeaseCmdsImpl::lease6UpdateHandler(), isc::lease_cmds::LeaseCmdsImpl::lease6WipeHandler(), isc::lease_cmds::LeaseCmdsImpl::leaseAddHandler(), isc::stat_cmds::LeaseStatCmdsImpl::makeResultSet4(), isc::stat_cmds::LeaseStatCmdsImpl::makeResultSet6(), isc::dhcp::Dhcpv6Srv::processRSOO(), isc::dhcp::LeaseMgr::recountLeaseStats4(), isc::dhcp::LeaseMgr::recountLeaseStats6(), isc::dhcp::Dhcpv6Srv::requiredClassify(), isc::dhcp::Dhcpv4Srv::requiredClassify(), isc::dhcp::Dhcpv6Srv::selectSubnet(), isc::dhcp::Dhcpv4Srv::selectSubnet(), isc::dhcp::Dhcpv4Srv::selectSubnet4o6(), and isc::dhcp::Dhcpv4Srv::setFixedFields().

◆ getD2ClientConfig()

const D2ClientConfigPtr & isc::dhcp::CfgMgr::getD2ClientConfig ( ) const

Fetches the DHCP-DDNS configuration pointer.

Returns
a reference to the current configuration pointer.

Definition at line 60 of file cfgmgr.cc.

◆ getD2ClientMgr()

◆ getDataDir()

std::string isc::dhcp::CfgMgr::getDataDir ( ) const

returns path do the data directory

This method returns a path to writable directory that DHCP servers can store data in.

Returns
data directory

Definition at line 30 of file cfgmgr.cc.

Referenced by isc::dhcp::Memfile_LeaseMgr::getDefaultLeaseFilePath().

◆ getFamily()

uint16_t isc::dhcp::CfgMgr::getFamily ( ) const
inline

Returns address family.

Definition at line 242 of file cfgmgr.h.

Referenced by isc::dhcp::ClientClassDef::toElement(), and isc::dhcp::SrvConfig::toElement().

◆ getStagingCfg()

SrvConfigPtr isc::dhcp::CfgMgr::getStagingCfg ( )

Returns a pointer to the staging configuration.

The staging configuration is used by the configuration parsers to create new configuration. The staging configuration doesn't affect the server's operation until it is committed. The staging configuration is a non-const object which can be modified by the caller.

Multiple consecutive calls to this function return the same object which can be modified from various places of the code (e.g. various configuration parsers).

Returns
non-null pointer to the staging configuration.

Definition at line 160 of file cfgmgr.cc.

Referenced by isc::dhcp::SanityChecker::checkLease(), isc::dhcp::HostReservationIdsParser4::HostReservationIdsParser4(), isc::dhcp::HostReservationIdsParser6::HostReservationIdsParser6(), isc::dhcp::Dhcp6to4Ipc::open(), isc::dhcp::Dhcp4to6Ipc::open(), isc::dhcp::Subnet4ConfigParser::parse(), and isc::dhcp::Subnet6ConfigParser::parse().

◆ instance()

CfgMgr & isc::dhcp::CfgMgr::instance ( )
static

returns a single instance of Configuration Manager

CfgMgr is a singleton and this method is the only way of accessing it.

Definition at line 25 of file cfgmgr.cc.

Referenced by isc::dhcp::Dhcpv4Srv::acceptServerId(), isc::dhcp::Dhcpv4Srv::adjustIfaceData(), isc::dhcp::Dhcpv6Srv::assignIA_NA(), isc::dhcp::Dhcpv4Srv::assignLease(), isc::dhcp::Dhcpv4Srv::buildCfgOptionList(), isc::dhcp::Dhcpv6Srv::buildCfgOptionList(), isc::dhcp::SanityChecker::checkLease(), isc::dhcp::Dhcpv6Srv::createNameChangeRequests(), isc::dhcp::Dhcpv6Srv::d2ClientErrorHandler(), isc::dhcp::Dhcpv4Srv::d2ClientErrorHandler(), isc::dhcp::Dhcpv4Srv::declineLease(), isc::dhcp::Dhcpv6Srv::declineLease(), isc::dhcp::Dhcpv4Srv::deferredUnpack(), isc::dhcp::Dhcpv6Srv::evaluateClasses(), isc::dhcp::Dhcpv4Srv::evaluateClasses(), isc::dhcp::Dhcpv6Srv::extendIA_NA(), isc::dhcp::Memfile_LeaseMgr::getDefaultLeaseFilePath(), isc::dhcp::Dhcpv6Srv::getMAC(), isc::dhcp::HostReservationIdsParser4::HostReservationIdsParser4(), isc::dhcp::HostReservationIdsParser6::HostReservationIdsParser6(), isc::dhcp::Dhcpv6Srv::initContext(), isc::lease_cmds::LeaseCmdsImpl::lease4UpdateHandler(), isc::lease_cmds::LeaseCmdsImpl::lease4WipeHandler(), isc::lease_cmds::LeaseCmdsImpl::lease6UpdateHandler(), isc::lease_cmds::LeaseCmdsImpl::lease6WipeHandler(), isc::lease_cmds::LeaseCmdsImpl::leaseAddHandler(), isc::stat_cmds::LeaseStatCmdsImpl::makeResultSet4(), isc::stat_cmds::LeaseStatCmdsImpl::makeResultSet6(), isc::dhcp::Dhcp6to4Ipc::open(), isc::dhcp::Dhcp4to6Ipc::open(), isc::dhcp::Subnet4ConfigParser::parse(), isc::dhcp::Subnet6ConfigParser::parse(), isc::dhcp::Dhcpv6Srv::processClientFqdn(), isc::dhcp::Dhcpv6Srv::processRSOO(), isc::dhcp::LeaseMgr::recountLeaseStats4(), isc::dhcp::LeaseMgr::recountLeaseStats6(), isc::dhcp::Dhcpv6Srv::requiredClassify(), isc::dhcp::Dhcpv4Srv::requiredClassify(), isc::dhcp::Dhcpv6Srv::selectSubnet(), isc::dhcp::Dhcpv4Srv::selectSubnet(), isc::dhcp::Dhcpv4Srv::selectSubnet4o6(), isc::dhcp::Dhcpv4Srv::setFixedFields(), isc::dhcp::Dhcpv6Srv::startD2(), isc::dhcp::Dhcpv4Srv::startD2(), isc::dhcp::Dhcpv6Srv::stopD2(), isc::dhcp::Dhcpv4Srv::stopD2(), isc::dhcp::ClientClassDef::toElement(), and isc::dhcp::SrvConfig::toElement().

◆ revert()

void isc::dhcp::CfgMgr::revert ( const size_t  index)

Reverts to one of the previous configurations.

This function reverts to selected previous configuration. The previous configuration is entirely copied to a new SrvConfig instance. This new instance has a unique sequence id (sequence id is not copied). The previous configuration (being copied) is not modified by this operation.

The configuration to be copied is identified by the index value which is the distance between the current (most recent) and desired configuration. If the index is out of range an exception is thrown.

Warning
Revert operation will rollback any changes to the staging configuration (if it exists).
This function requires that the entire previous configuration is copied to the new configuration object. This is not working for some of the complex configuration objects, e.g. subnets. Hence, the "revert" operation is not really usable at this point.
Parameters
indexA distance from the current configuration to the past configuration to be reverted. The minimal value is 1 which points to the nearest configuration.
Exceptions
isc::OutOfRangeif the specified index is out of range.

Definition at line 121 of file cfgmgr.cc.

References isc_throw.

◆ rollback()

void isc::dhcp::CfgMgr::rollback ( )

Removes staging configuration.

This function should be called when there is a staging configuration (likely created in the previous configuration attempt) but the entirely new configuration should be created. It removes the existing staging configuration and the next call to CfgMgr::getStagingCfg will return a fresh (default) configuration.

This function is exception safe.

Definition at line 113 of file cfgmgr.cc.

◆ setD2ClientConfig()

void isc::dhcp::CfgMgr::setD2ClientConfig ( D2ClientConfigPtr new_config)

Updates the DHCP-DDNS client configuration to the given value.

Passes the new configuration to the D2ClientMgr instance, d2_client_mgr_, which will attempt to apply the new configuration by shutting down its sender and opening a new connection per the new configuration (see D2ClientMgr::setD2ClientConfig()).

Parameters
new_configpointer to the new client configuration.
Exceptions
Underlyingmethod(s) will throw D2ClientError if given an empty pointer.

Definition at line 40 of file cfgmgr.cc.

◆ setDataDir()

void isc::dhcp::CfgMgr::setDataDir ( const std::string &  datadir)

Sets new data directory.

Parameters
datadirNew data directory.

Definition at line 35 of file cfgmgr.cc.

◆ setFamily()

void isc::dhcp::CfgMgr::setFamily ( uint16_t  family)
inline

Sets address family (AF_INET or AF_INET6)

Definition at line 237 of file cfgmgr.h.

Member Data Documentation

◆ CONFIG_LIST_SIZE

const size_t isc::dhcp::CfgMgr::CONFIG_LIST_SIZE = 10
static

A number of configurations held by CfgMgr.

Todo:
Make it configurable.

Definition at line 75 of file cfgmgr.h.


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