mirror of
https://gitlab.com/chrony/chrony.git
synced 2025-12-04 01:25:07 -05:00
Compare commits
231 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b5658f4d9c | ||
|
|
ad58baa13b | ||
|
|
c6fdeeb6bb | ||
|
|
7712455d9a | ||
|
|
a9a5f98406 | ||
|
|
9ac8f64d89 | ||
|
|
0da5cf9163 | ||
|
|
f6a39d75a7 | ||
|
|
25aa9f5b42 | ||
|
|
829b3adac3 | ||
|
|
4847a3a259 | ||
|
|
551541d9c8 | ||
|
|
f996f4c9fb | ||
|
|
ac78ad60f3 | ||
|
|
42d7cf8922 | ||
|
|
e811ba7b4c | ||
|
|
cb464cac4d | ||
|
|
fa409ddc8f | ||
|
|
821226e473 | ||
|
|
0e298bedf6 | ||
|
|
aa76760268 | ||
|
|
8bf87bbfde | ||
|
|
38e889c85c | ||
|
|
d5b737cce8 | ||
|
|
6ba764b5be | ||
|
|
707b857b68 | ||
|
|
f8d609fee5 | ||
|
|
01f797ac05 | ||
|
|
6fa11a853a | ||
|
|
9c78ad708b | ||
|
|
57f8160d6c | ||
|
|
8d80ce444f | ||
|
|
95c3acf67e | ||
|
|
561f7a66dd | ||
|
|
0193688671 | ||
|
|
6d7605a3d0 | ||
|
|
e0171f6e96 | ||
|
|
4ef1c6f2c8 | ||
|
|
f7e2d7c2ec | ||
|
|
3d1be1cd75 | ||
|
|
2d509eb8bd | ||
|
|
6ca73bf670 | ||
|
|
f7802f0111 | ||
|
|
2f3ef235a1 | ||
|
|
1ad22e9a02 | ||
|
|
6d2fb9f782 | ||
|
|
22e5ed44c2 | ||
|
|
9666831818 | ||
|
|
ff8e04f9ba | ||
|
|
52272f4dc5 | ||
|
|
18a66a2ba8 | ||
|
|
8aa9eb19c8 | ||
|
|
62027f1b47 | ||
|
|
41805d572f | ||
|
|
58f768928a | ||
|
|
0074135097 | ||
|
|
8eb7ce8581 | ||
|
|
2ceb3c89ca | ||
|
|
d46e2a69a1 | ||
|
|
20f9454be3 | ||
|
|
8092366897 | ||
|
|
066254b6c8 | ||
|
|
79811bf3e2 | ||
|
|
32bf32e7d5 | ||
|
|
df968ca47c | ||
|
|
cce7a5f15e | ||
|
|
288043c13b | ||
|
|
78ae4ebfaa | ||
|
|
cf700a0084 | ||
|
|
60a25f6e71 | ||
|
|
3eff836b2e | ||
|
|
2b9fe764d5 | ||
|
|
030e3b2dab | ||
|
|
5079f6bbff | ||
|
|
afceb9d24e | ||
|
|
a2656a20bc | ||
|
|
359d444343 | ||
|
|
d510154ba2 | ||
|
|
1c901b82dc | ||
|
|
ea3672df4e | ||
|
|
72d0b3c913 | ||
|
|
51a2d8dfd8 | ||
|
|
bc25380950 | ||
|
|
ae1e3bf73c | ||
|
|
9673a2726c | ||
|
|
02524397c1 | ||
|
|
5e5dde1a67 | ||
|
|
0f8def4ca4 | ||
|
|
182ec04e24 | ||
|
|
ebae435398 | ||
|
|
52657945d8 | ||
|
|
12166f8a47 | ||
|
|
c5f1dd8615 | ||
|
|
10e67e3c1d | ||
|
|
4e8ceaae86 | ||
|
|
73d4eaafbb | ||
|
|
cf00179964 | ||
|
|
edda0c60b3 | ||
|
|
f2eb6b165a | ||
|
|
4933c216b2 | ||
|
|
0655def57f | ||
|
|
6eafff2450 | ||
|
|
0bb772c575 | ||
|
|
b261693095 | ||
|
|
129db63e30 | ||
|
|
1759d89d8a | ||
|
|
0540b17fb9 | ||
|
|
8893dda350 | ||
|
|
b14689d59b | ||
|
|
1ca844af98 | ||
|
|
3059747c35 | ||
|
|
bbbb3633a7 | ||
|
|
df6c2a432f | ||
|
|
d0acfc2652 | ||
|
|
711cda6aed | ||
|
|
0c738d84af | ||
|
|
be1e1dc441 | ||
|
|
2a305d8e16 | ||
|
|
15b6ab77ea | ||
|
|
6199822783 | ||
|
|
0b72b2940a | ||
|
|
d4ce3f19c3 | ||
|
|
824e86a82f | ||
|
|
2a5c045c3d | ||
|
|
f7c65a4b88 | ||
|
|
a8956f2f56 | ||
|
|
91c9f84a01 | ||
|
|
2be89bc6f2 | ||
|
|
d6c447a445 | ||
|
|
a60586eaad | ||
|
|
d77356837a | ||
|
|
d6842301dd | ||
|
|
19b3c5be26 | ||
|
|
5fb5a89f02 | ||
|
|
9367e7b9af | ||
|
|
6673cadfa2 | ||
|
|
b485051b65 | ||
|
|
9a01ccc07f | ||
|
|
1b8deaf354 | ||
|
|
c7d0232bb1 | ||
|
|
79e5f2be13 | ||
|
|
9ab181eb9c | ||
|
|
3cc6021e03 | ||
|
|
375389fa1e | ||
|
|
777303f130 | ||
|
|
6015f99d98 | ||
|
|
78fc17c661 | ||
|
|
d42addf746 | ||
|
|
f570eb76b3 | ||
|
|
cc3f5962b8 | ||
|
|
6ab3d1daa3 | ||
|
|
b088b70f82 | ||
|
|
fbbb6bbc00 | ||
|
|
5c36342958 | ||
|
|
f1a0cacc5a | ||
|
|
1d2a0856b4 | ||
|
|
7fb50d9a3e | ||
|
|
919b5b5a7d | ||
|
|
1e35b26826 | ||
|
|
27b0b5824a | ||
|
|
1d72d22bc5 | ||
|
|
e0c9ed44f9 | ||
|
|
411f4da340 | ||
|
|
4fac84098e | ||
|
|
21b2063a6f | ||
|
|
917c191650 | ||
|
|
2bfce03d29 | ||
|
|
1cb8167be0 | ||
|
|
40d33cc64d | ||
|
|
95433e9639 | ||
|
|
bbe1a09e7e | ||
|
|
dce2366b3a | ||
|
|
bab7ba22cf | ||
|
|
d6a91057ae | ||
|
|
c6e9065498 | ||
|
|
22fda21eae | ||
|
|
103a520aa6 | ||
|
|
86531a51a7 | ||
|
|
2b7e4d645f | ||
|
|
a5f63180fc | ||
|
|
934d4e04b5 | ||
|
|
1b8547059a | ||
|
|
91279a0f28 | ||
|
|
31ba3144c8 | ||
|
|
0bf34725e3 | ||
|
|
91749ebb2b | ||
|
|
4ba3dd66ad | ||
|
|
d40696f7f3 | ||
|
|
4a401a9e83 | ||
|
|
6a2a837ede | ||
|
|
eca08a281c | ||
|
|
9fd8f76fa0 | ||
|
|
50de930730 | ||
|
|
da1097095c | ||
|
|
ec7d302a6c | ||
|
|
8cc7ebffa9 | ||
|
|
de4d14843f | ||
|
|
18605795a7 | ||
|
|
da2c8d9076 | ||
|
|
3120f8adb6 | ||
|
|
2dcc16169b | ||
|
|
a8efd8c398 | ||
|
|
bb40f4aff4 | ||
|
|
66c7ac4d24 | ||
|
|
7f12919fea | ||
|
|
55e0c6a0a1 | ||
|
|
20f306602b | ||
|
|
70735d8d79 | ||
|
|
165e6805ab | ||
|
|
2a0c35646c | ||
|
|
28710e0449 | ||
|
|
c5587b60b2 | ||
|
|
bb95c39356 | ||
|
|
20a43409c6 | ||
|
|
4699f7ca0b | ||
|
|
bc7586b3f4 | ||
|
|
8d3d45ea1a | ||
|
|
21ba1d3761 | ||
|
|
e79584bb9e | ||
|
|
bca7819247 | ||
|
|
0ecabae2c3 | ||
|
|
598c04eea2 | ||
|
|
faec23f6bd | ||
|
|
896dad9224 | ||
|
|
680612cf09 | ||
|
|
3fbd4bb15f | ||
|
|
cb9055072d | ||
|
|
0fc9b555f1 | ||
|
|
6ed58628f5 | ||
|
|
efff149988 | ||
|
|
b02d4092f1 |
15
.gitignore
vendored
15
.gitignore
vendored
@@ -1,6 +1,19 @@
|
|||||||
*.swp
|
.deps
|
||||||
|
.vimrc
|
||||||
*.o
|
*.o
|
||||||
|
*.swp
|
||||||
|
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.log
|
||||||
|
tags
|
||||||
version.h
|
version.h
|
||||||
|
|||||||
12
INSTALL
12
INSTALL
@@ -81,12 +81,14 @@ Now that the software is successfully installed, the next step is to
|
|||||||
set up a configuration file. The contents of this depend on the
|
set up a configuration file. The contents of this depend on the
|
||||||
network environment in which the computer operates. Typical scenarios
|
network environment in which the computer operates. Typical scenarios
|
||||||
are described in the manual. The simplest case is for a computer with
|
are described in the manual. The simplest case is for a computer with
|
||||||
a permanent Internet connection - suppose you want to use the NTP
|
a permanent Internet connection - suppose you want to use public NTP
|
||||||
server ntp1.foobar.com as your time reference. You would create an
|
servers from the pool.ntp.org project as your time reference. You would
|
||||||
/etc/chrony.conf file containing
|
create an /etc/chrony.conf file containing
|
||||||
|
|
||||||
server ntp1.foobar.com
|
server 0.pool.ntp.org
|
||||||
driftfile /etc/chrony.drift
|
server 1.pool.ntp.org
|
||||||
|
server 2.pool.ntp.org
|
||||||
|
driftfile /var/lib/chrony/drift
|
||||||
|
|
||||||
and then run /usr/local/sbin/chronyd.
|
and then run /usr/local/sbin/chronyd.
|
||||||
|
|
||||||
|
|||||||
67
Makefile.in
67
Makefile.in
@@ -27,32 +27,32 @@ SBINDIR=@SBINDIR@
|
|||||||
MANDIR=@MANDIR@
|
MANDIR=@MANDIR@
|
||||||
INFODIR=@INFODIR@
|
INFODIR=@INFODIR@
|
||||||
DOCDIR=@DOCDIR@
|
DOCDIR=@DOCDIR@
|
||||||
|
LOCALSTATEDIR=@LOCALSTATEDIR@
|
||||||
|
CHRONYVARDIR=@CHRONYVARDIR@
|
||||||
|
|
||||||
CC = @CC@
|
CC = @CC@
|
||||||
CCWARNFLAGS = @CCWARNFLAGS@
|
CFLAGS = @CFLAGS@
|
||||||
OPTFLAGS = @CFLAGS@
|
CPPFLAGS = @CPPFLAGS@
|
||||||
CPPFLAGS = @CPPFLAGS@ @SYSDEFS@ @EXTRA_DEFS@
|
|
||||||
|
|
||||||
DESTDIR=
|
DESTDIR=
|
||||||
|
|
||||||
|
HASH_OBJ = @HASH_OBJ@
|
||||||
|
|
||||||
OBJS = util.o sched.o regress.o local.o \
|
OBJS = util.o sched.o regress.o local.o \
|
||||||
sys.o main.o ntp_io.o ntp_core.o ntp_sources.o \
|
sys.o main.o ntp_io.o ntp_core.o ntp_sources.o \
|
||||||
sources.o sourcestats.o reference.o \
|
sources.o sourcestats.o reference.o \
|
||||||
logging.o conf.o cmdmon.o md5.o keys.o \
|
logging.o conf.o cmdmon.o keys.o \
|
||||||
nameserv.o acquire.o manual.o addrfilt.o \
|
nameserv.o acquire.o manual.o addrfilt.o \
|
||||||
cmdparse.o mkdirpp.o rtc.o pktlength.o clientlog.o \
|
cmdparse.o mkdirpp.o rtc.o pktlength.o clientlog.o \
|
||||||
broadcast.o refclock.o refclock_shm.o refclock_sock.o \
|
broadcast.o refclock.o refclock_shm.o refclock_sock.o \
|
||||||
refclock_pps.o tempcomp.o
|
refclock_pps.o tempcomp.o $(HASH_OBJ)
|
||||||
|
|
||||||
EXTRA_OBJS=@EXTRA_OBJECTS@
|
EXTRA_OBJS=@EXTRA_OBJECTS@
|
||||||
|
|
||||||
CLI_OBJS = client.o md5.o nameserv.o getdate.o cmdparse.o \
|
CLI_OBJS = client.o nameserv.o getdate.o cmdparse.o \
|
||||||
pktlength.o util.o
|
pktlength.o util.o $(HASH_OBJ)
|
||||||
|
|
||||||
SRCS = $(patsubst %.o,%.c,$(OBJS))
|
ALL_OBJS = $(OBJS) $(EXTRA_OBJS) $(CLI_OBJS)
|
||||||
EXTRA_SRCS = $(patsubst %.o,%.c,$(EXTRA_OBJS))
|
|
||||||
|
|
||||||
CLI_SRCS = $(patsubst %.o,%.c,$(CLI_OBJS))
|
|
||||||
|
|
||||||
LDFLAGS = @LDFLAGS@
|
LDFLAGS = @LDFLAGS@
|
||||||
LIBS = @LIBS@
|
LIBS = @LIBS@
|
||||||
@@ -60,36 +60,30 @@ LIBS = @LIBS@
|
|||||||
EXTRA_LIBS=@EXTRA_LIBS@
|
EXTRA_LIBS=@EXTRA_LIBS@
|
||||||
EXTRA_CLI_LIBS=@EXTRA_CLI_LIBS@
|
EXTRA_CLI_LIBS=@EXTRA_CLI_LIBS@
|
||||||
|
|
||||||
CFLAGS = $(CCWARNFLAGS) $(OPTFLAGS)
|
|
||||||
|
|
||||||
# Until we have a main procedure we can link, just build object files
|
# Until we have a main procedure we can link, just build object files
|
||||||
# to test compilation
|
# to test compilation
|
||||||
|
|
||||||
all : chronyd chronyc
|
all : chronyd chronyc
|
||||||
|
|
||||||
chronyd : $(OBJS) $(EXTRA_OBJS)
|
chronyd : $(OBJS) $(EXTRA_OBJS)
|
||||||
$(CC) $(OPTFLAGS) -o chronyd $(OBJS) $(EXTRA_OBJS) $(LDFLAGS) $(LIBS) $(EXTRA_LIBS)
|
$(CC) $(CFLAGS) -o chronyd $(OBJS) $(EXTRA_OBJS) $(LDFLAGS) @HASH_LINK@ $(LIBS) $(EXTRA_LIBS)
|
||||||
|
|
||||||
chronyc : $(CLI_OBJS)
|
chronyc : $(CLI_OBJS)
|
||||||
$(CC) $(OPTFLAGS) -o chronyc $(CLI_OBJS) $(LDFLAGS) @READLINE_LINK@ $(LIBS) $(EXTRA_CLI_LIBS)
|
$(CC) $(CFLAGS) -o chronyc $(CLI_OBJS) $(LDFLAGS) @READLINE_LINK@ @HASH_LINK@ $(LIBS) $(EXTRA_CLI_LIBS)
|
||||||
|
|
||||||
conf.o : conf.c
|
|
||||||
$(CC) $(CFLAGS) $(CPPFLAGS) -DDEFAULT_CONF_DIR=\"$(SYSCONFDIR)\" -c $<
|
|
||||||
|
|
||||||
client.o : client.c
|
client.o : client.c
|
||||||
$(CC) $(CFLAGS) $(CPPFLAGS) @READLINE_COMPILE@ -c $<
|
$(CC) $(CFLAGS) $(CPPFLAGS) @READLINE_COMPILE@ -c $<
|
||||||
|
|
||||||
.depend :
|
$(HASH_OBJ) : $(patsubst %.o,%.c,$(HASH_OBJ))
|
||||||
gcc -MM $(SRCS) $(EXTRA_SRCS) > .depend
|
$(CC) $(CFLAGS) $(CPPFLAGS) @HASH_COMPILE@ -c $<
|
||||||
|
|
||||||
distclean :
|
distclean : clean
|
||||||
-rm -f *.o *.s chronyc chronyd core options.h Makefile *~
|
-rm -f Makefile
|
||||||
|
-rm -f chrony.conf.5 chrony.texi chronyc.1 chronyd.8
|
||||||
|
|
||||||
clean :
|
clean :
|
||||||
-rm -f *.o *.s chronyc chronyd core *~
|
-rm -f *.o *.s chronyc chronyd core *~ chrony.info chrony.html chrony.txt
|
||||||
|
-rm -rf .deps
|
||||||
version.h : version.txt
|
|
||||||
./mkversion
|
|
||||||
|
|
||||||
getdate.c : ;
|
getdate.c : ;
|
||||||
getdate :
|
getdate :
|
||||||
@@ -99,6 +93,7 @@ getdate :
|
|||||||
# seem to vary between systems.
|
# seem to vary between systems.
|
||||||
|
|
||||||
install: chronyd chronyc
|
install: chronyd chronyc
|
||||||
|
[ -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)$(DOCDIR) ] || mkdir -p $(DESTDIR)$(DOCDIR)
|
[ -d $(DESTDIR)$(DOCDIR) ] || mkdir -p $(DESTDIR)$(DOCDIR)
|
||||||
@@ -106,6 +101,7 @@ install: chronyd chronyc
|
|||||||
[ -d $(DESTDIR)$(MANDIR)/man5 ] || mkdir -p $(DESTDIR)$(MANDIR)/man5
|
[ -d $(DESTDIR)$(MANDIR)/man5 ] || mkdir -p $(DESTDIR)$(MANDIR)/man5
|
||||||
[ -d $(DESTDIR)$(MANDIR)/man8 ] || mkdir -p $(DESTDIR)$(MANDIR)/man8
|
[ -d $(DESTDIR)$(MANDIR)/man8 ] || mkdir -p $(DESTDIR)$(MANDIR)/man8
|
||||||
[ -d $(DESTDIR)$(DOCDIR) ] || mkdir -p $(DESTDIR)$(DOCDIR)
|
[ -d $(DESTDIR)$(DOCDIR) ] || mkdir -p $(DESTDIR)$(DOCDIR)
|
||||||
|
[ -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
|
||||||
cp chronyd $(DESTDIR)$(SBINDIR)/chronyd
|
cp chronyd $(DESTDIR)$(SBINDIR)/chronyd
|
||||||
@@ -133,11 +129,6 @@ install: chronyd chronyc
|
|||||||
%.s : %.c
|
%.s : %.c
|
||||||
$(CC) $(CFLAGS) $(CPPFLAGS) -S $<
|
$(CC) $(CFLAGS) $(CPPFLAGS) -S $<
|
||||||
|
|
||||||
main.o logging.o client.o : version.h
|
|
||||||
|
|
||||||
# makeinfo v4 required to generate plain text and html
|
|
||||||
MAKEINFO:=makeinfo
|
|
||||||
|
|
||||||
install-docs : docs
|
install-docs : docs
|
||||||
[ -d $(DESTDIR)$(DOCDIR) ] || mkdir -p $(DESTDIR)$(DOCDIR)
|
[ -d $(DESTDIR)$(DOCDIR) ] || mkdir -p $(DESTDIR)$(DOCDIR)
|
||||||
cp chrony.txt $(DESTDIR)$(DOCDIR)/chrony.txt
|
cp chrony.txt $(DESTDIR)$(DOCDIR)/chrony.txt
|
||||||
@@ -151,15 +142,23 @@ install-docs : docs
|
|||||||
docs : chrony.txt chrony.html chrony.info
|
docs : chrony.txt chrony.html chrony.info
|
||||||
|
|
||||||
chrony.txt : chrony.texi
|
chrony.txt : chrony.texi
|
||||||
$(MAKEINFO) --no-headers --number-sections -o chrony.txt chrony.texi
|
makeinfo --no-headers --number-sections -o chrony.txt chrony.texi
|
||||||
|
|
||||||
chrony.html : chrony.texi
|
chrony.html : chrony.texi
|
||||||
$(MAKEINFO) --no-split --html --number-sections -o 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
|
chrony.info : chrony.texi
|
||||||
$(MAKEINFO) chrony.texi
|
makeinfo chrony.texi
|
||||||
|
|
||||||
# This is only relevant if you're maintaining the website!
|
# This is only relevant if you're maintaining the website!
|
||||||
faq.php : faq.txt faqgen.pl
|
faq.php : faq.txt faqgen.pl
|
||||||
perl faqgen.pl < faq.txt > faq.php
|
perl faqgen.pl < faq.txt > faq.php
|
||||||
|
|
||||||
|
.deps:
|
||||||
|
@mkdir .deps
|
||||||
|
|
||||||
|
.deps/%.d: %.c | .deps
|
||||||
|
@$(CC) -MM $(CPPFLAGS) -MT '$(<:%.c=%.o) $@' $< -o $@
|
||||||
|
|
||||||
|
-include $(ALL_OBJS:%.o=.deps/%.d)
|
||||||
|
|||||||
73
NEWS
73
NEWS
@@ -1,3 +1,70 @@
|
|||||||
|
New in version 1.29
|
||||||
|
===================
|
||||||
|
|
||||||
|
Security fixes
|
||||||
|
--------------
|
||||||
|
* Fix crash when processing crafted commands (CVE-2012-4502)
|
||||||
|
(possible with IP addresses allowed by cmdallow and localhost)
|
||||||
|
* Don't send uninitialized data in SUBNETS_ACCESSED and CLIENT_ACCESSES
|
||||||
|
replies (CVE-2012-4503) (not used by chronyc)
|
||||||
|
|
||||||
|
Other changes
|
||||||
|
-------------
|
||||||
|
* Drop support for SUBNETS_ACCESSED and CLIENT_ACCESSES commands
|
||||||
|
|
||||||
|
New in version 1.28
|
||||||
|
===================
|
||||||
|
|
||||||
|
* Combine sources to improve accuracy
|
||||||
|
* Make config and command parser strict
|
||||||
|
* Add -a option to chronyc to authenticate automatically
|
||||||
|
* Add -R option to ignore initstepslew and makestep directives
|
||||||
|
* Add generatecommandkey, minsamples, maxsamples and user directives
|
||||||
|
* Improve compatibility with NTPv1 and NTPv2 clients
|
||||||
|
* Create sockets only in selected family with -4/-6 option
|
||||||
|
* Treat address bind errors as non-fatal
|
||||||
|
* Extend tracking log
|
||||||
|
* Accept float values as initstepslew threshold
|
||||||
|
* Allow hostnames in offline, online and burst commands
|
||||||
|
* Fix and improve peer polling
|
||||||
|
* Fix crash in config parsing with too many servers
|
||||||
|
* Fix crash with duplicated initstepslew address
|
||||||
|
* Fix delta calculation with extreme frequency offsets
|
||||||
|
* Set local stratum correctly
|
||||||
|
* Remove unnecessary adjtimex calls
|
||||||
|
* Set paths in documentation by configure
|
||||||
|
* Update chrony.spec
|
||||||
|
|
||||||
|
New in version 1.27
|
||||||
|
===================
|
||||||
|
|
||||||
|
* Support for stronger keys via NSS or libtomcrypt library
|
||||||
|
* Support reading leap second data from tz database
|
||||||
|
* Support for precise clock stepping on Linux
|
||||||
|
* Support for nanoseconds in SHM refclock
|
||||||
|
* Make offset corrections smoother on Linux
|
||||||
|
* Make transmit timestamps random below clock precision
|
||||||
|
* Add corrtimeratio and maxchange directives
|
||||||
|
* Extend tracking, sources and activity reports
|
||||||
|
* Wait in foreground process until daemon is fully initialized
|
||||||
|
* Fix crash with slow name resolving
|
||||||
|
* Fix iburst with jittery sources
|
||||||
|
* Fix offset stored in rtc data right after trimrtc
|
||||||
|
* Fix crash and hang with RTC or manual samples
|
||||||
|
* Don't use readonly adjtime on Linux kernels before 2.6.28
|
||||||
|
* Changed chronyc protocol, incompatible with older versions
|
||||||
|
|
||||||
|
New in version 1.26
|
||||||
|
===================
|
||||||
|
|
||||||
|
* Add compatibility with Linux 3.0 and later
|
||||||
|
* Use proper source address in NTP replies on multihomed IPv6 hosts
|
||||||
|
* Accept NTP packets with versions 4, 3 and 2
|
||||||
|
* Cope with unexpected backward time jumps
|
||||||
|
* Don't reset kernel frequency on start without drift file
|
||||||
|
* Retry on permanent DNS error by default
|
||||||
|
* Add waitsync command
|
||||||
|
|
||||||
New in version 1.25
|
New in version 1.25
|
||||||
===================
|
===================
|
||||||
|
|
||||||
@@ -6,6 +73,7 @@ New in version 1.25
|
|||||||
* Improve polling interval adjustment
|
* Improve polling interval adjustment
|
||||||
* Improve stability with temporary asymmetric delays
|
* Improve stability with temporary asymmetric delays
|
||||||
* Improve source selection
|
* Improve source selection
|
||||||
|
* Improve initial synchronisation
|
||||||
* Add delayed server name resolving
|
* Add delayed server name resolving
|
||||||
* Add temperature compensation
|
* Add temperature compensation
|
||||||
* Add nanosecond slewing to Linux driver
|
* Add nanosecond slewing to Linux driver
|
||||||
@@ -13,7 +81,8 @@ New in version 1.25
|
|||||||
* Add iburst, minstratum, maxdelaydevratio, polltarget,
|
* Add iburst, minstratum, maxdelaydevratio, polltarget,
|
||||||
prefer, noselect options
|
prefer, noselect options
|
||||||
* Add rtcsync directive to enable Linux 11-minute mode
|
* Add rtcsync directive to enable Linux 11-minute mode
|
||||||
* Add reselectdist, stratumweight, logbanner, maxclockerror directives
|
* Add reselectdist, stratumweight, logbanner, maxclockerror,
|
||||||
|
include directives
|
||||||
* Add -n option to not detach daemon from terminal
|
* Add -n option to not detach daemon from terminal
|
||||||
* Fix pidfile directive
|
* Fix pidfile directive
|
||||||
* Fix name resolving with disabled IPv6 support
|
* Fix name resolving with disabled IPv6 support
|
||||||
@@ -23,9 +92,9 @@ New in version 1.25
|
|||||||
* Fix file descriptor leaks
|
* Fix file descriptor leaks
|
||||||
* Increase burst polling interval and stop on KoD RATE
|
* Increase burst polling interval and stop on KoD RATE
|
||||||
* Set maxupdateskew to 1000 ppm by default
|
* Set maxupdateskew to 1000 ppm by default
|
||||||
* Consider offline sources unreachable
|
|
||||||
* Require password for clients command
|
* Require password for clients command
|
||||||
* Update drift file at most once per hour
|
* Update drift file at most once per hour
|
||||||
|
* Use system headers for Linux RTC support
|
||||||
* Reduce default chronyc timeout and make it configurable
|
* Reduce default chronyc timeout and make it configurable
|
||||||
* Avoid large values in chronyc sources and sourcestats output
|
* Avoid large values in chronyc sources and sourcestats output
|
||||||
* Add reselect command to force reselecting best source
|
* Add reselect command to force reselecting best source
|
||||||
|
|||||||
21
README
21
README
@@ -10,7 +10,7 @@ time. This does most of the work.
|
|||||||
|
|
||||||
chronyc is a command-line interface program which can be used to
|
chronyc is a command-line interface program which can be used to
|
||||||
monitor chronyd's performance and to change various operating
|
monitor chronyd's performance and to change various operating
|
||||||
parateters whilst it is running.
|
parameters whilst it is running.
|
||||||
|
|
||||||
chronyd's main function is to obtain measurements of the true (UTC)
|
chronyd's main function is to obtain measurements of the true (UTC)
|
||||||
time from one of several sources, and correct the system clock
|
time from one of several sources, and correct the system clock
|
||||||
@@ -21,12 +21,12 @@ between measurements from the reference.
|
|||||||
The reference time can be derived from Network Time Protocol (NTP)
|
The reference time can be derived from Network Time Protocol (NTP)
|
||||||
servers, reference clocks, or wristwatch-and-keyboard (via chronyc).
|
servers, reference clocks, or wristwatch-and-keyboard (via chronyc).
|
||||||
The main source of information about the Network Time Protocol is
|
The main source of information about the Network Time Protocol is
|
||||||
http://www.eecis.udel.edu/~ntp.
|
http://www.ntp.org.
|
||||||
|
|
||||||
It is designed so that it can work on computers which only have
|
It is designed so that it can work on computers which only have
|
||||||
intermittent access to reference sources, for example computers which
|
intermittent access to reference sources, for example computers which
|
||||||
use a dial-up account to access the Internet. Of course, it will work
|
use a dial-up account to access the Internet or laptops. Of course, it
|
||||||
on computers with permanent connections too.
|
will work well on computers with permanent connections too.
|
||||||
|
|
||||||
In addition, on Linux it can monitor the system's real time clock
|
In addition, on Linux it can monitor the system's real time clock
|
||||||
performance, so the system can maintain accurate time even across
|
performance, so the system can maintain accurate time even across
|
||||||
@@ -48,10 +48,7 @@ What will chrony run on?
|
|||||||
|
|
||||||
Chrony can be successfully built and run on
|
Chrony can be successfully built and run on
|
||||||
|
|
||||||
1. Linux v1.2.13, v2.0.x, 2.1.x (partially), 2.2.x, 2.3.x, 2.4.x, 2.6.x.
|
1. Linux 2.2.x, 2.3.x, 2.4.x, 2.6.x, 3.x
|
||||||
Real time clock support is limited to 2.0.32 onwards and to 2.2, 2.3,
|
|
||||||
2.4 and 2.6 series only. i386, x86_64, PowerPC are known to be
|
|
||||||
supported.
|
|
||||||
|
|
||||||
2. Solaris 2.5/2.5.1/2.6/2.7/2.8 (various platforms)
|
2. Solaris 2.5/2.5.1/2.6/2.7/2.8 (various platforms)
|
||||||
|
|
||||||
@@ -88,12 +85,6 @@ through the URL
|
|||||||
|
|
||||||
http://chrony.tuxfamily.org/
|
http://chrony.tuxfamily.org/
|
||||||
|
|
||||||
What can chrony not do?
|
|
||||||
=======================
|
|
||||||
|
|
||||||
Compared to the `reference' RFC1305 implementation xntpd, chronyd does
|
|
||||||
not support broadcast modes.
|
|
||||||
|
|
||||||
Where are new versions announced?
|
Where are new versions announced?
|
||||||
=================================
|
=================================
|
||||||
|
|
||||||
@@ -252,5 +243,3 @@ Doug Woodward <dougw@whistler.com>
|
|||||||
|
|
||||||
Many other people have contributed bug reports and suggestions. I'm
|
Many other people have contributed bug reports and suggestions. I'm
|
||||||
sorry I can't identify all of you individually.
|
sorry I can't identify all of you individually.
|
||||||
|
|
||||||
vim:tw=72
|
|
||||||
|
|||||||
76
acquire.c
76
acquire.c
@@ -37,6 +37,8 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
#include "sysincl.h"
|
#include "sysincl.h"
|
||||||
|
|
||||||
#include "acquire.h"
|
#include "acquire.h"
|
||||||
@@ -61,6 +63,10 @@
|
|||||||
|
|
||||||
#define RETRANSMISSION_TIMEOUT (1.0)
|
#define RETRANSMISSION_TIMEOUT (1.0)
|
||||||
|
|
||||||
|
#define NTP_VERSION 3
|
||||||
|
#define NTP_MAX_COMPAT_VERSION 4
|
||||||
|
#define NTP_MIN_COMPAT_VERSION 2
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
IPAddr ip_addr; /* Address of the server */
|
IPAddr ip_addr; /* Address of the server */
|
||||||
int sanity; /* Flag indicating whether source
|
int sanity; /* Flag indicating whether source
|
||||||
@@ -88,7 +94,7 @@ static int n_sources;
|
|||||||
static int n_started_sources;
|
static int n_started_sources;
|
||||||
static int n_completed_sources;
|
static int n_completed_sources;
|
||||||
|
|
||||||
static int init_slew_threshold = -1;
|
static double init_slew_threshold;
|
||||||
|
|
||||||
union sockaddr_in46 {
|
union sockaddr_in46 {
|
||||||
struct sockaddr_in in4;
|
struct sockaddr_in in4;
|
||||||
@@ -137,7 +143,6 @@ static SCH_TimeoutID source_start_timeout_id;
|
|||||||
void
|
void
|
||||||
ACQ_Initialise(void)
|
ACQ_Initialise(void)
|
||||||
{
|
{
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -146,7 +151,6 @@ ACQ_Initialise(void)
|
|||||||
void
|
void
|
||||||
ACQ_Finalise(void)
|
ACQ_Finalise(void)
|
||||||
{
|
{
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -195,7 +199,7 @@ prepare_socket(int family)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (bind(sock_fd, &my_addr.u, addrlen) < 0) {
|
if (bind(sock_fd, &my_addr.u, addrlen) < 0) {
|
||||||
LOG(LOGS_ERR, LOGF_Acquire, "Could not bind socket : %s\n", strerror(errno));
|
LOG(LOGS_ERR, LOGF_Acquire, "Could not bind socket : %s", strerror(errno));
|
||||||
/* but keep running */
|
/* but keep running */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -234,8 +238,6 @@ finalise_io(void)
|
|||||||
}
|
}
|
||||||
sock_fd6 = -1;
|
sock_fd6 = -1;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -244,12 +246,13 @@ static void
|
|||||||
probe_source(SourceRecord *src)
|
probe_source(SourceRecord *src)
|
||||||
{
|
{
|
||||||
NTP_Packet pkt;
|
NTP_Packet pkt;
|
||||||
int version = 3;
|
int version = NTP_VERSION;
|
||||||
NTP_Mode my_mode = MODE_CLIENT;
|
NTP_Mode my_mode = MODE_CLIENT;
|
||||||
struct timeval cooked;
|
struct timeval cooked;
|
||||||
union sockaddr_in46 his_addr;
|
union sockaddr_in46 his_addr;
|
||||||
int sock_fd;
|
int sock_fd;
|
||||||
socklen_t addrlen;
|
socklen_t addrlen;
|
||||||
|
uint32_t ts_fuzz;
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
printf("Sending probe to %s sent=%d samples=%d\n", UTI_IPToString(&src->ip_addr), src->n_probes_sent, src->n_samples);
|
printf("Sending probe to %s sent=%d samples=%d\n", UTI_IPToString(&src->ip_addr), src->n_probes_sent, src->n_samples);
|
||||||
@@ -262,9 +265,9 @@ probe_source(SourceRecord *src)
|
|||||||
pkt.stratum = 0;
|
pkt.stratum = 0;
|
||||||
pkt.poll = 4;
|
pkt.poll = 4;
|
||||||
pkt.precision = -6; /* as ntpdate */
|
pkt.precision = -6; /* as ntpdate */
|
||||||
pkt.root_delay = double_to_int32(1.0); /* 1 second */
|
pkt.root_delay = UTI_DoubleToInt32(1.0); /* 1 second */
|
||||||
pkt.root_dispersion = double_to_int32(1.0); /* likewise */
|
pkt.root_dispersion = UTI_DoubleToInt32(1.0); /* likewise */
|
||||||
pkt.reference_id = 0UL;
|
pkt.reference_id = 0;
|
||||||
pkt.reference_ts.hi = 0; /* Set to 0 */
|
pkt.reference_ts.hi = 0; /* Set to 0 */
|
||||||
pkt.reference_ts.lo = 0; /* Set to 0 */
|
pkt.reference_ts.lo = 0; /* Set to 0 */
|
||||||
pkt.originate_ts.hi = 0; /* Set to 0 */
|
pkt.originate_ts.hi = 0; /* Set to 0 */
|
||||||
@@ -298,8 +301,9 @@ probe_source(SourceRecord *src)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ts_fuzz = UTI_GetNTPTsFuzz(LCL_GetSysPrecisionAsLog());
|
||||||
LCL_ReadCookedTime(&cooked, NULL);
|
LCL_ReadCookedTime(&cooked, NULL);
|
||||||
UTI_TimevalToInt64(&cooked, &pkt.transmit_ts);
|
UTI_TimevalToInt64(&cooked, &pkt.transmit_ts, ts_fuzz);
|
||||||
|
|
||||||
if (sendto(sock_fd, (void *) &pkt, NTP_NORMAL_PACKET_SIZE,
|
if (sendto(sock_fd, (void *) &pkt, NTP_NORMAL_PACKET_SIZE,
|
||||||
0,
|
0,
|
||||||
@@ -314,8 +318,6 @@ probe_source(SourceRecord *src)
|
|||||||
++(src->n_dead_probes);
|
++(src->n_dead_probes);
|
||||||
src->timer_running = 1;
|
src->timer_running = 1;
|
||||||
src->timeout_id = SCH_AddTimeoutByDelay(RETRANSMISSION_TIMEOUT, transmit_timeout, (void *) src);
|
src->timeout_id = SCH_AddTimeoutByDelay(RETRANSMISSION_TIMEOUT, transmit_timeout, (void *) src);
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -370,7 +372,7 @@ process_receive(NTP_Packet *msg, SourceRecord *src, struct timeval *now)
|
|||||||
mode = lvm & 0x7;
|
mode = lvm & 0x7;
|
||||||
|
|
||||||
if ((leap == LEAP_Unsynchronised) ||
|
if ((leap == LEAP_Unsynchronised) ||
|
||||||
(version != 3) ||
|
(version < NTP_MIN_COMPAT_VERSION || version > NTP_MAX_COMPAT_VERSION) ||
|
||||||
(mode != MODE_SERVER && mode != MODE_PASSIVE)) {
|
(mode != MODE_SERVER && mode != MODE_PASSIVE)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -391,8 +393,8 @@ process_receive(NTP_Packet *msg, SourceRecord *src, struct timeval *now)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
root_delay = int32_to_double(msg->root_delay);
|
root_delay = UTI_Int32ToDouble(msg->root_delay);
|
||||||
root_dispersion = int32_to_double(msg->root_dispersion);
|
root_dispersion = UTI_Int32ToDouble(msg->root_dispersion);
|
||||||
|
|
||||||
UTI_Int64ToTimeval(&src->last_tx, &local_orig);
|
UTI_Int64ToTimeval(&src->last_tx, &local_orig);
|
||||||
UTI_Int64ToTimeval(&msg->receive_ts, &remote_rx);
|
UTI_Int64ToTimeval(&msg->receive_ts, &remote_rx);
|
||||||
@@ -447,7 +449,7 @@ read_from_socket(void *anything)
|
|||||||
his_addr_len = sizeof(his_addr);
|
his_addr_len = sizeof(his_addr);
|
||||||
|
|
||||||
/* Get timestamp */
|
/* Get timestamp */
|
||||||
SCH_GetFileReadyTime(&now, NULL);
|
SCH_GetLastEventTime(&now, NULL, NULL);
|
||||||
|
|
||||||
sock_fd = (long)anything;
|
sock_fd = (long)anything;
|
||||||
status = recvfrom (sock_fd, (char *)&msg, message_length, flags,
|
status = recvfrom (sock_fd, (char *)&msg, message_length, flags,
|
||||||
@@ -693,7 +695,7 @@ process_measurements(void)
|
|||||||
the system clock is fast of the reference, i.e. it needs to be
|
the system clock is fast of the reference, i.e. it needs to be
|
||||||
stepped backwards. */
|
stepped backwards. */
|
||||||
|
|
||||||
if (fabs(estimated_offset) > (double) init_slew_threshold) {
|
if (fabs(estimated_offset) > init_slew_threshold) {
|
||||||
LOG(LOGS_INFO, LOGF_Acquire, "System's initial offset : %.6f seconds %s of true (step)",
|
LOG(LOGS_INFO, LOGF_Acquire, "System's initial offset : %.6f seconds %s of true (step)",
|
||||||
fabs(estimated_offset),
|
fabs(estimated_offset),
|
||||||
(estimated_offset >= 0) ? "fast" : "slow");
|
(estimated_offset >= 0) ? "fast" : "slow");
|
||||||
@@ -702,7 +704,7 @@ process_measurements(void)
|
|||||||
LOG(LOGS_INFO, LOGF_Acquire, "System's initial offset : %.6f seconds %s of true (slew)",
|
LOG(LOGS_INFO, LOGF_Acquire, "System's initial offset : %.6f seconds %s of true (slew)",
|
||||||
fabs(estimated_offset),
|
fabs(estimated_offset),
|
||||||
(estimated_offset >= 0) ? "fast" : "slow");
|
(estimated_offset >= 0) ? "fast" : "slow");
|
||||||
LCL_AccumulateOffset(estimated_offset);
|
LCL_AccumulateOffset(estimated_offset, 0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@@ -745,10 +747,11 @@ start_source_timeout_handler(void *not_used)
|
|||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
void
|
void
|
||||||
ACQ_StartAcquisition(int n, IPAddr *ip_addrs, int threshold, void (*after_hook)(void *), void *anything)
|
ACQ_StartAcquisition(int n, IPAddr *ip_addrs, double threshold, void (*after_hook)(void *), void *anything)
|
||||||
{
|
{
|
||||||
|
|
||||||
int i, ip4, ip6;
|
int i, ip4, ip6;
|
||||||
|
int k, duplicate_ip;
|
||||||
|
|
||||||
saved_after_hook = after_hook;
|
saved_after_hook = after_hook;
|
||||||
saved_after_hook_anything = anything;
|
saved_after_hook_anything = anything;
|
||||||
@@ -757,26 +760,37 @@ ACQ_StartAcquisition(int n, IPAddr *ip_addrs, int threshold, void (*after_hook)(
|
|||||||
|
|
||||||
n_started_sources = 0;
|
n_started_sources = 0;
|
||||||
n_completed_sources = 0;
|
n_completed_sources = 0;
|
||||||
n_sources = n;
|
n_sources = 0;
|
||||||
sources = MallocArray(SourceRecord, n);
|
sources = MallocArray(SourceRecord, n);
|
||||||
|
|
||||||
for (i = ip4 = ip6 = 0; i < n; i++) {
|
for (i = ip4 = ip6 = 0; i < n; i++) {
|
||||||
sources[i].ip_addr = ip_addrs[i];
|
/* check for duplicate IP addresses and ignore them */
|
||||||
sources[i].n_samples = 0;
|
duplicate_ip = 0;
|
||||||
sources[i].n_total_samples = 0;
|
for (k = 0; k < i; k++) {
|
||||||
sources[i].n_dead_probes = 0;
|
duplicate_ip |= UTI_CompareIPs(&(sources[k].ip_addr),
|
||||||
if (ip_addrs[i].family == IPADDR_INET4)
|
&ip_addrs[i],
|
||||||
ip4++;
|
NULL) == 0;
|
||||||
else if (ip_addrs[i].family == IPADDR_INET6)
|
}
|
||||||
ip6++;
|
if (!duplicate_ip) {
|
||||||
|
sources[n_sources].ip_addr = ip_addrs[i];
|
||||||
|
sources[n_sources].n_samples = 0;
|
||||||
|
sources[n_sources].n_total_samples = 0;
|
||||||
|
sources[n_sources].n_dead_probes = 0;
|
||||||
|
if (ip_addrs[i].family == IPADDR_INET4)
|
||||||
|
ip4++;
|
||||||
|
else if (ip_addrs[i].family == IPADDR_INET6)
|
||||||
|
ip6++;
|
||||||
|
n_sources++;
|
||||||
|
} else {
|
||||||
|
LOG(LOGS_WARN, LOGF_Acquire, "Ignoring duplicate source: %s",
|
||||||
|
UTI_IPToString(&ip_addrs[i]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
initialise_io((ip4 && ip6) ? IPADDR_UNSPEC : (ip4 ? IPADDR_INET4 : IPADDR_INET6));
|
initialise_io((ip4 && ip6) ? IPADDR_UNSPEC : (ip4 ? IPADDR_INET4 : IPADDR_INET6));
|
||||||
|
|
||||||
/* Start sampling first source */
|
/* Start sampling first source */
|
||||||
start_next_source();
|
start_next_source();
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ extern void ACQ_Initialise(void);
|
|||||||
|
|
||||||
extern void ACQ_Finalise(void);
|
extern void ACQ_Finalise(void);
|
||||||
|
|
||||||
extern void ACQ_StartAcquisition(int n, IPAddr *ip_addrs, int init_slew_threshold,
|
extern void ACQ_StartAcquisition(int n, IPAddr *ip_addrs, double init_slew_threshold,
|
||||||
void (*after_hook)(void *), void *anything);
|
void (*after_hook)(void *), void *anything);
|
||||||
|
|
||||||
extern void ACQ_AccumulateSample(ACQ_Source acq_source, double offset, double root_distance);
|
extern void ACQ_AccumulateSample(ACQ_Source acq_source, double offset, double root_distance);
|
||||||
|
|||||||
@@ -28,6 +28,8 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
#include "sysincl.h"
|
#include "sysincl.h"
|
||||||
|
|
||||||
#include "addrfilt.h"
|
#include "addrfilt.h"
|
||||||
@@ -114,8 +116,6 @@ close_node(TableNode *node)
|
|||||||
Free(node->extended);
|
Free(node->extended);
|
||||||
node->extended = NULL;
|
node->extended = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -139,7 +139,6 @@ open_node(TableNode *node)
|
|||||||
child_node->extended = NULL;
|
child_node->extended = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -406,7 +405,6 @@ static void print_node(TableNode *node, uint32_t *addr, int ip_len, int shift, i
|
|||||||
print_node(sub_node, new_addr, ip_len, shift - 4, subnet_bits + 4);
|
print_node(sub_node, new_addr, ip_len, shift - 4, subnet_bits + 4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -421,7 +419,6 @@ static void print_table(ADF_AuthTable table)
|
|||||||
memset(addr, 0, sizeof (addr));
|
memset(addr, 0, sizeof (addr));
|
||||||
printf("IPv6 table:\n");
|
printf("IPv6 table:\n");
|
||||||
print_node(&table->base6, addr, 4, 124, 0);
|
print_node(&table->base6, addr, 4, 124, 0);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|||||||
17
broadcast.c
17
broadcast.c
@@ -24,6 +24,8 @@
|
|||||||
Deal with broadcast server functions.
|
Deal with broadcast server functions.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
#include "sysincl.h"
|
#include "sysincl.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
|
|
||||||
@@ -47,7 +49,6 @@ static int max_destinations = 0;
|
|||||||
void
|
void
|
||||||
BRD_Initialise(void)
|
BRD_Initialise(void)
|
||||||
{
|
{
|
||||||
return; /* Nothing to do */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -55,7 +56,6 @@ BRD_Initialise(void)
|
|||||||
void
|
void
|
||||||
BRD_Finalise(void)
|
BRD_Finalise(void)
|
||||||
{
|
{
|
||||||
return; /* Nothing to do */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -71,7 +71,7 @@ timeout_handler(void *arbitrary)
|
|||||||
int leap;
|
int leap;
|
||||||
int are_we_synchronised, our_stratum;
|
int are_we_synchronised, our_stratum;
|
||||||
NTP_Leap leap_status;
|
NTP_Leap leap_status;
|
||||||
unsigned long our_ref_id;
|
uint32_t our_ref_id, ts_fuzz;
|
||||||
struct timeval our_ref_time;
|
struct timeval our_ref_time;
|
||||||
double our_root_delay, our_root_dispersion;
|
double our_root_delay, our_root_dispersion;
|
||||||
struct timeval local_transmit;
|
struct timeval local_transmit;
|
||||||
@@ -89,7 +89,7 @@ timeout_handler(void *arbitrary)
|
|||||||
if (are_we_synchronised) {
|
if (are_we_synchronised) {
|
||||||
leap = (int) leap_status;
|
leap = (int) leap_status;
|
||||||
} else {
|
} else {
|
||||||
leap = 3;
|
leap = LEAP_Unsynchronised;
|
||||||
}
|
}
|
||||||
|
|
||||||
message.lvm = ((leap << 6) &0xc0) | ((version << 3) & 0x38) | (MODE_BROADCAST & 0x07);
|
message.lvm = ((leap << 6) &0xc0) | ((version << 3) & 0x38) | (MODE_BROADCAST & 0x07);
|
||||||
@@ -99,20 +99,21 @@ timeout_handler(void *arbitrary)
|
|||||||
|
|
||||||
/* If we're sending a client mode packet and we aren't synchronized yet,
|
/* If we're sending a client mode packet and we aren't synchronized yet,
|
||||||
we might have to set up artificial values for some of these parameters */
|
we might have to set up artificial values for some of these parameters */
|
||||||
message.root_delay = double_to_int32(our_root_delay);
|
message.root_delay = UTI_DoubleToInt32(our_root_delay);
|
||||||
message.root_dispersion = double_to_int32(our_root_dispersion);
|
message.root_dispersion = UTI_DoubleToInt32(our_root_dispersion);
|
||||||
|
|
||||||
message.reference_id = htonl((NTP_int32) our_ref_id);
|
message.reference_id = htonl((NTP_int32) our_ref_id);
|
||||||
|
|
||||||
/* Now fill in timestamps */
|
/* Now fill in timestamps */
|
||||||
UTI_TimevalToInt64(&our_ref_time, &message.reference_ts);
|
UTI_TimevalToInt64(&our_ref_time, &message.reference_ts, 0);
|
||||||
message.originate_ts.hi = 0UL;
|
message.originate_ts.hi = 0UL;
|
||||||
message.originate_ts.lo = 0UL;
|
message.originate_ts.lo = 0UL;
|
||||||
message.receive_ts.hi = 0UL;
|
message.receive_ts.hi = 0UL;
|
||||||
message.receive_ts.lo = 0UL;
|
message.receive_ts.lo = 0UL;
|
||||||
|
|
||||||
|
ts_fuzz = UTI_GetNTPTsFuzz(message.precision);
|
||||||
LCL_ReadCookedTime(&local_transmit, NULL);
|
LCL_ReadCookedTime(&local_transmit, NULL);
|
||||||
UTI_TimevalToInt64(&local_transmit, &message.transmit_ts);
|
UTI_TimevalToInt64(&local_transmit, &message.transmit_ts, ts_fuzz);
|
||||||
NIO_SendNormalPacket(&message, &d->addr);
|
NIO_SendNormalPacket(&message, &d->addr);
|
||||||
|
|
||||||
/* Requeue timeout. Don't care if interval drifts gradually, so just do it
|
/* Requeue timeout. Don't care if interval drifts gradually, so just do it
|
||||||
|
|||||||
69
candm.h
69
candm.h
@@ -31,6 +31,7 @@
|
|||||||
|
|
||||||
#include "sysincl.h"
|
#include "sysincl.h"
|
||||||
#include "addressing.h"
|
#include "addressing.h"
|
||||||
|
#include "hash.h"
|
||||||
|
|
||||||
/* This is the default port to use for CANDM, if no alternative is
|
/* This is the default port to use for CANDM, if no alternative is
|
||||||
defined */
|
defined */
|
||||||
@@ -86,7 +87,8 @@
|
|||||||
#define REQ_MODIFY_POLLTARGET 46
|
#define REQ_MODIFY_POLLTARGET 46
|
||||||
#define REQ_MODIFY_MAXDELAYDEVRATIO 47
|
#define REQ_MODIFY_MAXDELAYDEVRATIO 47
|
||||||
#define REQ_RESELECT 48
|
#define REQ_RESELECT 48
|
||||||
#define N_REQUEST_TYPES 49
|
#define REQ_RESELECTDISTANCE 49
|
||||||
|
#define N_REQUEST_TYPES 50
|
||||||
|
|
||||||
/* Special utoken value used to log on with first exchange being the
|
/* Special utoken value used to log on with first exchange being the
|
||||||
password. (This time value has long since gone by) */
|
password. (This time value has long since gone by) */
|
||||||
@@ -296,22 +298,10 @@ typedef struct {
|
|||||||
uint32_t bits_specd;
|
uint32_t bits_specd;
|
||||||
} REQ_SubnetsAccessed_Subnet;
|
} REQ_SubnetsAccessed_Subnet;
|
||||||
|
|
||||||
#define MAX_SUBNETS_ACCESSED 8
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
uint32_t n_subnets;
|
|
||||||
REQ_SubnetsAccessed_Subnet subnets[MAX_SUBNETS_ACCESSED];
|
|
||||||
} REQ_SubnetsAccessed;
|
|
||||||
|
|
||||||
/* This is based on the response size rather than the
|
/* This is based on the response size rather than the
|
||||||
request size */
|
request size */
|
||||||
#define MAX_CLIENT_ACCESSES 8
|
#define MAX_CLIENT_ACCESSES 8
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
uint32_t n_clients;
|
|
||||||
IPAddr client_ips[MAX_CLIENT_ACCESSES];
|
|
||||||
} REQ_ClientAccesses;
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t first_index;
|
uint32_t first_index;
|
||||||
uint32_t n_indices;
|
uint32_t n_indices;
|
||||||
@@ -339,6 +329,11 @@ typedef struct {
|
|||||||
int32_t EOR;
|
int32_t EOR;
|
||||||
} REQ_Reselect;
|
} REQ_Reselect;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
Float distance;
|
||||||
|
int32_t EOR;
|
||||||
|
} REQ_ReselectDistance;
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
#define PKT_TYPE_CMD_REQUEST 1
|
#define PKT_TYPE_CMD_REQUEST 1
|
||||||
@@ -359,11 +354,15 @@ typedef struct {
|
|||||||
Version 4 : IPv6 addressing added, 64-bit time values, sourcestats
|
Version 4 : IPv6 addressing added, 64-bit time values, sourcestats
|
||||||
and tracking reports extended, added flags to NTP source request,
|
and tracking reports extended, added flags to NTP source request,
|
||||||
trimmed source report, replaced fixed-point format with floating-point
|
trimmed source report, replaced fixed-point format with floating-point
|
||||||
and used also instead of integer microseconds
|
and used also instead of integer microseconds, new commands: modify stratum,
|
||||||
|
modify polltarget, modify maxdelaydevratio, reselect, reselectdistance
|
||||||
|
|
||||||
|
Version 5 : auth data moved to the end of the packet to allow hashes with
|
||||||
|
different sizes, extended sources, tracking and activity reports, dropped
|
||||||
|
subnets accessed and client accesses
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define PROTO_VERSION_NUMBER 4
|
#define PROTO_VERSION_NUMBER 5
|
||||||
|
|
||||||
/* The oldest protocol version that is compatible enough with
|
/* The oldest protocol version that is compatible enough with
|
||||||
the current version to report a version mismatch */
|
the current version to report a version mismatch */
|
||||||
@@ -383,7 +382,6 @@ typedef struct {
|
|||||||
uint32_t sequence; /* Client's sequence number */
|
uint32_t sequence; /* Client's sequence number */
|
||||||
uint32_t utoken; /* Unique token per incarnation of daemon */
|
uint32_t utoken; /* Unique token per incarnation of daemon */
|
||||||
uint32_t token; /* Command token (to prevent replay attack) */
|
uint32_t token; /* Command token (to prevent replay attack) */
|
||||||
uint32_t auth[4]; /* MD5 authentication of the packet */
|
|
||||||
|
|
||||||
union {
|
union {
|
||||||
REQ_Online online;
|
REQ_Online online;
|
||||||
@@ -417,16 +415,19 @@ typedef struct {
|
|||||||
REQ_RTCReport rtcreport;
|
REQ_RTCReport rtcreport;
|
||||||
REQ_TrimRTC trimrtc;
|
REQ_TrimRTC trimrtc;
|
||||||
REQ_CycleLogs cyclelogs;
|
REQ_CycleLogs cyclelogs;
|
||||||
REQ_SubnetsAccessed subnets_accessed;
|
|
||||||
REQ_ClientAccesses client_accesses;
|
|
||||||
REQ_ClientAccessesByIndex client_accesses_by_index;
|
REQ_ClientAccessesByIndex client_accesses_by_index;
|
||||||
REQ_ManualList manual_list;
|
REQ_ManualList manual_list;
|
||||||
REQ_ManualDelete manual_delete;
|
REQ_ManualDelete manual_delete;
|
||||||
REQ_MakeStep make_step;
|
REQ_MakeStep make_step;
|
||||||
REQ_Activity activity;
|
REQ_Activity activity;
|
||||||
REQ_Reselect reselect;
|
REQ_Reselect reselect;
|
||||||
|
REQ_ReselectDistance reselect_distance;
|
||||||
} data; /* Command specific parameters */
|
} data; /* Command specific parameters */
|
||||||
|
|
||||||
|
/* authentication of the packet, there is no hole after the actual data
|
||||||
|
from the data union, this field only sets the maximum auth size */
|
||||||
|
uint8_t auth[MAX_HASH_LENGTH];
|
||||||
|
|
||||||
} CMD_Request;
|
} CMD_Request;
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -493,7 +494,10 @@ typedef struct {
|
|||||||
#define RPY_SD_ST_FALSETICKER 2
|
#define RPY_SD_ST_FALSETICKER 2
|
||||||
#define RPY_SD_ST_JITTERY 3
|
#define RPY_SD_ST_JITTERY 3
|
||||||
#define RPY_SD_ST_CANDIDATE 4
|
#define RPY_SD_ST_CANDIDATE 4
|
||||||
#define RPY_SD_ST_OUTLYER 5
|
#define RPY_SD_ST_OUTLIER 5
|
||||||
|
|
||||||
|
#define RPY_SD_FLAG_NOSELECT 0x1
|
||||||
|
#define RPY_SD_FLAG_PREFER 0x2
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
IPAddr ip_addr;
|
IPAddr ip_addr;
|
||||||
@@ -501,6 +505,8 @@ typedef struct {
|
|||||||
uint16_t stratum;
|
uint16_t stratum;
|
||||||
uint16_t state;
|
uint16_t state;
|
||||||
uint16_t mode;
|
uint16_t mode;
|
||||||
|
uint16_t flags;
|
||||||
|
uint16_t reachability;
|
||||||
uint32_t since_sample;
|
uint32_t since_sample;
|
||||||
Float orig_latest_meas;
|
Float orig_latest_meas;
|
||||||
Float latest_meas;
|
Float latest_meas;
|
||||||
@@ -511,14 +517,18 @@ typedef struct {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t ref_id;
|
uint32_t ref_id;
|
||||||
IPAddr ip_addr;
|
IPAddr ip_addr;
|
||||||
uint32_t stratum;
|
uint16_t stratum;
|
||||||
|
uint16_t leap_status;
|
||||||
Timeval ref_time;
|
Timeval ref_time;
|
||||||
Float current_correction;
|
Float current_correction;
|
||||||
|
Float last_offset;
|
||||||
|
Float rms_offset;
|
||||||
Float freq_ppm;
|
Float freq_ppm;
|
||||||
Float resid_freq_ppm;
|
Float resid_freq_ppm;
|
||||||
Float skew_ppm;
|
Float skew_ppm;
|
||||||
Float root_delay;
|
Float root_delay;
|
||||||
Float root_dispersion;
|
Float root_dispersion;
|
||||||
|
Float last_update_interval;
|
||||||
int32_t EOR;
|
int32_t EOR;
|
||||||
} RPY_Tracking;
|
} RPY_Tracking;
|
||||||
|
|
||||||
@@ -559,11 +569,6 @@ typedef struct {
|
|||||||
uint32_t bitmap[8];
|
uint32_t bitmap[8];
|
||||||
} RPY_SubnetsAccessed_Subnet;
|
} RPY_SubnetsAccessed_Subnet;
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
uint32_t n_subnets;
|
|
||||||
RPY_SubnetsAccessed_Subnet subnets[MAX_SUBNETS_ACCESSED];
|
|
||||||
} RPY_SubnetsAccessed;
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
IPAddr ip;
|
IPAddr ip;
|
||||||
uint32_t client_hits;
|
uint32_t client_hits;
|
||||||
@@ -575,11 +580,6 @@ typedef struct {
|
|||||||
uint32_t last_cmd_hit_ago;
|
uint32_t last_cmd_hit_ago;
|
||||||
} RPY_ClientAccesses_Client;
|
} RPY_ClientAccesses_Client;
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
uint32_t n_clients;
|
|
||||||
RPY_ClientAccesses_Client clients[MAX_CLIENT_ACCESSES];
|
|
||||||
} RPY_ClientAccesses;
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t n_indices; /* how many indices there are in the server's table */
|
uint32_t n_indices; /* how many indices there are in the server's table */
|
||||||
uint32_t next_index; /* the index 1 beyond those processed on this call */
|
uint32_t next_index; /* the index 1 beyond those processed on this call */
|
||||||
@@ -606,6 +606,7 @@ typedef struct {
|
|||||||
int32_t offline;
|
int32_t offline;
|
||||||
int32_t burst_online;
|
int32_t burst_online;
|
||||||
int32_t burst_offline;
|
int32_t burst_offline;
|
||||||
|
int32_t unresolved;
|
||||||
int32_t EOR;
|
int32_t EOR;
|
||||||
} RPY_Activity;
|
} RPY_Activity;
|
||||||
|
|
||||||
@@ -624,8 +625,6 @@ typedef struct {
|
|||||||
uint32_t utoken; /* Unique token per incarnation of daemon */
|
uint32_t utoken; /* Unique token per incarnation of daemon */
|
||||||
uint32_t token; /* New command token (only if command was successfully
|
uint32_t token; /* New command token (only if command was successfully
|
||||||
authenticated) */
|
authenticated) */
|
||||||
uint32_t auth[4]; /* MD5 authentication of the packet */
|
|
||||||
|
|
||||||
union {
|
union {
|
||||||
RPY_Null null;
|
RPY_Null null;
|
||||||
RPY_N_Sources n_sources;
|
RPY_N_Sources n_sources;
|
||||||
@@ -634,13 +633,15 @@ typedef struct {
|
|||||||
RPY_Tracking tracking;
|
RPY_Tracking tracking;
|
||||||
RPY_Sourcestats sourcestats;
|
RPY_Sourcestats sourcestats;
|
||||||
RPY_Rtc rtc;
|
RPY_Rtc rtc;
|
||||||
RPY_SubnetsAccessed subnets_accessed;
|
|
||||||
RPY_ClientAccesses client_accesses;
|
|
||||||
RPY_ClientAccessesByIndex client_accesses_by_index;
|
RPY_ClientAccessesByIndex client_accesses_by_index;
|
||||||
RPY_ManualList manual_list;
|
RPY_ManualList manual_list;
|
||||||
RPY_Activity activity;
|
RPY_Activity activity;
|
||||||
} data; /* Reply specific parameters */
|
} data; /* Reply specific parameters */
|
||||||
|
|
||||||
|
/* authentication of the packet, there is no hole after the actual data
|
||||||
|
from the data union, this field only sets the maximum auth size */
|
||||||
|
uint8_t auth[MAX_HASH_LENGTH];
|
||||||
|
|
||||||
} CMD_Reply;
|
} CMD_Reply;
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|||||||
16
chrony.1
16
chrony.1
@@ -1,4 +1,4 @@
|
|||||||
.TH CHRONY 1 "December 04, 2009" chrony "User's Manual"
|
.TH CHRONY 1 "@MAN_DATE@" "chrony @VERSION@" "User's Manual"
|
||||||
.SH NAME
|
.SH NAME
|
||||||
chrony \- programs for keeping computer clocks accurate
|
chrony \- programs for keeping computer clocks accurate
|
||||||
|
|
||||||
@@ -21,7 +21,7 @@ to the Internet, and it can also act as an RFC1305-compatible NTP server.
|
|||||||
.SH USAGE
|
.SH USAGE
|
||||||
\fIchronyc\fR is a command-line interface program which can be used to
|
\fIchronyc\fR is a command-line interface program which can be used to
|
||||||
monitor \fIchronyd\fR's performance and to change various operating
|
monitor \fIchronyd\fR's performance and to change various operating
|
||||||
parateters whilst it is running.
|
parameters whilst it is running.
|
||||||
|
|
||||||
\fIchronyd\fR's main function is to obtain measurements of the true (UTC)
|
\fIchronyd\fR's main function is to obtain measurements of the true (UTC)
|
||||||
time from one of several sources, and correct the system clock
|
time from one of several sources, and correct the system clock
|
||||||
@@ -32,16 +32,16 @@ between measurements from the reference.
|
|||||||
The reference time can be derived from either Network Time Protocol
|
The reference time can be derived from either Network Time Protocol
|
||||||
(NTP) servers, reference clocks, or wristwatch-and-keyboard (via \fIchronyc\fR).
|
(NTP) servers, reference clocks, or wristwatch-and-keyboard (via \fIchronyc\fR).
|
||||||
The main source of information about the Network Time Protocol is
|
The main source of information about the Network Time Protocol is
|
||||||
\fIhttp://www.eecis.udel.edu/~ntp\fR.
|
\fIhttp://www.ntp.org\fR.
|
||||||
|
|
||||||
It is designed so that it can work on computers which only have
|
It is designed so that it can work on computers which only have
|
||||||
intermittent access to reference sources, for example computers which
|
intermittent access to reference sources, for example computers which
|
||||||
use a dial-up account to access the Internet. Of course, it will work
|
use a dial-up account to access the Internet or laptops. Of course, it
|
||||||
on computers with permanent connections too.
|
will work well on computers with permanent connections too.
|
||||||
|
|
||||||
In addition, for Linux 2.0.x (for x >= 32) or 2.2 onwards, chronyd can monitor
|
In addition, on Linux it can monitor the system's real time clock
|
||||||
the system's real time clock performance, so the system can maintain accurate
|
performance, so the system can maintain accurate time even across
|
||||||
time even across reboots.
|
reboots.
|
||||||
|
|
||||||
Typical accuracies available between 2 machines are
|
Typical accuracies available between 2 machines are
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
.TH chrony.conf 5 "December 04, 2009" chrony "Configuration Files"
|
.TH chrony.conf 5 "@MAN_DATE@" "chrony @VERSION@" "Configuration Files"
|
||||||
.SH NAME
|
.SH NAME
|
||||||
chrony.conf \- chronyd configuration file
|
chrony.conf \- chronyd configuration file
|
||||||
|
|
||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
.B /etc/chrony.conf
|
.B @SYSCONFDIR@/chrony.conf
|
||||||
|
|
||||||
.SH DESCRIPTION
|
.SH DESCRIPTION
|
||||||
\fIchrony\fR is a pair of programs for maintaining the accuracy of computer
|
\fIchrony\fR is a pair of programs for maintaining the accuracy of computer
|
||||||
@@ -12,7 +12,7 @@ boot time.
|
|||||||
|
|
||||||
Assuming that you have found some servers, you need to set up a
|
Assuming that you have found some servers, you need to set up a
|
||||||
configuration file to run \fIchrony\fR. The (compiled-in) default location
|
configuration file to run \fIchrony\fR. The (compiled-in) default location
|
||||||
for this file is \fB/etc/chrony.conf\fR. Assuming that your ntp servers
|
for this file is \fB@SYSCONFDIR@/chrony.conf\fR. Assuming that your ntp servers
|
||||||
are called `a.b.c' and `d.e.f', your \fBchrony.conf\fR file could contain
|
are called `a.b.c' and `d.e.f', your \fBchrony.conf\fR file could contain
|
||||||
as a minimum
|
as a minimum
|
||||||
|
|
||||||
@@ -29,9 +29,9 @@ useful configuration file would look something like
|
|||||||
server a.b.c
|
server a.b.c
|
||||||
server d.e.f
|
server d.e.f
|
||||||
server g.h.i
|
server g.h.i
|
||||||
keyfile /etc/chrony.keys
|
keyfile @SYSCONFDIR@/chrony.keys
|
||||||
commandkey 1
|
commandkey 1
|
||||||
driftfile /etc/chrony.drift
|
driftfile @CHRONYVARDIR@/drift
|
||||||
|
|
||||||
|
|
||||||
.SH "SEE ALSO"
|
.SH "SEE ALSO"
|
||||||
29
chrony.lsm
29
chrony.lsm
@@ -1,29 +0,0 @@
|
|||||||
Begin3
|
|
||||||
Title: chrony
|
|
||||||
Version: 1.18
|
|
||||||
Entered-date: 01APR02
|
|
||||||
Description: A pair of programs for keeping computer clocks accurate.
|
|
||||||
chronyd is a background (daemon) program and chronyc is a
|
|
||||||
command-line interface to it. Time reference sources for
|
|
||||||
chronyd can be RFC1305 NTP servers, human (via keyboard and
|
|
||||||
chronyc), and the computer's real-time clock at boot time
|
|
||||||
(Linux only). chronyd can determine the rate at which the
|
|
||||||
computer gains or loses time and compensate for it whilst no
|
|
||||||
external reference is present. chronyd's use of NTP servers
|
|
||||||
can be switched on and off (through chronyc) to support
|
|
||||||
computers with dial-up/intermittent access to the
|
|
||||||
Internet. chronyd can also act as an RFC1305-compatible NTP
|
|
||||||
server.
|
|
||||||
Keywords: time NTP RFC1305 RTC adjtime
|
|
||||||
Author: rc@rc0.org.uk (Richard Curnow)
|
|
||||||
Maintained-by: rc@rc0.org.uk (Richard Curnow)
|
|
||||||
Primary-site: chrony.tuxfamily.org
|
|
||||||
295k chrony-1.18.tar.gz
|
|
||||||
2k chrony.lsm
|
|
||||||
Platforms: Linux 2.0/2.1/2.2/2.3/2.4 (x86, powerpc)
|
|
||||||
Solaris 2.5/6/7/8, SunOS 4.1.4. (Sparc)
|
|
||||||
BSDI/386.
|
|
||||||
NetBSD
|
|
||||||
Solaris 2.8 (x86)
|
|
||||||
Copying-policy: GPL
|
|
||||||
End
|
|
||||||
@@ -1,38 +1,43 @@
|
|||||||
|
%global chrony_version @@VERSION@@
|
||||||
|
%if 0%(echo %{chrony_version} | grep -q pre && echo 1)
|
||||||
|
%global prerelease %(echo %{chrony_version} | sed 's/.*-//')
|
||||||
|
%endif
|
||||||
Summary: An NTP client/server
|
Summary: An NTP client/server
|
||||||
Name: chrony
|
Name: chrony
|
||||||
Version: @@VERSION@@
|
Version: %(echo %{chrony_version} | sed 's/-.*//')
|
||||||
Release: 1
|
Release: %{!?prerelease:1}%{?prerelease:0.1.%{prerelease}}
|
||||||
Source: chrony-%{version}.tar.gz
|
Source: chrony-%{version}%{?prerelease:-%{prerelease}}.tar.gz
|
||||||
Copyright: GPL
|
License: GPLv2
|
||||||
Group: Applications/Utilities
|
Group: Applications/Utilities
|
||||||
Packager: Richard P. Curnow <rc@rc0.org.uk>
|
|
||||||
BuildRoot: %{_tmppath}/%{name}-%{version}-root-%(id -u -n)
|
BuildRoot: %{_tmppath}/%{name}-%{version}-root-%(id -u -n)
|
||||||
Requires: info
|
Requires: info
|
||||||
|
|
||||||
%description
|
%description
|
||||||
A pair of programs for keeping computer clocks accurate. chronyd is a
|
chrony is a client and server for the Network Time Protocol (NTP).
|
||||||
background (daemon) program and chronyc is a command-line interface to it.
|
This program keeps your computer's clock accurate. It was specially
|
||||||
Time reference sources for chronyd can be RFC1305 NTP servers, human (via
|
designed to support systems with intermittent Internet connections,
|
||||||
keyboard and chronyc), and the computer's real-time clock at boot time (Linux
|
but it also works well in permanently connected environments. It can
|
||||||
only). chronyd can determine the rate at which the computer gains or loses
|
also use hardware reference clocks, the system real-time clock, or
|
||||||
time and compensate for it whilst no external reference is present. chronyd's
|
manual input as time references.
|
||||||
use of NTP servers can be switched on and off (through chronyc) to support
|
|
||||||
computers with dial-up/intermittent access to the Internet. chronyd can also
|
|
||||||
act as an RFC1305-compatible NTP server.
|
|
||||||
|
|
||||||
%prep
|
%prep
|
||||||
%setup
|
%setup -q -n %{name}-%{version}%{?prerelease:-%{prerelease}}
|
||||||
|
|
||||||
%build
|
%build
|
||||||
./configure --prefix=%{_prefix} --mandir=%{_mandir}
|
./configure \
|
||||||
make CC=gcc CFLAGS=-O2 prefix=%{_prefix}
|
--prefix=%{_prefix} \
|
||||||
make chrony.txt prefix=%{_prefix}
|
--bindir=%{_bindir} \
|
||||||
make chrony.info prefix=%{_prefix}
|
--sbindir=%{_sbindir} \
|
||||||
|
--infodir=%{_infodir} \
|
||||||
|
--mandir=%{_mandir}
|
||||||
|
make
|
||||||
|
make chrony.txt
|
||||||
|
make chrony.info
|
||||||
|
|
||||||
%install
|
%install
|
||||||
rm -rf $RPM_BUILD_ROOT
|
rm -rf $RPM_BUILD_ROOT
|
||||||
cd $RPM_BUILD_DIR/chrony-%{version}
|
make install DESTDIR=$RPM_BUILD_ROOT
|
||||||
make install DESTDIR=$RPM_BUILD_ROOT prefix=%{_prefix}
|
rm -rf $RPM_BUILD_ROOT%{_docdir}
|
||||||
mkdir -p $RPM_BUILD_ROOT%{_infodir}
|
mkdir -p $RPM_BUILD_ROOT%{_infodir}
|
||||||
cp chrony.info* $RPM_BUILD_ROOT%{_infodir}
|
cp chrony.info* $RPM_BUILD_ROOT%{_infodir}
|
||||||
|
|
||||||
@@ -47,6 +52,6 @@ cp chrony.info* $RPM_BUILD_ROOT%{_infodir}
|
|||||||
%doc README
|
%doc README
|
||||||
%doc chrony.txt
|
%doc chrony.txt
|
||||||
%doc COPYING
|
%doc COPYING
|
||||||
%doc examples/chrony.conf.example
|
%doc examples/chrony.conf.example*
|
||||||
%doc examples/chrony.keys.example
|
%doc examples/chrony.keys.example
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -40,6 +40,7 @@ struct timex {
|
|||||||
#define ADJ_MAXERROR 0x0004 /* maximum time error */
|
#define ADJ_MAXERROR 0x0004 /* maximum time error */
|
||||||
#define ADJ_STATUS 0x0010 /* clock status */
|
#define ADJ_STATUS 0x0010 /* clock status */
|
||||||
#define ADJ_TIMECONST 0x0020 /* pll time constant */
|
#define ADJ_TIMECONST 0x0020 /* pll time constant */
|
||||||
|
#define ADJ_SETOFFSET 0x0100 /* add 'time' to current time */
|
||||||
#define ADJ_NANO 0x2000 /* select nanosecond resolution */
|
#define ADJ_NANO 0x2000 /* select nanosecond resolution */
|
||||||
#define ADJ_TICK 0x4000 /* tick value */
|
#define ADJ_TICK 0x4000 /* tick value */
|
||||||
#define ADJ_OFFSET_SINGLESHOT 0x8001 /* old-fashioned adjtime */
|
#define ADJ_OFFSET_SINGLESHOT 0x8001 /* old-fashioned adjtime */
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
.TH CHRONYC 1 "December 04, 2009" chrony "User's Manual"
|
.TH CHRONYC 1 "@MAN_DATE@" "chrony @VERSION@" "User's Manual"
|
||||||
.SH NAME
|
.SH NAME
|
||||||
chronyc \- command-line interface for chronyd
|
chronyc \- command-line interface for chronyd
|
||||||
|
|
||||||
@@ -12,7 +12,7 @@ clocks.
|
|||||||
|
|
||||||
\fBchronyc\fR is a command-line interface program which can be used to
|
\fBchronyc\fR is a command-line interface program which can be used to
|
||||||
monitor \fIchronyd\fR's performance and to change various operating
|
monitor \fIchronyd\fR's performance and to change various operating
|
||||||
parateters whilst it is running.
|
parameters whilst it is running.
|
||||||
|
|
||||||
.SH USAGE
|
.SH USAGE
|
||||||
A detailed description of all commands supported by \fBchronyc\fR is available
|
A detailed description of all commands supported by \fBchronyc\fR is available
|
||||||
@@ -42,14 +42,20 @@ resolve hostnames only to IPv6 addresses
|
|||||||
allow multiple commands to be specified on the command line. Each argument
|
allow multiple commands to be specified on the command line. Each argument
|
||||||
will be interpreted as a whole command.
|
will be interpreted as a whole command.
|
||||||
.TP
|
.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). The configuration file is
|
||||||
|
needed for the \fB-a\fR option.
|
||||||
|
.TP
|
||||||
|
\fB\-a\fR
|
||||||
|
With this option chronyc will try to authenticate automatically on
|
||||||
|
start. It will read the configuration file, read the command key from the
|
||||||
|
keyfile and run the authhash and password commands.
|
||||||
|
.TP
|
||||||
\fIcommand\fR
|
\fIcommand\fR
|
||||||
specify command. If no command is given, chronyc will read commands
|
specify command. If no command is given, chronyc will read commands
|
||||||
interactively.
|
interactively.
|
||||||
|
|
||||||
|
|
||||||
.SH VERSION
|
|
||||||
1.24
|
|
||||||
|
|
||||||
.SH BUGS
|
.SH BUGS
|
||||||
To report bugs, please visit \fIhttp://chrony.tuxfamily.org\fR
|
To report bugs, please visit \fIhttp://chrony.tuxfamily.org\fR
|
||||||
|
|
||||||
@@ -67,4 +73,3 @@ Man Pages Project". Please see \fIhttp://www.netmeister.org/misc/m2p2/index.htm
|
|||||||
for details.
|
for details.
|
||||||
|
|
||||||
The complete chrony documentation is supplied in texinfo format.
|
The complete chrony documentation is supplied in texinfo format.
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
.TH CHRONYD 8 "December 04, 2009" chrony "System Administration"
|
.TH CHRONYD 8 "@MAN_DATE@" "chrony @VERSION@" "System Administration"
|
||||||
.SH NAME
|
.SH NAME
|
||||||
chronyd \- chrony background daemon
|
chronyd \- chrony background daemon
|
||||||
|
|
||||||
@@ -21,13 +21,13 @@ gains or loses time, and compensates for this.
|
|||||||
|
|
||||||
.SH USAGE
|
.SH USAGE
|
||||||
\fBchronyd\fR is usually started at boot-time and requires superuser
|
\fBchronyd\fR is usually started at boot-time and requires superuser
|
||||||
priviliges.
|
privileges.
|
||||||
|
|
||||||
If \fBchronyd\fR has been installed to its default location
|
If \fBchronyd\fR has been installed to its default location
|
||||||
\fI/usr/local/sbin/chronyd\fR, starting it is simply a matter of entering the
|
\fI@SBINDIR@/chronyd\fR, starting it is simply a matter of entering the
|
||||||
command:
|
command:
|
||||||
|
|
||||||
\fI/usr/local/sbin/chronyd\fR
|
\fI@SBINDIR@/chronyd\fR
|
||||||
|
|
||||||
Information messages and warnings will be logged to syslog.
|
Information messages and warnings will be logged to syslog.
|
||||||
|
|
||||||
@@ -56,7 +56,7 @@ to syslog.
|
|||||||
.TP
|
.TP
|
||||||
\fB\-f\fR \fIconf-file\fR
|
\fB\-f\fR \fIconf-file\fR
|
||||||
This option can be used to specify an alternate location for the
|
This option can be used to specify an alternate location for the
|
||||||
configuration file (default \fI/etc/chrony.conf\fR).
|
configuration file (default \fI@SYSCONFDIR@/chrony.conf\fR).
|
||||||
.TP
|
.TP
|
||||||
.B \-r
|
.B \-r
|
||||||
This option will reload sample histories for each of the servers being used.
|
This option will reload sample histories for each of the servers being used.
|
||||||
@@ -69,6 +69,12 @@ systems where the kernel can maintain clock compensation whilst not under
|
|||||||
On systems where this is not the case, e.g. Solaris and SunOS the option
|
On systems where this is not the case, e.g. Solaris and SunOS the option
|
||||||
should not be used.
|
should not be used.
|
||||||
.TP
|
.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 conjuction
|
||||||
|
with the \fB-r\fR option.
|
||||||
|
.TP
|
||||||
.B \-s
|
.B \-s
|
||||||
This option will set the system clock from the computer's real-time
|
This option will set the system clock from the computer's real-time
|
||||||
clock. This is analogous to supplying the \fI-s\fR flag to the
|
clock. This is analogous to supplying the \fI-s\fR flag to the
|
||||||
@@ -100,16 +106,13 @@ user. So far, it works only on Linux when compiled with capabilities support.
|
|||||||
This option displays \fBchronyd\fR's version number to the terminal and exits
|
This option displays \fBchronyd\fR's version number to the terminal and exits
|
||||||
.TP
|
.TP
|
||||||
.B \-4
|
.B \-4
|
||||||
Resolve hostnames only to IPv4 addresses.
|
Resolve hostnames only to IPv4 addresses and create only IPv4 sockets.
|
||||||
.TP
|
.TP
|
||||||
.B \-6
|
.B \-6
|
||||||
Resolve hostnames only to IPv6 addresses.
|
Resolve hostnames only to IPv6 addresses and create only IPv6 sockets.
|
||||||
|
|
||||||
.SH FILES
|
.SH FILES
|
||||||
\fI/etc/chrony.conf\fR
|
\fI@SYSCONFDIR@/chrony.conf\fR
|
||||||
|
|
||||||
.SH VERSION
|
|
||||||
Version 1.24
|
|
||||||
|
|
||||||
.SH BUGS
|
.SH BUGS
|
||||||
To report bugs, please visit \fIhttp://chrony.tuxfamily.org/\fR
|
To report bugs, please visit \fIhttp://chrony.tuxfamily.org/\fR
|
||||||
@@ -122,8 +125,7 @@ from \fIhttp://go.to/chrony\fR
|
|||||||
.BR chrony(1),
|
.BR chrony(1),
|
||||||
.BR chronyc(1),
|
.BR chronyc(1),
|
||||||
.BR chrony.conf(5),
|
.BR chrony.conf(5),
|
||||||
.BR clock(8),
|
.BR hwclock(8),
|
||||||
.BR xntpd(8),
|
|
||||||
.BR ntpd(8)
|
.BR ntpd(8)
|
||||||
|
|
||||||
.SH AUTHOR
|
.SH AUTHOR
|
||||||
@@ -31,6 +31,8 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
#include "sysincl.h"
|
#include "sysincl.h"
|
||||||
#include "clientlog.h"
|
#include "clientlog.h"
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
@@ -172,7 +174,6 @@ CLG_Initialise(void)
|
|||||||
void
|
void
|
||||||
CLG_Finalise(void)
|
CLG_Finalise(void)
|
||||||
{
|
{
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|||||||
340
cmdmon.c
340
cmdmon.c
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
* Copyright (C) Richard P. Curnow 1997-2003
|
* Copyright (C) Richard P. Curnow 1997-2003
|
||||||
* Copyright (C) Miroslav Lichvar 2009-2011
|
* Copyright (C) Miroslav Lichvar 2009-2012
|
||||||
*
|
*
|
||||||
* 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
|
||||||
@@ -25,6 +25,8 @@
|
|||||||
Command and monitoring module in the main program
|
Command and monitoring module in the main program
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
#include "sysincl.h"
|
#include "sysincl.h"
|
||||||
|
|
||||||
#include "cmdmon.h"
|
#include "cmdmon.h"
|
||||||
@@ -32,7 +34,6 @@
|
|||||||
#include "sched.h"
|
#include "sched.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
#include "md5.h"
|
|
||||||
#include "keys.h"
|
#include "keys.h"
|
||||||
#include "ntp_sources.h"
|
#include "ntp_sources.h"
|
||||||
#include "ntp_core.h"
|
#include "ntp_core.h"
|
||||||
@@ -158,7 +159,8 @@ static int permissions[] = {
|
|||||||
PERMIT_AUTH, /* MODIFY_MINSTRATUM */
|
PERMIT_AUTH, /* MODIFY_MINSTRATUM */
|
||||||
PERMIT_AUTH, /* MODIFY_POLLTARGET */
|
PERMIT_AUTH, /* MODIFY_POLLTARGET */
|
||||||
PERMIT_AUTH, /* MODIFY_MAXDELAYDEVRATIO */
|
PERMIT_AUTH, /* MODIFY_MAXDELAYDEVRATIO */
|
||||||
PERMIT_AUTH /* RESELECT */
|
PERMIT_AUTH, /* RESELECT */
|
||||||
|
PERMIT_AUTH /* RESELECTDISTANCE */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -184,9 +186,6 @@ prepare_socket(int family)
|
|||||||
int on_off = 1;
|
int on_off = 1;
|
||||||
|
|
||||||
port_number = CNF_GetCommandPort();
|
port_number = CNF_GetCommandPort();
|
||||||
if (port_number < 0) {
|
|
||||||
port_number = DEFAULT_CANDM_PORT;
|
|
||||||
}
|
|
||||||
|
|
||||||
sock_fd = socket(family, SOCK_DGRAM, 0);
|
sock_fd = socket(family, SOCK_DGRAM, 0);
|
||||||
if (sock_fd < 0) {
|
if (sock_fd < 0) {
|
||||||
@@ -249,8 +248,10 @@ prepare_socket(int family)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (bind(sock_fd, &my_addr.u, my_addr_len) < 0) {
|
if (bind(sock_fd, &my_addr.u, my_addr_len) < 0) {
|
||||||
LOG_FATAL(LOGF_CmdMon, "Could not bind %s command socket : %s",
|
LOG(LOGS_ERR, LOGF_CmdMon, "Could not bind %s command socket : %s",
|
||||||
family == AF_INET ? "IPv4" : "IPv6", strerror(errno));
|
family == AF_INET ? "IPv4" : "IPv6", strerror(errno));
|
||||||
|
close(sock_fd);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Register handler for read events on the socket */
|
/* Register handler for read events on the socket */
|
||||||
@@ -262,7 +263,7 @@ prepare_socket(int family)
|
|||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
void
|
void
|
||||||
CAM_Initialise(void)
|
CAM_Initialise(int family)
|
||||||
{
|
{
|
||||||
assert(!initialised);
|
assert(!initialised);
|
||||||
initialised = 1;
|
initialised = 1;
|
||||||
@@ -278,9 +279,15 @@ CAM_Initialise(void)
|
|||||||
free_replies = NULL;
|
free_replies = NULL;
|
||||||
kept_replies.next = NULL;
|
kept_replies.next = NULL;
|
||||||
|
|
||||||
sock_fd4 = prepare_socket(AF_INET);
|
if (family == IPADDR_UNSPEC || family == IPADDR_INET4)
|
||||||
|
sock_fd4 = prepare_socket(AF_INET);
|
||||||
|
else
|
||||||
|
sock_fd4 = -1;
|
||||||
#ifdef HAVE_IPV6
|
#ifdef HAVE_IPV6
|
||||||
sock_fd6 = prepare_socket(AF_INET6);
|
if (family == IPADDR_UNSPEC || family == IPADDR_INET6)
|
||||||
|
sock_fd6 = prepare_socket(AF_INET6);
|
||||||
|
else
|
||||||
|
sock_fd6 = -1;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (sock_fd4 < 0
|
if (sock_fd4 < 0
|
||||||
@@ -316,7 +323,6 @@ CAM_Finalise(void)
|
|||||||
ADF_DestroyTable(access_auth_table);
|
ADF_DestroyTable(access_auth_table);
|
||||||
|
|
||||||
initialised = 0;
|
initialised = 0;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -325,57 +331,28 @@ CAM_Finalise(void)
|
|||||||
rest of the packet */
|
rest of the packet */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
check_rx_packet_auth(CMD_Request *packet)
|
check_rx_packet_auth(CMD_Request *packet, int packet_len)
|
||||||
{
|
{
|
||||||
|
int pkt_len, auth_len;
|
||||||
char *key;
|
|
||||||
int keylen;
|
|
||||||
int pkt_len;
|
|
||||||
MD5_CTX ctx;
|
|
||||||
|
|
||||||
pkt_len = PKL_CommandLength(packet);
|
pkt_len = PKL_CommandLength(packet);
|
||||||
|
auth_len = packet_len - pkt_len;
|
||||||
|
|
||||||
KEY_CommandKey(&key, &keylen);
|
return KEY_CheckAuth(KEY_GetCommandKey(), (unsigned char *)packet,
|
||||||
|
pkt_len, ((unsigned char *)packet) + pkt_len, auth_len);
|
||||||
MD5Init(&ctx);
|
|
||||||
MD5Update(&ctx, (unsigned char *) key, keylen);
|
|
||||||
MD5Update(&ctx, (unsigned char *) packet, offsetof(CMD_Request, auth));
|
|
||||||
if (pkt_len > offsetof(CMD_Request, data)) {
|
|
||||||
MD5Update(&ctx, (unsigned char *) &(packet->data), pkt_len - offsetof(CMD_Request, data));
|
|
||||||
}
|
|
||||||
MD5Final(&ctx);
|
|
||||||
|
|
||||||
if (!memcmp((void *) &ctx.digest, (void *) &(packet->auth), 16)) {
|
|
||||||
return 1;
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
static void
|
static int
|
||||||
generate_tx_packet_auth(CMD_Reply *packet)
|
generate_tx_packet_auth(CMD_Reply *packet)
|
||||||
{
|
{
|
||||||
char *key;
|
|
||||||
int keylen;
|
|
||||||
MD5_CTX ctx;
|
|
||||||
int pkt_len;
|
int pkt_len;
|
||||||
|
|
||||||
pkt_len = PKL_ReplyLength(packet);
|
pkt_len = PKL_ReplyLength(packet);
|
||||||
|
|
||||||
KEY_CommandKey(&key, &keylen);
|
return KEY_GenerateAuth(KEY_GetCommandKey(), (unsigned char *)packet,
|
||||||
|
pkt_len, ((unsigned char *)packet) + pkt_len, sizeof (packet->auth));
|
||||||
MD5Init(&ctx);
|
|
||||||
MD5Update(&ctx, (unsigned char *) key, keylen);
|
|
||||||
MD5Update(&ctx, (unsigned char *) packet, offsetof(CMD_Request, auth));
|
|
||||||
if (pkt_len > offsetof(CMD_Reply, data)) {
|
|
||||||
MD5Update(&ctx, (unsigned char *) &(packet->data), pkt_len - offsetof(CMD_Reply, data));
|
|
||||||
}
|
|
||||||
MD5Final(&ctx);
|
|
||||||
|
|
||||||
memcpy(&(packet->auth), &ctx.digest, 16);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -717,7 +694,7 @@ print_reply_packet(CMD_Reply *pkt)
|
|||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
transmit_reply(CMD_Reply *msg, union sockaddr_in46 *where_to)
|
transmit_reply(CMD_Reply *msg, union sockaddr_in46 *where_to, int auth_len)
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
int tx_message_length;
|
int tx_message_length;
|
||||||
@@ -739,7 +716,7 @@ transmit_reply(CMD_Reply *msg, union sockaddr_in46 *where_to)
|
|||||||
assert(0);
|
assert(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
tx_message_length = PKL_ReplyLength(msg);
|
tx_message_length = PKL_ReplyLength(msg) + auth_len;
|
||||||
status = sendto(sock_fd, (void *) msg, tx_message_length, 0,
|
status = sendto(sock_fd, (void *) msg, tx_message_length, 0,
|
||||||
&where_to->u, addrlen);
|
&where_to->u, addrlen);
|
||||||
|
|
||||||
@@ -766,8 +743,6 @@ transmit_reply(CMD_Reply *msg, union sockaddr_in46 *where_to)
|
|||||||
|
|
||||||
LOG(LOGS_WARN, LOGF_CmdMon, "Could not send response to %s:%hu", UTI_IPToString(&ip), port);
|
LOG(LOGS_WARN, LOGF_CmdMon, "Could not send response to %s:%hu", UTI_IPToString(&ip), port);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -977,7 +952,7 @@ handle_settime(CMD_Request *rx_message, CMD_Reply *tx_message)
|
|||||||
if (MNL_AcceptTimestamp(&ts, &offset_cs, &dfreq_ppm, &new_afreq_ppm)) {
|
if (MNL_AcceptTimestamp(&ts, &offset_cs, &dfreq_ppm, &new_afreq_ppm)) {
|
||||||
tx_message->status = htons(STT_SUCCESS);
|
tx_message->status = htons(STT_SUCCESS);
|
||||||
tx_message->reply = htons(RPY_MANUAL_TIMESTAMP);
|
tx_message->reply = htons(RPY_MANUAL_TIMESTAMP);
|
||||||
tx_message->data.manual_timestamp.centiseconds = htonl(offset_cs);
|
tx_message->data.manual_timestamp.centiseconds = htonl((int32_t)offset_cs);
|
||||||
tx_message->data.manual_timestamp.dfreq_ppm = UTI_FloatHostToNetwork(dfreq_ppm);
|
tx_message->data.manual_timestamp.dfreq_ppm = UTI_FloatHostToNetwork(dfreq_ppm);
|
||||||
tx_message->data.manual_timestamp.new_afreq_ppm = UTI_FloatHostToNetwork(new_afreq_ppm);
|
tx_message->data.manual_timestamp.new_afreq_ppm = UTI_FloatHostToNetwork(new_afreq_ppm);
|
||||||
} else {
|
} else {
|
||||||
@@ -1076,6 +1051,9 @@ handle_source_data(CMD_Request *rx_message, CMD_Reply *tx_message)
|
|||||||
case RPT_CANDIDATE:
|
case RPT_CANDIDATE:
|
||||||
tx_message->data.source_data.state = htons(RPY_SD_ST_CANDIDATE);
|
tx_message->data.source_data.state = htons(RPY_SD_ST_CANDIDATE);
|
||||||
break;
|
break;
|
||||||
|
case RPT_OUTLIER:
|
||||||
|
tx_message->data.source_data.state = htons(RPY_SD_ST_OUTLIER);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
switch (report.mode) {
|
switch (report.mode) {
|
||||||
case RPT_NTP_CLIENT:
|
case RPT_NTP_CLIENT:
|
||||||
@@ -1088,6 +1066,18 @@ handle_source_data(CMD_Request *rx_message, CMD_Reply *tx_message)
|
|||||||
tx_message->data.source_data.mode = htons(RPY_SD_MD_REF);
|
tx_message->data.source_data.mode = htons(RPY_SD_MD_REF);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
switch (report.sel_option) {
|
||||||
|
case RPT_NORMAL:
|
||||||
|
tx_message->data.source_data.flags = htons(0);
|
||||||
|
break;
|
||||||
|
case RPT_PREFER:
|
||||||
|
tx_message->data.source_data.flags = htons(RPY_SD_FLAG_PREFER);
|
||||||
|
break;
|
||||||
|
case RPT_NOSELECT:
|
||||||
|
tx_message->data.source_data.flags = htons(RPY_SD_FLAG_PREFER);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
tx_message->data.source_data.reachability = htons(report.reachability);
|
||||||
tx_message->data.source_data.since_sample = htonl(report.latest_meas_ago);
|
tx_message->data.source_data.since_sample = htonl(report.latest_meas_ago);
|
||||||
tx_message->data.source_data.orig_latest_meas = UTI_FloatHostToNetwork(report.orig_latest_meas);
|
tx_message->data.source_data.orig_latest_meas = UTI_FloatHostToNetwork(report.orig_latest_meas);
|
||||||
tx_message->data.source_data.latest_meas = UTI_FloatHostToNetwork(report.latest_meas);
|
tx_message->data.source_data.latest_meas = UTI_FloatHostToNetwork(report.latest_meas);
|
||||||
@@ -1380,7 +1370,7 @@ handle_doffset(CMD_Request *rx_message, CMD_Reply *tx_message)
|
|||||||
usec = (long)(ntohl(rx_message->data.doffset.usec));
|
usec = (long)(ntohl(rx_message->data.doffset.usec));
|
||||||
doffset = (double) sec + 1.0e-6 * (double) usec;
|
doffset = (double) sec + 1.0e-6 * (double) usec;
|
||||||
LOG(LOGS_INFO, LOGF_CmdMon, "Accumulated delta offset of %.6f seconds", doffset);
|
LOG(LOGS_INFO, LOGF_CmdMon, "Accumulated delta offset of %.6f seconds", doffset);
|
||||||
LCL_AccumulateOffset(doffset);
|
LCL_AccumulateOffset(doffset, 0.0);
|
||||||
tx_message->status = htons(STT_SUCCESS);
|
tx_message->status = htons(STT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1396,14 +1386,18 @@ handle_tracking(CMD_Request *rx_message, CMD_Reply *tx_message)
|
|||||||
tx_message->reply = htons(RPY_TRACKING);
|
tx_message->reply = htons(RPY_TRACKING);
|
||||||
tx_message->data.tracking.ref_id = htonl(rpt.ref_id);
|
tx_message->data.tracking.ref_id = htonl(rpt.ref_id);
|
||||||
UTI_IPHostToNetwork(&rpt.ip_addr, &tx_message->data.tracking.ip_addr);
|
UTI_IPHostToNetwork(&rpt.ip_addr, &tx_message->data.tracking.ip_addr);
|
||||||
tx_message->data.tracking.stratum = htonl(rpt.stratum);
|
tx_message->data.tracking.stratum = htons(rpt.stratum);
|
||||||
|
tx_message->data.tracking.leap_status = htons(rpt.leap_status);
|
||||||
UTI_TimevalHostToNetwork(&rpt.ref_time, &tx_message->data.tracking.ref_time);
|
UTI_TimevalHostToNetwork(&rpt.ref_time, &tx_message->data.tracking.ref_time);
|
||||||
tx_message->data.tracking.current_correction = UTI_FloatHostToNetwork(rpt.current_correction);
|
tx_message->data.tracking.current_correction = UTI_FloatHostToNetwork(rpt.current_correction);
|
||||||
|
tx_message->data.tracking.last_offset = UTI_FloatHostToNetwork(rpt.last_offset);
|
||||||
|
tx_message->data.tracking.rms_offset = UTI_FloatHostToNetwork(rpt.rms_offset);
|
||||||
tx_message->data.tracking.freq_ppm = UTI_FloatHostToNetwork(rpt.freq_ppm);
|
tx_message->data.tracking.freq_ppm = UTI_FloatHostToNetwork(rpt.freq_ppm);
|
||||||
tx_message->data.tracking.resid_freq_ppm = UTI_FloatHostToNetwork(rpt.resid_freq_ppm);
|
tx_message->data.tracking.resid_freq_ppm = UTI_FloatHostToNetwork(rpt.resid_freq_ppm);
|
||||||
tx_message->data.tracking.skew_ppm = UTI_FloatHostToNetwork(rpt.skew_ppm);
|
tx_message->data.tracking.skew_ppm = UTI_FloatHostToNetwork(rpt.skew_ppm);
|
||||||
tx_message->data.tracking.root_delay = UTI_FloatHostToNetwork(rpt.root_delay);
|
tx_message->data.tracking.root_delay = UTI_FloatHostToNetwork(rpt.root_delay);
|
||||||
tx_message->data.tracking.root_dispersion = UTI_FloatHostToNetwork(rpt.root_dispersion);
|
tx_message->data.tracking.root_dispersion = UTI_FloatHostToNetwork(rpt.root_dispersion);
|
||||||
|
tx_message->data.tracking.last_update_interval = UTI_FloatHostToNetwork(rpt.last_update_interval);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -1457,7 +1451,6 @@ handle_rtcreport(CMD_Request *rx_message, CMD_Reply *tx_message)
|
|||||||
} else {
|
} else {
|
||||||
tx_message->status = htons(STT_NORTC);
|
tx_message->status = htons(STT_NORTC);
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -1472,7 +1465,6 @@ handle_trimrtc(CMD_Request *rx_message, CMD_Reply *tx_message)
|
|||||||
} else {
|
} else {
|
||||||
tx_message->status = htons(STT_NORTC);
|
tx_message->status = htons(STT_NORTC);
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -1483,110 +1475,6 @@ handle_cyclelogs(CMD_Request *rx_message, CMD_Reply *tx_message)
|
|||||||
LOG_CycleLogFiles();
|
LOG_CycleLogFiles();
|
||||||
|
|
||||||
tx_message->status = htons(STT_SUCCESS);
|
tx_message->status = htons(STT_SUCCESS);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ================================================== */
|
|
||||||
|
|
||||||
#define FLIPL(X) ((X) = htonl(X))
|
|
||||||
|
|
||||||
static void
|
|
||||||
handle_subnets_accessed(CMD_Request *rx_message, CMD_Reply *tx_message)
|
|
||||||
{
|
|
||||||
int i, j;
|
|
||||||
unsigned long ns, bits_specd;
|
|
||||||
IPAddr ip;
|
|
||||||
CLG_Status result;
|
|
||||||
|
|
||||||
ns = ntohl(rx_message->data.subnets_accessed.n_subnets);
|
|
||||||
tx_message->status = htons(STT_SUCCESS);
|
|
||||||
tx_message->reply = htons(RPY_SUBNETS_ACCESSED);
|
|
||||||
tx_message->data.subnets_accessed.n_subnets = htonl(ns);
|
|
||||||
|
|
||||||
for (i=0; i<ns; i++) {
|
|
||||||
UTI_IPNetworkToHost(&rx_message->data.subnets_accessed.subnets[i].ip, &ip);
|
|
||||||
bits_specd = ntohl(rx_message->data.subnets_accessed.subnets[i].bits_specd);
|
|
||||||
|
|
||||||
UTI_IPHostToNetwork(&ip, &tx_message->data.subnets_accessed.subnets[i].ip);
|
|
||||||
tx_message->data.subnets_accessed.subnets[i].bits_specd = htonl(bits_specd);
|
|
||||||
|
|
||||||
result = CLG_GetSubnetBitmap(&ip, bits_specd, tx_message->data.subnets_accessed.subnets[i].bitmap);
|
|
||||||
switch (result) {
|
|
||||||
case CLG_SUCCESS:
|
|
||||||
case CLG_EMPTYSUBNET:
|
|
||||||
/* Flip endianness of each 4 byte word. Don't care if subnet
|
|
||||||
is empty - just return an all-zero bitmap. */
|
|
||||||
for (j=0; j<8; j++) {
|
|
||||||
FLIPL(tx_message->data.subnets_accessed.subnets[i].bitmap[j]);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case CLG_BADSUBNET:
|
|
||||||
tx_message->status = htons(STT_BADSUBNET);
|
|
||||||
return;
|
|
||||||
case CLG_INACTIVE:
|
|
||||||
tx_message->status = htons(STT_INACTIVE);
|
|
||||||
return;
|
|
||||||
default:
|
|
||||||
assert(0);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ================================================== */
|
|
||||||
|
|
||||||
static void
|
|
||||||
handle_client_accesses(CMD_Request *rx_message, CMD_Reply *tx_message)
|
|
||||||
{
|
|
||||||
CLG_Status result;
|
|
||||||
RPT_ClientAccess_Report report;
|
|
||||||
unsigned long nc;
|
|
||||||
IPAddr ip;
|
|
||||||
int i;
|
|
||||||
struct timeval now;
|
|
||||||
|
|
||||||
LCL_ReadCookedTime(&now, NULL);
|
|
||||||
|
|
||||||
nc = ntohl(rx_message->data.client_accesses.n_clients);
|
|
||||||
tx_message->status = htons(STT_SUCCESS);
|
|
||||||
tx_message->reply = htons(RPY_CLIENT_ACCESSES);
|
|
||||||
tx_message->data.client_accesses.n_clients = htonl(nc);
|
|
||||||
|
|
||||||
printf("%d %d\n", (int)sizeof(RPY_ClientAccesses_Client), (int)offsetof(CMD_Reply, data.client_accesses.clients));
|
|
||||||
|
|
||||||
for (i=0; i<nc; i++) {
|
|
||||||
UTI_IPNetworkToHost(&rx_message->data.client_accesses.client_ips[i], &ip);
|
|
||||||
UTI_IPHostToNetwork(&ip, &tx_message->data.client_accesses.clients[i].ip);
|
|
||||||
|
|
||||||
result = CLG_GetClientAccessReportByIP(&ip, &report, now.tv_sec);
|
|
||||||
switch (result) {
|
|
||||||
case CLG_SUCCESS:
|
|
||||||
tx_message->data.client_accesses.clients[i].client_hits = htonl(report.client_hits);
|
|
||||||
tx_message->data.client_accesses.clients[i].peer_hits = htonl(report.peer_hits);
|
|
||||||
tx_message->data.client_accesses.clients[i].cmd_hits_auth = htonl(report.cmd_hits_auth);
|
|
||||||
tx_message->data.client_accesses.clients[i].cmd_hits_normal = htonl(report.cmd_hits_normal);
|
|
||||||
tx_message->data.client_accesses.clients[i].cmd_hits_bad = htonl(report.cmd_hits_bad);
|
|
||||||
tx_message->data.client_accesses.clients[i].last_ntp_hit_ago = htonl(report.last_ntp_hit_ago);
|
|
||||||
tx_message->data.client_accesses.clients[i].last_cmd_hit_ago = htonl(report.last_cmd_hit_ago);
|
|
||||||
printf("%s %lu %lu %lu %lu %lu %lu %lu\n", UTI_IPToString(&ip), report.client_hits, report.peer_hits, report.cmd_hits_auth, report.cmd_hits_normal, report.cmd_hits_bad, report.last_ntp_hit_ago, report.last_cmd_hit_ago);
|
|
||||||
break;
|
|
||||||
case CLG_EMPTYSUBNET:
|
|
||||||
/* Signal back to the client that this single client address
|
|
||||||
was unknown */
|
|
||||||
ip.family = IPADDR_UNSPEC;
|
|
||||||
UTI_IPHostToNetwork(&ip, &tx_message->data.client_accesses.clients[i].ip);
|
|
||||||
break;
|
|
||||||
case CLG_INACTIVE:
|
|
||||||
tx_message->status = htons(STT_INACTIVE);
|
|
||||||
return;
|
|
||||||
default:
|
|
||||||
assert(0);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -1691,7 +1579,6 @@ handle_make_step(CMD_Request *rx_message, CMD_Reply *tx_message)
|
|||||||
{
|
{
|
||||||
LCL_MakeStep(0.0);
|
LCL_MakeStep(0.0);
|
||||||
tx_message->status = htons(STT_SUCCESS);
|
tx_message->status = htons(STT_SUCCESS);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -1705,18 +1592,29 @@ handle_activity(CMD_Request *rx_message, CMD_Reply *tx_message)
|
|||||||
tx_message->data.activity.offline = htonl(report.offline);
|
tx_message->data.activity.offline = htonl(report.offline);
|
||||||
tx_message->data.activity.burst_online = htonl(report.burst_online);
|
tx_message->data.activity.burst_online = htonl(report.burst_online);
|
||||||
tx_message->data.activity.burst_offline = htonl(report.burst_offline);
|
tx_message->data.activity.burst_offline = htonl(report.burst_offline);
|
||||||
|
tx_message->data.activity.unresolved = htonl(report.unresolved);
|
||||||
tx_message->status = htons(STT_SUCCESS);
|
tx_message->status = htons(STT_SUCCESS);
|
||||||
tx_message->reply = htons(RPY_ACTIVITY);
|
tx_message->reply = htons(RPY_ACTIVITY);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
|
static void
|
||||||
|
handle_reselect_distance(CMD_Request *rx_message, CMD_Reply *tx_message)
|
||||||
|
{
|
||||||
|
double dist;
|
||||||
|
dist = UTI_FloatNetworkToHost(rx_message->data.reselect_distance.distance);
|
||||||
|
SRC_SetReselectDistance(dist);
|
||||||
|
tx_message->status = htons(STT_SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
handle_reselect(CMD_Request *rx_message, CMD_Reply *tx_message)
|
handle_reselect(CMD_Request *rx_message, CMD_Reply *tx_message)
|
||||||
{
|
{
|
||||||
SRC_ReselectSource();
|
SRC_ReselectSource();
|
||||||
tx_message->status = htons(STT_SUCCESS);
|
tx_message->status = htons(STT_SUCCESS);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -1741,7 +1639,7 @@ read_from_cmd_socket(void *anything)
|
|||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
int read_length; /* Length of packet read */
|
int read_length; /* Length of packet read */
|
||||||
int expected_length; /* Expected length of packet */
|
int expected_length; /* Expected length of packet without auth data */
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
CMD_Request rx_message;
|
CMD_Request rx_message;
|
||||||
CMD_Reply tx_message, *prev_tx_message;
|
CMD_Reply tx_message, *prev_tx_message;
|
||||||
@@ -1751,7 +1649,8 @@ read_from_cmd_socket(void *anything)
|
|||||||
socklen_t from_length;
|
socklen_t from_length;
|
||||||
IPAddr remote_ip;
|
IPAddr remote_ip;
|
||||||
unsigned short remote_port;
|
unsigned short remote_port;
|
||||||
int md5_ok;
|
int auth_length;
|
||||||
|
int auth_ok;
|
||||||
int utoken_ok, token_ok;
|
int utoken_ok, token_ok;
|
||||||
int issue_token;
|
int issue_token;
|
||||||
int valid_ts;
|
int valid_ts;
|
||||||
@@ -1781,29 +1680,10 @@ read_from_cmd_socket(void *anything)
|
|||||||
}
|
}
|
||||||
|
|
||||||
read_length = status;
|
read_length = status;
|
||||||
expected_length = PKL_CommandLength(&rx_message);
|
|
||||||
rx_command = ntohs(rx_message.command);
|
|
||||||
|
|
||||||
LCL_ReadRawTime(&now);
|
LCL_ReadRawTime(&now);
|
||||||
LCL_CookTime(&now, &cooked_now, NULL);
|
LCL_CookTime(&now, &cooked_now, NULL);
|
||||||
|
|
||||||
tx_message.version = PROTO_VERSION_NUMBER;
|
|
||||||
tx_message.pkt_type = PKT_TYPE_CMD_REPLY;
|
|
||||||
tx_message.res1 = 0;
|
|
||||||
tx_message.res2 = 0;
|
|
||||||
tx_message.command = rx_message.command;
|
|
||||||
tx_message.sequence = rx_message.sequence;
|
|
||||||
tx_message.reply = htons(RPY_NULL);
|
|
||||||
tx_message.number = htons(1);
|
|
||||||
tx_message.total = htons(1);
|
|
||||||
tx_message.pad1 = 0;
|
|
||||||
tx_message.utoken = htonl(utoken);
|
|
||||||
/* Set this to a default (invalid) value. This protects against the
|
|
||||||
token field being set to an arbitrary value if we reject the
|
|
||||||
message, e.g. due to the host failing the access check. */
|
|
||||||
tx_message.token = htonl(0xffffffffUL);
|
|
||||||
memset(&tx_message.auth, 0, sizeof(tx_message.auth));
|
|
||||||
|
|
||||||
switch (where_from.u.sa_family) {
|
switch (where_from.u.sa_family) {
|
||||||
case AF_INET:
|
case AF_INET:
|
||||||
remote_ip.family = IPADDR_INET4;
|
remote_ip.family = IPADDR_INET4;
|
||||||
@@ -1830,7 +1710,14 @@ read_from_cmd_socket(void *anything)
|
|||||||
|
|
||||||
allowed = ADF_IsAllowed(access_auth_table, &remote_ip) || localhost;
|
allowed = ADF_IsAllowed(access_auth_table, &remote_ip) || localhost;
|
||||||
|
|
||||||
if (read_length < offsetof(CMD_Request, data) ||
|
/* Message size sanity check */
|
||||||
|
if (read_length >= offsetof(CMD_Request, data)) {
|
||||||
|
expected_length = PKL_CommandLength(&rx_message);
|
||||||
|
} else {
|
||||||
|
expected_length = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (expected_length < offsetof(CMD_Request, data) ||
|
||||||
rx_message.pkt_type != PKT_TYPE_CMD_REQUEST ||
|
rx_message.pkt_type != PKT_TYPE_CMD_REQUEST ||
|
||||||
rx_message.res1 != 0 ||
|
rx_message.res1 != 0 ||
|
||||||
rx_message.res2 != 0) {
|
rx_message.res2 != 0) {
|
||||||
@@ -1842,6 +1729,25 @@ read_from_cmd_socket(void *anything)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rx_command = ntohs(rx_message.command);
|
||||||
|
|
||||||
|
tx_message.version = PROTO_VERSION_NUMBER;
|
||||||
|
tx_message.pkt_type = PKT_TYPE_CMD_REPLY;
|
||||||
|
tx_message.res1 = 0;
|
||||||
|
tx_message.res2 = 0;
|
||||||
|
tx_message.command = rx_message.command;
|
||||||
|
tx_message.sequence = rx_message.sequence;
|
||||||
|
tx_message.reply = htons(RPY_NULL);
|
||||||
|
tx_message.number = htons(1);
|
||||||
|
tx_message.total = htons(1);
|
||||||
|
tx_message.pad1 = 0;
|
||||||
|
tx_message.utoken = htonl(utoken);
|
||||||
|
/* Set this to a default (invalid) value. This protects against the
|
||||||
|
token field being set to an arbitrary value if we reject the
|
||||||
|
message, e.g. due to the host failing the access check. */
|
||||||
|
tx_message.token = htonl(0xffffffffUL);
|
||||||
|
memset(&tx_message.auth, 0, sizeof(tx_message.auth));
|
||||||
|
|
||||||
if (rx_message.version != PROTO_VERSION_NUMBER) {
|
if (rx_message.version != PROTO_VERSION_NUMBER) {
|
||||||
tx_message.status = htons(STT_NOHOSTACCESS);
|
tx_message.status = htons(STT_NOHOSTACCESS);
|
||||||
if (!LOG_RateLimited()) {
|
if (!LOG_RateLimited()) {
|
||||||
@@ -1852,7 +1758,10 @@ read_from_cmd_socket(void *anything)
|
|||||||
|
|
||||||
if (rx_message.version >= PROTO_VERSION_MISMATCH_COMPAT) {
|
if (rx_message.version >= PROTO_VERSION_MISMATCH_COMPAT) {
|
||||||
tx_message.status = htons(STT_BADPKTVERSION);
|
tx_message.status = htons(STT_BADPKTVERSION);
|
||||||
transmit_reply(&tx_message, &where_from);
|
/* add empty MD5 auth so older clients will not drop
|
||||||
|
the reply due to bad length */
|
||||||
|
memset(((char *)&tx_message) + PKL_ReplyLength(&tx_message), 0, 16);
|
||||||
|
transmit_reply(&tx_message, &where_from, 16);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1865,11 +1774,11 @@ read_from_cmd_socket(void *anything)
|
|||||||
CLG_LogCommandAccess(&remote_ip, CLG_CMD_BAD_PKT, cooked_now.tv_sec);
|
CLG_LogCommandAccess(&remote_ip, CLG_CMD_BAD_PKT, cooked_now.tv_sec);
|
||||||
|
|
||||||
tx_message.status = htons(STT_INVALID);
|
tx_message.status = htons(STT_INVALID);
|
||||||
transmit_reply(&tx_message, &where_from);
|
transmit_reply(&tx_message, &where_from, 0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (read_length != expected_length) {
|
if (read_length < expected_length) {
|
||||||
if (!LOG_RateLimited()) {
|
if (!LOG_RateLimited()) {
|
||||||
LOG(LOGS_WARN, LOGF_CmdMon, "Read incorrectly sized command packet from %s:%hu", UTI_IPToString(&remote_ip), remote_port);
|
LOG(LOGS_WARN, LOGF_CmdMon, "Read incorrectly sized command packet from %s:%hu", UTI_IPToString(&remote_ip), remote_port);
|
||||||
}
|
}
|
||||||
@@ -1877,7 +1786,7 @@ read_from_cmd_socket(void *anything)
|
|||||||
CLG_LogCommandAccess(&remote_ip, CLG_CMD_BAD_PKT, cooked_now.tv_sec);
|
CLG_LogCommandAccess(&remote_ip, CLG_CMD_BAD_PKT, cooked_now.tv_sec);
|
||||||
|
|
||||||
tx_message.status = htons(STT_BADPKTLENGTH);
|
tx_message.status = htons(STT_BADPKTLENGTH);
|
||||||
transmit_reply(&tx_message, &where_from);
|
transmit_reply(&tx_message, &where_from, 0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1894,7 +1803,7 @@ read_from_cmd_socket(void *anything)
|
|||||||
}
|
}
|
||||||
|
|
||||||
tx_message.status = htons(STT_NOHOSTACCESS);
|
tx_message.status = htons(STT_NOHOSTACCESS);
|
||||||
transmit_reply(&tx_message, &where_from);
|
transmit_reply(&tx_message, &where_from, 0);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1905,18 +1814,18 @@ read_from_cmd_socket(void *anything)
|
|||||||
clients will set their utokens to 0 to save us wasting our time
|
clients will set their utokens to 0 to save us wasting our time
|
||||||
if the packet is unauthenticatable. */
|
if the packet is unauthenticatable. */
|
||||||
if (rx_message.utoken != 0) {
|
if (rx_message.utoken != 0) {
|
||||||
md5_ok = check_rx_packet_auth(&rx_message);
|
auth_ok = check_rx_packet_auth(&rx_message, read_length);
|
||||||
} else {
|
} else {
|
||||||
md5_ok = 0;
|
auth_ok = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* All this malarky is to protect the system against various forms
|
/* All this malarky is to protect the system against various forms
|
||||||
of attack.
|
of attack.
|
||||||
|
|
||||||
Simple packet forgeries are blocked by requiring the packet to
|
Simple packet forgeries are blocked by requiring the packet to
|
||||||
authenticate properly with MD5. (The assumption is that the
|
authenticate properly with MD5 or other crypto hash. (The
|
||||||
command key is in a read-only keys file read by the daemon, and
|
assumption is that the command key is in a read-only keys file
|
||||||
is known only to administrators.)
|
read by the daemon, and is known only to administrators.)
|
||||||
|
|
||||||
Replay attacks are prevented by 2 fields in the packet. The
|
Replay attacks are prevented by 2 fields in the packet. The
|
||||||
'token' field is where the client plays back to us a token that
|
'token' field is where the client plays back to us a token that
|
||||||
@@ -1958,13 +1867,13 @@ read_from_cmd_socket(void *anything)
|
|||||||
rx_message_seq = ntohl(rx_message.sequence);
|
rx_message_seq = ntohl(rx_message.sequence);
|
||||||
rx_attempt = ntohs(rx_message.attempt);
|
rx_attempt = ntohs(rx_message.attempt);
|
||||||
|
|
||||||
if (md5_ok && utoken_ok) {
|
if (auth_ok && utoken_ok) {
|
||||||
token_ok = check_token(rx_message_token);
|
token_ok = check_token(rx_message_token);
|
||||||
} else {
|
} else {
|
||||||
token_ok = 0;
|
token_ok = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (md5_ok && utoken_ok && !token_ok) {
|
if (auth_ok && utoken_ok && !token_ok) {
|
||||||
/* This might be a resent message, due to the client not getting
|
/* This might be a resent message, due to the client not getting
|
||||||
our reply to the first attempt. See if we can find the message. */
|
our reply to the first attempt. See if we can find the message. */
|
||||||
prev_tx_message = lookup_reply(rx_message_token, rx_message_seq, rx_attempt);
|
prev_tx_message = lookup_reply(rx_message_token, rx_message_seq, rx_attempt);
|
||||||
@@ -1982,14 +1891,14 @@ read_from_cmd_socket(void *anything)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (md5_ok && utoken_ok && token_ok) {
|
if (auth_ok && utoken_ok && token_ok) {
|
||||||
/* See whether we can discard the previous reply from storage */
|
/* See whether we can discard the previous reply from storage */
|
||||||
token_acknowledged(rx_message_token, &now);
|
token_acknowledged(rx_message_token, &now);
|
||||||
}
|
}
|
||||||
|
|
||||||
valid_ts = 0;
|
valid_ts = 0;
|
||||||
|
|
||||||
if (md5_ok) {
|
if (auth_ok) {
|
||||||
struct timeval ts;
|
struct timeval ts;
|
||||||
|
|
||||||
UTI_TimevalNetworkToHost(&rx_message.data.logon.ts, &ts);
|
UTI_TimevalNetworkToHost(&rx_message.data.logon.ts, &ts);
|
||||||
@@ -2004,7 +1913,7 @@ read_from_cmd_socket(void *anything)
|
|||||||
issue_token = 0;
|
issue_token = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
authenticated = md5_ok & utoken_ok & token_ok;
|
authenticated = auth_ok & utoken_ok & token_ok;
|
||||||
|
|
||||||
if (authenticated) {
|
if (authenticated) {
|
||||||
CLG_LogCommandAccess(&remote_ip, CLG_CMD_AUTH, cooked_now.tv_sec);
|
CLG_LogCommandAccess(&remote_ip, CLG_CMD_AUTH, cooked_now.tv_sec);
|
||||||
@@ -2104,15 +2013,15 @@ read_from_cmd_socket(void *anything)
|
|||||||
/* If the log-on fails, record the reason why */
|
/* If the log-on fails, record the reason why */
|
||||||
if (!issue_token && !LOG_RateLimited()) {
|
if (!issue_token && !LOG_RateLimited()) {
|
||||||
LOG(LOGS_WARN, LOGF_CmdMon,
|
LOG(LOGS_WARN, LOGF_CmdMon,
|
||||||
"Bad command logon from %s port %d (md5_ok=%d valid_ts=%d)\n",
|
"Bad command logon from %s port %d (auth_ok=%d valid_ts=%d)",
|
||||||
UTI_IPToString(&remote_ip),
|
UTI_IPToString(&remote_ip),
|
||||||
remote_port,
|
remote_port,
|
||||||
md5_ok, valid_ts);
|
auth_ok, valid_ts);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (issue_token == 1) {
|
if (issue_token == 1) {
|
||||||
tx_message.status = htons(STT_SUCCESS);
|
tx_message.status = htons(STT_SUCCESS);
|
||||||
} else if (!md5_ok) {
|
} else if (!auth_ok) {
|
||||||
tx_message.status = htons(STT_UNAUTH);
|
tx_message.status = htons(STT_UNAUTH);
|
||||||
} else if (!valid_ts) {
|
} else if (!valid_ts) {
|
||||||
tx_message.status = htons(STT_INVALIDTS);
|
tx_message.status = htons(STT_INVALIDTS);
|
||||||
@@ -2230,14 +2139,6 @@ read_from_cmd_socket(void *anything)
|
|||||||
handle_cyclelogs(&rx_message, &tx_message);
|
handle_cyclelogs(&rx_message, &tx_message);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case REQ_SUBNETS_ACCESSED:
|
|
||||||
handle_subnets_accessed(&rx_message, &tx_message);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case REQ_CLIENT_ACCESSES:
|
|
||||||
handle_client_accesses(&rx_message, &tx_message);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case REQ_CLIENT_ACCESSES_BY_INDEX:
|
case REQ_CLIENT_ACCESSES_BY_INDEX:
|
||||||
handle_client_accesses_by_index(&rx_message, &tx_message);
|
handle_client_accesses_by_index(&rx_message, &tx_message);
|
||||||
break;
|
break;
|
||||||
@@ -2258,6 +2159,10 @@ read_from_cmd_socket(void *anything)
|
|||||||
handle_activity(&rx_message, &tx_message);
|
handle_activity(&rx_message, &tx_message);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case REQ_RESELECTDISTANCE:
|
||||||
|
handle_reselect_distance(&rx_message, &tx_message);
|
||||||
|
break;
|
||||||
|
|
||||||
case REQ_RESELECT:
|
case REQ_RESELECT:
|
||||||
handle_reselect(&rx_message, &tx_message);
|
handle_reselect(&rx_message, &tx_message);
|
||||||
break;
|
break;
|
||||||
@@ -2271,7 +2176,7 @@ read_from_cmd_socket(void *anything)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
/* Ignore message */
|
assert(0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -2279,8 +2184,10 @@ read_from_cmd_socket(void *anything)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (md5_ok) {
|
if (auth_ok) {
|
||||||
generate_tx_packet_auth(&tx_message);
|
auth_length = generate_tx_packet_auth(&tx_message);
|
||||||
|
} else {
|
||||||
|
auth_length = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (token_ok) {
|
if (token_ok) {
|
||||||
@@ -2299,16 +2206,13 @@ read_from_cmd_socket(void *anything)
|
|||||||
static int do_it=1;
|
static int do_it=1;
|
||||||
|
|
||||||
if (do_it) {
|
if (do_it) {
|
||||||
transmit_reply(&tx_message, &where_from);
|
transmit_reply(&tx_message, &where_from, auth_length);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
do_it = ((do_it + 1) % 3);
|
do_it = ((do_it + 1) % 3);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|||||||
2
cmdmon.h
2
cmdmon.h
@@ -29,7 +29,7 @@
|
|||||||
|
|
||||||
#include "addressing.h"
|
#include "addressing.h"
|
||||||
|
|
||||||
extern void CAM_Initialise(void);
|
extern void CAM_Initialise(int family);
|
||||||
|
|
||||||
extern void CAM_Finalise(void);
|
extern void CAM_Finalise(void);
|
||||||
|
|
||||||
|
|||||||
159
cmdparse.c
159
cmdparse.c
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
* Copyright (C) Richard P. Curnow 1997-2003
|
* Copyright (C) Richard P. Curnow 1997-2003
|
||||||
|
* Copyright (C) Miroslav Lichvar 2013
|
||||||
*
|
*
|
||||||
* 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
|
||||||
@@ -26,24 +27,23 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
#include "sysincl.h"
|
#include "sysincl.h"
|
||||||
|
|
||||||
#include "cmdparse.h"
|
#include "cmdparse.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "nameserv.h"
|
#include "nameserv.h"
|
||||||
|
#include "util.h"
|
||||||
#define MAXLEN 2047
|
|
||||||
#define SMAXLEN "2047"
|
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
CPS_Status
|
CPS_Status
|
||||||
CPS_ParseNTPSourceAdd(const char *line, CPS_NTP_Source *src)
|
CPS_ParseNTPSourceAdd(char *line, CPS_NTP_Source *src)
|
||||||
{
|
{
|
||||||
|
char *hostname, *cmd;
|
||||||
int ok, n, done;
|
int ok, n, done;
|
||||||
char cmd[MAXLEN+1], hostname[MAXLEN+1];
|
|
||||||
CPS_Status result;
|
CPS_Status result;
|
||||||
DNS_Status s;
|
|
||||||
|
|
||||||
src->port = SRC_DEFAULT_PORT;
|
src->port = SRC_DEFAULT_PORT;
|
||||||
src->params.minpoll = SRC_DEFAULT_MINPOLL;
|
src->params.minpoll = SRC_DEFAULT_MINPOLL;
|
||||||
@@ -62,33 +62,22 @@ CPS_ParseNTPSourceAdd(const char *line, CPS_NTP_Source *src)
|
|||||||
|
|
||||||
result = CPS_Success;
|
result = CPS_Success;
|
||||||
|
|
||||||
ok = 0;
|
hostname = line;
|
||||||
if (sscanf(line, "%" SMAXLEN "s%n", hostname, &n) == 1) {
|
line = CPS_SplitWord(line);
|
||||||
s = DNS_Name2IPAddress(hostname, &src->ip_addr);
|
|
||||||
if (s == DNS_Success) {
|
|
||||||
ok = 1;
|
|
||||||
src->name = NULL;
|
|
||||||
} else if (s == DNS_TryAgain) {
|
|
||||||
ok = 1;
|
|
||||||
src->ip_addr.family = IPADDR_UNSPEC;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ok) {
|
if (!*hostname) {
|
||||||
result = CPS_BadHost;
|
result = CPS_BadHost;
|
||||||
|
ok = 0;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
line += n;
|
|
||||||
|
|
||||||
/* Parse subfields */
|
/* Parse subfields */
|
||||||
ok = 1;
|
ok = 1;
|
||||||
done = 0;
|
done = 0;
|
||||||
do {
|
do {
|
||||||
if (sscanf(line, "%" SMAXLEN "s%n", cmd, &n) == 1) {
|
cmd = line;
|
||||||
|
line = CPS_SplitWord(line);
|
||||||
|
|
||||||
line += n;
|
if (*cmd) {
|
||||||
|
if (!strcasecmp(cmd, "port")) {
|
||||||
if (!strncasecmp(cmd, "port", 4)) {
|
|
||||||
if (sscanf(line, "%hu%n", &src->port, &n) != 1) {
|
if (sscanf(line, "%hu%n", &src->port, &n) != 1) {
|
||||||
result = CPS_BadPort;
|
result = CPS_BadPort;
|
||||||
ok = 0;
|
ok = 0;
|
||||||
@@ -96,7 +85,7 @@ CPS_ParseNTPSourceAdd(const char *line, CPS_NTP_Source *src)
|
|||||||
} else {
|
} else {
|
||||||
line += n;
|
line += n;
|
||||||
}
|
}
|
||||||
} else if (!strncasecmp(cmd, "minpoll", 7)) {
|
} else if (!strcasecmp(cmd, "minpoll")) {
|
||||||
if (sscanf(line, "%d%n", &src->params.minpoll, &n) != 1) {
|
if (sscanf(line, "%d%n", &src->params.minpoll, &n) != 1) {
|
||||||
result = CPS_BadMinpoll;
|
result = CPS_BadMinpoll;
|
||||||
ok = 0;
|
ok = 0;
|
||||||
@@ -104,7 +93,7 @@ CPS_ParseNTPSourceAdd(const char *line, CPS_NTP_Source *src)
|
|||||||
} else {
|
} else {
|
||||||
line += n;
|
line += n;
|
||||||
}
|
}
|
||||||
} else if (!strncasecmp(cmd, "maxpoll", 7)) {
|
} else if (!strcasecmp(cmd, "maxpoll")) {
|
||||||
if (sscanf(line, "%d%n", &src->params.maxpoll, &n) != 1) {
|
if (sscanf(line, "%d%n", &src->params.maxpoll, &n) != 1) {
|
||||||
result = CPS_BadMaxpoll;
|
result = CPS_BadMaxpoll;
|
||||||
ok = 0;
|
ok = 0;
|
||||||
@@ -112,7 +101,7 @@ CPS_ParseNTPSourceAdd(const char *line, CPS_NTP_Source *src)
|
|||||||
} else {
|
} else {
|
||||||
line += n;
|
line += n;
|
||||||
}
|
}
|
||||||
} else if (!strncasecmp(cmd, "presend", 7)) {
|
} else if (!strcasecmp(cmd, "presend")) {
|
||||||
if (sscanf(line, "%d%n", &src->params.presend_minpoll, &n) != 1) {
|
if (sscanf(line, "%d%n", &src->params.presend_minpoll, &n) != 1) {
|
||||||
result = CPS_BadPresend;
|
result = CPS_BadPresend;
|
||||||
ok = 0;
|
ok = 0;
|
||||||
@@ -120,7 +109,7 @@ CPS_ParseNTPSourceAdd(const char *line, CPS_NTP_Source *src)
|
|||||||
} else {
|
} else {
|
||||||
line += n;
|
line += n;
|
||||||
}
|
}
|
||||||
} else if (!strncasecmp(cmd, "maxdelaydevratio", 16)) {
|
} else if (!strcasecmp(cmd, "maxdelaydevratio")) {
|
||||||
if (sscanf(line, "%lf%n", &src->params.max_delay_dev_ratio, &n) != 1) {
|
if (sscanf(line, "%lf%n", &src->params.max_delay_dev_ratio, &n) != 1) {
|
||||||
result = CPS_BadMaxdelaydevratio;
|
result = CPS_BadMaxdelaydevratio;
|
||||||
ok = 0;
|
ok = 0;
|
||||||
@@ -128,8 +117,7 @@ CPS_ParseNTPSourceAdd(const char *line, CPS_NTP_Source *src)
|
|||||||
} else {
|
} else {
|
||||||
line += n;
|
line += n;
|
||||||
}
|
}
|
||||||
/* This MUST come before the following one ! */
|
} else if (!strcasecmp(cmd, "maxdelayratio")) {
|
||||||
} else if (!strncasecmp(cmd, "maxdelayratio", 13)) {
|
|
||||||
if (sscanf(line, "%lf%n", &src->params.max_delay_ratio, &n) != 1) {
|
if (sscanf(line, "%lf%n", &src->params.max_delay_ratio, &n) != 1) {
|
||||||
result = CPS_BadMaxdelayratio;
|
result = CPS_BadMaxdelayratio;
|
||||||
ok = 0;
|
ok = 0;
|
||||||
@@ -137,7 +125,7 @@ CPS_ParseNTPSourceAdd(const char *line, CPS_NTP_Source *src)
|
|||||||
} else {
|
} else {
|
||||||
line += n;
|
line += n;
|
||||||
}
|
}
|
||||||
} else if (!strncasecmp(cmd, "maxdelay", 8)) {
|
} else if (!strcasecmp(cmd, "maxdelay")) {
|
||||||
if (sscanf(line, "%lf%n", &src->params.max_delay, &n) != 1) {
|
if (sscanf(line, "%lf%n", &src->params.max_delay, &n) != 1) {
|
||||||
result = CPS_BadMaxdelay;
|
result = CPS_BadMaxdelay;
|
||||||
ok = 0;
|
ok = 0;
|
||||||
@@ -145,7 +133,7 @@ CPS_ParseNTPSourceAdd(const char *line, CPS_NTP_Source *src)
|
|||||||
} else {
|
} else {
|
||||||
line += n;
|
line += n;
|
||||||
}
|
}
|
||||||
} else if (!strncasecmp(cmd, "key", 3)) {
|
} else if (!strcasecmp(cmd, "key")) {
|
||||||
if (sscanf(line, "%lu%n", &src->params.authkey, &n) != 1) {
|
if (sscanf(line, "%lu%n", &src->params.authkey, &n) != 1) {
|
||||||
result = CPS_BadKey;
|
result = CPS_BadKey;
|
||||||
ok = 0;
|
ok = 0;
|
||||||
@@ -153,16 +141,16 @@ CPS_ParseNTPSourceAdd(const char *line, CPS_NTP_Source *src)
|
|||||||
} else {
|
} else {
|
||||||
line += n;
|
line += n;
|
||||||
}
|
}
|
||||||
} else if (!strncasecmp(cmd, "offline", 7)) {
|
} else if (!strcasecmp(cmd, "offline")) {
|
||||||
src->params.online = 0;
|
src->params.online = 0;
|
||||||
|
|
||||||
} else if (!strncasecmp(cmd, "auto_offline", 12)) {
|
} else if (!strcasecmp(cmd, "auto_offline")) {
|
||||||
src->params.auto_offline = 1;
|
src->params.auto_offline = 1;
|
||||||
|
|
||||||
} else if (!strncasecmp(cmd, "iburst", 6)) {
|
} else if (!strcasecmp(cmd, "iburst")) {
|
||||||
src->params.iburst = 1;
|
src->params.iburst = 1;
|
||||||
|
|
||||||
} else if (!strncasecmp(cmd, "minstratum", 10)) {
|
} else if (!strcasecmp(cmd, "minstratum")) {
|
||||||
if (sscanf(line, "%d%n", &src->params.min_stratum, &n) != 1) {
|
if (sscanf(line, "%d%n", &src->params.min_stratum, &n) != 1) {
|
||||||
result = CPS_BadMinstratum;
|
result = CPS_BadMinstratum;
|
||||||
ok = 0;
|
ok = 0;
|
||||||
@@ -171,7 +159,7 @@ CPS_ParseNTPSourceAdd(const char *line, CPS_NTP_Source *src)
|
|||||||
line += n;
|
line += n;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (!strncasecmp(cmd, "polltarget", 10)) {
|
} else if (!strcasecmp(cmd, "polltarget")) {
|
||||||
if (sscanf(line, "%d%n", &src->params.poll_target, &n) != 1) {
|
if (sscanf(line, "%d%n", &src->params.poll_target, &n) != 1) {
|
||||||
result = CPS_BadPolltarget;
|
result = CPS_BadPolltarget;
|
||||||
ok = 0;
|
ok = 0;
|
||||||
@@ -180,10 +168,10 @@ CPS_ParseNTPSourceAdd(const char *line, CPS_NTP_Source *src)
|
|||||||
line += n;
|
line += n;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (!strncasecmp(cmd, "noselect", 8)) {
|
} else if (!strcasecmp(cmd, "noselect")) {
|
||||||
src->params.sel_option = SRC_SelectNoselect;
|
src->params.sel_option = SRC_SelectNoselect;
|
||||||
|
|
||||||
} else if (!strncasecmp(cmd, "prefer", 6)) {
|
} else if (!strcasecmp(cmd, "prefer")) {
|
||||||
src->params.sel_option = SRC_SelectPrefer;
|
src->params.sel_option = SRC_SelectPrefer;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@@ -197,11 +185,8 @@ CPS_ParseNTPSourceAdd(const char *line, CPS_NTP_Source *src)
|
|||||||
} while (!done);
|
} while (!done);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ok && src->ip_addr.family == IPADDR_UNSPEC) {
|
if (ok) {
|
||||||
n = strlen(hostname);
|
src->name = strdup(hostname);
|
||||||
src->name = MallocArray(char, n + 1);
|
|
||||||
strncpy(src->name, hostname, n);
|
|
||||||
src->name[n] = '\0';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@@ -210,3 +195,87 @@ CPS_ParseNTPSourceAdd(const char *line, CPS_NTP_Source *src)
|
|||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
|
void
|
||||||
|
CPS_NormalizeLine(char *line)
|
||||||
|
{
|
||||||
|
char *p, *q;
|
||||||
|
int space = 1, first = 1;
|
||||||
|
|
||||||
|
/* Remove white-space at beginning and replace white-spaces with space char */
|
||||||
|
for (p = q = line; *p; p++) {
|
||||||
|
if (isspace(*p)) {
|
||||||
|
if (!space)
|
||||||
|
*q++ = ' ';
|
||||||
|
space = 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Discard comment lines */
|
||||||
|
if (first && strchr("!;#%", *p))
|
||||||
|
break;
|
||||||
|
|
||||||
|
*q++ = *p;
|
||||||
|
space = first = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Strip trailing space */
|
||||||
|
if (q > line && q[-1] == ' ')
|
||||||
|
q--;
|
||||||
|
|
||||||
|
*q = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
char *
|
||||||
|
CPS_SplitWord(char *line)
|
||||||
|
{
|
||||||
|
char *p = line, *q = line;
|
||||||
|
|
||||||
|
/* Skip white-space before the word */
|
||||||
|
while (*q && isspace(*q))
|
||||||
|
q++;
|
||||||
|
|
||||||
|
/* Move the word to the beginning */
|
||||||
|
while (*q && !isspace(*q))
|
||||||
|
*p++ = *q++;
|
||||||
|
|
||||||
|
/* Find the next word */
|
||||||
|
while (*q && isspace(*q))
|
||||||
|
q++;
|
||||||
|
|
||||||
|
*p = '\0';
|
||||||
|
|
||||||
|
/* Return pointer to the next word or NUL */
|
||||||
|
return q;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
CPS_ParseKey(char *line, unsigned long *id, const char **hash, char **key)
|
||||||
|
{
|
||||||
|
char *s1, *s2, *s3, *s4;
|
||||||
|
|
||||||
|
s1 = line;
|
||||||
|
s2 = CPS_SplitWord(s1);
|
||||||
|
s3 = CPS_SplitWord(s2);
|
||||||
|
s4 = CPS_SplitWord(s3);
|
||||||
|
|
||||||
|
/* Require two or three words */
|
||||||
|
if (!*s2 || *s4)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (sscanf(s1, "%lu", id) != 1)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (*s3) {
|
||||||
|
*hash = s2;
|
||||||
|
*key = s3;
|
||||||
|
} else {
|
||||||
|
*hash = "MD5";
|
||||||
|
*key = s2;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|||||||
10
cmdparse.h
10
cmdparse.h
@@ -47,15 +47,21 @@ typedef enum {
|
|||||||
} CPS_Status;
|
} CPS_Status;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
IPAddr ip_addr;
|
|
||||||
char *name;
|
char *name;
|
||||||
unsigned short port;
|
unsigned short port;
|
||||||
SourceParameters params;
|
SourceParameters params;
|
||||||
} CPS_NTP_Source;
|
} CPS_NTP_Source;
|
||||||
|
|
||||||
/* 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(const char *line, CPS_NTP_Source *src);
|
extern CPS_Status CPS_ParseNTPSourceAdd(char *line, CPS_NTP_Source *src);
|
||||||
|
|
||||||
|
/* Remove extra white-space and comments */
|
||||||
|
extern void CPS_NormalizeLine(char *line);
|
||||||
|
|
||||||
|
/* Terminate first word and return pointer to the next word */
|
||||||
|
extern char *CPS_SplitWord(char *line);
|
||||||
|
|
||||||
|
/* Parse a key from keyfile */
|
||||||
|
extern int CPS_ParseKey(char *line, unsigned long *id, const char **hash, char **key);
|
||||||
|
|
||||||
#endif /* GOT_CMDPARSE_H */
|
#endif /* GOT_CMDPARSE_H */
|
||||||
|
|||||||
12
conf.h
12
conf.h
@@ -29,6 +29,8 @@
|
|||||||
|
|
||||||
#include "addressing.h"
|
#include "addressing.h"
|
||||||
|
|
||||||
|
extern void CNF_SetRestarted(int);
|
||||||
|
|
||||||
extern char *CNF_GetRtcDevice(void);
|
extern char *CNF_GetRtcDevice(void);
|
||||||
|
|
||||||
extern void CNF_ReadFile(const char *filename);
|
extern void CNF_ReadFile(const char *filename);
|
||||||
@@ -54,12 +56,14 @@ extern int CNF_GetLogTempComp(void);
|
|||||||
extern char *CNF_GetKeysFile(void);
|
extern char *CNF_GetKeysFile(void);
|
||||||
extern char *CNF_GetRtcFile(void);
|
extern char *CNF_GetRtcFile(void);
|
||||||
extern unsigned long CNF_GetCommandKey(void);
|
extern unsigned long CNF_GetCommandKey(void);
|
||||||
|
extern int CNF_GetGenerateCommandKey(void);
|
||||||
extern int CNF_GetDumpOnExit(void);
|
extern int CNF_GetDumpOnExit(void);
|
||||||
extern int CNF_GetManualEnabled(void);
|
extern int CNF_GetManualEnabled(void);
|
||||||
extern int CNF_GetCommandPort(void);
|
extern int CNF_GetCommandPort(void);
|
||||||
extern int CNF_GetRTCOnUTC(void);
|
extern int CNF_GetRTCOnUTC(void);
|
||||||
extern int CNF_GetRTCSync(void);
|
extern int CNF_GetRTCSync(void);
|
||||||
extern void CNF_GetMakeStep(int *limit, double *threshold);
|
extern void CNF_GetMakeStep(int *limit, double *threshold);
|
||||||
|
extern void CNF_GetMaxChange(int *delay, int *ignore, double *offset);
|
||||||
extern void CNF_GetLogChange(int *enabled, double *threshold);
|
extern void CNF_GetLogChange(int *enabled, double *threshold);
|
||||||
extern void CNF_GetMailOnChange(int *enabled, double *threshold, char **user);
|
extern void CNF_GetMailOnChange(int *enabled, double *threshold, char **user);
|
||||||
extern int CNF_GetNoClientLog(void);
|
extern int CNF_GetNoClientLog(void);
|
||||||
@@ -68,15 +72,18 @@ extern void CNF_GetFallbackDrifts(int *min, int *max);
|
|||||||
extern void CNF_GetBindAddress(int family, IPAddr *addr);
|
extern void CNF_GetBindAddress(int family, IPAddr *addr);
|
||||||
extern void CNF_GetBindCommandAddress(int family, IPAddr *addr);
|
extern void CNF_GetBindCommandAddress(int family, IPAddr *addr);
|
||||||
extern char *CNF_GetPidFile(void);
|
extern char *CNF_GetPidFile(void);
|
||||||
|
extern char *CNF_GetLeapSecTimezone(void);
|
||||||
extern void CNF_GetLinuxHz(int *set, int *hz);
|
extern void CNF_GetLinuxHz(int *set, int *hz);
|
||||||
extern void CNF_GetLinuxFreqScale(int *set, double *freq_scale);
|
extern void CNF_GetLinuxFreqScale(int *set, double *freq_scale);
|
||||||
|
|
||||||
/* 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_GetCorrectionTimeRatio(void);
|
||||||
|
|
||||||
extern double CNF_GetReselectDistance(void);
|
extern double CNF_GetReselectDistance(void);
|
||||||
extern double CNF_GetStratumWeight(void);
|
extern double CNF_GetStratumWeight(void);
|
||||||
|
extern double CNF_GetCombineLimit(void);
|
||||||
|
|
||||||
extern int CNF_AllowLocalReference(int *stratum);
|
extern int CNF_AllowLocalReference(int *stratum);
|
||||||
|
|
||||||
@@ -87,4 +94,9 @@ extern int CNF_GetLockMemory(void);
|
|||||||
|
|
||||||
extern void CNF_GetTempComp(char **file, double *interval, double *T0, double *k0, double *k1, double *k2);
|
extern void CNF_GetTempComp(char **file, double *interval, double *T0, double *k0, double *k1, double *k2);
|
||||||
|
|
||||||
|
extern char *CNF_GetUser(void);
|
||||||
|
|
||||||
|
extern int CNF_GetMaxSamples(void);
|
||||||
|
extern int CNF_GetMinSamples(void);
|
||||||
|
|
||||||
#endif /* GOT_CONF_H */
|
#endif /* GOT_CONF_H */
|
||||||
|
|||||||
265
configure
vendored
265
configure
vendored
@@ -4,9 +4,12 @@
|
|||||||
# chronyd/chronyc - Programs for keeping computer clocks accurate.
|
# chronyd/chronyc - Programs for keeping computer clocks accurate.
|
||||||
#
|
#
|
||||||
# Copyright (C) Richard P. Curnow 1997-2003
|
# Copyright (C) Richard P. Curnow 1997-2003
|
||||||
|
# Copyright (C) Miroslav Lichvar 2009, 2012
|
||||||
#
|
#
|
||||||
# =======================================================================
|
# =======================================================================
|
||||||
|
|
||||||
|
rm -f config.h config.log
|
||||||
|
|
||||||
# This configure script determines the operating system type and version
|
# This configure script determines the operating system type and version
|
||||||
|
|
||||||
if [ "x${CC}" = "x" ]; then
|
if [ "x${CC}" = "x" ]; then
|
||||||
@@ -24,9 +27,7 @@ fi
|
|||||||
MYCPPFLAGS="${CPPFLAGS}"
|
MYCPPFLAGS="${CPPFLAGS}"
|
||||||
|
|
||||||
if [ "x${MYCC}" = "xgcc" ]; then
|
if [ "x${MYCC}" = "xgcc" ]; then
|
||||||
CCWARNFLAGS="-Wmissing-prototypes -Wall"
|
MYCFLAGS="${MYCFLAGS} -Wmissing-prototypes -Wall"
|
||||||
else
|
|
||||||
CCWARNFLAGS=""
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
MYLDFLAGS="${LDFLAGS}"
|
MYLDFLAGS="${LDFLAGS}"
|
||||||
@@ -42,7 +43,7 @@ test_code () {
|
|||||||
ldflags=$4
|
ldflags=$4
|
||||||
code=$5
|
code=$5
|
||||||
|
|
||||||
printf "Checking for $name : "
|
echo -n "Checking for $name : "
|
||||||
|
|
||||||
(
|
(
|
||||||
for h in $headers; do
|
for h in $headers; do
|
||||||
@@ -53,23 +54,30 @@ test_code () {
|
|||||||
echo "return 0; }"
|
echo "return 0; }"
|
||||||
) > docheck.c
|
) > docheck.c
|
||||||
|
|
||||||
$MYCC $MYCFLAGS $MYCPPFLAGS $cflags -o docheck docheck.c $ldflags $MYLDFLAGS >/dev/null 2>&1
|
echo "docheck.c:" >> config.log
|
||||||
|
cat docheck.c >> config.log
|
||||||
|
echo $MYCC $MYCFLAGS $MYCPPFLAGS $cflags -o docheck docheck.c $ldflags \
|
||||||
|
$MYLDFLAGS >> config.log
|
||||||
|
$MYCC $MYCFLAGS $MYCPPFLAGS $cflags -o docheck docheck.c $ldflags \
|
||||||
|
$MYLDFLAGS >> config.log 2>&1
|
||||||
|
|
||||||
if [ $? -eq 0 ]
|
if [ $? -eq 0 ]
|
||||||
then
|
then
|
||||||
printf "Yes\n"
|
echo "Yes"
|
||||||
result=0
|
result=0
|
||||||
else
|
else
|
||||||
printf "No\n"
|
echo "No"
|
||||||
result=1
|
result=1
|
||||||
fi
|
fi
|
||||||
rm -f docheck.c docheck
|
rm -f docheck.c docheck
|
||||||
|
echo >> config.log
|
||||||
return $result
|
return $result
|
||||||
}
|
}
|
||||||
#}}}
|
#}}}
|
||||||
#{{{ usage
|
#{{{ usage
|
||||||
usage () {
|
usage () {
|
||||||
cat <<EOF;
|
cat <<EOF
|
||||||
\`configure' configures tdl to adapt to many kinds of systems.
|
\`configure' configures this package to adapt to many kinds of systems.
|
||||||
|
|
||||||
Usage: ./configure [OPTION]...
|
Usage: ./configure [OPTION]...
|
||||||
|
|
||||||
@@ -97,10 +105,15 @@ For better control, use the options below.
|
|||||||
--readline-inc-dir=DIR Specify where readline include directory is
|
--readline-inc-dir=DIR Specify where readline include directory is
|
||||||
--readline-lib-dir=DIR Specify where readline lib directory is
|
--readline-lib-dir=DIR Specify where readline lib directory is
|
||||||
--with-ncurses-library=DIR Specify where ncurses lib directory is
|
--with-ncurses-library=DIR Specify where ncurses lib directory is
|
||||||
|
--without-nss Don't use NSS even if it is available
|
||||||
|
--without-tomcrypt Don't use libtomcrypt even if it is available
|
||||||
--disable-ipv6 Disable IPv6 support
|
--disable-ipv6 Disable IPv6 support
|
||||||
--disable-pps Disable PPS API support
|
--disable-pps Disable PPS API support
|
||||||
--disable-rtc Don't include RTC even on Linux
|
--disable-rtc Don't include RTC even on Linux
|
||||||
--disable-linuxcaps Disable Linux capabilities support
|
--disable-linuxcaps Disable Linux capabilities support
|
||||||
|
--disable-forcednsretry Don't retry on permanent DNS error
|
||||||
|
--with-sendmail=PATH Path to sendmail binary [/usr/lib/sendmail]
|
||||||
|
--enable-trace Enable tracing
|
||||||
|
|
||||||
Fine tuning of the installation directories:
|
Fine tuning of the installation directories:
|
||||||
--sysconfdir=DIR chrony.conf location [/etc]
|
--sysconfdir=DIR chrony.conf location [/etc]
|
||||||
@@ -110,6 +123,8 @@ Fine tuning of the installation directories:
|
|||||||
--infodir=DIR info documentation [DATAROOTDIR/info]
|
--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]
|
||||||
|
--chronyvardir=DIR location for chrony data [LOCALSTATEDIR/lib/chrony]
|
||||||
|
|
||||||
Overriding system detection when cross-compiling:
|
Overriding system detection when cross-compiling:
|
||||||
--host-system=OS Specify system name (uname -s)
|
--host-system=OS Specify system name (uname -s)
|
||||||
@@ -131,6 +146,15 @@ EOF
|
|||||||
|
|
||||||
}
|
}
|
||||||
#}}}
|
#}}}
|
||||||
|
#{{{
|
||||||
|
add_def () {
|
||||||
|
if [ "x$2" = "x" ]; then
|
||||||
|
echo "#define $1 1" >> config.h
|
||||||
|
else
|
||||||
|
echo "#define $1 $2" >> config.h
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
#}}}
|
||||||
|
|
||||||
# ======================================================================
|
# ======================================================================
|
||||||
|
|
||||||
@@ -150,7 +174,10 @@ SYSDEFS=""
|
|||||||
feat_readline=1
|
feat_readline=1
|
||||||
try_readline=1
|
try_readline=1
|
||||||
try_editline=1
|
try_editline=1
|
||||||
|
try_nss=1
|
||||||
|
try_tomcrypt=1
|
||||||
feat_rtc=1
|
feat_rtc=1
|
||||||
|
try_rtc=0
|
||||||
feat_linuxcaps=1
|
feat_linuxcaps=1
|
||||||
try_linuxcaps=0
|
try_linuxcaps=0
|
||||||
readline_lib=""
|
readline_lib=""
|
||||||
@@ -160,12 +187,14 @@ feat_ipv6=1
|
|||||||
feat_pps=1
|
feat_pps=1
|
||||||
try_setsched=0
|
try_setsched=0
|
||||||
try_lockmem=0
|
try_lockmem=0
|
||||||
|
feat_forcednsretry=1
|
||||||
|
mail_program="/usr/lib/sendmail"
|
||||||
|
|
||||||
for option
|
for option
|
||||||
do
|
do
|
||||||
case "$option" in
|
case "$option" in
|
||||||
--trace )
|
--enable-trace )
|
||||||
EXTRA_DEFS="-DTRACEON"
|
add_def TRACEON
|
||||||
;;
|
;;
|
||||||
--disable-readline )
|
--disable-readline )
|
||||||
feat_readline=0
|
feat_readline=0
|
||||||
@@ -212,6 +241,12 @@ do
|
|||||||
--docdir=* )
|
--docdir=* )
|
||||||
SETDOCDIR=`echo $option | sed -e 's/^.*=//;'`
|
SETDOCDIR=`echo $option | sed -e 's/^.*=//;'`
|
||||||
;;
|
;;
|
||||||
|
--localstatedir=* )
|
||||||
|
SETLOCALSTATEDIR=`echo $option | sed -e 's/^.*=//;'`
|
||||||
|
;;
|
||||||
|
--chronyvardir=* )
|
||||||
|
SETCHRONYVARDIR=`echo $option | sed -e 's/^.*=//;'`
|
||||||
|
;;
|
||||||
--disable-rtc)
|
--disable-rtc)
|
||||||
feat_rtc=0
|
feat_rtc=0
|
||||||
;;
|
;;
|
||||||
@@ -224,6 +259,18 @@ do
|
|||||||
--disable-linuxcaps)
|
--disable-linuxcaps)
|
||||||
feat_linuxcaps=0
|
feat_linuxcaps=0
|
||||||
;;
|
;;
|
||||||
|
--disable-forcednsretry)
|
||||||
|
feat_forcednsretry=0
|
||||||
|
;;
|
||||||
|
--with-sendmail=* )
|
||||||
|
mail_program=`echo $option | sed -e 's/^.*=//;'`
|
||||||
|
;;
|
||||||
|
--without-nss )
|
||||||
|
try_nss=0
|
||||||
|
;;
|
||||||
|
--without-tomcrypt )
|
||||||
|
try_tomcrypt=0
|
||||||
|
;;
|
||||||
--host-system=* )
|
--host-system=* )
|
||||||
OPERATINGSYSTEM=`echo $option | sed -e 's/^.*=//;'`
|
OPERATINGSYSTEM=`echo $option | sed -e 's/^.*=//;'`
|
||||||
;;
|
;;
|
||||||
@@ -250,37 +297,30 @@ case $SYSTEM in
|
|||||||
4.* )
|
4.* )
|
||||||
EXTRA_OBJECTS="sys_sunos.o strerror.o"
|
EXTRA_OBJECTS="sys_sunos.o strerror.o"
|
||||||
EXTRA_LIBS="-lkvm"
|
EXTRA_LIBS="-lkvm"
|
||||||
SYSDEFS="-DSUNOS"
|
add_def SUNOS
|
||||||
echo "Configuring for SunOS (" $SYSTEM "version" $VERSION ")"
|
echo "Configuring for SunOS (" $SYSTEM "version" $VERSION ")"
|
||||||
;;
|
;;
|
||||||
5.* )
|
5.* )
|
||||||
EXTRA_OBJECTS="sys_solaris.o"
|
EXTRA_OBJECTS="sys_solaris.o"
|
||||||
EXTRA_LIBS="-lsocket -lnsl -lkvm -lelf"
|
EXTRA_LIBS="-lsocket -lnsl -lkvm -lelf"
|
||||||
EXTRA_CLI_LIBS="-lsocket -lnsl"
|
EXTRA_CLI_LIBS="-lsocket -lnsl"
|
||||||
SYSDEFS="-DSOLARIS"
|
add_def SOLARIS
|
||||||
echo "Configuring for Solaris (" $SYSTEM "SunOS version" $VERSION ")"
|
echo "Configuring for Solaris (" $SYSTEM "SunOS version" $VERSION ")"
|
||||||
if [ $VERSION = "5.3" ]; then
|
|
||||||
SYSDEFS="$SYSDEFS -DHAS_NO_BZERO"
|
|
||||||
echo "Using memset() instead of bzero()"
|
|
||||||
fi
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
;;
|
;;
|
||||||
Linux* )
|
Linux* )
|
||||||
EXTRA_OBJECTS="sys_linux.o wrap_adjtimex.o"
|
EXTRA_OBJECTS="sys_linux.o wrap_adjtimex.o"
|
||||||
if [ $feat_rtc -eq 1 ] ; then
|
|
||||||
EXTRA_OBJECTS="$EXTRA_OBJECTS rtc_linux.o"
|
|
||||||
EXTRA_DEFS="$EXTRA_DEFS -DFEAT_RTC=1"
|
|
||||||
fi
|
|
||||||
try_linuxcaps=1
|
try_linuxcaps=1
|
||||||
|
try_rtc=1
|
||||||
try_setsched=1
|
try_setsched=1
|
||||||
try_lockmem=1
|
try_lockmem=1
|
||||||
SYSDEFS="-DLINUX"
|
add_def LINUX
|
||||||
echo "Configuring for " $SYSTEM
|
echo "Configuring for " $SYSTEM
|
||||||
if [ "${MACHINE}" = "alpha" ]; then
|
if [ "${MACHINE}" = "alpha" ]; then
|
||||||
echo "Enabling -mieee"
|
echo "Enabling -mieee"
|
||||||
# FIXME: Should really test for GCC
|
# FIXME: Should really test for GCC
|
||||||
SYSDEFS="$SYSDEFS -mieee -DALPHA"
|
MYCFLAGS="$MYCFLAGS -mieee"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
|
||||||
@@ -289,7 +329,7 @@ case $SYSTEM in
|
|||||||
# be supported with the SunOS 4.x driver files.
|
# be supported with the SunOS 4.x driver files.
|
||||||
EXTRA_OBJECTS="sys_sunos.o strerror.o"
|
EXTRA_OBJECTS="sys_sunos.o strerror.o"
|
||||||
EXTRA_LIBS="-lkvm"
|
EXTRA_LIBS="-lkvm"
|
||||||
SYSDEFS="-DSUNOS"
|
add_def SUNOS
|
||||||
echo "Configuring for $SYSTEM (using SunOS driver)"
|
echo "Configuring for $SYSTEM (using SunOS driver)"
|
||||||
;;
|
;;
|
||||||
NetBSD-* )
|
NetBSD-* )
|
||||||
@@ -304,13 +344,13 @@ case $SYSTEM in
|
|||||||
EXTRA_OBJECTS="sys_solaris.o"
|
EXTRA_OBJECTS="sys_solaris.o"
|
||||||
EXTRA_LIBS="-lsocket -lnsl -lkvm -lelf"
|
EXTRA_LIBS="-lsocket -lnsl -lkvm -lelf"
|
||||||
EXTRA_CLI_LIBS="-lsocket -lnsl"
|
EXTRA_CLI_LIBS="-lsocket -lnsl"
|
||||||
SYSDEFS="-DSOLARIS"
|
add_def SOLARIS
|
||||||
echo "Configuring for Solaris (" $SYSTEM "SunOS version" $VERSION ")"
|
echo "Configuring for Solaris (" $SYSTEM "SunOS version" $VERSION ")"
|
||||||
;;
|
;;
|
||||||
CYGWIN32_NT-i[3456]86 )
|
CYGWIN32_NT-i[3456]86 )
|
||||||
EXTRA_OBJECTS="sys_winnt.o"
|
EXTRA_OBJECTS="sys_winnt.o"
|
||||||
EXTRA_LIBS=""
|
EXTRA_LIBS=""
|
||||||
SYSDEFS="-DWINNT"
|
add_def WINNT
|
||||||
echo "Configuring for Windows NT (Cygwin32)"
|
echo "Configuring for Windows NT (Cygwin32)"
|
||||||
;;
|
;;
|
||||||
* )
|
* )
|
||||||
@@ -326,17 +366,17 @@ else
|
|||||||
if test_code 'math in -lm' 'math.h' '' '-lm' "$MATHCODE"; then
|
if test_code 'math in -lm' 'math.h' '' '-lm' "$MATHCODE"; then
|
||||||
LIBS="-lm"
|
LIBS="-lm"
|
||||||
else
|
else
|
||||||
printf "Can't compile/link a program which uses sqrt(), log(), pow(), bailing out\n"
|
echo "Can't compile/link a program which uses sqrt(), log(), pow(), bailing out"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if test_code '<stdint.h>' 'stdint.h' '' '' ''; then
|
if test_code '<stdint.h>' 'stdint.h' '' '' ''; then
|
||||||
SYSDEFS="${SYSDEFS} -DHAS_STDINT_H"
|
add_def HAS_STDINT_H
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if test_code '<inttypes.h>' 'inttypes.h' '' '' ''; then
|
if test_code '<inttypes.h>' 'inttypes.h' '' '' ''; then
|
||||||
SYSDEFS="${SYSDEFS} -DHAS_INTTYPES_H"
|
add_def HAS_INTTYPES_H
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $feat_ipv6 = "1" ] && \
|
if [ $feat_ipv6 = "1" ] && \
|
||||||
@@ -346,17 +386,42 @@ if [ $feat_ipv6 = "1" ] && \
|
|||||||
n.sin6_addr = in6addr_any;
|
n.sin6_addr = in6addr_any;
|
||||||
return !inet_ntop(AF_INET6, &n.sin6_addr.s6_addr, p, sizeof(p));'
|
return !inet_ntop(AF_INET6, &n.sin6_addr.s6_addr, p, sizeof(p));'
|
||||||
then
|
then
|
||||||
SYSDEFS="${SYSDEFS} -DHAVE_IPV6"
|
add_def HAVE_IPV6
|
||||||
|
if test_code 'in6_pktinfo' 'sys/socket.h netinet/in.h' '' '' '
|
||||||
|
return sizeof(struct in6_pktinfo);'
|
||||||
|
then
|
||||||
|
add_def HAVE_IN6_PKTINFO
|
||||||
|
else
|
||||||
|
if test_code 'in6_pktinfo with _GNU_SOURCE' 'sys/socket.h netinet/in.h' \
|
||||||
|
'-D_GNU_SOURCE' '' 'return sizeof(struct in6_pktinfo);'
|
||||||
|
then
|
||||||
|
add_def _GNU_SOURCE
|
||||||
|
add_def HAVE_IN6_PKTINFO
|
||||||
|
fi
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $feat_pps = "1" ] && \
|
timepps_h=""
|
||||||
test_code 'PPS API' 'timepps.h' '' '' '
|
if [ $feat_pps = "1" ]; then
|
||||||
|
if test_code '<sys/timepps.h>' 'sys/timepps.h' '' '' ''; then
|
||||||
|
timepps_h="sys/timepps.h"
|
||||||
|
add_def HAVE_SYS_TIMEPPS_H
|
||||||
|
else
|
||||||
|
if test_code '<timepps.h>' 'timepps.h' '' '' ''; then
|
||||||
|
timepps_h="timepps.h"
|
||||||
|
add_def HAVE_TIMEPPS_H
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "x$timepps_h" != "x" ] && \
|
||||||
|
test_code 'PPSAPI' "string.h $timepps_h" '' '' '
|
||||||
pps_handle_t h;
|
pps_handle_t h;
|
||||||
pps_info_t i;
|
pps_info_t i;
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
return time_pps_fetch(&h, PPS_TSFMT_TSPEC, &i, &ts);'
|
return time_pps_fetch(h, PPS_TSFMT_TSPEC, &i, &ts);'
|
||||||
then
|
then
|
||||||
SYSDEFS="${SYSDEFS} -DHAVE_PPSAPI"
|
add_def HAVE_PPSAPI
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $feat_linuxcaps = "1" ] && [ $try_linuxcaps = "1" ] && \
|
if [ $feat_linuxcaps = "1" ] && [ $try_linuxcaps = "1" ] && \
|
||||||
@@ -366,10 +431,18 @@ if [ $feat_linuxcaps = "1" ] && [ $try_linuxcaps = "1" ] && \
|
|||||||
'' '-lcap' \
|
'' '-lcap' \
|
||||||
'prctl(PR_SET_KEEPCAPS, 1);cap_set_proc(cap_from_text("cap_sys_time=ep"));'
|
'prctl(PR_SET_KEEPCAPS, 1);cap_set_proc(cap_from_text("cap_sys_time=ep"));'
|
||||||
then
|
then
|
||||||
EXTRA_DEFS="${EXTRA_DEFS} -DFEAT_LINUXCAPS=1"
|
add_def FEAT_LINUXCAPS
|
||||||
EXTRA_LIBS="-lcap"
|
EXTRA_LIBS="-lcap"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ $feat_rtc = "1" ] && [ $try_rtc = "1" ] && \
|
||||||
|
test_code '<linux/rtc.h>' 'sys/ioctl.h linux/rtc.h' '' '' \
|
||||||
|
'ioctl(1, RTC_UIE_ON&RTC_UIE_OFF&RTC_RD_TIME&RTC_SET_TIME, 0&RTC_UF);'
|
||||||
|
then
|
||||||
|
EXTRA_OBJECTS="$EXTRA_OBJECTS rtc_linux.o"
|
||||||
|
add_def FEAT_RTC
|
||||||
|
fi
|
||||||
|
|
||||||
if [ $try_setsched = "1" ] && \
|
if [ $try_setsched = "1" ] && \
|
||||||
test_code \
|
test_code \
|
||||||
'sched_setscheduler()' \
|
'sched_setscheduler()' \
|
||||||
@@ -378,7 +451,7 @@ if [ $try_setsched = "1" ] && \
|
|||||||
sched_get_priority_max(SCHED_FIFO);
|
sched_get_priority_max(SCHED_FIFO);
|
||||||
sched_setscheduler(0, SCHED_FIFO, &sched);'
|
sched_setscheduler(0, SCHED_FIFO, &sched);'
|
||||||
then
|
then
|
||||||
SYSDEFS="${SYSDEFS} -DHAVE_SCHED_SETSCHEDULER"
|
add_def HAVE_SCHED_SETSCHEDULER
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $try_lockmem = "1" ] && \
|
if [ $try_lockmem = "1" ] && \
|
||||||
@@ -389,7 +462,12 @@ if [ $try_lockmem = "1" ] && \
|
|||||||
setrlimit(RLIMIT_MEMLOCK, &rlim);
|
setrlimit(RLIMIT_MEMLOCK, &rlim);
|
||||||
mlockall(MCL_CURRENT|MCL_FUTURE);'
|
mlockall(MCL_CURRENT|MCL_FUTURE);'
|
||||||
then
|
then
|
||||||
SYSDEFS="${SYSDEFS} -DHAVE_MLOCKALL"
|
add_def HAVE_MLOCKALL
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $feat_forcednsretry = "1" ]
|
||||||
|
then
|
||||||
|
add_def FORCE_DNSRETRY
|
||||||
fi
|
fi
|
||||||
|
|
||||||
READLINE_COMPILE=""
|
READLINE_COMPILE=""
|
||||||
@@ -400,22 +478,66 @@ if [ $feat_readline = "1" ]; then
|
|||||||
"$readline_inc" "$readline_lib -ledit" \
|
"$readline_inc" "$readline_lib -ledit" \
|
||||||
'add_history(readline("prompt"));'
|
'add_history(readline("prompt"));'
|
||||||
then
|
then
|
||||||
READLINE_COMPILE="-DFEAT_READLINE=1 -DUSE_EDITLINE=1 $readline_inc"
|
add_def FEAT_READLINE
|
||||||
|
add_def USE_EDITLINE
|
||||||
|
READLINE_COMPILE="$readline_inc"
|
||||||
READLINE_LINK="$readline_lib -ledit"
|
READLINE_LINK="$readline_lib -ledit"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "x$READLINE_LINK" = "x" ] && [ $try_readline = "1" ]; then
|
if [ "x$READLINE_LINK" = "x" ] && [ $try_readline = "1" ]; then
|
||||||
if test_code readline 'stdio.h readline/readline.h readline/history.h' \
|
if test_code readline 'stdio.h readline/readline.h readline/history.h' \
|
||||||
|
"$readline_inc" "$readline_lib $ncurses_lib -lreadline" \
|
||||||
|
'add_history(readline("prompt"));'
|
||||||
|
then
|
||||||
|
add_def FEAT_READLINE
|
||||||
|
READLINE_COMPILE="$readline_inc"
|
||||||
|
READLINE_LINK="$readline_lib $ncurses_lib -lreadline"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "x$READLINE_LINK" = "x" ] && [ $try_readline = "1" ]; then
|
||||||
|
if test_code 'readline with -lncurses' \
|
||||||
|
'stdio.h readline/readline.h readline/history.h' \
|
||||||
"$readline_inc" "$readline_lib $ncurses_lib -lreadline -lncurses" \
|
"$readline_inc" "$readline_lib $ncurses_lib -lreadline -lncurses" \
|
||||||
'add_history(readline("prompt"));'
|
'add_history(readline("prompt"));'
|
||||||
then
|
then
|
||||||
READLINE_COMPILE="-DFEAT_READLINE=1 $readline_inc"
|
add_def FEAT_READLINE
|
||||||
|
READLINE_COMPILE="$readline_inc"
|
||||||
READLINE_LINK="$readline_lib $ncurses_lib -lreadline -lncurses"
|
READLINE_LINK="$readline_lib $ncurses_lib -lreadline -lncurses"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
HASH_OBJ="hash_intmd5.o"
|
||||||
|
HASH_COMPILE=""
|
||||||
|
HASH_LINK=""
|
||||||
|
|
||||||
|
if [ $try_nss = "1" ]; then
|
||||||
|
test_cflags="`pkg-config --cflags nss`"
|
||||||
|
test_link="`pkg-config --libs-only-L nss` -lfreebl3"
|
||||||
|
if test_code 'NSS' 'nss.h hasht.h nsslowhash.h' \
|
||||||
|
"$test_cflags" "$test_link" \
|
||||||
|
'NSSLOWHASH_Begin(NSSLOWHASH_NewContext(NSSLOW_Init(), HASH_AlgSHA512));'
|
||||||
|
then
|
||||||
|
HASH_OBJ="hash_nss.o"
|
||||||
|
HASH_COMPILE="$test_cflags"
|
||||||
|
HASH_LINK="$test_link"
|
||||||
|
add_def GENERATE_SHA1_KEY
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "x$HASH_LINK" = "x" ] && [ $try_tomcrypt = "1" ]; then
|
||||||
|
if test_code 'tomcrypt' 'tomcrypt.h' '-I/usr/include/tomcrypt' '-ltomcrypt' \
|
||||||
|
'hash_memory_multi(find_hash("md5"), NULL, NULL, NULL, 0, NULL, 0);'
|
||||||
|
then
|
||||||
|
HASH_OBJ="hash_tomcrypt.o"
|
||||||
|
HASH_COMPILE="-I/usr/include/tomcrypt"
|
||||||
|
HASH_LINK="-ltomcrypt"
|
||||||
|
add_def GENERATE_SHA1_KEY
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
SYSCONFDIR=/etc
|
SYSCONFDIR=/etc
|
||||||
if [ "x$SETSYSCONFDIR" != "x" ]; then
|
if [ "x$SETSYSCONFDIR" != "x" ]; then
|
||||||
SYSCONFDIR=$SETSYSCONFDIR
|
SYSCONFDIR=$SETSYSCONFDIR
|
||||||
@@ -461,26 +583,51 @@ if [ "x$SETDOCDIR" != "x" ]; then
|
|||||||
DOCDIR=$SETDOCDIR
|
DOCDIR=$SETDOCDIR
|
||||||
fi
|
fi
|
||||||
|
|
||||||
sed -e "s%@EXTRA_OBJECTS@%${EXTRA_OBJECTS}%;\
|
LOCALSTATEDIR=/var
|
||||||
s%@CC@%${MYCC}%;\
|
if [ "x$SETLOCALSTATEDIR" != "x" ]; then
|
||||||
s%@CFLAGS@%${MYCFLAGS}%;\
|
LOCALSTATEDIR=$SETLOCALSTATEDIR
|
||||||
s%@CCWARNFLAGS@%${CCWARNFLAGS}%;\
|
fi
|
||||||
s%@CPPFLAGS@%${CPPFLAGS}%;\
|
|
||||||
s%@LIBS@%${LIBS}%;\
|
CHRONYVARDIR=${LOCALSTATEDIR}/lib/chrony
|
||||||
s%@LDFLAGS@%${MYLDFLAGS}%;\
|
if [ "x$SETCHRONYVARDIR" != "x" ]; then
|
||||||
s%@EXTRA_LIBS@%${EXTRA_LIBS}%;\
|
CHRONYVARDIR=$SETCHRONYVARDIR
|
||||||
s%@SYSDEFS@%${SYSDEFS}%;\
|
fi
|
||||||
s%@EXTRA_DEFS@%${EXTRA_DEFS}%;\
|
|
||||||
s%@EXTRA_CLI_LIBS@%${EXTRA_CLI_LIBS}%;\
|
add_def DEFAULT_CONF_FILE "\"$SYSCONFDIR/chrony.conf\""
|
||||||
s%@READLINE_COMPILE@%${READLINE_COMPILE}%;\
|
add_def MAIL_PROGRAM "\"$mail_program\""
|
||||||
s%@READLINE_LINK@%${READLINE_LINK}%;\
|
|
||||||
s%@SYSCONFDIR@%${SYSCONFDIR}%;\
|
if [ -f version.txt ]; then
|
||||||
s%@BINDIR@%${BINDIR}%;\
|
add_def CHRONY_VERSION "\"`cat version.txt`\""
|
||||||
s%@SBINDIR@%${SBINDIR}%;\
|
else
|
||||||
s%@DOCDIR@%${DOCDIR}%;\
|
add_def CHRONY_VERSION "\"DEVELOPMENT\""
|
||||||
s%@MANDIR@%${MANDIR}%;\
|
fi
|
||||||
s%@INFODIR@%${INFODIR}%;"\
|
|
||||||
< Makefile.in > Makefile
|
for f in Makefile chrony.conf.5 chrony.texi chronyc.1 chronyd.8
|
||||||
|
do
|
||||||
|
echo Creating $f
|
||||||
|
sed -e "s%@EXTRA_OBJECTS@%${EXTRA_OBJECTS}%;\
|
||||||
|
s%@CC@%${MYCC}%;\
|
||||||
|
s%@CFLAGS@%${MYCFLAGS}%;\
|
||||||
|
s%@CPPFLAGS@%${CPPFLAGS}%;\
|
||||||
|
s%@LIBS@%${LIBS}%;\
|
||||||
|
s%@LDFLAGS@%${MYLDFLAGS}%;\
|
||||||
|
s%@EXTRA_LIBS@%${EXTRA_LIBS}%;\
|
||||||
|
s%@EXTRA_CLI_LIBS@%${EXTRA_CLI_LIBS}%;\
|
||||||
|
s%@READLINE_COMPILE@%${READLINE_COMPILE}%;\
|
||||||
|
s%@READLINE_LINK@%${READLINE_LINK}%;\
|
||||||
|
s%@HASH_OBJ@%${HASH_OBJ}%;\
|
||||||
|
s%@HASH_LINK@%${HASH_LINK}%;\
|
||||||
|
s%@HASH_COMPILE@%${HASH_COMPILE}%;\
|
||||||
|
s%@SYSCONFDIR@%${SYSCONFDIR}%;\
|
||||||
|
s%@BINDIR@%${BINDIR}%;\
|
||||||
|
s%@SBINDIR@%${SBINDIR}%;\
|
||||||
|
s%@DOCDIR@%${DOCDIR}%;\
|
||||||
|
s%@MANDIR@%${MANDIR}%;\
|
||||||
|
s%@INFODIR@%${INFODIR}%;\
|
||||||
|
s%@LOCALSTATEDIR@%${LOCALSTATEDIR}%;\
|
||||||
|
s%@CHRONYVARDIR@%${CHRONYVARDIR}%;"\
|
||||||
|
< ${f}.in > $f
|
||||||
|
done
|
||||||
|
|
||||||
# =======================================================================
|
# =======================================================================
|
||||||
# vim:et:sw=2:ht=2:sts=2:fdm=marker:cms=#%s
|
# vim:et:sw=2:ht=2:sts=2:fdm=marker:cms=#%s
|
||||||
|
|||||||
@@ -40,21 +40,21 @@
|
|||||||
# more 'NTP servers'. You will probably find that your Internet Service
|
# more 'NTP servers'. You will probably find that your Internet Service
|
||||||
# Provider or company have one or more NTP servers that you can specify.
|
# Provider or company have one or more NTP servers that you can specify.
|
||||||
# Failing that, there are a lot of public NTP servers. There is a list
|
# Failing that, there are a lot of public NTP servers. There is a list
|
||||||
# you can access at
|
# you can access at http://support.ntp.org/bin/view/Servers/WebHome or
|
||||||
# http://www.eecis.udel.edu/~mills/ntp/servers.htm.
|
# you can use servers from the pool.ntp.org project.
|
||||||
|
|
||||||
! server ntp0.your-isp.com
|
! server 0.pool.ntp.org iburst
|
||||||
! server ntp1.your-isp.com
|
! server 1.pool.ntp.org iburst
|
||||||
! server ntp.public-server.org
|
! server 2.pool.ntp.org iburst
|
||||||
|
|
||||||
# However, for dial-up use you probably want these instead. The word
|
# However, for dial-up use you probably want these instead. The word
|
||||||
# 'offline' means that the server is not visible at boot time. Use
|
# 'offline' means that the server is not visible at boot time. Use
|
||||||
# chronyc's 'online' command to tell chronyd that these servers have
|
# chronyc's 'online' command to tell chronyd that these servers have
|
||||||
# become visible after you go on-line.
|
# become visible after you go on-line.
|
||||||
|
|
||||||
! server ntp0.your-isp.com offline
|
! server 0.pool.ntp.org offline
|
||||||
! server ntp1.your-isp.com offline
|
! server 1.pool.ntp.org offline
|
||||||
! server ntp.public-server.org offline
|
! server 2.pool.ntp.org offline
|
||||||
|
|
||||||
# You may want to specify NTP 'peers' instead. If you run a network
|
# You may want to specify NTP 'peers' instead. If you run a network
|
||||||
# with a lot of computers and want several computers running chrony to
|
# with a lot of computers and want several computers running chrony to
|
||||||
@@ -89,7 +89,7 @@
|
|||||||
# immediately so that it doesn't gain or lose any more time. You
|
# immediately so that it doesn't gain or lose any more time. You
|
||||||
# generally want this, so it is uncommented.
|
# generally want this, so it is uncommented.
|
||||||
|
|
||||||
driftfile /etc/chrony.drift
|
driftfile /var/lib/chrony/drift
|
||||||
|
|
||||||
# If you want to use the program called chronyc to configure aspects of
|
# If you want to use the program called chronyc to configure aspects of
|
||||||
# chronyd's operation once it is running (e.g. tell it the Internet link
|
# chronyd's operation once it is running (e.g. tell it the Internet link
|
||||||
@@ -122,7 +122,7 @@ commandkey 1
|
|||||||
# Enable these two options to use this.
|
# Enable these two options to use this.
|
||||||
|
|
||||||
! dumponexit
|
! dumponexit
|
||||||
! dumpdir /var/log/chrony
|
! dumpdir /var/lib/chrony
|
||||||
|
|
||||||
# chronyd writes its process ID to a file. If you try to start a second
|
# chronyd writes its process ID to a file. If you try to start a second
|
||||||
# copy of chronyd, it will detect that the process named in the file is
|
# copy of chronyd, it will detect that the process named in the file is
|
||||||
@@ -133,17 +133,16 @@ commandkey 1
|
|||||||
|
|
||||||
#######################################################################
|
#######################################################################
|
||||||
### INITIAL CLOCK CORRECTION
|
### INITIAL CLOCK CORRECTION
|
||||||
# This option is only useful if your NTP servers are visible at boot
|
# This option is useful to quickly correct the clock on start if it's
|
||||||
# time. This probably means you are on a LAN. If so, the following
|
# off by a large amount. The value '10' means that if the error is less
|
||||||
# option will choose the best-looking of the servers and correct the
|
|
||||||
# system time to that. The value '10' means that if the error is less
|
|
||||||
# than 10 seconds, it will be gradually removed by speeding up or
|
# than 10 seconds, it will be gradually removed by speeding up or
|
||||||
# slowing down your computer's clock until it is correct. If the error
|
# slowing down your computer's clock until it is correct. If the error
|
||||||
# is above 10 seconds, an immediate time jump will be applied to correct
|
# is above 10 seconds, an immediate time jump will be applied to correct
|
||||||
# it. Some software can get upset if the system clock jumps (especially
|
# it. The value '1' means the step is allowed only on the first update
|
||||||
# backwards), so be careful!
|
# of the clock. Some software can get upset if the system clock jumps
|
||||||
|
# (especially backwards), so be careful!
|
||||||
|
|
||||||
! initstepslew 10 ntp0.your-company.com ntp1.your-company.com ntp2.your-company.com
|
! makestep 10 1
|
||||||
|
|
||||||
#######################################################################
|
#######################################################################
|
||||||
### LOGGING
|
### LOGGING
|
||||||
@@ -255,13 +254,6 @@ commandkey 1
|
|||||||
# put into chronyc to allow you to modify chronyd's parameters. By
|
# put into chronyc to allow you to modify chronyd's parameters. By
|
||||||
# default all you can do is view information about chronyd's operation.
|
# default all you can do is view information about chronyd's operation.
|
||||||
|
|
||||||
# Some people have reported that the need the following line to allow
|
|
||||||
# chronyc to work even on the same machine. This should not be
|
|
||||||
# necessary, and the problem is being investigated. You can leave this
|
|
||||||
# line enabled, as it's benign otherwise.
|
|
||||||
|
|
||||||
cmdallow 127.0.0.1
|
|
||||||
|
|
||||||
#######################################################################
|
#######################################################################
|
||||||
### REAL TIME CLOCK
|
### REAL TIME CLOCK
|
||||||
# chronyd can characterise the system's real-time clock. This is the
|
# chronyd can characterise the system's real-time clock. This is the
|
||||||
@@ -273,7 +265,7 @@ cmdallow 127.0.0.1
|
|||||||
# You need to have 'enhanced RTC support' compiled into your Linux
|
# You need to have 'enhanced RTC support' compiled into your Linux
|
||||||
# kernel. (Note, these options apply only to Linux.)
|
# kernel. (Note, these options apply only to Linux.)
|
||||||
|
|
||||||
! rtcfile /etc/chrony.rtc
|
! rtcfile /var/lib/chrony/rtc
|
||||||
|
|
||||||
# Your RTC can be set to keep Universal Coordinated Time (UTC) or local
|
# Your RTC can be set to keep Universal Coordinated Time (UTC) or local
|
||||||
# time. (Local time means UTC +/- the effect of your timezone.) If you
|
# time. (Local time means UTC +/- the effect of your timezone.) If you
|
||||||
|
|||||||
46
examples/chrony.conf.example2
Normal file
46
examples/chrony.conf.example2
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
# Use public servers from the pool.ntp.org project.
|
||||||
|
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
|
||||||
|
server 0.pool.ntp.org iburst
|
||||||
|
server 1.pool.ntp.org iburst
|
||||||
|
server 2.pool.ntp.org iburst
|
||||||
|
server 3.pool.ntp.org iburst
|
||||||
|
|
||||||
|
# Ignore stratum in source selection.
|
||||||
|
stratumweight 0
|
||||||
|
|
||||||
|
# Record the rate at which the system clock gains/losses time.
|
||||||
|
driftfile /var/lib/chrony/drift
|
||||||
|
|
||||||
|
# Enable kernel RTC synchronization.
|
||||||
|
rtcsync
|
||||||
|
|
||||||
|
# In first three updates step the system clock instead of slew
|
||||||
|
# if the adjustment is larger than 10 seconds.
|
||||||
|
makestep 10 3
|
||||||
|
|
||||||
|
# Allow NTP client access from local network.
|
||||||
|
#allow 192.168/16
|
||||||
|
|
||||||
|
# Listen for commands only on localhost.
|
||||||
|
bindcmdaddress 127.0.0.1
|
||||||
|
bindcmdaddress ::1
|
||||||
|
|
||||||
|
# Serve time even if not synchronized to any NTP server.
|
||||||
|
#local stratum 10
|
||||||
|
|
||||||
|
keyfile /etc/chrony.keys
|
||||||
|
|
||||||
|
# Specify the key used as password for chronyc.
|
||||||
|
commandkey 1
|
||||||
|
|
||||||
|
# Generate command key if missing.
|
||||||
|
generatecommandkey
|
||||||
|
|
||||||
|
# Disable logging of client accesses.
|
||||||
|
noclientlog
|
||||||
|
|
||||||
|
# Send a message to syslog if a clock adjustment is larger than 0.5 seconds.
|
||||||
|
logchange 0.5
|
||||||
|
|
||||||
|
logdir /var/log/chrony
|
||||||
|
#log measurements statistics tracking
|
||||||
@@ -1,26 +1,29 @@
|
|||||||
#######################################################################
|
#######################################################################
|
||||||
#
|
#
|
||||||
# This is an example chrony keys file. You should copy it to /etc/chrony.keys
|
# This is an example chrony keys file. You should copy it to /etc/chrony.keys
|
||||||
# after editing it to set up the key(s) you want to use. In most situations,
|
# after editing it to set up the key(s) you want to use. It should be readable
|
||||||
# you will require a single key (the 'commandkey') so that you can supply a
|
# only by root or the user chronyd drops the root privileges to. In most
|
||||||
# password to chronyc to enable you to modify chronyd's operation whilst it is
|
# situations, you will require a single key (the 'commandkey') so that you can
|
||||||
# running.
|
# supply a password to chronyc to enable you to modify chronyd's operation
|
||||||
|
# whilst it is running.
|
||||||
#
|
#
|
||||||
# Copyright 2002 Richard P. Curnow
|
# Copyright 2002 Richard P. Curnow
|
||||||
#
|
#
|
||||||
#######################################################################
|
######################################################################
|
||||||
# A valid key line looks like this
|
|
||||||
|
|
||||||
1 a_key
|
# Examples of valid keys:
|
||||||
|
|
||||||
# It must consist of an integer, followed by whitespace, followed by a block of
|
#1 ALongAndRandomPassword
|
||||||
# text with no spaces in it. (You cannot put a space in a key). If you wanted
|
#2 MD5 HEX:B028F91EA5C38D06C2E140B26C7F41EC
|
||||||
# to use the above line as your commandkey (i.e. chronyc password), you would
|
#3 SHA1 HEX:1DC764E0791B11FA67EFC7ECBC4B0D73F68A070C
|
||||||
# put the following line into chrony.conf (remove the # from the start):
|
|
||||||
|
|
||||||
# commandkey 1
|
# The keys should be random for maximum security. If you wanted to use a key
|
||||||
|
# with ID 1 as your commandkey (i.e. chronyc password) you would put
|
||||||
|
# "commandkey 1" into chrony.conf. If no commandkey is present in the keys
|
||||||
|
# file and the generatecommandkey directive is specified in chrony.conf,
|
||||||
|
# a random commandkey will be generated and added to the keys file
|
||||||
|
# automatically on chronyd start.
|
||||||
|
|
||||||
# You might want to define more keys if you use the MD5 authentication facility
|
# You might want to define more keys if you use the authentication facility
|
||||||
# in the network time protocol to authenticate request/response packets between
|
# in the network time protocol to authenticate request/response packets between
|
||||||
# trusted clients and servers.
|
# trusted clients and servers.
|
||||||
|
|
||||||
|
|||||||
71
faq.txt
71
faq.txt
@@ -68,7 +68,7 @@ support hardware reference clocks to your computer, then xntpd will work fine.
|
|||||||
Apart from not supporting hardware clocks, chrony will work fine too.
|
Apart from not supporting hardware clocks, chrony will work fine too.
|
||||||
|
|
||||||
If your computer connects to the 'net for 5 minutes once a day (or something
|
If your computer connects to the 'net for 5 minutes once a day (or something
|
||||||
like that), or you turn your (Linux v2.0) computer off when you're not using
|
like that), or you turn your Linux computer off when you're not using
|
||||||
it, or you want to use NTP on an isolated network with no hardware clocks in
|
it, or you want to use NTP on an isolated network with no hardware clocks in
|
||||||
sight, chrony will work much better for you.
|
sight, chrony will work much better for you.
|
||||||
|
|
||||||
@@ -96,56 +96,6 @@ at all, I found xntpd gave me no help with managing the local clock's
|
|||||||
gain/loss rate on the NTP master node (which I set from my watch). I
|
gain/loss rate on the NTP master node (which I set from my watch). I
|
||||||
added some automated support in chrony to deal with this.
|
added some automated support in chrony to deal with this.
|
||||||
|
|
||||||
S: Compilation issues
|
|
||||||
Q:How do I apply source patches?
|
|
||||||
Sometimes we release source patches rather than a full version when we need to
|
|
||||||
provide a fix for small problems. Supposing you have chrony-1.X.tar.gz and a
|
|
||||||
source patch chrony-1.X-1.X.1.gz. The steps required are:
|
|
||||||
|
|
||||||
tar xzvf ../chrony-1.X.tar.gz
|
|
||||||
cd chrony-1.X
|
|
||||||
gunzip < ../../chrony-1.X-1.X.1.gz | patch -p1
|
|
||||||
./configure
|
|
||||||
make
|
|
||||||
make install
|
|
||||||
|
|
||||||
Q:Can I compile chrony with an ANSI-C compiler that is not GCC v2.x?
|
|
||||||
I have had reports that chrony can be compiled with GCC v1.42, by using the
|
|
||||||
following trick when running make
|
|
||||||
|
|
||||||
make CC='gcc -D__FUNCTION__=\"function_not_available\"'
|
|
||||||
|
|
||||||
(this gets around the lack of a __FUNCTION__ macro in GCC v1.)
|
|
||||||
|
|
||||||
The same trick may be enough to allow other compilers to be used.
|
|
||||||
|
|
||||||
Q: I get errors like 'client.c:44: readline/readline.h: file not found'
|
|
||||||
Read the section about 'readline' in the INSTALL file or in chrony.txt. You
|
|
||||||
may need to disable readline support (e.g. if you haven't got readline
|
|
||||||
installed at all, or just don't want it), or specify the location of the
|
|
||||||
readline files (e.g. if you've installed them in a non-standard place).
|
|
||||||
|
|
||||||
Q: I have RedHat 7.3 and can't compile rtc_linux.c (error in spinlock.h)
|
|
||||||
The following solution has been found for this. Enter the following 3 commands
|
|
||||||
(as root):
|
|
||||||
|
|
||||||
cd /usr/include/
|
|
||||||
mv linux linux.rh
|
|
||||||
ln -s /usr/src/linux/include/linux ./linux
|
|
||||||
|
|
||||||
The problem seems to be that RedHat provide their own kernel header files in
|
|
||||||
/usr/include/linux. Besides differing from those used by your current kernel,
|
|
||||||
if you compiled it yourself, they also seem to have been changed in a way that
|
|
||||||
causes a problem compiling chrony. Chrony compiles fine with standard kernel
|
|
||||||
header files.
|
|
||||||
|
|
||||||
There have also been reports that just replacing the file
|
|
||||||
/usr/src/linux/spinlock.h by the equivalent file from a vanilla kernel source
|
|
||||||
tree is sufficient to fix the problem.
|
|
||||||
|
|
||||||
Note : from version 1.21 onwards, this problem no longer exists. The kernel
|
|
||||||
header files are no longer included.
|
|
||||||
|
|
||||||
S: Selection of NTP servers
|
S: Selection of NTP servers
|
||||||
Q: I have several computers on a LAN. Should I make one the master, or make them all clients of an external server?
|
Q: I have several computers on a LAN. Should I make one the master, or make them all clients of an external server?
|
||||||
I think the best configuration is to make one computer the master, with the
|
I think the best configuration is to make one computer the master, with the
|
||||||
@@ -201,15 +151,6 @@ Do you have a 'local stratum X' directive in the chrony.conf file? If X is
|
|||||||
lower than the stratum of the server you're trying to use, this situation will
|
lower than the stratum of the server you're trying to use, this situation will
|
||||||
arise. You should always make X quite high (e.g. 10) in this directive.
|
arise. You should always make X quite high (e.g. 10) in this directive.
|
||||||
|
|
||||||
S: Issues with chronyd
|
|
||||||
|
|
||||||
Q: chronyd crashes after a syslog message "adjtimex failed for set frequency"
|
|
||||||
The usual cause is that the kernel is running with a different value of 'HZ'
|
|
||||||
(the timer interrupt rate) than the value that was found in the kernel header
|
|
||||||
files when chrony was compiled. The chrony.conf file can include options to
|
|
||||||
modify the HZ value (see the discussion of linux_hz and linux_freq_scale in the
|
|
||||||
documentation), however the problem is to find the value of HZ being used.
|
|
||||||
|
|
||||||
S: Issues with chronyc
|
S: Issues with chronyc
|
||||||
|
|
||||||
Q: I keep getting the error '510 No command access from this host --- Reply not authenticated'.
|
Q: I keep getting the error '510 No command access from this host --- Reply not authenticated'.
|
||||||
@@ -268,14 +209,6 @@ For the real time clock support to work, you need the following three things:
|
|||||||
* enhanced RTC support compiled into the kernel
|
* enhanced RTC support compiled into the kernel
|
||||||
* an 'rtcfile' directive in your chrony.conf file.
|
* an 'rtcfile' directive in your chrony.conf file.
|
||||||
|
|
||||||
S: Problems with isolated networks.
|
|
||||||
|
|
||||||
Q: When I use the 'settime' command, chronyd crashes.
|
|
||||||
If you enter times that are too far away from the real time, chronyd will
|
|
||||||
think the system clock runs fast or slow by an excessive amount. The required
|
|
||||||
compensation factor will be outside the bounds for the adjtimex() system call.
|
|
||||||
chronyd will crash when it tries to apply such an excessive adjustment.
|
|
||||||
|
|
||||||
S: Microsoft Windows
|
S: Microsoft Windows
|
||||||
|
|
||||||
Q: Does chrony support Windows?
|
Q: Does chrony support Windows?
|
||||||
@@ -338,7 +271,7 @@ The program needs to see the definitions of structures used to interact with
|
|||||||
the real time clock (via /dev/rtc) and with the adjtimex() system call. Sadly
|
the real time clock (via /dev/rtc) and with the adjtimex() system call. Sadly
|
||||||
this has led to a number of compilation problems with newer kernels which have
|
this has led to a number of compilation problems with newer kernels which have
|
||||||
been increasingly hard to fix in a way that makes the code compilable on all
|
been increasingly hard to fix in a way that makes the code compilable on all
|
||||||
Linux kernel versions (from 2.0 up anyway, I doubt 1.x still works.) Hopefully
|
Linux kernel versions. Hopefully
|
||||||
the situation will not deteriorate further with future kernel versions.
|
the situation will not deteriorate further with future kernel versions.
|
||||||
|
|
||||||
Q: I get "Could not open /dev/rtc, Device or resource busy" in my syslog file.
|
Q: I get "Could not open /dev/rtc, Device or resource busy" in my syslog file.
|
||||||
|
|||||||
41
hash.h
Normal file
41
hash.h
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
chronyd/chronyc - Programs for keeping computer clocks accurate.
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
* Copyright (C) Miroslav Lichvar 2012
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
=======================================================================
|
||||||
|
|
||||||
|
Header file for crypto hashing.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef GOT_HASH_H
|
||||||
|
#define GOT_HASH_H
|
||||||
|
|
||||||
|
/* length of hash values produced by SHA512 */
|
||||||
|
#define MAX_HASH_LENGTH 64
|
||||||
|
|
||||||
|
extern int HSH_GetHashId(const char *name);
|
||||||
|
|
||||||
|
extern unsigned int HSH_Hash(int id,
|
||||||
|
const unsigned char *in1, unsigned int in1_len,
|
||||||
|
const unsigned char *in2, unsigned int in2_len,
|
||||||
|
unsigned char *out, unsigned int out_len);
|
||||||
|
|
||||||
|
#endif
|
||||||
64
hash_intmd5.c
Normal file
64
hash_intmd5.c
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
chronyd/chronyc - Programs for keeping computer clocks accurate.
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
* Copyright (C) Miroslav Lichvar 2012
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
=======================================================================
|
||||||
|
|
||||||
|
Routines implementing crypto hashing using internal MD5 implementation.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
#include "sysincl.h"
|
||||||
|
#include "hash.h"
|
||||||
|
#include "memory.h"
|
||||||
|
|
||||||
|
#include "md5.c"
|
||||||
|
|
||||||
|
static MD5_CTX ctx;
|
||||||
|
|
||||||
|
int
|
||||||
|
HSH_GetHashId(const char *name)
|
||||||
|
{
|
||||||
|
/* only MD5 is supported */
|
||||||
|
if (strcmp(name, "MD5"))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int
|
||||||
|
HSH_Hash(int id, const unsigned char *in1, unsigned int in1_len,
|
||||||
|
const unsigned char *in2, unsigned int in2_len,
|
||||||
|
unsigned char *out, unsigned int out_len)
|
||||||
|
{
|
||||||
|
if (out_len < 16)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
MD5Init(&ctx);
|
||||||
|
MD5Update(&ctx, in1, in1_len);
|
||||||
|
if (in2)
|
||||||
|
MD5Update(&ctx, in2, in2_len);
|
||||||
|
MD5Final(&ctx);
|
||||||
|
|
||||||
|
memcpy(out, ctx.digest, 16);
|
||||||
|
|
||||||
|
return 16;
|
||||||
|
}
|
||||||
89
hash_nss.c
Normal file
89
hash_nss.c
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
/*
|
||||||
|
chronyd/chronyc - Programs for keeping computer clocks accurate.
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
* Copyright (C) Miroslav Lichvar 2012
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
=======================================================================
|
||||||
|
|
||||||
|
Routines implementing crypto hashing using NSSLOWHASH API of the NSS library.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <nss.h>
|
||||||
|
#include <hasht.h>
|
||||||
|
#include <nsslowhash.h>
|
||||||
|
|
||||||
|
/* #include "config.h" */
|
||||||
|
#include "hash.h"
|
||||||
|
|
||||||
|
static NSSLOWInitContext *ictx;
|
||||||
|
|
||||||
|
struct hash {
|
||||||
|
HASH_HashType type;
|
||||||
|
const char *name;
|
||||||
|
NSSLOWHASHContext *context;
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct hash hashes[] = {
|
||||||
|
{ HASH_AlgMD5, "MD5", NULL },
|
||||||
|
{ HASH_AlgSHA1, "SHA1", NULL },
|
||||||
|
{ HASH_AlgSHA256, "SHA256", NULL },
|
||||||
|
{ HASH_AlgSHA384, "SHA384", NULL },
|
||||||
|
{ HASH_AlgSHA512, "SHA512", NULL },
|
||||||
|
{ 0, NULL, NULL }
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
HSH_GetHashId(const char *name)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; hashes[i].name; i++) {
|
||||||
|
if (!strcmp(name, hashes[i].name))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!hashes[i].name)
|
||||||
|
return -1; /* not found */
|
||||||
|
|
||||||
|
if (!ictx && !(ictx = NSSLOW_Init()))
|
||||||
|
return -1; /* couldn't init NSS */
|
||||||
|
|
||||||
|
if (!hashes[i].context &&
|
||||||
|
!(hashes[i].context = NSSLOWHASH_NewContext(ictx, hashes[i].type)))
|
||||||
|
return -1; /* couldn't init hash */
|
||||||
|
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int
|
||||||
|
HSH_Hash(int id, const unsigned char *in1, unsigned int in1_len,
|
||||||
|
const unsigned char *in2, unsigned int in2_len,
|
||||||
|
unsigned char *out, unsigned int out_len)
|
||||||
|
{
|
||||||
|
unsigned int ret;
|
||||||
|
|
||||||
|
NSSLOWHASH_Begin(hashes[id].context);
|
||||||
|
NSSLOWHASH_Update(hashes[id].context, in1, in1_len);
|
||||||
|
if (in2)
|
||||||
|
NSSLOWHASH_Update(hashes[id].context, in2, in2_len);
|
||||||
|
NSSLOWHASH_End(hashes[id].context, out, &ret, out_len);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
116
hash_tomcrypt.c
Normal file
116
hash_tomcrypt.c
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
/*
|
||||||
|
chronyd/chronyc - Programs for keeping computer clocks accurate.
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
* Copyright (C) Miroslav Lichvar 2012
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
=======================================================================
|
||||||
|
|
||||||
|
Routines implementing crypto hashing using tomcrypt library.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <tomcrypt.h>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
#include "hash.h"
|
||||||
|
|
||||||
|
struct hash {
|
||||||
|
const char *name;
|
||||||
|
const char *int_name;
|
||||||
|
const struct ltc_hash_descriptor *desc;
|
||||||
|
};
|
||||||
|
|
||||||
|
static const struct hash hashes[] = {
|
||||||
|
{ "MD5", "md5", &md5_desc },
|
||||||
|
#ifdef LTC_RIPEMD128
|
||||||
|
{ "RMD128", "rmd128", &rmd128_desc },
|
||||||
|
#endif
|
||||||
|
#ifdef LTC_RIPEMD160
|
||||||
|
{ "RMD160", "rmd160", &rmd160_desc },
|
||||||
|
#endif
|
||||||
|
#ifdef LTC_RIPEMD256
|
||||||
|
{ "RMD256", "rmd256", &rmd256_desc },
|
||||||
|
#endif
|
||||||
|
#ifdef LTC_RIPEMD320
|
||||||
|
{ "RMD320", "rmd320", &rmd320_desc },
|
||||||
|
#endif
|
||||||
|
#ifdef LTC_SHA1
|
||||||
|
{ "SHA1", "sha1", &sha1_desc },
|
||||||
|
#endif
|
||||||
|
#ifdef LTC_SHA256
|
||||||
|
{ "SHA256", "sha256", &sha256_desc },
|
||||||
|
#endif
|
||||||
|
#ifdef LTC_SHA384
|
||||||
|
{ "SHA384", "sha384", &sha384_desc },
|
||||||
|
#endif
|
||||||
|
#ifdef LTC_SHA512
|
||||||
|
{ "SHA512", "sha512", &sha512_desc },
|
||||||
|
#endif
|
||||||
|
#ifdef LTC_TIGER
|
||||||
|
{ "TIGER", "tiger", &tiger_desc },
|
||||||
|
#endif
|
||||||
|
#ifdef LTC_WHIRLPOOL
|
||||||
|
{ "WHIRLPOOL", "whirlpool", &whirlpool_desc },
|
||||||
|
#endif
|
||||||
|
{ NULL, NULL, NULL }
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
HSH_GetHashId(const char *name)
|
||||||
|
{
|
||||||
|
int i, h;
|
||||||
|
|
||||||
|
for (i = 0; hashes[i].name; i++) {
|
||||||
|
if (!strcmp(name, hashes[i].name))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!hashes[i].name)
|
||||||
|
return -1; /* not found */
|
||||||
|
|
||||||
|
h = find_hash(hashes[i].int_name);
|
||||||
|
if (h >= 0)
|
||||||
|
return h; /* already registered */
|
||||||
|
|
||||||
|
/* register and try again */
|
||||||
|
register_hash(hashes[i].desc);
|
||||||
|
|
||||||
|
return find_hash(hashes[i].int_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int
|
||||||
|
HSH_Hash(int id, const unsigned char *in1, unsigned int in1_len,
|
||||||
|
const unsigned char *in2, unsigned int in2_len,
|
||||||
|
unsigned char *out, unsigned int out_len)
|
||||||
|
{
|
||||||
|
unsigned long len;
|
||||||
|
int r;
|
||||||
|
|
||||||
|
len = out_len;
|
||||||
|
if (in2)
|
||||||
|
r = hash_memory_multi(id, out, &len,
|
||||||
|
in1, (unsigned long)in1_len, in2, (unsigned long)in2_len, NULL, 0);
|
||||||
|
else
|
||||||
|
r = hash_memory(id, in1, in1_len, out, &len);
|
||||||
|
|
||||||
|
if (r != CRYPT_OK)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return len;
|
||||||
|
}
|
||||||
75
io_linux.h
75
io_linux.h
@@ -1,75 +0,0 @@
|
|||||||
/* Taken from <asm-$foo/ioctl.h> in the Linux kernel sources.
|
|
||||||
* The ioctl.h file is pretty similar from one architecture to another.
|
|
||||||
* */
|
|
||||||
#ifndef IO_LINUX_H
|
|
||||||
#define IO_LINUX_H
|
|
||||||
|
|
||||||
/* Hmm. These constants vary a bit between systems. */
|
|
||||||
/* (__sh__ includes both sh and sh64) */
|
|
||||||
/* (__s390__ includes both s390 and s390x) */
|
|
||||||
#if defined(__i386__) || defined(__sh__) || defined(__arm__) || defined(__x86_64__) || defined(__s390__)
|
|
||||||
#define CHRONY_IOC_NRBITS 8
|
|
||||||
#define CHRONY_IOC_TYPEBITS 8
|
|
||||||
#define CHRONY_IOC_SIZEBITS 14
|
|
||||||
#define CHRONY_IOC_DIRBITS 2
|
|
||||||
|
|
||||||
#define CHRONY_IOC_NONE 0U
|
|
||||||
#define CHRONY_IOC_WRITE 1U
|
|
||||||
#define CHRONY_IOC_READ 2U
|
|
||||||
|
|
||||||
#elif defined(__alpha__) || defined(__sparc__) || defined(__ppc__) || defined(__ppc64__) || defined(__sparc64__)
|
|
||||||
#define CHRONY_IOC_NRBITS 8
|
|
||||||
#define CHRONY_IOC_TYPEBITS 8
|
|
||||||
#define CHRONY_IOC_SIZEBITS 13
|
|
||||||
#define CHRONY_IOC_DIRBITS 2
|
|
||||||
|
|
||||||
#define CHRONY_IOC_NONE 1U
|
|
||||||
#define CHRONY_IOC_READ 2U
|
|
||||||
#define CHRONY_IOC_WRITE 4U
|
|
||||||
|
|
||||||
#elif defined(__mips__) || defined(__mips32__) || defined(__powerpc__)
|
|
||||||
#define CHRONY_IOC_NRBITS 8
|
|
||||||
#define CHRONY_IOC_TYPEBITS 8
|
|
||||||
#define CHRONY_IOC_SIZEBITS 13
|
|
||||||
#define CHRONY_IOC_DIRBITS 3
|
|
||||||
#define CHRONY_IOC_NONE 1U
|
|
||||||
#define CHRONY_IOC_READ 2U
|
|
||||||
#define CHRONY_IOC_WRITE 4U
|
|
||||||
|
|
||||||
#else
|
|
||||||
#error "I don't know the values of the _IOC_* constants for your architecture"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define CHRONY_IOC_NRMASK ((1 << CHRONY_IOC_NRBITS)-1)
|
|
||||||
#define CHRONY_IOC_TYPEMASK ((1 << CHRONY_IOC_TYPEBITS)-1)
|
|
||||||
#define CHRONY_IOC_SIZEMASK ((1 << CHRONY_IOC_SIZEBITS)-1)
|
|
||||||
#define CHRONY_IOC_DIRMASK ((1 << CHRONY_IOC_DIRBITS)-1)
|
|
||||||
|
|
||||||
#define CHRONY_IOC_NRSHIFT 0
|
|
||||||
#define CHRONY_IOC_TYPESHIFT (CHRONY_IOC_NRSHIFT+CHRONY_IOC_NRBITS)
|
|
||||||
#define CHRONY_IOC_SIZESHIFT (CHRONY_IOC_TYPESHIFT+CHRONY_IOC_TYPEBITS)
|
|
||||||
#define CHRONY_IOC_DIRSHIFT (CHRONY_IOC_SIZESHIFT+CHRONY_IOC_SIZEBITS)
|
|
||||||
|
|
||||||
#define CHRONY_IOC(dir,type,nr,size) \
|
|
||||||
(((dir) << CHRONY_IOC_DIRSHIFT) | \
|
|
||||||
((type) << CHRONY_IOC_TYPESHIFT) | \
|
|
||||||
((nr) << CHRONY_IOC_NRSHIFT) | \
|
|
||||||
((size) << CHRONY_IOC_SIZESHIFT))
|
|
||||||
|
|
||||||
/* used to create numbers */
|
|
||||||
#define CHRONY_IO(type,nr) CHRONY_IOC(CHRONY_IOC_NONE,(type),(nr),0)
|
|
||||||
#define CHRONY_IOR(type,nr,size) CHRONY_IOC(CHRONY_IOC_READ,(type),(nr),sizeof(size))
|
|
||||||
#define CHRONY_IOW(type,nr,size) CHRONY_IOC(CHRONY_IOC_WRITE,(type),(nr),sizeof(size))
|
|
||||||
#define CHRONY_IOWR(type,nr,size) CHRONY_IOC(CHRONY_IOC_READ|CHRONY_IOC_WRITE,(type),(nr),sizeof(size))
|
|
||||||
|
|
||||||
#define RTC_UIE_ON CHRONY_IO('p', 0x03) /* Update int. enable on */
|
|
||||||
#define RTC_UIE_OFF CHRONY_IO('p', 0x04) /* ... off */
|
|
||||||
|
|
||||||
#define RTC_RD_TIME CHRONY_IOR('p', 0x09, struct rtc_time) /* Read RTC time */
|
|
||||||
#define RTC_SET_TIME CHRONY_IOW('p', 0x0a, struct rtc_time) /* Set RTC time */
|
|
||||||
|
|
||||||
/* From mc146818.h */
|
|
||||||
#define RTC_UIE 0x10 /* update-finished interrupt enable */
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
320
keys.c
320
keys.c
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
* Copyright (C) Richard P. Curnow 1997-2003
|
* Copyright (C) Richard P. Curnow 1997-2003
|
||||||
|
* Copyright (C) Miroslav Lichvar 2012-2013
|
||||||
*
|
*
|
||||||
* 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
|
||||||
@@ -25,18 +26,25 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include "config.h"
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include "sysincl.h"
|
||||||
|
|
||||||
#include "keys.h"
|
#include "keys.h"
|
||||||
|
#include "cmdparse.h"
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
|
#include "util.h"
|
||||||
|
#include "local.h"
|
||||||
|
#include "logging.h"
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
unsigned long id;
|
unsigned long id;
|
||||||
char *val;
|
char *val;
|
||||||
int len;
|
int len;
|
||||||
|
int hash_id;
|
||||||
|
int auth_delay;
|
||||||
} Key;
|
} Key;
|
||||||
|
|
||||||
#define MAX_KEYS 256
|
#define MAX_KEYS 256
|
||||||
@@ -45,13 +53,71 @@ static int n_keys;
|
|||||||
static Key keys[MAX_KEYS];
|
static Key keys[MAX_KEYS];
|
||||||
|
|
||||||
static int command_key_valid;
|
static int command_key_valid;
|
||||||
static int command_key_pos;
|
static int command_key_id;
|
||||||
static int cache_valid;
|
static int cache_valid;
|
||||||
static unsigned long cache_key_id;
|
static unsigned long cache_key_id;
|
||||||
static int cache_key_pos;
|
static int cache_key_pos;
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
|
static int
|
||||||
|
generate_key(unsigned long key_id)
|
||||||
|
{
|
||||||
|
#ifdef GENERATE_SHA1_KEY
|
||||||
|
unsigned char key[20];
|
||||||
|
const char *hashname = "SHA1";
|
||||||
|
#else
|
||||||
|
unsigned char key[16];
|
||||||
|
const char *hashname = "MD5";
|
||||||
|
#endif
|
||||||
|
const char *key_file, *rand_dev = "/dev/urandom";
|
||||||
|
FILE *f;
|
||||||
|
struct stat st;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
key_file = CNF_GetKeysFile();
|
||||||
|
|
||||||
|
if (!key_file)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
f = fopen(rand_dev, "r");
|
||||||
|
if (!f || fread(key, sizeof (key), 1, f) != 1) {
|
||||||
|
if (f)
|
||||||
|
fclose(f);
|
||||||
|
LOG_FATAL(LOGF_Keys, "Could not read %s", rand_dev);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
fclose(f);
|
||||||
|
|
||||||
|
f = fopen(key_file, "a");
|
||||||
|
if (!f) {
|
||||||
|
LOG_FATAL(LOGF_Keys, "Could not open keyfile %s for writing", key_file);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Make sure the keyfile is not world-readable */
|
||||||
|
if (stat(key_file, &st) || chmod(key_file, st.st_mode & 0770)) {
|
||||||
|
fclose(f);
|
||||||
|
LOG_FATAL(LOGF_Keys, "Could not change permissions of keyfile %s", key_file);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(f, "\n%lu %s HEX:", key_id, hashname);
|
||||||
|
for (i = 0; i < sizeof (key); i++)
|
||||||
|
fprintf(f, "%02hhX", key[i]);
|
||||||
|
fprintf(f, "\n");
|
||||||
|
fclose(f);
|
||||||
|
|
||||||
|
/* Erase the key from stack */
|
||||||
|
memset(key, 0, sizeof (key));
|
||||||
|
|
||||||
|
LOG(LOGS_INFO, LOGF_Keys, "Generated key %lu", key_id);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
void
|
void
|
||||||
KEY_Initialise(void)
|
KEY_Initialise(void)
|
||||||
{
|
{
|
||||||
@@ -59,7 +125,11 @@ KEY_Initialise(void)
|
|||||||
command_key_valid = 0;
|
command_key_valid = 0;
|
||||||
cache_valid = 0;
|
cache_valid = 0;
|
||||||
KEY_Reload();
|
KEY_Reload();
|
||||||
return;
|
|
||||||
|
if (CNF_GetGenerateCommandKey() && !KEY_KeyKnown(KEY_GetCommandKey())) {
|
||||||
|
if (generate_key(KEY_GetCommandKey()))
|
||||||
|
KEY_Reload();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -67,8 +137,37 @@ KEY_Initialise(void)
|
|||||||
void
|
void
|
||||||
KEY_Finalise(void)
|
KEY_Finalise(void)
|
||||||
{
|
{
|
||||||
/* Nothing to do */
|
}
|
||||||
return;
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static int
|
||||||
|
determine_hash_delay(int key_id)
|
||||||
|
{
|
||||||
|
NTP_Packet pkt;
|
||||||
|
struct timeval before, after;
|
||||||
|
unsigned long usecs, min_usecs=0;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < 10; i++) {
|
||||||
|
LCL_ReadRawTime(&before);
|
||||||
|
KEY_GenerateAuth(key_id, (unsigned char *)&pkt, NTP_NORMAL_PACKET_SIZE,
|
||||||
|
(unsigned char *)&pkt.auth_data, sizeof (pkt.auth_data));
|
||||||
|
LCL_ReadRawTime(&after);
|
||||||
|
|
||||||
|
usecs = (after.tv_sec - before.tv_sec) * 1000000 + (after.tv_usec - before.tv_usec);
|
||||||
|
|
||||||
|
if (i == 0 || usecs < min_usecs) {
|
||||||
|
min_usecs = usecs;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
LOG(LOGS_INFO, LOGF_Keys, "authentication delay for key %lu: %d useconds", key_id, min_usecs);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Add on a bit extra to allow for copying, conversions etc */
|
||||||
|
return min_usecs + (min_usecs >> 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -93,61 +192,84 @@ compare_keys_by_id(const void *a, const void *b)
|
|||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
|
|
||||||
#define KEYLEN 2047
|
|
||||||
#define SKEYLEN "2047"
|
|
||||||
|
|
||||||
void
|
void
|
||||||
KEY_Reload(void)
|
KEY_Reload(void)
|
||||||
{
|
{
|
||||||
int i, len1;
|
int i, line_number;
|
||||||
char *key_file;
|
|
||||||
FILE *in;
|
FILE *in;
|
||||||
unsigned long key_id;
|
unsigned long key_id;
|
||||||
char line[KEYLEN+1], keyval[KEYLEN+1];
|
char line[2048], *keyval, *key_file;
|
||||||
|
const char *hashname;
|
||||||
|
|
||||||
for (i=0; i<n_keys; i++) {
|
for (i=0; i<n_keys; i++) {
|
||||||
Free(keys[i].val);
|
Free(keys[i].val);
|
||||||
}
|
}
|
||||||
|
|
||||||
n_keys = 0;
|
n_keys = 0;
|
||||||
|
|
||||||
key_file = CNF_GetKeysFile();
|
|
||||||
|
|
||||||
if (key_file) {
|
|
||||||
in = fopen(key_file, "r");
|
|
||||||
if (in) {
|
|
||||||
while (fgets(line, sizeof(line), in)) {
|
|
||||||
len1 = strlen(line) - 1;
|
|
||||||
|
|
||||||
/* Guard against removing last character of the line
|
|
||||||
* if the last line of the file is missing an end-of-line */
|
|
||||||
if (line[len1] == '\n') {
|
|
||||||
line[len1] = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sscanf(line, "%lu%" SKEYLEN "s", &key_id, keyval) == 2) {
|
|
||||||
keys[n_keys].id = key_id;
|
|
||||||
keys[n_keys].len = strlen(keyval);
|
|
||||||
keys[n_keys].val = MallocArray(char, 1 + keys[n_keys].len);
|
|
||||||
strcpy(keys[n_keys].val, keyval);
|
|
||||||
n_keys++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fclose(in);
|
|
||||||
|
|
||||||
/* Sort keys into order. Note, if there's a duplicate, it is
|
|
||||||
arbitrary which one we use later - the user should have been
|
|
||||||
more careful! */
|
|
||||||
qsort((void *) keys, n_keys, sizeof(Key), compare_keys_by_id);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
command_key_valid = 0;
|
command_key_valid = 0;
|
||||||
cache_valid = 0;
|
cache_valid = 0;
|
||||||
|
|
||||||
return;
|
key_file = CNF_GetKeysFile();
|
||||||
|
line_number = 0;
|
||||||
|
|
||||||
|
if (!key_file)
|
||||||
|
return;
|
||||||
|
|
||||||
|
in = fopen(key_file, "r");
|
||||||
|
if (!in) {
|
||||||
|
LOG(LOGS_WARN, LOGF_Keys, "Could not open keyfile %s", key_file);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (fgets(line, sizeof (line), in)) {
|
||||||
|
line_number++;
|
||||||
|
|
||||||
|
CPS_NormalizeLine(line);
|
||||||
|
if (!*line)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!CPS_ParseKey(line, &key_id, &hashname, &keyval)) {
|
||||||
|
LOG(LOGS_WARN, LOGF_Keys, "Could not parse key at line %d in file %s", line_number, key_file);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
keys[n_keys].hash_id = HSH_GetHashId(hashname);
|
||||||
|
if (keys[n_keys].hash_id < 0) {
|
||||||
|
LOG(LOGS_WARN, LOGF_Keys, "Unknown hash function in key %lu", key_id);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
keys[n_keys].len = UTI_DecodePasswordFromText(keyval);
|
||||||
|
if (!keys[n_keys].len) {
|
||||||
|
LOG(LOGS_WARN, LOGF_Keys, "Could not decode password in key %lu", key_id);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
keys[n_keys].id = key_id;
|
||||||
|
keys[n_keys].val = MallocArray(char, keys[n_keys].len);
|
||||||
|
memcpy(keys[n_keys].val, keyval, keys[n_keys].len);
|
||||||
|
n_keys++;
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(in);
|
||||||
|
|
||||||
|
/* Sort keys into order. Note, if there's a duplicate, it is
|
||||||
|
arbitrary which one we use later - the user should have been
|
||||||
|
more careful! */
|
||||||
|
qsort((void *) keys, n_keys, sizeof(Key), compare_keys_by_id);
|
||||||
|
|
||||||
|
/* Check for duplicates */
|
||||||
|
for (i = 1; i < n_keys; i++) {
|
||||||
|
if (keys[i - 1].id == keys[i].id) {
|
||||||
|
LOG(LOGS_WARN, LOGF_Keys, "Detected duplicate key %lu", key_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Erase any passwords from stack */
|
||||||
|
memset(line, 0, sizeof (line));
|
||||||
|
|
||||||
|
for (i=0; i<n_keys; i++) {
|
||||||
|
keys[i].auth_delay = determine_hash_delay(keys[i].id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -170,30 +292,8 @@ lookup_key(unsigned long id)
|
|||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
void
|
static int
|
||||||
KEY_CommandKey(char **key, int *len)
|
get_key_pos(unsigned long key_id)
|
||||||
{
|
|
||||||
unsigned long command_key_id;
|
|
||||||
|
|
||||||
if (!command_key_valid) {
|
|
||||||
command_key_id = CNF_GetCommandKey();
|
|
||||||
command_key_pos = lookup_key(command_key_id);
|
|
||||||
command_key_valid = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (command_key_pos >= 0) {
|
|
||||||
*key = keys[command_key_pos].val;
|
|
||||||
*len = keys[command_key_pos].len;
|
|
||||||
} else {
|
|
||||||
*key = "";
|
|
||||||
*len = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ================================================== */
|
|
||||||
|
|
||||||
int
|
|
||||||
KEY_GetKey(unsigned long key_id, char **key, int *len)
|
|
||||||
{
|
{
|
||||||
if (!cache_valid || key_id != cache_key_id) {
|
if (!cache_valid || key_id != cache_key_id) {
|
||||||
cache_valid = 1;
|
cache_valid = 1;
|
||||||
@@ -201,15 +301,19 @@ KEY_GetKey(unsigned long key_id, char **key, int *len)
|
|||||||
cache_key_id = key_id;
|
cache_key_id = key_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cache_key_pos >= 0) {
|
return cache_key_pos;
|
||||||
*key = keys[cache_key_pos].val;
|
}
|
||||||
*len = keys[cache_key_pos].len;
|
|
||||||
return 1;
|
/* ================================================== */
|
||||||
} else {
|
|
||||||
*key = "";
|
unsigned long
|
||||||
*len = 0;
|
KEY_GetCommandKey(void)
|
||||||
return 0;
|
{
|
||||||
|
if (!command_key_valid) {
|
||||||
|
command_key_id = CNF_GetCommandKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return command_key_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -237,3 +341,57 @@ KEY_KeyKnown(unsigned long key_id)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
KEY_GetAuthDelay(unsigned long key_id)
|
||||||
|
{
|
||||||
|
int key_pos;
|
||||||
|
|
||||||
|
key_pos = get_key_pos(key_id);
|
||||||
|
|
||||||
|
if (key_pos < 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return keys[key_pos].auth_delay;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
KEY_GenerateAuth(unsigned long key_id, const unsigned char *data, int data_len,
|
||||||
|
unsigned char *auth, int auth_len)
|
||||||
|
{
|
||||||
|
int key_pos;
|
||||||
|
|
||||||
|
key_pos = get_key_pos(key_id);
|
||||||
|
|
||||||
|
if (key_pos < 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return UTI_GenerateNTPAuth(keys[key_pos].hash_id,
|
||||||
|
(unsigned char *)keys[key_pos].val, keys[key_pos].len,
|
||||||
|
data, data_len, auth, auth_len);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
KEY_CheckAuth(unsigned long key_id, const unsigned char *data, int data_len,
|
||||||
|
const unsigned char *auth, int auth_len)
|
||||||
|
{
|
||||||
|
int key_pos;
|
||||||
|
|
||||||
|
key_pos = get_key_pos(key_id);
|
||||||
|
|
||||||
|
if (key_pos < 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return UTI_CheckNTPAuth(keys[key_pos].hash_id,
|
||||||
|
(unsigned char *)keys[key_pos].val, keys[key_pos].len,
|
||||||
|
data, data_len, auth, auth_len);
|
||||||
|
}
|
||||||
|
|||||||
8
keys.h
8
keys.h
@@ -32,9 +32,15 @@ extern void KEY_Finalise(void);
|
|||||||
|
|
||||||
extern void KEY_Reload(void);
|
extern void KEY_Reload(void);
|
||||||
|
|
||||||
extern void KEY_CommandKey(char **key, int *len);
|
extern unsigned long KEY_GetCommandKey(void);
|
||||||
|
|
||||||
extern int KEY_GetKey(unsigned long key_id, char **key, int *len);
|
extern int KEY_GetKey(unsigned long key_id, char **key, int *len);
|
||||||
extern int KEY_KeyKnown(unsigned long key_id);
|
extern int KEY_KeyKnown(unsigned long key_id);
|
||||||
|
extern int KEY_GetAuthDelay(unsigned long key_id);
|
||||||
|
|
||||||
|
extern int KEY_GenerateAuth(unsigned long key_id, const unsigned char *data,
|
||||||
|
int data_len, unsigned char *auth, int auth_len);
|
||||||
|
extern int KEY_CheckAuth(unsigned long key_id, const unsigned char *data,
|
||||||
|
int data_len, const unsigned char *auth, int auth_len);
|
||||||
|
|
||||||
#endif /* GOT_KEYS_H */
|
#endif /* GOT_KEYS_H */
|
||||||
|
|||||||
54
local.c
54
local.c
@@ -28,8 +28,9 @@
|
|||||||
They interface with the system specific driver files in sys_*.c
|
They interface with the system specific driver files in sys_*.c
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <assert.h>
|
#include "config.h"
|
||||||
#include <stddef.h>
|
|
||||||
|
#include "sysincl.h"
|
||||||
|
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
#include "local.h"
|
#include "local.h"
|
||||||
@@ -103,12 +104,11 @@ static double max_clock_error;
|
|||||||
static void
|
static void
|
||||||
calculate_sys_precision(void)
|
calculate_sys_precision(void)
|
||||||
{
|
{
|
||||||
struct timeval tv, old_tv, first_tv;
|
struct timeval tv, old_tv;
|
||||||
int dusec, best_dusec;
|
int dusec, best_dusec;
|
||||||
int iters;
|
int iters;
|
||||||
|
|
||||||
gettimeofday(&old_tv, NULL);
|
gettimeofday(&old_tv, NULL);
|
||||||
first_tv = old_tv;
|
|
||||||
best_dusec = 1000000; /* Assume we must be better than a second */
|
best_dusec = 1000000; /* Assume we must be better than a second */
|
||||||
iters = 0;
|
iters = 0;
|
||||||
do {
|
do {
|
||||||
@@ -131,8 +131,6 @@ calculate_sys_precision(void)
|
|||||||
precision_log--;
|
precision_log--;
|
||||||
best_dusec *= 2;
|
best_dusec *= 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -166,7 +164,6 @@ LCL_Initialise(void)
|
|||||||
void
|
void
|
||||||
LCL_Finalise(void)
|
LCL_Finalise(void)
|
||||||
{
|
{
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -219,14 +216,11 @@ LCL_AddParameterChangeHandler(LCL_ParameterChangeHandler handler, void *anything
|
|||||||
new_entry->prev = change_list.prev;
|
new_entry->prev = change_list.prev;
|
||||||
change_list.prev->next = new_entry;
|
change_list.prev->next = new_entry;
|
||||||
change_list.prev = new_entry;
|
change_list.prev = new_entry;
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
/* Remove a handler */
|
/* Remove a handler */
|
||||||
extern
|
|
||||||
void LCL_RemoveParameterChangeHandler(LCL_ParameterChangeHandler handler, void *anything)
|
void LCL_RemoveParameterChangeHandler(LCL_ParameterChangeHandler handler, void *anything)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -250,8 +244,6 @@ void LCL_RemoveParameterChangeHandler(LCL_ParameterChangeHandler handler, void *
|
|||||||
ptr->prev->next = ptr->next;
|
ptr->prev->next = ptr->next;
|
||||||
|
|
||||||
free(ptr);
|
free(ptr);
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -278,8 +270,6 @@ LCL_AddDispersionNotifyHandler(LCL_DispersionNotifyHandler handler, void *anythi
|
|||||||
new_entry->prev = dispersion_notify_list.prev;
|
new_entry->prev = dispersion_notify_list.prev;
|
||||||
dispersion_notify_list.prev->next = new_entry;
|
dispersion_notify_list.prev->next = new_entry;
|
||||||
dispersion_notify_list.prev = new_entry;
|
dispersion_notify_list.prev = new_entry;
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -309,8 +299,6 @@ void LCL_RemoveDispersionNotifyHandler(LCL_DispersionNotifyHandler handler, void
|
|||||||
ptr->prev->next = ptr->next;
|
ptr->prev->next = ptr->next;
|
||||||
|
|
||||||
free(ptr);
|
free(ptr);
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -357,14 +345,14 @@ LCL_GetOffsetCorrection(struct timeval *raw, double *correction, double *err)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
/* This is just a simple passthrough of the system specific routine */
|
/* Return current frequency */
|
||||||
|
|
||||||
double
|
double
|
||||||
LCL_ReadAbsoluteFrequency(void)
|
LCL_ReadAbsoluteFrequency(void)
|
||||||
{
|
{
|
||||||
double freq;
|
double freq;
|
||||||
|
|
||||||
freq = (*drv_read_freq)();
|
freq = current_freq_ppm;
|
||||||
|
|
||||||
/* Undo temperature compensation */
|
/* Undo temperature compensation */
|
||||||
if (temp_comp_ppm != 0.0) {
|
if (temp_comp_ppm != 0.0) {
|
||||||
@@ -442,7 +430,7 @@ LCL_AccumulateDeltaFrequency(double dfreq)
|
|||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
void
|
void
|
||||||
LCL_AccumulateOffset(double offset)
|
LCL_AccumulateOffset(double offset, double corr_rate)
|
||||||
{
|
{
|
||||||
ChangeListEntry *ptr;
|
ChangeListEntry *ptr;
|
||||||
struct timeval raw, cooked;
|
struct timeval raw, cooked;
|
||||||
@@ -453,7 +441,7 @@ LCL_AccumulateOffset(double offset)
|
|||||||
LCL_ReadRawTime(&raw);
|
LCL_ReadRawTime(&raw);
|
||||||
LCL_CookTime(&raw, &cooked, NULL);
|
LCL_CookTime(&raw, &cooked, NULL);
|
||||||
|
|
||||||
(*drv_accrue_offset)(offset);
|
(*drv_accrue_offset)(offset, corr_rate);
|
||||||
|
|
||||||
/* Dispatch to all handlers */
|
/* Dispatch to all handlers */
|
||||||
for (ptr = change_list.next; ptr != &change_list; ptr = ptr->next) {
|
for (ptr = change_list.next; ptr != &change_list; ptr = ptr->next) {
|
||||||
@@ -488,7 +476,23 @@ LCL_ApplyStepOffset(double offset)
|
|||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
void
|
void
|
||||||
LCL_AccumulateFrequencyAndOffset(double dfreq, double doffset)
|
LCL_NotifyExternalTimeStep(struct timeval *raw, struct timeval *cooked,
|
||||||
|
double offset, double dispersion)
|
||||||
|
{
|
||||||
|
ChangeListEntry *ptr;
|
||||||
|
|
||||||
|
/* Dispatch to all handlers */
|
||||||
|
for (ptr = change_list.next; ptr != &change_list; ptr = ptr->next) {
|
||||||
|
(ptr->handler)(raw, cooked, 0.0, offset, 1, ptr->anything);
|
||||||
|
}
|
||||||
|
|
||||||
|
lcl_InvokeDispersionNotifyHandlers(dispersion);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
void
|
||||||
|
LCL_AccumulateFrequencyAndOffset(double dfreq, double doffset, double corr_rate)
|
||||||
{
|
{
|
||||||
ChangeListEntry *ptr;
|
ChangeListEntry *ptr;
|
||||||
struct timeval raw, cooked;
|
struct timeval raw, cooked;
|
||||||
@@ -515,7 +519,7 @@ LCL_AccumulateFrequencyAndOffset(double dfreq, double doffset)
|
|||||||
current_freq_ppm = (*drv_set_freq)(current_freq_ppm);
|
current_freq_ppm = (*drv_set_freq)(current_freq_ppm);
|
||||||
dfreq = (current_freq_ppm - old_freq_ppm) / (1.0e6 + old_freq_ppm);
|
dfreq = (current_freq_ppm - old_freq_ppm) / (1.0e6 + old_freq_ppm);
|
||||||
|
|
||||||
(*drv_accrue_offset)(doffset);
|
(*drv_accrue_offset)(doffset, corr_rate);
|
||||||
|
|
||||||
/* Dispatch to all handlers */
|
/* Dispatch to all handlers */
|
||||||
for (ptr = change_list.next; ptr != &change_list; ptr = ptr->next) {
|
for (ptr = change_list.next; ptr != &change_list; ptr = ptr->next) {
|
||||||
@@ -560,8 +564,6 @@ lcl_RegisterSystemDrivers(lcl_ReadFrequencyDriver read_freq,
|
|||||||
#ifdef TRACEON
|
#ifdef TRACEON
|
||||||
LOG(LOGS_INFO, LOGF_Local, "Local freq=%.3fppm", current_freq_ppm);
|
LOG(LOGS_INFO, LOGF_Local, "Local freq=%.3fppm", current_freq_ppm);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -581,7 +583,7 @@ LCL_MakeStep(double threshold)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* Cancel remaining slew and make the step */
|
/* Cancel remaining slew and make the step */
|
||||||
LCL_AccumulateOffset(correction);
|
LCL_AccumulateOffset(correction, 0.0);
|
||||||
LCL_ApplyStepOffset(-correction);
|
LCL_ApplyStepOffset(-correction);
|
||||||
|
|
||||||
LOG(LOGS_WARN, LOGF_Local, "System clock was stepped by %.3f seconds", correction);
|
LOG(LOGS_WARN, LOGF_Local, "System clock was stepped by %.3f seconds", correction);
|
||||||
@@ -597,8 +599,6 @@ LCL_SetLeap(int leap)
|
|||||||
if (drv_set_leap) {
|
if (drv_set_leap) {
|
||||||
(drv_set_leap)(leap);
|
(drv_set_leap)(leap);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|||||||
12
local.h
12
local.h
@@ -138,9 +138,10 @@ extern void LCL_AccumulateDeltaFrequency(double dfreq);
|
|||||||
/* Routine to apply an offset (in seconds) to the local clock. The
|
/* Routine to apply an offset (in seconds) to the local clock. The
|
||||||
argument should be positive to move the clock backwards (i.e. the
|
argument should be positive to move the clock backwards (i.e. the
|
||||||
local clock is currently fast of true time), or negative to move it
|
local clock is currently fast of true time), or negative to move it
|
||||||
forwards (i.e. it is currently slow of true time). */
|
forwards (i.e. it is currently slow of true time). Provided is also
|
||||||
|
a suggested correction rate (correction time * offset). */
|
||||||
|
|
||||||
extern void LCL_AccumulateOffset(double offset);
|
extern void LCL_AccumulateOffset(double offset, double corr_rate);
|
||||||
|
|
||||||
/* Routine to apply an immediate offset by doing a sudden step if
|
/* Routine to apply an immediate offset by doing a sudden step if
|
||||||
possible. (Intended for use after an initial estimate of offset has
|
possible. (Intended for use after an initial estimate of offset has
|
||||||
@@ -151,9 +152,14 @@ extern void LCL_AccumulateOffset(double offset);
|
|||||||
|
|
||||||
extern void LCL_ApplyStepOffset(double offset);
|
extern void LCL_ApplyStepOffset(double offset);
|
||||||
|
|
||||||
|
/* Routine to invoke notify handlers on an unexpected time jump
|
||||||
|
in system clock */
|
||||||
|
extern void LCL_NotifyExternalTimeStep(struct timeval *raw, struct timeval *cooked,
|
||||||
|
double offset, double dispersion);
|
||||||
|
|
||||||
/* Perform the combination of modifying the frequency and applying
|
/* Perform the combination of modifying the frequency and applying
|
||||||
a slew, in one easy step */
|
a slew, in one easy step */
|
||||||
extern void LCL_AccumulateFrequencyAndOffset(double dfreq, double doffset);
|
extern void LCL_AccumulateFrequencyAndOffset(double dfreq, double doffset, double corr_rate);
|
||||||
|
|
||||||
/* Routine to read the system precision as a log to base 2 value. */
|
/* Routine to read the system precision as a log to base 2 value. */
|
||||||
extern int LCL_GetSysPrecisionAsLog(void);
|
extern int LCL_GetSysPrecisionAsLog(void);
|
||||||
|
|||||||
5
localp.h
5
localp.h
@@ -41,8 +41,9 @@ typedef double (*lcl_ReadFrequencyDriver)(void);
|
|||||||
typedef double (*lcl_SetFrequencyDriver)(double freq_ppm);
|
typedef double (*lcl_SetFrequencyDriver)(double freq_ppm);
|
||||||
|
|
||||||
/* System driver to accrue an offset. A positive argument means slew
|
/* System driver to accrue an offset. A positive argument means slew
|
||||||
the clock forwards. */
|
the clock forwards. The suggested correction rate of time to correct the
|
||||||
typedef void (*lcl_AccrueOffsetDriver)(double offset);
|
offset is given in 'corr_rate'. */
|
||||||
|
typedef void (*lcl_AccrueOffsetDriver)(double offset, double corr_rate);
|
||||||
|
|
||||||
/* System driver to apply a step offset. A positive argument means step
|
/* System driver to apply a step offset. A positive argument means step
|
||||||
the clock forwards. */
|
the clock forwards. */
|
||||||
|
|||||||
43
logging.c
43
logging.c
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
* Copyright (C) Richard P. Curnow 1997-2003
|
* Copyright (C) Richard P. Curnow 1997-2003
|
||||||
* Copyright (C) Miroslav Lichvar 2011
|
* Copyright (C) Miroslav Lichvar 2011-2012
|
||||||
*
|
*
|
||||||
* 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
|
||||||
@@ -25,12 +25,12 @@
|
|||||||
Module to handle logging of diagnostic information
|
Module to handle logging of diagnostic information
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
#include "sysincl.h"
|
#include "sysincl.h"
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
#include "version.h"
|
|
||||||
#include "mkdirpp.h"
|
#include "mkdirpp.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
@@ -40,6 +40,8 @@ static int initialised = 0;
|
|||||||
|
|
||||||
static int system_log = 0;
|
static int system_log = 0;
|
||||||
|
|
||||||
|
static int parent_fd = 0;
|
||||||
|
|
||||||
static time_t last_limited = 0;
|
static time_t last_limited = 0;
|
||||||
|
|
||||||
#ifdef WINNT
|
#ifdef WINNT
|
||||||
@@ -71,8 +73,6 @@ LOG_Initialise(void)
|
|||||||
#ifdef WINNT
|
#ifdef WINNT
|
||||||
logfile = fopen("./chronyd.err", "a");
|
logfile = fopen("./chronyd.err", "a");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -94,7 +94,6 @@ LOG_Finalise(void)
|
|||||||
LOG_CycleLogFiles();
|
LOG_CycleLogFiles();
|
||||||
|
|
||||||
initialised = 0;
|
initialised = 0;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -129,7 +128,6 @@ LOG_Line_Function(LOG_Severity severity, LOG_Facility facility, const char *form
|
|||||||
fprintf(stderr, "%s\n", buf);
|
fprintf(stderr, "%s\n", buf);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -153,11 +151,13 @@ LOG_Fatal_Function(LOG_Facility facility, const char *format, ...)
|
|||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Fatal error : %s\n", buf);
|
fprintf(stderr, "Fatal error : %s\n", buf);
|
||||||
}
|
}
|
||||||
|
if (parent_fd) {
|
||||||
|
if (write(parent_fd, buf, strlen(buf) + 1) < 0)
|
||||||
|
; /* Not much we can do here */
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
MAI_CleanupAndExit();
|
exit(1);
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -178,7 +178,6 @@ LOG_Position(const char *filename, int line_number, const char *function_name)
|
|||||||
fprintf(stderr, "%s:%d:(%s)[%s] ", filename, line_number, function_name, buf);
|
fprintf(stderr, "%s:%d:(%s)[%s] ", filename, line_number, function_name, buf);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -190,12 +189,28 @@ LOG_OpenSystemLog(void)
|
|||||||
#else
|
#else
|
||||||
system_log = 1;
|
system_log = 1;
|
||||||
openlog("chronyd", LOG_PID, LOG_DAEMON);
|
openlog("chronyd", LOG_PID, LOG_DAEMON);
|
||||||
LOG(LOGS_INFO, LOGF_Logging, "chronyd version %s starting", PROGRAM_VERSION_STRING);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
|
void
|
||||||
|
LOG_SetParentFd(int fd)
|
||||||
|
{
|
||||||
|
parent_fd = fd;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
void
|
||||||
|
LOG_CloseParentFd()
|
||||||
|
{
|
||||||
|
if (parent_fd > 0)
|
||||||
|
close(parent_fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
int
|
int
|
||||||
LOG_RateLimited(void)
|
LOG_RateLimited(void)
|
||||||
{
|
{
|
||||||
@@ -282,14 +297,10 @@ LOG_CreateLogFileDir(void)
|
|||||||
{
|
{
|
||||||
const char *logdir;
|
const char *logdir;
|
||||||
|
|
||||||
if (n_filelogs <= 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
logdir = CNF_GetLogDir();
|
logdir = CNF_GetLogDir();
|
||||||
|
|
||||||
if (!mkdir_and_parents(logdir)) {
|
if (!mkdir_and_parents(logdir)) {
|
||||||
LOG(LOGS_ERR, LOGF_Logging, "Could not create directory %s", logdir);
|
LOG(LOGS_ERR, LOGF_Logging, "Could not create directory %s", logdir);
|
||||||
n_filelogs = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ typedef enum {
|
|||||||
LOGF_CmdMon,
|
LOGF_CmdMon,
|
||||||
LOGF_Acquire,
|
LOGF_Acquire,
|
||||||
LOGF_Manual,
|
LOGF_Manual,
|
||||||
|
LOGF_Keys,
|
||||||
LOGF_Logging,
|
LOGF_Logging,
|
||||||
LOGF_Rtc,
|
LOGF_Rtc,
|
||||||
LOGF_Regress,
|
LOGF_Regress,
|
||||||
@@ -85,6 +86,12 @@ extern void LOG_Position(const char *filename, int line_number, const char *func
|
|||||||
/* Log messages to syslog instead of stderr */
|
/* Log messages to syslog instead of stderr */
|
||||||
extern void LOG_OpenSystemLog(void);
|
extern void LOG_OpenSystemLog(void);
|
||||||
|
|
||||||
|
/* Send fatal message also to the foreground process */
|
||||||
|
extern void LOG_SetParentFd(int fd);
|
||||||
|
|
||||||
|
/* Close the pipe to the foreground process so it can exit */
|
||||||
|
extern void LOG_CloseParentFd(void);
|
||||||
|
|
||||||
/* Return zero once per 10 seconds */
|
/* Return zero once per 10 seconds */
|
||||||
extern int LOG_RateLimited(void);
|
extern int LOG_RateLimited(void);
|
||||||
|
|
||||||
|
|||||||
89
main.c
89
main.c
@@ -4,6 +4,7 @@
|
|||||||
**********************************************************************
|
**********************************************************************
|
||||||
* Copyright (C) Richard P. Curnow 1997-2003
|
* Copyright (C) Richard P. Curnow 1997-2003
|
||||||
* Copyright (C) John G. Hasler 2009
|
* Copyright (C) John G. Hasler 2009
|
||||||
|
* Copyright (C) Miroslav Lichvar 2012
|
||||||
*
|
*
|
||||||
* 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
|
||||||
@@ -25,6 +26,8 @@
|
|||||||
The main program
|
The main program
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
#include "sysincl.h"
|
#include "sysincl.h"
|
||||||
|
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
@@ -43,7 +46,6 @@
|
|||||||
#include "keys.h"
|
#include "keys.h"
|
||||||
#include "acquire.h"
|
#include "acquire.h"
|
||||||
#include "manual.h"
|
#include "manual.h"
|
||||||
#include "version.h"
|
|
||||||
#include "rtc.h"
|
#include "rtc.h"
|
||||||
#include "refclock.h"
|
#include "refclock.h"
|
||||||
#include "clientlog.h"
|
#include "clientlog.h"
|
||||||
@@ -86,13 +88,13 @@ MAI_CleanupAndExit(void)
|
|||||||
TMC_Finalise();
|
TMC_Finalise();
|
||||||
MNL_Finalise();
|
MNL_Finalise();
|
||||||
ACQ_Finalise();
|
ACQ_Finalise();
|
||||||
KEY_Finalise();
|
|
||||||
CLG_Finalise();
|
CLG_Finalise();
|
||||||
NSR_Finalise();
|
NSR_Finalise();
|
||||||
NCR_Finalise();
|
NCR_Finalise();
|
||||||
BRD_Finalise();
|
BRD_Finalise();
|
||||||
SST_Finalise();
|
SST_Finalise();
|
||||||
REF_Finalise();
|
REF_Finalise();
|
||||||
|
KEY_Finalise();
|
||||||
RCL_Finalise();
|
RCL_Finalise();
|
||||||
SRC_Finalise();
|
SRC_Finalise();
|
||||||
RTC_Finalise();
|
RTC_Finalise();
|
||||||
@@ -114,7 +116,6 @@ MAI_CleanupAndExit(void)
|
|||||||
static void
|
static void
|
||||||
signal_cleanup(int x)
|
signal_cleanup(int x)
|
||||||
{
|
{
|
||||||
LOG(LOGS_WARN, LOGF_Main, "chronyd exiting on signal");
|
|
||||||
if (!initialised) exit(0);
|
if (!initialised) exit(0);
|
||||||
SCH_QuitProgram();
|
SCH_QuitProgram();
|
||||||
}
|
}
|
||||||
@@ -124,6 +125,8 @@ signal_cleanup(int x)
|
|||||||
static void
|
static void
|
||||||
post_acquire_hook(void *anything)
|
post_acquire_hook(void *anything)
|
||||||
{
|
{
|
||||||
|
/* Close the pipe to the foreground process so it can exit */
|
||||||
|
LOG_CloseParentFd();
|
||||||
|
|
||||||
CNF_AddSources();
|
CNF_AddSources();
|
||||||
CNF_AddBroadcasts();
|
CNF_AddBroadcasts();
|
||||||
@@ -214,7 +217,13 @@ go_daemon(void)
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
int pid, fd;
|
int pid, fd, pipefd[2];
|
||||||
|
|
||||||
|
/* Create pipe which will the daemon use to notify the grandparent
|
||||||
|
when it's initialised or send an error message */
|
||||||
|
if (pipe(pipefd)) {
|
||||||
|
LOG(LOGS_ERR, LOGF_Logging, "Could not detach, pipe failed : %s", strerror(errno));
|
||||||
|
}
|
||||||
|
|
||||||
/* Does this preserve existing signal handlers? */
|
/* Does this preserve existing signal handlers? */
|
||||||
pid = fork();
|
pid = fork();
|
||||||
@@ -222,8 +231,22 @@ go_daemon(void)
|
|||||||
if (pid < 0) {
|
if (pid < 0) {
|
||||||
LOG(LOGS_ERR, LOGF_Logging, "Could not detach, fork failed : %s", strerror(errno));
|
LOG(LOGS_ERR, LOGF_Logging, "Could not detach, fork failed : %s", strerror(errno));
|
||||||
} else if (pid > 0) {
|
} else if (pid > 0) {
|
||||||
exit(0); /* In the 'grandparent' */
|
/* In the 'grandparent' */
|
||||||
|
char message[1024];
|
||||||
|
int r;
|
||||||
|
|
||||||
|
close(pipefd[1]);
|
||||||
|
r = read(pipefd[0], message, sizeof (message));
|
||||||
|
if (r) {
|
||||||
|
if (r > 0) {
|
||||||
|
/* Print the error message from the child */
|
||||||
|
fprintf(stderr, "%.1024s\n", message);
|
||||||
|
}
|
||||||
|
exit(1);
|
||||||
|
} else
|
||||||
|
exit(0);
|
||||||
} else {
|
} else {
|
||||||
|
close(pipefd[0]);
|
||||||
|
|
||||||
setsid();
|
setsid();
|
||||||
|
|
||||||
@@ -237,10 +260,19 @@ go_daemon(void)
|
|||||||
} else {
|
} else {
|
||||||
/* In the child we want to leave running as the daemon */
|
/* In the child we want to leave running as the daemon */
|
||||||
|
|
||||||
/* Don't keep stdin/out/err from before. */
|
/* Change current directory to / */
|
||||||
for (fd=0; fd<1024; fd++) {
|
if (chdir("/") < 0) {
|
||||||
close(fd);
|
LOG(LOGS_ERR, LOGF_Logging, "Could not chdir to / : %s", strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Don't keep stdin/out/err from before. But don't close
|
||||||
|
the parent pipe yet. */
|
||||||
|
for (fd=0; fd<1024; fd++) {
|
||||||
|
if (fd != pipefd[1])
|
||||||
|
close(fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_SetParentFd(pipefd[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -252,10 +284,10 @@ go_daemon(void)
|
|||||||
int main
|
int main
|
||||||
(int argc, char **argv)
|
(int argc, char **argv)
|
||||||
{
|
{
|
||||||
char *conf_file = NULL;
|
const char *conf_file = DEFAULT_CONF_FILE;
|
||||||
char *user = NULL;
|
char *user = NULL;
|
||||||
int debug = 0, nofork = 0;
|
int debug = 0, nofork = 0, address_family = IPADDR_UNSPEC;
|
||||||
int do_init_rtc = 0;
|
int do_init_rtc = 0, restarted = 0;
|
||||||
int other_pid;
|
int other_pid;
|
||||||
int lock_memory = 0, sched_priority = 0;
|
int lock_memory = 0, sched_priority = 0;
|
||||||
|
|
||||||
@@ -276,6 +308,8 @@ int main
|
|||||||
lock_memory = 1;
|
lock_memory = 1;
|
||||||
} else if (!strcmp("-r", *argv)) {
|
} else if (!strcmp("-r", *argv)) {
|
||||||
reload = 1;
|
reload = 1;
|
||||||
|
} else if (!strcmp("-R", *argv)) {
|
||||||
|
restarted = 1;
|
||||||
} else if (!strcmp("-u", *argv)) {
|
} else if (!strcmp("-u", *argv)) {
|
||||||
++argv, --argc;
|
++argv, --argc;
|
||||||
if (argc == 0) {
|
if (argc == 0) {
|
||||||
@@ -287,7 +321,7 @@ int main
|
|||||||
do_init_rtc = 1;
|
do_init_rtc = 1;
|
||||||
} else if (!strcmp("-v", *argv) || !strcmp("--version",*argv)) {
|
} else if (!strcmp("-v", *argv) || !strcmp("--version",*argv)) {
|
||||||
/* This write to the terminal is OK, it comes before we turn into a daemon */
|
/* This write to the terminal is OK, it comes before we turn into a daemon */
|
||||||
printf("chronyd (chrony) version %s\n", PROGRAM_VERSION_STRING);
|
printf("chronyd (chrony) version %s\n", CHRONY_VERSION);
|
||||||
exit(0);
|
exit(0);
|
||||||
} else if (!strcmp("-n", *argv)) {
|
} else if (!strcmp("-n", *argv)) {
|
||||||
nofork = 1;
|
nofork = 1;
|
||||||
@@ -295,17 +329,14 @@ int main
|
|||||||
debug = 1;
|
debug = 1;
|
||||||
nofork = 1;
|
nofork = 1;
|
||||||
} else if (!strcmp("-4", *argv)) {
|
} else if (!strcmp("-4", *argv)) {
|
||||||
DNS_SetAddressFamily(IPADDR_INET4);
|
address_family = IPADDR_INET4;
|
||||||
} else if (!strcmp("-6", *argv)) {
|
} else if (!strcmp("-6", *argv)) {
|
||||||
DNS_SetAddressFamily(IPADDR_INET6);
|
address_family = IPADDR_INET6;
|
||||||
} else {
|
} else {
|
||||||
LOG_FATAL(LOGF_Main, "Unrecognized command line option [%s]", *argv);
|
LOG_FATAL(LOGF_Main, "Unrecognized command line option [%s]", *argv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CNF_ReadFile(conf_file);
|
|
||||||
|
|
||||||
#ifndef SYS_WINNT
|
|
||||||
if (getuid() != 0) {
|
if (getuid() != 0) {
|
||||||
/* This write to the terminal is OK, it comes before we turn into a daemon */
|
/* This write to the terminal is OK, it comes before we turn into a daemon */
|
||||||
fprintf(stderr,"Not superuser\n");
|
fprintf(stderr,"Not superuser\n");
|
||||||
@@ -321,19 +352,24 @@ int main
|
|||||||
LOG_OpenSystemLog();
|
LOG_OpenSystemLog();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOG(LOGS_INFO, LOGF_Main, "chronyd version %s starting", CHRONY_VERSION);
|
||||||
|
|
||||||
|
DNS_SetAddressFamily(address_family);
|
||||||
|
|
||||||
|
CNF_SetRestarted(restarted);
|
||||||
|
CNF_ReadFile(conf_file);
|
||||||
|
|
||||||
/* Check whether another chronyd may already be running. Do this after
|
/* Check whether another chronyd may already be running. Do this after
|
||||||
* forking, so that message logging goes to the right place (i.e. syslog), in
|
* forking, so that message logging goes to the right place (i.e. syslog), in
|
||||||
* case this chronyd is being run from a boot script. */
|
* case this chronyd is being run from a boot script. */
|
||||||
if (maybe_another_chronyd_running(&other_pid)) {
|
if (maybe_another_chronyd_running(&other_pid)) {
|
||||||
LOG_FATAL(LOGF_Main, "Another chronyd may already be running (pid=%d), check lockfile (%s)",
|
LOG_FATAL(LOGF_Main, "Another chronyd may already be running (pid=%d), check lockfile (%s)",
|
||||||
other_pid, CNF_GetPidFile());
|
other_pid, CNF_GetPidFile());
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write our lockfile to prevent other chronyds running. This has *GOT* to
|
/* Write our lockfile to prevent other chronyds running. This has *GOT* to
|
||||||
* be done *AFTER* the daemon-creation fork() */
|
* be done *AFTER* the daemon-creation fork() */
|
||||||
write_lockfile();
|
write_lockfile();
|
||||||
#endif
|
|
||||||
|
|
||||||
if (do_init_rtc) {
|
if (do_init_rtc) {
|
||||||
RTC_TimePreInit();
|
RTC_TimePreInit();
|
||||||
@@ -342,11 +378,12 @@ int main
|
|||||||
LCL_Initialise();
|
LCL_Initialise();
|
||||||
SCH_Initialise();
|
SCH_Initialise();
|
||||||
SYS_Initialise();
|
SYS_Initialise();
|
||||||
NIO_Initialise();
|
NIO_Initialise(address_family);
|
||||||
CAM_Initialise();
|
CAM_Initialise(address_family);
|
||||||
RTC_Initialise();
|
RTC_Initialise();
|
||||||
SRC_Initialise();
|
SRC_Initialise();
|
||||||
RCL_Initialise();
|
RCL_Initialise();
|
||||||
|
KEY_Initialise();
|
||||||
|
|
||||||
/* Command-line switch must have priority */
|
/* Command-line switch must have priority */
|
||||||
if (!sched_priority) {
|
if (!sched_priority) {
|
||||||
@@ -360,23 +397,25 @@ int main
|
|||||||
SYS_LockMemory();
|
SYS_LockMemory();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!user) {
|
||||||
|
user = CNF_GetUser();
|
||||||
|
}
|
||||||
if (user) {
|
if (user) {
|
||||||
SYS_DropRoot(user);
|
SYS_DropRoot(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOG_CreateLogFileDir();
|
||||||
|
|
||||||
REF_Initialise();
|
REF_Initialise();
|
||||||
SST_Initialise();
|
SST_Initialise();
|
||||||
BRD_Initialise();
|
BRD_Initialise();
|
||||||
NCR_Initialise();
|
NCR_Initialise();
|
||||||
NSR_Initialise();
|
NSR_Initialise();
|
||||||
CLG_Initialise();
|
CLG_Initialise();
|
||||||
KEY_Initialise();
|
|
||||||
ACQ_Initialise();
|
ACQ_Initialise();
|
||||||
MNL_Initialise();
|
MNL_Initialise();
|
||||||
TMC_Initialise();
|
TMC_Initialise();
|
||||||
|
|
||||||
LOG_CreateLogFileDir();
|
|
||||||
|
|
||||||
/* From now on, it is safe to do finalisation on exit */
|
/* From now on, it is safe to do finalisation on exit */
|
||||||
initialised = 1;
|
initialised = 1;
|
||||||
|
|
||||||
@@ -397,6 +436,8 @@ int main
|
|||||||
the scheduler. */
|
the scheduler. */
|
||||||
SCH_MainLoop();
|
SCH_MainLoop();
|
||||||
|
|
||||||
|
LOG(LOGS_INFO, LOGF_Main, "chronyd exiting");
|
||||||
|
|
||||||
MAI_CleanupAndExit();
|
MAI_CleanupAndExit();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
80
make_release
80
make_release
@@ -1,52 +1,54 @@
|
|||||||
#!/usr/bin/env perl
|
#!/bin/sh
|
||||||
|
|
||||||
$tool = "chrony";
|
LANG=C
|
||||||
|
export LANG
|
||||||
|
|
||||||
$version = shift || die "Usage : $0 <version>\n";
|
if [ $# -ne 1 ]; then
|
||||||
$subdir = "${tool}-${version}";
|
echo "Usage : $0 <version>"
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
|
||||||
unless (-d ".git") {
|
version=$1
|
||||||
die "No .git subdirectory?"
|
subdir=chrony-${version}
|
||||||
}
|
mandate=$(date +'%B %Y')
|
||||||
|
|
||||||
unless (-d "RELEASES") {
|
umask 022
|
||||||
mkdir "RELEASES", 0755;
|
|
||||||
}
|
|
||||||
|
|
||||||
system ("git tag -s $version");
|
if [ ! -d .git ]; then
|
||||||
die "git-tag failed" if ($? != 0);
|
echo "No .git subdirectory?"
|
||||||
if (-d "RELEASES/$subdir") {
|
exit 3
|
||||||
system ("rm -rf RELEASES/$subdir");
|
fi
|
||||||
}
|
|
||||||
|
|
||||||
system ("git archive --format=tar --prefix=RELEASES/${subdir}/ $version | tar xf -");
|
[ -d RELEASES ] || mkdir RELEASES
|
||||||
die "git-tar-tree failed" if ($? != 0);
|
|
||||||
|
|
||||||
chdir "RELEASES";
|
git tag -s $version || exit 1
|
||||||
$here = qx/pwd/;
|
|
||||||
chomp $here;
|
|
||||||
chdir $subdir;
|
|
||||||
|
|
||||||
open (OUT, ">version.txt");
|
rm -rf RELEASES/$subdir
|
||||||
print OUT $version."\n";
|
|
||||||
close OUT;
|
|
||||||
|
|
||||||
open (IN, "<${tool}.spec.sample");
|
git archive --format=tar --prefix=RELEASES/${subdir}/ $version | \
|
||||||
open (OUT, ">${tool}.spec");
|
tar xf - || exit 1
|
||||||
while (<IN>) {
|
|
||||||
s/\@\@VERSION\@\@/$version/;
|
|
||||||
print OUT;
|
|
||||||
}
|
|
||||||
close (IN);
|
|
||||||
close (OUT);
|
|
||||||
|
|
||||||
system("makeinfo --no-headers --number-sections -o chrony.txt chrony.texi");
|
cd RELEASES/$subdir || exit 1
|
||||||
unlink "make_release";
|
|
||||||
unlink "${tool}.spec.sample";
|
|
||||||
unlink ".gitignore";
|
|
||||||
|
|
||||||
chdir $here;
|
echo $version > version.txt
|
||||||
system ("tar cvf - $subdir | gzip -9 > ${subdir}.tar.gz");
|
|
||||||
system ("gpg -b -a -o ${subdir}-tar-gz-asc.txt ${subdir}.tar.gz");
|
sed -e "s%@@VERSION@@%${version}%" < chrony.spec.sample > chrony.spec
|
||||||
|
|
||||||
|
for m in chrony.1.in chronyc.1.in chrony.conf.5.in chronyd.8.in; do
|
||||||
|
sed -e "s%@VERSION@%${version}%;s%@MAN_DATE@%${mandate}%" \
|
||||||
|
< $m > ${m}_
|
||||||
|
mv -f ${m}_ $m
|
||||||
|
done
|
||||||
|
|
||||||
|
./configure && make chrony.txt || exit 1
|
||||||
|
mv chrony.txt chrony.txt_
|
||||||
|
make distclean
|
||||||
|
mv chrony.txt_ chrony.txt
|
||||||
|
|
||||||
|
rm -f faqgen.pl make_release chrony.spec.sample .gitignore
|
||||||
|
|
||||||
|
cd ..
|
||||||
|
tar cvf - $subdir | gzip -9 > ${subdir}.tar.gz
|
||||||
|
gpg -b -a -o ${subdir}-tar-gz-asc.txt ${subdir}.tar.gz
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
12
manual.c
12
manual.c
@@ -30,7 +30,9 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stddef.h>
|
#include "config.h"
|
||||||
|
|
||||||
|
#include "sysincl.h"
|
||||||
|
|
||||||
#include "manual.h"
|
#include "manual.h"
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
@@ -91,8 +93,6 @@ MNL_Initialise(void)
|
|||||||
error = ERROR_MARGIN;
|
error = ERROR_MARGIN;
|
||||||
|
|
||||||
LCL_AddParameterChangeHandler(slew_samples, NULL);
|
LCL_AddParameterChangeHandler(slew_samples, NULL);
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -100,7 +100,6 @@ MNL_Initialise(void)
|
|||||||
void
|
void
|
||||||
MNL_Finalise(void)
|
MNL_Finalise(void)
|
||||||
{
|
{
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -143,6 +142,8 @@ estimate_and_set_system(struct timeval *now, int offset_provided, double offset,
|
|||||||
}
|
}
|
||||||
b1 = freq = 0.0;
|
b1 = freq = 0.0;
|
||||||
found_freq = 0;
|
found_freq = 0;
|
||||||
|
agos[0] = 0.0;
|
||||||
|
offsets[0] = b0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (offset_provided) {
|
if (offset_provided) {
|
||||||
@@ -153,7 +154,7 @@ estimate_and_set_system(struct timeval *now, int offset_provided, double offset,
|
|||||||
|
|
||||||
if (found_freq) {
|
if (found_freq) {
|
||||||
LOG(LOGS_INFO, LOGF_Manual,
|
LOG(LOGS_INFO, LOGF_Manual,
|
||||||
"Making a frequency change of %.3fppm and a slew of %.6f\n",
|
"Making a frequency change of %.3f ppm and a slew of %.6f",
|
||||||
1.0e6 * freq, slew_by);
|
1.0e6 * freq, slew_by);
|
||||||
|
|
||||||
REF_SetManualReference(now,
|
REF_SetManualReference(now,
|
||||||
@@ -235,7 +236,6 @@ slew_samples(struct timeval *raw,
|
|||||||
dfreq, doffset);
|
dfreq, doffset);
|
||||||
samples[i].offset += delta_time;
|
samples[i].offset += delta_time;
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|||||||
6
md5.h
6
md5.h
@@ -32,11 +32,7 @@
|
|||||||
***********************************************************************
|
***********************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef HAS_STDINT_H
|
#include "sysincl.h"
|
||||||
#include <stdint.h>
|
|
||||||
#elif defined(HAS_INTTYPES_H)
|
|
||||||
#include <inttypes.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* typedef a 32-bit type */
|
/* typedef a 32-bit type */
|
||||||
typedef uint32_t UINT4;
|
typedef uint32_t UINT4;
|
||||||
|
|||||||
2
memory.h
2
memory.h
@@ -27,8 +27,6 @@
|
|||||||
#ifndef GOT_MEMORY_H
|
#ifndef GOT_MEMORY_H
|
||||||
#define GOT_MEMORY_H
|
#define GOT_MEMORY_H
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#define Malloc(x) malloc(x)
|
#define Malloc(x) malloc(x)
|
||||||
#define MallocNew(T) ((T *) malloc(sizeof(T)))
|
#define MallocNew(T) ((T *) malloc(sizeof(T)))
|
||||||
#define MallocArray(T, n) ((T *) malloc((n) * sizeof(T)))
|
#define MallocArray(T, n) ((T *) malloc((n) * sizeof(T)))
|
||||||
|
|||||||
@@ -26,6 +26,8 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
#include "sysincl.h"
|
#include "sysincl.h"
|
||||||
|
|
||||||
#include "mkdirpp.h"
|
#include "mkdirpp.h"
|
||||||
|
|||||||
15
mkversion
15
mkversion
@@ -1,15 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
rm -f version.h
|
|
||||||
echo "#ifndef VERSION_H" > version.h
|
|
||||||
echo "#define VERSION_H 1" >> version.h
|
|
||||||
|
|
||||||
if [ -f version.txt ]; then
|
|
||||||
ver=`cat version.txt`
|
|
||||||
echo "#define PROGRAM_VERSION_STRING \"$ver\"" >> version.h
|
|
||||||
else
|
|
||||||
echo "#define PROGRAM_VERSION_STRING \"DEVELOPMENT\"" >> version.h
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "#endif /* VERSION_H */" >> version.h
|
|
||||||
|
|
||||||
12
nameserv.c
12
nameserv.c
@@ -26,11 +26,12 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
#include "sysincl.h"
|
#include "sysincl.h"
|
||||||
|
|
||||||
#include "nameserv.h"
|
#include "nameserv.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include <resolv.h>
|
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
@@ -56,7 +57,11 @@ DNS_Name2IPAddress(const char *name, IPAddr *addr)
|
|||||||
result = getaddrinfo(name, NULL, &hints, &res);
|
result = getaddrinfo(name, NULL, &hints, &res);
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
|
#ifdef FORCE_DNSRETRY
|
||||||
|
return DNS_TryAgain;
|
||||||
|
#else
|
||||||
return result == EAI_AGAIN ? DNS_TryAgain : DNS_Failure;
|
return result == EAI_AGAIN ? DNS_TryAgain : DNS_Failure;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ai = res; !result && ai != NULL; ai = ai->ai_next) {
|
for (ai = res; !result && ai != NULL; ai = ai->ai_next) {
|
||||||
@@ -94,8 +99,13 @@ DNS_Name2IPAddress(const char *name, IPAddr *addr)
|
|||||||
return DNS_Success;
|
return DNS_Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef FORCE_DNSRETRY
|
||||||
|
return DNS_TryAgain;
|
||||||
|
#else
|
||||||
return DNS_Failure;
|
return DNS_Failure;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|||||||
32
ntp.h
32
ntp.h
@@ -27,11 +27,9 @@
|
|||||||
#ifndef GOT_NTP_H
|
#ifndef GOT_NTP_H
|
||||||
#define GOT_NTP_H
|
#define GOT_NTP_H
|
||||||
|
|
||||||
#ifdef HAS_STDINT_H
|
#include "sysincl.h"
|
||||||
#include <stdint.h>
|
|
||||||
#elif defined(HAS_INTTYPES_H)
|
#include "hash.h"
|
||||||
#include <inttypes.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t hi;
|
uint32_t hi;
|
||||||
@@ -40,7 +38,7 @@ typedef struct {
|
|||||||
|
|
||||||
typedef uint32_t NTP_int32;
|
typedef uint32_t NTP_int32;
|
||||||
|
|
||||||
#define AUTH_DATA_LEN 16
|
#define MAX_NTP_AUTH_DATA_LEN MAX_HASH_LENGTH
|
||||||
|
|
||||||
/* Type definition for leap bits */
|
/* Type definition for leap bits */
|
||||||
typedef enum {
|
typedef enum {
|
||||||
@@ -72,7 +70,7 @@ typedef struct {
|
|||||||
NTP_int64 receive_ts;
|
NTP_int64 receive_ts;
|
||||||
NTP_int64 transmit_ts;
|
NTP_int64 transmit_ts;
|
||||||
NTP_int32 auth_keyid;
|
NTP_int32 auth_keyid;
|
||||||
uint8_t auth_data[AUTH_DATA_LEN];
|
uint8_t auth_data[MAX_NTP_AUTH_DATA_LEN];
|
||||||
} NTP_Packet;
|
} NTP_Packet;
|
||||||
|
|
||||||
/* We have to declare a buffer type to hold a datagram read from the
|
/* We have to declare a buffer type to hold a datagram read from the
|
||||||
@@ -89,24 +87,6 @@ typedef union {
|
|||||||
uint8_t arbitrary[MAX_NTP_MESSAGE_SIZE];
|
uint8_t arbitrary[MAX_NTP_MESSAGE_SIZE];
|
||||||
} ReceiveBuffer;
|
} ReceiveBuffer;
|
||||||
|
|
||||||
#define NTP_NORMAL_PACKET_SIZE (sizeof(NTP_Packet) - (sizeof(NTP_int32) + AUTH_DATA_LEN))
|
#define NTP_NORMAL_PACKET_SIZE offsetof(NTP_Packet, auth_keyid)
|
||||||
|
|
||||||
/* ================================================== */
|
|
||||||
|
|
||||||
inline static double
|
|
||||||
int32_to_double(NTP_int32 x)
|
|
||||||
{
|
|
||||||
return (double) ntohl(x) / 65536.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ================================================== */
|
|
||||||
|
|
||||||
inline static NTP_int32
|
|
||||||
double_to_int32(double x)
|
|
||||||
{
|
|
||||||
return htonl((NTP_int32)(0.5 + 65536.0 * x));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ================================================== */
|
|
||||||
|
|
||||||
#endif /* GOT_NTP_H */
|
#endif /* GOT_NTP_H */
|
||||||
|
|||||||
878
ntp_core.c
878
ntp_core.c
File diff suppressed because it is too large
Load Diff
13
ntp_core.h
13
ntp_core.h
@@ -54,20 +54,11 @@ extern void NCR_DestroyInstance(NCR_Instance instance);
|
|||||||
|
|
||||||
/* This routine is called when a new packet arrives off the network,
|
/* This routine is called when a new packet arrives off the network,
|
||||||
and it relates to a source we have an ongoing protocol exchange with */
|
and it relates to a source we have an ongoing protocol exchange with */
|
||||||
extern void NCR_ProcessNoauthKnown(NTP_Packet *message, struct timeval *now, double now_err, NCR_Instance data);
|
extern void NCR_ProcessKnown(NTP_Packet *message, struct timeval *now, double now_err, NCR_Instance data, int length);
|
||||||
|
|
||||||
/* This routine is called when a new packet arrives off the network,
|
/* This routine is called when a new packet arrives off the network,
|
||||||
and we do not recognize its source */
|
and we do not recognize its source */
|
||||||
extern void NCR_ProcessNoauthUnknown(NTP_Packet *message, struct timeval *now, double now_err, NTP_Remote_Address *remote_addr);
|
extern void NCR_ProcessUnknown(NTP_Packet *message, struct timeval *now, double now_err, NTP_Remote_Address *remote_addr, int length);
|
||||||
|
|
||||||
/* This routine is called when a new authenticated packet arrives off
|
|
||||||
the network, and it relates to a source we have an ongoing protocol
|
|
||||||
exchange with */
|
|
||||||
extern void NCR_ProcessAuthKnown(NTP_Packet *message, struct timeval *now, double now_err, NCR_Instance data);
|
|
||||||
|
|
||||||
/* This routine is called when a new authenticated packet arrives off
|
|
||||||
the network, and we do not recognize its source */
|
|
||||||
extern void NCR_ProcessAuthUnknown(NTP_Packet *message, struct timeval *now, double now_err, NTP_Remote_Address *remote_addr);
|
|
||||||
|
|
||||||
/* Slew receive and transmit times in instance records */
|
/* Slew receive and transmit times in instance records */
|
||||||
extern void NCR_SlewTimes(NCR_Instance inst, struct timeval *when, double dfreq, double doffset);
|
extern void NCR_SlewTimes(NCR_Instance inst, struct timeval *when, double dfreq, double doffset);
|
||||||
|
|||||||
89
ntp_io.c
89
ntp_io.c
@@ -26,6 +26,8 @@
|
|||||||
This file deals with the IO aspects of reading and writing NTP packets
|
This file deals with the IO aspects of reading and writing NTP packets
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
#include "sysincl.h"
|
#include "sysincl.h"
|
||||||
|
|
||||||
#include "ntp_io.h"
|
#include "ntp_io.h"
|
||||||
@@ -37,8 +39,6 @@
|
|||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
#include <fcntl.h>
|
|
||||||
|
|
||||||
union sockaddr_in46 {
|
union sockaddr_in46 {
|
||||||
struct sockaddr_in in4;
|
struct sockaddr_in in4;
|
||||||
#ifdef HAVE_IPV6
|
#ifdef HAVE_IPV6
|
||||||
@@ -157,6 +157,16 @@ prepare_socket(int family)
|
|||||||
LOG(LOGS_ERR, LOGF_NtpIO, "Could not request IPV6_V6ONLY socket option");
|
LOG(LOGS_ERR, LOGF_NtpIO, "Could not request IPV6_V6ONLY socket option");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef IPV6_RECVPKTINFO
|
||||||
|
if (setsockopt(sock_fd, IPPROTO_IPV6, IPV6_RECVPKTINFO, (char *)&on_off, sizeof(on_off)) < 0) {
|
||||||
|
LOG(LOGS_ERR, LOGF_NtpIO, "Could not request IPv6 packet info socket option");
|
||||||
|
}
|
||||||
|
#elif defined(IPV6_PKTINFO)
|
||||||
|
if (setsockopt(sock_fd, IPPROTO_IPV6, IPV6_PKTINFO, (char *)&on_off, sizeof(on_off)) < 0) {
|
||||||
|
LOG(LOGS_ERR, LOGF_NtpIO, "Could not request IPv6 packet info socket option");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -200,8 +210,10 @@ prepare_socket(int family)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (bind(sock_fd, &my_addr.u, my_addr_len) < 0) {
|
if (bind(sock_fd, &my_addr.u, my_addr_len) < 0) {
|
||||||
LOG_FATAL(LOGF_NtpIO, "Could not bind %s NTP socket : %s",
|
LOG(LOGS_ERR, LOGF_NtpIO, "Could not bind %s NTP socket : %s",
|
||||||
family == AF_INET ? "IPv4" : "IPv6", strerror(errno));
|
family == AF_INET ? "IPv4" : "IPv6", strerror(errno));
|
||||||
|
close(sock_fd);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Register handler for read events on the socket */
|
/* Register handler for read events on the socket */
|
||||||
@@ -219,17 +231,25 @@ prepare_socket(int family)
|
|||||||
return sock_fd;
|
return sock_fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
void
|
void
|
||||||
NIO_Initialise(void)
|
NIO_Initialise(int family)
|
||||||
{
|
{
|
||||||
assert(!initialised);
|
assert(!initialised);
|
||||||
initialised = 1;
|
initialised = 1;
|
||||||
|
|
||||||
do_size_checks();
|
do_size_checks();
|
||||||
|
|
||||||
sock_fd4 = prepare_socket(AF_INET);
|
if (family == IPADDR_UNSPEC || family == IPADDR_INET4)
|
||||||
|
sock_fd4 = prepare_socket(AF_INET);
|
||||||
|
else
|
||||||
|
sock_fd4 = -1;
|
||||||
#ifdef HAVE_IPV6
|
#ifdef HAVE_IPV6
|
||||||
sock_fd6 = prepare_socket(AF_INET6);
|
if (family == IPADDR_UNSPEC || family == IPADDR_INET6)
|
||||||
|
sock_fd6 = prepare_socket(AF_INET6);
|
||||||
|
else
|
||||||
|
sock_fd6 = -1;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (sock_fd4 < 0
|
if (sock_fd4 < 0
|
||||||
@@ -239,8 +259,6 @@ NIO_Initialise(void)
|
|||||||
) {
|
) {
|
||||||
LOG_FATAL(LOGF_NtpIO, "Could not open any NTP socket");
|
LOG_FATAL(LOGF_NtpIO, "Could not open any NTP socket");
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -261,7 +279,6 @@ NIO_Finalise(void)
|
|||||||
sock_fd6 = -1;
|
sock_fd6 = -1;
|
||||||
#endif
|
#endif
|
||||||
initialised = 0;
|
initialised = 0;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -279,7 +296,7 @@ read_from_socket(void *anything)
|
|||||||
ReceiveBuffer message;
|
ReceiveBuffer message;
|
||||||
union sockaddr_in46 where_from;
|
union sockaddr_in46 where_from;
|
||||||
unsigned int flags = 0;
|
unsigned int flags = 0;
|
||||||
struct timeval now;
|
struct timeval now, now_raw;
|
||||||
double now_err;
|
double now_err;
|
||||||
NTP_Remote_Address remote_addr;
|
NTP_Remote_Address remote_addr;
|
||||||
char cmsgbuf[256];
|
char cmsgbuf[256];
|
||||||
@@ -289,7 +306,7 @@ read_from_socket(void *anything)
|
|||||||
|
|
||||||
assert(initialised);
|
assert(initialised);
|
||||||
|
|
||||||
SCH_GetFileReadyTime(&now, &now_err);
|
SCH_GetLastEventTime(&now, &now_err, &now_raw);
|
||||||
|
|
||||||
iov.iov_base = message.arbitrary;
|
iov.iov_base = message.arbitrary;
|
||||||
iov.iov_len = sizeof(message);
|
iov.iov_len = sizeof(message);
|
||||||
@@ -343,23 +360,32 @@ read_from_socket(void *anything)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(IPV6_PKTINFO) && defined(HAVE_IN6_PKTINFO)
|
||||||
|
if (cmsg->cmsg_level == IPPROTO_IPV6 && cmsg->cmsg_type == IPV6_PKTINFO) {
|
||||||
|
struct in6_pktinfo ipi;
|
||||||
|
|
||||||
|
memcpy(&ipi, CMSG_DATA(cmsg), sizeof(ipi));
|
||||||
|
memcpy(&remote_addr.local_ip_addr.addr.in6, &ipi.ipi6_addr.s6_addr,
|
||||||
|
sizeof (remote_addr.local_ip_addr.addr.in6));
|
||||||
|
remote_addr.local_ip_addr.family = IPADDR_INET6;
|
||||||
|
}
|
||||||
|
#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 == SO_TIMESTAMP) {
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
|
|
||||||
memcpy(&tv, CMSG_DATA(cmsg), sizeof(tv));
|
memcpy(&tv, CMSG_DATA(cmsg), sizeof(tv));
|
||||||
LCL_CookTime(&tv, &now, &now_err);
|
|
||||||
|
/* This should be more accurate than LCL_CookTime(&now_raw,...) */
|
||||||
|
UTI_AddDiffToTimeval(&now, &now_raw, &tv, &now);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status == NTP_NORMAL_PACKET_SIZE) {
|
if (status >= NTP_NORMAL_PACKET_SIZE && status <= sizeof(NTP_Packet)) {
|
||||||
|
|
||||||
NSR_ProcessReceive((NTP_Packet *) &message.ntp_pkt, &now, now_err, &remote_addr);
|
NSR_ProcessReceive((NTP_Packet *) &message.ntp_pkt, &now, now_err, &remote_addr, status);
|
||||||
|
|
||||||
} else if (status == sizeof(NTP_Packet)) {
|
|
||||||
|
|
||||||
NSR_ProcessAuthenticatedReceive((NTP_Packet *) &message.ntp_pkt, &now, now_err, &remote_addr);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
@@ -367,8 +393,6 @@ read_from_socket(void *anything)
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -443,6 +467,25 @@ send_packet(void *packet, int packetlen, NTP_Remote_Address *remote_addr)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(IPV6_PKTINFO) && defined(HAVE_IN6_PKTINFO)
|
||||||
|
if (remote_addr->local_ip_addr.family == IPADDR_INET6) {
|
||||||
|
struct cmsghdr *cmsg;
|
||||||
|
struct in6_pktinfo *ipi;
|
||||||
|
|
||||||
|
cmsg = CMSG_FIRSTHDR(&msg);
|
||||||
|
memset(cmsg, 0, CMSG_SPACE(sizeof(struct in6_pktinfo)));
|
||||||
|
cmsglen += CMSG_SPACE(sizeof(struct in6_pktinfo));
|
||||||
|
|
||||||
|
cmsg->cmsg_level = IPPROTO_IPV6;
|
||||||
|
cmsg->cmsg_type = IPV6_PKTINFO;
|
||||||
|
cmsg->cmsg_len = CMSG_LEN(sizeof(struct in6_pktinfo));
|
||||||
|
|
||||||
|
ipi = (struct in6_pktinfo *) CMSG_DATA(cmsg);
|
||||||
|
memcpy(&ipi->ipi6_addr.s6_addr, &remote_addr->local_ip_addr.addr.in6,
|
||||||
|
sizeof(ipi->ipi6_addr.s6_addr));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
LOG(LOGS_INFO, LOGF_NtpIO, "sending to %s:%d from %s",
|
LOG(LOGS_INFO, LOGF_NtpIO, "sending to %s:%d from %s",
|
||||||
UTI_IPToString(&remote_addr->ip_addr), remote_addr->port, UTI_IPToString(&remote_addr->local_ip_addr));
|
UTI_IPToString(&remote_addr->ip_addr), remote_addr->port, UTI_IPToString(&remote_addr->local_ip_addr));
|
||||||
@@ -464,8 +507,6 @@ send_packet(void *packet, int packetlen, NTP_Remote_Address *remote_addr)
|
|||||||
LOG(LOGS_WARN, LOGF_NtpIO, "Could not send to %s:%d : %s",
|
LOG(LOGS_WARN, LOGF_NtpIO, "Could not send to %s:%d : %s",
|
||||||
UTI_IPToString(&remote_addr->ip_addr), remote_addr->port, strerror(errno));
|
UTI_IPToString(&remote_addr->ip_addr), remote_addr->port, strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -481,9 +522,9 @@ NIO_SendNormalPacket(NTP_Packet *packet, NTP_Remote_Address *remote_addr)
|
|||||||
/* Send an authenticated packet to a given address */
|
/* Send an authenticated packet to a given address */
|
||||||
|
|
||||||
void
|
void
|
||||||
NIO_SendAuthenticatedPacket(NTP_Packet *packet, NTP_Remote_Address *remote_addr)
|
NIO_SendAuthenticatedPacket(NTP_Packet *packet, NTP_Remote_Address *remote_addr, int auth_len)
|
||||||
{
|
{
|
||||||
send_packet((void *) packet, sizeof(NTP_Packet), remote_addr);
|
send_packet((void *) packet, NTP_NORMAL_PACKET_SIZE + auth_len, remote_addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|||||||
4
ntp_io.h
4
ntp_io.h
@@ -32,7 +32,7 @@
|
|||||||
#include "addressing.h"
|
#include "addressing.h"
|
||||||
|
|
||||||
/* Function to initialise the module. */
|
/* Function to initialise the module. */
|
||||||
extern void NIO_Initialise(void);
|
extern void NIO_Initialise(int family);
|
||||||
|
|
||||||
/* Function to finalise the module */
|
/* Function to finalise the module */
|
||||||
extern void NIO_Finalise(void);
|
extern void NIO_Finalise(void);
|
||||||
@@ -41,7 +41,7 @@ extern void NIO_Finalise(void);
|
|||||||
extern void NIO_SendNormalPacket(NTP_Packet *packet, NTP_Remote_Address *remote_addr);
|
extern void NIO_SendNormalPacket(NTP_Packet *packet, NTP_Remote_Address *remote_addr);
|
||||||
|
|
||||||
/* Function to transmit an authenticated packet */
|
/* Function to transmit an authenticated packet */
|
||||||
extern void NIO_SendAuthenticatedPacket(NTP_Packet *packet, NTP_Remote_Address *remote_addr);
|
extern void NIO_SendAuthenticatedPacket(NTP_Packet *packet, NTP_Remote_Address *remote_addr, int auth_len);
|
||||||
|
|
||||||
/* Function to send a datagram to a remote machine's UDP echo port. */
|
/* Function to send a datagram to a remote machine's UDP echo port. */
|
||||||
extern void NIO_SendEcho(NTP_Remote_Address *remote_addr);
|
extern void NIO_SendEcho(NTP_Remote_Address *remote_addr);
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
* Copyright (C) Richard P. Curnow 1997-2003
|
* Copyright (C) Richard P. Curnow 1997-2003
|
||||||
* Copyright (C) Miroslav Lichvar 2011
|
* Copyright (C) Miroslav Lichvar 2011-2012
|
||||||
*
|
*
|
||||||
* 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
|
||||||
@@ -27,6 +27,8 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
#include "sysincl.h"
|
#include "sysincl.h"
|
||||||
|
|
||||||
#include "ntp_sources.h"
|
#include "ntp_sources.h"
|
||||||
@@ -101,8 +103,6 @@ NSR_Initialise(void)
|
|||||||
initialised = 1;
|
initialised = 1;
|
||||||
|
|
||||||
LCL_AddParameterChangeHandler(slew_sources, NULL);
|
LCL_AddParameterChangeHandler(slew_sources, NULL);
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -111,7 +111,6 @@ void
|
|||||||
NSR_Finalise(void)
|
NSR_Finalise(void)
|
||||||
{
|
{
|
||||||
initialised = 0;
|
initialised = 0;
|
||||||
return; /* Nothing to do yet */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -177,8 +176,6 @@ find_slot(NTP_Remote_Address *remote_addr, int *slot, int *found)
|
|||||||
*found = 0;
|
*found = 0;
|
||||||
*slot = hash;
|
*slot = hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -285,6 +282,19 @@ NSR_AddUnresolvedSource(char *name, int port, NTP_Source_Type type, SourceParame
|
|||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
|
void
|
||||||
|
NSR_ResolveSources(void)
|
||||||
|
{
|
||||||
|
/* Try to resolve unresolved sources now */
|
||||||
|
if (resolving_interval) {
|
||||||
|
SCH_RemoveTimeout(resolving_id);
|
||||||
|
resolving_interval--;
|
||||||
|
resolve_sources(NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
/* Procedure to remove a source. We don't bother whether the port
|
/* Procedure to remove a source. We don't bother whether the port
|
||||||
address is matched - we're only interested in removing a record for
|
address is matched - we're only interested in removing a record for
|
||||||
the right IP address. Thus the caller can specify the port number
|
the right IP address. Thus the caller can specify the port number
|
||||||
@@ -331,9 +341,10 @@ NSR_RemoveSource(NTP_Remote_Address *remote_addr)
|
|||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
/* 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 */
|
||||||
void
|
void
|
||||||
NSR_ProcessReceive(NTP_Packet *message, struct timeval *now, double now_err, NTP_Remote_Address *remote_addr)
|
NSR_ProcessReceive(NTP_Packet *message, struct timeval *now, double now_err, NTP_Remote_Address *remote_addr, int length)
|
||||||
{
|
{
|
||||||
int slot, found;
|
int slot, found;
|
||||||
|
|
||||||
@@ -347,27 +358,9 @@ NSR_ProcessReceive(NTP_Packet *message, struct timeval *now, double now_err, NTP
|
|||||||
|
|
||||||
find_slot(remote_addr, &slot, &found);
|
find_slot(remote_addr, &slot, &found);
|
||||||
if (found == 2) { /* Must match IP address AND port number */
|
if (found == 2) { /* Must match IP address AND port number */
|
||||||
NCR_ProcessNoauthKnown(message, now, now_err, records[slot].data);
|
NCR_ProcessKnown(message, now, now_err, records[slot].data, length);
|
||||||
} else {
|
} else {
|
||||||
NCR_ProcessNoauthUnknown(message, now, now_err, remote_addr);
|
NCR_ProcessUnknown(message, now, now_err, remote_addr, length);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ================================================== */
|
|
||||||
|
|
||||||
/* This routine is called by ntp_io when a new packet with an authentication tail arrives off the network */
|
|
||||||
void
|
|
||||||
NSR_ProcessAuthenticatedReceive(NTP_Packet *message, struct timeval *now, double now_err, NTP_Remote_Address *remote_addr)
|
|
||||||
{
|
|
||||||
int slot, found;
|
|
||||||
|
|
||||||
assert(initialised);
|
|
||||||
|
|
||||||
find_slot(remote_addr, &slot, &found);
|
|
||||||
if (found == 2) {
|
|
||||||
NCR_ProcessAuthKnown(message, now, now_err, records[slot].data);
|
|
||||||
} else {
|
|
||||||
NCR_ProcessAuthUnknown(message, now, now_err, remote_addr);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -404,12 +397,7 @@ NSR_TakeSourcesOnline(IPAddr *mask, IPAddr *address)
|
|||||||
int i;
|
int i;
|
||||||
int any;
|
int any;
|
||||||
|
|
||||||
/* Try to resolve unresolved sources now */
|
NSR_ResolveSources();
|
||||||
if (resolving_interval) {
|
|
||||||
SCH_RemoveTimeout(resolving_id);
|
|
||||||
resolving_interval--;
|
|
||||||
resolve_sources(NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
any = 0;
|
any = 0;
|
||||||
for (i=0; i<N_RECORDS; i++) {
|
for (i=0; i<N_RECORDS; i++) {
|
||||||
@@ -672,12 +660,11 @@ NSR_GetActivityReport(RPT_ActivityReport *report)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add unresolved sources to offline count */
|
report->unresolved = 0;
|
||||||
for (us = unresolved_sources; us; us = us->next) {
|
|
||||||
report->offline++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
for (us = unresolved_sources; us; us = us->next) {
|
||||||
|
report->unresolved++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -54,14 +54,14 @@ extern NSR_Status NSR_AddSource(NTP_Remote_Address *remote_addr, NTP_Source_Type
|
|||||||
until it succeeds or fails with a non-temporary error. */
|
until it succeeds or fails with a non-temporary error. */
|
||||||
extern void NSR_AddUnresolvedSource(char *name, int port, NTP_Source_Type type, SourceParameters *params);
|
extern void NSR_AddUnresolvedSource(char *name, int port, NTP_Source_Type type, SourceParameters *params);
|
||||||
|
|
||||||
|
/* Procedure to try resolve unresolved sources immediately. */
|
||||||
|
extern void NSR_ResolveSources(void);
|
||||||
|
|
||||||
/* Procedure to remove a source */
|
/* Procedure to remove a source */
|
||||||
extern NSR_Status NSR_RemoveSource(NTP_Remote_Address *remote_addr);
|
extern NSR_Status NSR_RemoveSource(NTP_Remote_Address *remote_addr);
|
||||||
|
|
||||||
/* 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);
|
extern void NSR_ProcessReceive(NTP_Packet *message, struct timeval *now, double now_err, NTP_Remote_Address *remote_addr, int length);
|
||||||
|
|
||||||
/* This routine is called by ntp_io when a new packet with an authentication tail arrives off the network */
|
|
||||||
extern void NSR_ProcessAuthenticatedReceive(NTP_Packet *message, struct timeval *now, double now_err, NTP_Remote_Address *remote_addr);
|
|
||||||
|
|
||||||
/* Initialisation function */
|
/* Initialisation function */
|
||||||
extern void NSR_Initialise(void);
|
extern void NSR_Initialise(void);
|
||||||
|
|||||||
42
pktlength.c
42
pktlength.c
@@ -26,6 +26,8 @@
|
|||||||
integer endianness within the structures.
|
integer endianness within the structures.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
#include "sysincl.h"
|
#include "sysincl.h"
|
||||||
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
@@ -122,19 +124,9 @@ PKL_CommandLength(CMD_Request *r)
|
|||||||
case REQ_CYCLELOGS :
|
case REQ_CYCLELOGS :
|
||||||
return offsetof(CMD_Request, data.cyclelogs.EOR);
|
return offsetof(CMD_Request, data.cyclelogs.EOR);
|
||||||
case REQ_SUBNETS_ACCESSED :
|
case REQ_SUBNETS_ACCESSED :
|
||||||
{
|
|
||||||
unsigned long ns;
|
|
||||||
ns = ntohl(r->data.subnets_accessed.n_subnets);
|
|
||||||
return (offsetof(CMD_Request, data.subnets_accessed.subnets) +
|
|
||||||
ns * sizeof(REQ_SubnetsAccessed_Subnet));
|
|
||||||
}
|
|
||||||
case REQ_CLIENT_ACCESSES:
|
case REQ_CLIENT_ACCESSES:
|
||||||
{
|
/* No longer supported */
|
||||||
unsigned long nc;
|
return 0;
|
||||||
nc = ntohl(r->data.client_accesses.n_clients);
|
|
||||||
return (offsetof(CMD_Request, data.client_accesses.client_ips) +
|
|
||||||
nc * sizeof(unsigned long));
|
|
||||||
}
|
|
||||||
case REQ_CLIENT_ACCESSES_BY_INDEX:
|
case REQ_CLIENT_ACCESSES_BY_INDEX:
|
||||||
return offsetof(CMD_Request, data.client_accesses_by_index.EOR);
|
return offsetof(CMD_Request, data.client_accesses_by_index.EOR);
|
||||||
case REQ_MANUAL_LIST:
|
case REQ_MANUAL_LIST:
|
||||||
@@ -147,6 +139,8 @@ PKL_CommandLength(CMD_Request *r)
|
|||||||
return offsetof(CMD_Request, data.activity.EOR);
|
return offsetof(CMD_Request, data.activity.EOR);
|
||||||
case REQ_RESELECT:
|
case REQ_RESELECT:
|
||||||
return offsetof(CMD_Request, data.reselect.EOR);
|
return offsetof(CMD_Request, data.reselect.EOR);
|
||||||
|
case REQ_RESELECTDISTANCE:
|
||||||
|
return offsetof(CMD_Request, data.reselect_distance.EOR);
|
||||||
case REQ_MODIFY_MINSTRATUM:
|
case REQ_MODIFY_MINSTRATUM:
|
||||||
return offsetof(CMD_Request, data.modify_minstratum.EOR);
|
return offsetof(CMD_Request, data.modify_minstratum.EOR);
|
||||||
case REQ_MODIFY_POLLTARGET:
|
case REQ_MODIFY_POLLTARGET:
|
||||||
@@ -190,29 +184,15 @@ PKL_ReplyLength(CMD_Reply *r)
|
|||||||
case RPY_RTC:
|
case RPY_RTC:
|
||||||
return offsetof(CMD_Reply, data.rtc.EOR);
|
return offsetof(CMD_Reply, data.rtc.EOR);
|
||||||
case RPY_SUBNETS_ACCESSED :
|
case RPY_SUBNETS_ACCESSED :
|
||||||
{
|
|
||||||
unsigned long ns = ntohl(r->data.subnets_accessed.n_subnets);
|
|
||||||
if (r->status == htons(STT_SUCCESS)) {
|
|
||||||
return (offsetof(CMD_Reply, data.subnets_accessed.subnets) +
|
|
||||||
ns * sizeof(RPY_SubnetsAccessed_Subnet));
|
|
||||||
} else {
|
|
||||||
return offsetof(CMD_Reply, data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case RPY_CLIENT_ACCESSES:
|
case RPY_CLIENT_ACCESSES:
|
||||||
{
|
/* No longer supported */
|
||||||
unsigned long nc = ntohl(r->data.client_accesses.n_clients);
|
return 0;
|
||||||
if (r->status == htons(STT_SUCCESS)) {
|
|
||||||
return (offsetof(CMD_Reply, data.client_accesses.clients) +
|
|
||||||
nc * sizeof(RPY_ClientAccesses_Client));
|
|
||||||
} else {
|
|
||||||
return offsetof(CMD_Reply, data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case RPY_CLIENT_ACCESSES_BY_INDEX:
|
case RPY_CLIENT_ACCESSES_BY_INDEX:
|
||||||
{
|
{
|
||||||
unsigned long nc = ntohl(r->data.client_accesses_by_index.n_clients);
|
unsigned long nc = ntohl(r->data.client_accesses_by_index.n_clients);
|
||||||
if (r->status == htons(STT_SUCCESS)) {
|
if (r->status == htons(STT_SUCCESS)) {
|
||||||
|
if (nc > MAX_CLIENT_ACCESSES)
|
||||||
|
return 0;
|
||||||
return (offsetof(CMD_Reply, data.client_accesses_by_index.clients) +
|
return (offsetof(CMD_Reply, data.client_accesses_by_index.clients) +
|
||||||
nc * sizeof(RPY_ClientAccesses_Client));
|
nc * sizeof(RPY_ClientAccesses_Client));
|
||||||
} else {
|
} else {
|
||||||
@@ -222,6 +202,8 @@ PKL_ReplyLength(CMD_Reply *r)
|
|||||||
case RPY_MANUAL_LIST:
|
case RPY_MANUAL_LIST:
|
||||||
{
|
{
|
||||||
unsigned long ns = ntohl(r->data.manual_list.n_samples);
|
unsigned long ns = ntohl(r->data.manual_list.n_samples);
|
||||||
|
if (ns > MAX_MANUAL_LIST_SAMPLES)
|
||||||
|
return 0;
|
||||||
if (r->status == htons(STT_SUCCESS)) {
|
if (r->status == htons(STT_SUCCESS)) {
|
||||||
return (offsetof(CMD_Reply, data.manual_list.samples) +
|
return (offsetof(CMD_Reply, data.manual_list.samples) +
|
||||||
ns * sizeof(RPY_ManualListSample));
|
ns * sizeof(RPY_ManualListSample));
|
||||||
|
|||||||
54
refclock.c
54
refclock.c
@@ -25,6 +25,8 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
#include "refclock.h"
|
#include "refclock.h"
|
||||||
#include "reference.h"
|
#include "reference.h"
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
@@ -72,8 +74,8 @@ struct RCL_Instance_Record {
|
|||||||
int leap_status;
|
int leap_status;
|
||||||
int pps_rate;
|
int pps_rate;
|
||||||
struct MedianFilter filter;
|
struct MedianFilter filter;
|
||||||
unsigned long ref_id;
|
uint32_t ref_id;
|
||||||
unsigned long lock_ref;
|
uint32_t lock_ref;
|
||||||
double offset;
|
double offset;
|
||||||
double delay;
|
double delay;
|
||||||
double precision;
|
double precision;
|
||||||
@@ -112,6 +114,11 @@ RCL_Initialise(void)
|
|||||||
{
|
{
|
||||||
CNF_AddRefclocks();
|
CNF_AddRefclocks();
|
||||||
|
|
||||||
|
if (n_sources > 0) {
|
||||||
|
LCL_AddParameterChangeHandler(slew_samples, NULL);
|
||||||
|
LCL_AddDispersionNotifyHandler(add_dispersion, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
logfileid = CNF_GetLogRefclocks() ? LOG_FileOpen("refclocks",
|
logfileid = CNF_GetLogRefclocks() ? LOG_FileOpen("refclocks",
|
||||||
" Date (UTC) Time Refid DP L P Raw offset Cooked offset Disp.")
|
" Date (UTC) Time Refid DP L P Raw offset Cooked offset Disp.")
|
||||||
: -1;
|
: -1;
|
||||||
@@ -148,14 +155,14 @@ RCL_AddRefclock(RefclockParameters *params)
|
|||||||
if (n_sources == MAX_RCL_SOURCES)
|
if (n_sources == MAX_RCL_SOURCES)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (strncmp(params->driver_name, "SHM", 4) == 0) {
|
if (strcmp(params->driver_name, "SHM") == 0) {
|
||||||
inst->driver = &RCL_SHM_driver;
|
inst->driver = &RCL_SHM_driver;
|
||||||
inst->precision = 1e-6;
|
inst->precision = 1e-6;
|
||||||
} else if (strncmp(params->driver_name, "SOCK", 4) == 0) {
|
} else if (strcmp(params->driver_name, "SOCK") == 0) {
|
||||||
inst->driver = &RCL_SOCK_driver;
|
inst->driver = &RCL_SOCK_driver;
|
||||||
inst->precision = 1e-9;
|
inst->precision = 1e-9;
|
||||||
pps_source = 1;
|
pps_source = 1;
|
||||||
} else if (strncmp(params->driver_name, "PPS", 4) == 0) {
|
} else if (strcmp(params->driver_name, "PPS") == 0) {
|
||||||
inst->driver = &RCL_PPS_driver;
|
inst->driver = &RCL_PPS_driver;
|
||||||
inst->precision = 1e-9;
|
inst->precision = 1e-9;
|
||||||
pps_source = 1;
|
pps_source = 1;
|
||||||
@@ -175,7 +182,7 @@ RCL_AddRefclock(RefclockParameters *params)
|
|||||||
inst->driver_poll = params->driver_poll;
|
inst->driver_poll = params->driver_poll;
|
||||||
inst->poll = params->poll;
|
inst->poll = params->poll;
|
||||||
inst->driver_polled = 0;
|
inst->driver_polled = 0;
|
||||||
inst->leap_status = 0;
|
inst->leap_status = LEAP_Normal;
|
||||||
inst->pps_rate = params->pps_rate;
|
inst->pps_rate = params->pps_rate;
|
||||||
inst->lock_ref = params->lock_ref_id;
|
inst->lock_ref = params->lock_ref_id;
|
||||||
inst->offset = params->offset;
|
inst->offset = params->offset;
|
||||||
@@ -242,6 +249,8 @@ RCL_AddRefclock(RefclockParameters *params)
|
|||||||
#endif
|
#endif
|
||||||
n_sources++;
|
n_sources++;
|
||||||
|
|
||||||
|
Free(params->driver_name);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -264,18 +273,13 @@ RCL_StartRefclocks(void)
|
|||||||
} else
|
} else
|
||||||
inst->lock_ref = -1;
|
inst->lock_ref = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (n_sources > 0) {
|
|
||||||
LCL_AddParameterChangeHandler(slew_samples, NULL);
|
|
||||||
LCL_AddDispersionNotifyHandler(add_dispersion, NULL);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
RCL_ReportSource(RPT_SourceReport *report, struct timeval *now)
|
RCL_ReportSource(RPT_SourceReport *report, struct timeval *now)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
unsigned long ref_id;
|
uint32_t ref_id;
|
||||||
|
|
||||||
assert(report->ip_addr.family == IPADDR_INET4);
|
assert(report->ip_addr.family == IPADDR_INET4);
|
||||||
ref_id = report->ip_addr.addr.in4;
|
ref_id = report->ip_addr.addr.in4;
|
||||||
@@ -334,7 +338,7 @@ RCL_GetDriverOption(RCL_Instance instance, char *name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
RCL_AddSample(RCL_Instance instance, struct timeval *sample_time, double offset, NTP_Leap leap_status)
|
RCL_AddSample(RCL_Instance instance, struct timeval *sample_time, double offset, int leap)
|
||||||
{
|
{
|
||||||
double correction, dispersion;
|
double correction, dispersion;
|
||||||
struct timeval cooked_time;
|
struct timeval cooked_time;
|
||||||
@@ -347,7 +351,17 @@ RCL_AddSample(RCL_Instance instance, struct timeval *sample_time, double offset,
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
filter_add_sample(&instance->filter, &cooked_time, offset - correction + instance->offset, dispersion);
|
filter_add_sample(&instance->filter, &cooked_time, offset - correction + instance->offset, dispersion);
|
||||||
instance->leap_status = leap_status;
|
|
||||||
|
switch (leap) {
|
||||||
|
case LEAP_Normal:
|
||||||
|
case LEAP_InsertSecond:
|
||||||
|
case LEAP_DeleteSecond:
|
||||||
|
instance->leap_status = leap;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
instance->leap_status = LEAP_Unsynchronised;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
log_sample(instance, &cooked_time, 0, 0, offset, offset - correction + instance->offset, dispersion);
|
log_sample(instance, &cooked_time, 0, 0, offset, offset - correction + instance->offset, dispersion);
|
||||||
|
|
||||||
@@ -416,7 +430,7 @@ RCL_AddPulse(RCL_Instance instance, struct timeval *pulse_time, double second)
|
|||||||
int is_synchronised, stratum;
|
int is_synchronised, stratum;
|
||||||
double root_delay, root_dispersion, distance;
|
double root_delay, root_dispersion, distance;
|
||||||
NTP_Leap leap;
|
NTP_Leap leap;
|
||||||
unsigned long ref_id;
|
uint32_t ref_id;
|
||||||
|
|
||||||
/* Ignore the pulse if we are not well synchronized */
|
/* Ignore the pulse if we are not well synchronized */
|
||||||
|
|
||||||
@@ -438,7 +452,7 @@ RCL_AddPulse(RCL_Instance instance, struct timeval *pulse_time, double second)
|
|||||||
filter_add_sample(&instance->filter, &cooked_time, offset, dispersion);
|
filter_add_sample(&instance->filter, &cooked_time, offset, dispersion);
|
||||||
instance->leap_status = LEAP_Normal;
|
instance->leap_status = LEAP_Normal;
|
||||||
|
|
||||||
log_sample(instance, &cooked_time, 0, 1, second, offset, dispersion);
|
log_sample(instance, &cooked_time, 0, 1, offset + correction - instance->offset, offset, dispersion);
|
||||||
|
|
||||||
/* for logging purposes */
|
/* for logging purposes */
|
||||||
if (!instance->driver->poll)
|
if (!instance->driver->poll)
|
||||||
@@ -467,7 +481,7 @@ pps_stratum(RCL_Instance instance, struct timeval *tv)
|
|||||||
int is_synchronised, stratum, i;
|
int is_synchronised, stratum, i;
|
||||||
double root_delay, root_dispersion;
|
double root_delay, root_dispersion;
|
||||||
NTP_Leap leap;
|
NTP_Leap leap;
|
||||||
unsigned long ref_id;
|
uint32_t ref_id;
|
||||||
|
|
||||||
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);
|
||||||
@@ -825,8 +839,8 @@ filter_get_sample(struct MedianFilter *filter, struct timeval *sample_time, doub
|
|||||||
prev_avg_var = filter->avg_var;
|
prev_avg_var = filter->avg_var;
|
||||||
|
|
||||||
/* update exponential moving average of the variance */
|
/* update exponential moving average of the variance */
|
||||||
if (filter->avg_var_n > 100) {
|
if (filter->avg_var_n > 50) {
|
||||||
filter->avg_var += dof / (dof + 100.0) * (var - filter->avg_var);
|
filter->avg_var += dof / (dof + 50.0) * (var - filter->avg_var);
|
||||||
} else {
|
} else {
|
||||||
filter->avg_var = (filter->avg_var * filter->avg_var_n + var * dof) /
|
filter->avg_var = (filter->avg_var * filter->avg_var_n + var * dof) /
|
||||||
(dof + filter->avg_var_n);
|
(dof + filter->avg_var_n);
|
||||||
@@ -867,6 +881,8 @@ filter_slew_samples(struct MedianFilter *filter, struct timeval *when, double df
|
|||||||
#if 0
|
#if 0
|
||||||
LOG(LOGS_INFO, LOGF_Refclock, "i=%d old_off=%.9f new_off=%.9f",
|
LOG(LOGS_INFO, LOGF_Refclock, "i=%d old_off=%.9f new_off=%.9f",
|
||||||
i, prev_offset, filter->samples[i].offset);
|
i, prev_offset, filter->samples[i].offset);
|
||||||
|
#else
|
||||||
|
(void)prev_offset;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,14 +32,14 @@
|
|||||||
#include "sources.h"
|
#include "sources.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char driver_name[4];
|
char *driver_name;
|
||||||
char *driver_parameter;
|
char *driver_parameter;
|
||||||
int driver_poll;
|
int driver_poll;
|
||||||
int poll;
|
int poll;
|
||||||
int filter_length;
|
int filter_length;
|
||||||
int pps_rate;
|
int pps_rate;
|
||||||
unsigned long ref_id;
|
uint32_t ref_id;
|
||||||
unsigned long lock_ref_id;
|
uint32_t lock_ref_id;
|
||||||
double offset;
|
double offset;
|
||||||
double delay;
|
double delay;
|
||||||
double precision;
|
double precision;
|
||||||
@@ -66,7 +66,7 @@ extern void RCL_SetDriverData(RCL_Instance instance, void *data);
|
|||||||
extern void *RCL_GetDriverData(RCL_Instance instance);
|
extern void *RCL_GetDriverData(RCL_Instance instance);
|
||||||
extern char *RCL_GetDriverParameter(RCL_Instance instance);
|
extern char *RCL_GetDriverParameter(RCL_Instance instance);
|
||||||
extern char *RCL_GetDriverOption(RCL_Instance instance, char *name);
|
extern char *RCL_GetDriverOption(RCL_Instance instance, char *name);
|
||||||
extern int RCL_AddSample(RCL_Instance instance, struct timeval *sample_time, double offset, NTP_Leap leap_status);
|
extern int RCL_AddSample(RCL_Instance instance, struct timeval *sample_time, double offset, int leap);
|
||||||
extern int RCL_AddPulse(RCL_Instance instance, struct timeval *pulse_time, double second);
|
extern int RCL_AddPulse(RCL_Instance instance, struct timeval *pulse_time, double second);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -25,11 +25,17 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
#include "refclock.h"
|
#include "refclock.h"
|
||||||
|
|
||||||
#if HAVE_PPSAPI
|
#if HAVE_PPSAPI
|
||||||
|
|
||||||
|
#if defined(HAVE_SYS_TIMEPPS_H)
|
||||||
|
#include <sys/timepps.h>
|
||||||
|
#elif defined(HAVE_TIMEPPS_H)
|
||||||
#include <timepps.h>
|
#include <timepps.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
|
|||||||
@@ -25,13 +25,14 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include "sysincl.h"
|
||||||
|
|
||||||
#include "refclock.h"
|
#include "refclock.h"
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/shm.h>
|
|
||||||
|
|
||||||
#define SHMKEY 0x4e545030
|
#define SHMKEY 0x4e545030
|
||||||
|
|
||||||
struct shmTime {
|
struct shmTime {
|
||||||
@@ -43,7 +44,7 @@ struct shmTime {
|
|||||||
* use values
|
* use values
|
||||||
* clear valid
|
* clear valid
|
||||||
*/
|
*/
|
||||||
int count;
|
volatile int count;
|
||||||
time_t clockTimeStampSec;
|
time_t clockTimeStampSec;
|
||||||
int clockTimeStampUSec;
|
int clockTimeStampUSec;
|
||||||
time_t receiveTimeStampSec;
|
time_t receiveTimeStampSec;
|
||||||
@@ -51,8 +52,10 @@ struct shmTime {
|
|||||||
int leap;
|
int leap;
|
||||||
int precision;
|
int precision;
|
||||||
int nsamples;
|
int nsamples;
|
||||||
int valid;
|
volatile int valid;
|
||||||
int dummy[10];
|
int clockTimeStampNSec;
|
||||||
|
int receiveTimeStampNSec;
|
||||||
|
int dummy[8];
|
||||||
};
|
};
|
||||||
|
|
||||||
static int shm_initialise(RCL_Instance instance) {
|
static int shm_initialise(RCL_Instance instance) {
|
||||||
@@ -87,7 +90,7 @@ static void shm_finalise(RCL_Instance instance)
|
|||||||
|
|
||||||
static int shm_poll(RCL_Instance instance)
|
static int shm_poll(RCL_Instance instance)
|
||||||
{
|
{
|
||||||
struct timeval tv1, tv2;
|
struct timeval tv;
|
||||||
struct shmTime t, *shm;
|
struct shmTime t, *shm;
|
||||||
double offset;
|
double offset;
|
||||||
|
|
||||||
@@ -105,13 +108,17 @@ static int shm_poll(RCL_Instance instance)
|
|||||||
|
|
||||||
shm->valid = 0;
|
shm->valid = 0;
|
||||||
|
|
||||||
tv1.tv_sec = t.receiveTimeStampSec;
|
tv.tv_sec = t.receiveTimeStampSec;
|
||||||
tv1.tv_usec = t.receiveTimeStampUSec;
|
tv.tv_usec = t.receiveTimeStampUSec;
|
||||||
tv2.tv_sec = t.clockTimeStampSec;
|
|
||||||
tv2.tv_usec = t.clockTimeStampUSec;
|
|
||||||
|
|
||||||
UTI_DiffTimevalsToDouble(&offset, &tv2, &tv1);
|
offset = t.clockTimeStampSec - t.receiveTimeStampSec;
|
||||||
return RCL_AddSample(instance, &tv1, offset, t.leap);
|
if (t.clockTimeStampNSec / 1000 == t.clockTimeStampUSec &&
|
||||||
|
t.receiveTimeStampNSec / 1000 == t.receiveTimeStampUSec)
|
||||||
|
offset += (t.clockTimeStampNSec - t.receiveTimeStampNSec) * 1e-9;
|
||||||
|
else
|
||||||
|
offset += (t.clockTimeStampUSec - t.receiveTimeStampUSec) * 1e-6;
|
||||||
|
|
||||||
|
return RCL_AddSample(instance, &tv, offset, t.leap);
|
||||||
}
|
}
|
||||||
|
|
||||||
RefclockDriver RCL_SHM_driver = {
|
RefclockDriver RCL_SHM_driver = {
|
||||||
|
|||||||
@@ -25,16 +25,15 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include "sysincl.h"
|
||||||
|
|
||||||
#include "refclock.h"
|
#include "refclock.h"
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "sched.h"
|
#include "sched.h"
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <sys/un.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#define SOCK_MAGIC 0x534f434b
|
#define SOCK_MAGIC 0x534f434b
|
||||||
|
|
||||||
struct sock_sample {
|
struct sock_sample {
|
||||||
|
|||||||
419
reference.c
419
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-2011
|
* Copyright (C) Miroslav Lichvar 2009-2013
|
||||||
*
|
*
|
||||||
* 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
|
||||||
@@ -25,6 +25,8 @@
|
|||||||
This module keeps track of the source which we are claiming to be
|
This module keeps track of the source which we are claiming to be
|
||||||
our reference, for the purposes of generating outgoing NTP packets */
|
our reference, for the purposes of generating outgoing NTP packets */
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
#include "sysincl.h"
|
#include "sysincl.h"
|
||||||
|
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
@@ -37,16 +39,18 @@
|
|||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
|
/* The minimum allowed skew */
|
||||||
|
#define MIN_SKEW 1.0e-12
|
||||||
|
|
||||||
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 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;
|
||||||
static unsigned long our_ref_id;
|
static uint32_t our_ref_id;
|
||||||
static IPAddr our_ref_ip;
|
static IPAddr our_ref_ip;
|
||||||
struct timeval our_ref_time; /* Stored relative to reference, NOT local time */
|
struct timeval our_ref_time; /* Stored relative to reference, NOT local time */
|
||||||
static double our_offset;
|
|
||||||
static double our_skew;
|
static double our_skew;
|
||||||
static double our_residual_freq;
|
static double our_residual_freq;
|
||||||
static double our_root_delay;
|
static double our_root_delay;
|
||||||
@@ -54,6 +58,12 @@ static double our_root_dispersion;
|
|||||||
|
|
||||||
static double max_update_skew;
|
static double max_update_skew;
|
||||||
|
|
||||||
|
static double last_offset;
|
||||||
|
static double avg2_offset;
|
||||||
|
static int avg2_moving;
|
||||||
|
|
||||||
|
static double correction_time_ratio;
|
||||||
|
|
||||||
/* Flag indicating that we are initialised */
|
/* Flag indicating that we are initialised */
|
||||||
static int initialised = 0;
|
static int initialised = 0;
|
||||||
|
|
||||||
@@ -61,6 +71,12 @@ static int initialised = 0;
|
|||||||
static int make_step_limit;
|
static int make_step_limit;
|
||||||
static double make_step_threshold;
|
static double make_step_threshold;
|
||||||
|
|
||||||
|
/* Number of updates before offset checking, number of ignored updates
|
||||||
|
before exiting and the maximum allowed offset */
|
||||||
|
static int max_offset_delay;
|
||||||
|
static int max_offset_ignore;
|
||||||
|
static double max_offset;
|
||||||
|
|
||||||
/* Flag and threshold for logging clock changes to syslog */
|
/* Flag and threshold for logging clock changes to syslog */
|
||||||
static int do_log_change;
|
static int do_log_change;
|
||||||
static double log_change_threshold;
|
static double log_change_threshold;
|
||||||
@@ -76,7 +92,10 @@ static double drift_file_age;
|
|||||||
|
|
||||||
static void update_drift_file(double, double);
|
static void update_drift_file(double, double);
|
||||||
|
|
||||||
#define MAIL_PROGRAM "/usr/lib/sendmail"
|
/* Name of a system timezone containing leap seconds occuring at midnight */
|
||||||
|
static char *leap_tzname;
|
||||||
|
static time_t last_tz_leap_check;
|
||||||
|
static NTP_Leap tz_leap;
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
@@ -110,11 +129,29 @@ static double last_ref_update_interval;
|
|||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
|
static NTP_Leap get_tz_leap(time_t when);
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static void
|
||||||
|
handle_slew(struct timeval *raw,
|
||||||
|
struct timeval *cooked,
|
||||||
|
double dfreq,
|
||||||
|
double doffset,
|
||||||
|
int is_step_change,
|
||||||
|
void *anything)
|
||||||
|
{
|
||||||
|
if (is_step_change) {
|
||||||
|
UTI_AddDoubleToTimeval(&last_ref_update, -doffset, &last_ref_update);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
void
|
void
|
||||||
REF_Initialise(void)
|
REF_Initialise(void)
|
||||||
{
|
{
|
||||||
FILE *in;
|
FILE *in;
|
||||||
char line[1024];
|
|
||||||
double file_freq_ppm, file_skew_ppm;
|
double file_freq_ppm, file_skew_ppm;
|
||||||
double our_frequency_ppm;
|
double our_frequency_ppm;
|
||||||
|
|
||||||
@@ -127,45 +164,61 @@ REF_Initialise(void)
|
|||||||
our_frequency_ppm = 0.0;
|
our_frequency_ppm = 0.0;
|
||||||
our_skew = 1.0; /* i.e. rather bad */
|
our_skew = 1.0; /* i.e. rather bad */
|
||||||
our_residual_freq = 0.0;
|
our_residual_freq = 0.0;
|
||||||
|
drift_file_age = 0.0;
|
||||||
|
|
||||||
/* Now see if we can get the drift file opened */
|
/* Now see if we can get the drift file opened */
|
||||||
drift_file = CNF_GetDriftFile();
|
drift_file = CNF_GetDriftFile();
|
||||||
if (drift_file) {
|
if (drift_file) {
|
||||||
in = fopen(drift_file, "r");
|
in = fopen(drift_file, "r");
|
||||||
if (in) {
|
if (in) {
|
||||||
if (fgets(line, sizeof(line), in)) {
|
if (fscanf(in, "%lf%lf", &file_freq_ppm, &file_skew_ppm) == 2) {
|
||||||
if (sscanf(line, "%lf%lf", &file_freq_ppm, &file_skew_ppm) == 2) {
|
/* We have read valid data */
|
||||||
/* We have read valid data */
|
our_frequency_ppm = file_freq_ppm;
|
||||||
our_frequency_ppm = file_freq_ppm;
|
our_skew = 1.0e-6 * file_skew_ppm;
|
||||||
our_skew = 1.0e-6 * file_skew_ppm;
|
if (our_skew < MIN_SKEW)
|
||||||
} else {
|
our_skew = MIN_SKEW;
|
||||||
LOG(LOGS_WARN, LOGF_Reference, "Could not parse valid frequency and skew from driftfile %s",
|
LOG(LOGS_INFO, LOGF_Reference, "Frequency %.3f +/- %.3f ppm read from %s",
|
||||||
drift_file);
|
file_freq_ppm, file_skew_ppm, drift_file);
|
||||||
}
|
LCL_SetAbsoluteFrequency(our_frequency_ppm);
|
||||||
} else {
|
} else {
|
||||||
LOG(LOGS_WARN, LOGF_Reference, "Could not read valid frequency and skew from driftfile %s",
|
LOG(LOGS_WARN, LOGF_Reference, "Could not read valid frequency and skew from driftfile %s",
|
||||||
drift_file);
|
drift_file);
|
||||||
}
|
}
|
||||||
fclose(in);
|
fclose(in);
|
||||||
} else {
|
|
||||||
LOG(LOGS_WARN, LOGF_Reference, "Could not open driftfile %s for reading",
|
|
||||||
drift_file);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
drift_file_age = 0.0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LCL_SetAbsoluteFrequency(our_frequency_ppm);
|
if (our_frequency_ppm == 0.0) {
|
||||||
|
our_frequency_ppm = LCL_ReadAbsoluteFrequency();
|
||||||
|
if (our_frequency_ppm != 0.0) {
|
||||||
|
LOG(LOGS_INFO, LOGF_Reference, "Initial frequency %.3f ppm", our_frequency_ppm);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
logfileid = CNF_GetLogTracking() ? LOG_FileOpen("tracking",
|
logfileid = CNF_GetLogTracking() ? LOG_FileOpen("tracking",
|
||||||
" Date (UTC) Time IP Address St Freq ppm Skew ppm Offset")
|
" Date (UTC) Time IP Address St Freq ppm Skew ppm Offset L Co Offset sd Rem. corr.")
|
||||||
: -1;
|
: -1;
|
||||||
|
|
||||||
max_update_skew = fabs(CNF_GetMaxUpdateSkew()) * 1.0e-6;
|
max_update_skew = fabs(CNF_GetMaxUpdateSkew()) * 1.0e-6;
|
||||||
|
|
||||||
|
correction_time_ratio = CNF_GetCorrectionTimeRatio();
|
||||||
|
|
||||||
enable_local_stratum = CNF_AllowLocalReference(&local_stratum);
|
enable_local_stratum = CNF_AllowLocalReference(&local_stratum);
|
||||||
|
|
||||||
|
leap_tzname = CNF_GetLeapSecTimezone();
|
||||||
|
if (leap_tzname) {
|
||||||
|
/* Check that the timezone has good data for Jun 30 2008 and Dec 31 2008 */
|
||||||
|
if (get_tz_leap(1214784000) == LEAP_Normal &&
|
||||||
|
get_tz_leap(1230681600) == LEAP_InsertSecond) {
|
||||||
|
LOG(LOGS_INFO, LOGF_Reference, "Using %s timezone to obtain leap second data", leap_tzname);
|
||||||
|
} else {
|
||||||
|
LOG(LOGS_WARN, LOGF_Reference, "Timezone %s failed leap second check, ignoring", leap_tzname);
|
||||||
|
leap_tzname = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CNF_GetMakeStep(&make_step_limit, &make_step_threshold);
|
CNF_GetMakeStep(&make_step_limit, &make_step_threshold);
|
||||||
|
CNF_GetMaxChange(&max_offset_delay, &max_offset_ignore, &max_offset);
|
||||||
CNF_GetLogChange(&do_log_change, &log_change_threshold);
|
CNF_GetLogChange(&do_log_change, &log_change_threshold);
|
||||||
CNF_GetMailOnChange(&do_mail_change, &mail_change_threshold, &mail_change_user);
|
CNF_GetMailOnChange(&do_mail_change, &mail_change_threshold, &mail_change_user);
|
||||||
|
|
||||||
@@ -176,11 +229,14 @@ REF_Initialise(void)
|
|||||||
memset(fb_drifts, 0, sizeof (struct fb_drift) * (fb_drift_max - fb_drift_min + 1));
|
memset(fb_drifts, 0, sizeof (struct fb_drift) * (fb_drift_max - fb_drift_min + 1));
|
||||||
next_fb_drift = 0;
|
next_fb_drift = 0;
|
||||||
fb_drift_timeout_id = -1;
|
fb_drift_timeout_id = -1;
|
||||||
last_ref_update.tv_sec = 0;
|
|
||||||
last_ref_update.tv_usec = 0;
|
|
||||||
last_ref_update_interval = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
last_ref_update.tv_sec = 0;
|
||||||
|
last_ref_update.tv_usec = 0;
|
||||||
|
last_ref_update_interval = 0.0;
|
||||||
|
|
||||||
|
LCL_AddParameterChangeHandler(handle_slew, NULL);
|
||||||
|
|
||||||
/* And just to prevent anything wierd ... */
|
/* And just to prevent anything wierd ... */
|
||||||
if (do_log_change) {
|
if (do_log_change) {
|
||||||
log_change_threshold = fabs(log_change_threshold);
|
log_change_threshold = fabs(log_change_threshold);
|
||||||
@@ -188,8 +244,6 @@ REF_Initialise(void)
|
|||||||
|
|
||||||
/* Make first entry in tracking log */
|
/* Make first entry in tracking log */
|
||||||
REF_SetUnsynchronised();
|
REF_SetUnsynchronised();
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -208,7 +262,6 @@ REF_Finalise(void)
|
|||||||
Free(fb_drifts);
|
Free(fb_drifts);
|
||||||
|
|
||||||
initialised = 0;
|
initialised = 0;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -258,9 +311,13 @@ update_drift_file(double freq_ppm, double skew)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Write the frequency and skew parameters in ppm */
|
/* Write the frequency and skew parameters in ppm */
|
||||||
fprintf(out, "%20.4f %20.4f\n", freq_ppm, 1.0e6 * skew);
|
if ((fprintf(out, "%20.6f %20.6f\n", freq_ppm, 1.0e6 * skew) < 0) |
|
||||||
|
fclose(out)) {
|
||||||
fclose(out);
|
Free(temp_drift_file);
|
||||||
|
LOG(LOGS_WARN, LOGF_Reference, "Could not write to temporary driftfile %s.tmp",
|
||||||
|
drift_file);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* Clone the file attributes from the existing file if there is one. */
|
/* Clone the file attributes from the existing file if there is one. */
|
||||||
|
|
||||||
@@ -276,7 +333,7 @@ update_drift_file(double freq_ppm, double skew)
|
|||||||
if (rename(temp_drift_file,drift_file)) {
|
if (rename(temp_drift_file,drift_file)) {
|
||||||
unlink(temp_drift_file);
|
unlink(temp_drift_file);
|
||||||
Free(temp_drift_file);
|
Free(temp_drift_file);
|
||||||
LOG(LOGS_WARN, LOGF_Reference, "Could not replace old driftfile %s with new one %s.tmp (%d)",
|
LOG(LOGS_WARN, LOGF_Reference, "Could not replace old driftfile %s with new one %s.tmp",
|
||||||
drift_file,drift_file);
|
drift_file,drift_file);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -365,7 +422,7 @@ schedule_fb_drift(struct timeval *now)
|
|||||||
|
|
||||||
UTI_DiffTimevalsToDouble(&unsynchronised, now, &last_ref_update);
|
UTI_DiffTimevalsToDouble(&unsynchronised, now, &last_ref_update);
|
||||||
|
|
||||||
for (c = 0, i = fb_drift_min; i <= fb_drift_max; i++) {
|
for (c = secs = 0, i = fb_drift_min; i <= fb_drift_max; i++) {
|
||||||
secs = 1 << i;
|
secs = 1 << i;
|
||||||
|
|
||||||
if (fb_drifts[i - fb_drift_min].secs < secs)
|
if (fb_drifts[i - fb_drift_min].secs < secs)
|
||||||
@@ -401,12 +458,11 @@ schedule_fb_drift(struct timeval *now)
|
|||||||
#define S_MAX_USER_LEN "128"
|
#define S_MAX_USER_LEN "128"
|
||||||
|
|
||||||
static void
|
static void
|
||||||
maybe_log_offset(double offset)
|
maybe_log_offset(double offset, time_t now)
|
||||||
{
|
{
|
||||||
double abs_offset;
|
double abs_offset;
|
||||||
FILE *p;
|
FILE *p;
|
||||||
char buffer[BUFLEN], host[BUFLEN];
|
char buffer[BUFLEN], host[BUFLEN];
|
||||||
time_t now;
|
|
||||||
struct tm stm;
|
struct tm stm;
|
||||||
|
|
||||||
abs_offset = fabs(offset);
|
abs_offset = fabs(offset);
|
||||||
@@ -428,7 +484,6 @@ maybe_log_offset(double offset)
|
|||||||
}
|
}
|
||||||
fprintf(p, "Subject: chronyd reports change to system clock on node [%s]\n", host);
|
fprintf(p, "Subject: chronyd reports change to system clock on node [%s]\n", host);
|
||||||
fputs("\n", p);
|
fputs("\n", p);
|
||||||
now = time(NULL);
|
|
||||||
stm = *localtime(&now);
|
stm = *localtime(&now);
|
||||||
strftime(buffer, sizeof(buffer), "On %A, %d %B %Y\n with the system clock reading %H:%M:%S (%Z)", &stm);
|
strftime(buffer, sizeof(buffer), "On %A, %d %B %Y\n with the system clock reading %H:%M:%S (%Z)", &stm);
|
||||||
fputs(buffer, p);
|
fputs(buffer, p);
|
||||||
@@ -464,20 +519,109 @@ maybe_make_step()
|
|||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
static void
|
static int
|
||||||
update_leap_status(NTP_Leap leap)
|
is_offset_ok(double offset)
|
||||||
|
{
|
||||||
|
if (max_offset_delay < 0)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
if (max_offset_delay > 0) {
|
||||||
|
max_offset_delay--;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
offset = fabs(offset);
|
||||||
|
if (offset > max_offset) {
|
||||||
|
LOG(LOGS_WARN, LOGF_Reference,
|
||||||
|
"Adjustment of %.3f seconds exceeds the allowed maximum of %.3f seconds (%s) ",
|
||||||
|
offset, max_offset, !max_offset_ignore ? "exiting" : "ignored");
|
||||||
|
if (!max_offset_ignore)
|
||||||
|
SCH_QuitProgram();
|
||||||
|
else if (max_offset_ignore > 0)
|
||||||
|
max_offset_ignore--;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static NTP_Leap
|
||||||
|
get_tz_leap(time_t when)
|
||||||
|
{
|
||||||
|
struct tm stm;
|
||||||
|
time_t t;
|
||||||
|
char *tz_env, tz_orig[128];
|
||||||
|
|
||||||
|
/* Do this check at most twice a day */
|
||||||
|
when = when / (12 * 3600) * (12 * 3600);
|
||||||
|
if (last_tz_leap_check == when)
|
||||||
|
return tz_leap;
|
||||||
|
|
||||||
|
last_tz_leap_check = when;
|
||||||
|
tz_leap = LEAP_Normal;
|
||||||
|
|
||||||
|
stm = *gmtime(&when);
|
||||||
|
|
||||||
|
/* Check for leap second only in the latter half of June and December */
|
||||||
|
if (stm.tm_mon == 5 && stm.tm_mday > 14)
|
||||||
|
stm.tm_mday = 30;
|
||||||
|
else if (stm.tm_mon == 11 && stm.tm_mday > 14)
|
||||||
|
stm.tm_mday = 31;
|
||||||
|
else
|
||||||
|
return tz_leap;
|
||||||
|
|
||||||
|
/* Temporarily switch to the timezone containing leap seconds */
|
||||||
|
tz_env = getenv("TZ");
|
||||||
|
if (tz_env) {
|
||||||
|
if (strlen(tz_env) >= sizeof (tz_orig))
|
||||||
|
return tz_leap;
|
||||||
|
strcpy(tz_orig, tz_env);
|
||||||
|
}
|
||||||
|
setenv("TZ", leap_tzname, 1);
|
||||||
|
tzset();
|
||||||
|
|
||||||
|
/* Set the time to 23:59:60 and see how it overflows in mktime() */
|
||||||
|
stm.tm_sec = 60;
|
||||||
|
stm.tm_min = 59;
|
||||||
|
stm.tm_hour = 23;
|
||||||
|
|
||||||
|
t = mktime(&stm);
|
||||||
|
|
||||||
|
if (tz_env)
|
||||||
|
setenv("TZ", tz_orig, 1);
|
||||||
|
else
|
||||||
|
unsetenv("TZ");
|
||||||
|
tzset();
|
||||||
|
|
||||||
|
if (t == -1)
|
||||||
|
return tz_leap;
|
||||||
|
|
||||||
|
if (stm.tm_sec == 60)
|
||||||
|
tz_leap = LEAP_InsertSecond;
|
||||||
|
else if (stm.tm_sec == 1)
|
||||||
|
tz_leap = LEAP_DeleteSecond;
|
||||||
|
|
||||||
|
return tz_leap;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static void
|
||||||
|
update_leap_status(NTP_Leap leap, time_t now)
|
||||||
{
|
{
|
||||||
time_t now;
|
|
||||||
struct tm stm;
|
struct tm stm;
|
||||||
int leap_sec;
|
int leap_sec;
|
||||||
|
|
||||||
leap_sec = 0;
|
leap_sec = 0;
|
||||||
|
|
||||||
|
if (leap_tzname && now && leap == LEAP_Normal)
|
||||||
|
leap = get_tz_leap(now);
|
||||||
|
|
||||||
if (leap == LEAP_InsertSecond || leap == LEAP_DeleteSecond) {
|
if (leap == LEAP_InsertSecond || leap == LEAP_DeleteSecond) {
|
||||||
/* Insert/delete leap second only on June 30 or December 31
|
/* Insert/delete leap second only on June 30 or December 31
|
||||||
and in other months ignore the leap status completely */
|
and in other months ignore the leap status completely */
|
||||||
|
|
||||||
now = time(NULL);
|
|
||||||
stm = *gmtime(&now);
|
stm = *gmtime(&now);
|
||||||
|
|
||||||
if (stm.tm_mon != 5 && stm.tm_mon != 11) {
|
if (stm.tm_mon != 5 && stm.tm_mon != 11) {
|
||||||
@@ -503,11 +647,16 @@ update_leap_status(NTP_Leap leap)
|
|||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
write_log(struct timeval *ref_time, char *ref, int stratum, double freq, double skew, double offset)
|
write_log(struct timeval *ref_time, char *ref, int stratum, NTP_Leap leap,
|
||||||
|
double freq, double skew, double offset, int combined_sources,
|
||||||
|
double offset_sd, double uncorrected_offset)
|
||||||
{
|
{
|
||||||
|
const char leap_codes[4] = {'N', '+', '-', '?'};
|
||||||
if (logfileid != -1) {
|
if (logfileid != -1) {
|
||||||
LOG_FileWrite(logfileid, "%s %-15s %2d %10.3f %10.3f %10.3e",
|
LOG_FileWrite(logfileid, "%s %-15s %2d %10.3f %10.3f %10.3e %1c %2d %10.3e %10.3e",
|
||||||
UTI_TimeToLogForm(ref_time->tv_sec), ref, stratum, freq, skew, offset);
|
UTI_TimeToLogForm(ref_time->tv_sec), ref, stratum, freq, skew,
|
||||||
|
offset, leap_codes[leap], combined_sources, offset_sd,
|
||||||
|
uncorrected_offset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -516,10 +665,12 @@ write_log(struct timeval *ref_time, char *ref, int stratum, double freq, double
|
|||||||
void
|
void
|
||||||
REF_SetReference(int stratum,
|
REF_SetReference(int stratum,
|
||||||
NTP_Leap leap,
|
NTP_Leap leap,
|
||||||
unsigned long ref_id,
|
int combined_sources,
|
||||||
|
uint32_t ref_id,
|
||||||
IPAddr *ref_ip,
|
IPAddr *ref_ip,
|
||||||
struct timeval *ref_time,
|
struct timeval *ref_time,
|
||||||
double offset,
|
double offset,
|
||||||
|
double offset_sd,
|
||||||
double frequency,
|
double frequency,
|
||||||
double skew,
|
double skew,
|
||||||
double root_delay,
|
double root_delay,
|
||||||
@@ -531,19 +682,20 @@ REF_SetReference(int stratum,
|
|||||||
double old_weight, new_weight, sum_weight;
|
double old_weight, new_weight, sum_weight;
|
||||||
double delta_freq1, delta_freq2;
|
double delta_freq1, delta_freq2;
|
||||||
double skew1, skew2;
|
double skew1, skew2;
|
||||||
|
double our_offset;
|
||||||
double our_frequency;
|
double our_frequency;
|
||||||
|
|
||||||
double abs_freq_ppm;
|
double abs_freq_ppm;
|
||||||
|
|
||||||
double update_interval;
|
double update_interval;
|
||||||
|
double elapsed;
|
||||||
|
double correction_rate;
|
||||||
|
double uncorrected_offset;
|
||||||
|
struct timeval now, raw_now, ev_now, ev_raw_now;
|
||||||
|
|
||||||
assert(initialised);
|
assert(initialised);
|
||||||
|
|
||||||
/* Avoid getting NaNs */
|
/* Guard against dividing by zero */
|
||||||
if (skew < 1e-12)
|
if (skew < MIN_SKEW)
|
||||||
skew = 1e-12;
|
skew = MIN_SKEW;
|
||||||
if (our_skew < 1e-12)
|
|
||||||
our_skew = 1e-12;
|
|
||||||
|
|
||||||
/* If we get a serious rounding error in the source stats regression
|
/* If we get a serious rounding error in the source stats regression
|
||||||
processing, there is a remote chance that the skew argument is a
|
processing, there is a remote chance that the skew argument is a
|
||||||
@@ -563,8 +715,20 @@ REF_SetReference(int stratum,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LCL_ReadRawTime(&raw_now);
|
||||||
|
|
||||||
are_we_synchronised = 1;
|
/* This is cheaper than calling LCL_CookTime */
|
||||||
|
SCH_GetLastEventTime(&ev_now, NULL, &ev_raw_now);
|
||||||
|
UTI_DiffTimevalsToDouble(&uncorrected_offset, &ev_now, &ev_raw_now);
|
||||||
|
UTI_AddDoubleToTimeval(&raw_now, uncorrected_offset, &now);
|
||||||
|
|
||||||
|
UTI_DiffTimevalsToDouble(&elapsed, &now, ref_time);
|
||||||
|
our_offset = offset + elapsed * frequency;
|
||||||
|
|
||||||
|
if (!is_offset_ok(our_offset))
|
||||||
|
return;
|
||||||
|
|
||||||
|
are_we_synchronised = leap != LEAP_Unsynchronised ? 1 : 0;
|
||||||
our_stratum = stratum + 1;
|
our_stratum = stratum + 1;
|
||||||
our_ref_id = ref_id;
|
our_ref_id = ref_id;
|
||||||
if (ref_ip)
|
if (ref_ip)
|
||||||
@@ -572,16 +736,37 @@ REF_SetReference(int stratum,
|
|||||||
else
|
else
|
||||||
our_ref_ip.family = IPADDR_UNSPEC;
|
our_ref_ip.family = IPADDR_UNSPEC;
|
||||||
our_ref_time = *ref_time;
|
our_ref_time = *ref_time;
|
||||||
our_offset = offset;
|
|
||||||
our_root_delay = root_delay;
|
our_root_delay = root_delay;
|
||||||
our_root_dispersion = root_dispersion;
|
our_root_dispersion = root_dispersion;
|
||||||
|
|
||||||
update_leap_status(leap);
|
if (last_ref_update.tv_sec) {
|
||||||
|
UTI_DiffTimevalsToDouble(&update_interval, &now, &last_ref_update);
|
||||||
|
if (update_interval < 0.0)
|
||||||
|
update_interval = 0.0;
|
||||||
|
} else {
|
||||||
|
update_interval = 0.0;
|
||||||
|
}
|
||||||
|
last_ref_update = now;
|
||||||
|
|
||||||
|
/* We want to correct the offset quickly, but we also want to keep the
|
||||||
|
frequency error caused by the correction itself low.
|
||||||
|
|
||||||
|
Define correction rate as the area of the region bounded by the graph of
|
||||||
|
offset corrected in time. Set the rate so that the time needed to correct
|
||||||
|
an offset equal to the current sourcestats stddev will be equal to the
|
||||||
|
update interval multiplied by the correction time ratio (assuming linear
|
||||||
|
adjustment). The offset and the time needed to make the correction are
|
||||||
|
inversely proportional.
|
||||||
|
|
||||||
|
This is only a suggestion and it's up to the system driver how the
|
||||||
|
adjustment will be executed. */
|
||||||
|
|
||||||
|
correction_rate = correction_time_ratio * 0.5 * offset_sd * update_interval;
|
||||||
|
|
||||||
/* Eliminate updates that are based on totally unreliable frequency
|
/* Eliminate updates that are based on totally unreliable frequency
|
||||||
information */
|
information. Ignore this limit with manual reference. */
|
||||||
|
|
||||||
if (fabs(skew) < max_update_skew) {
|
if (fabs(skew) < max_update_skew || leap == LEAP_Unsynchronised) {
|
||||||
|
|
||||||
previous_skew = our_skew;
|
previous_skew = our_skew;
|
||||||
new_skew = skew;
|
new_skew = skew;
|
||||||
@@ -593,9 +778,10 @@ REF_SetReference(int stratum,
|
|||||||
the local module. */
|
the local module. */
|
||||||
new_freq = frequency;
|
new_freq = frequency;
|
||||||
|
|
||||||
/* Set new frequency based on weighted average of old and new skew. */
|
/* Set new frequency based on weighted average of old and new skew. With
|
||||||
|
manual reference the old frequency has no weight. */
|
||||||
|
|
||||||
old_weight = 1.0 / Sqr(previous_skew);
|
old_weight = leap != LEAP_Unsynchronised ? 1.0 / Sqr(previous_skew) : 0.0;
|
||||||
new_weight = 3.0 / Sqr(new_skew);
|
new_weight = 3.0 / Sqr(new_skew);
|
||||||
|
|
||||||
sum_weight = old_weight + new_weight;
|
sum_weight = old_weight + new_weight;
|
||||||
@@ -611,32 +797,34 @@ REF_SetReference(int stratum,
|
|||||||
|
|
||||||
our_residual_freq = new_freq - our_frequency;
|
our_residual_freq = new_freq - our_frequency;
|
||||||
|
|
||||||
maybe_log_offset(our_offset);
|
LCL_AccumulateFrequencyAndOffset(our_frequency, our_offset, correction_rate);
|
||||||
LCL_AccumulateFrequencyAndOffset(our_frequency, our_offset);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
LOG(LOGS_INFO, LOGF_Reference, "Skew %f too large to track, offset=%f", skew, our_offset);
|
LOG(LOGS_INFO, LOGF_Reference, "Skew %f too large to track, offset=%f", skew, our_offset);
|
||||||
#endif
|
#endif
|
||||||
maybe_log_offset(our_offset);
|
LCL_AccumulateOffset(our_offset, correction_rate);
|
||||||
LCL_AccumulateOffset(our_offset);
|
|
||||||
|
|
||||||
our_residual_freq = frequency;
|
our_residual_freq = frequency;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
update_leap_status(leap, raw_now.tv_sec);
|
||||||
|
maybe_log_offset(our_offset, raw_now.tv_sec);
|
||||||
maybe_make_step();
|
maybe_make_step();
|
||||||
|
|
||||||
abs_freq_ppm = LCL_ReadAbsoluteFrequency();
|
abs_freq_ppm = LCL_ReadAbsoluteFrequency();
|
||||||
|
|
||||||
write_log(ref_time,
|
write_log(&now,
|
||||||
our_ref_ip.family != IPADDR_UNSPEC ? UTI_IPToString(&our_ref_ip) : UTI_RefidToString(our_ref_id),
|
our_ref_ip.family != IPADDR_UNSPEC ? UTI_IPToString(&our_ref_ip) : UTI_RefidToString(our_ref_id),
|
||||||
our_stratum,
|
our_stratum,
|
||||||
|
our_leap_status,
|
||||||
abs_freq_ppm,
|
abs_freq_ppm,
|
||||||
1.0e6*our_skew,
|
1.0e6*our_skew,
|
||||||
our_offset);
|
our_offset,
|
||||||
|
combined_sources,
|
||||||
UTI_DiffTimevalsToDouble(&update_interval, ref_time, &last_ref_update);
|
offset_sd,
|
||||||
|
uncorrected_offset);
|
||||||
|
|
||||||
if (drift_file) {
|
if (drift_file) {
|
||||||
/* Update drift file at most once per hour */
|
/* Update drift file at most once per hour */
|
||||||
@@ -652,14 +840,17 @@ REF_SetReference(int stratum,
|
|||||||
update_fb_drifts(abs_freq_ppm, update_interval);
|
update_fb_drifts(abs_freq_ppm, update_interval);
|
||||||
}
|
}
|
||||||
|
|
||||||
last_ref_update = *ref_time;
|
|
||||||
last_ref_update_interval = update_interval;
|
last_ref_update_interval = update_interval;
|
||||||
|
last_offset = our_offset;
|
||||||
|
|
||||||
/* And now set the freq and offset to zero */
|
/* Update the moving average of squares of offset, quickly on start */
|
||||||
our_frequency = 0.0;
|
if (avg2_moving) {
|
||||||
our_offset = 0.0;
|
avg2_offset += 0.1 * (our_offset * our_offset - avg2_offset);
|
||||||
|
} else {
|
||||||
return;
|
if (avg2_offset > 0.0 && avg2_offset < our_offset * our_offset)
|
||||||
|
avg2_moving = 1;
|
||||||
|
avg2_offset = our_offset * our_offset;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -673,32 +864,13 @@ REF_SetManualReference
|
|||||||
double skew
|
double skew
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
double abs_freq_ppm;
|
uint32_t manual_refid = 0x4D414E55; /* MANU */
|
||||||
|
|
||||||
/* We are not synchronised to an external source, as such. This is
|
/* We are not synchronised to an external source, as such. This is
|
||||||
only supposed to be used with the local source option, really
|
only supposed to be used with the local source option, really
|
||||||
... */
|
... */
|
||||||
are_we_synchronised = 0;
|
REF_SetReference(0, LEAP_Unsynchronised, 1, manual_refid, NULL,
|
||||||
|
ref_time, offset, 0.0, frequency, skew, 0.0, 0.0);
|
||||||
our_skew = skew;
|
|
||||||
our_residual_freq = 0.0;
|
|
||||||
|
|
||||||
maybe_log_offset(offset);
|
|
||||||
LCL_AccumulateFrequencyAndOffset(frequency, offset);
|
|
||||||
maybe_make_step();
|
|
||||||
|
|
||||||
abs_freq_ppm = LCL_ReadAbsoluteFrequency();
|
|
||||||
|
|
||||||
write_log(ref_time,
|
|
||||||
"127.127.1.1",
|
|
||||||
our_stratum,
|
|
||||||
abs_freq_ppm,
|
|
||||||
1.0e6*our_skew,
|
|
||||||
our_offset);
|
|
||||||
|
|
||||||
if (drift_file) {
|
|
||||||
update_drift_file(abs_freq_ppm, our_skew);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -707,26 +879,32 @@ void
|
|||||||
REF_SetUnsynchronised(void)
|
REF_SetUnsynchronised(void)
|
||||||
{
|
{
|
||||||
/* Variables required for logging to statistics log */
|
/* Variables required for logging to statistics log */
|
||||||
struct timeval now;
|
struct timeval now, now_raw;
|
||||||
|
double uncorrected_offset;
|
||||||
|
|
||||||
assert(initialised);
|
assert(initialised);
|
||||||
|
|
||||||
LCL_ReadCookedTime(&now, NULL);
|
/* This is cheaper than calling LCL_CookTime */
|
||||||
|
SCH_GetLastEventTime(&now, NULL, &now_raw);
|
||||||
|
UTI_DiffTimevalsToDouble(&uncorrected_offset, &now, &now_raw);
|
||||||
|
|
||||||
if (fb_drifts) {
|
if (fb_drifts) {
|
||||||
schedule_fb_drift(&now);
|
schedule_fb_drift(&now);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
update_leap_status(LEAP_Unsynchronised, 0);
|
||||||
|
are_we_synchronised = 0;
|
||||||
|
|
||||||
write_log(&now,
|
write_log(&now,
|
||||||
"0.0.0.0",
|
"0.0.0.0",
|
||||||
0,
|
0,
|
||||||
|
our_leap_status,
|
||||||
LCL_ReadAbsoluteFrequency(),
|
LCL_ReadAbsoluteFrequency(),
|
||||||
1.0e6*our_skew,
|
1.0e6*our_skew,
|
||||||
0.0);
|
0.0,
|
||||||
|
0,
|
||||||
are_we_synchronised = 0;
|
0.0,
|
||||||
|
uncorrected_offset);
|
||||||
update_leap_status(LEAP_Unsynchronised);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -738,7 +916,7 @@ REF_GetReferenceParams
|
|||||||
int *is_synchronised,
|
int *is_synchronised,
|
||||||
NTP_Leap *leap_status,
|
NTP_Leap *leap_status,
|
||||||
int *stratum,
|
int *stratum,
|
||||||
unsigned long *ref_id,
|
uint32_t *ref_id,
|
||||||
struct timeval *ref_time,
|
struct timeval *ref_time,
|
||||||
double *root_delay,
|
double *root_delay,
|
||||||
double *root_dispersion
|
double *root_dispersion
|
||||||
@@ -791,7 +969,7 @@ REF_GetReferenceParams
|
|||||||
|
|
||||||
*leap_status = LEAP_Unsynchronised;
|
*leap_status = LEAP_Unsynchronised;
|
||||||
*stratum = 0;
|
*stratum = 0;
|
||||||
*ref_id = 0UL;
|
*ref_id = 0;
|
||||||
ref_time->tv_sec = ref_time->tv_usec = 0;
|
ref_time->tv_sec = ref_time->tv_usec = 0;
|
||||||
/* These values seem to be standard for a client, and
|
/* These values seem to be standard for a client, and
|
||||||
any peer or client of ours will ignore them anyway because
|
any peer or client of ours will ignore them anyway because
|
||||||
@@ -866,6 +1044,22 @@ REF_GetTrackingReport(RPT_TrackingReport *rep)
|
|||||||
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 = 0;
|
||||||
|
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->freq_ppm = LCL_ReadAbsoluteFrequency();
|
||||||
|
rep->resid_freq_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_offset = last_offset;
|
||||||
|
rep->rms_offset = sqrt(avg2_offset);
|
||||||
|
|
||||||
if (are_we_synchronised) {
|
if (are_we_synchronised) {
|
||||||
|
|
||||||
UTI_DiffTimevalsToDouble(&elapsed, &now_cooked, &our_ref_time);
|
UTI_DiffTimevalsToDouble(&elapsed, &now_cooked, &our_ref_time);
|
||||||
@@ -875,8 +1069,6 @@ REF_GetTrackingReport(RPT_TrackingReport *rep)
|
|||||||
rep->ip_addr = our_ref_ip;
|
rep->ip_addr = our_ref_ip;
|
||||||
rep->stratum = our_stratum;
|
rep->stratum = our_stratum;
|
||||||
rep->ref_time = our_ref_time;
|
rep->ref_time = our_ref_time;
|
||||||
rep->current_correction = correction;
|
|
||||||
rep->freq_ppm = LCL_ReadAbsoluteFrequency();
|
|
||||||
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_delay = our_root_delay;
|
||||||
@@ -888,26 +1080,7 @@ REF_GetTrackingReport(RPT_TrackingReport *rep)
|
|||||||
rep->ip_addr.family = IPADDR_UNSPEC;
|
rep->ip_addr.family = IPADDR_UNSPEC;
|
||||||
rep->stratum = local_stratum;
|
rep->stratum = local_stratum;
|
||||||
rep->ref_time = now_cooked;
|
rep->ref_time = now_cooked;
|
||||||
rep->current_correction = correction;
|
|
||||||
rep->freq_ppm = LCL_ReadAbsoluteFrequency();
|
|
||||||
rep->resid_freq_ppm = 0.0;
|
|
||||||
rep->skew_ppm = 0.0;
|
|
||||||
rep->root_delay = 0.0;
|
|
||||||
rep->root_dispersion = LCL_GetSysPrecisionAsQuantum();
|
rep->root_dispersion = LCL_GetSysPrecisionAsQuantum();
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
rep->ref_id = 0UL;
|
|
||||||
rep->ip_addr.family = IPADDR_UNSPEC;
|
|
||||||
rep->stratum = 0;
|
|
||||||
rep->ref_time.tv_sec = 0;
|
|
||||||
rep->ref_time.tv_usec = 0;
|
|
||||||
rep->current_correction = correction;
|
|
||||||
rep->freq_ppm = LCL_ReadAbsoluteFrequency();
|
|
||||||
rep->resid_freq_ppm = 0.0;
|
|
||||||
rep->skew_ppm = 0.0;
|
|
||||||
rep->root_delay = 0.0;
|
|
||||||
rep->root_dispersion = 0.0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ extern void REF_GetReferenceParams
|
|||||||
int *is_synchronised,
|
int *is_synchronised,
|
||||||
NTP_Leap *leap,
|
NTP_Leap *leap,
|
||||||
int *stratum,
|
int *stratum,
|
||||||
unsigned long *ref_id,
|
uint32_t *ref_id,
|
||||||
struct timeval *ref_time,
|
struct timeval *ref_time,
|
||||||
double *root_delay,
|
double *root_delay,
|
||||||
double *root_dispersion
|
double *root_dispersion
|
||||||
@@ -105,10 +105,12 @@ extern void REF_SetReference
|
|||||||
(
|
(
|
||||||
int stratum,
|
int stratum,
|
||||||
NTP_Leap leap,
|
NTP_Leap leap,
|
||||||
unsigned long ref_id,
|
int combined_sources,
|
||||||
|
uint32_t ref_id,
|
||||||
IPAddr *ref_ip,
|
IPAddr *ref_ip,
|
||||||
struct timeval *ref_time,
|
struct timeval *ref_time,
|
||||||
double offset,
|
double offset,
|
||||||
|
double offset_sd,
|
||||||
double frequency,
|
double frequency,
|
||||||
double skew,
|
double skew,
|
||||||
double root_delay,
|
double root_delay,
|
||||||
|
|||||||
34
regress.c
34
regress.c
@@ -26,11 +26,9 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <assert.h>
|
#include "config.h"
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include "sysincl.h"
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "regress.h"
|
#include "regress.h"
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
@@ -101,8 +99,6 @@ RGR_WeightedRegression
|
|||||||
*sb0 = sqrt(*s2 / W + aa * aa);
|
*sb0 = sqrt(*s2 / W + aa * aa);
|
||||||
|
|
||||||
*s2 *= (n / W); /* Giving weighted average of variances */
|
*s2 *= (n / W); /* Giving weighted average of variances */
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -226,6 +222,9 @@ RGR_FindBestRegression
|
|||||||
int m, /* number of extra samples in x and y arrays
|
int m, /* number of extra samples in x and y arrays
|
||||||
(negative index) which can be used to
|
(negative index) which can be used to
|
||||||
extend runs test */
|
extend runs test */
|
||||||
|
int min_samples, /* minimum number of samples to be kept after
|
||||||
|
changing the starting index to pass the runs
|
||||||
|
test */
|
||||||
|
|
||||||
/* And now the results */
|
/* And now the results */
|
||||||
|
|
||||||
@@ -297,7 +296,13 @@ RGR_FindBestRegression
|
|||||||
/* Count number of runs */
|
/* Count number of runs */
|
||||||
nruns = n_runs_from_residuals(resid, n - resid_start);
|
nruns = n_runs_from_residuals(resid, n - resid_start);
|
||||||
|
|
||||||
if (nruns > critical_runs[n - resid_start] || n - start <= MIN_SAMPLES_FOR_REGRESS) {
|
if (nruns > critical_runs[n - resid_start] ||
|
||||||
|
n - start <= MIN_SAMPLES_FOR_REGRESS ||
|
||||||
|
n - start <= min_samples) {
|
||||||
|
if (start != resid_start) {
|
||||||
|
/* Ignore extra samples in returned nruns */
|
||||||
|
nruns = n_runs_from_residuals(resid - resid_start + start, n - start);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
/* Try dropping one sample at a time until the runs test passes. */
|
/* Try dropping one sample at a time until the runs test passes. */
|
||||||
@@ -416,7 +421,7 @@ find_ordered_entry(double *x, int n, int index)
|
|||||||
{
|
{
|
||||||
int flags[MAX_POINTS];
|
int flags[MAX_POINTS];
|
||||||
|
|
||||||
bzero(flags, n * sizeof(int));
|
memset(flags, 0, n * sizeof(int));
|
||||||
return find_ordered_entry_with_flags(x, n, index, flags);
|
return find_ordered_entry_with_flags(x, n, index, flags);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -582,7 +587,7 @@ RGR_FindBestRobustRegression
|
|||||||
Estimate standard deviation of b and expand range about b based
|
Estimate standard deviation of b and expand range about b based
|
||||||
on that. */
|
on that. */
|
||||||
sb = sqrt(s2 * W/V);
|
sb = sqrt(s2 * W/V);
|
||||||
if (sb > 0.0) {
|
if (sb > tol) {
|
||||||
incr = 3.0 * sb;
|
incr = 3.0 * sb;
|
||||||
} else {
|
} else {
|
||||||
incr = 3.0 * tol;
|
incr = 3.0 * tol;
|
||||||
@@ -592,6 +597,11 @@ RGR_FindBestRobustRegression
|
|||||||
bhi = b;
|
bhi = b;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
/* Make sure incr is significant to blo and bhi */
|
||||||
|
while (bhi + incr == bhi || blo - incr == blo) {
|
||||||
|
incr *= 2;
|
||||||
|
}
|
||||||
|
|
||||||
blo -= incr;
|
blo -= incr;
|
||||||
bhi += incr;
|
bhi += incr;
|
||||||
|
|
||||||
@@ -599,8 +609,8 @@ RGR_FindBestRobustRegression
|
|||||||
eval_robust_residual(x + start, y + start, n_points, blo, &a, &rlo);
|
eval_robust_residual(x + start, y + start, n_points, blo, &a, &rlo);
|
||||||
eval_robust_residual(x + start, y + start, n_points, bhi, &a, &rhi);
|
eval_robust_residual(x + start, y + start, n_points, bhi, &a, &rhi);
|
||||||
|
|
||||||
} while (rlo * rhi > 0.0); /* fn vals have same sign, i.e. root not
|
} while (rlo * rhi >= 0.0); /* fn vals have same sign or one is zero,
|
||||||
in interval. */
|
i.e. root not in interval (rlo, rhi). */
|
||||||
|
|
||||||
/* OK, so the root for b lies in (blo, bhi). Start bisecting */
|
/* OK, so the root for b lies in (blo, bhi). Start bisecting */
|
||||||
do {
|
do {
|
||||||
@@ -617,7 +627,7 @@ RGR_FindBestRobustRegression
|
|||||||
} else {
|
} else {
|
||||||
assert(0);
|
assert(0);
|
||||||
}
|
}
|
||||||
} while ((bhi - blo) > tol);
|
} while ((bhi - blo) > tol && (bmid - blo) * (bhi - bmid) > 0.0);
|
||||||
|
|
||||||
*b0 = a;
|
*b0 = a;
|
||||||
*b1 = bmid;
|
*b1 = bmid;
|
||||||
|
|||||||
@@ -80,6 +80,9 @@ RGR_FindBestRegression
|
|||||||
int m, /* number of extra samples in x and y arrays
|
int m, /* number of extra samples in x and y arrays
|
||||||
(negative index) which can be used to
|
(negative index) which can be used to
|
||||||
extend runs test */
|
extend runs test */
|
||||||
|
int min_samples, /* minimum number of samples to be kept after
|
||||||
|
changing the starting index to pass the runs
|
||||||
|
test */
|
||||||
|
|
||||||
/* And now the results */
|
/* And now the results */
|
||||||
|
|
||||||
|
|||||||
13
reports.h
13
reports.h
@@ -37,8 +37,10 @@ typedef struct {
|
|||||||
int stratum;
|
int stratum;
|
||||||
int poll;
|
int poll;
|
||||||
enum {RPT_NTP_CLIENT, RPT_NTP_PEER, RPT_LOCAL_REFERENCE} mode;
|
enum {RPT_NTP_CLIENT, RPT_NTP_PEER, RPT_LOCAL_REFERENCE} mode;
|
||||||
enum {RPT_SYNC, RPT_UNREACH, RPT_FALSETICKER, RPT_JITTERY, RPT_CANDIDATE} state;
|
enum {RPT_SYNC, RPT_UNREACH, RPT_FALSETICKER, RPT_JITTERY, RPT_CANDIDATE, RPT_OUTLIER} state;
|
||||||
|
enum {RPT_NORMAL, RPT_PREFER, RPT_NOSELECT} sel_option;
|
||||||
|
|
||||||
|
int reachability;
|
||||||
unsigned long latest_meas_ago; /* seconds */
|
unsigned long latest_meas_ago; /* seconds */
|
||||||
double orig_latest_meas; /* seconds */
|
double orig_latest_meas; /* seconds */
|
||||||
double latest_meas; /* seconds */
|
double latest_meas; /* seconds */
|
||||||
@@ -46,20 +48,24 @@ typedef struct {
|
|||||||
} RPT_SourceReport ;
|
} RPT_SourceReport ;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
unsigned long ref_id;
|
uint32_t ref_id;
|
||||||
IPAddr ip_addr;
|
IPAddr ip_addr;
|
||||||
unsigned long stratum;
|
unsigned long stratum;
|
||||||
|
unsigned long leap_status;
|
||||||
struct timeval ref_time;
|
struct timeval ref_time;
|
||||||
double current_correction;
|
double current_correction;
|
||||||
|
double last_offset;
|
||||||
|
double rms_offset;
|
||||||
double freq_ppm;
|
double freq_ppm;
|
||||||
double resid_freq_ppm;
|
double resid_freq_ppm;
|
||||||
double skew_ppm;
|
double skew_ppm;
|
||||||
double root_delay;
|
double root_delay;
|
||||||
double root_dispersion;
|
double root_dispersion;
|
||||||
|
double last_update_interval;
|
||||||
} RPT_TrackingReport;
|
} RPT_TrackingReport;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
unsigned long ref_id;
|
uint32_t ref_id;
|
||||||
IPAddr ip_addr;
|
IPAddr ip_addr;
|
||||||
unsigned long n_samples;
|
unsigned long n_samples;
|
||||||
unsigned long n_runs;
|
unsigned long n_runs;
|
||||||
@@ -113,6 +119,7 @@ typedef struct {
|
|||||||
int offline;
|
int offline;
|
||||||
int burst_online;
|
int burst_online;
|
||||||
int burst_offline;
|
int burst_offline;
|
||||||
|
int unresolved;
|
||||||
} RPT_ActivityReport;
|
} RPT_ActivityReport;
|
||||||
|
|
||||||
#endif /* GOT_REPORTS_H */
|
#endif /* GOT_REPORTS_H */
|
||||||
|
|||||||
5
rtc.c
5
rtc.c
@@ -23,6 +23,8 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
#include "sysincl.h"
|
#include "sysincl.h"
|
||||||
|
|
||||||
#include "rtc.h"
|
#include "rtc.h"
|
||||||
@@ -106,9 +108,6 @@ RTC_Initialise(void)
|
|||||||
} else {
|
} else {
|
||||||
driver_initialised = 0;
|
driver_initialised = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|||||||
151
rtc_linux.c
151
rtc_linux.c
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
* Copyright (C) Richard P. Curnow 1997-2003
|
* Copyright (C) Richard P. Curnow 1997-2003
|
||||||
|
* Copyright (C) Miroslav Lichvar 2012
|
||||||
*
|
*
|
||||||
* 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
|
||||||
@@ -26,25 +27,11 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if defined LINUX
|
#include "config.h"
|
||||||
|
|
||||||
#ifdef sparc
|
#include "sysincl.h"
|
||||||
#define __KERNEL__
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <linux/rtc.h>
|
||||||
#include <stdlib.h>
|
|
||||||
#include <math.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include <sys/time.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
|
|
||||||
#include <sys/ioctl.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <assert.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
#include "sched.h"
|
#include "sched.h"
|
||||||
@@ -54,22 +41,9 @@
|
|||||||
#include "regress.h"
|
#include "regress.h"
|
||||||
#include "rtc.h"
|
#include "rtc.h"
|
||||||
#include "rtc_linux.h"
|
#include "rtc_linux.h"
|
||||||
#include "io_linux.h"
|
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
|
|
||||||
struct rtc_time {
|
|
||||||
int tm_sec;
|
|
||||||
int tm_min;
|
|
||||||
int tm_hour;
|
|
||||||
int tm_mday;
|
|
||||||
int tm_mon;
|
|
||||||
int tm_year;
|
|
||||||
int tm_wday;
|
|
||||||
int tm_yday;
|
|
||||||
int tm_isdst;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
/* Forward prototypes */
|
/* Forward prototypes */
|
||||||
|
|
||||||
@@ -198,7 +172,6 @@ discard_samples(int new_first)
|
|||||||
memmove(system_times, system_times + new_first, n_to_save * sizeof(struct timeval));
|
memmove(system_times, system_times + new_first, n_to_save * sizeof(struct timeval));
|
||||||
|
|
||||||
n_samples = n_to_save;
|
n_samples = n_to_save;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -226,8 +199,6 @@ accumulate_sample(time_t rtc, struct timeval *sys)
|
|||||||
++n_samples_since_regression;
|
++n_samples_since_regression;
|
||||||
}
|
}
|
||||||
++n_samples;
|
++n_samples;
|
||||||
return;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -244,14 +215,12 @@ run_regression(int new_sample,
|
|||||||
{
|
{
|
||||||
double rtc_rel[MAX_SAMPLES]; /* Relative times on RTC axis */
|
double rtc_rel[MAX_SAMPLES]; /* Relative times on RTC axis */
|
||||||
double offsets[MAX_SAMPLES]; /* How much the RTC is fast of the system clock */
|
double offsets[MAX_SAMPLES]; /* How much the RTC is fast of the system clock */
|
||||||
int i, n;
|
int i;
|
||||||
double est_intercept, est_slope;
|
double est_intercept, est_slope;
|
||||||
int best_new_start;
|
int best_new_start;
|
||||||
|
|
||||||
if (n_samples > 0) {
|
if (n_samples > 0) {
|
||||||
|
|
||||||
n = n_samples - 1;
|
|
||||||
|
|
||||||
for (i=0; i<n_samples; i++) {
|
for (i=0; i<n_samples; i++) {
|
||||||
rtc_rel[i] = rtc_trim[i] + (double)(rtc_sec[i] - rtc_ref);
|
rtc_rel[i] = rtc_trim[i] + (double)(rtc_sec[i] - rtc_ref);
|
||||||
offsets[i] = ((double) (rtc_ref - system_times[i].tv_sec) -
|
offsets[i] = ((double) (rtc_ref - system_times[i].tv_sec) -
|
||||||
@@ -319,6 +288,8 @@ slew_samples
|
|||||||
dfreq, doffset,
|
dfreq, doffset,
|
||||||
old_seconds_fast, 1.0e6 * old_gain_rate,
|
old_seconds_fast, 1.0e6 * old_gain_rate,
|
||||||
coef_seconds_fast, 1.0e6 * coef_gain_rate);
|
coef_seconds_fast, 1.0e6 * coef_gain_rate);
|
||||||
|
#else
|
||||||
|
(void)old_seconds_fast; (void)old_gain_rate;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -479,10 +450,14 @@ write_coefs_to_file(int valid,time_t ref_time,double offset,double rate)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Gain rate is written out in ppm */
|
/* Gain rate is written out in ppm */
|
||||||
fprintf(out, "%1d %ld %.6f %.3f\n",
|
if ((fprintf(out, "%1d %ld %.6f %.3f\n",
|
||||||
valid,ref_time, offset, 1.0e6 * rate);
|
valid,ref_time, offset, 1.0e6 * rate) < 0) |
|
||||||
|
fclose(out)) {
|
||||||
fclose(out);
|
Free(temp_coefs_file_name);
|
||||||
|
LOG(LOGS_WARN, LOGF_RtcLinux, "Could not write to temporary RTC file %s.tmp",
|
||||||
|
coefs_file_name);
|
||||||
|
return RTC_ST_BADFILE;
|
||||||
|
}
|
||||||
|
|
||||||
/* Clone the file attributes from the existing file if there is one. */
|
/* Clone the file attributes from the existing file if there is one. */
|
||||||
|
|
||||||
@@ -517,62 +492,6 @@ write_coefs_to_file(int valid,time_t ref_time,double offset,double rate)
|
|||||||
int
|
int
|
||||||
RTC_Linux_Initialise(void)
|
RTC_Linux_Initialise(void)
|
||||||
{
|
{
|
||||||
int major, minor, patch;
|
|
||||||
|
|
||||||
/* Check whether we can support the real time clock.
|
|
||||||
|
|
||||||
Linux 1.2.x - haven't checked yet
|
|
||||||
|
|
||||||
Linux 1.3.x - don't know, haven't got a system to look at
|
|
||||||
|
|
||||||
Linux 2.0.x - For x<=31, using any variant of the adjtimex() call
|
|
||||||
sets the kernel into a mode where the RTC was updated every 11
|
|
||||||
minutes. The only way to escape this is to use settimeofday().
|
|
||||||
Since we need to have sole control over the RTC to be able to
|
|
||||||
measure its drift rate, and there is no 'notify' callback to warn
|
|
||||||
you that the kernel is going to do this, I can't see a way to
|
|
||||||
support this.
|
|
||||||
|
|
||||||
Linux 2.0.x - For x>=32 the adjtimex()/RTC behaviour was
|
|
||||||
modified, so that as long as the STA_UNSYNC flag is set the RTC
|
|
||||||
is left alone. This is the mode we exploit here, so that the RTC
|
|
||||||
continues to go its own sweet way, unless we make updates to it
|
|
||||||
from this module.
|
|
||||||
|
|
||||||
Linux 2.1.x - don't know, haven't got a system to look at.
|
|
||||||
|
|
||||||
Linux 2.2.x, 2.3.x and 2.4.x are believed to be OK for all
|
|
||||||
patch levels
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
SYS_Linux_GetKernelVersion(&major, &minor, &patch);
|
|
||||||
|
|
||||||
/* Obviously this test can get more elaborate when we know about
|
|
||||||
more system types. */
|
|
||||||
if (major != 2) {
|
|
||||||
return 0;
|
|
||||||
} else {
|
|
||||||
switch (minor) {
|
|
||||||
case 0:
|
|
||||||
if (patch <= 31) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
return 0;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
case 3:
|
|
||||||
case 4:
|
|
||||||
case 5:
|
|
||||||
case 6:
|
|
||||||
case 7:
|
|
||||||
case 8:
|
|
||||||
break; /* OK for all patch levels */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Setup details depending on configuration options */
|
/* Setup details depending on configuration options */
|
||||||
setup_config();
|
setup_config();
|
||||||
|
|
||||||
@@ -681,6 +600,9 @@ set_rtc(time_t new_rtc_time)
|
|||||||
rtc_raw.tm_mday = rtc_tm.tm_mday;
|
rtc_raw.tm_mday = rtc_tm.tm_mday;
|
||||||
rtc_raw.tm_mon = rtc_tm.tm_mon;
|
rtc_raw.tm_mon = rtc_tm.tm_mon;
|
||||||
rtc_raw.tm_year = rtc_tm.tm_year;
|
rtc_raw.tm_year = rtc_tm.tm_year;
|
||||||
|
rtc_raw.tm_wday = rtc_tm.tm_wday;
|
||||||
|
rtc_raw.tm_yday = rtc_tm.tm_yday;
|
||||||
|
rtc_raw.tm_isdst = rtc_tm.tm_isdst;
|
||||||
|
|
||||||
status = ioctl(fd, RTC_SET_TIME, &rtc_raw);
|
status = ioctl(fd, RTC_SET_TIME, &rtc_raw);
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
@@ -727,7 +649,7 @@ handle_initial_trim(void)
|
|||||||
sys_error_now = rtc_error_now - coef_seconds_fast;
|
sys_error_now = rtc_error_now - coef_seconds_fast;
|
||||||
|
|
||||||
LOG(LOGS_INFO, LOGF_RtcLinux, "System trim from RTC = %f", sys_error_now);
|
LOG(LOGS_INFO, LOGF_RtcLinux, "System trim from RTC = %f", sys_error_now);
|
||||||
LCL_AccumulateOffset(sys_error_now);
|
LCL_AccumulateOffset(sys_error_now, 0.0);
|
||||||
} else {
|
} else {
|
||||||
LOG(LOGS_WARN, LOGF_RtcLinux, "No valid file coefficients, cannot trim system time");
|
LOG(LOGS_WARN, LOGF_RtcLinux, "No valid file coefficients, cannot trim system time");
|
||||||
}
|
}
|
||||||
@@ -737,8 +659,6 @@ handle_initial_trim(void)
|
|||||||
(after_init_hook)(after_init_hook_arg);
|
(after_init_hook)(after_init_hook_arg);
|
||||||
|
|
||||||
operating_mode = OM_NORMAL;
|
operating_mode = OM_NORMAL;
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -758,6 +678,7 @@ handle_relock_after_trim(void)
|
|||||||
LOG(LOGS_WARN, LOGF_RtcLinux, "Could not do regression after trim");
|
LOG(LOGS_WARN, LOGF_RtcLinux, "Could not do regression after trim");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
coefs_valid = 0;
|
||||||
n_samples = 0;
|
n_samples = 0;
|
||||||
n_samples_since_regression = 0;
|
n_samples_since_regression = 0;
|
||||||
operating_mode = OM_NORMAL;
|
operating_mode = OM_NORMAL;
|
||||||
@@ -846,13 +767,13 @@ read_from_device(void *any)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((data & RTC_UIE) == RTC_UIE) {
|
if ((data & RTC_UF) == RTC_UF) {
|
||||||
/* Update interrupt detected */
|
/* Update interrupt detected */
|
||||||
|
|
||||||
/* Read RTC time, sandwiched between two polls of the system clock
|
/* Read RTC time, sandwiched between two polls of the system clock
|
||||||
so we can bound any error. */
|
so we can bound any error. */
|
||||||
|
|
||||||
SCH_GetFileReadyTime(&sys_time, NULL);
|
SCH_GetLastEventTime(&sys_time, NULL, NULL);
|
||||||
|
|
||||||
status = ioctl(fd, RTC_RD_TIME, &rtc_raw);
|
status = ioctl(fd, RTC_RD_TIME, &rtc_raw);
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
@@ -997,7 +918,7 @@ RTC_Linux_TimePreInit(void)
|
|||||||
time_t rtc_t, estimated_correct_rtc_t;
|
time_t rtc_t, estimated_correct_rtc_t;
|
||||||
long interval;
|
long interval;
|
||||||
double accumulated_error = 0.0;
|
double accumulated_error = 0.0;
|
||||||
struct timeval new_sys_time;
|
struct timeval new_sys_time, old_sys_time;
|
||||||
|
|
||||||
coefs_file_name = CNF_GetRtcFile();
|
coefs_file_name = CNF_GetRtcFile();
|
||||||
|
|
||||||
@@ -1032,8 +953,6 @@ RTC_Linux_TimePreInit(void)
|
|||||||
accumulated_error = file_ref_offset + (double)(interval) * 1.0e-6 * file_rate_ppm;
|
accumulated_error = file_ref_offset + (double)(interval) * 1.0e-6 * file_rate_ppm;
|
||||||
|
|
||||||
/* Correct time */
|
/* Correct time */
|
||||||
LOG(LOGS_INFO, LOGF_RtcLinux, "Set system time, error in RTC = %f",
|
|
||||||
accumulated_error);
|
|
||||||
estimated_correct_rtc_t = rtc_t - (long)(0.5 + accumulated_error);
|
estimated_correct_rtc_t = rtc_t - (long)(0.5 + accumulated_error);
|
||||||
} else {
|
} else {
|
||||||
estimated_correct_rtc_t = rtc_t - (long)(0.5 + accumulated_error);
|
estimated_correct_rtc_t = rtc_t - (long)(0.5 + accumulated_error);
|
||||||
@@ -1042,9 +961,18 @@ RTC_Linux_TimePreInit(void)
|
|||||||
new_sys_time.tv_sec = estimated_correct_rtc_t;
|
new_sys_time.tv_sec = estimated_correct_rtc_t;
|
||||||
new_sys_time.tv_usec = 0;
|
new_sys_time.tv_usec = 0;
|
||||||
|
|
||||||
/* Tough luck if this fails */
|
/* Set system time only if the step is larger than 1 second */
|
||||||
if (settimeofday(&new_sys_time, NULL) < 0) {
|
if (!(gettimeofday(&old_sys_time, NULL) < 0) &&
|
||||||
LOG(LOGS_WARN, LOGF_RtcLinux, "Could not settimeofday");
|
(old_sys_time.tv_sec - new_sys_time.tv_sec > 1 ||
|
||||||
|
old_sys_time.tv_sec - new_sys_time.tv_sec < -1)) {
|
||||||
|
|
||||||
|
LOG(LOGS_INFO, LOGF_RtcLinux, "Set system time, error in RTC = %f",
|
||||||
|
accumulated_error);
|
||||||
|
|
||||||
|
/* Tough luck if this fails */
|
||||||
|
if (settimeofday(&new_sys_time, NULL) < 0) {
|
||||||
|
LOG(LOGS_WARN, LOGF_RtcLinux, "Could not settimeofday");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LOG(LOGS_WARN, LOGF_RtcLinux, "Could not convert RTC reading to seconds since 1/1/1970");
|
LOG(LOGS_WARN, LOGF_RtcLinux, "Could not convert RTC reading to seconds since 1/1/1970");
|
||||||
@@ -1107,6 +1035,11 @@ RTC_Linux_Trim(void)
|
|||||||
n_samples = 0;
|
n_samples = 0;
|
||||||
operating_mode = OM_AFTERTRIM;
|
operating_mode = OM_AFTERTRIM;
|
||||||
|
|
||||||
|
/* Estimate the offset in case writertc is called or chronyd
|
||||||
|
is terminated during rapid sampling */
|
||||||
|
coef_seconds_fast = -now.tv_usec / 1e6 + 0.5;
|
||||||
|
coef_ref_time = now.tv_sec;
|
||||||
|
|
||||||
/* And start rapid sampling, interrupts on now */
|
/* And start rapid sampling, interrupts on now */
|
||||||
if (timeout_running) {
|
if (timeout_running) {
|
||||||
SCH_RemoveTimeout(timeout_id);
|
SCH_RemoveTimeout(timeout_id);
|
||||||
@@ -1118,7 +1051,3 @@ RTC_Linux_Trim(void)
|
|||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
|
||||||
|
|
||||||
#endif /* defined LINUX */
|
|
||||||
|
|||||||
@@ -28,8 +28,6 @@
|
|||||||
|
|
||||||
#include "reports.h"
|
#include "reports.h"
|
||||||
|
|
||||||
#if defined LINUX
|
|
||||||
|
|
||||||
extern int RTC_Linux_Initialise(void);
|
extern int RTC_Linux_Initialise(void);
|
||||||
extern void RTC_Linux_Finalise(void);
|
extern void RTC_Linux_Finalise(void);
|
||||||
extern void RTC_Linux_TimePreInit(void);
|
extern void RTC_Linux_TimePreInit(void);
|
||||||
@@ -44,6 +42,4 @@ extern int RTC_Linux_Trim(void);
|
|||||||
|
|
||||||
extern void RTC_Linux_CycleLogFile(void);
|
extern void RTC_Linux_CycleLogFile(void);
|
||||||
|
|
||||||
#endif /* defined LINUX */
|
|
||||||
|
|
||||||
#endif /* _GOT_RTC_LINUX_H */
|
#endif /* _GOT_RTC_LINUX_H */
|
||||||
|
|||||||
153
sched.c
153
sched.c
@@ -26,6 +26,8 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
#include "sysincl.h"
|
#include "sysincl.h"
|
||||||
|
|
||||||
#include "sched.h"
|
#include "sched.h"
|
||||||
@@ -68,9 +70,9 @@ typedef struct {
|
|||||||
|
|
||||||
static FileHandlerEntry file_handlers[FD_SET_SIZE];
|
static FileHandlerEntry file_handlers[FD_SET_SIZE];
|
||||||
|
|
||||||
/* Last timestamp when a file descriptor became readable */
|
/* Timestamp when last select() returned */
|
||||||
static struct timeval last_fdready;
|
static struct timeval last_select_ts, last_select_ts_raw;
|
||||||
static double last_fdready_err;
|
static double last_select_ts_err;
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
@@ -129,8 +131,6 @@ handle_slew(struct timeval *raw,
|
|||||||
void
|
void
|
||||||
SCH_Initialise(void)
|
SCH_Initialise(void)
|
||||||
{
|
{
|
||||||
struct timeval tv;
|
|
||||||
|
|
||||||
FD_ZERO(&read_fds);
|
FD_ZERO(&read_fds);
|
||||||
n_read_fds = 0;
|
n_read_fds = 0;
|
||||||
|
|
||||||
@@ -144,12 +144,12 @@ SCH_Initialise(void)
|
|||||||
|
|
||||||
LCL_AddParameterChangeHandler(handle_slew, NULL);
|
LCL_AddParameterChangeHandler(handle_slew, NULL);
|
||||||
|
|
||||||
LCL_ReadRawTime(&tv);
|
LCL_ReadRawTime(&last_select_ts_raw);
|
||||||
srandom(tv.tv_sec * tv.tv_usec);
|
last_select_ts = last_select_ts_raw;
|
||||||
|
|
||||||
|
srandom(last_select_ts.tv_sec << 16 ^ last_select_ts.tv_usec);
|
||||||
|
|
||||||
initialised = 1;
|
initialised = 1;
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -158,7 +158,6 @@ SCH_Initialise(void)
|
|||||||
void
|
void
|
||||||
SCH_Finalise(void) {
|
SCH_Finalise(void) {
|
||||||
initialised = 0;
|
initialised = 0;
|
||||||
return; /* Nothing to do for now */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -185,8 +184,6 @@ SCH_AddInputFileHandler
|
|||||||
if ((fd + 1) > one_highest_fd) {
|
if ((fd + 1) > one_highest_fd) {
|
||||||
one_highest_fd = fd + 1;
|
one_highest_fd = fd + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -217,19 +214,20 @@ SCH_RemoveInputFileHandler(int fd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
one_highest_fd = fd_to_check;
|
one_highest_fd = fd_to_check;
|
||||||
|
|
||||||
return;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
void
|
void
|
||||||
SCH_GetFileReadyTime(struct timeval *tv, double *err)
|
SCH_GetLastEventTime(struct timeval *cooked, double *err, struct timeval *raw)
|
||||||
{
|
{
|
||||||
*tv = last_fdready;
|
if (cooked) {
|
||||||
if (err)
|
*cooked = last_select_ts;
|
||||||
*err = last_fdready_err;
|
if (err)
|
||||||
|
*err = last_select_ts_err;
|
||||||
|
}
|
||||||
|
if (raw)
|
||||||
|
*raw = last_select_ts_raw;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -263,7 +261,6 @@ release_tqe(TimerQueueEntry *node)
|
|||||||
{
|
{
|
||||||
node->next = tqe_free_list;
|
node->next = tqe_free_list;
|
||||||
tqe_free_list = node;
|
tqe_free_list = node;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -316,6 +313,7 @@ SCH_AddTimeoutByDelay(double delay, SCH_TimeoutHandler handler, SCH_ArbitraryArg
|
|||||||
struct timeval now, then;
|
struct timeval now, then;
|
||||||
|
|
||||||
assert(initialised);
|
assert(initialised);
|
||||||
|
assert(delay >= 0.0);
|
||||||
|
|
||||||
LCL_ReadRawTime(&now);
|
LCL_ReadRawTime(&now);
|
||||||
UTI_AddDoubleToTimeval(&now, delay, &then);
|
UTI_AddDoubleToTimeval(&now, delay, &then);
|
||||||
@@ -337,6 +335,7 @@ SCH_AddTimeoutInClass(double min_delay, double separation, double randomness,
|
|||||||
double new_min_delay;
|
double new_min_delay;
|
||||||
|
|
||||||
assert(initialised);
|
assert(initialised);
|
||||||
|
assert(min_delay >= 0.0);
|
||||||
assert(class < SCH_NumberOfClasses);
|
assert(class < SCH_NumberOfClasses);
|
||||||
|
|
||||||
if (randomness > 0.0) {
|
if (randomness > 0.0) {
|
||||||
@@ -426,18 +425,26 @@ SCH_RemoveTimeout(SCH_TimeoutID id)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
/* The current time (now) has to be passed in from the
|
/* Try to dispatch any timeouts that have already gone by, and
|
||||||
caller to avoid race conditions */
|
keep going until all are done. (The earlier ones may take so
|
||||||
|
long to do that the later ones come around by the time they are
|
||||||
|
completed). */
|
||||||
|
|
||||||
static int
|
static void
|
||||||
dispatch_timeouts(struct timeval *now) {
|
dispatch_timeouts(struct timeval *now) {
|
||||||
TimerQueueEntry *ptr;
|
TimerQueueEntry *ptr;
|
||||||
SCH_TimeoutHandler handler;
|
SCH_TimeoutHandler handler;
|
||||||
SCH_ArbitraryArgument arg;
|
SCH_ArbitraryArgument arg;
|
||||||
int n_done = 0;
|
int n_done = 0, n_entries_on_start = n_timer_queue_entries;
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
LCL_ReadRawTime(now);
|
||||||
|
|
||||||
|
if (!(n_timer_queue_entries > 0 &&
|
||||||
|
UTI_CompareTimevals(now, &(timer_queue.next->tv)) >= 0)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if ((n_timer_queue_entries > 0) &&
|
|
||||||
(UTI_CompareTimevals(now, &(timer_queue.next->tv)) >= 0)) {
|
|
||||||
ptr = timer_queue.next;
|
ptr = timer_queue.next;
|
||||||
|
|
||||||
last_class_dispatch[ptr->class] = *now;
|
last_class_dispatch[ptr->class] = *now;
|
||||||
@@ -452,10 +459,17 @@ dispatch_timeouts(struct timeval *now) {
|
|||||||
|
|
||||||
/* Increment count of timeouts handled */
|
/* Increment count of timeouts handled */
|
||||||
++n_done;
|
++n_done;
|
||||||
|
|
||||||
|
/* If more timeouts were handled than there were in the timer queue on
|
||||||
|
start and there are now, assume some code is scheduling timeouts with
|
||||||
|
negative delays and abort. Make the actual limit higher in case the
|
||||||
|
machine is temporarily overloaded and dispatching the handlers takes
|
||||||
|
more time than was delay of a scheduled timeout. */
|
||||||
|
if (n_done > n_timer_queue_entries * 4 &&
|
||||||
|
n_done > n_entries_on_start * 4) {
|
||||||
|
LOG_FATAL(LOGF_Scheduler, "Possible infinite loop in scheduling");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return n_done;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -493,12 +507,11 @@ handle_slew(struct timeval *raw,
|
|||||||
void *anything)
|
void *anything)
|
||||||
{
|
{
|
||||||
TimerQueueEntry *ptr;
|
TimerQueueEntry *ptr;
|
||||||
|
double delta;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (is_step_change) {
|
if (is_step_change) {
|
||||||
/* We're not interested in anything else - it won't affect the
|
/* If a step change occurs, just shift all raw time stamps by the offset */
|
||||||
functionality of timer event dispatching. If a step change
|
|
||||||
occurs, just shift all the timeouts by the offset */
|
|
||||||
|
|
||||||
for (ptr = timer_queue.next; ptr != &timer_queue; ptr = ptr->next) {
|
for (ptr = timer_queue.next; ptr != &timer_queue; ptr = ptr->next) {
|
||||||
UTI_AddDoubleToTimeval(&ptr->tv, -doffset, &ptr->tv);
|
UTI_AddDoubleToTimeval(&ptr->tv, -doffset, &ptr->tv);
|
||||||
@@ -507,7 +520,39 @@ handle_slew(struct timeval *raw,
|
|||||||
for (i = 0; i < SCH_NumberOfClasses; i++) {
|
for (i = 0; i < SCH_NumberOfClasses; i++) {
|
||||||
UTI_AddDoubleToTimeval(&last_class_dispatch[i], -doffset, &last_class_dispatch[i]);
|
UTI_AddDoubleToTimeval(&last_class_dispatch[i], -doffset, &last_class_dispatch[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UTI_AddDoubleToTimeval(&last_select_ts_raw, -doffset, &last_select_ts_raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UTI_AdjustTimeval(&last_select_ts, cooked, &last_select_ts, &delta, dfreq, doffset);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
/* Try to handle unexpected backward time jump */
|
||||||
|
|
||||||
|
static void
|
||||||
|
recover_backjump(struct timeval *raw, struct timeval *cooked, int timeout)
|
||||||
|
{
|
||||||
|
double diff, err;
|
||||||
|
|
||||||
|
UTI_DiffTimevalsToDouble(&diff, &last_select_ts_raw, raw);
|
||||||
|
|
||||||
|
if (n_timer_queue_entries > 0) {
|
||||||
|
UTI_DiffTimevalsToDouble(&err, &(timer_queue.next->tv), &last_select_ts_raw);
|
||||||
|
} else {
|
||||||
|
err = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
diff += err;
|
||||||
|
|
||||||
|
if (timeout) {
|
||||||
|
err = 1.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG(LOGS_WARN, LOGF_Scheduler, "Backward time jump detected! (correction %.1f +- %.1f seconds)", diff, err);
|
||||||
|
|
||||||
|
LCL_NotifyExternalTimeStep(raw, cooked, diff, err);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -516,9 +561,10 @@ void
|
|||||||
SCH_MainLoop(void)
|
SCH_MainLoop(void)
|
||||||
{
|
{
|
||||||
fd_set rd;
|
fd_set rd;
|
||||||
int status;
|
int status, errsv;
|
||||||
struct timeval tv, *ptv;
|
struct timeval tv, *ptv;
|
||||||
struct timeval now;
|
struct timeval now, cooked;
|
||||||
|
double err;
|
||||||
|
|
||||||
assert(initialised);
|
assert(initialised);
|
||||||
|
|
||||||
@@ -527,20 +573,15 @@ SCH_MainLoop(void)
|
|||||||
/* Copy current set of read file descriptors */
|
/* Copy current set of read file descriptors */
|
||||||
memcpy((void *) &rd, (void *) &read_fds, sizeof(fd_set));
|
memcpy((void *) &rd, (void *) &read_fds, sizeof(fd_set));
|
||||||
|
|
||||||
/* Try to dispatch any timeouts that have already gone by, and
|
/* Dispatch timeouts and fill now with current raw time */
|
||||||
keep going until all are done. (The earlier ones may take so
|
dispatch_timeouts(&now);
|
||||||
long to do that the later ones come around by the time they are
|
|
||||||
completed). */
|
|
||||||
|
|
||||||
do {
|
|
||||||
LCL_ReadRawTime(&now);
|
|
||||||
} while (dispatch_timeouts(&now) > 0);
|
|
||||||
|
|
||||||
/* Check whether there is a timeout and set it up */
|
/* Check whether there is a timeout and set it up */
|
||||||
if (n_timer_queue_entries > 0) {
|
if (n_timer_queue_entries > 0) {
|
||||||
|
|
||||||
UTI_DiffTimevals(&tv, &(timer_queue.next->tv), &now);
|
UTI_DiffTimevals(&tv, &(timer_queue.next->tv), &now);
|
||||||
ptv = &tv;
|
ptv = &tv;
|
||||||
|
assert(tv.tv_sec > 0 || tv.tv_usec > 0);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
ptv = NULL;
|
ptv = NULL;
|
||||||
@@ -548,24 +589,33 @@ SCH_MainLoop(void)
|
|||||||
|
|
||||||
/* if there are no file descriptors being waited on and no
|
/* if there are no file descriptors being waited on and no
|
||||||
timeout set, this is clearly ridiculous, so stop the run */
|
timeout set, this is clearly ridiculous, so stop the run */
|
||||||
|
assert(ptv || n_read_fds);
|
||||||
if (!ptv && (n_read_fds == 0)) {
|
|
||||||
LOG_FATAL(LOGF_Scheduler, "No descriptors or timeout to wait for");
|
|
||||||
}
|
|
||||||
|
|
||||||
status = select(one_highest_fd, &rd, NULL, NULL, ptv);
|
status = select(one_highest_fd, &rd, NULL, NULL, ptv);
|
||||||
|
errsv = errno;
|
||||||
|
|
||||||
|
LCL_ReadRawTime(&now);
|
||||||
|
LCL_CookTime(&now, &cooked, &err);
|
||||||
|
|
||||||
|
/* Check if time didn't jump backwards */
|
||||||
|
if (last_select_ts_raw.tv_sec > now.tv_sec + 1) {
|
||||||
|
recover_backjump(&now, &cooked, status == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
last_select_ts_raw = now;
|
||||||
|
last_select_ts = cooked;
|
||||||
|
last_select_ts_err = err;
|
||||||
|
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
assert(need_to_exit);
|
if (!need_to_exit && errsv != EINTR) {
|
||||||
|
LOG_FATAL(LOGF_Scheduler, "select() failed : %s", strerror(errsv));
|
||||||
|
}
|
||||||
} else if (status > 0) {
|
} else if (status > 0) {
|
||||||
/* A file descriptor is ready to read */
|
/* A file descriptor is ready to read */
|
||||||
|
|
||||||
LCL_ReadCookedTime(&last_fdready, &last_fdready_err);
|
|
||||||
dispatch_filehandlers(status, &rd);
|
dispatch_filehandlers(status, &rd);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
assert(status == 0);
|
|
||||||
|
|
||||||
/* No descriptors readable, timeout must have elapsed.
|
/* No descriptors readable, timeout must have elapsed.
|
||||||
Therefore, tv must be non-null */
|
Therefore, tv must be non-null */
|
||||||
assert(ptv);
|
assert(ptv);
|
||||||
@@ -576,9 +626,6 @@ SCH_MainLoop(void)
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|||||||
5
sched.h
5
sched.h
@@ -58,9 +58,8 @@ extern void SCH_AddInputFileHandler
|
|||||||
);
|
);
|
||||||
extern void SCH_RemoveInputFileHandler(int fd);
|
extern void SCH_RemoveInputFileHandler(int fd);
|
||||||
|
|
||||||
/* Get the time (cooked) when file descriptor became ready, intended for use
|
/* Get the time stamp taken after a file descriptor became ready or a timeout expired */
|
||||||
in file handlers */
|
extern void SCH_GetLastEventTime(struct timeval *cooked, double *err, struct timeval *raw);
|
||||||
extern void SCH_GetFileReadyTime(struct timeval *tv, double *err);
|
|
||||||
|
|
||||||
/* This queues a timeout to elapse at a given (raw) local time */
|
/* This queues a timeout to elapse at a given (raw) local time */
|
||||||
extern SCH_TimeoutID SCH_AddTimeout(struct timeval *tv, SCH_TimeoutHandler, SCH_ArbitraryArgument);
|
extern SCH_TimeoutID SCH_AddTimeout(struct timeval *tv, SCH_TimeoutHandler, SCH_ArbitraryArgument);
|
||||||
|
|||||||
218
sources.c
218
sources.c
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
* Copyright (C) Richard P. Curnow 1997-2003
|
* Copyright (C) Richard P. Curnow 1997-2003
|
||||||
* Copyright (C) Miroslav Lichvar 2011
|
* Copyright (C) Miroslav Lichvar 2011-2013
|
||||||
*
|
*
|
||||||
* 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
|
||||||
@@ -28,6 +28,8 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
#include "sysincl.h"
|
#include "sysincl.h"
|
||||||
|
|
||||||
#include "sources.h"
|
#include "sources.h"
|
||||||
@@ -42,6 +44,7 @@
|
|||||||
#include "reports.h"
|
#include "reports.h"
|
||||||
#include "nameserv.h"
|
#include "nameserv.h"
|
||||||
#include "mkdirpp.h"
|
#include "mkdirpp.h"
|
||||||
|
#include "sched.h"
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
/* Flag indicating that we are initialised */
|
/* Flag indicating that we are initialised */
|
||||||
@@ -53,10 +56,7 @@ struct SelectInfo {
|
|||||||
int stratum;
|
int stratum;
|
||||||
int select_ok;
|
int select_ok;
|
||||||
double variance;
|
double variance;
|
||||||
double root_delay;
|
|
||||||
double root_dispersion;
|
|
||||||
double root_distance;
|
double root_distance;
|
||||||
double best_offset;
|
|
||||||
double lo_limit;
|
double lo_limit;
|
||||||
double hi_limit;
|
double hi_limit;
|
||||||
};
|
};
|
||||||
@@ -82,8 +82,8 @@ struct SRC_Instance_Record {
|
|||||||
SST_Stats stats;
|
SST_Stats stats;
|
||||||
NTP_Leap leap_status; /* Leap status */
|
NTP_Leap leap_status; /* Leap status */
|
||||||
int index; /* Index back into the array of source */
|
int index; /* Index back into the array of source */
|
||||||
unsigned long ref_id; /* The reference ID of this source
|
uint32_t ref_id; /* The reference ID of this source
|
||||||
(i.e. its IP address, NOT the
|
(i.e. from its IP address, NOT the
|
||||||
reference _it_ is sync'd to) */
|
reference _it_ is sync'd to) */
|
||||||
IPAddr *ip_addr; /* Its IP address if NTP source */
|
IPAddr *ip_addr; /* Its IP address if NTP source */
|
||||||
|
|
||||||
@@ -93,6 +93,12 @@ struct SRC_Instance_Record {
|
|||||||
/* Reachability register */
|
/* Reachability register */
|
||||||
int reachability;
|
int reachability;
|
||||||
|
|
||||||
|
/* Flag indicating that only few samples were accumulated so far */
|
||||||
|
int beginning;
|
||||||
|
|
||||||
|
/* Updates left before allowing combining */
|
||||||
|
int outlier;
|
||||||
|
|
||||||
/* Flag indicating the status of the source */
|
/* Flag indicating the status of the source */
|
||||||
SRC_Status status;
|
SRC_Status status;
|
||||||
|
|
||||||
@@ -135,8 +141,12 @@ static int selected_source_index; /* Which source index is currently
|
|||||||
/* Score needed to replace the currently selected source */
|
/* Score needed to replace the currently selected source */
|
||||||
#define SCORE_LIMIT 10.0
|
#define SCORE_LIMIT 10.0
|
||||||
|
|
||||||
|
/* Number of updates needed to reset the outlier status */
|
||||||
|
#define OUTLIER_PENALTY 32
|
||||||
|
|
||||||
static double reselect_distance;
|
static double reselect_distance;
|
||||||
static double stratum_weight;
|
static double stratum_weight;
|
||||||
|
static double combine_limit;
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
/* Forward prototype */
|
/* Forward prototype */
|
||||||
@@ -159,12 +169,11 @@ void SRC_Initialise(void) {
|
|||||||
selected_source_index = INVALID_SOURCE;
|
selected_source_index = INVALID_SOURCE;
|
||||||
reselect_distance = CNF_GetReselectDistance();
|
reselect_distance = CNF_GetReselectDistance();
|
||||||
stratum_weight = CNF_GetStratumWeight();
|
stratum_weight = CNF_GetStratumWeight();
|
||||||
|
combine_limit = CNF_GetCombineLimit();
|
||||||
initialised = 1;
|
initialised = 1;
|
||||||
|
|
||||||
LCL_AddParameterChangeHandler(slew_sources, NULL);
|
LCL_AddParameterChangeHandler(slew_sources, NULL);
|
||||||
LCL_AddDispersionNotifyHandler(add_dispersion, NULL);
|
LCL_AddDispersionNotifyHandler(add_dispersion, NULL);
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -174,14 +183,13 @@ void SRC_Finalise(void)
|
|||||||
LCL_RemoveParameterChangeHandler(slew_sources, NULL);
|
LCL_RemoveParameterChangeHandler(slew_sources, NULL);
|
||||||
LCL_RemoveDispersionNotifyHandler(add_dispersion, NULL);
|
LCL_RemoveDispersionNotifyHandler(add_dispersion, NULL);
|
||||||
initialised = 0;
|
initialised = 0;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
/* Function to create a new instance. This would be called by one of
|
/* Function to create a new instance. This would be called by one of
|
||||||
the individual source-type instance creation routines. */
|
the individual source-type instance creation routines. */
|
||||||
|
|
||||||
SRC_Instance SRC_CreateNewInstance(unsigned long ref_id, SRC_Type type, SRC_SelectOption sel_option, IPAddr *addr)
|
SRC_Instance SRC_CreateNewInstance(uint32_t ref_id, SRC_Type type, SRC_SelectOption sel_option, IPAddr *addr)
|
||||||
{
|
{
|
||||||
SRC_Instance result;
|
SRC_Instance result;
|
||||||
|
|
||||||
@@ -211,6 +219,8 @@ SRC_Instance SRC_CreateNewInstance(unsigned long ref_id, SRC_Type type, SRC_Sele
|
|||||||
result->ip_addr = addr;
|
result->ip_addr = addr;
|
||||||
result->selectable = 0;
|
result->selectable = 0;
|
||||||
result->reachability = 0;
|
result->reachability = 0;
|
||||||
|
result->beginning = 1;
|
||||||
|
result->outlier = 0;
|
||||||
result->status = SRC_BAD_STATS;
|
result->status = SRC_BAD_STATS;
|
||||||
result->type = type;
|
result->type = type;
|
||||||
result->sel_score = 1.0;
|
result->sel_score = 1.0;
|
||||||
@@ -266,7 +276,6 @@ void SRC_GetFrequencyRange(SRC_Instance instance, double *lo, double *hi)
|
|||||||
assert(initialised);
|
assert(initialised);
|
||||||
|
|
||||||
SST_GetFrequencyRange(instance->stats, lo, hi);
|
SST_GetFrequencyRange(instance->stats, lo, hi);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -309,8 +318,6 @@ void SRC_AccumulateSample
|
|||||||
SST_DoNewRegression(inst->stats);
|
SST_DoNewRegression(inst->stats);
|
||||||
/* And redo clock selection */
|
/* And redo clock selection */
|
||||||
SRC_SelectSource(inst->ref_id);
|
SRC_SelectSource(inst->ref_id);
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -357,6 +364,10 @@ SRC_UpdateReachability(SRC_Instance inst, int reachable)
|
|||||||
inst->reachability |= !!reachable;
|
inst->reachability |= !!reachable;
|
||||||
inst->reachability &= ~(-1 << REACH_BITS);
|
inst->reachability &= ~(-1 << REACH_BITS);
|
||||||
|
|
||||||
|
/* The beginning is over when the first sample is at the end of the register */
|
||||||
|
if (inst->reachability & (1 << (REACH_BITS - 1)))
|
||||||
|
inst->beginning = 0;
|
||||||
|
|
||||||
if (!reachable && inst->index == selected_source_index) {
|
if (!reachable && inst->index == selected_source_index) {
|
||||||
/* Try to select a better source */
|
/* Try to select a better source */
|
||||||
SRC_SelectSource(0);
|
SRC_SelectSource(0);
|
||||||
@@ -368,8 +379,12 @@ SRC_UpdateReachability(SRC_Instance inst, int reachable)
|
|||||||
void
|
void
|
||||||
SRC_ResetReachability(SRC_Instance inst)
|
SRC_ResetReachability(SRC_Instance inst)
|
||||||
{
|
{
|
||||||
|
/* This should be disabled until source selection is modified to keep
|
||||||
|
a peer selected even when not reachable */
|
||||||
|
#if 0
|
||||||
inst->reachability = 0;
|
inst->reachability = 0;
|
||||||
SRC_UpdateReachability(inst, 0);
|
SRC_UpdateReachability(inst, 0);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -409,28 +424,106 @@ source_to_string(SRC_Instance inst)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static int
|
||||||
|
combine_sources(int n_sel_sources, struct timeval *ref_time, double *offset,
|
||||||
|
double *offset_sd, double *frequency, double *skew)
|
||||||
|
{
|
||||||
|
struct timeval src_ref_time;
|
||||||
|
double src_offset, src_offset_sd, src_frequency, src_skew;
|
||||||
|
double src_root_delay, src_root_dispersion, elapsed;
|
||||||
|
double offset_weight, sum_offset_weight, sum_offset, sum2_offset_sd;
|
||||||
|
double frequency_weight, sum_frequency_weight, sum_frequency, inv_sum2_skew;
|
||||||
|
int i, index, combined;
|
||||||
|
|
||||||
|
if (n_sel_sources == 1)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
sum_offset_weight = sum_offset = sum2_offset_sd = 0.0;
|
||||||
|
sum_frequency_weight = sum_frequency = inv_sum2_skew = 0.0;
|
||||||
|
|
||||||
|
for (i = combined = 0; i < n_sel_sources; i++) {
|
||||||
|
index = sel_sources[i];
|
||||||
|
SST_GetTrackingData(sources[index]->stats, &src_ref_time,
|
||||||
|
&src_offset, &src_offset_sd,
|
||||||
|
&src_frequency, &src_skew,
|
||||||
|
&src_root_delay, &src_root_dispersion);
|
||||||
|
|
||||||
|
/* Don't include this source if its distance is longer than the distance of
|
||||||
|
the selected source multiplied by the limit, their estimated frequencies
|
||||||
|
are not close, or it was recently marked as outlier */
|
||||||
|
|
||||||
|
if (index != selected_source_index &&
|
||||||
|
(sources[index]->sel_info.root_distance > combine_limit *
|
||||||
|
(reselect_distance + sources[selected_source_index]->sel_info.root_distance) ||
|
||||||
|
fabs(*frequency - src_frequency) >
|
||||||
|
combine_limit * (*skew + src_skew + LCL_GetMaxClockError()))) {
|
||||||
|
sources[index]->outlier = !sources[index]->beginning ? OUTLIER_PENALTY : 1;
|
||||||
|
} else if (sources[index]->outlier) {
|
||||||
|
sources[index]->outlier--;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sources[index]->outlier)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
UTI_DiffTimevalsToDouble(&elapsed, ref_time, &src_ref_time);
|
||||||
|
src_offset += elapsed * src_frequency;
|
||||||
|
offset_weight = 1.0 / sources[index]->sel_info.root_distance;
|
||||||
|
frequency_weight = 1.0 / src_skew;
|
||||||
|
|
||||||
|
#ifdef TRACEON
|
||||||
|
LOG(LOGS_INFO, LOGF_Sources, "combining index=%d oweight=%e offset=%e sd=%e fweight=%e freq=%e skew=%e",
|
||||||
|
index, offset_weight, src_offset, src_offset_sd, frequency_weight, src_frequency, src_skew);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
sum_offset_weight += offset_weight;
|
||||||
|
sum_offset += offset_weight * src_offset;
|
||||||
|
sum2_offset_sd += offset_weight * (src_offset_sd * src_offset_sd +
|
||||||
|
(src_offset - *offset) * (src_offset - *offset));
|
||||||
|
|
||||||
|
sum_frequency_weight += frequency_weight;
|
||||||
|
sum_frequency += frequency_weight * src_frequency;
|
||||||
|
inv_sum2_skew += 1.0 / (src_skew * src_skew);
|
||||||
|
|
||||||
|
combined++;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(combined);
|
||||||
|
*offset = sum_offset / sum_offset_weight;
|
||||||
|
*offset_sd = sqrt(sum2_offset_sd / sum_offset_weight);
|
||||||
|
*frequency = sum_frequency / sum_frequency_weight;
|
||||||
|
*skew = 1.0 / sqrt(inv_sum2_skew);
|
||||||
|
|
||||||
|
#ifdef TRACEON
|
||||||
|
LOG(LOGS_INFO, LOGF_Sources, "combined result offset=%e sd=%e freq=%e skew=%e",
|
||||||
|
*offset, *offset_sd, *frequency, *skew);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return combined;
|
||||||
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
/* This function selects the current reference from amongst the pool
|
/* This function selects the current reference from amongst the pool
|
||||||
of sources we are holding.
|
of sources we are holding.
|
||||||
|
|
||||||
Updates are only made to the local reference if a new source is selected
|
Updates are only made to the local reference if a new source is selected
|
||||||
or match_addr is equal to the selected reference source address */
|
or match_refid is equal to the selected reference source refid */
|
||||||
|
|
||||||
void
|
void
|
||||||
SRC_SelectSource(unsigned long match_addr)
|
SRC_SelectSource(uint32_t match_refid)
|
||||||
{
|
{
|
||||||
int i, j, index, old_selected_index;
|
int i, j, index, old_selected_index;
|
||||||
struct timeval now;
|
struct timeval now, ref_time;
|
||||||
double src_offset, src_offset_sd, src_frequency, src_skew;
|
double src_offset, src_offset_sd, src_frequency, src_skew;
|
||||||
double src_accrued_dispersion;
|
double src_root_delay, src_root_dispersion;
|
||||||
int n_endpoints, j1, j2;
|
int n_endpoints, j1, j2;
|
||||||
double best_lo, best_hi;
|
double best_lo, best_hi;
|
||||||
int depth, best_depth;
|
int depth, best_depth;
|
||||||
int n_sel_sources;
|
int n_sel_sources, combined;
|
||||||
double distance, sel_src_distance;
|
double distance, sel_src_distance;
|
||||||
int stratum, min_stratum;
|
int stratum, min_stratum;
|
||||||
struct SelectInfo *si;
|
struct SelectInfo *si;
|
||||||
double total_root_dispersion;
|
|
||||||
int n_badstats_sources;
|
int n_badstats_sources;
|
||||||
int max_sel_reach, max_badstat_reach;
|
int max_sel_reach, max_badstat_reach;
|
||||||
int max_score_index;
|
int max_score_index;
|
||||||
@@ -449,7 +542,8 @@ SRC_SelectSource(unsigned long match_addr)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
LCL_ReadCookedTime(&now, NULL);
|
/* This is accurate enough and cheaper than calling LCL_ReadCookedTime */
|
||||||
|
SCH_GetLastEventTime(&now, NULL, NULL);
|
||||||
|
|
||||||
/* Step 1 - build intervals about each source */
|
/* Step 1 - build intervals about each source */
|
||||||
n_endpoints = 0;
|
n_endpoints = 0;
|
||||||
@@ -464,20 +558,16 @@ SRC_SelectSource(unsigned long match_addr)
|
|||||||
si = &(sources[i]->sel_info);
|
si = &(sources[i]->sel_info);
|
||||||
SST_GetSelectionData(sources[i]->stats, &now,
|
SST_GetSelectionData(sources[i]->stats, &now,
|
||||||
&(si->stratum),
|
&(si->stratum),
|
||||||
&(si->best_offset),
|
&(si->lo_limit),
|
||||||
&(si->root_delay),
|
&(si->hi_limit),
|
||||||
&(si->root_dispersion),
|
&(si->root_distance),
|
||||||
&(si->variance),
|
&(si->variance),
|
||||||
&(si->select_ok));
|
&(si->select_ok));
|
||||||
|
|
||||||
si->root_distance = si->root_dispersion + 0.5 * fabs(si->root_delay);
|
|
||||||
si->lo_limit = si->best_offset - si->root_distance;
|
|
||||||
si->hi_limit = si->best_offset + si->root_distance;
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
LOG(LOGS_INFO, LOGF_Sources, "%s off=%f dist=%f lo=%f hi=%f",
|
LOG(LOGS_INFO, LOGF_Sources, "%s dist=%f lo=%f hi=%f",
|
||||||
source_to_string(sources[i]),
|
source_to_string(sources[i]),
|
||||||
si->best_offset, si->root_distance,
|
si->root_distance,
|
||||||
si->lo_limit, si->hi_limit);
|
si->lo_limit, si->hi_limit);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -766,6 +856,7 @@ SRC_SelectSource(unsigned long match_addr)
|
|||||||
/* Reset score for non-selectable sources */
|
/* Reset score for non-selectable sources */
|
||||||
if (sources[i]->status != SRC_SELECTABLE) {
|
if (sources[i]->status != SRC_SELECTABLE) {
|
||||||
sources[i]->sel_score = 1.0;
|
sources[i]->sel_score = 1.0;
|
||||||
|
sources[i]->outlier = OUTLIER_PENALTY;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -778,8 +869,8 @@ SRC_SelectSource(unsigned long match_addr)
|
|||||||
|
|
||||||
/* Update score, but only for source pairs where one source
|
/* Update score, but only for source pairs where one source
|
||||||
has a new sample */
|
has a new sample */
|
||||||
if (sources[i]->ref_id == match_addr ||
|
if (sources[i]->ref_id == match_refid ||
|
||||||
sources[selected_source_index]->ref_id == match_addr) {
|
sources[selected_source_index]->ref_id == match_refid) {
|
||||||
|
|
||||||
sources[i]->sel_score *= sel_src_distance / distance;
|
sources[i]->sel_score *= sel_src_distance / distance;
|
||||||
|
|
||||||
@@ -798,7 +889,7 @@ SRC_SelectSource(unsigned long match_addr)
|
|||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
LOG(LOGS_INFO, LOGF_Sources, "select score=%f refid=%lx match_refid=%lx status=%d dist=%f",
|
LOG(LOGS_INFO, LOGF_Sources, "select score=%f refid=%lx match_refid=%lx status=%d dist=%f",
|
||||||
sources[i]->sel_score, sources[i]->ref_id, match_addr, sources[i]->status, distance);
|
sources[i]->sel_score, sources[i]->ref_id, match_refid, sources[i]->status, distance);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (max_score < sources[i]->sel_score) {
|
if (max_score < sources[i]->sel_score) {
|
||||||
@@ -829,38 +920,40 @@ SRC_SelectSource(unsigned long match_addr)
|
|||||||
/* New source has been selected, reset all scores */
|
/* New source has been selected, reset all scores */
|
||||||
for (i=0; i < n_sources; i++) {
|
for (i=0; i < n_sources; i++) {
|
||||||
sources[i]->sel_score = 1.0;
|
sources[i]->sel_score = 1.0;
|
||||||
|
sources[i]->outlier = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sources[selected_source_index]->status = SRC_SYNC;
|
sources[selected_source_index]->status = SRC_SYNC;
|
||||||
|
|
||||||
/* Update local reference only when a new source was selected or a new
|
/* Update local reference only when a new source was selected or a new
|
||||||
sample was received (i.e. match_addr is equal to selected ref_id) */
|
sample was received (i.e. match_refid is equal to selected refid) */
|
||||||
if (selected_source_index != old_selected_index ||
|
if (selected_source_index != old_selected_index ||
|
||||||
match_addr == sources[selected_source_index]->ref_id) {
|
match_refid == sources[selected_source_index]->ref_id) {
|
||||||
|
|
||||||
/* Now just use the statistics of the selected source for
|
/* Now just use the statistics of the selected source combined with
|
||||||
trimming the local clock */
|
the other selectable sources for trimming the local clock */
|
||||||
|
|
||||||
LCL_ReadCookedTime(&now, NULL);
|
SST_GetTrackingData(sources[selected_source_index]->stats, &ref_time,
|
||||||
|
|
||||||
SST_GetTrackingData(sources[selected_source_index]->stats, &now,
|
|
||||||
&src_offset, &src_offset_sd,
|
&src_offset, &src_offset_sd,
|
||||||
&src_accrued_dispersion,
|
&src_frequency, &src_skew,
|
||||||
&src_frequency, &src_skew);
|
&src_root_delay, &src_root_dispersion);
|
||||||
|
|
||||||
total_root_dispersion = (src_accrued_dispersion +
|
combined = combine_sources(n_sel_sources, &ref_time, &src_offset,
|
||||||
sources[selected_source_index]->sel_info.root_dispersion);
|
&src_offset_sd, &src_frequency, &src_skew);
|
||||||
|
|
||||||
REF_SetReference(min_stratum, leap_status,
|
REF_SetReference(sources[selected_source_index]->sel_info.stratum,
|
||||||
|
leap_status,
|
||||||
|
combined,
|
||||||
sources[selected_source_index]->ref_id,
|
sources[selected_source_index]->ref_id,
|
||||||
sources[selected_source_index]->ip_addr,
|
sources[selected_source_index]->ip_addr,
|
||||||
&now,
|
&ref_time,
|
||||||
src_offset,
|
src_offset,
|
||||||
|
src_offset_sd,
|
||||||
src_frequency,
|
src_frequency,
|
||||||
src_skew,
|
src_skew,
|
||||||
sources[selected_source_index]->sel_info.root_delay,
|
src_root_delay,
|
||||||
total_root_dispersion);
|
src_root_dispersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@@ -897,6 +990,17 @@ SRC_ReselectSource(void)
|
|||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
|
void
|
||||||
|
SRC_SetReselectDistance(double distance)
|
||||||
|
{
|
||||||
|
if (reselect_distance != distance) {
|
||||||
|
reselect_distance = distance;
|
||||||
|
LOG(LOGS_INFO, LOGF_Sources, "New reselect distance %f", distance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
double
|
double
|
||||||
SRC_PredictOffset(SRC_Instance inst, struct timeval *when)
|
SRC_PredictOffset(SRC_Instance inst, struct timeval *when)
|
||||||
{
|
{
|
||||||
@@ -1083,6 +1187,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_OK:
|
||||||
case SRC_BAD_STATS:
|
case SRC_BAD_STATS:
|
||||||
case SRC_UNREACHABLE:
|
case SRC_UNREACHABLE:
|
||||||
report->state = RPT_UNREACH;
|
report->state = RPT_UNREACH;
|
||||||
@@ -1091,12 +1196,29 @@ SRC_ReportSource(int index, RPT_SourceReport *report, struct timeval *now)
|
|||||||
report->state = RPT_FALSETICKER;
|
report->state = RPT_FALSETICKER;
|
||||||
break;
|
break;
|
||||||
case SRC_SELECTABLE:
|
case SRC_SELECTABLE:
|
||||||
report->state = RPT_CANDIDATE;
|
report->state = src->outlier ? RPT_OUTLIER : RPT_CANDIDATE;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
assert(0);
|
assert(0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch (src->sel_option) {
|
||||||
|
case SRC_SelectNormal:
|
||||||
|
report->sel_option = RPT_NOSELECT;
|
||||||
|
break;
|
||||||
|
case SRC_SelectPrefer:
|
||||||
|
report->sel_option = RPT_PREFER;
|
||||||
|
break;
|
||||||
|
case SRC_SelectNoselect:
|
||||||
|
report->sel_option = RPT_NOSELECT;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
assert(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
report->reachability = src->reachability;
|
||||||
|
|
||||||
/* Call stats module to fill out estimates */
|
/* Call stats module to fill out estimates */
|
||||||
SST_DoSourceReport(src->stats, report, now);
|
SST_DoSourceReport(src->stats, report, now);
|
||||||
|
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ typedef enum {
|
|||||||
/* Function to create a new instance. This would be called by one of
|
/* Function to create a new instance. This would be called by one of
|
||||||
the individual source-type instance creation routines. */
|
the individual source-type instance creation routines. */
|
||||||
|
|
||||||
extern SRC_Instance SRC_CreateNewInstance(unsigned long ref_id, SRC_Type type, SRC_SelectOption sel_option, IPAddr *addr);
|
extern SRC_Instance SRC_CreateNewInstance(uint32_t ref_id, SRC_Type type, SRC_SelectOption sel_option, IPAddr *addr);
|
||||||
|
|
||||||
/* Function to get rid of a source when it is being unconfigured.
|
/* Function to get rid of a source when it is being unconfigured.
|
||||||
This may cause the current reference source to be reselected, if this
|
This may cause the current reference source to be reselected, if this
|
||||||
@@ -135,11 +135,14 @@ extern void SRC_ResetReachability(SRC_Instance inst);
|
|||||||
reference source address. (This avoids updating the frequency
|
reference source address. (This avoids updating the frequency
|
||||||
tracking for every sample from other sources - only the ones from
|
tracking for every sample from other sources - only the ones from
|
||||||
the selected reference make a difference) */
|
the selected reference make a difference) */
|
||||||
extern void SRC_SelectSource(unsigned long match_addr);
|
extern void SRC_SelectSource(uint32_t match_refid);
|
||||||
|
|
||||||
/* Force reselecting the best source */
|
/* Force reselecting the best source */
|
||||||
extern void SRC_ReselectSource(void);
|
extern void SRC_ReselectSource(void);
|
||||||
|
|
||||||
|
/* Set reselect distance */
|
||||||
|
extern void SRC_SetReselectDistance(double distance);
|
||||||
|
|
||||||
/* Predict the offset of the local clock relative to a given source at
|
/* Predict the offset of the local clock relative to a given source at
|
||||||
a given local cooked time. Positive indicates local clock is FAST
|
a given local cooked time. Positive indicates local clock is FAST
|
||||||
relative to reference. */
|
relative to reference. */
|
||||||
|
|||||||
165
sourcestats.c
165
sourcestats.c
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
* Copyright (C) Richard P. Curnow 1997-2003
|
* Copyright (C) Richard P. Curnow 1997-2003
|
||||||
* Copyright (C) Miroslav Lichvar 2011
|
* Copyright (C) Miroslav Lichvar 2011-2012
|
||||||
*
|
*
|
||||||
* 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
|
||||||
@@ -26,6 +26,8 @@
|
|||||||
analysis on the samples obtained from the sources,
|
analysis on the samples obtained from the sources,
|
||||||
to determined frequencies and error bounds. */
|
to determined frequencies and error bounds. */
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
#include "sysincl.h"
|
#include "sysincl.h"
|
||||||
|
|
||||||
#include "sourcestats.h"
|
#include "sourcestats.h"
|
||||||
@@ -41,10 +43,17 @@
|
|||||||
to store per source */
|
to store per source */
|
||||||
#define MAX_SAMPLES 64
|
#define MAX_SAMPLES 64
|
||||||
|
|
||||||
|
/* User defined maximum and minimum number of samples */
|
||||||
|
int max_samples;
|
||||||
|
int min_samples;
|
||||||
|
|
||||||
/* This is the assumed worst case bound on an unknown frequency,
|
/* This is the assumed worst case bound on an unknown frequency,
|
||||||
2000ppm, which would be pretty bad */
|
2000ppm, which would be pretty bad */
|
||||||
#define WORST_CASE_FREQ_BOUND (2000.0/1.0e6)
|
#define WORST_CASE_FREQ_BOUND (2000.0/1.0e6)
|
||||||
|
|
||||||
|
/* The minimum allowed skew */
|
||||||
|
#define MIN_SKEW 1.0e-12
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
static LOG_FileID logfileid;
|
static LOG_FileID logfileid;
|
||||||
@@ -56,7 +65,7 @@ static LOG_FileID logfileid;
|
|||||||
struct SST_Stats_Record {
|
struct SST_Stats_Record {
|
||||||
|
|
||||||
/* Reference ID and IP address of source, used for logging to statistics log */
|
/* Reference ID and IP address of source, used for logging to statistics log */
|
||||||
unsigned long refid;
|
uint32_t refid;
|
||||||
IPAddr *ip_addr;
|
IPAddr *ip_addr;
|
||||||
|
|
||||||
/* Number of samples currently stored. The samples are stored in circular
|
/* Number of samples currently stored. The samples are stored in circular
|
||||||
@@ -158,6 +167,8 @@ SST_Initialise(void)
|
|||||||
logfileid = CNF_GetLogStatistics() ? LOG_FileOpen("statistics",
|
logfileid = CNF_GetLogStatistics() ? LOG_FileOpen("statistics",
|
||||||
" Date (UTC) Time IP Address Std dev'n Est offset Offset sd Diff freq Est skew Stress Ns Bs Nr")
|
" Date (UTC) Time IP Address Std dev'n Est offset Offset sd Diff freq Est skew Stress Ns Bs Nr")
|
||||||
: -1;
|
: -1;
|
||||||
|
max_samples = CNF_GetMaxSamples();
|
||||||
|
min_samples = CNF_GetMinSamples();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -171,7 +182,7 @@ SST_Finalise(void)
|
|||||||
/* This function creates a new instance of the statistics handler */
|
/* This function creates a new instance of the statistics handler */
|
||||||
|
|
||||||
SST_Stats
|
SST_Stats
|
||||||
SST_CreateInstance(unsigned long refid, IPAddr *addr)
|
SST_CreateInstance(uint32_t refid, IPAddr *addr)
|
||||||
{
|
{
|
||||||
SST_Stats inst;
|
SST_Stats inst;
|
||||||
inst = MallocNew(struct SST_Stats_Record);
|
inst = MallocNew(struct SST_Stats_Record);
|
||||||
@@ -202,7 +213,6 @@ void
|
|||||||
SST_DeleteInstance(SST_Stats inst)
|
SST_DeleteInstance(SST_Stats inst)
|
||||||
{
|
{
|
||||||
Free(inst);
|
Free(inst);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -237,10 +247,20 @@ SST_AccumulateSample(SST_Stats inst, struct timeval *sample_time,
|
|||||||
{
|
{
|
||||||
int n, m;
|
int n, m;
|
||||||
|
|
||||||
if (inst->n_samples == MAX_SAMPLES) {
|
/* Make room for the new sample */
|
||||||
|
if (inst->n_samples > 0 &&
|
||||||
|
(inst->n_samples == MAX_SAMPLES || inst->n_samples == max_samples)) {
|
||||||
prune_register(inst, 1);
|
prune_register(inst, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Make sure it's newer than the last sample */
|
||||||
|
if (inst->n_samples &&
|
||||||
|
UTI_CompareTimevals(&inst->sample_times[inst->last_sample], sample_time) >= 0) {
|
||||||
|
LOG(LOGS_WARN, LOGF_SourceStats, "Out of order sample detected, discarding history for %s",
|
||||||
|
inst->ip_addr ? UTI_IPToString(inst->ip_addr) : UTI_RefidToString(inst->refid));
|
||||||
|
prune_register(inst, inst->n_samples);
|
||||||
|
}
|
||||||
|
|
||||||
n = inst->last_sample = (inst->last_sample + 1) %
|
n = inst->last_sample = (inst->last_sample + 1) %
|
||||||
(MAX_SAMPLES * REGRESS_RUNS_RATIO);
|
(MAX_SAMPLES * REGRESS_RUNS_RATIO);
|
||||||
m = n % MAX_SAMPLES;
|
m = n % MAX_SAMPLES;
|
||||||
@@ -248,7 +268,7 @@ SST_AccumulateSample(SST_Stats inst, struct timeval *sample_time,
|
|||||||
inst->sample_times[n] = *sample_time;
|
inst->sample_times[n] = *sample_time;
|
||||||
inst->offsets[n] = offset;
|
inst->offsets[n] = offset;
|
||||||
inst->orig_offsets[m] = offset;
|
inst->orig_offsets[m] = offset;
|
||||||
inst->peer_delays[m] = fabs(peer_delay);
|
inst->peer_delays[m] = peer_delay;
|
||||||
inst->peer_dispersions[m] = peer_dispersion;
|
inst->peer_dispersions[m] = peer_dispersion;
|
||||||
inst->root_delays[m] = root_delay;
|
inst->root_delays[m] = root_delay;
|
||||||
inst->root_dispersions[m] = root_dispersion;
|
inst->root_dispersions[m] = root_dispersion;
|
||||||
@@ -324,7 +344,7 @@ find_best_sample_index(SST_Stats inst, double *times_back)
|
|||||||
elapsed = -times_back[i];
|
elapsed = -times_back[i];
|
||||||
assert(elapsed >= 0.0);
|
assert(elapsed >= 0.0);
|
||||||
|
|
||||||
root_distance = inst->root_dispersions[j] + elapsed * inst->skew + 0.5 * fabs(inst->root_delays[j]);
|
root_distance = inst->root_dispersions[j] + elapsed * inst->skew + 0.5 * inst->root_delays[j];
|
||||||
if (root_distance < best_root_distance) {
|
if (root_distance < best_root_distance) {
|
||||||
best_root_distance = root_distance;
|
best_root_distance = root_distance;
|
||||||
best_index = i;
|
best_index = i;
|
||||||
@@ -337,8 +357,6 @@ find_best_sample_index(SST_Stats inst, double *times_back)
|
|||||||
#if 0
|
#if 0
|
||||||
LOG(LOGS_INFO, LOGF_SourceStats, "n=%d best_index=%d", n, best_index);
|
LOG(LOGS_INFO, LOGF_SourceStats, "n=%d best_index=%d", n, best_index);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -384,7 +402,7 @@ SST_DoNewRegression(SST_Stats inst)
|
|||||||
int best_start, times_back_start;
|
int best_start, times_back_start;
|
||||||
double est_intercept, est_slope, est_var, est_intercept_sd, est_slope_sd;
|
double est_intercept, est_slope, est_var, est_intercept_sd, est_slope_sd;
|
||||||
int i, j, nruns;
|
int i, j, nruns;
|
||||||
double min_distance;
|
double min_distance, mean_distance;
|
||||||
double sd_weight, sd;
|
double sd_weight, sd;
|
||||||
double old_skew, old_freq, stress;
|
double old_skew, old_freq, stress;
|
||||||
|
|
||||||
@@ -395,17 +413,19 @@ SST_DoNewRegression(SST_Stats inst)
|
|||||||
offsets[i + inst->runs_samples] = inst->offsets[get_runsbuf_index(inst, i)];
|
offsets[i + inst->runs_samples] = inst->offsets[get_runsbuf_index(inst, i)];
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0, min_distance = DBL_MAX; i < inst->n_samples; i++) {
|
for (i = 0, mean_distance = 0.0, min_distance = DBL_MAX; i < inst->n_samples; i++) {
|
||||||
j = get_buf_index(inst, i);
|
j = get_buf_index(inst, i);
|
||||||
peer_distances[i] = 0.5 * inst->peer_delays[j] + inst->peer_dispersions[j];
|
peer_distances[i] = 0.5 * inst->peer_delays[j] + inst->peer_dispersions[j];
|
||||||
|
mean_distance += peer_distances[i];
|
||||||
if (peer_distances[i] < min_distance) {
|
if (peer_distances[i] < min_distance) {
|
||||||
min_distance = peer_distances[i];
|
min_distance = peer_distances[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
mean_distance /= inst->n_samples;
|
||||||
|
|
||||||
/* And now, work out the weight vector */
|
/* And now, work out the weight vector */
|
||||||
|
|
||||||
sd = sqrt(inst->variance);
|
sd = mean_distance - min_distance;
|
||||||
if (sd > min_distance || sd <= 0.0)
|
if (sd > min_distance || sd <= 0.0)
|
||||||
sd = min_distance;
|
sd = min_distance;
|
||||||
|
|
||||||
@@ -418,6 +438,7 @@ SST_DoNewRegression(SST_Stats inst)
|
|||||||
inst->regression_ok = RGR_FindBestRegression(times_back + inst->runs_samples,
|
inst->regression_ok = RGR_FindBestRegression(times_back + inst->runs_samples,
|
||||||
offsets + inst->runs_samples, weights,
|
offsets + inst->runs_samples, weights,
|
||||||
inst->n_samples, inst->runs_samples,
|
inst->n_samples, inst->runs_samples,
|
||||||
|
min_samples,
|
||||||
&est_intercept, &est_slope, &est_var,
|
&est_intercept, &est_slope, &est_var,
|
||||||
&est_intercept_sd, &est_slope_sd,
|
&est_intercept_sd, &est_slope_sd,
|
||||||
&best_start, &nruns, °rees_of_freedom);
|
&best_start, &nruns, °rees_of_freedom);
|
||||||
@@ -435,6 +456,9 @@ SST_DoNewRegression(SST_Stats inst)
|
|||||||
inst->variance = est_var;
|
inst->variance = est_var;
|
||||||
inst->nruns = nruns;
|
inst->nruns = nruns;
|
||||||
|
|
||||||
|
if (inst->skew < MIN_SKEW)
|
||||||
|
inst->skew = MIN_SKEW;
|
||||||
|
|
||||||
stress = fabs(old_freq - inst->estimated_frequency) / old_skew;
|
stress = fabs(old_freq - inst->estimated_frequency) / old_skew;
|
||||||
|
|
||||||
if (best_start > 0) {
|
if (best_start > 0) {
|
||||||
@@ -478,38 +502,6 @@ SST_DoNewRegression(SST_Stats inst)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
|
||||||
|
|
||||||
void
|
|
||||||
SST_GetReferenceData(SST_Stats inst, struct timeval *now,
|
|
||||||
int *stratum, double *offset,
|
|
||||||
double *root_delay, double *root_dispersion,
|
|
||||||
double *frequency, double *skew)
|
|
||||||
{
|
|
||||||
|
|
||||||
double elapsed;
|
|
||||||
int i, j;
|
|
||||||
|
|
||||||
*frequency = inst->estimated_frequency;
|
|
||||||
*skew = inst->skew;
|
|
||||||
|
|
||||||
i = get_runsbuf_index(inst, inst->best_single_sample);
|
|
||||||
j = get_buf_index(inst, inst->best_single_sample);
|
|
||||||
|
|
||||||
UTI_DiffTimevalsToDouble(&elapsed, now, &inst->sample_times[i]);
|
|
||||||
*root_delay = inst->root_delays[j];
|
|
||||||
*root_dispersion = inst->root_dispersions[j] + elapsed * inst->skew;
|
|
||||||
*offset = inst->offsets[i] + elapsed * inst->estimated_frequency;
|
|
||||||
*stratum = inst->strata[j];
|
|
||||||
|
|
||||||
#ifdef TRACEON
|
|
||||||
LOG(LOGS_INFO, LOGF_SourceStats, "n=%d freq=%f skew=%f del=%f disp=%f ofs=%f str=%d",
|
|
||||||
inst->n_samples, *frequency, *skew, *root_delay, *root_dispersion, *offset, *stratum);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
/* Return the assumed worst case range of values that this source's
|
/* Return the assumed worst case range of values that this source's
|
||||||
frequency lies within. Frequency is defined as the amount of time
|
frequency lies within. Frequency is defined as the amount of time
|
||||||
@@ -524,88 +516,92 @@ SST_GetFrequencyRange(SST_Stats inst,
|
|||||||
skew = inst->skew;
|
skew = inst->skew;
|
||||||
*lo = freq - skew;
|
*lo = freq - skew;
|
||||||
*hi = freq + skew;
|
*hi = freq + skew;
|
||||||
}
|
|
||||||
|
|
||||||
/* ================================================== */
|
/* This function is currently used only to determine the values of delta
|
||||||
|
and epsilon in the ntp_core module. Limit the skew to a reasonable maximum
|
||||||
|
to avoid failing the dispersion test too easily. */
|
||||||
|
if (skew > WORST_CASE_FREQ_BOUND) {
|
||||||
|
*lo = -WORST_CASE_FREQ_BOUND;
|
||||||
|
*hi = WORST_CASE_FREQ_BOUND;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
void
|
void
|
||||||
SST_GetSelectionData(SST_Stats inst, struct timeval *now,
|
SST_GetSelectionData(SST_Stats inst, struct timeval *now,
|
||||||
int *stratum,
|
int *stratum,
|
||||||
double *best_offset, double *best_root_delay,
|
double *offset_lo_limit,
|
||||||
double *best_root_dispersion,
|
double *offset_hi_limit,
|
||||||
|
double *root_distance,
|
||||||
double *variance, int *select_ok)
|
double *variance, int *select_ok)
|
||||||
{
|
{
|
||||||
double average_offset;
|
double offset, sample_elapsed;
|
||||||
double sample_elapsed;
|
|
||||||
double elapsed;
|
|
||||||
int i, j;
|
int i, j;
|
||||||
int average_ok;
|
|
||||||
double peer_distance;
|
|
||||||
|
|
||||||
i = get_runsbuf_index(inst, inst->best_single_sample);
|
i = get_runsbuf_index(inst, inst->best_single_sample);
|
||||||
j = get_buf_index(inst, inst->best_single_sample);
|
j = get_buf_index(inst, inst->best_single_sample);
|
||||||
|
|
||||||
*stratum = inst->strata[j];
|
*stratum = inst->strata[get_buf_index(inst, inst->n_samples - 1)];
|
||||||
*variance = inst->variance;
|
*variance = inst->variance;
|
||||||
|
|
||||||
peer_distance = inst->peer_dispersions[j] + 0.5 * inst->peer_delays[j];
|
|
||||||
UTI_DiffTimevalsToDouble(&elapsed, now, &(inst->offset_time));
|
|
||||||
|
|
||||||
UTI_DiffTimevalsToDouble(&sample_elapsed, now, &inst->sample_times[i]);
|
UTI_DiffTimevalsToDouble(&sample_elapsed, now, &inst->sample_times[i]);
|
||||||
*best_offset = inst->offsets[i] + sample_elapsed * inst->estimated_frequency;
|
offset = inst->offsets[i] + sample_elapsed * inst->estimated_frequency;
|
||||||
*best_root_delay = inst->root_delays[j];
|
*root_distance = 0.5 * inst->root_delays[j] +
|
||||||
*best_root_dispersion = inst->root_dispersions[j] + sample_elapsed * inst->skew;
|
inst->root_dispersions[j] + sample_elapsed * inst->skew;
|
||||||
|
|
||||||
|
*offset_lo_limit = offset - *root_distance;
|
||||||
|
*offset_hi_limit = offset + *root_distance;
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
double average_offset, elapsed;
|
||||||
|
int average_ok;
|
||||||
/* average_ok ignored for now */
|
/* average_ok ignored for now */
|
||||||
|
UTI_DiffTimevalsToDouble(&elapsed, now, &(inst->offset_time));
|
||||||
average_offset = inst->estimated_offset + inst->estimated_frequency * elapsed;
|
average_offset = inst->estimated_offset + inst->estimated_frequency * elapsed;
|
||||||
if (fabs(average_offset - *best_offset) <= peer_distance) {
|
if (fabs(average_offset - offset) <=
|
||||||
|
inst->peer_dispersions[j] + 0.5 * inst->peer_delays[j]) {
|
||||||
average_ok = 1;
|
average_ok = 1;
|
||||||
} else {
|
} else {
|
||||||
average_ok = 0;
|
average_ok = 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
*select_ok = inst->regression_ok;
|
*select_ok = inst->regression_ok;
|
||||||
|
|
||||||
#ifdef TRACEON
|
#ifdef TRACEON
|
||||||
LOG(LOGS_INFO, LOGF_SourceStats, "n=%d off=%f del=%f dis=%f var=%f pdist=%f avoff=%f avok=%d selok=%d",
|
LOG(LOGS_INFO, LOGF_SourceStats, "n=%d off=%f dist=%f var=%f selok=%d",
|
||||||
inst->n_samples, *best_offset, *best_root_delay, *best_root_dispersion, *variance,
|
inst->n_samples, offset, *root_distance, *variance, *select_ok);
|
||||||
peer_distance, average_offset, average_ok, *select_ok);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
void
|
void
|
||||||
SST_GetTrackingData(SST_Stats inst, struct timeval *now,
|
SST_GetTrackingData(SST_Stats inst, struct timeval *ref_time,
|
||||||
double *average_offset, double *offset_sd,
|
double *average_offset, double *offset_sd,
|
||||||
double *accrued_dispersion,
|
double *frequency, double *skew,
|
||||||
double *frequency, double *skew)
|
double *root_delay, double *root_dispersion)
|
||||||
{
|
{
|
||||||
int i, j;
|
int i, j;
|
||||||
double peer_distance;
|
double elapsed_sample;
|
||||||
double elapsed_offset, elapsed_sample;
|
|
||||||
|
|
||||||
i = get_runsbuf_index(inst, inst->best_single_sample);
|
i = get_runsbuf_index(inst, inst->best_single_sample);
|
||||||
j = get_buf_index(inst, inst->best_single_sample);
|
j = get_buf_index(inst, inst->best_single_sample);
|
||||||
|
|
||||||
|
*ref_time = inst->offset_time;
|
||||||
|
*average_offset = inst->estimated_offset;
|
||||||
|
*offset_sd = inst->estimated_offset_sd;
|
||||||
*frequency = inst->estimated_frequency;
|
*frequency = inst->estimated_frequency;
|
||||||
*skew = inst->skew;
|
*skew = inst->skew;
|
||||||
|
*root_delay = inst->root_delays[j];
|
||||||
|
|
||||||
peer_distance = inst->peer_dispersions[j] + 0.5 * inst->peer_delays[j];
|
UTI_DiffTimevalsToDouble(&elapsed_sample, &inst->offset_time, &inst->sample_times[i]);
|
||||||
UTI_DiffTimevalsToDouble(&elapsed_offset, now, &(inst->offset_time));
|
*root_dispersion = inst->root_dispersions[j] + inst->skew * elapsed_sample;
|
||||||
*average_offset = inst->estimated_offset + inst->estimated_frequency * elapsed_offset;
|
|
||||||
*offset_sd = inst->estimated_offset_sd + elapsed_offset * inst->skew;
|
|
||||||
|
|
||||||
UTI_DiffTimevalsToDouble(&elapsed_sample, now, &inst->sample_times[i]);
|
|
||||||
*accrued_dispersion = inst->skew * elapsed_sample;
|
|
||||||
|
|
||||||
#ifdef TRACEON
|
#ifdef TRACEON
|
||||||
LOG(LOGS_INFO, LOGF_SourceStats, "n=%d freq=%f (%.3fppm) skew=%f (%.3fppm) pdist=%f avoff=%f offsd=%f accrdis=%f",
|
LOG(LOGS_INFO, LOGF_SourceStats, "n=%d freq=%f (%.3fppm) skew=%f (%.3fppm) avoff=%f offsd=%f disp=%f",
|
||||||
inst->n_samples, *frequency, 1.0e6* *frequency, *skew, 1.0e6* *skew, peer_distance, *average_offset, *offset_sd, *accrued_dispersion);
|
inst->n_samples, *frequency, 1.0e6* *frequency, *skew, 1.0e6* *skew, *average_offset, *offset_sd, *root_dispersion);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -620,6 +616,9 @@ SST_SlewSamples(SST_Stats inst, struct timeval *when, double dfreq, double doffs
|
|||||||
struct timeval *sample, prev;
|
struct timeval *sample, prev;
|
||||||
double prev_offset, prev_freq;
|
double prev_offset, prev_freq;
|
||||||
|
|
||||||
|
if (!inst->n_samples)
|
||||||
|
return;
|
||||||
|
|
||||||
for (m = -inst->runs_samples; m < inst->n_samples; m++) {
|
for (m = -inst->runs_samples; m < inst->n_samples; m++) {
|
||||||
i = get_runsbuf_index(inst, m);
|
i = get_runsbuf_index(inst, m);
|
||||||
sample = &(inst->sample_times[i]);
|
sample = &(inst->sample_times[i]);
|
||||||
@@ -631,6 +630,8 @@ SST_SlewSamples(SST_Stats inst, struct timeval *when, double dfreq, double doffs
|
|||||||
LOG(LOGS_INFO, LOGF_SourceStats, "i=%d old_st=[%s] new_st=[%s] old_off=%f new_off=%f",
|
LOG(LOGS_INFO, LOGF_SourceStats, "i=%d old_st=[%s] new_st=[%s] old_off=%f new_off=%f",
|
||||||
i, UTI_TimevalToString(&prev), UTI_TimevalToString(sample),
|
i, UTI_TimevalToString(&prev), UTI_TimevalToString(sample),
|
||||||
prev_offset, inst->offsets[i]);
|
prev_offset, inst->offsets[i]);
|
||||||
|
#else
|
||||||
|
(void)prev_offset;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -648,9 +649,9 @@ SST_SlewSamples(SST_Stats inst, struct timeval *when, double dfreq, double doffs
|
|||||||
UTI_TimevalToString(&prev), UTI_TimevalToString(&(inst->offset_time)),
|
UTI_TimevalToString(&prev), UTI_TimevalToString(&(inst->offset_time)),
|
||||||
prev_offset, inst->estimated_offset,
|
prev_offset, inst->estimated_offset,
|
||||||
1.0e6*prev_freq, 1.0e6*inst->estimated_frequency);
|
1.0e6*prev_freq, 1.0e6*inst->estimated_frequency);
|
||||||
|
#else
|
||||||
|
(void)prev; (void)prev_freq;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ extern void SST_Initialise(void);
|
|||||||
extern void SST_Finalise(void);
|
extern void SST_Finalise(void);
|
||||||
|
|
||||||
/* This function creates a new instance of the statistics handler */
|
/* This function creates a new instance of the statistics handler */
|
||||||
extern SST_Stats SST_CreateInstance(unsigned long refid, IPAddr *addr);
|
extern SST_Stats SST_CreateInstance(uint32_t refid, IPAddr *addr);
|
||||||
|
|
||||||
/* This function deletes an instance of the statistics handler. */
|
/* This function deletes an instance of the statistics handler. */
|
||||||
extern void SST_DeleteInstance(SST_Stats inst);
|
extern void SST_DeleteInstance(SST_Stats inst);
|
||||||
@@ -82,26 +82,17 @@ extern void SST_GetFrequencyRange(SST_Stats inst, double *lo, double *hi);
|
|||||||
extern void
|
extern void
|
||||||
SST_GetSelectionData(SST_Stats inst, struct timeval *now,
|
SST_GetSelectionData(SST_Stats inst, struct timeval *now,
|
||||||
int *stratum,
|
int *stratum,
|
||||||
double *best_offset, double *best_root_delay,
|
double *offset_lo_limit,
|
||||||
double *best_root_dispersion,
|
double *offset_hi_limit,
|
||||||
double *variance,
|
double *root_distance,
|
||||||
int *select_ok);
|
double *variance, int *select_ok);
|
||||||
|
|
||||||
/* Get data needed when setting up tracking on this source */
|
/* Get data needed when setting up tracking on this source */
|
||||||
extern void
|
extern void
|
||||||
SST_GetTrackingData(SST_Stats inst, struct timeval *now,
|
SST_GetTrackingData(SST_Stats inst, struct timeval *ref_time,
|
||||||
double *average_offset, double *offset_sd,
|
double *average_offset, double *offset_sd,
|
||||||
double *accrued_dispersion,
|
double *frequency, double *skew,
|
||||||
double *frequency, double *skew);
|
double *root_delay, double *root_dispersion);
|
||||||
|
|
||||||
/* Get parameters for using this source as the reference */
|
|
||||||
extern void
|
|
||||||
SST_GetReferenceData(SST_Stats inst, struct timeval *now,
|
|
||||||
int *stratum, double *offset,
|
|
||||||
double *root_delay, double *root_dispersion,
|
|
||||||
double *frequency, double *skew);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* This routine is called when the local machine clock parameters are
|
/* This routine is called when the local machine clock parameters are
|
||||||
changed. It adjusts all existing samples that we are holding for
|
changed. It adjusts all existing samples that we are holding for
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ typedef struct {
|
|||||||
#define SRC_DEFAULT_MAXPOLL 10
|
#define SRC_DEFAULT_MAXPOLL 10
|
||||||
#define SRC_DEFAULT_PRESEND_MINPOLL 0
|
#define SRC_DEFAULT_PRESEND_MINPOLL 0
|
||||||
#define SRC_DEFAULT_MAXDELAY 16.0
|
#define SRC_DEFAULT_MAXDELAY 16.0
|
||||||
#define SRC_DEFAULT_MAXDELAYRATIO 16384.0
|
#define SRC_DEFAULT_MAXDELAYRATIO 0.0
|
||||||
#define SRC_DEFAULT_MAXDELAYDEVRATIO 10.0
|
#define SRC_DEFAULT_MAXDELAYDEVRATIO 10.0
|
||||||
#define SRC_DEFAULT_MINSTRATUM 0
|
#define SRC_DEFAULT_MINSTRATUM 0
|
||||||
#define SRC_DEFAULT_POLLTARGET 6
|
#define SRC_DEFAULT_POLLTARGET 6
|
||||||
|
|||||||
@@ -24,6 +24,8 @@
|
|||||||
Replacement strerror function for systems that don't have it
|
Replacement strerror function for systems that don't have it
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
#ifdef SUNOS
|
#ifdef SUNOS
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|||||||
10
sys.c
10
sys.c
@@ -25,6 +25,8 @@
|
|||||||
in the various operating-system specific modules
|
in the various operating-system specific modules
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
#include "sys.h"
|
#include "sys.h"
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
|
|
||||||
@@ -89,8 +91,6 @@ SYS_Finalise(void)
|
|||||||
#if defined(__NetBSD__)
|
#if defined(__NetBSD__)
|
||||||
SYS_NetBSD_Finalise();
|
SYS_NetBSD_Finalise();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -102,8 +102,6 @@ void SYS_DropRoot(char *user)
|
|||||||
#else
|
#else
|
||||||
LOG_FATAL(LOGF_Sys, "dropping root privileges not supported");
|
LOG_FATAL(LOGF_Sys, "dropping root privileges not supported");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -115,8 +113,6 @@ void SYS_SetScheduler(int SchedPriority)
|
|||||||
#else
|
#else
|
||||||
LOG_FATAL(LOGF_Sys, "scheduler priority setting not supported");
|
LOG_FATAL(LOGF_Sys, "scheduler priority setting not supported");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -128,8 +124,6 @@ void SYS_LockMemory(void)
|
|||||||
#else
|
#else
|
||||||
LOG_FATAL(LOGF_Sys, "memory locking not supported");
|
LOG_FATAL(LOGF_Sys, "memory locking not supported");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|||||||
487
sys_linux.c
487
sys_linux.c
@@ -4,7 +4,7 @@
|
|||||||
**********************************************************************
|
**********************************************************************
|
||||||
* Copyright (C) Richard P. Curnow 1997-2003
|
* Copyright (C) Richard P. Curnow 1997-2003
|
||||||
* Copyright (C) John G. Hasler 2009
|
* Copyright (C) John G. Hasler 2009
|
||||||
* Copyright (C) Miroslav Lichvar 2009-2011
|
* Copyright (C) Miroslav Lichvar 2009-2012
|
||||||
*
|
*
|
||||||
* 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
|
||||||
@@ -27,14 +27,10 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef LINUX
|
#include "config.h"
|
||||||
|
|
||||||
|
#include "sysincl.h"
|
||||||
|
|
||||||
#include <sys/time.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <math.h>
|
|
||||||
#include <ctype.h>
|
|
||||||
#include <assert.h>
|
|
||||||
#include <sys/utsname.h>
|
#include <sys/utsname.h>
|
||||||
|
|
||||||
#if defined(HAVE_SCHED_SETSCHEDULER)
|
#if defined(HAVE_SCHED_SETSCHEDULER)
|
||||||
@@ -104,8 +100,7 @@ static int version_patchlevel;
|
|||||||
/* Flag indicating whether adjtimex() returns the remaining time adjustment
|
/* Flag indicating whether adjtimex() returns the remaining time adjustment
|
||||||
or not. If not we have to read the outstanding adjustment by setting it to
|
or not. If not we have to read the outstanding adjustment by setting it to
|
||||||
zero, examining the return value and setting the outstanding adjustment back
|
zero, examining the return value and setting the outstanding adjustment back
|
||||||
again. If 1, txc.modes equal to zero is used to read the time. If 2,
|
again. */
|
||||||
txc.modes is set to ADJ_OFFSET_SS_READ. */
|
|
||||||
|
|
||||||
static int have_readonly_adjtime;
|
static int have_readonly_adjtime;
|
||||||
|
|
||||||
@@ -114,6 +109,9 @@ static int have_readonly_adjtime;
|
|||||||
adjustments. */
|
adjustments. */
|
||||||
static int have_nanopll;
|
static int have_nanopll;
|
||||||
|
|
||||||
|
/* Flag indicating whether adjtimex() can step the clock */
|
||||||
|
static int have_setoffset;
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
static void handle_end_of_slew(void *anything);
|
static void handle_end_of_slew(void *anything);
|
||||||
@@ -170,6 +168,9 @@ static SCH_TimeoutID slew_timeout_id;
|
|||||||
a fast slew */
|
a fast slew */
|
||||||
static double delta_total_tick;
|
static double delta_total_tick;
|
||||||
|
|
||||||
|
/* Maximum length of one fast slew */
|
||||||
|
#define MAX_FASTSLEW_TIMEOUT (3600 * 24 * 7)
|
||||||
|
|
||||||
/* Max amount of time that we wish to slew by using adjtime (or its
|
/* Max amount of time that we wish to slew by using adjtime (or its
|
||||||
equivalent). If more than this is outstanding, we alter the value
|
equivalent). If more than this is outstanding, we alter the value
|
||||||
of tick instead, for a set period. Set this according to the
|
of tick instead, for a set period. Set this according to the
|
||||||
@@ -178,7 +179,7 @@ static double delta_total_tick;
|
|||||||
#define MAX_ADJUST_WITH_ADJTIME (0.2)
|
#define MAX_ADJUST_WITH_ADJTIME (0.2)
|
||||||
|
|
||||||
/* Max amount of time that should be adjusted by kernel PLL */
|
/* Max amount of time that should be adjusted by kernel PLL */
|
||||||
#define MAX_ADJUST_WITH_NANOPLL (1.0e-5)
|
#define MAX_ADJUST_WITH_NANOPLL (0.5)
|
||||||
|
|
||||||
/* The amount by which we alter 'tick' when doing a large slew */
|
/* The amount by which we alter 'tick' when doing a large slew */
|
||||||
static int slew_delta_tick;
|
static int slew_delta_tick;
|
||||||
@@ -205,6 +206,18 @@ static double fast_slew_error;
|
|||||||
/* The rate at which frequency and tick values are updated in kernel. */
|
/* The rate at which frequency and tick values are updated in kernel. */
|
||||||
static int tick_update_hz;
|
static int tick_update_hz;
|
||||||
|
|
||||||
|
#define MIN_PLL_TIME_CONSTANT 0
|
||||||
|
#define MAX_PLL_TIME_CONSTANT 10
|
||||||
|
|
||||||
|
/* PLL time constant used when adjusting offset by PLL */
|
||||||
|
static long pll_time_constant;
|
||||||
|
|
||||||
|
/* Suggested offset correction rate (correction time * offset) */
|
||||||
|
static double correction_rate;
|
||||||
|
|
||||||
|
/* Kernel time constant shift */
|
||||||
|
static int shift_pll;
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
/* These routines are used to estimate maximum error in offset correction */
|
/* These routines are used to estimate maximum error in offset correction */
|
||||||
|
|
||||||
@@ -265,9 +278,8 @@ update_nano_slew_error(long offset, int new)
|
|||||||
if (offset == 0 && nano_slew_error == 0)
|
if (offset == 0 && nano_slew_error == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* maximum error in offset reported by adjtimex, assuming PLL constant 0
|
/* maximum error in offset reported by adjtimex */
|
||||||
and SHIFT_PLL = 2 */
|
offset /= (1 << (shift_pll + pll_time_constant)) - (new ? 0 : 1);
|
||||||
offset /= new ? 4 : 3;
|
|
||||||
if (offset < 0)
|
if (offset < 0)
|
||||||
offset = -offset;
|
offset = -offset;
|
||||||
|
|
||||||
@@ -336,6 +348,27 @@ get_fast_slew_error(struct timeval *now)
|
|||||||
return left > 0.0 ? fast_slew_error : 0.0;
|
return left > 0.0 ? fast_slew_error : 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
/* Select PLL time constant according to the suggested correction rate. */
|
||||||
|
|
||||||
|
static long
|
||||||
|
get_pll_constant(double offset)
|
||||||
|
{
|
||||||
|
long c;
|
||||||
|
double corr_time;
|
||||||
|
|
||||||
|
if (offset < 1e-9)
|
||||||
|
return MIN_PLL_TIME_CONSTANT;
|
||||||
|
|
||||||
|
corr_time = correction_rate / offset;
|
||||||
|
|
||||||
|
for (c = MIN_PLL_TIME_CONSTANT; c < MAX_PLL_TIME_CONSTANT; c++)
|
||||||
|
if (corr_time < 1 << (c + 1 + shift_pll))
|
||||||
|
break;
|
||||||
|
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
/* This routine stops a fast slew, determines how long the slew has
|
/* This routine stops a fast slew, determines how long the slew has
|
||||||
been running for, and consequently how much adjustment has actually
|
been running for, and consequently how much adjustment has actually
|
||||||
@@ -380,7 +413,8 @@ stop_fast_slew(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
/* This routine reschedules fast slew timeout after frequency was changed */
|
/* This routine reschedules fast slew timeout according
|
||||||
|
to the current frequency and offset */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
adjust_fast_slew(double old_tick, double old_delta_tick)
|
adjust_fast_slew(double old_tick, double old_delta_tick)
|
||||||
@@ -401,8 +435,8 @@ adjust_fast_slew(double old_tick, double old_delta_tick)
|
|||||||
|
|
||||||
dseconds = -offset_register * (current_total_tick + delta_total_tick) / delta_total_tick;
|
dseconds = -offset_register * (current_total_tick + delta_total_tick) / delta_total_tick;
|
||||||
|
|
||||||
if (dseconds > 3600 * 24 * 7)
|
if (dseconds > MAX_FASTSLEW_TIMEOUT)
|
||||||
dseconds = 3600 * 24 * 7;
|
dseconds = MAX_FASTSLEW_TIMEOUT;
|
||||||
UTI_AddDoubleToTimeval(&tv, dseconds, &end_of_slew);
|
UTI_AddDoubleToTimeval(&tv, dseconds, &end_of_slew);
|
||||||
|
|
||||||
slew_start_tv = tv;
|
slew_start_tv = tv;
|
||||||
@@ -449,7 +483,7 @@ initiate_slew(void)
|
|||||||
update_nano_slew_error(offset, 0);
|
update_nano_slew_error(offset, 0);
|
||||||
|
|
||||||
offset = 0;
|
offset = 0;
|
||||||
if (TMX_ApplyPLLOffset(offset) < 0) {
|
if (TMX_ApplyPLLOffset(offset, MIN_PLL_TIME_CONSTANT) < 0) {
|
||||||
LOG_FATAL(LOGF_SysLinux, "adjtimex() failed");
|
LOG_FATAL(LOGF_SysLinux, "adjtimex() failed");
|
||||||
}
|
}
|
||||||
nano_slewing = 0;
|
nano_slewing = 0;
|
||||||
@@ -457,13 +491,23 @@ initiate_slew(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (have_nanopll && fabs(offset_register) < MAX_ADJUST_WITH_NANOPLL) {
|
if (have_nanopll && fabs(offset_register) < MAX_ADJUST_WITH_NANOPLL) {
|
||||||
/* Use PLL with fixed frequency to do the shift */
|
/* Use the PLL with fixed frequency to do the shift. Until the kernel has a
|
||||||
|
support for linear offset adjustments with programmable rate this is the
|
||||||
|
best we can do. */
|
||||||
offset = 1.0e9 * -offset_register;
|
offset = 1.0e9 * -offset_register;
|
||||||
|
|
||||||
if (TMX_ApplyPLLOffset(offset) < 0) {
|
/* First adjustment after accrue_offset() sets the PLL time constant */
|
||||||
|
if (pll_time_constant < 0) {
|
||||||
|
pll_time_constant = get_pll_constant(fabs(offset_register));
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(pll_time_constant >= MIN_PLL_TIME_CONSTANT &&
|
||||||
|
pll_time_constant <= MAX_PLL_TIME_CONSTANT);
|
||||||
|
|
||||||
|
if (TMX_ApplyPLLOffset(offset, pll_time_constant) < 0) {
|
||||||
LOG_FATAL(LOGF_SysLinux, "adjtimex() failed");
|
LOG_FATAL(LOGF_SysLinux, "adjtimex() failed");
|
||||||
}
|
}
|
||||||
offset_register = 0.0;
|
offset_register = 0.0; /* Don't keep the sub-nanosecond leftover */
|
||||||
nano_slewing = 1;
|
nano_slewing = 1;
|
||||||
update_nano_slew_error(offset, 1);
|
update_nano_slew_error(offset, 1);
|
||||||
} else if (fabs(offset_register) < MAX_ADJUST_WITH_ADJTIME) {
|
} else if (fabs(offset_register) < MAX_ADJUST_WITH_ADJTIME) {
|
||||||
@@ -493,14 +537,22 @@ initiate_slew(void)
|
|||||||
max_allowed_tick = nominal_tick + max_tick_bias;
|
max_allowed_tick = nominal_tick + max_tick_bias;
|
||||||
|
|
||||||
if (offset_register > 0) {
|
if (offset_register > 0) {
|
||||||
|
if (current_tick <= min_allowed_tick) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
slewing_tick = current_tick - slew_delta_tick;
|
slewing_tick = current_tick - slew_delta_tick;
|
||||||
if (slewing_tick <= min_allowed_tick) {
|
if (slewing_tick < min_allowed_tick) {
|
||||||
slewing_tick = min_allowed_tick + 1;
|
slewing_tick = min_allowed_tick;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if (current_tick >= max_allowed_tick) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
slewing_tick = current_tick + slew_delta_tick;
|
slewing_tick = current_tick + slew_delta_tick;
|
||||||
if (slewing_tick >= max_allowed_tick) {
|
if (slewing_tick > max_allowed_tick) {
|
||||||
slewing_tick = max_allowed_tick - 1;
|
slewing_tick = max_allowed_tick;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -509,6 +561,8 @@ initiate_slew(void)
|
|||||||
delta_total_tick = (double) tick_adjust / 1.0e6;
|
delta_total_tick = (double) tick_adjust / 1.0e6;
|
||||||
dseconds = - offset_register * (current_total_tick + delta_total_tick) / delta_total_tick;
|
dseconds = - offset_register * (current_total_tick + delta_total_tick) / delta_total_tick;
|
||||||
|
|
||||||
|
assert(dseconds > 0.0);
|
||||||
|
|
||||||
/* Now set the thing off */
|
/* Now set the thing off */
|
||||||
if (gettimeofday(&T0, NULL) < 0) {
|
if (gettimeofday(&T0, NULL) < 0) {
|
||||||
LOG_FATAL(LOGF_SysLinux, "gettimeofday() failed");
|
LOG_FATAL(LOGF_SysLinux, "gettimeofday() failed");
|
||||||
@@ -528,9 +582,8 @@ initiate_slew(void)
|
|||||||
fast_slewing = 1;
|
fast_slewing = 1;
|
||||||
slew_start_tv = T0;
|
slew_start_tv = T0;
|
||||||
|
|
||||||
/* Set up timeout for end of slew, limit to one week */
|
if (dseconds > MAX_FASTSLEW_TIMEOUT)
|
||||||
if (dseconds > 3600 * 24 * 7)
|
dseconds = MAX_FASTSLEW_TIMEOUT;
|
||||||
dseconds = 3600 * 24 * 7;
|
|
||||||
UTI_AddDoubleToTimeval(&T0, dseconds, &end_of_slew);
|
UTI_AddDoubleToTimeval(&T0, dseconds, &end_of_slew);
|
||||||
|
|
||||||
slew_timeout_id = SCH_AddTimeout(&end_of_slew, handle_end_of_slew, NULL);
|
slew_timeout_id = SCH_AddTimeout(&end_of_slew, handle_end_of_slew, NULL);
|
||||||
@@ -539,8 +592,6 @@ initiate_slew(void)
|
|||||||
offset_register = 0.0;
|
offset_register = 0.0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -576,16 +627,21 @@ abort_slew(void)
|
|||||||
time) */
|
time) */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
accrue_offset(double offset)
|
accrue_offset(double offset, double corr_rate)
|
||||||
{
|
{
|
||||||
/* Add the new offset to the register */
|
/* Add the new offset to the register */
|
||||||
offset_register += offset;
|
offset_register += offset;
|
||||||
|
|
||||||
|
correction_rate = corr_rate;
|
||||||
|
|
||||||
|
/* Select a new time constant on the next adjustment */
|
||||||
|
pll_time_constant = -1;
|
||||||
|
|
||||||
if (!fast_slewing) {
|
if (!fast_slewing) {
|
||||||
initiate_slew();
|
initiate_slew();
|
||||||
} /* Otherwise, when the fast slew completes, any other stuff
|
} else {
|
||||||
in the offset register will be applied */
|
adjust_fast_slew(current_total_tick, delta_total_tick);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -601,23 +657,29 @@ apply_step_offset(double offset)
|
|||||||
abort_slew();
|
abort_slew();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gettimeofday(&old_time, NULL) < 0) {
|
if (have_setoffset) {
|
||||||
LOG_FATAL(LOGF_SysLinux, "gettimeofday() failed");
|
if (TMX_ApplyStepOffset(-offset) < 0) {
|
||||||
|
LOG_FATAL(LOGF_SysLinux, "adjtimex() failed");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (gettimeofday(&old_time, NULL) < 0) {
|
||||||
|
LOG_FATAL(LOGF_SysLinux, "gettimeofday() failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
UTI_AddDoubleToTimeval(&old_time, -offset, &new_time);
|
||||||
|
|
||||||
|
if (settimeofday(&new_time, NULL) < 0) {
|
||||||
|
LOG_FATAL(LOGF_SysLinux, "settimeofday() failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gettimeofday(&old_time, NULL) < 0) {
|
||||||
|
LOG_FATAL(LOGF_SysLinux, "gettimeofday() failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
UTI_DiffTimevalsToDouble(&err, &old_time, &new_time);
|
||||||
|
lcl_InvokeDispersionNotifyHandlers(fabs(err));
|
||||||
}
|
}
|
||||||
|
|
||||||
UTI_AddDoubleToTimeval(&old_time, -offset, &new_time);
|
|
||||||
|
|
||||||
if (settimeofday(&new_time, NULL) < 0) {
|
|
||||||
LOG_FATAL(LOGF_SysLinux, "settimeofday() failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (gettimeofday(&old_time, NULL) < 0) {
|
|
||||||
LOG_FATAL(LOGF_SysLinux, "gettimeofday() failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
UTI_DiffTimevalsToDouble(&err, &old_time, &new_time);
|
|
||||||
lcl_InvokeDispersionNotifyHandlers(fabs(err));
|
|
||||||
|
|
||||||
initiate_slew();
|
initiate_slew();
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -638,32 +700,14 @@ set_frequency(double freq_ppm)
|
|||||||
double scaled_freq; /* what adjtimex & the kernel use */
|
double scaled_freq; /* what adjtimex & the kernel use */
|
||||||
double old_total_tick;
|
double old_total_tick;
|
||||||
int required_delta_tick;
|
int required_delta_tick;
|
||||||
int neg; /* True if estimate is that local clock runs slow,
|
|
||||||
i.e. positive frequency correction required */
|
|
||||||
|
|
||||||
|
|
||||||
if (freq_ppm < 0.0) {
|
|
||||||
neg = 1;
|
|
||||||
freq_ppm = -freq_ppm;
|
|
||||||
} else {
|
|
||||||
neg = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
required_delta_tick = our_round(freq_ppm / dhz);
|
required_delta_tick = our_round(freq_ppm / dhz);
|
||||||
required_freq = freq_ppm - dhz * (double) required_delta_tick;
|
required_freq = -(freq_ppm - dhz * required_delta_tick);
|
||||||
|
required_tick = nominal_tick - required_delta_tick;
|
||||||
|
scaled_freq = freq_scale * required_freq;
|
||||||
|
|
||||||
if (neg) {
|
min_allowed_tick = nominal_tick - max_tick_bias;
|
||||||
/* Uncompensated local clock runs slow */
|
max_allowed_tick = nominal_tick + max_tick_bias;
|
||||||
required_tick = nominal_tick + required_delta_tick;
|
|
||||||
scaled_freq = freq_scale * required_freq;
|
|
||||||
} else {
|
|
||||||
/* Uncompensated local clock runs fast */
|
|
||||||
required_tick = nominal_tick - required_delta_tick;
|
|
||||||
scaled_freq = -freq_scale * required_freq;
|
|
||||||
}
|
|
||||||
|
|
||||||
min_allowed_tick = nominal_tick - max_tick_bias + 5;
|
|
||||||
max_allowed_tick = nominal_tick + max_tick_bias - 5;
|
|
||||||
|
|
||||||
if (required_tick < min_allowed_tick || required_tick > max_allowed_tick) {
|
if (required_tick < min_allowed_tick || required_tick > max_allowed_tick) {
|
||||||
LOG(LOGS_WARN, LOGF_SysLinux, "Required tick %ld outside allowed range (%ld .. %ld)", required_tick, min_allowed_tick, max_allowed_tick);
|
LOG(LOGS_WARN, LOGF_SysLinux, "Required tick %ld outside allowed range (%ld .. %ld)", required_tick, min_allowed_tick, max_allowed_tick);
|
||||||
@@ -709,15 +753,17 @@ read_frequency(void)
|
|||||||
double tick_term;
|
double tick_term;
|
||||||
double unscaled_freq;
|
double unscaled_freq;
|
||||||
double freq_term;
|
double freq_term;
|
||||||
|
long tick;
|
||||||
|
|
||||||
if (TMX_GetFrequency(&unscaled_freq) < 0) {
|
if (TMX_GetFrequency(&unscaled_freq, &tick) < 0) {
|
||||||
LOG_FATAL(LOGF_SysLinux, "adjtimex() failed");
|
LOG_FATAL(LOGF_SysLinux, "adjtimex() failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Use current_tick here rather than txc.tick, otherwise we're
|
if (fast_slewing) {
|
||||||
thrown off course when doing a fast slew (in which case, txc.tick
|
tick -= slewing_tick - current_tick;
|
||||||
is nowhere near the nominal value) */
|
}
|
||||||
tick_term = dhz * (double)(nominal_tick - current_tick);
|
|
||||||
|
tick_term = dhz * (double)(nominal_tick - tick);
|
||||||
freq_term = unscaled_freq / freq_scale;
|
freq_term = unscaled_freq / freq_scale;
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
@@ -754,29 +800,19 @@ get_offset_correction(struct timeval *raw,
|
|||||||
if (!slow_slewing) {
|
if (!slow_slewing) {
|
||||||
offset = 0;
|
offset = 0;
|
||||||
} else {
|
} else {
|
||||||
switch (have_readonly_adjtime) {
|
if (have_readonly_adjtime) {
|
||||||
case 2:
|
if (TMX_GetOffsetLeft(&offset) < 0) {
|
||||||
if (TMX_GetOffsetLeft(&offset) < 0) {
|
LOG_FATAL(LOGF_SysLinux, "adjtimex() failed");
|
||||||
LOG_FATAL(LOGF_SysLinux, "adjtimex() failed");
|
}
|
||||||
}
|
} else {
|
||||||
break;
|
toffset = 0;
|
||||||
case 0:
|
if (TMX_ApplyOffset(&toffset) < 0) {
|
||||||
toffset = 0;
|
LOG_FATAL(LOGF_SysLinux, "adjtimex() failed");
|
||||||
if (TMX_ApplyOffset(&toffset) < 0) {
|
}
|
||||||
LOG_FATAL(LOGF_SysLinux, "adjtimex() failed");
|
offset = toffset;
|
||||||
}
|
if (TMX_ApplyOffset(&toffset) < 0) {
|
||||||
offset = toffset;
|
LOG_FATAL(LOGF_SysLinux, "adjtimex() failed");
|
||||||
if (TMX_ApplyOffset(&toffset) < 0) {
|
}
|
||||||
LOG_FATAL(LOGF_SysLinux, "adjtimex() failed");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
if (TMX_GetOffsetLeftOld(&offset) < 0) {
|
|
||||||
LOG_FATAL(LOGF_SysLinux, "adjtimex() failed");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
assert(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (offset == 0) {
|
if (offset == 0) {
|
||||||
@@ -812,8 +848,6 @@ get_offset_correction(struct timeval *raw,
|
|||||||
update_nano_slew_error(noffset, 0);
|
update_nano_slew_error(noffset, 0);
|
||||||
*err = get_slow_slew_error(raw) + get_fast_slew_error(raw) + get_nano_slew_error();;
|
*err = get_slow_slew_error(raw) + get_fast_slew_error(raw) + get_nano_slew_error();;
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -827,8 +861,6 @@ set_leap(int leap)
|
|||||||
|
|
||||||
LOG(LOGS_INFO, LOGF_SysLinux, "System clock status set to %s leap second",
|
LOG(LOGS_INFO, LOGF_SysLinux, "System clock status set to %s leap second",
|
||||||
leap ? (leap > 0 ? "insert" : "delete") : "not insert/delete");
|
leap ? (leap > 0 ? "insert" : "delete") : "not insert/delete");
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -866,7 +898,43 @@ guess_hz_and_shift_hz(int tick, int *hz, int *shift_hz)
|
|||||||
/* oh dear. doomed. */
|
/* oh dear. doomed. */
|
||||||
*hz = 0;
|
*hz = 0;
|
||||||
*shift_hz = 0;
|
*shift_hz = 0;
|
||||||
return;
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static int
|
||||||
|
get_hz_and_shift_hz(int *hz, int *shift_hz)
|
||||||
|
{
|
||||||
|
#ifdef _SC_CLK_TCK
|
||||||
|
if ((*hz = sysconf(_SC_CLK_TCK)) < 1) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*hz == 100) {
|
||||||
|
*shift_hz = 7;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (*shift_hz = 1; (*hz >> *shift_hz) > 1; (*shift_hz)++)
|
||||||
|
;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
#else
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static int
|
||||||
|
kernelvercmp(int major1, int minor1, int patch1,
|
||||||
|
int major2, int minor2, int patch2)
|
||||||
|
{
|
||||||
|
if (major1 != major2)
|
||||||
|
return major1 - major2;
|
||||||
|
if (minor1 != minor2)
|
||||||
|
return minor1 - minor2;
|
||||||
|
return patch1 - patch2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -883,20 +951,23 @@ get_version_specific_details(void)
|
|||||||
int config_hz, set_config_hz; /* values of HZ from conf file */
|
int config_hz, set_config_hz; /* values of HZ from conf file */
|
||||||
int set_config_freq_scale;
|
int set_config_freq_scale;
|
||||||
double config_freq_scale;
|
double config_freq_scale;
|
||||||
double calculated_freq_scale;
|
|
||||||
struct tmx_params tmx_params;
|
struct tmx_params tmx_params;
|
||||||
struct utsname uts;
|
struct utsname uts;
|
||||||
|
|
||||||
TMX_ReadCurrentParams(&tmx_params);
|
if (!get_hz_and_shift_hz(&hz, &shift_hz)) {
|
||||||
|
TMX_ReadCurrentParams(&tmx_params);
|
||||||
|
|
||||||
guess_hz_and_shift_hz(tmx_params.tick, &hz, &shift_hz);
|
guess_hz_and_shift_hz(tmx_params.tick, &hz, &shift_hz);
|
||||||
|
|
||||||
if (!shift_hz) {
|
if (!shift_hz) {
|
||||||
LOG_FATAL(LOGF_SysLinux, "Can't determine hz (txc.tick=%ld txc.freq=%ld (%.8f) txc.offset=%ld)",
|
LOG_FATAL(LOGF_SysLinux, "Can't determine hz (txc.tick=%ld txc.freq=%ld (%.8f) txc.offset=%ld)",
|
||||||
tmx_params.tick, tmx_params.freq, tmx_params.dfreq, tmx_params.offset);
|
tmx_params.tick, tmx_params.freq, tmx_params.dfreq, tmx_params.offset);
|
||||||
} else {
|
} else {
|
||||||
LOG(LOGS_INFO, LOGF_SysLinux, "Initial txc.tick=%ld txc.freq=%ld (%.8f) txc.offset=%ld => hz=%d shift_hz=%d",
|
#if 0
|
||||||
tmx_params.tick, tmx_params.freq, tmx_params.dfreq, tmx_params.offset, hz, shift_hz);
|
LOG(LOGS_INFO, LOGF_SysLinux, "Initial txc.tick=%ld txc.freq=%ld (%.8f) txc.offset=%ld => hz=%d shift_hz=%d",
|
||||||
|
tmx_params.tick, tmx_params.freq, tmx_params.dfreq, tmx_params.offset, hz, shift_hz);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CNF_GetLinuxHz(&set_config_hz, &config_hz);
|
CNF_GetLinuxHz(&set_config_hz, &config_hz);
|
||||||
@@ -912,10 +983,6 @@ get_version_specific_details(void)
|
|||||||
max_tick_bias = nominal_tick / 10;
|
max_tick_bias = nominal_tick / 10;
|
||||||
tick_update_hz = hz;
|
tick_update_hz = hz;
|
||||||
|
|
||||||
LOG(LOGS_INFO, LOGF_SysLinux, "set_config_hz=%d hz=%d shift_hz=%d basic_freq_scale=%.8f nominal_tick=%d slew_delta_tick=%d max_tick_bias=%d",
|
|
||||||
set_config_hz, hz, shift_hz, basic_freq_scale, nominal_tick, slew_delta_tick, max_tick_bias);
|
|
||||||
|
|
||||||
|
|
||||||
/* The basic_freq_scale comes from:
|
/* The basic_freq_scale comes from:
|
||||||
* the kernel increments the usec counter HZ times per second (if the timer
|
* the kernel increments the usec counter HZ times per second (if the timer
|
||||||
interrupt period were perfect)
|
interrupt period were perfect)
|
||||||
@@ -946,7 +1013,9 @@ get_version_specific_details(void)
|
|||||||
if (uname(&uts) < 0) {
|
if (uname(&uts) < 0) {
|
||||||
LOG_FATAL(LOGF_SysLinux, "Cannot uname(2) to get kernel version, sorry.");
|
LOG_FATAL(LOGF_SysLinux, "Cannot uname(2) to get kernel version, sorry.");
|
||||||
}
|
}
|
||||||
if (sscanf(uts.release, "%d.%d.%d", &major, &minor, &patch) != 3) {
|
|
||||||
|
patch = 0;
|
||||||
|
if (sscanf(uts.release, "%d.%d.%d", &major, &minor, &patch) < 2) {
|
||||||
LOG_FATAL(LOGF_SysLinux, "Cannot read information from uname, sorry");
|
LOG_FATAL(LOGF_SysLinux, "Cannot read information from uname, sorry");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -956,101 +1025,60 @@ get_version_specific_details(void)
|
|||||||
version_minor = minor;
|
version_minor = minor;
|
||||||
version_patchlevel = patch;
|
version_patchlevel = patch;
|
||||||
|
|
||||||
have_nanopll = 0;
|
if (kernelvercmp(major, minor, patch, 2, 2, 0) < 0) {
|
||||||
|
LOG_FATAL(LOGF_SysLinux, "Kernel version not supported, sorry.");
|
||||||
|
}
|
||||||
|
|
||||||
switch (major) {
|
if (kernelvercmp(major, minor, patch, 2, 6, 27) < 0) {
|
||||||
case 1:
|
freq_scale = (hz == 100) ? (128.0 / 128.125) : basic_freq_scale;
|
||||||
/* Does Linux v1.x even support HZ!=100? */
|
} else {
|
||||||
switch (minor) {
|
/* These don't seem to need scaling */
|
||||||
case 2:
|
freq_scale = 1.0;
|
||||||
if (patch == 13) {
|
|
||||||
freq_scale = (hz==100) ? (128.0 / 100.0) : basic_freq_scale ; /* I _think_! */
|
|
||||||
have_readonly_adjtime = 1;
|
|
||||||
} else {
|
|
||||||
LOG_FATAL(LOGF_SysLinux, "Kernel version not supported yet, sorry.");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
/* I guess the change from the 1.2.x scaling to the 2.0.x
|
|
||||||
scaling must have happened during 1.3 development. I
|
|
||||||
haven't a clue where though, until someone looks it
|
|
||||||
up. */
|
|
||||||
LOG_FATAL(LOGF_SysLinux, "Kernel version not supported yet, sorry.");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
LOG_FATAL(LOGF_SysLinux, "Kernel version not supported yet, sorry.");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
switch (minor) {
|
|
||||||
case 0:
|
|
||||||
if (patch < 32) {
|
|
||||||
freq_scale = (hz==100) ? (128.0 / 125.0) : basic_freq_scale;
|
|
||||||
have_readonly_adjtime = 1;
|
|
||||||
} else if (patch >= 32) {
|
|
||||||
freq_scale = (hz==100) ? (128.0 / 128.125) : basic_freq_scale;
|
|
||||||
|
|
||||||
/* The functionality in kernel/time.c in the kernel source
|
if (kernelvercmp(major, minor, patch, 2, 6, 33) < 0) {
|
||||||
was modified with regard to what comes back in the
|
/* Tickless kernels before 2.6.33 accumulated ticks only in
|
||||||
txc.offset field on return from adjtimex. If txc.modes
|
half-second intervals */
|
||||||
was ADJ_OFFSET_SINGLESHOT on entry, the outstanding
|
tick_update_hz = 2;
|
||||||
adjustment is returned, however the running offset will
|
}
|
||||||
be modified to the passed value. */
|
}
|
||||||
have_readonly_adjtime = 0;
|
|
||||||
}
|
/* ADJ_OFFSET_SS_READ support. It's available since 2.6.24,
|
||||||
break;
|
but was buggy until 2.6.28. */
|
||||||
case 1:
|
if (kernelvercmp(major, minor, patch, 2, 6, 28) < 0) {
|
||||||
/* I know that earlier 2.1 kernels were like 2.0.31, hence
|
have_readonly_adjtime = 0;
|
||||||
the settings below. However, the 2.0.32 behaviour may
|
} else {
|
||||||
have been added late in the 2.1 series, however I have no
|
have_readonly_adjtime = 1;
|
||||||
idea at which patch level. Leave it like this until
|
}
|
||||||
someone supplies some info. */
|
|
||||||
freq_scale = (hz==100) ? (128.0 / 125.0) : basic_freq_scale;
|
/* ADJ_NANO support */
|
||||||
have_readonly_adjtime = 0; /* For safety ! */
|
if (kernelvercmp(major, minor, patch, 2, 6, 27) < 0) {
|
||||||
break;
|
have_nanopll = 0;
|
||||||
case 2:
|
} else {
|
||||||
case 3:
|
have_nanopll = 1;
|
||||||
case 4:
|
}
|
||||||
case 5:
|
|
||||||
case 6:
|
/* ADJ_SETOFFSET support */
|
||||||
if (minor < 6 || patch < 27) {
|
if (kernelvercmp(major, minor, patch, 2, 6, 39) < 0) {
|
||||||
/* These seem to be like 2.0.32 */
|
have_setoffset = 0;
|
||||||
freq_scale = (hz==100) ? (128.0 / 128.125) : basic_freq_scale;
|
} else {
|
||||||
have_readonly_adjtime = 0;
|
have_setoffset = 1;
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
if (patch < 33) {
|
/* PLL time constant changed in 2.6.31 */
|
||||||
/* Tickless kernels before 2.6.33 accumulated ticks only in
|
if (kernelvercmp(major, minor, patch, 2, 6, 31) < 0) {
|
||||||
half-second intervals. */
|
shift_pll = 4;
|
||||||
tick_update_hz = 2;
|
} else {
|
||||||
}
|
shift_pll = 2;
|
||||||
/* Let's be optimistic that these will be the same until proven
|
|
||||||
otherwise :-) */
|
|
||||||
case 7:
|
|
||||||
case 8:
|
|
||||||
/* These don't seem to need scaling */
|
|
||||||
freq_scale = 1.0;
|
|
||||||
have_readonly_adjtime = 2;
|
|
||||||
have_nanopll = 1;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
LOG_FATAL(LOGF_SysLinux, "Kernel version not supported yet, sorry.");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
LOG_FATAL(LOGF_SysLinux, "Kernel's major version not supported yet, sorry");
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Override freq_scale if it appears in conf file */
|
/* Override freq_scale if it appears in conf file */
|
||||||
CNF_GetLinuxFreqScale(&set_config_freq_scale, &config_freq_scale);
|
CNF_GetLinuxFreqScale(&set_config_freq_scale, &config_freq_scale);
|
||||||
calculated_freq_scale = freq_scale;
|
if (set_config_freq_scale) {
|
||||||
if (set_config_freq_scale) freq_scale = config_freq_scale;
|
freq_scale = config_freq_scale;
|
||||||
|
}
|
||||||
LOG(LOGS_INFO, LOGF_SysLinux, "calculated_freq_scale=%.8f freq_scale=%.8f",
|
|
||||||
calculated_freq_scale, freq_scale);
|
|
||||||
|
|
||||||
|
LOG(LOGS_INFO, LOGF_SysLinux, "hz=%d shift_hz=%d freq_scale=%.8f nominal_tick=%d slew_delta_tick=%d max_tick_bias=%d shift_pll=%d",
|
||||||
|
hz, shift_hz, freq_scale, nominal_tick, slew_delta_tick, max_tick_bias, shift_pll);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -1060,25 +1088,19 @@ void
|
|||||||
SYS_Linux_Initialise(void)
|
SYS_Linux_Initialise(void)
|
||||||
{
|
{
|
||||||
long offset;
|
long offset;
|
||||||
|
double freq;
|
||||||
|
|
||||||
offset_register = 0.0;
|
offset_register = 0.0;
|
||||||
fast_slewing = 0;
|
fast_slewing = 0;
|
||||||
|
|
||||||
get_version_specific_details();
|
get_version_specific_details();
|
||||||
|
|
||||||
current_tick = nominal_tick;
|
|
||||||
current_total_tick = 1.0 / dhz;
|
|
||||||
|
|
||||||
lcl_RegisterSystemDrivers(read_frequency, set_frequency,
|
|
||||||
accrue_offset, apply_step_offset,
|
|
||||||
get_offset_correction, set_leap);
|
|
||||||
|
|
||||||
offset = 0;
|
offset = 0;
|
||||||
if (TMX_ApplyOffset(&offset) < 0) {
|
if (TMX_ApplyOffset(&offset) < 0) {
|
||||||
LOG_FATAL(LOGF_SysLinux, "adjtimex() failed");
|
LOG_FATAL(LOGF_SysLinux, "adjtimex() failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (have_readonly_adjtime == 2 && (TMX_GetOffsetLeft(&offset) < 0 || offset)) {
|
if (have_readonly_adjtime && (TMX_GetOffsetLeft(&offset) < 0 || offset)) {
|
||||||
LOG(LOGS_INFO, LOGF_SysLinux, "adjtimex() doesn't support ADJ_OFFSET_SS_READ");
|
LOG(LOGS_INFO, LOGF_SysLinux, "adjtimex() doesn't support ADJ_OFFSET_SS_READ");
|
||||||
have_readonly_adjtime = 0;
|
have_readonly_adjtime = 0;
|
||||||
}
|
}
|
||||||
@@ -1088,7 +1110,20 @@ SYS_Linux_Initialise(void)
|
|||||||
have_nanopll = 0;
|
have_nanopll = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (have_setoffset && TMX_TestStepOffset() < 0) {
|
||||||
|
LOG(LOGS_INFO, LOGF_SysLinux, "adjtimex() doesn't support ADJ_SETOFFSET");
|
||||||
|
have_setoffset = 0;
|
||||||
|
}
|
||||||
|
|
||||||
TMX_SetSync(CNF_GetRTCSync());
|
TMX_SetSync(CNF_GetRTCSync());
|
||||||
|
|
||||||
|
/* Read current kernel frequency */
|
||||||
|
TMX_GetFrequency(&freq, ¤t_tick);
|
||||||
|
current_total_tick = (current_tick + freq / freq_scale / dhz) / 1.0e6;
|
||||||
|
|
||||||
|
lcl_RegisterSystemDrivers(read_frequency, set_frequency,
|
||||||
|
accrue_offset, apply_step_offset,
|
||||||
|
get_offset_correction, set_leap);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -1104,16 +1139,6 @@ SYS_Linux_Finalise(void)
|
|||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
void
|
|
||||||
SYS_Linux_GetKernelVersion(int *major, int *minor, int *patchlevel)
|
|
||||||
{
|
|
||||||
*major = version_major;
|
|
||||||
*minor = version_minor;
|
|
||||||
*patchlevel = version_patchlevel;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ================================================== */
|
|
||||||
|
|
||||||
#ifdef FEAT_LINUXCAPS
|
#ifdef FEAT_LINUXCAPS
|
||||||
void
|
void
|
||||||
SYS_Linux_DropRoot(char *user)
|
SYS_Linux_DropRoot(char *user)
|
||||||
@@ -1154,7 +1179,9 @@ SYS_Linux_DropRoot(char *user)
|
|||||||
|
|
||||||
cap_free(cap);
|
cap_free(cap);
|
||||||
|
|
||||||
|
#if 0
|
||||||
LOG(LOGS_INFO, LOGF_SysLinux, "Privileges dropped to user %s", user);
|
LOG(LOGS_INFO, LOGF_SysLinux, "Privileges dropped to user %s", user);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -1183,7 +1210,9 @@ void SYS_Linux_SetScheduler(int SchedPriority)
|
|||||||
LOG(LOGS_ERR, LOGF_SysLinux, "sched_setscheduler() failed");
|
LOG(LOGS_ERR, LOGF_SysLinux, "sched_setscheduler() failed");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
#if 0
|
||||||
LOG(LOGS_INFO, LOGF_SysLinux, "Enabled SCHED_FIFO with priority %d", sched.sched_priority);
|
LOG(LOGS_INFO, LOGF_SysLinux, "Enabled SCHED_FIFO with priority %d", sched.sched_priority);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1207,15 +1236,11 @@ void SYS_Linux_MemLockAll(int LockAll)
|
|||||||
LOG(LOGS_ERR, LOGF_SysLinux, "mlockall() failed");
|
LOG(LOGS_ERR, LOGF_SysLinux, "mlockall() failed");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
#if 0
|
||||||
LOG(LOGS_INFO, LOGF_SysLinux, "Successfully locked into RAM");
|
LOG(LOGS_INFO, LOGF_SysLinux, "Successfully locked into RAM");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /* HAVE_MLOCKALL */
|
#endif /* HAVE_MLOCKALL */
|
||||||
|
|
||||||
#endif /* LINUX */
|
|
||||||
|
|
||||||
/* vim:ts=8
|
|
||||||
* */
|
|
||||||
|
|
||||||
|
|||||||
@@ -31,8 +31,6 @@ extern void SYS_Linux_Initialise(void);
|
|||||||
|
|
||||||
extern void SYS_Linux_Finalise(void);
|
extern void SYS_Linux_Finalise(void);
|
||||||
|
|
||||||
extern void SYS_Linux_GetKernelVersion(int *major, int *minor, int *patchlevel);
|
|
||||||
|
|
||||||
extern void SYS_Linux_DropRoot(char *user);
|
extern void SYS_Linux_DropRoot(char *user);
|
||||||
|
|
||||||
extern void SYS_Linux_MemLockAll(int LockAll);
|
extern void SYS_Linux_MemLockAll(int LockAll);
|
||||||
|
|||||||
@@ -25,6 +25,8 @@
|
|||||||
Driver file for the NetBSD operating system.
|
Driver file for the NetBSD operating system.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
#ifdef __NetBSD__
|
#ifdef __NetBSD__
|
||||||
|
|
||||||
#include <kvm.h>
|
#include <kvm.h>
|
||||||
@@ -197,7 +199,7 @@ stop_adjust(void)
|
|||||||
slew backwards */
|
slew backwards */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
accrue_offset(double offset)
|
accrue_offset(double offset, double corr_rate)
|
||||||
{
|
{
|
||||||
stop_adjust();
|
stop_adjust();
|
||||||
offset_register += offset;
|
offset_register += offset;
|
||||||
|
|||||||
@@ -24,6 +24,8 @@
|
|||||||
Driver file for Solaris operating system
|
Driver file for Solaris operating system
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
#ifdef SOLARIS
|
#ifdef SOLARIS
|
||||||
|
|
||||||
#include <kvm.h>
|
#include <kvm.h>
|
||||||
@@ -108,8 +110,6 @@ clock_initialise(void)
|
|||||||
if (adjtime(&newadj, &oldadj) < 0) {
|
if (adjtime(&newadj, &oldadj) < 0) {
|
||||||
LOG_FATAL(LOGF_SysSolaris, "adjtime() failed");
|
LOG_FATAL(LOGF_SysSolaris, "adjtime() failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -118,9 +118,6 @@ static void
|
|||||||
clock_finalise(void)
|
clock_finalise(void)
|
||||||
{
|
{
|
||||||
/* Nothing to do yet */
|
/* Nothing to do yet */
|
||||||
|
|
||||||
return;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -210,12 +207,11 @@ stop_adjust(void)
|
|||||||
slew backwards */
|
slew backwards */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
accrue_offset(double offset)
|
accrue_offset(double offset, double corr_rate)
|
||||||
{
|
{
|
||||||
stop_adjust();
|
stop_adjust();
|
||||||
offset_register += offset;
|
offset_register += offset;
|
||||||
start_adjust();
|
start_adjust();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -294,7 +290,6 @@ get_offset_correction(struct timeval *raw,
|
|||||||
start_adjust();
|
start_adjust();
|
||||||
if (err)
|
if (err)
|
||||||
*err = 0.0;
|
*err = 0.0;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -302,7 +297,6 @@ get_offset_correction(struct timeval *raw,
|
|||||||
static void
|
static void
|
||||||
immediate_step(void)
|
immediate_step(void)
|
||||||
{
|
{
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -466,8 +460,6 @@ SYS_Solaris_Finalise(void)
|
|||||||
if (need_dosynctodr) {
|
if (need_dosynctodr) {
|
||||||
set_dosynctodr(1);
|
set_dosynctodr(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|||||||
14
sys_sunos.c
14
sys_sunos.c
@@ -24,6 +24,8 @@
|
|||||||
Driver file for the SunOS 4.1.x operating system.
|
Driver file for the SunOS 4.1.x operating system.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
#ifdef SUNOS
|
#ifdef SUNOS
|
||||||
|
|
||||||
#include <kvm.h>
|
#include <kvm.h>
|
||||||
@@ -99,8 +101,6 @@ clock_initialise(void)
|
|||||||
if (adjtime(&newadj, &oldadj) < 0) {
|
if (adjtime(&newadj, &oldadj) < 0) {
|
||||||
LOG_FATAL(LOGF_SysSunOS, "adjtime() failed");
|
LOG_FATAL(LOGF_SysSunOS, "adjtime() failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -109,9 +109,6 @@ static void
|
|||||||
clock_finalise(void)
|
clock_finalise(void)
|
||||||
{
|
{
|
||||||
/* Nothing to do yet */
|
/* Nothing to do yet */
|
||||||
|
|
||||||
return;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -214,12 +211,11 @@ stop_adjust(void)
|
|||||||
slew backwards */
|
slew backwards */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
accrue_offset(double offset)
|
accrue_offset(double offset, double corr_rate)
|
||||||
{
|
{
|
||||||
stop_adjust();
|
stop_adjust();
|
||||||
offset_register += offset;
|
offset_register += offset;
|
||||||
start_adjust();
|
start_adjust();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -281,7 +277,6 @@ get_offset_correction(struct timeval *raw,
|
|||||||
start_adjust();
|
start_adjust();
|
||||||
if (err)
|
if (err)
|
||||||
*err = 0.0;
|
*err = 0.0;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -289,7 +284,6 @@ get_offset_correction(struct timeval *raw,
|
|||||||
static void
|
static void
|
||||||
immediate_step(void)
|
immediate_step(void)
|
||||||
{
|
{
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -418,8 +412,6 @@ SYS_SunOS_Finalise(void)
|
|||||||
/* When exiting, we want to return the machine to its 'autonomous'
|
/* When exiting, we want to return the machine to its 'autonomous'
|
||||||
tracking mode */
|
tracking mode */
|
||||||
setup_kernel(1);
|
setup_kernel(1);
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|||||||
@@ -45,6 +45,7 @@
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
|
#include <resolv.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
@@ -56,6 +57,8 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <sys/un.h>
|
||||||
|
#include <sys/shm.h>
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
@@ -86,10 +89,6 @@
|
|||||||
#include <nlist.h>
|
#include <nlist.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined (HAS_NO_BZERO)
|
|
||||||
#define bzero(ptr,n) memset(ptr,0,n)
|
|
||||||
#endif /* HAS_NO_BZERO */
|
|
||||||
|
|
||||||
#if defined (WINNT)
|
#if defined (WINNT)
|
||||||
|
|
||||||
/* Designed to work with the GCC from the GNAT-3.10 for Win32
|
/* Designed to work with the GCC from the GNAT-3.10 for Win32
|
||||||
|
|||||||
@@ -25,6 +25,8 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
#include "local.h"
|
#include "local.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
|
|||||||
155
util.c
155
util.c
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
* Copyright (C) Richard P. Curnow 1997-2003
|
* Copyright (C) Richard P. Curnow 1997-2003
|
||||||
* Copyright (C) Miroslav Lichvar 2009
|
* Copyright (C) Miroslav Lichvar 2009, 2012-2013
|
||||||
*
|
*
|
||||||
* 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
|
||||||
@@ -25,10 +25,12 @@
|
|||||||
Various utility functions
|
Various utility functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
#include "sysincl.h"
|
#include "sysincl.h"
|
||||||
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "md5.h"
|
#include "hash.h"
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
@@ -105,8 +107,6 @@ UTI_DiffTimevals(struct timeval *result,
|
|||||||
(0,1000000) */
|
(0,1000000) */
|
||||||
|
|
||||||
UTI_NormaliseTimeval(result); /* JGH */
|
UTI_NormaliseTimeval(result); /* JGH */
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
@@ -135,7 +135,8 @@ UTI_AddDoubleToTimeval(struct timeval *start,
|
|||||||
is too marginal here. */
|
is too marginal here. */
|
||||||
|
|
||||||
int_part = (long) increment;
|
int_part = (long) increment;
|
||||||
frac_part = (long) (0.5 + 1.0e6 * (increment - (double)int_part));
|
increment = (increment - int_part) * 1.0e6;
|
||||||
|
frac_part = (long) (increment > 0.0 ? increment + 0.5 : increment - 0.5);
|
||||||
|
|
||||||
end->tv_sec = int_part + start->tv_sec;
|
end->tv_sec = int_part + start->tv_sec;
|
||||||
end->tv_usec = frac_part + start->tv_usec;
|
end->tv_usec = frac_part + start->tv_usec;
|
||||||
@@ -187,6 +188,18 @@ UTI_AverageDiffTimevals (struct timeval *earlier,
|
|||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
|
void
|
||||||
|
UTI_AddDiffToTimeval(struct timeval *a, struct timeval *b,
|
||||||
|
struct timeval *c, struct timeval *result)
|
||||||
|
{
|
||||||
|
double diff;
|
||||||
|
|
||||||
|
UTI_DiffTimevalsToDouble(&diff, a, b);
|
||||||
|
UTI_AddDoubleToTimeval(c, diff, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
#define POOL_ENTRIES 16
|
#define POOL_ENTRIES 16
|
||||||
#define BUFFER_LENGTH 64
|
#define BUFFER_LENGTH 64
|
||||||
static char buffer_pool[POOL_ENTRIES][BUFFER_LENGTH];
|
static char buffer_pool[POOL_ENTRIES][BUFFER_LENGTH];
|
||||||
@@ -210,19 +223,6 @@ UTI_TimevalToString(struct timeval *tv)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
|
||||||
#define JAN_1970 0x83aa7e80UL
|
|
||||||
|
|
||||||
inline static void
|
|
||||||
int64_to_timeval(NTP_int64 *src,
|
|
||||||
struct timeval *dest)
|
|
||||||
{
|
|
||||||
dest->tv_sec = ntohl(src->hi) - JAN_1970;
|
|
||||||
|
|
||||||
/* Until I invent a slick way to do this, just do it the obvious way */
|
|
||||||
dest->tv_usec = (int)(0.5 + (double)(ntohl(src->lo)) / 4294.967296);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
/* Convert an NTP timestamp into a temporary string, largely
|
/* Convert an NTP timestamp into a temporary string, largely
|
||||||
for diagnostic display */
|
for diagnostic display */
|
||||||
@@ -231,14 +231,14 @@ char *
|
|||||||
UTI_TimestampToString(NTP_int64 *ts)
|
UTI_TimestampToString(NTP_int64 *ts)
|
||||||
{
|
{
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
int64_to_timeval(ts, &tv);
|
UTI_Int64ToTimeval(ts, &tv);
|
||||||
return UTI_TimevalToString(&tv);
|
return UTI_TimevalToString(&tv);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
char *
|
char *
|
||||||
UTI_RefidToString(unsigned long ref_id)
|
UTI_RefidToString(uint32_t ref_id)
|
||||||
{
|
{
|
||||||
unsigned int i, j, c;
|
unsigned int i, j, c;
|
||||||
char buf[5], *result;
|
char buf[5], *result;
|
||||||
@@ -331,19 +331,27 @@ UTI_StringToIP(const char *addr, IPAddr *ip)
|
|||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
unsigned long
|
uint32_t
|
||||||
UTI_IPToRefid(IPAddr *ip)
|
UTI_IPToRefid(IPAddr *ip)
|
||||||
{
|
{
|
||||||
MD5_CTX ctx;
|
static int MD5_hash = -1;
|
||||||
|
unsigned char buf[16];
|
||||||
|
|
||||||
switch (ip->family) {
|
switch (ip->family) {
|
||||||
case IPADDR_INET4:
|
case IPADDR_INET4:
|
||||||
return ip->addr.in4;
|
return ip->addr.in4;
|
||||||
case IPADDR_INET6:
|
case IPADDR_INET6:
|
||||||
MD5Init(&ctx);
|
if (MD5_hash < 0) {
|
||||||
MD5Update(&ctx, (unsigned const char *) ip->addr.in6, sizeof (ip->addr.in6));
|
MD5_hash = HSH_GetHashId("MD5");
|
||||||
MD5Final(&ctx);
|
assert(MD5_hash >= 0);
|
||||||
return ctx.digest[0] << 24 | ctx.digest[1] << 16 | ctx.digest[2] << 8 | ctx.digest[3];
|
}
|
||||||
|
|
||||||
|
if (HSH_Hash(MD5_hash, (unsigned const char *)ip->addr.in6, sizeof
|
||||||
|
(ip->addr.in6), NULL, 0, buf, 16) != 16) {
|
||||||
|
assert(0);
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
return buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3];
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -449,16 +457,53 @@ UTI_AdjustTimeval(struct timeval *old_tv, struct timeval *when, struct timeval *
|
|||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
|
uint32_t
|
||||||
|
UTI_GetNTPTsFuzz(int precision)
|
||||||
|
{
|
||||||
|
uint32_t fuzz;
|
||||||
|
int fuzz_bits;
|
||||||
|
|
||||||
|
fuzz_bits = 32 - 1 + precision;
|
||||||
|
fuzz = random() % (1 << fuzz_bits);
|
||||||
|
|
||||||
|
return fuzz;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
double
|
||||||
|
UTI_Int32ToDouble(NTP_int32 x)
|
||||||
|
{
|
||||||
|
return (double) ntohl(x) / 65536.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
#define MAX_NTP_INT32 (4294967295.0 / 65536.0)
|
||||||
|
|
||||||
|
NTP_int32
|
||||||
|
UTI_DoubleToInt32(double x)
|
||||||
|
{
|
||||||
|
if (x > MAX_NTP_INT32)
|
||||||
|
x = MAX_NTP_INT32;
|
||||||
|
else if (x < 0)
|
||||||
|
x = 0.0;
|
||||||
|
return htonl((NTP_int32)(0.5 + 65536.0 * x));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
/* Seconds part of RFC1305 timestamp correponding to the origin of the
|
/* Seconds part of RFC1305 timestamp correponding to the origin of the
|
||||||
struct timeval format. */
|
struct timeval format. */
|
||||||
#define JAN_1970 0x83aa7e80UL
|
#define JAN_1970 0x83aa7e80UL
|
||||||
|
|
||||||
void
|
void
|
||||||
UTI_TimevalToInt64(struct timeval *src,
|
UTI_TimevalToInt64(struct timeval *src,
|
||||||
NTP_int64 *dest)
|
NTP_int64 *dest, uint32_t fuzz)
|
||||||
{
|
{
|
||||||
unsigned long usec = src->tv_usec;
|
unsigned long usec = src->tv_usec;
|
||||||
unsigned long sec = src->tv_sec;
|
unsigned long sec = src->tv_sec;
|
||||||
|
uint32_t lo;
|
||||||
|
|
||||||
/* Recognize zero as a special case - it always signifies
|
/* Recognize zero as a special case - it always signifies
|
||||||
an 'unknown' value */
|
an 'unknown' value */
|
||||||
@@ -468,7 +513,12 @@ UTI_TimevalToInt64(struct timeval *src,
|
|||||||
dest->hi = htonl(src->tv_sec + JAN_1970);
|
dest->hi = htonl(src->tv_sec + JAN_1970);
|
||||||
|
|
||||||
/* This formula gives an error of about 0.1us worst case */
|
/* This formula gives an error of about 0.1us worst case */
|
||||||
dest->lo = htonl(4295 * usec - (usec>>5) - (usec>>9));
|
lo = 4295 * usec - (usec>>5) - (usec>>9);
|
||||||
|
|
||||||
|
/* Add the fuzz */
|
||||||
|
lo ^= fuzz;
|
||||||
|
|
||||||
|
dest->lo = htonl(lo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -610,3 +660,52 @@ UTI_FdSetCloexec(int fd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
UTI_GenerateNTPAuth(int hash_id, const unsigned char *key, int key_len,
|
||||||
|
const unsigned char *data, int data_len, unsigned char *auth, int auth_len)
|
||||||
|
{
|
||||||
|
return HSH_Hash(hash_id, key, key_len, data, data_len, auth, auth_len);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
UTI_CheckNTPAuth(int hash_id, const unsigned char *key, int key_len,
|
||||||
|
const unsigned char *data, int data_len, const unsigned char *auth, int auth_len)
|
||||||
|
{
|
||||||
|
unsigned char buf[MAX_HASH_LENGTH];
|
||||||
|
|
||||||
|
return UTI_GenerateNTPAuth(hash_id, key, key_len, data, data_len,
|
||||||
|
buf, sizeof (buf)) == auth_len && !memcmp(buf, auth, auth_len);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
UTI_DecodePasswordFromText(char *key)
|
||||||
|
{
|
||||||
|
int i, j, len = strlen(key);
|
||||||
|
char buf[3], *p;
|
||||||
|
|
||||||
|
if (!strncmp(key, "ASCII:", 6)) {
|
||||||
|
memmove(key, key + 6, len - 6);
|
||||||
|
return len - 6;
|
||||||
|
} else if (!strncmp(key, "HEX:", 4)) {
|
||||||
|
if ((len - 4) % 2)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
for (i = 0, j = 4; j + 1 < len; i++, j += 2) {
|
||||||
|
buf[0] = key[j], buf[1] = key[j + 1], buf[2] = '\0';
|
||||||
|
key[i] = strtol(buf, &p, 16);
|
||||||
|
|
||||||
|
if (p != buf + 2)
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return i;
|
||||||
|
} else {
|
||||||
|
/* assume ASCII */
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
23
util.h
23
util.h
@@ -32,6 +32,7 @@
|
|||||||
#include "addressing.h"
|
#include "addressing.h"
|
||||||
#include "ntp.h"
|
#include "ntp.h"
|
||||||
#include "candm.h"
|
#include "candm.h"
|
||||||
|
#include "hash.h"
|
||||||
|
|
||||||
/* Convert a timeval into a floating point number of seconds */
|
/* Convert a timeval into a floating point number of seconds */
|
||||||
extern void UTI_TimevalToDouble(struct timeval *a, double *b);
|
extern void UTI_TimevalToDouble(struct timeval *a, double *b);
|
||||||
@@ -62,6 +63,9 @@ extern void UTI_AddDoubleToTimeval(struct timeval *start, double increment, stru
|
|||||||
/* Calculate the average and difference (as a double) of two timevals */
|
/* Calculate the average and difference (as a double) of two timevals */
|
||||||
extern void UTI_AverageDiffTimevals(struct timeval *earlier, struct timeval *later, struct timeval *average, double *diff);
|
extern void UTI_AverageDiffTimevals(struct timeval *earlier, struct timeval *later, struct timeval *average, double *diff);
|
||||||
|
|
||||||
|
/* Calculate result = a - b + c */
|
||||||
|
extern void UTI_AddDiffToTimeval(struct timeval *a, struct timeval *b, struct timeval *c, struct timeval *result);
|
||||||
|
|
||||||
/* Convert a timeval into a temporary string, largely for diagnostic
|
/* Convert a timeval into a temporary string, largely for diagnostic
|
||||||
display */
|
display */
|
||||||
extern char *UTI_TimevalToString(struct timeval *tv);
|
extern char *UTI_TimevalToString(struct timeval *tv);
|
||||||
@@ -71,13 +75,13 @@ extern char *UTI_TimevalToString(struct timeval *tv);
|
|||||||
extern char *UTI_TimestampToString(NTP_int64 *ts);
|
extern char *UTI_TimestampToString(NTP_int64 *ts);
|
||||||
|
|
||||||
/* Convert ref_id into a temporary string, for diagnostics */
|
/* Convert ref_id into a temporary string, for diagnostics */
|
||||||
extern char *UTI_RefidToString(unsigned long ref_id);
|
extern char *UTI_RefidToString(uint32_t ref_id);
|
||||||
|
|
||||||
/* Convert an IP address to string, for diagnostics */
|
/* Convert an IP address to string, for diagnostics */
|
||||||
extern char *UTI_IPToString(IPAddr *ip);
|
extern char *UTI_IPToString(IPAddr *ip);
|
||||||
|
|
||||||
extern int UTI_StringToIP(const char *addr, IPAddr *ip);
|
extern int UTI_StringToIP(const char *addr, IPAddr *ip);
|
||||||
extern unsigned long UTI_IPToRefid(IPAddr *ip);
|
extern uint32_t UTI_IPToRefid(IPAddr *ip);
|
||||||
extern void UTI_IPHostToNetwork(IPAddr *src, IPAddr *dest);
|
extern void UTI_IPHostToNetwork(IPAddr *src, IPAddr *dest);
|
||||||
extern void UTI_IPNetworkToHost(IPAddr *src, IPAddr *dest);
|
extern void UTI_IPNetworkToHost(IPAddr *src, IPAddr *dest);
|
||||||
extern int UTI_CompareIPs(IPAddr *a, IPAddr *b, IPAddr *mask);
|
extern int UTI_CompareIPs(IPAddr *a, IPAddr *b, IPAddr *mask);
|
||||||
@@ -87,8 +91,13 @@ extern char *UTI_TimeToLogForm(time_t t);
|
|||||||
/* Adjust time following a frequency/offset change */
|
/* Adjust time following a frequency/offset change */
|
||||||
extern void UTI_AdjustTimeval(struct timeval *old_tv, struct timeval *when, struct timeval *new_tv, double *delta, double dfreq, double doffset);
|
extern void UTI_AdjustTimeval(struct timeval *old_tv, struct timeval *when, struct timeval *new_tv, double *delta, double dfreq, double doffset);
|
||||||
|
|
||||||
|
/* Get a random value to fuzz an NTP timestamp in the given precision */
|
||||||
|
extern uint32_t UTI_GetNTPTsFuzz(int precision);
|
||||||
|
|
||||||
extern void UTI_TimevalToInt64(struct timeval *src, NTP_int64 *dest);
|
extern double UTI_Int32ToDouble(NTP_int32 x);
|
||||||
|
extern NTP_int32 UTI_DoubleToInt32(double x);
|
||||||
|
|
||||||
|
extern void UTI_TimevalToInt64(struct timeval *src, NTP_int64 *dest, uint32_t fuzz);
|
||||||
|
|
||||||
extern void UTI_Int64ToTimeval(NTP_int64 *src, struct timeval *dest);
|
extern void UTI_Int64ToTimeval(NTP_int64 *src, struct timeval *dest);
|
||||||
|
|
||||||
@@ -101,6 +110,14 @@ extern Float UTI_FloatHostToNetwork(double x);
|
|||||||
/* Set FD_CLOEXEC on descriptor */
|
/* Set FD_CLOEXEC on descriptor */
|
||||||
extern void UTI_FdSetCloexec(int fd);
|
extern void UTI_FdSetCloexec(int fd);
|
||||||
|
|
||||||
|
extern int UTI_GenerateNTPAuth(int hash_id, const unsigned char *key, int key_len,
|
||||||
|
const unsigned char *data, int data_len, unsigned char *auth, int auth_len);
|
||||||
|
extern int UTI_CheckNTPAuth(int hash_id, const unsigned char *key, int key_len,
|
||||||
|
const unsigned char *data, int data_len, const unsigned char *auth, int auth_len);
|
||||||
|
|
||||||
|
/* Decode password encoded in ASCII or HEX */
|
||||||
|
extern int UTI_DecodePasswordFromText(char *key);
|
||||||
|
|
||||||
#if defined (INLINE_UTILITIES)
|
#if defined (INLINE_UTILITIES)
|
||||||
#define INLINE_STATIC inline static
|
#define INLINE_STATIC inline static
|
||||||
#include "util.c"
|
#include "util.c"
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
DEVELOPMENT
|
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
* Copyright (C) Richard P. Curnow 1997-2002
|
* Copyright (C) Richard P. Curnow 1997-2002
|
||||||
* Copyright (C) Miroslav Lichvar 2011
|
* Copyright (C) Miroslav Lichvar 2011-2012
|
||||||
*
|
*
|
||||||
* 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
|
||||||
@@ -29,9 +29,7 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef LINUX
|
#include "config.h"
|
||||||
|
|
||||||
#define _LOOSE_KERNEL_NAMES
|
|
||||||
|
|
||||||
#include "chrony_timex.h"
|
#include "chrony_timex.h"
|
||||||
#include "wrap_adjtimex.h"
|
#include "wrap_adjtimex.h"
|
||||||
@@ -84,24 +82,14 @@ TMX_SetFrequency(double *freq, long tick)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
TMX_GetFrequency(double *freq)
|
TMX_GetFrequency(double *freq, long *tick)
|
||||||
{
|
{
|
||||||
struct timex txc;
|
struct timex txc;
|
||||||
int result;
|
int result;
|
||||||
txc.modes = 0; /* pure read */
|
txc.modes = 0; /* pure read */
|
||||||
result = adjtimex(&txc);
|
result = adjtimex(&txc);
|
||||||
*freq = txc.freq / (double)(1 << SHIFT_USEC);
|
*freq = txc.freq / (double)(1 << SHIFT_USEC);
|
||||||
return result;
|
*tick = txc.tick;
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
TMX_GetOffsetLeftOld(long *offset)
|
|
||||||
{
|
|
||||||
struct timex txc;
|
|
||||||
int result;
|
|
||||||
txc.modes = 0; /* pure read */
|
|
||||||
result = adjtimex(&txc);
|
|
||||||
*offset = txc.offset;
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -215,13 +203,13 @@ TMX_EnableNanoPLL(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
TMX_ApplyPLLOffset(long offset)
|
TMX_ApplyPLLOffset(long offset, long constant)
|
||||||
{
|
{
|
||||||
struct timex txc;
|
struct timex txc;
|
||||||
|
|
||||||
txc.modes = ADJ_OFFSET | ADJ_TIMECONST | ADJ_NANO;
|
txc.modes = ADJ_OFFSET | ADJ_TIMECONST | ADJ_NANO;
|
||||||
txc.offset = offset;
|
txc.offset = offset;
|
||||||
txc.constant = 0;
|
txc.constant = constant;
|
||||||
return adjtimex(&txc);
|
return adjtimex(&txc);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -237,5 +225,50 @@ TMX_GetPLLOffsetLeft(long *offset)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
int
|
||||||
|
TMX_TestStepOffset(void)
|
||||||
|
{
|
||||||
|
struct timex txc;
|
||||||
|
|
||||||
|
/* Zero maxerror and check it's reset to a maximum after ADJ_SETOFFSET.
|
||||||
|
This seems to be the only way how to verify that the kernel really
|
||||||
|
supports the ADJ_SETOFFSET mode as it doesn't return an error on unknown
|
||||||
|
mode. */
|
||||||
|
|
||||||
|
txc.modes = ADJ_MAXERROR;
|
||||||
|
txc.maxerror = 0;
|
||||||
|
if (adjtimex(&txc) < 0 || txc.maxerror != 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
txc.modes = ADJ_SETOFFSET;
|
||||||
|
txc.time.tv_sec = 0;
|
||||||
|
txc.time.tv_usec = 0;
|
||||||
|
if (adjtimex(&txc) < 0 || txc.maxerror < 100000)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
TMX_ApplyStepOffset(double offset)
|
||||||
|
{
|
||||||
|
struct timex txc;
|
||||||
|
|
||||||
|
txc.modes = ADJ_SETOFFSET;
|
||||||
|
if (offset >= 0) {
|
||||||
|
txc.time.tv_sec = offset;
|
||||||
|
} else {
|
||||||
|
txc.time.tv_sec = offset - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ADJ_NANO changes the status even with ADJ_SETOFFSET, use it only when
|
||||||
|
STA_NANO is already enabled */
|
||||||
|
if (status & STA_PLL) {
|
||||||
|
txc.modes |= ADJ_NANO;
|
||||||
|
txc.time.tv_usec = 1e9 * (offset - txc.time.tv_sec);
|
||||||
|
} else {
|
||||||
|
txc.time.tv_usec = 1e6 * (offset - txc.time.tv_sec);
|
||||||
|
}
|
||||||
|
|
||||||
|
return adjtimex(&txc);
|
||||||
|
}
|
||||||
|
|||||||
@@ -67,15 +67,16 @@ struct tmx_params {
|
|||||||
int TMX_SetTick(long tick);
|
int TMX_SetTick(long tick);
|
||||||
int TMX_ApplyOffset(long *offset);
|
int TMX_ApplyOffset(long *offset);
|
||||||
int TMX_SetFrequency(double *freq, long tick);
|
int TMX_SetFrequency(double *freq, long tick);
|
||||||
int TMX_GetFrequency(double *freq);
|
int TMX_GetFrequency(double *freq, long *tick);
|
||||||
int TMX_GetOffsetLeftOld(long *offset);
|
|
||||||
int TMX_GetOffsetLeft(long *offset);
|
int TMX_GetOffsetLeft(long *offset);
|
||||||
int TMX_ReadCurrentParams(struct tmx_params *params);
|
int TMX_ReadCurrentParams(struct tmx_params *params);
|
||||||
int TMX_SetLeap(int leap);
|
int TMX_SetLeap(int leap);
|
||||||
int TMX_SetSync(int sync);
|
int TMX_SetSync(int sync);
|
||||||
int TMX_EnableNanoPLL(void);
|
int TMX_EnableNanoPLL(void);
|
||||||
int TMX_ApplyPLLOffset(long offset);
|
int TMX_ApplyPLLOffset(long offset, long constant);
|
||||||
int TMX_GetPLLOffsetLeft(long *offset);
|
int TMX_GetPLLOffsetLeft(long *offset);
|
||||||
|
int TMX_TestStepOffset(void);
|
||||||
|
int TMX_ApplyStepOffset(double offset);
|
||||||
|
|
||||||
#endif /* GOT_WRAP_ADJTIMEX_H */
|
#endif /* GOT_WRAP_ADJTIMEX_H */
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user