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

Defines

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

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.


Define Documentation

#define TCP_STATE_SENT (   flags)    ( (flags) << 0 )

TCP flags that have been sent in outgoing packets.

Definition at line 176 of file tcp.h.

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

#define TCP_FLAGS_SENT (   state)    ( ( (state) >> 0 ) & 0xff )

Definition at line 177 of file tcp.h.

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

TCP flags that have been acknowledged by the peer.

Note that this applies only to SYN and FIN.

Definition at line 183 of file tcp.h.

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

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

Definition at line 184 of file tcp.h.

#define TCP_STATE_RCVD (   flags)    ( (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 191 of file tcp.h.

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

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

Definition at line 192 of file tcp.h.

#define TCP_FLAGS_SENDING (   state)    ( TCP_FLAGS_SENT ( state ) & ~TCP_FLAGS_ACKED ( state ) )

TCP flags that are currently being sent in outgoing packets.

Definition at line 195 of file tcp.h.

Referenced by tcp_rx_ack(), and tcp_xmit_sack().

#define TCP_CLOSED   TCP_RST

CLOSED.

The connection has not yet been used for anything.

Definition at line 202 of file tcp.h.

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

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

Referenced by tcp_state().

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

Referenced by tcp_expired(), and tcp_state().

#define TCP_SYN_RCVD
Value:
( TCP_STATE_SENT ( TCP_SYN | TCP_ACK ) |            \
                          TCP_STATE_RCVD ( TCP_SYN ) )

SYN_RCVD.

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

Definition at line 221 of file tcp.h.

Referenced by tcp_expired(), and tcp_state().

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

ESTABLISHED.

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

Definition at line 228 of file tcp.h.

Referenced by tcp_expired(), and tcp_state().

#define TCP_FIN_WAIT_1
Value:
( TCP_STATE_SENT ( TCP_SYN | TCP_ACK | TCP_FIN ) |  \
                          TCP_STATE_ACKED ( TCP_SYN ) |                     \
                          TCP_STATE_RCVD ( TCP_SYN ) )

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

Referenced by tcp_expired(), and tcp_state().

#define TCP_FIN_WAIT_2
Value:
( TCP_STATE_SENT ( TCP_SYN | TCP_ACK | TCP_FIN ) |  \
                          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 255 of file tcp.h.

Referenced by tcp_state().

Value:
( TCP_STATE_SENT ( TCP_SYN | TCP_ACK | TCP_FIN ) |  \
                          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 268 of file tcp.h.

Referenced by tcp_expired(), and tcp_state().

#define TCP_TIME_WAIT
Value:
( TCP_STATE_SENT ( TCP_SYN | TCP_ACK | TCP_FIN ) |  \
                          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 278 of file tcp.h.

Referenced by tcp_state(), and tcp_wait_expired().

#define TCP_CLOSE_WAIT
Value:
( TCP_STATE_SENT ( TCP_SYN | TCP_ACK ) |            \
                          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 287 of file tcp.h.

Referenced by tcp_expired(), and tcp_state().

#define TCP_CAN_SEND_DATA (   state)
Value:
( ( (state) & ( TCP_STATE_ACKED ( TCP_SYN ) |                       \
                        TCP_STATE_SENT ( TCP_FIN ) ) )                      \
          == TCP_STATE_ACKED ( TCP_SYN ) )

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

Referenced by tcp_xmit_sack(), and tcp_xmit_win().

Value:
( ( (state) & ( TCP_STATE_ACKED ( TCP_SYN ) |                       \
                        TCP_STATE_RCVD ( TCP_SYN ) ) )                      \
          == ( TCP_STATE_ACKED ( TCP_SYN ) | TCP_STATE_RCVD ( TCP_SYN ) ) )

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

Referenced by tcp_rx_ack().

Value:
( ( (state) & ( TCP_STATE_ACKED ( TCP_FIN ) |                       \
                        TCP_STATE_RCVD ( TCP_FIN ) ) )                      \
          == ( 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 316 of file tcp.h.

Referenced by tcp_first_unfinished(), and tcp_rx().