Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Sebastian Schrader
Kea
Commits
37af2830
Commit
37af2830
authored
Aug 27, 2013
by
Marcin Siodelski
Browse files
[master] Merge branch 'trac3083'
parents
0607a3ac
8c203f0a
Changes
10
Hide whitespace changes
Inline
Side-by-side
src/bin/dhcp4/dhcp4_srv.cc
View file @
37af2830
...
...
@@ -715,9 +715,13 @@ Dhcpv4Srv::assignLease(const Pkt4Ptr& question, Pkt4Ptr& answer) {
// will try to honour the hint, but it is just a hint - some other address
// may be used instead. If fake_allocation is set to false, the lease will
// be inserted into the LeaseMgr as well.
// @todo pass the actual FQDN data.
Lease4Ptr
old_lease
;
Lease4Ptr
lease
=
alloc_engine_
->
allocateAddress4
(
subnet
,
client_id
,
hwaddr
,
hint
,
fake_allocation
,
callout_handle
);
hint
,
false
,
false
,
""
,
fake_allocation
,
callout_handle
,
old_lease
);
if
(
lease
)
{
// We have a lease! Let's set it in the packet and send it back to
...
...
src/lib/dhcpsrv/alloc_engine.cc
View file @
37af2830
...
...
@@ -93,7 +93,7 @@ AllocEngine::IterativeAllocator::pickAddress(const SubnetPtr& subnet,
// Let's get the last allocated address. It is usually set correctly,
// but there are times when it won't be (like after removing a pool or
// perhaps restaring the server).
// perhaps restar
t
ing the server).
IOAddress
last
=
subnet
->
getLastAllocated
();
const
PoolCollection
&
pools
=
subnet
->
getPools
();
...
...
@@ -140,7 +140,7 @@ AllocEngine::IterativeAllocator::pickAddress(const SubnetPtr& subnet,
return
(
next
);
}
// there is a next pool, let's try first add
d
ress from it
// there is a next pool, let's try first address from it
next
=
(
*
it
)
->
getFirstAddress
();
subnet
->
setLastAllocated
(
next
);
return
(
next
);
...
...
@@ -330,8 +330,17 @@ AllocEngine::allocateAddress4(const SubnetPtr& subnet,
const
ClientIdPtr
&
clientid
,
const
HWAddrPtr
&
hwaddr
,
const
IOAddress
&
hint
,
const
bool
fwd_dns_update
,
const
bool
rev_dns_update
,
const
std
::
string
&
hostname
,
bool
fake_allocation
,
const
isc
::
hooks
::
CalloutHandlePtr
&
callout_handle
)
{
const
isc
::
hooks
::
CalloutHandlePtr
&
callout_handle
,
Lease4Ptr
&
old_lease
)
{
// The NULL pointer indicates that the old lease didn't exist. It may
// be later set to non NULL value if existing lease is found in the
// database.
old_lease
.
reset
();
try
{
// Allocator is always created in AllocEngine constructor and there is
...
...
@@ -351,10 +360,13 @@ AllocEngine::allocateAddress4(const SubnetPtr& subnet,
// Check if there's existing lease for that subnet/clientid/hwaddr combination.
Lease4Ptr
existing
=
LeaseMgrFactory
::
instance
().
getLease4
(
*
hwaddr
,
subnet
->
getID
());
if
(
existing
)
{
// Save the old lease, before renewal.
old_lease
.
reset
(
new
Lease4
(
*
existing
));
// We have a lease already. This is a returning client, probably after
// its reboot.
existing
=
renewLease4
(
subnet
,
clientid
,
hwaddr
,
existing
,
callout_handle
,
fake_allocation
);
existing
=
renewLease4
(
subnet
,
clientid
,
hwaddr
,
fwd_dns_update
,
rev_dns_update
,
hostname
,
existing
,
callout_handle
,
fake_allocation
);
if
(
existing
)
{
return
(
existing
);
}
...
...
@@ -366,9 +378,13 @@ AllocEngine::allocateAddress4(const SubnetPtr& subnet,
if
(
clientid
)
{
existing
=
LeaseMgrFactory
::
instance
().
getLease4
(
*
clientid
,
subnet
->
getID
());
if
(
existing
)
{
// Save the old lease before renewal.
old_lease
.
reset
(
new
Lease4
(
*
existing
));
// we have a lease already. This is a returning client, probably after
// its reboot.
existing
=
renewLease4
(
subnet
,
clientid
,
hwaddr
,
existing
,
callout_handle
,
existing
=
renewLease4
(
subnet
,
clientid
,
hwaddr
,
fwd_dns_update
,
rev_dns_update
,
hostname
,
existing
,
callout_handle
,
fake_allocation
);
// @todo: produce a warning. We haven't found him using MAC address, but
// we found him using client-id
...
...
@@ -387,7 +403,9 @@ AllocEngine::allocateAddress4(const SubnetPtr& subnet,
// The hint is valid and not currently used, let's create a lease for it
Lease4Ptr
lease
=
createLease4
(
subnet
,
clientid
,
hwaddr
,
hint
,
callout_handle
,
fake_allocation
);
fwd_dns_update
,
rev_dns_update
,
hostname
,
callout_handle
,
fake_allocation
);
// It can happen that the lease allocation failed (we could have lost
// the race condition. That means that the hint is lo longer usable and
...
...
@@ -397,8 +415,12 @@ AllocEngine::allocateAddress4(const SubnetPtr& subnet,
}
}
else
{
if
(
existing
->
expired
())
{
// Save the old lease, before reusing it.
old_lease
.
reset
(
new
Lease4
(
*
existing
));
return
(
reuseExpiredLease
(
existing
,
subnet
,
clientid
,
hwaddr
,
callout_handle
,
fake_allocation
));
fwd_dns_update
,
rev_dns_update
,
hostname
,
callout_handle
,
fake_allocation
));
}
}
...
...
@@ -431,7 +453,9 @@ AllocEngine::allocateAddress4(const SubnetPtr& subnet,
if
(
!
existing
)
{
// there's no existing lease for selected candidate, so it is
// free. Let's allocate it.
Lease4Ptr
lease
=
createLease4
(
subnet
,
clientid
,
hwaddr
,
candidate
,
Lease4Ptr
lease
=
createLease4
(
subnet
,
clientid
,
hwaddr
,
candidate
,
fwd_dns_update
,
rev_dns_update
,
hostname
,
callout_handle
,
fake_allocation
);
if
(
lease
)
{
return
(
lease
);
...
...
@@ -442,8 +466,12 @@ AllocEngine::allocateAddress4(const SubnetPtr& subnet,
// allocation attempts.
}
else
{
if
(
existing
->
expired
())
{
// Save old lease before reusing it.
old_lease
.
reset
(
new
Lease4
(
*
existing
));
return
(
reuseExpiredLease
(
existing
,
subnet
,
clientid
,
hwaddr
,
callout_handle
,
fake_allocation
));
fwd_dns_update
,
rev_dns_update
,
hostname
,
callout_handle
,
fake_allocation
));
}
}
...
...
@@ -466,6 +494,9 @@ AllocEngine::allocateAddress4(const SubnetPtr& subnet,
Lease4Ptr
AllocEngine
::
renewLease4
(
const
SubnetPtr
&
subnet
,
const
ClientIdPtr
&
clientid
,
const
HWAddrPtr
&
hwaddr
,
const
bool
fwd_dns_update
,
const
bool
rev_dns_update
,
const
std
::
string
&
hostname
,
const
Lease4Ptr
&
lease
,
const
isc
::
hooks
::
CalloutHandlePtr
&
callout_handle
,
bool
fake_allocation
/* = false */
)
{
...
...
@@ -487,6 +518,9 @@ Lease4Ptr AllocEngine::renewLease4(const SubnetPtr& subnet,
lease
->
t1_
=
subnet
->
getT1
();
lease
->
t2_
=
subnet
->
getT2
();
lease
->
valid_lft_
=
subnet
->
getValid
();
lease
->
fqdn_fwd_
=
fwd_dns_update
;
lease
->
fqdn_rev_
=
rev_dns_update
;
lease
->
hostname_
=
hostname
;
bool
skip
=
false
;
// Execute all callouts registered for packet6_send
...
...
@@ -615,6 +649,9 @@ Lease4Ptr AllocEngine::reuseExpiredLease(Lease4Ptr& expired,
const
SubnetPtr
&
subnet
,
const
ClientIdPtr
&
clientid
,
const
HWAddrPtr
&
hwaddr
,
const
bool
fwd_dns_update
,
const
bool
rev_dns_update
,
const
std
::
string
&
hostname
,
const
isc
::
hooks
::
CalloutHandlePtr
&
callout_handle
,
bool
fake_allocation
/*= false */
)
{
...
...
@@ -631,9 +668,9 @@ Lease4Ptr AllocEngine::reuseExpiredLease(Lease4Ptr& expired,
expired
->
cltt_
=
time
(
NULL
);
expired
->
subnet_id_
=
subnet
->
getID
();
expired
->
fixed_
=
false
;
expired
->
hostname_
=
std
::
string
(
""
)
;
expired
->
fqdn_fwd_
=
f
als
e
;
expired
->
fqdn_rev_
=
fals
e
;
expired
->
hostname_
=
hostname
;
expired
->
fqdn_fwd_
=
f
wd_dns_updat
e
;
expired
->
fqdn_rev_
=
rev_dns_updat
e
;
/// @todo: log here that the lease was reused (there's ticket #2524 for
/// logging in libdhcpsrv)
...
...
@@ -771,6 +808,9 @@ Lease4Ptr AllocEngine::createLease4(const SubnetPtr& subnet,
const
DuidPtr
&
clientid
,
const
HWAddrPtr
&
hwaddr
,
const
IOAddress
&
addr
,
const
bool
fwd_dns_update
,
const
bool
rev_dns_update
,
const
std
::
string
&
hostname
,
const
isc
::
hooks
::
CalloutHandlePtr
&
callout_handle
,
bool
fake_allocation
/*= false */
)
{
if
(
!
hwaddr
)
{
...
...
@@ -789,6 +829,11 @@ Lease4Ptr AllocEngine::createLease4(const SubnetPtr& subnet,
subnet
->
getT1
(),
subnet
->
getT2
(),
now
,
subnet
->
getID
()));
// Set FQDN specific lease parameters.
lease
->
fqdn_fwd_
=
fwd_dns_update
;
lease
->
fqdn_rev_
=
rev_dns_update
;
lease
->
hostname_
=
hostname
;
// Let's execute all callouts registered for lease4_select
if
(
callout_handle
&&
HooksManager
::
getHooksManager
().
calloutsPresent
(
hook_index_lease4_select_
))
{
...
...
@@ -827,8 +872,6 @@ Lease4Ptr AllocEngine::createLease4(const SubnetPtr& subnet,
callout_handle
->
getArgument
(
"lease4"
,
lease
);
}
if
(
!
fake_allocation
)
{
// That is a real (REQUEST) allocation
bool
status
=
LeaseMgrFactory
::
instance
().
addLease
(
lease
);
...
...
src/lib/dhcpsrv/alloc_engine.h
View file @
37af2830
...
...
@@ -182,28 +182,63 @@ protected:
/// we give up (0 means unlimited)
AllocEngine
(
AllocType
engine_type
,
unsigned
int
attempts
);
/// @brief
Allocates an
IPv4 lease
/// @brief
Returns
IPv4 lease
.
///
/// This method uses currently selected allocator to pick an address from
/// specified subnet, creates a lease for that address and then inserts
/// it into LeaseMgr (if this allocation is not fake).
/// This method finds the appropriate lease for the client using the
/// following algorithm:
/// - If lease exists for the combination of the HW address, client id and
/// subnet, try to renew a lease and return it.
/// - If lease exists for the combination of the client id and subnet, try
/// to renew the lease and return it.
/// - If client supplied an address hint and this address is available,
/// allocate the new lease with this address.
/// - If client supplied an address hint and the lease for this address
/// exists in the database, return this lease if it is expired.
/// - Pick new address from the pool and try to allocate it for the client,
/// if expired lease exists for the picked address, try to reuse this lease.
///
/// When a server should do DNS updates, it is required that allocation
/// returns the information how the lease was obtained by the allocation
/// engine. In particular, the DHCP server should be able to check whether
/// existing lease was returned, or new lease was allocated. When existing
/// lease was returned, server should check whether the FQDN has changed
/// between the allocation of the old and new lease. If so, server should
/// perform appropriate DNS update. If not, server may choose to not
/// perform the update. The information about the old lease is returned via
/// @c old_lease parameter. If NULL value is returned, it is an indication
/// that new lease was allocated for the client. If non-NULL value is
/// returned, it is an indication that allocation engine reused/renewed an
/// existing lease.
///
/// @param subnet subnet the allocation should come from
/// @param clientid Client identifier
/// @param hwaddr client's hardware address info
/// @param hint a hint that the client provided
/// @param fake_allocation is this real i.e. REQUEST (false) or just picking
/// @param hwaddr Client's hardware address info
/// @param hint A hint that the client provided
/// @param fwd_dns_update Indicates whether forward DNS update will be
/// performed for the client (true) or not (false).
/// @param rev_dns_update Indicates whether reverse DNS update will be
/// performed for the client (true) or not (false).
/// @param hostname A string carrying hostname to be used for DNS updates.
/// @param fake_allocation Is this real i.e. REQUEST (false) or just picking
/// an address for DISCOVER that is not really allocated (true)
/// @param callout_handle
a
callout handle (used in hooks). A lease callouts
/// @param callout_handle
A
callout handle (used in hooks). A lease callouts
/// will be executed if this parameter is passed.
/// @param [out] old_lease Holds the pointer to a previous instance of a
/// lease. The NULL pointer indicates that lease didn't exist prior
/// to calling this function (e.g. new lease has been allocated).
///
/// @return Allocated IPv4 lease (or NULL if allocation failed)
Lease4Ptr
allocateAddress4
(
const
SubnetPtr
&
subnet
,
const
ClientIdPtr
&
clientid
,
const
HWAddrPtr
&
hwaddr
,
const
isc
::
asiolink
::
IOAddress
&
hint
,
const
bool
fwd_dns_update
,
const
bool
rev_dns_update
,
const
std
::
string
&
hostname
,
bool
fake_allocation
,
const
isc
::
hooks
::
CalloutHandlePtr
&
callout_handle
);
const
isc
::
hooks
::
CalloutHandlePtr
&
callout_handle
,
Lease4Ptr
&
old_lease
);
/// @brief Renews a IPv4 lease
///
...
...
@@ -214,18 +249,26 @@ protected:
/// to get a new lease. It thinks that it gets a new lease, but in fact
/// we are only renewing the still valid lease for that client.
///
/// @param subnet subnet the client is attached to
/// @param clientid client identifier
/// @param hwaddr client's hardware address
/// @param lease lease to be renewed
/// @param subnet A subnet the client is attached to
/// @param clientid Client identifier
/// @param hwaddr Client's hardware address
/// @param fwd_dns_update Indicates whether forward DNS update will be
/// performed for the client (true) or not (false).
/// @param rev_dns_update Indicates whether reverse DNS update will be
/// performed for the client (true) or not (false).
/// @param hostname A string carrying hostname to be used for DNS updates.
/// @param lease A lease to be renewed
/// @param callout_handle a callout handle (used in hooks). A lease callouts
/// will be executed if this parameter is passed.
/// @param fake_allocation
i
s this real i.e. REQUEST (false) or just picking
/// @param fake_allocation
I
s this real i.e. REQUEST (false) or just picking
/// an address for DISCOVER that is not really allocated (true)
Lease4Ptr
renewLease4
(
const
SubnetPtr
&
subnet
,
const
ClientIdPtr
&
clientid
,
const
HWAddrPtr
&
hwaddr
,
const
bool
fwd_dns_update
,
const
bool
rev_dns_update
,
const
std
::
string
&
hostname
,
const
Lease4Ptr
&
lease
,
const
isc
::
hooks
::
CalloutHandlePtr
&
callout_handle
,
bool
fake_allocation
/* = false */
);
...
...
@@ -241,9 +284,11 @@ protected:
/// @param iaid iaid field from the IA_NA container that client sent
/// @param hint a hint that the client provided
/// @param fwd_dns_update A boolean value which indicates that server takes
/// responisibility for the forward DNS Update for this lease (if true).
/// responsibility for the forward DNS Update for this lease
/// (if true).
/// @param rev_dns_update A boolean value which indicates that server takes
/// responibility for the reverse DNS Update for this lease (if true).
/// responsibility for the reverse DNS Update for this lease
/// (if true).
/// @param hostname A fully qualified domain-name of the client.
/// @param fake_allocation is this real i.e. REQUEST (false) or just picking
/// an address for SOLICIT that is not really allocated (true)
...
...
@@ -272,20 +317,28 @@ private:
/// into the database. That may fail in some cases, e.g. when there is another
/// allocation process and we lost a race to a specific lease.
///
/// @param subnet subnet the lease is allocated from
/// @param clientid client identifier
/// @param hwaddr client's hardware address
/// @param addr an address that was selected and is confirmed to be available
/// @param subnet Subnet the lease is allocated from
/// @param clientid Client identifier
/// @param hwaddr Client's hardware address
/// @param addr An address that was selected and is confirmed to be available
/// @param fwd_dns_update Indicates whether forward DNS update will be
/// performed for the client (true) or not (false).
/// @param rev_dns_update Indicates whether reverse DNS update will be
/// performed for the client (true) or not (false).
/// @param hostname A string carrying hostname to be used for DNS updates.
/// @param callout_handle a callout handle (used in hooks). A lease callouts
/// will be executed if this parameter is passed (and there are callouts
/// registered)
/// @param fake_allocation
i
s this real i.e. REQUEST (false) or just picking
/// @param fake_allocation
I
s this real i.e. REQUEST (false) or just picking
/// an address for DISCOVER that is not really allocated (true)
/// @return allocated lease (or NULL in the unlikely case of the lease just
/// becomed unavailable)
Lease4Ptr
createLease4
(
const
SubnetPtr
&
subnet
,
const
DuidPtr
&
clientid
,
const
HWAddrPtr
&
hwaddr
,
const
isc
::
asiolink
::
IOAddress
&
addr
,
const
bool
fwd_dns_update
,
const
bool
rev_dns_update
,
const
std
::
string
&
hostname
,
const
isc
::
hooks
::
CalloutHandlePtr
&
callout_handle
,
bool
fake_allocation
=
false
);
...
...
@@ -301,9 +354,11 @@ private:
/// @param addr an address that was selected and is confirmed to be
/// available
/// @param fwd_dns_update A boolean value which indicates that server takes
/// responisibility for the forward DNS Update for this lease (if true).
/// responsibility for the forward DNS Update for this lease
/// (if true).
/// @param rev_dns_update A boolean value which indicates that server takes
/// responibility for the reverse DNS Update for this lease (if true).
/// responsibility for the reverse DNS Update for this lease
/// (if true).
/// @param hostname A fully qualified domain-name of the client.
/// @param callout_handle a callout handle (used in hooks). A lease callouts
/// will be executed if this parameter is passed (and there are callouts
...
...
@@ -311,7 +366,7 @@ private:
/// @param fake_allocation is this real i.e. REQUEST (false) or just picking
/// an address for SOLICIT that is not really allocated (true)
/// @return allocated lease (or NULL in the unlikely case of the lease just
/// bec
o
me
d
unavailable)
///
bec
a
me unavailable)
Lease6Ptr
createLease6
(
const
Subnet6Ptr
&
subnet
,
const
DuidPtr
&
duid
,
uint32_t
iaid
,
const
isc
::
asiolink
::
IOAddress
&
addr
,
const
bool
fwd_dns_update
,
const
bool
rev_dns_update
,
...
...
@@ -325,19 +380,28 @@ private:
/// is updated if this is real (i.e. REQUEST, fake_allocation = false), not
/// dummy allocation request (i.e. DISCOVER, fake_allocation = true).
///
/// @param expired old, expired lease
/// @param subnet subnet the lease is allocated from
/// @param clientid client identifier
/// @param hwaddr client's hardware address
/// @param callout_handle a callout handle (used in hooks). A lease callouts
/// @param expired Old, expired lease
/// @param subnet Subnet the lease is allocated from
/// @param clientid Client identifier
/// @param hwaddr Client's hardware address
/// @param fwd_dns_update Indicates whether forward DNS update will be
/// performed for the client (true) or not (false).
/// @param rev_dns_update Indicates whether reverse DNS update will be
/// performed for the client (true) or not (false).
/// @param hostname A string carrying hostname to be used for DNS updates.
/// @param callout_handle A callout handle (used in hooks). A lease callouts
/// will be executed if this parameter is passed.
/// @param fake_allocation
i
s this real i.e. REQUEST (false) or just picking
/// @param fake_allocation
I
s this real i.e. REQUEST (false) or just picking
/// an address for DISCOVER that is not really allocated (true)
/// @return refreshed lease
/// @throw BadValue if trying to recycle lease that is still valid
Lease4Ptr
reuseExpiredLease
(
Lease4Ptr
&
expired
,
const
SubnetPtr
&
subnet
,
Lease4Ptr
reuseExpiredLease
(
Lease4Ptr
&
expired
,
const
SubnetPtr
&
subnet
,
const
ClientIdPtr
&
clientid
,
const
HWAddrPtr
&
hwaddr
,
const
bool
fwd_dns_update
,
const
bool
rev_dns_update
,
const
std
::
string
&
hostname
,
const
isc
::
hooks
::
CalloutHandlePtr
&
callout_handle
,
bool
fake_allocation
=
false
);
...
...
@@ -352,9 +416,11 @@ private:
/// @param duid client's DUID
/// @param iaid IAID from the IA_NA container the client sent to us
/// @param fwd_dns_update A boolean value which indicates that server takes
/// responisibility for the forward DNS Update for this lease (if true).
/// responsibility for the forward DNS Update for this lease
/// (if true).
/// @param rev_dns_update A boolean value which indicates that server takes
/// responibility for the reverse DNS Update for this lease (if true).
/// responsibility for the reverse DNS Update for this lease
/// (if true).
/// @param hostname A fully qualified domain-name of the client.
/// @param callout_handle a callout handle (used in hooks). A lease callouts
/// will be executed if this parameter is passed.
...
...
src/lib/dhcpsrv/lease_mgr.cc
View file @
37af2830
...
...
@@ -38,6 +38,52 @@ Lease::Lease(const isc::asiolink::IOAddress& addr, uint32_t t1, uint32_t t2,
subnet_id_
(
subnet_id
),
fixed_
(
false
),
fqdn_fwd_
(
false
),
fqdn_rev_
(
false
)
{
}
Lease4
::
Lease4
(
const
Lease4
&
other
)
:
Lease
(
other
.
addr_
,
other
.
t1_
,
other
.
t2_
,
other
.
valid_lft_
,
other
.
subnet_id_
,
other
.
cltt_
),
ext_
(
other
.
ext_
),
hwaddr_
(
other
.
hwaddr_
)
{
fixed_
=
other
.
fixed_
;
fqdn_fwd_
=
other
.
fqdn_fwd_
;
fqdn_rev_
=
other
.
fqdn_rev_
;
hostname_
=
other
.
hostname_
;
comments_
=
other
.
comments_
;
if
(
other
.
client_id_
)
{
client_id_
.
reset
(
new
ClientId
(
other
.
client_id_
->
getClientId
()));
}
else
{
client_id_
.
reset
();
}
}
Lease4
&
Lease4
::
operator
=
(
const
Lease4
&
other
)
{
if
(
this
!=
&
other
)
{
addr_
=
other
.
addr_
;
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_
;
ext_
=
other
.
ext_
;
hwaddr_
=
other
.
hwaddr_
;
if
(
other
.
client_id_
)
{
client_id_
.
reset
(
new
ClientId
(
other
.
client_id_
->
getClientId
()));
}
else
{
client_id_
.
reset
();
}
}
return
(
*
this
);
}
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
)
...
...
src/lib/dhcpsrv/lease_mgr.h
View file @
37af2830
// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2012
-2013
Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
...
...
@@ -259,6 +259,16 @@ struct Lease4 : public Lease {
Lease4
()
:
Lease
(
0
,
0
,
0
,
0
,
0
,
0
)
{
}
/// @brief Copy constructor
///
/// @param other the @c Lease4 object to be copied.
Lease4
(
const
Lease4
&
other
);
/// @brief Assignment operator.
///
/// @param other the @c Lease4 object to be assigned.
Lease4
&
operator
=
(
const
Lease4
&
other
);
/// @brief Compare two leases for equality
///
/// @param other lease6 object with which to compare
...
...
src/lib/dhcpsrv/memfile_lease_mgr.cc
View file @
37af2830
...
...
@@ -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
)
{
...
...
src/lib/dhcpsrv/memfile_lease_mgr.h
View file @
37af2830
...
...
@@ -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 lease
s
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.