1c398230bSWarner Losh /*- 251369649SPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause 351369649SPedro F. Giffuni * 4df8bae1dSRodney W. Grimes * Copyright (c) 1982, 1986, 1993 5d22e451dSRobert Watson * The Regents of the University of California. 6d22e451dSRobert Watson * All rights reserved. 7df8bae1dSRodney W. Grimes * 8df8bae1dSRodney W. Grimes * Redistribution and use in source and binary forms, with or without 9df8bae1dSRodney W. Grimes * modification, are permitted provided that the following conditions 10df8bae1dSRodney W. Grimes * are met: 11df8bae1dSRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 12df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer. 13df8bae1dSRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 14df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 15df8bae1dSRodney W. Grimes * documentation and/or other materials provided with the distribution. 16fbbd9655SWarner Losh * 3. Neither the name of the University nor the names of its contributors 17df8bae1dSRodney W. Grimes * may be used to endorse or promote products derived from this software 18df8bae1dSRodney W. Grimes * without specific prior written permission. 19df8bae1dSRodney W. Grimes * 20df8bae1dSRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21df8bae1dSRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22df8bae1dSRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23df8bae1dSRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24df8bae1dSRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25df8bae1dSRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26df8bae1dSRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27df8bae1dSRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28df8bae1dSRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29df8bae1dSRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30df8bae1dSRodney W. Grimes * SUCH DAMAGE. 31df8bae1dSRodney W. Grimes */ 32df8bae1dSRodney W. Grimes 33707f139eSPaul Richards #ifndef _NETINET_TCP_FSM_H_ 34707f139eSPaul Richards #define _NETINET_TCP_FSM_H_ 35707f139eSPaul Richards 36df8bae1dSRodney W. Grimes /* 37df8bae1dSRodney W. Grimes * TCP FSM state definitions. 38d22e451dSRobert Watson * 39df8bae1dSRodney W. Grimes * Per RFC793, September, 1981. 40df8bae1dSRodney W. Grimes */ 41df8bae1dSRodney W. Grimes 42df8bae1dSRodney W. Grimes #define TCP_NSTATES 11 43df8bae1dSRodney W. Grimes 44df8bae1dSRodney W. Grimes #define TCPS_CLOSED 0 /* closed */ 45df8bae1dSRodney W. Grimes #define TCPS_LISTEN 1 /* listening for connection */ 46df8bae1dSRodney W. Grimes #define TCPS_SYN_SENT 2 /* active, have sent syn */ 4798734750SRobert Watson #define TCPS_SYN_RECEIVED 3 /* have sent and received syn */ 48df8bae1dSRodney W. Grimes /* states < TCPS_ESTABLISHED are those where connections not established */ 49df8bae1dSRodney W. Grimes #define TCPS_ESTABLISHED 4 /* established */ 50df8bae1dSRodney W. Grimes #define TCPS_CLOSE_WAIT 5 /* rcvd fin, waiting for close */ 51df8bae1dSRodney W. Grimes /* states > TCPS_CLOSE_WAIT are those where user has closed */ 52df8bae1dSRodney W. Grimes #define TCPS_FIN_WAIT_1 6 /* have closed, sent fin */ 53df8bae1dSRodney W. Grimes #define TCPS_CLOSING 7 /* closed xchd FIN; await FIN ACK */ 54df8bae1dSRodney W. Grimes #define TCPS_LAST_ACK 8 /* had fin and close; await FIN ACK */ 55df8bae1dSRodney W. Grimes /* states > TCPS_CLOSE_WAIT && < TCPS_FIN_WAIT_2 await ACK of FIN */ 56df8bae1dSRodney W. Grimes #define TCPS_FIN_WAIT_2 9 /* have closed, fin is acked */ 57df8bae1dSRodney W. Grimes #define TCPS_TIME_WAIT 10 /* in 2*msl quiet wait after close */ 58df8bae1dSRodney W. Grimes 59df8bae1dSRodney W. Grimes #define TCPS_HAVERCVDSYN(s) ((s) >= TCPS_SYN_RECEIVED) 606a7be6e8SGarrett Wollman #define TCPS_HAVEESTABLISHED(s) ((s) >= TCPS_ESTABLISHED) 61e7106d6bSHiren Panchasara #define TCPS_HAVERCVDFIN(s) \ 62e7106d6bSHiren Panchasara ((s) == TCPS_CLOSE_WAIT || ((s) >= TCPS_CLOSING && (s) != TCPS_FIN_WAIT_2)) 63df8bae1dSRodney W. Grimes 64*a00f4ac2SGleb Smirnoff #ifdef TCPOUTFLAGS 65*a00f4ac2SGleb Smirnoff /* 66*a00f4ac2SGleb Smirnoff * Flags used when sending segments in tcp_output. Basic flags (TH_RST, 67*a00f4ac2SGleb Smirnoff * TH_ACK,TH_SYN,TH_FIN) are totally determined by state, with the proviso 68*a00f4ac2SGleb Smirnoff * that TH_FIN is sent only if all data queued for output is included in the 69*a00f4ac2SGleb Smirnoff * segment. 70*a00f4ac2SGleb Smirnoff */ 71*a00f4ac2SGleb Smirnoff static u_char tcp_outflags[TCP_NSTATES] = { 72*a00f4ac2SGleb Smirnoff TH_RST|TH_ACK, /* 0, CLOSED */ 73*a00f4ac2SGleb Smirnoff 0, /* 1, LISTEN */ 74*a00f4ac2SGleb Smirnoff TH_SYN, /* 2, SYN_SENT */ 75*a00f4ac2SGleb Smirnoff TH_SYN|TH_ACK, /* 3, SYN_RECEIVED */ 76*a00f4ac2SGleb Smirnoff TH_ACK, /* 4, ESTABLISHED */ 77*a00f4ac2SGleb Smirnoff TH_ACK, /* 5, CLOSE_WAIT */ 78*a00f4ac2SGleb Smirnoff TH_FIN|TH_ACK, /* 6, FIN_WAIT_1 */ 79*a00f4ac2SGleb Smirnoff TH_FIN|TH_ACK, /* 7, CLOSING */ 80*a00f4ac2SGleb Smirnoff TH_FIN|TH_ACK, /* 8, LAST_ACK */ 81*a00f4ac2SGleb Smirnoff TH_ACK, /* 9, FIN_WAIT_2 */ 82*a00f4ac2SGleb Smirnoff TH_ACK, /* 10, TIME_WAIT */ 83*a00f4ac2SGleb Smirnoff }; 84*a00f4ac2SGleb Smirnoff #endif 85df8bae1dSRodney W. Grimes 86df8bae1dSRodney W. Grimes #ifdef TCPSTATES 87218cbbeaSDag-Erling Smørgrav static char const * const tcpstates[] = { 88df8bae1dSRodney W. Grimes "CLOSED", "LISTEN", "SYN_SENT", "SYN_RCVD", 89df8bae1dSRodney W. Grimes "ESTABLISHED", "CLOSE_WAIT", "FIN_WAIT_1", "CLOSING", 90df8bae1dSRodney W. Grimes "LAST_ACK", "FIN_WAIT_2", "TIME_WAIT", 91df8bae1dSRodney W. Grimes }; 92df8bae1dSRodney W. Grimes #endif 93707f139eSPaul Richards 94707f139eSPaul Richards #endif 95