]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
ntp: check if packet was received by right socket
authorMiroslav Lichvar <mlichvar@redhat.com>
Mon, 24 Mar 2014 16:10:35 +0000 (17:10 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Tue, 25 Mar 2014 14:24:38 +0000 (15:24 +0100)
ntp_core.c
ntp_core.h
ntp_sources.c

index c963ab942fbe8a2b073a090875e1206ee66f4a63..14d267b7404152c6b101b6b9d0b6392fc34f39f0 100644 (file)
@@ -1275,6 +1275,7 @@ NCR_ProcessKnown
  struct timeval *now,           /* timestamp at time of receipt */
  double now_err,
  NCR_Instance inst,             /* the instance record for this peer/server */
+ int sock_fd,                   /* the receiving socket */
  int length                     /* the length of the received packet */
  )
 {
@@ -1282,6 +1283,14 @@ NCR_ProcessKnown
   int version;
   int auth_len;
 
+  /* Make sure the packet was received by the sending socket */
+  if (sock_fd != inst->local_addr.sock_fd) {
+    DEBUG_LOG(LOGF_NtpCore,
+              "Packet received by wrong socket %d (expected %d)",
+              sock_fd, inst->local_addr.sock_fd);
+    return;
+  }
+
   /* Ignore packets from offline sources */
   if (inst->opmode == MD_OFFLINE) {
     return;
index a0352891cc47ba24c5c93acdb86b8bddd9608a60..5af536f859e907d8e49e93dbe0761cba2f88072e 100644 (file)
@@ -54,7 +54,7 @@ extern void NCR_DestroyInstance(NCR_Instance instance);
 
 /* This routine is called when a new packet arrives off the network,
    and it relates to a source we have an ongoing protocol exchange with */
-extern void NCR_ProcessKnown(NTP_Packet *message, struct timeval *now, double now_err, NCR_Instance data, int length);
+extern void NCR_ProcessKnown(NTP_Packet *message, struct timeval *now, double now_err, NCR_Instance data, int sock_fd, int length);
 
 /* This routine is called when a new packet arrives off the network,
    and we do not recognize its source */
index 7391e54c26e1cd8fdaeb99164a03aef72cd5a005..11085925fdd547383e0fa7f79d1e171ad1049c85 100644 (file)
@@ -356,7 +356,8 @@ NSR_ProcessReceive(NTP_Packet *message, struct timeval *now, double now_err, NTP
   
   find_slot(remote_addr, &slot, &found);
   if (found == 2) { /* Must match IP address AND port number */
-    NCR_ProcessKnown(message, now, now_err, records[slot].data, length);
+    NCR_ProcessKnown(message, now, now_err, records[slot].data,
+                     local_addr->sock_fd, length);
   } else {
     NCR_ProcessUnknown(message, now, now_err, remote_addr, local_addr, length);
   }