[network-data] ensure ExternalRouteLookup() picks longest match (#8582)

This commit updates the `ExternalRouteLookup()` to ensure we pick
the longest match before checking the route preference.
This commit is contained in:
Abtin Keshavarzian
2022-12-28 17:09:30 -08:00
committed by GitHub
parent 60700b1562
commit 3aab651adc
+2 -1
View File
@@ -334,7 +334,8 @@ Error LeaderBase::ExternalRouteLookup(uint8_t aDomainId, const Ip6::Address &aDe
for (const HasRouteEntry *entry = hasRoute->GetFirstEntry(); entry <= hasRoute->GetLastEntry();
entry = entry->GetNext())
{
if (bestRouteEntry == nullptr || CompareRouteEntries(*entry, *bestRouteEntry) > 0)
if ((bestRouteEntry == nullptr) || (prefixLength > bestMatchLength) ||
CompareRouteEntries(*entry, *bestRouteEntry) > 0)
{
bestRouteEntry = entry;
bestMatchLength = prefixLength;