iPXE
Data Structures | Defines | 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...

Defines

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

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.
static int tcp_in_window (uint32_t seq, uint32_t start, uint32_t len)
 Check if TCP sequence number lies within window.

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.

Detailed Description

TCP protocol.

This file defines the iPXE TCP API.

Definition in file tcp.h.


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

Referenced by tcp_dump_flags(), tcp_rx(), tcp_rx_syn(), and tcp_xmit_reset().

#define TCP_PSH   0x08

Definition at line 160 of file tcp.h.

Referenced by tcp_dump_flags(), and tcp_xmit_sack().

#define TCP_RST   0x04

Definition at line 161 of file tcp.h.

Referenced by tcp_dump_flags(), tcp_rx(), and tcp_xmit_reset().

#define TCP_SYN   0x02
#define TCP_FIN   0x01
#define TCP_MASK_HLEN   0xf0

Mask for TCP header length field.

Definition at line 324 of file tcp.h.

Referenced by tcp_rx().

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

Referenced by tcp_xmit_sack().

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

Referenced by tcp_xmit_win().

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

Referenced by tcp_rx().

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

Referenced by tcp_keepalive_expired(), and tcp_rx_ack().

Value:
( MAX_LL_NET_HEADER_LEN +                               \
          sizeof ( struct tcp_header ) +                        \
          sizeof ( struct tcp_mss_option ) +                    \
          sizeof ( struct tcp_window_scale_padded_option ) +    \
          sizeof ( struct tcp_timestamp_padded_option ) )

TCP maximum header length.

Definition at line 393 of file tcp.h.

Referenced by tcp_xmit_reset(), and tcp_xmit_sack().

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

Referenced by tcp_shutdown().


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
static int32_t tcp_cmp ( uint32_t  seq1,
uint32_t  seq2 
) [inline, static]

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

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

                                         {
        return ( ( int32_t ) ( seq1 - seq2 ) );
}
static int tcp_in_window ( uint32_t  seq,
uint32_t  start,
uint32_t  len 
) [inline, static]

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

Referenced by tcp_rx_rst().

                                                 {
        return ( ( seq - start ) < len );
}

Variable Documentation

Definition at line 69 of file tcp.h.

Referenced by xhci_nop().

Definition at line 70 of file tcp.h.

Referenced by tcp_xmit_sack().

struct tcpip_protocol tcp_protocol __tcpip_protocol

ICMPv4 TCP/IP protocol.

Definition at line 100 of file icmpv4.c.