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...


#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...
 Advertised TCP window scale. More...
 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...
 CLOSED. More...
#define TCP_LISTEN   0
 LISTEN. More...
 SYN_SENT. More...
#define TCP_SYN_RCVD
 SYN_RCVD. More...
#define TCP_FIN_WAIT_1
 FIN_WAIT_1. More...
#define TCP_FIN_WAIT_2
 FIN_WAIT_2. More...
 TIME_WAIT. More...
 CLOSE_WAIT. More...
#define TCP_CAN_SEND_DATA(state)
 Can send data in current state. More...
 Have ever been fully established. More...
 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   ( 256 * 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...
 TCP keepalive period. More...
 TCP maximum header length. More...
 TCP finish wait time. More...


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...


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


#define TCP_CWR   0x80

Definition at line 156 of file tcp.h.


#define TCP_ECE   0x40

Definition at line 157 of file tcp.h.


#define TCP_URG   0x20

Definition at line 158 of file tcp.h.


#define TCP_ACK   0x10

Definition at line 159 of file tcp.h.


#define TCP_PSH   0x08

Definition at line 160 of file tcp.h.


#define TCP_RST   0x04

Definition at line 161 of file tcp.h.


#define TCP_SYN   0x02

Definition at line 162 of file tcp.h.


#define TCP_FIN   0x01

Definition at line 163 of file tcp.h.


#define TCP_MASK_HLEN   0xf0

Mask for TCP header length field.

Definition at line 324 of file tcp.h.


#define TCP_MIN_PORT   1

Smallest port number on which a TCP connection can listen.

Definition at line 327 of file tcp.h.


#define TCP_MAX_WINDOW_SIZE   ( 256 * 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) Home Internet connection: expected bandwidth 10MB/s, typical RTT 25ms, minimum required window 256kB

c) WAN: expected bandwidth 2MB/s, typical RTT 100ms, minimum required window 200kB.

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 maximum window size of 256kB.

Definition at line 356 of file tcp.h.


#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 372 of file tcp.h.


#define TCP_MSL   ( 2 * 60 * TICKS_PER_SEC )

TCP maximum segment lifetime.

Currently set to 2 minutes, as per RFC 793.

Definition at line 379 of file tcp.h.



TCP keepalive period.

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

Definition at line 387 of file tcp.h.


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
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 393 of file tcp.h.



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 434 of file tcp.h.

Function Documentation



◆ tcp_cmp()

static int32_t tcp_cmp ( uint32_t  seq1,
uint32_t  seq2 

Compare TCP sequence numbers.

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 412 of file tcp.h.

412  {
413  return ( ( int32_t ) ( seq1 - seq2 ) );
414 }
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 

Check if TCP sequence number lies within window.

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

Definition at line 424 of file tcp.h.

425  {
426  return ( ( seq - start ) < len );
427 }
u16 seq
802.11 Sequence Control field
Definition: ieee80211.h:19
uint32_t start
Starting offset.
Definition: netvsc.h:12
uint32_t len
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.