Commit 231fed6c authored by Marcin Siodelski's avatar Marcin Siodelski

[3083] Return a copy of the lease when getLease is called.

Also, updateLease4 and updateLease6 are implemented.
parent bf6d6bcd
......@@ -62,7 +62,7 @@ Lease4Ptr Memfile_LeaseMgr::getLease4(const isc::asiolink::IOAddress& addr) cons
if (l == storage4_.end()) {
return (Lease4Ptr());
} else {
return (*l);
return (Lease4Ptr(new Lease4(**l)));
}
}
......@@ -94,7 +94,7 @@ Lease4Ptr Memfile_LeaseMgr::getLease4(const HWAddr& hwaddr,
}
// Lease was found. Return it to the caller.
return (*lease);
return (Lease4Ptr(new Lease4(**lease)));
}
Lease4Collection Memfile_LeaseMgr::getLease4(const ClientId& clientid) const {
......@@ -123,11 +123,11 @@ Lease4Ptr Memfile_LeaseMgr::getLease4(const ClientId& client_id,
return Lease4Ptr();
}
// Lease was found. Return it to the caller.
return (*lease);
return (Lease4Ptr(new Lease4(**lease)));
}
Lease6Ptr Memfile_LeaseMgr::getLease6(
const isc::asiolink::IOAddress& addr) const {
Lease6Ptr
Memfile_LeaseMgr::getLease6(const isc::asiolink::IOAddress& addr) const {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
DHCPSRV_MEMFILE_GET_ADDR6).arg(addr.toText());
......@@ -135,7 +135,7 @@ Lease6Ptr Memfile_LeaseMgr::getLease6(
if (l == storage6_.end()) {
return (Lease6Ptr());
} else {
return (*l);
return (Lease6Ptr(new Lease6(**l)));
}
}
......@@ -167,20 +167,31 @@ Lease6Ptr Memfile_LeaseMgr::getLease6(const DUID& duid, uint32_t iaid,
return (Lease6Ptr());
}
// Lease was found, return it to the caller.
return (*lease);
return (Lease6Ptr(new Lease6(**lease)));
}
void Memfile_LeaseMgr::updateLease4(const Lease4Ptr& lease) {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
DHCPSRV_MEMFILE_UPDATE_ADDR4).arg(lease->addr_.toText());
Lease4Storage::iterator lease_it = storage4_.find(lease->addr_);
if (lease_it == storage4_.end()) {
isc_throw(NoSuchLease, "failed to update the lease with address "
<< lease->addr_.toText() << " - no such lease");
}
**lease_it = *lease;
}
void Memfile_LeaseMgr::updateLease6(const Lease6Ptr& lease) {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
DHCPSRV_MEMFILE_UPDATE_ADDR6).arg(lease->addr_.toText());
Lease6Storage::iterator lease_it = storage6_.find(lease->addr_);
if (lease_it == storage6_.end()) {
isc_throw(NoSuchLease, "failed to update the lease with address "
<< lease->addr_.toText() << " - no such lease");
}
**lease_it = *lease;
}
bool Memfile_LeaseMgr::deleteLease(const isc::asiolink::IOAddress& addr) {
......
......@@ -65,8 +65,10 @@ public:
/// @brief Returns existing IPv4 lease for specified IPv4 address.
///
/// @todo Not implemented yet
/// @param addr address of the searched lease
/// This function returns a copy of the lease. The modification in the
/// return lease does not affect the instance held in the lease storage.
///
/// @param addr An address of the searched lease.
///
/// @return a collection of leases
virtual Lease4Ptr getLease4(const isc::asiolink::IOAddress& addr) const;
......@@ -85,10 +87,11 @@ public:
/// @return lease collection
virtual Lease4Collection getLease4(const isc::dhcp::HWAddr& hwaddr) const;
/// @brief Returns existing IPv4 leases for specified hardware address
/// @brief Returns existing IPv4 lease for specified hardware address
/// and a subnet
///
/// @todo Not implemented yet
/// This function returns a copy of the lease. The modification in the
/// return lease does not affect the instance held in the lease storage.
///
/// There can be at most one lease for a given HW address in a single
/// pool, so this method with either return a single lease or NULL.
......@@ -109,11 +112,12 @@ public:
/// @brief Returns existing IPv4 lease for specified client-id
///
/// This function returns a copy of the lease. The modification in the
/// return lease does not affect the instance held in the lease storage.
///
/// There can be at most one lease for a given HW address in a single
/// pool, so this method with either return a single lease or NULL.
///
/// @todo Not implemented yet
///
/// @param clientid client identifier
/// @param subnet_id identifier of the subnet that lease must belong to
///
......@@ -123,7 +127,10 @@ public:
/// @brief Returns existing IPv6 lease for a given IPv6 address.
///
/// @param addr address of the searched lease
/// This function returns a copy of the lease. The modification in the
/// return lease does not affect the instance held in the lease storage.
///
/// @param addr An address of the searched lease.
///
/// @return smart pointer to the lease (or NULL if a lease is not found)
virtual Lease6Ptr getLease6(const isc::asiolink::IOAddress& addr) const;
......@@ -140,27 +147,31 @@ public:
/// @brief Returns existing IPv6 lease for a given DUID+IA combination
///
/// @todo Not implemented yet
/// This function returns a copy of the lease. The modification in the
/// return lease does not affect the instance held in the lease storage.
///
/// @param duid client DUID
/// @param iaid IA identifier
/// @param subnet_id identifier of the subnet the lease must belong to
///
/// @return smart pointer to the lease (or NULL if a lease is not found)
virtual Lease6Ptr getLease6(const DUID& duid, uint32_t iaid, SubnetID subnet_id) const;
virtual Lease6Ptr getLease6(const DUID& duid, uint32_t iaid,
SubnetID subnet_id) const;
/// @brief Updates IPv4 lease.
///
/// @todo Not implemented yet
/// @warning This function does not validate the pointer to the lease.
/// It is caller's responsibility to pass the valid pointer.
///
/// @param lease4 The lease to be updated.
///
/// If no such lease is present, an exception will be thrown.
virtual void updateLease4(const Lease4Ptr& lease4);
/// @brief Updates IPv4 lease.
/// @brief Updates IPv6 lease.
///
/// @todo Not implemented yet
/// @warning This function does not validate the pointer to the lease.
/// It is caller's responsibility to pass the valid pointer.
///
/// @param lease6 The lease to be updated.
///
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment