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

Recognize "localhost" as special and resolve to the loopback address. #4830

Merged

Conversation

jellefoks
Copy link
Member

@jellefoks jellefoks commented Feb 4, 2025

Avoid using the system resolver to lookup localhost. This ensures that the application is free to use the localhost hostname and assume that both IPv4 and IPv6 adddress queries for localhost names will always resolve to the respective IP loopback address (https://datatracker.ietf.org/doc/html/rfc6761#section-6.3).

This fixes IPv6 localhost not resolving for devices where /etc/hosts is misconfigured.

b/369361511
b/377982714

@jellefoks jellefoks force-pushed the localhost_ipv4_and_ipv6_always_fix branch from 3ed7159 to 5c634f6 Compare February 4, 2025 08:42
@jellefoks jellefoks force-pushed the localhost_ipv4_and_ipv6_always_fix branch 9 times, most recently from afe4aff to 40e3df2 Compare February 5, 2025 01:52
@jellefoks
Copy link
Member Author

jellefoks commented Feb 5, 2025

Note: Only the last single commit "Recognize localhost before handing off to system" is new for this PR, the others are from #4827 that this PR depends on.

@kaidokert kaidokert requested a review from hlwarriner February 5, 2025 03:10
This adds more combinations of parameters for LocalHost and SunnyDay
PosixSocketResolveTest tests, including insuring that lookups work
as expected with address family, socket type, and protocol hints.

This will ensure that PosixSocketResolveTest will also detect systems where
IPv6 localhost lookups don't work.

b/369361511
Make SunnyDayFlags more forgiving, as well as the error return value
for Starboard < 16 and be a little more forgiving for hint flags
returned with the results.
@jellefoks jellefoks force-pushed the localhost_ipv4_and_ipv6_always_fix branch 2 times, most recently from 6d6cb62 to db4f461 Compare February 5, 2025 05:21
@jellefoks
Copy link
Member Author

Removed on-device label. The only remaining failures were issues not related to this PR.

@kaidokert kaidokert removed the request for review from maxz-lab February 5, 2025 18:48
@jellefoks jellefoks force-pushed the localhost_ipv4_and_ipv6_always_fix branch from d4e78c3 to 14884a5 Compare February 6, 2025 00:03
@jellefoks jellefoks force-pushed the localhost_ipv4_and_ipv6_always_fix branch from 14884a5 to 9e440b7 Compare February 6, 2025 22:24
struct sockaddr_in6* address =
reinterpret_cast<struct sockaddr_in6*>(musl_ai->ai_addr);
address->sin6_addr = IN6ADDR_LOOPBACK_INIT;
// address->sin6_addr.__in6_u.__u6_addr8[0] = 5;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we remove the comments here?

@jellefoks jellefoks merged commit f58d6df into youtube:25.lts.1+ Feb 7, 2025
291 of 295 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants