Kea 2.7.7
pool.h
Go to the documentation of this file.
1// Copyright (C) 2012-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#ifndef POOL_H
8#define POOL_H
9
10#include <asiolink/io_address.h>
11#include <cc/data.h>
12#include <cc/user_context.h>
13#include <dhcp/classify.h>
16#include <dhcpsrv/cfg_option.h>
18#include <dhcpsrv/lease.h>
20#include <util/bigints.h>
21#include <util/optional.h>
22
23#include <boost/shared_ptr.hpp>
24
25#include <vector>
26
27namespace isc {
28namespace dhcp {
29
35
36public:
39
46 uint64_t getID() const {
47 return (id_);
48 }
49
56 void setID(const uint64_t id) {
57 id_ = id;
58 }
59
64 return (first_);
65 }
66
70 return (last_);
71 }
72
76 bool inRange(const isc::asiolink::IOAddress& addr) const;
77
81 return (type_);
82 }
83
87 virtual std::string toText() const;
88
94 virtual ~Pool() = default;
95
102 return (capacity_);
103 }
104
107 return (cfg_option_);
108 }
109
113 return (cfg_option_);
114 }
115
121 bool clientSupported(const ClientClasses& client_classes) const;
122
126 void allowClientClass(const isc::dhcp::ClientClass& class_name);
127
130 return (client_classes_);
131 }
132
137
141 void addAdditionalClass(const ClientClass& class_name);
142
145 return (additional_classes_);
146 }
147
152
161
165 void setAllocationState(const AllocationStatePtr& allocation_state) {
166 allocation_state_ = allocation_state;
167 }
168
172 virtual data::ElementPtr toElement() const;
173
174
178 return (ddns_send_updates_);
179 }
180
184 void setDdnsSendUpdates(const util::Optional<bool>& ddns_send_updates) {
185 ddns_send_updates_ = ddns_send_updates;
186 }
187
193
197 void setDdnsOverrideNoUpdate(const util::Optional<bool>& ddns_override_no_update) {
198 ddns_override_no_update_ = ddns_override_no_update;
199 }
200
206
211 ddns_override_client_update) {
212 ddns_override_client_update_ = ddns_override_client_update;
213 }
214
220
224 void
226 ddns_replace_client_name_mode) {
227 ddns_replace_client_name_mode_ = ddns_replace_client_name_mode;
228 }
229
233 return (ddns_generated_prefix_);
234 }
235
239 void setDdnsGeneratedPrefix(const util::Optional<std::string>& ddns_generated_prefix) {
240 ddns_generated_prefix_ = ddns_generated_prefix;
241 }
242
248
252 void setDdnsQualifyingSuffix(const util::Optional<std::string>& ddns_qualifying_suffix) {
253 ddns_qualifying_suffix_ = ddns_qualifying_suffix;
254 }
255
259 return (ddns_update_on_renew_);
260 }
261
265 void setDdnsUpdateOnRenew(const util::Optional<bool>& ddns_update_on_renew) {
266 ddns_update_on_renew_ = ddns_update_on_renew;
267 }
268
274
278 void setDdnsConflictResolutionMode(const util::Optional<std::string>& ddns_conflict_resolution_mode) {
279 ddns_conflict_resolution_mode_ = ddns_conflict_resolution_mode;
280 }
281
282
286 return (ddns_ttl_percent_);
287 }
288
292 void setDdnsTtlPercent(const util::Optional<double>& ddns_ttl_percent) {
293 ddns_ttl_percent_ = ddns_ttl_percent;
294 }
295
298 getDdnsTtl() const {
299 return (ddns_ttl_);
300 }
301
305 void setDdnsTtl(const util::Optional<uint32_t>& ddns_ttl) {
306 ddns_ttl_ = ddns_ttl;
307 }
308
312 return (ddns_ttl_min_);
313 }
314
318 void setDdnsTtlMin(const util::Optional<uint32_t>& ddns_ttl_min) {
319 ddns_ttl_min_ = ddns_ttl_min;
320 }
321
325 return (ddns_ttl_max_);
326 }
327
331 void setDdnsTtlMax(const util::Optional<uint32_t>& ddns_ttl_max) {
332 ddns_ttl_max_ = ddns_ttl_max;
333 }
334
338 return (hostname_char_set_);
339 }
340
344 void setHostnameCharSet(const util::Optional<std::string>& hostname_char_set) {
345 hostname_char_set_ = hostname_char_set;
346 }
347
353
358 hostname_char_replacement) {
359 hostname_char_replacement_ = hostname_char_replacement;
360 }
361
365 bool hasDdnsParameters() const;
366
367protected:
368
378 Pool(Lease::Type type,
379 const isc::asiolink::IOAddress& first,
380 const isc::asiolink::IOAddress& last);
381
386 uint64_t id_;
387
390
393
396
404
407
415
420
423
426
430
434
437
440
443
446
449
452
455
458
461
464
468
472};
473
474class Pool4;
475
477typedef boost::shared_ptr<Pool4> Pool4Ptr;
478
483class Pool4 : public Pool {
484public:
489 Pool4(const isc::asiolink::IOAddress& first,
490 const isc::asiolink::IOAddress& last);
491
496 Pool4(const isc::asiolink::IOAddress& prefix,
497 uint8_t prefix_len);
498
510 static Pool4Ptr create(const isc::asiolink::IOAddress& first,
511 const isc::asiolink::IOAddress& last);
512
524 static Pool4Ptr create(const isc::asiolink::IOAddress& prefix,
525 uint8_t prefix_len);
526
530 virtual data::ElementPtr toElement() const;
531};
532
533class Pool6;
534
536typedef boost::shared_ptr<Pool6> Pool6Ptr;
537
542class Pool6 : public Pool {
543public:
544
552 Pool6(Lease::Type type, const isc::asiolink::IOAddress& first,
553 const isc::asiolink::IOAddress& last);
554
582 Pool6(Lease::Type type, const isc::asiolink::IOAddress& prefix,
583 uint8_t prefix_len, uint8_t delegated_len = 128);
584
597 Pool6(const asiolink::IOAddress& prefix, const uint8_t prefix_len,
598 const uint8_t delegated_len,
599 const asiolink::IOAddress& excluded_prefix,
600 const uint8_t excluded_prefix_len);
601
614 static Pool6Ptr create(Lease::Type type,
615 const isc::asiolink::IOAddress& first,
616 const isc::asiolink::IOAddress& last);
617
631 static Pool6Ptr create(Lease::Type type,
632 const isc::asiolink::IOAddress& prefix,
633 uint8_t prefix_len,
634 uint8_t delegated_len = 128);
635
650 static Pool6Ptr create(const asiolink::IOAddress& prefix,
651 const uint8_t prefix_len,
652 const uint8_t delegated_len,
653 const asiolink::IOAddress& excluded_prefix,
654 const uint8_t excluded_prefix_len);
655
660 return (type_);
661 }
662
668 uint8_t getLength() const {
669 return (prefix_len_);
670 }
671
677 return (pd_exclude_option_);
678 }
679
683 virtual data::ElementPtr toElement() const;
684
688 virtual std::string toText() const;
689
690private:
691
710 void init(const Lease::Type& type,
711 const asiolink::IOAddress& prefix,
712 const uint8_t prefix_len,
713 const uint8_t delegated_len,
714 const asiolink::IOAddress& excluded_prefix,
715 const uint8_t excluded_prefix_len);
716
718 uint8_t prefix_len_;
719
721 Option6PDExcludePtr pd_exclude_option_;
722
723};
724
726typedef boost::shared_ptr<Pool> PoolPtr;
727
729typedef std::vector<PoolPtr> PoolCollection;
730
731} // end of isc::dhcp namespace
732} // end of isc namespace
733
734#endif // POOL_H
Defines elements for storing the names of client classes.
Container for storing client class names.
Definition classify.h:109
Pool information for IPv4 addresses.
Definition pool.h:483
virtual data::ElementPtr toElement() const
Unparse a Pool4 object.
Definition pool.cc:228
Pool4(const isc::asiolink::IOAddress &first, const isc::asiolink::IOAddress &last)
the constructor for Pool4 "min-max" style definition
Definition pool.cc:77
static Pool4Ptr create(const isc::asiolink::IOAddress &first, const isc::asiolink::IOAddress &last)
Factory function for creating an instance of the Pool4.
Definition pool.cc:127
Pool information for IPv6 addresses and prefixes.
Definition pool.h:542
uint8_t getLength() const
returns delegated prefix length
Definition pool.h:668
virtual data::ElementPtr toElement() const
Unparse a Pool6 object.
Definition pool.cc:439
Option6PDExcludePtr getPrefixExcludeOption() const
Returns instance of the pool specific Prefix Exclude option.
Definition pool.h:676
static Pool6Ptr create(Lease::Type type, const isc::asiolink::IOAddress &first, const isc::asiolink::IOAddress &last)
Factory function for creating an instance of the Pool6.
Definition pool.cc:352
virtual std::string toText() const
returns textual representation of the pool
Definition pool.cc:509
Pool6(Lease::Type type, const isc::asiolink::IOAddress &first, const isc::asiolink::IOAddress &last)
the constructor for Pool6 "min-max" style definition
Definition pool.cc:249
Lease::Type getType() const
returns pool type
Definition pool.h:659
base class for Pool4 and Pool6
Definition pool.h:34
data::ConstElementPtr user_context_
Pointer to the user context (may be NULL)
Definition pool.h:422
util::Optional< std::string > getHostnameCharSet() const
Return the char set regexp used to sanitize client hostnames.
Definition pool.h:337
const ClientClasses & getAdditionalClasses() const
Returns the additional classes list.
Definition pool.h:144
virtual data::ElementPtr toElement() const
Unparse a pool object.
Definition pool.cc:137
util::Optional< uint32_t > ddns_ttl_
Explicit value to use for DNS TTL.
Definition pool.h:457
util::Optional< std::string > getDdnsQualifyingSuffix() const
Returns ddns-qualifying-suffix.
Definition pool.h:245
CfgOptionPtr cfg_option_
Pointer to the option data configuration for this pool.
Definition pool.h:406
util::Optional< double > getDdnsTtlPercent() const
Returns ddns-ttl-percent.
Definition pool.h:285
util::Optional< std::string > hostname_char_replacement_
A string to replace invalid characters when scrubbing hostnames.
Definition pool.h:471
void setDdnsTtlPercent(const util::Optional< double > &ddns_ttl_percent)
Sets new ddns-ttl-percent.
Definition pool.h:292
util::Optional< uint32_t > ddns_ttl_max_
Maximum value to use for DNS TTL.
Definition pool.h:463
void setID(const uint64_t id)
Sets Pool-id.
Definition pool.h:56
ClientClasses & getMutableAdditionalClasses()
Returns the mutable additional classes list.
Definition pool.h:149
void setDdnsOverrideNoUpdate(const util::Optional< bool > &ddns_override_no_update)
Sets new ddns-override-no-update.
Definition pool.h:197
void setDdnsTtlMin(const util::Optional< uint32_t > &ddns_ttl_min)
Sets new ddns-ttl-min.
Definition pool.h:318
util::Optional< bool > ddns_update_on_renew_
Should Kea perform updates when leases are extended.
Definition pool.h:448
Pool(Lease::Type type, const isc::asiolink::IOAddress &first, const isc::asiolink::IOAddress &last)
protected constructor
Definition pool.cc:21
util::Optional< bool > getDdnsUpdateOnRenew() const
Returns ddns-update-on-renew.
Definition pool.h:258
util::Optional< std::string > ddns_qualifying_suffix_
Suffix Kea should use when to qualify partial domain-names.
Definition pool.h:445
isc::util::uint128_t getCapacity() const
Returns the number of all leases in this pool.
Definition pool.h:101
util::Optional< D2ClientConfig::ReplaceClientNameMode > getDdnsReplaceClientNameMode() const
Returns ddns-replace-client-name-mode.
Definition pool.h:217
void setDdnsTtlMax(const util::Optional< uint32_t > &ddns_ttl_max)
Sets new ddns-ttl-max.
Definition pool.h:331
void setHostnameCharSet(const util::Optional< std::string > &hostname_char_set)
Sets new hostname-char-set.
Definition pool.h:344
util::Optional< std::string > hostname_char_set_
Regular expression describing invalid characters for client hostnames.
Definition pool.h:467
const isc::asiolink::IOAddress & getFirstAddress() const
Returns the first address in a pool.
Definition pool.h:63
util::Optional< bool > getDdnsSendUpdates() const
Returns ddns-send-updates.
Definition pool.h:177
util::Optional< D2ClientConfig::ReplaceClientNameMode > ddns_replace_client_name_mode_
How Kea should handle the domain-name supplied by the client.
Definition pool.h:439
ClientClasses additional_classes_
Additional classes.
Definition pool.h:419
void setDdnsConflictResolutionMode(const util::Optional< std::string > &ddns_conflict_resolution_mode)
Sets new ddns-conflict-resolution-mode.
Definition pool.h:278
bool hasDdnsParameters() const
Checks if any of the DDNS parameters has a value.
Definition pool.cc:60
util::Optional< uint32_t > ddns_ttl_min_
Minimum value to use for DNS TTL.
Definition pool.h:460
uint64_t id_
pool-id
Definition pool.h:386
AllocationStatePtr getAllocationState() const
Returns pool-specific allocation state.
Definition pool.h:158
Lease::Type getType() const
Returns pool type (v4, v6 non-temporary, v6 temp, v6 prefix)
Definition pool.h:80
const isc::asiolink::IOAddress & getLastAddress() const
Returns the last address in a pool.
Definition pool.h:69
void setDdnsTtl(const util::Optional< uint32_t > &ddns_ttl)
Sets new ddns-ttl.
Definition pool.h:305
util::Optional< uint32_t > getDdnsTtlMax() const
Returns ddns-ttl-max.
Definition pool.h:324
ClientClasses & getMutableClientClasses()
Returns the mutable list of allowed client classes.
Definition pool.h:134
void setAllocationState(const AllocationStatePtr &allocation_state)
Sets pool-specific allocation state.
Definition pool.h:165
util::Optional< std::string > ddns_generated_prefix_
Prefix Kea should use when generating domain-names.
Definition pool.h:442
util::Optional< bool > ddns_override_client_update_
Should Kea perform updates, even if client requested delegation.
Definition pool.h:436
util::Optional< double > ddns_ttl_percent_
Percentage of the lease lifetime to use for DNS TTL.
Definition pool.h:454
void setDdnsSendUpdates(const util::Optional< bool > &ddns_send_updates)
Sets new ddns-send-updates.
Definition pool.h:184
isc::util::uint128_t capacity_
Stores number of possible leases.
Definition pool.h:403
uint64_t getID() const
Returns Pool-id.
Definition pool.h:46
ClientClasses client_classes_
List of client classes allowed to use this pool.
Definition pool.h:414
util::Optional< std::string > getDdnsGeneratedPrefix() const
Returns ddns-generated-prefix.
Definition pool.h:232
const ClientClasses & getClientClasses() const
Returns the list of allowed client classes.
Definition pool.h:129
void allowClientClass(const isc::dhcp::ClientClass &class_name)
Adds class clas_name to the allowed client classes list.
Definition pool.cc:38
util::Optional< bool > ddns_override_no_update_
Should Kea perform updates, even if client requested no updates.
Definition pool.h:433
isc::asiolink::IOAddress last_
The last address in a pool.
Definition pool.h:392
AllocationStatePtr allocation_state_
Holds pool-specific allocation state.
Definition pool.h:425
isc::asiolink::IOAddress first_
The first address in a pool.
Definition pool.h:389
util::Optional< uint32_t > getDdnsTtlMin() const
Returns ddns-ttl-min.
Definition pool.h:311
util::Optional< bool > getDdnsOverrideNoUpdate() const
Returns ddns-override-no-update.
Definition pool.h:190
void setDdnsReplaceClientNameMode(const util::Optional< D2ClientConfig::ReplaceClientNameMode > &ddns_replace_client_name_mode)
Sets new ddns-replace-client-name-mode.
Definition pool.h:225
util::Optional< bool > getDdnsOverrideClientUpdate() const
Returns ddns-override-client-update.
Definition pool.h:203
util::Optional< std::string > ddns_conflict_resolution_mode_
DDNS conflict resolution mode.
Definition pool.h:451
void setDdnsQualifyingSuffix(const util::Optional< std::string > &ddns_qualifying_suffix)
Sets new ddns-qualifying-suffix.
Definition pool.h:252
void setDdnsUpdateOnRenew(const util::Optional< bool > &ddns_update_on_renew)
Sets new ddns-update-on-renew.
Definition pool.h:265
void setHostnameCharReplacement(const util::Optional< std::string > &hostname_char_replacement)
Sets new hostname-char-replacement.
Definition pool.h:357
util::Optional< bool > ddns_send_updates_
Should Kea perform DNS updates.
Definition pool.h:429
void setDdnsGeneratedPrefix(const util::Optional< std::string > &ddns_generated_prefix)
Sets new ddns-generated-prefix.
Definition pool.h:239
util::Optional< uint32_t > getDdnsTtl() const
Returns ddns-ttl.
Definition pool.h:298
CfgOptionPtr getCfgOption()
Returns pointer to the option data configuration for this pool.
Definition pool.h:106
virtual std::string toText() const
returns textual representation of the pool
Definition pool.cc:52
bool inRange(const isc::asiolink::IOAddress &addr) const
Checks if a given address is in the range.
Definition pool.cc:28
void addAdditionalClass(const ClientClass &class_name)
Adds class class_name to the additional classes list.
Definition pool.cc:45
void setDdnsOverrideClientUpdate(const util::Optional< bool > &ddns_override_client_update)
Sets new ddns-override-client-update.
Definition pool.h:210
bool clientSupported(const ClientClasses &client_classes) const
Checks whether this pool supports client that belongs to specified classes.
Definition pool.cc:33
virtual ~Pool()=default
virtual destructor
util::Optional< std::string > getHostnameCharReplacement() const
Return the invalid char replacement used to sanitize client hostnames.
Definition pool.h:350
util::Optional< std::string > getDdnsConflictResolutionMode() const
Returns ddns-conflict-resolution-mode.
Definition pool.h:271
ConstCfgOptionPtr getCfgOption() const
Returns const pointer to the option data configuration for this pool.
Definition pool.h:112
Lease::Type type_
defines a lease type that will be served from this pool
Definition pool.h:395
A template representing an optional value.
Definition optional.h:36
Defines the D2ClientConfig class.
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:29
boost::shared_ptr< Element > ElementPtr
Definition data.h:28
boost::shared_ptr< Pool4 > Pool4Ptr
a pointer an IPv4 Pool
Definition pool.h:477
std::string ClientClass
Defines a single class name.
Definition classify.h:43
boost::shared_ptr< CfgOption > CfgOptionPtr
Non-const pointer.
Definition cfg_option.h:892
boost::shared_ptr< Option6PDExclude > Option6PDExcludePtr
Pointer to the Option6PDExclude object.
boost::shared_ptr< AllocationState > AllocationStatePtr
Type of the pointer to the AllocationState.
std::vector< PoolPtr > PoolCollection
a container for either IPv4 or IPv6 Pools
Definition pool.h:729
boost::shared_ptr< Pool > PoolPtr
a pointer to either IPv4 or IPv6 Pool
Definition pool.h:726
boost::shared_ptr< const CfgOption > ConstCfgOptionPtr
Const pointer.
Definition cfg_option.h:895
boost::shared_ptr< Pool6 > Pool6Ptr
a pointer an IPv6 Pool
Definition pool.h:536
boost::multiprecision::checked_uint128_t uint128_t
Definition bigints.h:21
Defines the logger used by the top-level component of kea-lfc.
Abstract class for configuration Cfg_* classes.
Base class for user context.
Type
Type of lease or pool.
Definition lease.h:46