iPXE
TCP states

The TCP state is defined by a combination of the flags that have been sent to the peer, the flags that have been acknowledged by the peer, and the flags that have been received from the peer. More...

Macros

#define TCP_STATE_SENT(flags)
 TCP flags that have been sent in outgoing packets.
#define TCP_FLAGS_SENT(state)
#define TCP_STATE_ACKED(flags)
 TCP flags that have been acknowledged by the peer.
#define TCP_FLAGS_ACKED(state)
#define TCP_STATE_RCVD(flags)
 TCP flags that have been received from the peer.
#define TCP_FLAGS_RCVD(state)
#define TCP_FLAGS_SENDING(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.

Detailed Description

The TCP state is defined by a combination of the flags that have been sent to the peer, the flags that have been acknowledged by the peer, and the flags that have been received from the peer.

Macro Definition Documentation

◆ TCP_STATE_SENT

#define TCP_STATE_SENT ( flags)
Value:
( (flags) << 0 )
uint8_t flags
Flags.
Definition ena.h:7

TCP flags that have been sent in outgoing packets.

Definition at line 177 of file tcp.h.

Referenced by tcp_close(), tcp_open(), tcp_rx_ack(), and tcp_rx_syn().

◆ TCP_FLAGS_SENT

#define TCP_FLAGS_SENT ( state)
Value:
( ( (state) >> 0 ) & 0xff )
uint8_t state
State.
Definition eth_slow.h:36

Definition at line 178 of file tcp.h.

◆ TCP_STATE_ACKED

#define TCP_STATE_ACKED ( flags)
Value:
( (flags) << 8 )

TCP flags that have been acknowledged by the peer.

Note that this applies only to SYN and FIN.

Definition at line 184 of file tcp.h.

Referenced by tcp_close(), tcp_rx_ack(), and tcp_rx_rst().

◆ TCP_FLAGS_ACKED

#define TCP_FLAGS_ACKED ( state)
Value:
( ( (state) >> 8 ) & 0xff )

Definition at line 185 of file tcp.h.

◆ TCP_STATE_RCVD

#define TCP_STATE_RCVD ( flags)
Value:
( (flags) << 16 )

TCP flags that have been received from the peer.

Note that this applies only to SYN and FIN, and that once SYN has been received, we should always be sending ACK.

Definition at line 192 of file tcp.h.

Referenced by tcp_close(), tcp_rx(), tcp_rx_enqueue(), tcp_rx_fin(), tcp_rx_rst(), and tcp_rx_syn().

◆ TCP_FLAGS_RCVD

#define TCP_FLAGS_RCVD ( state)
Value:
( ( (state) >> 16 ) & 0xff )

Definition at line 193 of file tcp.h.

◆ TCP_FLAGS_SENDING

#define TCP_FLAGS_SENDING ( state)
Value:
#define TCP_FLAGS_SENT(state)
Definition tcp.h:178
#define TCP_FLAGS_ACKED(state)
Definition tcp.h:185

TCP flags that are currently being sent in outgoing packets.

Definition at line 196 of file tcp.h.

196#define TCP_FLAGS_SENDING(state) \
197 ( TCP_FLAGS_SENT ( state ) & ~TCP_FLAGS_ACKED ( state ) )

Referenced by tcp_rx_ack(), and tcp_xmit_sack().

◆ TCP_CLOSED

#define TCP_CLOSED   TCP_RST

CLOSED.

The connection has not yet been used for anything.

Definition at line 203 of file tcp.h.

Referenced by tcp_close(), tcp_expired(), tcp_open(), tcp_rx_rst(), tcp_shutdown(), tcp_state(), and tcp_wait_expired().

◆ TCP_LISTEN

#define TCP_LISTEN   0

LISTEN.

Not currently used as a state; we have no support for listening connections. Given a unique value to avoid compiler warnings.

Definition at line 210 of file tcp.h.

Referenced by tcp_state().

◆ TCP_SYN_SENT

#define TCP_SYN_SENT   ( TCP_STATE_SENT ( TCP_SYN ) )

SYN_SENT.

SYN has been sent, nothing has yet been received or acknowledged.

Definition at line 216 of file tcp.h.

Referenced by tcp_expired(), and tcp_state().

◆ TCP_SYN_RCVD

