Kea 1.5.0
lease.h
Go to the documentation of this file.
1// Copyright (C) 2013-2018 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 typedef enum {
39 TYPE_NA = 0,
40 TYPE_TA = 1,
41 TYPE_PD = 2,
42 TYPE_V4 = 3
44
48 static std::string typeToText(Type type);
49
55 static Type textToType(const std::string& text);
56
58
59
61 static const uint32_t STATE_DEFAULT;
62
64 static const uint32_t STATE_DECLINED;
65
67 static const uint32_t STATE_EXPIRED_RECLAIMED;
68
76 static std::string basicStatesToText(const uint32_t state);
77
90 Lease(const isc::asiolink::IOAddress& addr, uint32_t t1, uint32_t t2,
91 uint32_t valid_lft, SubnetID subnet_id, time_t cltt,
92 const bool fqdn_fwd, const bool fqdn_rev,
93 const std::string& hostname,
94 const HWAddrPtr& hwaddr);
95
97 virtual ~Lease() {}
98
103
111 uint32_t t1_;
112
120 uint32_t t2_;
121
125 uint32_t valid_lft_;
126
131 time_t cltt_;
132
137
141 std::string hostname_;
142
147
152
157
167 uint32_t state_;
168
172 virtual std::string toText() const = 0;
173
176 bool expired() const;
177
182 bool stateExpiredReclaimed() const;
183
187 bool stateDeclined() const;
188
197 bool hasIdenticalFqdn(const Lease& other) const;
198
207 const std::vector<uint8_t>& getHWAddrVector() const;
208
213 int64_t getExpirationTime() const;
214
225 virtual void decline(uint32_t probation_period) = 0;
226
229
230protected:
231
240 static void fromElementCommon(const LeasePtr& lease,
241 const data::ConstElementPtr& element);
242
243};
244
245struct Lease4;
246
248typedef boost::shared_ptr<Lease4> Lease4Ptr;
249
256struct Lease4 : public Lease {
257
263
278 Lease4(const isc::asiolink::IOAddress& addr, const HWAddrPtr& hwaddr,
279 const uint8_t* clientid, size_t clientid_len, uint32_t valid_lft,
280 uint32_t t1, uint32_t t2, time_t cltt, uint32_t subnet_id,
281 const bool fqdn_fwd = false, const bool fqdn_rev = false,
282 const std::string& hostname = "")
283 : Lease(addr, t1, t2, valid_lft, subnet_id, cltt, fqdn_fwd, fqdn_rev,
284 hostname, hwaddr) {
285 if (clientid_len) {
286 client_id_.reset(new ClientId(clientid, clientid_len));
287 }
288 }
289
303 Lease4(const isc::asiolink::IOAddress& address,
304 const HWAddrPtr& hw_address,
305 const ClientIdPtr& client_id,
306 const uint32_t valid_lifetime,
307 const uint32_t t1,
308 const uint32_t t2,
309 const time_t cltt,
310 const SubnetID subnet_id,
311 const bool fqdn_fwd = false,
312 const bool fqdn_rev = false,
313 const std::string& hostname = "");
314
315
319 Lease4() : Lease(0, 0, 0, 0, 0, 0, false, false, "", HWAddrPtr())
320 {
321 }
322
326 Lease4(const Lease4& other);
327
336 static std::string statesToText(const uint32_t state);
337
347 const std::vector<uint8_t>& getClientIdVector() const;
348
409 bool belongsToClient(const HWAddrPtr& hw_address,
410 const ClientIdPtr& client_id) const;
411
415 Lease4& operator=(const Lease4& other);
416
420 bool operator==(const Lease4& other) const;
421
425 bool operator!=(const Lease4& other) const {
426 return (!operator==(other));
427 }
428
432 virtual std::string toText() const;
433
439 void decline(uint32_t probation_period);
440
442 virtual isc::data::ElementPtr toElement() const;
443
449 static Lease4Ptr fromElement(const data::ConstElementPtr& element);
450
452};
453
455typedef std::vector<Lease4Ptr> Lease4Collection;
456
458typedef boost::shared_ptr<Lease4Collection> Lease4CollectionPtr;
459
460struct Lease6;
461
463typedef boost::shared_ptr<Lease6> Lease6Ptr;
464
471struct Lease6 : public Lease {
472
477
481 uint8_t prefixlen_;
482
488 uint32_t iaid_;
489
492
498
500
513 Lease6(Lease::Type type, const isc::asiolink::IOAddress& addr, DuidPtr duid,
514 uint32_t iaid, uint32_t preferred, uint32_t valid, uint32_t t1,
515 uint32_t t2, SubnetID subnet_id, const HWAddrPtr& hwaddr = HWAddrPtr(),
516 uint8_t prefixlen = 128);
517
534 Lease6(Lease::Type type, const isc::asiolink::IOAddress& addr, DuidPtr duid,
535 uint32_t iaid, uint32_t preferred, uint32_t valid, uint32_t t1,
536 uint32_t t2, SubnetID subnet_id, const bool fqdn_fwd,
537 const bool fqdn_rev, const std::string& hostname,
538 const HWAddrPtr& hwaddr = HWAddrPtr(), uint8_t prefixlen = 128);
539
543 Lease6();
544
553 static std::string statesToText(const uint32_t state);
554
563 const std::vector<uint8_t>& getDuidVector() const;
564
570 void decline(uint32_t probation_period);
571
575 bool operator==(const Lease6& other) const;
576
580 bool operator!=(const Lease6& other) const {
581 return (!operator==(other));
582 }
583
587 virtual std::string toText() const;
588
590 virtual isc::data::ElementPtr toElement() const;
591
597 static Lease6Ptr fromElement(const data::ConstElementPtr& element);
598};
599
601typedef boost::shared_ptr<const Lease6> ConstLease6Ptr;
602
604typedef std::vector<Lease6Ptr> Lease6Collection;
605
606
608typedef boost::shared_ptr<Lease6Collection> Lease6CollectionPtr;
609
616std::ostream&
617operator<<(std::ostream& os, const Lease& lease);
618
619}; // end of isc::dhcp namespace
620}; // end of isc namespace
621
622#endif // LEASE_H
Holds Client identifier or client IPv4 address.
Definition: duid.h:111
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:23
boost::shared_ptr< Element > ElementPtr
Definition: data.h:22
boost::shared_ptr< Lease4Collection > Lease4CollectionPtr
A shared pointer to the collection of IPv4 leases.
Definition: lease.h:458
boost::shared_ptr< DUID > DuidPtr
Definition: duid.h:21
boost::shared_ptr< Lease6 > Lease6Ptr
Pointer to a Lease6 structure.
Definition: lease.h:463
std::vector< Lease6Ptr > Lease6Collection
A collection of IPv6 leases.
Definition: lease.h:604
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:29
boost::shared_ptr< ClientId > ClientIdPtr
Shared pointer to a Client ID.
Definition: duid.h:105
boost::shared_ptr< Lease6Collection > Lease6CollectionPtr
A shared pointer to the collection of IPv6 leases.
Definition: lease.h:608
boost::shared_ptr< const Lease6 > ConstLease6Ptr
Pointer to a const Lease6 structure.
Definition: lease.h:601
std::vector< Lease4Ptr > Lease4Collection
A collection of IPv4 leases.
Definition: lease.h:455
boost::shared_ptr< Lease4 > Lease4Ptr
Pointer to a Lease4 structure.
Definition: lease.h:248
Defines the logger used by the top-level component of kea-dhcp-ddns.
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:256
ClientIdPtr client_id_
Client identifier.
Definition: lease.h:262
void decline(uint32_t probation_period)
Sets IPv4 lease to declined state.
Definition: lease.cc:353
static std::string statesToText(const uint32_t state)
Returns name of the lease states specific to DHCPv4.
Definition: lease.cc:312
bool operator==(const Lease4 &other) const
Compare two leases for equality.
Definition: lease.cc:578
bool operator!=(const Lease4 &other) const
Compare two leases for inequality.
Definition: lease.h:425
const std::vector< uint8_t > & getClientIdVector() const
Returns a client identifier.
Definition: lease.cc:317
virtual isc::data::ElementPtr toElement() const
Return the JSON representation of a lease.
Definition: lease.cc:401
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:336
Lease4(const isc::asiolink::IOAddress &addr, const HWAddrPtr &hwaddr, const uint8_t *clientid, size_t clientid_len, uint32_t valid_lft, uint32_t t1, uint32_t t2, 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:278
Lease4()
Default constructor.
Definition: lease.h:319
Lease4 & operator=(const Lease4 &other)
Assignment operator.
Definition: lease.cc:367
virtual std::string toText() const
Convert lease to printable form.
Definition: lease.cc:556
static Lease4Ptr fromElement(const data::ConstElementPtr &element)
Returns pointer to the IPv4 lease created from JSON representation.
Definition: lease.cc:426
Structure that holds a lease for IPv6 address and/or prefix.
Definition: lease.h:471
const std::vector< uint8_t > & getDuidVector() const
Returns a reference to a vector representing a DUID.
Definition: lease.cc:506
virtual std::string toText() const
Convert Lease to Printable Form.
Definition: lease.cc:531
bool operator==(const Lease6 &other) const
Compare two leases for equality.
Definition: lease.cc:595
static std::string statesToText(const uint32_t state)
Returns name of the lease states specific to DHCPv6.
Definition: lease.cc:501
Lease6()
Constructor.
Definition: lease.cc:494
Lease::Type type_
Lease type.
Definition: lease.h:476
bool operator!=(const Lease6 &other) const
Compare two leases for inequality.
Definition: lease.h:580
uint32_t iaid_
Identity Association Identifier (IAID)
Definition: lease.h:488
uint32_t preferred_lft_
preferred lifetime
Definition: lease.h:497
DuidPtr duid_
Client identifier.
Definition: lease.h:491
static Lease6Ptr fromElement(const data::ConstElementPtr &element)
Returns pointer to the IPv6 lease created from JSON representation.
Definition: lease.cc:647
uint8_t prefixlen_
IPv6 prefix length.
Definition: lease.h:481
virtual isc::data::ElementPtr toElement() const
Return the JSON representation of a lease.
Definition: lease.cc:616
void decline(uint32_t probation_period)
Sets IPv6 lease to declined state.
Definition: lease.cc:516
a common structure for IPv4 and IPv6 leases
Definition: lease.h:35
bool hasIdenticalFqdn(const Lease &other) const
Returns true if the other lease has equal FQDN data.
Definition: lease.cc:115
virtual void decline(uint32_t probation_period)=0
Sets lease to DECLINED state.
virtual ~Lease()
Destructor.
Definition: lease.h:97
uint32_t t1_
Renewal timer.
Definition: lease.h:111
uint32_t t2_
Rebinding timer.
Definition: lease.h:120
bool stateDeclined() const
Indicates if the lease is in the "declined" state.
Definition: lease.cc:105
bool stateExpiredReclaimed() const
Indicates if the lease is in the "expired-reclaimed" state.
Definition: lease.cc:100
static const uint32_t STATE_DEFAULT
A lease in the default state.
Definition: lease.h:61
SubnetID subnet_id_
Subnet identifier.
Definition: lease.h:136
const std::vector< uint8_t > & getHWAddrVector() const
Returns raw (as vector) hardware address.
Definition: lease.cc:327
uint32_t valid_lft_
Valid lifetime.
Definition: lease.h:125
static std::string basicStatesToText(const uint32_t state)
Returns name(s) of the basic lease state(s).
Definition: lease.cc:77
static const uint32_t STATE_DECLINED
Declined lease.
Definition: lease.h:64
bool expired() const
returns true if the lease is expired
Definition: lease.cc:95
static const uint32_t STATE_EXPIRED_RECLAIMED
Expired and reclaimed lease.
Definition: lease.h:67
Type
Type of lease or pool.
Definition: lease.h:38
@ TYPE_TA
the lease contains temporary IPv6 address
Definition: lease.h:40
@ TYPE_PD
the lease contains IPv6 prefix (for prefix delegation)
Definition: lease.h:41
@ TYPE_V4
IPv4 lease.
Definition: lease.h:42
@ TYPE_NA
the lease contains non-temporary IPv6 address
Definition: lease.h:39
std::string hostname_
Client hostname.
Definition: lease.h:141
uint32_t state_
Holds the lease state(s).
Definition: lease.h:167
int64_t getExpirationTime() const
Returns lease expiration time.
Definition: lease.cc:110
bool fqdn_fwd_
Forward zone updated?
Definition: lease.h:146
time_t cltt_
Client last transmission time.
Definition: lease.h:131
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:122
static std::string typeToText(Type type)
returns text representation of a lease type
Definition: lease.cc:39
static Type textToType(const std::string &text)
Converts type name to the actual type.
Definition: lease.cc:59
HWAddrPtr hwaddr_
Client's MAC/hardware address.
Definition: lease.h:156
bool fqdn_rev_
Reverse zone updated?
Definition: lease.h:151
isc::asiolink::IOAddress addr_
IPv4 ot IPv6 address.
Definition: lease.h:102