Commit 2b06d0f7 authored by Francis Dupont's avatar Francis Dupont

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

parents 15293d06 08799aa8
......@@ -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.
The second argument includes the error string.
% DHCP4_PACKET_PROCESS_EXCEPTION exception occurred during packet processing: %1
This error message indicates that an 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_PROCESS_EXCEPTION exception occurred during packet processing
This error message indicates that a non-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_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
A debug message noting that the server has received the specified type of
......
......@@ -415,101 +415,105 @@ Dhcpv4Srv::sendPacket(const Pkt4Ptr& packet) {
bool
Dhcpv4Srv::run() {
while (!shutdown_) {
// client's message and server's response
Pkt4Ptr query;
try {
try {
uint32_t timeout = 1000;
LOG_DEBUG(packet4_logger, DBG_DHCP4_DETAIL, DHCP4_BUFFER_WAIT).arg(timeout);
query = receivePacket(timeout);
// Log if packet has arrived. We can't log the detailed information
// about the DHCP message because it hasn't been unpacked/parsed
// yet, and it can't be parsed at this point because hooks will
// have to process it first. The only information available at this
// point are: the interface, source address and destination addresses
// and ports.
if (query) {
LOG_DEBUG(packet4_logger, DBG_DHCP4_BASIC, DHCP4_BUFFER_RECEIVED)
.arg(query->getRemoteAddr().toText())
.arg(query->getRemotePort())
.arg(query->getLocalAddr().toText())
.arg(query->getLocalPort())
.arg(query->getIface());
} else {
LOG_DEBUG(packet4_logger, DBG_DHCP4_DETAIL, DHCP4_BUFFER_WAIT_INTERRUPTED)
.arg(timeout);
}
} catch (const SignalInterruptOnSelect&) {
// Packet reception interrupted because a signal has been received.
// This is not an error because we might have received a SIGTERM,
// SIGINT, SIGHUP or SIGCHILD which are handled by the server. For
// signals that are not handled by the server we rely on the default
// behavior of the system.
LOG_DEBUG(packet4_logger, DBG_DHCP4_DETAIL,
DHCP4_BUFFER_WAIT_SIGNAL)
.arg(signal_set_->getNext());
} catch (const std::exception& e) {
// Log all other errors.
LOG_ERROR(packet4_logger, DHCP4_BUFFER_RECEIVE_FAIL).arg(e.what());
}
// Handle next signal received by the process. It must be called after
// an attempt to receive a packet to properly handle server shut down.
// The SIGTERM or SIGINT will be received prior to, or during execution
// of select() (select is invoked by receivePacket()). When that
// happens, select will be interrupted. The signal handler will be
// invoked immediately after select(). The handler will set the
// shutdown flag and cause the process to terminate before the next
// select() function is called. If the function was called before
// receivePacket the process could wait up to the duration of timeout
// of select() to terminate.
try {
handleSignal();
} catch (const std::exception& e) {
// Standard exception occurred. Let's be on the safe side to
// catch std::exception.
LOG_ERROR(dhcp4_logger, DHCP4_HANDLE_SIGNAL_EXCEPTION)
.arg(e.what());
}
// Timeout may be reached or signal received, which breaks select()
// with no reception occurred. No need to log anything here because
// we have logged right after the call to receivePacket().
if (!query) {
continue;
}
processPacket(query);
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_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)
.arg("an unknown exception 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
Pkt4Ptr query;
Pkt4Ptr rsp;
try {
uint32_t timeout = 1000;
LOG_DEBUG(packet4_logger, DBG_DHCP4_DETAIL, DHCP4_BUFFER_WAIT).arg(timeout);
query = receivePacket(timeout);
// Log if packet has arrived. We can't log the detailed information
// about the DHCP message because it hasn't been unpacked/parsed
// yet, and it can't be parsed at this point because hooks will
// have to process it first. The only information available at this
// point are: the interface, source address and destination addresses
// and ports.
if (query) {
LOG_DEBUG(packet4_logger, DBG_DHCP4_BASIC, DHCP4_BUFFER_RECEIVED)
.arg(query->getRemoteAddr().toText())
.arg(query->getRemotePort())
.arg(query->getLocalAddr().toText())
.arg(query->getLocalPort())
.arg(query->getIface());
} else {
LOG_DEBUG(packet4_logger, DBG_DHCP4_DETAIL, DHCP4_BUFFER_WAIT_INTERRUPTED)
.arg(timeout);
}
} catch (const SignalInterruptOnSelect) {
// Packet reception interrupted because a signal has been received.
// This is not an error because we might have received a SIGTERM,
// SIGINT, SIGHUP or SIGCHILD which are handled by the server. For
// signals that are not handled by the server we rely on the default
// behavior of the system.
LOG_DEBUG(packet4_logger, DBG_DHCP4_DETAIL, DHCP4_BUFFER_WAIT_SIGNAL)
.arg(signal_set_->getNext());
} catch (const std::exception& e) {
// Log all other errors.
LOG_ERROR(packet4_logger, DHCP4_BUFFER_RECEIVE_FAIL).arg(e.what());
}
// Handle next signal received by the process. It must be called after
// an attempt to receive a packet to properly handle server shut down.
// The SIGTERM or SIGINT will be received prior to, or during execution
// of select() (select is invoked by receivePacket()). When that
// happens, select will be interrupted. The signal handler will be
// invoked immediately after select(). The handler will set the
// shutdown flag and cause the process to terminate before the next
// select() function is called. If the function was called before
// receivePacket the process could wait up to the duration of timeout
// of select() to terminate.
try {
handleSignal();
} catch (const std::exception& e) {
// Standard exception occurred. Let's be on the safe side to
// catch std::exception.
LOG_ERROR(dhcp4_logger, DHCP4_HANDLE_SIGNAL_EXCEPTION)
.arg(e.what());
}
// Timeout may be reached or signal received, which breaks select()
// with no reception occurred. No need to log anything here because
// we have logged right after the call to receivePacket().
if (!query) {
return;
}
processPacket(query);
}
}
void
Dhcpv4Srv::processPacket(Pkt4Ptr& query) {
Pkt4Ptr rsp;
// Log reception of the packet. We need to increase it early, as any
// 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().
isc::stats::StatsMgr::instance().addValue("pkt4-received",
static_cast<int64_t>(1));
......@@ -712,9 +716,6 @@ Dhcpv4Srv::processPacket(Pkt4Ptr& query) {
// Clear skip flag if it was set in previous callouts
callout_handle->setStatus(CalloutHandle::NEXT_STEP_CONTINUE);
// Also pass the corresponding query packet as argument
callout_handle->setArgument("query4", query);
// Set our response
callout_handle->setArgument("response4", rsp);
......
......@@ -208,13 +208,18 @@ public:
/// @brief Main server processing loop.
///
/// Main server processing loop. Receives incoming packets, and calls
/// processPacket for each of them.
/// Main server processing loop. Call the processing one routine
/// until shut down.
///
/// @return true, if being shut down gracefully, fail if experienced
/// critical error.
/// @return true, if being shut down gracefully, never fail.
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.
///
/// It verifies correctness of the passed packet, call per-type processXXX
......
......@@ -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
second argument specifies packet type.
% DHCP6_PACKET_PROCESS_EXCEPTION exception occurred during packet processing: %1
This error message indicates that an 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_PROCESS_EXCEPTION exception occurred during packet processing
This error message indicates that a non-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_PROCESS_FAIL processing of %1 message received from %2 failed: %3
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
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
A debug message noting that the server has received the specified type of
packet on the specified interface. The first argument specifies the
......
This diff is collapsed.
// 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
// 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.
///
/// Main server processing loop. Receives incoming packets, verifies
/// their correctness, generates appropriate answer (if needed) and
/// transmits responses.
/// Main server processing loop. Call the processing one routine
/// until shut down.
///
/// @return true, if being shut down gracefully, fail if experienced
/// critical error.
/// @return true, if being shut down gracefully, never fail.
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.
void shutdown();
......
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