SYNCACHE(4)

πŸ’– SYNCACHE(4) πŸ’–

okay bestie, pull up a chair because we're talking about syncache and syncookies β€” the sysctl(8) MIBs that let you control TCP SYN caching in the system. this is the Kernel Interfaces Manual page, and honestly? it's giving "the internet's bouncer at the door." let's go 🫢


✨ NAME ✨

syncache, syncookies β€” the sysctl(8) MIBs for controlling TCP SYN caching. periodt. πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

sysctl net.inet.tcp.syncookies
sysctl net.inet.tcp.syncookies_only

sysctl net.inet.tcp.syncache.hashsize
sysctl net.inet.tcp.syncache.bucketlimit
sysctl net.inet.tcp.syncache.cachelimit
sysctl net.inet.tcp.syncache.rexmtlimit
sysctl net.inet.tcp.syncache.count

🌸 DESCRIPTION 🌸

so the syncache sysctl(8) MIB is literally the control panel for TCP SYN caching in the system, and its whole entire job is handling SYN flood Denial of Service attacks. main character energy, honestly. πŸ‘‘

here's the vibe: when a TCP SYN segment shows up on a port that corresponds to a listen socket, an entry gets made in the syncache, and a SYN,ACK segment gets sent right back to the peer. that syncache entry is holding the TCP options from the initial SYN, plus enough state to do a SYN,ACK retransmission, and it takes up less space than a TCP control block endpoint. tiny but mighty ✨. then, if an incoming segment contains an ACK for the SYN,ACK and it matches a syncache entry, the system goes ahead and creates a TCP control block using the options stored in that syncache entry β€” and the entry is then released. bye bestie πŸ¦‹

the syncache protects the system from SYN flood DoS attacks by minimizing the amount of state kept on the server, and by limiting the overall size of the syncache. no cap.

syncookies is the little trick that virtually expands the size of the syncache by keeping state regarding the initial SYN in the network. enabling syncookies sends a cryptographic value in the SYN,ACK reply to the client machine, and that value comes right back in the client's ACK. if the corresponding entry isn't found in the syncache but the value passes specific security checks, the connection gets accepted. this is only used if the syncache is unable to handle the volume of incoming connections, and a prior entry has been evicted from the cache.

⚠️ okay so syncookies has a certain number of disadvantages that a paranoid administrator may wish to take note of. since the TCP options from the initial SYN are not saved, they are not applied to the connection β€” which precludes use of features like window scale, timestamps, or exact MSS sizing. and because the returning ACK establishes the connection, it may be possible for an attacker to ACK flood a machine in an attempt to create a connection. while steps have been taken to mitigate this risk, this may provide a way to bypass firewalls which filter incoming segments with the SYN bit set. 😭

to disable the syncache and run only with syncookies, set net.inet.tcp.syncookies_only to 1.


🧚 the syncache variables 🧚

the syncache implements a number of variables in the net.inet.tcp.syncache branch of the sysctl(3) MIB. several of these may be tuned by setting the corresponding variable in the loader(8).

  • hashsize β€” size of the syncache hash table, must be a power of 2. read-only, tunable via loader(8).
  • bucketlimit β€” limit on the number of entries permitted in each bucket of the hash table. this should be left at a low value to minimize search time. read-only, tunable via loader(8).
  • cachelimit β€” limit on the total number of entries in the syncache. defaults to (hashsize Γ— bucketlimit), and may be set lower to minimize memory consumption. read-only, tunable via loader(8).
  • rexmtlimit β€” maximum number of times a SYN,ACK is retransmitted before being discarded. the default of 3 retransmits corresponds to a 45 second timeout, and this value may be increased depending on the RTT to client machines. tunable via sysctl(3).
  • count β€” number of entries present in the syncache (read-only).

πŸ“Š the netstat(1) stats πŸ“Š

statistics on the performance of the syncache may be obtained via netstat(1), which provides the following counts:

  • syncache entries added β€” entries successfully inserted in the syncache.
  • retransmitted β€” SYN,ACK retransmissions due to a timeout expiring.
  • dupsyn β€” incoming SYN segment matching an existing entry.
  • dropped β€” SYNs dropped because SYN,ACK could not be sent.
  • completed β€” successfully completed connections.
  • bucket overflow β€” entries dropped for exceeding per-bucket size.
  • cache overflow β€” entries dropped for exceeding overall cache size.
  • reset β€” RST segment received.
  • stale β€” entries dropped due to maximum retransmissions or listen socket disappearance.
  • aborted β€” new socket allocation failures.
  • badack β€” entries dropped due to bad ACK reply.
  • unreach β€” entries dropped due to ICMP unreachable messages.
  • zone failures β€” failures to allocate new syncache entry.
  • cookies received β€” connections created from segment containing ACK.

🌈 SEE ALSO 🌈

netstat(1), tcp(4), loader(8), sysctl(8)


πŸ’œ HISTORY πŸ’œ

the existing syncache implementation first appeared in FreeBSD 4.5. the original concept of a syncache originally appeared in BSD/OS, and was later modified by NetBSD, then further extended here. glow-up after glow-up, fr fr. ⭐


πŸ‘‘ AUTHORS πŸ‘‘

the syncache code and manual page were written by Jonathan Lemon <jlemon@FreeBSD.org>.


and that's the whole page bestie, you ate that πŸ“ β€” this one's from the Debian distribution, dated January 22, 2008, and it's the SYNCACHE(4) page. mwah πŸ’‹ go forth and tune your hash tables responsibly. πŸŽ€πŸ’–

πŸ“¦ where this page comes from