]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1119] add server ID to perfdhcp DHCPRELEASEs
authorAndrei Pavel <andrei@isc.org>
Tue, 22 Jun 2021 08:15:16 +0000 (11:15 +0300)
committerAndrei Pavel <andrei@isc.org>
Tue, 22 Jun 2021 08:16:33 +0000 (11:16 +0300)
src/bin/perfdhcp/test_control.cc

index 996508ad870d96b9a326b56c9cf629e7f71e035d..dd7c37a160ead3a4994b5e4a602a530bc4ba412b 100644 (file)
@@ -189,6 +189,34 @@ TestControl::createMessageFromAck(const uint16_t msg_type,
     msg->setCiaddr(ack->getYiaddr());
     msg->setHWAddr(ack->getHWAddr());
     msg->addOption(generateClientId(msg->getHWAddr()));
+    if (msg_type == DHCPRELEASE) {
+        // RFC 2132: DHCPRELEASE MUST include server ID.
+        if (options_.isUseFirst()) {
+            // Honor the '-1' flag if it exists.
+            if (first_packet_serverid_.empty()) {
+                isc_throw(isc::BadValue,
+                          "Unable to create "
+                              << msg_type_str
+                              << "from the first packet which lacks the server "
+                                 "identifier option");
+            }
+            msg->addOption(Option::factory(Option::V4,
+                                           DHO_DHCP_SERVER_IDENTIFIER,
+                                           first_packet_serverid_));
+        } else {
+            // Otherwise take it from the DHCPACK message.
+            OptionPtr server_identifier(
+                ack->getOption(DHO_DHCP_SERVER_IDENTIFIER));
+            if (!server_identifier) {
+                isc_throw(isc::BadValue,
+                          "Unable to create "
+                              << msg_type_str
+                              << "from a DHCPACK message without the server "
+                                 "identifier option");
+            }
+            msg->addOption(server_identifier);
+        }
+    }
     return (msg);
 }