home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1995 April / Internet Tools.iso / applic / ntp / depredated / xntp2 / notes.me.Z / notes.me
Encoding:
Text File  |  1991-09-29  |  43.8 KB  |  1,100 lines

  1. .if t .po 1.4i
  2. .if t .ll 5.8i
  3. .if n .po 0.5i
  4. .if n .ll 6.5i
  5. .nr sp 14
  6. .sz 14
  7. \&
  8. .na
  9. .if n .nr tf 1
  10. .he ''%''
  11. .ce 99
  12. \f3On the Care and Feeding of Xntpd\f1
  13. .ce 0
  14. .if t .sp 0.7v
  15. .if n .sp 1.0v
  16. .nr sp 12
  17. .sz 12
  18. .ce 99
  19. Dennis Ferguson
  20. \f2University of Toronto\f1
  21. .ce 0
  22. .nr sp 10
  23. .sz 10
  24. .sp 1.5v
  25. .uh "Introduction"
  26. .pp
  27. This is a collection of notes concerning the use of
  28. .i xntpd
  29. and related programs, and on dealing successfully with the
  30. Network Time Protocol in general.  Be careful to note that
  31. what follows is in no way canonical nor authoritative, but
  32. rather has a relatively high content of opinion and conjecture
  33. derived from an understanding of the protocol and some (often
  34. bad) experience with it.  I might change my mind tomorrow, and
  35. would be happy to have my mind changed for me by popular dissent.
  36. .pp
  37. This is the advertising section.
  38. .i Xntpd
  39. is a complete implementation of the NTP Version 2 specification,
  40. as defined in RFC 1119.  It also retains compatability with NTP
  41. Version 1, as defined in RFC 1059, though this compatability is
  42. sometimes only semiautomatic.
  43. .i Xntpd
  44. does no floating point arithmetic, and manipulates the 64 bit NTP
  45. timestamps as 64 bit integers where appropriate.
  46. .i Xntpd
  47. fully implements NTP Version 2 authentication and NTP mode 6 control
  48. messages.  A complete, flexible address\-and\-mask restriction
  49. facility has been included.  The server is fully reconfigurable at
  50. run time via NTP
  51. private mode 7 messages, and exposes a considerable amount of internal
  52. detail via that mechanism as well.  The latter function allows
  53. .i xntpd
  54. to be extensively debugged via protocol messages, something which makes
  55. it an advantageous porting base to construct servers intended to run
  56. on minimal platforms.
  57. .pp
  58. The code is biased
  59. towards the needs of a busy primary server.  Tables are hashed to
  60. allow efficient handling of a large number of pollers, though at
  61. the expense of additional overhead when the number of pollers is
  62. small.  Many fancy features have been included to permit efficient
  63. management and monitoring of a busy primary server, features which
  64. are simply excess baggage for a server on a high stratum client.  The
  65. code was written with near neurotic attention to details which can affect
  66. precision, and as a consequence should be able to make good use of
  67. high performance special purpose hardware (unfortunately, the
  68. latter does not really include Unix machines).
  69. .i Xntpd
  70. was designed with radio clock support in mind, and can provide support
  71. for even the most perverse, inconvenient radio clock designs without
  72. seriously impacting, or requiring consideration for, the performance of other
  73. parts of the server.  The server has methodically avoided the use of
  74. Unix-specific library routines where ever possible by implementing local
  75. versions, this to aid in porting the code to non-Unix platforms.
  76. .pp
  77. There are, however, several drawbacks to all of this.
  78. .i Xntpd
  79. is very, very fat.  The number lines of C code which
  80. .i xntpd
  81. is made from exceeds the number of lines of PDP\-11 assembler in
  82. the fuzzball NTP server by a factor of 10 or so.  This is rotten if your
  83. intended platform for the daemon is memory\-limited.
  84. .i Xntpd
  85. uses SIGIO for all input, a facility which appears to not have universal
  86. support and whose use seems to exercise the parts of your vendors' kernels
  87. which are most likely to have been done poorly.  The code is unforgiving
  88. in the face of kernel problems which affect performance, and generally
  89. requires that you repair the problems in the kernel.  The code has
  90. a distinctly experimental flavour and contains features which could
  91. charitably be termed failed experiments, but which the author has not
  92. gotten around to backing out of yet.  There is code which has not been
  93. exercised (e.g. leap second support) due to the inconvenience of setting
  94. up tests.  Much was learned from the addition of support for a variety
  95. of clock devices, with the result that this support could use some
  96. rewriting.
  97. .i Xntpd
  98. is far from being a finished product, and may never be.
  99. .pp
  100. If this hasn't scared you away, read on.
  101. .uh "How NTP Works"
  102. .pp
  103. The approach used by NTP to achieve time synchronization among a
  104. group of clocks is somewhat
  105. different than other such protocols.  In particular, NTP
  106. does not attempt to synchronize clocks to each other.  Rather, each
  107. server attempts to synchronize to UTC (i.e. standard time) using
  108. the best available source.  This is a fine point which is worth
  109. understanding.  A group of NTP\-synchronized clocks may be close
  110. to each other in time, but this is not a consequence of the clocks
  111. in the group having synchronized to each other, but rather because
  112. each clock has synchronized closely to UTC via the best source it
  113. has access to.  As such, trying to
  114. synchronize a group of clocks to a set of servers whose time is
  115. not in mutual agreement may not result in any sort of useful
  116. synchronization of the clocks, even if you don't care about UTC.  NTP
  117. operates on the premise that there is one true standard time, and that if
  118. several servers which claim synchronization to standard time disagree
  119. about what that time is then one or more of them must be broken.  There
  120. is no attempt to resolve differences more gracefully since the premise
  121. is that substantial differences cannot exist.  In
  122. essence, NTP expects that the time being distributed from the top
  123. of the synchronization subnet will be derived from some external source
  124. of UTC (e.g. a radio clock).  This makes it somewhat
  125. inconvenient (though not impossible) to
  126. synchronize hosts together without a reliable source of UTC to
  127. synchronize them to.  If your network is isolated and you cannot
  128. access other people's servers across the Internet, a radio clock
  129. may make a good investment.
  130. .pp
  131. Time is distributed through a heirarchy of NTP servers, with each
  132. server adopting a
  133. .i stratum
  134. which indicates how far away from an external source of UTC it is
  135. operating at.  Stratum 1 servers, which are at the top of the
  136. pile (or bottom, depending on your point of view), have access to
  137. some external time source, usually a radio clock synchronized to
  138. time signal broadcasts from radio stations which explicitly provide
  139. a standard time service.  A stratum 2 server is one which
  140. is currently obtaining time from a stratum 1 server, a stratum 3
  141. server gets its time from a stratum 2 server, and so on.  To avoid
  142. long lived synchronization loops the number of strata is limited to
  143. 15.
  144. .pp
  145. Each client in the synchronization subnet (which may also be a server
  146. for other, higher stratum clients) chooses exactly one
  147. of the available servers to synchronize to, usually from among the
  148. lowest stratum servers it has access to.  It is thus possible to
  149. construct a synchronization subnet where each server has exactly
  150. one source of lower stratum time to synchronize to.  This is, however,
  151. not an optimal configuration, for indeed NTP operates under another
  152. premise as well, that each server's time should be viewed with a certain
  153. amount of distrust.  NTP really prefers to have access to several
  154. sources of lower stratum time (at least three) since it can then
  155. apply an agreement algorithm to detect insanity on the part of any
  156. one of these.  Normally, when all servers are in agreement, NTP will
  157. choose the best of these, where \*(lqbest\*(rq is defined in terms
  158. of lowest stratum, closest (in terms of network delay) and claimed
  159. precision, along with several other considerations.  The implication
  160. is that, while one should aim to provide each client with three or
  161. more sources of lower stratum time, several of these will only be
  162. providing backup service and may be of lesser quality in terms of
  163. network delay and stratum (i.e. a same stratum peer which receives
  164. time from lower stratum sources the local server doesn't acess
  165. directly can also provide good backup service).
  166. .pp
  167. Finally, there is the issue of association modes.  There are a
  168. number of \*(lqmodes\*(rq in which
  169. NTP servers can associate with each other, with the mode of
  170. each server in the pair indicating the behaviour the other server can
  171. expect from it.  In particular, when configuring a server to obtain
  172. time from other servers, there is a choice of two modes which may be
  173. alternatively used.  Configuring an association in
  174. .i "symmetric active"
  175. mode (usually indicated by a
  176. .i peer
  177. declaration in configuration files) indicates to the remote server that
  178. one wishes to obtain time from the remote server and that
  179. one is also willing to supply
  180. time to the remote server if need be.  Configurating an association
  181. in
  182. .i client
  183. mode (usually indicated by a
  184. .i server
  185. declaration in configuration files) indicates the one wishes to obtain
  186. time from the remote server, but that one is
  187. .b not
  188. willing to provide time to the remote.  It is the author's opinion
  189. that symmetric active mode should be used for configuring all peer
  190. associations
  191. between NTP daemons (or stateful NTP entities).  Client mode is for
  192. use by boot time date-setting programs and the like, which really
  193. have no time to provide and which don't retain state about associations
  194. over the longer term.
  195. .uh "Configuring Xntpd"
  196. .pp
  197. At start up time
  198. .i xntpd
  199. reads its initial configuration from a file, usually
  200. .i /etc/ntp.conf
  201. unless you have compiled in a different name.  Putting something
  202. in this file which will enable the server to obtain time from
  203. somewhere is usually the first big hurdle after installation of
  204. the software.  At its simplest (this is usually where you should
  205. start), what you need to do in the configuration file is mention
  206. the servers that the daemon should poll for time with
  207. .i peer
  208. declarations.  To jump right into this, a working
  209. configuration file might look like
  210. (\f3do not copy this directly\fP):
  211. .(l
  212. #
  213. # Peer configuration for 128.100.100.7
  214. # (expected to operate at stratum 2)
  215. #
  216.  
  217. peer 128.100.49.105    # suzuki.ccie.utoronto.ca
  218. peer 128.8.10.1        # umd1.umd.edu
  219. peer 192.35.82.50    # lilben.tn.cornell.edu
  220.  
  221. driftfile /etc/ntp.drift
  222. .)l
  223. .pp
  224. This particular host is expected to operate at stratum 2 by virtue
  225. of the fact that two of the three servers declared (the first two,
  226. actually) have radio clocks and typically run at stratum 1.  The
  227. third server in the list has no radio clock, but is known to
  228. maintain associations with a number of stratum 1 peers and typically
  229. operates at stratum 2.  Of particular importance with the latter host
  230. is that it maintains associations with peers besides the two stratum
  231. 1 peers mentioned.
  232. .pp
  233. Note that I also threw in a
  234. .i driftfile
  235. declaration, since this entry should also appear in all
  236. configuration files.  One of the things the NTP daemon does
  237. when it is first started is to compute the error in the speed of
  238. the clock on the computer it is running on.  It usually takes about a
  239. day or so after the daemon is started to compute a good estimate
  240. of this (and it needs a good estimate to synchronize closely to
  241. its server).  Once the initial value is computed it will change
  242. only by relatively small amounts during the course of continued
  243. operation.  The
  244. .i driftfile
  245. entry indicates to the daemon the name of a file where it may
  246. store the current value of the frequency error (or clock drift) so
  247. that, if the daemon is stopped and restarted, it can reinitialize
  248. itself to the previous estimate and avoid the day's worth of
  249. time it will take to resynchronize.  Since this is a desireable feature, a
  250. .i driftfile
  251. declaration should always be included in the configuration file.
  252. .pp
  253. Returning to peer selection, the canonical source of information
  254. concerning the location of stratum 1 and good quality stratum 2
  255. servers is the file
  256. .i pub/ntp/clock.txt
  257. available via anonymous ftp from louie.udel.edu.  If you are setting
  258. up a single NTP host for testing you might obtain this file and locate
  259. three servers to obtain time from.  Ideally one would pick two primary
  260. servers (i.e. stratum 1) and one secondary (stratum 2) from that
  261. list to use.  It
  262. is also better to chose servers which are likely to be
  263. \*(lqclose\*(rq to you in terms of network topology, though you
  264. shouldn't worry overly about this if you are unable to determine
  265. who is close and who isn't.
  266. .pp
  267. Hopefully, however, your intention is to synchronize a larger number
  268. of hosts via NTP.  In this case you will want to synchronize a few
  269. of your hosts to more distant primary servers, and then synchronize
  270. (some of) the rest of your hosts to these.  A good way to do this is
  271. the following scheme:
  272. .ip (1)
  273. Choose three of your local hosts to operate as stratum 2 servers.  Then
  274. choose six stratum 1 servers and configure each of your stratum 2 servers
  275. with a pair of these.  Try to ensure that each stratum 2 server has at
  276. least one \*(lqclose\*(rq stratum 1 peer, if you can.  In addition,
  277. peer each of the stratum 2 servers to the other two (i.e. each configuration
  278. will list four peers, two remote and two local).
  279. .ip (2)
  280. From the remaining hosts, choose those you would like to operate at
  281. stratum 3.  This might be all of the rest if you're are only concerned
  282. with a dozen or two hosts in total, or might be things like file servers
  283. and machines with good clocks if you have many hosts to synchronize.  Provide
  284. each stratum 3 server with an identical configuration file pointing
  285. at the three stratum 2 hosts.
  286. .ip (3)
  287. Synchronize anything which remains (which will operate at stratum 4) to
  288. three or four nearby stratum 3 servers.
  289. .pp
  290. The above arrangement should provide very good, robust time service
  291. with a minimum of traffic to distant servers and with manageable
  292. loads on all local servers.  While it is theoretically possible
  293. to extend the synchronization subnet to even higher strata, this
  294. is seldom justified and can make the maintenance of configuration
  295. files unmanageable.  Serving time to a higher stratum peer is
  296. very inexpensive in terms of load on the lower stratum server
  297. if the latter is located on the same concatenated LAN.  When planning
  298. your network you might, beyond this, keep in mind a couple of generic
  299. \*(lqdon'ts\*(rq, in particular:
  300. .ip (1)
  301. Don't synchronize a server to a same stratum peer unless the latter
  302. is receiving time from lower stratum sources the former doesn't talk
  303. to directly, and
  304. .ip (2)
  305. Don't configure peer associations with higher stratum servers.  Let the
  306. higher strata configure lower stratum servers, but not the inverse.
  307. .lp
  308. There are many useful exceptions to these rules.  When in doubt, however,
  309. follow them.
  310. .pp
  311. Note that mention was made of machines with \*(lqgood\*(rq clocks
  312. versus machines with \*(lqbad\*(rq ones.  There are two things that
  313. make a clock \*(lqgood\*(rq, the precision of the clock (e.g. how many
  314. low order bits in a struct timeval are actually significant) and
  315. the frequency of occurance (or lack thereof) of such things as
  316. lost clock interrupts.  Among the most common computers
  317. I have observed there to be a fairly simple algorithm for determining
  318. the goodness of its clock.  If the machine is a Vax it probably has
  319. a good clock (the low order bit in the time is in the microseconds
  320. and most of these seem to manage to get along without losing clock
  321. interrupts).  If the machine is a Sun it probably doesn't (the low order
  322. clock bit is at the 10 or 20 millisecond mark and Suns like to lose
  323. clock interrupts, particularly if they have a screen and particularly
  324. if they run SunOS 4.0.x).  If you have IBM RTs running AOS 4.3, they
  325. have fair clocks (low order clock bit at about a millisecond and
  326. they don't lose clock interrupts, though they do have trouble with
  327. clock rollovers while reading the low order clock bits) but I recommend
  328. them as low stratum NTP servers anyway since
  329. they aren't much use as anything else.  For
  330. other machines you are on your own since I don't have enough data points
  331. to venture an opinion.  In any event, if at all possible you should try
  332. to use machines with \*(lqgood\*(rq clocks for the lower strata.
  333. .pp
  334. A final item worth considering is what to do if you buy a radio clock.  An
  335. effective way to deal with this is to not change the configuration above
  336. at all, but simply turn one of the stratum 2 servers into a stratum 1
  337. by attaching the radio clock.  Note that the remainder of your synchronization
  338. subnet will be promoted one stratum when you do this, but the remaining
  339. servers maintaining distant associations will continue to provide good
  340. backup service should the radio fail.  Don't depend solely on your
  341. radio clock equipped time server unless circumstances demand it.
  342. .uh "Xntpd versus Ntpd"
  343. .pp
  344. There are several items of note when dealing with a mixture of
  345. .i xntpd
  346. and
  347. .i ntpd
  348. servers.
  349. .i Xntpd
  350. is an NTP Version 2 implementation.  As such, by default when no
  351. additional information is available concerning the preferences of
  352. the peer,
  353. .i xntpd
  354. claims to be Version 2 in the packets that it
  355. sends.
  356. .pp
  357. .i Ntpd ,
  358. while implementing most of the Version 2 algorithms, still believes
  359. itself to be a Version 1 implementation.  The sticky part here is
  360. that when
  361. .i ntpd
  362. receives a packet claiming to be from a Version 2 server, it throws
  363. it away early in the input section.  Hence there is a danger that
  364. in some situations
  365. .i ntpd
  366. will ignore packets from
  367. .i xntpd .
  368. .pp
  369. .i Xntpd
  370. is aware of this problem.  In particular, when
  371. .i xntpd
  372. is polled by a host claiming to be a Version 1 implementation,
  373. .i xntpd
  374. claims to be a Version 1 implementation in the packets returned
  375. to the poller.  This allows
  376. .i xntpd
  377. to serve
  378. .i ntpd
  379. clients transparently.  The trouble occurs when an
  380. .i ntpd
  381. server is configured in an
  382. .i xntpd
  383. configuration file.  With no further indication,
  384. .i xntpd
  385. will send packets claiming to be Version 2 when it polls, and these
  386. will be ignored by
  387. .i ntpd .
  388. .pp
  389. To get around this,
  390. .i xntpd
  391. allows a qualifier to be added to configuration entries to indicate
  392. which version to use when polling.  Hence the entry
  393. .(l
  394. peer 130.43.2.2 version 1    # apple.com (running ntpd)
  395. .)l
  396. .lp
  397. will cause Version 1 packets to be sent to the host address 130.43.2.2.
  398. If you are testing
  399. .i xntpd
  400. against existing
  401. .i ntpd
  402. servers you will need to be careful about this.
  403. .pp
  404. There are a few other items to watch when converting an
  405. .i ntpd
  406. configuration file for use with
  407. .i xntpd .
  408. The first is to remove the
  409. .i precision
  410. entry from the configuration file, if there is one.  There was a time
  411. when the precision claimed by a server was mostly commentary, with no
  412. particularly useful purpose.  This
  413. is no longer the case, however, and so changing the precision a server claims
  414. should only be done with some consideration as to how this alters the
  415. performance of the server.  The default precision claimed by
  416. .i xntpd
  417. will be right for most situations.  A section later on will deal with when
  418. and how it is appropriate to change a server's precision without doing
  419. things you don't intend.
  420. .pp
  421. Second, note that in the example configuration file above numeric
  422. addresses are used in the peer declarations.  It is also possible to
  423. use names requiring resolution instead, but only if some additional
  424. configuration is done
  425. .i (xntpd
  426. doesn't include the resolver routines itself, and requires that a
  427. second program be used to do name resolution).  If you find numeric addresses
  428. offensive, see below.
  429. .pp
  430. Finally,
  431. .i passive
  432. and
  433. .i client
  434. entries in an
  435. .i ntpd
  436. configuration file have no useful semantics for
  437. .i xntpd
  438. and should be deleted.
  439. .i Xntpd
  440. won't reset the kernel variable
  441. .i tickadj
  442. when it starts, so you can remove anything dealing with this in the
  443. configuration file.  The configuration of radio clock peers
  444. is done using different configuration language in
  445. .i xntpd
  446. configuration files, so you will need to delete these entries from
  447. your
  448. .i ntpd
  449. configuration file and see below for the equivalent language.
  450. .uh "Traffic Monitoring"
  451. .pp
  452. .i Xntpd
  453. handles peers whose stratum is higher than the stratum of the
  454. local server and pollers using client mode by a fast path which
  455. minimizes the work done in responding to their polls, and normally
  456. retains no memory of these pollers.  Sometimes, however, it is
  457. interesting to be able to determine who is polling the server, and
  458. how often, as well as who has been sending other types of
  459. queries to the server.
  460. .pp
  461. To allow this,
  462. .i xntpd
  463. implements a traffic monitoring facility which records the source
  464. address and a minimal amount of other information from each packet
  465. which is received by the server.  This can be enabled by adding the
  466. following line to the server's configuration file:
  467. .(l
  468. monitor yes
  469. .)l
  470. The recorded information can be displayed using the
  471. .i xntpdc
  472. query program, described briefly below.
  473. .uh "Address\-and\-Mask Restrictions"
  474. .pp
  475. The address\-and\-mask configuration facility supported by
  476. .i xntpd
  477. is quite flexible and general.  The major drawback is that
  478. while the internal implementation is very nice, the user
  479. interface sucks.  For this reason it is probably worth doing
  480. an example here.
  481. .pp
  482. Briefly, the facility works as follows.  There is an internal
  483. list, each entry of which holds an address, a mask and a set
  484. of flags.  On receipt of a packet, the source address of the
  485. packet is compared to each entry in the list, with a match
  486. being posted when the following is true:
  487. .(l
  488. (source_addr & mask) == (address & mask)
  489. .)l
  490. A particular source address may match several list entries.  In
  491. this case the entry with the most one bits in the mask is chosen.  The
  492. flags associated with this entry are returned.
  493. .pp
  494. In the current implementation the flags always add restrictions.  In
  495. effect, an entry with no flags set leaves matching hosts unrestricted.  An
  496. entry can be added to the internal list using a
  497. .i restrict
  498. statement.  The flags associated with the entry are specified textually.
  499. For example, the
  500. .i notrust
  501. flag indicates that hosts matching this entry, while treated normally
  502. in other respects, shouldn't be trusted for synchronization.  The
  503. .i nomodify
  504. flag indicates that hosts matching this entry should not be allowed
  505. to do run time configuration.  There are many more flags, see the
  506. man page.
  507. .pp
  508. Now the example.  Suppose you are running the server on a host whose
  509. address is 128.100.100.7.  You would like to ensure that run time
  510. reconfiguration requests can only be made from the local host and that
  511. the server only ever synchronizes to one of a pair of off campus servers
  512. or, failing that, a time source on net 128.100.  The following entries
  513. in the configuration file would implement this policy:
  514. .(l
  515. # By default, don't trust and don't allow modifications
  516. restrict default notrust nomodify
  517.  
  518. # These guys are trusted for time, but no modifications allowed
  519. restrict 128.100.0.0 mask 255.255.0.0 nomodify
  520. restrict 128.8.10.1 nomodify
  521. restrict 192.35.82.50 nomodify
  522.  
  523. # The local addresses are unrestricted
  524. restrict 128.100.100.7
  525. restrict 127.0.0.1
  526. .)l
  527. .pp
  528. The first entry is the default entry, which all hosts match and hence
  529. which provides the default set of flags.  The next three entries
  530. indicate that matching hosts will only have the
  531. .i nomodify
  532. flag set and hence will be trusted for time.  If the mask
  533. isn't specified in the
  534. .i restrict
  535. statement it defaults to 255.255.255.255.  Note that the address
  536. 128.100.100.7 matches three entries in the table, the default
  537. entry (mask 0.0.0.0), the entry for net 128.100 (mask 255.255.0.0)
  538. and the entry for the host itself (mask 255.255.255.255).  As expected,
  539. the flags for the host are derived from the last entry since the mask
  540. has the most bits set.
  541. .pp
  542. The only other thing worth mentioning is that the restrict statements
  543. apply to packets from all hosts, including those that are configured
  544. elsewhere in the configuration file and even including your clock
  545. pseudopeer(s), in any.  Hence, if you specify a default set of restrictions
  546. which you don't wish to be applied to your configured peers, you must
  547. remove those restrictions for the configured peers with additional
  548. .i restrict
  549. statements mentioning each peer.
  550. .uh "Authentication"
  551. .pp
  552. .i Xntpd
  553. supports the optional authentication procedure specified in the NTP
  554. Version 2 specification.  Briefly, when an association runs in
  555. authenticated mode each packet transmitted has appended to it
  556. a 32\-bit key ID and a 64\-bit crypto checksum of the contents
  557. of the packet computed using the DES algorithm.  The receiving
  558. peer recomputes the checksum and compares it with the one included
  559. in the packet.  For this to work, the peers must share a DES encryption
  560. key and, further, must associate the shared key with the same key ID.
  561. .pp
  562. This facility requires some minor modifications to the basic packet
  563. processing procedures to actually implement the restrictions to be
  564. placed on unauthenticated associations.  These modifications
  565. are enabled by the
  566. .i authenticate
  567. configuration statement.  In particular, in authenticated mode peers which
  568. send unauthenticated packets, peers which send authenticated
  569. packets which the local server is unable to decrypt and peers which
  570. send authenticated packets encrypted using a key we don't trust are
  571. all marked untrustworthy and unsuitable for synchronization.  Note that
  572. while the server may know many keys (identified by many key IDs), it
  573. is possible to declare only a subset of these as trusted.  This allows
  574. the server to share keys with a client which requires authenticated time
  575. and which trusts the server but which is not trusted by the server.  Also,
  576. some additional configuration language is required to specify the key ID
  577. to be used to authenticate each configured peer association.  Hence, for
  578. a server running in authenticated mode, the configuration file might look
  579. similar to the following:
  580. .(l
  581. #
  582. # Peer configuration for 128.100.100.7
  583. # (expected to operate at stratum 2)
  584. # Fully authenticated this time.
  585. #
  586.  
  587. peer 128.100.49.105 key 22    # suzuki.ccie.utoronto.ca
  588. peer 128.8.10.1 key 4        # umd1.umd.edu
  589. peer 192.35.82.50 key 6        # lilben.tn.cornell.edu
  590.  
  591. authenticate yes
  592. trustedkey 4 6 22
  593. keys /etc/ntp.keys
  594. authdelay 0.000323
  595.  
  596. driftfile /etc/ntp.drift
  597. .)l
  598. .pp
  599. There are a couple of previously unmentioned things in here.  The
  600. .i authdelay
  601. statement is an estimate of the amount of processing
  602. time taken between the freezing
  603. of a transmit timestamp and the actual transmission of the packet when
  604. authentication is enabled (i.e. more or less the time it takes for the
  605. DES routine to encrypt a single block), and is used as a correction
  606. for the transmit timestamp.  This can be computed for your
  607. CPU by the
  608. .i authspeed
  609. program in the distribution's
  610. .i authstuff/
  611. directory.  The usage is similar to the following:
  612. .(l
  613. authspeed -n 30000 auth.samplekeys
  614. .)l
  615. .pp
  616. The
  617. .i keys
  618. statement, which declares the location of a file containing the
  619. list of keys and associated key IDs the server knows about (for
  620. obvious reasons this file is better left unreadable by anyone
  621. except the server).  The contents of this file might look like:
  622. .(l
  623. #
  624. # Keys 4, 6 and 22 are the actually identical
  625. #
  626. 4\0\0\0\0\0\0\0A\0\0\0DonTTelL
  627. 6\0\0\0\0\0\0\0S\0\0\089dfdca8a8cbd998
  628. 22\0\0\0\0\0\0N\0\0\0c4ef6e5454e5ec4c
  629.  
  630. #
  631. # The following 3 are also identical
  632. #
  633. 100\0\0\0\0\0A\0\0\0SeCReT
  634. 10000\0\0\0N\0\0\0d3e54352e5548080
  635. 1000000\0S\0\0\0a7cb86a4cba80101
  636. .)l
  637. .pp
  638. A DES encryption key is 56 bits long, and is written as an 8 octet
  639. number with 7 bits of the key in each octet.  The eighth bit in the
  640. octet is a parity bit and is set maintain odd parity in each octet.  In
  641. the keys file, the first token on each line indicates the key ID, the
  642. second token the format of the key and the third the key itself.  There
  643. are three key formats.  An
  644. .i A
  645. indicates that the key is a 1\-to\-8 character ASCII string
  646. and that the 7\-bit ASCII representation of each character should
  647. be used as an octet of the key (like a Unix password).  An
  648. .i S
  649. indicates that the key is written as a hex number in the DES
  650. standard format, with the low order bit of each octet being the parity
  651. bit.  An
  652. .i N
  653. indicates that the key is again a hex number, but that it is written
  654. in NTP standard format, with the high order bit of each octet
  655. being the parity bit (confusing enough?).  The daemon demands that,
  656. for the latter two formats, the parity bits be set correctly to
  657. maintain odd parity (there was a good reason for this which I have
  658. since forgotten...).  The key IDs are arbitrary, unsigned 32\-bit
  659. numbers.
  660. .pp
  661. The big trouble with the authentication facility is the keys file.  It is
  662. a maintenance headache and a security problem.  This should be fixed
  663. some day.
  664. .uh "Query Programs"
  665. .pp
  666. Two separate query programs are included with the
  667. .i xntp
  668. distribution,
  669. .i ntpq
  670. and
  671. .i xntpdc .
  672. .i Ntpq
  673. is a rather nice program which sends queries and receives responses
  674. using NTP standard mode 6 control messages.  Since it uses the standard
  675. query protocol it may be used to query the fuzzball NTP servers as well
  676. as
  677. .i xntpd .
  678. .pp
  679. .i Xnptdc
  680. is a horrid program which uses NTP private mode 7 messages to make
  681. requests to the server.  The format and and contents of these messages
  682. are specific to
  683. .i xntpd .
  684. The program does allow inspection of a wide
  685. variety of internal counters and other state data, and hence does make
  686. a pretty good debugging tool even if it is frustrating to use.  The
  687. other thing of note about
  688. .i xntpdc
  689. is that it provides a user interface to the runtime reconfiguration
  690. facility.
  691. .pp
  692. Both of these programs are nonessential.  The sole reason for this section
  693. is to point out an inconsistancy which can be awfully annoying if it
  694. catches you, and which is worth keeping firmly in mind.  Both
  695. .i xntpdc
  696. and
  697. .i xntpd
  698. demand that anything which has dimensions of time be specified in units
  699. of seconds, both in the configuration file and when doing runtime
  700. reconfiguration.  Both programs also print the values in seconds.
  701. .i Ntpq ,
  702. on the other hand, obeys the standard by printing all time values in
  703. milliseconds.  This makes the process of looking at values with
  704. .i ntpq
  705. and then changing them in the configuration file or with
  706. .i xntpdc
  707. very prone to errors (by three orders of magnitude).  I wish this
  708. problem didn't exist, but
  709. .i xntpd
  710. and its love of seconds predate the mode 6 protocol and the latter's
  711. (fuzzball\-derived) millisecond orientation, making the
  712. inconsistancy irresolvable without considerable work.
  713. .uh "Runtime Reconfiguration"
  714. .pp
  715. .i Xntpd
  716. was written specifically to allow its configuration to be fully modifiable
  717. at run time.  Indeed, the only way to configure the server is at run time.
  718. The configuration file is read only after the rest of the server has
  719. been initialized into a running, but default unconfigured, state.  This
  720. facility was included
  721. not so much for the benefit of Unix, where it is handy but
  722. not strictly essential, but rather for limited platforms
  723. where the feature is more important for maintenance.  Never\-the\-less,
  724. runtime configuration works very nicely for Unix servers as well.
  725. .pp
  726. Nearly all of the things it is possible to configure in the configuration
  727. file may be altered via NTP mode 7 messages using the
  728. .i xntpdc
  729. program.  Mode 6 messages may also provide some limited configuration
  730. functionality (though I think the only thing you can currently do
  731. with mode 6 messages is set the leap second warning bits) and the
  732. .i ntpq
  733. program provides generic support for the latter.
  734. .pp
  735. Mode 6 and mode 7 messages which would modify the configuration
  736. of the server are required to be authenticated using standard NTP
  737. authentication.  To enable the facilities one must, in addition
  738. to specifying the location of a keys file, indicate in the configuration
  739. file the key IDs to be used for authenticating reconfiguration requests.
  740. Hence the following fragment might be added to a configuration file
  741. to enable the mode 6
  742. .i (ntpq)
  743. and mode 7
  744. .i (xntpdc)
  745. facilities in the daemon:
  746. .(l
  747. keys /etc/ntp.keys
  748. requestkey 65535    # for mode 7 requests
  749. controlkey 65534    # for mode 6 requests
  750. .)l
  751. .lp
  752. If the
  753. .i requestkey
  754. and/or the
  755. .i controlkey
  756. configuration statements are omitted from the configuration file, the
  757. corresponding runtime reconfiguration facility is disabled.
  758. .pp
  759. The query programs require the user to specify a key ID and a key to
  760. use for authenticating requests to be sent.  The key ID provided
  761. should be the same as the one mentioned in the configuration file,
  762. while the key should match that corresponding to the key ID in
  763. the keys file.  As the query programs prompt for the key as a
  764. password, it is useful to make the request and control authentication
  765. keys typable (in ASCII format) from the keyboard.
  766. .uh "Name Resolution"
  767. .pp
  768. A recent addition to
  769. .i xntpd
  770. is the ability to specify host names requiring resolution in
  771. .i peer
  772. and
  773. .i server
  774. statements in the
  775. configuration file.  There are several reasons why this was not
  776. permitted in the past.  Chief among these is the fact that
  777. name service is unreliable and the interface to the Unix resolver
  778. routines is synchronous.  The hangs this combination can cause are
  779. unacceptable once the NTP server is running (and remember it is up
  780. and running before the configuration file is read).
  781. .pp
  782. Instead of running the resolver itself the daemon defers this task
  783. to a separate program,
  784. .i xntpres .
  785. When the daemon comes across a
  786. .i peer
  787. or
  788. .i server
  789. entry with a non\-numeric host address it records the relevant information
  790. in a temporary file and continues on.  When the end of the configuration
  791. file has been reached and one or more entries requiring the resolver have
  792. been found the server runs an instance of
  793. .i xntpres
  794. with the temporary file as an argument.  The server then continues on
  795. normally but with the offending peers/servers omitted from its configuration.
  796. .pp
  797. What
  798. .i xntpres
  799. does attempt to resolve each name.  When it successfully gets one it
  800. configures the peer entry into the server using the same mode 7 runtime
  801. reconfiguration facility that
  802. .i xntpdc
  803. uses.
  804. If temporary resolver failures occur,
  805. .i xntpres
  806. will periodically retry the offending requests until a definite response
  807. is received.  The program will continue to run until all entries have
  808. been resolved.
  809. .pp
  810. There are several configuration requirements if
  811. .i xntpres
  812. is to be used.  The path to the
  813. .i xntpres
  814. program must be made known to the daemon via a
  815. .i resolver
  816. configuration entry, and mode 7 runtime reconfiguration must be enabled.  The
  817. following fragment might be used to accomplish this:
  818. .(l
  819. resolver /local/etc/xntpres
  820. keys /etc/ntp.keys
  821. requestkey 65535
  822. .)l
  823. Note that
  824. .i xntpres
  825. sends packets to the server with a source address of 127.0.0.1.  You
  826. should obviously avoid \f2restrict\fPing modification requests from
  827. this address or
  828. .i xntpres
  829. will fail.
  830. .uh "Tickadj and Friends"
  831. .pp
  832. .i Xntpd
  833. understands intimately the peculiarities of the kernel implementation
  834. of the \f2adjtime\fP(2) system call as it is done on most machines.  Two
  835. variables are of interest, these being
  836. .i tick
  837. and
  838. .i tickadj.
  839. .pp
  840. The variable
  841. .i tick
  842. is expected to be the number of microseconds added to the system
  843. time on each clock interrupt.  The variable
  844. .i tickadj
  845. is used by the time adjustment code as a slew rate.  When the time is
  846. being slewed via a call to
  847. .i adjtime()
  848. the kernel essentially increases or reduces
  849. .i tick
  850. by
  851. .i tickadj
  852. microseconds until the specified slew has been done.  Unfortunately,
  853. the Berkeley code will vary the clock increment by exactly
  854. .i tickadj
  855. microseconds only, meaning that adjustments are truncated to be an integral
  856. multiple of
  857. .i tickadj
  858. (this latter behaviour is a misfeature, and is the only reason the
  859. code needs to concern itself with the internal implementation of
  860. \f2adjtime\f1 at all).  Thus, to make very sure it avoids problems
  861. related to the roundoff, the daemon on startup reads the values of
  862. .i tick
  863. and
  864. .i tickadj
  865. from
  866. .i /dev/kmem
  867. when it starts.  It then ensures that all adjustments given to
  868. .i adjtime()
  869. are an even multiple of
  870. .i tickadj
  871. microseconds, and computes the biggest adjustment that can be made in
  872. the 4 second adjustment interval (using both the value of
  873. .i tickadj
  874. and the value of
  875. .i tick )
  876. so it can avoid exceeding this limit if possible.
  877. .pp
  878. Unfortunately, the value of
  879. .i tickadj
  880. set by default is almost always too large for
  881. .i xntpd .
  882. NTP operates by continuously making small adjustments to the clock.  If
  883. .i tickadj
  884. is set too large the adjustments will disappear in the roundoff, while
  885. if
  886. .i tickadj
  887. is too small, NTP will have difficulty if it needs to make an occasional
  888. large adjustment.  While the daemon itself will read the kernel's value
  889. of
  890. .i tickadj
  891. it will not change the value even if it is unsuitable.  You must do
  892. this yourself before the daemon is started, either with
  893. .i adb
  894. or, in the running kernel only, with the
  895. .i tickadj
  896. program in the
  897. .i xntp
  898. distribution's
  899. .i util/
  900. directory.  Note that the latter program will also compute an optimal
  901. value of
  902. .i tickadj
  903. for NTP use based on the kernel's value of
  904. .i tick.
  905. .pp
  906. The
  907. .i tickadj
  908. program will also reset several other kernel variables if asked.  It
  909. will change the value
  910. of
  911. .i tick
  912. if you wish, this being necessary on a few machines with very broken
  913. clocks.  It will also set the value of the
  914. .i dosynctodr
  915. variable to zero if it exists and if you want.  This kernel variable
  916. tells some Suns to attempt synchronize the system clock to the time of day
  917. clock, something you really don't want to be happen when
  918. .i xntpd
  919. is trying to keep it under control.
  920. .pp
  921. All this stuff about diddling kernel variables so the NTP daemon
  922. will work is really silly.  If vendors would ship machines with
  923. clocks that kept reasonable time and would make their
  924. .i adjtime()
  925. system call apply the slew it is given exactly, independent of the
  926. value of
  927. .i tickadj,
  928. all this could go away.
  929. .uh "Tuning Your Subnet"
  930. .pp
  931. There are several parameters available for tuning your server.  These
  932. are set using the
  933. .i precision
  934. and
  935. .i maxskew
  936. configuration statements.  A fragment which would simply reset these
  937. to their default values (i.e. do nothing useful) follows:
  938. .(l
  939. precision -6
  940. maxskew 0.01
  941. .)l
  942. The
  943. .i precision
  944. statement sets the value of
  945. .i sys.precision
  946. while the
  947. .i maxskew
  948. statement sets the value of
  949. .i NTP.MAXSKW
  950. (both of these variables are defined in RFC 1119).
  951. .pp
  952. Sys.precision is defined in the NTP specification to be the base 2
  953. logarithm of the expected precision of the system clock.  It used
  954. to be set by reading the kernel's clock interrupt period and computing
  955. a value of sys.precision which gave a precision close to this, in
  956. essence making the value rather unpredictable.  This was unfortunate
  957. since, for NTP version 2, sys.precision acquired several quite
  958. important functions and is useful as a tuning parameter.  The current
  959. behaviour is to default this value to -6 in all servers.
  960. .pp
  961. The NTP protocol makes use of sys.precision in several places.  Sys.precison
  962. is included in packets sent to peers and is used by them as a sort of
  963. quality indicator.  When faced with selecting one of several servers of
  964. the same stratum and about the same network path delay for synchonization
  965. purposes, clients will tend to prefer to synchronize to those claiming
  966. the smallest (most negative) sys.precision.  The effect is particularly
  967. pronounced when all the servers are on the same LAN.  Hence, if you run
  968. several stratum 1 servers, or 3 or 4 stratum 2 servers, but you would
  969. like the client machines to prefer one of these over the other(s) for
  970. synchronization, you can achieve this effect by decreasing sys.precision
  971. on the preferred server and/or increasing this value on the others.
  972. .pp
  973. The other tuning parameter is the antihop aperture and is derived from
  974. sys.precision and NTP.MAXSKW using the following equation:
  975. .(l
  976. 2**sys.precision + NTP.MAXSKW
  977. .)l
  978. Making the antihop aperture larger will make the server less likely to
  979. hop from its current system peer (synchronization source) to another,
  980. while increasing the probability of the server remaining synchonized
  981. to a peer which has gone insane.  Making the antihop aperture smaller
  982. allows the server to hop more freely from peer to peer, but this can
  983. also cause it to generate a fair bit more NTP packet traffic than
  984. necessary for no good purpose.  Given the agreement among current
  985. stratum 1 NTP servers and the performance typical of the Internet, it
  986. is recommended that the antihop aperture be maintained with a value
  987. of between 0.020 and 0.030 (if you calculate the default value you will
  988. find it is about 0.026).  You can change the antihop
  989. aperture by
  990. changing the value of NTP.MAXSKW via a
  991. .i maxskew
  992. configuration statement.  Note, however, that if you wish to change
  993. sys.precision via a
  994. .i precision
  995. configuration statement, but
  996. .i don't
  997. wish to alter the antihop aperture, you must change NTP.MAXSKW to
  998. compensate.
  999. .pp
  1000. All this stuff is far too complicated.
  1001. .uh "Leap Second Support"
  1002. .pp
  1003. .i Xntpd
  1004. understands leap seconds and will attempt to take appropriate
  1005. action when one occurs.  In principle, within four seconds of the
  1006. insertion of a leap second, every host running
  1007. .i xntpd
  1008. will have had its clock stepped back one second to maintain time
  1009. synchronization with UTC.  Servers with active radio clocks will
  1010. also take any clock\-dependent action required to avoid being lead
  1011. astray by clocks which don't understand leap seconds.
  1012. .pp
  1013. Unfortunately, it has proved awfully hard to devise a test for this
  1014. feature.  Because of this, what
  1015. .i xntpd
  1016. will actually do when a leap second occurs is a good question.
  1017. .uh "Clock Support Overview"
  1018. .pp
  1019. .i Xntpd
  1020. was designed to support radio (and other external) clocks and does
  1021. some parts of this function nicely.  Clocks are treated
  1022. by the protocol as favoured NTP peers, even to the point of
  1023. referring to them with an (invalid) IP host address.  Clock
  1024. addresses are of the form 127.127.\f2t\fP.\f2u\fP, where
  1025. \f2t\fP specifies the particular type of clock (i.e. refers to
  1026. a particular clock driver) and \f2u\fP is
  1027. a \*(lqunit\*(rq number whose interpretation is clock driver
  1028. dependent.  This is analogous to the use of major and minor
  1029. device numbers by Unix.
  1030. .pp
  1031. Because clocks look much like peers, both configuration file
  1032. syntax and runtime reconfiguration commands can be be adopted
  1033. to control clocks unchanged.  Clocks are configured via
  1034. .i server
  1035. declarations in the configuration file
  1036. (\f2peer\fP declarations can also be used, but for hysterical reasons the
  1037. .i server
  1038. form is preferred), can be started and stopped using
  1039. .i xntpdc
  1040. and are subject to address\-and\-mask restrictions much like
  1041. a normal peer.  As a concession to the need to sometimes transmit
  1042. additional information to clock drivers, however, an additional
  1043. configuration file statement was added, the
  1044. .i fudge
  1045. statement.  This enables one to specify the values two time quantities,
  1046. two integral values and two flags, the use of which is dependent on
  1047. the particular clock driver the values are given to.  For example,
  1048. to configure a PST radio clock which can be accessed through the serial
  1049. device /dev/pst1, with propagation delays to WWV and WWVH of 7.5 and
  1050. 26.5 milliseconds, respectively, on a machine with an imprecise system
  1051. clock and with the driver set to disbelieve the radio clock once it
  1052. has gone 30 minutes without an update, one might use the following
  1053. configuration file entries:
  1054. .(l
  1055. server 127.127.3.1
  1056. fudge 127.127.3.1 time1 0.0075 time2 0.0265
  1057. fudge 127.127.3.1 value2 30 flag1 1
  1058. .)l
  1059. .pp
  1060. Unfortunately, all
  1061. .i xntpd
  1062. radio clock support currently expects to use the Berkeley terminal
  1063. driver.  Worse, while most drivers don't absolutely demand it, all
  1064. clock driver development to date has been done using the services of
  1065. a line discipline which takes receive timestamps in the kernel,
  1066. in the interrupt routine of the async hardware driver.  Worse still,
  1067. the algorithms used to process input data from the clocks assume
  1068. that the terminal driver will be well behaved.  This assumption
  1069. may require modifications to individual async hardware drivers
  1070. on some machines (Sun is bad for doing silly things with their
  1071. terminal drivers).  The reason for this is that the clock support
  1072. was designed to take advantage of the performance of a particular
  1073. dedicated hardware platform, and is somewhat less than forgiving
  1074. of the woes of lesser machines.  If you can provide a suitable
  1075. platform for
  1076. .i xntpd ,
  1077. however, the clock support is really very good.
  1078. .pp
  1079. There are several undocumented programs which are useful if
  1080. you are trying to set up a clock, to be found in the
  1081. .i clockstuff/
  1082. directory of the distribution.  The most useful of these is the
  1083. .i propdelay
  1084. program, which can compute high frequency radio propagation
  1085. delays between any two points whose latitude and longitude
  1086. are known.  The program understands something about the
  1087. phenomena which allow high frequency radio propagation to
  1088. occur, and will generally provide a better estimate than a
  1089. calculation based on the great circle distance.  The other
  1090. two programs in the directory are
  1091. .i clktest ,
  1092. which allows one to exercise the generic clock line discipline,
  1093. and
  1094. .i chutest ,
  1095. which runs the basic reduction algorithms used by the daemon on
  1096. data received from a serial port.
  1097. .pp
  1098. The authoritative source of information on particular clock drivers
  1099. is the \f2xntpd\fP(8) manual page.
  1100.