#define TCP_SYN_RCVD
Value:
TCP_STATE_RCVD ( TCP_SYN ) )
#define TCP_STATE_SENT(flags)
TCP flags that have been sent in outgoing packets.
Definition tcp.h:177
#define TCP_ACK
Definition tcp.h:160
#define TCP_SYN
Definition tcp.h:163

SYN_RCVD.

SYN has been sent but not acknowledged, SYN has been received.

Definition at line 222 of file tcp.h.

222#define TCP_SYN_RCVD ( TCP_STATE_SENT ( TCP_SYN | TCP_ACK ) | \
223 TCP_STATE_RCVD ( TCP_SYN ) )

Referenced by tcp_expired(), and tcp_state().

◆ TCP_ESTABLISHED

#define TCP_ESTABLISHED
Value:
TCP_STATE_ACKED ( TCP_SYN ) | \
TCP_STATE_RCVD ( TCP_SYN ) )

ESTABLISHED.

SYN has been sent and acknowledged, SYN has been received.

Definition at line 229 of file tcp.h.

229#define TCP_ESTABLISHED ( TCP_STATE_SENT ( TCP_SYN | TCP_ACK ) | \
230 TCP_STATE_ACKED ( TCP_SYN ) | \
231 TCP_STATE_RCVD ( TCP_SYN ) )

Referenced by tcp_expired(), and tcp_state().

◆ TCP_FIN_WAIT_1

#define TCP_FIN_WAIT_1
Value:
TCP_STATE_ACKED ( TCP_SYN ) | \
TCP_STATE_RCVD ( TCP_SYN ) )
#define TCP_FIN
Definition tcp.h:164

FIN_WAIT_1.

SYN has been sent and acknowledged, SYN has been received, FIN has been sent but not acknowledged, FIN has not been received.

RFC 793 shows that we can enter FIN_WAIT_1 without have had SYN acknowledged, i.e. if the application closes the connection after sending and receiving SYN, but before having had SYN acknowledged. However, we have to pretend that SYN has been acknowledged anyway, otherwise we end up sending SYN and FIN in the same sequence number slot. Therefore, when we transition from SYN_RCVD to FIN_WAIT_1, we have to remember to set TCP_STATE_ACKED(TCP_SYN) and increment our sequence number.

Definition at line 247 of file tcp.h.

247#define TCP_FIN_WAIT_1 ( TCP_STATE_SENT ( TCP_SYN | TCP_ACK | TCP_FIN ) | \
248 TCP_STATE_ACKED ( TCP_SYN ) | \
249 TCP_STATE_RCVD ( TCP_SYN ) )

Referenced by tcp_expired(), and tcp_state().

◆ TCP_FIN_WAIT_2

#define TCP_FIN_WAIT_2
Value:
TCP_STATE_ACKED ( TCP_SYN | TCP_FIN ) | \
TCP_STATE_RCVD ( TCP_SYN ) )

FIN_WAIT_2.

SYN has been sent and acknowledged, SYN has been received, FIN has been sent and acknowledged, FIN ha not been received.

Definition at line 256 of file tcp.h.

256#define TCP_FIN_WAIT_2 ( TCP_STATE_SENT ( TCP_SYN | TCP_ACK | TCP_FIN ) | \
257 TCP_STATE_ACKED ( TCP_SYN | TCP_FIN ) | \
258 TCP_STATE_RCVD ( TCP_SYN ) )

Referenced by tcp_state().

◆ TCP_CLOSING_OR_LAST_ACK

#define TCP_CLOSING_OR_LAST_ACK
Value:
TCP_STATE_ACKED ( TCP_SYN ) | \
TCP_STATE_RCVD ( TCP_SYN | TCP_FIN ) )

CLOSING / LAST_ACK.

SYN has been sent and acknowledged, SYN has been received, FIN has been sent but not acknowledged, FIN has been received.

This state actually encompasses both CLOSING and LAST_ACK; they are identical with the definition of state that we use. I don't believe that they need to be distinguished.

Definition at line 269 of file tcp.h.

269#define TCP_CLOSING_OR_LAST_ACK \
270 ( TCP_STATE_SENT ( TCP_SYN | TCP_ACK | TCP_FIN ) | \
271 TCP_STATE_ACKED ( TCP_SYN ) | \
272 TCP_STATE_RCVD ( TCP_SYN | TCP_FIN ) )

Referenced by tcp_expired(), and tcp_state().

◆ TCP_TIME_WAIT

#define TCP_TIME_WAIT
Value:
TCP_STATE_ACKED ( TCP_SYN | TCP_FIN ) | \
TCP_STATE_RCVD ( TCP_SYN | TCP_FIN ) )

TIME_WAIT.

SYN has been sent and acknowledged, SYN has been received, FIN has been sent and acknowledged, FIN has been received.

Definition at line 279 of file tcp.h.

279#define TCP_TIME_WAIT ( TCP_STATE_SENT ( TCP_SYN | TCP_ACK | TCP_FIN ) | \
280 TCP_STATE_ACKED ( TCP_SYN | TCP_FIN ) | \
281 TCP_STATE_RCVD ( TCP_SYN | TCP_FIN ) )

Referenced by tcp_state(), and tcp_wait_expired().

◆ TCP_CLOSE_WAIT

#define TCP_CLOSE_WAIT
Value:
TCP_STATE_ACKED ( TCP_SYN ) | \
TCP_STATE_RCVD ( TCP_SYN | TCP_FIN ) )

CLOSE_WAIT.

SYN has been sent and acknowledged, SYN has been received, FIN has been received.

Definition at line 288 of file tcp.h.

288#define TCP_CLOSE_WAIT ( TCP_STATE_SENT ( TCP_SYN | TCP_ACK ) | \
289 TCP_STATE_ACKED ( TCP_SYN ) | \
290 TCP_STATE_RCVD ( TCP_SYN | TCP_FIN ) )

Referenced by tcp_expired(), and tcp_state().

◆ TCP_CAN_SEND_DATA

#define TCP_CAN_SEND_DATA ( state)
Value:
( ( (state) & ( TCP_STATE_ACKED ( TCP_SYN ) | \
TCP_STATE_SENT ( TCP_FIN ) ) ) \
#define TCP_STATE_ACKED(flags)
TCP flags that have been acknowledged by the peer.
Definition tcp.h:184

Can send data in current state.

We can send data if and only if we have had our SYN acked and we have not yet sent our FIN.

Definition at line 297 of file tcp.h.

297#define TCP_CAN_SEND_DATA(state) \
298 ( ( (state) & ( TCP_STATE_ACKED ( TCP_SYN ) | \
299 TCP_STATE_SENT ( TCP_FIN ) ) ) \
300 == TCP_STATE_ACKED ( TCP_SYN ) )

Referenced by tcp_xmit_sack(), and tcp_xmit_win().

◆ TCP_HAS_BEEN_ESTABLISHED

#define TCP_HAS_BEEN_ESTABLISHED ( state)
Value:
( ( (state) & ( TCP_STATE_ACKED ( TCP_SYN ) | \
TCP_STATE_RCVD ( TCP_SYN ) ) ) \
#define TCP_STATE_RCVD(flags)
TCP flags that have been received from the peer.
Definition tcp.h:192

Have ever been fully established.

We have been fully established if we have both received a SYN and had our own SYN acked.

Definition at line 307 of file tcp.h.

307#define TCP_HAS_BEEN_ESTABLISHED(state) \
308 ( ( (state) & ( TCP_STATE_ACKED ( TCP_SYN ) | \
309 TCP_STATE_RCVD ( TCP_SYN ) ) ) \
310 == ( TCP_STATE_ACKED ( TCP_SYN ) | TCP_STATE_RCVD ( TCP_SYN ) ) )

Referenced by tcp_progress(), and tcp_rx_ack().

◆ TCP_CLOSED_GRACEFULLY

#define TCP_CLOSED_GRACEFULLY ( state)
Value:
( ( (state) & ( TCP_STATE_ACKED ( TCP_FIN ) | \
TCP_STATE_RCVD ( TCP_FIN ) ) ) \

Have closed gracefully.

We have closed gracefully if we have both received a FIN and had our own FIN acked.

Definition at line 317 of file tcp.h.

317#define TCP_CLOSED_GRACEFULLY(state) \
318 ( ( (state) & ( TCP_STATE_ACKED ( TCP_FIN ) | \
319 TCP_STATE_RCVD ( TCP_FIN ) ) ) \
320 == ( TCP_STATE_ACKED ( TCP_FIN ) | TCP_STATE_RCVD ( TCP_FIN ) ) )

Referenced by tcp_first_unfinished(), and tcp_rx().