From nobody Sun Mar 19 16:33:29 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 4Pfk2K4Gy6z40P8j; Sun, 19 Mar 2023 16:33:29 +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 4Pfk2K3P8Lz4Tbp; Sun, 19 Mar 2023 16:33:29 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1679243609; 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=HNuPepCpaGnBRxs3JPevR2aq0TqVOMZQLVz8Um1vB64=; b=V3iB2X7ZKV12wkzWPuHehfF6XJYFQHnmQFlvvKQggV73dojVLH/a0ehWwiFsmyl4luGcMZ XN7qpu0GimUdr9s+47xZBQDt3Gn936R6R3az+CB8kGdS9QIPMzN6NI85GFBOQfnuO5q8T+ 81XrSYMIRk7qltXymRgEJGcPWE+xp8HMMBEAlLLS86aLmwmzTEqWSU2D1r7/pG5YRzCLqy 7H2fWmrxa8iwYuMGYyH6wwUGROT5uBdWHu2vHv7N8mhcQTEX6lEEiqj3KHRnIWZ2BWoGJI lFM0aF3fb4AqSGF6ulqfucjrM7VWxL6+YghVF4pucC8V9jqfhlKOr1EEL3RQpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1679243609; 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=HNuPepCpaGnBRxs3JPevR2aq0TqVOMZQLVz8Um1vB64=; b=ZdEI7uXk95QzbWURpuBLyTmnQM0EDdgz+2QvgMt7MnT5kDt2ssaIWvlgYp81LHytAoi3GE OUNuwAybtXsGEAxTYBpKWMRMkRa5NYq4S2TAGeyz5aaxfBOfDLLRWk0V7THwz00xYPsH1x 5/AWXLlFCZmwmG6M9k9e7krSPo+BmyWbrWKg68DefXLHeZ8mFQS6RkrwShoAT8OZP/a8wz RTUyQwurI9o4qi0DjS5lZVd/0HRayUFTtLUY+Xu0aE88Yn2JsKfALAdTr5qSV4dKUXBk/i YR75xyv3y1sdEjx2V4XAqjuy8RGy8zPCJiqR+CCEbRcGSEjTStuzc8dczz4CzA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1679243609; a=rsa-sha256; cv=none; b=hy/JiNJsuj7SF1cwiYLQv8LBqYkvGaPyFVSM11/tUzFmHPtpgF++WYSN3F1Fd2TyMXs1RV /KD6Q14IeCkRA68+2pKutmx6PkMPq/JqT7A3bxgMo3UOt0bq215M1djpW1s0HuRPQgvQCJ Yu3PS4wTqBaqayWFoO+Wm7c9Beh7p5Ev4dWDSFiJQVk9mzI1HnQWAuZaNpaDTh7lTDjC9k iFZDCHxpRw955Kw1vH22+49DaZ0Ti16+4zS7rtrgPQ8hVs849kXuNOhhroK2cS6N1iMyFC 4eGfuX6GJ9Yj+MOyfyvc2TSOE1LIZ8c73jGMUWd0QixhArcrtzj7krJwaQiHEw== 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 4Pfk2K2SsqzwPp; Sun, 19 Mar 2023 16:33:29 +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 32JGXT3v003232; Sun, 19 Mar 2023 16:33:29 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 32JGXT2e003231; Sun, 19 Mar 2023 16:33:29 GMT (envelope-from git) Date: Sun, 19 Mar 2023 16:33:29 GMT Message-Id: <202303191633.32JGXT2e003231@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: ea6d16926666 - main - ping: Avoid reporting negative time statistics 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: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: ea6d16926666a717e2c0a898b954d1477ac34804 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=ea6d16926666a717e2c0a898b954d1477ac34804 commit ea6d16926666a717e2c0a898b954d1477ac34804 Author: Jose Luis Duran AuthorDate: 2023-02-09 23:38:54 +0000 Commit: Mark Johnston CommitDate: 2023-03-19 16:24:06 +0000 ping: Avoid reporting negative time statistics Display a warning when the time goes back. PR: 192417 Reviewed by: markj MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D38480 --- sbin/ping/ping.c | 8 +++++++- sbin/ping/tests/test_ping.py | 30 +++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/sbin/ping/ping.c b/sbin/ping/ping.c index 299b582e29c1..6b82fe3da9de 100644 --- a/sbin/ping/ping.c +++ b/sbin/ping/ping.c @@ -1212,8 +1212,14 @@ pr_pack(char *buf, ssize_t cc, struct sockaddr_in *from, struct timespec *tv) tv1.tv_sec = ntohl(tv32.tv32_sec); tv1.tv_nsec = ntohl(tv32.tv32_nsec); timespecsub(tv, &tv1, tv); - triptime = ((double)tv->tv_sec) * 1000.0 + + triptime = ((double)tv->tv_sec) * 1000.0 + ((double)tv->tv_nsec) / 1000000.0; + if (triptime < 0) { + warnx("time of day goes back (%.3f ms)," + " clamping time to 0", + triptime); + triptime = 0; + } tsum += triptime; tsumsq += triptime * triptime; if (triptime < tmin) diff --git a/sbin/ping/tests/test_ping.py b/sbin/ping/tests/test_ping.py index 7040faa71a5d..f1c961c5b551 100644 --- a/sbin/ping/tests/test_ping.py +++ b/sbin/ping/tests/test_ping.py @@ -268,6 +268,7 @@ def redact(output): ("hlim=[0-9]*", "hlim="), ("ttl=[0-9]*", "ttl="), ("time=[0-9.-]*", "time="), + ("\(-[0-9\.]+[0-9]+ ms\)", "(- ms)"), ("[0-9\.]+/[0-9.]+", "/"), ] for pattern, repl in pattern_replacements: @@ -1209,6 +1210,32 @@ ping: quoted data too short (28 bytes) from 192.0.2.2 }, id="_3_1_special_udp", ), + pytest.param( + { + "src": "192.0.2.1", + "dst": "192.0.2.2", + "icmp_type": 0, + "icmp_code": 0, + "special": "warp", + }, + { + "returncode": 0, + "stdout": """\ +PATTERN: 0x01 +PING 192.0.2.2 (192.0.2.2): 56 data bytes +64 bytes from: icmp_seq=0 ttl= time= ms + +--- 192.0.2.2 ping statistics --- +1 packets transmitted, 1 packets received, 0.0% packet loss +round-trip min/avg/max/stddev = /// ms +""", + "stderr": """\ +ping: time of day goes back (- ms), clamping time to 0 +""", + "redacted": True, + }, + id="_0_0_special_warp", + ), ] @pytest.mark.parametrize("pinger_kargs, expected", pinger_testdata) @@ -1221,6 +1248,7 @@ ping: quoted data too short (28 bytes) from 192.0.2.2 assert ping.returncode == expected["returncode"] if expected["redacted"]: assert redact(ping.stdout) == expected["stdout"] + assert redact(ping.stderr) == expected["stderr"] else: assert ping.stdout == expected["stdout"] - assert ping.stderr == expected["stderr"] + assert ping.stderr == expected["stderr"]