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
Support for ares getaddrinfo #232
Conversation
@ki11roy: Changes have been made to public function prototypes. It breaks API and ABI compatibility with existing integrations that use those functions. Can you elaborate on why this decision was made? Otherwise I do like the fact that a new private structure is used, it helps with portability in my opinion (especially since I've done a bit of work with legacy systems like SCO). I need some time to evaluate the code further to see how it differs from #112 by @ChristianAmmer |
@bradh352 From one side ares_parse_a_reply/ares_parse_aaaa_reply look more like private and as I guess intended for some special cases. Update: |
Reverted public function prototypes back to original. |
please re-base your changesets against current master now that the original ticket has been merged. Thanks! |
Don't merge, rebase (cleanup any problems) and force-push. Makes things much easier to review... |
Oh, that was an intermediate commit, please ignore it. Squashed and cleaned up a bit. |
@ChristianAmmer care to review this PR as well? |
I will review this Pull Request. I'm not sure how to start best because the changes are quite a lot and I think it's not wise to comment inline the code. I think it's good to start here by describing my first thoughts.
For the rest I will have to look in more detail soon, but it's great to see features implemented like the file lookup, setting |
|
Do you agree with me, that a suffix should be tried for both families before trying the next suffix in the search list?
How do you intend to change
The dot suffix specifies a FQDN and
With user I mean also the c-ares developers. The interface is not self explaining, you have to read the implementation to know what happens with the result arguments |
Agree, see below.
Something similar to adding ever_got_nodata flag, like ever_got_servfail:
So it is not fatal if we have some results. If there are no - handle it accordingly in the gethostbyname/getaddrinfo just like with ARES_ENODATA (note status == ARES_ESERVFAIL)
Right, it works. I have compared libc implementations of gethostbyname and getaddrinfo and it seems that I have misunderstood some docs, like this:
is valid for getaddrinfo too, but not mentioned in the manual.
It is not in sync with ares_search anymore, so you have missed some new code:
Copy-paste is (almost) always a bad thing so I think it is better to return back to ares_search as I did in this PR.
It is, but I doubt that separating that in two will get things easier. Though if you have ideas how to improve I will consider it. |
@ChristianAmmer Flag description:
And the code:
And the test
There are some tests with MockNoCheckRespChannelTest,
|
Regarding
I did not copy-paste the
But with an additional flag you will not solve the check-suffix-for-both-families-before-switch-to-next-suffix task. Which you already agreed with me. Regarding
The functions need not to be changed at all. They have an output argument
Is not the full truth because you make extra allocations and copies in |
I would like to clarify if #94 is a real issue before discussing any further, see my comment above. |
@bagder @bradh352 any comments? The code below works as expected.
|
So how are you going to return this, and upcoming fixes, without copying them in two places?
You are making an extra copy into completely different structure, while you can parse into the right place straight away. And that is not counting various ai_hints which can influence parsing too, for example canonical name.
And judging by the test above it works without any fixes even now and even with ares_gethostbyname. Or have I missed something? Please explain.
Please show me exact lines and tell what makes you think of them as 'extra allocations'.
Same.
Allocates, copies and then happily frees it after every add_to_addrinfo call:
And looking into ares_free_hostent it seems how many? Five + address count allocations.
While I agree about the copy, please justify your statement about deletion, with the particular lines. |
I'm thinking of a function which implements the new requirement and that one gets called from both places.
The test above is changed by you, it probably tries "www.first.com" with the first DNS request, so no switch of the suffix is done anymore.
The |
I've explained how it works in the comments above. In short - it retries all the SERVFAILs and work with the suffixes too. There is an example which can't work according to your assumptions.
It is written by me and works in trunk perfectly.
No it is not. Please explain how it works without referring to probabilities. It can't by your logic.
Can't see how more allocations and frees be possibly more efficient. Do you understand that this addresses are freed when freeing the hostent? Your code:
My code:
Code for the reference:
Well, we really can reuse addresses as we are controlling allocation and ares_free_addrinfo, but it involves deeper modification of parse function. |
Ok, I tried your test with verbose output:
As you can see, it tries "www.first.com" with the first DNS request. I'm not going to comment your list about allocations and copies. Without measuring it, your argument about efficiency is uncertain. But changing the function like you did makes it
|
It tries and fails with the first request! And with the second and the third! And than it succeeds!
I am addressing your assumptions that your code has less copies and allocations. That was your initial point:
So I assume that was full truth and there are less allocations in my code. And my point was not about performance. It is about parsing into the right structure and supporting hints and cnames and other flags as I told before and less allocations as a consequence and a bonus. |
It does not switch the suffixes as the name of the test states. Have a look at the other
I did not made such an assumption. |
Correct, the switching is not the task of this mechanism. So that returning us to the beginning:
So it will check suffix for both families as the test proves. |
@bagder it seems that getaddrinfo is useless without proper sorting, which is a tricky and involves connecting to multiple addresses. I have partly adopted the version from https://android.googlesource.com/platform/bionic/+/2e23e29245aa42d0f9419187c94e72dba3888eef/libc/netbsd/net/getaddrinfo.c which seems compatible by license.
Update: |
@ki11roy the license for that code is certainly with with us to use. If you use code straight from there you should make an effort to maintain that license blob. I was a bit afraid that we needed sorting for it to be sensible, but I'm also glad that this is already discovered, realized and seemingly also soon fixed! For me personally I think the sorting can go in as a separate PR, to make the review process slightly easier and reduce the total patch size of each PR. Also, since this is a new function that no existing user who would pull from github immediately would be using so having a short gap in time in the master branch with this "lack of feature" is not a concern. |
i'll review the comments and latest changeset this weekend. Any chance we can get the conflicts cleaned up before then? |
I'll try to fix it today, a bit later. |
…be a pointer copy of the ai member of hquery)
Just trying to take a peek at this, I see some comments regarding responses with no data results not properly continuing on, which is what I think #226 is trying to say, so you might have stumbled on the same bug? I haven't had time to try to reproduce myself. I do agree the readability is reduced due to the wrappers for the parse a and aaaa replies and seems like a lot of additional code for no real gain over the initial implementation by @ChristianAmmer just copying the data from hostent over into addrinfo, or am I missing something and there is metadata that is missing? |
Could be, but I think it is another issue.
Well, initially I though about moving it into another file, like ares__parse_into_addrinfo and combine a and aaaa versions there. Yes, there are some fields which needed while parsing, port for example and canonical name. Moreover there is a TTL parameter which can be moved into ares_addrinfo so you wont't need ares_addrttl/ares_addr6ttl anymore. Will you agree on a separate file considering the above? |
I would personally love to have access to the TTL in the ares_addrinfo struct. I think I can definitely get behind what you're saying, but I would like to have one additional thing done, and that would be to replace the existing ares_parse_a_reply() and ares_parse_aaaa_reply() with wrappers around your new ares__parse_into_addrinfo(). We don't have code that does similar things ... and since those are public functions, even if we choose not to use them internally, we need to keep them for compatibility. |
Just wanted to check in on the progress here. Thanks! |
I want to split this PR into smaller ones, in the next couple of days. |
@k11roy just checking in ... |
@bradh352 oh, sorry, looking into it |
@ki11roy hate to be a pain ... got other people opening issues on getaddrinfo() now that I think may be resolved by your solutions. |
@bradh352 got a problem with CNAME TTL placement in ares_addrinfo structure. The possible solutions:
The first one adds one integer per list element overhead, so the second one seems better. Will do the second variant. |
eh, 30 years ago I might be concerned about an additional integer. These days though, I'd rather have more information in case needed. I think option #1 is better. |
I have made #1 and it seems simpler indeed. Still have some tests to add and fix. |
great, thanks! |
@ki11roy just checking in |
#257 supersedes this |
This is a deeply reworked #112, though I have changed everything except maybe tests. It still lacks proper sorting (rfc and sortlist), but I hope to fix it later.
Update: sorting as a separate function available in #239
Summary of changes:
ares_parse_a_reply/ares_parse_aaaa_reply both changed to parse into ares_addrinfo structurechanged back in favour of private ares__parse_a/ares__parse_aaaa