Reimplement ares_gethostbyname() by wrapping ares_getaddrinfo()#428
Merged
bradh352 merged 15 commits intoc-ares:mainfrom Oct 16, 2021
bradh352:gethostbyname_wrap_getaddrinfo
Merged
Reimplement ares_gethostbyname() by wrapping ares_getaddrinfo()#428bradh352 merged 15 commits intoc-ares:mainfrom bradh352:gethostbyname_wrap_getaddrinfo
bradh352 merged 15 commits intoc-ares:mainfrom
bradh352:gethostbyname_wrap_getaddrinfo
Conversation
…ady for making gethostbyname a wrapper for getaddrinfo
…ame packet. re-enable TCP tests for getaddrinfo.
Member
Author
|
@ChristianAmmer, please review and see if this accomplishes your goal from PR #94 |
Member
Author
Member
That's fine with me. I've started a review and it looks fine but I haven't managed to get through it all... |
Closed
sergepetrenko
pushed a commit
to tarantool/c-ares
that referenced
this pull request
Jul 29, 2022
…es#428) ares_gethostbyname() and ares_getaddrinfo() do a lot of similar things, however ares_getaddrinfo() has some desirable behaviors that should be imported into ares_gethostbyname(). For one, it sorts the address lists for the most likely to succeed based on the current system routes. Next, when AF_UNSPEC is specified, it properly handles search lists instead of first searching all of AF_INET6 then AF_INET, since ares_gethostbyname() searches in parallel. Therefore, this PR should also resolve the issues attempted in c-ares#94. A few things this PR does: 1. ares_parse_a_reply() and ares_parse_aaaa_reply() had very similar code to translate struct ares_addrinfo into a struct hostent as well as into struct ares_addrttl/ares_addr6ttl this has been split out into helper functions of ares__addrinfo2hostent() and ares__addrinfo2addrttl() to prevent this duplicative code. 2. ares_getaddrinfo() was apparently never honoring HOSTALIASES, and this was discovered once ares_gethostbyname() was turned into a wrapper, the affected test cases started failing. 3. A slight API modification to save the query hostname into struct ares_addrinfo as the last element of name. Since this is the last element, and all user-level instances of struct ares_addrinfo are allocated internally by c-ares, this is not an ABI-breaking change nor would it impact any API compatibility. This was needed since struct hostent has an h_name element. 4. Test Framework: MockServer tests via TCP would fail if more than 1 request was received at a time which is common when ares_getaddrinfo() queries for both A and AAAA records simultaneously. Infact, this was a long standing issue in which the ares_getaddrinfo() test were bypassing TCP alltogether. This has been corrected, the message is now processed in a loop. 5. Some tests had to be updated for overall correctness as they were invalid but somehow passing prior to this change. Change By: Brad House (@bradh352)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ares_gethostbyname()andares_getaddrinfo()do a lot of similar things, howeverares_getaddrinfo()has some desirable behaviors that should be imported intoares_gethostbyname(). For one, it sorts the address lists for the most likely to succeed based on the current system routes. Next, whenAF_UNSPECis specified, it properly handles search lists instead of first searching all ofAF_INET6thenAF_INET, it searches in parallel. Therefore, this PR should also resolve the issues attempted in #94.A few things this PR does:
ares_parse_a_reply()andares_parse_aaaa_reply()had very similar code to translatestruct ares_addrinfointo astruct hostentas well as intostruct ares_addrttl/ares_addr6ttlthis has been split out into helper functions ofares__addrinfo2hostent()andares__addrinfo2addrttl()to prevent this duplicative code.ares_getaddrinfo()was apparently never honoringHOSTALIASES, and this was discovered onceares_gethostbyname()was turned into a wrapper, the affected test cases started failing.struct ares_addrinfoas the last element ofname. Since this is the last element, and all user-level instances ofstruct ares_addrinfoare allocated internally by c-ares, this is not an ABI-breaking change nor would it impact any API compatibility. This was needed sincestruct hostenthas anh_nameelement.ares_getaddrinfo()queries for both A and AAAA records simultaneously. Infact, this was a long standing issue in which theares_getaddrinfo()test were bypassing TCP alltogether. This has been corrected, the message is now processed in a loop.