Helper functions for TCP. More...
#include "core/net.h"
#include "core/socket.h"
#include "core/tcp.h"
#include "core/tcp_misc.h"
#include "core/tcp_timer.h"
#include "core/ip.h"
#include "ipv4/ipv4.h"
#include "ipv6/ipv6.h"
#include "mibs/mib2_module.h"
#include "mibs/tcp_mib_module.h"
#include "date_time.h"
#include "debug.h"
#include "hash/md5.h"
Go to the source code of this file.
Macros | |
#define | TRACE_LEVEL TCP_TRACE_LEVEL |
Functions | |
error_t | tcpSendSegment (Socket *socket, uint8_t flags, uint32_t seqNum, uint32_t ackNum, size_t length, bool_t addToQueue) |
Send a TCP segment. More... | |
error_t | tcpSendResetSegment (Socket *socket, uint32_t seqNum) |
Send a TCP reset segment. More... | |
error_t | tcpRejectSegment (NetInterface *interface, const IpPseudoHeader *pseudoHeader, const TcpHeader *segment, size_t length) |
Send a TCP reset in response to an invalid segment. More... | |
error_t | tcpAddOption (TcpHeader *segment, uint8_t kind, const void *value, uint8_t length) |
Append an option to the TCP header. More... | |
const TcpOption * | tcpGetOption (const TcpHeader *segment, uint8_t kind) |
Search the TCP header for a given option. More... | |
uint32_t | tcpGenerateInitialSeqNum (const IpAddr *localIpAddr, uint16_t localPort, const IpAddr *remoteIpAddr, uint16_t remotePort) |
Initial sequence number generation. More... | |
error_t | tcpCheckSeqNum (Socket *socket, const TcpHeader *segment, size_t length) |
Test the sequence number of an incoming segment. More... | |
error_t | tcpCheckSyn (Socket *socket, const TcpHeader *segment, size_t length) |
Check the SYN bit of an incoming segment. More... | |
error_t | tcpCheckAck (Socket *socket, const TcpHeader *segment, size_t length) |
Test the ACK field of an incoming segment. More... | |
bool_t | tcpIsDuplicateSyn (Socket *socket, const IpPseudoHeader *pseudoHeader, const TcpHeader *segment) |
Test whether the incoming SYN segment is a duplicate. More... | |
bool_t | tcpIsDuplicateAck (Socket *socket, const TcpHeader *segment, size_t length) |
Test whether the incoming acknowledgment is a duplicate. More... | |
void | tcpFastRetransmit (Socket *socket) |
Fast retransmit procedure. More... | |
void | tcpFastRecovery (Socket *socket, const TcpHeader *segment, uint_t n) |
Fast recovery procedure. More... | |
void | tcpFastLossRecovery (Socket *socket, const TcpHeader *segment) |
Fast loss recovery procedure. More... | |
void | tcpProcessSegmentData (Socket *socket, const TcpHeader *segment, const NetBuffer *buffer, size_t offset, size_t length) |
Process the segment text. More... | |
void | tcpDeleteControlBlock (Socket *socket) |
Delete TCB structure. More... | |
void | tcpUpdateRetransmitQueue (Socket *socket) |
Remove acknowledged segments from retransmission queue. More... | |
void | tcpFlushRetransmitQueue (Socket *socket) |
Flush retransmission queue. More... | |
void | tcpFlushSynQueue (Socket *socket) |
Flush SYN queue. More... | |
void | tcpUpdateSackBlocks (Socket *socket, uint32_t *leftEdge, uint32_t *rightEdge) |
Update the list of non-contiguous blocks that have been received. More... | |
void | tcpUpdateSendWindow (Socket *socket, const TcpHeader *segment) |
Update send window. More... | |
void | tcpUpdateReceiveWindow (Socket *socket) |
Update receive window so as to avoid Silly Window Syndrome. More... | |
bool_t | tcpComputeRto (Socket *socket) |
Compute retransmission timeout. More... | |
error_t | tcpRetransmitSegment (Socket *socket) |
TCP segment retransmission. More... | |
error_t | tcpNagleAlgo (Socket *socket, uint_t flags) |
Nagle algorithm implementation. More... | |
void | tcpChangeState (Socket *socket, TcpState newState) |
Update TCP FSM current state. More... | |
void | tcpUpdateEvents (Socket *socket) |
Update TCP related events. More... | |
uint_t | tcpWaitForEvents (Socket *socket, uint_t eventMask, systime_t timeout) |
Wait for a particular TCP event. More... | |
void | tcpWriteTxBuffer (Socket *socket, uint32_t seqNum, const uint8_t *data, size_t length) |
Copy incoming data to the send buffer. More... | |
error_t | tcpReadTxBuffer (Socket *socket, uint32_t seqNum, NetBuffer *buffer, size_t length) |
Copy data from the send buffer. More... | |
void | tcpWriteRxBuffer (Socket *socket, uint32_t seqNum, const NetBuffer *data, size_t dataOffset, size_t length) |
Copy incoming data to the receive buffer. More... | |
void | tcpReadRxBuffer (Socket *socket, uint32_t seqNum, uint8_t *data, size_t length) |
Copy data from the receive buffer. More... | |
void | tcpDumpHeader (const TcpHeader *segment, size_t length, uint32_t iss, uint32_t irs) |
Dump TCP header for debugging purpose. More... | |
Detailed Description
Helper functions for TCP.
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.
- Version
- 2.4.4
Definition in file tcp_misc.c.
Macro Definition Documentation
◆ TRACE_LEVEL
#define TRACE_LEVEL TCP_TRACE_LEVEL |
Definition at line 32 of file tcp_misc.c.
Function Documentation
◆ tcpAddOption()
Append an option to the TCP header.
- Parameters
-
[in] segment Pointer to the TCP header [in] kind Option code [in] value Option value [in] length Length of the option value, in bytes
- Returns
- Error code
Definition at line 554 of file tcp_misc.c.
◆ tcpChangeState()
Update TCP FSM current state.
- Parameters
-
[in] socket Handle referencing the socket [in] newState New TCP state to switch to
Definition at line 2021 of file tcp_misc.c.
◆ tcpCheckAck()
Test the ACK field of an incoming segment.
- Parameters
-
[in] socket Handle referencing the current socket [in] segment Pointer to the TCP segment to check [in] length Length of the segment data
- Returns
- NO_ERROR if the acknowledgment is acceptable, ERROR_FAILURE otherwise
Definition at line 844 of file tcp_misc.c.
◆ tcpCheckSeqNum()
Test the sequence number of an incoming segment.
- Parameters
-
[in] socket Handle referencing the current socket [in] segment Pointer to the TCP segment to check [in] length Length of the segment data
- Returns
- NO_ERROR if the incoming segment is acceptable, ERROR_FAILURE otherwise
Definition at line 719 of file tcp_misc.c.
◆ tcpCheckSyn()
Check the SYN bit of an incoming segment.
- Parameters
-
[in] socket Handle referencing the current socket [in] segment Pointer to the TCP segment to check [in] length Length of the segment data
- Returns
- ERROR_FAILURE if the SYN is in the window, NO_ERROR otherwise
Definition at line 810 of file tcp_misc.c.
◆ tcpComputeRto()
Compute retransmission timeout.
- Parameters
-
[in] socket Handle referencing the socket
- Returns
- TRUE if the RTT measurement is complete, else FALSE
Definition at line 1675 of file tcp_misc.c.
◆ tcpDeleteControlBlock()
void tcpDeleteControlBlock | ( | Socket * | socket | ) |
Delete TCB structure.
- Parameters
-
[in] socket Handle referencing the socket
Definition at line 1371 of file tcp_misc.c.
◆ tcpDumpHeader()
void tcpDumpHeader | ( | const TcpHeader * | segment, |
size_t | length, | ||
uint32_t | iss, | ||
uint32_t | irs | ||
) |
Dump TCP header for debugging purpose.
- Parameters
-
[in] segment Pointer to the TCP header [in] length Length of the segment data [in] iss Initial send sequence number (needed to compute relative SEQ number) [in] irs Initial receive sequence number (needed to compute relative ACK number)
Definition at line 2388 of file tcp_misc.c.
◆ tcpFastLossRecovery()
Fast loss recovery procedure.
- Parameters
-
[in] socket Handle referencing the current socket [in] segment Pointer to the incoming TCP segment
Definition at line 1265 of file tcp_misc.c.
◆ tcpFastRecovery()
Fast recovery procedure.
- Parameters
-
[in] socket Handle referencing the current socket [in] segment Pointer to the incoming TCP segment [in] n Number of bytes acknowledged by the incoming ACK
Definition at line 1216 of file tcp_misc.c.
◆ tcpFastRetransmit()
void tcpFastRetransmit | ( | Socket * | socket | ) |
Fast retransmit procedure.
- Parameters
-
[in] socket Handle referencing the current socket
Definition at line 1177 of file tcp_misc.c.
◆ tcpFlushRetransmitQueue()
void tcpFlushRetransmitQueue | ( | Socket * | socket | ) |
Flush retransmission queue.
- Parameters
-
[in] socket Handle referencing the socket
Definition at line 1474 of file tcp_misc.c.
◆ tcpFlushSynQueue()
void tcpFlushSynQueue | ( | Socket * | socket | ) |
Flush SYN queue.
- Parameters
-
[in] socket Handle referencing the socket
Definition at line 1503 of file tcp_misc.c.
◆ tcpGenerateInitialSeqNum()
uint32_t tcpGenerateInitialSeqNum | ( | const IpAddr * | localIpAddr, |
uint16_t | localPort, | ||
const IpAddr * | remoteIpAddr, | ||
uint16_t | remotePort | ||
) |
Initial sequence number generation.
- Parameters
-
[in] localIpAddr Local IP address [in] localPort Local port [in] remoteIpAddr Remote IP address [in] remotePort Remote port
- Returns
- Value of the initial sequence number
Definition at line 683 of file tcp_misc.c.
◆ tcpGetOption()
Search the TCP header for a given option.
- Parameters
-
[in] segment Pointer to the TCP header [in] kind Code of the option to find
- Returns
- If the specified option is found, a pointer to the corresponding option is returned. Otherwise NULL pointer is returned
Definition at line 617 of file tcp_misc.c.
◆ tcpIsDuplicateAck()
Test whether the incoming acknowledgment is a duplicate.
- Parameters
-
[in] socket Handle referencing the current socket [in] segment Pointer to the TCP segment to check [in] length Length of the segment data
- Returns
- TRUE if the ACK is duplicate, else FALSE
Definition at line 1134 of file tcp_misc.c.
◆ tcpIsDuplicateSyn()
bool_t tcpIsDuplicateSyn | ( | Socket * | socket, |
const IpPseudoHeader * | pseudoHeader, | ||
const TcpHeader * | segment | ||
) |
Test whether the incoming SYN segment is a duplicate.
- Parameters
-
[in] socket Handle referencing the current socket [in] pseudoHeader TCP pseudo header [in] segment Pointer to the TCP segment to check
- Returns
- TRUE if the SYN segment is duplicate, else FALSE
Definition at line 1058 of file tcp_misc.c.
◆ tcpNagleAlgo()
Nagle algorithm implementation.
- Parameters
-
[in] socket Handle referencing the socket [in] flags Set of flags that influences the behavior of this function
- Returns
- Error code
Definition at line 1900 of file tcp_misc.c.
◆ tcpProcessSegmentData()
void tcpProcessSegmentData | ( | Socket * | socket, |
const TcpHeader * | segment, | ||
const NetBuffer * | buffer, | ||
size_t | offset, | ||
size_t | length | ||
) |
Process the segment text.
- Parameters
-
[in] socket Handle referencing the current socket [in] segment Pointer to the TCP header [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
Definition at line 1303 of file tcp_misc.c.
◆ tcpReadRxBuffer()
void tcpReadRxBuffer | ( | Socket * | socket, |
uint32_t | seqNum, | ||
uint8_t * | data, | ||
size_t | length | ||
) |
Copy data from the receive buffer.
- Parameters
-
[in] socket Handle referencing the socket [in] seqNum Sequence number of the first data to read [out] data Pointer to the output buffer [in] length Number of data to read
Definition at line 2353 of file tcp_misc.c.
◆ tcpReadTxBuffer()
Copy data from the send buffer.
- Parameters
-
[in] socket Handle referencing the socket [in] seqNum Sequence number of the first data to read [out] buffer Pointer to the output buffer [in] length Number of data to read
- Returns
- Error code
Definition at line 2274 of file tcp_misc.c.
◆ tcpRejectSegment()
error_t tcpRejectSegment | ( | NetInterface * | interface, |
const IpPseudoHeader * | pseudoHeader, | ||
const TcpHeader * | segment, | ||
size_t | length | ||
) |
Send a TCP reset in response to an invalid segment.
- Parameters
-
[in] interface Underlying network interface [in] pseudoHeader TCP pseudo header describing the incoming segment [in] segment Incoming TCP segment [in] length Length of the incoming segment data
- Returns
- Error code
Definition at line 404 of file tcp_misc.c.
◆ tcpRetransmitSegment()
TCP segment retransmission.
- Parameters
-
[in] socket Handle referencing the socket
- Returns
- Error code
Definition at line 1744 of file tcp_misc.c.
◆ tcpSendResetSegment()
Send a TCP reset segment.
- Parameters
-
[in] socket Handle referencing a socket [in] seqNum Sequence number
- Returns
- Error code
Definition at line 371 of file tcp_misc.c.
◆ tcpSendSegment()
error_t tcpSendSegment | ( | Socket * | socket, |
uint8_t | flags, | ||
uint32_t | seqNum, | ||
uint32_t | ackNum, | ||
size_t | length, | ||
bool_t | addToQueue | ||
) |
Send a TCP segment.
- Parameters
-
[in] socket Handle referencing a socket [in] flags Value that contains bitwise OR of flags (see TcpFlags enumeration) [in] seqNum Sequence number [in] ackNum Acknowledgment number [in] length Length of the segment data [in] addToQueue Add the segment to retransmission queue
- Returns
- Error code
Definition at line 68 of file tcp_misc.c.
◆ tcpUpdateEvents()
void tcpUpdateEvents | ( | Socket * | socket | ) |
Update TCP related events.
- Parameters
-
[in] socket Handle referencing the socket
Definition at line 2052 of file tcp_misc.c.
◆ tcpUpdateReceiveWindow()
void tcpUpdateReceiveWindow | ( | Socket * | socket | ) |
Update receive window so as to avoid Silly Window Syndrome.
- Parameters
-
[in] socket Handle referencing the socket
Definition at line 1636 of file tcp_misc.c.
◆ tcpUpdateRetransmitQueue()
void tcpUpdateRetransmitQueue | ( | Socket * | socket | ) |
Remove acknowledged segments from retransmission queue.
- Parameters
-
[in] socket Handle referencing the socket
Definition at line 1392 of file tcp_misc.c.
◆ tcpUpdateSackBlocks()
void tcpUpdateSackBlocks | ( | Socket * | socket, |
uint32_t * | leftEdge, | ||
uint32_t * | rightEdge | ||
) |
Update the list of non-contiguous blocks that have been received.
- Parameters
-
[in] socket Handle referencing the socket [in,out] leftEdge First sequence number occupied by the incoming data [in,out] rightEdge Sequence number immediately following the incoming data
Definition at line 1531 of file tcp_misc.c.
◆ tcpUpdateSendWindow()
Update send window.
- Parameters
-
[in] socket Handle referencing the socket [in] segment Pointer to the incoming TCP segment
Definition at line 1586 of file tcp_misc.c.
◆ tcpWaitForEvents()
Wait for a particular TCP event.
- Parameters
-
[in] socket Handle referencing the socket [in] eventMask Logic OR of all the TCP events that will complete the wait [in] timeout Maximum time to wait
- Returns
- Logic OR of all the TCP events that satisfied the wait
Definition at line 2200 of file tcp_misc.c.
◆ tcpWriteRxBuffer()
void tcpWriteRxBuffer | ( | Socket * | socket, |
uint32_t | seqNum, | ||
const NetBuffer * | data, | ||
size_t | dataOffset, | ||
size_t | length | ||
) |
Copy incoming data to the receive buffer.
- Parameters
-
[in] socket Handle referencing the socket [in] seqNum First sequence number occupied by the incoming data [in] data Multi-part buffer containing the incoming data [in] dataOffset Offset to the first data byte [in] length Number of data to write
Definition at line 2318 of file tcp_misc.c.
◆ tcpWriteTxBuffer()
void tcpWriteTxBuffer | ( | Socket * | socket, |
uint32_t | seqNum, | ||
const uint8_t * | data, | ||
size_t | length | ||
) |
Copy incoming data to the send buffer.
- Parameters
-
[in] socket Handle referencing the socket [in] seqNum First sequence number occupied by the incoming data [in] data Data to write [in] length Number of data to write
Definition at line 2238 of file tcp_misc.c.