iPXE
Data Structures | Macros | Functions | Variables
tcp.h File Reference

TCP protocol. More...

#include <ipxe/tcpip.h>

Go to the source code of this file.

Data Structures

struct  tcp_header
 A TCP header. More...
 
struct  tcp_option
 Generic TCP option. More...
 
struct  tcp_mss_option
 TCP MSS option. More...
 
struct  tcp_window_scale_option
 TCP window scale option. More...
 
struct  tcp_window_scale_padded_option
 Padded TCP window scale option (used for sending) More...
 
struct  tcp_sack_permitted_option
 TCP selective acknowledgement permitted option. More...
 
struct  tcp_sack_permitted_padded_option
 Padded TCP selective acknowledgement permitted option (used for sending) More...
 
struct  tcp_sack_option
 TCP selective acknowledgement option. More...
 
struct  tcp_sack_block
 TCP selective acknowledgement block. More...
 
struct  tcp_sack_padded_option
 Padded TCP selective acknowledgement option (used for sending) More...
 
struct  tcp_timestamp_option
 TCP timestamp option. More...
 
struct  tcp_timestamp_padded_option
 Padded TCP timestamp option (used for sending) More...
 
struct  tcp_options
 Parsed TCP options. More...
 

Macros

#define TCP_OPTION_END   0
 End of TCP options list. More...
 
#define TCP_OPTION_NOP   1
 TCP option pad. More...
 
#define TCP_OPTION_MSS   2
 Code for the TCP MSS option. More...
 
#define TCP_OPTION_WS   3
 Code for the TCP window scale option. More...
 
#define TCP_RX_WINDOW_SCALE   9
 Advertised TCP window scale. More...
 
#define TCP_OPTION_SACK_PERMITTED   4
 Code for the TCP selective acknowledgement permitted option. More...
 
#define TCP_SACK_MAX   3
 Maximum number of selective acknowledgement blocks. More...
 
#define TCP_OPTION_SACK   5
 Code for the TCP selective acknowledgement option. More...
 
#define TCP_OPTION_TS   8
 Code for the TCP timestamp option. More...
 
#define TCP_CWR   0x80
 
#define TCP_ECE   0x40
 
#define TCP_URG   0x20
 
#define TCP_ACK   0x10
 
#define TCP_PSH   0x08
 
#define TCP_RST   0x04
 
#define TCP_SYN   0x02
 
#define TCP_FIN   0x01
 
#define TCP_STATE_SENT(flags)   ( (flags) << 0 )
 TCP flags that have been sent in outgoing packets. More...
 
#define TCP_FLAGS_SENT(state)   ( ( (state) >> 0 ) & 0xff )
 
#define TCP_STATE_ACKED(flags)   ( (flags) << 8 )
 TCP flags that have been acknowledged by the peer. More...
 
#define TCP_FLAGS_ACKED(state)   ( ( (state) >> 8 ) & 0xff )
 
#define TCP_STATE_RCVD(flags)   ( (flags) << 16 )
 TCP flags that have been received from the peer. More...
 
#define TCP_FLAGS_RCVD(state)   ( ( (state) >> 16 ) & 0xff )
 
#define TCP_FLAGS_SENDING(state)   ( TCP_FLAGS_SENT ( state ) & ~TCP_FLAGS_ACKED ( state ) )
 TCP flags that are currently being sent in outgoing packets. More...
 
#define TCP_CLOSED   TCP_RST
 CLOSED. More...
 
#define TCP_LISTEN   0
 LISTEN. More...
 
#define TCP_SYN_SENT   ( TCP_STATE_SENT ( TCP_SYN ) )
 SYN_SENT. More...
 
#define TCP_SYN_RCVD
 SYN_RCVD. More...
 
#define TCP_ESTABLISHED
 ESTABLISHED. More...
 
#define TCP_FIN_WAIT_1
 FIN_WAIT_1. More...
 
#define TCP_FIN_WAIT_2
 FIN_WAIT_2. More...
 
#define TCP_CLOSING_OR_LAST_ACK
 CLOSING / LAST_ACK. More...
 
#define TCP_TIME_WAIT
 TIME_WAIT. More...
 
#define TCP_CLOSE_WAIT
 CLOSE_WAIT. More...
 
#define TCP_CAN_SEND_DATA(state)
 Can send data in current state. More...
 
