summaryrefslogtreecommitdiffstats
path: root/src/lib/dhcpsrv/lease_mgr.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/dhcpsrv/lease_mgr.cc')
-rw-r--r--src/lib/dhcpsrv/lease_mgr.cc131
1 files changed, 12 insertions, 119 deletions
diff --git a/src/lib/dhcpsrv/lease_mgr.cc b/src/lib/dhcpsrv/lease_mgr.cc
index 2310dd4cd5..e4fa07f2b9 100644
--- a/src/lib/dhcpsrv/lease_mgr.cc
+++ b/src/lib/dhcpsrv/lease_mgr.cc
@@ -32,33 +32,6 @@ using namespace std;
namespace isc {
namespace dhcp {
-Lease::Lease(const isc::asiolink::IOAddress& addr, uint32_t t1, uint32_t t2,
- uint32_t valid_lft, SubnetID subnet_id, time_t cltt)
- :addr_(addr), t1_(t1), t2_(t2), valid_lft_(valid_lft), cltt_(cltt),
- subnet_id_(subnet_id), fixed_(false), fqdn_fwd_(false), fqdn_rev_(false) {
-}
-
-Lease6::Lease6(LeaseType type, const isc::asiolink::IOAddress& addr,
- DuidPtr duid, uint32_t iaid, uint32_t preferred, uint32_t valid,
- uint32_t t1, uint32_t t2, SubnetID subnet_id, uint8_t prefixlen)
- : Lease(addr, t1, t2, valid, subnet_id, 0/*cltt*/),
- type_(type), prefixlen_(prefixlen), iaid_(iaid), duid_(duid),
- preferred_lft_(preferred) {
- if (!duid) {
- isc_throw(InvalidOperation, "DUID must be specified for a lease");
- }
-
- cltt_ = time(NULL);
-}
-
-bool Lease::expired() const {
-
- // Let's use int64 to avoid problems with negative/large uint32 values
- int64_t expire_time = cltt_ + valid_lft_;
- return (expire_time < time(NULL));
-}
-
-
std::string LeaseMgr::getParameter(const std::string& name) const {
ParameterMap::const_iterator param = parameters_.find(name);
if (param == parameters_.end()) {
@@ -67,101 +40,21 @@ std::string LeaseMgr::getParameter(const std::string& name) const {
return (param->second);
}
-std::string
-Lease6::toText() const {
- ostringstream stream;
+Lease6Ptr
+LeaseMgr::getLease6(Lease::Type type, const DUID& duid,
+ uint32_t iaid, SubnetID subnet_id) const {
+ Lease6Collection col = getLeases6(type, duid, iaid, subnet_id);
- stream << "Type: " << static_cast<int>(type_) << " (";
- switch (type_) {
- case Lease6::LEASE_IA_NA:
- stream << "IA_NA)\n";
- break;
- case Lease6::LEASE_IA_TA:
- stream << "IA_TA)\n";
- break;
- case Lease6::LEASE_IA_PD:
- stream << "IA_PD)\n";
- break;
- default:
- stream << "unknown)\n";
+ if (col.size() > 1) {
+ isc_throw(MultipleRecords, "More than one lease found for type "
+ << static_cast<int>(type) << ", duid "
+ << duid.toText() << ", iaid " << iaid
+ << " and subnet-id " << subnet_id);
}
- stream << "Address: " << addr_.toText() << "\n"
- << "Prefix length: " << static_cast<int>(prefixlen_) << "\n"
- << "IAID: " << iaid_ << "\n"
- << "Pref life: " << preferred_lft_ << "\n"
- << "Valid life: " << valid_lft_ << "\n"
- << "Cltt: " << cltt_ << "\n"
- << "Subnet ID: " << subnet_id_ << "\n";
-
- return (stream.str());
-}
-
-std::string
-Lease4::toText() const {
- ostringstream stream;
-
- stream << "Address: " << addr_.toText() << "\n"
- << "Valid life: " << valid_lft_ << "\n"
- << "T1: " << t1_ << "\n"
- << "T2: " << t2_ << "\n"
- << "Cltt: " << cltt_ << "\n"
- << "Subnet ID: " << subnet_id_ << "\n";
-
- return (stream.str());
-}
-
-
-bool
-Lease4::operator==(const Lease4& other) const {
- if ( (client_id_ && !other.client_id_) ||
- (!client_id_ && other.client_id_) ) {
- // One lease has client-id, but the other doesn't
- return false;
+ if (col.empty()) {
+ return (Lease6Ptr());
}
-
- if (client_id_ && other.client_id_ &&
- *client_id_ != *other.client_id_) {
- // Different client-ids
- return false;
- }
-
- return (
- addr_ == other.addr_ &&
- ext_ == other.ext_ &&
- hwaddr_ == other.hwaddr_ &&
- t1_ == other.t1_ &&
- t2_ == other.t2_ &&
- valid_lft_ == other.valid_lft_ &&
- cltt_ == other.cltt_ &&
- subnet_id_ == other.subnet_id_ &&
- fixed_ == other.fixed_ &&
- hostname_ == other.hostname_ &&
- fqdn_fwd_ == other.fqdn_fwd_ &&
- fqdn_rev_ == other.fqdn_rev_ &&
- comments_ == other.comments_
- );
-}
-
-bool
-Lease6::operator==(const Lease6& other) const {
- return (
- addr_ == other.addr_ &&
- type_ == other.type_ &&
- prefixlen_ == other.prefixlen_ &&
- iaid_ == other.iaid_ &&
- *duid_ == *other.duid_ &&
- preferred_lft_ == other.preferred_lft_ &&
- valid_lft_ == other.valid_lft_ &&
- t1_ == other.t1_ &&
- t2_ == other.t2_ &&
- cltt_ == other.cltt_ &&
- subnet_id_ == other.subnet_id_ &&
- fixed_ == other.fixed_ &&
- hostname_ == other.hostname_ &&
- fqdn_fwd_ == other.fqdn_fwd_ &&
- fqdn_rev_ == other.fqdn_rev_ &&
- comments_ == other.comments_
- );
+ return (*col.begin());
}
} // namespace isc::dhcp