xref: /freebsd/share/man/man4/syncache.4 (revision 298aa4e5fa88df3ad8eaf50aca3daac20450ea6f)
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 ErmilovTransaction TCP accelerated opens (see
74298aa4e5SRuslan Ermilov.Xr ttcp 4 )
75298aa4e5SRuslan Ermilovare also supported, and bypass the
76298aa4e5SRuslan Ermilov.Nm .
77298aa4e5SRuslan Ermilov.Pp
78298aa4e5SRuslan Ermilov.Nm Syncookies
79298aa4e5SRuslan Ermilovprovides a way to virtually expand the size of the
80298aa4e5SRuslan Ermilov.Nm
81298aa4e5SRuslan Ermilovby keeping state regarding the initial SYN in the network.
82298aa4e5SRuslan ErmilovEnabling
83298aa4e5SRuslan Ermilov.Nm syncookies
84298aa4e5SRuslan Ermilovsends a cryptographic value in the SYN,ACK reply to
85298aa4e5SRuslan Ermilovthe client machine, which is then returned in the client's ACK.
86298aa4e5SRuslan ErmilovIf the corresponding entry is not found in the
87298aa4e5SRuslan Ermilov.Nm ,
88298aa4e5SRuslan Ermilovbut the value
89298aa4e5SRuslan Ermilovpasses specific security checks, the connection will be accepted.
90298aa4e5SRuslan ErmilovThis is only used if the
91298aa4e5SRuslan Ermilov.Nm
92298aa4e5SRuslan Ermilovis unable to handle the volume of
93298aa4e5SRuslan Ermilovincoming connections, and a prior entry has been evicted from the cache.
94298aa4e5SRuslan Ermilov.Pp
95298aa4e5SRuslan Ermilov.Nm Syncookies
96298aa4e5SRuslan Ermilovhave a certain number of disadvantages that a paranoid
97298aa4e5SRuslan Ermilovadministrator may wish to take note of.
98298aa4e5SRuslan ErmilovSince the TCP options from the initial SYN are not saved, they are not
99298aa4e5SRuslan Ermilovapplied to the connection, precluding use of features like window scale,
100298aa4e5SRuslan Ermilovtimestamps, or exact MSS sizing.
101298aa4e5SRuslan ErmilovAs the returning ACK establishes the connection, it may be possible for
102298aa4e5SRuslan Ermilovan attacker to ACK flood a machine in an attempt to create a connection.
103298aa4e5SRuslan ErmilovWhile steps have been taken to militate this risk, this may provide a way
104298aa4e5SRuslan Ermilovto bypass firewalls which filter incoming segments with the SYN bit set.
105298aa4e5SRuslan Ermilov.Pp
106298aa4e5SRuslan ErmilovThe
107298aa4e5SRuslan Ermilov.Nm
108298aa4e5SRuslan Ermilovimplements a number of variables in
109298aa4e5SRuslan Ermilovthe
110298aa4e5SRuslan Ermilov.Va net.inet.tcp.syncache
111298aa4e5SRuslan Ermilovbranch of the
112298aa4e5SRuslan Ermilov.Xr sysctl 3
113298aa4e5SRuslan ErmilovMIB.
114298aa4e5SRuslan ErmilovSeveral of these may be tuned by setting the corresponding
115298aa4e5SRuslan Ermilovvariable in the
116298aa4e5SRuslan Ermilov.Xr loader 8 .
117298aa4e5SRuslan Ermilov.Bl -tag -width ".Va bucketlimit"
118298aa4e5SRuslan Ermilov.It Va hashsize
119298aa4e5SRuslan ErmilovSize of the
120298aa4e5SRuslan Ermilov.Nm
121298aa4e5SRuslan Ermilovhash table, must be a power of 2.
122298aa4e5SRuslan ErmilovRead-only, tunable via
123298aa4e5SRuslan Ermilov.Xr loader 8 .
124298aa4e5SRuslan Ermilov.It Va bucketlimit
125298aa4e5SRuslan ErmilovLimit on the number of entries permitted in each bucket of the hash table.
126298aa4e5SRuslan ErmilovThis should be left at a low value to minimize search time.
127298aa4e5SRuslan ErmilovRead-only, tunable via
128298aa4e5SRuslan Ermilov.Xr loader 8 .
129298aa4e5SRuslan Ermilov.It Va cachelimit
130298aa4e5SRuslan ErmilovLimit on the total number of entries in the
131298aa4e5SRuslan Ermilov.Nm .
132298aa4e5SRuslan ErmilovDefaults to
133298aa4e5SRuslan Ermilov.Va ( hashsize No \(mu Va bucketlimit ) ,
134298aa4e5SRuslan Ermilovmay be set lower to minimize memory
135298aa4e5SRuslan Ermilovconsumption.
136298aa4e5SRuslan ErmilovRead-only, tunable via
137298aa4e5SRuslan Ermilov.Xr loader 8 .
138298aa4e5SRuslan Ermilov.It Va rexmtlimit
139298aa4e5SRuslan ErmilovMaximum number of times a SYN,ACK is retransmitted before being discarded.
140298aa4e5SRuslan ErmilovThe default of 3 retransmits corresponds to a 15 second timeout, this value
141298aa4e5SRuslan Ermilovmay be increased depending on the RTT to client machines.
142298aa4e5SRuslan ErmilovTunable via
143298aa4e5SRuslan Ermilov.Xr sysctl 3 .
144298aa4e5SRuslan Ermilov.It Va count
145298aa4e5SRuslan ErmilovNumber of entries present in the
146298aa4e5SRuslan Ermilov.Nm
147298aa4e5SRuslan Ermilov(read-only).
148298aa4e5SRuslan Ermilov.El
149298aa4e5SRuslan Ermilov.Pp
150298aa4e5SRuslan ErmilovStatistics on the performance of the
151298aa4e5SRuslan Ermilov.Nm
152298aa4e5SRuslan Ermilovmay be obtained via
153298aa4e5SRuslan Ermilov.Xr netstat 1 ,
154298aa4e5SRuslan Ermilovwhich provides the following counts:
155298aa4e5SRuslan Ermilov.Bl -tag -width ".Li cookies received"
156298aa4e5SRuslan Ermilov.It Li "syncache entries added"
157298aa4e5SRuslan ErmilovEntries successfully inserted in the
158298aa4e5SRuslan Ermilov.Nm .
159298aa4e5SRuslan Ermilov.It Li retransmitted
160298aa4e5SRuslan ErmilovSYN,ACK retransmissions due to a timeout expiring.
161298aa4e5SRuslan Ermilov.It Li dupsyn
162298aa4e5SRuslan ErmilovIncoming SYN segment matching an existing entry.
163298aa4e5SRuslan Ermilov.It Li dropped
164298aa4e5SRuslan ErmilovSYNs dropped because SYN,ACK could not be sent.
165298aa4e5SRuslan Ermilov.It Li completed
166298aa4e5SRuslan ErmilovSuccessfully completed connections.
167298aa4e5SRuslan Ermilov.It Li "bucket overflow"
168298aa4e5SRuslan ErmilovEntries dropped for exceeding per-bucket size.
169298aa4e5SRuslan Ermilov.It Li "cache overflow"
170298aa4e5SRuslan ErmilovEntries dropped for exceeding overall cache size.
171298aa4e5SRuslan Ermilov.It Li reset
172298aa4e5SRuslan ErmilovRST segment received.
173298aa4e5SRuslan Ermilov.It Li stale
174298aa4e5SRuslan ErmilovEntries dropped due to maximum retransmissions or listen socket disappearance.
175298aa4e5SRuslan Ermilov.It Li aborted
176298aa4e5SRuslan ErmilovNew socket allocation failures.
177298aa4e5SRuslan Ermilov.It Li badack
178298aa4e5SRuslan ErmilovEntries dropped due to bad ACK reply.
179298aa4e5SRuslan Ermilov.It Li unreach
180298aa4e5SRuslan ErmilovEntries dropped due to ICMP unreachable messages.
181298aa4e5SRuslan Ermilov.It Li "zone failures"
182298aa4e5SRuslan ErmilovFailures to allocate new
183298aa4e5SRuslan Ermilov.Nm
184298aa4e5SRuslan Ermiloventry.
185298aa4e5SRuslan Ermilov.It Li "cookies received"
186298aa4e5SRuslan ErmilovConnections created from segment containing ACK.
187298aa4e5SRuslan Ermilov.El
188298aa4e5SRuslan Ermilov.Sh SEE ALSO
189298aa4e5SRuslan Ermilov.Xr netstat 1 ,
190298aa4e5SRuslan Ermilov.Xr tcp 4 ,
191298aa4e5SRuslan Ermilov.Xr ttcp 4 ,
192298aa4e5SRuslan Ermilov.Xr loader 8 ,
193298aa4e5SRuslan Ermilov.Xr sysctl 8
194298aa4e5SRuslan Ermilov.Sh HISTORY
195298aa4e5SRuslan ErmilovThe existing
196298aa4e5SRuslan Ermilov.Nm
197298aa4e5SRuslan Ermilovimplementation
198298aa4e5SRuslan Ermilovfirst appeared in
199298aa4e5SRuslan Ermilov.Fx 4.5 .
200298aa4e5SRuslan ErmilovThe original concept of a
201298aa4e5SRuslan Ermilov.Nm
202298aa4e5SRuslan Ermilovoriginally appeared in
203298aa4e5SRuslan Ermilov.Bsx ,
204298aa4e5SRuslan Ermilovand was later modified by
205298aa4e5SRuslan Ermilov.Nx ,
206298aa4e5SRuslan Ermilovthen further extended here.
207298aa4e5SRuslan Ermilov.Sh AUTHORS
208298aa4e5SRuslan ErmilovThe
209298aa4e5SRuslan Ermilov.Nm
210298aa4e5SRuslan Ermilovcode and manual page were written by
211298aa4e5SRuslan Ermilov.An Jonathan Lemon Aq jlemon@FreeBSD.org .
212