Browse Source

[2187] Log exceptions from IfaceMgr::send and IfaceMgr::receiveX.

Marcin Siodelski 12 years ago
parent
commit
1a7e6f8b2d

+ 9 - 0
src/bin/dhcp4/dhcp4_messages.mes

@@ -42,12 +42,21 @@ server is about to open sockets on the specified port.
 The IPv4 DHCP server has received a packet that it is unable to
 The IPv4 DHCP server has received a packet that it is unable to
 interpret. The reason why the packet is invalid is included in the message.
 interpret. The reason why the packet is invalid is included in the message.
 
 
+% DHCP4_PACKET_RECEIVE_FAIL error on attempt to receive packet: %1
+The IPv4 DHCP server tried to receive a packet but unexpected error
+occured during this attempt. The reason for the error is included in
+the message.
+
 % DHCP4_PACKET_RECEIVED %1 (type %2) packet received on interface %3
 % DHCP4_PACKET_RECEIVED %1 (type %2) packet received on interface %3
 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.  Note that a packet marked as UNKNOWN
 packet on the specified interface.  Note that a packet marked as UNKNOWN
 may well be a valid DHCP packet, just a type not expected by the server
 may well be a valid DHCP packet, just a type not expected by the server
 (e.g. it will report a received OFFER packet as UNKNOWN).
 (e.g. it will report a received OFFER packet as UNKNOWN).
 
 
+% DHCPV4_PACKET_SEND_FAIL failed to send DHCPv4 packet: %1
+This error is output if IPv6 DHCP server fails to send assembled DHCP
+message to a client. The reason for the error is included in the message.
+
 % DHCP4_PACK_FAIL failed to assemble response correctly
 % DHCP4_PACK_FAIL failed to assemble response correctly
 This error is output if the server failed to assemble the data to be
 This error is output if the server failed to assemble the data to be
 returned to the client into a valid packet.  The cause is most likely
 returned to the client into a valid packet.  The cause is most likely

+ 12 - 2
src/bin/dhcp4/dhcp4_srv.cc

@@ -73,9 +73,15 @@ Dhcpv4Srv::run() {
         int timeout = 1000;
         int timeout = 1000;
 
 
         // client's message and server's response
         // client's message and server's response
-        Pkt4Ptr query = IfaceMgr::instance().receive4(timeout);
+        Pkt4Ptr query;
         Pkt4Ptr rsp;
         Pkt4Ptr rsp;
 
 
+        try {
+            query = IfaceMgr::instance().receive4(timeout);
+        } catch (const std::exception& e) {
+            LOG_ERROR(dhcp4_logger, DHCP4_PACKET_RECEIVE_FAIL).arg(e.what());
+        }
+
         if (query) {
         if (query) {
             try {
             try {
                 query->unpack();
                 query->unpack();
@@ -141,7 +147,11 @@ Dhcpv4Srv::run() {
                           .arg(rsp->getType()).arg(rsp->toText());
                           .arg(rsp->getType()).arg(rsp->toText());
 
 
                 if (rsp->pack()) {
                 if (rsp->pack()) {
-                    IfaceMgr::instance().send(rsp);
+                    try {
+                        IfaceMgr::instance().send(rsp);
+                    } catch (const std::exception& ex) {
+                        LOG_ERROR(dhcp4_logger, DHCP4_PACKET_SEND_FAIL).arg(ex.what());
+                    }
                 } else {
                 } else {
                     LOG_ERROR(dhcp4_logger, DHCP4_PACK_FAIL);
                     LOG_ERROR(dhcp4_logger, DHCP4_PACK_FAIL);
                 }
                 }

+ 9 - 0
src/bin/dhcp6/dhcp6_messages.mes

@@ -45,12 +45,21 @@ server is about to open sockets on the specified port.
 % DHCP6_PACKET_PARSE_FAIL failed to parse incoming packet
 % DHCP6_PACKET_PARSE_FAIL failed to parse incoming packet
 The IPv6 DHCP server has received a packet that it is unable to interpret.
 The IPv6 DHCP server has received a packet that it is unable to interpret.
 
 
+% DHCP6_PACKET_RECEIVE_FAIL error on attempt to receive packet: %1
+The IPv6 DHCP server tried to receive a packet but unexpected error
+occured during this attempt. The reason for the error is included in
+the message.
+
 % DHCP6_PACKET_RECEIVED %1 (type %2) packet received
 % DHCP6_PACKET_RECEIVED %1 (type %2) packet received
 A debug message noting that the server has received the specified type
 A debug message noting that the server has received the specified type
 of packet.  Note that a packet marked as UNKNOWN may well be a valid
 of packet.  Note that a packet marked as UNKNOWN may well be a valid
 DHCP packet, just a type not expected by the server (e.g. it will report
 DHCP packet, just a type not expected by the server (e.g. it will report
 a received OFFER packet as UNKNOWN).
 a received OFFER packet as UNKNOWN).
 
 
+% DHCPV6_PACKET_SEND_FAIL failed to send DHCPv6 packet: %1
+This error is output if IPv6 DHCP server fails to send assembled DHCP
+message to a client. The reason fo the error is included in the message.
+
 % DHCP6_PACK_FAIL failed to assemble response correctly
 % DHCP6_PACK_FAIL failed to assemble response correctly
 This error is output if the server failed to assemble the data to be
 This error is output if the server failed to assemble the data to be
 returned to the client into a valid packet.  The reason is most likely
 returned to the client into a valid packet.  The reason is most likely

+ 12 - 2
src/bin/dhcp6/dhcp6_srv.cc

@@ -84,9 +84,15 @@ bool Dhcpv6Srv::run() {
         int timeout = 1000;
         int timeout = 1000;
 
 
         // client's message and server's response
         // client's message and server's response
-        Pkt6Ptr query = IfaceMgr::instance().receive6(timeout);
+        Pkt6Ptr query;
         Pkt6Ptr rsp;
         Pkt6Ptr rsp;
 
 
+        try {
+            query = IfaceMgr::instance().receive6(timeout);
+        } catch (const std::exception& ex) {
+            LOG_ERROR(dhcp6_logger, DHCP6_PACKET_RECEIVE_FAIL).arg(e.what());
+        }
+
         if (query) {
         if (query) {
             if (!query->unpack()) {
             if (!query->unpack()) {
                 LOG_DEBUG(dhcp6_logger, DBG_DHCP6_DETAIL,
                 LOG_DEBUG(dhcp6_logger, DBG_DHCP6_DETAIL,
@@ -154,7 +160,11 @@ bool Dhcpv6Srv::run() {
                           .arg(rsp->getType()).arg(rsp->toText());
                           .arg(rsp->getType()).arg(rsp->toText());
 
 
                 if (rsp->pack()) {
                 if (rsp->pack()) {
-                    IfaceMgr::instance().send(rsp);
+                    try {
+                        IfaceMgr::instance().send(rsp);
+                    } catch (const std::exception& ex) {
+                        LOG_ERROR(dhcp6_logger, DHCP6_PACKET_SEND_FAIL).arg(ex.what());
+                    }
                 } else {
                 } else {
                     LOG_ERROR(dhcp6_logger, DHCP6_PACK_FAIL);
                     LOG_ERROR(dhcp6_logger, DHCP6_PACK_FAIL);
                 }
                 }