mirror of
https://gitlab.com/chrony/chrony.git
synced 2025-12-04 10:25:06 -05:00
Compare commits
87 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
db286ca6ea | ||
|
|
85fbfd9b15 | ||
|
|
b819c7fe55 | ||
|
|
2b5c86b9a3 | ||
|
|
0a848e2528 | ||
|
|
b443ec5ea5 | ||
|
|
37d1467368 | ||
|
|
1d9d19d76b | ||
|
|
9603f0552a | ||
|
|
12befc2afd | ||
|
|
78f20f7b3e | ||
|
|
b703bc32c9 | ||
|
|
09afdd4b36 | ||
|
|
5cadaf8d55 | ||
|
|
89ac745184 | ||
|
|
e2422023c4 | ||
|
|
1ec0813663 | ||
|
|
6ba7fad2a7 | ||
|
|
962ca91574 | ||
|
|
91cbebb629 | ||
|
|
722f038f1f | ||
|
|
5e61c002a6 | ||
|
|
46e1e79921 | ||
|
|
546e5e236c | ||
|
|
16a1a89bf4 | ||
|
|
8a996572d2 | ||
|
|
5f082b9a4d | ||
|
|
4622173135 | ||
|
|
99e1c44c25 | ||
|
|
b48e4421de | ||
|
|
d1f4e5876b | ||
|
|
71b7e689c0 | ||
|
|
26b87b844d | ||
|
|
1834ee05e5 | ||
|
|
7d7bf915ac | ||
|
|
d86e9f4aa3 | ||
|
|
942b52a3ca | ||
|
|
b252c57a22 | ||
|
|
2aab6a85a4 | ||
|
|
10719d6d35 | ||
|
|
59938efd23 | ||
|
|
53b15bd5c7 | ||
|
|
5084a8b342 | ||
|
|
4d1c795804 | ||
|
|
a9049569af | ||
|
|
dec1d2bfb2 | ||
|
|
62e66bda60 | ||
|
|
3abaa92926 | ||
|
|
37e6357c02 | ||
|
|
6accd19eb3 | ||
|
|
da96d334ab | ||
|
|
5a92dbe784 | ||
|
|
8fe5e9cf1e | ||
|
|
81f440a882 | ||
|
|
981f897c96 | ||
|
|
eb75ce7d07 | ||
|
|
5645e57ce0 | ||
|
|
a12c7c422b | ||
|
|
d70e815e9f | ||
|
|
eb329e9f52 | ||
|
|
5833be6ccf | ||
|
|
ea3950d57e | ||
|
|
3f51805e62 | ||
|
|
b45f53dd20 | ||
|
|
9749a1c6fc | ||
|
|
5ca5d279d7 | ||
|
|
7b52c1578f | ||
|
|
72975ce1f0 | ||
|
|
9a4c22db03 | ||
|
|
e7af875b68 | ||
|
|
4acca9b727 | ||
|
|
b2d93b2e38 | ||
|
|
74afffed0c | ||
|
|
5828426977 | ||
|
|
d04fb4b7fa | ||
|
|
f5fe3ab4a1 | ||
|
|
6b6b097fe8 | ||
|
|
4998afc9bb | ||
|
|
80f4d75968 | ||
|
|
910663c37b | ||
|
|
34a4695e81 | ||
|
|
fe00319f45 | ||
|
|
4c77d18416 | ||
|
|
a63e18edb8 | ||
|
|
8b676502de | ||
|
|
cf5b344ea8 | ||
|
|
4ab98f62e9 |
15
.gitignore
vendored
15
.gitignore
vendored
@@ -7,18 +7,19 @@
|
|||||||
tags
|
tags
|
||||||
/RELEASES
|
/RELEASES
|
||||||
/Makefile
|
/Makefile
|
||||||
/chrony.conf.5
|
|
||||||
/chrony.info
|
|
||||||
/chrony.html
|
|
||||||
/chrony.texi
|
|
||||||
/chrony.txt
|
|
||||||
/chronyc
|
/chronyc
|
||||||
/chronyc.1
|
|
||||||
/chronyd
|
/chronyd
|
||||||
/chronyd.8
|
|
||||||
/config.h
|
/config.h
|
||||||
/config.log
|
/config.log
|
||||||
|
/doc/Makefile
|
||||||
|
/doc/*.html
|
||||||
|
/doc/*.man
|
||||||
|
/doc/*.man.in
|
||||||
|
/doc/*.txt
|
||||||
/getdate.c
|
/getdate.c
|
||||||
/version.h
|
/version.h
|
||||||
/test/simulation/clknetsim
|
/test/simulation/clknetsim
|
||||||
/test/simulation/tmp
|
/test/simulation/tmp
|
||||||
|
/test/unit/Makefile
|
||||||
|
/test/unit/*.test
|
||||||
|
/test/unit/*.o
|
||||||
|
|||||||
49
Makefile.in
49
Makefile.in
@@ -24,9 +24,6 @@
|
|||||||
SYSCONFDIR=@SYSCONFDIR@
|
SYSCONFDIR=@SYSCONFDIR@
|
||||||
BINDIR=@BINDIR@
|
BINDIR=@BINDIR@
|
||||||
SBINDIR=@SBINDIR@
|
SBINDIR=@SBINDIR@
|
||||||
MANDIR=@MANDIR@
|
|
||||||
INFODIR=@INFODIR@
|
|
||||||
DOCDIR=@DOCDIR@
|
|
||||||
LOCALSTATEDIR=@LOCALSTATEDIR@
|
LOCALSTATEDIR=@LOCALSTATEDIR@
|
||||||
CHRONYVARDIR=@CHRONYVARDIR@
|
CHRONYVARDIR=@CHRONYVARDIR@
|
||||||
|
|
||||||
@@ -74,11 +71,12 @@ $(HASH_OBJ) : $(patsubst %.o,%.c,$(HASH_OBJ))
|
|||||||
|
|
||||||
distclean : clean
|
distclean : clean
|
||||||
-rm -f .DS_Store
|
-rm -f .DS_Store
|
||||||
-rm -f Makefile
|
-rm -f Makefile config.h config.log
|
||||||
-rm -f chrony.conf.5 chrony.texi chronyc.1 chronyd.8
|
$(MAKE) -C doc distclean
|
||||||
|
$(MAKE) -C test/unit distclean
|
||||||
|
|
||||||
clean :
|
clean :
|
||||||
-rm -f *.o *.s chronyc chronyd core *~ chrony.info chrony.html chrony.txt
|
-rm -f *.o *.s chronyc chronyd core *~
|
||||||
-rm -rf .deps
|
-rm -rf .deps
|
||||||
-rm -rf *.dSYM
|
-rm -rf *.dSYM
|
||||||
|
|
||||||
@@ -96,9 +94,6 @@ install: chronyd chronyc
|
|||||||
[ -d $(DESTDIR)$(SYSCONFDIR) ] || mkdir -p $(DESTDIR)$(SYSCONFDIR)
|
[ -d $(DESTDIR)$(SYSCONFDIR) ] || mkdir -p $(DESTDIR)$(SYSCONFDIR)
|
||||||
[ -d $(DESTDIR)$(SBINDIR) ] || mkdir -p $(DESTDIR)$(SBINDIR)
|
[ -d $(DESTDIR)$(SBINDIR) ] || mkdir -p $(DESTDIR)$(SBINDIR)
|
||||||
[ -d $(DESTDIR)$(BINDIR) ] || mkdir -p $(DESTDIR)$(BINDIR)
|
[ -d $(DESTDIR)$(BINDIR) ] || mkdir -p $(DESTDIR)$(BINDIR)
|
||||||
[ -d $(DESTDIR)$(MANDIR)/man1 ] || mkdir -p $(DESTDIR)$(MANDIR)/man1
|
|
||||||
[ -d $(DESTDIR)$(MANDIR)/man5 ] || mkdir -p $(DESTDIR)$(MANDIR)/man5
|
|
||||||
[ -d $(DESTDIR)$(MANDIR)/man8 ] || mkdir -p $(DESTDIR)$(MANDIR)/man8
|
|
||||||
[ -d $(DESTDIR)$(CHRONYVARDIR) ] || mkdir -p $(DESTDIR)$(CHRONYVARDIR)
|
[ -d $(DESTDIR)$(CHRONYVARDIR) ] || mkdir -p $(DESTDIR)$(CHRONYVARDIR)
|
||||||
if [ -f $(DESTDIR)$(SBINDIR)/chronyd ]; then rm -f $(DESTDIR)$(SBINDIR)/chronyd ; fi
|
if [ -f $(DESTDIR)$(SBINDIR)/chronyd ]; then rm -f $(DESTDIR)$(SBINDIR)/chronyd ; fi
|
||||||
if [ -f $(DESTDIR)$(BINDIR)/chronyc ]; then rm -f $(DESTDIR)$(BINDIR)/chronyc ; fi
|
if [ -f $(DESTDIR)$(BINDIR)/chronyc ]; then rm -f $(DESTDIR)$(BINDIR)/chronyc ; fi
|
||||||
@@ -106,12 +101,13 @@ install: chronyd chronyc
|
|||||||
chmod 755 $(DESTDIR)$(SBINDIR)/chronyd
|
chmod 755 $(DESTDIR)$(SBINDIR)/chronyd
|
||||||
cp chronyc $(DESTDIR)$(BINDIR)/chronyc
|
cp chronyc $(DESTDIR)$(BINDIR)/chronyc
|
||||||
chmod 755 $(DESTDIR)$(BINDIR)/chronyc
|
chmod 755 $(DESTDIR)$(BINDIR)/chronyc
|
||||||
cp chronyc.1 $(DESTDIR)$(MANDIR)/man1
|
$(MAKE) -C doc install
|
||||||
chmod 644 $(DESTDIR)$(MANDIR)/man1/chronyc.1
|
|
||||||
cp chronyd.8 $(DESTDIR)$(MANDIR)/man8
|
docs :
|
||||||
chmod 644 $(DESTDIR)$(MANDIR)/man8/chronyd.8
|
$(MAKE) -C doc docs
|
||||||
cp chrony.conf.5 $(DESTDIR)$(MANDIR)/man5
|
|
||||||
chmod 644 $(DESTDIR)$(MANDIR)/man5/chrony.conf.5
|
install-docs :
|
||||||
|
$(MAKE) -C doc install-docs
|
||||||
|
|
||||||
%.o : %.c
|
%.o : %.c
|
||||||
$(CC) $(CFLAGS) $(CPPFLAGS) -c $<
|
$(CC) $(CFLAGS) $(CPPFLAGS) -c $<
|
||||||
@@ -120,30 +116,9 @@ install: chronyd chronyc
|
|||||||
$(CC) $(CFLAGS) $(CPPFLAGS) -S $<
|
$(CC) $(CFLAGS) $(CPPFLAGS) -S $<
|
||||||
|
|
||||||
check : chronyd chronyc
|
check : chronyd chronyc
|
||||||
|
$(MAKE) -C test/unit check
|
||||||
cd test/simulation && ./run
|
cd test/simulation && ./run
|
||||||
|
|
||||||
install-docs : docs
|
|
||||||
[ -d $(DESTDIR)$(DOCDIR) ] || mkdir -p $(DESTDIR)$(DOCDIR)
|
|
||||||
cp chrony.txt $(DESTDIR)$(DOCDIR)/chrony.txt
|
|
||||||
chmod 644 $(DESTDIR)$(DOCDIR)/chrony.txt
|
|
||||||
cp chrony.html $(DESTDIR)$(DOCDIR)/chrony.html
|
|
||||||
chmod 644 $(DESTDIR)$(DOCDIR)/chrony.html
|
|
||||||
[ -d $(DESTDIR)$(INFODIR) ] || mkdir -p $(DESTDIR)$(INFODIR)
|
|
||||||
cp chrony.info* $(DESTDIR)$(INFODIR)
|
|
||||||
chmod 644 $(DESTDIR)$(INFODIR)/chrony.info*
|
|
||||||
|
|
||||||
docs : chrony.txt chrony.html chrony.info
|
|
||||||
|
|
||||||
chrony.txt : chrony.texi
|
|
||||||
makeinfo --no-headers --number-sections -o chrony.txt chrony.texi
|
|
||||||
|
|
||||||
chrony.html : chrony.texi
|
|
||||||
command -v texi2html > /dev/null 2>&1 && texi2html chrony.texi || \
|
|
||||||
makeinfo --no-split --html --number-sections -o chrony.html chrony.texi
|
|
||||||
|
|
||||||
chrony.info : chrony.texi
|
|
||||||
makeinfo chrony.texi
|
|
||||||
|
|
||||||
Makefile : Makefile.in configure
|
Makefile : Makefile.in configure
|
||||||
@echo
|
@echo
|
||||||
@echo Makefile needs to be regenerated, run ./configure
|
@echo Makefile needs to be regenerated, run ./configure
|
||||||
|
|||||||
39
NEWS
39
NEWS
@@ -1,3 +1,42 @@
|
|||||||
|
New in version 2.4.1
|
||||||
|
====================
|
||||||
|
|
||||||
|
Bug fixes
|
||||||
|
---------
|
||||||
|
* Fix processing of kernel timestamps on non-Linux systems
|
||||||
|
* Fix crash with smoothtime directive
|
||||||
|
* Fix validation of refclock sample times
|
||||||
|
* Fix parsing of refclock directive
|
||||||
|
|
||||||
|
New in version 2.4
|
||||||
|
==================
|
||||||
|
|
||||||
|
Enhancements
|
||||||
|
------------
|
||||||
|
* Add orphan option to local directive for orphan mode compatible with ntpd
|
||||||
|
* Add distance option to local directive to set activation threshold
|
||||||
|
(1 second by default)
|
||||||
|
* Add maxdrift directive to set maximum allowed drift of system clock
|
||||||
|
* Try to replace NTP sources exceeding maximum distance
|
||||||
|
* Randomise source replacement to avoid getting stuck with bad sources
|
||||||
|
* Randomise selection of sources from pools on start
|
||||||
|
* Ignore reference timestamp as ntpd doesn't always set it correctly
|
||||||
|
* Modify tracking report to use same values as seen by NTP clients
|
||||||
|
* Add -c option to chronyc to write reports in CSV format
|
||||||
|
* Provide detailed manual pages
|
||||||
|
|
||||||
|
Bug fixes
|
||||||
|
---------
|
||||||
|
* Fix SOCK refclock to work correctly when not specified as last refclock
|
||||||
|
* Fix initstepslew and -q/-Q options to accept time from own NTP clients
|
||||||
|
* Fix authentication with keys using 512-bit hash functions
|
||||||
|
* Fix crash on exit when multiple signals are received
|
||||||
|
* Fix conversion of very small floating-point numbers in command packets
|
||||||
|
|
||||||
|
Removed features
|
||||||
|
----------------
|
||||||
|
* Drop documentation in Texinfo format
|
||||||
|
|
||||||
New in version 2.3
|
New in version 2.3
|
||||||
==================
|
==================
|
||||||
|
|
||||||
|
|||||||
16
README
16
README
@@ -53,7 +53,7 @@ ready-formatted plain text (chrony.txt) in the distribution.
|
|||||||
There is also information available on the chrony web pages, accessible
|
There is also information available on the chrony web pages, accessible
|
||||||
through the URL
|
through the URL
|
||||||
|
|
||||||
http://chrony.tuxfamily.org/
|
https://chrony.tuxfamily.org/
|
||||||
|
|
||||||
Where are new versions announced?
|
Where are new versions announced?
|
||||||
=================================
|
=================================
|
||||||
@@ -84,6 +84,12 @@ chrony-dev-request@chrony.tuxfamily.org
|
|||||||
|
|
||||||
as applicable.
|
as applicable.
|
||||||
|
|
||||||
|
When you are reporting a bug, please send us all the information you can.
|
||||||
|
Unfortunately, chrony has proven to be one of those programs where it is very
|
||||||
|
difficult to reproduce bugs in a different environment. So we may have to
|
||||||
|
interact with you quite a lot to obtain enough extra logging and tracing to
|
||||||
|
pin-point the problem in some cases. Please be patient and plan for this!
|
||||||
|
|
||||||
License
|
License
|
||||||
=======
|
=======
|
||||||
|
|
||||||
@@ -105,6 +111,10 @@ Miroslav Lichvar <mlichvar@redhat.com>
|
|||||||
Acknowledgements
|
Acknowledgements
|
||||||
================
|
================
|
||||||
|
|
||||||
|
In writing the chronyd program, extensive use has been made of RFC 1305
|
||||||
|
and RFC 5905, written by David Mills. The source code of the NTP reference
|
||||||
|
implementation has been used to check the details of the protocol.
|
||||||
|
|
||||||
The following people have provided patches and other major contributions
|
The following people have provided patches and other major contributions
|
||||||
to the program :
|
to the program :
|
||||||
|
|
||||||
@@ -131,6 +141,7 @@ Erik Bryer <ebryer@spots.ab.ca>
|
|||||||
Bryan Christianson <bryan@whatroute.net>
|
Bryan Christianson <bryan@whatroute.net>
|
||||||
Support for Mac OS X
|
Support for Mac OS X
|
||||||
Support for privilege separation
|
Support for privilege separation
|
||||||
|
Entries in contrib directory
|
||||||
|
|
||||||
Juliusz Chroboczek <jch@pps.jussieu.fr>
|
Juliusz Chroboczek <jch@pps.jussieu.fr>
|
||||||
Fix install rule in Makefile if chronyd file is in use.
|
Fix install rule in Makefile if chronyd file is in use.
|
||||||
@@ -217,6 +228,9 @@ Andreas Piesk <apiesk@virbus.de>
|
|||||||
Timo Teras <timo.teras@iki.fi>
|
Timo Teras <timo.teras@iki.fi>
|
||||||
Patch to reply correctly on multihomed hosts
|
Patch to reply correctly on multihomed hosts
|
||||||
|
|
||||||
|
Stephen Wadeley <swadeley@redhat.com>
|
||||||
|
Improvements to man pages
|
||||||
|
|
||||||
Wolfgang Weisselberg <weissel@netcologne.de>
|
Wolfgang Weisselberg <weissel@netcologne.de>
|
||||||
Entries in contrib directory
|
Entries in contrib directory
|
||||||
|
|
||||||
|
|||||||
114
addrfilt.c
114
addrfilt.c
@@ -401,117 +401,3 @@ ADF_IsAnyAllowed(ADF_AuthTable table, int family)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
|
||||||
|
|
||||||
#if defined TEST
|
|
||||||
|
|
||||||
static void print_node(TableNode *node, uint32_t *addr, int ip_len, int shift, int subnet_bits)
|
|
||||||
{
|
|
||||||
uint32_t new_addr[4];
|
|
||||||
int i;
|
|
||||||
TableNode *sub_node;
|
|
||||||
|
|
||||||
for (i=0; i<subnet_bits; i++) putchar(' ');
|
|
||||||
|
|
||||||
if (ip_len == 1)
|
|
||||||
printf("%d.%d.%d.%d",
|
|
||||||
((addr[0] >> 24) & 255),
|
|
||||||
((addr[0] >> 16) & 255),
|
|
||||||
((addr[0] >> 8) & 255),
|
|
||||||
((addr[0] ) & 255));
|
|
||||||
else {
|
|
||||||
for (i=0; i<4; i++) {
|
|
||||||
if (addr[i])
|
|
||||||
printf("%d.%d.%d.%d",
|
|
||||||
((addr[i] >> 24) & 255),
|
|
||||||
((addr[i] >> 16) & 255),
|
|
||||||
((addr[i] >> 8) & 255),
|
|
||||||
((addr[i] ) & 255));
|
|
||||||
putchar(i < 3 ? ':' : '\0');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
printf("/%d : %s\n",
|
|
||||||
subnet_bits,
|
|
||||||
(node->state == ALLOW) ? "allow" :
|
|
||||||
(node->state == DENY) ? "deny" : "as parent");
|
|
||||||
if (node->extended) {
|
|
||||||
for (i=0; i<16; i++) {
|
|
||||||
sub_node = &(node->extended[i]);
|
|
||||||
new_addr[0] = addr[0];
|
|
||||||
new_addr[1] = addr[1];
|
|
||||||
new_addr[2] = addr[2];
|
|
||||||
new_addr[3] = addr[3];
|
|
||||||
new_addr[ip_len - 1 - shift / 32] |= ((uint32_t)i << (shift % 32));
|
|
||||||
print_node(sub_node, new_addr, ip_len, shift - 4, subnet_bits + 4);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void print_table(ADF_AuthTable table)
|
|
||||||
{
|
|
||||||
uint32_t addr[4];
|
|
||||||
|
|
||||||
memset(addr, 0, sizeof (addr));
|
|
||||||
printf("IPv4 table:\n");
|
|
||||||
print_node(&table->base4, addr, 1, 28, 0);
|
|
||||||
|
|
||||||
memset(addr, 0, sizeof (addr));
|
|
||||||
printf("IPv6 table:\n");
|
|
||||||
print_node(&table->base6, addr, 4, 124, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ================================================== */
|
|
||||||
|
|
||||||
int main (int argc, char **argv)
|
|
||||||
{
|
|
||||||
IPAddr ip;
|
|
||||||
ADF_AuthTable table;
|
|
||||||
table = ADF_CreateTable();
|
|
||||||
|
|
||||||
ip.family = IPADDR_INET4;
|
|
||||||
|
|
||||||
ip.addr.in4 = 0x7e800000;
|
|
||||||
ADF_Allow(table, &ip, 9);
|
|
||||||
ip.addr.in4 = 0x7ecc0000;
|
|
||||||
ADF_Deny(table, &ip, 14);
|
|
||||||
#if 0
|
|
||||||
ip.addr.in4 = 0x7f000001;
|
|
||||||
ADF_Deny(table, &ip, 32);
|
|
||||||
ip.addr.in4 = 0x7f000000;
|
|
||||||
ADF_Allow(table, &ip, 8);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
printf("allowed: %d\n", ADF_IsAllowed(table, &ip));
|
|
||||||
ip.addr.in4 ^= 1;
|
|
||||||
printf("allowed: %d\n", ADF_IsAllowed(table, &ip));
|
|
||||||
|
|
||||||
ip.family = IPADDR_INET6;
|
|
||||||
|
|
||||||
memcpy(ip.addr.in6, "abcdefghijklmnop", 16);
|
|
||||||
ADF_Deny(table, &ip, 66);
|
|
||||||
ADF_Allow(table, &ip, 59);
|
|
||||||
|
|
||||||
memcpy(ip.addr.in6, "xbcdefghijklmnop", 16);
|
|
||||||
ADF_Deny(table, &ip, 128);
|
|
||||||
ip.addr.in6[15] ^= 3;
|
|
||||||
ADF_Allow(table, &ip, 127);
|
|
||||||
|
|
||||||
printf("allowed: %d\n", ADF_IsAllowed(table, &ip));
|
|
||||||
ip.addr.in4 ^= 1;
|
|
||||||
printf("allowed: %d\n", ADF_IsAllowed(table, &ip));
|
|
||||||
|
|
||||||
print_table(table);
|
|
||||||
|
|
||||||
ADF_DestroyTable(table);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* defined TEST */
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
9
candm.h
9
candm.h
@@ -93,11 +93,8 @@
|
|||||||
#define REQ_REFRESH 53
|
#define REQ_REFRESH 53
|
||||||
#define REQ_SERVER_STATS 54
|
#define REQ_SERVER_STATS 54
|
||||||
#define REQ_CLIENT_ACCESSES_BY_INDEX2 55
|
#define REQ_CLIENT_ACCESSES_BY_INDEX2 55
|
||||||
#define N_REQUEST_TYPES 56
|
#define REQ_LOCAL2 56
|
||||||
|
#define N_REQUEST_TYPES 57
|
||||||
/* Special utoken value used to log on with first exchange being the
|
|
||||||
password. (This time value has long since gone by) */
|
|
||||||
#define SPECIAL_UTOKEN 0x10101010
|
|
||||||
|
|
||||||
/* Structure used to exchange timevals independent on size of time_t */
|
/* Structure used to exchange timevals independent on size of time_t */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -215,6 +212,8 @@ typedef struct {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t on_off;
|
int32_t on_off;
|
||||||
int32_t stratum;
|
int32_t stratum;
|
||||||
|
Float distance;
|
||||||
|
int32_t orphan;
|
||||||
int32_t EOR;
|
int32_t EOR;
|
||||||
} REQ_Local;
|
} REQ_Local;
|
||||||
|
|
||||||
|
|||||||
@@ -1,67 +0,0 @@
|
|||||||
.TH chrony.conf 5 "@MAN_DATE@" "chrony @VERSION@" "Configuration Files"
|
|
||||||
.SH NAME
|
|
||||||
chrony.conf \- chronyd configuration file
|
|
||||||
|
|
||||||
.SH SYNOPSIS
|
|
||||||
.B @SYSCONFDIR@/chrony.conf
|
|
||||||
|
|
||||||
.SH DESCRIPTION
|
|
||||||
\fIchrony\fR is a pair of programs for maintaining the accuracy of computer
|
|
||||||
clocks. \fIchronyd\fR is a background daemon program that can be started at
|
|
||||||
boot time.
|
|
||||||
|
|
||||||
Assuming that you have found some servers, you need to set up a
|
|
||||||
configuration file to run \fIchrony\fR. The (compiled-in) default location
|
|
||||||
for this file is \fB@SYSCONFDIR@/chrony.conf\fR. Assuming that your NTP
|
|
||||||
servers are called `foo.example.net', `bar.example.net' and `baz.example.net',
|
|
||||||
your \fBchrony.conf\fR file could contain as a minimum
|
|
||||||
|
|
||||||
.EX
|
|
||||||
server foo.example.net
|
|
||||||
server bar.example.net
|
|
||||||
server baz.example.net
|
|
||||||
.EE
|
|
||||||
|
|
||||||
However, you will probably want to include some of the other directives
|
|
||||||
described in detail in the documentation supplied with the distribution
|
|
||||||
(\fIchrony.txt\fR and \fIchrony.texi\fR). The following directives may be
|
|
||||||
particularly useful : `driftfile', `makestep', `rtcsync'. Also, the `iburst'
|
|
||||||
server option is useful to speed up the initial synchronization. The smallest
|
|
||||||
useful configuration file would look something like
|
|
||||||
|
|
||||||
.EX
|
|
||||||
server foo.example.net iburst
|
|
||||||
server bar.example.net iburst
|
|
||||||
server baz.example.net iburst
|
|
||||||
driftfile @CHRONYVARDIR@/drift
|
|
||||||
makestep 1.0 3
|
|
||||||
rtcsync
|
|
||||||
.EE
|
|
||||||
|
|
||||||
When using a pool of NTP servers (one name is used for multiple servers which
|
|
||||||
may change over time), it's better to specify them with the `pool' directive
|
|
||||||
instead of multiple `server' directives. The configuration file could in this
|
|
||||||
case look like
|
|
||||||
|
|
||||||
.EX
|
|
||||||
pool pool.ntp.org iburst
|
|
||||||
driftfile @CHRONYVARDIR@/drift
|
|
||||||
makestep 1.0 3
|
|
||||||
rtcsync
|
|
||||||
.EE
|
|
||||||
|
|
||||||
.SH "SEE ALSO"
|
|
||||||
.BR chronyc(1),
|
|
||||||
.BR chronyd(8)
|
|
||||||
|
|
||||||
.I http://chrony.tuxfamily.org/
|
|
||||||
|
|
||||||
.SH AUTHOR
|
|
||||||
Richard Curnow <rc@rc0.org.uk>
|
|
||||||
|
|
||||||
This man-page was written by Jan Schaumann <jschauma@netmeister.org> as part of "The Missing
|
|
||||||
Man Pages Project". Please see \fIhttp://www.netmeister.org/misc/m2p2/index.html\fR
|
|
||||||
for details.
|
|
||||||
|
|
||||||
The complete chrony documentation is supplied in texinfo format.
|
|
||||||
|
|
||||||
5205
chrony.texi.in
5205
chrony.texi.in
File diff suppressed because it is too large
Load Diff
74
chronyc.1.in
74
chronyc.1.in
@@ -1,74 +0,0 @@
|
|||||||
.TH CHRONYC 1 "@MAN_DATE@" "chrony @VERSION@" "User's Manual"
|
|
||||||
.SH NAME
|
|
||||||
chronyc \- command-line interface for chronyd
|
|
||||||
|
|
||||||
.SH SYNOPSIS
|
|
||||||
.B chronyc
|
|
||||||
[\fIOPTIONS\fR]
|
|
||||||
|
|
||||||
.SH DESCRIPTION
|
|
||||||
\fIchrony\fR is a pair of programs for maintaining the accuracy of computer
|
|
||||||
clocks.
|
|
||||||
|
|
||||||
\fBchronyc\fR is a command-line interface program which can be used to
|
|
||||||
monitor \fIchronyd\fR's performance and to change various operating
|
|
||||||
parameters whilst it is running.
|
|
||||||
|
|
||||||
.SH USAGE
|
|
||||||
A detailed description of all commands supported by \fBchronyc\fR is available
|
|
||||||
via the documentation supplied with the distribution (\fIchrony.txt\fR and
|
|
||||||
\fIchrony.texi\fR).
|
|
||||||
|
|
||||||
.SH OPTIONS
|
|
||||||
A summary of the options supported by \fBchronyc\fR is included below.
|
|
||||||
|
|
||||||
.TP
|
|
||||||
\fB\-h\fR \fIhostname\fR
|
|
||||||
specify hostname or comma-separated list of addresses
|
|
||||||
(default @CHRONYSOCKDIR@/chronyd.sock,127.0.0.1,::1)
|
|
||||||
.TP
|
|
||||||
\fB\-p\fR \fIport-number\fR
|
|
||||||
specify port-number
|
|
||||||
.TP
|
|
||||||
\fB\-n\fR
|
|
||||||
display raw IP addresses (don't attempt to look up hostnames)
|
|
||||||
.TP
|
|
||||||
\fB\-d\fR
|
|
||||||
print debugging messages (if compiled with debugging support)
|
|
||||||
.TP
|
|
||||||
\fB\-4\fR
|
|
||||||
resolve hostnames only to IPv4 addresses
|
|
||||||
.TP
|
|
||||||
\fB\-6\fR
|
|
||||||
resolve hostnames only to IPv6 addresses
|
|
||||||
.TP
|
|
||||||
\fB\-m\fR
|
|
||||||
allow multiple commands to be specified on the command line. Each argument
|
|
||||||
will be interpreted as a whole command.
|
|
||||||
.TP
|
|
||||||
\fB\-f\fR \fIconf-file\fR
|
|
||||||
this option is ignored and is provided only for compatibility.
|
|
||||||
.TP
|
|
||||||
\fB\-a\fR
|
|
||||||
this option is ignored and is provided only for compatibility.
|
|
||||||
.TP
|
|
||||||
\fIcommand\fR
|
|
||||||
specify command. If no command is given, chronyc will read commands
|
|
||||||
interactively.
|
|
||||||
|
|
||||||
.SH BUGS
|
|
||||||
To report bugs, please visit \fIhttp://chrony.tuxfamily.org\fR
|
|
||||||
|
|
||||||
.SH "SEE ALSO"
|
|
||||||
.BR chronyd(8)
|
|
||||||
|
|
||||||
.I http://chrony.tuxfamily.org/
|
|
||||||
|
|
||||||
.SH AUTHOR
|
|
||||||
Richard Curnow <rc@rc0.org.uk>
|
|
||||||
|
|
||||||
This man-page was written by Jan Schaumann <jschauma@netmeister.org> as part of "The Missing
|
|
||||||
Man Pages Project". Please see \fIhttp://www.netmeister.org/misc/m2p2/index.html\fR
|
|
||||||
for details.
|
|
||||||
|
|
||||||
The complete chrony documentation is supplied in texinfo format.
|
|
||||||
166
chronyd.8.in
166
chronyd.8.in
@@ -1,166 +0,0 @@
|
|||||||
.TH CHRONYD 8 "@MAN_DATE@" "chrony @VERSION@" "System Administration"
|
|
||||||
.SH NAME
|
|
||||||
chronyd \- chrony background daemon
|
|
||||||
|
|
||||||
.SH SYNOPSIS
|
|
||||||
.B chronyd
|
|
||||||
[\fIOPTIONS\fR] [\fIconfiguration commands\fR]
|
|
||||||
|
|
||||||
.SH DESCRIPTION
|
|
||||||
\fIchrony\fR is a pair of programs for maintaining the accuracy of computer
|
|
||||||
clocks. \fBchronyd\fR is a background daemon program that can be started at boot
|
|
||||||
time.
|
|
||||||
|
|
||||||
\fBchronyd\fR is a daemon which runs in background on the
|
|
||||||
system. It obtains measurements (e.g. via the network) of the
|
|
||||||
system's offset relative to other systems, and adjusts the system
|
|
||||||
time accordingly. For isolated systems, the user can periodically
|
|
||||||
enter the correct time by hand (using \fIchronyc\fR). In either case,
|
|
||||||
\fBchronyd\fR determines the rate at which the computer
|
|
||||||
gains or loses time, and compensates for this.
|
|
||||||
|
|
||||||
.SH USAGE
|
|
||||||
\fBchronyd\fR is usually started at boot-time and requires superuser
|
|
||||||
privileges.
|
|
||||||
|
|
||||||
If \fBchronyd\fR has been installed to its default location
|
|
||||||
\fI@SBINDIR@/chronyd\fR, starting it is simply a matter of entering the
|
|
||||||
command:
|
|
||||||
|
|
||||||
\fI@SBINDIR@/chronyd\fR
|
|
||||||
|
|
||||||
Information messages and warnings will be logged to syslog.
|
|
||||||
|
|
||||||
If no configuration commands are specified on the command line,
|
|
||||||
\fBchronyd\fR will read the commands from the configuration file
|
|
||||||
(default \fI@SYSCONFDIR@/chrony.conf\fR).
|
|
||||||
|
|
||||||
.SH OPTIONS
|
|
||||||
A summary of the options supported by \fBchronyd\fR is included below.
|
|
||||||
|
|
||||||
.TP
|
|
||||||
\fB\-P\fR \fIpriority\fR
|
|
||||||
On Linux, this option will select the SCHED_FIFO real-time scheduler at the
|
|
||||||
specified priority (which must be between 0 and 100). On Mac OS X, this
|
|
||||||
option must have either a value of 0 (the default) to disable the thread
|
|
||||||
time constraint policy or 1 for the policy to be enabled. Other systems do not
|
|
||||||
support this option.
|
|
||||||
.TP
|
|
||||||
.B \-m
|
|
||||||
This option will lock chronyd into RAM so that it will never be paged out.
|
|
||||||
This mode is only supported on Linux.
|
|
||||||
.TP
|
|
||||||
.B \-n
|
|
||||||
When run in this mode, the program will not detach itself from the
|
|
||||||
terminal.
|
|
||||||
.TP
|
|
||||||
.B \-d
|
|
||||||
When run in this mode, the program will not detach itself from the
|
|
||||||
terminal, and all messages will be sent to the terminal instead of
|
|
||||||
to syslog. When \fBchronyd\fR was compiled with debugging support,
|
|
||||||
this option can be used twice to print also debugging messages.
|
|
||||||
.TP
|
|
||||||
\fB\-f\fR \fIconf-file\fR
|
|
||||||
This option can be used to specify an alternate location for the
|
|
||||||
configuration file (default \fI@SYSCONFDIR@/chrony.conf\fR).
|
|
||||||
.TP
|
|
||||||
.B \-r
|
|
||||||
This option will reload sample histories for each of the servers being used.
|
|
||||||
These histories are created by using the \fIdump\fR command in \fIchronyc\fR,
|
|
||||||
or by setting the \fIdumponexit\fR directive in the configuration file. This
|
|
||||||
option is useful if you want to stop and restart \fBchronyd\fR briefly for any
|
|
||||||
reason, e.g. to install a new version. However, it should be used only on
|
|
||||||
systems where the kernel can maintain clock compensation whilst not under
|
|
||||||
\fBchronyd\fR's control (i.e. Linux, FreeBSD, NetBSD and Solaris).
|
|
||||||
.TP
|
|
||||||
.B \-R
|
|
||||||
When this option is used, the \fIinitstepslew\fR directive and the
|
|
||||||
\fImakestep\fR directive used with a positive limit will be ignored. This
|
|
||||||
option is useful when restarting \fBchronyd\fR and can be used in conjunction
|
|
||||||
with the \fB-r\fR option.
|
|
||||||
.TP
|
|
||||||
.B \-s
|
|
||||||
This option will set the system clock from the computer's real-time clock or
|
|
||||||
to the last modification time of the file specified by the \fIdriftfile\fR
|
|
||||||
directive. Real-time clocks are supported only on Linux.
|
|
||||||
|
|
||||||
If used in conjunction with the \fB-r\fR flag, \fBchronyd\fR will attempt
|
|
||||||
to preserve the old samples after setting the system clock from
|
|
||||||
the real time clock (RTC). This can be used to allow \fBchronyd\fR to
|
|
||||||
perform long term averaging of the gain or loss rate across system
|
|
||||||
reboots, and is useful for dial-up systems that are shut down when
|
|
||||||
not in use. For this to work well, it relies on \fBchronyd\fR having
|
|
||||||
been able to determine accurate statistics for the difference
|
|
||||||
between the RTC and system clock last time the computer was on.
|
|
||||||
|
|
||||||
If the last modification time of the drift file is later than the current time
|
|
||||||
and the RTC time, the system time will be set to it to restore the time when
|
|
||||||
\fBchronyd\fR was previously stopped. This is useful on computers that have no
|
|
||||||
RTC or the RTC is broken (e.g. it has no battery).
|
|
||||||
.TP
|
|
||||||
\fB\-u\fR \fIuser\fR
|
|
||||||
This option sets the name of the system user to which \fBchronyd\fR will switch
|
|
||||||
after start in order to drop root privileges. It overrides the \fBuser\fR
|
|
||||||
directive from the configuration file (default \fB@DEFAULT_USER@\fR).
|
|
||||||
|
|
||||||
On Linux, \fBchronyd\fR needs to be compiled with support for the \fBlibcap\fR
|
|
||||||
library. On Mac OS X, FreeBSD, NetBSD and Solaris \fBchronyd\fR forks into two
|
|
||||||
processes. The child process retains root privileges, but can only perform a
|
|
||||||
very limited range of privileged system calls on behalf of the parent.
|
|
||||||
.TP
|
|
||||||
\fB\-F\fR \fIlevel\fR
|
|
||||||
This option configures a system call filter when \fBchronyd\fR is compiled with
|
|
||||||
support for the Linux secure computing (seccomp) facility. In level 1 the
|
|
||||||
process is killed when a forbidden system call is made, in level -1 the SYSSIG
|
|
||||||
signal is thrown instead and in level 0 the filter is disabled (default 0).
|
|
||||||
|
|
||||||
It's recommended to enable the filter only when it's known to work on the
|
|
||||||
version of the system where \fBchrony\fR is installed as the filter needs to
|
|
||||||
allow also system calls made from libraries that \fBchronyd\fR is using (e.g.
|
|
||||||
libc) and different versions or implementations of the libraries may make
|
|
||||||
different system calls. If the filter is missing some system call,
|
|
||||||
\fBchronyd\fR could be killed even in normal operation.
|
|
||||||
.TP
|
|
||||||
.B \-q
|
|
||||||
When run in this mode, chronyd will set the system clock once
|
|
||||||
and exit. It will not detach from the terminal.
|
|
||||||
.TP
|
|
||||||
.B \-Q
|
|
||||||
This option is similar to \fB\-q\fR, but it will only print the offset and
|
|
||||||
not correct the clock.
|
|
||||||
.TP
|
|
||||||
.B \-v
|
|
||||||
This option displays \fBchronyd\fR's version number to the terminal and exits
|
|
||||||
.TP
|
|
||||||
.B \-4
|
|
||||||
Resolve hostnames only to IPv4 addresses and create only IPv4 sockets.
|
|
||||||
.TP
|
|
||||||
.B \-6
|
|
||||||
Resolve hostnames only to IPv6 addresses and create only IPv6 sockets.
|
|
||||||
|
|
||||||
.SH FILES
|
|
||||||
\fI@SYSCONFDIR@/chrony.conf\fR
|
|
||||||
|
|
||||||
.SH BUGS
|
|
||||||
To report bugs, please visit \fIhttp://chrony.tuxfamily.org/\fR
|
|
||||||
|
|
||||||
.SH "SEE ALSO"
|
|
||||||
\fBchronyd\fR is documented in detail in the documentation supplied with the
|
|
||||||
distribution (\fIchrony.txt\fR and \fIchrony.texi\fR).
|
|
||||||
|
|
||||||
.BR chronyc(1),
|
|
||||||
.BR chrony.conf(5),
|
|
||||||
.BR hwclock(8),
|
|
||||||
.BR ntpd(8)
|
|
||||||
|
|
||||||
.I http://chrony.tuxfamily.org/
|
|
||||||
|
|
||||||
.SH AUTHOR
|
|
||||||
Richard Curnow <rc@rc0.org.uk>
|
|
||||||
|
|
||||||
This man-page was written by Jan Schaumann <jschauma@netmeister.org> as part
|
|
||||||
of "The Missing Man Pages Project". Please see
|
|
||||||
\fIhttp://www.netmeister.org/misc/m2p2/index.html\fR for details.
|
|
||||||
|
|
||||||
The complete chrony documentation is supplied in texinfo format.
|
|
||||||
|
|
||||||
74
cmdmon.c
74
cmdmon.c
@@ -132,6 +132,7 @@ static const char permissions[] = {
|
|||||||
PERMIT_AUTH, /* REFRESH */
|
PERMIT_AUTH, /* REFRESH */
|
||||||
PERMIT_AUTH, /* SERVER_STATS */
|
PERMIT_AUTH, /* SERVER_STATS */
|
||||||
PERMIT_AUTH, /* CLIENT_ACCESSES_BY_INDEX2 */
|
PERMIT_AUTH, /* CLIENT_ACCESSES_BY_INDEX2 */
|
||||||
|
PERMIT_AUTH, /* LOCAL2 */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -248,43 +249,51 @@ prepare_socket(int family, int port_number)
|
|||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
void
|
static void
|
||||||
CAM_Initialise(int family)
|
do_size_checks(void)
|
||||||
{
|
{
|
||||||
int i, port_number;
|
int i, request_length, padding_length, reply_length;
|
||||||
|
CMD_Request request;
|
||||||
|
CMD_Reply reply;
|
||||||
|
|
||||||
assert(!initialised);
|
assert(offsetof(CMD_Request, data) == 20);
|
||||||
initialised = 1;
|
assert(offsetof(CMD_Reply, data) == 28);
|
||||||
|
|
||||||
assert(sizeof (permissions) / sizeof (permissions[0]) == N_REQUEST_TYPES);
|
|
||||||
|
|
||||||
for (i = 0; i < N_REQUEST_TYPES; i++) {
|
for (i = 0; i < N_REQUEST_TYPES; i++) {
|
||||||
CMD_Request r;
|
request.version = PROTO_VERSION_NUMBER;
|
||||||
int command_length, padding_length;
|
request.command = htons(i);
|
||||||
|
request_length = PKL_CommandLength(&request);
|
||||||
r.version = PROTO_VERSION_NUMBER;
|
padding_length = PKL_CommandPaddingLength(&request);
|
||||||
r.command = htons(i);
|
if (padding_length > MAX_PADDING_LENGTH || padding_length > request_length ||
|
||||||
command_length = PKL_CommandLength(&r);
|
request_length > sizeof (CMD_Request) ||
|
||||||
padding_length = PKL_CommandPaddingLength(&r);
|
(request_length && request_length < offsetof(CMD_Request, data)))
|
||||||
assert(padding_length <= MAX_PADDING_LENGTH && padding_length <= command_length);
|
assert(0);
|
||||||
assert((command_length >= offsetof(CMD_Request, data) &&
|
|
||||||
command_length <= sizeof (CMD_Request)) || command_length == 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 1; i < N_REPLY_TYPES; i++) {
|
for (i = 1; i < N_REPLY_TYPES; i++) {
|
||||||
CMD_Reply r;
|
reply.reply = htons(i);
|
||||||
int reply_length;
|
reply.status = STT_SUCCESS;
|
||||||
|
reply.data.manual_list.n_samples = htonl(MAX_MANUAL_LIST_SAMPLES);
|
||||||
r.reply = htons(i);
|
reply_length = PKL_ReplyLength(&reply);
|
||||||
r.status = STT_SUCCESS;
|
if ((reply_length && reply_length < offsetof(CMD_Reply, data)) ||
|
||||||
r.data.manual_list.n_samples = htonl(MAX_MANUAL_LIST_SAMPLES);
|
reply_length > sizeof (CMD_Reply))
|
||||||
reply_length = PKL_ReplyLength(&r);
|
assert(0);
|
||||||
assert((reply_length >= offsetof(CMD_Reply, data) &&
|
|
||||||
reply_length <= sizeof (CMD_Reply)) || reply_length == 0);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
void
|
||||||
|
CAM_Initialise(int family)
|
||||||
|
{
|
||||||
|
int port_number;
|
||||||
|
|
||||||
|
assert(!initialised);
|
||||||
|
assert(sizeof (permissions) / sizeof (permissions[0]) == N_REQUEST_TYPES);
|
||||||
|
do_size_checks();
|
||||||
|
|
||||||
|
initialised = 1;
|
||||||
sock_fdu = -1;
|
sock_fdu = -1;
|
||||||
|
|
||||||
port_number = CNF_GetCommandPort();
|
port_number = CNF_GetCommandPort();
|
||||||
|
|
||||||
if (port_number && (family == IPADDR_UNSPEC || family == IPADDR_INET4))
|
if (port_number && (family == IPADDR_UNSPEC || family == IPADDR_INET4))
|
||||||
@@ -576,11 +585,10 @@ handle_settime(CMD_Request *rx_message, CMD_Reply *tx_message)
|
|||||||
static void
|
static void
|
||||||
handle_local(CMD_Request *rx_message, CMD_Reply *tx_message)
|
handle_local(CMD_Request *rx_message, CMD_Reply *tx_message)
|
||||||
{
|
{
|
||||||
int on_off, stratum;
|
if (ntohl(rx_message->data.local.on_off)) {
|
||||||
on_off = ntohl(rx_message->data.local.on_off);
|
REF_EnableLocal(ntohl(rx_message->data.local.stratum),
|
||||||
if (on_off) {
|
UTI_FloatNetworkToHost(rx_message->data.local.distance),
|
||||||
stratum = ntohl(rx_message->data.local.stratum);
|
ntohl(rx_message->data.local.orphan));
|
||||||
REF_EnableLocal(stratum);
|
|
||||||
} else {
|
} else {
|
||||||
REF_DisableLocal();
|
REF_DisableLocal();
|
||||||
}
|
}
|
||||||
@@ -1409,7 +1417,7 @@ read_from_cmd_socket(void *anything)
|
|||||||
handle_settime(&rx_message, &tx_message);
|
handle_settime(&rx_message, &tx_message);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case REQ_LOCAL:
|
case REQ_LOCAL2:
|
||||||
handle_local(&rx_message, &tx_message);
|
handle_local(&rx_message, &tx_message);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|||||||
37
cmdparse.c
37
cmdparse.c
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
* Copyright (C) Richard P. Curnow 1997-2003
|
* Copyright (C) Richard P. Curnow 1997-2003
|
||||||
* Copyright (C) Miroslav Lichvar 2013-2014
|
* Copyright (C) Miroslav Lichvar 2013-2014, 2016
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of version 2 of the GNU General Public License as
|
* it under the terms of version 2 of the GNU General Public License as
|
||||||
@@ -223,6 +223,41 @@ CPS_ParseNTPSourceAdd(char *line, CPS_NTP_Source *src)
|
|||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
CPS_ParseLocal(char *line, int *stratum, int *orphan, double *distance)
|
||||||
|
{
|
||||||
|
int n;
|
||||||
|
char *cmd;
|
||||||
|
|
||||||
|
*stratum = 10;
|
||||||
|
*distance = 1.0;
|
||||||
|
*orphan = 0;
|
||||||
|
|
||||||
|
while (*line) {
|
||||||
|
cmd = line;
|
||||||
|
line = CPS_SplitWord(line);
|
||||||
|
|
||||||
|
if (!strcasecmp(cmd, "stratum")) {
|
||||||
|
if (sscanf(line, "%d%n", stratum, &n) != 1 ||
|
||||||
|
*stratum >= NTP_MAX_STRATUM || *stratum <= 0)
|
||||||
|
return 0;
|
||||||
|
} else if (!strcasecmp(cmd, "orphan")) {
|
||||||
|
*orphan = 1;
|
||||||
|
n = 0;
|
||||||
|
} else if (!strcasecmp(cmd, "distance")) {
|
||||||
|
if (sscanf(line, "%lf%n", distance, &n) != 1)
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
line += n;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
void
|
void
|
||||||
CPS_StatusToString(CPS_Status status, char *dest, int len)
|
CPS_StatusToString(CPS_Status status, char *dest, int len)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -59,6 +59,9 @@ typedef struct {
|
|||||||
/* Parse a command to add an NTP server or peer */
|
/* Parse a command to add an NTP server or peer */
|
||||||
extern CPS_Status CPS_ParseNTPSourceAdd(char *line, CPS_NTP_Source *src);
|
extern CPS_Status CPS_ParseNTPSourceAdd(char *line, CPS_NTP_Source *src);
|
||||||
|
|
||||||
|
/* Parse a command to enable local reference */
|
||||||
|
extern int CPS_ParseLocal(char *line, int *stratum, int *orphan, double *distance);
|
||||||
|
|
||||||
/* Get a string describing error status */
|
/* Get a string describing error status */
|
||||||
extern void CPS_StatusToString(CPS_Status status, char *dest, int len);
|
extern void CPS_StatusToString(CPS_Status status, char *dest, int len);
|
||||||
|
|
||||||
|
|||||||
32
conf.c
32
conf.c
@@ -85,6 +85,7 @@ static char *rtc_file = NULL;
|
|||||||
static double max_update_skew = 1000.0;
|
static double max_update_skew = 1000.0;
|
||||||
static double correction_time_ratio = 3.0;
|
static double correction_time_ratio = 3.0;
|
||||||
static double max_clock_error = 1.0; /* in ppm */
|
static double max_clock_error = 1.0; /* in ppm */
|
||||||
|
static double max_drift = 500000.0; /* in ppm */
|
||||||
static double max_slew_rate = 1e6 / 12.0; /* in ppm */
|
static double max_slew_rate = 1e6 / 12.0; /* in ppm */
|
||||||
|
|
||||||
static double max_distance = 3.0;
|
static double max_distance = 3.0;
|
||||||
@@ -107,6 +108,8 @@ static char *dumpdir;
|
|||||||
|
|
||||||
static int enable_local=0;
|
static int enable_local=0;
|
||||||
static int local_stratum;
|
static int local_stratum;
|
||||||
|
static int local_orphan;
|
||||||
|
static double local_distance;
|
||||||
|
|
||||||
/* Threshold (in seconds) - if absolute value of initial error is less
|
/* Threshold (in seconds) - if absolute value of initial error is less
|
||||||
than this, slew instead of stepping */
|
than this, slew instead of stepping */
|
||||||
@@ -489,6 +492,8 @@ CNF_ParseLine(const char *filename, int number, char *line)
|
|||||||
parse_double(p, &max_clock_error);
|
parse_double(p, &max_clock_error);
|
||||||
} else if (!strcasecmp(command, "maxdistance")) {
|
} else if (!strcasecmp(command, "maxdistance")) {
|
||||||
parse_double(p, &max_distance);
|
parse_double(p, &max_distance);
|
||||||
|
} else if (!strcasecmp(command, "maxdrift")) {
|
||||||
|
parse_double(p, &max_drift);
|
||||||
} else if (!strcasecmp(command, "maxsamples")) {
|
} else if (!strcasecmp(command, "maxsamples")) {
|
||||||
parse_int(p, &max_samples);
|
parse_int(p, &max_samples);
|
||||||
} else if (!strcasecmp(command, "maxslewrate")) {
|
} else if (!strcasecmp(command, "maxslewrate")) {
|
||||||
@@ -691,9 +696,9 @@ parse_refclock(char *line)
|
|||||||
line = CPS_SplitWord(line);
|
line = CPS_SplitWord(line);
|
||||||
param = Strdup(p);
|
param = Strdup(p);
|
||||||
|
|
||||||
while (*line) {
|
for (cmd = line; *cmd; line += n, cmd = line) {
|
||||||
cmd = line;
|
|
||||||
line = CPS_SplitWord(line);
|
line = CPS_SplitWord(line);
|
||||||
|
|
||||||
if (!strcasecmp(cmd, "refid")) {
|
if (!strcasecmp(cmd, "refid")) {
|
||||||
if (sscanf(line, "%4s%n", (char *)ref, &n) != 1)
|
if (sscanf(line, "%4s%n", (char *)ref, &n) != 1)
|
||||||
break;
|
break;
|
||||||
@@ -751,10 +756,9 @@ parse_refclock(char *line)
|
|||||||
other_parse_error("Invalid refclock option");
|
other_parse_error("Invalid refclock option");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
line += n;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*line) {
|
if (*cmd) {
|
||||||
command_parse_error();
|
command_parse_error();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -814,13 +818,9 @@ parse_log(char *line)
|
|||||||
static void
|
static void
|
||||||
parse_local(char *line)
|
parse_local(char *line)
|
||||||
{
|
{
|
||||||
int stratum;
|
if (!CPS_ParseLocal(line, &local_stratum, &local_orphan, &local_distance))
|
||||||
if (sscanf(line, "stratum%d", &stratum) == 1) {
|
|
||||||
local_stratum = stratum;
|
|
||||||
enable_local = 1;
|
|
||||||
} else {
|
|
||||||
command_parse_error();
|
command_parse_error();
|
||||||
}
|
enable_local = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -1486,6 +1486,14 @@ CNF_GetMaxUpdateSkew(void)
|
|||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
|
double
|
||||||
|
CNF_GetMaxDrift(void)
|
||||||
|
{
|
||||||
|
return max_drift;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
double
|
double
|
||||||
CNF_GetMaxClockError(void)
|
CNF_GetMaxClockError(void)
|
||||||
{
|
{
|
||||||
@@ -1558,10 +1566,12 @@ CNF_GetCommandPort(void) {
|
|||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
int
|
int
|
||||||
CNF_AllowLocalReference(int *stratum)
|
CNF_AllowLocalReference(int *stratum, int *orphan, double *distance)
|
||||||
{
|
{
|
||||||
if (enable_local) {
|
if (enable_local) {
|
||||||
*stratum = local_stratum;
|
*stratum = local_stratum;
|
||||||
|
*orphan = local_orphan;
|
||||||
|
*distance = local_distance;
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
3
conf.h
3
conf.h
@@ -83,6 +83,7 @@ extern char *CNF_GetLeapSecTimezone(void);
|
|||||||
/* Value returned in ppm, as read from file */
|
/* Value returned in ppm, as read from file */
|
||||||
extern double CNF_GetMaxUpdateSkew(void);
|
extern double CNF_GetMaxUpdateSkew(void);
|
||||||
extern double CNF_GetMaxClockError(void);
|
extern double CNF_GetMaxClockError(void);
|
||||||
|
extern double CNF_GetMaxDrift(void);
|
||||||
extern double CNF_GetCorrectionTimeRatio(void);
|
extern double CNF_GetCorrectionTimeRatio(void);
|
||||||
extern double CNF_GetMaxSlewRate(void);
|
extern double CNF_GetMaxSlewRate(void);
|
||||||
|
|
||||||
@@ -91,7 +92,7 @@ extern double CNF_GetReselectDistance(void);
|
|||||||
extern double CNF_GetStratumWeight(void);
|
extern double CNF_GetStratumWeight(void);
|
||||||
extern double CNF_GetCombineLimit(void);
|
extern double CNF_GetCombineLimit(void);
|
||||||
|
|
||||||
extern int CNF_AllowLocalReference(int *stratum);
|
extern int CNF_AllowLocalReference(int *stratum, int *orphan, double *distance);
|
||||||
|
|
||||||
extern void CNF_SetupAccessRestrictions(void);
|
extern void CNF_SetupAccessRestrictions(void);
|
||||||
|
|
||||||
|
|||||||
12
configure
vendored
12
configure
vendored
@@ -111,7 +111,6 @@ Fine tuning of the installation directories:
|
|||||||
--bindir=DIR user executables [EPREFIX/bin]
|
--bindir=DIR user executables [EPREFIX/bin]
|
||||||
--sbindir=DIR system admin executables [EPREFIX/sbin]
|
--sbindir=DIR system admin executables [EPREFIX/sbin]
|
||||||
--datarootdir=DIR data root [PREFIX/share]
|
--datarootdir=DIR data root [PREFIX/share]
|
||||||
--infodir=DIR info documentation [DATAROOTDIR/info]
|
|
||||||
--mandir=DIR man documentation [DATAROOTDIR/man]
|
--mandir=DIR man documentation [DATAROOTDIR/man]
|
||||||
--docdir=DIR documentation root [DATAROOTDIR/doc/chrony]
|
--docdir=DIR documentation root [DATAROOTDIR/doc/chrony]
|
||||||
--localstatedir=DIR modifiable single-machine data [/var]
|
--localstatedir=DIR modifiable single-machine data [/var]
|
||||||
@@ -261,9 +260,6 @@ do
|
|||||||
--datarootdir=* )
|
--datarootdir=* )
|
||||||
SETDATAROOTDIR=`echo $option | sed -e 's/^.*=//;'`
|
SETDATAROOTDIR=`echo $option | sed -e 's/^.*=//;'`
|
||||||
;;
|
;;
|
||||||
--infodir=* )
|
|
||||||
SETINFODIR=`echo $option | sed -e 's/^.*=//;'`
|
|
||||||
;;
|
|
||||||
--mandir=* )
|
--mandir=* )
|
||||||
SETMANDIR=`echo $option | sed -e 's/^.*=//;'`
|
SETMANDIR=`echo $option | sed -e 's/^.*=//;'`
|
||||||
;;
|
;;
|
||||||
@@ -797,11 +793,6 @@ if [ "x$SETDATAROOTDIR" != "x" ]; then
|
|||||||
DATAROOTDIR=$SETDATAROOTDIR
|
DATAROOTDIR=$SETDATAROOTDIR
|
||||||
fi
|
fi
|
||||||
|
|
||||||
INFODIR=${DATAROOTDIR}/info
|
|
||||||
if [ "x$SETINFODIR" != "x" ]; then
|
|
||||||
INFODIR=$SETINFODIR
|
|
||||||
fi
|
|
||||||
|
|
||||||
MANDIR=${DATAROOTDIR}/man
|
MANDIR=${DATAROOTDIR}/man
|
||||||
if [ "x$SETMANDIR" != "x" ]; then
|
if [ "x$SETMANDIR" != "x" ]; then
|
||||||
MANDIR=$SETMANDIR
|
MANDIR=$SETMANDIR
|
||||||
@@ -848,7 +839,7 @@ fi
|
|||||||
|
|
||||||
add_def CHRONY_VERSION "\"${CHRONY_VERSION}\""
|
add_def CHRONY_VERSION "\"${CHRONY_VERSION}\""
|
||||||
|
|
||||||
for f in Makefile chrony.conf.5 chrony.texi chronyc.1 chronyd.8
|
for f in Makefile doc/Makefile test/unit/Makefile
|
||||||
do
|
do
|
||||||
echo Creating $f
|
echo Creating $f
|
||||||
sed -e "s%@EXTRA_OBJECTS@%${EXTRA_OBJECTS}%;\
|
sed -e "s%@EXTRA_OBJECTS@%${EXTRA_OBJECTS}%;\
|
||||||
@@ -867,7 +858,6 @@ do
|
|||||||
s%@SBINDIR@%${SBINDIR}%;\
|
s%@SBINDIR@%${SBINDIR}%;\
|
||||||
s%@DOCDIR@%${DOCDIR}%;\
|
s%@DOCDIR@%${DOCDIR}%;\
|
||||||
s%@MANDIR@%${MANDIR}%;\
|
s%@MANDIR@%${MANDIR}%;\
|
||||||
s%@INFODIR@%${INFODIR}%;\
|
|
||||||
s%@LOCALSTATEDIR@%${LOCALSTATEDIR}%;\
|
s%@LOCALSTATEDIR@%${LOCALSTATEDIR}%;\
|
||||||
s%@CHRONYSOCKDIR@%${CHRONYSOCKDIR}%;\
|
s%@CHRONYSOCKDIR@%${CHRONYSOCKDIR}%;\
|
||||||
s%@CHRONYVARDIR@%${CHRONYVARDIR}%;\
|
s%@CHRONYVARDIR@%${CHRONYVARDIR}%;\
|
||||||
|
|||||||
72
doc/Makefile.in
Normal file
72
doc/Makefile.in
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
ADOC = asciidoctor
|
||||||
|
ADOC_FLAGS =
|
||||||
|
SED = sed
|
||||||
|
HTML_TO_TXT = w3m -dump -T text/html
|
||||||
|
|
||||||
|
MAN_FILES = chrony.conf.man chronyc.man chronyd.man
|
||||||
|
TXT_FILES = faq.txt installation.txt
|
||||||
|
HTML_FILES = $(MAN_FILES:%.man=%.html) $(TXT_FILES:%.txt=%.html)
|
||||||
|
MAN_IN_FILES = $(MAN_FILES:%.man=%.man.in)
|
||||||
|
|
||||||
|
SYSCONFDIR = @SYSCONFDIR@
|
||||||
|
BINDIR = @BINDIR@
|
||||||
|
SBINDIR = @SBINDIR@
|
||||||
|
MANDIR = @MANDIR@
|
||||||
|
DOCDIR = @DOCDIR@
|
||||||
|
CHRONYSOCKDIR = @CHRONYSOCKDIR@
|
||||||
|
CHRONYVARDIR = @CHRONYVARDIR@
|
||||||
|
CHRONY_VERSION = @CHRONY_VERSION@
|
||||||
|
DEFAULT_USER = @DEFAULT_USER@
|
||||||
|
DEFAULT_HWCLOCK_FILE = @DEFAULT_HWCLOCK_FILE@
|
||||||
|
|
||||||
|
SED_COMMANDS = "s%\@SYSCONFDIR\@%$(SYSCONFDIR)%g;\
|
||||||
|
s%\@BINDIR\@%$(BINDIR)%g;\
|
||||||
|
s%\@SBINDIR\@%$(SBINDIR)%g;\
|
||||||
|
s%\@CHRONY_VERSION\@%$(CHRONY_VERSION)%g;\
|
||||||
|
s%\@DEFAULT_HWCLOCK_FILE\@%$(DEFAULT_HWCLOCK_FILE)%g;\
|
||||||
|
s%\@DEFAULT_USER\@%$(DEFAULT_USER)%g;\
|
||||||
|
s%\@CHRONYSOCKDIR\@%$(CHRONYSOCKDIR)%g;\
|
||||||
|
s%\@CHRONYVARDIR\@%$(CHRONYVARDIR)%g;"
|
||||||
|
|
||||||
|
man: $(MAN_FILES) $(MAN_IN_FILES)
|
||||||
|
html: $(HTML_FILES)
|
||||||
|
txt: $(TXT_FILES)
|
||||||
|
docs: man html
|
||||||
|
|
||||||
|
%.html: %.adoc
|
||||||
|
$(ADOC) $(ADOC_FLAGS) -b html -o - $< | $(SED) -e $(SED_COMMANDS) > $@
|
||||||
|
|
||||||
|
%.man.in: %.adoc
|
||||||
|
$(ADOC) $(ADOC_FLAGS) -b manpage -o $@ $<
|
||||||
|
|
||||||
|
%.man: %.man.in
|
||||||
|
$(SED) -e $(SED_COMMANDS) < $< > $@
|
||||||
|
|
||||||
|
%.txt: %.html
|
||||||
|
$(HTML_TO_TXT) < $< > $@
|
||||||
|
|
||||||
|
install: $(MAN_FILES)
|
||||||
|
[ -d $(DESTDIR)$(MANDIR)/man1 ] || mkdir -p $(DESTDIR)$(MANDIR)/man1
|
||||||
|
[ -d $(DESTDIR)$(MANDIR)/man5 ] || mkdir -p $(DESTDIR)$(MANDIR)/man5
|
||||||
|
[ -d $(DESTDIR)$(MANDIR)/man8 ] || mkdir -p $(DESTDIR)$(MANDIR)/man8
|
||||||
|
cp chronyc.man $(DESTDIR)$(MANDIR)/man1/chronyc.1
|
||||||
|
chmod 644 $(DESTDIR)$(MANDIR)/man1/chronyc.1
|
||||||
|
cp chronyd.man $(DESTDIR)$(MANDIR)/man8/chronyd.8
|
||||||
|
chmod 644 $(DESTDIR)$(MANDIR)/man8/chronyd.8
|
||||||
|
cp chrony.conf.man $(DESTDIR)$(MANDIR)/man5/chrony.conf.5
|
||||||
|
chmod 644 $(DESTDIR)$(MANDIR)/man5/chrony.conf.5
|
||||||
|
|
||||||
|
install-docs: $(HTML_FILES)
|
||||||
|
[ -d $(DESTDIR)$(DOCDIR) ] || mkdir -p $(DESTDIR)$(DOCDIR)
|
||||||
|
for f in $(HTML_FILES); do \
|
||||||
|
cp $$f $(DESTDIR)$(DOCDIR); \
|
||||||
|
chmod 644 $(DESTDIR)$(DOCDIR)/$$f; \
|
||||||
|
done
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f $(MAN_FILES) $(TXT_FILES) $(HTML_FILES)
|
||||||
|
rm -f $(MAN_IN_FILES)
|
||||||
|
|
||||||
|
distclean:
|
||||||
|
rm -f $(MAN_FILES) $(TXT_FILES) $(HTML_FILES)
|
||||||
|
rm -f Makefile
|
||||||
2108
doc/chrony.conf.adoc
Normal file
2108
doc/chrony.conf.adoc
Normal file
File diff suppressed because it is too large
Load Diff
1126
doc/chronyc.adoc
Normal file
1126
doc/chronyc.adoc
Normal file
File diff suppressed because it is too large
Load Diff
164
doc/chronyd.adoc
Normal file
164
doc/chronyd.adoc
Normal file
@@ -0,0 +1,164 @@
|
|||||||
|
// This file is part of chrony
|
||||||
|
//
|
||||||
|
// Copyright (C) Richard P. Curnow 1997-2003
|
||||||
|
// Copyright (C) Miroslav Lichvar 2009-2016
|
||||||
|
//
|
||||||
|
// This program is free software; you can redistribute it and/or modify
|
||||||
|
// it under the terms of version 2 of the GNU General Public License as
|
||||||
|
// published by the Free Software Foundation.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful, but
|
||||||
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
// General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License along
|
||||||
|
// with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
|
= chronyd(8)
|
||||||
|
:doctype: manpage
|
||||||
|
:man manual: System Administration
|
||||||
|
:man source: chrony @CHRONY_VERSION@
|
||||||
|
|
||||||
|
== NAME
|
||||||
|
|
||||||
|
chronyd - chrony daemon
|
||||||
|
|
||||||
|
== SYNOPSIS
|
||||||
|
|
||||||
|
*chronyd* [_OPTION_]... [_DIRECTIVE_]...
|
||||||
|
|
||||||
|
== DESCRIPTION
|
||||||
|
|
||||||
|
*chronyd* is a daemon for synchronisation of the system clock. It can
|
||||||
|
synchronise the clock with NTP servers, reference clocks (e.g. a GPS receiver),
|
||||||
|
and manual input using wristwatch and keyboard via *chronyc*. It can also
|
||||||
|
operate as an NTPv4 (RFC 5905) server and peer to provide a time service to
|
||||||
|
other computers in the network.
|
||||||
|
|
||||||
|
If no configuration directives are specified on the command line, *chronyd*
|
||||||
|
will read them from a configuration file. The compiled-in default location of
|
||||||
|
the file is _@SYSCONFDIR@/chrony.conf_.
|
||||||
|
|
||||||
|
Information messages and warnings will be logged to syslog.
|
||||||
|
|
||||||
|
== OPTIONS
|
||||||
|
|
||||||
|
*-4*::
|
||||||
|
With this option hostnames will be resolved only to IPv4 addresses and only
|
||||||
|
IPv4 sockets will be created.
|
||||||
|
|
||||||
|
*-6*::
|
||||||
|
With this option hostnames will be resolved only to IPv6 addresses and only
|
||||||
|
IPv6 sockets will be created.
|
||||||
|
|
||||||
|
*-f* _file_::
|
||||||
|
This option can be used to specify an alternate location for the configuration
|
||||||
|
file (default _@SYSCONFDIR@/chrony.conf_).
|
||||||
|
|
||||||
|
*-n*::
|
||||||
|
When run in this mode, the program will not detach itself from the terminal.
|
||||||
|
|
||||||
|
*-d*::
|
||||||
|
When run in this mode, the program will not detach itself from the terminal,
|
||||||
|
and all messages will be sent to the terminal instead of to syslog. When
|
||||||
|
*chronyd* was compiled with debugging support, this option can be used twice to
|
||||||
|
print also debugging messages.
|
||||||
|
|
||||||
|
*-q*::
|
||||||
|
When run in this mode, *chronyd* will set the system clock once and exit. It
|
||||||
|
will not detach from the terminal.
|
||||||
|
|
||||||
|
*-Q*::
|
||||||
|
This option is similar to *-q*, but it will only print the offset without any
|
||||||
|
corrections of the clock.
|
||||||
|
|
||||||
|
*-r*::
|
||||||
|
This option will reload sample histories for each of the servers and refclocks
|
||||||
|
being used. These histories are created by using the
|
||||||
|
<<chronyc.adoc#dump,*dump*>> command in *chronyc*, or by setting the
|
||||||
|
<<chrony.conf.adoc#dumponexit,*dumponexit*>> directive in the configuration
|
||||||
|
file. This option is useful if you want to stop and restart *chronyd* briefly
|
||||||
|
for any reason, e.g. to install a new version. However, it should be used only
|
||||||
|
on systems where the kernel can maintain clock compensation whilst not under
|
||||||
|
*chronyd*'s control (i.e. Linux, FreeBSD, NetBSD and Solaris).
|
||||||
|
|
||||||
|
*-R*::
|
||||||
|
When this option is used, the <<chrony.conf.adoc#initstepslew,*initstepslew*>>
|
||||||
|
directive and the <<chrony.conf.adoc#makestep,*makestep*>> directive used with
|
||||||
|
a positive limit will be ignored. This option is useful when restarting
|
||||||
|
*chronyd* and can be used in conjunction with the *-r* option.
|
||||||
|
|
||||||
|
*-s*::
|
||||||
|
This option will set the system clock from the computer's real-time clock (RTC)
|
||||||
|
or to the last modification time of the file specified by the
|
||||||
|
<<chrony.conf.adoc#driftfile,*driftfile*>> directive. Real-time clocks are
|
||||||
|
supported only on Linux.
|
||||||
|
+
|
||||||
|
If used in conjunction with the *-r* flag, *chronyd* will attempt to preserve
|
||||||
|
the old samples after setting the system clock from the RTC. This can be used
|
||||||
|
to allow *chronyd* to perform long term averaging of the gain or loss rate
|
||||||
|
across system reboots, and is useful for systems with intermittent access to
|
||||||
|
network that are shut down when not in use. For this to work well, it relies
|
||||||
|
on *chronyd* having been able to determine accurate statistics for the
|
||||||
|
difference between the RTC and system clock last time the computer was on.
|
||||||
|
+
|
||||||
|
If the last modification time of the drift file is later than both the current
|
||||||
|
time and the RTC time, the system time will be set to it to restore the time
|
||||||
|
when *chronyd* was previously stopped. This is useful on computers that have no
|
||||||
|
RTC or the RTC is broken (e.g. it has no battery).
|
||||||
|
|
||||||
|
*-u* _user_::
|
||||||
|
This option sets the name of the system user to which *chronyd* will switch
|
||||||
|
after start in order to drop root privileges. It overrides the
|
||||||
|
<<chrony.conf.adoc#user,*user*>> directive (default _@DEFAULT_USER@_).
|
||||||
|
+
|
||||||
|
On Linux, *chronyd* needs to be compiled with support for the *libcap* library.
|
||||||
|
On Mac OS X, FreeBSD, NetBSD and Solaris *chronyd* forks into two processes.
|
||||||
|
The child process retains root privileges, but can only perform a very limited
|
||||||
|
range of privileged system calls on behalf of the parent.
|
||||||
|
|
||||||
|
*-F* _level_::
|
||||||
|
This option configures a system call filter when *chronyd* is compiled with
|
||||||
|
support for the Linux secure computing (seccomp) facility. In level 1 the
|
||||||
|
process is killed when a forbidden system call is made, in level -1 the SYSSIG
|
||||||
|
signal is thrown instead and in level 0 the filter is disabled (default 0).
|
||||||
|
+
|
||||||
|
It's recommended to enable the filter only when it's known to work on the
|
||||||
|
version of the system where *chrony* is installed as the filter needs to allow
|
||||||
|
also system calls made from libraries that *chronyd* is using (e.g. libc) and
|
||||||
|
different versions or implementations of the libraries may make different
|
||||||
|
system calls. If the filter is missing some system call, *chronyd* could be
|
||||||
|
killed even in normal operation.
|
||||||
|
|
||||||
|
*-P* _priority_::
|
||||||
|
On Linux, this option will select the SCHED_FIFO real-time scheduler at the
|
||||||
|
specified priority (which must be between 0 and 100). On Mac OS X, this option
|
||||||
|
must have either a value of 0 (the default) to disable the thread time
|
||||||
|
constraint policy or 1 for the policy to be enabled. Other systems do not
|
||||||
|
support this option.
|
||||||
|
|
||||||
|
*-m*::
|
||||||
|
This option will lock *chronyd* into RAM so that it will never be paged out.
|
||||||
|
This mode is only supported on Linux.
|
||||||
|
|
||||||
|
*-v*::
|
||||||
|
With this option *chronyd* will print version number to the terminal and exit.
|
||||||
|
|
||||||
|
== FILES
|
||||||
|
|
||||||
|
_@SYSCONFDIR@/chrony.conf_
|
||||||
|
|
||||||
|
== SEE ALSO
|
||||||
|
|
||||||
|
<<chronyc.adoc#,*chronyc(1)*>>, <<chrony.conf.adoc#,*chrony.conf(5)*>>
|
||||||
|
|
||||||
|
== BUGS
|
||||||
|
|
||||||
|
For instructions on how to report bugs, please visit
|
||||||
|
https://chrony.tuxfamily.org/.
|
||||||
|
|
||||||
|
== AUTHORS
|
||||||
|
|
||||||
|
chrony was written by Richard Curnow, Miroslav Lichvar and others.
|
||||||
442
doc/faq.adoc
442
doc/faq.adoc
@@ -1,77 +1,71 @@
|
|||||||
|
// This file is part of chrony
|
||||||
|
//
|
||||||
|
// Copyright (C) Richard P. Curnow 1997-2003
|
||||||
|
// Copyright (C) Miroslav Lichvar 2014-2016
|
||||||
|
//
|
||||||
|
// This program is free software; you can redistribute it and/or modify
|
||||||
|
// it under the terms of version 2 of the GNU General Public License as
|
||||||
|
// published by the Free Software Foundation.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful, but
|
||||||
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
// General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License along
|
||||||
|
// with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
|
= Frequently Asked Questions
|
||||||
:toc:
|
:toc:
|
||||||
:numbered:
|
:numbered:
|
||||||
|
|
||||||
Frequently Asked Questions
|
== `chrony` compared to other programs
|
||||||
==========================
|
|
||||||
|
|
||||||
== +chrony+ compared to other programs
|
=== How does `chrony` compare to `ntpd`?
|
||||||
|
|
||||||
=== How does +chrony+ compare to +ntpd+?
|
`chronyd` was designed to work well in a wide range of conditions and it can
|
||||||
|
usually synchronise the system clock faster and with better time accuracy. It
|
||||||
+chronyd+ was designed to work well in a wide range of conditions and it can
|
|
||||||
usually synchronise the system clock faster and with better time accuracy. It
|
|
||||||
doesn't implement some of the less useful NTP modes like broadcast client or
|
doesn't implement some of the less useful NTP modes like broadcast client or
|
||||||
multicast server/client.
|
multicast server/client.
|
||||||
|
|
||||||
For a more detailed comparison of features and performance, see the
|
If your computer is connected to the Internet only for few minutes at a time,
|
||||||
http://chrony.tuxfamily.org/comparison.html[comparison page] on the +chrony+
|
|
||||||
website and the
|
|
||||||
http://chrony.tuxfamily.org/manual.html#Comparison-with-ntpd[Comparison with
|
|
||||||
ntpd] section in the manual.
|
|
||||||
|
|
||||||
If your computer is connected to the internet only for few minutes at a time,
|
|
||||||
the network connection is often congested, you turn your computer off or
|
the network connection is often congested, you turn your computer off or
|
||||||
suspend it frequently, the clock is not very stable (e.g. there are rapid
|
suspend it frequently, the clock is not very stable (e.g. there are rapid
|
||||||
changes in the temperature or it's a virtual machine), or you want to use NTP
|
changes in the temperature or it's a virtual machine), or you want to use NTP
|
||||||
on an isolated network with no hardware reference clocks in sight, +chrony+
|
on an isolated network with no hardware reference clocks in sight, `chrony`
|
||||||
will probably work much better for you.
|
will probably work much better for you.
|
||||||
|
|
||||||
The original reason +chrony+ was written was that +ntpd+ (called +xntpd+ at the
|
For a more detailed comparison of features and performance, see the
|
||||||
time) could not to do anything sensible on a PC which was connected to the 'net
|
https://chrony.tuxfamily.org/comparison.html[comparison page] on the `chrony`
|
||||||
only for about 5 minutes once or twice a day, mainly to upload/download email
|
website.
|
||||||
and news. The requirements were
|
|
||||||
|
|
||||||
* slew the time to correct it when going online and NTP servers
|
|
||||||
become visible
|
|
||||||
* determine the rate at which the computer gains or loses time and
|
|
||||||
use this information to keep it reasonably correct between connects
|
|
||||||
to the 'net. This has to be done using a method that does not care
|
|
||||||
about the intermittent availability of the references or the fact
|
|
||||||
the computer is turned off between groups of measurements.
|
|
||||||
* maintain the time across reboots, by working out the error and
|
|
||||||
drift rate of the computer's real-time clock and using this
|
|
||||||
information to set the system clock correctly at boot up.
|
|
||||||
|
|
||||||
Also, when working with isolated networks with no true time references at all
|
|
||||||
+ntpd+ was found to give no help with managing the local clock's gain/loss rate
|
|
||||||
on the NTP master node (which was set from watch). Some automated support was
|
|
||||||
added to +chrony+ to deal with this.
|
|
||||||
|
|
||||||
== Configuration issues
|
== Configuration issues
|
||||||
|
|
||||||
=== What is the minimum recommended configuration for an NTP client?
|
=== What is the minimum recommended configuration for an NTP client?
|
||||||
|
|
||||||
First, the client needs to know which NTP servers it should ask for the current
|
First, the client needs to know which NTP servers it should ask for the current
|
||||||
time. They are specified by the +server+ or +pool+ directive. The +pool+
|
time. They are specified by the `server` or `pool` directive. The `pool`
|
||||||
directive can be used for names that resolve to multiple addresses. For good
|
directive can be used for names that resolve to multiple addresses. For good
|
||||||
reliability the client should have at least three servers. The +iburst+ option
|
reliability the client should have at least three servers. The `iburst` option
|
||||||
speeds up the initial synchronisation.
|
speeds up the initial synchronisation.
|
||||||
|
|
||||||
To stabilize the initial synchronisation on the next start, the estimated drift
|
To stabilize the initial synchronisation on the next start, the estimated drift
|
||||||
of the system clock is saved by adding the +driftfile+ directive.
|
of the system clock is saved to a file specified by the `driftfile` directive.
|
||||||
|
|
||||||
If the system clock can be far from the true time after boot for any reason,
|
If the system clock can be far from the true time after boot for any reason,
|
||||||
+chronyd+ should be allowed to correct it quickly by stepping instead of
|
`chronyd` should be allowed to correct it quickly by stepping instead of
|
||||||
slewing, which would take a very long time. The +makestep+ directive does
|
slewing, which would take a very long time. The `makestep` directive does
|
||||||
that.
|
that.
|
||||||
|
|
||||||
In order to keep the real-time clock (RTC) close to the true time on Linux, so
|
In order to keep the real-time clock (RTC) close to the true time, so the
|
||||||
the system time is reasonably close to the true time when it's initialized on
|
system time is reasonably close to the true time when it's initialized on the
|
||||||
the next boot from the RTC, the +rtcsync+ directive enables a kernel mode in
|
next boot from the RTC, the `rtcsync` directive enables a mode in which the
|
||||||
which the system time is copied to the RTC every 11 minutes.
|
system time is periodically copied to the RTC. It is supported on Linux and Mac
|
||||||
|
OS X.
|
||||||
|
|
||||||
If you want to use public NTP servers from the
|
If you want to use public NTP servers from the
|
||||||
http://www.pool.ntp.org/[pool.ntp.org] project, the minimal 'chrony.conf' file
|
http://www.pool.ntp.org/[pool.ntp.org] project, the minimal _chrony.conf_ file
|
||||||
could be:
|
could be:
|
||||||
|
|
||||||
----
|
----
|
||||||
@@ -83,15 +77,15 @@ rtcsync
|
|||||||
|
|
||||||
=== How do I make an NTP server from an NTP client?
|
=== How do I make an NTP server from an NTP client?
|
||||||
|
|
||||||
You need to add an +allow+ directive to the 'chrony.conf' file in order to open
|
You need to add an `allow` directive to the _chrony.conf_ file in order to open
|
||||||
the NTP port and allow +chronyd+ to reply to client requests. +allow+ with no
|
the NTP port and allow `chronyd` to reply to client requests. `allow` with no
|
||||||
specified subnet allows all IPv4 and IPv6 addresses.
|
specified subnet allows all IPv4 and IPv6 addresses.
|
||||||
|
|
||||||
=== I have several computers on a LAN. Should be all clients of an external server?
|
=== I have several computers on a LAN. Should be all clients of an external server?
|
||||||
|
|
||||||
The best configuration is usually to make one computer the master, with
|
The best configuration is usually to make one computer the server, with
|
||||||
the others as clients of it. Add a +local+ directive to the master's
|
the others as clients of it. Add a `local` directive to the server's
|
||||||
'chrony.conf' file. This configuration will be better because
|
_chrony.conf_ file. This configuration will be better because
|
||||||
|
|
||||||
* the load on the external connection is less
|
* the load on the external connection is less
|
||||||
* the load on the external NTP server(s) is less
|
* the load on the external NTP server(s) is less
|
||||||
@@ -100,79 +94,79 @@ the others as clients of it. Add a +local+ directive to the master's
|
|||||||
|
|
||||||
=== Must I specify servers by IP address if DNS is not available on chronyd start?
|
=== Must I specify servers by IP address if DNS is not available on chronyd start?
|
||||||
|
|
||||||
No. Starting from version 1.25, +chronyd+ will keep trying to resolve
|
No. Starting from version 1.25, `chronyd` will keep trying to resolve
|
||||||
the hostnames specified in the +server+ and +peer+ directives in
|
the names specified by the `server`, `pool`, and `peer` directives in an
|
||||||
increasing intervals until it succeeds. The +online+ command can be
|
increasing interval until it succeeds. The `online` command can be issued from
|
||||||
issued from +chronyc+ to try to resolve them immediately.
|
`chronyc` to try to resolve them immediately.
|
||||||
|
|
||||||
=== How can I make +chronyd+ more secure?
|
=== How can I make `chronyd` more secure?
|
||||||
|
|
||||||
If you don't need to serve time to NTP clients or peers, you can add +port 0+
|
If you don't need to serve time to NTP clients or peers, you can add `port 0`
|
||||||
to the 'chrony.conf' file to completely disable the NTP server functionality
|
to the _chrony.conf_ file to completely disable the NTP server functionality
|
||||||
and prevent NTP requests from reaching +chronyd+. Starting from version 2.0,
|
and prevent NTP requests from reaching `chronyd`. Starting from version 2.0,
|
||||||
the NTP server port is open only when client access is allowed by the +allow+
|
the NTP server port is open only when client access is allowed by the `allow`
|
||||||
directive or command, an NTP peer is configured, or the +broadcast+ directive
|
directive or command, an NTP peer is configured, or the `broadcast` directive
|
||||||
is used.
|
is used.
|
||||||
|
|
||||||
If you don't need to use +chronyc+ remotely, you can add the following
|
If you don't need to use `chronyc` remotely, you can add the following
|
||||||
directives to the configuration file to bind the command sockets to the
|
directives to the configuration file to bind the command sockets to the
|
||||||
loopback interface. This is done by default since version 2.0.
|
loopback interface. This is done by default since version 2.0.
|
||||||
|
|
||||||
----
|
----
|
||||||
bindcmdaddress 127.0.0.1
|
bindcmdaddress 127.0.0.1
|
||||||
bindcmdaddress ::1
|
bindcmdaddress ::1
|
||||||
----
|
----
|
||||||
|
|
||||||
If you don't need to use +chronyc+ at all or you need to run +chronyc+ only
|
If you don't need to use `chronyc` at all or you need to run `chronyc` only
|
||||||
under the root or chrony user (which can access +chronyd+ through a Unix domain
|
under the root or _chrony_ user (which can access `chronyd` through a Unix
|
||||||
socket since version 2.2), you can disable the internet command sockets
|
domain socket since version 2.2), you can disable the internet command sockets
|
||||||
completely by adding +cmdport 0+ to the configuration file.
|
completely by adding `cmdport 0` to the configuration file.
|
||||||
|
|
||||||
You can specify an unprivileged user with the +-u+ option, or the +user+
|
You can specify an unprivileged user with the `-u` option, or the `user`
|
||||||
directive in the 'chrony.conf' file, to which +chronyd+ will switch after start
|
directive in the _chrony.conf_ file, to which `chronyd` will switch after start
|
||||||
in order to drop root privileges. The configure script has a +--with-user+
|
in order to drop root privileges. The configure script has a `--with-user`
|
||||||
option, which sets the default user. On Linux, +chronyd+ needs to be compiled
|
option, which sets the default user. On Linux, `chronyd` needs to be compiled
|
||||||
with support for the +libcap+ library. On other systems, +chronyd+ forks into
|
with support for the `libcap` library. On other systems, `chronyd` forks into
|
||||||
two processes. The child process retains root privileges, but can only perform
|
two processes. The child process retains root privileges, but can only perform
|
||||||
a very limited range of privileged system calls on behalf of the parent.
|
a very limited range of privileged system calls on behalf of the parent.
|
||||||
|
|
||||||
Also, if +chronyd+ is compiled with support for the Linux secure computing
|
Also, if `chronyd` is compiled with support for the Linux secure computing
|
||||||
(seccomp) facility, you can enable a system call filter with the +-F+ option.
|
(seccomp) facility, you can enable a system call filter with the `-F` option.
|
||||||
It will significantly reduce the kernel attack surface and possibly prevent
|
It will significantly reduce the kernel attack surface and possibly prevent
|
||||||
kernel exploits from the +chronyd+ process if it's compromised. It's
|
kernel exploits from the `chronyd` process if it's compromised. It's
|
||||||
recommended to enable the filter only when it's known to work on the version of
|
recommended to enable the filter only when it's known to work on the version of
|
||||||
the system where +chrony+ is installed as the filter needs to allow also system
|
the system where `chrony` is installed as the filter needs to allow also system
|
||||||
calls made from libraries that +chronyd+ is using (e.g. libc) and different
|
calls made from libraries that `chronyd` is using (e.g. libc) and different
|
||||||
versions or implementations of the libraries may make different system calls.
|
versions or implementations of the libraries may make different system calls.
|
||||||
If the filter is missing some system call, +chronyd+ could be killed even in
|
If the filter is missing some system call, `chronyd` could be killed even in
|
||||||
normal operation.
|
normal operation.
|
||||||
|
|
||||||
=== How can I improve the accuracy of the system clock with NTP sources?
|
=== How can I improve the accuracy of the system clock with NTP sources?
|
||||||
|
|
||||||
Select NTP servers that are well synchronised, stable and close to your
|
Select NTP servers that are well synchronised, stable and close to your
|
||||||
network. It's better to use more than one server, three or four is usually
|
network. It's better to use more than one server, three or four is usually
|
||||||
recommended as the minimum, so +chronyd+ can detect falsetickers and combine
|
recommended as the minimum, so `chronyd` can detect servers that serve false
|
||||||
measurements from multiple sources.
|
time and combine measurements from multiple sources.
|
||||||
|
|
||||||
There are also useful options which can be set in the +server+ directive, they
|
There are also useful options which can be set in the `server` directive, they
|
||||||
are +minpoll+, +maxpoll+, +polltarget+, +maxdelay+, +maxdelayratio+ and
|
are `minpoll`, `maxpoll`, `polltarget`, `maxdelay`, `maxdelayratio` and
|
||||||
+maxdelaydevratio+.
|
`maxdelaydevratio`.
|
||||||
|
|
||||||
The first three options set the minimum and maximum allowed polling interval,
|
The first three options set the minimum and maximum allowed polling interval,
|
||||||
and how should be the actual interval adjusted in the specified range. Their
|
and how should be the actual interval adjusted in the specified range. Their
|
||||||
default values are 6 (64 seconds) for +minpoll+, 10 (1024 seconds) for
|
default values are 6 (64 seconds) for `minpoll`, 10 (1024 seconds) for
|
||||||
+maxpoll+ and 6 (samples) for +polltarget+. The default values should be used
|
`maxpoll` and 6 (samples) for `polltarget`. The default values should be used
|
||||||
for general servers on the internet. With your own NTP servers or if have
|
for general servers on the Internet. With your own NTP servers or if have
|
||||||
permission to poll some servers more frequently, setting these options for
|
permission to poll some servers more frequently, setting these options for
|
||||||
shorter polling intervals may significantly improve the accuracy of the system
|
shorter polling intervals may significantly improve the accuracy of the system
|
||||||
clock.
|
clock.
|
||||||
|
|
||||||
The optimal polling interval depends on many factors, including the ratio
|
The optimal polling interval depends mainly on two factors, stability of the
|
||||||
between the wander of the clock and the network jitter (sometimes expressed in
|
network latency and stability of the system clock (which mainly depends on the
|
||||||
NTP documents as the Allan intercept), the temperature sensitivity of the
|
temperature sensitivity of the crystal oscillator and the maximum rate of the
|
||||||
crystal oscillator and the maximum rate of change of the temperature.
|
temperature change).
|
||||||
|
|
||||||
An example of the directive for an NTP server on the internet that you are
|
An example of the directive for an NTP server on the Internet that you are
|
||||||
allowed to poll frequently could be
|
allowed to poll frequently could be
|
||||||
|
|
||||||
----
|
----
|
||||||
@@ -188,96 +182,126 @@ server ntp.local minpoll 2 maxpoll 4 polltarget 30
|
|||||||
|
|
||||||
The maxdelay options are useful to ignore measurements with larger delay (e.g.
|
The maxdelay options are useful to ignore measurements with larger delay (e.g.
|
||||||
due to congestion in the network) and improve the stability of the
|
due to congestion in the network) and improve the stability of the
|
||||||
synchronisation. The +maxdelaydevratio+ option could be added to the example
|
synchronisation. The `maxdelaydevratio` option could be added to the example
|
||||||
with local NTP server
|
with local NTP server
|
||||||
|
|
||||||
----
|
----
|
||||||
server ntp.local minpoll 2 maxpoll 4 polltarget 30 maxdelaydevratio 2
|
server ntp.local minpoll 2 maxpoll 4 polltarget 30 maxdelaydevratio 2
|
||||||
----
|
----
|
||||||
|
|
||||||
=== What happened to the +commandkey+ and +generatecommandkey+ directives?
|
=== What happened to the `commandkey` and `generatecommandkey` directives?
|
||||||
|
|
||||||
They were removed in version 2.2. Authentication is no longer supported in the
|
They were removed in version 2.2. Authentication is no longer supported in the
|
||||||
command protocol. Commands that required authentication are now allowed only
|
command protocol. Commands that required authentication are now allowed only
|
||||||
through a Unix domain socket, which is accessible only by the root and chrony
|
through a Unix domain socket, which is accessible only by the root and _chrony_
|
||||||
users. If you need to configure +chronyd+ remotely or locally without the root
|
users. If you need to configure `chronyd` remotely or locally without the root
|
||||||
password, please consider using ssh and/or sudo to run +chronyc+ under the root
|
password, please consider using ssh and/or sudo to run `chronyc` under the root
|
||||||
or chrony user on the same host as +chronyd+ is running.
|
or _chrony_ user on the host where `chronyd` is running.
|
||||||
|
|
||||||
== Computer is not synchronising
|
== Computer is not synchronising
|
||||||
|
|
||||||
This is the most common problem. There are a number of reasons, see the
|
This is the most common problem. There are a number of reasons, see the
|
||||||
following questions.
|
following questions.
|
||||||
|
|
||||||
=== Behind a firewall?
|
=== Behind a firewall?
|
||||||
|
|
||||||
If there is a firewall between you and the NTP server you're trying to use, the
|
Check the `Reach` value printed by the ``chronyc``'s `sources` command. If it's
|
||||||
packets may be blocked. Try using a tool like +wireshark+ or +tcpdump+ to see if
|
zero, it means `chronyd` did not get any valid responses from the NTP server
|
||||||
you're getting responses from the server. If you have an external modem, see
|
you are trying to use. If there is a firewall between you and the server, the
|
||||||
if the receive light blinks straight after the transmit light (when the link is
|
packets may be blocked. Try using a tool like `wireshark` or `tcpdump` to see
|
||||||
quiet apart from the NTP traffic.) Try adding +log measurements+ to the
|
if you're getting any responses from the server.
|
||||||
'chrony.conf' file and look in the 'measurements.log' file after +chronyd+ has
|
|
||||||
been running for a short period. See if any measurements appear.
|
|
||||||
|
|
||||||
=== Are NTP servers specified with the +offline+ option?
|
When `chronyd` is receiving responses from the servers, the output of the
|
||||||
|
`sources` command issued few minutes after `chronyd` start might look like
|
||||||
|
this:
|
||||||
|
|
||||||
Check that you're using +chronyc+\'s +online+ and +offline+ commands
|
----
|
||||||
appropriately. Again, check in 'measurements.log' to see if you're getting any
|
210 Number of sources = 3
|
||||||
|
MS Name/IP address Stratum Poll Reach LastRx Last sample
|
||||||
|
===============================================================================
|
||||||
|
^* foo.example.net 2 6 377 34 +484us[ -157us] +/- 30ms
|
||||||
|
^- bar.example.net 2 6 377 34 +33ms[ +32ms] +/- 47ms
|
||||||
|
^+ baz.example.net 3 6 377 35 -1397us[-2033us] +/- 60ms
|
||||||
|
----
|
||||||
|
|
||||||
|
=== Are NTP servers specified with the `offline` option?
|
||||||
|
|
||||||
|
Check that you're using ``chronyc``'s `online` and `offline` commands
|
||||||
|
appropriately. Again, check in _measurements.log_ to see if you're getting any
|
||||||
data back from the server.
|
data back from the server.
|
||||||
|
|
||||||
=== Is +chronyd+ allowed to step the system clock?
|
=== Is `chronyd` allowed to step the system clock?
|
||||||
|
|
||||||
By default, +chronyd+ adjusts the clock gradually by slowing it down or
|
By default, `chronyd` adjusts the clock gradually by slowing it down or
|
||||||
speeding it up. If the clock is too far from the correct time, it will take
|
speeding it up. If the clock is too far from the true time, it will take
|
||||||
a long time to correct the error. The +System time+ value printed by the
|
a long time to correct the error. The `System time` value printed by the
|
||||||
+chronyc+'s +tracking+ command is the remaining correction that needs to be
|
``chronyc``'s `tracking` command is the remaining correction that needs to be
|
||||||
applied to the system clock.
|
applied to the system clock.
|
||||||
|
|
||||||
The +makestep+ directive can be used to allow +chronyd+ to step the clock. For
|
The `makestep` directive can be used to allow `chronyd` to step the clock. For
|
||||||
example, if 'chrony.conf' had
|
example, if _chrony.conf_ had
|
||||||
|
|
||||||
----
|
----
|
||||||
makestep 1 3
|
makestep 1 3
|
||||||
----
|
----
|
||||||
|
|
||||||
the clock would be stepped in the first three updates if its offset was larger
|
the clock would be stepped in the first three updates if its offset was larger
|
||||||
than one second. Normally, it's recommended to allow the step only in the
|
than one second. Normally, it's recommended to allow the step only in the first
|
||||||
first few updates, but in some cases (e.g. a computer without RTC or virtual
|
few updates, but in some cases (e.g. a computer without an RTC or virtual
|
||||||
machine which can be suspended and resumed with incorrect time) it may be
|
machine which can be suspended and resumed with an incorrect time) it may be
|
||||||
necessary to allow the step at any clock update. The example above would
|
necessary to allow the step on any clock update. The example above would change
|
||||||
change to
|
to
|
||||||
|
|
||||||
----
|
----
|
||||||
makestep 1 -1
|
makestep 1 -1
|
||||||
----
|
----
|
||||||
|
|
||||||
== Issues with +chronyc+
|
== Issues with `chronyc`
|
||||||
|
|
||||||
=== I keep getting the error +506 Cannot talk to daemon+
|
=== I keep getting the error `506 Cannot talk to daemon`
|
||||||
|
|
||||||
When accessing +chronyd+ remotely, make sure that the 'chrony.conf' file (on
|
When accessing `chronyd` remotely, make sure that the _chrony.conf_ file (on
|
||||||
the computer where +chronyd+ is running) has a 'cmdallow' entry for the
|
the computer where `chronyd` is running) has a `cmdallow` entry for the
|
||||||
computer you are running +chronyc+ on and an appropriate 'bindcmdaddress'
|
computer you are running `chronyc` on and an appropriate `bindcmdaddress`
|
||||||
directive. This isn't necessary for localhost.
|
directive. This isn't necessary for localhost.
|
||||||
|
|
||||||
Perhaps +chronyd+ is not running. Try using the +ps+ command (e.g. on Linux,
|
Perhaps `chronyd` is not running. Try using the `ps` command (e.g. on Linux,
|
||||||
+ps -auxw+) to see if it's running. Or try +netstat -a+ and see if the ports
|
`ps -auxw`) to see if it's running. Or try `netstat -a` and see if the ports
|
||||||
123/udp and 323/udp are listening. If +chronyd+ is not running, you may have a
|
123/udp and 323/udp are listening. If `chronyd` is not running, you may have a
|
||||||
problem with the way you are trying to start it (e.g. at boot time).
|
problem with the way you are trying to start it (e.g. at boot time).
|
||||||
|
|
||||||
Perhaps you have a firewall set up in a way that blocks packets on port
|
Perhaps you have a firewall set up in a way that blocks packets on port
|
||||||
323/udp. You need to amend the firewall configuration in this case.
|
323/udp. You need to amend the firewall configuration in this case.
|
||||||
|
|
||||||
=== I keep getting the error +501 Not authorised+
|
=== I keep getting the error `501 Not authorised`
|
||||||
|
|
||||||
Since version 2.2, the +password+ command doesn't do anything and +chronyc+
|
Since version 2.2, the `password` command doesn't do anything and `chronyc`
|
||||||
needs to run under the root or chrony user, which are allowed to access the
|
needs to run locally under the root or _chrony_ user, which are allowed to
|
||||||
Unix domain command socket.
|
access the ``chronyd``'s Unix domain command socket.
|
||||||
|
|
||||||
=== Is the +chronyc+ / +chronyd+ protocol documented anywhere?
|
With older versions, you need to authenticate with the `password` command first
|
||||||
|
or use the `-a` option to authenticate automatically on start. The
|
||||||
|
configuration file needs to specify a file which contains keys (`keyfile`
|
||||||
|
directive) and which key in the key file should be used for `chronyc`
|
||||||
|
authentication (`commandkey` directive).
|
||||||
|
|
||||||
Only by the source code :-) See 'cmdmon.c' (+chronyd+ side) and 'client.c'
|
=== Why does `chronyc tracking` always print an IPv4 address as reference ID?
|
||||||
(+chronyc+ side).
|
|
||||||
|
The reference ID is a 32-bit value and is always printed in quad-dotted
|
||||||
|
notation, even if the reference source doesn't have an IPv4 address. For IPv4
|
||||||
|
addresses, the reference ID is equal to the address, but for IPv6 addresses it
|
||||||
|
is the first 32 bits of the MD5 sum of the address. For reference clocks, the
|
||||||
|
reference ID is the value specified with the `refid` option in the `refclock`
|
||||||
|
directive.
|
||||||
|
|
||||||
|
If you need to get the IP address of the current reference source, use the `-n`
|
||||||
|
option to disable resolving of IP addresses and read the second field (printed
|
||||||
|
in parentheses) on the `Reference ID` line.
|
||||||
|
|
||||||
|
=== Is the `chronyc` / `chronyd` protocol documented anywhere?
|
||||||
|
|
||||||
|
Only by the source code. See _cmdmon.c_ (`chronyd` side) and _client.c_
|
||||||
|
(`chronyc` side).
|
||||||
|
|
||||||
== Real-time clock issues
|
== Real-time clock issues
|
||||||
|
|
||||||
@@ -287,96 +311,94 @@ This is the clock which keeps the time even when your computer is turned off.
|
|||||||
It is used to initialize the system clock on boot. It normally doesn't drift
|
It is used to initialize the system clock on boot. It normally doesn't drift
|
||||||
more than few seconds per day.
|
more than few seconds per day.
|
||||||
|
|
||||||
There are two approaches how +chronyd+ can work with it. One is to use the
|
There are two approaches how `chronyd` can work with it. One is to use the
|
||||||
+rtcsync+ directive, which tells +chronyd+ to enable a kernel mode which sets
|
`rtcsync` directive, which tells `chronyd` to enable a kernel mode which sets
|
||||||
the RTC from the system clock every 11 minutes. +chronyd+ itself won't touch
|
the RTC from the system clock every 11 minutes. `chronyd` itself won't touch
|
||||||
the RTC. If the computer is not turned off for a long time, the RTC should
|
the RTC. If the computer is not turned off for a long time, the RTC should
|
||||||
still be close to the true time when the system clock will be initialized from
|
still be close to the true time when the system clock will be initialized from
|
||||||
it on the next boot.
|
it on the next boot.
|
||||||
|
|
||||||
The other option is to use the +rtcfile+ directive, which will tell +chronyd+
|
The other option is to use the `rtcfile` directive, which tells `chronyd` to
|
||||||
to monitor the rate at which the RTC gains or loses time. When +chronyd+ is
|
monitor the rate at which the RTC gains or loses time. When `chronyd` is
|
||||||
started with the +-s+ option on the next boot, it will set the system time from
|
started with the `-s` option on the next boot, it will set the system time from
|
||||||
the RTC and also compensate for the drift it has measured previously. The
|
the RTC and also compensate for the drift it has measured previously. The
|
||||||
+rtcautotrim+ directive can be used to keep the RTC close to the true time, but
|
`rtcautotrim` directive can be used to keep the RTC close to the true time, but
|
||||||
it's not strictly necessary if its only purpose is to set the system clock when
|
it's not strictly necessary if its only purpose is to set the system clock when
|
||||||
+chronyd+ is started on boot. See the documentation for details.
|
`chronyd` is started on boot. See the documentation for details.
|
||||||
|
|
||||||
=== I want to use +chronyd+'s RTC support. Must I disable +hwclock+?
|
=== I want to use ``chronyd``'s RTC support. Must I disable `hwclock`?
|
||||||
|
|
||||||
The +hwclock+ program is often set-up by default in the boot and shutdown
|
The `hwclock` program is often set-up by default in the boot and shutdown
|
||||||
scripts with many Linux installations. With the kernel RTC synchronisation
|
scripts with many Linux installations. With the kernel RTC synchronisation
|
||||||
(+rtcsync+ directive), the RTC will be set also every 11 minutes as long as the
|
(`rtcsync` directive), the RTC will be set also every 11 minutes as long as the
|
||||||
system clock is synchronised. If you want to use +chronyd+'s RTC monitoring
|
system clock is synchronised. If you want to use ``chronyd``'s RTC monitoring
|
||||||
(+rtcfile+ directive), it's important to disable +hwclock+ in the shutdown
|
(`rtcfile` directive), it's important to disable `hwclock` in the shutdown
|
||||||
procedure. If you don't, it will over-write the RTC with a new value, unknown
|
procedure. If you don't, it will over-write the RTC with a new value, unknown
|
||||||
to +chronyd+. At the next reboot, +chronyd+ started with the +-s+ option will
|
to `chronyd`. At the next reboot, `chronyd` started with the `-s` option will
|
||||||
compensate this (wrong) time with its estimate of how far the RTC has drifted
|
compensate this (wrong) time with its estimate of how far the RTC has drifted
|
||||||
whilst the power was off, giving a meaningless initial system time.
|
whilst the power was off, giving a meaningless initial system time.
|
||||||
|
|
||||||
There is no need to remove +hwclock+ from the boot process, as long as +chronyd+
|
There is no need to remove `hwclock` from the boot process, as long as `chronyd`
|
||||||
is started after it has run.
|
is started after it has run.
|
||||||
|
|
||||||
=== I just keep getting the +513 RTC driver not running+ message
|
=== I just keep getting the `513 RTC driver not running` message
|
||||||
|
|
||||||
For the real time clock support to work, you need the following three
|
For the real-time clock support to work, you need the following three
|
||||||
things
|
things
|
||||||
|
|
||||||
* a kernel that is supported (e.g. 2.2 onwards)
|
* an RTC in your computer
|
||||||
* enhanced RTC support compiled into the kernel
|
* a Linux kernel with enabled RTC support
|
||||||
* an +rtcfile+ directive in your 'chrony.conf' file
|
* an `rtcfile` directive in your _chrony.conf_ file
|
||||||
|
|
||||||
== NTP-specific issues
|
=== I get `Could not open /dev/rtc, Device or resource busy` in my syslog file
|
||||||
|
|
||||||
=== Can +chronyd+ be driven from broadcast NTP servers?
|
|
||||||
|
|
||||||
No, the broadcast client mode is not supported and there is currently no plan
|
|
||||||
to implement it. The broadcast and multicast modes are inherently less
|
|
||||||
accurate and less secure (even with authentication) than the ordinary
|
|
||||||
server/client mode and they are not as useful as they used to be. Even with
|
|
||||||
very modest hardware a single NTP server can serve time to hundreds of
|
|
||||||
thousands of clients using the ordinary mode.
|
|
||||||
|
|
||||||
=== Can +chronyd+ transmit broadcast NTP packets?
|
|
||||||
|
|
||||||
Yes, the +broadcast+ directive can be used to enable the broadcast server mode
|
|
||||||
to serve time to clients in the network which support the broadcast client mode
|
|
||||||
(it's not supported in +chronyd+, see the previous question).
|
|
||||||
|
|
||||||
=== Can +chronyd+ keep the system clock a fixed offset away from real time?
|
|
||||||
|
|
||||||
This is not possible as the program currently stands.
|
|
||||||
|
|
||||||
=== What happens if the network connection is dropped without using +chronyc+'s +offline+ command first?
|
|
||||||
|
|
||||||
+chronyd+ will keep trying to access the server(s) that it thinks are online.
|
|
||||||
When the network is connected again, it will take some time (on average half of
|
|
||||||
the current polling interval) before new measurements are made and the clock is
|
|
||||||
corrected. If the servers were set to offline and the +online+ command was
|
|
||||||
issued when the network was connected, +chronyd+ would make new measurements
|
|
||||||
immediately.
|
|
||||||
|
|
||||||
The +auto_offline+ option to the +server+ entry in the 'chrony.conf' file may
|
|
||||||
be useful to switch the servers to the offline state automatically.
|
|
||||||
|
|
||||||
== Linux-specific issues
|
|
||||||
|
|
||||||
=== I get +Could not open /dev/rtc, Device or resource busy+ in my syslog file
|
|
||||||
|
|
||||||
Some other program running on the system may be using the device.
|
Some other program running on the system may be using the device.
|
||||||
|
|
||||||
== Microsoft Windows
|
== NTP-specific issues
|
||||||
|
|
||||||
=== Does +chrony+ support Windows?
|
=== Can `chronyd` be driven from broadcast NTP servers?
|
||||||
|
|
||||||
No. The +chronyc+ program (the command-line client used for configuring
|
No, the broadcast client mode is not supported and there is currently no plan
|
||||||
+chronyd+ while it is running) has been successfully built and run under
|
to implement it. The broadcast and multicast modes are inherently less
|
||||||
Cygwin in the past. +chronyd+ is not portable, because part of it is
|
accurate and less secure (even with authentication) than the ordinary
|
||||||
very system-dependent. It needs adapting to work with Windows'
|
server/client mode and they are not as useful as they used to be. Even with
|
||||||
|
very modest hardware a single NTP server can serve time to hundreds of
|
||||||
|
thousands of clients using the ordinary mode.
|
||||||
|
|
||||||
|
=== Can `chronyd` transmit broadcast NTP packets?
|
||||||
|
|
||||||
|
Yes, the `broadcast` directive can be used to enable the broadcast server mode
|
||||||
|
to serve time to clients in the network which support the broadcast client mode
|
||||||
|
(it's not supported in `chronyd`, see the previous question).
|
||||||
|
|
||||||
|
=== Can `chronyd` keep the system clock a fixed offset away from real time?
|
||||||
|
|
||||||
|
This is not possible as the program currently stands.
|
||||||
|
|
||||||
|
=== What happens if the network connection is dropped without using ``chronyc``'s `offline` command first?
|
||||||
|
|
||||||
|
`chronyd` will keep trying to access the server(s) that it thinks are online.
|
||||||
|
When the network is connected again, it will take some time (on average half of
|
||||||
|
the maximum polling interval) before new measurements are made and the clock is
|
||||||
|
corrected. If the servers were set to offline and the `online` command was
|
||||||
|
issued when the network was connected, `chronyd` would make new measurements
|
||||||
|
immediately.
|
||||||
|
|
||||||
|
The `auto_offline` option to the `server` entry in the _chrony.conf_ file may
|
||||||
|
be useful to switch the servers to the offline state automatically.
|
||||||
|
|
||||||
|
== Operating systems
|
||||||
|
|
||||||
|
=== Does `chrony` support Windows?
|
||||||
|
|
||||||
|
No. The `chronyc` program (the command-line client used for configuring
|
||||||
|
`chronyd` while it is running) has been successfully built and run under
|
||||||
|
Cygwin in the past. `chronyd` is not portable, because part of it is
|
||||||
|
very system-dependent. It needs adapting to work with Windows'
|
||||||
equivalent of the adjtimex() call, and it needs to be made to work as a
|
equivalent of the adjtimex() call, and it needs to be made to work as a
|
||||||
service.
|
service.
|
||||||
|
|
||||||
=== Are there any plans to support Windows?
|
=== Are there any plans to support Windows?
|
||||||
|
|
||||||
We have no plans to do this. Anyone is welcome to pick this work up and
|
We have no plans to do this. Anyone is welcome to pick this work up and
|
||||||
contribute it back to the project.
|
contribute it back to the project.
|
||||||
|
|||||||
189
doc/installation.adoc
Normal file
189
doc/installation.adoc
Normal file
@@ -0,0 +1,189 @@
|
|||||||
|
// This file is part of chrony
|
||||||
|
//
|
||||||
|
// Copyright (C) Richard P. Curnow 1997-2003
|
||||||
|
// Copyright (C) Miroslav Lichvar 2009-2016
|
||||||
|
//
|
||||||
|
// This program is free software; you can redistribute it and/or modify
|
||||||
|
// it under the terms of version 2 of the GNU General Public License as
|
||||||
|
// published by the Free Software Foundation.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful, but
|
||||||
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
// General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License along
|
||||||
|
// with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
|
= Installation
|
||||||
|
|
||||||
|
The software is distributed as source code which has to be compiled. The source
|
||||||
|
code is supplied in the form of a gzipped tar file, which unpacks to a
|
||||||
|
subdirectory identifying the name and version of the program.
|
||||||
|
|
||||||
|
After unpacking the source code, change directory into it, and type
|
||||||
|
|
||||||
|
----
|
||||||
|
./configure
|
||||||
|
----
|
||||||
|
|
||||||
|
This is a shell script that automatically determines the system type. There is
|
||||||
|
a single optional parameter, `--prefix` which indicates the directory tree
|
||||||
|
where the software should be installed. For example,
|
||||||
|
|
||||||
|
----
|
||||||
|
./configure --prefix=/opt/free
|
||||||
|
----
|
||||||
|
|
||||||
|
will install the `chronyd` daemon into `/opt/free/sbin` and the `chronyc`
|
||||||
|
control program into `/opt/free/bin`. The default value for the prefix is
|
||||||
|
`/usr/local`.
|
||||||
|
|
||||||
|
The configure script assumes you want to use gcc as your compiler. If you want
|
||||||
|
to use a different compiler, you can configure this way:
|
||||||
|
|
||||||
|
----
|
||||||
|
CC=cc CFLAGS=-O ./configure --prefix=/opt/free
|
||||||
|
----
|
||||||
|
|
||||||
|
for Bourne-family shells, or
|
||||||
|
|
||||||
|
----
|
||||||
|
setenv CC cc
|
||||||
|
setenv CFLAGS -O
|
||||||
|
./configure --prefix=/opt/free
|
||||||
|
----
|
||||||
|
|
||||||
|
for C-family shells.
|
||||||
|
|
||||||
|
If the software cannot (yet) be built on your system, an error message will be
|
||||||
|
shown. Otherwise, `Makefile` will be generated.
|
||||||
|
|
||||||
|
On Linux, if development files for the libcap library are available, `chronyd`
|
||||||
|
will be built with support for dropping root privileges. On other systems no
|
||||||
|
extra library is needed. The default user which `chronyd` should run as can be
|
||||||
|
specified with the `--with-user` option of the configure script.
|
||||||
|
|
||||||
|
If development files for the editline or readline library are available,
|
||||||
|
`chronyc` will be built with line editing support. If you don't want this,
|
||||||
|
specify the `--disable-readline` flag to configure.
|
||||||
|
|
||||||
|
If a `timepps.h` header is available (e.g. from the
|
||||||
|
http://linuxpps.org[LinuxPPS project]), `chronyd` will be built with PPS API
|
||||||
|
reference clock driver. If the header is installed in a location that isn't
|
||||||
|
normally searched by the compiler, you can add it to the searched locations by
|
||||||
|
setting the `CPPFLAGS` variable to `-I/path/to/timepps`.
|
||||||
|
|
||||||
|
Now type
|
||||||
|
|
||||||
|
----
|
||||||
|
make
|
||||||
|
----
|
||||||
|
|
||||||
|
to build the programs.
|
||||||
|
|
||||||
|
If you want to build the manual in HTML, type
|
||||||
|
|
||||||
|
----
|
||||||
|
make docs
|
||||||
|
----
|
||||||
|
|
||||||
|
Once the programs have been successfully compiled, they need to be installed in
|
||||||
|
their target locations. This step normally needs to be performed by the
|
||||||
|
superuser, and requires the following command to be entered.
|
||||||
|
|
||||||
|
----
|
||||||
|
make install
|
||||||
|
----
|
||||||
|
|
||||||
|
This will install the binaries and man pages.
|
||||||
|
|
||||||
|
To install the HTML version of the manual, enter the command
|
||||||
|
|
||||||
|
----
|
||||||
|
make install-docs
|
||||||
|
----
|
||||||
|
|
||||||
|
Now that the software is successfully installed, the next step is to set up a
|
||||||
|
configuration file. The default location of the file is _/etc/chrony.conf_.
|
||||||
|
Several examples of configuration with comments are included in the examples
|
||||||
|
directory. Suppose you want to use public NTP servers from the pool.ntp.org
|
||||||
|
project as your time reference. A minimal useful configuration file could be
|
||||||
|
|
||||||
|
----
|
||||||
|
pool pool.ntp.org iburst
|
||||||
|
makestep 1.0 3
|
||||||
|
rtcsync
|
||||||
|
----
|
||||||
|
|
||||||
|
Then, `chronyd` can be run. For security reasons, it's recommended to create an
|
||||||
|
unprivileged user for `chronyd` and specify it with the `-u` command-line
|
||||||
|
option or the `user` directive in the configuration file, or set the default
|
||||||
|
user with the `--with-user` configure option before building.
|
||||||
|
|
||||||
|
== Support for line editing libraries
|
||||||
|
|
||||||
|
`chronyc` can be built with support for line editing, this allows you to use
|
||||||
|
the cursor keys to replay and edit old commands. Two libraries are supported
|
||||||
|
which provide such functionality, editline and GNU readline.
|
||||||
|
|
||||||
|
Please note that readline since version 6.0 is licensed under GPLv3+ which is
|
||||||
|
incompatible with chrony's license GPLv2. You should use editline instead if
|
||||||
|
you don't want to use older readline versions.
|
||||||
|
|
||||||
|
The configure script will automatically enable the line editing support if one
|
||||||
|
of the supported libraries is available. If they are both available, the
|
||||||
|
editline library will be used.
|
||||||
|
|
||||||
|
If you don't want to use it (in which case chronyc will use a minimal command
|
||||||
|
line interface), invoke configure like this:
|
||||||
|
|
||||||
|
----
|
||||||
|
./configure --disable-readline other-options...
|
||||||
|
----
|
||||||
|
|
||||||
|
If you have editline, readline or ncurses installed in locations that aren't
|
||||||
|
normally searched by the compiler and linker, you need to use extra options:
|
||||||
|
|
||||||
|
`--with-readline-includes=directory_name`::
|
||||||
|
This defines the name of the directory above the one where `readline.h` is.
|
||||||
|
`readline.h` is assumed to be in `editline` or `readline` subdirectory of the
|
||||||
|
named directory.
|
||||||
|
|
||||||
|
`--with-readline-library=directory_name`::
|
||||||
|
This defines the directory containing the `libedit.a` or `libedit.so` file,
|
||||||
|
or `libreadline.a` or `libreadline.so` file.
|
||||||
|
|
||||||
|
`--with-ncurses-library=directory_name`::
|
||||||
|
This defines the directory containing the `libncurses.a` or `libncurses.so`
|
||||||
|
file.
|
||||||
|
|
||||||
|
== Extra options for package builders
|
||||||
|
|
||||||
|
The configure and make procedures have some extra options that may be useful if
|
||||||
|
you are building a distribution package for chrony.
|
||||||
|
|
||||||
|
The `--mandir=DIR` option to configure specifies an install directory for the
|
||||||
|
man pages. This overrides the `man` subdirectory of the argument to the
|
||||||
|
--prefix option.
|
||||||
|
|
||||||
|
----
|
||||||
|
./configure --prefix=/usr --mandir=/usr/share/man
|
||||||
|
----
|
||||||
|
|
||||||
|
to set both options together.
|
||||||
|
|
||||||
|
The final option is the `DESTDIR` option to the make command. For example, you
|
||||||
|
could use the commands
|
||||||
|
|
||||||
|
----
|
||||||
|
./configure --prefix=/usr --mandir=/usr/share/man
|
||||||
|
make all docs
|
||||||
|
make install DESTDIR=./tmp
|
||||||
|
cd tmp
|
||||||
|
tar cvf - . | gzip -9 > chrony.tar.gz
|
||||||
|
----
|
||||||
|
|
||||||
|
to build a package. When untarred within the root directory, this will install
|
||||||
|
the files to the intended final locations.
|
||||||
@@ -10,7 +10,6 @@ Source: chrony-%{version}%{?prerelease:-%{prerelease}}.tar.gz
|
|||||||
License: GPLv2
|
License: GPLv2
|
||||||
Group: Applications/Utilities
|
Group: Applications/Utilities
|
||||||
BuildRoot: %{_tmppath}/%{name}-%{version}-root-%(id -u -n)
|
BuildRoot: %{_tmppath}/%{name}-%{version}-root-%(id -u -n)
|
||||||
Requires: info
|
|
||||||
|
|
||||||
%description
|
%description
|
||||||
chrony is a client and server for the Network Time Protocol (NTP).
|
chrony is a client and server for the Network Time Protocol (NTP).
|
||||||
@@ -28,29 +27,20 @@ manual input as time references.
|
|||||||
--prefix=%{_prefix} \
|
--prefix=%{_prefix} \
|
||||||
--bindir=%{_bindir} \
|
--bindir=%{_bindir} \
|
||||||
--sbindir=%{_sbindir} \
|
--sbindir=%{_sbindir} \
|
||||||
--infodir=%{_infodir} \
|
|
||||||
--mandir=%{_mandir}
|
--mandir=%{_mandir}
|
||||||
make
|
make
|
||||||
make chrony.txt
|
|
||||||
make chrony.info
|
|
||||||
|
|
||||||
%install
|
%install
|
||||||
rm -rf $RPM_BUILD_ROOT
|
rm -rf $RPM_BUILD_ROOT
|
||||||
make install DESTDIR=$RPM_BUILD_ROOT
|
make install DESTDIR=$RPM_BUILD_ROOT
|
||||||
rm -rf $RPM_BUILD_ROOT%{_docdir}
|
|
||||||
mkdir -p $RPM_BUILD_ROOT%{_infodir}
|
|
||||||
cp chrony.info* $RPM_BUILD_ROOT%{_infodir}
|
|
||||||
|
|
||||||
%files
|
%files
|
||||||
%{_sbindir}/chronyd
|
%{_sbindir}/chronyd
|
||||||
%{_bindir}/chronyc
|
%{_bindir}/chronyc
|
||||||
%{_infodir}/chrony.info*
|
|
||||||
%{_mandir}/man1/chronyc.1.gz
|
%{_mandir}/man1/chronyc.1.gz
|
||||||
%{_mandir}/man5/chrony.conf.5.gz
|
%{_mandir}/man5/chrony.conf.5.gz
|
||||||
%{_mandir}/man8/chronyd.8.gz
|
%{_mandir}/man8/chronyd.8.gz
|
||||||
%doc README
|
%doc README FAQ NEWS COPYING
|
||||||
%doc chrony.txt
|
|
||||||
%doc COPYING
|
|
||||||
%doc examples/chrony.conf.example*
|
%doc examples/chrony.conf.example*
|
||||||
%doc examples/chrony.keys.example
|
%doc examples/chrony.keys.example
|
||||||
|
|
||||||
|
|||||||
16
local.c
16
local.c
@@ -42,13 +42,12 @@
|
|||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
/* Maximum allowed frequency offset in ppm, the time must not stop
|
|
||||||
or run backwards */
|
|
||||||
#define MAX_FREQ 500000.0
|
|
||||||
|
|
||||||
/* Variable to store the current frequency, in ppm */
|
/* Variable to store the current frequency, in ppm */
|
||||||
static double current_freq_ppm;
|
static double current_freq_ppm;
|
||||||
|
|
||||||
|
/* Maximum allowed frequency, in ppm */
|
||||||
|
static double max_freq_ppm;
|
||||||
|
|
||||||
/* Temperature compensation, in ppm */
|
/* Temperature compensation, in ppm */
|
||||||
static double temp_comp_ppm;
|
static double temp_comp_ppm;
|
||||||
|
|
||||||
@@ -166,6 +165,11 @@ LCL_Initialise(void)
|
|||||||
|
|
||||||
calculate_sys_precision();
|
calculate_sys_precision();
|
||||||
|
|
||||||
|
/* This is the maximum allowed frequency offset in ppm, the time must
|
||||||
|
never stop or run backwards */
|
||||||
|
max_freq_ppm = CNF_GetMaxDrift();
|
||||||
|
max_freq_ppm = CLAMP(0.0, max_freq_ppm, 500000.0);
|
||||||
|
|
||||||
max_clock_error = CNF_GetMaxClockError() * 1e-6;
|
max_clock_error = CNF_GetMaxClockError() * 1e-6;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -406,12 +410,12 @@ LCL_ReadAbsoluteFrequency(void)
|
|||||||
static double
|
static double
|
||||||
clamp_freq(double freq)
|
clamp_freq(double freq)
|
||||||
{
|
{
|
||||||
if (freq <= MAX_FREQ && freq >= -MAX_FREQ)
|
if (freq <= max_freq_ppm && freq >= -max_freq_ppm)
|
||||||
return freq;
|
return freq;
|
||||||
|
|
||||||
LOG(LOGS_WARN, LOGF_Local, "Frequency %.1f ppm exceeds allowed maximum", freq);
|
LOG(LOGS_WARN, LOGF_Local, "Frequency %.1f ppm exceeds allowed maximum", freq);
|
||||||
|
|
||||||
return freq >= MAX_FREQ ? MAX_FREQ : -MAX_FREQ;
|
return CLAMP(-max_freq_ppm, freq, max_freq_ppm);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|||||||
27
make_release
27
make_release
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
LANG=C
|
LANG=C.UTF-8
|
||||||
export LANG
|
export LANG
|
||||||
|
|
||||||
if [ $# -ne 1 ]; then
|
if [ $# -ne 1 ]; then
|
||||||
@@ -11,7 +11,6 @@ fi
|
|||||||
version=$1
|
version=$1
|
||||||
tag=$version
|
tag=$version
|
||||||
subdir=chrony-${version}
|
subdir=chrony-${version}
|
||||||
mandate=$(date +'%B %Y')
|
|
||||||
|
|
||||||
umask 022
|
umask 022
|
||||||
|
|
||||||
@@ -39,29 +38,13 @@ echo $version > version.txt
|
|||||||
|
|
||||||
sed -i -e "s%@@VERSION@@%${version}%" examples/chrony.spec
|
sed -i -e "s%@@VERSION@@%${version}%" examples/chrony.spec
|
||||||
|
|
||||||
for m in chronyc.1.in chrony.conf.5.in chronyd.8.in; do
|
./configure && make -C doc man txt || exit 1
|
||||||
sed -e "s%@VERSION@%${version}%;s%@MAN_DATE@%${mandate}%" \
|
|
||||||
< $m > ${m}_
|
|
||||||
mv -f ${m}_ $m
|
|
||||||
done
|
|
||||||
|
|
||||||
./configure && make chrony.txt getdate.c || exit 1
|
iconv -f utf-8 -t ascii//TRANSLIT < doc/installation.txt > INSTALL
|
||||||
|
iconv -f utf-8 -t ascii//TRANSLIT < doc/faq.txt > FAQ
|
||||||
awk '/^[1-9] Installation$/{p=1}
|
|
||||||
/^[1-9]\.. Support for line editing/{exit}; p' chrony.txt | \
|
|
||||||
tail -n +4 > INSTALL
|
|
||||||
|
|
||||||
if [ $(wc -l < INSTALL) -gt 100 -o $(wc -l < INSTALL) -lt 85 ]; then
|
|
||||||
echo "INSTALL generated incorrectly?"
|
|
||||||
exit 3
|
|
||||||
fi
|
|
||||||
|
|
||||||
a2x --lynx -f text doc/faq.adoc || exit 1
|
|
||||||
mv doc/faq.text FAQ
|
|
||||||
rm -rf doc
|
|
||||||
|
|
||||||
make distclean
|
make distclean
|
||||||
rm -f config.h config.log make_release .gitignore
|
rm -f make_release .gitignore
|
||||||
|
|
||||||
cd ..
|
cd ..
|
||||||
tar cv --owner root --group root $subdir | gzip -9 > ${subdir}.tar.gz
|
tar cv --owner root --group root $subdir | gzip -9 > ${subdir}.tar.gz
|
||||||
|
|||||||
6
ntp.h
6
ntp.h
@@ -53,8 +53,8 @@ typedef uint32_t NTP_int32;
|
|||||||
#define NTP_MAX_EXTENSIONS_LENGTH 1024
|
#define NTP_MAX_EXTENSIONS_LENGTH 1024
|
||||||
|
|
||||||
/* The minimum and maximum supported length of MAC */
|
/* The minimum and maximum supported length of MAC */
|
||||||
#define NTP_MIN_MAC_LENGTH 16
|
#define NTP_MIN_MAC_LENGTH (4 + 16)
|
||||||
#define NTP_MAX_MAC_LENGTH MAX_HASH_LENGTH
|
#define NTP_MAX_MAC_LENGTH (4 + MAX_HASH_LENGTH)
|
||||||
|
|
||||||
/* Type definition for leap bits */
|
/* Type definition for leap bits */
|
||||||
typedef enum {
|
typedef enum {
|
||||||
@@ -91,7 +91,7 @@ typedef struct {
|
|||||||
|
|
||||||
/* Optional message authentication code (MAC) */
|
/* Optional message authentication code (MAC) */
|
||||||
NTP_int32 auth_keyid;
|
NTP_int32 auth_keyid;
|
||||||
uint8_t auth_data[NTP_MAX_MAC_LENGTH];
|
uint8_t auth_data[NTP_MAX_MAC_LENGTH - 4];
|
||||||
} NTP_Packet;
|
} NTP_Packet;
|
||||||
|
|
||||||
#define NTP_NORMAL_PACKET_LENGTH (int)offsetof(NTP_Packet, auth_keyid)
|
#define NTP_NORMAL_PACKET_LENGTH (int)offsetof(NTP_Packet, auth_keyid)
|
||||||
|
|||||||
45
ntp_core.c
45
ntp_core.c
@@ -602,6 +602,7 @@ NCR_ChangeRemoteAddress(NCR_Instance inst, NTP_Remote_Address *remote_addr)
|
|||||||
close_client_socket(inst);
|
close_client_socket(inst);
|
||||||
else {
|
else {
|
||||||
NIO_CloseServerSocket(inst->local_addr.sock_fd);
|
NIO_CloseServerSocket(inst->local_addr.sock_fd);
|
||||||
|
inst->local_addr.ip_addr.family = IPADDR_UNSPEC;
|
||||||
inst->local_addr.sock_fd = NIO_OpenServerSocket(remote_addr);
|
inst->local_addr.sock_fd = NIO_OpenServerSocket(remote_addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -800,7 +801,7 @@ transmit_packet(NTP_Mode my_mode, /* The mode this machine wants to be */
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
NTP_Packet message;
|
NTP_Packet message;
|
||||||
int leap, auth_len, length, ret, precision;
|
int auth_len, length, ret, precision;
|
||||||
struct timeval local_receive, local_transmit;
|
struct timeval local_receive, local_transmit;
|
||||||
NTP_int64 ts_fuzz;
|
NTP_int64 ts_fuzz;
|
||||||
|
|
||||||
@@ -822,7 +823,7 @@ transmit_packet(NTP_Mode my_mode, /* The mode this machine wants to be */
|
|||||||
if (my_mode == MODE_CLIENT) {
|
if (my_mode == MODE_CLIENT) {
|
||||||
/* Don't reveal local time or state of the clock in client packets */
|
/* Don't reveal local time or state of the clock in client packets */
|
||||||
precision = 32;
|
precision = 32;
|
||||||
are_we_synchronised = leap_status = our_stratum = our_ref_id = 0;
|
leap_status = our_stratum = our_ref_id = 0;
|
||||||
our_ref_time.tv_sec = our_ref_time.tv_usec = 0;
|
our_ref_time.tv_sec = our_ref_time.tv_usec = 0;
|
||||||
our_root_delay = our_root_dispersion = 0.0;
|
our_root_delay = our_root_dispersion = 0.0;
|
||||||
} else {
|
} else {
|
||||||
@@ -858,14 +859,8 @@ transmit_packet(NTP_Mode my_mode, /* The mode this machine wants to be */
|
|||||||
local_receive = *local_rx;
|
local_receive = *local_rx;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (are_we_synchronised) {
|
|
||||||
leap = (int) leap_status;
|
|
||||||
} else {
|
|
||||||
leap = LEAP_Unsynchronised;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Generate transmit packet */
|
/* Generate transmit packet */
|
||||||
message.lvm = NTP_LVM(leap, version, my_mode);
|
message.lvm = NTP_LVM(leap_status, version, my_mode);
|
||||||
/* Stratum 16 and larger are invalid */
|
/* Stratum 16 and larger are invalid */
|
||||||
if (our_stratum < NTP_MAX_STRATUM) {
|
if (our_stratum < NTP_MAX_STRATUM) {
|
||||||
message.stratum = our_stratum;
|
message.stratum = our_stratum;
|
||||||
@@ -961,6 +956,7 @@ static void
|
|||||||
transmit_timeout(void *arg)
|
transmit_timeout(void *arg)
|
||||||
{
|
{
|
||||||
NCR_Instance inst = (NCR_Instance) arg;
|
NCR_Instance inst = (NCR_Instance) arg;
|
||||||
|
NTP_Local_Address local_addr;
|
||||||
int sent;
|
int sent;
|
||||||
|
|
||||||
inst->tx_timeout_id = 0;
|
inst->tx_timeout_id = 0;
|
||||||
@@ -996,6 +992,10 @@ transmit_timeout(void *arg)
|
|||||||
inst->local_addr.sock_fd = NIO_OpenClientSocket(&inst->remote_addr);
|
inst->local_addr.sock_fd = NIO_OpenClientSocket(&inst->remote_addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Don't require the packet to be sent from the same address as before */
|
||||||
|
local_addr.ip_addr.family = IPADDR_UNSPEC;
|
||||||
|
local_addr.sock_fd = inst->local_addr.sock_fd;
|
||||||
|
|
||||||
/* Check whether we need to 'warm up' the link to the other end by
|
/* Check whether we need to 'warm up' the link to the other end by
|
||||||
sending an NTP exchange to ensure both ends' ARP caches are
|
sending an NTP exchange to ensure both ends' ARP caches are
|
||||||
primed. On loaded systems this might also help ensure that bits
|
primed. On loaded systems this might also help ensure that bits
|
||||||
@@ -1009,7 +1009,7 @@ transmit_timeout(void *arg)
|
|||||||
as the reply will be ignored */
|
as the reply will be ignored */
|
||||||
transmit_packet(MODE_CLIENT, inst->local_poll, inst->version, 0, 0,
|
transmit_packet(MODE_CLIENT, inst->local_poll, inst->version, 0, 0,
|
||||||
&inst->remote_orig, &inst->local_rx, NULL, NULL,
|
&inst->remote_orig, &inst->local_rx, NULL, NULL,
|
||||||
&inst->remote_addr, &inst->local_addr);
|
&inst->remote_addr, &local_addr);
|
||||||
|
|
||||||
inst->presend_done = 1;
|
inst->presend_done = 1;
|
||||||
|
|
||||||
@@ -1027,7 +1027,7 @@ transmit_timeout(void *arg)
|
|||||||
&inst->remote_orig,
|
&inst->remote_orig,
|
||||||
&inst->local_rx, &inst->local_tx, &inst->local_ntp_tx,
|
&inst->local_rx, &inst->local_tx, &inst->local_ntp_tx,
|
||||||
&inst->remote_addr,
|
&inst->remote_addr,
|
||||||
&inst->local_addr);
|
&local_addr);
|
||||||
|
|
||||||
++inst->tx_count;
|
++inst->tx_count;
|
||||||
|
|
||||||
@@ -1184,7 +1184,6 @@ receive_packet(NTP_Packet *message, struct timeval *now, double now_err, NCR_Ins
|
|||||||
|
|
||||||
/* These are the timeval equivalents of the remote epochs */
|
/* These are the timeval equivalents of the remote epochs */
|
||||||
struct timeval remote_receive_tv, remote_transmit_tv;
|
struct timeval remote_receive_tv, remote_transmit_tv;
|
||||||
struct timeval remote_reference_tv;
|
|
||||||
struct timeval local_average, remote_average;
|
struct timeval local_average, remote_average;
|
||||||
double local_interval, remote_interval;
|
double local_interval, remote_interval;
|
||||||
|
|
||||||
@@ -1223,7 +1222,6 @@ receive_packet(NTP_Packet *message, struct timeval *now, double now_err, NCR_Ins
|
|||||||
|
|
||||||
UTI_Int64ToTimeval(&message->receive_ts, &remote_receive_tv);
|
UTI_Int64ToTimeval(&message->receive_ts, &remote_receive_tv);
|
||||||
UTI_Int64ToTimeval(&message->transmit_ts, &remote_transmit_tv);
|
UTI_Int64ToTimeval(&message->transmit_ts, &remote_transmit_tv);
|
||||||
UTI_Int64ToTimeval(&message->reference_ts, &remote_reference_tv);
|
|
||||||
|
|
||||||
/* Check if the packet is valid per RFC 5905, section 8.
|
/* Check if the packet is valid per RFC 5905, section 8.
|
||||||
The test values are 1 when passed and 0 when failed. */
|
The test values are 1 when passed and 0 when failed. */
|
||||||
@@ -1241,7 +1239,6 @@ receive_packet(NTP_Packet *message, struct timeval *now, double now_err, NCR_Ins
|
|||||||
association if not properly 'up'. */
|
association if not properly 'up'. */
|
||||||
test3 = (message->originate_ts.hi || message->originate_ts.lo) &&
|
test3 = (message->originate_ts.hi || message->originate_ts.lo) &&
|
||||||
(message->receive_ts.hi || message->receive_ts.lo) &&
|
(message->receive_ts.hi || message->receive_ts.lo) &&
|
||||||
(message->reference_ts.hi || message->reference_ts.lo) &&
|
|
||||||
(message->transmit_ts.hi || message->transmit_ts.lo);
|
(message->transmit_ts.hi || message->transmit_ts.lo);
|
||||||
|
|
||||||
/* Test 4 would check for denied access. It would always pass as this
|
/* Test 4 would check for denied access. It would always pass as this
|
||||||
@@ -1262,10 +1259,8 @@ receive_packet(NTP_Packet *message, struct timeval *now, double now_err, NCR_Ins
|
|||||||
message->stratum != NTP_INVALID_STRATUM;
|
message->stratum != NTP_INVALID_STRATUM;
|
||||||
|
|
||||||
/* Test 7 checks for bad data. The root distance must be smaller than a
|
/* Test 7 checks for bad data. The root distance must be smaller than a
|
||||||
defined maximum and the transmit time must not be before the time of
|
defined maximum. */
|
||||||
the last synchronisation update. */
|
test7 = pkt_root_delay / 2.0 + pkt_root_dispersion < NTP_MAX_DISPERSION;
|
||||||
test7 = pkt_root_delay / 2.0 + pkt_root_dispersion < NTP_MAX_DISPERSION &&
|
|
||||||
UTI_CompareTimevals(&remote_reference_tv, &remote_transmit_tv) < 1;
|
|
||||||
|
|
||||||
/* The packet is considered valid if the tests above passed */
|
/* The packet is considered valid if the tests above passed */
|
||||||
valid_packet = test1 && test2 && test3 && test5 && test6 && test7;
|
valid_packet = test1 && test2 && test3 && test5 && test6 && test7;
|
||||||
@@ -1353,7 +1348,8 @@ receive_packet(NTP_Packet *message, struct timeval *now, double now_err, NCR_Ins
|
|||||||
|
|
||||||
/* Test D requires that the remote peer is not synchronised to us to
|
/* Test D requires that the remote peer is not synchronised to us to
|
||||||
prevent a synchronisation loop */
|
prevent a synchronisation loop */
|
||||||
testD = message->stratum <= 1 || pkt_refid != UTI_IPToRefid(&local_addr->ip_addr);
|
testD = message->stratum <= 1 || REF_GetMode() != REF_ModeNormal ||
|
||||||
|
pkt_refid != UTI_IPToRefid(&local_addr->ip_addr);
|
||||||
} else {
|
} else {
|
||||||
offset = delay = dispersion = 0.0;
|
offset = delay = dispersion = 0.0;
|
||||||
sample_time = *now;
|
sample_time = *now;
|
||||||
@@ -1450,6 +1446,9 @@ receive_packet(NTP_Packet *message, struct timeval *now, double now_err, NCR_Ins
|
|||||||
server and the socket can be closed */
|
server and the socket can be closed */
|
||||||
close_client_socket(inst);
|
close_client_socket(inst);
|
||||||
|
|
||||||
|
/* Update the local address */
|
||||||
|
inst->local_addr.ip_addr = local_addr->ip_addr;
|
||||||
|
|
||||||
requeue_transmit = 1;
|
requeue_transmit = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2008,6 +2007,14 @@ NCR_GetRemoteAddress(NCR_Instance inst)
|
|||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
|
uint32_t
|
||||||
|
NCR_GetLocalRefid(NCR_Instance inst)
|
||||||
|
{
|
||||||
|
return UTI_IPToRefid(&inst->local_addr.ip_addr);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
int NCR_IsSyncPeer(NCR_Instance inst)
|
int NCR_IsSyncPeer(NCR_Instance inst)
|
||||||
{
|
{
|
||||||
return SRC_IsSyncPeer(inst->source);
|
return SRC_IsSyncPeer(inst->source);
|
||||||
|
|||||||
@@ -105,6 +105,8 @@ extern void NCR_IncrementActivityCounters(NCR_Instance inst, int *online, int *o
|
|||||||
|
|
||||||
extern NTP_Remote_Address *NCR_GetRemoteAddress(NCR_Instance instance);
|
extern NTP_Remote_Address *NCR_GetRemoteAddress(NCR_Instance instance);
|
||||||
|
|
||||||
|
extern uint32_t NCR_GetLocalRefid(NCR_Instance inst);
|
||||||
|
|
||||||
extern int NCR_IsSyncPeer(NCR_Instance instance);
|
extern int NCR_IsSyncPeer(NCR_Instance instance);
|
||||||
|
|
||||||
extern void NCR_AddBroadcastDestination(IPAddr *addr, unsigned short port, int interval);
|
extern void NCR_AddBroadcastDestination(IPAddr *addr, unsigned short port, int interval);
|
||||||
|
|||||||
18
ntp_io.c
18
ntp_io.c
@@ -162,21 +162,21 @@ prepare_socket(int family, int port_number, int client_only)
|
|||||||
/* Make the socket capable of re-using an old address if binding to a specific port */
|
/* Make the socket capable of re-using an old address if binding to a specific port */
|
||||||
if (port_number &&
|
if (port_number &&
|
||||||
setsockopt(sock_fd, SOL_SOCKET, SO_REUSEADDR, (char *)&on_off, sizeof(on_off)) < 0) {
|
setsockopt(sock_fd, SOL_SOCKET, SO_REUSEADDR, (char *)&on_off, sizeof(on_off)) < 0) {
|
||||||
LOG(LOGS_ERR, LOGF_NtpIO, "Could not set reuseaddr socket options");
|
LOG(LOGS_ERR, LOGF_NtpIO, "Could not set %s socket option", "SO_REUSEADDR");
|
||||||
/* Don't quit - we might survive anyway */
|
/* Don't quit - we might survive anyway */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Make the socket capable of sending broadcast pkts - needed for NTP broadcast mode */
|
/* Make the socket capable of sending broadcast pkts - needed for NTP broadcast mode */
|
||||||
if (!client_only &&
|
if (!client_only &&
|
||||||
setsockopt(sock_fd, SOL_SOCKET, SO_BROADCAST, (char *)&on_off, sizeof(on_off)) < 0) {
|
setsockopt(sock_fd, SOL_SOCKET, SO_BROADCAST, (char *)&on_off, sizeof(on_off)) < 0) {
|
||||||
LOG(LOGS_ERR, LOGF_NtpIO, "Could not set broadcast socket options");
|
LOG(LOGS_ERR, LOGF_NtpIO, "Could not set %s socket option", "SO_BROADCAST");
|
||||||
/* Don't quit - we might survive anyway */
|
/* Don't quit - we might survive anyway */
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SO_TIMESTAMP
|
#ifdef SO_TIMESTAMP
|
||||||
/* Enable receiving of timestamp control messages */
|
/* Enable receiving of timestamp control messages */
|
||||||
if (setsockopt(sock_fd, SOL_SOCKET, SO_TIMESTAMP, (char *)&on_off, sizeof(on_off)) < 0) {
|
if (setsockopt(sock_fd, SOL_SOCKET, SO_TIMESTAMP, (char *)&on_off, sizeof(on_off)) < 0) {
|
||||||
LOG(LOGS_ERR, LOGF_NtpIO, "Could not set timestamp socket options");
|
LOG(LOGS_ERR, LOGF_NtpIO, "Could not set %s socket option", "SO_TIMESTAMP");
|
||||||
/* Don't quit - we might survive anyway */
|
/* Don't quit - we might survive anyway */
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -185,7 +185,7 @@ prepare_socket(int family, int port_number, int client_only)
|
|||||||
/* Allow binding to address that doesn't exist yet */
|
/* Allow binding to address that doesn't exist yet */
|
||||||
if (my_addr_len > 0 &&
|
if (my_addr_len > 0 &&
|
||||||
setsockopt(sock_fd, IPPROTO_IP, IP_FREEBIND, (char *)&on_off, sizeof(on_off)) < 0) {
|
setsockopt(sock_fd, IPPROTO_IP, IP_FREEBIND, (char *)&on_off, sizeof(on_off)) < 0) {
|
||||||
LOG(LOGS_ERR, LOGF_NtpIO, "Could not set free bind socket option");
|
LOG(LOGS_ERR, LOGF_NtpIO, "Could not set %s socket option", "IP_FREEBIND");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -193,7 +193,7 @@ prepare_socket(int family, int port_number, int client_only)
|
|||||||
#ifdef HAVE_IN_PKTINFO
|
#ifdef HAVE_IN_PKTINFO
|
||||||
/* We want the local IP info on server sockets */
|
/* We want the local IP info on server sockets */
|
||||||
if (setsockopt(sock_fd, IPPROTO_IP, IP_PKTINFO, (char *)&on_off, sizeof(on_off)) < 0) {
|
if (setsockopt(sock_fd, IPPROTO_IP, IP_PKTINFO, (char *)&on_off, sizeof(on_off)) < 0) {
|
||||||
LOG(LOGS_ERR, LOGF_NtpIO, "Could not set packet info socket option");
|
LOG(LOGS_ERR, LOGF_NtpIO, "Could not set %s socket option", "IP_PKTINFO");
|
||||||
/* Don't quit - we might survive anyway */
|
/* Don't quit - we might survive anyway */
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -203,18 +203,18 @@ prepare_socket(int family, int port_number, int client_only)
|
|||||||
#ifdef IPV6_V6ONLY
|
#ifdef IPV6_V6ONLY
|
||||||
/* Receive IPv6 packets only */
|
/* Receive IPv6 packets only */
|
||||||
if (setsockopt(sock_fd, IPPROTO_IPV6, IPV6_V6ONLY, (char *)&on_off, sizeof(on_off)) < 0) {
|
if (setsockopt(sock_fd, IPPROTO_IPV6, IPV6_V6ONLY, (char *)&on_off, sizeof(on_off)) < 0) {
|
||||||
LOG(LOGS_ERR, LOGF_NtpIO, "Could not set IPV6_V6ONLY socket option");
|
LOG(LOGS_ERR, LOGF_NtpIO, "Could not set %s socket option", "IPV6_V6ONLY");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_IN6_PKTINFO
|
#ifdef HAVE_IN6_PKTINFO
|
||||||
#ifdef IPV6_RECVPKTINFO
|
#ifdef IPV6_RECVPKTINFO
|
||||||
if (setsockopt(sock_fd, IPPROTO_IPV6, IPV6_RECVPKTINFO, (char *)&on_off, sizeof(on_off)) < 0) {
|
if (setsockopt(sock_fd, IPPROTO_IPV6, IPV6_RECVPKTINFO, (char *)&on_off, sizeof(on_off)) < 0) {
|
||||||
LOG(LOGS_ERR, LOGF_NtpIO, "Could not set IPv6 packet info socket option");
|
LOG(LOGS_ERR, LOGF_NtpIO, "Could not set %s socket option", "IPV6_RECVPKTINFO");
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (setsockopt(sock_fd, IPPROTO_IPV6, IPV6_PKTINFO, (char *)&on_off, sizeof(on_off)) < 0) {
|
if (setsockopt(sock_fd, IPPROTO_IPV6, IPV6_PKTINFO, (char *)&on_off, sizeof(on_off)) < 0) {
|
||||||
LOG(LOGS_ERR, LOGF_NtpIO, "Could not set IPv6 packet info socket option");
|
LOG(LOGS_ERR, LOGF_NtpIO, "Could not set %s socket option", "IPV6_PKTINFO");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
@@ -556,7 +556,7 @@ read_from_socket(void *anything)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef SO_TIMESTAMP
|
#ifdef SO_TIMESTAMP
|
||||||
if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SO_TIMESTAMP) {
|
if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_TIMESTAMP) {
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
|
|
||||||
memcpy(&tv, CMSG_DATA(cmsg), sizeof(tv));
|
memcpy(&tv, CMSG_DATA(cmsg), sizeof(tv));
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
* Copyright (C) Richard P. Curnow 1997-2003
|
* Copyright (C) Richard P. Curnow 1997-2003
|
||||||
* Copyright (C) Miroslav Lichvar 2011-2012, 2014
|
* Copyright (C) Miroslav Lichvar 2011-2012, 2014, 2016
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of version 2 of the GNU General Public License as
|
* it under the terms of version 2 of the GNU General Public License as
|
||||||
@@ -53,8 +53,7 @@ typedef struct {
|
|||||||
int pool; /* Number of the pool from which was this source
|
int pool; /* Number of the pool from which was this source
|
||||||
added or INVALID_POOL */
|
added or INVALID_POOL */
|
||||||
int tentative; /* Flag indicating there was no valid response
|
int tentative; /* Flag indicating there was no valid response
|
||||||
yet and the source may be removed if other
|
received from the source yet */
|
||||||
sources from the pool respond first */
|
|
||||||
} SourceRecord;
|
} SourceRecord;
|
||||||
|
|
||||||
/* Hash table of SourceRecord, its size is a power of two and it's never
|
/* Hash table of SourceRecord, its size is a power of two and it's never
|
||||||
@@ -71,6 +70,7 @@ static int auto_start_sources = 0;
|
|||||||
struct UnresolvedSource {
|
struct UnresolvedSource {
|
||||||
char *name;
|
char *name;
|
||||||
int port;
|
int port;
|
||||||
|
int random_order;
|
||||||
int replacement;
|
int replacement;
|
||||||
union {
|
union {
|
||||||
struct {
|
struct {
|
||||||
@@ -311,7 +311,7 @@ add_source(NTP_Remote_Address *remote_addr, char *name, NTP_Source_Type type, So
|
|||||||
record->remote_addr = NCR_GetRemoteAddress(record->data);
|
record->remote_addr = NCR_GetRemoteAddress(record->data);
|
||||||
record->name = name ? Strdup(name) : NULL;
|
record->name = name ? Strdup(name) : NULL;
|
||||||
record->pool = pool;
|
record->pool = pool;
|
||||||
record->tentative = pool != INVALID_POOL ? 1 : 0;
|
record->tentative = 1;
|
||||||
|
|
||||||
if (auto_start_sources)
|
if (auto_start_sources)
|
||||||
NCR_StartInstance(record->data);
|
NCR_StartInstance(record->data);
|
||||||
@@ -328,6 +328,7 @@ replace_source(NTP_Remote_Address *old_addr, NTP_Remote_Address *new_addr)
|
|||||||
{
|
{
|
||||||
int slot1, slot2, found;
|
int slot1, slot2, found;
|
||||||
SourceRecord *record;
|
SourceRecord *record;
|
||||||
|
struct SourcePool *pool;
|
||||||
|
|
||||||
find_slot(old_addr, &slot1, &found);
|
find_slot(old_addr, &slot1, &found);
|
||||||
if (!found)
|
if (!found)
|
||||||
@@ -341,6 +342,15 @@ replace_source(NTP_Remote_Address *old_addr, NTP_Remote_Address *new_addr)
|
|||||||
NCR_ChangeRemoteAddress(record->data, new_addr);
|
NCR_ChangeRemoteAddress(record->data, new_addr);
|
||||||
record->remote_addr = NCR_GetRemoteAddress(record->data);
|
record->remote_addr = NCR_GetRemoteAddress(record->data);
|
||||||
|
|
||||||
|
if (!record->tentative) {
|
||||||
|
record->tentative = 1;
|
||||||
|
|
||||||
|
if (record->pool != INVALID_POOL) {
|
||||||
|
pool = ARR_GetElement(pools, record->pool);
|
||||||
|
pool->sources--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* The hash table must be rebuilt for the new address */
|
/* The hash table must be rebuilt for the new address */
|
||||||
rehash_records();
|
rehash_records();
|
||||||
|
|
||||||
@@ -358,13 +368,17 @@ process_resolved_name(struct UnresolvedSource *us, IPAddr *ip_addrs, int n_addrs
|
|||||||
{
|
{
|
||||||
NTP_Remote_Address address;
|
NTP_Remote_Address address;
|
||||||
int i, added;
|
int i, added;
|
||||||
|
unsigned short first = 0;
|
||||||
|
|
||||||
|
if (us->random_order)
|
||||||
|
UTI_GetRandomBytes(&first, sizeof (first));
|
||||||
|
|
||||||
for (i = added = 0; i < n_addrs; i++) {
|
for (i = added = 0; i < n_addrs; i++) {
|
||||||
DEBUG_LOG(LOGF_NtpSources, "(%d) %s", i + 1, UTI_IPToString(&ip_addrs[i]));
|
address.ip_addr = ip_addrs[((unsigned int)i + first) % n_addrs];
|
||||||
|
|
||||||
address.ip_addr = ip_addrs[i];
|
|
||||||
address.port = us->port;
|
address.port = us->port;
|
||||||
|
|
||||||
|
DEBUG_LOG(LOGF_NtpSources, "(%d) %s", i + 1, UTI_IPToString(&address.ip_addr));
|
||||||
|
|
||||||
if (us->replacement) {
|
if (us->replacement) {
|
||||||
if (replace_source(&us->replace_source, &address) != NSR_AlreadyInUse)
|
if (replace_source(&us->replace_source, &address) != NSR_AlreadyInUse)
|
||||||
break;
|
break;
|
||||||
@@ -507,6 +521,7 @@ NSR_AddSourceByName(char *name, int port, int pool, NTP_Source_Type type, Source
|
|||||||
us = MallocNew(struct UnresolvedSource);
|
us = MallocNew(struct UnresolvedSource);
|
||||||
us->name = Strdup(name);
|
us->name = Strdup(name);
|
||||||
us->port = port;
|
us->port = port;
|
||||||
|
us->random_order = 0;
|
||||||
us->replacement = 0;
|
us->replacement = 0;
|
||||||
us->new_source.type = type;
|
us->new_source.type = type;
|
||||||
us->new_source.params = *params;
|
us->new_source.params = *params;
|
||||||
@@ -648,6 +663,11 @@ resolve_source_replacement(SourceRecord *record)
|
|||||||
us = MallocNew(struct UnresolvedSource);
|
us = MallocNew(struct UnresolvedSource);
|
||||||
us->name = Strdup(record->name);
|
us->name = Strdup(record->name);
|
||||||
us->port = record->remote_addr->port;
|
us->port = record->remote_addr->port;
|
||||||
|
/* If there never was a valid reply from this source (e.g. it was a bad
|
||||||
|
replacement), ignore the order of addresses from the resolver to not get
|
||||||
|
stuck to a pair of addresses if the order doesn't change, or a group of
|
||||||
|
IPv4/IPv6 addresses if the resolver prefers inaccessible IP family */
|
||||||
|
us->random_order = record->tentative;
|
||||||
us->replacement = 1;
|
us->replacement = 1;
|
||||||
us->replace_source = *record->remote_addr;
|
us->replace_source = *record->remote_addr;
|
||||||
|
|
||||||
@@ -733,6 +753,26 @@ static void remove_tentative_pool_sources(int pool)
|
|||||||
rehash_records();
|
rehash_records();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
uint32_t
|
||||||
|
NSR_GetLocalRefid(IPAddr *address)
|
||||||
|
{
|
||||||
|
NTP_Remote_Address remote_addr;
|
||||||
|
int slot, found;
|
||||||
|
|
||||||
|
remote_addr.ip_addr = *address;
|
||||||
|
remote_addr.port = 0;
|
||||||
|
|
||||||
|
find_slot(&remote_addr, &slot, &found);
|
||||||
|
if (!found)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return NCR_GetLocalRefid(get_record(slot)->data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
/* This routine is called by ntp_io when a new packet arrives off the network,
|
/* This routine is called by ntp_io when a new packet arrives off the network,
|
||||||
possibly with an authentication tail */
|
possibly with an authentication tail */
|
||||||
void
|
void
|
||||||
@@ -752,20 +792,21 @@ NSR_ProcessReceive(NTP_Packet *message, struct timeval *now, double now_err, NTP
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (record->tentative) {
|
if (record->tentative) {
|
||||||
/* First reply from a pool source */
|
/* This was the first valid reply from the source */
|
||||||
record->tentative = 0;
|
record->tentative = 0;
|
||||||
|
|
||||||
assert(record->pool != INVALID_POOL);
|
if (record->pool != INVALID_POOL) {
|
||||||
pool = (struct SourcePool *)ARR_GetElement(pools, record->pool);
|
pool = ARR_GetElement(pools, record->pool);
|
||||||
pool->sources++;
|
pool->sources++;
|
||||||
|
|
||||||
DEBUG_LOG(LOGF_NtpSources, "pool %s has %d confirmed sources",
|
DEBUG_LOG(LOGF_NtpSources, "pool %s has %d confirmed sources",
|
||||||
record->name, pool->sources);
|
record->name, pool->sources);
|
||||||
|
|
||||||
/* If the number of sources reached the configured maximum, remove
|
/* If the number of sources from the pool reached the configured
|
||||||
the tentative sources added from this pool */
|
maximum, remove the remaining tentative sources */
|
||||||
if (pool->sources >= pool->max_sources)
|
if (pool->sources >= pool->max_sources)
|
||||||
remove_tentative_pool_sources(record->pool);
|
remove_tentative_pool_sources(record->pool);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
NCR_ProcessUnknown(message, now, now_err, remote_addr, local_addr, length);
|
NCR_ProcessUnknown(message, now, now_err, remote_addr, local_addr, length);
|
||||||
|
|||||||
@@ -83,6 +83,9 @@ extern void NSR_HandleBadSource(IPAddr *address);
|
|||||||
/* Procedure to resolve all names again */
|
/* Procedure to resolve all names again */
|
||||||
extern void NSR_RefreshAddresses(void);
|
extern void NSR_RefreshAddresses(void);
|
||||||
|
|
||||||
|
/* Procedure to get local reference ID corresponding to a source */
|
||||||
|
extern uint32_t NSR_GetLocalRefid(IPAddr *address);
|
||||||
|
|
||||||
/* This routine is called by ntp_io when a new packet arrives off the network */
|
/* This routine is called by ntp_io when a new packet arrives off the network */
|
||||||
extern void NSR_ProcessReceive(NTP_Packet *message, struct timeval *now, double now_err, NTP_Remote_Address *remote_addr, NTP_Local_Address *local_addr, int length);
|
extern void NSR_ProcessReceive(NTP_Packet *message, struct timeval *now, double now_err, NTP_Remote_Address *remote_addr, NTP_Local_Address *local_addr, int length);
|
||||||
|
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ static const struct request_length request_lengths[] = {
|
|||||||
REQ_LENGTH_ENTRY(modify_maxupdateskew, null), /* MODIFY_MAXUPDATESKEW */
|
REQ_LENGTH_ENTRY(modify_maxupdateskew, null), /* MODIFY_MAXUPDATESKEW */
|
||||||
REQ_LENGTH_ENTRY(logon, null), /* LOGON */
|
REQ_LENGTH_ENTRY(logon, null), /* LOGON */
|
||||||
REQ_LENGTH_ENTRY(settime, manual_timestamp), /* SETTIME */
|
REQ_LENGTH_ENTRY(settime, manual_timestamp), /* SETTIME */
|
||||||
REQ_LENGTH_ENTRY(local, null), /* LOCAL */
|
{ 0, 0 }, /* LOCAL */
|
||||||
REQ_LENGTH_ENTRY(manual, null), /* MANUAL */
|
REQ_LENGTH_ENTRY(manual, null), /* MANUAL */
|
||||||
REQ_LENGTH_ENTRY(null, n_sources), /* N_SOURCES */
|
REQ_LENGTH_ENTRY(null, n_sources), /* N_SOURCES */
|
||||||
REQ_LENGTH_ENTRY(source_data, source_data), /* SOURCE_DATA */
|
REQ_LENGTH_ENTRY(source_data, source_data), /* SOURCE_DATA */
|
||||||
@@ -112,6 +112,7 @@ static const struct request_length request_lengths[] = {
|
|||||||
REQ_LENGTH_ENTRY(null, server_stats), /* SERVER_STATS */
|
REQ_LENGTH_ENTRY(null, server_stats), /* SERVER_STATS */
|
||||||
REQ_LENGTH_ENTRY(client_accesses_by_index,
|
REQ_LENGTH_ENTRY(client_accesses_by_index,
|
||||||
client_accesses_by_index), /* CLIENT_ACCESSES_BY_INDEX2 */
|
client_accesses_by_index), /* CLIENT_ACCESSES_BY_INDEX2 */
|
||||||
|
REQ_LENGTH_ENTRY(local, null), /* LOCAL2 */
|
||||||
};
|
};
|
||||||
|
|
||||||
static const uint16_t reply_lengths[] = {
|
static const uint16_t reply_lengths[] = {
|
||||||
|
|||||||
57
refclock.c
57
refclock.c
@@ -87,12 +87,12 @@ struct RCL_Instance_Record {
|
|||||||
SRC_Instance source;
|
SRC_Instance source;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Array of RCL_Instance_Record */
|
/* Array of pointers to RCL_Instance_Record */
|
||||||
static ARR_Instance refclocks;
|
static ARR_Instance refclocks;
|
||||||
|
|
||||||
static LOG_FileID logfileid;
|
static LOG_FileID logfileid;
|
||||||
|
|
||||||
static int valid_sample_time(RCL_Instance instance, struct timeval *tv);
|
static int valid_sample_time(RCL_Instance instance, struct timeval *raw, struct timeval *cooked);
|
||||||
static int pps_stratum(RCL_Instance instance, struct timeval *tv);
|
static int pps_stratum(RCL_Instance instance, struct timeval *tv);
|
||||||
static void poll_timeout(void *arg);
|
static void poll_timeout(void *arg);
|
||||||
static void slew_samples(struct timeval *raw, struct timeval *cooked, double dfreq,
|
static void slew_samples(struct timeval *raw, struct timeval *cooked, double dfreq,
|
||||||
@@ -106,6 +106,7 @@ static void filter_reset(struct MedianFilter *filter);
|
|||||||
static double filter_get_avg_sample_dispersion(struct MedianFilter *filter);
|
static double filter_get_avg_sample_dispersion(struct MedianFilter *filter);
|
||||||
static void filter_add_sample(struct MedianFilter *filter, struct timeval *sample_time, double offset, double dispersion);
|
static void filter_add_sample(struct MedianFilter *filter, struct timeval *sample_time, double offset, double dispersion);
|
||||||
static int filter_get_last_sample(struct MedianFilter *filter, struct timeval *sample_time, double *offset, double *dispersion);
|
static int filter_get_last_sample(struct MedianFilter *filter, struct timeval *sample_time, double *offset, double *dispersion);
|
||||||
|
static int filter_get_samples(struct MedianFilter *filter);
|
||||||
static int filter_select_samples(struct MedianFilter *filter);
|
static int filter_select_samples(struct MedianFilter *filter);
|
||||||
static int filter_get_sample(struct MedianFilter *filter, struct timeval *sample_time, double *offset, double *dispersion);
|
static int filter_get_sample(struct MedianFilter *filter, struct timeval *sample_time, double *offset, double *dispersion);
|
||||||
static void filter_slew_samples(struct MedianFilter *filter, struct timeval *when, double dfreq, double doffset);
|
static void filter_slew_samples(struct MedianFilter *filter, struct timeval *when, double dfreq, double doffset);
|
||||||
@@ -114,13 +115,13 @@ static void filter_add_dispersion(struct MedianFilter *filter, double dispersion
|
|||||||
static RCL_Instance
|
static RCL_Instance
|
||||||
get_refclock(unsigned int index)
|
get_refclock(unsigned int index)
|
||||||
{
|
{
|
||||||
return (RCL_Instance)ARR_GetElement(refclocks, index);
|
return *(RCL_Instance *)ARR_GetElement(refclocks, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
RCL_Initialise(void)
|
RCL_Initialise(void)
|
||||||
{
|
{
|
||||||
refclocks = ARR_CreateInstance(sizeof (struct RCL_Instance_Record));
|
refclocks = ARR_CreateInstance(sizeof (RCL_Instance));
|
||||||
|
|
||||||
CNF_AddRefclocks();
|
CNF_AddRefclocks();
|
||||||
|
|
||||||
@@ -148,6 +149,7 @@ RCL_Finalise(void)
|
|||||||
filter_fini(&inst->filter);
|
filter_fini(&inst->filter);
|
||||||
Free(inst->driver_parameter);
|
Free(inst->driver_parameter);
|
||||||
SRC_DestroyInstance(inst->source);
|
SRC_DestroyInstance(inst->source);
|
||||||
|
Free(inst);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ARR_GetSize(refclocks) > 0) {
|
if (ARR_GetSize(refclocks) > 0) {
|
||||||
@@ -162,8 +164,10 @@ int
|
|||||||
RCL_AddRefclock(RefclockParameters *params)
|
RCL_AddRefclock(RefclockParameters *params)
|
||||||
{
|
{
|
||||||
int pps_source = 0;
|
int pps_source = 0;
|
||||||
|
RCL_Instance inst;
|
||||||
|
|
||||||
RCL_Instance inst = ARR_GetNewElement(refclocks);
|
inst = MallocNew(struct RCL_Instance_Record);
|
||||||
|
*(RCL_Instance *)ARR_GetNewElement(refclocks) = inst;
|
||||||
|
|
||||||
if (strcmp(params->driver_name, "SHM") == 0) {
|
if (strcmp(params->driver_name, "SHM") == 0) {
|
||||||
inst->driver = &RCL_SHM_driver;
|
inst->driver = &RCL_SHM_driver;
|
||||||
@@ -369,7 +373,7 @@ RCL_AddSample(RCL_Instance instance, struct timeval *sample_time, double offset,
|
|||||||
|
|
||||||
/* Make sure the timestamp and offset provided by the driver are sane */
|
/* Make sure the timestamp and offset provided by the driver are sane */
|
||||||
if (!UTI_IsTimeOffsetSane(sample_time, offset) ||
|
if (!UTI_IsTimeOffsetSane(sample_time, offset) ||
|
||||||
!valid_sample_time(instance, sample_time))
|
!valid_sample_time(instance, sample_time, &cooked_time))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
switch (leap) {
|
switch (leap) {
|
||||||
@@ -409,7 +413,7 @@ RCL_AddPulse(RCL_Instance instance, struct timeval *pulse_time, double second)
|
|||||||
dispersion += instance->precision;
|
dispersion += instance->precision;
|
||||||
|
|
||||||
if (!UTI_IsTimeOffsetSane(pulse_time, 0.0) ||
|
if (!UTI_IsTimeOffsetSane(pulse_time, 0.0) ||
|
||||||
!valid_sample_time(instance, pulse_time))
|
!valid_sample_time(instance, pulse_time, &cooked_time))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
rate = instance->pps_rate;
|
rate = instance->pps_rate;
|
||||||
@@ -470,15 +474,16 @@ RCL_AddPulse(RCL_Instance instance, struct timeval *pulse_time, double second)
|
|||||||
double root_delay, root_dispersion, distance;
|
double root_delay, root_dispersion, distance;
|
||||||
uint32_t ref_id;
|
uint32_t ref_id;
|
||||||
|
|
||||||
/* Ignore the pulse if we are not well synchronized */
|
/* Ignore the pulse if we are not well synchronized and the local
|
||||||
|
reference is not active */
|
||||||
|
|
||||||
REF_GetReferenceParams(&cooked_time, &is_synchronised, &leap, &stratum,
|
REF_GetReferenceParams(&cooked_time, &is_synchronised, &leap, &stratum,
|
||||||
&ref_id, &ref_time, &root_delay, &root_dispersion);
|
&ref_id, &ref_time, &root_delay, &root_dispersion);
|
||||||
distance = fabs(root_delay) / 2 + root_dispersion;
|
distance = fabs(root_delay) / 2 + root_dispersion;
|
||||||
|
|
||||||
if (!is_synchronised || distance >= 0.5 / rate) {
|
if (leap == LEAP_Unsynchronised || distance >= 0.5 / rate) {
|
||||||
DEBUG_LOG(LOGF_Refclock, "refclock pulse ignored second=%.9f sync=%d dist=%.9f",
|
DEBUG_LOG(LOGF_Refclock, "refclock pulse ignored second=%.9f sync=%d dist=%.9f",
|
||||||
second, is_synchronised, distance);
|
second, leap != LEAP_Unsynchronised, distance);
|
||||||
/* Drop also all stored samples */
|
/* Drop also all stored samples */
|
||||||
filter_reset(&instance->filter);
|
filter_reset(&instance->filter);
|
||||||
return 0;
|
return 0;
|
||||||
@@ -499,18 +504,25 @@ RCL_AddPulse(RCL_Instance instance, struct timeval *pulse_time, double second)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
valid_sample_time(RCL_Instance instance, struct timeval *tv)
|
valid_sample_time(RCL_Instance instance, struct timeval *raw, struct timeval *cooked)
|
||||||
{
|
{
|
||||||
struct timeval raw_time;
|
struct timeval raw_time, last_sample_time;
|
||||||
double diff;
|
double diff, last_offset, last_dispersion;
|
||||||
|
|
||||||
LCL_ReadRawTime(&raw_time);
|
LCL_ReadRawTime(&raw_time);
|
||||||
UTI_DiffTimevalsToDouble(&diff, &raw_time, tv);
|
UTI_DiffTimevalsToDouble(&diff, &raw_time, raw);
|
||||||
if (diff < 0.0 || diff > UTI_Log2ToDouble(instance->poll + 1)) {
|
|
||||||
DEBUG_LOG(LOGF_Refclock, "%s refclock sample not valid age=%.6f tv=%s",
|
if (diff < 0.0 || diff > UTI_Log2ToDouble(instance->poll + 1) ||
|
||||||
UTI_RefidToString(instance->ref_id), diff, UTI_TimevalToString(tv));
|
(filter_get_samples(&instance->filter) > 0 &&
|
||||||
|
filter_get_last_sample(&instance->filter, &last_sample_time,
|
||||||
|
&last_offset, &last_dispersion) &&
|
||||||
|
UTI_CompareTimevals(&last_sample_time, cooked) >= 0)) {
|
||||||
|
DEBUG_LOG(LOGF_Refclock, "%s refclock sample not valid age=%.6f raw=%s cooked=%s",
|
||||||
|
UTI_RefidToString(instance->ref_id), diff,
|
||||||
|
UTI_TimevalToString(raw), UTI_TimevalToString(cooked));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -528,9 +540,10 @@ pps_stratum(RCL_Instance instance, struct timeval *tv)
|
|||||||
REF_GetReferenceParams(tv, &is_synchronised, &leap, &stratum,
|
REF_GetReferenceParams(tv, &is_synchronised, &leap, &stratum,
|
||||||
&ref_id, &ref_time, &root_delay, &root_dispersion);
|
&ref_id, &ref_time, &root_delay, &root_dispersion);
|
||||||
|
|
||||||
/* Don't change our stratum if local stratum is active
|
/* Don't change our stratum if the local reference is active
|
||||||
or this is the current source */
|
or this is the current source */
|
||||||
if (ref_id == instance->ref_id || REF_IsLocalActive())
|
if (ref_id == instance->ref_id ||
|
||||||
|
(!is_synchronised && leap != LEAP_Unsynchronised))
|
||||||
return stratum - 1;
|
return stratum - 1;
|
||||||
|
|
||||||
/* Or the current source is another PPS refclock */
|
/* Or the current source is another PPS refclock */
|
||||||
@@ -714,6 +727,12 @@ filter_get_last_sample(struct MedianFilter *filter, struct timeval *sample_time,
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
filter_get_samples(struct MedianFilter *filter)
|
||||||
|
{
|
||||||
|
return filter->used;
|
||||||
|
}
|
||||||
|
|
||||||
static const struct FilterSample *tmp_sorted_array;
|
static const struct FilterSample *tmp_sorted_array;
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|||||||
106
reference.c
106
reference.c
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
* Copyright (C) Richard P. Curnow 1997-2003
|
* Copyright (C) Richard P. Curnow 1997-2003
|
||||||
* Copyright (C) Miroslav Lichvar 2009-2015
|
* Copyright (C) Miroslav Lichvar 2009-2016
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of version 2 of the GNU General Public License as
|
* it under the terms of version 2 of the GNU General Public License as
|
||||||
@@ -45,6 +45,8 @@
|
|||||||
static int are_we_synchronised;
|
static int are_we_synchronised;
|
||||||
static int enable_local_stratum;
|
static int enable_local_stratum;
|
||||||
static int local_stratum;
|
static int local_stratum;
|
||||||
|
static int local_orphan;
|
||||||
|
static double local_distance;
|
||||||
static NTP_Leap our_leap_status;
|
static NTP_Leap our_leap_status;
|
||||||
static int our_leap_sec;
|
static int our_leap_sec;
|
||||||
static int our_stratum;
|
static int our_stratum;
|
||||||
@@ -230,7 +232,7 @@ REF_Initialise(void)
|
|||||||
|
|
||||||
correction_time_ratio = CNF_GetCorrectionTimeRatio();
|
correction_time_ratio = CNF_GetCorrectionTimeRatio();
|
||||||
|
|
||||||
enable_local_stratum = CNF_AllowLocalReference(&local_stratum);
|
enable_local_stratum = CNF_AllowLocalReference(&local_stratum, &local_orphan, &local_distance);
|
||||||
|
|
||||||
leap_timeout_id = 0;
|
leap_timeout_id = 0;
|
||||||
leap_in_progress = 0;
|
leap_in_progress = 0;
|
||||||
@@ -1157,29 +1159,37 @@ REF_GetReferenceParams
|
|||||||
double *root_dispersion
|
double *root_dispersion
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
double elapsed;
|
double elapsed, dispersion;
|
||||||
double extra_dispersion;
|
|
||||||
|
|
||||||
assert(initialised);
|
assert(initialised);
|
||||||
|
|
||||||
if (are_we_synchronised) {
|
if (are_we_synchronised) {
|
||||||
|
UTI_DiffTimevalsToDouble(&elapsed, local_time, &our_ref_time);
|
||||||
|
dispersion = our_root_dispersion +
|
||||||
|
(our_skew + fabs(our_residual_freq) + LCL_GetMaxClockError()) * elapsed;
|
||||||
|
} else {
|
||||||
|
dispersion = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Local reference is active when enabled and the clock is not synchronised
|
||||||
|
or the root distance exceeds the threshold */
|
||||||
|
|
||||||
|
if (are_we_synchronised &&
|
||||||
|
!(enable_local_stratum && our_root_delay / 2 + dispersion > local_distance)) {
|
||||||
|
|
||||||
*is_synchronised = 1;
|
*is_synchronised = 1;
|
||||||
|
|
||||||
*stratum = our_stratum;
|
*stratum = our_stratum;
|
||||||
|
|
||||||
UTI_DiffTimevalsToDouble(&elapsed, local_time, &our_ref_time);
|
|
||||||
extra_dispersion = (our_skew + fabs(our_residual_freq) + LCL_GetMaxClockError()) * elapsed;
|
|
||||||
|
|
||||||
*leap_status = !leap_in_progress ? our_leap_status : LEAP_Unsynchronised;
|
*leap_status = !leap_in_progress ? our_leap_status : LEAP_Unsynchronised;
|
||||||
*ref_id = our_ref_id;
|
*ref_id = our_ref_id;
|
||||||
*ref_time = our_ref_time;
|
*ref_time = our_ref_time;
|
||||||
*root_delay = our_root_delay;
|
*root_delay = our_root_delay;
|
||||||
*root_dispersion = our_root_dispersion + extra_dispersion;
|
*root_dispersion = dispersion;
|
||||||
|
|
||||||
} else if (enable_local_stratum) {
|
} else if (enable_local_stratum) {
|
||||||
|
|
||||||
*is_synchronised = 1;
|
*is_synchronised = 0;
|
||||||
|
|
||||||
*stratum = local_stratum;
|
*stratum = local_stratum;
|
||||||
*ref_id = NTP_REFID_LOCAL;
|
*ref_id = NTP_REFID_LOCAL;
|
||||||
@@ -1220,13 +1230,27 @@ REF_GetReferenceParams
|
|||||||
int
|
int
|
||||||
REF_GetOurStratum(void)
|
REF_GetOurStratum(void)
|
||||||
{
|
{
|
||||||
if (are_we_synchronised) {
|
struct timeval now_cooked, ref_time;
|
||||||
return our_stratum;
|
int synchronised, stratum;
|
||||||
} else if (enable_local_stratum) {
|
NTP_Leap leap_status;
|
||||||
return local_stratum;
|
uint32_t ref_id;
|
||||||
} else {
|
double root_delay, root_dispersion;
|
||||||
|
|
||||||
|
SCH_GetLastEventTime(&now_cooked, NULL, NULL);
|
||||||
|
REF_GetReferenceParams(&now_cooked, &synchronised, &leap_status, &stratum,
|
||||||
|
&ref_id, &ref_time, &root_delay, &root_dispersion);
|
||||||
|
|
||||||
|
return stratum;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
REF_GetOrphanStratum(void)
|
||||||
|
{
|
||||||
|
if (!enable_local_stratum || !local_orphan || mode != REF_ModeNormal)
|
||||||
return NTP_MAX_STRATUM;
|
return NTP_MAX_STRATUM;
|
||||||
}
|
return local_stratum;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -1257,10 +1281,12 @@ REF_ModifyMakestep(int limit, double threshold)
|
|||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
void
|
void
|
||||||
REF_EnableLocal(int stratum)
|
REF_EnableLocal(int stratum, double distance, int orphan)
|
||||||
{
|
{
|
||||||
enable_local_stratum = 1;
|
enable_local_stratum = 1;
|
||||||
local_stratum = stratum;
|
local_stratum = CLAMP(1, stratum, NTP_MAX_STRATUM - 1);
|
||||||
|
local_distance = distance;
|
||||||
|
local_orphan = !!orphan;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -1273,14 +1299,6 @@ REF_DisableLocal(void)
|
|||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
int
|
|
||||||
REF_IsLocalActive(void)
|
|
||||||
{
|
|
||||||
return !are_we_synchronised && enable_local_stratum;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ================================================== */
|
|
||||||
|
|
||||||
#define LEAP_SECOND_CLOSE 5
|
#define LEAP_SECOND_CLOSE 5
|
||||||
|
|
||||||
int REF_IsLeapSecondClose(void)
|
int REF_IsLeapSecondClose(void)
|
||||||
@@ -1309,52 +1327,34 @@ int REF_IsLeapSecondClose(void)
|
|||||||
void
|
void
|
||||||
REF_GetTrackingReport(RPT_TrackingReport *rep)
|
REF_GetTrackingReport(RPT_TrackingReport *rep)
|
||||||
{
|
{
|
||||||
double elapsed;
|
|
||||||
double extra_dispersion;
|
|
||||||
struct timeval now_raw, now_cooked;
|
struct timeval now_raw, now_cooked;
|
||||||
double correction;
|
double correction;
|
||||||
|
int synchronised;
|
||||||
|
|
||||||
LCL_ReadRawTime(&now_raw);
|
LCL_ReadRawTime(&now_raw);
|
||||||
LCL_GetOffsetCorrection(&now_raw, &correction, NULL);
|
LCL_GetOffsetCorrection(&now_raw, &correction, NULL);
|
||||||
UTI_AddDoubleToTimeval(&now_raw, correction, &now_cooked);
|
UTI_AddDoubleToTimeval(&now_raw, correction, &now_cooked);
|
||||||
|
|
||||||
rep->ref_id = NTP_REFID_UNSYNC;
|
REF_GetReferenceParams(&now_cooked, &synchronised,
|
||||||
|
&rep->leap_status, &rep->stratum,
|
||||||
|
&rep->ref_id, &rep->ref_time,
|
||||||
|
&rep->root_delay, &rep->root_dispersion);
|
||||||
|
|
||||||
|
if (rep->stratum == NTP_MAX_STRATUM)
|
||||||
|
rep->stratum = 0;
|
||||||
|
|
||||||
rep->ip_addr.family = IPADDR_UNSPEC;
|
rep->ip_addr.family = IPADDR_UNSPEC;
|
||||||
rep->stratum = 0;
|
|
||||||
rep->leap_status = our_leap_status;
|
|
||||||
rep->ref_time.tv_sec = 0;
|
|
||||||
rep->ref_time.tv_usec = 0;
|
|
||||||
rep->current_correction = correction;
|
rep->current_correction = correction;
|
||||||
rep->freq_ppm = LCL_ReadAbsoluteFrequency();
|
rep->freq_ppm = LCL_ReadAbsoluteFrequency();
|
||||||
rep->resid_freq_ppm = 0.0;
|
rep->resid_freq_ppm = 0.0;
|
||||||
rep->skew_ppm = 0.0;
|
rep->skew_ppm = 0.0;
|
||||||
rep->root_delay = 0.0;
|
|
||||||
rep->root_dispersion = 0.0;
|
|
||||||
rep->last_update_interval = last_ref_update_interval;
|
rep->last_update_interval = last_ref_update_interval;
|
||||||
rep->last_offset = last_offset;
|
rep->last_offset = last_offset;
|
||||||
rep->rms_offset = sqrt(avg2_offset);
|
rep->rms_offset = sqrt(avg2_offset);
|
||||||
|
|
||||||
if (are_we_synchronised) {
|
if (synchronised) {
|
||||||
|
|
||||||
UTI_DiffTimevalsToDouble(&elapsed, &now_cooked, &our_ref_time);
|
|
||||||
extra_dispersion = (our_skew + fabs(our_residual_freq) + LCL_GetMaxClockError()) * elapsed;
|
|
||||||
|
|
||||||
rep->ref_id = our_ref_id;
|
|
||||||
rep->ip_addr = our_ref_ip;
|
rep->ip_addr = our_ref_ip;
|
||||||
rep->stratum = our_stratum;
|
|
||||||
rep->ref_time = our_ref_time;
|
|
||||||
rep->resid_freq_ppm = 1.0e6 * our_residual_freq;
|
rep->resid_freq_ppm = 1.0e6 * our_residual_freq;
|
||||||
rep->skew_ppm = 1.0e6 * our_skew;
|
rep->skew_ppm = 1.0e6 * our_skew;
|
||||||
rep->root_delay = our_root_delay;
|
|
||||||
rep->root_dispersion = our_root_dispersion + extra_dispersion;
|
|
||||||
|
|
||||||
} else if (enable_local_stratum) {
|
|
||||||
|
|
||||||
rep->ref_id = NTP_REFID_LOCAL;
|
|
||||||
rep->ip_addr.family = IPADDR_UNSPEC;
|
|
||||||
rep->stratum = local_stratum;
|
|
||||||
rep->ref_time = now_cooked;
|
|
||||||
rep->root_dispersion = LCL_GetSysPrecisionAsQuantum();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -165,6 +165,9 @@ REF_SetUnsynchronised(void);
|
|||||||
synchronised */
|
synchronised */
|
||||||
extern int REF_GetOurStratum(void);
|
extern int REF_GetOurStratum(void);
|
||||||
|
|
||||||
|
/* Return stratum of the local reference if orphan mode is enabled */
|
||||||
|
extern int REF_GetOrphanStratum(void);
|
||||||
|
|
||||||
/* Return the current skew */
|
/* Return the current skew */
|
||||||
extern double REF_GetSkew(void);
|
extern double REF_GetSkew(void);
|
||||||
|
|
||||||
@@ -174,9 +177,8 @@ extern void REF_ModifyMaxupdateskew(double new_max_update_skew);
|
|||||||
/* Modify makestep settings */
|
/* Modify makestep settings */
|
||||||
extern void REF_ModifyMakestep(int limit, double threshold);
|
extern void REF_ModifyMakestep(int limit, double threshold);
|
||||||
|
|
||||||
extern void REF_EnableLocal(int stratum);
|
extern void REF_EnableLocal(int stratum, double distance, int orphan);
|
||||||
extern void REF_DisableLocal(void);
|
extern void REF_DisableLocal(void);
|
||||||
extern int REF_IsLocalActive(void);
|
|
||||||
|
|
||||||
/* Check if current raw or cooked time is close to a leap second
|
/* Check if current raw or cooked time is close to a leap second
|
||||||
and is better to discard any measurements */
|
and is better to discard any measurements */
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
|
|
||||||
#include "sysincl.h"
|
#include "sysincl.h"
|
||||||
#include "addressing.h"
|
#include "addressing.h"
|
||||||
|
#include "ntp.h"
|
||||||
|
|
||||||
#define REPORT_INVALID_OFFSET 0x80000000
|
#define REPORT_INVALID_OFFSET 0x80000000
|
||||||
|
|
||||||
@@ -50,8 +51,8 @@ typedef struct {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t ref_id;
|
uint32_t ref_id;
|
||||||
IPAddr ip_addr;
|
IPAddr ip_addr;
|
||||||
unsigned long stratum;
|
int stratum;
|
||||||
unsigned long leap_status;
|
NTP_Leap leap_status;
|
||||||
struct timeval ref_time;
|
struct timeval ref_time;
|
||||||
double current_correction;
|
double current_correction;
|
||||||
double last_offset;
|
double last_offset;
|
||||||
|
|||||||
7
sched.c
7
sched.c
@@ -179,7 +179,8 @@ SCH_AddInputFileHandler
|
|||||||
/* Don't want to allow the same fd to register a handler more than
|
/* Don't want to allow the same fd to register a handler more than
|
||||||
once without deleting a previous association - this suggests
|
once without deleting a previous association - this suggests
|
||||||
a bug somewhere else in the program. */
|
a bug somewhere else in the program. */
|
||||||
assert(!FD_ISSET(fd, &read_fds));
|
if (FD_ISSET(fd, &read_fds))
|
||||||
|
assert(0);
|
||||||
|
|
||||||
++n_read_fds;
|
++n_read_fds;
|
||||||
|
|
||||||
@@ -208,7 +209,8 @@ SCH_RemoveInputFileHandler(int fd)
|
|||||||
assert(initialised);
|
assert(initialised);
|
||||||
|
|
||||||
/* Check that a handler was registered for the fd in question */
|
/* Check that a handler was registered for the fd in question */
|
||||||
assert(FD_ISSET(fd, &read_fds));
|
if (!FD_ISSET(fd, &read_fds))
|
||||||
|
assert(0);
|
||||||
|
|
||||||
--n_read_fds;
|
--n_read_fds;
|
||||||
|
|
||||||
@@ -717,7 +719,6 @@ SCH_MainLoop(void)
|
|||||||
void
|
void
|
||||||
SCH_QuitProgram(void)
|
SCH_QuitProgram(void)
|
||||||
{
|
{
|
||||||
assert(initialised);
|
|
||||||
need_to_exit = 1;
|
need_to_exit = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
43
smooth.c
43
smooth.c
@@ -137,7 +137,7 @@ get_smoothing(struct timeval *now, double *poffset, double *pfreq,
|
|||||||
static void
|
static void
|
||||||
update_stages(void)
|
update_stages(void)
|
||||||
{
|
{
|
||||||
double s1, s2, s, l1, l2, l3, lc, f, f2;
|
double s1, s2, s, l1, l2, l3, lc, f, f2, l1t[2], l3t[2], err[2];
|
||||||
int i, dir;
|
int i, dir;
|
||||||
|
|
||||||
/* Prepare the three stages so that the integral of the frequency offset
|
/* Prepare the three stages so that the integral of the frequency offset
|
||||||
@@ -146,22 +146,41 @@ update_stages(void)
|
|||||||
s1 = smooth_offset / max_wander;
|
s1 = smooth_offset / max_wander;
|
||||||
s2 = smooth_freq * smooth_freq / (2.0 * max_wander * max_wander);
|
s2 = smooth_freq * smooth_freq / (2.0 * max_wander * max_wander);
|
||||||
|
|
||||||
l1 = l2 = l3 = 0.0;
|
|
||||||
|
|
||||||
/* Calculate the lengths of the 1st and 3rd stage assuming there is no
|
/* Calculate the lengths of the 1st and 3rd stage assuming there is no
|
||||||
frequency limit. If length of the 1st stage comes out negative, switch
|
frequency limit. The direction of the 1st stage is selected so that
|
||||||
its direction. */
|
the lengths will not be negative. With extremely small offsets both
|
||||||
for (dir = -1; dir <= 1; dir += 2) {
|
directions may give a negative length due to numerical errors, so select
|
||||||
|
the one which gives a smaller error. */
|
||||||
|
|
||||||
|
for (i = 0, dir = -1; i <= 1; i++, dir += 2) {
|
||||||
|
err[i] = 0.0;
|
||||||
s = dir * s1 + s2;
|
s = dir * s1 + s2;
|
||||||
if (s >= 0.0) {
|
|
||||||
l3 = sqrt(s);
|
if (s < 0.0) {
|
||||||
l1 = l3 - dir * smooth_freq / max_wander;
|
err[i] += -s;
|
||||||
if (l1 >= 0.0)
|
s = 0.0;
|
||||||
break;
|
}
|
||||||
|
|
||||||
|
l3t[i] = sqrt(s);
|
||||||
|
l1t[i] = l3t[i] - dir * smooth_freq / max_wander;
|
||||||
|
|
||||||
|
if (l1t[i] < 0.0) {
|
||||||
|
err[i] += l1t[i] * l1t[i];
|
||||||
|
l1t[i] = 0.0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(dir <= 1 && l1 >= 0.0 && l3 >= 0.0);
|
if (err[0] < err[1]) {
|
||||||
|
l1 = l1t[0];
|
||||||
|
l3 = l3t[0];
|
||||||
|
dir = -1;
|
||||||
|
} else {
|
||||||
|
l1 = l1t[1];
|
||||||
|
l3 = l3t[1];
|
||||||
|
dir = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
l2 = 0.0;
|
||||||
|
|
||||||
/* If the limit was reached, shorten 1st+3rd stages and set a 2nd stage */
|
/* If the limit was reached, shorten 1st+3rd stages and set a 2nd stage */
|
||||||
f = dir * smooth_freq + l1 * max_wander - max_freq;
|
f = dir * smooth_freq + l1 * max_wander - max_freq;
|
||||||
|
|||||||
68
sources.c
68
sources.c
@@ -73,6 +73,8 @@ typedef enum {
|
|||||||
SRC_BAD_DISTANCE, /* Has root distance longer than allowed maximum */
|
SRC_BAD_DISTANCE, /* Has root distance longer than allowed maximum */
|
||||||
SRC_WAITS_STATS, /* Others have bad stats, selection postponed */
|
SRC_WAITS_STATS, /* Others have bad stats, selection postponed */
|
||||||
SRC_STALE, /* Has older samples than others */
|
SRC_STALE, /* Has older samples than others */
|
||||||
|
SRC_ORPHAN, /* Has stratum equal or larger than orphan stratum */
|
||||||
|
SRC_UNTRUSTED, /* Overlaps trusted sources */
|
||||||
SRC_FALSETICKER, /* Doesn't agree with others */
|
SRC_FALSETICKER, /* Doesn't agree with others */
|
||||||
SRC_JITTERY, /* Scatter worse than other's dispersion (not used) */
|
SRC_JITTERY, /* Scatter worse than other's dispersion (not used) */
|
||||||
SRC_WAITS_SOURCES, /* Not enough sources, selection postponed */
|
SRC_WAITS_SOURCES, /* Not enough sources, selection postponed */
|
||||||
@@ -429,9 +431,11 @@ SRC_UpdateReachability(SRC_Instance inst, int reachable)
|
|||||||
REF_SetUnsynchronised();
|
REF_SetUnsynchronised();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Try to replace NTP sources that are unreachable or falsetickers */
|
/* Try to replace NTP sources that are unreachable, falsetickers, or
|
||||||
if (inst->type == SRC_NTP && (inst->status == SRC_FALSETICKER ||
|
have root distance larger than the allowed maximum */
|
||||||
(!inst->reachability && inst->reachability_size == SOURCE_REACH_BITS))) {
|
if (inst->type == SRC_NTP &&
|
||||||
|
((!inst->reachability && inst->reachability_size == SOURCE_REACH_BITS) ||
|
||||||
|
inst->status == SRC_FALSETICKER || inst->status == SRC_BAD_DISTANCE)) {
|
||||||
NSR_HandleBadSource(inst->ip_addr);
|
NSR_HandleBadSource(inst->ip_addr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -605,6 +609,7 @@ SRC_SelectSource(SRC_Instance updated_inst)
|
|||||||
int n_badstats_sources, max_sel_reach, max_badstat_reach, sel_req_source;
|
int n_badstats_sources, max_sel_reach, max_badstat_reach, sel_req_source;
|
||||||
int depth, best_depth, trust_depth, best_trust_depth;
|
int depth, best_depth, trust_depth, best_trust_depth;
|
||||||
int combined, stratum, min_stratum, max_score_index;
|
int combined, stratum, min_stratum, max_score_index;
|
||||||
|
int orphan_stratum, orphan_source;
|
||||||
double src_offset, src_offset_sd, src_frequency, src_skew;
|
double src_offset, src_offset_sd, src_frequency, src_skew;
|
||||||
double src_root_delay, src_root_dispersion;
|
double src_root_delay, src_root_dispersion;
|
||||||
double best_lo, best_hi, distance, sel_src_distance, max_score;
|
double best_lo, best_hi, distance, sel_src_distance, max_score;
|
||||||
@@ -678,6 +683,9 @@ SRC_SelectSource(SRC_Instance updated_inst)
|
|||||||
max_sel_reach = sources[i]->reachability;
|
max_sel_reach = sources[i]->reachability;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
orphan_stratum = REF_GetOrphanStratum();
|
||||||
|
orphan_source = INVALID_SOURCE;
|
||||||
|
|
||||||
for (i = 0; i < n_sources; i++) {
|
for (i = 0; i < n_sources; i++) {
|
||||||
if (sources[i]->status != SRC_OK)
|
if (sources[i]->status != SRC_OK)
|
||||||
continue;
|
continue;
|
||||||
@@ -692,7 +700,56 @@ SRC_SelectSource(SRC_Instance updated_inst)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* When the local reference is configured with the orphan option, NTP
|
||||||
|
sources that have stratum equal to the configured local stratum are
|
||||||
|
considered to be orphans (i.e. serving local time while not being
|
||||||
|
synchronised with real time) and are excluded from the normal source
|
||||||
|
selection. Sources with stratum larger than the local stratum are
|
||||||
|
considered to be directly on indirectly synchronised to an orphan and
|
||||||
|
are always ignored.
|
||||||
|
|
||||||
|
If no selectable source is available and all orphan sources have
|
||||||
|
reference IDs larger than the local ID, no source will be selected and
|
||||||
|
the local reference mode will be activated at some point, i.e. this host
|
||||||
|
will become an orphan. Otherwise, the orphan source with the smallest
|
||||||
|
reference ID will be selected. This ensures a group of servers polling
|
||||||
|
each other (with the same orphan configuration) which have no external
|
||||||
|
source can settle down to a state where only one server is serving its
|
||||||
|
local unsychronised time and others are synchronised to it. */
|
||||||
|
|
||||||
|
if (si->stratum >= orphan_stratum && sources[i]->type == SRC_NTP) {
|
||||||
|
sources[i]->status = SRC_ORPHAN;
|
||||||
|
|
||||||
|
if (si->stratum == orphan_stratum && sources[i]->reachability &&
|
||||||
|
(orphan_source == INVALID_SOURCE ||
|
||||||
|
sources[i]->ref_id < sources[orphan_source]->ref_id))
|
||||||
|
orphan_source = i;
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
++n_sel_sources;
|
++n_sel_sources;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If no selectable source is available, consider the orphan source */
|
||||||
|
if (!n_sel_sources && orphan_source != INVALID_SOURCE) {
|
||||||
|
uint32_t local_ref_id = NSR_GetLocalRefid(sources[orphan_source]->ip_addr);
|
||||||
|
|
||||||
|
if (!local_ref_id) {
|
||||||
|
LOG(LOGS_ERR, LOGF_Sources, "Unknown local refid in orphan mode");
|
||||||
|
} else if (sources[orphan_source]->ref_id < local_ref_id) {
|
||||||
|
sources[orphan_source]->status = SRC_OK;
|
||||||
|
n_sel_sources = 1;
|
||||||
|
DEBUG_LOG(LOGF_Sources, "selecting orphan refid=%"PRIx32,
|
||||||
|
sources[orphan_source]->ref_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < n_sources; i++) {
|
||||||
|
if (sources[i]->status != SRC_OK)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
si = &sources[i]->sel_info;
|
||||||
|
|
||||||
j1 = n_endpoints;
|
j1 = n_endpoints;
|
||||||
j2 = j1 + 1;
|
j2 = j1 + 1;
|
||||||
@@ -834,6 +891,9 @@ SRC_SelectSource(SRC_Instance updated_inst)
|
|||||||
|
|
||||||
if (sources[i]->sel_options & SRC_SELECT_REQUIRE)
|
if (sources[i]->sel_options & SRC_SELECT_REQUIRE)
|
||||||
sel_req_source = 0;
|
sel_req_source = 0;
|
||||||
|
} else if (sources[i]->sel_info.lo_limit <= best_lo &&
|
||||||
|
sources[i]->sel_info.hi_limit >= best_hi) {
|
||||||
|
sources[i]->status = SRC_UNTRUSTED;
|
||||||
} else {
|
} else {
|
||||||
sources[i]->status = SRC_FALSETICKER;
|
sources[i]->status = SRC_FALSETICKER;
|
||||||
}
|
}
|
||||||
@@ -1252,6 +1312,7 @@ SRC_ReportSource(int index, RPT_SourceReport *report, struct timeval *now)
|
|||||||
case SRC_BAD_STATS:
|
case SRC_BAD_STATS:
|
||||||
case SRC_BAD_DISTANCE:
|
case SRC_BAD_DISTANCE:
|
||||||
case SRC_STALE:
|
case SRC_STALE:
|
||||||
|
case SRC_ORPHAN:
|
||||||
case SRC_WAITS_STATS:
|
case SRC_WAITS_STATS:
|
||||||
report->state = RPT_UNREACH;
|
report->state = RPT_UNREACH;
|
||||||
break;
|
break;
|
||||||
@@ -1261,6 +1322,7 @@ SRC_ReportSource(int index, RPT_SourceReport *report, struct timeval *now)
|
|||||||
case SRC_JITTERY:
|
case SRC_JITTERY:
|
||||||
report->state = RPT_JITTERY;
|
report->state = RPT_JITTERY;
|
||||||
break;
|
break;
|
||||||
|
case SRC_UNTRUSTED:
|
||||||
case SRC_WAITS_SOURCES:
|
case SRC_WAITS_SOURCES:
|
||||||
case SRC_NONPREFERRED:
|
case SRC_NONPREFERRED:
|
||||||
case SRC_WAITS_UPDATE:
|
case SRC_WAITS_UPDATE:
|
||||||
|
|||||||
6
stubs.c
6
stubs.c
@@ -230,6 +230,12 @@ NSR_InitiateSampleBurst(int n_good_samples, int n_total_samples,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t
|
||||||
|
NSR_GetLocalRefid(IPAddr *address)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
NSR_TakeSourcesOnline(IPAddr *mask, IPAddr *address)
|
NSR_TakeSourcesOnline(IPAddr *mask, IPAddr *address)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -50,6 +50,7 @@
|
|||||||
#ifdef FEAT_SCFILTER
|
#ifdef FEAT_SCFILTER
|
||||||
#include <sys/prctl.h>
|
#include <sys/prctl.h>
|
||||||
#include <seccomp.h>
|
#include <seccomp.h>
|
||||||
|
#include <termios.h>
|
||||||
#ifdef FEAT_PHC
|
#ifdef FEAT_PHC
|
||||||
#include <linux/ptp_clock.h>
|
#include <linux/ptp_clock.h>
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
. test.common
|
. ./test.common
|
||||||
|
|
||||||
test_start "default test settings"
|
test_start "default test settings"
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
. test.common
|
. ./test.common
|
||||||
|
|
||||||
test_start "large network"
|
test_start "large network"
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
. test.common
|
. ./test.common
|
||||||
|
|
||||||
test_start "large frequency offset"
|
test_start "large frequency offset"
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
. test.common
|
. ./test.common
|
||||||
|
|
||||||
test_start "large time offset"
|
test_start "large time offset"
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
. test.common
|
. ./test.common
|
||||||
|
|
||||||
test_start "external time step"
|
test_start "external time step"
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
. test.common
|
. ./test.common
|
||||||
|
|
||||||
test_start "large jitter"
|
test_start "large jitter"
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
. test.common
|
. ./test.common
|
||||||
|
|
||||||
test_start "large wander"
|
test_start "large wander"
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
. test.common
|
. ./test.common
|
||||||
test_start "NTP eras"
|
test_start "NTP eras"
|
||||||
|
|
||||||
# Assume NTP_ERA_SPLIT is between years 1960 and 1990
|
# Assume NTP_ERA_SPLIT is between years 1960 and 1990
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
. test.common
|
. ./test.common
|
||||||
|
|
||||||
test_start "source selection"
|
test_start "source selection"
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
. test.common
|
. ./test.common
|
||||||
test_start "minpoll/maxpoll options"
|
test_start "minpoll/maxpoll options"
|
||||||
|
|
||||||
wander=0.0
|
wander=0.0
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
. test.common
|
. ./test.common
|
||||||
test_start "iburst option"
|
test_start "iburst option"
|
||||||
|
|
||||||
freq_offset=1e-4
|
freq_offset=1e-4
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
. test.common
|
. ./test.common
|
||||||
test_start "initstepslew directive"
|
test_start "initstepslew directive"
|
||||||
|
|
||||||
freq_offset=0.0
|
freq_offset=0.0
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
. test.common
|
. ./test.common
|
||||||
test_start "driftfile directive"
|
test_start "driftfile directive"
|
||||||
|
|
||||||
servers=0
|
servers=0
|
||||||
|
|||||||
@@ -1,20 +1,43 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
. test.common
|
. ./test.common
|
||||||
|
|
||||||
test_start "NTP authentication"
|
test_start "NTP authentication"
|
||||||
|
|
||||||
server_conf="keyfile tmp/keys"
|
server_conf="keyfile tmp/server.keys"
|
||||||
client_conf="keyfile tmp/keys"
|
client_conf="keyfile tmp/client.keys"
|
||||||
|
|
||||||
cat > tmp/keys <<-EOF
|
cat > tmp/server.keys <<-EOF
|
||||||
1 $(tr -c -d 'a-zA-Z0-9' < /dev/urandom 2> /dev/null | head -c 24)
|
1 MD5 HEX:6B5D3C6A2E4A74775E4F6F3B7A35453E6E5C5F302D783D2979505C663C295A5E
|
||||||
2 ASCII:$(tr -c -d 'a-zA-Z0-9' < /dev/urandom 2> /dev/null | head -c 24)
|
2 MD5 HEX:6B5D3C6A2E4A74775E4F6F3B7A35453E6E5C5F302D783D2979505C663C295A5E
|
||||||
3 MD5 ASCII:$(tr -c -d 'a-zA-Z' < /dev/urandom 2> /dev/null | head -c 24)
|
3 MD5 HEX:6B5D3C6A2E4A74775E4F6F3B7A35453E6E5C5F302D783D2979505C663C295A5E
|
||||||
4 MD5 HEX:$(tr -c -d '0-9A-F' < /dev/urandom 2> /dev/null | head -c 32)
|
4 MD5 HEX:6B5D3C6A2E4A74775E4F6F3B7A35453E6E5C5F302D783D2979505C663C295A5E
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
for key in 1 2 3 4; do
|
cat > tmp/client.keys <<-EOF
|
||||||
|
1 k]<j.Jtw^Oo;z5E>n\_0-x=)yP\f<)Z^
|
||||||
|
2 ASCII:k]<j.Jtw^Oo;z5E>n\_0-x=)yP\f<)Z^
|
||||||
|
3 MD5 ASCII:k]<j.Jtw^Oo;z5E>n\_0-x=)yP\f<)Z^
|
||||||
|
4 MD5 HEX:6B5D3C6A2E4A74775E4F6F3B7A35453E6E5C5F302D783D2979505C663C295A5E
|
||||||
|
EOF
|
||||||
|
|
||||||
|
keys=4
|
||||||
|
|
||||||
|
if grep -q 'FEAT_SECHASH 1' ../../config.h; then
|
||||||
|
hashes="MD5 SHA1 SHA256 SHA384 SHA512"
|
||||||
|
else
|
||||||
|
hashes="MD5"
|
||||||
|
fi
|
||||||
|
|
||||||
|
for hash in $hashes; do
|
||||||
|
keys=$[$keys + 1]
|
||||||
|
key=$(echo $keys $hash HEX:$(tr -c -d '0-9A-F' < /dev/urandom 2> /dev/null | \
|
||||||
|
head -c $[$RANDOM % 64 * 2 + 2]))
|
||||||
|
echo "$key" >> tmp/server.keys
|
||||||
|
echo "$key" >> tmp/client.keys
|
||||||
|
done
|
||||||
|
|
||||||
|
for key in $(seq $keys); do
|
||||||
client_server_options="key $key"
|
client_server_options="key $key"
|
||||||
run_test || test_fail
|
run_test || test_fail
|
||||||
check_chronyd_exit || test_fail
|
check_chronyd_exit || test_fail
|
||||||
@@ -31,7 +54,7 @@ check_chronyd_exit || test_fail
|
|||||||
check_sync && test_fail
|
check_sync && test_fail
|
||||||
check_packet_interval || test_fail
|
check_packet_interval || test_fail
|
||||||
|
|
||||||
server_conf="keyfile tmp/keys"
|
server_conf="keyfile tmp/server.keys"
|
||||||
client_conf=""
|
client_conf=""
|
||||||
|
|
||||||
run_test || test_fail
|
run_test || test_fail
|
||||||
@@ -40,10 +63,10 @@ check_chronyd_exit || test_fail
|
|||||||
check_sync && test_fail
|
check_sync && test_fail
|
||||||
check_packet_interval || test_fail
|
check_packet_interval || test_fail
|
||||||
|
|
||||||
client_conf="keyfile tmp/keys"
|
client_conf="keyfile tmp/client.keys"
|
||||||
clients=2
|
clients=2
|
||||||
peers=2
|
peers=2
|
||||||
max_sync_time=300
|
max_sync_time=500
|
||||||
base_delay="$default_base_delay (* -1 (equal 0.1 from 3) (equal 0.1 to 1))"
|
base_delay="$default_base_delay (* -1 (equal 0.1 from 3) (equal 0.1 to 1))"
|
||||||
client_lpeer_options="key 1"
|
client_lpeer_options="key 1"
|
||||||
client_rpeer_options="key 1"
|
client_rpeer_options="key 1"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
. test.common
|
. ./test.common
|
||||||
test_start "SHM refclock"
|
test_start "SHM refclock"
|
||||||
|
|
||||||
servers=0
|
servers=0
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
. test.common
|
. ./test.common
|
||||||
|
|
||||||
test_start "allow/deny directives"
|
test_start "allow/deny directives"
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
. test.common
|
. ./test.common
|
||||||
|
|
||||||
test_start "NTP peers"
|
test_start "NTP peers"
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
. test.common
|
. ./test.common
|
||||||
test_start "makestep directive"
|
test_start "makestep directive"
|
||||||
|
|
||||||
client_conf="makestep 0 -1
|
client_conf="makestep 0 -1
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
. test.common
|
. ./test.common
|
||||||
|
|
||||||
test_start "chronyc"
|
test_start "chronyc"
|
||||||
|
|
||||||
@@ -13,7 +13,7 @@ check_chronyd_exit || test_fail
|
|||||||
|
|
||||||
check_chronyc_output "^Reference ID : 192\.168\.123\.1 \(192\.168\.123\.1\)
|
check_chronyc_output "^Reference ID : 192\.168\.123\.1 \(192\.168\.123\.1\)
|
||||||
Stratum : 2
|
Stratum : 2
|
||||||
Ref time \(UTC\) : Fri Jan 1 00:1.:.. 2010
|
Ref time \(UTC\) : Fri Jan 01 00:1.:.. 2010
|
||||||
System time : 0\.0000..... seconds (slow|fast) of NTP time
|
System time : 0\.0000..... seconds (slow|fast) of NTP time
|
||||||
Last offset : [+-]0\.000...... seconds
|
Last offset : [+-]0\.000...... seconds
|
||||||
RMS offset : 0\.000...... seconds
|
RMS offset : 0\.000...... seconds
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
. test.common
|
. ./test.common
|
||||||
|
|
||||||
test_start "reply to client configured as server"
|
test_start "reply to client configured as server"
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
. test.common
|
. ./test.common
|
||||||
|
|
||||||
test_start "port and acquisitionport directives"
|
test_start "port and acquisitionport directives"
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
. test.common
|
. ./test.common
|
||||||
test_start "leap second"
|
test_start "leap second"
|
||||||
|
|
||||||
export CLKNETSIM_START_DATE=$(TZ=UTC date -d 'Dec 30 2008 0:00:00' +'%s')
|
export CLKNETSIM_START_DATE=$(TZ=UTC date -d 'Dec 30 2008 0:00:00' +'%s')
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
. test.common
|
. ./test.common
|
||||||
test_start "presend option"
|
test_start "presend option"
|
||||||
|
|
||||||
min_sync_time=140
|
min_sync_time=140
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
. test.common
|
. ./test.common
|
||||||
|
|
||||||
test_start "cmdmon timestamps"
|
test_start "cmdmon timestamps"
|
||||||
|
|
||||||
@@ -10,11 +10,11 @@ grep -q 'HAVE_LONG_TIME_T 1' ../../config.h || test_skip
|
|||||||
limit=2
|
limit=2
|
||||||
client_server_options="noselect"
|
client_server_options="noselect"
|
||||||
client_conf="local stratum 1"
|
client_conf="local stratum 1"
|
||||||
chronyc_start="0.5"
|
chronyc_start="1.5"
|
||||||
chronyc_conf="tracking"
|
chronyc_conf="tracking"
|
||||||
|
|
||||||
for year in `seq 1850 100 2300`; do
|
for year in `seq 1850 100 2300`; do
|
||||||
date="Jan 1 00:00:00 $year"
|
date="Jan 01 00:00:00 $year"
|
||||||
export CLKNETSIM_START_DATE=$(date -d "$date UTC" +'%s')
|
export CLKNETSIM_START_DATE=$(date -d "$date UTC" +'%s')
|
||||||
run_test || test_fail
|
run_test || test_fail
|
||||||
check_chronyd_exit || test_fail
|
check_chronyd_exit || test_fail
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
. test.common
|
. ./test.common
|
||||||
|
|
||||||
test_start "minsources directive"
|
test_start "minsources directive"
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
. test.common
|
. ./test.common
|
||||||
test_start "fallback drift"
|
test_start "fallback drift"
|
||||||
|
|
||||||
limit=100000
|
limit=100000
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
. test.common
|
. ./test.common
|
||||||
test_start "maxdelay options"
|
test_start "maxdelay options"
|
||||||
|
|
||||||
max_sync_time=2000
|
max_sync_time=2000
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
. test.common
|
. ./test.common
|
||||||
test_start "smoothtime option"
|
test_start "smoothtime option"
|
||||||
|
|
||||||
server_strata=2
|
server_strata=2
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
. test.common
|
. ./test.common
|
||||||
|
|
||||||
test_start "source selection options"
|
test_start "source selection options"
|
||||||
|
|
||||||
|
|||||||
23
test/simulation/121-orphan
Executable file
23
test/simulation/121-orphan
Executable file
@@ -0,0 +1,23 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
. ./test.common
|
||||||
|
|
||||||
|
test_start "orphan option"
|
||||||
|
|
||||||
|
server_strata=3
|
||||||
|
server_conf="local stratum 5 orphan
|
||||||
|
server 192.168.123.1
|
||||||
|
server 192.168.123.2
|
||||||
|
server 192.168.123.3"
|
||||||
|
max_sync_time=500
|
||||||
|
chronyc_start=300
|
||||||
|
chronyc_conf="tracking"
|
||||||
|
time_rms_limit=5e-4
|
||||||
|
|
||||||
|
run_test || test_fail
|
||||||
|
check_chronyd_exit || test_fail
|
||||||
|
check_source_selection || test_fail
|
||||||
|
check_sync || test_fail
|
||||||
|
check_chronyc_output "^.*Stratum *: 7.*$" || test_fail
|
||||||
|
|
||||||
|
test_pass
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
. test.common
|
. ./test.common
|
||||||
|
|
||||||
# Test fix in commit 60d0fa299307076143da94d36deb7b908fa9bdb7
|
# Test fix in commit 60d0fa299307076143da94d36deb7b908fa9bdb7
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
. test.common
|
. ./test.common
|
||||||
|
|
||||||
# Test fix in commit 4253075a97141edfa62043ab71bd0673587e6629
|
# Test fix in commit 4253075a97141edfa62043ab71bd0673587e6629
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
This is a collection of simulation tests. They use clknetsim to simulate
|
This is a collection of simulation tests using the clknetsim simulator
|
||||||
multiple systems connected in a network. It's available at
|
(supported on Linux only).
|
||||||
|
|
||||||
https://github.com/mlichvar/clknetsim
|
https://github.com/mlichvar/clknetsim
|
||||||
|
|
||||||
If this directory doesn't have a clknetsim subdirectory, a known working
|
The CLKNETSIM_PATH environment variable should point to the directory where
|
||||||
revision will be downloaded and compiled automatically.
|
clknetsim was downloaded and compiled. If the variable is not set, the tests
|
||||||
|
will look for clknetsim in ./clknetsim in the current directory.
|
||||||
Currently it runs only on Linux.
|
|
||||||
|
|
||||||
The tests are written in bash and they can be run directly. The ./run script
|
The tests are written in bash and they can be run directly. The ./run script
|
||||||
runs all tests.
|
runs all tests.
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
. test.common
|
|
||||||
|
|
||||||
passed=() failed=() skipped=()
|
passed=() failed=() skipped=()
|
||||||
|
|
||||||
[ $# -gt 0 ] && tests=($@) || tests=([0-9]*-*[^_])
|
[ $# -gt 0 ] && tests=($@) || tests=([0-9]*-*[^_])
|
||||||
|
|||||||
@@ -15,27 +15,11 @@
|
|||||||
|
|
||||||
export LC_ALL=C
|
export LC_ALL=C
|
||||||
export PATH=../../:$PATH
|
export PATH=../../:$PATH
|
||||||
export CLKNETSIM_PATH=clknetsim
|
export CLKNETSIM_PATH=${CLKNETSIM_PATH:-clknetsim}
|
||||||
|
|
||||||
# Known working clknetsim revision
|
if [ ! -x $CLKNETSIM_PATH/clknetsim ]; then
|
||||||
clknetsim_revision=1e56224dee1db69c0027e9bd63c2a202d4765959
|
echo "SKIP (clknetsim not found)"
|
||||||
clknetsim_url=https://github.com/mlichvar/clknetsim/archive/$clknetsim_revision.tar.gz
|
exit 9
|
||||||
|
|
||||||
# Only Linux is supported
|
|
||||||
if [ "$(uname -s)" != Linux ]; then
|
|
||||||
echo "Simulation tests supported only on Linux"
|
|
||||||
exit 3
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Try to download clknetsim if not found
|
|
||||||
if [ ! -e $CLKNETSIM_PATH ]; then
|
|
||||||
curl -L "$clknetsim_url" | tar xz || exit 3
|
|
||||||
ln -s clknetsim-$clknetsim_revision clknetsim || exit 3
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Try to build clknetsim if not built
|
|
||||||
if [ ! -x $CLKNETSIM_PATH/clknetsim -o ! -e $CLKNETSIM_PATH/clknetsim.so ]; then
|
|
||||||
make -C clknetsim || exit 3
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
. $CLKNETSIM_PATH/clknetsim.bash
|
. $CLKNETSIM_PATH/clknetsim.bash
|
||||||
|
|||||||
45
test/unit/Makefile.in
Normal file
45
test/unit/Makefile.in
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
TEST_WRAPPER =
|
||||||
|
CHRONY_SRCDIR = ../..
|
||||||
|
|
||||||
|
CC = @CC@
|
||||||
|
CFLAGS = @CFLAGS@
|
||||||
|
CPPFLAGS = -I$(CHRONY_SRCDIR) @CPPFLAGS@
|
||||||
|
LDFLAGS = @LDFLAGS@ @LIBS@ @EXTRA_LIBS@
|
||||||
|
|
||||||
|
SHARED_OBJS = test.o
|
||||||
|
|
||||||
|
TEST_OBJS := $(sort $(patsubst %.c,%.o,$(wildcard *.c)))
|
||||||
|
TESTS := $(patsubst %.o,%.test,$(filter-out $(SHARED_OBJS),$(TEST_OBJS)))
|
||||||
|
|
||||||
|
FILTER_OBJS = %/main.o %/client.o %/getdate.o
|
||||||
|
CHRONY_OBJS := $(filter-out $(FILTER_OBJS),$(wildcard $(CHRONY_SRCDIR)/*.o))
|
||||||
|
|
||||||
|
all: $(TESTS)
|
||||||
|
|
||||||
|
%.test: %.o $(SHARED_OBJS)
|
||||||
|
$(CC) $(CFLAGS) -o $@ $^ $(CHRONY_OBJS:%/$*.o=) $(LDFLAGS)
|
||||||
|
|
||||||
|
%.o: %.c
|
||||||
|
$(CC) $(CPPFLAGS) $(CFLAGS) -c $<
|
||||||
|
|
||||||
|
check: $(TESTS)
|
||||||
|
@ret=0; \
|
||||||
|
for t in $^; do \
|
||||||
|
$(TEST_WRAPPER) ./$$t || ret=1; \
|
||||||
|
done; \
|
||||||
|
exit $$ret
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f *.o $(TESTS)
|
||||||
|
rm -rf .deps
|
||||||
|
|
||||||
|
distclean: clean
|
||||||
|
rm -f Makefile
|
||||||
|
|
||||||
|
.deps:
|
||||||
|
@mkdir .deps
|
||||||
|
|
||||||
|
.deps/%.d: %.c | .deps
|
||||||
|
@$(CC) -MM $(CPPFLAGS) -MT '$(<:%.c=%.o) $@' $< -o $@
|
||||||
|
|
||||||
|
-include $(TEST_OBJS:%.o=.deps/%.d)
|
||||||
83
test/unit/addrfilt.c
Normal file
83
test/unit/addrfilt.c
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
/*
|
||||||
|
**********************************************************************
|
||||||
|
* Copyright (C) Miroslav Lichvar 2016
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of version 2 of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <addrfilt.c>
|
||||||
|
#include <logging.h>
|
||||||
|
#include <util.h>
|
||||||
|
#include "test.h"
|
||||||
|
|
||||||
|
void
|
||||||
|
test_unit(void)
|
||||||
|
{
|
||||||
|
int i, j, sub, maxsub;
|
||||||
|
IPAddr ip;
|
||||||
|
ADF_AuthTable table;
|
||||||
|
|
||||||
|
table = ADF_CreateTable();
|
||||||
|
|
||||||
|
for (i = 0; i < 100; i++) {
|
||||||
|
for (j = 0; j < 1000; j++) {
|
||||||
|
if (j % 2) {
|
||||||
|
maxsub = 32;
|
||||||
|
TST_GetRandomAddress(&ip, IPADDR_INET4, -1);
|
||||||
|
} else {
|
||||||
|
maxsub = 128;
|
||||||
|
TST_GetRandomAddress(&ip, IPADDR_INET6, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
DEBUG_LOG(0, "address %s", UTI_IPToString(&ip));
|
||||||
|
|
||||||
|
sub = random() % (maxsub + 1);
|
||||||
|
|
||||||
|
TEST_CHECK(!ADF_IsAllowed(table, &ip));
|
||||||
|
ADF_Allow(table, &ip, sub);
|
||||||
|
TEST_CHECK(ADF_IsAllowed(table, &ip));
|
||||||
|
|
||||||
|
if (sub < maxsub) {
|
||||||
|
TST_SwapAddressBit(&ip, sub);
|
||||||
|
TEST_CHECK(ADF_IsAllowed(table, &ip));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sub > 0) {
|
||||||
|
TST_SwapAddressBit(&ip, sub - 1);
|
||||||
|
TEST_CHECK(!ADF_IsAllowed(table, &ip));
|
||||||
|
if (sub % 4 != 1) {
|
||||||
|
ADF_Deny(table, &ip, sub - 1);
|
||||||
|
TST_SwapAddressBit(&ip, sub - 1);
|
||||||
|
TEST_CHECK(!ADF_IsAllowed(table, &ip));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sub > 4) {
|
||||||
|
ADF_AllowAll(table, &ip, sub - 4);
|
||||||
|
TEST_CHECK(ADF_IsAllowed(table, &ip));
|
||||||
|
}
|
||||||
|
|
||||||
|
ADF_DenyAll(table, &ip, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
ip.family = IPADDR_INET4;
|
||||||
|
ADF_DenyAll(table, &ip, 0);
|
||||||
|
ip.family = IPADDR_INET6;
|
||||||
|
ADF_DenyAll(table, &ip, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
ADF_DestroyTable(table);
|
||||||
|
}
|
||||||
84
test/unit/clientlog.c
Normal file
84
test/unit/clientlog.c
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
/*
|
||||||
|
**********************************************************************
|
||||||
|
* Copyright (C) Miroslav Lichvar 2016
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of version 2 of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <clientlog.c>
|
||||||
|
#include "test.h"
|
||||||
|
|
||||||
|
void
|
||||||
|
test_unit(void)
|
||||||
|
{
|
||||||
|
int i, j, index;
|
||||||
|
struct timeval tv;
|
||||||
|
IPAddr ip;
|
||||||
|
char conf[][100] = {
|
||||||
|
"clientloglimit 10000",
|
||||||
|
"ratelimit interval 3 burst 4 leak 3",
|
||||||
|
"cmdratelimit interval 3 burst 4 leak 3",
|
||||||
|
};
|
||||||
|
|
||||||
|
CNF_Initialise(0);
|
||||||
|
for (i = 0; i < sizeof conf / sizeof conf[0]; i++)
|
||||||
|
CNF_ParseLine(NULL, i + 1, conf[i]);
|
||||||
|
|
||||||
|
CLG_Initialise();
|
||||||
|
|
||||||
|
TEST_CHECK(ARR_GetSize(records) == 16);
|
||||||
|
|
||||||
|
for (i = 0; i < 500; i++) {
|
||||||
|
DEBUG_LOG(0, "iteration %d", i);
|
||||||
|
|
||||||
|
tv.tv_sec = (time_t)random() & 0x0fffffff;
|
||||||
|
tv.tv_usec = 0;
|
||||||
|
|
||||||
|
for (j = 0; j < 1000; j++) {
|
||||||
|
TST_GetRandomAddress(&ip, IPADDR_UNSPEC, i % 8 ? -1 : i / 8 % 9);
|
||||||
|
DEBUG_LOG(0, "address %s", UTI_IPToString(&ip));
|
||||||
|
|
||||||
|
if (random() % 2) {
|
||||||
|
index = CLG_LogNTPAccess(&ip, &tv);
|
||||||
|
TEST_CHECK(index >= 0);
|
||||||
|
CLG_LimitNTPResponseRate(index);
|
||||||
|
} else {
|
||||||
|
index = CLG_LogCommandAccess(&ip, &tv);
|
||||||
|
TEST_CHECK(index >= 0);
|
||||||
|
CLG_LimitCommandResponseRate(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
UTI_AddDoubleToTimeval(&tv, (1 << random() % 14) / 100.0, &tv);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DEBUG_LOG(0, "records %d", ARR_GetSize(records));
|
||||||
|
TEST_CHECK(ARR_GetSize(records) == 128);
|
||||||
|
|
||||||
|
for (i = j = 0; i < 10000; i++) {
|
||||||
|
tv.tv_sec += 1;
|
||||||
|
index = CLG_LogNTPAccess(&ip, &tv);
|
||||||
|
TEST_CHECK(index >= 0);
|
||||||
|
if (!CLG_LimitNTPResponseRate(index))
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
|
||||||
|
DEBUG_LOG(0, "requests %u responses %u", i, j);
|
||||||
|
TEST_CHECK(j * 4 < i && j * 6 > i);
|
||||||
|
|
||||||
|
CLG_Finalise();
|
||||||
|
CNF_Finalise();
|
||||||
|
}
|
||||||
99
test/unit/ntp_sources.c
Normal file
99
test/unit/ntp_sources.c
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
/*
|
||||||
|
**********************************************************************
|
||||||
|
* Copyright (C) Miroslav Lichvar 2016
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of version 2 of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <ntp_sources.c>
|
||||||
|
#include <conf.h>
|
||||||
|
#include <ntp_io.h>
|
||||||
|
#include "test.h"
|
||||||
|
|
||||||
|
void
|
||||||
|
test_unit(void)
|
||||||
|
{
|
||||||
|
int i, j, k, slot, found;
|
||||||
|
uint32_t hash = 0;
|
||||||
|
NTP_Remote_Address addrs[256], addr;
|
||||||
|
SourceParameters params;
|
||||||
|
char conf[] = "port 0";
|
||||||
|
|
||||||
|
memset(¶ms, 0, sizeof (params));
|
||||||
|
|
||||||
|
CNF_Initialise(0);
|
||||||
|
CNF_ParseLine(NULL, 1, conf);
|
||||||
|
|
||||||
|
LCL_Initialise();
|
||||||
|
SCH_Initialise();
|
||||||
|
SRC_Initialise();
|
||||||
|
NIO_Initialise(IPADDR_UNSPEC);
|
||||||
|
NCR_Initialise();
|
||||||
|
NSR_Initialise();
|
||||||
|
|
||||||
|
for (i = 0; i < 6; i++) {
|
||||||
|
TEST_CHECK(ARR_GetSize(records) == 1);
|
||||||
|
|
||||||
|
DEBUG_LOG(0, "collision mod %u", 1U << i);
|
||||||
|
|
||||||
|
for (j = 0; j < sizeof (addrs) / sizeof (addrs[0]); j++) {
|
||||||
|
do {
|
||||||
|
TST_GetRandomAddress(&addrs[j].ip_addr, IPADDR_UNSPEC, -1);
|
||||||
|
} while (UTI_IPToHash(&addrs[j].ip_addr) % (1U << i) != hash % (1U << i));
|
||||||
|
|
||||||
|
addrs[j].port = random() % 1024;
|
||||||
|
|
||||||
|
if (!j)
|
||||||
|
hash = UTI_IPToHash(&addrs[j].ip_addr);
|
||||||
|
|
||||||
|
DEBUG_LOG(0, "adding source %s hash %"PRIu32, UTI_IPToString(&addrs[j].ip_addr),
|
||||||
|
UTI_IPToHash(&addrs[j].ip_addr) % (1U << i));
|
||||||
|
|
||||||
|
NSR_AddSource(&addrs[j], random() % 2 ? NTP_SERVER : NTP_PEER, ¶ms);
|
||||||
|
|
||||||
|
for (k = 0; k < j; k++) {
|
||||||
|
addr = addrs[k];
|
||||||
|
find_slot(&addr, &slot, &found);
|
||||||
|
TEST_CHECK(found == 2);
|
||||||
|
TEST_CHECK(!UTI_CompareIPs(&get_record(slot)->remote_addr->ip_addr,
|
||||||
|
&addr.ip_addr, NULL));
|
||||||
|
addr.port++;
|
||||||
|
find_slot(&addr, &slot, &found);
|
||||||
|
TEST_CHECK(found == 1);
|
||||||
|
TEST_CHECK(!UTI_CompareIPs(&get_record(slot)->remote_addr->ip_addr,
|
||||||
|
&addr.ip_addr, NULL));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (j = 0; j < sizeof (addrs) / sizeof (addrs[0]); j++) {
|
||||||
|
DEBUG_LOG(0, "removing source %s", UTI_IPToString(&addrs[j].ip_addr));
|
||||||
|
NSR_RemoveSource(&addrs[j]);
|
||||||
|
|
||||||
|
for (k = 0; k < sizeof (addrs) / sizeof (addrs[0]); k++) {
|
||||||
|
find_slot(&addrs[k], &slot, &found);
|
||||||
|
TEST_CHECK(found == (k <= j ? 0 : 2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
NSR_Finalise();
|
||||||
|
NCR_Finalise();
|
||||||
|
NIO_Finalise();
|
||||||
|
SRC_Finalise();
|
||||||
|
SCH_Finalise();
|
||||||
|
LCL_Finalise();
|
||||||
|
CNF_Finalise();
|
||||||
|
}
|
||||||
63
test/unit/smooth.c
Normal file
63
test/unit/smooth.c
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
**********************************************************************
|
||||||
|
* Copyright (C) Miroslav Lichvar 2016
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of version 2 of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <smooth.c>
|
||||||
|
#include "test.h"
|
||||||
|
|
||||||
|
void
|
||||||
|
test_unit(void)
|
||||||
|
{
|
||||||
|
int i, j;
|
||||||
|
struct timeval tv;
|
||||||
|
double offset, freq, wander;
|
||||||
|
char conf[] = "smoothtime 300 0.01";
|
||||||
|
|
||||||
|
CNF_Initialise(0);
|
||||||
|
CNF_ParseLine(NULL, 1, conf);
|
||||||
|
|
||||||
|
LCL_Initialise();
|
||||||
|
SMT_Initialise();
|
||||||
|
locked = 0;
|
||||||
|
|
||||||
|
for (i = 0; i < 500; i++) {
|
||||||
|
tv.tv_sec = tv.tv_usec = 0;
|
||||||
|
SMT_Reset(&tv);
|
||||||
|
|
||||||
|
DEBUG_LOG(0, "iteration %d", i);
|
||||||
|
|
||||||
|
offset = (random() % 1000000 - 500000) / 1.0e6;
|
||||||
|
freq = (random() % 1000000 - 500000) / 1.0e9;
|
||||||
|
update_smoothing(&tv, offset, freq);
|
||||||
|
|
||||||
|
for (j = 0; j < 10000; j++) {
|
||||||
|
update_smoothing(&tv, 0.0, 0.0);
|
||||||
|
UTI_AddDoubleToTimeval(&tv, 16.0, &tv);
|
||||||
|
get_smoothing(&tv, &offset, &freq, &wander);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CHECK(fabs(offset) < 1e-12);
|
||||||
|
TEST_CHECK(fabs(freq) < 1e-12);
|
||||||
|
TEST_CHECK(fabs(wander) < 1e-12);
|
||||||
|
}
|
||||||
|
|
||||||
|
SMT_Finalise();
|
||||||
|
LCL_Finalise();
|
||||||
|
CNF_Finalise();
|
||||||
|
}
|
||||||
137
test/unit/sources.c
Normal file
137
test/unit/sources.c
Normal file
@@ -0,0 +1,137 @@
|
|||||||
|
/*
|
||||||
|
**********************************************************************
|
||||||
|
* Copyright (C) Miroslav Lichvar 2016
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of version 2 of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sources.c>
|
||||||
|
#include "test.h"
|
||||||
|
|
||||||
|
void
|
||||||
|
test_unit(void)
|
||||||
|
{
|
||||||
|
SRC_Instance srcs[16];
|
||||||
|
RPT_SourceReport report;
|
||||||
|
IPAddr addr;
|
||||||
|
int i, j, k, l, samples, sel_options;
|
||||||
|
double offset, delay, disp;
|
||||||
|
struct timeval tv;
|
||||||
|
|
||||||
|
CNF_Initialise(0);
|
||||||
|
LCL_Initialise();
|
||||||
|
TST_RegisterDummyDrivers();
|
||||||
|
SCH_Initialise();
|
||||||
|
SRC_Initialise();
|
||||||
|
REF_Initialise();
|
||||||
|
|
||||||
|
REF_SetMode(REF_ModeIgnore);
|
||||||
|
|
||||||
|
for (i = 0; i < 1000; i++) {
|
||||||
|
DEBUG_LOG(0, "iteration %d", i);
|
||||||
|
|
||||||
|
for (j = 0; j < sizeof (srcs) / sizeof (srcs[0]); j++) {
|
||||||
|
TEST_CHECK(n_sources == j);
|
||||||
|
|
||||||
|
TST_GetRandomAddress(&addr, IPADDR_UNSPEC, -1);
|
||||||
|
|
||||||
|
sel_options = i & random() & (SRC_SELECT_NOSELECT | SRC_SELECT_PREFER |
|
||||||
|
SRC_SELECT_TRUST | SRC_SELECT_REQUIRE);
|
||||||
|
|
||||||
|
DEBUG_LOG(0, "added source %d options %d", j, sel_options);
|
||||||
|
srcs[j] = SRC_CreateNewInstance(UTI_IPToRefid(&addr), SRC_NTP, sel_options, &addr,
|
||||||
|
SRC_DEFAULT_MINSAMPLES, SRC_DEFAULT_MAXSAMPLES);
|
||||||
|
SRC_UpdateReachability(srcs[j], 1);
|
||||||
|
|
||||||
|
samples = (i + j) % 5 + 3;
|
||||||
|
|
||||||
|
offset = TST_GetRandomDouble(-1.0, 1.0);
|
||||||
|
|
||||||
|
for (k = 0; k < samples; k++) {
|
||||||
|
SCH_GetLastEventTime(&tv, NULL, NULL);
|
||||||
|
UTI_AddDoubleToTimeval(&tv, TST_GetRandomDouble(k - samples, k - samples + 1), &tv);
|
||||||
|
|
||||||
|
offset += TST_GetRandomDouble(-1.0e-2, 1.0e-2);
|
||||||
|
delay = TST_GetRandomDouble(1.0e-6, 1.0e-1);
|
||||||
|
disp = TST_GetRandomDouble(1.0e-6, 1.0e-1);
|
||||||
|
|
||||||
|
DEBUG_LOG(0, "source %d sample %d offset %f delay %f disp %f", j, k,
|
||||||
|
offset, delay, disp);
|
||||||
|
|
||||||
|
SRC_AccumulateSample(srcs[j], &tv, offset, delay, disp, delay, disp,
|
||||||
|
1, LEAP_Normal);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (k = 0; k <= j; k++) {
|
||||||
|
int passed = 0, trusted = 0, trusted_passed = 0, required = 0, required_passed = 0;
|
||||||
|
double trusted_lo = DBL_MAX, trusted_hi = DBL_MIN;
|
||||||
|
double passed_lo = DBL_MAX, passed_hi = DBL_MIN;
|
||||||
|
|
||||||
|
SRC_SelectSource(srcs[k]);
|
||||||
|
DEBUG_LOG(0, "source %d status %d", k, sources[k]->status);
|
||||||
|
|
||||||
|
for (l = 0; l <= j; l++) {
|
||||||
|
TEST_CHECK(sources[l]->status > SRC_OK && sources[l]->status <= SRC_SELECTED);
|
||||||
|
if (sources[l]->sel_options & SRC_SELECT_NOSELECT) {
|
||||||
|
TEST_CHECK(sources[l]->status == SRC_UNSELECTABLE);
|
||||||
|
} else if (sources[l]->status != SRC_BAD_DISTANCE) {
|
||||||
|
if (sources[l]->status >= SRC_NONPREFERRED) {
|
||||||
|
passed++;
|
||||||
|
if (passed_lo > sources[l]->sel_info.lo_limit)
|
||||||
|
passed_lo = sources[l]->sel_info.lo_limit;
|
||||||
|
if (passed_hi < sources[l]->sel_info.hi_limit)
|
||||||
|
passed_hi = sources[l]->sel_info.hi_limit;
|
||||||
|
}
|
||||||
|
if (sources[l]->sel_options & SRC_SELECT_TRUST) {
|
||||||
|
trusted++;
|
||||||
|
if (trusted_lo > sources[l]->sel_info.lo_limit)
|
||||||
|
trusted_lo = sources[l]->sel_info.lo_limit;
|
||||||
|
if (trusted_hi < sources[l]->sel_info.hi_limit)
|
||||||
|
trusted_hi = sources[l]->sel_info.hi_limit;
|
||||||
|
if (sources[l]->status >= SRC_NONPREFERRED)
|
||||||
|
trusted_passed++;
|
||||||
|
}
|
||||||
|
if (sources[l]->sel_options & SRC_SELECT_REQUIRE) {
|
||||||
|
required++;
|
||||||
|
if (sources[l]->status >= SRC_NONPREFERRED)
|
||||||
|
required_passed++;
|
||||||
|
}
|
||||||
|
if (sources[l]->sel_options & SRC_SELECT_PREFER)
|
||||||
|
TEST_CHECK(sources[l]->status != SRC_NONPREFERRED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DEBUG_LOG(0, "sources %d passed %d trusted %d/%d required %d/%d", j, passed,
|
||||||
|
trusted_passed, trusted, required_passed, required);
|
||||||
|
|
||||||
|
TEST_CHECK(!trusted || !passed || (passed_lo >= trusted_lo && passed_hi <= trusted_hi));
|
||||||
|
TEST_CHECK(!passed || trusted != 1 || (trusted == 1 && trusted_passed == 1));
|
||||||
|
TEST_CHECK(!passed || !required || required_passed > 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (j = 0; j < sizeof (srcs) / sizeof (srcs[0]); j++) {
|
||||||
|
SRC_ReportSource(j, &report, &tv);
|
||||||
|
SRC_DestroyInstance(srcs[j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
REF_Finalise();
|
||||||
|
SRC_Finalise();
|
||||||
|
SCH_Finalise();
|
||||||
|
LCL_Finalise();
|
||||||
|
CNF_Finalise();
|
||||||
|
}
|
||||||
165
test/unit/test.c
Normal file
165
test/unit/test.c
Normal file
@@ -0,0 +1,165 @@
|
|||||||
|
/*
|
||||||
|
**********************************************************************
|
||||||
|
* Copyright (C) Miroslav Lichvar 2016
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of version 2 of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <config.h>
|
||||||
|
#include <sysincl.h>
|
||||||
|
#include <logging.h>
|
||||||
|
#include <localp.h>
|
||||||
|
|
||||||
|
#include "test.h"
|
||||||
|
|
||||||
|
void
|
||||||
|
TST_Fail(int line)
|
||||||
|
{
|
||||||
|
printf("FAIL (on line %d)\n", line);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
char *test_name, *s;
|
||||||
|
int i, seed = 0;
|
||||||
|
struct timeval tv;
|
||||||
|
|
||||||
|
test_name = argv[0];
|
||||||
|
s = strrchr(test_name, '.');
|
||||||
|
if (s)
|
||||||
|
*s = '\0';
|
||||||
|
s = strrchr(test_name, '/');
|
||||||
|
if (s)
|
||||||
|
test_name = s + 1;
|
||||||
|
|
||||||
|
for (i = 1; i < argc; i++) {
|
||||||
|
if (!strcmp(argv[i], "-d")) {
|
||||||
|
LOG_SetDebugLevel(2);
|
||||||
|
} else if (!strcmp(argv[i], "-s") && i + 1 < argc) {
|
||||||
|
seed = atoi(argv[++i]);
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "Unknown option\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
gettimeofday(&tv, NULL);
|
||||||
|
srandom(seed ? seed : tv.tv_sec ^ (tv.tv_usec << 10));
|
||||||
|
|
||||||
|
printf("Testing %-30s ", test_name);
|
||||||
|
fflush(stdout);
|
||||||
|
|
||||||
|
test_unit();
|
||||||
|
|
||||||
|
printf("PASS\n");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
double
|
||||||
|
TST_GetRandomDouble(double min, double max)
|
||||||
|
{
|
||||||
|
return min + (double)random() / RAND_MAX * (max - min);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
TST_GetRandomAddress(IPAddr *ip, int family, int bits)
|
||||||
|
{
|
||||||
|
if (family != IPADDR_INET4 && family != IPADDR_INET6)
|
||||||
|
family = random() % 2 ? IPADDR_INET4 : IPADDR_INET6;
|
||||||
|
|
||||||
|
ip->family = family;
|
||||||
|
|
||||||
|
if (family == IPADDR_INET4) {
|
||||||
|
if (bits < 0)
|
||||||
|
bits = 32;
|
||||||
|
assert(bits <= 32);
|
||||||
|
|
||||||
|
if (bits > 16)
|
||||||
|
ip->addr.in4 = (uint32_t)random() % (1U << (bits - 16)) << 16 |
|
||||||
|
(uint32_t)random() % (1U << 16);
|
||||||
|
else
|
||||||
|
ip->addr.in4 = (uint32_t)random() % (1U << bits);
|
||||||
|
} else {
|
||||||
|
int i, b;
|
||||||
|
|
||||||
|
if (bits < 0)
|
||||||
|
bits = 128;
|
||||||
|
assert(bits <= 128);
|
||||||
|
|
||||||
|
for (i = 0, b = 120; i < 16; i++, b -= 8) {
|
||||||
|
if (b >= bits) {
|
||||||
|
ip->addr.in6[i] = 0;
|
||||||
|
} else {
|
||||||
|
ip->addr.in6[i] = random() % (1U << MIN(bits - b, 8));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
TST_SwapAddressBit(IPAddr *ip, unsigned int b)
|
||||||
|
{
|
||||||
|
if (ip->family == IPADDR_INET4) {
|
||||||
|
assert(b < 32);
|
||||||
|
ip->addr.in4 ^= 1U << (31 - b);
|
||||||
|
} else if (ip->family == IPADDR_INET6) {
|
||||||
|
assert(b < 128);
|
||||||
|
ip->addr.in6[b / 8] ^= 1U << (7 - b % 8);
|
||||||
|
} else {
|
||||||
|
assert(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static double
|
||||||
|
read_frequency(void)
|
||||||
|
{
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static double
|
||||||
|
set_frequency(double freq_ppm)
|
||||||
|
{
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
accrue_offset(double offset, double corr_rate)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
apply_step_offset(double offset)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
offset_convert(struct timeval *raw, double *corr, double *err)
|
||||||
|
{
|
||||||
|
*corr = 0.0;
|
||||||
|
if (err)
|
||||||
|
*err = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
TST_RegisterDummyDrivers(void)
|
||||||
|
{
|
||||||
|
lcl_RegisterSystemDrivers(read_frequency, set_frequency, accrue_offset,
|
||||||
|
apply_step_offset, offset_convert, NULL, NULL);
|
||||||
|
}
|
||||||
43
test/unit/test.h
Normal file
43
test/unit/test.h
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
**********************************************************************
|
||||||
|
* Copyright (C) Miroslav Lichvar 2016
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of version 2 of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef GOT_TEST_H
|
||||||
|
#define GOT_TEST_H
|
||||||
|
|
||||||
|
#include <addressing.h>
|
||||||
|
|
||||||
|
extern void test_unit(void);
|
||||||
|
|
||||||
|
#define TEST_CHECK(expr) \
|
||||||
|
do { \
|
||||||
|
if (!(expr)) { \
|
||||||
|
TST_Fail(__LINE__); \
|
||||||
|
exit(1); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
extern void TST_Fail(int line);
|
||||||
|
|
||||||
|
extern double TST_GetRandomDouble(double min, double max);
|
||||||
|
extern void TST_GetRandomAddress(IPAddr *ip, int family, int bits);
|
||||||
|
extern void TST_SwapAddressBit(IPAddr *ip, unsigned int b);
|
||||||
|
extern void TST_RegisterDummyDrivers(void);
|
||||||
|
|
||||||
|
#endif
|
||||||
13
util.c
13
util.c
@@ -362,6 +362,7 @@ UTI_IPToRefid(IPAddr *ip)
|
|||||||
uint32_t
|
uint32_t
|
||||||
UTI_IPToHash(IPAddr *ip)
|
UTI_IPToHash(IPAddr *ip)
|
||||||
{
|
{
|
||||||
|
static uint32_t seed = 0;
|
||||||
unsigned char *addr;
|
unsigned char *addr;
|
||||||
unsigned int i, len;
|
unsigned int i, len;
|
||||||
uint32_t hash;
|
uint32_t hash;
|
||||||
@@ -379,10 +380,15 @@ UTI_IPToHash(IPAddr *ip)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0, hash = 0; i < len; i++)
|
/* Include a random seed in the hash to randomize collisions
|
||||||
|
and order of addresses in hash tables */
|
||||||
|
while (!seed)
|
||||||
|
UTI_GetRandomBytes(&seed, sizeof (seed));
|
||||||
|
|
||||||
|
for (i = 0, hash = seed; i < len; i++)
|
||||||
hash = 71 * hash + addr[i];
|
hash = 71 * hash + addr[i];
|
||||||
|
|
||||||
return hash;
|
return hash + seed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -801,9 +807,10 @@ UTI_FloatNetworkToHost(Float f)
|
|||||||
|
|
||||||
x = ntohl(f.f);
|
x = ntohl(f.f);
|
||||||
|
|
||||||
exp = (x >> FLOAT_COEF_BITS) - FLOAT_COEF_BITS;
|
exp = x >> FLOAT_COEF_BITS;
|
||||||
if (exp >= 1 << (FLOAT_EXP_BITS - 1))
|
if (exp >= 1 << (FLOAT_EXP_BITS - 1))
|
||||||
exp -= 1 << FLOAT_EXP_BITS;
|
exp -= 1 << FLOAT_EXP_BITS;
|
||||||
|
exp -= FLOAT_COEF_BITS;
|
||||||
|
|
||||||
coef = x % (1U << FLOAT_COEF_BITS);
|
coef = x % (1U << FLOAT_COEF_BITS);
|
||||||
if (coef >= 1 << (FLOAT_COEF_BITS - 1))
|
if (coef >= 1 << (FLOAT_COEF_BITS - 1))
|
||||||
|
|||||||
Reference in New Issue
Block a user