Commit 7e2fdf2c authored by Marcin Siodelski's avatar Marcin Siodelski

[3534] Addressed review comments.

parent 24154b6c
...@@ -152,7 +152,7 @@ ControlledDhcpv4Srv::processConfig(isc::data::ConstElementPtr config) { ...@@ -152,7 +152,7 @@ ControlledDhcpv4Srv::processConfig(isc::data::ConstElementPtr config) {
// is no need to rollback configuration if socket fails to open on any // is no need to rollback configuration if socket fails to open on any
// of the interfaces. // of the interfaces.
CfgMgr::instance().getStagingCfg()-> CfgMgr::instance().getStagingCfg()->
getCfgIface().openSockets(CfgIface::V4, srv->getPort(), getCfgIface().openSockets(AF_INET, srv->getPort(),
getInstance()->useBroadcast()); getInstance()->useBroadcast());
return (answer); return (answer);
......
...@@ -2918,7 +2918,7 @@ TEST_F(Dhcp4ParserTest, selectedInterfaces) { ...@@ -2918,7 +2918,7 @@ TEST_F(Dhcp4ParserTest, selectedInterfaces) {
checkResult(status, 0); checkResult(status, 0);
CfgMgr::instance().getStagingCfg()-> CfgMgr::instance().getStagingCfg()->
getCfgIface().openSockets(CfgIface::V4, 10000); getCfgIface().openSockets(AF_INET, 10000);
// eth0 and eth1 were explicitly selected. eth2 was not. // eth0 and eth1 were explicitly selected. eth2 was not.
EXPECT_TRUE(test_config.socketOpen("eth0", AF_INET)); EXPECT_TRUE(test_config.socketOpen("eth0", AF_INET));
...@@ -2954,7 +2954,7 @@ TEST_F(Dhcp4ParserTest, allInterfaces) { ...@@ -2954,7 +2954,7 @@ TEST_F(Dhcp4ParserTest, allInterfaces) {
checkResult(status, 0); checkResult(status, 0);
CfgMgr::instance().getStagingCfg()-> CfgMgr::instance().getStagingCfg()->
getCfgIface().openSockets(CfgIface::V4, 10000); getCfgIface().openSockets(AF_INET, 10000);
// All interfaces should be now active. // All interfaces should be now active.
ASSERT_TRUE(test_config.socketOpen("eth0", AF_INET)); ASSERT_TRUE(test_config.socketOpen("eth0", AF_INET));
......
...@@ -147,7 +147,7 @@ ControlledDhcpv6Srv::processConfig(isc::data::ConstElementPtr config) { ...@@ -147,7 +147,7 @@ ControlledDhcpv6Srv::processConfig(isc::data::ConstElementPtr config) {
// is no need to rollback configuration if socket fails to open on any // is no need to rollback configuration if socket fails to open on any
// of the interfaces. // of the interfaces.
CfgMgr::instance().getStagingCfg()-> CfgMgr::instance().getStagingCfg()->
getCfgIface().openSockets(CfgIface::V6, srv->getPort()); getCfgIface().openSockets(AF_INET6, srv->getPort());
return (answer); return (answer);
} }
......
...@@ -55,6 +55,12 @@ following section applies only to the Bundy backend. ...@@ -55,6 +55,12 @@ following section applies only to the Bundy backend.
build, the configuration is then applied ("committed") and commit() method is build, the configuration is then applied ("committed") and commit() method is
called. called.
\note With the implementation of the Kea ticket #3534 we're moving away from
the concept of commit being called for individual parsers. When this ticket
and a couple of followup tickets are implemented, the commit will be a
single operation executed for the whole configuration received from many
parsers.
All parsers are defined in src/bin/dhcp6/config_parser.cc file. Some of them All parsers are defined in src/bin/dhcp6/config_parser.cc file. Some of them
are generic (e.g. Uint32Parser that is able to handle any are generic (e.g. Uint32Parser that is able to handle any
unsigned 32 bit integer), but some are very specialized (e.g. unsigned 32 bit integer), but some are very specialized (e.g.
......
...@@ -3056,7 +3056,7 @@ TEST_F(Dhcp6ParserTest, selectedInterfaces) { ...@@ -3056,7 +3056,7 @@ TEST_F(Dhcp6ParserTest, selectedInterfaces) {
checkResult(status, 0); checkResult(status, 0);
CfgMgr::instance().getStagingCfg()-> CfgMgr::instance().getStagingCfg()->
getCfgIface().openSockets(CfgIface::V6, 10000); getCfgIface().openSockets(AF_INET6, 10000);
// eth0 and eth1 were explicitly selected. eth2 was not. // eth0 and eth1 were explicitly selected. eth2 was not.
EXPECT_TRUE(test_config.socketOpen("eth0", AF_INET6)); EXPECT_TRUE(test_config.socketOpen("eth0", AF_INET6));
...@@ -3090,7 +3090,7 @@ TEST_F(Dhcp6ParserTest, allInterfaces) { ...@@ -3090,7 +3090,7 @@ TEST_F(Dhcp6ParserTest, allInterfaces) {
checkResult(status, 0); checkResult(status, 0);
CfgMgr::instance().getStagingCfg()-> CfgMgr::instance().getStagingCfg()->
getCfgIface().openSockets(CfgIface::V6, 10000); getCfgIface().openSockets(AF_INET6, 10000);
// All interfaces should be now active. // All interfaces should be now active.
EXPECT_TRUE(test_config.socketOpen("eth0", AF_INET6)); EXPECT_TRUE(test_config.socketOpen("eth0", AF_INET6));
......
...@@ -30,7 +30,7 @@ $(man_MANS): ...@@ -30,7 +30,7 @@ $(man_MANS):
endif endif
kea.conf: kea.conf.pre kea.conf: kea.conf.pre
$(top_srcdir)/tools/path_replacer.sh $(builddir)/kea.conf.pre $@ $(top_srcdir)/tools/path_replacer.sh $(top_srcdir)/src/bin/keactrl/kea.conf.pre $@
if INSTALL_CONFIGURATIONS if INSTALL_CONFIGURATIONS
......
...@@ -42,7 +42,7 @@ CfgIface::equals(const CfgIface& other) const { ...@@ -42,7 +42,7 @@ CfgIface::equals(const CfgIface& other) const {
} }
void void
CfgIface::openSockets(const Family& family, const uint16_t port, CfgIface::openSockets(const uint16_t family, const uint16_t port,
const bool use_bcast) const { const bool use_bcast) const {
// If wildcard interface '*' was not specified, set all interfaces to // If wildcard interface '*' was not specified, set all interfaces to
// inactive state. We will later enable them selectively using the // inactive state. We will later enable them selectively using the
...@@ -68,7 +68,7 @@ CfgIface::openSockets(const Family& family, const uint16_t port, ...@@ -68,7 +68,7 @@ CfgIface::openSockets(const Family& family, const uint16_t port,
<< *iface_name << "' as this interface doesn't" << *iface_name << "' as this interface doesn't"
" exist"); " exist");
} else if (family == V4) { } else if (family == AF_INET) {
iface->inactive4_ = false; iface->inactive4_ = false;
} else { } else {
...@@ -78,7 +78,7 @@ CfgIface::openSockets(const Family& family, const uint16_t port, ...@@ -78,7 +78,7 @@ CfgIface::openSockets(const Family& family, const uint16_t port,
} }
// Select unicast sockets. It works only for V6. Ignore for V4. // Select unicast sockets. It works only for V6. Ignore for V4.
if (family == V6) { if (family == AF_INET6) {
for (UnicastMap::const_iterator unicast = unicast_map_.begin(); for (UnicastMap::const_iterator unicast = unicast_map_.begin();
unicast != unicast_map_.end(); ++unicast) { unicast != unicast_map_.end(); ++unicast) {
Iface* iface = IfaceMgr::instance().getIface(unicast->first); Iface* iface = IfaceMgr::instance().getIface(unicast->first);
...@@ -102,7 +102,7 @@ CfgIface::openSockets(const Family& family, const uint16_t port, ...@@ -102,7 +102,7 @@ CfgIface::openSockets(const Family& family, const uint16_t port,
IfaceMgrErrorMsgCallback error_callback = IfaceMgrErrorMsgCallback error_callback =
boost::bind(&CfgIface::socketOpenErrorHandler, _1); boost::bind(&CfgIface::socketOpenErrorHandler, _1);
bool sopen; bool sopen;
if (family == V4) { if (family == AF_INET) {
sopen = IfaceMgr::instance().openSockets4(port, use_bcast, sopen = IfaceMgr::instance().openSockets4(port, use_bcast,
error_callback); error_callback);
} else { } else {
...@@ -124,13 +124,13 @@ CfgIface::reset() { ...@@ -124,13 +124,13 @@ CfgIface::reset() {
} }
void void
CfgIface::setState(const Family& family, const bool inactive, CfgIface::setState(const uint16_t family, const bool inactive,
const bool loopback_inactive) const { const bool loopback_inactive) const {
IfaceMgr::IfaceCollection ifaces = IfaceMgr::instance().getIfaces(); IfaceMgr::IfaceCollection ifaces = IfaceMgr::instance().getIfaces();
for (IfaceMgr::IfaceCollection::iterator iface = ifaces.begin(); for (IfaceMgr::IfaceCollection::iterator iface = ifaces.begin();
iface != ifaces.end(); ++iface) { iface != ifaces.end(); ++iface) {
Iface* iface_ptr = IfaceMgr::instance().getIface(iface->getName()); Iface* iface_ptr = IfaceMgr::instance().getIface(iface->getName());
if (family == V4) { if (family == AF_INET) {
iface_ptr->inactive4_ = iface_ptr->flag_loopback_ ? iface_ptr->inactive4_ = iface_ptr->flag_loopback_ ?
loopback_inactive : inactive; loopback_inactive : inactive;
} else { } else {
...@@ -146,7 +146,7 @@ CfgIface::socketOpenErrorHandler(const std::string& errmsg) { ...@@ -146,7 +146,7 @@ CfgIface::socketOpenErrorHandler(const std::string& errmsg) {
} }
void void
CfgIface::use(const Family& family, const std::string& iface_name) { CfgIface::use(const uint16_t family, const std::string& iface_name) {
// The interface name specified may have two formats, e.g.: // The interface name specified may have two formats, e.g.:
// - eth0 // - eth0
// - eth0/2001:db8:1::1. // - eth0/2001:db8:1::1.
...@@ -192,7 +192,7 @@ CfgIface::use(const Family& family, const std::string& iface_name) { ...@@ -192,7 +192,7 @@ CfgIface::use(const Family& family, const std::string& iface_name) {
} }
} else if (family == V4) { } else if (family == AF_INET) {
isc_throw(InvalidIfaceName, "unicast addresses in the format of: " isc_throw(InvalidIfaceName, "unicast addresses in the format of: "
"iface-name/unicast-addr_stress can only be specified for" "iface-name/unicast-addr_stress can only be specified for"
" IPv6 addr_stress family"); " IPv6 addr_stress family");
......
...@@ -64,6 +64,11 @@ public: ...@@ -64,6 +64,11 @@ public:
/// ///
/// Once interfaces have been specified the sockets (either IPv4 or IPv6) /// Once interfaces have been specified the sockets (either IPv4 or IPv6)
/// can be opened by calling @c CfgIface::openSockets function. /// can be opened by calling @c CfgIface::openSockets function.
///
/// @warning This class makes use of the AF_INET and AF_INET6 family literals,
/// but it doesn't verify that the address family value passed as @c uint16_t
/// parameter is equal to one of them. It is a callers responsibility to
/// guarantee that the address family value is correct.
class CfgIface { class CfgIface {
public: public:
/// @brief Keyword used to enable all interfaces. /// @brief Keyword used to enable all interfaces.
...@@ -72,14 +77,6 @@ public: ...@@ -72,14 +77,6 @@ public:
/// that DHCP server should listen on all interfaces. /// that DHCP server should listen on all interfaces.
static const char* ALL_IFACES_KEYWORD; static const char* ALL_IFACES_KEYWORD;
/// @brief Protocol family: IPv4 or IPv6.
///
/// Depending on the family specified, the IPv4 or IPv6 sockets are
/// opened.
enum Family {
V4, V6
};
/// @brief Constructor. /// @brief Constructor.
CfgIface(); CfgIface();
...@@ -100,12 +97,12 @@ public: ...@@ -100,12 +97,12 @@ public:
/// documentation for details how to specify interfaces and unicast /// documentation for details how to specify interfaces and unicast
/// addresses to bind the sockets to. /// addresses to bind the sockets to.
/// ///
/// @param family Address family (v4 or v6). /// @param family Address family (AF_INET or AF_INET6).
/// @param port Port number to be used to bind sockets to. /// @param port Port number to be used to bind sockets to.
/// @param use_bcast A boolean flag which indicates if the broadcast /// @param use_bcast A boolean flag which indicates if the broadcast
/// traffic should be received through the socket. This parameter is /// traffic should be received through the socket. This parameter is
/// ignored for IPv6. /// ignored for IPv6.
void openSockets(const Family& family, const uint16_t port, void openSockets(const uint16_t family, const uint16_t port,
const bool use_bcast = true) const; const bool use_bcast = true) const;
/// @brief Puts the interface configuration into default state. /// @brief Puts the interface configuration into default state.
...@@ -132,7 +129,7 @@ public: ...@@ -132,7 +129,7 @@ public:
/// not allowed when specifying a unicast address. For example: /// not allowed when specifying a unicast address. For example:
/// */2001:db8:1::1 is not allowed. /// */2001:db8:1::1 is not allowed.
/// ///
/// @param family Address family (v4 or v6). /// @param family Address family (AF_INET or AF_INET6).
/// @param iface_name Explicit interface name, a wildcard name (*) of /// @param iface_name Explicit interface name, a wildcard name (*) of
/// the interface(s) or the pair of iterface/unicast-address to be used /// the interface(s) or the pair of iterface/unicast-address to be used
/// to receive DHCP traffic. /// to receive DHCP traffic.
...@@ -144,7 +141,7 @@ public: ...@@ -144,7 +141,7 @@ public:
/// @throw DuplicateIfaceName If the interface is already selected, i.e. /// @throw DuplicateIfaceName If the interface is already selected, i.e.
/// @throw IOError when specified unicast address is invalid. /// @throw IOError when specified unicast address is invalid.
/// @c CfgIface::use has been already called for this interface. /// @c CfgIface::use has been already called for this interface.
void use(const Family& family, const std::string& iface_name); void use(const uint16_t family, const std::string& iface_name);
/// @brief Equality operator. /// @brief Equality operator.
/// ///
...@@ -171,13 +168,13 @@ private: ...@@ -171,13 +168,13 @@ private:
/// This function selects all interfaces to receive DHCP traffic or /// This function selects all interfaces to receive DHCP traffic or
/// deselects all interfaces so as none of them receives a DHCP traffic. /// deselects all interfaces so as none of them receives a DHCP traffic.
/// ///
/// @param family Address family (v4 or v6). /// @param family Address family (AF_INET or AF_INET6).
/// @param inactive A boolean value which indicates if all interfaces /// @param inactive A boolean value which indicates if all interfaces
/// (except loopback) should be selected or deselected. /// (except loopback) should be selected or deselected.
/// @param loopback_inactive A boolean value which indicates if loopback /// @param loopback_inactive A boolean value which indicates if loopback
/// interface should be selected or deselected. /// interface should be selected or deselected.
/// should be deselected/inactive (true) or selected/active (false). /// should be deselected/inactive (true) or selected/active (false).
void setState(const Family& family, const bool inactive, void setState(const uint16_t family, const bool inactive,
const bool loopback_inactive) const; const bool loopback_inactive) const;
/// @brief Error handler for executed when opening a socket fail. /// @brief Error handler for executed when opening a socket fail.
......
...@@ -406,8 +406,8 @@ public: ...@@ -406,8 +406,8 @@ public:
/// @brief Commits the staging configuration. /// @brief Commits the staging configuration.
/// ///
/// The staging configuration becomes current configuration when this /// The staging configuration becomes current configuration when this
/// function is called. It removes the oldest configurations held in the /// function is called. It removes the oldest configuration held in the
/// history so as the size of the list of configuration does not excide /// history so as the size of the list of configuration does not exceed
/// the @c CONFIG_LIST_SIZE. /// the @c CONFIG_LIST_SIZE.
/// ///
/// This function is exception safe. /// This function is exception safe.
...@@ -438,6 +438,10 @@ public: ...@@ -438,6 +438,10 @@ public:
/// @warning Revert operation will rollback any changes to the staging /// @warning Revert operation will rollback any changes to the staging
/// configuration (if it exists). /// configuration (if it exists).
/// ///
/// @param index A distance from the current configuration to the
/// past configuration to be reverted. The minimal value is 1 which points
/// to the nearest configuration.
///
/// @throw isc::OutOfRange if the specified index is out of range. /// @throw isc::OutOfRange if the specified index is out of range.
void revert(const size_t index); void revert(const size_t index);
...@@ -530,7 +534,7 @@ protected: ...@@ -530,7 +534,7 @@ protected:
private: private:
/// @brief Checks if current configuration is created and creates if needed. /// @brief Checks if current configuration is created and creates it if needed.
/// ///
/// This private method is called to ensure that the current configuration /// This private method is called to ensure that the current configuration
/// is created. If current configuration is not set, it creates the /// is created. If current configuration is not set, it creates the
......
...@@ -93,7 +93,7 @@ Configuration::copy(Configuration& new_config) const { ...@@ -93,7 +93,7 @@ Configuration::copy(Configuration& new_config) const {
void void
Configuration::applyLoggingCfg() const { Configuration::applyLoggingCfg() const {
/// @todo Remove the hardcoded location. /// @todo Remove the hardcoded location.
setenv("B10_LOCKFILE_DIR_FROM_BUILD", "/tmp", 1); setenv("KEA_LOCKFILE_DIR_FROM_BUILD", "/tmp", 1);
std::list<LoggerSpecification> specs; std::list<LoggerSpecification> specs;
for (LoggingInfoStorage::const_iterator it = logging_info_.begin(); for (LoggingInfoStorage::const_iterator it = logging_info_.begin();
......
...@@ -195,7 +195,7 @@ InterfaceListConfigParser::build(ConstElementPtr value) { ...@@ -195,7 +195,7 @@ InterfaceListConfigParser::build(ConstElementPtr value) {
std::string iface_name = iface->stringValue(); std::string iface_name = iface->stringValue();
try { try {
cfg_iface.use(global_context_->universe_ == Option::V4 ? cfg_iface.use(global_context_->universe_ == Option::V4 ?
CfgIface::V4 : CfgIface::V6, iface_name); AF_INET : AF_INET6, iface_name);
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
isc_throw(DhcpConfigError, "Failed to select interface: " isc_throw(DhcpConfigError, "Failed to select interface: "
......
// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC") // Copyright (C) 2012, 2014 Internet Systems Consortium, Inc. ("ISC")
// //
// Permission to use, copy, modify, and/or distribute this software for any // Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above // purpose with or without fee is hereby granted, provided that the above
...@@ -39,11 +39,47 @@ only available backend is MySQL (see \ref isc::dhcp::MySqlLeaseMgr). ...@@ -39,11 +39,47 @@ only available backend is MySQL (see \ref isc::dhcp::MySqlLeaseMgr).
@section cfgmgr Configuration Manager @section cfgmgr Configuration Manager
Configuration Manager (\ref isc::dhcp::CfgMgr) stores configuration information Configuration Manager (\ref isc::dhcp::CfgMgr) is a singleton object which
necessary for DHCPv4 and DHCPv6 server operation. In particular, it stores holds configuration information necessary for the operation of Kea daemons.
subnets (\ref isc::dhcp::Subnet4 and \ref isc::dhcp::Subnet6) together with A complete collection of information for the daemon is stored in the
their pools (\ref isc::dhcp::Pool4 and \ref isc::dhcp::Pool6), options and \ref isc::dhcp::Configuration object. Internally, the Configuration Manager
other information specified by the user in the Kea configuration. holds a list of \ref isc::dhcp::Configuration objects, from which one
is marked as "current configuration".
When the server starts up or is being reconfigured a new
\ref isc::dhcp::Configuration object, referred to as "staging configuration",
is created. The staging configuration is held at the tip of the list of
configurations. The object can be accessed by calling the
\ref isc::dhcp::CfgMgr::getStagingCfg. This object can be accessed
from different stages of the configuration parsing and modified as needed.
Modifications of to the staging configuration do not affect the current
configuration. The staging configuration is unused until the
\ref isc::dhcp::CfgMgr::commit function is called. This exception safe method
marks the staging object as "current configuration". The const pointer to the
current configuration can be accessed by calling a
\ref isc::dhcp::CfgMgr::getCurrentCfg.
The staging configuration can be discarded at any time before it is committed
by calling the \ref isc::dhcp::CfgMgr::rollback. This removes the
\ref isc::dhcp::Configuration object from the Configuration Manager. When
the \ref isc::dhcp::CfgMgr::getStagingCfg is called again a fresh/default
\ref isc::dhcp::Configuration object is returned.
The Configuration Manager stores previous configurations, i.e. configurations
which occurred prior to the most current configuration. This is currently
unused (except for unit tests) by the deamons, but in the future this
mechanism can be used to trigger a rollover of the server configuration
to a last good configuration that the administrator prefers.
The previous configurations are identified by the value which specifies a
distance between the current configuration and the previous
configuration. For example: the value of 1 identifies an immediate
predecessor of the current configuration, the value of 2 identifies the
one that occurred before it etc.
@todo Currently, only a subset of configuration information is stored in
the \ref isc::dhcp::Configuration object. Kea developers are actively working
on migrating the other configuration parameters to it.
@section allocengine Allocation Engine @section allocengine Allocation Engine
......
...@@ -67,11 +67,11 @@ CfgIfaceTest::unicastOpen(const std::string& iface_name) const { ...@@ -67,11 +67,11 @@ CfgIfaceTest::unicastOpen(const std::string& iface_name) const {
TEST_F(CfgIfaceTest, explicitNamesV4) { TEST_F(CfgIfaceTest, explicitNamesV4) {
CfgIface cfg; CfgIface cfg;
// Specify valid interface names. There should be no error. // Specify valid interface names. There should be no error.
ASSERT_NO_THROW(cfg.use(CfgIface::V4, "eth0")); ASSERT_NO_THROW(cfg.use(AF_INET, "eth0"));
ASSERT_NO_THROW(cfg.use(CfgIface::V4, "eth1")); ASSERT_NO_THROW(cfg.use(AF_INET, "eth1"));
// Open sockets on specified interfaces. // Open sockets on specified interfaces.
cfg.openSockets(CfgIface::V4, DHCP4_SERVER_PORT); cfg.openSockets(AF_INET, DHCP4_SERVER_PORT);
// Sockets should be now open on eth0 and eth1, but not on loopback. // Sockets should be now open on eth0 and eth1, but not on loopback.
EXPECT_TRUE(socketOpen("eth0", AF_INET)); EXPECT_TRUE(socketOpen("eth0", AF_INET));
...@@ -91,9 +91,9 @@ TEST_F(CfgIfaceTest, explicitNamesV4) { ...@@ -91,9 +91,9 @@ TEST_F(CfgIfaceTest, explicitNamesV4) {
// Reset configuration and select only one interface this time. // Reset configuration and select only one interface this time.
cfg.reset(); cfg.reset();
ASSERT_NO_THROW(cfg.use(CfgIface::V4, "eth1")); ASSERT_NO_THROW(cfg.use(AF_INET, "eth1"));
cfg.openSockets(CfgIface::V4, DHCP4_SERVER_PORT); cfg.openSockets(AF_INET, DHCP4_SERVER_PORT);
// Socket should be open on eth1 only. // Socket should be open on eth1 only.
EXPECT_FALSE(socketOpen("eth0", AF_INET)); EXPECT_FALSE(socketOpen("eth0", AF_INET));
...@@ -107,11 +107,11 @@ TEST_F(CfgIfaceTest, explicitNamesV4) { ...@@ -107,11 +107,11 @@ TEST_F(CfgIfaceTest, explicitNamesV4) {
TEST_F(CfgIfaceTest, explicitNamesV6) { TEST_F(CfgIfaceTest, explicitNamesV6) {
CfgIface cfg; CfgIface cfg;
// Specify valid interface names. There should be no error. // Specify valid interface names. There should be no error.
ASSERT_NO_THROW(cfg.use(CfgIface::V6, "eth0")); ASSERT_NO_THROW(cfg.use(AF_INET6, "eth0"));
ASSERT_NO_THROW(cfg.use(CfgIface::V6, "eth1")); ASSERT_NO_THROW(cfg.use(AF_INET6, "eth1"));
// Open sockets on specified interfaces. // Open sockets on specified interfaces.
cfg.openSockets(CfgIface::V6, DHCP6_SERVER_PORT); cfg.openSockets(AF_INET6, DHCP6_SERVER_PORT);
// Sockets should be now open on eth0 and eth1, but not on loopback. // Sockets should be now open on eth0 and eth1, but not on loopback.
EXPECT_TRUE(socketOpen("eth0", AF_INET6)); EXPECT_TRUE(socketOpen("eth0", AF_INET6));
...@@ -131,9 +131,9 @@ TEST_F(CfgIfaceTest, explicitNamesV6) { ...@@ -131,9 +131,9 @@ TEST_F(CfgIfaceTest, explicitNamesV6) {
// Reset configuration and select only one interface this time. // Reset configuration and select only one interface this time.
cfg.reset(); cfg.reset();
ASSERT_NO_THROW(cfg.use(CfgIface::V6, "eth1")); ASSERT_NO_THROW(cfg.use(AF_INET6, "eth1"));
cfg.openSockets(CfgIface::V6, DHCP6_SERVER_PORT); cfg.openSockets(AF_INET6, DHCP6_SERVER_PORT);
// Socket should be open on eth1 only. // Socket should be open on eth1 only.
EXPECT_FALSE(socketOpen("eth0", AF_INET6)); EXPECT_FALSE(socketOpen("eth0", AF_INET6));
...@@ -146,9 +146,9 @@ TEST_F(CfgIfaceTest, explicitNamesV6) { ...@@ -146,9 +146,9 @@ TEST_F(CfgIfaceTest, explicitNamesV6) {
// select all interfaces to open IPv4 sockets. // select all interfaces to open IPv4 sockets.
TEST_F(CfgIfaceTest, wildcardV4) { TEST_F(CfgIfaceTest, wildcardV4) {
CfgIface cfg; CfgIface cfg;
ASSERT_NO_THROW(cfg.use(CfgIface::V4, "*")); ASSERT_NO_THROW(cfg.use(AF_INET, "*"));
cfg.openSockets(CfgIface::V4, DHCP4_SERVER_PORT); cfg.openSockets(AF_INET, DHCP4_SERVER_PORT);
// Sockets should be now open on eth0 and eth1, but not on loopback. // Sockets should be now open on eth0 and eth1, but not on loopback.
EXPECT_TRUE(socketOpen("eth0", AF_INET)); EXPECT_TRUE(socketOpen("eth0", AF_INET));
...@@ -165,9 +165,9 @@ TEST_F(CfgIfaceTest, wildcardV4) { ...@@ -165,9 +165,9 @@ TEST_F(CfgIfaceTest, wildcardV4) {
// select all interfaces to open IPv6 sockets. // select all interfaces to open IPv6 sockets.
TEST_F(CfgIfaceTest, wildcardV6) { TEST_F(CfgIfaceTest, wildcardV6) {
CfgIface cfg; CfgIface cfg;
ASSERT_NO_THROW(cfg.use(CfgIface::V6, "*")); ASSERT_NO_THROW(cfg.use(AF_INET6, "*"));
cfg.openSockets(CfgIface::V6, DHCP6_SERVER_PORT); cfg.openSockets(AF_INET6, DHCP6_SERVER_PORT);
// Sockets should be now open on eth0 and eth1, but not on loopback. // Sockets should be now open on eth0 and eth1, but not on loopback.
EXPECT_TRUE(socketOpen("eth0", AF_INET6)); EXPECT_TRUE(socketOpen("eth0", AF_INET6));
...@@ -188,10 +188,10 @@ TEST_F(CfgIfaceTest, validUnicast) { ...@@ -188,10 +188,10 @@ TEST_F(CfgIfaceTest, validUnicast) {
// One socket will be opened on link-local address, one on unicast but // One socket will be opened on link-local address, one on unicast but
// on the same interface. // on the same interface.
ASSERT_NO_THROW(cfg.use(CfgIface::V6, "eth0")); ASSERT_NO_THROW(cfg.use(AF_INET6, "eth0"));
ASSERT_NO_THROW(cfg.use(CfgIface::V6, "eth0/2001:db8:1::1")); ASSERT_NO_THROW(cfg.use(AF_INET6, "eth0/2001:db8:1::1"));
cfg.openSockets(CfgIface::V6, DHCP6_SERVER_PORT); cfg.openSockets(AF_INET6, DHCP6_SERVER_PORT);
EXPECT_TRUE(socketOpen("eth0", AF_INET6)); EXPECT_TRUE(socketOpen("eth0", AF_INET6));
EXPECT_TRUE(unicastOpen("eth0")); EXPECT_TRUE(unicastOpen("eth0"));
...@@ -200,26 +200,26 @@ TEST_F(CfgIfaceTest, validUnicast) { ...@@ -200,26 +200,26 @@ TEST_F(CfgIfaceTest, validUnicast) {
// Test that when invalid interface names are specified an exception is thrown. // Test that when invalid interface names are specified an exception is thrown.
TEST_F(CfgIfaceTest, invalidValues) { TEST_F(CfgIfaceTest, invalidValues) {
CfgIface cfg; CfgIface cfg;
ASSERT_THROW(cfg.use(CfgIface::V4, ""), InvalidIfaceName); ASSERT_THROW(cfg.use(AF_INET, ""), InvalidIfaceName);
ASSERT_THROW(cfg.use(CfgIface::V4, " "), InvalidIfaceName); ASSERT_THROW(cfg.use(AF_INET, " "), InvalidIfaceName);
ASSERT_THROW(cfg.use(CfgIface::V4, "bogus"), NoSuchIface); ASSERT_THROW(cfg.use(AF_INET, "bogus"), NoSuchIface);
ASSERT_NO_THROW(cfg.use(CfgIface::V4, "eth0")); ASSERT_NO_THROW(cfg.use(AF_INET, "eth0"));
ASSERT_THROW(cfg.use(CfgIface::V4, "eth0"), DuplicateIfaceName); ASSERT_THROW(cfg.use(AF_INET, "eth0"), DuplicateIfaceName);
ASSERT_THROW(cfg.use(CfgIface::V4, "eth0/2001:db8:1::1"), InvalidIfaceName); ASSERT_THROW(cfg.use(AF_INET, "eth0/2001:db8:1::1"), InvalidIfaceName);
ASSERT_THROW(cfg.use(CfgIface::V6, "eth0/"), InvalidIfaceName); ASSERT_THROW(cfg.use(AF_INET6, "eth0/"), InvalidIfaceName);
ASSERT_THROW(cfg.use(CfgIface::V6, "/2001:db8:1::1"), InvalidIfaceName); ASSERT_THROW(cfg.use(AF_INET6, "/2001:db8:1::1"), InvalidIfaceName);
ASSERT_THROW(cfg.use(CfgIface::V6, "*/2001:db8:1::1"), InvalidIfaceName); ASSERT_THROW(cfg.use(AF_INET6, "*/2001:db8:1::1"), InvalidIfaceName);
ASSERT_THROW(cfg.use(CfgIface::V6, "bogus/2001:db8:1::1"), NoSuchIface); ASSERT_THROW(cfg.use(AF_INET6, "bogus/2001:db8:1::1"), NoSuchIface);
ASSERT_THROW(cfg.use(CfgIface::V6, "eth0/fe80::3a60:77ff:fed5:cdef"), ASSERT_THROW(cfg.use(AF_INET6, "eth0/fe80::3a60:77ff:fed5:cdef"),
InvalidIfaceName); InvalidIfaceName);
ASSERT_THROW(cfg.use(CfgIface::V6, "eth0/fe80::3a60:77ff:fed5:cdef"), ASSERT_THROW(cfg.use(AF_INET6, "eth0/fe80::3a60:77ff:fed5:cdef"),
InvalidIfaceName); InvalidIfaceName);
ASSERT_THROW(cfg.use(CfgIface::V6, "eth0/2001:db8:1::2"), NoSuchAddress); ASSERT_THROW(cfg.use(AF_INET6, "eth0/2001:db8:1::2"), NoSuchAddress);