Kea 2.2.0
memfile_lease_storage.h
Go to the documentation of this file.
1// Copyright (C) 2015-2022 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 MEMFILE_LEASE_STORAGE_H
8#define MEMFILE_LEASE_STORAGE_H
9
10#include <asiolink/io_address.h>
11#include <dhcpsrv/lease.h>
12#include <dhcpsrv/subnet_id.h>
13
14#include <boost/multi_index/indexed_by.hpp>
15#include <boost/multi_index/member.hpp>
16#include <boost/multi_index/mem_fun.hpp>
17#include <boost/multi_index/ordered_index.hpp>
18#include <boost/multi_index_container.hpp>
19#include <boost/multi_index/composite_key.hpp>
20
21#include <vector>
22
23namespace isc {
24namespace dhcp {
25
27struct AddressIndexTag { };
28
31
34
37
40
43
45struct DuidIndexTag { };
46
49
52
53
65typedef boost::multi_index_container<
66 // It holds pointers to Lease6 objects.
68 boost::multi_index::indexed_by<
69 // Specification of the first index starts here.
70 // This index sorts leases by IPv6 addresses represented as
71 // IOAddress objects.
72 boost::multi_index::ordered_unique<
73 boost::multi_index::tag<AddressIndexTag>,
74 boost::multi_index::member<Lease, isc::asiolink::IOAddress, &Lease::addr_>
75 >,
76
77 // Specification of the second index starts here.
78 boost::multi_index::ordered_non_unique<
79 boost::multi_index::tag<DuidIaidTypeIndexTag>,
80 // This is a composite index that will be used to search for
81 // the lease using three attributes: DUID, IAID and lease type.
82 boost::multi_index::composite_key<
83 Lease6,
84 // The DUID can be retrieved from the Lease6 object using
85 // a getDuidVector const function.
86 boost::multi_index::const_mem_fun<Lease6, const std::vector<uint8_t>&,
88 // The two other ingredients of this index are IAID and
89 // lease type.
90 boost::multi_index::member<Lease6, uint32_t, &Lease6::iaid_>,
91 boost::multi_index::member<Lease6, Lease::Type, &Lease6::type_>
92 >
93 >,
94
95 // Specification of the third index starts here.
96 boost::multi_index::ordered_non_unique<
97 boost::multi_index::tag<ExpirationIndexTag>,
98 // This is a composite index that is used to search for
99 // the expired leases. Depending on the value of the first component
100 // of the search key, the reclaimed or not reclaimed leases can
101 // be searched.
102 boost::multi_index::composite_key<
103 Lease6,
104 // The boolean value specifying if lease is reclaimed or not.
105 boost::multi_index::const_mem_fun<Lease, bool,
107 // Lease expiration time.
108 boost::multi_index::const_mem_fun<Lease, int64_t,
110 >
111 >,
112
113 // Specification of the fourth index starts here.
114 // This index sorts leases by SubnetID.
115 boost::multi_index::ordered_non_unique<
116 boost::multi_index::tag<SubnetIdIndexTag>,
117 boost::multi_index::member<Lease, isc::dhcp::SubnetID,
119 >,
120
121 // Specification of the fifth index starts here
122 // This index is used to retrieve leases for matching duid.
123 boost::multi_index::ordered_non_unique<
124 boost::multi_index::tag<DuidIndexTag>,
125 boost::multi_index::const_mem_fun<Lease6,
126 const std::vector<uint8_t>&,
128 >,
129
130 // Specification of the sixth index starts here
131 // This index is used to retrieve leases for matching hostname.
132 boost::multi_index::ordered_non_unique<
133 boost::multi_index::tag<HostnameIndexTag>,
134 boost::multi_index::member<Lease, std::string, &Lease::hostname_>
135 >
136 >
137> Lease6Storage; // Specify the type name of this container.
138
151typedef boost::multi_index_container<
152 // It holds pointers to Lease4 objects.
153 Lease4Ptr,
154 // Specification of search indexes starts here.
155 boost::multi_index::indexed_by<
156 // Specification of the first index starts here.
157 // This index sorts leases by IPv4 addresses represented as
158 // IOAddress objects.
159 boost::multi_index::ordered_unique<
160 boost::multi_index::tag<AddressIndexTag>,
161 // The IPv4 address are held in addr_ members that belong to
162 // Lease class.
163 boost::multi_index::member<Lease, isc::asiolink::IOAddress, &Lease::addr_>
164 >,
165
166 // Specification of the second index starts here.
167 boost::multi_index::ordered_non_unique<
168 boost::multi_index::tag<HWAddressSubnetIdIndexTag>,
169 // This is a composite index that combines two attributes of the
170 // Lease4 object: hardware address and subnet id.
171 boost::multi_index::composite_key<
172 Lease4,
173 // The hardware address is held in the hwaddr_ member of the
174 // Lease4 object, which is a HWAddr object. Boost does not
175 // provide a key extractor for getting a member of a member,
176 // so we need a simple method for that.
177 boost::multi_index::const_mem_fun<Lease, const std::vector<uint8_t>&,
179 // The subnet id is held in the subnet_id_ member of Lease4
180 // class. Note that the subnet_id_ is defined in the base
181 // class (Lease) so we have to point to this class rather
182 // than derived class: Lease4.
183 boost::multi_index::member<Lease, SubnetID, &Lease::subnet_id_>
184 >
185 >,
186
187 // Specification of the third index starts here.
188 boost::multi_index::ordered_non_unique<
189 boost::multi_index::tag<ClientIdSubnetIdIndexTag>,
190 // This is a composite index that uses two values to search for a
191 // lease: client id and subnet id.
192 boost::multi_index::composite_key<
193 Lease4,
194 // The client id can be retrieved from the Lease4 object by
195 // calling getClientIdVector const function.
196 boost::multi_index::const_mem_fun<Lease4, const std::vector<uint8_t>&,
198 // The subnet id is accessed through the subnet_id_ member.
199 boost::multi_index::member<Lease, uint32_t, &Lease::subnet_id_>
200 >
201 >,
202
203 // Specification of the fourth index starts here.
204 boost::multi_index::ordered_non_unique<
205 boost::multi_index::tag<ExpirationIndexTag>,
206 // This is a composite index that will be used to search for
207 // the expired leases. Depending on the value of the first component
208 // of the search key, the reclaimed or not reclaimed leases will can
209 // be searched.
210 boost::multi_index::composite_key<
211 Lease4,
212 // The boolean value specifying if lease is reclaimed or not.
213 boost::multi_index::const_mem_fun<Lease, bool,
215 // Lease expiration time.
216 boost::multi_index::const_mem_fun<Lease, int64_t,
218 >
219 >,
220
221 // Specification of the fifth index starts here.
222 // This index sorts leases by SubnetID.
223 boost::multi_index::ordered_non_unique<
224 boost::multi_index::tag<SubnetIdIndexTag>,
225 boost::multi_index::member<Lease, isc::dhcp::SubnetID, &Lease::subnet_id_>
226 >,
227
228 // Specification of the seventh index starts here
229 // This index is used to retrieve leases for matching hostname.
230 boost::multi_index::ordered_non_unique<
231 boost::multi_index::tag<HostnameIndexTag>,
232 boost::multi_index::member<Lease, std::string, &Lease::hostname_>
233 >
234 >
235> Lease4Storage; // Specify the type name for this container.
236
238
241
242
244typedef Lease6Storage::index<AddressIndexTag>::type Lease6StorageAddressIndex;
245
247typedef Lease6Storage::index<DuidIaidTypeIndexTag>::type Lease6StorageDuidIaidTypeIndex;
248
250typedef Lease6Storage::index<ExpirationIndexTag>::type Lease6StorageExpirationIndex;
251
253typedef Lease6Storage::index<SubnetIdIndexTag>::type Lease6StorageSubnetIdIndex;
254
256typedef Lease6Storage::index<DuidIndexTag>::type Lease6StorageDuidIndex;
257
259typedef Lease6Storage::index<HostnameIndexTag>::type Lease6StorageHostnameIndex;
260
262typedef Lease4Storage::index<AddressIndexTag>::type Lease4StorageAddressIndex;
263
265typedef Lease4Storage::index<ExpirationIndexTag>::type Lease4StorageExpirationIndex;
266
268typedef Lease4Storage::index<HWAddressSubnetIdIndexTag>::type
270
272typedef Lease4Storage::index<ClientIdSubnetIdIndexTag>::type
274
276typedef Lease4Storage::index<SubnetIdIndexTag>::type Lease4StorageSubnetIdIndex;
277
279typedef Lease4Storage::index<HostnameIndexTag>::type Lease4StorageHostnameIndex;
280
282} // end of isc::dhcp namespace
283} // end of isc namespace
284
285#endif // MEMFILE_LEASE_STORAGE_H
boost::multi_index_container< Lease4Ptr, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< boost::multi_index::tag< AddressIndexTag >, boost::multi_index::member< Lease, isc::asiolink::IOAddress, &Lease::addr_ > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< HWAddressSubnetIdIndexTag >, boost::multi_index::composite_key< Lease4, boost::multi_index::const_mem_fun< Lease, const std::vector< uint8_t > &, &Lease::getHWAddrVector >, boost::multi_index::member< Lease, SubnetID, &Lease::subnet_id_ > > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< ClientIdSubnetIdIndexTag >, boost::multi_index::composite_key< Lease4, boost::multi_index::const_mem_fun< Lease4, const std::vector< uint8_t > &, &Lease4::getClientIdVector >, boost::multi_index::member< Lease, uint32_t, &Lease::subnet_id_ > > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< ExpirationIndexTag >, boost::multi_index::composite_key< Lease4, boost::multi_index::const_mem_fun< Lease, bool, &Lease::stateExpiredReclaimed >, boost::multi_index::const_mem_fun< Lease, int64_t, &Lease::getExpirationTime > > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< SubnetIdIndexTag >, boost::multi_index::member< Lease, isc::dhcp::SubnetID, &Lease::subnet_id_ > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< HostnameIndexTag >, boost::multi_index::member< Lease, std::string, &Lease::hostname_ > > > > Lease4Storage
A multi index container holding DHCPv4 leases.
Lease6Storage::index< ExpirationIndexTag >::type Lease6StorageExpirationIndex
DHCPv6 lease storage index by expiration time.
Lease6Storage::index< DuidIndexTag >::type Lease6StorageDuidIndex
DHCPv6 lease storage index by DUID.
boost::shared_ptr< Lease6 > Lease6Ptr
Pointer to a Lease6 structure.
Definition: lease.h:503
Lease6Storage::index< DuidIaidTypeIndexTag >::type Lease6StorageDuidIaidTypeIndex
DHCPv6 lease storage index by DUID, IAID, lease type.
Lease4Storage::index< ExpirationIndexTag >::type Lease4StorageExpirationIndex
DHCPv4 lease storage index by expiration time.
Lease6Storage::index< AddressIndexTag >::type Lease6StorageAddressIndex
DHCPv6 lease storage index by address.
Lease4Storage::index< HostnameIndexTag >::type Lease4StorageHostnameIndex
DHCPv4 lease storage index by hostname.
Lease6Storage::index< HostnameIndexTag >::type Lease6StorageHostnameIndex
DHCPv6 lease storage index by hostname.
Lease4Storage::index< ClientIdSubnetIdIndexTag >::type Lease4StorageClientIdSubnetIdIndex
DHCPv4 lease storage index by client and subnet identifier.
Lease4Storage::index< HWAddressSubnetIdIndexTag >::type Lease4StorageHWAddressSubnetIdIndex
DHCPv4 lease storage index by HW address and subnet identifier.
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
Definition: subnet_id.h:24
boost::multi_index_container< Lease6Ptr, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< boost::multi_index::tag< AddressIndexTag >, boost::multi_index::member< Lease, isc::asiolink::IOAddress, &Lease::addr_ > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< DuidIaidTypeIndexTag >, boost::multi_index::composite_key< Lease6, boost::multi_index::const_mem_fun< Lease6, const std::vector< uint8_t > &, &Lease6::getDuidVector >, boost::multi_index::member< Lease6, uint32_t, &Lease6::iaid_ >, boost::multi_index::member< Lease6, Lease::Type, &Lease6::type_ > > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< ExpirationIndexTag >, boost::multi_index::composite_key< Lease6, boost::multi_index::const_mem_fun< Lease, bool, &Lease::stateExpiredReclaimed >, boost::multi_index::const_mem_fun< Lease, int64_t, &Lease::getExpirationTime > > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< SubnetIdIndexTag >, boost::multi_index::member< Lease, isc::dhcp::SubnetID, &Lease::subnet_id_ > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< DuidIndexTag >, boost::multi_index::const_mem_fun< Lease6, const std::vector< uint8_t > &, &Lease6::getDuidVector > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< HostnameIndexTag >, boost::multi_index::member< Lease, std::string, &Lease::hostname_ > > > > Lease6Storage
A multi index container holding DHCPv6 leases.
Lease4Storage::index< SubnetIdIndexTag >::type Lease4StorageSubnetIdIndex
DHCPv4 lease storage index subnet identifier.
Lease4Storage::index< AddressIndexTag >::type Lease4StorageAddressIndex
DHCPv4 lease storage index by address.
boost::shared_ptr< Lease4 > Lease4Ptr
Pointer to a Lease4 structure.
Definition: lease.h:284
Lease6Storage::index< SubnetIdIndexTag >::type Lease6StorageSubnetIdIndex
DHCPv6 lease storage index by Subnet-id.
Defines the logger used by the top-level component of kea-lfc.
Tag for indexes by address.
Tag for indexes by client and subnet identifiers.
Tag for indexes by DUID, IAID, lease type tuple.
Tag for index using DUID.
Tag for indexes by expiration time.
Tag for indexes by HW address, subnet identifier tuple.
Tag for index using hostname.
Structure that holds a lease for IPv4 address.
Definition: lease.h:295
const std::vector< uint8_t > & getClientIdVector() const
Returns a client identifier.
Definition: lease.cc:345
Structure that holds a lease for IPv6 address and/or prefix.
Definition: lease.h:514
const std::vector< uint8_t > & getDuidVector() const
Returns a reference to a vector representing a DUID.
Definition: lease.cc:533
a common structure for IPv4 and IPv6 leases
Definition: lease.h:31
bool stateExpiredReclaimed() const
Indicates if the lease is in the "expired-reclaimed" state.
Definition: lease.cc:113
SubnetID subnet_id_
Subnet identifier.
Definition: lease.h:154
const std::vector< uint8_t > & getHWAddrVector() const
Returns raw (as vector) hardware address.
Definition: lease.cc:355
int64_t getExpirationTime() const
Returns lease expiration time.
Definition: lease.cc:123
Tag for indexes by subnet-id.