Skip to content

Commit cf57a6b

Browse files
Stop forcing a particular interface ID when sending response messages.
Because we were storing the PeerAddress in the session when getting a message, we effectively pinned sessions to particular interface ids at that point. This can lead to routing failures. We should only be pinning to interface IDs for link-local addresses, just like we do for initial IP resolution via DNS-SD.
1 parent 84970a0 commit cf57a6b

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/transport/SessionManager.cpp

+21-6
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,20 @@ using Transport::SecureSession;
5757

5858
namespace {
5959
Global<GroupPeerTable> gGroupPeerTable;
60+
61+
// Helper function that strips off the interface ID from a peer address that is
62+
// not an IPv6 link-local address. For any other address type we should rely on
63+
// the device's routing table to route messages sent. Forcing messages down a
64+
// specific interface might fail with "no route to host".
65+
void CorrectPeerAddressInterfaceID(Transport::PeerAddress & peerAddress)
66+
{
67+
if (peerAddress.GetIPAddress().IsIPv6LinkLocal())
68+
{
69+
return;
70+
}
71+
peerAddress.SetInterface(Inet::InterfaceId::Null());
72+
}
73+
6074
} // namespace
6175

6276
uint32_t EncryptedPacketBufferHandle::GetMessageCounter() const
@@ -633,7 +647,9 @@ void SessionManager::UnauthenticatedMessageDispatch(const PacketHeader & partial
633647

634648
const SessionHandle & session = optionalSession.Value();
635649
Transport::UnauthenticatedSession * unsecuredSession = session->AsUnauthenticatedSession();
636-
unsecuredSession->SetPeerAddress(peerAddress);
650+
Transport::PeerAddress mutablePeerAddress = peerAddress;
651+
CorrectPeerAddressInterfaceID(mutablePeerAddress);
652+
unsecuredSession->SetPeerAddress(mutablePeerAddress);
637653
SessionMessageDelegate::DuplicateMessage isDuplicate = SessionMessageDelegate::DuplicateMessage::No;
638654

639655
unsecuredSession->MarkActiveRx();
@@ -766,12 +782,11 @@ void SessionManager::SecureUnicastMessageDispatch(const PacketHeader & partialPa
766782
secureSession->GetSessionMessageCounter().GetPeerMessageCounter().CommitEncryptedUnicast(packetHeader.GetMessageCounter());
767783
}
768784

769-
// TODO: once mDNS address resolution is available reconsider if this is required
770-
// This updates the peer address once a packet is received from a new address
771-
// and serves as a way to auto-detect peer changing IPs.
772-
if (secureSession->GetPeerAddress() != peerAddress)
785+
Transport::PeerAddress mutablePeerAddress = peerAddress;
786+
CorrectPeerAddressInterfaceID(mutablePeerAddress);
787+
if (secureSession->GetPeerAddress() != mutablePeerAddress)
773788
{
774-
secureSession->SetPeerAddress(peerAddress);
789+
secureSession->SetPeerAddress(mutablePeerAddress);
775790
}
776791

777792
if (mCB != nullptr)

0 commit comments

Comments
 (0)