From: Marcin Siodelski Date: Fri, 13 Feb 2015 12:01:38 +0000 (+0100) Subject: [3604] Addressed remaining review comments. X-Git-Tag: trac3712_base~9^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e7237625d206e6e8a4e39b195f1fd96954c7bfce;p=thirdparty%2Fkea.git [3604] Addressed remaining review comments. --- diff --git a/src/lib/dhcpsrv/cfg_iface.cc b/src/lib/dhcpsrv/cfg_iface.cc index 1d082faa70..9a6c816acd 100644 --- a/src/lib/dhcpsrv/cfg_iface.cc +++ b/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 diff --git a/src/lib/dhcpsrv/cfg_iface.h b/src/lib/dhcpsrv/cfg_iface.h index ec370dbea6..3a1a1cce82 100644 --- a/src/lib/dhcpsrv/cfg_iface.h +++ b/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. diff --git a/src/lib/dhcpsrv/parsers/ifaces_config_parser.cc b/src/lib/dhcpsrv/parsers/ifaces_config_parser.cc index ae2d0cd694..c335ba28f0 100644 --- a/src/lib/dhcpsrv/parsers/ifaces_config_parser.cc +++ b/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) { } diff --git a/src/lib/dhcpsrv/parsers/ifaces_config_parser.h b/src/lib/dhcpsrv/parsers/ifaces_config_parser.h index 207fe127d6..ac0b69f040 100644 --- a/src/lib/dhcpsrv/parsers/ifaces_config_parser.h +++ b/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". ///