[PATCH net] net: fall back to skb_iif for the timestamping pktinfo if_index

JR Lanteigne <[email protected]>
Newsgroups org.kernel.vger.netdev
Message-ID <[email protected]>
put_ts_pktinfo() resolves the interface index of a received packet
from its napi id. The lookup fails on drivers whose napi instances
are not attached to the delivering net_device (e.g. ti cpsw, which
keeps them on an internal dummy device) and on kernels built without
CONFIG_NET_RX_BUSY_POLL, where skb_napi_id() is always 0. In those
cases SCM_TIMESTAMPING_PKTINFO carries if_index 0 and applications
cannot tell which interface produced the hardware timestamp. chronyd,
for example, then ignores valid hardware timestamps.

Fall back to skb->skb_iif, which is set for every received packet.
On aggregated interfaces this reports the aggregating device instead
of the physical one, but only in cases where the napi lookup already
failed and nothing was reported at all.

Fixes: aad9c8c470f2 ("net: add new control message for incoming HW-timestamped packets")
Signed-off-by: JR Lanteigne <[email protected]>
---
A userspace fallback for existing kernels was proposed to chrony
separately.

 net/socket.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/socket.c b/net/socket.c
--- a/net/socket.c
+++ b/net/socket.c
@@ -900,6 +900,8 @@ static void put_ts_pktinfo(struct msghdr *msg, struct sk_buff *skb,
 			if_index = orig_dev->ifindex;
 		rcu_read_unlock();
 	}
+	if (!if_index)
+		if_index = skb->skb_iif;
 	ts_pktinfo.if_index = if_index;
 
 	ts_pktinfo.pkt_length = skb->len - skb_mac_offset(skb);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.