xref: /csrg-svn/sys/netinet/tcp_fsm.h (revision 63218)
123189Smckusick /*
2*63218Sbostic  * Copyright (c) 1982, 1986, 1993
3*63218Sbostic  *	The Regents of the University of California.  All rights reserved.
423189Smckusick  *
544484Sbostic  * %sccs.include.redist.c%
632787Sbostic  *
7*63218Sbostic  *	@(#)tcp_fsm.h	8.1 (Berkeley) 06/10/93
823189Smckusick  */
94725Swnj 
104725Swnj /*
114924Swnj  * TCP FSM state definitions.
125065Swnj  * Per RFC793, September, 1981.
134725Swnj  */
144725Swnj 
155065Swnj #define	TCP_NSTATES	11
164725Swnj 
175065Swnj #define	TCPS_CLOSED		0	/* closed */
185065Swnj #define	TCPS_LISTEN		1	/* listening for connection */
195065Swnj #define	TCPS_SYN_SENT		2	/* active, have sent syn */
205085Swnj #define	TCPS_SYN_RECEIVED	3	/* have send and received syn */
215074Swnj /* states < TCPS_ESTABLISHED are those where connections not established */
225065Swnj #define	TCPS_ESTABLISHED	4	/* established */
235085Swnj #define	TCPS_CLOSE_WAIT		5	/* rcvd fin, waiting for close */
245074Swnj /* states > TCPS_CLOSE_WAIT are those where user has closed */
255085Swnj #define	TCPS_FIN_WAIT_1		6	/* have closed, sent fin */
265085Swnj #define	TCPS_CLOSING		7	/* closed xchd FIN; await FIN ACK */
275085Swnj #define	TCPS_LAST_ACK		8	/* had fin and close; await FIN ACK */
285085Swnj /* states > TCPS_CLOSE_WAIT && < TCPS_FIN_WAIT_2 await ACK of FIN */
295085Swnj #define	TCPS_FIN_WAIT_2		9	/* have closed, fin is acked */
305085Swnj #define	TCPS_TIME_WAIT		10	/* in 2*msl quiet wait after close */
314725Swnj 
325085Swnj #define	TCPS_HAVERCVDSYN(s)	((s) >= TCPS_SYN_RECEIVED)
335065Swnj #define	TCPS_HAVERCVDFIN(s)	((s) >= TCPS_TIME_WAIT)
345065Swnj 
355085Swnj #ifdef	TCPOUTFLAGS
365085Swnj /*
375085Swnj  * Flags used when sending segments in tcp_output.
385085Swnj  * Basic flags (TH_RST,TH_ACK,TH_SYN,TH_FIN) are totally
395173Swnj  * determined by state, with the proviso that TH_FIN is sent only
405173Swnj  * if all data queued for output is included in the segment.
415085Swnj  */
425085Swnj u_char	tcp_outflags[TCP_NSTATES] = {
435085Swnj     TH_RST|TH_ACK, 0, TH_SYN, TH_SYN|TH_ACK,
445085Swnj     TH_ACK, TH_ACK,
455244Sroot     TH_FIN|TH_ACK, TH_FIN|TH_ACK, TH_FIN|TH_ACK, TH_ACK, TH_ACK,
465085Swnj };
475085Swnj #endif
485085Swnj 
494730Swnj #ifdef KPROF
504899Swnj int	tcp_acounts[TCP_NSTATES][PRU_NREQ];
514725Swnj #endif
524725Swnj 
535085Swnj #ifdef	TCPSTATES
544725Swnj char *tcpstates[] = {
555065Swnj 	"CLOSED",	"LISTEN",	"SYN_SENT",	"SYN_RCVD",
565244Sroot 	"ESTABLISHED",	"CLOSE_WAIT",	"FIN_WAIT_1",	"CLOSING",
575244Sroot 	"LAST_ACK",	"FIN_WAIT_2",	"TIME_WAIT",
584725Swnj };
594725Swnj #endif
60