TianoCore EDK2 master
Loading...
Searching...
No Matches
TcpMisc.c File Reference
#include "TcpMain.h"

Go to the source code of this file.

Data Structures

union  NETWORK_ADDRESS
 
struct  ISN_HASH_CTX
 

Functions

EFI_STATUS TcpInitTcbLocal (IN OUT TCP_CB *Tcb)
 
VOID TcpInitTcbPeer (IN OUT TCP_CB *Tcb, IN TCP_SEG *Seg, IN TCP_OPTION *Opt)
 
BOOLEAN TcpIsIpEqual (IN EFI_IP_ADDRESS *Ip1, IN EFI_IP_ADDRESS *Ip2, IN UINT8 Version)
 
BOOLEAN TcpIsIpZero (IN EFI_IP_ADDRESS *Ip, IN UINT8 Version)
 
TCP_CBTcpLocateListenTcb (IN TCP_PEER *Local, IN TCP_PEER *Remote, IN UINT8 Version)
 
BOOLEAN TcpFindTcbByPeer (IN EFI_IP_ADDRESS *Addr, IN TCP_PORTNO Port, IN UINT8 Version)
 
TCP_CBTcpLocateTcb (IN TCP_PORTNO LocalPort, IN EFI_IP_ADDRESS *LocalIp, IN TCP_PORTNO RemotePort, IN EFI_IP_ADDRESS *RemoteIp, IN UINT8 Version, IN BOOLEAN Syn)
 
INTN TcpInsertTcb (IN TCP_CB *Tcb)
 
TCP_CBTcpCloneTcb (IN TCP_CB *Tcb)
 
EFI_STATUS TcpGetIsn (IN UINT8 *LocalIp, IN UINTN LocalIpSize, IN UINT16 LocalPort, IN UINT8 *RemoteIp, IN UINTN RemoteIpSize, IN UINT16 RemotePort, OUT TCP_SEQNO *Isn)
 
UINT16 TcpGetRcvMss (IN SOCKET *Sock)
 
VOID TcpSetState (IN TCP_CB *Tcb, IN UINT8 State)
 
UINT16 TcpChecksum (IN NET_BUF *Nbuf, IN UINT16 HeadSum)
 
TCP_SEGTcpFormatNetbuf (IN TCP_CB *Tcb, IN OUT NET_BUF *Nbuf)
 
EFI_STATUS TcpOnAppConnect (IN OUT TCP_CB *Tcb)
 
VOID TcpOnAppClose (IN OUT TCP_CB *Tcb)
 
INTN TcpOnAppSend (IN OUT TCP_CB *Tcb)
 
VOID TcpOnAppConsume (IN TCP_CB *Tcb)
 
VOID TcpOnAppAbort (IN TCP_CB *Tcb)
 
VOID TcpResetConnection (IN TCP_CB *Tcb)
 
EFI_STATUS TcpInstallDevicePath (IN SOCKET *Sock)
 

Variables

LIST_ENTRY mTcpRunQue
 
LIST_ENTRY mTcpListenQue
 
TCP_SEQNO mTcpGlobalSecret
 
CHAR16 * mTcpStateName []
 

Detailed Description

Misc support routines for TCP driver.

(C) Copyright 2014 Hewlett-Packard Development Company, L.P.
Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.
Copyright (c) Microsoft Corporation SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file TcpMisc.c.

Function Documentation

◆ TcpChecksum()

UINT16 TcpChecksum ( IN NET_BUF Nbuf,
IN UINT16  HeadSum 
)

Compute the TCP segment's checksum.

Parameters
[in]NbufPointer to the buffer that contains the TCP segment.
[in]HeadSumThe checksum value of the fixed part of pseudo header.
Returns
The checksum value.

Definition at line 854 of file TcpMisc.c.

◆ TcpCloneTcb()

TCP_CB * TcpCloneTcb ( IN TCP_CB Tcb)

Clone a TCP_CB from Tcb.

Parameters
[in]TcbPointer to the TCP_CB to be cloned.
Returns
Pointer to the new cloned TCP_CB; if NULL, error condition occurred.

Definition at line 534 of file TcpMisc.c.

◆ TcpFindTcbByPeer()

BOOLEAN TcpFindTcbByPeer ( IN EFI_IP_ADDRESS Addr,
IN TCP_PORTNO  Port,
IN UINT8  Version 
)

Try to find one Tcb whose <Ip, Port> equals to <IN Addr, IN Port>.

Parameters
[in]AddrPointer to the IP address needs to match.
[in]PortThe port number needs to match.
[in]VersionIP_VERSION_4 indicates TCP is running on IP4 stack, IP_VERSION_6 indicates TCP is running on IP6 stack.
Return values
TRUEThe Tcb which matches the <Addr Port> pair exists.
FALSEOtherwise

Definition at line 364 of file TcpMisc.c.

◆ TcpFormatNetbuf()

TCP_SEG * TcpFormatNetbuf ( IN TCP_CB Tcb,
IN OUT NET_BUF Nbuf 
)

Translate the information from the head of the received TCP segment Nbuf contents and fill it into a TCP_SEG structure.

Parameters
[in]TcbPointer to the TCP_CB of this TCP instance.
[in,out]NbufPointer to the buffer contains the TCP segment.
Returns
Pointer to the TCP_SEG that contains the translated TCP head information.

Definition at line 883 of file TcpMisc.c.

◆ TcpGetIsn()

EFI_STATUS TcpGetIsn ( IN UINT8 *  LocalIp,
IN UINTN  LocalIpSize,
IN UINT16  LocalPort,
IN UINT8 *  RemoteIp,
IN UINTN  RemoteIpSize,
IN UINT16  RemotePort,
OUT TCP_SEQNO *  Isn 
)

Retrieves the Initial Sequence Number (ISN) for a TCP connection identified by local and remote IP addresses and ports.

This method is based on https://datatracker.ietf.org/doc/html/rfc9293#section-3.4.1 Where the ISN is computed as follows: ISN = TimeStamp + MD5(LocalIP, LocalPort, RemoteIP, RemotePort, Secret)

Otherwise: ISN = M + F(localip, localport, remoteip, remoteport, secretkey)

"Here M is the 4 microsecond timer, and F() is a pseudorandom function (PRF) of the connection's identifying parameters ("localip, localport, remoteip, remoteport") and a secret key ("secretkey") (SHLD-1). F() MUST NOT be computable from the outside (MUST-9), or an attacker could still guess at sequence numbers from the ISN used for some other connection. The PRF could be implemented as a cryptographic hash of the concatenation of the TCP connection parameters and some secret data. For discussion of the selection of a specific hash algorithm and management of the secret key data."

Parameters
[in]LocalIpA pointer to the local IP address of the TCP connection.
[in]LocalIpSizeThe size, in bytes, of the LocalIp buffer.
[in]LocalPortThe local port number of the TCP connection.
[in]RemoteIpA pointer to the remote IP address of the TCP connection.
[in]RemoteIpSizeThe size, in bytes, of the RemoteIp buffer.
[in]RemotePortThe remote port number of the TCP connection.
[out]IsnA pointer to the variable that will receive the Initial Sequence Number (ISN).
Return values
EFI_SUCCESSThe operation completed successfully, and the ISN was retrieved.
EFI_INVALID_PARAMETEROne or more of the input parameters are invalid.
EFI_UNSUPPORTEDThe operation is not supported.

Definition at line 605 of file TcpMisc.c.

◆ TcpGetRcvMss()

UINT16 TcpGetRcvMss ( IN SOCKET Sock)

Get the local mss.

Parameters
[in]SockPointer to the socket to get mss.
Returns
The mss size.

Definition at line 737 of file TcpMisc.c.

◆ TcpInitTcbLocal()

