From: Francis Dupont Date: Thu, 18 Jul 2024 09:31:24 +0000 (+0200) Subject: [#3440] Added design comment X-Git-Tag: Kea-2.7.1~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=fdbcd4eeb443138a09564964fdf644be29afdef2;p=thirdparty%2Fkea.git [#3440] Added design comment --- 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 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 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);