Kea  1.5.0
isc::dhcp::HostMgr Class Reference

Host Manager. More...

#include <host_mgr.h>

+ Inheritance diagram for isc::dhcp::HostMgr:

Public Member Functions

virtual void add (const HostPtr &host)
 Adds a new host to the alternate data source. More...
 
virtual bool del (const SubnetID &subnet_id, const asiolink::IOAddress &addr)
 Attempts to delete a host by address. More...
 
virtual bool del4 (const SubnetID &subnet_id, const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len)
 Attempts to delete a host by (subnet4-id, identifier, identifier-type) More...
 
virtual bool del6 (const SubnetID &subnet_id, const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len)
 Attempts to delete a host by (subnet6-id, identifier, identifier-type) More...
 
virtual ConstHostPtr get4 (const SubnetID &subnet_id, const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len) const
 Returns a host connected to the IPv4 subnet. More...
 
virtual ConstHostPtr get4 (const SubnetID &subnet_id, const asiolink::IOAddress &address) const
 Returns a host connected to the IPv4 subnet and having a reservation for a specified IPv4 address. More...
 
virtual ConstHostPtr get4Any (const SubnetID &subnet_id, const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len) const
 Returns any host connected to the IPv4 subnet. More...
 
virtual ConstHostPtr get6 (const SubnetID &subnet_id, const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len) const
 Returns a host connected to the IPv6 subnet. More...
 
virtual ConstHostPtr get6 (const asiolink::IOAddress &prefix, const uint8_t prefix_len) const
 Returns a host using the specified IPv6 prefix. More...
 
virtual ConstHostPtr get6 (const SubnetID &subnet_id, const asiolink::IOAddress &addr) const
 Returns a host from specific subnet and reserved address. More...
 
virtual ConstHostPtr get6Any (const SubnetID &subnet_id, const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len) const
 Returns any host connected to the IPv6 subnet. More...
 
virtual ConstHostCollection getAll (const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len) const
 Return all hosts connected to any subnet for which reservations have been made using a specified identifier. More...
 
virtual ConstHostCollection getAll4 (const asiolink::IOAddress &address) const
 Returns a collection of hosts using the specified IPv4 address. More...
 
HostDataSourcePtr getHostDataSource () const
 Returns the first host data source. More...
 
HostDataSourceListgetHostDataSourceList ()
 Returns the host data source list. More...
 
bool getNegativeCaching () const
 Returns the negative caching flag. More...
 
virtual std::string getType () const
 Return backend type. More...
 
void setNegativeCaching (bool negative_caching)
 Sets the negative caching flag. More...
 
- Public Member Functions inherited from isc::dhcp::BaseHostDataSource
virtual ~BaseHostDataSource ()
 Default destructor implementation. More...
 
virtual void commit ()
 Commit Transactions. More...
 
virtual void rollback ()
 Rollback Transactions. More...
 

Static Public Member Functions

static void addBackend (const std::string &access)
 Add an alternate host backend (aka host data source). More...
 
static bool checkCacheBackend (bool logging=false)
 Check for the cache host backend. More...
 
static void create ()
 Creates new instance of the HostMgr. More...
 
static void delAllBackends ()
 Delete all alternate backends. More...
 
static bool delBackend (const std::string &db_type)
 Delete an alternate host backend (aka host data source). More...
 
static HostMgrinstance ()
 Returns a sole instance of the HostMgr. More...
 

Protected Member Functions

virtual void cache (ConstHostPtr host) const
 Cache an answer. More...
 
virtual void cacheNegative (const SubnetID &ipv4_subnet_id, const SubnetID &ipv6_subnet_id, const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len) const
 Cache a negative answer. More...
 

Protected Attributes

bool negative_caching_
 The negative caching flag. More...
 

Additional Inherited Members

- Public Types inherited from isc::dhcp::BaseHostDataSource
enum  IdType { ID_HWADDR = 0, ID_DUID = 1 }
 Specifies the type of an identifier. More...
 

