From nobody Sat Sep 28 10:38:04 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4XG3hF0dH6z5X8V5; Sat, 28 Sep 2024 10:38:05 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XG3hD6yHQz46VJ; Sat, 28 Sep 2024 10:38:04 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1727519885; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=jFMtQ1z1NWufItF3k5M31mO5Wn0FiBcUPyJIakvCLoY=; b=dtWqJh3c3Km4RvtQA/lWggPPeoy+jS403Ihw6tw7uT+hjXtwa4qAZobcDUEeSielAjRZ03 T6HU9AS/hR4jUpM5EvsapChMFQ8tqan6By2mCxpyToRx8zQQP+unTLGO31UIBJ0cAsjGB+ r70On2DhpKXbSsHm7C67mRaBtOedHy2La0c0/Gj7IN8BMcF4q1NbSyCmlZFX/dlskkWmB9 t77I8WLZBmCgo/xGAWkdUiZghMtpxvrkH7V8duST7k9eOJ4WwcWaFBVAI1hHvPaXVX2n7+ EUfKCH6B6Q3DVWbxpROtszHj1B0nA+NPELk9vDfuFfBOYvBDs3p1GZGTimBcDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1727519885; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=jFMtQ1z1NWufItF3k5M31mO5Wn0FiBcUPyJIakvCLoY=; b=vSfA9vaZwojcwvUTMt1iwW4La3JxWz5Y2x4H53Cq5R4DfOmreA947Ex5koqKCae3mJtRWj vy73NFDCYChwWLvX67ukMCJjkaW7S/a7nwmZQvrzSFmvrz+oFG6s2+aZoDWO/QDw3RgvsT uAhd2c1gMN4o+XKZUiLZGy4TP7jtMTEAliETfMP9nAnZDFo4s0cMT+/dkpN4ut4rfDwFwN LMgFTWvsxs63nVR1MSrrETmtNErlEAfZxjX8ECI+Ut1YhCIxFwJqo3dn/xem7nR7QaH+hN oYDE+3FoB+04rugMS78oBrd9Xx7wTMwtEMB+bvgnKo71v1NZzXzXHdLjqX5WwQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1727519885; a=rsa-sha256; cv=none; b=QlYv/rLLfYyHNjqiLIJQylICcaaj0Q9jSFbbB6nmOZBxOT0rJDh6kxGXYDcTwnINFFsGNQ 75lbCIsj4fv5zHuRVZkO9w1bkCkk2heJOiia5BUPizaDMOSQuSvtt4JRpV29xiq4qseG+a j1F9hME+/h96kjpWJWi9qmjGZn1gH53W0JnXZ6LV1iQlrL/QBhZxyJtQnvNZBMruxSe8Hu ai9GHTIlkT+TLh64FKvq2DWmp+0N8wd9RrYBVcCkU/JlhzqjXAfKCCa+ErRony/zA0Dymg huLNRwqsc9A2bWskT7PgaCSZVjVhOmlDFjMTFxIkJE1qcYBoVJH07hd7EjsqmA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4XG3hD686vzKyx; Sat, 28 Sep 2024 10:38:04 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 48SAc4LK097335; Sat, 28 Sep 2024 10:38:04 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 48SAc4M7097332; Sat, 28 Sep 2024 10:38:04 GMT (envelope-from git) Date: Sat, 28 Sep 2024 10:38:04 GMT Message-Id: <202409281038.48SAc4M7097332@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: "Bjoern A. Zeeb" Subject: git: ff26fd77ee44 - stable/14 - libc/getnameinfo: stop adding NI_NUMERICHOST where inappropriate List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bz X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: ff26fd77ee44de1b2a4c0a527deb6eb44c2fa238 Auto-Submitted: auto-generated The branch stable/14 has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=ff26fd77ee44de1b2a4c0a527deb6eb44c2fa238 commit ff26fd77ee44de1b2a4c0a527deb6eb44c2fa238 Author: Bjoern A. Zeeb AuthorDate: 2024-06-10 11:34:25 +0000 Commit: Bjoern A. Zeeb CommitDate: 2024-09-28 10:35:11 +0000 libc/getnameinfo: stop adding NI_NUMERICHOST where inappropriate Checking the first nibble of the IPv6 address to be 0 and then excluding two well known cases (v4-mapped, loopback) leaves us with more cases where the first nibble could be 0, e.g., the RFC 6052, 2.1 Well-Known Prefix 64:ff9b::/96. It is not practical to track them all and it is not clear what lead to this special casing originally, so remove them. While here also remove the IN6_IS_ADDR_LINKLOCAL() + NI_NUMERICHOST case as link-local address resolution does exist. We do leave the IN6_IS_ADDR_MULTICAST() case for now as I could not find any references to any official reverse lookups for these. Adding comments for more case (and some historic behaviour) in order to make it easier to follow the logic. PR: 279618 Fixes: 6cb9418289f90 Reviewed by: hrs Differential Revision: https://reviews.freebsd.org/D45547 (cherry picked from commit c179937b986ec3959d89bfeb8eed0a6f58a28649) --- lib/libc/net/getnameinfo.c | 54 +++++++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/lib/libc/net/getnameinfo.c b/lib/libc/net/getnameinfo.c index 7ab490abb67f..01bceaa98fce 100644 --- a/lib/libc/net/getnameinfo.c +++ b/lib/libc/net/getnameinfo.c @@ -229,24 +229,44 @@ getnameinfo_inet(const struct afd *afd, case AF_INET6: { const struct sockaddr_in6 *sin6; + sin6 = (const struct sockaddr_in6 *)sa; - switch (sin6->sin6_addr.s6_addr[0]) { - case 0x00: - if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) - ; - else if (IN6_IS_ADDR_LOOPBACK(&sin6->sin6_addr)) - ; - else - flags |= NI_NUMERICHOST; - break; - default: - if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) { - flags |= NI_NUMERICHOST; - } - else if (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr)) - flags |= NI_NUMERICHOST; - break; - } + + /* + * https://pubs.opengroup.org/onlinepubs/9699919799/functions/getnameinfo.html + * "[IP6] [Option Start] If the socket address structure + * contains an IPv4-mapped IPv6 address or an IPv4-compatible + * IPv6 address, the implementation shall extract the embedded + * IPv4 address and lookup the node name for that IPv4 address. + * [Option End]" + * => getipnodebyaddr() handles this case for us. + * => in case of NI_NUMERICHOST being set, inet_ntop[6] will + * handle it too. + * + * "If the address is the IPv6 unspecified address ( "::" ), + * a lookup shall not be performed and the behavior shall be + * the same as when the node's name cannot be located." + * => getipnodebyaddr() handles this case for us. + * => in case of NI_NUMERICHOST being set, + * ip6_parsenumeric() -> inet_ntop[6] will handle it too. + */ + + /* + * We used to exclude link-local from lookups. + * Even though calles in the resolver chain may not (yet) + * properly deal with them, we no longer do as for link-local + * there is a path to resolve these. See: + * RFC 6303 4.5. IPv6 Link-Local Addresses + * RFC 6762 4. Reverse Address Mapping + * + * XXX For IPv6 MC the only reference found was + * https://www.ietf.org/archive/id/draft-michaelson-as112-ipv6-02.html + * but there are also no "empty zone"s for x.0.f.f.ip6.arpa + * in DNS servers. Keep catching it here for now and + * do not attempt name resolution but return the address string. + */ + if (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr)) + flags |= NI_NUMERICHOST; } break; #endif