Kea 2.7.6
allocator.cc
Go to the documentation of this file.
1// Copyright (C) 2022-2024 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#include <dhcpsrv/allocator.h>
10#include <dhcpsrv/dhcpsrv_log.h>
11
12using namespace isc::util;
13
14namespace isc {
15namespace dhcp {
16
18 : inited_(false),
19 pool_type_(type),
20 subnet_id_(0),
21 subnet_(subnet) {
22 // Remember subnet ID in a separate variable. It may be needed in
23 // the destructor where the subnet weak pointer is unavailable.
24 subnet_id_ = subnet_.lock()->getID();
25}
26
29 // If there is no lease manager instance, the callbacks are
30 // gone already anyway.
31 return;
32 }
33 // Remove the callbacks.
35}
36
37bool
39 PoolPtr pool, uint8_t hint_prefix_length) {
40 auto pool6 = boost::dynamic_pointer_cast<Pool6>(pool);
41 if (!pool6) {
42 return (false);
43 }
44
45 if (!hint_prefix_length) {
46 return (true);
47 }
48
49 if (prefix_length_match == Allocator::PREFIX_LEN_EQUAL &&
50 pool6->getLength() != hint_prefix_length) {
51 return (false);
52 }
53
54 if (prefix_length_match == Allocator::PREFIX_LEN_LOWER &&
55 pool6->getLength() >= hint_prefix_length) {
56 return (false);
57 }
58
59 if (prefix_length_match == Allocator::PREFIX_LEN_HIGHER &&
60 pool6->getLength() <= hint_prefix_length) {
61 return (false);
62 }
63
64 return (true);
65}
66
67void
69 if (inited_) {
70 return;
71 }
72 auto subnet = subnet_.lock();
74 .arg(getType())
76 .arg(subnet->toText());
78 inited_ = true;
79}
80
81}
82}
void initAfterConfigure()
Performs allocator initialization after server's reconfiguration.
Definition allocator.cc:68
SubnetID subnet_id_
ID of a subnet to which the allocator belongs.
Definition allocator.h:229
virtual void initAfterConfigureInternal()
Allocator-specific initialization function.
Definition allocator.h:172
Lease::Type pool_type_
Defines pool type allocation.
Definition allocator.h:226
PrefixLenMatchType
Type of preferred PD-pool prefix length selection criteria.
Definition allocator.h:61
bool inited_
Indicates if the allocator has been initialized.
Definition allocator.h:223
Allocator(Lease::Type type, const WeakSubnetPtr &subnet)
Constructor.
Definition allocator.cc:17
virtual ~Allocator()
Virtual destructor.
Definition allocator.cc:27
WeakSubnetPtr subnet_
Weak pointer to the subnet owning the allocator.
Definition allocator.h:232
virtual std::string getType() const =0
Returns allocator type string.
static bool isValidPrefixPool(Allocator::PrefixLenMatchType prefix_length_match, PoolPtr pool, uint8_t hint_prefix_length)
Check if the pool matches the selection criteria relative to the provided hint prefix length.
Definition allocator.cc:38
static TrackingLeaseMgr & instance()
Return current lease manager.
static bool haveInstance()
Indicates if the lease manager has been instantiated.
void unregisterCallbacks(SubnetID subnet_id, Lease::Type lease_type)
Unregisters all callbacks for a given subnet identifier.
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
Definition macros.h:20
isc::log::Logger dhcpsrv_logger("dhcpsrv")
DHCP server library Logger.
Definition dhcpsrv_log.h:56
boost::weak_ptr< Subnet > WeakSubnetPtr
Weak pointer to the Subnet.
Definition allocator.h:32
const isc::log::MessageID DHCPSRV_CFGMGR_USE_ALLOCATOR
boost::shared_ptr< Pool > PoolPtr
a pointer to either IPv4 or IPv6 Pool
Definition pool.h:485
Defines the logger used by the top-level component of kea-lfc.
Type
Type of lease or pool.
Definition lease.h:46
static std::string typeToText(Type type)
returns text representation of a lease type
Definition lease.cc:55