summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorTed Unangst <tedu@cvs.openbsd.org>2015-11-20 18:53:43 +0000
committerTed Unangst <tedu@cvs.openbsd.org>2015-11-20 18:53:43 +0000
commit53fbe7c442e483fee0bf4c198c7ef3183f141a5c (patch)
treea9e566db57d76c5a8678f9c74edcbccfd10f4339 /usr.sbin
parente2aca0d4fc68fdd4855a7aebd410778b1e2e5d8d (diff)
use RMS for jitter. we're linking with enough libraries that libm is tiny.
ok deraadt
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/ntpd/Makefile4
-rw-r--r--usr.sbin/ntpd/control.c14
2 files changed, 9 insertions, 9 deletions
diff --git a/usr.sbin/ntpd/Makefile b/usr.sbin/ntpd/Makefile
index 20582ce62f1..d9acd258440 100644
--- a/usr.sbin/ntpd/Makefile
+++ b/usr.sbin/ntpd/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.15 2015/10/05 17:26:22 deraadt Exp $
+# $OpenBSD: Makefile,v 1.16 2015/11/20 18:53:42 tedu Exp $
PROG= ntpd
SRCS= ntpd.c log.c ntp.c ntp_msg.c parse.y config.c \
@@ -11,7 +11,7 @@ CFLAGS+= -Wmissing-declarations
CFLAGS+= -Wshadow -Wpointer-arith -Wcast-qual
CFLAGS+= -Wsign-compare
YFLAGS=
-LDADD+= -lutil -ltls -lssl -lcrypto
+LDADD+= -lm -lutil -ltls -lssl -lcrypto
DPADD+= ${LIBUTIL} ${LIBCRYPTO} ${LIBSSL} ${LIBTLS}
LINKS= ${BINDIR}/ntpd ${BINDIR}/ntpctl
MAN= ntpd.8 ntpd.conf.5 ntpctl.8
diff --git a/usr.sbin/ntpd/control.c b/usr.sbin/ntpd/control.c
index 08740ba90aa..4f31836b81d 100644
--- a/usr.sbin/ntpd/control.c
+++ b/usr.sbin/ntpd/control.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: control.c,v 1.7 2015/10/23 14:52:20 phessler Exp $ */
+/* $OpenBSD: control.c,v 1.8 2015/11/20 18:53:42 tedu Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -22,6 +22,7 @@
#include <sys/socket.h>
#include <sys/un.h>
#include <errno.h>
+#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -33,6 +34,8 @@
#define CONTROL_BACKLOG 5
+#define square(x) ((x) * (x))
+
int
control_init(char *path)
{
@@ -354,21 +357,18 @@ build_show_peer(struct ctl_show_peer *cp, struct ntp_peer *p)
cp->delay /= validdelaycnt;
}
- /*
- * use simple average for jitter calculation, as the
- * RFC5905-recommended RMS average needs the math library
- */
jittercnt = 0;
cp->jitter = 0.0;
for (shift = 0; shift < OFFSET_ARRAY_SIZE; shift++) {
if (p->reply[shift].delay > 0.0 && shift != best) {
- cp->jitter += p->reply[shift].delay -
- p->reply[best].delay;
+ cp->jitter += square(p->reply[shift].delay -
+ p->reply[best].delay);
jittercnt++;
}
}
if (jittercnt > 1)
cp->jitter /= jittercnt;
+ cp->jitter = sqrt(cp->jitter);
if (p->shift == 0)
shift = OFFSET_ARRAY_SIZE - 1;