internet: Fix src address selection for localhost

This commit is contained in:
Tommaso Pecorella
2021-10-10 00:09:00 +02:00
parent 24f73cc470
commit ed8d74879a

View File

@@ -601,6 +601,11 @@ Ipv6Address Ipv6L3Protocol::SourceAddressSelection (uint32_t interface, Ipv6Addr
NS_LOG_FUNCTION (this << interface << dest);
Ipv6Address ret;
if (dest.IsLocalhost ())
{
return Ipv6Address::GetLoopback ();
}
if (dest.IsLinkLocal () || dest.IsLinkLocalMulticast ())
{
for (uint32_t i = 0; i < GetNAddresses (interface); i++)
@@ -632,6 +637,8 @@ Ipv6Address Ipv6L3Protocol::SourceAddressSelection (uint32_t interface, Ipv6Addr
}
// no specific match found. Use a global address (any useful is fine).
NS_ASSERT_MSG (!ret.IsAny (),
"Could not find any address for " << dest << " on interface " << interface);
return ret;
}