tcp_timer.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /* $OpenBSD: tcp_timer.h,v 1.13 2011/07/06 23:44:20 sthen Exp $ */
  2. /* $NetBSD: tcp_timer.h,v 1.6 1995/03/26 20:32:37 jtc Exp $ */
  3. /*
  4. * Copyright (c) 1982, 1986, 1993
  5. * The Regents of the University of California. All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of the University nor the names of its contributors
  16. * may be used to endorse or promote products derived from this software
  17. * without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  20. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  23. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  24. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  25. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  26. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  27. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  28. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  29. * SUCH DAMAGE.
  30. *
  31. * @(#)tcp_timer.h 8.1 (Berkeley) 6/10/93
  32. */
  33. #ifndef _NETINET_TCP_TIMER_H_
  34. #define _NETINET_TCP_TIMER_H_
  35. /*
  36. * Definitions of the TCP timers. These timers are counted
  37. * down PR_SLOWHZ times a second.
  38. */
  39. #define TCPT_NTIMERS 4
  40. #define TCPT_REXMT 0 /* retransmit */
  41. #define TCPT_PERSIST 1 /* retransmit persistence */
  42. #define TCPT_KEEP 2 /* keep alive */
  43. #define TCPT_2MSL 3 /* 2*msl quiet time timer */
  44. /*
  45. * The TCPT_REXMT timer is used to force retransmissions.
  46. * The TCP has the TCPT_REXMT timer set whenever segments
  47. * have been sent for which ACKs are expected but not yet
  48. * received. If an ACK is received which advances tp->snd_una,
  49. * then the retransmit timer is cleared (if there are no more
  50. * outstanding segments) or reset to the base value (if there
  51. * are more ACKs expected). Whenever the retransmit timer goes off,
  52. * we retransmit one unacknowledged segment, and do a backoff
  53. * on the retransmit timer.
  54. *
  55. * The TCPT_PERSIST timer is used to keep window size information
  56. * flowing even if the window goes shut. If all previous transmissions
  57. * have been acknowledged (so that there are no retransmissions in progress),
  58. * and the window is too small to bother sending anything, then we start
  59. * the TCPT_PERSIST timer. When it expires, if the window is nonzero,
  60. * we go to transmit state. Otherwise, at intervals send a single byte
  61. * into the peer's window to force him to update our window information.
  62. * We do this at most as often as TCPT_PERSMIN time intervals,
  63. * but no more frequently than the current estimate of round-trip
  64. * packet time. The TCPT_PERSIST timer is cleared whenever we receive
  65. * a window update from the peer.
  66. *
  67. * The TCPT_KEEP timer is used to keep connections alive. If an
  68. * connection is idle (no segments received) for TCPTV_KEEP_INIT amount of time,
  69. * but not yet established, then we drop the connection. Once the connection
  70. * is established, if the connection is idle for TCPTV_KEEP_IDLE time
  71. * (and keepalives have been enabled on the socket), we begin to probe
  72. * the connection. We force the peer to send us a segment by sending:
  73. * <SEQ=SND.UNA-1><ACK=RCV.NXT><CTL=ACK>
  74. * This segment is (deliberately) outside the window, and should elicit
  75. * an ack segment in response from the peer. If, despite the TCPT_KEEP
  76. * initiated segments we cannot elicit a response from a peer in TCPT_MAXIDLE
  77. * amount of time probing, then we drop the connection.
  78. */
  79. /*
  80. * Time constants.
  81. */
  82. #define TCPTV_MSL ( 30*PR_SLOWHZ) /* max seg lifetime (hah!) */
  83. #define TCPTV_SRTTBASE 0 /* base roundtrip time;
  84. if 0, no idea yet */
  85. #define TCPTV_SRTTDFLT ( 3*PR_SLOWHZ) /* assumed RTT if no info */
  86. #define TCPTV_PERSMIN ( 5*PR_SLOWHZ) /* retransmit persistence */
  87. #define TCPTV_PERSMAX ( 60*PR_SLOWHZ) /* maximum persist interval */
  88. #define TCPTV_KEEP_INIT ( 75*PR_SLOWHZ) /* initial connect keep alive */
  89. #define TCPTV_KEEP_IDLE (120*60*PR_SLOWHZ) /* dflt time before probing */
  90. #define TCPTV_KEEPINTVL ( 75*PR_SLOWHZ) /* default probe interval */
  91. #define TCPTV_KEEPCNT 8 /* max probes before drop */
  92. #define TCPTV_MIN ( 1*PR_SLOWHZ) /* minimum allowable value */
  93. #define TCPTV_REXMTMAX ( 64*PR_SLOWHZ) /* max allowable REXMT value */
  94. #define TCP_LINGERTIME 120 /* linger at most 2 minutes */
  95. #define TCP_MAXRXTSHIFT 12 /* maximum retransmits */
  96. #define TCP_DELACK_TICKS (hz / PR_FASTHZ) /* time to delay ACK */
  97. #ifdef TCPTIMERS
  98. const char *tcptimers[] =
  99. { "REXMT", "PERSIST", "KEEP", "2MSL" };
  100. #endif /* TCPTIMERS */
  101. /*
  102. * Init, arm, disarm, and test TCP timers.
  103. */
  104. #define TCP_TIMER_INIT(tp, timer) \
  105. timeout_set(&(tp)->t_timer[(timer)], tcp_timer_funcs[(timer)], tp)
  106. #define TCP_TIMER_ARM(tp, timer, nticks) \
  107. timeout_add(&(tp)->t_timer[(timer)], (nticks) * (hz / PR_SLOWHZ))
  108. #define TCP_TIMER_DISARM(tp, timer) \
  109. timeout_del(&(tp)->t_timer[(timer)])
  110. #define TCP_TIMER_ISARMED(tp, timer) \
  111. timeout_pending(&(tp)->t_timer[(timer)])
  112. /*
  113. * Force a time value to be in a certain range.
  114. */
  115. #define TCPT_RANGESET(tv, value, tvmin, tvmax) \
  116. do { \
  117. (tv) = (value); \
  118. if ((tv) < (tvmin)) \
  119. (tv) = (tvmin); \
  120. else if ((tv) > (tvmax)) \
  121. (tv) = (tvmax); \
  122. } while (/* CONSTCOND */ 0)
  123. #ifdef _KERNEL
  124. typedef void (*tcp_timer_func_t)(void *);
  125. extern const tcp_timer_func_t tcp_timer_funcs[TCPT_NTIMERS];
  126. extern int tcptv_keep_init;
  127. extern int tcp_always_keepalive; /* assume SO_KEEPALIVE is always set */
  128. extern int tcp_keepidle; /* time before keepalive probes begin */
  129. extern int tcp_keepintvl; /* time between keepalive probes */
  130. extern int tcp_maxidle; /* time to drop after starting probes */
  131. extern int tcp_ttl; /* time to live for TCP segs */
  132. extern int tcp_backoff[];
  133. void tcp_timer_init(void);
  134. #endif /* _KERNEL */
  135. #endif /* _NETINET_TCP_TIMER_H_ */