EFI_STATUS TcpInitTcbLocal ( IN OUT TCP_CB Tcb)

Initialize the Tcb local related members.

Parameters
[in,out]TcbPointer to the TCP_CB of this TCP instance.
Return values
EFI_SUCCESSThe operation completed successfully
othersThe underlying functions failed and could not complete the operation

Definition at line 76 of file TcpMisc.c.

◆ TcpInitTcbPeer()

VOID TcpInitTcbPeer ( IN OUT TCP_CB Tcb,
IN TCP_SEG Seg,
IN TCP_OPTION Opt 
)

Initialize the peer related members.

Parameters
[in,out]TcbPointer to the TCP_CB of this TCP instance.
[in]SegPointer to the segment that contains the peer's initial info.
[in]OptPointer to the options announced by the peer.

Definition at line 157 of file TcpMisc.c.

◆ TcpInsertTcb()

INTN TcpInsertTcb ( IN TCP_CB Tcb)

Insert a Tcb into the proper queue.

Parameters
[in]TcbPointer to the TCP_CB to be inserted.
Return values
0The Tcb was inserted successfully.
-1Error condition occurred.

Definition at line 478 of file TcpMisc.c.

◆ TcpInstallDevicePath()

EFI_STATUS TcpInstallDevicePath ( IN SOCKET Sock)

Install the device path protocol on the TCP instance.

Parameters
[in]SockPointer to the socket representing the TCP instance.
Return values
EFI_SUCCESSThe device path protocol was installed.
otherFailed to install the device path protocol.

Definition at line 1180 of file TcpMisc.c.

◆ TcpIsIpEqual()

BOOLEAN TcpIsIpEqual ( IN EFI_IP_ADDRESS Ip1,
IN EFI_IP_ADDRESS Ip2,
IN UINT8  Version 
)

Check whether one IP address equals the other.

Parameters
[in]Ip1Pointer to IP address to be checked.
[in]Ip2Pointer to IP address to be checked.
[in]VersionIP_VERSION_4 indicates the IP address is an IPv4 address, IP_VERSION_6 indicates the IP address is an IPv6 address.
Return values
TRUEIp1 equals Ip2.
FALSEIp1 does not equal Ip2.

Definition at line 239 of file TcpMisc.c.

◆ TcpIsIpZero()

BOOLEAN TcpIsIpZero ( IN EFI_IP_ADDRESS Ip,
IN UINT8  Version 
)

Check whether one IP address is filled with ZERO.

Parameters
[in]IpPointer to the IP address to be checked.
[in]VersionIP_VERSION_4 indicates the IP address is an IPv4 address, IP_VERSION_6 indicates the IP address is an IPv6 address.
Return values
TRUEIp is all zero address.
FALSEIp is not all zero address.

Definition at line 266 of file TcpMisc.c.

◆ TcpLocateListenTcb()

TCP_CB * TcpLocateListenTcb ( IN TCP_PEER Local,
IN TCP_PEER Remote,
IN UINT8  Version 
)

Locate a listen TCB that matchs the Local and Remote.

Parameters
[in]LocalPointer to the local (IP, Port).
[in]RemotePointer to the remote (IP, Port).
[in]VersionIP_VERSION_4 indicates TCP is running on IP4 stack, IP_VERSION_6 indicates TCP is running on IP6 stack.
Returns
Pointer to the TCP_CB with the least number of wildcards, if NULL no match is found.

Definition at line 294 of file TcpMisc.c.

◆ TcpLocateTcb()

TCP_CB * TcpLocateTcb ( IN TCP_PORTNO  LocalPort,
IN EFI_IP_ADDRESS LocalIp,
IN TCP_PORTNO  RemotePort,
IN EFI_IP_ADDRESS RemoteIp,
IN UINT8  Version,
IN BOOLEAN  Syn 
)

Locate the TCP_CB related to the socket pair.

