diff options
author | Francis Dupont <fdupont@isc.org> | 2024-07-18 11:31:24 +0200 |
---|---|---|
committer | Francis Dupont <fdupont@isc.org> | 2024-07-19 17:49:52 +0200 |
commit | fdbcd4eeb443138a09564964fdf644be29afdef2 (patch) | |
tree | fc9aeb2b0ca5aa5ecad4016a8fa1584f99d10a80 | |
parent | [#3440] Added an empty check (diff) | |
download | kea-fdbcd4eeb443138a09564964fdf644be29afdef2.tar.xz kea-fdbcd4eeb443138a09564964fdf644be29afdef2.zip |
[#3440] Added design comment
-rw-r--r-- | src/lib/dhcp/libdhcp++.cc | 9 | ||||
-rw-r--r-- | src/lib/dhcp/tests/libdhcp++_unittest.cc | 2 |
2 files changed, 9 insertions, 2 deletions
diff --git a/src/lib/dhcp/libdhcp++.cc b/src/lib/dhcp/libdhcp++.cc index 64ec288b02..20b6cbda9d 100644 --- a/src/lib/dhcp/libdhcp++.cc +++ b/src/lib/dhcp/libdhcp++.cc @@ -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 diff --git a/src/lib/dhcp/tests/libdhcp++_unittest.cc b/src/lib/dhcp/tests/libdhcp++_unittest.cc index 0d275ec450..f292643014 100644 --- a/src/lib/dhcp/tests/libdhcp++_unittest.cc +++ b/src/lib/dhcp/tests/libdhcp++_unittest.cc @@ -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); |