]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3440] Added design comment
authorFrancis Dupont <fdupont@isc.org>
Thu, 18 Jul 2024 09:31:24 +0000 (11:31 +0200)
committerFrancis Dupont <fdupont@isc.org>
Fri, 19 Jul 2024 15:49:52 +0000 (17:49 +0200)
src/lib/dhcp/libdhcp++.cc
src/lib/dhcp/tests/libdhcp++_unittest.cc

index 64ec288b026a56ae038dc6f471e1cae5a603c6d4..20b6cbda9dd4f1df65ce92f45a5810674fe4f33d 100644 (file)
@@ -485,8 +485,15 @@ LibDHCP::unpackOptions4(const OptionBuffer& buf, const string& option_space,
     // The buffer being read comprises a set of options, each starting with
     // a one-byte type code and a one-byte length field.
 
-    // Track seen options in a first pass.
+    // Track seen options in a first pass. We use 2 different data structures
+    // (seen and counts) because this code is in the critical path and
+    // having more than one instance of an option is a very rare case.
+
+    // Record if an option was already seen using the most efficient
+    // data structure for this goal.
     vector<bool> seen(256, false);
+    // Handle the very rare case where an option is more than once in the
+    // input buffer, in other / common case it stays empty.
     unordered_map<uint8_t, size_t> counts;
     while (offset < buf.size()) {
         // Get the option type
index 0d275ec450c086707c926e523f5a772eadf2d433..f2926430142e8ab53ebb000d562b95b94f626098 100644 (file)
@@ -1358,7 +1358,7 @@ TEST_F(LibDhcpTest, splitOptionWithSuboptionWhichOverflow) {
                                                        RAI_OPTION_SUBSCRIBER_ID,
                                                        buf_in.begin(),
                                                        buf_in.end()));
-ASSERT_TRUE(subscriber_id_opt);
+    ASSERT_TRUE(subscriber_id_opt);
     rai->addOption(subscriber_id_opt);
 
     splitOptionWithSuboptionWhichOverflow(rai, circuit_id_opt, remote_id_opt, subscriber_id_opt);