Kea 3.1.5
lease_query_impl.h
Go to the documentation of this file.
1// Copyright (C) 2020-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 LEASE_QUERY_IMPL_H
8#define LEASE_QUERY_IMPL_H
9
11#include <asiolink/io_address.h>
12#include <asiolink/io_service.h>
13#include <dhcp/pkt.h>
14#include <dhcpsrv/pool.h>
15#include <cc/data.h>
16#include <cc/simple_parser.h>
17
18#include <boost/functional/hash.hpp>
19#include <unordered_set>
20
21namespace isc {
22namespace lease_query {
23
26public:
27 QueryTerminated(const char* file, size_t line, const char* what) :
28 isc::Exception(file, line, what) {
29 }
30};
31
32#define CHECK_TERMINATED \
33 if (LeaseQueryImpl::terminated_) { \
34 isc_throw(isc::lease_query::QueryTerminated, "terminated"); \
35 }
36
39public:
43 AddressList(uint16_t family)
44 : family_(family) { };
45
53 void insert(const isc::asiolink::IOAddress& address);
54
61 bool contains(const isc::asiolink::IOAddress& address) const;
62
64 size_t size() const {
65 return (addresses_.size());
66 }
67
69 uint16_t getFamily() {
70 return (family_);
71 }
72
73private:
75 uint16_t family_;
76
78 std::unordered_set<asiolink::IOAddress, asiolink::IOAddress::Hash> addresses_;
79};
80
83 std::size_t operator()(const isc::dhcp::PoolPtr& p) const noexcept {
84 const auto& f = p->getFirstAddress();
85 const auto& l = p->getLastAddress();
86
88 std::size_t h1 = haddr(f);
89 std::size_t h2 = haddr(l);
90
91 // hash_combine
92 return h1 ^ (h2 + 0x9e3779b97f4a7c15ULL + (h1 << 6) + (h1 >> 2));
93 }
94};
95
99 const isc::dhcp::PoolPtr& b) const noexcept {
100 return a->getFirstAddress() == b->getFirstAddress() &&
101 a->getLastAddress() == b->getLastAddress();
102 }
103};
104
106using PoolRangeSet = std::unordered_set<isc::dhcp::PoolPtr,
109
112class PoolSet {
113public:
117 PoolSet(uint16_t family)
118 : family_(family) { };
119
130 void insert(const isc::asiolink::IOAddress& prefix, uint8_t prefix_len);
131
138 bool contains(const isc::asiolink::IOAddress& address) const;
139
141 size_t size() const {
142 return (pools_.size());
143 }
144
146 uint16_t getFamily() const {
147 return (family_);
148 }
149
150private:
152 uint16_t family_;
153
155 PoolRangeSet pools_;
156};
157
159class LeaseQueryImpl : public boost::noncopyable {
160public:
165 LeaseQueryImpl(uint16_t family, const isc::data::ConstElementPtr config);
166
168 virtual ~LeaseQueryImpl();
169
175 bool isRequester(const isc::asiolink::IOAddress& address) const;
176
178 size_t getNumRequesters() const {
179 return (address_list_.size());
180 }
181
183 size_t getNumRequesterPools() const {
184 return (pool_set_.size());
185 }
186
199 virtual void processQuery(isc::dhcp::PktPtr base_query,
200 bool& invalid) const = 0;
201
204
206 uint16_t getFamily() {
207 return (address_list_.getFamily());
208 }
209
214 return (io_service_);
215 }
216
221 io_service_ = io_service;
222 }
223
225 static bool terminated_;
226
228 static size_t PageSize;
229
230private:
238 void parserRequesters(isc::data::ConstElementPtr requesters);
239
241 isc::asiolink::IOServicePtr io_service_;
242
244 AddressList address_list_;
245
247 PoolSet pool_set_;
248};
249
251typedef boost::shared_ptr<LeaseQueryImpl> LeaseQueryImplPtr;
252
253} // end of namespace isc::lease_query
254} // end of namespace isc
255
256#endif // LEASE_QUERY_IMPL_H
This is a base class for exceptions thrown from the DNS library module.
Exception(const char *file, size_t line, const char *what)
Constructor for a given type for exceptions with file name and file line number.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Manages a unique list of IP addresses.
size_t size() const
Returns the number of addresses in the list.
bool contains(const isc::asiolink::IOAddress &address) const
Checks if an address is present in the list.
AddressList(uint16_t family)
Constructor.
uint16_t getFamily()
Returns the protocol family of the address list.
void insert(const isc::asiolink::IOAddress &address)
Inserts an address into the list.
uint16_t getFamily()
Returns the protocol family of the impl.
static bool terminated_
Terminated flag.
LeaseQueryImpl(uint16_t family, const isc::data::ConstElementPtr config)
Constructor.
static const isc::data::SimpleKeywords LEASE_QUERY_KEYWORDS
Keywords for Lease Query configuration.
size_t getNumRequesters() const
Returns the number of valid requester.
size_t getNumRequesterPools() const
Returns the number of valid requester pools.
isc::asiolink::IOServicePtr getIOService()
Get the hook I/O service.
bool isRequester(const isc::asiolink::IOAddress &address) const
Checks if the given address belongs to a valid requester.
void setIOService(isc::asiolink::IOServicePtr io_service)
Set the hook I/O service.
static size_t PageSize
Page size to commands.
virtual void processQuery(isc::dhcp::PktPtr base_query, bool &invalid) const =0
Processes a single client Lease Query.
Manages a unique set of Pools of a given protocol family.
uint16_t getFamily() const
Returns the protocol family of the address set.
size_t size() const
Returns the number of pools in the set.
void insert(const isc::asiolink::IOAddress &prefix, uint8_t prefix_len)
Inserts an pool into the set.
PoolSet(uint16_t family)
Constructor.
bool contains(const isc::asiolink::IOAddress &address) const
Checks if an address is present in the set.
QueryTerminated(const char *file, size_t line, const char *what)
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:29
std::map< std::string, isc::data::Element::types > SimpleKeywords
This specifies all accepted keywords with their types.
boost::shared_ptr< isc::dhcp::Pkt > PktPtr
A pointer to either Pkt4 or Pkt6 packet.
Definition pkt.h:999
boost::shared_ptr< Pool > PoolPtr
a pointer to either IPv4 or IPv6 Pool
Definition pool.h:726
boost::shared_ptr< LeaseQueryImpl > LeaseQueryImplPtr
Defines a smart pointer to LeaseQueryImpl instance.
std::unordered_set< isc::dhcp::PoolPtr, PoolRangeHash, PoolRangeEqual > PoolRangeSet
Defines an alias for a set of pools hashed by range.
Defines the logger used by the top-level component of kea-lfc.
Equality comparator for two pools based on their address range.
bool operator()(const isc::dhcp::PoolPtr &a, const isc::dhcp::PoolPtr &b) const noexcept
Hash for a Pool based on it's address range.
std::size_t operator()(const isc::dhcp::PoolPtr &p) const noexcept