TCP

Transmission Control Protocol provides reliable, ordered, error-checked segments in IP datagrams. Segment structure:

Source Port (16-bit)Destination Port (16-bit)Sequence Number (32-bit)Acknowledge Number (32-bit)Data Offset (4-bit)Reserved (3-bit)Flags (9 bits)Window Size (16-bit)Checksum (16-bit)Urgent Pointer (16-bit)Options Payload

TCP Flags

Checksum is computed similar to UDP using pseudo-header.

Windows size controls how much data can be sent unacknowledged, i.e. the sender will keep sending data even though the ack segments have not been received yet for the previously sent segments. There are two window sizes in TCP:

Modern TCP implementations use 4 algorithms: slow-start, congestion avoidance, fast retransmit and fast recovery (RFC 5681).

Slow-start initially sets the congestion window size to 1, 2 or 10 of the Maximum Segment Size (MSS) and then increases it by 1 MSS with each ack. The CWND increase may not be exactly exponential, because the receiver may sends its ack for every second segment. The CWND increase carries on until either a packet loss is detected, or RWND limit is reached, or the slow start threshold (ssthresh) is reached. In case of a loss, the behavior depends on the TCP congestion avoidance algorithm. Once ssthresh is reached, the rate of CWND change becomes linear - it increases by 1 MSS for each round-trip time (RTT).

Fast Retransmit uses typically 4 duplicate acknowledgements to assume that the packet was lost and will not arrive out-of-order and retransmits it before the retransmission’s timer times out.

TCP vulnerabilities

The obvious protection for all kinds of TCP vulnerabilities is to use IPSec.