Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ISC Open Source Projects
Kea
Commits
9c8ff76f
Commit
9c8ff76f
authored
Mar 03, 2015
by
Tomek Mrugalski
🛰
Browse files
[3709] createLease4() now uses ClientContext4
parent
7394da5b
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/lib/dhcpsrv/alloc_engine.cc
View file @
9c8ff76f
...
...
@@ -926,13 +926,7 @@ AllocEngine::allocateLease4(ClientContext4& ctx) {
if
(
!
existing
)
{
// The candidate address is currently unused. Let's create a
// lease for it.
Lease4Ptr
lease
=
createLease4
(
ctx
.
subnet_
,
ctx
.
clientid_
,
ctx
.
hwaddr_
,
candidate
,
ctx
.
fwd_dns_update_
,
ctx
.
rev_dns_update_
,
ctx
.
hostname_
,
ctx
.
callout_handle_
,
ctx
.
fake_allocation_
);
Lease4Ptr
lease
=
createLease4
(
ctx
,
candidate
);
// If we have allocated the lease let's return it. Also,
// always return when tried to allocate reserved address,
...
...
@@ -995,10 +989,7 @@ AllocEngine::allocateLease4(ClientContext4& ctx) {
if
(
!
existing
)
{
// there's no existing lease for selected candidate, so it is
// free. Let's allocate it.
Lease4Ptr
lease
=
createLease4
(
ctx
.
subnet_
,
ctx
.
clientid_
,
ctx
.
hwaddr_
,
candidate
,
ctx
.
fwd_dns_update_
,
ctx
.
rev_dns_update_
,
ctx
.
hostname_
,
ctx
.
callout_handle_
,
ctx
.
fake_allocation_
);
Lease4Ptr
lease
=
createLease4
(
ctx
,
candidate
);
if
(
lease
)
{
return
(
lease
);
}
...
...
@@ -1457,41 +1448,39 @@ Lease6Ptr AllocEngine::createLease6(ClientContext6& ctx,
}
}
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
)
{
Lease4Ptr
AllocEngine
::
createLease4
(
const
ClientContext4
&
ctx
,
const
IOAddress
&
addr
)
{
if
(
!
ctx
.
hwaddr_
)
{
isc_throw
(
BadValue
,
"Can't create a lease with NULL HW address"
);
}
if
(
!
ctx
.
subnet_
)
{
isc_throw
(
BadValue
,
"Can't create a lease without a subnet"
);
}
time_t
now
=
time
(
NULL
);
// @todo: remove this kludge after ticket #2590 is implemented
std
::
vector
<
uint8_t
>
local_copy
;
if
(
clientid
)
{
local_copy
=
clientid
->
getDuid
();
if
(
ctx
.
clientid
_
)
{
local_copy
=
ctx
.
clientid
_
->
getDuid
();
}
Lease4Ptr
lease
(
new
Lease4
(
addr
,
hwaddr
,
&
local_copy
[
0
],
local_copy
.
size
(),
subnet
->
getValid
(),
subnet
->
getT1
(),
subnet
->
getT2
(),
now
,
subnet
->
getID
()));
Lease4Ptr
lease
(
new
Lease4
(
addr
,
ctx
.
hwaddr_
,
&
local_copy
[
0
],
local_copy
.
size
(),
ctx
.
subnet_
->
getValid
(),
ctx
.
subnet_
->
getT1
(),
ctx
.
subnet_
->
getT2
(),
now
,
ctx
.
subnet_
->
getID
()));
// Set FQDN specific lease parameters.
lease
->
fqdn_fwd_
=
fwd_dns_update
;
lease
->
fqdn_rev_
=
rev_dns_update
;
lease
->
hostname_
=
hostname
;
lease
->
fqdn_fwd_
=
ctx
.
fwd_dns_update
_
;
lease
->
fqdn_rev_
=
ctx
.
rev_dns_update
_
;
lease
->
hostname_
=
ctx
.
hostname
_
;
// Let's execute all callouts registered for lease4_select
if
(
callout_handle
&&
if
(
ctx
.
callout_handle
_
&&
HooksManager
::
getHooksManager
().
calloutsPresent
(
hook_index_lease4_select_
))
{
// Delete all previous arguments
callout_handle
->
deleteAllArguments
();
ctx
.
callout_handle
_
->
deleteAllArguments
();
// Pass necessary arguments
...
...
@@ -1499,32 +1488,32 @@ Lease4Ptr AllocEngine::createLease4(const SubnetPtr& subnet,
// with using SubnetPtr to point to Subnet4 object. Users should not
// be confused with dynamic_pointer_casts. They should get a concrete
// pointer (Subnet4Ptr) pointing to a Subnet4 object.
Subnet4Ptr
subnet4
=
boost
::
dynamic_pointer_cast
<
Subnet4
>
(
subnet
);
callout_handle
->
setArgument
(
"subnet4"
,
subnet4
);
Subnet4Ptr
subnet4
=
boost
::
dynamic_pointer_cast
<
Subnet4
>
(
ctx
.
subnet
_
);
ctx
.
callout_handle
_
->
setArgument
(
"subnet4"
,
subnet4
);
// Is this solicit (fake = true) or request (fake = false)
callout_handle
->
setArgument
(
"fake_allocation"
,
fake_allocation
);
ctx
.
callout_handle
_
->
setArgument
(
"fake_allocation"
,
ctx
.
fake_allocation
_
);
// Pass the intended lease as well
callout_handle
->
setArgument
(
"lease4"
,
lease
);
ctx
.
callout_handle
_
->
setArgument
(
"lease4"
,
lease
);
// This is the first callout, so no need to clear any arguments
HooksManager
::
callCallouts
(
hook_index_lease4_select_
,
*
callout_handle
);
HooksManager
::
callCallouts
(
hook_index_lease4_select_
,
*
ctx
.
callout_handle
_
);
// Callouts decided to skip the action. This means that the lease is not
// assigned, so the client will get NoAddrAvail as a result. The lease
// won't be inserted into the database.
if
(
callout_handle
->
getSkip
())
{
if
(
ctx
.
callout_handle
_
->
getSkip
())
{
LOG_DEBUG
(
dhcpsrv_logger
,
DHCPSRV_DBG_HOOKS
,
DHCPSRV_HOOK_LEASE4_SELECT_SKIP
);
return
(
Lease4Ptr
());
}
// Let's use whatever callout returned. Hopefully it is the same lease
// we handled to it.
callout_handle
->
getArgument
(
"lease4"
,
lease
);
ctx
.
callout_handle
_
->
getArgument
(
"lease4"
,
lease
);
}
if
(
!
fake_allocation
)
{
if
(
!
ctx
.
fake_allocation
_
)
{
// That is a real (REQUEST) allocation
bool
status
=
LeaseMgrFactory
::
instance
().
addLease
(
lease
);
if
(
status
)
{
...
...
src/lib/dhcpsrv/alloc_engine.h
View file @
9c8ff76f
...
...
@@ -234,10 +234,11 @@ protected:
}
/// @brief Constructor with parameters
///
/// @param subnet subnet the allocation should come from (mandatory)
/// @param clientid Client identifier (optional)
/// @param hwaddr Client's hardware address info (mandatory)
/// @param
hint
A hint that the client provided (may be 0.0.0.0)
/// @param
requested_addr
A hint that the client provided (may be 0.0.0.0)
/// @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
...
...
@@ -586,7 +587,7 @@ protected:
/// @ref ClientContext4::subnet_ subnet the allocation should come from
/// @ref ClientContext4::clientid_ Client identifier
/// @ref ClientContext4::hwaddr_ Client's hardware address info
/// @ref ClientContext4::
hint
_ A hint that the client provided
/// @ref ClientContext4::
requested_address
_ A hint that the client provided
/// @ref ClientContext4::fwd_dns_update_ Indicates whether forward DNS
/// update will be performed for the client (true) or not (false).
/// @ref ClientContext4::rev_dns_update_ Indicates whether reverse DNS
...
...
@@ -702,7 +703,6 @@ protected:
Lease6Collection
allocateLeases6
(
ClientContext6
&
ctx
);
/// @brief Renews existing DHCPv6 leases for a given IA.
///
/// This method updates the leases associated with a specified IA container.
...
...
@@ -725,8 +725,6 @@ protected:
Lease6Collection
renewLeases6
(
ClientContext6
&
ctx
);
/// @brief returns allocator for a given pool type
/// @param type type of pool (V4, IA, TA or PD)
/// @throw BadValue if allocator for a given type is missing
...
...
@@ -743,30 +741,29 @@ 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 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 Is this real i.e. REQUEST (false) or just picking
/// an address for DISCOVER that is not really allocated (true)
/// @param ctx client context that contains additional parameters.
///
/// In particular, the following fields from Client context are used:
/// @ref ClientContext4::subnet_ Subnet the lease is allocated from
/// @ref ClientContext4::clientid_ Client identifier
/// @ref ClientContext4::hwaddr_ Client's hardware address
/// @ref ClientContext4::fwd_dns_update_ Indicates whether forward DNS update
/// will be performed for the client (true) or not (false).
/// @ref ClientContext4::rev_dns_update_ Indicates whether reverse DNS update
/// will be performed for the client (true) or not (false).
/// @ref ClientContext4::hostname_ A string carrying hostname to be used for
/// DNS updates.
/// @ref ClientContext4::callout_handle_ a callout handle (used in hooks).
/// A lease callouts will be executed if this parameter is passed
/// (and there are callouts registered)
/// @ref ClientContext4::fake_allocation_ Is 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
);
Lease4Ptr
createLease4
(
const
ClientContext4
&
ctx
,
const
isc
::
asiolink
::
IOAddress
&
addr
);
/// @brief Updates the specified lease with the information from a context.
///
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment