Browse Source

[4106] Added new exception Dhcp4o6IpcError.

Marcin Siodelski 9 years ago
parent
commit
e42ed52098

+ 7 - 7
src/lib/dhcpsrv/dhcp4o6_ipc.cc

@@ -47,7 +47,7 @@ int Dhcp4o6IpcBase::open(const uint16_t port, const int side) {
     // Open socket
     int sock = socket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP);
     if (sock < 0) {
-        isc_throw(Unexpected, "Failed to create DHCP4o6 socket.");
+        isc_throw(Dhcp4o6IpcError, "Failed to create DHCP4o6 socket.");
     }
 
     // Set reuse address
@@ -55,13 +55,13 @@ int Dhcp4o6IpcBase::open(const uint16_t port, const int side) {
     if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, static_cast<const void*>(&flag),
                    sizeof(flag)) < 0) {
         ::close(sock);
-        isc_throw(Unexpected, "Failed to set SO_REUSEADDR on DHCP4o6 socket.");
+        isc_throw(Dhcp4o6IpcError, "Failed to set SO_REUSEADDR on DHCP4o6 socket.");
     }
 
     // Set no blocking
     if (fcntl(sock, F_SETFL, O_NONBLOCK) < 0) {
         ::close(sock);
-        isc_throw(Unexpected, "Failed to set O_NONBLOCK on DHCP4o6 socket.");
+        isc_throw(Dhcp4o6IpcError, "Failed to set O_NONBLOCK on DHCP4o6 socket.");
     }
 
     // Bind to the local address
@@ -78,7 +78,7 @@ int Dhcp4o6IpcBase::open(const uint16_t port, const int side) {
     }
     if (bind(sock, (struct sockaddr *)&local6, sizeof(local6)) < 0) {
         ::close(sock);
-        isc_throw(Unexpected, "Failed to bind DHCP4o6 socket.");
+        isc_throw(Dhcp4o6IpcError, "Failed to bind DHCP4o6 socket.");
     }
 
     // Connect to the remote address
@@ -96,13 +96,13 @@ int Dhcp4o6IpcBase::open(const uint16_t port, const int side) {
     if (connect(sock, reinterpret_cast<const struct sockaddr*>(&remote6),
                 sizeof(remote6)) < 0) {
         ::close(sock);
-        isc_throw(Unexpected, "Failed to connect DHCP4o6 socket.");
+        isc_throw(Dhcp4o6IpcError, "Failed to connect DHCP4o6 socket.");
     }
 
     if (socket_fd_ != -1) {
         if (dup2(sock, socket_fd_) == -1) {
             ::close(sock);
-            isc_throw(Unexpected, "Failed to duplicate DHCP4o6 socket.");
+            isc_throw(Dhcp4o6IpcError, "Failed to duplicate DHCP4o6 socket.");
         }
         if (sock != socket_fd_) {
             ::close(sock);
@@ -129,7 +129,7 @@ Pkt6Ptr Dhcp4o6IpcBase::receive() {
     uint8_t buf[65536];
     ssize_t cc = recv(socket_fd_, buf, sizeof(buf), 0);
     if (cc < 0) {
-        isc_throw(Unexpected, "Failed to receive on DHCP4o6 socket.");
+        isc_throw(Dhcp4o6IpcError, "Failed to receive on DHCP4o6 socket.");
     }
     Pkt6Ptr pkt = Pkt6Ptr(new Pkt6(buf, cc));
     pkt->updateTimestamp();

+ 9 - 2
src/lib/dhcpsrv/dhcp4o6_ipc.h

@@ -19,15 +19,22 @@
 /// This file defines the class Kea uses as a base for
 /// DHCPv4-over-DHCPv6 communication between servers.
 ///
-#include <dhcp/pkt6.h>
 
+#include <exceptions/exceptions.h>
+#include <dhcp/pkt6.h>
 #include <boost/noncopyable.hpp>
-
 #include <stdint.h>
 
 namespace isc {
 namespace dhcp {
 
+/// @brief Exception thrown when error occurs as a result of use of IPC.
+class Dhcp4o6IpcError : public Exception {
+public:
+    Dhcp4o6IpcError(const char* file, size_t line, const char* what) :
+        isc::Exception(file, line, what) { };
+};
+
 /// @brief 
 ///
 class Dhcp4o6IpcBase : public boost::noncopyable {

+ 1 - 1
src/lib/dhcpsrv/tests/dhcp4o6_ipc_unittest.cc

@@ -327,7 +327,7 @@ TEST_F(Dhcp4o6IpcBaseTest, openError) {
     ASSERT_NE(-1, ipc_bound.getSocketFd());
 
     ipc.setDesiredPort(TEST_PORT + 10);
-    ASSERT_THROW(ipc.open(), isc::Unexpected);
+    ASSERT_THROW(ipc.open(), isc::dhcp::Dhcp4o6IpcError);
 
     EXPECT_EQ(sock_fd, ipc.getSocketFd());
     EXPECT_EQ(TEST_PORT, ipc.getPort());