Kea 1.5.0
host_mgr.h
Go to the documentation of this file.
1// Copyright (C) 2014-2018 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
13#include <dhcpsrv/host.h>
14#include <dhcpsrv/subnet_id.h>
15#include <boost/noncopyable.hpp>
16#include <boost/scoped_ptr.hpp>
17#include <string>
18
19namespace isc {
20namespace dhcp {
21
54class HostMgr : public boost::noncopyable, public BaseHostDataSource {
55public:
56
63 static void create();
64
73 static void addBackend(const std::string& access);
74
79 static bool delBackend(const std::string& db_type);
80
82 static void delAllBackends();
83
91 static bool checkCacheBackend(bool logging = false);
92
101 static HostMgr& instance();
102
122 virtual ConstHostCollection
123 getAll(const Host::IdentifierType& identifier_type,
124 const uint8_t* identifier_begin,
125 const size_t identifier_len) const;
126
140 virtual ConstHostCollection
141 getAll4(const asiolink::IOAddress& address) const;
142
158 virtual ConstHostPtr
159 get4Any(const SubnetID& subnet_id,
160 const Host::IdentifierType& identifier_type,
161 const uint8_t* identifier_begin,
162 const size_t identifier_len) const;
163
177 virtual ConstHostPtr
178 get4(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type,
179 const uint8_t* identifier_begin, const size_t identifier_len) const;
180
192 virtual ConstHostPtr
193 get4(const SubnetID& subnet_id, const asiolink::IOAddress& address) const;
194
210 virtual ConstHostPtr
211 get6Any(const SubnetID& subnet_id,
212 const Host::IdentifierType& identifier_type,
213 const uint8_t* identifier_begin,
214 const size_t identifier_len) const;
215
229 virtual ConstHostPtr
230 get6(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type,
231 const uint8_t* identifier_begin, const size_t identifier_len) const;
232
242 virtual ConstHostPtr
243 get6(const asiolink::IOAddress& prefix, const uint8_t prefix_len) const;
244
251 virtual ConstHostPtr
252 get6(const SubnetID& subnet_id, const asiolink::IOAddress& addr) const;
253
260 virtual void add(const HostPtr& host);
261
269 virtual bool del(const SubnetID& subnet_id, const asiolink::IOAddress& addr);
270
281 virtual bool
282 del4(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type,
283 const uint8_t* identifier_begin, const size_t identifier_len);
284
295 virtual bool
296 del6(const SubnetID& subnet_id, const Host::IdentifierType& identifier_type,
297 const uint8_t* identifier_begin, const size_t identifier_len);
298
304 virtual std::string getType() const {
305 return (std::string("host_mgr"));
306 }
307
312 return (alternate_sources_);
313 }
314
320
324 bool getNegativeCaching() const {
325 return (negative_caching_);
326 }
327
330 void setNegativeCaching(bool negative_caching) {
331 negative_caching_ = negative_caching;
332 }
333
334protected:
341
345 virtual void cache(ConstHostPtr host) const;
346
354 virtual void cacheNegative(const SubnetID& ipv4_subnet_id,
355 const SubnetID& ipv6_subnet_id,
356 const Host::IdentifierType& identifier_type,
357 const uint8_t* identifier_begin,
358 const size_t identifier_len) const;
359
360private:
361
363 HostMgr() : negative_caching_(false) { }
364
366 HostDataSourceList alternate_sources_;
367
369 CacheHostDataSourcePtr cache_ptr_;
370
373 static boost::scoped_ptr<HostMgr>& getHostMgrPtr();
374
375};
376}
377}
378
379#endif // HOST_MGR_H
Base interface for the classes implementing simple data source for host reservations.
Host Manager.
Definition: host_mgr.h:54
virtual void add(const HostPtr &host)
Adds a new host to the alternate data source.
Definition: host_mgr.cc:331
static void delAllBackends()
Delete all alternate backends.
Definition: host_mgr.cc:55
static void create()
Creates new instance of the HostMgr.
Definition: host_mgr.cc:40
bool negative_caching_
The negative caching flag.
Definition: host_mgr.h:340
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:408
bool getNegativeCaching() const
Returns the negative caching flag.
Definition: host_mgr.h:324
virtual std::string getType() const
Return backend type.
Definition: host_mgr.h:304
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:99
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:125
virtual void cache(ConstHostPtr host) const
Cache an answer.
Definition: host_mgr.cc:395
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:378
static bool delBackend(const std::string &db_type)
Delete an alternate host backend (aka host data source).
Definition: host_mgr.cc:50
static void addBackend(const std::string &access)
Add an alternate host backend (aka host data source).
Definition: host_mgr.cc:45
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:289
void setNegativeCaching(bool negative_caching)
Sets the negative caching flag.
Definition: host_mgr.h:330
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:175
HostDataSourcePtr getHostDataSource() const
Returns the first host data source.
Definition: host_mgr.cc:60
static bool checkCacheBackend(bool logging=false)
Check for the cache host backend.
Definition: host_mgr.cc:68
virtual bool del(const SubnetID &subnet_id, const asiolink::IOAddress &addr)
Attempts to delete a host by address.
Definition: host_mgr.cc:346
static HostMgr & instance()
Returns a sole instance of the HostMgr.
Definition: host_mgr.cc:90
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:242
HostDataSourceList & getHostDataSourceList()
Returns the host data source list.
Definition: host_mgr.h:311
virtual ConstHostCollection getAll4(const asiolink::IOAddress &address) const
Returns a collection of hosts using the specified IPv4 address.
Definition: host_mgr.cc:115
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:361
IdentifierType
Type of the host identifier.
Definition: host.h:252
boost::shared_ptr< BaseHostDataSource > HostDataSourcePtr
HostDataSource pointer.
boost::shared_ptr< Host > HostPtr
Pointer to the Host object.
Definition: host.h:725
std::vector< ConstHostPtr > ConstHostCollection
Collection of the const Host objects.
Definition: host.h:731
std::vector< HostDataSourcePtr > HostDataSourceList
HostDataSource list.
boost::shared_ptr< CacheHostDataSource > CacheHostDataSourcePtr
CacheHostDataSource pointer.
uint32_t SubnetID
Unique identifier for a subnet (both v4 and v6)
Definition: lease.h:24
boost::shared_ptr< const Host > ConstHostPtr
Const pointer to the Host object.
Definition: host.h:728
Defines the logger used by the top-level component of kea-dhcp-ddns.