Detailed Description

Host Manager.

This is a singleton class which provides access to multiple sources of information about static host reservations. These sources are also referred to as host data sources. Each source derives (directly or indirectly) from the BaseHostDataSource.

The HostMgr is a central point for providing information about the host reservations. Internally, it relays the queries (calls to the appropriate methods declared in the BaseHostDataSource) to the data sources it is connected to. The HostMgr is always connected to the server's configuration, accessible through the CfgHosts object in the CfgMgr. The CfgHosts object holds all reservations specified in the DHCP server configuration file. If a particular reservation is not found in the CfgHosts object, the HostMgr will try to find it using alternate host data storages. An alternate host data storage is usually a database (e.g. SQL database), accessible through a dedicated host data source object (a.k.a. database backend). This datasource is responsible for managing the connection with the database and forming appropriate queries to retrieve (or update) the information about the reservations.

The use of alternate host data sources is optional and usually requires additional configuration to be specified by the server administrator. For example, for the SQL database the user's credentials, database address, and database name are required. The HostMgr passes these parameters to an appropriate datasource which is responsible for opening a connection and maintaining it.

It is possible to switch to different alternate data sources or disable the use of alternate datasources, e.g. as a result of server's reconfiguration. However, the use of the primary host data source (i.e. reservations specified in the configuration file) can't be disabled.

Definition at line 54 of file host_mgr.h.

Member Function Documentation

◆ add()

void isc::dhcp::HostMgr::add ( const HostPtr host)
virtual

Adds a new host to the alternate data source.

This method will throw an exception if no alternate data source is in use.

Parameters
hostPointer to the new Host object being added.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 331 of file host_mgr.cc.

References isc_throw.

◆ addBackend()

void isc::dhcp::HostMgr::addBackend ( const std::string &  access)
static

Add an alternate host backend (aka host data source).

Parameters
accessHost backend access parameters for the alternate host backend. It holds "keyword=value" pairs, separated by spaces. The supported values are specific to the alternate backend in use. However, the "type" parameter will be common and it will specify which backend is to be used. Currently, no parameters are supported and the parameter is ignored.

Definition at line 45 of file host_mgr.cc.

References isc::dhcp::HostDataSourceFactory::add().

Referenced by isc::dhcp::CfgDbAccess::createManagers().

+ Here is the call graph for this function:

◆ cache()

void isc::dhcp::HostMgr::cache ( ConstHostPtr  host) const
protectedvirtual

Cache an answer.

Parameters
hostPointer to the missied host.

Definition at line 395 of file host_mgr.cc.

◆ cacheNegative()

void isc::dhcp::HostMgr::cacheNegative ( const SubnetID ipv4_subnet_id,
const SubnetID ipv6_subnet_id,
const Host::IdentifierType identifier_type,
const uint8_t *  identifier_begin,
const size_t  identifier_len 
) const
protectedvirtual

Cache a negative answer.

Parameters
ipv4_subnet_idIdentifier of the IPv4 subnet.
ipv6_subnet_idIdentifier of the IPv6 subnet.
identifier_typeIdentifier type.
identifier_beginPointer to a beginning of the Identifier.
identifier_lenIdentifier length.

Definition at line 408 of file host_mgr.cc.

References isc::asiolink::IOAddress::IPV4_ZERO_ADDRESS().

+ Here is the call graph for this function:

◆ checkCacheBackend()

bool isc::dhcp::HostMgr::checkCacheBackend ( bool  logging = false)
static

Check for the cache host backend.

Checks if the first host backend implements the cache abstract class and sets cache_ptr_.

Parameters
loggingWhen true (not the default) emit an informational log.
Returns
true if the first host backend is a cache.

Definition at line 68 of file host_mgr.cc.

References isc::dhcp::hosts_logger, and LOG_INFO.

Referenced by isc::dhcp::CfgDbAccess::createManagers().

◆ create()

void isc::dhcp::HostMgr::create ( )
static

Creates new instance of the HostMgr.

