]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
ntp: read interface index from control messages
authorMiroslav Lichvar <mlichvar@redhat.com>
Mon, 24 Oct 2016 10:35:01 +0000 (12:35 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 10 Nov 2016 14:26:56 +0000 (15:26 +0100)
ntp_io.c
ntp_io_linux.c
ntp_io_linux.h

index 32534485c9ea9de0f82bbcfdd27af76fd1431106..80b062c2db1162f5c917b94d0deb9b87ffaa90b7 100644 (file)
--- a/ntp_io.c
+++ b/ntp_io.c
@@ -572,6 +572,7 @@ process_message(struct msghdr *hdr, int length, int sock_fd)
   NTP_Local_Timestamp local_ts;
   struct timespec sched_ts;
   struct cmsghdr *cmsg;
+  int if_index;
 
   SCH_GetLastEventTime(&local_ts.ts, &local_ts.err, NULL);
   local_ts.source = NTP_TS_DAEMON;
@@ -592,6 +593,7 @@ process_message(struct msghdr *hdr, int length, int sock_fd)
 
   local_addr.ip_addr.family = IPADDR_UNSPEC;
   local_addr.sock_fd = sock_fd;
+  if_index = -1;
 
   for (cmsg = CMSG_FIRSTHDR(hdr); cmsg; cmsg = CMSG_NXTHDR(hdr, cmsg)) {
 #ifdef HAVE_IN_PKTINFO
@@ -601,6 +603,7 @@ process_message(struct msghdr *hdr, int length, int sock_fd)
       memcpy(&ipi, CMSG_DATA(cmsg), sizeof(ipi));
       local_addr.ip_addr.addr.in4 = ntohl(ipi.ipi_addr.s_addr);
       local_addr.ip_addr.family = IPADDR_INET4;
+      if_index = ipi.ipi_ifindex;
     }
 #endif
 
@@ -612,6 +615,7 @@ process_message(struct msghdr *hdr, int length, int sock_fd)
       memcpy(&local_addr.ip_addr.addr.in6, &ipi.ipi6_addr.s6_addr,
              sizeof (local_addr.ip_addr.addr.in6));
       local_addr.ip_addr.family = IPADDR_INET6;
+      if_index = ipi.ipi6_ifindex;
     }
 #endif
 
@@ -640,14 +644,14 @@ process_message(struct msghdr *hdr, int length, int sock_fd)
 
 #ifdef HAVE_LINUX_TIMESTAMPING
   if (NIO_Linux_ProcessMessage(&remote_addr, &local_addr, &local_ts,
-                               hdr, length, sock_fd))
+                               hdr, length, sock_fd, if_index))
     return;
 #endif
 
-  DEBUG_LOG(LOGF_NtpIO, "Received %d bytes from %s:%d to %s fd=%d tss=%d delay=%.9f",
+  DEBUG_LOG(LOGF_NtpIO, "Received %d bytes from %s:%d to %s fd=%d if=%d tss=%d delay=%.9f",
             length, UTI_IPToString(&remote_addr.ip_addr), remote_addr.port,
-            UTI_IPToString(&local_addr.ip_addr), local_addr.sock_fd, local_ts.source,
-            UTI_DiffTimespecsToDouble(&sched_ts, &local_ts.ts));
+            UTI_IPToString(&local_addr.ip_addr), local_addr.sock_fd, if_index,
+            local_ts.source, UTI_DiffTimespecsToDouble(&sched_ts, &local_ts.ts));
 
   /* Just ignore the packet if it's not of a recognized length */
   if (length < NTP_NORMAL_PACKET_LENGTH || length > sizeof (NTP_Receive_Buffer))
index 187bbc0b1856e01720fe577fb4a5aa989dbbb508..0eaa1624c0b90491d6ae66c323cce882706207c4 100644 (file)
@@ -185,7 +185,7 @@ extract_udp_data(unsigned char *msg, NTP_Remote_Address *remote_addr, int len)
 int
 NIO_Linux_ProcessMessage(NTP_Remote_Address *remote_addr, NTP_Local_Address *local_addr,
                          NTP_Local_Timestamp *local_ts, struct msghdr *hdr,
-                         int length, int sock_fd)
+                         int length, int sock_fd, int if_index)
 {
   struct cmsghdr *cmsg;
 
@@ -225,9 +225,9 @@ NIO_Linux_ProcessMessage(NTP_Remote_Address *remote_addr, NTP_Local_Address *loc
      currently doesn't seem to be a better way to get them both. */
   length = extract_udp_data(hdr->msg_iov[0].iov_base, remote_addr, length);
 
-  DEBUG_LOG(LOGF_NtpIOLinux, "Received %d bytes from error queue for %s:%d fd=%d tss=%d",
+  DEBUG_LOG(LOGF_NtpIOLinux, "Received %d bytes from error queue for %s:%d fd=%d if=%d tss=%d",
             length, UTI_IPToString(&remote_addr->ip_addr), remote_addr->port,
-            sock_fd, local_ts->source);
+            sock_fd, if_index, local_ts->source);
 
   if (length < NTP_NORMAL_PACKET_LENGTH)
     return 1;
index a70ac1b00844b5a4a0c163ba5d70775bb61cd60e..db140ba22addf72692510de26eca52dd30fd1899 100644 (file)
@@ -32,6 +32,6 @@ extern int NIO_Linux_SetTimestampSocketOptions(int sock_fd, int client_only, int
 
 extern int NIO_Linux_ProcessMessage(NTP_Remote_Address *remote_addr, NTP_Local_Address *local_addr,
                                     NTP_Local_Timestamp *local_ts, struct msghdr *hdr, int length,
-                                    int sock_fd);
+                                    int sock_fd, int if_index);
 
 extern int NIO_Linux_RequestTxTimestamp(struct msghdr *msg, int cmsglen, int sock_fd);