#define TCP_HAS_BEEN_ESTABLISHED(state)
 Have ever been fully established. More...
 
#define TCP_CLOSED_GRACEFULLY(state)
 Have closed gracefully. More...
 
#define TCP_MASK_HLEN   0xf0
 Mask for TCP header length field. More...
 
#define TCP_MIN_PORT   1
 Smallest port number on which a TCP connection can listen. More...
 
#define TCP_MAX_WINDOW_SIZE   ( 2048 * 1024 )
 Maxmimum advertised TCP window size. More...
 
#define TCP_PATH_MTU   ( 1280 - 40 /* IPv6 */ - 20 /* TCP */ - 12 /* TCP timestamp */ )
 Path MTU. More...
 
#define TCP_MSL   ( 2 * 60 * TICKS_PER_SEC )
 TCP maximum segment lifetime. More...
 
#define TCP_KEEPALIVE_DELAY   ( 15 * TICKS_PER_SEC )
 TCP keepalive period. More...
 
#define TCP_MAX_HEADER_LEN
 TCP maximum header length. More...
 
#define TCP_FINISH_TIMEOUT   ( 1 * TICKS_PER_SEC )
 TCP finish wait time. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
struct tcp_window_scale_padded_option __attribute ((packed))
 
static int32_t tcp_cmp (uint32_t seq1, uint32_t seq2)
 Compare TCP sequence numbers. More...
 
static int tcp_in_window (uint32_t seq, uint32_t start, uint32_t len)
 Check if TCP sequence number lies within window. More...
 

Variables

struct tcp_header __attribute__
 
uint8_t nop
 
struct tcp_window_scale_option wsopt
 
struct tcp_sack_permitted_option __attribute
 
struct tcpip_protocol tcp_protocol __tcpip_protocol
 ICMPv4 TCP/IP protocol. More...
 

Detailed Description

TCP protocol.

This file defines the iPXE TCP API.

Definition in file tcp.h.

Macro Definition Documentation

◆ TCP_CWR

#define TCP_CWR   0x80

Definition at line 156 of file tcp.h.

◆ TCP_ECE

#define TCP_ECE   0x40

Definition at line 157 of file tcp.h.

◆ TCP_URG

#define TCP_URG   0x20

Definition at line 158 of file tcp.h.

◆ TCP_ACK

#define TCP_ACK   0x10

Definition at line 159 of file tcp.h.

◆ TCP_PSH

#define TCP_PSH   0x08

Definition at line 160 of file tcp.h.

◆ TCP_RST

#define TCP_RST   0x04

Definition at line 161 of file tcp.h.

◆ TCP_SYN

#define TCP_SYN   0x02

Definition at line 162 of file tcp.h.

◆ TCP_FIN

#define TCP_FIN   0x01

Definition at line 163 of file tcp.h.

◆ TCP_MASK_HLEN

#define TCP_MASK_HLEN   0xf0

Mask for TCP header length field.

Definition at line 324 of file tcp.h.

◆ TCP_MIN_PORT

#define TCP_MIN_PORT   1

Smallest port number on which a TCP connection can listen.

Definition at line 327 of file tcp.h.

◆ TCP_MAX_WINDOW_SIZE

#define TCP_MAX_WINDOW_SIZE   ( 2048 * 1024 )

Maxmimum advertised TCP window size.

The maximum bandwidth on any link is limited by

max_bandwidth * round_trip_time = tcp_window

Some rough expectations for achievable bandwidths over various links are:

a) Gigabit LAN: expected bandwidth 125MB/s, typical RTT 0.5ms, minimum required window 64kB

b) 10-Gigabit LAN: expected bandwidth 1250MB/s, typical RTT 0.5ms, minimum required window 640kB

c) Home Internet connection: expected bandwidth 50MB/s, typical RTT 25ms, minimum required window 1280kB

d) International WAN: expected bandwidth 50MB/s, typical RTT 25ms, minimum required window 1280kB

e) Intercontinental WAN: expected bandwidth 5MB/s, typical RTT 250ms, minimum required window 1280kB.

The maximum possible value for the TCP window size is 1GB (using the maximum window scale of 2**14). However, it is advisable to keep the window size as small as possible (without limiting bandwidth), since in the event of a lost packet the window size represents the maximum amount that will need to be retransmitted.

