Commit 4ef1b286 authored by Soheil Hassas Yeganeh's avatar Soheil Hassas Yeganeh Committed by David S. Miller

tcp: mark skbs with SCM_TIMESTAMPING_OPT_STATS

SOF_TIMESTAMPING_OPT_STATS can be enabled and disabled
while packets are collected on the error queue.
So, checking SOF_TIMESTAMPING_OPT_STATS in sk->sk_tsflags
is not enough to safely assume that the skb contains
OPT_STATS data.

Add a bit in sock_exterr_skb to indicate whether the
skb contains opt_stats data.

Fixes: 1c885808 ("tcp: SOF_TIMESTAMPING_OPT_STATS option for SO_TIMESTAMPING")
Reported-by: default avatarJongHwan Kim <zzoru007@gmail.com>
Signed-off-by: default avatarSoheil Hassas Yeganeh <soheil@google.com>
Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Signed-off-by: default avatarWillem de Bruijn <willemb@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 8605330a
...@@ -20,6 +20,8 @@ struct sock_exterr_skb { ...@@ -20,6 +20,8 @@ struct sock_exterr_skb {
struct sock_extended_err ee; struct sock_extended_err ee;
u16 addr_offset; u16 addr_offset;
__be16 port; __be16 port;
u8 opt_stats:1,
unused:7;
}; };
#endif #endif
...@@ -3793,16 +3793,20 @@ EXPORT_SYMBOL(skb_clone_sk); ...@@ -3793,16 +3793,20 @@ EXPORT_SYMBOL(skb_clone_sk);
static void __skb_complete_tx_timestamp(struct sk_buff *skb, static void __skb_complete_tx_timestamp(struct sk_buff *skb,
struct sock *sk, struct sock *sk,
int tstype) int tstype,
bool opt_stats)
{ {
struct sock_exterr_skb *serr; struct sock_exterr_skb *serr;
int err; int err;
BUILD_BUG_ON(sizeof(struct sock_exterr_skb) > sizeof(skb->cb));
serr = SKB_EXT_ERR(skb); serr = SKB_EXT_ERR(skb);
memset(serr, 0, sizeof(*serr)); memset(serr, 0, sizeof(*serr));
serr->ee.ee_errno = ENOMSG; serr->ee.ee_errno = ENOMSG;
serr->ee.ee_origin = SO_EE_ORIGIN_TIMESTAMPING; serr->ee.ee_origin = SO_EE_ORIGIN_TIMESTAMPING;
serr->ee.ee_info = tstype; serr->ee.ee_info = tstype;
serr->opt_stats = opt_stats;
if (sk->sk_tsflags & SOF_TIMESTAMPING_OPT_ID) { if (sk->sk_tsflags & SOF_TIMESTAMPING_OPT_ID) {
serr->ee.ee_data = skb_shinfo(skb)->tskey; serr->ee.ee_data = skb_shinfo(skb)->tskey;
if (sk->sk_protocol == IPPROTO_TCP && if (sk->sk_protocol == IPPROTO_TCP &&
...@@ -3843,7 +3847,7 @@ void skb_complete_tx_timestamp(struct sk_buff *skb, ...@@ -3843,7 +3847,7 @@ void skb_complete_tx_timestamp(struct sk_buff *skb,
*/ */
if (likely(atomic_inc_not_zero(&sk->sk_refcnt))) { if (likely(atomic_inc_not_zero(&sk->sk_refcnt))) {
*skb_hwtstamps(skb) = *hwtstamps; *skb_hwtstamps(skb) = *hwtstamps;
__skb_complete_tx_timestamp(skb, sk, SCM_TSTAMP_SND); __skb_complete_tx_timestamp(skb, sk, SCM_TSTAMP_SND, false);
sock_put(sk); sock_put(sk);
} }
} }
...@@ -3854,7 +3858,7 @@ void __skb_tstamp_tx(struct sk_buff *orig_skb, ...@@ -3854,7 +3858,7 @@ void __skb_tstamp_tx(struct sk_buff *orig_skb,
struct sock *sk, int tstype) struct sock *sk, int tstype)
{ {
struct sk_buff *skb; struct sk_buff *skb;
bool tsonly; bool tsonly, opt_stats = false;
if (!sk) if (!sk)
return; return;
...@@ -3867,9 +3871,10 @@ void __skb_tstamp_tx(struct sk_buff *orig_skb, ...@@ -3867,9 +3871,10 @@ void __skb_tstamp_tx(struct sk_buff *orig_skb,
#ifdef CONFIG_INET #ifdef CONFIG_INET
if ((sk->sk_tsflags & SOF_TIMESTAMPING_OPT_STATS) && if ((sk->sk_tsflags & SOF_TIMESTAMPING_OPT_STATS) &&
sk->sk_protocol == IPPROTO_TCP && sk->sk_protocol == IPPROTO_TCP &&
sk->sk_type == SOCK_STREAM) sk->sk_type == SOCK_STREAM) {
skb = tcp_get_timestamping_opt_stats(sk); skb = tcp_get_timestamping_opt_stats(sk);
else opt_stats = true;
} else
#endif #endif
skb = alloc_skb(0, GFP_ATOMIC); skb = alloc_skb(0, GFP_ATOMIC);
} else { } else {
...@@ -3888,7 +3893,7 @@ void __skb_tstamp_tx(struct sk_buff *orig_skb, ...@@ -3888,7 +3893,7 @@ void __skb_tstamp_tx(struct sk_buff *orig_skb,
else else
skb->tstamp = ktime_get_real(); skb->tstamp = ktime_get_real();
__skb_complete_tx_timestamp(skb, sk, tstype); __skb_complete_tx_timestamp(skb, sk, tstype, opt_stats);
} }
EXPORT_SYMBOL_GPL(__skb_tstamp_tx); EXPORT_SYMBOL_GPL(__skb_tstamp_tx);
......
...@@ -706,7 +706,7 @@ void __sock_recv_timestamp(struct msghdr *msg, struct sock *sk, ...@@ -706,7 +706,7 @@ void __sock_recv_timestamp(struct msghdr *msg, struct sock *sk,
SCM_TIMESTAMPING, sizeof(tss), &tss); SCM_TIMESTAMPING, sizeof(tss), &tss);
if (skb_is_err_queue(skb) && skb->len && if (skb_is_err_queue(skb) && skb->len &&
(sk->sk_tsflags & SOF_TIMESTAMPING_OPT_STATS)) SKB_EXT_ERR(skb)->opt_stats)
put_cmsg(msg, SOL_SOCKET, SCM_TIMESTAMPING_OPT_STATS, put_cmsg(msg, SOL_SOCKET, SCM_TIMESTAMPING_OPT_STATS,
skb->len, skb->data); skb->len, skb->data);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment