xref: /illumos-gate/usr/src/uts/common/netinet/tcp_timer.h (revision 2d6eb4a5e0a47d30189497241345dc5466bb68ab)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * Copyright (c) 1982, 1986 Regents of the University of California.
37c478bd9Sstevel@tonic-gate  * All rights reserved.
4*48bbca81SDaniel Hoffman  * Copyright (c) 2016 by Delphix. All rights reserved.
57c478bd9Sstevel@tonic-gate  *
67c478bd9Sstevel@tonic-gate  * Redistribution and use in source and binary forms are permitted
77c478bd9Sstevel@tonic-gate  * provided that the above copyright notice and this paragraph are
87c478bd9Sstevel@tonic-gate  * duplicated in all such forms and that any documentation,
97c478bd9Sstevel@tonic-gate  * advertising materials, and other materials related to such
107c478bd9Sstevel@tonic-gate  * distribution and use acknowledge that the software was developed
117c478bd9Sstevel@tonic-gate  * by the University of California, Berkeley.  The name of the
127c478bd9Sstevel@tonic-gate  * University may not be used to endorse or promote products derived
137c478bd9Sstevel@tonic-gate  * from this software without specific prior written permission.
147c478bd9Sstevel@tonic-gate  */
157c478bd9Sstevel@tonic-gate 
167c478bd9Sstevel@tonic-gate /*
177c478bd9Sstevel@tonic-gate  * Definitions of the TCP timers.  These timers are counted
187c478bd9Sstevel@tonic-gate  * down PR_SLOWHZ times a second.
197c478bd9Sstevel@tonic-gate  */
207c478bd9Sstevel@tonic-gate 
217c478bd9Sstevel@tonic-gate #ifndef	_NETINET_TCP_TIMER_H
227c478bd9Sstevel@tonic-gate #define	_NETINET_TCP_TIMER_H
237c478bd9Sstevel@tonic-gate 
247c478bd9Sstevel@tonic-gate /* tcp_timer.h 1.13 89/06/16 SMI; from UCB 7.6 6/29/88 */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
277c478bd9Sstevel@tonic-gate extern "C" {
287c478bd9Sstevel@tonic-gate #endif
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #define	TCPT_NTIMERS	4
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #define	TCPT_REXMT	0		/* retransmit */
337c478bd9Sstevel@tonic-gate #define	TCPT_PERSIST	1		/* retransmit persistance */
347c478bd9Sstevel@tonic-gate #define	TCPT_KEEP	2		/* keep alive */
357c478bd9Sstevel@tonic-gate #define	TCPT_2MSL	3		/* 2*msl quiet time timer */
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate /*
387c478bd9Sstevel@tonic-gate  * The TCPT_REXMT timer is used to force retransmissions.
397c478bd9Sstevel@tonic-gate  * The TCP has the TCPT_REXMT timer set whenever segments
407c478bd9Sstevel@tonic-gate  * have been sent for which ACKs are expected but not yet
417c478bd9Sstevel@tonic-gate  * received.  If an ACK is received which advances tp->snd_una,
427c478bd9Sstevel@tonic-gate  * then the retransmit timer is cleared (if there are no more
437c478bd9Sstevel@tonic-gate  * outstanding segments) or reset to the base value (if there
447c478bd9Sstevel@tonic-gate  * are more ACKs expected).  Whenever the retransmit timer goes off,
457c478bd9Sstevel@tonic-gate  * we retransmit one unacknowledged segment, and do a backoff
467c478bd9Sstevel@tonic-gate  * on the retransmit timer.
477c478bd9Sstevel@tonic-gate  *
487c478bd9Sstevel@tonic-gate  * The TCPT_PERSIST timer is used to keep window size information
497c478bd9Sstevel@tonic-gate  * flowing even if the window goes shut.  If all previous transmissions
507c478bd9Sstevel@tonic-gate  * have been acknowledged (so that there are no retransmissions in progress),
517c478bd9Sstevel@tonic-gate  * and the window is too small to bother sending anything, then we start
527c478bd9Sstevel@tonic-gate  * the TCPT_PERSIST timer.  When it expires, if the window is nonzero,
537c478bd9Sstevel@tonic-gate  * we go to transmit state.  Otherwise, at intervals send a single byte
54*48bbca81SDaniel Hoffman  * into the peer's window to force it to update our window information.
557c478bd9Sstevel@tonic-gate  * We do this at most as often as TCPT_PERSMIN time intervals,
567c478bd9Sstevel@tonic-gate  * but no more frequently than the current estimate of round-trip
577c478bd9Sstevel@tonic-gate  * packet time.  The TCPT_PERSIST timer is cleared whenever we receive
587c478bd9Sstevel@tonic-gate  * a window update from the peer.
597c478bd9Sstevel@tonic-gate  *
607c478bd9Sstevel@tonic-gate  * The TCPT_KEEP timer is used to keep connections alive.  If a
617c478bd9Sstevel@tonic-gate  * connection is idle (no segments received) for TCPTV_KEEP_INIT amount of time,
627c478bd9Sstevel@tonic-gate  * but not yet established, then we drop the connection.  Once the connection
637c478bd9Sstevel@tonic-gate  * is established, if the connection is idle for TCPTV_KEEP_IDLE time
647c478bd9Sstevel@tonic-gate  * (and keepalives have been enabled on the socket), we begin to probe
657c478bd9Sstevel@tonic-gate  * the connection.  We force the peer to send us a segment by sending:
667c478bd9Sstevel@tonic-gate  *	<SEQ=SND.UNA-1><ACK=RCV.NXT><CTL=ACK>
677c478bd9Sstevel@tonic-gate  * This segment is (deliberately) outside the window, and should elicit
687c478bd9Sstevel@tonic-gate  * an ack segment in response from the peer.  If, despite the TCPT_KEEP
697c478bd9Sstevel@tonic-gate  * initiated segments we cannot elicit a response from a peer in TCPT_MAXIDLE
707c478bd9Sstevel@tonic-gate  * amount of time probing, then we drop the connection.
717c478bd9Sstevel@tonic-gate  */
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate #define	TCP_TTL		60		/* default time to live for TCP segs */
747c478bd9Sstevel@tonic-gate /*
757c478bd9Sstevel@tonic-gate  * Time constants.
767c478bd9Sstevel@tonic-gate  */
777c478bd9Sstevel@tonic-gate #define	TCPTV_MSL	(30*PR_SLOWHZ)		/* max seg lifetime (hah!) */
787c478bd9Sstevel@tonic-gate #define	TCPTV_SRTTBASE	0			/* base roundtrip time; */
797c478bd9Sstevel@tonic-gate 						/* if 0, no idea yet */
807c478bd9Sstevel@tonic-gate #define	TCPTV_SRTTDFLT	(3*PR_SLOWHZ)		/* assumed RTT if no info */
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate #define	TCPTV_PERSMIN	(5*PR_SLOWHZ)		/* retransmit persistance */
837c478bd9Sstevel@tonic-gate #define	TCPTV_PERSMAX	(60*PR_SLOWHZ)		/* maximum persist interval */
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate #define	TCPTV_KEEP_INIT	(75*PR_SLOWHZ)		/* initial connect keep alive */
867c478bd9Sstevel@tonic-gate #define	TCPTV_KEEP_IDLE	(120*60*PR_SLOWHZ)	/* dflt time before probing */
877c478bd9Sstevel@tonic-gate #define	TCPTV_KEEPINTVL	(75*PR_SLOWHZ)		/* default probe interval */
887c478bd9Sstevel@tonic-gate #define	TCPTV_KEEPCNT	8			/* max probes before drop */
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate #define	TCPTV_MIN	(1*PR_SLOWHZ)		/* minimum allowable value */
917c478bd9Sstevel@tonic-gate #define	TCPTV_REXMTMAX	(64*PR_SLOWHZ)		/* max allowable REXMT value */
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate #define	TCP_LINGERTIME	120			/* linger at most 2 minutes */
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate #define	TCP_MAXRXTSHIFT	12			/* maximum retransmits */
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate #ifdef	TCPTIMERS
987c478bd9Sstevel@tonic-gate char *tcptimers[] =
997c478bd9Sstevel@tonic-gate 	{ "REXMT", "PERSIST", "KEEP", "2MSL" };
1007c478bd9Sstevel@tonic-gate #endif
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate /*
1037c478bd9Sstevel@tonic-gate  * Force a time value to be in a certain range.
1047c478bd9Sstevel@tonic-gate  */
1057c478bd9Sstevel@tonic-gate #define	TCPT_RANGESET(tv, value, tvmin, tvmax) { \
1067c478bd9Sstevel@tonic-gate 	(tv) = (value); \
1077c478bd9Sstevel@tonic-gate 	if ((tv) < (tvmin)) \
1087c478bd9Sstevel@tonic-gate 		(tv) = (tvmin); \
1097c478bd9Sstevel@tonic-gate 	else if ((tv) > (tvmax)) \
1107c478bd9Sstevel@tonic-gate 		(tv) = (tvmax); \
1117c478bd9Sstevel@tonic-gate }
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1147c478bd9Sstevel@tonic-gate }
1157c478bd9Sstevel@tonic-gate #endif
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate #endif	/* _NETINET_TCP_TIMER_H */
118