public inbox for libc-help@sourceware.org
 help / color / mirror / Atom feed
From: Glenn Golden <gdg@zplane.com>
To: libc-help@sourceware.org
Subject: getent ahostsv4 seems to interact with network interface addressing
Date: Sat, 4 Nov 2023 07:23:56 -0600	[thread overview]
Message-ID: <ZUZF7JMvAILKhosE@huh.zplane.com> (raw)


System:
  Arch linux, glibc 2.38-7, kernel 6.1.59-1, commodity i686 laptop.

Description of issue:
  Not sure if this is a bug or just a misunderstanding on my part as to how
  getent ought to be behaving when attempting lookups using the ahostsv4
  database, expecting it to query and return results from /etc/hosts.

  The behavior of "getent ahostsv4 HOSTNAME" seems to strangely depend on
  whether there are any network interfaces presently having an assigned v4
  address, as demonstrated in detail in "Steps to reproduce" below.

  In the typical case, when at least one network interface has a v4 address
  assigned to it, then "getent ahostsv4 HOSTNAME" behaves as expected, i.e.
  it returns the addresses of HOSTNAME obtained from /etc/hosts. But if there
  are no network interfaces having an assigned v4 address, then that same
  command fails with a null return and exits with code 2, which is documented
  (in getent.1) as

      "One or more supplied keys could not be found in the database."

  I am baffled by this. If this is expected behavior, can someone explain
  why?


Steps to reproduce (as root):

  #
  # Step 0: Display all interfaces having v4 addresses. NOTE: In this example,
  # interface wlu2 happens to be a WiFi dongle.
  #

      $ ip -4 -br addr
      lo               UNKNOWN        127.0.0.1/8
      wlu2             UP             192.168.1.16/32

  #
  # Step 1: Demonstrate that getent behaves as expected to resolve the v4
  # address of host 'sam.zplane.com' (which appears in /etc/hosts):
  #

      $ getent ahostsv4 sam.zplane.com
      192.168.1.15    STREAM sam.zplane.com
      192.168.1.15    DGRAM
      192.168.1.15    RAW

  #
  # Step 2: Now remove the v4 addr from interface wlu2:
  #

      $ ip addr del 192.168.1.16/32 dev wlu2

  #
  # Step 3: Confirm that wlu2 (or any other external interface) no longer
  # has a v4 address:
  #

      $ ip -4 -br addr
      lo               UNKNOWN        127.0.0.1/8

  #
  # Step 4: Now getent fails to resolve the same local host as before,
  # displaying nothing and exiting with code 2:
  #

      $ getent ahostsv4 sam.zplane.com
      $ echo $?
      2


  #
  # Step 5: Re-assign an address to wlu2. (NOTE: Any address will do here,
  # it does not have to be on the 192.168.1 local subnet.)
  #

      $ ip addr add 192.168.1.16/32 dev wlu2

  #
  # Step 6: Now getent once again behaves as expected:
  #

      $ getent ahostsv4 sam.zplane.com
      192.168.1.15    STREAM sam.zplane.com
      192.168.1.15    DGRAM
      192.168.1.15    RAW


Possibly related to:

    https://sourceware.org/bugzilla/show_bug.cgi?id=24816
    https://bugs.launchpad.net/ubuntu/+source/glibc/+bug/1945097
    https://unix.stackexchange.com/questions/98693/
    https://unix.stackexchange.com/questions/71379/


TIA for any insight into this behavior.

Thanks,

Glenn Golden

             reply	other threads:[~2023-11-04 13:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-04 13:23 Glenn Golden [this message]
2023-11-05 20:10 ` Florian Weimer
2023-11-06  0:43   ` Glenn Golden
2023-11-06  5:58     ` Florian Weimer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZUZF7JMvAILKhosE@huh.zplane.com \
    --to=gdg@zplane.com \
    --cc=libc-help@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).