Skip to content

Glossary

TCP state (tcpcb)

The kernel's per-connection state structure — sequence numbers, RTT estimates, congestion window, retransmit timers, and the protocol state machine.

A tcpcb (TCP control block) is the kernel structure that holds the complete per-connection state of a TCP connection. Every TCP socket has one underneath.

What it stores:

  • The protocol state (CLOSED, LISTEN, SYN_SENT, SYN_RCVD, ESTABLISHED, FIN_WAIT_1, FIN_WAIT_2, CLOSE_WAIT, CLOSING, LAST_ACK, TIME_WAIT).
  • Sequence numbers (send next, recv next, send unacknowledged, recv window).
  • RTT estimate + variance (drives retransmit timeouts).
  • Congestion window + slow-start threshold (per the chosen congestion-control algorithm).
  • Receive and send buffer pointers (mbuf chains).
  • Retransmit timer, keepalive timer, persist timer, 2MSL timer.
  • A per-connection lock.

apple-oss-distributions/xnubsd/netinet/tcp_var.hstruct tcpcb — every TCP connection's complete kernel-side state.View on GitHub(line ) apple-oss-distributions/xnubsd/netinet/tcp_subr.ctcpcb allocation, lookup, and helper functions.View on GitHub(line )

The per-connection lock is XNU's chosen concurrency model — different connections can be processed in parallel on different CPUs as long as their tcpcbs are independently locked. Hashing-based NIC steering helps spread the load.

State transitions happen in:

  • tcp_input — receive path.
  • tcp_output — send path, retransmits.
  • tcp_timer — timeouts.

See also: mbuf, and the TCP internals article.