From nobody Wed Oct 11 19:45:35 2023 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 4S5NXv30Hvz4wcVw; Wed, 11 Oct 2023 19:45:35 +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 4S5NXv2Sx6z3Dry; Wed, 11 Oct 2023 19:45:35 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1697053535; 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=f/MrJTwstubg1zKUByedpiYxLzuOeSGFWn20gCYbPy0=; b=wfbfMaAhwHMc37+fnaP1s4pkRCVS6tg4Fd9t5+fs8za3lXs3H22bupgH/DfPLe/onn1v1c kt40rj4W2RwwbSi3urSraAUYvN0yKbXEDJFgkxTdck+LhRK6HP7bjFuqhwdPafd9Fis3L2 L08sB9AxhtfhBfWejoNTIP8fETe4kEBUyTtSMhqqffk/JUHNJN6Eq2S3y6ninIsodlqA3Z JLi46y7N1ztVh76jpYUMKZIPLELktykN22adlJpuZqnWzFSibRo+mVQDEVVJhkl4ez9rwL 3Qu+4axNK+rj+ye0uXJjiLC+vNioTLGZ5lj3QvFYOzSZrbQREfqZyk7szHrwgQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1697053535; a=rsa-sha256; cv=none; b=Bqci76cCYVNWNxSE1hslCSgij812b5G69q+YFnqKR1K89qEHhL4Nvm869mREUKrMB95kco nAQGTWbsqE91gvpay4ogWvViKyraSGR9j6DkXAr4xksQj5kVMW3CSNcVGqjooJ1uGebwvk GAKm06KXsUm1g57L4hPGrrP5v5uW/CBvoFJigumbbFFUe2hBObcRFjvpKEpzqxkewFO0KN e61MaERssntW1OLZFkDJaALwDgYmsZLte97yHy5lL66AEr4L/5J4g6hOwlVpZ1/Bk+Ykcj hjndcpcc5lnP74yKCHoE4DmScIPbqoenPPD4PK5sSyusgTogri1j+7t4cjhkBw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1697053535; 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=f/MrJTwstubg1zKUByedpiYxLzuOeSGFWn20gCYbPy0=; b=qJKTlldvAfEU7Ym+G7loIeNhFPmWO9+q7AMDAo2rbRPiIOZ2/St1v/DdZEuYaeAJSKjxmS MMfTP168VTjnL2teefTxrhFzZVmSe7+McRi+Q+6c0bEMtv7WRhXDjuWay3HoV8kX+xSio2 1WmwGM1TOkjT1Sg87HhEKfj89FJzTSQSq/q7GunVs25kYWGwNxHpozQrxu+l08CoeKsZTK AnxZDAFStBYbD3g35SXovn7Cq1m7B+ytCNGQ4YTtG+EDm74gHRztDqogWLft54OC/4J6Qd uCzrdzH/0dkP/4Aq2SdYYDCNee1MrPOo4p1dbBDj4p3bwIep0sghe4fozo9EXA== 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 4S5NXv1QdjzZ2y; Wed, 11 Oct 2023 19:45:35 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 39BJjZ3t025157; Wed, 11 Oct 2023 19:45:35 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 39BJjZnC025154; Wed, 11 Oct 2023 19:45:35 GMT (envelope-from git) Date: Wed, 11 Oct 2023 19:45:35 GMT Message-Id: <202310111945.39BJjZnC025154@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= Subject: git: c4ffb80ef18f - main - ping: Consistently use EX_NOHOST for DNS failures. 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: des X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: c4ffb80ef18f6b581dc28c14bc579e0e7c73438c Auto-Submitted: auto-generated The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=c4ffb80ef18f6b581dc28c14bc579e0e7c73438c commit c4ffb80ef18f6b581dc28c14bc579e0e7c73438c Author: Dag-Erling Smørgrav AuthorDate: 2023-10-11 19:44:30 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2023-10-11 19:44:30 +0000 ping: Consistently use EX_NOHOST for DNS failures. Traditionally, ping returned exit code EX_NOHOST if a DNS lookup failed. That is still the case for the legacy code in the new merged ping, but not for IPv6 targets, nor when a DNS lookup is performed in order to determine which version of the tool to invoke. While here, also make sure that the error message is consistent. Sponsored by: NetApp, Inc. Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D42159 --- sbin/ping/main.c | 10 +++++++--- sbin/ping/ping6.c | 5 +++-- sbin/ping/tests/ping_test.sh | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/sbin/ping/main.c b/sbin/ping/main.c index 686b412a19b7..65896a5dba7b 100644 --- a/sbin/ping/main.c +++ b/sbin/ping/main.c @@ -41,6 +41,7 @@ #include #include #include +#include #include #include "main.h" @@ -94,6 +95,7 @@ main(int argc, char *argv[]) #endif #if defined(INET) && defined(INET6) struct addrinfo hints, *res, *ai; + const char *target; int error; #endif int opt; @@ -143,6 +145,7 @@ main(int argc, char *argv[]) usage(); #if defined(INET) && defined(INET6) + target = argv[argc - 1]; memset(&hints, 0, sizeof(hints)); hints.ai_socktype = SOCK_RAW; if (feature_present("inet") && !feature_present("inet6")) @@ -151,9 +154,10 @@ main(int argc, char *argv[]) hints.ai_family = AF_INET6; else hints.ai_family = AF_UNSPEC; - error = getaddrinfo(argv[argc - 1], NULL, &hints, &res); + error = getaddrinfo(target, NULL, &hints, &res); if (res == NULL) - errx(1, "%s", gai_strerror(error)); + errx(EX_NOHOST, "cannot resolve %s: %s", + target, gai_strerror(error)); for (ai = res; ai != NULL; ai = ai->ai_next) { if (ai->ai_family == AF_INET) { freeaddrinfo(res); @@ -165,7 +169,7 @@ main(int argc, char *argv[]) } } freeaddrinfo(res); - errx(1, "Unknown host"); + errx(EX_NOHOST, "cannot resolve %s", target); #endif #ifdef INET ping4: diff --git a/sbin/ping/ping6.c b/sbin/ping/ping6.c index a71ef8a84aee..10deb57ad6bc 100644 --- a/sbin/ping/ping6.c +++ b/sbin/ping/ping6.c @@ -654,14 +654,15 @@ ping6(int argc, char *argv[]) error = cap_getaddrinfo(capdns, target, NULL, &hints, &res); if (error) - errx(1, "%s", gai_strerror(error)); + errx(EX_NOHOST, "cannot resolve %s: %s", + target, gai_strerror(error)); if (res->ai_canonname) hostname = strdup(res->ai_canonname); else hostname = target; if (!res->ai_addr) - errx(1, "cap_getaddrinfo failed"); + errx(EX_NOHOST, "cannot resolve %s", target); (void)memcpy(&dst, res->ai_addr, res->ai_addrlen); diff --git a/sbin/ping/tests/ping_test.sh b/sbin/ping/tests/ping_test.sh index 1dff25bd43a6..c30592aa7e2e 100644 --- a/sbin/ping/tests/ping_test.sh +++ b/sbin/ping/tests/ping_test.sh @@ -165,6 +165,39 @@ ping6_4_body() ping6 -4 localhost } +atf_test_case ping_nohost +ping_nohost_head() +{ + atf_set "descr" "ping a nonexistent host" +} +ping_nohost_body() +{ + atf_check -s exit:68 -e match:"cannot resolve" \ + ping nonexistent.in-addr.arpa. +} + +atf_test_case ping4_nohost +ping4_nohost_head() +{ + atf_set "descr" "ping -4 a nonexistent host" +} +ping4_nohost_body() +{ + atf_check -s exit:68 -e match:"cannot resolve" \ + ping -4 nonexistent.in-addr.arpa. +} + +atf_test_case ping6_nohost +ping6_nohost_head() +{ + atf_set "descr" "ping -6 a nonexistent host" +} +ping6_nohost_body() +{ + atf_check -s exit:68 -e match:"cannot resolve" \ + ping -6 nonexistent.in-addr.arpa. +} + atf_test_case "inject_opts" "cleanup" inject_opts_head() { @@ -227,6 +260,9 @@ atf_init_test_cases() atf_add_test_case ping_46 atf_add_test_case ping_64 atf_add_test_case ping6_4 + atf_add_test_case ping_nohost + atf_add_test_case ping4_nohost + atf_add_test_case ping6_nohost atf_add_test_case inject_opts atf_add_test_case inject_pip atf_add_test_case inject_reply