mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Subject: Re: [musl] Other DNS/stub resolver changes
Date: Wed, 21 Sep 2022 18:19:49 -0400	[thread overview]
Message-ID: <20220921221949.GX9709@brightrain.aerifal.cx> (raw)
In-Reply-To: <20220921160819.GU9709@brightrain.aerifal.cx>

On Wed, Sep 21, 2022 at 12:08:19PM -0400, Rich Felker wrote:
> In the process of working out TCP fallback support, some other
> potential/likely changes to the DNS/stub resolver behavior are
> emerging, which I'd like to document here and open for feedback.
> 
> The EAI_NODATA is already covered in an existing thread.
> 
> One weird thing I noticed is that, while lookup_name.c's name_from_dns
> is processing error RCODE values, it actually never sees them because
> __res_msend just treats errors as non-answers. This probably doesn't
> matter, but it does prevent us from ever issuing EAI_FAIL. And from
> the standpoint of the res_* API (res_query/res_send) the caller may be
> expecting to see specific errors and to be able to act on them (todo:
> check what other implementations do here).

At least glibc seems to have no code paths that can produce EAI_FAIL,
and empirically, their res_query returns -1/failure when the
nameserver gives ServFail (tested with lookup of dnssec-failed.org)
rather than making the error packet available to the caller.

> The reason __res_msend doesn't return errors packets is a consequence
> of implementation details, specifically, that it considers erroring
> slots unanswered, and reuses the buffer for them as temp space to
> receive answers that might turn out to be for another query, which
> clobbers them.
> 
> This is rather ugly, and I think I'd like to give __res_msend its own
> 512-byte receive buffer to receive into. This would give us the choice
> to keep error results or not, as we see fit, rather than tying us to
> the current behavior.

As such, I think perhaps I should just leave this alone. Leaving it
alone saves 512 bytes of stack, and doesn't really make the work of
adding TCP any harder.

One remaining motivation for having our own buffer here is that, in
the case where the caller of res_send only provides a small buffer
(smaller than 512 bytes), we would not be able to determine if a
packet equal to the buffer length had been truncated (by the recv
function on the client side) without TCP fallback. This is a mess I
don't want to get into. However, rather than spending an extra 512
bytes of stack in the __res_msend DNS query core, we can just make
"buffer must be >= 512 bytes" part of __res_msend's contract, and
res_send can be responsible for using a local buffer of its own if the
application's buffer is too small, then copying the result.

Rich

      reply	other threads:[~2022-09-21 22:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-21 16:08 Rich Felker
2022-09-21 22:19 ` Rich Felker [this message]

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=20220921221949.GX9709@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=musl@lists.openwall.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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 NNTP newsgroup(s).