Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
ISC Open Source Projects
Kea
Commits
cf8d1122
Commit
cf8d1122
authored
Mar 04, 2017
by
Francis Dupont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[5145b] Rebased keeping host_parser in hooks
parent
99705e8b
Changes
16
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
368 additions
and
205 deletions
+368
-205
src/bin/agent/ca_cfg_mgr.cc
src/bin/agent/ca_cfg_mgr.cc
+2
-2
src/bin/agent/ca_cfg_mgr.h
src/bin/agent/ca_cfg_mgr.h
+14
-14
src/bin/agent/simple_parser.cc
src/bin/agent/simple_parser.cc
+7
-8
src/bin/agent/tests/ca_cfg_mgr_unittests.cc
src/bin/agent/tests/ca_cfg_mgr_unittests.cc
+14
-16
src/bin/dhcp4/json_config_parser.cc
src/bin/dhcp4/json_config_parser.cc
+8
-8
src/bin/dhcp6/json_config_parser.cc
src/bin/dhcp6/json_config_parser.cc
+8
-8
src/lib/Makefile.am
src/lib/Makefile.am
+1
-1
src/lib/dhcpsrv/srv_config.cc
src/lib/dhcpsrv/srv_config.cc
+51
-5
src/lib/dhcpsrv/srv_config.h
src/lib/dhcpsrv/srv_config.h
+18
-0
src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc
src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc
+20
-27
src/lib/dhcpsrv/tests/srv_config_unittest.cc
src/lib/dhcpsrv/tests/srv_config_unittest.cc
+25
-0
src/lib/hooks/Makefile.am
src/lib/hooks/Makefile.am
+1
-0
src/lib/hooks/hooks_config.cc
src/lib/hooks/hooks_config.cc
+87
-0
src/lib/hooks/hooks_config.h
src/lib/hooks/hooks_config.h
+103
-0
src/lib/hooks/hooks_parser.cc
src/lib/hooks/hooks_parser.cc
+5
-55
src/lib/hooks/hooks_parser.h
src/lib/hooks/hooks_parser.h
+4
-61
No files found.
src/bin/agent/ca_cfg_mgr.cc
View file @
cf8d1122
...
@@ -24,7 +24,7 @@ CtrlAgentCfgContext::CtrlAgentCfgContext()
...
@@ -24,7 +24,7 @@ CtrlAgentCfgContext::CtrlAgentCfgContext()
CtrlAgentCfgContext
::
CtrlAgentCfgContext
(
const
CtrlAgentCfgContext
&
orig
)
CtrlAgentCfgContext
::
CtrlAgentCfgContext
(
const
CtrlAgentCfgContext
&
orig
)
:
DCfgContextBase
(),
http_host_
(
orig
.
http_host_
),
http_port_
(
orig
.
http_port_
),
:
DCfgContextBase
(),
http_host_
(
orig
.
http_host_
),
http_port_
(
orig
.
http_port_
),
libraries_
(
orig
.
libraries
_
)
{
hooks_config_
(
orig
.
hooks_config
_
)
{
// We're copying pointers here only. The underlying data will be shared by
// We're copying pointers here only. The underlying data will be shared by
// old and new context. That's how shared pointers work and I see no reason
// old and new context. That's how shared pointers work and I see no reason
...
@@ -74,7 +74,7 @@ CtrlAgentCfgMgr::getConfigSummary(const uint32_t /*selection*/) {
...
@@ -74,7 +74,7 @@ CtrlAgentCfgMgr::getConfigSummary(const uint32_t /*selection*/) {
}
}
// Finally, print the hook libraries names
// Finally, print the hook libraries names
const
hooks
::
HookLibsCollection
libs
=
ctx
->
get
Libraries
();
const
isc
::
hooks
::
HookLibsCollection
libs
=
ctx
->
get
HooksConfig
().
get
();
s
<<
", "
<<
libs
.
size
()
<<
" lib(s):"
;
s
<<
", "
<<
libs
.
size
()
<<
" lib(s):"
;
for
(
auto
lib
=
libs
.
begin
();
lib
!=
libs
.
end
();
++
lib
)
{
for
(
auto
lib
=
libs
.
begin
();
lib
!=
libs
.
end
();
++
lib
)
{
s
<<
lib
->
first
<<
" "
;
s
<<
lib
->
first
<<
" "
;
...
...
src/bin/agent/ca_cfg_mgr.h
View file @
cf8d1122
...
@@ -8,9 +8,9 @@
...
@@ -8,9 +8,9 @@
#define CTRL_AGENT_CFG_MGR_H
#define CTRL_AGENT_CFG_MGR_H
#include <cc/data.h>
#include <cc/data.h>
#include <hooks/hooks_config.h>
#include <process/d_cfg_mgr.h>
#include <process/d_cfg_mgr.h>
#include <boost/pointer_cast.hpp>
#include <boost/pointer_cast.hpp>
#include <hooks/libinfo.h>
namespace
isc
{
namespace
isc
{
namespace
agent
{
namespace
agent
{
...
@@ -61,7 +61,7 @@ public:
...
@@ -61,7 +61,7 @@ public:
///
///
/// @param type type of the server being controlled
/// @param type type of the server being controlled
/// @return pointer to the Element that holds control-socket map (or NULL)
/// @return pointer to the Element that holds control-socket map (or NULL)
const
data
::
ConstElementPtr
getControlSocketInfo
(
ServerType
type
)
const
;
const
isc
::
data
::
ConstElementPtr
getControlSocketInfo
(
ServerType
type
)
const
;
/// @brief Sets information about the control socket
/// @brief Sets information about the control socket
///
///
...
@@ -102,20 +102,20 @@ public:
...
@@ -102,20 +102,20 @@ public:
return
(
http_port_
);
return
(
http_port_
);
}
}
/// @brief Returns a list of hook libraries
/// @brief Returns non-const reference to configured hooks libraries.
/// @return a list of hook libraries
///
const
hooks
::
HookLibsCollection
&
getLibraries
()
const
{
/// @return non-const reference to configured hooks libraries.
return
(
libraries_
);
isc
::
hooks
::
HooksConfig
&
getHooksConfig
()
{
return
(
hooks_config_
);
}
}
/// @brief
S
et
s the list of
hook libraries
/// @brief
R
et
urns const reference to configured
hook
s
libraries
.
///
///
/// @
params libs a coolection of libraries to remember
.
/// @
return const reference to configured hooks libraries
.
void
setLibraries
(
const
hooks
::
HookLibsCollection
&
libs
)
{
const
isc
::
hooks
::
HooksConfig
&
getHooksConfig
()
const
{
libraries_
=
libs
;
return
(
hooks_config_
)
;
}
}
private:
private:
/// @brief Private copy constructor
/// @brief Private copy constructor
...
@@ -132,7 +132,7 @@ private:
...
@@ -132,7 +132,7 @@ private:
CtrlAgentCfgContext
&
operator
=
(
const
CtrlAgentCfgContext
&
rhs
);
CtrlAgentCfgContext
&
operator
=
(
const
CtrlAgentCfgContext
&
rhs
);
/// Socket information will be stored here (for all supported servers)
/// Socket information will be stored here (for all supported servers)
data
::
ConstElementPtr
ctrl_sockets_
[
MAX_TYPE_SUPPORTED
+
1
];
isc
::
data
::
ConstElementPtr
ctrl_sockets_
[
MAX_TYPE_SUPPORTED
+
1
];
/// Hostname the CA should listen on.
/// Hostname the CA should listen on.
std
::
string
http_host_
;
std
::
string
http_host_
;
...
@@ -140,8 +140,8 @@ private:
...
@@ -140,8 +140,8 @@ private:
/// TCP port the CA should listen on.
/// TCP port the CA should listen on.
uint16_t
http_port_
;
uint16_t
http_port_
;
///
List of
hook libraries.
///
@brief Configured
hook
s
libraries.
hooks
::
Hook
LibsCollection
libraries
_
;
isc
::
hooks
::
Hook
sConfig
hooks_config
_
;
};
};
/// @brief Ctrl Agent Configuration Manager.
/// @brief Ctrl Agent Configuration Manager.
...
...
src/bin/agent/simple_parser.cc
View file @
cf8d1122
...
@@ -107,22 +107,21 @@ AgentSimpleParser::parse(const CtrlAgentCfgContextPtr& ctx,
...
@@ -107,22 +107,21 @@ AgentSimpleParser::parse(const CtrlAgentCfgContextPtr& ctx,
}
}
// Finally, let's get the hook libs!
// Finally, let's get the hook libs!
hooks
::
HooksLibrariesParser
hooks_parser
;
using
namespace
isc
::
hooks
;
HooksConfig
&
libraries
=
ctx
->
getHooksConfig
();
ConstElementPtr
hooks
=
config
->
get
(
"hooks-libraries"
);
ConstElementPtr
hooks
=
config
->
get
(
"hooks-libraries"
);
if
(
hooks
)
{
if
(
hooks
)
{
hooks_parser
.
parse
(
hooks
);
HooksLibrariesParser
hooks_parser
;
hooks_parser
.
verifyLibraries
();
hooks_parser
.
parse
(
libraries
,
hooks
);
libraries
.
verifyLibraries
(
hooks
->
getPosition
());
hooks
::
HookLibsCollection
libs
;
hooks_parser
.
getLibraries
(
libs
);
ctx
->
setLibraries
(
libs
);
}
}
if
(
!
check_only
)
{
if
(
!
check_only
)
{
// This occurs last as if it succeeds, there is no easy way
// This occurs last as if it succeeds, there is no easy way
// revert it. As a result, the failure to commit a subsequent
// revert it. As a result, the failure to commit a subsequent
// change causes problems when trying to roll back.
// change causes problems when trying to roll back.
hooks_parser
.
loadLibraries
();
libraries
.
loadLibraries
();
}
}
}
}
...
...
src/bin/agent/tests/ca_cfg_mgr_unittests.cc
View file @
cf8d1122
...
@@ -10,12 +10,12 @@
...
@@ -10,12 +10,12 @@
#include <process/testutils/d_test_stubs.h>
#include <process/testutils/d_test_stubs.h>
#include <process/d_cfg_mgr.h>
#include <process/d_cfg_mgr.h>
#include <agent/tests/test_libraries.h>
#include <agent/tests/test_libraries.h>
#include <hooks/libinfo.h>
#include <boost/scoped_ptr.hpp>
#include <boost/scoped_ptr.hpp>
#include <gtest/gtest.h>
#include <gtest/gtest.h>
using
namespace
isc
::
agent
;
using
namespace
isc
::
agent
;
using
namespace
isc
::
data
;
using
namespace
isc
::
data
;
using
namespace
isc
::
dhcp
;
using
namespace
isc
::
hooks
;
using
namespace
isc
::
hooks
;
using
namespace
isc
::
process
;
using
namespace
isc
::
process
;
...
@@ -123,11 +123,10 @@ TEST(CtrlAgentCfgMgr, contextSocketInfoCopy) {
...
@@ -123,11 +123,10 @@ TEST(CtrlAgentCfgMgr, contextSocketInfoCopy) {
EXPECT_NO_THROW
(
ctx
.
setHttpPort
(
12345
));
EXPECT_NO_THROW
(
ctx
.
setHttpPort
(
12345
));
EXPECT_NO_THROW
(
ctx
.
setHttpHost
(
"bellatrix"
));
EXPECT_NO_THROW
(
ctx
.
setHttpHost
(
"bellatrix"
));
Hook
LibsCollection
libs
;
Hook
sConfig
&
libs
=
ctx
.
getHooksConfig
()
;
string
exp_name
(
"testlib1.so"
);
string
exp_name
(
"testlib1.so"
);
ConstElementPtr
exp_param
(
new
StringElement
(
"myparam"
));
ConstElementPtr
exp_param
(
new
StringElement
(
"myparam"
));
libs
.
push_back
(
make_pair
(
exp_name
,
exp_param
));
libs
.
add
(
exp_name
,
exp_param
);
ctx
.
setLibraries
(
libs
);
// Make a copy.
// Make a copy.
DCfgContextBasePtr
copy_base
(
ctx
.
clone
());
DCfgContextBasePtr
copy_base
(
ctx
.
clone
());
...
@@ -147,7 +146,7 @@ TEST(CtrlAgentCfgMgr, contextSocketInfoCopy) {
...
@@ -147,7 +146,7 @@ TEST(CtrlAgentCfgMgr, contextSocketInfoCopy) {
EXPECT_EQ
(
socket3
->
str
(),
copy
->
getControlSocketInfo
(
CtrlAgentCfgContext
::
TYPE_DHCP6
)
->
str
());
EXPECT_EQ
(
socket3
->
str
(),
copy
->
getControlSocketInfo
(
CtrlAgentCfgContext
::
TYPE_DHCP6
)
->
str
());
// Check hook libs
// Check hook libs
HookLibsCollection
libs2
=
copy
->
get
Libraries
();
const
HookLibsCollection
&
libs2
=
copy
->
get
HooksConfig
().
get
();
ASSERT_EQ
(
1
,
libs2
.
size
());
ASSERT_EQ
(
1
,
libs2
.
size
());
EXPECT_EQ
(
exp_name
,
libs2
[
0
].
first
);
EXPECT_EQ
(
exp_name
,
libs2
[
0
].
first
);
ASSERT_TRUE
(
libs2
[
0
].
second
);
ASSERT_TRUE
(
libs2
[
0
].
second
);
...
@@ -160,19 +159,18 @@ TEST(CtrlAgentCfgMgr, contextHookParams) {
...
@@ -160,19 +159,18 @@ TEST(CtrlAgentCfgMgr, contextHookParams) {
CtrlAgentCfgContext
ctx
;
CtrlAgentCfgContext
ctx
;
// By default there should be no hooks.
// By default there should be no hooks.
Hook
LibsCollection
libs
=
ctx
.
get
Libraries
();
Hook
sConfig
&
libs
=
ctx
.
get
HooksConfig
();
EXPECT_TRUE
(
libs
.
empty
());
EXPECT_TRUE
(
libs
.
get
().
empty
());
libs
.
push_back
(
std
::
make_pair
(
"libone.so"
,
ConstElementPtr
())
)
;
libs
.
add
(
"libone.so"
,
ConstElementPtr
());
libs
.
push_back
(
std
::
make_pair
(
"libtwo.so"
,
Element
::
fromJSON
(
"{
\"
foo
\"
: true}"
))
)
;
libs
.
add
(
"libtwo.so"
,
Element
::
fromJSON
(
"{
\"
foo
\"
: true}"
));
libs
.
push_back
(
std
::
make_pair
(
"libthree.so"
,
Element
::
fromJSON
(
"{
\"
bar
\"
: 42}"
))
)
;
libs
.
add
(
"libthree.so"
,
Element
::
fromJSON
(
"{
\"
bar
\"
: 42}"
));
ctx
.
setLibraries
(
libs
);
const
HooksConfig
&
stored_libs
=
ctx
.
getHooksConfig
();
EXPECT_EQ
(
3
,
stored_libs
.
get
().
size
());
HookLibsCollection
stored_libs
=
ctx
.
getLibraries
();
// @todo add a == operator to HooksConfig
EXPECT_EQ
(
3
,
stored_libs
.
size
());
EXPECT_EQ
(
libs
.
get
(),
stored_libs
.
get
());
EXPECT_EQ
(
libs
,
stored_libs
);
}
}
/// Control Agent configurations used in tests.
/// Control Agent configurations used in tests.
...
@@ -389,7 +387,7 @@ TEST_F(AgentParserTest, configParseHooks) {
...
@@ -389,7 +387,7 @@ TEST_F(AgentParserTest, configParseHooks) {
// The context now should have the library specified.
// The context now should have the library specified.
CtrlAgentCfgContextPtr
ctx
=
cfg_mgr_
.
getCtrlAgentCfgContext
();
CtrlAgentCfgContextPtr
ctx
=
cfg_mgr_
.
getCtrlAgentCfgContext
();
HookLibsCollection
libs
=
ctx
->
get
Libraries
();
const
HookLibsCollection
libs
=
ctx
->
get
HooksConfig
().
get
();
ASSERT_EQ
(
1
,
libs
.
size
());
ASSERT_EQ
(
1
,
libs
.
size
());
EXPECT_EQ
(
string
(
BASIC_CALLOUT_LIBRARY
),
libs
[
0
].
first
);
EXPECT_EQ
(
string
(
BASIC_CALLOUT_LIBRARY
),
libs
[
0
].
first
);
ASSERT_TRUE
(
libs
[
0
].
second
);
ASSERT_TRUE
(
libs
[
0
].
second
);
...
...
src/bin/dhcp4/json_config_parser.cc
View file @
cf8d1122
...
@@ -42,6 +42,7 @@ using namespace isc;
...
@@ -42,6 +42,7 @@ using namespace isc;
using
namespace
isc
::
dhcp
;
using
namespace
isc
::
dhcp
;
using
namespace
isc
::
data
;
using
namespace
isc
::
data
;
using
namespace
isc
::
asiolink
;
using
namespace
isc
::
asiolink
;
using
namespace
isc
::
hooks
;
namespace
{
namespace
{
...
@@ -431,11 +432,6 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set,
...
@@ -431,11 +432,6 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set,
// for option definitions. This is equivalent to commiting empty container.
// for option definitions. This is equivalent to commiting empty container.
LibDHCP
::
setRuntimeOptionDefs
(
OptionDefSpaceContainer
());
LibDHCP
::
setRuntimeOptionDefs
(
OptionDefSpaceContainer
());
// Some of the parsers alter the state of the system in a way that can't
// easily be undone. (Or alter it in a way such that undoing the change has
// the same risk of failure as doing the change.)
hooks
::
HooksLibrariesParser
hooks_parser
;
// Answer will hold the result.
// Answer will hold the result.
ConstElementPtr
answer
;
ConstElementPtr
answer
;
// Rollback informs whether error occurred and original data
// Rollback informs whether error occurred and original data
...
@@ -515,8 +511,10 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set,
...
@@ -515,8 +511,10 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set,
}
}
if
(
config_pair
.
first
==
"hooks-libraries"
)
{
if
(
config_pair
.
first
==
"hooks-libraries"
)
{
hooks_parser
.
parse
(
config_pair
.
second
);
HooksLibrariesParser
hooks_parser
;
hooks_parser
.
verifyLibraries
();
HooksConfig
&
libraries
=
srv_cfg
->
getHooksConfig
();
hooks_parser
.
parse
(
libraries
,
config_pair
.
second
);
libraries
.
verifyLibraries
(
config_pair
.
second
->
getPosition
());
continue
;
continue
;
}
}
...
@@ -637,7 +635,9 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set,
...
@@ -637,7 +635,9 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set,
// This occurs last as if it succeeds, there is no easy way
// This occurs last as if it succeeds, there is no easy way
// revert it. As a result, the failure to commit a subsequent
// revert it. As a result, the failure to commit a subsequent
// change causes problems when trying to roll back.
// change causes problems when trying to roll back.
hooks_parser
.
loadLibraries
();
const
HooksConfig
&
libraries
=
CfgMgr
::
instance
().
getStagingCfg
()
->
getHooksConfig
();
libraries
.
loadLibraries
();
}
}
catch
(
const
isc
::
Exception
&
ex
)
{
catch
(
const
isc
::
Exception
&
ex
)
{
LOG_ERROR
(
dhcp4_logger
,
DHCP4_PARSER_COMMIT_FAIL
).
arg
(
ex
.
what
());
LOG_ERROR
(
dhcp4_logger
,
DHCP4_PARSER_COMMIT_FAIL
).
arg
(
ex
.
what
());
...
...
src/bin/dhcp6/json_config_parser.cc
View file @
cf8d1122
...
@@ -54,6 +54,7 @@ using namespace isc;
...
@@ -54,6 +54,7 @@ using namespace isc;
using
namespace
isc
::
data
;
using
namespace
isc
::
data
;
using
namespace
isc
::
dhcp
;
using
namespace
isc
::
dhcp
;
using
namespace
isc
::
asiolink
;
using
namespace
isc
::
asiolink
;
using
namespace
isc
::
hooks
;
namespace
{
namespace
{
...
@@ -638,11 +639,6 @@ configureDhcp6Server(Dhcpv6Srv&, isc::data::ConstElementPtr config_set,
...
@@ -638,11 +639,6 @@ configureDhcp6Server(Dhcpv6Srv&, isc::data::ConstElementPtr config_set,
// for option definitions. This is equivalent to commiting empty container.
// for option definitions. This is equivalent to commiting empty container.
LibDHCP
::
setRuntimeOptionDefs
(
OptionDefSpaceContainer
());
LibDHCP
::
setRuntimeOptionDefs
(
OptionDefSpaceContainer
());
// Some of the parsers alter state of the system that can't easily
// be undone. (Or alter it in a way such that undoing the change
// has the same risk of failure as doing the change.)
hooks
::
HooksLibrariesParser
hooks_parser
;
// This is a way to convert ConstElementPtr to ElementPtr.
// This is a way to convert ConstElementPtr to ElementPtr.
// We need a config that can be edited, because we will insert
// We need a config that can be edited, because we will insert
// default values and will insert derived values as well.
// default values and will insert derived values as well.
...
@@ -738,8 +734,10 @@ configureDhcp6Server(Dhcpv6Srv&, isc::data::ConstElementPtr config_set,
...
@@ -738,8 +734,10 @@ configureDhcp6Server(Dhcpv6Srv&, isc::data::ConstElementPtr config_set,
}
}
if
(
config_pair
.
first
==
"hooks-libraries"
)
{
if
(
config_pair
.
first
==
"hooks-libraries"
)
{
hooks_parser
.
parse
(
config_pair
.
second
);
HooksLibrariesParser
hooks_parser
;
hooks_parser
.
verifyLibraries
();
HooksConfig
&
libraries
=
srv_config
->
getHooksConfig
();
hooks_parser
.
parse
(
libraries
,
config_pair
.
second
);
libraries
.
verifyLibraries
(
config_pair
.
second
->
getPosition
());
continue
;
continue
;
}
}
...
@@ -860,7 +858,9 @@ configureDhcp6Server(Dhcpv6Srv&, isc::data::ConstElementPtr config_set,
...
@@ -860,7 +858,9 @@ configureDhcp6Server(Dhcpv6Srv&, isc::data::ConstElementPtr config_set,
// This occurs last as if it succeeds, there is no easy way to
// This occurs last as if it succeeds, there is no easy way to
// revert it. As a result, the failure to commit a subsequent
// revert it. As a result, the failure to commit a subsequent
// change causes problems when trying to roll back.
// change causes problems when trying to roll back.
hooks_parser
.
loadLibraries
();
const
HooksConfig
&
libraries
=
CfgMgr
::
instance
().
getStagingCfg
()
->
getHooksConfig
();
libraries
.
loadLibraries
();
}
}
catch
(
const
isc
::
Exception
&
ex
)
{
catch
(
const
isc
::
Exception
&
ex
)
{
LOG_ERROR
(
dhcp6_logger
,
DHCP6_PARSER_COMMIT_FAIL
).
arg
(
ex
.
what
());
LOG_ERROR
(
dhcp6_logger
,
DHCP6_PARSER_COMMIT_FAIL
).
arg
(
ex
.
what
());
...
...
src/lib/Makefile.am
View file @
cf8d1122
# The following build order must be maintained.
# The following build order must be maintained.
SUBDIRS
=
exceptions util log cryptolink dns cc
hooks
asiolink testutils dhcp config
\
SUBDIRS
=
exceptions util log cryptolink dns cc asiolink testutils
hooks
dhcp config
\
stats asiodns dhcp_ddns
eval
dhcpsrv cfgrpt process http
stats asiodns dhcp_ddns
eval
dhcpsrv cfgrpt process http
src/lib/dhcpsrv/srv_config.cc
View file @
cf8d1122
...
@@ -110,6 +110,14 @@ SrvConfig::copy(SrvConfig& new_config) const {
...
@@ -110,6 +110,14 @@ SrvConfig::copy(SrvConfig& new_config) const {
new_config
.
class_dictionary_
.
reset
(
new
ClientClassDictionary
(
*
class_dictionary_
));
new_config
.
class_dictionary_
.
reset
(
new
ClientClassDictionary
(
*
class_dictionary_
));
// Replace the D2 client configuration
// Replace the D2 client configuration
new_config
.
setD2ClientConfig
(
getD2ClientConfig
());
new_config
.
setD2ClientConfig
(
getD2ClientConfig
());
// Replace configured hooks libraries.
new_config
.
hooks_config_
.
clear
();
using
namespace
isc
::
hooks
;
for
(
HookLibsCollection
::
const_iterator
it
=
hooks_config_
.
get
().
begin
();
it
!=
hooks_config_
.
get
().
end
();
++
it
)
{
new_config
.
hooks_config_
.
add
(
it
->
first
,
it
->
second
);
}
}
}
void
void
...
@@ -151,11 +159,49 @@ SrvConfig::equals(const SrvConfig& other) const {
...
@@ -151,11 +159,49 @@ SrvConfig::equals(const SrvConfig& other) const {
}
}
}
}
// Logging information is equal between objects, so check other values.
// Logging information is equal between objects, so check other values.
return
((
*
cfg_iface_
==
*
other
.
cfg_iface_
)
&&
if
((
*
cfg_iface_
!=
*
other
.
cfg_iface_
)
||
(
*
cfg_option_def_
==
*
other
.
cfg_option_def_
)
&&
(
*
cfg_option_def_
!=
*
other
.
cfg_option_def_
)
||
(
*
cfg_option_
==
*
other
.
cfg_option_
)
&&
(
*
cfg_option_
!=
*
other
.
cfg_option_
)
||
(
*
class_dictionary_
==
*
other
.
class_dictionary_
)
&&
(
*
class_dictionary_
!=
*
other
.
class_dictionary_
)
||
(
*
d2_client_config_
==
*
other
.
d2_client_config_
));
(
*
d2_client_config_
!=
*
other
.
d2_client_config_
))
{
return
(
false
);
}
// Now only configured hooks libraries can differ.
// If number of configured hooks libraries are different, then
// configurations aren't equal.
if
(
hooks_config_
.
get
().
size
()
!=
other
.
hooks_config_
.
get
().
size
())
{
return
(
false
);
}
// Pass through all configured hooks libraries.
using
namespace
isc
::
hooks
;
for
(
isc
::
hooks
::
HookLibsCollection
::
const_iterator
this_it
=
hooks_config_
.
get
().
begin
();
this_it
!=
hooks_config_
.
get
().
end
();
++
this_it
)
{
bool
match
=
false
;
for
(
isc
::
hooks
::
HookLibsCollection
::
const_iterator
other_it
=
other
.
hooks_config_
.
get
().
begin
();
other_it
!=
other
.
hooks_config_
.
get
().
end
();
++
other_it
)
{
if
(
this_it
->
first
!=
other_it
->
first
)
{
continue
;
}
if
(
isNull
(
this_it
->
second
)
&&
isNull
(
other_it
->
second
))
{
match
=
true
;
break
;
}
if
(
isNull
(
this_it
->
second
)
||
isNull
(
other_it
->
second
))
{
continue
;
}
if
(
this_it
->
second
->
equals
(
*
other_it
->
second
))
{
match
=
true
;
break
;
}
}
// No match found for the particular hooks library so return false.
if
(
!
match
)
{
return
(
false
);
}
}
return
(
true
);
}
}
void
void
...
...
src/lib/dhcpsrv/srv_config.h
View file @
cf8d1122
...
@@ -22,6 +22,7 @@
...
@@ -22,6 +22,7 @@
#include <dhcpsrv/client_class_def.h>
#include <dhcpsrv/client_class_def.h>
#include <dhcpsrv/d2_client_cfg.h>
#include <dhcpsrv/d2_client_cfg.h>
#include <dhcpsrv/logging_info.h>
#include <dhcpsrv/logging_info.h>
#include <hooks/hooks_config.h>
#include <cc/data.h>
#include <cc/data.h>
#include <boost/shared_ptr.hpp>
#include <boost/shared_ptr.hpp>
#include <vector>
#include <vector>
...
@@ -365,6 +366,20 @@ public:
...
@@ -365,6 +366,20 @@ public:
class_dictionary_
=
dictionary
;
class_dictionary_
=
dictionary
;
}
}
/// @brief Returns non-const reference to configured hooks libraries.
///
/// @return non-const reference to configured hooks libraries.
isc
::
hooks
::
HooksConfig
&
getHooksConfig
()
{
return
(
hooks_config_
);
}
/// @brief Returns const reference to configured hooks libraries.
///
/// @return const reference to configured hooks libraries.
const
isc
::
hooks
::
HooksConfig
&
getHooksConfig
()
const
{
return
(
hooks_config_
);
}
/// @brief Copies the current configuration to a new configuration.
/// @brief Copies the current configuration to a new configuration.
///
///
/// This method copies the parameters stored in the configuration to
/// This method copies the parameters stored in the configuration to
...
@@ -593,6 +608,9 @@ private:
...
@@ -593,6 +608,9 @@ private:
/// @brief Pointer to the dictionary of global client class definitions
/// @brief Pointer to the dictionary of global client class definitions
ClientClassDictionaryPtr
class_dictionary_
;
ClientClassDictionaryPtr
class_dictionary_
;
/// @brief Configured hooks libraries.
isc
::
hooks
::
HooksConfig
hooks_config_
;
/// @brief Decline Period time
/// @brief Decline Period time
///
///
/// This timer specifies decline probation period, the time after a declined
/// This timer specifies decline probation period, the time after a declined
...
...
src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc
View file @
cf8d1122
...
@@ -18,10 +18,10 @@
...
@@ -18,10 +18,10 @@
#include <dhcpsrv/subnet.h>
#include <dhcpsrv/subnet.h>
#include <dhcpsrv/cfg_mac_source.h>
#include <dhcpsrv/cfg_mac_source.h>
#include <dhcpsrv/parsers/dhcp_parsers.h>
#include <dhcpsrv/parsers/dhcp_parsers.h>
#include <hooks/hooks_parser.h>
#include <dhcpsrv/tests/test_libraries.h>
#include <dhcpsrv/tests/test_libraries.h>
#include <dhcpsrv/testutils/config_result_check.h>
#include <dhcpsrv/testutils/config_result_check.h>
#include <exceptions/exceptions.h>
#include <exceptions/exceptions.h>
#include <hooks/hooks_parser.h>
#include <hooks/hooks_manager.h>
#include <hooks/hooks_manager.h>
#include <gtest/gtest.h>
#include <gtest/gtest.h>
...
@@ -377,10 +377,12 @@ public:
...
@@ -377,10 +377,12 @@ public:
}
}
if
(
config_pair
.
first
==
"hooks-libraries"
)
{
if
(
config_pair
.
first
==
"hooks-libraries"
)
{
hooks_libraries_parser_
.
reset
(
new
HooksLibrariesParser
());
HooksLibrariesParser
hook_parser
;
hooks_libraries_parser_
->
parse
(
config_pair
.
second
);
HooksConfig
&
libraries
=
hooks_libraries_parser_
->
verifyLibraries
();
CfgMgr
::
instance
().
getStagingCfg
()
->
getHooksConfig
();
hooks_libraries_parser_
->
loadLibraries
();
hook_parser
.
parse
(
libraries
,
config_pair
.
second
);
libraries
.
verifyLibraries
(
config_pair
.
second
->
getPosition
());
libraries
.
loadLibraries
();
continue
;
continue
;
}
}
}
}
...
@@ -610,10 +612,10 @@ public:
...
@@ -610,10 +612,10 @@ public:
CfgMgr
::
instance
().
setD2ClientConfig
(
tmp
);
CfgMgr
::
instance
().
setD2ClientConfig
(
tmp
);
}
}
///
@brief Parsers used in the parsing of the configuration
///
Allows the tests to interrogate the state of the libraries (if required).
///
const
isc
::
hooks
::
HookLibsCollection
&
getLibraries
()
{
/// Allows the tests to interrogate the state of the parsers (if required).
return
(
CfgMgr
::
instance
().
getStagingCfg
()
->
getHooksConfig
().
get
());
boost
::
shared_ptr
<
HooksLibrariesParser
>
hooks_libraries_parser_
;
}
/// @brief specifies IP protocol family (AF_INET or AF_INET6)
/// @brief specifies IP protocol family (AF_INET or AF_INET6)
uint16_t
family_
;
uint16_t
family_
;
...
@@ -1306,8 +1308,7 @@ TEST_F(ParseConfigTest, noHooksLibraries) {
...
@@ -1306,8 +1308,7 @@ TEST_F(ParseConfigTest, noHooksLibraries) {
ASSERT_TRUE
(
rcode
==
0
)
<<
error_text_
;
ASSERT_TRUE
(
rcode
==
0
)
<<
error_text_
;
// Check that the parser recorded nothing.
// Check that the parser recorded nothing.
isc
::
hooks
::
HookLibsCollection
libraries
;
isc
::
hooks
::
HookLibsCollection
libraries
=
getLibraries
();
hooks_libraries_parser_
->
getLibraries
(
libraries
);
EXPECT_TRUE
(
libraries
.
empty
());
EXPECT_TRUE
(
libraries
.
empty
());
// Check that there are still no libraries loaded.
// Check that there are still no libraries loaded.
...
@@ -1329,8 +1330,7 @@ TEST_F(ParseConfigTest, oneHooksLibrary) {
...
@@ -1329,8 +1330,7 @@ TEST_F(ParseConfigTest, oneHooksLibrary) {
ASSERT_TRUE
(
rcode
==
0
)
<<
error_text_
;
ASSERT_TRUE
(
rcode
==
0
)
<<
error_text_
;
// Check that the parser recorded a single library.