summaryrefslogtreecommitdiffstats
path: root/usr.sbin
diff options
context:
space:
mode:
authorwollman <wollman@FreeBSD.org>1994-09-29 23:44:43 +0000
committerwollman <wollman@FreeBSD.org>1994-09-29 23:44:43 +0000
commitfd4b49373e27271d64d29752090f46ad2b3f3bea (patch)
tree1f2a8b3d97acb098acf071ca1f41de6d2d00ed1c /usr.sbin
parent1cba639cb2d728cbbb3866d923f8826a01269414 (diff)
downloadFreeBSD-src-fd4b49373e27271d64d29752090f46ad2b3f3bea.zip
FreeBSD-src-fd4b49373e27271d64d29752090f46ad2b3f3bea.tar.gz
Merged changes from the vendor branch. NB: this will NOT compile until
after the NEXT commit.
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/xntpd/Makefile5
-rw-r--r--usr.sbin/xntpd/README.FreeBSD79
-rw-r--r--usr.sbin/xntpd/authstuff/md5driver.c12
-rw-r--r--usr.sbin/xntpd/doc/ntpq.8319
-rw-r--r--usr.sbin/xntpd/include/ntp_machine.h61
-rw-r--r--usr.sbin/xntpd/lib/authdes.c.export2
-rw-r--r--usr.sbin/xntpd/lib/msyslog.c2
-rw-r--r--usr.sbin/xntpd/ntpq/ntpq.c154
-rw-r--r--usr.sbin/xntpd/util/tickadj.c12
-rw-r--r--usr.sbin/xntpd/xntpd/ntp_control.c317
-rw-r--r--usr.sbin/xntpd/xntpd/ntp_loopfilter.c1185
-rw-r--r--usr.sbin/xntpd/xntpd/ntp_request.c403
-rw-r--r--usr.sbin/xntpd/xntpd/ntp_unixclock.c79
-rw-r--r--usr.sbin/xntpd/xntpd/refclock_trak.c1083
-rw-r--r--usr.sbin/xntpd/xntpdc/ntpdc.c98
15 files changed, 1455 insertions, 2356 deletions
diff --git a/usr.sbin/xntpd/Makefile b/usr.sbin/xntpd/Makefile
index 8d724c5..962e64a 100644
--- a/usr.sbin/xntpd/Makefile
+++ b/usr.sbin/xntpd/Makefile
@@ -1,8 +1,7 @@
#
# Makefile for xntpd.
-# $Id$
+# $Id: Makefile,v 1.3 1994/02/03 22:30:30 wollman Exp $
#
-
-SUBDIR= lib parse xntpd xntpdc ntpq ntpdate ntptrace xntpres authstuff util
+SUBDIR= lib parse xntpd xntpdc ntpq ntpdate ntptrace authstuff util
.include <bsd.subdir.mk>
diff --git a/usr.sbin/xntpd/README.FreeBSD b/usr.sbin/xntpd/README.FreeBSD
index 4dffdc8..798a685 100644
--- a/usr.sbin/xntpd/README.FreeBSD
+++ b/usr.sbin/xntpd/README.FreeBSD
@@ -1,8 +1,8 @@
- $Id$
+ $Id: README.FreeBSD,v 1.7 1994/04/21 21:10:20 wollman Exp $
This version of NTP was converted to the BSD-style Makefile system by
-Garrett Wollman (wollman@freefall.cdrom.com); it is based on version
-3.3s (late beta) from the University of Delaware.
+Garrett Wollman (wollman@FreeBSD.org); it is based on version
+3.4e (beta) from the University of Delaware.
Besides the Makefile changes, the DES code has been completely removed
in order to make this code exportable. If you have a legal copy of
@@ -11,74 +11,5 @@ to the AUTHDEFS in Makefile.inc.
You can change CLOCKDEFS in the same file to add other reference clocks.
-This version of xntpd knows how to talk to the kernelized NTP PLL which is
-present in versions of FreeBSD-current after 21 April 1994. When this code
-is more widely released, I'll provide the patches to Mills.
-
-----------------------------------------------------
-Support for Conrad electronic's "DCF-77 Uhr, Mobil".
-----------------------------------------------------
-Conrad electronic in Germany,, Phone (+49) 962230111 (?), sells a gadget
-called "DCF77 Uhr, mobil", which is a DCF77 timecode receiver with a
-rs-232 interface. The price is around DM130.
- 9-pin interface is Order# 97 94 57 66
- 25-pin interface is Order# 97 94 81 66
-
-You must define
- -DDCF77 -DPPS -DFREEBSD_CONRAD -DDEBUG
-when you compile xntpd. You can later remove -DDEBUG, if you feel like it.
-
-You must also have
- options COM_BIDIR
-defined in your kernel, and finally the ttyport you intend to use must
-have special interrupt vector:
- device sio1 at isa? port "IO_COM2" tty irq 3 vector siointrts
- ^^^^^^^^^^^^
-connect the radio-clock to the tty port and link it to /dev/refclock-0:
-
- cd /dev
- sh MAKEDEV cua1
- ln -s /dev/cua01 /dev/refclock-0
-
-make a directory to gather statistics in:
- mkdir /var/tmp/ntp
-
-Create a /etc/ntp.conf along these lines:
-
- # DCF77 without PPS
- server 127.127.8.20
- # DCF77 with PPS
- #server 127.127.8.148 prefer
-
- driftfile /var/tmp/ntp/ntp.drift
- statsdir /var/tmp/ntp
- statistics loopstats
- statistics peerstats
- statistics clockstats
- filegen peerstats file peerstats type day enable
- filegen loopstats file loopstats type day enable
- filegen clockstats file clockstats type day enable
-
-Try to start it:
- comcontrol ttyd1 bidir
- tickadj -A
- xntpd -d -d -d
-
-You should see the red LED flash on the receiver every second now. You
-may have to experiment a bit with the location, and possibly adjust the
-minute variable resistor inside to get a good signal. Be aware, that just
-because you see the light flash, is not the same as the signal being
-received by the computer. The chip doing the work in the reciver uses
-less than 1 micro-ampere, so even if RTS isn't pulled low, it will happily
-receive, but be unable to buffer the signal to the rs-232 levels needed.
-
-You can see what's going on in /var/log/messages, and query the
-daemon using xntpdc and ntpq, in particular the "clockvar" command
-of ntpq will tell about the clocks healt.
-
-I live in Slagelse, Denmark, which is ~1000 Km from Mainflingen, yet
-I have +/- 2 ms precision from this cheap gadget. If you have a very
-stable signal, you can use the 'pps' address instead to improve your
-timing.
-
-Have fun... Poul-Henning Kamp <phk@login.dkuug.dk>
+This port should work under either FreeBSD 1.1 or FreeBSD 2.0. For
+1.1, change the `-DSYS_44BSD' in Makefile.inc to `-DSYS_386BSD'.
diff --git a/usr.sbin/xntpd/authstuff/md5driver.c b/usr.sbin/xntpd/authstuff/md5driver.c
index a608add..0d7e132 100644
--- a/usr.sbin/xntpd/authstuff/md5driver.c
+++ b/usr.sbin/xntpd/authstuff/md5driver.c
@@ -1,4 +1,4 @@
-/* md5driver.c,v 3.1 1993/07/06 01:05:07 jbj Exp
+/*
***********************************************************************
** md5driver.c -- sample test routines **
** RSA Data Security, Inc. MD5 Message-Digest Algorithm **
@@ -25,7 +25,7 @@
#include <stdio.h>
#include <sys/types.h>
#include <time.h>
-#ifdef SYS_BSDI
+#if defined(SYS_BSDI) || defined(SYS_44BSD)
#include <sys/time.h>
#endif /* SYS_BSDI */
#include "md5.h"
@@ -57,7 +57,7 @@ MD5_CTX *mdContext;
#define TEST_BLOCKS 10000
/* number of test bytes = TEST_BLOCK_SIZE * TEST_BLOCKS */
-static LONG TEST_BYTES = (LONG)TEST_BLOCK_SIZE * (LONG)TEST_BLOCKS;
+static long TEST_BYTES = (long)TEST_BLOCK_SIZE * (long)TEST_BLOCKS;
/* A time trial routine, to measure the speed of MD5.
Measures wall time required to digest TEST_BLOCKS * TEST_BLOCK_SIZE
@@ -76,7 +76,7 @@ MDTimeTrial ()
data[i] = (unsigned char)(i & 0xFF);
/* start timer */
- printf ("MD5 time trial. Processing %ld characters...\n", TEST_BYTES);
+ printf ("MD5 time trial. Processing %ld characters...\n", (long)TEST_BYTES);
time (&startTime);
/* digest data in TEST_BLOCK_SIZE byte blocks */
@@ -90,10 +90,10 @@ MDTimeTrial ()
MDPrint (&mdContext);
printf (" is digest of test input.\n");
printf
- ("Seconds to process test input: %ld\n", (LONG)(endTime-startTime));
+ ("Seconds to process test input: %ld\n", (long)endTime-startTime);
printf
("Characters processed per second: %ld\n",
- TEST_BYTES/(endTime-startTime));
+ (long)(TEST_BYTES/(endTime-startTime)));
}
/* Computes the message digest for string inString.
diff --git a/usr.sbin/xntpd/doc/ntpq.8 b/usr.sbin/xntpd/doc/ntpq.8
index ad37476..379c5cf 100644
--- a/usr.sbin/xntpd/doc/ntpq.8
+++ b/usr.sbin/xntpd/doc/ntpq.8
@@ -1,5 +1,5 @@
''' $Header
-'''
+'''
.de Sh
.br
.ne 5
@@ -48,7 +48,7 @@ ntpq - standard Network Time Protocol query program
[
.B -inp
] [
-.B -c
+.B -c
.I command
] [
.I host
@@ -57,26 +57,26 @@ ntpq - standard Network Time Protocol query program
]
.SH DESCRIPTION
.I Ntpq
-is used to query NTP servers which implement the recommended NTP
-mode 6 control message format about current state and to request
-changes in that state. The
-program may be run either in interactive mode or controlled using
-command line arguments. Requests to read and write arbitrary
-variables can be assembled, with raw and pretty\-printed output
-options being available.
+is used to query NTP servers which implement the recommended NTP mode 6
+control message format about current state and to request changes in
+that state. The program may be run either in interactive mode or
+controlled using command line arguments. Requests to read and write
+arbitrary variables can be assembled, with raw and pretty\-printed
+output options being available.
.I Ntpq
-can also obtain and print a list of peers in a common format
-by sending multiple queries to the server.
+can also obtain and print a list of peers in a common format by sending
+multiple queries to the server.
.PP
If one or more request options is included on the command line when
.I ntpq
-is executed, each of the requests will be sent to the NTP servers running
-on each of the hosts given as command line arguments, or on
+is executed, each of the requests will be sent to the NTP servers
+running on each of the hosts given as command line arguments, or on
.I localhost
-by default. If no request options are given,
+by default. If no request options are given,
.I ntpq
will attempt to read commands from the standard input and execute these
-on the NTP server running on the first host given on the command line, again
+on the NTP server running on the first host given on the command line,
+again
defaulting to
.I localhost
when no other host is specified.
@@ -86,53 +86,54 @@ will prompt for commands if the standard input is a terminal device.
.I Ntpq
uses NTP mode 6 packets to communicate with the NTP server, and hence
can be used to query any compatable server on the network which permits
-it. Note that since NTP is a UDP protocol this communication will be
+it. Note that since NTP is a UDP protocol this communication will be
somewhat unreliable, especially over large distances in terms of network
topology.
.I Ntpq
makes one attempt to retransmit requests, and will time requests out if
the remote host is not heard from within a suitable time out time.
.PP
-Command line options are described following. Specifying a command
-line option other than
+Command line options are described following. Specifying a command line
+option other than
.B -i
or
.B -n
will cause the specified query (queries) to be sent to the indicated
-host(s) immediately. Otherwise,
+host(s) immediately. Otherwise,
.I ntpq
-will attempt to read interactive format commands from the standard input.
+will attempt to read interactive format commands from the standard
+input.
.Ip -c 8
The following argument is interpreted as an interactive format command
and is added to the list of commands to be executed on the specified
-host(s). Multiple
+host(s). Multiple
.B -c
options may be given.
.Ip -i 8
Force
.I ntpq
-to operate in interactive mode. Prompts will be written to the
-standard output and commands read from the standard input.
+to operate in interactive mode. Prompts will be written to the standard
+output and commands read from the standard input.
.Ip -n 8
Output all host addresses in dotted\-quad numeric format rather than
converting to the canonical host names.
.Ip -p 8
-Print a list of the peers known to the server as well as a summary
-of their state. This is equivalent to the \*(L"peers\*(R" interactive
+Print a list of the peers known to the server as well as a summary of
+their state. This is equivalent to the \*(L"peers\*(R" interactive
command.
.SH INTERNAL COMMANDS
.PP
-Interactive format commands consist of a keyword followed by zero
-to four arguments. Only enough characters of the full keyword to
-uniquely identify the command need be typed. The output of a command
-is normally sent to the standard output, but optionally the output of
-individual commands may be sent to a file by appending a \*(L">\*(R",
-followed by a file name, to the command line.
+Interactive format commands consist of a keyword followed by zero to
+four arguments. Only enough characters of the full keyword to uniquely
+identify the command need be typed. The output of a command is normally
+sent to the standard output, but optionally the output of individual
+commands may be sent to a file by appending a \*(L">\*(R", followed by a
+file name, to the command line.
.PP
A number of interactive format commands are executed entirely within the
.I ntpq
-program itself and do not result in NTP mode 6 requests being sent
-to a server. These are described following.
+program itself and do not result in NTP mode 6 requests being sent to a
+server. These are described following.
.PP
.B ?
[
@@ -143,7 +144,7 @@ A \*(L"?\*(R" by itself will print a list of all the command keywords
known to this incarnation of
.IR ntpq .
A \*(L"?\*(R" followed by a command keyword will print funcation and
-usage information about the command. This command is probably a better
+usage information about the command. This command is probably a better
source of information about
.I ntpq
than this manual page.
@@ -151,8 +152,8 @@ than this manual page.
.B timeout
.I millseconds
.PP
-Specify a time out period for responses to server queries. The default
-is about 5000 milliseconds. Note that since
+Specify a time out period for responses to server queries. The default
+is about 5000 milliseconds. Note that since
.I ntpq
retries each query once after a time out the total waiting time for a
time out will be twice the time out value set.
@@ -161,10 +162,10 @@ time out will be twice the time out value set.
.I milliseconds
.PP
Specify a time interval to be added to timestamps included in requests
-which require authentication. This is used to enable (unreliable) server
+which require authentication. This is used to enable (unreliable) server
reconfiguration over long delay network paths or between machines whose
-clocks are unsynchronized. Actually the server does not now require
-time stamps in authenticated requests, so this command may be obsolete.
+clocks are unsynchronized. Actually the server does not now require time
+stamps in authenticated requests, so this command may be obsolete.
.PP
.B host
.I hostname
@@ -181,30 +182,30 @@ address.
.B verbose
]
.PP
-Poll the current server in client mode. The first argument is the
-number of times to poll (default is 1) while the second argument may
-be given to obtain a more detailed output of the results. This command
-is currently just wishful thinking.
+Poll the current server in client mode. The first argument is the number
+of times to poll (default is 1) while the second argument may be given
+to obtain a more detailed output of the results. This command is
+currently just wishful thinking.
.PP
.B keyid
.I #
.PP
This command allows the specification of a key number to be used to
-authenticate configuration requests. This must correspond to a
-key number the server has been configured to use for this purpose.
+authenticate configuration requests. This must correspond to a key
+number the server has been configured to use for this purpose.
.PP
.B passwd
.PP
This command prompts you to type in a password (which will not be
-echoed) which will be used to authenticate configuration requests. The
-password must correspond to the key configured for use by the NTP
-server for this purpose if such requests are to be successful.
+echoed) which will be used to authenticate configuration requests. The
+password must correspond to the key configured for use by the NTP server
+for this purpose if such requests are to be successful.
.PP
.B "hostnames yes|no"
.PP
If \*(L"yes\*(R" is specified, host names are printed in information
-displays. If \*(L"no\*(R" is given, numeric addresses are printed
-instead. The default is \*(L"yes\*(R" unless modified using the command
+displays. If \*(L"no\*(R" is given, numeric addresses are printed
+instead. The default is \*(L"yes\*(R" unless modified using the command
line
.B -n
switch.
@@ -212,15 +213,15 @@ switch.
.B raw
.PP
Causes all output from query commands is printed as received from the
-remote server. The only formating/intepretation done on the data is
-to transform nonascii data into a printable (but barely understandable)
+remote server. The only formating/intepretation done on the data is to
+transform nonascii data into a printable (but barely understandable)
form.
.PP
.B cooked
.PP
-Causes output from query commands to be \*(L"cooked\*(R". Variables
+Causes output from query commands to be \*(L"cooked\*(R". Variables
which are recognized by the server will have their values reformatted
-for human consumption. Variables which
+for human consumption. Variables which
.I ntpq
thinks should have a decodeable value but didn't are marked with a
trailing \*(L"?\*(R".
@@ -230,23 +231,24 @@ trailing \*(L"?\*(R".
.PP
Sets the NTP version number which
.I ntpq
-claims in packets. Defaults to 3, Note that mode 6 control messages (and modes,
-for that matter) didn't exist in NTP version 1. There appear to be no
-servers left which demand version 1.
+claims in packets. Defaults to 3, Note that mode 6 control messages (and
+modes, for that matter) didn't exist in NTP version 1. There appear to
+be no servers left which demand version 1.
.PP
.B authenticate
.B yes|no
.PP
Normally
.I ntpq
-does not authenticate requests unless they are write requests. The command
+does not authenticate requests unless they are write requests. The
+command
.B authenticate yes
causes
.I ntpq
-to send authentication with all requests it makes. Authenticated requests
-causes some servers to handle requests slightly differently, and can
-occasionally melt the CPU in fuzzballs if you turn authentication on before
-doing a peer display.
+to send authentication with all requests it makes. Authenticated
+requests causes some servers to handle requests slightly differently,
+and can occasionally melt the CPU in fuzzballs if you turn
+authentication on before doing a peer display.
.PP
.B addvars
.IR <variable_name>[=<value>] [,...]
@@ -254,25 +256,24 @@ doing a peer display.
.IR <variable_name> [,...]
.B clearvars
.PP
-The data carried by NTP mode 6 messages consists of a list of items
-of the form
+The data carried by NTP mode 6 messages consists of a list of items of
+the form
.IP "" 8
<variable_name>=<value>
.PP
where the \*(L"=<value>\*(R" is ignored, and can be omitted, in requests
to the server to read variables.
.I Ntpq
-maintains an internal list in which data to be included in control messages
-can be assembled, and sent using
-the
+maintains an internal list in which data to be included in control
+messages can be assembled, and sent using the
.B readlist
and
.B writelist
-commands described below. The
+commands described below. The
.B addvars
command allows variables and their optional values to be added to the
-list. If more than one variable is to be added, the list should be
-comma\-separated and not contain white space. The
+list. If more than one variable is to be added, the list should be
+comma\-separated and not contain white space. The
.B rmvars
command can be used to remove individual variables from the list, while
the
@@ -293,16 +294,15 @@ Exit
Each peer known to an NTP server has a 16 bit integer
.I association
.I identifier
-assigned to it. NTP control messages which carry peer variables
-must identify the peer the values correspond to by including
-its association ID. An association ID of 0 is special, and indicates
-the variables are system variables, whose names are drawn from a
-separate name space.
-.PP
-Control message commands result in one or more NTP mode 6
-messages being sent to the server, and cause the data returned to be
-printed in some format. Most commands currently implemented send a single
-message and expect a single response. The current exceptions are the
+assigned to it. NTP control messages which carry peer variables must
+identify the peer the values correspond to by including its association
+ID. An association ID of 0 is special, and indicates the variables are
+system variables, whose names are drawn from a separate name space.
+.PP
+Control message commands result in one or more NTP mode 6 messages being
+sent to the server, and cause the data returned to be printed in some
+format. Most commands currently implemented send a single message and
+expect a single response. The current exceptions are the
.B peers
command, which will send a preprogrammed series of messages to obtain
the data it needs, and the
@@ -313,57 +313,53 @@ commands, which will iterate over a range of associations.
.PP
.B associations
.PP
-Obtains and prints a list of association identifiers and
-peer statuses for in\-spec
-peers of the server being queried. The list is printed in
-columns. The first of these is an index numbering the associations
-from 1 for internal use, the second the actual association identifier
-returned by the server and the third the status word for the peer. This
+Obtains and prints a list of association identifiers and peer statuses
+for in\-spec peers of the server being queried. The list is printed in
+columns. The first of these is an index numbering the associations from
+1 for internal use, the second the actual association identifier
+returned by the server and the third the status word for the peer. This
is followed by a number of columns containing data decoded from the
-status word. Note
-that the data returned by the \*(L"associations\*(R" command is cached
-internally in
+status word. Note that the data returned by the \*(L"associations\*(R"
+command is cached internally in
.IR ntpq .
The index is then of use when dealing with stupid servers which use
-association identifiers which are hard for humans to type, in that
-for any subsequent commands which require an association identifier
-as an argument, the form
+association identifiers which are hard for humans to type, in that for
+any subsequent commands which require an association identifier as an
+argument, the form
.I &index
may be used as an alternative.
.PP
.B lassocations
.PP
Obtains and prints a list of association identifiers and peer statuses
-for all associations for which the server is maintaining state. This
-command differs from the
-\*(L"associations\*(R"
-command only for servers which retain state for out\-of\-spec client
-associations (i.e. fuzzballs). Such associations are normally omitted
-from the display when the
-\*(L"associations\*(R"
-command is used, but are included in the output of
-\*(L"lassociations\*(R".
+for all associations for which the server is maintaining state. This
+command differs from the \*(L"associations\*(R" command only for servers
+which retain state for out\-of\-spec client associations (i.e.
+fuzzballs). Such associations are normally omitted from the display when
+the \*(L"associations\*(R" command is used, but are included in the
+output of \*(L"lassociations\*(R".
.PP
.B passociations
.PP
-Prints association data concerning in\-spec peers from the internally cached
-list of associations. This command performs
-identically to the \*(L"associations\*(R" except that it displays the
-internally stored data rather than making a new query.
+Prints association data concerning in\-spec peers from the internally
+cached list of associations. This command performs identically to the
+\*(L"associations\*(R" except that it displays the internally stored
+data rather than making a new query.
.PP
.B lpassociations
.PP
Print data for all associations, including out\-of\-spec client
-associations, from the internally cached list of associations. This command
-differs from \*(L"passociations\*(R" only when dealing with fuzzballs.
+associations, from the internally cached list of associations. This
+command differs from \*(L"passociations\*(R" only when dealing with
+fuzzballs.
.PP
.B pstatus
.I assocID
.PP
-Sends a read status request to the server for the given association.
-The names and values of the peer variables returned will be printed. Note
-that the status word from the header is displayed preceding the variables,
-both in hexidecimal and in pidgeon English.
+Sends a read status request to the server for the given association. The
+names and values of the peer variables returned will be printed. Note
+that the status word from the header is displayed preceding the
+variables, both in hexidecimal and in pidgeon English.
.PP
.B readvar
[
@@ -373,13 +369,12 @@ both in hexidecimal and in pidgeon English.
]
.PP
Requests that the values of the specified variables be returned by the
-server by sending a read variables request. If the association ID
-is omitted or is given as zero the variables
-are system variables, otherwise they
-are peer variables and the values returned will be those
-of the corresponding peer. Omitting the variable list will send a
-request with no data which should induce the server to return a
-default display.
+server by sending a read variables request. If the association ID is
+omitted or is given as zero the variables are system variables,
+otherwise they are peer variables and the values returned will be those
+of the corresponding peer. Omitting the variable list will send a
+request with no data which should induce the server to return a default
+display.
.PP
.B rv
[
@@ -405,12 +400,12 @@ request, except the specified variables are written instead of read.
.I assocID
]
.PP
-Requests that the values of the variables in the internal variable
-list be returned by the server. If the association ID is omitted
-or is 0 the variables are assumed to be system variables. Otherwise
-they are treated as peer variables. If the internal variable list
-is empty a request is sent without data, which should induce the remote
-server to return a default display.
+Requests that the values of the variables in the internal variable list
+be returned by the server. If the association ID is omitted or is 0 the
+variables are assumed to be system variables. Otherwise they are treated
+as peer variables. If the internal variable list is empty a request is
+sent without data, which should induce the remote server to return a
+default display.
.PP
.B rl
[
@@ -428,8 +423,7 @@ command.
.PP
Like the
.B readlist
-request, except the internal list variables are written instead of
-read.
+request, except the internal list variables are written instead of read.
.PP
.B mreadvar
.I assocID
@@ -441,7 +435,7 @@ read.
Like the
.B readvar
command except the query is done for each of a range of (nonzero)
-association IDs. This range is determined from the association list
+association IDs. This range is determined from the association list
cached by the most recent
.B associations
command.
@@ -464,7 +458,7 @@ command.
Like the
.B readlist
command except the query is done for each of a range of (nonzero)
-association IDs. This range is determined from the association list
+association IDs. This range is determined from the association list
cached by the most recent
.B associations
command.
@@ -485,15 +479,16 @@ command.
.IR <variable_name>[=<value>] [,...]
]
.PP
-Requests that a list of the server's clock variables be sent. Servers
+Requests that a list of the server's clock variables be sent. Servers
which have a radio clock or other external synchronization will respond
-positively to this. If the association identifier is omitted or zero
-the request is for the variables of the \*(L"system clock\*(R" and will
-generally get a positive response from all servers with a clock. If the
-server treats clocks as pseudo\-peers, and hence can possibly have more than
-one clock connected at once, referencing the appropriate
-peer association ID will show the variables of a particular clock. Omitting
-the variable list will cause the server to return a default variable display.
+positively to this. If the association identifier is omitted or zero the
+request is for the variables of the \*(L"system clock\*(R" and will
+generally get a positive response from all servers with a clock. If the
+server treats clocks as pseudo\-peers, and hence can possibly have more
+than one clock connected at once, referencing the appropriate peer
+association ID will show the variables of a particular clock. Omitting
+the variable list will cause the server to return a default variable
+display.
.PP
.B cv
[
@@ -509,40 +504,42 @@ command.
.PP
.B peers
.PP
-Obtains a list of in\-spec peers of the server, along
-with a summary of each peer's state. Summary information includes the address
-of the remote peer, the reference ID (0.0.0.0 if the refID is unknown),
-the stratum of the remote peer, the polling interval,
-in seconds, the reachability
-register, in octal, and the current estimated delay, offset and dispersion
-of the peer, all in seconds.
+Obtains a list of in\-spec peers of the server, along with a summary of
+each peer's state. Summary information includes the address of the
+remote peer, the reference ID (0.0.0.0 if the refID is unknown), the
+stratum of the remote peer, the type of the peer (local, unicast,
+multicast or broadcast), when the last packet was received, the polling
+interval, in seconds, the reachability register, in octal, and the
+current estimated delay, offset and dispersion of the peer, all in
+seconds.
.PP
The character in the left margin indicates the fate of this peer in the
-clock selection process. The codes mean: <sp> discarded due to high stratum
-and/or failed sanity checks; \*(L"x\*(R" designated falsticker by the
-intersection algorithm; \*(L".\*(R" culled from the end of the candidate
-list; \*(L"-\*(R" discarded by the clustering algorithmi; \*(L"+\*(R"
-included in the final selection set; \*(L"#\*(R" selected for synchronizatio;n
-but distance exceeds maximum; \*(L"*\*(R" selected for synchronization; and
-\*(L"o\*(R" selected for synchronization, pps signal in use.
+clock selection process. The codes mean: <sp> discarded due to high
+stratum and/or failed sanity checks; \*(L"x\*(R" designated falsticker
+by the intersection algorithm; \*(L".\*(R" culled from the end of the
+candidate list; \*(L"-\*(R" discarded by the clustering algorithmi;
+\*(L"+\*(R" included in the final selection set; \*(L"#\*(R" selected
+for synchronizatio;n but distance exceeds maximum; \*(L"*\*(R" selected
+for synchronization; and \*(L"o\*(R" selected for synchronization, pps
+signal in use.
.PP
Note that since the
.B peers
-command depends on the ability to parse the values in the
-responses it gets it may fail to work from time to time with servers
-which poorly control the data formats.
+command depends on the ability to parse the values in the responses it
+gets it may fail to work from time to time with servers which poorly
+control the data formats.
.PP
-The contents of the host field may be one of four forms. It may be a host name,
-an IP address, a reference clock implementation name with its parameter or
-\*(L"REFCLK(<implementation number>, <parameter>)\*(R". On \*(L"hostnames no\*(R"
-only IP\-addresses will be displayed.
+The contents of the host field may be one of four forms. It may be a
+host name, an IP address, a reference clock implementation name with its
+parameter or \*(L"REFCLK(<implementation number>, <parameter>)\*(R". On
+\*(L"hostnames no\*(R" only IP\-addresses will be displayed.
.PP
.B lpeers
.PP
Like
.BR peers ,
except a summary of all associations for which the server is maintaining
-state is printed. This can produce a much longer list of peers from
+state is printed. This can produce a much longer list of peers from
fuzzball servers.
.PP
.B opeers
@@ -561,6 +558,6 @@ messages about invalid associations occurring and terminating the
command.
.PP
The timeout time is a fixed constant, which means you wait a long time
-for time outs since it assumes sort of a worst case. The program
-should improve the time out estimate as it sends queries to a particular
-host, but doesn't.
+for time outs since it assumes sort of a worst case. The program should
+improve the time out estimate as it sends queries to a particular host,
+but doesn't.
diff --git a/usr.sbin/xntpd/include/ntp_machine.h b/usr.sbin/xntpd/include/ntp_machine.h
index 16c3fbf..2051de1 100644
--- a/usr.sbin/xntpd/include/ntp_machine.h
+++ b/usr.sbin/xntpd/include/ntp_machine.h
@@ -1,4 +1,4 @@
-/* ntp_machine.h,v 3.1 1993/07/06 01:06:49 jbj Exp
+/*
* Collect all machine dependent idiosyncrasies in one place.
*/
@@ -181,6 +181,7 @@ in this file.
#define RETSIGTYPE void
#define NTP_SYSCALL_GET 132
#define NTP_SYSCALL_ADJ 147
+#define HAVE_MODEM_CONTROL
#ifndef STR_SYSTEM
#define STR_SYSTEM "UNIX/SunOS 4.x"
#endif
@@ -219,6 +220,7 @@ in this file.
#define HAVE_ATT_SETPGRP
#define HAVE_ATT_NICE
#define UDP_WILDCARD_DELIVERY
+#define HAVE_MODEM_CONTROL
#ifndef STR_SYSTEM
#define STR_SYSTEM "UNIX/Solaris 2.x"
#endif
@@ -277,6 +279,7 @@ in this file.
#define HAVE_BSD_NICE
#define RETSIGTYPE void
#define NTP_SYSCALLS_STD
+#define HAVE_MODEM_CONTROL
#ifndef STR_SYSTEM
#define STR_SYSTEM "UNIX/Ultrix"
#endif
@@ -365,6 +368,26 @@ in this file.
#endif
/*
+ * 4.4 bsd
+ */
+#if defined(SYS_44BSD)
+#define HAVE_SIGNALED_IO
+#define HAVE_LIBKVM
+#define NTP_POSIX_SOURCE
+#define HAVE_BSD_NICE
+#ifndef STR_SYSTEM
+#define STR_SYSTEM "UNIX/4.4BSD"
+#endif
+#ifdef SYS_FREEBSD
+#define HAVE_TERMIOS
+#define HAVE_UNAME
+#define HAVE_SYS_TIMEX_H
+#define NTP_SYSCALLS_LIBC
+#define KERNEL_PLL
+#endif
+#endif
+
+/*
* Linux
*/
#if defined(SYS_LINUX)
@@ -386,14 +409,13 @@ in this file.
* 386BSD and any variants 8-) - should really have only ONE define
* for this bunch.
*/
-#if defined(SYS_386BSD) || defined(SYS_FREEBSD) || defined(SYS_NETBSD)
+#if defined(SYS_386BSD) || defined(SYS_NETBSD)
#define HAVE_SIGNALED_IO
#define HAVE_READKMEM
#define NTP_POSIX_SOURCE
#define HAVE_BSD_NICE
#ifndef STR_SYSTEM
-#define STR_SYSTEM "UNIX/*BSD"
-#endif
+#define STR_SYSTEM "UNIX/\052BSD"
#endif
#ifdef SYS_FREEBSD
#define HAVE_TERMIOS
@@ -402,6 +424,7 @@ in this file.
#define NTP_SYSCALLS_LIBC
#define KERNEL_PLL
#endif
+#endif
/*
* DEC AXP OSF/1
@@ -412,12 +435,42 @@ in this file.
#define NTP_POSIX_SOURCE
#define NTP_SYSCALLS_STD
#define HAVE_BSD_NICE
+#define HAVE_MODEM_CONTROL
#ifndef STR_SYSTEM
#define STR_SYSTEM "UNIX/DECOSF1"
#endif
#endif
/*
+ * Intel x86 OSF/1
+ */
+#if defined(SYS_IX86OSF1)
+#define HAVE_SIGNALED_IO
+#define HAVE_READKMEM
+#define NTP_POSIX_SOURCE
+#define NTP_SYSCALLS_STD
+#define HAVE_BSD_NICE
+#define HAVE_MODEM_CONTROL
+#define SYS_DECOSF1
+#ifndef STR_SYSTEM
+#define STR_SYSTEM "UNIX/IX86OSF1"
+#endif
+#endif
+
+/*
+ * ISI
+ */
+#if defined(SYS_BSD)
+#define NO_SIGNED_CHAR_DECL
+#define HAVE_BSD_NICE
+#define HAVE_BSD_TTYS
+#define HAVE_READKMEM
+#define HAVE_SIGNALED_IO
+#define NEED_VSPRINTF
+#undef NTP_POSIX_SOURCE
+#endif
+
+/*
* I386
* XXX - what OS?
*/
diff --git a/usr.sbin/xntpd/lib/authdes.c.export b/usr.sbin/xntpd/lib/authdes.c.export
index a63c6d3..cb311f9 100644
--- a/usr.sbin/xntpd/lib/authdes.c.export
+++ b/usr.sbin/xntpd/lib/authdes.c.export
@@ -1,4 +1,4 @@
-/* authdes.c.export,v 3.1 1993/07/06 01:07:48 jbj Exp
+/*
* authdes.c - dummy encryption routines for destinations outside the USA.
*
* Sorry, folks; I hate this, too. Send me your e-mail address in an
diff --git a/usr.sbin/xntpd/lib/msyslog.c b/usr.sbin/xntpd/lib/msyslog.c
index a637e50..aca016b 100644
--- a/usr.sbin/xntpd/lib/msyslog.c
+++ b/usr.sbin/xntpd/lib/msyslog.c
@@ -1,4 +1,4 @@
-/* msyslog.c,v 3.1 1993/07/06 01:08:36 jbj Exp
+/*
* msyslog - either send a message to the terminal or print it on
* the standard output.
*
diff --git a/usr.sbin/xntpd/ntpq/ntpq.c b/usr.sbin/xntpd/ntpq/ntpq.c
index 73c2a35..441b283 100644
--- a/usr.sbin/xntpd/ntpq/ntpq.c
+++ b/usr.sbin/xntpd/ntpq/ntpq.c
@@ -1,4 +1,4 @@
-/* ntpq.c,v 3.1 1993/07/06 01:09:29 jbj Exp
+/*
* ntpq - query an NTP server using mode 6 commands
*/
#include <stdio.h>
@@ -27,7 +27,7 @@ char *prompt = "ntpq> "; /* prompt to ask him about */
/*
* Keyid used for authenticated requests. Obtained on the fly.
*/
-U_LONG info_auth_keyid = -1;
+u_long info_auth_keyid = -1;
/*
* Type of key md5 or des
@@ -88,7 +88,7 @@ struct ctl_var sys_var[] = {
{ CS_LEAP, LP, "leap" }, /* 1 */
{ CS_STRATUM, UI, "stratum" }, /* 2 */
{ CS_PRECISION, IN, "precision" }, /* 3 */
- { CS_ROOTDELAY, FU, "rootdelay" }, /* 4 */
+ { CS_ROOTDELAY, FS, "rootdelay" }, /* 4 */
{ CS_ROOTDISPERSION, FU, "rootdispersion" }, /* 5 */
{ CS_REFID, RF, "refid" }, /* 6 */
{ CS_REFTIME, TS, "reftime" }, /* 7 */
@@ -96,7 +96,7 @@ struct ctl_var sys_var[] = {
{ CS_PEERID, UI, "peer" }, /* 9 */
{ CS_OFFSET, FL, "phase" }, /* 10 */
{ CS_DRIFT, FS, "freq" }, /* 11 */
- { CS_COMPLIANCE, UI, "compliance" }, /* 12 */
+ { CS_COMPLIANCE, FU, "error" }, /* 12 */
{ CS_CLOCK, TS, "clock" }, /* 13 */
{ CS_LEAPIND, LP, "leapindicator" }, /* 14 */
{ CS_LEAPWARNING, LP, "leapwarning" }, /* 15 */
@@ -149,7 +149,7 @@ struct ctl_var peer_var[] = {
{ CP_FLASH, TST, "flash"}, /* 34 */
{ CP_DISP, AR, "disp" }, /* 35 */
/*
- * These are duplicate entires so that we can
+ * These are duplicate entries so that we can
* process deviant version of the xntp protocal.
*/
{ CP_SRCADR, HA, "peeraddr" }, /* 4 */
@@ -173,8 +173,8 @@ struct ctl_var clock_var[] = {
{ CC_BADDATA, UI, "baddata" }, /* 6 */
{ CC_FUDGETIME1, FL, "fudgetime1" }, /* 7 */
{ CC_FUDGETIME2, FL, "fudgetime2" }, /* 8 */
- { CC_FUDGEVAL1, IN, "fudgeval1" }, /* 9 */
- { CC_FUDGEVAL2, IN, "fudgeval2" }, /* 10 */
+ { CC_FUDGEVAL1, UI, "stratum" }, /* 9 */
+ { CC_FUDGEVAL2, RF, "refid" }, /* 10 */
{ CC_FLAGS, UI, "flags" }, /* 11 */
{ CC_DEVICE, ST, "device" }, /* 12 */
{ 0, EOV, "" }
@@ -308,11 +308,6 @@ static void tokenize P((char *, char **, int *));
static int findcmd P((char *, struct xcmd *, struct xcmd *, struct xcmd **));
static int getarg P((char *, int, arg_v *));
static int rtdatetolfp P((char *, l_fp *));
-
-#ifdef UNUSED
-static int decodereach P((char *, U_LONG *));
-#endif /* UNUSED */
-
static int decodearr P((char *, int *, l_fp *));
static char * getcode P((int, struct codestring *));
static void help P((struct parse *, FILE *));
@@ -339,7 +334,7 @@ static void authenticate P((struct parse *, FILE *));
static void ntpversion P((struct parse *, FILE *));
static void warning P((char *, char *, char *));
static void error P((char *, char *, char *));
-static U_LONG getkeyid P((char *));
+static u_long getkeyid P((char *));
static void atoascii P((int, char *, char *));
static void makeascii P((int, char *, FILE *));
static char * getevents P((int));
@@ -424,7 +419,7 @@ struct xcmd builtins[] = {
#define DEFSTIMEOUT (2) /* 2 second time out after first */
#define DEFDELAY 0x51EB852 /* 20 milliseconds, l_fp fraction */
#define DEFHOST "localhost" /* default host name */
-#define LENHOSTNAME 256 /* host name is 256 characters LONG */
+#define LENHOSTNAME 256 /* host name is 256 characters long */
#define MAXCMDS 100 /* maximum commands on cmd line */
#define MAXHOSTS 100 /* maximum hosts on cmd line */
#define MAXLINE 512 /* maximum line length */
@@ -454,12 +449,12 @@ struct servent *server_entry = NULL; /* server entry for ntp */
u_short sequence;
/*
- * Holds data returned from queries. Declare buffer LONG to be sure of
+ * Holds data returned from queries. Declare buffer long to be sure of
* alignment.
*/
#define MAXFRAGS 24 /* maximum number of fragments */
#define DATASIZE (MAXFRAGS*480) /* maximum amount of data */
-LONG pktdata[DATASIZE/sizeof(LONG)];
+long pktdata[DATASIZE/sizeof(long)];
/*
* Holds association data for use with the &n operator.
@@ -597,7 +592,7 @@ static int
openhost(hname)
char *hname;
{
- U_LONG netnum;
+ u_long netnum;
char temphost[LENHOSTNAME];
if (server_entry == NULL) {
@@ -712,9 +707,9 @@ getresponse(opcode, associd, rstatus, rsize, rdata, timeo)
/*
* This is pretty tricky. We may get between 1 and MAXFRAG packets
* back in response to the request. We peel the data out of
- * each packet and collect it in one LONG block. When the last
+ * each packet and collect it in one long block. When the last
* packet in the sequence is received we'll know how much data we
- * should have had. Note we use one LONG time out, should reconsider.
+ * should have had. Note we use one long time out, should reconsider.
*/
*rsize = 0;
if (rstatus)
@@ -879,8 +874,8 @@ again:
if (debug >= 3) {
int shouldbesize;
- U_LONG key;
- U_LONG *lpkt;
+ u_long key;
+ u_long *lpkt;
int maclen;
/*
@@ -898,15 +893,15 @@ again:
printf(
"Packet shows signs of authentication (total %d, data %d, mac %d)\n",
n, shouldbesize, maclen);
- lpkt = (U_LONG *)&rpkt;
+ lpkt = (u_long *)&rpkt;
printf("%08lx %08lx %08lx %08lx %08lx %08lx\n",
- ntohl(lpkt[(n - maclen)/sizeof(U_LONG) - 3]),
- ntohl(lpkt[(n - maclen)/sizeof(U_LONG) - 2]),
- ntohl(lpkt[(n - maclen)/sizeof(U_LONG) - 1]),
- ntohl(lpkt[(n - maclen)/sizeof(U_LONG)]),
- ntohl(lpkt[(n - maclen)/sizeof(U_LONG) + 1]),
- ntohl(lpkt[(n - maclen)/sizeof(U_LONG) + 2]));
- key = ntohl(lpkt[(n - maclen) / sizeof(U_LONG)]);
+ (u_long)ntohl(lpkt[(n - maclen)/sizeof(u_long) - 3]),
+ (u_long)ntohl(lpkt[(n - maclen)/sizeof(u_long) - 2]),
+ (u_long)ntohl(lpkt[(n - maclen)/sizeof(u_long) - 1]),
+ (u_long)ntohl(lpkt[(n - maclen)/sizeof(u_long)]),
+ (u_long)ntohl(lpkt[(n - maclen)/sizeof(u_long) + 1]),
+ (u_long)ntohl(lpkt[(n - maclen)/sizeof(u_long) + 2]));
+ key = ntohl(lpkt[(n - maclen) / sizeof(u_long)]);
printf("Authenticated with keyid %lu\n", key);
if (key != 0 && key != info_auth_keyid) {
printf("We don't know that key\n");
@@ -1067,7 +1062,7 @@ sendrequest(opcode, associd, auth, qsize, qdata)
if (qsize > 0) {
memmove((char *)qpkt.data, qdata, qsize);
pktsize = qsize + CTL_HEADER_LEN;
- while (pktsize & (sizeof(U_LONG)-1)) {
+ while (pktsize & (sizeof(u_long) - 1)) {
qpkt.data[qsize++] = 0;
pktsize++;
}
@@ -1118,7 +1113,7 @@ sendrequest(opcode, associd, auth, qsize, qdata)
* cp currently points. Cp should be aligned
* properly. Then do the encryptions.
*/
- *(U_LONG *)(&qpkt.data[qsize]) = htonl(info_auth_keyid);
+ *(u_long *)(&qpkt.data[qsize]) = htonl(info_auth_keyid);
maclen = authencrypt(info_auth_keyid, (U_LONG *)&qpkt,
pktsize);
return sendpkt((char *)&qpkt, pktsize + maclen);
@@ -1542,21 +1537,22 @@ getarg(str, code, argp)
int
getnetnum(host, num, fullhost)
char *host;
- U_LONG *num;
+ u_long *num;
char *fullhost;
{
struct hostent *hp;
if (decodenetnum(host, num)) {
if (fullhost != 0) {
- (void) sprintf(fullhost,
- "%d.%d.%d.%d", ((htonl(*num)>>24)&0xff),
- ((htonl(*num)>>16)&0xff), ((htonl(*num)>>8)&0xff),
- (htonl(*num)&0xff));
+ (void) sprintf(fullhost, "%lu.%lu.%lu.%lu",
+ (u_long)((htonl(*num) >> 24) & 0xff),
+ (u_long)((htonl(*num) >> 16) & 0xff),
+ (u_long)((htonl(*num) >> 8) & 0xff),
+ (u_long)(htonl(*num) & 0xff));
}
return 1;
} else if ((hp = gethostbyname(host)) != 0) {
- memmove((char *)num, hp->h_addr, sizeof(U_LONG));
+ memmove((char *)num, hp->h_addr, sizeof(u_long));
if (fullhost != 0)
(void) strcpy(fullhost, hp->h_name);
return 1;
@@ -1573,7 +1569,7 @@ getnetnum(host, num, fullhost)
*/
char *
nntohost(netnum)
- U_LONG netnum;
+ u_long netnum;
{
if (!showhostnames)
return numtoa(netnum);
@@ -1613,7 +1609,7 @@ rtdatetolfp(str, lfp)
/*
* Catch special case
*/
- lfp->l_ui = lfp->l_uf = 0;
+ L_CLR(lfp);
return 1;
}
return 0;
@@ -1654,7 +1650,7 @@ rtdatetolfp(str, lfp)
* Catch special case. If cal.year == 0 this is a zero timestamp.
*/
if (cal.year == 0) {
- lfp->l_ui = lfp->l_uf = 0;
+ L_CLR(lfp);
return 1;
}
@@ -1748,49 +1744,18 @@ decodetime(str, lfp)
}
-#ifdef UNUSED
-/*
- * decodereach - decode a (possibly octal or hex, damn fuzzballs) reachability
- */
-static int
-decodereach(str, uval)
- char *str;
- U_LONG *uval;
-{
- U_LONG u;
-
- if (*str == '0') {
- /*
- * Could be octal or hex
- */
- if (*(str+1) == 'x' || *(str+1) == 'X')
- return hextoint(str+2, uval);
- return octtoint(str, uval);
- }
-
- if (!atouint(str, &u))
- return 0;
-
- if (u > 255)
- return octtoint(str, uval);
- *uval = u;
- return 1;
-}
-#endif /* UNUSED */
-
-
/*
* decodeint - decode an integer
*/
int
decodeint(str, val)
char *str;
- LONG *val;
+ long *val;
{
if (*str == '0') {
if (*(str+1) == 'x' || *(str+1) == 'X')
- return hextoint(str+2, (U_LONG *)val);
- return octtoint(str, (U_LONG *)val);
+ return hextoint(str+2, (u_long *)&val);
+ return octtoint(str, (u_long *)&val);
}
return atoint(str, val);
}
@@ -1802,7 +1767,7 @@ decodeint(str, val)
int
decodeuint(str, val)
char *str;
- U_LONG *val;
+ u_long *val;
{
if (*str == '0') {
if (*(str+1) == 'x' || *(str+1) == 'X')
@@ -2017,18 +1982,18 @@ delay(pcmd, fp)
FILE *fp;
{
int isneg;
- U_LONG val;
+ u_long val;
if (pcmd->nargs == 0) {
val = delay_time.l_ui * 1000 + delay_time.l_uf / 4294967;
- (void) fprintf(fp, "delay %d ms\n", val);
+ (void) fprintf(fp, "delay %lu ms\n", val);
} else {
if (pcmd->argval[0].ival < 0) {
isneg = 1;
- val = (U_LONG)(-pcmd->argval[0].ival);
+ val = (u_long)(-pcmd->argval[0].ival);
} else {
isneg = 0;
- val = (U_LONG)pcmd->argval[0].ival;
+ val = (u_long)pcmd->argval[0].ival;
}
delay_time.l_ui = val / 1000;
@@ -2092,7 +2057,7 @@ keyid(pcmd, fp)
if (info_auth_keyid == -1)
(void) fprintf(fp, "no keyid defined\n");
else
- (void) fprintf(fp, "keyid is %u\n", info_auth_keyid);
+ (void) fprintf(fp, "keyid is %lu\n", info_auth_keyid);
} else {
info_auth_keyid = pcmd->argval[0].uval;
}
@@ -2344,7 +2309,7 @@ error(fmt, st1, st2)
/*
* getkeyid - prompt the user for a keyid to use
*/
-static U_LONG
+static u_long
getkeyid(prompt)
char *prompt;
{
@@ -2368,7 +2333,7 @@ char *prompt;
if (strcmp(pbuf, "0") == 0)
return 0;
- return (U_LONG) atoi(pbuf);
+ return (u_long) atoi(pbuf);
}
@@ -2515,7 +2480,9 @@ statustoa(type, st)
case TYPE_SYS:
(void)strcpy(cb, getcode(CTL_SYS_LI(st), leap_codes));
(void)strcat(cb, ", ");
- (void)strcat(cb, getcode(CTL_SYS_SOURCE(st), sync_codes));
+ (void)strcat(cb, getcode(CTL_SYS_SOURCE(st) & ~CTL_SST_TS_PPS, sync_codes));
+ if (CTL_SYS_SOURCE(st) & CTL_SST_TS_PPS)
+ (void)strcat(cb, "/PPS");
(void)strcat(cb, ", ");
(void)strcat(cb, getevents(CTL_SYS_NEVNT(st)));
(void)strcat(cb, ", ");
@@ -2853,7 +2820,7 @@ outputarr(fp, name, narr, lfp)
static char *
tstflags(val)
- U_LONG val;
+ u_long val;
{
register char *cb, *s;
register int i;
@@ -2865,7 +2832,7 @@ tstflags(val)
if (++nextcb >= NUMCB)
nextcb = 0;
- sprintf(cb, "0x%x", val);
+ sprintf(cb, "0x%lx", val);
cb += strlen(cb);
if (val <= ((1<<8)-1)) {
if (!val) {
@@ -2909,8 +2876,9 @@ cookedprint(datatype, length, data, status, fp)
int fmt;
struct ctl_var *varlist;
l_fp lfp;
- LONG ival;
- U_LONG uval;
+ long ival;
+ u_long hval;
+ u_long uval;
l_fp lfparr[8];
int narr;
@@ -2986,12 +2954,12 @@ cookedprint(datatype, length, data, status, fp)
case HA:
case NA:
- if (!decodenetnum(value, &uval))
+ if (!decodenetnum(value, &hval))
output_raw = '?';
else if (fmt == HA)
- output(fp, name, nntohost(uval));
+ output(fp, name, nntohost(hval));
else
- output(fp, name, numtoa(uval));
+ output(fp, name, numtoa(hval));
break;
case ST:
@@ -2999,8 +2967,8 @@ cookedprint(datatype, length, data, status, fp)
break;
case RF:
- if (decodenetnum(value, &uval))
- output(fp, name, nntohost(uval));
+ if (decodenetnum(value, &hval))
+ output(fp, name, nntohost(hval));
else if ((int)strlen(value) <= 4)
output(fp, name, value);
else
@@ -3028,7 +2996,7 @@ cookedprint(datatype, length, data, status, fp)
else {
char b[10];
- (void) sprintf(b, "%03o", uval);
+ (void) sprintf(b, "%03lo", uval);
output(fp, name, b);
}
break;
diff --git a/usr.sbin/xntpd/util/tickadj.c b/usr.sbin/xntpd/util/tickadj.c
index dcf6935..796d822 100644
--- a/usr.sbin/xntpd/util/tickadj.c
+++ b/usr.sbin/xntpd/util/tickadj.c
@@ -7,8 +7,12 @@
*/
#include <stdio.h>
+#if !defined(SYS_VAX) && !defined(SYS_BSD)
+#include <unistd.h>
+#endif /* SYS_VAX */
+
#ifdef SYS_LINUX
-#include <sys/timex.h>
+#include "sys/timex.h"
struct timex txc;
@@ -42,7 +46,9 @@ main(int argc, char ** argv)
#else /* not Linux... kmem tweaking: */
#include <sys/types.h>
+#ifndef SYS_BSD
#include <sys/file.h>
+#endif
#include <sys/stat.h>
#if defined(SYS_AUX3) || defined(SYS_AUX2)
@@ -69,7 +75,7 @@ main(int argc, char ** argv)
#endif
#endif
-#ifdef SYS_PTX
+#if defined(SYS_PTX) || defined(SYS_IX86OSF1)
#define L_SET SEEK_SET
#endif
@@ -559,7 +565,7 @@ readvar(fd, off, var)
}
if (i != sizeof(int)) {
(void) fprintf(stderr, "%s: read expected %d, got %d\n",
- progname, sizeof(int), i);
+ progname, (int)sizeof(int), i);
exit(1);
}
}
diff --git a/usr.sbin/xntpd/xntpd/ntp_control.c b/usr.sbin/xntpd/xntpd/ntp_control.c
index ef9c37a..0f1dc2b 100644
--- a/usr.sbin/xntpd/xntpd/ntp_control.c
+++ b/usr.sbin/xntpd/xntpd/ntp_control.c
@@ -3,11 +3,12 @@
*/
#include <stdio.h>
#include <ctype.h>
-#include <signal.h>
#include <sys/types.h>
+#include <signal.h>
#include <sys/time.h>
#include "ntpd.h"
+#include "ntp_io.h"
#include "ntp_refclock.h"
#include "ntp_control.h"
#include "ntp_stdlib.h"
@@ -41,18 +42,13 @@ static void ctl_flushpkt P((int));
static void ctl_putdata P((char *, int, int));
static void ctl_putstr P((char *, char *, int));
static void ctl_putlfp P((char *, l_fp *));
-
-#ifdef UNUSED
-static void ctl_putulfp P((char *, l_fp *));
-#endif /* UNUSED */
-
static void ctl_putfp P((char *, s_fp));
static void ctl_putufp P((char *, u_fp));
-static void ctl_putuint P((char *, U_LONG));
-static void ctl_puthex P((char *, U_LONG));
-static void ctl_putint P((char *, LONG));
+static void ctl_putuint P((char *, u_long));
+static void ctl_puthex P((char *, u_long));
+static void ctl_putint P((char *, long));
static void ctl_putts P((char *, l_fp *));
-static void ctl_putadr P((char *, U_LONG));
+static void ctl_putadr P((char *, u_long));
static void ctl_putid P((char *, char *));
static void ctl_putarray P((char *, s_fp *, int));
static void ctl_putsys P((int));
@@ -61,7 +57,7 @@ static void ctl_putpeer P((int, struct peer *));
static void ctl_putclock P((int, struct refclockstat *, int));
#endif /* REFCLOCK */
static struct ctl_var *ctl_getitem P((struct ctl_var *, char **));
-static unsigned long count_var P((struct ctl_var *));
+static u_long count_var P((struct ctl_var *));
static void control_unspec P((struct recvbuf *, int));
static void read_status P((struct recvbuf *, int));
static void read_variables P((struct recvbuf *, int));
@@ -101,7 +97,7 @@ static struct ctl_var sys_var[] = {
{ CS_PEERID, RO, "peer" }, /* 9 */
{ CS_OFFSET, RO, "phase" }, /* 10 */
{ CS_DRIFT, RO, "freq" }, /* 11 */
- { CS_COMPLIANCE, RO, "compliance" }, /* 12 */
+ { CS_COMPLIANCE, RO, "error" }, /* 12 */
{ CS_CLOCK, RO, "clock" }, /* 13 */
{ CS_LEAPIND, RW, "leapindicator" }, /* 14 */
{ CS_LEAPWARNING, RW, "leapwarning" }, /* 15 */
@@ -231,8 +227,8 @@ static struct ctl_var clock_var[] = {
{ CC_BADDATA, RO, "baddata" }, /* 6 */
{ CC_FUDGETIME1, RO, "fudgetime1" }, /* 7 */
{ CC_FUDGETIME2, RO, "fudgetime2" }, /* 8 */
- { CC_FUDGEVAL1, RO, "fudgeval1" }, /* 9 */
- { CC_FUDGEVAL2, RO, "fudgeval2" }, /* 10 */
+ { CC_FUDGEVAL1, RO, "stratum" }, /* 9 */
+ { CC_FUDGEVAL2, RO, "refid" }, /* 10 */
{ CC_FLAGS, RO, "flags" }, /* 11 */
{ CC_DEVICE, RO, "device" }, /* 12 */
{ CC_VARLIST, RO, "clock_var_list" },/* 13 */
@@ -304,30 +300,36 @@ static struct utsname utsname;
* set peer->sstclktype to something different than CTL_SST_TS_UNSPEC.
*/
static u_char clocktypes[] = {
- CTL_SST_TS_NTP, /* REFCLK_NONE */
- CTL_SST_TS_UNSPEC, /* REFCLK_LOCALCLOCK */
- CTL_SST_TS_UHF, /* REFCLK_GPS_TRAK */
- CTL_SST_TS_HF, /* REFCLK_WWV_PST */
- CTL_SST_TS_LF, /* REFCLK_WWVB_SPECTRACOM */
- CTL_SST_TS_UHF, /* REFCLK_GOES_TRUETIME */
- CTL_SST_TS_UHF, /* REFCLK_GOES_TRAK */
- CTL_SST_TS_HF, /* REFCLK_CHU */
+ CTL_SST_TS_NTP, /* REFCLK_NONE (0) */
+ CTL_SST_TS_LOCAL, /* REFCLK_LOCALCLOCK (1) */
+ CTL_SST_TS_UHF, /* REFCLK_GPS_TRAK (2) */
+ CTL_SST_TS_HF, /* REFCLK_WWV_PST (3) */
+ CTL_SST_TS_LF, /* REFCLK_WWVB_SPECTRACOM (4) */
+ CTL_SST_TS_UHF, /* REFCLK_GOES_TRUETIME (5) */
+ CTL_SST_TS_UHF, /* REFCLK_GOES_TRAK (6) */
+ CTL_SST_TS_HF, /* REFCLK_CHU (7) */
CTL_SST_TS_LF, /* REFCLOCK_PARSE - default value - driver supplies actual value in peer->sstclktype */
- CTL_SST_TS_LF, /* REFCLK_WWVB_SPECTRACOM_HP */
- CTL_SST_TS_UHF, /* REFCLK_GPS_AS2201 */
- CTL_SST_TS_LF, /* REFCLK_OMEGA_TRUETIME */
- CTL_SST_TS_UNSPEC, /* Future expansion */
- CTL_SST_TS_UNSPEC, /* Future expansion */
- CTL_SST_TS_UNSPEC, /* Future expansion */
- CTL_SST_TS_UNSPEC /* Future expansion */
+ CTL_SST_TS_LF, /* REFCLK_GPS_MX4200 (9) */
+ CTL_SST_TS_UHF, /* REFCLK_GPS_AS2201 (10) */
+ CTL_SST_TS_LF, /* REFCLK_OMEGA_TRUETIME (11) */
+ CTL_SST_TS_UHF, /* REFCLK_IRIG_TPRO (12) */
+ CTL_SST_TS_ATOM, /* REFCLK_ATOM_LEITCH (13) */
+ CTL_SST_TS_LF, /* REFCLK_MSF_EES (14) */
+ CTL_SST_TS_UHF, /* REFCLK_GPSTM_TRUETIME (15) */
+ CTL_SST_TS_UHF, /* REFCLK_IRIG_BANCOMM (16) */
+ CTL_SST_TS_UHF, /* REFCLK_GPS_DATU (17) */
+ CTL_SST_TS_TELEPHONE, /* REFCLK_NIST_ACT (18) */
+ CTL_SST_TS_HF, /* REFCLK_WWV_HEATH (19) */
+ CTL_SST_TS_UHF, /* REFCLK_GPS_NMEA (20) */
+ CTL_SST_TS_UHF, /* REFCLK_GPS_MOTO (21) */
+ CTL_SST_TS_ATOM /* REFCLK_ATOM_PPS (22) */
};
-
/*
* Keyid used for authenticating write requests.
*/
-U_LONG ctl_auth_keyid;
+u_long ctl_auth_keyid;
/*
* We keep track of the last error reported by the system internally
@@ -339,21 +341,21 @@ static u_char ctl_sys_num_events;
/*
* Statistic counters to keep track of requests and responses.
*/
-U_LONG ctltimereset; /* time stats reset */
-U_LONG numctlreq; /* number of requests we've received */
-U_LONG numctlbadpkts; /* number of bad control packets */
-U_LONG numctlresponses; /* number of resp packets sent with data */
-U_LONG numctlfrags; /* number of fragments sent */
-U_LONG numctlerrors; /* number of error responses sent */
-U_LONG numctltooshort; /* number of too short input packets */
-U_LONG numctlinputresp; /* number of responses on input */
-U_LONG numctlinputfrag; /* number of fragments on input */
-U_LONG numctlinputerr; /* number of input pkts with err bit set */
-U_LONG numctlbadoffset; /* number of input pkts with nonzero offset */
-U_LONG numctlbadversion; /* number of input pkts with unknown version */
-U_LONG numctldatatooshort; /* data too short for count */
-U_LONG numctlbadop; /* bad op code found in packet */
-U_LONG numasyncmsgs; /* number of async messages we've sent */
+u_long ctltimereset; /* time stats reset */
+u_long numctlreq; /* number of requests we've received */
+u_long numctlbadpkts; /* number of bad control packets */
+u_long numctlresponses; /* number of resp packets sent with data */
+u_long numctlfrags; /* number of fragments sent */
+u_long numctlerrors; /* number of error responses sent */
+u_long numctltooshort; /* number of too short input packets */
+u_long numctlinputresp; /* number of responses on input */
+u_long numctlinputfrag; /* number of fragments on input */
+u_long numctlinputerr; /* number of input pkts with err bit set */
+u_long numctlbadoffset; /* number of input pkts with nonzero offset */
+u_long numctlbadversion; /* number of input pkts with unknown version */
+u_long numctldatatooshort; /* data too short for count */
+u_long numctlbadop; /* bad op code found in packet */
+u_long numasyncmsgs; /* number of async messages we've sent */
/*
* Imported from the I/O module
@@ -368,7 +370,7 @@ extern int debug;
/*
* Imported from the timer module
*/
-extern U_LONG current_time;
+extern u_long current_time;
extern struct peer *assoc_hash[];
extern int pps_control; /* flag for 1-pps signal present */
@@ -380,7 +382,7 @@ extern u_char sys_stratum;
extern s_char sys_precision;
extern s_fp sys_rootdelay;
extern u_fp sys_rootdispersion;
-extern U_LONG sys_refid;
+extern u_long sys_refid;
extern l_fp sys_reftime;
extern l_fp sys_refskew;
extern u_char sys_poll;
@@ -390,7 +392,7 @@ extern struct peer *sys_peer;
*/
extern l_fp last_offset;
extern s_fp drift_comp;
-extern int time_constant;
+extern u_fp sys_maxd;
extern int pll_control;
/*
* Imported from the leap module
@@ -419,7 +421,7 @@ static struct interface *lcl_inter;
static u_char res_authenticate;
static u_char res_authokay;
-static U_LONG res_keyid;
+static u_long res_keyid;
#define MAXDATALINELEN (72)
@@ -480,14 +482,14 @@ ctl_error(errcode)
if (res_authenticate) {
int maclen;
- *(U_LONG *)((u_char *)&rpkt + CTL_HEADER_LEN)
+ *(u_long *)((u_char *)&rpkt + CTL_HEADER_LEN)
= htonl(res_keyid);
maclen =
authencrypt(res_keyid, (U_LONG *)&rpkt, CTL_HEADER_LEN);
- sendpkt(rmt_addr, lcl_inter, (struct pkt *)&rpkt,
+ sendpkt(rmt_addr, lcl_inter, -2, (struct pkt *)&rpkt,
CTL_HEADER_LEN + maclen);
} else {
- sendpkt(rmt_addr, lcl_inter, (struct pkt *)&rpkt,
+ sendpkt(rmt_addr, lcl_inter, -3, (struct pkt *)&rpkt,
CTL_HEADER_LEN);
}
numctlerrors++;
@@ -596,17 +598,17 @@ process_control(rbufp, restrict)
properlen = (properlen + 7) & ~7;
- if ((rbufp->recv_length & (sizeof(U_LONG)-1)) == 0
+ if ((rbufp->recv_length & (sizeof(u_long)-1)) == 0
&& (maclen = (rbufp->recv_length - properlen)) >= MIN_MAC_LEN
&& maclen <= MAX_MAC_LEN) {
res_authenticate = 1;
- res_keyid = ntohl(*(U_LONG *)((u_char *)pkt + properlen));
+ res_keyid = ntohl(*(u_long *)((u_char *)pkt + properlen));
#ifdef DEBUG
if (debug >= 3)
printf(
- "recv_len %d, properlen %d, wants auth with keyid %d, MAC length=%d\n",
+ "recv_len %d, properlen %d, wants auth with keyid %ld, MAC length=%d\n",
rbufp->recv_length, properlen, res_keyid, maclen);
#endif
if (!authhavekey(res_keyid)) {
@@ -728,15 +730,18 @@ ctlsysstatus()
register u_char clock;
clock = CTL_SST_TS_UNSPEC;
- if (sys_peer != 0)
- if (sys_peer->sstclktype != CTL_SST_TS_UNSPEC)
+ if (sys_peer != 0) {
+ if (sys_peer->sstclktype != CTL_SST_TS_UNSPEC) {
clock = sys_peer->sstclktype;
- else {
+ if (pps_control)
+ clock |= CTL_SST_TS_PPS;
+ } else {
if (sys_peer->refclktype < sizeof(clocktypes))
clock = clocktypes[sys_peer->refclktype];
if (pps_control)
clock |= CTL_SST_TS_PPS;
}
+ }
return (u_short)CTL_SYS_STATUS(sys_leap, clock,
ctl_sys_num_events, ctl_sys_last_event);
}
@@ -788,6 +793,7 @@ ctl_flushpkt(more)
rpkt.sequence = htons(ctl_trap[i].tr_sequence);
sendpkt(&ctl_trap[i].tr_addr,
ctl_trap[i].tr_localaddr,
+ -4,
(struct pkt *)&rpkt, sendlen);
if (!more)
ctl_trap[i].tr_sequence++;
@@ -808,14 +814,14 @@ ctl_flushpkt(more)
*datapt++ = '\0';
totlen++;
}
- *(U_LONG *)datapt = htonl(res_keyid);
+ *(u_long *)datapt = htonl(res_keyid);
maclen =
authencrypt(res_keyid, (U_LONG *)&rpkt, totlen);
- sendpkt(rmt_addr, lcl_inter, (struct pkt *)&rpkt,
+ sendpkt(rmt_addr, lcl_inter, -5, (struct pkt *)&rpkt,
totlen + maclen);
} else {
- sendpkt(rmt_addr, lcl_inter, (struct pkt *)&rpkt,
+ sendpkt(rmt_addr, lcl_inter, -6, (struct pkt *)&rpkt,
sendlen);
}
if (more)
@@ -935,33 +941,6 @@ ctl_putlfp(tag, ts)
}
-#ifdef UNUSED
-/*
- * ctl_putlfp - write a tagged, unsigned l_fp into the response
- */
-static void
-ctl_putulfp(tag, ts)
- char *tag;
- l_fp *ts;
-{
- register char *cp, *cq;
- char buffer[200];
-
- cp = buffer;
- cq = tag;
- while (*cq != '\0')
- *cp++ = *cq++;
-
- *cp++ = '=';
- cq = ulfptoms(ts, 3);
- while (*cq != '\0')
- *cp++ = *cq++;
-
- ctl_putdata(buffer, cp - buffer, 0);
-}
-#endif /* UNUSED */
-
-
/*
* ctl_putfp - write a tagged s_fp number into the response
*/
@@ -1018,7 +997,7 @@ ctl_putufp(tag, ufp)
static void
ctl_putuint(tag, uval)
char *tag;
- U_LONG uval;
+ u_long uval;
{
register char *cp, *cq;
char buffer[200];
@@ -1029,7 +1008,7 @@ ctl_putuint(tag, uval)
*cp++ = *cq++;
*cp++ = '=';
- (void) sprintf(cp, "%u", uval);
+ (void) sprintf(cp, "%lu", uval);
while (*cp != '\0')
cp++;
@@ -1043,7 +1022,7 @@ ctl_putuint(tag, uval)
static void
ctl_puthex(tag, uval)
char *tag;
- U_LONG uval;
+ u_long uval;
{
register char *cp, *cq;
char buffer[200];
@@ -1068,7 +1047,7 @@ ctl_puthex(tag, uval)
static void
ctl_putint(tag, ival)
char *tag;
- LONG ival;
+ long ival;
{
register char *cp, *cq;
char buffer[200];
@@ -1079,7 +1058,7 @@ ctl_putint(tag, ival)
*cp++ = *cq++;
*cp++ = '=';
- (void) sprintf(cp, "%d", ival);
+ (void) sprintf(cp, "%ld", ival);
while (*cp != '\0')
cp++;
@@ -1119,7 +1098,7 @@ ctl_putts(tag, ts)
static void
ctl_putadr(tag, addr)
char *tag;
- U_LONG addr;
+ u_long addr;
{
register char *cp, *cq;
char buffer[200];
@@ -1225,13 +1204,13 @@ ctl_putsys(varid)
switch (varid) {
case CS_LEAP:
- ctl_putuint(sys_var[CS_LEAP].text, (U_LONG)sys_leap);
+ ctl_putuint(sys_var[CS_LEAP].text, sys_leap);
break;
case CS_STRATUM:
- ctl_putuint(sys_var[CS_STRATUM].text, (U_LONG)sys_stratum);
+ ctl_putuint(sys_var[CS_STRATUM].text, sys_stratum);
break;
case CS_PRECISION:
- ctl_putint(sys_var[CS_PRECISION].text, (LONG)sys_precision);
+ ctl_putint(sys_var[CS_PRECISION].text, sys_precision);
break;
case CS_ROOTDELAY:
ctl_putfp(sys_var[CS_ROOTDELAY].text, sys_rootdelay);
@@ -1241,23 +1220,23 @@ ctl_putsys(varid)
sys_rootdispersion);
break;
case CS_REFID:
- if (sys_stratum <= 1)
- ctl_putid(sys_var[CS_REFID].text, (char *)&sys_refid);
- else
+ if (sys_stratum > 1)
ctl_putadr(sys_var[CS_REFID].text, sys_refid);
+ else
+ ctl_putid(sys_var[CS_REFID].text, (char *)&sys_refid);
break;
case CS_REFTIME:
ctl_putts(sys_var[CS_REFTIME].text, &sys_reftime);
break;
case CS_POLL:
- ctl_putuint(sys_var[CS_POLL].text, (U_LONG)sys_poll);
+ ctl_putuint(sys_var[CS_POLL].text, sys_poll);
break;
case CS_PEERID:
if (sys_peer == NULL)
- ctl_putuint(sys_var[CS_PEERID].text, (U_LONG)0);
+ ctl_putuint(sys_var[CS_PEERID].text, 0);
else
ctl_putuint(sys_var[CS_PEERID].text,
- (U_LONG)sys_peer->associd);
+ sys_peer->associd);
break;
case CS_OFFSET:
ctl_putlfp(sys_var[CS_OFFSET].text, &last_offset);
@@ -1266,17 +1245,17 @@ ctl_putsys(varid)
ctl_putfp(sys_var[CS_DRIFT].text, drift_comp);
break;
case CS_COMPLIANCE:
- ctl_putuint(sys_var[CS_COMPLIANCE].text, (U_LONG)time_constant);
+ ctl_putufp(sys_var[CS_COMPLIANCE].text, sys_maxd);
break;
case CS_CLOCK:
get_systime(&tmp);
ctl_putts(sys_var[CS_CLOCK].text, &tmp);
break;
case CS_LEAPIND:
- ctl_putuint(sys_var[CS_LEAPIND].text, (U_LONG)leap_indicator);
+ ctl_putuint(sys_var[CS_LEAPIND].text, leap_indicator);
break;
case CS_LEAPWARNING:
- ctl_putuint(sys_var[CS_LEAPWARNING].text, (U_LONG)leap_warning);
+ ctl_putuint(sys_var[CS_LEAPWARNING].text, leap_warning);
break;
case CS_PROCESSOR:
#ifndef HAVE_UNAME
@@ -1297,7 +1276,7 @@ ctl_putsys(varid)
#endif /* HAVE_UNAME */
break;
case CS_KEYID:
- ctl_putuint(sys_var[CS_KEYID].text, (U_LONG)0);
+ ctl_putuint(sys_var[CS_KEYID].text, 0);
break;
case CS_REFSKEW:
ctl_putlfp(sys_var[CS_REFSKEW].text, &sys_refskew);
@@ -1378,15 +1357,15 @@ ctl_putpeer(varid, peer)
switch (varid) {
case CP_CONFIG:
ctl_putuint(peer_var[CP_CONFIG].text,
- (U_LONG)((peer->flags & FLAG_CONFIG) != 0));
+ ((peer->flags & FLAG_CONFIG) != 0));
break;
case CP_AUTHENABLE:
ctl_putuint(peer_var[CP_AUTHENABLE].text,
- (U_LONG)((peer->flags & FLAG_AUTHENABLE) != 0));
+ ((peer->flags & FLAG_AUTHENABLE) != 0));
break;
case CP_AUTHENTIC:
ctl_putuint(peer_var[CP_AUTHENTIC].text,
- (U_LONG)((peer->flags & FLAG_AUTHENTIC) != 0));
+ ((peer->flags & FLAG_AUTHENTIC) != 0));
break;
case CP_SRCADR:
ctl_putadr(peer_var[CP_SRCADR].text,
@@ -1394,33 +1373,40 @@ ctl_putpeer(varid, peer)
break;
case CP_SRCPORT:
ctl_putuint(peer_var[CP_SRCPORT].text,
- (U_LONG)ntohs(peer->srcadr.sin_port));
+ ntohs(peer->srcadr.sin_port));
break;
case CP_DSTADR:
ctl_putadr(peer_var[CP_DSTADR].text,
- peer->dstadr->sin.sin_addr.s_addr);
+ peer->processed ?
+ peer->cast_flags & MDF_BCAST ?
+ peer->dstadr->bcast.sin_addr.s_addr:
+ peer->cast_flags ?
+ peer->dstadr->sin.sin_addr.s_addr ?
+ peer->dstadr->sin.sin_addr.s_addr:
+ peer->dstadr->bcast.sin_addr.s_addr:
+ 8 : 12);
break;
case CP_DSTPORT:
ctl_putuint(peer_var[CP_DSTPORT].text,
- (U_LONG)ntohs(peer->dstadr->sin.sin_port));
+ ntohs(peer->dstadr->sin.sin_port));
break;
case CP_LEAP:
- ctl_putuint(peer_var[CP_LEAP].text, (U_LONG)peer->leap);
+ ctl_putuint(peer_var[CP_LEAP].text, peer->leap);
break;
case CP_HMODE:
- ctl_putuint(peer_var[CP_HMODE].text, (U_LONG)peer->hmode);
+ ctl_putuint(peer_var[CP_HMODE].text, peer->hmode);
break;
case CP_STRATUM:
- ctl_putuint(peer_var[CP_STRATUM].text, (U_LONG)peer->stratum);
+ ctl_putuint(peer_var[CP_STRATUM].text, peer->stratum);
break;
case CP_PPOLL:
- ctl_putuint(peer_var[CP_PPOLL].text, (U_LONG)peer->ppoll);
+ ctl_putuint(peer_var[CP_PPOLL].text, peer->ppoll);
break;
case CP_HPOLL:
- ctl_putuint(peer_var[CP_HPOLL].text, (U_LONG)peer->hpoll);
+ ctl_putuint(peer_var[CP_HPOLL].text, peer->hpoll);
break;
case CP_PRECISION:
- ctl_putint(peer_var[CP_PRECISION].text, (LONG)peer->precision);
+ ctl_putint(peer_var[CP_PRECISION].text, peer->precision);
break;
case CP_ROOTDELAY:
ctl_putfp(peer_var[CP_ROOTDELAY].text, peer->rootdelay);
@@ -1431,7 +1417,12 @@ ctl_putpeer(varid, peer)
break;
case CP_REFID:
if (peer->stratum > 1)
- ctl_putadr(peer_var[CP_REFID].text, peer->refid);
+ if (peer->flags & FLAG_REFCLOCK)
+ ctl_putadr(peer_var[CP_REFID].text,
+ peer->srcadr.sin_addr.s_addr);
+ else
+ ctl_putadr(peer_var[CP_REFID].text,
+ peer->refid);
else
ctl_putid(peer_var[CP_REFID].text,
(char *)&peer->refid);
@@ -1449,13 +1440,13 @@ ctl_putpeer(varid, peer)
ctl_putts(peer_var[CP_XMT].text, &peer->xmt);
break;
case CP_REACH:
- ctl_puthex(peer_var[CP_REACH].text, (U_LONG)peer->reach);
+ ctl_puthex(peer_var[CP_REACH].text, peer->reach);
break;
case CP_FLASH:
- ctl_puthex(peer_var[CP_FLASH].text, (U_LONG)peer->flash);
+ ctl_puthex(peer_var[CP_FLASH].text, peer->flash);
break;
case CP_VALID:
- ctl_putuint(peer_var[CP_VALID].text, (U_LONG)peer->valid);
+ ctl_putuint(peer_var[CP_VALID].text, peer->valid);
break;
case CP_TIMER:
ctl_putuint(peer_var[CP_TIMER].text,
@@ -1486,7 +1477,7 @@ ctl_putpeer(varid, peer)
(s_fp *)peer->filter_error, (int)peer->filter_nextpt);
break;
case CP_PMODE:
- ctl_putuint(peer_var[CP_PMODE].text, (U_LONG)peer->pmode);
+ ctl_putuint(peer_var[CP_PMODE].text, peer->pmode);
break;
case CP_RECEIVED:
ctl_putuint(peer_var[CP_RECEIVED].text, peer->received);
@@ -1552,8 +1543,7 @@ ctl_putclock(varid, clock, mustput)
case CC_TYPE:
if (mustput || clock->clockdesc == NULL
|| *(clock->clockdesc) == '\0') {
- ctl_putuint(clock_var[CC_TYPE].text,
- (U_LONG)clock->type);
+ ctl_putuint(clock_var[CC_TYPE].text, clock->type);
}
break;
case CC_TIMECODE:
@@ -1561,7 +1551,7 @@ ctl_putclock(varid, clock, mustput)
(int)clock->lencode);
break;
case CC_POLL:
- ctl_putuint(clock_var[CC_POLL].text, (U_LONG)clock->polls);
+ ctl_putuint(clock_var[CC_POLL].text, clock->polls);
break;
case CC_NOREPLY:
ctl_putuint(clock_var[CC_NOREPLY].text, clock->noresponse);
@@ -1589,14 +1579,17 @@ ctl_putclock(varid, clock, mustput)
break;
case CC_FUDGEVAL2:
if (mustput || (clock->haveflags & CLK_HAVEVAL2))
- ctl_putint(clock_var[CC_FUDGEVAL2].text,
- clock->fudgeval2);
+ if (clock->fudgeval1 > 1)
+ ctl_putadr(clock_var[CC_FUDGEVAL2].text,
+ clock->fudgeval2);
+ else
+ ctl_putid(clock_var[CC_FUDGEVAL2].text,
+ (char *)&clock->fudgeval2);
break;
case CC_FLAGS:
if (mustput || (clock->haveflags &
(CLK_HAVEFLAG1|CLK_HAVEFLAG2|CLK_HAVEFLAG3|CLK_HAVEFLAG4)))
- ctl_putuint(clock_var[CC_FLAGS].text,
- (U_LONG)clock->flags);
+ ctl_putuint(clock_var[CC_FLAGS].text, clock->flags);
break;
case CC_DEVICE:
if (clock->clockdesc == NULL || *(clock->clockdesc) == '\0') {
@@ -1966,8 +1959,8 @@ write_variables(rbufp, restrict)
register struct ctl_var *v;
register int ext_var;
char *valuep;
- LONG val;
- u_char leapind, leapwarn;
+ long val;
+ int leapind, leapwarn;
/*
* If he's trying to write into a peer tell him no way
@@ -1985,8 +1978,8 @@ write_variables(rbufp, restrict)
/*
* Set flags to not-in-sync so we can tell when we get something.
*/
- leapind = (u_char)~0;
- leapwarn = (u_char)~0;
+ leapind = ~0;
+ leapwarn = ~0;
/*
* Look through the variables. Dump out at the first sign of trouble.
@@ -2037,13 +2030,13 @@ write_variables(rbufp, restrict)
switch(v->code) {
case CS_LEAP:
case CS_LEAPIND:
- leapind = (u_char)val;
+ leapind = val;
break;
case CS_LEAPWARNING:
- leapwarn = (u_char)val;
+ leapwarn = val;
break;
default:
- ctl_error(CERR_UNSPEC); /* our fault, really */
+ ctl_error(CERR_UNSPEC); /* our fault, really */
return;
}
}
@@ -2052,7 +2045,7 @@ write_variables(rbufp, restrict)
/*
* If we got anything, do it.
*/
- if (leapind != (u_char)~0 || leapwarn != (u_char)~0) {
+ if (leapind != ~0 || leapwarn != ~0) {
if (!leap_setleap((int)leapind, (int)leapwarn)) {
ctl_error(CERR_PERMISSION);
return;
@@ -2436,18 +2429,32 @@ report_event(err, peer)
if (!(err & PEER_EVENT)) {
if (ctl_sys_num_events < CTL_SYS_MAXEVENTS)
ctl_sys_num_events++;
- if (ctl_sys_last_event != (u_char)err)
- syslog(LOG_INFO, "system event %x status %x",
- err, ctlsysstatus());
- ctl_sys_last_event = (u_char)err;
+ if (ctl_sys_last_event != (u_char)err) {
+ syslog(LOG_INFO, "system event %x status %x",
+ err, ctlsysstatus());
+#ifdef DEBUG
+ if (debug)
+ printf("report_event: system event %x status %x\n",
+ err, ctlsysstatus());
+#endif
+ ctl_sys_last_event = (u_char)err;
+ }
} else if (peer != 0) {
peer->last_event = (u_char)(err & ~PEER_EVENT);
if (peer->num_events < CTL_PEER_MAXEVENTS)
- peer->num_events++;
+ peer->num_events++;
syslog(LOG_INFO, "peer %s event %x status %x",
ntoa(&peer->srcadr), err, ctlpeerstatus(peer));
+#ifdef DEBUG
+ if (debug)
+ printf("peer %s event %x status %x\n",
+ ntoa(&peer->srcadr), err, ctlpeerstatus(peer));
+#endif
} else {
syslog(LOG_ERR, "report_event: err %x, no peer", err);
+#ifdef DEBUG
+ printf("report_event: err %x, no peer\n", err);
+#endif
return;
}
@@ -2489,10 +2496,8 @@ report_event(err, peer)
clock.kv_list = (struct ctl_var *)0;
refclock_control(&peer->srcadr,
- (struct refclockstat *)0,
- &clock);
- ctl_puthex("refclockstatus",
- (U_LONG)ctlclkstatus(&clock));
+ (struct refclockstat *)0, &clock);
+ ctl_puthex("refclockstatus", ctlclkstatus(&clock));
for (i = 1; i <= CC_MAXCODE; i++)
ctl_putclock(i, &clock, 0);
@@ -2528,7 +2533,7 @@ report_event(err, peer)
&clock);
ctl_puthex("refclockstatus",
- (U_LONG)ctlclkstatus(&clock));
+ ctlclkstatus(&clock));
for (i = 1; i <= CC_MAXCODE; i++)
ctl_putclock(i, &clock, 0);
@@ -2572,11 +2577,11 @@ ctl_clr_stats()
numasyncmsgs = 0;
}
-static unsigned long
+static u_long
count_var(k)
struct ctl_var *k;
{
- register unsigned long c;
+ register u_long c;
c = 0;
while (k && !(k++->flags & EOV))
@@ -2588,10 +2593,10 @@ count_var(k)
char *
add_var(kv, size, def)
struct ctl_var **kv;
- unsigned long size;
+ u_long size;
int def;
{
- register unsigned long c;
+ register u_long c;
register struct ctl_var *k;
c = count_var(*kv);
@@ -2617,7 +2622,7 @@ void
set_var(kv, data, size, def)
struct ctl_var **kv;
char *data;
- unsigned long size;
+ u_long size;
int def;
{
register struct ctl_var *k;
@@ -2665,7 +2670,7 @@ set_var(kv, data, size, def)
void
set_sys_var(data, size, def)
char *data;
- unsigned long size;
+ u_long size;
int def;
{
set_var(&ext_sys_var, data, size, def);
diff --git a/usr.sbin/xntpd/xntpd/ntp_loopfilter.c b/usr.sbin/xntpd/xntpd/ntp_loopfilter.c
index 13cbd61..6fcf0a0 100644
--- a/usr.sbin/xntpd/xntpd/ntp_loopfilter.c
+++ b/usr.sbin/xntpd/xntpd/ntp_loopfilter.c
@@ -1,7 +1,6 @@
/*
* ntp_loopfilter.c - implements the NTP loop filter algorithm
*/
-
#include <stdio.h>
#include <ctype.h>
#include <sys/time.h>
@@ -10,45 +9,19 @@
#include "ntpd.h"
#include "ntp_io.h"
#include "ntp_unixtime.h"
-
-#if defined(PPS) || defined(PPSCLK) || defined(PPSPPS)
-#include <sys/stat.h>
-#include "ntp_refclock.h"
-#endif /* PPS || PPSCLK || PPSPPS */
-
-#if defined(PPSCLK) || defined(PPSPPS)
-#if defined(HAVE_BSD_TTYS)
-#include <sgtty.h>
-#endif /* HAVE_BSD_TTYS */
-
-#if defined(HAVE_SYSV_TTYS)
-#include <termio.h>
-#endif /* HAVE_SYSV_TTYS */
-
-#ifdef HAVE_TERMIOS
-#include <termios.h>
-#endif
-#if defined(STREAM)
-#include <stropts.h>
-#if defined(PPSCLK)
-#include <sys/clkdefs.h>
-#endif /* PPSCLK */
-#endif /* STREAM */
-
-#endif /* PPSCLK || PPSPPS */
-
-#if defined(PPSPPS)
-#include <sys/ppsclock.h>
-#endif /* PPSPPS */
-
#include "ntp_stdlib.h"
#ifdef KERNEL_PLL
+#ifdef HAVE_SYS_TIMEX_H
#include <sys/timex.h>
+#else
+#include "sys/timex.h"
+#endif /* not HAVE_SYS_TIMEX_H */
+
#ifndef NTP_SYSCALLS_LIBC
#define ntp_gettime(t) syscall(SYS_ntp_gettime, (t))
#define ntp_adjtime(t) syscall(SYS_ntp_adjtime, (t))
-#endif
+#endif /* not NTP_SYSCALLS_LIBC */
#endif /* KERNEL_PLL */
/*
@@ -61,122 +34,83 @@
* seconds. When adjustments are capped inside this range (see
* CLOCK_MAX_{I,F}) both the clock_adjust and the compliance
* registers should be fine. (When the compliance is above 16, it
- * will at most accumulate 2**CLOCK_MULT times the maximum offset,
+ * will at most accumulate 2 ** CLOCK_MULT times the maximum offset,
* which means it fits in a s_fp.)
*
* The skew compensation is a special case. In version 2, it was
- * kept in ms/4s (i.e., CLOCK_FREQ was 10). In version 3 (Section 5)
- * it seems to be 2**-16ms/4s in a s_fp for a maximum of +-125ppm
+ * kept in ms / 4s (i.e., CLOCK_FREQ was 10). In version 3 (Section 5)
+ * it seems to be 2 ** -16ms / 4s in a s_fp for a maximum of +-125ppm
* (stated maximum 100ppm). Since this seems about to change to a
- * larger range, it will be kept in units of 2**-20 (CLOCK_DSCALE)
+ * larger range, it will be kept in units of 2 ** -20 (CLOCK_DSCALE)
* in an s_fp (mainly because that's nearly the same as parts per
* million). Note that this is ``seconds per second'', whereas a
* clock adjustment is a 32-bit fraction of a second to be applied
- * every 2**CLOCK_ADJ seconds; to find it, shift the drift right by
- * (CLOCK_DSCALE-16-CLOCK_ADJ). When updating the drift, on the other
- * hand, the CLOCK_FREQ factor from the spec assumes the value to be
- * in ``seconds per 4 seconds''; to get our units, CLOCK_ADJ must be
+ * every 2 ** CLOCK_ADJ seconds; to find it, shift the drift right by
+ * (CLOCK_DSCALE - 16 - CLOCK_ADJ). When updating the drift, on the
+ * other hand, the CLOCK_FREQ factor from the spec assumes the value to
+ * be in ``seconds per 4 seconds''; to get our units, CLOCK_ADJ must be
* added to the shift.
+ *
+ * Kernel PLL/PPS state machine
+ *
+ * The following state machine is used when the kernel PLL modifications
+ * described in the README.kernel file are present. The initial
+ * configuration routine loop_config() sets up the initial frequency
+ * estimate and tests if the kernel modifications are present. If so and
+ * the PLL mode bit 1 (STA_PLL) of the mode word in the drift file
+ * (ntp.drift) is set, pll_control is set true and the kernel pll is
+ * enabled. If the kernel modifications are present and the PLL mode bit
+ * 2 (STA_PPSFREQ) is set, the kernel PPS frequency discipline is
+ * enabled.
+ *
+ * Each update to a prefer peer sets pps_update true if it survives the
+ * intersection algorithm and its time is within range. The PPS time
+ * discipline is enabled (STA_PPSTIME bit set in the status word) when
+ * pps_update is true and the PPS frequency discipline is enabled. If
+ * the PPS time discipline is enabled and the kernel reports a PPS
+ * signal is present, the pps_control variable is set to the current
+ * time. If the current time is later than pps_control by PPS_MAXAGE
+ * (120 s), this variable is set to zero.
+ *
+ * The pll_enable switch can be set both at configuration time and at
+ * run time using xntpdc. If true, the kernel modifications are active
+ * as described above; if false, the kernel is bypassed entirely (except
+ * for the PPS frequency update, if enabled) and the daemon PLL used
+ * instead.
*/
-
-/*
- * Macro to compute log2(). We don't want to to this very often, but
- * needs what must.
- */
-#define LOG2(r, t) \
- do { \
- LONG x = t; \
- r = 0; \
- while(x >> 1) \
- r++; \
- }
-
#define RSH_DRIFT_TO_FRAC (CLOCK_DSCALE - 16)
#define RSH_DRIFT_TO_ADJ (RSH_DRIFT_TO_FRAC - CLOCK_ADJ)
#define RSH_FRAC_TO_FREQ (CLOCK_FREQ + CLOCK_ADJ - RSH_DRIFT_TO_FRAC)
-#define PPS_MAXAGE 120 /* pps signal timeout (s) */
-#define PPS_MAXUPDATE 600 /* pps update timeout (s) */
+#define PPS_MAXAGE 120 /* kernel pps signal timeout (s) */
/*
* Program variables
*/
- l_fp last_offset; /* last adjustment done */
-static LONG clock_adjust; /* clock adjust (fraction only) */
-
- s_fp drift_comp; /* drift compensation register */
-static s_fp max_comp; /* drift limit imposed by max host clock slew */
-
- int time_constant; /* log2 of time constant (0 .. 4) */
-static U_LONG tcadj_time; /* last time-constant adjust time */
-
- U_LONG watchdog_timer; /* watchdog timer, in seconds */
-static int first_adjustment; /* 1 if waiting for first adjustment */
-static int tc_counter; /* time-constant hold counter */
-
-static l_fp pps_offset; /* filtered pps offset */
-static u_fp pps_dispersion; /* pps dispersion */
-static U_LONG pps_time; /* last pps sample time */
-
- int pps_control; /* true if working pps signal */
+ l_fp last_offset; /* last clock offset */
+ u_long last_time; /* time of last clock update (s) */
+ u_fp clock_stability; /* clock stability (ppm) */
+ s_fp clock_frequency; /* clock frequency error (ppm) */
+ s_fp drift_comp; /* pll frequency (ppm) */
+static long clock_adjust; /* clock adjust (fraction only) */
+static s_fp max_comp; /* max frequency offset (ppm) */
+ int tc_counter; /* poll-adjust counter */
+ int pll_status; /* status bits for kernel pll */
int pll_control; /* true if working kernel pll */
-static l_fp pps_delay; /* pps tuning offset */
- U_LONG pps_update; /* last pps update time */
+ int pll_enable; /* true if pll enabled */
+ u_long pps_control; /* last pps sample time */
+ int pps_update; /* pps update valid */
int fdpps = -1; /* pps file descriptor */
-#if defined(PPS) || defined(PPSCLK) || defined(PPSPPS)
-/*
- * This module has support for a 1-pps signal to fine-tune the local
- * clock. The signal is optional; when present and operating within
- * given tolerances in frequency and jitter, it is used to discipline
- * the local clock. In order for this to work, the local clock must be
- * set to within +-500 ms by another means, such as a radio clock or
- * NTP itself. The 1-pps signal is connected via a serial port and
- * gadget box consisting of a one-shot and EIA level-converter. When
- * operated at 38.4 kbps with a SPARCstation IPC, this arrangement has a
- * worst-case jitter less than 26 us. The pps delay configuration
- * declaration can be used to compensate for miscellaneous uart and
- * os delays. Allow about 247 us for uart delays at 38400 bps and
- * -1 ms for SunOS streams nonsense.
- */
-
-/*
- * A really messy way to map an integer baud rate to the system baud rate.
- * There should be a better way.
- */
-#define SYS_BAUD(i) \
- ( i == 38400 ? B38400 : \
- ( i == 19200 ? B19200 : \
- ( i == 9600 ? B9600 : \
- ( i == 4800 ? B4800 : \
- ( i == 2400 ? B2400 : \
- ( i == 1200 ? B1200 : \
- ( i == 600 ? B600 : \
- ( i == 300 ? B300 : 0 ))))))))
-
-#define PPS_BAUD B38400 /* default serial port speed */
-timecode */
-#define PPS_DEV "/dev/pps" /* pps port */
-#define PPS_FAC 3 /* pps shift (log2 trimmed samples) */
-#define PPS_TRIM 6 /* samples trimmed from median filter */
-#define NPPS ((1 << PPS_FAC) + 2 * PPS_TRIM) /* pps filter size */
-#define PPS_XCPT "\377" /* intercept character */
-
-#if defined(PPSCLK)
-static struct refclockio io; /* given to the I/O handler */
-static int pps_baud; /* baud rate of PPS line */
-#endif /* PPSCLK */
-static U_LONG nsamples; /* number of pps samples collected */
-static LONG samples[NPPS]; /* median filter for pps samples */
-
-#endif /* PPS || PPSCLK || PPSPPS */
-
/*
* Imported from the ntp_proto module
*/
-extern u_char sys_stratum;
-extern s_fp sys_rootdelay;
-extern u_fp sys_rootdispersion;
-extern s_char sys_precision;
+extern s_fp sys_rootdelay; /* root delay */
+extern u_fp sys_rootdispersion; /* root dispersion */
+extern struct peer *sys_peer; /* system peer pointer */
+extern u_char sys_poll; /* log2 of system poll interval */
+extern u_char sys_leap; /* system leap bits */
+extern l_fp sys_refskew; /* accumulated skew since last update */
+extern u_fp sys_maxd; /* max dispersion of survivor list */
/*
* Imported from ntp_io.c
@@ -191,31 +125,13 @@ extern int debug; /* global debug flag */
/*
* Imported from timer module
*/
-extern U_LONG current_time; /* like it says, in seconds */
-
-/*
- * sys_poll and sys_refskew are set here
- */
-extern u_char sys_poll; /* log2 of system poll interval */
-extern u_char sys_leap; /* system leap bits */
-extern l_fp sys_refskew; /* accumulated skew since last update */
-extern u_fp sys_maxd; /* max dispersion of survivor list */
+extern u_long current_time; /* like it says, in seconds */
/*
* Imported from leap module
*/
extern u_char leapbits; /* sanitized leap bits */
-/*
- * Function prototypes
- */
-#if defined(PPS) || defined(PPSCLK) || defined(PPSPPS)
-int pps_sample P((l_fp *));
-#if defined(PPSCLK)
-static void pps_receive P((struct recvbuf *));
-#endif /* PPSCLK */
-#endif /* PPS || PPSCLK || PPSPPS */
-
#if defined(KERNEL_PLL)
#define MOD_BITS (MOD_OFFSET | MOD_MAXERROR | MOD_ESTERROR | \
MOD_STATUS | MOD_TIMECONST)
@@ -225,7 +141,6 @@ extern int syscall P((int, void *, ...));
#endif /* no NTP syscalls in libc */
void pll_trap P((void));
-static int pll_status; /* status bits for kernel pll */
static struct sigvec sigsys; /* current sigvec status */
static struct sigvec newsigsys; /* new sigvec status */
#endif /* KERNEL_PLL */
@@ -236,299 +151,164 @@ static struct sigvec newsigsys; /* new sigvec status */
void
init_loopfilter()
{
- extern U_LONG tsf_maxslew;
- U_LONG tsf_limit;
-#if defined(PPSCLK)
- int fd232;
-#endif /* PPSCLK */
- clock_adjust = 0;
- drift_comp = 0;
- time_constant = 0;
- tcadj_time = 0;
- watchdog_timer = 0;
- tc_counter = 0;
- last_offset.l_i = 0;
- last_offset.l_f = 0;
- first_adjustment = 1;
+ extern u_long tsf_maxslew;
+ u_long tsf_limit;
-/*
- * Limit for drift_comp, minimum of two values. The first is to avoid
- * signed overflow, the second to keep within 75% of the maximum
- * adjustment possible in adj_systime().
- */
+ /*
+ * Limit for drift_comp, minimum of two values. The first is to
+ * avoid signed overflow, the second to keep within 75% of the
+ * maximum adjustment possible in adj_systime().
+ */
max_comp = 0x7fff0000;
tsf_limit = ((tsf_maxslew >> 1) + (tsf_maxslew >> 2));
if ((max_comp >> RSH_DRIFT_TO_ADJ) > tsf_limit)
max_comp = tsf_limit << RSH_DRIFT_TO_ADJ;
- pps_control = 0;
-#if defined(PPS) || defined(PPSCLK) || defined(PPSPPS)
-#if defined(PPSCLK)
- pps_baud = PPS_BAUD;
-#endif /* PPSCLK */
- pps_delay.l_i = 0;
- pps_delay.l_f = 0;
- pps_time = pps_update = 0;
- nsamples = 0;
-#if defined(PPSCLK)
-
- /*
- * Open pps serial port. We don't care if the serial port comes
- * up; if not, we just use the timecode. Therefore, if anything
- * goes wrong, just reclaim the resources and continue.
- */
- fd232 = open(PPS_DEV, O_RDONLY);
- if (fd232 == -1) {
- syslog(LOG_ERR, "loopfilter: open of %s: %m", PPS_DEV);
- return;
- }
-
-#if !defined(HPUXGADGET) /* dedicated to Ken Stone */
-#if defined(HAVE_SYSV_TTYS)
- /*
- * System V serial line parameters (termio interface)
- */
- PPSCLK SUPPORT NOT AVAILABLE IN TERMIO INTERFACE
-#endif /* HAVE_SYSV_TTYS */
-#if defined(HAVE_TERMIOS)
- /*
- * POSIX serial line parameters (termios interface)
- *
- * The PPSCLK option provides timestamping at the driver level.
- * It uses a 1-pps signal and level converter (gadget box) and
- * requires the tty_clk streams module and SunOS 4.1.1 or
- * later.
- */
- { struct termios ttyb, *ttyp;
-
- ttyp = &ttyb;
- if (tcgetattr(fd232, ttyp) < 0) {
- syslog(LOG_ERR,
- "loopfilter: tcgetattr(%s): %m", PPS_DEV);
- goto screwed;
- }
- ttyp->c_iflag = IGNBRK|IGNPAR|ICRNL;
- ttyp->c_oflag = 0;
- ttyp->c_cflag = PPS_BAUD|CS8|CLOCAL|CREAD;
- ttyp->c_lflag = ICANON;
- ttyp->c_cc[VERASE] = ttyp->c_cc[VKILL] = '\0';
- if (tcsetattr(fd232, TCSANOW, ttyp) < 0) {
- syslog(LOG_ERR,
- "loopfilter: tcsetattr(%s): %m", PPS_DEV);
- goto screwed;
- }
- if (tcflush(fd232, TCIOFLUSH) < 0) {
- syslog(LOG_ERR,
- "loopfilter: tcflush(%s): %m", PPS_DEV);
- goto screwed;
- }
- }
-#endif /* HAVE_TERMIOS */
-#if defined(STREAM)
- while (ioctl(fd232, I_POP, 0 ) >= 0) ;
- if (ioctl(fd232, I_PUSH, "clk") < 0) {
- syslog(LOG_ERR,
- "loopfilter: ioctl(%s, I_PUSH, clk): %m", PPS_DEV);
- goto screwed;
- }
- if (ioctl(fd232, CLK_SETSTR, PPS_XCPT) < 0) {
- syslog(LOG_ERR,
- "loopfilter: ioctl(%s, CLK_SETSTR, PPS_XCPT): %m", PPS_DEV);
- goto screwed;
- }
-#endif /* STREAM */
-#if defined(HAVE_BSD_TTYS)
- /*
- * 4.3bsd serial line parameters (sgttyb interface)
- *
- * The PPSCLK option provides timestamping at the driver level.
- * It uses a 1-pps signal and level converter (gadget box) and
- * requires the tty_clk line discipline and 4.3bsd or later.
- */
- { struct sgttyb ttyb;
- int ldisc = CLKLDISC;
-
- if (ioctl(fd232, TIOCGETP, &ttyb) < 0) {
- syslog(LOG_ERR,
- "loopfilter: ioctl(%s, TIOCGETP): %m", PPS_DEV);
- goto screwed;
- }
- ttyb.sg_ispeed = ttyb.sg_ospeed = PPS_BAUD;
- ttyb.sg_erase = ttyb.sg_kill = '\r';
- ttyb.sg_flags = RAW;
- if (ioctl(fd232, TIOCSETP, &ttyb) < 0) {
- syslog(LOG_ERR,
- "loopfilter: ioctl(%s, TIOCSETP): %m", PPS_DEV);
- goto screwed;
- }
- if (ioctl(fd232, TIOCSETD, &ldisc) < 0) {
- syslog(LOG_ERR,
- "loopfilter: ioctl(%s, TIOCSETD): %m", PPS_DEV);
- goto screwed;
- }
- }
-#endif /* HAVE_BSD_TTYS */
-#endif /* HPUXGADGET */
- fdpps = fd232;
-
/*
- * Insert in device list.
+ * Reset clockworks
*/
- io.clock_recv = pps_receive;
- io.srcclock = (caddr_t)NULL;
- io.datalen = 0;
- io.fd = fdpps;
-#if defined(HPUXGADGET)
- if (!io_addclock_simple(&io))
-#else
- if (!io_addclock(&io))
-#endif /* HPUXGADGET */
- goto screwed;
- return;
+ drift_comp = 0;
+ clock_adjust = 0;
+ tc_counter = 0;
+ sys_poll = NTP_MINPOLL;
- /*
- * Something broke. Reclaim resources.
- */
-screwed:
- (void)close(fdpps);
- return;
-#endif /* PPSCLK */
-#endif /* PPS || PPSCLK || PPSPPS */
+ L_CLR(&last_offset);
+ last_time = 0;
+ clock_frequency = 0;
+ clock_stability = 0;
+ pps_update = pps_control = 0;
}
/*
* local_clock - the NTP logical clock loop filter. Returns 1 if the
- * clock was stepped, 0 if it was slewed and -1 if it is
- * hopeless.
+ * clock was stepped, 0 if it was slewed and -1 if it is hopeless.
*/
int
local_clock(fp_offset, peer)
l_fp *fp_offset; /* best offset estimate */
struct peer *peer; /* from peer - for messages */
{
- register LONG offset;
- register U_LONG tmp_ui;
- register U_LONG tmp_uf;
- register LONG tmp;
- int isneg;
+ long offset;
+ long tmp;
+ int return_code;
+ l_fp ftmp;
+ s_fp stmp;
+ u_fp smax;
+ long allan;
+ long interval;
#if defined(KERNEL_PLL)
struct timex ntv;
#endif /* KERNEL_PLL */
+ /*
+ * Initialize estimated measurement error and Allan variance
+ * intercept point. The measurement error is assumed the sum of
+ * the peer dispersion plus select dispersion, which seems
+ * reasonable. The Allan variance intercept point is assumed
+ * at MAXSEC for reference clocks and twice that for peer
+ * clocks, which seems cowardly.
+ */
+ if (peer->refclktype)
+ allan = CLOCK_MAXSEC;
+ else
+ allan = CLOCK_MAXSEC << 1;
+
+ if (!last_time)
+ last_time = current_time;
+ interval = (long)(current_time - last_time);
+ clock_adjust = 0;
+ offset = fp_offset->l_f;
+ smax = peer->dispersion + peer->selectdisp;
+ return_code = 0;
+
#ifdef DEBUG
if (debug > 1)
- printf("local_clock(%s, %s)\n", lfptoa(fp_offset, 6),
- ntoa(&peer->srcadr));
+ printf(
+ "local_clock: offset %s peer %s watch %ld)\n",
+ lfptoa(fp_offset, 6), ntoa(&peer->srcadr),
+ interval);
#endif
/*
- * Take the absolute value of the offset
- */
- tmp_ui = fp_offset->l_ui;
- tmp_uf = fp_offset->l_uf;
- if (M_ISNEG(tmp_ui, tmp_uf)) {
- M_NEG(tmp_ui, tmp_uf);
- isneg = 1;
- } else
- isneg = 0;
-
- /*
* If the clock is way off, don't tempt fate by correcting it.
*/
- if (tmp_ui >= CLOCK_WAYTOOBIG) {
+ ftmp = *fp_offset;
+ if (L_ISNEG(&ftmp))
+ L_NEG(&ftmp);
+ if (ftmp.l_ui >= CLOCK_WAYTOOBIG) {
syslog(LOG_ERR,
- "Clock appears to be %u seconds %s, something may be wrong",
- tmp_ui, isneg>0?"fast":"slow");
+ "time error %s is way too large (set clock manually)",
+ lfptoa(fp_offset, 6));
#ifndef BIGTIMESTEP
return (-1);
#endif /* BIGTIMESTEP */
- }
/*
- * Save this offset for later perusal
+ * If the magnitude of the offset is greater than CLOCK.MAX
+ * (128 ms), reset the time and frequency. We are quite
+ * aggresive here, since the intrinsic clock oscillator
+ * frequency error can be quite large, sometimes over +-300 ppm.
+ * With something this large and a noisy peer, the casual time
+ * updates wander right through the acceptable range, causing
+ * this section to trigger.
*/
- last_offset = *fp_offset;
+ } else if (ftmp.l_ui > CLOCK_MAX_I || (ftmp.l_ui == CLOCK_MAX_I
+ && ftmp.l_uf >= CLOCK_MAX_F)) {
+ tc_counter = 0;
+ sys_poll = peer->minpoll;
- /*
- * If the magnitude of the offset is greater than CLOCK.MAX,
- * step the time and reset the registers.
- */
- if (tmp_ui > CLOCK_MAX_I || (tmp_ui == CLOCK_MAX_I
- && (U_LONG)tmp_uf >= (U_LONG)CLOCK_MAX_F)) {
- if (watchdog_timer < CLOCK_MINSTEP) {
- /* Mustn't step yet, pretend we adjusted. */
- syslog(LOG_INFO,
- "clock correction %s too large (ignored)\n",
- lfptoa(fp_offset, 6));
- return (0);
- }
- syslog(LOG_NOTICE, "clock reset (%s) %s\n",
+ /*
+ * Either we are not in synchronization, or we have gone
+ * CLOCK_MINSTEP (900 s) since the last acceptable
+ * update. We step the clock and leave the frequency
+ * alone. Since the clock filter has been reset, the
+ * dispersions will be high upon recovery and the quick-
+ * march code below will trigger to keep the clock in
+ * bounds.
+ */
+ if (sys_leap == LEAP_NOTINSYNC || interval >
+ CLOCK_MINSTEP) {
+ step_systime(fp_offset);
+ syslog(LOG_NOTICE,
+
+ "time reset (%s) %s s",
#ifdef SLEWALWAYS
- "slew",
+ "slew",
#else
- "step",
+ "step",
#endif
- lfptoa(fp_offset, 6));
- step_systime(fp_offset);
- clock_adjust = 0;
- watchdog_timer = 0;
- first_adjustment = 1;
- pps_update = 0;
- return (1);
- }
+ lfptoa(fp_offset, 6));
+ return_code = 1;
+
+ /*
+ * The local clock is out of range, but we haven't
+ * allowed enough time for the peer (usually a radio
+ * clock) to recover after a leap second. Pretend we wuz
+ * never here.
+ */
+ } else
+ return (return_code);
/*
- * Here we've got an offset small enough to slew. Note that
- * since the offset is small we don't have to carry the damned
- * high order longword in our calculations.
- *
- * The time constant and sample interval are approximated with
- * shifts, as in Section 5 of the v3 spec. The spec procedure
- * looks strange, as an interval of 64 to 127 seconds seems to
- * cause multiplication with 128 (and so on). This code lowers
- * the multiplier by one bit.
- *
- * The time constant update goes after adjust and skew updates,
- * as in appendix G.
- */
- /*
- * If pps samples are valid, update offset, root delay and
- * root dispersion. Also, set the system stratum to 1, even if
- * the source of approximate time runs at a higher stratum. This
- * may be a dramatic surprise to high-stratum clients, since all
- * of a sudden this server looks like a stratum-1 clock.
- */
- if (pps_control) {
- last_offset = pps_offset;
- sys_maxd = pps_dispersion;
- sys_stratum = 1;
- sys_rootdelay = 0;
- offset = LFPTOFP(&pps_offset);
- if (offset < 0)
- offset = -offset;
- sys_rootdispersion = offset + pps_dispersion;
- }
- offset = last_offset.l_f;
-
- /*
- * The pll_control is active when the phase-lock code is
+ * This code segment works when the clock-adjustment code is
* implemented in the kernel, which at present is only in the
- * (modified) SunOS 4.1.x, Ultrix 4.3 and OSF/1 kernels. In the
+ * (modified) SunOS 4.1, Ultrix 4.3 and OSF/1 kernels. In the
* case of the DECstation 5000/240 and Alpha AXP, additional
- * kernal modifications provide a true microsecond clock. We
- * know the scaling of the frequency variable (s_fp) is the
- * same as the kernel variable (1 << SHIFT_USEC = 16).
- *
- * For kernels with the PPS discipline, the current offset and
- * dispersion are set from kernel variables to maintain
- * beauteous displays, but don't do much of anything.
- *
- * In the case of stock kernels the phase-lock loop is
- * implemented the hard way and the clock_adjust and drift_comp
- * computed as required.
- */
- if (pll_control) {
+ * kernel modifications provide a true microsecond clock. We
+ * know the scaling of the frequency variable (s_fp) is the same
+ * as the kernel variable (1 << SHIFT_USEC = 16).
+ */
#if defined(KERNEL_PLL)
+ } else if (pll_control && pll_enable) {
+ l_fp pps_offset;
+ u_fp pps_dispersion;
+
+ /*
+ * We initialize the structure for the ntp_adjtime()
+ * system call. We have to convert everything to
+ * microseconds first. Afterwards, remember the
+ * frequency offset for the drift file.
+ */
memset((char *)&ntv, 0, sizeof ntv);
ntv.modes = MOD_BITS;
if (offset >= 0) {
@@ -537,210 +317,310 @@ local_clock(fp_offset, peer)
TSFTOTVU(-offset, ntv.offset);
ntv.offset = -ntv.offset;
}
- TSFTOTVU(sys_rootdispersion + sys_rootdelay / 2, ntv.maxerror);
+ TSFTOTVU(sys_rootdispersion + sys_rootdelay / 2,
+ ntv.maxerror);
TSFTOTVU(sys_rootdispersion, ntv.esterror);
- ntv.status = pll_status;
- if (pps_update)
+ ntv.status = pll_status & (STA_PLL | STA_PPSFREQ);
+ if (pps_update && pll_status & STA_PPSFREQ)
ntv.status |= STA_PPSTIME;
if (sys_leap & LEAP_ADDSECOND &&
- sys_leap & LEAP_DELSECOND)
+ sys_leap & LEAP_DELSECOND)
ntv.status |= STA_UNSYNC;
else if (sys_leap & LEAP_ADDSECOND)
ntv.status |= STA_INS;
else if (sys_leap & LEAP_DELSECOND)
ntv.status |= STA_DEL;
- ntv.constant = time_constant;
+ ntv.constant = min(peer->ppoll, sys_poll) - NTP_MINPOLL;
(void)ntp_adjtime(&ntv);
drift_comp = ntv.freq;
- if (ntv.status & STA_PPSTIME && ntv.status & STA_PPSSIGNAL
- && ntv.shift) {
- if (ntv.offset >= 0) {
+ pll_status = ntv.status;
+
+ /*
+ * If the kernel pps discipline is working, monitor its
+ * performance.
+ */
+ if (pll_status & STA_PPSTIME && pll_status &
+ STA_PPSSIGNAL && ntv.shift) {
+ if (ntv.offset >= 0)
TVUTOTSF(ntv.offset, offset);
- } else {
+ else {
TVUTOTSF(-ntv.offset, offset);
offset = -offset;
}
- pps_offset.l_i = pps_offset.l_f = 0;
- M_ADDF(pps_offset.l_i, pps_offset.l_f, offset);
+ L_CLR(&pps_offset);
+ L_ADDF(&pps_offset, offset);
TVUTOTSF(ntv.jitter, tmp);
pps_dispersion = (tmp >> 16) & 0xffff;
- pps_time = current_time;
+ if (!pps_control)
+ syslog(LOG_INFO,
+ "kernel pps sync enabled");
+ pps_control = current_time;
record_peer_stats(&loopback_interface->sin,
- ctlsysstatus(), &pps_offset, 0, pps_dispersion);
- } else
- pps_time = 0;
-#endif /* KERNEL_PLL */
- } else {
- if (offset < 0) {
- clock_adjust = -((-offset) >> time_constant);
- } else {
- clock_adjust = offset >> time_constant;
+ ctlsysstatus(), fp_offset, 0,
+ pps_dispersion);
}
+#endif /* KERNEL_PLL */
- /*
- * Calculate the new frequency error. The factor given
- * in the spec gives the adjustment per 2**CLOCK_ADJ
- * seconds, but we want it as a (scaled) pure ratio, so
- * we include that factor now and remove it later.
- */
- if (first_adjustment) {
- first_adjustment = 0;
- } else {
+ /*
+ * If the dispersion exceeds 128 ms, we need to quick-march it
+ * to nominal zero offset and wait for the next update. This is
+ * necessary when the intrinsic frequency error is large and the
+ * clock has drifted during the interval the clock filter was
+ * stabilizing. Note that, if unsynchronized, the dispersion is
+ * always greater than 128 ms, so we don't need a check for
+ * that.
+ */
+ } else if (smax > CLOCK_MAX_FP) {
+ clock_adjust = offset;
+
+ /*
+ * If the dispersion has increased substantially over the
+ * previous value, we have a spike which probably should be
+ * suppressed. A factor of eight has been found reasonable by
+ * simulation.
+ */
+ } else if (smax > sys_maxd << 3) {
+ return (0);
+
+ /*
+ * If the interval between corrections is less than the Allan
+ * variance intercept point, we use a phase-lock loop to compute
+ * new values of time and frequency. The bandwidth is controlled
+ * by the time constant, which is adjusted in response to the
+ * phase error and dispersion. Note the frequency is not changed
+ * if the local clock driver is in control.
+ */
+ } else if (interval < allan) {
+ int time_constant = min(peer->ppoll, sys_poll) -
+ NTP_MINPOLL;
+ int ltmp = interval;
+
+ if (offset < 0)
+ clock_adjust = -(-offset >> time_constant);
+ else
+ clock_adjust = offset >> time_constant;
+ if (interval && !(peer->refclktype ==
+ REFCLK_LOCALCLOCK)) {
tmp = peer->maxpoll;
- tmp_uf = watchdog_timer;
- if (tmp_uf == 0)
- tmp_uf = 1;
- while (tmp_uf < (1 << peer->maxpoll)) {
+ while (ltmp < (1 << peer->maxpoll)) {
tmp--;
- tmp_uf <<= 1;
+ ltmp <<= 1;
}
-
- /*
- * We apply the frequency scaling at the same
- * time as the sample interval; this ensures a
- * safe right-shift. (as long as it keeps below
- * 31 bits, which current parameters should
- * ensure.
- */
- tmp = (RSH_FRAC_TO_FREQ - tmp) +
- time_constant + time_constant;
+ tmp = (RSH_FRAC_TO_FREQ - tmp) + time_constant +
+ time_constant;
if (offset < 0)
- tmp = -((-offset) >> tmp);
+ tmp = -(-offset >> tmp);
else
tmp = offset >> tmp;
drift_comp += tmp;
- if (drift_comp > max_comp)
- drift_comp = max_comp;
- else if (drift_comp < -max_comp)
- drift_comp = -max_comp;
}
+
+ /*
+ * If the interval between corrections is greater than the Allan
+ * variance intercept point, we use a hybrid frequency-lock loop
+ * to compute new values of phase and frequency. The following
+ * code is based on ideas suggested by Judah Levine of NIST and
+ * used in his "lockclock" implementation of ACTS. The magic
+ * factor of 4 in the left shift is to convert from s_fp to ppm.
+ */
+ } else {
+ clock_adjust = offset;
+ stmp = (offset / interval) << 4;
+ if (stmp < 0)
+ drift_comp -= -stmp >> CLOCK_G;
+ else
+ drift_comp += stmp >> CLOCK_G;
}
- watchdog_timer = 0;
/*
- * Determine when to adjust the time constant and poll interval.
+ * As a sanity check, we clamp the frequency not to exceed the
+ * slew rate of the stock Unix adjtime() system call. Finally,
+ * do a little housekeeping.
*/
- if (pps_control)
- time_constant = 0;
- else if (current_time - tcadj_time >= (1 << sys_poll) && !pps_control) {
- tcadj_time = current_time;
- tmp = offset;
- if (tmp < 0)
- tmp = -tmp;
- tmp = tmp >> (16 + CLOCK_WEIGHTTC - time_constant);
- if (tmp > sys_maxd) {
- tc_counter = 0;
- time_constant--;
+ if (drift_comp > max_comp)
+ drift_comp = max_comp;
+ else if (drift_comp < -max_comp)
+ drift_comp = -max_comp;
+ if (interval > (1 << (peer->minpoll - 1))) {
+
+ /*
+ * Determine when to adjust the poll interval. We do
+ * this regardless of what source controls the loop,
+ * since we might flap back and forth between sources.
+ */
+ stmp = LFPTOFP(fp_offset);
+ if (stmp < 0)
+ stmp = -stmp;
+ if (stmp > smax) {
+ tc_counter -= (int)sys_poll << 1;
+ if (tc_counter < -CLOCK_LIMIT) {
+ tc_counter = -CLOCK_LIMIT;
+ if (sys_poll > peer->minpoll) {
+ sys_poll--;
+ tc_counter = 0;
+ }
+ }
} else {
- tc_counter++;
- if (tc_counter > CLOCK_HOLDTC) {
- tc_counter = 0;
- time_constant++;
+ tc_counter += (int)sys_poll;
+ if (tc_counter > CLOCK_LIMIT) {
+ tc_counter = CLOCK_LIMIT;
+ if (sys_poll < peer->maxpoll) {
+ sys_poll++;
+ tc_counter = 0;
+ }
}
}
- if (time_constant < (int)(peer->minpoll - NTP_MINPOLL))
- time_constant = peer->minpoll - NTP_MINPOLL;
- if (time_constant > (int)(peer->maxpoll - NTP_MINPOLL))
- time_constant = peer->maxpoll - NTP_MINPOLL;
+
+ /*
+ * Calculate the frequency offset and frequency
+ * stability. These are useful for performance
+ * monitoring, but do not affect the loop variables. The
+ * results are scaled as a s_fp in ppm, because we know
+ * more than we should.
+ */
+ ftmp = *fp_offset;
+ L_SUB(&ftmp, &last_offset);
+ clock_frequency = (LFPTOFP(&ftmp) / interval) << 20;
+ if (clock_frequency < -max_comp)
+ clock_frequency = -max_comp;
+ else if (clock_frequency > max_comp)
+ clock_frequency = max_comp;
+ stmp = clock_frequency;
+ if (stmp < 0)
+ stmp = -stmp;
+ stmp -= clock_stability;
+ if (stmp < 0)
+ clock_stability -= -stmp >> NTP_MAXD;
+ else
+ clock_stability += stmp >> NTP_MAXD;
}
- sys_poll = (u_char)(NTP_MINPOLL + time_constant);
+ last_offset = *fp_offset;
+ last_time = current_time;
#ifdef DEBUG
if (debug > 1)
- printf("adj %s, drft %s, tau %3i\n",
- mfptoa((clock_adjust<0?-1:0), clock_adjust, 6),
- fptoa(drift_comp, 6), time_constant);
+ printf(
+ "local_clock: phase %s freq %s err %s allan %ld poll %d\n",
+ mfptoa((clock_adjust < 0 ? -1 : 0), clock_adjust,
+ 6), fptoa(drift_comp, 3), fptoa(smax, 6), allan,
+ sys_poll);
#endif /* DEBUG */
- (void) record_loop_stats(&last_offset, &drift_comp, time_constant);
+ (void) record_loop_stats(fp_offset, drift_comp, sys_poll);
/*
* Whew. I've had enough.
*/
- return (0);
+ return (return_code);
}
/*
- * adj_host_clock - Called every 2**CLOCK_ADJ seconds to update host clock
+ * adj_host_clock - Called every 1 << CLOCK_ADJ seconds to update host
+ * clock
*/
void
adj_host_clock()
{
- register LONG adjustment;
-#if defined(PPSPPS)
- struct ppsclockev ev;
- l_fp ts;
-#endif /* PPSPPS */
-
- watchdog_timer += (1 << CLOCK_ADJ);
- if (watchdog_timer >= NTP_MAXAGE) {
- first_adjustment = 1; /* don't use next offset for freq */
- }
- if (sys_refskew.l_i >= NTP_MAXSKEW)
- sys_refskew.l_f = 0; /* clamp it */
- else
- L_ADDUF(&sys_refskew, NTP_SKEWINC);
+ register long adjustment;
+ l_fp offset;
-#if defined(PPS) || defined(PPSCLK) || defined(PPSPPS)
-#if defined(PPSPPS)
/*
- * Note that nothing ugly happens even if the CIOGETEV ioctl is
- * not configured. Correct for signal delays (!) for ultimate
- * finick.
+ * Update the dispersion since the last update. Don't allow
+ * frequency measurements over periods longer than NTP_MAXAGE
+ * (86400 s = one day).
*/
- if (fdpps != -1 && ioctl(fdpps, CIOGETEV, (caddr_t)&ev) >= 0) {
- static int last_serial = 0; /* avoid stale events */
-
- if (last_serial != ev.serial) {
- TVUTOTSF(ev.tv.tv_usec, ts.l_uf);
- ts.l_ui = 0; /* seconds don't matter here */
- L_SUB(&ts, &pps_delay);
- ts.l_uf = ~ts.l_uf; /* map [0.5..1[ into [-0.5..0[ */
- ts.l_ui = (ts.l_f < 0) ? ~0 : 0; /* sign extension */
- (void)pps_sample(&ts);
- last_serial = ev.serial;
- }
- }
-#endif /* PPSPPS */
-#endif /* PPS || PPSCLK || PPSPPS */
- if (pps_time && current_time - pps_time > PPS_MAXAGE)
- pps_time = 0;
- if (pps_update && current_time - pps_update > PPS_MAXUPDATE)
- pps_update = 0;
- if (pps_time && pps_update) {
- if (!pps_control)
- syslog(LOG_INFO, "PPS synch");
- pps_control = 1;
- } else {
+ if (current_time - last_time > NTP_MAXAGE)
+ last_time = 0;
+ L_ADDUF(&sys_refskew, NTP_SKEWINC);
+
+ /*
+ * Declare PPS kernel unsync if the pps signal has been heard
+ * during the last few minutes.
+ */
+ if (pps_control && current_time - pps_control > PPS_MAXAGE) {
if (pps_control)
- syslog(LOG_INFO, "PPS synch lost");
+ syslog(LOG_INFO, "kernel pps sync disabled");
pps_control = 0;
}
/*
- * Resist the following code if the phase-lock loop has been
- * implemented in the kernel.
+ * If the phase-lock loop is not implemented in the kernel, we
+ * do it the hard way using incremental adjustments and the
+ * adjtime() system call.
*/
- if (pll_control)
+ if (pll_control && pll_enable)
return;
adjustment = clock_adjust;
if (adjustment < 0)
- adjustment = -((-adjustment) >> CLOCK_PHASE);
+ adjustment = -(-adjustment >> CLOCK_PHASE);
else
adjustment >>= CLOCK_PHASE;
clock_adjust -= adjustment;
if (drift_comp < 0)
- adjustment -= ((-drift_comp) >> RSH_DRIFT_TO_ADJ);
+ adjustment -= -drift_comp >> RSH_DRIFT_TO_ADJ;
else
adjustment += drift_comp >> RSH_DRIFT_TO_ADJ;
- { l_fp offset;
- offset.l_i = 0;
- offset.l_f = adjustment;
- adj_systime(&offset);
+ /*
+ * Intricate wrinkle. If the local clock driver is in use and
+ * selected for synchronization, somebody else may be tinker the
+ * adjtime() syscall. In this case we have to avoid calling
+ * adjtime(), since that may truncate the other guy's requests.
+ * That means the local clock fudge time and frequency
+ * adjustments don't work in that case. Caveat empty.
+ */
+ if (sys_peer) {
+ if (sys_peer->refclktype == REFCLK_LOCALCLOCK &&
+ sys_peer->flags & FLAG_PREFER)
+ return;
}
+ L_CLR(&offset);
+ L_ADDF(&offset, adjustment);
+ adj_systime(&offset);
+}
+
+
+/*
+ * adj_frequency - adjust local clock frequency
+ */
+void
+adj_frequency(freq)
+ s_fp freq; /* frequency (ppm) */
+{
+#if defined(KERNEL_PLL)
+ struct timex ntv;
+#endif /* KERNEL_PLL */
+
+ /*
+ * This routine adjusts the frequency offset. It is used by the
+ * local clock driver to adjust frequency when no external
+ * discipline source is available and by the acts driver when
+ * the interval between updates is greater than 1 <<
+ * NTP_MAXPOLL. Note that the maximum offset is limited by
+ * max_comp when the daemon pll is used, but the maximum may be
+ * different when the kernel pll is used.
+ */
+ drift_comp += freq;
+ if (drift_comp > max_comp)
+ drift_comp = max_comp;
+ else if (drift_comp < -max_comp)
+ drift_comp = -max_comp;
+#if defined(KERNEL_PLL)
+ /*
+ * If the phase-lock code is implemented in the kernel, set the
+ * kernel frequency as well, but be sure to set drift_comp to
+ * the actual frequency.
+ */
+ if (!(pll_control && pll_enable))
+ return;
+ memset((char *)&ntv, 0, sizeof ntv);
+ ntv.modes = MOD_FREQUENCY;
+ ntv.freq = freq + drift_comp;
+ (void)ntp_adjtime(&ntv);
+ drift_comp = ntv.freq;
+#endif /* KERNEL_PLL */
}
@@ -753,106 +633,76 @@ loop_config(item, lfp_value, int_value)
l_fp *lfp_value;
int int_value;
{
- s_fp tmp;
#if defined(KERNEL_PLL)
struct timex ntv;
#endif /* KERNEL_PLL */
+#ifdef DEBUG
+ if (debug) {
+ printf("loop_config %d %s %x\n", item,
+ lfptoa(lfp_value, 3), int_value);
+ }
+#endif
switch (item) {
- case LOOP_DRIFTCOMP:
- tmp = LFPTOFP(lfp_value);
- if (tmp >= max_comp || tmp <= -max_comp) {
- syslog(LOG_ERR,
- "loop_config: frequency offset %s in ntp.conf file is too large",
- fptoa(tmp, 5));
- } else {
- drift_comp = tmp;
+
+ case LOOP_DRIFTCOMP:
+ drift_comp = LFPTOFP(lfp_value);
+ if (drift_comp > max_comp)
+ drift_comp = max_comp;
+ if (drift_comp < -max_comp)
+ drift_comp = -max_comp;
#if defined(KERNEL_PLL)
- /*
- * If the phase-lock code is implemented in the
- * kernel, give the time_constant and saved
- * frequency offset to the kernel. If not, no
- * harm is done.
- */
+ /*
+ * If the phase-lock code is implemented in the kernel,
+ * give the time_constant and saved frequency offset to
+ * the kernel. If not, no harm is done. We do this
+ * whether or not the use of the kernel mods is
+ * requested, in order to clear out the trash from
+ * possible prior customers.
+ */
+ memset((char *)&ntv, 0, sizeof ntv);
+ pll_status = int_value & (STA_PLL | STA_PPSFREQ);
+ if (pll_status & STA_PLL)
pll_control = 1;
- pll_status = STA_PLL | STA_PPSFREQ;
- ntv.modes = MOD_BITS | MOD_FREQUENCY;
- ntv.offset = 0;
+ else
+ pll_control = 0;
+ ntv.modes = MOD_BITS | MOD_FREQUENCY;
+ if (pll_status) {
ntv.freq = drift_comp;
ntv.maxerror = NTP_MAXDISPERSE;
ntv.esterror = NTP_MAXDISPERSE;
ntv.status = pll_status | STA_UNSYNC;
- ntv.constant = time_constant;
- newsigsys.sv_handler = pll_trap;
- newsigsys.sv_mask = 0;
- newsigsys.sv_flags = 0;
- if ((sigvec(SIGSYS, &newsigsys, &sigsys)))
- syslog(LOG_ERR,
- "sigvec() fails to save SIGSYS trap: %m\n");
- (void)ntp_adjtime(&ntv);
- if ((sigvec(SIGSYS, &sigsys, (struct sigvec *)NULL)))
- syslog(LOG_ERR,
- "sigvec() fails to restore SIGSYS trap: %m\n");
- if (pll_control)
- syslog(LOG_NOTICE,
- "using kernel phase-lock loop %04x",
- ntv.status);
- else
- syslog(LOG_NOTICE,
- "using xntpd phase-lock loop");
-#endif /* KERNEL_PLL */
-
+ ntv.constant = sys_poll - NTP_MINPOLL;
}
+ newsigsys.sv_handler = pll_trap;
+ newsigsys.sv_mask = 0;
+ newsigsys.sv_flags = 0;
+ if ((sigvec(SIGSYS, &newsigsys, &sigsys)))
+ syslog(LOG_ERR,
+ "sigvec() fails to save SIGSYS trap: %m");
+ (void)ntp_adjtime(&ntv);
+ if ((sigvec(SIGSYS, &sigsys,
+ (struct sigvec *)NULL)))
+ syslog(LOG_ERR,
+ "sigvec() fails to restore SIGSYS trap: %m");
+ if (pll_control)
+ syslog(LOG_NOTICE,
+ "using kernel phase-lock loop %04x",
+ ntv.status);
+ else
+ syslog(LOG_NOTICE,
+ "using xntpd phase-lock loop");
+#endif /* KERNEL_PLL */
break;
-
- case LOOP_PPSDELAY:
- pps_delay = *lfp_value;
- break;
-
-#if defined(PPSCLK)
- case LOOP_PPSBAUD:
-#if defined(HAVE_TERMIOS)
- /*
- * System V TERMIOS serial line parameters
- * (termios interface)
- */
- { struct termios ttyb, *ttyp;
- if (fdpps == -1)
- return;
-
- ttyp = &ttyb;
- if (tcgetattr(fdpps, ttyp) < 0)
- return;
- ttyp->c_cflag = CS8|CLOCAL|CREAD | int_value;
- if (tcsetattr(fdpps, TCSANOW, ttyp) < 0)
- return;
- }
-#endif /* HAVE_TERMIOS */
-#if defined(HAVE_BSD_TTYS)
-
- /*
- * 4.3bsd serial line parameters (sgttyb interface)
- */
- { struct sgttyb ttyb;
-
- if (fdpps == -1 || ioctl(fdpps, TIOCGETP, &ttyb) < 0)
- return;
- ttyb.sg_ispeed = ttyb.sg_ospeed = SYS_BAUD(int_value);
- if (ioctl(fdpps, TIOCSETP, &ttyb) < 0)
- return;
- }
-#endif /* HAVE_BSD_TTYS */
- pps_baud = int_value;
- break;
-#endif /* PPSCLK */
- default:
+ default:
/* sigh */
break;
}
}
+
#if defined(KERNEL_PLL)
/*
* _trap - trap processor for undefined syscalls
@@ -869,128 +719,3 @@ pll_trap()
}
#endif /* KERNEL_PLL */
-#if defined(PPSCLK)
-/*
- * pps_receive - compute and store 1-pps signal offset
- *
- * This routine is called once per second when the 1-pps signal is
- * present. It calculates the offset of the local clock relative to the
- * 1-pps signal and saves in a circular buffer for later use. If the
- * clock line discipline is active, its timestamp is used; otherwise,
- * the buffer timestamp is used.
- */
-static void
-pps_receive(rbufp)
- struct recvbuf *rbufp;
-{
- u_char *dpt; /* buffer pointer */
- l_fp ts; /* l_fp temps */
- int dpend; /* buffer length */
-
- /*
- * Set up pointers, check the buffer length, discard intercept
- * character and convert unix timeval to timestamp format.
- */
- dpt = (u_char *)&rbufp->recv_space;
- dpend = rbufp->recv_length;
-#if !defined(HPUXGADGET)
- dpt++;
- dpend--;
-#endif /* HPUXGADGET */
- if (dpend != sizeof(struct timeval) || !buftvtots((char *)dpt, &ts))
- ts = rbufp->recv_time;
-
- /*
- * Correct for uart and os delay and process sample offset.
- */
- L_SUB(&ts, &pps_delay);
- L_NEG(&ts);
- (void)pps_sample(&ts);
-}
-#endif /* PPSCLK */
-
-#if defined(PPS) || defined(PPSCLK) || defined(PPSPPS)
-/*
- * pps_sample - process pps sample offset
- */
-int pps_sample(tsr)
- l_fp *tsr;
-{
- int i, j; /* temp ints */
- LONG sort[NPPS]; /* temp array for sorting */
- l_fp lftemp, ts; /* l_fp temps */
- u_fp utemp; /* u_fp temp */
- LONG ltemp; /* long temp */
-
- /*
- * Note the seconds offset is already in the low-order timestamp
- * doubleword, so all we have to do is sign-extend and invert
- * it. The resulting offset is believed only if within
- * CLOCK_MAX.
- */
- ts = *tsr;
- lftemp.l_i = lftemp.l_f = 0;
- M_ADDF(lftemp.l_i, lftemp.l_f, ts.l_f);
- if (ts.l_f <= -CLOCK_MAX_F || ts.l_f >= CLOCK_MAX_F) {
- pps_time = 0;
- return (-1);
- }
-
- /*
- * Save the sample in a circular buffer for later processing.
- */
- nsamples++;
- i = ((int)(nsamples)) % NPPS;
- samples[i] = lftemp.l_f;
- if (i != NPPS-1)
- return (0);
-
- /*
- * When the buffer fills up, construct an array of sorted
- * samples.
- */
- pps_time = current_time;
- for (i = 0; i < NPPS; i++) {
- sort[i] = samples[i];
- for (j = 0; j < i; j++) {
- if (sort[j] > sort[i]) {
- ltemp = sort[j];
- sort[j] = sort[i];
- sort[i] = ltemp;
- }
- }
- }
-
- /*
- * Compute offset as the average of all samples in the filter
- * less PPS_TRIM samples trimmed from the beginning and end,
- * dispersion as the difference between max and min of samples
- * retained. The system stratum, root delay and root dispersion
- * are also set here.
- */
- pps_offset.l_i = pps_offset.l_f = 0;
- for (i = PPS_TRIM; i < NPPS - PPS_TRIM; i++)
- M_ADDF(pps_offset.l_i, pps_offset.l_f, sort[i]);
- if (L_ISNEG(&pps_offset)) {
- L_NEG(&pps_offset);
- for (i = 0; i < PPS_FAC; i++)
- L_RSHIFT(&pps_offset);
- L_NEG(&pps_offset);
- } else {
- for (i = 0; i < PPS_FAC; i++)
- L_RSHIFT(&pps_offset);
- }
- lftemp.l_i = 0;
- lftemp.l_f = sort[NPPS-1-PPS_TRIM] - sort[PPS_TRIM];
- pps_dispersion = LFPTOFP(&lftemp);
-#ifdef DEBUG
- if (debug)
- printf("pps_filter: %s %s %s\n", lfptoa(&pps_delay, 6),
- lfptoa(&pps_offset, 6), lfptoa(&lftemp, 5));
-#endif /* DEBUG */
- record_peer_stats(&loopback_interface->sin, ctlsysstatus(),
- &pps_offset, 0, pps_dispersion);
- return (0);
-}
-#endif /* PPS || PPSCLK || PPSPPS */
-
diff --git a/usr.sbin/xntpd/xntpd/ntp_request.c b/usr.sbin/xntpd/xntpd/ntp_request.c
index 355b13b..d06fd13 100644
--- a/usr.sbin/xntpd/xntpd/ntp_request.c
+++ b/usr.sbin/xntpd/xntpd/ntp_request.c
@@ -1,10 +1,9 @@
-/* ntp_request.c,v 3.1 1993/07/06 01:11:26 jbj Exp
+/*
* ntp_request.c - respond to information requests
*/
#include <sys/types.h>
#include <stdio.h>
#include <errno.h>
-#include <sys/ioctl.h>
#include <sys/time.h>
#include "ntpd.h"
@@ -17,7 +16,12 @@
#include "ntp_stdlib.h"
#ifdef KERNEL_PLL
+#ifdef HAVE_SYS_TIMEX_H
#include <sys/timex.h>
+#else
+#include "sys/timex.h"
+#endif
+
#ifndef NTP_SYSCALLS_LIBC
#define ntp_gettime(t) syscall(SYS_ntp_gettime, (t))
#define ntp_adjtime(t) syscall(SYS_ntp_adjtime, (t))
@@ -64,7 +68,7 @@ static void do_conf P((struct sockaddr_in *, struct interface *, struct req_pkt
static void do_unconf P((struct sockaddr_in *, struct interface *, struct req_pkt *));
static void set_sys_flag P((struct sockaddr_in *, struct interface *, struct req_pkt *));
static void clr_sys_flag P((struct sockaddr_in *, struct interface *, struct req_pkt *));
-static void setclr_flags P((struct sockaddr_in *, struct interface *, struct req_pkt *, U_LONG));
+static void setclr_flags P((struct sockaddr_in *, struct interface *, struct req_pkt *, u_long));
static void do_monitor P((struct sockaddr_in *, struct interface *, struct req_pkt *));
static void do_nomonitor P((struct sockaddr_in *, struct interface *, struct req_pkt *));
static void list_restrict P((struct sockaddr_in *, struct interface *, struct req_pkt *));
@@ -72,7 +76,8 @@ static void do_resaddflags P((struct sockaddr_in *, struct interface *, struct r
static void do_ressubflags P((struct sockaddr_in *, struct interface *, struct req_pkt *));
static void do_unrestrict P((struct sockaddr_in *, struct interface *, struct req_pkt *));
static void do_restrict P((struct sockaddr_in *, struct interface *, struct req_pkt *, int));
-static void mon_getlist P((struct sockaddr_in *, struct interface *, struct req_pkt *));
+static void mon_getlist_0 P((struct sockaddr_in *, struct interface *, struct req_pkt *));
+static void mon_getlist_1 P((struct sockaddr_in *, struct interface *, struct req_pkt *));
static void reset_stats P((struct sockaddr_in *, struct interface *, struct req_pkt *));
static void reset_peer P((struct sockaddr_in *, struct interface *, struct req_pkt *));
static void do_key_reread P((struct sockaddr_in *, struct interface *, struct req_pkt *));
@@ -127,23 +132,24 @@ static struct req_proc xntp_codes[] = {
{ REQ_RESADDFLAGS, AUTH, sizeof(struct conf_restrict), do_resaddflags },
{ REQ_RESSUBFLAGS, AUTH, sizeof(struct conf_restrict), do_ressubflags },
{ REQ_UNRESTRICT, AUTH, sizeof(struct conf_restrict), do_unrestrict },
- { REQ_MON_GETLIST, NOAUTH, 0, mon_getlist },
+ { REQ_MON_GETLIST, NOAUTH, 0, mon_getlist_0 },
+ { REQ_MON_GETLIST_1, NOAUTH, 0, mon_getlist_1 },
{ REQ_RESET_STATS, AUTH, sizeof(struct reset_flags), reset_stats },
{ REQ_RESET_PEER, AUTH, sizeof(struct conf_unpeer), reset_peer },
{ REQ_REREAD_KEYS, AUTH, 0, do_key_reread },
{ REQ_DO_DIRTY_HACK, AUTH, 0, do_dirty_hack },
{ REQ_DONT_DIRTY_HACK, AUTH, 0, dont_dirty_hack },
- { REQ_TRUSTKEY, AUTH, sizeof(U_LONG), trust_key },
- { REQ_UNTRUSTKEY, AUTH, sizeof(U_LONG), untrust_key },
+ { REQ_TRUSTKEY, AUTH, sizeof(u_long), trust_key },
+ { REQ_UNTRUSTKEY, AUTH, sizeof(u_long), untrust_key },
{ REQ_AUTHINFO, NOAUTH, 0, get_auth_info },
{ REQ_TRAPS, NOAUTH, 0, req_get_traps },
{ REQ_ADD_TRAP, AUTH, sizeof(struct conf_trap), req_set_trap },
{ REQ_CLR_TRAP, AUTH, sizeof(struct conf_trap), req_clr_trap },
- { REQ_REQUEST_KEY, AUTH, sizeof(U_LONG), set_request_keyid },
- { REQ_CONTROL_KEY, AUTH, sizeof(U_LONG), set_control_keyid },
+ { REQ_REQUEST_KEY, AUTH, sizeof(u_long), set_request_keyid },
+ { REQ_CONTROL_KEY, AUTH, sizeof(u_long), set_control_keyid },
{ REQ_GET_CTLSTATS, NOAUTH, 0, get_ctl_stats },
{ REQ_GET_LEAPINFO, NOAUTH, 0, get_leap_info },
- { REQ_SET_PRECISION, AUTH, sizeof(LONG), set_precision },
+ { REQ_SET_PRECISION, AUTH, sizeof(long), set_precision },
#ifdef KERNEL_PLL
{ REQ_GET_KERNEL, NOAUTH, 0, get_kernel_info },
#endif /* KERNEL_PLL */
@@ -160,16 +166,16 @@ static struct req_proc xntp_codes[] = {
* Authentication keyid used to authenticate requests. Zero means we
* don't allow writing anything.
*/
-U_LONG info_auth_keyid;
+u_long info_auth_keyid;
/*
* Statistic counters to keep track of requests and responses.
*/
-U_LONG numrequests; /* number of requests we've received */
-U_LONG numresppkts; /* number of resp packets sent with data */
+u_long numrequests; /* number of requests we've received */
+u_long numresppkts; /* number of resp packets sent with data */
-U_LONG errorcounter[INFO_ERR_AUTH+1]; /* lazy way to count errors, indexed */
+u_long errorcounter[INFO_ERR_AUTH+1]; /* lazy way to count errors, indexed */
/* by the error code */
#if defined(KERNEL_PLL) && !defined(NTP_SYSCALLS_LIBC)
@@ -189,18 +195,33 @@ extern int debug;
/*
* Imported from the timer module
*/
-extern U_LONG current_time;
+extern u_long current_time;
/*
* Imported from ntp_loopfilter.c
*/
extern int pll_control;
+extern int pll_enable;
+extern int pps_control;
+
+/*
+ * Imported from ntp_monitor.c
+ */
+extern int mon_enabled;
+
+/*
+ * Imported from ntp_util.c
+ */
+extern int stats_control;
+
+extern struct peer *peer_hash[];
+extern struct peer *sys_peer;
/*
* A hack. To keep the authentication module clear of xntp-ism's, we
* include a time reset variable for its stats here.
*/
-static U_LONG auth_timereset;
+static u_long auth_timereset;
/*
* Response packet used by these routines. Also some state information
@@ -260,7 +281,7 @@ req_ack(srcadr, inter, inpkt, errcode)
/*
* send packet and bump counters
*/
- sendpkt(srcadr, inter, (struct pkt *)&rpkt, RESP_HEADER_SIZE);
+ sendpkt(srcadr, inter, -1, (struct pkt *)&rpkt, RESP_HEADER_SIZE);
errorcounter[errcode]++;
}
@@ -324,7 +345,7 @@ more_pkt()
rpkt.rm_vn_mode = RM_VN_MODE(RESP_BIT, MORE_BIT);
rpkt.auth_seq = AUTH_SEQ(0, seqno);
rpkt.err_nitems = htons((u_short)nitems);
- sendpkt(toaddr, frominter, (struct pkt *)&rpkt,
+ sendpkt(toaddr, frominter, -1, (struct pkt *)&rpkt,
RESP_HEADER_SIZE+databytes);
numresppkts++;
@@ -390,7 +411,7 @@ flush_pkt()
rpkt.rm_vn_mode = RM_VN_MODE(RESP_BIT, 0);
rpkt.auth_seq = AUTH_SEQ(0, seqno);
rpkt.err_nitems = htons((u_short)nitems);
- sendpkt(toaddr, frominter, (struct pkt *)&rpkt,
+ sendpkt(toaddr, frominter, -1, (struct pkt *)&rpkt,
RESP_HEADER_SIZE+databytes);
numresppkts++;
}
@@ -483,20 +504,18 @@ process_private(rbufp, mod_okay)
* time stamp.
*/
if (proc->needs_auth) {
- register U_LONG tmp_ui;
- register U_LONG tmp_uf;
+ l_fp ftmp;
/*
* If this guy is restricted from doing this, don't let him
* If wrong key was used, or packet doesn't have mac, return.
*/
- if (!INFO_IS_AUTH(inpkt->auth_seq)
- || info_auth_keyid == 0
+ if (!INFO_IS_AUTH(inpkt->auth_seq) || info_auth_keyid == 0
|| ntohl(inpkt->keyid) != info_auth_keyid) {
#ifdef DEBUG
if (debug > 4)
printf(
- "failed auth %d info_auth_keyid %u pkt keyid %u\n",
+ "failed auth %d info_auth_keyid %lu pkt keyid %u\n",
INFO_IS_AUTH(inpkt->auth_seq),
info_auth_keyid, ntohl(inpkt->keyid));
#endif
@@ -506,8 +525,8 @@ process_private(rbufp, mod_okay)
if (rbufp->recv_length > REQ_LEN_MAC) {
#ifdef DEBUG
if (debug > 4)
- printf("failed pkt length pkt %d req %d too long\n",
- rbufp->recv_length, REQ_LEN_MAC);
+ printf("bad pkt length %d\n",
+ rbufp->recv_length);
#endif
req_ack(srcadr, inter, inpkt, INFO_ERR_FMT);
return;
@@ -525,15 +544,12 @@ process_private(rbufp, mod_okay)
* calculate absolute time difference between xmit time stamp
* and receive time stamp. If too large, too bad.
*/
- tmp_ui = ntohl(inpkt->tstamp.l_ui);
- tmp_uf = ntohl(inpkt->tstamp.l_uf);
- M_SUB(tmp_ui, tmp_uf, rbufp->recv_time.l_ui,
- rbufp->recv_time.l_uf);
- if (M_ISNEG(tmp_ui, tmp_uf))
- M_NEG(tmp_ui, tmp_uf);
+ NTOHL_FP(&inpkt->tstamp, &ftmp);
+ L_SUB(&ftmp, &rbufp->recv_time);
+ if (L_ISNEG(&ftmp))
+ L_NEG(&ftmp);
- if (M_ISHIS(tmp_ui, tmp_uf,
- INFO_TS_MAXSKEW_UI, INFO_TS_MAXSKEW_UF)) {
+ if (ftmp.l_ui >= INFO_TS_MAXSKEW_UI) {
/*
* He's a loser. Tell him.
*/
@@ -590,8 +606,6 @@ peer_list(srcadr, inter, inpkt)
register struct info_peer_list *ip;
register struct peer *pp;
register int i;
- extern struct peer *peer_hash[];
- extern struct peer *sys_peer;
ip = (struct info_peer_list *)prepare_pkt(srcadr, inter, inpkt,
sizeof(struct info_peer_list));
@@ -630,8 +644,6 @@ peer_list_sum(srcadr, inter, inpkt)
register struct info_peer_summary *ips;
register struct peer *pp;
register int i;
- extern struct peer *peer_hash[];
- extern struct peer *sys_peer;
#ifdef DEBUG
if (debug > 2)
@@ -647,10 +659,14 @@ peer_list_sum(srcadr, inter, inpkt)
if (debug > 3)
printf("sum: got one\n");
#endif
- if (pp->dstadr == any_interface)
- ips->dstadr = 0;
- else
- ips->dstadr = pp->dstadr->sin.sin_addr.s_addr;
+ ips->dstadr = (pp->processed) ?
+ pp->cast_flags == MDF_BCAST ?
+ pp->dstadr->bcast.sin_addr.s_addr:
+ pp->cast_flags ?
+ pp->dstadr->sin.sin_addr.s_addr ?
+ pp->dstadr->sin.sin_addr.s_addr:
+ pp->dstadr->bcast.sin_addr.s_addr:
+ 1 : 5;
ips->srcadr = pp->srcadr.sin_addr.s_addr;
ips->srcport = pp->srcadr.sin_port;
ips->stratum = pp->stratum;
@@ -714,7 +730,14 @@ peer_info (srcadr, inter, inpkt)
ipl++;
if ((pp = findexistingpeer(&addr, (struct peer *)0)) == 0)
continue;
- ip->dstadr = NSRCADR(&pp->dstadr->sin);
+ ip->dstadr = (pp->processed) ?
+ pp->cast_flags == MDF_BCAST ?
+ pp->dstadr->bcast.sin_addr.s_addr:
+ pp->cast_flags ?
+ pp->dstadr->sin.sin_addr.s_addr ?
+ pp->dstadr->sin.sin_addr.s_addr:
+ pp->dstadr->bcast.sin_addr.s_addr:
+ 2 : 6;
ip->srcadr = NSRCADR(&pp->srcadr);
ip->srcport = NSRCPORT(&pp->srcadr);
ip->flags = 0;
@@ -745,7 +768,7 @@ peer_info (srcadr, inter, inpkt)
ip->reach = pp->reach;
ip->unreach = pp->unreach;
ip->flash = pp->flash;
- ip->estbdelay = htonl(pp->estbdelay);
+ ip->estbdelay = HTONS_FP(pp->estbdelay);
ip->ttl = pp->ttl;
ip->associd = htons(pp->associd);
ip->rootdelay = HTONS_FP(pp->rootdelay);
@@ -805,7 +828,14 @@ peer_stats (srcadr, inter, inpkt)
ipl++;
if ((pp = findexistingpeer(&addr, (struct peer *)0)) == 0)
continue;
- ip->dstadr = NSRCADR(&pp->dstadr->sin);
+ ip->dstadr = (pp->processed) ?
+ pp->cast_flags == MDF_BCAST ?
+ pp->dstadr->bcast.sin_addr.s_addr:
+ pp->cast_flags ?
+ pp->dstadr->sin.sin_addr.s_addr ?
+ pp->dstadr->sin.sin_addr.s_addr:
+ pp->dstadr->bcast.sin_addr.s_addr:
+ 3 : 7;
ip->srcadr = NSRCADR(&pp->srcadr);
ip->srcport = NSRCPORT(&pp->srcadr);
ip->flags = 0;
@@ -828,21 +858,13 @@ peer_stats (srcadr, inter, inpkt)
= htonl(pp->event_timer.event_time - current_time);
ip->timereachable = htonl(current_time - pp->timereachable);
ip->sent = htonl(pp->sent);
- ip->received = htonl(pp->received);
ip->processed = htonl(pp->processed);
- ip->badlength = 0;
ip->badauth = htonl(pp->badauth);
ip->bogusorg = htonl(pp->bogusorg);
ip->oldpkt = htonl(pp->oldpkt);
- ip->baddelay = 0;
- ip->seldelay = 0;
ip->seldisp = htonl(pp->seldisptoolarge);
ip->selbroken = htonl(pp->selbroken);
- ip->selold = htonl(pp->seltooold);
ip->candidate = pp->candidate;
- ip->falseticker = 0;
- ip->select = pp->select;
- ip->select_total = 0;
ip = (struct info_peer_stats *)more_pkt();
}
flush_pkt();
@@ -868,14 +890,16 @@ sys_info(srcadr, inter, inpkt)
extern s_char sys_precision;
extern s_fp sys_rootdelay;
extern u_fp sys_rootdispersion;
- extern U_LONG sys_refid;
+ extern u_long sys_refid;
extern l_fp sys_reftime;
extern u_char sys_poll;
extern struct peer *sys_peer;
extern int sys_bclient;
- extern U_LONG sys_bdelay;
+ extern s_fp sys_bdelay;
extern int sys_authenticate;
- extern U_LONG sys_authdelay;
+ extern u_long sys_authdelay;
+ extern u_fp clock_stability;
+ extern s_fp clock_frequency;
is = (struct info_sys *)prepare_pkt(srcadr, inter, inpkt,
sizeof(struct info_sys));
@@ -892,6 +916,8 @@ sys_info(srcadr, inter, inpkt)
is->precision = sys_precision;
is->rootdelay = htonl(sys_rootdelay);
is->rootdispersion = htonl(sys_rootdispersion);
+ is->frequency = htonl(clock_frequency);
+ is->stability = htonl(clock_stability);
is->refid = sys_refid;
HTONL_FP(&sys_reftime, &is->reftime);
@@ -901,9 +927,20 @@ sys_info(srcadr, inter, inpkt)
if (sys_bclient)
is->flags |= INFO_FLAG_BCLIENT;
if (sys_authenticate)
- is->flags |= INFO_FLAG_AUTHENABLE;
- HTONL_UF(sys_bdelay, &is->bdelay);
+ is->flags |= INFO_FLAG_AUTHENTICATE;
+ if (pll_enable)
+ is->flags |= INFO_FLAG_PLL;
+ if (pll_control)
+ is->flags |= INFO_FLAG_PLL_SYNC;
+ if (pps_control)
+ is->flags |= INFO_FLAG_PPS_SYNC;
+ if (mon_enabled != MON_OFF)
+ is->flags |= INFO_FLAG_MONITOR;
+ if (stats_control)
+ is->flags |= INFO_FLAG_FILEGEN;
+ is->bdelay = HTONS_FP(sys_bdelay);
HTONL_UF(sys_authdelay, &is->authdelay);
+
(void) more_pkt();
flush_pkt();
}
@@ -923,15 +960,15 @@ sys_stats(srcadr, inter, inpkt)
/*
* Importations from the protocol module
*/
- extern U_LONG sys_stattime;
- extern U_LONG sys_badstratum;
- extern U_LONG sys_oldversionpkt;
- extern U_LONG sys_newversionpkt;
- extern U_LONG sys_unknownversion;
- extern U_LONG sys_badlength;
- extern U_LONG sys_processed;
- extern U_LONG sys_badauth;
- extern U_LONG sys_limitrejected;
+ extern u_long sys_stattime;
+ extern u_long sys_badstratum;
+ extern u_long sys_oldversionpkt;
+ extern u_long sys_newversionpkt;
+ extern u_long sys_unknownversion;
+ extern u_long sys_badlength;
+ extern u_long sys_processed;
+ extern u_long sys_badauth;
+ extern u_long sys_limitrejected;
ss = (struct info_sys_stats *)prepare_pkt(srcadr, inter, inpkt,
sizeof(struct info_sys_stats));
@@ -968,10 +1005,10 @@ mem_stats(srcadr, inter, inpkt)
*/
extern int peer_hash_count[HASH_SIZE];
extern int peer_free_count;
- extern U_LONG peer_timereset;
- extern U_LONG findpeer_calls;
- extern U_LONG peer_allocations;
- extern U_LONG peer_demobilizations;
+ extern u_long peer_timereset;
+ extern u_long findpeer_calls;
+ extern u_long peer_allocations;
+ extern u_long peer_demobilizations;
extern int total_peer_structs;
ms = (struct info_mem_stats *)prepare_pkt(srcadr, inter, inpkt,
@@ -1010,18 +1047,18 @@ io_stats(srcadr, inter, inpkt)
/*
* Importations from the io module
*/
- extern U_LONG io_timereset;
- extern U_LONG full_recvbufs;
- extern U_LONG free_recvbufs;
- extern U_LONG total_recvbufs;
- extern U_LONG lowater_additions;
- extern U_LONG packets_dropped;
- extern U_LONG packets_ignored;
- extern U_LONG packets_received;
- extern U_LONG packets_sent;
- extern U_LONG packets_notsent;
- extern U_LONG handler_calls;
- extern U_LONG handler_pkts;
+ extern u_long io_timereset;
+ extern u_long full_recvbufs;
+ extern u_long free_recvbufs;
+ extern u_long total_recvbufs;
+ extern u_long lowater_additions;
+ extern u_long packets_dropped;
+ extern u_long packets_ignored;
+ extern u_long packets_received;
+ extern u_long packets_sent;
+ extern u_long packets_notsent;
+ extern u_long handler_calls;
+ extern u_long handler_pkts;
io = (struct info_io_stats *)prepare_pkt(srcadr, inter, inpkt,
sizeof(struct info_io_stats));
@@ -1058,10 +1095,10 @@ timer_stats(srcadr, inter, inpkt)
/*
* Importations from the timer module
*/
- extern U_LONG alarm_overflow;
- extern U_LONG timer_timereset;
- extern U_LONG timer_overflows;
- extern U_LONG timer_xmtcalls;
+ extern u_long alarm_overflow;
+ extern u_long timer_timereset;
+ extern u_long timer_overflows;
+ extern u_long timer_xmtcalls;
ts = (struct info_timer_stats *)prepare_pkt(srcadr, inter, inpkt,
sizeof(struct info_timer_stats));
@@ -1093,8 +1130,8 @@ loop_info(srcadr, inter, inpkt)
*/
extern l_fp last_offset;
extern s_fp drift_comp;
- extern int time_constant;
- extern U_LONG watchdog_timer;
+ extern int tc_counter;
+ extern u_long last_time;
li = (struct info_loop *)prepare_pkt(srcadr, inter, inpkt,
sizeof(struct info_loop));
@@ -1102,8 +1139,8 @@ loop_info(srcadr, inter, inpkt)
HTONL_FP(&last_offset, &li->last_offset);
FPTOLFP(drift_comp, &tmp);
HTONL_FP(&tmp, &li->drift_comp);
- li->compliance = htonl(time_constant);
- li->watchdog_timer = htonl(watchdog_timer);
+ li->compliance = htonl(tc_counter);
+ li->watchdog_timer = htonl(current_time - last_time);
(void) more_pkt();
flush_pkt();
@@ -1141,7 +1178,7 @@ do_conf(srcadr, inter, inpkt)
&& cp->hmode != MODE_CLIENT
&& cp->hmode != MODE_BROADCAST)
fl = 1;
- if (cp->flags & ~(CONF_FLAG_AUTHENABLE|CONF_FLAG_PREFER))
+ if (cp->flags & ~(CONF_FLAG_AUTHENABLE | CONF_FLAG_PREFER))
fl = 1;
cp++;
}
@@ -1267,7 +1304,7 @@ set_sys_flag(srcadr, inter, inpkt)
struct interface *inter;
struct req_pkt *inpkt;
{
- setclr_flags(srcadr, inter, inpkt, (U_LONG)1);
+ setclr_flags(srcadr, inter, inpkt, 1);
}
@@ -1280,7 +1317,7 @@ clr_sys_flag(srcadr, inter, inpkt)
struct interface *inter;
struct req_pkt *inpkt;
{
- setclr_flags(srcadr, inter, inpkt, (U_LONG)0);
+ setclr_flags(srcadr, inter, inpkt, 0);
}
@@ -1292,9 +1329,9 @@ setclr_flags(srcadr, inter, inpkt, set)
struct sockaddr_in *srcadr;
struct interface *inter;
struct req_pkt *inpkt;
- U_LONG set;
+ u_long set;
{
- register U_LONG flags;
+ register u_long flags;
if (INFO_NITEMS(inpkt->err_nitems) > 1) {
req_ack(srcadr, inter, inpkt, INFO_ERR_FMT);
@@ -1303,21 +1340,23 @@ setclr_flags(srcadr, inter, inpkt, set)
flags = ((struct conf_sys_flags *)inpkt->data)->flags;
- if (flags
- & ~(SYS_FLAG_BCLIENT | SYS_FLAG_MCLIENT | SYS_FLAG_AUTHENTICATE)) {
+ if (flags & ~(SYS_FLAG_BCLIENT | SYS_FLAG_AUTHENTICATE |
+ SYS_FLAG_PLL | SYS_FLAG_MONITOR |
+ SYS_FLAG_FILEGEN)) {
req_ack(srcadr, inter, inpkt, INFO_ERR_FMT);
return;
}
if (flags & SYS_FLAG_BCLIENT)
proto_config(PROTO_BROADCLIENT, set);
- if (flags & SYS_FLAG_MCLIENT)
- if (set)
- proto_config(PROTO_MULTICAST_ADD, INADDR_NTP);
- else
- proto_config(PROTO_MULTICAST_DEL, INADDR_NTP);
if (flags & SYS_FLAG_AUTHENTICATE)
proto_config(PROTO_AUTHENTICATE, set);
+ if (flags & SYS_FLAG_PLL)
+ proto_config(PROTO_PLL, set);
+ if (flags & SYS_FLAG_MONITOR)
+ proto_config(PROTO_MONITOR, set);
+ if (flags & SYS_FLAG_FILEGEN)
+ proto_config(PROTO_FILEGEN, set);
req_ack(srcadr, inter, inpkt, INFO_OKAY);
}
@@ -1456,7 +1495,7 @@ do_restrict(srcadr, inter, inpkt, op)
bad = 1;
if (cr->flags & ~(RES_ALLFLAGS))
bad = 1;
- if (cr->addr == INADDR_ANY && cr->mask != INADDR_ANY)
+ if (cr->addr == htonl(INADDR_ANY) && cr->mask != htonl(INADDR_ANY))
bad = 1;
cr++;
}
@@ -1492,7 +1531,7 @@ do_restrict(srcadr, inter, inpkt, op)
* mon_getlist - return monitor data
*/
static void
-mon_getlist(srcadr, inter, inpkt)
+mon_getlist_0(srcadr, inter, inpkt)
struct sockaddr_in *srcadr;
struct interface *inter;
struct req_pkt *inpkt;
@@ -1504,7 +1543,7 @@ mon_getlist(srcadr, inter, inpkt)
#ifdef DEBUG
if (debug > 2)
- printf("wants monitor list\n");
+ printf("wants monitor 0 list\n");
#endif
if (!mon_enabled) {
req_ack(srcadr, inter, inpkt, INFO_ERR_NODATA);
@@ -1532,6 +1571,57 @@ mon_getlist(srcadr, inter, inpkt)
}
/*
+ * mon_getlist - return monitor data
+ */
+static void
+mon_getlist_1(srcadr, inter, inpkt)
+ struct sockaddr_in *srcadr;
+ struct interface *inter;
+ struct req_pkt *inpkt;
+{
+ register struct info_monitor_1 *im;
+ register struct mon_data *md;
+ extern struct mon_data mon_mru_list;
+ extern int mon_enabled;
+
+#ifdef DEBUG
+ if (debug > 2)
+ printf("wants monitor 1 list\n");
+#endif
+ if (!mon_enabled) {
+ req_ack(srcadr, inter, inpkt, INFO_ERR_NODATA);
+ return;
+ }
+
+ im = (struct info_monitor_1 *)prepare_pkt(srcadr, inter, inpkt,
+ sizeof(struct info_monitor_1));
+ for (md = mon_mru_list.mru_next; md != &mon_mru_list && im != 0;
+ md = md->mru_next) {
+ im->lasttime = htonl(current_time - md->lasttime);
+ im->firsttime = htonl(current_time - md->firsttime);
+ if (md->lastdrop)
+ im->lastdrop = htonl(current_time - md->lastdrop);
+ else
+ im->lastdrop = 0;
+ im->count = htonl(md->count);
+ im->addr = md->rmtadr;
+ im->daddr = md->cast_flags == MDF_BCAST ?
+ md->interface->bcast.sin_addr.s_addr :
+ md->cast_flags ?
+ md->interface->sin.sin_addr.s_addr ?
+ md->interface->sin.sin_addr.s_addr :
+ md->interface->bcast.sin_addr.s_addr :
+ 4;
+ im->flags = md->cast_flags;
+ im->port = md->rmtport;
+ im->mode = md->mode;
+ im->version = md->version;
+ im = (struct info_monitor_1 *)more_pkt();
+ }
+ flush_pkt();
+}
+
+/*
* Module entry points and the flags they correspond with
*/
struct reset_entry {
@@ -1559,7 +1649,7 @@ reset_stats(srcadr, inter, inpkt)
struct interface *inter;
struct req_pkt *inpkt;
{
- U_LONG flags;
+ u_long flags;
struct reset_entry *rent;
if (INFO_NITEMS(inpkt->err_nitems) > 1) {
@@ -1716,11 +1806,11 @@ do_trustkey(srcadr, inter, inpkt, trust)
struct req_pkt *inpkt;
int trust;
{
- register U_LONG *kp;
+ register u_long *kp;
register int items;
items = INFO_NITEMS(inpkt->err_nitems);
- kp = (U_LONG *)inpkt->data;
+ kp = (u_long *)inpkt->data;
while (items-- > 0) {
authtrust(*kp, trust);
kp++;
@@ -1744,14 +1834,13 @@ get_auth_info(srcadr, inter, inpkt)
/*
* Importations from the authentication module
*/
- extern U_LONG authnumkeys;
- extern U_LONG authnumfreekeys;
- extern U_LONG authkeylookups;
- extern U_LONG authkeynotfound;
- extern U_LONG authencryptions;
- extern U_LONG authdecryptions;
- extern U_LONG authdecryptok;
- extern U_LONG authkeyuncached;
+ extern u_long authnumkeys;
+ extern u_long authnumfreekeys;
+ extern u_long authkeylookups;
+ extern u_long authkeynotfound;
+ extern u_long authencryptions;
+ extern u_long authdecryptions;
+ extern u_long authkeyuncached;
ia = (struct info_auth *)prepare_pkt(srcadr, inter, inpkt,
sizeof(struct info_auth));
@@ -1762,7 +1851,6 @@ get_auth_info(srcadr, inter, inpkt)
ia->keynotfound = htonl(authkeynotfound);
ia->encryptions = htonl(authencryptions);
ia->decryptions = htonl(authdecryptions);
- ia->decryptok = htonl(authdecryptok);
ia->keyuncached = htonl(authkeyuncached);
ia->timereset = htonl(current_time - auth_timereset);
@@ -1782,18 +1870,16 @@ reset_auth_stats()
/*
* Importations from the authentication module
*/
- extern U_LONG authkeylookups;
- extern U_LONG authkeynotfound;
- extern U_LONG authencryptions;
- extern U_LONG authdecryptions;
- extern U_LONG authdecryptok;
- extern U_LONG authkeyuncached;
+ extern u_long authkeylookups;
+ extern u_long authkeynotfound;
+ extern u_long authencryptions;
+ extern u_long authdecryptions;
+ extern u_long authkeyuncached;
authkeylookups = 0;
authkeynotfound = 0;
authencryptions = 0;
authdecryptions = 0;
- authdecryptok = 0;
authkeyuncached = 0;
auth_timereset = current_time;
}
@@ -1839,7 +1925,7 @@ req_get_traps(srcadr, inter, inpkt)
it->settime = htonl(current_time - tr->tr_settime);
it->origtime = htonl(current_time - tr->tr_origtime);
it->resets = htonl(tr->tr_resets);
- it->flags = htonl((U_LONG)tr->tr_flags);
+ it->flags = htonl((u_long)tr->tr_flags);
it = (struct info_trap *)more_pkt();
}
}
@@ -1953,7 +2039,7 @@ set_request_keyid(srcadr, inter, inpkt)
struct interface *inter;
struct req_pkt *inpkt;
{
- U_LONG keyid;
+ u_long keyid;
/*
* Restrict ourselves to one item only.
@@ -1963,7 +2049,7 @@ set_request_keyid(srcadr, inter, inpkt)
return;
}
- keyid = ntohl(*((U_LONG *)(inpkt->data)));
+ keyid = ntohl(*((u_long *)(inpkt->data)));
info_auth_keyid = keyid;
req_ack(srcadr, inter, inpkt, INFO_OKAY);
}
@@ -1979,8 +2065,8 @@ set_control_keyid(srcadr, inter, inpkt)
struct interface *inter;
struct req_pkt *inpkt;
{
- U_LONG keyid;
- extern U_LONG ctl_auth_keyid;
+ u_long keyid;
+ extern u_long ctl_auth_keyid;
/*
* Restrict ourselves to one item only.
@@ -1990,7 +2076,7 @@ set_control_keyid(srcadr, inter, inpkt)
return;
}
- keyid = ntohl(*((U_LONG *)(inpkt->data)));
+ keyid = ntohl(*((u_long *)(inpkt->data)));
ctl_auth_keyid = keyid;
req_ack(srcadr, inter, inpkt, INFO_OKAY);
}
@@ -2011,21 +2097,21 @@ get_ctl_stats(srcadr, inter, inpkt)
/*
* Importations from the control module
*/
- extern U_LONG ctltimereset;
- extern U_LONG numctlreq;
- extern U_LONG numctlbadpkts;
- extern U_LONG numctlresponses;
- extern U_LONG numctlfrags;
- extern U_LONG numctlerrors;
- extern U_LONG numctltooshort;
- extern U_LONG numctlinputresp;
- extern U_LONG numctlinputfrag;
- extern U_LONG numctlinputerr;
- extern U_LONG numctlbadoffset;
- extern U_LONG numctlbadversion;
- extern U_LONG numctldatatooshort;
- extern U_LONG numctlbadop;
- extern U_LONG numasyncmsgs;
+ extern u_long ctltimereset;
+ extern u_long numctlreq;
+ extern u_long numctlbadpkts;
+ extern u_long numctlresponses;
+ extern u_long numctlfrags;
+ extern u_long numctlerrors;
+ extern u_long numctltooshort;
+ extern u_long numctlinputresp;
+ extern u_long numctlinputfrag;
+ extern u_long numctlinputerr;
+ extern u_long numctlbadoffset;
+ extern u_long numctlbadversion;
+ extern u_long numctldatatooshort;
+ extern u_long numctlbadop;
+ extern u_long numasyncmsgs;
ic = (struct info_control *)prepare_pkt(srcadr, inter, inpkt,
sizeof(struct info_control));
@@ -2074,13 +2160,13 @@ get_leap_info(srcadr, inter, inpkt)
extern u_char leap_indicator;
extern u_char leap_warning;
extern u_char leapbits;
- extern U_LONG leap_timer;
- extern U_LONG leap_processcalls;
- extern U_LONG leap_notclose;
- extern U_LONG leap_monthofleap;
- extern U_LONG leap_dayofleap;
- extern U_LONG leap_hoursfromleap;
- extern U_LONG leap_happened;
+ extern u_long leap_timer;
+ extern u_long leap_processcalls;
+ extern u_long leap_notclose;
+ extern u_long leap_monthofleap;
+ extern u_long leap_dayofleap;
+ extern u_long leap_hoursfromleap;
+ extern u_long leap_happened;
il = (struct info_leap *)prepare_pkt(srcadr, inter, inpkt,
sizeof(struct info_leap));
@@ -2200,7 +2286,7 @@ get_clock_info(srcadr, inter, inpkt)
ic->noresponse = htonl(clock.noresponse);
ic->badformat = htonl(clock.badformat);
ic->baddata = htonl(clock.baddata);
- ic->timestarted = clock.timereset;
+ ic->timestarted = htonl(clock.timereset);
HTONL_FP(&clock.fudgetime1, &ic->fudgetime1);
HTONL_FP(&clock.fudgetime2, &ic->fudgetime2);
ic->fudgeval1 = htonl(clock.fudgeval1);
@@ -2287,9 +2373,9 @@ set_precision(srcadr, inter, inpkt)
struct interface *inter;
struct req_pkt *inpkt;
{
- register LONG precision;
+ register long precision;
- precision = ntohl(*(LONG *)(inpkt->data));
+ precision = ntohl(*(long *)(inpkt->data));
if (INFO_NITEMS(inpkt->err_nitems) > 1 ||
precision > -1 || precision < -20) {
@@ -2355,10 +2441,9 @@ get_clkbug_info(srcadr, inter, inpkt)
if (i > NUMCBUGTIMES)
i = NUMCBUGTIMES;
ic->ntimes = (u_char)i;
- ic->stimes = htonl((U_LONG)bug.stimes & ((1<<i)-1));
+ ic->stimes = htonl(bug.stimes);
while (--i >= 0) {
- ic->times[i].l_ui = htonl(bug.times[i].l_ui);
- ic->times[i].l_uf = htonl(bug.times[i].l_uf);
+ HTONL_FP(&bug.times[i], &ic->times[i]);
}
ic = (struct info_clkbug *)more_pkt();
diff --git a/usr.sbin/xntpd/xntpd/ntp_unixclock.c b/usr.sbin/xntpd/xntpd/ntp_unixclock.c
index df728f0..8123c4f 100644
--- a/usr.sbin/xntpd/xntpd/ntp_unixclock.c
+++ b/usr.sbin/xntpd/xntpd/ntp_unixclock.c
@@ -1,4 +1,4 @@
-/* ntp_unixclock.c,v 3.1 1993/07/06 01:11:30 jbj Exp
+/*
* ntp_unixclock.c - routines for reading and adjusting a 4BSD-style
* system clock
*/
@@ -9,7 +9,7 @@
#include <sys/stat.h>
#include <sys/time.h>
-#if defined(SYS_HPUX) || defined(sgi) || defined(SYS_BSDI)
+#if defined(SYS_HPUX) || defined(sgi) || defined(SYS_BSDI) || defined(SYS_44BSD)
#include <sys/param.h>
#include <utmp.h>
#endif
@@ -24,7 +24,7 @@
#include "ntp_stdlib.h"
#if defined(HAVE_LIBKVM)
-#ifdef SYS_BSDI
+#if defined(SYS_BSDI) || defined(SYS_44BSD)
#include <sys/proc.h>
#endif /* SYS_BSDI */
#include <kvm.h>
@@ -65,19 +65,19 @@ extern int debug;
* We also remember the clock precision we computed from the kernel in
* case someone asks us.
*/
-extern LONG adj_precision; /* adj precision in usec (tickadj) */
-extern LONG tvu_maxslew; /* maximum adjust doable in 1<<CLOCK_ADJ sec (usec) */
+extern long adj_precision; /* adj precision in usec (tickadj) */
+extern long tvu_maxslew; /* maximum adjust doable in 1<<CLOCK_ADJ sec (usec) */
-extern U_LONG tsf_maxslew; /* same as above, as LONG format */
+extern u_long tsf_maxslew; /* same as above, as long format */
extern l_fp sys_clock_offset; /* correction for current system time */
/*
* Import sys_clock (it is updated in get_systime)
*/
-extern LONG sys_clock;
+extern long sys_clock;
-static void clock_parms P((U_LONG *, U_LONG *));
+static void clock_parms P((u_long *, u_long *));
/*
* init_systime - initialize the system clock support code, return
@@ -101,9 +101,9 @@ static void clock_parms P((U_LONG *, U_LONG *));
void
init_systime()
{
- U_LONG tickadj;
- U_LONG tick;
- U_LONG hz;
+ u_long tickadj;
+ u_long tick;
+ u_long hz;
/*
* Obtain the values
@@ -111,7 +111,7 @@ init_systime()
clock_parms(&tickadj, &tick);
#ifdef DEBUG
if (debug)
- printf("kernel vars: tickadj = %d, tick = %d\n", tickadj, tick);
+ printf("kernel vars: tickadj = %ld, tick = %ld\n", tickadj, tick);
#endif
/*
@@ -166,14 +166,14 @@ init_systime()
#ifdef DEBUG
if (debug)
printf(
- "adj_precision = %d, tvu_maxslew = %d, tsf_maxslew = 0.%08x\n",
+ "adj_precision = %ld, tvu_maxslew = %ld, tsf_maxslew = 0.%08lx\n",
adj_precision, tvu_maxslew, tsf_maxslew);
#endif
/*
* Set the current offset to 0
*/
- sys_clock_offset.l_ui = sys_clock_offset.l_uf = 0;
+ L_CLR(&sys_clock_offset);
}
#ifdef HAVE_LIBKVM
@@ -184,8 +184,8 @@ init_systime()
*/
static void
clock_parms(tickadj, tick)
- U_LONG *tickadj;
- U_LONG *tick;
+ u_long *tickadj;
+ u_long *tick;
{
static struct nlist nl[] = {
#define N_TICKADJ 0
@@ -265,8 +265,8 @@ clock_parms(tickadj, tick)
*/
static void
clock_parms(tickadj, tick)
- U_LONG *tickadj;
- U_LONG *tick;
+ u_long *tickadj;
+ u_long *tick;
{
*tick = 10000; /* microseconds */
*tickadj = 80; /* microseconds */
@@ -279,8 +279,13 @@ clock_parms(tickadj, tick)
#endif
#ifdef SYS_HPUX
+#if defined(hp9000s300)
#define K_TICKADJ_NAME "_tickadj"
#define K_TICK_NAME "_old_tick"
+#else
+#define K_TICKADJ_NAME "tickadj"
+#define K_TICK_NAME "old_tick"
+#endif
#endif
/* The defaults if not defined previously */
@@ -293,8 +298,8 @@ clock_parms(tickadj, tick)
static void
clock_parms(tickadj, tick)
- U_LONG *tickadj;
- U_LONG *tick;
+ u_long *tickadj;
+ u_long *tick;
{
register int i;
int kmem;
@@ -392,8 +397,8 @@ clock_parms(tickadj, tick)
}
close(kmem);
- *tickadj = (U_LONG)vars[K_TICKADJ];
- *tick = (U_LONG)vars[K_TICK];
+ *tickadj = (u_long)vars[K_TICKADJ];
+ *tick = (u_long)vars[K_TICK];
#undef K_TICKADJ
#undef K_TICK
@@ -413,8 +418,8 @@ clock_parms(tickadj, tick)
*/
static void
clock_parms(tickadj, tick)
- U_LONG *tickadj;
- U_LONG *tick;
+ u_long *tickadj;
+ u_long *tick;
{
int hz;
@@ -442,8 +447,8 @@ clock_parms(tickadj, tick)
*/
static void
clock_parms(tickadj, tick)
- U_LONG *tickadj;
- U_LONG *tick;
+ u_long *tickadj;
+ u_long *tick;
{
*tick = 10000;
*tickadj = 150;
@@ -463,8 +468,8 @@ clock_parms(tickadj, tick)
*/
static void
clock_parms(tickadj, tick)
- U_LONG *tickadj;
- U_LONG *tick;
+ u_long *tickadj;
+ u_long *tick;
{
#ifdef RS6000
*tickadj = 1000;
@@ -496,8 +501,8 @@ clock_parms(tickadj, tick)
*/
static void
clock_parms(tickadj, tick)
- U_LONG *tickadj;
- U_LONG *tick;
+ u_long *tickadj;
+ u_long *tick;
{
register int i;
int kmem;
@@ -575,8 +580,8 @@ clock_parms(tickadj, tick)
}
close(kmem);
- *tickadj = (U_LONG)vars[K_TICKADJ];
- *tick = (U_LONG)(1000000/sysconf(_SC_CLK_TCK));
+ *tickadj = (u_long)vars[K_TICKADJ];
+ *tick = (u_long)(1000000/sysconf(_SC_CLK_TCK));
#undef K_TICKADJ
#undef N_NAME
@@ -584,18 +589,18 @@ clock_parms(tickadj, tick)
#endif /* SOLARIS */
#ifdef SYS_LINUX
-#include <sys/timex.h>
+#include "sys/timex.h"
static void
clock_parms(tickadj, tick)
- U_LONG *tickadj;
- U_LONG *tick;
+ u_long *tickadj;
+ u_long *tick;
{
struct timex txc;
txc.mode = 0;
__adjtimex(&txc);
- *tickadj = (U_LONG)1; /* our adjtime is accurate */
- *tick = (U_LONG)txc.tick;
+ *tickadj = (u_long)1; /* our adjtime is accurate */
+ *tick = (u_long)txc.tick;
}
#endif /* SYS_LINUX */
diff --git a/usr.sbin/xntpd/xntpd/refclock_trak.c b/usr.sbin/xntpd/xntpd/refclock_trak.c
index f2b3eb1..d10d752 100644
--- a/usr.sbin/xntpd/xntpd/refclock_trak.c
+++ b/usr.sbin/xntpd/xntpd/refclock_trak.c
@@ -1,11 +1,10 @@
/*
- * refclock_trak.c - clock driver for the TRAK 8810 GPS STATION CLOCK
- * Tsuruoka Tomoaki Oct 30, 1993
- * tsuruoka@nc.fukuoka-u.ac.jp
- * Faculty of Engineering,
- * Fukuoka University, Fukuoka, JAPAN
+ * refclock_trak - clock driver for the TRAK 8820 GPS Station Clock
+ *
+ * Thanks to Tomoaki TSURUOKA <tsuruoka@nc.fukuoka-u.ac.jp> for the
+ * previous version from which this one was developed.
*/
-#if defined(REFCLOCK) && (defined(TRAK) || defined(TRAKCLK) || defined(TRAKPPS))
+#if defined(REFCLOCK) && defined(TRAK)
#include <stdio.h>
#include <ctype.h>
@@ -14,494 +13,201 @@
#include "ntpd.h"
#include "ntp_io.h"
#include "ntp_refclock.h"
-#include "ntp_unixtime.h"
-
-static void gps_send();
-
-#if defined(HAVE_BSD_TTYS)
-#include <sgtty.h>
-#endif /* HAVE_BSD_TTYS */
-
-#if defined(HAVE_SYSV_TTYS)
-#include <termio.h>
-#endif /* HAVE_SYSV_TTYS */
-
-#if defined(STREAM)
-#include <termios.h>
-#include <stropts.h>
-#if defined(TRAKCLK)
-#include <sys/clkdefs.h>
-#endif /* TRAKCLK */
-#endif /* STREAM */
-
-#if defined (TRAKPPS)
-#include <sys/ppsclock.h>
-#endif /* TRAKPPS */
-
#include "ntp_stdlib.h"
/*
- * This driver supports the TRAK 8810 GPS Receiver with
- * Buffered RS-232-C Interface Module.
+ * This driver supports the TRAK 8820 GPS Station Clock. The claimed
+ * accuracy at the 1-pps output is 200-300 ns relative to the broadcast
+ * signal; however, in most cases the actual accuracy is limited by the
+ * precision of the timecode and the latencies of the serial interface
+ * and operating system.
*
- * Most of codes are copied from refclock_as2201.c, Thanks a lot.
+ * For best accuracy, this radio requires the LDISC_ACTS line
+ * discipline, which captures a timestamp at the '*' on-time character
+ * of the timecode. Using this discipline the jitter is in the order of
+ * 1 ms and systematic error about 0.5 ms. If unavailable, the buffer
+ * timestamp is used, which is captured at the \r ending the timecode
+ * message. This introduces a systematic error of 23 character times, or
+ * about 24 ms at 9600 bps, together with a jitter well over 8 ms on Sun
+ * IPC-class machines.
*
- * The program expects the radio responses once per seccond
- * ( by "rqts,u" command or panel control )
- * of the form "*RQTS U,ddd:hh:mm:ss.0,Q\r\n for UTC" where
- * ddd= day of year
- * hh= hours
- * mm= minutes
- * ss= seconds
- * Q= Quality byte. Q=0 Phase error > 20 us
- * Q=6 Pahse error < 20 us
- * > 10 us
- * Q=5 Pahse error < 10 us
- * > 1 us
- * Q=4 Pahse error < 1 us
- * > 100 ns
- * Q=3 Pahse error < 100 ns
- * > 10 ns
- * Q=2 Pahse error < 10 ns
- * (note that my clock almost stable at 1 us per 10 hours)
+ * Using the memus, the radio should be set for 9600 bps, one stop bit
+ * and no parity. It should be set to operate in computer (no echo)
+ * mode. The timecode format includes neither the year nor leap-second
+ * warning. No provisions are included in this preliminary version of
+ * the driver to read and record detailed internal radio status.
*
- * Request leap second status - if needed.
- * send: rqls\n
- * reply: RQLS yy,mm,dd
- * where: yy is year
- * mm is month
- * dd is day of month.baud
- * Note: Default data is all zeros
- * i.e. RQLS 00,00,00
- */
-
-/*
- * Definitions
+ * In operation, this driver sends a RQTS\r request to the radio at
+ * initialization in order to put it in continuous time output mode. The
+ * radio then sends the following message once each second:
+ *
+ * *RQTS U,ddd:hh:mm:ss.0,q<cr><lf>
+ *
+ * on-time = '*' * ddd = day of year
+ * hh:mm:ss = hours, minutes, seconds
+ * q = quality indicator (phase error), 0-6:
+ * 0 > 20 us
+ * 6 > 10 us
+ * 5 > 1 us
+ * 4 > 100 ns
+ * 3 > 10 ns
+ * 2 < 10 ns
+ *
+ * The alarm condition is indicated by '0' at Q, which means the radio
+ * has a phase error than 20 usec relative to the broadcast time. The
+ * absence of year, DST and leap-second warning in this format is also
+ * alarming.
+ *
+ * The continuous time mode is disabled using the RQTX<cr> request,
+ * following which the radio sends a RQTX DONE<cr><lf> response. In the
+ * normal mode, other control and status requests are effective,
+ * including the leap-second status request RQLS<cr>. The radio responds
+ * wtih RQLS yy,mm,dd<cr><lf>, where yy,mm,dd are the year, month and
+ * day. Presumably, this gives the epoch of the next leap second,
+ * RQLS 00,00,00 if none is specified in the GPS message. Specified in
+ * this form, the information is generally useless and is ignored by
+ * the driver.
+ *
+ * Fudge Factors
+ *
+ * There are no special fudge factors other than the generic.
*/
-#define MAXUNITS 4 /* max number of GPS units */
-#define GPS232 "/dev/gps%d" /* name of radio device */
-#define SPEED232 B9600 /* uart speed (9600 bps) */
/*
- * Radio interface parameters
+ * Interface definitions
*/
-#define GPSPRECISION (-20) /* precision assumed (about 1 us) */
-#define GPSREFID "GPS" /* reference id */
-#define GPSDESCRIPTION "TRAK 8810 GPS station clock" /* who we are */
-#define GPSHSREFID 0x7f7f020a /* 127.127.2.10 refid hi strata */
-#define GMT 0 /* hour offset from Greenwich */
-#define NCODES 3 /* stages of median filter */
-#define LENTOC 25 /* *RQTS U,ddd:hh:mm:ss.0,Q datecode length */
-#define BMAX 100 /* timecode buffer length */
-#define CODEDIFF 0x20000000 /* 0.125 seconds as an l_fp fraction */
+#define DEVICE "/dev/trak%d" /* device name and unit */
+#define SPEED232 B9600 /* uart speed (9600 baud) */
+#define PRECISION (-10) /* precision assumed (about 1 ms) */
+#define REFID "TRAK" /* reference ID */
+#define DESCRIPTION "TRACK 8810/8820 Station Clock" /* WRU */
-/*
- * Hack to avoid excercising the multiplier. I have no pride.
- */
-#define MULBY10(x) (((x)<<3) + ((x)<<1))
+#define NSAMPLES 3 /* stages of median filter */
+#define LENTRAK 24 /* timecode length */
+#define C_CTO "RQTS\r" /* start continuous time output */
/*
* Imported from ntp_timer module
*/
-extern U_LONG current_time; /* current time (s) */
-
-/*
- * Imported from ntp_loopfilter module
- */
-extern int fdpps; /* pps file descriptor */
+extern u_long current_time; /* current time (s) */
/*
* Imported from ntpd module
*/
-extern int debug; /* global debug flag */
+extern int debug; /* global debug flag */
/*
- * GPS unit control structure.
+ * Unit control structure
*/
-struct gpsunit {
- struct peer *peer; /* associated peer structure */
- struct refclockio io; /* given to the I/O handler */
- l_fp lastrec; /* last data receive time */
- l_fp lastref; /* last timecode time */
- l_fp offset[NCODES]; /* recent sample offsets */
- char lastcode[BMAX]; /* last timecode received */
- u_short polled; /* when polled, means a last sample */
- u_char lencode; /* length of last received ASCII string */
- U_LONG lasttime; /* last time clock heard from */
-#ifdef TRAKPPS
- U_LONG lastev; /* last ppsclock second */
-#endif /* TRAKPPS */
- u_char unit; /* unit number for this guy */
- u_char status; /* clock status */
- u_char lastevent; /* last clock event */
- u_char reason; /* reason for last abort */
- u_char year; /* year of eternity */
- u_short day; /* day of year */
- u_char hour; /* hour of day */
- u_char minute; /* minute of hour */
- u_char second; /* seconds of minute */
- u_short msec; /* milliseconds of second */
- u_char leap; /* leap indicators */
- U_LONG yearstart; /* start of current year */
- /*
- * Status tallies
- */
- U_LONG polls; /* polls sent */
- U_LONG noreply; /* no replies to polls */
- U_LONG coderecv; /* timecodes received */
- U_LONG badformat; /* bad format */
- U_LONG baddata; /* bad data */
- U_LONG timestarted; /* time we started this */
-};
-
+struct wwvbunit {
+ int pollcnt; /* poll message counter */
-/*
- * Data space for the unit structures. Note that we allocate these on
- * the fly, but never give them back.
- */
-static struct gpsunit *gpsunits[MAXUNITS];
-static u_char unitinuse[MAXUNITS];
-
-/*
- * Keep the fudge factors separately so they can be set even
- * when no clock is configured.
- */
-static l_fp fudgefactor[MAXUNITS];
-static u_char stratumtouse[MAXUNITS];
-static u_char sloppyclockflag[MAXUNITS];
+ u_char tcswitch; /* timecode switch */
+ char qualchar; /* quality indicator */
+};
/*
* Function prototypes
*/
-static void trak_init P(());
-static int trak_start P((u_int, struct peer *));
-static void trak_shutdown P((int));
-static void trak_report_event P((struct gpsunit *, int));
+static int trak_start P((int, struct peer *));
+static void trak_shutdown P((int, struct peer *));
static void trak_receive P((struct recvbuf *));
-static char trak_process P((struct gpsunit *, l_fp *, u_fp *));
-static void trak_poll P((int unit, struct peer *));
-static void trak_control P((u_int, struct refclockstat *, struct refclockstat *));
-static void trak_buginfo P((int, struct refclockbug *));
+static void trak_poll P((int, struct peer *));
/*
* Transfer vector
*/
-struct refclock refclock_trak = {
- trak_start, trak_shutdown, trak_poll,
- trak_control, trak_init, trak_buginfo, NOFLAGS
+struct refclock refclock_trak = {
+ trak_start, /* start up driver */
+ trak_shutdown, /* shut down driver */
+ trak_poll, /* transmit poll message */
+ noentry, /* not used (old trak_control) */
+ noentry, /* initialize driver (not used) */
+ noentry, /* not used (old trak_buginfo) */
+ NOFLAGS /* not used */
};
-/*
- * trak_init - initialize internal gps driver data
- */
-static void
-trak_init()
-{
- register int i;
- /*
- * Just zero the data arrays
- */
- memset((char *)gpsunits, 0, sizeof gpsunits);
- memset((char *)unitinuse, 0, sizeof unitinuse);
-
- /*
- * Initialize fudge factors to default.
- */
- for (i = 0; i < MAXUNITS; i++) {
- fudgefactor[i].l_ui = 0;
- fudgefactor[i].l_uf = 0;
- stratumtouse[i] = 0;
- sloppyclockflag[i] = 0;
- }
-}
-
/*
- * trak_start - open the GPS devices and initialize data for processing
+ * trak_start - open the devices and initialize data for processing
*/
static int
trak_start(unit, peer)
- u_int unit;
+ int unit;
struct peer *peer;
{
- register struct gpsunit *gps;
- register int i;
- int fd232;
- char trakdev[20];
-#ifdef TRAKPPS
- struct ppsclockev ev;
-#endif /* TRAKPPS */
+ register struct wwvbunit *up;
+ struct refclockproc *pp;
+ int fd;
+ char device[20];
/*
- * Check configuration info
+ * Open serial port. The LDISC_ACTS line discipline inserts a
+ * timestamp following the "*" on-time character of the
+ * timecode.
*/
- if (unit >= MAXUNITS) {
- syslog(LOG_ERR, "trak_start: unit %d invalid", unit);
- return (0);
- }
- if (unitinuse[unit]) {
- syslog(LOG_ERR, "trak_start: unit %d in use", unit);
+ (void)sprintf(device, DEVICE, unit);
+ if (!(fd = refclock_open(device, SPEED232, LDISC_ACTS)))
return (0);
- }
/*
- * Open serial port
+ * Allocate and initialize unit structure
*/
- (void) sprintf(trakdev, GPS232, unit);
- fd232 = open(trakdev, O_RDWR, 0777);
- if (fd232 == -1) {
- syslog(LOG_ERR, "trak_start: open of %s: %m", trakdev);
+ if (!(up = (struct wwvbunit *)
+ emalloc(sizeof(struct wwvbunit)))) {
+ (void) close(fd);
return (0);
}
-
-#if defined(HAVE_SYSV_TTYS)
- /*
- * System V serial line parameters (termio interface)
- *
- */
- { struct termio ttyb;
- if (ioctl(fd232, TCGETA, &ttyb) < 0) {
- syslog(LOG_ERR,
- "trak_start: ioctl(%s, TCGETA): %m", trakdev);
- goto screwed;
- }
- ttyb.c_iflag = IGNBRK|IGNPAR|ICRNL;
- ttyb.c_oflag = 0;
- ttyb.c_cflag = SPEED232|CS8|CLOCAL|CREAD;
- ttyb.c_lflag = ICANON;
- ttyb.c_cc[VERASE] = ttyb.c_cc[VKILL] = '\0';
- if (ioctl(fd232, TCSETA, &ttyb) < 0) {
- syslog(LOG_ERR,
- "trak_start: ioctl(%s, TCSETA): %m", trakdev);
- goto screwed;
- }
- }
-#endif /* HAVE_SYSV_TTYS */
-#if defined(STREAM)
- /*
- * POSIX/STREAMS serial line parameters (termios interface)
- *
- * The TRAKCLK option provides timestamping at the driver level.
- * It requires the tty_clk streams module.
- *
- * The TRAKPPS option provides timestamping at the driver level.
- * It uses a 1-pps signal and level converter (gadget box) and
- * requires the ppsclock streams module and SunOS 4.1.1 or
- * later.
- */
- { struct termios ttyb, *ttyp;
-
- ttyp = &ttyb;
- if (tcgetattr(fd232, ttyp) < 0) {
- syslog(LOG_ERR,
- "trak_start: tcgetattr(%s): %m", trakdev);
- goto screwed;
- }
- ttyp->c_iflag = IGNBRK|IGNPAR;
- ttyp->c_oflag = 0;
- ttyp->c_cflag = SPEED232|CS8|CLOCAL|CREAD;
- ttyp->c_lflag = ICANON;
- ttyp->c_cc[VERASE] = ttyp->c_cc[VKILL] = '\0';
- if (tcsetattr(fd232, TCSANOW, ttyp) < 0) {
- syslog(LOG_ERR,
- "trak_start: tcsetattr(%s): %m", trakdev);
- goto screwed;
- }
- if (tcflush(fd232, TCIOFLUSH) < 0) {
- syslog(LOG_ERR,
- "trak_start: tcflush(%s): %m", trakdev);
- goto screwed;
- }
-#if defined(TRAKCLK)
- if (ioctl(fd232, I_PUSH, "clk") < 0)
- syslog(LOG_ERR,
- "trak_start: ioctl(%s, I_PUSH, clk): %m", trakdev);
- if (ioctl(fd232, CLK_SETSTR, "*") < 0)
- syslog(LOG_ERR,
- "trak_start: ioctl(%s, CLK_SETSTR): %m", trakdev);
-#endif /* TRAKCLK */
-#if defined(TRAKPPS)
- if (ioctl(fd232, I_PUSH, "ppsclock") < 0)
- syslog(LOG_ERR,
- "trak_start: ioctl(%s, I_PUSH, ppsclock): %m", trakdev);
- else
- fdpps = fd232;
-#endif /* TRAKPPS */
- }
-#endif /* STREAM */
-#if defined(HAVE_BSD_TTYS)
- /*
- * 4.3bsd serial line parameters (sgttyb interface)
- *
- * The TRAKCLK option provides timestamping at the driver level.
- * It requires the tty_clk line discipline and 4.3bsd or later.
- */
- { struct sgttyb ttyb;
-#if defined(TRAKCLK)
- int ldisc = CLKLDISC;
-#endif /* TRAKCLK */
-
- if (ioctl(fd232, TIOCGETP, &ttyb) < 0) {
- syslog(LOG_ERR,
- "trak_start: ioctl(%s, TIOCGETP): %m", trakdev);
- goto screwed;
- }
- ttyb.sg_ispeed = ttyb.sg_ospeed = SPEED232;
-#if defined(TRAKCLK)
- ttyb.sg_erase = ttyb.sg_kill = '\r';
- ttyb.sg_flags = RAW;
-#else
- ttyb.sg_erase = ttyb.sg_kill = '\0';
- ttyb.sg_flags = EVENP|ODDP|CRMOD;
-#endif /* TRAKCLK */
- if (ioctl(fd232, TIOCSETP, &ttyb) < 0) {
- syslog(LOG_ERR,
- "trak_start: ioctl(%s, TIOCSETP): %m", trakdev);
- goto screwed;
- }
-#if defined(TRAKCLK)
- if (ioctl(fd232, TIOCSETD, &ldisc) < 0) {
- syslog(LOG_ERR,
- "trak_start: ioctl(%s, TIOCSETD): %m",trakdev);
- goto screwed;
- }
-#endif /* TRAKCLK */
- }
-#endif /* HAVE_BSD_TTYS */
-
- /*
- * Allocate unit structure
- */
- if (gpsunits[unit] != 0) {
- gps = gpsunits[unit]; /* The one we want is okay */
- } else {
- for (i = 0; i < MAXUNITS; i++) {
- if (!unitinuse[i] && gpsunits[i] != 0)
- break;
- }
- if (i < MAXUNITS) {
- /*
- * Reclaim this one
- */
- gps = gpsunits[i];
- gpsunits[i] = 0;
- } else {
- gps = (struct gpsunit *)
- emalloc(sizeof(struct gpsunit));
- }
+ memset((char *)up, 0, sizeof(struct wwvbunit));
+ pp = peer->procptr;
+ pp->io.clock_recv = trak_receive;
+ pp->io.srcclock = (caddr_t)peer;
+ pp->io.datalen = 0;
+ pp->io.fd = fd;
+ if (!io_addclock(&pp->io)) {
+ (void) close(fd);
+ free(up);
+ return (0);
}
- bzero((char *)gps, sizeof(struct gpsunit));
- gpsunits[unit] = gps;
+ pp->unitptr = (caddr_t)up;
/*
- * Set up the structures
+ * Initialize miscellaneous variables
*/
- gps->peer = peer;
- gps->unit = (u_char)unit;
- gps->timestarted = current_time;
-
- gps->io.clock_recv = trak_receive;
- gps->io.srcclock = (caddr_t)gps;
- gps->io.datalen = 0;
- gps->io.fd = fd232;
-#ifdef TRAKPPS
- if (ioctl(fd232, CIOGETEV, (caddr_t)&ev) < 0) {
- syslog(LOG_ERR,
- "trak_start: ioctl(%s, CIOGETEV): %m", trakdev);
- goto screwed;
- } else
- gps->lastev = ev.tv.tv_sec;
-#endif /* TRAKPPS */
- if (!io_addclock(&gps->io)) {
- goto screwed;
- }
+ peer->precision = PRECISION;
+ pp->clockdesc = DESCRIPTION;
+ memcpy((char *)&pp->refid, REFID, 4);
+ up->pollcnt = 2;
/*
- * All done. Initialize a few random peer variables, then
- * return success. Note that root delay and root dispersion are
- * always zero for this clock.
- */
- peer->precision = GPSPRECISION;
- peer->rootdelay = 0;
- peer->rootdispersion = 0;
- peer->stratum = stratumtouse[unit];
- if (stratumtouse[unit] <= 1)
- bcopy(GPSREFID, (char *)&peer->refid, 4);
- else
- peer->refid = htonl(GPSHSREFID);
- unitinuse[unit] = 1;
- /*
- * request to give time code
+ * Start continuous time output. If something breaks, fold the
+ * tent and go home.
*/
- {
- void gps_send();
- gps_send(gps,"\rRQTS,U\r");
- gps_send(gps,"SEL 00\r");
+ if (write(pp->io.fd, C_CTO, sizeof(C_CTO)) != sizeof(C_CTO)) {
+ refclock_report(peer, CEVNT_FAULT);
+ (void) close(fd);
+ free(up);
+ return (0);
}
-
return (1);
-
- /*
- * Something broke; abandon ship.
- */
-screwed:
- (void) close(fd232);
- return (0);
-}
-
-/*
- * trak_shutdown - shut down a GPS clock
- */
-static void
-trak_shutdown(unit)
- int unit;
-{
- register struct gpsunit *gps;
- void gps_send();
-
- if (unit >= MAXUNITS) {
- syslog(LOG_ERR, "trak_shutdown: unit %d invalid", unit);
- return;
- }
- if (!unitinuse[unit]) {
- syslog(LOG_ERR, "trak_shutdown: unit %d not in use", unit);
- return;
- }
- gps = gpsunits[unit];
- /*
- * request not to give time code any more
- */
- gps_send(gps,"RQTX\r");
- /*
- * Tell the I/O module to turn us off. We're history.
- */
- io_closeclock(&gps->io);
-
- unitinuse[unit] = 0;
}
/*
- * trak_report_event - note the occurance of an event
- *
- * This routine presently just remembers the report and logs it, but
- * does nothing heroic for the trap handler.
+ * trak_shutdown - shut down the clock
*/
static void
-trak_report_event(gps, code)
- struct gpsunit *gps;
- int code;
-{
+trak_shutdown(unit, peer)
+ int unit;
struct peer *peer;
+{
+ register struct wwvbunit *up;
+ struct refclockproc *pp;
- peer = gps->peer;
- if (gps->status != (u_char)code) {
- gps->status = (u_char)code;
- if (code != CEVNT_NOMINAL)
- gps->lastevent = (u_char)code;
- syslog(LOG_INFO,
- "clock %s event %x\n", ntoa(&peer->srcadr), code);
- }
+ pp = peer->procptr;
+ up = (struct wwvbunit *)pp->unitptr;
+ io_closeclock(&pp->io);
+ free(up);
}
@@ -512,495 +218,122 @@ static void
trak_receive(rbufp)
struct recvbuf *rbufp;
{
- register int i,cmdtype;
- register struct gpsunit *gps;
-
-#if defined(TRAKPPS)
- struct ppsclockev ev;
+ register struct wwvbunit *up;
+ struct refclockproc *pp;
+ struct peer *peer;
l_fp trtmp;
-#endif /* TRAKPPS */
- register u_char *dpt;
- register u_char *cp;
- register u_char *dpend;
- l_fp tstmp;
- u_fp dispersion;
+ char *dpt, *dpend;
+ char qchar;
/*
- * Get the clock this applies to and pointers to the data.
- * Edit the timecode to remove control chars and trashbits.
+ * Initialize pointers and read the timecode and timestamp. We
+ * then chuck out everything, including runts, except one
+ * message each poll interval.
*/
- gps = (struct gpsunit *)rbufp->recv_srcclock;
- dpt = (u_char *)&rbufp->recv_space;
- dpend = dpt + rbufp->recv_length;
- cp = (u_char *)gps->lastcode;
-
- while (dpt < dpend) {
-#ifdef TRAKCLK /* prior to TRAKPPS due to timestamp */
- if ((*cp = 0x7f & *dpt++) != '*' ) cp++;
- else if (*cp == '*' ) { /* caught magic character */
- if ( dpend - dpt < 8) {
- /* short timestamp */
- if(debug) puts("gps: short timestamp.");
- return;
- }
- if (!buftvtots(dpt,&gps->lastrec)) {
- /* screwy timestamp */
- if(debug) puts("gps: screwy timestamp.");
- return;
- }
- dpt += 8;
+ peer = (struct peer *)rbufp->recv_srcclock;
+ pp = peer->procptr;
+ up = (struct wwvbunit *)pp->unitptr;
+ pp->lencode = refclock_gtlin(rbufp, pp->lastcode, BMAX,
+ &pp->lastrec);
+ if (up->tcswitch || pp->lencode < 9)
+ return;
+ up->tcswitch = 1;
+
+ /*
+ * We get a buffer and timestamp following the '*' on-time
+ * character. If a valid timestamp, we use that in place of the
+ * buffer timestamp and edit out the timestamp for prettyprint
+ * billboards.
+ */
+ dpt = pp->lastcode;
+ dpend = dpt + pp->lencode;
+ if (*dpt == '*' && buftvtots(dpt + 1, &trtmp)) {
+ if (trtmp.l_i == pp->lastrec.l_i || trtmp.l_i ==
+ pp->lastrec.l_i + 1) {
+ pp->lastrec = trtmp;
+ dpt += 9;
+ while (dpt < dpend)
+ *(dpt - 8) = *dpt++;
}
-#else
-#ifdef TRAKPPS
- if ((*cp = 0x7f & *dpt++) >= ' ') cp++;
-#else
- /* both are not specified */
-#endif /* TRAKPPS */
-#endif /* TRAKCLK */
}
- *cp = '\0';
- gps->lencode = cp - (u_char *)gps->lastcode;
- if (gps->lencode == 0) return;
-
+ up->pollcnt = 2;
+ record_clock_stats(&peer->srcadr, pp->lastcode);
#ifdef DEBUG
if (debug)
- printf("gps: timecode %d %s\n",
- gps->lencode, gps->lastcode);
+ printf("trak: timecode %d %s\n", pp->lencode,
+ pp->lastcode);
#endif
/*
- * We check the timecode format and decode its contents. The
- * timecode has format *........RQTS U,ddd:hh:mm:ss.0,Q\r\n).
- * 012345678901234567890123
+ * We get down to business, check the timecode format and decode
+ * its contents. If the timecode has invalid length or is not in
+ * proper format, we declare bad format and exit.
*/
-#define RQTS 0
-#define RQLS 1
- cp = (u_char *)gps->lastcode;
- gps->leap = 0;
- cmdtype=0;
- if(strncmp(cp,"*RQTS",5)==0) {
- cmdtype=RQTS;
- cp += 8;
- }
- else if(strncmp(cp,"RQTS",4)==0) {
- cmdtype=RQTS;
- cp += 7;
- }
- else if(strncmp(cp,"RQLS",4)==0) {
- cmdtype=RQLS;
- cp += 5;
- }
- else
- return;
-
- switch( cmdtype ) {
- case RQTS:
- /*
- * Check time code format of TRAK 8810
- */
- if( !isdigit(cp[0]) ||
- !isdigit(cp[1]) ||
- !isdigit(cp[2]) ||
- cp[3] != ':' ||
- !isdigit(cp[4]) ||
- !isdigit(cp[5]) ||
- cp[6] != ':' ||
- !isdigit(cp[7]) ||
- !isdigit(cp[8]) ||
- cp[9] != ':' ||
- !isdigit(cp[10])||
- !isdigit(cp[11])) {
- gps->badformat++;
- trak_report_event(gps, CEVNT_BADREPLY);
- return;
- }
- break;
- case RQLS:
- /*
- * reply for leap second request
- */
- if (cp[0] !='0' || cp[1] != '0' ) gps->leap = LEAP_ADDSECOND;
- return;
- default:
+ if (pp->lencode < LENTRAK) {
+ refclock_report(peer, CEVNT_BADREPLY);
return;
-
}
/*
- * Convert date and check values.
- */
- gps->day = cp[0] - '0';
- gps->day = MULBY10(gps->day) + cp[1] - '0';
- gps->day = MULBY10(gps->day) + cp[2] - '0';
- if (gps->day < 1 || gps->day > 366) {
- gps->baddata++;
- trak_report_event(gps, CEVNT_BADDATE);
- return;
- }
- /*
- * Convert time and check values.
- */
- gps->hour = MULBY10(cp[4] - '0') + cp[5] - '0';
- gps->minute = MULBY10(cp[7] - '0') + cp[8] - '0';
- gps->second = MULBY10(cp[10] - '0') + cp[11] - '0';
- gps->msec = 0;
- if (gps->hour > 23 || gps->minute > 59 || gps->second > 59) {
- gps->baddata++;
- trak_report_event(gps, CEVNT_BADTIME);
+ * Timecode format: "*RQTS U,ddd:hh:mm:ss.0,q"
+ */
+ if (sscanf(pp->lastcode, "*RQTS U,%3d:%2d:%2d:%2d.0,%c",
+ &pp->day, &pp->hour, &pp->minute, &pp->second, &qchar) != 5) {
+ refclock_report(peer, CEVNT_BADREPLY);
return;
}
- if (!gps->polled) return;
-
/*
- * Test for synchronization Check for quality byte.
+ * Decode quality and leap characters. If unsynchronized, set
+ * the leap bits accordingly and exit.
*/
-/*
- switch( cp[15] ) {
- case '0':
- if(gps->peer->stratum == stratumtouse[gps->unit]) {
- gps->peer->stratum = 10 ;
- bzero(&gps->peer->refid,4);
- }
- break;
- default:
- if(gps->peer->stratum != stratumtouse[gps->unit]) {
- gps->peer->stratum = stratumtouse[gps->unit] ;
- bcopy(GPSREFID,&gps->peer->refid,4);
- }
- break;
+ if (qchar == '0')
+ pp->leap = LEAP_NOTINSYNC;
+ else {
+ pp->leap = 0;
+ pp->lasttime = current_time;
}
-*/
- if( cp[15] == '0') /* TRAK derailed from tracking satellites */
- {
- gps->leap = LEAP_NOTINSYNC;
- gps->noreply++;
- trak_report_event(gps, CEVNT_TIMEOUT);
- }
- else
- {
- gps->lasttime = current_time;
- if( gps->lastevent == CEVNT_TIMEOUT ) {
- gps->status = CEVNT_NOMINAL;
- trak_report_event(gps, CEVNT_NOMINAL);
- }
- }
-
- /*
- * Now, compute the reference time value. Use the heavy
- * machinery for the second, which presumably is the one which
- * occured at the last pps pulse and which was captured by the
- * loop_filter module. All we have to do here is present a
- * reasonable facsimile of the time at that pulse so the clock-
- * filter and selection machinery declares us truechimer. The
- * precision offset within the second is really tuned by the
- * loop_filter module. Note that this code does not yet know how
- * to do the years and relies on the clock-calendar chip for
- * sanity.
- */
-
-#if defined(TRAKPPS)
-
- /*
- * timestamp must be greater than previous one.
- */
- if (ioctl(fdpps, CIOGETEV, (caddr_t)&ev) >= 0) {
- ev.tv.tv_sec += (U_LONG)JAN_1970;
- TVTOTS(&ev.tv,&gps->lastrec);
- if (gps->lastev < ev.tv.tv_sec) {
- gps->lastev = ev.tv.tv_sec;
- } else { /* in case of 1-pps missing */
- gps->lastev = ev.tv.tv_sec;
- return;
- }
- }
- else
- return; /* failed to get timestamp */
-#endif /* TRAKPPS */
-
- if (!clocktime(gps->day, gps->hour, gps->minute,
- gps->second, GMT, gps->lastrec.l_ui,
- &gps->yearstart, &gps->lastref.l_ui)) {
- gps->baddata++;
- trak_report_event(gps, CEVNT_BADTIME);
-#ifdef DEBUG
- if(debug) printf("gps: bad date \n");
-#endif
- return;
- }
- MSUTOTSF(gps->msec, gps->lastref.l_uf);
- tstmp = gps->lastref;
-
- L_SUB(&tstmp, &gps->lastrec);
- L_ADD(&tstmp, &(fudgefactor[gps->unit]));
- i = ((int)(gps->coderecv)) % NCODES;
- gps->offset[i] = tstmp;
- gps->coderecv++;
-#if DEBUG
- if (debug)
- printf("gps: times %s %s %s\n",
- ulfptoa(&gps->lastref, 6), ulfptoa(&gps->lastrec, 6),
- lfptoa(&tstmp, 6));
-#endif
-/* if( tstmp.l_ui != 0 ) return; something wrong */
/*
- * Process the samples in the median filter, add the fudge
- * factor and pass the offset and dispersion along. We use
- * lastref as both the reference time and receive time in order
- * to avoid being cute, like setting the reference time later
- * than the receive time, which may cause a paranoid protocol
- * module to chuck out the data.
+ * Process the new sample in the median filter and determine the
+ * reference clock offset and dispersion. We use lastrec as both
+ * the reference time and receive time in order to avoid being
+ * cute, like setting the reference time later than the receive
+ * time, which may cause a paranoid protocol module to chuck out
+ * the data.
*/
- if (gps->coderecv < NCODES)
- return;
- if (!trak_process(gps, &tstmp, &dispersion)) {
- gps->baddata++;
- trak_report_event(gps, CEVNT_BADTIME);
+ if (!refclock_process(pp, NSAMPLES, NSAMPLES)) {
+ refclock_report(peer, CEVNT_BADTIME);
return;
}
- refclock_receive(gps->peer, &tstmp, GMT, dispersion,
- &gps->lastrec, &gps->lastrec, gps->leap);
- /*
- * after all, clear polled flag
- */
- gps->polled = 0;
+ refclock_receive(peer, &pp->offset, 0, pp->dispersion,
+ &pp->lastrec, &pp->lastrec, pp->leap);
}
-/*
- * ==================================================================
- * gps_send(gps,cmd) Sends a command to the GPS receiver.
- * as gps_send(gps,"rqts,u\r");
- * ==================================================================
- */
-static void
-gps_send(gps,cmd)
- struct gpsunit *gps;
- char *cmd;
-{
- if (write(gps->io.fd, cmd, strlen(cmd)) == -1) {
- syslog(LOG_ERR, "gps_send: unit %d: %m", gps->unit);
- trak_report_event(gps,CEVNT_FAULT);
- } else {
- gps->polls++;
- }
-}
-
-/*
- * trak_process - process a pile of samples from the clock
- *
- * This routine uses a three-stage median filter to calculate offset and
- * dispersion and reduce jitter. The dispersion is calculated as the
- * span of the filter (max - min).
- */
-static char
-trak_process(gps, offset, dispersion)
- struct gpsunit *gps;
- l_fp *offset;
- u_fp *dispersion;
-{
- register int i, j;
- register U_LONG tmp_ui, tmp_uf;
- int not_median1 = -1; /* XXX correct? */
- int not_median2 = -1; /* XXX correct? */
- int median;
- u_fp disp_tmp, disp_tmp2;
-
- /*
- * This code implements a three-stage median filter. First, we
- * check if the samples are within 125 ms of each other. If not,
- * dump the sample set. We take the median of the three offsets
- * and use that as the sample offset. There probably is not much
- * to be gained by a longer filter, since the clock filter in
- * ntp_proto should do its thing.
- */
- disp_tmp2 = 0;
- for (i = 0; i < NCODES-1; i++) {
- for (j = i+1; j < NCODES; j++) {
- tmp_ui = gps->offset[i].l_ui;
- tmp_uf = gps->offset[i].l_uf;
- M_SUB(tmp_ui, tmp_uf, gps->offset[j].l_ui,
- gps->offset[j].l_uf);
- if (M_ISNEG(tmp_ui, tmp_uf)) {
- M_NEG(tmp_ui, tmp_uf);
- }
- if (tmp_ui != 0 || tmp_uf > CODEDIFF) {
- return (0);
- }
- disp_tmp = MFPTOFP(0, tmp_uf);
- if (disp_tmp > disp_tmp2) {
- disp_tmp2 = disp_tmp;
- not_median1 = i;
- not_median2 = j;
- }
- }
- }
- if (gps->lasttime == 0)
- disp_tmp2 = NTP_MAXDISPERSE;
- else
- disp_tmp2 = current_time - gps->lasttime;
- if (not_median1 == 0) {
- if (not_median2 == 1)
- median = 2;
- else
- median = 1;
- } else {
- median = 0;
- }
- *offset = gps->offset[median];
- *dispersion = disp_tmp2;
- return (1);
-}
/*
* trak_poll - called by the transmit procedure
- *
- * We go to great pains to avoid changing state here, since there may be
- * more than one eavesdropper receiving the same timecode.
*/
static void
trak_poll(unit, peer)
int unit;
struct peer *peer;
{
- struct gpsunit *gps;
+ register struct wwvbunit *up;
+ struct refclockproc *pp;
- if (unit >= MAXUNITS) {
- syslog(LOG_ERR, "trak_poll: unit %d invalid", unit);
- return;
- }
- if (!unitinuse[unit]) {
- syslog(LOG_ERR, "trak_poll: unit %d not in use", unit);
- return;
- }
- gps = gpsunits[unit];
- if ((current_time - gps->lasttime) > 150)
- trak_report_event(gpsunits[unit], CEVNT_TIMEOUT);
/*
- * usually trak_receive can get a timestamp every second
+ * We don't really do anything here, except arm the receiving
+ * side to capture a sample and check for timeouts.
*/
-#if !defined(TRAKPPS) && !defined(TRAKCLK)
- gettstamp(&gps->lastrec);
-#endif
- gps->polls++;
- /*
- * may be polled every 16 seconds (minpoll 4)
- */
- gps->polled = 1;
-}
-
-/*
- * trak_control - set fudge factors, return statistics
- */
-static void
-trak_control(unit, in, out)
- u_int unit;
- struct refclockstat *in;
- struct refclockstat *out;
-{
- register struct gpsunit *gps;
-
- if (unit >= MAXUNITS) {
- syslog(LOG_ERR, "trak_control: unit %d invalid", unit);
- return;
- }
-
- if (in != 0) {
- if (in->haveflags & CLK_HAVETIME1)
- fudgefactor[unit] = in->fudgetime1;
- if (in->haveflags & CLK_HAVEVAL1) {
- stratumtouse[unit] = (u_char)(in->fudgeval1 & 0xf);
- if (unitinuse[unit]) {
- struct peer *peer;
-
- /*
- * Should actually reselect clock, but
- * will wait for the next timecode
- */
- gps = gpsunits[unit];
- peer = gps->peer;
- peer->stratum = stratumtouse[unit];
- if (stratumtouse[unit] <= 1)
- bcopy(GPSREFID, (char *)&peer->refid,
- 4);
- else
- peer->refid = htonl(GPSHSREFID);
- }
- }
- }
-
- if (out != 0) {
- out->type = REFCLK_GPS_TRAK;
- out->haveflags
- = CLK_HAVETIME1|CLK_HAVEVAL1|CLK_HAVEVAL2;
- out->clockdesc = GPSDESCRIPTION;
- out->fudgetime1 = fudgefactor[unit];
- out->fudgetime2.l_ui = 0;
- out->fudgetime2.l_uf = 0;
- out->fudgeval1 = (LONG)stratumtouse[unit];
- out->fudgeval2 = 0;
- out->flags = sloppyclockflag[unit];
- if (unitinuse[unit]) {
- gps = gpsunits[unit];
- out->lencode = gps->lencode; /* LENTOC */;
- out->lastcode = gps->lastcode;
- out->timereset = current_time - gps->timestarted;
- out->polls = gps->polls;
- out->noresponse = gps->noreply;
- out->badformat = gps->badformat;
- out->baddata = gps->baddata;
- out->lastevent = gps->lastevent;
- out->currentstatus = gps->status;
- } else {
- out->lencode = 0;
- out->lastcode = "";
- out->polls = out->noresponse = 0;
- out->badformat = out->baddata = 0;
- out->timereset = 0;
- out->currentstatus = out->lastevent = CEVNT_NOMINAL;
- }
- }
+ pp = peer->procptr;
+ up = (struct wwvbunit *)pp->unitptr;
+ if (up->pollcnt == 0)
+ refclock_report(peer, CEVNT_TIMEOUT);
+ else
+ up->pollcnt--;
+ up->tcswitch = 0;
+ pp->polls++;
}
-/*
- * trak_buginfo - return clock dependent debugging info
- */
-static void
-trak_buginfo(unit, bug)
- int unit;
- register struct refclockbug *bug;
-{
- register struct gpsunit *gps;
-
- if (unit >= MAXUNITS) {
- syslog(LOG_ERR, "trak_buginfo: unit %d invalid", unit);
- return;
- }
-
- if (!unitinuse[unit])
- return;
- gps = gpsunits[unit];
-
- bug->nvalues = 10;
- bug->ntimes = 5;
- if (gps->lasttime != 0)
- bug->values[0] = current_time - gps->lasttime;
- else
- bug->values[0] = 0;
- bug->values[1] = (U_LONG)gps->reason;
- bug->values[2] = (U_LONG)gps->year;
- bug->values[3] = (U_LONG)gps->day;
- bug->values[4] = (U_LONG)gps->hour;
- bug->values[5] = (U_LONG)gps->minute;
- bug->values[6] = (U_LONG)gps->second;
- bug->values[7] = (U_LONG)gps->msec;
- bug->values[8] = gps->noreply;
- bug->values[9] = gps->yearstart;
- bug->stimes = 0x1c;
- bug->times[0] = gps->lastref;
- bug->times[1] = gps->lastrec;
- bug->times[2] = gps->offset[0];
- bug->times[3] = gps->offset[1];
- bug->times[4] = gps->offset[2];
-}
#endif
diff --git a/usr.sbin/xntpd/xntpdc/ntpdc.c b/usr.sbin/xntpd/xntpdc/ntpdc.c
index 3113c9f..387540b 100644
--- a/usr.sbin/xntpd/xntpdc/ntpdc.c
+++ b/usr.sbin/xntpd/xntpdc/ntpdc.c
@@ -1,4 +1,4 @@
-/* ntpdc.c,v 3.1 1993/07/06 01:11:59 jbj Exp
+/*
* xntpdc - control and monitor your xntpd daemon
*/
#include <stdio.h>
@@ -26,7 +26,7 @@ static char * prompt = "xntpdc> "; /* prompt to ask him about */
/*
* Keyid used for authenticated requests. Obtained on the fly.
*/
-static U_LONG info_auth_keyid;
+static u_long info_auth_keyid;
/*
* Type of key md5 or des
@@ -51,7 +51,7 @@ static void docmd P((char *));
static void tokenize P((char *, char **, int *));
static int findcmd P((char *, struct xcmd *, struct xcmd *, struct xcmd **));
static int getarg P((char *, int, arg_v *));
-static int getnetnum P((char *, U_LONG *, char *));
+static int getnetnum P((char *, u_long *, char *));
static void help P((struct parse *, FILE *));
#if defined(sgi) || defined(SYS_BSDI) || defined(__STDC__)
static int helpsort P((const void *, const void *));
@@ -62,7 +62,6 @@ static void printusage P((struct xcmd *, FILE *));
static void timeout P((struct parse *, FILE *));
static void delay P((struct parse *, FILE *));
static void host P((struct parse *, FILE *));
-static void ntp_poll P((struct parse *, FILE *));
static void keyid P((struct parse *, FILE *));
static void keytype P((struct parse *, FILE *));
static void passwd P((struct parse *, FILE *));
@@ -72,17 +71,17 @@ static void quit P((struct parse *, FILE *));
static void version P((struct parse *, FILE *));
static void warning P((char *, char *, char *));
static void error P((char *, char *, char *));
-static U_LONG getkeyid P((char *));
+static u_long getkeyid P((char *));
/*
* Built-in commands we understand
*/
static struct xcmd builtins[] = {
- { "?", help, { OPT|STR, NO, NO, NO },
+ { "?", help, { OPT|NTP_STR, NO, NO, NO },
{ "command", "", "", "" },
"tell the use and syntax of commands" },
- { "help", help, { OPT|STR, NO, NO, NO },
+ { "help", help, { OPT|NTP_STR, NO, NO, NO },
{ "command", "", "", "" },
"tell the use and syntax of commands" },
{ "timeout", timeout, { OPT|UINT, NO, NO, NO },
@@ -91,19 +90,16 @@ static struct xcmd builtins[] = {
{ "delay", delay, { OPT|INT, NO, NO, NO },
{ "msec", "", "", "" },
"set the delay added to encryption time stamps" },
- { "host", host, { OPT|STR, NO, NO, NO },
+ { "host", host, { OPT|NTP_STR, NO, NO, NO },
{ "hostname", "", "", "" },
"specify the host whose NTP server we talk to" },
- { "poll", ntp_poll, { OPT|UINT, OPT|STR, NO, NO },
- { "n", "verbose", "", "" },
- "poll an NTP server in client mode `n' times" },
- { "passwd", passwd, { NO, NO, NO, NO },
+ { "passwd", passwd, { OPT|NTP_STR, NO, NO, NO },
{ "", "", "", "" },
"specify a password to use for authenticated requests"},
- { "hostnames", hostnames, { OPT|STR, NO, NO, NO },
+ { "hostnames", hostnames, { OPT|NTP_STR, NO, NO, NO },
{ "yes|no", "", "", "" },
"specify whether hostnames or net numbers are printed"},
- { "debug", setdebug, { OPT|STR, NO, NO, NO },
+ { "debug", setdebug, { OPT|NTP_STR, NO, NO, NO },
{ "no|more|less", "", "", "" },
"set/change debugging level" },
{ "quit", quit, { NO, NO, NO, NO },
@@ -112,7 +108,7 @@ static struct xcmd builtins[] = {
{ "keyid", keyid, { OPT|UINT, NO, NO, NO },
{ "key#", "", "", "" },
"set keyid to use for authenticated requests" },
- { "keytype", keytype, { STR, NO, NO, NO },
+ { "keytype", keytype, { NTP_STR, NO, NO, NO },
{ "key type (md5|des)", "", "", "" },
"set key type to use for authenticated requests (des|md5)" },
{ "version", version, { NO, NO, NO, NO },
@@ -130,7 +126,7 @@ static struct xcmd builtins[] = {
#define DEFSTIMEOUT (2) /* 2 second time out after first */
#define DEFDELAY 0x51EB852 /* 20 milliseconds, l_fp fraction */
#define DEFHOST "localhost" /* default host name */
-#define LENHOSTNAME 256 /* host name is 256 characters LONG */
+#define LENHOSTNAME 256 /* host name is 256 characters long */
#define MAXCMDS 100 /* maximum commands on cmd line */
#define MAXHOSTS 100 /* maximum hosts on cmd line */
#define MAXLINE 512 /* maximum line length */
@@ -313,7 +309,7 @@ static int
openhost(hname)
char *hname;
{
- U_LONG netnum;
+ u_long netnum;
char temphost[LENHOSTNAME];
if (server_entry == NULL) {
@@ -429,9 +425,9 @@ getresponse(implcode, reqcode, ritems, rsize, rdata)
/*
* This is pretty tricky. We may get between 1 and many packets
* back in response to the request. We peel the data out of
- * each packet and collect it in one LONG block. When the last
+ * each packet and collect it in one long block. When the last
* packet in the sequence is received we'll know how many we
- * should have had. Note we use one LONG time out, should reconsider.
+ * should have had. Note we use one long time out, should reconsider.
*/
*ritems = 0;
*rsize = 0;
@@ -702,7 +698,8 @@ sendrequest(implcode, reqcode, auth, qitems, qsize, qdata)
* doquery - send a request and process the response
*/
int
-doquery(implcode, reqcode, auth, qitems, qsize, qdata, ritems, rsize, rdata)
+doquery(implcode, reqcode, auth, qitems, qsize, qdata, ritems, rsize, rdata,
+ quiet_mask)
int implcode;
int reqcode;
int auth;
@@ -712,6 +709,7 @@ doquery(implcode, reqcode, auth, qitems, qsize, qdata, ritems, rsize, rdata)
int *ritems;
int *rsize;
char **rdata;
+ int quiet_mask;
{
int res;
char junk[512];
@@ -755,7 +753,8 @@ doquery(implcode, reqcode, auth, qitems, qsize, qdata, ritems, rsize, rdata)
*/
res = getresponse(implcode, reqcode, ritems, rsize, rdata);
- if (res > 0) {
+ /* log error message if not told to be quiet */
+ if ((res > 0) && (((1 << res) & quiet_mask) == 0)) {
switch(res) {
case INFO_ERR_IMPL:
(void) fprintf(stderr,
@@ -764,6 +763,7 @@ doquery(implcode, reqcode, auth, qitems, qsize, qdata, ritems, rsize, rdata)
case INFO_ERR_REQ:
(void) fprintf(stderr,
"***Server doesn't implement this request\n");
+ break;
case INFO_ERR_FMT:
(void) fprintf(stderr,
"***Server reports a format error in the received packet (shouldn't happen)\n");
@@ -1030,7 +1030,7 @@ getarg(str, code, argp)
static char *digits = "0123456789";
switch (code & ~OPT) {
- case STR:
+ case NTP_STR:
argp->string = str;
break;
case ADD:
@@ -1081,7 +1081,7 @@ getarg(str, code, argp)
static int
getnetnum(host, num, fullhost)
char *host;
- U_LONG *num;
+ u_long *num;
char *fullhost;
{
struct hostent *hp;
@@ -1089,13 +1089,13 @@ getnetnum(host, num, fullhost)
if (decodenetnum(host, num)) {
if (fullhost != 0) {
(void) sprintf(fullhost,
- "%d.%d.%d.%d", ((htonl(*num)>>24)&0xff),
- ((htonl(*num)>>16)&0xff), ((htonl(*num)>>8)&0xff),
- (htonl(*num)&0xff));
+ "%u.%u.%u.%u", (u_int)((htonl(*num)>>24)&0xff),
+ (u_int)((htonl(*num)>>16)&0xff), (u_int)((htonl(*num)>>8)&0xff),
+ (u_int)(htonl(*num)&0xff));
}
return 1;
} else if ((hp = gethostbyname(host)) != 0) {
- memmove((char *)num, hp->h_addr, sizeof(U_LONG));
+ memmove((char *)num, hp->h_addr, sizeof(u_long));
if (fullhost != 0)
(void) strcpy(fullhost, hp->h_name);
return 1;
@@ -1112,7 +1112,7 @@ getnetnum(host, num, fullhost)
*/
char *
nntohost(netnum)
- U_LONG netnum;
+ u_long netnum;
{
if (!showhostnames)
return numtoa(netnum);
@@ -1267,18 +1267,18 @@ delay(pcmd, fp)
FILE *fp;
{
int isneg;
- U_LONG val;
+ u_long val;
if (pcmd->nargs == 0) {
val = delay_time.l_ui * 1000 + delay_time.l_uf / 4294967;
- (void) fprintf(fp, "delay %d ms\n", val);
+ (void) fprintf(fp, "delay %lu ms\n", val);
} else {
if (pcmd->argval[0].ival < 0) {
isneg = 1;
- val = (U_LONG)(-pcmd->argval[0].ival);
+ val = (u_long)(-pcmd->argval[0].ival);
} else {
isneg = 0;
- val = (U_LONG)pcmd->argval[0].ival;
+ val = (u_long)pcmd->argval[0].ival;
}
delay_time.l_ui = val / 1000;
@@ -1317,19 +1317,6 @@ host(pcmd, fp)
/*
- * poll - do one (or more) polls of the host via NTP
- */
-/*ARGSUSED*/
-static void
-ntp_poll(pcmd, fp)
- struct parse *pcmd;
- FILE *fp;
-{
- (void) fprintf(fp, "poll not implemented yet\n");
-}
-
-
-/*
* keyid - get a keyid to use for authenticating requests
*/
static void
@@ -1341,7 +1328,7 @@ keyid(pcmd, fp)
if (info_auth_keyid == 0)
(void) fprintf(fp, "no keyid defined\n");
else
- (void) fprintf(fp, "keyid is %u\n", info_auth_keyid);
+ (void) fprintf(fp, "keyid is %lu\n", info_auth_keyid);
} else {
info_auth_keyid = pcmd->argval[0].uval;
}
@@ -1396,11 +1383,16 @@ passwd(pcmd, fp)
return;
}
}
- pass = getpass("Password: ");
- if (*pass == '\0')
- (void) fprintf(fp, "Password unchanged\n");
- else
- authusekey(info_auth_keyid, info_auth_keytype, pass);
+ if (!interactive) {
+ authusekey(info_auth_keyid, info_auth_keytype,
+ pcmd->argval[0].string);
+ } else {
+ pass = getpass("Password: ");
+ if (*pass == '\0')
+ (void) fprintf(fp, "Password unchanged\n");
+ else
+ authusekey(info_auth_keyid, info_auth_keytype, pass);
+ }
}
@@ -1515,7 +1507,7 @@ error(fmt, st1, st2)
/*
* getkeyid - prompt the user for a keyid to use
*/
-static U_LONG
+static u_long
getkeyid(prompt)
char *prompt;
{
@@ -1536,5 +1528,5 @@ char *prompt;
*p = '\0';
if (fi != stdin)
fclose(fi);
- return (U_LONG)atoi(pbuf);
+ return (u_long)atoi(pbuf);
}
OpenPOWER on IntegriCloud