Skip to content

Commit

Permalink
net: packetmmap: fix only tx timestamp on request
Browse files Browse the repository at this point in the history
[ Upstream commit 171c3b1 ]

The packetmmap tx ring should only return timestamps if requested via
setsockopt PACKET_TIMESTAMP, as documented. This allows compatibility
with non-timestamp aware user-space code which checks
tp_status == TP_STATUS_AVAILABLE; not expecting additional timestamp
flags to be set in tp_status.

Fixes: b9c32fb ("packet: if hw/sw ts enabled in rx/tx ring, report which ts we got")
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
Signed-off-by: Richard Sanger <rsanger@wand.net.nz>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
rsanger authored and gregkh committed Jun 3, 2021
1 parent 1f1b431 commit 9c38601
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions net/packet/af_packet.c
Expand Up @@ -421,7 +421,8 @@ static __u32 tpacket_get_timestamp(struct sk_buff *skb, struct timespec64 *ts,
ktime_to_timespec64_cond(shhwtstamps->hwtstamp, ts))
return TP_STATUS_TS_RAW_HARDWARE;

if (ktime_to_timespec64_cond(skb->tstamp, ts))
if ((flags & SOF_TIMESTAMPING_SOFTWARE) &&
ktime_to_timespec64_cond(skb->tstamp, ts))
return TP_STATUS_TS_SOFTWARE;

return 0;
Expand Down Expand Up @@ -2339,7 +2340,12 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev,

skb_copy_bits(skb, 0, h.raw + macoff, snaplen);

if (!(ts_status = tpacket_get_timestamp(skb, &ts, po->tp_tstamp)))
/* Always timestamp; prefer an existing software timestamp taken
* closer to the time of capture.
*/
ts_status = tpacket_get_timestamp(skb, &ts,
po->tp_tstamp | SOF_TIMESTAMPING_SOFTWARE);
if (!ts_status)
ktime_get_real_ts64(&ts);

status |= ts_status;
Expand Down

0 comments on commit 9c38601

Please sign in to comment.