]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
ntp: fix accepting requests from configured sources
authorMiroslav Lichvar <mlichvar@redhat.com>
Fri, 21 Nov 2014 10:43:47 +0000 (11:43 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Fri, 21 Nov 2014 10:43:47 +0000 (11:43 +0100)
When using server socket to send client requests (acquisitionport 123)
and currently not waiting for a reply, the socket check will fail for
client requests from the source.

The check needs to be moved to correctly handle the requests as from an
unknown source.

ntp_core.c

index 0f5a49b2df5744c9c3f139372f1cae38e27a0cc2..8de4e4582c1f33c52e54a6ef50cb40ec69d9cd52 100644 (file)
@@ -1420,19 +1420,6 @@ NCR_ProcessKnown
 {
   int pkt_mode, proc_packet, proc_as_unknown, log_peer_access;
 
-  /* Make sure the packet was received by the sending socket */
-  if (local_addr->sock_fd != inst->local_addr.sock_fd) {
-    DEBUG_LOG(LOGF_NtpCore,
-              "Packet received by wrong socket %d (expected %d)",
-              local_addr->sock_fd, inst->local_addr.sock_fd);
-    return;
-  }
-
-  /* Ignore packets from offline sources */
-  if (inst->opmode == MD_OFFLINE || inst->tx_suspended) {
-    return;
-  }
-
   if (!check_packet_format(message, length))
     return;
 
@@ -1528,10 +1515,24 @@ NCR_ProcessKnown
     CLG_LogNTPPeerAccess(&inst->remote_addr.ip_addr, now->tv_sec);
 
   if (proc_packet) {
+    /* Check if the reply was received by the socket that sent the request */
+    if (local_addr->sock_fd != inst->local_addr.sock_fd) {
+      DEBUG_LOG(LOGF_NtpCore,
+                "Packet received by wrong socket %d (expected %d)",
+                local_addr->sock_fd, inst->local_addr.sock_fd);
+      return;
+    }
+
+    /* Ignore packets from offline sources */
+    if (inst->opmode == MD_OFFLINE || inst->tx_suspended) {
+      DEBUG_LOG(LOGF_NtpCore, "Packet from offline source");
+      return;
+    }
+
     receive_packet(message, now, now_err, inst, local_addr, length);
   } else if (proc_as_unknown) {
     NCR_ProcessUnknown(message, now, now_err, &inst->remote_addr,
-                       &inst->local_addr, length);
+                       local_addr, length);
   } else {
     DEBUG_LOG(LOGF_NtpCore, "NTP packet discarded pkt_mode=%d our_mode=%d",
               pkt_mode, inst->mode);