Browse Source

[2765] Fixed error handling in the IfaceMgr::openSockets4.

Marcin Siodelski 11 years ago
parent
commit
5b9c261d8b
1 changed files with 9 additions and 5 deletions
  1. 9 5
      src/lib/dhcp/iface_mgr.cc

+ 9 - 5
src/lib/dhcp/iface_mgr.cc

@@ -295,7 +295,6 @@ void IfaceMgr::stubDetectIfaces() {
 bool
 bool
 IfaceMgr::openSockets4(const uint16_t port, const bool use_bcast,
 IfaceMgr::openSockets4(const uint16_t port, const bool use_bcast,
                        IfaceMgrErrorMsgCallback error_handler) {
                        IfaceMgrErrorMsgCallback error_handler) {
-    int sock;
     int count = 0;
     int count = 0;
 
 
 // This option is used to bind sockets to particular interfaces.
 // This option is used to bind sockets to particular interfaces.
@@ -332,6 +331,7 @@ IfaceMgr::openSockets4(const uint16_t port, const bool use_bcast,
                 continue;
                 continue;
             }
             }
 
 
+            int sock = -1;
             // If selected interface is broadcast capable set appropriate
             // If selected interface is broadcast capable set appropriate
             // options on the socket so as it can receive and send broadcast
             // options on the socket so as it can receive and send broadcast
             // messages.
             // messages.
@@ -347,6 +347,7 @@ IfaceMgr::openSockets4(const uint16_t port, const bool use_bcast,
                                             " listen broadcast traffic on a"
                                             " listen broadcast traffic on a"
                                             " single interface",
                                             " single interface",
                                             error_handler);
                                             error_handler);
+                    continue;
 
 
                 } else {
                 } else {
                     try {
                     try {
@@ -356,6 +357,7 @@ IfaceMgr::openSockets4(const uint16_t port, const bool use_bcast,
                                           true, true);
                                           true, true);
                     } catch (const Exception& ex) {
                     } catch (const Exception& ex) {
                         handleSocketConfigError(ex.what(), error_handler);
                         handleSocketConfigError(ex.what(), error_handler);
+                        continue;
 
 
                     }
                     }
                     // Binding socket to an interface is not supported so we
                     // Binding socket to an interface is not supported so we
@@ -373,17 +375,19 @@ IfaceMgr::openSockets4(const uint16_t port, const bool use_bcast,
                                       false, false);
                                       false, false);
                 } catch (const Exception& ex) {
                 } catch (const Exception& ex) {
                     handleSocketConfigError(ex.what(), error_handler);
                     handleSocketConfigError(ex.what(), error_handler);
+                    continue;
                 }
                 }
 
 
             }
             }
             if (sock < 0) {
             if (sock < 0) {
                 const char* errstr = strerror(errno);
                 const char* errstr = strerror(errno);
-                isc_throw(SocketConfigError, "failed to open IPv4 socket"
-                          << " supporting broadcast traffic, reason:"
-                          << errstr);
+                handleSocketConfigError(std::string("failed to open IPv4 socket,"
+                                                    " reason:") + errstr,
+                                        error_handler);
+            } else {
+                ++count;
             }
             }
 
 
-            count++;
         }
         }
     }
     }
     return (count > 0);
     return (count > 0);