From ed8d74879a1cfd79715d2384d4f67fa3d121a75c Mon Sep 17 00:00:00 2001 From: Tommaso Pecorella Date: Sun, 10 Oct 2021 00:09:00 +0200 Subject: [PATCH] internet: Fix src address selection for localhost --- src/internet/model/ipv6-l3-protocol.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/internet/model/ipv6-l3-protocol.cc b/src/internet/model/ipv6-l3-protocol.cc index edf5f60b8..e3f68c8ed 100644 --- a/src/internet/model/ipv6-l3-protocol.cc +++ b/src/internet/model/ipv6-l3-protocol.cc @@ -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; }