mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-08-31 22:15:23 +00:00
[5442] Store network states in DHCPv4 and DHCPv6 servers.
This commit is contained in:
@@ -416,7 +416,7 @@ const std::string Dhcpv4Srv::VENDOR_CLASS_PREFIX("VENDOR_CLASS_");
|
|||||||
Dhcpv4Srv::Dhcpv4Srv(uint16_t port, const bool use_bcast,
|
Dhcpv4Srv::Dhcpv4Srv(uint16_t port, const bool use_bcast,
|
||||||
const bool direct_response_desired)
|
const bool direct_response_desired)
|
||||||
: io_service_(new IOService()), shutdown_(true), alloc_engine_(), port_(port),
|
: 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);
|
LOG_DEBUG(dhcp4_logger, DBG_DHCP4_START, DHCP4_OPEN_SOCKET).arg(port);
|
||||||
try {
|
try {
|
||||||
@@ -804,7 +804,10 @@ Dhcpv4Srv::run_one() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
processPacket(query, rsp);
|
// If the DHCP service has been globally disabled, drop the packet.
|
||||||
|
if (network_state_.isServiceEnabled()) {
|
||||||
|
processPacket(query, rsp);
|
||||||
|
}
|
||||||
|
|
||||||
if (!rsp) {
|
if (!rsp) {
|
||||||
return;
|
return;
|
||||||
|
@@ -15,10 +15,11 @@
|
|||||||
#include <dhcp/option4_client_fqdn.h>
|
#include <dhcp/option4_client_fqdn.h>
|
||||||
#include <dhcp/option_custom.h>
|
#include <dhcp/option_custom.h>
|
||||||
#include <dhcp_ddns/ncr_msg.h>
|
#include <dhcp_ddns/ncr_msg.h>
|
||||||
#include <dhcpsrv/d2_client_mgr.h>
|
|
||||||
#include <dhcpsrv/subnet.h>
|
|
||||||
#include <dhcpsrv/alloc_engine.h>
|
#include <dhcpsrv/alloc_engine.h>
|
||||||
#include <dhcpsrv/cfg_option.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 <hooks/callout_handle.h>
|
||||||
#include <dhcpsrv/daemon.h>
|
#include <dhcpsrv/daemon.h>
|
||||||
|
|
||||||
@@ -840,6 +841,10 @@ private:
|
|||||||
uint16_t port_; ///< UDP port number on which server listens.
|
uint16_t port_; ///< UDP port number on which server listens.
|
||||||
bool use_bcast_; ///< Should broadcast be enabled on sockets (if true).
|
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:
|
public:
|
||||||
/// Class methods for DHCPv4-over-DHCPv6 handler
|
/// 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)
|
Dhcpv6Srv::Dhcpv6Srv(uint16_t port)
|
||||||
: io_service_(new IOService()), port_(port), serverid_(), shutdown_(true),
|
: 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);
|
LOG_DEBUG(dhcp6_logger, DBG_DHCP6_START, DHCP6_OPEN_SOCKET).arg(port);
|
||||||
@@ -468,7 +468,10 @@ void Dhcpv6Srv::run_one() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
processPacket(query, rsp);
|
// If the DHCP service has been globally disabled, drop the packet.
|
||||||
|
if (network_state_.isServiceEnabled()) {
|
||||||
|
processPacket(query, rsp);
|
||||||
|
}
|
||||||
|
|
||||||
if (!rsp) {
|
if (!rsp) {
|
||||||
return;
|
return;
|
||||||
|
@@ -19,6 +19,7 @@
|
|||||||
#include <dhcpsrv/alloc_engine.h>
|
#include <dhcpsrv/alloc_engine.h>
|
||||||
#include <dhcpsrv/cfg_option.h>
|
#include <dhcpsrv/cfg_option.h>
|
||||||
#include <dhcpsrv/d2_client_mgr.h>
|
#include <dhcpsrv/d2_client_mgr.h>
|
||||||
|
#include <dhcpsrv/network_state.h>
|
||||||
#include <dhcpsrv/subnet.h>
|
#include <dhcpsrv/subnet.h>
|
||||||
#include <hooks/callout_handle.h>
|
#include <hooks/callout_handle.h>
|
||||||
#include <dhcpsrv/daemon.h>
|
#include <dhcpsrv/daemon.h>
|
||||||
@@ -871,6 +872,13 @@ protected:
|
|||||||
/// Holds a list of @c isc::dhcp_ddns::NameChangeRequest objects, which
|
/// Holds a list of @c isc::dhcp_ddns::NameChangeRequest objects, which
|
||||||
/// are waiting for sending to kea-dhcp-ddns module.
|
/// are waiting for sending to kea-dhcp-ddns module.
|
||||||
std::queue<isc::dhcp_ddns::NameChangeRequest> name_change_reqs_;
|
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
|
}; // namespace isc::dhcp
|
||||||
|
@@ -18,9 +18,14 @@ class NetworkStateImpl : public boost::enable_shared_from_this<NetworkStateImpl>
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
/// @brief Constructor.
|
/// @brief Constructor.
|
||||||
NetworkStateImpl()
|
NetworkStateImpl(const NetworkState::ServerType& server_type)
|
||||||
: globally_disabled_(false), disabled_subnets_(), disabled_networks_(),
|
: server_type_(server_type), globally_disabled_(false), disabled_subnets_(),
|
||||||
timer_present_(false), timer_mgr_(TimerMgr::instance()) {
|
disabled_networks_(), timer_present_(false), timer_mgr_(TimerMgr::instance()) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @brief Destructor.
|
||||||
|
~NetworkStateImpl() {
|
||||||
|
destroyTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Globally disables or enables DHCP service.
|
/// @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.
|
/// @brief A flag indicating if DHCP service is globally disabled.
|
||||||
bool globally_disabled_;
|
bool globally_disabled_;
|
||||||
|
|
||||||
@@ -86,8 +94,8 @@ public:
|
|||||||
TimerMgrPtr timer_mgr_;
|
TimerMgrPtr timer_mgr_;
|
||||||
};
|
};
|
||||||
|
|
||||||
NetworkState::NetworkState()
|
NetworkState::NetworkState(const NetworkState::ServerType& server_type)
|
||||||
: impl_(new NetworkStateImpl()) {
|
: impl_(new NetworkStateImpl(server_type)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@@ -45,6 +45,12 @@ class NetworkStateImpl;
|
|||||||
class NetworkState {
|
class NetworkState {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
/// @brief DHCP server type.
|
||||||
|
enum ServerType {
|
||||||
|
DHCPv4,
|
||||||
|
DHCPv6
|
||||||
|
};
|
||||||
|
|
||||||
/// @brief Type of the container holding collection of subnet identifiers.
|
/// @brief Type of the container holding collection of subnet identifiers.
|
||||||
typedef std::set<SubnetID> Subnets;
|
typedef std::set<SubnetID> Subnets;
|
||||||
|
|
||||||
@@ -52,7 +58,7 @@ public:
|
|||||||
typedef std::set<std::string> Networks;
|
typedef std::set<std::string> Networks;
|
||||||
|
|
||||||
/// @brief Constructor.
|
/// @brief Constructor.
|
||||||
NetworkState();
|
NetworkState(const ServerType& server_type);
|
||||||
|
|
||||||
/// @brief Globally disables DHCP service.
|
/// @brief Globally disables DHCP service.
|
||||||
///
|
///
|
||||||
@@ -134,6 +140,9 @@ private:
|
|||||||
boost::shared_ptr<NetworkStateImpl> impl_;
|
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::dhcp
|
||||||
} // end of namespace isc
|
} // end of namespace isc
|
||||||
|
|
||||||
|
@@ -65,7 +65,7 @@ public:
|
|||||||
|
|
||||||
// This test verifies that it is possible to disable and then enable service.
|
// This test verifies that it is possible to disable and then enable service.
|
||||||
TEST_F(NetworkStateTest, disableEnableService) {
|
TEST_F(NetworkStateTest, disableEnableService) {
|
||||||
NetworkState state;
|
NetworkState state(NetworkState::DHCPv4);
|
||||||
state.disableService();
|
state.disableService();
|
||||||
EXPECT_FALSE(state.isServiceEnabled());
|
EXPECT_FALSE(state.isServiceEnabled());
|
||||||
state.enableService();
|
state.enableService();
|
||||||
@@ -75,7 +75,7 @@ TEST_F(NetworkStateTest, disableEnableService) {
|
|||||||
// This test verifies that enableAll() enables the service. This test will be extended
|
// This test verifies that enableAll() enables the service. This test will be extended
|
||||||
// in the future to verify that it also enables disabled scopes.
|
// in the future to verify that it also enables disabled scopes.
|
||||||
TEST_F(NetworkStateTest, enableAll) {
|
TEST_F(NetworkStateTest, enableAll) {
|
||||||
NetworkState state;
|
NetworkState state(NetworkState::DHCPv4);
|
||||||
state.disableService();
|
state.disableService();
|
||||||
EXPECT_FALSE(state.isServiceEnabled());
|
EXPECT_FALSE(state.isServiceEnabled());
|
||||||
state.enableAll();
|
state.enableAll();
|
||||||
@@ -85,7 +85,7 @@ TEST_F(NetworkStateTest, enableAll) {
|
|||||||
// This test verifies that it is possible to setup delayed execution of enableAll
|
// This test verifies that it is possible to setup delayed execution of enableAll
|
||||||
// function.
|
// function.
|
||||||
TEST_F(NetworkStateTest, delayedEnableAll) {
|
TEST_F(NetworkStateTest, delayedEnableAll) {
|
||||||
NetworkState state;
|
NetworkState state(NetworkState::DHCPv4);
|
||||||
// Disable the service and then schedule enabling it in 1 second.
|
// Disable the service and then schedule enabling it in 1 second.
|
||||||
state.disableService();
|
state.disableService();
|
||||||
state.delayedEnableAll(1);
|
state.delayedEnableAll(1);
|
||||||
@@ -99,7 +99,7 @@ TEST_F(NetworkStateTest, delayedEnableAll) {
|
|||||||
// This test verifies that explicitly enabling the service cancels the timer
|
// This test verifies that explicitly enabling the service cancels the timer
|
||||||
// scheduled for automatically enabling it.
|
// scheduled for automatically enabling it.
|
||||||
TEST_F(NetworkStateTest, earlyEnableAll) {
|
TEST_F(NetworkStateTest, earlyEnableAll) {
|
||||||
NetworkState state;
|
NetworkState state(NetworkState::DHCPv4);
|
||||||
// Disable the service.
|
// Disable the service.
|
||||||
state.disableService();
|
state.disableService();
|
||||||
EXPECT_FALSE(state.isServiceEnabled());
|
EXPECT_FALSE(state.isServiceEnabled());
|
||||||
@@ -115,7 +115,7 @@ TEST_F(NetworkStateTest, earlyEnableAll) {
|
|||||||
// This test verifies that it is possible to call delayedEnableAll multiple times
|
// This test verifies that it is possible to call delayedEnableAll multiple times
|
||||||
// and that it results in only one timer being scheduled.
|
// and that it results in only one timer being scheduled.
|
||||||
TEST_F(NetworkStateTest, multipleDelayedEnableAll) {
|
TEST_F(NetworkStateTest, multipleDelayedEnableAll) {
|
||||||
NetworkState state;
|
NetworkState state(NetworkState::DHCPv4);
|
||||||
// Disable the service and then schedule enabling it in 1 second.
|
// Disable the service and then schedule enabling it in 1 second.
|
||||||
state.disableService();
|
state.disableService();
|
||||||
// Schedule the first timer for 5 seconds.
|
// Schedule the first timer for 5 seconds.
|
||||||
|
Reference in New Issue
Block a user