[Git][NTPsec/ntpsec][master] 4 commits: Remove unused MY_get_cipherbyname in ntp_auth.h

Hal Murray gitlab at mg.gitlab.com
Tue Jan 8 03:51:47 UTC 2019


Hal Murray pushed to branch master at NTPsec / ntpsec


Commits:
b8b61d6f by Hal Murray at 2019-01-08T03:50:58Z
Remove unused MY_get_cipherbyname in ntp_auth.h

- - - - -
54e700a5 by Hal Murray at 2019-01-08T03:50:58Z
Fix outcount logging in rawstats

It was getting cleared before logging thus making logging useless.

- - - - -
6343b96b by Hal Murray at 2019-01-08T03:50:58Z
Add attic/clocks - hack to collect info on clock_gettime timing

- - - - -
15b0c8a2 by Hal Murray at 2019-01-08T03:50:58Z
Cleanup tests/option-tester and python3-tester

Remove binary testing - now done by waf check
Make pipefail optional - big warning if not available

- - - - -


7 changed files:

- attic/README
- + attic/clocks.c
- attic/wscript
- include/ntp_auth.h
- ntpd/ntp_proto.c
- tests/option-tester.sh
- tests/python3-tester.sh


Changes:

=====================================
attic/README
=====================================
@@ -1,7 +1,8 @@
 = README file for directory attic/ =
 
 This is a dusty attic containing code we have not quite decided to
-discard.  Programs in it are not installed by default. Not much
+discard and chunks of code that may be useful is exploring performance
+or corner cases.  Programs in it are not installed by default. Not much
 documentation, alas.  Read the header comments.
 
 calc_tickadj::	Calculates "optimal" value for tick given ntp.drift file
@@ -12,6 +13,10 @@ digest-find.c::	Hack to see if various digests are supported by OpenSSL
 digest-timing.c:: Hack to measure execution times for various digests
 		and key lengths
 
+clocks::	Hack to measure properties of system clocks.
+
+		and key lengths
+
 kern.c:: 	Header comment from deep in the mists of past time says:
 		"This program simulates a first-order, type-II
 		phase-lock loop using actual code segments from


