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
ISC Open Source Projects
Kea
Commits
bc730569
Commit
bc730569
authored
Jan 05, 2017
by
Tomek Mrugalski
🛰
Browse files
[5032] Duplicate mac-sources are no longer accepted.
parent
4cf4bc1a
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/lib/dhcpsrv/cfg_mac_source.cc
View file @
bc730569
// Copyright (C) 2014-2015 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2014-2015
,2017
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
...
...
@@ -47,6 +47,16 @@ uint32_t CfgMACSource::MACSourceFromText(const std::string& name) {
isc_throw
(
BadValue
,
"Can't convert '"
<<
name
<<
"' to any known MAC source."
);
}
void
CfgMACSource
::
add
(
uint32_t
source
)
{
for
(
CfgMACSources
::
const_iterator
it
=
mac_sources_
.
begin
();
it
!=
mac_sources_
.
end
();
++
it
)
{
if
(
*
it
==
source
)
{
isc_throw
(
InvalidParameter
,
"mac-source paramter "
<<
source
<<
"' specified twice."
);
}
}
mac_sources_
.
push_back
(
source
);
}
};
};
src/lib/dhcpsrv/cfg_mac_source.h
View file @
bc730569
// Copyright (C) 2014-2015 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2014-2015
,2017
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
...
...
@@ -52,10 +52,8 @@ class CfgMACSource {
/// @param source MAC source (see constants in Pkt::HWADDR_SOURCE_*)
///
/// Specified source is being added to the mac_sources_ array.
/// @todo implement add(string) version of this method.
void
add
(
uint32_t
source
)
{
mac_sources_
.
push_back
(
source
);
}
/// @throw InvalidParameter if such a source is already defined.
void
add
(
uint32_t
source
);
/// @brief Provides access to the configure MAC/Hardware address sources.
///
...
...
src/lib/dhcpsrv/parsers/dhcp_parsers.cc
View file @
bc730569
...
...
@@ -193,6 +193,9 @@ MACSourcesListConfigParser::parse(CfgMACSource& mac_sources, ConstElementPtr val
source
=
CfgMACSource
::
MACSourceFromText
(
source_str
);
mac_sources
.
add
(
source
);
++
cnt
;
}
catch
(
const
InvalidParameter
&
ex
)
{
isc_throw
(
DhcpConfigError
,
"The mac-sources value '"
<<
source_str
<<
"' was specified twice ("
<<
value
->
getPosition
()
<<
")"
);
}
catch
(
const
std
::
exception
&
ex
)
{
isc_throw
(
DhcpConfigError
,
"Failed to convert '"
<<
source_str
<<
"' to any recognized MAC source:"
...
...
src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc
View file @
bc730569
...
...
@@ -292,6 +292,29 @@ TEST_F(DhcpParserTest, MacSourcesBogus) {
EXPECT_THROW
(
parser
.
parse
(
sources
,
values
),
DhcpConfigError
);
}
/// Verifies the code that properly catches duplicate entries
/// in mac-sources definition.
TEST_F
(
DhcpParserTest
,
MacSourcesDuplicate
)
{
// That's an equivalent of the following snippet:
// "mac-sources: [ \"duid\", \"ipv6\" ]";
ElementPtr
values
=
Element
::
createList
();
values
->
add
(
Element
::
create
(
"ipv6-link-local"
));
values
->
add
(
Element
::
create
(
"duid"
));
values
->
add
(
Element
::
create
(
"duid"
));
values
->
add
(
Element
::
create
(
"duid"
));
// Let's grab server configuration from CfgMgr
SrvConfigPtr
cfg
=
CfgMgr
::
instance
().
getStagingCfg
();
ASSERT_TRUE
(
cfg
);
CfgMACSource
&
sources
=
cfg
->
getMACSources
();
// This should parse the configuration and check that it throws.
MACSourcesListConfigParser
parser
;
EXPECT_THROW
(
parser
.
parse
(
sources
,
values
),
DhcpConfigError
);
}
/// @brief Test Fixture class which provides basic structure for testing
/// configuration parsing. This is essentially the same structure provided
/// by dhcp servers.
...
...
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