#tcp-three-way-handshake
Describe the TCP three-way handshake. What is in each packet?
Что отвечать
The client sends a SYN with its ISN (initial sequence number). The server replies with SYN-ACK: it acknowledges the client's ISN+1 and sends its own ISN. The client replies with an ACK for the server's ISN+1. After three packets both sides know each other's starting sequence numbers, and the connection is Established.
Что хотят услышать
A senior should say: - the ISN is chosen at random (not zero) to avoid predictability and hijacking attacks - in the SYN packet the client announces its options: MSS, window scale, SACK permitted, timestamp - the server's SYN-ACK carries its options too; the final choice is the intersection - after the handshake comes slow start: cwnd grows from the initial congestion window (10 segments on modern Linux) exponentially up to ssthresh - if a SYN is lost, there is an exponential backoff retry (1s, 2s, 4s, and so on), controlled by `net.ipv4.tcp_syn_retries`
Подводные камни
- ✗ Saying the handshake is 3 RTT. No, it is 1 RTT (3 packets, but the client can send data with the third ACK through TCP Fast Open).
- ✗ Forgetting the options in the SYN, which matter for understanding tuning.
- ✗ Confusing SYN-flood protection with SYN cookies. SYN cookies build the server ISN from a hash of the 4-tuple plus a secret, so there is no half-open state to hold.
Follow-up
- ? What is TCP Fast Open, and why did it never see wide adoption?
- ? How do SYN cookies work, and why are they turned on only under attack rather than by default?
- ? What does a SYN-ACK carry beyond the ISN acknowledgment?
Глубина в базе знаний