From da9a6105b2cab2f92135a282d00cc939760e64c0 Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Sun, 8 Sep 2019 15:22:36 +0100 Subject: arping, tracepath, traceroute6: use clock_gettime(CLOCK_MONOTONIC) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The CLOCK_MONOTONIC_RAW does not get ntp adjustments, that can be considered as a good thing when trying to avoid time jumps.  But downside of RAW time is that it does not get adjtime(3) adjustments resulting to incorrect lenght of a time period.  After all ntp has two functions, it tries to get clock to display correct time and make it run right pace.  The later is what is what is needed when measuring time differences, so CLOCK_MONOTONIC is the indeed better choice. Sure enough an unlucky measurement might to badly wrong when in between start and end of a latency measurement adjtime(3) does an adjustment.  Due to nature of this problem these freak measurements are hard to reproduce, and hopefully rather rare.  If this really turns out to be a problem then the question should be what sort of incorrect time measurement is preferred. Reference: https://github.com/iputils/iputils/pull/213 CC: Petr Vorel Signed-off-by: Sami Kerola --- arping.c | 4 ++-- tracepath.c | 4 ++-- traceroute6.c | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/arping.c b/arping.c index 30884f6..2d05728 100644 --- a/arping.c +++ b/arping.c @@ -268,7 +268,7 @@ static int send_pack(struct run_state *ctl) memcpy(p, &ctl->gdst, 4); p += 4; - clock_gettime(CLOCK_MONOTONIC_RAW, &now); + clock_gettime(CLOCK_MONOTONIC, &now); err = sendto(ctl->socketfd, buf, p - buf, 0, (struct sockaddr *)HE, sll_len(ah->ar_hln)); if (err == p - buf) { ctl->last = now; @@ -323,7 +323,7 @@ static int recv_pack(struct run_state *ctl, unsigned char *buf, ssize_t len, unsigned char *p = (unsigned char *)(ah + 1); struct in_addr src_ip, dst_ip; - clock_gettime(CLOCK_MONOTONIC_RAW, &ts); + clock_gettime(CLOCK_MONOTONIC, &ts); /* Filter out wild packets */ if (FROM->sll_pkttype != PACKET_HOST && diff --git a/tracepath.c b/tracepath.c index dda50f6..1b5748e 100644 --- a/tracepath.c +++ b/tracepath.c @@ -171,7 +171,7 @@ static int recverr(struct run_state *const ctl) memset(&rcvbuf, -1, sizeof(rcvbuf)); msg = reset; - clock_gettime(CLOCK_MONOTONIC_RAW, &ts); + clock_gettime(CLOCK_MONOTONIC, &ts); recv_size = recvmsg(ctl->socket_fd, &msg, MSG_ERRQUEUE); if (recv_size < 0) { if (errno == EAGAIN) @@ -376,7 +376,7 @@ static int probe_ttl(struct run_state *const ctl) htons(ctl->base_port + ctl->hisptr); break; } - clock_gettime(CLOCK_MONOTONIC_RAW, &hdr->ts); + clock_gettime(CLOCK_MONOTONIC, &hdr->ts); ctl->his[ctl->hisptr].hops = ctl->ttl; ctl->his[ctl->hisptr].sendtime = hdr->ts; if (sendto(ctl->socket_fd, ctl->pktbuf, ctl->mtu - ctl->overhead, 0, diff --git a/traceroute6.c b/traceroute6.c index 880425d..d395e54 100644 --- a/traceroute6.c +++ b/traceroute6.c @@ -419,7 +419,7 @@ static void send_probe(struct run_state *ctl, uint32_t seq, int ttl) pkt->ident = htonl(ctl->ident); pkt->seq = htonl(seq); - clock_gettime(CLOCK_MONOTONIC_RAW, &pkt->ts); + clock_gettime(CLOCK_MONOTONIC, &pkt->ts); i = setsockopt(ctl->sndsock, SOL_IPV6, IPV6_UNICAST_HOPS, &ttl, sizeof(ttl)); if (i < 0) @@ -860,10 +860,10 @@ int main(int argc, char **argv) struct timespec t1, t2; struct in6_addr to_addr; - clock_gettime(CLOCK_MONOTONIC_RAW, &t1); + clock_gettime(CLOCK_MONOTONIC, &t1); send_probe(&ctl, ++seq, ttl); while ((cc = wait_for_reply(&ctl, &from, &to_addr, reset_timer)) != 0) { - clock_gettime(CLOCK_MONOTONIC_RAW, &t2); + clock_gettime(CLOCK_MONOTONIC, &t2); if ((i = packet_ok(&ctl, cc, &from, &to_addr, seq, &t1))) { if (memcmp(&from.sin6_addr, &lastaddr, sizeof(from.sin6_addr))) { -- cgit v1.2.1