[CONNECTOR]: Update documentation to match reality.
[linux-2.6/verdex.git] / net / core / request_sock.c
blobb8203de5ff073c4e3bda5166ef1542b793141a0c
1 /*
2 * NET Generic infrastructure for Network protocols.
4 * Authors: Arnaldo Carvalho de Melo <acme@conectiva.com.br>
6 * From code originally in include/net/tcp.h
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.
14 #include <linux/module.h>
15 #include <linux/random.h>
16 #include <linux/slab.h>
17 #include <linux/string.h>
19 #include <net/request_sock.h>
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.
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.
34 int sysctl_max_syn_backlog = 256;
36 int reqsk_queue_alloc(struct request_sock_queue *queue,
37 const int nr_table_entries)
39 const int lopt_size = sizeof(struct listen_sock) +
40 nr_table_entries * sizeof(struct request_sock *);
41 struct listen_sock *lopt = kmalloc(lopt_size, GFP_KERNEL);
43 if (lopt == NULL)
44 return -ENOMEM;
46 memset(lopt, 0, lopt_size);
48 for (lopt->max_qlen_log = 6;
49 (1 << lopt->max_qlen_log) < sysctl_max_syn_backlog;
50 lopt->max_qlen_log++);
52 get_random_bytes(&lopt->hash_rnd, sizeof(lopt->hash_rnd));
53 rwlock_init(&queue->syn_wait_lock);
54 queue->rskq_accept_head = queue->rskq_accept_head = NULL;
55 queue->rskq_defer_accept = 0;
56 lopt->nr_table_entries = nr_table_entries;
58 write_lock_bh(&queue->syn_wait_lock);
59 queue->listen_opt = lopt;
60 write_unlock_bh(&queue->syn_wait_lock);
62 return 0;
65 EXPORT_SYMBOL(reqsk_queue_alloc);
67 void reqsk_queue_destroy(struct request_sock_queue *queue)
69 /* make all the listen_opt local to us */
70 struct listen_sock *lopt = reqsk_queue_yank_listen_sk(queue);
72 if (lopt->qlen != 0) {
73 int i;
75 for (i = 0; i < lopt->nr_table_entries; i++) {
76 struct request_sock *req;
78 while ((req = lopt->syn_table[i]) != NULL) {
79 lopt->syn_table[i] = req->dl_next;
80 lopt->qlen--;
81 reqsk_free(req);
86 BUG_TRAP(lopt->qlen == 0);
87 kfree(lopt);
90 EXPORT_SYMBOL(reqsk_queue_destroy);