Parcourir la source

[3604] Addressed remaining review comments.

Marcin Siodelski il y a 10 ans
Parent
commit
e7237625d2

+ 15 - 12
src/lib/dhcpsrv/cfg_iface.cc

@@ -202,6 +202,20 @@ CfgIface::socketTypeToText() const {
     isc_throw(Unexpected, "unsupported socket type " << socket_type_);
 }
 
+CfgIface::SocketType
+CfgIface::textToSocketType(const std::string& socket_type_name) const {
+    if (socket_type_name == "udp") {
+        return (SOCKET_UDP);
+
+    } else if (socket_type_name == "raw") {
+        return (SOCKET_RAW);
+
+    } else {
+        isc_throw(InvalidSocketType, "unsupported socket type '"
+                  << socket_type_name << "'");
+    }
+}
+
 void
 CfgIface::use(const uint16_t family, const std::string& iface_name) {
     // The interface name specified may have two formats, e.g.:
@@ -363,18 +377,7 @@ CfgIface::useSocketType(const uint16_t family,
 void
 CfgIface::useSocketType(const uint16_t family,
                         const std::string& socket_type_name) {
-    SocketType socket_type;
-    if (socket_type_name == "udp") {
-        socket_type = SOCKET_UDP;
-
-    } else if (socket_type_name == "raw") {
-        socket_type = SOCKET_RAW;
-
-    } else {
-        isc_throw(InvalidSocketType, "unsupported socket type '"
-                  << socket_type_name << "'");
-    }
-    useSocketType(family, socket_type);
+    useSocketType(family, textToSocketType(socket_type_name));
 }
 
 } // end of isc::dhcp namespace

+ 11 - 0
src/lib/dhcpsrv/cfg_iface.h

@@ -174,6 +174,10 @@ public:
 
     /// @brief Sets the specified socket type to be used by the server.
     ///
+    /// Supported socket types for DHCPv4 are:
+    /// - @c SOCKET_RAW
+    /// - @c SOCKET_UDP
+    ///
     /// @param family Address family (AF_INET or AF_INET6).
     /// @param socket_type Socket type.
     ///
@@ -201,6 +205,13 @@ public:
     /// @brief Returns the socket type in the textual format.
     std::string socketTypeToText() const;
 
+    /// @brief Converts the socket type in the textual format to the type
+    /// represented by the @c SocketType.
+    ///
+    /// @throw InvalidSocketType if the specified value of the @c socket_type_name
+    /// is invalid.
+    SocketType textToSocketType(const std::string& socket_type_name) const;
+
     /// @brief Equality operator.
     ///
     /// @param other Object to be compared with this object.

+ 2 - 2
src/lib/dhcpsrv/parsers/ifaces_config_parser.cc

@@ -25,7 +25,7 @@ using namespace isc::data;
 namespace isc {
 namespace dhcp {
 
-InterfaceListConfigParser::InterfaceListConfigParser(const int protocol)
+InterfaceListConfigParser::InterfaceListConfigParser(const uint16_t protocol)
     : protocol_(protocol) {
 }
 
@@ -50,7 +50,7 @@ InterfaceListConfigParser::commit() {
     // Nothing to do.
 }
 
-IfacesConfigParser::IfacesConfigParser(const int protocol)
+IfacesConfigParser::IfacesConfigParser(const uint16_t protocol)
     : protocol_(protocol) {
 }
 

+ 3 - 5
src/lib/dhcpsrv/parsers/ifaces_config_parser.h

@@ -34,9 +34,7 @@ public:
     /// @brief Constructor
     ///
     /// @param protocol AF_INET for DHCPv4 and AF_INET6 for DHCPv6.
-    ///
-    /// @throw BadValue if supplied parameter name is not "interface"
-    InterfaceListConfigParser(const int protocol);
+    InterfaceListConfigParser(const uint16_t protocol);
 
     /// @brief Parses a list of interface names.
     ///
@@ -59,7 +57,7 @@ public:
 private:
 
     /// @brief AF_INET for DHCPv4 and AF_INET6 for DHCPv6.
-    int protocol_;
+    uint16_t protocol_;
 
 };
 
@@ -82,7 +80,7 @@ public:
     /// @brief Constructor
     ///
     /// @param protocol AF_INET for DHCPv4 and AF_INET6 for DHCPv6.
-    IfacesConfigParser(const int protocol);
+    IfacesConfigParser(const uint16_t protocol);
 
     /// @brief Parses generic parameters in "interfaces-config".
     ///