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
d777fbc7
Commit
d777fbc7
authored
Jul 15, 2014
by
Marcin Siodelski
Browse files
[3390] Append basic options that we always want be returned.
parent
e3ada096
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/bin/dhcp4/dhcp4_srv.cc
View file @
d777fbc7
...
...
@@ -1422,6 +1422,7 @@ Dhcpv4Srv::processInform(Pkt4Ptr& inform) {
copyDefaultFields
(
inform
,
ack
);
appendRequestedOptions
(
inform
,
ack
);
appendRequestedVendorOptions
(
inform
,
ack
);
appendBasicOptions
(
inform
,
ack
);
adjustIfaceData
(
inform
,
ack
);
// There are cases for the DHCPINFORM that the server receives it via
...
...
src/bin/dhcp4/tests/dhcp4_client.cc
View file @
d777fbc7
...
...
@@ -25,7 +25,8 @@ namespace dhcp {
namespace
test
{
Dhcp4Client
::
Configuration
::
Configuration
()
:
routers_
(),
dns_servers_
(),
serverid_
(
"0.0.0.0"
)
{
:
routers_
(),
dns_servers_
(),
log_servers_
(),
quotes_servers_
(),
serverid_
(
"0.0.0.0"
)
{
reset
();
}
...
...
@@ -33,6 +34,8 @@ void
Dhcp4Client
::
Configuration
::
reset
()
{
routers_
.
clear
();
dns_servers_
.
clear
();
log_servers_
.
clear
();
quotes_servers_
.
clear
();
serverid_
=
asiolink
::
IOAddress
(
"0.0.0.0"
);
}
...
...
@@ -69,25 +72,38 @@ Dhcp4Client::applyConfiguration() {
config_
.
reset
();
// Routers
Option4AddrLstPtr
opt_routers
=
boost
::
dynamic_pointer_cast
<
Option4AddrLst
>
(
resp
->
getOption
(
DHO_ROUTERS
));
if
(
opt_routers
)
{
config_
.
routers_
=
opt_routers
->
getAddresses
();
}
// DNS Servers
Option4AddrLstPtr
opt_dns_servers
=
boost
::
dynamic_pointer_cast
<
Option4AddrLst
>
(
resp
->
getOption
(
DHO_DOMAIN_NAME_SERVERS
));
if
(
opt_dns_servers
)
{
config_
.
dns_servers_
=
opt_dns_servers
->
getAddresses
();
}
// Log Servers
Option4AddrLstPtr
opt_log_servers
=
boost
::
dynamic_pointer_cast
<
Option4AddrLst
>
(
resp
->
getOption
(
DHO_LOG_SERVERS
));
if
(
opt_log_servers
)
{
config_
.
log_servers_
=
opt_routers
->
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_dns_servers
->
getAddresses
();
}
// Server Identifier
OptionCustomPtr
opt_serverid
=
boost
::
dynamic_pointer_cast
<
OptionCustom
>
(
resp
->
getOption
(
DHO_DHCP_SERVER_IDENTIFIER
));
if
(
opt_serverid
)
{
config_
.
serverid_
=
opt_serverid
->
readAddress
();
}
/// @todo Other possible configuration.
/// @todo Other possible configuration
, e.g. lease
.
}
void
...
...
src/bin/dhcp4/tests/dhcp4_client.h
View file @
d777fbc7
...
...
@@ -59,6 +59,8 @@ public:
struct
Configuration
{
Option4AddrLst
::
AddressContainer
routers_
;
Option4AddrLst
::
AddressContainer
dns_servers_
;
Option4AddrLst
::
AddressContainer
log_servers_
;
Option4AddrLst
::
AddressContainer
quotes_servers_
;
Lease4
lease_
;
asiolink
::
IOAddress
serverid_
;
...
...
@@ -200,6 +202,17 @@ public:
private:
/// @brief Stores configuration received from the server.
///
/// This methods stores the configuration obtained from the DHCP server
/// in the @c Configuration structure. This configuration includes:
/// - obtained lease
/// - server id of the server that provided the configuration
/// - lease
/// - selected options (used by unit tests):
/// - DNS Servers
/// - Routers
/// - Log Servers
/// - Quotes Servers
void
applyConfiguration
();
/// @brief Creates client's side DHCP message.
...
...
src/bin/dhcp4/tests/inform_unittest.cc
View file @
d777fbc7
...
...
@@ -36,12 +36,16 @@ namespace {
/// - 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.
///
/// - Configuration 1:
/// - Use for testing relayed messages
/// - 1 subnet: 192.0.2.0/24
/// - Router option present: 192.0.2.200 and 192.0.2.201
/// - Domain Name Server option present: 192.0.2.202, 192.0.2.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
*
INFORM_CONFIGS
[]
=
{
// Configuration 0
"{
\"
interfaces
\"
: [
\"
all
\"
],"
...
...
@@ -62,7 +66,20 @@ const char* INFORM_CONFIGS[] = {
"
\"
data
\"
:
\"
10.0.0.202,10.0.0.203
\"
,"
"
\"
csv-format
\"
: true,"
"
\"
space
\"
:
\"
dhcp4
\"
"
" },"
" {"
"
\"
name
\"
:
\"
log-servers
\"
,"
"
\"
code
\"
: 7,"
"
\"
data
\"
:
\"
10.0.0.200,10.0.0.201
\"
,"
"
\"
csv-format
\"
: true,"
"
\"
space
\"
:
\"
dhcp4
\"
"
" },"
" {"
"
\"
name
\"
:
\"
cookie-servers
\"
,"
"
\"
code
\"
: 8,"
"
\"
data
\"
:
\"
10.0.0.202,10.0.0.203
\"
,"
"
\"
csv-format
\"
: true,"
"
\"
space
\"
:
\"
dhcp4
\"
"
" } ]"
" } ]"
"}"
,
...
...
@@ -85,7 +102,20 @@ const char* INFORM_CONFIGS[] = {
"
\"
data
\"
:
\"
192.0.2.202,192.0.2.203
\"
,"
"
\"
csv-format
\"
: true,"
"
\"
space
\"
:
\"
dhcp4
\"
"
" },"
" {"
"
\"
name
\"
:
\"
log-servers
\"
,"
"
\"
code
\"
: 7,"
"
\"
data
\"
:
\"
10.0.0.200,10.0.0.201
\"
,"
"
\"
csv-format
\"
: true,"
"
\"
space
\"
:
\"
dhcp4
\"
"
" },"
" {"
"
\"
name
\"
:
\"
cookie-servers
\"
,"
"
\"
code
\"
: 8,"
"
\"
data
\"
:
\"
10.0.0.202,10.0.0.203
\"
,"
"
\"
csv-format
\"
: true,"
"
\"
space
\"
:
\"
dhcp4
\"
"
" } ]"
" } ]"
"}"
...
...
@@ -116,7 +146,7 @@ TEST_F(InformTest, directClientBroadcast) {
// Configure DHCP server.
configure
(
INFORM_CONFIGS
[
0
],
*
client
.
getServer
());
// Request some configuration when DHCPINFORM is sent.
client
.
requestOptions
(
DHO_
DOMAIN_NAME
_SERVERS
,
DHO_
ROUT
ERS
);
client
.
requestOptions
(
DHO_
LOG
_SERVERS
,
DHO_
COOKIE_SERV
ERS
);
// Preconfigure the client with the IP address.
client
.
createLease
(
IOAddress
(
"10.0.0.56"
),
600
);
// Send DHCPINFORM message to the server.
...
...
@@ -141,13 +171,21 @@ TEST_F(InformTest, directClientBroadcast) {
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 Log Servers option has been received.
ASSERT_EQ
(
2
,
client
.
config_
.
quotes_servers_
.
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 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
());
// Check that we can send another DHCPINFORM message using
// different ciaddr and we will get the configuration.
client
.
createLease
(
IOAddress
(
"10.0.0.12"
),
600
);
// This time do not request
DNS
Servers option and it should not
// This time do not request
Quotes
Servers option and it should not
// be returned.
client
.
requestOptions
(
DHO_
ROUT
ERS
);
client
.
requestOptions
(
DHO_
LOG_SERV
ERS
);
// Send DHCPINFORM.
ASSERT_NO_THROW
(
client
.
doInform
());
ASSERT_TRUE
(
client
.
getContext
().
response_
);
...
...
@@ -165,7 +203,11 @@ TEST_F(InformTest, directClientBroadcast) {
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_TRUE
(
client
.
config_
.
dns_servers_
.
empty
());
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 hasn't been received.
ASSERT_TRUE
(
client
.
config_
.
quotes_servers_
.
empty
());
}
// This test checks that the server drops DHCPINFORM message when the
...
...
@@ -175,7 +217,7 @@ TEST_F(InformTest, directClientBroadcastNoAddress) {
// Configure DHCP server.
configure
(
INFORM_CONFIGS
[
0
],
*
client
.
getServer
());
// Request some configuration when DHCPINFORM is sent.
client
.
requestOptions
(
DHO_
DOMAIN_NAME
_SERVERS
,
DHO_
ROUT
ERS
);
client
.
requestOptions
(
DHO_
LOG
_SERVERS
,
DHO_
COOKIE_SERV
ERS
);
// Send DHCPINFORM message to the server.
ASSERT_NO_THROW
(
client
.
doInform
());
// Make sure that the server dropped the message.
...
...
@@ -189,8 +231,6 @@ TEST_F(InformTest, directClientUnicast) {
Dhcp4Client
client
;
// Configure DHCP server.
configure
(
INFORM_CONFIGS
[
0
],
*
client
.
getServer
());
// Request some configuration when DHCPINFORM is sent.
client
.
requestOptions
(
DHO_DOMAIN_NAME_SERVERS
,
DHO_ROUTERS
);
// Preconfigure the client with the IP address.
client
.
createLease
(
IOAddress
(
"10.0.0.56"
),
600
);
// Set remote address to unicast.
...
...
@@ -225,8 +265,6 @@ TEST_F(InformTest, directClientNoCiaddr) {
Dhcp4Client
client
;
// Configure DHCP server.
configure
(
INFORM_CONFIGS
[
0
],
*
client
.
getServer
());
// Request some configuration when DHCPINFORM is sent.
client
.
requestOptions
(
DHO_DOMAIN_NAME_SERVERS
,
DHO_ROUTERS
);
// Preconfigure the client with the IP address.
client
.
createLease
(
IOAddress
(
"10.0.0.56"
),
600
);
// Send DHCPINFORM message (with ciaddr not set) to the server.
...
...
@@ -261,7 +299,7 @@ TEST_F(InformTest, relayedClient) {
// Message is relayed.
client
.
useRelay
();
// Request some configuration when DHCPINFORM is sent.
client
.
requestOptions
(
DHO_
DOMAIN_NAME
_SERVERS
,
DHO_
ROUT
ERS
);
client
.
requestOptions
(
DHO_
LOG
_SERVERS
,
DHO_
COOKIE_SERV
ERS
);
// Preconfigure the client with the IP address.
client
.
createLease
(
IOAddress
(
"192.0.2.56"
),
600
);
// Send DHCPINFORM message to the server.
...
...
@@ -285,6 +323,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_
.
log_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
());
}
// This test checks that the server can respond to the DHCPINFORM message
...
...
@@ -295,8 +341,6 @@ TEST_F(InformTest, relayedClientNoCiaddr) {
configure
(
INFORM_CONFIGS
[
1
],
*
client
.
getServer
());
// Message is relayed.
client
.
useRelay
();
// Request some configuration when DHCPINFORM is sent.
client
.
requestOptions
(
DHO_DOMAIN_NAME_SERVERS
,
DHO_ROUTERS
);
// Send DHCPINFORM message to the server.
ASSERT_NO_THROW
(
client
.
doInform
());
// Make sure that the server responded.
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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