Page MenuHomeFreeBSD

ping6: Annotate truncating of time values saved in a packet

Authored by asomers on Aug 12 2019, 7:30 AM.



Annotate truncating of time values saved in a packet

Submitted by: Ján Sučan <>
Sponsored by: Google, inc. (Google Summer of Code 2019)

Diff Detail

Lint OK
No Unit Test Coverage
Build Status
Buildable 25793
Build 24365: arc lint + arc unit

Event Timeline

jansucan created this revision.Aug 12 2019, 7:30 AM
asomers added inline comments.Aug 12 2019, 7:21 PM

Yeah they're truncated. That much is clear from the cast. But why?

jansucan added inline comments.Aug 13 2019, 4:13 AM

Please, tell me what's the correct comment. Or should remove it?

A useful comment would tell the reader why it's ok to truncate the time in this case. Usually, that would be very bad. But in this case, we're only concerned about the difference between two close timespecs. Dropping the MSB from both samples won't affect their difference[1]. So a useful comment would say something like "Truncate seconds down to 32 bits in order to fit the timestamp within 8 bytes of the packet. We're only concerned with durations, not absolute times".

[1] Actually, it could affect the difference once every 68 years or so. But your other commit, which replaces gettimeofday with clock_gettime, will mostly fix that. CLOCK_MONOTONIC is implemented by measuring seconds since boot. So then ping6 will only have a problem after 68 years of _uptime_.

In fact, maybe you should combine this revision with the clock_gettime change. The combination is more correct than this change alone.

The revision has been combined.

asomers commandeered this revision.Aug 13 2019, 4:26 PM
asomers abandoned this revision.
asomers edited reviewers, added: jansucan; removed: asomers.

Closing in favor of D21226