Skip to content

Commit

Permalink
Update non-LL interface for the dedup logic as well
Browse files Browse the repository at this point in the history
  • Loading branch information
andreilitvin committed Dec 17, 2024
1 parent 7346411 commit a0b84f8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/lib/address_resolve/AddressResolve_DefaultImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* limitations under the License.
*/

#include "transport/raw/PeerAddress.h"
#include <lib/address_resolve/AddressResolve_DefaultImpl.h>

#include <lib/address_resolve/TracingStructs.h>
Expand Down Expand Up @@ -128,6 +129,17 @@ NodeLookupAction NodeLookupHandle::NextAction(System::Clock::Timestamp now)

bool NodeLookupResults::UpdateResults(const ResolveResult & result, const Dnssd::IPAddressSorter::IpScore newScore)
{
Transport::PeerAddress addressWithAdjustedInterface = result.address;
if (!addressWithAdjustedInterface.GetIPAddress().IsIPv6LinkLocal())
{
// Only use the DNS-SD resolution's InterfaceID for addresses that are IPv6 LLA.
// For all other addresses, we should rely on the device's routing table to route messages sent.
// Forcing messages down an InterfaceId might fail. For example, in bridged networks like Thread,
// mDNS advertisements are not usually received on the same interface the peer is reachable on.
addressWithAdjustedInterface.SetInterface(Inet::InterfaceId::Null());
ChipLogDetail(Discovery, "Lookup clearing interface for non LL address");
}

uint8_t insertAtIndex = 0;
for (; insertAtIndex < kNodeLookupResultsLen; insertAtIndex++)
{
Expand All @@ -139,7 +151,7 @@ bool NodeLookupResults::UpdateResults(const ResolveResult & result, const Dnssd:

auto & oldAddress = results[insertAtIndex].address;

if (oldAddress == result.address)
if (oldAddress == addressWithAdjustedInterface)
{
// this address is already in our list.
return false;
Expand Down Expand Up @@ -179,17 +191,9 @@ bool NodeLookupResults::UpdateResults(const ResolveResult & result, const Dnssd:
count++;
}

auto & updatedResult = results[insertAtIndex];
updatedResult = result;
if (!updatedResult.address.GetIPAddress().IsIPv6LinkLocal())
{
// Only use the DNS-SD resolution's InterfaceID for addresses that are IPv6 LLA.
// For all other addresses, we should rely on the device's routing table to route messages sent.
// Forcing messages down an InterfaceId might fail. For example, in bridged networks like Thread,
// mDNS advertisements are not usually received on the same interface the peer is reachable on.
updatedResult.address.SetInterface(Inet::InterfaceId::Null());
ChipLogDetail(Discovery, "Lookup clearing interface for non LL address");
}
auto & updatedResult = results[insertAtIndex];
updatedResult = result;
updatedResult.address = addressWithAdjustedInterface;

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ using chip::Dnssd::IPAddressSorter::ScoreIpAddress;

constexpr uint8_t kNumberOfAvailableSlots = CHIP_CONFIG_MDNS_RESOLVE_LOOKUP_RESULTS;

/// Get an address that should have `kUniqueLocal` (one of the lowest) priority.
///
/// Since for various tests we check filling the cache with values, we allow
/// unique address generation by varying the `idx` parameter
///
/// @param idx - a value to generate a unique IP address (in case we do not wand dedups)
/// @param port - port in case some tests would like to vary it. Required for PeerAddress
/// @param interfaceId - interface required for PeerAddress
Transport::PeerAddress GetAddressWithLowScore(uint16_t idx = 4, uint16_t port = CHIP_PORT,
Inet::InterfaceId interfaceId = Inet::InterfaceId::Null())
{
Expand Down

0 comments on commit a0b84f8

Please sign in to comment.