3 * refclock_local - local pseudo-clock driver
5 * wjm 17-aug-1995: add a hook for special treatment of VMS_LOCALUNIT
14 #include "ntp_refclock.h"
15 #include "ntp_stdlib.h"
21 #include "ntp_syscall.h"
25 * This is a hack to allow a machine to use its own system clock as a
26 * reference clock, i.e., to free-run using no outside clock discipline
27 * source. Note that the clock selection algorithm will not select this
28 * driver unless all other sources of synchronization have been lost.
29 * This is useful if you want to use NTP in an isolated environment
30 * with no radio clock or NIST modem available. Pick a machine that you
31 * figure has a good clock oscillator and configure it with this
32 * driver. Set the clock using the best means available, like
33 * eyeball-and-wristwatch. Then, point all the other machines at this
34 * one or use broadcast (not multicast) mode to distribute time.
36 * Another application for this driver is if you want to use a
37 * particular server's clock as the clock of last resort when all other
38 * normal synchronization sources have gone away. This is especially
39 * useful if that server has an ovenized oscillator. However, the
40 * preferred was to do this is using orphan mode. See the documentation.
42 * A third application for this driver is when an external discipline
43 * source is available, such as the NIST "lockclock" program, which
44 * synchronizes the local clock via a telephone modem and the NIST
45 * Automated Computer Time Service (ACTS), or the Digital Time
46 * Synchronization Service (DTSS), which runs on DCE machines. In this
47 * case the stratum should be set at zero, indicating a bona fide
48 * stratum-1 source. Exercise some caution with this, since there is no
49 * easy way to telegraph via NTP that something might be wrong in the
50 * discipline source itself. In the case of DTSS, the local clock can
51 * have a rather large jitter, depending on the interval between
52 * corrections and the intrinsic frequency error of the clock
53 * oscillator. In extreme cases, this can cause clients to exceed the
54 * 128-ms slew window and drop off the NTP subnet.
58 * If fudge flag1 is lit, the leap second bit is set in the peer
59 * status word. It should be set early in the day of a leap second
60 * event and set dark on the day after the event.
62 * Note the fudge time1 and time2 have been deprecated. The fudge time1
63 * was intended to apply a bias offset. This can be done using the Unix
64 * date command. The fudge time2 was intended to apply a bias frequency.
65 * This can be done using the frequency file and/or the freq
66 * configuration command.
69 * Local interface definitions
71 #define PRECISION (-7) /* about 10 ms precision */
72 #define DESCRIPTION "Undisciplined local clock" /* WRU */
73 #define STRATUM 5 /* default stratum */
74 #define DISPERSION .01 /* default dispersion (10 ms) */
77 * Imported from the timer module
79 extern u_long current_time;
82 * Imported from ntp_proto
84 extern s_char sys_precision;
89 static int local_start (int, struct peer *);
90 static void local_poll (int, struct peer *);
95 static u_long poll_time; /* last time polled */
100 struct refclock refclock_local = {
101 local_start, /* start up driver */
102 noentry, /* shut down driver (not used) */
103 local_poll, /* transmit poll message */
104 noentry, /* not used (old lcl_control) */
105 noentry, /* initialize driver (not used) */
106 noentry, /* not used (old lcl_buginfo) */
107 NOFLAGS /* not used */
112 * local_start - start up the clock
120 struct refclockproc *pp;
125 * Initialize miscellaneous variables
127 peer->precision = sys_precision;
128 pp->leap = LEAP_NOTINSYNC;
129 peer->stratum = STRATUM;
130 pp->stratum = STRATUM;
131 pp->clockdesc = DESCRIPTION;
132 memcpy(&pp->refid, "LOCL", 4);
133 poll_time = current_time;
139 * local_poll - called by the transmit procedure
141 * LOCKCLOCK: If the kernel supports the nanokernel or microkernel
142 * system calls, the leap bits are extracted from the kernel. If there
143 * is a kernel error or the kernel leap bits are set to 11, the NTP leap
144 * bits are set to 11 and the stratum is set to infinity. Otherwise, the
145 * NTP leap bits are set to the kernel leap bits and the stratum is set
146 * as fudged. This behavior does not faithfully follow the
147 * specification, but is probably more appropriate in a multiple-server
148 * national laboratory network.
156 #if defined(KERNEL_PLL) && defined(LOCKCLOCK)
158 #endif /* KERNEL_PLL LOCKCLOCK */
159 struct refclockproc *pp;
162 * Do no evil unless the house is dark or lit with our own lamp.
164 if (!(sys_peer == NULL || sys_peer == peer))
167 #if defined(VMS) && defined(VMS_LOCALUNIT)
168 if (unit == VMS_LOCALUNIT) {
169 extern void vms_local_poll(struct peer *);
171 vms_local_poll(peer);
174 #endif /* VMS && VMS_LOCALUNIT */
180 * Ramble through the usual filtering and grooming code, which
181 * is essentially a no-op and included mostly for pretty
182 * billboards. We allow a one-time time adjustment using fudge
183 * time1 (s) and a continuous frequency adjustment using fudge
186 poll_time = current_time;
187 refclock_process_offset(pp, pp->lastrec, pp->lastrec, 0);
190 * If another process is disciplining the system clock, we set
191 * the leap bits and quality indicators from the kernel.
193 #if defined(KERNEL_PLL) && defined(LOCKCLOCK)
194 memset(&ntv, 0, sizeof ntv);
195 switch (ntp_adjtime(&ntv)) {
197 pp->leap = LEAP_NOWARNING;
198 peer->stratum = pp->stratum;
202 pp->leap = LEAP_ADDSECOND;
203 peer->stratum = pp->stratum;
207 pp->leap = LEAP_DELSECOND;
208 peer->stratum = pp->stratum;
212 pp->leap = LEAP_NOTINSYNC;
213 peer->stratum = STRATUM_UNSPEC;
217 #else /* KERNEL_PLL LOCKCLOCK */
218 if (pp->sloppyclockflag & CLK_FLAG1)
219 pp->leap = LEAP_ADDSECOND;
221 pp->leap = LEAP_NOWARNING;
222 pp->disp = DISPERSION;
224 #endif /* KERNEL_PLL LOCKCLOCK */
225 pp->lastref = pp->lastrec;
226 refclock_receive(peer);
229 int refclock_local_bs;
230 #endif /* REFCLOCK */