1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Copyright (C) 2020-2024 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Kea Hooks Basic
// Commercial End User License Agreement v2.0. See COPYING file in the premium/
// directory.

#include <config.h>

#include <lease_query_impl.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <blq_service.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.

using namespace isc;
using namespace isc::asiolink;
using namespace isc::data;
using namespace isc::dhcp;
using namespace isc::lease_query;

void
AddressList::insert(const IOAddress& address) {
    // Check for duplicates as inserts into set do not.
    // Proper family check is done in by contains().
    if (contains(address)) {
        isc_throw(BadValue, "address is already in the list");
    }

    static_cast<void>(addresses_.insert(address));
}

bool
AddressList::contains(const IOAddress& address) const {
    // Make sure we have the right family.
    if (address.getFamily() != family_) {
        isc_throw(BadValue, "not a " << (family_ == AF_INET ? "IPv4" : "IPv6")
                   << " address");
    }

    return (addresses_.count(address));
}

const SimpleKeywords
LeaseQueryImpl::LEASE_QUERY_KEYWORDS =
{
    { "requesters",     Element::list   },
    { "advanced",       Element::map    },
    { "comment",        Element::string },
    { "prefix-lengths", Element::list   }, // v6 only
};

LeaseQueryImpl::LeaseQueryImpl(uint16_t family,
                               const ConstElementPtr config)
    : address_list_(family) {

    if (!config || (config->getType() != Element::map)) {
        isc_throw(BadValue, "Lease Query config is empty or not a map");
    }

    ConstElementPtr requesters = config->get("requesters");
    if (!requesters || (requesters->getType() != Element::list)) {
        isc_throw(BadValue,
                  "'requesters' address list is missing or not a list");
    }

    for (auto const& address_elem : requesters->listValue()) {
        try {
            IOAddress address(address_elem->stringValue());
            address_list_.insert(address);
        } catch (const std::exception& ex) {
            isc_throw(BadValue,
                      "'requesters' entry '" << address_elem->stringValue()
                      << "' is invalid: " << ex.what());
        }
    }

    if (address_list_.size() == 0) {
        isc_throw(BadValue, "'requesters' address list cannot be empty");
    }

    ConstElementPtr advanced = config->get("advanced");
    if (advanced) {
        BulkLeaseQueryService::create(this, advanced);
    }
}

bool
LeaseQueryImpl::isRequester(const IOAddress& address) const {
    return (address_list_.contains(address));
}

bool
LeaseQueryImpl::terminated_ = false;

size_t
LeaseQueryImpl::PageSize = 100;