/plushcap/analysis/cloudflare/the-day-my-ping-took-countermeasures

The day my ping took countermeasures

What's this blog post about?

The article discusses how the Linux command-line utility `ping` handles clock adjustments on a system, which can cause confusion due to its reliance on time measurements. The author explains that when the clock goes backwards or forwards by more than 1 second, ping displays warnings like "time of day goes back" and "taking countermeasures." While this behavior is intended as a safety measure to avoid reporting incorrect latency values, it can lead users to believe there are network issues. Ping uses the system clock for measuring time intervals between sending and receiving packets. However, when the clock changes direction due to adjustments made by Network Time Protocol (NTP) daemons or leap second events, ping may display misleading information regarding latency and packet loss rates. The author demonstrates this issue using scapy, a Python library for crafting network packets. The article suggests that ignoring clock changes might be acceptable in most cases since they are rare occurrences and difficult to test. It recommends using the CLOCK_MONOTONIC time source when possible to measure durations accurately because it is not affected by adjustments or Daylight Saving Time (DST) transitions. In conclusion, ping's handling of clock changes can cause confusion for users who may interpret its warnings as indicators of network problems rather than a response to system clock manipulations. Developers could improve the utility by using CLOCK_MONOTONIC in situations where it would provide more accurate results. As long as leap seconds remain an issue, ping will likely continue displaying countermeasures for significant clock changes. To summarize: - `ping` uses the system clock to measure latency between sending and receiving packets. - When the clock goes backwards or forwards by more than 1 second due to NTP adjustments or leap seconds, ping displays warnings like "time of day goes back" and "taking countermeasures." - Using CLOCK_MONOTONIC can help measure time durations accurately without being affected by clock changes. - Ignoring clock changes might be acceptable in most cases since they are rare occurrences and difficult to test. - Ping could potentially improve its functionality by using CLOCK_MONOTONIC instead of relying on the system clock when measuring latency, particularly during significant clock adjustments or leap seconds.

Company
Cloudflare

Date published
July 11, 2023

Author(s)
Marek Majkowski

Word count
2663

Hacker News points
20

Language
English


By Matt Makai. 2021-2024.