From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from beige.elm.relay.mailchannels.net (beige.elm.relay.mailchannels.net [23.83.212.16]) by sourceware.org (Postfix) with ESMTPS id 41A4B3858288 for ; Fri, 15 Sep 2023 23:48:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 41A4B3858288 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=sourceware.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=sourceware.org X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 469A0840EEA; Fri, 15 Sep 2023 23:48:10 +0000 (UTC) Received: from pdx1-sub0-mail-a222.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id DB5F2840CB3; Fri, 15 Sep 2023 23:48:09 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1694821689; a=rsa-sha256; cv=none; b=dRCEz/F8ZoLwdy62q0Dt34pEwbAxmB7Wdedcsl62blyq6XsRIO6R6wPdxH4MGDvEFyrBnL aNzbcrgXVCgkGFXhxY2tfAJ2NZXq9KJNYaVr0YhtCYOD9T00HbnrY65Uo0vPuvM4ja/jNM djdbEVBVfgyCIa5UnVl7LFWicewvuPi6NRjPsYgsXymFN7Li8Eg2in9CdoCW+ZQs8ukElO e+lPxQP/+xba2r+y/C5x/VAK6SkukX6whpbEIALQF5ODyVYLrF6BF6ouwuhizQqVEyJ0ax TdQFbDM3IYHqZnjvoRQ12yLkuMF3EiKC/9VHYweaNX0cIm6xZvcQo2Y4WCoLVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1694821689; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=414ia39GgaJk5Eda45n2xsEl53VDe/sGXmdw1DwmaDQ=; b=DyRMciFbWDft1HZLHhq26e4VszZEiEc3EgnZ9QZNVYYUFRc8scW6KEKRaIAf1F6sXulyMV tUBD6k7+RD5l2lwz/BKfOToLZP/Hg92c1kj+hCdqEG4Q01SumRwVzDFzMEfLkmtfjN3tng fXE6oMGxolFxBszZqPRHGMekG+MnIdCR4oTtzPruKZKmVHyZSuWwnFpD880zNRpkSFA2En 2DhZ4K3fEBsgaN9zwC8n4MPGvYCFCrQj2qmzttx7r6uNn7M3UT0wdPr/9eNoP58mfp3Af/ CXns7nfZjVcMftBMCAR7BhPLJo4bq6BdFEGJLcIj7J/7yHLxUeblkkXCn51pLA== ARC-Authentication-Results: i=1; rspamd-7d5dc8fd68-q65xz; auth=pass smtp.auth=dreamhost smtp.mailfrom=siddhesh@sourceware.org X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org X-MC-Relay: Neutral X-MC-Copy: stored-urls X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Reign-Share: 1684cf573fdc650f_1694821690112_2367984341 X-MC-Loop-Signature: 1694821690112:3608219229 X-MC-Ingress-Time: 1694821690112 Received: from pdx1-sub0-mail-a222.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.114.198.214 (trex/6.9.1); Fri, 15 Sep 2023 23:48:10 +0000 Received: from fedora.redhat.com (bras-vprn-toroon4834w-lp130-02-142-113-138-41.dsl.bell.ca [142.113.138.41]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a222.dreamhost.com (Postfix) with ESMTPSA id 4RnW8n3SzwzC7; Fri, 15 Sep 2023 16:48:09 -0700 (PDT) From: Siddhesh Poyarekar To: libc-stable@sourceware.org Cc: DJ Delorie Subject: [pushed 2.35 10/13] gaih_inet: split loopback lookup into its own function Date: Fri, 15 Sep 2023 19:47:52 -0400 Message-ID: <20230915234755.1148216-11-siddhesh@sourceware.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230915234755.1148216-1-siddhesh@sourceware.org> References: <20230915234755.1148216-1-siddhesh@sourceware.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1172.1 required=5.0 tests=BAYES_00,GIT_PATCH_0,KAM_DMARC_NONE,KAM_DMARC_STATUS,KAM_SHORT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_SOFTFAIL,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Flatten the condition nesting and replace the alloca for RET.AT/ATR with a single array LOCAL_AT[2]. This gets rid of alloca and alloca accounting. `git diff -b` is probably the best way to view this change since much of the diff is whitespace changes. Signed-off-by: Siddhesh Poyarekar Reviewed-by: DJ Delorie (cherry picked from commit 657472b2a50f67b12e5bbe5827582c9c2bb82dc3) --- sysdeps/posix/getaddrinfo.c | 127 ++++++++++++++++++------------------ 1 file changed, 62 insertions(+), 65 deletions(-) diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c index bc385dd322..47c41d332d 100644 --- a/sysdeps/posix/getaddrinfo.c +++ b/sysdeps/posix/getaddrinfo.c @@ -1004,6 +1004,32 @@ try_simple_gethostbyname (const char *name, const struct addrinfo *req, return -EAI_NODATA; } +/* Add local address information into RES. RES->AT is assumed to have enough + space for two tuples and is zeroed out. */ + +static void +get_local_addresses (const struct addrinfo *req, struct gaih_result *res) +{ + struct gaih_addrtuple *atr = res->at; + if (req->ai_family == AF_UNSPEC) + res->at->next = res->at + 1; + + if (req->ai_family == AF_UNSPEC || req->ai_family == AF_INET6) + { + res->at->family = AF_INET6; + if ((req->ai_flags & AI_PASSIVE) == 0) + memcpy (res->at->addr, &in6addr_loopback, sizeof (struct in6_addr)); + atr = res->at->next; + } + + if (req->ai_family == AF_UNSPEC || req->ai_family == AF_INET) + { + atr->family = AF_INET; + if ((req->ai_flags & AI_PASSIVE) == 0) + atr->addr[0] = htonl (INADDR_LOOPBACK); + } +} + static int gaih_inet (const char *name, const struct gaih_service *service, const struct addrinfo *req, struct addrinfo **pai, @@ -1014,10 +1040,6 @@ gaih_inet (const char *name, const struct gaih_service *service, const char *orig_name = name; - /* Reserve stack memory for the scratch buffer in the getaddrinfo - function. */ - size_t alloca_used = sizeof (struct scratch_buffer); - int rc; if ((rc = get_servtuples (service, req, st, tmpbuf)) != 0) return rc; @@ -1027,76 +1049,51 @@ gaih_inet (const char *name, const struct gaih_service *service, int result = 0; struct gaih_result res = {0}; - if (name != NULL) + struct gaih_addrtuple local_at[2] = {0}; + + res.at = local_at; + + if (__glibc_unlikely (name == NULL)) { - if (req->ai_flags & AI_IDN) - { - char *out; - result = __idna_to_dns_encoding (name, &out); - if (result != 0) - return -result; - name = out; - malloc_name = true; - } + get_local_addresses (req, &res); + goto process_list; + } - res.at = alloca_account (sizeof (struct gaih_addrtuple), alloca_used); - res.at->scopeid = 0; - res.at->next = NULL; + if (req->ai_flags & AI_IDN) + { + char *out; + result = __idna_to_dns_encoding (name, &out); + if (result != 0) + return -result; + name = out; + malloc_name = true; + } - if ((result = text_to_binary_address (name, req, &res)) != 0) - goto free_and_return; - else if (res.at != NULL) - goto process_list; + if ((result = text_to_binary_address (name, req, &res)) != 0) + goto free_and_return; + else if (res.at != NULL) + goto process_list; - if ((result = try_simple_gethostbyname (name, req, tmpbuf, &res)) != 0) - goto free_and_return; - else if (res.at != NULL) - goto process_list; + if ((result = try_simple_gethostbyname (name, req, tmpbuf, &res)) != 0) + goto free_and_return; + else if (res.at != NULL) + goto process_list; #ifdef USE_NSCD - if ((result = get_nscd_addresses (name, req, &res)) != 0) - goto free_and_return; - else if (res.at != NULL) - goto process_list; + if ((result = get_nscd_addresses (name, req, &res)) != 0) + goto free_and_return; + else if (res.at != NULL) + goto process_list; #endif - if ((result = get_nss_addresses (name, req, tmpbuf, &res)) != 0) - goto free_and_return; - else if (res.at != NULL) - goto process_list; - - /* None of the lookups worked, so name not found. */ - result = -EAI_NONAME; - goto free_and_return; - } - else - { - struct gaih_addrtuple *atr; - atr = res.at = alloca_account (sizeof (struct gaih_addrtuple), - alloca_used); - memset (res.at, '\0', sizeof (struct gaih_addrtuple)); - - if (req->ai_family == AF_UNSPEC) - { - res.at->next = __alloca (sizeof (struct gaih_addrtuple)); - memset (res.at->next, '\0', sizeof (struct gaih_addrtuple)); - } - - if (req->ai_family == AF_UNSPEC || req->ai_family == AF_INET6) - { - res.at->family = AF_INET6; - if ((req->ai_flags & AI_PASSIVE) == 0) - memcpy (res.at->addr, &in6addr_loopback, sizeof (struct in6_addr)); - atr = res.at->next; - } + if ((result = get_nss_addresses (name, req, tmpbuf, &res)) != 0) + goto free_and_return; + else if (res.at != NULL) + goto process_list; - if (req->ai_family == AF_UNSPEC || req->ai_family == AF_INET) - { - atr->family = AF_INET; - if ((req->ai_flags & AI_PASSIVE) == 0) - atr->addr[0] = htonl (INADDR_LOOPBACK); - } - } + /* None of the lookups worked, so name not found. */ + result = -EAI_NONAME; + goto free_and_return; process_list: { -- 2.41.0