tcp_options.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * Copyright (C) 2007 iptelorg GmbH
  3. *
  4. * Permission to use, copy, modify, and distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. /*! \file
  17. * \brief tcp options
  18. *
  19. */
  20. #ifndef tcp_options_h
  21. #define tcp_options_h
  22. #ifdef USE_TCP
  23. #ifndef NO_TCP_ASYNC
  24. #define TCP_ASYNC /* enabled async mode */
  25. #endif
  26. #if !defined(NO_TCP_CONNECT_WAIT) && defined(TCP_ASYNC)
  27. #define TCP_CONNECT_WAIT /* enable pending connects support */
  28. #endif
  29. #if defined(TCP_CONNECT_WAIT) && !defined(TCP_ASYNC)
  30. /* check for impossible configuration: TCP_CONNECT_WAIT w/o TCP_ASYNC */
  31. #warning "disabling TCP_CONNECT_WAIT because TCP_ASYNC is not defined"
  32. #undef TCP_CONNECT_WAIT
  33. #endif
  34. #ifndef NO_TCP_FD_CACHE
  35. #define TCP_FD_CACHE /* enable fd caching */
  36. #endif
  37. /* defer accept */
  38. #ifndef NO_TCP_DEFER_ACCEPT
  39. #ifdef __OS_linux
  40. #define HAVE_TCP_DEFER_ACCEPT
  41. #elif defined __OS_freebsd
  42. #define HAVE_TCP_ACCEPT_FILTER
  43. #endif /* __OS_ */
  44. #endif /* NO_TCP_DEFER_ACCEPT */
  45. /* syn count */
  46. #ifndef NO_TCP_SYNCNT
  47. #ifdef __OS_linux
  48. #define HAVE_TCP_SYNCNT
  49. #endif /* __OS_*/
  50. #endif /* NO_TCP_SYNCNT */
  51. /* tcp linger2 */
  52. #ifndef NO_TCP_LINGER2
  53. #ifdef __OS_linux
  54. #define HAVE_TCP_LINGER2
  55. #endif /* __OS_ */
  56. #endif /* NO_TCP_LINGER2 */
  57. /* keepalive */
  58. #ifndef NO_TCP_KEEPALIVE
  59. #define HAVE_SO_KEEPALIVE
  60. #endif /* NO_TCP_KEEPALIVE */
  61. /* keepintvl */
  62. #ifndef NO_TCP_KEEPINTVL
  63. #ifdef __OS_linux
  64. #define HAVE_TCP_KEEPINTVL
  65. #endif /* __OS_ */
  66. #endif /* NO_TCP_KEEPIDLE */
  67. /* keepidle */
  68. #ifndef NO_TCP_KEEPIDLE
  69. #ifdef __OS_linux
  70. #define HAVE_TCP_KEEPIDLE
  71. #endif /* __OS_*/
  72. #endif /* NO_TCP_KEEPIDLE */
  73. /* keepcnt */
  74. #ifndef NO_TCP_KEEPCNT
  75. #ifdef __OS_linux
  76. #define HAVE_TCP_KEEPCNT
  77. #endif /* __OS_ */
  78. #endif /* NO_TCP_KEEPCNT */
  79. /* delayed ack (quick_ack) */
  80. #ifndef NO_TCP_QUICKACK
  81. #ifdef __OS_linux
  82. #define HAVE_TCP_QUICKACK
  83. #endif /* __OS_ */
  84. #endif /* NO_TCP_QUICKACK */
  85. #endif /* USE_TCP */
  86. struct cfg_group_tcp{
  87. /* ser tcp options, low level */
  88. int connect_timeout_s; /* in s */
  89. int send_timeout; /* in ticks (s fixed to ticks) */
  90. int con_lifetime; /* in ticks (s fixed to ticks) */
  91. int max_connections; /* max tcp connections (includes tls connections) */
  92. int max_tls_connections; /* max tls connections */
  93. int no_connect; /* do not open any new tcp connection (but accept them) */
  94. int fd_cache; /* on /off */
  95. /* tcp async options */
  96. int async; /* on / off */
  97. int tcp_connect_wait; /* on / off, depends on async */
  98. unsigned int tcpconn_wq_max; /* maximum queue len per connection */
  99. unsigned int tcp_wq_max; /* maximum overall queued bytes */
  100. /* tcp socket options */
  101. int defer_accept; /* on / off */
  102. int delayed_ack; /* delay ack on connect */
  103. int syncnt; /* numbers of SYNs retrs. before giving up connecting */
  104. int linger2; /* lifetime of orphaned FIN_WAIT2 state sockets */
  105. int keepalive; /* on /off */
  106. int keepidle; /* idle time (s) before tcp starts sending keepalives */
  107. int keepintvl; /* interval between keep alives */
  108. int keepcnt; /* maximum no. of keepalives before giving up */
  109. /* other options */
  110. int crlf_ping; /* on/off - reply to double CRLF keepalives */
  111. int accept_aliases;
  112. int alias_flags;
  113. int new_conn_alias_flags;
  114. int accept_no_cl; /* on/off - accept messages without content-length */
  115. /* internal, "fixed" vars */
  116. unsigned int rd_buf_size; /* read buffer size (should be > max. datagram)*/
  117. unsigned int wq_blk_size; /* async write block size (debugging use) */
  118. };
  119. extern struct cfg_group_tcp tcp_default_cfg;
  120. /* tcp config handle*/
  121. extern void* tcp_cfg;
  122. void init_tcp_options(void);
  123. void tcp_options_check(void);
  124. int tcp_register_cfg(void);
  125. void tcp_options_get(struct cfg_group_tcp* t);
  126. #ifdef USE_TCP
  127. int tcp_set_clone_rcvbuf(int v);
  128. #endif /* USE_TCP */
  129. #endif /* tcp_options_h */