syncookies.c (b44084c2c822f99dd3f2334b288b7e463d222662) syncookies.c (b23a002fc6f0c19846ee0382f019429af54a27e9)
1/*
2 * Syncookies implementation for the Linux kernel
3 *
4 * Copyright (C) 1997 Andi Kleen
5 * Based on ideas by D.J.Bernstein and Eric Schenk.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License

--- 11 unchanged lines hidden (view full) ---

20#include <net/route.h>
21
22/* Timestamps: lowest bits store TCP options */
23#define TSBITS 6
24#define TSMASK (((__u32)1 << TSBITS) - 1)
25
26extern int sysctl_tcp_syncookies;
27
1/*
2 * Syncookies implementation for the Linux kernel
3 *
4 * Copyright (C) 1997 Andi Kleen
5 * Based on ideas by D.J.Bernstein and Eric Schenk.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License

--- 11 unchanged lines hidden (view full) ---

20#include <net/route.h>
21
22/* Timestamps: lowest bits store TCP options */
23#define TSBITS 6
24#define TSMASK (((__u32)1 << TSBITS) - 1)
25
26extern int sysctl_tcp_syncookies;
27
28__u32 syncookie_secret[2][16-4+SHA_DIGEST_WORDS];
29EXPORT_SYMBOL(syncookie_secret);
28static u32 syncookie_secret[2][16-4+SHA_DIGEST_WORDS];
30
29
31static __init int init_syncookies(void)
32{
33 get_random_bytes(syncookie_secret, sizeof(syncookie_secret));
34 return 0;
35}
36__initcall(init_syncookies);
37
38#define COOKIEBITS 24 /* Upper bits store count */
39#define COOKIEMASK (((__u32)1 << COOKIEBITS) - 1)
40
41static DEFINE_PER_CPU(__u32 [16 + 5 + SHA_WORKSPACE_WORDS],
42 ipv4_cookie_scratch);
43
44static u32 cookie_hash(__be32 saddr, __be32 daddr, __be16 sport, __be16 dport,
45 u32 count, int c)
46{
30#define COOKIEBITS 24 /* Upper bits store count */
31#define COOKIEMASK (((__u32)1 << COOKIEBITS) - 1)
32
33static DEFINE_PER_CPU(__u32 [16 + 5 + SHA_WORKSPACE_WORDS],
34 ipv4_cookie_scratch);
35
36static u32 cookie_hash(__be32 saddr, __be32 daddr, __be16 sport, __be16 dport,
37 u32 count, int c)
38{
47 __u32 *tmp = __get_cpu_var(ipv4_cookie_scratch);
39 __u32 *tmp;
48
40
41 net_get_random_once(syncookie_secret, sizeof(syncookie_secret));
42
43 tmp = __get_cpu_var(ipv4_cookie_scratch);
49 memcpy(tmp + 4, syncookie_secret[c], sizeof(syncookie_secret[c]));
50 tmp[0] = (__force u32)saddr;
51 tmp[1] = (__force u32)daddr;
52 tmp[2] = ((__force u32)sport << 16) + (__force u32)dport;
53 tmp[3] = count;
54 sha_transform(tmp + 16, (__u8 *)tmp, tmp + 16 + 5);
55
56 return tmp[17];

--- 320 unchanged lines hidden ---
44 memcpy(tmp + 4, syncookie_secret[c], sizeof(syncookie_secret[c]));
45 tmp[0] = (__force u32)saddr;
46 tmp[1] = (__force u32)daddr;
47 tmp[2] = ((__force u32)sport << 16) + (__force u32)dport;
48 tmp[3] = count;
49 sha_transform(tmp + 16, (__u8 *)tmp, tmp + 16 + 5);
50
51 return tmp[17];

--- 320 unchanged lines hidden ---