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

Implement host lookups #49

Closed
wants to merge 17 commits into from
Closed

Commits on May 10, 2023

  1. Cargo: add dns-lookup crate

    Co-Authored-By: Félix Baylac-Jacqué <felix@alternativebit.fr>
    flokli and picnoir committed May 10, 2023
    Configuration menu
    Copy the full SHA
    23289bd View commit details
    Browse the repository at this point in the history
  2. protocol: add HstResponseHeader and serialization test

    Co-Authored-By: Félix Baylac-Jacqué <felix@alternativebit.fr>
    flokli and picnoir committed May 10, 2023
    Configuration menu
    Copy the full SHA
    a045349 View commit details
    Browse the repository at this point in the history
  3. src/handlers: implement serialize_host

    Also add some error codes used in the response header.
    
    Co-Authored-By: Félix Baylac-Jacqué <felix@alternativebit.fr>
    flokli and picnoir committed May 10, 2023
    Configuration menu
    Copy the full SHA
    ef805a4 View commit details
    Browse the repository at this point in the history

Commits on May 19, 2023

  1. src/handlers.rs: handle GETHOSTBYADDR, GETHOSTBYADDRv6

    Co-Authored-By: Félix Baylac-Jacqué <felix@alternativebit.fr>
    flokli and picnoir committed May 19, 2023
    Configuration menu
    Copy the full SHA
    ee60daa View commit details
    Browse the repository at this point in the history
  2. src/handlers: implement GETHOSTBYNAME*

    Co-Authored-By: Félix Baylac-Jacqué <felix@alternativebit.fr>
    flokli and picnoir committed May 19, 2023
    Configuration menu
    Copy the full SHA
    2e6ffe6 View commit details
    Browse the repository at this point in the history
  3. src/protocol: add AiResponse{Header} structs and serialization test

    Co-Authored-By: Florian Klink <flokli@flokli.de>
    picnoir and flokli committed May 19, 2023
    Configuration menu
    Copy the full SHA
    de9e5f0 View commit details
    Browse the repository at this point in the history
  4. src/handlers: Implement the GETAI operation

    We implement the GETAI (aka. get address info) operation. Most of the
    glibc applications will rely on this operation to perform the hostname
    -> addrs resolutions.
    
    We add some unit tests checking that we're correctly serializing the
    address info header and its payload. The expected data used in these
    tests has been extracted from various Nscd socket dumps. We also add
    an integration test checking that getaddrinfo is able to resolve
    localhost.
    
    Co-Authored-By: Florian Klink <flokli@flokli.de>
    picnoir and flokli committed May 19, 2023
    Configuration menu
    Copy the full SHA
    4953d97 View commit details
    Browse the repository at this point in the history
  5. Handle IPv6-only results even in GETHOSTBYNAME

    Previously IPv6-only results would return an empty successful result
    message. This doesn't seem to be a valid response from the perspective
    of Glibc. In my case it caused Firefox to crash.
    andir authored and flokli committed May 19, 2023
    Configuration menu
    Copy the full SHA
    96237d8 View commit details
    Browse the repository at this point in the history
  6. Remove useless lambda and lambda call in serialize_host

    We don't have to use a lambda to return a value from a
    sub-expression. Rust takes the last value in a scope as return value
    even if it isn't a function.
    andir authored and flokli committed May 19, 2023
    Configuration menu
    Copy the full SHA
    f881aac View commit details
    Browse the repository at this point in the history
  7. Move the host serialize code to a associated function

    The function belongs to the data format and not to the actual
    processing logic. This isn't a clean cut just yet all over the
    codebase but moving this very fragile piece into its own function will
    enable us to test it in isolation.
    andir authored and flokli committed May 19, 2023
    Configuration menu
    Copy the full SHA
    f0a162b View commit details
    Browse the repository at this point in the history
  8. Make the GETHOSTBYNAMEv6 handling similar to the v4 equivalent

    This makes the result filtering similar and thus should be less confusing.
    andir authored and flokli committed May 19, 2023
    Configuration menu
    Copy the full SHA
    1f386d7 View commit details
    Browse the repository at this point in the history
  9. Use as_slice().to_vec() instead of manually pre-allocated buffers

    This is as efficient as doing the manual pre-allocation as the
    `to_vec` method will use the length of the slice for the initial size
    allocation of the vector.
    andir authored and flokli committed May 19, 2023
    Configuration menu
    Copy the full SHA
    c6773d6 View commit details
    Browse the repository at this point in the history
  10. Make Host::serialize able to serialize empty address lists

    Previously this would produce a malformed packet as far as glibc is
    concerned.
    
    If there are no addresses the "found" field should not be one and the
    other lookup fields can also be left blank.
    andir authored and flokli committed May 19, 2023
    Configuration menu
    Copy the full SHA
    384182e View commit details
    Browse the repository at this point in the history
  11. Move common HostResponseHeader to const structs

    This moves the "well-known" wire format structs to constants that can
    be reused without having to duplicate their definition all the time.
    andir authored and flokli committed May 19, 2023
    Configuration menu
    Copy the full SHA
    22dda36 View commit details
    Browse the repository at this point in the history
  12. Configuration menu
    Copy the full SHA
    94f54bb View commit details
    Browse the repository at this point in the history

Commits on Oct 20, 2023

  1. gethostbyname/gethostbyaddr: use proper glibc function

    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
    picnoir committed Oct 20, 2023
    Configuration menu
    Copy the full SHA
    66c79cd View commit details
    Browse the repository at this point in the history

Commits on Oct 24, 2023

  1. Merge pull request #9 from nix-community/nin/ghbn

    Gethostbyname: use proper glibc function
    flokli committed Oct 24, 2023
    Configuration menu
    Copy the full SHA
    77fd58d View commit details
    Browse the repository at this point in the history