lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <alpine.DEB.1.10.1009051521120.13886@red.crap.retrofitta.se>
Date:	Sun, 5 Sep 2010 15:25:32 +0200 (CEST)
From:	Thomas Habets <thomas@...ets.pp.se>
To:	Jan Ceuleers <jan.ceuleers@...puter.org>
cc:	Thomas Habets <thomas@...ets.pp.se>, netdev@...r.kernel.org
Subject: Re: [PATCH] iputils ping,ping6: use monotonic clock to schedule
 pings

On Sun, 5 Sep 2010, Jan Ceuleers wrote:
>> +int
>> +getclock(struct timeval *tv)
>> +{
>> +#ifdef CLOCK_MONOTONIC
>> + struct timespec ts;
>> + if (!clock_gettime(CLOCK_MONOTONIC, &ts)) {
>> + tv->tv_sec = ts.tv_sec;
>> + tv->tv_usec = ts.tv_nsec / 1000;
>> + return;
>> + }
>> +#endif
>
> Don't you need a return value there?

Good thing *somebody is awake*. Yes. 0. The return value is not actually
checked anywhere (nor was the gettimeofday() calls I replaced), but I 
added it because I felt it should have a return value in the future, and 
one that matched gettimeofday().

Thanks.

Fixed version:

-----------

This fixes the problem where when time is set backwards 'ping' appears
to freeze until the walltime catches up with the previously set time.

Adds dependency on librt.

diff --git a/Makefile b/Makefile
index 42f8475..a6812a3 100644
--- a/Makefile
+++ b/Makefile
@@ -28,8 +28,8 @@ all: $(TARGETS)

  tftpd: tftpd.o tftpsubs.o
  arping: arping.o -lsysfs
-ping: ping.o ping_common.o
-ping6: ping6.o ping_common.o -lresolv -lcrypto
+ping: ping.o ping_common.o -lrt
+ping6: ping6.o ping_common.o -lresolv -lcrypto -lrt
  ping.o ping6.o ping_common.o: ping_common.h
  tftpd.o tftpsubs.o: tftp.h

diff --git a/ping_common.c b/ping_common.c
index e0edf39..5883e63 100644
--- a/ping_common.c
+++ b/ping_common.c
@@ -304,6 +304,20 @@ void print_timestamp(void)
         }
  }

+int
+getclock(struct timeval *tv)
+{
+#ifdef CLOCK_MONOTONIC
+       struct timespec ts;
+       if (!clock_gettime(CLOCK_MONOTONIC, &ts)) {
+               tv->tv_sec = ts.tv_sec;
+               tv->tv_usec = ts.tv_nsec / 1000;
+               return 0;
+       }
+#endif
+       return gettimeofday(tv, NULL);
+}
+
  /*
   * pinger --
   *     Compose and transmit an ICMP ECHO REQUEST packet.  The IP packet
@@ -324,13 +338,13 @@ int pinger(void)

         /* Check that packets < rate*time + preload */
         if (cur_time.tv_sec == 0) {
-               gettimeofday(&cur_time, NULL);
+               getclock(&cur_time);
                 tokens = interval*(preload-1);
         } else {
                 long ntokens;
                 struct timeval tv;

-               gettimeofday(&tv, NULL);
+               getclock(&tv);
                 ntokens = (tv.tv_sec - cur_time.tv_sec)*1000 +
                         (tv.tv_usec-cur_time.tv_usec)/1000;
                 if (!interval) {

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