<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Handshake · XB Field Notes</title><link>https://hk.xbcatm.com/tags/handshake/</link><description>Illustrated field notes on HTTP, DNS, TLS, Caddy, SSH, releases, and recovery.</description><generator>Hugo</generator><language>en-us</language><atom:link href="https://hk.xbcatm.com/tags/handshake/index.xml" rel="self" type="application/rss+xml"/><item><title>SYN cookies answer when the queue overflows</title><link>https://hk.xbcatm.com/posts/tcp-syn-cookies-when-syns-overflow/</link><pubDate>Sat, 30 Oct 2027 00:00:00 +0000</pubDate><guid>https://hk.xbcatm.com/posts/tcp-syn-cookies-when-syns-overflow/</guid><description>SYN cookies reduce retained pending-request state; established connections still need admission and application capacity.</description><content:encoded>&lt;p&gt;A Linux TCP listener distinguishes pending handshake requests from established connections waiting for &lt;code&gt;accept()&lt;/code&gt;. These are commonly called the SYN queue and accept queue. Their capacity limits and overflow paths differ, so diagnosing a connection failure requires identifying which stage is under pressure.&lt;/p&gt;
&lt;p&gt;SYN cookies reduce retained per-request state while a handshake is incomplete. The server encodes recoverable information in its SYN-ACK and reconstructs connection state after a valid reply. This saves pending-request memory; it does not make processing free, remove established-connection state, or guarantee admission and normal application performance.&lt;/p&gt;
&lt;figure class="technical-diagram"&gt;&lt;img loading="lazy" src="https://hk.xbcatm.com/visuals/posts-tcp-syn-cookies-when-syns-overflow.detail.en.svg" alt="The SYN queue concerns pending handshakes; the accept queue holds established connections. A client sends SYN, receives a SYN-ACK carrying a cookie in the sequence number, and sends an ACK for verification. A valid cookie still needs connection admission. Established connections still wait for application accept(); cookies do not add acceptance or processing capacity." width="720" height="2310"&gt;&lt;figcaption&gt;SYN cookies concern the handshake. Verification does not bypass the accept queue or increase application acceptance capacity.&lt;/figcaption&gt;&lt;/figure&gt;
&lt;h2 id="two-queues-two-different-symptoms"&gt;Two queues, two different symptoms&lt;/h2&gt;
&lt;p&gt;On the ordinary stateful path, the listener remembers a request while awaiting the final ACK. Linux documents &lt;code&gt;tcp_max_syn_backlog&lt;/code&gt; as a per-listener limit on remembered requests; the documented memory-dependent default and request-size estimate are not universal allocation measurements. The application&amp;rsquo;s &lt;code&gt;listen()&lt;/code&gt; backlog, capped by &lt;code&gt;somaxconn&lt;/code&gt;, bounds established connections waiting for acceptance. Linux has defaulted &lt;code&gt;somaxconn&lt;/code&gt; to 4096 since 5.4; actual settings can differ.&lt;/p&gt;
&lt;p&gt;Cookies can help when pending-handshake state is exhausted, but do not guarantee connection completion. A full accept queue can prevent creation or admission of the established child. With &lt;code&gt;tcp_abort_on_overflow=0&lt;/code&gt;, some stateful paths ignore the ACK and retain the pending request, allowing later recovery. A client may already report connect success; other attempts may time out. The earlier 400-client account is not reproduced or bound to retained raw results in this review, so it cannot establish an exact loss count.&lt;/p&gt;
&lt;h2 id="the-cookie-is-the-state-you-refused-to-store"&gt;The cookie is the state you refused to store&lt;/h2&gt;
&lt;p&gt;Linux mode 1 uses cookies as an overflow fallback when CONFIG_SYN_COOKIES is enabled; mode 2 generates them unconditionally for testing. In the pinned Linux 6.12 IPv4 implementation, the sequence number combines keyed hashes, the client initial sequence number, a time counter and an MSS-table index. The raw high bits of the returned acknowledgment are not simply a readable counter.&lt;/p&gt;
&lt;p&gt;That implementation advances its counter every sixty seconds and accepts only the current or preceding counter slot before further validation. A seventy-second-old cookie can cross two boundaries and fail; elapsed time alone does not fix the outcome. Validation also binds connection fields and checks the recovered index. These checks resist blind spoofing but provide neither application authentication nor a universal one-in-2²⁴ security guarantee.&lt;/p&gt;
&lt;h2 id="what-a-cookie-cannot-carry"&gt;What a cookie cannot carry&lt;/h2&gt;
&lt;p&gt;Option support depends on the implementation and handshake. Linux 6.12 can encode window-scale, SACK and ECN information in timestamp bits and recover it from the timestamp echo. Without that timestamp path, options can be lost. The documentation warns about extension and performance limitations, but does not justify saying every cookie SYN-ACK has no options or every admitted connection is slower.&lt;/p&gt;
&lt;p&gt;The pinned IPv4 implementation chooses among four MSS-table entries, rather than preserving an arbitrary advertisement exactly. If scaling is absent, a 65535-byte receive window can constrain a long-RTT transfer; that is a conditional window limit, not measured cookie-mode throughput. Missing SACK changes recovery information without forcing retransmission of every later segment. Capture the actual options before attributing a slowdown to cookies.&lt;/p&gt;
&lt;h2 id="when-it-breaks"&gt;When it breaks&lt;/h2&gt;
&lt;p&gt;Cookies can reduce visible pending-request depth while pressure continues. Monitor changes in &lt;code&gt;SyncookiesSent&lt;/code&gt; alongside queue occupancy, connection attempts, CPU load, warnings and application outcomes. A rising counter is not proof of an attack: legitimate overload or unconditional test mode can also produce cookies. Application failures remain possible and useful evidence; cookies do not make all flooding invisible.&lt;/p&gt;
&lt;p&gt;Cookies do not add accept-queue or application-processing capacity. Investigate &lt;code&gt;ListenOverflows&lt;/code&gt;, acceptance rate and resource limits together before choosing a remedy. A larger backlog absorbs some bursts but does not increase sustained processing capacity. Faster acceptance or additional workers helps only when that stage is the bottleneck; changing cookie mode does not repair a stalled application.&lt;/p&gt;
&lt;h2 id="check-it-quickly"&gt;Check it quickly&lt;/h2&gt;
&lt;p&gt;These read-only Linux commands inspect configuration, cumulative counters and listening queues; they do not reproduce a flood, validate cookies or measure packet delivery:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;sysctl net.ipv4.tcp_syncookies net.ipv4.tcp_max_syn_backlog net.core.somaxconn
nstat -az | grep -E &amp;#39;Syncookies|ListenOverflow|ListenDrops&amp;#39;
ss -lnt
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Take comparable snapshots in the relevant network namespace and examine deltas. A healthy current service can have nonzero historical counters, and a brief nonempty accept queue is normal. For a listening TCP socket, &lt;code&gt;Recv-Q&lt;/code&gt; shows established connections waiting for &lt;code&gt;accept()&lt;/code&gt; and &lt;code&gt;Send-Q&lt;/code&gt; the backlog limit. Sustained occupancy near that limit, new overflows and request failures together are stronger evidence of acceptance pressure than any single total.&lt;/p&gt;
&lt;h2 id="sources"&gt;Sources&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.rfc-editor.org/rfc/rfc4987.html"&gt;RFC 4987 TCP SYN flood mitigation&lt;/a&gt;, the cookie construction and its trade-offs, checked 2026-09-16.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.rfc-editor.org/rfc/rfc9293.html"&gt;RFC 9293 TCP&lt;/a&gt;, the three-way handshake and the notion of a backlog, checked 2026-09-16.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.kernel.org/networking/ip-sysctl.html"&gt;Linux kernel ip-sysctl&lt;/a&gt;, tcp_syncookies, tcp_max_syn_backlog, somaxconn and tcp_abort_on_overflow, checked 2026-09-16.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://raw.githubusercontent.com/torvalds/linux/v6.12/net/ipv4/syncookies.c"&gt;Linux 6.12 IPv4 SYN cookies&lt;/a&gt;, keyed cookie construction, MSS table and timestamp-carried options, checked 2026-10-19.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://raw.githubusercontent.com/torvalds/linux/v6.12/include/net/tcp.h"&gt;Linux 6.12 TCP cookie timing&lt;/a&gt;, sixty-second counter and two-slot age test, checked 2026-10-19.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/torvalds/linux/blob/v6.12/net/ipv4/tcp_minisocks.c"&gt;Linux 6.12 pending request handling&lt;/a&gt;, conditional overflow handling and retained requests, checked 2026-10-19.&lt;/li&gt;
&lt;/ul&gt;</content:encoded></item></channel></rss>