2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-29 13:07:50 +00:00

[#2799] set error if IOService is null in callouts

This commit is contained in:
Razvan Becheriu 2023-03-24 08:37:40 +02:00
parent e101a5cb2c
commit b885916e36
4 changed files with 79 additions and 4 deletions

View File

@ -20,6 +20,9 @@
#include <hooks/hooks.h>
#include <process/daemon.h>
#include <sstream>
#include <string>
namespace isc {
namespace ha {
@ -34,6 +37,7 @@ using namespace isc::dhcp;
using namespace isc::ha;
using namespace isc::hooks;
using namespace isc::process;
using namespace std;
extern "C" {
@ -44,6 +48,13 @@ int dhcp4_srv_configured(CalloutHandle& handle) {
try {
isc::asiolink::IOServicePtr io_service;
handle.getArgument("io_context", io_service);
if (!io_service) {
// Should not happen!
handle.setStatus(isc::hooks::CalloutHandle::NEXT_STEP_DROP);
const string error("Error: io_context is null");
handle.setArgument("error", error);
return (1);
}
isc::dhcp::NetworkStatePtr network_state;
handle.getArgument("network_state", network_state);
impl->startService(io_service, network_state, HAServerType::DHCPv4);
@ -52,6 +63,10 @@ int dhcp4_srv_configured(CalloutHandle& handle) {
LOG_ERROR(ha_logger, HA_DHCP4_START_SERVICE_FAILED)
.arg(ex.what());
handle.setStatus(isc::hooks::CalloutHandle::NEXT_STEP_DROP);
ostringstream os;
os << "Error: " << ex.what();
string error(os.str());
handle.setArgument("error", error);
return (1);
}
return (0);
@ -107,6 +122,13 @@ int dhcp6_srv_configured(CalloutHandle& handle) {
try {
isc::asiolink::IOServicePtr io_service;
handle.getArgument("io_context", io_service);
if (!io_service) {
// Should not happen!
handle.setStatus(isc::hooks::CalloutHandle::NEXT_STEP_DROP);
const string error("Error: io_context is null");
handle.setArgument("error", error);
return (1);
}
isc::dhcp::NetworkStatePtr network_state;
handle.getArgument("network_state", network_state);
impl->startService(io_service, network_state, HAServerType::DHCPv6);
@ -115,6 +137,10 @@ int dhcp6_srv_configured(CalloutHandle& handle) {
LOG_ERROR(ha_logger, HA_DHCP6_START_SERVICE_FAILED)
.arg(ex.what());
handle.setStatus(isc::hooks::CalloutHandle::NEXT_STEP_DROP);
ostringstream os;
os << "Error: " << ex.what();
string error(os.str());
handle.setArgument("error", error);
return (1);
}
return (0);

View File

@ -19,11 +19,15 @@
#include <mysql_cb_dhcp6.h>
#include <mysql_cb_log.h>
#include <sstream>
#include <string>
using namespace isc::cb;
using namespace isc::dhcp;
using namespace isc::hooks;
using namespace isc::log;
using namespace isc::process;
using namespace std;
extern "C" {
@ -65,6 +69,12 @@ int load(LibraryHandle& /* handle */) {
int dhcp4_srv_configured(CalloutHandle& handle) {
isc::asiolink::IOServicePtr io_service;
handle.getArgument("io_context", io_service);
if (!io_service) {
const string error("Error: io_context is null");
handle.setArgument("error", error);
handle.setStatus(isc::hooks::CalloutHandle::NEXT_STEP_DROP);
return (1);
}
isc::dhcp::MySqlConfigBackendImpl::setIOService(io_service);
return (0);
}
@ -78,6 +88,12 @@ int dhcp4_srv_configured(CalloutHandle& handle) {
int dhcp6_srv_configured(CalloutHandle& handle) {
isc::asiolink::IOServicePtr io_service;
handle.getArgument("io_context", io_service);
if (!io_service) {
const string error("Error: io_context is null");
handle.setArgument("error", error);
handle.setStatus(isc::hooks::CalloutHandle::NEXT_STEP_DROP);
return (1);
}
isc::dhcp::MySqlConfigBackendImpl::setIOService(io_service);
return (0);
}

View File

@ -19,11 +19,15 @@
#include <pgsql_cb_dhcp6.h>
#include <pgsql_cb_log.h>
#include <sstream>
#include <string>
using namespace isc::cb;
using namespace isc::dhcp;
using namespace isc::hooks;
using namespace isc::log;
using namespace isc::process;
using namespace std;
extern "C" {
@ -65,6 +69,12 @@ int load(LibraryHandle& /* handle */) {
int dhcp4_srv_configured(CalloutHandle& handle) {
isc::asiolink::IOServicePtr io_service;
handle.getArgument("io_context", io_service);
if (!io_service) {
const string error("Error: io_context is null");
handle.setArgument("error", error);
handle.setStatus(isc::hooks::CalloutHandle::NEXT_STEP_DROP);
return (1);
}
isc::dhcp::PgSqlConfigBackendImpl::setIOService(io_service);
return (0);
}
@ -78,6 +88,12 @@ int dhcp4_srv_configured(CalloutHandle& handle) {
int dhcp6_srv_configured(CalloutHandle& handle) {
isc::asiolink::IOServicePtr io_service;
handle.getArgument("io_context", io_service);
if (!io_service) {
const string error("Error: io_context is null");
handle.setArgument("error", error);
handle.setStatus(isc::hooks::CalloutHandle::NEXT_STEP_DROP);
return (1);
}
isc::dhcp::PgSqlConfigBackendImpl::setIOService(io_service);
return (0);
}

View File

@ -18,6 +18,8 @@
#include <dhcpsrv/subnet.h>
#include <process/daemon.h>
#include <string>
namespace isc {
namespace run_script {
@ -34,6 +36,7 @@ using namespace isc::hooks;
using namespace isc::process;
using namespace isc::run_script;
using namespace isc::util;
using namespace std;
// Functions accessed by the hooks framework use C linkage to avoid the name
// mangling that accompanies use of the C++ compiler as well as to avoid
@ -48,7 +51,7 @@ int load(LibraryHandle& handle) {
try {
// Make the hook library not loadable by d2 or ca.
uint16_t family = CfgMgr::instance().getFamily();
const std::string& proc_name = Daemon::getProcName();
const string& proc_name = Daemon::getProcName();
if (family == AF_INET) {
if (proc_name != "kea-dhcp4") {
isc_throw(isc::Unexpected, "Bad process name: " << proc_name
@ -63,7 +66,7 @@ int load(LibraryHandle& handle) {
impl.reset(new RunScriptImpl());
impl->configure(handle);
} catch (const std::exception& ex) {
} catch (const exception& ex) {
LOG_ERROR(run_script_logger, RUN_SCRIPT_LOAD_ERROR)
.arg(ex.what());
return (1);
@ -90,9 +93,16 @@ int dhcp4_srv_configured(CalloutHandle& handle) {
try {
isc::asiolink::IOServicePtr io_service;
handle.getArgument("io_context", io_service);
if (!io_service) {
// Should not happen!
handle.setStatus(isc::hooks::CalloutHandle::NEXT_STEP_DROP);
const string error("Error: io_context is null");
handle.setArgument("error", error);
return (1);
}
RunScriptImpl::setIOService(io_service);
} catch (const std::exception& ex) {
} catch (const exception& ex) {
LOG_ERROR(run_script_logger, RUN_SCRIPT_LOAD_ERROR)
.arg(ex.what());
handle.setStatus(isc::hooks::CalloutHandle::NEXT_STEP_DROP);
@ -108,9 +118,16 @@ int dhcp6_srv_configured(CalloutHandle& handle) {
try {
isc::asiolink::IOServicePtr io_service;
handle.getArgument("io_context", io_service);
if (!io_service) {
// Should not happen!
handle.setStatus(isc::hooks::CalloutHandle::NEXT_STEP_DROP);
const string error("Error: io_context is null");
handle.setArgument("error", error);
return (1);
}
RunScriptImpl::setIOService(io_service);
} catch (const std::exception& ex) {
} catch (const exception& ex) {
LOG_ERROR(run_script_logger, RUN_SCRIPT_LOAD_ERROR)
.arg(ex.what());
handle.setStatus(isc::hooks::CalloutHandle::NEXT_STEP_DROP);