]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
Many files:
authorHarlan Stenn <stenn@ntp.org>
Tue, 25 Jul 2000 00:45:02 +0000 (00:45 -0000)
committerHarlan Stenn <stenn@ntp.org>
Tue, 25 Jul 2000 00:45:02 +0000 (00:45 -0000)
  * ntpd/ntp_request.c:
  * ntpd/ntp_proto.c:
  * ntpd/ntp_peer.c:
  * ntpd/ntp_io.c:
  * ntpd/ntp_intres.c:
  * ntpd/ntp_crypto.c (make_keylist):
  * ntpd/ntp_control.c:
  * ntpd/ntp_config.c (CONF_MOD_IBURST, save_resolve):
  * include/ntpd.h (findpeerbyassoc, newpeer, peer_config, *_interface):
  * include/ntp_request.h (CONF_FLAG_IBURST):
  * include/ntp_crypto.h (crypto_xmit, make_keylist):
  * include/ntp.h (FLAG_IBURST):
  * html/release.htm:
  * html/confopt.htm:
  * html/assoc.htm:
  Add iburst option, fix broadcast/multicast and some types.
  From: Dave Mills

bk: 397ce30eCJ_VvQV1LJN2F5eu05rDHw

18 files changed:
ChangeLog
configure
configure.in
html/assoc.htm
html/confopt.htm
html/release.htm
include/ntp.h
include/ntp_crypto.h
include/ntp_request.h
include/ntpd.h
ntpd/ntp_config.c
ntpd/ntp_control.c
ntpd/ntp_crypto.c
ntpd/ntp_intres.c
ntpd/ntp_io.c
ntpd/ntp_peer.c
ntpd/ntp_proto.c
ntpd/ntp_request.c

index 2fa9f3a0cba5a2bfd98102d2057557f7b188c3a2..86d7867849e2d2b4bfbcb11dd40c97ea30563010 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+2000-07-24  Harlan Stenn  <stenn@whimsy.udel.edu>
+
+       * ntpd/ntp_request.c: 
+       * ntpd/ntp_proto.c: 
+       * ntpd/ntp_peer.c: 
+       * ntpd/ntp_io.c: 
+       * ntpd/ntp_intres.c: 
+       * ntpd/ntp_crypto.c (make_keylist): 
+       * ntpd/ntp_control.c: 
+       * ntpd/ntp_config.c (CONF_MOD_IBURST, save_resolve): 
+       * include/ntpd.h (findpeerbyassoc, newpeer, peer_config, *_interface): 
+       * include/ntp_request.h (CONF_FLAG_IBURST): 
+       * include/ntp_crypto.h (crypto_xmit, make_keylist): 
+       * include/ntp.h (FLAG_IBURST): 
+       * html/release.htm: 
+       * html/confopt.htm: 
+       * html/assoc.htm: 
+       Add iburst option, fix broadcast/multicast and some types.
+       From: Dave Mills
+
 2000-07-20  Harlan Stenn  <stenn@whimsy.udel.edu>
 
        * scripts/Makefile.am (bin_SCRIPTS): Install ntp-wait
index 57028a91a7a9336cf883025539564c45533dcccf..92ac3a8db72e3b4d3f9e9b1eed2528038c6f7bb4 100755 (executable)
--- a/configure
+++ b/configure
@@ -1091,7 +1091,7 @@ fi
 
 PACKAGE=ntp
 
-VERSION=4.0.99k
+VERSION=4.0.99k1
 
 if test "`CDPATH=: && cd $srcdir && pwd`" != "`pwd`" &&
    test -f $srcdir/config.status; then
index 592b105a67b725c8b1d9fbe93053e2cd8e543909..e752cc586f822f8ba3e2ff49b744104b4ce7550a 100644 (file)
@@ -5,7 +5,7 @@ AC_CANONICAL_SYSTEM
 AC_DEFINE_UNQUOTED(STR_SYSTEM, "$target")
 AM_CONFIG_HEADER(config.h)
 AC_ARG_PROGRAM
-AM_INIT_AUTOMAKE(ntp, 4.0.99k)
+AM_INIT_AUTOMAKE(ntp, 4.0.99k1)
 AC_PREREQ(2.14)
 
 ac_cv_var_oncore_ok=no
index 69cb7bc5b1f20cd84153adc601a19ee06464dba6..1303a4aa7ba55f1e43b956b3aee18e5d07614036 100644 (file)
-<HTML>
-<HEAD>
-   <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
-   <META NAME="GENERATOR" CONTENT="Mozilla/4.01 [en] (Win95; I) [Netscape]">
-   <TITLE>Release Notes
-</TITLE>
-</HEAD>
-<BODY>
-
-<H3>
-Association Management</H3>
-
-<HR>
-<H4>
-Association Modes</H4>
-This release of the NTP Version 4 (NTPv4) daemon for Unix incorporates
-new features and refinements to the NTP Version 3 (NTPv3) algorithms. However,
-it continues the tradition of retaining backwards compatibility with older
-versions. The NTPv4 version has been under development for quite a while
-and isn't finished yet. In fact, quite a number of NTPv4 features have
-already been implemented in the current NTPv3, including a number of new
+<HTML><TITLE>
+Association Management
+</TITLE></HEAD><BODY><H3>
+Association Management
+</H3><HR>
+
+<H4>Association Modes</H4>
+
+The NTP Version 4 incorporates new features and refinements to the NTP
+Version 3 (NTPv3) algorithms. However, it continues the tradition of
+retaining backwards compatibility with older versions. However, a number
+of new features have been implemented, including a number of new
 operating modes for automatic server discovery and improved accuracy in
-occasionally-connected networks. Following is an extended abstract describing
-the new features..
-
-<P>An ephemeral association of some mode is mobilized when a message arrives
-from another client or server. For instance, a symmetric-passive association
-is mobilized upon arrival of a message from a symmetric- active peer. A
-client association is mobilized upon arrival of a broadcast message from
-a multicast server or a server message from a manycast server. Ephemeral
-associations are demobilized when either (a) the server becomes unreachable
-or (b) an error occurs on initial contact before the association is mobilized.
-
-<P>The one exception to (a) and (b) above is when
-<TT><A HREF="authopt.htm">autokey</A></TT> is in use and the initial
-authentication check fails due to unknown
-key identifier or autokey mismatch. This exception is necessary because
-the Unix kernel does not bind the local address until the first packet
-is received. The result in broadcast mode is a rather painful initial exchange,
-where authentication fails until after the first round of messages. The
-result in multicast mode is in general fatal, especially if multiple interfaces
-are in use. As promiscuous modes such as multicast and manycast require
-authentication for reliable and safe operation, autokey is in general useless
-with these modes until and if the input/output machinery is overhauled.
+occasionally-connected networks. Following is an extended abstract
+describing the new features. Additional information is available on the
+<a href=confopt.htm>Configuration Options</a> page..
+
+<P>An ephemeral association of some mode is mobilized when a message
+arrives from a server or peer. For instance, a symmetric-passive
+association is mobilized upon arrival of a message from a symmetric-
+active peer. A client association is mobilized upon arrival of a
+broadcast message from a multicast server or a server message from a
+manycast server. Ordinarily, successful mobilization requires the server
+or peer provide acceptable cryptographic credentials, either using
+traditional symmetric-key cryptography or public-key cryptography new to
+NTPv4. Ephemeral associations are demobilized when either (a) the server
+becomes unreachable or (b) the server refreshes key media without
+notifying the client.
 
 <P>Following is a summary of the protocol operations for each mode.
 
-<P>Peer Modes (Active and Passive)
+<P>Symmetric Modes (Active and Passive)
+
 <UL>In these modes, two client/server peers agree to back each other up,
-should the synchronization source for either peer fail. One or both peers
-is configured in symmetric-active mode using the peer command. Alternatively,
-one - the active peer - is configured in this mode and the other, the passive
-peer, operates in symmetric-passive mode and requires no prior configuration.
-Both association scenarios operate in NTPv4 as in NTPv3; however, several
-bugs in the handling of keys and recovery of resources when an active peer
-fails, have been corrected in NTPv4. The original NTPv3 authentication
-scheme is applicable in this mode, as well as the new NTPv3 autokey scheme.</UL>
+should the synchronization source for either peer fail. One or both
+peers is configured in symmetric-active mode using the <tt>peer</tt>
+command. Alternatively, one - the active peer - is configured in this
+mode and the other, the passive peer, operates in symmetric-passive mode
+and requires no prior configuration. Both association scenarios operate
+in NTPv4 as in NTPv3; however, several bugs in the handling of keys and
+recovery of resources when an active peer fails have been corrected in
+NTPv4. The original NTPv3 authentication scheme is applicable in this
+mode, as well as the new NTPv3 autokey scheme.</UL>
+
 Client/Server Modes
