tcp_fsm.h File Reference

TCP finite state machine. More...

#include "core/tcp.h"

Go to the source code of this file.

Functions

void tcpProcessSegment (NetInterface *interface, const IpPseudoHeader *pseudoHeader, const NetBuffer *buffer, size_t offset, const NetRxAncillary *ancillary)
 Incoming TCP segment processing. More...
 
void tcpStateClosed (NetInterface *interface, const IpPseudoHeader *pseudoHeader, const TcpHeader *segment, size_t length)
 CLOSED state. More...
 
void tcpStateListen (Socket *socket, NetInterface *interface, const IpPseudoHeader *pseudoHeader, const TcpHeader *segment, size_t length)
 LISTEN state. More...
 
void tcpStateSynSent (Socket *socket, const TcpHeader *segment, size_t length)
 SYN-SENT state. More...
 
void tcpStateSynReceived (Socket *socket, const TcpHeader *segment, const NetBuffer *buffer, size_t offset, size_t length)
 SYN-RECEIVED state. More...
 
void tcpStateEstablished (Socket *socket, const TcpHeader *segment, const NetBuffer *buffer, size_t offset, size_t length)
 ESTABLISHED state. More...
 
void tcpStateCloseWait (Socket *socket, const TcpHeader *segment, size_t length)
 CLOSE-WAIT state. More...
 
void tcpStateLastAck (Socket *socket, const TcpHeader *segment, size_t length)
 LAST-ACK state. More...
 
void tcpStateFinWait1 (Socket *socket, const TcpHeader *segment, const NetBuffer *buffer, size_t offset, size_t length)
 FIN-WAIT-1 state. More...
 
void tcpStateFinWait2 (Socket *socket, const TcpHeader *segment, const NetBuffer *buffer, size_t offset, size_t length)
 FIN-WAIT-2 state. More...
 
void tcpStateClosing (Socket *socket, const TcpHeader *segment, size_t length)
 CLOSING state. More...
 
void tcpStateTimeWait (Socket *socket, const TcpHeader *segment, size_t length)
 TIME-WAIT state. More...
 

Detailed Description

TCP finite state machine.

License

SPDX-License-Identifier: GPL-2.0-or-later

Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.

This file is part of CycloneTCP Open.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
2.4.0

Definition in file tcp_fsm.h.

Function Documentation

◆ tcpProcessSegment()

void tcpProcessSegment ( NetInterface interface,
const IpPseudoHeader pseudoHeader,
const NetBuffer buffer,
size_t  offset,
const NetRxAncillary ancillary 
)

Incoming TCP segment processing.

Parameters
[in]interfaceUnderlying network interface
[in]pseudoHeaderTCP pseudo header
[in]bufferMulti-part buffer that holds the incoming TCP segment
[in]offsetOffset to the first byte of the TCP header
[in]ancillaryAdditional options passed to the stack along with the packet

Definition at line 73 of file tcp_fsm.c.

◆ tcpStateClosed()

void tcpStateClosed ( NetInterface interface,
const IpPseudoHeader pseudoHeader,
const TcpHeader segment,
size_t  length 
)

CLOSED state.

This is the default state that each connection starts in before the process of establishing it begins

Parameters
[in]interfaceUnderlying network interface
[in]pseudoHeaderTCP pseudo header
[in]segmentIncoming TCP segment
[in]lengthLength of the segment data

Definition at line 439 of file tcp_fsm.c.

◆ tcpStateCloseWait()

void tcpStateCloseWait ( Socket socket,
const TcpHeader segment,
size_t  length 
)

CLOSE-WAIT state.

The device has received a close request (FIN) from the other device. It must now wait for the application to acknowledge this request and generate a matching request

Parameters
[in]socketHandle referencing the current socket
[in]segmentIncoming TCP segment
[in]lengthLength of the segment data

Definition at line 986 of file tcp_fsm.c.

◆ tcpStateClosing()

void tcpStateClosing ( Socket socket,
const TcpHeader segment,
size_t  length 
)

CLOSING state.

The device has received a FIN from the other device and sent an ACK for it, but not yet received an ACK for its own FIN message

Parameters
[in]socketHandle referencing the current socket
[in]segmentIncoming TCP segment
[in]lengthLength of the segment data

Definition at line 1254 of file tcp_fsm.c.

◆ tcpStateEstablished()

