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