From nobody Fri May 27 12:16:48 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 022F01B3C0FA; Fri, 27 May 2022 12:16:49 +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 4L8kLm6bjkz4pQn; Fri, 27 May 2022 12:16:48 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1653653808; 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=k9B/tdFSyfhqqEmAnr0BwBZwwebB/esWFny8OVYpbis=; b=iSSB+a3q47f2KxsomzpfnVtqFbvec9adrXJWXEhbXuKfw/VUTCFMP9xHuuLaPUFUhldT8l JE5qbr42McB6GXhTi4YkI4+uaQtE6cQ0jC60uTJwp7A0PgwTsuW+DDUZnJMltvsw7fkU7d IES2+qCJtXGyzGAKe2ffRT8aplDpjNsaYeM/1QXh6R3I8kLkV/rDt4AZourQDyfdb1VWZz VrdK+i3aiDWWYqHEic6OcHILzByoEJVL6dL9+EWM5hCRHl/yyURySu2pnDtMY/kFKQ6N+L WyxrOWEqNGSWK1lpMelgX0vm8d2gsyGpYv/DLWAJFKkS/VpTi5CBJHXQN2vZcg== 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 C181A220DF; Fri, 27 May 2022 12:16:48 +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 24RCGm86059289; Fri, 27 May 2022 12:16:48 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 24RCGmKs059288; Fri, 27 May 2022 12:16:48 GMT (envelope-from git) Date: Fri, 27 May 2022 12:16:48 GMT Message-Id: <202205271216.24RCGmKs059288@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: e23a0f521f68 - stable/13 - ping: if -S srcaddr uses a numeric address, use that protocol 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: e23a0f521f68c8385d5b98897cf0135dc9bac78a Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1653653808; 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=k9B/tdFSyfhqqEmAnr0BwBZwwebB/esWFny8OVYpbis=; b=NKKFBrLgztIAJ0mm1r+/jCcd59xZU90Ch7l8Ul4zhZSU5dN1+VB4jkpszDH8Q4ysdvkYbz zcWjRRvlHWHcWFkEii3XoRE52w/rfAN6ME98brxoQkcRh/oDDxc4LGEiFiqK1QmRVkIMb1 qxVd8NR8CmLyZc6vLIyTLWfRdRWGSIagfvos/agNV71XBtaRG/nQiRW10452ZysdT1k3z0 S9Nc44HxHWy48yhefGT/uTB7d3r7G40Js4XGolxrfvPlxUCue4Y7qOoFXOpjeyFJ1TI0KC 831frZt9YgT4FiTxNOWw1OzJqoTRpcJ80T+pLBMzP/Q/cBDR652X5SGWb5WcbQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1653653808; a=rsa-sha256; cv=none; b=qi5z2nw/biS7+ylyprng2vZMks0dhBuR0+TcpJBZx3f8eeVbqwU5ThEe6kJnsdnfNPbvYx Eygg27MyWFStym1IQ9MpT2r+UB6KnRs0PzVDJE8xazpTbUY0LlHEt9fA+VvNFUrBzTbDfw FatmFnD9Y7p9KRAdtKBoIrBWqpbTr2eyvufzGDOCg9WmE2MpIsObf02+JBMTR8SwZgYd1R 80WfzW8AqVPLBkjCrgjvVZtHc3Scco7xjpkvXs/bXLJUknQmkxRcN1Z9kjxhEmb6ju0f9k enmnfa6ypYuf97fmh2z7P+u6kzg/qHkMzgGH8z7DoAc/KTunbWHofu9zaVufyw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by karels: URL: https://cgit.FreeBSD.org/src/commit/?id=e23a0f521f68c8385d5b98897cf0135dc9bac78a commit e23a0f521f68c8385d5b98897cf0135dc9bac78a Author: Mike Karels AuthorDate: 2022-05-20 14:16:01 +0000 Commit: Mike Karels CommitDate: 2022-05-27 12:11:46 +0000 ping: if -S srcaddr uses a numeric address, use that protocol The command "ping -S dotted.quad hostname" fails on dual-stack hosts with the confusing message "ping: invalid source address: Name does not resolve" because IPv6 is selected in preference. If the argument to -S is numeric (likely), select the corresponding address family, as if -4 or -6 was specified. Add tests that either IPv4 or IPv6 can be forced via a -S parameter. Reviewed by: asomers Differential Revision: https://reviews.freebsd.org/D35271 (cherry picked from commit 5af718a5927a9e078201ebc7ad1310e5b4918b7a) --- sbin/ping/main.c | 12 ++++++++++++ sbin/ping/tests/ping_c1_s56_t1_S127.out | 6 ++++++ sbin/ping/tests/ping_c1_s8_t1_S1.out | 6 ++++++ sbin/ping/tests/ping_test.sh | 26 ++++++++++++++++++++++++++ 4 files changed, 50 insertions(+) diff --git a/sbin/ping/main.c b/sbin/ping/main.c index 1d0b714f1480..11fa17b5ce2d 100644 --- a/sbin/ping/main.c +++ b/sbin/ping/main.c @@ -93,6 +93,18 @@ main(int argc, char *argv[]) case '6': ipv6 = true; break; +#endif +#if defined(INET) && defined(INET6) + case 'S': + /* + * If -S is given with a numeric parameter, + * force use of the corresponding version. + */ + if (inet_pton(AF_INET, optarg, &a) == 1) + ipv4 = true; + else if (inet_pton(AF_INET6, optarg, &a) == 1) + ipv6 = true; + break; #endif default: break; diff --git a/sbin/ping/tests/ping_c1_s56_t1_S127.out b/sbin/ping/tests/ping_c1_s56_t1_S127.out new file mode 100644 index 000000000000..07d90918293b --- /dev/null +++ b/sbin/ping/tests/ping_c1_s56_t1_S127.out @@ -0,0 +1,6 @@ +PING localhost from: 56 data bytes +64 bytes from: icmp_seq=0 ttl= time= ms + +--- localhost ping statistics --- +1 packets transmitted, 1 packets received, 0.0% packet loss +round-trip min/avg/max/stddev = /// ms diff --git a/sbin/ping/tests/ping_c1_s8_t1_S1.out b/sbin/ping/tests/ping_c1_s8_t1_S1.out new file mode 100644 index 000000000000..81c56e6cf586 --- /dev/null +++ b/sbin/ping/tests/ping_c1_s8_t1_S1.out @@ -0,0 +1,6 @@ +PING6(56=40+8+8 bytes) ::1 --> ::1 +16 bytes from ::1, icmp_seq=0 hlim= time= ms + +--- localhost ping6 statistics --- +1 packets transmitted, 1 packets received, 0.0% packet loss +round-trip min/avg/max/std-dev = /// ms diff --git a/sbin/ping/tests/ping_test.sh b/sbin/ping/tests/ping_test.sh index 54af89f4a22b..7f11af7e9818 100644 --- a/sbin/ping/tests/ping_test.sh +++ b/sbin/ping/tests/ping_test.sh @@ -49,6 +49,18 @@ ping_c1_s56_t1_body() { check_ping_statistics std.out $(atf_get_srcdir)/ping_c1_s56_t1.out } +atf_test_case ping_c1_s56_t1_S127 +ping_c1_s56_t1_S127_head() { + atf_set "descr" "Check that ping -S 127.0.0.1 localhost succeeds" +} +ping_c1_s56_t1_S127_body() { + require_ipv4 + require_ipv6 + atf_check -s exit:0 -o save:std.out -e empty \ + ping -c 1 -s 56 -t 1 -S 127.0.0.1 localhost + check_ping_statistics std.out $(atf_get_srcdir)/ping_c1_s56_t1_S127.out +} + atf_test_case ping_6_c1_s8_t1 ping_6_c1_s8_t1_head() { atf_set "descr" "Stop after receiving 1 ECHO_RESPONSE packet" @@ -60,6 +72,18 @@ ping_6_c1_s8_t1_body() { check_ping_statistics std.out $(atf_get_srcdir)/ping_6_c1_s8_t1.out } +atf_test_case ping_c1_s8_t1_S1 +ping_c1_s8_t1_S1_head() { + atf_set "descr" "Check that ping -S ::1 localhost succeeds" +} +ping_c1_s8_t1_S1_body() { + require_ipv4 + require_ipv6 + atf_check -s exit:0 -o save:std.out -e empty \ + ping -c 1 -s 8 -t 1 -S ::1 localhost + check_ping_statistics std.out $(atf_get_srcdir)/ping_c1_s8_t1_S1.out +} + atf_test_case ping6_c1_s8_t1 ping6_c1_s8_t1_head() { atf_set "descr" "Use IPv6 when invoked as ping6" @@ -104,7 +128,9 @@ ping6_46_body() { atf_init_test_cases() { atf_add_test_case ping_c1_s56_t1 + atf_add_test_case ping_c1_s56_t1_S127 atf_add_test_case ping_6_c1_s8_t1 + atf_add_test_case ping_c1_s8_t1_S1 atf_add_test_case ping6_c1_s8_t1 atf_add_test_case ping_c1t6 atf_add_test_case ping6_c1t4