Kea: host_mgr.h Source File

| Kea 3.0.3-git

host_mgr.h
Go to the documentation of this file.
1// Copyright (C) 2014-2023 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#ifndef HOST_MGR_H
8#define HOST_MGR_H
9
10#include <asiolink/io_service.h>
11#include <database/database_connection.h>
12#include <dhcpsrv/base_host_data_source.h>
13#include <dhcpsrv/cache_host_data_source.h>
14#include <dhcpsrv/host.h>
15#include <dhcpsrv/subnet_id.h>
16#include <boost/noncopyable.hpp>
17#include <boost/scoped_ptr.hpp>
18#include <string>
19#include <cstdint>
20
21namespace isc {
22namespace dhcp {
23
24// Enum flags to define a target of the host manager functions.
25 enum HostMgrOperationTarget {
26 // The operation target not specified. Consider nothing.
27 UNSPECIFIED_SOURCE = 0,
28 // Consider only the CfgHosts instance.
29 PRIMARY_SOURCE = 1, // 1 << 1
30 // Consider only the alternate sources.
31 ALTERNATE_SOURCES = 2, // 1 << 2
32 // Consider both CfgInstance and alternate sources.
33 ALL_SOURCES = 3 // PRIMARY_SOURCE | ALTERNATE_SOURCES
34};
35
68 class HostMgr : public boost::noncopyable, public BaseHostDataSource {
69public:
70
77 static void create();
78
88 static void addBackend(const std::string& access);
89
94 static bool delBackend(const std::string& db_type);
95
105 static bool delBackend(const std::string& db_type,
106 const std::string& access,
107 bool if_unusable = false);
108
110 static void delAllBackends();
111
119 static bool checkCacheBackend(bool logging = false);
120
129 static HostMgr& instance();
130
151 ConstHostCollection
152 getAll(const Host::IdentifierType& identifier_type,
153 const uint8_t* identifier_begin,
154 const size_t identifier_len,
155 const HostMgrOperationTarget target) const;
156
159 virtual ConstHostCollection
160 getAll(const Host::IdentifierType& identifier_type,
161 const uint8_t* identifier_begin,
162 const size_t identifier_len) const;
163
180 ConstHostCollection
181 getAll4(const SubnetID& subnet_id, const HostMgrOperationTarget target) const;
182
185 virtual ConstHostCollection
186 getAll4(const SubnetID& subnet_id) const;
187
204 ConstHostCollection
205 getAll6(const SubnetID& subnet_id,
206 const HostMgrOperationTarget target) const;
207
210 virtual ConstHostCollection
211 getAll6(const SubnetID& subnet_id) const;
212
222 ConstHostCollection
223 getAllbyHostname(const std::string& hostname,
224 const HostMgrOperationTarget target) const;
225
228 virtual ConstHostCollection
229 getAllbyHostname(const std::string& hostname) const;
230
241 ConstHostCollection
242 getAllbyHostname4(const std::string& hostname, const SubnetID& subnet_id,
243 const HostMgrOperationTarget target) const;
244
247 virtual ConstHostCollection
248 getAllbyHostname4(const std::string& hostname, const SubnetID& subnet_id) const;
249
260 ConstHostCollection
261 getAllbyHostname6(const std::string& hostname, const SubnetID& subnet_id,
262 const HostMgrOperationTarget target) const;
263
266 virtual ConstHostCollection
267 getAllbyHostname6(const std::string& hostname, const SubnetID& subnet_id) const;
268
293 virtual ConstHostCollection
294 getPage4(const SubnetID& subnet_id,
295 size_t& source_index,
296 uint64_t lower_host_id,
297 const HostPageSize& page_size) const;
298
323 virtual ConstHostCollection
324 getPage6(const SubnetID& subnet_id,
325 size_t& source_index,
326 uint64_t lower_host_id,
327 const HostPageSize& page_size) const;
328
351 virtual ConstHostCollection
352 getPage4(size_t& source_index,
353 uint64_t lower_host_id,
354 const HostPageSize& page_size) const;
355
378 virtual ConstHostCollection
379 getPage6(size_t& source_index,
380 uint64_t lower_host_id,
381 const HostPageSize& page_size) const;
382
397 ConstHostCollection
398 getAll4(const asiolink::IOAddress& address,
399 const HostMgrOperationTarget target) const;
400
403 virtual ConstHostCollection
404 getAll4(const asiolink::IOAddress& address) const;
405
422 ConstHostPtr
423 get4Any(const SubnetID& subnet_id,
424 const Host::IdentifierType& identifier_type,
425 const uint8_t* identifier_begin,
426 const size_t identifier_len,
427 const HostMgrOperationTarget target) const;
428
431 virtual ConstHostPtr
432 get4Any(const SubnetID& subnet_id,
433 const Host::IdentifierType& identifier_type,
434 const uint8_t* identifier_begin,
435 const size_t identifier_len) const;
436
451 ConstHostPtr
452 get4(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type,
453 const uint8_t* identifier_begin, const size_t identifier_len,
454 const HostMgrOperationTarget target) const;
455
458 virtual ConstHostPtr
459 get4(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type,
460 const uint8_t* identifier_begin, const size_t identifier_len) const;
461
474 ConstHostPtr
475 get4(const SubnetID& subnet_id, const asiolink::IOAddress& address,
476 const HostMgrOperationTarget target) const;
477
480 virtual ConstHostPtr
481 get4(const SubnetID& subnet_id, const asiolink::IOAddress& address) const;
482
507 ConstHostCollection
508 getAll4(const SubnetID& subnet_id,
509 const asiolink::IOAddress& address,
510 const HostMgrOperationTarget target) const;
511
514 virtual ConstHostCollection
515 getAll4(const SubnetID& subnet_id,
516 const asiolink::IOAddress& address) const;
517
534 ConstHostPtr
535 get6Any(const SubnetID& subnet_id,
536 const Host::IdentifierType& identifier_type,
537 const uint8_t* identifier_begin,
538 const size_t identifier_len,
539 const HostMgrOperationTarget target) const;
540
543 virtual ConstHostPtr
544 get6Any(const SubnetID& subnet_id,
545 const Host::IdentifierType& identifier_type,
546 const uint8_t* identifier_begin,
547 const size_t identifier_len) const;
548
563 ConstHostPtr
564 get6(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type,
565 const uint8_t* identifier_begin, const size_t identifier_len,
566 const HostMgrOperationTarget target) const;
567
570 virtual ConstHostPtr
571 get6(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type,
572 const uint8_t* identifier_begin, const size_t identifier_len) const;
573
584 ConstHostPtr
585 get6(const asiolink::IOAddress& prefix, const uint8_t prefix_len,
586 const HostMgrOperationTarget target) const;
587
590 virtual ConstHostPtr
591 get6(const asiolink::IOAddress& prefix, const uint8_t prefix_len) const;
592
600 ConstHostPtr
601 get6(const SubnetID& subnet_id, const asiolink::IOAddress& addr,
602 const HostMgrOperationTarget target) const;
603
606 virtual ConstHostPtr
607 get6(const SubnetID& subnet_id, const asiolink::IOAddress& addr) const;
608
633 ConstHostCollection
634 getAll6(const SubnetID& subnet_id,
635 const asiolink::IOAddress& address,
636 const HostMgrOperationTarget target) const;
637
640 virtual ConstHostCollection
641 getAll6(const SubnetID& subnet_id,
642 const asiolink::IOAddress& address) const;
643
646 virtual ConstHostCollection
647 getAll6(const asiolink::IOAddress& address) const;
648
663 ConstHostCollection
664 getAll6(const asiolink::IOAddress& address,
665 const HostMgrOperationTarget target) const;
666
674 void add(const HostPtr& host, const HostMgrOperationTarget target);
675
678 virtual void add(const HostPtr& host);
679
693 bool del(const SubnetID& subnet_id, const asiolink::IOAddress& addr,
694 const HostMgrOperationTarget target);
695
698 virtual bool del(const SubnetID& subnet_id, const asiolink::IOAddress& addr);
699
712 bool
713 del4(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type,
714 const uint8_t* identifier_begin, const size_t identifier_len,
715 const HostMgrOperationTarget target);
716
719 virtual bool
720 del4(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type,
721 const uint8_t* identifier_begin, const size_t identifier_len);
722
735 bool
736 del6(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type,
737 const uint8_t* identifier_begin, const size_t identifier_len,
738 const HostMgrOperationTarget target);
739
742 virtual bool
743 del6(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type,
744 const uint8_t* identifier_begin, const size_t identifier_len);
745
752 void update(HostPtr const& host, const HostMgrOperationTarget target);
753
756 void update(HostPtr const& host);
757
763 virtual std::string getType() const {
764 return (std::string("host_mgr"));
765 }
766
770 HostDataSourceList& getHostDataSourceList() {
771 return (alternate_sources_);
772 }
773
778 HostDataSourcePtr getHostDataSource() const;
779
783 bool getNegativeCaching() const {
784 return (negative_caching_);
785 }
786
789 void setNegativeCaching(bool negative_caching) {
790 negative_caching_ = negative_caching;
791 }
792
796 bool getDisableSingleQuery() const {
797 return (disable_single_query_);
798 }
799
802 void setDisableSingleQuery(bool disable_single_query) {
803 disable_single_query_ = disable_single_query;
804 }
805
824 virtual bool setIPReservationsUnique(const bool unique);
825
831 bool getIPReservationsUnique() const {
832 return (ip_reservations_unique_);
833 }
834
835protected:
836
842 bool negative_caching_;
843
849 bool disable_single_query_;
850
854 virtual void cache(ConstHostPtr host) const;
855
863 virtual void cacheNegative(const SubnetID& ipv4_subnet_id,
864 const SubnetID& ipv6_subnet_id,
865 const Host::IdentifierType& identifier_type,
866 const uint8_t* identifier_begin,
867 const size_t identifier_len) const;
868
869private:
870
877 bool ip_reservations_unique_;
878
880 HostMgr() : negative_caching_(false), disable_single_query_(false),
881 ip_reservations_unique_(true) { }
882
884 HostDataSourceList alternate_sources_;
885
887 CacheHostDataSourcePtr cache_ptr_;
888
891 static boost::scoped_ptr<HostMgr>& getHostMgrPtr();
892};
893
894} // namespace dhcp
895} // namespace isc
896
897#endif // HOST_MGR_H
base_host_data_source.h
cache_host_data_source.h
isc::asiolink::IOAddress
The IOAddress class represents an IP addresses (version agnostic).
Definition io_address.h:45
isc::dhcp::BaseHostDataSource
Base interface for the classes implementing simple data source for host reservations.
Definition base_host_data_source.h:88
isc::dhcp::HostMgr::getAll6
ConstHostCollection getAll6(const SubnetID &subnet_id, const HostMgrOperationTarget target) const
Return all hosts in a DHCPv6 subnet.
Definition host_mgr.cc:171
isc::dhcp::HostMgr::getAll4
ConstHostCollection getAll4(const SubnetID &subnet_id, const HostMgrOperationTarget target) const
Return all hosts in a DHCPv4 subnet.
Definition host_mgr.cc:151
isc::dhcp::HostMgr::delAllBackends
static void delAllBackends()
Delete all alternate backends.
Definition host_mgr.cc:79
isc::dhcp::HostMgr::create
static void create()
Creates new instance of the HostMgr.
Definition host_mgr.cc:52
isc::dhcp::HostMgr::negative_caching_
bool negative_caching_
The negative caching flag.
Definition host_mgr.h:842
isc::dhcp::HostMgr::cacheNegative
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.
Definition host_mgr.cc:940
isc::dhcp::HostMgr::getPage6
virtual ConstHostCollection getPage6(const SubnetID &subnet_id, size_t &source_index, uint64_t lower_host_id, const HostPageSize &page_size) const
Returns range of hosts in a DHCPv6 subnet.
Definition host_mgr.cc:290
isc::dhcp::HostMgr::getNegativeCaching
bool getNegativeCaching() const
Returns the negative caching flag.
Definition host_mgr.h:783
isc::dhcp::HostMgr::setIPReservationsUnique
virtual bool setIPReservationsUnique(const bool unique)
Controls whether IP reservations are unique or non-unique.
Definition host_mgr.cc:958
isc::dhcp::HostMgr::get6Any
ConstHostPtr get6Any(const SubnetID &subnet_id, const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len, const HostMgrOperationTarget target) const
Returns any host connected to the IPv6 subnet.
Definition host_mgr.cc:590
isc::dhcp::HostMgr::setDisableSingleQuery
void setDisableSingleQuery(bool disable_single_query)
Sets the disable single query flag.
Definition host_mgr.h:802
isc::dhcp::HostMgr::getType
virtual std::string getType() const
Return backend type.
Definition host_mgr.h:763
isc::dhcp::HostMgr::getAllbyHostname4
ConstHostCollection getAllbyHostname4(const std::string &hostname, const SubnetID &subnet_id, const HostMgrOperationTarget target) const
Return all hosts with a hostname in a DHCPv4 subnet.
Definition host_mgr.cc:211
isc::dhcp::HostMgr::del4
bool del4(const SubnetID &subnet_id, const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len, const HostMgrOperationTarget target)
Attempts to delete a host by (subnet4-id, identifier, identifier-type, operation-target).
Definition host_mgr.cc:824
isc::dhcp::HostMgr::cache
virtual void cache(ConstHostPtr host) const
Cache an answer.
Definition host_mgr.cc:927
isc::dhcp::HostMgr::delBackend
static bool delBackend(const std::string &db_type)
Delete an alternate host backend (aka host data source).
Definition host_mgr.cc:62
isc::dhcp::HostMgr::addBackend
static void addBackend(const std::string &access)
Add an alternate host backend (aka host data source).
Definition host_mgr.cc:57
isc::dhcp::HostMgr::getAll
ConstHostCollection getAll(const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len, const HostMgrOperationTarget target) const
Return all hosts connected to any subnet for which reservations have been made using a specified iden...
Definition host_mgr.cc:123
isc::dhcp::HostMgr::get4Any
ConstHostPtr get4Any(const SubnetID &subnet_id, const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len, const HostMgrOperationTarget target) const
Returns any host connected to the IPv4 subnet.
Definition host_mgr.cc:401
isc::dhcp::HostMgr::getDisableSingleQuery
bool getDisableSingleQuery() const
Returns the disable single query flag.
Definition host_mgr.h:796
isc::dhcp::HostMgr::del6
bool del6(const SubnetID &subnet_id, const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len, const HostMgrOperationTarget target)
Attempts to delete a host by (subnet6-id, identifier, identifier-type, operation-target).
Definition host_mgr.cc:861
isc::dhcp::HostMgr::add
void add(const HostPtr &host, const HostMgrOperationTarget target)
Adds a new host to the alternate data source.
Definition host_mgr.cc:764
isc::dhcp::HostMgr::del
bool del(const SubnetID &subnet_id, const asiolink::IOAddress &addr, const HostMgrOperationTarget target)
Attempts to delete hosts by address.
Definition host_mgr.cc:794
isc::dhcp::HostMgr::setNegativeCaching
void setNegativeCaching(bool negative_caching)
Sets the negative caching flag.
Definition host_mgr.h:789
isc::dhcp::HostMgr::getAllbyHostname6
ConstHostCollection getAllbyHostname6(const std::string &hostname, const SubnetID &subnet_id, const HostMgrOperationTarget target) const
Return all hosts with a hostname in a DHCPv6 subnet.
Definition host_mgr.cc:235
isc::dhcp::HostMgr::disable_single_query_
bool disable_single_query_
The disable single query flag.
Definition host_mgr.h:849
isc::dhcp::HostMgr::getPage4
virtual ConstHostCollection getPage4(const SubnetID &subnet_id, size_t &source_index, uint64_t lower_host_id, const HostPageSize &page_size) const
Returns range of hosts in a DHCPv4 subnet.
Definition host_mgr.cc:259
isc::dhcp::HostMgr::getHostDataSource
HostDataSourcePtr getHostDataSource() const
Returns the first host data source.
Definition host_mgr.cc:84
isc::dhcp::HostMgr::checkCacheBackend
static bool checkCacheBackend(bool logging=false)
Check for the cache host backend.
Definition host_mgr.cc:92
isc::dhcp::HostMgr::getIPReservationsUnique
bool getIPReservationsUnique() const
Returns the boolean flag indicating if the IP reservations must be unique or can be non-unique.
Definition host_mgr.h:831
isc::dhcp::HostMgr::instance
static HostMgr & instance()
Returns a sole instance of the HostMgr.
Definition host_mgr.cc:114
isc::dhcp::HostMgr::update
void update(HostPtr const &host, const HostMgrOperationTarget target)
Implements BaseHostDataSource::update() for alternate sources.
Definition host_mgr.cc:898
isc::dhcp::HostMgr::getAllbyHostname
ConstHostCollection getAllbyHostname(const std::string &hostname, const HostMgrOperationTarget target) const
Return all hosts with a hostname.
Definition host_mgr.cc:191
isc::dhcp::HostMgr::getHostDataSourceList
HostDataSourceList & getHostDataSourceList()
Returns the host data source list.
Definition host_mgr.h:770
isc::dhcp::HostMgr::get4
ConstHostPtr get4(const SubnetID &subnet_id, const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len, const HostMgrOperationTarget target) const
Returns a host connected to the IPv4 subnet.
Definition host_mgr.cc:465
isc::dhcp::HostMgr::get6
ConstHostPtr get6(const SubnetID &subnet_id, const Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len, const HostMgrOperationTarget target) const
Returns a host connected to the IPv6 subnet.
Definition host_mgr.cc:650
isc::dhcp::HostPageSize
Wraps value holding size of the page with host reservations.
Definition base_host_data_source.h:53
isc::dhcp::Host::IdentifierType
IdentifierType
Type of the host identifier.
Definition host.h:337
database_connection.h
host.h
io_service.h
isc::dhcp
Definition dhcp4/client_handler.cc:20
isc::dhcp::HostDataSourcePtr
boost::shared_ptr< BaseHostDataSource > HostDataSourcePtr
HostDataSource pointer.
Definition base_host_data_source.h:572
isc::dhcp::HostPtr
boost::shared_ptr< Host > HostPtr
Pointer to the Host object.
Definition host.h:837
isc::dhcp::ConstHostCollection
std::vector< ConstHostPtr > ConstHostCollection
Collection of the const Host objects.
Definition host.h:843
isc::dhcp::HostDataSourceList
std::vector< HostDataSourcePtr > HostDataSourceList
HostDataSource list.
Definition base_host_data_source.h:575
isc::dhcp::CacheHostDataSourcePtr
boost::shared_ptr< CacheHostDataSource > CacheHostDataSourcePtr
CacheHostDataSource pointer.
Definition cache_host_data_source.h:63
isc::dhcp::SubnetID
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
Definition subnet_id.h:25
isc::dhcp::ConstHostPtr
boost::shared_ptr< const Host > ConstHostPtr
Const pointer to the Host object.
Definition host.h:840
isc::dhcp::HostMgrOperationTarget
HostMgrOperationTarget
Definition host_mgr.h:25
isc::dhcp::PRIMARY_SOURCE
@ PRIMARY_SOURCE
Definition host_mgr.h:29
isc::dhcp::ALTERNATE_SOURCES
@ ALTERNATE_SOURCES
Definition host_mgr.h:31
isc::dhcp::UNSPECIFIED_SOURCE
@ UNSPECIFIED_SOURCE
Definition host_mgr.h:27
isc::dhcp::ALL_SOURCES
@ ALL_SOURCES
Definition host_mgr.h:33
isc
Defines the logger used by the top-level component of kea-lfc.
Definition agent_parser.cc:148
subnet_id.h