From nobody Sat May 2 03:17:38 2026 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 4g6tQ01Vgtz6cTNw for ; Sat, 02 May 2026 03:17:44 +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 "R13" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4g6tPz6FNsz3K3g for ; Sat, 02 May 2026 03:17:43 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1777691864; 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=hu8WBRoLOgq9UQp314TyLZ0HOWFdmSAOwKapVmhGeXg=; b=xCWNMibHsTOgrMvlsSH6qFAPMvNtNX+kvPqwnNpWCfFpPg7010C6lDZn+Zw0mSbjF/L7b+ Ludq5ClXXuNIdsmWEPIe6AXDsPh9HxYrJM1Dv/1umpe5/Jz9jH02erJH2HCye9QeRSrcMn enn8Vidk8wIDlKSUQls1UM0j0LveqPTe7s27gwUzNgHsaQXe1pxSW3JeYM1SZRdGnH+8wq aKtU/aCe+xF6z5SCwUG9I1EYCxsVCLitvlmxBQFT+5bERg4go38q9uCVyVnsmpfOqtfSyk Zs6aqR/tkr/EvufuPtfUpfRSXMQr0Gw3gbXBQ8hBKdzqm8mPGFURxH+o9DKYCg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1777691864; a=rsa-sha256; cv=none; b=XqZnqHrM1JqmvBOW/MXnCWjVbeGax8E8GrqvGn9aNnC3wvzggIqAGR7+oteyCvb4LNOhgT 4G2mAxDfZ1ZNFCcwCHOTmwTrbghoA4axJ2FTWLcFutn+24maXDyh1GjuGX92nECLHGTjrX bdoo61c7x/vboC92S5yMuasTqiBxLcCf4hq2d/XcY0RFchSrPIv0KWY/YF1KGROYzZYZ4g GMsfc5W1zNUJULTW0noMpkvVtWyME06tbEucyZbie+elJXDaqQejPHo8juojwIBIJAwtel Mzlw44ay6TYZH265CEh2iQq8oFVCOzWI+euqsZL8M6iO+xb0eo1E89dfh8bmkg== 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=1777691864; 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=hu8WBRoLOgq9UQp314TyLZ0HOWFdmSAOwKapVmhGeXg=; b=tjE0EdhEL70DqOVrnotZaLw71RO06bunPYth6Qt1504FFCndpXBS3gJZpzELsCmBho+ska u0gBiNJNrcHvmfhNgUxrwczqwRiLO1NYdPDDs8MhfsQbNtJtut0lmf/sL0i84Pnb9hdApC rrIwVCwPZa4SxpNv3vot5kfG1Lg1yd/zh69z6Bf02zHa9LQN26Aj2k9V+g9Ljhg++6DERW xHn3Xj35N3SotTNoBf01KSQ/d5sSGiXbl/w2NWA7RevKDVJ4PWorZv+ZdSmGo6F7UfkJi7 yj80NgDCjATxaBUloBLKOakDxV/QAqubIYeRgJMYcO2r6FyFIarSVyBnKKTngg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4g6tPz5s2nzC2J for ; Sat, 02 May 2026 03:17:43 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 44fd1 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Sat, 02 May 2026 03:17:38 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Maxim Konovalov Subject: git: 069681afd58a - main - ping: use CLOCK_REALTIME for ICMP Originate Timestamp 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: maxim X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 069681afd58a711eb7407be4a9c9a05f787d250f Auto-Submitted: auto-generated Date: Sat, 02 May 2026 03:17:38 +0000 Message-Id: <69f56cd2.44fd1.7be2d8f3@gitrepo.freebsd.org> The branch main has been updated by maxim: URL: https://cgit.FreeBSD.org/src/commit/?id=069681afd58a711eb7407be4a9c9a05f787d250f commit 069681afd58a711eb7407be4a9c9a05f787d250f Author: Maxim Konovalov AuthorDate: 2026-05-01 17:45:27 +0000 Commit: Maxim Konovalov CommitDate: 2026-05-02 03:16:55 +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 --- 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 d10e3c85c9bd..579ecb9151bb 100644 --- a/sbin/ping/ping.c +++ b/sbin/ping/ping.c @@ -1029,9 +1029,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()