-
-
Notifications
You must be signed in to change notification settings - Fork 1
Gethostbyname: use proper glibc function #9
Conversation
Codecov Report
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. @@ Coverage Diff @@
## host-lookups #9 +/- ##
===============================================
Coverage ? 58.29%
===============================================
Files ? 6
Lines ? 458
Branches ? 0
===============================================
Hits ? 267
Misses ? 191
Partials ? 0 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
0eaa3ad to
c175727
Compare
86105b7 to
0a09950
Compare
9d227db to
a8dff2d
Compare
|
Adressed Flokli's nits. Seems to work. I'll use that on my systems the whole day to see if it breaks more stuff. |
|
I tested that for the day. 2 issues with this:
Here's the h_errno definition: |
|
Turns out, a lot of things were wrong. I ended up rewriting this PR from scratch twice since last commit… I think I finally found the right abstraction for hostent... ...and the right defaults wrt. error management. More information in the commit message. According to sockburp, we're bit-to-bit identical to Nscd for these two new operations now. [Edit]: hmm, seems like the CI setup has more aliases than my NixOS desktop for localhost. This is annoying, trying to find a more "stable" test case across different hosts. |
3f7da03 to
0d96cf3
Compare
|
I've been using this PR for the last 12h. Sockburp is happy, it seems to behave correctly. |
|
This fails to build on |
^ on x86_64. What the hell. EDIT: got it. c_char is u8 on arm64, i8 on x86. Fixing that. |
We internally used getai to restpond to the gethostbyname/gethostbyaddr operations. Sadly, it does not behave as expected and breaks some tools (like hostname --fqdn, see #4. We FFI the right Glibc gethostbyname_2r/gethostbyaddr_2r (now deprecated) functions and use it to back the GETHOSTBYNAME, GETHOSTBYNAME6, GETHOSTBYADDR, and GETHOSTBYADDR6 Nscd interfaces. Using sockburp, we realized the hostent serialization function was bogus: we totally forgot to serialize the aliases. This commit fixes this and makes sure we're producing bit-to-bit identical results with Nscd for gethostbyname/getaddrinfo. Took me three try to get this right. This is actually the third full rewrite. The Nscd behaviour for these two legacy functions is *really* confusing. We're supposed to ignore the herrno (herrno != errno!!) and set it to 0 if gethostbyaddr/name returns a non-null hostent. If we end up with a null hostent, we return the herrno together with a dummy hostent header. I tried to keep things as safe as possible by extracting the glibc hostent to a proper rust structure. This structure mirrors the libc hostent in a Rust idiomatic way. We should probably try to upstream the FFI part of this commit to the Nix crate at some point. Fixes #4
|
@flokli: PTAL on aarch64 |
|
Yes, now builds and works on |
|
We both tested this for an extended period of time, and also validated with sockburp comparing responses from nsncd with glibc-nscd. Other than DNS servers returning responses sometimes in different order, there seems to be no differences for host-related lookups. Let's get this in! |
Note: we decided to rewrite the history of the fork who somehow got out of hand. Feature-wise, this version bump fixes the various host faulty behaviour. See the nix-community/nsncd#9 and nix-community/nsncd#10 PRs for more details. We're in the process of upstreaming this change to twosigma/nsncd, however, upstream has been pretty slow to review our PRs so far. Since the hostname bug surfaces quite regularly in the Nixpkgs issue tracker, we decided to use the nix-community fork as canon for Nixpkgs for now. Fixes: NixOS#132646 Fixes: NixOS#261269
We internally used getai to restpond to the gethostbyname operations. Sadly, it did not behave as expected and broke some tools (like hostname --fqdn, see #4.
We FFI the right Glibc gethostbyname_2r (now deprecated) function and use it to back the GETHOSTBYNAME and GETHOSTBYNAME6 Nscd interfaces.
Fixes #4