Kea 2.5.8
allocator.cc
Go to the documentation of this file.
1// Copyright (C) 2022-2023 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.
34 auto& lease_mgr = LeaseMgrFactory::instance();
35 lease_mgr.unregisterCallbacks(subnet_id_, pool_type_);
36}
37
38bool
40 PoolPtr pool, uint8_t hint_prefix_length) {
41 auto pool6 = boost::dynamic_pointer_cast<Pool6>(pool);
42 if (!pool6) {
43 return (false);
44 }
45
46 if (!hint_prefix_length) {
47 return (true);
48 }
49
50 if (prefix_length_match == Allocator::PREFIX_LEN_EQUAL &&
51 pool6->getLength() != hint_prefix_length) {
52 return (false);
53 }
54
55 if (prefix_length_match == Allocator::PREFIX_LEN_LOWER &&
56 pool6->getLength() >= hint_prefix_length) {
57 return (false);
58 }
59
60 if (prefix_length_match == Allocator::PREFIX_LEN_HIGHER &&
61 pool6->getLength() <= hint_prefix_length) {
62 return (false);
63 }
64
65 return (true);
66}
67
68void
70 if (inited_) {
71 return;
72 }
73 auto subnet = subnet_.lock();
75 .arg(getType())
77 .arg(subnet->toText());
79 inited_ = true;
80}
81
82}
83}
void initAfterConfigure()
Performs allocator initialization after server's reconfiguration.
Definition: allocator.cc:69
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:39
static TrackingLeaseMgr & instance()
Return current lease manager.
static bool haveInstance()
Indicates if the lease manager has been instantiated.
#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:483
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:54