xref: /csrg-svn/sys/netinet/tcp_timer.h (revision 44490)
123195Smckusick /*
229154Smckusick  * Copyright (c) 1982, 1986 Regents of the University of California.
332789Sbostic  * All rights reserved.
423195Smckusick  *
5*44490Sbostic  * %sccs.include.redist.c%
632789Sbostic  *
7*44490Sbostic  *	@(#)tcp_timer.h	7.8 (Berkeley) 06/28/90
823195Smckusick  */
95125Swnj 
105125Swnj /*
115125Swnj  * Definitions of the TCP timers.  These timers are counted
125125Swnj  * down PR_SLOWHZ times a second.
135125Swnj  */
149860Ssam #define	TCPT_NTIMERS	4
155125Swnj 
165125Swnj #define	TCPT_REXMT	0		/* retransmit */
175165Swnj #define	TCPT_PERSIST	1		/* retransmit persistance */
185165Swnj #define	TCPT_KEEP	2		/* keep alive */
195165Swnj #define	TCPT_2MSL	3		/* 2*msl quiet time timer */
205125Swnj 
215165Swnj /*
225165Swnj  * The TCPT_REXMT timer is used to force retransmissions.
235165Swnj  * The TCP has the TCPT_REXMT timer set whenever segments
245165Swnj  * have been sent for which ACKs are expected but not yet
255165Swnj  * received.  If an ACK is received which advances tp->snd_una,
265165Swnj  * then the retransmit timer is cleared (if there are no more
275165Swnj  * outstanding segments) or reset to the base value (if there
285165Swnj  * are more ACKs expected).  Whenever the retransmit timer goes off,
2924820Skarels  * we retransmit one unacknowledged segment, and do a backoff
3024820Skarels  * on the retransmit timer.
315165Swnj  *
325165Swnj  * The TCPT_PERSIST timer is used to keep window size information
337041Swnj  * flowing even if the window goes shut.  If all previous transmissions
347041Swnj  * have been acknowledged (so that there are no retransmissions in progress),
3524820Skarels  * and the window is too small to bother sending anything, then we start
3624820Skarels  * the TCPT_PERSIST timer.  When it expires, if the window is nonzero,
3724820Skarels  * we go to transmit state.  Otherwise, at intervals send a single byte
3824820Skarels  * into the peer's window to force him to update our window information.
3924820Skarels  * We do this at most as often as TCPT_PERSMIN time intervals,
4024820Skarels  * but no more frequently than the current estimate of round-trip
4124820Skarels  * packet time.  The TCPT_PERSIST timer is cleared whenever we receive
4224820Skarels  * a window update from the peer.
435165Swnj  *
445165Swnj  * The TCPT_KEEP timer is used to keep connections alive.  If an
4533747Skarels  * connection is idle (no segments received) for TCPTV_KEEP_INIT amount of time,
4633747Skarels  * but not yet established, then we drop the connection.  Once the connection
4733747Skarels  * is established, if the connection is idle for TCPTV_KEEP_IDLE time
4833747Skarels  * (and keepalives have been enabled on the socket), we begin to probe
4933747Skarels  * the connection.  We force the peer to send us a segment by sending:
505165Swnj  *	<SEQ=SND.UNA-1><ACK=RCV.NXT><CTL=ACK>
515165Swnj  * This segment is (deliberately) outside the window, and should elicit
525165Swnj  * an ack segment in response from the peer.  If, despite the TCPT_KEEP
535165Swnj  * initiated segments we cannot elicit a response from a peer in TCPT_MAXIDLE
5433747Skarels  * amount of time probing, then we drop the connection.
555165Swnj  */
565165Swnj 
5740686Skarels #define	TCP_TTL		60		/* default time to live for TCP segs */
585125Swnj /*
595165Swnj  * Time constants.
605125Swnj  */
6133747Skarels #define	TCPTV_MSL	( 30*PR_SLOWHZ)		/* max seg lifetime (hah!) */
6218647Skarels #define	TCPTV_SRTTBASE	0			/* base roundtrip time;
6318647Skarels 						   if 0, no idea yet */
6426990Skarels #define	TCPTV_SRTTDFLT	(  3*PR_SLOWHZ)		/* assumed RTT if no info */
6525889Skarels 
665165Swnj #define	TCPTV_PERSMIN	(  5*PR_SLOWHZ)		/* retransmit persistance */
6731726Skarels #define	TCPTV_PERSMAX	( 60*PR_SLOWHZ)		/* maximum persist interval */
685125Swnj 
6933747Skarels #define	TCPTV_KEEP_INIT	( 75*PR_SLOWHZ)		/* initial connect keep alive */
7033747Skarels #define	TCPTV_KEEP_IDLE	(120*60*PR_SLOWHZ)	/* dflt time before probing */
7133747Skarels #define	TCPTV_KEEPINTVL	( 75*PR_SLOWHZ)		/* default probe interval */
7233747Skarels #define	TCPTV_KEEPCNT	8			/* max probes before drop */
735125Swnj 
745165Swnj #define	TCPTV_MIN	(  1*PR_SLOWHZ)		/* minimum allowable value */
7531726Skarels #define	TCPTV_REXMTMAX	( 64*PR_SLOWHZ)		/* max allowable REXMT value */
765125Swnj 
775392Swnj #define	TCP_LINGERTIME	120			/* linger at most 2 minutes */
785392Swnj 
7924820Skarels #define	TCP_MAXRXTSHIFT	12			/* maximum retransmits */
805691Swnj 
815125Swnj #ifdef	TCPTIMERS
825125Swnj char *tcptimers[] =
839860Ssam     { "REXMT", "PERSIST", "KEEP", "2MSL" };
845125Swnj #endif
855165Swnj 
865165Swnj /*
875165Swnj  * Force a time value to be in a certain range.
885165Swnj  */
895245Sroot #define	TCPT_RANGESET(tv, value, tvmin, tvmax) { \
905165Swnj 	(tv) = (value); \
915165Swnj 	if ((tv) < (tvmin)) \
925165Swnj 		(tv) = (tvmin); \
9331726Skarels 	else if ((tv) > (tvmax)) \
945245Sroot 		(tv) = (tvmax); \
955245Sroot }
9631726Skarels 
9731726Skarels #ifdef KERNEL
9833747Skarels extern int tcp_keepidle;		/* time before keepalive probes begin */
9933747Skarels extern int tcp_keepintvl;		/* time between keepalive probes */
10033747Skarels extern int tcp_maxidle;			/* time to drop after starting probes */
10133747Skarels extern int tcp_ttl;			/* time to live for TCP segs */
10231726Skarels extern int tcp_backoff[];
10331726Skarels #endif
104