Kea 3.1.1
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
11#include <cc/data.h>
12#include <asiolink/io_address.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
25public:
26
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
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.
141 const uint8_t prefix_len);
142
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
212
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
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
IdentifierType
Type of the host identifier.
Definition host.h:337
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: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::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.