[chrony-dev] [PATCH v2] socket: ignore zero if_index in timestamping pktinfo

[ Thread Index | Date Index | More chrony.tuxfamily.org/chrony-dev Archives ]


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. Ignore it when extracting the
control messages, so the timestamping if_index keeps its
INVALID_IF_INDEX initialization and the existing fallback to the
if_index of the message itself applies.
---
v2: moved the check from ntp_io_linux.c to the control message
extraction in socket.c, as suggested.

 socket.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/socket.c b/socket.c
index e217e31..000e62e 100644
--- a/socket.c
+++ b/socket.c
@@ -997,7 +997,8 @@ process_header(struct msghdr *msg, int msg_length, int sock_fd, int flags,
       struct scm_ts_pktinfo ts_pktinfo;
 
       memcpy(&ts_pktinfo, CMSG_DATA(cmsg), sizeof (ts_pktinfo));
-      message->timestamp.if_index = ts_pktinfo.if_index;
+      if (ts_pktinfo.if_index != 0)
+        message->timestamp.if_index = ts_pktinfo.if_index;
       message->timestamp.l2_length = ts_pktinfo.pkt_length;
     }
 #endif
-- 
2.43.0


-- 
To unsubscribe email chrony-dev-request@xxxxxxxxxxxxxxxxxxxx with "unsubscribe" in the subject.
For help email chrony-dev-request@xxxxxxxxxxxxxxxxxxxx with "help" in the subject.
Trouble?  Email listmaster@xxxxxxxxxxxxxxxxxxxx.


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/