void tcpStateEstablished ( Socket socket,
const TcpHeader segment,
const NetBuffer buffer,
size_t  offset,
size_t  length 
)

ESTABLISHED state.

Data can be exchanged freely once both devices in the connection enter this state. This will continue until the connection is closed

Parameters
[in]socketHandle referencing the current socket
[in]segmentIncoming TCP segment
[in]bufferMulti-part buffer containing the incoming TCP segment
[in]offsetOffset to the first data byte
[in]lengthLength of the segment data

Definition at line 900 of file tcp_fsm.c.

◆ tcpStateFinWait1()

void tcpStateFinWait1 ( Socket socket,
const TcpHeader segment,
const NetBuffer buffer,
size_t  offset,
size_t  length 
)

FIN-WAIT-1 state.

A device in this state is waiting for an ACK for a FIN it has sent, or is waiting for a connection termination request from the other device

Parameters
[in]socketHandle referencing the current socket
[in]segmentIncoming TCP segment
[in]bufferMulti-part buffer containing the incoming TCP segment
[in]offsetOffset to the first data byte
[in]lengthLength of the segment data

Definition at line 1094 of file tcp_fsm.c.

◆ tcpStateFinWait2()

void tcpStateFinWait2 ( Socket socket,
const TcpHeader segment,
const NetBuffer buffer,
size_t  offset,
size_t  length 
)

FIN-WAIT-2 state.

A device in this state has received an ACK for its request to terminate the connection and is now waiting for a matching FIN from the other device

Parameters
[in]socketHandle referencing the current socket
[in]segmentIncoming TCP segment
[in]bufferMulti-part buffer containing the incoming TCP segment
[in]offsetOffset to the first data byte
[in]lengthLength of the segment data

Definition at line 1185 of file tcp_fsm.c.

◆ tcpStateLastAck()

void tcpStateLastAck ( Socket socket,
const TcpHeader segment,
size_t  length 
)

LAST-ACK state.

A device that has already received a close request and acknowledged it, has sent its own FIN and is waiting for an ACK to this request

Parameters
[in]socketHandle referencing the current socket
[in]segmentIncoming TCP segment
[in]lengthLength of the segment data

Definition at line 1045 of file tcp_fsm.c.

◆ tcpStateListen()

void tcpStateListen ( Socket socket,
NetInterface interface,
const IpPseudoHeader pseudoHeader,
const TcpHeader segment,
size_t  length 
)

LISTEN state.

A device (normally a server) is waiting to receive a synchronize (SYN) message from a client. It has not yet sent its own SYN message

Parameters
[in]socketHandle referencing the current socket
[in]interfaceUnderlying network interface
[in]pseudoHeaderTCP pseudo header
[in]segmentIncoming TCP segment
[in]lengthLength of the segment data

Definition at line 467 of file tcp_fsm.c.

◆ tcpStateSynReceived()

void tcpStateSynReceived ( Socket socket,
const TcpHeader segment,
const NetBuffer buffer,
size_t  offset,
size_t  length 
)

SYN-RECEIVED state.

The device has both received a SYN from its partner and sent its own SYN. It is now waiting for an ACK to its SYN to finish connection setup

Parameters
[in]socketHandle referencing the current socket
[in]segmentIncoming TCP segment
[in]bufferMulti-part buffer containing the incoming TCP segment
[in]offsetOffset to the first data byte
[in]lengthLength of the segment data

Definition at line 798 of file tcp_fsm.c.

◆ tcpStateSynSent()

void tcpStateSynSent ( Socket socket,
const TcpHeader segment,
size_t  length 
)

SYN-SENT state.

The device (normally a client) has sent a synchronize (SYN) message and is waiting for a matching SYN from the other device (usually a server)

Parameters
[in]socketHandle referencing the current socket
[in]segmentIncoming TCP segment
[in]lengthLength of the segment data

Definition at line 652 of file tcp_fsm.c.

◆ tcpStateTimeWait()

void tcpStateTimeWait ( Socket socket,
const TcpHeader segment,
size_t  length 
)

TIME-WAIT state.

The device has now received a FIN from the other device and acknowledged it, and sent its own FIN and received an ACK for it. We are done, except for waiting to ensure the ACK is received and prevent potential overlap with new connections

Parameters
[in]socketHandle referencing the current socket
[in]segmentIncoming TCP segment
[in]lengthLength of the segment data

Definition at line 1307 of file tcp_fsm.c.