diff options
author | Sami Kerola <kerolasa@iki.fi> | 2019-09-08 15:22:36 +0100 |
---|---|---|
committer | Sami Kerola <kerolasa@iki.fi> | 2019-09-08 15:35:18 +0100 |
commit | da9a6105b2cab2f92135a282d00cc939760e64c0 (patch) | |
tree | 956ac10d59ac058755272c94968727db3b7597b8 | |
parent | 9ada40bac7bab3f3ff4f501d7362cf16c7940451 (diff) | |
download | iputils-tracepath-time.tar.gz |
arping, tracepath, traceroute6: use clock_gettime(CLOCK_MONOTONIC)tracepath-time
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 <petr.vorel@gmail.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
-rw-r--r-- | arping.c | 4 | ||||
-rw-r--r-- | tracepath.c | 4 | ||||
-rw-r--r-- | traceroute6.c | 6 |
3 files changed, 7 insertions, 7 deletions
@@ -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))) { |