1c398230bSWarner Losh /*- 2df8bae1dSRodney W. Grimes * Copyright (c) 1982, 1986, 1993 3d22e451dSRobert Watson * The Regents of the University of California. 4d22e451dSRobert Watson * All rights reserved. 5df8bae1dSRodney W. Grimes * 6df8bae1dSRodney W. Grimes * Redistribution and use in source and binary forms, with or without 7df8bae1dSRodney W. Grimes * modification, are permitted provided that the following conditions 8df8bae1dSRodney W. Grimes * are met: 9df8bae1dSRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 10df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer. 11df8bae1dSRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 12df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 13df8bae1dSRodney W. Grimes * documentation and/or other materials provided with the distribution. 14df8bae1dSRodney W. Grimes * 4. Neither the name of the University nor the names of its contributors 15df8bae1dSRodney W. Grimes * may be used to endorse or promote products derived from this software 16df8bae1dSRodney W. Grimes * without specific prior written permission. 17df8bae1dSRodney W. Grimes * 18df8bae1dSRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19df8bae1dSRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20df8bae1dSRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21df8bae1dSRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22df8bae1dSRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23df8bae1dSRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24df8bae1dSRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25df8bae1dSRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26df8bae1dSRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27df8bae1dSRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28df8bae1dSRodney W. Grimes * SUCH DAMAGE. 29df8bae1dSRodney W. Grimes * 30df8bae1dSRodney W. Grimes * @(#)tcp_fsm.h 8.1 (Berkeley) 6/10/93 31c3aac50fSPeter Wemm * $FreeBSD$ 32df8bae1dSRodney W. Grimes */ 33df8bae1dSRodney W. Grimes 34707f139eSPaul Richards #ifndef _NETINET_TCP_FSM_H_ 35707f139eSPaul Richards #define _NETINET_TCP_FSM_H_ 36707f139eSPaul Richards 37df8bae1dSRodney W. Grimes /* 38df8bae1dSRodney W. Grimes * TCP FSM state definitions. 39d22e451dSRobert Watson * 40df8bae1dSRodney W. Grimes * Per RFC793, September, 1981. 41df8bae1dSRodney W. Grimes */ 42df8bae1dSRodney W. Grimes 43df8bae1dSRodney W. Grimes #define TCP_NSTATES 11 44df8bae1dSRodney W. Grimes 45df8bae1dSRodney W. Grimes #define TCPS_CLOSED 0 /* closed */ 46df8bae1dSRodney W. Grimes #define TCPS_LISTEN 1 /* listening for connection */ 47df8bae1dSRodney W. Grimes #define TCPS_SYN_SENT 2 /* active, have sent syn */ 4898734750SRobert Watson #define TCPS_SYN_RECEIVED 3 /* have sent and received syn */ 49df8bae1dSRodney W. Grimes /* states < TCPS_ESTABLISHED are those where connections not established */ 50df8bae1dSRodney W. Grimes #define TCPS_ESTABLISHED 4 /* established */ 51df8bae1dSRodney W. Grimes #define TCPS_CLOSE_WAIT 5 /* rcvd fin, waiting for close */ 52df8bae1dSRodney W. Grimes /* states > TCPS_CLOSE_WAIT are those where user has closed */ 53df8bae1dSRodney W. Grimes #define TCPS_FIN_WAIT_1 6 /* have closed, sent fin */ 54df8bae1dSRodney W. Grimes #define TCPS_CLOSING 7 /* closed xchd FIN; await FIN ACK */ 55df8bae1dSRodney W. Grimes #define TCPS_LAST_ACK 8 /* had fin and close; await FIN ACK */ 56df8bae1dSRodney W. Grimes /* states > TCPS_CLOSE_WAIT && < TCPS_FIN_WAIT_2 await ACK of FIN */ 57df8bae1dSRodney W. Grimes #define TCPS_FIN_WAIT_2 9 /* have closed, fin is acked */ 58df8bae1dSRodney W. Grimes #define TCPS_TIME_WAIT 10 /* in 2*msl quiet wait after close */ 59df8bae1dSRodney W. Grimes 6076429de4SYoshinobu Inoue /* for KAME src sync over BSD*'s */ 6176429de4SYoshinobu Inoue #define TCP6_NSTATES TCP_NSTATES 6276429de4SYoshinobu Inoue #define TCP6S_CLOSED TCPS_CLOSED 6376429de4SYoshinobu Inoue #define TCP6S_LISTEN TCPS_LISTEN 6476429de4SYoshinobu Inoue #define TCP6S_SYN_SENT TCPS_SYN_SENT 6576429de4SYoshinobu Inoue #define TCP6S_SYN_RECEIVED TCPS_SYN_RECEIVED 6676429de4SYoshinobu Inoue #define TCP6S_ESTABLISHED TCPS_ESTABLISHED 6776429de4SYoshinobu Inoue #define TCP6S_CLOSE_WAIT TCPS_CLOSE_WAIT 6876429de4SYoshinobu Inoue #define TCP6S_FIN_WAIT_1 TCPS_FIN_WAIT_1 6976429de4SYoshinobu Inoue #define TCP6S_CLOSING TCPS_CLOSING 7076429de4SYoshinobu Inoue #define TCP6S_LAST_ACK TCPS_LAST_ACK 7176429de4SYoshinobu Inoue #define TCP6S_FIN_WAIT_2 TCPS_FIN_WAIT_2 7276429de4SYoshinobu Inoue #define TCP6S_TIME_WAIT TCPS_TIME_WAIT 7376429de4SYoshinobu Inoue 74df8bae1dSRodney W. Grimes #define TCPS_HAVERCVDSYN(s) ((s) >= TCPS_SYN_RECEIVED) 756a7be6e8SGarrett Wollman #define TCPS_HAVEESTABLISHED(s) ((s) >= TCPS_ESTABLISHED) 76*e7106d6bSHiren Panchasara #define TCPS_HAVERCVDFIN(s) \ 77*e7106d6bSHiren Panchasara ((s) == TCPS_CLOSE_WAIT || ((s) >= TCPS_CLOSING && (s) != TCPS_FIN_WAIT_2)) 78df8bae1dSRodney W. Grimes 79df8bae1dSRodney W. Grimes #ifdef TCPOUTFLAGS 80df8bae1dSRodney W. Grimes /* 81d22e451dSRobert Watson * Flags used when sending segments in tcp_output. Basic flags (TH_RST, 82d22e451dSRobert Watson * TH_ACK,TH_SYN,TH_FIN) are totally determined by state, with the proviso 83d22e451dSRobert Watson * that TH_FIN is sent only if all data queued for output is included in the 84d22e451dSRobert Watson * segment. 85df8bae1dSRodney W. Grimes */ 860312fbe9SPoul-Henning Kamp static u_char tcp_outflags[TCP_NSTATES] = { 8729089b51SJulian Elischer TH_RST|TH_ACK, /* 0, CLOSED */ 8829089b51SJulian Elischer 0, /* 1, LISTEN */ 8929089b51SJulian Elischer TH_SYN, /* 2, SYN_SENT */ 9029089b51SJulian Elischer TH_SYN|TH_ACK, /* 3, SYN_RECEIVED */ 9129089b51SJulian Elischer TH_ACK, /* 4, ESTABLISHED */ 9229089b51SJulian Elischer TH_ACK, /* 5, CLOSE_WAIT */ 9329089b51SJulian Elischer TH_FIN|TH_ACK, /* 6, FIN_WAIT_1 */ 945dc0f70dSJonathan Lemon TH_FIN|TH_ACK, /* 7, CLOSING */ 9529089b51SJulian Elischer TH_FIN|TH_ACK, /* 8, LAST_ACK */ 9629089b51SJulian Elischer TH_ACK, /* 9, FIN_WAIT_2 */ 9729089b51SJulian Elischer TH_ACK, /* 10, TIME_WAIT */ 98df8bae1dSRodney W. Grimes }; 99df8bae1dSRodney W. Grimes #endif 100df8bae1dSRodney W. Grimes 101df8bae1dSRodney W. Grimes #ifdef KPROF 102df8bae1dSRodney W. Grimes int tcp_acounts[TCP_NSTATES][PRU_NREQ]; 103df8bae1dSRodney W. Grimes #endif 104df8bae1dSRodney W. Grimes 105df8bae1dSRodney W. Grimes #ifdef TCPSTATES 106218cbbeaSDag-Erling Smørgrav static char const * const tcpstates[] = { 107df8bae1dSRodney W. Grimes "CLOSED", "LISTEN", "SYN_SENT", "SYN_RCVD", 108df8bae1dSRodney W. Grimes "ESTABLISHED", "CLOSE_WAIT", "FIN_WAIT_1", "CLOSING", 109df8bae1dSRodney W. Grimes "LAST_ACK", "FIN_WAIT_2", "TIME_WAIT", 110df8bae1dSRodney W. Grimes }; 111df8bae1dSRodney W. Grimes #endif 112707f139eSPaul Richards 113707f139eSPaul Richards #endif 114