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
bbdef979
Commit
bbdef979
authored
Sep 17, 2014
by
Marcin Siodelski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[3589] Created an object to hold the option configuration.
parent
efcbf029
Changes
15
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
753 additions
and
259 deletions
+753
-259
src/bin/dhcp4/dhcp4_srv.cc
src/bin/dhcp4/dhcp4_srv.cc
+4
-4
src/bin/dhcp4/tests/config_parser_unittest.cc
src/bin/dhcp4/tests/config_parser_unittest.cc
+45
-45
src/bin/dhcp6/dhcp6_srv.cc
src/bin/dhcp6/dhcp6_srv.cc
+2
-2
src/bin/dhcp6/tests/config_parser_unittest.cc
src/bin/dhcp6/tests/config_parser_unittest.cc
+41
-41
src/lib/dhcpsrv/Makefile.am
src/lib/dhcpsrv/Makefile.am
+1
-0
src/lib/dhcpsrv/cfg_option.cc
src/lib/dhcpsrv/cfg_option.cc
+98
-0
src/lib/dhcpsrv/cfg_option.h
src/lib/dhcpsrv/cfg_option.h
+267
-0
src/lib/dhcpsrv/dhcp_parsers.cc
src/lib/dhcpsrv/dhcp_parsers.cc
+11
-10
src/lib/dhcpsrv/dhcp_parsers.h
src/lib/dhcpsrv/dhcp_parsers.h
+4
-3
src/lib/dhcpsrv/subnet.cc
src/lib/dhcpsrv/subnet.cc
+4
-4
src/lib/dhcpsrv/subnet.h
src/lib/dhcpsrv/subnet.h
+3
-121
src/lib/dhcpsrv/tests/Makefile.am
src/lib/dhcpsrv/tests/Makefile.am
+1
-0
src/lib/dhcpsrv/tests/cfg_option_unittest.cc
src/lib/dhcpsrv/tests/cfg_option_unittest.cc
+243
-0
src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc
src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc
+9
-9
src/lib/dhcpsrv/tests/subnet_unittest.cc
src/lib/dhcpsrv/tests/subnet_unittest.cc
+20
-20
No files found.
src/bin/dhcp4/dhcp4_srv.cc
View file @
bbdef979
...
...
@@ -599,7 +599,7 @@ Dhcpv4Srv::appendRequestedOptions(const Pkt4Ptr& question, Pkt4Ptr& msg) {
for
(
std
::
vector
<
uint8_t
>::
const_iterator
opt
=
requested_opts
.
begin
();
opt
!=
requested_opts
.
end
();
++
opt
)
{
if
(
!
msg
->
getOption
(
*
opt
))
{
Subnet
::
OptionDescriptor
desc
=
OptionDescriptor
desc
=
subnet
->
getOptionDescriptor
(
"dhcp4"
,
*
opt
);
if
(
desc
.
option
&&
!
msg
->
getOption
(
*
opt
))
{
msg
->
addOption
(
desc
.
option
);
...
...
@@ -650,7 +650,7 @@ Dhcpv4Srv::appendRequestedVendorOptions(const Pkt4Ptr& question, Pkt4Ptr& answer
for
(
std
::
vector
<
uint8_t
>::
const_iterator
code
=
requested_opts
.
begin
();
code
!=
requested_opts
.
end
();
++
code
)
{
if
(
!
vendor_rsp
->
getOption
(
*
code
))
{
Subnet
::
OptionDescriptor
desc
=
subnet
->
getVendorOptionDescriptor
(
vendor_id
,
OptionDescriptor
desc
=
subnet
->
getVendorOptionDescriptor
(
vendor_id
,
*
code
);
if
(
desc
.
option
)
{
vendor_rsp
->
addOption
(
desc
.
option
);
...
...
@@ -689,7 +689,7 @@ Dhcpv4Srv::appendBasicOptions(const Pkt4Ptr& question, Pkt4Ptr& msg) {
OptionPtr
opt
=
msg
->
getOption
(
required_options
[
i
]);
if
(
!
opt
)
{
// Check whether option has been configured.
Subnet
::
OptionDescriptor
desc
=
OptionDescriptor
desc
=
subnet
->
getOptionDescriptor
(
"dhcp4"
,
required_options
[
i
]);
if
(
desc
.
option
)
{
msg
->
addOption
(
desc
.
option
);
...
...
@@ -1949,7 +1949,7 @@ bool Dhcpv4Srv::classSpecificProcessing(const Pkt4Ptr& query, const Pkt4Ptr& rsp
// Now try to set up file field in DHCPv4 packet. We will just copy
// content of the boot-file option, which contains the same information.
Subnet
::
OptionDescriptor
desc
=
OptionDescriptor
desc
=
subnet
->
getOptionDescriptor
(
"dhcp4"
,
DHO_BOOT_FILE_NAME
);
if
(
desc
.
option
)
{
...
...
src/bin/dhcp4/tests/config_parser_unittest.cc
View file @
bbdef979
...
...
@@ -231,7 +231,7 @@ public:
/// @return Descriptor of the option. If the descriptor holds a
/// NULL option pointer, it means that there was no such option
/// in the subnet.
Subnet
::
OptionDescriptor
OptionDescriptor
getOptionFromSubnet
(
const
IOAddress
&
subnet_address
,
const
uint16_t
option_code
,
const
uint16_t
expected_options_count
=
1
)
{
...
...
@@ -243,7 +243,7 @@ public:
<<
subnet_address
.
toText
()
<<
"does not exist in Config Manager"
;
}
Subnet
::
OptionContainerPtr
options
=
OptionContainerPtr
options
=
subnet
->
getOptionDescriptors
(
"dhcp4"
);
if
(
expected_options_count
!=
options
->
size
())
{
ADD_FAILURE
()
<<
"The number of options in the subnet '"
...
...
@@ -253,13 +253,13 @@ public:
}
// Get the search index. Index #1 is to search using option code.
const
Subnet
::
OptionContainerTypeIndex
&
idx
=
options
->
get
<
1
>
();
const
OptionContainerTypeIndex
&
idx
=
options
->
get
<
1
>
();
// Get the options for specified index. Expecting one option to be
// returned but in theory we may have multiple options with the same
// code so we get the range.
std
::
pair
<
Subnet
::
OptionContainerTypeIndex
::
const_iterator
,
Subnet
::
OptionContainerTypeIndex
::
const_iterator
>
range
=
std
::
pair
<
OptionContainerTypeIndex
::
const_iterator
,
OptionContainerTypeIndex
::
const_iterator
>
range
=
idx
.
equal_range
(
option_code
);
if
(
std
::
distance
(
range
.
first
,
range
.
second
)
>
1
)
{
ADD_FAILURE
()
<<
"There is more than one option having the"
...
...
@@ -267,7 +267,7 @@ public:
<<
subnet_address
.
toText
()
<<
"'. Expected "
" at most one option"
;
}
else
if
(
std
::
distance
(
range
.
first
,
range
.
second
)
==
0
)
{
return
(
Subnet
::
OptionDescriptor
(
OptionPtr
(),
false
));
return
(
OptionDescriptor
(
OptionPtr
(),
false
));
}
return
(
*
range
.
first
);
...
...
@@ -319,7 +319,7 @@ public:
/// @param expected_data_len length of the reference data.
/// @param extra_data if true extra data is allowed in an option
/// after tested data.
void
testOption
(
const
Subnet
::
OptionDescriptor
&
option_desc
,
void
testOption
(
const
OptionDescriptor
&
option_desc
,
uint16_t
expected_code
,
const
uint8_t
*
expected_data
,
size_t
expected_data_len
,
bool
extra_data
=
false
)
{
...
...
@@ -378,7 +378,7 @@ public:
std
::
string
config
=
createConfigWithOption
(
params
);
ASSERT_TRUE
(
executeConfiguration
(
config
,
"parse option configuration"
));
// The subnet should now hold one option with the specified option code.
Subnet
::
OptionDescriptor
desc
=
OptionDescriptor
desc
=
getOptionFromSubnet
(
IOAddress
(
"192.0.2.24"
),
option_code
);
ASSERT_TRUE
(
desc
.
option
);
testOption
(
desc
,
option_code
,
expected_data
,
expected_data_len
);
...
...
@@ -1797,17 +1797,17 @@ TEST_F(Dhcp4ParserTest, optionDataDefaults) {
Subnet4Ptr
subnet
=
CfgMgr
::
instance
().
getSubnet4
(
IOAddress
(
"192.0.2.200"
),
classify_
);
ASSERT_TRUE
(
subnet
);
Subnet
::
OptionContainerPtr
options
=
subnet
->
getOptionDescriptors
(
"dhcp4"
);
OptionContainerPtr
options
=
subnet
->
getOptionDescriptors
(
"dhcp4"
);
ASSERT_EQ
(
2
,
options
->
size
());
// Get the search index. Index #1 is to search using option code.
const
Subnet
::
OptionContainerTypeIndex
&
idx
=
options
->
get
<
1
>
();
const
OptionContainerTypeIndex
&
idx
=
options
->
get
<
1
>
();
// Get the options for specified index. Expecting one option to be
// returned but in theory we may have multiple options with the same
// code so we get the range.
std
::
pair
<
Subnet
::
OptionContainerTypeIndex
::
const_iterator
,
Subnet
::
OptionContainerTypeIndex
::
const_iterator
>
range
=
std
::
pair
<
OptionContainerTypeIndex
::
const_iterator
,
OptionContainerTypeIndex
::
const_iterator
>
range
=
idx
.
equal_range
(
56
);
// Expect single option with the code equal to 56.
ASSERT_EQ
(
1
,
std
::
distance
(
range
.
first
,
range
.
second
));
...
...
@@ -1884,16 +1884,16 @@ TEST_F(Dhcp4ParserTest, optionDataTwoSpaces) {
classify_
);
ASSERT_TRUE
(
subnet
);
// Try to get the option from the space dhcp4.
Subnet
::
OptionDescriptor
desc1
=
subnet
->
getOptionDescriptor
(
"dhcp4"
,
56
);
OptionDescriptor
desc1
=
subnet
->
getOptionDescriptor
(
"dhcp4"
,
56
);
ASSERT_TRUE
(
desc1
.
option
);
EXPECT_EQ
(
56
,
desc1
.
option
->
getType
());
// Try to get the option from the space isc.
Subnet
::
OptionDescriptor
desc2
=
subnet
->
getOptionDescriptor
(
"isc"
,
56
);
OptionDescriptor
desc2
=
subnet
->
getOptionDescriptor
(
"isc"
,
56
);
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.
Subnet
::
OptionDescriptor
desc3
=
subnet
->
getOptionDescriptor
(
"non-existing"
,
56
);
OptionDescriptor
desc3
=
subnet
->
getOptionDescriptor
(
"non-existing"
,
56
);
ASSERT_FALSE
(
desc3
.
option
);
}
...
...
@@ -2039,12 +2039,12 @@ TEST_F(Dhcp4ParserTest, optionDataEncapsulate) {
ASSERT_TRUE
(
subnet
);
// We should have one option available.
Subnet
::
OptionContainerPtr
options
=
subnet
->
getOptionDescriptors
(
"dhcp4"
);
OptionContainerPtr
options
=
subnet
->
getOptionDescriptors
(
"dhcp4"
);
ASSERT_TRUE
(
options
);
ASSERT_EQ
(
1
,
options
->
size
());
// Get the option.
Subnet
::
OptionDescriptor
desc
=
subnet
->
getOptionDescriptor
(
"dhcp4"
,
222
);
OptionDescriptor
desc
=
subnet
->
getOptionDescriptor
(
"dhcp4"
,
222
);
EXPECT_TRUE
(
desc
.
option
);
EXPECT_EQ
(
222
,
desc
.
option
->
getType
());
...
...
@@ -2104,17 +2104,17 @@ TEST_F(Dhcp4ParserTest, optionDataInSingleSubnet) {
Subnet4Ptr
subnet
=
CfgMgr
::
instance
().
getSubnet4
(
IOAddress
(
"192.0.2.24"
),
classify_
);
ASSERT_TRUE
(
subnet
);
Subnet
::
OptionContainerPtr
options
=
subnet
->
getOptionDescriptors
(
"dhcp4"
);
OptionContainerPtr
options
=
subnet
->
getOptionDescriptors
(
"dhcp4"
);
ASSERT_EQ
(
2
,
options
->
size
());
// Get the search index. Index #1 is to search using option code.
const
Subnet
::
OptionContainerTypeIndex
&
idx
=
options
->
get
<
1
>
();
const
OptionContainerTypeIndex
&
idx
=
options
->
get
<
1
>
();
// Get the options for specified index. Expecting one option to be
// returned but in theory we may have multiple options with the same
// code so we get the range.
std
::
pair
<
Subnet
::
OptionContainerTypeIndex
::
const_iterator
,
Subnet
::
OptionContainerTypeIndex
::
const_iterator
>
range
=
std
::
pair
<
OptionContainerTypeIndex
::
const_iterator
,
OptionContainerTypeIndex
::
const_iterator
>
range
=
idx
.
equal_range
(
56
);
// Expect single option with the code equal to 100.
ASSERT_EQ
(
1
,
std
::
distance
(
range
.
first
,
range
.
second
));
...
...
@@ -2150,7 +2150,7 @@ TEST_F(Dhcp4ParserTest, optionDataBoolean) {
" boolean value"
));
// The subnet should now hold one option with the code 19.
Subnet
::
OptionDescriptor
desc
=
getOptionFromSubnet
(
IOAddress
(
"192.0.2.24"
),
OptionDescriptor
desc
=
getOptionFromSubnet
(
IOAddress
(
"192.0.2.24"
),
19
);
ASSERT_TRUE
(
desc
.
option
);
...
...
@@ -2255,17 +2255,17 @@ TEST_F(Dhcp4ParserTest, optionDataInMultipleSubnets) {
Subnet4Ptr
subnet1
=
CfgMgr
::
instance
().
getSubnet4
(
IOAddress
(
"192.0.2.100"
),
classify_
);
ASSERT_TRUE
(
subnet1
);
Subnet
::
OptionContainerPtr
options1
=
subnet1
->
getOptionDescriptors
(
"dhcp4"
);
OptionContainerPtr
options1
=
subnet1
->
getOptionDescriptors
(
"dhcp4"
);
ASSERT_EQ
(
1
,
options1
->
size
());
// Get the search index. Index #1 is to search using option code.
const
Subnet
::
OptionContainerTypeIndex
&
idx1
=
options1
->
get
<
1
>
();
const
OptionContainerTypeIndex
&
idx1
=
options1
->
get
<
1
>
();
// Get the options for specified index. Expecting one option to be
// returned but in theory we may have multiple options with the same
// code so we get the range.
std
::
pair
<
Subnet
::
OptionContainerTypeIndex
::
const_iterator
,
Subnet
::
OptionContainerTypeIndex
::
const_iterator
>
range1
=
std
::
pair
<
OptionContainerTypeIndex
::
const_iterator
,
OptionContainerTypeIndex
::
const_iterator
>
range1
=
idx1
.
equal_range
(
56
);
// Expect single option with the code equal to 56.
ASSERT_EQ
(
1
,
std
::
distance
(
range1
.
first
,
range1
.
second
));
...
...
@@ -2280,12 +2280,12 @@ TEST_F(Dhcp4ParserTest, optionDataInMultipleSubnets) {
Subnet4Ptr
subnet2
=
CfgMgr
::
instance
().
getSubnet4
(
IOAddress
(
"192.0.3.102"
),
classify_
);
ASSERT_TRUE
(
subnet2
);
Subnet
::
OptionContainerPtr
options2
=
subnet2
->
getOptionDescriptors
(
"dhcp4"
);
OptionContainerPtr
options2
=
subnet2
->
getOptionDescriptors
(
"dhcp4"
);
ASSERT_EQ
(
1
,
options2
->
size
());
const
Subnet
::
OptionContainerTypeIndex
&
idx2
=
options2
->
get
<
1
>
();
std
::
pair
<
Subnet
::
OptionContainerTypeIndex
::
const_iterator
,
Subnet
::
OptionContainerTypeIndex
::
const_iterator
>
range2
=
const
OptionContainerTypeIndex
&
idx2
=
options2
->
get
<
1
>
();
std
::
pair
<
OptionContainerTypeIndex
::
const_iterator
,
OptionContainerTypeIndex
::
const_iterator
>
range2
=
idx2
.
equal_range
(
23
);
ASSERT_EQ
(
1
,
std
::
distance
(
range2
.
first
,
range2
.
second
));
...
...
@@ -2358,17 +2358,17 @@ TEST_F(Dhcp4ParserTest, optionDataLowerCase) {
Subnet4Ptr
subnet
=
CfgMgr
::
instance
().
getSubnet4
(
IOAddress
(
"192.0.2.5"
),
classify_
);
ASSERT_TRUE
(
subnet
);
Subnet
::
OptionContainerPtr
options
=
subnet
->
getOptionDescriptors
(
"dhcp4"
);
OptionContainerPtr
options
=
subnet
->
getOptionDescriptors
(
"dhcp4"
);
ASSERT_EQ
(
1
,
options
->
size
());
// Get the search index. Index #1 is to search using option code.
const
Subnet
::
OptionContainerTypeIndex
&
idx
=
options
->
get
<
1
>
();
const
OptionContainerTypeIndex
&
idx
=
options
->
get
<
1
>
();
// Get the options for specified index. Expecting one option to be
// returned but in theory we may have multiple options with the same
// code so we get the range.
std
::
pair
<
Subnet
::
OptionContainerTypeIndex
::
const_iterator
,
Subnet
::
OptionContainerTypeIndex
::
const_iterator
>
range
=
std
::
pair
<
OptionContainerTypeIndex
::
const_iterator
,
OptionContainerTypeIndex
::
const_iterator
>
range
=
idx
.
equal_range
(
56
);
// Expect single option with the code equal to 100.
ASSERT_EQ
(
1
,
std
::
distance
(
range
.
first
,
range
.
second
));
...
...
@@ -2401,19 +2401,19 @@ TEST_F(Dhcp4ParserTest, stdOptionData) {
Subnet4Ptr
subnet
=
CfgMgr
::
instance
().
getSubnet4
(
IOAddress
(
"192.0.2.5"
),
classify_
);
ASSERT_TRUE
(
subnet
);
Subnet
::
OptionContainerPtr
options
=
OptionContainerPtr
options
=
subnet
->
getOptionDescriptors
(
"dhcp4"
);
ASSERT_TRUE
(
options
);
ASSERT_EQ
(
1
,
options
->
size
());
// Get the search index. Index #1 is to search using option code.
const
Subnet
::
OptionContainerTypeIndex
&
idx
=
options
->
get
<
1
>
();
const
OptionContainerTypeIndex
&
idx
=
options
->
get
<
1
>
();
// Get the options for specified index. Expecting one option to be
// returned but in theory we may have multiple options with the same
// code so we get the range.
std
::
pair
<
Subnet
::
OptionContainerTypeIndex
::
const_iterator
,
Subnet
::
OptionContainerTypeIndex
::
const_iterator
>
range
=
std
::
pair
<
OptionContainerTypeIndex
::
const_iterator
,
OptionContainerTypeIndex
::
const_iterator
>
range
=
idx
.
equal_range
(
DHO_NIS_SERVERS
);
// Expect single option with the code equal to NIS_SERVERS option code.
ASSERT_EQ
(
1
,
std
::
distance
(
range
.
first
,
range
.
second
));
...
...
@@ -2611,12 +2611,12 @@ TEST_F(Dhcp4ParserTest, stdOptionDataEncapsulate) {
ASSERT_TRUE
(
subnet
);
// We should have one option available.
Subnet
::
OptionContainerPtr
options
=
subnet
->
getOptionDescriptors
(
"dhcp4"
);
OptionContainerPtr
options
=
subnet
->
getOptionDescriptors
(
"dhcp4"
);
ASSERT_TRUE
(
options
);
ASSERT_EQ
(
1
,
options
->
size
());
// Get the option.
Subnet
::
OptionDescriptor
desc
=
OptionDescriptor
desc
=
subnet
->
getOptionDescriptor
(
"dhcp4"
,
DHO_VENDOR_ENCAPSULATED_OPTIONS
);
EXPECT_TRUE
(
desc
.
option
);
EXPECT_EQ
(
DHO_VENDOR_ENCAPSULATED_OPTIONS
,
desc
.
option
->
getType
());
...
...
@@ -2695,17 +2695,17 @@ TEST_F(Dhcp4ParserTest, vendorOptionsHex) {
ASSERT_TRUE
(
subnet
);
// Try to get the option from the vendor space 4491
Subnet
::
OptionDescriptor
desc1
=
subnet
->
getVendorOptionDescriptor
(
VENDOR_ID_CABLE_LABS
,
100
);
OptionDescriptor
desc1
=
subnet
->
getVendorOptionDescriptor
(
VENDOR_ID_CABLE_LABS
,
100
);
ASSERT_TRUE
(
desc1
.
option
);
EXPECT_EQ
(
100
,
desc1
.
option
->
getType
());
// Try to get the option from the vendor space 1234
Subnet
::
OptionDescriptor
desc2
=
subnet
->
getVendorOptionDescriptor
(
1234
,
100
);
OptionDescriptor
desc2
=
subnet
->
getVendorOptionDescriptor
(
1234
,
100
);
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.
Subnet
::
OptionDescriptor
desc3
=
subnet
->
getVendorOptionDescriptor
(
5678
,
100
);
OptionDescriptor
desc3
=
subnet
->
getVendorOptionDescriptor
(
5678
,
100
);
ASSERT_FALSE
(
desc3
.
option
);
}
...
...
@@ -2756,13 +2756,13 @@ TEST_F(Dhcp4ParserTest, vendorOptionsCsv) {
ASSERT_TRUE
(
subnet
);
// Try to get the option from the vendor space 4491
Subnet
::
OptionDescriptor
desc1
=
subnet
->
getVendorOptionDescriptor
(
VENDOR_ID_CABLE_LABS
,
100
);
OptionDescriptor
desc1
=
subnet
->
getVendorOptionDescriptor
(
VENDOR_ID_CABLE_LABS
,
100
);
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.
Subnet
::
OptionDescriptor
desc2
=
subnet
->
getVendorOptionDescriptor
(
5678
,
100
);
OptionDescriptor
desc2
=
subnet
->
getVendorOptionDescriptor
(
5678
,
100
);
ASSERT_FALSE
(
desc2
.
option
);
}
...
...
src/bin/dhcp6/dhcp6_srv.cc
View file @
bbdef979
...
...
@@ -731,7 +731,7 @@ Dhcpv6Srv::appendRequestedOptions(const Pkt6Ptr& question, Pkt6Ptr& answer) {
// Get the list of options that client requested.
const
std
::
vector
<
uint16_t
>&
requested_opts
=
option_oro
->
getValues
();
BOOST_FOREACH
(
uint16_t
opt
,
requested_opts
)
{
Subnet
::
OptionDescriptor
desc
=
subnet
->
getOptionDescriptor
(
"dhcp6"
,
opt
);
OptionDescriptor
desc
=
subnet
->
getOptionDescriptor
(
"dhcp6"
,
opt
);
if
(
desc
.
option
)
{
answer
->
addOption
(
desc
.
option
);
}
...
...
@@ -777,7 +777,7 @@ Dhcpv6Srv::appendRequestedVendorOptions(const Pkt6Ptr& question, Pkt6Ptr& answer
bool
added
=
false
;
const
std
::
vector
<
uint16_t
>&
requested_opts
=
oro
->
getValues
();
BOOST_FOREACH
(
uint16_t
opt
,
requested_opts
)
{
Subnet
::
OptionDescriptor
desc
=
subnet
->
getVendorOptionDescriptor
(
vendor_id
,
opt
);
OptionDescriptor
desc
=
subnet
->
getVendorOptionDescriptor
(
vendor_id
,
opt
);
if
(
desc
.
option
)
{
vendor_rsp
->
addOption
(
desc
.
option
);
added
=
true
;
...
...
src/bin/dhcp6/tests/config_parser_unittest.cc
View file @
bbdef979
...
...
@@ -243,7 +243,7 @@ public:
/// @return Descriptor of the option. If the descriptor holds a
/// NULL option pointer, it means that there was no such option
/// in the subnet.
Subnet
::
OptionDescriptor
OptionDescriptor
getOptionFromSubnet
(
const
IOAddress
&
subnet_address
,
const
uint16_t
option_code
,
const
uint16_t
expected_options_count
=
1
)
{
...
...
@@ -255,7 +255,7 @@ public:
<<
subnet_address
.
toText
()
<<
"does not exist in Config Manager"
;
}
Subnet
::
OptionContainerPtr
options
=
OptionContainerPtr
options
=
subnet
->
getOptionDescriptors
(
"dhcp6"
);
if
(
expected_options_count
!=
options
->
size
())
{
ADD_FAILURE
()
<<
"The number of options in the subnet '"
...
...
@@ -265,13 +265,13 @@ public:
}
// Get the search index. Index #1 is to search using option code.
const
Subnet
::
OptionContainerTypeIndex
&
idx
=
options
->
get
<
1
>
();
const
OptionContainerTypeIndex
&
idx
=
options
->
get
<
1
>
();
// Get the options for specified index. Expecting one option to be
// returned but in theory we may have multiple options with the same
// code so we get the range.
std
::
pair
<
Subnet
::
OptionContainerTypeIndex
::
const_iterator
,
Subnet
::
OptionContainerTypeIndex
::
const_iterator
>
range
=
std
::
pair
<
OptionContainerTypeIndex
::
const_iterator
,
OptionContainerTypeIndex
::
const_iterator
>
range
=
idx
.
equal_range
(
option_code
);
if
(
std
::
distance
(
range
.
first
,
range
.
second
)
>
1
)
{
ADD_FAILURE
()
<<
"There is more than one option having the"
...
...
@@ -279,7 +279,7 @@ public:
<<
subnet_address
.
toText
()
<<
"'. Expected "
" at most one option"
;
}
else
if
(
std
::
distance
(
range
.
first
,
range
.
second
)
==
0
)
{
return
(
Subnet
::
OptionDescriptor
(
OptionPtr
(),
false
));
return
(
OptionDescriptor
(
OptionPtr
(),
false
));
}
return
(
*
range
.
first
);
...
...
@@ -413,7 +413,7 @@ public:
/// @param expected_data_len length of the reference data.
/// @param extra_data if true extra data is allowed in an option
/// after tested data.
void
testOption
(
const
Subnet
::
OptionDescriptor
&
option_desc
,
void
testOption
(
const
OptionDescriptor
&
option_desc
,
uint16_t
expected_code
,
const
uint8_t
*
expected_data
,
size_t
expected_data_len
,
bool
extra_data
=
false
)
{
...
...
@@ -473,7 +473,7 @@ public:
ASSERT_TRUE
(
executeConfiguration
(
config
,
"parse option configuration"
));
// The subnet should now hold one option with the specified code.
Subnet
::
OptionDescriptor
desc
=
OptionDescriptor
desc
=
getOptionFromSubnet
(
IOAddress
(
"2001:db8:1::5"
),
option_code
);
ASSERT_TRUE
(
desc
.
option
);
testOption
(
desc
,
option_code
,
expected_data
,
expected_data_len
);
...
...
@@ -2030,17 +2030,17 @@ TEST_F(Dhcp6ParserTest, optionDataDefaults) {
Subnet6Ptr
subnet
=
CfgMgr
::
instance
().
getSubnet6
(
IOAddress
(
"2001:db8:1::5"
),
classify_
);
ASSERT_TRUE
(
subnet
);
Subnet
::
OptionContainerPtr
options
=
subnet
->
getOptionDescriptors
(
"dhcp6"
);
OptionContainerPtr
options
=
subnet
->
getOptionDescriptors
(
"dhcp6"
);
ASSERT_EQ
(
2
,
options
->
size
());
// Get the search index. Index #1 is to search using option code.
const
Subnet
::
OptionContainerTypeIndex
&
idx
=
options
->
get
<
1
>
();
const
OptionContainerTypeIndex
&
idx
=
options
->
get
<
1
>
();
// Get the options for specified index. Expecting one option to be
// returned but in theory we may have multiple options with the same
// code so we get the range.
std
::
pair
<
Subnet
::
OptionContainerTypeIndex
::
const_iterator
,
Subnet
::
OptionContainerTypeIndex
::
const_iterator
>
range
=
std
::
pair
<
OptionContainerTypeIndex
::
const_iterator
,
OptionContainerTypeIndex
::
const_iterator
>
range
=
idx
.
equal_range
(
D6O_SUBSCRIBER_ID
);
// Expect single option with the code equal to 38.
ASSERT_EQ
(
1
,
std
::
distance
(
range
.
first
,
range
.
second
));
...
...
@@ -2126,16 +2126,16 @@ TEST_F(Dhcp6ParserTest, optionDataTwoSpaces) {
classify_
);
ASSERT_TRUE
(
subnet
);
// Try to get the option from the space dhcp6.
Subnet
::
OptionDescriptor
desc1
=
subnet
->
getOptionDescriptor
(
"dhcp6"
,
38
);
OptionDescriptor
desc1
=
subnet
->
getOptionDescriptor
(
"dhcp6"
,
38
);
ASSERT_TRUE
(
desc1
.
option
);
EXPECT_EQ
(
38
,
desc1
.
option
->
getType
());
// Try to get the option from the space isc.
Subnet
::
OptionDescriptor
desc2
=
subnet
->
getOptionDescriptor
(
"isc"
,
38
);
OptionDescriptor
desc2
=
subnet
->
getOptionDescriptor
(
"isc"
,
38
);
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.
Subnet
::
OptionDescriptor
desc3
=
subnet
->
getOptionDescriptor
(
"non-existing"
,
38
);
OptionDescriptor
desc3
=
subnet
->
getOptionDescriptor
(
"non-existing"
,
38
);
ASSERT_FALSE
(
desc3
.
option
);
}
...
...
@@ -2283,12 +2283,12 @@ TEST_F(Dhcp6ParserTest, optionDataEncapsulate) {
ASSERT_TRUE
(
subnet
);
// We should have one option available.
Subnet
::
OptionContainerPtr
options
=
subnet
->
getOptionDescriptors
(
"dhcp6"
);
OptionContainerPtr
options
=
subnet
->
getOptionDescriptors
(
"dhcp6"
);
ASSERT_TRUE
(
options
);
ASSERT_EQ
(
1
,
options
->
size
());
// Get the option.
Subnet
::
OptionDescriptor
desc
=
subnet
->
getOptionDescriptor
(
"dhcp6"
,
100
);
OptionDescriptor
desc
=
subnet
->
getOptionDescriptor
(
"dhcp6"
,
100
);
EXPECT_TRUE
(
desc
.
option
);
EXPECT_EQ
(
100
,
desc
.
option
->
getType
());
...
...
@@ -2344,17 +2344,17 @@ TEST_F(Dhcp6ParserTest, optionDataInMultipleSubnets) {
Subnet6Ptr
subnet1
=
CfgMgr
::
instance
().
getSubnet6
(
IOAddress
(
"2001:db8:1::5"
),
classify_
);
ASSERT_TRUE
(
subnet1
);
Subnet
::
OptionContainerPtr
options1
=
subnet1
->
getOptionDescriptors
(
"dhcp6"
);
OptionContainerPtr
options1
=
subnet1
->
getOptionDescriptors
(
"dhcp6"
);
ASSERT_EQ
(
1
,
options1
->
size
());
// Get the search index. Index #1 is to search using option code.
const
Subnet
::
OptionContainerTypeIndex
&
idx1
=
options1
->
get
<
1
>
();
const
OptionContainerTypeIndex
&
idx1
=
options1
->
get
<
1
>
();
// Get the options for specified index. Expecting one option to be
// returned but in theory we may have multiple options with the same
// code so we get the range.
std
::
pair
<
Subnet
::
OptionContainerTypeIndex
::
const_iterator
,
Subnet
::
OptionContainerTypeIndex
::
const_iterator
>
range1
=
std
::
pair
<
OptionContainerTypeIndex
::
const_iterator
,
OptionContainerTypeIndex
::
const_iterator
>
range1
=
idx1
.
equal_range
(
D6O_SUBSCRIBER_ID
);
// Expect single option with the code equal to 38.
ASSERT_EQ
(
1
,
std
::
distance
(
range1
.
first
,
range1
.
second
));
...
...
@@ -2370,12 +2370,12 @@ TEST_F(Dhcp6ParserTest, optionDataInMultipleSubnets) {
Subnet6Ptr
subnet2
=
CfgMgr
::
instance
().
getSubnet6
(
IOAddress
(
"2001:db8:2::4"
),
classify_
);
ASSERT_TRUE
(
subnet2
);
Subnet
::
OptionContainerPtr
options2
=
subnet2
->
getOptionDescriptors
(
"dhcp6"
);
OptionContainerPtr
options2
=
subnet2
->
getOptionDescriptors
(
"dhcp6"
);
ASSERT_EQ
(
1
,
options2
->
size
());
const
Subnet
::
OptionContainerTypeIndex
&
idx2
=
options2
->
get
<
1
>
();
std
::
pair
<
Subnet
::
OptionContainerTypeIndex
::
const_iterator
,
Subnet
::
OptionContainerTypeIndex
::
const_iterator
>
range2
=
const
OptionContainerTypeIndex
&
idx2
=
options2
->
get
<
1
>
();
std
::
pair
<
OptionContainerTypeIndex
::
const_iterator
,
OptionContainerTypeIndex
::
const_iterator
>
range2
=
idx2
.
equal_range
(
D6O_USER_CLASS
);
ASSERT_EQ
(
1
,
std
::
distance
(
range2
.
first
,
range2
.
second
));
...
...
@@ -2405,7 +2405,7 @@ TEST_F(Dhcp6ParserTest, optionDataBoolean) {
CfgMgr
::
instance
().
commit
();
// The subnet should now hold one option with the code 1000.
Subnet
::
OptionDescriptor
desc
=
OptionDescriptor
desc
=
getOptionFromSubnet
(
IOAddress
(
"2001:db8:1::5"
),
1000
);
ASSERT_TRUE
(
desc
.
option
);
...
...
@@ -2541,17 +2541,17 @@ TEST_F(Dhcp6ParserTest, optionDataLowerCase) {
Subnet6Ptr
subnet
=
CfgMgr
::
instance
().
getSubnet6
(
IOAddress
(
"2001:db8:1::5"
),
classify_
);
ASSERT_TRUE
(
subnet
);
Subnet
::
OptionContainerPtr
options
=
subnet
->
getOptionDescriptors
(
"dhcp6"
);
OptionContainerPtr
options
=
subnet
->
getOptionDescriptors
(
"dhcp6"
);
ASSERT_EQ
(
1
,
options
->
size
());
// Get the search index. Index #1 is to search using option code.
const
Subnet
::
OptionContainerTypeIndex
&
idx
=
options
->
get
<
1
>
();
const
OptionContainerTypeIndex
&
idx
=
options
->
get
<
1
>
();
// Get the options for specified index. Expecting one option to be
// returned but in theory we may have multiple options with the same
// code so we get the range.
std
::
pair
<
Subnet
::
OptionContainerTypeIndex
::
const_iterator
,
Subnet
::
OptionContainerTypeIndex
::
const_iterator
>
range
=
std
::
pair
<
OptionContainerTypeIndex
::
const_iterator
,
OptionContainerTypeIndex
::
const_iterator
>
range
=
idx
.
equal_range
(
D6O_SUBSCRIBER_ID
);
// Expect single option with the code equal to 38.
ASSERT_EQ
(
1
,
std
::
distance
(
range
.
first
,
range
.
second
));
...
...
@@ -2584,17 +2584,17 @@ TEST_F(Dhcp6ParserTest, stdOptionData) {
Subnet6Ptr
subnet
=
CfgMgr
::
instance
().
getSubnet6
(
IOAddress
(
"2001:db8:1::5"
),
classify_
);
ASSERT_TRUE
(
subnet
);
Subnet
::
OptionContainerPtr
options
=
subnet
->
getOptionDescriptors
(
"dhcp6"
);
OptionContainerPtr
options
=
subnet
->
getOptionDescriptors
(
"dhcp6"
);
ASSERT_EQ
(
1
,
options
->
size
());
// Get the search index. Index #1 is to search using option code.
const
Subnet
::
OptionContainerTypeIndex
&
idx
=
options
->
get
<
1
>
();
const
OptionContainerTypeIndex
&
idx
=
options
->
get
<
1
>
();
// Get the options for specified index. Expecting one option to be
// returned but in theory we may have multiple options with the same
// code so we get the range.
std
::
pair
<
Subnet
::
OptionContainerTypeIndex
::
const_iterator
,
Subnet
::
OptionContainerTypeIndex
::
const_iterator
>
range
=
std
::
pair
<
OptionContainerTypeIndex
::
const_iterator
,
OptionContainerTypeIndex
::
const_iterator
>
range
=
idx
.
equal_range
(
D6O_IA_NA
);
// Expect single option with the code equal to IA_NA option code.
ASSERT_EQ
(
1
,
std
::
distance
(
range
.
first
,
range
.
second
));
...
...
@@ -2664,17 +2664,17 @@ TEST_F(Dhcp6ParserTest, vendorOptionsHex) {
ASSERT_TRUE
(
subnet
);
// Try to get the option from the vendor space 4491
Subnet
::
OptionDescriptor
desc1
=
subnet
->
getVendorOptionDescriptor
(
4491
,
100
);
OptionDescriptor
desc1
=
subnet
->
getVendorOptionDescriptor
(
4491
,
100
);
ASSERT_TRUE
(
desc1
.
option
);
EXPECT_EQ
(
100
,
desc1
.
option
->
getType
());
// Try to get the option from the vendor space 1234
Subnet
::
OptionDescriptor
desc2
=
subnet
->
getVendorOptionDescriptor
(
1234
,
100
);
OptionDescriptor
desc2
=
subnet
->
getVendorOptionDescriptor
(
1234
,
100
);
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.
Subnet
::
OptionDescriptor
desc3
=
subnet
->
getVendorOptionDescriptor
(
5678
,
38
);
OptionDescriptor
desc3
=
subnet
->
getVendorOptionDescriptor
(
5678
,
38
);
ASSERT_FALSE
(
desc3
.
option
);
}
...
...
@@ -2726,13 +2726,13 @@ TEST_F(Dhcp6ParserTest, vendorOptionsCsv) {
ASSERT_TRUE
(
subnet
);
// Try to get the option from the vendor space 4491
Subnet
::
OptionDescriptor
desc1
=
subnet
->
getVendorOptionDescriptor
(
4491
,
100
);
OptionDescriptor
desc1
=
subnet
->
getVendorOptionDescriptor
(
4491
,
100
);
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.
Subnet
::
OptionDescriptor
desc2
=
subnet
->
getVendorOptionDescriptor
(
5678
,
100
);
OptionDescriptor
desc2
=
subnet
->
getVendorOptionDescriptor
(
5678
,
100
);
ASSERT_FALSE
(
desc2
.
option
);
}
...
...
@@ -2865,12 +2865,12 @@ TEST_F(Dhcp6ParserTest, stdOptionDataEncapsulate) {
ASSERT_TRUE
(
subnet
);
// We should have one option available.
Subnet
::
OptionContainerPtr
options
=
subnet
->
getOptionDescriptors
(
"dhcp6"
);
OptionContainerPtr
options
=
subnet
->
getOptionDescriptors
(
"dhcp6"
);
ASSERT_TRUE
(
options
);
ASSERT_EQ
(
1
,
options
->
size
());
// Get the option.
Subnet
::
OptionDescriptor
desc
=
OptionDescriptor
desc
=
subnet
->
getOptionDescriptor
(
"dhcp6"
,
D6O_VENDOR_OPTS
);
EXPECT_TRUE
(
desc
.
option
);
EXPECT_EQ
(
D6O_VENDOR_OPTS
,
desc
.
option
->
getType
());
...
...
src/lib/dhcpsrv/Makefile.am
View file @
bbdef979
...
...
@@ -46,6 +46,7 @@ libkea_dhcpsrv_la_SOURCES += addr_utilities.cc addr_utilities.h
libkea_dhcpsrv_la_SOURCES
+=
alloc_engine.cc alloc_engine.h
libkea_dhcpsrv_la_SOURCES
+=
callout_handle_store.h
libkea_dhcpsrv_la_SOURCES
+=
cfg_iface.cc cfg_iface.h
libkea_dhcpsrv_la_SOURCES
+=
cfg_option.cc cfg_option.h
libkea_dhcpsrv_la_SOURCES
+=
cfg_option_def.cc cfg_option_def.h
libkea_dhcpsrv_la_SOURCES
+=
cfgmgr.cc cfgmgr.h
libkea_dhcpsrv_la_SOURCES
+=
csv_lease_file4.cc csv_lease_file4.h
...
...
src/lib/dhcpsrv/cfg_option.cc
0 → 100644
View file @
bbdef979
// Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.