summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2011-07-07 21:01:00 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2011-07-07 21:01:00 +0000
commitaa8f00f72023e768d8aa6923f7678cd709a10702 (patch)
tree4fd25e0633b0f3e2a4cc5e307b4f8e524826a296 /usr.sbin
parentc3785e5755298479f2016257ae5995e5eff60df2 (diff)
timed's time is up. use ntpd(8). Even our own fossil developers
switched a while back. ok miod, kettenis
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/Makefile4
-rw-r--r--usr.sbin/ntpd/ntpd.85
-rw-r--r--usr.sbin/rdate/rdate.88
-rw-r--r--usr.sbin/timed/CHANGES146
-rw-r--r--usr.sbin/timed/Makefile5
-rw-r--r--usr.sbin/timed/SMM.doc/timed/Makefile18
-rw-r--r--usr.sbin/timed/SMM.doc/timed/date51
-rw-r--r--usr.sbin/timed/SMM.doc/timed/loop52
-rw-r--r--usr.sbin/timed/SMM.doc/timed/spell.ok34
-rw-r--r--usr.sbin/timed/SMM.doc/timed/time51
-rw-r--r--usr.sbin/timed/SMM.doc/timed/timed.ms469
-rw-r--r--usr.sbin/timed/SMM.doc/timed/unused51
-rw-r--r--usr.sbin/timed/SMM.doc/timedop/Makefile11
-rw-r--r--usr.sbin/timed/SMM.doc/timedop/timed.ms275
-rw-r--r--usr.sbin/timed/timed/Makefile15
-rw-r--r--usr.sbin/timed/timed/acksend.c118
-rw-r--r--usr.sbin/timed/timed/byteorder.c74
-rw-r--r--usr.sbin/timed/timed/candidate.c156
-rw-r--r--usr.sbin/timed/timed/cksum.c75
-rw-r--r--usr.sbin/timed/timed/correct.c177
-rw-r--r--usr.sbin/timed/timed/globals.h170
-rw-r--r--usr.sbin/timed/timed/master.c833
-rw-r--r--usr.sbin/timed/timed/measure.c314
-rw-r--r--usr.sbin/timed/timed/networkdelta.c250
-rw-r--r--usr.sbin/timed/timed/pathnames.h37
-rw-r--r--usr.sbin/timed/timed/readmsg.c496
-rw-r--r--usr.sbin/timed/timed/slave.c683
-rw-r--r--usr.sbin/timed/timed/timed-extern.h82
-rw-r--r--usr.sbin/timed/timed/timed.8281
-rw-r--r--usr.sbin/timed/timed/timed.c801
-rw-r--r--usr.sbin/timed/timedc/Makefile12
-rw-r--r--usr.sbin/timed/timedc/cmds.c564
-rw-r--r--usr.sbin/timed/timedc/cmdtab.c51
-rw-r--r--usr.sbin/timed/timedc/timedc-extern.h48
-rw-r--r--usr.sbin/timed/timedc/timedc.8142
-rw-r--r--usr.sbin/timed/timedc/timedc.c273
-rw-r--r--usr.sbin/timed/timedc/timedc.h63
37 files changed, 8 insertions, 6887 deletions
diff --git a/usr.sbin/Makefile b/usr.sbin/Makefile
index 22eba3b68f0..0b35c43e68c 100644
--- a/usr.sbin/Makefile
+++ b/usr.sbin/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.157 2011/06/09 22:59:08 oga Exp $
+# $OpenBSD: Makefile,v 1.158 2011/07/07 21:00:59 deraadt Exp $
.include <bsd.own.mk>
@@ -14,7 +14,7 @@ SUBDIR= ac accton acpidump adduser amd apm apmd arp \
rbootd rdate relayctl relayd repquota rip6query ripctl ripd \
rmt route6d rpc.bootparamd rpc.lockd rpc.statd rtadvd rtsold rwhod \
sa sasyncd sensorsd sliplogin slstats smtpd snmpctl snmpd spamdb \
- spray syslogc syslogd sysmerge tcpdrop tcpdump timed tokenadm \
+ spray syslogc syslogd sysmerge tcpdrop tcpdump tokenadm \
tokeninit traceroute traceroute6 trpt usbdevs user vipw watchdogd \
wsconscfg wsfontload wsmoused zdump zic ztsscale
diff --git a/usr.sbin/ntpd/ntpd.8 b/usr.sbin/ntpd/ntpd.8
index 27ad87b7bcb..0e06827e187 100644
--- a/usr.sbin/ntpd/ntpd.8
+++ b/usr.sbin/ntpd/ntpd.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: ntpd.8,v 1.27 2009/02/12 01:33:37 stevesk Exp $
+.\" $OpenBSD: ntpd.8,v 1.28 2011/07/07 21:00:59 deraadt Exp $
.\"
.\" Copyright (c) 2003, 2004, 2006 Henning Brauer <henning@openbsd.org>
.\"
@@ -14,7 +14,7 @@
.\" AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
.\" OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: February 12 2009 $
+.Dd $Mdocdate: July 7 2011 $
.Dt NTPD 8
.Os
.Sh NAME
@@ -137,7 +137,6 @@ Drift file.
.Xr rc 8 ,
.Xr rc.conf 8 ,
.Xr rdate 8 ,
-.Xr timed 8
.Rs
.%R RFC 1305
.%T "Network Time Protocol (Version 3)"
diff --git a/usr.sbin/rdate/rdate.8 b/usr.sbin/rdate/rdate.8
index 6669af689ba..21f340ceb23 100644
--- a/usr.sbin/rdate/rdate.8
+++ b/usr.sbin/rdate/rdate.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: rdate.8,v 1.30 2007/05/31 19:20:28 jmc Exp $
+.\" $OpenBSD: rdate.8,v 1.31 2011/07/07 21:00:59 deraadt Exp $
.\" $NetBSD: rdate.8,v 1.4 1996/04/08 20:55:17 jtc Exp $
.\"
.\" Copyright (c) 1994 Christos Zoulas
@@ -29,7 +29,7 @@
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd $Mdocdate: May 31 2007 $
+.Dd $Mdocdate: July 7 2011 $
.Dt RDATE 8
.Os
.Sh NAME
@@ -112,5 +112,5 @@ adjustment, put the following line into root's crontab:
.Xr date 1 ,
.Xr adjtime 2 ,
.Xr inetd 8 ,
-.Xr ntpd 8 ,
-.Xr timed 8
+.Xr ntpd 8
+
diff --git a/usr.sbin/timed/CHANGES b/usr.sbin/timed/CHANGES
deleted file mode 100644
index 4172af3741e..00000000000
--- a/usr.sbin/timed/CHANGES
+++ /dev/null
@@ -1,146 +0,0 @@
-# $OpenBSD: CHANGES,v 1.3 2002/06/03 12:04:08 deraadt Exp $
-#
-# @(#)CHANGES 5.1 (Berkeley) 5/11/93
-
-This new version is almost identical to the timed and timedc code
-that has been shipped for years by a workstation vendor.
-
-Among the many changes:
-
-improve `timedc msite` to accept a list of hostnames.
-
-change slave-masters to answer the packets generated by `timedc msite`
- with the name of the real master, not their own. This makes it
- possible to "chase the chain" of slave servers to the ultimate
- master.
-
-much improve the log caused by `timedc trace on`:
- -made `timed -t` work.
- -suppression of repeated entries, which both slowed down the daemon
- (sometimes catastrophically) and tended to make disks fill up
- even more quickly.
- -better time stamps on log entries
- -more messages
- -dump information about slaves, master, and so on each time
- a message asking the log be turned on is received, and
- when the log is turned off.
- -fewer CPU cycles
-
-use a hash table to keep track of slaves, instead of the stupid linear
- list. This becomes handy with hundreds of slaves, instead of
- the original design limit of "a room with a few VAX's."
-
-separate the main protocol timer from that used to look for other networks
- to master.
-
-time stamp packets received by the daemon, so that time corrections
- are not made (even more) inaccurate by waiting in the internal,
- timed queue while the daemon is processing other messages.
-
-made -n and -i work with subnets not named in /etc/networks
-
-compute the median of the measured clocks, instead of the average
- of "good" times.
-
-vastly improve the accuracy of the clock difference measure by
- `timedc clockdiff`.
-
-use adjtime() when possible, and directly set the clock only when
- necessary.
-
-when the requested adjustment is small, perform only part of it, to
- damp oscillations and improve the long term accuracy of the
- adjustments.
-
-fix uncounted core-dumps on machines that do not allow dereferencing 0
- in both the daemon and timedc.
-
-fix "master loop detection".
-
-fix several cases in which multi-homed masters could get into shouting
- matches, consuming all available network bandwidth and CPU cycles
- (which ever runs out first), and convincing all bystanders to stop
- advancing their own clocks.
-
-refuse to behave badly when other machines do. Instead of arguing forever,
- go off and sulk when other machines refuse to play by the rules.
-
-increase the maximum number of clients.
-
-add "-F host,host2,..." to "freerun" or "trust" only some hosts. This
- is handy both when only some machines should be trusted to let
- root use the `date` command to change time in the network.
-
- It is also handy when one machine has some other way of adjusting
- its clock, whether NTP or a direct radio or atomic connection.
- "-F localhost" causes `timed` to "trust" only itself.
-
- It is also handy to build a hierarchy of timed masters crossing
- networks. The TSP protocol has no provision of "goodness of clock",
- no natural way to completely heal network paritions. Judicious
- use of -F or -G can cause each gateway to trust only itself and
- machines closer to a central machine with a radio or atomic clock.
-
-add #ifdef code that supports NIS "netgroups" of trusted hosts, which
- can be easier to administer than -F.
-
-add #ifdef code to compute an aged total adjustment. This can be used
- in systems that can make long term changes in their system clock
- frequency, e.g. "timetrim" in the Silicon Graphics kernel.
-
-
-Problems observed by others that are unresolved include:
-
-Practically any users can send to the master TSP messages and this
- way corrupt the reliability of the system. Authentication
- of messages should be provided. Unfortunately, that would
- require changing the protocol with all of the implied
- compatibility problems. Fortunately, the new -F and -G args
- can be used to cause the daemon to ignore time changes from
- untrusted machines.
-
-MAN. The limit of 1013 on the number of slaves hosts should be doc'ed.
-
- It should be dynamically allocated with no limit. On a
- large network, one host could possibly master over many
- more than 30 hosts. Given the timers in the code and
- effectively in the protocol, and the time required by each
- master to talk to each slave, it is not practical to have
- more than 200-300 slaves. The master cannot keep up because
- the slave-chatting is single-threaded. when the master
- gets behind, slaves start demanding elections. To
- significantly increase the number of slaves would require
- multi-treading things, and given that a network with more
- than 300 directly addressable machines has worse problems
- than keep the time of day right, not worth worrying about.
-
-UGLY,CODE. timedc/cmds.c has a lots of repeated code in it.
-
-**** The first thing is that each command is set up as if it
- were an individual program taking argc and argv. A more
- conventional calling style should be used. I don't think
- any of the routines take more than a couple arguments.
-
-UGLY. fxn definition syntax does't follow convention:
- has type on same line.
-
-**** It needs to be fixed at least enough that tags
- will work on it. An entire cleanup might be nice later, but
- is noncritical.
-
-LOBBY(mildly),CODE: Would be very convenient if date(1) took a
- +-<number> argument to set the time relatively. With
- the advent of timed it is now reasonable to synchronize
- with WWV, which is nearly impossible to do "by hand"
- with just an absolute date, and scripts are too slow.
- format could be +-nn...nn.ss, where the '.' is required
- to remove ambiguity.
-
-**** If you want to do it go ahead. It sounds useful. As far as
- syntax goes, the normal format for the date should work just
- fine for this. If the date is preceeded by a plus or minus,
- the change is relative, otherwise it is absolute.
-
-
-Vernon Schryver.
-vjs@sgi.com
diff --git a/usr.sbin/timed/Makefile b/usr.sbin/timed/Makefile
deleted file mode 100644
index 38a64a7926a..00000000000
--- a/usr.sbin/timed/Makefile
+++ /dev/null
@@ -1,5 +0,0 @@
-# $OpenBSD: Makefile,v 1.5 2010/01/04 17:50:40 deraadt Exp $
-
-SUBDIR= timed timedc
-
-.include <bsd.subdir.mk>
diff --git a/usr.sbin/timed/SMM.doc/timed/Makefile b/usr.sbin/timed/SMM.doc/timed/Makefile
deleted file mode 100644
index d53ac0a34ac..00000000000
--- a/usr.sbin/timed/SMM.doc/timed/Makefile
+++ /dev/null
@@ -1,18 +0,0 @@
-# $OpenBSD: Makefile,v 1.3 2004/02/01 15:01:52 jmc Exp $
-# @(#)Makefile 8.2 (Berkeley) 5/11/94
-
-DIR= smm/12.timed
-SRCS= timed.ms
-.if make(install)
-SRCS+= date loop time timed.ms unused
-.endif
-MACROS= -ms
-
-paper.ps: ${SRCS}
- ${SOELIM} -I${.CURDIR} ${.ALLSRC} | ${TBL} | ${ROFF} > ${.TARGET}
-
-paper.txt: ${SRCS}
- ${SOELIM} -I${.CURDIR} ${.ALLSRC} | ${TBL} | \
- ${ROFF} -Tascii > ${.TARGET}
-
-.include <bsd.doc.mk>
diff --git a/usr.sbin/timed/SMM.doc/timed/date b/usr.sbin/timed/SMM.doc/timed/date
deleted file mode 100644
index 80ba6aab493..00000000000
--- a/usr.sbin/timed/SMM.doc/timed/date
+++ /dev/null
@@ -1,51 +0,0 @@
-.\" $OpenBSD: date,v 1.2 2003/06/02 23:36:55 millert Exp $
-.\"
-.\" Copyright (c) 1986, 1993
-.\" The Regents of the University of California. All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\" 3. Neither the name of the University nor the names of its contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" @(#)date 8.1 (Berkeley) 6/8/93
-.\"
-.ft B
-.TS
-center;
-ce | ce | ce | ce
-| c | c | c | s |
-| c s s s |.
-Byte 1 Byte 2 Byte 3 Byte 4
-=
-Type Version No. Sequence No.
-_
-Seconds of Time to Set
-_
-Microseconds of Time to Set
-_
-Machine Name
-_
-\&. . .
-_
-.TE
-.ft R
diff --git a/usr.sbin/timed/SMM.doc/timed/loop b/usr.sbin/timed/SMM.doc/timed/loop
deleted file mode 100644
index ba1e67a67b4..00000000000
--- a/usr.sbin/timed/SMM.doc/timed/loop
+++ /dev/null
@@ -1,52 +0,0 @@
-.\" $OpenBSD: loop,v 1.2 2003/06/02 23:36:55 millert Exp $
-.\"
-.\" Copyright (c) 1986, 1993
-.\" The Regents of the University of California. All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\" 3. Neither the name of the University nor the names of its contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" @(#)loop 8.1 (Berkeley) 6/8/93
-.\"
-.ft B
-.TS
-center;
-ce | ce | ce | ce
-| c | c | c | s |
-| c | c s s |
-| c s s s |.
-Byte 1 Byte 2 Byte 3 Byte 4
-=
-Type Version No. Sequence No.
-_
-Hop Count ( unused )
-_
-( unused )
-_
-Machine Name
-_
-\&. . .
-_
-.TE
-.ft R
diff --git a/usr.sbin/timed/SMM.doc/timed/spell.ok b/usr.sbin/timed/SMM.doc/timed/spell.ok
deleted file mode 100644
index 8ecfe15d852..00000000000
--- a/usr.sbin/timed/SMM.doc/timed/spell.ok
+++ /dev/null
@@ -1,34 +0,0 @@
-ACK
-ADJTIME
-Adjtime
-CS
-CSELT
-Candidature
-DATEACK
-DoD
-Gusella
-MASTERACK
-MASTERREQ
-MASTERUP
-MSITE
-MSITEREQ
-Protocol''SMM:22
-Riccardo
-SETDATE
-SETDATEREQ
-SETTIME
-SLAVEUP
-SMM:22
-Stefano
-TRACEOFF
-TRACEON
-TSP
-Timedc
-UDP
-USENIX
-Zatti
-candidature
-ce
-daemon
-daemons
-timedc
diff --git a/usr.sbin/timed/SMM.doc/timed/time b/usr.sbin/timed/SMM.doc/timed/time
deleted file mode 100644
index c8883db9839..00000000000
--- a/usr.sbin/timed/SMM.doc/timed/time
+++ /dev/null
@@ -1,51 +0,0 @@
-.\" $OpenBSD: time,v 1.2 2003/06/02 23:36:55 millert Exp $
-.\"
-.\" Copyright (c) 1986, 1993
-.\" The Regents of the University of California. All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\" 3. Neither the name of the University nor the names of its contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" @(#)time 8.1 (Berkeley) 6/8/93
-.\"
-.ft B
-.TS
-center;
-ce | ce | ce | ce
-| c | c | c | s |
-| c s s s |.
-Byte 1 Byte 2 Byte 3 Byte 4
-=
-Type Version No. Sequence No.
-_
-Seconds of Adjustment
-_
-Microseconds of Adjustment
-_
-Machine Name
-_
-\&. . .
-_
-.TE
-.ft R
diff --git a/usr.sbin/timed/SMM.doc/timed/timed.ms b/usr.sbin/timed/SMM.doc/timed/timed.ms
deleted file mode 100644
index a6e319ce19c..00000000000
--- a/usr.sbin/timed/SMM.doc/timed/timed.ms
+++ /dev/null
@@ -1,469 +0,0 @@
-.\" $OpenBSD: timed.ms,v 1.3 2003/11/04 14:07:48 jmc Exp $
-.\"
-.\" Copyright (c) 1986, 1993
-.\" The Regents of the University of California. All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\" 3. Neither the name of the University nor the names of its contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" @(#)timed.ms 8.1 (Berkeley) 6/8/93
-.\"
-.TL
-The Berkeley
-.UX
-.br
-Time Synchronization Protocol
-.AU
-Riccardo Gusella, Stefano Zatti, and James M. Bloom
-.AI
-Computer Systems Research Group
-Computer Science Division
-Department of Electrical Engineering and Computer Science
-University of California, Berkeley
-Berkeley, CA 94720
-.FS
-This work was sponsored by the Defense Advanced Research Projects Agency
-(DoD), monitored by the Naval Electronics Systems
-Command under contract No. N00039-84-C-0089, and by the Italian CSELT
-Corporation.
-The views and conclusions contained in this document are those of the
-authors and should not be interpreted as representing official policies,
-either expressed or implied, of the Defense Research Projects Agency,
-of the US Government, or of CSELT.
-.FE
-.LP
-.OH 'The Berkeley UNIX Time Synchronization Protocol''SMM:12-%'
-.EH 'SMM:12-%''The Berkeley UNIX Time Synchronization Protocol'
-.SH
-Introduction
-.PP
-The Time Synchronization Protocol (TSP)
-has been designed for specific use by the program \fItimed\fP,
-a local area network clock synchronizer for
-the UNIX 4.3BSD operating
-system.
-Timed is built on the DARPA UDP protocol [4] and
-is based on a master slave scheme.
-.PP
-TSP serves a dual purpose.
-First, it supports messages for the synchronization of the clocks
-of the various hosts in a local area network.
-Second, it supports messages for the election that occurs
-among slave time daemons when, for any reason, the master disappears.
-The synchronization mechanism and the election procedure
-employed by the program timed are described
-in other documents [1,2,3].
-.PP
-Briefly, the synchronization software, which works in a
-local area network, consists of a collection of \fItime daemons\fP
-(one per machine) and is based on a master-slave
-structure.
-The present implementation keeps processor clocks synchronized
-within 20 milliseconds.
-A \fImaster time daemon\fP measures the time
-difference between the clock of the machine on which it
-is running and those of all other machines. The current implementation
-uses ICMP \fITime Stamp Requests\fP [5] to measure the clock difference
-between machines.
-The master computes the \fInetwork time\fP as the average of the
-times provided by nonfaulty clocks.\**
-.FS
-A clock is considered to be faulty when its value
-is more than a small specified
-interval apart from the majority of the clocks
-of the machines on the same network.
-See [1,2] for more details.
-.FE
-It then sends to each \fIslave time daemon\fP the
-correction that should be performed on the clock of its machine.
-This process is repeated periodically.
-Since the correction is expressed as a time difference rather than an
-absolute time, transmission delays do not interfere with synchronization.
-When a machine comes up and joins the network,
-it starts a slave time daemon, which
-will ask the master for the correct time and will reset the machine's clock
-before any user activity can begin.
-The time daemons therefore maintain a single network time in spite of
-the drift of clocks away from each other.
-.PP
-Additionally, a time daemon on gateway machines may run as
-a \fIsubmaster\fP.
-A submaster time daemon functions as a slave on one network that
-already has a master and as master on other networks.
-In addition, a submaster is responsible for propagating broadcast
-packets from one network to the other.
-.PP
-To ensure that service provided is continuous and reliable,
-it is necessary to implement an election algorithm that will elect a
-new master should the machine running the current master crash, the master
-terminate (for example, because of a run-time error), or the network be
-partitioned.
-Under our algorithm, slaves are able to realize when the master has
-stopped functioning and to elect a new master from among themselves.
-It is important to note that since the failure of the master results
-only in a gradual divergence of clock values, the election
-need not occur immediately.
-.PP
-All the communication occurring among time daemons uses the TSP
-protocol.
-While some messages need not be sent in a reliable way,
-most communication in TSP requires reliability not provided by the underlying
-protocol.
-Reliability is achieved by the use of acknowledgements, sequence numbers, and
-retransmission when message losses occur.
-When a message that requires acknowledgement is not acknowledged after
-multiple attempts,
-the time daemon that has sent the message will assume that the
-addressee is down.
-This document will not describe the details of how reliability is
-implemented, but will only point out when
-a message type requires a reliable transport mechanism.
-.PP
-The message format in TSP is the same for all message types;
-however, in some instances, one or more fields are not used.
-The next section describes the message format.
-The following sections describe
-in detail the different message types, their use and the contents
-of each field. NOTE: The message format is likely to change in
-future versions of timed.
-.sp 2
-.SH
-Message Format
-.PP
-All fields are based upon 8-bit bytes. Fields should be sent in
-network byte order if they are more than one byte long.
-The structure of a TSP message is the following:
-.IP 1)
-A one byte message type.
-.IP 2)
-A one byte version number, specifying the protocol version which the
-message uses.
-.IP 3)
-A two byte sequence number to be used for recognizing duplicate messages
-that occur when messages are retransmitted.
-.IP 4)
-Eight bytes of packet specific data. This field contains two 4 byte time
-values, a one byte hop count, or may be unused depending on the type
-of the packet.
-.IP 5)
-A zero-terminated string of up to 256 \s-2ASCII\s+2 characters with the name of
-the machine sending the message.
-.PP
-The following charts describe the message types,
-show their fields, and explain their usages.
-For the purpose of the following discussion, a time daemon can
-be considered to be in
-one of three states: slave, master, or candidate for election to master.
-Also, the term \fIbroadcast\fP refers to
-the sending of a message to all active time daemons.
-.sp 1
-.SH
-Adjtime Message
-.so time
-.LP
-Type: TSP_ADJTIME (1)
-.sp 1
-.PP
-The master sends this message to a slave to communicate
-the difference between
-the clock of the slave and
-the network time the master has just computed.
-The slave will accordingly
-adjust the time of its machine.
-This message requires an acknowledgement.
-.sp 1
-.SH
-Acknowledgement Message
-.so unused
-.LP
-Type: TSP_ACK (2)
-.sp 1
-.PP
-Both the master and the slaves use this message for
-acknowledgement only.
-It is used in several different contexts, for example
-in reply to an Adjtime message.
-.sp 1
-.SH
-Master Request Message
-.so unused
-.LP
-Type: TSP_MASTERREQ (3)
-.sp 1
-.PP
-A newly-started time daemon broadcasts this message to
-locate a master. No other action is implied by this packet.
-It requires a Master Acknowledgement.
-.sp 1
-.SH
-Master Acknowledgement
-.so unused
-.LP
-Type: TSP_MASTERACK (4)
-.sp 1
-.PP
-The master sends this message to acknowledge the Master Request message
-and the Conflict Resolution Message.
-.sp 1
-.SH
-Set Network Time Message
-.so date
-.LP
-Type: TSP_SETTIME (5)
-.sp 1
-.PP
-The master sends this message to slave time daemons to set their time.
-This packet is sent to newly started time daemons and when the network
-date is changed.
-It contains the master's time as an approximation of the network time.
-It requires an acknowledgement.
-The next
-synchronization round will eliminate the small time difference
-caused by the random delay in the communication channel.
-.sp 1
-.SH
-Master Active Message
-.so unused
-.LP
-Type: TSP_MASTERUP (6)
-.sp 1
-.PP
-The master broadcasts this message to
-solicit the names of the active slaves.
-Slaves will reply with a Slave Active message.
-.sp 1
-.SH
-Slave Active Message
-.so unused
-.LP
-Type: TSP_SLAVEUP (7)
-.sp 1
-.PP
-A slave sends this message to the master in answer to a Master Active message.
-This message is also sent when a new slave starts up to inform the master that
-it wants to be synchronized.
-.sp 1
-.SH
-Master Candidature Message
-.so unused
-.LP
-Type: TSP_ELECTION (8)
-.sp 1
-.PP
-A slave eligible to become a master broadcasts this message when its election
-timer expires.
-The message declares that the slave wishes to become the new master.
-.sp 1
-.SH
-Candidature Acceptance Message
-.so unused
-.LP
-Type: TSP_ACCEPT (9)
-.sp 1
-.PP
-A slave sends this message to accept the candidature of the time daemon
-that has broadcast an Election message.
-The candidate will add the slave's name to the list of machines that it
-will control should it become the master.
-.sp 1
-.SH
-Candidature Rejection Message
-.so unused
-.LP
-Type: TSP_REFUSE (10)
-.sp 1
-.PP
-After a slave accepts the candidature of a time daemon, it will reply
-to any election messages from other slaves
-with this message.
-This rejects any candidature other than the first received.
-.sp 1
-.SH
-Multiple Master Notification Message
-.so unused
-.LP
-Type: TSP_CONFLICT (11)
-.sp 1
-.PP
-When two or more masters reply to a Master Request message, the slave
-uses this message to inform one of them that more than one master exists.
-.sp 1
-.SH
-Conflict Resolution Message
-.so unused
-.LP
-Type: TSP_RESOLVE (12)
-.sp 1
-.PP
-A master which has been informed of the existence of other masters
-broadcasts this message to determine who the other masters are.
-.sp 1
-.SH
-Quit Message
-.so unused
-.LP
-Type: TSP_QUIT (13)
-.sp 1
-.PP
-This message is sent by the master in three different contexts:
-1) to a candidate that broadcasts an Master Candidature message,
-2) to another master when notified of its existence,
-3) to another master if a loop is detected.
-In all cases, the recipient time daemon will become a slave.
-This message requires an acknowledgement.
-.sp 1
-.SH
-Date Command
-.LP
-Type: TSP_DATE (14)
-.LP
-Currently unused.
-.SH
-Date Command (remote)
-.LP
-Type: TSP_DATEREQ (15)
-.LP
-Currently unused.
-.SH
-Set Date Acknowledgement Message
-.so unused
-.LP
-Type: TSP_DATEACK (16)
-.sp 1
-.PP
-The master sends this message to a slave in acknowledgement of a
-Set Date Request Message.
-The same message is sent by the local time daemon to the program
-\fIdate(1)\fP to confirm that the network date has been set by the
-master.
-.sp 1
-.SH
-Start Tracing Message
-.so unused
-.LP
-Type: TSP_TRACEON (17)
-.sp 1
-.PP
-The controlling program \fItimedc\fP sends this message to the local
-time daemon to start the recording in a system file of
-all messages received.
-.sp 1
-.SH
-Stop Tracing Message
-.so unused
-.LP
-Type: TSP_TRACEOFF (18)
-.sp 1
-.PP
-\fITimedc\fP sends this message to the local
-time daemon to stop the recording of
-messages received.
-.sp 1
-.SH
-Master Site Message
-.so unused
-.LP
-Type: TSP_MSITE (19)
-.sp 1
-.PP
-\fITimedc\fP sends this message to the local time daemon to find out
-where the master is running.
-.sp 1
-.SH
-Remote Master Site Message
-.so unused
-.LP
-Type: TSP_MSITEREQ (20)
-.sp 1
-.PP
-A local time daemon broadcasts this message to find the location
-of the master.
-It then uses the Acknowledgement message to
-communicate this location to \fItimedc\fP.
-.sp 1
-.SH
-Test Message
-.so unused
-.LP
-Type: TSP_TEST (21)
-.sp 1
-.PP
-For testing purposes, \fItimedc\fP sends this message to a slave
-to cause its election timer to expire. NOTE: \fItimed\fP
-is not normally compiled to support this.
-.sp 1
-.SH
-Set Date Message
-.so date
-.LP
-Type: TSP_SETDATE (22)
-.sp 1
-.PP
-The program \fIdate\fP\|(1) sends this message to the local time daemon
-when a super-user wants to set the network date.
-If the local time daemon is the master, it will set the date;
-if it is a slave, it will communicate the desired date to the master.
-.sp 1
-.SH
-Set Date Request Message
-.so date
-.LP
-Type: TSP_SETDATEREQ (23)
-.sp 1
-.PP
-A slave that has received a Set Date message will communicate the
-desired date to the master using this message.
-.sp 1
-.SH
-Loop Detection Message
-.so loop
-.LP
-Type: TSP_LOOP (24)
-.sp 1
-.PP
-This packet is initiated by all masters occasionally to attempt to detect loops.
-All submasters forward this packet onto the networks over which they are master.
-If a master receives a packet it sent out initially,
-it knows that a loop exists and tries to correct the problem.
-.SH
-References
-.IP 1.
-R. Gusella and S. Zatti,
-\fITEMPO: A Network Time Controller for Distributed Berkeley UNIX System\fP,
-USENIX Summer Conference Proceedings, Salt Lake City, June 1984.
-.IP 2.
-R. Gusella and S. Zatti, \fIClock Synchronization in a Local Area Network\fP,
-University of California, Berkeley, Technical Report, \fIto appear\fP.
-.IP 3.
-R. Gusella and S. Zatti,
-\fIAn Election Algorithm for a Distributed Clock Synchronization Program\fP,
-University of California, Berkeley, CS Technical Report #275, Dec. 1985.
-.IP 4.
-Postel, J., \fIUser Datagram Protocol\fP, RFC 768.
-Network Information Center, SRI International, Menlo Park, California,
-August 1980.
-.IP 5.
-Postel, J., \fIInternet Control Message Protocol\fP, RFC 792.
-Network Information Center, SRI International, Menlo Park, California,
-September 1981.
diff --git a/usr.sbin/timed/SMM.doc/timed/unused b/usr.sbin/timed/SMM.doc/timed/unused
deleted file mode 100644
index 5315b42944f..00000000000
--- a/usr.sbin/timed/SMM.doc/timed/unused
+++ /dev/null
@@ -1,51 +0,0 @@
-.\" $OpenBSD: unused,v 1.3 2009/08/13 19:56:05 jmc Exp $
-.\"
-.\" Copyright (c) 1986, 1993
-.\" The Regents of the University of California. All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\" 3. Neither the name of the University nor the names of its contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" @(#)unused 8.1 (Berkeley) 6/8/93
-.\"
-.ft B
-.TS
-center;
-ce | ce | ce | ce
-| c | c | c | s |
-| c s s s |.
-Byte 1 Byte 2 Byte 3 Byte 4
-=
-Type Version No. Sequence No.
-_
-( unused )
-_
-( unused )
-_
-Machine Name
-_
-\&. . .
-_
-.TE
-.ft R
diff --git a/usr.sbin/timed/SMM.doc/timedop/Makefile b/usr.sbin/timed/SMM.doc/timedop/Makefile
deleted file mode 100644
index 84691b88eae..00000000000
--- a/usr.sbin/timed/SMM.doc/timedop/Makefile
+++ /dev/null
@@ -1,11 +0,0 @@
-# $OpenBSD: Makefile,v 1.2 2004/02/01 15:01:53 jmc Exp $
-# @(#)Makefile 8.1 (Berkeley) 6/8/93
-
-DIR= smm/11.timedop
-SRCS= timed.ms
-MACROS= -ms
-
-paper.txt: ${SRCS}
- ${ROFF} -Tascii ${SRCS} > ${.TARGET}
-
-.include <bsd.doc.mk>
diff --git a/usr.sbin/timed/SMM.doc/timedop/timed.ms b/usr.sbin/timed/SMM.doc/timedop/timed.ms
deleted file mode 100644
index 76187bd0bb3..00000000000
--- a/usr.sbin/timed/SMM.doc/timedop/timed.ms
+++ /dev/null
@@ -1,275 +0,0 @@
-.\" $OpenBSD: timed.ms,v 1.3 2003/11/04 14:07:48 jmc Exp $
-.\"
-.\" Copyright (c) 1986, 1993
-.\" The Regents of the University of California. All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\" 3. Neither the name of the University nor the names of its contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" @(#)timed.ms 8.1 (Berkeley) 6/8/93
-.\"
-.TL
-Timed Installation and Operation Guide
-.AU
-Riccardo Gusella, Stefano Zatti, James M. Bloom
-.AI
-Computer Systems Research Group
-Computer Science Division
-Department of Electrical Engineering and Computer Science
-University of California, Berkeley
-Berkeley, CA 94720
-.AU
-Kirk Smith
-.AI
-Engineering Computer Network
-Department of Electrical Engineering
-Purdue University
-West Lafayette, IN 47906
-.FS
-This work was sponsored by the Defense Advanced Research Projects Agency
-(DoD), monitored by the Naval Electronics Systems
-Command under contract No. N00039-84-C-0089, and by the CSELT
-Corporation of Italy.
-The views and conclusions contained in this document are those of the
-authors and should not be interpreted as representing official policies,
-either expressed or implied, of the Defense Research Projects Agency,
-of the US Government, or of CSELT.
-.FE
-.LP
-.EH 'SMM:11-%''Timed Installation and Operation'
-.OH 'Timed Installation and Operation''SMM:11-%'
-.SH
-Introduction
-.PP
-The clock synchronization service for
-the UNIX 4.3BSD operating system is composed of a collection of
-time daemons (\fItimed\fP) running on the machines in a local
-area network.
-The algorithms implemented by the service is based on a master-slave scheme.
-The time daemons communicate with each other using the
-\fITime Synchronization Protocol\fP (TSP) which
-is built on the DARPA UDP protocol and described in detail in [4].
-.PP
-A time daemon has a twofold function.
-First, it supports the synchronization of the clocks
-of the various hosts in a local area network.
-Second, it starts (or takes part in) the election that occurs
-among slave time daemons when, for any reason, the master disappears.
-The synchronization mechanism and the election procedure
-employed by the program \fItimed\fP are described
-in other documents [1,2,3].
-The next paragraphs are a brief overview of how the time daemon works.
-This document is mainly concerned with the administrative and technical
-issues of running \fItimed\fP at a particular site.
-.PP
-A \fImaster time daemon\fP measures the time
-differences between the clock of the machine on which it
-is running and those of all other machines.
-The master computes the \fInetwork time\fP as the average of the
-times provided by nonfaulty clocks.\**
-.FS
-A clock is considered to be faulty when its value
-is more than a small specified
-interval apart from the majority of the clocks
-of the other machines [1,2].
-.FE
-It then sends to each \fIslave time daemon\fP the
-correction that should be performed on the clock of its machine.
-This process is repeated periodically.
-Since the correction is expressed as a time difference rather than an
-absolute time, transmission delays do not interfere with
-the accuracy of the synchronization.
-When a machine comes up and joins the network,
-it starts a slave time daemon which
-will ask the master for the correct time and will reset the machine's clock
-before any user activity can begin.
-The time daemons are able to maintain a single network time in spite of
-the drift of clocks away from each other.
-The present implementation keeps processor clocks synchronized
-within 20 milliseconds.
-.PP
-To ensure that the service provided is continuous and reliable,
-it is necessary to implement an election algorithm to elect a
-new master should the machine running the current master crash, the master
-terminate (for example, because of a run-time error), or
-the network be partitioned.
-Under our algorithm, slaves are able to realize when the master has
-stopped functioning and to elect a new master from among themselves.
-It is important to note that, since the failure of the master results
-only in a gradual divergence of clock values, the election
-need not occur immediately.
-.PP
-The machines that are gateways between distinct local area
-networks require particular care.
-A time daemon on such machines may act as a \fIsubmaster\fP.
-This artifact depends on the current inability of
-transmission protocols to broadcast a message on a network
-other than the one to which the broadcasting machine is connected.
-The submaster appears as a slave on one network, and as a master
-on one or more of the other networks to which it is connected.
-.PP
-A submaster classifies each network as one of three types.
-A \fIslave network\fP is a network on which the submaster acts as a slave.
-There can only be one slave network.
-A \fImaster network\fP is a network on which the submaster acts as a master.
-An \fIignored network\fP is any other network which already has a valid master.
-The submaster tries periodically to become master on an ignored
-network, but gives up immediately if a master already exists.
-.SH
-Guidelines
-.PP
-While the synchronization algorithm is quite general, the election
-one, requiring a broadcast mechanism, puts constraints on
-the kind of network on which time daemons can run.
-The time daemon will only work on networks with broadcast capability
-augmented with point-to-point links.
-Machines that are only connected to point-to-point,
-non-broadcast networks may not use the time daemon.
-.PP
-If we exclude submasters, there will normally be, at most, one master time
-daemon in a local area internetwork.
-During an election, only one of the slave time daemons
-will become the new master.
-However, because of the characteristics of its machine,
-a slave can be prevented from becoming the master.
-Therefore, a subset of machines must be designated as potential
-master time daemons.
-A master time daemon will require CPU resources
-proportional to the number of slaves, in general, more than
-a slave time daemon, so it may be advisable to limit master time
-daemons to machines with more powerful processors or lighter loads.
-Also, machines with inaccurate clocks should not be used as masters.
-This is a purely administrative decision: an organization may
-well allow all of its machines to run master time daemons.
-.PP
-At the administrative level, a time daemon on a machine
-with multiple network interfaces, may be told to ignore all
-but one network or to ignore one network.
-This is done with the \fI\-n network\fP and \fI\-i network\fP
-options respectively at start-up time.
-Typically, the time daemon would be instructed to ignore all but
-the networks belonging to the local administrative control.
-.PP
-There are some limitations to the current
-implementation of the time daemon.
-It is expected that these limitations will be removed in future releases.
-The constant NHOSTS in /usr/src/usr.sbin/timed/timed/globals.h limits the
-maximum number of machines that may be directly controlled by one
-master time daemon.
-The current maximum is 1013.
-The constant must be changed and the program recompiled if a site wishes to
-run \fItimed\fP on a larger (inter)network.
-.PP
-In addition, there is a \fIpathological situation\fP to
-be avoided at all costs, that might occur when
-time daemons run on multiply-connected local area networks.
-In this case, as we have seen, time daemons running on gateway machines
-will be submasters and they will act on some of those
-networks as master time daemons.
-Consider machines A and B that are both gateways between
-networks X and Y.
-If time daemons were started on both A and B without constraints, it would be
-possible for submaster time daemon A to be a slave on network X
-and the master on network Y, while submaster time daemon B is a slave on
-network Y and the master on network X.
-This \fIloop\fP of master time daemons will not function properly
-or guarantee a unique time on both networks, and will cause
-the submasters to use large amounts of system resources in the form
-of network bandwidth and CPU time.
-In fact, this kind of \fIloop\fP can also be generated with more
-than two master time daemons,
-when several local area networks are interconnected.
-.SH
-Installation
-.PP
-In order to start the time daemon on a given machine,
-the following lines should be
-added to \fI/etc/rc.conf.local\fP:
-.sp 2
-.in 1i
-.nf
-timed_flags=""
-.fi
-.in -1i
-.sp
-.LP
-.PP
-Also, the file \fI/etc/services\fP should contain the following
-line:
-.sp 2
-.ti 1i
-timed 525/udp timeserver
-.sp
-.LP
-Some of the most commonly used \fIflags\fP are:
-.IP "-n network" 13
-to add network to the list of allowed networks.
-.IP "-i network"
-to ignore the named network.
-.IP -t
-to place tracing information in \fI/var/log/timed.log\fP.
-.IP -M
-to allow this time daemon to become a master.
-A time daemon run without this option will be forced in the state of
-slave during an election.
-.LP
-See the timed(8) manual page for more information on the various flags.
-.SH
-Daily Operation
-.PP
-\fITimedc(8)\fP is used to control the operation of the time daemon.
-It may be used to:
-.IP \(bu
-measure the differences between machines' clocks
-.IP \(bu
-find the location where the master \fItimed\fP is running
-.IP \(bu
-enable or disable tracing of messages received by \fItimed\fP
-.IP \(bu
-perform various debugging actions
-.LP
-See the manual page on \fItimed\fP\|(8) and \fItimedc\fP\|(8)
-for more detailed information.
-.PP
-The \fIdate(1)\fP command can be used to set the network date.
-In order to set the time on a single machine, the \fI-n\fP flag
-can be given to date(1).
-.bp
-.SH
-References
-.IP 1.
-R. Gusella and S. Zatti,
-\fITEMPO: A Network Time Controller for Distributed Berkeley UNIX System\fP,
-USENIX Summer Conference Proceedings, Salt Lake City, June 1984.
-.IP 2.
-R. Gusella and S. Zatti, \fIClock Synchronization in a Local Area Network\fP,
-University of California, Berkeley, Technical Report, \fIto appear\fP.
-.IP 3.
-R. Gusella and S. Zatti,
-\fIAn Election Algorithm for a Distributed Clock Synchronization Program\fP,
-University of California, Berkeley, CS Technical Report #275, Dec. 1985.
-.IP 4.
-R. Gusella and S. Zatti,
-\fIThe Berkeley UNIX 4.3BSD Time Synchronization Protocol\fP,
-UNIX Programmer's Manual, 4.3 Berkeley Software Distribution, Volume 2c.
diff --git a/usr.sbin/timed/timed/Makefile b/usr.sbin/timed/timed/Makefile
deleted file mode 100644
index b8d870c114f..00000000000
--- a/usr.sbin/timed/timed/Makefile
+++ /dev/null
@@ -1,15 +0,0 @@
-# $OpenBSD: Makefile,v 1.7 2002/06/18 00:40:30 ericj Exp $
-#
-# @(#)Makefile 5.12 (Berkeley) 5/7/93
-#
-# optional flags are: MEASURE TESTING DEBUG
-
-PROG= timed
-SRCS= acksend.c candidate.c correct.c master.c networkdelta.c readmsg.c \
- slave.c timed.c byteorder.c measure.c cksum.c
-DPADD= ${LIBUTIL}
-LDADD= -lutil
-MAN= timed.8
-
-.include "../../Makefile.inc"
-.include <bsd.prog.mk>
diff --git a/usr.sbin/timed/timed/acksend.c b/usr.sbin/timed/timed/acksend.c
deleted file mode 100644
index 5672d7ee362..00000000000
--- a/usr.sbin/timed/timed/acksend.c
+++ /dev/null
@@ -1,118 +0,0 @@
-/* $OpenBSD: acksend.c,v 1.7 2009/10/27 23:59:57 deraadt Exp $ */
-
-/*-
- * Copyright (c) 1985, 1993 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include "globals.h"
-
-
-struct tsp *answer;
-
-void
-xmit(int type,
- u_short seq,
- struct sockaddr_in *addr)
-{
- static struct tsp msg;
-
- msg.tsp_type = type;
- msg.tsp_seq = seq;
- msg.tsp_vers = TSPVERSION;
- strlcpy(msg.tsp_name, hostname, sizeof msg.tsp_name);
- bytenetorder(&msg);
- if (sendto(sock, (char *)&msg, sizeof(struct tsp), 0,
- (struct sockaddr*)addr, sizeof(struct sockaddr)) < 0) {
- trace_sendto_err(addr->sin_addr);
- }
-}
-
-
-/*
- * Acksend implements reliable datagram transmission by using sequence
- * numbers and retransmission when necessary.
- * If `name' is ANYADDR, this routine implements reliable broadcast.
- *
- * Because this function calls readmsg(), none of its args may be in
- * a message provided by readmsg().
- */
-struct tsp *
-acksend(struct tsp *message, /* this message */
- struct sockaddr_in *addr, char *name, /* to here */
- int ack, /* look for this ack */
- struct netinfo *net, /* receive from this network */
- int bad) /* 1=losing patience */
-{
- struct timeval twait;
- int count;
- long msec;
-
- message->tsp_vers = TSPVERSION;
- message->tsp_seq = sequence;
- if (trace) {
- fprintf(fd, "acksend: to %s: ",
- (name == ANYADDR ? "broadcast" : name));
- print(message, addr);
- }
- bytenetorder(message);
-
- msec = 200;
- count = bad ? 1 : 5; /* 5 packets in 6.4 seconds */
- answer = 0;
- do {
- if (!answer) {
- /* do not go crazy transmitting just because the
- * other guy cannot keep our sequence numbers
- * straight.
- */
- if (sendto(sock, (char *)message, sizeof(struct tsp),
- 0, (struct sockaddr*)addr,
- sizeof(struct sockaddr)) < 0) {
- trace_sendto_err(addr->sin_addr);
- break;
- }
- }
-
- mstotvround(&twait, msec);
- answer = readmsg(ack, name, &twait, net);
- if (answer != 0) {
- if (answer->tsp_seq != sequence) {
- if (trace)
- fprintf(fd,"acksend: seq # %u!=%u\n",
- answer->tsp_seq, sequence);
- continue;
- }
- break;
- }
-
- msec *= 2;
- } while (--count > 0);
- sequence++;
-
- return(answer);
-}
diff --git a/usr.sbin/timed/timed/byteorder.c b/usr.sbin/timed/timed/byteorder.c
deleted file mode 100644
index 6bd4f794a98..00000000000
--- a/usr.sbin/timed/timed/byteorder.c
+++ /dev/null
@@ -1,74 +0,0 @@
-/* $OpenBSD: byteorder.c,v 1.6 2009/10/27 23:59:57 deraadt Exp $ */
-
-/*-
- * Copyright (c) 1985, 1993 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include "globals.h"
-
-/*
- * Two routines to do the necessary byte swapping for timed protocol
- * messages. Protocol is defined in /usr/include/protocols/timed.h
- */
-void
-bytenetorder(struct tsp *ptr)
-{
- ptr->tsp_seq = htons((u_short)ptr->tsp_seq);
- switch (ptr->tsp_type) {
-
- case TSP_SETTIME:
- case TSP_ADJTIME:
- case TSP_SETDATE:
- case TSP_SETDATEREQ:
- ptr->tsp_time.tv_sec = htonl((u_long)ptr->tsp_time.tv_sec);
- ptr->tsp_time.tv_usec = htonl((u_long)ptr->tsp_time.tv_usec);
- break;
-
- default:
- break; /* nothing more needed */
- }
-}
-
-void
-bytehostorder(struct tsp *ptr)
-{
- ptr->tsp_seq = ntohs((u_short)ptr->tsp_seq);
- switch (ptr->tsp_type) {
-
- case TSP_SETTIME:
- case TSP_ADJTIME:
- case TSP_SETDATE:
- case TSP_SETDATEREQ:
- ptr->tsp_time.tv_sec = ntohl((u_long)ptr->tsp_time.tv_sec);
- ptr->tsp_time.tv_usec = ntohl((u_long)ptr->tsp_time.tv_usec);
- break;
-
- default:
- break; /* nothing more needed */
- }
-}
diff --git a/usr.sbin/timed/timed/candidate.c b/usr.sbin/timed/timed/candidate.c
deleted file mode 100644
index 88585f13830..00000000000
--- a/usr.sbin/timed/timed/candidate.c
+++ /dev/null
@@ -1,156 +0,0 @@
-/* $OpenBSD: candidate.c,v 1.8 2011/03/19 23:40:11 okan Exp $ */
-
-/*-
- * Copyright (c) 1985, 1993 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include "globals.h"
-
-/*
- * `election' candidates a host as master: it is called by a slave
- * which runs with the -M option set when its election timeout expires.
- * Note the conservative approach: if a new timed comes up, or another
- * candidate sends an election request, the candidature is withdrawn.
- */
-int
-election(net)
- struct netinfo *net;
-{
- struct tsp *resp, msg;
- struct timeval then, wait;
- struct tsp *answer;
- struct hosttbl *htp;
- char loop_lim = 0;
-
-/* This code can get totally confused if it gets slightly behind. For
- * example, if readmsg() has some QUIT messages waiting from the last
- * round, we would send an ELECTION message, get the stale QUIT,
- * and give up. This results in network storms when several machines
- * do it at once.
- */
- timerclear(&wait);
- while (0 != readmsg(TSP_REFUSE, ANYADDR, &wait, net)) {
- if (trace)
- fprintf(fd, "election: discarded stale REFUSE\n");
- }
- while (0 != readmsg(TSP_QUIT, ANYADDR, &wait, net)) {
- if (trace)
- fprintf(fd, "election: discarded stale QUIT\n");
- }
-
-again:
- syslog(LOG_INFO, "This machine is a candidate time master");
- if (trace)
- fprintf(fd, "This machine is a candidate time master\n");
- msg.tsp_type = TSP_ELECTION;
- msg.tsp_vers = TSPVERSION;
- strlcpy(msg.tsp_name, hostname, sizeof msg.tsp_name);
- bytenetorder(&msg);
- if (sendto(sock, (char *)&msg, sizeof(struct tsp), 0,
- (struct sockaddr*)&net->dest_addr,
- sizeof(struct sockaddr)) < 0) {
- trace_sendto_err(net->dest_addr.sin_addr);
- return(SLAVE);
- }
-
- (void)gettimeofday(&then, 0);
- then.tv_sec += 3;
- for (;;) {
- (void)gettimeofday(&wait, 0);
- timersub(&then, &wait, &wait);
- resp = readmsg(TSP_ANY, ANYADDR, &wait, net);
- if (!resp)
- return(MASTER);
-
- switch (resp->tsp_type) {
-
- case TSP_ACCEPT:
- (void)addmach(resp->tsp_name, &from,fromnet);
- break;
-
- case TSP_MASTERUP:
- case TSP_MASTERREQ:
- /*
- * If another timedaemon is coming up at the same
- * time, give up, and let it be the master.
- */
- if (++loop_lim < 5
- && !good_host_name(resp->tsp_name)) {
- (void)addmach(resp->tsp_name, &from,fromnet);
- suppress(&from, resp->tsp_name, net);
- goto again;
- }
- rmnetmachs(net);
- return(SLAVE);
-
- case TSP_QUIT:
- case TSP_REFUSE:
- /*
- * Collision: change value of election timer
- * using exponential backoff.
- *
- * Fooey.
- * An exponential backoff on a delay starting at
- * 6 to 15 minutes for a process that takes
- * milliseconds is silly. It is particularly
- * strange that the original code would increase
- * the backoff without bound.
- */
- rmnetmachs(net);
- return(SLAVE);
-
- case TSP_ELECTION:
- /* no master for another round */
- htp = addmach(resp->tsp_name,&from,fromnet);
- msg.tsp_type = TSP_REFUSE;
- strlcpy(msg.tsp_name, hostname, sizeof msg.tsp_name);
- answer = acksend(&msg, &htp->addr, htp->name,
- TSP_ACK, 0, htp->noanswer);
- if (!answer) {
- syslog(LOG_ERR, "error in election from %s",
- htp->name);
- }
- break;
-
- case TSP_SLAVEUP:
- (void)addmach(resp->tsp_name, &from,fromnet);
- break;
-
- case TSP_SETDATE:
- case TSP_SETDATEREQ:
- break;
-
- default:
- if (trace) {
- fprintf(fd, "candidate: ");
- print(resp, &from);
- }
- break;
- }
- }
-}
diff --git a/usr.sbin/timed/timed/cksum.c b/usr.sbin/timed/timed/cksum.c
deleted file mode 100644
index b8040c1219e..00000000000
--- a/usr.sbin/timed/timed/cksum.c
+++ /dev/null
@@ -1,75 +0,0 @@
-/* $OpenBSD: cksum.c,v 1.6 2009/10/27 23:59:57 deraadt Exp $ */
-
-/*-
- * Copyright (c) 1985, 1993 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/types.h>
-
-/*
- * I N _ C K S U M
- *
- * Checksum routine for Internet Protocol family headers (C Version)
- *
- * There is no profit in a specialized version of the checksum
- * function for any machine where int's are 32 bits and shorts are 16.
- *
- * All timed packets are smaller than 32K shorts, so there is no need to
- * worry about carries except at the end.
- */
-int
-in_cksum(u_short *addr, int len)
-{
- int nleft = len;
- u_short *w = addr;
- u_short answer;
- int sum = 0;
-
- /*
- * Our algorithm is simple, using a 32 bit accumulator (sum),
- * we add sequential 16 bit words to it, and at the end, fold
- * back all the carry bits from the top 16 bits into the lower
- * 16 bits.
- */
- while( nleft > 1 ) {
- sum += *w++;
- nleft -= 2;
- }
-
- /* mop up an odd byte, if necessary */
- if( nleft == 1 )
- sum += (*(u_char *)w) << 8;
-
- /*
- * add back carry outs from top 16 bits to low 16 bits
- */
- sum = (sum >> 16) + (sum & 0xffff); /* add hi 16 to low 16 */
- sum += (sum >> 16); /* add carry */
- answer = ~sum; /* truncate to 16 bits */
- return (answer);
-}
diff --git a/usr.sbin/timed/timed/correct.c b/usr.sbin/timed/timed/correct.c
deleted file mode 100644
index a159ced26eb..00000000000
--- a/usr.sbin/timed/timed/correct.c
+++ /dev/null
@@ -1,177 +0,0 @@
-/* $OpenBSD: correct.c,v 1.9 2009/10/27 23:59:57 deraadt Exp $ */
-
-/*-
- * Copyright (c) 1985, 1993 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include "globals.h"
-#include <math.h>
-#include <sys/types.h>
-#include <sys/times.h>
-
-static void adjclock(struct timeval*);
-
-/*
- * sends to the slaves the corrections for their clocks after fixing our
- * own
- */
-void
-correct(long avdelta)
-{
- struct hosttbl *htp;
- int corr;
- struct timeval adjlocal, tmptv;
- struct tsp to;
- struct tsp *answer;
-
- mstotvround(&adjlocal, avdelta);
-
- for (htp = self.l_fwd; htp != &self; htp = htp->l_fwd) {
- if (htp->delta != HOSTDOWN) {
- corr = avdelta - htp->delta;
-/* If the other machine is off in the weeds, set its time directly.
- * If a slave gets the wrong day, the original code would simply
- * fix the minutes. If you fix a network partition, you can get
- * into such situations.
- */
- if (htp->need_set
- || corr >= MAXADJ*1000
- || corr <= -MAXADJ*1000) {
- htp->need_set = 0;
- (void)gettimeofday(&tmptv,0);
- timeradd(&tmptv, &adjlocal, &tmptv);
- to.tsp_time.tv_sec = tmptv.tv_sec;
- to.tsp_time.tv_usec = tmptv.tv_usec;
- to.tsp_type = TSP_SETTIME;
- } else {
- tmptv.tv_sec = to.tsp_time.tv_sec ;
- tmptv.tv_usec = to.tsp_time.tv_usec ;
- mstotvround(&tmptv, corr);
- to.tsp_time.tv_sec = tmptv.tv_sec;
- to.tsp_time.tv_usec = tmptv.tv_usec;
- to.tsp_type = TSP_ADJTIME;
- }
- strlcpy(to.tsp_name, hostname, sizeof to.tsp_name);
- answer = acksend(&to, &htp->addr, htp->name,
- TSP_ACK, 0, 0);
- if (!answer) {
- htp->delta = HOSTDOWN;
- syslog(LOG_WARNING,
- "no reply to time correction from %s",
- htp->name);
- if (++htp->noanswer >= LOSTHOST) {
- if (trace) {
- fprintf(fd,
- "purging %s for not answering\n",
- htp->name);
- (void)fflush(fd);
- }
- htp = remmach(htp);
- }
- }
- }
- }
-
- /*
- * adjust our own clock now that we are not sending it out
- */
- adjclock(&adjlocal);
-}
-
-
-static void
-adjclock(struct timeval *corr)
-{
- static int passes = 0;
- static int smoother = 0;
- long delta; /* adjustment in usec */
- long ndelta;
- struct timeval now;
- struct timeval adj;
-
- if (!timerisset(corr))
- return;
-
- adj = *corr;
- if (adj.tv_sec < MAXADJ && adj.tv_sec > - MAXADJ) {
- delta = adj.tv_sec*1000000 + adj.tv_usec;
- /* If the correction is less than the minimum round
- * trip time for an ICMP packet, and thus
- * less than the likely error in the measurement,
- * do not do the entire correction. Do half
- * or a quarter of it.
- */
-
- if (delta > -MIN_ROUND*1000
- && delta < MIN_ROUND*1000) {
- if (smoother <= 4)
- smoother++;
- ndelta = delta >> smoother;
- if (trace)
- fprintf(fd,
- "trimming delta %ld usec to %ld\n",
- delta, ndelta);
- adj.tv_usec = ndelta;
- adj.tv_sec = 0;
- } else if (smoother > 0) {
- smoother--;
- }
- if (0 > adjtime(corr, 0)) {
- syslog(LOG_ERR, "adjtime: %m");
- }
- if (passes > 1
- && (delta < -BIG_ADJ || delta > BIG_ADJ)) {
- smoother = 0;
- passes = 0;
- syslog(LOG_WARNING,
- "large time adjustment of %+.3f sec",
- delta/1000000.0);
- }
- } else {
- syslog(LOG_WARNING,
- "clock correction %ld sec too large to adjust",
- adj.tv_sec);
- (void) gettimeofday(&now, 0);
- timeradd(&now, corr, &now);
- if (settimeofday(&now, 0) < 0)
- syslog(LOG_ERR, "settimeofday: %m");
- }
-}
-
-
-/* adjust the time in a message by the time it
- * spent in the queue
- */
-void
-adj_msg_time(struct tsp *msg, struct timeval *now)
-{
- struct timeval diff;
-
- timersub(now, &from_when, &diff);
- timeradd(&msg->tsp_time, &diff, &msg->tsp_time);
-}
diff --git a/usr.sbin/timed/timed/globals.h b/usr.sbin/timed/timed/globals.h
deleted file mode 100644
index ae9df042a6e..00000000000
--- a/usr.sbin/timed/timed/globals.h
+++ /dev/null
@@ -1,170 +0,0 @@
-/* $OpenBSD: globals.h,v 1.8 2003/08/19 19:41:21 deraadt Exp $ */
-
-/*-
- * Copyright (c) 1985 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)globals.h 5.1 (Berkeley) 5/11/93
- */
-
-#include <sys/param.h>
-#include <sys/time.h>
-#include <sys/socket.h>
-
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-#include <errno.h>
-#include <limits.h>
-#include <netdb.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <syslog.h>
-#include <syslog.h>
-#include <poll.h>
-#include <unistd.h>
-
-#include <protocols/timed.h>
-
-#define SECHR (60*60)
-#define SECDAY (24*SECHR)
-
-extern int sock;
-
-/* Best expected round trip for a measurement.
- * This is essentially the number of milliseconds per CPU tick (CLK_TCK?).
- * All delays shorter than this are usually reported as 0.
- */
-#define MIN_ROUND ((1000-1)/CLK_TCK)
-
-
-#define SAMPLEINTVL 240 /* synch() freq for master in sec */
-#define MAXADJ 20 /* max adjtime() correction in sec */
-
-#define MAX_TRIM 3000000 /* max drift in nsec/sec, 0.3% */
-#define BIG_ADJ (MAX_TRIM/1000*SAMPLEINTVL*2) /* max good adj */
-
-#define MINTOUT 360 /* election delays, 6-15 minutes */
-#define MAXTOUT 900
-
-#define BAD_STATUS (-1)
-#define GOOD 1
-#define UNREACHABLE 2
-#define NONSTDTIME 3
-#define HOSTDOWN 0x7fffffff
-
-#define MAX_HOPCNT 10 /* max value for tsp_hpcnt */
-
-#define LOSTHOST 3 /* forget after this many failures */
-
-#define VALID_RANGE (MAXADJ*1000) /* good times in milliseconds */
-#define GOOD_RANGE (MIN_ROUND*2)
-#define VGOOD_RANGE (MIN_ROUND-1)
-
-
-/*
- * Global and per-network states.
- */
-#define NOMASTER 0 /* no good master */
-#define SLAVE 1
-#define MASTER 2
-#define IGNORE 4
-#define ALL (SLAVE|MASTER|IGNORE)
-#define SUBMASTER (SLAVE|MASTER)
-
-#define NHOSTS 1013 /* max of hosts controlled by timed
- * This must be a prime number.
- */
-struct hosttbl {
- struct hosttbl *h_bak; /* hash chain */
- struct hosttbl *h_fwd;
- struct hosttbl *l_bak; /* "sequential" list */
- struct hosttbl *l_fwd;
- struct netinfo *ntp;
- struct sockaddr_in addr;
- char name[MAXHOSTNAMELEN+1];
- u_char head; /* 1=head of hash chain */
- u_char good; /* 0=trusted host, for averaging */
- u_char noanswer; /* count of failures to answer */
- u_char need_set; /* need a SETTIME */
- u_short seq;
- long delta;
-};
-
-/* closed hash table with internal chaining */
-extern struct hosttbl hosttbl[NHOSTS+1];
-#define self hosttbl[0]
-#define hostname (self.name)
-
-volatile sig_atomic_t gotintr;
-
-struct netinfo {
- struct netinfo *next;
- struct in_addr net;
- u_long mask;
- struct in_addr my_addr;
- struct sockaddr_in dest_addr; /* broadcast addr or point-point */
- long status;
- struct timeval slvwait; /* delay before sending our time */
- int quit_count; /* recent QUITs */
-};
-
-#include "timed-extern.h"
-
-#define tvtomsround(tv) ((tv).tv_sec*1000 + ((tv).tv_usec + 500)/1000)
-
-extern struct netinfo *nettab;
-extern int status;
-extern int trace;
-extern int sock;
-extern struct sockaddr_in from;
-extern struct timeval from_when; /* when the last msg arrived */
-extern u_short sequence; /* TSP message sequence number */
-extern struct netinfo *fromnet, *slavenet;
-extern FILE *fd;
-extern long delay2;
-extern int nslavenets; /* nets were I could be a slave */
-extern int nmasternets; /* nets were I could be a master */
-extern int nignorednets; /* ignored nets */
-extern int nnets; /* nets I am connected to */
-
-
-#define trace_msg(msg) {if (trace) fprintf(fd, msg);}
-
-#define trace_sendto_err(addr) { \
- int st_errno = errno; \
- syslog(LOG_ERR, "%s %d: sendto %s: %m", \
- __FILE__, __LINE__, inet_ntoa(addr)); \
- if (trace) \
- fprintf(fd, "%s %d: sendto %s: %d", __FILE__, __LINE__, \
- inet_ntoa(addr), st_errno); \
-}
-
-#define max(a, b) ((a) < (b) ? (b) : (a))
-#define min(a, b) ((a) > (b) ? (b) : (a))
-#define abs(x) ((x) >= 0 ? (x) : -(x))
diff --git a/usr.sbin/timed/timed/master.c b/usr.sbin/timed/timed/master.c
deleted file mode 100644
index b8bc29d7dd1..00000000000
--- a/usr.sbin/timed/timed/master.c
+++ /dev/null
@@ -1,833 +0,0 @@
-/* $OpenBSD: master.c,v 1.11 2011/03/19 23:40:11 okan Exp $ */
-
-/*-
- * Copyright (c) 1985, 1993 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include "globals.h"
-#include <sys/file.h>
-#include <sys/types.h>
-#include <sys/times.h>
-#include <setjmp.h>
-#include <util.h>
-#include <utmp.h>
-
-#include "pathnames.h"
-
-extern int measure_delta;
-extern jmp_buf jmpenv;
-extern int Mflag;
-extern int justquit;
-
-static int dictate;
-static int slvcount; /* slaves listening to our clock */
-
-static void mchgdate(struct tsp*);
-
-/*
- * The main function of `master' is to periodically compute the differences
- * (deltas) between its clock and the clocks of the slaves, to compute the
- * network average delta, and to send to the slaves the differences between
- * their individual deltas and the network delta.
- * While waiting, it receives messages from the slaves (i.e. requests for
- * master's name, remote requests to set the network time, ...), and
- * takes the appropriate action.
- */
-int
-master()
-{
- struct hosttbl *htp;
- long pollingtime;
-#define POLLRATE 4
- int polls;
- struct timeval wait, ntime;
- time_t tmpt;
- struct tsp *msg, *answer, to;
- char newdate[32];
- struct sockaddr_in taddr;
- char tname[MAXHOSTNAMELEN];
- struct netinfo *ntp;
- int i;
-
- syslog(LOG_NOTICE, "This machine is master");
- if (trace)
- fprintf(fd, "This machine is master\n");
- for (ntp = nettab; ntp != NULL; ntp = ntp->next) {
- if (ntp->status == MASTER)
- masterup(ntp);
- }
- (void)gettimeofday(&ntime, 0);
- pollingtime = ntime.tv_sec+3;
- if (justquit)
- polls = 0;
- else
- polls = POLLRATE-1;
-
-/* Process all outstanding messages before spending the long time necessary
- * to update all timers.
- */
-loop:
- (void)gettimeofday(&ntime, 0);
- wait.tv_sec = pollingtime - ntime.tv_sec;
- if (wait.tv_sec < 0)
- wait.tv_sec = 0;
- wait.tv_usec = 0;
- msg = readmsg(TSP_ANY, ANYADDR, &wait, 0);
- if (!msg) {
- (void)gettimeofday(&ntime, 0);
- if (ntime.tv_sec >= pollingtime) {
- pollingtime = ntime.tv_sec + SAMPLEINTVL;
- get_goodgroup(0);
-
-/* If a bogus master told us to quit, we can have decided to ignore a
- * network. Therefore, periodically try to take over everything.
- */
- polls = (polls + 1) % POLLRATE;
- if (0 == polls && nignorednets > 0) {
- trace_msg("Looking for nets to re-master\n");
- for (ntp = nettab; ntp; ntp = ntp->next) {
- if (ntp->status == IGNORE
- || ntp->status == NOMASTER) {
- lookformaster(ntp);
- if (ntp->status == MASTER) {
- masterup(ntp);
- polls = POLLRATE-1;
- }
- }
- if (ntp->status == MASTER
- && --ntp->quit_count < 0)
- ntp->quit_count = 0;
- }
- if (polls != 0)
- setstatus();
- }
-
- synch(0L);
-
- for (ntp = nettab; ntp != NULL; ntp = ntp->next) {
- to.tsp_type = TSP_LOOP;
- to.tsp_vers = TSPVERSION;
- to.tsp_seq = sequence++;
- to.tsp_hopcnt = MAX_HOPCNT;
- strlcpy(to.tsp_name, hostname,
- sizeof to.tsp_name);
- bytenetorder(&to);
- if (sendto(sock, (char *)&to,
- sizeof(struct tsp), 0,
- (struct sockaddr*)&ntp->dest_addr,
- sizeof(ntp->dest_addr)) < 0) {
- trace_sendto_err(ntp->dest_addr.sin_addr);
- }
- }
- }
-
-
- } else {
- switch (msg->tsp_type) {
-
- case TSP_MASTERREQ:
- break;
-
- case TSP_SLAVEUP:
- newslave(msg);
- break;
-
- case TSP_SETDATE:
- /*
- * XXX check to see it is from ourself
- */
- tmpt = msg->tsp_time.tv_sec;
- strlcpy(newdate, ctime(&tmpt), sizeof newdate);
- if (!good_host_name(msg->tsp_name)) {
- syslog(LOG_NOTICE,
- "attempted date change by %s to %s",
- msg->tsp_name, newdate);
- spreadtime();
- break;
- }
-
- mchgdate(msg);
- (void)gettimeofday(&ntime, 0);
- pollingtime = ntime.tv_sec + SAMPLEINTVL;
- break;
-
- case TSP_SETDATEREQ:
- if (!fromnet || fromnet->status != MASTER)
- break;
- tmpt = msg->tsp_time.tv_sec;
- strlcpy(newdate, ctime(&tmpt), sizeof newdate);
- htp = findhost(msg->tsp_name);
- if (htp == 0) {
- syslog(LOG_ERR,
- "attempted SET DATEREQ by uncontrolled %s to %s",
- msg->tsp_name, newdate);
- break;
- }
- if (htp->seq == msg->tsp_seq)
- break;
- htp->seq = msg->tsp_seq;
- if (!htp->good) {
- syslog(LOG_NOTICE,
- "attempted SET DATEREQ by untrusted %s to %s",
- msg->tsp_name, newdate);
- spreadtime();
- break;
- }
-
- mchgdate(msg);
- (void)gettimeofday(&ntime, 0);
- pollingtime = ntime.tv_sec + SAMPLEINTVL;
- break;
-
- case TSP_MSITE:
- xmit(TSP_ACK, msg->tsp_seq, &from);
- break;
-
- case TSP_MSITEREQ:
- break;
-
- case TSP_TRACEON:
- traceon();
- break;
-
- case TSP_TRACEOFF:
- traceoff("Tracing ended at %s\n");
- break;
-
- case TSP_ELECTION:
- if (!fromnet)
- break;
- if (fromnet->status == MASTER) {
- pollingtime = 0;
- (void)addmach(msg->tsp_name, &from,fromnet);
- }
- taddr = from;
- strlcpy(tname, msg->tsp_name, sizeof tname);
- to.tsp_type = TSP_QUIT;
- strlcpy(to.tsp_name, hostname, sizeof to.tsp_name);
- answer = acksend(&to, &taddr, tname,
- TSP_ACK, 0, 1);
- if (answer == NULL) {
- syslog(LOG_ERR, "election error by %s",
- tname);
- }
- break;
-
- case TSP_CONFLICT:
- /*
- * After a network partition, there can be
- * more than one master: the first slave to
- * come up will notify here the situation.
- */
- if (!fromnet || fromnet->status != MASTER)
- break;
- strlcpy(to.tsp_name, hostname, sizeof to.tsp_name);
-
- /* The other master often gets into the same state,
- * with boring results if we stay at it forever.
- */
- ntp = fromnet; /* (acksend() can leave fromnet=0 */
- for (i = 0; i < 3; i++) {
- to.tsp_type = TSP_RESOLVE;
- strlcpy(to.tsp_name, hostname,
- sizeof to.tsp_name);
- answer = acksend(&to, &ntp->dest_addr,
- ANYADDR, TSP_MASTERACK,
- ntp, 0);
- if (!answer)
- break;
- htp = addmach(answer->tsp_name,&from,ntp);
- to.tsp_type = TSP_QUIT;
- msg = acksend(&to, &htp->addr, htp->name,
- TSP_ACK, 0, htp->noanswer);
- if (msg == NULL) {
- syslog(LOG_ERR,
- "no response from %s to CONFLICT-QUIT",
- htp->name);
- }
- }
- masterup(ntp);
- pollingtime = 0;
- break;
-
- case TSP_RESOLVE:
- if (!fromnet || fromnet->status != MASTER)
- break;
- /*
- * do not want to call synch() while waiting
- * to be killed!
- */
- (void)gettimeofday(&ntime, (struct timezone *)0);
- pollingtime = ntime.tv_sec + SAMPLEINTVL;
- break;
-
- case TSP_QUIT:
- doquit(msg); /* become a slave */
- break;
-
- case TSP_LOOP:
- if (!fromnet || fromnet->status != MASTER
- || !strcmp(msg->tsp_name, hostname))
- break;
- /*
- * We should not have received this from a net
- * we are master on. There must be two masters.
- */
- htp = addmach(msg->tsp_name, &from,fromnet);
- to.tsp_type = TSP_QUIT;
- strlcpy(to.tsp_name, hostname, sizeof to.tsp_name);
- answer = acksend(&to, &htp->addr, htp->name,
- TSP_ACK, 0, 1);
- if (!answer) {
- syslog(LOG_WARNING,
- "loop breakage: no reply from %s=%s to QUIT",
- htp->name, inet_ntoa(htp->addr.sin_addr));
- (void)remmach(htp);
- }
-
- case TSP_TEST:
- if (trace) {
- fprintf(fd,
- "\tnets = %d, masters = %d, slaves = %d, ignored = %d\n",
- nnets, nmasternets, nslavenets, nignorednets);
- setstatus();
- }
- pollingtime = 0;
- polls = POLLRATE-1;
- break;
-
- default:
- if (trace) {
- fprintf(fd, "garbage message: ");
- print(msg, &from);
- }
- break;
- }
- }
- goto loop;
-}
-
-
-/*
- * change the system date on the master
- */
-static void
-mchgdate(struct tsp *msg)
-{
- char tname[MAXHOSTNAMELEN];
- char olddate[32];
- struct timeval otime, ntime, tmptv;
-
- strlcpy(tname, msg->tsp_name, sizeof tname);
-
- xmit(TSP_DATEACK, msg->tsp_seq, &from);
-
- strlcpy(olddate, date(), sizeof olddate);
-
- /* adjust time for residence on the queue */
- (void)gettimeofday(&otime, 0);
- adj_msg_time(msg,&otime);
-
- timersub(&msg->tsp_time, &otime, &ntime);
- if (ntime.tv_sec < MAXADJ && ntime.tv_sec > -MAXADJ) {
- /*
- * do not change the clock if we can adjust it
- */
- dictate = 3;
- synch(tvtomsround(ntime));
- } else {
- logwtmp("|", "date", "");
- tmptv.tv_sec = msg->tsp_time.tv_sec;
- tmptv.tv_usec = msg->tsp_time.tv_usec;
- (void)settimeofday(&tmptv, 0);
- logwtmp("{", "date", "");
- spreadtime();
- }
-
- syslog(LOG_NOTICE, "date changed by %s from %s",
- tname, olddate);
-}
-
-
-/*
- * synchronize all of the slaves
- */
-void
-synch(long mydelta)
-{
- struct hosttbl *htp;
- int measure_status;
- struct timeval check, stop, wait;
-
- if (slvcount > 0) {
- if (trace)
- fprintf(fd, "measurements starting at %s\n", date());
- (void)gettimeofday(&check, 0);
- for (htp = self.l_fwd; htp != &self; htp = htp->l_fwd) {
- if (htp->noanswer != 0) {
- measure_status = measure(500, 100,
- htp->name,
- &htp->addr,0);
- } else {
- measure_status = measure(3000, 100,
- htp->name,
- &htp->addr,0);
- }
- if (measure_status != GOOD) {
- /* The slave did not respond. We have
- * just wasted lots of time on it.
- */
- htp->delta = HOSTDOWN;
- if (++htp->noanswer >= LOSTHOST) {
- if (trace) {
- fprintf(fd,
- "purging %s for not answering ICMP\n",
- htp->name);
- (void)fflush(fd);
- }
- htp = remmach(htp);
- }
- } else {
- htp->delta = measure_delta;
- }
- (void)gettimeofday(&stop, 0);
- timersub(&stop, &check, &stop);
- if (stop.tv_sec >= 1) {
- if (trace)
- (void)fflush(fd);
- /*
- * ack messages periodically
- */
- timerclear(&wait);
- if (0 != readmsg(TSP_TRACEON,ANYADDR,
- &wait,0))
- traceon();
- (void)gettimeofday(&check, 0);
- }
- }
- if (trace)
- fprintf(fd, "measurements finished at %s\n", date());
- }
- if (!(status & SLAVE)) {
- if (!dictate) {
- mydelta = networkdelta();
- } else {
- dictate--;
- }
- }
- if (trace && (mydelta != 0 || (status & SLAVE)))
- fprintf(fd,"local correction of %ld ms.\n", mydelta);
- correct(mydelta);
-}
-
-/*
- * sends the time to each slave after the master
- * has received the command to set the network time
- */
-void
-spreadtime()
-{
- struct hosttbl *htp;
- struct tsp to;
- struct tsp *answer;
- struct timeval tmptv;
-
-/* Do not listen to the consensus after forcing the time. This is because
- * the consensus takes a while to reach the time we are dictating.
- */
- dictate = 2;
- for (htp = self.l_fwd; htp != &self; htp = htp->l_fwd) {
- to.tsp_type = TSP_SETTIME;
- strlcpy(to.tsp_name, hostname, sizeof to.tsp_name);
- (void)gettimeofday(&tmptv, 0);
- to.tsp_time.tv_sec = tmptv.tv_sec;
- to.tsp_time.tv_usec = tmptv.tv_usec;
- answer = acksend(&to, &htp->addr, htp->name,
- TSP_ACK, 0, htp->noanswer);
- if (answer == 0) {
- /* We client does not respond, then we have
- * just wasted lots of time on it.
- */
- syslog(LOG_WARNING,
- "no reply to SETTIME from %s", htp->name);
- if (++htp->noanswer >= LOSTHOST) {
- if (trace) {
- fprintf(fd,
- "purging %s for not answering",
- htp->name);
- (void)fflush(fd);
- }
- htp = remmach(htp);
- }
- }
- }
-}
-
-
-void
-prthp(clock_t delta)
-{
- static time_t next_time;
- time_t this_time;
- struct tms tm;
- struct hosttbl *htp;
- int length, l;
- int i;
-
- if (!fd) /* quit if tracing already off */
- return;
-
- this_time = times(&tm);
- if (this_time + delta < next_time)
- return;
- next_time = this_time + CLK_TCK;
-
- fprintf(fd, "host table: %d entries at %s\n", slvcount, date());
- htp = self.l_fwd;
- length = 1;
- for (i = 1; i <= slvcount; i++, htp = htp->l_fwd) {
- l = strlen(htp->name) + 1;
- if (length+l >= 80) {
- fprintf(fd, "\n");
- length = 0;
- }
- length += l;
- fprintf(fd, " %s", htp->name);
- }
- fprintf(fd, "\n");
-}
-
-
-static struct hosttbl *newhost_hash;
-static struct hosttbl *lasthfree = &hosttbl[0];
-
-
-struct hosttbl * /* answer or 0 */
-findhost(char *name)
-{
- int i, j;
- struct hosttbl *htp;
- char *p;
-
- j= 0;
- for (p = name, i = 0; i < 8 && *p != '\0'; i++, p++)
- j = (j << 2) ^ *p;
- newhost_hash = &hosttbl[j % NHOSTS];
-
- htp = newhost_hash;
- if (htp->name[0] == '\0')
- return(0);
- do {
- if (!strcmp(name, htp->name))
- return(htp);
- htp = htp->h_fwd;
- } while (htp != newhost_hash);
- return(0);
-}
-
-/*
- * add a host to the list of controlled machines if not already there
- */
-struct hosttbl *
-addmach(char *name, struct sockaddr_in *addr, struct netinfo *ntp)
-{
- struct hosttbl *ret, *p, *b, *f;
-
- ret = findhost(name);
- if (ret == 0) {
- if (slvcount >= NHOSTS) {
- if (trace) {
- fprintf(fd, "no more slots in host table\n");
- prthp(CLK_TCK);
- }
- syslog(LOG_ERR, "no more slots in host table");
- Mflag = 0;
- longjmp(jmpenv, 2); /* give up and be a slave */
- }
-
- /* if our home hash slot is occupied, find a free entry
- * in the hash table
- */
- if (newhost_hash->name[0] != '\0') {
- do {
- ret = lasthfree;
- if (++lasthfree > &hosttbl[NHOSTS])
- lasthfree = &hosttbl[1];
- } while (ret->name[0] != '\0');
-
- if (!newhost_hash->head) {
- /* Move an interloper using our home. Use
- * scratch pointers in case the new head is
- * pointing to itself.
- */
- f = newhost_hash->h_fwd;
- b = newhost_hash->h_bak;
- f->h_bak = ret;
- b->h_fwd = ret;
- f = newhost_hash->l_fwd;
- b = newhost_hash->l_bak;
- f->l_bak = ret;
- b->l_fwd = ret;
- bcopy(newhost_hash,ret,sizeof(*ret));
- ret = newhost_hash;
- ret->head = 1;
- ret->h_fwd = ret;
- ret->h_bak = ret;
- } else {
- /* link to an existing chain in our home
- */
- ret->head = 0;
- p = newhost_hash->h_bak;
- ret->h_fwd = newhost_hash;
- ret->h_bak = p;
- p->h_fwd = ret;
- newhost_hash->h_bak = ret;
- }
- } else {
- ret = newhost_hash;
- ret->head = 1;
- ret->h_fwd = ret;
- ret->h_bak = ret;
- }
- ret->addr = *addr;
- ret->ntp = ntp;
- (void)strncpy(ret->name, name, sizeof(ret->name));
- ret->good = good_host_name(name);
- ret->l_fwd = &self;
- ret->l_bak = self.l_bak;
- self.l_bak->l_fwd = ret;
- self.l_bak = ret;
- slvcount++;
-
- ret->noanswer = 0;
- ret->need_set = 1;
-
- } else {
- ret->noanswer = (ret->noanswer != 0);
- }
-
- /* need to clear sequence number anyhow */
- ret->seq = 0;
- return(ret);
-}
-
-/*
- * remove the machine with the given index in the host table.
- */
-struct hosttbl *
-remmach(struct hosttbl *htp)
-{
- struct hosttbl *lprv, *hnxt, *f, *b;
-
- if (trace)
- fprintf(fd, "remove %s\n", htp->name);
-
- /* get out of the lists */
- htp->l_fwd->l_bak = lprv = htp->l_bak;
- htp->l_bak->l_fwd = htp->l_fwd;
- htp->h_fwd->h_bak = htp->h_bak;
- htp->h_bak->h_fwd = hnxt = htp->h_fwd;
-
- /* If we are in the home slot, pull up the chain */
- if (htp->head && hnxt != htp) {
- if (lprv == hnxt)
- lprv = htp;
-
- /* Use scratch pointers in case the new head is pointing to
- * itself.
- */
- f = hnxt->h_fwd;
- b = hnxt->h_bak;
- f->h_bak = htp;
- b->h_fwd = htp;
- f = hnxt->l_fwd;
- b = hnxt->l_bak;
- f->l_bak = htp;
- b->l_fwd = htp;
- hnxt->head = 1;
- bcopy(hnxt, htp, sizeof(*htp));
- lasthfree = hnxt;
- } else {
- lasthfree = htp;
- }
-
- lasthfree->name[0] = '\0';
- lasthfree->h_fwd = 0;
- lasthfree->l_fwd = 0;
- slvcount--;
-
- return lprv;
-}
-
-
-/*
- * Remove all the machines from the host table that exist on the given
- * network. This is called when a master transitions to a slave on a
- * given network.
- */
-void
-rmnetmachs(struct netinfo *ntp)
-{
- struct hosttbl *htp;
-
- if (trace)
- prthp(CLK_TCK);
- for (htp = self.l_fwd; htp != &self; htp = htp->l_fwd) {
- if (ntp == htp->ntp)
- htp = remmach(htp);
- }
- if (trace)
- prthp(CLK_TCK);
-}
-
-
-void
-masterup(struct netinfo *net)
-{
- xmit(TSP_MASTERUP, 0, &net->dest_addr);
-
- /*
- * Do not tell new slaves our time for a while. This ensures
- * we do not tell them to start using our time, before we have
- * found a good master.
- */
- (void)gettimeofday(&net->slvwait, 0);
-}
-
-void
-newslave(struct tsp *msg)
-{
- struct hosttbl *htp;
- struct tsp *answer, to;
- struct timeval now, tmptv;
-
- if (!fromnet || fromnet->status != MASTER)
- return;
-
- htp = addmach(msg->tsp_name, &from,fromnet);
- htp->seq = msg->tsp_seq;
- if (trace)
- prthp(0);
-
- /*
- * If we are stable, send our time to the slave.
- * Do not go crazy if the date has been changed.
- */
- (void)gettimeofday(&now, 0);
- if (now.tv_sec >= fromnet->slvwait.tv_sec+3
- || now.tv_sec < fromnet->slvwait.tv_sec) {
- to.tsp_type = TSP_SETTIME;
- strlcpy(to.tsp_name, hostname, sizeof to.tsp_name);
- (void)gettimeofday(&tmptv, 0);
- to.tsp_time.tv_sec = tmptv.tv_sec;
- to.tsp_time.tv_usec = tmptv.tv_usec;
- answer = acksend(&to, &htp->addr,
- htp->name, TSP_ACK,
- 0, htp->noanswer);
- if (answer) {
- htp->need_set = 0;
- } else {
- syslog(LOG_WARNING,
- "no reply to initial SETTIME from %s",
- htp->name);
- htp->noanswer = LOSTHOST;
- }
- }
-}
-
-
-/*
- * react to a TSP_QUIT:
- */
-void
-doquit(struct tsp *msg)
-{
- if (fromnet->status == MASTER) {
- if (!good_host_name(msg->tsp_name)) {
- if (fromnet->quit_count <= 0) {
- syslog(LOG_NOTICE,"untrusted %s told us QUIT",
- msg->tsp_name);
- suppress(&from, msg->tsp_name, fromnet);
- fromnet->quit_count = 1;
- return;
- }
- syslog(LOG_NOTICE, "untrusted %s told us QUIT twice",
- msg->tsp_name);
- fromnet->quit_count = 2;
- fromnet->status = NOMASTER;
- } else {
- fromnet->status = SLAVE;
- }
- rmnetmachs(fromnet);
- longjmp(jmpenv, 2); /* give up and be a slave */
-
- } else {
- if (!good_host_name(msg->tsp_name)) {
- syslog(LOG_NOTICE, "untrusted %s told us QUIT",
- msg->tsp_name);
- fromnet->quit_count = 2;
- }
- }
-}
-
-void
-traceon(void)
-{
- if (!fd) {
- fd = fopen(_PATH_TIMEDLOG, "w");
- if (!fd) {
- trace = 0;
- return;
- }
- fprintf(fd,"Tracing started at %s\n", date());
- }
- trace = 1;
- get_goodgroup(1);
- setstatus();
- prthp(CLK_TCK);
-}
-
-
-void
-traceoff(const char *msg)
-{
- get_goodgroup(1);
- setstatus();
- prthp(CLK_TCK);
- if (trace) {
- fprintf(fd, msg, date());
- (void)fclose(fd);
- fd = NULL;
- }
-#ifdef GPROF
- moncontrol(0);
- _mcleanup();
- moncontrol(1);
-#endif
- trace = 0;
-}
diff --git a/usr.sbin/timed/timed/measure.c b/usr.sbin/timed/timed/measure.c
deleted file mode 100644
index 34fbf792694..00000000000
--- a/usr.sbin/timed/timed/measure.c
+++ /dev/null
@@ -1,314 +0,0 @@
-/* $OpenBSD: measure.c,v 1.14 2009/10/27 23:59:57 deraadt Exp $ */
-
-/*-
- * Copyright (c) 1985, 1993 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include "globals.h"
-#include <netinet/in_systm.h>
-#include <netinet/ip.h>
-#include <netinet/ip_icmp.h>
-#include <signal.h>
-#include <poll.h>
-
-#define MSEC_DAY (SECDAY*1000)
-
-#define PACKET_IN 1024
-
-#define MSGS 5 /* timestamps to average */
-#define TRIALS 10 /* max # of timestamps sent */
-
-extern int sock_raw;
-
-int measure_delta;
-
-extern int in_cksum(u_short*, int);
-
-static n_short seqno = 0;
-
-/*
- * Measures the differences between machines' clocks using
- * ICMP timestamp messages.
- */
-int /* status val defined in globals.h */
-measure(u_long maxmsec, u_long wmsec, char *hname, struct sockaddr_in *addr,
- int print)
-{
- socklen_t length;
- int measure_status;
- int rcvcount, trials;
- int cc, count;
- struct pollfd pfd[1];
- long sendtime, recvtime, histime1, histime2;
- long idelta, odelta, total;
- long min_idelta, min_odelta;
- struct timeval tdone, tcur, ttrans, twait, tout;
- u_char packet[PACKET_IN], opacket[64];
- struct icmp *icp = (struct icmp *) packet;
- struct icmp *oicp = (struct icmp *) opacket;
- struct ip *ip = (struct ip *) packet;
-
- min_idelta = min_odelta = 0x7fffffff;
- measure_status = HOSTDOWN;
- measure_delta = HOSTDOWN;
- trials = 0;
- errno = 0;
-
- /* open raw socket used to measure time differences */
- if (sock_raw < 0) {
- sock_raw = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
- if (sock_raw < 0) {
- syslog(LOG_ERR, "opening raw socket: %m");
- goto quit;
- }
- }
-
- /*
- * empty the icmp input queue
- */
- pfd[0].fd = sock_raw;
- pfd[0].events = POLLIN;
- for (;;) {
- if (poll(pfd, 1, 0)) {
- length = sizeof(struct sockaddr_in);
- siginterrupt(SIGINT, 1);
- cc = recvfrom(sock_raw, (char *)packet, PACKET_IN, 0,
- 0, &length);
- if (cc < 0) {
- if (errno == EINTR && gotintr)
- goto bail;
- siginterrupt(SIGINT, 0);
- goto quit;
- }
- siginterrupt(SIGINT, 0);
- continue;
- }
- break;
- }
-
- /*
- * Choose the smallest transmission time in each of the two
- * directions. Use these two latter quantities to compute the delta
- * between the two clocks.
- */
-
- oicp->icmp_type = ICMP_TSTAMP;
- oicp->icmp_code = 0;
- oicp->icmp_id = getpid();
- oicp->icmp_rtime = 0;
- oicp->icmp_ttime = 0;
- oicp->icmp_seq = seqno;
-
- (void)gettimeofday(&tdone, 0);
- mstotvround(&tout, maxmsec);
- timeradd(&tdone, &tout, &tdone); /* when we give up */
-
- mstotvround(&twait, wmsec);
-
- rcvcount = 0;
- trials = 0;
- while (rcvcount < MSGS) {
- (void)gettimeofday(&tcur, 0);
-
- /*
- * keep sending until we have sent the max
- */
- if (trials < TRIALS) {
- trials++;
- oicp->icmp_otime = htonl((tcur.tv_sec % SECDAY) * 1000
- + tcur.tv_usec / 1000);
- oicp->icmp_cksum = 0;
- oicp->icmp_cksum = in_cksum((u_short*)oicp,
- sizeof(*oicp));
-
- siginterrupt(SIGINT, 1);
- count = sendto(sock_raw, opacket, sizeof(*oicp), 0,
- (struct sockaddr*)addr,
- sizeof(struct sockaddr));
- if (count < 0) {
- if (errno == EINTR && gotintr)
- goto bail;
- siginterrupt(SIGINT, 0);
- if (measure_status == HOSTDOWN)
- measure_status = UNREACHABLE;
- goto quit;
- }
- siginterrupt(SIGINT, 0);
- ++oicp->icmp_seq;
-
- timeradd(&tcur, &twait, &ttrans);
- } else {
- ttrans = tdone;
- }
-
- while (rcvcount < trials) {
- timersub(&ttrans, &tcur, &tout);
- if (tout.tv_sec < 0)
- tout.tv_sec = 0;
-
- count = poll(pfd, 1,
- tout.tv_sec * 1000 + tout.tv_usec / 1000);
- (void)gettimeofday(&tcur, (struct timezone *)0);
- if (count <= 0)
- break;
-
- length = sizeof(struct sockaddr_in);
- siginterrupt(SIGINT, 1);
- cc = recvfrom(sock_raw, (char *)packet, PACKET_IN, 0,
- 0,&length);
- if (cc < 0) {
- if (errno == EINTR && gotintr)
- goto bail;
- siginterrupt(SIGINT, 0);
- goto quit;
- }
- siginterrupt(SIGINT, 0);
-
- /*
- * got something. See if it is ours
- */
- icp = (struct icmp *)(packet + (ip->ip_hl << 2));
- if (cc < sizeof(*ip)
- || icp->icmp_type != ICMP_TSTAMPREPLY
- || icp->icmp_id != oicp->icmp_id
- || icp->icmp_seq < seqno
- || icp->icmp_seq >= oicp->icmp_seq)
- continue;
-
- sendtime = ntohl(icp->icmp_otime);
- recvtime = ((tcur.tv_sec % SECDAY) * 1000 +
- tcur.tv_usec / 1000);
-
- total = recvtime-sendtime;
- if (total < 0) /* do not hassle midnight */
- continue;
-
- rcvcount++;
- histime1 = ntohl(icp->icmp_rtime);
- histime2 = ntohl(icp->icmp_ttime);
- /*
- * a host using a time format different from
- * msec. since midnight UT (as per RFC792) should
- * set the high order bit of the 32-bit time
- * value it transmits.
- */
- if ((histime1 & 0x80000000) != 0) {
- measure_status = NONSTDTIME;
- goto quit;
- }
- measure_status = GOOD;
-
- idelta = recvtime-histime2;
- odelta = histime1-sendtime;
-
- /* do not be confused by midnight */
- if (idelta < -MSEC_DAY/2) idelta += MSEC_DAY;
- else if (idelta > MSEC_DAY/2) idelta -= MSEC_DAY;
-
- if (odelta < -MSEC_DAY/2) odelta += MSEC_DAY;
- else if (odelta > MSEC_DAY/2) odelta -= MSEC_DAY;
-
- /* save the quantization error so that we can get a
- * measurement finer than our system clock.
- */
- if (total < MIN_ROUND) {
- measure_delta = (odelta - idelta)/2;
- goto quit;
- }
-
- if (idelta < min_idelta)
- min_idelta = idelta;
- if (odelta < min_odelta)
- min_odelta = odelta;
-
- measure_delta = (min_odelta - min_idelta)/2;
- }
-
- if (tcur.tv_sec > tdone.tv_sec
- || (tcur.tv_sec == tdone.tv_sec
- && tcur.tv_usec >= tdone.tv_usec))
- break;
- }
-
-quit:
- seqno += TRIALS; /* allocate our sequence numbers */
-
- /*
- * If no answer is received for TRIALS consecutive times,
- * the machine is assumed to be down
- */
- if (measure_status == GOOD) {
- if (trace) {
- fprintf(fd,
- "measured delta %4d, %d trials to %-15s %s\n",
- measure_delta, trials,
- inet_ntoa(addr->sin_addr), hname);
- }
- } else if (print) {
- if (errno != 0)
- fprintf(stderr, "measure %s: %s\n", hname,
- strerror(errno));
- } else {
- if (errno != 0) {
- syslog(LOG_ERR, "measure %s: %m", hname);
- } else {
- syslog(LOG_ERR, "measure: %s did not respond", hname);
- }
- if (trace) {
- fprintf(fd,
- "measure: %s failed after %d trials\n",
- hname, trials);
- (void)fflush(fd);
- }
- }
-
- return(measure_status);
-bail:
- siginterrupt(SIGINT, 0);
- return (0);
-}
-
-/*
- * round a number of milliseconds into a struct timeval
- */
-void
-mstotvround(struct timeval *res, long x)
-{
- if (x < 0)
- x = -((-x + 3)/5);
- else
- x = (x+3)/5;
- x *= 5;
-
- res->tv_sec = x/1000;
- res->tv_usec = (x-res->tv_sec*1000)*1000;
- if (res->tv_usec < 0) {
- res->tv_usec += 1000000;
- res->tv_sec--;
- }
-}
diff --git a/usr.sbin/timed/timed/networkdelta.c b/usr.sbin/timed/timed/networkdelta.c
deleted file mode 100644
index 8962d55cba8..00000000000
--- a/usr.sbin/timed/timed/networkdelta.c
+++ /dev/null
@@ -1,250 +0,0 @@
-/* $OpenBSD: networkdelta.c,v 1.8 2009/10/27 23:59:57 deraadt Exp $ */
-
-/*-
- * Copyright (c) 1985, 1993 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include "globals.h"
-
-static long median(float, float*, long*, long*, unsigned int);
-
-/*
- * Compute a corrected date.
- * Compute the median of the reasonable differences. First compute
- * the median of all authorized differences, and then compute the
- * median of all differences that are reasonably close to the first
- * median.
- *
- * This differs from the original BSD implementation, which looked for
- * the largest group of machines with essentially the same date.
- * That assumed that machines with bad clocks would be uniformly
- * distributed. Unfortunately, in real life networks, the distribution
- * of machines is not uniform among models of machines, and the
- * distribution of errors in clocks tends to be quite consistent
- * for a given model. In other words, all model VI Supre Servres
- * from GoFast Inc. tend to have about the same error.
- * The original BSD implementation would chose the clock of the
- * most common model, and discard all others.
- *
- * Therefore, get best we can do is to try to average over all
- * of the machines in the network, while discarding "obviously"
- * bad values.
- */
-long
-networkdelta(void)
-{
- struct hosttbl *htp;
- long med;
- long lodelta, hidelta;
- long logood, higood;
- long x[NHOSTS];
- long *xp;
- int numdelta;
- float eps;
-
- /*
- * compute the median of the good values
- */
- med = 0;
- numdelta = 1;
- xp = &x[0];
- *xp = 0; /* account for ourself */
- for (htp = self.l_fwd; htp != &self; htp = htp->l_fwd) {
- if (htp->good
- && htp->noanswer == 0
- && htp->delta != HOSTDOWN) {
- med += htp->delta;
- numdelta++;
- *++xp = htp->delta;
- }
- }
-
- /*
- * If we are the only trusted time keeper, then do not change our
- * clock. There may be another time keeping service active.
- */
- if (numdelta == 1)
- return 0;
-
- med /= numdelta;
- eps = med - x[0];
- if (trace)
- fprintf(fd, "median of %d values starting at %ld is about ",
- numdelta, med);
- med = median(med, &eps, &x[0], xp+1, VALID_RANGE);
-
- /*
- * compute the median of all values near the good median
- */
- hidelta = med + GOOD_RANGE;
- lodelta = med - GOOD_RANGE;
- higood = med + VGOOD_RANGE;
- logood = med - VGOOD_RANGE;
- xp = &x[0];
- htp = &self;
- do {
- if (htp->noanswer == 0
- && htp->delta >= lodelta
- && htp->delta <= hidelta
- && (htp->good
- || (htp->delta >= logood
- && htp->delta <= higood))) {
- *xp++ = htp->delta;
- }
- } while (&self != (htp = htp->l_fwd));
-
- if (xp == &x[0]) {
- if (trace)
- fprintf(fd, "nothing close to median %ld\n", med);
- return med;
- }
-
- if (xp == &x[1]) {
- if (trace)
- fprintf(fd, "only value near median is %ld\n", x[0]);
- return x[0];
- }
-
- if (trace)
- fprintf(fd, "median of %d values starting at %ld is ",
- xp-&x[0], med);
- return median(med, &eps, &x[0], xp, 1);
-}
-
-
-/*
- * compute the median of an array of signed integers, using the idea
- * in <<Numerical Recipes>>.
- */
-static long
-median(float a, float *eps_ptr, long *x, long *xlim, unsigned int gnuf)
-{
- long *xptr;
- float ap = LONG_MAX; /* bounds on the median */
- float am = -LONG_MAX;
- float aa;
- int npts; /* # of points above & below guess */
- float xp; /* closet point above the guess */
- float xm; /* closet point below the guess */
- float eps;
- float dum, sum, sumx;
- int pass;
-#define AMP 1.5 /* smoothing constants */
-#define AFAC 1.5
-
- eps = *eps_ptr;
- if (eps < 1.0) {
- eps = -eps;
- if (eps < 1.0)
- eps = 1.0;
- }
-
- for (pass = 1; ; pass++) { /* loop over the data */
- sum = 0.0;
- sumx = 0.0;
- npts = 0;
- xp = LONG_MAX;
- xm = -LONG_MAX;
-
- for (xptr = x; xptr != xlim; xptr++) {
- float xx = *xptr;
-
- dum = xx - a;
- if (dum != 0.0) { /* avoid dividing by 0 */
- if (dum > 0.0) {
- npts++;
- if (xx < xp)
- xp = xx;
- } else {
- npts--;
- if (xx > xm)
- xm = xx;
- dum = -dum;
- }
- dum = 1.0/(eps + dum);
- sum += dum;
- sumx += xx * dum;
- }
- }
-
- if (ap-am < gnuf || sum == 0) {
- if (trace)
- fprintf(fd,
- "%ld in %d passes; early out balance=%d\n",
- (long)a, pass, npts);
- return a; /* guess was good enough */
- }
-
- aa = (sumx/sum-a)*AMP;
- if (npts >= 2) { /* guess was too low */
- am = a;
- aa = xp + max(0.0, aa);
- if (aa > ap)
- aa = (a + ap)/2;
-
- } else if (npts <= -2) { /* guess was two high */
- ap = a;
- aa = xm + min(0.0, aa);
- if (aa < am)
- aa = (a + am)/2;
-
- } else {
- break; /* got it */
- }
-
- if (a == aa) {
- if (trace)
- fprintf(fd,
- "%ld in %d passes; force out balance=%d\n",
- (long)a, pass, npts);
- return a;
- }
- eps = AFAC*abs(aa - a);
- *eps_ptr = eps;
- a = aa;
- }
-
- if (((x - xlim) % 2) != 0) { /* even number of points? */
- if (npts == 0) /* yes, return an average */
- a = (xp+xm)/2;
- else if (npts > 0)
- a = (a+xp)/2;
- else
- a = (xm+a)/2;
-
- } else if (npts != 0) { /* odd number of points */
- if (npts > 0)
- a = xp;
- else
- a = xm;
- }
-
- if (trace)
- fprintf(fd, "%ld in %d passes\n", (long)a, pass);
- return a;
-}
diff --git a/usr.sbin/timed/timed/pathnames.h b/usr.sbin/timed/timed/pathnames.h
deleted file mode 100644
index 8498c4e9d02..00000000000
--- a/usr.sbin/timed/timed/pathnames.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/* $OpenBSD: pathnames.h,v 1.4 2003/06/02 23:36:55 millert Exp $ */
-
-/*-
- * Copyright (c) 1985 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)pathnames.h 5.6 (Berkeley) 5/11/93
- */
-
-#include <paths.h>
-
-#define _PATH_MASTERLOG "/var/log/timed.masterlog"
-#define _PATH_TIMEDLOG "/var/log/timed.log"
diff --git a/usr.sbin/timed/timed/readmsg.c b/usr.sbin/timed/timed/readmsg.c
deleted file mode 100644
index c7f4ee8b506..00000000000
--- a/usr.sbin/timed/timed/readmsg.c
+++ /dev/null
@@ -1,496 +0,0 @@
-/* $OpenBSD: readmsg.c,v 1.17 2011/03/19 23:40:11 okan Exp $ */
-
-/*-
- * Copyright (c) 1985, 1993 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include "globals.h"
-
-extern char *tsptype[];
-
-/*
- * LOOKAT checks if the message is of the requested type and comes from
- * the right machine, returning 1 in case of affirmative answer
- */
-#define LOOKAT(msg, mtype, mfrom, netp, froms) \
- (((mtype) == TSP_ANY || (mtype) == (msg).tsp_type) && \
- ((mfrom) == 0 || !strcmp((mfrom), (msg).tsp_name)) && \
- ((netp) == 0 || \
- ((netp)->mask & (froms).sin_addr.s_addr) == (netp)->net.s_addr))
-
-struct timeval rtime, rwait, rtout;
-struct tsp msgin;
-static struct tsplist {
- struct tsp info;
- struct timeval when;
- struct sockaddr_in addr;
- struct tsplist *p;
-} msgslist;
-struct sockaddr_in from;
-struct netinfo *fromnet;
-struct timeval from_when;
-
-/*
- * `readmsg' returns message `type' sent by `machfrom' if it finds it
- * either in the receive queue, or in a linked list of previously received
- * messages that it maintains.
- * Otherwise it waits to see if the appropriate message arrives within
- * `intvl' seconds. If not, it returns NULL.
- */
-
-struct tsp *
-readmsg(int type, char *machfrom, struct timeval *intvl,
- struct netinfo *netfrom)
-{
- int length;
- socklen_t salength;
- struct pollfd pfd[1];
- static struct tsplist *head = &msgslist;
- static struct tsplist *tail = &msgslist;
- static int msgcnt = 0;
- struct tsplist *prev;
- struct netinfo *ntp;
- struct tsplist *ptr;
- ssize_t n;
-
- if (trace) {
- fprintf(fd, "readmsg: looking for %s from %s, %s\n",
- tsptype[type], machfrom == NULL ? "ANY" : machfrom,
- netfrom == NULL ? "ANYNET" : inet_ntoa(netfrom->net));
- if (head->p != 0) {
- length = 1;
- for (ptr = head->p; ptr != 0; ptr = ptr->p) {
- /* do not repeat the hundreds of messages */
- if (++length > 3) {
- if (ptr == tail) {
- fprintf(fd,"\t ...%d skipped\n",
- length);
- } else {
- continue;
- }
- }
- fprintf(fd, length > 1 ? "\t" : "queue:\t");
- print(&ptr->info, &ptr->addr);
- }
- }
- }
-
- ptr = head->p;
- prev = head;
-
- /*
- * Look for the requested message scanning through the
- * linked list. If found, return it and free the space
- */
-
- while (ptr != NULL) {
- if (LOOKAT(ptr->info, type, machfrom, netfrom, ptr->addr)) {
-again:
- msgin = ptr->info;
- from = ptr->addr;
- from_when = ptr->when;
- prev->p = ptr->p;
- if (ptr == tail)
- tail = prev;
- free((char *)ptr);
- fromnet = NULL;
- if (netfrom == NULL)
- for (ntp = nettab; ntp != NULL; ntp = ntp->next) {
- if ((ntp->mask & from.sin_addr.s_addr) ==
- ntp->net.s_addr) {
- fromnet = ntp;
- break;
- }
- }
- else
- fromnet = netfrom;
- if (trace) {
- fprintf(fd, "readmsg: found ");
- print(&msgin, &from);
- }
-
-/* The protocol can get far behind. When it does, it gets
- * hopelessly confused. So delete duplicate messages.
- */
- for (ptr = prev; (ptr = ptr->p) != NULL; prev = ptr) {
- if (ptr->addr.sin_addr.s_addr
- == from.sin_addr.s_addr
- && ptr->info.tsp_type == msgin.tsp_type) {
- if (trace)
- fprintf(fd, "\tdup ");
- goto again;
- }
- }
- msgcnt--;
- return(&msgin);
- } else {
- prev = ptr;
- ptr = ptr->p;
- }
- }
-
- /*
- * If the message was not in the linked list, it may still be
- * coming from the network. Set the timer and wait
- * on a poll to read the next incoming message: if it is the
- * right one, return it, otherwise insert it in the linked list.
- */
-
- (void)gettimeofday(&rtout, 0);
- timeradd(&rtout, intvl, &rtout);
- for (;;) {
- (void)gettimeofday(&rtime, 0);
- timersub(&rtout, &rtime, &rwait);
- if (rwait.tv_sec < 0)
- timerclear(&rwait);
- else if (rwait.tv_sec == 0
- && rwait.tv_usec < 1000000/CLK_TCK)
- rwait.tv_usec = 1000000/CLK_TCK;
-
- if (trace) {
- fprintf(fd, "readmsg: wait %ld.%6ld at %s\n",
- rwait.tv_sec, rwait.tv_usec, date());
- /* Notice a full disk, as we flush trace info.
- * It is better to flush periodically than at
- * every line because the tracing consists of bursts
- * of many lines. Without care, tracing slows
- * down the code enough to break the protocol.
- */
- if (rwait.tv_sec != 0
- && EOF == fflush(fd))
- traceoff("Tracing ended for cause at %s\n");
- }
-
- pfd[0].fd = sock;
- pfd[0].events = POLLIN;
- if (!poll(pfd, 1, rwait.tv_sec * 1000 +
- rwait.tv_usec / 1000)) {
- if (rwait.tv_sec == 0 && rwait.tv_usec == 0)
- return(0);
- continue;
- }
- salength = sizeof(from);
- if ((n = recvfrom(sock, (char *)&msgin, sizeof(struct tsp), 0,
- (struct sockaddr *)&from, &salength)) < 0) {
- syslog(LOG_ERR, "recvfrom: %m");
- exit(1);
- }
- if (n < sizeof(struct tsp)) {
- syslog(LOG_NOTICE, "short packet (%u/%u bytes) from %s",
- n, sizeof(struct tsp), inet_ntoa(from.sin_addr));
- continue;
- }
-
- (void)gettimeofday(&from_when, (struct timezone *)0);
- bytehostorder(&msgin);
-
- if (msgin.tsp_vers > TSPVERSION) {
- if (trace) {
- fprintf(fd,"readmsg: version mismatch\n");
- /* should do a dump of the packet */
- }
- continue;
- }
-
- if (memchr(msgin.tsp_name, '\0', sizeof msgin.tsp_name) ==
- NULL) {
- syslog(LOG_NOTICE, "hostname field not NUL terminated "
- "in packet from %s", inet_ntoa(from.sin_addr));
- continue;
- }
-
- fromnet = NULL;
- for (ntp = nettab; ntp != NULL; ntp = ntp->next)
- if ((ntp->mask & from.sin_addr.s_addr) ==
- ntp->net.s_addr) {
- fromnet = ntp;
- break;
- }
-
- /*
- * drop packets from nets we are ignoring permanently
- */
- if (fromnet == NULL) {
- /*
- * The following messages may originate on
- * this host with an ignored network address
- */
- if (msgin.tsp_type != TSP_TRACEON &&
- msgin.tsp_type != TSP_SETDATE &&
- msgin.tsp_type != TSP_MSITE &&
- msgin.tsp_type != TSP_TEST &&
- msgin.tsp_type != TSP_TRACEOFF) {
- if (trace) {
- fprintf(fd,"readmsg: discard null net ");
- print(&msgin, &from);
- }
- continue;
- }
- }
-
- /*
- * Throw away messages coming from this machine,
- * unless they are of some particular type.
- * This gets rid of broadcast messages and reduces
- * master processing time.
- */
- if (!strcmp(msgin.tsp_name, hostname)
- && msgin.tsp_type != TSP_SETDATE
- && msgin.tsp_type != TSP_TEST
- && msgin.tsp_type != TSP_MSITE
- && msgin.tsp_type != TSP_TRACEON
- && msgin.tsp_type != TSP_TRACEOFF
- && msgin.tsp_type != TSP_LOOP) {
- if (trace) {
- fprintf(fd, "readmsg: discard own ");
- print(&msgin, &from);
- }
- continue;
- }
-
- /*
- * Send acknowledgements here; this is faster and
- * avoids deadlocks that would occur if acks were
- * sent from a higher level routine. Different
- * acknowledgements are necessary, depending on
- * status.
- */
- if (fromnet == NULL) /* do not de-reference 0 */
- ignoreack();
- else if (fromnet->status == MASTER)
- masterack();
- else if (fromnet->status == SLAVE)
- slaveack();
- else
- ignoreack();
-
- if (LOOKAT(msgin, type, machfrom, netfrom, from)) {
- if (trace) {
- fprintf(fd, "readmsg: ");
- print(&msgin, &from);
- }
- return(&msgin);
- } else if (++msgcnt > NHOSTS*3) {
-
-/* The protocol gets hopelessly confused if it gets too far
-* behind. However, it seems able to recover from all cases of lost
-* packets. Therefore, if we are swamped, throw everything away.
-*/
- if (trace)
- fprintf(fd,
- "readmsg: discarding %d msgs\n",
- msgcnt);
- msgcnt = 0;
- while ((ptr=head->p) != NULL) {
- head->p = ptr->p;
- free((char *)ptr);
- }
- tail = head;
- } else {
- tail->p = (struct tsplist *)
- malloc(sizeof(struct tsplist));
- tail = tail->p;
- tail->p = NULL;
- tail->info = msgin;
- tail->addr = from;
- /* timestamp msgs so SETTIMEs are correct */
- tail->when = from_when;
- }
- }
-}
-
-/*
- * Send the necessary acknowledgements:
- * only the type ACK is to be sent by a slave
- */
-void
-slaveack(void)
-{
- switch(msgin.tsp_type) {
-
- case TSP_ADJTIME:
- case TSP_SETTIME:
- case TSP_ACCEPT:
- case TSP_REFUSE:
- case TSP_TRACEON:
- case TSP_TRACEOFF:
- case TSP_QUIT:
- if (trace) {
- fprintf(fd, "Slaveack: ");
- print(&msgin, &from);
- }
- xmit(TSP_ACK,msgin.tsp_seq, &from);
- break;
-
- default:
- if (trace) {
- fprintf(fd, "Slaveack: no ack: ");
- print(&msgin, &from);
- }
- break;
- }
-}
-
-/*
- * Certain packets may arrive from this machine on ignored networks.
- * These packets should be acknowledged.
- */
-void
-ignoreack(void)
-{
- switch(msgin.tsp_type) {
-
- case TSP_TRACEON:
- case TSP_TRACEOFF:
- case TSP_QUIT:
- if (trace) {
- fprintf(fd, "Ignoreack: ");
- print(&msgin, &from);
- }
- xmit(TSP_ACK,msgin.tsp_seq, &from);
- break;
-
- default:
- if (trace) {
- fprintf(fd, "Ignoreack: no ack: ");
- print(&msgin, &from);
- }
- break;
- }
-}
-
-/*
- * `masterack' sends the necessary acknowledgments
- * to the messages received by a master
- */
-void
-masterack(void)
-{
- struct tsp resp;
-
- resp = msgin;
- resp.tsp_vers = TSPVERSION;
- strlcpy(resp.tsp_name, hostname, sizeof resp.tsp_name);
-
- switch(msgin.tsp_type) {
-
- case TSP_QUIT:
- case TSP_TRACEON:
- case TSP_TRACEOFF:
- case TSP_MSITEREQ:
- if (trace) {
- fprintf(fd, "Masterack: ");
- print(&msgin, &from);
- }
- xmit(TSP_ACK,msgin.tsp_seq, &from);
- break;
-
- case TSP_RESOLVE:
- case TSP_MASTERREQ:
- if (trace) {
- fprintf(fd, "Masterack: ");
- print(&msgin, &from);
- }
- xmit(TSP_MASTERACK,msgin.tsp_seq, &from);
- break;
-
- default:
- if (trace) {
- fprintf(fd,"Masterack: no ack: ");
- print(&msgin, &from);
- }
- break;
- }
-}
-
-/*
- * Print a TSP message
- */
-void
-print(struct tsp *msg, struct sockaddr_in *addr)
-{
- char tm[26];
- time_t msgtime;
-
- if (msg->tsp_type >= TSPTYPENUMBER) {
- fprintf(fd, "bad type (%u) on packet from %s\n",
- msg->tsp_type, inet_ntoa(addr->sin_addr));
- return;
- }
-
- switch (msg->tsp_type) {
-
- case TSP_LOOP:
- fprintf(fd, "%s %d %-6u #%d %-15s %s\n",
- tsptype[msg->tsp_type],
- msg->tsp_vers,
- msg->tsp_seq,
- msg->tsp_hopcnt,
- inet_ntoa(addr->sin_addr),
- msg->tsp_name);
- break;
-
- case TSP_SETTIME:
- case TSP_SETDATE:
- case TSP_SETDATEREQ:
-#ifdef sgi
- (void)cftime(tm, "%D %T", &msg->tsp_time.tv_sec);
-#else
- msgtime = msg->tsp_time.tv_sec;
- strftime(tm, sizeof(tm), "%D %T", localtime(&msgtime));
-#endif /* sgi */
- fprintf(fd, "%s %d %-6u %s %-15s %s\n",
- tsptype[msg->tsp_type],
- msg->tsp_vers,
- msg->tsp_seq,
- tm,
- inet_ntoa(addr->sin_addr),
- msg->tsp_name);
- break;
-
- case TSP_ADJTIME:
- fprintf(fd, "%s %d %-6u (%d,%d) %-15s %s\n",
- tsptype[msg->tsp_type],
- msg->tsp_vers,
- msg->tsp_seq,
- msg->tsp_time.tv_sec,
- msg->tsp_time.tv_usec,
- inet_ntoa(addr->sin_addr),
- msg->tsp_name);
- break;
-
- default:
- fprintf(fd, "%s %d %-6u %-15s %s\n",
- tsptype[msg->tsp_type],
- msg->tsp_vers,
- msg->tsp_seq,
- inet_ntoa(addr->sin_addr),
- msg->tsp_name);
- break;
- }
-}
diff --git a/usr.sbin/timed/timed/slave.c b/usr.sbin/timed/timed/slave.c
deleted file mode 100644
index 982fe5b206b..00000000000
--- a/usr.sbin/timed/timed/slave.c
+++ /dev/null
@@ -1,683 +0,0 @@
-/* $OpenBSD: slave.c,v 1.12 2009/10/27 23:59:57 deraadt Exp $ */
-
-/*-
- * Copyright (c) 1985, 1993 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include "globals.h"
-#include <setjmp.h>
-#include "pathnames.h"
-#include <utmp.h>
-#include <util.h>
-
-extern jmp_buf jmpenv;
-extern int Mflag;
-extern int justquit;
-
-extern u_short sequence;
-
-static char master_name[MAXHOSTNAMELEN];
-static struct netinfo *old_slavenet;
-static int old_status;
-
-static void schgdate(struct tsp *, char *);
-static void setmaster(struct tsp *);
-static void answerdelay(void);
-
-int
-slave(void)
-{
- int tries;
- long electiontime, refusetime, looktime, looptime, adjtime;
- u_short seq;
- long fastelection;
-#define FASTTOUT 3
- struct in_addr cadr;
- struct timeval otime;
- struct sockaddr_in taddr;
- char tname[MAXHOSTNAMELEN];
- struct tsp *msg, to;
- struct timeval ntime, wait, tmptv;
- time_t tmpt;
- struct tsp *answer;
- char olddate[32];
- char newdate[32];
- struct netinfo *ntp;
- struct hosttbl *htp;
-
-
- old_slavenet = 0;
- seq = 0;
- refusetime = 0;
- adjtime = 0;
-
- (void)gettimeofday(&ntime, 0);
- electiontime = ntime.tv_sec + delay2;
- fastelection = ntime.tv_sec + FASTTOUT;
- if (justquit)
- looktime = electiontime;
- else
- looktime = fastelection;
- looptime = fastelection;
-
- if (slavenet)
- xmit(TSP_SLAVEUP, 0, &slavenet->dest_addr);
- if (status & MASTER) {
- for (ntp = nettab; ntp != NULL; ntp = ntp->next) {
- if (ntp->status == MASTER)
- masterup(ntp);
- }
- }
-
-loop:
- get_goodgroup(0);
- (void)gettimeofday(&ntime, (struct timezone *)0);
- if (ntime.tv_sec > electiontime) {
- if (trace)
- fprintf(fd, "election timer expired\n");
- longjmp(jmpenv, 1);
- }
-
- if (ntime.tv_sec >= looktime) {
- if (trace)
- fprintf(fd, "Looking for nets to master\n");
-
- if (Mflag && nignorednets > 0) {
- for (ntp = nettab; ntp != NULL; ntp = ntp->next) {
- if (ntp->status == IGNORE
- || ntp->status == NOMASTER) {
- lookformaster(ntp);
- if (ntp->status == MASTER) {
- masterup(ntp);
- } else if (ntp->status == MASTER) {
- ntp->status = NOMASTER;
- }
- }
- if (ntp->status == MASTER
- && --ntp->quit_count < 0)
- ntp->quit_count = 0;
- }
- makeslave(slavenet); /* prune extras */
- setstatus();
- }
- (void)gettimeofday(&ntime, 0);
- looktime = ntime.tv_sec + delay2;
- }
- if (ntime.tv_sec >= looptime) {
- if (trace)
- fprintf(fd, "Looking for loops\n");
- for (ntp = nettab; ntp != NULL; ntp = ntp->next) {
- if (ntp->status == MASTER) {
- to.tsp_type = TSP_LOOP;
- to.tsp_vers = TSPVERSION;
- to.tsp_seq = sequence++;
- to.tsp_hopcnt = MAX_HOPCNT;
- strlcpy(to.tsp_name, hostname, sizeof to.tsp_name);
- bytenetorder(&to);
- if (sendto(sock, (char *)&to, sizeof(struct tsp), 0,
- (struct sockaddr*)&ntp->dest_addr,
- sizeof(ntp->dest_addr)) < 0) {
- trace_sendto_err(ntp->dest_addr.sin_addr);
- }
- }
- }
- (void)gettimeofday(&ntime, 0);
- looptime = ntime.tv_sec + delay2;
- }
-
- wait.tv_sec = min(electiontime,min(looktime,looptime)) - ntime.tv_sec;
- if (wait.tv_sec < 0)
- wait.tv_sec = 0;
- wait.tv_sec += FASTTOUT;
- wait.tv_usec = 0;
- msg = readmsg(TSP_ANY, ANYADDR, &wait, 0);
-
- if (msg != NULL) {
- /*
- * filter stuff not for us
- */
- switch (msg->tsp_type) {
- case TSP_SETDATE:
- case TSP_TRACEOFF:
- case TSP_TRACEON:
- /*
- * XXX check to see they are from ourself
- */
- break;
-
- case TSP_TEST:
- case TSP_MSITE:
- break;
-
- case TSP_MASTERUP:
- if (!fromnet) {
- if (trace) {
- fprintf(fd, "slave ignored: ");
- print(msg, &from);
- }
- goto loop;
- }
- break;
-
- default:
- if (!fromnet
- || fromnet->status == IGNORE
- || fromnet->status == NOMASTER) {
- if (trace) {
- fprintf(fd, "slave ignored: ");
- print(msg, &from);
- }
- goto loop;
- }
- break;
- }
-
-
- /*
- * now process the message
- */
- switch (msg->tsp_type) {
-
- case TSP_ADJTIME:
- if (fromnet != slavenet)
- break;
- if (!good_host_name(msg->tsp_name)) {
- syslog(LOG_NOTICE,
- "attempted time adjustment by %s",
- msg->tsp_name);
- suppress(&from, msg->tsp_name, fromnet);
- break;
- }
- /*
- * Speed up loop detection in case we have a loop.
- * Otherwise the clocks can race until the loop
- * is found.
- */
- (void)gettimeofday(&otime, 0);
- if (adjtime < otime.tv_sec)
- looptime -= (looptime-otime.tv_sec)/2 + 1;
-
- setmaster(msg);
- if (seq != msg->tsp_seq) {
- seq = msg->tsp_seq;
- synch(tvtomsround(msg->tsp_time));
- }
- (void)gettimeofday(&ntime, 0);
- electiontime = ntime.tv_sec + delay2;
- fastelection = ntime.tv_sec + FASTTOUT;
- adjtime = ntime.tv_sec + SAMPLEINTVL*2;
- break;
-
- case TSP_SETTIME:
- if (fromnet != slavenet)
- break;
- if (seq == msg->tsp_seq)
- break;
- seq = msg->tsp_seq;
-
- /* adjust time for residence on the queue */
- (void)gettimeofday(&otime, 0);
- adj_msg_time(msg,&otime);
- /*
- * the following line is necessary due to syslog
- * calling ctime() which clobbers the static buffer
- */
- strlcpy(olddate, date(), sizeof olddate);
- tmpt = msg->tsp_time.tv_sec;
- strlcpy(newdate, ctime(&tmpt), sizeof newdate);
-
- if (!good_host_name(msg->tsp_name)) {
- syslog(LOG_NOTICE,
- "attempted time setting by untrusted %s to %s",
- msg->tsp_name, newdate);
- suppress(&from, msg->tsp_name, fromnet);
- break;
- }
-
- setmaster(msg);
- timersub(&msg->tsp_time, &otime, &ntime);
- if (ntime.tv_sec < MAXADJ && ntime.tv_sec > -MAXADJ) {
- /*
- * do not change the clock if we can adjust it
- */
- synch(tvtomsround(ntime));
- } else {
- logwtmp("|", "date", "");
- tmptv.tv_sec = msg->tsp_time.tv_sec;
- tmptv.tv_usec = msg->tsp_time.tv_usec;
- (void)settimeofday(&tmptv, 0);
- logwtmp("{", "date", "");
- syslog(LOG_NOTICE,
- "date changed by %s from %s",
- msg->tsp_name, olddate);
- if (status & MASTER)
- spreadtime();
- }
- (void)gettimeofday(&ntime, 0);
- electiontime = ntime.tv_sec + delay2;
- fastelection = ntime.tv_sec + FASTTOUT;
-
-/* This patches a bad protocol bug. Imagine a system with several networks,
- * where there are a pair of redundant gateways between a pair of networks,
- * each running timed. Assume that we start with a third machine mastering
- * one of the networks, and one of the gateways mastering the other.
- * Imagine that the third machine goes away and the non-master gateway
- * decides to replace it. If things are timed just 'right,' we will have
- * each gateway mastering one network for a little while. If a SETTIME
- * message gets into the network at that time, perhaps from the newly
- * masterful gateway as it was taking control, the SETTIME will loop
- * forever. Each time a gateway receives it on its slave side, it will
- * call spreadtime to forward it on its mastered network. We are now in
- * a permanent loop, since the SETTIME msgs will keep any clock
- * in the network from advancing. Normally, the 'LOOP' stuff will detect
- * and correct the situation. However, with the clocks stopped, the
- * 'looptime' timer cannot expire. While they are in this state, the
- * masters will try to saturate the network with SETTIME packets.
- */
- looptime = ntime.tv_sec + (looptime-otime.tv_sec)/2-1;
- break;
-
- case TSP_MASTERUP:
- if (slavenet && fromnet != slavenet)
- break;
- if (!good_host_name(msg->tsp_name)) {
- suppress(&from, msg->tsp_name, fromnet);
- if (electiontime > fastelection)
- electiontime = fastelection;
- break;
- }
- makeslave(fromnet);
- setmaster(msg);
- setstatus();
- answerdelay();
- xmit(TSP_SLAVEUP, 0, &from);
- (void)gettimeofday(&ntime, 0);
- electiontime = ntime.tv_sec + delay2;
- fastelection = ntime.tv_sec + FASTTOUT;
- refusetime = 0;
- break;
-
- case TSP_MASTERREQ:
- if (fromnet->status != SLAVE)
- break;
- (void)gettimeofday(&ntime, 0);
- electiontime = ntime.tv_sec + delay2;
- break;
-
- case TSP_SETDATE:
- tmpt = msg->tsp_time.tv_sec;
- strlcpy(newdate, ctime(&tmpt), sizeof newdate);
- schgdate(msg, newdate);
- break;
-
- case TSP_SETDATEREQ:
- if (fromnet->status != MASTER)
- break;
- tmpt = msg->tsp_time.tv_sec;
- strlcpy(newdate, ctime(&tmpt), sizeof newdate);
- htp = findhost(msg->tsp_name);
- if (0 == htp) {
- syslog(LOG_WARNING,
- "DATEREQ from uncontrolled machine");
- break;
- }
- if (!htp->good) {
- syslog(LOG_WARNING,
- "attempted date change by untrusted %s to %s",
- htp->name, newdate);
- spreadtime();
- break;
- }
- schgdate(msg, newdate);
- break;
-
- case TSP_TRACEON:
- traceon();
- break;
-
- case TSP_TRACEOFF:
- traceoff("Tracing ended at %s\n");
- break;
-
- case TSP_SLAVEUP:
- newslave(msg);
- break;
-
- case TSP_ELECTION:
- if (fromnet->status == SLAVE) {
- (void)gettimeofday(&ntime, 0);
- electiontime = ntime.tv_sec + delay2;
- fastelection = ntime.tv_sec + FASTTOUT;
- seq = 0;
- if (!good_host_name(msg->tsp_name)) {
- syslog(LOG_NOTICE,
- "suppress election of %s",
- msg->tsp_name);
- to.tsp_type = TSP_QUIT;
- electiontime = fastelection;
- } else if (cadr.s_addr != from.sin_addr.s_addr
- && ntime.tv_sec < refusetime) {
-/* if the candidate has to repeat itself, the old code would refuse it
- * the second time. That would prevent elections.
- */
- to.tsp_type = TSP_REFUSE;
- } else {
- cadr.s_addr = from.sin_addr.s_addr;
- to.tsp_type = TSP_ACCEPT;
- refusetime = ntime.tv_sec + 30;
- }
- taddr = from;
- strlcpy(tname, msg->tsp_name, sizeof tname);
- strlcpy(to.tsp_name, hostname,
- sizeof to.tsp_name);
- answerdelay();
- if (!acksend(&to, &taddr, tname,
- TSP_ACK, 0, 0))
- syslog(LOG_WARNING,
- "no answer from candidate %s\n",
- tname);
-
- } else { /* fromnet->status == MASTER */
- htp = addmach(msg->tsp_name, &from,fromnet);
- to.tsp_type = TSP_QUIT;
- strlcpy(to.tsp_name, hostname,
- sizeof to.tsp_name);
- if (!acksend(&to, &htp->addr, htp->name,
- TSP_ACK, 0, htp->noanswer)) {
- syslog(LOG_ERR,
- "no reply from %s to ELECTION-QUIT",
- htp->name);
- (void)remmach(htp);
- }
- }
- break;
-
- case TSP_CONFLICT:
- if (fromnet->status != MASTER)
- break;
- /*
- * After a network partition, there can be
- * more than one master: the first slave to
- * come up will notify here the situation.
- */
- strlcpy(to.tsp_name, hostname, sizeof to.tsp_name);
-
- /* The other master often gets into the same state,
- * with boring results.
- */
- ntp = fromnet; /* (acksend() can leave fromnet=0 */
- for (tries = 0; tries < 3; tries++) {
- to.tsp_type = TSP_RESOLVE;
- answer = acksend(&to, &ntp->dest_addr,
- ANYADDR, TSP_MASTERACK,
- ntp, 0);
- if (answer == NULL)
- break;
- htp = addmach(answer->tsp_name,&from,ntp);
- to.tsp_type = TSP_QUIT;
- answer = acksend(&to, &htp->addr, htp->name,
- TSP_ACK, 0, htp->noanswer);
- if (!answer) {
- syslog(LOG_WARNING,
- "conflict error: no reply from %s to QUIT",
- htp->name);
- (void)remmach(htp);
- }
- }
- masterup(ntp);
- break;
-
- case TSP_MSITE:
- if (!slavenet)
- break;
- taddr = from;
- to.tsp_type = TSP_MSITEREQ;
- to.tsp_vers = TSPVERSION;
- to.tsp_seq = 0;
- strlcpy(to.tsp_name, hostname, sizeof to.tsp_name);
- answer = acksend(&to, &slavenet->dest_addr,
- ANYADDR, TSP_ACK,
- slavenet, 0);
- if (answer != NULL
- && good_host_name(answer->tsp_name)) {
- setmaster(answer);
- to.tsp_type = TSP_ACK;
- strlcpy(to.tsp_name, answer->tsp_name,
- sizeof to.tsp_name);
- bytenetorder(&to);
- if (sendto(sock, (char *)&to,
- sizeof(struct tsp), 0,
- (struct sockaddr*)&taddr, sizeof(taddr)) < 0) {
- trace_sendto_err(taddr.sin_addr);
- }
- }
- break;
-
- case TSP_MSITEREQ:
- break;
-
- case TSP_ACCEPT:
- case TSP_REFUSE:
- case TSP_RESOLVE:
- break;
-
- case TSP_QUIT:
- doquit(msg); /* become a slave */
- break;
-
- case TSP_TEST:
- electiontime = 0;
- break;
-
- case TSP_LOOP:
- /* looking for loops of masters */
- if (!(status & MASTER))
- break;
- if (fromnet->status == SLAVE) {
- if (!strcmp(msg->tsp_name, hostname)) {
- /*
- * Someone forwarded our message back to
- * us. There must be a loop. Tell the
- * master of this network to quit.
- *
- * The other master often gets into
- * the same state, with boring results.
- */
- ntp = fromnet;
- for (tries = 0; tries < 3; tries++) {
- to.tsp_type = TSP_RESOLVE;
- answer = acksend(&to, &ntp->dest_addr,
- ANYADDR, TSP_MASTERACK,
- ntp,0);
- if (answer == NULL)
- break;
- taddr = from;
- strlcpy(tname, answer->tsp_name,
- sizeof tname);
- to.tsp_type = TSP_QUIT;
- strlcpy(to.tsp_name, hostname,
- sizeof to.tsp_name);
- if (!acksend(&to, &taddr, tname,
- TSP_ACK, 0, 1)) {
- syslog(LOG_ERR,
- "no reply from %s to slave LOOP-QUIT",
- tname);
- } else {
- electiontime = 0;
- }
- }
- (void)gettimeofday(&ntime, 0);
- looptime = ntime.tv_sec + FASTTOUT;
- } else {
- if (msg->tsp_hopcnt-- < 1)
- break;
- bytenetorder(msg);
- for (ntp = nettab; ntp != 0; ntp = ntp->next) {
- if (ntp->status == MASTER
- && 0 > sendto(sock, (char *)msg,
- sizeof(struct tsp), 0,
- (struct sockaddr*)&ntp->dest_addr,
- sizeof(ntp->dest_addr)))
- trace_sendto_err(ntp->dest_addr.sin_addr);
- }
- }
- } else { /* fromnet->status == MASTER */
- /*
- * We should not have received this from a net
- * we are master on. There must be two masters,
- * unless the packet was really from us.
- */
- if (from.sin_addr.s_addr
- == fromnet->my_addr.s_addr) {
- if (trace)
- fprintf(fd,"discarding forwarded LOOP\n");
- break;
- }
-
- /*
- * The other master often gets into the same
- * state, with boring results.
- */
- ntp = fromnet;
- for (tries = 0; tries < 3; tries++) {
- to.tsp_type = TSP_RESOLVE;
- answer = acksend(&to, &ntp->dest_addr,
- ANYADDR, TSP_MASTERACK,
- ntp,0);
- if (!answer)
- break;
- htp = addmach(answer->tsp_name,
- &from,ntp);
- to.tsp_type = TSP_QUIT;
- strlcpy(to.tsp_name, hostname,
- sizeof to.tsp_name);
- if (!acksend(&to,&htp->addr,htp->name,
- TSP_ACK, 0, htp->noanswer)) {
- syslog(LOG_ERR,
- "no reply from %s to master LOOP-QUIT",
- htp->name);
- (void)remmach(htp);
- }
- }
- (void)gettimeofday(&ntime, 0);
- looptime = ntime.tv_sec + FASTTOUT;
- }
- break;
- default:
- if (trace) {
- fprintf(fd, "garbage message: ");
- print(msg, &from);
- }
- break;
- }
- }
- goto loop;
-}
-
-
-/*
- * tell the world who our master is
- */
-static void
-setmaster(struct tsp *msg)
-{
- if (slavenet
- && (slavenet != old_slavenet
- || strcmp(msg->tsp_name, master_name)
- || old_status != status)) {
- strlcpy(master_name, msg->tsp_name, sizeof master_name);
- old_slavenet = slavenet;
- old_status = status;
-
- if (status & MASTER) {
- syslog(LOG_NOTICE, "submaster to %s", master_name);
- if (trace)
- fprintf(fd, "submaster to %s\n", master_name);
-
- } else {
- syslog(LOG_NOTICE, "slave to %s", master_name);
- if (trace)
- fprintf(fd, "slave to %s\n", master_name);
- }
- }
-}
-
-
-
-/*
- * handle date change request on a slave
- */
-static void
-schgdate(struct tsp *msg, char *newdate)
-{
- struct tsp to;
- u_short seq;
- struct sockaddr_in taddr;
- struct timeval otime;
-
- if (!slavenet)
- return; /* no where to forward */
-
- taddr = from;
- seq = msg->tsp_seq;
-
- syslog(LOG_INFO,
- "forwarding date change by %s to %s",
- msg->tsp_name, newdate);
-
- /* adjust time for residence on the queue */
- (void)gettimeofday(&otime, 0);
- adj_msg_time(msg, &otime);
-
- to.tsp_type = TSP_SETDATEREQ;
- to.tsp_time = msg->tsp_time;
- strlcpy(to.tsp_name, hostname, sizeof to.tsp_name);
- if (!acksend(&to, &slavenet->dest_addr,
- ANYADDR, TSP_DATEACK,
- slavenet, 0))
- return; /* no answer */
-
- xmit(TSP_DATEACK, seq, &taddr);
-}
-
-
-/*
- * Used before answering a broadcast message to avoid network
- * contention and likely collisions.
- */
-static void
-answerdelay(void)
-{
- struct timeval timeout;
-
- timeout.tv_sec = 0;
- timeout.tv_usec = casual(1, 100 * 1000);
-
- (void)select(0, NULL, NULL, NULL, &timeout);
- return;
-}
diff --git a/usr.sbin/timed/timed/timed-extern.h b/usr.sbin/timed/timed/timed-extern.h
deleted file mode 100644
index a85b93dc94d..00000000000
--- a/usr.sbin/timed/timed/timed-extern.h
+++ /dev/null
@@ -1,82 +0,0 @@
-/* $OpenBSD: timed-extern.h,v 1.4 2003/06/02 23:36:55 millert Exp $ */
-
-/*-
- * Copyright (c) 1993 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)extern.h 5.1 (Berkeley) 5/11/93
- */
-
-struct hosttbl;
-struct netinfo;
-struct sockaddr_in;
-struct timeval;
-struct tsp;
-
-struct hosttbl *addmach(char *, struct sockaddr_in *, struct netinfo *);
-struct hosttbl *findhost(char *);
-struct hosttbl *remmach(struct hosttbl *);
-
-struct tsp *readmsg(int, char *, struct timeval *, struct netinfo *);
-struct tsp *acksend(struct tsp *,
- struct sockaddr_in *, char *, int, struct netinfo *, int);
-
-void adj_msg_time(struct tsp *, struct timeval *);
-void bytehostorder(struct tsp *);
-void bytenetorder(struct tsp *);
-void byteorder(struct tsp *);
-long casual(long, long);
-int cksum(u_short *, int);
-void correct(long);
-char *date(void);
-void doquit(struct tsp *);
-int election(struct netinfo *);
-void get_goodgroup(int);
-int good_host_name(const char *);
-void ignoreack(void);
-int in_cksum(u_short *, int);
-void lookformaster(struct netinfo *);
-void makeslave(struct netinfo *);
-int master(void);
-void masterack(void);
-void masterup(struct netinfo *);
-int measure(u_long, u_long, char *, struct sockaddr_in *, int);
-void mstotvround(struct timeval *, long);
-long networkdelta(void);
-void newslave(struct tsp *);
-void print(struct tsp *, struct sockaddr_in *);
-void prthp(clock_t);
-void rmnetmachs(struct netinfo *);
-void setstatus(void);
-int slave(void);
-void slaveack(void);
-void spreadtime(void);
-void suppress(struct sockaddr_in *, const char *, struct netinfo *);
-void synch(long);
-void traceoff(const char *);
-void traceon(void);
-void xmit(int, u_short, struct sockaddr_in *);
diff --git a/usr.sbin/timed/timed/timed.8 b/usr.sbin/timed/timed/timed.8
deleted file mode 100644
index 94db164c2cb..00000000000
--- a/usr.sbin/timed/timed/timed.8
+++ /dev/null
@@ -1,281 +0,0 @@
-.\" $OpenBSD: timed.8,v 1.17 2011/05/02 11:14:11 jmc Exp $
-.\"
-.\" Copyright (c) 1980, 1991 Regents of the University of California.
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\" 3. Neither the name of the University nor the names of its contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" @(#)timed.8 6.7 (Berkeley) 5/11/93
-.\"
-.Dd $Mdocdate: May 2 2011 $
-.Dt TIMED 8
-.Os
-.Sh NAME
-.Nm timed
-.Nd time server daemon
-.Sh SYNOPSIS
-.Nm timed
-.Op Fl dMt
-.Op Fl F Ar host ...
-.Op Fl G Ar netgroup
-.Xo
-.Oo Fl i Ar network |
-.Fl n Ar network Oc
-.Xc
-.Sh DESCRIPTION
-The
-.Nm
-utility is a time server daemon
-which is normally invoked at boot time from the
-.Xr rc 8
-file.
-It synchronizes the host's time with the time of other
-machines, which are also running
-.Nm timed ,
-in a local area network.
-These time servers will slow down the clocks of some machines
-and speed up the clocks of others to bring them to the average network time.
-The average network time is computed from measurements of clock differences
-using the
-.Tn ICMP
-timestamp request message.
-.Pp
-The following options are available:
-.Bl -tag -width indent
-.It Fl d
-Enable debugging mode;
-do not detach from the terminal.
-.It Fl F Ar host ...
-Create a list of trusted hosts.
-The
-.Nm
-utility will only accept trusted hosts as masters.
-If it finds an untrusted host claiming to be master,
-.Nm
-will suppress incoming messages from that host
-and call for a new election.
-This option implies the
-.Fl M
-option.
-If this option is not specified,
-all hosts on the connected networks are treated as trustworthy.
-.It Fl G Ar netgroup
-Specify a netgroup of trustworthy hosts,
-in addition to any masters specified with the
-.It Fl i Ar network
-Add
-.Ar network
-to the list of networks to ignore.
-All other networks
-to which the machine is directly connected
-are used by
-.Nm timed .
-This option may be specified multiple times
-to add more than one network to the list.
-.Fl M
-flag.
-This option may only be specified once.
-.It Fl M
-Allow this host to become a
-.Nm
-master if necessary.
-.It Fl n Ar network
-Add
-.Ar network
-to the list of allowed networks.
-All other networks
-to which the machine is directly connected
-are ignored by
-.Nm timed .
-This option may be specified multiple times
-to add more than one network to the list.
-.It Fl t
-Enable tracing of received messages
-and log to the file
-.Pa /var/log/timed.log .
-Tracing can be turned on or off while
-.Nm
-is running with the
-.Xr timedc 8
-utility.
-.El
-.Pp
-The
-.Fl n
-and
-.Fl i
-flags are mutually exclusive
-and require as arguments real networks to which
-the host is connected
-(see
-.Xr networks 5 ) .
-If neither flag is specified,
-.Nm
-will listen on all connected networks.
-.Pp
-A
-.Nm
-running without the
-.Fl M
-nor
-.Fl F
-flags will always remain a slave.
-If the
-.Fl F
-flag is not used,
-.Nm
-will treat all machines as trustworthy.
-.Pp
-The
-.Nm
-utility is based on a master-slave
-scheme.
-When
-.Nm
-is started on a machine, it asks the master for the network time
-and sets the host's clock to that time.
-After that, it accepts synchronization messages periodically sent by
-the master and calls
-.Xr adjtime 2
-to perform the needed corrections on the host's clock.
-.Pp
-It also communicates with
-.Xr date 1
-in order to set the date globally,
-and with
-.Xr timedc 8 ,
-a
-.Nm
-control utility.
-If the machine running the master becomes unreachable,
-the slaves will elect a new master
-from among those slaves
-which are running with at least one of the
-.Fl M
-and
-.Fl F
-flags.
-.Pp
-At startup
-.Nm
-normally checks for a master time server on each network to which
-it is connected, except as modified by the
-.Fl n
-and
-.Fl i
-options described above.
-It will request synchronization service from the first master server
-located.
-If permitted by the
-.Fl M
-or
-.Fl F
-flags, it will provide synchronization service on any attached networks
-on which no trusted master server was detected.
-Such a server propagates the time computed by the top-level master.
-The
-.Nm
-utility will periodically check for the presence of a master
-on those networks for which it is operating as a slave.
-If it finds that there are no trusted masters on a network,
-it will begin the election process on that network.
-.Pp
-One way to synchronize a group of machines is to use an
-.Tn NTP
-daemon to
-synchronize the clock of one machine to a distant standard or a radio
-receiver and
-.Fl F Ar hostname
-to tell its timed daemon to trust only itself.
-.Pp
-Messages printed by the kernel on the system console occur with
-interrupts disabled.
-This means that the clock stops while they are printing.
-A machine with many disk or network hardware problems and consequent
-messages cannot keep good time by itself.
-Each message typically causes
-the clock to lose a dozen milliseconds.
-A time daemon can correct the result.
-.Pp
-Messages in the system log about machines that failed to respond
-usually indicate machines that crashed or were turned off.
-Complaints about machines that failed to respond to initial time
-settings are often associated with
-.Dq multi-homed
-machines that looked for time masters on more than one network and eventually
-chose to become a slave on the other network.
-.Sh FILES
-.Bl -tag -width /var/log/timed.masterlog -compact
-.It Pa /var/log/timed.log
-tracing file for
-.Nm
-.It Pa /var/log/timed.masterlog
-log file for master
-.Nm
-.El
-.Sh SEE ALSO
-.Xr date 1 ,
-.Xr adjtime 2 ,
-.Xr gettimeofday 2 ,
-.Xr icmp 4 ,
-.Xr netgroup 5 ,
-.Xr networks 5 ,
-.Xr ntpd 8 ,
-.Xr rdate 8 ,
-.Xr timedc 8
-.Rs
-.%T "TSP: The Time Synchronization Protocol for UNIX 4.3BSD"
-.%A R. Gusella
-.%A S. Zatti
-.Re
-.Sh HISTORY
-The
-.Nm
-utility appeared in
-.Bx 4.3 .
-.Sh CAVEATS
-Temporal chaos will result if two or more time daemons attempt
-to adjust the same clock.
-If both
-.Nm
-and another time daemon are run on the same machine,
-ensure that the
-.Fl F
-flag is used, so that
-.Nm
-never attempts to adjust the local clock.
-.Pp
-The protocol is based on
-.Tn UDP/IP
-broadcasts.
-All machines within the range of a broadcast that are using the
-.Tn TSP
-protocol must cooperate.
-There cannot be more than a single administrative domain using the
-.Fl F
-flag among all machines reached by a broadcast packet.
-Failure to follow this rule is usually indicated by complaints concerning
-.Dq untrusted
-machines in the system log.
diff --git a/usr.sbin/timed/timed/timed.c b/usr.sbin/timed/timed/timed.c
deleted file mode 100644
index b42ca1981ba..00000000000
--- a/usr.sbin/timed/timed/timed.c
+++ /dev/null
@@ -1,801 +0,0 @@
-/* $OpenBSD: timed.c,v 1.30 2011/03/19 23:40:11 okan Exp $ */
-
-/*-
- * Copyright (c) 1985, 1993 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#define TSPTYPES
-#include "globals.h"
-#include <net/if.h>
-#include <sys/file.h>
-#include <sys/ioctl.h>
-#include <setjmp.h>
-#include "pathnames.h"
-#include <math.h>
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/times.h>
-#include <netgroup.h>
-#include <err.h>
-#include <ifaddrs.h>
-
-int trace = 0;
-int sock, sock_raw = -1;
-int status = 0;
-u_short sequence; /* sequence number */
-long delay2;
-
-int nslavenets; /* nets were I could be a slave */
-int nmasternets; /* nets were I could be a master */
-int nignorednets; /* ignored nets */
-int nnets; /* nets I am connected to */
-
-FILE *fd; /* trace file FD */
-
-jmp_buf jmpenv;
-
-volatile sig_atomic_t gotintr;
-
-struct netinfo *nettab = 0;
-struct netinfo *slavenet;
-int Mflag;
-int justquit = 0;
-int debug;
-
-struct nets {
- char name[1024];
- in_addr_t net;
- TAILQ_ENTRY(nets) next;
-};
-static TAILQ_HEAD(, nets) nets;
-
-struct hosttbl hosttbl[NHOSTS+1]; /* known hosts */
-
-/* List of hosts we trust */
-struct goodhost {
- char name[MAXHOSTNAMELEN];
- int perm;
- TAILQ_ENTRY(goodhost) next;
-};
-static TAILQ_HEAD(, goodhost) goodhosts;
-
-static char *goodgroup; /* net group of trusted hosts */
-
-/* prototypes */
-static void addnetname(const char *);
-static void checkignorednets(void);
-static void pickslavenet(struct netinfo *);
-static void add_good_host(const char *, int);
-static void usage(void);
-
-/*
- * The timedaemons synchronize the clocks of hosts in a local area network.
- * One daemon runs as master, all the others as slaves. The master
- * performs the task of computing clock differences and sends correction
- * values to the slaves.
- * Slaves start an election to choose a new master when the latter disappears
- * because of a machine crash, network partition, or when killed.
- * A resolution protocol is used to kill all but one of the masters
- * that happen to exist in segments of a partitioned network when the
- * network partition is fixed.
- *
- * Authors: Riccardo Gusella & Stefano Zatti
- *
- * overhauled at Silicon Graphics
- */
-int
-main(int argc, char **argv)
-{
- int on;
- int ret;
- int nflag, iflag;
- struct timeval ntime;
- struct servent *srvp;
- struct netinfo *ntp;
- struct netinfo *ntip;
- struct netinfo *savefromnet;
- struct nets *nt;
- struct sockaddr_in server;
- u_short port;
- int ch;
- struct ifaddrs *ifap, *ifa;
-
- ntip = NULL;
-
- on = 1;
- nflag = 0;
- iflag = 0;
-
- TAILQ_INIT(&nets);
- TAILQ_INIT(&goodhosts);
-
- opterr = 0;
- while ((ch = getopt(argc, argv, "F:G:Mdi:n:t")) != -1) {
- switch (ch) {
- case 'F':
- add_good_host(optarg, 1);
- while (optind < argc && argv[optind][0] != '-')
- add_good_host(argv[optind++], 1);
- break;
- case 'G':
- if (goodgroup != NULL) {
- fprintf(stderr,"timed: only one net group\n");
- exit(1);
- }
- goodgroup = optarg;
- break;
- case 'M':
- Mflag = 1;
- break;
- case 'd':
- debug = 1;
- break;
- case 'i':
- iflag = 1;
- addnetname(optarg);
- break;
- case 'n':
- nflag = 1;
- addnetname(optarg);
- break;
- case 't':
- trace = 1;
- break;
- default:
- usage();
- /* NOTREACHED */
- }
- }
-
- if (optind < argc)
- usage();
-
- if (nflag && iflag) {
- fprintf(stderr, "timed: -i and -n make no sense together\n");
- exit(1);
- }
-
- /*
- * If we care about which machine is the master, then we must be
- * willing to be a master as well.
- */
- if ((goodgroup != NULL) || !TAILQ_EMPTY(&goodhosts))
- Mflag = 1;
-
- if (gethostname(hostname, sizeof(hostname)) < 0) {
- perror("gethostname");
- exit(1);
- }
- self.l_bak = &self;
- self.l_fwd = &self;
- self.h_bak = &self;
- self.h_fwd = &self;
- self.head = 1;
- self.good = 1;
-
- /* Add ourselves to the list of trusted hosts */
- if (!TAILQ_EMPTY(&goodhosts))
- add_good_host(hostname, 1);
-
- if ((srvp = getservbyname("timed", "udp")) == NULL) {
- fprintf(stderr, "unknown service 'timed/udp'\n");
- exit(1);
- }
- port = srvp->s_port;
- bzero(&server, sizeof(server));
- server.sin_port = srvp->s_port;
- server.sin_family = AF_INET;
- sock = socket(AF_INET, SOCK_DGRAM, 0);
- if (sock < 0) {
- perror("socket");
- exit(1);
- }
- if (setsockopt(sock, SOL_SOCKET, SO_BROADCAST, (char *)&on,
- sizeof(on)) < 0) {
- perror("setsockopt");
- exit(1);
- }
- if (bind(sock, (struct sockaddr*)&server, sizeof(server))) {
- if (errno == EADDRINUSE)
- fprintf(stderr,"timed: time daemon already running\n");
- else
- perror("bind");
- exit(1);
- }
-
- sequence = arc4random(); /* initial seq number */
-
- gettimeofday(&ntime, 0);
- /* rounds kernel variable time to multiple of 5 ms. */
- ntime.tv_sec = 0;
- ntime.tv_usec = -((ntime.tv_usec/1000) % 5) * 1000;
- (void)adjtime(&ntime, (struct timeval *)0);
-
- TAILQ_FOREACH(nt, &nets, next) {
- struct netent *nentp;
-
- nentp = getnetbyname(nt->name);
- if (nentp == 0) {
- nt->net = inet_network(nt->name);
- if (nt->net != INADDR_NONE)
- nentp = getnetbyaddr(nt->net, AF_INET);
- }
- if (nentp != 0) {
- nt->net = nentp->n_net;
- } else if (nt->net == INADDR_NONE) {
- fprintf(stderr, "timed: unknown net %s\n", nt->name);
- exit(1);
- } else if (nt->net == INADDR_ANY) {
- fprintf(stderr, "timed: bad net %s\n", nt->name);
- exit(1);
- } else {
- fprintf(stderr,
- "timed: warning: %s unknown in /etc/networks\n",
- nt->name);
- }
-
- if (0 == (nt->net & 0xff000000))
- nt->net <<= 8;
- if (0 == (nt->net & 0xff000000))
- nt->net <<= 8;
- if (0 == (nt->net & 0xff000000))
- nt->net <<= 8;
- }
-
- if (getifaddrs(&ifap) != 0) {
- perror("timed: get interface configuration");
- exit(1);
- }
-
- ntp = NULL;
- for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
- if (ifa->ifa_addr->sa_family != AF_INET)
- continue;
- if (!ntp)
- ntp = (struct netinfo*)malloc(sizeof(struct netinfo));
- bzero(ntp, sizeof(*ntp));
- ntp->my_addr=((struct sockaddr_in *)ifa->ifa_addr)->sin_addr;
- ntp->status = NOMASTER;
-
- if ((ifa->ifa_flags & IFF_UP) == 0)
- continue;
- if ((ifa->ifa_flags & IFF_BROADCAST) == 0 &&
- (ifa->ifa_flags & IFF_POINTOPOINT) == 0) {
- continue;
- }
-
- ((struct sockaddr_in *)ifa->ifa_addr)->sin_addr = ntp->my_addr;
- ntp->mask = ((struct sockaddr_in *)
- ifa->ifa_netmask)->sin_addr.s_addr;
-
- if (ifa->ifa_flags & IFF_BROADCAST) {
- ntp->dest_addr = *(struct sockaddr_in *)ifa->ifa_broadaddr;
- /* What if the broadcast address is all ones?
- * So we cannot just mask ntp->dest_addr. */
- ntp->net = ntp->my_addr;
- ntp->net.s_addr &= ntp->mask;
- } else {
- ntp->dest_addr = *(struct sockaddr_in *)ifa->ifa_dstaddr;
- ntp->net = ntp->dest_addr.sin_addr;
- }
-
- ntp->dest_addr.sin_port = port;
-
- TAILQ_FOREACH(nt, &nets, next) {
- if (ntohl(ntp->net.s_addr) == nt->net)
- break;
- }
- if ((nflag && !nt) || (iflag && nt))
- continue;
-
- ntp->next = NULL;
- if (nettab == NULL) {
- nettab = ntp;
- } else {
- ntip->next = ntp;
- }
- ntip = ntp;
- ntp = NULL;
- }
-
- if (ntp)
- (void) free((char *)ntp);
- if (nettab == NULL) {
- fprintf(stderr, "timed: no network usable\n");
- exit(1);
- }
- freeifaddrs(ifap);
-
- /* election timer delay in secs. */
- delay2 = casual(MINTOUT, MAXTOUT);
-
- if (!debug)
- daemon(debug, 0);
-
- if (trace)
- traceon();
- openlog("timed", LOG_CONS|LOG_PID, LOG_DAEMON);
-
- /*
- * keep returning here
- */
- ret = setjmp(jmpenv);
- savefromnet = fromnet;
- setstatus();
-
- if (Mflag) {
- switch (ret) {
-
- case 0:
- checkignorednets();
- pickslavenet(0);
- break;
- case 1:
- /* Just lost our master */
- if (slavenet != 0)
- slavenet->status = election(slavenet);
- if (!slavenet || slavenet->status == MASTER) {
- checkignorednets();
- pickslavenet(0);
- } else {
- makeslave(slavenet); /* prune extras */
- }
- break;
-
- case 2:
- /* Just been told to quit */
- justquit = 1;
- pickslavenet(savefromnet);
- break;
- }
-
- setstatus();
- if (!(status & MASTER) && sock_raw != -1) {
- /* sock_raw is not being used now */
- (void)close(sock_raw);
- sock_raw = -1;
- }
-
- if (status == MASTER)
- master();
- else
- slave();
-
- } else {
- if (sock_raw != -1) {
- (void)close(sock_raw);
- sock_raw = -1;
- }
-
- if (ret) {
- /* we just lost our master or were told to quit */
- justquit = 1;
- }
- for (ntp = nettab; ntp != NULL; ntp = ntp->next) {
- if (ntp->status == MASTER) {
- rmnetmachs(ntp);
- ntp->status = NOMASTER;
- }
- }
- checkignorednets();
- pickslavenet(0);
- setstatus();
-
- slave();
- }
- /* NOTREACHED */
- return(0);
-}
-
-
-/*
- * suppress an upstart, untrustworthy, self-appointed master
- */
-void
-suppress(struct sockaddr_in *addr, const char *name, struct netinfo *net)
-{
- struct sockaddr_in tgt;
- char tname[MAXHOSTNAMELEN];
- struct tsp msg;
- static struct timeval wait;
-
- if (trace)
- fprintf(fd, "suppress: %s\n", name);
- tgt = *addr;
- strlcpy(tname, name, sizeof(tname));
-
- while (readmsg(TSP_ANY, ANYADDR, &wait, net) != NULL) {
- if (trace)
- fprintf(fd, "suppress:\tdiscarded packet from %s\n",
- name);
- }
-
- syslog(LOG_NOTICE, "suppressing false master %s", tname);
-
- memset(&msg, 0, sizeof(msg));
- msg.tsp_type = TSP_QUIT;
- strlcpy(msg.tsp_name, hostname, sizeof msg.tsp_name);
-
- (void)acksend(&msg, &tgt, tname, TSP_ACK, 0, 1);
-}
-
-void
-lookformaster(struct netinfo *ntp)
-{
- struct tsp resp, conflict, *answer;
- struct timeval ntime;
- char mastername[MAXHOSTNAMELEN];
- struct sockaddr_in masteraddr;
-
- get_goodgroup(0);
- ntp->status = SLAVE;
-
- /* look for master */
- memset(&resp, 0, sizeof(resp));
- resp.tsp_type = TSP_MASTERREQ;
- strlcpy(resp.tsp_name, hostname, sizeof(resp.tsp_name));
-
- answer = acksend(&resp, &ntp->dest_addr, ANYADDR,
- TSP_MASTERACK, ntp, 0);
- if ((answer != NULL) && !good_host_name(answer->tsp_name)) {
- suppress(&from, answer->tsp_name, ntp);
- ntp->status = NOMASTER;
- answer = 0;
- }
-
- if (answer == NULL) {
- /*
- * Various conditions can cause conflict: races between
- * two just started timedaemons when no master is
- * present, or timedaemons started during an election.
- * A conservative approach is taken. Give up and became a
- * slave, postponing election of a master until first
- * timer expires.
- */
- timerclear(&ntime);
- answer = readmsg(TSP_MASTERREQ, ANYADDR, &ntime, ntp);
- if (answer != NULL) {
- if (!good_host_name(answer->tsp_name)) {
- suppress(&from, answer->tsp_name, ntp);
- ntp->status = NOMASTER;
- }
- return;
- }
-
- timerclear(&ntime);
- answer = readmsg(TSP_MASTERUP, ANYADDR, &ntime, ntp);
- if (answer != NULL) {
- if (!good_host_name(answer->tsp_name)) {
- suppress(&from, answer->tsp_name, ntp);
- ntp->status = NOMASTER;
- }
- return;
- }
-
- timerclear(&ntime);
- answer = readmsg(TSP_ELECTION, ANYADDR, &ntime, ntp);
- if (answer != NULL) {
- if (!good_host_name(answer->tsp_name)) {
- suppress(&from, answer->tsp_name, ntp);
- ntp->status = NOMASTER;
- }
- return;
- }
-
- if (Mflag)
- ntp->status = MASTER;
- else
- ntp->status = NOMASTER;
- return;
- }
-
- ntp->status = SLAVE;
- strlcpy(mastername, answer->tsp_name, sizeof mastername);
- masteraddr = from;
-
- /*
- * If network has been partitioned, there might be other
- * masters; tell the one we have just acknowledged that
- * it has to gain control over the others.
- */
- ntime.tv_sec = 0;
- ntime.tv_usec = 300000;
- answer = readmsg(TSP_MASTERACK, ANYADDR, &ntime, ntp);
-
- /*
- * checking also not to send CONFLICT to ack'ed master
- * due to duplicated MASTERACKs
- */
- if (answer != NULL &&
- strcmp(answer->tsp_name, mastername) != 0) {
- conflict.tsp_type = TSP_CONFLICT;
- strlcpy(conflict.tsp_name, hostname, sizeof conflict.tsp_name);
- if (!acksend(&conflict, &masteraddr, mastername,
- TSP_ACK, 0, 0)) {
- syslog(LOG_ERR,
- "error on sending TSP_CONFLICT");
- }
- }
-}
-
-/*
- * based on the current network configuration, set the status, and count
- * networks;
- */
-void
-setstatus(void)
-{
- struct netinfo *ntp;
-
- status = 0;
- nmasternets = nslavenets = nnets = nignorednets = 0;
- if (trace)
- fprintf(fd, "Net status:\n");
- for (ntp = nettab; ntp != NULL; ntp = ntp->next) {
- switch ((int)ntp->status) {
- case MASTER:
- nmasternets++;
- break;
- case SLAVE:
- nslavenets++;
- break;
- case NOMASTER:
- case IGNORE:
- nignorednets++;
- break;
- }
- if (trace) {
- fprintf(fd, "\t%-16s", inet_ntoa(ntp->net));
- switch ((int)ntp->status) {
- case NOMASTER:
- fprintf(fd, "NOMASTER\n");
- break;
- case MASTER:
- fprintf(fd, "MASTER\n");
- break;
- case SLAVE:
- fprintf(fd, "SLAVE\n");
- break;
- case IGNORE:
- fprintf(fd, "IGNORE\n");
- break;
- default:
- fprintf(fd, "invalid state %d\n",
- (int)ntp->status);
- break;
- }
- }
- nnets++;
- status |= ntp->status;
- }
- status &= ~IGNORE;
- if (trace)
- fprintf(fd,
- "\tnets=%d masters=%d slaves=%d ignored=%d delay2=%ld\n",
- nnets, nmasternets, nslavenets, nignorednets, delay2);
-}
-
-void
-makeslave(struct netinfo *net)
-{
- struct netinfo *ntp;
-
- for (ntp = nettab; ntp != NULL; ntp = ntp->next) {
- if (ntp->status == SLAVE && ntp != net)
- ntp->status = IGNORE;
- }
- slavenet = net;
-}
-
-/*
- * Try to become master over ignored nets..
- */
-static void
-checkignorednets(void)
-{
- struct netinfo *ntp;
-
- for (ntp = nettab; ntp != NULL; ntp = ntp->next) {
- if (!Mflag && ntp->status == SLAVE)
- break;
-
- if (ntp->status == IGNORE || ntp->status == NOMASTER) {
- lookformaster(ntp);
- if (!Mflag && ntp->status == SLAVE)
- break;
- }
- }
-}
-
-/*
- * choose a good network on which to be a slave
- * The ignored networks must have already been checked.
- * Take a hint about for a good network.
- */
-static void
-pickslavenet(struct netinfo *ntp)
-{
- if (slavenet != 0 && slavenet->status == SLAVE) {
- makeslave(slavenet); /* prune extras */
- return;
- }
-
- if (ntp == 0 || ntp->status != SLAVE) {
- for (ntp = nettab; ntp != 0; ntp = ntp->next) {
- if (ntp->status == SLAVE)
- break;
- }
- }
- makeslave(ntp);
-}
-
-/*
- * returns a random number in the range [inf, sup]
- */
-long
-casual(long inf, long sup)
-{
- return (inf + random() % (sup - inf + 1));
-}
-
-char *
-date(void)
-{
- struct timeval tv;
- time_t t;
-
- (void)gettimeofday(&tv, (struct timezone *)0);
- t = tv.tv_sec;
- return (ctime(&t));
-}
-
-void
-addnetname(const char *name)
-{
- struct nets *netlist;
-
- if ((netlist = (struct nets *)calloc(1, sizeof(*netlist))) == NULL)
- err(1, "malloc");
- strlcpy(netlist->name, name, sizeof(netlist->name));
- TAILQ_INSERT_TAIL(&nets, netlist, next);
-}
-
-/*
- * add_good_host() -
- *
- * Add a host to our list of trusted hosts.
- */
-static void
-add_good_host(const char *name, int perm)
-{
- struct goodhost *ghp;
- struct hostent *hentp;
-
- if ((ghp = (struct goodhost *)calloc(1, sizeof(*ghp))) == NULL)
- err(1, "malloc");
- strlcpy(ghp->name, name, sizeof(ghp->name));
- ghp->perm = perm;
- TAILQ_INSERT_TAIL(&goodhosts, ghp, next);
-
- if ((hentp = gethostbyname(name)) == NULL && perm)
- (void)fprintf(stderr, "unknown host %s\n", name);
-}
-
-
-/* update our image of the net-group of trustworthy hosts
- */
-void
-get_goodgroup(int force)
-{
-# define NG_DELAY (30*60*CLK_TCK) /* 30 minutes */
- static unsigned long last_update = -NG_DELAY;
- unsigned long new_update;
- struct hosttbl *htp;
- struct goodhost *ghp, *nxt;
- const char *mach, *usr, *dom;
- struct tms tm;
-
-
- /* if no netgroup, then we are finished */
- if (goodgroup == 0 || !Mflag)
- return;
-
- /* Do not chatter with the netgroup master too often.
- */
- new_update = times(&tm);
- if (new_update < last_update + NG_DELAY
- && !force)
- return;
- last_update = new_update;
-
- /* forget the old temporary entries */
- for (ghp = TAILQ_FIRST(&goodhosts); ghp != NULL; ghp = nxt) {
- nxt = TAILQ_NEXT(ghp, next);
-
- if (!ghp->perm) {
- TAILQ_REMOVE(&goodhosts, ghp, next);
- free(ghp);
- }
- }
-
- /* quit now if we are not one of the trusted masters
- */
- if (!innetgr(goodgroup, &hostname[0], 0,0)) {
- if (trace)
- (void)fprintf(fd, "get_goodgroup: %s not in %s\n",
- &hostname[0], goodgroup);
- return;
- }
- if (trace)
- (void)fprintf(fd, "get_goodgroup: %s in %s\n",
- &hostname[0], goodgroup);
-
- /* mark the entire netgroup as trusted */
- (void)setnetgrent(goodgroup);
- while (getnetgrent(&mach,&usr,&dom)) {
- if (0 != mach)
- add_good_host(mach,0);
- }
- (void)endnetgrent();
-
- /* update list of slaves */
- for (htp = self.l_fwd; htp != &self; htp = htp->l_fwd) {
- htp->good = good_host_name(&htp->name[0]);
- }
-}
-
-
-/* see if a machine is trustworthy
- */
-int /* 1=trust hp to change our date */
-good_host_name(const char *name)
-{
- struct goodhost *ghp;
-
- if (TAILQ_EMPTY(&goodhosts) || !Mflag)
- return (1);
-
- TAILQ_FOREACH(ghp, &goodhosts, next) {
- if (strcasecmp(ghp->name, name) == 0)
- return (1);
- }
-
- /* XXX - Should be no need for this since we already added ourselves */
- if (strcasecmp(name, hostname) == 0)
- return (1);
-
- return (0);
-}
-
-static void
-usage(void)
-{
- (void)fprintf(stderr, "usage: timed [-dMt] [-F host ...] [-G netgroup] "
- "[-i network | -n network]\n");
- exit(1);
-}
diff --git a/usr.sbin/timed/timedc/Makefile b/usr.sbin/timed/timedc/Makefile
deleted file mode 100644
index 91e65aeff4e..00000000000
--- a/usr.sbin/timed/timedc/Makefile
+++ /dev/null
@@ -1,12 +0,0 @@
-# $OpenBSD: Makefile,v 1.7 2004/11/10 22:07:45 drahn Exp $
-#
-# @(#)Makefile 5.4 (Berkeley) 5/11/93
-
-PROG= timedc
-SRCS= cmds.c cmdtab.c timedc.c byteorder.c measure.c cksum.c
-MAN= timedc.8
-LDSTATIC=${STATIC}
-.PATH: ${.CURDIR}/../timed
-
-.include "../../Makefile.inc"
-.include <bsd.prog.mk>
diff --git a/usr.sbin/timed/timedc/cmds.c b/usr.sbin/timed/timedc/cmds.c
deleted file mode 100644
index 04bf9d0f2dd..00000000000
--- a/usr.sbin/timed/timedc/cmds.c
+++ /dev/null
@@ -1,564 +0,0 @@
-/* $OpenBSD: cmds.c,v 1.21 2009/10/27 23:59:57 deraadt Exp $ */
-
-/*-
- * Copyright (c) 1985, 1993 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifdef sgi
-#ident "$Revision: 1.21 $"
-#endif
-
-#include "timedc.h"
-#include <sys/file.h>
-
-#include <netinet/in_systm.h>
-#include <netinet/ip.h>
-#include <netinet/ip_icmp.h>
-
-#include <poll.h>
-#include <signal.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#define TSPTYPES
-#include <protocols/timed.h>
-
-#ifdef sgi
-#include <bstring.h>
-#include <sys/clock.h>
-#else
-#define SECHR (60*60)
-#define SECDAY (24*SECHR)
-#endif /* sgi */
-
-# define DATE_PROTO "udp"
-# define DATE_PORT "time"
-
-
-int sock;
-int sock_raw;
-char myname[MAXHOSTNAMELEN];
-struct hostent *hp;
-struct sockaddr_in server;
-struct sockaddr_in dayaddr;
-extern int measure_delta;
-
-void bytenetorder(struct tsp *);
-void bytehostorder(struct tsp *);
-
-
-#define BU ((unsigned long)2208988800U) /* seconds before UNIX epoch */
-
-
-/* compute the difference between our date and another machine
- */
-static int /* difference in days from our time */
-daydiff(char *hostname)
-{
- struct sockaddr_in from;
- struct timeval now;
- struct pollfd pfd;
- unsigned long sec;
- int i, trials;
- socklen_t fromlen;
-
- for (trials = 0; trials < 10; trials++) {
- /* ask for the time */
- sec = 0;
-
- siginterrupt(SIGINT, 1);
- if (sendto(sock, &sec, sizeof(sec), 0,
- (struct sockaddr *)&dayaddr, sizeof(dayaddr)) < 0) {
- if (errno == EINTR && gotintr)
- goto bail;
- siginterrupt(SIGINT, 0);
- perror("sendto(sock)");
- goto bail;
- }
- siginterrupt(SIGINT, 0);
-
- for (;;) {
- pfd.fd = sock;
- pfd.events = POLLIN;
- i = poll(&pfd, 1, 2 * 1000);
- if (i < 0) {
- if (errno == EINTR) {
- if (gotintr)
- goto bail;
- continue;
- }
- perror("poll(date read)");
- goto bail;
- }
- if (i == 0)
- break;
-
- fromlen = sizeof(from);
- siginterrupt(SIGINT, 1);
- if (recvfrom(sock, &sec, sizeof(sec), 0,
- (struct sockaddr *)&from, &fromlen) < 0) {
- if (errno == EINTR && gotintr)
- goto bail;
- siginterrupt(SIGINT, 0);
- perror("recvfrom(date read)");
- goto bail;
- }
- siginterrupt(SIGINT, 0);
-
- sec = ntohl(sec);
- if (sec < BU) {
- fprintf(stderr, "%s says it is before 1970: %lu",
- hostname, sec);
- goto bail;
- }
- sec -= BU;
-
- (void)gettimeofday(&now, (struct timezone *)NULL);
- return (sec - now.tv_sec);
- }
- }
-
- /* if we get here, we tried too many times */
- fprintf(stderr,"%s will not tell us the date\n", hostname);
-
-bail:
- siginterrupt(SIGINT, 0);
- return (0);
-}
-
-
-/*
- * Clockdiff computes the difference between the time of the machine on
- * which it is called and the time of the machines given as argument.
- * The time differences measured by clockdiff are obtained using a sequence
- * of ICMP TSTAMP messages which are returned to the sender by the IP module
- * in the remote machine.
- * In order to compare clocks of machines in different time zones, the time
- * is transmitted (as a 32-bit value) in milliseconds since midnight UT.
- * If a hosts uses a different time format, it should set the high order
- * bit of the 32-bit quantity it transmits.
- * However, VMS apparently transmits the time in milliseconds since midnight
- * local time (rather than GMT) without setting the high order bit.
- * Furthermore, it does not understand daylight-saving time. This makes
- * clockdiff behaving inconsistently with hosts running VMS.
- *
- * In order to reduce the sensitivity to the variance of message transmission
- * time, clockdiff sends a sequence of messages. Yet, measures between
- * two `distant' hosts can be affected by a small error. The error can,
- * however, be reduced by increasing the number of messages sent in each
- * measurement.
- */
-void
-clockdiff(int argc, char *argv[])
-{
- struct servent *sp;
- long avg;
- int avg_cnt;
- extern int measure(u_long, u_long, char *, struct sockaddr_in *, int);
- int measure_status;
-
- if (argc < 2) {
- printf("usage: clockdiff host ...\n");
- return;
- }
-
- (void)gethostname(myname,sizeof(myname));
-
- /* get the address for the date ready */
- sp = getservbyname(DATE_PORT, DATE_PROTO);
- if (!sp) {
- (void)fprintf(stderr, "%s/%s is an unknown service\n",
- DATE_PORT, DATE_PROTO);
- dayaddr.sin_port = 0;
- } else
- dayaddr.sin_port = sp->s_port;
-
- measure_status = 0;
- while (argc > 1) {
- argc--;
- argv++;
-
- siginterrupt(SIGINT, 1);
- hp = gethostbyname(*argv);
- if (hp == NULL) {
- if (errno == EINTR && gotintr) {
- siginterrupt(SIGINT, 0);
- return;
- }
- siginterrupt(SIGINT, 0);
- fprintf(stderr, "timedc: %s: ", *argv);
- herror(0);
- continue;
- }
- siginterrupt(SIGINT, 0);
-
- server.sin_family = hp->h_addrtype;
- bcopy(hp->h_addr, &server.sin_addr.s_addr, hp->h_length);
- for (avg_cnt = 0, avg = 0; avg_cnt < 16; avg_cnt++) {
- measure_status = measure(10000, 100, *argv, &server, 1);
- if (measure_status != GOOD)
- break;
- avg += measure_delta;
- }
- if (measure_status == GOOD)
- measure_delta = avg/avg_cnt;
-
- switch (measure_status) {
- case HOSTDOWN:
- printf("%s is down\n", hp->h_name);
- continue;
- case NONSTDTIME:
- printf("%s transmits a non-standard time format\n",
- hp->h_name);
- continue;
- case UNREACHABLE:
- printf("%s is unreachable\n", hp->h_name);
- continue;
- }
-
- /*
- * Try to get the date only after using ICMP timestamps to
- * get the time. This is because the date protocol
- * is optional.
- */
- if (dayaddr.sin_port != 0) {
- dayaddr.sin_family = hp->h_addrtype;
- bcopy(hp->h_addr, &dayaddr.sin_addr.s_addr,
- hp->h_length);
- avg = daydiff(*argv);
- if (avg > SECDAY) {
- printf("time on %s is %ld days ahead %s\n",
- hp->h_name, avg/SECDAY, myname);
- continue;
- } else if (avg < -SECDAY) {
- printf("time on %s is %ld days behind %s\n",
- hp->h_name, -avg/SECDAY, myname);
- continue;
- }
- }
-
- if (measure_delta > 0) {
- printf("time on %s is %d ms. ahead of time on %s\n",
- hp->h_name, measure_delta, myname);
- } else if (measure_delta == 0) {
- printf("%s and %s have the same time\n",
- hp->h_name, myname);
- } else {
- printf("time on %s is %d ms. behind time on %s\n",
- hp->h_name, -measure_delta, myname);
- }
- }
-}
-
-
-/*
- * finds location of master timedaemon
- */
-void
-msite(int argc, char *argv[])
-{
- struct sockaddr_in dest, from;
- struct servent *srvp;
- int i, cc;
- socklen_t length;
- struct pollfd pfd;
- struct tsp msg;
- char *tgtname;
-
- if (argc < 1) {
- printf("usage: msite [hostname]\n");
- return;
- }
-
- srvp = getservbyname("timed", "udp");
- if (srvp == 0) {
- fprintf(stderr, "udp/timed: unknown service\n");
- return;
- }
- memset(&dest, 0, sizeof dest);
- dest.sin_port = srvp->s_port;
- dest.sin_family = AF_INET;
-
- (void)gethostname(myname, sizeof(myname));
- i = 1;
-
- do {
- tgtname = (i >= argc) ? myname : argv[i];
- siginterrupt(SIGINT, 1);
- hp = gethostbyname(tgtname);
- if (hp == 0) {
- if (errno == EINTR && gotintr)
- goto bail;
- siginterrupt(SIGINT, 0);
- fprintf(stderr, "timedc: %s: ", tgtname);
- herror(0);
- continue;
- }
-
- bcopy(hp->h_addr, &dest.sin_addr.s_addr, hp->h_length);
- (void)strlcpy(msg.tsp_name, myname, sizeof msg.tsp_name);
- msg.tsp_type = TSP_MSITE;
- msg.tsp_vers = TSPVERSION;
- bytenetorder(&msg);
-
- if (sendto(sock, &msg, sizeof(struct tsp), 0,
- (struct sockaddr *)&dest, sizeof(dest)) < 0) {
- if (errno == EINTR && gotintr)
- goto bail;
- siginterrupt(SIGINT, 0);
- perror("sendto");
- continue;
- }
-
- pfd.fd = sock;
- pfd.events = POLLIN;
- switch (poll(&pfd, 1, 15 * 1000)) {
- case -1:
- if (errno == EINTR && gotintr)
- goto bail;
- siginterrupt(SIGINT, 0);
- continue;
- case 1:
- length = sizeof(from);
- cc = recvfrom(sock, &msg, sizeof(struct tsp), 0,
- (struct sockaddr *)&from, &length);
- if (cc < 0) {
- if (errno == EINTR && gotintr)
- goto bail;
- siginterrupt(SIGINT, 0);
- perror("recvfrom");
- continue;
- }
- siginterrupt(SIGINT, 0);
-
- if (cc < sizeof(struct tsp)) {
- fprintf(stderr,
- "short packet (%u/%u bytes) from %s\n",
- cc, sizeof(struct tsp),
- inet_ntoa(from.sin_addr));
- continue;
- }
- bytehostorder(&msg);
- if (msg.tsp_type == TSP_ACK) {
- printf("master timedaemon at %s is %s\n",
- tgtname, msg.tsp_name);
- } else {
- if (msg.tsp_type >= TSPTYPENUMBER)
- printf("received unknown ack: %u\n",
- msg.tsp_type);
- else
- printf("received wrong ack: %s\n",
- tsptype[msg.tsp_type]);
- }
- break;
- case 0:
- siginterrupt(SIGINT, 0);
- printf("communication error with %s\n", tgtname);
- break;
- }
- } while (++i < argc);
-
-bail:
- siginterrupt(SIGINT, 0);
-}
-
-/*
- * quits timedc
- */
-void
-quit(int ignored, char *unused[])
-{
- exit(0);
-}
-
-
-/*
- * Causes the election timer to expire on the selected hosts
- * It sends just one udp message per machine, relying on
- * reliability of communication channel.
- */
-void
-testing(int argc, char *argv[])
-{
- struct sockaddr_in sin;
- struct tsp msg;
- struct servent *srvp;
-
- if (argc < 2) {
- printf("usage: election host1 [host2 ...]\n");
- return;
- }
-
- srvp = getservbyname("timed", "udp");
- if (srvp == 0) {
- fprintf(stderr, "udp/timed: unknown service\n");
- return;
- }
-
- while (argc > 1) {
- argc--;
- argv++;
-
- siginterrupt(SIGINT, 1);
- hp = gethostbyname(*argv);
- if (hp == NULL) {
- if (errno == EINTR && gotintr)
- goto bail;
- siginterrupt(SIGINT, 0);
- fprintf(stderr, "timedc: %s: ", *argv);
- herror(0);
- argc--;
- argv++;
- continue;
- }
-
- memset(&sin, 0, sizeof sin);
- sin.sin_port = srvp->s_port;
- sin.sin_family = hp->h_addrtype;
- bcopy(hp->h_addr, &sin.sin_addr.s_addr, hp->h_length);
-
- msg.tsp_type = TSP_TEST;
- msg.tsp_vers = TSPVERSION;
- (void)gethostname(myname, sizeof(myname));
- (void)strncpy(msg.tsp_name, myname, sizeof(msg.tsp_name));
- bytenetorder(&msg);
-
- if (sendto(sock, &msg, sizeof(struct tsp), 0,
- (struct sockaddr *)&sin, sizeof(sin)) < 0) {
- if (errno == EINTR && gotintr)
- goto bail;
- siginterrupt(SIGINT, 0);
- perror("sendto");
- }
- }
-bail:
- siginterrupt(SIGINT, 0);
-}
-
-
-/*
- * Enables or disables tracing on local timedaemon
- */
-void
-tracing(int argc, char *argv[])
-{
- struct sockaddr_in dest;
- struct sockaddr_in from;
- struct tsp msg;
- struct servent *srvp;
- struct pollfd pfd;
- int cc, onflag;
- socklen_t length;
-
- if (argc != 2) {
- printf("usage: tracing { on | off }\n");
- return;
- }
-
- srvp = getservbyname("timed", "udp");
- if (srvp == 0) {
- fprintf(stderr, "udp/timed: unknown service\n");
- return;
- }
-
- memset(&dest, 0, sizeof dest);
- dest.sin_port = srvp->s_port;
- dest.sin_family = AF_INET;
-
- (void)gethostname(myname,sizeof(myname));
- siginterrupt(SIGINT, 1);
- hp = gethostbyname(myname);
- if (hp == NULL && errno == EINTR && gotintr)
- goto bail;
-
- bcopy(hp->h_addr, &dest.sin_addr.s_addr, hp->h_length);
-
- if (strcmp(argv[1], "on") == 0) {
- msg.tsp_type = TSP_TRACEON;
- onflag = ON;
- } else {
- msg.tsp_type = TSP_TRACEOFF;
- onflag = OFF;
- }
-
- (void)strlcpy(msg.tsp_name, myname, sizeof msg.tsp_name);
- msg.tsp_vers = TSPVERSION;
- bytenetorder(&msg);
- if (sendto(sock, &msg, sizeof(struct tsp), 0,
- (struct sockaddr *)&dest, sizeof(dest)) < 0) {
- if (errno == EINTR && gotintr)
- goto bail;
- siginterrupt(SIGINT, 0);
- perror("sendto");
- return;
- }
-
- pfd.fd = sock;
- pfd.events = POLLIN;
- switch (poll(&pfd, 1, 5 * 1000)) {
- case 1:
- length = sizeof(from);
- cc = recvfrom(sock, &msg, sizeof(struct tsp), 0,
- (struct sockaddr *)&from, &length);
- if (cc < 0) {
- if (errno == EINTR && gotintr)
- goto bail;
- siginterrupt(SIGINT, 0);
- perror("recvfrom");
- return;
- }
- siginterrupt(SIGINT, 0);
- if (cc < sizeof(struct tsp)) {
- fprintf(stderr, "short packet (%u/%u bytes) from %s\n",
- cc, sizeof(struct tsp), inet_ntoa(from.sin_addr));
- goto bail;
- }
- bytehostorder(&msg);
- if (msg.tsp_type == TSP_ACK) {
- if (onflag)
- printf("timed tracing enabled\n");
- else
- printf("timed tracing disabled\n");
- } else {
- if (msg.tsp_type >= TSPTYPENUMBER)
- printf("unknown ack received: %u\n",
- msg.tsp_type);
- else
- printf("wrong ack received: %s\n",
- tsptype[msg.tsp_type]);
- }
- break;
- case 0:
- siginterrupt(SIGINT, 0);
- printf("communication error\n");
- break;
- }
-bail:
- siginterrupt(SIGINT, 0);
-}
diff --git a/usr.sbin/timed/timedc/cmdtab.c b/usr.sbin/timed/timedc/cmdtab.c
deleted file mode 100644
index 7c93deeffd5..00000000000
--- a/usr.sbin/timed/timedc/cmdtab.c
+++ /dev/null
@@ -1,51 +0,0 @@
-/* $OpenBSD: cmdtab.c,v 1.5 2009/10/27 23:59:57 deraadt Exp $ */
-
-/*
- * Copyright (c) 1983 Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include "timedc.h"
-
-char clockdiffhelp[] = "measures clock differences between machines";
-char helphelp[] = "gets help on commands";
-char msitehelp[] = "finds location of master";
-char quithelp[] = "exits timedc";
-char testinghelp[] = "causes election timers to expire";
-char tracinghelp[] = "turns tracing on or off";
-
-struct cmd cmdtab[] = {
- { "clockdiff", clockdiffhelp, clockdiff, 0 },
- { "election", testinghelp, testing, 1 },
- { "help", helphelp, help, 0 },
- { "msite", msitehelp, msite, 0 },
- { "quit", quithelp, quit, 0 },
- { "trace", tracinghelp, tracing, 1 },
- { "?", helphelp, help, 0 },
-};
-
-int NCMDS = sizeof (cmdtab) / sizeof (cmdtab[0]);
diff --git a/usr.sbin/timed/timedc/timedc-extern.h b/usr.sbin/timed/timedc/timedc-extern.h
deleted file mode 100644
index 5e65ed0cada..00000000000
--- a/usr.sbin/timed/timedc/timedc-extern.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/* $OpenBSD: timedc-extern.h,v 1.7 2003/10/12 23:44:13 deraadt Exp $ */
-
-/*-
- * Copyright (c) 1993 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)extern.h 5.1 (Berkeley) 5/11/93
- */
-
-struct tsp;
-
-void bytehostorder(struct tsp *);
-void bytenetorder(struct tsp *);
-void clockdiff(int, char *[]);
-void help(int, char *[]);
-int makeargv(void);
-void msite(int, char *[]);
-void quit(int, char *[]);
-void testing(int, char *[]);
-void tracing(int, char *[]);
-
-void sigintr(int);
-extern volatile sig_atomic_t gotintr;
-
diff --git a/usr.sbin/timed/timedc/timedc.8 b/usr.sbin/timed/timedc/timedc.8
deleted file mode 100644
index 0b7241118ee..00000000000
--- a/usr.sbin/timed/timedc/timedc.8
+++ /dev/null
@@ -1,142 +0,0 @@
-.\" $OpenBSD: timedc.8,v 1.14 2007/05/31 19:20:30 jmc Exp $
-.\"
-.\" Copyright (c) 1980, 1991 Regents of the University of California.
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\" 3. Neither the name of the University nor the names of its contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" @(#)timedc.8 6.7 (Berkeley) 5/11/93
-.\"
-.Dd $Mdocdate: May 31 2007 $
-.Dt TIMEDC 8
-.Os
-.Sh NAME
-.Nm timedc
-.Nd timed control program
-.Sh SYNOPSIS
-.Nm timedc
-.Op Ar command Op Ar argument ...
-.Sh DESCRIPTION
-.Nm
-is used to control the operation of the
-.Xr timed 8
-program.
-It may be used to:
-.Pp
-.Bl -bullet -compact
-.It
-Measure the differences between machines' clocks,
-.It
-Find the location where the master time server is running,
-.It
-Enable or disable tracing of messages received by
-.Xr timed ,
-and
-.It
-Perform various debugging actions.
-.El
-.Pp
-Without any arguments,
-.Nm
-will prompt for commands from the standard input.
-If arguments are supplied,
-.Nm
-interprets the first argument as a command and the remaining
-arguments as parameters to the command.
-The standard input may be redirected causing
-.Nm
-to read commands from a file.
-Commands may be abbreviated;
-recognized commands are:
-.Pp
-.Bl -tag -width Ds -compact
-.It Ic \&? Op Ar command ...
-.Pp
-.It Ic help Op Ar command ...
-Print a short description of each command specified in the argument list,
-or, if no arguments are given, a list of the recognized commands.
-.Pp
-.It Ic clockdiff Ar host Op Ar ...
-Compute the differences between the clock of the host machine
-and the clocks of the machines given as arguments.
-.Pp
-.It Ic msite Op Ar host ...
-Show the master time server for specified host(s).
-.Pp
-.It Xo
-.Ic trace
-.Li \&{ Ar on Li \&|
-.Ar off \&}
-.Xc
-Enable or disable the tracing of incoming messages to
-.Xr timed
-in the file
-.Pa /var/log/timed.log .
-.Pp
-.It Ic election Ar host
-Asks the daemon
-on the target host to reset its
-.Dq election
-timers and to ensure that a time master has been elected.
-.Pp
-.It Ic quit
-Exit from timedc.
-.El
-.Pp
-Other commands may be included for use in testing and debugging
-.Xr timed ;
-the help command and
-the program source may be consulted for details.
-.Sh FILES
-.Bl -tag -width /var/log/timed.masterlog -compact
-.It Pa /var/log/timed.log
-tracing file for timed
-.It Pa /var/log/timed.masterlog
-log file for master timed
-.El
-.Sh DIAGNOSTICS
-.Bl -tag -width Ds -compact
-.It ?Ambiguous command
-abbreviation matches more than one command
-.It ?Invalid command
-no match found
-.It ?Privileged command
-command can be executed by root only
-.El
-.Sh SEE ALSO
-.Xr date 1 ,
-.Xr adjtime 2 ,
-.Xr icmp 4 ,
-.Xr timed 8
-.Rs
-.%T "TSP: The Time Synchronization Protocol for UNIX 4.3BSD"
-.%A R. Gusella
-.%A S. Zatti
-.Re
-.Sh HISTORY
-The
-.Nm
-command appeared in
-.Bx 4.3 .
diff --git a/usr.sbin/timed/timedc/timedc.c b/usr.sbin/timed/timedc/timedc.c
deleted file mode 100644
index 94d085dc107..00000000000
--- a/usr.sbin/timed/timedc/timedc.c
+++ /dev/null
@@ -1,273 +0,0 @@
-/* $OpenBSD: timedc.c,v 1.14 2009/10/27 23:59:57 deraadt Exp $ */
-
-/*-
- * Copyright (c) 1985, 1993 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include "timedc.h"
-#include <string.h>
-#include <signal.h>
-#include <ctype.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <syslog.h>
-
-int trace = 0;
-FILE *fd = NULL;
-int margc;
-int fromatty;
-#define MAX_MARGV 20
-char *margv[MAX_MARGV];
-char cmdline[200];
-
-static struct cmd *getcmd(char *);
-volatile sig_atomic_t gotintr;
-
-int
-main(int argc, char *argv[])
-{
- extern int sock_raw, sock;
- struct sockaddr_in sin;
- struct cmd *c;
-
- sock_raw = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
- if (sock_raw < 0) {
- perror("opening raw socket");
- exit(1);
- }
-
- openlog("timedc", LOG_ODELAY, LOG_AUTH);
-
- sock = socket(AF_INET, SOCK_DGRAM, 0);
- if (sock < 0) {
- perror("opening socket");
- (void)close(sock_raw);
- return (-1);
- }
-
- memset(&sin, 0, sizeof sin);
- sin.sin_family = AF_INET;
- sin.sin_addr.s_addr = INADDR_ANY;
- if (bind(sock, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
- fprintf(stderr, "all reserved ports in use\n");
- (void)close(sock_raw);
- exit(1);
- }
-
- if (--argc > 0) {
- c = getcmd(*++argv);
- if (c == (struct cmd *)-1) {
- printf("?Ambiguous command\n");
- exit(1);
- }
- if (c == 0) {
- printf("?Invalid command\n");
- exit(1);
- }
- if (c->c_priv && getuid()) {
- printf("?Privileged command\n");
- exit(1);
- }
- (*c->c_handler)(argc, argv);
- exit(0);
- }
-
- fromatty = isatty(fileno(stdin));
- (void) signal(SIGINT, sigintr);
- for (;;) {
- if (gotintr) {
- putchar('\n');
- gotintr = 0;
- }
- if (fromatty) {
- printf("timedc> ");
- (void) fflush(stdout);
- }
-
- siginterrupt(SIGINT, 1);
- if (fgets(cmdline, sizeof(cmdline), stdin) == NULL) {
- if (errno == EINTR && gotintr) {
- siginterrupt(SIGINT, 0);
- continue;
- }
- quit(0, NULL);
- }
- siginterrupt(SIGINT, 0);
-
- if (cmdline[0] == 0)
- break;
- if (makeargv()) {
- printf("?Too many arguments\n");
- continue;
- }
- if (margv[0] == 0)
- continue;
- c = getcmd(margv[0]);
- if (c == (struct cmd *)-1) {
- printf("?Ambiguous command\n");
- continue;
- }
- if (c == 0) {
- printf("?Invalid command\n");
- continue;
- }
- if (c->c_priv && getuid()) {
- printf("?Privileged command\n");
- continue;
- }
- (*c->c_handler)(margc, margv);
- }
- return 0;
-}
-
-void
-sigintr(int signo)
-{
- if (!fromatty)
- _exit(0);
- gotintr = 1;
-}
-
-static struct cmd *
-getcmd(char *name)
-{
- char *p, *q;
- struct cmd *c, *found;
- int nmatches, longest;
- extern struct cmd cmdtab[];
- extern int NCMDS;
-
- longest = 0;
- nmatches = 0;
- found = 0;
- for (c = cmdtab; c < &cmdtab[NCMDS]; c++) {
- p = c->c_name;
- for (q = name; *q == *p++; q++)
- if (*q == 0) /* exact match? */
- return (c);
- if (!*q) { /* the name was a prefix */
- if (q - name > longest) {
- longest = q - name;
- nmatches = 1;
- found = c;
- } else if (q - name == longest)
- nmatches++;
- }
- }
- if (nmatches > 1)
- return ((struct cmd *)-1);
- return (found);
-}
-
-/*
- * Slice a string up into argc/argv.
- */
-int
-makeargv(void)
-{
- char **argp = margv;
- char *cp;
-
- margc = 0;
- for (cp = cmdline; margc < MAX_MARGV - 1 && *cp; ) {
- while (isspace(*cp))
- cp++;
- if (*cp == '\0')
- break;
- *argp++ = cp;
- margc += 1;
- while (*cp != '\0' && !isspace(*cp))
- cp++;
- if (*cp == '\0')
- break;
- *cp++ = '\0';
- }
- if (margc == MAX_MARGV - 1)
- return 1;
- *argp++ = 0;
- return 0;
-}
-
-#define HELPINDENT (sizeof ("directory"))
-
-/*
- * Help command.
- */
-void
-help(int argc, char *argv[])
-{
- extern struct cmd cmdtab[];
- struct cmd *c;
-
- if (argc == 1) {
- int columns, width = 0, lines;
- extern int NCMDS;
- int i, j, w;
-
- printf("Commands may be abbreviated. Commands are:\n\n");
- for (c = cmdtab; c < &cmdtab[NCMDS]; c++) {
- int len = strlen(c->c_name);
-
- if (len > width)
- width = len;
- }
- width = (width + 8) &~ 7;
- columns = 80 / width;
- if (columns == 0)
- columns = 1;
- lines = (NCMDS + columns - 1) / columns;
- for (i = 0; i < lines; i++) {
- for (j = 0; j < columns; j++) {
- c = cmdtab + j * lines + i;
- printf("%s", c->c_name);
- if (c + lines >= &cmdtab[NCMDS]) {
- printf("\n");
- break;
- }
- w = strlen(c->c_name);
- while (w < width) {
- w = (w + 8) &~ 7;
- putchar('\t');
- }
- }
- }
- return;
- }
- while (--argc > 0) {
- char *arg;
- arg = *++argv;
- c = getcmd(arg);
- if (c == (struct cmd *)-1)
- printf("?Ambiguous help command %s\n", arg);
- else if (c == (struct cmd *)0)
- printf("?Invalid help command %s\n", arg);
- else
- printf("%-*s\t%s\n", (int)HELPINDENT,
- c->c_name, c->c_help);
- }
-}
diff --git a/usr.sbin/timed/timedc/timedc.h b/usr.sbin/timed/timedc/timedc.h
deleted file mode 100644
index 9e121b887ac..00000000000
--- a/usr.sbin/timed/timedc/timedc.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/* $OpenBSD: timedc.h,v 1.6 2004/05/31 10:38:20 otto Exp $ */
-
-/*-
- * Copyright (c) 1985, 1993 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)timedc.h 5.1 (Berkeley) 5/11/93
- */
-
-#include <sys/param.h>
-#include <sys/time.h>
-#ifdef sgi
-#include <sys/uio.h>
-#endif
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-#include <errno.h>
-#include <netdb.h>
-#include <stdio.h>
-
-
-#define ON 1
-#define OFF 0
-
-#define GOOD 1
-#define UNREACHABLE 2
-#define NONSTDTIME 3
-#define HOSTDOWN 0x7fffffff
-
-struct cmd {
- char *c_name; /* command name */
- char *c_help; /* help message */
- void (*c_handler)(int, char **); /* routine to do the work */
- int c_priv; /* privileged command */
-};
-
-#include "timedc-extern.h"