tcp_fsm.h revision 45439
11541Srgrimes/* 21541Srgrimes * Copyright (c) 1982, 1986, 1993 31541Srgrimes * The Regents of the University of California. All rights reserved. 41541Srgrimes * 51541Srgrimes * Redistribution and use in source and binary forms, with or without 61541Srgrimes * modification, are permitted provided that the following conditions 71541Srgrimes * are met: 81541Srgrimes * 1. Redistributions of source code must retain the above copyright 91541Srgrimes * notice, this list of conditions and the following disclaimer. 101541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111541Srgrimes * notice, this list of conditions and the following disclaimer in the 121541Srgrimes * documentation and/or other materials provided with the distribution. 131541Srgrimes * 3. All advertising materials mentioning features or use of this software 141541Srgrimes * must display the following acknowledgement: 151541Srgrimes * This product includes software developed by the University of 161541Srgrimes * California, Berkeley and its contributors. 171541Srgrimes * 4. Neither the name of the University nor the names of its contributors 181541Srgrimes * may be used to endorse or promote products derived from this software 191541Srgrimes * without specific prior written permission. 201541Srgrimes * 211541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 221541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 231541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 241541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 251541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 261541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 271541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 281541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 291541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 301541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 311541Srgrimes * SUCH DAMAGE. 321541Srgrimes * 331541Srgrimes * @(#)tcp_fsm.h 8.1 (Berkeley) 6/10/93 3445439Sjulian * $Id: tcp_fsm.h,v 1.10 1997/08/16 19:15:38 wollman Exp $ 351541Srgrimes */ 361541Srgrimes 372169Spaul#ifndef _NETINET_TCP_FSM_H_ 382169Spaul#define _NETINET_TCP_FSM_H_ 392169Spaul 401541Srgrimes/* 411541Srgrimes * TCP FSM state definitions. 421541Srgrimes * Per RFC793, September, 1981. 431541Srgrimes */ 441541Srgrimes 451541Srgrimes#define TCP_NSTATES 11 461541Srgrimes 471541Srgrimes#define TCPS_CLOSED 0 /* closed */ 481541Srgrimes#define TCPS_LISTEN 1 /* listening for connection */ 491541Srgrimes#define TCPS_SYN_SENT 2 /* active, have sent syn */ 501541Srgrimes#define TCPS_SYN_RECEIVED 3 /* have send and received syn */ 511541Srgrimes/* states < TCPS_ESTABLISHED are those where connections not established */ 521541Srgrimes#define TCPS_ESTABLISHED 4 /* established */ 531541Srgrimes#define TCPS_CLOSE_WAIT 5 /* rcvd fin, waiting for close */ 541541Srgrimes/* states > TCPS_CLOSE_WAIT are those where user has closed */ 551541Srgrimes#define TCPS_FIN_WAIT_1 6 /* have closed, sent fin */ 561541Srgrimes#define TCPS_CLOSING 7 /* closed xchd FIN; await FIN ACK */ 571541Srgrimes#define TCPS_LAST_ACK 8 /* had fin and close; await FIN ACK */ 581541Srgrimes/* states > TCPS_CLOSE_WAIT && < TCPS_FIN_WAIT_2 await ACK of FIN */ 591541Srgrimes#define TCPS_FIN_WAIT_2 9 /* have closed, fin is acked */ 601541Srgrimes#define TCPS_TIME_WAIT 10 /* in 2*msl quiet wait after close */ 611541Srgrimes 621541Srgrimes#define TCPS_HAVERCVDSYN(s) ((s) >= TCPS_SYN_RECEIVED) 632304Swollman#define TCPS_HAVEESTABLISHED(s) ((s) >= TCPS_ESTABLISHED) 641541Srgrimes#define TCPS_HAVERCVDFIN(s) ((s) >= TCPS_TIME_WAIT) 651541Srgrimes 661541Srgrimes#ifdef TCPOUTFLAGS 671541Srgrimes/* 681541Srgrimes * Flags used when sending segments in tcp_output. 691541Srgrimes * Basic flags (TH_RST,TH_ACK,TH_SYN,TH_FIN) are totally 701541Srgrimes * determined by state, with the proviso that TH_FIN is sent only 711541Srgrimes * if all data queued for output is included in the segment. 721541Srgrimes */ 7312296Sphkstatic u_char tcp_outflags[TCP_NSTATES] = { 7445439Sjulian TH_RST|TH_ACK, /* 0, CLOSED */ 7545439Sjulian 0, /* 1, LISTEN */ 7645439Sjulian TH_SYN, /* 2, SYN_SENT */ 7745439Sjulian TH_SYN|TH_ACK, /* 3, SYN_RECEIVED */ 7845439Sjulian TH_ACK, /* 4, ESTABLISHED */ 7945439Sjulian TH_ACK, /* 5, CLOSE_WAIT */ 8045439Sjulian TH_FIN|TH_ACK, /* 6, FIN_WAIT_1 */ 8145439Sjulian TH_ACK, /* 7, CLOSING */ 8245439Sjulian TH_FIN|TH_ACK, /* 8, LAST_ACK */ 8345439Sjulian TH_ACK, /* 9, FIN_WAIT_2 */ 8445439Sjulian TH_ACK, /* 10, TIME_WAIT */ 8545439Sjulian}; 861541Srgrimes#endif 871541Srgrimes 881541Srgrimes#ifdef KPROF 891541Srgrimesint tcp_acounts[TCP_NSTATES][PRU_NREQ]; 901541Srgrimes#endif 911541Srgrimes 921541Srgrimes#ifdef TCPSTATES 931541Srgrimeschar *tcpstates[] = { 941541Srgrimes "CLOSED", "LISTEN", "SYN_SENT", "SYN_RCVD", 951541Srgrimes "ESTABLISHED", "CLOSE_WAIT", "FIN_WAIT_1", "CLOSING", 961541Srgrimes "LAST_ACK", "FIN_WAIT_2", "TIME_WAIT", 971541Srgrimes}; 981541Srgrimes#endif 992169Spaul 1002169Spaul#endif 101