Skip to content

Commit

Permalink
Bluetooth: increment TX timestamping tskey always for stream sockets
Browse files Browse the repository at this point in the history
Documentation/networking/timestamping.rst implies TX timestamping OPT_ID
tskey increments for each sendmsg.  In practice: TCP socket increments
it for all sendmsg, timestamping on or off, but UDP only when
timestamping is on. The user-visible counter resets when OPT_ID is
turned on, so difference can be seen only if timestamping is enabled for
some packets only (eg. via SO_TIMESTAMPING CMSG).

Fix BT sockets to work in the same way: stream sockets increment tskey
for all sendmsg (seqpacket already increment for timestamped only).

Fixes: 134f4b3 ("Bluetooth: add support for skb TX SND/COMPLETION timestamping")
Signed-off-by: Pauli Virtanen <pav@iki.fi>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
  • Loading branch information
Pauli Virtanen authored and Luiz Augusto von Dentz committed Apr 10, 2025
1 parent e92900c commit c174cd0
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions net/bluetooth/hci_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -3072,6 +3072,7 @@ void hci_setup_tx_timestamp(struct sk_buff *skb, size_t key_offset,
const struct sockcm_cookie *sockc)
{
struct sock *sk = skb ? skb->sk : NULL;
int key;

/* This shall be called on a single skb of those generated by user
* sendmsg(), and only when the sendmsg() does not return error to
Expand All @@ -3087,13 +3088,16 @@ void hci_setup_tx_timestamp(struct sk_buff *skb, size_t key_offset,

sock_tx_timestamp(sk, sockc, &skb_shinfo(skb)->tx_flags);

if (sk->sk_type == SOCK_STREAM)
key = atomic_add_return(key_offset, &sk->sk_tskey);

if (sockc->tsflags & SOF_TIMESTAMPING_OPT_ID &&
sockc->tsflags & SOF_TIMESTAMPING_TX_RECORD_MASK) {
if (sockc->tsflags & SOCKCM_FLAG_TS_OPT_ID) {
skb_shinfo(skb)->tskey = sockc->ts_opt_id;
} else {
int key = atomic_add_return(key_offset, &sk->sk_tskey);

if (sk->sk_type != SOCK_STREAM)
key = atomic_inc_return(&sk->sk_tskey);
skb_shinfo(skb)->tskey = key - 1;
}
}
Expand Down

0 comments on commit c174cd0

Please sign in to comment.