Kea 3.3.3
host_cache_impl.h
Go to the documentation of this file.
1// Copyright (C) 2018-2026 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 <asiolink/io_address.h>
11#include <cc/data.h>
13#include <dhcpsrv/host.h>
14#include <dhcpsrv/subnet_id.h>
17
18#include <vector>
19
20#include <boost/shared_ptr.hpp>
21
22namespace isc {
23namespace host_cache {
24
27public:
28
32
34 virtual ~HostCacheImpl();
35
37 size_t maximum_;
38
40 void setMaximum(size_t maximum) {
41 maximum_ = maximum;
42 }
43
45 size_t getMaximum() const {
46 return (maximum_);
47 }
48
58 dhcp::ConstHostPtr get4(const dhcp::SubnetID& subnet_id,
59 const dhcp::Host::IdentifierType& identifier_type,
60 const uint8_t* identifier_begin,
61 const size_t identifier_len);
62
70 dhcp::ConstHostPtr get4(const dhcp::SubnetID& subnet_id,
71 const asiolink::IOAddress& address);
72
82 dhcp::ConstHostPtr get6(const dhcp::SubnetID& subnet_id,
83 const dhcp::Host::IdentifierType& identifier_type,
84 const uint8_t* identifier_begin,
85 const size_t identifier_len);
86
94 const uint8_t prefix_len);
95
103 dhcp::ConstHostPtr get6(const dhcp::SubnetID& subnet_id,
104 const asiolink::IOAddress& address);
105
117 HostContainerSequencedIndex::iterator
118 getHostInternal(const dhcp::SubnetID& subnet_id, const bool subnet6,
119 const dhcp::Host::IdentifierType& identifier_type,
120 const uint8_t* identifier,
121 const size_t identifier_len);
122
130 HostContainerSequencedIndex::iterator
131 getHostInternal4(const dhcp::SubnetID& subnet_id,
132 const asiolink::IOAddress& address);
133
140 // host is found.
143 const uint8_t prefix_len);
144
154 getHostInternal6(const dhcp::SubnetID& subnet_id,
155 const asiolink::IOAddress& address);
156
162 bool add(const dhcp::HostPtr& host);
163
169 std::string del4(const dhcp::SubnetID& subnet_id,
170 const asiolink::IOAddress& addr);
171
180 std::string del4(const dhcp::SubnetID& subnet_id,
181 const dhcp::Host::IdentifierType& identifier_type,
182 const uint8_t* identifier_begin,
183 const size_t identifier_len);
184
190 std::string del6(const dhcp::SubnetID& subnet_id,
191 const asiolink::IOAddress& addr);
192
201 std::string del6(const dhcp::SubnetID& subnet_id,
202 const dhcp::Host::IdentifierType& identifier_type,
203 const uint8_t* identifier_begin,
204 const size_t identifier_len);
205
214
219
229 size_t insert(const dhcp::ConstHostPtr& host, bool overwrite);
230
237 void update(isc::dhcp::ConstHostPtr const& host);
238
243 bool insertResv6(const dhcp::HostPtr& host);
244
254 bool remove(const dhcp::HostPtr& host);
255
259 void removeResv6(const dhcp::HostPtr& host);
260
262 void clear() {
263 cache_.clear();
264 cache6_.clear();
265 }
266
270 void flush(size_t count);
271
275 size_t size() const {
276 return (cache_.size());
277 }
278
282 size_t capacity() const {
283 return (maximum_);
284 }
285
301 get(const dhcp::Host::IdentifierType& identifier_type,
302 const uint8_t* identifier_begin,
303 const size_t identifier_len) const;
304
305private:
306
314 HostContainer cache_;
315
321 Resv6Container cache6_;
322};
323
324} // end of namespace isc::host_cache
325} // end of namespace isc
326
327#endif
IdentifierType
Type of the host identifier.
Definition host.h:340
void flush(size_t count)
Flush entries.
size_t capacity() const
Return the maximum number of entries.
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.
void removeResv6(const dhcp::HostPtr &host)
Remove IPv6 reservations.
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.
size_t getMaximum() const
Get maximum number of elements.
dhcp::HostPtr relocate(dhcp::HostPtr host)
Relocate an entry to the end of sequenced index.
size_t maximum_
Maximum number of elements (0 means unbound).
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...
virtual ~HostCacheImpl()
Destructor.
void update(isc::dhcp::ConstHostPtr const &host)
Implements isc::dhcp::BaseHostDataSource::update() for HostCacheImpl.
void clear()
Flush all entries.
dhcp::HostPtr getHostInternal6(const asiolink::IOAddress &prefix, const uint8_t prefix_len)
Returns a host using the specified IPv6 prefix.
bool add(const dhcp::HostPtr &host)
Adds a new host to the collection.
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.
std::string del6(const dhcp::SubnetID &subnet_id, const asiolink::IOAddress &addr)
Attempts to delete a host by (subnet-id6, address).
void setMaximum(size_t maximum)
Set maximum number of elements.
std::string del4(const dhcp::SubnetID &subnet_id, const asiolink::IOAddress &addr)
Attempts to delete a host by (subnet-id4, address).
data::ElementPtr toElement() const
Unparse cache content.
size_t size() const
Return the number of entries.
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.
bool insertResv6(const dhcp::HostPtr &host)
Insert IPv6 reservations.
bool remove(const dhcp::HostPtr &host)
Remove a host from the cache.
size_t insert(const dhcp::ConstHostPtr &host, bool overwrite)
Insert a host into the cache.
boost::shared_ptr< Element > ElementPtr
Definition data.h:29
boost::shared_ptr< Host > HostPtr
Pointer to the Host object.
Definition host.h:840
std::vector< ConstHostPtr > ConstHostCollection
Collection of the const Host objects.
Definition host.h:846
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:843
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
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
Defines the logger used by the top-level component of kea-lfc.