tcp: rename tcp_skb_timestamp()
authorEric Dumazet <edumazet@google.com>
Fri, 20 Oct 2023 12:57:41 +0000 (12:57 +0000)
committerDavid S. Miller <davem@davemloft.net>
Mon, 23 Oct 2023 08:35:01 +0000 (09:35 +0100)
This helper returns a 32bit TCP TSval from skb->tstamp.

As we are going to support usec or ms units soon, rename it
to tcp_skb_timestamp_ts() and add a boolean to select the unit.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/tcp.h
net/ipv4/tcp_input.c
net/ipv4/tcp_output.c
net/ipv4/tcp_timer.c

index 0534526a535da7cee7d8d49fd556fe4d7a4eefb6..493f8550055bca09b69a9d3129d6ba781a1233f8 100644 (file)
@@ -837,17 +837,21 @@ static inline u32 tcp_stamp_us_delta(u64 t1, u64 t0)
        return max_t(s64, t1 - t0, 0);
 }
 
-static inline u32 tcp_skb_timestamp(const struct sk_buff *skb)
-{
-       return tcp_ns_to_ts(skb->skb_mstamp_ns);
-}
-
 /* provide the departure time in us unit */
 static inline u64 tcp_skb_timestamp_us(const struct sk_buff *skb)
 {
        return div_u64(skb->skb_mstamp_ns, NSEC_PER_USEC);
 }
 
+/* Provide skb TSval in usec or ms unit */
+static inline u32 tcp_skb_timestamp_ts(bool usec_ts, const struct sk_buff *skb)
+{
+       if (usec_ts)
+               return tcp_skb_timestamp_us(skb);
+
+       return div_u64(skb->skb_mstamp_ns, NSEC_PER_MSEC);
+}
+
 static inline u32 tcp_tw_tsval(const struct tcp_timewait_sock *tcptw)
 {
        return tcp_clock_ts(false) + tcptw->tw_ts_offset;
index ffce17545b62c78595c5dd569665a6ebe6a29bbc..de68cad82d19e37171deadc45c5acc0cfd90c315 100644 (file)
@@ -2442,7 +2442,7 @@ static bool tcp_skb_spurious_retrans(const struct tcp_sock *tp,
                                     const struct sk_buff *skb)
 {
        return (TCP_SKB_CB(skb)->sacked & TCPCB_RETRANS) &&
-              tcp_tsopt_ecr_before(tp, tcp_skb_timestamp(skb));
+              tcp_tsopt_ecr_before(tp, tcp_skb_timestamp_ts(false, skb));
 }
 
 /* Nothing was retransmitted or returned timestamp is less
index 909f85aefd7401aeffcd098356c5e3823bffd89e..03a2a9fc0dc191d7066d679913d41bd2ef2d685a 100644 (file)
@@ -799,7 +799,7 @@ static unsigned int tcp_syn_options(struct sock *sk, struct sk_buff *skb,
 
        if (likely(READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_timestamps) && !*md5)) {
                opts->options |= OPTION_TS;
-               opts->tsval = tcp_skb_timestamp(skb) + tp->tsoffset;
+               opts->tsval = tcp_skb_timestamp_ts(false, skb) + tp->tsoffset;
                opts->tsecr = tp->rx_opt.ts_recent;
                remaining -= TCPOLEN_TSTAMP_ALIGNED;
        }
@@ -884,7 +884,7 @@ static unsigned int tcp_synack_options(const struct sock *sk,
        }
        if (likely(ireq->tstamp_ok)) {
                opts->options |= OPTION_TS;
-               opts->tsval = tcp_skb_timestamp(skb) + tcp_rsk(req)->ts_off;
+               opts->tsval = tcp_skb_timestamp_ts(false, skb) + tcp_rsk(req)->ts_off;
                opts->tsecr = READ_ONCE(req->ts_recent);
                remaining -= TCPOLEN_TSTAMP_ALIGNED;
        }
@@ -943,7 +943,7 @@ static unsigned int tcp_established_options(struct sock *sk, struct sk_buff *skb
 
        if (likely(tp->rx_opt.tstamp_ok)) {
                opts->options |= OPTION_TS;
-               opts->tsval = skb ? tcp_skb_timestamp(skb) + tp->tsoffset : 0;
+               opts->tsval = skb ? tcp_skb_timestamp_ts(false, skb) + tp->tsoffset : 0;
                opts->tsecr = tp->rx_opt.ts_recent;
                size += TCPOLEN_TSTAMP_ALIGNED;
        }
@@ -3379,7 +3379,7 @@ int tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb, int segs)
 
        /* Save stamp of the first (attempted) retransmit. */
        if (!tp->retrans_stamp)
-               tp->retrans_stamp = tcp_skb_timestamp(skb);
+               tp->retrans_stamp = tcp_skb_timestamp_ts(false, skb);
 
        if (tp->undo_retrans < 0)
                tp->undo_retrans = 0;
index 63247c78dc13d445c1e1c5cf24e7ffd7a1faa403..8764a9a2dc213f648ffc64f79950037b1f44ee99 100644 (file)
@@ -479,7 +479,7 @@ static bool tcp_rtx_probe0_timed_out(const struct sock *sk,
                return false;
 
        rtx_delta = (u32)msecs_to_jiffies(tcp_time_stamp(tp) -
-                       (tp->retrans_stamp ?: tcp_skb_timestamp(skb)));
+                       (tp->retrans_stamp ?: tcp_skb_timestamp_ts(false, skb)));
 
        return rtx_delta > timeout;
 }
@@ -534,7 +534,7 @@ void tcp_retransmit_timer(struct sock *sk)
                struct inet_sock *inet = inet_sk(sk);
                u32 rtx_delta;
 
-               rtx_delta = tcp_time_stamp(tp) - (tp->retrans_stamp ?: tcp_skb_timestamp(skb));
+               rtx_delta = tcp_time_stamp(tp) - (tp->retrans_stamp ?: tcp_skb_timestamp_ts(false, skb));
                if (sk->sk_family == AF_INET) {
                        net_dbg_ratelimited("Probing zero-window on %pI4:%u/%u, seq=%u:%u, recv %ums ago, lasting %ums\n",
                                &inet->inet_daddr, ntohs(inet->inet_dport),