Kea: container.h Source File

| Kea 3.2.0-git

container.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 CONTAINER_H
8#define CONTAINER_H
9
10#include <dhcpsrv/host.h>
11#include <dhcpsrv/subnet_id.h>
12#include <boost/multi_index_container.hpp>
13#include <boost/multi_index/composite_key.hpp>
14#include <boost/multi_index/mem_fun.hpp>
15#include <boost/multi_index/member.hpp>
16#include <boost/multi_index/ordered_index.hpp>
17#include <boost/multi_index/sequenced_index.hpp>
18#include <boost/multi_index/hashed_index.hpp>
19#include <boost/multi_index/identity.hpp>
20
21namespace isc {
22 namespace host_cache {
23
25 struct HostSequencedIndexTag { };
26
28 struct HostHashedIndexTag { };
29
31 struct HostIdentifierIndexTag { };
32
34 struct HostAddress4IndexTag { };
35
45typedef boost::multi_index_container<
46 // This container stores pointers to Host objects.
47 dhcp::HostPtr,
48 // Start specification of indexes here.
49 boost::multi_index::indexed_by<
50 // Sequenced index implements least-recently-used.
51 boost::multi_index::sequenced<
52 boost::multi_index::tag<HostSequencedIndexTag>
53 >,
54 // Hash index for direct retrieval.
55 boost::multi_index::hashed_unique<
56 boost::multi_index::tag<HostHashedIndexTag>,
57 boost::multi_index::identity<dhcp::HostPtr>
58 >,
59 // This index is used to search for the host using one of the
60 // identifiers, i.e. HW address or DUID. The elements of this
61 // index are non-unique because there may be multiple reservations
62 // for the same host belonging to a different subnets.
63 boost::multi_index::ordered_non_unique<
64 boost::multi_index::tag<HostIdentifierIndexTag>,
65 // The index comprises actual identifier (HW address or DUID) in
66 // a binary form and a type of the identifier which indicates
67 // that it is HW address or DUID.
68 boost::multi_index::composite_key<
69 // Composite key uses members of the Host class.
70 dhcp::Host,
71 // Binary identifier is retrieved from the Host class using
72 // a getIdentifier method.
73 boost::multi_index::const_mem_fun<
74 dhcp::Host, const std::vector<uint8_t>&,
75 &dhcp::Host::getIdentifier
76 >,
77 // Identifier type is retrieved from the Host class using
78 // a getIdentifierType method.
79 boost::multi_index::const_mem_fun<
80 dhcp::Host, dhcp::Host::IdentifierType,
81 &dhcp::Host::getIdentifierType
82 >
83 >
84 >,
85
86 // This index is used to search for the host using reserved IPv4
87 // address.
88 boost::multi_index::ordered_non_unique<
89 boost::multi_index::tag<HostAddress4IndexTag>,
90 // Index using values returned by the @c Host::getIPv4Reservation.
91 boost::multi_index::const_mem_fun<dhcp::Host,
92 const asiolink::IOAddress&,
93 &dhcp::Host::getIPv4Reservation>
94 >
95 >
96> HostContainer;
97
101 typedef HostContainer::index<HostSequencedIndexTag>::type HostContainerSequencedIndex;
102
106 typedef HostContainer::index<HostHashedIndexTag>::type HostContainerHashedIndex;
107
112 typedef HostContainer::index<HostIdentifierIndexTag>::type HostContainerIdentifierIndex;
113
115typedef std::pair<HostContainerIdentifierIndex::iterator,
116 HostContainerIdentifierIndex::iterator> HostContainerIdentifierIndexRange;
117
122 typedef HostContainer::index<HostAddress4IndexTag>::type HostContainerAddress4Index;
123
125typedef std::pair<HostContainerAddress4Index::iterator,
126 HostContainerAddress4Index::iterator> HostContainerAddress4IndexRange;
127
134 struct HostResrv6Tuple {
135
140 HostResrv6Tuple(const dhcp::IPv6Resrv& resrv, const dhcp::HostPtr& host)
141 : resrv_(resrv), host_(host),
142 subnet_id_(host ? host->getIPv6SubnetID() : dhcp::SUBNET_ID_UNUSED) {
143 }
144
146 const dhcp::IPv6Resrv resrv_;
147
149 dhcp::HostPtr host_;
150
152 const dhcp::SubnetID subnet_id_;
153
155 const asiolink::IOAddress& getKey() const {
156 return (resrv_.getPrefix());
157 }
158};
159
161 struct Resv6AddressIndexTag { };
162
164 struct Resv6SubnetAddressIndexTag { };
165
171typedef boost::multi_index_container<
172
173 // This containers stores (IPv6Resrv, HostPtr) tuples
174 HostResrv6Tuple,
175
176 // Start specification of indexes here.
177 boost::multi_index::indexed_by<
178
179 // First index is used to search by an address.
180 boost::multi_index::ordered_non_unique<
181 boost::multi_index::tag<Resv6AddressIndexTag>,
182
183 // Address is extracted by calling IPv6Resrv::getPrefix()
184 // and it will return an IOAddress object.
185 boost::multi_index::const_mem_fun<
186 HostResrv6Tuple, const asiolink::IOAddress&, &HostResrv6Tuple::getKey>
187 >,
188
189 // Second index is used to search by (subnet_id, address) pair.
190 boost::multi_index::ordered_unique<
191 boost::multi_index::tag<Resv6SubnetAddressIndexTag>,
192
195 boost::multi_index::composite_key<
196
197 // Composite key uses members of the HostResrv6Tuple class.
198 HostResrv6Tuple,
199
200 // First key extractor. Gets subnet-id as a member of the
201 // HostResrv6Tuple structure.
202 boost::multi_index::member<HostResrv6Tuple,
203 const dhcp::SubnetID,
204 &HostResrv6Tuple::subnet_id_>,
205
206 // Second key extractor. Address is extracted by calling
207 // IPv6Resrv::getPrefix() and it will return an IOAddress object.
208 boost::multi_index::const_mem_fun<
209 HostResrv6Tuple, const asiolink::IOAddress&,
210 &HostResrv6Tuple::getKey
211 >
212 >
213 >
214 >
215> Resv6Container;
216
221typedef Resv6Container::index<Resv6AddressIndexTag>::type
222 Resv6ContainerAddressIndex;
223
225typedef std::pair<Resv6ContainerAddressIndex::iterator,
226 Resv6ContainerAddressIndex::iterator> Resv6ContainerAddressIndexRange;
227
232typedef Resv6Container::index<Resv6SubnetAddressIndexTag>::type
233 Resv6ContainerSubnetAddressIndex;
234
236typedef std::pair<Resv6ContainerSubnetAddressIndex::iterator,
237 Resv6ContainerSubnetAddressIndex::iterator> Resv6ContainerSubnetAddressIndexRange;
238
239}; // end of isc::dhcp namespace
240}; // end of isc namespace
241
242#endif // CONTAINER_H
isc::asiolink::IOAddress
The IOAddress class represents an IP addresses (version agnostic).
Definition io_address.h:53
isc::dhcp::Host
Represents a device with IPv4 and/or IPv6 reservations.
Definition host.h:327
isc::dhcp::Host::getIdentifierType
IdentifierType getIdentifierType() const
Returns the identifier type.
Definition host.cc:280
isc::dhcp::Host::getIPv4Reservation
const asiolink::IOAddress & getIPv4Reservation() const
Returns reserved IPv4 address.
Definition host.h:562
isc::dhcp::Host::getIdentifier
const std::vector< uint8_t > & getIdentifier() const
Returns the identifier in a binary form.
Definition host.cc:275
isc::dhcp::Host::IdentifierType
IdentifierType
Type of the host identifier.
Definition host.h:337
isc::dhcp::IPv6Resrv
IPv6 reservation for a host.
Definition host.h:163
host.h
isc::dhcp
Definition dhcp4/client_handler.cc:20
isc::dhcp::HostPtr
boost::shared_ptr< Host > HostPtr
Pointer to the Host object.
Definition host.h:837
isc::dhcp::SubnetID
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
Definition subnet_id.h:25
isc::host_cache
Definition container.h:22
isc::host_cache::HostContainerAddress4Index
HostContainer::index< HostAddress4IndexTag >::type HostContainerAddress4Index
Reserved Ipv4 address index type in the HostContainer.
Definition container.h:122
isc::host_cache::Resv6ContainerSubnetAddressIndexRange
std::pair< Resv6ContainerSubnetAddressIndex::iterator, Resv6ContainerSubnetAddressIndex::iterator > Resv6ContainerSubnetAddressIndexRange
Results range returned using the Resv6ContainerSubnetAddressIndex.
Definition container.h:237
isc::host_cache::HostContainerIdentifierIndex
HostContainer::index< HostIdentifierIndexTag >::type HostContainerIdentifierIndex
Identifier index type in the HostContainer.
Definition container.h:112
isc::host_cache::HostContainerAddress4IndexRange
std::pair< HostContainerAddress4Index::iterator, HostContainerAddress4Index::iterator > HostContainerAddress4IndexRange
Results range returned using the HostContainerAddress4Index.
Definition container.h:126
isc::host_cache::HostContainerHashedIndex
HostContainer::index< HostHashedIndexTag >::type HostContainerHashedIndex
Hashed index type in the HostContainer.
Definition container.h:106
isc::host_cache::HostContainerIdentifierIndexRange
std::pair< HostContainerIdentifierIndex::iterator, HostContainerIdentifierIndex::iterator > HostContainerIdentifierIndexRange
Results range returned using the HostContainerIdentifierIndex.
Definition container.h:116
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::Resv6ContainerAddressIndexRange
std::pair< Resv6ContainerAddressIndex::iterator, Resv6ContainerAddressIndex::iterator > Resv6ContainerAddressIndexRange
Results range returned using the Resv6ContainerAddressIndex.
Definition container.h:226
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::host_cache::Resv6ContainerAddressIndex
Resv6Container::index< Resv6AddressIndexTag >::type Resv6ContainerAddressIndex
First index type in the Resv6Container.
Definition container.h:222
isc::host_cache::HostContainerSequencedIndex
HostContainer::index< HostSequencedIndexTag >::type HostContainerSequencedIndex
Sequenced index type in the HostContainer.
Definition container.h:101
isc::host_cache::Resv6ContainerSubnetAddressIndex
Resv6Container::index< Resv6SubnetAddressIndexTag >::type Resv6ContainerSubnetAddressIndex
Second index type in the Resv6Container.
Definition container.h:233
isc
Defines the logger used by the top-level component of kea-lfc.
Definition check_exists_add.cc:18
isc::host_cache::HostAddress4IndexTag
Tag for the index for searching by reserved IPv4 address.
Definition container.h:34
isc::host_cache::HostHashedIndexTag
Tag for the hashed index.
Definition container.h:28
isc::host_cache::HostIdentifierIndexTag
Tag for the index for searching by identifier.
Definition container.h:31
isc::host_cache::HostResrv6Tuple
Defines one entry for the Host Container for v6 hosts.
Definition container.h:134
isc::host_cache::HostResrv6Tuple::resrv_
const dhcp::IPv6Resrv resrv_
Address or prefix reservation.
Definition container.h:146
isc::host_cache::HostResrv6Tuple::host_
dhcp::HostPtr host_
Pointer to the host object.
Definition container.h:149
isc::host_cache::HostResrv6Tuple::HostResrv6Tuple
HostResrv6Tuple(const dhcp::IPv6Resrv &resrv, const dhcp::HostPtr &host)
Default constructor.
Definition container.h:140
isc::host_cache::HostResrv6Tuple::subnet_id_
const dhcp::SubnetID subnet_id_
Value of the IPv6 Subnet-id.
Definition container.h:152
isc::host_cache::HostResrv6Tuple::getKey
const asiolink::IOAddress & getKey() const
Key extractor (used in the second composite key).
Definition container.h:155
isc::host_cache::HostSequencedIndexTag
Tag for the sequenced index.
Definition container.h:25
isc::host_cache::Resv6AddressIndexTag
Tag for the index for searching by address.
Definition container.h:161
isc::host_cache::Resv6SubnetAddressIndexTag
Tag for the index for searching by subnet and address.
Definition container.h:164
subnet_id.h