If an instance of the HostMgr already exists, it will be replaced by the new instance. Thus, any instances of alternate host data sources will be dropped.

Definition at line 40 of file host_mgr.cc.

Referenced by isc::dhcp::CfgDbAccess::createManagers().

◆ del()

bool isc::dhcp::HostMgr::del ( const SubnetID subnet_id,
const asiolink::IOAddress addr 
)
virtual

Attempts to delete a host by address.

This method supports both v4 and v6.

Parameters
subnet_idsubnet identifier.
addrspecified address.
Returns
true if deletion was successful, false otherwise.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 346 of file host_mgr.cc.

References isc_throw.

◆ del4()

bool isc::dhcp::HostMgr::del4 ( const SubnetID subnet_id,
const Host::IdentifierType identifier_type,
const uint8_t *  identifier_begin,
const size_t  identifier_len 
)
virtual

Attempts to delete a host by (subnet4-id, identifier, identifier-type)

This method supports v4 only.

Parameters
subnet_idIPv4 Subnet identifier.
identifier_typeIdentifier type.
identifier_beginPointer to a beginning of a buffer containing an identifier.
identifier_lenIdentifier length.
Returns
true if deletion was successful, false otherwise.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 361 of file host_mgr.cc.

References isc_throw.

◆ del6()

bool isc::dhcp::HostMgr::del6 ( const SubnetID subnet_id,
const Host::IdentifierType identifier_type,
const uint8_t *  identifier_begin,
const size_t  identifier_len 
)
virtual

Attempts to delete a host by (subnet6-id, identifier, identifier-type)

This method supports v6 only.

Parameters
subnet_idIPv6 Subnet identifier.
identifier_typeIdentifier type.
identifier_beginPointer to a beginning of a buffer containing an identifier.
identifier_lenIdentifier length.
Returns
true if deletion was successful, false otherwise.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 378 of file host_mgr.cc.

References isc_throw.

◆ delAllBackends()

void isc::dhcp::HostMgr::delAllBackends ( )
static

Delete all alternate backends.

Definition at line 55 of file host_mgr.cc.

◆ delBackend()

bool isc::dhcp::HostMgr::delBackend ( const std::string &  db_type)
static

Delete an alternate host backend (aka host data source).

Parameters
db_typedatabase backend type.
Returns
true when found and removed, false when not found.

Definition at line 50 of file host_mgr.cc.

References isc::dhcp::HostDataSourceFactory::del().

+ Here is the call graph for this function:

◆ get4() [1/2]

ConstHostPtr isc::dhcp::HostMgr::get4 ( const SubnetID subnet_id,
const Host::IdentifierType identifier_type,
const uint8_t *  identifier_begin,
const size_t  identifier_len 
) const
virtual

Returns a host connected to the IPv4 subnet.

This method returns a single reservation for a particular host as documented in the BaseHostDataSource::get4.

Parameters
subnet_idSubnet identifier.
identifier_typeIdentifier type.
identifier_beginPointer to a beginning of a buffer containing an identifier.
identifier_lenIdentifier length.
Returns
Const Host object for which reservation has been made using the specified identifier.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 175 of file host_mgr.cc.

Referenced by isc::dhcp::AllocEngine::findGlobalReservation(), and isc::dhcp::AllocEngine::findReservation().

◆ get4() [2/2]

ConstHostPtr isc::dhcp::HostMgr::get4 ( const SubnetID subnet_id,
const asiolink::IOAddress address 
) const
virtual

Returns a host connected to the IPv4 subnet and having a reservation for a specified IPv4 address.

This method returns a single reservation for the particular host (identified by the HW address or DUID) as documented in the BaseHostDataSource::get4.

Parameters
subnet_idSubnet identifier.
addressreserved IPv4 address.
Returns
Const Host object using a specified IPv4 address.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 191 of file host_mgr.cc.

References isc::dhcp::HOSTS_DBG_TRACE, isc::dhcp::hosts_logger, LOG_DEBUG, and isc::asiolink::IOAddress::toText().

