Browse Source

[3437] Addressed review comments.

Marcin Siodelski 11 years ago
parent
commit
99046c3b8d

+ 7 - 0
doc/examples/kea6/several-subnets.json

@@ -8,6 +8,13 @@
 # Kea is told to listen on eth0 interface only.
 # Kea is told to listen on eth0 interface only.
   "interfaces": [ "eth0" ],
   "interfaces": [ "eth0" ],
 
 
+# We need to specify lease type. As of May 2014, three backends are supported:
+# memfile, mysql and pgsql. We'll just use memfile, because it doesn't require
+# any prior set up.
+  "lease-database": {
+    "type": "memfile"
+  },
+
 # Addresses will be assigned with preferred and valid lifetimes
 # Addresses will be assigned with preferred and valid lifetimes
 # being 3000 and 4000, respectively. Client is told to start
 # being 3000 and 4000, respectively. Client is told to start
 # renewing after 1000 seconds. If the server does not repond
 # renewing after 1000 seconds. If the server does not repond

+ 3 - 11
src/bin/dhcp4/dhcp4_srv.cc

@@ -90,10 +90,9 @@ Dhcpv4Srv::Dhcpv4Srv(uint16_t port, const bool use_bcast,
 
 
     LOG_DEBUG(dhcp4_logger, DBG_DHCP4_START, DHCP4_OPEN_SOCKET).arg(port);
     LOG_DEBUG(dhcp4_logger, DBG_DHCP4_START, DHCP4_OPEN_SOCKET).arg(port);
     try {
     try {
-        // Open sockets only if port is non-zero. Port 0 is used for testing
-        // purposes in two cases:
-        // - when non-socket related testing is performed
-        // - when the particular test supplies its own packet filtering class.
+        // Port 0 is used for testing purposes where we don't open broadcast
+        // capable sockets. So, set the packet filter handling direct traffic
+        // only if we are in non-test mode.
         if (port) {
         if (port) {
             // First call to instance() will create IfaceMgr (it's a singleton)
             // First call to instance() will create IfaceMgr (it's a singleton)
             // it may throw something if things go wrong.
             // it may throw something if things go wrong.
@@ -103,13 +102,6 @@ Dhcpv4Srv::Dhcpv4Srv(uint16_t port, const bool use_bcast,
             // may be lacking on some OSes, so there is no guarantee that server
             // may be lacking on some OSes, so there is no guarantee that server
             // will be able to respond directly.
             // will be able to respond directly.
             IfaceMgr::instance().setMatchingPacketFilter(direct_response_desired);
             IfaceMgr::instance().setMatchingPacketFilter(direct_response_desired);
-
-            // Create error handler. This handler will be called every time
-            // the socket opening operation fails. We use this handler to
-            // log a warning.
-            isc::dhcp::IfaceMgrErrorMsgCallback error_handler =
-                boost::bind(&Dhcpv4Srv::ifaceMgrSocket4ErrorHandler, _1);
-            IfaceMgr::instance().openSockets4(port_, use_bcast_, error_handler);
         }
         }
 
 
         // Instantiate allocation engine
         // Instantiate allocation engine

+ 6 - 15
src/bin/dhcp6/dhcp6_srv.cc

@@ -122,21 +122,12 @@ Dhcpv6Srv::Dhcpv6Srv(uint16_t port)
 
 
     // Initialize objects required for DHCP server operation.
     // Initialize objects required for DHCP server operation.
     try {
     try {
-        // Port 0 is used for testing purposes. It means that the server should
-        // not open any sockets at all. Some tests, e.g. configuration parser,
-        // require Dhcpv6Srv object, but they don't really need it to do
-        // anything. This speed up and simplifies the tests.
-        if (port > 0) {
-            if (IfaceMgr::instance().countIfaces() == 0) {
-                LOG_ERROR(dhcp6_logger, DHCP6_NO_INTERFACES);
-                return;
-            }
-            // Create error handler. This handler will be called every time
-            // the socket opening operation fails. We use this handler to
-            // log a warning.
-            isc::dhcp::IfaceMgrErrorMsgCallback error_handler =
-                boost::bind(&Dhcpv6Srv::ifaceMgrSocket6ErrorHandler, _1);
-            IfaceMgr::instance().openSockets6(port_, error_handler);
+        // Port 0 is used for testing purposes where in most cases we don't
+        // rely on the physical interfaces. Therefore, it should be possible
+        // to create an object even when there are no usable interfaces.
+        if ((port > 0) && (IfaceMgr::instance().countIfaces() == 0)) {
+            LOG_ERROR(dhcp6_logger, DHCP6_NO_INTERFACES);
+            return;
         }
         }
 
 
         string duid_file = CfgMgr::instance().getDataDir() + "/" + string(SERVER_DUID_FILE);
         string duid_file = CfgMgr::instance().getDataDir() + "/" + string(SERVER_DUID_FILE);

+ 8 - 2
src/lib/dhcp/pkt_filter.cc

@@ -41,21 +41,27 @@ PktFilter::openFallbackSocket(const isc::asiolink::IOAddress& addr,
 
 
     if (bind(sock, reinterpret_cast<struct sockaddr*>(&addr4),
     if (bind(sock, reinterpret_cast<struct sockaddr*>(&addr4),
              sizeof(addr4)) < 0) {
              sizeof(addr4)) < 0) {
+        // Get the error message immediately after the bind because the
+        // invocation to close() below would override the errno.
+        char* errmsg = strerror(errno);
         // Remember to close the socket if we failed to bind it.
         // Remember to close the socket if we failed to bind it.
         close(sock);
         close(sock);
         isc_throw(SocketConfigError, "failed to bind fallback socket to"
         isc_throw(SocketConfigError, "failed to bind fallback socket to"
                   " address " << addr << ", port " << port
                   " address " << addr << ", port " << port
-                  << ", reason: " << strerror(errno)
+                  << ", reason: " << errmsg
                   << " - is another DHCP server running?");
                   << " - is another DHCP server running?");
     }
     }
 
 
     // Set socket to non-blocking mode. This is to prevent the read from the
     // Set socket to non-blocking mode. This is to prevent the read from the
     // fallback socket to block message processing on the primary socket.
     // fallback socket to block message processing on the primary socket.
     if (fcntl(sock, F_SETFL, O_NONBLOCK) != 0) {
     if (fcntl(sock, F_SETFL, O_NONBLOCK) != 0) {
+        // Get the error message immediately after the bind because the
+        // invocation to close() below would override the errno.
+        char* errmsg = strerror(errno);
         close(sock);
         close(sock);
         isc_throw(SocketConfigError, "failed to set SO_NONBLOCK option on the"
         isc_throw(SocketConfigError, "failed to set SO_NONBLOCK option on the"
                   " fallback socket, bound to " << addr << ", port "
                   " fallback socket, bound to " << addr << ", port "
-                  << port << ", reason: " << strerror(errno));
+                  << port << ", reason: " << errmsg);
     }
     }
     // Successfully created and bound a fallback socket. Return a descriptor.
     // Successfully created and bound a fallback socket. Return a descriptor.
     return (sock);
     return (sock);

+ 4 - 2
src/lib/dhcp/pkt_filter_inet6.cc

@@ -74,11 +74,13 @@ PktFilterInet6::openSocket(const Iface& iface,
     }
     }
 
 
     if (bind(sock, (struct sockaddr *)&addr6, sizeof(addr6)) < 0) {
     if (bind(sock, (struct sockaddr *)&addr6, sizeof(addr6)) < 0) {
+        // Get the error message immediately after the bind because the
+        // invocation to close() below would override the errno.
+        char* errmsg = strerror(errno);
         close(sock);
         close(sock);
-        std::cout << errno << std::endl;
         isc_throw(SocketConfigError, "Failed to bind socket " << sock << " to "
         isc_throw(SocketConfigError, "Failed to bind socket " << sock << " to "
                   << addr.toText() << "/port=" << port
                   << addr.toText() << "/port=" << port
-                  << ": " << strerror(errno));
+                  << ": " << errmsg);
     }
     }
 #ifdef IPV6_RECVPKTINFO
 #ifdef IPV6_RECVPKTINFO
     // RFC3542 - a new way
     // RFC3542 - a new way