Parcourir la source

[3807] Pkt6::getType now returns all message types, including client side.

Marcin Siodelski il y a 10 ans
Parent
commit
5597704e05
4 fichiers modifiés avec 66 ajouts et 15 suppressions
  1. 1 1
      src/lib/dhcp/pkt4.h
  2. 28 0
      src/lib/dhcp/pkt6.cc
  3. 9 14
      src/lib/dhcp/pkt6.h
  4. 28 0
      src/lib/dhcp/tests/pkt6_unittest.cc

+ 1 - 1
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.
     ///

+ 28 - 0
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);
 

+ 9 - 14
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

+ 28 - 0
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;