diff options
author | Jaroslav Kysela <perex@hera.kernel.org> | 2005-06-21 10:39:41 -0400 |
---|---|---|
committer | Jaroslav Kysela <perex@hera.kernel.org> | 2005-06-21 10:39:41 -0400 |
commit | fae6ec69c84d71b1d5bda9ede1a262c1681684aa (patch) | |
tree | eb4aff9a5c2b7d04ce09a3717bb1dd4a79fe7595 /net/core/request_sock.c | |
parent | bbc0274e9bb2e3f1d724d445a2bd32566b9b66f7 (diff) | |
parent | 1d345dac1f30af1cd9f3a1faa12f9f18f17f236e (diff) |
Merge with /pub/scm/linux/kernel/git/torvalds/linux-2.6.git
Diffstat (limited to 'net/core/request_sock.c')
-rw-r--r-- | net/core/request_sock.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/net/core/request_sock.c b/net/core/request_sock.c new file mode 100644 index 000000000000..bb55675f0685 --- /dev/null +++ b/net/core/request_sock.c | |||
@@ -0,0 +1,64 @@ | |||
1 | /* | ||
2 | * NET Generic infrastructure for Network protocols. | ||
3 | * | ||
4 | * Authors: Arnaldo Carvalho de Melo <acme@conectiva.com.br> | ||
5 | * | ||
6 | * From code originally in include/net/tcp.h | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or | ||
9 | * modify it under the terms of the GNU General Public License | ||
10 | * as published by the Free Software Foundation; either version | ||
11 | * 2 of the License, or (at your option) any later version. | ||
12 | */ | ||
13 | |||
14 | #include <linux/module.h> | ||
15 | #include <linux/random.h> | ||
16 | #include <linux/slab.h> | ||
17 | #include <linux/string.h> | ||
18 | |||
19 | #include <net/request_sock.h> | ||
20 | |||
21 | /* | ||
22 | * Maximum number of SYN_RECV sockets in queue per LISTEN socket. | ||
23 | * One SYN_RECV socket costs about 80bytes on a 32bit machine. | ||
24 | * It would be better to replace it with a global counter for all sockets | ||
25 | * but then some measure against one socket starving all other sockets | ||
26 | * would be needed. | ||
27 | * | ||
28 | * It was 128 by default. Experiments with real servers show, that | ||
29 | * it is absolutely not enough even at 100conn/sec. 256 cures most | ||
30 | * of problems. This value is adjusted to 128 for very small machines | ||
31 | * (<=32Mb of memory) and to 1024 on normal or better ones (>=256Mb). | ||
32 | * Further increasing requires to change hash table size. | ||
33 | */ | ||
34 | int sysctl_max_syn_backlog = 256; | ||
35 | EXPORT_SYMBOL(sysctl_max_syn_backlog); | ||
36 | |||
37 | int reqsk_queue_alloc(struct request_sock_queue *queue, | ||
38 | const int nr_table_entries) | ||
39 | { | ||
40 | const int lopt_size = sizeof(struct listen_sock) + | ||
41 | nr_table_entries * sizeof(struct request_sock *); | ||
42 | struct listen_sock *lopt = kmalloc(lopt_size, GFP_KERNEL); | ||
43 | |||
44 | if (lopt == NULL) | ||
45 | return -ENOMEM; | ||
46 | |||
47 | memset(lopt, 0, lopt_size); | ||
48 | |||
49 | for (lopt->max_qlen_log = 6; | ||
50 | (1 << lopt->max_qlen_log) < sysctl_max_syn_backlog; | ||
51 | lopt->max_qlen_log++); | ||
52 | |||
53 | get_random_bytes(&lopt->hash_rnd, sizeof(lopt->hash_rnd)); | ||
54 | rwlock_init(&queue->syn_wait_lock); | ||
55 | queue->rskq_accept_head = queue->rskq_accept_head = NULL; | ||
56 | |||
57 | write_lock_bh(&queue->syn_wait_lock); | ||
58 | queue->listen_opt = lopt; | ||
59 | write_unlock_bh(&queue->syn_wait_lock); | ||
60 | |||
61 | return 0; | ||
62 | } | ||
63 | |||
64 | EXPORT_SYMBOL(reqsk_queue_alloc); | ||