The kernel fills the if_index of SCM_TIMESTAMPING_PKTINFO from the
napi id of the packet (put_ts_pktinfo() in net/socket.c). Some drivers
keep their napi instances on an internal dummy device (e.g. ti cpsw).
Kernels without CONFIG_NET_RX_BUSY_POLL cannot resolve any napi id.
In both cases the lookup fails and the if_index is 0.

get_interface() then failed. Valid HW timestamps were dropped. The
less accurate kernel timestamps were used instead.

Zero is not a valid interface index. Treat it like a missing
timestamping if_index and use the if_index of the message itself.
---
Seen on a BeagleBone Black (ti cpsw, 6.6-rt kernel). chronyd accepts
hwtimestamp eth0, then logs "HW clock not found for interface 0" for
every packet. Every measurement silently degrades to kernel timestamps
(K in measurements.log).

The fix treats 0 like a missing if_index and uses the message if_index
instead. Zero is never a valid interface index, so nothing valid is
lost. On a bonded interface the message if_index names the bond. The
bond has no HW clock, so the timestamp is dropped there, same as
before this change.

Validated on the affected hardware: measurements.log flips from "K K"
to "H H". Offsets against two GPS-disciplined observers on the same
switch improve from ~100 us of kernel latency noise to under 1 us.

 ntp_io_linux.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ntp_io_linux.c b/ntp_io_linux.c
index 3144246..ab62d06 100644
--- a/ntp_io_linux.c
+++ b/ntp_io_linux.c
@@ -846,7 +846,7 @@ NIO_Linux_ProcessMessage(SCK_Message *message, 
NTP_Local_Address *local_addr,
   iface = NULL;
 
   ts_if_index = message->timestamp.if_index;
-  if (ts_if_index == INVALID_IF_INDEX)
+  if (ts_if_index == INVALID_IF_INDEX || ts_if_index == 0)
     ts_if_index = message->if_index;
   l2_length = message->timestamp.l2_length;
 
-- 
2.43.0


-- 
To unsubscribe email [email protected] with "unsubscribe" 
in the subject.
For help email [email protected] with "help" in the 
subject.
Trouble?  Email [email protected].

Reply via email to