Commit 16cf6477 authored by Eric Dumazet's avatar Eric Dumazet Committed by David S. Miller

tcp: replace tcp_time_stamp_raw()

In preparation of usec TCP TS support, remove tcp_time_stamp_raw()
in favor of tcp_clock_ts() helper. This helper will return a suitable
32bit result to feed TS values, depending on a socket field.

Also add tcp_tw_tsval() and tcp_rsk_tsval() helpers to factorize
the details.

We do not yet support usec timestamps.
Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 2a7c8d29
...@@ -803,6 +803,16 @@ static inline u64 tcp_clock_ms(void) ...@@ -803,6 +803,16 @@ static inline u64 tcp_clock_ms(void)
return div_u64(tcp_clock_ns(), NSEC_PER_MSEC); return div_u64(tcp_clock_ns(), NSEC_PER_MSEC);
} }
/* TCP Timestamp included in TS option (RFC 1323) can either use ms
* or usec resolution. Each socket carries a flag to select one or other
* resolution, as the route attribute could change anytime.
* Each flow must stick to initial resolution.
*/
static inline u32 tcp_clock_ts(bool usec_ts)
{
return usec_ts ? tcp_clock_us() : tcp_clock_ms();
}
/* This should only be used in contexts where tp->tcp_mstamp is up to date */ /* This should only be used in contexts where tp->tcp_mstamp is up to date */
static inline u32 tcp_time_stamp(const struct tcp_sock *tp) static inline u32 tcp_time_stamp(const struct tcp_sock *tp)
{ {
...@@ -820,12 +830,6 @@ static inline u64 tcp_ns_to_ts(u64 ns) ...@@ -820,12 +830,6 @@ static inline u64 tcp_ns_to_ts(u64 ns)
return div_u64(ns, NSEC_PER_SEC / TCP_TS_HZ); return div_u64(ns, NSEC_PER_SEC / TCP_TS_HZ);
} }
/* Could use tcp_clock_us() / 1000, but this version uses a single divide */
static inline u32 tcp_time_stamp_raw(void)
{
return tcp_ns_to_ts(tcp_clock_ns());
}
void tcp_mstamp_refresh(struct tcp_sock *tp); void tcp_mstamp_refresh(struct tcp_sock *tp);
static inline u32 tcp_stamp_us_delta(u64 t1, u64 t0) static inline u32 tcp_stamp_us_delta(u64 t1, u64 t0)
...@@ -844,6 +848,15 @@ static inline u64 tcp_skb_timestamp_us(const struct sk_buff *skb) ...@@ -844,6 +848,15 @@ static inline u64 tcp_skb_timestamp_us(const struct sk_buff *skb)
return div_u64(skb->skb_mstamp_ns, NSEC_PER_USEC); return div_u64(skb->skb_mstamp_ns, NSEC_PER_USEC);
} }
static inline u32 tcp_tw_tsval(const struct tcp_timewait_sock *tcptw)
{
return tcp_clock_ts(false) + tcptw->tw_ts_offset;
}
static inline u32 tcp_rsk_tsval(const struct tcp_request_sock *treq)
{
return tcp_clock_ts(false) + treq->ts_off;
}
#define tcp_flag_byte(th) (((u_int8_t *)th)[13]) #define tcp_flag_byte(th) (((u_int8_t *)th)[13])
......
...@@ -3632,7 +3632,7 @@ int do_tcp_setsockopt(struct sock *sk, int level, int optname, ...@@ -3632,7 +3632,7 @@ int do_tcp_setsockopt(struct sock *sk, int level, int optname,
if (!tp->repair) if (!tp->repair)
err = -EPERM; err = -EPERM;
else else
WRITE_ONCE(tp->tsoffset, val - tcp_time_stamp_raw()); WRITE_ONCE(tp->tsoffset, val - tcp_clock_ts(false));
break; break;
case TCP_REPAIR_WINDOW: case TCP_REPAIR_WINDOW:
err = tcp_repair_set_window(tp, optval, optlen); err = tcp_repair_set_window(tp, optval, optlen);
...@@ -4143,7 +4143,7 @@ int do_tcp_getsockopt(struct sock *sk, int level, ...@@ -4143,7 +4143,7 @@ int do_tcp_getsockopt(struct sock *sk, int level,
break; break;
case TCP_TIMESTAMP: case TCP_TIMESTAMP:
val = tcp_time_stamp_raw() + READ_ONCE(tp->tsoffset); val = tcp_clock_ts(false) + READ_ONCE(tp->tsoffset);
break; break;
case TCP_NOTSENT_LOWAT: case TCP_NOTSENT_LOWAT:
val = READ_ONCE(tp->notsent_lowat); val = READ_ONCE(tp->notsent_lowat);
......
...@@ -954,7 +954,7 @@ static void tcp_v4_timewait_ack(struct sock *sk, struct sk_buff *skb) ...@@ -954,7 +954,7 @@ static void tcp_v4_timewait_ack(struct sock *sk, struct sk_buff *skb)
tcp_v4_send_ack(sk, skb, tcp_v4_send_ack(sk, skb,
tcptw->tw_snd_nxt, tcptw->tw_rcv_nxt, tcptw->tw_snd_nxt, tcptw->tw_rcv_nxt,
tcptw->tw_rcv_wnd >> tw->tw_rcv_wscale, tcptw->tw_rcv_wnd >> tw->tw_rcv_wscale,
tcp_time_stamp_raw() + tcptw->tw_ts_offset, tcp_tw_tsval(tcptw),
tcptw->tw_ts_recent, tcptw->tw_ts_recent,
tw->tw_bound_dev_if, tw->tw_bound_dev_if,
tcp_twsk_md5_key(tcptw), tcp_twsk_md5_key(tcptw),
...@@ -988,7 +988,7 @@ static void tcp_v4_reqsk_send_ack(const struct sock *sk, struct sk_buff *skb, ...@@ -988,7 +988,7 @@ static void tcp_v4_reqsk_send_ack(const struct sock *sk, struct sk_buff *skb,
tcp_v4_send_ack(sk, skb, seq, tcp_v4_send_ack(sk, skb, seq,
tcp_rsk(req)->rcv_nxt, tcp_rsk(req)->rcv_nxt,
req->rsk_rcv_wnd >> inet_rsk(req)->rcv_wscale, req->rsk_rcv_wnd >> inet_rsk(req)->rcv_wscale,
tcp_time_stamp_raw() + tcp_rsk(req)->ts_off, tcp_rsk_tsval(tcp_rsk(req)),
READ_ONCE(req->ts_recent), READ_ONCE(req->ts_recent),
0, 0,
tcp_md5_do_lookup(sk, l3index, addr, AF_INET), tcp_md5_do_lookup(sk, l3index, addr, AF_INET),
......
...@@ -1096,7 +1096,7 @@ static void tcp_v6_timewait_ack(struct sock *sk, struct sk_buff *skb) ...@@ -1096,7 +1096,7 @@ static void tcp_v6_timewait_ack(struct sock *sk, struct sk_buff *skb)
tcp_v6_send_ack(sk, skb, tcptw->tw_snd_nxt, tcptw->tw_rcv_nxt, tcp_v6_send_ack(sk, skb, tcptw->tw_snd_nxt, tcptw->tw_rcv_nxt,
tcptw->tw_rcv_wnd >> tw->tw_rcv_wscale, tcptw->tw_rcv_wnd >> tw->tw_rcv_wscale,
tcp_time_stamp_raw() + tcptw->tw_ts_offset, tcp_tw_tsval(tcptw),
tcptw->tw_ts_recent, tw->tw_bound_dev_if, tcp_twsk_md5_key(tcptw), tcptw->tw_ts_recent, tw->tw_bound_dev_if, tcp_twsk_md5_key(tcptw),
tw->tw_tclass, cpu_to_be32(tw->tw_flowlabel), tw->tw_priority, tw->tw_tclass, cpu_to_be32(tw->tw_flowlabel), tw->tw_priority,
tw->tw_txhash); tw->tw_txhash);
...@@ -1123,7 +1123,7 @@ static void tcp_v6_reqsk_send_ack(const struct sock *sk, struct sk_buff *skb, ...@@ -1123,7 +1123,7 @@ static void tcp_v6_reqsk_send_ack(const struct sock *sk, struct sk_buff *skb,
tcp_rsk(req)->snt_isn + 1 : tcp_sk(sk)->snd_nxt, tcp_rsk(req)->snt_isn + 1 : tcp_sk(sk)->snd_nxt,
tcp_rsk(req)->rcv_nxt, tcp_rsk(req)->rcv_nxt,
req->rsk_rcv_wnd >> inet_rsk(req)->rcv_wscale, req->rsk_rcv_wnd >> inet_rsk(req)->rcv_wscale,
tcp_time_stamp_raw() + tcp_rsk(req)->ts_off, tcp_rsk_tsval(tcp_rsk(req)),
READ_ONCE(req->ts_recent), sk->sk_bound_dev_if, READ_ONCE(req->ts_recent), sk->sk_bound_dev_if,
tcp_v6_md5_do_lookup(sk, &ipv6_hdr(skb)->saddr, l3index), tcp_v6_md5_do_lookup(sk, &ipv6_hdr(skb)->saddr, l3index),
ipv6_get_dsfield(ipv6_hdr(skb)), 0, ipv6_get_dsfield(ipv6_hdr(skb)), 0,
......
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