Parameters
[in]LocalPortThe local port number.
[in]LocalIpThe local IP address.
[in]RemotePortThe remote port number.
[in]RemoteIpThe remote IP address.
[in]VersionIP_VERSION_4 indicates TCP is running on IP4 stack, IP_VERSION_6 indicates TCP is running on IP6 stack.
[in]SynIf TRUE, the listen sockets are searched.
Returns
Pointer to the related TCP_CB. If NULL, no match is found.

Definition at line 420 of file TcpMisc.c.

◆ TcpOnAppAbort()

VOID TcpOnAppAbort ( IN TCP_CB Tcb)

Abort the connection by sending a reset segment. Called when the application wants to abort the connection.

Parameters
[in]TcbPointer to the TCP_CB of the TCP instance.

Definition at line 1098 of file TcpMisc.c.

◆ TcpOnAppClose()

VOID TcpOnAppClose ( IN OUT TCP_CB Tcb)

Initiate the connection close procedure, called when applications want to close the connection.

Parameters
[in,out]TcbPointer to the TCP_CB of this TCP instance.

Definition at line 961 of file TcpMisc.c.

◆ TcpOnAppConnect()

EFI_STATUS TcpOnAppConnect ( IN OUT TCP_CB Tcb)

Initialize an active connection.

Parameters
[in,out]TcbPointer to the TCP_CB that wants to initiate a connection.
Return values
EFI_SUCCESSThe operation completed successfully
othersThe underlying functions failed and could not complete the operation

Definition at line 934 of file TcpMisc.c.

◆ TcpOnAppConsume()

VOID TcpOnAppConsume ( IN TCP_CB Tcb)

Application has consumed some data. Check whether to send a window update ack or a delayed ack.

Parameters
[in]TcbPointer to the TCP_CB of this TCP instance.

Definition at line 1054 of file TcpMisc.c.

◆ TcpOnAppSend()

INTN TcpOnAppSend ( IN OUT TCP_CB Tcb)

Check whether the application's newly delivered data can be sent out.

Parameters
[in,out]TcbPointer to the TCP_CB of this TCP instance.
Return values
0The data has been sent out successfully.
-1The Tcb is not in a state that data is permitted to be sent out.

Definition at line 1012 of file TcpMisc.c.

◆ TcpResetConnection()

VOID TcpResetConnection ( IN TCP_CB Tcb)

Reset the connection related with Tcb.

Parameters
[in]TcbPointer to the TCP_CB of the connection to be reset.

Definition at line 1130 of file TcpMisc.c.

◆ TcpSetState()

VOID TcpSetState ( IN TCP_CB Tcb,
IN UINT8  State 
)

Set the Tcb's state.

Parameters
[in]TcbPointer to the TCP_CB of this TCP instance.
[in]StateThe state to be set.

Definition at line 801 of file TcpMisc.c.

Variable Documentation

◆ mTcpGlobalSecret

TCP_SEQNO mTcpGlobalSecret

Definition at line 27 of file TcpMisc.c.

◆ mTcpListenQue

LIST_ENTRY mTcpListenQue
Initial value:
= {
&mTcpListenQue,
&mTcpListenQue
}

Definition at line 18 of file TcpMisc.c.

◆ mTcpRunQue

LIST_ENTRY mTcpRunQue
Initial value:
= {
&mTcpRunQue,
&mTcpRunQue
}

Definition at line 13 of file TcpMisc.c.

◆ mTcpStateName

CHAR16* mTcpStateName[]
Initial value:
= {
L"TCP_CLOSED",
L"TCP_LISTEN",
L"TCP_SYN_SENT",
L"TCP_SYN_RCVD",
L"TCP_ESTABLISHED",
L"TCP_FIN_WAIT_1",
L"TCP_FIN_WAIT_2",
L"TCP_CLOSING",
L"TCP_TIME_WAIT",
L"TCP_CLOSE_WAIT",
L"TCP_LAST_ACK"
}

Definition at line 52 of file TcpMisc.c.