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
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
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
Adam Osuchowski
Kea
Commits
b1899f97
Commit
b1899f97
authored
May 20, 2016
by
Marcin Siodelski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[3572] DHCPv4 server sends host specific options.
parent
e7c3e4bb
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
258 additions
and
17 deletions
+258
-17
src/bin/dhcp4/dhcp4_srv.cc
src/bin/dhcp4/dhcp4_srv.cc
+9
-1
src/bin/dhcp4/tests/Makefile.am
src/bin/dhcp4/tests/Makefile.am
+1
-0
src/bin/dhcp4/tests/dhcp4_client.cc
src/bin/dhcp4/tests/dhcp4_client.cc
+2
-2
src/bin/dhcp4/tests/host_options_unittest.cc
src/bin/dhcp4/tests/host_options_unittest.cc
+232
-0
src/bin/dhcp4/tests/inform_unittest.cc
src/bin/dhcp4/tests/inform_unittest.cc
+13
-13
src/lib/dhcpsrv/host.cc
src/lib/dhcpsrv/host.cc
+1
-1
No files found.
src/bin/dhcp4/dhcp4_srv.cc
View file @
b1899f97
...
...
@@ -916,13 +916,21 @@ void
Dhcpv4Srv
::
buildCfgOptionList
(
Dhcpv4Exchange
&
ex
)
{
CfgOptionList
&
co_list
=
ex
.
getCfgOptionList
();
//
First subnet configured options
//
Retrieve subnet.
Subnet4Ptr
subnet
=
ex
.
getContext
()
->
subnet_
;
if
(
!
subnet
)
{
// All methods using the CfgOptionList object return soon when
// there is no subnet so do the same
return
;
}
// Firstly, host specific options.
const
ConstHostPtr
&
host
=
ex
.
getContext
()
->
host_
;
if
(
host
)
{
co_list
.
push_back
(
host
->
getCfgOption4
());
}
// Secondly, subnet configured options.
if
(
!
subnet
->
getCfgOption
()
->
empty
())
{
co_list
.
push_back
(
subnet
->
getCfgOption
());
}
...
...
src/bin/dhcp4/tests/Makefile.am
View file @
b1899f97
...
...
@@ -89,6 +89,7 @@ dhcp4_unittests_SOURCES += dhcp4_client.cc dhcp4_client.h
dhcp4_unittests_SOURCES
+=
hooks_unittest.cc
dhcp4_unittests_SOURCES
+=
inform_unittest.cc
dhcp4_unittests_SOURCES
+=
dora_unittest.cc
dhcp4_unittests_SOURCES
+=
host_options_unittest.cc
dhcp4_unittests_SOURCES
+=
release_unittest.cc
dhcp4_unittests_SOURCES
+=
out_of_range_unittest.cc
dhcp4_unittests_SOURCES
+=
decline_unittest.cc
...
...
src/bin/dhcp4/tests/dhcp4_client.cc
View file @
b1899f97
...
...
@@ -163,13 +163,13 @@ Dhcp4Client::applyConfiguration() {
Option4AddrLstPtr
opt_log_servers
=
boost
::
dynamic_pointer_cast
<
Option4AddrLst
>
(
resp
->
getOption
(
DHO_LOG_SERVERS
));
if
(
opt_log_servers
)
{
config_
.
log_servers_
=
opt_
rout
ers
->
getAddresses
();
config_
.
log_servers_
=
opt_
log_serv
ers
->
getAddresses
();
}
// Quotes Servers
Option4AddrLstPtr
opt_quotes_servers
=
boost
::
dynamic_pointer_cast
<
Option4AddrLst
>
(
resp
->
getOption
(
DHO_COOKIE_SERVERS
));
if
(
opt_quotes_servers
)
{
config_
.
quotes_servers_
=
opt_
dn
s_servers
->
getAddresses
();
config_
.
quotes_servers_
=
opt_
quote
s_servers
->
getAddresses
();
}
// Server Identifier
OptionCustomPtr
opt_serverid
=
boost
::
dynamic_pointer_cast
<
...
...
src/bin/dhcp4/tests/host_options_unittest.cc
0 → 100644
View file @
b1899f97
// Copyright (C) 2016 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#include <config.h>
#include <dhcp/dhcp4.h>
#include <dhcp/tests/iface_mgr_test_config.h>
#include <dhcp4/tests/dhcp4_test_utils.h>
#include <dhcp4/tests/dhcp4_client.h>
#include <stats/stats_mgr.h>
using
namespace
isc
;
using
namespace
isc
::
asiolink
;
using
namespace
isc
::
dhcp
;
using
namespace
isc
::
dhcp
::
test
;
namespace
{
/// @brief Set of JSON configurations used throughout the tests.
///
/// - Configuration 0:
/// - Used for testing direct traffic
/// - 1 subnet: 10.0.0.0/24
/// - 1 pool: 10.0.0.10-10.0.0.100
/// - Router option present: 10.0.0.200 and 10.0.0.201
/// - Domain Name Server option present: 10.0.0.202, 10.0.0.203.
/// - Log Servers option present: 192.0.2.200 and 192.0.2.201
/// - Quotes Servers option present: 192.0.2.202, 192.0.2.203.
///
const
char
*
HOST_CONFIGS
[]
=
{
// Configuration 0
"{
\"
interfaces-config
\"
: {"
"
\"
interfaces
\"
: [
\"
*
\"
]"
"},"
"
\"
valid-lifetime
\"
: 600,"
"
\"
subnet4
\"
: [ { "
"
\"
subnet
\"
:
\"
10.0.0.0/24
\"
, "
"
\"
id
\"
: 1,"
"
\"
pools
\"
: [ {
\"
pool
\"
:
\"
10.0.0.10-10.0.0.100
\"
} ],"
"
\"
option-data
\"
: [ {"
"
\"
name
\"
:
\"
routers
\"
,"
"
\"
data
\"
:
\"
10.0.0.200,10.0.0.201
\"
"
" },"
" {"
"
\"
name
\"
:
\"
domain-name-servers
\"
,"
"
\"
data
\"
:
\"
10.0.0.202,10.0.0.203
\"
"
" },"
" {"
"
\"
name
\"
:
\"
log-servers
\"
,"
"
\"
data
\"
:
\"
10.0.0.200,10.0.0.201
\"
"
" },"
" {"
"
\"
name
\"
:
\"
cookie-servers
\"
,"
"
\"
data
\"
:
\"
10.0.0.202,10.0.0.203
\"
"
" } ],"
"
\"
reservations
\"
: [ "
" {"
"
\"
hw-address
\"
:
\"
aa:bb:cc:dd:ee:ff
\"
,"
"
\"
ip-address
\"
:
\"
10.0.0.7
\"
,"
"
\"
option-data
\"
: [ {"
"
\"
name
\"
:
\"
cookie-servers
\"
,"
"
\"
data
\"
:
\"
10.1.1.202,10.1.1.203
\"
"
" },"
" {"
"
\"
name
\"
:
\"
log-servers
\"
,"
"
\"
data
\"
:
\"
10.1.1.200,10.1.1.201
\"
"
" } ]"
" } ]"
" } ]"
"}"
,
// Configuration 1
"{
\"
interfaces-config
\"
: {"
"
\"
interfaces
\"
: [
\"
*
\"
]"
"},"
"
\"
valid-lifetime
\"
: 600,"
"
\"
subnet4
\"
: [ { "
"
\"
subnet
\"
:
\"
10.0.0.0/24
\"
, "
"
\"
id
\"
: 1,"
"
\"
pools
\"
: [ {
\"
pool
\"
:
\"
10.0.0.10-10.0.0.100
\"
} ],"
"
\"
option-data
\"
: [ {"
"
\"
name
\"
:
\"
routers
\"
,"
"
\"
data
\"
:
\"
10.0.0.200,10.0.0.201
\"
"
" },"
" {"
"
\"
name
\"
:
\"
domain-name-servers
\"
,"
"
\"
data
\"
:
\"
10.0.0.202,10.0.0.203
\"
"
" },"
" {"
"
\"
name
\"
:
\"
log-servers
\"
,"
"
\"
data
\"
:
\"
10.0.0.200,10.0.0.201
\"
"
" },"
" {"
"
\"
name
\"
:
\"
cookie-servers
\"
,"
"
\"
data
\"
:
\"
10.0.0.202,10.0.0.203
\"
"
" } ],"
"
\"
reservations
\"
: [ "
" {"
"
\"
hw-address
\"
:
\"
aa:bb:cc:dd:ee:ff
\"
,"
"
\"
ip-address
\"
:
\"
10.0.0.7
\"
,"
"
\"
option-data
\"
: [ {"
"
\"
name
\"
:
\"
routers
\"
,"
"
\"
data
\"
:
\"
10.1.1.200,10.1.1.201
\"
"
" },"
" {"
"
\"
name
\"
:
\"
domain-name-servers
\"
,"
"
\"
data
\"
:
\"
10.1.1.202,10.1.1.203
\"
"
" } ]"
" } ]"
" } ]"
"}"
};
/// @brief Test fixture class for testing static reservations of options.
class
HostOptionsTest
:
public
Dhcpv4SrvTest
{
public:
/// @brief Constructor.
///
/// Sets up fake interfaces.
HostOptionsTest
()
:
Dhcpv4SrvTest
(),
iface_mgr_test_config_
(
true
)
{
IfaceMgr
::
instance
().
openSockets4
();
// Let's wipe all existing statistics.
isc
::
stats
::
StatsMgr
::
instance
().
removeAll
();
}
/// @brief Destructor.
///
/// Cleans up statistics after the test.
virtual
~
HostOptionsTest
()
{
// Let's wipe all existing statistics.
isc
::
stats
::
StatsMgr
::
instance
().
removeAll
();
}
/// @brief Interface Manager's fake configuration control.
IfaceMgrTestConfig
iface_mgr_test_config_
;
};
TEST_F
(
HostOptionsTest
,
overrideRequestedOptions
)
{
Dhcp4Client
client
(
Dhcp4Client
::
SELECTING
);
client
.
setHWAddress
(
"aa:bb:cc:dd:ee:ff"
);
client
.
requestOptions
(
DHO_DOMAIN_NAME_SERVERS
,
DHO_LOG_SERVERS
,
DHO_COOKIE_SERVERS
);
// Configure DHCP server.
configure
(
HOST_CONFIGS
[
0
],
*
client
.
getServer
());
// Perform 4-way exchange with the server but to not request any
// specific address in the DHCPDISCOVER message.
ASSERT_NO_THROW
(
client
.
doDORA
());
// Make sure that the server responded.
ASSERT_TRUE
(
client
.
getContext
().
response_
);
Pkt4Ptr
resp
=
client
.
getContext
().
response_
;
// Make sure that the server has responded with DHCPACK.
ASSERT_EQ
(
DHCPACK
,
static_cast
<
int
>
(
resp
->
getType
()));
// Response must not be relayed.
EXPECT_FALSE
(
resp
->
isRelayed
());
// Make sure that the server id is present.
EXPECT_EQ
(
"10.0.0.1"
,
client
.
config_
.
serverid_
.
toText
());
// Make sure that the client has got the lease for the reserved
// address.
ASSERT_EQ
(
"10.0.0.7"
,
client
.
config_
.
lease_
.
addr_
.
toText
());
ASSERT_EQ
(
2
,
client
.
config_
.
routers_
.
size
());
EXPECT_EQ
(
"10.0.0.200"
,
client
.
config_
.
routers_
[
0
].
toText
());
EXPECT_EQ
(
"10.0.0.201"
,
client
.
config_
.
routers_
[
1
].
toText
());
// Make sure that the DNS Servers option has been received.
ASSERT_EQ
(
2
,
client
.
config_
.
dns_servers_
.
size
());
EXPECT_EQ
(
"10.0.0.202"
,
client
.
config_
.
dns_servers_
[
0
].
toText
());
EXPECT_EQ
(
"10.0.0.203"
,
client
.
config_
.
dns_servers_
[
1
].
toText
());
// Make sure that the Quotes Servers option has been received.
ASSERT_EQ
(
2
,
client
.
config_
.
quotes_servers_
.
size
());
EXPECT_EQ
(
"10.1.1.202"
,
client
.
config_
.
quotes_servers_
[
0
].
toText
());
EXPECT_EQ
(
"10.1.1.203"
,
client
.
config_
.
quotes_servers_
[
1
].
toText
());
// Make sure that the Log Servers option has been received.
ASSERT_EQ
(
2
,
client
.
config_
.
log_servers_
.
size
());
EXPECT_EQ
(
"10.1.1.200"
,
client
.
config_
.
log_servers_
[
0
].
toText
());
EXPECT_EQ
(
"10.1.1.201"
,
client
.
config_
.
log_servers_
[
1
].
toText
());
}
TEST_F
(
HostOptionsTest
,
overrideDefaultOptions
)
{
Dhcp4Client
client
(
Dhcp4Client
::
SELECTING
);
client
.
setHWAddress
(
"aa:bb:cc:dd:ee:ff"
);
client
.
requestOptions
(
DHO_LOG_SERVERS
,
DHO_COOKIE_SERVERS
);
// Configure DHCP server.
configure
(
HOST_CONFIGS
[
1
],
*
client
.
getServer
());
// Perform 4-way exchange with the server but to not request any
// specific address in the DHCPDISCOVER message.
ASSERT_NO_THROW
(
client
.
doDORA
());
// Make sure that the server responded.
ASSERT_TRUE
(
client
.
getContext
().
response_
);
Pkt4Ptr
resp
=
client
.
getContext
().
response_
;
// Make sure that the server has responded with DHCPACK.
ASSERT_EQ
(
DHCPACK
,
static_cast
<
int
>
(
resp
->
getType
()));
// Response must not be relayed.
EXPECT_FALSE
(
resp
->
isRelayed
());
// Make sure that the server id is present.
EXPECT_EQ
(
"10.0.0.1"
,
client
.
config_
.
serverid_
.
toText
());
// Make sure that the client has got the lease for the reserved
// address.
ASSERT_EQ
(
"10.0.0.7"
,
client
.
config_
.
lease_
.
addr_
.
toText
());
ASSERT_EQ
(
2
,
client
.
config_
.
routers_
.
size
());
EXPECT_EQ
(
"10.1.1.200"
,
client
.
config_
.
routers_
[
0
].
toText
());
EXPECT_EQ
(
"10.1.1.201"
,
client
.
config_
.
routers_
[
1
].
toText
());
// Make sure that the DNS Servers option has been received.
ASSERT_EQ
(
2
,
client
.
config_
.
dns_servers_
.
size
());
EXPECT_EQ
(
"10.1.1.202"
,
client
.
config_
.
dns_servers_
[
0
].
toText
());
EXPECT_EQ
(
"10.1.1.203"
,
client
.
config_
.
dns_servers_
[
1
].
toText
());
// Make sure that the Quotes Servers option has been received.
ASSERT_EQ
(
2
,
client
.
config_
.
quotes_servers_
.
size
());
EXPECT_EQ
(
"10.0.0.202"
,
client
.
config_
.
quotes_servers_
[
0
].
toText
());
EXPECT_EQ
(
"10.0.0.203"
,
client
.
config_
.
quotes_servers_
[
1
].
toText
());
// Make sure that the Log Servers option has been received.
ASSERT_EQ
(
2
,
client
.
config_
.
log_servers_
.
size
());
EXPECT_EQ
(
"10.0.0.200"
,
client
.
config_
.
log_servers_
[
0
].
toText
());
EXPECT_EQ
(
"10.0.0.201"
,
client
.
config_
.
log_servers_
[
1
].
toText
());
}
}
// end of anonymous namespace
src/bin/dhcp4/tests/inform_unittest.cc
View file @
b1899f97
// Copyright (C) 2014-201
5
Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2014-201
6
Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
...
...
@@ -58,11 +58,11 @@ const char* INFORM_CONFIGS[] = {
" },"
" {"
"
\"
name
\"
:
\"
log-servers
\"
,"
"
\"
data
\"
:
\"
10.0.0.20
0,10.0.0.201
\"
"
"
\"
data
\"
:
\"
10.0.0.20
2,10.0.0.203
\"
"
" },"
" {"
"
\"
name
\"
:
\"
cookie-servers
\"
,"
"
\"
data
\"
:
\"
10.0.0.20
2,10.0.0.203
\"
"
"
\"
data
\"
:
\"
10.0.0.20
0,10.0.0.201
\"
"
" } ]"
" } ]"
"}"
,
...
...
@@ -159,12 +159,12 @@ TEST_F(InformTest, directClientBroadcast) {
EXPECT_EQ
(
"10.0.0.203"
,
client
.
config_
.
dns_servers_
[
1
].
toText
());
// Make sure that the Log Servers option has been received.
ASSERT_EQ
(
2
,
client
.
config_
.
quotes_servers_
.
size
());
EXPECT_EQ
(
"10.0.0.200"
,
client
.
config_
.
rout
ers_
[
0
].
toText
());
EXPECT_EQ
(
"10.0.0.201"
,
client
.
config_
.
rout
ers_
[
1
].
toText
());
EXPECT_EQ
(
"10.0.0.200"
,
client
.
config_
.
quotes_serv
ers_
[
0
].
toText
());
EXPECT_EQ
(
"10.0.0.201"
,
client
.
config_
.
quotes_serv
ers_
[
1
].
toText
());
// Make sure that the Quotes Servers option has been received.
ASSERT_EQ
(
2
,
client
.
config_
.
log_servers_
.
size
());
EXPECT_EQ
(
"10.0.0.202"
,
client
.
config_
.
dns
_servers_
[
0
].
toText
());
EXPECT_EQ
(
"10.0.0.203"
,
client
.
config_
.
dns
_servers_
[
1
].
toText
());
EXPECT_EQ
(
"10.0.0.202"
,
client
.
config_
.
log
_servers_
[
0
].
toText
());
EXPECT_EQ
(
"10.0.0.203"
,
client
.
config_
.
log
_servers_
[
1
].
toText
());
// Check that we can send another DHCPINFORM message using
// different ciaddr and we will get the configuration.
...
...
@@ -313,14 +313,14 @@ TEST_F(InformTest, relayedClient) {
ASSERT_EQ
(
2
,
client
.
config_
.
dns_servers_
.
size
());
EXPECT_EQ
(
"192.0.2.202"
,
client
.
config_
.
dns_servers_
[
0
].
toText
());
EXPECT_EQ
(
"192.0.2.203"
,
client
.
config_
.
dns_servers_
[
1
].
toText
());
// Make sure that the Log Servers option has been received.
ASSERT_EQ
(
2
,
client
.
config_
.
quotes_servers_
.
size
());
EXPECT_EQ
(
"192.0.2.200"
,
client
.
config_
.
routers_
[
0
].
toText
());
EXPECT_EQ
(
"192.0.2.201"
,
client
.
config_
.
routers_
[
1
].
toText
());
// Make sure that the Quotes Servers option has been received.
ASSERT_EQ
(
2
,
client
.
config_
.
quotes_servers_
.
size
());
EXPECT_EQ
(
"10.0.0.202"
,
client
.
config_
.
quotes_servers_
[
0
].
toText
());
EXPECT_EQ
(
"10.0.0.203"
,
client
.
config_
.
quotes_servers_
[
1
].
toText
());
// Make sure that the Log Servers option has been received.
ASSERT_EQ
(
2
,
client
.
config_
.
log_servers_
.
size
());
EXPECT_EQ
(
"1
92.0.2.202"
,
client
.
config_
.
dns
_servers_
[
0
].
toText
());
EXPECT_EQ
(
"1
92.0.2.203"
,
client
.
config_
.
dns
_servers_
[
1
].
toText
());
EXPECT_EQ
(
"1
0.0.0.200"
,
client
.
config_
.
log
_servers_
[
0
].
toText
());
EXPECT_EQ
(
"1
0.0.0.201"
,
client
.
config_
.
log
_servers_
[
1
].
toText
());
}
// This test checks that the server can respond to the DHCPINFORM message
...
...
src/lib/dhcpsrv/host.cc
View file @
b1899f97
...
...
@@ -81,7 +81,7 @@ Host::Host(const uint8_t* identifier, const size_t identifier_len,
ipv4_reservation_
(
asiolink
::
IOAddress
::
IPV4_ZERO_ADDRESS
()),
hostname_
(
hostname
),
dhcp4_client_classes_
(
dhcp4_client_classes
),
dhcp6_client_classes_
(
dhcp6_client_classes
),
host_id_
(
0
),
cfg_option4_
(
),
cfg_option6_
(
)
{
cfg_option4_
(
new
CfgOption
()),
cfg_option6_
(
new
CfgOption
()
)
{
// Initialize host identifier.
setIdentifier
(
identifier
,
identifier_len
,
identifier_type
);
...
...
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