Browse Source

[3604] Improved logging for socket type selection.

Marcin Siodelski 10 years ago
parent
commit
832d041938

+ 2 - 2
src/lib/dhcpsrv/cfg_iface.cc

@@ -61,8 +61,6 @@ CfgIface::openSockets(const uint16_t family, const uint16_t port,
     // sockets. However, this may be unsupported on some operating
     // systems, so there is no guarantee.
     if ((family == AF_INET) && (!IfaceMgr::instance().isTestMode())) {
-        LOG_INFO(dhcpsrv_logger, DHCPSRV_CFGMGR_SOCKET_TYPE_SELECT)
-            .arg(socketTypeToText());
         iface_mgr.setMatchingPacketFilter(socket_type_ == SOCKET_RAW);
         if ((socket_type_ == SOCKET_RAW) &&
             !iface_mgr.isDirectResponseSupported()) {
@@ -358,6 +356,8 @@ CfgIface::useSocketType(const uint16_t family,
                   " the DHCPv6 server");
     }
     socket_type_ = socket_type;
+    LOG_INFO(dhcpsrv_logger, DHCPSRV_CFGMGR_SOCKET_TYPE_SELECT)
+        .arg(socketTypeToText());
 }
 
 void

+ 3 - 3
src/lib/dhcpsrv/cfg_iface.h

@@ -198,6 +198,9 @@ public:
     void useSocketType(const uint16_t family,
                        const std::string& socket_type_name);
 
+    /// @brief Returns the socket type in the textual format.
+    std::string socketTypeToText() const;
+
     /// @brief Equality operator.
     ///
     /// @param other Object to be compared with this object.
@@ -242,9 +245,6 @@ private:
     /// @param errmsg Error message being logged by the function.
     static void socketOpenErrorHandler(const std::string& errmsg);
 
-    /// @brief Returns the socket type in the textual format.
-    std::string socketTypeToText() const;
-
     /// @brief Represents a set of interface names.
     typedef std::set<std::string> IfaceSet;
 

+ 6 - 1
src/lib/dhcpsrv/dhcpsrv_messages.mes

@@ -99,6 +99,11 @@ This is a debug message reporting that the DHCP configuration manager has
 returned the specified IPv6 subnet when given the address hint specified
 because it is the only subnet defined.
 
+% DHCPSRV_CFGMGR_SOCKET_TYPE_DEFAULT "socket-type" not specified , using default socket type %1
+This informational message is logged when the administrator hasn't
+specified the "socket-type" parameter in configuration for interfaces.
+In such case, the default socket type will be used.
+
 % DHCPSRV_CFGMGR_SOCKET_RAW_UNSUPPORTED use of raw sockets is unsupported on this OS, datagram sockets will be used
 This warning message is logged when the user specified that the
 DHCPv4 server should use the raw sockets to receive the DHCP
@@ -111,7 +116,7 @@ back to use of the datagram IP/UDP sockets. The responses to
 the directly connected clients will be broadcast. The responses
 to relayed clients will be unicast as usual.
 
-% DHCPSRV_CFGMGR_SOCKET_TYPE_SELECT trying to use socket type %1
+% DHCPSRV_CFGMGR_SOCKET_TYPE_SELECT using socket type %1
 This informational message is logged when the DHCPv4 server selects the
 socket type to be used for all sockets that will be opened on the
 interfaces. Typically, the socket type is specified by the server

+ 10 - 4
src/lib/dhcpsrv/parsers/ifaces_config_parser.cc

@@ -14,6 +14,7 @@
 
 #include <cc/data.h>
 #include <dhcpsrv/cfgmgr.h>
+#include <dhcpsrv/dhcpsrv_log.h>
 #include <dhcpsrv/parsers/ifaces_config_parser.h>
 #include <boost/foreach.hpp>
 #include <string>
@@ -88,14 +89,12 @@ IfacesConfigParser4::build(isc::data::ConstElementPtr ifaces_config) {
 
     // Get the pointer to the interface configuration.
     CfgIfacePtr cfg = CfgMgr::instance().getStagingCfg()->getCfgIface();
-    // The default is to use the raw sockets, if the "socket-type" parameter
-    // hasn't been specified.
-    cfg->useSocketType(AF_INET, CfgIface::SOCKET_RAW);
-
+    bool socket_type_specified = false;
     BOOST_FOREACH(ConfigPair element, ifaces_config->mapValue()) {
         try {
             if (element.first == "socket-type") {
                 cfg->useSocketType(AF_INET, element.second->stringValue());
+                socket_type_specified = true;
 
             } else if (!isGenericParameter(element.first)) {
                 isc_throw(DhcpConfigError, "usupported parameter '"
@@ -108,6 +107,13 @@ IfacesConfigParser4::build(isc::data::ConstElementPtr ifaces_config) {
                       << element.second->getPosition() << ")");
         }
     }
+
+    // User hasn't specified the socket type. Log that we are using
+    // the default type.
+    if (!socket_type_specified) {
+        LOG_INFO(dhcpsrv_logger, DHCPSRV_CFGMGR_SOCKET_TYPE_DEFAULT)
+            .arg(cfg->socketTypeToText());
+    }
 }
 
 IfacesConfigParser6::IfacesConfigParser6()

+ 4 - 0
src/lib/dhcpsrv/tests/cfg_iface_unittest.cc

@@ -358,21 +358,25 @@ TEST(CfgIfaceNoStubTest, useSocketType) {
     CfgIface cfg;
     // Select datagram sockets.
     ASSERT_NO_THROW(cfg.useSocketType(AF_INET, "datagram"));
+    EXPECT_EQ("datagram", cfg.socketTypeToText());
     ASSERT_NO_THROW(cfg.openSockets(AF_INET, 10067, true));
     // For datagram sockets, the direct traffic is not supported.
     ASSERT_TRUE(!IfaceMgr::instance().isDirectResponseSupported());
 
     // Select raw sockets.
     ASSERT_NO_THROW(cfg.useSocketType(AF_INET, "raw"));
+    EXPECT_EQ("raw", cfg.socketTypeToText());
     ASSERT_NO_THROW(cfg.openSockets(AF_INET, 10067, true));
     // For raw sockets, the direct traffic is supported.
     ASSERT_TRUE(IfaceMgr::instance().isDirectResponseSupported());
 
     ASSERT_NO_THROW(cfg.useSocketType(AF_INET, CfgIface::SOCKET_DGRAM));
+    EXPECT_EQ("datagram", cfg.socketTypeToText());
     ASSERT_NO_THROW(cfg.openSockets(AF_INET, 10067, true));
     ASSERT_TRUE(!IfaceMgr::instance().isDirectResponseSupported());
 
     ASSERT_NO_THROW(cfg.useSocketType(AF_INET, CfgIface::SOCKET_RAW));
+    EXPECT_EQ("raw", cfg.socketTypeToText());
     ASSERT_NO_THROW(cfg.openSockets(AF_INET, 10067, true));
     ASSERT_TRUE(IfaceMgr::instance().isDirectResponseSupported());