+ Here is the call graph for this function:

◆ get4Any()

ConstHostPtr isc::dhcp::HostMgr::get4Any ( const SubnetID subnet_id,
const Host::IdentifierType identifier_type,
const uint8_t *  identifier_begin,
const size_t  identifier_len 
) const
virtual

Returns any host connected to the IPv4 subnet.

This method returns a single reservation for a particular host as documented in the BaseHostDataSource::get4 even when the reservation is marked as from negative caching. This allows to monitor negative caching.

Parameters
subnet_idSubnet identifier.
identifier_typeIdentifier type.
identifier_beginPointer to a beginning of a buffer containing an identifier.
identifier_lenIdentifier length.
Returns
Const Host object for which reservation has been made using the specified identifier.

Definition at line 125 of file host_mgr.cc.

References isc::dhcp::Host::getIdentifierAsText(), isc::dhcp::HOSTS_DBG_RESULTS, isc::dhcp::HOSTS_DBG_TRACE, isc::dhcp::hosts_logger, and LOG_DEBUG.

+ Here is the call graph for this function:

◆ get6() [1/3]

ConstHostPtr isc::dhcp::HostMgr::get6 ( const SubnetID subnet_id,
const Host::IdentifierType identifier_type,
const uint8_t *  identifier_begin,
const size_t  identifier_len 
) const
virtual

Returns a host connected to the IPv6 subnet.

This method returns a host connected to the IPv6 subnet as described in the BaseHostDataSource::get6.

Parameters
subnet_idSubnet identifier.
identifier_typeIdentifier type.
identifier_beginPointer to a beginning of a buffer containing an identifier.
identifier_lenIdentifier length.
Returns
Const Host object for which reservation has been made using the specified identifier.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 289 of file host_mgr.cc.

Referenced by isc::dhcp::AllocEngine::findGlobalReservation(), and isc::dhcp::AllocEngine::findReservation().

◆ get6() [2/3]

ConstHostPtr isc::dhcp::HostMgr::get6 ( const asiolink::IOAddress prefix,
const uint8_t  prefix_len 
) const
virtual

Returns a host using the specified IPv6 prefix.

This method returns a host using specified IPv6 prefix, as described in the BaseHostDataSource::get6.

Parameters
prefixIPv6 prefix for which the Host object is searched.
prefix_lenIPv6 prefix length.
Returns
Const Host object using a specified IPv6 prefix.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 218 of file host_mgr.cc.

References isc::dhcp::HOSTS_DBG_TRACE, isc::dhcp::hosts_logger, LOG_DEBUG, and isc::asiolink::IOAddress::toText().

+ Here is the call graph for this function:

◆ get6() [3/3]

ConstHostPtr isc::dhcp::HostMgr::get6 ( const SubnetID subnet_id,
const asiolink::IOAddress addr 
) const
virtual

Returns a host from specific subnet and reserved address.

Parameters
subnet_idsubnet identifier.
addrspecified address.
Returns
Const host object that has a reservation for specified address.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 305 of file host_mgr.cc.

References isc::dhcp::HOSTS_DBG_TRACE, isc::dhcp::hosts_logger, LOG_DEBUG, and isc::asiolink::IOAddress::toText().

+ Here is the call graph for this function:

◆ get6Any()

ConstHostPtr isc::dhcp::HostMgr::get6Any ( const SubnetID subnet_id,
const Host::IdentifierType identifier_type,
const uint8_t *  identifier_begin,
const size_t  identifier_len 
) const
virtual

Returns any host connected to the IPv6 subnet.

This method returns a host connected to the IPv6 subnet as described in the BaseHostDataSource::get6 even when the

reservation is marked as from negative caching. This allows to monitor negative caching.

Parameters
subnet_idSubnet identifier.
identifier_typeIdentifier type.
identifier_beginPointer to a beginning of a buffer containing an identifier.
identifier_lenIdentifier length.
Returns
Const Host object for which reservation has been made using the specified identifier.

