Kea  2.1.7-git
lease.h
Go to the documentation of this file.
1 // Copyright (C) 2013-2022 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 
18 namespace isc {
19 namespace dhcp {
20 
21 struct Lease;
22 
24 typedef boost::shared_ptr<Lease> LeasePtr;
25 
31 
33  static const uint32_t INFINITY_LFT = 0xffffffff;
34 
42  static std::string lifetimeToText(uint32_t lifetime);
43 
45  typedef enum {
46  TYPE_NA = 0,
47  TYPE_TA = 1,
48  TYPE_PD = 2,
49  TYPE_V4 = 3
50  } Type;
51 
55  static std::string typeToText(Type type);
56 
62  static Type textToType(const std::string& text);
63 
65 
66  static const uint32_t STATE_DEFAULT;
69 
71  static const uint32_t STATE_DECLINED;
72 
74  static const uint32_t STATE_EXPIRED_RECLAIMED;
75 
83  static std::string basicStatesToText(const uint32_t state);
84 
102  Lease(const isc::asiolink::IOAddress& addr,
103  uint32_t valid_lft, SubnetID subnet_id, time_t cltt,
104  const bool fqdn_fwd, const bool fqdn_rev,
105  const std::string& hostname,
106  const HWAddrPtr& hwaddr);
107 
109  virtual ~Lease() {}
110 
115 
119  uint32_t valid_lft_;
120 
125 
132 
137  time_t cltt_;
138 
144 
149 
153  std::string hostname_;
154 
158  bool fqdn_fwd_;
159 
163  bool fqdn_rev_;
164 
169 
179  uint32_t state_;
180 
184  virtual std::string toText() const = 0;
185 
188  bool expired() const;
189 
194  bool stateExpiredReclaimed() const;
195 
199  bool stateDeclined() const;
200 
209  bool hasIdenticalFqdn(const Lease& other) const;
210 
219  const std::vector<uint8_t>& getHWAddrVector() const;
220 
225  int64_t getExpirationTime() const;
226 
237  virtual void decline(uint32_t probation_period) = 0;
238 
241 
252  static void syncCurrentExpirationTime(const Lease& from, Lease& to);
253 
262 
263 protected:
264 
273  static void fromElementCommon(const LeasePtr& lease,
274  const data::ConstElementPtr& element);
275 
276 };
277 
278 struct Lease4;
279 
281 typedef boost::shared_ptr<Lease4> Lease4Ptr;
282 
289 struct Lease4 : public Lease {
290 
296 
309  Lease4(const isc::asiolink::IOAddress& addr, const HWAddrPtr& hwaddr,
310  const uint8_t* clientid, size_t clientid_len, uint32_t valid_lft,
311  time_t cltt, uint32_t subnet_id,
312  const bool fqdn_fwd = false, const bool fqdn_rev = false,
313  const std::string& hostname = "")
314  : Lease(addr, valid_lft, subnet_id, cltt, fqdn_fwd, fqdn_rev,
315  hostname, hwaddr) {
316  if (clientid_len) {
317  client_id_.reset(new ClientId(clientid, clientid_len));
318  }
319  }
320 
332  Lease4(const isc::asiolink::IOAddress& address,
333  const HWAddrPtr& hw_address,
334  const ClientIdPtr& client_id,
335  const uint32_t valid_lifetime,
336  const time_t cltt,
337  const SubnetID subnet_id,
338  const bool fqdn_fwd = false,
339  const bool fqdn_rev = false,
340  const std::string& hostname = "");
341 
342 
346  Lease4() : Lease(0, 0, 0, 0, false, false, "", HWAddrPtr())
347  {
348  }
349 
353  Lease4(const Lease4& other);
354 
363  static std::string statesToText(const uint32_t state);
364 
374  const std::vector<uint8_t>& getClientIdVector() const;
375 
436  bool belongsToClient(const HWAddrPtr& hw_address,
437  const ClientIdPtr& client_id) const;
438 
442  Lease4& operator=(const Lease4& other);
443 
447  bool operator==(const Lease4& other) const;
448 
452  bool operator!=(const Lease4& other) const {
453  return (!operator==(other));
454  }
455 
459  virtual std::string toText() const;
460 
466  void decline(uint32_t probation_period);
467 
469  virtual isc::data::ElementPtr toElement() const;
470 
476  static Lease4Ptr fromElement(const data::ConstElementPtr& element);
477 
479 };
480 
482 typedef std::vector<Lease4Ptr> Lease4Collection;
483 
485 typedef boost::shared_ptr<Lease4Collection> Lease4CollectionPtr;
486 
487 struct Lease6;
488 
490 typedef boost::shared_ptr<Lease6> Lease6Ptr;
491 
498 struct Lease6 : public Lease {
499 
504 
508  uint8_t prefixlen_;
509 
515  uint32_t iaid_;
516 
519 
524  uint32_t preferred_lft_;
525 
533 
535 
546  Lease6(Lease::Type type, const isc::asiolink::IOAddress& addr, DuidPtr duid,
547  uint32_t iaid, uint32_t preferred, uint32_t valid,
548  SubnetID subnet_id, const HWAddrPtr& hwaddr = HWAddrPtr(),
549  uint8_t prefixlen = 128);
550 
565  Lease6(Lease::Type type, const isc::asiolink::IOAddress& addr, DuidPtr duid,
566  uint32_t iaid, uint32_t preferred, uint32_t valid,
567  SubnetID subnet_id, const bool fqdn_fwd,
568  const bool fqdn_rev, const std::string& hostname,
569  const HWAddrPtr& hwaddr = HWAddrPtr(), uint8_t prefixlen = 128);
570 
574  Lease6();
575 
584  static std::string statesToText(const uint32_t state);
585 
594  const std::vector<uint8_t>& getDuidVector() const;
595 
601  void decline(uint32_t probation_period);
602 
606  bool operator==(const Lease6& other) const;
607 
611  bool operator!=(const Lease6& other) const {
612  return (!operator==(other));
613  }
614 
618  virtual std::string toText() const;
619 
621  virtual isc::data::ElementPtr toElement() const;
622 
628  static Lease6Ptr fromElement(const data::ConstElementPtr& element);
629 };
630 
632 typedef boost::shared_ptr<const Lease6> ConstLease6Ptr;
633 
635 typedef std::vector<Lease6Ptr> Lease6Collection;
636 
637 
639 typedef boost::shared_ptr<Lease6Collection> Lease6CollectionPtr;
640 
647 std::ostream&
648 operator<<(std::ostream& os, const Lease& lease);
649 
650 }; // end of isc::dhcp namespace
651 }; // end of isc namespace
652 
653 #endif // LEASE_H
static std::string lifetimeToText(uint32_t lifetime)
Print lifetime.
Definition: lease.cc:29
uint32_t state_
Holds the lease state(s).
Definition: lease.h:179
boost::shared_ptr< DUID > DuidPtr
Definition: duid.h:20
HWAddrPtr hwaddr_
Client&#39;s MAC/hardware address.
Definition: lease.h:168
uint32_t iaid_
Identity Association Identifier (IAID)
Definition: lease.h:515
static const uint32_t STATE_EXPIRED_RECLAIMED
Expired and reclaimed lease.
Definition: lease.h:74
Structure that holds a lease for IPv4 address.
Definition: lease.h:289
uint32_t reuseable_preferred_lft_
Remaining preferred lifetime.
Definition: lease.h:532
bool fqdn_rev_
Reverse zone updated?
Definition: lease.h:163
virtual void decline(uint32_t probation_period)=0
Sets lease to DECLINED state.
boost::shared_ptr< HWAddr > HWAddrPtr
Shared pointer to a hardware address structure.
Definition: hwaddr.h:154
static std::string typeToText(Type type)
returns text representation of a lease type
Definition: lease.cc:52
const std::vector< uint8_t > & getHWAddrVector() const
Returns raw (as vector) hardware address.
Definition: lease.cc:355
Base class for user context.
Definition: user_context.h:22
time_t cltt_
Client last transmission time.
Definition: lease.h:137
uint32_t preferred_lft_
Preferred lifetime.
Definition: lease.h:524
bool fqdn_fwd_
Forward zone updated?
Definition: lease.h:158
std::vector< Lease4Ptr > Lease4Collection
A collection of IPv4 leases.
Definition: lease.h:482
the lease contains IPv6 prefix (for prefix delegation)
Definition: lease.h:48
boost::shared_ptr< Element > ElementPtr
Definition: data.h:24
std::string hostname_
Client hostname.
Definition: lease.h:153
boost::shared_ptr< const Lease6 > ConstLease6Ptr
Pointer to a const Lease6 structure.
Definition: lease.h:632
SubnetID subnet_id_
Subnet identifier.
Definition: lease.h:148
virtual std::string toText() const =0
Convert Lease to Printable Form.
boost::shared_ptr< Lease > LeasePtr
Pointer to the lease object.
Definition: lease.h:21
bool operator!=(const Lease4 &other) const
Compare two leases for inequality.
Definition: lease.h:452
bool operator==(const Element &a, const Element &b)
Definition: data.cc:210
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:291
int64_t getExpirationTime() const
Returns lease expiration time.
Definition: lease.cc:123
boost::shared_ptr< Lease4 > Lease4Ptr
Pointer to a Lease4 structure.
Definition: lease.h:278
Abstract class for configuration Cfg_* classes.
boost::shared_ptr< Lease4Collection > Lease4CollectionPtr
A shared pointer to the collection of IPv4 leases.
Definition: lease.h:485
Lease4()
Default constructor.
Definition: lease.h:346
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:309
IPv4 lease.
Definition: lease.h:49
void updateCurrentExpirationTime()
Update lease current expiration time with new value, so that additional operations can be done withou...
Definition: lease.cc:286
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:27
DuidPtr duid_
Client identifier.
Definition: lease.h:518
Structure that holds a lease for IPv6 address and/or prefix.
Definition: lease.h:498
ClientIdPtr client_id_
Client identifier.
Definition: lease.h:295
Lease::Type type_
Lease type.
Definition: lease.h:503
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
uint8_t prefixlen_
IPv6 prefix length.
Definition: lease.h:508
std::vector< Lease6Ptr > Lease6Collection
A collection of IPv6 leases.
Definition: lease.h:635
boost::shared_ptr< ClientId > ClientIdPtr
Shared pointer to a Client ID.
Definition: duid.h:103
the lease contains temporary IPv6 address
Definition: lease.h:47
the lease contains non-temporary IPv6 address
Definition: lease.h:46
bool expired() const
returns true if the lease is expired
Definition: lease.cc:108
time_t current_cltt_
Current client last transmission time.
Definition: lease.h:143
Defines the logger used by the top-level component of kea-lfc.
static Type textToType(const std::string &text)
Converts type name to the actual type.
Definition: lease.cc:72
bool operator!=(const Lease6 &other) const
Compare two leases for inequality.
Definition: lease.h:611
bool stateExpiredReclaimed() const
Indicates if the lease is in the "expired-reclaimed" state.
Definition: lease.cc:113
static const uint32_t INFINITY_LFT
Infinity (means static, i.e. never expire)
Definition: lease.h:33
a common structure for IPv4 and IPv6 leases
Definition: lease.h:30
Type
Type of lease or pool.
Definition: lease.h:45
std::ostream & operator<<(std::ostream &os, const OpaqueDataTuple &tuple)
Inserts the OpaqueDataTuple as a string into stream.
Holds Client identifier or client IPv4 address.
Definition: duid.h:111
static std::string basicStatesToText(const uint32_t state)
Returns name(s) of the basic lease state(s).
Definition: lease.cc:90
boost::shared_ptr< Lease6Collection > Lease6CollectionPtr
A shared pointer to the collection of IPv6 leases.
Definition: lease.h:639
virtual ~Lease()
Destructor.
Definition: lease.h:109
uint32_t reuseable_valid_lft_
Remaining valid lifetime.
Definition: lease.h:131
isc::asiolink::IOAddress addr_
IPv4 ot IPv6 address.
Definition: lease.h:114
static const uint32_t STATE_DEFAULT
A lease in the default state.
Definition: lease.h:68
static const uint32_t STATE_DECLINED
Declined lease.
Definition: lease.h:71
bool stateDeclined() const
Indicates if the lease is in the "declined" state.
Definition: lease.cc:118
uint32_t valid_lft_
Valid lifetime.
Definition: lease.h:119
virtual isc::data::ElementPtr toElement() const =0
Unparse a configuration object.
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
boost::shared_ptr< Lease6 > Lease6Ptr
Pointer to a Lease6 structure.
Definition: lease.h:487
uint32_t current_valid_lft_
Current valid lifetime.
Definition: lease.h:124
bool hasIdenticalFqdn(const Lease &other) const
Returns true if the other lease has equal FQDN data.
Definition: lease.cc:128
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
Definition: subnet_id.h:24