Kea: lease.h Source File

| Kea 3.2.0-git

lease.h
Go to the documentation of this file.
1// Copyright (C) 2013-2026 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 LEASE_H
8#define LEASE_H
9
10#include <asiolink/io_address.h>
11#include <dhcp/duid.h>
12#include <dhcp/option.h>
13#include <dhcp/hwaddr.h>
14#include <dhcpsrv/subnet_id.h>
15#include <cc/user_context.h>
16#include <cc/cfg_to_element.h>
17#include <util/dhcp_space.h>
18
19namespace isc {
20namespace dhcp {
21
22struct Lease;
23
25 typedef boost::shared_ptr<Lease> LeasePtr;
26
31 struct Lease : public isc::data::UserContext, public isc::data::CfgToElement {
32
34 static const uint32_t INFINITY_LFT = 0xffffffff;
35
43 static std::string lifetimeToText(uint32_t lifetime);
44
46 enum Type : uint16_t {
47 TYPE_NA = 0,
48 TYPE_TA = 1,
49 TYPE_PD = 2,
50 TYPE_V4 = 3,
51 };
52
56 static std::string typeToText(Type type);
57
63 static Type textToType(const std::string& text);
64
66
67
69 static constexpr uint32_t STATE_DEFAULT = 0;
70
72 static constexpr uint32_t STATE_DECLINED = 1;
73
75 static constexpr uint32_t STATE_EXPIRED_RECLAIMED = 2;
76
78 static constexpr uint32_t STATE_RELEASED = 3;
79
81 static constexpr uint32_t STATE_REGISTERED = 4;
82
90 static std::string basicStatesToText(const uint32_t state);
91
109 Lease(const isc::asiolink::IOAddress& addr,
110 uint32_t valid_lft, SubnetID subnet_id, time_t cltt,
111 const bool fqdn_fwd, const bool fqdn_rev,
112 const std::string& hostname,
113 const HWAddrPtr& hwaddr);
114
116 virtual ~Lease() {}
117
121 virtual Lease::Type getType() const = 0;
122
126 isc::asiolink::IOAddress addr_;
127
131 uint32_t valid_lft_;
132
136 uint32_t current_valid_lft_;
137
143 uint32_t reuseable_valid_lft_;
144
149 time_t cltt_;
150
155 time_t current_cltt_;
156
160 SubnetID subnet_id_;
161
165 uint32_t pool_id_;
166
170 std::string hostname_;
171
175 bool fqdn_fwd_;
176
180 bool fqdn_rev_;
181
185 HWAddrPtr hwaddr_;
186
196 uint32_t state_;
197
201 virtual std::string toText() const = 0;
202
205 bool expired() const;
206
211 bool stateExpiredReclaimed() const;
212
216 bool stateDeclined() const;
217
221 bool stateRegistered() const;
222
231 bool hasIdenticalFqdn(const Lease& other) const;
232
241 const std::vector<uint8_t>& getHWAddrVector() const;
242
247 int64_t getExpirationTime() const;
248
259 virtual void decline(uint32_t probation_period) = 0;
260
262 using isc::data::CfgToElement::toElement;
263
274 static void syncCurrentExpirationTime(const Lease& from, Lease& to);
275
283 void updateCurrentExpirationTime();
284
295 bool updateUserContextISC(const std::string elem_name,
296 data::ConstElementPtr new_values);
297protected:
298
307 static void fromElementCommon(const LeasePtr& lease,
308 const data::ConstElementPtr& element);
309
310};
311
312struct Lease4;
313
315 typedef boost::shared_ptr<Lease4> Lease4Ptr;
316
323 struct Lease4 : public Lease {
324
329 ClientIdPtr client_id_;
330
343 Lease4(const isc::asiolink::IOAddress& addr, const HWAddrPtr& hwaddr,
344 const uint8_t* clientid, size_t clientid_len, uint32_t valid_lft,
345 time_t cltt, uint32_t subnet_id,
346 const bool fqdn_fwd = false, const bool fqdn_rev = false,
347 const std::string& hostname = "")
348 : Lease(addr, valid_lft, subnet_id, cltt, fqdn_fwd, fqdn_rev,
349 hostname, hwaddr) {
350 if (clientid_len) {
351 client_id_.reset(new ClientId(clientid, clientid_len));
352 }
353 }
354
366 Lease4(const isc::asiolink::IOAddress& address,
367 const HWAddrPtr& hw_address,
368 const ClientIdPtr& client_id,
369 const uint32_t valid_lifetime,
370 const time_t cltt,
371 const SubnetID subnet_id,
372 const bool fqdn_fwd = false,
373 const bool fqdn_rev = false,
374 const std::string& hostname = "");
375
376
380 Lease4();
381
388 virtual Lease::Type getType() const {
389 return (Lease::TYPE_V4);
390 }
391
400 static std::string statesToText(const uint32_t state);
401
411 const std::vector<uint8_t>& getClientIdVector() const;
412
473 bool belongsToClient(const HWAddrPtr& hw_address,
474 const ClientIdPtr& client_id) const;
475
479 bool operator==(const Lease4& other) const;
480
484 bool operator!=(const Lease4& other) const {
485 return (!operator==(other));
486 }
487
491 virtual std::string toText() const;
492
498 void decline(uint32_t probation_period);
499
501 virtual isc::data::ElementPtr toElement() const;
502
508 static Lease4Ptr fromElement(const data::ConstElementPtr& element);
509
511
513 std::vector<uint8_t> remote_id_;
514
516 std::vector<uint8_t> relay_id_;
517};
518
520 typedef std::vector<Lease4Ptr> Lease4Collection;
521
523 typedef boost::shared_ptr<Lease4Collection> Lease4CollectionPtr;
524
525struct Lease6;
526
528 typedef boost::shared_ptr<Lease6> Lease6Ptr;
529
536 struct Lease6 : public Lease {
537
541 Lease::Type type_;
542
546 uint8_t prefixlen_;
547
553 uint32_t iaid_;
554
556 DuidPtr duid_;
557
562 uint32_t preferred_lft_;
563
570 uint32_t reuseable_preferred_lft_;
571
573 typedef enum {
574 ACTION_IGNORE,
575 ACTION_DELETE,
576 ACTION_UPDATE
577 } ExtendedInfoAction;
578
580 ExtendedInfoAction extended_info_action_;
581
583
594 Lease6(Lease::Type type, const isc::asiolink::IOAddress& addr, DuidPtr duid,
595 uint32_t iaid, uint32_t preferred, uint32_t valid,
596 SubnetID subnet_id, const HWAddrPtr& hwaddr = HWAddrPtr(),
597 uint8_t prefixlen = 128);
598
613 Lease6(Lease::Type type, const isc::asiolink::IOAddress& addr, DuidPtr duid,
614 uint32_t iaid, uint32_t preferred, uint32_t valid,
615 SubnetID subnet_id, const bool fqdn_fwd,
616 const bool fqdn_rev, const std::string& hostname,
617 const HWAddrPtr& hwaddr = HWAddrPtr(), uint8_t prefixlen = 128);
618
622 Lease6();
623
630 virtual Lease::Type getType() const {
631 return (type_);
632 }
633
642 static std::string statesToText(const uint32_t state);
643
652 const std::vector<uint8_t>& getDuidVector() const;
653
659 void decline(uint32_t probation_period);
660
664 bool operator==(const Lease6& other) const;
665
669 bool operator!=(const Lease6& other) const {
670 return (!operator==(other));
671 }
672
676 virtual std::string toText() const;
677
679 virtual isc::data::ElementPtr toElement() const;
680
686 static Lease6Ptr fromElement(const data::ConstElementPtr& element);
687};
688
690 typedef boost::shared_ptr<const Lease6> ConstLease6Ptr;
691
693 typedef std::vector<Lease6Ptr> Lease6Collection;
694
696 typedef boost::shared_ptr<Lease6Collection> Lease6CollectionPtr;
697
704std::ostream&
705 operator<<(std::ostream& os, const Lease& lease);
706
709namespace {
710
711template <isc::util::DhcpSpace D>
712struct AdapterLease {};
713
714template <>
715struct AdapterLease<isc::util::DHCPv4> {
716 using type = Lease4;
717};
718
719template <>
720struct AdapterLease<isc::util::DHCPv6> {
721 using type = Lease6;
722};
723
724} // namespace
725
726template <isc::util::DhcpSpace D>
727 using LeaseT = typename AdapterLease<D>::type;
728
729template <isc::util::DhcpSpace D>
730 using LeaseTPtr = boost::shared_ptr<LeaseT<D>>;
732
733} // end of isc::dhcp namespace
734} // end of isc namespace
735
736#endif // LEASE_H
cfg_to_element.h
isc::asiolink::IOAddress
The IOAddress class represents an IP addresses (version agnostic).
Definition io_address.h:53
isc::dhcp::ClientId
Holds Client identifier or client IPv4 address.
Definition duid.h:222
dhcp_space.h
duid.h
hwaddr.h
io_address.h
isc::asiolink::operator<<
std::ostream & operator<<(std::ostream &os, const IOAddress &address)
Insert the IOAddress as a string into stream.
Definition io_address.cc:131
isc::data::ConstElementPtr
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:30
isc::data::ElementPtr
boost::shared_ptr< Element > ElementPtr
Definition data.h:29
isc::dhcp
Definition dhcp4/client_handler.cc:20
isc::dhcp::Lease4CollectionPtr
boost::shared_ptr< Lease4Collection > Lease4CollectionPtr
A shared pointer to the collection of IPv4 leases.
Definition lease.h:523
isc::dhcp::DuidPtr
boost::shared_ptr< DUID > DuidPtr
Definition duid.h:136
isc::dhcp::Lease6Ptr
boost::shared_ptr< Lease6 > Lease6Ptr
Pointer to a Lease6 structure.
Definition lease.h:528
isc::dhcp::Lease6Collection
std::vector< Lease6Ptr > Lease6Collection
A collection of IPv6 leases.
Definition lease.h:693
isc::dhcp::LeaseTPtr
boost::shared_ptr< LeaseT< D > > LeaseTPtr
Definition lease.h:730
isc::dhcp::HWAddrPtr
boost::shared_ptr< HWAddr > HWAddrPtr
Shared pointer to a hardware address structure.
Definition hwaddr.h:154
isc::dhcp::SubnetID
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
Definition subnet_id.h:25
isc::dhcp::LeasePtr
boost::shared_ptr< Lease > LeasePtr
Pointer to the lease object.
Definition lease.h:25
isc::dhcp::ClientIdPtr
boost::shared_ptr< ClientId > ClientIdPtr
Shared pointer to a Client ID.
Definition duid.h:216
isc::dhcp::Lease6CollectionPtr
boost::shared_ptr< Lease6Collection > Lease6CollectionPtr
A shared pointer to the collection of IPv6 leases.
Definition lease.h:696
isc::dhcp::ConstLease6Ptr
boost::shared_ptr< const Lease6 > ConstLease6Ptr
Pointer to a const Lease6 structure.
Definition lease.h:690
isc::dhcp::LeaseT
typename AdapterLease< D >::type LeaseT
Definition lease.h:727
isc::dhcp::Lease4Collection
std::vector< Lease4Ptr > Lease4Collection
A collection of IPv4 leases.
Definition lease.h:520
isc::dhcp::Lease4Ptr
boost::shared_ptr< Lease4 > Lease4Ptr
Pointer to a Lease4 structure.
Definition lease.h:315
isc::util::DHCPv6
@ DHCPv6
Definition dhcp_space.h:19
isc::util::DHCPv4
@ DHCPv4
Definition dhcp_space.h:18
isc
Defines the logger used by the top-level component of kea-lfc.
Definition check_exists_add.cc:18
option.h
isc::data::CfgToElement
Abstract class for configuration Cfg_* classes.
Definition cfg_to_element.h:29
isc::data::CfgToElement::toElement
virtual isc::data::ElementPtr toElement() const =0
Unparse a configuration object.
isc::data::UserContext
Base class for user context.
Definition user_context.h:22
isc::dhcp::Lease4
Structure that holds a lease for IPv4 address.
Definition lease.h:323
isc::dhcp::Lease4::client_id_
ClientIdPtr client_id_
Client identifier.
Definition lease.h:329
isc::dhcp::Lease4::decline
void decline(uint32_t probation_period)
Sets IPv4 lease to declined state.
Definition lease.cc:380
isc::dhcp::Lease4::statesToText
static std::string statesToText(const uint32_t state)
Returns name of the lease states specific to DHCPv4.
Definition lease.cc:339
isc::dhcp::Lease4::Lease4
Lease4(const isc::asiolink::IOAddress &addr, const HWAddrPtr &hwaddr, const uint8_t *clientid, size_t clientid_len, uint32_t valid_lft, time_t cltt, uint32_t subnet_id, const bool fqdn_fwd=false, const bool fqdn_rev=false, const std::string &hostname="")
Constructor.
Definition lease.h:343
isc::dhcp::Lease4::operator==
bool operator==(const Lease4 &other) const
Compare two leases for equality.
Definition lease.cc:603
isc::dhcp::Lease4::getType
virtual Lease::Type getType() const
Returns Lease type.
Definition lease.h:388
isc::dhcp::Lease4::remote_id_
std::vector< uint8_t > remote_id_
Remote identifier for Bulk Lease Query.
Definition lease.h:513
isc::dhcp::Lease4::relay_id_
std::vector< uint8_t > relay_id_
Relay identifier for Bulk Lease Query.
Definition lease.h:516
isc::dhcp::Lease4::operator!=
bool operator!=(const Lease4 &other) const
Compare two leases for inequality.
Definition lease.h:484
isc::dhcp::Lease4::getClientIdVector
const std::vector< uint8_t > & getClientIdVector() const
Returns a client identifier.
Definition lease.cc:344
isc::dhcp::Lease4::toElement
virtual isc::data::ElementPtr toElement() const
Return the JSON representation of a lease.
Definition lease.cc:393
isc::dhcp::Lease4::belongsToClient
bool belongsToClient(const HWAddrPtr &hw_address, const ClientIdPtr &client_id) const
Check if the lease belongs to the client with the given identifiers.
Definition lease.cc:363
isc::dhcp::Lease4::Lease4
Lease4()
Default constructor.
Definition lease.cc:335
isc::dhcp::Lease4::toText
virtual std::string toText() const
Convert lease to printable form.
Definition lease.cc:579
isc::dhcp::Lease4::fromElement
static Lease4Ptr fromElement(const data::ConstElementPtr &element)
Returns pointer to the IPv4 lease created from JSON representation.
Definition lease.cc:421
isc::dhcp::Lease6
Structure that holds a lease for IPv6 address and/or prefix.
Definition lease.h:536
isc::dhcp::Lease6::extended_info_action_
ExtendedInfoAction extended_info_action_
Record the action on extended info tables in the lease.
Definition lease.h:580
isc::dhcp::Lease6::getDuidVector
const std::vector< uint8_t > & getDuidVector() const
Returns a reference to a vector representing a DUID.
Definition lease.cc:530
isc::dhcp::Lease6::getType
virtual Lease::Type getType() const
Returns Lease type.
Definition lease.h:630
isc::dhcp::Lease6::ExtendedInfoAction
ExtendedInfoAction
Action on extended info tables.
Definition lease.h:573
isc::dhcp::Lease6::ACTION_UPDATE
@ ACTION_UPDATE
update extended info tables.
Definition lease.h:576
isc::dhcp::Lease6::ACTION_DELETE
@ ACTION_DELETE
delete reference to the lease
Definition lease.h:575
isc::dhcp::Lease6::ACTION_IGNORE
@ ACTION_IGNORE
ignore extended info,
Definition lease.h:574
isc::dhcp::Lease6::toText
virtual std::string toText() const
Convert Lease to Printable Form.
Definition lease.cc:553
isc::dhcp::Lease6::Lease6
Lease6(Lease::Type type, const isc::asiolink::IOAddress &addr, DuidPtr duid, uint32_t iaid, uint32_t preferred, uint32_t valid, SubnetID subnet_id, const HWAddrPtr &hwaddr=HWAddrPtr(), uint8_t prefixlen=128)
Constructor.
Definition lease.cc:457
isc::dhcp::Lease6::operator==
bool operator==(const Lease6 &other) const
Compare two leases for equality.
Definition lease.cc:622
isc::dhcp::Lease6::statesToText
static std::string statesToText(const uint32_t state)
Returns name of the lease states specific to DHCPv6.
Definition lease.cc:525
isc::dhcp::Lease6::Lease6
Lease6()
Constructor.
Definition lease.cc:517
isc::dhcp::Lease6::type_
Lease::Type type_
Lease type.
Definition lease.h:541
isc::dhcp::Lease6::reuseable_preferred_lft_
uint32_t reuseable_preferred_lft_
Remaining preferred lifetime.
Definition lease.h:570
isc::dhcp::Lease6::operator!=
bool operator!=(const Lease6 &other) const
Compare two leases for inequality.
Definition lease.h:669
isc::dhcp::Lease6::iaid_
uint32_t iaid_
Identity Association Identifier (IAID).
Definition lease.h:553
isc::dhcp::Lease6::preferred_lft_
uint32_t preferred_lft_
Preferred lifetime.
Definition lease.h:562
isc::dhcp::Lease6::duid_
DuidPtr duid_
Client identifier.
Definition lease.h:556
isc::dhcp::Lease6::fromElement
static Lease6Ptr fromElement(const data::ConstElementPtr &element)
Returns pointer to the IPv6 lease created from JSON representation.
Definition lease.cc:680
isc::dhcp::Lease6::prefixlen_
uint8_t prefixlen_
IPv6 prefix length.
Definition lease.h:546
isc::dhcp::Lease6::toElement
virtual isc::data::ElementPtr toElement() const
Return the JSON representation of a lease.
Definition lease.cc:646
isc::dhcp::Lease6::decline
void decline(uint32_t probation_period)
Sets IPv6 lease to declined state.
Definition lease.cc:540
isc::dhcp::Lease
a common structure for IPv4 and IPv6 leases
Definition lease.h:31
isc::dhcp::Lease::updateCurrentExpirationTime
void updateCurrentExpirationTime()
Update lease current expiration time with new value, so that additional operations can be done withou...
Definition lease.cc:311
isc::dhcp::Lease::hasIdenticalFqdn
bool hasIdenticalFqdn(const Lease &other) const
Returns true if the other lease has equal FQDN data.
Definition lease.cc:136
isc::dhcp::Lease::decline
virtual void decline(uint32_t probation_period)=0
Sets lease to DECLINED state.
isc::dhcp::Lease::INFINITY_LFT
static const uint32_t INFINITY_LFT
Infinity (means static, i.e. never expire).
Definition lease.h:34
isc::dhcp::Lease::STATE_DEFAULT
static constexpr uint32_t STATE_DEFAULT
A lease in the default state.
Definition lease.h:69
isc::dhcp::Lease::~Lease
virtual ~Lease()
Destructor.
Definition lease.h:116
isc::dhcp::Lease::reuseable_valid_lft_
uint32_t reuseable_valid_lft_
Remaining valid lifetime.
Definition lease.h:143
isc::dhcp::Lease::lifetimeToText
static std::string lifetimeToText(uint32_t lifetime)
Print lifetime.
Definition lease.cc:34
isc::dhcp::Lease::STATE_EXPIRED_RECLAIMED
static constexpr uint32_t STATE_EXPIRED_RECLAIMED
Expired and reclaimed lease.
Definition lease.h:75
isc::dhcp::Lease::stateDeclined
bool stateDeclined() const
Indicates if the lease is in the "declined" state.
Definition lease.cc:121
isc::dhcp::Lease::stateExpiredReclaimed
bool stateExpiredReclaimed() const
Indicates if the lease is in the "expired-reclaimed" state.
Definition lease.cc:116
isc::dhcp::Lease::STATE_DECLINED
static constexpr uint32_t STATE_DECLINED
Declined lease.
Definition lease.h:72
isc::dhcp::Lease::STATE_REGISTERED
static constexpr uint32_t STATE_REGISTERED
Registered self-generated lease.
Definition lease.h:81
isc::dhcp::Lease::current_valid_lft_
uint32_t current_valid_lft_
Current valid lifetime.
Definition lease.h:136
isc::dhcp::Lease::subnet_id_
SubnetID subnet_id_
Subnet identifier.
Definition lease.h:160
isc::dhcp::Lease::pool_id_
uint32_t pool_id_
The pool id.
Definition lease.h:165
isc::dhcp::Lease::getHWAddrVector
const std::vector< uint8_t > & getHWAddrVector() const
Returns raw (as vector) hardware address.
Definition lease.cc:354
isc::dhcp::Lease::valid_lft_
uint32_t valid_lft_
Valid lifetime.
Definition lease.h:131
isc::dhcp::Lease::stateRegistered
bool stateRegistered() const
Indicates if the lease is in the "registered" state.
Definition lease.cc:126
isc::dhcp::Lease::basicStatesToText
static std::string basicStatesToText(const uint32_t state)
Returns name(s) of the basic lease state(s).
Definition lease.cc:89
isc::dhcp::Lease::expired
bool expired() const
returns true if the lease is expired
Definition lease.cc:111
isc::dhcp::Lease::STATE_RELEASED
static constexpr uint32_t STATE_RELEASED
Released lease held in the database for lease affinity.
Definition lease.h:78
isc::dhcp::Lease::Lease
Lease(const isc::asiolink::IOAddress &addr, uint32_t valid_lft, SubnetID subnet_id, time_t cltt, const bool fqdn_fwd, const bool fqdn_rev, const std::string &hostname, const HWAddrPtr &hwaddr)
Constructor.
Definition lease.cc:44
isc::dhcp::Lease::syncCurrentExpirationTime
static void syncCurrentExpirationTime(const Lease &from, Lease &to)
Sync lease current expiration time with new value from another lease, so that additional operations c...
Definition lease.cc:316
isc::dhcp::Lease::hostname_
std::string hostname_
Client hostname.
Definition lease.h:170
isc::dhcp::Lease::state_
uint32_t state_
Holds the lease state(s).
Definition lease.h:196
isc::dhcp::Lease::getType
virtual Lease::Type getType() const =0
Returns Lease type.
isc::dhcp::Lease::getExpirationTime
int64_t getExpirationTime() const
Returns lease expiration time.
Definition lease.cc:131
isc::dhcp::Lease::Type
Type
Type of lease or pool.
Definition lease.h:46
isc::dhcp::Lease::TYPE_TA
@ TYPE_TA
deprecated (temporary IPv6 address)
Definition lease.h:48
isc::dhcp::Lease::TYPE_PD
@ TYPE_PD
the lease contains IPv6 prefix (for prefix delegation)
Definition lease.h:49
isc::dhcp::Lease::TYPE_V4
@ TYPE_V4
IPv4 lease.
Definition lease.h:50
isc::dhcp::Lease::TYPE_NA
@ TYPE_NA
the lease contains non-temporary IPv6 address
Definition lease.h:47
isc::dhcp::Lease::fqdn_fwd_
bool fqdn_fwd_
Forward zone updated?
Definition lease.h:175
isc::dhcp::Lease::cltt_
time_t cltt_
Client last transmission time.
Definition lease.h:149
isc::dhcp::Lease::updateUserContextISC
bool updateUserContextISC(const std::string elem_name, data::ConstElementPtr new_values)
Update the ISC entry in the lease's user-context.
Definition lease.cc:765
isc::dhcp::Lease::toText
virtual std::string toText() const =0
Convert Lease to Printable Form.
isc::dhcp::Lease::fromElementCommon
static void fromElementCommon(const LeasePtr &lease, const data::ConstElementPtr &element)
Sets common (for v4 and v6) properties of the lease object.
Definition lease.cc:143
isc::dhcp::Lease::typeToText
static std::string typeToText(Type type)
returns text representation of a lease type
Definition lease.cc:56
isc::dhcp::Lease::textToType
static Type textToType(const std::string &text)
Converts type name to the actual type.
Definition lease.cc:74
isc::dhcp::Lease::hwaddr_
HWAddrPtr hwaddr_
Client's MAC/hardware address.
Definition lease.h:185
isc::dhcp::Lease::fqdn_rev_
bool fqdn_rev_
Reverse zone updated?
Definition lease.h:180
isc::dhcp::Lease::addr_
isc::asiolink::IOAddress addr_
IPv4 ot IPv6 address.
Definition lease.h:126
isc::dhcp::Lease::current_cltt_
time_t current_cltt_
Current client last transmission time.
Definition lease.h:155
subnet_id.h
user_context.h