-<UL>In these modes, a client sends a request to the server and expects
-a reply at some future time. The client is configured in client mode using
-the server (sic) command; the server requires no prior configuration. The
-original NTPv3 authentication scheme is applicable in this mode, as well
-as the new NTPv3 autokey scheme.</UL>
+
+<UL>In these modes, a client sends a request to the server and expects a
+reply at some future time. The client is configured in client mode using
+the <tt>server</tt> (sic) command; the server requires no prior
+configuration. The original NTPv3 authentication scheme is applicable in
+this mode, as well as the new NTPv3 autokey scheme. In addition, the
+burst modes described below can be used in appropriate cases.</UL>
+
 Broadcast/Multicast Modes
+
 <UL>In these modes, the server generates messages at intervals specified
-by the minpoll subcommand. When using IP multicast addresses, the scope
-of the multicast tree is specified by the ttl subcommand in hops. When
-using a local interface broadcast address, the scope is limited to the
-attached subnet. The client responds to the first message received by waiting
-an interval randomized over the minpoll interval, in order to avoid implosions.
-Then, it polls the server in burst mode, in order to accumulate data to
-reliably set the host clock. This normally results in eight client/server
-cycles over a 32-s interval. When the next multicast message is received,
-the client computes the offset between the system clock just set and the
-apparent time of the multicast message in order to correct the apparent
-time in future multicast messages.</UL>
+by the <tt>minpoll</tt> keyword to the configuration command. When using
+IP multicast addresses, the scope of the multicast tree is specified by
+the <tt>ttl</tt> keyword in hops. When using a local interface broadcast
+address, the scope is limited to the attached subnet. The client
+responds to the first message received by waiting an interval randomized
+over the <tt>minpoll</tt> interval, in order to avoid implosions. Then,
+it polls the server in burst mode in order to accumulate data to
+reliably set the host clock. This normally results in eight
+client/server cycles over a 30-s interval. When the next multicast
+message is received, the client computes the offset between the system
+clock just set and the apparent time of the multicast message in order
+to correct the apparent time in future multicast messages.</UL>
+
 Manycast Mode
+
 <UL>In this mode, a configured client broadcasts a request message as in
-client mode to a designated multicast group address. All servers configured
-as manycast clients and in ttl range respond with a server reply message.
-Each reply mobilizes a persistent client/server association as in client
-mode. Then, the NTP intersection and clustering algorithms act to discard
-all but the "best" of these associations, which then continue as in client/server
-mode.</UL>
-
-<H4>
-Burst Mode</H4>
-Burst mode can be configured when the network attachment requires an initial
-calling or training procedure. Each poll initiates a burst of eight request
-messages at intervals randomized over the range 3-5 s. The reply messages
-update the clock filter, which then selects the best (most accurate) among
-them. When the last reply in the burst is sent, the next reply updates
-the client variables and system clock in the usual manner, as if only a
-single request/reply cycle had occurred. This mode does produce additional
-network overhead and can cause trouble if used indiscriminately. It should
-only be used where the poll interval is expected to settle to values above
-1024 s.
-<H4>
-Revised Error Checking</H4>
-It is very important to avoid spurious mobilizations from possibly broken
-or rogue servers; in particular, to avoid denial-of-service attacks. In
-order to resist such attacks, arriving messages that might mobilize ephemeral
-associations are carefully screened using a series of eleven sanity checks.
-<OL>
-<LI>
-Duplicate packet. This message is a duplicate of one previously received.</LI>
-
-<BR>&nbsp;
-<LI>
-Bogus packet. This message did not result from a message previously sent,
-or messages have been received out of order.</LI>
-
-<BR>&nbsp;
-<LI>
-Unsynchronized. The server has not yet stored the previous timestamps.</LI>
-
-<BR>&nbsp;
-<LI>
-Invalid delay or dispersion. Either the delay or dispersion or both computed
-from the message timestamps are above the normal range.</LI>
-
-<BR>&nbsp;
-<LI>
-Authentication failed. The sent MAC does not match the received MAC, either
-due to the wrong key material or damaged message.</LI>
-
-<BR>&nbsp;
-<LI>
-Server unsynchronized. The server indicates unsynchronized in the leap
-bits included in the packet.</LI>
-
-<BR>&nbsp;
-<LI>
-Server stratum check. The server is operating at a stratum above the normal
-range.</LI>
-
-<BR>&nbsp;
-<LI>
-Delay/dispersion check. The related server packet data values are above
-the normal range.</LI>
-
-<BR>&nbsp;
-<LI>
-Autokey failed. The hash of the current session key does not match the
-most recent key identifiers used. (The hash is repeated four times, in
-order to recover from lost packets whenever possible.)</LI>
-
-<BR>&nbsp;
-<LI>
-Access denied. The sender has been blocked by the access control list.</LI>
-
-<BR>&nbsp;
-<LI>
-Key not found. The key identifier does not match any identifier in the
-key list or the key has expired or been revoked.</LI>
-</OL>
-Failure to pass tests 5-11 is sufficient evidence to discard the packet
-without forming an association. However, failure to pass tests 1-4 is not
-necessarily grounds to reject the packet, since subsequent packets may
-be acceptable. In this case, the association is mobilized, but only the
-packet timestamps are stored. For the moment, and until the cryptographic
-signature algorithm is available, test 9 is temporarily disabled.
-<BR>
-<HR>
-<ADDRESS>
-David L. Mills (mills@udel.edu)</ADDRESS>
-
-<BR>&nbsp;
-</BODY>
-</HTML>
+client mode to a designated multicast group address. All servers
+configured as manycast servers and in <tt>ttl</tt> range respond with a
+server reply message. Each reply mobilizes a persistent client/server
+association as in client mode. Then, the NTP intersection and clustering
+algorithms act to discard all but the "best" of these associations,
+which then continue as in client/server mode.
+
+<p>The above scenario happens at each manycast message; however, once
+the persisten association has been mobilized, subsequent server replies
+are discarded, since they fail one or more of the authentication checks.
+It is important in manycast mode to avoid frequeny request messages,
+since each one requires all manycast servers in range to respond. The
+result could well be an implosion, either minor or major, depending on
+the number of servers in range.</UL>
+
+<H4>Burst Modes</H4>
+
+<p>There are two burst modes that can be activated for client/server
+mode. One of these <tt>iburst</tt> is intended for cases where it is
+important to set the clock quickly when an association is first
+mobilized. It results in good accuracy with intermittent connections
+typical of PPP and ISDN services. When enabled, at each poll interval
+the client sends eight messages over the next 30-s and processes them in
+a batch. However, the interval between the first and subsequent messages
+is about 20 s in order for a dialup modem to complete the call. Outlyers
+due to initial dial-up delays, etc., are avoided and the client sets the
+clock within 30 s after the first message.</LI>
+
+<p>The other burst mode <tt>burst</tt> can be configured when the
+network attachment requires an initial calling or training procedure.
+Each poll initiates a burst of eight request messages at intervals
+randomized over the range 3-5 s. The reply messages update the clock
+filter, which then selects the best (most accurate) among them. When the
+last reply in the burst is sent, the next reply updates the client
+variables and system clock in the usual manner, as if only a single
+request/reply cycle had occurred. This mode does produce additional
+network overhead and can cause trouble if used indiscriminately. It
+should only be used where the poll interval is expected to settle to
+values above 1024 s.
+
+
+<hr><a href=index.htm><img align=left src=pic/home.gif></a><address><a
+href=mailto:mills@udel.edu> David L. Mills &lt;mills@udel.edu&gt;</a>
+</address></a></body></html>
index e3a8a629807ac5135630690c20037373857c82ad..0c09a5115374fc832c55f0370034b72a9cd03b33 100644 (file)
@@ -22,29 +22,25 @@ remote server or peer (IP class A, B and C), (b) the broadcast address
 of a local interface, (m) a multicast address (IP class D), or (r) a
 reference clock address (127.127.x.x). Note that some options are not
 supported by all these commands while autokey and burst modes are
-supported by these commands,
-their effect in some weird mode combinations can be meaningless
-or even destructive.
+supported by these commands, their effect in some weird mode
+combinations can be meaningless or even destructive.
 
 <dl>
 
-<dt><tt>peer <i>address</i> [key <i>key</i> | autokey | publickey
-<i>keyfile</i>] [burst] [version <i>version</i>] [prefer] [minpoll
-<i>minpoll</i>] [maxpoll <i>maxpoll</i>]</tt></dt>
+<dt><tt>peer <i>address</i> [key <i>key</i> | autokey] [version
+<i>version</i>] [prefer] [minpoll <i>minpoll</i>] [maxpoll
+<i>maxpoll</i>]</tt></dt>
 
