-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
fix ReceiveFrom with dual mode socket #92086
Conversation
Tagging subscribers to this area: @dotnet/ncl Issue Detailsfixes #92006 After thinking about it I see no reason why
|
src/libraries/System.Net.Primitives/src/System/Net/IPEndPoint.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Primitives/tests/FunctionalTests/IPEndPointTest.cs
Show resolved
Hide resolved
{ | ||
throw new ArgumentException(SR.Format(SR.net_InvalidAddressFamily, socketAddress.Family.ToString(), GetType().FullName, AddressFamily.ToString()), nameof(socketAddress)); | ||
throw new ArgumentException(SR.Format(SR.net_InvalidAddressFamily, socketAddress.Family.ToString(), GetType().FullName), nameof(socketAddress)); | ||
} | ||
|
||
int minSize = AddressFamily == AddressFamily.InterNetworkV6 ? SocketAddress.IPv6AddressSize : SocketAddress.IPv4AddressSize; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're no longer requiring that socketAddress.Family == AddressFamily, does this size check still matter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to but than we can possibly get exception when we access the underlying buffer and it is too small. So I feel the extra check provides better feedback.
if (_remoteEndPoint!.AddressFamily == AddressFamily.InterNetworkV6 && _socketAddress!.Family == AddressFamily.InterNetwork) | ||
{ | ||
_remoteEndPoint = _remoteEndPoint!.Create(_socketAddress); | ||
_remoteEndPoint = new IPEndPoint(_socketAddress.GetIPAddress().MapToIPv6(), _socketAddress.GetPort()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this something IPEndPoint.Create(SocketAddress) should be doing instead of doing it at this one call site?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this one is tricky - we have cases when the address is IPv4 and Create
would just work - but we want IPv6 IPv4Mapped addresses for DualMode sockets. I guess mostly for compatibility reasons so this is handled as special case.
{ | ||
_remoteEndPoint = new IPEndPoint(_socketAddress.GetIPAddress().MapToIPv6(), _socketAddress.GetPort()); | ||
} | ||
else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly here: if this logic were moved into IPEndPoint.Create, would that a) address the duplication between these two call sites and b) potentially avoid bugs elsewhere? Or would that introduce problems?
/backport to release/8.0 |
Started backporting to release/8.0: https://github.com/dotnet/runtime/actions/runs/6195384920 |
Fixes #92006
This is regression against 7.0
It seems like the old internal code handled cases when IPv4
EndPoint
was passed toReceiveFrom
on dual mode socket and the received address is actually IPv4 mapped into IPv6. But that case fails now and we fail to setRemoteEndPoint
leaving whatever was there - in case of the provided repro creating loop or possibly sending message to wrong peer.After thinking about it I see no reason why
IPEndPoint.Create
needs to really care aboutAddressFamily
as long as it is IP. The documentation claims that it needs to be correct type but it does not talk about IPv4 vs IPv6. And we allocate newEndPoint
so the actual value of the old one does not matter. It will also make it easier to consume new API from #88970 as we exposedSocketAddresses
to consumers and they may need to eat with it.The regression was introduced by PR #89841