Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Kea
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
415
Issues
415
List
Boards
Labels
Service Desk
Milestones
Merge Requests
67
Merge Requests
67
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
ISC Open Source Projects
Kea
Commits
606b06ce
Commit
606b06ce
authored
Nov 13, 2013
by
Marcin Siodelski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[2940] Fixed handling of the NULL client identifier in the Memfile backend
parent
578392d0
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
47 additions
and
37 deletions
+47
-37
src/lib/dhcpsrv/lease.cc
src/lib/dhcpsrv/lease.cc
+9
-0
src/lib/dhcpsrv/lease.h
src/lib/dhcpsrv/lease.h
+6
-0
src/lib/dhcpsrv/memfile_lease_mgr.cc
src/lib/dhcpsrv/memfile_lease_mgr.cc
+5
-5
src/lib/dhcpsrv/memfile_lease_mgr.h
src/lib/dhcpsrv/memfile_lease_mgr.h
+4
-28
src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc
src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc
+23
-4
No files found.
src/lib/dhcpsrv/lease.cc
View file @
606b06ce
...
@@ -74,6 +74,15 @@ Lease4::Lease4(const Lease4& other)
...
@@ -74,6 +74,15 @@ Lease4::Lease4(const Lease4& other)
}
}
}
}
std
::
vector
<
uint8_t
>
Lease4
::
getClientIdVector
()
const
{
if
(
!
client_id_
)
{
return
std
::
vector
<
uint8_t
>
();
}
return
(
client_id_
->
getClientId
());
}
Lease4
&
Lease4
&
Lease4
::
operator
=
(
const
Lease4
&
other
)
{
Lease4
::
operator
=
(
const
Lease4
&
other
)
{
if
(
this
!=
&
other
)
{
if
(
this
!=
&
other
)
{
...
...
src/lib/dhcpsrv/lease.h
View file @
606b06ce
...
@@ -209,6 +209,12 @@ struct Lease4 : public Lease {
...
@@ -209,6 +209,12 @@ struct Lease4 : public Lease {
/// @param other the @c Lease4 object to be copied.
/// @param other the @c Lease4 object to be copied.
Lease4
(
const
Lease4
&
other
);
Lease4
(
const
Lease4
&
other
);
/// @brief Returns a client identifier.
///
/// @return A client identifier as vector, or an empty vector if client
/// identifier is NULL.
std
::
vector
<
uint8_t
>
getClientIdVector
()
const
;
/// @brief Assignment operator.
/// @brief Assignment operator.
///
///
/// @param other the @c Lease4 object to be assigned.
/// @param other the @c Lease4 object to be assigned.
...
...
src/lib/dhcpsrv/memfile_lease_mgr.cc
View file @
606b06ce
...
@@ -80,7 +80,7 @@ Memfile_LeaseMgr::getLease4(const HWAddr& hwaddr) const {
...
@@ -80,7 +80,7 @@ Memfile_LeaseMgr::getLease4(const HWAddr& hwaddr) const {
lease
!=
idx
.
end
();
++
lease
)
{
lease
!=
idx
.
end
();
++
lease
)
{
// Every Lease4 has a hardware address, so we can compare it
// Every Lease4 has a hardware address, so we can compare it
if
((
*
lease
)
->
hwaddr_
==
hwaddr
.
hwaddr_
)
{
if
((
*
lease
)
->
hwaddr_
==
hwaddr
.
hwaddr_
)
{
collection
.
push_back
((
*
lease
));
collection
.
push_back
((
*
lease
));
}
}
}
}
...
@@ -113,9 +113,9 @@ Memfile_LeaseMgr::getLease4(const HWAddr& hwaddr, SubnetID subnet_id) const {
...
@@ -113,9 +113,9 @@ Memfile_LeaseMgr::getLease4(const HWAddr& hwaddr, SubnetID subnet_id) const {
}
}
Lease4Collection
Lease4Collection
Memfile_LeaseMgr
::
getLease4
(
const
ClientId
&
clientid
)
const
{
Memfile_LeaseMgr
::
getLease4
(
const
ClientId
&
client
_
id
)
const
{
LOG_DEBUG
(
dhcpsrv_logger
,
DHCPSRV_DBG_TRACE_DETAIL
,
LOG_DEBUG
(
dhcpsrv_logger
,
DHCPSRV_DBG_TRACE_DETAIL
,
DHCPSRV_MEMFILE_GET_CLIENTID
).
arg
(
clientid
.
toText
());
DHCPSRV_MEMFILE_GET_CLIENTID
).
arg
(
client
_
id
.
toText
());
typedef
Memfile_LeaseMgr
::
Lease4Storage
::
nth_index
<
0
>::
type
SearchIndex
;
typedef
Memfile_LeaseMgr
::
Lease4Storage
::
nth_index
<
0
>::
type
SearchIndex
;
Lease4Collection
collection
;
Lease4Collection
collection
;
const
SearchIndex
&
idx
=
storage4_
.
get
<
0
>
();
const
SearchIndex
&
idx
=
storage4_
.
get
<
0
>
();
...
@@ -124,8 +124,8 @@ Memfile_LeaseMgr::getLease4(const ClientId& clientid) const {
...
@@ -124,8 +124,8 @@ Memfile_LeaseMgr::getLease4(const ClientId& clientid) const {
// client-id is not mandatory in DHCPv4. There can be a lease that does
// client-id is not mandatory in DHCPv4. There can be a lease that does
// not have a client-id. Dereferencing null pointer would be a bad thing
// not have a client-id. Dereferencing null pointer would be a bad thing
if
((
*
lease
)
->
client_id_
&&
*
(
*
lease
)
->
client_id_
==
clientid
)
{
if
((
*
lease
)
->
client_id_
&&
*
(
*
lease
)
->
client_id_
==
client
_
id
)
{
collection
.
push_back
((
*
lease
));
collection
.
push_back
((
*
lease
));
}
}
}
}
...
...
src/lib/dhcpsrv/memfile_lease_mgr.h
View file @
606b06ce
...
@@ -330,20 +330,8 @@ protected:
...
@@ -330,20 +330,8 @@ protected:
// lease: client id and subnet id.
// lease: client id and subnet id.
boost
::
multi_index
::
composite_key
<
boost
::
multi_index
::
composite_key
<
Lease4
,
Lease4
,
// The client id value is not directly accessible through the
boost
::
multi_index
::
const_mem_fun
<
Lease4
,
std
::
vector
<
uint8_t
>
,
// Lease4 object as it is wrapped with the ClientIdPtr object.
&
Lease4
::
getClientIdVector
>
,
// Therefore we use the KeyFromKeyExtractor class to access
// client id through this cascaded structure. The client id
// is used as an index value.
KeyFromKeyExtractor
<
// Specify that the vector holding client id value can be obtained
// from the ClientId object.
boost
::
multi_index
::
const_mem_fun
<
ClientId
,
std
::
vector
<
uint8_t
>
,
&
ClientId
::
getClientId
>
,
// Specify that the ClientId object (actually pointer to it) can
// be accessed by the client_id_ member of Lease4 class.
boost
::
multi_index
::
member
<
Lease4
,
ClientIdPtr
,
&
Lease4
::
client_id_
>
>
,
// The subnet id is accessed through the subnet_id_ member.
// The subnet id is accessed through the subnet_id_ member.
boost
::
multi_index
::
member
<
Lease
,
uint32_t
,
&
Lease
::
subnet_id_
>
boost
::
multi_index
::
member
<
Lease
,
uint32_t
,
&
Lease
::
subnet_id_
>
>
>
...
@@ -355,20 +343,8 @@ protected:
...
@@ -355,20 +343,8 @@ protected:
// lease: client id and subnet id.
// lease: client id and subnet id.
boost
::
multi_index
::
composite_key
<
boost
::
multi_index
::
composite_key
<
Lease4
,
Lease4
,
// The client id value is not directly accessible through the
boost
::
multi_index
::
const_mem_fun
<
Lease4
,
std
::
vector
<
uint8_t
>
,
// Lease4 object as it is wrapped with the ClientIdPtr object.
&
Lease4
::
getClientIdVector
>
,
// Therefore we use the KeyFromKeyExtractor class to access
// client id through this cascaded structure. The client id
// is used as an index value.
KeyFromKeyExtractor
<
// Specify that the vector holding client id value can be obtained
// from the ClientId object.
boost
::
multi_index
::
const_mem_fun
<
ClientId
,
std
::
vector
<
uint8_t
>
,
&
ClientId
::
getClientId
>
,
// Specify that the ClientId object (actually pointer to it) can
// be accessed by the client_id_ member of Lease4 class.
boost
::
multi_index
::
member
<
Lease4
,
ClientIdPtr
,
&
Lease4
::
client_id_
>
>
,
// The hardware address is held in the hwaddr_ member of the
// The hardware address is held in the hwaddr_ member of the
// Lease4 object.
// Lease4 object.
boost
::
multi_index
::
member
<
Lease4
,
std
::
vector
<
uint8_t
>
,
boost
::
multi_index
::
member
<
Lease4
,
std
::
vector
<
uint8_t
>
,
...
...
src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc
View file @
606b06ce
...
@@ -164,14 +164,17 @@ TEST_F(MemfileLeaseMgrTest, getLease4NullClientId) {
...
@@ -164,14 +164,17 @@ TEST_F(MemfileLeaseMgrTest, getLease4NullClientId) {
// Let's initialize a specific lease ... But this time
// Let's initialize a specific lease ... But this time
// We keep its client id for further lookup and
// We keep its client id for further lookup and
// We clearly 'reset' it ...
// We clearly 'reset' it ...
Lease4Ptr
lease
=
initializeLease4
(
straddress4_
[
4
]);
Lease4Ptr
lease
A
=
initializeLease4
(
straddress4_
[
4
]);
ClientIdPtr
client_id
=
lease
->
client_id_
;
ClientIdPtr
client_id
=
lease
A
->
client_id_
;
lease
->
client_id_
=
ClientIdPtr
();
lease
A
->
client_id_
=
ClientIdPtr
();
EXPECT_TRUE
(
lease_mgr
->
addLease
(
lease
));
EXPECT_TRUE
(
lease_mgr
->
addLease
(
lease
A
));
Lease4Collection
returned
=
lease_mgr
->
getLease4
(
*
client_id
);
Lease4Collection
returned
=
lease_mgr
->
getLease4
(
*
client_id
);
// Shouldn't have our previous lease ...
// Shouldn't have our previous lease ...
ASSERT_EQ
(
0
,
returned
.
size
());
ASSERT_EQ
(
0
,
returned
.
size
());
Lease4Ptr
leaseB
=
initializeLease4
(
straddress4_
[
5
]);
// Shouldn't throw any null pointer exception
EXPECT_NO_THROW
(
lease_mgr
->
addLease
(
leaseB
));
}
}
// Checks lease4 retrieval through HWAddr
// Checks lease4 retrieval through HWAddr
...
@@ -216,4 +219,20 @@ TEST_F(MemfileLeaseMgrTest, getLease4ClientIdHWAddrSubnetId) {
...
@@ -216,4 +219,20 @@ TEST_F(MemfileLeaseMgrTest, getLease4ClientIdHWAddrSubnetId) {
EXPECT_TRUE
(
lease
==
Lease4Ptr
());
EXPECT_TRUE
(
lease
==
Lease4Ptr
());
}
}
TEST_F
(
MemfileLeaseMgrTest
,
getLease4ClientIdVector
)
{
const
LeaseMgr
::
ParameterMap
pmap
;
boost
::
scoped_ptr
<
Memfile_LeaseMgr
>
lease_mgr
(
new
Memfile_LeaseMgr
(
pmap
));
const
std
::
vector
<
uint8_t
>
vec
;
Lease4Ptr
lease
=
initializeLease4
(
straddress4_
[
7
]);
// Check that this lease has null client-id
ASSERT_TRUE
(
lease
->
client_id_
==
ClientIdPtr
());
// Check that this return empty vector
ASSERT_TRUE
(
lease
->
getClientIdVector
()
==
vec
);
// Let's take a lease with client-id not null
lease
=
initializeLease4
(
straddress4_
[
6
]);
// Check that they return same client-id value
ASSERT_TRUE
(
lease
->
client_id_
->
getClientId
()
==
lease
->
getClientIdVector
());
}
};
// end of anonymous namespace
};
// end of anonymous namespace
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