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
Sebastian Schrader
Kea
Commits
3a1e8654
Commit
3a1e8654
authored
Oct 15, 2014
by
Tomek Mrugalski
🛰
Browse files
[3589] Trailing underscores added to OptionDescriptor members.
parent
3307c992
Changes
10
Hide whitespace changes
Inline
Side-by-side
src/bin/dhcp4/dhcp4_srv.cc
View file @
3a1e8654
...
...
@@ -600,8 +600,8 @@ Dhcpv4Srv::appendRequestedOptions(const Pkt4Ptr& question, Pkt4Ptr& msg) {
opt
!=
requested_opts
.
end
();
++
opt
)
{
if
(
!
msg
->
getOption
(
*
opt
))
{
OptionDescriptor
desc
=
subnet
->
getCfgOption
()
->
get
(
"dhcp4"
,
*
opt
);
if
(
desc
.
option
&&
!
msg
->
getOption
(
*
opt
))
{
msg
->
addOption
(
desc
.
option
);
if
(
desc
.
option
_
&&
!
msg
->
getOption
(
*
opt
))
{
msg
->
addOption
(
desc
.
option
_
);
}
}
}
...
...
@@ -651,8 +651,8 @@ Dhcpv4Srv::appendRequestedVendorOptions(const Pkt4Ptr& question, Pkt4Ptr& answer
if
(
!
vendor_rsp
->
getOption
(
*
code
))
{
OptionDescriptor
desc
=
subnet
->
getCfgOption
()
->
get
(
vendor_id
,
*
code
);
if
(
desc
.
option
)
{
vendor_rsp
->
addOption
(
desc
.
option
);
if
(
desc
.
option
_
)
{
vendor_rsp
->
addOption
(
desc
.
option
_
);
added
=
true
;
}
}
...
...
@@ -690,8 +690,8 @@ Dhcpv4Srv::appendBasicOptions(const Pkt4Ptr& question, Pkt4Ptr& msg) {
// Check whether option has been configured.
OptionDescriptor
desc
=
subnet
->
getCfgOption
()
->
get
(
"dhcp4"
,
required_options
[
i
]);
if
(
desc
.
option
)
{
msg
->
addOption
(
desc
.
option
);
if
(
desc
.
option
_
)
{
msg
->
addOption
(
desc
.
option
_
);
}
}
}
...
...
@@ -1951,9 +1951,9 @@ bool Dhcpv4Srv::classSpecificProcessing(const Pkt4Ptr& query, const Pkt4Ptr& rsp
OptionDescriptor
desc
=
subnet
->
getCfgOption
()
->
get
(
"dhcp4"
,
DHO_BOOT_FILE_NAME
);
if
(
desc
.
option
)
{
if
(
desc
.
option
_
)
{
boost
::
shared_ptr
<
OptionString
>
boot
=
boost
::
dynamic_pointer_cast
<
OptionString
>
(
desc
.
option
);
boost
::
dynamic_pointer_cast
<
OptionString
>
(
desc
.
option
_
);
if
(
boot
)
{
std
::
string
filename
=
boot
->
getValue
();
rsp
->
setFile
((
const
uint8_t
*
)
filename
.
c_str
(),
filename
.
size
());
...
...
src/bin/dhcp4/tests/config_parser_unittest.cc
View file @
3a1e8654
...
...
@@ -324,30 +324,30 @@ public:
size_t
expected_data_len
,
bool
extra_data
=
false
)
{
// Check if option descriptor contains valid option pointer.
ASSERT_TRUE
(
option_desc
.
option
);
ASSERT_TRUE
(
option_desc
.
option
_
);
// Verify option type.
EXPECT_EQ
(
expected_code
,
option_desc
.
option
->
getType
());
EXPECT_EQ
(
expected_code
,
option_desc
.
option
_
->
getType
());
// We may have many different option types being created. Some of them
// have dedicated classes derived from Option class. In such case if
// we want to verify the option contents against expected_data we have
// to prepare raw buffer with the contents of the option. The easiest
// way is to call pack() which will prepare on-wire data.
util
::
OutputBuffer
buf
(
option_desc
.
option
->
getData
().
size
());
option_desc
.
option
->
pack
(
buf
);
util
::
OutputBuffer
buf
(
option_desc
.
option
_
->
getData
().
size
());
option_desc
.
option
_
->
pack
(
buf
);
if
(
extra_data
)
{
// The length of the buffer must be at least equal to size of the
// reference data but it can sometimes be greater than that. This is
// because some options carry suboptions that increase the overall
// length.
ASSERT_GE
(
buf
.
getLength
()
-
option_desc
.
option
->
getHeaderLen
(),
ASSERT_GE
(
buf
.
getLength
()
-
option_desc
.
option
_
->
getHeaderLen
(),
expected_data_len
);
}
else
{
ASSERT_EQ
(
buf
.
getLength
()
-
option_desc
.
option
->
getHeaderLen
(),
ASSERT_EQ
(
buf
.
getLength
()
-
option_desc
.
option
_
->
getHeaderLen
(),
expected_data_len
);
}
// Verify that the data is correct. Do not verify suboptions and a header.
const
uint8_t
*
data
=
static_cast
<
const
uint8_t
*>
(
buf
.
getData
());
EXPECT_EQ
(
0
,
memcmp
(
expected_data
,
data
+
option_desc
.
option
->
getHeaderLen
(),
EXPECT_EQ
(
0
,
memcmp
(
expected_data
,
data
+
option_desc
.
option
_
->
getHeaderLen
(),
expected_data_len
));
}
...
...
@@ -380,7 +380,7 @@ public:
// The subnet should now hold one option with the specified option code.
OptionDescriptor
desc
=
getOptionFromSubnet
(
IOAddress
(
"192.0.2.24"
),
option_code
);
ASSERT_TRUE
(
desc
.
option
);
ASSERT_TRUE
(
desc
.
option
_
);
testOption
(
desc
,
option_code
,
expected_data
,
expected_data_len
);
}
...
...
@@ -1885,16 +1885,16 @@ TEST_F(Dhcp4ParserTest, optionDataTwoSpaces) {
ASSERT_TRUE
(
subnet
);
// Try to get the option from the space dhcp4.
OptionDescriptor
desc1
=
subnet
->
getCfgOption
()
->
get
(
"dhcp4"
,
56
);
ASSERT_TRUE
(
desc1
.
option
);
EXPECT_EQ
(
56
,
desc1
.
option
->
getType
());
ASSERT_TRUE
(
desc1
.
option
_
);
EXPECT_EQ
(
56
,
desc1
.
option
_
->
getType
());
// Try to get the option from the space isc.
OptionDescriptor
desc2
=
subnet
->
getCfgOption
()
->
get
(
"isc"
,
56
);
ASSERT_TRUE
(
desc2
.
option
);
EXPECT_EQ
(
56
,
desc1
.
option
->
getType
());
ASSERT_TRUE
(
desc2
.
option
_
);
EXPECT_EQ
(
56
,
desc1
.
option
_
->
getType
());
// Try to get the non-existing option from the non-existing
// option space and expect that option is not returned.
OptionDescriptor
desc3
=
subnet
->
getCfgOption
()
->
get
(
"non-existing"
,
56
);
ASSERT_FALSE
(
desc3
.
option
);
ASSERT_FALSE
(
desc3
.
option
_
);
}
// The goal of this test is to verify that it is possible to
...
...
@@ -2045,17 +2045,17 @@ TEST_F(Dhcp4ParserTest, optionDataEncapsulate) {
// Get the option.
OptionDescriptor
desc
=
subnet
->
getCfgOption
()
->
get
(
"dhcp4"
,
222
);
EXPECT_TRUE
(
desc
.
option
);
EXPECT_EQ
(
222
,
desc
.
option
->
getType
());
EXPECT_TRUE
(
desc
.
option
_
);
EXPECT_EQ
(
222
,
desc
.
option
_
->
getType
());
// This opton should comprise two sub-options.
// One of them is 'foo' with code 1.
OptionPtr
option_foo
=
desc
.
option
->
getOption
(
1
);
OptionPtr
option_foo
=
desc
.
option
_
->
getOption
(
1
);
ASSERT_TRUE
(
option_foo
);
EXPECT_EQ
(
1
,
option_foo
->
getType
());
// ...another one 'foo2' with code 2.
OptionPtr
option_foo2
=
desc
.
option
->
getOption
(
2
);
OptionPtr
option_foo2
=
desc
.
option
_
->
getOption
(
2
);
ASSERT_TRUE
(
option_foo2
);
EXPECT_EQ
(
2
,
option_foo2
->
getType
());
}
...
...
@@ -2152,7 +2152,7 @@ TEST_F(Dhcp4ParserTest, optionDataBoolean) {
// The subnet should now hold one option with the code 19.
OptionDescriptor
desc
=
getOptionFromSubnet
(
IOAddress
(
"192.0.2.24"
),
19
);
ASSERT_TRUE
(
desc
.
option
);
ASSERT_TRUE
(
desc
.
option
_
);
// This option should be set to "true", represented as 0x1 in the option
// buffer.
...
...
@@ -2419,7 +2419,7 @@ TEST_F(Dhcp4ParserTest, stdOptionData) {
ASSERT_EQ
(
1
,
std
::
distance
(
range
.
first
,
range
.
second
));
// The actual pointer to the option is held in the option field
// in the structure returned.
OptionPtr
option
=
range
.
first
->
option
;
OptionPtr
option
=
range
.
first
->
option
_
;
ASSERT_TRUE
(
option
);
// Option object returned for here is expected to be Option6IA
// which is derived from Option. This class is dedicated to
...
...
@@ -2618,11 +2618,11 @@ TEST_F(Dhcp4ParserTest, stdOptionDataEncapsulate) {
// Get the option.
OptionDescriptor
desc
=
subnet
->
getCfgOption
()
->
get
(
"dhcp4"
,
DHO_VENDOR_ENCAPSULATED_OPTIONS
);
EXPECT_TRUE
(
desc
.
option
);
EXPECT_EQ
(
DHO_VENDOR_ENCAPSULATED_OPTIONS
,
desc
.
option
->
getType
());
EXPECT_TRUE
(
desc
.
option
_
);
EXPECT_EQ
(
DHO_VENDOR_ENCAPSULATED_OPTIONS
,
desc
.
option
_
->
getType
());
// Option with the code 1 should be added as a sub-option.
OptionPtr
option_foo
=
desc
.
option
->
getOption
(
1
);
OptionPtr
option_foo
=
desc
.
option
_
->
getOption
(
1
);
ASSERT_TRUE
(
option_foo
);
EXPECT_EQ
(
1
,
option_foo
->
getType
());
// This option comprises a single uint32_t value thus it is
...
...
@@ -2635,7 +2635,7 @@ TEST_F(Dhcp4ParserTest, stdOptionDataEncapsulate) {
EXPECT_EQ
(
1234
,
option_foo_uint32
->
getValue
());
// Option with the code 2 should be added as a sub-option.
OptionPtr
option_foo2
=
desc
.
option
->
getOption
(
2
);
OptionPtr
option_foo2
=
desc
.
option
_
->
getOption
(
2
);
ASSERT_TRUE
(
option_foo2
);
EXPECT_EQ
(
2
,
option_foo2
->
getType
());
// This option comprises the IPV4 address. Such option is
...
...
@@ -2647,7 +2647,7 @@ TEST_F(Dhcp4ParserTest, stdOptionDataEncapsulate) {
EXPECT_EQ
(
"192.168.2.1"
,
option_foo2_v4
->
readAddress
().
toText
());
// Option with the code 3 should not be added.
EXPECT_FALSE
(
desc
.
option
->
getOption
(
3
));
EXPECT_FALSE
(
desc
.
option
_
->
getOption
(
3
));
}
// This test checks if vendor options can be specified in the config file
...
...
@@ -2696,17 +2696,17 @@ TEST_F(Dhcp4ParserTest, vendorOptionsHex) {
// Try to get the option from the vendor space 4491
OptionDescriptor
desc1
=
subnet
->
getCfgOption
()
->
get
(
VENDOR_ID_CABLE_LABS
,
100
);
ASSERT_TRUE
(
desc1
.
option
);
EXPECT_EQ
(
100
,
desc1
.
option
->
getType
());
ASSERT_TRUE
(
desc1
.
option
_
);
EXPECT_EQ
(
100
,
desc1
.
option
_
->
getType
());
// Try to get the option from the vendor space 1234
OptionDescriptor
desc2
=
subnet
->
getCfgOption
()
->
get
(
1234
,
100
);
ASSERT_TRUE
(
desc2
.
option
);
EXPECT_EQ
(
100
,
desc1
.
option
->
getType
());
ASSERT_TRUE
(
desc2
.
option
_
);
EXPECT_EQ
(
100
,
desc1
.
option
_
->
getType
());
// Try to get the non-existing option from the non-existing
// option space and expect that option is not returned.
OptionDescriptor
desc3
=
subnet
->
getCfgOption
()
->
get
(
5678
,
100
);
ASSERT_FALSE
(
desc3
.
option
);
ASSERT_FALSE
(
desc3
.
option
_
);
}
// This test checks if vendor options can be specified in the config file,
...
...
@@ -2757,13 +2757,13 @@ TEST_F(Dhcp4ParserTest, vendorOptionsCsv) {
// Try to get the option from the vendor space 4491
OptionDescriptor
desc1
=
subnet
->
getCfgOption
()
->
get
(
VENDOR_ID_CABLE_LABS
,
100
);
ASSERT_TRUE
(
desc1
.
option
);
EXPECT_EQ
(
100
,
desc1
.
option
->
getType
());
ASSERT_TRUE
(
desc1
.
option
_
);
EXPECT_EQ
(
100
,
desc1
.
option
_
->
getType
());
// Try to get the non-existing option from the non-existing
// option space and expect that option is not returned.
OptionDescriptor
desc2
=
subnet
->
getCfgOption
()
->
get
(
5678
,
100
);
ASSERT_FALSE
(
desc2
.
option
);
ASSERT_FALSE
(
desc2
.
option
_
);
}
...
...
src/bin/dhcp6/dhcp6_srv.cc
View file @
3a1e8654
...
...
@@ -732,8 +732,8 @@ Dhcpv6Srv::appendRequestedOptions(const Pkt6Ptr& question, Pkt6Ptr& answer) {
const
std
::
vector
<
uint16_t
>&
requested_opts
=
option_oro
->
getValues
();
BOOST_FOREACH
(
uint16_t
opt
,
requested_opts
)
{
OptionDescriptor
desc
=
subnet
->
getCfgOption
()
->
get
(
"dhcp6"
,
opt
);
if
(
desc
.
option
)
{
answer
->
addOption
(
desc
.
option
);
if
(
desc
.
option
_
)
{
answer
->
addOption
(
desc
.
option
_
);
}
}
}
...
...
@@ -778,8 +778,8 @@ Dhcpv6Srv::appendRequestedVendorOptions(const Pkt6Ptr& question, Pkt6Ptr& answer
const
std
::
vector
<
uint16_t
>&
requested_opts
=
oro
->
getValues
();
BOOST_FOREACH
(
uint16_t
opt
,
requested_opts
)
{
OptionDescriptor
desc
=
subnet
->
getCfgOption
()
->
get
(
vendor_id
,
opt
);
if
(
desc
.
option
)
{
vendor_rsp
->
addOption
(
desc
.
option
);
if
(
desc
.
option
_
)
{
vendor_rsp
->
addOption
(
desc
.
option
_
);
added
=
true
;
}
}
...
...
src/bin/dhcp6/tests/config_parser_unittest.cc
View file @
3a1e8654
...
...
@@ -418,30 +418,30 @@ public:
size_t
expected_data_len
,
bool
extra_data
=
false
)
{
// Check if option descriptor contains valid option pointer.
ASSERT_TRUE
(
option_desc
.
option
);
ASSERT_TRUE
(
option_desc
.
option
_
);
// Verify option type.
EXPECT_EQ
(
expected_code
,
option_desc
.
option
->
getType
());
EXPECT_EQ
(
expected_code
,
option_desc
.
option
_
->
getType
());
// We may have many different option types being created. Some of them
// have dedicated classes derived from Option class. In such case if
// we want to verify the option contents against expected_data we have
// to prepare raw buffer with the contents of the option. The easiest
// way is to call pack() which will prepare on-wire data.
util
::
OutputBuffer
buf
(
option_desc
.
option
->
getData
().
size
());
option_desc
.
option
->
pack
(
buf
);
util
::
OutputBuffer
buf
(
option_desc
.
option
_
->
getData
().
size
());
option_desc
.
option
_
->
pack
(
buf
);
if
(
extra_data
)
{
// The length of the buffer must be at least equal to size of the
// reference data but it can sometimes be greater than that. This is
// because some options carry suboptions that increase the overall
// length.
ASSERT_GE
(
buf
.
getLength
()
-
option_desc
.
option
->
getHeaderLen
(),
ASSERT_GE
(
buf
.
getLength
()
-
option_desc
.
option
_
->
getHeaderLen
(),
expected_data_len
);
}
else
{
ASSERT_EQ
(
buf
.
getLength
()
-
option_desc
.
option
->
getHeaderLen
(),
ASSERT_EQ
(
buf
.
getLength
()
-
option_desc
.
option
_
->
getHeaderLen
(),
expected_data_len
);
}
// Verify that the data is correct. Do not verify suboptions and a header.
const
uint8_t
*
data
=
static_cast
<
const
uint8_t
*>
(
buf
.
getData
());
EXPECT_EQ
(
0
,
memcmp
(
expected_data
,
data
+
option_desc
.
option
->
getHeaderLen
(),
EXPECT_EQ
(
0
,
memcmp
(
expected_data
,
data
+
option_desc
.
option
_
->
getHeaderLen
(),
expected_data_len
));
}
...
...
@@ -475,7 +475,7 @@ public:
// The subnet should now hold one option with the specified code.
OptionDescriptor
desc
=
getOptionFromSubnet
(
IOAddress
(
"2001:db8:1::5"
),
option_code
);
ASSERT_TRUE
(
desc
.
option
);
ASSERT_TRUE
(
desc
.
option
_
);
testOption
(
desc
,
option_code
,
expected_data
,
expected_data_len
);
CfgMgr
::
instance
().
clear
();
}
...
...
@@ -2127,16 +2127,16 @@ TEST_F(Dhcp6ParserTest, optionDataTwoSpaces) {
ASSERT_TRUE
(
subnet
);
// Try to get the option from the space dhcp6.
OptionDescriptor
desc1
=
subnet
->
getCfgOption
()
->
get
(
"dhcp6"
,
38
);
ASSERT_TRUE
(
desc1
.
option
);
EXPECT_EQ
(
38
,
desc1
.
option
->
getType
());
ASSERT_TRUE
(
desc1
.
option
_
);
EXPECT_EQ
(
38
,
desc1
.
option
_
->
getType
());
// Try to get the option from the space isc.
OptionDescriptor
desc2
=
subnet
->
getCfgOption
()
->
get
(
"isc"
,
38
);
ASSERT_TRUE
(
desc2
.
option
);
EXPECT_EQ
(
38
,
desc1
.
option
->
getType
());
ASSERT_TRUE
(
desc2
.
option
_
);
EXPECT_EQ
(
38
,
desc1
.
option
_
->
getType
());
// Try to get the non-existing option from the non-existing
// option space and expect that option is not returned.
OptionDescriptor
desc3
=
subnet
->
getCfgOption
()
->
get
(
"non-existing"
,
38
);
ASSERT_FALSE
(
desc3
.
option
);
ASSERT_FALSE
(
desc3
.
option
_
);
}
// The goal of this test is to verify that it is possible to
...
...
@@ -2289,17 +2289,17 @@ TEST_F(Dhcp6ParserTest, optionDataEncapsulate) {
// Get the option.
OptionDescriptor
desc
=
subnet
->
getCfgOption
()
->
get
(
"dhcp6"
,
100
);
EXPECT_TRUE
(
desc
.
option
);
EXPECT_EQ
(
100
,
desc
.
option
->
getType
());
EXPECT_TRUE
(
desc
.
option
_
);
EXPECT_EQ
(
100
,
desc
.
option
_
->
getType
());
// This opton should comprise two sub-options.
// Onf of them is 'foo' with code 110.
OptionPtr
option_foo
=
desc
.
option
->
getOption
(
110
);
OptionPtr
option_foo
=
desc
.
option
_
->
getOption
(
110
);
ASSERT_TRUE
(
option_foo
);
EXPECT_EQ
(
110
,
option_foo
->
getType
());
// ...another one 'foo2' with code 111.
OptionPtr
option_foo2
=
desc
.
option
->
getOption
(
111
);
OptionPtr
option_foo2
=
desc
.
option
_
->
getOption
(
111
);
ASSERT_TRUE
(
option_foo2
);
EXPECT_EQ
(
111
,
option_foo2
->
getType
());
}
...
...
@@ -2407,7 +2407,7 @@ TEST_F(Dhcp6ParserTest, optionDataBoolean) {
// The subnet should now hold one option with the code 1000.
OptionDescriptor
desc
=
getOptionFromSubnet
(
IOAddress
(
"2001:db8:1::5"
),
1000
);
ASSERT_TRUE
(
desc
.
option
);
ASSERT_TRUE
(
desc
.
option
_
);
// This option should be set to "true", represented as 0x1 in the option
// buffer.
...
...
@@ -2600,7 +2600,7 @@ TEST_F(Dhcp6ParserTest, stdOptionData) {
ASSERT_EQ
(
1
,
std
::
distance
(
range
.
first
,
range
.
second
));
// The actual pointer to the option is held in the option field
// in the structure returned.
OptionPtr
option
=
range
.
first
->
option
;
OptionPtr
option
=
range
.
first
->
option
_
;
ASSERT_TRUE
(
option
);
// Option object returned for here is expected to be Option6IA
// which is derived from Option. This class is dedicated to
...
...
@@ -2665,17 +2665,17 @@ TEST_F(Dhcp6ParserTest, vendorOptionsHex) {
// Try to get the option from the vendor space 4491
OptionDescriptor
desc1
=
subnet
->
getCfgOption
()
->
get
(
4491
,
100
);
ASSERT_TRUE
(
desc1
.
option
);
EXPECT_EQ
(
100
,
desc1
.
option
->
getType
());
ASSERT_TRUE
(
desc1
.
option
_
);
EXPECT_EQ
(
100
,
desc1
.
option
_
->
getType
());
// Try to get the option from the vendor space 1234
OptionDescriptor
desc2
=
subnet
->
getCfgOption
()
->
get
(
1234
,
100
);
ASSERT_TRUE
(
desc2
.
option
);
EXPECT_EQ
(
100
,
desc1
.
option
->
getType
());
ASSERT_TRUE
(
desc2
.
option
_
);
EXPECT_EQ
(
100
,
desc1
.
option
_
->
getType
());
// Try to get the non-existing option from the non-existing
// option space and expect that option is not returned.
OptionDescriptor
desc3
=
subnet
->
getCfgOption
()
->
get
(
5678
,
38
);
ASSERT_FALSE
(
desc3
.
option
);
ASSERT_FALSE
(
desc3
.
option
_
);
}
// This test checks if vendor options can be specified in the config file,
...
...
@@ -2727,13 +2727,13 @@ TEST_F(Dhcp6ParserTest, vendorOptionsCsv) {
// Try to get the option from the vendor space 4491
OptionDescriptor
desc1
=
subnet
->
getCfgOption
()
->
get
(
4491
,
100
);
ASSERT_TRUE
(
desc1
.
option
);
EXPECT_EQ
(
100
,
desc1
.
option
->
getType
());
ASSERT_TRUE
(
desc1
.
option
_
);
EXPECT_EQ
(
100
,
desc1
.
option
_
->
getType
());
// Try to get the non-existing option from the non-existing
// option space and expect that option is not returned.
OptionDescriptor
desc2
=
subnet
->
getCfgOption
()
->
get
(
5678
,
100
);
ASSERT_FALSE
(
desc2
.
option
);
ASSERT_FALSE
(
desc2
.
option
_
);
}
/// @todo add tests similar to vendorOptionsCsv and vendorOptionsHex, but for
...
...
@@ -2875,11 +2875,11 @@ TEST_F(Dhcp6ParserTest, DISABLED_stdOptionDataEncapsulate) {
// Get the option.
OptionDescriptor
desc
=
subnet
->
getCfgOption
()
->
get
(
"dhcp6"
,
D6O_VENDOR_OPTS
);
EXPECT_TRUE
(
desc
.
option
);
EXPECT_EQ
(
D6O_VENDOR_OPTS
,
desc
.
option
->
getType
());
EXPECT_TRUE
(
desc
.
option
_
);
EXPECT_EQ
(
D6O_VENDOR_OPTS
,
desc
.
option
_
->
getType
());
// Option with the code 110 should be added as a sub-option.
OptionPtr
option_foo
=
desc
.
option
->
getOption
(
110
);
OptionPtr
option_foo
=
desc
.
option
_
->
getOption
(
110
);
ASSERT_TRUE
(
option_foo
);
EXPECT_EQ
(
110
,
option_foo
->
getType
());
// This option comprises a single uint32_t value thus it is
...
...
@@ -2892,7 +2892,7 @@ TEST_F(Dhcp6ParserTest, DISABLED_stdOptionDataEncapsulate) {
EXPECT_EQ
(
1234
,
option_foo_uint32
->
getValue
());
// Option with the code 111 should be added as a sub-option.
OptionPtr
option_foo2
=
desc
.
option
->
getOption
(
111
);
OptionPtr
option_foo2
=
desc
.
option
_
->
getOption
(
111
);
ASSERT_TRUE
(
option_foo2
);
EXPECT_EQ
(
111
,
option_foo2
->
getType
());
// This option comprises the IPV4 address. Such option is
...
...
@@ -2904,7 +2904,7 @@ TEST_F(Dhcp6ParserTest, DISABLED_stdOptionDataEncapsulate) {
EXPECT_EQ
(
"192.168.2.1"
,
option_foo2_v4
->
readAddress
().
toText
());
// Option with the code 112 should not be added.
EXPECT_FALSE
(
desc
.
option
->
getOption
(
112
));
EXPECT_FALSE
(
desc
.
option
_
->
getOption
(
112
));
}
// Tests of the hooks libraries configuration. All tests have the pre-
...
...
src/lib/dhcpsrv/cfg_option.cc
View file @
3a1e8654
...
...
@@ -23,8 +23,8 @@ namespace dhcp {
bool
OptionDescriptor
::
equals
(
const
OptionDescriptor
&
other
)
const
{
return
(
persistent
==
other
.
persistent
&&
option
->
equals
(
other
.
option
));
return
(
persistent
_
==
other
.
persistent
_
&&
option
_
->
equals
(
other
.
option
_
));
}
bool
...
...
@@ -82,14 +82,14 @@ CfgOption::encapsulateInternal(const std::string& option_space) {
OptionContainerPtr
options
=
getAll
(
option_space
);
for
(
OptionContainer
::
const_iterator
opt
=
options
->
begin
();
opt
!=
options
->
end
();
++
opt
)
{
const
std
::
string
&
encap_space
=
opt
->
option
->
getEncapsulatedSpace
();
const
std
::
string
&
encap_space
=
opt
->
option
_
->
getEncapsulatedSpace
();
if
(
!
encap_space
.
empty
())
{
OptionContainerPtr
encap_options
=
getAll
(
encap_space
);
for
(
OptionContainer
::
const_iterator
encap_opt
=
encap_options
->
begin
();
encap_opt
!=
encap_options
->
end
();
++
encap_opt
)
{
if
(
!
opt
->
option
->
getOption
(
encap_opt
->
option
->
getType
()))
{
opt
->
option
->
addOption
(
encap_opt
->
option
);
if
(
!
opt
->
option
_
->
getOption
(
encap_opt
->
option
_
->
getType
()))
{
opt
->
option
_
->
addOption
(
encap_opt
->
option
_
);
}
}
}
...
...
@@ -121,12 +121,12 @@ CfgOption::mergeInternal(const OptionSpaceContainer<OptionContainer,
src_opt
!=
src_all
->
end
();
++
src_opt
)
{
const
OptionContainerTypeIndex
&
idx
=
dest_all
->
get
<
1
>
();
const
OptionContainerTypeRange
&
range
=
idx
.
equal_range
(
src_opt
->
option
->
getType
());
idx
.
equal_range
(
src_opt
->
option
_
->
getType
());
// If there is no such option in the destination container,
// add one.
if
(
std
::
distance
(
range
.
first
,
range
.
second
)
==
0
)
{
dest_container
.
addItem
(
OptionDescriptor
(
src_opt
->
option
,
src_opt
->
persistent
),
dest_container
.
addItem
(
OptionDescriptor
(
src_opt
->
option
_
,
src_opt
->
persistent
_
),
*
it
);
}
}
...
...
src/lib/dhcpsrv/cfg_option.h
View file @
3a1e8654
...
...
@@ -38,23 +38,23 @@ namespace dhcp {
/// (persistent = true).
struct
OptionDescriptor
{
/// Option instance.
OptionPtr
option
;
OptionPtr
option
_
;
/// Persistent flag, if true option is always sent to the client,
/// if false option is sent to the client on request.
bool
persistent
;
bool
persistent
_
;
/// @brief Constructor.
///
/// @param opt option
/// @param persist if true option is always sent.
OptionDescriptor
(
const
OptionPtr
&
opt
,
bool
persist
)
:
option
(
opt
),
persistent
(
persist
)
{};
:
option
_
(
opt
),
persistent
_
(
persist
)
{};
/// @brief Constructor
///
/// @param persist if true option is always sent.
OptionDescriptor
(
bool
persist
)
:
option
(
OptionPtr
()),
persistent
(
persist
)
{};
:
option
_
(
OptionPtr
()),
persistent
_
(
persist
)
{};
/// @brief Checks if the one descriptor is equal to another.
///
...
...
@@ -140,7 +140,7 @@ typedef boost::multi_index_container<
boost
::
multi_index
::
member
<
OptionDescriptor
,
OptionPtr
,
&
OptionDescriptor
::
option
&
OptionDescriptor
::
option
_
>
>
>
,
...
...
@@ -150,7 +150,7 @@ typedef boost::multi_index_container<
boost
::
multi_index
::
member
<
OptionDescriptor
,
bool
,
&
OptionDescriptor
::
persistent
&
OptionDescriptor
::
persistent
_
>
>
>
...
...
src/lib/dhcpsrv/dhcp_parsers.cc
View file @
3a1e8654
...
...
@@ -327,13 +327,13 @@ OptionDataParser::build(ConstElementPtr option_data_entries) {
// Try to create the option instance.
createOption
(
option_data_entries
);
if
(
!
option_descriptor_
.
option
)
{
if
(
!
option_descriptor_
.
option
_
)
{
isc_throw
(
isc
::
InvalidOperation
,
"parser logic error: no option has been configured and"
" thus there is nothing to commit. Has build() been called?"
);
}
cfg_
->
add
(
option_descriptor_
.
option
,
option_descriptor_
.
persistent
,
cfg_
->
add
(
option_descriptor_
.
option
_
,
option_descriptor_
.
persistent
_
,
option_space_
);
}
...
...
@@ -516,8 +516,8 @@ OptionDataParser::createOption(ConstElementPtr option_data) {
// until the commit stage when it is inserted into the main storage.
// If an option with the same code exists in main storage already the
// old option is replaced.
option_descriptor_
.
option
=
option
;
option_descriptor_
.
persistent
=
false
;
option_descriptor_
.
option
_
=
option
;
option_descriptor_
.
persistent
_
=
false
;
}
else
{
// Option name should match the definition. The option name
...
...
@@ -540,8 +540,8 @@ OptionDataParser::createOption(ConstElementPtr option_data) {
def
->
optionFactory
(
universe
,
code
,
data_tokens
)
:
def
->
optionFactory
(
universe
,
code
,
binary
);
OptionDescriptor
desc
(
option
,
false
);
option_descriptor_
.
option
=
option
;
option_descriptor_
.
persistent
=
false
;
option_descriptor_
.
option
_
=
option
;
option_descriptor_
.
persistent
_
=
false
;
}
catch
(
const
isc
::
Exception
&
ex
)
{
isc_throw
(
DhcpConfigError
,
"option data does not match"
...
...
src/lib/dhcpsrv/tests/cfg_option_unittest.cc
View file @
3a1e8654
...
...
@@ -106,8 +106,8 @@ TEST(CfgOptionTest, add) {
uint16_t
expected_code
=
100
;
for
(
OptionContainer
::
const_iterator
option_desc
=
options
->
begin
();
option_desc
!=
options
->
end
();
++
option_desc
)
{
ASSERT_TRUE
(
option_desc
->
option
);
EXPECT_EQ
(
expected_code
,
option_desc
->
option
->
getType
());
ASSERT_TRUE
(
option_desc
->
option
_
);
EXPECT_EQ
(
expected_code
,
option_desc
->
option
_
->
getType
());
++
expected_code
;
}
...
...
@@ -119,8 +119,8 @@ TEST(CfgOptionTest, add) {
expected_code
=
105
;
for
(
OptionContainer
::
const_iterator
option_desc
=
options
->
begin
();
option_desc
!=
options
->
end
();
++
option_desc
)
{
ASSERT_TRUE
(
option_desc
->
option
);
EXPECT_EQ
(
expected_code
,
option_desc
->
option
->
getType
());
ASSERT_TRUE
(
option_desc
->
option
_
);
EXPECT_EQ
(
expected_code
,
option_desc
->
option
_
->
getType
());
++
expected_code
;
}
...
...
@@ -174,32 +174,32 @@ TEST(CfgOption, merge) {
// Validate the options in the dhcp6 option space in the destination.
for
(
uint16_t
code
=
100
;
code
<
110
;
++
code
)
{
OptionDescriptor
desc
=
cfg_dst
.
get
(
"dhcp6"
,
code
);
ASSERT_TRUE
(
desc
.
option
);
ASSERT_EQ
(
1
,
desc
.
option
->
getData
().
size
());
ASSERT_TRUE
(
desc
.
option
_
);
ASSERT_EQ
(
1
,
desc
.
option
_
->
getData
().
size
());
// The options with even option codes should hold one byte of data
// equal to 0x1. These are the ones that we have initially added to
// the destination configuration. The other options should hold the
// values of 0xFF which indicates that they have been merged from the
// source configuration.
if
((
code
%
2
)
==
0
)
{
EXPECT_EQ
(
0x01
,
desc
.
option
->
getData
()[
0
]);
EXPECT_EQ
(
0x01
,
desc
.
option
_
->
getData
()[
0
]);
}
else
{
EXPECT_EQ
(
0xFF
,
desc
.
option
->
getData
()[
0
]);
EXPECT_EQ
(
0xFF
,
desc
.
option
_
->
getData
()[
0
]);
}
}
// Validate the options in the vendor space.
for
(
uint16_t
code
=
100
;
code
<
110
;
++
code
)
{
OptionDescriptor
desc
=
cfg_dst
.
get
(
123
,
code
);
ASSERT_TRUE
(
desc
.
option
);
ASSERT_EQ
(
1
,
desc
.
option
->
getData
().
size
());