diff --git a/src/hooks/dhcp/high_availability/ha_callouts.cc b/src/hooks/dhcp/high_availability/ha_callouts.cc index 9988f01b96..1d3e99d990 100644 --- a/src/hooks/dhcp/high_availability/ha_callouts.cc +++ b/src/hooks/dhcp/high_availability/ha_callouts.cc @@ -20,6 +20,9 @@ #include #include +#include +#include + 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); diff --git a/src/hooks/dhcp/mysql_cb/mysql_cb_callouts.cc b/src/hooks/dhcp/mysql_cb/mysql_cb_callouts.cc index fb30474e6c..c9e0dbefb2 100644 --- a/src/hooks/dhcp/mysql_cb/mysql_cb_callouts.cc +++ b/src/hooks/dhcp/mysql_cb/mysql_cb_callouts.cc @@ -19,11 +19,15 @@ #include #include +#include +#include + 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); } diff --git a/src/hooks/dhcp/pgsql_cb/pgsql_cb_callouts.cc b/src/hooks/dhcp/pgsql_cb/pgsql_cb_callouts.cc index 669fb84025..7e85401f27 100644 --- a/src/hooks/dhcp/pgsql_cb/pgsql_cb_callouts.cc +++ b/src/hooks/dhcp/pgsql_cb/pgsql_cb_callouts.cc @@ -19,11 +19,15 @@ #include #include +#include +#include + 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); } diff --git a/src/hooks/dhcp/run_script/run_script_callouts.cc b/src/hooks/dhcp/run_script/run_script_callouts.cc index 4a339278f0..8ecdc14c9d 100644 --- a/src/hooks/dhcp/run_script/run_script_callouts.cc +++ b/src/hooks/dhcp/run_script/run_script_callouts.cc @@ -18,6 +18,8 @@ #include #include +#include + 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);