aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier Cochard <olivier@FreeBSD.org>2026-05-28 10:40:48 +0000
committerOlivier Cochard <olivier@FreeBSD.org>2026-05-28 10:40:48 +0000
commitff873565bc2c3e47fe1d070305aa851189ee8bcf (patch)
tree71d1fa9da89448c280fbb6b8fefb72b5dc853220
parentd62e8c5c6fdc9e3b006bf126e1fb863e8bdd6c51 (diff)
ping: fix test timestamp_origin when tstamprepl is disabled
The timestamp_origin test sends an ICMP Timestamp Request (ping -Mt) and parses the tso/tsr fields out of the reply. When the sysctl net.inet.icmp.tstamprepl is 0, the kernel silently drops the request, ping receives no reply, and the sed extraction yields an empty $tso. The test then fails inside atf_check test -n "$tso" with the unhelpful message Approved by: maxim Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D57287
-rw-r--r--sbin/ping/tests/ping_test.sh16
1 files changed, 15 insertions, 1 deletions
diff --git a/sbin/ping/tests/ping_test.sh b/sbin/ping/tests/ping_test.sh
index af700615dc8d..ab45ad809a52 100644
--- a/sbin/ping/tests/ping_test.sh
+++ b/sbin/ping/tests/ping_test.sh
@@ -253,14 +253,22 @@ inject_reply_cleanup()
ifconfig `cat tun.txt` destroy
}
-atf_test_case timestamp_origin
+atf_test_case timestamp_origin cleanup
timestamp_origin_head()
{
atf_set "descr" "ICMP Originate Timestamp"
+ atf_set "require.user" "root"
+ atf_set "require.config" "allow_sysctl_side_effects"
}
timestamp_origin_body()
{
require_ipv4
+ # The kernel only replies to ICMP timestamp requests when
+ # net.inet.icmp.tstamprepl is enabled. Save the current value
+ # so the cleanup hook can restore it, then enable replies.
+ sysctl -n net.inet.icmp.tstamprepl > tstamprepl.txt
+ sysctl net.inet.icmp.tstamprepl=1
+
# Run ping timestamp
out=$(ping -Mt -c1 127.0.0.1)
@@ -286,6 +294,12 @@ timestamp_origin_body()
atf_fail "tso ($tso) differs from tsr ($tsr) by $diff seconds"
fi
}
+timestamp_origin_cleanup()
+{
+ if [ -f tstamprepl.txt ]; then
+ sysctl net.inet.icmp.tstamprepl=`cat tstamprepl.txt`
+ fi
+}
atf_init_test_cases()
{