| Kea 3.0.2-git

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
10#include <exceptions/exceptions.h>
11#include <asiolink/io_address.h>
12#include <asiolink/io_service.h>
13#include <dhcp/pkt.h>
14#include <cc/data.h>
15#include <cc/simple_parser.h>
16
17#include <boost/functional/hash.hpp>
18#include <unordered_set>
19
20 namespace isc {
21 namespace lease_query {
22
24 class QueryTerminated : public isc::Exception {
25 public:
26 QueryTerminated(const char* file, size_t line, const char* what) :
27 isc::Exception(file, line, what) {
28 }
29};
30
31#define CHECK_TERMINATED \
32 if (LeaseQueryImpl::terminated_) { \
33 isc_throw(isc::lease_query::QueryTerminated, "terminated"); \
34 }
35
37 class AddressList {
38 public:
42 AddressList(uint16_t family)
43 : family_(family) { };
44
52 void insert(const isc::asiolink::IOAddress& address);
53
60 bool contains(const isc::asiolink::IOAddress& address) const;
61
63 size_t size() const {
64 return (addresses_.size());
65 }
66
68 uint16_t getFamily() {
69 return (family_);
70 }
71
72 private:
74 uint16_t family_;
75
77 std::unordered_set<asiolink::IOAddress, boost::hash<asiolink::IOAddress> > addresses_;
78};
79
81 class LeaseQueryImpl : public boost::noncopyable {
82 public:
87 LeaseQueryImpl(uint16_t family, const isc::data::ConstElementPtr config);
88
90 virtual ~LeaseQueryImpl();
91
97 bool isRequester(const isc::asiolink::IOAddress& address) const;
98
100 size_t getNumRequesters() const {
101 return (address_list_.size());
102 }
103
114 virtual void processQuery(isc::dhcp::PktPtr base_query) const = 0;
115
117 static const isc::data::SimpleKeywords LEASE_QUERY_KEYWORDS;
118
120 uint16_t getFamily() {
121 return (address_list_.getFamily());
122 }
123
127 isc::asiolink::IOServicePtr getIOService() {
128 return (io_service_);
129 }
130
134 void setIOService(isc::asiolink::IOServicePtr io_service) {
135 io_service_ = io_service;
136 }
137
139 static bool terminated_;
140
142 static size_t PageSize;
143
144 private:
145
147 isc::asiolink::IOServicePtr io_service_;
148
150 AddressList address_list_;
151};
152
154 typedef boost::shared_ptr<LeaseQueryImpl> LeaseQueryImplPtr;
155
156} // end of namespace isc::lease_query
157} // end of namespace isc
158
159#endif // LEASE_QUERY_IMPL_H
isc::Exception
This is a base class for exceptions thrown from the DNS library module.
Definition exceptions/exceptions.h:23
isc::Exception::Exception
Exception(const char *file, size_t line, const char *what)
Constructor for a given type for exceptions with file name and file line number.
Definition exceptions/exceptions.cc:17
isc::Exception::what
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Definition exceptions/exceptions.cc:32
isc::asiolink::IOAddress
The IOAddress class represents an IP addresses (version agnostic).
Definition io_address.h:45
isc::lease_query::AddressList
Manages a unique list of IP addresses.
Definition lease_query_impl.h:37
isc::lease_query::AddressList::size
size_t size() const
Returns the number of addresses in the list.
Definition lease_query_impl.h:63
isc::lease_query::AddressList::contains
bool contains(const isc::asiolink::IOAddress &address) const
Checks if an address is present in the list.
Definition lease_query_impl.cc:30
isc::lease_query::AddressList::AddressList
AddressList(uint16_t family)
Constructor.
Definition lease_query_impl.h:42
isc::lease_query::AddressList::getFamily
uint16_t getFamily()
Returns the protocol family of the address list.
Definition lease_query_impl.h:68
isc::lease_query::AddressList::insert
void insert(const isc::asiolink::IOAddress &address)
Inserts an address into the list.
Definition lease_query_impl.cc:19
isc::lease_query::LeaseQueryImpl::processQuery
virtual void processQuery(isc::dhcp::PktPtr base_query) const =0
Processes a single client Lease Query.
isc::lease_query::LeaseQueryImpl::getFamily
uint16_t getFamily()
Returns the protocol family of the impl.
Definition lease_query_impl.h:120
isc::lease_query::LeaseQueryImpl::terminated_
static bool terminated_
Terminated flag.
Definition lease_query_impl.h:139
isc::lease_query::LeaseQueryImpl::LeaseQueryImpl
LeaseQueryImpl(uint16_t family, const isc::data::ConstElementPtr config)
Constructor.
Definition lease_query_impl.cc:49
isc::lease_query::LeaseQueryImpl::LEASE_QUERY_KEYWORDS
static const isc::data::SimpleKeywords LEASE_QUERY_KEYWORDS
Keywords for Lease Query configuration.
Definition lease_query_impl.h:117
isc::lease_query::LeaseQueryImpl::getNumRequesters
size_t getNumRequesters() const
Returns the number of valid requester.
Definition lease_query_impl.h:100
isc::lease_query::LeaseQueryImpl::getIOService
isc::asiolink::IOServicePtr getIOService()
Get the hook I/O service.
Definition lease_query_impl.h:127
isc::lease_query::LeaseQueryImpl::isRequester
bool isRequester(const isc::asiolink::IOAddress &address) const
Checks if the given address belongs to a valid requester.
Definition lease_query_impl.cc:89
isc::lease_query::LeaseQueryImpl::setIOService
void setIOService(isc::asiolink::IOServicePtr io_service)
Set the hook I/O service.
Definition lease_query_impl.h:134
isc::lease_query::LeaseQueryImpl::PageSize
static size_t PageSize
Page size to commands.
Definition lease_query_impl.h:142
isc::lease_query::LeaseQueryImpl::~LeaseQueryImpl
virtual ~LeaseQueryImpl()
Destructor.
Definition lease_query_impl.cc:84
isc::lease_query::QueryTerminated::QueryTerminated
QueryTerminated(const char *file, size_t line, const char *what)
Definition lease_query_impl.h:26
data.h
exceptions.h
io_address.h
io_service.h
simple_parser.h
isc::asiolink::IOServicePtr
boost::shared_ptr< IOService > IOServicePtr
Defines a smart pointer to an IOService instance.
Definition io_service.h:28
isc::config
Definition command_interpreter.cc:23
isc::data::ConstElementPtr
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:29
isc::data::SimpleKeywords
std::map< std::string, isc::data::Element::types > SimpleKeywords
This specifies all accepted keywords with their types.
Definition lib/cc/simple_parser.h:36
isc::dhcp::PktPtr
boost::shared_ptr< isc::dhcp::Pkt > PktPtr
A pointer to either Pkt4 or Pkt6 packet.
Definition pkt.h:998
isc::lease_query
Definition blq_msg.h:15
isc::lease_query::LeaseQueryImplPtr
boost::shared_ptr< LeaseQueryImpl > LeaseQueryImplPtr
Defines a smart pointer to LeaseQueryImpl instance.
Definition lease_query_impl.h:154
isc
Defines the logger used by the top-level component of kea-lfc.
Definition agent_parser.cc:148
pkt.h