2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-31 05:55:28 +00:00

[4267] Finished merge of trac4266 (run_one server routine)

This commit is contained in:
Francis Dupont
2016-02-24 14:00:14 +01:00
6 changed files with 524 additions and 498 deletions

View File

@@ -449,10 +449,17 @@ This error message is issued when preparing an on-wire format of the packet
has failed. The first argument identifies the client and the DHCP transaction. has failed. The first argument identifies the client and the DHCP transaction.
The second argument includes the error string. The second argument includes the error string.
% DHCP4_PACKET_PROCESS_EXCEPTION exception occurred during packet processing: %1 % DHCP4_PACKET_PROCESS_EXCEPTION exception occurred during packet processing
This error message indicates that an exception was raised during packet processing This error message indicates that a non-standard exception was raised
that was not caught by other, more specific exception handlers. This packet will during packet processing that was not caught by other, more specific
be dropped and the server will continue operation. exception handlers. This packet will be dropped and the server will
continue operation.
% DHCP4_PACKET_PROCESS_STD_EXCEPTION exception occurred during packet processing: %1
This error message indicates that a standard exception was raised
during packet processing that was not caught by other, more specific
exception handlers. This packet will be dropped and the server will
continue operation.
% DHCP4_PACKET_RECEIVED %1: %2 (type %3) received from %4 to %5 on interface %6 % DHCP4_PACKET_RECEIVED %1: %2 (type %3) received from %4 to %5 on interface %6
A debug message noting that the server has received the specified type of A debug message noting that the server has received the specified type of

View File

