From nobody Thu Oct 22 00:45:42 2026 X-Original-To: dev-commits-src-branches@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 4j96rk6XcBz6wqQy for ; Thu, 22 Oct 2026 00:45:42 +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) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4j96rk5fnGz3Lv6 for ; Thu, 22 Oct 2026 00:45:42 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1792629942; 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=y09AI73u+EVQEK/cod9GWETyKQFfi8fDGh8KWU21ZfQ=; b=LMUa1T+Tj6fkrhXjaquaI0IfiOPoFoymKJkYG9dXeIfadEhsTg12KeMB0egmU/iD2qTL2k KmApnYp8NYbSfs3DJZCVosw6hrlmxxMZOM9HoPZFeTHDZTlYJAaCR8DX4A+QNMVBLzgArg zUEv0n4CLhhY4ncVQFmxPPp7ZXE3yfSaXU8oai+GIUXG/0tXfxXCkeUfqINQJSmTOt85TQ YV1kTBWoCiG4MAllI9VZxFdcG/Z5EyDkofeHH6LrCCpSgDRwwvHFLwdU05Zvkmlj6DfG95 wpHbMULJ3fxcDKBT7ZkDqkXc77KcuMTIWnP6jOy9BtLCT3s4yNWjyOQ8iApfsA== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1792629942; b=G97p0FJvbdlA0tuvYbYpvbRCm8aD0uP3+b1WkD5sy+wVMfLhbRCii/7u+OMXOh0UpQfgaR BtLlLZxAzCDA7Iwc1na/Emv8HYvDH1fJZTZNgiAS6steg9de2wSQWFTptiB+AQyqApwAMG Zb1IvZSXHYh3CUjgyR9iOAzgYQMkij5eAcZoV7gqqRZ8nDupZV06/K2QvD2UiA/RX/9mGY oQxF2mnxCasG1nLq3pjStxmYkC7IfVXYu8DKo2olMRsPs4qfDYZU9VSVOEc5e+xScDVRxn o0ldETIreeZMLw1EDZTsjg+bD+9ukGUNA4ENwBYrxBn/WsyN6NyaILqJ3HfJXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1792629942; 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=y09AI73u+EVQEK/cod9GWETyKQFfi8fDGh8KWU21ZfQ=; b=Fki1xOtQntROpBK2t58zqbEoHmJ7lKQuOGOjT4sXFAfzklm3CEkD6HRFbcUbkzLrYNQiTM ZsOgRv7hpdK0Md3Q3sAoufwfT7PCT+Fw1+ty+LYC+DyIhsWs9GiGX74HAtOfV7hhW/hd4b iKCmlPpkABsUf7KzsGHA4Jqf3PKMjhLlogwZMe3UkiOSlADUjZrckwr/DjTy9r6CNPzvcI r4FbVVIogxGD6z4JBtZyFGR6yqVCaeyck7bqZpU5oh5AeaxKMzIBKkO+XHIeOIu+sfSmpb 1A5uL6H+Cic/O21jlvce1w/YGvVnGV1KIsCmKQH6QanQU7DJIetqXsw1tdLcZw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4j96rk51f4zH0R for ; Thu, 22 Oct 2026 00:45:42 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 40d8b by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Thu, 22 Oct 2026 00:45:42 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Maxim Konovalov Subject: git: 6c604ba42861 - stable/15 - ping: use CLOCK_REALTIME for ICMP Originate Timestamp List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org List-Id: Commits to the stable branches of the FreeBSD src repository List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: maxim X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: 6c604ba42861812895f464264bfd0f27a647f81d Auto-Submitted: auto-generated Date: Thu, 22 Oct 2026 00:45:42 +0000 Message-Id: <6ad95cb6.40d8b.4b38206a@gitrepo.freebsd.org> The branch stable/15 has been updated by maxim: URL: https://cgit.FreeBSD.org/src/commit/?id=6c604ba42861812895f464264bfd0f27a647f81d commit 6c604ba42861812895f464264bfd0f27a647f81d Author: Maxim Konovalov AuthorDate: 2026-05-01 17:45:27 +0000 Commit: Maxim Konovalov CommitDate: 2026-10-22 00:41:37 +0000 ping: use CLOCK_REALTIME for ICMP Originate Timestamp RFC 792 defines the ICMP Originate Timestamp field as milliseconds since midnight UTC. However, ping(8) currently derives this value from CLOCK_MONOTONIC, which represents time since an unspecified starting point and is not related to UTC. The issue was introduced by commit 1ad76f1b6047, which replaced gettimeofday(2) with clock_gettime(CLOCK_MONOTONIC) for timekeeping in ping(8). Fix this by using CLOCK_REALTIME when generating the ICMP originate timestamp. Before: $ ping -Mt -c1 127.0.0.1 ICMP_TSTAMP PING 127.0.0.1 (127.0.0.1): 56 data bytes <...> time=0.061 ms tso=16:50:31 tsr=17:38:28 tst=17:38:28 (note the tso is off) After: $ ping -Mt -c1 127.0.0.1 ICMP_TSTAMP PING 127.0.0.1 (127.0.0.1): 56 data bytes <...> time=0.038 ms tso=17:42:09 tsr=17:42:09 tst=17:42:09 Reviewed by: asomers, glebius Fixes: 1ad76f1b6047 MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D56759 (cherry picked from commit 069681afd58a711eb7407be4a9c9a05f787d250f) --- sbin/ping/ping.c | 9 ++++++++- sbin/ping/tests/ping_test.sh | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/sbin/ping/ping.c b/sbin/ping/ping.c index b7043eee1709..362561f246e8 100644 --- a/sbin/ping/ping.c +++ b/sbin/ping/ping.c @@ -1031,9 +1031,16 @@ pinger(void) */ tv32.tv32_sec = (uint32_t)htonl(now.tv_sec); tv32.tv32_nsec = (uint32_t)htonl(now.tv_nsec); - if (options & F_TIME) + if (options & F_TIME) { + /* + * However, per RFC 792 the Originate Timestamp (otime) + * should be milliseconds since midnight UTC. Something, + * that CLOCK_MONOTONIC does not guarantee. + */ + (void)clock_gettime(CLOCK_REALTIME, &now); icp.icmp_otime = htonl((now.tv_sec % (24*60*60)) * 1000 + now.tv_nsec / 1000000); + } if (timing) bcopy((void *)&tv32, (void *)&outpack[ICMP_MINLEN + phdr_len], diff --git a/sbin/ping/tests/ping_test.sh b/sbin/ping/tests/ping_test.sh index 5a12ace104d7..6e090cfd945a 100644 --- a/sbin/ping/tests/ping_test.sh +++ b/sbin/ping/tests/ping_test.sh @@ -253,6 +253,40 @@ inject_reply_cleanup() ifconfig `cat tun.txt` destroy } +atf_test_case timestamp_origin +timestamp_origin_head() +{ + atf_set "descr" "ICMP Originate Timestamp" +} +timestamp_origin_body() +{ + require_ipv4 + # Run ping timestamp + out=$(ping -Mt -c1 127.0.0.1) + + # Extract tso and tsr + tso=$(echo "$out" | sed -n 's/.*tso=\([0-9:]*\).*/\1/p') + tsr=$(echo "$out" | sed -n 's/.*tsr=\([0-9:]*\).*/\1/p') + + atf_check test -n "$tso" + atf_check test -n "$tsr" + + # Convert tso and tsr from HH:MM:SS to seconds + tso_s=`date -jf %H:%M:%S $tso` + tsr_s=`date -jf %H:%M:%S $tsr` + + diff=$((tso_s - tsr_s)) + # Tolerate negative time difference between the sender and receiver + if [ $diff -lt 0 ]; then + diff=$(( -diff )) + fi + + # Tolerate 2 seconds difference + if [ $diff -gt 2 ]; then + atf_fail "tso ($tso) differs from tsr ($tsr) by $diff seconds" + fi +} + atf_init_test_cases() { atf_add_test_case ping_c1_s56_t1 @@ -271,6 +305,7 @@ atf_init_test_cases() atf_add_test_case inject_opts atf_add_test_case inject_pip atf_add_test_case inject_reply + atf_add_test_case timestamp_origin } check_ping_statistics()