TCP finite state machine. More...
#include "core/net.h"
#include "core/ip.h"
#include "core/socket.h"
#include "core/tcp.h"
#include "core/tcp_fsm.h"
#include "core/tcp_misc.h"
#include "core/tcp_timer.h"
#include "ipv4/ipv4.h"
#include "ipv4/ipv4_misc.h"
#include "ipv6/ipv6.h"
#include "mibs/mib2_module.h"
#include "mibs/tcp_mib_module.h"
#include "date_time.h"
#include "debug.h"
Go to the source code of this file.
Macros | |
#define | TRACE_LEVEL TCP_TRACE_LEVEL |
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.
Description
The TCP state machine progresses from one state to another in response to events (user calls, incoming segments and timeouts). This file describes the state transitions caused by incoming segments. Refer to the following RFCs for complete details:
- RFC 793: Transmission Control Protocol
- RFC 1122: Requirements for Internet Hosts - Communication Layers
- Version
- 2.4.4
Definition in file tcp_fsm.c.
Macro Definition Documentation
◆ TRACE_LEVEL
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] interface Underlying network interface [in] pseudoHeader TCP pseudo header [in] buffer Multi-part buffer that holds the incoming TCP segment [in] offset Offset to the first byte of the TCP header [in] ancillary Additional options passed to the stack along with the packet
◆ 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] interface Underlying network interface [in] pseudoHeader TCP pseudo header [in] segment Incoming TCP segment [in] length Length of the segment data
◆ tcpStateCloseWait()
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] socket Handle referencing the current socket [in] segment Incoming TCP segment [in] length Length of the segment data
◆ tcpStateClosing()
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] socket Handle referencing the current socket [in] segment Incoming TCP segment [in] length Length of the segment data
◆ 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] socket Handle referencing the current socket [in] segment Incoming TCP segment [in] buffer Multi-part buffer containing the incoming TCP segment [in] offset Offset to the first data byte [in] length Length of the segment data
◆ 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] socket Handle referencing the current socket [in] segment Incoming TCP segment [in] buffer Multi-part buffer containing the incoming TCP segment [in] offset Offset to the first data byte [in] length Length of the segment data
◆ 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] socket Handle referencing the current socket [in] segment Incoming TCP segment [in] buffer Multi-part buffer containing the incoming TCP segment [in] offset Offset to the first data byte [in] length Length of the segment data
◆ tcpStateLastAck()
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] socket Handle referencing the current socket [in] segment Incoming TCP segment [in] length Length of the segment data
◆ 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] socket Handle referencing the current socket [in] interface Underlying network interface [in] pseudoHeader TCP pseudo header [in] segment Incoming TCP segment [in] length Length of the segment data
◆ 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] socket Handle referencing the current socket [in] segment Incoming TCP segment [in] buffer Multi-part buffer containing the incoming TCP segment [in] offset Offset to the first data byte [in] length Length of the segment data
◆ tcpStateSynSent()
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] socket Handle referencing the current socket [in] segment Incoming TCP segment [in] length Length of the segment data
◆ tcpStateTimeWait()
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] socket Handle referencing the current socket [in] segment Incoming TCP segment [in] length Length of the segment data