Kea 2.7.5
random_allocation_state.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>
9#include <boost/make_shared.hpp>
10
11using namespace isc::asiolink;
12
13namespace isc {
14namespace dhcp {
15
18 if (pool->getType() == Lease::TYPE_PD) {
19 // Pool classes ensure that the proper type is used for
20 // the IPv6 specific lease types, so we can just cast
21 // to the Pool6 pointer.
22 auto pd_pool = boost::dynamic_pointer_cast<Pool6>(pool);
23 return (boost::make_shared<PoolRandomAllocationState>(pd_pool->getFirstAddress(),
24 pd_pool->getLastAddress(),
25 pd_pool->getLength()));
26 }
27 return (boost::make_shared<PoolRandomAllocationState>(pool->getFirstAddress(), pool->getLastAddress()));
28}
29
31 : permutation_(new IPRangePermutation(AddressRange(first, last))) {
32}
33
35 const uint8_t delegated)
36 : permutation_(new IPRangePermutation(PrefixRange(first, last, delegated))) {
37}
38
39} // end of namespace isc::dhcp
40} // end of namespace isc
Random IP address/prefix permutation based on Fisher-Yates shuffle.
PoolRandomAllocationState(const asiolink::IOAddress &first, const asiolink::IOAddress &last)
Constructor from an IP address pool.
static PoolRandomAllocationStatePtr create(const PoolPtr &pool)
Factory function creating the state instance from pool.
boost::shared_ptr< PoolRandomAllocationState > PoolRandomAllocationStatePtr
Type of the pointer to the PoolRandomAllocationState.
boost::shared_ptr< Pool > PoolPtr
a pointer to either IPv4 or IPv6 Pool
Definition pool.h:488
Defines the logger used by the top-level component of kea-lfc.
Structure representing IP address range.
Definition ip_range.h:16
@ TYPE_PD
the lease contains IPv6 prefix (for prefix delegation)
Definition lease.h:49
Structure representing delegated prefix range.
Definition ip_range.h:32