Kea  1.5.0
lease.cc
Go to the documentation of this file.
1 // Copyright (C) 2012-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 #include <config.h>
8 
9 #include <dhcpsrv/lease.h>
10 #include <util/pointer_util.h>
11 #include <boost/algorithm/string.hpp>
12 #include <boost/scoped_ptr.hpp>
13 #include <sstream>
14 #include <iostream>
15 
16 
17 using namespace isc::util;
18 using namespace isc::data;
19 using namespace std;
20 
21 namespace isc {
22 namespace dhcp {
23 
24 const uint32_t Lease::STATE_DEFAULT = 0x0;
25 const uint32_t Lease::STATE_DECLINED = 0x1;
26 const uint32_t Lease::STATE_EXPIRED_RECLAIMED = 0x2;
27 
28 Lease::Lease(const isc::asiolink::IOAddress& addr, uint32_t t1, uint32_t t2,
29  uint32_t valid_lft, SubnetID subnet_id, time_t cltt,
30  const bool fqdn_fwd, const bool fqdn_rev,
31  const std::string& hostname, const HWAddrPtr& hwaddr)
32  :addr_(addr), t1_(t1), t2_(t2), valid_lft_(valid_lft), cltt_(cltt),
33  subnet_id_(subnet_id), hostname_(hostname), fqdn_fwd_(fqdn_fwd),
34  fqdn_rev_(fqdn_rev), hwaddr_(hwaddr), state_(STATE_DEFAULT) {
35 }
36 
37 
38 std::string
40  switch (type) {
41  case Lease::TYPE_V4:
42  return string("V4");
43  case Lease::TYPE_NA:
44  return string("IA_NA");
45  case Lease::TYPE_TA:
46  return string("IA_TA");
47  case Lease::TYPE_PD:
48  return string("IA_PD");
49  break;
50  default: {
51  stringstream tmp;
52  tmp << "unknown (" << type << ")";
53  return (tmp.str());
54  }
55  }
56 }
57 
59 Lease::textToType(const std::string& text) {
60  if (text == "V4") {
61  return (TYPE_V4);
62 
63  } else if (text == "IA_NA") {
64  return (TYPE_NA);
65 
66  } else if (text == "IA_TA") {
67  return (TYPE_TA);
68 
69  } else if (text == "IA_PD") {
70  return (TYPE_PD);
71  }
72 
73  isc_throw(BadValue, "unsupported lease type " << text);
74 }
75 
76 std::string
77 Lease::basicStatesToText(const uint32_t state) {
78  switch (state) {
79  case STATE_DEFAULT:
80  return ("default");
81  case STATE_DECLINED:
82  return ("declined");
84  return ("expired-reclaimed");
85  default:
86  // The default case will be handled further on
87  ;
88  }
89  std::ostringstream s;
90  s << "unknown (" << state << ")";
91  return s.str();
92 }
93 
94 bool
95 Lease::expired() const {
96  return (getExpirationTime() < time(NULL));
97 }
98 
99 bool
101  return (state_ == STATE_EXPIRED_RECLAIMED);
102 }
103 
104 bool
106  return (state_ == STATE_DECLINED);
107 }
108 
109 int64_t
111  return (static_cast<int64_t>(cltt_) + valid_lft_);
112 }
113 
114 bool
115 Lease::hasIdenticalFqdn(const Lease& other) const {
116  return (boost::algorithm::iequals(hostname_, other.hostname_) &&
117  fqdn_fwd_ == other.fqdn_fwd_ &&
118  fqdn_rev_ == other.fqdn_rev_);
119 }
120 
121 void
123  if (!element) {
124  isc_throw(BadValue, "parsed lease data is null");
125  }
126 
127  if (element->getType() != Element::map) {
128  isc_throw(BadValue, "parsed lease data is not a JSON map");
129  }
130 
131 
132  if (!lease) {
133  isc_throw(Unexpected, "pointer to parsed lease is null");
134  }
135 
136  // IP address.
137  ConstElementPtr ip_address = element->get("ip-address");
138  if (!ip_address || (ip_address->getType() != Element::string)) {
139  isc_throw(BadValue, "ip-address not present in the parsed lease"
140  " or it is not a string");
141  }
142 
143  boost::scoped_ptr<asiolink::IOAddress> io_address;
144  try {
145  io_address.reset(new asiolink::IOAddress(ip_address->stringValue()));
146 
147  } catch (const std::exception& ex) {
148  isc_throw(BadValue, "invalid IP address " << ip_address->stringValue()
149  << " in the parsed lease");
150  }
151 
152  lease->addr_ = *io_address;
153 
154  // Subnet identifier.
155  ConstElementPtr subnet_id = element->get("subnet-id");
156  if (!subnet_id || (subnet_id->getType() != Element::integer)) {
157  isc_throw(BadValue, "subnet-id not present in the parsed lease"
158  " or it is not a number");
159  }
160 
161  if (subnet_id->intValue() <= 0) {
162  isc_throw(BadValue, "subnet-id " << subnet_id->intValue() << " is not"
163  << " a positive integer");
164  }
165 
166  lease->subnet_id_ = SubnetID(subnet_id->intValue());
167 
168  // Hardware address.
169  ConstElementPtr hw_address = element->get("hw-address");
170  if (hw_address) {
171  if (hw_address->getType() != Element::string) {
172  isc_throw(BadValue, "hw-address is not a string in the parsed lease");
173 
174  }
175 
176  try {
177  HWAddr parsed_hw_address = HWAddr::fromText(hw_address->stringValue());
178  lease->hwaddr_.reset(new HWAddr(parsed_hw_address.hwaddr_, HTYPE_ETHER));
179 
180  } catch (const std::exception& ex) {
181  isc_throw(BadValue, "invalid hardware address "
182  << hw_address->stringValue() << " in the parsed lease");
183  }
184  }
185 
186  // cltt
187  ConstElementPtr cltt = element->get("cltt");
188  if (!cltt || (cltt->getType() != Element::integer)) {
189  isc_throw(BadValue, "cltt is not present in the parsed lease"
190  " or it is not a number");
191  }
192 
193  if (cltt->intValue() <= 0) {
194  isc_throw(BadValue, "cltt " << cltt->intValue() << " is not a"
195  " positive integer in the parsed lease");
196  }
197 
198  lease->cltt_ = static_cast<time_t>(cltt->intValue());
199 
200  // valid lifetime
201  ConstElementPtr valid_lifetime = element->get("valid-lft");
202  if (!valid_lifetime || (valid_lifetime->getType() != Element::integer)) {
203  isc_throw(BadValue, "valid-lft is not present in the parsed lease"
204  " or it is not a number");
205  }
206 
207  if (valid_lifetime->intValue() < 0) {
208  isc_throw(BadValue, "valid-lft " << valid_lifetime->intValue()
209  << " is negative in the parsed lease");
210  }
211 
212  lease->valid_lft_ = valid_lifetime->intValue();
213 
214  // fqdn-fwd
215  ConstElementPtr fqdn_fwd = element->get("fqdn-fwd");
216  if (!fqdn_fwd || fqdn_fwd->getType() != Element::boolean) {
217  isc_throw(BadValue, "fqdn-fwd is not present in the parsed lease"
218  " or it is not a boolean value");
219  }
220 
221  lease->fqdn_fwd_ = fqdn_fwd->boolValue();
222 
223  // fqdn-fwd
224  ConstElementPtr fqdn_rev = element->get("fqdn-rev");
225  if (!fqdn_rev || (fqdn_rev->getType() != Element::boolean)) {
226  isc_throw(BadValue, "fqdn-rev is not present in the parsed lease"
227  " or it is not a boolean value");
228  }
229 
230  lease->fqdn_rev_ = fqdn_rev->boolValue();
231 
232  // hostname
233  ConstElementPtr hostname = element->get("hostname");
234  if (!hostname || (hostname->getType() != Element::string)) {
235  isc_throw(BadValue, "hostname is not present in the parsed lease"
236  " or it is not a string value");
237  }
238 
239  lease->hostname_ = hostname->stringValue();
240 
241  // state
242  ConstElementPtr state = element->get("state");
243  if (!state || (state->getType() != Element::integer)) {
244  isc_throw(BadValue, "state is not present in the parsed lease"
245  " or it is not a number");
246  }
247 
248  if ((state->intValue() < 0) || (state->intValue() > Lease::STATE_EXPIRED_RECLAIMED)) {
249  isc_throw(BadValue, "state " << state->intValue()
250  << " must be in range [0.."
252  }
253 
254  lease->state_ = state->intValue();
255 
256  // user context
257  ConstElementPtr ctx = element->get("user-context");
258  if (ctx) {
259  if (ctx->getType() != Element::map) {
260  isc_throw(BadValue, "user context is not a map");
261  }
262  lease->setContext(ctx);
263  }
264 }
265 
266 Lease4::Lease4(const Lease4& other)
267  : Lease(other.addr_, other.t1_, other.t2_, other.valid_lft_,
268  other.subnet_id_, other.cltt_, other.fqdn_fwd_,
269  other.fqdn_rev_, other.hostname_, other.hwaddr_) {
270 
271  // Copy over fields derived from Lease.
272  state_ = other.state_;
273 
274  // Copy the hardware address if it is defined.
275  if (other.hwaddr_) {
276  hwaddr_.reset(new HWAddr(*other.hwaddr_));
277  } else {
278  hwaddr_.reset();
279  }
280 
281  if (other.client_id_) {
282  client_id_.reset(new ClientId(other.client_id_->getClientId()));
283 
284  } else {
285  client_id_.reset();
286 
287  }
288 
289  if (other.getContext()) {
290  setContext(other.getContext());
291  }
292 }
293 
295  const HWAddrPtr& hw_address,
296  const ClientIdPtr& client_id,
297  const uint32_t valid_lifetime,
298  const uint32_t t1,
299  const uint32_t t2,
300  const time_t cltt,
301  const SubnetID subnet_id,
302  const bool fqdn_fwd,
303  const bool fqdn_rev,
304  const std::string& hostname)
305 
306  : Lease(address, t1, t2, valid_lifetime, subnet_id, cltt, fqdn_fwd,
307  fqdn_rev, hostname, hw_address),
308  client_id_(client_id) {
309 }
310 
311 std::string
312 Lease4::statesToText(const uint32_t state) {
313  return (Lease::basicStatesToText(state));
314 }
315 
316 const std::vector<uint8_t>&
318  if(!client_id_) {
319  static std::vector<uint8_t> empty_vec;
320  return (empty_vec);
321  }
322 
323  return (client_id_->getClientId());
324 }
325 
326 const std::vector<uint8_t>&
328  if (!hwaddr_) {
329  static std::vector<uint8_t> empty_vec;
330  return (empty_vec);
331  }
332  return (hwaddr_->hwaddr_);
333 }
334 
335 bool
337  const ClientIdPtr& client_id) const {
338  // If client id matches, lease matches.
339  if (equalValues(client_id, client_id_)) {
340  return (true);
341 
342  } else if (!client_id || !client_id_) {
343  // If client id is unspecified, use HW address.
344  if (equalValues(hw_address, hwaddr_)) {
345  return (true);
346  }
347  }
348 
349  return (false);
350 }
351 
352 void
353 Lease4::decline(uint32_t probation_period) {
354  hwaddr_.reset(new HWAddr());
355  client_id_.reset();
356  t1_ = 0;
357  t2_ = 0;
358  cltt_ = time(NULL);
359  hostname_ = string("");
360  fqdn_fwd_ = false;
361  fqdn_rev_ = false;
363  valid_lft_ = probation_period;
364 }
365 
366 Lease4&
367 Lease4::operator=(const Lease4& other) {
368  if (this != &other) {
369  addr_ = other.addr_;
370  t1_ = other.t1_;
371  t2_ = other.t2_;
372  valid_lft_ = other.valid_lft_;
373  cltt_ = other.cltt_;
374  subnet_id_ = other.subnet_id_;
375  hostname_ = other.hostname_;
376  fqdn_fwd_ = other.fqdn_fwd_;
377  fqdn_rev_ = other.fqdn_rev_;
378  state_ = other.state_;
379 
380  // Copy the hardware address if it is defined.
381  if (other.hwaddr_) {
382  hwaddr_.reset(new HWAddr(*other.hwaddr_));
383  } else {
384  hwaddr_.reset();
385  }
386 
387  if (other.client_id_) {
388  client_id_.reset(new ClientId(other.client_id_->getClientId()));
389  } else {
390  client_id_.reset();
391  }
392 
393  if (other.getContext()) {
394  setContext(other.getContext());
395  }
396  }
397  return (*this);
398 }
399 
402  // Prepare the map
403  ElementPtr map = Element::createMap();
404  contextToElement(map);
405  map->set("ip-address", Element::create(addr_.toText()));
406  map->set("subnet-id", Element::create(static_cast<long int>(subnet_id_)));
407  map->set("hw-address", Element::create(hwaddr_->toText(false)));
408 
409  if (client_id_) {
410  map->set("client-id", Element::create(client_id_->toText()));
411  }
412 
413  map->set("cltt", Element::create(cltt_));
414  map->set("valid-lft", Element::create(static_cast<long int>(valid_lft_)));
415 
416  map->set("fqdn-fwd", Element::create(fqdn_fwd_));
417  map->set("fqdn-rev", Element::create(fqdn_rev_));
418  map->set("hostname", Element::create(hostname_));
419 
420  map->set("state", Element::create(static_cast<int>(state_)));
421 
422  return (map);
423 }
424 
425 Lease4Ptr
427  Lease4Ptr lease(new Lease4());
428 
429  // Extract common lease properties into the lease.
430  fromElementCommon(boost::dynamic_pointer_cast<Lease>(lease), element);
431 
432  // Validate ip-address, which must be an IPv4 address.
433  if (!lease->addr_.isV4()) {
434  isc_throw(BadValue, "address " << lease->addr_ << " it not an IPv4 address");
435  }
436 
437  // Make sure the hw-addres is present.
438  if (!lease->hwaddr_) {
439  isc_throw(BadValue, "hw-address not present in the parsed lease");
440  }
441 
442 
443  // Client identifier is IPv4 specific.
444  ConstElementPtr client_id = element->get("client-id");
445  if (client_id) {
446  if (client_id->getType() != Element::string) {
447  isc_throw(BadValue, "client identifier is not a string in the"
448  " parsed lease");
449  }
450 
451  try {
452  lease->client_id_ = ClientId::fromText(client_id->stringValue());
453 
454  } catch (const std::exception& ex) {
455  isc_throw(BadValue, "invalid client identifier "
456  << client_id->stringValue() << " in the parsed lease");
457  }
458  }
459 
460  return (lease);
461 }
462 
464  DuidPtr duid, uint32_t iaid, uint32_t preferred, uint32_t valid,
465  uint32_t t1, uint32_t t2, SubnetID subnet_id,
466  const HWAddrPtr& hwaddr, uint8_t prefixlen)
467  : Lease(addr, t1, t2, valid, subnet_id, 0/*cltt*/, false, false, "", hwaddr),
468  type_(type), prefixlen_(prefixlen), iaid_(iaid), duid_(duid),
469  preferred_lft_(preferred) {
470  if (!duid) {
471  isc_throw(InvalidOperation, "DUID is mandatory for an IPv6 lease");
472  }
473 
474  cltt_ = time(NULL);
475 }
476 
478  DuidPtr duid, uint32_t iaid, uint32_t preferred, uint32_t valid,
479  uint32_t t1, uint32_t t2, SubnetID subnet_id,
480  const bool fqdn_fwd, const bool fqdn_rev,
481  const std::string& hostname, const HWAddrPtr& hwaddr,
482  uint8_t prefixlen)
483  : Lease(addr, t1, t2, valid, subnet_id, 0/*cltt*/,
484  fqdn_fwd, fqdn_rev, hostname, hwaddr),
485  type_(type), prefixlen_(prefixlen), iaid_(iaid), duid_(duid),
486  preferred_lft_(preferred) {
487  if (!duid) {
488  isc_throw(InvalidOperation, "DUID is mandatory for an IPv6 lease");
489  }
490 
491  cltt_ = time(NULL);
492 }
493 
495  : Lease(isc::asiolink::IOAddress("::"), 0, 0, 0, 0, 0, false, false, "",
496  HWAddrPtr()), type_(TYPE_NA), prefixlen_(0), iaid_(0),
497  duid_(DuidPtr()), preferred_lft_(0) {
498 }
499 
500 std::string
501 Lease6::statesToText(const uint32_t state) {
502  return (Lease::basicStatesToText(state));
503 }
504 
505 const std::vector<uint8_t>&
507  if (!duid_) {
508  static std::vector<uint8_t> empty_vec;
509  return (empty_vec);
510  }
511 
512  return (duid_->getDuid());
513 }
514 
515 void
516 Lease6::decline(uint32_t probation_period) {
517  hwaddr_.reset();
518  duid_.reset(new DUID(DUID::EMPTY()));
519  t1_ = 0;
520  t2_ = 0;
521  preferred_lft_ = 0;
522  valid_lft_ = probation_period;
523  cltt_ = time(NULL);
524  hostname_ = string("");
525  fqdn_fwd_ = false;
526  fqdn_rev_ = false;
528 }
529 
530 std::string
531 Lease6::toText() const {
532  ostringstream stream;
533 
535  stream << "Type: " << typeToText(type_) << "("
536  << static_cast<int>(type_) << ")\n"
537  << "Address: " << addr_ << "\n"
538  << "Prefix length: " << static_cast<int>(prefixlen_) << "\n"
539  << "IAID: " << iaid_ << "\n"
540  << "Pref life: " << preferred_lft_ << "\n"
541  << "Valid life: " << valid_lft_ << "\n"
542  << "Cltt: " << cltt_ << "\n"
543  << "DUID: " << (duid_?duid_->toText():"(none)") << "\n"
544  << "Hardware addr: " << (hwaddr_?hwaddr_->toText(false):"(none)") << "\n"
545  << "Subnet ID: " << subnet_id_ << "\n"
546  << "State: " << statesToText(state_) << "\n";
547 
548  if (getContext()) {
549  stream << "User context: " << getContext()->str() << "\n";
550  }
551 
552  return (stream.str());
553 }
554 
555 std::string
556 Lease4::toText() const {
557  ostringstream stream;
558 
559  stream << "Address: " << addr_ << "\n"
560  << "Valid life: " << valid_lft_ << "\n"
561  << "T1: " << t1_ << "\n"
562  << "T2: " << t2_ << "\n"
563  << "Cltt: " << cltt_ << "\n"
564  << "Hardware addr: " << (hwaddr_ ? hwaddr_->toText(false) : "(none)") << "\n"
565  << "Client id: " << (client_id_ ? client_id_->toText() : "(none)") << "\n"
566  << "Subnet ID: " << subnet_id_ << "\n"
567  << "State: " << statesToText(state_) << "\n";
568 
569  if (getContext()) {
570  stream << "User context: " << getContext()->str() << "\n";
571  }
572 
573  return (stream.str());
574 }
575 
576 
577 bool
578 Lease4::operator==(const Lease4& other) const {
579  return (nullOrEqualValues(hwaddr_, other.hwaddr_) &&
581  addr_ == other.addr_ &&
582  subnet_id_ == other.subnet_id_ &&
583  t1_ == other.t1_ &&
584  t2_ == other.t2_ &&
585  valid_lft_ == other.valid_lft_ &&
586  cltt_ == other.cltt_ &&
587  hostname_ == other.hostname_ &&
588  fqdn_fwd_ == other.fqdn_fwd_ &&
589  fqdn_rev_ == other.fqdn_rev_ &&
590  state_ == other.state_ &&
592 }
593 
594 bool
595 Lease6::operator==(const Lease6& other) const {
596  return (nullOrEqualValues(duid_, other.duid_) &&
598  addr_ == other.addr_ &&
599  type_ == other.type_ &&
600  prefixlen_ == other.prefixlen_ &&
601  iaid_ == other.iaid_ &&
602  preferred_lft_ == other.preferred_lft_ &&
603  valid_lft_ == other.valid_lft_ &&
604  t1_ == other.t1_ &&
605  t2_ == other.t2_ &&
606  cltt_ == other.cltt_ &&
607  subnet_id_ == other.subnet_id_ &&
608  hostname_ == other.hostname_ &&
609  fqdn_fwd_ == other.fqdn_fwd_ &&
610  fqdn_rev_ == other.fqdn_rev_ &&
611  state_ == other.state_ &&
613 }
614 
617  // Prepare the map
618  ElementPtr map = Element::createMap();
619  contextToElement(map);
620  map->set("ip-address", Element::create(addr_.toText()));
621  map->set("type", Element::create(typeToText(type_)));
622  if (type_ == Lease::TYPE_PD) {
623  map->set("prefix-len", Element::create(prefixlen_));
624  }
625  map->set("iaid", Element::create(static_cast<long int>(iaid_)));
626  map->set("duid", Element::create(duid_->toText()));
627  map->set("subnet-id", Element::create(static_cast<long int>(subnet_id_)));
628 
629  map->set("cltt", Element::create(cltt_));
630  map->set("preferred-lft", Element::create(static_cast<long int>(preferred_lft_)));
631  map->set("valid-lft", Element::create(static_cast<long int>(valid_lft_)));
632 
633  map->set("fqdn-fwd", Element::create(fqdn_fwd_));
634  map->set("fqdn-rev", Element::create(fqdn_rev_));
635  map->set("hostname", Element::create(hostname_));
636 
637  if (hwaddr_) {
638  map->set("hw-address", Element::create(hwaddr_->toText(false)));
639  }
640 
641  map->set("state", Element::create(static_cast<long int>(state_)));
642 
643  return (map);
644 }
645 
646 Lease6Ptr
648  Lease6Ptr lease(new Lease6());
649 
650  // Extract common lease properties into the lease.
651  fromElementCommon(boost::dynamic_pointer_cast<Lease>(lease), element);
652 
653  // Validate ip-address, which must be an IPv6 address.
654  if (!lease->addr_.isV6()) {
655  isc_throw(BadValue, "address " << lease->addr_ << " it not an IPv6 address");
656  }
657 
658  // lease type
659  ConstElementPtr lease_type = element->get("type");
660  if (!lease_type || (lease_type->getType() != Element::string)) {
661  isc_throw(BadValue, "type is not present in the parsed lease"
662  " or it is not a string value");
663  }
664 
665  lease->type_ = textToType(lease_type->stringValue());
666 
667  // prefix length
668  ConstElementPtr prefix_len = element->get("prefix-len");
669  if (lease->type_ == Lease::TYPE_PD) {
670  if (!prefix_len || (prefix_len->getType() != Element::integer)) {
671  isc_throw(BadValue, "prefix-len is not present in the parsed lease"
672  " or it is not a number");
673  }
674 
675  if ((prefix_len->intValue() < 1) || (prefix_len->intValue() > 128)) {
676  isc_throw(BadValue, "prefix-len " << prefix_len->intValue()
677  << " must be in range of [1..128]");
678  }
679 
680  lease->prefixlen_ = static_cast<uint8_t>(prefix_len->intValue());
681  }
682 
683  // IAID
684  ConstElementPtr iaid = element->get("iaid");
685  if (!iaid || (iaid->getType() != Element::integer)) {
686  isc_throw(BadValue, "iaid is not present in the parsed lease"
687  " or it is not a number");
688  }
689 
690  if (iaid->intValue() < 0) {
691  isc_throw(BadValue, "iaid " << iaid->intValue() << " must not be negative");
692  }
693 
694  lease->iaid_ = static_cast<uint32_t>(iaid->intValue());
695 
696  // DUID
697  ConstElementPtr duid = element->get("duid");
698  if (!duid || (duid->getType() != Element::string)) {
699  isc_throw(BadValue, "duid not present in the parsed lease"
700  " or it is not a string");
701  }
702 
703  try {
704  DUID parsed_duid = DUID::fromText(duid->stringValue());
705  lease->duid_.reset(new DUID(parsed_duid.getDuid()));
706 
707  } catch (const std::exception& ex) {
708  isc_throw(BadValue, "invalid DUID "
709  << duid->stringValue() << " in the parsed lease");
710  }
711 
712  // preferred lifetime
713  ConstElementPtr preferred_lft = element->get("preferred-lft");
714  if (!preferred_lft || (preferred_lft->getType() != Element::integer)) {
715  isc_throw(BadValue, "preferred-lft is not present in the parsed lease"
716  " or is not a number");
717  }
718 
719  if (preferred_lft->intValue() < 0) {
720  isc_throw(BadValue, "preferred-lft " << preferred_lft->intValue()
721  << " must not be negative");
722  }
723 
724  lease->preferred_lft_ = static_cast<uint32_t>(preferred_lft->intValue());
725 
726  return (lease);
727 }
728 
729 std::ostream&
730 operator<<(std::ostream& os, const Lease& lease) {
731  os << lease.toText();
732  return (os);
733 }
734 
735 } // namespace isc::dhcp
736 } // namespace isc
uint32_t state_
Holds the lease state(s).
Definition: lease.h:167
boost::shared_ptr< DUID > DuidPtr
Definition: duid.h:20
void setContext(const data::ConstElementPtr &ctx)
Sets user context.
Definition: user_context.h:30
static ClientIdPtr fromText(const std::string &text)
Create client identifier from the textual format.
Definition: duid.cc:131
HWAddrPtr hwaddr_
Client's MAC/hardware address.
Definition: lease.h:156
uint32_t iaid_
Identity Association Identifier (IAID)
Definition: lease.h:488
static const uint32_t STATE_EXPIRED_RECLAIMED
Expired and reclaimed lease.
Definition: lease.h:67
Structure that holds a lease for IPv4 address.
Definition: lease.h:256
data::ConstElementPtr getContext() const
Returns const pointer to the user context.
Definition: user_context.h:24
bool fqdn_rev_
Reverse zone updated?
Definition: lease.h:151
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:39
const std::vector< uint8_t > & getHWAddrVector() const
Returns raw (as vector) hardware address.
Definition: lease.cc:327
time_t cltt_
Client last transmission time.
Definition: lease.h:131
uint32_t preferred_lft_
preferred lifetime
Definition: lease.h:497
static const DUID & EMPTY()
Defines the constant "empty" DUID.
Definition: duid.cc:68
bool fqdn_fwd_
Forward zone updated?
Definition: lease.h:146
virtual std::string toText() const
Convert Lease to Printable Form.
Definition: lease.cc:531
virtual isc::data::ElementPtr toElement() const
Return the JSON representation of a lease.
Definition: lease.cc:401
static Lease4Ptr fromElement(const data::ConstElementPtr &element)
Returns pointer to the IPv4 lease created from JSON representation.
Definition: lease.cc:426
the lease contains IPv6 prefix (for prefix delegation)
Definition: lease.h:41
boost::shared_ptr< Element > ElementPtr
Definition: data.h:20
std::vector< uint8_t > hwaddr_
Definition: hwaddr.h:98
static DUID fromText(const std::string &text)
Create DUID from the textual format.
Definition: duid.cc:61
void decline(uint32_t probation_period)
Sets IPv4 lease to declined state.
Definition: lease.cc:353
std::string hostname_
Client hostname.
Definition: lease.h:141
SubnetID subnet_id_
Subnet identifier.
Definition: lease.h:136
virtual std::string toText() const =0
Convert Lease to Printable Form.
boost::shared_ptr< Lease > LeasePtr
Pointer to the lease object.
Definition: lease.h:26
Holds DUID (DHCPv6 Unique Identifier)
Definition: duid.h:27
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
uint32_t t1_
Renewal timer.
Definition: lease.h:111
Definition: edns.h:19
int64_t getExpirationTime() const
Returns lease expiration time.
Definition: lease.cc:110
boost::shared_ptr< Lease4 > Lease4Ptr
Pointer to a Lease4 structure.
Definition: lease.h:245
A generic exception that is thrown when an unexpected error condition occurs.
Lease4()
Default constructor.
Definition: lease.h:319
bool equalValues(const T &ptr1, const T &ptr2)
This function checks if two pointers are non-null and values are equal.
Definition: pointer_util.h:27
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:23
DuidPtr duid_
Client identifier.
Definition: lease.h:491
std::vector< uint8_t > duid_
The actual content of the DUID.
Definition: duid.h:99
Structure that holds a lease for IPv6 address and/or prefix.
Definition: lease.h:471
ClientIdPtr client_id_
Client identifier.
Definition: lease.h:262
Lease::Type type_
Lease type.
Definition: lease.h:476
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
void contextToElement(data::ElementPtr map) const
Merge unparse a user_context object.
Definition: user_context.cc:15
uint8_t prefixlen_
IPv6 prefix length.
Definition: lease.h:481
boost::shared_ptr< ClientId > ClientIdPtr
Shared pointer to a Client ID.
Definition: duid.h:103
the lease contains temporary IPv6 address
Definition: lease.h:40
bool operator==(const Lease4 &other) const
Compare two leases for equality.
Definition: lease.cc:578
const std::vector< uint8_t > & getDuid() const
Returns a const reference to the actual DUID value.
Definition: duid.cc:44
the lease contains non-temporary IPv6 address
Definition: lease.h:39
bool nullOrEqualValues(const T &ptr1, const T &ptr2)
This function checks if two pointers are both null or both are non-null and they point to equal value...
Definition: pointer_util.h:42
Lease6()
Constructor.
Definition: lease.cc:494
Ethernet 10Mbps.
Definition: dhcp4.h:56
bool expired() const
returns true if the lease is expired
Definition: lease.cc:95
Lease4 & operator=(const Lease4 &other)
Assignment operator.
Definition: lease.cc:367
virtual isc::data::ElementPtr toElement() const
Return the JSON representation of a lease.
Definition: lease.cc:616
Defines the logger used by the top-level component of kea-dhcp-ddns.
static Lease6Ptr fromElement(const data::ConstElementPtr &element)
Returns pointer to the IPv6 lease created from JSON representation.
Definition: lease.cc:647
static Type textToType(const std::string &text)
Converts type name to the actual type.
Definition: lease.cc:59
const std::vector< uint8_t > & getDuidVector() const
Returns a reference to a vector representing a DUID.
Definition: lease.cc:506
static std::string statesToText(const uint32_t state)
Returns name of the lease states specific to DHCPv4.
Definition: lease.cc:312
bool stateExpiredReclaimed() const
Indicates if the lease is in the "expired-reclaimed" state.
Definition: lease.cc:100
a common structure for IPv4 and IPv6 leases
Definition: lease.h:35
static std::string statesToText(const uint32_t state)
Returns name of the lease states specific to DHCPv6.
Definition: lease.cc:501
static HWAddr fromText(const std::string &text, const uint16_t htype=HTYPE_ETHER)
Creates instance of the hardware address from textual format.
Definition: hwaddr.cc:70
Type
Type of lease or pool.
Definition: lease.h:38
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
A generic exception that is thrown if a function is called in a prohibited way.
static std::string basicStatesToText(const uint32_t state)
Returns name(s) of the basic lease state(s).
Definition: lease.cc:77
void decline(uint32_t probation_period)
Sets IPv6 lease to declined state.
Definition: lease.cc:516
Hardware type that represents information from DHCPv4 packet.
Definition: hwaddr.h:20
isc::asiolink::IOAddress addr_
IPv4 ot IPv6 address.
Definition: lease.h:102
static const uint32_t STATE_DEFAULT
A lease in the default state.
Definition: lease.h:61
bool operator==(const Lease6 &other) const
Compare two leases for equality.
Definition: lease.cc:595
static const uint32_t STATE_DECLINED
Declined lease.
Definition: lease.h:64
bool stateDeclined() const
Indicates if the lease is in the "declined" state.
Definition: lease.cc:105
uint32_t t2_
Rebinding timer.
Definition: lease.h:120
uint32_t valid_lft_
Valid lifetime.
Definition: lease.h:125
const std::vector< uint8_t > & getClientIdVector() const
Returns a client identifier.
Definition: lease.cc:317
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
virtual std::string toText() const
Convert lease to printable form.
Definition: lease.cc:556
boost::shared_ptr< Lease6 > Lease6Ptr
Pointer to a Lease6 structure.
Definition: lease.h:460
bool hasIdenticalFqdn(const Lease &other) const
Returns true if the other lease has equal FQDN data.
Definition: lease.cc:115
uint32_t SubnetID
Unique identifier for a subnet (both v4 and v6)
Definition: lease.h:24