xref: /original-bsd/sys/netinet/tcp_fsm.h (revision 2301fdfb)
1 /*
2  * Copyright (c) 1982, 1986 Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that the above copyright notice and this paragraph are
7  * duplicated in all such forms and that any documentation,
8  * advertising materials, and other materials related to such
9  * distribution and use acknowledge that the software was developed
10  * by the University of California, Berkeley.  The name of the
11  * University may not be used to endorse or promote products derived
12  * from this software without specific prior written permission.
13  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16  *
17  *	@(#)tcp_fsm.h	7.3 (Berkeley) 06/29/88
18  */
19 
20 /*
21  * TCP FSM state definitions.
22  * Per RFC793, September, 1981.
23  */
24 
25 #define	TCP_NSTATES	11
26 
27 #define	TCPS_CLOSED		0	/* closed */
28 #define	TCPS_LISTEN		1	/* listening for connection */
29 #define	TCPS_SYN_SENT		2	/* active, have sent syn */
30 #define	TCPS_SYN_RECEIVED	3	/* have send and received syn */
31 /* states < TCPS_ESTABLISHED are those where connections not established */
32 #define	TCPS_ESTABLISHED	4	/* established */
33 #define	TCPS_CLOSE_WAIT		5	/* rcvd fin, waiting for close */
34 /* states > TCPS_CLOSE_WAIT are those where user has closed */
35 #define	TCPS_FIN_WAIT_1		6	/* have closed, sent fin */
36 #define	TCPS_CLOSING		7	/* closed xchd FIN; await FIN ACK */
37 #define	TCPS_LAST_ACK		8	/* had fin and close; await FIN ACK */
38 /* states > TCPS_CLOSE_WAIT && < TCPS_FIN_WAIT_2 await ACK of FIN */
39 #define	TCPS_FIN_WAIT_2		9	/* have closed, fin is acked */
40 #define	TCPS_TIME_WAIT		10	/* in 2*msl quiet wait after close */
41 
42 #define	TCPS_HAVERCVDSYN(s)	((s) >= TCPS_SYN_RECEIVED)
43 #define	TCPS_HAVERCVDFIN(s)	((s) >= TCPS_TIME_WAIT)
44 
45 #ifdef	TCPOUTFLAGS
46 /*
47  * Flags used when sending segments in tcp_output.
48  * Basic flags (TH_RST,TH_ACK,TH_SYN,TH_FIN) are totally
49  * determined by state, with the proviso that TH_FIN is sent only
50  * if all data queued for output is included in the segment.
51  */
52 u_char	tcp_outflags[TCP_NSTATES] = {
53     TH_RST|TH_ACK, 0, TH_SYN, TH_SYN|TH_ACK,
54     TH_ACK, TH_ACK,
55     TH_FIN|TH_ACK, TH_FIN|TH_ACK, TH_FIN|TH_ACK, TH_ACK, TH_ACK,
56 };
57 #endif
58 
59 #ifdef KPROF
60 int	tcp_acounts[TCP_NSTATES][PRU_NREQ];
61 #endif
62 
63 #ifdef	TCPSTATES
64 char *tcpstates[] = {
65 	"CLOSED",	"LISTEN",	"SYN_SENT",	"SYN_RCVD",
66 	"ESTABLISHED",	"CLOSE_WAIT",	"FIN_WAIT_1",	"CLOSING",
67 	"LAST_ACK",	"FIN_WAIT_2",	"TIME_WAIT",
68 };
69 #endif
70