Kea 2.7.1
lease.h
Go to the documentation of this file.
1// Copyright (C) 2013-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#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
25typedef boost::shared_ptr<Lease> LeasePtr;
26
32
34 static const uint32_t INFINITY_LFT = 0xffffffff;
35
43 static std::string lifetimeToText(uint32_t lifetime);
44
46 typedef enum {
47 TYPE_NA = 0,
48 TYPE_TA = 1,
49 TYPE_PD = 2,
50 TYPE_V4 = 3
52
56 static std::string typeToText(Type type);
57
63 static Type textToType(const std::string& text);
64
66
67
69 static const uint32_t STATE_DEFAULT;
70
72 static const uint32_t STATE_DECLINED;
73
75 static const uint32_t STATE_EXPIRED_RECLAIMED;
76
78 static const uint32_t STATE_RELEASED;
79
87 static std::string basicStatesToText(const uint32_t state);
88
107 uint32_t valid_lft, SubnetID subnet_id, time_t cltt,
108 const bool fqdn_fwd, const bool fqdn_rev,
109 const std::string& hostname,
110 const HWAddrPtr& hwaddr);
111
113 virtual ~Lease() {}
114
118 virtual Lease::Type getType() const = 0;
119
124
128 uint32_t valid_lft_;
129
134
141
146 time_t cltt_;
147
153
158
162 uint32_t pool_id_;
163
167 std::string hostname_;
168
173
178
183
193 uint32_t state_;
194
198 virtual std::string toText() const = 0;
199
202 bool expired() const;
203
208 bool stateExpiredReclaimed() const;
209
213 bool stateDeclined() const;
214
223 bool hasIdenticalFqdn(const Lease& other) const;
224
233 const std::vector<uint8_t>& getHWAddrVector() const;
234
239 int64_t getExpirationTime() const;
240
251 virtual void decline(uint32_t probation_period) = 0;
252
255
266 static void syncCurrentExpirationTime(const Lease& from, Lease& to);
267
276
277protected:
278
287 static void fromElementCommon(const LeasePtr& lease,
288 const data::ConstElementPtr& element);
289
290};
291
292struct Lease4;
293
295typedef boost::shared_ptr<Lease4> Lease4Ptr;
296
303struct Lease4 : public Lease {
304
310
323 Lease4(const isc::asiolink::IOAddress& addr, const HWAddrPtr& hwaddr,
324 const uint8_t* clientid, size_t clientid_len, uint32_t valid_lft,
325 time_t cltt, uint32_t subnet_id,
326 const bool fqdn_fwd = false, const bool fqdn_rev = false,
327 const std::string& hostname = "")
328 : Lease(addr, valid_lft, subnet_id, cltt, fqdn_fwd, fqdn_rev,
329 hostname, hwaddr) {
330 if (clientid_len) {
331 client_id_.reset(new ClientId(clientid, clientid_len));
332 }
333 }
334
346 Lease4(const isc::asiolink::IOAddress& address,
347 const HWAddrPtr& hw_address,
348 const ClientIdPtr& client_id,
349 const uint32_t valid_lifetime,
350 const time_t cltt,
351 const SubnetID subnet_id,
352 const bool fqdn_fwd = false,
353 const bool fqdn_rev = false,
354 const std::string& hostname = "");
355
356
360 Lease4();
361
368 virtual Lease::Type getType() const {
369 return (Lease::TYPE_V4);
370 }
371
380 static std::string statesToText(const uint32_t state);
381
391 const std::vector<uint8_t>& getClientIdVector() const;
392
453 bool belongsToClient(const HWAddrPtr& hw_address,
454 const ClientIdPtr& client_id) const;
455
459 bool operator==(const Lease4& other) const;
460
464 bool operator!=(const Lease4& other) const {
465 return (!operator==(other));
466 }
467
471 virtual std::string toText() const;
472
478 void decline(uint32_t probation_period);
479
481 virtual isc::data::ElementPtr toElement() const;
482
488 static Lease4Ptr fromElement(const data::ConstElementPtr& element);
489
491
493 std::vector<uint8_t> remote_id_;
494
496 std::vector<uint8_t> relay_id_;
497};
498
500typedef std::vector<Lease4Ptr> Lease4Collection;
501
503typedef boost::shared_ptr<Lease4Collection> Lease4CollectionPtr;
504
505struct Lease6;
506
508typedef boost::shared_ptr<Lease6> Lease6Ptr;
509
516struct Lease6 : public Lease {
517
522
526 uint8_t prefixlen_;
527
533 uint32_t iaid_;
534
537
543
551
558
561
563
574 Lease6(Lease::Type type, const isc::asiolink::IOAddress& addr, DuidPtr duid,
575 uint32_t iaid, uint32_t preferred, uint32_t valid,
576 SubnetID subnet_id, const HWAddrPtr& hwaddr = HWAddrPtr(),
577 uint8_t prefixlen = 128);
578
593 Lease6(Lease::Type type, const isc::asiolink::IOAddress& addr, DuidPtr duid,
594 uint32_t iaid, uint32_t preferred, uint32_t valid,
595 SubnetID subnet_id, const bool fqdn_fwd,
596 const bool fqdn_rev, const std::string& hostname,
597 const HWAddrPtr& hwaddr = HWAddrPtr(), uint8_t prefixlen = 128);
598
602 Lease6();
603
610 virtual Lease::Type getType() const {
611 return (type_);
612 }
613
622 static std::string statesToText(const uint32_t state);
623
632 const std::vector<uint8_t>& getDuidVector() const;
633
639 void decline(uint32_t probation_period);
640
644 bool operator==(const Lease6& other) const;
645
649 bool operator!=(const Lease6& other) const {
650 return (!operator==(other));
651 }
652
656 virtual std::string toText() const;
657
659 virtual isc::data::ElementPtr toElement() const;
660
666 static Lease6Ptr fromElement(const data::ConstElementPtr& element);
667};
668
670typedef boost::shared_ptr<const Lease6> ConstLease6Ptr;
671
673typedef std::vector<Lease6Ptr> Lease6Collection;
674
676typedef boost::shared_ptr<Lease6Collection> Lease6CollectionPtr;
677
684std::ostream&
685operator<<(std::ostream& os, const Lease& lease);
686
689namespace {
690
691template <isc::util::DhcpSpace D>
692struct AdapterLease {};
693
694template <>
695struct AdapterLease<isc::util::DHCPv4> {
696 using type = Lease4;
697};
698
699template <>
700struct AdapterLease<isc::util::DHCPv6> {
701 using type = Lease6;
702};
703
704} // namespace
705
706template <isc::util::DhcpSpace D>
707using LeaseT = typename AdapterLease<D>::type;
708
709template <isc::util::DhcpSpace D>
710using LeaseTPtr = boost::shared_ptr<LeaseT<D>>;
712
713} // end of isc::dhcp namespace
714} // end of isc namespace
715
716#endif // LEASE_H
Holds Client identifier or client IPv4 address.
Definition duid.h:222
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:29
boost::shared_ptr< Element > ElementPtr
Definition data.h:28
boost::shared_ptr< Lease4Collection > Lease4CollectionPtr
A shared pointer to the collection of IPv4 leases.
Definition lease.h:503
boost::shared_ptr< DUID > DuidPtr
Definition duid.h:136
boost::shared_ptr< Lease6 > Lease6Ptr
Pointer to a Lease6 structure.
Definition lease.h:508
std::vector< Lease6Ptr > Lease6Collection
A collection of IPv6 leases.
Definition lease.h:673
boost::shared_ptr< LeaseT< D > > LeaseTPtr
Definition lease.h:710
boost::shared_ptr< HWAddr > HWAddrPtr
Shared pointer to a hardware address structure.
Definition hwaddr.h:154
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
Definition subnet_id.h:25
boost::shared_ptr< Lease > LeasePtr
Pointer to the lease object.
Definition lease.h:25
boost::shared_ptr< ClientId > ClientIdPtr
Shared pointer to a Client ID.
Definition duid.h:216
boost::shared_ptr< Lease6Collection > Lease6CollectionPtr
A shared pointer to the collection of IPv6 leases.
Definition lease.h:676
boost::shared_ptr< const Lease6 > ConstLease6Ptr
Pointer to a const Lease6 structure.
Definition lease.h:670
typename AdapterLease< D >::type LeaseT
Definition lease.h:707
std::vector< Lease4Ptr > Lease4Collection
A collection of IPv4 leases.
Definition lease.h:500
boost::shared_ptr< Lease4 > Lease4Ptr
Pointer to a Lease4 structure.
Definition lease.h:295
Defines the logger used by the top-level component of kea-lfc.
Abstract class for configuration Cfg_* classes.
virtual isc::data::ElementPtr toElement() const =0
Unparse a configuration object.
Base class for user context.
Structure that holds a lease for IPv4 address.
Definition lease.h:303
ClientIdPtr client_id_
Client identifier.
Definition lease.h:309
void decline(uint32_t probation_period)
Sets IPv4 lease to declined state.
Definition lease.cc:377
static std::string statesToText(const uint32_t state)
Returns name of the lease states specific to DHCPv4.
Definition lease.cc:336
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:323
bool operator==(const Lease4 &other) const
Compare two leases for equality.
Definition lease.cc:585
virtual Lease::Type getType() const
Returns Lease type.
Definition lease.h:368
std::vector< uint8_t > remote_id_
Remote identifier for Bulk Lease Query.
Definition lease.h:493
std::vector< uint8_t > relay_id_
Relay identifier for Bulk Lease Query.
Definition lease.h:496
bool operator!=(const Lease4 &other) const
Compare two leases for inequality.
Definition lease.h:464
const std::vector< uint8_t > & getClientIdVector() const
Returns a client identifier.
Definition lease.cc:341
virtual isc::data::ElementPtr toElement() const
Return the JSON representation of a lease.
Definition lease.cc:389
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:360
Lease4()
Default constructor.
Definition lease.cc:332
virtual std::string toText() const
Convert lease to printable form.
Definition lease.cc:561
static Lease4Ptr fromElement(const data::ConstElementPtr &element)
Returns pointer to the IPv4 lease created from JSON representation.
Definition lease.cc:417
Structure that holds a lease for IPv6 address and/or prefix.
Definition lease.h:516
ExtendedInfoAction extended_info_action_
Record the action on extended info tables in the lease.
Definition lease.h:560
const std::vector< uint8_t > & getDuidVector() const
Returns a reference to a vector representing a DUID.
Definition lease.cc:512
virtual Lease::Type getType() const
Returns Lease type.
Definition lease.h:610
ExtendedInfoAction
Action on extended info tables.
Definition lease.h:553
@ ACTION_UPDATE
update extended info tables.
Definition lease.h:556
@ ACTION_DELETE
delete reference to the lease
Definition lease.h:555
@ ACTION_IGNORE
ignore extended info,
Definition lease.h:554
virtual std::string toText() const
Convert Lease to Printable Form.
Definition lease.cc:535
bool operator==(const Lease6 &other) const
Compare two leases for equality.
Definition lease.cc:604
static std::string statesToText(const uint32_t state)
Returns name of the lease states specific to DHCPv6.
Definition lease.cc:507
Lease6()
Constructor.
Definition lease.cc:499
Lease::Type type_
Lease type.
Definition lease.h:521
uint32_t reuseable_preferred_lft_
Remaining preferred lifetime.
Definition lease.h:550
bool operator!=(const Lease6 &other) const
Compare two leases for inequality.
Definition lease.h:649
uint32_t iaid_
Identity Association Identifier (IAID)
Definition lease.h:533
uint32_t preferred_lft_
Preferred lifetime.
Definition lease.h:542
DuidPtr duid_
Client identifier.
Definition lease.h:536
static Lease6Ptr fromElement(const data::ConstElementPtr &element)
Returns pointer to the IPv6 lease created from JSON representation.
Definition lease.cc:662
uint8_t prefixlen_
IPv6 prefix length.
Definition lease.h:526
virtual isc::data::ElementPtr toElement() const
Return the JSON representation of a lease.
Definition lease.cc:628
void decline(uint32_t probation_period)
Sets IPv6 lease to declined state.
Definition lease.cc:522
a common structure for IPv4 and IPv6 leases
Definition lease.h:31
void updateCurrentExpirationTime()
Update lease current expiration time with new value, so that additional operations can be done withou...
Definition lease.cc:308
bool hasIdenticalFqdn(const Lease &other) const
Returns true if the other lease has equal FQDN data.
Definition lease.cc:133
virtual void decline(uint32_t probation_period)=0
Sets lease to DECLINED state.
static const uint32_t INFINITY_LFT
Infinity (means static, i.e. never expire)
Definition lease.h:34
virtual ~Lease()
Destructor.
Definition lease.h:113
uint32_t reuseable_valid_lft_
Remaining valid lifetime.
Definition lease.h:140
static std::string lifetimeToText(uint32_t lifetime)
Print lifetime.
Definition lease.cc:33
bool stateDeclined() const
Indicates if the lease is in the "declined" state.
Definition lease.cc:123
bool stateExpiredReclaimed() const
Indicates if the lease is in the "expired-reclaimed" state.
Definition lease.cc:118
static const uint32_t STATE_DEFAULT
A lease in the default state.
Definition lease.h:69
uint32_t current_valid_lft_
Current valid lifetime.
Definition lease.h:133
SubnetID subnet_id_
Subnet identifier.
Definition lease.h:157
uint32_t pool_id_
The pool id.
Definition lease.h:162
const std::vector< uint8_t > & getHWAddrVector() const
Returns raw (as vector) hardware address.
Definition lease.cc:351
uint32_t valid_lft_
Valid lifetime.
Definition lease.h:128
static std::string basicStatesToText(const uint32_t state)
Returns name(s) of the basic lease state(s).
Definition lease.cc:93
static const uint32_t STATE_DECLINED
Declined lease.
Definition lease.h:72
bool expired() const
returns true if the lease is expired
Definition lease.cc:113
static const uint32_t STATE_RELEASED
Released lease held in the database for lease affinity.
Definition lease.h:78
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:43
static const uint32_t STATE_EXPIRED_RECLAIMED
Expired and reclaimed lease.
Definition lease.h:75
Type
Type of lease or pool.
Definition lease.h:46
@ TYPE_TA
the lease contains temporary IPv6 address
Definition lease.h:48
@ TYPE_PD
the lease contains IPv6 prefix (for prefix delegation)
Definition lease.h:49
@ TYPE_V4
IPv4 lease.
Definition lease.h:50
@ TYPE_NA
the lease contains non-temporary IPv6 address
Definition lease.h:47
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:313
std::string hostname_
Client hostname.
Definition lease.h:167
uint32_t state_
Holds the lease state(s).
Definition lease.h:193
virtual Lease::Type getType() const =0
Returns Lease type.
int64_t getExpirationTime() const
Returns lease expiration time.
Definition lease.cc:128
bool fqdn_fwd_
Forward zone updated?
Definition lease.h:172
time_t cltt_
Client last transmission time.
Definition lease.h:146
virtual std::string toText() const =0
Convert Lease to Printable Form.
static void fromElementCommon(const LeasePtr &lease, const data::ConstElementPtr &element)
Sets common (for v4 and v6) properties of the lease object.
Definition lease.cc:140
static std::string typeToText(Type type)
returns text representation of a lease type
Definition lease.cc:55
static Type textToType(const std::string &text)
Converts type name to the actual type.
Definition lease.cc:75
HWAddrPtr hwaddr_
Client's MAC/hardware address.
Definition lease.h:182
bool fqdn_rev_
Reverse zone updated?
Definition lease.h:177
isc::asiolink::IOAddress addr_
IPv4 ot IPv6 address.
Definition lease.h:123
time_t current_cltt_
Current client last transmission time.
Definition lease.h:152