Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop forcing a particular interface ID when sending response messages. #32581

Merged
merged 1 commit into from
Mar 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions src/transport/SessionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ using Transport::SecureSession;

namespace {
Global<GroupPeerTable> gGroupPeerTable;

// Helper function that strips off the interface ID from a peer address that is
// not an IPv6 link-local address. For any other address type we should rely on
// the device's routing table to route messages sent. Forcing messages down a
// specific interface might fail with "no route to host".
void CorrectPeerAddressInterfaceID(Transport::PeerAddress & peerAddress)
{
if (peerAddress.GetIPAddress().IsIPv6LinkLocal())
{
return;
}
peerAddress.SetInterface(Inet::InterfaceId::Null());
}

} // namespace

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

const SessionHandle & session = optionalSession.Value();
Transport::UnauthenticatedSession * unsecuredSession = session->AsUnauthenticatedSession();
unsecuredSession->SetPeerAddress(peerAddress);
Transport::PeerAddress mutablePeerAddress = peerAddress;
CorrectPeerAddressInterfaceID(mutablePeerAddress);
unsecuredSession->SetPeerAddress(mutablePeerAddress);
SessionMessageDelegate::DuplicateMessage isDuplicate = SessionMessageDelegate::DuplicateMessage::No;

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

// TODO: once mDNS address resolution is available reconsider if this is required
// This updates the peer address once a packet is received from a new address
// and serves as a way to auto-detect peer changing IPs.
if (secureSession->GetPeerAddress() != peerAddress)
Transport::PeerAddress mutablePeerAddress = peerAddress;
CorrectPeerAddressInterfaceID(mutablePeerAddress);
if (secureSession->GetPeerAddress() != mutablePeerAddress)
{
secureSession->SetPeerAddress(peerAddress);
secureSession->SetPeerAddress(mutablePeerAddress);
}

if (mCB != nullptr)
Expand Down
Loading