Definition at line 242 of file host_mgr.cc.

References isc::dhcp::Host::getIdentifierAsText(), isc::dhcp::HOSTS_DBG_RESULTS, isc::dhcp::HOSTS_DBG_TRACE, isc::dhcp::hosts_logger, and LOG_DEBUG.

+ Here is the call graph for this function:

◆ getAll()

ConstHostCollection isc::dhcp::HostMgr::getAll ( const Host::IdentifierType identifier_type,
const uint8_t *  identifier_begin,
const size_t  identifier_len 
) const
virtual

Return all hosts connected to any subnet for which reservations have been made using a specified identifier.

This method returns all Host objects representing reservations for a specified identifier as documented in the BaseHostDataSource::getAll.

It retrieves reservations from both primary and alternate host data source as a single collection of Host objects, i.e. if matching reservations are in both sources, all of them are returned. The reservations from the primary data source are placed before the reservations from the alternate source.

Parameters
identifier_typeIdentifier type.
identifier_beginPointer to a beginning of a buffer containing an identifier.
identifier_lenIdentifier length.
Returns
Collection of const Host objects.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 99 of file host_mgr.cc.

Referenced by isc::dhcp::AllocEngine::findReservation().

◆ getAll4()

ConstHostCollection isc::dhcp::HostMgr::getAll4 ( const asiolink::IOAddress address) const
virtual

Returns a collection of hosts using the specified IPv4 address.

This method may return multiple Host objects if they are connected to different subnets.

If matching reservations are both in the primary and the alternate data source, all of them are returned. The reservations from the primary data source are placed before the reservations from the alternate source.

Parameters
addressIPv4 address for which the Host object is searched.
Returns
Collection of const Host objects.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 115 of file host_mgr.cc.

◆ getHostDataSource()

HostDataSourcePtr isc::dhcp::HostMgr::getHostDataSource ( ) const

Returns the first host data source.

May return NULL if the host data source list is empty.

Returns
pointer to the first host data source (or NULL).

Definition at line 60 of file host_mgr.cc.

◆ getHostDataSourceList()

HostDataSourceList& isc::dhcp::HostMgr::getHostDataSourceList ( )
inline

Returns the host data source list.

Returns
reference to the host data source list.

Definition at line 311 of file host_mgr.h.

◆ getNegativeCaching()

bool isc::dhcp::HostMgr::getNegativeCaching ( ) const
inline

Returns the negative caching flag.

Returns
the negative caching flag.

Definition at line 324 of file host_mgr.h.

References negative_caching_.

◆ getType()

virtual std::string isc::dhcp::HostMgr::getType ( ) const
inlinevirtual

Return backend type.

Returns the type of the backend (e.g. "mysql", "memfile" etc.)

Returns
Type of the backend.

Implements isc::dhcp::BaseHostDataSource.

Definition at line 304 of file host_mgr.h.

◆ instance()

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

Returns a sole instance of the HostMgr.

This method should be used to retrieve an instance of the HostMgr to be used to gather/manage host reservations. It returns an instance of the HostMgr created by the create method. If such instance doesn't exist yet, it is created using the create method with the default value of the data access string, which configures the host manager to not use the alternate host data source.

Definition at line 90 of file host_mgr.cc.

Referenced by isc::dhcp::AllocEngine::findGlobalReservation(), and isc::dhcp::AllocEngine::findReservation().

◆ setNegativeCaching()

void isc::dhcp::HostMgr::setNegativeCaching ( bool  negative_caching)
inline

Sets the negative caching flag.

Definition at line 330 of file host_mgr.h.

References negative_caching_.

Member Data Documentation

◆ negative_caching_

bool isc::dhcp::HostMgr::negative_caching_
protected

The negative caching flag.

When true and the first backend is a cache negative answers are inserted in the cache. This works for get[46] for a subnet and an identifier.

Definition at line 340 of file host_mgr.h.

Referenced by getNegativeCaching(), and setNegativeCaching().


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