From nobody Sat Dec 03 16:01:53 2022 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 4NPZLn5m3qz4jjnL; Sat, 3 Dec 2022 16:01:53 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4NPZLn2D2Kz3t88; Sat, 3 Dec 2022 16:01:53 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1670083313; 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=lD/XIHpt+vFoJ8eB1Ihqsg7mn3DXnRcNV3H00VTLuJg=; b=Vb5mgO3gECXlrAMkyyzZQhKv8FNrmogBCl7e8fgbE7oERuawZGAarcVBAF3Cg8C3Z+uc3m VqxPHNmNj6c0Lpn0Xn0IJa6pgMiTghwNJl0Y8G6iqbVnrGAcgqIF7L7OziPiPtlWPFGywy 6/1iu+CXS4f7S/59pKHfnDI/9mr8eMHwa09xQJogdYiZBoHg2+/oEruWIl9ddbxuwOLV+H ke8PxjMzB666ghi9yFfevXrEN2iEivAOaKmc8aju66e9lchpn+LsLWT/1UppgnhDag2npU KTV+ZiBSBQm+s2xetB+W8UeIemkhj380fxfoUoQw9r3s+KG/4aEZoKqVjaTfgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1670083313; 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=lD/XIHpt+vFoJ8eB1Ihqsg7mn3DXnRcNV3H00VTLuJg=; b=EeSfI8dvvn5wqB7aLIbGaYNKsyFAI4O3NgTXzR9IJzgg9FqKdKNQkZIMb8xZ+g9MIIR96M tOrWDv3KsE/iC8ThvKuBY7ab6km0WigpqTxD1m5eMrFG9pqBGPFMC4te4jEvAoMJzoWO0G ubU+BG3eHiF9eWwSs/ZHHDM67uvZ7w7qSNvik6EeKbM5jcunHKmBEOs8aMcxJG2fI4BnS0 PqDffTRJz5g4aDusOu0vmc31dZLp8Kja0/amoEOuYtDsWFBBKow7Lxtz0tD/GpIGeTrV6y 5bzALgilvAbQl1VnWFqW0xDUig7Y/4zlmo4Nrh5ILzxXwxjeDDiXmtStq7DpQw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1670083313; a=rsa-sha256; cv=none; b=dztRUtNvdeJwcQ++ybGZMuaxl7tjicCEGrryFh8rUqkneT1F/fdH1lQi8gGO9GVRRwAq8w ZbzoT8l/UPl1BpVD9m2r4ENbxNiRJGmoPp4nqmfP76kCcG4aQdCfWz0cJTtp7RDOi2izDb CMlGRTvsfMIFEAAttHtaqtVsjuVQQWXofIZCFTMFKU3NiaBTRYWiVCJlPK+EzbHltaa3Ol 0rVwzUdzAZp/oDg1sIs/o61YVIKDzDIPRQruJnqghPAUSbDd7OgXdIlbI3WgxYtn+iAD/3 nYosA7g/zoKDoi6TjKwvL4ARO+z/eutS9m4JyWatZC3W25NiP1RtiBNAJhISMg== 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 4NPZLn1Kw3z11SS; Sat, 3 Dec 2022 16:01:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 2B3G1rLF007910; Sat, 3 Dec 2022 16:01:53 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2B3G1rHo007909; Sat, 3 Dec 2022 16:01:53 GMT (envelope-from git) Date: Sat, 3 Dec 2022 16:01:53 GMT Message-Id: <202212031601.2B3G1rHo007909@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mike Karels Subject: git: f395174bbb2c - stable/13 - getaddrinfo: distinguish missing addrs from unresolvable names 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: karels X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: f395174bbb2c6a0a7bba7b08364e8e5e289ef780 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by karels: URL: https://cgit.FreeBSD.org/src/commit/?id=f395174bbb2c6a0a7bba7b08364e8e5e289ef780 commit f395174bbb2c6a0a7bba7b08364e8e5e289ef780 Author: Mike Karels AuthorDate: 2022-11-02 15:57:59 +0000 Commit: Mike Karels CommitDate: 2022-12-03 15:16:46 +0000 getaddrinfo: distinguish missing addrs from unresolvable names Rework getaddrinfo(3) to return different error values for unresolvable names (same as before, EAI_NONAME) and those without a requested addr (EAI_ADDRFAMILY) when using DNS. This is implemented via an added error in the nsswitch layer, NS_ADDRFAMILY, which is used only by getaddrinfo(). The error is passed through nsdispatch(3), but that routine has no changes to handle this error. The error originates in the getaddrinfo DNS layer called via nsdispatch(), and is processed by the search layer that calls nsdispatch(). While here, add a little style to returns near those that were modified. Reviewed in https://reviews.freebsd.org/D37139 with related changes. Reviewed by: bz (cherry picked from commit 144361386696582c04592f200a4c2e3339c81a25) --- include/nsswitch.h | 1 + lib/libc/net/getaddrinfo.c | 16 +++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/include/nsswitch.h b/include/nsswitch.h index f7131292dd78..2be7a59fd1b9 100644 --- a/include/nsswitch.h +++ b/include/nsswitch.h @@ -53,6 +53,7 @@ #define NS_NOTFOUND (1<<2) /* source responded 'no such entry' */ #define NS_TRYAGAIN (1<<3) /* source busy, may respond to retry */ #define NS_RETURN (1<<4) /* stop search, e.g. for ERANGE */ +#define NS_ADDRFAMILY (1<<5) /* no addr for fam, getaddrinfo only */ #define NS_TERMINATE (NS_SUCCESS|NS_RETURN) /* flags that end search */ #define NS_STATUSMASK 0x000000ff /* bitmask to get the status flags */ diff --git a/lib/libc/net/getaddrinfo.c b/lib/libc/net/getaddrinfo.c index abe4eb17cf72..14729087b82a 100644 --- a/lib/libc/net/getaddrinfo.c +++ b/lib/libc/net/getaddrinfo.c @@ -1953,6 +1953,9 @@ explore_fqdn(const struct addrinfo *pai, const char *hostname, case NS_NOTFOUND: error = EAI_NONAME; goto free; + case NS_ADDRFAMILY: + error = EAI_ADDRFAMILY; + goto free; case NS_SUCCESS: error = 0; for (cur = result; cur; cur = cur->ai_next) { @@ -2341,7 +2344,9 @@ _dns_getaddrinfo(void *rv, void *cb_data, va_list ap) if (res_searchN(hostname, &q, res) < 0) { free(buf); free(buf2); - return NS_NOTFOUND; + if (res->res_h_errno == NO_DATA) + return (NS_ADDRFAMILY); + return (NS_NOTFOUND); } /* prefer IPv6 */ if (q.next) { @@ -2363,15 +2368,16 @@ _dns_getaddrinfo(void *rv, void *cb_data, va_list ap) if (sentinel.ai_next == NULL) switch (res->res_h_errno) { case HOST_NOT_FOUND: + return (NS_NOTFOUND); case NO_DATA: - return NS_NOTFOUND; + return (NS_ADDRFAMILY); case TRY_AGAIN: - return NS_TRYAGAIN; + return (NS_TRYAGAIN); default: - return NS_UNAVAIL; + return (NS_UNAVAIL); } *((struct addrinfo **)rv) = sentinel.ai_next; - return NS_SUCCESS; + return (NS_SUCCESS); } static void