Kea 2.2.0
host_mgr.h
Go to the documentation of this file.
1// Copyright (C) 2014-2021 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>
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
20namespace isc {
21namespace dhcp {
22
55class HostMgr : public boost::noncopyable, public BaseHostDataSource {
56public:
57
64 static void create();
65
75 static void addBackend(const std::string& access);
76
81 static bool delBackend(const std::string& db_type);
82
92 static bool delBackend(const std::string& db_type,
93 const std::string& access,
94 bool if_unusable = false);
95
97 static void delAllBackends();
98
106 static bool checkCacheBackend(bool logging = false);
107
116 static HostMgr& instance();
117
137 virtual ConstHostCollection
138 getAll(const Host::IdentifierType& identifier_type,
139 const uint8_t* identifier_begin,
140 const size_t identifier_len) const;
141
157 virtual ConstHostCollection
158 getAll4(const SubnetID& subnet_id) const;
159
175 virtual ConstHostCollection
176 getAll6(const SubnetID& subnet_id) const;
177
186 virtual ConstHostCollection
187 getAllbyHostname(const std::string& hostname) const;
188
198 virtual ConstHostCollection
199 getAllbyHostname4(const std::string& hostname, const SubnetID& subnet_id) const;
200
210 virtual ConstHostCollection
211 getAllbyHostname6(const std::string& hostname, const SubnetID& subnet_id) const;
212
237 virtual ConstHostCollection
238 getPage4(const SubnetID& subnet_id,
239 size_t& source_index,
240 uint64_t lower_host_id,
241 const HostPageSize& page_size) const;
242
267 virtual ConstHostCollection
268 getPage6(const SubnetID& subnet_id,
269 size_t& source_index,
270 uint64_t lower_host_id,
271 const HostPageSize& page_size) const;
272
295 virtual ConstHostCollection
296 getPage4(size_t& source_index,
297 uint64_t lower_host_id,
298 const HostPageSize& page_size) const;
299
322 virtual ConstHostCollection
323 getPage6(size_t& source_index,
324 uint64_t lower_host_id,
325 const HostPageSize& page_size) const;
326
340 virtual ConstHostCollection
341 getAll4(const asiolink::IOAddress& address) const;
342
358 virtual ConstHostPtr
359 get4Any(const SubnetID& subnet_id,
360 const Host::IdentifierType& identifier_type,
361 const uint8_t* identifier_begin,
362 const size_t identifier_len) const;
363
377 virtual ConstHostPtr
378 get4(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type,
379 const uint8_t* identifier_begin, const size_t identifier_len) const;
380
392 virtual ConstHostPtr
393 get4(const SubnetID& subnet_id, const asiolink::IOAddress& address) const;
394
418 virtual ConstHostCollection
419 getAll4(const SubnetID& subnet_id,
420 const asiolink::IOAddress& address) const;
421
437 virtual ConstHostPtr
438 get6Any(const SubnetID& subnet_id,
439 const Host::IdentifierType& identifier_type,
440 const uint8_t* identifier_begin,
441 const size_t identifier_len) const;
442
456 virtual ConstHostPtr
457 get6(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type,
458 const uint8_t* identifier_begin, const size_t identifier_len) const;
459
469 virtual ConstHostPtr
470 get6(const asiolink::IOAddress& prefix, const uint8_t prefix_len) const;
471
478 virtual ConstHostPtr
479 get6(const SubnetID& subnet_id, const asiolink::IOAddress& addr) const;
480
504 virtual ConstHostCollection
505 getAll6(const SubnetID& subnet_id,
506 const asiolink::IOAddress& address) const;
507
514 virtual void add(const HostPtr& host);
515
528 virtual bool del(const SubnetID& subnet_id, const asiolink::IOAddress& addr);
529
540 virtual bool
541 del4(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type,
542 const uint8_t* identifier_begin, const size_t identifier_len);
543
554 virtual bool
555 del6(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type,
556 const uint8_t* identifier_begin, const size_t identifier_len);
557
563 virtual std::string getType() const {
564 return (std::string("host_mgr"));
565 }
566
571 return (alternate_sources_);
572 }
573
579
583 bool getNegativeCaching() const {
584 return (negative_caching_);
585 }
586
589 void setNegativeCaching(bool negative_caching) {
590 negative_caching_ = negative_caching;
591 }
592
597 return (disable_single_query_);
598 }
599
602 void setDisableSingleQuery(bool disable_single_query) {
603 disable_single_query_ = disable_single_query;
604 }
605
624 virtual bool setIPReservationsUnique(const bool unique);
625
632 return (ip_reservations_unique_);
633 }
634
638 static void setIOService(const isc::asiolink::IOServicePtr& io_service) {
639 io_service_ = io_service;
640 }
641
644 return (io_service_);
645 }
646
647protected:
648
655
662
666 virtual void cache(ConstHostPtr host) const;
667
675 virtual void cacheNegative(const SubnetID& ipv4_subnet_id,
676 const SubnetID& ipv6_subnet_id,
677 const Host::IdentifierType& identifier_type,
678 const uint8_t* identifier_begin,
679 const size_t identifier_len) const;
680
681private:
682
689 bool ip_reservations_unique_;
690
693 ip_reservations_unique_(true) { }
694
696 HostDataSourceList alternate_sources_;
697
699 CacheHostDataSourcePtr cache_ptr_;
700
703 static boost::scoped_ptr<HostMgr>& getHostMgrPtr();
704
706 static isc::asiolink::IOServicePtr io_service_;
707};
708
709} // namespace dhcp
710} // namespace isc
711
712#endif // HOST_MGR_H
Base interface for the classes implementing simple data source for host reservations.
Host Manager.
Definition: host_mgr.h:55
static void setIOService(const isc::asiolink::IOServicePtr &io_service)
Sets IO service to be used by the Host Manager.
Definition: host_mgr.h:638
virtual void add(const HostPtr &host)
Adds a new host to the alternate data source.
Definition: host_mgr.cc:557
static void delAllBackends()
Delete all alternate backends.
Definition: host_mgr.cc:70
static void create()
Creates new instance of the HostMgr.
Definition: host_mgr.cc:43
bool negative_caching_
The negative caching flag.
Definition: host_mgr.h:654
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:634
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:217
bool getNegativeCaching() const
Returns the negative caching flag.
Definition: host_mgr.h:583
virtual bool setIPReservationsUnique(const bool unique)
Controls whether IP reservations are unique or non-unique.
Definition: host_mgr.cc:652
void setDisableSingleQuery(bool disable_single_query)
Sets the disable single query flag.
Definition: host_mgr.h:602
virtual std::string getType() const
Return backend type.
Definition: host_mgr.h:563
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 iden...
Definition: host_mgr.cc:114
virtual ConstHostCollection getAllbyHostname6(const std::string &hostname, const SubnetID &subnet_id) const
Return all hosts with a hostname in a DHCPv6 subnet.
Definition: host_mgr.cc:173
virtual ConstHostCollection getAllbyHostname4(const std::string &hostname, const SubnetID &subnet_id) const
Return all hosts with a hostname in a DHCPv4 subnet.
Definition: host_mgr.cc:160
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.
Definition: host_mgr.cc:318
virtual void cache(ConstHostPtr host) const
Cache an answer.
Definition: host_mgr.cc:621
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)
Definition: host_mgr.cc:604
static bool delBackend(const std::string &db_type)
Delete an alternate host backend (aka host data source).
Definition: host_mgr.cc:53
static void addBackend(const std::string &access)
Add an alternate host backend (aka host data source).
Definition: host_mgr.cc:48
static isc::asiolink::IOServicePtr & getIOService()
Returns pointer to the IO service.
Definition: host_mgr.h:643
bool getDisableSingleQuery() const
Returns the disable single query flag.
Definition: host_mgr.h:596
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.
Definition: host_mgr.cc:498
virtual ConstHostCollection getAll6(const SubnetID &subnet_id) const
Return all hosts in a DHCPv6 subnet.
Definition: host_mgr.cc:140
void setNegativeCaching(bool negative_caching)
Sets the negative caching flag.
Definition: host_mgr.h:589
bool disable_single_query_
The disable single query flag.
Definition: host_mgr.h:661
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:186
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.
Definition: host_mgr.cc:368
HostDataSourcePtr getHostDataSource() const
Returns the first host data source.
Definition: host_mgr.cc:75
static bool checkCacheBackend(bool logging=false)
Check for the cache host backend.
Definition: host_mgr.cc:83
bool getIPReservationsUnique() const
Returns the boolean flag indicating if the IP reservations must be unique or can be non-unique.
Definition: host_mgr.h:631
virtual bool del(const SubnetID &subnet_id, const asiolink::IOAddress &addr)
Attempts to delete hosts by address.
Definition: host_mgr.cc:572
static HostMgr & instance()
Returns a sole instance of the HostMgr.
Definition: host_mgr.cc:105
virtual ConstHostCollection getAll4(const SubnetID &subnet_id) const
Return all hosts in a DHCPv4 subnet.
Definition: host_mgr.cc:129
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.
Definition: host_mgr.cc:451
virtual ConstHostCollection getAllbyHostname(const std::string &hostname) const
Return all hosts with a hostname.
Definition: host_mgr.cc:150
HostDataSourceList & getHostDataSourceList()
Returns the host data source list.
Definition: host_mgr.h:570
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)
Definition: host_mgr.cc:587
Wraps value holding size of the page with host reservations.
IdentifierType
Type of the host identifier.
Definition: host.h:307
boost::shared_ptr< BaseHostDataSource > HostDataSourcePtr
HostDataSource pointer.
boost::shared_ptr< Host > HostPtr
Pointer to the Host object.
Definition: host.h:785
std::vector< ConstHostPtr > ConstHostCollection
Collection of the const Host objects.
Definition: host.h:791
std::vector< HostDataSourcePtr > HostDataSourceList
HostDataSource list.
boost::shared_ptr< CacheHostDataSource > CacheHostDataSourcePtr
CacheHostDataSource pointer.
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
Definition: subnet_id.h:24
boost::shared_ptr< const Host > ConstHostPtr
Const pointer to the Host object.
Definition: host.h:788
Defines the logger used by the top-level component of kea-lfc.