request_sock.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. #include <linux/module.h>
  14. #include <linux/random.h>
  15. #include <linux/slab.h>
  16. #include <linux/string.h>
  17. #include <net/request_sock.h>
  18. int reqsk_queue_alloc(struct request_sock_queue *queue,
  19. const int nr_table_entries)
  20. {
  21. const int lopt_size = sizeof(struct listen_sock) +
  22. nr_table_entries * sizeof(struct request_sock *);
  23. struct listen_sock *lopt = kmalloc(lopt_size, GFP_KERNEL);
  24. if (lopt == NULL)
  25. return -ENOMEM;
  26. memset(lopt, 0, lopt_size);
  27. for (lopt->max_qlen_log = 6;
  28. (1 << lopt->max_qlen_log) < sysctl_max_syn_backlog;
  29. lopt->max_qlen_log++);
  30. get_random_bytes(&lopt->hash_rnd, sizeof(lopt->hash_rnd));
  31. rwlock_init(&queue->syn_wait_lock);
  32. queue->rskq_accept_head = queue->rskq_accept_head = NULL;
  33. write_lock_bh(&queue->syn_wait_lock);
  34. queue->listen_opt = lopt;
  35. write_unlock_bh(&queue->syn_wait_lock);
  36. return 0;
  37. }
  38. EXPORT_SYMBOL(reqsk_queue_alloc);