tcp_options.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * $Id$
  3. *
  4. * Copyright (C) 2007 iptelorg GmbH
  5. *
  6. * Permission to use, copy, modify, and distribute this software for any
  7. * purpose with or without fee is hereby granted, provided that the above
  8. * copyright notice and this permission notice appear in all copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  11. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  12. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  13. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  14. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  15. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  16. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. /*
  19. * tcp options
  20. *
  21. * History:
  22. * --------
  23. * 2007-11-28 created by andrei
  24. */
  25. #include "tcp_options.h"
  26. #include "dprint.h"
  27. #include "globals.h"
  28. #include "timer_ticks.h"
  29. struct tcp_cfg_options tcp_options;
  30. /* set defaults */
  31. void init_tcp_options()
  32. {
  33. #ifdef TCP_BUF_WRITE
  34. tcp_options.tcp_buf_write=0;
  35. tcp_options.tcpconn_wq_max=32*1024; /* 32 k */
  36. tcp_options.tcp_wq_max=10*1024*1024; /* 10 MB */
  37. tcp_options.tcp_wq_timeout=S_TO_TICKS(tcp_send_timeout);
  38. #ifdef TCP_CONNECT_WAIT
  39. tcp_options.tcp_connect_wait=1;
  40. #endif /* TCP_CONNECT_WAIT */
  41. #endif /* TCP_BUF_WRITE */
  42. #ifdef TCP_FD_CACHE
  43. tcp_options.fd_cache=1;
  44. #endif
  45. #ifdef HAVE_SO_KEEPALIVE
  46. tcp_options.keepalive=1;
  47. #endif
  48. /*
  49. #if defined HAVE_TCP_DEFER_ACCEPT || defined HAVE_TCP_ACCEPT_FILTER
  50. tcp_options.defer_accept=1;
  51. #endif
  52. */
  53. #ifdef HAVE_TCP_QUICKACK
  54. tcp_options.delayed_ack=1;
  55. #endif
  56. tcp_options.crlf_ping=1;
  57. }
  58. #define W_OPT_NC(option) \
  59. if (tcp_options.option){\
  60. WARN("tcp_options: tcp_" #option \
  61. " cannot be enabled (recompile needed)\n"); \
  62. tcp_options.option=0; \
  63. }
  64. #define W_OPT_NS(option) \
  65. if (tcp_options.option){\
  66. WARN("tcp_options: tcp_" #option \
  67. " cannot be enabled (no OS support)\n"); \
  68. tcp_options.option=0; \
  69. }
  70. /* checks & warns if some tcp_option cannot be enabled */
  71. void tcp_options_check()
  72. {
  73. #ifndef TCP_FD_CACHE
  74. W_OPT_NC(defer_accept);
  75. #endif
  76. #ifndef TCP_BUF_WRITE
  77. W_OPT_NC(tcp_buf_write);
  78. W_OPT_NC(tcpconn_wq_max);
  79. W_OPT_NC(tcp_wq_max);
  80. W_OPT_NC(tcp_wq_timeout);
  81. #endif /* TCP_BUF_WRITE */
  82. #ifndef TCP_CONNECT_WAIT
  83. W_OPT_NC(tcp_connect_wait);
  84. #endif /* TCP_CONNECT_WAIT */
  85. if (tcp_options.tcp_connect_wait && !tcp_options.tcp_buf_write){
  86. WARN("tcp_options: tcp_connect_wait depends on tcp_buf_write, "
  87. " disabling...\n");
  88. tcp_options.tcp_connect_wait=0;
  89. }
  90. #if ! defined HAVE_TCP_DEFER_ACCEPT && ! defined HAVE_TCP_ACCEPT_FILTER
  91. W_OPT_NS(defer_accept);
  92. #endif
  93. #ifndef HAVE_TCP_SYNCNT
  94. W_OPT_NS(syncnt);
  95. #endif
  96. #ifndef HAVE_TCP_LINGER2
  97. W_OPT_NS(linger2);
  98. #endif
  99. #ifndef HAVE_TCP_KEEPINTVL
  100. W_OPT_NS(keepintvl);
  101. #endif
  102. #ifndef HAVE_TCP_KEEPIDLE
  103. W_OPT_NS(keepidle);
  104. #endif
  105. #ifndef HAVE_TCP_KEEPCNT
  106. W_OPT_NS(keepcnt);
  107. #endif
  108. if (tcp_options.keepintvl || tcp_options.keepidle || tcp_options.keepcnt){
  109. tcp_options.keepalive=1; /* force on */
  110. }
  111. #ifndef HAVE_SO_KEEPALIVE
  112. W_OPT_NS(keepalive);
  113. #endif
  114. #ifndef HAVE_TCP_QUICKACK
  115. W_OPT_NS(delayed_ack);
  116. #endif
  117. }
  118. void tcp_options_get(struct tcp_cfg_options* t)
  119. {
  120. *t=tcp_options;
  121. }