=====================================
attic/clocks.c
=====================================
@@ -0,0 +1,196 @@
+/* Last modified on Sat Aug 28 14:30:11 PDT 1999 by murray */
+
+#include <errno.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <time.h>
+
+struct table {
+  const int type;
+  const char* name;
+};
+
+#define BATCHSIZE 1000000
+#define BILLION 1000000000
+#define HISTSIZE 250
+
+struct table clocks [] = {
+  {CLOCK_REALTIME, "CLOCK_REALTIME"},
+#ifdef CLOCK_REALTIME_COARSE
+  {CLOCK_REALTIME_COARSE, "CLOCK_REALTIME_COARSE"},
+#endif
+#ifdef CLOCK_MONOTONIC
+  {CLOCK_MONOTONIC, "CLOCK_MONOTONIC"},
+#endif
+#ifdef CLOCK_MONOTONIC_RAW
+  {CLOCK_MONOTONIC_RAW, "CLOCK_MONOTONIC_RAW"},
+#endif
+#ifdef CLOCK_BOOTTIME
+  {CLOCK_BOOTTIME, "CLOCK_BOOTTIME"},
+#endif
+  {0, NULL}
+};
+
+/* This is the number of paired reads with no change in time. */
+/* Hack: Making this global avoids returning more than one item.  */
+int dups;
+
+int do_res(int type, const char* name);
+int do_average(int type, const char* name);
+int do_fastest(int type, const char* name);
+void do_hist(int type, int fastest);
+
+int do_res(int type, const char* name) {
+  int err;
+  struct timespec ts;
+
+  err = clock_getres(type, &ts);
+  if (-1 == err) {
+    printf("clock_getres(%s) didn't work, err %d\n", name, errno);
+    return -1;
+  }
+  return ts.tv_nsec;
+}
+
+int do_average(int type, const char* name) {
+  int err, i;
+  struct timespec start, stop;
+  uint64_t sec, nanos;
+
+  err = clock_gettime(type, &start);
+  if (-1 == err) {
+    printf("clock_gettime(%s) didn't work, err %d\n", name, errno);
+    return -1;
+  }
+
+  clock_gettime(CLOCK_REALTIME, &start);
+  for (i = 0; i < BATCHSIZE; i++) {
+    clock_gettime(type, &stop);
+  }
+  clock_gettime(CLOCK_REALTIME, &stop);
+
+  /* Beware of overflowing 32 bits. */
+  sec = (stop.tv_sec-start.tv_sec);
+  nanos = sec*BILLION + (stop.tv_nsec-start.tv_nsec);
+  return nanos/BATCHSIZE;
+
+}
+
+int do_fastest(int type, const char* name) {
+  int i;
+  struct timespec start, stop;
+  uint64_t sec, nanos, fastest;
+
+  (void)name;  /* Squash unused warnings */
+
+  dups = 0;
+  fastest = 999999999;
+  for (i = 0; i < BATCHSIZE; i++) {
+    clock_gettime(type, &start);  /* warm up caches */
+    clock_gettime(type, &start);
+    clock_gettime(type, &stop);
+    sec = (stop.tv_sec-start.tv_sec);
+    nanos = sec*BILLION + (stop.tv_nsec-start.tv_nsec);
+    if (0 == nanos) {
+        /* I've seen this on Pi 1. */
+        dups++;
+        continue;
+    }
+    if (nanos < fastest) fastest = nanos;
+  }
+
+  return fastest;
+}
+
+void do_hist(int type, int fastest) {
+  int nsPerBucket = 5;
+  int i;
+  int delta, lines, toobig, hits, miss;
+  struct timespec start, stop;
+  uint64_t sec, nanos;
+  unsigned int hist[HISTSIZE];
+
+  dups = 0;
+  toobig = 0;
+  for (i = 0; i < HISTSIZE; i++) hist[i] = 0;
+
+  for (i = 0; i < BATCHSIZE; i++) {
+    clock_gettime(type, &start);
+    clock_gettime(type, &stop);
+    sec = (stop.tv_sec-start.tv_sec);
+    nanos = sec*BILLION + (stop.tv_nsec-start.tv_nsec);
+    if (0 == nanos) {
+      /* I've seen this on Pi 1. */
+      dups++;
+      continue;
+    }
+    delta = (nanos-fastest) / nsPerBucket;
+    if (0 > delta) {
+      /* fastest wasn't fast enough. */
+      printf("Too small: %ld, %d\n", (long)nanos, fastest);
+      continue;
+    }
+    if (delta < HISTSIZE) {
+      hist[delta]++;
+    } else {
+      toobig++;
+    }
+  }
+  printf("\n");
+  printf("Histogram: CLOCK_REALTIME, %d ns per bucket, %d samples.\n",
+    nsPerBucket, BATCHSIZE);
+  printf("        ns      hits\n");
+  lines = 0;
+  hits = 0;
+  for (i=0; i<HISTSIZE; i++) {
+    if ((5 <= lines) && (0.98*BATCHSIZE<hits)) break;  /* minimal printout */
+    if (hist[i]) {
+      printf("%10d  %8u\n", i*nsPerBucket+fastest, hist[i]);
+      lines++;
+      hits += hist[i];
+    }
+  }
+  miss = i;
+  for (  ; i<HISTSIZE; i++) {
+    toobig += hist[i];
+  }
+  
+  if (toobig) printf("%d samples were bigger than %d.\n",
+                toobig, miss*nsPerBucket+fastest);
+}
+
+
+int main(int argc, char *argv[])
+{
+  int i;
+  int res, average, fastest;
+
+  (void)argc;  /* Squash unused warnings */
+  (void)argv;
+
+printf("      res   avg     min  dups  CLOCK\n");
+for (i=0; (NULL != clocks[i].name); i++) {
+  res = do_res(clocks[i].type, clocks[i].name);
+  average = do_average(clocks[i].type, clocks[i].name);
+  fastest = do_fastest(clocks[i].type, clocks[i].name);
+  printf("%9d %5d %7d", res, average, fastest);
+  if (0.9*BATCHSIZE < dups)
+    /* Hack: negative to show good if close to all are bad */
+    printf(" %5d", dups-BATCHSIZE);
+  else if (0 < dups)
+    printf(" %5d", dups);
+  else
+    printf("      ");
+  printf("  %s\n", clocks[i].name);
+  fflush(stdout);
+}
+
+if (1) {
+  fastest = do_fastest(CLOCK_REALTIME, "CLOCK_REALTIME");
+  do_hist(CLOCK_REALTIME, fastest);
+}
+
+return 0;
+  
+}
+


=====================================
attic/wscript
=====================================
@@ -1,7 +1,7 @@
 def build(ctx):
     bldnode = ctx.bldnode.abspath()
 
