]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
ntp: set interface index in IP*_PKTINFO when responding
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 29 Aug 2018 08:56:14 +0000 (10:56 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 30 Aug 2018 09:56:13 +0000 (11:56 +0200)
When a server with multiple interfaces in the same network is sending a
response, setting the ipi_spec_dst/ipi6_addr field of the IP*_PKTINFO
control message selects the source address, but not necessarily the
interface. The packet has the expected source address, but it may be
sent by an interface that doesn't have the address.

Set the ipi_ifindex/ipi6_ifindex field to respond on the same interface
as the request was received from to avoid asymmetries in delay and
timestamping.

ntp_io.c

index e92d27ebbfa81326e91696893aab1687141c188a..ec844cb6ee054ac0eb61482f1eb1184ed5abc9b7 100644 (file)
--- a/ntp_io.c
+++ b/ntp_io.c
@@ -827,6 +827,8 @@ NIO_SendPacket(NTP_Packet *packet, NTP_Remote_Address *remote_addr,
 
     ipi = (struct in_pktinfo *) CMSG_DATA(cmsg);
     ipi->ipi_spec_dst.s_addr = htonl(local_addr->ip_addr.addr.in4);
+    if (local_addr->if_index != INVALID_IF_INDEX)
+      ipi->ipi_ifindex = local_addr->if_index;
   }
 #endif
 
@@ -845,6 +847,8 @@ NIO_SendPacket(NTP_Packet *packet, NTP_Remote_Address *remote_addr,
     ipi = (struct in6_pktinfo *) CMSG_DATA(cmsg);
     memcpy(&ipi->ipi6_addr.s6_addr, &local_addr->ip_addr.addr.in6,
         sizeof(ipi->ipi6_addr.s6_addr));
+    if (local_addr->if_index != INVALID_IF_INDEX)
+      ipi->ipi6_ifindex = local_addr->if_index;
   }
 #endif