summaryrefslogtreecommitdiff
path: root/net/ipv4
diff options
context:
space:
mode:
authorEric Dumazet <edumazet@google.com>2023-10-20 12:57:42 +0000
committerDavid S. Miller <davem@davemloft.net>2023-10-23 09:35:01 +0100
commit003e07a1e48e9423647d2fef1c86b4caab3a94be (patch)
tree2f9ab2156cf5cb6b24543d4076ff954d619596e5 /net/ipv4
parentd1a02ed66fe62aa2edd77bd54e270ebc33bd12ff (diff)
tcp: move tcp_ns_to_ts() to net/ipv4/syncookies.c
tcp_ns_to_ts() is only used once from cookie_init_timestamp(). Also add the 'bool usec_ts' parameter to enable usec TS later. Signed-off-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4')
-rw-r--r--net/ipv4/syncookies.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/net/ipv4/syncookies.c b/net/ipv4/syncookies.c
index 3b4dafefb4b0..62395fdb0ca5 100644
--- a/net/ipv4/syncookies.c
+++ b/net/ipv4/syncookies.c
@@ -51,6 +51,14 @@ static u32 cookie_hash(__be32 saddr, __be32 daddr, __be16 sport, __be16 dport,
count, &syncookie_secret[c]);
}
+/* Convert one nsec 64bit timestamp to ts (ms or usec resolution) */
+static u64 tcp_ns_to_ts(bool usec_ts, u64 val)
+{
+ if (usec_ts)
+ return div_u64(val, NSEC_PER_USEC);
+
+ return div_u64(val, NSEC_PER_MSEC);
+}
/*
* when syncookies are in effect and tcp timestamps are enabled we encode
@@ -62,7 +70,7 @@ static u32 cookie_hash(__be32 saddr, __be32 daddr, __be16 sport, __be16 dport,
u64 cookie_init_timestamp(struct request_sock *req, u64 now)
{
const struct inet_request_sock *ireq = inet_rsk(req);
- u64 ts, ts_now = tcp_ns_to_ts(now);
+ u64 ts, ts_now = tcp_ns_to_ts(false, now);
u32 options = 0;
options = ireq->wscale_ok ? ireq->snd_wscale : TS_OPT_WSCALE_MASK;