Commit cff0cf5a authored by Marcin Siodelski's avatar Marcin Siodelski

[5442] Store network states in DHCPv4 and DHCPv6 servers.

parent 218f7033
......@@ -416,7 +416,7 @@ const std::string Dhcpv4Srv::VENDOR_CLASS_PREFIX("VENDOR_CLASS_");
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 {
......@@ -804,7 +804,10 @@ Dhcpv4Srv::run_one() {
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;
......
......@@ -15,10 +15,11 @@
#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>
......@@ -840,6 +841,10 @@ private:
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
......
......@@ -179,7 +179,7 @@ const std::string Dhcpv6Srv::VENDOR_CLASS_PREFIX("VENDOR_CLASS_");
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);
......@@ -468,7 +468,10 @@ void Dhcpv6Srv::run_one() {
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;
......
......@@ -19,6 +19,7 @@
#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>
......@@ -871,6 +872,13 @@ protected:
/// 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
......
......@@ -18,9 +18,14 @@ class NetworkStateImpl : public boost::enable_shared_from_this<NetworkStateImpl>
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.
......@@ -66,6 +71,9 @@ public:
}
}
/// @brief Server type.
NetworkState::ServerType server_type_;
/// @brief A flag indicating if DHCP service is globally disabled.
bool globally_disabled_;
......@@ -86,8 +94,8 @@ public:
TimerMgrPtr timer_mgr_;
};
NetworkState::NetworkState()
: impl_(new NetworkStateImpl()) {
NetworkState::NetworkState(const NetworkState::ServerType& server_type)
: impl_(new NetworkStateImpl(server_type)) {
}
void
......
......@@ -45,6 +45,12 @@ class NetworkStateImpl;
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;
......@@ -52,7 +58,7 @@ public:
typedef std::set<std::string> Networks;
/// @brief Constructor.
NetworkState();
NetworkState(const ServerType& server_type);
/// @brief Globally disables DHCP service.
///
......@@ -134,6 +140,9 @@ private:
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
......
......@@ -65,7 +65,7 @@ public:
// 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();
......@@ -75,7 +75,7 @@ TEST_F(NetworkStateTest, disableEnableService) {
// 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();
......@@ -85,7 +85,7 @@ TEST_F(NetworkStateTest, 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);
......@@ -99,7 +99,7 @@ TEST_F(NetworkStateTest, delayedEnableAll) {
// 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());
......@@ -115,7 +115,7 @@ TEST_F(NetworkStateTest, earlyEnableAll) {
// 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.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment