From: Miroslav Lichvar Date: Wed, 29 Aug 2018 08:56:14 +0000 (+0200) Subject: ntp: set interface index in IP*_PKTINFO when responding X-Git-Tag: 3.4-pre1~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5fc7674e366fa1bfda162bdaba57243cff0a55a7;p=thirdparty%2Fchrony.git ntp: set interface index in IP*_PKTINFO when responding 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. --- diff --git a/ntp_io.c b/ntp_io.c index e92d27eb..ec844cb6 100644 --- 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