We therefore choose a (rounded up) maximum window size of 2048kB.

Definition at line 362 of file tcp.h.

◆ TCP_PATH_MTU

#define TCP_PATH_MTU   ( 1280 - 40 /* IPv6 */ - 20 /* TCP */ - 12 /* TCP timestamp */ )

Path MTU.

IPv6 requires all data link layers to support a datagram size of 1280 bytes. We choose to use this as our maximum transmitted datagram size, on the assumption that any practical link layer we encounter will allow this size. This is a very conservative assumption in practice, but the impact of making such a conservative assumption is insignificant since the amount of data that we transmit (rather than receive) is negligible.

We allow space within this 1280 bytes for an IPv6 header, a TCP header, and a (padded) TCP timestamp option.

Definition at line 378 of file tcp.h.

◆ TCP_MSL

#define TCP_MSL   ( 2 * 60 * TICKS_PER_SEC )

TCP maximum segment lifetime.

Currently set to 2 minutes, as per RFC 793.

Definition at line 385 of file tcp.h.

◆ TCP_KEEPALIVE_DELAY

#define TCP_KEEPALIVE_DELAY   ( 15 * TICKS_PER_SEC )

TCP keepalive period.

We send keepalive ACKs after this period of inactivity has elapsed on an established connection.

Definition at line 393 of file tcp.h.

◆ TCP_MAX_HEADER_LEN

#define TCP_MAX_HEADER_LEN
Value:
sizeof ( struct tcp_header ) + \
sizeof ( struct tcp_mss_option ) + \
sizeof ( struct tcp_window_scale_padded_option ) + \
sizeof ( struct tcp_timestamp_padded_option ) )
Padded TCP window scale option (used for sending)
Definition: tcp.h:65
#define MAX_LL_NET_HEADER_LEN
Maximum combined length of a link-layer and network-layer header.
Definition: netdevice.h:58
Padded TCP timestamp option (used for sending)
Definition: tcp.h:133
A TCP header.
Definition: tcp.h:19
TCP MSS option.
Definition: tcp.h:48

TCP maximum header length.

Definition at line 399 of file tcp.h.

◆ TCP_FINISH_TIMEOUT

#define TCP_FINISH_TIMEOUT   ( 1 * TICKS_PER_SEC )

TCP finish wait time.

Currently set to one second, since we should not allow a slowly responding server to substantially delay a call to shutdown().

Definition at line 440 of file tcp.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ tcp_cmp()

static int32_t tcp_cmp ( uint32_t  seq1,
uint32_t  seq2 
)
inlinestatic

Compare TCP sequence numbers.

Parameters
seq1Sequence number 1
seq2Sequence number 2
Return values
diffSequence difference

Analogous to memcmp(), returns an integer less than, equal to, or greater than zero if seq1 is found, respectively, to be before, equal to, or after seq2.

Definition at line 418 of file tcp.h.

418  {
419  return ( ( int32_t ) ( seq1 - seq2 ) );
420 }
signed int int32_t
Definition: stdint.h:17

Referenced by tcp_process_rx_queue(), tcp_rx_enqueue(), tcp_rx_seq(), and tcp_sack_block().

◆ tcp_in_window()

static int tcp_in_window ( uint32_t  seq,
uint32_t  start,
uint32_t  len 
)
inlinestatic

Check if TCP sequence number lies within window.

Parameters
seqSequence number
startStart of window
lenLength of window
Return values
in_windowSequence number is within window

Definition at line 430 of file tcp.h.

431  {
432  return ( ( seq - start ) < len );
433 }
u16 seq
802.11 Sequence Control field
Definition: ieee80211.h:19
uint32_t start
Starting offset.
Definition: netvsc.h:12
uint32_t len
Length.
Definition: ena.h:14

References len, seq, and start.

Referenced by tcp_rx_rst().

Variable Documentation

◆ __attribute__

◆ nop

uint8_t nop

Definition at line 13 of file tcp.h.

Referenced by xhci_nop().

◆ wsopt

Definition at line 14 of file tcp.h.

Referenced by tcp_xmit_sack().

◆ __tcpip_protocol

struct tcpip_protocol tcp_protocol __tcpip_protocol

ICMPv4 TCP/IP protocol.

ICMPv4 TCP/IP protocol.

Definition at line 100 of file icmpv4.c.