From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from cornsilk.elm.relay.mailchannels.net (cornsilk.elm.relay.mailchannels.net [23.83.212.40]) by sourceware.org (Postfix) with ESMTPS id BFEDA385800C for ; Sat, 16 Sep 2023 00:49:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BFEDA385800C 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 65C0B7A1A9F; Sat, 16 Sep 2023 00:49:15 +0000 (UTC) Received: from pdx1-sub0-mail-a258.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id D84E67A1D2C; Sat, 16 Sep 2023 00:49:14 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1694825354; a=rsa-sha256; cv=none; b=uPLwouAowuWeIxqcIjvcbF3nzJiMC/W/aEffVmzBxT55j1duUP6SZibc1/cfma1hDV7Nl0 S25hZgb8mXry15zNDDbbjYBHTXRGixwnx7/ZGH/O9tYfZq9MTuxwI17vkCyQEf7qoo86jb g09tdsqQKSgu1nHJK23cjGFxNsj/18QFC7qpeCDX6Cz+e4AIVdxF3pqcKsxo9bHd/d+lVT Cxn74bwc/P5w+PN9HeAcXa/XCL3SOVKXUQsIYjc8Yt8bu7CyT87zPBUP9WguUDutbBcchM pAyRRtiWMs1siMvLWZS1GSMlPShG6dLXsI298hL6Ficd9dSw53LB/5U2YbKyIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1694825354; 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=0dV5NILoYgUHQgpyEgAoIBTbcwIibZI513MmLSRQD4E=; b=kMdTXzDfeVDRXr3bc8EjvT+nJQMnep8zr5XKPSCrIA+FgSxIEZ0M/o2fzz1cFnXDy+Q8Ll niGAtjXCfnSfQXl0DPIxynQpzHHhq/dWRhUocK/xh+6YIqWP26EaNHyUvw4I2gdwgQ/Dg2 7m19z83sIEaTyqSVKh5TUYTx/hD8SnGuJESG51xzr7gJ+Q807HhY5ZaTgzfIybfqvAcQPB npDAxYth8ju9pGXV9lY3eEmiTuRZIB4N/6TchnkA30mmZyZWlds/LAMRQ/TK0cK7nOpqDW Tz3Tf3YM3QA4Dp9WfHM11ZQkkyPgSwVHI+t1wRRyAqUZxI3/zDpqrllkgp71Fw== ARC-Authentication-Results: i=1; rspamd-7c449d4847-ml89v; auth=pass smtp.auth=dreamhost smtp.mailfrom=siddhesh@sourceware.org X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org X-MC-Relay: Good X-MC-Copy: stored-urls X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Share-Unite: 67d86c16544d24bb_1694825355261_4246668011 X-MC-Loop-Signature: 1694825355261:3069703165 X-MC-Ingress-Time: 1694825355261 Received: from pdx1-sub0-mail-a258.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.117.103.179 (trex/6.9.1); Sat, 16 Sep 2023 00:49:15 +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-a258.dreamhost.com (Postfix) with ESMTPSA id 4RnXWG3MdCzLG; Fri, 15 Sep 2023 17:49:14 -0700 (PDT) From: Siddhesh Poyarekar To: libc-stable@sourceware.org Cc: DJ Delorie Subject: [pushed 2.34 11/14] gaih_inet: split loopback lookup into its own function Date: Fri, 15 Sep 2023 20:48:58 -0400 Message-ID: <20230916004902.1151607-12-siddhesh@sourceware.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230916004902.1151607-1-siddhesh@sourceware.org> References: <20230916004902.1151607-1-siddhesh@sourceware.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1172.4 required=5.0 tests=BAYES_00,GIT_PATCH_0,KAM_DMARC_NONE,KAM_DMARC_STATUS,KAM_SHORT,RCVD_IN_DNSWL_NONE,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 6be109d07f..827c43b369 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