| Kea 3.0.2-git

lease_query_impl.cc
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#include <config.h>
8
9#include <lease_query_impl.h>
10#include <blq_service.h>
11
12 using namespace isc;
13 using namespace isc::asiolink;
14 using namespace isc::data;
15 using namespace isc::dhcp;
16 using namespace isc::lease_query;
17
18 void
19 AddressList::insert(const IOAddress& address) {
20 // Check for duplicates as inserts into set do not.
21 // Proper family check is done in by contains().
22 if (contains(address)) {
23 isc_throw(BadValue, "address is already in the list");
24 }
25
26 static_cast<void>(addresses_.insert(address));
27}
28
29 bool
30 AddressList::contains(const IOAddress& address) const {
31 // Make sure we have the right family.
32 if (address.getFamily() != family_) {
33 isc_throw(BadValue, "not a " << (family_ == AF_INET ? "IPv4" : "IPv6")
34 << " address");
35 }
36
37 return (addresses_.count(address));
38}
39
40 const SimpleKeywords
41 LeaseQueryImpl::LEASE_QUERY_KEYWORDS =
42{
43 { "requesters", Element::list },
44 { "advanced", Element::map },
45 { "comment", Element::string },
46 { "prefix-lengths", Element::list }, // v6 only
47};
48
49 LeaseQueryImpl::LeaseQueryImpl(uint16_t family,
50 const ConstElementPtr config)
51 : io_service_(new IOService()), address_list_(family) {
52
53 if (!config || (config->getType() != Element::map)) {
54 isc_throw(BadValue, "Lease Query config is empty or not a map");
55 }
56
57 ConstElementPtr requesters = config->get("requesters");
58 if (!requesters || (requesters->getType() != Element::list)) {
59 isc_throw(BadValue,
60 "'requesters' address list is missing or not a list");
61 }
62
63 for (auto const& address_elem : requesters->listValue()) {
64 try {
65 IOAddress address(address_elem->stringValue());
66 address_list_.insert(address);
67 } catch (const std::exception& ex) {
68 isc_throw(BadValue,
69 "'requesters' entry '" << address_elem->stringValue()
70 << "' is invalid: " << ex.what());
71 }
72 }
73
74 if (address_list_.size() == 0) {
75 isc_throw(BadValue, "'requesters' address list cannot be empty");
76 }
77
78 ConstElementPtr advanced = config->get("advanced");
79 if (advanced) {
80 BulkLeaseQueryService::create(this, advanced);
81 }
82}
83
84 LeaseQueryImpl::~LeaseQueryImpl() {
85 io_service_->stopAndPoll();
86}
87
88 bool
89 LeaseQueryImpl::isRequester(const IOAddress& address) const {
90 return (address_list_.contains(address));
91}
92
93 bool
94 LeaseQueryImpl::terminated_ = false;
95
96 size_t
97 LeaseQueryImpl::PageSize = 100;
if
if(!(yy_init))
Definition agent_lexer.cc:1900
blq_service.h
Element::map
@ map
Definition data.h:147
Element::list
@ list
Definition data.h:146
Element::string
@ string
Definition data.h:144
isc::BadValue
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
Definition exceptions/exceptions.h:132
isc::asiolink::IOAddress
The IOAddress class represents an IP addresses (version agnostic).
Definition io_address.h:45
isc::asiolink::IOAddress::getFamily
short getFamily() const
Returns the address family.
Definition io_address.cc:96
isc::asiolink::IOService
The IOService class is a wrapper for the ASIO io_context class.
Definition io_service.h:32
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::insert
void insert(const isc::asiolink::IOAddress &address)
Inserts an address into the list.
Definition lease_query_impl.cc:19
isc::lease_query::BulkLeaseQueryService::create
static void create(LeaseQueryImpl *impl, isc::data::ConstElementPtr advanced)
Create a new instance of the BulkLeaseQueryService.
Definition blq_service.cc:230
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::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::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_throw
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Definition exceptions/exceptions.h:210
lease_query_impl.h
isc::asiolink
Definition addr_utilities.cc:170
isc::config
Definition command_interpreter.cc:23
isc::data
Definition base_stamped_element.cc:12
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
Definition dhcp4/client_handler.cc:20
isc::lease_query
Definition blq_msg.h:15
isc
Defines the logger used by the top-level component of kea-lfc.
Definition agent_parser.cc:148