syncookies.c (73ed8e03388d16c12fc577e5c700b58a29045a15) | syncookies.c (003e07a1e48e9423647d2fef1c86b4caab3a94be) |
---|---|
1// SPDX-License-Identifier: GPL-2.0-or-later 2/* 3 * Syncookies implementation for the Linux kernel 4 * 5 * Copyright (C) 1997 Andi Kleen 6 * Based on ideas by D.J.Bernstein and Eric Schenk. 7 */ 8 --- 37 unchanged lines hidden (view full) --- 46 u32 count, int c) 47{ 48 net_get_random_once(syncookie_secret, sizeof(syncookie_secret)); 49 return siphash_4u32((__force u32)saddr, (__force u32)daddr, 50 (__force u32)sport << 16 | (__force u32)dport, 51 count, &syncookie_secret[c]); 52} 53 | 1// SPDX-License-Identifier: GPL-2.0-or-later 2/* 3 * Syncookies implementation for the Linux kernel 4 * 5 * Copyright (C) 1997 Andi Kleen 6 * Based on ideas by D.J.Bernstein and Eric Schenk. 7 */ 8 --- 37 unchanged lines hidden (view full) --- 46 u32 count, int c) 47{ 48 net_get_random_once(syncookie_secret, sizeof(syncookie_secret)); 49 return siphash_4u32((__force u32)saddr, (__force u32)daddr, 50 (__force u32)sport << 16 | (__force u32)dport, 51 count, &syncookie_secret[c]); 52} 53 |
54/* Convert one nsec 64bit timestamp to ts (ms or usec resolution) */ 55static u64 tcp_ns_to_ts(bool usec_ts, u64 val) 56{ 57 if (usec_ts) 58 return div_u64(val, NSEC_PER_USEC); |
|
54 | 59 |
60 return div_u64(val, NSEC_PER_MSEC); 61} 62 |
|
55/* 56 * when syncookies are in effect and tcp timestamps are enabled we encode 57 * tcp options in the lower bits of the timestamp value that will be 58 * sent in the syn-ack. 59 * Since subsequent timestamps use the normal tcp_time_stamp value, we 60 * must make sure that the resulting initial timestamp is <= tcp_time_stamp. 61 */ 62u64 cookie_init_timestamp(struct request_sock *req, u64 now) 63{ 64 const struct inet_request_sock *ireq = inet_rsk(req); | 63/* 64 * when syncookies are in effect and tcp timestamps are enabled we encode 65 * tcp options in the lower bits of the timestamp value that will be 66 * sent in the syn-ack. 67 * Since subsequent timestamps use the normal tcp_time_stamp value, we 68 * must make sure that the resulting initial timestamp is <= tcp_time_stamp. 69 */ 70u64 cookie_init_timestamp(struct request_sock *req, u64 now) 71{ 72 const struct inet_request_sock *ireq = inet_rsk(req); |
65 u64 ts, ts_now = tcp_ns_to_ts(now); | 73 u64 ts, ts_now = tcp_ns_to_ts(false, now); |
66 u32 options = 0; 67 68 options = ireq->wscale_ok ? ireq->snd_wscale : TS_OPT_WSCALE_MASK; 69 if (ireq->sack_ok) 70 options |= TS_OPT_SACK; 71 if (ireq->ecn_ok) 72 options |= TS_OPT_ECN; 73 --- 376 unchanged lines hidden --- | 74 u32 options = 0; 75 76 options = ireq->wscale_ok ? ireq->snd_wscale : TS_OPT_WSCALE_MASK; 77 if (ireq->sack_ok) 78 options |= TS_OPT_SACK; 79 if (ireq->ecn_ok) 80 options |= TS_OPT_ECN; 81 --- 376 unchanged lines hidden --- |