From: Florian Weimer <fweimer@redhat.com>
To: Siddhesh Poyarekar <siddhesh@gotplt.org>
Cc: libc-alpha@sourceware.org
Subject: Re: [PATCH 13/13] nss_dns: Rewrite _nss_dns_gethostbyname4_r using current interfaces
Date: Wed, 24 Aug 2022 14:25:17 +0200 [thread overview]
Message-ID: <877d2x7rrm.fsf@oldenburg.str.redhat.com> (raw)
In-Reply-To: <3cf51cb4-c01e-7fee-509a-2e58c3e616d3@gotplt.org> (Siddhesh Poyarekar's message of "Tue, 23 Aug 2022 08:49:37 -0400")
* Siddhesh Poyarekar:
> On 2022-08-10 05:31, Florian Weimer via Libc-alpha wrote:
>
> Could you please add a comment on why a barrier is needed here?
>
>> + asm ("":::"memory");
It's a leftover from debugging. I'll drop it in a repost.
>> @@ -1236,36 +1126,32 @@ gaih_getanswer (const querybuf *answer1, int anslen1, const querybuf *answer2,
>> is a recoverable error we now return TRYAGIN even if the first
>> response was SUCCESS. */
>> - if (anslen1 > 0)
>> - status = gaih_getanswer_slice(answer1, anslen1, qname,
>> - &pat, &buffer, &buflen,
>> - errnop, h_errnop, ttlp,
>> - &first);
>> -
>> - if ((status == NSS_STATUS_SUCCESS || status == NSS_STATUS_NOTFOUND
>> - || (status == NSS_STATUS_TRYAGAIN
>> - /* We want to look at the second answer in case of an
>> - NSS_STATUS_TRYAGAIN only if the error is non-recoverable, i.e.
>> - *h_errnop is NO_RECOVERY. If not, and if the failure was due to
>> - an insufficient buffer (ERANGE), then we need to drop the results
>> - and pass on the NSS_STATUS_TRYAGAIN to the caller so that it can
>> - repeat the query with a larger buffer. */
>> - && (*errnop != ERANGE || *h_errnop == NO_RECOVERY)))
>> - && answer2 != NULL && anslen2 > 0)
>> + if (packet1len > 0)
>> {
>> - enum nss_status status2 = gaih_getanswer_slice(answer2, anslen2, qname,
>> - &pat, &buffer, &buflen,
>> - errnop, h_errnop, ttlp,
>> - &first);
>> + status = gaih_getanswer_slice (packet1, packet1len,
>> + abuf, &pat, errnop, h_errnop, ttlp, true);
>> + if (alloc_buffer_has_failed (abuf))
>> + /* Do not try parsing the second packet if a larger result
>> + buffer is needed. */
>
> NSS_STATUS_TRYAGAIN? It does the right thing in the caller
> eventually, but this doesn't seem semantically correct.
I'm going to add more comments and switch this to NSS_STATUS_TRYAGAIN.
For one of the other functions, internal NSS_STATUS_SUCCESS is the only
case in which a resize is attempted. See the code around line 267.
>> + return NSS_STATUS_SUCCESS;
>> + }
>> +
>> + if ((status == NSS_STATUS_SUCCESS || status == NSS_STATUS_NOTFOUND)
>> + && packet2 != NULL && packet2len > 0)
>> + {
>> + enum nss_status status2
>> + = gaih_getanswer_slice (packet2, packet2len,
>> + abuf, &pat, errnop, h_errnop, ttlp,
>> + /* Success means that data with a
>> + canonical name has already been
>> + stored. Do not store the name again. */
>> + status != NSS_STATUS_SUCCESS);
>> + if (alloc_buffer_has_failed (abuf))
>> + /* Let the caller implement the buffer resizing protocol. */
>> + return NSS_STATUS_SUCCESS;
>
> Same, wouldn't NSS_STATUS_TRYAGAIN be more correct here?
I think we can remove this early return because the caller ignores the
status anyway for the buffer-exhausted case, so we do not need to
special-case it here.
I'll repost this with the barrier removed and more comments added.
Thanks,
Florian
prev parent reply other threads:[~2022-08-24 12:25 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-10 9:30 [PATCH 00/13] nss_dns: Fix handling of non-host CNAMEs (bug 12154) Florian Weimer
2022-08-10 9:30 ` [PATCH 01/13] resolv: Add tst-resolv-byaddr for testing reverse lookup Florian Weimer
2022-08-18 15:26 ` Siddhesh Poyarekar
2022-08-10 9:30 ` [PATCH 02/13] resolv: Add tst-resolv-aliases Florian Weimer
2022-08-18 16:36 ` Siddhesh Poyarekar
2022-08-19 14:20 ` Florian Weimer
2022-08-19 14:27 ` Siddhesh Poyarekar
2022-08-19 14:54 ` Florian Weimer
2022-08-24 13:30 ` Florian Weimer
2022-08-10 9:30 ` [PATCH 03/13] resolv: Add internal __res_binary_hnok function Florian Weimer
2022-08-18 16:40 ` Siddhesh Poyarekar
2022-08-10 9:30 ` [PATCH 04/13] resolv: Add the __ns_samebinaryname function Florian Weimer
2022-08-18 16:46 ` Siddhesh Poyarekar
2022-08-10 9:30 ` [PATCH 05/13] resolv: Add internal __ns_name_length_uncompressed function Florian Weimer
2022-08-18 17:23 ` Siddhesh Poyarekar
2022-08-10 9:30 ` [PATCH 06/13] resolv: Add DNS packet parsing helpers geared towards wire format Florian Weimer
2022-08-18 18:57 ` Siddhesh Poyarekar
2022-08-19 14:59 ` Florian Weimer
2022-08-19 15:13 ` Siddhesh Poyarekar
2022-08-22 15:59 ` Siddhesh Poyarekar
2022-08-10 9:30 ` [PATCH 07/13] nss_dns: Split getanswer_ptr from getanswer_r Florian Weimer
2022-08-22 16:18 ` Siddhesh Poyarekar
2022-08-10 9:30 ` [PATCH 08/13] nss_dns: Rewrite _nss_dns_gethostbyaddr2_r and getanswer_ptr Florian Weimer
2022-08-22 21:59 ` Siddhesh Poyarekar
2022-08-10 9:30 ` [PATCH 09/13] nss_dns: Remove remnants of IPv6 address mapping Florian Weimer
2022-08-22 22:05 ` Siddhesh Poyarekar
2022-08-10 9:30 ` [PATCH 10/13] nss_dns: Rewrite getanswer_r to match getanswer_ptr (bug 12154, bug 29305) Florian Weimer
2022-08-22 22:20 ` Siddhesh Poyarekar
2022-08-10 9:31 ` [PATCH 11/13] nss_dns: In gaih_getanswer_slice, skip strange aliases (bug 12154) Florian Weimer
2022-08-23 12:23 ` Siddhesh Poyarekar
2022-08-10 9:31 ` [PATCH 12/13] resolv: Add new tst-resolv-invalid-cname Florian Weimer
2022-08-23 12:32 ` Siddhesh Poyarekar
2022-08-10 9:31 ` [PATCH 13/13] nss_dns: Rewrite _nss_dns_gethostbyname4_r using current interfaces Florian Weimer
2022-08-23 12:49 ` Siddhesh Poyarekar
2022-08-24 12:25 ` Florian Weimer [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=877d2x7rrm.fsf@oldenburg.str.redhat.com \
--to=fweimer@redhat.com \
--cc=libc-alpha@sourceware.org \
--cc=siddhesh@gotplt.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).