1139823Simp/*-
21541Srgrimes * Copyright (c) 1982, 1986, 1993
3169465Srwatson *	The Regents of the University of California.
4169465Srwatson * All rights reserved.
51541Srgrimes *
61541Srgrimes * Redistribution and use in source and binary forms, with or without
71541Srgrimes * modification, are permitted provided that the following conditions
81541Srgrimes * are met:
91541Srgrimes * 1. Redistributions of source code must retain the above copyright
101541Srgrimes *    notice, this list of conditions and the following disclaimer.
111541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
121541Srgrimes *    notice, this list of conditions and the following disclaimer in the
131541Srgrimes *    documentation and/or other materials provided with the distribution.
141541Srgrimes * 4. Neither the name of the University nor the names of its contributors
151541Srgrimes *    may be used to endorse or promote products derived from this software
161541Srgrimes *    without specific prior written permission.
171541Srgrimes *
181541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
191541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
201541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
211541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
221541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
231541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
241541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
251541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
261541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
271541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
281541Srgrimes * SUCH DAMAGE.
291541Srgrimes *
301541Srgrimes *	@(#)tcp_fsm.h	8.1 (Berkeley) 6/10/93
3150477Speter * $FreeBSD$
321541Srgrimes */
331541Srgrimes
342169Spaul#ifndef _NETINET_TCP_FSM_H_
35169465Srwatson#define	_NETINET_TCP_FSM_H_
362169Spaul
371541Srgrimes/*
381541Srgrimes * TCP FSM state definitions.
39169465Srwatson *
401541Srgrimes * Per RFC793, September, 1981.
411541Srgrimes */
421541Srgrimes
431541Srgrimes#define	TCP_NSTATES	11
441541Srgrimes
451541Srgrimes#define	TCPS_CLOSED		0	/* closed */
461541Srgrimes#define	TCPS_LISTEN		1	/* listening for connection */
471541Srgrimes#define	TCPS_SYN_SENT		2	/* active, have sent syn */
48137971Srwatson#define	TCPS_SYN_RECEIVED	3	/* have sent and received syn */
491541Srgrimes/* states < TCPS_ESTABLISHED are those where connections not established */
501541Srgrimes#define	TCPS_ESTABLISHED	4	/* established */
511541Srgrimes#define	TCPS_CLOSE_WAIT		5	/* rcvd fin, waiting for close */
521541Srgrimes/* states > TCPS_CLOSE_WAIT are those where user has closed */
531541Srgrimes#define	TCPS_FIN_WAIT_1		6	/* have closed, sent fin */
541541Srgrimes#define	TCPS_CLOSING		7	/* closed xchd FIN; await FIN ACK */
551541Srgrimes#define	TCPS_LAST_ACK		8	/* had fin and close; await FIN ACK */
561541Srgrimes/* states > TCPS_CLOSE_WAIT && < TCPS_FIN_WAIT_2 await ACK of FIN */
571541Srgrimes#define	TCPS_FIN_WAIT_2		9	/* have closed, fin is acked */
581541Srgrimes#define	TCPS_TIME_WAIT		10	/* in 2*msl quiet wait after close */
591541Srgrimes
6052904Sshin/* for KAME src sync over BSD*'s */
6152904Sshin#define	TCP6_NSTATES		TCP_NSTATES
6252904Sshin#define	TCP6S_CLOSED		TCPS_CLOSED
6352904Sshin#define	TCP6S_LISTEN		TCPS_LISTEN
6452904Sshin#define	TCP6S_SYN_SENT		TCPS_SYN_SENT
6552904Sshin#define	TCP6S_SYN_RECEIVED	TCPS_SYN_RECEIVED
6652904Sshin#define	TCP6S_ESTABLISHED	TCPS_ESTABLISHED
6752904Sshin#define	TCP6S_CLOSE_WAIT	TCPS_CLOSE_WAIT
6852904Sshin#define	TCP6S_FIN_WAIT_1	TCPS_FIN_WAIT_1
6952904Sshin#define	TCP6S_CLOSING		TCPS_CLOSING
7052904Sshin#define	TCP6S_LAST_ACK		TCPS_LAST_ACK
7152904Sshin#define	TCP6S_FIN_WAIT_2	TCPS_FIN_WAIT_2
7252904Sshin#define	TCP6S_TIME_WAIT		TCPS_TIME_WAIT
7352904Sshin
741541Srgrimes#define	TCPS_HAVERCVDSYN(s)	((s) >= TCPS_SYN_RECEIVED)
7552904Sshin#define	TCPS_HAVEESTABLISHED(s)	((s) >= TCPS_ESTABLISHED)
761541Srgrimes#define	TCPS_HAVERCVDFIN(s)	((s) >= TCPS_TIME_WAIT)
771541Srgrimes
781541Srgrimes#ifdef	TCPOUTFLAGS
791541Srgrimes/*
80169465Srwatson * Flags used when sending segments in tcp_output.  Basic flags (TH_RST,
81169465Srwatson * TH_ACK,TH_SYN,TH_FIN) are totally determined by state, with the proviso
82169465Srwatson * that TH_FIN is sent only if all data queued for output is included in the
83169465Srwatson * segment.
841541Srgrimes */
8512296Sphkstatic u_char	tcp_outflags[TCP_NSTATES] = {
8645439Sjulian	TH_RST|TH_ACK,		/* 0, CLOSED */
8745439Sjulian	0,			/* 1, LISTEN */
8845439Sjulian	TH_SYN,			/* 2, SYN_SENT */
8945439Sjulian	TH_SYN|TH_ACK,		/* 3, SYN_RECEIVED */
9045439Sjulian	TH_ACK,			/* 4, ESTABLISHED */
9145439Sjulian	TH_ACK,			/* 5, CLOSE_WAIT */
9245439Sjulian	TH_FIN|TH_ACK,		/* 6, FIN_WAIT_1 */
9352952Sjlemon	TH_FIN|TH_ACK,		/* 7, CLOSING */
9445439Sjulian	TH_FIN|TH_ACK,		/* 8, LAST_ACK */
9545439Sjulian	TH_ACK,			/* 9, FIN_WAIT_2 */
9645439Sjulian	TH_ACK,			/* 10, TIME_WAIT */
9745439Sjulian};
981541Srgrimes#endif
991541Srgrimes
1001541Srgrimes#ifdef KPROF
1011541Srgrimesint	tcp_acounts[TCP_NSTATES][PRU_NREQ];
1021541Srgrimes#endif
1031541Srgrimes
1041541Srgrimes#ifdef	TCPSTATES
105171656Sdesstatic char const * const tcpstates[] = {
1061541Srgrimes	"CLOSED",	"LISTEN",	"SYN_SENT",	"SYN_RCVD",
1071541Srgrimes	"ESTABLISHED",	"CLOSE_WAIT",	"FIN_WAIT_1",	"CLOSING",
1081541Srgrimes	"LAST_ACK",	"FIN_WAIT_2",	"TIME_WAIT",
1091541Srgrimes};
1101541Srgrimes#endif
1112169Spaul
1122169Spaul#endif
113