xref: /freebsd/share/man/man4/syncache.4 (revision 4548510be1249b1886945d1ce09cde681b7f94b4)
1298aa4e5SRuslan Ermilov.\"
2298aa4e5SRuslan Ermilov.\" syncache - TCP SYN caching to handle SYN flood DoS.
3298aa4e5SRuslan Ermilov.\"
4298aa4e5SRuslan Ermilov.\" Redistribution and use in source and binary forms, with or without
5298aa4e5SRuslan Ermilov.\" modification, are permitted provided that the following conditions
6298aa4e5SRuslan Ermilov.\" are met:
7298aa4e5SRuslan Ermilov.\" 1. Redistributions of source code must retain the above copyright
8298aa4e5SRuslan Ermilov.\"    notice, this list of conditions and the following disclaimer.
9298aa4e5SRuslan Ermilov.\" 2. Redistributions in binary form must reproduce the above copyright
10298aa4e5SRuslan Ermilov.\"    notice, this list of conditions and the following disclaimer in the
11298aa4e5SRuslan Ermilov.\"    documentation and/or other materials provided with the distribution.
12298aa4e5SRuslan Ermilov.\"
13298aa4e5SRuslan Ermilov.\" $FreeBSD$
14298aa4e5SRuslan Ermilov.\"
15298aa4e5SRuslan Ermilov.Dd August 31, 2001
16298aa4e5SRuslan Ermilov.Dt SYNCACHE 4
17298aa4e5SRuslan Ermilov.Os
18298aa4e5SRuslan Ermilov.Sh NAME
19298aa4e5SRuslan Ermilov.Nm syncache , syncookies
20298aa4e5SRuslan Ermilov.Nd
21298aa4e5SRuslan Ermilov.Xr sysctl 8
22298aa4e5SRuslan ErmilovMIBs for controlling TCP SYN caching
23298aa4e5SRuslan Ermilov.Sh SYNOPSIS
24298aa4e5SRuslan Ermilov.Bl -item -compact
25298aa4e5SRuslan Ermilov.It
26298aa4e5SRuslan Ermilov.Nm sysctl Cm net.inet.tcp.syncookies
27298aa4e5SRuslan Ermilov.El
28298aa4e5SRuslan Ermilov.Pp
29298aa4e5SRuslan Ermilov.Bl -item -compact
30298aa4e5SRuslan Ermilov.It
31298aa4e5SRuslan Ermilov.Nm sysctl Cm net.inet.tcp.syncache.hashsize
32298aa4e5SRuslan Ermilov.It
33298aa4e5SRuslan Ermilov.Nm sysctl Cm net.inet.tcp.syncache.bucketlimit
34298aa4e5SRuslan Ermilov.It
35298aa4e5SRuslan Ermilov.Nm sysctl Cm net.inet.tcp.syncache.cachelimit
36298aa4e5SRuslan Ermilov.It
37298aa4e5SRuslan Ermilov.Nm sysctl Cm net.inet.tcp.syncache.rexmtlimit
38298aa4e5SRuslan Ermilov.It
39298aa4e5SRuslan Ermilov.Nm sysctl Cm net.inet.tcp.syncache.count
40298aa4e5SRuslan Ermilov.El
41298aa4e5SRuslan Ermilov.Sh DESCRIPTION
42298aa4e5SRuslan ErmilovThe
43298aa4e5SRuslan Ermilov.Nm
44298aa4e5SRuslan Ermilov.Xr sysctl 8
45298aa4e5SRuslan ErmilovMIB is used to control the TCP SYN caching in the system, which
46298aa4e5SRuslan Ermilovis intended to handle SYN flood Denial of Service attacks.
47298aa4e5SRuslan Ermilov.Pp
48298aa4e5SRuslan ErmilovWhen a TCP SYN segment is received on a port corresponding to a listen
49298aa4e5SRuslan Ermilovsocket, an entry is made in the
50298aa4e5SRuslan Ermilov.Nm ,
51298aa4e5SRuslan Ermilovand a SYN,ACK segment is
52298aa4e5SRuslan Ermilovreturned to the peer.
53298aa4e5SRuslan ErmilovThe
54298aa4e5SRuslan Ermilov.Nm
55298aa4e5SRuslan Ermiloventry holds the TCP options from the initial SYN,
56298aa4e5SRuslan Ermilovenough state to perform a SYN,ACK retransmission, and takes up less
57298aa4e5SRuslan Ermilovspace than a TCP control block endpoint.
58298aa4e5SRuslan ErmilovAn incoming segment which contains an ACK for the SYN,ACK
59298aa4e5SRuslan Ermilovand matches a
60298aa4e5SRuslan Ermilov.Nm
61298aa4e5SRuslan Ermiloventry will cause the system to create a TCP control block
62298aa4e5SRuslan Ermilovwith the options stored in the
63298aa4e5SRuslan Ermilov.Nm
64298aa4e5SRuslan Ermiloventry, which is then released.
65298aa4e5SRuslan Ermilov.Pp
66298aa4e5SRuslan ErmilovThe
67298aa4e5SRuslan Ermilov.Nm
68298aa4e5SRuslan Ermilovprotects the system from SYN flood DoS attacks by minimizing
69298aa4e5SRuslan Ermilovthe amount of state kept on the server, and by limiting the overall size
70298aa4e5SRuslan Ermilovof the
71298aa4e5SRuslan Ermilov.Nm .
72298aa4e5SRuslan Ermilov.Pp
73298aa4e5SRuslan Ermilov.Nm Syncookies
74298aa4e5SRuslan Ermilovprovides a way to virtually expand the size of the
75298aa4e5SRuslan Ermilov.Nm
76298aa4e5SRuslan Ermilovby keeping state regarding the initial SYN in the network.
77298aa4e5SRuslan ErmilovEnabling
78298aa4e5SRuslan Ermilov.Nm syncookies
79298aa4e5SRuslan Ermilovsends a cryptographic value in the SYN,ACK reply to
80298aa4e5SRuslan Ermilovthe client machine, which is then returned in the client's ACK.
81298aa4e5SRuslan ErmilovIf the corresponding entry is not found in the
82298aa4e5SRuslan Ermilov.Nm ,
83298aa4e5SRuslan Ermilovbut the value
84298aa4e5SRuslan Ermilovpasses specific security checks, the connection will be accepted.
85298aa4e5SRuslan ErmilovThis is only used if the
86298aa4e5SRuslan Ermilov.Nm
87298aa4e5SRuslan Ermilovis unable to handle the volume of
88298aa4e5SRuslan Ermilovincoming connections, and a prior entry has been evicted from the cache.
89298aa4e5SRuslan Ermilov.Pp
90298aa4e5SRuslan Ermilov.Nm Syncookies
91298aa4e5SRuslan Ermilovhave a certain number of disadvantages that a paranoid
92298aa4e5SRuslan Ermilovadministrator may wish to take note of.
93298aa4e5SRuslan ErmilovSince the TCP options from the initial SYN are not saved, they are not
94298aa4e5SRuslan Ermilovapplied to the connection, precluding use of features like window scale,
95298aa4e5SRuslan Ermilovtimestamps, or exact MSS sizing.
96298aa4e5SRuslan ErmilovAs the returning ACK establishes the connection, it may be possible for
97298aa4e5SRuslan Ermilovan attacker to ACK flood a machine in an attempt to create a connection.
984548510bSChristian BruefferWhile steps have been taken to mitigate this risk, this may provide a way
99298aa4e5SRuslan Ermilovto bypass firewalls which filter incoming segments with the SYN bit set.
100298aa4e5SRuslan Ermilov.Pp
101298aa4e5SRuslan ErmilovThe
102298aa4e5SRuslan Ermilov.Nm
103298aa4e5SRuslan Ermilovimplements a number of variables in
104298aa4e5SRuslan Ermilovthe
105298aa4e5SRuslan Ermilov.Va net.inet.tcp.syncache
106298aa4e5SRuslan Ermilovbranch of the
107298aa4e5SRuslan Ermilov.Xr sysctl 3
108298aa4e5SRuslan ErmilovMIB.
109298aa4e5SRuslan ErmilovSeveral of these may be tuned by setting the corresponding
110298aa4e5SRuslan Ermilovvariable in the
111298aa4e5SRuslan Ermilov.Xr loader 8 .
112298aa4e5SRuslan Ermilov.Bl -tag -width ".Va bucketlimit"
113298aa4e5SRuslan Ermilov.It Va hashsize
114298aa4e5SRuslan ErmilovSize of the
115298aa4e5SRuslan Ermilov.Nm
116298aa4e5SRuslan Ermilovhash table, must be a power of 2.
117298aa4e5SRuslan ErmilovRead-only, tunable via
118298aa4e5SRuslan Ermilov.Xr loader 8 .
119298aa4e5SRuslan Ermilov.It Va bucketlimit
120298aa4e5SRuslan ErmilovLimit on the number of entries permitted in each bucket of the hash table.
121298aa4e5SRuslan ErmilovThis should be left at a low value to minimize search time.
122298aa4e5SRuslan ErmilovRead-only, tunable via
123298aa4e5SRuslan Ermilov.Xr loader 8 .
124298aa4e5SRuslan Ermilov.It Va cachelimit
125298aa4e5SRuslan ErmilovLimit on the total number of entries in the
126298aa4e5SRuslan Ermilov.Nm .
127298aa4e5SRuslan ErmilovDefaults to
128298aa4e5SRuslan Ermilov.Va ( hashsize No \(mu Va bucketlimit ) ,
129298aa4e5SRuslan Ermilovmay be set lower to minimize memory
130298aa4e5SRuslan Ermilovconsumption.
131298aa4e5SRuslan ErmilovRead-only, tunable via
132298aa4e5SRuslan Ermilov.Xr loader 8 .
133298aa4e5SRuslan Ermilov.It Va rexmtlimit
134298aa4e5SRuslan ErmilovMaximum number of times a SYN,ACK is retransmitted before being discarded.
135298aa4e5SRuslan ErmilovThe default of 3 retransmits corresponds to a 15 second timeout, this value
136298aa4e5SRuslan Ermilovmay be increased depending on the RTT to client machines.
137298aa4e5SRuslan ErmilovTunable via
138298aa4e5SRuslan Ermilov.Xr sysctl 3 .
139298aa4e5SRuslan Ermilov.It Va count
140298aa4e5SRuslan ErmilovNumber of entries present in the
141298aa4e5SRuslan Ermilov.Nm
142298aa4e5SRuslan Ermilov(read-only).
143298aa4e5SRuslan Ermilov.El
144298aa4e5SRuslan Ermilov.Pp
145298aa4e5SRuslan ErmilovStatistics on the performance of the
146298aa4e5SRuslan Ermilov.Nm
147298aa4e5SRuslan Ermilovmay be obtained via
148298aa4e5SRuslan Ermilov.Xr netstat 1 ,
149298aa4e5SRuslan Ermilovwhich provides the following counts:
150298aa4e5SRuslan Ermilov.Bl -tag -width ".Li cookies received"
151298aa4e5SRuslan Ermilov.It Li "syncache entries added"
152298aa4e5SRuslan ErmilovEntries successfully inserted in the
153298aa4e5SRuslan Ermilov.Nm .
154298aa4e5SRuslan Ermilov.It Li retransmitted
155298aa4e5SRuslan ErmilovSYN,ACK retransmissions due to a timeout expiring.
156298aa4e5SRuslan Ermilov.It Li dupsyn
157298aa4e5SRuslan ErmilovIncoming SYN segment matching an existing entry.
158298aa4e5SRuslan Ermilov.It Li dropped
159298aa4e5SRuslan ErmilovSYNs dropped because SYN,ACK could not be sent.
160298aa4e5SRuslan Ermilov.It Li completed
161298aa4e5SRuslan ErmilovSuccessfully completed connections.
162298aa4e5SRuslan Ermilov.It Li "bucket overflow"
163298aa4e5SRuslan ErmilovEntries dropped for exceeding per-bucket size.
164298aa4e5SRuslan Ermilov.It Li "cache overflow"
165298aa4e5SRuslan ErmilovEntries dropped for exceeding overall cache size.
166298aa4e5SRuslan Ermilov.It Li reset
167298aa4e5SRuslan ErmilovRST segment received.
168298aa4e5SRuslan Ermilov.It Li stale
169298aa4e5SRuslan ErmilovEntries dropped due to maximum retransmissions or listen socket disappearance.
170298aa4e5SRuslan Ermilov.It Li aborted
171298aa4e5SRuslan ErmilovNew socket allocation failures.
172298aa4e5SRuslan Ermilov.It Li badack
173298aa4e5SRuslan ErmilovEntries dropped due to bad ACK reply.
174298aa4e5SRuslan Ermilov.It Li unreach
175298aa4e5SRuslan ErmilovEntries dropped due to ICMP unreachable messages.
176298aa4e5SRuslan Ermilov.It Li "zone failures"
177298aa4e5SRuslan ErmilovFailures to allocate new
178298aa4e5SRuslan Ermilov.Nm
179298aa4e5SRuslan Ermiloventry.
180298aa4e5SRuslan Ermilov.It Li "cookies received"
181298aa4e5SRuslan ErmilovConnections created from segment containing ACK.
182298aa4e5SRuslan Ermilov.El
183298aa4e5SRuslan Ermilov.Sh SEE ALSO
184298aa4e5SRuslan Ermilov.Xr netstat 1 ,
185298aa4e5SRuslan Ermilov.Xr tcp 4 ,
186298aa4e5SRuslan Ermilov.Xr loader 8 ,
187298aa4e5SRuslan Ermilov.Xr sysctl 8
188298aa4e5SRuslan Ermilov.Sh HISTORY
189298aa4e5SRuslan ErmilovThe existing
190298aa4e5SRuslan Ermilov.Nm
191298aa4e5SRuslan Ermilovimplementation
192298aa4e5SRuslan Ermilovfirst appeared in
193298aa4e5SRuslan Ermilov.Fx 4.5 .
194298aa4e5SRuslan ErmilovThe original concept of a
195298aa4e5SRuslan Ermilov.Nm
196298aa4e5SRuslan Ermilovoriginally appeared in
197298aa4e5SRuslan Ermilov.Bsx ,
198298aa4e5SRuslan Ermilovand was later modified by
199298aa4e5SRuslan Ermilov.Nx ,
200298aa4e5SRuslan Ermilovthen further extended here.
201298aa4e5SRuslan Ermilov.Sh AUTHORS
202298aa4e5SRuslan ErmilovThe
203298aa4e5SRuslan Ermilov.Nm
204298aa4e5SRuslan Ermilovcode and manual page were written by
205298aa4e5SRuslan Ermilov.An Jonathan Lemon Aq jlemon@FreeBSD.org .
206