From: Marcin Siodelski Date: Mon, 18 May 2015 14:34:20 +0000 (+0200) Subject: [3807] Pkt6::getType now returns all message types, including client side. X-Git-Tag: trac3732a_base~19^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5597704e052ef406098aeaac340cce81ac52a5ea;p=thirdparty%2Fkea.git [3807] Pkt6::getType now returns all message types, including client side. --- diff --git a/src/lib/dhcp/pkt4.h b/src/lib/dhcp/pkt4.h index 8dfa312d76..9d2b54334a 100644 --- a/src/lib/dhcp/pkt4.h +++ b/src/lib/dhcp/pkt4.h @@ -244,7 +244,7 @@ public: /// @param type message type to be set void setType(uint8_t type); - /// @brief Returns name of the DHCP message. + /// @brief Returns name of the DHCP message for a given type number. /// /// @param type DHCPv4 message type which name should be returned. /// diff --git a/src/lib/dhcp/pkt6.cc b/src/lib/dhcp/pkt6.cc index a62726fcce..8a8b93adee 100644 --- a/src/lib/dhcp/pkt6.cc +++ b/src/lib/dhcp/pkt6.cc @@ -562,17 +562,27 @@ Pkt6::getOptions(uint16_t opt_type) { const char* Pkt6::getName(const uint8_t type) { + static const char* ADVERTISE = "ADVERTISE"; static const char* CONFIRM = "CONFIRM"; static const char* DECLINE = "DECLINE"; static const char* INFORMATION_REQUEST = "INFORMATION_REQUEST"; + static const char* LEASEQUERY = "LEASEQUERY"; + static const char* LEASEQUERY_REPLY = "LEASEQUERY_REPLY"; static const char* REBIND = "REBIND"; + static const char* RECONFIGURE = "RECONFIGURE"; + static const char* RELAY_FORW = "RELAY_FORWARD"; + static const char* RELAY_REPL = "RELAY_REPLY"; static const char* RELEASE = "RELEASE"; static const char* RENEW = "RENEW"; + static const char* REPLY = "REPLY"; static const char* REQUEST = "REQUEST"; static const char* SOLICIT = "SOLICIT"; static const char* UNKNOWN = "UNKNOWN"; switch (type) { + case DHCPV6_ADVERTISE: + return (ADVERTISE); + case DHCPV6_CONFIRM: return (CONFIRM); @@ -582,15 +592,33 @@ Pkt6::getName(const uint8_t type) { case DHCPV6_INFORMATION_REQUEST: return (INFORMATION_REQUEST); + case DHCPV6_LEASEQUERY: + return (LEASEQUERY); + + case DHCPV6_LEASEQUERY_REPLY: + return (LEASEQUERY_REPLY); + case DHCPV6_REBIND: return (REBIND); + case DHCPV6_RECONFIGURE: + return (RECONFIGURE); + + case DHCPV6_RELAY_FORW: + return (RELAY_FORW); + + case DHCPV6_RELAY_REPL: + return (RELAY_REPL); + case DHCPV6_RELEASE: return (RELEASE); case DHCPV6_RENEW: return (RENEW); + case DHCPV6_REPLY: + return (REPLY); + case DHCPV6_REQUEST: return (REQUEST); diff --git a/src/lib/dhcp/pkt6.h b/src/lib/dhcp/pkt6.h index 92a63a9e53..febb92d35f 100644 --- a/src/lib/dhcp/pkt6.h +++ b/src/lib/dhcp/pkt6.h @@ -266,32 +266,27 @@ public: /// @param relay structure with necessary relay information void addRelayInfo(const RelayInfo& relay); - /// @brief Returns name of the DHCPv6 message. - /// - /// Returns the name of valid packet received by the server (e.g. SOLICIT). - /// If the packet is unknown - or if it is a valid DHCP packet but not one - /// expected to be received by the server (such as an ADVERTISE), the string - /// "UNKNOWN" is returned. This method is used in debug messages. + /// @brief Returns name of the DHCPv6 message for a given type number. /// /// As the operation of the method does not depend on any server state, it /// is declared static. There is also non-static getName() method that /// works on Pkt6 objects. /// - /// @param type DHCPv6 packet type + /// @param type DHCPv6 message type which name should be returned. /// - /// @return Pointer to "const" string containing the packet name. - /// Note that this string is statically allocated and MUST NOT - /// be freed by the caller. + /// @return Pointer to "const" string containing the message name. If + /// the message type is unknnown the "UNKNOWN" is returned. The caller + /// must not release the returned pointer. static const char* getName(const uint8_t type); - /// @brief returns textual representation of packet type. + /// @brief Returns name of the DHCPv6 message. /// /// This method requires an object. There is also static version, which /// requires one parameter (type). /// - /// @return Pointer to "const" string containing packet name. - /// Note that this string is statically allocated and MUST NOT - /// be freed by the caller. + /// @return Pointer to "const" string containing the message name. If + /// the message type is unknnown the "UNKNOWN" is returned. The caller + /// must not release the returned pointer. const char* getName() const; /// @brief copies relay information from client's packet to server's response diff --git a/src/lib/dhcp/tests/pkt6_unittest.cc b/src/lib/dhcp/tests/pkt6_unittest.cc index 6b8087bd2b..d015359765 100755 --- a/src/lib/dhcp/tests/pkt6_unittest.cc +++ b/src/lib/dhcp/tests/pkt6_unittest.cc @@ -509,6 +509,10 @@ TEST_F(Pkt6Test, getName) { uint8_t type = itype; switch (type) { + case DHCPV6_ADVERTISE: + EXPECT_STREQ("ADVERTISE", Pkt6::getName(type)); + break; + case DHCPV6_CONFIRM: EXPECT_STREQ("CONFIRM", Pkt6::getName(type)); break; @@ -522,10 +526,30 @@ TEST_F(Pkt6Test, getName) { Pkt6::getName(type)); break; + case DHCPV6_LEASEQUERY: + EXPECT_STREQ("LEASEQUERY", Pkt6::getName(type)); + break; + + case DHCPV6_LEASEQUERY_REPLY: + EXPECT_STREQ("LEASEQUERY_REPLY", Pkt6::getName(type)); + break; + case DHCPV6_REBIND: EXPECT_STREQ("REBIND", Pkt6::getName(type)); break; + case DHCPV6_RECONFIGURE: + EXPECT_STREQ("RECONFIGURE", Pkt6::getName(type)); + break; + + case DHCPV6_RELAY_FORW: + EXPECT_STREQ("RELAY_FORWARD", Pkt6::getName(type)); + break; + + case DHCPV6_RELAY_REPL: + EXPECT_STREQ("RELAY_REPLY", Pkt6::getName(type)); + break; + case DHCPV6_RELEASE: EXPECT_STREQ("RELEASE", Pkt6::getName(type)); break; @@ -534,6 +558,10 @@ TEST_F(Pkt6Test, getName) { EXPECT_STREQ("RENEW", Pkt6::getName(type)); break; + case DHCPV6_REPLY: + EXPECT_STREQ("REPLY", Pkt6::getName(type)); + break; + case DHCPV6_REQUEST: EXPECT_STREQ("REQUEST", Pkt6::getName(type)); break;