Kea 3.1.1
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
12using namespace isc;
13using namespace isc::asiolink;
14using namespace isc::data;
15using namespace isc::dhcp;
16using namespace isc::lease_query;
17
18void
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
29bool
30AddressList::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
42{
43 { "requesters", Element::list },
44 { "advanced", Element::map },
45 { "comment", Element::string },
46 { "prefix-lengths", Element::list }, // v6 only
47};
48
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) {
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
85 io_service_->stopAndPoll();
86}
87
88bool
90 return (address_list_.contains(address));
91}
92
93bool
95
96size_t
if(!(yy_init))
@ map
Definition data.h:147
@ list
Definition data.h:146
@ string
Definition data.h:144
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
bool contains(const isc::asiolink::IOAddress &address) const
Checks if an address is present in the list.
void insert(const isc::asiolink::IOAddress &address)
Inserts an address into the list.
static void create(LeaseQueryImpl *impl, isc::data::ConstElementPtr advanced)
Create a new instance of the BulkLeaseQueryService.
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.
bool isRequester(const isc::asiolink::IOAddress &address) const
Checks if the given address belongs to a valid requester.
static size_t PageSize
Page size to commands.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
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.
Defines the logger used by the top-level component of kea-lfc.