-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Narrow AddressFamily passed to getaddrinfo when IPv6 is unsupported #112642
base: main
Are you sure you want to change the base?
Conversation
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.
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
Comments suppressed due to low confidence (1)
src/libraries/System.Net.NameResolution/src/System/Net/Dns.cs:390
- The new method ValidateAddressFamily should be covered by tests to ensure its correctness.
private static bool ValidateAddressFamily(ref AddressFamily addressFamily, string hostName, bool justAddresses, [NotNullWhen(false)] out object? resultOnFailure)
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.
LGTM
In #107979 (comment) you've mentioned that we filter out such results after the query. Should we be able to remove that logic, or can the OS still return AAAA results for IPv4-only calls?
@@ -386,10 +387,44 @@ private static IPHostEntry GetHostEntryCore(string hostName, AddressFamily addre | |||
private static IPAddress[] GetHostAddressesCore(string hostName, AddressFamily addressFamily, NameResolutionActivity? activityOrDefault = default) => | |||
(IPAddress[])GetHostEntryOrAddressesCore(hostName, justAddresses: true, addressFamily, activityOrDefault); | |||
|
|||
private static bool ValidateAddressFamily(ref AddressFamily addressFamily, string hostName, bool justAddresses, [NotNullWhen(false)] out object? resultOnFailure) | |||
{ | |||
if (!SocketProtocolSupportPal.OSSupportsIPv6) |
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.
should this be symmetric e.g. should we apply same logic to IPv4?
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 OSSupportsIPv4 == false
a practical real-life user scenario? I would be hesitant to add logic to handle it otherwise. It would be virtually untestable; we don't have a System.Net.DisableIPv4
switch, and I don't think it would make much sense to add one.
/azp run runtime-libraries-coreclr outerloop |
Azure Pipelines successfully started running 1 pipeline(s). |
When IPv6 is unsupported or disabled, we should avoid passing
AF_UNSPEC
to the platform calls since those will doAAAA
resolve attempts which might result in failures surfacing to the user, see #107979. Instead, we can narrow down the query toAF_INET
so failures are avoided.The change has been validated by packet captures on Windows and Linux. There are no
AAAA
questions whenSystem.Net.DisableIPv6
is set totrue
.Fixes #107979.