-<p><dt><tt>server <i>address</i> [key <i>key</i> | autokey | publickey
-<i>keyfile</i>] [burst] [version <i>version</i>] [prefer] [minpoll
-<i>minpoll</i>] [maxpoll <i>maxpoll</i>] [publickey
-<i>keyfile</i>]</tt></dt>
+<p><dt><tt>server <i>address</i> [key <i>key</i> | autokey] [burst]
+[iburst] [version <i>version</i>] [prefer] [minpoll <i>minpoll</i>]
+[maxpoll <i>maxpoll</i>]</tt></dt>
 
-<p><dt><tt>broadcast <i>address</i> [key <i>key</i> | autokey] [burst]
-[version <i>version</i>] [minpoll <i>minpoll</i>] [maxpoll
-<i>maxpoll</i>] [ttl <i>ttl</i>]</tt></dt>
+<p><dt><tt>broadcast <i>address</i> [key <i>key</i> | autokey] [version
+<i>version</i>] [minpoll <i>minpoll</i>] [ttl <i>ttl</i>]</tt></dt>
 
-<p><dt><tt>manycastclient <i>address</i> [key <i>key</i> | autokey |
-publickey <i>keyfile</i>] [burst] [version <i>version</i>] [minpoll
-<i>minpoll</i> [maxpoll <i>maxpoll</i>] [ttl <i>ttl</i>] [publickey
-<i>file</i>]</tt></dt>
+<p><dt><tt>manycastclient <i>address</i> [key <i>key</i> | autokey]
+[version <i>version</i>] [minpoll <i>minpoll</i> [ttl
+<i>ttl</i>]</tt></dt>
 
 <p><dd>These four commands specify the time server name or address to
 be used and the mode in which to operate. The <i>address</i> can be
@@ -129,9 +125,13 @@ are discarded as if never heard.</dd>
 include authentication fields encrypted using the autokey scheme
 described in the <a href=authopt.htm>Authentication Options</a>
 page.</dd>
+
 <dt><tt>burst</tt></dt>
-<dd>At each poll interval, send a burst of eight packets spaced, instead
-of the usual one.</dd>
+<dd>At each poll interval, send a burst of eight packets spaced at 1-s
+intervals instead of the usual one.</dd>
+<dt><tt>iburst</tt></dt>
+<dd>At the first poll interval, send a burst of eight packets spaced at
+1-s intervals instead of the usual one.</dd>
 
 <dt><tt>key </tt><i><tt>key</tt></i></dt>
 <dd>All packets sent to and received from the server or peer are to
@@ -152,14 +152,6 @@ host will be chosen for synchronization among a set of correctly
 operating hosts. See the <a href="prefer.htm">Mitigation Rules and the
 <tt>prefer</tt> Keyword </a>page for further information.</dd>
 
-<DT><TT>publickey <I>file</I></TT></DT>
-<DD>This command requires the NTP daemon build process be configured
-with the RSA library. The command specifies the name of the public key
-file for the server or peer. The default name for this file is
-<tt>ntpkey_<i>host</i></tt>, where <i>host</i> is the DNS canonical name
-of the server or peer. See the <a href=authopt.htm>Authentication
-Options</a> page for further information.</dd>
-
 <dt><tt>ttl <i>ttl</i></tt></dt>
 <dd>This option is used only with broadcast mode. It specifies the
 time-to-live <i><tt>ttl</tt></i> to use on multicast packets. Selection
index 7f31b38b17b440bc842f65c31add7f8206669278..9b4d9c0e002e010876bb91879eb99d65b97b7950 100644 (file)
@@ -51,23 +51,15 @@ in such cases was clamped to the minimum, usually 64 s. For those
 servers with hundreds of clients, the new design can dramatically reduce
 the network load.</LI>
 
-<P><LI>A <A HREF=assoc.htm>burst-mode</A> feature is available which
-results in good accuracy with intermittent connections typical of PPP
-and ISDN services. When enabled, at each poll interval the server sends
-eight messages over the next 30-s interval and processes them in a
-batch. However, the interval between the first and subsequent messages
-is about 20 s in order for a dialup modem to complete the call. Outlyers
-due to initial dial-up delays, etc., are avoided and the server
-synchronizes with its peer generally within 30 s.</LI>
-
-<P><LI>In addition to the NTPv3 authentication scheme, which uses
-private-key cryptography, a new NTPv4 <A HREF=authopt.htm>autokey
-</A>authentication scheme is available. Autokey uses public-key
-technology and avoids the need to distribute keys by separate means. The
-design is such that full accuracy is available without degradation due
-to processing demands of the public-key routines. It can be used in any
-of the NTP association modes, but is most useful in broadcast/multicast
-modes.</LI>
+<P><LI>There are two <A HREF=assoc.htm>burst-mode</A> features available
+where special conditions apply. One of these is enabled by the
+<tt>iburst</tt> keyword in the <tt>server</tt> configuration command. It
+is intended for cases where it is important to set the clock quickly
+when an association is first mobilized. The other is enabled by the
+<tt>burst</tt> keyword in the <tt>server</tt> configuration command. It
+is intended for cases where the network attachment requires an initial
+calling or training procedure. See the <A HREF=assoc.htm>Association
+Management</a> page for further information.
 
 <P><LI>NTPv4 includes two new association modes which in most
 applications can avoid per-host configuration altogether. Both of these
@@ -137,7 +129,6 @@ note the NTP authentication routines use the interface defined in the
 <P><LI>The enable and disable commands have a few changes in their
 arguments see the <TT>ntpd</TT> <A HREF=confopt.htm>Configuration
 Options</A> page for details.</LI>
-
 <P><LI>The scheme for enabling the <TT>ppsclock</TT> line
 discipline/streams module has changed. Formerly, it was enabled by
 setting <TT>fudge flag3</TT> for the serial port connected to the PPS
@@ -187,7 +178,8 @@ kernel</TT> command either in the configuration file or via
 <TT>ntpdc</TT>.</LI>
 
 <p><li>A new pulse-per-second (PPS) generic interface described in <a
-href=http://www.eecis.udel.edu/~mills/reports.htm>Mogul, J., D. Mills, J.
+href=http://www.eecis.udel.edu/~mills/reports.htm>Mogul, J., D. Mills,
+J.
 Brittenson, J. Stone and U. Windl. Pulse-per-second API for Unix-like
 operating systems, version 1. Request for Comments RFC-2783, Internet
 Engineering Task Force, March 2000, 31 pp</a> is supported. Older
index cf1050f9e698224cb6b2896b325033e0ccc3c57a..d96cb6566048749e6dedf0fd6c30a1f696587c0c 100644 (file)
@@ -406,9 +406,10 @@ struct peer {
 #define        FLAG_SYSPEER    0x0040  /* this is one of the selected peers */
 #define FLAG_PREFER    0x0080  /* this is the preferred peer */
 #define FLAG_BURST     0x0100  /* burst mode */
-#define FLAG_SKEY      0x0200  /* autokey authentication */
-#define FLAG_NOSELECT  0x0400  /* this is a "noselect" peer */
-#define FLAG_AUTOKEY   0x0800  /* autokey confirmed */
+#define FLAG_IBURST    0x0200  /* initial burst mode */
+#define FLAG_SKEY      0x0400  /* autokey authentication */
+#define FLAG_NOSELECT  0x0800  /* this is a "noselect" peer */
+#define FLAG_AUTOKEY   0x1000  /* autokey confirmed */
 
 /*
  * Definitions for the clear() routine.  We use memset() to clear
index b9731623df302e77e206170a38895289b81c572f..27b2ae2b67996c1599ba260d8b1d58edac9e2586 100644 (file)
  */
 extern void    crypto_recv     P((struct peer *, struct recvbuf *));
 extern int     crypto_xmit     P((u_int32 *, int, u_int, keyid_t,
-                                   associd_t));
+                                   u_int));
 extern keyid_t session_key     P((struct sockaddr_in *, struct
                                    sockaddr_in *, keyid_t, keyid_t,
                                    u_long));
-extern void    make_keylist    P((struct peer *));
+extern void    make_keylist    P((struct peer *, struct interface *));
 extern void    key_expire      P((struct peer *));
 extern void    crypto_agree    P((void));
 #ifdef PUBKEY
index 4457c6ae9e41cefdc0db3cfac8d40c7af608276c..8af524814bd8996e42a663dbf9abac315c7c46ec 100644 (file)
@@ -532,11 +532,12 @@ struct conf_peer {
        char keystr[MAXFILENAME]; /* public key file name*/
 };
 
-#define        CONF_FLAG_AUTHENABLE    0x1
-#define CONF_FLAG_PREFER       0x2
-#define CONF_FLAG_BURST                0x4
-#define CONF_FLAG_NOSELECT     0x8
-#define CONF_FLAG_SKEY         0x10
+#define        CONF_FLAG_AUTHENABLE    0x01
+#define CONF_FLAG_PREFER       0x02
+#define CONF_FLAG_BURST                0x04
+#define CONF_FLAG_IBURST       0x08
+#define CONF_FLAG_NOSELECT     0x10
+#define CONF_FLAG_SKEY         0x20
 
 /*
  * Structure for passing peer deletion information.  Currently
index 852ed63e2d90e152741f5f642db9e5e3c44979ee..b077c984b571035dcaa7ccc8e8cbf2ee81c98a01 100644 (file)
@@ -124,18 +124,17 @@ extern    void    ntp_monitor P((struct recvbuf *));
 extern void    init_peer       P((void));
 extern struct peer *findexistingpeer P((struct sockaddr_in *, struct peer *, int));
 extern struct peer *findpeer   P((struct sockaddr_in *, struct interface *, int, int, int *));
-extern struct peer *findpeerbyassoc P((associd_t));
-extern struct peer *newpeer    P((struct sockaddr_in *, struct interface *, int, int, int, int, int, u_long));
+extern struct peer *findpeerbyassoc P((u_int));
+extern struct peer *newpeer    P((struct sockaddr_in *, struct interface *, int, int, int, int, u_int, int, keyid_t));
 extern void    peer_all_reset  P((void));
 extern void    peer_clr_stats  P((void));
-extern struct peer *peer_config P((struct sockaddr_in *, struct interface *, int, int, int, int, int, int, keyid_t, u_char *));
+extern struct peer *peer_config P((struct sockaddr_in *, struct interface *, int, int, int, int, u_int, int, keyid_t, u_char *));
 extern void    peer_reset      P((struct peer *));
 extern int     peer_unconfig   P((struct sockaddr_in *, struct interface *, int));
 extern void    unpeer          P((struct peer *));
 extern void    clear_all       P((void));
 extern void    expire_all      P((void));
 extern struct  peer *findmanycastpeer  P((l_fp *));
-extern void    peer_config_manycast    P((struct peer *, struct peer *));
 
 /* ntp_proto.c */
 extern void    transmit        P((struct peer *));
@@ -252,8 +251,9 @@ extern u_long       io_timereset;           /* time counters were reset */
 /*
  * Interface stuff
  */
-extern struct interface *any_interface;        /* pointer to default interface */
-extern struct interface *loopback_interface;   /* point to loopback interface */
+extern struct interface *any_interface;        /* default interface */
+extern struct interface *loopback_interface; /* loopback interface */
+extern struct interface *mcast_interface; /* multicast interface */
 
 /*
  * File descriptor masks etc. for call to select
index 0225127c65407fb8985b301582fd6d41efcb56c7..0a28bbad928da5aed43d06a27b4ac3bbab23f67f 100644 (file)
@@ -154,12 +154,13 @@ extern int priority_done;
 #define CONF_MOD_MAXPOLL       4
 #define CONF_MOD_PREFER                5
 #define CONF_MOD_BURST         6
-#define CONF_MOD_SKEY          7
-#define CONF_MOD_TTL           8
-#define CONF_MOD_MODE          9
-#define CONF_MOD_NOSELECT      10
+#define CONF_MOD_IBURST                7
+#define CONF_MOD_SKEY          8
+#define CONF_MOD_TTL           9
+#define CONF_MOD_MODE          10
+#define CONF_MOD_NOSELECT      11
 #ifdef PUBKEY
-#define CONF_MOD_PUBLICKEY     11
+#define CONF_MOD_PUBLICKEY     12
 #endif /* PUBKEY */
 
 /*
@@ -282,6 +283,7 @@ static      struct keyword keywords[] = {
 static struct keyword mod_keywords[] = {
        { "autokey",            CONF_MOD_SKEY },
        { "burst",              CONF_MOD_BURST },
+       { "iburst",             CONF_MOD_IBURST },
        { "key",                CONF_MOD_KEY },
        { "maxpoll",            CONF_MOD_MAXPOLL },
        { "minpoll",            CONF_MOD_MINPOLL },
@@ -509,7 +511,7 @@ static      int gettokens_netinfo P((struct netinfo_config_state *, char **, int *));
 static int gettokens P((FILE *, char *, char **, int *));
 static int matchkey P((char *, struct keyword *));
 static int getnetnum P((const char *, struct sockaddr_in *, int));
-static void save_resolve P((char *, int, int, int, int, int, int,
+static void save_resolve P((char *, int, int, int, int, u_int, int,
     keyid_t, u_char *));
 static void do_resolve_internal P((void));
 static void abort_resolve P((void));
@@ -715,7 +717,7 @@ getconfig(
        keyid_t peerkey;
        u_char *peerkeystr;
        u_long fudgeflag;
-       int peerflags;
+       u_int peerflags;
        int hmode;
        struct sockaddr_in peeraddr;
        struct sockaddr_in maskaddr;
@@ -1100,6 +1102,10 @@ getconfig(
                                case CONF_MOD_BURST:
                                    peerflags |= FLAG_BURST;
                                    break;
+
+                               case CONF_MOD_IBURST:
+                                   peerflags |= FLAG_IBURST;
+                                   break;
 #ifdef AUTOKEY
                                case CONF_MOD_SKEY:
                                    peerflags |= FLAG_SKEY |
@@ -1160,10 +1166,9 @@ getconfig(
                            }
        
                        } else if (errflg == -1) {
-                               save_resolve(tokens[1], hmode,
-                                   peerversion, minpoll, maxpoll,
-                                   peerflags, ttl, peerkey,
-                                   peerkeystr);
+                               save_resolve(tokens[1], hmode, peerversion,
+                                   minpoll, maxpoll, peerflags, ttl,
+                                   peerkey, peerkeystr);
                        }
                        break;
 
@@ -1255,20 +1260,10 @@ getconfig(
                        } else
                            proto_config(PROTO_MULTICAST_ADD,
                                         htonl(INADDR_NTP), 0.);
-                       if (tok == CONFIG_MULTICASTCLIENT) {
+                       if (tok == CONFIG_MULTICASTCLIENT)
                                sys_bclient = 1;
-#ifdef DEBUG
-                               if (debug)
-                                   printf("sys_bclient\n");
-#endif /* DEBUG */
-                       }
-                       else if (tok == CONFIG_MANYCASTSERVER) {
+                       else if (tok == CONFIG_MANYCASTSERVER)
                                sys_manycastserver = 1;
-#ifdef DEBUG
-                               if (debug)
-                                   printf("sys_manycastserver\n");
-#endif /* DEBUG */
-                       }
                        break;
 
                    case CONFIG_AUTHENTICATE:
@@ -1801,10 +1796,9 @@ getconfig(
                                        break;
                                }
                        }
-                       if (!errflg) {
+                       if (!errflg)
                                filegen_config(filegen, tokens[peerversion],
-                                              (u_char)peerkey, (u_char)peerflags);
-                       }
+                                  (u_char)peerkey, (u_char)peerflags);
                        break;
 
                    case CONFIG_SETVAR:
@@ -2340,7 +2334,7 @@ save_resolve(
        int version,
        int minpoll,
        int maxpoll,
-       int flags,
+       u_int flags,
        int ttl,
        keyid_t keyid,
        u_char *keystr
@@ -2388,7 +2382,7 @@ save_resolve(
            mode, version, minpoll, maxpoll, flags, ttl, keyid, keystr);
 #ifdef DEBUG
        if (debug > 1)
-               printf("config: %s %d %d %d %d %d %d %08x %s\n", name, mode,
+               printf("config: %s %d %d %d %d %x %d %08x %s\n", name, mode,
                    version, minpoll, maxpoll, flags, ttl, keyid, keystr);
 #endif
 
index 2c5c67764dd3184b2ae8dacd8b1b0954aa5f329b..18c1f26e4b65f1f76844b28f42d5cdb026450cfd 100644 (file)
@@ -425,7 +425,7 @@ u_long numasyncmsgs;                /* number of async messages we've sent */
 static struct ntp_control rpkt;
 static u_char  res_version;
 static u_char  res_opcode;
-static u_short res_associd;
+static associd_t res_associd;
 static int     res_offset;
 static u_char * datapt;
 static u_char * dataend;
@@ -1860,7 +1860,7 @@ control_unspec(
         * doesn't exist.
         */
        if (res_associd != 0) {
-               if ((peer = findpeerbyassoc((int)res_associd)) == 0) {
+               if ((peer = findpeerbyassoc(res_associd)) == 0) {
                        ctl_error(CERR_BADASSOC);
                        return;
                }
@@ -1921,7 +1921,7 @@ read_status(
                            sizeof(u_short), 1);
                ctl_flushpkt(0);
        } else {
-               peer = findpeerbyassoc((int)res_associd);
+               peer = findpeerbyassoc(res_associd);
                if (peer == 0) {
                        ctl_error(CERR_BADASSOC);
                } else {
@@ -2020,7 +2020,7 @@ read_variables(
                 * Wants info for a particular peer. See if we know
                 * the guy.
                 */
-               peer = findpeerbyassoc((int)res_associd);
+               peer = findpeerbyassoc(res_associd);
                if (peer == 0) {
                        ctl_error(CERR_BADASSOC);
                        return;
@@ -2209,7 +2209,7 @@ read_clock_status(
                        }
                }
        } else {
-               peer = findpeerbyassoc((int)res_associd);
+               peer = findpeerbyassoc(res_associd);
                if (peer == 0 || !(peer->flags & FLAG_REFCLOCK)) {
                        ctl_error(CERR_BADASSOC);
                        return;
index 3efb93aaeb4460aaa812b60e991824c040d09329..8186a54c8729cc48f81f7a4d5806aa3fe04f9541 100644 (file)
@@ -178,7 +178,8 @@ session_key(
  */
 void
 make_keylist(
-       struct peer *peer       /* peer structure pointer */
+       struct peer *peer,      /* peer structure pointer */
+       struct interface *dstadr /* interface */
        )
 {
        struct autokey *ap;     /* autokey pointer */
@@ -224,8 +225,8 @@ make_keylist(
         * cookie if client mode or the host cookie if symmetric modes.
         */
        ltemp = sys_automax;
-       peer->hcookie = session_key(&peer->dstadr->sin, &peer->srcadr,
-           0, sys_private, 0);
+       peer->hcookie = session_key(&dstadr->sin, &peer->srcadr, 0,
+           sys_private, 0);
        if (peer->hmode == MODE_BROADCAST)
                cookie = 0;
        else
@@ -233,9 +234,8 @@ make_keylist(
        for (i = 0; i < NTP_MAXSESSION; i++) {
                peer->keylist[i] = keyid;
                peer->keynumber = i;
-               keyid = session_key(&peer->dstadr->sin, (peer->hmode ==
-                   MODE_BROADCAST) ? &peer->dstadr->bcast :
-                   &peer->srcadr, keyid, cookie, ltemp);
+               keyid = session_key(&dstadr->sin, &peer->srcadr, keyid,
+                   cookie, ltemp);
                ltemp -= 1 << peer->kpoll;
                if (auth_havekey(keyid) || keyid <= NTP_MAXKEY ||
                    ltemp <= (1 << (peer->kpoll + 1)))
@@ -817,7 +817,7 @@ crypto_xmit(
        int start,              /* offset to extension field */
        u_int code,             /* extension field code */
        keyid_t cookie,         /* session cookie */
-       associd_t associd       /* association ID */
+       u_int associd           /* association ID */
        )
 {
        struct peer *peer;      /* peer structure pointer */
index ad333fa5e785dbbe79814c9ddba917b537aa6690..fd1774f4edc1a8a78491f55ff29223438d478742 100644 (file)
@@ -138,7 +138,7 @@ char *req_file;             /* name of the file with configuration info */
 static RETSIGTYPE bong         P((int));
 static void    checkparent     P((void));
 static void    removeentry     P((struct conf_entry *));
-static void    addentry        P((char *, int, int, int, int, int,
+static void    addentry        P((char *, int, int, int, int, u_int,
                                   int, keyid_t, char *));
 static int     findhostaddr    P((struct conf_entry *));
 static void    openntp         P((void));
@@ -160,7 +160,7 @@ struct ntp_res_c_pkt {              /* Control packet: */
        int version;
        int minpoll;
        int maxpoll;
-       int flags;
+       u_int flags;
        int ttl;
        keyid_t keyid;
        u_char keystr[MAXFILENAME];
@@ -387,7 +387,7 @@ addentry(
        int version,
        int minpoll,
        int maxpoll,
-       int flags,
+       u_int flags,
        int ttl,
        keyid_t keyid,
        char *keystr
@@ -400,9 +400,9 @@ addentry(
 #ifdef DEBUG
        if (debug > 1)
                msyslog(LOG_INFO, 
-                       "intres: <%s> %d %d %d %d %d %d %u %s\n",
-                       name, mode, version,
-                       minpoll, maxpoll, flags, ttl, keyid, keystr);
+                   "intres: <%s> %d %d %d %d %x %d %x %s\n", name,
+                   mode, version, minpoll, maxpoll, flags, ttl, keyid,
+                   keystr);
 #endif
        len = strlen(name) + 1;
        cp = (char *)emalloc(len);
@@ -923,7 +923,7 @@ readconf(
        register int i;
        char *token[NUMTOK];
        u_long intval[NUMTOK];
-       int flags;
+       u_int flags;
        char buf[MAXLINESIZE];
        char *bp;
 
@@ -977,7 +977,7 @@ readconf(
                }
 
                if ((intval[TOK_FLAGS] & ~(FLAG_AUTHENABLE | FLAG_PREFER |
-                                  FLAG_NOSELECT | FLAG_BURST | FLAG_SKEY))
+                   FLAG_NOSELECT | FLAG_BURST | FLAG_IBURST | FLAG_SKEY))
                    != 0) {
                        msyslog(LOG_ERR, "invalid flags (%ld) in file %s",
                                intval[TOK_FLAGS], name);
@@ -993,6 +993,8 @@ readconf(
                    flags |= CONF_FLAG_NOSELECT;
                if (intval[TOK_FLAGS] & FLAG_BURST)
                    flags |= CONF_FLAG_BURST;
+               if (intval[TOK_FLAGS] & FLAG_IBURST)
+                   flags |= CONF_FLAG_IBURST;
                if (intval[TOK_FLAGS] & FLAG_SKEY)
                    flags |= CONF_FLAG_SKEY;
 
index 6ab7d267d8a2b20a8431cd963a4d321d6e750cfc..5934277be643f42605db6be24d4d87944ba67b10 100644 (file)
@@ -116,8 +116,9 @@ u_long io_timereset;                /* time counters were reset */
 /*
  * Interface stuff
  */
-struct interface *any_interface;       /* pointer to default interface */
-struct interface *loopback_interface;  /* point to loopback interface */
+struct interface *any_interface;       /* default interface */
+struct interface *loopback_interface;  /* loopback interface */
+struct interface *mcast_interface;     /* multicast interface */
 static struct interface inter_list[MAXINTERFACES];
 static int ninterfaces;
 
@@ -241,6 +242,7 @@ create_sockets(
        inter_list[0].sent = 0;
        inter_list[0].notsent = 0;
        inter_list[0].flags = INT_BROADCAST;
+       any_interface = &inter_list[0];
 
 #if _BSDI_VERSION >= 199510
 #if    _BSDI_VERSION >= 199701
@@ -274,46 +276,32 @@ create_sockets(
                if ((ifap->ifa_flags & IFF_UP) == 0)
                    continue;
 
-               if (ifap->ifa_flags & IFF_LOOPBACK)
-               {
+               if (ifap->ifa_flags & IFF_LOOPBACK) {
                        sin = (struct sockaddr_in *)ifap->ifa_addr;
                        if (ntohl(sin->sin_addr.s_addr) != 0x7f000001)
-                       {
                                continue;
-                       }
                }
-
                inter_list[i].flags = 0;
                if (ifap->ifa_flags & IFF_BROADCAST)
-                   inter_list[i].flags |= INT_BROADCAST;
-
-               (void)strcpy(inter_list[i].name, ifap->ifa_name);
-
+                       inter_list[i].flags |= INT_BROADCAST;
+               strcpy(inter_list[i].name, ifap->ifa_name);
                sin = (struct sockaddr_in *)ifap->ifa_addr;
                inter_list[i].sin = *sin;
                inter_list[i].sin.sin_port = port;
-
-               if (ifap->ifa_flags & IFF_LOOPBACK)
-               {
+               if (ifap->ifa_flags & IFF_LOOPBACK) {
                        inter_list[i].flags = INT_LOOPBACK;
                        if (loopback_interface == NULL
                            || ntohl(sin->sin_addr.s_addr) != 0x7f000001)
                            loopback_interface = &inter_list[i];
                }
-
-               if (inter_list[i].flags & INT_BROADCAST)
-               {
+               if (inter_list[i].flags & INT_BROADCAST) {
                        sin = (struct sockaddr_in *)ifap->ifa_broadaddr;
                        inter_list[i].bcast = *sin;
                        inter_list[i].bcast.sin_port = port;
                }
-
-               if (ifap->ifa_flags & (IFF_LOOPBACK|IFF_POINTOPOINT))
-               {
+               if (ifap->ifa_flags & (IFF_LOOPBACK|IFF_POINTOPOINT)) {
                        inter_list[i].mask.sin_addr.s_addr = 0xffffffff;
-               }
-               else
-               {
+               } else {
                        sin = (struct sockaddr_in *)ifap->ifa_netmask;
                        inter_list[i].mask = *sin;
                }
@@ -613,10 +601,16 @@ create_sockets(
        ninterfaces = i;
        maxactivefd = 0;
        FD_ZERO(&activefds);
+
+       /*
+        * There is a crock here. We set mcast_interface to the first
+        * non-loopback interface.
+        */
        for (i = 0; i < ninterfaces; i++) {
-               inter_list[i].fd =
-                   open_socket(&inter_list[i].sin,
-                               inter_list[i].flags & INT_BROADCAST, 0);
+               inter_list[i].fd = open_socket(&inter_list[i].sin,
+                   inter_list[i].flags & INT_BROADCAST, 0);
+               if (!(inter_list[i].flags & INT_LOOPBACK))
+                       mcast_interface = &inter_list[i];
        }
 
        /*
@@ -653,13 +647,13 @@ create_sockets(
         */
        resmask.sin_addr.s_addr = ~ (u_int32)0;
        for (i = 1; i < ninterfaces; i++)
-           hack_restrict(RESTRICT_FLAGS, &inter_list[i].sin, &resmask,
-                         RESM_NTPONLY|RESM_INTERFACE, RES_IGNORE);
-
-       any_interface = &inter_list[0];
+               hack_restrict(RESTRICT_FLAGS, &inter_list[i].sin, &resmask,
+                   RESM_NTPONLY|RESM_INTERFACE, RES_IGNORE);
 #ifdef DEBUG
-       if (debug > 2) {
+       if (debug > 1) {
                printf("create_sockets: ninterfaces=%d\n", ninterfaces);
+               printf("multicast %s\n",
+                   inet_ntoa(mcast_interface->sin.sin_addr));
                for (i = 0; i < ninterfaces; i++) {
                        printf("interface %d:  fd=%d,  bfd=%d,  name=%.8s,  flags=0x%x\n",
                               i,
@@ -1131,7 +1125,7 @@ findbcastinter(
                    return &inter_list[i];
        }
 #endif /* SIOCGIFCONF */
-       return any_interface;
+       return mcast_interface;
 }
 
 
@@ -1172,13 +1166,6 @@ sendpkt(
 #else
 #define badaddrs ((struct cache *)0)           /* Only used in empty loops! */
 #endif
-
-       /*
-        * check if the source address is a multicast address - replace
-        * interface with any-interface if so.
-        */
-       if (IN_MULTICAST(ntohl(inter->sin.sin_addr.s_addr)))
-           inter = any_interface;
 #ifdef DEBUG
        if (debug > 1)
            printf("%ssendpkt(fd=%d dst=%s, src=%s, ttl=%d, len=%d)\n",
index 9969940a0fe0cbcf4931144d1a160a496fc54cee..33b4b628257849283d3e0b48eab26c2f32f044dd 100644 (file)
@@ -308,7 +308,7 @@ findpeer(
  */
 struct peer *
 findpeerbyassoc(
-       associd_t assoc
+       u_int assoc
        )
 {
        register struct peer *peer;
@@ -511,7 +511,7 @@ peer_config(
        int version,
        int minpoll,
        int maxpoll,
-       int flags,
+       u_int flags,
        int ttl,
        keyid_t key,
        u_char *keystr
@@ -556,19 +556,10 @@ peer_config(
                 * structure for him.
                 */
                peer = newpeer(srcadr, dstadr, hmode, version, minpoll,
-                   maxpoll, ttl, key);
+                   maxpoll, flags | FLAG_CONFIG, ttl, key);
                if (peer == 0)
                        return (peer);
-               peer->flags |= flags | FLAG_CONFIG;
        }
-#ifdef DEBUG
-       if (debug)
-               printf(
-                   "peer_config: %s mode %d vers %d min %d max %d flags 0x%04x ttl %d key %08x\n",
-                   ntoa(&peer->srcadr), peer->hmode, peer->version,
-                   peer->minpoll, peer->maxpoll, peer->flags, peer->ttl,
-                   peer->keyid);
-#endif
 #ifdef PUBKEY
        if (!(peer->flags & FLAG_SKEY) || peer->hmode == MODE_BROADCAST)
                return (peer);
@@ -591,8 +582,9 @@ newpeer(
        int version,
        int minpoll,
        int maxpoll,
+       u_int flags,
        int ttl,
-       u_long key
+       keyid_t key
        )
 {
        register struct peer *peer;
@@ -638,6 +630,7 @@ newpeer(
        peer->version = (u_char)version;
        peer->minpoll = (u_char)minpoll;
        peer->maxpoll = (u_char)maxpoll;
+       peer->flags = flags;
        peer->hpoll = peer->minpoll;
        peer->ppoll = peer->minpoll;
        peer->ttl = ttl;
@@ -648,7 +641,7 @@ newpeer(
        peer->stratum = STRATUM_UNSPEC;
        peer_clear(peer);
        peer->update = peer->outdate = current_time;
-       peer->nextdate = peer->outdate + (RANDOM & ((1 << NTP_MINDPOLL) - 1));
+       peer->nextdate = peer->outdate + (RANDOM & ((1 << NTP_MINPOLL) - 1));
 
        /*
         * Assign him an association ID and increment the system variable
@@ -698,8 +691,11 @@ newpeer(
        assoc_hash_count[i]++;
 #ifdef DEBUG
        if (debug)
-               printf("mobilize %u %d next %lu\n", peer->associd,
-                   peer_associations, peer->nextdate - peer->outdate);
+               printf(
+                   "newpeer: %s mode %d vers %d min %d max %d flags 0x%04x ttl %d key %08x\n",
+                   ntoa(&peer->srcadr), peer->hmode, peer->version,
+                   peer->minpoll, peer->maxpoll, peer->flags, peer->ttl,
+                   peer->keyid);
 #endif
        return peer;
 }
@@ -747,20 +743,6 @@ peer_unconfig(
        return num_found;
 }
 
-/*
- * peer_copy_manycast - copy manycast peer variables to new association
- *   (right now it simply copies the transmit timestamp)
- */
-void
-peer_config_manycast(
-       struct peer *peer1,
-       struct peer *peer2
-       )
-{
-       peer2->cast_flags = MDF_ACAST;
-       peer2->xmt = peer1->xmt;
-}
-
 /*
  * peer_clr_stats - clear peer module stat counters
  */
index c5a198d6d14fd0c7aa112636bdd1a389d2afaf6d..ef0296bdc86481da98ca0de1dda22b62975b3725 100644 (file)
@@ -134,13 +134,10 @@ transmit(
                                }
                        }
                        hpoll = peer->minpoll;
-                       if (peer->flags & FLAG_BURST) {
-                               if (peer->flags & FLAG_MCAST2)
-                                       peer->burst = NTP_SHIFT;
-                               else
-                                       peer->burst = 2;
-                       }
-
+                       if (peer->flags & FLAG_IBURST)
+                               peer->burst = NTP_SHIFT;
+                       else if (peer->flags & FLAG_BURST)
+                               peer->burst = 2;
                } else {
 
                        /*
@@ -178,8 +175,8 @@ transmit(
                         * keylist, since no further transmissions will
                         * be made.
                         */
+                       peer->flags &= ~FLAG_IBURST;
                        if (peer->flags & FLAG_MCAST2) {
-                               peer->flags &= ~FLAG_BURST;
                                peer->hmode = MODE_BCLIENT;
 #ifdef AUTOKEY
                                key_expire(peer);
@@ -232,6 +229,7 @@ receive(
        keyid_t skeyid;                 /* cryptographic keys */
 #ifdef AUTOKEY
        keyid_t pkeyid, tkeyid;         /* cryptographic keys */
+       struct sockaddr_in *dstadr_sin; /* active runway */
 #endif /* AUTOKEY */
        struct peer *peer2;
        int retcode = AM_NOMATCH;
@@ -311,7 +309,7 @@ receive(
                }
        }
        if ((PKT_MODE(pkt->li_vn_mode) == MODE_BROADCAST &&
-           !sys_bclient))
+           !sys_bclient) || rbufp->dstadr == any_interface)
                return;
 
        /*
@@ -363,10 +361,17 @@ receive(
         * authenticate the packet if required. Note that we burn only
         * MD5 or DES cycles, again to reduce exposure. There may be no
         * matching association and that's okay.
+        *
+        * More on the autokey mambo. Normally the local interface
+        * address is the unicast one. However, if the sender is a
+        * broadcaster, the broadcast address is used. Notwithstanding
+        * that, if the sender is a multicaster, the broadcast address
+        * is null, so use the unicast address anyway. Don't ask.
         */
        peer = findpeer(&rbufp->recv_srcadr, rbufp->dstadr, rbufp->fd,
            hismode, &retcode);
        is_authentic = 0;
+       dstadr_sin = &rbufp->dstadr->sin;
        if (has_mac == 0) {
 #ifdef DEBUG
                if (debug)
@@ -409,51 +414,38 @@ receive(
                         *
                         * # if unsync, 0
                         * % can't happen
-                        *
-                        * You won't believe this. If in passive mode
-                        * and peer->assoc is nonzero, the active peer
-                        * has previously synchronized and will be using
-                        * nonzero cookie. If peer->assoc is zero, that
-                        * never happened and his cookie is zero. What
-                        * tangled cookies we weave.
                         */
                        if (hismode == MODE_BROADCAST) {
                                pkeyid = 0;
+                               if (rbufp->dstadr->bcast.sin_addr.s_addr
+                                   != 0)
+                                       dstadr_sin =
+                                           &rbufp->dstadr->bcast;
                        } else if (peer == 0) {
                                pkeyid = session_key(
-                                   &rbufp->recv_srcadr,
-                                   &rbufp->dstadr->sin, 0, sys_private,
-                                   0);
+                                   &rbufp->recv_srcadr, dstadr_sin, 0,
+                                   sys_private, 0);
                        } else {
                                pkeyid = peer->pcookie.key;
                        }
 
                        /*
                         * The session key includes both the public
-                        * values and cookie. We have to be careful to
-                        * use the right socket addresses for broadcast
-                        * and unicast packets. In case of an extension
+                        * values and cookie. In case of an extension
                         * field, the cookie used for authentication
                         * purposes is zero. Note the hash is saved for
                         * use later in the autokey mambo.
                         */
-                       if (hismode == MODE_BROADCAST) {
-                               tkeyid = session_key(
-                                   &rbufp->recv_srcadr,
-                                   &rbufp->dstadr->bcast, skeyid,
-                                   pkeyid, 2);
-                       } else if (authlen > LEN_PKT_NOMAC) {
+                       if (authlen > LEN_PKT_NOMAC && pkeyid != 0) {
                                session_key(&rbufp->recv_srcadr,
-                                   &rbufp->dstadr->sin, skeyid, 0, 2);
+                                   dstadr_sin, skeyid, 0, 2);
                                tkeyid = session_key(
-                                   &rbufp->recv_srcadr,
-                                   &rbufp->dstadr->sin, skeyid, pkeyid,
-                                   0);
+                                   &rbufp->recv_srcadr, dstadr_sin,
+                                   skeyid, pkeyid, 0);
                        } else {
                                tkeyid = session_key(
-                                   &rbufp->recv_srcadr,
-                                   &rbufp->dstadr->sin, skeyid, pkeyid,
-                                   2);
+                                   &rbufp->recv_srcadr, dstadr_sin,
+                                   skeyid, pkeyid, 2);
                        }
 
                }
@@ -508,6 +500,9 @@ receive(
                 * zero to tell the caller about this.
                 */
                if (!sys_bclient || sys_manycastserver) {
+                       if (IN_CLASSD(
+                           ntohl(dstadr_sin->sin_addr.s_addr)))
+                               rbufp->dstadr = mcast_interface;
                        if (is_authentic)
                                fast_xmit(rbufp, MODE_SERVER, skeyid);
                        else
@@ -526,7 +521,7 @@ receive(
                 * be properly authenticated and it's darn funny of the
                 * manycaster isn't around now. 
                 */
-               if ((sys_authenticate && !is_authentic)) {
+               if (sys_authenticate && !is_authentic) {
                        is_error = 1;
                        break;
                }
@@ -544,12 +539,14 @@ receive(
                 */
                peer = newpeer(&rbufp->recv_srcadr, rbufp->dstadr,
                    MODE_CLIENT, PKT_VERSION(pkt->li_vn_mode),
-                   NTP_MINDPOLL, NTP_MAXDPOLL, 0, skeyid);
+                   NTP_MINDPOLL, NTP_MAXDPOLL, FLAG_IBURST |
+                   (peer2->flags & (FLAG_AUTHENABLE | FLAG_SKEY)), 0,
+                   skeyid);
                if (peer == 0) {
                        is_error = 1;
                        break;
                }
-               peer_config_manycast(peer2, peer);
+               peer->cast_flags |= peer2->flags & MDF_ACAST;
 #if defined(PUBKEY) && 0
                if (crypto_flags)
                        ntp_res_name(peer->srcadr.sin_addr.s_addr,
@@ -579,7 +576,7 @@ receive(
                }
                peer = newpeer(&rbufp->recv_srcadr, rbufp->dstadr,
                    MODE_PASSIVE, PKT_VERSION(pkt->li_vn_mode),
-                   NTP_MINDPOLL, NTP_MAXDPOLL, 0, skeyid);
+                   NTP_MINDPOLL, NTP_MAXDPOLL, 0, 0, skeyid);
 #if defined(PUBKEY) && 0
                if (crypto_flags)
                        ntp_res_name(peer->srcadr.sin_addr.s_addr,
@@ -600,10 +597,10 @@ receive(
                }
                peer = newpeer(&rbufp->recv_srcadr, rbufp->dstadr,
                    MODE_MCLIENT, PKT_VERSION(pkt->li_vn_mode),
-                   NTP_MINDPOLL, NTP_MAXDPOLL, 0, skeyid);
+                   NTP_MINDPOLL, NTP_MAXDPOLL, 0, 0, skeyid);
                if (peer == 0)
                        break;
-               peer->flags |= FLAG_MCAST1 | FLAG_MCAST2 | FLAG_BURST;
+               peer->flags |= FLAG_MCAST1 | FLAG_MCAST2 | FLAG_IBURST;
                peer->hmode = MODE_CLIENT;
 #if defined(PUBKEY) && 0
                if (crypto_flags)
@@ -725,6 +722,7 @@ receive(
                        peer->pkeyid = skeyid;
                } else {
                        int i;
+
                        for (i = 0; ; i++) {
                                if (tkeyid == peer->pkeyid ||
                                    tkeyid == peer->recauto.key) {
@@ -734,34 +732,19 @@ receive(
                                }
                                if (i > peer->recauto.seq)
                                        break;
-
-                               if (hismode == MODE_BROADCAST)
-                                       tkeyid = session_key(
-                                           &rbufp->recv_srcadr,
-                                           &rbufp->dstadr->bcast,
-                                           tkeyid, pkeyid, 0);
-                               else
-                                       tkeyid = session_key(
-                                           &rbufp->recv_srcadr,
-                                           &rbufp->dstadr->sin,
-                                           tkeyid, pkeyid, 0);
+                               tkeyid = session_key(
+                                   &rbufp->recv_srcadr, dstadr_sin,
+                                   tkeyid, pkeyid, 0);
                        }
                }
 #ifdef PUBKEY
                /*
                 * If the autokey boogie fails, the server may be bogus
-                * or worse. Raise an alarm and retrieve the autokey
-                * values again. If the server has in fact come up with
-                * new autokey values, this saves a timeout and general
-                * reset. On the other hand, an intruder could replay at
-                * speed packets from old associations with different
-                * cookies, which would cause needless server requests
-                * and burdensome responses. Since victim client sends a
-                * message only at poll intervals and victim server
-                * burns no PKI cycles, the attack doesn't do much harm.
+                * or worse. If the server has new autokey values, but
+                * the client has not seen them, the result will be
+                * timeout and general reset. The alternative is a
+                * vulnerability to self-interference in manycast mode.
                 */
-               if (peer->flash & TEST10)
-                       peer->flags &= ~FLAG_AUTOKEY;
                if (!(peer->flags & FLAG_AUTOKEY))
                        peer->flash |= TEST11;
 
@@ -1119,7 +1102,7 @@ poll_update(
        if (peer->burst > 0) {
                if (peer->nextdate != current_time)
                        return;
-               if (peer->flags & FLAG_REFCLOCK)
+               if (peer->flags & (FLAG_REFCLOCK | FLAG_IBURST))
                        peer->nextdate++;
                else if (peer->reach & 0x1)
                        peer->nextdate += RANDPOLL(BURST_INTERVAL2);
@@ -1131,13 +1114,13 @@ poll_update(
                peer->nextdate = peer->outdate + RANDPOLL(peer->kpoll);
        }
 
+#ifdef AUTOKEY
        /*
         * Bit of crass arrogance at this point. If the poll interval
         * has changed and we have a keylist, the lifetimes in the
         * keylist are probably bogus. In this case purge the keylist
         * and regenerate it later.
         */
-#ifdef AUTOKEY
        if (peer->kpoll != oldpoll)
                key_expire(peer);
 #endif /* AUTOKEY */
@@ -1184,7 +1167,7 @@ peer_clear(
         */
        peer->flags &= ~FLAG_AUTOKEY;
        if (peer->flags & FLAG_MCAST2) {
-               peer->flags |= FLAG_MCAST1 | FLAG_BURST;
+               peer->flags |= FLAG_MCAST1 | FLAG_IBURST;
                peer->hmode = MODE_CLIENT;
        }
        memset(CLEAR_TO_ZERO(peer), 0, LEN_CLEAR_TO_ZERO);
@@ -1811,12 +1794,23 @@ peer_xmit(
        )
 {
        struct pkt xpkt;        /* transmit packet */
-       int find_rtt = (peer->cast_flags & MDF_MCAST) &&
-           peer->hmode != MODE_BROADCAST;
+       int find_rtt;
+       struct interface *dstadr;
        int sendlen, pktlen;
        keyid_t xkeyid;         /* transmit key ID */
        l_fp xmt_tx;
 
+       /*
+        * Nonsense time. If multicast or if the interface is not bound,
+        * use the multicast interface. Mommy swat me for this is ugly.
+        */
+       find_rtt = (peer->cast_flags & MDF_MCAST) && peer->hmode !=
+           MODE_BROADCAST;
+       if (find_rtt || peer->dstadr == any_interface)
+               dstadr = mcast_interface;
+       else
+               dstadr = peer->dstadr;
+
        /*
         * Initialize transmit packet header fields.
         */
@@ -1838,22 +1832,18 @@ peer_xmit(
         * is authenticated and contains a MAC. If not, the transmitted
         * packet is not authenticated.
         *
-        * In the current I/O semantics we can't find the local
-        * interface address to generate a session key until after
-        * receiving a packet. So, the first packet goes out
-        * unauthenticated. That's why the really icky test next is
-        * here.
+        * In the current I/O semantics the default interface is set
+        * until after receiving a packet and setting the right
+        * interface. So, the first packet goes out unauthenticated.
+        * That's why the really icky test next is here.
         */
        sendlen = LEN_PKT_NOMAC;
-       if (!(peer->flags & FLAG_AUTHENABLE) ||
-           (peer->dstadr->sin.sin_addr.s_addr == 0 &&
-           peer->dstadr->bcast.sin_addr.s_addr == 0)) {
+       if (!(peer->flags & FLAG_AUTHENABLE)) {
                get_systime(&peer->xmt);
                HTONL_FP(&peer->xmt, &xpkt.xmt);
-               sendpkt(&peer->srcadr, find_rtt ? any_interface :
-                   peer->dstadr, ((peer->cast_flags & MDF_MCAST) &&
-                   !find_rtt) ? ((peer->cast_flags & MDF_ACAST) ? -7 :
-                   peer->ttl) : -8, &xpkt, sendlen);
+               sendpkt(&peer->srcadr, dstadr, ((peer->cast_flags &
+                   MDF_MCAST) && !find_rtt) ? ((peer->cast_flags &
+                   MDF_ACAST) ? -7 : peer->ttl) : -8, &xpkt, sendlen);
                peer->sent++;
 #ifdef DEBUG
                if (debug)
@@ -1918,7 +1908,7 @@ peer_xmit(
                         * it.
                         */
                        if (peer->keynumber == 0)
-                               make_keylist(peer);
+                               make_keylist(peer, dstadr);
                        else
                                peer->keynumber--;
                        xkeyid = peer->keylist[peer->keynumber];
@@ -2012,7 +2002,8 @@ peer_xmit(
                            (peer->cmmd >> 16) != CRYPTO_AUTO)
                                sendlen += crypto_xmit((u_int32 *)&xpkt,
                                    sendlen, CRYPTO_AUTO | CRYPTO_RESP,
-                                   peer->hcookie, peer->associd);
+                                   peer->hcookie,
+                                   peer->associd);
 #ifdef PUBKEY
                        else if (crypto_flags & CRYPTO_FLAG_TAI &&
                            sys_tai == 0)
@@ -2071,10 +2062,8 @@ peer_xmit(
                 * private value of zero. Most intricate.
                 */
                if (sendlen > LEN_PKT_NOMAC)
-                       session_key(&peer->dstadr->sin,
-                           (peer->hmode == MODE_BROADCAST) ?
-                           &peer->dstadr->bcast : &peer->srcadr,
-                           xkeyid, 0, 2);
+                       session_key(&dstadr->sin, &peer->srcadr, xkeyid,
+                           0, 2);
        } 
 #endif /* AUTOKEY */
        xkeyid = peer->keyid;
@@ -2092,10 +2081,9 @@ peer_xmit(
                msyslog(LOG_ERR, "buffer overflow %u", pktlen);
                exit(-1);
        }
-       sendpkt(&peer->srcadr, find_rtt ? any_interface : peer->dstadr,
-           ((peer->cast_flags & MDF_MCAST) && !find_rtt) ?
-           ((peer->cast_flags & MDF_ACAST) ? -7 : peer->ttl) : -7,
-           &xpkt, pktlen);
+       sendpkt(&peer->srcadr, dstadr, ((peer->cast_flags &
+           MDF_MCAST) && !find_rtt) ? ((peer->cast_flags & MDF_ACAST) ?
+           -7 : peer->ttl) : -7, &xpkt, pktlen);
 
        /*
         * Calculate the encryption delay. Keep the minimum over
@@ -2217,7 +2205,7 @@ fast_xmit(
                            CRYPTO_RESP;
                        sendlen += crypto_xmit((u_int32 *)&xpkt,
                            sendlen, code, cookie,
-                           (u_int)htonl(rpkt->exten[1]));
+                           htonl(rpkt->exten[1]));
                } else {
                        session_key(&rbufp->dstadr->sin,
                            &rbufp->recv_srcadr, xkeyid, cookie, 2);
index 452d7e1cae0577f78868734bdf86b815ed45ecc3..bc9133d36ccabbf5a2d3c00c5811bbc6daf3d62d 100644 (file)
@@ -1134,7 +1134,7 @@ do_conf(
        struct req_pkt *inpkt
        )
 {
-       int fl;
+       u_int fl;
        register struct conf_peer *cp;
        register int items;
        struct sockaddr_in peeraddr;
@@ -1156,8 +1156,9 @@ do_conf(
                    && cp->hmode != MODE_CLIENT
                    && cp->hmode != MODE_BROADCAST)
                    fl = 1;
-               if (cp->flags & ~(CONF_FLAG_AUTHENABLE | CONF_FLAG_PREFER
-                     | CONF_FLAG_NOSELECT | CONF_FLAG_BURST | CONF_FLAG_SKEY))
+               if (cp->flags & ~(CONF_FLAG_AUTHENABLE | CONF_FLAG_PREFER |
+                   CONF_FLAG_NOSELECT | CONF_FLAG_BURST | CONF_FLAG_IBURST |
+                   CONF_FLAG_SKEY))
                    fl = 1;
                cp++;
        }
@@ -1197,13 +1198,15 @@ do_conf(
        while (items-- > 0) {
                fl = 0;
                if (cp->flags & CONF_FLAG_AUTHENABLE)
-                   fl |= FLAG_AUTHENABLE;
+                       fl |= FLAG_AUTHENABLE;
                if (cp->flags & CONF_FLAG_PREFER)
-                   fl |= FLAG_PREFER;
+                       fl |= FLAG_PREFER;
                if (cp->flags & CONF_FLAG_NOSELECT)
-                   fl |= FLAG_NOSELECT;
+                       fl |= FLAG_NOSELECT;
                if (cp->flags & CONF_FLAG_BURST)
-                   fl |= FLAG_BURST;
+                       fl |= FLAG_BURST;
+               if (cp->flags & CONF_FLAG_IBURST)
+                       fl |= FLAG_IBURST;
                if (cp->flags & CONF_FLAG_SKEY)
                        fl |= FLAG_SKEY;
                peeraddr.sin_addr.s_addr = cp->peeraddr;
@@ -1270,13 +1273,13 @@ dns_a(
        }
 
        while (items-- > 0) {
-               u_short associd;
+               associd_t associd;
                size_t hnl;
                struct peer *peer;
                int bogon = 0;
 
                associd = dp->associd;
-               peer = findpeerbyassoc((int)associd);
+               peer = findpeerbyassoc(associd);
                if (peer == 0 || peer->flags & FLAG_REFCLOCK) {
                        msyslog(LOG_ERR, "dns_a: %s",
                                (peer == 0)
@@ -1420,7 +1423,7 @@ setclr_flags(
        u_long set
        )
 {
-       register u_long flags;
+       register u_int flags;
 
        if (INFO_NITEMS(inpkt->err_nitems) > 1) {
                msyslog(LOG_ERR, "setclr_flags: err_nitems > 1");
@@ -1433,7 +1436,7 @@ setclr_flags(
        if (flags & ~(SYS_FLAG_BCLIENT | SYS_FLAG_AUTHENTICATE |
                      SYS_FLAG_NTP | SYS_FLAG_KERNEL | SYS_FLAG_MONITOR |
                      SYS_FLAG_FILEGEN)) {
-               msyslog(LOG_ERR, "setclr_flags: extra flags: %#lx",
+               msyslog(LOG_ERR, "setclr_flags: extra flags: %#x",
                        flags & ~(SYS_FLAG_BCLIENT | SYS_FLAG_AUTHENTICATE | 
                                  SYS_FLAG_NTP | SYS_FLAG_KERNEL |
                                  SYS_FLAG_MONITOR | SYS_FLAG_FILEGEN));