@@ -415,10 +415,29 @@ Dhcpv4Srv::sendPacket(const Pkt4Ptr& packet) {
bool bool
Dhcpv4Srv::run() { Dhcpv4Srv::run() {
while (!shutdown_) { while (!shutdown_) {
try {
run_one();
} catch (const std::exception& e) {
// General catch-all exception that are not caught by more specific
// catches. This one is for exceptions derived from std::exception.
LOG_ERROR(packet4_logger, DHCP4_PACKET_PROCESS_STD_EXCEPTION)
.arg(e.what());
} catch (...) {
// General catch-all exception that are not caught by more specific
// catches. This one is for other exceptions, not derived from
// std::exception.
LOG_ERROR(packet4_logger, DHCP4_PACKET_PROCESS_EXCEPTION);
}
}
return (true);
}
void
Dhcpv4Srv::run_one() {
// client's message and server's response // client's message and server's response
Pkt4Ptr query; Pkt4Ptr query;
Pkt4Ptr rsp;
try {
try { try {
uint32_t timeout = 1000; uint32_t timeout = 1000;
@@ -444,14 +463,13 @@ Dhcpv4Srv::run() {
.arg(timeout); .arg(timeout);
} }
} catch (const SignalInterruptOnSelect&) { } catch (const SignalInterruptOnSelect) {
// Packet reception interrupted because a signal has been received. // Packet reception interrupted because a signal has been received.
// This is not an error because we might have received a SIGTERM, // This is not an error because we might have received a SIGTERM,
// SIGINT, SIGHUP or SIGCHILD which are handled by the server. For // SIGINT, SIGHUP or SIGCHILD which are handled by the server. For
// signals that are not handled by the server we rely on the default // signals that are not handled by the server we rely on the default
// behavior of the system. // behavior of the system.
LOG_DEBUG(packet4_logger, DBG_DHCP4_DETAIL, LOG_DEBUG(packet4_logger, DBG_DHCP4_DETAIL, DHCP4_BUFFER_WAIT_SIGNAL)
DHCP4_BUFFER_WAIT_SIGNAL)
.arg(signal_set_->getNext()); .arg(signal_set_->getNext());
} catch (const std::exception& e) { } catch (const std::exception& e) {
// Log all other errors. // Log all other errors.
@@ -481,35 +499,21 @@ Dhcpv4Srv::run() {
// with no reception occurred. No need to log anything here because // with no reception occurred. No need to log anything here because
// we have logged right after the call to receivePacket(). // we have logged right after the call to receivePacket().
if (!query) { if (!query) {
continue; return;
} }
processPacket(query); processPacket(query);
} catch (const std::exception& e) {
// General catch-all exception that are not caught by more specific
// catches. This one is for exceptions derived from std::exception.
LOG_ERROR(packet4_logger, DHCP4_PACKET_PROCESS_EXCEPTION)
.arg(e.what());
} catch (...) {
// General catch-all exception that are not caught by more specific
// catches. This one is for other exceptions, not derived from
// std::exception.
LOG_ERROR(packet4_logger, DHCP4_PACKET_PROCESS_EXCEPTION)
.arg("an unknown exception not derived from std::exception");
} }
} }
return (true);
}
void void
Dhcpv4Srv::processPacket(Pkt4Ptr& query) { Dhcpv4Srv::processPacket(Pkt4Ptr& query) {
Pkt4Ptr rsp; Pkt4Ptr rsp;
// Log reception of the packet. We need to increase it early, as any // Log reception of the packet. We need to increase it early, as any
// failures in unpacking will cause the packet to be dropped. We // failures in unpacking will cause the packet to be dropped. We
// will increase type specific statistoc further down the road. // will increase type specific statistic further down the road.
// See processStatsReceived(). // See processStatsReceived().
isc::stats::StatsMgr::instance().addValue("pkt4-received", isc::stats::StatsMgr::instance().addValue("pkt4-received",
static_cast<int64_t>(1)); static_cast<int64_t>(1));
@@ -712,9 +716,6 @@ Dhcpv4Srv::processPacket(Pkt4Ptr& query) {
// Clear skip flag if it was set in previous callouts // Clear skip flag if it was set in previous callouts
callout_handle->setStatus(CalloutHandle::NEXT_STEP_CONTINUE); callout_handle->setStatus(CalloutHandle::NEXT_STEP_CONTINUE);
// Also pass the corresponding query packet as argument
callout_handle->setArgument("query4", query);
// Set our response // Set our response
callout_handle->setArgument("response4", rsp); callout_handle->setArgument("response4", rsp);

View File

@@ -208,13 +208,18 @@ public:
/// @brief Main server processing loop. /// @brief Main server processing loop.
/// ///
/// Main server processing loop. Receives incoming packets, and calls /// Main server processing loop. Call the processing one routine
/// processPacket for each of them. /// until shut down.
/// ///
/// @return true, if being shut down gracefully, fail if experienced /// @return true, if being shut down gracefully, never fail.
/// critical error.
bool run(); bool run();
/// @brief Main server processing one.
///
/// Main server processing one. Receives one incoming packet, calls
/// the processing packet routing,
void run_one();
/// @brief Process a single incoming DHCPv4 packet. /// @brief Process a single incoming DHCPv4 packet.
/// ///
/// It verifies correctness of the passed packet, call per-type processXXX /// It verifies correctness of the passed packet, call per-type processXXX

View File

@@ -417,16 +417,23 @@ because packets of this type must be sent to multicast. The first argument
specifies the client and transaction identification information, the specifies the client and transaction identification information, the
second argument specifies packet type. second argument specifies packet type.
% DHCP6_PACKET_PROCESS_EXCEPTION exception occurred during packet processing: %1 % DHCP6_PACKET_PROCESS_EXCEPTION exception occurred during packet processing
This error message indicates that an exception was raised during packet processing This error message indicates that a non-standard exception was raised
that was not caught by other, more specific exception handlers. This packet will during packet processing that was not caught by other, more specific
be dropped and the server will continue operation. exception handlers. This packet will be dropped and the server will
continue operation.
% DHCP6_PACKET_PROCESS_FAIL processing of %1 message received from %2 failed: %3 % DHCP6_PACKET_PROCESS_FAIL processing of %1 message received from %2 failed: %3
This is a general catch-all message indicating that the processing of the This is a general catch-all message indicating that the processing of the
specified packet type from the indicated address failed. The reason is given in the specified packet type from the indicated address failed. The reason is given in the
message. The server will not send a response but will instead ignore the packet. message. The server will not send a response but will instead ignore the packet.
% DHCP6_PACKET_PROCESS_STD_EXCEPTION exception occurred during packet processing: %1
This error message indicates that a standard exception was raised
during packet processing that was not caught by other, more specific
exception handlers. This packet will be dropped and the server will
continue operation.
% DHCP6_PACKET_RECEIVED %1: %2 (type %3) received from %4 to %5 on interface %6 % DHCP6_PACKET_RECEIVED %1: %2 (type %3) received from %4 to %5 on interface %6
A debug message noting that the server has received the specified type of A debug message noting that the server has received the specified type of
packet on the specified interface. The first argument specifies the packet on the specified interface. The first argument specifies the

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2011-2015 Internet Systems Consortium, Inc. ("ISC") // Copyright (C) 2011-2016 Internet Systems Consortium, Inc. ("ISC")
// //
// This Source Code Form is subject to the terms of the Mozilla Public // This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -288,12 +288,28 @@ Dhcpv6Srv::createContext(const Pkt6Ptr& pkt) {
bool Dhcpv6Srv::run() { bool Dhcpv6Srv::run() {
while (!shutdown_) { while (!shutdown_) {
try {
run_one();
} catch (const std::exception& e) {
// General catch-all standard exceptions that are not caught by more
// specific catches.
LOG_ERROR(packet6_logger, DHCP6_PACKET_PROCESS_STD_EXCEPTION)
.arg(e.what());
} catch (...) {
// General catch-all non-standard exception that are not caught
// by more specific catches.
LOG_ERROR(packet6_logger, DHCP6_PACKET_PROCESS_EXCEPTION);
}
}
return (true);
}
void Dhcpv6Srv::run_one() {
// client's message and server's response // client's message and server's response
Pkt6Ptr query; Pkt6Ptr query;
Pkt6Ptr rsp; Pkt6Ptr rsp;
try {
try { try {
uint32_t timeout = 1000; uint32_t timeout = 1000;
LOG_DEBUG(packet6_logger, DBG_DHCP6_DETAIL, DHCP6_BUFFER_WAIT).arg(timeout); LOG_DEBUG(packet6_logger, DBG_DHCP6_DETAIL, DHCP6_BUFFER_WAIT).arg(timeout);
@@ -357,7 +373,7 @@ bool Dhcpv6Srv::run() {
// Timeout may be reached or signal received, which breaks select() // Timeout may be reached or signal received, which breaks select()
// with no packet received // with no packet received
if (!query) { if (!query) {
continue; return;
} }
// In order to parse the DHCP options, the server needs to use some // In order to parse the DHCP options, the server needs to use some
@@ -425,7 +441,7 @@ bool Dhcpv6Srv::run() {
static_cast<int64_t>(1)); static_cast<int64_t>(1));
StatsMgr::instance().addValue("pkt6-receive-drop", StatsMgr::instance().addValue("pkt6-receive-drop",
static_cast<int64_t>(1)); static_cast<int64_t>(1));
continue; return;
} }
} }
@@ -438,7 +454,7 @@ bool Dhcpv6Srv::run() {
// Increase the statistic of dropped packets. // Increase the statistic of dropped packets.
StatsMgr::instance().addValue("pkt6-receive-drop", static_cast<int64_t>(1)); StatsMgr::instance().addValue("pkt6-receive-drop", static_cast<int64_t>(1));
continue; return;
} }
// Check if the received query has been sent to unicast or multicast. // Check if the received query has been sent to unicast or multicast.
@@ -448,7 +464,7 @@ bool Dhcpv6Srv::run() {
// Increase the statistic of dropped packets. // Increase the statistic of dropped packets.
StatsMgr::instance().addValue("pkt6-receive-drop", static_cast<int64_t>(1)); StatsMgr::instance().addValue("pkt6-receive-drop", static_cast<int64_t>(1));
continue; return;
} }
LOG_DEBUG(packet6_logger, DBG_DHCP6_BASIC_DATA, DHCP6_PACKET_RECEIVED) LOG_DEBUG(packet6_logger, DBG_DHCP6_BASIC_DATA, DHCP6_PACKET_RECEIVED)
@@ -483,7 +499,7 @@ bool Dhcpv6Srv::run() {
if (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_SKIP) { if (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_SKIP) {
LOG_DEBUG(hooks_logger, DBG_DHCP6_HOOKS, DHCP6_HOOK_PACKET_RCVD_SKIP) LOG_DEBUG(hooks_logger, DBG_DHCP6_HOOKS, DHCP6_HOOK_PACKET_RCVD_SKIP)
.arg(query->getLabel()); .arg(query->getLabel());
continue; return;
} }
/// @todo: Add support for DROP status. /// @todo: Add support for DROP status.
@@ -636,7 +652,7 @@ bool Dhcpv6Srv::run() {
} catch (const std::exception& e) { } catch (const std::exception& e) {
LOG_ERROR(options6_logger, DHCP6_PACK_FAIL) LOG_ERROR(options6_logger, DHCP6_PACK_FAIL)
.arg(e.what()); .arg(e.what());
continue; return;
} }
} }
@@ -665,7 +681,7 @@ bool Dhcpv6Srv::run() {
if (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_SKIP) { if (callout_handle->getStatus() == CalloutHandle::NEXT_STEP_SKIP) {
LOG_DEBUG(hooks_logger, DBG_DHCP6_HOOKS, DHCP6_HOOK_BUFFER_SEND_SKIP) LOG_DEBUG(hooks_logger, DBG_DHCP6_HOOKS, DHCP6_HOOK_BUFFER_SEND_SKIP)
.arg(rsp->getLabel()); .arg(rsp->getLabel());
continue; return;
} }
/// @todo: Add support for DROP status /// @todo: Add support for DROP status
@@ -687,21 +703,6 @@ bool Dhcpv6Srv::run() {
.arg(e.what()); .arg(e.what());
} }
} }
} catch (const std::exception& e) {
// General catch-all standard exceptions that are not caught by more
// specific catches.
LOG_ERROR(packet6_logger, DHCP6_PACKET_PROCESS_EXCEPTION)
.arg(e.what());
} catch (...) {
// General catch-all non-standard exception that are not caught
// by more specific catches.
LOG_ERROR(packet6_logger, DHCP6_PACKET_PROCESS_EXCEPTION)
.arg("an unknown exception not derived from std::exception");
}
}
return (true);
} }
std::string std::string

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2011-2015 Internet Systems Consortium, Inc. ("ISC") // Copyright (C) 2011-2016 Internet Systems Consortium, Inc. ("ISC")
// //
// This Source Code Form is subject to the terms of the Mozilla Public // This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -89,14 +89,19 @@ public:
/// @brief Main server processing loop. /// @brief Main server processing loop.
/// ///
/// Main server processing loop. Receives incoming packets, verifies /// Main server processing loop. Call the processing one routine
/// their correctness, generates appropriate answer (if needed) and /// until shut down.
/// transmits responses.
/// ///
/// @return true, if being shut down gracefully, fail if experienced /// @return true, if being shut down gracefully, never fail.
/// critical error.
bool run(); bool run();
/// @brief Main server processing one.
///
/// Main server processing one. Receives one incoming packet, verifies
/// its correctness, generates appropriate answer (if needed) and
/// transmits response.
void run_one();
/// @brief Instructs the server to shut down. /// @brief Instructs the server to shut down.
void shutdown(); void shutdown();