Filter local interface DNS results by address family#128705
Filter local interface DNS results by address family#128705simonrozsival wants to merge 2 commits into
Conversation
When SystemNative_GetHostEntryForName augments local hostname results with getifaddrs entries, keep the interface address family consistent with the requested getaddrinfo family. This preserves AF_UNSPEC behavior while preventing IPv6 interface addresses from leaking into IPv4-only lookups. Co-authored-by: Copilot <[email protected]>
|
Tagging subscribers to this area: @karelz, @dotnet/ncl |
There was a problem hiding this comment.
Pull request overview
Fix for issue #128371: when SystemNative_GetHostEntryForName augments getaddrinfo results with addresses from getifaddrs for local hostname lookups, it now filters interface addresses by the requested address family, matching the filter that getaddrinfo already applies via hint.ai_family. This prevents IPv6 interface addresses from leaking into IPv4-only lookups (and vice versa) on platforms like Android.
Changes:
- Skip
getifaddrsentries whose family doesn't matchplatformFamily(unlessAF_UNSPEC) in both the counting and the copy loops. - Cache
ifa->ifa_addr->sa_familyin a localinterfaceFamilyto avoid redundant dereferencing.
|
/azp run runtime-android |
|
Azure Pipelines successfully started running 1 pipeline(s). |
This comment has been minimized.
This comment has been minimized.
|
/azp run runtime-extra-platforms |
|
Azure Pipelines successfully started running 1 pipeline(s). |
rzikm
left a comment
There was a problem hiding this comment.
LGTM, this looks like it will address all recent problems with new DNS tests on Android
|
Will this also fix test disabled by #127742? |
🤖 Copilot Code Review — PR #128705Note This review was generated by GitHub Copilot. Holistic AssessmentMotivation: The PR fixes a real bug where Approach: The fix applies the same Summary: ✅ LGTM. The change is minimal, correct, and directly addresses the reported inconsistency. No blocking issues found. Detailed Findings✅ Correctness — Filter applied consistently in both loopsBoth the counting pass (line ~456) and the population pass (line ~521) apply the identical filter: sa_family_t interfaceFamily = ifa->ifa_addr->sa_family;
if (platformFamily != AF_UNSPEC && interfaceFamily != platformFamily)
{
continue;
}This ensures ✅ Backward compatibility —
|
Note
This PR description was generated with GitHub Copilot.
Fixes #128371
SystemNative_GetHostEntryForNamealready passes the requested address family togetaddrinfothroughhint.ai_family. However, when the queried name matches the value returned bygethostname(), the PAL augments those resolver results with local interface addresses fromgetifaddrs. That augmentation path was not applying the same address-family filter, so an IPv4-only lookup could still append IPv6 interface addresses, and vice versa.This became observable on Android after the minimum API level was raised from 21 to 24. Android API 24 exposes Bionic
getifaddrs, soHAVE_GETIFADDRSis now true for Android native builds and this local-interface augmentation can run there. The failing CI pattern points specifically at Windows-hosted physical Android device lanes: those devices appear to enter the local-hostname augmentation path forlocalhost, while Ubuntu emulator lanes and a local Samsung physical device did not.The fix filters
getifaddrsentries by the requested platform family in both the counting and population passes. Requests withAF_UNSPECare intentionally left unchanged, so default/unspecified lookups can continue returning both IPv4 and IPv6 addresses as before.I considered making this Android-specific or filtering in managed code, but the mismatch is in the native PAL contract: callers pass an address family into
SystemNative_GetHostEntryForName,getaddrinfohonors it, and only the nativegetifaddrsaugmentation ignores it. Keeping the fix in native makes the whole returnedHostEntryinternally consistent across platforms. The behavioral impact on non-Android Unix platforms should be limited to local-hostname lookups that explicitly request IPv4 or IPv6; those calls should not receive opposite-family interface addresses.