Kea 3.1.1
host_cache.h
Go to the documentation of this file.
1// Copyright (C) 2018-2025 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_CACHE_H
8#define HOST_CACHE_H
9
10#include <config.h>
12#include <cc/data.h>
13#include <asiolink/io_address.h>
15#include <dhcpsrv/host.h>
16#include <dhcpsrv/subnet_id.h>
17#include <config/cmds_impl.h>
18#include <boost/scoped_ptr.hpp>
19#include <boost/shared_ptr.hpp>
20#include <mutex>
21#include <vector>
22
23namespace isc {
24namespace host_cache {
25
26class HostCacheImpl;
27
35 private isc::config::CmdsImpl {
36public:
37
40 HostCache();
41
43 virtual ~HostCache();
44
49 virtual void configure(const data::ConstElementPtr& config);
50
52 virtual void setMaximum(size_t maximum);
53
55 virtual size_t getMaximum() const;
56
60
66
81 getAll(const dhcp::Host::IdentifierType& identifier_type,
82 const uint8_t* identifier_begin,
83 const size_t identifier_len) const;
84
94 getAll4(const dhcp::SubnetID& subnet_id) const;
95
105 getAll6(const dhcp::SubnetID& subnet_id) const;
106
116 getAllbyHostname(const std::string& hostname) const;
117
128 getAllbyHostname4(const std::string& hostname,
129 const dhcp::SubnetID& subnet_id) const;
130
141 getAllbyHostname6(const std::string& hostname,
142 const dhcp::SubnetID& subnet_id) const;
143
157 getPage4(const dhcp::SubnetID& subnet_id,
158 size_t& source_index,
159 uint64_t lower_host_id,
160 const dhcp::HostPageSize& page_size) const;
161
175 getPage6(const dhcp::SubnetID& subnet_id,
176 size_t& source_index,
177 uint64_t lower_host_id,
178 const dhcp::HostPageSize& page_size) const;
179
192 getPage4(size_t& source_index,
193 uint64_t lower_host_id,
194 const dhcp::HostPageSize& page_size) const;
195
208 getPage6(size_t& source_index,
209 uint64_t lower_host_id,
210 const dhcp::HostPageSize& page_size) const;
211
222 getAll4(const asiolink::IOAddress& address) const;
223
234 virtual dhcp::ConstHostPtr
235 get4(const dhcp::SubnetID& subnet_id,
236 const dhcp::Host::IdentifierType& identifier_type,
237 const uint8_t* identifier_begin,
238 const size_t identifier_len) const;
239
256 virtual dhcp::ConstHostPtr
257 get4(const dhcp::SubnetID& subnet_id,
258 const asiolink::IOAddress& address) const;
259
268 getAll4(const dhcp::SubnetID& subnet_id,
269 const asiolink::IOAddress& address) const;
270
281 virtual dhcp::ConstHostPtr
282 get6(const dhcp::SubnetID& subnet_id,
283 const dhcp::Host::IdentifierType& identifier_type,
284 const uint8_t* identifier_begin,
285 const size_t identifier_len) const;
286
293 virtual dhcp::ConstHostPtr
294 get6(const asiolink::IOAddress& prefix, const uint8_t prefix_len) const;
295
303 virtual dhcp::ConstHostPtr
304 get6(const dhcp::SubnetID& subnet_id,
305 const asiolink::IOAddress& address) const;
306
315 getAll6(const dhcp::SubnetID& subnet_id,
316 const asiolink::IOAddress& address) const;
317
327 getAll6(const asiolink::IOAddress& address) const;
328
339 virtual void add(const dhcp::HostPtr& host);
340
348 virtual bool del(const dhcp::SubnetID& subnet_id,
349 const asiolink::IOAddress& addr);
350
361 virtual bool del4(const dhcp::SubnetID& subnet_id,
362 const dhcp::Host::IdentifierType& identifier_type,
363 const uint8_t* identifier_begin,
364 const size_t identifier_len);
365
376 virtual bool del6(const dhcp::SubnetID& subnet_id,
377 const dhcp::Host::IdentifierType& identifier_type,
378 const uint8_t* identifier_begin,
379 const size_t identifier_len);
380
387 void update(isc::dhcp::HostPtr const& host);
388
394 virtual std::string getType() const {
395 return ("cache");
396 }
397
414 virtual bool setIPReservationsUnique(const bool unique);
415
419 virtual data::ElementPtr toElement() const;
420
430 virtual size_t insert(const dhcp::ConstHostPtr& host, bool overwrite);
431
441 virtual bool remove(const dhcp::HostPtr& host);
442
446 virtual void flush(size_t count);
447
451 virtual size_t size() const;
452
456 virtual size_t capacity() const;
457
473 get(const dhcp::Host::IdentifierType& identifier_type,
474 const uint8_t* identifier_begin,
475 const size_t identifier_len) const;
476
480
498
514
538
566
593
612
631
645
670
671protected:
672
674 boost::shared_ptr<HostCacheImpl> impl_;
675
677 boost::scoped_ptr<std::mutex> mutex_;
678};
679
681typedef boost::shared_ptr<HostCache> HostCachePtr;
682
690
691} // end of namespace isc::host_cache
692} // end of namespace isc
693
694#endif
Base class that command handler implementers may use for common tasks.
Definition cmds_impl.h:21
Abstract interface extending base simple data source for host reservations to host cache.
Wraps value holding size of the page with host reservations.
IdentifierType
Type of the host identifier.
Definition host.h:337
Per-packet callout handle.
Host Cache hooks library implementation.
virtual size_t size() const
Return the number of entries.
virtual void configure(const data::ConstElementPtr &config)
Parses configuration.
Definition host_cache.cc:42
virtual bool setIPReservationsUnique(const bool unique)
Controls whether IP reservations are unique or non-unique.
boost::shared_ptr< HostCacheImpl > impl_
Implementation.
Definition host_cache.h:674
virtual size_t getMaximum() const
Get maximum number of cached hosts.
Definition host_cache.cc:52
virtual void flush(size_t count)
Flush entries.
int cacheLoadHandler(hooks::CalloutHandle &handle)
cache-load command handler.
virtual dhcp::ConstHostCollection getAll(const dhcp::Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len) const
BaseHostDataSource methods.
Definition host_cache.cc:58
virtual bool del6(const dhcp::SubnetID &subnet_id, const dhcp::Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len)
Attempts to delete a host by (subnet-id6, identifier, identifier-type)
virtual bool del4(const dhcp::SubnetID &subnet_id, const dhcp::Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len)
Attempts to delete a host by (subnet-id4, identifier, identifier-type)
virtual dhcp::ConstHostCollection getAllbyHostname4(const std::string &hostname, const dhcp::SubnetID &subnet_id) const
Return all hosts with a hostname in a DHCPv4 subnet.
Definition host_cache.cc:80
virtual ~HostCache()
Destructor.
Definition host_cache.cc:38
void update(isc::dhcp::HostPtr const &host)
Implements isc::dhcp::BaseHostDataSource::update() for HostCache.
virtual dhcp::ConstHostPtr get6(const dhcp::SubnetID &subnet_id, const dhcp::Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len) const
Returns a host connected to the IPv6 subnet.
int cacheRemoveHandler(hooks::CalloutHandle &handle)
cache-remove command handler.
virtual size_t capacity() const
Return the maximum number of entries.
virtual void setMaximum(size_t maximum)
Set maximum number of cached hosts (0 means unbound).
Definition host_cache.cc:47
virtual void add(const dhcp::HostPtr &host)
Adds a new host to the collection.
int cacheInsertHandler(hooks::CalloutHandle &handle)
cache-insert command handler.
boost::scoped_ptr< std::mutex > mutex_
mutex
Definition host_cache.h:677
virtual bool del(const dhcp::SubnetID &subnet_id, const asiolink::IOAddress &addr)
Attempts to delete a host by (subnet-id, address)
virtual size_t insert(const dhcp::ConstHostPtr &host, bool overwrite)
Insert a host into the cache.
int cacheGetByIdHandler(hooks::CalloutHandle &handle)
cache-get-by-id command handler.
int cacheWriteHandler(hooks::CalloutHandle &handle)
cache-write command handler.
virtual dhcp::ConstHostCollection getPage4(const dhcp::SubnetID &subnet_id, size_t &source_index, uint64_t lower_host_id, const dhcp::HostPageSize &page_size) const
Return range of hosts in a DHCPv4 subnet.
Definition host_cache.cc:92
virtual dhcp::ConstHostCollection getAll6(const dhcp::SubnetID &subnet_id) const
Return all hosts in a DHCPv6 subnet.
Definition host_cache.cc:70
virtual dhcp::ConstHostCollection getAll4(const dhcp::SubnetID &subnet_id) const
Return all hosts in a DHCPv4 subnet.
Definition host_cache.cc:65
int cacheFlushHandler(hooks::CalloutHandle &handle)
cache-flush command handler.
virtual dhcp::ConstHostCollection getAllbyHostname6(const std::string &hostname, const dhcp::SubnetID &subnet_id) const
Return all hosts with a hostname in a DHCPv6 subnet.
Definition host_cache.cc:86
virtual dhcp::ConstHostCollection getAllbyHostname(const std::string &hostname) const
Return all hosts with a hostname.
Definition host_cache.cc:75
virtual std::string getType() const
Return backend type.
Definition host_cache.h:394
virtual dhcp::ConstHostCollection get(const dhcp::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...
int cacheSizeHandler(hooks::CalloutHandle &handle)
Command handlers.
virtual bool remove(const dhcp::HostPtr &host)
Remove a host from the cache.
virtual data::ElementPtr toElement() const
Returns the whole content of the cache as Element tree.
virtual dhcp::ConstHostCollection getPage6(const dhcp::SubnetID &subnet_id, size_t &source_index, uint64_t lower_host_id, const dhcp::HostPageSize &page_size) const
Return range of hosts in a DHCPv6 subnet.
virtual dhcp::ConstHostPtr get4(const dhcp::SubnetID &subnet_id, const dhcp::Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len) const
Returns a host connected to the IPv4 subnet.
int cacheGetHandler(hooks::CalloutHandle &handle)
cache-get command handler.
int cacheClearHandler(hooks::CalloutHandle &handle)
cache-clear command handler.
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:29
boost::shared_ptr< Element > ElementPtr
Definition data.h:28
boost::shared_ptr< Host > HostPtr
Pointer to the Host object.
Definition host.h:837
std::vector< ConstHostPtr > ConstHostCollection
Collection of the const Host objects.
Definition host.h:843
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
Definition subnet_id.h:25
boost::shared_ptr< const Host > ConstHostPtr
Const pointer to the Host object.
Definition host.h:840
boost::shared_ptr< HostCache > HostCachePtr
Pointer to the Host Cache hooks library implementation.
Definition host_cache.h:681
ElementPtr toElement(const ConstHostPtr &host)
Unparse a host cache entry.
Definition entry.cc:25
Defines the logger used by the top-level component of kea-lfc.