-    util = ['sht', 'digest-find', 'digest-timing']
+    util = ['sht', 'digest-find', 'digest-timing', 'clocks']
 
     for name in util:
         ctx(


=====================================
include/ntp_auth.h
=====================================
@@ -63,12 +63,6 @@ extern	unsigned long authcmacfail;	/* fails from cmac_decrypt*/
 extern	uptime_t auth_timereset;	/* current_time when stats reset */
 
 
-/* EVP_get_cipherbyname() is broken on
- * old CentOS, NetBSD, FreeBSD, and maybe others.
- */
-extern const EVP_CIPHER * MY_get_cipherbyname(const char * name);
-
-
 /* Not in CMAC API */
 #define CMAC_MAX_MAC_LENGTH 64
 


=====================================
ntpd/ntp_proto.c
=====================================
@@ -470,6 +470,7 @@ handle_procpkt(
 	struct peer *peer
 	)
 {
+	int outcount = peer->outcount;
 
 	/* Shouldn't happen, but include this for safety. */
 	if(peer == NULL) { return; }
@@ -485,7 +486,7 @@ handle_procpkt(
 
 	/* Origin timestamp validation */
 	if(PKT_MODE(rbufp->pkt.li_vn_mode) == MODE_SERVER) {
-		if(peer->outcount == 0) {
+		if(outcount == 0) {
 			peer->flash |= BOGON1;
 			peer->oldpkt++;
 			return;
@@ -512,6 +513,7 @@ handle_procpkt(
 	*/
 
 	peer->outcount = 0;
+	outcount--;
 
 	if(is_kod(rbufp)) {
 		if(!memcmp(rbufp->pkt.refid, "RATE", REFIDLEN)) {
@@ -605,7 +607,7 @@ handle_procpkt(
 			 rbufp->pkt.rootdelay, rbufp->pkt.rootdisp,
 			 /* FIXME: this cast is disgusting */
 			 *(const uint32_t*)rbufp->pkt.refid,
-			 peer->outcount);
+			 outcount);
 
 	/* If either burst mode is armed, enable the burst.
 	 * Compute the headway for the next packet and delay if


=====================================
tests/option-tester.sh
=====================================
@@ -10,7 +10,7 @@
 
 # set pipefail to catch pipeline failures
 # Unfortunately, it doesn't work on some older sh-es
-if /bin/sh -c "set -o pipefail"
+if /bin/sh -c "set -o pipefail" 2> /dev/null
 then
   set -o pipefail
 fi
@@ -47,27 +47,6 @@ doit ()
   then
     echo                                  2>&1   | tee -a $DIR/test.log
     echo "Trouble with $DIR"              2>&1   | tee -a $DIR/test.log
-  else
-    echo -n "VERSION: "                   2>&1   | tee -a $DIR/test.log
-    ./$DIR/main/ntpd/ntpd --version       2>&1   | tee -a $DIR/test.log
-    echo -n "VERSION: "                   2>&1   | tee -a $DIR/test.log
-    ./$DIR/main/ntpclients/ntpq --version 2>&1   | tee -a $DIR/test.log
-    echo -n "VERSION: "                   2>&1   | tee -a $DIR/test.log
-    ./$DIR/main/ntpclients/ntpdig --version 2>&1 | tee -a $DIR/test.log
-    if [ `uname -s` != "NetBSD" ]
-    then
-      # no Python/curses on NetBSD
-      echo -n "VERSION: "                 2>&1   | tee -a $DIR/test.log
-      ./$DIR/main/ntpclients/ntpmon --version 2>&1 | tee -a $DIR/test.log
-    fi
-if [ "`which gpsmon 2>/dev/null`" != "" ]
-then
-    # needs GPSD library
-    echo -n "VERSION: "                         2>&1 | tee -a $DIR/test.log
-    ./$DIR/main/ntpclients/ntploggps --version  2>&1 | tee -a $DIR/test.log
-fi
-    echo -n "VERSION: "                         2>&1 | tee -a $DIR/test.log
-    ./$DIR/main/ntpclients/ntplogtemp --version 2>&1 | tee -a $DIR/test.log
   fi
   echo
   echo
@@ -91,6 +70,26 @@ fi
 # should try cross compile
 
 echo
+
+grep warning:                    test*/test.log
+grep error:                      test*/test.log
+grep "The configuration failed"  test*/test.log
+grep ^Trouble                    test*/test.log
+echo
+
+echo -n "## ";  python --version
+if test -n "$PYTHONPATH"
+then
+  echo "## PYTHONPATH is" \"$PYTHONPATH\"
+fi
+
+if ! /bin/sh -c "set -o pipefail" 2> /dev/null
+then
+  echo "### Old sh - no pipefail"
+  echo "### We can't test for errors during build"
+  echo "### You will have to scan the log files."
+fi
+
 if [ `uname -s` = "Linux" -a ! -f /usr/include/seccomp.h ]
 then
     echo
@@ -98,18 +97,4 @@ then
     echo
 fi
 
-if ! /bin/sh -c "set -o pipefail"
-then
-  echo "### old sh - no pipefail"
-  echo "We can't test for errors"
-  echo "###          You will have to scan the log files."
-fi
 
-echo "PYTHONPATH is" \"$PYTHONPATH\"
-grep VERSION: test*/test.log
-echo
-grep warning:                    test*/test.log
-grep error:                      test*/test.log
-grep "The configuration failed"  test*/test.log
-grep ^Trouble                    test*/test.log
-echo


=====================================
tests/python3-tester.sh
=====================================
@@ -5,17 +5,19 @@
 # This is a clone of option-tester.sh
 # to build with python3 and do minimal (version) testing.
 
-# set pipefail to catch pipeline failures
-set -o pipefail
-# crash on unset shell variables
-set -u
-
 if [ "`which python3 2>/dev/null`" = "" ]
 then
   echo "# Error: No python3 on this system."
   exit 1
 fi
 
+# set pipefail to catch pipeline failures
+# Unfortunately, it doesn't work on some older sh-es
+if /bin/sh -c "set -o pipefail" 2> /dev/null
+then
+  set -o pipefail
+fi
+
 doit ()
 {
   DIR=test-$1
@@ -41,27 +43,6 @@ doit ()
   then
     echo                          2>&1   | tee -a $DIR/test.log
     echo "Trouble with $DIR"      2>&1   | tee -a $DIR/test.log
-  else
-    echo -n "VERSION: "                             2>&1 | tee -a $DIR/test.log
-    ./$DIR/main/ntpd/ntpd --version                 2>&1 | tee -a $DIR/test.log
-    echo -n "VERSION: "                             2>&1 | tee -a $DIR/test.log
-    python3 ./$DIR/main/ntpclients/ntpq --version   2>&1 | tee -a $DIR/test.log
-    echo -n "VERSION: "                             2>&1 | tee -a $DIR/test.log
-    python3 ./$DIR/main/ntpclients/ntpdig --version 2>&1 | tee -a $DIR/test.log
-    if [ `uname -s` != "NetBSD" ]
-    then
-      # no Python/curses on NetBSD
-      echo -n "VERSION: "                           2>&1 | tee -a $DIR/test.log
-      python3 ./$DIR/main/ntpclients/ntpmon --version 2>&1 | tee -a $DIR/test.log
-    fi
-    # if [ "`which gpsmon 2>/dev/null`" != "" ]
-    # then
-    # needs GPSD library - don't know how to test for python3 version
-    # echo -n "VERSION: "                                2>&1 | tee -a $DIR/test.log
-    # python3 ./$DIR/main/ntpclients/ntploggps --version 2>&1 | tee -a $DIR/test.log
-    # fi
-    echo -n "VERSION: "                                 2>&1 | tee -a $DIR/test.log
-    python3 ./$DIR/main/ntpclients/ntplogtemp --version 2>&1 | tee -a $DIR/test.log
   fi
   echo
   echo
@@ -72,11 +53,23 @@ doit ()
 
 doit python3 "--disable-droproot --disable-dns-lookup --disable-mdns-registration --disable-manpage"
 
-echo "PYTHONPATH is" \"$PYTHONPATH\"
-grep VERSION: test*/test.log
-echo
+
 grep warning:                    test*/test.log
 grep error:                      test*/test.log
 grep "The configuration failed"  test*/test.log
 grep ^Trouble                    test*/test.log
 echo
+
+echo -n "## ";  python3 --version
+if test -n "$PYTHONPATH"
+then
+  echo "## PYTHONPATH is" \"$PYTHONPATH\"
+fi
+
+if ! /bin/sh -c "set -o pipefail" 2> /dev/null
+then
+  echo "### Old sh - no pipefail"
+  echo "### We can't test for errors during build"
+  echo "### You will have to scan the log files."
+fi
+



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/38577bd5016b7781f267902c2108424f93b3d828...15b0c8a21d232648207e9ecebb67ecf0c595d597

-- 
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/38577bd5016b7781f267902c2108424f93b3d828...15b0c8a21d232648207e9ecebb67ecf0c595d597
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20190108/cdc5b748/attachment-0001.html>


More information about the vc mailing list