Dhcpv4Srv::Dhcpv4Srv(uint16_t port, const bool use_bcast,
const bool direct_response_desired)
: io_service_(new IOService()), shutdown_(true), alloc_engine_(), port_(port),
- use_bcast_(use_bcast) {
+ use_bcast_(use_bcast), network_state_(NetworkState::DHCPv4) {
LOG_DEBUG(dhcp4_logger, DBG_DHCP4_START, DHCP4_OPEN_SOCKET).arg(port);
try {
return;
}
- processPacket(query, rsp);
+ // If the DHCP service has been globally disabled, drop the packet.
+ if (network_state_.isServiceEnabled()) {
+ processPacket(query, rsp);
+ }
if (!rsp) {
return;
#include <dhcp/option4_client_fqdn.h>
#include <dhcp/option_custom.h>
#include <dhcp_ddns/ncr_msg.h>
-#include <dhcpsrv/d2_client_mgr.h>
-#include <dhcpsrv/subnet.h>
#include <dhcpsrv/alloc_engine.h>
#include <dhcpsrv/cfg_option.h>
+#include <dhcpsrv/d2_client_mgr.h>
+#include <dhcpsrv/network_state.h>
+#include <dhcpsrv/subnet.h>
#include <hooks/callout_handle.h>
#include <dhcpsrv/daemon.h>
uint16_t port_; ///< UDP port number on which server listens.
bool use_bcast_; ///< Should broadcast be enabled on sockets (if true).
+ /// @brief Holds information about disabled DHCP service and/or
+ /// disabled subnet/network scopes.
+ NetworkState network_state_;
+
public:
/// Class methods for DHCPv4-over-DHCPv6 handler
Dhcpv6Srv::Dhcpv6Srv(uint16_t port)
: io_service_(new IOService()), port_(port), serverid_(), shutdown_(true),
- alloc_engine_()
+ alloc_engine_(), name_change_reqs_(), network_state_(NetworkState::DHCPv6)
{
LOG_DEBUG(dhcp6_logger, DBG_DHCP6_START, DHCP6_OPEN_SOCKET).arg(port);
return;
}
- processPacket(query, rsp);
+ // If the DHCP service has been globally disabled, drop the packet.
+ if (network_state_.isServiceEnabled()) {
+ processPacket(query, rsp);
+ }
if (!rsp) {
return;
#include <dhcpsrv/alloc_engine.h>
#include <dhcpsrv/cfg_option.h>
#include <dhcpsrv/d2_client_mgr.h>
+#include <dhcpsrv/network_state.h>
#include <dhcpsrv/subnet.h>
#include <hooks/callout_handle.h>
#include <dhcpsrv/daemon.h>
/// Holds a list of @c isc::dhcp_ddns::NameChangeRequest objects, which
/// are waiting for sending to kea-dhcp-ddns module.
std::queue<isc::dhcp_ddns::NameChangeRequest> name_change_reqs_;
+
+private:
+
+ /// @brief Holds information about disabled DHCP service and/or
+ /// disabled subnet/network scopes.
+ NetworkState network_state_;
+
};
}; // namespace isc::dhcp
public:
/// @brief Constructor.
- NetworkStateImpl()
- : globally_disabled_(false), disabled_subnets_(), disabled_networks_(),
- timer_present_(false), timer_mgr_(TimerMgr::instance()) {
+ NetworkStateImpl(const NetworkState::ServerType& server_type)
+ : server_type_(server_type), globally_disabled_(false), disabled_subnets_(),
+ disabled_networks_(), timer_present_(false), timer_mgr_(TimerMgr::instance()) {
+ }
+
+ /// @brief Destructor.
+ ~NetworkStateImpl() {
+ destroyTimer();
}
/// @brief Globally disables or enables DHCP service.
}
}
+ /// @brief Server type.
+ NetworkState::ServerType server_type_;
+
/// @brief A flag indicating if DHCP service is globally disabled.
bool globally_disabled_;
TimerMgrPtr timer_mgr_;
};
-NetworkState::NetworkState()
- : impl_(new NetworkStateImpl()) {
+NetworkState::NetworkState(const NetworkState::ServerType& server_type)
+ : impl_(new NetworkStateImpl(server_type)) {
}
void
class NetworkState {
public:
+ /// @brief DHCP server type.
+ enum ServerType {
+ DHCPv4,
+ DHCPv6
+ };
+
/// @brief Type of the container holding collection of subnet identifiers.
typedef std::set<SubnetID> Subnets;
typedef std::set<std::string> Networks;
/// @brief Constructor.
- NetworkState();
+ NetworkState(const ServerType& server_type);
/// @brief Globally disables DHCP service.
///
boost::shared_ptr<NetworkStateImpl> impl_;
};
+/// @brief Pointer to the @c NetworkState object.
+typedef boost::shared_ptr<NetworkState> NetworkStatePtr;
+
} // end of namespace isc::dhcp
} // end of namespace isc
// This test verifies that it is possible to disable and then enable service.
TEST_F(NetworkStateTest, disableEnableService) {
- NetworkState state;
+ NetworkState state(NetworkState::DHCPv4);
state.disableService();
EXPECT_FALSE(state.isServiceEnabled());
state.enableService();
// This test verifies that enableAll() enables the service. This test will be extended
// in the future to verify that it also enables disabled scopes.
TEST_F(NetworkStateTest, enableAll) {
- NetworkState state;
+ NetworkState state(NetworkState::DHCPv4);
state.disableService();
EXPECT_FALSE(state.isServiceEnabled());
state.enableAll();
// This test verifies that it is possible to setup delayed execution of enableAll
// function.
TEST_F(NetworkStateTest, delayedEnableAll) {
- NetworkState state;
+ NetworkState state(NetworkState::DHCPv4);
// Disable the service and then schedule enabling it in 1 second.
state.disableService();
state.delayedEnableAll(1);
// This test verifies that explicitly enabling the service cancels the timer
// scheduled for automatically enabling it.
TEST_F(NetworkStateTest, earlyEnableAll) {
- NetworkState state;
+ NetworkState state(NetworkState::DHCPv4);
// Disable the service.
state.disableService();
EXPECT_FALSE(state.isServiceEnabled());
// This test verifies that it is possible to call delayedEnableAll multiple times
// and that it results in only one timer being scheduled.
TEST_F(NetworkStateTest, multipleDelayedEnableAll) {
- NetworkState state;
+ NetworkState state(NetworkState::DHCPv4);
// Disable the service and then schedule enabling it in 1 second.
state.disableService();
// Schedule the first timer for 5 seconds.