Kea 2.0.1
lease.h
Go to the documentation of this file.
1// Copyright (C) 2013-2021 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 <cc/user_context.h>
15#include <cc/cfg_to_element.h>
16
17namespace isc {
18namespace dhcp {
19
24typedef uint32_t SubnetID;
25
26struct Lease;
27
29typedef boost::shared_ptr<Lease> LeasePtr;
30
36
38 static const uint32_t INFINITY_LFT = 0xffffffff;
39
47 static std::string lifetimeToText(uint32_t lifetime);
48
50 typedef enum {
51 TYPE_NA = 0,
52 TYPE_TA = 1,
53 TYPE_PD = 2,
54 TYPE_V4 = 3
56
60 static std::string typeToText(Type type);
61
67 static Type textToType(const std::string& text);
68
70
71
73 static const uint32_t STATE_DEFAULT;
74
76 static const uint32_t STATE_DECLINED;
77
79 static const uint32_t STATE_EXPIRED_RECLAIMED;
80
88 static std::string basicStatesToText(const uint32_t state);
89
108 uint32_t valid_lft, SubnetID subnet_id, time_t cltt,
109 const bool fqdn_fwd, const bool fqdn_rev,
110 const std::string& hostname,
111 const HWAddrPtr& hwaddr);
112
114 virtual ~Lease() {}
115
120
124 uint32_t valid_lft_;
125
130
137
142 time_t cltt_;
143
149
154
158 std::string hostname_;
159
164
169
174
184 uint32_t state_;
185
189 virtual std::string toText() const = 0;
190
193 bool expired() const;
194
199 bool stateExpiredReclaimed() const;
200
204 bool stateDeclined() const;
205
214 bool hasIdenticalFqdn(const Lease& other) const;
215
224 const std::vector<uint8_t>& getHWAddrVector() const;
225
230 int64_t getExpirationTime() const;
231
242 virtual void decline(uint32_t probation_period) = 0;
243
246
257 static void syncCurrentExpirationTime(const Lease& from, Lease& to);
258
267
268protected:
269
278 static void fromElementCommon(const LeasePtr& lease,
279 const data::ConstElementPtr& element);
280
281};
282
283struct Lease4;
284
286typedef boost::shared_ptr<Lease4> Lease4Ptr;
287
294struct Lease4 : public Lease {
295
301
314 Lease4(const isc::asiolink::IOAddress& addr, const HWAddrPtr& hwaddr,
315 const uint8_t* clientid, size_t clientid_len, uint32_t valid_lft,
316 time_t cltt, uint32_t subnet_id,
317 const bool fqdn_fwd = false, const bool fqdn_rev = false,
318 const std::string& hostname = "")
319 : Lease(addr, valid_lft, subnet_id, cltt, fqdn_fwd, fqdn_rev,
320 hostname, hwaddr) {
321 if (clientid_len) {
322 client_id_.reset(new ClientId(clientid, clientid_len));
323 }
324 }
325
337 Lease4(const isc::asiolink::IOAddress& address,
338 const HWAddrPtr& hw_address,
339 const ClientIdPtr& client_id,
340 const uint32_t valid_lifetime,
341 const time_t cltt,
342 const SubnetID subnet_id,
343 const bool fqdn_fwd = false,
344 const bool fqdn_rev = false,
345 const std::string& hostname = "");
346
347
351 Lease4() : Lease(0, 0, 0, 0, false, false, "", HWAddrPtr())
352 {
353 }
354
358 Lease4(const Lease4& other);
359
368 static std::string statesToText(const uint32_t state);
369
379 const std::vector<uint8_t>& getClientIdVector() const;
380
441 bool belongsToClient(const HWAddrPtr& hw_address,
442 const ClientIdPtr& client_id) const;
443
447 Lease4& operator=(const Lease4& other);
448
452 bool operator==(const Lease4& other) const;
453
457 bool operator!=(const Lease4& other) const {
458 return (!operator==(other));
459 }
460
464 virtual std::string toText() const;
465
471 void decline(uint32_t probation_period);
472
474 virtual isc::data::ElementPtr toElement() const;
475
481 static Lease4Ptr fromElement(const data::ConstElementPtr& element);
482
484};
485
487typedef std::vector<Lease4Ptr> Lease4Collection;
488
490typedef boost::shared_ptr<Lease4Collection> Lease4CollectionPtr;
491
492struct Lease6;
493
495typedef boost::shared_ptr<Lease6> Lease6Ptr;
496
503struct Lease6 : public Lease {
504
509
513 uint8_t prefixlen_;
514
520 uint32_t iaid_;
521
524
530
538
540
551 Lease6(Lease::Type type, const isc::asiolink::IOAddress& addr, DuidPtr duid,
552 uint32_t iaid, uint32_t preferred, uint32_t valid,
553 SubnetID subnet_id, const HWAddrPtr& hwaddr = HWAddrPtr(),
554 uint8_t prefixlen = 128);
555
570 Lease6(Lease::Type type, const isc::asiolink::IOAddress& addr, DuidPtr duid,
571 uint32_t iaid, uint32_t preferred, uint32_t valid,
572 SubnetID subnet_id, const bool fqdn_fwd,
573 const bool fqdn_rev, const std::string& hostname,
574 const HWAddrPtr& hwaddr = HWAddrPtr(), uint8_t prefixlen = 128);
575
579 Lease6();
580
589 static std::string statesToText(const uint32_t state);
590
599 const std::vector<uint8_t>& getDuidVector() const;
600
606 void decline(uint32_t probation_period);
607
611 bool operator==(const Lease6& other) const;
612
616 bool operator!=(const Lease6& other) const {
617 return (!operator==(other));
618 }
619
623 virtual std::string toText() const;
624
626 virtual isc::data::ElementPtr toElement() const;
627
633 static Lease6Ptr fromElement(const data::ConstElementPtr& element);
634};
635
637typedef boost::shared_ptr<const Lease6> ConstLease6Ptr;
638
640typedef std::vector<Lease6Ptr> Lease6Collection;
641
642
644typedef boost::shared_ptr<Lease6Collection> Lease6CollectionPtr;
645
652std::ostream&
653operator<<(std::ostream& os, const Lease& lease);
654
655}; // end of isc::dhcp namespace
656}; // end of isc namespace
657
658#endif // LEASE_H
Holds Client identifier or client IPv4 address.
Definition: duid.h:111
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:27
boost::shared_ptr< Element > ElementPtr
Definition: data.h:24
boost::shared_ptr< Lease4Collection > Lease4CollectionPtr
A shared pointer to the collection of IPv4 leases.
Definition: lease.h:490
boost::shared_ptr< DUID > DuidPtr
Definition: duid.h:20
boost::shared_ptr< Lease6 > Lease6Ptr
Pointer to a Lease6 structure.
Definition: lease.h:492
std::vector< Lease6Ptr > Lease6Collection
A collection of IPv6 leases.
Definition: lease.h:640
std::ostream & operator<<(std::ostream &os, const OpaqueDataTuple &tuple)
Inserts the OpaqueDataTuple as a string into stream.
boost::shared_ptr< HWAddr > HWAddrPtr
Shared pointer to a hardware address structure.
Definition: hwaddr.h:154
uint32_t SubnetID
Unique identifier for a subnet (both v4 and v6)
Definition: lease.h:24
boost::shared_ptr< Lease > LeasePtr
Pointer to the lease object.
Definition: lease.h:26
boost::shared_ptr< ClientId > ClientIdPtr
Shared pointer to a Client ID.
Definition: duid.h:103
boost::shared_ptr< Lease6Collection > Lease6CollectionPtr
A shared pointer to the collection of IPv6 leases.
Definition: lease.h:644
boost::shared_ptr< const Lease6 > ConstLease6Ptr
Pointer to a const Lease6 structure.
Definition: lease.h:637
std::vector< Lease4Ptr > Lease4Collection
A collection of IPv4 leases.
Definition: lease.h:487
boost::shared_ptr< Lease4 > Lease4Ptr
Pointer to a Lease4 structure.
Definition: lease.h:283
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.
Definition: user_context.h:22
Structure that holds a lease for IPv4 address.
Definition: lease.h:294
ClientIdPtr client_id_
Client identifier.
Definition: lease.h:300
void decline(uint32_t probation_period)
Sets IPv4 lease to declined state.
Definition: lease.cc:378
static std::string statesToText(const uint32_t state)
Returns name of the lease states specific to DHCPv4.
Definition: lease.cc:337
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:314
bool operator==(const Lease4 &other) const
Compare two leases for equality.
Definition: lease.cc:598
bool operator!=(const Lease4 &other) const
Compare two leases for inequality.
Definition: lease.h:457
const std::vector< uint8_t > & getClientIdVector() const
Returns a client identifier.
Definition: lease.cc:342
virtual isc::data::ElementPtr toElement() const
Return the JSON representation of a lease.
Definition: lease.cc:425
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:361
Lease4()
Default constructor.
Definition: lease.h:351
Lease4 & operator=(const Lease4 &other)
Assignment operator.
Definition: lease.cc:390
virtual std::string toText() const
Convert lease to printable form.
Definition: lease.cc:578
static Lease4Ptr fromElement(const data::ConstElementPtr &element)
Returns pointer to the IPv4 lease created from JSON representation.
Definition: lease.cc:450
Structure that holds a lease for IPv6 address and/or prefix.
Definition: lease.h:503
const std::vector< uint8_t > & getDuidVector() const
Returns a reference to a vector representing a DUID.
Definition: lease.cc:530
virtual std::string toText() const
Convert Lease to Printable Form.
Definition: lease.cc:553
bool operator==(const Lease6 &other) const
Compare two leases for equality.
Definition: lease.cc:616
static std::string statesToText(const uint32_t state)
Returns name of the lease states specific to DHCPv6.
Definition: lease.cc:525
Lease6()
Constructor.
Definition: lease.cc:518
Lease::Type type_
Lease type.
Definition: lease.h:508
uint32_t reuseable_preferred_lft_
Remaining preferred lifetime.
Definition: lease.h:537
bool operator!=(const Lease6 &other) const
Compare two leases for inequality.
Definition: lease.h:616
uint32_t iaid_
Identity Association Identifier (IAID)
Definition: lease.h:520
uint32_t preferred_lft_
Preferred lifetime.
Definition: lease.h:529
DuidPtr duid_
Client identifier.
Definition: lease.h:523
static Lease6Ptr fromElement(const data::ConstElementPtr &element)
Returns pointer to the IPv6 lease created from JSON representation.
Definition: lease.cc:670
uint8_t prefixlen_
IPv6 prefix length.
Definition: lease.h:513
virtual isc::data::ElementPtr toElement() const
Return the JSON representation of a lease.
Definition: lease.cc:639
void decline(uint32_t probation_period)
Sets IPv6 lease to declined state.
Definition: lease.cc:540
a common structure for IPv4 and IPv6 leases
Definition: lease.h:35
void updateCurrentExpirationTime()
Update lease current expiration time with new value, so that additional operations can be done withou...
Definition: lease.cc:283
bool hasIdenticalFqdn(const Lease &other) const
Returns true if the other lease has equal FQDN data.
Definition: lease.cc:128
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:38
virtual ~Lease()
Destructor.
Definition: lease.h:114
uint32_t reuseable_valid_lft_
Remaining valid lifetime.
Definition: lease.h:136
static std::string lifetimeToText(uint32_t lifetime)
Print lifetime.
Definition: lease.cc:29
bool stateDeclined() const
Indicates if the lease is in the "declined" state.
Definition: lease.cc:118
bool stateExpiredReclaimed() const
Indicates if the lease is in the "expired-reclaimed" state.
Definition: lease.cc:113
static const uint32_t STATE_DEFAULT
A lease in the default state.
Definition: lease.h:73
uint32_t current_valid_lft_
Current valid lifetime.
Definition: lease.h:129
SubnetID subnet_id_
Subnet identifier.
Definition: lease.h:153
const std::vector< uint8_t > & getHWAddrVector() const
Returns raw (as vector) hardware address.
Definition: lease.cc:352
uint32_t valid_lft_
Valid lifetime.
Definition: lease.h:124
static std::string basicStatesToText(const uint32_t state)
Returns name(s) of the basic lease state(s).
Definition: lease.cc:90
static const uint32_t STATE_DECLINED
Declined lease.
Definition: lease.h:76
bool expired() const
returns true if the lease is expired
Definition: lease.cc:108
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:39
static const uint32_t STATE_EXPIRED_RECLAIMED
Expired and reclaimed lease.
Definition: lease.h:79
Type
Type of lease or pool.
Definition: lease.h:50
@ TYPE_TA
the lease contains temporary IPv6 address
Definition: lease.h:52
@ TYPE_PD
the lease contains IPv6 prefix (for prefix delegation)
Definition: lease.h:53
@ TYPE_V4
IPv4 lease.
Definition: lease.h:54
@ TYPE_NA
the lease contains non-temporary IPv6 address
Definition: lease.h:51
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:288
std::string hostname_
Client hostname.
Definition: lease.h:158
uint32_t state_
Holds the lease state(s).
Definition: lease.h:184
int64_t getExpirationTime() const
Returns lease expiration time.
Definition: lease.cc:123
bool fqdn_fwd_
Forward zone updated?
Definition: lease.h:163
time_t cltt_
Client last transmission time.
Definition: lease.h:142
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:135
static std::string typeToText(Type type)
returns text representation of a lease type
Definition: lease.cc:52
static Type textToType(const std::string &text)
Converts type name to the actual type.
Definition: lease.cc:72
HWAddrPtr hwaddr_
Client's MAC/hardware address.
Definition: lease.h:173
bool fqdn_rev_
Reverse zone updated?
Definition: lease.h:168
isc::asiolink::IOAddress addr_
IPv4 ot IPv6 address.
Definition: lease.h:119
time_t current_cltt_
Current client last transmission time.
Definition: lease.h:148