]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
ntp: use NTP instead of echo for presend
authorMiroslav Lichvar <mlichvar@redhat.com>
Fri, 15 Aug 2014 13:45:48 +0000 (15:45 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Fri, 15 Aug 2014 14:49:45 +0000 (16:49 +0200)
Switch to NTP for presend as the echo service (RFC 862) is rarely
enabled. When presend is active, send an NTP client packet to the
server/peer and ignore the reply.

This also fixes presend with separate client sockets. The destination
port can't be changed on connected sockets, so the echo packet was sent
to the NTP port instead of the echo port.

chrony.texi.in
ntp_core.c
ntp_io.c
ntp_io.h

index 43bde8855142105068d409713eb8b8c5381971aa..2e477bcfd305202ccd89d5ea3f8dbfd9d7082132 100644 (file)
@@ -2836,18 +2836,18 @@ of the machines.
 
 In order to avoid this problem, the @code{presend} option may be used.
 It takes a single integer argument, which is the smallest polling
-interval for which a pair of packets will be exchanged between the
-client and the server prior to the actual measurement being initiated by
-the client.  For example, with the following option included in a
+interval for which an extra pair of NTP packets will be exchanged
+between the client and the server prior to the actual measurement.
+For example, with the following option included in a
 @code{server} directive :
 
 @example
 presend 9
 @end example
 
-when the polling interval is 512 seconds or more, a UDP echo datagram
-will be sent to the server a short time (currently 4 seconds) before the
-NTP client mode datagram.
+when the polling interval is 512 seconds or more, an extra NTP client
+packet will be sent to the server a short time (currently 4 seconds)
+before making the actual measurement.
 
 @item key
 The NTP protocol supports the inclusion of checksums in the packets, to
index 278b8049cc997e4ef83c662a54336641887c8c98..d550b457d107ad3969be50c7441a10ed5085ca52 100644 (file)
@@ -85,8 +85,8 @@ struct NCR_Instance_Record {
                                    received packets) */
 
   int presend_minpoll;           /* If the current polling interval is
-                                    at least this, an echo datagram
-                                    will be send some time before every
+                                    at least this, an extra client packet
+                                    will be send some time before normal
                                     transmit.  This ensures that both
                                     us and the server/peer have an ARP
                                     entry for each other ready, which
@@ -191,7 +191,7 @@ struct NCR_Instance_Record {
 #define IBURST_GOOD_SAMPLES 4
 #define IBURST_TOTAL_SAMPLES SOURCE_REACH_BITS
 
-/* Time to wait after sending echo to 'warm up' link */
+/* Time to wait after sending packet to 'warm up' link */
 #define WARM_UP_DELAY 4.0
 
 /* The NTP protocol version that we support */
@@ -820,7 +820,7 @@ transmit_timeout(void *arg)
   }
 
   /* Check whether we need to 'warm up' the link to the other end by
-     sending an echo exchange to ensure both ends' ARP caches are
+     sending an NTP exchange to ensure both ends' ARP caches are
      primed.  On loaded systems this might also help ensure that bits
      of the program are paged in properly before we start. */
 
@@ -828,8 +828,11 @@ transmit_timeout(void *arg)
       (inst->presend_minpoll <= inst->local_poll) &&
       !inst->presend_done) {
     
-    /* Send */
-    NIO_SendEcho(&inst->remote_addr, &inst->local_addr);
+    /* Send a client packet, don't store the local tx values
+       as the reply will be ignored */
+    transmit_packet(MODE_CLIENT, inst->local_poll, NTP_VERSION, 0, 0,
+                    &inst->remote_orig, &inst->local_rx, NULL, NULL,
+                    &inst->remote_addr, &inst->local_addr);
 
     inst->presend_done = 1;
 
@@ -1483,6 +1486,9 @@ NCR_ProcessKnown
       break;
 
     case MODE_SERVER:
+      /* Ignore presend reply */
+      if (inst->presend_done)
+        break;
 
       switch(inst->mode) {
         case MODE_ACTIVE:
index d69173503a38ead1efd69676b5b80446b657d4a7..a57be3b1ff5052d9298f422cde16db317adfa4ed 100644 (file)
--- a/ntp_io.c
+++ b/ntp_io.c
@@ -687,20 +687,3 @@ NIO_SendAuthenticatedPacket(NTP_Packet *packet, NTP_Remote_Address *remote_addr,
 {
   send_packet((void *) packet, NTP_NORMAL_PACKET_SIZE + auth_len, remote_addr, local_addr);
 }
-
-/* ================================================== */
-
-/* We ought to use getservbyname, but I can't really see this changing */
-#define ECHO_PORT 7
-
-void
-NIO_SendEcho(NTP_Remote_Address *remote_addr, NTP_Local_Address *local_addr)
-{
-  unsigned long magic_message = 0xbe7ab1e7UL;
-  NTP_Remote_Address addr;
-
-  addr = *remote_addr;
-  addr.port = ECHO_PORT;
-
-  send_packet((void *) &magic_message, sizeof(unsigned long), &addr, local_addr);
-}
index 2d7f3599a2769bc661a99ac57a0fdc6807771b90..581a94af6062a437d56f9f3ca5f17735708f0f0e 100644 (file)
--- a/ntp_io.h
+++ b/ntp_io.h
@@ -56,7 +56,4 @@ extern void NIO_SendNormalPacket(NTP_Packet *packet, NTP_Remote_Address *remote_
 /* Function to transmit an authenticated packet */
 extern void NIO_SendAuthenticatedPacket(NTP_Packet *packet, NTP_Remote_Address *remote_addr, NTP_Local_Address *local_addr, int auth_len);
 
-/* Function to send a datagram to a remote machine's UDP echo port. */
-extern void NIO_SendEcho(NTP_Remote_Address *remote_addr, NTP_Local_Address *local_addr);
-
 #endif /* GOT_NTP_IO_H */