From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 249353857C4A for ; Thu, 17 Mar 2022 04:51:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 249353857C4A Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-643-Hbqq5AtJPjKm6teMJKUvXw-1; Thu, 17 Mar 2022 00:51:17 -0400 X-MC-Unique: Hbqq5AtJPjKm6teMJKUvXw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0CCAC185A7A4; Thu, 17 Mar 2022 04:51:17 +0000 (UTC) Received: from greed.delorie.com (ovpn-112-4.rdu2.redhat.com [10.10.112.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EC7A0409B419; Thu, 17 Mar 2022 04:51:16 +0000 (UTC) Received: from greed.delorie.com.redhat.com (localhost [127.0.0.1]) by greed.delorie.com (8.15.2/8.15.2) with ESMTP id 22H4pGA01745136; Thu, 17 Mar 2022 00:51:16 -0400 From: DJ Delorie To: Siddhesh Poyarekar Cc: libc-alpha@sourceware.org Subject: Re: [PATCH v2 10/12] gaih_inet: split loopback lookup into its own function In-Reply-To: <20220314094835.1159523-11-siddhesh@sourceware.org> (message from Siddhesh Poyarekar via Libc-alpha on Mon, 14 Mar 2022 15:18:33 +0530) Date: Thu, 17 Mar 2022 00:51:16 -0400 Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Mar 2022 04:51:23 -0000 Siddhesh Poyarekar via Libc-alpha writes: > 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. reviewing alternate diff then... ;-) LGTM. Reviewed-by: DJ Delorie > +/* 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); > + } > +} Ok. > > - /* Reserve stack memory for the scratch buffer in the getaddrinfo > - function. */ > - size_t alloca_used = sizeof (struct scratch_buffer); > - Ok. > struct gaih_result res = {0}; > + struct gaih_addrtuple local_at[2] = {0}; > + > + res.at = local_at; > + > + if (__glibc_unlikely (name == NULL)) > - if (name != NULL) > { > + get_local_addresses (req, &res); > + goto process_list; > + } > + Ok. > > - res.at = alloca_account (sizeof (struct gaih_addrtuple), alloca_used); > - res.at->scopeid = 0; > - res.at->next = NULL; Ok. > - 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 (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); > - } > - } Ok.