Kea: host_cache_impl.h Source File

| Kea 3.2.0-git

host_cache_impl.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_IMPL_H
8#define HOST_CACHE_IMPL_H
9
10#include <exceptions/exceptions.h>
11#include <cc/data.h>
12#include <asiolink/io_address.h>
13#include <dhcpsrv/base_host_data_source.h>
14#include <dhcpsrv/host.h>
15#include <dhcpsrv/subnet_id.h>
16#include <container.h>
17#include <boost/shared_ptr.hpp>
18#include <vector>
19
20namespace isc {
21namespace host_cache {
22
24 class HostCacheImpl {
25public:
26
29 HostCacheImpl();
30
32 virtual ~HostCacheImpl();
33
35 size_t maximum_;
36
38 void setMaximum(size_t maximum) {
39 maximum_ = maximum;
40 }
41
43 size_t getMaximum() const {
44 return (maximum_);
45 }
46
56 dhcp::ConstHostPtr get4(const dhcp::SubnetID& subnet_id,
57 const dhcp::Host::IdentifierType& identifier_type,
58 const uint8_t* identifier_begin,
59 const size_t identifier_len);
60
68 dhcp::ConstHostPtr get4(const dhcp::SubnetID& subnet_id,
69 const asiolink::IOAddress& address);
70
80 dhcp::ConstHostPtr get6(const dhcp::SubnetID& subnet_id,
81 const dhcp::Host::IdentifierType& identifier_type,
82 const uint8_t* identifier_begin,
83 const size_t identifier_len);
84
91 dhcp::ConstHostPtr get6(const asiolink::IOAddress& prefix,
92 const uint8_t prefix_len);
93
101 dhcp::ConstHostPtr get6(const dhcp::SubnetID& subnet_id,
102 const asiolink::IOAddress& address);
103
115 HostContainerSequencedIndex::iterator
116 getHostInternal(const dhcp::SubnetID& subnet_id, const bool subnet6,
117 const dhcp::Host::IdentifierType& identifier_type,
118 const uint8_t* identifier,
119 const size_t identifier_len);
120
128 HostContainerSequencedIndex::iterator
129 getHostInternal4(const dhcp::SubnetID& subnet_id,
130 const asiolink::IOAddress& address);
131
138 // host is found.
139 dhcp::HostPtr
140 getHostInternal6(const asiolink::IOAddress& prefix,
141 const uint8_t prefix_len);
142
151 dhcp::HostPtr
152 getHostInternal6(const dhcp::SubnetID& subnet_id,
153 const asiolink::IOAddress& address);
154
160 bool add(const dhcp::HostPtr& host);
161
167 std::string del4(const dhcp::SubnetID& subnet_id,
168 const asiolink::IOAddress& addr);
169
178 std::string del4(const dhcp::SubnetID& subnet_id,
179 const dhcp::Host::IdentifierType& identifier_type,
180 const uint8_t* identifier_begin,
181 const size_t identifier_len);
182
188 std::string del6(const dhcp::SubnetID& subnet_id,
189 const asiolink::IOAddress& addr);
190
199 std::string del6(const dhcp::SubnetID& subnet_id,
200 const dhcp::Host::IdentifierType& identifier_type,
201 const uint8_t* identifier_begin,
202 const size_t identifier_len);
203
211 dhcp::HostPtr relocate(dhcp::HostPtr host);
212
216 data::ElementPtr toElement() const;
217
227 size_t insert(const dhcp::ConstHostPtr& host, bool overwrite);
228
235 void update(isc::dhcp::ConstHostPtr const& host);
236
241 bool insertResv6(const dhcp::HostPtr& host);
242
252 bool remove(const dhcp::HostPtr& host);
253
257 void removeResv6(const dhcp::HostPtr& host);
258
260 void clear() {
261 cache_.clear();
262 cache6_.clear();
263 }
264
268 void flush(size_t count);
269
273 size_t size() const {
274 return (cache_.size());
275 }
276
280 size_t capacity() const {
281 return (maximum_);
282 }
283
298 virtual dhcp::ConstHostCollection
299 get(const dhcp::Host::IdentifierType& identifier_type,
300 const uint8_t* identifier_begin,
301 const size_t identifier_len) const;
302
303private:
304
312 HostContainer cache_;
313
319 Resv6Container cache6_;
320};
321
322} // end of namespace isc::host_cache
323} // end of namespace isc
324
325#endif
base_host_data_source.h
isc::asiolink::IOAddress
The IOAddress class represents an IP addresses (version agnostic).
Definition io_address.h:53
isc::dhcp::Host::IdentifierType
IdentifierType
Type of the host identifier.
Definition host.h:337
isc::host_cache::HostCacheImpl::flush
void flush(size_t count)
Flush entries.
Definition host_cache_impl.cc:497
isc::host_cache::HostCacheImpl::capacity
size_t capacity() const
Return the maximum number of entries.
Definition host_cache_impl.h:280
isc::host_cache::HostCacheImpl::get6
dhcp::ConstHostPtr get6(const dhcp::SubnetID &subnet_id, const dhcp::Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len)
Returns a host connected to the IPv6 subnet.
Definition host_cache_impl.cc:143
isc::host_cache::HostCacheImpl::removeResv6
void removeResv6(const dhcp::HostPtr &host)
Remove IPv6 reservations.
Definition host_cache_impl.cc:51
isc::host_cache::HostCacheImpl::getHostInternal4
HostContainerSequencedIndex::iterator getHostInternal4(const dhcp::SubnetID &subnet_id, const asiolink::IOAddress &address)
Returns a host connected to the IPv4 subnet and having a reservation for a specified IPv4 address.
Definition host_cache_impl.cc:198
isc::host_cache::HostCacheImpl::getMaximum
size_t getMaximum() const
Get maximum number of elements.
Definition host_cache_impl.h:43
isc::host_cache::HostCacheImpl::relocate
dhcp::HostPtr relocate(dhcp::HostPtr host)
Relocate an entry to the end of sequenced index.
Definition host_cache_impl.cc:100
isc::host_cache::HostCacheImpl::maximum_
size_t maximum_
Maximum number of elements (0 means unbound).
Definition host_cache_impl.h:35
isc::host_cache::HostCacheImpl::get
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...
Definition host_cache_impl.cc:528
isc::host_cache::HostCacheImpl::~HostCacheImpl
virtual ~HostCacheImpl()
Destructor.
Definition host_cache_impl.cc:27
isc::host_cache::HostCacheImpl::update
void update(isc::dhcp::ConstHostPtr const &host)
Implements isc::dhcp::BaseHostDataSource::update() for HostCacheImpl.
Definition host_cache_impl.cc:359
isc::host_cache::HostCacheImpl::clear
void clear()
Flush all entries.
Definition host_cache_impl.h:260
isc::host_cache::HostCacheImpl::getHostInternal6
dhcp::HostPtr getHostInternal6(const asiolink::IOAddress &prefix, const uint8_t prefix_len)
Returns a host using the specified IPv6 prefix.
Definition host_cache_impl.cc:215
isc::host_cache::HostCacheImpl::add
bool add(const dhcp::HostPtr &host)
Adds a new host to the collection.
Definition host_cache_impl.cc:390
isc::host_cache::HostCacheImpl::getHostInternal
HostContainerSequencedIndex::iterator getHostInternal(const dhcp::SubnetID &subnet_id, const bool subnet6, const dhcp::Host::IdentifierType &identifier_type, const uint8_t *identifier, const size_t identifier_len)
Returns Host object connected to a subnet.
Definition host_cache_impl.cc:172
isc::host_cache::HostCacheImpl::HostCacheImpl
HostCacheImpl()
Constructor.
Definition host_cache_impl.cc:24
isc::host_cache::HostCacheImpl::del6
std::string del6(const dhcp::SubnetID &subnet_id, const asiolink::IOAddress &addr)
Attempts to delete a host by (subnet-id6, address).
Definition host_cache_impl.cc:415
isc::host_cache::HostCacheImpl::setMaximum
void setMaximum(size_t maximum)
Set maximum number of elements.
Definition host_cache_impl.h:38
isc::host_cache::HostCacheImpl::del4
std::string del4(const dhcp::SubnetID &subnet_id, const asiolink::IOAddress &addr)
Attempts to delete a host by (subnet-id4, address).
Definition host_cache_impl.cc:395
isc::host_cache::HostCacheImpl::toElement
data::ElementPtr toElement() const
Unparse cache content.
Definition host_cache_impl.cc:513
isc::host_cache::HostCacheImpl::size
size_t size() const
Return the number of entries.
Definition host_cache_impl.h:273
isc::host_cache::HostCacheImpl::get4
dhcp::ConstHostPtr get4(const dhcp::SubnetID &subnet_id, const dhcp::Host::IdentifierType &identifier_type, const uint8_t *identifier_begin, const size_t identifier_len)
Returns a host connected to the IPv4 subnet.
Definition host_cache_impl.cc:116
isc::host_cache::HostCacheImpl::insertResv6
bool insertResv6(const dhcp::HostPtr &host)
Insert IPv6 reservations.
Definition host_cache_impl.cc:31
isc::host_cache::HostCacheImpl::remove
bool remove(const dhcp::HostPtr &host)
Remove a host from the cache.
Definition host_cache_impl.cc:483
isc::host_cache::HostCacheImpl::insert
size_t insert(const dhcp::ConstHostPtr &host, bool overwrite)
Insert a host into the cache.
Definition host_cache_impl.cc:248
container.h
data.h
exceptions.h
host.h
io_address.h
isc::data::ElementPtr
boost::shared_ptr< Element > ElementPtr
Definition data.h:29
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::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::host_cache
Definition container.h:22
isc::host_cache::HostContainer
boost::multi_index_container< dhcp::HostPtr, boost::multi_index::indexed_by< boost::multi_index::sequenced< boost::multi_index::tag< HostSequencedIndexTag > >, boost::multi_index::hashed_unique< boost::multi_index::tag< HostHashedIndexTag >, boost::multi_index::identity< dhcp::HostPtr > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< HostIdentifierIndexTag >, boost::multi_index::composite_key< dhcp::Host, boost::multi_index::const_mem_fun< dhcp::Host, const std::vector< uint8_t > &, &dhcp::Host::getIdentifier >, boost::multi_index::const_mem_fun< dhcp::Host, dhcp::Host::IdentifierType, &dhcp::Host::getIdentifierType > > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< HostAddress4IndexTag >, boost::multi_index::const_mem_fun< dhcp::Host, const asiolink::IOAddress &, &dhcp::Host::getIPv4Reservation > > > > HostContainer
Multi-index container holding host cache entries.
Definition container.h:96
isc::host_cache::Resv6Container
boost::multi_index_container< HostResrv6Tuple, boost::multi_index::indexed_by< boost::multi_index::ordered_non_unique< boost::multi_index::tag< Resv6AddressIndexTag >, boost::multi_index::const_mem_fun< HostResrv6Tuple, const asiolink::IOAddress &, &HostResrv6Tuple::getKey > >, boost::multi_index::ordered_unique< boost::multi_index::tag< Resv6SubnetAddressIndexTag >, boost::multi_index::composite_key< HostResrv6Tuple, boost::multi_index::member< HostResrv6Tuple, const dhcp::SubnetID, &HostResrv6Tuple::subnet_id_ >, boost::multi_index::const_mem_fun< HostResrv6Tuple, const asiolink::IOAddress &, &HostResrv6Tuple::getKey > > > > > Resv6Container
Multi-index container holding IPv6 reservations.
Definition container.h:215
isc
Defines the logger used by the top-level component of kea-lfc.
Definition check_exists_add.cc:18
subnet_id.h